Browse Source

HDFS-919. Create test to validate the BlocksVerified metric. Contributed by Gary Murry.

git-svn-id: https://svn.apache.org/repos/asf/hadoop/hdfs/trunk@903906 13f79535-47bb-0310-9956-ffa450edef68
Konstantin Boudnik 15 years ago
parent
commit
cd3e998e24
2 changed files with 17 additions and 3 deletions
  1. 3 0
      CHANGES.txt
  2. 14 3
      src/test/hdfs/org/apache/hadoop/hdfs/TestDatanodeBlockScanner.java

+ 3 - 0
CHANGES.txt

@@ -663,6 +663,9 @@ Release 0.20.2 - Unreleased
     HDFS-737. Add full path name of the file to the block information and 
     HDFS-737. Add full path name of the file to the block information and 
     summary of total number of files, blocks, live and deadnodes to 
     summary of total number of files, blocks, live and deadnodes to 
     metasave output. (Jitendra Nath Pandey via suresh)
     metasave output. (Jitendra Nath Pandey via suresh)
+
+    HDFS-919. Create test to validate the BlocksVerified metric (Gary Murry
+    via cos)
     
     
   BUG FIXES
   BUG FIXES
 
 

+ 14 - 3
src/test/hdfs/org/apache/hadoop/hdfs/TestDatanodeBlockScanner.java

@@ -50,12 +50,15 @@ public class TestDatanodeBlockScanner extends TestCase {
   
   
   private static Pattern pattern = 
   private static Pattern pattern = 
              Pattern.compile(".*?(blk_[-]*\\d+).*?scan time\\s*:\\s*(\\d+)");
              Pattern.compile(".*?(blk_[-]*\\d+).*?scan time\\s*:\\s*(\\d+)");
+  
+  private static Pattern pattern_blockVerify = 
+             Pattern.compile(".*?(SCAN_PERIOD)\\s*:\\s*(\\d+.*?)");
   /**
   /**
    * This connects to datanode and fetches block verification data.
    * This connects to datanode and fetches block verification data.
    * It repeats this until the given block has a verification time > 0.
    * It repeats this until the given block has a verification time > 0.
    */
    */
   private static long waitForVerification(DatanodeInfo dn, FileSystem fs, 
   private static long waitForVerification(DatanodeInfo dn, FileSystem fs, 
-                                          Path file) throws IOException {
+                                          Path file, int blocksValidated) throws IOException {
     URL url = new URL("http://localhost:" + dn.getInfoPort() +
     URL url = new URL("http://localhost:" + dn.getInfoPort() +
                       "/blockScannerReport?listblocks");
                       "/blockScannerReport?listblocks");
     long lastWarnTime = System.currentTimeMillis();
     long lastWarnTime = System.currentTimeMillis();
@@ -65,6 +68,14 @@ public class TestDatanodeBlockScanner extends TestCase {
     
     
     while (verificationTime <= 0) {
     while (verificationTime <= 0) {
       String response = DFSTestUtil.urlGet(url);
       String response = DFSTestUtil.urlGet(url);
+      if(blocksValidated >= 0) {
+        for(Matcher matcher = pattern_blockVerify.matcher(response); matcher.find();) {
+          if (block.equals(matcher.group(1))) {
+            assertEquals(1, blocksValidated);
+            break;
+          }
+        }
+      }
       for(Matcher matcher = pattern.matcher(response); matcher.find();) {
       for(Matcher matcher = pattern.matcher(response); matcher.find();) {
         if (block.equals(matcher.group(1))) {
         if (block.equals(matcher.group(1))) {
           verificationTime = Long.parseLong(matcher.group(2));
           verificationTime = Long.parseLong(matcher.group(2));
@@ -115,7 +126,7 @@ public class TestDatanodeBlockScanner extends TestCase {
     /*
     /*
      * The cluster restarted. The block should be verified by now.
      * The cluster restarted. The block should be verified by now.
      */
      */
-    assertTrue(waitForVerification(dn, fs, file1) > startTime);
+    assertTrue(waitForVerification(dn, fs, file1, 1) > startTime);
     
     
     /*
     /*
      * Create a new file and read the block. The block should be marked 
      * Create a new file and read the block. The block should be marked 
@@ -124,7 +135,7 @@ public class TestDatanodeBlockScanner extends TestCase {
     DFSTestUtil.createFile(fs, file2, 10, (short)1, 0);
     DFSTestUtil.createFile(fs, file2, 10, (short)1, 0);
     IOUtils.copyBytes(fs.open(file2), new IOUtils.NullOutputStream(), 
     IOUtils.copyBytes(fs.open(file2), new IOUtils.NullOutputStream(), 
                       conf, true); 
                       conf, true); 
-    assertTrue(waitForVerification(dn, fs, file2) > startTime);
+    assertTrue(waitForVerification(dn, fs, file2, 2) > startTime);
     
     
     cluster.shutdown();
     cluster.shutdown();
   }
   }