From fd687bb4c4edc18c560c9a3dfe8d1f061031288d Mon Sep 17 00:00:00 2001 From: slfan1989 <55643692+slfan1989@users.noreply.github.com> Date: Wed, 21 Sep 2022 01:36:24 +0800 Subject: [PATCH] YARN-11305. Fix TestLogAggregationService#testLocalFileDeletionAfterUpload Failed After YARN-11241. (#4893). Contributed by fanshilun. Signed-off-by: Ayush Saxena --- .../logaggregation/TestLogAggregationService.java | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) 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/logaggregation/TestLogAggregationService.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/logaggregation/TestLogAggregationService.java index 8185f5019c..4ec8f462f5 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/logaggregation/TestLogAggregationService.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/logaggregation/TestLogAggregationService.java @@ -56,6 +56,7 @@ import java.util.List; import java.util.Map; import java.util.Set; +import java.util.Random; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; import java.util.concurrent.CountDownLatch; @@ -206,7 +207,9 @@ private void verifyLocalFileDeletion( logAggregationService.init(this.conf); logAggregationService.start(); - ApplicationId application1 = BuilderUtils.newApplicationId(1234, 1); + Random random = new Random(System.currentTimeMillis()); + long clusterTimeStamp = random.nextLong(); + ApplicationId application1 = BuilderUtils.newApplicationId(clusterTimeStamp, 1); // AppLogDir should be created File app1LogDir = @@ -245,15 +248,9 @@ private void verifyLocalFileDeletion( String containerIdStr = container11.toString(); File containerLogDir = new File(app1LogDir, containerIdStr); - int count = 0; - int maxAttempts = 50; for (String fileType : new String[]{"stdout", "stderr", "syslog"}) { File f = new File(containerLogDir, fileType); - count = 0; - while ((f.exists()) && (count < maxAttempts)) { - count++; - Thread.sleep(100); - } + GenericTestUtils.waitFor(() -> !f.exists(), 1000, 1000 * 50); Assert.assertFalse("File [" + f + "] was not deleted", f.exists()); } Assert.assertFalse("Directory [" + app1LogDir + "] was not deleted",