|
@@ -23,8 +23,10 @@ import static org.junit.Assert.assertNull;
|
|
|
import static org.junit.Assert.assertTrue;
|
|
|
import static org.mockito.Matchers.any;
|
|
|
import static org.mockito.Matchers.argThat;
|
|
|
+import static org.mockito.Matchers.refEq;
|
|
|
import static org.mockito.Mockito.mock;
|
|
|
import static org.mockito.Mockito.reset;
|
|
|
+import static org.mockito.Mockito.times;
|
|
|
import static org.mockito.Mockito.verify;
|
|
|
import static org.mockito.Mockito.when;
|
|
|
import static org.mockito.Mockito.atLeastOnce;
|
|
@@ -518,6 +520,17 @@ public class TestContainer {
|
|
|
ContainerLaunch launcher = wc.launcher.running.get(wc.c.getContainerId());
|
|
|
wc.killContainer();
|
|
|
assertEquals(ContainerState.KILLING, wc.c.getContainerState());
|
|
|
+
|
|
|
+ // check that container cleanup hasn't started at this point.
|
|
|
+ LocalizationCleanupMatcher cleanupResources =
|
|
|
+ new LocalizationCleanupMatcher(wc.c);
|
|
|
+ verify(wc.localizerBus, times(0)).handle(argThat(cleanupResources));
|
|
|
+
|
|
|
+ // check if containerlauncher cleans up the container launch.
|
|
|
+ verify(wc.launcherBus)
|
|
|
+ .handle(refEq(new ContainersLauncherEvent(wc.c,
|
|
|
+ ContainersLauncherEventType.CLEANUP_CONTAINER), "timestamp"));
|
|
|
+
|
|
|
launcher.call();
|
|
|
wc.drainDispatcherEvents();
|
|
|
assertEquals(ContainerState.CONTAINER_CLEANEDUP_AFTER_KILL,
|
|
@@ -530,6 +543,7 @@ public class TestContainer {
|
|
|
assertEquals(ContainerState.DONE, wc.c.getContainerState());
|
|
|
assertEquals(killed + 1, metrics.getKilledContainers());
|
|
|
assertEquals(0, metrics.getRunningContainers());
|
|
|
+ assertEquals(0, wc.launcher.running.size());
|
|
|
} finally {
|
|
|
if (wc != null) {
|
|
|
wc.finished();
|
|
@@ -856,7 +870,7 @@ public class TestContainer {
|
|
|
ResourcesReleasedMatcher matchesReq =
|
|
|
new ResourcesReleasedMatcher(wc.localResources, EnumSet.of(
|
|
|
LocalResourceVisibility.PUBLIC, LocalResourceVisibility.PRIVATE,
|
|
|
- LocalResourceVisibility.APPLICATION));
|
|
|
+ LocalResourceVisibility.APPLICATION), wc.c);
|
|
|
verify(wc.localizerBus, atLeastOnce()).handle(argThat(matchesReq));
|
|
|
}
|
|
|
|
|
@@ -864,13 +878,35 @@ public class TestContainer {
|
|
|
verify(wc.context.getNodeStatusUpdater()).sendOutofBandHeartBeat();
|
|
|
}
|
|
|
|
|
|
- private static class ResourcesReleasedMatcher extends
|
|
|
+ // Argument matcher for matching container localization cleanup event.
|
|
|
+ private static class LocalizationCleanupMatcher extends
|
|
|
ArgumentMatcher<LocalizationEvent> {
|
|
|
+ Container c;
|
|
|
+
|
|
|
+ LocalizationCleanupMatcher(Container c){
|
|
|
+ this.c = c;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean matches(Object o) {
|
|
|
+ if (!(o instanceof ContainerLocalizationCleanupEvent)) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ ContainerLocalizationCleanupEvent evt =
|
|
|
+ (ContainerLocalizationCleanupEvent) o;
|
|
|
+
|
|
|
+ return (evt.getContainer() == c);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private static class ResourcesReleasedMatcher extends
|
|
|
+ LocalizationCleanupMatcher {
|
|
|
final HashSet<LocalResourceRequest> resources =
|
|
|
new HashSet<LocalResourceRequest>();
|
|
|
|
|
|
ResourcesReleasedMatcher(Map<String, LocalResource> allResources,
|
|
|
- EnumSet<LocalResourceVisibility> vis) throws URISyntaxException {
|
|
|
+ EnumSet<LocalResourceVisibility> vis, Container c) throws URISyntaxException {
|
|
|
+ super(c);
|
|
|
for (Entry<String, LocalResource> e : allResources.entrySet()) {
|
|
|
if (vis.contains(e.getValue().getVisibility())) {
|
|
|
resources.add(new LocalResourceRequest(e.getValue()));
|
|
@@ -880,9 +916,12 @@ public class TestContainer {
|
|
|
|
|
|
@Override
|
|
|
public boolean matches(Object o) {
|
|
|
- if (!(o instanceof ContainerLocalizationCleanupEvent)) {
|
|
|
+ // match event type and container.
|
|
|
+ if(!super.matches(o)){
|
|
|
return false;
|
|
|
}
|
|
|
+
|
|
|
+ // match resources.
|
|
|
ContainerLocalizationCleanupEvent evt =
|
|
|
(ContainerLocalizationCleanupEvent) o;
|
|
|
final HashSet<LocalResourceRequest> expected =
|