Skip to content
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
package org.apache.hadoop.yarn.server.nodemanager.containermanager.launcher;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.test.Whitebox;
import org.apache.hadoop.yarn.api.records.ApplicationAttemptId;
import org.apache.hadoop.yarn.api.records.ApplicationId;
import org.apache.hadoop.yarn.api.records.ContainerId;
Expand All @@ -40,8 +39,6 @@

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
Expand Down Expand Up @@ -123,10 +120,8 @@ public void setup() throws IllegalArgumentException, IllegalAccessException {
@SuppressWarnings("unchecked")
@Test
public void testLaunchContainerEvent()
throws IllegalArgumentException, IllegalAccessException {
Map<ContainerId, ContainerLaunch> dummyMap =
(Map<ContainerId, ContainerLaunch>) Whitebox.getInternalState(spy,
"running");
throws IllegalArgumentException {
Map<ContainerId, ContainerLaunch> dummyMap = spy.running;
when(event.getType())
.thenReturn(ContainersLauncherEventType.LAUNCH_CONTAINER);
assertEquals(0, dummyMap.size());
Expand All @@ -139,10 +134,8 @@ public void testLaunchContainerEvent()
@SuppressWarnings("unchecked")
@Test
public void testRelaunchContainerEvent()
throws IllegalArgumentException, IllegalAccessException {
Map<ContainerId, ContainerLaunch> dummyMap =
(Map<ContainerId, ContainerLaunch>) Whitebox.getInternalState(spy,
"running");
throws IllegalArgumentException {
Map<ContainerId, ContainerLaunch> dummyMap = spy.running;
when(event.getType())
.thenReturn(ContainersLauncherEventType.RELAUNCH_CONTAINER);
assertEquals(0, dummyMap.size());
Expand All @@ -159,10 +152,8 @@ public void testRelaunchContainerEvent()
@SuppressWarnings("unchecked")
@Test
public void testRecoverContainerEvent()
throws IllegalArgumentException, IllegalAccessException {
Map<ContainerId, ContainerLaunch> dummyMap =
(Map<ContainerId, ContainerLaunch>) Whitebox.getInternalState(spy,
"running");
throws IllegalArgumentException {
Map<ContainerId, ContainerLaunch> dummyMap = spy.running;
when(event.getType())
.thenReturn(ContainersLauncherEventType.RECOVER_CONTAINER);
assertEquals(0, dummyMap.size());
Expand All @@ -178,7 +169,7 @@ public void testRecoverContainerEvent()

@Test
public void testRecoverPausedContainerEvent()
throws IllegalArgumentException, IllegalAccessException {
throws IllegalArgumentException {
when(event.getType())
.thenReturn(ContainersLauncherEventType.RECOVER_PAUSED_CONTAINER);
spy.handle(event);
Expand All @@ -189,27 +180,23 @@ public void testRecoverPausedContainerEvent()
@Test
public void testCleanupContainerEvent()
throws IllegalArgumentException, IllegalAccessException, IOException {
Map<ContainerId, ContainerLaunch> dummyMap = Collections
.synchronizedMap(new HashMap<ContainerId, ContainerLaunch>());
dummyMap.put(containerId, containerLaunch);
Whitebox.setInternalState(spy, "running", dummyMap);
spy.running.clear();
spy.running.put(containerId, containerLaunch);

when(event.getType())
.thenReturn(ContainersLauncherEventType.CLEANUP_CONTAINER);
assertEquals(1, dummyMap.size());
assertEquals(1, spy.running.size());
spy.handle(event);
assertEquals(0, dummyMap.size());
assertEquals(0, spy.running.size());
Mockito.verify(containerLauncher, Mockito.times(1))
.submit(Mockito.any(ContainerCleanup.class));
}

@Test
public void testCleanupContainerForReINITEvent()
throws IllegalArgumentException, IllegalAccessException, IOException {
Map<ContainerId, ContainerLaunch> dummyMap = Collections
.synchronizedMap(new HashMap<ContainerId, ContainerLaunch>());
dummyMap.put(containerId, containerLaunch);
Whitebox.setInternalState(spy, "running", dummyMap);
spy.running.clear();
spy.running.put(containerId, containerLaunch);

when(event.getType())
.thenReturn(ContainersLauncherEventType.CLEANUP_CONTAINER_FOR_REINIT);
Expand All @@ -226,9 +213,6 @@ public void testCleanupContainerForReINITEvent()
@Test
public void testSignalContainerEvent()
throws IllegalArgumentException, IllegalAccessException, IOException {
Map<ContainerId, ContainerLaunch> dummyMap = Collections
.synchronizedMap(new HashMap<ContainerId, ContainerLaunch>());
dummyMap.put(containerId, containerLaunch);

SignalContainersLauncherEvent dummyEvent =
mock(SignalContainersLauncherEvent.class);
Expand All @@ -238,46 +222,43 @@ public void testSignalContainerEvent()
when(containerId.getApplicationAttemptId().getApplicationId())
.thenReturn(appId);

Whitebox.setInternalState(spy, "running", dummyMap);
spy.running.clear();
spy.running.put(containerId, containerLaunch);
when(dummyEvent.getType())
.thenReturn(ContainersLauncherEventType.SIGNAL_CONTAINER);
when(dummyEvent.getCommand())
.thenReturn(SignalContainerCommand.GRACEFUL_SHUTDOWN);
doNothing().when(containerLaunch)
.signalContainer(SignalContainerCommand.GRACEFUL_SHUTDOWN);
spy.handle(dummyEvent);
assertEquals(1, dummyMap.size());
assertEquals(1, spy.running.size());
Mockito.verify(containerLaunch, Mockito.times(1))
.signalContainer(SignalContainerCommand.GRACEFUL_SHUTDOWN);
}

@Test
public void testPauseContainerEvent()
throws IllegalArgumentException, IllegalAccessException, IOException {
Map<ContainerId, ContainerLaunch> dummyMap = Collections
.synchronizedMap(new HashMap<ContainerId, ContainerLaunch>());
dummyMap.put(containerId, containerLaunch);
Whitebox.setInternalState(spy, "running", dummyMap);
spy.running.clear();
spy.running.put(containerId, containerLaunch);
when(event.getType())
.thenReturn(ContainersLauncherEventType.PAUSE_CONTAINER);
doNothing().when(containerLaunch).pauseContainer();
spy.handle(event);
assertEquals(1, dummyMap.size());
assertEquals(1, spy.running.size());
Mockito.verify(containerLaunch, Mockito.times(1)).pauseContainer();
}

@Test
public void testResumeContainerEvent()
throws IllegalArgumentException, IllegalAccessException, IOException {
Map<ContainerId, ContainerLaunch> dummyMap = Collections
.synchronizedMap(new HashMap<ContainerId, ContainerLaunch>());
dummyMap.put(containerId, containerLaunch);
Whitebox.setInternalState(spy, "running", dummyMap);
spy.running.clear();
spy.running.put(containerId, containerLaunch);
when(event.getType())
.thenReturn(ContainersLauncherEventType.RESUME_CONTAINER);
doNothing().when(containerLaunch).resumeContainer();
spy.handle(event);
assertEquals(1, dummyMap.size());
assertEquals(1, spy.running.size());
Mockito.verify(containerLaunch, Mockito.times(1)).resumeContainer();
}
}