Kaynağa Gözat

HDFS-1015. Fix intermittent failure in TestSecurityTokenEditLog. Contribute by Jitendra Nath Pandey.


git-svn-id: https://svn.apache.org/repos/asf/hadoop/hdfs/trunk@925004 13f79535-47bb-0310-9956-ffa450edef68
Suresh Srinivas 15 yıl önce
ebeveyn
işleme
c6e770a755

+ 5 - 2
CHANGES.txt

@@ -163,8 +163,8 @@ Trunk (unreleased changes)
     Lipcon via hairong)
     Lipcon via hairong)
 
 
     HDFS-630. In DFSOutputStream.nextBlockOutputStream(), the client can
     HDFS-630. In DFSOutputStream.nextBlockOutputStream(), the client can
-              exclude specific datanodes when locating the next block.
-              (Cosmin Lehene via Stack)
+    exclude specific datanodes when locating the next block.
+    (Cosmin Lehene via Stack)
 
 
     HDFS-922. Remove unnecessary semicolon added by HDFS-877 that causes
     HDFS-922. Remove unnecessary semicolon added by HDFS-877 that causes
     problems for Eclipse compilation. (jghoman)
     problems for Eclipse compilation. (jghoman)
@@ -200,6 +200,9 @@ Trunk (unreleased changes)
 
 
     HDFS-961. dfs_readdir incorrectly parses paths. (Eli Collins via tomwhite)
     HDFS-961. dfs_readdir incorrectly parses paths. (Eli Collins via tomwhite)
 
 
+    HDFS-1015. Fix intermittent failure in TestSecurityTokenEditLog.
+    (Jitendra Nath Pandey via suresh)
+    
 Release 0.21.0 - Unreleased
 Release 0.21.0 - Unreleased
 
 
   INCOMPATIBLE CHANGES
   INCOMPATIBLE CHANGES

+ 8 - 0
src/java/org/apache/hadoop/hdfs/security/token/delegation/DelegationTokenSecretManager.java

@@ -204,6 +204,14 @@ public class DelegationTokenSecretManager
     }
     }
     currentTokens.remove(identifier);
     currentTokens.remove(identifier);
   }
   }
+  
+  /**
+   * Returns the number of delegation keys currently stored.
+   * @return number of delegation keys
+   */
+  public synchronized int getNumberOfKeys() {
+    return allKeys.size();
+  }
 
 
   /**
   /**
    * Private helper methods to save delegation keys and tokens in fsimage
    * Private helper methods to save delegation keys and tokens in fsimage

+ 4 - 4
src/test/hdfs/org/apache/hadoop/hdfs/server/namenode/TestSecurityTokenEditLog.java

@@ -96,7 +96,6 @@ public class TestSecurityTokenEditLog extends TestCase {
       cluster.waitActive();
       cluster.waitActive();
       fileSys = cluster.getFileSystem();
       fileSys = cluster.getFileSystem();
       final FSNamesystem namesystem = cluster.getNamesystem();
       final FSNamesystem namesystem = cluster.getNamesystem();
-      namesystem.getDelegationTokenSecretManager().startThreads();
   
   
       for (Iterator<URI> it = cluster.getNameDirs().iterator(); it.hasNext(); ) {
       for (Iterator<URI> it = cluster.getNameDirs().iterator(); it.hasNext(); ) {
         File dir = new File(it.next().getPath());
         File dir = new File(it.next().getPath());
@@ -110,6 +109,7 @@ public class TestSecurityTokenEditLog extends TestCase {
       editLog.setBufferCapacity(2048);
       editLog.setBufferCapacity(2048);
       editLog.close();
       editLog.close();
       editLog.open();
       editLog.open();
+      namesystem.getDelegationTokenSecretManager().startThreads();
     
     
       // Create threads and make them run transactions concurrently.
       // Create threads and make them run transactions concurrently.
       Thread threadId[] = new Thread[NUM_THREADS];
       Thread threadId[] = new Thread[NUM_THREADS];
@@ -129,13 +129,13 @@ public class TestSecurityTokenEditLog extends TestCase {
       } 
       } 
       
       
       editLog.close();
       editLog.close();
-      editLog.open();
   
   
       // Verify that we can read in all the transactions that we have written.
       // Verify that we can read in all the transactions that we have written.
       // If there were any corruptions, it is likely that the reading in
       // If there were any corruptions, it is likely that the reading in
       // of these transactions will throw an exception.
       // of these transactions will throw an exception.
       //
       //
       namesystem.getDelegationTokenSecretManager().stopThreads();
       namesystem.getDelegationTokenSecretManager().stopThreads();
+      int numKeys = namesystem.getDelegationTokenSecretManager().getNumberOfKeys();
       for (Iterator<StorageDirectory> it = 
       for (Iterator<StorageDirectory> it = 
               fsimage.dirIterator(NameNodeDirType.EDITS); it.hasNext();) {
               fsimage.dirIterator(NameNodeDirType.EDITS); it.hasNext();) {
         File editFile = FSImage.getImageFile(it.next(), NameNodeFile.EDITS);
         File editFile = FSImage.getImageFile(it.next(), NameNodeFile.EDITS);
@@ -143,9 +143,9 @@ public class TestSecurityTokenEditLog extends TestCase {
         int numEdits = namesystem.getEditLog().loadFSEdits(
         int numEdits = namesystem.getEditLog().loadFSEdits(
                                   new EditLogFileInputStream(editFile));
                                   new EditLogFileInputStream(editFile));
         assertTrue("Verification for " + editFile + " failed. " +
         assertTrue("Verification for " + editFile + " failed. " +
-                   "Expected " + (NUM_THREADS * opsPerTrans * NUM_TRANSACTIONS + 2) + " transactions. "+
+                   "Expected " + (NUM_THREADS * opsPerTrans * NUM_TRANSACTIONS + numKeys) + " transactions. "+
                    "Found " + numEdits + " transactions.",
                    "Found " + numEdits + " transactions.",
-                   numEdits == NUM_THREADS * opsPerTrans * NUM_TRANSACTIONS +2);
+                   numEdits == NUM_THREADS * opsPerTrans * NUM_TRANSACTIONS +numKeys);
   
   
       }
       }
     } finally {
     } finally {