ソースを参照

HDFS-9176. Fix TestDirectoryScanner#testThrottling often fails. (Daniel Templeton via lei)

(cherry picked from commit 6dd47d754cb11297c8710a5c318c034abea7a836)
Lei Xu 9 年 前
コミット
ad1f0f307b

+ 3 - 0
hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt

@@ -1163,6 +1163,9 @@ Release 2.8.0 - UNRELEASED
     HDFS-9159. [OIV] : return value of the command is not correct if invalid
     value specified in "-p (processor)" option (nijel via vinayakumarb)
 
+    HDFS-9176. Fix TestDirectoryScanner#testThrottling often fails.
+    (Daniel Templeton via lei)
+
 Release 2.7.2 - UNRELEASED
 
   INCOMPATIBLE CHANGES

+ 12 - 5
hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/TestDirectoryScanner.java

@@ -665,17 +665,24 @@ public class TestDirectoryScanner {
           interruptor.schedule(new Runnable() {
             @Override
             public void run() {
-              scanner.shutdown();
               nowMs.set(Time.monotonicNow());
+              scanner.shutdown();
             }
           }, 2L, TimeUnit.SECONDS);
 
           scanner.reconcile();
           assertFalse(scanner.getRunStatus());
-          LOG.info("Scanner took " + (Time.monotonicNow() - nowMs.get())
-              + "ms to shutdown");
-          assertTrue("Scanner took too long to shutdown",
-              Time.monotonicNow() - nowMs.get() < 1000L);
+
+          long finalMs = nowMs.get();
+
+          // If the scan didn't complete before the shutdown was run, check
+          // that the shutdown was timely
+          if (finalMs > 0) {
+            LOG.info("Scanner took " + (Time.monotonicNow() - finalMs)
+                + "ms to shutdown");
+            assertTrue("Scanner took too long to shutdown",
+                Time.monotonicNow() - finalMs < 1000L);
+          }
 
           ratio =
               (float)scanner.timeWaitingMs.get() / scanner.timeRunningMs.get();