Browse Source

HADOOP-19415. [JDK17] Upgrade JUnit from 4 to 5 in hadoop-common Part7. (#7664)

* HADOOP-19415. [JDK17] Upgrade JUnit from 4 to 5 in hadoop-common Part7.

Co-authored-by: He Xiaoqiao <hexiaoqiao@apache.org>
Co-authored-by: Hualong Zhang <hualong.z@hotmail.com>
Reviewed-by: Chris Nauroth <cnauroth@apache.org>
Reviewed-by: He Xiaoqiao <hexiaoqiao@apache.org>
Reviewed-by: Hualong Zhang <hualong.z@hotmail.com>
Signed-off-by: Shilun Fan <slfan1989@apache.org>
slfan1989 3 tuần trước cách đây
mục cha
commit
c4abdd7da9
40 tập tin đã thay đổi với 1875 bổ sung1696 xóa
  1. 1 1
      hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/conf/TestConfigRedactor.java
  2. 237 197
      hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestFileUtil.java
  3. 62 41
      hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestPath.java
  4. 21 15
      hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestStat.java
  5. 3 2
      hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/contract/AbstractFSContract.java
  6. 57 63
      hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/contract/ContractTestUtils.java
  7. 2 2
      hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/contract/ftp/FTPContract.java
  8. 6 6
      hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/contract/rawlocal/TestRawLocalContractUnderlyingFileBehavior.java
  9. 20 23
      hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/shell/TestTextCommand.java
  10. 95 76
      hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/viewfs/TestChRootedFileSystem.java
  11. 22 19
      hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/viewfs/TestHCFSMountTableConfigLoader.java
  12. 169 144
      hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/viewfs/TestNestedMountPoint.java
  13. 28 26
      hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/viewfs/TestRegexMountPoint.java
  14. 0 2
      hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/viewfs/TestViewFileSystemLocalFileSystem.java
  15. 12 11
      hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/viewfs/TestViewFileSystemWithAuthorityLocalFileSystem.java
  16. 13 9
      hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/viewfs/TestViewFsOverloadSchemeListStatus.java
  17. 185 179
      hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/viewfs/ViewFileSystemBaseTest.java
  18. 4 3
      hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/viewfs/ViewFsTestSetup.java
  19. 339 348
      hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/ha/ClientBaseWithFixes.java
  20. 47 35
      hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/ha/TestActiveStandbyElectorRealZK.java
  21. 27 26
      hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/ha/TestZKFailoverController.java
  22. 12 8
      hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/ha/TestZKFailoverControllerStress.java
  23. 4 4
      hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/metrics2/impl/MetricsRecords.java
  24. 25 22
      hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/metrics2/sink/RollingFileSystemSinkTestBase.java
  25. 9 9
      hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/metrics2/sink/TestRollingFileSystemSinkWithLocal.java
  26. 115 87
      hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/TestUserGroupInformation.java
  27. 54 46
      hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/token/delegation/TestZKDelegationTokenSecretManager.java
  28. 172 166
      hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/token/delegation/web/TestDelegationTokenAuthenticationHandlerWithMocks.java
  29. 8 8
      hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/service/ServiceAssert.java
  30. 9 9
      hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/service/TestGlobalStateChangeListener.java
  31. 5 5
      hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/service/TestServiceLifecycle.java
  32. 23 18
      hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/test/GenericTestUtils.java
  33. 11 7
      hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/test/LambdaTestUtils.java
  34. 29 24
      hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/test/MetricsAsserts.java
  35. 12 12
      hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/test/MoreAsserts.java
  36. 17 19
      hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/tools/GetGroupsTestBase.java
  37. 4 4
      hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/fs/contract/hdfs/HDFSContract.java
  38. 4 4
      hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/ha/TestGetGroupsWithHA.java
  39. 4 4
      hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/TestGetGroups.java
  40. 8 12
      hadoop-tools/hadoop-aws/src/test/java/org/apache/hadoop/fs/s3a/ITestS3ATemporaryCredentials.java

+ 1 - 1
hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/conf/TestConfigRedactor.java

@@ -18,7 +18,7 @@
 
 package org.apache.hadoop.conf;
 
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
 
 import java.util.Arrays;
 import java.util.List;

Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 237 - 197
hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestFileUtil.java


+ 62 - 41
hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestPath.java

@@ -18,8 +18,8 @@
 
 package org.apache.hadoop.fs;
 
-import org.junit.Assert;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.Timeout;
 
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
@@ -40,10 +40,11 @@ import org.apache.hadoop.thirdparty.com.google.common.base.Joiner;
 
 import static org.apache.hadoop.test.PlatformAssumptions.assumeNotWindows;
 import static org.apache.hadoop.test.PlatformAssumptions.assumeWindows;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.fail;
 
 /**
  * Test Hadoop Filesystem Paths.
@@ -76,7 +77,8 @@ public class TestPath {
     return mergeStatuses(paths);
   }
 
-  @Test (timeout = 30000)
+  @Test
+  @Timeout(value = 30)
   public void testToString() {
     toStringTest("/");
     toStringTest("/foo");
@@ -109,7 +111,8 @@ public class TestPath {
     assertEquals(pathString, new Path(pathString).toString());
   }
 
-  @Test (timeout = 30000)
+  @Test
+  @Timeout(value = 30)
   public void testNormalize() throws URISyntaxException {
     assertEquals("", new Path(".").toString());
     assertEquals("..", new Path("..").toString());
@@ -133,7 +136,8 @@ public class TestPath {
     }
   }
 
-  @Test (timeout = 30000)
+  @Test
+  @Timeout(value = 30)
   public void testIsAbsolute() {
     assertTrue(new Path("/").isAbsolute());
     assertTrue(new Path("/foo").isAbsolute());
@@ -146,7 +150,8 @@ public class TestPath {
     }
   }
 
-  @Test (timeout = 30000)
+  @Test
+  @Timeout(value = 30)
   public void testParent() {
     assertEquals(new Path("/foo"), new Path("/foo/bar").getParent());
     assertEquals(new Path("foo"), new Path("foo/bar").getParent());
@@ -157,7 +162,8 @@ public class TestPath {
     }
   }
 
-  @Test (timeout = 30000)
+  @Test
+  @Timeout(value = 30)
   public void testChild() {
     assertEquals(new Path("."), new Path(".", "."));
     assertEquals(new Path("/"), new Path("/", "."));
@@ -177,7 +183,8 @@ public class TestPath {
     }
   }
 
-  @Test (timeout = 30000)
+  @Test
+  @Timeout(value = 30)
   public void testPathThreeArgContructor() {
     assertEquals(new Path("foo"), new Path(null, null, "foo"));
     assertEquals(new Path("scheme:///foo"), new Path("scheme", null, "/foo"));
@@ -213,12 +220,14 @@ public class TestPath {
     }
   }
 
-  @Test (timeout = 30000)
+  @Test
+  @Timeout(value = 30)
   public void testEquals() {
     assertFalse(new Path("/").equals(new Path("/foo")));
   }
 
-  @Test (timeout = 30000)
+  @Test
+  @Timeout(value = 30)
   public void testDots() {
     // Test Path(String) 
     assertEquals(new Path("/foo/bar/baz").toString(), "/foo/bar/baz");
@@ -257,7 +266,8 @@ public class TestPath {
   }
 
   /** Test that Windows paths are correctly handled */
-  @Test (timeout = 5000)
+  @Test
+  @Timeout(value = 5)
   public void testWindowsPaths() throws URISyntaxException, IOException {
     assumeWindows();
 
@@ -268,7 +278,8 @@ public class TestPath {
   }
 
   /** Test invalid paths on Windows are correctly rejected */
-  @Test (timeout = 5000)
+  @Test
+  @Timeout(value = 5)
   public void testInvalidWindowsPaths() throws URISyntaxException, IOException {
     assumeWindows();
 
@@ -286,20 +297,23 @@ public class TestPath {
   }
 
   /** Test Path objects created from other Path objects */
-  @Test (timeout = 30000)
+  @Test
+  @Timeout(value = 30)
   public void testChildParentResolution() throws URISyntaxException, IOException {
     Path parent = new Path("foo1://bar1/baz1");
     Path child  = new Path("foo2://bar2/baz2");
     assertEquals(child, new Path(parent, child));
   }
 
-  @Test (timeout = 30000)
+  @Test
+  @Timeout(value = 30)
   public void testScheme() throws java.io.IOException {
     assertEquals("foo:/bar", new Path("foo:/","/bar").toString());
     assertEquals("foo://bar/baz", new Path("foo://bar/","/baz").toString());
   }
 
-  @Test (timeout = 30000)
+  @Test
+  @Timeout(value = 30)
   public void testURI() throws URISyntaxException, IOException {
     URI uri = new URI("file:///bar#baz");
     Path path = new Path(uri);
@@ -322,18 +336,16 @@ public class TestPath {
   }
 
   /** Test URIs created from Path objects */
-  @Test (timeout = 30000)
+  @Test
+  @Timeout(value = 30)
   public void testPathToUriConversion() throws URISyntaxException, IOException {
     // Path differs from URI in that it ignores the query part..
-    assertEquals("? mark char in to URI",
-            new URI(null, null, "/foo?bar", null, null),
-            new Path("/foo?bar").toUri());
-    assertEquals("escape slashes chars in to URI",
-            new URI(null, null, "/foo\"bar", null, null),
-            new Path("/foo\"bar").toUri());
-    assertEquals("spaces in chars to URI",
-            new URI(null, null, "/foo bar", null, null),
-            new Path("/foo bar").toUri());
+    assertEquals(new URI(null, null, "/foo?bar", null, null),
+        new Path("/foo?bar").toUri(), "? mark char in to URI");
+    assertEquals(new URI(null, null, "/foo\"bar", null, null),
+        new Path("/foo\"bar").toUri(), "escape slashes chars in to URI");
+    assertEquals(new URI(null, null, "/foo bar", null, null),
+        new Path("/foo bar").toUri(), "spaces in chars to URI");
     // therefore "foo?bar" is a valid Path, so a URI created from a Path
     // has path "foo?bar" where in a straight URI the path part is just "foo"
     assertEquals("/foo?bar",
@@ -350,7 +362,8 @@ public class TestPath {
   }
 
   /** Test reserved characters in URIs (and therefore Paths) */
-  @Test (timeout = 30000)
+  @Test
+  @Timeout(value = 30)
   public void testReservedCharacters() throws URISyntaxException, IOException {
     // URI encodes the path
     assertEquals("/foo%20bar",
@@ -380,7 +393,8 @@ public class TestPath {
                 toURL().getPath());
   }
 
-  @Test (timeout = 30000)
+  @Test
+  @Timeout(value = 30)
   public void testMakeQualified() throws URISyntaxException {
     URI defaultUri = new URI("hdfs://host1/dir1");
     URI wd         = new URI("hdfs://host2/dir2");
@@ -394,7 +408,8 @@ public class TestPath {
                  new Path("file").makeQualified(defaultUri, new Path(wd)));
  }
 
-  @Test (timeout = 30000)
+  @Test
+  @Timeout(value = 30)
   public void testGetName() {
     assertEquals("", new Path("/").getName());
     assertEquals("foo", new Path("foo").getName());
@@ -404,7 +419,8 @@ public class TestPath {
     assertEquals("bar", new Path("hdfs://host/foo/bar").getName());
   }
   
-  @Test (timeout = 30000)
+  @Test
+  @Timeout(value = 30)
   public void testAvroReflect() throws Exception {
     // Avro expects explicitely stated, trusted packages used for (de-)serialization
     System.setProperty(ConfigConstants.CONFIG_AVRO_SERIALIZABLE_PACKAGES, "org.apache.hadoop.fs");
@@ -413,7 +429,8 @@ public class TestPath {
        "{\"type\":\"string\",\"java-class\":\"org.apache.hadoop.fs.Path\"}");
   }
 
-  @Test (timeout = 30000)
+  @Test
+  @Timeout(value = 30)
   public void testGlobEscapeStatus() throws Exception {
     // This test is not meaningful on Windows where * is disallowed in file name.
     assumeNotWindows();
@@ -472,7 +489,8 @@ public class TestPath {
     assertEquals(new Path(testRoot, "*/f"), stats[0].getPath());
   }
 
-  @Test (timeout = 30000)
+  @Test
+  @Timeout(value = 30)
   public void testMergePaths() {
     assertEquals(new Path("/foo/bar"),
       Path.mergePaths(new Path("/foo"),
@@ -506,7 +524,8 @@ public class TestPath {
         new Path("file://fileauthority/bar")));
   }
 
-  @Test (timeout = 30000)
+  @Test
+  @Timeout(value = 30)
   public void testIsWindowsAbsolutePath() {
     assumeWindows();
     assertTrue(Path.isWindowsAbsolutePath("C:\\test", false));
@@ -518,7 +537,8 @@ public class TestPath {
     assertFalse(Path.isWindowsAbsolutePath("/C:test", true));
   }
 
-  @Test(timeout = 30000)
+  @Test
+  @Timeout(value = 30)
   public void testSerDeser() throws Throwable {
     Path source = new Path("hdfs://localhost:4040/scratch");
     ByteArrayOutputStream baos = new ByteArrayOutputStream(256);
@@ -528,15 +548,16 @@ public class TestPath {
     ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
     try (ObjectInputStream ois = new ObjectInputStream(bais)) {
       Path deser = (Path) ois.readObject();
-      Assert.assertEquals(source, deser);
+      assertEquals(source, deser);
     }
 
   }
 
-  @Test(timeout = 30000)
+  @Test
+  @Timeout(value = 30)
   public void testSuffixFromRoot() {
     Path root = new Path("/");
-    Assert.assertNull(root.getParent());
-    Assert.assertEquals(new Path("/bar"), root.suffix("bar"));
+    assertNull(root.getParent());
+    assertEquals(new Path("/bar"), root.suffix("bar"));
   }
 }

+ 21 - 15
hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestStat.java

@@ -17,19 +17,20 @@
  */
 package org.apache.hadoop.fs;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.fail;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.fail;
+import static org.junit.jupiter.api.Assumptions.assumeTrue;
 
 import java.io.BufferedReader;
 import java.io.FileNotFoundException;
 import java.io.StringReader;
 
 import org.apache.hadoop.conf.Configuration;
-import org.junit.Assume;
-import org.junit.BeforeClass;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.Timeout;
 
 public class TestStat extends FileSystemTestHelper {
   static {
@@ -37,7 +38,7 @@ public class TestStat extends FileSystemTestHelper {
   }
   private static Stat stat;
 
-  @BeforeClass
+  @BeforeAll
   public static void setup() throws Exception {
     stat = new Stat(new Path("/dummypath"),
         4096l, false, FileSystem.get(new Configuration()));
@@ -95,7 +96,8 @@ public class TestStat extends FileSystemTestHelper {
     }
   }
 
-  @Test(timeout=10000)
+  @Test
+  @Timeout(value = 10)
   public void testStatLinux() throws Exception {
     String[] symlinks = new String[] {
         "6,symbolic link,1373584236,1373584236,777,andrew,andrew,`link' -> `target'",
@@ -110,7 +112,8 @@ public class TestStat extends FileSystemTestHelper {
     linux.test();
   }
 
-  @Test(timeout=10000)
+  @Test
+  @Timeout(value = 10)
   public void testStatFreeBSD() throws Exception {
     String[] symlinks = new String[] {
         "6,Symbolic Link,1373508941,1373508941,120755,awang,awang,`link' -> `target'"
@@ -125,9 +128,10 @@ public class TestStat extends FileSystemTestHelper {
     freebsd.test();
   }
 
-  @Test(timeout=10000)
+  @Test
+  @Timeout(value = 10)
   public void testStatFileNotFound() throws Exception {
-    Assume.assumeTrue(Stat.isAvailable());
+    assumeTrue(Stat.isAvailable());
     try {
       stat.getFileStatus();
       fail("Expected FileNotFoundException");
@@ -136,14 +140,16 @@ public class TestStat extends FileSystemTestHelper {
     }
   }
 
-  @Test(timeout=10000)
+  @Test
+  @Timeout(value = 10)
   public void testStatEnvironment() throws Exception {
     assertEquals("C", stat.getEnvironment("LANG"));
   }
 
-  @Test(timeout=10000)
+  @Test
+  @Timeout(value = 10)
   public void testStat() throws Exception {
-    Assume.assumeTrue(Stat.isAvailable());
+    assumeTrue(Stat.isAvailable());
     FileSystem fs = FileSystem.getLocal(new Configuration());
     Path testDir = new Path(getTestRootPath(fs), "teststat");
     fs.mkdirs(testDir);

+ 3 - 2
hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/contract/AbstractFSContract.java

@@ -18,11 +18,12 @@
 
 package org.apache.hadoop.fs.contract;
 
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.conf.Configured;
 import org.apache.hadoop.fs.FileSystem;
 import org.apache.hadoop.fs.Path;
-import org.junit.Assert;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -84,7 +85,7 @@ public abstract class AbstractFSContract extends Configured {
    */
   protected void addConfResource(String resource) {
     boolean found = maybeAddConfResource(resource);
-    Assert.assertTrue("Resource not found " + resource, found);
+    assertTrue(found, "Resource not found " + resource);
   }
 
   /**

+ 57 - 63
hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/contract/ContractTestUtils.java

@@ -36,8 +36,7 @@ import org.apache.hadoop.io.IOUtils;
 import org.apache.hadoop.util.functional.RemoteIterators;
 import org.apache.hadoop.util.functional.FutureIO;
 
-import org.assertj.core.api.Assertions;
-import org.junit.Assert;
+import org.junit.jupiter.api.Assertions;
 import org.junit.AssumptionViolatedException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -66,11 +65,12 @@ import java.util.concurrent.TimeoutException;
 import static org.apache.hadoop.fs.CommonConfigurationKeysPublic.IO_FILE_BUFFER_SIZE_DEFAULT;
 import static org.apache.hadoop.fs.CommonConfigurationKeysPublic.IO_FILE_BUFFER_SIZE_KEY;
 import static org.apache.hadoop.util.functional.RemoteIterators.foreach;
+import static org.assertj.core.api.Assertions.assertThat;
 
 /**
  * Utilities used across test cases.
  */
-public class ContractTestUtils extends Assert {
+public class ContractTestUtils extends Assertions {
 
   private static final Logger LOG =
       LoggerFactory.getLogger(ContractTestUtils.class);
@@ -99,11 +99,9 @@ public class ContractTestUtils extends Assert {
                                           String expected) {
     String val = props.getProperty(key);
     if (expected == null) {
-      assertNull("Non null property " + key + " = " + val, val);
+      assertNull(val, "Non null property " + key + " = " + val);
     } else {
-      assertEquals("property " + key + " = " + val,
-                          expected,
-                          val);
+      assertEquals(expected, val, "property " + key + " = " + val);
     }
   }
 
@@ -147,7 +145,7 @@ public class ContractTestUtils extends Assert {
     if (delete) {
       rejectRootOperation(path);
       boolean deleted = fs.delete(path, false);
-      assertTrue("Deleted", deleted);
+      assertTrue(deleted, "Deleted");
       assertPathDoesNotExist(fs, "Cleanup failed", path);
     }
   }
@@ -187,9 +185,8 @@ public class ContractTestUtils extends Assert {
   public static void writeDataset(FileSystem fs, Path path, byte[] src,
       int len, int buffersize, boolean overwrite, boolean useBuilder)
       throws IOException {
-    assertTrue(
-      "Not enough data in source array to write " + len + " bytes",
-      src.length >= len);
+    assertTrue(src.length >= len,
+        "Not enough data in source array to write " + len + " bytes");
     FSDataOutputStream out;
     if (useBuilder) {
       out = fs.createFile(path)
@@ -308,7 +305,7 @@ public class ContractTestUtils extends Assert {
     FileStatus stat = fs.getFileStatus(path);
     assertIsFile(path, stat);
     String statText = stat.toString();
-    assertEquals("wrong length " + statText, original.length, stat.getLen());
+    assertEquals(original.length, stat.getLen(), "wrong length " + statText);
     byte[] bytes = readDataset(fs, path, original.length);
     compareByteArrays(original, bytes, original.length);
   }
@@ -343,8 +340,8 @@ public class ContractTestUtils extends Assert {
   public static void compareByteArrays(byte[] original,
                                        byte[] received,
                                        int len) {
-    assertEquals("Number of bytes read != number written",
-                        len, received.length);
+    assertEquals(len, received.length,
+        "Number of bytes read != number written");
     int errors = 0;
     int firstErrorByte = -1;
     for (int i = 0; i < len; i++) {
@@ -488,8 +485,8 @@ public class ContractTestUtils extends Assert {
   public static void rename(FileSystem fileSystem, Path src, Path dst)
       throws IOException {
     rejectRootOperation(src, false);
-    assertTrue("rename(" + src + ", " + dst + ") failed",
-        fileSystem.rename(src, dst));
+    assertTrue(fileSystem.rename(src, dst),
+        "rename(" + src + ", " + dst + ") failed");
     assertPathDoesNotExist(fileSystem, "renamed source dir", src);
   }
 
@@ -602,7 +599,7 @@ public class ContractTestUtils extends Assert {
    * @param thrown a (possibly null) throwable to init the cause with
    * @throws AssertionError with the text and throwable -always
    */
-  public static void fail(String text, Throwable thrown) {
+  public static Object fail(String text, Throwable thrown) {
     throw new AssertionError(text, thrown);
   }
 
@@ -616,10 +613,8 @@ public class ContractTestUtils extends Assert {
   public static void assertFileHasLength(FileSystem fs, Path path,
                                          int expected) throws IOException {
     FileStatus status = fs.getFileStatus(path);
-    assertEquals(
-        "Wrong file length of file " + path + " status: " + status,
-        expected,
-        status.getLen());
+    assertEquals(expected, status.getLen(),
+        "Wrong file length of file " + path + " status: " + status);
   }
 
   /**
@@ -640,8 +635,8 @@ public class ContractTestUtils extends Assert {
    * @param fileStatus stats to check
    */
   public static void assertIsDirectory(FileStatus fileStatus) {
-    assertTrue("Should be a directory -but isn't: " + fileStatus,
-               fileStatus.isDirectory());
+    assertTrue(fileStatus.isDirectory(),
+        "Should be a directory -but isn't: " + fileStatus);
   }
 
   /**
@@ -654,7 +649,7 @@ public class ContractTestUtils extends Assert {
   public static void assertErasureCoded(final FileSystem fs, final Path path)
       throws IOException {
     FileStatus fileStatus = fs.getFileStatus(path);
-    assertTrue(path + " must be erasure coded!", fileStatus.isErasureCoded());
+    assertTrue(fileStatus.isErasureCoded(), path + " must be erasure coded!");
   }
 
   /**
@@ -667,8 +662,8 @@ public class ContractTestUtils extends Assert {
   public static void assertNotErasureCoded(final FileSystem fs,
       final Path path) throws IOException {
     FileStatus fileStatus = fs.getFileStatus(path);
-    assertFalse(path + " should not be erasure coded!",
-        fileStatus.isErasureCoded());
+    assertFalse(fileStatus.isErasureCoded(),
+        path + " should not be erasure coded!");
   }
 
   /**
@@ -817,7 +812,7 @@ public class ContractTestUtils extends Assert {
     boolean deleted = fs.delete(file, recursive);
     if (!deleted) {
       String dir = ls(fs, file.getParent());
-      assertTrue("Delete failed on " + file + ": " + dir, deleted);
+      assertTrue(deleted, "Delete failed on " + file + ": " + dir);
     }
     assertPathDoesNotExist(fs, "Deleted file", file);
   }
@@ -967,10 +962,10 @@ public class ContractTestUtils extends Assert {
    */
   public static void assertIsFile(Path filename, FileStatus status) {
     String fileInfo = filename + "  " + status;
-    assertFalse("File claims to be a directory " + fileInfo,
-                status.isDirectory());
-    assertFalse("File claims to be a symlink " + fileInfo,
-                       status.isSymlink());
+    assertFalse(status.isDirectory(),
+        "File claims to be a directory " + fileInfo);
+    assertFalse(status.isSymlink(),
+        "File claims to be a symlink " + fileInfo);
   }
 
   /**
@@ -1135,9 +1130,8 @@ public class ContractTestUtils extends Assert {
         found = true;
       }
     }
-    assertTrue("Path " + subdir
-                      + " not found in directory " + dir + ":" + builder,
-                      found);
+    assertTrue(found,
+        "Path " + subdir + " not found in directory " + dir + ":" + builder);
   }
 
   /**
@@ -1149,7 +1143,7 @@ public class ContractTestUtils extends Assert {
    * @throws IOException IO Problem
    */
   public static void assertMkdirs(FileSystem fs, Path dir) throws IOException {
-    assertTrue("mkdirs(" + dir + ") returned false", fs.mkdirs(dir));
+    assertTrue(fs.mkdirs(dir), "mkdirs(" + dir + ") returned false");
   }
 
   /**
@@ -1180,8 +1174,8 @@ public class ContractTestUtils extends Assert {
         break;
       }
     }
-    assertFalse("File content of file is not as expected at offset " + idx,
-                mismatch);
+    assertFalse(mismatch,
+        "File content of file is not as expected at offset " + idx);
   }
 
   /**
@@ -1256,7 +1250,7 @@ public class ContractTestUtils extends Assert {
       int o = readOffset + i;
       final byte orig = originalData[o];
       final byte current = data.get();
-      Assertions.assertThat(current)
+      assertThat(current)
           .describedAs("%s with read offset %d: data[0x%02X] != DATASET[0x%02X]",
                       operation, o, i, current)
           .isEqualTo(orig);
@@ -1716,23 +1710,23 @@ public class ContractTestUtils extends Assert {
   public static void assertCapabilities(
       Object stream, String[] shouldHaveCapabilities,
       String[] shouldNotHaveCapabilities) {
-    assertTrue("Stream should be instanceof StreamCapabilities",
-        stream instanceof StreamCapabilities);
+    assertTrue(stream instanceof StreamCapabilities,
+        "Stream should be instanceof StreamCapabilities");
 
     StreamCapabilities source = (StreamCapabilities) stream;
     if (shouldHaveCapabilities != null) {
       for (String shouldHaveCapability : shouldHaveCapabilities) {
-        assertTrue("Should have capability: " + shouldHaveCapability
-                + " in " + source,
-            source.hasCapability(shouldHaveCapability));
+        assertTrue(source.hasCapability(shouldHaveCapability),
+            "Should have capability: " + shouldHaveCapability
+            + " in " + source);
       }
     }
 
     if (shouldNotHaveCapabilities != null) {
       for (String shouldNotHaveCapability : shouldNotHaveCapabilities) {
-        assertFalse("Should not have capability: " + shouldNotHaveCapability
-                + " in " + source,
-            source.hasCapability(shouldNotHaveCapability));
+        assertFalse(source.hasCapability(shouldNotHaveCapability),
+            "Should not have capability: " + shouldNotHaveCapability
+            + " in " + source);
       }
     }
   }
@@ -1778,10 +1772,10 @@ public class ContractTestUtils extends Assert {
       final String...capabilities) throws IOException {
 
     for (String shouldHaveCapability: capabilities) {
-      assertTrue("Should have capability: " + shouldHaveCapability
-              + " under " + path
-              + " in " + source,
-          source.hasPathCapability(path, shouldHaveCapability));
+      assertTrue(source.hasPathCapability(path, shouldHaveCapability),
+          "Should have capability: " + shouldHaveCapability
+          + " under " + path
+          + " in " + source);
     }
   }
 
@@ -1799,9 +1793,9 @@ public class ContractTestUtils extends Assert {
       final String...capabilities) throws IOException {
 
     for (String shouldHaveCapability: capabilities) {
-      assertFalse("Path  must not support capability: " + shouldHaveCapability
-              + " under " + path,
-          source.hasPathCapability(path, shouldHaveCapability));
+      assertFalse(source.hasPathCapability(path, shouldHaveCapability),
+          "Path  must not support capability: " + shouldHaveCapability
+          + " under " + path);
     }
   }
 
@@ -1913,7 +1907,7 @@ public class ContractTestUtils extends Assert {
      * @param stats statistics array. Must not be null.
      */
     public TreeScanResults(FileStatus[] stats) {
-      assertNotNull("Null file status array", stats);
+      assertNotNull(stats, "Null file status array");
       for (FileStatus stat : stats) {
         add(stat);
       }
@@ -2025,12 +2019,12 @@ public class ContractTestUtils extends Assert {
      */
     public void assertSizeEquals(String text, long f, long d, long o) {
       String self = dump();
-      Assert.assertEquals(text + ": file count in " + self,
-          f, getFileCount());
-      Assert.assertEquals(text + ": directory count in " + self,
-          d, getDirCount());
-      Assert.assertEquals(text + ": 'other' count in " + self,
-          o, getOtherCount());
+      assertEquals(f, getFileCount(),
+          text + ": file count in " + self);
+      assertEquals(d, getDirCount(),
+          text + ": directory count in " + self);
+      assertEquals(o, getOtherCount(),
+          text + ": 'other' count in " + self);
     }
 
     /**
@@ -2055,13 +2049,13 @@ public class ContractTestUtils extends Assert {
     public void assertFieldsEquivalent(String fieldname,
         TreeScanResults that,
         List<Path> ours, List<Path> theirs) {
-      Assertions.assertThat(ours).
+      assertThat(ours).
           describedAs("list of %s", fieldname)
           .doesNotHaveDuplicates();
-      Assertions.assertThat(theirs).
+      assertThat(theirs).
           describedAs("list of %s in %s", fieldname, that)
           .doesNotHaveDuplicates();
-      Assertions.assertThat(ours)
+      assertThat(ours)
           .describedAs("Elements of %s", fieldname)
           .containsExactlyInAnyOrderElementsOf(theirs);
 

+ 2 - 2
hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/contract/ftp/FTPContract.java

@@ -25,7 +25,7 @@ import org.apache.hadoop.fs.contract.AbstractBondedFSContract;
 
 import java.net.URI;
 
-import static org.junit.Assert.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
 
 /**
  * The contract of FTP; requires the option "test.testdir" to be set
@@ -55,7 +55,7 @@ public class FTPContract extends AbstractBondedFSContract {
   @Override
   public Path getTestPath() {
     String pathString = getOption(TEST_FS_TESTDIR, null);
-    assertNotNull("Undefined test option " + TEST_FS_TESTDIR, pathString);
+    assertNotNull(pathString, "Undefined test option " + TEST_FS_TESTDIR);
     Path path = new Path(pathString);
     return path;
   }

+ 6 - 6
hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/contract/rawlocal/TestRawLocalContractUnderlyingFileBehavior.java

@@ -20,17 +20,17 @@ package org.apache.hadoop.fs.contract.rawlocal;
 
 import org.apache.hadoop.conf.Configuration;
 
-import org.junit.Assert;
-import org.junit.BeforeClass;
-import org.junit.Test;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
 
 import java.io.File;
 
-public class TestRawLocalContractUnderlyingFileBehavior extends Assert {
+public class TestRawLocalContractUnderlyingFileBehavior extends Assertions {
 
   private static File testDirectory;
 
-  @BeforeClass
+  @BeforeAll
   public static void before() {
     RawlocalFSContract contract =
       new RawlocalFSContract(new Configuration());
@@ -44,6 +44,6 @@ public class TestRawLocalContractUnderlyingFileBehavior extends Assert {
   public void testDeleteEmptyPath() throws Throwable {
     File nonexistent = new File(testDirectory, "testDeleteEmptyPath");
     assertFalse(nonexistent.exists());
-    assertFalse("nonexistent.delete() returned true", nonexistent.delete());
+    assertFalse(nonexistent.delete(), "nonexistent.delete() returned true");
   }
 }

+ 20 - 23
hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/shell/TestTextCommand.java

@@ -19,6 +19,7 @@
 package org.apache.hadoop.fs.shell;
 
 import static org.apache.hadoop.fs.CommonConfigurationKeysPublic.IO_FILE_BUFFER_SIZE_KEY;
+import static org.assertj.core.api.Assertions.assertThat;
 import static org.junit.jupiter.api.Assertions.assertThrows;
 
 import java.io.File;
@@ -35,15 +36,14 @@ import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.fs.Path;
 import org.apache.hadoop.io.SequenceFile;
 import org.apache.hadoop.test.GenericTestUtils;
-import org.assertj.core.api.Assertions;
-import org.junit.Rule;
 import org.junit.jupiter.api.Test;
-import org.junit.rules.Timeout;
+import org.junit.jupiter.api.Timeout;
 
 /**
  * This class tests the logic for displaying the binary formats supported
  * by the Text command.
  */
+@Timeout(30)
 public class TestTextCommand {
   private static final File TEST_ROOT_DIR =
       GenericTestUtils.getTestDir("testText");
@@ -66,9 +66,6 @@ public class TestTextCommand {
   private static final String SEQUENCE_FILE_EXPECTED_OUTPUT =
       "Key1\tValue1\nKey2\tValue2\n";
 
-  @Rule
-  public final Timeout testTimeout = new Timeout(30000);
-
   /**
    * Tests whether binary Avro data files are displayed correctly.
    */
@@ -76,7 +73,7 @@ public class TestTextCommand {
   public void testDisplayForAvroFiles() throws Exception {
     String output = readUsingTextCommand(AVRO_FILENAME,
                                          generateWeatherAvroBinaryData());
-    Assertions.assertThat(output).describedAs("output").isEqualTo(AVRO_EXPECTED_OUTPUT);
+    assertThat(output).describedAs("output").isEqualTo(AVRO_EXPECTED_OUTPUT);
   }
 
   @Test
@@ -86,14 +83,14 @@ public class TestTextCommand {
     createFile(AVRO_FILENAME, generateWeatherAvroBinaryData());
     URI uri = new URI(AVRO_FILENAME);
     String output = readUsingTextCommand(uri, conf);
-    Assertions.assertThat(output).describedAs("output").isEqualTo(AVRO_EXPECTED_OUTPUT);
+    assertThat(output).describedAs("output").isEqualTo(AVRO_EXPECTED_OUTPUT);
   }
 
   @Test
   public void testEmptyAvroFile() throws Exception {
     String output = readUsingTextCommand(AVRO_FILENAME,
                                          generateEmptyAvroBinaryData());
-    Assertions.assertThat(output).describedAs("output").isEmpty();
+    assertThat(output).describedAs("output").isEmpty();
   }
 
   @Test
@@ -138,7 +135,7 @@ public class TestTextCommand {
     URI uri = new URI(AVRO_FILENAME);
     Configuration conf = new Configuration();
     try (InputStream is = getInputStream(uri, conf)) {
-      Assertions.assertThat(is.read(new byte[10], 0, 0)).describedAs("bytes read").isEqualTo(0);
+      assertThat(is.read(new byte[10], 0, 0)).describedAs("bytes read").isEqualTo(0);
     }
   }
 
@@ -149,8 +146,8 @@ public class TestTextCommand {
     Configuration conf = new Configuration();
     try (InputStream is = getInputStream(uri, conf)) {
       inputStreamToString(is);
-      Assertions.assertThat(is.read()).describedAs("single byte EOF").isEqualTo(-1);
-      Assertions.assertThat(is.read(new byte[10], 0, 10)).describedAs("multi byte EOF")
+      assertThat(is.read()).describedAs("single byte EOF").isEqualTo(-1);
+      assertThat(is.read(new byte[10], 0, 10)).describedAs("multi byte EOF")
               .isEqualTo(-1);
     }
   }
@@ -164,7 +161,7 @@ public class TestTextCommand {
         InputStream is2 = getInputStream(uri, conf)) {
       String multiByteReads = inputStreamToString(is1);
       String singleByteReads = inputStreamSingleByteReadsToString(is2);
-      Assertions.assertThat(multiByteReads)
+      assertThat(multiByteReads)
           .describedAs("same bytes read from multi and single byte reads")
           .isEqualTo(singleByteReads);
     }
@@ -177,7 +174,7 @@ public class TestTextCommand {
   public void testEmptyTextFile() throws Exception {
     byte[] emptyContents = {};
     String output = readUsingTextCommand(TEXT_FILENAME, emptyContents);
-    Assertions.assertThat(output).describedAs("output").isEmpty();
+    assertThat(output).describedAs("output").isEmpty();
   }
 
   /**
@@ -188,7 +185,7 @@ public class TestTextCommand {
     byte[] oneByteContents = {'x'};
     String output = readUsingTextCommand(TEXT_FILENAME, oneByteContents);
     String expected = new String(oneByteContents, StandardCharsets.UTF_8);
-    Assertions.assertThat(output).describedAs("output").isEqualTo(expected);
+    assertThat(output).describedAs("output").isEqualTo(expected);
   }
 
   /**
@@ -199,7 +196,7 @@ public class TestTextCommand {
     byte[] twoByteContents = {'x', 'y'};
     String output = readUsingTextCommand(TEXT_FILENAME, twoByteContents);
     String expected = new String(twoByteContents, StandardCharsets.UTF_8);
-    Assertions.assertThat(output).describedAs("output").isEqualTo(expected);
+    assertThat(output).describedAs("output").isEqualTo(expected);
   }
 
   @Test
@@ -208,7 +205,7 @@ public class TestTextCommand {
     createNonWritableSequenceFile(SEQUENCE_FILENAME, conf);
     URI uri = new URI(SEQUENCE_FILENAME);
     String output = readUsingTextCommand(uri, conf);
-    Assertions.assertThat(output).describedAs("output").isEqualTo(SEQUENCE_FILE_EXPECTED_OUTPUT);
+    assertThat(output).describedAs("output").isEqualTo(SEQUENCE_FILE_EXPECTED_OUTPUT);
   }
 
   @Test
@@ -218,7 +215,7 @@ public class TestTextCommand {
     createNonWritableSequenceFile(SEQUENCE_FILENAME, conf);
     URI uri = new URI(SEQUENCE_FILENAME);
     String output = readUsingTextCommand(uri, conf);
-    Assertions.assertThat(output).describedAs("output").isEqualTo(SEQUENCE_FILE_EXPECTED_OUTPUT);
+    assertThat(output).describedAs("output").isEqualTo(SEQUENCE_FILE_EXPECTED_OUTPUT);
   }
 
   @Test
@@ -227,7 +224,7 @@ public class TestTextCommand {
     createEmptySequenceFile(SEQUENCE_FILENAME, conf);
     URI uri = new URI(SEQUENCE_FILENAME);
     String output = readUsingTextCommand(uri, conf);
-    Assertions.assertThat(output).describedAs("output").isEmpty();
+    assertThat(output).describedAs("output").isEmpty();
   }
 
   @Test
@@ -272,7 +269,7 @@ public class TestTextCommand {
     createNonWritableSequenceFile(SEQUENCE_FILENAME, conf);
     URI uri = new URI(SEQUENCE_FILENAME);
     try (InputStream is = getInputStream(uri, conf)) {
-      Assertions.assertThat(is.read(new byte[10], 0, 0)).describedAs("bytes read").isEqualTo(0);
+      assertThat(is.read(new byte[10], 0, 0)).describedAs("bytes read").isEqualTo(0);
     }
   }
 
@@ -283,8 +280,8 @@ public class TestTextCommand {
     URI uri = new URI(SEQUENCE_FILENAME);
     try (InputStream is = getInputStream(uri, conf)) {
       inputStreamToString(is);
-      Assertions.assertThat(is.read()).describedAs("single byte EOF").isEqualTo(-1);
-      Assertions.assertThat(is.read(new byte[10], 0, 10)).describedAs("multi byte EOF")
+      assertThat(is.read()).describedAs("single byte EOF").isEqualTo(-1);
+      assertThat(is.read(new byte[10], 0, 10)).describedAs("multi byte EOF")
               .isEqualTo(-1);
     }
   }
@@ -298,7 +295,7 @@ public class TestTextCommand {
         InputStream is2 = getInputStream(uri, conf)) {
       String multiByteReads = inputStreamToString(is1);
       String singleByteReads = inputStreamSingleByteReadsToString(is2);
-      Assertions.assertThat(multiByteReads)
+      assertThat(multiByteReads)
           .describedAs("same bytes read from multi and single byte reads")
           .isEqualTo(singleByteReads);
     }

+ 95 - 76
hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/viewfs/TestChRootedFileSystem.java

@@ -17,6 +17,17 @@
  */
 package org.apache.hadoop.fs.viewfs;
 
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.Mockito.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+import static org.mockito.Mockito.reset;
+
 import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.net.URI;
@@ -33,11 +44,10 @@ import org.apache.hadoop.fs.FilterFileSystem;
 import org.apache.hadoop.fs.FsConstants;
 import org.apache.hadoop.fs.Path;
 import org.apache.hadoop.fs.permission.AclEntry;
-import org.junit.After;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-import static org.mockito.Mockito.*;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.Timeout;
 
 public class TestChRootedFileSystem {
   FileSystem fSys; // The ChRoootedFs
@@ -45,7 +55,7 @@ public class TestChRootedFileSystem {
   Path chrootedTo;
   FileSystemTestHelper fileSystemTestHelper;
   
-  @Before
+  @BeforeEach
   public void setUp() throws Exception {
     // create the test root on local_fs
     Configuration conf = new Configuration();
@@ -62,7 +72,7 @@ public class TestChRootedFileSystem {
     fSys = new ChRootedFileSystem(chrootedTo.toUri(), conf);
   }
 
-  @After
+  @AfterEach
   public void tearDown() throws Exception {
     fSysTarget.delete(chrootedTo, true);
   }
@@ -70,17 +80,17 @@ public class TestChRootedFileSystem {
   @Test
   public void testURI() {
     URI uri = fSys.getUri();
-    Assert.assertEquals(chrootedTo.toUri(), uri);
+    assertEquals(chrootedTo.toUri(), uri);
   }
   
   @Test
   public void testBasicPaths() {
     URI uri = fSys.getUri();
-    Assert.assertEquals(chrootedTo.toUri(), uri);
-    Assert.assertEquals(fSys.makeQualified(
+    assertEquals(chrootedTo.toUri(), uri);
+    assertEquals(fSys.makeQualified(
         new Path(System.getProperty("user.home"))),
         fSys.getWorkingDirectory());
-    Assert.assertEquals(fSys.makeQualified(
+    assertEquals(fSys.makeQualified(
         new Path(System.getProperty("user.home"))),
         fSys.getHomeDirectory());
     /*
@@ -90,13 +100,13 @@ public class TestChRootedFileSystem {
      * But if we were to fix Path#makeQualified() then  the next test should
      *  have been:
 
-    Assert.assertEquals(
+    assertEquals(
         new Path(chrootedTo + "/foo/bar").makeQualified(
             FsConstants.LOCAL_FS_URI, null),
         fSys.makeQualified(new Path( "/foo/bar")));
     */
     
-    Assert.assertEquals(
+    assertEquals(
         new Path("/foo/bar").makeQualified(FsConstants.LOCAL_FS_URI, null),
         fSys.makeQualified(new Path("/foo/bar")));
   }
@@ -113,50 +123,50 @@ public class TestChRootedFileSystem {
 
     // Create file 
     fileSystemTestHelper.createFile(fSys, "/foo");
-    Assert.assertTrue(fSys.isFile(new Path("/foo")));
-    Assert.assertTrue(fSysTarget.isFile(new Path(chrootedTo, "foo")));
+    assertTrue(fSys.isFile(new Path("/foo")));
+    assertTrue(fSysTarget.isFile(new Path(chrootedTo, "foo")));
     
     // Create file with recursive dir
     fileSystemTestHelper.createFile(fSys, "/newDir/foo");
-    Assert.assertTrue(fSys.isFile(new Path("/newDir/foo")));
-    Assert.assertTrue(fSysTarget.isFile(new Path(chrootedTo,"newDir/foo")));
+    assertTrue(fSys.isFile(new Path("/newDir/foo")));
+    assertTrue(fSysTarget.isFile(new Path(chrootedTo, "newDir/foo")));
     
     // Delete the created file
-    Assert.assertTrue(fSys.delete(new Path("/newDir/foo"), false));
-    Assert.assertFalse(fSys.exists(new Path("/newDir/foo")));
-    Assert.assertFalse(fSysTarget.exists(new Path(chrootedTo, "newDir/foo")));
+    assertTrue(fSys.delete(new Path("/newDir/foo"), false));
+    assertFalse(fSys.exists(new Path("/newDir/foo")));
+    assertFalse(fSysTarget.exists(new Path(chrootedTo, "newDir/foo")));
     
     // Create file with a 2 component dirs recursively
     fileSystemTestHelper.createFile(fSys, "/newDir/newDir2/foo");
-    Assert.assertTrue(fSys.isFile(new Path("/newDir/newDir2/foo")));
-    Assert.assertTrue(fSysTarget.isFile(new Path(chrootedTo,"newDir/newDir2/foo")));
+    assertTrue(fSys.isFile(new Path("/newDir/newDir2/foo")));
+    assertTrue(fSysTarget.isFile(new Path(chrootedTo, "newDir/newDir2/foo")));
     
     // Delete the created file
-    Assert.assertTrue(fSys.delete(new Path("/newDir/newDir2/foo"), false));
-    Assert.assertFalse(fSys.exists(new Path("/newDir/newDir2/foo")));
-    Assert.assertFalse(fSysTarget.exists(new Path(chrootedTo,"newDir/newDir2/foo")));
+    assertTrue(fSys.delete(new Path("/newDir/newDir2/foo"), false));
+    assertFalse(fSys.exists(new Path("/newDir/newDir2/foo")));
+    assertFalse(fSysTarget.exists(new Path(chrootedTo, "newDir/newDir2/foo")));
   }
   
   
   @Test
   public void testMkdirDelete() throws IOException {
     fSys.mkdirs(fileSystemTestHelper.getTestRootPath(fSys, "/dirX"));
-    Assert.assertTrue(fSys.isDirectory(new Path("/dirX")));
-    Assert.assertTrue(fSysTarget.isDirectory(new Path(chrootedTo,"dirX")));
+    assertTrue(fSys.isDirectory(new Path("/dirX")));
+    assertTrue(fSysTarget.isDirectory(new Path(chrootedTo, "dirX")));
     
     fSys.mkdirs(fileSystemTestHelper.getTestRootPath(fSys, "/dirX/dirY"));
-    Assert.assertTrue(fSys.isDirectory(new Path("/dirX/dirY")));
-    Assert.assertTrue(fSysTarget.isDirectory(new Path(chrootedTo,"dirX/dirY")));
+    assertTrue(fSys.isDirectory(new Path("/dirX/dirY")));
+    assertTrue(fSysTarget.isDirectory(new Path(chrootedTo, "dirX/dirY")));
     
 
     // Delete the created dir
-    Assert.assertTrue(fSys.delete(new Path("/dirX/dirY"), false));
-    Assert.assertFalse(fSys.exists(new Path("/dirX/dirY")));
-    Assert.assertFalse(fSysTarget.exists(new Path(chrootedTo,"dirX/dirY")));
+    assertTrue(fSys.delete(new Path("/dirX/dirY"), false));
+    assertFalse(fSys.exists(new Path("/dirX/dirY")));
+    assertFalse(fSysTarget.exists(new Path(chrootedTo, "dirX/dirY")));
     
-    Assert.assertTrue(fSys.delete(new Path("/dirX"), false));
-    Assert.assertFalse(fSys.exists(new Path("/dirX")));
-    Assert.assertFalse(fSysTarget.exists(new Path(chrootedTo,"dirX")));
+    assertTrue(fSys.delete(new Path("/dirX"), false));
+    assertFalse(fSys.exists(new Path("/dirX")));
+    assertFalse(fSysTarget.exists(new Path(chrootedTo, "dirX")));
     
   }
   @Test
@@ -164,19 +174,19 @@ public class TestChRootedFileSystem {
     // Rename a file
     fileSystemTestHelper.createFile(fSys, "/newDir/foo");
     fSys.rename(new Path("/newDir/foo"), new Path("/newDir/fooBar"));
-    Assert.assertFalse(fSys.exists(new Path("/newDir/foo")));
-    Assert.assertFalse(fSysTarget.exists(new Path(chrootedTo,"newDir/foo")));
-    Assert.assertTrue(fSys.isFile(fileSystemTestHelper.getTestRootPath(fSys,"/newDir/fooBar")));
-    Assert.assertTrue(fSysTarget.isFile(new Path(chrootedTo,"newDir/fooBar")));
+    assertFalse(fSys.exists(new Path("/newDir/foo")));
+    assertFalse(fSysTarget.exists(new Path(chrootedTo, "newDir/foo")));
+    assertTrue(fSys.isFile(fileSystemTestHelper.getTestRootPath(fSys, "/newDir/fooBar")));
+    assertTrue(fSysTarget.isFile(new Path(chrootedTo, "newDir/fooBar")));
     
     
     // Rename a dir
     fSys.mkdirs(new Path("/newDir/dirFoo"));
     fSys.rename(new Path("/newDir/dirFoo"), new Path("/newDir/dirFooBar"));
-    Assert.assertFalse(fSys.exists(new Path("/newDir/dirFoo")));
-    Assert.assertFalse(fSysTarget.exists(new Path(chrootedTo,"newDir/dirFoo")));
-    Assert.assertTrue(fSys.isDirectory(fileSystemTestHelper.getTestRootPath(fSys,"/newDir/dirFooBar")));
-    Assert.assertTrue(fSysTarget.isDirectory(new Path(chrootedTo,"newDir/dirFooBar")));
+    assertFalse(fSys.exists(new Path("/newDir/dirFoo")));
+    assertFalse(fSysTarget.exists(new Path(chrootedTo, "newDir/dirFoo")));
+    assertTrue(fSys.isDirectory(fileSystemTestHelper.getTestRootPath(fSys, "/newDir/dirFooBar")));
+    assertTrue(fSysTarget.isDirectory(new Path(chrootedTo, "newDir/dirFooBar")));
   }
 
   @Test
@@ -184,8 +194,8 @@ public class TestChRootedFileSystem {
     // GetContentSummary of a dir
     fSys.mkdirs(new Path("/newDir/dirFoo"));
     ContentSummary cs = fSys.getContentSummary(new Path("/newDir/dirFoo"));
-    Assert.assertEquals(-1L, cs.getQuota());
-    Assert.assertEquals(-1L, cs.getSpaceQuota());
+    assertEquals(-1L, cs.getQuota());
+    assertEquals(-1L, cs.getSpaceQuota());
   }
   
   /**
@@ -207,15 +217,15 @@ public class TestChRootedFileSystem {
   public void testList() throws IOException {
     
     FileStatus fs = fSys.getFileStatus(new Path("/"));
-    Assert.assertTrue(fs.isDirectory());
+    assertTrue(fs.isDirectory());
     //  should return the full path not the chrooted path
-    Assert.assertEquals(fs.getPath(), chrootedTo);
+    assertEquals(fs.getPath(), chrootedTo);
     
     // list on Slash
     
     FileStatus[] dirPaths = fSys.listStatus(new Path("/"));
 
-    Assert.assertEquals(0, dirPaths.length);
+    assertEquals(0, dirPaths.length);
     
     
 
@@ -226,21 +236,21 @@ public class TestChRootedFileSystem {
     fSys.mkdirs(new Path("/dirX/dirXX"));
     
     dirPaths = fSys.listStatus(new Path("/"));
-    Assert.assertEquals(4, dirPaths.length); // note 2 crc files
+    assertEquals(4, dirPaths.length); // note 2 crc files
     
     // Note the the file status paths are the full paths on target
     fs = FileSystemTestHelper.containsPath(new Path(chrootedTo, "foo"), dirPaths);
-      Assert.assertNotNull(fs);
-      Assert.assertTrue(fs.isFile());
+    assertNotNull(fs);
+    assertTrue(fs.isFile());
     fs = FileSystemTestHelper.containsPath(new Path(chrootedTo, "bar"), dirPaths);
-      Assert.assertNotNull(fs);
-      Assert.assertTrue(fs.isFile());
+    assertNotNull(fs);
+    assertTrue(fs.isFile());
     fs = FileSystemTestHelper.containsPath(new Path(chrootedTo, "dirX"), dirPaths);
-      Assert.assertNotNull(fs);
-      Assert.assertTrue(fs.isDirectory());
+    assertNotNull(fs);
+    assertTrue(fs.isDirectory());
     fs = FileSystemTestHelper.containsPath(new Path(chrootedTo, "dirY"), dirPaths);
-      Assert.assertNotNull(fs);
-      Assert.assertTrue(fs.isDirectory());
+    assertNotNull(fs);
+    assertTrue(fs.isDirectory());
   }
   
   @Test
@@ -250,31 +260,31 @@ public class TestChRootedFileSystem {
     fSys.mkdirs(new Path("/testWd"));
     Path workDir = new Path("/testWd");
     fSys.setWorkingDirectory(workDir);
-    Assert.assertEquals(workDir, fSys.getWorkingDirectory());
+    assertEquals(workDir, fSys.getWorkingDirectory());
 
     fSys.setWorkingDirectory(new Path("."));
-    Assert.assertEquals(workDir, fSys.getWorkingDirectory());
+    assertEquals(workDir, fSys.getWorkingDirectory());
 
     fSys.setWorkingDirectory(new Path(".."));
-    Assert.assertEquals(workDir.getParent(), fSys.getWorkingDirectory());
+    assertEquals(workDir.getParent(), fSys.getWorkingDirectory());
     
     // cd using a relative path
 
     // Go back to our test root
     workDir = new Path("/testWd");
     fSys.setWorkingDirectory(workDir);
-    Assert.assertEquals(workDir, fSys.getWorkingDirectory());
+    assertEquals(workDir, fSys.getWorkingDirectory());
     
     Path relativeDir = new Path("existingDir1");
     Path absoluteDir = new Path(workDir,"existingDir1");
     fSys.mkdirs(absoluteDir);
     fSys.setWorkingDirectory(relativeDir);
-    Assert.assertEquals(absoluteDir, fSys.getWorkingDirectory());
+    assertEquals(absoluteDir, fSys.getWorkingDirectory());
     // cd using a absolute path
     absoluteDir = new Path("/test/existingDir2");
     fSys.mkdirs(absoluteDir);
     fSys.setWorkingDirectory(absoluteDir);
-    Assert.assertEquals(absoluteDir, fSys.getWorkingDirectory());
+    assertEquals(absoluteDir, fSys.getWorkingDirectory());
     
     // Now open a file relative to the wd we just set above.
     Path absoluteFooPath = new Path(absoluteDir, "foo");
@@ -283,14 +293,14 @@ public class TestChRootedFileSystem {
     
     // Now mkdir relative to the dir we cd'ed to
     fSys.mkdirs(new Path("newDir"));
-    Assert.assertTrue(fSys.isDirectory(new Path(absoluteDir, "newDir")));
+    assertTrue(fSys.isDirectory(new Path(absoluteDir, "newDir")));
 
     /* Filesystem impls (RawLocal and DistributedFileSystem do not check
      * for existing of working dir
     absoluteDir = getTestRootPath(fSys, "nonexistingPath");
     try {
       fSys.setWorkingDirectory(absoluteDir);
-      Assert.fail("cd to non existing dir should have failed");
+      fail("cd to non existing dir should have failed");
     } catch (Exception e) {
       // Exception as expected
     }
@@ -301,7 +311,7 @@ public class TestChRootedFileSystem {
     absoluteDir = new Path(LOCAL_FS_ROOT_URI + "/existingDir");
     fSys.mkdirs(absoluteDir);
     fSys.setWorkingDirectory(absoluteDir);
-    Assert.assertEquals(absoluteDir, fSys.getWorkingDirectory());
+    assertEquals(absoluteDir, fSys.getWorkingDirectory());
 
   }
   
@@ -311,15 +321,17 @@ public class TestChRootedFileSystem {
   
   @Test
   public void testResolvePath() throws IOException {
-    Assert.assertEquals(chrootedTo, fSys.resolvePath(new Path("/"))); 
+    assertEquals(chrootedTo, fSys.resolvePath(new Path("/")));
     fileSystemTestHelper.createFile(fSys, "/foo");
-    Assert.assertEquals(new Path(chrootedTo, "foo"),
+    assertEquals(new Path(chrootedTo, "foo"),
         fSys.resolvePath(new Path("/foo"))); 
   }
 
-  @Test(expected=FileNotFoundException.class) 
+  @Test
   public void testResolvePathNonExisting() throws IOException {
+    assertThrows(FileNotFoundException.class, () -> {
       fSys.resolvePath(new Path("/nonExisting"));
+    });
   }
   
   @Test
@@ -435,7 +447,8 @@ public class TestChRootedFileSystem {
     }
   }
 
-  @Test(timeout = 30000)
+  @Test
+  @Timeout(value = 30)
   public void testCreateSnapshot() throws Exception {
     Path snapRootPath = new Path("/snapPath");
     Path chRootedSnapRootPath = new Path("/a/b/snapPath");
@@ -452,7 +465,8 @@ public class TestChRootedFileSystem {
     verify(mockFs).createSnapshot(chRootedSnapRootPath, "snap1");
   }
 
-  @Test(timeout = 30000)
+  @Test
+  @Timeout(value = 30)
   public void testDeleteSnapshot() throws Exception {
     Path snapRootPath = new Path("/snapPath");
     Path chRootedSnapRootPath = new Path("/a/b/snapPath");
@@ -469,7 +483,8 @@ public class TestChRootedFileSystem {
     verify(mockFs).deleteSnapshot(chRootedSnapRootPath, "snap1");
   }
 
-  @Test(timeout = 30000)
+  @Test
+  @Timeout(value = 30)
   public void testRenameSnapshot() throws Exception {
     Path snapRootPath = new Path("/snapPath");
     Path chRootedSnapRootPath = new Path("/a/b/snapPath");
@@ -487,7 +502,8 @@ public class TestChRootedFileSystem {
         "snapNewName");
   }
 
-  @Test(timeout = 30000)
+  @Test
+  @Timeout(value = 30)
   public void testSetStoragePolicy() throws Exception {
     Path storagePolicyPath = new Path("/storagePolicy");
     Path chRootedStoragePolicyPath = new Path("/a/b/storagePolicy");
@@ -504,7 +520,8 @@ public class TestChRootedFileSystem {
     verify(mockFs).setStoragePolicy(chRootedStoragePolicyPath, "HOT");
   }
 
-  @Test(timeout = 30000)
+  @Test
+  @Timeout(value = 30)
   public void testUnsetStoragePolicy() throws Exception {
     Path storagePolicyPath = new Path("/storagePolicy");
     Path chRootedStoragePolicyPath = new Path("/a/b/storagePolicy");
@@ -521,7 +538,8 @@ public class TestChRootedFileSystem {
     verify(mockFs).unsetStoragePolicy(chRootedStoragePolicyPath);
   }
 
-  @Test(timeout = 30000)
+  @Test
+  @Timeout(value = 30)
   public void testGetStoragePolicy() throws Exception {
     Path storagePolicyPath = new Path("/storagePolicy");
     Path chRootedStoragePolicyPath = new Path("/a/b/storagePolicy");
@@ -538,7 +556,8 @@ public class TestChRootedFileSystem {
     verify(mockFs).getStoragePolicy(chRootedStoragePolicyPath);
   }
 
-  @Test(timeout = 30000)
+  @Test
+  @Timeout(value = 30)
   public void testGetAllStoragePolicy() throws Exception {
     Configuration conf = new Configuration();
     conf.setClass("fs.mockfs.impl", MockFileSystem.class, FileSystem.class);

+ 22 - 19
hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/viewfs/TestHCFSMountTableConfigLoader.java

@@ -17,6 +17,9 @@
  */
 package org.apache.hadoop.fs.viewfs;
 
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
 import java.io.File;
 import java.io.FileNotFoundException;
 import java.io.IOException;
@@ -28,11 +31,10 @@ import org.apache.hadoop.fs.FileSystemTestHelper;
 import org.apache.hadoop.fs.FsConstants;
 import org.apache.hadoop.fs.LocalFileSystem;
 import org.apache.hadoop.fs.Path;
-import org.junit.AfterClass;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
 
 /**
  * Tests the mount table loading.
@@ -69,7 +71,7 @@ public class TestHCFSMountTableConfigLoader {
           .append(TABLE_NAME).append(DOT).append(Constants.CONFIG_VIEWFS_LINK)
           .append(DOT).append(SRC_TWO).toString();
 
-  @BeforeClass
+  @BeforeAll
   public static void init() throws Exception {
     fsTarget = new LocalFileSystem();
     fsTarget.initialize(new URI("file:///"), new Configuration());
@@ -78,7 +80,7 @@ public class TestHCFSMountTableConfigLoader {
     fsTarget.mkdirs(targetTestRoot);
   }
 
-  @Before
+  @BeforeEach
   public void setUp() throws Exception {
     conf = new Configuration();
     conf.set(String.format(
@@ -100,8 +102,8 @@ public class TestHCFSMountTableConfigLoader {
             TARGET_TWO },
         new Path(newVersionMountTableFile.toURI()), conf);
     loader.load(targetTestRoot.toString(), conf);
-    Assert.assertEquals(conf.get(MOUNT_LINK_KEY_SRC_TWO), TARGET_TWO);
-    Assert.assertEquals(conf.get(MOUNT_LINK_KEY_SRC_ONE), TARGET_ONE);
+    assertEquals(conf.get(MOUNT_LINK_KEY_SRC_TWO), TARGET_TWO);
+    assertEquals(conf.get(MOUNT_LINK_KEY_SRC_ONE), TARGET_ONE);
   }
 
   @Test
@@ -119,8 +121,8 @@ public class TestHCFSMountTableConfigLoader {
         new Path(invalidMountFileName.toURI()), conf);
     // Pass mount table directory
     loader.load(path.toString(), conf);
-    Assert.assertEquals(null, conf.get(MOUNT_LINK_KEY_SRC_TWO));
-    Assert.assertEquals(null, conf.get(MOUNT_LINK_KEY_SRC_ONE));
+    assertEquals(null, conf.get(MOUNT_LINK_KEY_SRC_TWO));
+    assertEquals(null, conf.get(MOUNT_LINK_KEY_SRC_ONE));
     invalidMountFileName.delete();
   }
 
@@ -135,15 +137,16 @@ public class TestHCFSMountTableConfigLoader {
     invalidMountFileName.createNewFile();
     // Pass mount table directory
     loader.load(path.toString(), conf);
-    Assert.assertEquals(null, conf.get(MOUNT_LINK_KEY_SRC_TWO));
-    Assert.assertEquals(null, conf.get(MOUNT_LINK_KEY_SRC_ONE));
+    assertEquals(null, conf.get(MOUNT_LINK_KEY_SRC_TWO));
+    assertEquals(null, conf.get(MOUNT_LINK_KEY_SRC_ONE));
     invalidMountFileName.delete();
   }
 
-  @Test(expected = FileNotFoundException.class)
+  @Test
   public void testLoadWithMountFile() throws Exception {
-    loader.load(new URI(targetTestRoot.toString() + "/Non-Existent-File.xml")
-        .toString(), conf);
+    assertThrows(FileNotFoundException.class, () -> {
+      loader.load(new URI(targetTestRoot.toString() + "/Non-Existent-File.xml").toString(), conf);
+    });
   }
 
   @Test
@@ -153,11 +156,11 @@ public class TestHCFSMountTableConfigLoader {
         new String[] {TARGET_ONE, TARGET_TWO },
         new Path(oldVersionMountTableFile.toURI()), conf);
     loader.load(oldVersionMountTableFile.toURI().toString(), conf);
-    Assert.assertEquals(conf.get(MOUNT_LINK_KEY_SRC_TWO), TARGET_TWO);
-    Assert.assertEquals(conf.get(MOUNT_LINK_KEY_SRC_ONE), TARGET_ONE);
+    assertEquals(conf.get(MOUNT_LINK_KEY_SRC_TWO), TARGET_TWO);
+    assertEquals(conf.get(MOUNT_LINK_KEY_SRC_ONE), TARGET_ONE);
   }
 
-  @AfterClass
+  @AfterAll
   public static void tearDown() throws IOException {
     fsTarget.delete(targetTestRoot, true);
   }

+ 169 - 144
hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/viewfs/TestNestedMountPoint.java

@@ -17,6 +17,10 @@
  */
 package org.apache.hadoop.fs.viewfs;
 
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
 import java.net.URI;
 import java.util.List;
 import java.util.function.Function;
@@ -24,10 +28,9 @@ import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.fs.FileSystem;
 import org.apache.hadoop.fs.FsConstants;
 import org.apache.hadoop.fs.Path;
-import org.junit.After;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
 
 
 /**
@@ -65,7 +68,7 @@ public class TestNestedMountPoint {
   private static final URI NN5_TARGET = URI.create("hdfs://nn05/b/c/d/e");
   private static final URI NN6_TARGET = URI.create("hdfs://nn06/b/c/d/e/f");
 
-  @Before
+  @BeforeEach
   public void setUp() throws Exception {
     conf = new Configuration();
     mtName = TestNestedMountPoint.class.getName();
@@ -107,7 +110,7 @@ public class TestNestedMountPoint {
     };
   }
 
-  @After
+  @AfterEach
   public void tearDown() throws Exception {
     inodeTree = null;
   }
@@ -116,250 +119,272 @@ public class TestNestedMountPoint {
   public void testPathResolveToLink() throws Exception {
     // /a/b/c/d/e/f resolves to /a/b/c/d/e and /f
     InodeTree.ResolveResult resolveResult = inodeTree.resolve("/a/b/c/d/e/f", true);
-    Assert.assertEquals(InodeTree.ResultKind.EXTERNAL_DIR, resolveResult.kind);
-    Assert.assertEquals("/a/b/c/d/e", resolveResult.resolvedPath);
-    Assert.assertEquals(new Path("/f"), resolveResult.remainingPath);
-    Assert.assertTrue(resolveResult.targetFileSystem instanceof TestNestMountPointFileSystem);
-    Assert.assertEquals(NN4_TARGET, ((TestNestMountPointFileSystem) resolveResult.targetFileSystem).getUri());
-    Assert.assertTrue(resolveResult.isLastInternalDirLink());
+    assertEquals(InodeTree.ResultKind.EXTERNAL_DIR, resolveResult.kind);
+    assertEquals("/a/b/c/d/e", resolveResult.resolvedPath);
+    assertEquals(new Path("/f"), resolveResult.remainingPath);
+    assertTrue(resolveResult.targetFileSystem instanceof TestNestMountPointFileSystem);
+    assertEquals(NN4_TARGET,
+        ((TestNestMountPointFileSystem) resolveResult.targetFileSystem).getUri());
+    assertTrue(resolveResult.isLastInternalDirLink());
 
     // /a/b/c/d/e resolves to /a/b/c/d/e and /
     InodeTree.ResolveResult resolveResult2 = inodeTree.resolve("/a/b/c/d/e", true);
-    Assert.assertEquals(InodeTree.ResultKind.EXTERNAL_DIR, resolveResult2.kind);
-    Assert.assertEquals("/a/b/c/d/e", resolveResult2.resolvedPath);
-    Assert.assertEquals(new Path("/"), resolveResult2.remainingPath);
-    Assert.assertTrue(resolveResult2.targetFileSystem instanceof TestNestMountPointFileSystem);
-    Assert.assertEquals(NN4_TARGET, ((TestNestMountPointFileSystem) resolveResult2.targetFileSystem).getUri());
-    Assert.assertTrue(resolveResult2.isLastInternalDirLink());
+    assertEquals(InodeTree.ResultKind.EXTERNAL_DIR, resolveResult2.kind);
+    assertEquals("/a/b/c/d/e", resolveResult2.resolvedPath);
+    assertEquals(new Path("/"), resolveResult2.remainingPath);
+    assertTrue(resolveResult2.targetFileSystem instanceof TestNestMountPointFileSystem);
+    assertEquals(NN4_TARGET,
+        ((TestNestMountPointFileSystem) resolveResult2.targetFileSystem).getUri());
+    assertTrue(resolveResult2.isLastInternalDirLink());
 
     // /a/b/c/d/e/f/g/h/i resolves to /a/b/c/d/e and /f/g/h/i
     InodeTree.ResolveResult resolveResult3 = inodeTree.resolve("/a/b/c/d/e/f/g/h/i", true);
-    Assert.assertEquals(InodeTree.ResultKind.EXTERNAL_DIR, resolveResult3.kind);
-    Assert.assertEquals("/a/b/c/d/e", resolveResult3.resolvedPath);
-    Assert.assertEquals(new Path("/f/g/h/i"), resolveResult3.remainingPath);
-    Assert.assertTrue(resolveResult3.targetFileSystem instanceof TestNestMountPointFileSystem);
-    Assert.assertEquals(NN4_TARGET, ((TestNestMountPointFileSystem) resolveResult3.targetFileSystem).getUri());
-    Assert.assertTrue(resolveResult3.isLastInternalDirLink());
+    assertEquals(InodeTree.ResultKind.EXTERNAL_DIR, resolveResult3.kind);
+    assertEquals("/a/b/c/d/e", resolveResult3.resolvedPath);
+    assertEquals(new Path("/f/g/h/i"), resolveResult3.remainingPath);
+    assertTrue(resolveResult3.targetFileSystem instanceof TestNestMountPointFileSystem);
+    assertEquals(NN4_TARGET,
+        ((TestNestMountPointFileSystem) resolveResult3.targetFileSystem).getUri());
+    assertTrue(resolveResult3.isLastInternalDirLink());
   }
 
   @Test
   public void testPathResolveToLinkNotResolveLastComponent() throws Exception {
     // /a/b/c/d/e/f resolves to /a/b/c/d/e and /f
     InodeTree.ResolveResult resolveResult = inodeTree.resolve("/a/b/c/d/e/f", false);
-    Assert.assertEquals(InodeTree.ResultKind.EXTERNAL_DIR, resolveResult.kind);
-    Assert.assertEquals("/a/b/c/d/e", resolveResult.resolvedPath);
-    Assert.assertEquals(new Path("/f"), resolveResult.remainingPath);
-    Assert.assertTrue(resolveResult.targetFileSystem instanceof TestNestMountPointFileSystem);
-    Assert.assertEquals(NN4_TARGET, ((TestNestMountPointFileSystem) resolveResult.targetFileSystem).getUri());
-    Assert.assertTrue(resolveResult.isLastInternalDirLink());
+    assertEquals(InodeTree.ResultKind.EXTERNAL_DIR, resolveResult.kind);
+    assertEquals("/a/b/c/d/e", resolveResult.resolvedPath);
+    assertEquals(new Path("/f"), resolveResult.remainingPath);
+    assertTrue(resolveResult.targetFileSystem instanceof TestNestMountPointFileSystem);
+    assertEquals(NN4_TARGET,
+        ((TestNestMountPointFileSystem) resolveResult.targetFileSystem).getUri());
+    assertTrue(resolveResult.isLastInternalDirLink());
 
     // /a/b/c/d/e resolves to /a/b/c/d and /e
     InodeTree.ResolveResult resolveResult2 = inodeTree.resolve("/a/b/c/d/e", false);
-    Assert.assertEquals(InodeTree.ResultKind.EXTERNAL_DIR, resolveResult2.kind);
-    Assert.assertEquals("/a/b/c/d", resolveResult2.resolvedPath);
-    Assert.assertEquals(new Path("/e"), resolveResult2.remainingPath);
-    Assert.assertTrue(resolveResult2.targetFileSystem instanceof TestNestMountPointFileSystem);
-    Assert.assertEquals(NN3_TARGET, ((TestNestMountPointFileSystem) resolveResult2.targetFileSystem).getUri());
-    Assert.assertTrue(resolveResult2.isLastInternalDirLink());
+    assertEquals(InodeTree.ResultKind.EXTERNAL_DIR, resolveResult2.kind);
+    assertEquals("/a/b/c/d", resolveResult2.resolvedPath);
+    assertEquals(new Path("/e"), resolveResult2.remainingPath);
+    assertTrue(resolveResult2.targetFileSystem instanceof TestNestMountPointFileSystem);
+    assertEquals(NN3_TARGET,
+        ((TestNestMountPointFileSystem) resolveResult2.targetFileSystem).getUri());
+    assertTrue(resolveResult2.isLastInternalDirLink());
 
     // /a/b/c/d/e/f/g/h/i resolves to /a/b/c/d/e and /f/g/h/i
     InodeTree.ResolveResult resolveResult3 = inodeTree.resolve("/a/b/c/d/e/f/g/h/i", false);
-    Assert.assertEquals(InodeTree.ResultKind.EXTERNAL_DIR, resolveResult3.kind);
-    Assert.assertEquals("/a/b/c/d/e", resolveResult3.resolvedPath);
-    Assert.assertEquals(new Path("/f/g/h/i"), resolveResult3.remainingPath);
-    Assert.assertTrue(resolveResult3.targetFileSystem instanceof TestNestMountPointFileSystem);
-    Assert.assertEquals(NN4_TARGET, ((TestNestMountPointFileSystem) resolveResult3.targetFileSystem).getUri());
-    Assert.assertTrue(resolveResult3.isLastInternalDirLink());
+    assertEquals(InodeTree.ResultKind.EXTERNAL_DIR, resolveResult3.kind);
+    assertEquals("/a/b/c/d/e", resolveResult3.resolvedPath);
+    assertEquals(new Path("/f/g/h/i"), resolveResult3.remainingPath);
+    assertTrue(resolveResult3.targetFileSystem instanceof TestNestMountPointFileSystem);
+    assertEquals(NN4_TARGET,
+        ((TestNestMountPointFileSystem) resolveResult3.targetFileSystem).getUri());
+    assertTrue(resolveResult3.isLastInternalDirLink());
   }
 
   @Test
   public void testPathResolveToDirLink() throws Exception {
     // /a/b/c/d/f resolves to /a/b/c/d, /f
     InodeTree.ResolveResult resolveResult = inodeTree.resolve("/a/b/c/d/f", true);
-    Assert.assertEquals(InodeTree.ResultKind.EXTERNAL_DIR, resolveResult.kind);
-    Assert.assertEquals("/a/b/c/d", resolveResult.resolvedPath);
-    Assert.assertEquals(new Path("/f"), resolveResult.remainingPath);
-    Assert.assertTrue(resolveResult.targetFileSystem instanceof TestNestMountPointFileSystem);
-    Assert.assertEquals(NN3_TARGET, ((TestNestMountPointFileSystem) resolveResult.targetFileSystem).getUri());
-    Assert.assertTrue(resolveResult.isLastInternalDirLink());
+    assertEquals(InodeTree.ResultKind.EXTERNAL_DIR, resolveResult.kind);
+    assertEquals("/a/b/c/d", resolveResult.resolvedPath);
+    assertEquals(new Path("/f"), resolveResult.remainingPath);
+    assertTrue(resolveResult.targetFileSystem instanceof TestNestMountPointFileSystem);
+    assertEquals(NN3_TARGET,
+        ((TestNestMountPointFileSystem) resolveResult.targetFileSystem).getUri());
+    assertTrue(resolveResult.isLastInternalDirLink());
 
     // /a/b/c/d resolves to /a/b/c/d and /
     InodeTree.ResolveResult resolveResult2 = inodeTree.resolve("/a/b/c/d", true);
-    Assert.assertEquals(InodeTree.ResultKind.EXTERNAL_DIR, resolveResult2.kind);
-    Assert.assertEquals("/a/b/c/d", resolveResult2.resolvedPath);
-    Assert.assertEquals(new Path("/"), resolveResult2.remainingPath);
-    Assert.assertTrue(resolveResult2.targetFileSystem instanceof TestNestMountPointFileSystem);
-    Assert.assertEquals(NN3_TARGET, ((TestNestMountPointFileSystem) resolveResult2.targetFileSystem).getUri());
-    Assert.assertTrue(resolveResult2.isLastInternalDirLink());
+    assertEquals(InodeTree.ResultKind.EXTERNAL_DIR, resolveResult2.kind);
+    assertEquals("/a/b/c/d", resolveResult2.resolvedPath);
+    assertEquals(new Path("/"), resolveResult2.remainingPath);
+    assertTrue(resolveResult2.targetFileSystem instanceof TestNestMountPointFileSystem);
+    assertEquals(NN3_TARGET,
+        ((TestNestMountPointFileSystem) resolveResult2.targetFileSystem).getUri());
+    assertTrue(resolveResult2.isLastInternalDirLink());
 
     // /a/b/c/d/f/g/h/i resolves to /a/b/c/d and /f/g/h/i
     InodeTree.ResolveResult resolveResult3 = inodeTree.resolve("/a/b/c/d/f/g/h/i", true);
-    Assert.assertEquals(InodeTree.ResultKind.EXTERNAL_DIR, resolveResult3.kind);
-    Assert.assertEquals("/a/b/c/d", resolveResult3.resolvedPath);
-    Assert.assertEquals(new Path("/f/g/h/i"), resolveResult3.remainingPath);
-    Assert.assertTrue(resolveResult3.targetFileSystem instanceof TestNestMountPointFileSystem);
-    Assert.assertEquals(NN3_TARGET, ((TestNestMountPointFileSystem) resolveResult3.targetFileSystem).getUri());
-    Assert.assertTrue(resolveResult3.isLastInternalDirLink());
+    assertEquals(InodeTree.ResultKind.EXTERNAL_DIR, resolveResult3.kind);
+    assertEquals("/a/b/c/d", resolveResult3.resolvedPath);
+    assertEquals(new Path("/f/g/h/i"), resolveResult3.remainingPath);
+    assertTrue(resolveResult3.targetFileSystem instanceof TestNestMountPointFileSystem);
+    assertEquals(NN3_TARGET,
+        ((TestNestMountPointFileSystem) resolveResult3.targetFileSystem).getUri());
+    assertTrue(resolveResult3.isLastInternalDirLink());
   }
 
   @Test
   public void testPathResolveToDirLinkNotResolveLastComponent() throws Exception {
     // /a/b/c/d/f resolves to /a/b/c/d, /f
     InodeTree.ResolveResult resolveResult = inodeTree.resolve("/a/b/c/d/f", false);
-    Assert.assertEquals(InodeTree.ResultKind.EXTERNAL_DIR, resolveResult.kind);
-    Assert.assertEquals("/a/b/c/d", resolveResult.resolvedPath);
-    Assert.assertEquals(new Path("/f"), resolveResult.remainingPath);
-    Assert.assertTrue(resolveResult.targetFileSystem instanceof TestNestMountPointFileSystem);
-    Assert.assertEquals(NN3_TARGET, ((TestNestMountPointFileSystem) resolveResult.targetFileSystem).getUri());
-    Assert.assertTrue(resolveResult.isLastInternalDirLink());
+    assertEquals(InodeTree.ResultKind.EXTERNAL_DIR, resolveResult.kind);
+    assertEquals("/a/b/c/d", resolveResult.resolvedPath);
+    assertEquals(new Path("/f"), resolveResult.remainingPath);
+    assertTrue(resolveResult.targetFileSystem instanceof TestNestMountPointFileSystem);
+    assertEquals(NN3_TARGET,
+        ((TestNestMountPointFileSystem) resolveResult.targetFileSystem).getUri());
+    assertTrue(resolveResult.isLastInternalDirLink());
 
     // /a/b/c/d resolves to /a/b and /c/d
     InodeTree.ResolveResult resolveResult2 = inodeTree.resolve("/a/b/c/d", false);
-    Assert.assertEquals(InodeTree.ResultKind.EXTERNAL_DIR, resolveResult2.kind);
-    Assert.assertEquals("/a/b", resolveResult2.resolvedPath);
-    Assert.assertEquals(new Path("/c/d"), resolveResult2.remainingPath);
-    Assert.assertTrue(resolveResult2.targetFileSystem instanceof TestNestMountPointFileSystem);
-    Assert.assertEquals(NN1_TARGET, ((TestNestMountPointFileSystem) resolveResult2.targetFileSystem).getUri());
-    Assert.assertTrue(resolveResult2.isLastInternalDirLink());
+    assertEquals(InodeTree.ResultKind.EXTERNAL_DIR, resolveResult2.kind);
+    assertEquals("/a/b", resolveResult2.resolvedPath);
+    assertEquals(new Path("/c/d"), resolveResult2.remainingPath);
+    assertTrue(resolveResult2.targetFileSystem instanceof TestNestMountPointFileSystem);
+    assertEquals(NN1_TARGET,
+        ((TestNestMountPointFileSystem) resolveResult2.targetFileSystem).getUri());
+    assertTrue(resolveResult2.isLastInternalDirLink());
 
     // /a/b/c/d/f/g/h/i resolves to /a/b/c/d and /f/g/h/i
     InodeTree.ResolveResult resolveResult3 = inodeTree.resolve("/a/b/c/d/f/g/h/i", false);
-    Assert.assertEquals(InodeTree.ResultKind.EXTERNAL_DIR, resolveResult3.kind);
-    Assert.assertEquals("/a/b/c/d", resolveResult3.resolvedPath);
-    Assert.assertEquals(new Path("/f/g/h/i"), resolveResult3.remainingPath);
-    Assert.assertTrue(resolveResult3.targetFileSystem instanceof TestNestMountPointFileSystem);
-    Assert.assertEquals(NN3_TARGET, ((TestNestMountPointFileSystem) resolveResult3.targetFileSystem).getUri());
-    Assert.assertTrue(resolveResult3.isLastInternalDirLink());
+    assertEquals(InodeTree.ResultKind.EXTERNAL_DIR, resolveResult3.kind);
+    assertEquals("/a/b/c/d", resolveResult3.resolvedPath);
+    assertEquals(new Path("/f/g/h/i"), resolveResult3.remainingPath);
+    assertTrue(resolveResult3.targetFileSystem instanceof TestNestMountPointFileSystem);
+    assertEquals(NN3_TARGET,
+        ((TestNestMountPointFileSystem) resolveResult3.targetFileSystem).getUri());
+    assertTrue(resolveResult3.isLastInternalDirLink());
   }
 
   @Test
   public void testMultiNestedMountPointsPathResolveToDirLink() throws Exception {
     // /a/b/f resolves to /a/b and /f
     InodeTree.ResolveResult resolveResult = inodeTree.resolve("/a/b/f", true);
-    Assert.assertEquals(InodeTree.ResultKind.EXTERNAL_DIR, resolveResult.kind);
-    Assert.assertEquals("/a/b", resolveResult.resolvedPath);
-    Assert.assertEquals(new Path("/f"), resolveResult.remainingPath);
-    Assert.assertTrue(resolveResult.targetFileSystem instanceof TestNestMountPointFileSystem);
-    Assert.assertEquals(NN1_TARGET, ((TestNestMountPointFileSystem) resolveResult.targetFileSystem).getUri());
-    Assert.assertTrue(resolveResult.isLastInternalDirLink());
+    assertEquals(InodeTree.ResultKind.EXTERNAL_DIR, resolveResult.kind);
+    assertEquals("/a/b", resolveResult.resolvedPath);
+    assertEquals(new Path("/f"), resolveResult.remainingPath);
+    assertTrue(resolveResult.targetFileSystem instanceof TestNestMountPointFileSystem);
+    assertEquals(NN1_TARGET,
+        ((TestNestMountPointFileSystem) resolveResult.targetFileSystem).getUri());
+    assertTrue(resolveResult.isLastInternalDirLink());
 
     // /a/b resolves to /a/b and /
     InodeTree.ResolveResult resolveResult2 = inodeTree.resolve("/a/b", true);
-    Assert.assertEquals(InodeTree.ResultKind.EXTERNAL_DIR, resolveResult2.kind);
-    Assert.assertEquals("/a/b", resolveResult2.resolvedPath);
-    Assert.assertEquals(new Path("/"), resolveResult2.remainingPath);
-    Assert.assertTrue(resolveResult2.targetFileSystem instanceof TestNestMountPointFileSystem);
-    Assert.assertEquals(NN1_TARGET, ((TestNestMountPointFileSystem) resolveResult2.targetFileSystem).getUri());
-    Assert.assertTrue(resolveResult2.isLastInternalDirLink());
+    assertEquals(InodeTree.ResultKind.EXTERNAL_DIR, resolveResult2.kind);
+    assertEquals("/a/b", resolveResult2.resolvedPath);
+    assertEquals(new Path("/"), resolveResult2.remainingPath);
+    assertTrue(resolveResult2.targetFileSystem instanceof TestNestMountPointFileSystem);
+    assertEquals(NN1_TARGET,
+        ((TestNestMountPointFileSystem) resolveResult2.targetFileSystem).getUri());
+    assertTrue(resolveResult2.isLastInternalDirLink());
   }
 
   @Test
   public void testMultiNestedMountPointsPathResolveToDirLinkNotResolveLastComponent() throws Exception {
     // /a/b/f resolves to /a/b and /f
     InodeTree.ResolveResult resolveResult = inodeTree.resolve("/a/b/f", false);
-    Assert.assertEquals(InodeTree.ResultKind.EXTERNAL_DIR, resolveResult.kind);
-    Assert.assertEquals("/a/b", resolveResult.resolvedPath);
-    Assert.assertEquals(new Path("/f"), resolveResult.remainingPath);
-    Assert.assertTrue(resolveResult.targetFileSystem instanceof TestNestMountPointFileSystem);
-    Assert.assertEquals(NN1_TARGET, ((TestNestMountPointFileSystem) resolveResult.targetFileSystem).getUri());
-    Assert.assertTrue(resolveResult.isLastInternalDirLink());
+    assertEquals(InodeTree.ResultKind.EXTERNAL_DIR, resolveResult.kind);
+    assertEquals("/a/b", resolveResult.resolvedPath);
+    assertEquals(new Path("/f"), resolveResult.remainingPath);
+    assertTrue(resolveResult.targetFileSystem instanceof TestNestMountPointFileSystem);
+    assertEquals(NN1_TARGET,
+        ((TestNestMountPointFileSystem) resolveResult.targetFileSystem).getUri());
+    assertTrue(resolveResult.isLastInternalDirLink());
 
     // /a/b resolves to /a and /b
     InodeTree.ResolveResult resolveResult2 = inodeTree.resolve("/a/b", false);
-    Assert.assertEquals(InodeTree.ResultKind.INTERNAL_DIR, resolveResult2.kind);
-    Assert.assertEquals("/a", resolveResult2.resolvedPath);
-    Assert.assertEquals(new Path("/b"), resolveResult2.remainingPath);
-    Assert.assertTrue(resolveResult2.targetFileSystem instanceof TestNestMountPointInternalFileSystem);
-    Assert.assertEquals(fsUri, ((TestNestMountPointInternalFileSystem) resolveResult2.targetFileSystem).getUri());
-    Assert.assertFalse(resolveResult2.isLastInternalDirLink());
+    assertEquals(InodeTree.ResultKind.INTERNAL_DIR, resolveResult2.kind);
+    assertEquals("/a", resolveResult2.resolvedPath);
+    assertEquals(new Path("/b"), resolveResult2.remainingPath);
+    assertTrue(resolveResult2.targetFileSystem instanceof TestNestMountPointInternalFileSystem);
+    assertEquals(fsUri,
+        ((TestNestMountPointInternalFileSystem) resolveResult2.targetFileSystem).getUri());
+    assertFalse(resolveResult2.isLastInternalDirLink());
   }
 
   @Test
   public void testPathResolveToDirLinkLastComponentInternalDir() throws Exception {
     // /a/b/c resolves to /a/b and /c
     InodeTree.ResolveResult resolveResult = inodeTree.resolve("/a/b/c", true);
-    Assert.assertEquals(InodeTree.ResultKind.EXTERNAL_DIR, resolveResult.kind);
-    Assert.assertEquals("/a/b", resolveResult.resolvedPath);
-    Assert.assertEquals(new Path("/c"), resolveResult.remainingPath);
-    Assert.assertTrue(resolveResult.targetFileSystem instanceof TestNestMountPointFileSystem);
-    Assert.assertEquals(NN1_TARGET, ((TestNestMountPointFileSystem) resolveResult.targetFileSystem).getUri());
-    Assert.assertTrue(resolveResult.isLastInternalDirLink());
+    assertEquals(InodeTree.ResultKind.EXTERNAL_DIR, resolveResult.kind);
+    assertEquals("/a/b", resolveResult.resolvedPath);
+    assertEquals(new Path("/c"), resolveResult.remainingPath);
+    assertTrue(resolveResult.targetFileSystem instanceof TestNestMountPointFileSystem);
+    assertEquals(NN1_TARGET,
+        ((TestNestMountPointFileSystem) resolveResult.targetFileSystem).getUri());
+    assertTrue(resolveResult.isLastInternalDirLink());
   }
 
   @Test
   public void testPathResolveToDirLinkLastComponentInternalDirNotResolveLastComponent() throws Exception {
     // /a/b/c resolves to /a/b and /c
     InodeTree.ResolveResult resolveResult = inodeTree.resolve("/a/b/c", false);
-    Assert.assertEquals(InodeTree.ResultKind.EXTERNAL_DIR, resolveResult.kind);
-    Assert.assertEquals("/a/b", resolveResult.resolvedPath);
-    Assert.assertEquals(new Path("/c"), resolveResult.remainingPath);
-    Assert.assertTrue(resolveResult.targetFileSystem instanceof TestNestMountPointFileSystem);
-    Assert.assertEquals(NN1_TARGET, ((TestNestMountPointFileSystem) resolveResult.targetFileSystem).getUri());
-    Assert.assertTrue(resolveResult.isLastInternalDirLink());
+    assertEquals(InodeTree.ResultKind.EXTERNAL_DIR, resolveResult.kind);
+    assertEquals("/a/b", resolveResult.resolvedPath);
+    assertEquals(new Path("/c"), resolveResult.remainingPath);
+    assertTrue(resolveResult.targetFileSystem instanceof TestNestMountPointFileSystem);
+    assertEquals(NN1_TARGET,
+        ((TestNestMountPointFileSystem) resolveResult.targetFileSystem).getUri());
+    assertTrue(resolveResult.isLastInternalDirLink());
   }
 
   @Test
   public void testPathResolveToLinkFallBack() throws Exception {
     // /a/e resolves to linkfallback
     InodeTree.ResolveResult resolveResult = inodeTree.resolve("/a/e", true);
-    Assert.assertEquals(InodeTree.ResultKind.EXTERNAL_DIR, resolveResult.kind);
-    Assert.assertEquals("/", resolveResult.resolvedPath);
-    Assert.assertEquals(new Path("/a/e"), resolveResult.remainingPath);
-    Assert.assertTrue(resolveResult.targetFileSystem instanceof TestNestMountPointFileSystem);
-    Assert.assertEquals(LINKFALLBACK_TARGET, ((TestNestMountPointFileSystem) resolveResult.targetFileSystem).getUri());
-    Assert.assertFalse(resolveResult.isLastInternalDirLink());
+    assertEquals(InodeTree.ResultKind.EXTERNAL_DIR, resolveResult.kind);
+    assertEquals("/", resolveResult.resolvedPath);
+    assertEquals(new Path("/a/e"), resolveResult.remainingPath);
+    assertTrue(resolveResult.targetFileSystem instanceof TestNestMountPointFileSystem);
+    assertEquals(LINKFALLBACK_TARGET,
+        ((TestNestMountPointFileSystem) resolveResult.targetFileSystem).getUri());
+    assertFalse(resolveResult.isLastInternalDirLink());
   }
 
   @Test
   public void testPathNotResolveToLinkFallBackNotResolveLastComponent() throws Exception {
     // /a/e resolves to internalDir instead of linkfallback
     InodeTree.ResolveResult resolveResult = inodeTree.resolve("/a/e", false);
-    Assert.assertEquals(InodeTree.ResultKind.INTERNAL_DIR, resolveResult.kind);
-    Assert.assertEquals("/a", resolveResult.resolvedPath);
-    Assert.assertEquals(new Path("/e"), resolveResult.remainingPath);
-    Assert.assertTrue(resolveResult.targetFileSystem instanceof TestNestMountPointInternalFileSystem);
-    Assert.assertEquals(fsUri, ((TestNestMountPointInternalFileSystem) resolveResult.targetFileSystem).getUri());
-    Assert.assertFalse(resolveResult.isLastInternalDirLink());
+    assertEquals(InodeTree.ResultKind.INTERNAL_DIR, resolveResult.kind);
+    assertEquals("/a", resolveResult.resolvedPath);
+    assertEquals(new Path("/e"), resolveResult.remainingPath);
+    assertTrue(resolveResult.targetFileSystem instanceof TestNestMountPointInternalFileSystem);
+    assertEquals(fsUri,
+        ((TestNestMountPointInternalFileSystem) resolveResult.targetFileSystem).getUri());
+    assertFalse(resolveResult.isLastInternalDirLink());
   }
 
   @Test
   public void testPathResolveToInternalDir() throws Exception {
     // /b/c resolves to internal dir
     InodeTree.ResolveResult resolveResult = inodeTree.resolve("/b/c", true);
-    Assert.assertEquals(InodeTree.ResultKind.INTERNAL_DIR, resolveResult.kind);
-    Assert.assertEquals("/b/c", resolveResult.resolvedPath);
-    Assert.assertEquals(new Path("/"), resolveResult.remainingPath);
-    Assert.assertTrue(resolveResult.targetFileSystem instanceof TestNestMountPointInternalFileSystem);
-    Assert.assertEquals(fsUri, ((TestNestMountPointInternalFileSystem) resolveResult.targetFileSystem).getUri());
-    Assert.assertFalse(resolveResult.isLastInternalDirLink());
+    assertEquals(InodeTree.ResultKind.INTERNAL_DIR, resolveResult.kind);
+    assertEquals("/b/c", resolveResult.resolvedPath);
+    assertEquals(new Path("/"), resolveResult.remainingPath);
+    assertTrue(resolveResult.targetFileSystem instanceof TestNestMountPointInternalFileSystem);
+    assertEquals(fsUri,
+        ((TestNestMountPointInternalFileSystem) resolveResult.targetFileSystem).getUri());
+    assertFalse(resolveResult.isLastInternalDirLink());
   }
 
   @Test
   public void testPathResolveToInternalDirNotResolveLastComponent() throws Exception {
     // /b/c resolves to internal dir
     InodeTree.ResolveResult resolveResult = inodeTree.resolve("/b/c", false);
-    Assert.assertEquals(InodeTree.ResultKind.INTERNAL_DIR, resolveResult.kind);
-    Assert.assertEquals("/b", resolveResult.resolvedPath);
-    Assert.assertEquals(new Path("/c"), resolveResult.remainingPath);
-    Assert.assertTrue(resolveResult.targetFileSystem instanceof TestNestMountPointInternalFileSystem);
-    Assert.assertEquals(fsUri, ((TestNestMountPointInternalFileSystem) resolveResult.targetFileSystem).getUri());
-    Assert.assertFalse(resolveResult.isLastInternalDirLink());
+    assertEquals(InodeTree.ResultKind.INTERNAL_DIR, resolveResult.kind);
+    assertEquals("/b", resolveResult.resolvedPath);
+    assertEquals(new Path("/c"), resolveResult.remainingPath);
+    assertTrue(resolveResult.targetFileSystem instanceof TestNestMountPointInternalFileSystem);
+    assertEquals(fsUri,
+        ((TestNestMountPointInternalFileSystem) resolveResult.targetFileSystem).getUri());
+    assertFalse(resolveResult.isLastInternalDirLink());
   }
 
   @Test
   public void testSlashResolveToInternalDir() throws Exception {
     // / resolves to internal dir
     InodeTree.ResolveResult resolveResult = inodeTree.resolve("/", true);
-    Assert.assertEquals(InodeTree.ResultKind.INTERNAL_DIR, resolveResult.kind);
-    Assert.assertEquals("/", resolveResult.resolvedPath);
-    Assert.assertEquals(new Path("/"), resolveResult.remainingPath);
-    Assert.assertTrue(resolveResult.targetFileSystem instanceof TestNestMountPointInternalFileSystem);
-    Assert.assertFalse(resolveResult.isLastInternalDirLink());
+    assertEquals(InodeTree.ResultKind.INTERNAL_DIR, resolveResult.kind);
+    assertEquals("/", resolveResult.resolvedPath);
+    assertEquals(new Path("/"), resolveResult.remainingPath);
+    assertTrue(resolveResult.targetFileSystem instanceof TestNestMountPointInternalFileSystem);
+    assertFalse(resolveResult.isLastInternalDirLink());
   }
 
   @Test
   public void testInodeTreeMountPoints() throws Exception {
     List<InodeTree.MountPoint<FileSystem>> mountPoints = inodeTree.getMountPoints();
-    Assert.assertEquals(6, mountPoints.size());
+    assertEquals(6, mountPoints.size());
   }
 }

+ 28 - 26
hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/viewfs/TestRegexMountPoint.java

@@ -17,6 +17,9 @@
  */
 package org.apache.hadoop.fs.viewfs;
 
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
 import java.util.function.Function;
 import java.io.IOException;
 import java.net.URI;
@@ -24,10 +27,9 @@ import java.util.Map;
 import java.util.Set;
 
 import org.apache.hadoop.conf.Configuration;
-import org.junit.After;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -55,7 +57,7 @@ public class TestRegexMountPoint {
     }
   }
 
-  @Before
+  @BeforeEach
   public void setUp() throws Exception {
     conf = new Configuration();
     ConfigUtil.addLink(conf, TestRegexMountPoint.class.getName(), "/mnt",
@@ -88,7 +90,7 @@ public class TestRegexMountPoint {
     };
   }
 
-  @After
+  @AfterEach
   public void tearDown() throws Exception {
     inodeTree = null;
   }
@@ -101,14 +103,14 @@ public class TestRegexMountPoint {
         new RegexMountPoint(inodeTree, srcRegex, target, null);
     regexMountPoint.initialize();
     Map<String, Set<String>> varMap = regexMountPoint.getVarInDestPathMap();
-    Assert.assertEquals(varMap.size(), 3);
-    Assert.assertEquals(varMap.get("0").size(), 1);
-    Assert.assertTrue(varMap.get("0").contains("$0"));
-    Assert.assertEquals(varMap.get("1").size(), 2);
-    Assert.assertTrue(varMap.get("1").contains("${1}"));
-    Assert.assertTrue(varMap.get("1").contains("$1"));
-    Assert.assertEquals(varMap.get("2").size(), 1);
-    Assert.assertTrue(varMap.get("2").contains("${2}"));
+    assertEquals(varMap.size(), 3);
+    assertEquals(varMap.get("0").size(), 1);
+    assertTrue(varMap.get("0").contains("$0"));
+    assertEquals(varMap.get("1").size(), 2);
+    assertTrue(varMap.get("1").contains("${1}"));
+    assertTrue(varMap.get("1").contains("$1"));
+    assertEquals(varMap.get("2").size(), 1);
+    assertTrue(varMap.get("2").contains("${2}"));
   }
 
   @Test
@@ -121,18 +123,18 @@ public class TestRegexMountPoint {
     regexMountPoint.initialize();
     InodeTree.ResolveResult resolveResult =
         regexMountPoint.resolve("/user/hadoop/file1", true);
-    Assert.assertEquals(resolveResult.kind, InodeTree.ResultKind.EXTERNAL_DIR);
-    Assert.assertTrue(
+    assertEquals(resolveResult.kind, InodeTree.ResultKind.EXTERNAL_DIR);
+    assertTrue(
         resolveResult.targetFileSystem
             instanceof TestRegexMountPointFileSystem);
-    Assert.assertEquals("/user/hadoop", resolveResult.resolvedPath);
-    Assert.assertTrue(
+    assertEquals("/user/hadoop", resolveResult.resolvedPath);
+    assertTrue(
         resolveResult.targetFileSystem
             instanceof TestRegexMountPointFileSystem);
-    Assert.assertEquals("/namenode1/testResolve/hadoop",
+    assertEquals("/namenode1/testResolve/hadoop",
         ((TestRegexMountPointFileSystem) resolveResult.targetFileSystem)
             .getUri().toString());
-    Assert.assertEquals("/file1", resolveResult.remainingPath.toString());
+    assertEquals("/file1", resolveResult.remainingPath.toString());
   }
 
   @Test
@@ -149,18 +151,18 @@ public class TestRegexMountPoint {
     regexMountPoint.initialize();
     InodeTree.ResolveResult resolveResult =
         regexMountPoint.resolve("/user/hadoop_user1/file_index", true);
-    Assert.assertEquals(resolveResult.kind, InodeTree.ResultKind.EXTERNAL_DIR);
-    Assert.assertTrue(
+    assertEquals(resolveResult.kind, InodeTree.ResultKind.EXTERNAL_DIR);
+    assertTrue(
         resolveResult.targetFileSystem
             instanceof TestRegexMountPointFileSystem);
-    Assert.assertEquals("/user/hadoop_user1", resolveResult.resolvedPath);
-    Assert.assertTrue(
+    assertEquals("/user/hadoop_user1", resolveResult.resolvedPath);
+    assertTrue(
         resolveResult.targetFileSystem
             instanceof TestRegexMountPointFileSystem);
-    Assert.assertEquals("/namenode1/testResolve/hadoop-user1",
+    assertEquals("/namenode1/testResolve/hadoop-user1",
         ((TestRegexMountPointFileSystem) resolveResult.targetFileSystem)
             .getUri().toString());
-    Assert.assertEquals("/file_index",
+    assertEquals("/file_index",
         resolveResult.remainingPath.toString());
   }
 }

+ 0 - 2
hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/viewfs/TestViewFileSystemLocalFileSystem.java

@@ -17,7 +17,6 @@
  */
 package org.apache.hadoop.fs.viewfs;
 
-
 import java.io.IOException;
 import java.net.URI;
 
@@ -38,7 +37,6 @@ import org.junit.jupiter.api.AfterEach;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 
-
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 

+ 12 - 11
hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/viewfs/TestViewFileSystemWithAuthorityLocalFileSystem.java

@@ -17,6 +17,7 @@
  */
 package org.apache.hadoop.fs.viewfs;
 
+import static org.junit.jupiter.api.Assertions.assertEquals;
 
 import java.net.URI;
 
@@ -30,7 +31,6 @@ import org.apache.hadoop.security.UserGroupInformation;
 import java.io.IOException;
 
 import org.junit.jupiter.api.AfterEach;
-import org.junit.jupiter.api.Assertions;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 
@@ -76,15 +76,16 @@ public class TestViewFileSystemWithAuthorityLocalFileSystem extends ViewFileSyst
   @Override
   @Test
   public void testBasicPaths() {
-    Assertions.assertEquals(fsView.getUri(), schemeWithAuthority);
-    Assertions.assertEquals(fsView.getWorkingDirectory(),
-        fsView.makeQualified(
-        new Path("/user/" + System.getProperty("user.name"))));
-    Assertions.assertEquals(fsView.getHomeDirectory(),
-        fsView.makeQualified(
-        new Path("/user/" + System.getProperty("user.name"))));
-    Assertions.assertEquals(
-        fsView.makeQualified(new Path("/foo/bar")),
-        new Path("/foo/bar").makeQualified(schemeWithAuthority, null));
+    assertEquals(schemeWithAuthority,
+        fsView.getUri());
+    assertEquals(fsView.makeQualified(
+        new Path("/user/" + System.getProperty("user.name"))),
+        fsView.getWorkingDirectory());
+    assertEquals(fsView.makeQualified(
+        new Path("/user/" + System.getProperty("user.name"))),
+        fsView.getHomeDirectory());
+    assertEquals(
+        new Path("/foo/bar").makeQualified(schemeWithAuthority, null),
+        fsView.makeQualified(new Path("/foo/bar")));
   }
 }

+ 13 - 9
hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/viewfs/TestViewFsOverloadSchemeListStatus.java

@@ -32,12 +32,15 @@ import org.apache.hadoop.fs.LocalFileSystem;
 import org.apache.hadoop.fs.Path;
 import org.apache.hadoop.fs.permission.FsPermission;
 import org.apache.hadoop.test.GenericTestUtils;
-import org.junit.After;
-import org.junit.AfterClass;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.Timeout;
 
-import static org.junit.Assert.*;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
 
 /**
  * ViewFsOverloadScheme ListStatus.
@@ -49,7 +52,7 @@ public class TestViewFsOverloadSchemeListStatus {
   private Configuration conf;
   private static final String FILE_NAME = "file";
 
-  @Before
+  @BeforeEach
   public void setUp() {
     conf = new Configuration();
     conf.set(String.format("fs.%s.impl", FILE_NAME),
@@ -61,7 +64,7 @@ public class TestViewFsOverloadSchemeListStatus {
     assertTrue(TEST_DIR.mkdirs());
   }
 
-  @After
+  @AfterEach
   public void tearDown() throws IOException {
     FileUtil.fullyDelete(TEST_DIR);
   }
@@ -130,7 +133,8 @@ public class TestViewFsOverloadSchemeListStatus {
    * if there are no mount links configured. It should add fallback with the
    * chrootedFS at it's uri's root.
    */
-  @Test(timeout = 30000)
+  @Test
+  @Timeout(value = 30)
   public void testViewFSOverloadSchemeWithoutAnyMountLinks() throws Exception {
     Path initUri = new Path(TEST_DIR.toURI().toString(), "init");
     try (FileSystem fs = FileSystem.get(initUri.toUri(), conf)) {
@@ -154,7 +158,7 @@ public class TestViewFsOverloadSchemeListStatus {
     }
   }
 
-  @AfterClass
+  @AfterAll
   public static void cleanup() throws IOException {
     FileUtil.fullyDelete(TEST_DIR);
   }

Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 185 - 179
hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/viewfs/ViewFileSystemBaseTest.java


+ 4 - 3
hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/viewfs/ViewFsTestSetup.java

@@ -17,6 +17,8 @@
  */
 package org.apache.hadoop.fs.viewfs;
 
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
 import java.io.IOException;
 import java.net.URI;
 import java.net.URISyntaxException;
@@ -31,7 +33,6 @@ import org.apache.hadoop.fs.Path;
 import org.apache.hadoop.fs.viewfs.ViewFileSystemOverloadScheme.ChildFsGetter;
 import org.apache.hadoop.util.Shell;
 import org.eclipse.jetty.util.log.Log;
-import org.junit.Assert;
 
 
 /**
@@ -164,7 +165,7 @@ public class ViewFsTestSetup {
           out.writeBytes("<property><name>");
           if (isNfly) {
             String[] srcParts = src.split("[.]");
-            Assert.assertEquals("Invalid NFlyLink format", 3, srcParts.length);
+            assertEquals(3, srcParts.length, "Invalid NFlyLink format");
             String actualSrc = srcParts[srcParts.length - 1];
             String params = srcParts[srcParts.length - 2];
             out.writeBytes(prefix + Constants.CONFIG_VIEWFS_LINK_NFLY + "."
@@ -202,7 +203,7 @@ public class ViewFsTestSetup {
       boolean isNfly = src.startsWith(Constants.CONFIG_VIEWFS_LINK_NFLY);
       if (isNfly) {
         String[] srcParts = src.split("[.]");
-        Assert.assertEquals("Invalid NFlyLink format", 3, srcParts.length);
+        assertEquals(3, srcParts.length, "Invalid NFlyLink format");
         String actualSrc = srcParts[srcParts.length - 1];
         String params = srcParts[srcParts.length - 2];
         ConfigUtil.addLinkNfly(config, mountTableName, actualSrc, params,

+ 339 - 348
hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/ha/ClientBaseWithFixes.java

@@ -18,6 +18,10 @@
 
 package org.apache.hadoop.ha;
 
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.fail;
+
 import java.io.BufferedReader;
 import java.io.File;
 import java.io.IOException;
@@ -44,9 +48,8 @@ import org.apache.zookeeper.server.ServerCnxnFactory;
 import org.apache.zookeeper.server.ZKDatabase;
 import org.apache.zookeeper.server.ZooKeeperServer;
 import org.apache.zookeeper.server.persistence.FileTxnLog;
-import org.junit.After;
-import org.junit.Assert;
-import org.junit.Before;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -73,409 +76,397 @@ public abstract class ClientBaseWithFixes extends ZKTestCase {
     System.setProperty("zookeeper.4lw.commands.whitelist", "*");
   }
 
-    protected final String hostPort = initHostPort();
-    protected int maxCnxns = 0;
-    protected ServerCnxnFactory serverFactory = null;
-    protected File tmpDir = null;
+  protected final String hostPort = initHostPort();
+  protected int maxCnxns = 0;
+  protected ServerCnxnFactory serverFactory = null;
+  protected File tmpDir = null;
     
-    long initialFdCount;
+  long initialFdCount;
     
-    /**
-     * In general don't use this. Only use in the special case that you
-     * want to ignore results (for whatever reason) in your test. Don't
-     * use empty watchers in real code!
-     *
-     */
-    protected class NullWatcher implements Watcher {
-        @Override
-        public void process(WatchedEvent event) { /* nada */ }
-    }
+  /**
+   * In general don't use this. Only use in the special case that you
+   * want to ignore results (for whatever reason) in your test. Don't
+   * use empty watchers in real code!
+   *
+   */
+  protected class NullWatcher implements Watcher {
+    @Override
+    public void process(WatchedEvent event) { /* nada */ }
+  }
 
-    protected static class CountdownWatcher implements Watcher {
-        // XXX this doesn't need to be volatile! (Should probably be final)
-        volatile CountDownLatch clientConnected;
-        volatile boolean connected;
-        protected ZooKeeper client;
+  protected static class CountdownWatcher implements Watcher {
+    // XXX this doesn't need to be volatile! (Should probably be final)
+    volatile CountDownLatch clientConnected;
+    volatile boolean connected;
+    protected ZooKeeper client;
+
+    public void initializeWatchedClient(ZooKeeper zk) {
+      if (client != null) {
+        throw new RuntimeException("Watched Client was already set");
+      }
+      client = zk;
+    }
 
-        public void initializeWatchedClient(ZooKeeper zk) {
-            if (client != null) {
-                throw new RuntimeException("Watched Client was already set");
-            }
-            client = zk;
-        }
+    public CountdownWatcher() {
+      reset();
+    }
 
-        public CountdownWatcher() {
-            reset();
-        }
-        synchronized public void reset() {
-            clientConnected = new CountDownLatch(1);
-            connected = false;
-        }
-        @Override
-        synchronized public void process(WatchedEvent event) {
-            if (event.getState() == KeeperState.SyncConnected ||
-                event.getState() == KeeperState.ConnectedReadOnly) {
-                connected = true;
-                notifyAll();
-                clientConnected.countDown();
-            } else {
-                connected = false;
-                notifyAll();
-            }
-        }
-        synchronized boolean isConnected() {
-            return connected;
-        }
-        @VisibleForTesting
-        public synchronized void waitForConnected(long timeout)
-            throws InterruptedException, TimeoutException {
-            long expire = Time.now() + timeout;
-            long left = timeout;
-            while(!connected && left > 0) {
-                wait(left);
-                left = expire - Time.now();
-            }
-            if (!connected) {
-                throw new TimeoutException("Did not connect");
+    synchronized public void reset() {
+      clientConnected = new CountDownLatch(1);
+      connected = false;
+    }
 
-            }
-        }
-        @VisibleForTesting
-        public synchronized void waitForDisconnected(long timeout)
-            throws InterruptedException, TimeoutException {
-            long expire = Time.now() + timeout;
-            long left = timeout;
-            while(connected && left > 0) {
-                wait(left);
-                left = expire - Time.now();
-            }
-            if (connected) {
-                throw new TimeoutException("Did not disconnect");
+    @Override
+    synchronized public void process(WatchedEvent event) {
+      if (event.getState() == KeeperState.SyncConnected ||
+          event.getState() == KeeperState.ConnectedReadOnly) {
+        connected = true;
+        notifyAll();
+        clientConnected.countDown();
+      } else {
+        connected = false;
+        notifyAll();
+      }
+    }
 
-            }
-        }
+    synchronized boolean isConnected() {
+      return connected;
     }
 
-    protected TestableZooKeeper createClient()
-        throws IOException, InterruptedException
-    {
-        return createClient(hostPort);
+    @VisibleForTesting
+    public synchronized void waitForConnected(long timeout)
+        throws InterruptedException, TimeoutException {
+      long expire = Time.now() + timeout;
+      long left = timeout;
+      while(!connected && left > 0) {
+        wait(left);
+        left = expire - Time.now();
+      }
+      if (!connected) {
+        throw new TimeoutException("Did not connect");
+      }
     }
 
-    protected TestableZooKeeper createClient(String hp)
-        throws IOException, InterruptedException
-    {
-        CountdownWatcher watcher = new CountdownWatcher();
-        return createClient(watcher, hp);
+    @VisibleForTesting
+    public synchronized void waitForDisconnected(long timeout)
+        throws InterruptedException, TimeoutException {
+      long expire = Time.now() + timeout;
+      long left = timeout;
+      while(connected && left > 0) {
+        wait(left);
+        left = expire - Time.now();
+      }
+      if (connected) {
+        throw new TimeoutException("Did not disconnect");
+      }
     }
+  }
+
+  protected TestableZooKeeper createClient()
+      throws IOException, InterruptedException {
+    return createClient(hostPort);
+  }
 
-    private LinkedList<ZooKeeper> allClients;
-    private boolean allClientsSetup = false;
+  protected TestableZooKeeper createClient(String hp)
+      throws IOException, InterruptedException {
+    CountdownWatcher watcher = new CountdownWatcher();
+    return createClient(watcher, hp);
+  }
 
-    protected TestableZooKeeper createClient(CountdownWatcher watcher, String hp)
-        throws IOException, InterruptedException
-    {
-        return createClient(watcher, hp, CONNECTION_TIMEOUT);
-    }
+  private LinkedList<ZooKeeper> allClients;
+  private boolean allClientsSetup = false;
 
-    protected TestableZooKeeper createClient(CountdownWatcher watcher,
-            String hp, int timeout)
-        throws IOException, InterruptedException
-    {
-        watcher.reset();
-        TestableZooKeeper zk = new TestableZooKeeper(hp, timeout, watcher);
-        if (!watcher.clientConnected.await(timeout, TimeUnit.MILLISECONDS))
-        {
-            Assert.fail("Unable to connect to server");
-        }
-        synchronized(this) {
-            if (!allClientsSetup) {
-                LOG.error("allClients never setup");
-                Assert.fail("allClients never setup");
-            }
-            if (allClients != null) {
-                allClients.add(zk);
-            } else {
-                // test done - close the zk, not needed
-                zk.close();
-            }
-        }
-        watcher.initializeWatchedClient(zk);
-        return zk;
-    }
+  protected TestableZooKeeper createClient(CountdownWatcher watcher, String hp)
+      throws IOException, InterruptedException {
+    return createClient(watcher, hp, CONNECTION_TIMEOUT);
+  }
 
-    public static class HostPort {
-        String host;
-        int port;
-        public HostPort(String host, int port) {
-            this.host = host;
-            this.port = port;
-        }
+  protected TestableZooKeeper createClient(CountdownWatcher watcher,
+      String hp, int timeout) throws IOException, InterruptedException {
+    watcher.reset();
+    TestableZooKeeper zk = new TestableZooKeeper(hp, timeout, watcher);
+    if (!watcher.clientConnected.await(timeout, TimeUnit.MILLISECONDS)) {
+      fail("Unable to connect to server");
     }
-    public static List<HostPort> parseHostPortList(String hplist) {
-        ArrayList<HostPort> alist = new ArrayList<HostPort>();
-        for (String hp: hplist.split(",")) {
-            int idx = hp.lastIndexOf(':');
-            String host = hp.substring(0, idx);
-            int port;
-            try {
-                port = Integer.parseInt(hp.substring(idx + 1));
-            } catch(RuntimeException e) {
-                throw new RuntimeException("Problem parsing " + hp + e.toString());
-            }
-            alist.add(new HostPort(host,port));
-        }
-        return alist;
+    synchronized (this) {
+      if (!allClientsSetup) {
+        LOG.error("allClients never setup");
+        fail("allClients never setup");
+      }
+      if (allClients != null) {
+        allClients.add(zk);
+      } else {
+        // test done - close the zk, not needed
+        zk.close();
+      }
     }
+    watcher.initializeWatchedClient(zk);
+    return zk;
+  }
 
-    /**
-     * Send the 4letterword
-     * @param host the destination host
-     * @param port the destination port
-     * @param cmd the 4letterword
-     * @return
-     * @throws IOException
-     */
-    public static String send4LetterWord(String host, int port, String cmd)
-        throws IOException
-    {
-        LOG.info("connecting to " + host + " " + port);
-        Socket sock = new Socket(host, port);
-        BufferedReader reader = null;
-        try {
-            OutputStream outstream = sock.getOutputStream();
-            outstream.write(cmd.getBytes());
-            outstream.flush();
-            // this replicates NC - close the output stream before reading
-            sock.shutdownOutput();
-
-            reader =
-                new BufferedReader(
-                        new InputStreamReader(sock.getInputStream()));
-            StringBuilder sb = new StringBuilder();
-            String line;
-            while((line = reader.readLine()) != null) {
-                sb.append(line + "\n");
-            }
-            return sb.toString();
-        } finally {
-            sock.close();
-            if (reader != null) {
-                reader.close();
-            }
-        }
+  public static class HostPort {
+    String host;
+    int port;
+    public HostPort(String host, int port) {
+      this.host = host;
+      this.port = port;
     }
+  }
 
-    public static boolean waitForServerUp(String hp, long timeout) {
-        long start = Time.now();
-        while (true) {
-            try {
-                // if there are multiple hostports, just take the first one
-                HostPort hpobj = parseHostPortList(hp).get(0);
-                String result = send4LetterWord(hpobj.host, hpobj.port, "stat");
-                if (result.startsWith("Zookeeper version:") &&
-                        !result.contains("READ-ONLY")) {
-                    return true;
-                }
-            } catch (IOException e) {
-                // ignore as this is expected
-                LOG.info("server " + hp + " not up " + e);
-            }
+  public static List<HostPort> parseHostPortList(String hplist) {
+    ArrayList<HostPort> alist = new ArrayList<HostPort>();
+    for (String hp: hplist.split(",")) {
+      int idx = hp.lastIndexOf(':');
+      String host = hp.substring(0, idx);
+      int port;
+      try {
+        port = Integer.parseInt(hp.substring(idx + 1));
+      } catch(RuntimeException e) {
+        throw new RuntimeException("Problem parsing " + hp + e.toString());
+      }
+      alist.add(new HostPort(host, port));
+    }
+    return alist;
+  }
 
-            if (Time.now() > start + timeout) {
-                break;
-            }
-            try {
-                Thread.sleep(250);
-            } catch (InterruptedException e) {
-                // ignore
-            }
-        }
-        return false;
+  /**
+   * Send the 4letterword.
+   * @param host the destination host
+   * @param port the destination port
+   * @param cmd the 4letterword
+   * @return
+   * @throws IOException
+   */
+  public static String send4LetterWord(String host, int port, String cmd)
+      throws IOException {
+    LOG.info("connecting to " + host + " " + port);
+    Socket sock = new Socket(host, port);
+    BufferedReader reader = null;
+    try {
+      OutputStream outstream = sock.getOutputStream();
+      outstream.write(cmd.getBytes());
+      outstream.flush();
+      // this replicates NC - close the output stream before reading
+      sock.shutdownOutput();
+      reader = new BufferedReader(
+          new InputStreamReader(sock.getInputStream()));
+      StringBuilder sb = new StringBuilder();
+      String line;
+      while((line = reader.readLine()) != null) {
+        sb.append(line + "\n");
+      }
+      return sb.toString();
+    } finally {
+      sock.close();
+      if (reader != null) {
+        reader.close();
+      }
     }
-    public static boolean waitForServerDown(String hp, long timeout) {
-        long start = Time.now();
-        while (true) {
-            try {
-                HostPort hpobj = parseHostPortList(hp).get(0);
-                send4LetterWord(hpobj.host, hpobj.port, "stat");
-            } catch (IOException e) {
-                return true;
-            }
+  }
 
-            if (Time.now() > start + timeout) {
-                break;
-            }
-            try {
-                Thread.sleep(250);
-            } catch (InterruptedException e) {
-                // ignore
-            }
+  public static boolean waitForServerUp(String hp, long timeout) {
+    long start = Time.now();
+    while (true) {
+      try {
+        // if there are multiple hostports, just take the first one
+        HostPort hpobj = parseHostPortList(hp).get(0);
+        String result = send4LetterWord(hpobj.host, hpobj.port, "stat");
+        if (result.startsWith("Zookeeper version:") &&
+            !result.contains("READ-ONLY")) {
+          return true;
         }
-        return false;
+      } catch (IOException e) {
+        // ignore as this is expected
+        LOG.info("server " + hp + " not up " + e);
+      }
+
+      if (Time.now() > start + timeout) {
+        break;
+      }
+      try {
+        Thread.sleep(250);
+      } catch (InterruptedException e) {
+        // ignore
+      }
     }
+    return false;
+  }
 
-    public static File createTmpDir() throws IOException {
-        return createTmpDir(BASETEST);
-    }
-    static File createTmpDir(File parentDir) throws IOException {
-        File tmpFile = File.createTempFile("test", ".junit", parentDir);
-        // don't delete tmpFile - this ensures we don't attempt to create
-        // a tmpDir with a duplicate name
-        File tmpDir = new File(tmpFile + ".dir");
-        Assert.assertFalse(tmpDir.exists()); // never true if tmpfile does it's job
-        Assert.assertTrue(tmpDir.mkdirs());
-
-        return tmpDir;
+  public static boolean waitForServerDown(String hp, long timeout) {
+    long start = Time.now();
+    while (true) {
+      try {
+        HostPort hpobj = parseHostPortList(hp).get(0);
+        send4LetterWord(hpobj.host, hpobj.port, "stat");
+      } catch (IOException e) {
+        return true;
+      }
+
+      if (Time.now() > start + timeout) {
+        break;
+      }
+
+      try {
+        Thread.sleep(250);
+      } catch (InterruptedException e) {
+        // ignore
+      }
     }
+    return false;
+  }
 
-    private static int getPort(String hostPort) {
-        String[] split = hostPort.split(":");
-        String portstr = split[split.length-1];
-        String[] pc = portstr.split("/");
-        if (pc.length > 1) {
-            portstr = pc[0];
-        }
-        return Integer.parseInt(portstr);
-    }
+  public static File createTmpDir() throws IOException {
+    return createTmpDir(BASETEST);
+  }
 
-    static ServerCnxnFactory createNewServerInstance(File dataDir,
-            ServerCnxnFactory factory, String hostPort, int maxCnxns)
-        throws IOException, InterruptedException
-    {
-        ZooKeeperServer zks = new ZooKeeperServer(dataDir, dataDir, 3000);
-        final int PORT = getPort(hostPort);
-        if (factory == null) {
-            factory = ServerCnxnFactory.createFactory(PORT, maxCnxns);
-        }
-        factory.startup(zks);
-        Assert.assertTrue("waiting for server up",
-                   ClientBaseWithFixes.waitForServerUp("127.0.0.1:" + PORT,
-                                              CONNECTION_TIMEOUT));
+  static File createTmpDir(File parentDir) throws IOException {
+    File tmpFile = File.createTempFile("test", ".junit", parentDir);
+    // don't delete tmpFile - this ensures we don't attempt to create
+    // a tmpDir with a duplicate name
+    File tmpDir = new File(tmpFile + ".dir");
+    assertFalse(tmpDir.exists()); // never true if tmpfile does it's job
+    assertTrue(tmpDir.mkdirs());
+    return tmpDir;
+  }
 
-        return factory;
+  private static int getPort(String hostPort) {
+    String[] split = hostPort.split(":");
+    String portstr = split[split.length-1];
+    String[] pc = portstr.split("/");
+    if (pc.length > 1) {
+      portstr = pc[0];
     }
+    return Integer.parseInt(portstr);
+  }
 
-    static void shutdownServerInstance(ServerCnxnFactory factory,
-            String hostPort)
-    {
-        if (factory != null) {
-            ZKDatabase zkDb;
-            {
-                ZooKeeperServer zs = getServer(factory);
-        
-                zkDb = zs.getZKDatabase();
-            }
-            factory.shutdown();
-            try {
-                zkDb.close();
-            } catch (IOException ie) {
-                LOG.warn("Error closing logs ", ie);
-            }
-            final int PORT = getPort(hostPort);
-
-            Assert.assertTrue("waiting for server down",
-                       ClientBaseWithFixes.waitForServerDown("127.0.0.1:" + PORT,
-                                                    CONNECTION_TIMEOUT));
-        }
+  static ServerCnxnFactory createNewServerInstance(File dataDir,
+      ServerCnxnFactory factory, String hostPort, int maxCnxns)
+      throws IOException, InterruptedException {
+    ZooKeeperServer zks = new ZooKeeperServer(dataDir, dataDir, 3000);
+    final int port = getPort(hostPort);
+    if (factory == null) {
+      factory = ServerCnxnFactory.createFactory(port, maxCnxns);
     }
+    factory.startup(zks);
+    assertTrue(ClientBaseWithFixes.waitForServerUp("127.0.0.1:" + port,
+        CONNECTION_TIMEOUT), "waiting for server up");
+    return factory;
+  }
 
-    /**
-     * Test specific setup
-     */
-    public static void setupTestEnv() {
-        // during the tests we run with 100K prealloc in the logs.
-        // on windows systems prealloc of 64M was seen to take ~15seconds
-        // resulting in test Assert.failure (client timeout on first session).
-        // set env and directly in order to handle static init/gc issues
-        System.setProperty("zookeeper.preAllocSize", "100");
-        FileTxnLog.setPreallocSize(100 * 1024);
+  static void shutdownServerInstance(ServerCnxnFactory factory,
+      String hostPort) {
+    if (factory != null) {
+      ZKDatabase zkDb;
+      ZooKeeperServer zs = getServer(factory);
+      zkDb = zs.getZKDatabase();
+      factory.shutdown();
+      try {
+        zkDb.close();
+      } catch (IOException ie) {
+        LOG.warn("Error closing logs ", ie);
+      }
+      final int port = getPort(hostPort);
+      assertTrue(ClientBaseWithFixes.waitForServerDown("127.0.0.1:" + port,
+          CONNECTION_TIMEOUT), "waiting for server down");
     }
+  }
 
-    protected void setUpAll() throws Exception {
-        allClients = new LinkedList<ZooKeeper>();
-        allClientsSetup = true;
-    }
+  /**
+   * Test specific setup.
+   */
+  public static void setupTestEnv() {
+    // during the tests we run with 100K prealloc in the logs.
+    // on windows systems prealloc of 64M was seen to take ~15seconds
+    // resulting in test failure (client timeout on first session).
+    // set env and directly in order to handle static init/gc issues
+    System.setProperty("zookeeper.preAllocSize", "100");
+    FileTxnLog.setPreallocSize(100 * 1024);
+  }
 
-    @Before
-    public void setUp() throws Exception {
-        BASETEST.mkdirs();
+  protected void setUpAll() throws Exception {
+    allClients = new LinkedList<ZooKeeper>();
+    allClientsSetup = true;
+  }
 
-        setupTestEnv();
+  @BeforeEach
+  public void setUp() throws Exception {
+    BASETEST.mkdirs();
 
-        setUpAll();
+    setupTestEnv();
 
-        tmpDir = createTmpDir(BASETEST);
+    setUpAll();
 
-        startServer();
+    tmpDir = createTmpDir(BASETEST);
 
-        LOG.info("Client test setup finished");
-    }
+    startServer();
 
-    private String initHostPort() {
-        BASETEST.mkdirs();
-        int port = 0;
-        try {
-           port = ServerSocketUtil.getPort(port, 100);
-        } catch (IOException e) {
-           throw new RuntimeException(e);
-        }
-        return "127.0.0.1:" + port;
-    }
+    LOG.info("Client test setup finished");
+  }
 
-    protected void startServer() throws Exception {
-        LOG.info("STARTING server");
-        serverFactory = createNewServerInstance(tmpDir, serverFactory, hostPort, maxCnxns);
+  private String initHostPort() {
+    BASETEST.mkdirs();
+    int port = 0;
+    try {
+      port = ServerSocketUtil.getPort(port, 100);
+    } catch (IOException e) {
+      throw new RuntimeException(e);
     }
+    return "127.0.0.1:" + port;
+  }
 
-    protected void stopServer() throws Exception {
-        LOG.info("STOPPING server");
-        shutdownServerInstance(serverFactory, hostPort);
-        serverFactory = null;
-    }
+  protected void startServer() throws Exception {
+    LOG.info("STARTING server");
+    serverFactory = createNewServerInstance(tmpDir, serverFactory, hostPort, maxCnxns);
+  }
 
+  protected void stopServer() throws Exception {
+    LOG.info("STOPPING server");
+    shutdownServerInstance(serverFactory, hostPort);
+    serverFactory = null;
+  }
 
-    protected static ZooKeeperServer getServer(ServerCnxnFactory fac) {
-        return fac.getZooKeeperServer();
-    }
+  protected static ZooKeeperServer getServer(ServerCnxnFactory fac) {
+    return fac.getZooKeeperServer();
+  }
 
-    protected void tearDownAll() throws Exception {
-        synchronized (this) {
-            if (allClients != null) for (ZooKeeper zk : allClients) {
-                try {
-                    if (zk != null)
-                        zk.close();
-                } catch (InterruptedException e) {
-                    LOG.warn("ignoring interrupt", e);
-                }
+  protected void tearDownAll() throws Exception {
+    synchronized (this) {
+      if (allClients != null) for (ZooKeeper zk : allClients) {
+        try {
+            if (zk != null) {
+              zk.close();
             }
-            allClients = null;
+          } catch (InterruptedException e) {
+            LOG.warn("ignoring interrupt", e);
         }
+      }
+      allClients = null;
     }
+  }
 
-    @After
-    public void tearDown() throws Exception {
-        LOG.info("tearDown starting");
-
-        tearDownAll();
+  @AfterEach
+  public void tearDown() throws Exception {
+    LOG.info("tearDown starting");
 
-        stopServer();
+    tearDownAll();
 
-        if (tmpDir != null) {
-            Assert.assertTrue("delete " + tmpDir.toString(), recursiveDelete(tmpDir));
-        }
+    stopServer();
 
-        // This has to be set to null when the same instance of this class is reused between test cases
-        serverFactory = null;
+    if (tmpDir != null) {
+      assertTrue(recursiveDelete(tmpDir), "delete " + tmpDir.toString());
     }
 
-    public static boolean recursiveDelete(File d) {
-        if (d.isDirectory()) {
-            File children[] = d.listFiles();
-            for (File f : children) {
-                Assert.assertTrue("delete " + f.toString(), recursiveDelete(f));
-            }
-        }
-        return d.delete();
+    // This has to be set to null when the same instance of this class is reused between test cases
+    serverFactory = null;
+  }
+
+  public static boolean recursiveDelete(File d) {
+    if (d.isDirectory()) {
+      File[] children = d.listFiles();
+      for (File f : children) {
+        assertTrue(recursiveDelete(f), "delete " + f.toString());
+      }
     }
+    return d.delete();
+  }
 }

+ 47 - 35
hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/ha/TestActiveStandbyElectorRealZK.java

@@ -18,8 +18,14 @@
 
 package org.apache.hadoop.ha;
 
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.Mockito.anyString;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.timeout;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.reset;
 
 import java.util.Collections;
 import java.util.UUID;
@@ -33,9 +39,10 @@ import org.apache.zookeeper.CreateMode;
 import org.apache.zookeeper.ZooDefs.Ids;
 import org.apache.zookeeper.ZooKeeper;
 import org.apache.zookeeper.server.ZooKeeperServer;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.Timeout;
 import org.mockito.AdditionalMatchers;
-import org.mockito.Mockito;
 
 import org.apache.hadoop.thirdparty.com.google.common.primitives.Ints;
 import org.slf4j.event.Level;
@@ -58,7 +65,7 @@ public class TestActiveStandbyElectorRealZK extends ClientBaseWithFixes {
       new ActiveStandbyElectorCallback[NUM_ELECTORS];
   private ZooKeeperServer zkServer;
 
-  
+  @BeforeEach
   @Override
   public void setUp() throws Exception {
     super.setUp();
@@ -66,7 +73,7 @@ public class TestActiveStandbyElectorRealZK extends ClientBaseWithFixes {
     zkServer = getServer(serverFactory);
 
     for (int i = 0; i < NUM_ELECTORS; i++) {
-      cbs[i] =  Mockito.mock(ActiveStandbyElectorCallback.class);
+      cbs[i] = mock(ActiveStandbyElectorCallback.class);
       appDatas[i] = Ints.toByteArray(i);
       electors[i] = new ActiveStandbyElector(hostPort, 5000, PARENT_DIR,
           Ids.OPEN_ACL_UNSAFE, Collections.<ZKAuthInfo> emptyList(), cbs[i],
@@ -76,9 +83,9 @@ public class TestActiveStandbyElectorRealZK extends ClientBaseWithFixes {
   
   private void checkFatalsAndReset() throws Exception {
     for (int i = 0; i < NUM_ELECTORS; i++) {
-      Mockito.verify(cbs[i], Mockito.never()).notifyFatalError(
-          Mockito.anyString());
-      Mockito.reset(cbs[i]);
+      verify(cbs[i], never()).notifyFatalError(
+          anyString());
+      reset(cbs[i]);
     }
   }
 
@@ -88,7 +95,8 @@ public class TestActiveStandbyElectorRealZK extends ClientBaseWithFixes {
    * Upon becoming active the leader quits election and the test verifies that
    * the standby now becomes active.
    */
-  @Test(timeout=20000)
+  @Test
+  @Timeout(value = 20)
   public void testActiveStandbyTransition() throws Exception {
     LOG.info("starting test with parentDir:" + PARENT_DIR);
 
@@ -100,24 +108,24 @@ public class TestActiveStandbyElectorRealZK extends ClientBaseWithFixes {
     electors[0].joinElection(appDatas[0]);
     ActiveStandbyElectorTestUtil.waitForActiveLockData(null,
         zkServer, PARENT_DIR, appDatas[0]);
-    Mockito.verify(cbs[0], Mockito.timeout(1000)).becomeActive();
+    verify(cbs[0], timeout(1000)).becomeActive();
     checkFatalsAndReset();
 
     // Second elector joins election, becomes standby.
     electors[1].joinElection(appDatas[1]);
-    Mockito.verify(cbs[1], Mockito.timeout(1000)).becomeStandby();
+    verify(cbs[1], timeout(1000)).becomeStandby();
     checkFatalsAndReset();
     
     // First elector quits, second one should become active
     electors[0].quitElection(true);
     ActiveStandbyElectorTestUtil.waitForActiveLockData(null,
         zkServer, PARENT_DIR, appDatas[1]);
-    Mockito.verify(cbs[1], Mockito.timeout(1000)).becomeActive();
+    verify(cbs[1], timeout(1000)).becomeActive();
     checkFatalsAndReset();
     
     // First one rejoins, becomes standby, second one stays active
     electors[0].joinElection(appDatas[0]);
-    Mockito.verify(cbs[0], Mockito.timeout(1000)).becomeStandby();
+    verify(cbs[0], timeout(1000)).becomeStandby();
     checkFatalsAndReset();
     
     // Second one expires, first one becomes active
@@ -127,16 +135,16 @@ public class TestActiveStandbyElectorRealZK extends ClientBaseWithFixes {
       
       ActiveStandbyElectorTestUtil.waitForActiveLockData(null,
           zkServer, PARENT_DIR, appDatas[0]);
-      Mockito.verify(cbs[1], Mockito.timeout(1000)).enterNeutralMode();
-      Mockito.verify(cbs[0], Mockito.timeout(1000)).fenceOldActive(
+      verify(cbs[1], timeout(1000)).enterNeutralMode();
+      verify(cbs[0], timeout(1000)).fenceOldActive(
           AdditionalMatchers.aryEq(appDatas[1]));
-      Mockito.verify(cbs[0], Mockito.timeout(1000)).becomeActive();
+      verify(cbs[0], timeout(1000)).becomeActive();
     } finally {
       electors[1].allowSessionReestablishmentForTests();
     }
     
     // Second one eventually reconnects and becomes standby
-    Mockito.verify(cbs[1], Mockito.timeout(5000)).becomeStandby();
+    verify(cbs[1], timeout(5000)).becomeStandby();
     checkFatalsAndReset();
     
     // First one expires, second one should become active
@@ -146,10 +154,10 @@ public class TestActiveStandbyElectorRealZK extends ClientBaseWithFixes {
       
       ActiveStandbyElectorTestUtil.waitForActiveLockData(null,
           zkServer, PARENT_DIR, appDatas[1]);
-      Mockito.verify(cbs[0], Mockito.timeout(1000)).enterNeutralMode();
-      Mockito.verify(cbs[1], Mockito.timeout(1000)).fenceOldActive(
+      verify(cbs[0], timeout(1000)).enterNeutralMode();
+      verify(cbs[1], timeout(1000)).fenceOldActive(
           AdditionalMatchers.aryEq(appDatas[0]));
-      Mockito.verify(cbs[1], Mockito.timeout(1000)).becomeActive();
+      verify(cbs[1], timeout(1000)).becomeActive();
     } finally {
       electors[0].allowSessionReestablishmentForTests();
     }
@@ -157,7 +165,8 @@ public class TestActiveStandbyElectorRealZK extends ClientBaseWithFixes {
     checkFatalsAndReset();
   }
   
-  @Test(timeout=15000)
+  @Test
+  @Timeout(value = 15)
   public void testHandleSessionExpiration() throws Exception {
     ActiveStandbyElectorCallback cb = cbs[0];
     byte[] appData = appDatas[0];
@@ -169,19 +178,19 @@ public class TestActiveStandbyElectorRealZK extends ClientBaseWithFixes {
     ZooKeeperServer zks = getServer(serverFactory);
     ActiveStandbyElectorTestUtil.waitForActiveLockData(null,
         zks, PARENT_DIR, appData);
-    Mockito.verify(cb, Mockito.timeout(1000)).becomeActive();
+    verify(cb, timeout(1000)).becomeActive();
     checkFatalsAndReset();
     
     LOG.info("========================== Expiring session");
     zks.closeSession(elector.getZKSessionIdForTests());
 
     // Should enter neutral mode when disconnected
-    Mockito.verify(cb, Mockito.timeout(1000)).enterNeutralMode();
+    verify(cb, timeout(1000)).enterNeutralMode();
 
     // Should re-join the election and regain active
     ActiveStandbyElectorTestUtil.waitForActiveLockData(null,
         zks, PARENT_DIR, appData);
-    Mockito.verify(cb, Mockito.timeout(1000)).becomeActive();
+    verify(cb, timeout(1000)).becomeActive();
     checkFatalsAndReset();
     
     LOG.info("========================== Quitting election");
@@ -192,14 +201,15 @@ public class TestActiveStandbyElectorRealZK extends ClientBaseWithFixes {
     // Double check that we don't accidentally re-join the election
     // due to receiving the "expired" event.
     Thread.sleep(1000);
-    Mockito.verify(cb, Mockito.never()).becomeActive();
+    verify(cb, never()).becomeActive();
     ActiveStandbyElectorTestUtil.waitForActiveLockData(null,
         zks, PARENT_DIR, null);
 
     checkFatalsAndReset();
   }
   
-  @Test(timeout=15000)
+  @Test
+  @Timeout(value = 15)
   public void testHandleSessionExpirationOfStandby() throws Exception {
     // Let elector 0 be active
     electors[0].ensureParentZNode();
@@ -207,7 +217,7 @@ public class TestActiveStandbyElectorRealZK extends ClientBaseWithFixes {
     ZooKeeperServer zks = getServer(serverFactory);
     ActiveStandbyElectorTestUtil.waitForActiveLockData(null,
         zks, PARENT_DIR, appDatas[0]);
-    Mockito.verify(cbs[0], Mockito.timeout(1000)).becomeActive();
+    verify(cbs[0], timeout(1000)).becomeActive();
     checkFatalsAndReset();
     
     // Let elector 1 be standby
@@ -219,7 +229,7 @@ public class TestActiveStandbyElectorRealZK extends ClientBaseWithFixes {
     zks.closeSession(electors[1].getZKSessionIdForTests());
 
     // Should enter neutral mode when disconnected
-    Mockito.verify(cbs[1], Mockito.timeout(1000)).enterNeutralMode();
+    verify(cbs[1], timeout(1000)).enterNeutralMode();
 
     // Should re-join the election and go back to STANDBY
     ActiveStandbyElectorTestUtil.waitForElectorState(null, electors[1],
@@ -235,14 +245,15 @@ public class TestActiveStandbyElectorRealZK extends ClientBaseWithFixes {
     
     // due to receiving the "expired" event.
     Thread.sleep(1000);
-    Mockito.verify(cbs[1], Mockito.never()).becomeActive();
+    verify(cbs[1], never()).becomeActive();
     ActiveStandbyElectorTestUtil.waitForActiveLockData(null,
         zks, PARENT_DIR, null);
 
     checkFatalsAndReset();
   }
 
-  @Test(timeout=15000)
+  @Test
+  @Timeout(value = 15)
   public void testDontJoinElectionOnDisconnectAndReconnect() throws Exception {
     electors[0].ensureParentZNode();
 
@@ -253,8 +264,8 @@ public class TestActiveStandbyElectorRealZK extends ClientBaseWithFixes {
     waitForServerUp(hostPort, CONNECTION_TIMEOUT);
     // Have to sleep to allow time for the clients to reconnect.
     Thread.sleep(2000);
-    Mockito.verify(cbs[0], Mockito.never()).becomeActive();
-    Mockito.verify(cbs[1], Mockito.never()).becomeActive();
+    verify(cbs[0], never()).becomeActive();
+    verify(cbs[1], never()).becomeActive();
     checkFatalsAndReset();
   }
 
@@ -262,11 +273,12 @@ public class TestActiveStandbyElectorRealZK extends ClientBaseWithFixes {
    * Test to verify that proper ZooKeeper ACLs can be updated on
    * ActiveStandbyElector's parent znode.
    */
-  @Test(timeout = 15000)
+  @Test
+  @Timeout(value = 15)
   public void testSetZooKeeperACLsOnParentZnodeName()
       throws Exception {
     ActiveStandbyElectorCallback cb =
-        Mockito.mock(ActiveStandbyElectorCallback.class);
+        mock(ActiveStandbyElectorCallback.class);
     ActiveStandbyElector elector =
         new ActiveStandbyElector(hostPort, 5000, PARENT_DIR,
             Ids.READ_ACL_UNSAFE, Collections.<ZKAuthInfo>emptyList(), cb,

+ 27 - 26
hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/ha/TestZKFailoverController.java

@@ -17,12 +17,19 @@
  */
 package org.apache.hadoop.ha;
 
-import static org.junit.Assert.*;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.fail;
+import static org.mockito.ArgumentMatchers.same;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.doThrow;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.timeout;
+import static org.mockito.Mockito.verify;
 
 import java.net.InetSocketAddress;
 import java.security.NoSuchAlgorithmException;
 
-import java.util.concurrent.TimeUnit;
 import java.util.function.Supplier;
 import org.apache.hadoop.HadoopIllegalArgumentException;
 import org.apache.hadoop.conf.Configuration;
@@ -41,24 +48,18 @@ import org.apache.zookeeper.KeeperException;
 import org.apache.zookeeper.ZooKeeper;
 import org.apache.zookeeper.data.Stat;
 import org.apache.zookeeper.server.auth.DigestAuthenticationProvider;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.Timeout;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.Timeout;
 import org.mockito.Mockito;
 import org.slf4j.event.Level;
 
+@Timeout(180)
 public class TestZKFailoverController extends ClientBaseWithFixes {
   private Configuration conf;
   private MiniZKFCCluster cluster;
 
-  /**
-   * Set the timeout for every test
-   */
-  @Rule
-  public Timeout testTimeout = new Timeout(3, TimeUnit.MINUTES);
-
   // Set up ZK digest-based credentials for the purposes of the tests,
   // to make sure all of our functionality works with auth and ACLs
   // present.
@@ -81,7 +82,7 @@ public class TestZKFailoverController extends ClientBaseWithFixes {
     GenericTestUtils.setLogLevel(ActiveStandbyElector.LOG, Level.TRACE);
   }
   
-  @Before
+  @BeforeEach
   public void setupConfAndServices() {
     conf = new Configuration();
     conf.set(ZKFailoverController.ZK_ACL_KEY, TEST_ACL);
@@ -91,7 +92,7 @@ public class TestZKFailoverController extends ClientBaseWithFixes {
     this.cluster = new MiniZKFCCluster(conf, getServer(serverFactory));
   }
 
-  @After
+  @AfterEach
   public void teardown() {
     if (cluster != null) {
       try {
@@ -216,8 +217,8 @@ public class TestZKFailoverController extends ClientBaseWithFixes {
   @Test
   public void testWontRunWhenAutoFailoverDisabled() throws Exception {
     DummyHAService svc = cluster.getService(1);
-    svc = Mockito.spy(svc);
-    Mockito.doReturn(false).when(svc).isAutoFailoverEnabled();
+    svc = spy(svc);
+    doReturn(false).when(svc).isAutoFailoverEnabled();
     
     assertEquals(ZKFailoverController.ERR_CODE_AUTO_FAILOVER_NOT_ENABLED,
         runFC(svc, "-formatZK"));
@@ -253,8 +254,8 @@ public class TestZKFailoverController extends ClientBaseWithFixes {
    */
   @Test
   public void testFencingMustBeConfigured() throws Exception {
-    DummyHAService svc = Mockito.spy(cluster.getService(0));
-    Mockito.doThrow(new BadFencingConfigurationException("no fencing"))
+    DummyHAService svc = spy(cluster.getService(0));
+    doThrow(new BadFencingConfigurationException("no fencing"))
         .when(svc).checkFencingConfigured();
     // Format the base dir, should succeed
     assertEquals(0, runFC(svc, "-formatZK"));
@@ -289,7 +290,7 @@ public class TestZKFailoverController extends ClientBaseWithFixes {
     // Should fail back to svc0 at this point
     cluster.waitForHAState(0, HAServiceState.ACTIVE);
     // and fence svc1
-    Mockito.verify(svc1.fencer).fence(Mockito.same(svc1));
+    verify(svc1.fencer).fence(same(svc1));
   }
 
   /**
@@ -394,7 +395,7 @@ public class TestZKFailoverController extends ClientBaseWithFixes {
     cluster.waitForActiveLockHolder(null);
 
 
-    Mockito.verify(svc1.proxy, Mockito.timeout(2000).atLeastOnce())
+    verify(svc1.proxy, timeout(2000).atLeastOnce())
       .transitionToActive(Mockito.<StateChangeRequestInfo>any());
 
     cluster.waitForHAState(0, HAServiceState.INITIALIZING);
@@ -476,8 +477,8 @@ public class TestZKFailoverController extends ClientBaseWithFixes {
     long st = Time.now();
     proxy.cedeActive(3000);
     long et = Time.now();
-    assertTrue("RPC to cedeActive took " + (et - st) + " ms",
-        et - st < 1000);
+    assertTrue(et - st < 1000,
+        "RPC to cedeActive took " + (et - st) + " ms");
 
     // Should be in "INIT" state since it's not in the election
     // at this point.
@@ -488,9 +489,9 @@ public class TestZKFailoverController extends ClientBaseWithFixes {
     // since the other node in the cluster would have taken ACTIVE.
     cluster.waitForElectorState(0, ActiveStandbyElector.State.STANDBY);
     long et2 = Time.now();
-    assertTrue("Should take ~3 seconds to rejoin. Only took " + (et2 - et) +
-        "ms before rejoining.",
-        et2 - et > 2800);
+    assertTrue(et2 - et > 2800,
+        "Should take ~3 seconds to rejoin. Only took " + (et2 - et) +
+        "ms before rejoining.");
   }
 
   @Test

+ 12 - 8
hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/ha/TestZKFailoverControllerStress.java

@@ -24,9 +24,10 @@ import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.fs.CommonConfigurationKeys;
 import org.apache.hadoop.util.Time;
 import org.apache.zookeeper.server.ServerCnxn;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.Timeout;
 import org.mockito.Mockito;
 import org.mockito.invocation.InvocationOnMock;
 import org.mockito.stubbing.Answer;
@@ -45,14 +46,14 @@ public class TestZKFailoverControllerStress extends ClientBaseWithFixes {
   private Configuration conf;
   private MiniZKFCCluster cluster;
 
-  @Before
+  @BeforeEach
   public void setupConfAndServices() throws Exception {
     conf = new Configuration();
     conf.set(ZKFailoverController.ZK_QUORUM_KEY, hostPort);
     this.cluster = new MiniZKFCCluster(conf, getServer(serverFactory));
   }
   
-  @After
+  @AfterEach
   public void stopCluster() throws Exception {
     if (cluster != null) {
       cluster.stop();
@@ -63,7 +64,8 @@ public class TestZKFailoverControllerStress extends ClientBaseWithFixes {
    * Simply fail back and forth between two services for the
    * configured amount of time, via expiring their ZK sessions.
    */
-  @Test(timeout=(STRESS_RUNTIME_SECS + EXTRA_TIMEOUT_SECS) * 1000)
+  @Test
+  @Timeout(STRESS_RUNTIME_SECS + EXTRA_TIMEOUT_SECS)
   public void testExpireBackAndForth() throws Exception {
     cluster.start();
     long st = Time.now();
@@ -89,7 +91,8 @@ public class TestZKFailoverControllerStress extends ClientBaseWithFixes {
    * we just do random expirations and expect neither one to ever
    * generate fatal exceptions.
    */
-  @Test(timeout=(STRESS_RUNTIME_SECS + EXTRA_TIMEOUT_SECS) * 1000)
+  @Test
+  @Timeout(STRESS_RUNTIME_SECS + EXTRA_TIMEOUT_SECS)
   public void testRandomExpirations() throws Exception {
     cluster.start();
     long st = Time.now();
@@ -116,7 +119,8 @@ public class TestZKFailoverControllerStress extends ClientBaseWithFixes {
    * cluster. Meanwhile, causes ZK to disconnect clients every
    * 50ms, to trigger the retry code and failures to become active.
    */
-  @Test(timeout=(STRESS_RUNTIME_SECS + EXTRA_TIMEOUT_SECS) * 1000)
+  @Test
+  @Timeout(STRESS_RUNTIME_SECS + EXTRA_TIMEOUT_SECS)
   public void testRandomHealthAndDisconnects() throws Exception {
     long runFor = STRESS_RUNTIME_SECS * 1000;
     Mockito.doAnswer(new RandomlyThrow(0))

+ 4 - 4
hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/metrics2/impl/MetricsRecords.java

@@ -24,8 +24,8 @@ import org.apache.hadoop.metrics2.AbstractMetric;
 import org.apache.hadoop.metrics2.MetricsRecord;
 import org.apache.hadoop.metrics2.MetricsTag;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
 
 /**
  * Utility class mainly for tests
@@ -61,8 +61,8 @@ public class MetricsRecords {
       String metricName) {
     AbstractMetric resourceLimitMetric = getFirstMetricByName(
         record, metricName);
-    assertNotNull("Metric " + metricName + " doesn't exist",
-        resourceLimitMetric);
+    assertNotNull(resourceLimitMetric,
+        "Metric " + metricName + " doesn't exist");
   }
 
   private static MetricsTag getFirstTagByName(MetricsRecord record,

+ 25 - 22
hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/metrics2/sink/RollingFileSystemSinkTestBase.java

@@ -54,12 +54,12 @@ import org.apache.hadoop.metrics2.impl.TestMetricsConfig;
 import org.apache.hadoop.metrics2.lib.MutableGaugeInt;
 import org.apache.hadoop.metrics2.lib.MutableGaugeLong;
 import org.apache.hadoop.test.GenericTestUtils;
-import org.junit.AfterClass;
-import org.junit.Rule;
-import org.junit.rules.TestName;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import static org.junit.Assert.assertTrue;
+import org.apache.hadoop.test.TestName;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.extension.RegisterExtension;
+import static org.junit.jupiter.api.Assertions.assertTrue;
 
 /**
  * This class is a base class for testing the {@link RollingFileSystemSink}
@@ -78,8 +78,8 @@ public class RollingFileSystemSinkTestBase {
   /**
    * The name of the current test method.
    */
-  @Rule
-  public TestName methodName = new TestName();
+  @RegisterExtension
+  private TestName methodName = new TestName();
 
   /**
    * A sample metric class
@@ -119,7 +119,7 @@ public class RollingFileSystemSinkTestBase {
   /**
    * Set the date format's timezone to GMT.
    */
-  @BeforeClass
+  @BeforeAll
   public static void setup() {
     DATE_FORMAT.setTimeZone(TimeZone.getTimeZone("GMT"));
     FileUtil.fullyDelete(ROOT_TEST_DIR);
@@ -129,7 +129,7 @@ public class RollingFileSystemSinkTestBase {
    * Delete the test directory for this test.
    * @throws IOException thrown if the delete fails
    */
-  @AfterClass
+  @AfterAll
   public static void deleteBaseDir() throws IOException {
     FileUtil.fullyDelete(ROOT_TEST_DIR);
   }
@@ -138,12 +138,11 @@ public class RollingFileSystemSinkTestBase {
    * Create the test directory for this test.
    * @throws IOException thrown if the create fails
    */
-  @Before
+  @BeforeEach
   public void createMethodDir() throws IOException {
     methodDir = new File(ROOT_TEST_DIR, methodName.getMethodName());
 
-    assertTrue("Test directory already exists: " + methodDir,
-        methodDir.mkdirs());
+    assertTrue(methodDir.mkdirs(), "Test directory already exists: " + methodDir);
   }
 
   /**
@@ -265,7 +264,7 @@ public class RollingFileSystemSinkTestBase {
       }
     }
 
-    assertTrue("No valid log directories found", found);
+    assertTrue(found, "No valid log directories found");
 
     return metrics.toString();
   }
@@ -342,8 +341,9 @@ public class RollingFileSystemSinkTestBase {
         + "\\s+testTag22=testTagValue22,\\s+Hostname=.*$[\\n\\r]*",
          Pattern.MULTILINE);
 
-    assertTrue("Sink did not produce the expected output. Actual output was: "
-        + contents, expectedContentPattern.matcher(contents).matches());
+    assertTrue(expectedContentPattern.matcher(contents).matches(),
+        "Sink did not produce the expected output. Actual output was: "
+        + contents);
   }
 
   /**
@@ -366,8 +366,9 @@ public class RollingFileSystemSinkTestBase {
         + "\\s+testTag22=testTagValue22,\\s+Hostname=.*$[\\n\\r]*",
          Pattern.MULTILINE);
 
-    assertTrue("Sink did not produce the expected output. Actual output was: "
-        + contents, expectedContentPattern.matcher(contents).matches());
+    assertTrue(expectedContentPattern.matcher(contents).matches(),
+        "Sink did not produce the expected output. Actual output was: "
+        + contents);
   }
 
   /**
@@ -500,10 +501,12 @@ public class RollingFileSystemSinkTestBase {
       count++;
     }
 
-    assertTrue("The sink created additional unexpected log files. " + count
-        + " files were created", expected >= count);
-    assertTrue("The sink created too few log files. " + count + " files were "
-        + "created", expected <= count);
+    assertTrue(expected >= count,
+        "The sink created additional unexpected log files. " + count
+        + " files were created");
+    assertTrue(expected <= count,
+        "The sink created too few log files. " + count + " files were "
+        + "created");
   }
 
   /**

+ 9 - 9
hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/metrics2/sink/TestRollingFileSystemSinkWithLocal.java

@@ -21,9 +21,9 @@ package org.apache.hadoop.metrics2.sink;
 import org.apache.hadoop.fs.FileUtil;
 import org.apache.hadoop.metrics2.MetricsSystem;
 
-import org.junit.Test;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
+import org.junit.jupiter.api.Test;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
 
 /**
  * Test the {@link RollingFileSystemSink} class in the context of the local file
@@ -114,9 +114,9 @@ public class TestRollingFileSystemSinkWithLocal
       // publish the metrics
       ms.publishMetricsNow();
 
-      assertTrue("No exception was generated while writing metrics "
-          + "even though the target directory was not writable",
-          MockSink.errored);
+      assertTrue(MockSink.errored,
+          "No exception was generated while writing metrics "
+          + "even though the target directory was not writable");
 
       ms.stop();
       ms.shutdown();
@@ -143,10 +143,10 @@ public class TestRollingFileSystemSinkWithLocal
       // publish the metrics
       ms.publishMetricsNow();
 
-      assertFalse("An exception was generated while writing metrics "
+      assertFalse(MockSink.errored,
+          "An exception was generated while writing metrics "
           + "when the target directory was not writable, even though the "
-          + "sink is set to ignore errors",
-          MockSink.errored);
+          + "sink is set to ignore errors");
 
       ms.stop();
       ms.shutdown();

+ 115 - 87
hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/TestUserGroupInformation.java

@@ -33,12 +33,11 @@ import org.apache.hadoop.test.GenericTestUtils;
 import org.apache.hadoop.util.Shell;
 import org.apache.hadoop.util.StringUtils;
 import org.apache.hadoop.util.Time;
-import org.junit.After;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.mockito.Mockito;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.Timeout;
 import org.mockito.invocation.InvocationOnMock;
 import org.mockito.stubbing.Answer;
 import org.slf4j.Logger;
@@ -81,20 +80,21 @@ import static org.apache.hadoop.test.MetricsAsserts.assertGaugeGt;
 import static org.apache.hadoop.test.MetricsAsserts.assertQuantileGauges;
 import static org.apache.hadoop.test.MetricsAsserts.getDoubleGauge;
 import static org.apache.hadoop.test.MetricsAsserts.getMetrics;
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNotSame;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertSame;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNotSame;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertSame;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.fail;
 import static org.mockito.Mockito.atLeastOnce;
 import static org.mockito.Mockito.doThrow;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
 
 public class TestUserGroupInformation {
@@ -134,7 +134,7 @@ public class TestUserGroupInformation {
   }
 
   /** configure ugi */
-  @BeforeClass
+  @BeforeAll
   public static void setup() {
     javax.security.auth.login.Configuration.setConfiguration(
         new DummyLoginConfiguration());
@@ -145,29 +145,32 @@ public class TestUserGroupInformation {
     System.setProperty("hadoop.home.dir", (home != null ? home : "."));
   }
   
-  @Before
+  @BeforeEach
   public void setupUgi() {
     conf = new Configuration();
     UserGroupInformation.reset();
     UserGroupInformation.setConfiguration(conf);
   }
   
-  @After
+  @AfterEach
   public void resetUgi() {
     UserGroupInformation.setLoginUser(null);
   }
 
-  @Test(timeout = 30000)
+  @Test
+  @Timeout(value = 30)
   public void testSimpleLogin() throws IOException {
     tryLoginAuthenticationMethod(AuthenticationMethod.SIMPLE, true);
   }
 
-  @Test (timeout = 30000)
+  @Test
+  @Timeout(value = 30)
   public void testTokenLogin() throws IOException {
     tryLoginAuthenticationMethod(AuthenticationMethod.TOKEN, false);
   }
   
-  @Test (timeout = 30000)
+  @Test
+  @Timeout(value = 30)
   public void testProxyLogin() throws IOException {
     tryLoginAuthenticationMethod(AuthenticationMethod.PROXY, false);
   }
@@ -196,7 +199,8 @@ public class TestUserGroupInformation {
     }
   }
   
-  @Test (timeout = 30000)
+  @Test
+  @Timeout(value = 30)
   public void testGetRealAuthenticationMethod() {
     UserGroupInformation ugi = UserGroupInformation.createRemoteUser("user1");
     ugi.setAuthenticationMethod(AuthenticationMethod.SIMPLE);
@@ -207,7 +211,8 @@ public class TestUserGroupInformation {
     assertEquals(AuthenticationMethod.SIMPLE, ugi.getRealAuthenticationMethod());
   }
   
-  @Test (timeout = 30000)
+  @Test
+  @Timeout(value = 30)
   public void testCreateRemoteUser() {
     UserGroupInformation ugi = UserGroupInformation.createRemoteUser("user1");
     assertEquals(AuthenticationMethod.SIMPLE, ugi.getAuthenticationMethod());
@@ -219,7 +224,8 @@ public class TestUserGroupInformation {
   }
   
   /** Test login method */
-  @Test (timeout = 30000)
+  @Test
+  @Timeout(value = 30)
   public void testLogin() throws Exception {
     conf.set(HADOOP_USER_GROUP_METRICS_PERCENTILES_INTERVALS,
       String.valueOf(PERCENTILES_INTERVAL));
@@ -250,7 +256,8 @@ public class TestUserGroupInformation {
    * given user name - get all the groups.
    * Needs to happen before creating the test users
    */
-  @Test (timeout = 30000)
+  @Test
+  @Timeout(value = 30)
   public void testGetServerSideGroups() throws IOException,
                                                InterruptedException {
     // get the user name
@@ -311,7 +318,8 @@ public class TestUserGroupInformation {
   }
 
   /** test constructor */
-  @Test (timeout = 30000)
+  @Test
+  @Timeout(value = 30)
   public void testConstructor() throws Exception {
     // security off, so default should just return simple name
     testConstructorSuccess("user1", "user1");
@@ -325,7 +333,8 @@ public class TestUserGroupInformation {
   }
   
   /** test constructor */
-  @Test (timeout = 30000)
+  @Test
+  @Timeout(value = 30)
   public void testConstructorWithRules() throws Exception {
     // security off, but use rules if explicitly set
     conf.set(HADOOP_SECURITY_AUTH_TO_LOCAL,
@@ -357,7 +366,8 @@ public class TestUserGroupInformation {
   }
   
   /** test constructor */
-  @Test (timeout = 30000)
+  @Test
+  @Timeout(value = 30)
   public void testConstructorWithKerberos() throws Exception {
     // security on, default is remove default realm
     conf.set(HADOOP_SECURITY_AUTH_TO_LOCAL_MECHANISM, "hadoop");
@@ -387,7 +397,8 @@ public class TestUserGroupInformation {
   }
 
   /** test constructor */
-  @Test (timeout = 30000)
+  @Test
+  @Timeout(value = 30)
   public void testConstructorWithKerberosRules() throws Exception {
     // security on, explicit rules
     SecurityUtil.setAuthenticationMethod(AuthenticationMethod.KERBEROS, conf);
@@ -423,12 +434,13 @@ public class TestUserGroupInformation {
       String expect = (userName == null || userName.isEmpty())
           ? "Null user" : "Illegal principal name "+userName;
       String expect2 = "Malformed Kerberos name: "+userName;
-      assertTrue("Did not find "+ expect + " or " + expect2 + " in " + e,
-          e.toString().contains(expect) || e.toString().contains(expect2));
+      assertTrue(e.toString().contains(expect) || e.toString().contains(expect2),
+          "Did not find "+ expect + " or " + expect2 + " in " + e);
     }
   }
 
-  @Test (timeout = 30000)
+  @Test
+  @Timeout(value = 30)
   public void testSetConfigWithRules() {
     String[] rules = { "RULE:[1:TEST1]", "RULE:[1:TEST2]", "RULE:[1:TEST3]" };
 
@@ -458,7 +470,8 @@ public class TestUserGroupInformation {
     assertEquals(rules[2], KerberosName.getRules());
   }
 
-  @Test (timeout = 30000)
+  @Test
+  @Timeout(value = 30)
   public void testEnsureInitWithRules() throws IOException {
     String rules = "RULE:[1:RULE1]";
 
@@ -477,7 +490,8 @@ public class TestUserGroupInformation {
     assertEquals(rules, KerberosName.getRules());
   }
 
-  @Test (timeout = 30000)
+  @Test
+  @Timeout(value = 30)
   public void testEquals() throws Exception {
     UserGroupInformation uugi = 
       UserGroupInformation.createUserForTesting(USER_NAME, GROUP_NAMES);
@@ -495,7 +509,8 @@ public class TestUserGroupInformation {
     assertEquals(uugi.hashCode(), ugi3.hashCode());
   }
   
-  @Test (timeout = 30000)
+  @Test
+  @Timeout(value = 30)
   public void testEqualsWithRealUser() throws Exception {
     UserGroupInformation realUgi1 = UserGroupInformation.createUserForTesting(
         "RealUser", GROUP_NAMES);
@@ -508,7 +523,8 @@ public class TestUserGroupInformation {
     assertFalse(remoteUgi.equals(proxyUgi1));
   }
   
-  @Test (timeout = 30000)
+  @Test
+  @Timeout(value = 30)
   public void testGettingGroups() throws Exception {
     UserGroupInformation uugi = 
       UserGroupInformation.createUserForTesting(USER_NAME, GROUP_NAMES);
@@ -519,8 +535,8 @@ public class TestUserGroupInformation {
     assertEquals(GROUP1_NAME, uugi.getPrimaryGroupName());
   }
 
-  @SuppressWarnings("unchecked") // from Mockito mocks
-  @Test (timeout = 30000)
+  @SuppressWarnings("unchecked")@Test
+  @Timeout(value = 30)
   public <T extends TokenIdentifier> void testAddToken() throws Exception {
     UserGroupInformation ugi = 
         UserGroupInformation.createRemoteUser("someone"); 
@@ -557,8 +573,8 @@ public class TestUserGroupInformation {
     checkTokens(ugi, t1, t2, t3);    
   }
 
-  @SuppressWarnings("unchecked") // from Mockito mocks
-  @Test (timeout = 30000)
+  @SuppressWarnings("unchecked")@Test
+  @Timeout(value = 30)
   public <T extends TokenIdentifier> void testGetCreds() throws Exception {
     UserGroupInformation ugi = 
         UserGroupInformation.createRemoteUser("someone"); 
@@ -583,8 +599,8 @@ public class TestUserGroupInformation {
     checkTokens(ugi, t1, t2);
   }
 
-  @SuppressWarnings("unchecked") // from Mockito mocks
-  @Test (timeout = 30000)
+  @SuppressWarnings("unchecked")@Test
+  @Timeout(value = 30)
   public <T extends TokenIdentifier> void testAddCreds() throws Exception {
     UserGroupInformation ugi = 
         UserGroupInformation.createRemoteUser("someone"); 
@@ -609,7 +625,8 @@ public class TestUserGroupInformation {
     assertSame(secret, ugi.getCredentials().getSecretKey(secretKey));
   }
 
-  @Test (timeout = 30000)
+  @Test
+  @Timeout(value = 30)
   public <T extends TokenIdentifier> void testGetCredsNotSame()
       throws Exception {
     UserGroupInformation ugi = 
@@ -636,8 +653,8 @@ public class TestUserGroupInformation {
     assertEquals(tokens.length, ugiCreds.numberOfTokens());
   }
 
-  @SuppressWarnings("unchecked") // from Mockito mocks
-  @Test (timeout = 30000)
+  @SuppressWarnings("unchecked")@Test
+  @Timeout(value = 30)
   public <T extends TokenIdentifier> void testAddNamedToken() throws Exception {
     UserGroupInformation ugi = 
         UserGroupInformation.createRemoteUser("someone"); 
@@ -657,8 +674,8 @@ public class TestUserGroupInformation {
     assertSame(t1, ugi.getCredentials().getToken(service2));
   }
 
-  @SuppressWarnings("unchecked") // from Mockito mocks
-  @Test (timeout = 30000)
+  @SuppressWarnings("unchecked")@Test
+  @Timeout(value = 30)
   public <T extends TokenIdentifier> void testUGITokens() throws Exception {
     UserGroupInformation ugi = 
       UserGroupInformation.createUserForTesting("TheDoctor", 
@@ -704,7 +721,8 @@ public class TestUserGroupInformation {
     assertTrue(otherSet.contains(t2));
   }
   
-  @Test (timeout = 30000)
+  @Test
+  @Timeout(value = 30)
   public void testTokenIdentifiers() throws Exception {
     UserGroupInformation ugi = UserGroupInformation.createUserForTesting(
         "TheDoctor", new String[] { "TheTARDIS" });
@@ -732,7 +750,8 @@ public class TestUserGroupInformation {
     assertEquals(2, otherSet.size());
   }
 
-  @Test (timeout = 30000)
+  @Test
+  @Timeout(value = 30)
   public void testTestAuthMethod() throws Exception {
     UserGroupInformation ugi = UserGroupInformation.getCurrentUser();
     // verify the reverse mappings works
@@ -744,40 +763,42 @@ public class TestUserGroupInformation {
     }
   }
   
-  @Test (timeout = 30000)
+  @Test
+  @Timeout(value = 30)
   public void testUGIAuthMethod() throws Exception {
     final UserGroupInformation ugi = UserGroupInformation.getCurrentUser();
     final AuthenticationMethod am = AuthenticationMethod.KERBEROS;
     ugi.setAuthenticationMethod(am);
-    Assert.assertEquals(am, ugi.getAuthenticationMethod());
+    assertEquals(am, ugi.getAuthenticationMethod());
     ugi.doAs(new PrivilegedExceptionAction<Object>() {
       @Override
       public Object run() throws IOException {
-        Assert.assertEquals(am, UserGroupInformation.getCurrentUser()
+        assertEquals(am, UserGroupInformation.getCurrentUser()
             .getAuthenticationMethod());
         return null;
       }
     });
   }
   
-  @Test (timeout = 30000)
+  @Test
+  @Timeout(value = 30)
   public void testUGIAuthMethodInRealUser() throws Exception {
     final UserGroupInformation ugi = UserGroupInformation.getCurrentUser();
     UserGroupInformation proxyUgi = UserGroupInformation.createProxyUser(
         "proxy", ugi);
     final AuthenticationMethod am = AuthenticationMethod.KERBEROS;
     ugi.setAuthenticationMethod(am);
-    Assert.assertEquals(am, ugi.getAuthenticationMethod());
-    Assert.assertEquals(AuthenticationMethod.PROXY,
+    assertEquals(am, ugi.getAuthenticationMethod());
+    assertEquals(AuthenticationMethod.PROXY,
                         proxyUgi.getAuthenticationMethod());
-    Assert.assertEquals(am, UserGroupInformation
+    assertEquals(am, UserGroupInformation
         .getRealAuthenticationMethod(proxyUgi));
     proxyUgi.doAs(new PrivilegedExceptionAction<Object>() {
       @Override
       public Object run() throws IOException {
-        Assert.assertEquals(AuthenticationMethod.PROXY, UserGroupInformation
+        assertEquals(AuthenticationMethod.PROXY, UserGroupInformation
             .getCurrentUser().getAuthenticationMethod());
-        Assert.assertEquals(am, UserGroupInformation.getCurrentUser()
+        assertEquals(am, UserGroupInformation.getCurrentUser()
             .getRealUser().getAuthenticationMethod());
         return null;
       }
@@ -785,17 +806,18 @@ public class TestUserGroupInformation {
     UserGroupInformation proxyUgi2 = 
       new UserGroupInformation(proxyUgi.getSubject());
     proxyUgi2.setAuthenticationMethod(AuthenticationMethod.PROXY);
-    Assert.assertEquals(proxyUgi, proxyUgi2);
+    assertEquals(proxyUgi, proxyUgi2);
     // Equality should work if authMethod is null
     UserGroupInformation realugi = UserGroupInformation.getCurrentUser();
     UserGroupInformation proxyUgi3 = UserGroupInformation.createProxyUser(
         "proxyAnother", realugi);
     UserGroupInformation proxyUgi4 = 
       new UserGroupInformation(proxyUgi3.getSubject());
-    Assert.assertEquals(proxyUgi3, proxyUgi4);
+    assertEquals(proxyUgi3, proxyUgi4);
   }
   
-  @Test (timeout = 30000)
+  @Test
+  @Timeout(value = 30)
   public void testLoginObjectInSubject() throws Exception {
     UserGroupInformation loginUgi = UserGroupInformation.getLoginUser();
     UserGroupInformation anotherUgi = new UserGroupInformation(loginUgi
@@ -805,10 +827,11 @@ public class TestUserGroupInformation {
     LoginContext login2 = anotherUgi.getSubject().getPrincipals(User.class)
     .iterator().next().getLogin();
     //login1 and login2 must be same instances
-    Assert.assertTrue(login1 == login2);
+    assertTrue(login1 == login2);
   }
   
-  @Test (timeout = 30000)
+  @Test
+  @Timeout(value = 30)
   public void testLoginModuleCommit() throws Exception {
     UserGroupInformation loginUgi = UserGroupInformation.getLoginUser();
     User user1 = loginUgi.getSubject().getPrincipals(User.class).iterator()
@@ -819,7 +842,7 @@ public class TestUserGroupInformation {
     User user2 = loginUgi.getSubject().getPrincipals(User.class).iterator()
         .next();
     // user1 and user2 must be same instances.
-    Assert.assertTrue(user1 == user2);
+    assertTrue(user1 == user2);
   }
   
   public static void verifyLoginMetrics(long success, int failure)
@@ -857,7 +880,8 @@ public class TestUserGroupInformation {
    * with it, but that Subject was not created by Hadoop (ie it has no
    * associated User principal)
    */
-  @Test (timeout = 30000)
+  @Test
+  @Timeout(value = 30)
   public void testUGIUnderNonHadoopContext() throws Exception {
     Subject nonHadoopSubject = new Subject();
     Subject.doAs(nonHadoopSubject, new PrivilegedExceptionAction<Void>() {
@@ -870,7 +894,8 @@ public class TestUserGroupInformation {
       });
   }
 
-  @Test (timeout = 30000)
+  @Test
+  @Timeout(value = 30)
   public void testGetUGIFromSubject() throws Exception {
     KerberosPrincipal p = new KerberosPrincipal("guest");
     Subject subject = new Subject();
@@ -881,7 +906,8 @@ public class TestUserGroupInformation {
   }
 
   /** Test hasSufficientTimeElapsed method */
-  @Test (timeout = 30000)
+  @Test
+  @Timeout(value = 30)
   public void testHasSufficientTimeElapsed() throws Exception {
     // Make hasSufficientTimeElapsed public
     Method method = UserGroupInformation.class
@@ -915,7 +941,8 @@ public class TestUserGroupInformation {
     method.setAccessible(false);
   }
   
-  @Test(timeout=10000)
+  @Test
+  @Timeout(value = 10)
   public void testSetLoginUser() throws IOException {
     UserGroupInformation ugi = UserGroupInformation.createRemoteUser("test-user");
     UserGroupInformation.setLoginUser(ugi);
@@ -982,8 +1009,8 @@ public class TestUserGroupInformation {
             Token<? extends TokenIdentifier> t = mock(Token.class);
             when(t.getService()).thenReturn(new Text("t" + i));
             UserGroupInformation.getCurrentUser().addToken(t);
-            assertNull("ConcurrentModificationException encountered",
-                thread.cme);
+            assertNull(thread.cme,
+                "ConcurrentModificationException encountered");
           }
         } catch (ConcurrentModificationException cme) {
           cme.printStackTrace();
@@ -1139,7 +1166,7 @@ public class TestUserGroupInformation {
     String str =
         "5th retry, now:" + currentTime + ", retry:" + lastRetry;
     LOG.info(str);
-    assertEquals(str, endTime - reloginIntervalMs, lastRetry);
+    assertEquals(endTime - reloginIntervalMs, lastRetry, str);
 
     // make sure no more retries after (tgt endTime - login interval).
     UserGroupInformation.metrics.getRenewalFailures().incr();
@@ -1147,7 +1174,7 @@ public class TestUserGroupInformation {
         UserGroupInformation.getNextTgtRenewalTime(endTime, currentTime, rp);
     str = "overflow retry, now:" + currentTime + ", retry:" + lastRetry;
     LOG.info(str);
-    assertEquals(str, endTime - reloginIntervalMs, lastRetry);
+    assertEquals(endTime - reloginIntervalMs, lastRetry, str);
   }
 
   private void assertWithinBounds(final int numFailures, final long lastRetry,
@@ -1160,12 +1187,13 @@ public class TestUserGroupInformation {
         + ", lower bound:" + lower + ", upper bound:" + upper
         + ", retry:" + lastRetry);
     LOG.info(str);
-    assertTrue(str, lower <= lastRetry && lastRetry < upper);
+    assertTrue(lower <= lastRetry && lastRetry < upper, str);
   }
 
   // verify that getCurrentUser on the same and different subjects can be
   // concurrent.  Ie. no synchronization.
-  @Test(timeout=8000)
+  @Test
+  @Timeout(value = 8)
   public void testConcurrentGetCurrentUser() throws Exception {
     final CyclicBarrier barrier = new CyclicBarrier(2);
     final CountDownLatch latch = new CountDownLatch(1);
@@ -1181,7 +1209,7 @@ public class TestUserGroupInformation {
     Set<Principal> principals = testUgi1.getSubject().getPrincipals();
     User user =
         testUgi1.getSubject().getPrincipals(User.class).iterator().next();
-    final User spyUser = Mockito.spy(user);
+    final User spyUser = spy(user);
     principals.remove(user);
     principals.add(spyUser);
     when(spyUser.getName()).thenAnswer(new Answer<String>(){
@@ -1269,7 +1297,7 @@ public class TestUserGroupInformation {
     // there should be no exception when calling this
     userCredsRunnable.run();
     // isDestroyed should be called at least once
-    Mockito.verify(tgt, atLeastOnce()).isDestroyed();
+    verify(tgt, atLeastOnce()).isDestroyed();
   }
 
   @Test
@@ -1306,8 +1334,8 @@ public class TestUserGroupInformation {
     // Check if the tokens were loaded
     UserGroupInformation ugi = UserGroupInformation.getLoginUser();
     Credentials outCred = ugi.getCredentials();
-    assertEquals("Tokens: " + outCred.getAllTokens(),
-        2, outCred.getAllTokens().size());
+    assertEquals(2, outCred.getAllTokens().size(),
+        "Tokens: " + outCred.getAllTokens());
     boolean found0 = false;
     boolean found1 = false;
     for (Token<? extends TokenIdentifier> token : outCred.getAllTokens()) {
@@ -1321,10 +1349,10 @@ public class TestUserGroupInformation {
         found1 = true;
       }
     }
-    assertTrue("Expected token testTokenService0 not found: " + outCred,
-        found0);
-    assertTrue("Expected token testTokenService1 not found: " + outCred,
-        found1);
+    assertTrue(found0,
+        "Expected token testTokenService0 not found: " + outCred);
+    assertTrue(found1,
+        "Expected token testTokenService1 not found: " + outCred);
 
     // Try to add the same token through configuration and file
     Credentials cred1 = new Credentials();
@@ -1336,8 +1364,8 @@ public class TestUserGroupInformation {
 
     UserGroupInformation ugi1 = UserGroupInformation.getLoginUser();
     Credentials outCred1 = ugi1.getCredentials();
-    assertEquals("Tokens: " + outCred1.getAllTokens(),
-        1, outCred1.getAllTokens().size());
+    assertEquals(1, outCred1.getAllTokens().size(),
+        "Tokens: " + outCred1.getAllTokens());
   }
 
   @Test
@@ -1356,8 +1384,8 @@ public class TestUserGroupInformation {
     UserGroupInformation.reset();
     UserGroupInformation ugi = UserGroupInformation.getLoginUser();
     Credentials creds = ugi.getCredentials();
-    assertEquals("Tokens: " + creds.getAllTokens(),
-        1, creds.getAllTokens().size());
+    assertEquals(1, creds.getAllTokens().size(),
+        "Tokens: " + creds.getAllTokens());
     assertArrayEquals(creds.getToken(service).getIdentifier(), identity);
 
     // Cleanup

+ 54 - 46
hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/token/delegation/TestZKDelegationTokenSecretManager.java

@@ -18,6 +18,12 @@
 
 package org.apache.hadoop.security.token.delegation;
 
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.fail;
+
 import java.io.IOException;
 import java.nio.charset.StandardCharsets;
 import java.util.ArrayList;
@@ -53,18 +59,18 @@ import org.apache.zookeeper.data.ACL;
 import org.apache.zookeeper.data.Id;
 import org.apache.zookeeper.data.Stat;
 import org.apache.zookeeper.server.auth.DigestAuthenticationProvider;
-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.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.MethodOrderer;
+import org.junit.jupiter.api.Order;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestMethodOrder;
+import org.junit.jupiter.api.Timeout;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import static org.junit.Assert.fail;
-
-
+@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
+@Timeout(300)
 public class TestZKDelegationTokenSecretManager {
   private static final Logger LOG =
       LoggerFactory.getLogger(TestZKDelegationTokenSecretManager.class);
@@ -79,16 +85,13 @@ public class TestZKDelegationTokenSecretManager {
 
   protected TestingServer zkServer;
 
-  @Rule
-  public Timeout globalTimeout = new Timeout(300000, TimeUnit.MILLISECONDS);
-
-  @Before
+  @BeforeEach
   public void setup() throws Exception {
     zkServer = new TestingServer();
     zkServer.start();
   }
 
-  @After
+  @AfterEach
   public void tearDown() throws Exception {
     if (zkServer != null) {
       zkServer.close();
@@ -111,11 +114,13 @@ public class TestZKDelegationTokenSecretManager {
 
   @SuppressWarnings("unchecked")
   @Test
+  @Order(1)
   public void testMultiNodeOperations() throws Exception {
       testMultiNodeOperationsImpl(false);
   }
 
   @Test
+  @Order(2)
   public void testMultiNodeOperationsWithZeroRetry() throws Exception {
       testMultiNodeOperationsImpl(true);
   }
@@ -136,7 +141,7 @@ public class TestZKDelegationTokenSecretManager {
       Token<DelegationTokenIdentifier> token =
           (Token<DelegationTokenIdentifier>) tm1.createToken(
               UserGroupInformation.getCurrentUser(), "foo");
-      Assert.assertNotNull(token);
+      assertNotNull(token);
       tm2.verifyToken(token);
       tm2.renewToken(token, "foo");
       tm1.verifyToken(token);
@@ -150,7 +155,7 @@ public class TestZKDelegationTokenSecretManager {
 
       token = (Token<DelegationTokenIdentifier>) tm2.createToken(
           UserGroupInformation.getCurrentUser(), "bar");
-      Assert.assertNotNull(token);
+      assertNotNull(token);
       tm1.verifyToken(token);
       tm1.renewToken(token, "bar");
       tm2.verifyToken(token);
@@ -168,6 +173,7 @@ public class TestZKDelegationTokenSecretManager {
 
   @SuppressWarnings("unchecked")
   @Test
+  @Order(5)
   public void testNodeUpAferAWhile() throws Exception {
     for (int i = 0; i < TEST_RETRIES; i++) {
       String connectString = zkServer.getConnectString();
@@ -177,15 +183,15 @@ public class TestZKDelegationTokenSecretManager {
       Token<DelegationTokenIdentifier> token1 =
           (Token<DelegationTokenIdentifier>) tm1.createToken(
               UserGroupInformation.getCurrentUser(), "foo");
-      Assert.assertNotNull(token1);
+      assertNotNull(token1);
       Token<DelegationTokenIdentifier> token2 =
           (Token<DelegationTokenIdentifier>) tm1.createToken(
               UserGroupInformation.getCurrentUser(), "bar");
-      Assert.assertNotNull(token2);
+      assertNotNull(token2);
       Token<DelegationTokenIdentifier> token3 =
           (Token<DelegationTokenIdentifier>) tm1.createToken(
               UserGroupInformation.getCurrentUser(), "boo");
-      Assert.assertNotNull(token3);
+      assertNotNull(token3);
 
       tm1.verifyToken(token1);
       tm1.verifyToken(token2);
@@ -212,7 +218,7 @@ public class TestZKDelegationTokenSecretManager {
       Token<DelegationTokenIdentifier> token4 =
           (Token<DelegationTokenIdentifier>) tm2.createToken(
               UserGroupInformation.getCurrentUser(), "xyz");
-      Assert.assertNotNull(token4);
+      assertNotNull(token4);
       tm2.verifyToken(token4);
       tm1.verifyToken(token4);
 
@@ -241,6 +247,7 @@ public class TestZKDelegationTokenSecretManager {
 
   @SuppressWarnings("unchecked")
   @Test
+  @Order(6)
   public void testMultiNodeCompeteForSeqNum() throws Exception {
     DelegationTokenManager tm1, tm2 = null;
     String connectString = zkServer.getConnectString();
@@ -253,19 +260,17 @@ public class TestZKDelegationTokenSecretManager {
     Token<DelegationTokenIdentifier> token1 =
         (Token<DelegationTokenIdentifier>) tm1.createToken(
             UserGroupInformation.getCurrentUser(), "foo");
-    Assert.assertNotNull(token1);
+    assertNotNull(token1);
     AbstractDelegationTokenIdentifier id1 =
         tm1.getDelegationTokenSecretManager().decodeTokenIdentifier(token1);
-    Assert.assertEquals(
-        "Token seq should be the same", 1, id1.getSequenceNumber());
+    assertEquals(1, id1.getSequenceNumber(), "Token seq should be the same");
     Token<DelegationTokenIdentifier> token2 =
         (Token<DelegationTokenIdentifier>) tm1.createToken(
             UserGroupInformation.getCurrentUser(), "foo");
-    Assert.assertNotNull(token2);
+    assertNotNull(token2);
     AbstractDelegationTokenIdentifier id2 =
         tm1.getDelegationTokenSecretManager().decodeTokenIdentifier(token2);
-    Assert.assertEquals(
-        "Token seq should be the same", 2, id2.getSequenceNumber());
+    assertEquals(2, id2.getSequenceNumber(), "Token seq should be the same");
 
     tm2 = new DelegationTokenManager(conf, new Text("bla"));
     tm2.init();
@@ -273,19 +278,17 @@ public class TestZKDelegationTokenSecretManager {
     Token<DelegationTokenIdentifier> token3 =
         (Token<DelegationTokenIdentifier>) tm2.createToken(
             UserGroupInformation.getCurrentUser(), "foo");
-    Assert.assertNotNull(token3);
+    assertNotNull(token3);
     AbstractDelegationTokenIdentifier id3 =
         tm2.getDelegationTokenSecretManager().decodeTokenIdentifier(token3);
-    Assert.assertEquals(
-        "Token seq should be the same", 1001, id3.getSequenceNumber());
+    assertEquals(1001, id3.getSequenceNumber(), "Token seq should be the same");
     Token<DelegationTokenIdentifier> token4 =
         (Token<DelegationTokenIdentifier>) tm2.createToken(
             UserGroupInformation.getCurrentUser(), "foo");
-    Assert.assertNotNull(token4);
+    assertNotNull(token4);
     AbstractDelegationTokenIdentifier id4 =
         tm2.getDelegationTokenSecretManager().decodeTokenIdentifier(token4);
-    Assert.assertEquals(
-        "Token seq should be the same", 1002, id4.getSequenceNumber());
+    assertEquals(1002, id4.getSequenceNumber(), "Token seq should be the same");
 
     verifyDestroy(tm1, conf);
     verifyDestroy(tm2, conf);
@@ -293,6 +296,7 @@ public class TestZKDelegationTokenSecretManager {
 
   @SuppressWarnings("unchecked")
   @Test
+  @Order(3)
   public void testRenewTokenSingleManager() throws Exception {
     for (int i = 0; i < TEST_RETRIES; i++) {
       DelegationTokenManager tm1 = null;
@@ -304,7 +308,7 @@ public class TestZKDelegationTokenSecretManager {
       Token<DelegationTokenIdentifier> token =
           (Token<DelegationTokenIdentifier>)
           tm1.createToken(UserGroupInformation.getCurrentUser(), "foo");
-      Assert.assertNotNull(token);
+      assertNotNull(token);
       tm1.renewToken(token, "foo");
       tm1.verifyToken(token);
       verifyDestroy(tm1, conf);
@@ -313,6 +317,7 @@ public class TestZKDelegationTokenSecretManager {
 
   @SuppressWarnings("unchecked")
   @Test
+  @Order(9)
   public void testCancelTokenSingleManager() throws Exception {
     for (int i = 0; i < TEST_RETRIES; i++) {
       DelegationTokenManager tm1 = null;
@@ -324,7 +329,7 @@ public class TestZKDelegationTokenSecretManager {
       Token<DelegationTokenIdentifier> token =
           (Token<DelegationTokenIdentifier>)
           tm1.createToken(UserGroupInformation.getCurrentUser(), "foo");
-      Assert.assertNotNull(token);
+      assertNotNull(token);
       tm1.cancelToken(token, "foo");
       try {
         verifyTokenFail(tm1, token);
@@ -350,6 +355,7 @@ public class TestZKDelegationTokenSecretManager {
 
   @SuppressWarnings({ "unchecked", "rawtypes" })
   @Test
+  @Order(7)
   public void testStopThreads() throws Exception {
     DelegationTokenManager tm1 = null;
     String connectString = zkServer.getConnectString();
@@ -371,7 +377,7 @@ public class TestZKDelegationTokenSecretManager {
     Token<DelegationTokenIdentifier> token =
       (Token<DelegationTokenIdentifier>)
     tm1.createToken(UserGroupInformation.getCurrentUser(), "foo");
-    Assert.assertNotNull(token);
+    assertNotNull(token);
     tm1.destroy();
   }
 
@@ -420,8 +426,8 @@ public class TestZKDelegationTokenSecretManager {
   private void verifyACL(CuratorFramework curatorFramework,
       String path, ACL expectedACL) throws Exception {
     List<ACL> acls = curatorFramework.getACL().forPath(path);
-    Assert.assertEquals(1, acls.size());
-    Assert.assertEquals(expectedACL, acls.get(0));
+    assertEquals(1, acls.size());
+    assertEquals(expectedACL, acls.get(0));
   }
 
   // Since it is possible that there can be a delay for the cancel token message
@@ -452,6 +458,7 @@ public class TestZKDelegationTokenSecretManager {
 
   @SuppressWarnings({ "unchecked" })
   @Test
+  @Order(8)
   public void testNodesLoadedAfterRestart() throws Exception {
     final String connectString = zkServer.getConnectString();
     final Configuration conf = getSecretConf(connectString);
@@ -470,11 +477,11 @@ public class TestZKDelegationTokenSecretManager {
     Token<DelegationTokenIdentifier> token =
         (Token<DelegationTokenIdentifier>) tm
             .createToken(UserGroupInformation.getCurrentUser(), "good");
-    Assert.assertNotNull(token);
+    assertNotNull(token);
     Token<DelegationTokenIdentifier> cancelled =
         (Token<DelegationTokenIdentifier>) tm
             .createToken(UserGroupInformation.getCurrentUser(), "cancelled");
-    Assert.assertNotNull(cancelled);
+    assertNotNull(cancelled);
     tm.verifyToken(token);
     tm.verifyToken(cancelled);
 
@@ -511,12 +518,12 @@ public class TestZKDelegationTokenSecretManager {
         smNew.decodeTokenIdentifier(cancelled);
     AbstractDelegationTokenSecretManager.DelegationTokenInformation dtinfo =
         zksmNew.getTokenInfo(id);
-    Assert.assertNull("canceled dt should be gone!", dtinfo);
+    assertNull(dtinfo, "canceled dt should be gone!");
 
     // The good token should be loaded on startup, and removed after expiry.
     id = smNew.decodeTokenIdentifier(token);
     dtinfo = zksmNew.getTokenInfoFromMemory(id);
-    Assert.assertNotNull("good dt should be in memory!", dtinfo);
+    assertNotNull(dtinfo, "good dt should be in memory!");
 
     // Wait for the good token to expire.
     Thread.sleep(5000);
@@ -556,13 +563,14 @@ public class TestZKDelegationTokenSecretManager {
 
     // Check if the created NameSpace exists.
     Stat stat = curatorFramework.checkExists().forPath(workingPath);
-    Assert.assertNotNull(stat);
+    assertNotNull(stat);
 
     tm1.destroy();
     curatorFramework.close();
   }
 
   @Test
+  @Order(4)
   public void testCreateNameSpaceRepeatedly() throws Exception {
 
     String connectString = zkServer.getConnectString();
@@ -584,7 +592,7 @@ public class TestZKDelegationTokenSecretManager {
 
     // Check if the created NameSpace exists.
     Stat stat = curatorFramework.checkExists().forPath(workingPath);
-    Assert.assertNotNull(stat);
+    assertNotNull(stat);
 
     // Repeated creation will throw NodeExists exception
     LambdaTestUtils.intercept(KeeperException.class,
@@ -624,10 +632,10 @@ public class TestZKDelegationTokenSecretManager {
     List<Future<Boolean>> futures = executorService.invokeAll(
         Arrays.asList(tm1Callable, tm2Callable));
     for(Future<Boolean> future : futures) {
-      Assert.assertTrue(future.get());
+      assertTrue(future.get());
     }
     executorService.shutdownNow();
-    Assert.assertTrue(executorService.awaitTermination(1, TimeUnit.SECONDS));
+    assertTrue(executorService.awaitTermination(1, TimeUnit.SECONDS));
     tm1.destroy();
     tm2.destroy();
 
@@ -636,7 +644,7 @@ public class TestZKDelegationTokenSecretManager {
 
     // Check if the created NameSpace exists.
     Stat stat = curatorFramework.checkExists().forPath(workingPath);
-    Assert.assertNotNull(stat);
+    assertNotNull(stat);
 
     curatorFramework.close();
   }

+ 172 - 166
hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/token/delegation/web/TestDelegationTokenAuthenticationHandlerWithMocks.java

@@ -18,6 +18,18 @@
 package org.apache.hadoop.security.token.delegation.web;
 
 import static org.apache.hadoop.security.token.delegation.web.DelegationTokenAuthenticator.DelegationTokenOperation.*;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.fail;
+import static org.mockito.Mockito.contains;
+import static org.mockito.Mockito.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+import static org.mockito.Mockito.reset;
+import static org.mockito.Mockito.startsWith;
 
 import com.fasterxml.jackson.databind.ObjectMapper;
 
@@ -30,13 +42,10 @@ import org.apache.hadoop.security.authentication.server.AuthenticationHandler;
 import org.apache.hadoop.security.authentication.server.AuthenticationToken;
 import org.apache.hadoop.security.token.SecretManager;
 import org.apache.hadoop.security.token.Token;
-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 org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.Timeout;
 
 import javax.servlet.ServletException;
 import javax.servlet.http.HttpServletRequest;
@@ -47,8 +56,8 @@ import java.io.PrintWriter;
 import java.io.StringWriter;
 import java.util.Map;
 import java.util.Properties;
-import java.util.concurrent.TimeUnit;
 
+@Timeout(120)
 public class TestDelegationTokenAuthenticationHandlerWithMocks {
 
   public static class MockDelegationTokenAuthenticationHandler
@@ -93,10 +102,7 @@ public class TestDelegationTokenAuthenticationHandlerWithMocks {
 
   private DelegationTokenAuthenticationHandler handler;
 
-  @Rule
-  public Timeout testTimeout = new Timeout(120000, TimeUnit.MILLISECONDS);
-
-  @Before
+  @BeforeEach
   public void setUp() throws Exception {
     Properties conf = new Properties();
 
@@ -105,7 +111,7 @@ public class TestDelegationTokenAuthenticationHandlerWithMocks {
     handler.initTokenManager(conf);
   }
 
-  @After
+  @AfterEach
   public void cleanUp() {
       handler.destroy();
   }
@@ -130,40 +136,40 @@ public class TestDelegationTokenAuthenticationHandlerWithMocks {
   }
 
   private void testNonManagementOperation() throws Exception {
-    HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
-    Mockito.when(request.getParameter(
+    HttpServletRequest request = mock(HttpServletRequest.class);
+    when(request.getParameter(
         DelegationTokenAuthenticator.OP_PARAM)).thenReturn(null);
-    Assert.assertTrue(handler.managementOperation(null, request, null));
-    Mockito.when(request.getParameter(
+    assertTrue(handler.managementOperation(null, request, null));
+    when(request.getParameter(
         DelegationTokenAuthenticator.OP_PARAM)).thenReturn("CREATE");
-    Assert.assertTrue(handler.managementOperation(null, request, null));
+    assertTrue(handler.managementOperation(null, request, null));
   }
 
   private void testManagementOperationErrors() throws Exception {
-    HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
-    HttpServletResponse response = Mockito.mock(HttpServletResponse.class);
-    Mockito.when(request.getQueryString()).thenReturn(
+    HttpServletRequest request = mock(HttpServletRequest.class);
+    HttpServletResponse response = mock(HttpServletResponse.class);
+    when(request.getQueryString()).thenReturn(
         DelegationTokenAuthenticator.OP_PARAM + "=" +
             DelegationTokenAuthenticator.DelegationTokenOperation.
                 GETDELEGATIONTOKEN.toString()
     );
-    Mockito.when(request.getMethod()).thenReturn("FOO");
-    Assert.assertFalse(handler.managementOperation(null, request, response));
-    Mockito.verify(response).sendError(
-        Mockito.eq(HttpServletResponse.SC_BAD_REQUEST),
-        Mockito.startsWith("Wrong HTTP method"));
-
-    Mockito.reset(response);
-    Mockito.when(request.getMethod()).thenReturn(
+    when(request.getMethod()).thenReturn("FOO");
+    assertFalse(handler.managementOperation(null, request, response));
+    verify(response).sendError(
+        eq(HttpServletResponse.SC_BAD_REQUEST),
+        startsWith("Wrong HTTP method"));
+
+    reset(response);
+    when(request.getMethod()).thenReturn(
         DelegationTokenAuthenticator.DelegationTokenOperation.
             GETDELEGATIONTOKEN.getHttpMethod()
     );
-    Assert.assertFalse(handler.managementOperation(null, request, response));
-    Mockito.verify(response).setStatus(
-        Mockito.eq(HttpServletResponse.SC_UNAUTHORIZED));
-    Mockito.verify(response).setHeader(
-        Mockito.eq(KerberosAuthenticator.WWW_AUTHENTICATE),
-        Mockito.eq("mock"));
+    assertFalse(handler.managementOperation(null, request, response));
+    verify(response).setStatus(
+        eq(HttpServletResponse.SC_UNAUTHORIZED));
+    verify(response).setHeader(
+        eq(KerberosAuthenticator.WWW_AUTHENTICATE),
+        eq("mock"));
   }
 
   private Token<DelegationTokenIdentifier> testGetToken(String renewer,
@@ -171,17 +177,17 @@ public class TestDelegationTokenAuthenticationHandlerWithMocks {
     DelegationTokenAuthenticator.DelegationTokenOperation op =
         DelegationTokenAuthenticator.DelegationTokenOperation.
             GETDELEGATIONTOKEN;
-    HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
-    HttpServletResponse response = Mockito.mock(HttpServletResponse.class);
-    Mockito.when(request.getQueryString()).
+    HttpServletRequest request = mock(HttpServletRequest.class);
+    HttpServletResponse response = mock(HttpServletResponse.class);
+    when(request.getQueryString()).
         thenReturn(DelegationTokenAuthenticator.OP_PARAM + "=" + op.toString());
-    Mockito.when(request.getMethod()).thenReturn(op.getHttpMethod());
+    when(request.getMethod()).thenReturn(op.getHttpMethod());
 
-    AuthenticationToken token = Mockito.mock(AuthenticationToken.class);
-    Mockito.when(token.getUserName()).thenReturn("user");
-    Mockito.when(response.getWriter()).thenReturn(new PrintWriter(
+    AuthenticationToken token = mock(AuthenticationToken.class);
+    when(token.getUserName()).thenReturn("user");
+    when(response.getWriter()).thenReturn(new PrintWriter(
         new StringWriter()));
-    Assert.assertFalse(handler.managementOperation(token, request, response));
+    assertFalse(handler.managementOperation(token, request, response));
 
     String queryString =
         DelegationTokenAuthenticator.OP_PARAM + "=" + op.toString() + "&" +
@@ -190,27 +196,27 @@ public class TestDelegationTokenAuthenticationHandlerWithMocks {
       queryString += "&" + DelegationTokenAuthenticator.SERVICE_PARAM + "="
           + service;
     }
-    Mockito.when(request.getQueryString()).thenReturn(queryString);
-    Mockito.reset(response);
-    Mockito.reset(token);
-    Mockito.when(token.getUserName()).thenReturn("user");
+    when(request.getQueryString()).thenReturn(queryString);
+    reset(response);
+    reset(token);
+    when(token.getUserName()).thenReturn("user");
     StringWriter writer = new StringWriter();
     PrintWriter pwriter = new PrintWriter(writer);
-    Mockito.when(response.getWriter()).thenReturn(pwriter);
-    Assert.assertFalse(handler.managementOperation(token, request, response));
+    when(response.getWriter()).thenReturn(pwriter);
+    assertFalse(handler.managementOperation(token, request, response));
     if (renewer == null) {
-      Mockito.verify(token).getUserName();
+      verify(token).getUserName();
     } else {
-      Mockito.verify(token).getUserName();
+      verify(token).getUserName();
     }
-    Mockito.verify(response).setStatus(HttpServletResponse.SC_OK);
-    Mockito.verify(response).setContentType(MediaType.APPLICATION_JSON);
+    verify(response).setStatus(HttpServletResponse.SC_OK);
+    verify(response).setContentType(MediaType.APPLICATION_JSON);
     pwriter.close();
     String responseOutput = writer.toString();
     String tokenLabel = DelegationTokenAuthenticator.
         DELEGATION_TOKEN_JSON;
-    Assert.assertTrue(responseOutput.contains(tokenLabel));
-    Assert.assertTrue(responseOutput.contains(
+    assertTrue(responseOutput.contains(tokenLabel));
+    assertTrue(responseOutput.contains(
         DelegationTokenAuthenticator.DELEGATION_TOKEN_URL_STRING_JSON));
     ObjectMapper jsonMapper = new ObjectMapper();
     Map json = jsonMapper.readValue(responseOutput, Map.class);
@@ -221,11 +227,11 @@ public class TestDelegationTokenAuthenticationHandlerWithMocks {
     Token<DelegationTokenIdentifier> dt = new Token<DelegationTokenIdentifier>();
     dt.decodeFromUrlString(tokenStr);
     handler.getTokenManager().verifyToken(dt);
-    Assert.assertEquals(expectedTokenKind, dt.getKind());
+    assertEquals(expectedTokenKind, dt.getKind());
     if (service != null) {
-      Assert.assertEquals(service, dt.getService().toString());
+      assertEquals(service, dt.getService().toString());
     } else {
-      Assert.assertEquals(0, dt.getService().getLength());
+      assertEquals(0, dt.getService().getLength());
     }
     return dt;
   }
@@ -244,33 +250,33 @@ public class TestDelegationTokenAuthenticationHandlerWithMocks {
     DelegationTokenAuthenticator.DelegationTokenOperation op =
         DelegationTokenAuthenticator.DelegationTokenOperation.
             CANCELDELEGATIONTOKEN;
-    HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
-    HttpServletResponse response = Mockito.mock(HttpServletResponse.class);
-    Mockito.when(request.getQueryString()).thenReturn(
+    HttpServletRequest request = mock(HttpServletRequest.class);
+    HttpServletResponse response = mock(HttpServletResponse.class);
+    when(request.getQueryString()).thenReturn(
         DelegationTokenAuthenticator.OP_PARAM + "=" + op.toString());
-    Mockito.when(request.getMethod()).
+    when(request.getMethod()).
         thenReturn(op.getHttpMethod());
 
-    Assert.assertFalse(handler.managementOperation(null, request, response));
-    Mockito.verify(response).sendError(
-        Mockito.eq(HttpServletResponse.SC_BAD_REQUEST),
-        Mockito.contains("requires the parameter [token]"));
+    assertFalse(handler.managementOperation(null, request, response));
+    verify(response).sendError(
+        eq(HttpServletResponse.SC_BAD_REQUEST),
+        contains("requires the parameter [token]"));
 
-    Mockito.reset(response);
-    Mockito.when(request.getQueryString()).thenReturn(
+    reset(response);
+    when(request.getQueryString()).thenReturn(
         DelegationTokenAuthenticator.OP_PARAM + "=" + op.toString() + "&" +
             DelegationTokenAuthenticator.TOKEN_PARAM + "=" +
             token.encodeToUrlString()
     );
-    Assert.assertFalse(handler.managementOperation(null, request, response));
-    Mockito.verify(response).setStatus(HttpServletResponse.SC_OK);
+    assertFalse(handler.managementOperation(null, request, response));
+    verify(response).setStatus(HttpServletResponse.SC_OK);
     try {
       handler.getTokenManager().verifyToken(token);
-      Assert.fail();
+      fail();
     } catch (SecretManager.InvalidToken ex) {
       //NOP
     } catch (Throwable ex) {
-      Assert.fail();
+      fail();
     }
   }
 
@@ -288,42 +294,42 @@ public class TestDelegationTokenAuthenticationHandlerWithMocks {
     DelegationTokenAuthenticator.DelegationTokenOperation op =
         DelegationTokenAuthenticator.DelegationTokenOperation.
             RENEWDELEGATIONTOKEN;
-    HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
-    HttpServletResponse response = Mockito.mock(HttpServletResponse.class);
-    Mockito.when(request.getQueryString()).
+    HttpServletRequest request = mock(HttpServletRequest.class);
+    HttpServletResponse response = mock(HttpServletResponse.class);
+    when(request.getQueryString()).
         thenReturn(DelegationTokenAuthenticator.OP_PARAM + "=" + op.toString());
-    Mockito.when(request.getMethod()).
+    when(request.getMethod()).
         thenReturn(op.getHttpMethod());
 
-    Assert.assertFalse(handler.managementOperation(null, request, response));
-    Mockito.verify(response).setStatus(
-        Mockito.eq(HttpServletResponse.SC_UNAUTHORIZED));
-    Mockito.verify(response).setHeader(Mockito.eq(
+    assertFalse(handler.managementOperation(null, request, response));
+    verify(response).setStatus(
+        eq(HttpServletResponse.SC_UNAUTHORIZED));
+    verify(response).setHeader(eq(
             KerberosAuthenticator.WWW_AUTHENTICATE),
-        Mockito.eq("mock")
+        eq("mock")
     );
 
-    Mockito.reset(response);
-    AuthenticationToken token = Mockito.mock(AuthenticationToken.class);
-    Mockito.when(token.getUserName()).thenReturn(testRenewer);
-    Assert.assertFalse(handler.managementOperation(token, request, response));
-    Mockito.verify(response).sendError(
-        Mockito.eq(HttpServletResponse.SC_BAD_REQUEST),
-        Mockito.contains("requires the parameter [token]"));
+    reset(response);
+    AuthenticationToken token = mock(AuthenticationToken.class);
+    when(token.getUserName()).thenReturn(testRenewer);
+    assertFalse(handler.managementOperation(token, request, response));
+    verify(response).sendError(
+        eq(HttpServletResponse.SC_BAD_REQUEST),
+        contains("requires the parameter [token]"));
 
-    Mockito.reset(response);
+    reset(response);
     StringWriter writer = new StringWriter();
     PrintWriter pwriter = new PrintWriter(writer);
-    Mockito.when(response.getWriter()).thenReturn(pwriter);
+    when(response.getWriter()).thenReturn(pwriter);
 
-    Mockito.when(request.getQueryString()).
+    when(request.getQueryString()).
         thenReturn(DelegationTokenAuthenticator.OP_PARAM + "=" + op.toString() +
             "&" + DelegationTokenAuthenticator.TOKEN_PARAM + "=" +
             dToken.encodeToUrlString());
-    Assert.assertFalse(handler.managementOperation(token, request, response));
-    Mockito.verify(response).setStatus(HttpServletResponse.SC_OK);
+    assertFalse(handler.managementOperation(token, request, response));
+    verify(response).setStatus(HttpServletResponse.SC_OK);
     pwriter.close();
-    Assert.assertTrue(writer.toString().contains("long"));
+    assertTrue(writer.toString().contains("long"));
     handler.getTokenManager().verifyToken(dToken);
   }
 
@@ -337,104 +343,104 @@ public class TestDelegationTokenAuthenticationHandlerWithMocks {
 
   @SuppressWarnings("unchecked")
   private void testValidDelegationTokenQueryString() throws Exception {
-    HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
-    HttpServletResponse response = Mockito.mock(HttpServletResponse.class);
+    HttpServletRequest request = mock(HttpServletRequest.class);
+    HttpServletResponse response = mock(HttpServletResponse.class);
     Token<DelegationTokenIdentifier> dToken =
         (Token<DelegationTokenIdentifier>) handler.getTokenManager().createToken(
             UserGroupInformation.getCurrentUser(), "user");
-    Mockito.when(request.getQueryString()).thenReturn(
+    when(request.getQueryString()).thenReturn(
         DelegationTokenAuthenticator.DELEGATION_PARAM + "=" +
         dToken.encodeToUrlString());
 
     AuthenticationToken token = handler.authenticate(request, response);
-    Assert.assertEquals(UserGroupInformation.getCurrentUser().
+    assertEquals(UserGroupInformation.getCurrentUser().
             getShortUserName(), token.getUserName());
-    Assert.assertEquals(0, token.getExpires());
-    Assert.assertEquals(handler.getType(),
+    assertEquals(0, token.getExpires());
+    assertEquals(handler.getType(),
         token.getType());
-    Assert.assertTrue(token.isExpired());
+    assertTrue(token.isExpired());
   }
 
   @SuppressWarnings("unchecked")
   private void testValidDelegationTokenHeader() throws Exception {
-    HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
-    HttpServletResponse response = Mockito.mock(HttpServletResponse.class);
+    HttpServletRequest request = mock(HttpServletRequest.class);
+    HttpServletResponse response = mock(HttpServletResponse.class);
     Token<DelegationTokenIdentifier> dToken =
         (Token<DelegationTokenIdentifier>) handler.getTokenManager().createToken(
             UserGroupInformation.getCurrentUser(), "user");
-    Mockito.when(request.getHeader(Mockito.eq(
+    when(request.getHeader(eq(
         DelegationTokenAuthenticator.DELEGATION_TOKEN_HEADER))).thenReturn(
         dToken.encodeToUrlString());
 
     AuthenticationToken token = handler.authenticate(request, response);
-    Assert.assertEquals(UserGroupInformation.getCurrentUser().
+    assertEquals(UserGroupInformation.getCurrentUser().
         getShortUserName(), token.getUserName());
-    Assert.assertEquals(0, token.getExpires());
-    Assert.assertEquals(handler.getType(),
+    assertEquals(0, token.getExpires());
+    assertEquals(handler.getType(),
         token.getType());
-    Assert.assertTrue(token.isExpired());
+    assertTrue(token.isExpired());
   }
 
   private void testInvalidDelegationTokenQueryString() throws Exception {
-    HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
-    HttpServletResponse response = Mockito.mock(HttpServletResponse.class);
-    Mockito.when(request.getQueryString()).thenReturn(
+    HttpServletRequest request = mock(HttpServletRequest.class);
+    HttpServletResponse response = mock(HttpServletResponse.class);
+    when(request.getQueryString()).thenReturn(
         DelegationTokenAuthenticator.DELEGATION_PARAM + "=invalid");
     StringWriter writer = new StringWriter();
-    Mockito.when(response.getWriter()).thenReturn(new PrintWriter(writer));
-    Assert.assertNull(handler.authenticate(request, response));
-    Mockito.verify(response).setStatus(HttpServletResponse.SC_FORBIDDEN);
-    Assert.assertTrue(writer.toString().contains("AuthenticationException"));
+    when(response.getWriter()).thenReturn(new PrintWriter(writer));
+    assertNull(handler.authenticate(request, response));
+    verify(response).setStatus(HttpServletResponse.SC_FORBIDDEN);
+    assertTrue(writer.toString().contains("AuthenticationException"));
   }
 
   private void testInvalidDelegationTokenHeader() throws Exception {
-    HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
-    HttpServletResponse response = Mockito.mock(HttpServletResponse.class);
-    Mockito.when(request.getHeader(Mockito.eq(
+    HttpServletRequest request = mock(HttpServletRequest.class);
+    HttpServletResponse response = mock(HttpServletResponse.class);
+    when(request.getHeader(eq(
         DelegationTokenAuthenticator.DELEGATION_TOKEN_HEADER))).thenReturn(
         "invalid");
     StringWriter writer = new StringWriter();
-    Mockito.when(response.getWriter()).thenReturn(new PrintWriter(writer));
-    Assert.assertNull(handler.authenticate(request, response));
-    Assert.assertTrue(writer.toString().contains("AuthenticationException"));
+    when(response.getWriter()).thenReturn(new PrintWriter(writer));
+    assertNull(handler.authenticate(request, response));
+    assertTrue(writer.toString().contains("AuthenticationException"));
   }
 
   private String getToken() throws Exception {
     DelegationTokenAuthenticator.DelegationTokenOperation op =
         DelegationTokenAuthenticator.DelegationTokenOperation.
             GETDELEGATIONTOKEN;
-    HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
-    HttpServletResponse response = Mockito.mock(HttpServletResponse.class);
-    Mockito.when(request.getQueryString()).
+    HttpServletRequest request = mock(HttpServletRequest.class);
+    HttpServletResponse response = mock(HttpServletResponse.class);
+    when(request.getQueryString()).
         thenReturn(DelegationTokenAuthenticator.OP_PARAM + "=" + op.toString());
-    Mockito.when(request.getMethod()).thenReturn(op.getHttpMethod());
+    when(request.getMethod()).thenReturn(op.getHttpMethod());
 
-    AuthenticationToken token = Mockito.mock(AuthenticationToken.class);
-    Mockito.when(token.getUserName()).thenReturn("user");
-    Mockito.when(response.getWriter()).thenReturn(new PrintWriter(
+    AuthenticationToken token = mock(AuthenticationToken.class);
+    when(token.getUserName()).thenReturn("user");
+    when(response.getWriter()).thenReturn(new PrintWriter(
         new StringWriter()));
-    Assert.assertFalse(handler.managementOperation(token, request, response));
+    assertFalse(handler.managementOperation(token, request, response));
 
-    Mockito.when(request.getQueryString()).
+    when(request.getQueryString()).
         thenReturn(DelegationTokenAuthenticator.OP_PARAM + "=" + op.toString() +
             "&" + DelegationTokenAuthenticator.RENEWER_PARAM + "=" + null);
 
-    Mockito.reset(response);
-    Mockito.reset(token);
-    Mockito.when(token.getUserName()).thenReturn("user");
+    reset(response);
+    reset(token);
+    when(token.getUserName()).thenReturn("user");
     StringWriter writer = new StringWriter();
     PrintWriter pwriter = new PrintWriter(writer);
-    Mockito.when(response.getWriter()).thenReturn(pwriter);
-    Assert.assertFalse(handler.managementOperation(token, request, response));
-    Mockito.verify(token).getUserName();
-    Mockito.verify(response).setStatus(HttpServletResponse.SC_OK);
-    Mockito.verify(response).setContentType(MediaType.APPLICATION_JSON);
+    when(response.getWriter()).thenReturn(pwriter);
+    assertFalse(handler.managementOperation(token, request, response));
+    verify(token).getUserName();
+    verify(response).setStatus(HttpServletResponse.SC_OK);
+    verify(response).setContentType(MediaType.APPLICATION_JSON);
     pwriter.close();
     String responseOutput = writer.toString();
     String tokenLabel = DelegationTokenAuthenticator.
         DELEGATION_TOKEN_JSON;
-    Assert.assertTrue(responseOutput.contains(tokenLabel));
-    Assert.assertTrue(responseOutput.contains(
+    assertTrue(responseOutput.contains(tokenLabel));
+    assertTrue(responseOutput.contains(
         DelegationTokenAuthenticator.DELEGATION_TOKEN_URL_STRING_JSON));
     ObjectMapper jsonMapper = new ObjectMapper();
     Map json = jsonMapper.readValue(responseOutput, Map.class);
@@ -453,23 +459,23 @@ public class TestDelegationTokenAuthenticationHandlerWithMocks {
     DelegationTokenAuthenticator.DelegationTokenOperation op =
         DelegationTokenAuthenticator.DelegationTokenOperation.
             GETDELEGATIONTOKEN;
-    HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
-    Mockito.when(request.getMethod()).thenReturn(op.getHttpMethod());
-    HttpServletResponse response = Mockito.mock(HttpServletResponse.class);
-    Mockito.when(response.getWriter()).thenReturn(new PrintWriter(
+    HttpServletRequest request = mock(HttpServletRequest.class);
+    when(request.getMethod()).thenReturn(op.getHttpMethod());
+    HttpServletResponse response = mock(HttpServletResponse.class);
+    when(response.getWriter()).thenReturn(new PrintWriter(
         new StringWriter()));
     String tokenStr = getToken();
     // Try get a new token using the fetched token, should get 401.
-    Mockito.when(request.getQueryString()).
+    when(request.getQueryString()).
         thenReturn(DelegationTokenAuthenticator.OP_PARAM + "=" + op.toString() +
             "&" + DelegationTokenAuthenticator.RENEWER_PARAM + "=" + null +
         "&" + DelegationTokenAuthenticator.DELEGATION_PARAM + "=" + tokenStr);
-    Mockito.reset(response);
+    reset(response);
     StringWriter writer = new StringWriter();
     PrintWriter pwriter = new PrintWriter(writer);
-    Mockito.when(response.getWriter()).thenReturn(pwriter);
-    Assert.assertFalse(handler.managementOperation(null, request, response));
-    Mockito.verify(response).setStatus(HttpServletResponse.SC_UNAUTHORIZED);
+    when(response.getWriter()).thenReturn(pwriter);
+    assertFalse(handler.managementOperation(null, request, response));
+    verify(response).setStatus(HttpServletResponse.SC_UNAUTHORIZED);
   }
 
   @Test
@@ -477,23 +483,23 @@ public class TestDelegationTokenAuthenticationHandlerWithMocks {
     DelegationTokenAuthenticator.DelegationTokenOperation op =
         DelegationTokenAuthenticator.DelegationTokenOperation.
             RENEWDELEGATIONTOKEN;
-    HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
-    Mockito.when(request.getMethod()).thenReturn(op.getHttpMethod());
-    HttpServletResponse response = Mockito.mock(HttpServletResponse.class);
-    Mockito.when(response.getWriter()).thenReturn(new PrintWriter(
+    HttpServletRequest request = mock(HttpServletRequest.class);
+    when(request.getMethod()).thenReturn(op.getHttpMethod());
+    HttpServletResponse response = mock(HttpServletResponse.class);
+    when(response.getWriter()).thenReturn(new PrintWriter(
         new StringWriter()));
     String tokenStr = getToken();
     // Try renew a token using itself, should get 401.
-    Mockito.when(request.getQueryString()).
+    when(request.getQueryString()).
         thenReturn(DelegationTokenAuthenticator.OP_PARAM + "=" + op.toString() +
             "&" + DelegationTokenAuthenticator.TOKEN_PARAM + "=" + tokenStr +
             "&" + DelegationTokenAuthenticator.DELEGATION_PARAM + "=" + tokenStr);
-    Mockito.reset(response);
+    reset(response);
     StringWriter writer = new StringWriter();
     PrintWriter pwriter = new PrintWriter(writer);
-    Mockito.when(response.getWriter()).thenReturn(pwriter);
-    Assert.assertFalse(handler.managementOperation(null, request, response));
-    Mockito.verify(response).setStatus(HttpServletResponse.SC_UNAUTHORIZED);
+    when(response.getWriter()).thenReturn(pwriter);
+    assertFalse(handler.managementOperation(null, request, response));
+    verify(response).setStatus(HttpServletResponse.SC_UNAUTHORIZED);
   }
 
   @Test
@@ -510,14 +516,14 @@ public class TestDelegationTokenAuthenticationHandlerWithMocks {
 
       DelegationTokenAuthenticator.DelegationTokenOperation op =
           GETDELEGATIONTOKEN;
-      HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
-      HttpServletResponse response = Mockito.mock(HttpServletResponse.class);
-      Mockito.when(request.getQueryString()).thenReturn(
+      HttpServletRequest request = mock(HttpServletRequest.class);
+      HttpServletResponse response = mock(HttpServletResponse.class);
+      when(request.getQueryString()).thenReturn(
           DelegationTokenAuthenticator.OP_PARAM + "=" + op.toString());
-      Mockito.when(request.getMethod()).thenReturn(op.getHttpMethod());
+      when(request.getMethod()).thenReturn(op.getHttpMethod());
 
-      AuthenticationToken token = Mockito.mock(AuthenticationToken.class);
-      Mockito.when(token.getUserName()).thenReturn("user");
+      AuthenticationToken token = mock(AuthenticationToken.class);
+      when(token.getUserName()).thenReturn("user");
       final MutableBoolean closed = new MutableBoolean();
       PrintWriter printWriterCloseCount = new PrintWriter(new StringWriter()) {
         @Override
@@ -535,8 +541,8 @@ public class TestDelegationTokenAuthenticationHandlerWithMocks {
         }
 
       };
-      Mockito.when(response.getWriter()).thenReturn(printWriterCloseCount);
-      Assert.assertFalse(noAuthCloseHandler.managementOperation(token, request,
+      when(response.getWriter()).thenReturn(printWriterCloseCount);
+      assertFalse(noAuthCloseHandler.managementOperation(token, request,
           response));
     } finally {
       noAuthCloseHandler.destroy();

+ 8 - 8
hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/service/ServiceAssert.java

@@ -19,12 +19,12 @@
 package org.apache.hadoop.service;
 
 import org.apache.hadoop.service.Service;
-import org.junit.Assert;
+import org.junit.jupiter.api.Assertions;
 
 /**
  * A set of assertions about the state of any service
  */
-public class ServiceAssert extends Assert {
+public class ServiceAssert extends Assertions {
 
   public static void assertServiceStateCreated(Service service) {
     assertServiceInState(service, Service.STATE.NOTINITED);
@@ -43,9 +43,9 @@ public class ServiceAssert extends Assert {
   }
 
   public static void assertServiceInState(Service service, Service.STATE state) {
-    assertNotNull("Null service", service);
-    assertEquals("Service in wrong state: " + service, state,
-                 service.getServiceState());
+    assertNotNull(service, "Null service");
+    assertEquals(state, service.getServiceState(),
+        "Service in wrong state: " + service);
   }
 
   /**
@@ -58,7 +58,7 @@ public class ServiceAssert extends Assert {
   public static void assertStateCount(BreakableService service,
                         Service.STATE state,
                         int expected) {
-    assertNotNull("Null service", service);
+    assertNotNull(service, "Null service");
     int actual = service.getCount(state);
     if (expected != actual) {
       fail("Expected entry count for state [" + state +"] of " + service
@@ -74,7 +74,7 @@ public class ServiceAssert extends Assert {
    */
   public static void assertServiceConfigurationContains(Service service,
                                                         String key) {
-    assertNotNull("No option "+ key + " in service configuration",
-                  service.getConfig().get(key));
+    assertNotNull(service.getConfig().get(key),
+        "No option "+ key + " in service configuration");
   }
 }

+ 9 - 9
hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/service/TestGlobalStateChangeListener.java

@@ -23,8 +23,8 @@ import org.apache.hadoop.service.AbstractService;
 import org.apache.hadoop.service.LoggingStateChangeListener;
 import org.apache.hadoop.service.Service;
 import org.apache.hadoop.service.ServiceStateChangeListener;
-import org.junit.After;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Test;
 
 /**
  * Test global state changes. It is critical for all tests to clean up the
@@ -58,7 +58,7 @@ public class TestGlobalStateChangeListener extends ServiceAssert {
   /**
    * After every test case reset the list of global listeners.
    */
-  @After
+  @AfterEach
   public void cleanup() {
     AbstractService.resetGlobalListeners();
   }
@@ -70,7 +70,7 @@ public class TestGlobalStateChangeListener extends ServiceAssert {
    */
   public void assertListenerState(BreakableStateChangeListener breakable,
                                   Service.STATE state) {
-    assertEquals("Wrong state in " + breakable, state, breakable.getLastState());
+    assertEquals(state, breakable.getLastState(), "Wrong state in " + breakable);
   }
 
   /**
@@ -80,8 +80,8 @@ public class TestGlobalStateChangeListener extends ServiceAssert {
    */
   public void assertListenerEventCount(BreakableStateChangeListener breakable,
                                        int count) {
-    assertEquals("Wrong event count in " + breakable, count,
-                 breakable.getEventCount());
+    assertEquals(count, breakable.getEventCount(),
+        "Wrong event count in " + breakable);
   }
 
   /**
@@ -90,7 +90,7 @@ public class TestGlobalStateChangeListener extends ServiceAssert {
   @Test
   public void testRegisterListener() {
     register();
-    assertTrue("listener not registered", unregister());
+    assertTrue(unregister(), "listener not registered");
   }
 
   /**
@@ -100,9 +100,9 @@ public class TestGlobalStateChangeListener extends ServiceAssert {
   public void testRegisterListenerTwice() {
     register();
     register();
-    assertTrue("listener not registered", unregister());
+    assertTrue(unregister(), "listener not registered");
     //there should be no listener to unregister the second time
-    assertFalse("listener double registered", unregister());
+    assertFalse(unregister(), "listener double registered");
   }
 
   /**

+ 5 - 5
hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/service/TestServiceLifecycle.java

@@ -25,7 +25,7 @@ import org.apache.hadoop.service.LoggingStateChangeListener;
 import org.apache.hadoop.service.Service;
 import org.apache.hadoop.service.ServiceStateChangeListener;
 import org.apache.hadoop.service.ServiceStateException;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -204,10 +204,10 @@ public class TestServiceLifecycle extends ServiceAssert {
     assertEquals(Service.STATE.INITED, svc.getFailureState());
 
     Throwable failureCause = svc.getFailureCause();
-    assertNotNull("Null failure cause in " + svc, failureCause);
+    assertNotNull(failureCause, "Null failure cause in " + svc);
     BreakableService.BrokenLifecycleEvent cause =
       (BreakableService.BrokenLifecycleEvent) failureCause;
-    assertNotNull("null state in " + cause + " raised by " + svc, cause.state);
+    assertNotNull(cause.state, "null state in " + cause + " raised by " + svc);
     assertEquals(Service.STATE.INITED, cause.state);
   }
 
@@ -299,7 +299,7 @@ public class TestServiceLifecycle extends ServiceAssert {
 
   private void assertEventCount(BreakableStateChangeListener listener,
                                 int expected) {
-    assertEquals(listener.toString(), expected, listener.getEventCount());
+    assertEquals(expected, listener.getEventCount(), listener.toString());
   }
 
   @Test
@@ -343,7 +343,7 @@ public class TestServiceLifecycle extends ServiceAssert {
     long duration = System.currentTimeMillis() - start;
     assertEquals(Service.STATE.STOPPED, listener.notifyingState);
     assertServiceInState(service, Service.STATE.STOPPED);
-    assertTrue("Duration of " + duration + " too long", duration < 10000);
+    assertTrue(duration < 10000, "Duration of " + duration + " too long");
   }
 
   @Test

+ 23 - 18
hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/test/GenericTestUtils.java

@@ -64,8 +64,6 @@ import org.apache.log4j.LogManager;
 import org.apache.log4j.Logger;
 import org.apache.log4j.PatternLayout;
 import org.apache.log4j.WriterAppender;
-import org.junit.Assert;
-import org.junit.Assume;
 import org.mockito.invocation.InvocationOnMock;
 import org.mockito.stubbing.Answer;
 import org.slf4j.LoggerFactory;
@@ -75,6 +73,12 @@ import org.apache.hadoop.thirdparty.com.google.common.base.Joiner;
 import static org.apache.hadoop.fs.contract.ContractTestUtils.createFile;
 import static org.apache.hadoop.util.functional.CommonCallableSupplier.submit;
 import static org.apache.hadoop.util.functional.CommonCallableSupplier.waitForCompletion;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.fail;
+import static org.junit.jupiter.api.Assumptions.assumeTrue;
 
 /**
  * Test provides some very generic helpers which might be used across the tests
@@ -274,7 +278,7 @@ public abstract class GenericTestUtils {
    * Assert that a given file exists.
    */
   public static void assertExists(File f) {
-    Assert.assertTrue("File " + f + " should exist", f.exists());
+    assertTrue(f.exists(), "File " + f + " should exist");
   }
 
   /**
@@ -293,9 +297,9 @@ public abstract class GenericTestUtils {
     }
     Set<String> expectedSet = new TreeSet<>(
         Arrays.asList(expectedMatches));
-    Assert.assertEquals("Bad files matching " + pattern + " in " + dir,
-        Joiner.on(",").join(expectedSet),
-        Joiner.on(",").join(found));
+    assertEquals(Joiner.on(",").join(expectedSet),
+        Joiner.on(",").join(found),
+        "Bad files matching " + pattern + " in " + dir);
   }
 
   static final String E_NULL_THROWABLE = "Null Throwable";
@@ -325,7 +329,7 @@ public abstract class GenericTestUtils {
   public static void assertExceptionContains(String expectedText,
       Throwable t,
       String message) {
-    Assert.assertNotNull(E_NULL_THROWABLE, t);
+    assertNotNull(t, E_NULL_THROWABLE);
     String msg = t.toString();
     if (msg == null) {
       throw new AssertionError(E_NULL_THROWABLE_STRING, t);
@@ -692,15 +696,15 @@ public abstract class GenericTestUtils {
   }
 
   public static void assertDoesNotMatch(String output, String pattern) {
-    Assert.assertFalse("Expected output to match /" + pattern + "/" +
-        " but got:\n" + output,
-        Pattern.compile(pattern).matcher(output).find());
+    assertFalse(Pattern.compile(pattern).matcher(output).find(),
+        "Expected output to match /" + pattern + "/" +
+        " but got:\n" + output);
   }
 
   public static void assertMatches(String output, String pattern) {
-    Assert.assertTrue("Expected output to match /" + pattern + "/" +
-        " but got:\n" + output,
-        Pattern.compile(pattern).matcher(output).find());
+    assertTrue(Pattern.compile(pattern).matcher(output).find(),
+        "Expected output to match /" + pattern + "/" +
+        " but got:\n" + output);
   }
 
   public static void assertValueNear(long expected, long actual, long allowedError) {
@@ -709,8 +713,9 @@ public abstract class GenericTestUtils {
 
   public static void assertValueWithinRange(long expectedMin, long expectedMax,
       long actual) {
-    Assert.assertTrue("Expected " + actual + " to be in range (" + expectedMin + ","
-        + expectedMax + ")", expectedMin <= actual && actual <= expectedMax);
+    assertTrue(expectedMin <= actual && actual <= expectedMax,
+        "Expected " + actual + " to be in range (" + expectedMin + ","
+        + expectedMax + ")");
   }
 
   /**
@@ -741,7 +746,7 @@ public abstract class GenericTestUtils {
   public static void assertNoThreadsMatching(String regex) {
     Pattern pattern = Pattern.compile(regex);
     if (anyThreadMatching(pattern)) {
-      Assert.fail("Leaked thread matches " + regex);
+      fail("Leaked thread matches " + regex);
     }
   }
 
@@ -774,8 +779,8 @@ public abstract class GenericTestUtils {
    * in the definition of native profile in pom.xml.
    */
   public static void assumeInNativeProfile() {
-    Assume.assumeTrue(
-        Boolean.parseBoolean(System.getProperty("runningWithNative", "false")));
+    assumeTrue(Boolean.parseBoolean(
+        System.getProperty("runningWithNative", "false")));
   }
 
   /**

+ 11 - 7
hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/test/LambdaTestUtils.java

@@ -18,7 +18,11 @@
 
 package org.apache.hadoop.test;
 
-import org.junit.Assert;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.fail;
+
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -699,9 +703,9 @@ public final class LambdaTestUtils {
   public static <T> void assertOptionalEquals(String message,
       T expected,
       Optional<T> actual) {
-    Assert.assertNotNull(message, actual);
-    Assert.assertTrue(message +" -not present", actual.isPresent());
-    Assert.assertEquals(message, expected, actual.get());
+    assertNotNull(actual, message);
+    assertTrue(actual.isPresent(), message +" -not present");
+    assertEquals(expected, actual.get(), message);
   }
 
   /**
@@ -713,9 +717,9 @@ public final class LambdaTestUtils {
    */
   public static <T> void assertOptionalUnset(String message,
       Optional<T> actual) {
-    Assert.assertNotNull(message, actual);
+    assertNotNull(actual, message);
     actual.ifPresent(
-        t -> Assert.fail("Expected empty option, got " + t.toString()));
+        t -> fail("Expected empty option, got " + t.toString()));
   }
 
   /**
@@ -766,7 +770,7 @@ public final class LambdaTestUtils {
   public static<T> T notNull(String message, Callable<T> eval)
       throws Exception {
     T t = eval.call();
-    Assert.assertNotNull(message, t);
+    assertNotNull(t, message);
     return t;
   }
 

+ 29 - 24
hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/test/MetricsAsserts.java

@@ -20,10 +20,15 @@ package org.apache.hadoop.test;
 
 import static org.apache.hadoop.util.Preconditions.*;
 
-import org.junit.Assert;
-
 import static org.mockito.AdditionalMatchers.geq;
-import static org.mockito.Mockito.*;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.Mockito.anyString;
+import static org.mockito.Mockito.atLeast;
+import static org.mockito.Mockito.argThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
 
 import org.mockito.stubbing.Answer;
 import org.mockito.invocation.InvocationOnMock;
@@ -150,8 +155,8 @@ public class MetricsAsserts {
    */
   public static void assertGauge(String name, int expected,
                                  MetricsRecordBuilder rb) {
-    Assert.assertEquals("Bad value for metric " + name,
-        expected, getIntGauge(name, rb));
+    assertEquals(expected, getIntGauge(name, rb),
+        "Bad value for metric " + name);
   }
 
   public static int getIntGauge(String name, MetricsRecordBuilder rb) {
@@ -169,8 +174,8 @@ public class MetricsAsserts {
    */
   public static void assertCounter(String name, int expected,
                                    MetricsRecordBuilder rb) {
-    Assert.assertEquals("Bad value for metric " + name,
-        expected, getIntCounter(name, rb));
+    assertEquals(expected, getIntCounter(name, rb),
+        "Bad value for metric " + name);
   }
 
   public static int getIntCounter(String name, MetricsRecordBuilder rb) {
@@ -189,8 +194,8 @@ public class MetricsAsserts {
    */
   public static void assertGauge(String name, long expected,
                                  MetricsRecordBuilder rb) {
-    Assert.assertEquals("Bad value for metric " + name,
-        expected, getLongGauge(name, rb));
+    assertEquals(expected, getLongGauge(name, rb),
+        "Bad value for metric " + name);
   }
 
   public static long getLongGauge(String name, MetricsRecordBuilder rb) {
@@ -208,8 +213,8 @@ public class MetricsAsserts {
    */
   public static void assertGauge(String name, double expected,
                                  MetricsRecordBuilder rb) {
-    Assert.assertEquals("Bad value for metric " + name,
-        expected, getDoubleGauge(name, rb), EPSILON);
+    assertEquals(expected, getDoubleGauge(name, rb), EPSILON,
+        "Bad value for metric " + name);
   }
 
   public static double getDoubleGauge(String name, MetricsRecordBuilder rb) {
@@ -227,8 +232,8 @@ public class MetricsAsserts {
    */
   public static void assertCounter(String name, long expected,
                                    MetricsRecordBuilder rb) {
-    Assert.assertEquals("Bad value for metric " + name,
-        expected, getLongCounter(name, rb));
+    assertEquals(expected, getLongCounter(name, rb),
+        "Bad value for metric " + name);
   }
 
   public static long getLongCounter(String name, MetricsRecordBuilder rb) {
@@ -260,8 +265,8 @@ public class MetricsAsserts {
    */
   public static void assertGauge(String name, float expected,
                                  MetricsRecordBuilder rb) {
-    Assert.assertEquals("Bad value for metric " + name,
-        expected, getFloatGauge(name, rb), EPSILON);
+    assertEquals(expected, getFloatGauge(name, rb), EPSILON,
+        "Bad value for metric " + name);
   }
 
   public static float getFloatGauge(String name, MetricsRecordBuilder rb) {
@@ -275,8 +280,8 @@ public class MetricsAsserts {
    * Check that this metric was captured exactly once.
    */
   private static void checkCaptured(ArgumentCaptor<?> captor, String name) {
-    Assert.assertEquals("Expected exactly one metric for name " + name,
-        1, captor.getAllValues().size());
+    assertEquals(1, captor.getAllValues().size(),
+        "Expected exactly one metric for name " + name);
   }
 
   /**
@@ -331,8 +336,8 @@ public class MetricsAsserts {
    */
   public static void assertCounterGt(String name, long greater,
                                      MetricsRecordBuilder rb) {
-    Assert.assertTrue("Bad value for metric " + name,
-        getLongCounter(name, rb) > greater);
+    assertTrue(getLongCounter(name, rb) > greater,
+        "Bad value for metric " + name);
   }
 
   /**
@@ -354,8 +359,8 @@ public class MetricsAsserts {
    */
   public static void assertGaugeGt(String name, double greater,
                                    MetricsRecordBuilder rb) {
-    Assert.assertTrue("Bad value for metric " + name,
-        getDoubleGauge(name, rb) > greater);
+    assertTrue(getDoubleGauge(name, rb) > greater,
+        "Bad value for metric " + name);
   }
 
   /**
@@ -367,8 +372,8 @@ public class MetricsAsserts {
   public static void assertGaugeGte(String name, double greater,
       MetricsRecordBuilder rb) {
     double curValue = getDoubleGauge(name, rb);
-    Assert.assertTrue("Bad value for metric " + name,
-        curValue >= greater);
+    assertTrue(curValue >= greater,
+        "Bad value for metric " + name);
   }
 
   /**
@@ -444,7 +449,7 @@ public class MetricsAsserts {
    */
   public static void assertTag(String name, String expected,
       MetricsRecordBuilder rb) {
-    Assert.assertEquals("Bad Tag for metric " + name,
+    assertEquals("Bad Tag for metric " + name,
         expected, getStringTag(name, rb));
   }
 

+ 12 - 12
hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/test/MoreAsserts.java

@@ -21,8 +21,8 @@ package org.apache.hadoop.test;
 import java.util.Iterator;
 import java.util.concurrent.CompletableFuture;
 
-import org.assertj.core.api.Assertions;
-import org.junit.Assert;
+import org.junit.jupiter.api.Assertions;
+import static org.assertj.core.api.Assertions.assertThat;
 
 /**
  * A few more asserts
@@ -42,10 +42,10 @@ public class MoreAsserts {
     Iterator<T> it = actual.iterator();
     int i = 0;
     for (; i < expected.length && it.hasNext(); ++i) {
-      Assert.assertEquals("Element " + i + " for " + s, expected[i], it.next());
+      Assertions.assertEquals(expected[i], it.next(), "Element " + i + " for " + s);
     }
-    Assert.assertTrue("Expected more elements", i == expected.length);
-    Assert.assertTrue("Expected less elements", !it.hasNext());
+    Assertions.assertTrue(i == expected.length, "Expected more elements");
+    Assertions.assertTrue(!it.hasNext(), "Expected less elements");
   }
 
   /**
@@ -62,26 +62,26 @@ public class MoreAsserts {
     Iterator<T> ita = actual.iterator();
     int i = 0;
     while (ite.hasNext() && ita.hasNext()) {
-      Assert.assertEquals("Element " + i + " for " + s, ite.next(), ita.next());
+      Assertions.assertEquals(ite.next(), ita.next(), "Element " + i + " for " + s);
     }
-    Assert.assertTrue("Expected more elements", !ite.hasNext());
-    Assert.assertTrue("Expected less elements", !ita.hasNext());
+    Assertions.assertTrue(!ite.hasNext(), "Expected more elements");
+    Assertions.assertTrue(!ita.hasNext(), "Expected less elements");
   }
 
 
   public static <T> void assertFutureCompletedSuccessfully(CompletableFuture<T> future) {
-    Assertions.assertThat(future.isDone())
+    assertThat(future.isDone())
             .describedAs("This future is supposed to be " +
                     "completed successfully")
             .isTrue();
-    Assertions.assertThat(future.isCompletedExceptionally())
+    assertThat(future.isCompletedExceptionally())
             .describedAs("This future is supposed to be " +
                     "completed successfully")
             .isFalse();
   }
 
   public static <T> void assertFutureFailedExceptionally(CompletableFuture<T> future) {
-    Assertions.assertThat(future.isCompletedExceptionally())
+    assertThat(future.isCompletedExceptionally())
             .describedAs("This future is supposed to be " +
                     "completed exceptionally")
             .isTrue();
@@ -94,7 +94,7 @@ public class MoreAsserts {
    * @param message error message to print in case of mismatch.
    */
   public static <T> void assertEqual(T actual, T expected, String message) {
-    Assertions.assertThat(actual)
+    assertThat(actual)
             .describedAs("Mismatch in %s", message)
             .isEqualTo(expected);
   }

+ 17 - 19
hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/tools/GetGroupsTestBase.java

@@ -17,7 +17,7 @@
  */
 package org.apache.hadoop.tools;
 
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
 
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
@@ -27,8 +27,8 @@ import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.security.UserGroupInformation;
 import org.apache.hadoop.util.Tool;
 import org.apache.hadoop.util.ToolRunner;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
 
 public abstract class GetGroupsTestBase {
   
@@ -38,7 +38,7 @@ public abstract class GetGroupsTestBase {
   
   protected abstract Tool getTool(PrintStream o);
   
-  @Before
+  @BeforeEach
   public void setUpUsers() throws IOException {
     // Make sure the current user's info is in the list of test users.
     UserGroupInformation currentUser = UserGroupInformation.getCurrentUser();
@@ -52,42 +52,40 @@ public abstract class GetGroupsTestBase {
   public void testNoUserGiven() throws Exception {
     String actualOutput = runTool(conf, new String[0], true);
     UserGroupInformation currentUser = UserGroupInformation.getCurrentUser();
-    assertEquals("No user provided should default to current user",
-        getExpectedOutput(currentUser), actualOutput);
+    assertEquals(getExpectedOutput(currentUser), actualOutput,
+        "No user provided should default to current user");
   }
   
   @Test
   public void testExistingUser() throws Exception {
     String actualOutput = runTool(conf, new String[]{testUser1.getUserName()}, true);
-    assertEquals("Show only the output of the user given",
-        getExpectedOutput(testUser1), actualOutput);
+    assertEquals(getExpectedOutput(testUser1), actualOutput,
+        "Show only the output of the user given");
   }
   
   @Test
   public void testMultipleExistingUsers() throws Exception {
     String actualOutput = runTool(conf,
         new String[]{testUser1.getUserName(), testUser2.getUserName()}, true);
-    assertEquals("Show the output for both users given",
-        getExpectedOutput(testUser1) + getExpectedOutput(testUser2), actualOutput);
+    assertEquals(getExpectedOutput(testUser1) + getExpectedOutput(testUser2), actualOutput,
+        "Show the output for both users given");
   }
   
   @Test
   public void testNonExistentUser() throws Exception {
     String actualOutput = runTool(conf,
         new String[]{"does-not-exist"}, true);
-    assertEquals("Show the output for only the user given, with no groups",
-        getExpectedOutput(UserGroupInformation.createRemoteUser("does-not-exist")),
-        actualOutput);
+    assertEquals(getExpectedOutput(UserGroupInformation.createRemoteUser("does-not-exist")),
+        actualOutput, "Show the output for only the user given, with no groups");
   }
   
   @Test
   public void testMultipleNonExistingUsers() throws Exception {
     String actualOutput = runTool(conf,
         new String[]{"does-not-exist1", "does-not-exist2"}, true);
-    assertEquals("Show the output for only the user given, with no groups",
-        getExpectedOutput(UserGroupInformation.createRemoteUser("does-not-exist1")) +
+    assertEquals(getExpectedOutput(UserGroupInformation.createRemoteUser("does-not-exist1")) +
         getExpectedOutput(UserGroupInformation.createRemoteUser("does-not-exist2")),
-        actualOutput);
+        actualOutput, "Show the output for only the user given, with no groups");
   }
   
   @Test
@@ -95,12 +93,12 @@ public abstract class GetGroupsTestBase {
     String actualOutput = runTool(conf,
         new String[]{"does-not-exist1", testUser1.getUserName(),
                      "does-not-exist2", testUser2.getUserName()}, true);
-    assertEquals("Show the output for only the user given, with no groups",
-        getExpectedOutput(UserGroupInformation.createRemoteUser("does-not-exist1")) +
+    assertEquals(getExpectedOutput(UserGroupInformation.createRemoteUser("does-not-exist1")) +
         getExpectedOutput(testUser1) +
         getExpectedOutput(UserGroupInformation.createRemoteUser("does-not-exist2")) +
         getExpectedOutput(testUser2),
-        actualOutput);
+        actualOutput,
+        "Show the output for only the user given, with no groups");
   }
   
   private static String getExpectedOutput(UserGroupInformation user) {

+ 4 - 4
hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/fs/contract/hdfs/HDFSContract.java

@@ -27,7 +27,7 @@ import org.apache.hadoop.fs.contract.ContractOptions;
 import org.apache.hadoop.hdfs.DFSConfigKeys;
 import org.apache.hadoop.hdfs.HdfsConfiguration;
 import org.apache.hadoop.hdfs.MiniDFSCluster;
-import org.junit.Assert;
+import org.junit.jupiter.api.Assertions;
 
 import java.io.IOException;
 
@@ -73,14 +73,14 @@ public class HDFSContract extends AbstractFSContract {
   @Override
   public void init() throws IOException {
     super.init();
-    Assert.assertTrue("contract options not loaded",
-                      isSupported(ContractOptions.IS_CASE_SENSITIVE, false));
+    Assertions.assertTrue(isSupported(ContractOptions.IS_CASE_SENSITIVE, false),
+        "contract options not loaded");
   }
 
   @Override
   public FileSystem getTestFileSystem() throws IOException {
     //assumes cluster is not null
-    Assert.assertNotNull("cluster not created", cluster);
+    Assertions.assertNotNull(cluster, "cluster not created");
     return cluster.getFileSystem();
   }
 

+ 4 - 4
hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/ha/TestGetGroupsWithHA.java

@@ -26,14 +26,14 @@ import org.apache.hadoop.hdfs.MiniDFSNNTopology;
 import org.apache.hadoop.hdfs.tools.GetGroups;
 import org.apache.hadoop.tools.GetGroupsTestBase;
 import org.apache.hadoop.util.Tool;
-import org.junit.After;
-import org.junit.Before;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
 
 public class TestGetGroupsWithHA extends GetGroupsTestBase {
   
   private MiniDFSCluster cluster;
   
-  @Before
+  @BeforeEach
   public void setUpNameNode() throws IOException {
     conf = new HdfsConfiguration();
     cluster = new MiniDFSCluster.Builder(conf)
@@ -42,7 +42,7 @@ public class TestGetGroupsWithHA extends GetGroupsTestBase {
     HATestUtil.setFailoverConfigurations(cluster, conf);
   }
   
-  @After
+  @AfterEach
   public void tearDownNameNode() {
     if (cluster != null) {
       cluster.shutdown();

+ 4 - 4
hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/TestGetGroups.java

@@ -24,8 +24,8 @@ import org.apache.hadoop.hdfs.HdfsConfiguration;
 import org.apache.hadoop.hdfs.MiniDFSCluster;
 import org.apache.hadoop.tools.GetGroupsTestBase;
 import org.apache.hadoop.util.Tool;
-import org.junit.After;
-import org.junit.Before;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
 
 /**
  * Tests for the HDFS implementation of {@link GetGroups}
@@ -34,13 +34,13 @@ public class TestGetGroups extends GetGroupsTestBase {
   
   private MiniDFSCluster cluster;
 
-  @Before
+  @BeforeEach
   public void setUpNameNode() throws IOException {
     conf = new HdfsConfiguration();
     cluster = new MiniDFSCluster.Builder(conf).numDataNodes(0).build();
   }
   
-  @After
+  @AfterEach
   public void tearDownNameNode() {
     if (cluster != null) {
       cluster.shutdown();

+ 8 - 12
hadoop-tools/hadoop-aws/src/test/java/org/apache/hadoop/fs/s3a/ITestS3ATemporaryCredentials.java

@@ -30,7 +30,6 @@ import org.junit.jupiter.api.BeforeEach;
 import software.amazon.awssdk.services.sts.StsClient;
 import software.amazon.awssdk.services.sts.StsClientBuilder;
 import software.amazon.awssdk.services.sts.model.Credentials;
-import org.hamcrest.Matchers;
 import org.junit.jupiter.api.Test;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -56,7 +55,7 @@ import static org.apache.hadoop.fs.s3a.auth.RoleTestUtils.assertCredentialsEqual
 import static org.apache.hadoop.fs.s3a.auth.delegation.DelegationConstants.*;
 import static org.apache.hadoop.fs.s3a.auth.delegation.SessionTokenBinding.CREDENTIALS_CONVERTED_TO_DELEGATION_TOKEN;
 import static org.apache.hadoop.test.LambdaTestUtils.intercept;
-import static org.hamcrest.Matchers.containsString;
+import static org.assertj.core.api.Assertions.assertThat;
 
 /**
  * Tests use of temporary credentials (for example, AWS STS & S3).
@@ -205,9 +204,9 @@ public class ITestS3ATemporaryCredentials extends AbstractS3ATestBase {
           = (SessionTokenIdentifier) fs.getDelegationToken("")
           .decodeIdentifier();
       String ids = identifier.toString();
-      assertThat("origin in " + ids,
-          identifier.getOrigin(),
-          containsString(CREDENTIALS_CONVERTED_TO_DELEGATION_TOKEN));
+      assertThat(identifier.getOrigin()).
+          contains(CREDENTIALS_CONVERTED_TO_DELEGATION_TOKEN).
+          as("origin in " + ids);
 
       // and validate the AWS bits to make sure everything has come across.
       assertCredentialsEqual("Reissued credentials in " + ids,
@@ -236,13 +235,10 @@ public class ITestS3ATemporaryCredentials extends AbstractS3ATestBase {
     Duration actualDuration = Duration.between(localTimestamp,
         expirationTimestamp);
     Duration offset = actualDuration.minus(TEST_SESSION_TOKEN_DURATION);
-
-    assertThat(
-        "Duration of session " + actualDuration
-            + " out of expected range of with " + offset
-            + " this host's clock may be wrong.",
-        offset.getSeconds(),
-        Matchers.lessThanOrEqualTo(permittedExpiryOffset));
+    assertThat(offset.getSeconds()).isLessThanOrEqualTo(permittedExpiryOffset).
+        as( "Duration of session " + actualDuration +
+        " out of expected range of with " + offset +
+        " this host's clock may be wrong.");
   }
 
   protected void updateConfigWithSessionCreds(final Configuration conf,

Một số tệp đã không được hiển thị bởi vì quá nhiều tập tin thay đổi trong này khác