Browse Source

HDFS-11120. TestEncryptionZones should waitActive. Contributed by John Zhuge.

(cherry picked from commit 907b1431c0ead934e26cf7dbc51bfab5d7cc5ddc)
Xiao Chen 8 years ago
parent
commit
d81706cd99

+ 34 - 27
hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestEncryptionZones.java

@@ -93,7 +93,9 @@ import org.apache.log4j.Logger;
 import org.junit.After;
 import org.junit.Assert;
 import org.junit.Before;
+import org.junit.Rule;
 import org.junit.Test;
+import org.junit.rules.Timeout;
 import org.mockito.Mockito;
 
 import static org.junit.Assert.assertNotNull;
@@ -145,6 +147,9 @@ public class TestEncryptionZones {
       new Path(testRootDir.toString(), "test.jks").toUri();
   }
 
+  @Rule
+  public Timeout globalTimeout = new Timeout(120 * 1000);
+
   @Before
   public void setup() throws Exception {
     conf = new HdfsConfiguration();
@@ -159,6 +164,7 @@ public class TestEncryptionZones {
     conf.setInt(DFSConfigKeys.DFS_NAMENODE_LIST_ENCRYPTION_ZONES_NUM_RESPONSES,
         2);
     cluster = new MiniDFSCluster.Builder(conf).numDataNodes(1).build();
+    cluster.waitActive();
     Logger.getLogger(EncryptionZoneManager.class).setLevel(Level.TRACE);
     fs = cluster.getFileSystem();
     fsWrapper = new FileSystemTestWrapper(fs);
@@ -230,7 +236,7 @@ public class TestEncryptionZones {
    * with sticky bits.
    * @throws Exception
    */
-  @Test(timeout = 60000)
+  @Test
   public void testTrashStickyBit() throws Exception {
     // create an EZ /zones/zone1, make it world writable.
     final Path zoneParent = new Path("/zones");
@@ -293,7 +299,7 @@ public class TestEncryptionZones {
    * with sticky bits.
    * @throws Exception
    */
-  @Test(timeout = 60000)
+  @Test
   public void testProvisionTrash() throws Exception {
     // create an EZ /zones/zone1
     final Path zoneParent = new Path("/zones");
@@ -325,7 +331,8 @@ public class TestEncryptionZones {
     assertTrue(trashFileStatus.getPermission().getStickyBit());
   }
 
-  @Test(timeout = 60000)
+  // CHECKSTYLE:OFF:MethodLengthCheck
+  @Test
   public void testBasicOperations() throws Exception {
 
     int numZones = 0;
@@ -484,8 +491,9 @@ public class TestEncryptionZones {
     assertNumZones(numZones);
     assertZonePresent(null, nonpersistZone.toString());
   }
+  // CHECKSTYLE:ON:MethodLengthCheck
 
-  @Test(timeout = 60000)
+  @Test
   public void testBasicOperationsRootDir() throws Exception {
     int numZones = 0;
     final Path rootDir = new Path("/");
@@ -509,7 +517,7 @@ public class TestEncryptionZones {
   /**
    * Test listing encryption zones as a non super user.
    */
-  @Test(timeout = 60000)
+  @Test
   public void testListEncryptionZonesAsNonSuperUser() throws Exception {
 
     final UserGroupInformation user = UserGroupInformation.
@@ -543,7 +551,7 @@ public class TestEncryptionZones {
   /**
    * Test getEncryptionZoneForPath as a non super user.
    */
-  @Test(timeout = 60000)
+  @Test
   public void testGetEZAsNonSuperUser() throws Exception {
 
     final UserGroupInformation user = UserGroupInformation.
@@ -687,12 +695,12 @@ public class TestEncryptionZones {
     }
   }
 
-  @Test(timeout = 60000)
+  @Test
   public void testRenameFileSystem() throws Exception {
     doRenameEncryptionZone(fsWrapper);
   }
 
-  @Test(timeout = 60000)
+  @Test
   public void testRenameFileContext() throws Exception {
     doRenameEncryptionZone(fcWrapper);
   }
@@ -702,7 +710,7 @@ public class TestEncryptionZones {
     return blocks.getFileEncryptionInfo();
   }
 
-  @Test(timeout = 120000)
+  @Test
   public void testReadWrite() throws Exception {
     final HdfsAdmin dfsAdmin =
         new HdfsAdmin(FileSystem.getDefaultUri(conf), conf);
@@ -758,7 +766,7 @@ public class TestEncryptionZones {
     verifyFilesEqual(fs, encFile1, encFile2, len);
   }
 
-  @Test(timeout = 120000)
+  @Test
   public void testReadWriteUsingWebHdfs() throws Exception {
     final HdfsAdmin dfsAdmin =
         new HdfsAdmin(FileSystem.getDefaultUri(conf), conf);
@@ -807,7 +815,7 @@ public class TestEncryptionZones {
     out.close();
   }
 
-  @Test(timeout = 60000)
+  @Test
   public void testVersionAndSuiteNegotiation() throws Exception {
     final HdfsAdmin dfsAdmin =
         new HdfsAdmin(FileSystem.getDefaultUri(conf), conf);
@@ -934,14 +942,13 @@ public class TestEncryptionZones {
     }
   }
 
-  @Test(timeout = 120000)
+  @Test
   public void testCreateEZWithNoProvider() throws Exception {
     // Unset the key provider and make sure EZ ops don't work
     final Configuration clusterConf = cluster.getConfiguration(0);
     clusterConf
         .unset(CommonConfigurationKeysPublic.HADOOP_SECURITY_KEY_PROVIDER_PATH);
     cluster.restartNameNode(true);
-    cluster.waitActive();
     final Path zone1 = new Path("/zone1");
     fsWrapper.mkdir(zone1, FsPermission.getDirDefault(), true);
     try {
@@ -959,7 +966,7 @@ public class TestEncryptionZones {
     assertNumZones(0);
   }
 
-  @Test(timeout = 120000)
+  @Test
   public void testIsEncryptedMethod() throws Exception {
     doTestIsEncryptedMethod(new Path("/"));
     doTestIsEncryptedMethod(new Path("/.reserved/raw"));
@@ -1136,7 +1143,7 @@ public class TestEncryptionZones {
    * Tests the retry logic in startFile. We release the lock while generating
    * an EDEK, so tricky things can happen in the intervening time.
    */
-  @Test(timeout = 120000)
+  @Test
   public void testStartFileRetry() throws Exception {
     final Path zone1 = new Path("/zone1");
     final Path file = new Path(zone1, "file1");
@@ -1231,7 +1238,7 @@ public class TestEncryptionZones {
   /**
    * Tests obtaining delegation token from stored key
    */
-  @Test(timeout = 120000)
+  @Test
   public void testDelegationToken() throws Exception {
     UserGroupInformation.createRemoteUser("JobTracker");
     DistributedFileSystem dfs = cluster.getFileSystem();
@@ -1262,7 +1269,7 @@ public class TestEncryptionZones {
   /**
    * Test running fsck on a system with encryption zones.
    */
-  @Test(timeout = 60000)
+  @Test
   public void testFsckOnEncryptionZones() throws Exception {
     final int len = 8196;
     final Path zoneParent = new Path("/zones");
@@ -1293,7 +1300,7 @@ public class TestEncryptionZones {
    * Test correctness of successive snapshot creation and deletion
    * on a system with encryption zones.
    */
-  @Test(timeout = 60000)
+  @Test
   public void testSnapshotsOnEncryptionZones() throws Exception {
     final String TEST_KEY2 = "testkey2";
     DFSTestUtil.createKey(TEST_KEY2, cluster, conf);
@@ -1375,7 +1382,7 @@ public class TestEncryptionZones {
    * they function properly when the target is in the same
    * or different ez.
    */
-  @Test(timeout = 60000)
+  @Test
   public void testEncryptionZonesWithSymlinks() throws Exception {
     // Verify we can create an encryption zone over both link and target
     final int len = 8192;
@@ -1410,7 +1417,7 @@ public class TestEncryptionZones {
     fs.delete(target, true);
   }
 
-  @Test(timeout = 60000)
+  @Test
   public void testConcatFailsInEncryptionZones() throws Exception {
     final int len = 8192;
     final Path ez = new Path("/ez");
@@ -1435,7 +1442,7 @@ public class TestEncryptionZones {
   /**
    * Test running the OfflineImageViewer on a system with encryption zones.
    */
-  @Test(timeout = 60000)
+  @Test
   public void testOfflineImageViewerOnEncryptionZones() throws Exception {
     final int len = 8196;
     final Path zoneParent = new Path("/zones");
@@ -1466,7 +1473,7 @@ public class TestEncryptionZones {
   /**
    * Test creating encryption zone on the root path
    */
-  @Test(timeout = 60000)
+  @Test
   public void testEncryptionZonesOnRootPath() throws Exception {
     final int len = 8196;
     final Path rootDir = new Path("/");
@@ -1485,7 +1492,7 @@ public class TestEncryptionZones {
     DFSTestUtil.verifyFilesNotEqual(fs, zoneFile, rawFile, len);
   }
 
-  @Test(timeout = 60000)
+  @Test
   public void testEncryptionZonesOnRelativePath() throws Exception {
     final int len = 8196;
     final Path baseDir = new Path("/somewhere/base");
@@ -1503,7 +1510,7 @@ public class TestEncryptionZones {
         .getEncryptionZoneForPath(zoneDir).getPath().toString());
   }
 
-  @Test(timeout = 60000)
+  @Test
   public void testGetEncryptionZoneOnANonExistentPaths() throws Exception {
     final Path ezPath = new Path("/ez");
     fs.mkdirs(ezPath);
@@ -1518,7 +1525,7 @@ public class TestEncryptionZones {
     assertNull("Expected null for non-existent path not in EZ", ez);
   }
 
-  @Test(timeout = 120000)
+  @Test
   public void testEncryptionZoneWithTrash() throws Exception {
     // Create the encryption zone1
     final HdfsAdmin dfsAdmin =
@@ -1562,7 +1569,7 @@ public class TestEncryptionZones {
     verifyShellDeleteWithTrash(shell, topEZ);
   }
 
-  @Test(timeout = 120000)
+  @Test
   public void testRootDirEZTrash() throws Exception {
     final HdfsAdmin dfsAdmin =
         new HdfsAdmin(FileSystem.getDefaultUri(conf), conf);
@@ -1584,7 +1591,7 @@ public class TestEncryptionZones {
         encFileTrash, rootDirTrash);
   }
 
-  @Test(timeout = 120000)
+  @Test
   public void testGetTrashRoots() throws Exception {
     final HdfsAdmin dfsAdmin =
         new HdfsAdmin(FileSystem.getDefaultUri(conf), conf);