From e81796015a58eec3849935644271f74e361b6a0b Mon Sep 17 00:00:00 2001 From: Vinod Kumar Vavilapalli Date: Mon, 30 Dec 2013 22:22:24 +0000 Subject: [PATCH] YARN-1522. Fixed a race condition in the test TestApplicationCleanup that was causing it to randomly fail. Contributed by Liyin Liang. svn merge --ignore-ancestry -c 1554328 ../../trunk/ git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/branch-2@1554329 13f79535-47bb-0310-9956-ffa450edef68 --- hadoop-yarn-project/CHANGES.txt | 3 ++ .../TestApplicationCleanup.java | 34 +++++++++++-------- 2 files changed, 23 insertions(+), 14 deletions(-) diff --git a/hadoop-yarn-project/CHANGES.txt b/hadoop-yarn-project/CHANGES.txt index b15f133682c..ab44fee34a3 100644 --- a/hadoop-yarn-project/CHANGES.txt +++ b/hadoop-yarn-project/CHANGES.txt @@ -259,6 +259,9 @@ Release 2.4.0 - UNRELEASED YARN-1527. Fix yarn rmadmin command to print the correct usage info. (Akira AJISAKA via jianhe) + YARN-1522. Fixed a race condition in the test TestApplicationCleanup that was + causing it to randomly fail. (Liyin Liang via vinodkv) + Release 2.3.0 - UNRELEASED INCOMPATIBLE CHANGES diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestApplicationCleanup.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestApplicationCleanup.java index 5eecae0987f..75bb225d4eb 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestApplicationCleanup.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestApplicationCleanup.java @@ -100,26 +100,32 @@ public class TestApplicationCleanup { //currently only containers are cleaned via this //AM container is cleaned via container launcher resp = nm1.nodeHeartbeat(true); - List contsToClean = resp.getContainersToCleanup(); - List apps = resp.getApplicationsToCleanup(); - int cleanedConts = contsToClean.size(); - int cleanedApps = apps.size(); + List containersToCleanup = resp.getContainersToCleanup(); + List appsToCleanup = resp.getApplicationsToCleanup(); + int numCleanedContainers = containersToCleanup.size(); + int numCleanedApps = appsToCleanup.size(); waitCount = 0; - while ((cleanedConts < 2 || cleanedApps < 1) && waitCount++ < 200) { + while ((numCleanedContainers < 2 || numCleanedApps < 1) + && waitCount++ < 200) { LOG.info("Waiting to get cleanup events.. cleanedConts: " - + cleanedConts + " cleanedApps: " + cleanedApps); + + numCleanedContainers + " cleanedApps: " + numCleanedApps); Thread.sleep(100); resp = nm1.nodeHeartbeat(true); - contsToClean = resp.getContainersToCleanup(); - apps = resp.getApplicationsToCleanup(); - cleanedConts += contsToClean.size(); - cleanedApps += apps.size(); + List deltaContainersToCleanup = + resp.getContainersToCleanup(); + List deltaAppsToCleanup = resp.getApplicationsToCleanup(); + // Add the deltas to the global list + containersToCleanup.addAll(deltaContainersToCleanup); + appsToCleanup.addAll(deltaAppsToCleanup); + // Update counts now + numCleanedContainers = containersToCleanup.size(); + numCleanedApps = appsToCleanup.size(); } - Assert.assertEquals(1, apps.size()); - Assert.assertEquals(app.getApplicationId(), apps.get(0)); - Assert.assertEquals(1, cleanedApps); - Assert.assertEquals(2, cleanedConts); + Assert.assertEquals(1, appsToCleanup.size()); + Assert.assertEquals(app.getApplicationId(), appsToCleanup.get(0)); + Assert.assertEquals(1, numCleanedApps); + Assert.assertEquals(2, numCleanedContainers); rm.stop(); }