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

This commit is contained in:
Anu Engineer 2017-10-02 13:11:47 -07:00
parent ceca9694f9
commit 442ea85545
1 changed files with 8 additions and 7 deletions

View File

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