Browse Source

HADOOP-14752. TestCopyFromLocal#testCopyFromLocalWithThreads is fleaky. Contributed by Andras Bokor.

(cherry picked from commit 442ea85545ce3591f45211773a10346340abaed5)
Anu Engineer 7 years ago
parent
commit
0160a708ae

+ 8 - 7
hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/shell/TestCopyFromLocal.java

@@ -115,10 +115,10 @@ public class TestCopyFromLocal {
     Path dir = new Path("dir" + RandomStringUtils.randomNumeric(4));
     int numFiles = TestCopyFromLocal.initialize(dir);
     int maxThreads = Runtime.getRuntime().availableProcessors() * 2;
-    int randThreads = RandomUtils.nextInt(maxThreads);
-    int numActualThreads = randThreads == 0 ? 1 : randThreads;
-    String numThreads = Integer.toString(numActualThreads);
-    run(new TestMultiThreadedCopy(numActualThreads, numFiles), "-t", numThreads,
+    int randThreads = RandomUtils.nextInt(maxThreads - 1) + 1;
+    String numThreads = Integer.toString(randThreads);
+    run(new TestMultiThreadedCopy(randThreads,
+        randThreads == 1 ? 0 : numFiles), "-t", numThreads,
         new Path(dir, FROM_DIR_NAME).toString(),
         new Path(dir, TO_DIR_NAME).toString());
   }
@@ -144,6 +144,7 @@ public class TestCopyFromLocal {
   }
 
   private class TestMultiThreadedCopy extends CopyFromLocal {
+    public static final String NAME = "testCopyFromLocal";
     private int expectedThreads;
     private int expectedCompletedTaskCount;
 
@@ -164,9 +165,9 @@ public class TestCopyFromLocal {
       // 2) There are no active tasks in the executor
       // 3) Executor has shutdown correctly
       ThreadPoolExecutor executor = getExecutor();
-      Assert.assertEquals(executor.getCompletedTaskCount(),
-          expectedCompletedTaskCount);
-      Assert.assertEquals(executor.getActiveCount(), 0);
+      Assert.assertEquals(expectedCompletedTaskCount,
+          executor.getCompletedTaskCount());
+      Assert.assertEquals(0, executor.getActiveCount());
       Assert.assertTrue(executor.isTerminated());
     }
   }