From 0656d2dc83af6a48a8d8d0e37cdf1f813124f366 Mon Sep 17 00:00:00 2001 From: Tsuyoshi Ozawa Date: Thu, 26 Nov 2015 01:10:02 +0900 Subject: [PATCH] YARN-4380. TestResourceLocalizationService.testDownloadingResourcesOnContainerKill fails intermittently. Contributed by Varun Saxena. --- hadoop-yarn-project/CHANGES.txt | 3 +++ .../TestResourceLocalizationService.java | 18 +++++++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/hadoop-yarn-project/CHANGES.txt b/hadoop-yarn-project/CHANGES.txt index e0363357b2..d0b31ddc93 100644 --- a/hadoop-yarn-project/CHANGES.txt +++ b/hadoop-yarn-project/CHANGES.txt @@ -1106,6 +1106,9 @@ Release 2.7.3 - UNRELEASED YARN-4365. FileSystemNodeLabelStore should check for root dir existence on startup (Kuhu Shukla via jlowe) + YARN-4380. TestResourceLocalizationService.testDownloadingResourcesOnContainerKill + fails intermittently. (Varun Saxena via ozawa) + Release 2.7.2 - UNRELEASED INCOMPATIBLE CHANGES diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/localizer/TestResourceLocalizationService.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/localizer/TestResourceLocalizationService.java index c14ec7f45d..64d3d68ce2 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/localizer/TestResourceLocalizationService.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/localizer/TestResourceLocalizationService.java @@ -63,6 +63,7 @@ import java.util.concurrent.BrokenBarrierException; import java.util.concurrent.CyclicBarrier; import java.util.concurrent.Future; +import java.util.concurrent.atomic.AtomicInteger; import org.apache.hadoop.fs.Options; import org.apache.hadoop.yarn.server.nodemanager.executor.LocalizerStartContext; @@ -1101,14 +1102,21 @@ private void readObject(ObjectInputStream os) throws NotSerializableException { private static class DummyExecutor extends DefaultContainerExecutor { private volatile boolean stopLocalization = false; + private AtomicInteger numLocalizers = new AtomicInteger(0); @Override public void startLocalizer(LocalizerStartContext ctx) throws IOException, InterruptedException { + numLocalizers.incrementAndGet(); while (!stopLocalization) { Thread.yield(); } } - void setStopLocalization() { + private void waitForLocalizers(int num) { + while (numLocalizers.intValue() < num) { + Thread.yield(); + } + } + private void setStopLocalization() { stopLocalization = true; } } @@ -1251,6 +1259,10 @@ public boolean matches(Object o) { spyService.handle(new ContainerLocalizationRequestEvent(c2, rsrcs1)); dispatcher.await(); + // Wait for localizers of both container c1 and c2 to begin. + exec.waitForLocalizers(2); + LocalizerRunner locC1 = + spyService.getLocalizerRunner(c1.getContainerId().toString()); final String containerIdStr = c1.getContainerId().toString(); // Heartbeats from container localizer LocalResourceStatus rsrc1success = mock(LocalResourceStatus.class); @@ -1318,6 +1330,10 @@ public boolean matches(Object o) { Set paths = Sets.newHashSet(new Path(locPath1), new Path(locPath1 + "_tmp"), new Path(locPath2), new Path(locPath2 + "_tmp")); + // Wait for localizer runner thread for container c1 to finish. + while (locC1.getState() != Thread.State.TERMINATED) { + Thread.sleep(50); + } // Verify if downloading resources were submitted for deletion. verify(delService).delete(eq(user), (Path) eq(null), argThat(new DownloadingPathsMatcher(paths)));