You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-commits@hadoop.apache.org by ae...@apache.org on 2016/09/29 18:13:38 UTC

[16/50] [abbrv] hadoop git commit: HDFS-10426. TestPendingInvalidateBlock failed in trunk. Contributed by Yiqun Lin.

HDFS-10426. TestPendingInvalidateBlock failed in trunk. Contributed by Yiqun Lin.


Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo
Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/f55eb981
Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/f55eb981
Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/f55eb981

Branch: refs/heads/HDFS-7240
Commit: f55eb981dd408ca61d49488f83c99c1fc1f83134
Parents: df1d0f5
Author: Masatake Iwasaki <iw...@apache.org>
Authored: Wed Sep 28 01:29:24 2016 +0900
Committer: Masatake Iwasaki <iw...@apache.org>
Committed: Wed Sep 28 01:29:24 2016 +0900

----------------------------------------------------------------------
 .../TestPendingInvalidateBlock.java             | 37 ++++++++++++++++++--
 1 file changed, 34 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hadoop/blob/f55eb981/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement/TestPendingInvalidateBlock.java
----------------------------------------------------------------------
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement/TestPendingInvalidateBlock.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement/TestPendingInvalidateBlock.java
index 7500544..696b2aa 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement/TestPendingInvalidateBlock.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement/TestPendingInvalidateBlock.java
@@ -18,7 +18,6 @@
 package org.apache.hadoop.hdfs.server.blockmanagement;
 
 import java.lang.reflect.Method;
-import java.text.SimpleDateFormat;
 
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.fs.CommonConfigurationKeys;
@@ -40,6 +39,8 @@ import org.junit.Test;
 import org.mockito.Mockito;
 import org.mockito.internal.util.reflection.Whitebox;
 
+import com.google.common.base.Supplier;
+
 /**
  * Test if we can correctly delay the deletion of blocks.
  */
@@ -87,13 +88,24 @@ public class TestPendingInvalidateBlock {
     DFSTestUtil.createFile(dfs, foo, BLOCKSIZE, REPLICATION, 0);
     // restart NN
     cluster.restartNameNode(true);
+    InvalidateBlocks invalidateBlocks =
+        (InvalidateBlocks) Whitebox.getInternalState(cluster.getNamesystem()
+            .getBlockManager(), "invalidateBlocks");
+    InvalidateBlocks mockIb = Mockito.spy(invalidateBlocks);
+    // Return invalidation delay to delay the block's deletion
+    Mockito.doReturn(1L).when(mockIb).getInvalidationDelay();
+    Whitebox.setInternalState(cluster.getNamesystem().getBlockManager(),
+        "invalidateBlocks", mockIb);
     dfs.delete(foo, true);
+
     Assert.assertEquals(0, cluster.getNamesystem().getBlocksTotal());
     Assert.assertEquals(REPLICATION, cluster.getNamesystem()
         .getPendingDeletionBlocks());
     Assert.assertEquals(REPLICATION,
         dfs.getPendingDeletionBlocksCount());
-    Thread.sleep(6000);
+    Mockito.doReturn(0L).when(mockIb).getInvalidationDelay();
+
+    waitForBlocksToDelete();
     Assert.assertEquals(0, cluster.getNamesystem().getBlocksTotal());
     Assert.assertEquals(0, cluster.getNamesystem().getPendingDeletionBlocks());
     Assert.assertEquals(0, dfs.getPendingDeletionBlocksCount());
@@ -170,7 +182,7 @@ public class TestPendingInvalidateBlock {
     Assert.assertEquals(4, cluster.getNamesystem().getPendingDeletionBlocks());
 
     cluster.restartNameNode(true);
-    Thread.sleep(6000);
+    waitForBlocksToDelete();
     Assert.assertEquals(3, cluster.getNamesystem().getBlocksTotal());
     Assert.assertEquals(0, cluster.getNamesystem().getPendingDeletionBlocks());
   }
@@ -187,4 +199,23 @@ public class TestPendingInvalidateBlock {
     return cluster.getNamesystem().getUnderReplicatedBlocks();
   }
 
+  private void waitForBlocksToDelete() throws Exception {
+    GenericTestUtils.waitFor(new Supplier<Boolean>() {
+
+      @Override
+      public Boolean get() {
+        try {
+          cluster.triggerBlockReports();
+
+          if (cluster.getNamesystem().getPendingDeletionBlocks() == 0) {
+            return true;
+          }
+        } catch (Exception e) {
+          // Ignore the exception
+        }
+
+        return false;
+      }
+    }, 6000, 60000);
+  }
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: common-commits-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-commits-help@hadoop.apache.org