HDFS-13819. TestDirectoryScanner#testDirectoryScannerInFederatedCluster is flaky
Change-Id: I1cea6e67fcec72702ad202775dee3373261ac5cd Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/c15853f8 Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/c15853f8 Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/c15853f8 Branch: refs/heads/branch-3.1 Commit: c15853f87ae1ce4a474494f88407786b3a644068 Parents: 975d606 Author: Daniel Templeton <[email protected]> Authored: Tue Aug 14 17:03:10 2018 -0700 Committer: Arpit Agarwal <[email protected]> Committed: Mon Aug 20 14:54:58 2018 -0700 ---------------------------------------------------------------------- .../server/datanode/TestDirectoryScanner.java | 42 +++++++++++++++----- 1 file changed, 32 insertions(+), 10 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/hadoop/blob/c15853f8/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/TestDirectoryScanner.java ---------------------------------------------------------------------- diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/TestDirectoryScanner.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/TestDirectoryScanner.java index f792523..893fe20 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/TestDirectoryScanner.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/TestDirectoryScanner.java @@ -40,6 +40,7 @@ import java.util.Random; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; import java.util.concurrent.atomic.AtomicLong; import org.apache.commons.io.FileUtils; @@ -312,18 +313,29 @@ public class TestDirectoryScanner { return id; } - private void scan(long totalBlocks, int diffsize, long missingMetaFile, long missingBlockFile, - long missingMemoryBlocks, long mismatchBlocks) throws IOException { + private void scan(long totalBlocks, int diffsize, long missingMetaFile, + long missingBlockFile, long missingMemoryBlocks, long mismatchBlocks) + throws IOException, InterruptedException, TimeoutException { scan(totalBlocks, diffsize, missingMetaFile, missingBlockFile, missingMemoryBlocks, mismatchBlocks, 0); } private void scan(long totalBlocks, int diffsize, long missingMetaFile, long missingBlockFile, long missingMemoryBlocks, long mismatchBlocks, - long duplicateBlocks) throws IOException { + long duplicateBlocks) + throws IOException, InterruptedException, TimeoutException { scanner.reconcile(); - verifyStats(totalBlocks, diffsize, missingMetaFile, missingBlockFile, - missingMemoryBlocks, mismatchBlocks, duplicateBlocks); + + GenericTestUtils.waitFor(() -> { + try { + verifyStats(totalBlocks, diffsize, missingMetaFile, missingBlockFile, + missingMemoryBlocks, mismatchBlocks, duplicateBlocks); + } catch (AssertionError ex) { + return false; + } + + return true; + }, 50, 2000); } private void verifyStats(long totalBlocks, int diffsize, long missingMetaFile, @@ -785,7 +797,8 @@ public class TestDirectoryScanner { } } - private float runThrottleTest(int blocks) throws IOException { + private float runThrottleTest(int blocks) + throws IOException, InterruptedException, TimeoutException { scanner.setRetainDiffs(true); scan(blocks, 0, 0, 0, 0, 0); scanner.shutdown(); @@ -1069,10 +1082,19 @@ public class TestDirectoryScanner { scanner.setRetainDiffs(true); scanner.reconcile(); //Check blocks in corresponding BP - bpid = cluster.getNamesystem(1).getBlockPoolId(); - verifyStats(bp1Files, 0, 0, 0, 0, 0, 0); - bpid = cluster.getNamesystem(3).getBlockPoolId(); - verifyStats(bp2Files, 0, 0, 0, 0, 0, 0); + + GenericTestUtils.waitFor(() -> { + try { + bpid = cluster.getNamesystem(1).getBlockPoolId(); + verifyStats(bp1Files, 0, 0, 0, 0, 0, 0); + bpid = cluster.getNamesystem(3).getBlockPoolId(); + verifyStats(bp2Files, 0, 0, 0, 0, 0, 0); + } catch (AssertionError ex) { + return false; + } + + return true; + }, 50, 2000); } finally { if (scanner != null) { scanner.shutdown(); --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
