浏览代码

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

Co-authored-by: Ayush Saxena <ayushsaxena@apache.org>
Co-authored-by: Chris Nauroth <cnauroth@apache.org>
Reviewed-by: Ayush Saxena <ayushsaxena@apache.org>
Reviewed-by: Chris Nauroth <cnauroth@apache.org>
Signed-off-by: Shilun Fan <slfan1989@apache.org>
slfan1989 5 月之前
父节点
当前提交
f1ee35b8a1
共有 35 个文件被更改,包括 1013 次插入967 次删除
  1. 9 10
      hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/cli/CLITestHelper.java
  2. 5 5
      hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/cli/TestCLI.java
  3. 15 11
      hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/conf/TestConfServlet.java
  4. 6 7
      hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/conf/TestConfigRedactor.java
  5. 67 71
      hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/conf/TestConfiguration.java
  6. 21 20
      hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/conf/TestConfigurationDeprecation.java
  7. 21 21
      hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/conf/TestConfigurationFieldsBase.java
  8. 8 6
      hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/conf/TestConfigurationSubclass.java
  9. 7 6
      hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/conf/TestDeprecatedKeys.java
  10. 4 2
      hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/conf/TestGetInstances.java
  11. 55 77
      hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/conf/TestReconfiguration.java
  12. 114 120
      hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/conf/TestStorageUnit.java
  13. 104 83
      hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/crypto/CryptoStreamsTestBase.java
  14. 39 33
      hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/crypto/TestCryptoCodec.java
  15. 8 4
      hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/crypto/TestCryptoOutputStreamClosing.java
  16. 8 6
      hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/crypto/TestCryptoStreams.java
  17. 37 28
      hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/crypto/TestCryptoStreamsForLocalFS.java
  18. 41 29
      hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/crypto/TestCryptoStreamsNormal.java
  19. 2 2
      hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/crypto/TestCryptoStreamsWithJceAesCtrCryptoCodec.java
  20. 2 2
      hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/crypto/TestCryptoStreamsWithJceSm4CtrCryptoCodec.java
  21. 11 12
      hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/crypto/TestCryptoStreamsWithOpensslAesCtrCryptoCodec.java
  22. 16 16
      hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/crypto/TestCryptoStreamsWithOpensslSm4CtrCryptoCodec.java
  23. 21 15
      hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/crypto/TestCryptoUtils.java
  24. 33 27
      hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/crypto/TestOpensslCipher.java
  25. 84 79
      hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/crypto/key/TestCachingKeyProvider.java
  26. 18 18
      hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/crypto/key/TestKeyProvider.java
  27. 68 81
      hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/crypto/key/TestKeyProviderCryptoExtension.java
  28. 12 12
      hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/crypto/key/TestKeyProviderDelegationTokenExtension.java
  29. 49 49
      hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/crypto/key/TestKeyProviderFactory.java
  30. 10 10
      hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/crypto/key/TestKeyShell.java
  31. 70 62
      hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/crypto/key/TestValueQueue.java
  32. 8 12
      hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/crypto/key/kms/TestKMSClientProvider.java
  33. 11 16
      hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/crypto/key/kms/TestLoadBalancingKMSClientProvider.java
  34. 12 6
      hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/crypto/random/TestOpensslSecureRandom.java
  35. 17 9
      hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/crypto/random/TestOsSecureRandom.java

+ 9 - 10
hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/cli/CLITestHelper.java

@@ -26,8 +26,8 @@ import org.apache.hadoop.util.Shell;
 import org.apache.hadoop.util.StringUtils;
 import org.apache.hadoop.util.XMLUtils;
 
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.fail;
 
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -85,7 +85,7 @@ public class CLITestHelper {
             testConfigFile, e);
         success = false;
       }
-      assertTrue("Error reading test config file", success);
+      assertTrue(success, "Error reading test config file");
     }
   }
 
@@ -113,7 +113,7 @@ public class CLITestHelper {
     readTestConfigFile();
     
     conf = new Configuration();
-    conf.setBoolean(CommonConfigurationKeys.HADOOP_SECURITY_AUTHORIZATION, 
+    conf.setBoolean(CommonConfigurationKeys.HADOOP_SECURITY_AUTHORIZATION,
                     true);
 
     clitestDataDir = new File(TEST_CACHE_DATA_DIR).
@@ -262,10 +262,9 @@ public class CLITestHelper {
     	LOG.info("NONE");
     }
 
-    assertTrue("One of the tests failed. " +
-    		"See the Detailed results to identify " +
-    		"the command that failed", overallResults);
-    
+    assertTrue(overallResults, "One of the tests failed. " +
+        "See the Detailed results to identify " +
+        "the command that failed");
   }
   
   /**
@@ -310,8 +309,8 @@ public class CLITestHelper {
    *********************************/
   
   public void testAll() {
-    assertTrue("Number of tests has to be greater then zero",
-      testsFromConfigFile.size() > 0);
+    assertTrue(testsFromConfigFile.size() > 0,
+        "Number of tests has to be greater then zero");
     LOG.info("TestAll");
     // Run the tests defined in the testConf.xml config file.
     for (int index = 0; index < testsFromConfigFile.size(); index++) {

+ 5 - 5
hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/cli/TestCLI.java

@@ -20,21 +20,21 @@ package org.apache.hadoop.cli;
 
 import org.apache.hadoop.cli.util.CLICommand;
 import org.apache.hadoop.cli.util.CommandExecutor;
-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;
 
 /**
  * Tests for the Command Line Interface (CLI)
  */
 public class TestCLI extends CLITestHelper {
-  @Before
+  @BeforeEach
   @Override
   public void setUp() throws Exception {
     super.setUp();
   }
 
-  @After
+  @AfterEach
   @Override
   public void tearDown() throws Exception {
     super.tearDown();

+ 15 - 11
hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/conf/TestConfServlet.java

@@ -43,13 +43,17 @@ import org.apache.hadoop.thirdparty.com.google.common.base.Strings;
 import org.apache.hadoop.http.HttpServer2;
 import org.apache.hadoop.util.XMLUtils;
 
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.mockito.Mockito;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
 
-import static org.mockito.Mockito.when;
+import static org.mockito.Mockito.eq;
 import static org.mockito.Mockito.mock;
-import static org.junit.Assert.*;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+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 static org.junit.jupiter.api.Assertions.fail;
 
 /**
  * Basic test case that the ConfServlet can write configuration
@@ -64,7 +68,7 @@ public class TestConfServlet {
       new HashMap<String, String>();
   private static final Map<String, String> MASK_PROPERTIES = new HashMap<>();
 
-  @BeforeClass
+  @BeforeAll
   public static void initTestProperties() {
     TEST_PROPERTIES.put("test.key1", "value1");
     TEST_PROPERTIES.put("test.key2", "value2");
@@ -101,10 +105,10 @@ public class TestConfServlet {
     verifyMap.put("application/xml", ConfServlet.FORMAT_XML);
     verifyMap.put("application/json", ConfServlet.FORMAT_JSON);
 
-    HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
+    HttpServletRequest request = mock(HttpServletRequest.class);
     for(String contentTypeExpected : verifyMap.keySet()) {
       String contenTypeActual = verifyMap.get(contentTypeExpected);
-      Mockito.when(request.getHeader(HttpHeaders.ACCEPT))
+      when(request.getHeader(HttpHeaders.ACCEPT))
           .thenReturn(contentTypeExpected);
       assertEquals(contenTypeActual,
           ConfServlet.parseAcceptHeader(request));
@@ -160,9 +164,9 @@ public class TestConfServlet {
         } else {
           // if property name is not empty, and it's not in configuration
           // expect proper error code and error message is set to the response
-          Mockito.verify(response).sendError(
-              Mockito.eq(HttpServletResponse.SC_NOT_FOUND),
-              Mockito.eq("Property " + propertyName + " not found"));
+          verify(response).sendError(
+              eq(HttpServletResponse.SC_NOT_FOUND),
+              eq("Property " + propertyName + " not found"));
         }
       }
     } finally {

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

@@ -18,12 +18,13 @@
 
 package org.apache.hadoop.conf;
 
-import org.junit.Assert;
 import org.junit.Test;
 
 import java.util.Arrays;
 import java.util.List;
 
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
 /**
  * Tests the tool (and the default expression) for deciding which config
  * redact.
@@ -75,9 +76,8 @@ public class TestConfigRedactor {
     );
     for (String key : sensitiveKeys) {
       processedText = redactor.redact(key, ORIGINAL_VALUE);
-      Assert.assertEquals(
-          "Config parameter wasn't redacted and should be: " + key,
-          REDACTED_TEXT, processedText);
+      assertEquals(REDACTED_TEXT, processedText,
+          "Config parameter wasn't redacted and should be: " + key);
     }
 
     List<String> normalKeys = Arrays.asList(
@@ -90,9 +90,8 @@ public class TestConfigRedactor {
     );
     for (String key : normalKeys) {
       processedText = redactor.redact(key, ORIGINAL_VALUE);
-      Assert.assertEquals(
-          "Config parameter was redacted and shouldn't be: " + key,
-          ORIGINAL_VALUE, processedText);
+      assertEquals(ORIGINAL_VALUE, processedText,
+          "Config parameter was redacted and shouldn't be: " + key);
     }
   }
 }

+ 67 - 71
hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/conf/TestConfiguration.java

@@ -53,16 +53,24 @@ import static java.util.concurrent.TimeUnit.*;
 import com.fasterxml.jackson.databind.ObjectMapper;
 import org.apache.hadoop.fs.CommonConfigurationKeysPublic;
 import org.assertj.core.api.Assertions;
-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 static org.apache.hadoop.conf.StorageUnit.BYTES;
 import static org.apache.hadoop.conf.StorageUnit.GB;
 import static org.apache.hadoop.conf.StorageUnit.KB;
 import static org.apache.hadoop.conf.StorageUnit.MB;
 import static org.apache.hadoop.conf.StorageUnit.TB;
-import static org.junit.Assert.*;
+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.assertNull;
+import static org.junit.jupiter.api.Assertions.assertSame;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.fail;
 
 import org.apache.commons.lang3.StringUtils;
 import org.apache.hadoop.conf.Configuration.IntegerRanges;
@@ -110,12 +118,12 @@ public class TestConfiguration {
 
   private BufferedWriter out;
 
-  @Before
+  @BeforeEach
   public void setUp() throws Exception {
     conf = new Configuration();
   }
 
-  @After
+  @AfterEach
   public void tearDown() throws Exception {
     if(out != null) {
       out.close();
@@ -228,16 +236,16 @@ public class TestConfiguration {
       // Add the 2 different resources - this should generate a warning
       conf.addResource(in1);
       conf.addResource(in2);
-      assertEquals("should see the first value", "A", conf.get("prop"));
+      assertEquals("A", conf.get("prop"), "should see the first value");
 
       List<LoggingEvent> events = appender.getLog();
-      assertEquals("overriding a final parameter should cause logging", 1,
-          events.size());
+      assertEquals(1, events.size(),
+          "overriding a final parameter should cause logging");
       LoggingEvent loggingEvent = events.get(0);
       String renderedMessage = loggingEvent.getRenderedMessage();
-      assertTrue("did not see expected string inside message "+ renderedMessage,
-          renderedMessage.contains("an attempt to override final parameter: "
-              + "prop;  Ignoring."));
+      assertTrue(renderedMessage.contains(
+          "an attempt to override final parameter: prop;  Ignoring."),
+          "did not see expected string inside message "+ renderedMessage);
     } finally {
       // Make sure the appender is removed
       logger.removeAppender(appender);
@@ -272,8 +280,7 @@ public class TestConfiguration {
       for (LoggingEvent loggingEvent : events) {
         System.out.println("Event = " + loggingEvent.getRenderedMessage());
       }
-      assertTrue("adding same resource twice should not cause logging",
-          events.isEmpty());
+      assertTrue(events.isEmpty(), "adding same resource twice should not cause logging");
     } finally {
       // Make sure the appender is removed
       logger.removeAppender(appender);
@@ -302,14 +309,13 @@ public class TestConfiguration {
     try {
       // Add the resource - this should not produce a warning
       conf.addResource(in1);
-      assertEquals("should see the value", "A", conf.get("prop"));
+      assertEquals("A", conf.get("prop"), "should see the value");
 
       List<LoggingEvent> events = appender.getLog();
       for (LoggingEvent loggingEvent : events) {
         System.out.println("Event = " + loggingEvent.getRenderedMessage());
       }
-      assertTrue("adding same resource twice should not cause logging",
-          events.isEmpty());
+      assertTrue(events.isEmpty(), "adding same resource twice should not cause logging");
     } finally {
       // Make sure the appender is removed
       logger.removeAppender(appender);
@@ -336,16 +342,14 @@ public class TestConfiguration {
     try {
       // Add the resource - this should produce a warning
       conf.addResource(in1);
-      assertEquals("should see the value", "A", conf.get("prop"));
+      assertEquals("A", conf.get("prop"), "should see the value");
 
       List<LoggingEvent> events = appender.getLog();
-      assertEquals("overriding a final parameter should cause logging", 1,
-          events.size());
+      assertEquals(1, events.size(), "overriding a final parameter should cause logging");
       LoggingEvent loggingEvent = events.get(0);
       String renderedMessage = loggingEvent.getRenderedMessage();
-      assertTrue("did not see expected string inside message "+ renderedMessage,
-          renderedMessage.contains("an attempt to override final parameter: "
-              + "prop;  Ignoring."));
+      assertTrue(renderedMessage.contains("an attempt to override final parameter: " +
+          "prop;  Ignoring."), "did not see expected string inside message "+ renderedMessage);
     } finally {
       // Make sure the appender is removed
       logger.removeAppender(appender);
@@ -563,7 +567,7 @@ public class TestConfiguration {
     Path fileResource = new Path(CONFIG);
     Configuration conf1 = new Configuration();
     conf1.addResource(fileResource);
-    assertNull("my var is not null", conf1.get("my.var"));
+    assertNull(conf1.get("my.var"), "my var is not null");
 
     out=new BufferedWriter(new FileWriter(CONFIG2));
     startConfig();
@@ -573,7 +577,7 @@ public class TestConfiguration {
 
     Configuration conf2 = new Configuration(conf1);
     conf2.addResource(fileResource);
-    assertNull("my var is not final", conf2.get("my.var"));
+    assertNull(conf2.get("my.var"), "my var is not final");
   }
 
   @Test
@@ -808,10 +812,10 @@ public class TestConfiguration {
     conf.set("dirs", StringUtils.join(dirs, ","));
     for (int i = 0; i < 1000; i++) {
       String localPath = conf.getLocalPath("dirs", "dir" + i).toString();
-      assertTrue("Path doesn't end in specified dir: " + localPath,
-        localPath.endsWith("dir" + i));
-      assertFalse("Path has internal whitespace: " + localPath,
-        localPath.contains(" "));
+      assertTrue(localPath.endsWith("dir" + i),
+          "Path doesn't end in specified dir: " + localPath);
+      assertFalse(localPath.contains(" "),
+          "Path has internal whitespace: " + localPath);
     }
   }
 
@@ -825,10 +829,10 @@ public class TestConfiguration {
     conf.set("dirs", StringUtils.join(dirs, ","));
     for (int i = 0; i < 1000; i++) {
       String localPath = conf.getFile("dirs", "dir" + i).toString();
-      assertTrue("Path doesn't end in specified dir: " + localPath,
-        localPath.endsWith("dir" + i));
-      assertFalse("Path has internal whitespace: " + localPath,
-        localPath.contains(" "));
+      assertTrue(localPath.endsWith("dir" + i),
+          "Path doesn't end in specified dir: " + localPath);
+      assertFalse(localPath.contains(" "),
+          "Path has internal whitespace: " + localPath);
     }
   }
 
@@ -852,9 +856,9 @@ public class TestConfiguration {
     ByteArrayOutputStream baos = new ByteArrayOutputStream();
     conf.writeXml(baos);
     String result = baos.toString();
-    assertTrue("Result has proper header", result.startsWith(XMLHEADER));
+    assertTrue(result.startsWith(XMLHEADER), "Result has proper header");
 
-    assertTrue("Result has proper footer", result.endsWith("</configuration>"));
+    assertTrue(result.endsWith("</configuration>"), "Result has proper footer");
   }
 
   @Test
@@ -1194,7 +1198,7 @@ public class TestConfiguration {
   public void testGetRangeIterator() throws Exception {
     Configuration config = new Configuration(false);
     IntegerRanges ranges = config.getRange("Test", "");
-    assertFalse("Empty range has values", ranges.iterator().hasNext());
+    assertFalse(ranges.iterator().hasNext(), "Empty range has values");
     ranges = config.getRange("Test", "5");
     Set<Integer> expected = new HashSet<Integer>(Arrays.asList(5));
     Set<Integer> found = new HashSet<Integer>();
@@ -1689,18 +1693,15 @@ public class TestConfiguration {
     conf.set("fs.defaultFS", "value");
     String [] sources = conf.getPropertySources("test.foo");
     assertEquals(1, sources.length);
-    assertEquals(
-        "Resource string returned for a file-loaded property" +
-            " must be a proper absolute path",
-        fileResource,
-        new Path(sources[0]));
-    assertArrayEquals("Resource string returned for a set() property must be " +
-            "\"programmatically\"",
-        new String[]{"programmatically"},
-        conf.getPropertySources("fs.defaultFS"));
-    assertArrayEquals("Resource string returned for an unset property must "
-            + "be null",
-        null, conf.getPropertySources("fs.defaultFoo"));
+    assertEquals(fileResource, new Path(sources[0]),
+        "Resource string returned for a file-loaded property " +
+        "must be a proper absolute path");
+    assertArrayEquals(new String[]{"programmatically"},
+        conf.getPropertySources("fs.defaultFS"),
+        "Resource string returned for a set() property must be " +
+        "\"programmatically\"");
+    assertArrayEquals(null, conf.getPropertySources("fs.defaultFoo"),
+        "Resource string returned for an unset property must be null");
   }
 
   @Test
@@ -1716,11 +1717,9 @@ public class TestConfiguration {
     assertEquals("a", sources[0]);
     assertEquals("b", sources[1]);
     assertEquals("c", sources[2]);
-    assertEquals(
+    assertEquals(fileResource, new Path(sources[3]),
         "Resource string returned for a file-loaded property" +
-            " must be a proper absolute path",
-        fileResource,
-        new Path(sources[3]));
+        " must be a proper absolute path");
   }
 
   @Test
@@ -2225,10 +2224,10 @@ public class TestConfiguration {
     conf.set(key4, "value3");
 
     Map<String,String> res = conf.getValByRegex("^t\\..*\\.key\\d");
-    assertTrue("Conf didn't get key " + key1, res.containsKey(key1));
-    assertTrue("Conf didn't get key " + key2, res.containsKey(key2));
-    assertTrue("Picked out wrong key " + key3, !res.containsKey(key3));
-    assertTrue("Picked out wrong key " + key4, !res.containsKey(key4));
+    assertTrue(res.containsKey(key1), "Conf didn't get key " + key1);
+    assertTrue(res.containsKey(key2), "Conf didn't get key " + key2);
+    assertTrue(!res.containsKey(key3), "Picked out wrong key " + key3);
+    assertTrue(!res.containsKey(key4), "Picked out wrong key " + key4);
   }
 
   @Test
@@ -2236,11 +2235,9 @@ public class TestConfiguration {
     Configuration config = new Configuration();
     Class<?>[] classes =
         config.getClasses("testClassName", Configuration.class);
-    assertEquals(
-        "Not returning expected number of classes. Number of returned classes ="
-            + classes.length, 1, classes.length);
-    assertEquals("Not returning the default class Name", Configuration.class,
-        classes[0]);
+    assertEquals(1, classes.length,
+        "Not returning expected number of classes. Number of returned classes =" + classes.length);
+    assertEquals(Configuration.class, classes[0], "Not returning the default class Name");
   }
 
   @Test
@@ -2249,9 +2246,8 @@ public class TestConfiguration {
     Configuration config = new Configuration();
     config.set("testClassName", "");
     Class<?>[] classes = config.getClasses("testClassName", Configuration.class);
-    assertEquals(
-        "Not returning expected number of classes. Number of returned classes ="
-            + classes.length, 0, classes.length);
+    assertEquals(0, classes.length,
+        "Not returning expected number of classes. Number of returned classes =" + classes.length);
   }
 
   @Test
@@ -2292,7 +2288,7 @@ public class TestConfiguration {
         "foo${" + key + "}bar",
         "${" + key + "}bar")) {
       configuration.set(key, keyExpression);
-      assertEquals("Unexpected value", keyExpression, configuration.get(key));
+      assertEquals(keyExpression, configuration.get(key), "Unexpected value");
     }
   }
 
@@ -2311,7 +2307,7 @@ public class TestConfiguration {
         "${" + key + "bar")) {
       configuration.set(key, keyExpression);
       String value = configuration.get(key);
-      assertTrue("Unexpected value " + value, value.equals(keyExpression));
+      assertTrue(value.equals(keyExpression), "Unexpected value " + value);
     }
   }
 
@@ -2401,12 +2397,12 @@ public class TestConfiguration {
     Path fileResource = new Path(CONFIG);
     Configuration conf = new Configuration();
     Set<String> finalParameters = conf.getFinalParameters();
-    assertFalse("my.var already exists", finalParameters.contains("my.var"));
+    assertFalse(finalParameters.contains("my.var"), "my.var already exists");
     conf.addResource(fileResource);
-    assertEquals("my.var is undefined", "x", conf.get("my.var"));
-    assertFalse("finalparams not copied", finalParameters.contains("my.var"));
+    assertEquals("x", conf.get("my.var"), "my.var is undefined");
+    assertFalse(finalParameters.contains("my.var"), "finalparams not copied");
     finalParameters = conf.getFinalParameters();
-    assertTrue("my.var is not final", finalParameters.contains("my.var"));
+    assertTrue(finalParameters.contains("my.var"), "my.var is not final");
   }
 
   /**
@@ -2714,6 +2710,6 @@ public class TestConfiguration {
 
     Thread.sleep(1000); //give enough time for threads to run
 
-    assertFalse("ConcurrentModificationException occurred", exceptionOccurred.get());
+    assertFalse(exceptionOccurred.get(), "ConcurrentModificationException occurred");
   }
 }

+ 21 - 20
hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/conf/TestConfigurationDeprecation.java

@@ -18,9 +18,9 @@
 
 package org.apache.hadoop.conf;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
 
 import java.io.BufferedWriter;
 import java.io.File;
@@ -38,18 +38,18 @@ import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicInteger;
 
 import org.apache.hadoop.fs.CommonConfigurationKeys;
-import org.junit.Assert;
 
 import org.apache.hadoop.fs.Path;
 import org.apache.hadoop.conf.Configuration.DeprecationDelta;
-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.apache.hadoop.thirdparty.com.google.common.util.concurrent.ThreadFactoryBuilder;
 import org.apache.hadoop.thirdparty.com.google.common.util.concurrent.Uninterruptibles;
 
- 
+
 public class TestConfigurationDeprecation {
   private Configuration conf;
   final static String CONFIG = new File("./test-config" +
@@ -66,12 +66,12 @@ public class TestConfigurationDeprecation {
     Configuration.addDefaultResource("test-fake-default.xml");
   }
 
-  @Before
+  @BeforeEach
   public void setUp() throws Exception {
     conf = new Configuration(false);
   }
 
-  @After
+  @AfterEach
   public void tearDown() throws Exception {
     new File(CONFIG).delete();
     new File(CONFIG2).delete();
@@ -122,7 +122,7 @@ public class TestConfigurationDeprecation {
   /**
    * This test checks the correctness of loading/setting the properties in terms
    * of occurrence of deprecated keys.
-   * @throws IOException 
+   * @throws IOException
    */
   @Test
   public void testDeprecation() throws IOException {
@@ -319,9 +319,9 @@ public class TestConfigurationDeprecation {
         nKFound = true;
       }
     }
-    assertTrue("regular Key not found", kFound);
-    assertTrue("deprecated Key not found", dKFound);
-    assertTrue("new Key not found", nKFound);
+    assertTrue(kFound, "regular Key not found");
+    assertTrue(dKFound, "deprecated Key not found");
+    assertTrue(nKFound, "new Key not found");
   }
   
   @Test
@@ -353,7 +353,8 @@ public class TestConfigurationDeprecation {
    * and set() on Configuration objects.
    */
   @SuppressWarnings("deprecation")
-  @Test(timeout=60000)
+  @Test
+  @Timeout(value = 60)
   public void testConcurrentDeprecateAndManipulate() throws Exception {
     final int NUM_THREAD_IDS = 10;
     final int NUM_KEYS_PER_THREAD = 1000;
@@ -395,7 +396,7 @@ public class TestConfigurationDeprecation {
             String testNewKey = getTestKeyName(threadIndex, i) + ".new";
             String value = "value." + threadIndex + "." + i;
             conf.set(testNewKey, value);
-            Assert.assertEquals(value, conf.get(testNewKey));
+            assertEquals(value, conf.get(testNewKey));
           }
           return null;
         }
@@ -458,10 +459,10 @@ public class TestConfigurationDeprecation {
         new Configuration.DeprecationDelta(oldZkAddressKey, newZkAddressKey)});
 
     // ASSERT
-    assertEquals("Property should be accessible through deprecated key",
-        zkAddressValue, conf.get(oldZkAddressKey));
-    assertEquals("Property should be accessible through new key",
-        zkAddressValue, conf.get(newZkAddressKey));
+    assertEquals(zkAddressValue, conf.get(oldZkAddressKey),
+        "Property should be accessible through deprecated key");
+    assertEquals(zkAddressValue, conf.get(newZkAddressKey),
+        "Property should be accessible through new key");
   }
 
 }

+ 21 - 21
hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/conf/TestConfigurationFieldsBase.java

@@ -20,9 +20,9 @@ package org.apache.hadoop.conf;
 
 import org.apache.commons.lang3.StringUtils;
 import org.apache.hadoop.test.ReflectionUtils;
-import org.junit.Before;
-import org.junit.Ignore;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.Test;
 
 import java.lang.reflect.Field;
 import java.lang.reflect.Modifier;
@@ -40,9 +40,9 @@ import java.util.regex.Pattern;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
 
 /**
  * Base class for comparing fields in one or more Configuration classes
@@ -80,7 +80,7 @@ import static org.junit.Assert.assertNull;
  * run.  This class (and its subclasses) are mostly not intended to be
  * overridden, but to do a very specific form of comparison testing.
  */
-@Ignore
+@Disabled
 public abstract class TestConfigurationFieldsBase {
 
   private static final Logger LOG = LoggerFactory.getLogger(
@@ -397,13 +397,13 @@ public abstract class TestConfigurationFieldsBase {
    * Initialize the four variables corresponding the Configuration
    * class and the XML properties file.
    */
-  @Before
+  @BeforeEach
   public void setupTestConfigurationFields() {
     initializeMemberVariables();
 
     // Error if subclass hasn't set class members
-    assertNotNull("XML file name is null", xmlFilename);
-    assertNotNull("Configuration classes array is null", configurationClasses);
+    assertNotNull(xmlFilename, "XML file name is null");
+    assertNotNull(configurationClasses, "Configuration classes array is null");
 
     // Create class member/value map
     configurationMemberVariables = new HashMap<>();
@@ -449,8 +449,8 @@ public abstract class TestConfigurationFieldsBase {
   @Test
   public void testCompareConfigurationClassAgainstXml() {
     // Error if subclass hasn't set class members
-    assertNotNull("XML file name is null", xmlFilename);
-    assertNotNull("Configuration classes array is null", configurationClasses);
+    assertNotNull(xmlFilename, "XML file name is null");
+    assertNotNull(configurationClasses, "Configuration classes array is null");
 
     final int missingXmlSize = configurationFieldsMissingInXmlFile.size();
 
@@ -477,7 +477,7 @@ public abstract class TestConfigurationFieldsBase {
     }
     LOG.info("\n=====\n");
     if (errorIfMissingXmlProps) {
-      assertEquals(xmlErrorMsg.toString(), 0, missingXmlSize);
+      assertEquals(0, missingXmlSize, xmlErrorMsg.toString());
     }
   }
 
@@ -503,8 +503,8 @@ public abstract class TestConfigurationFieldsBase {
   @Test
   public void testCompareXmlAgainstConfigurationClass() {
     // Error if subclass hasn't set class members
-    assertNotNull("XML file name is null", xmlFilename);
-    assertNotNull("Configuration classes array is null", configurationClasses);
+    assertNotNull(xmlFilename, "XML file name is null");
+    assertNotNull(configurationClasses, "Configuration classes array is null");
 
     final int missingConfigSize = xmlFieldsMissingInConfiguration.size();
 
@@ -524,7 +524,7 @@ public abstract class TestConfigurationFieldsBase {
     }
     LOG.info("\n=====\n");
     if (errorIfMissingConfigProps) {
-      assertEquals(configErrorMsg.toString(), 0, missingConfigSize);
+      assertEquals(0, missingConfigSize, configErrorMsg.toString());
     }
   }
 
@@ -535,9 +535,9 @@ public abstract class TestConfigurationFieldsBase {
   @Test
   public void testXmlAgainstDefaultValuesInConfigurationClass() {
     // Error if subclass hasn't set class members
-    assertNotNull("XML file name is null", xmlFilename);
-    assertNotNull("Configuration member variables is null", configurationMemberVariables);
-    assertNotNull("Configuration default variables is null", configurationMemberVariables);
+    assertNotNull(xmlFilename, "XML file name is null");
+    assertNotNull(configurationMemberVariables, "Configuration member variables is null");
+    assertNotNull(configurationMemberVariables, "Configuration default variables is null");
 
     Set<String> xmlPropertiesWithEmptyValue = new TreeSet<>();
     Set<String> configPropertiesWithNoDefaultConfig = new TreeSet<>();
@@ -685,8 +685,8 @@ public abstract class TestConfigurationFieldsBase {
           if (StringUtils.isNumeric(ent.getValue())) {
             String crtValue =
                 filteredValues.putIfAbsent(ent.getValue(), ent.getKey());
-            assertNull("Parameters " + ent.getKey() + " and " + crtValue +
-                " are using the same default value!", crtValue);
+            assertNull(crtValue, "Parameters " + ent.getKey() + " and " + crtValue +
+                " are using the same default value!");
           }
           valuesChecked++;
         }

+ 8 - 6
hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/conf/TestConfigurationSubclass.java

@@ -17,9 +17,11 @@
  */
 package org.apache.hadoop.conf;
 
-import org.junit.Test;
-import static org.junit.Assert.*;
-
+import org.junit.jupiter.api.Test;
+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 java.util.Properties;
 
 /**
@@ -35,8 +37,8 @@ public class TestConfigurationSubclass {
   public void testGetProps() {
     SubConf conf = new SubConf(true);
     Properties properties = conf.getProperties();
-    assertNotNull("hadoop.tmp.dir is not set",
-            properties.getProperty("hadoop.tmp.dir"));
+    assertNotNull(properties.getProperty("hadoop.tmp.dir"),
+        "hadoop.tmp.dir is not set");
   }
 
   @Test
@@ -60,7 +62,7 @@ public class TestConfigurationSubclass {
       Properties properties = conf.getProperties();
       fail("Should not have got here");
     } catch (RuntimeException e) {
-      assertTrue(e.toString(),e.getMessage().contains("not found"));
+      assertTrue(e.getMessage().contains("not found"), e.toString());
     }
   }
 

+ 7 - 6
hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/conf/TestDeprecatedKeys.java

@@ -22,8 +22,9 @@ import java.io.ByteArrayOutputStream;
 import java.util.Map;
 
 import org.apache.hadoop.fs.CommonConfigurationKeys;
-import org.junit.Test;
-import static org.junit.Assert.*;
+import org.junit.jupiter.api.Test;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
 
 public class TestDeprecatedKeys {
  
@@ -95,9 +96,9 @@ public class TestDeprecatedKeys {
         nK2Found = true;
       }
     }
-    assertTrue("regular Key not found", kFound);
-    assertTrue("deprecated Key not found", dKFound);
-    assertTrue("new Key 1 not found", nK1Found);
-    assertTrue("new Key 2 not found", nK2Found);
+    assertTrue(kFound, "regular Key not found");
+    assertTrue(dKFound, "deprecated Key not found");
+    assertTrue(nK1Found, "new Key 1 not found");
+    assertTrue(nK2Found, "new Key 2 not found");
   }
 }

+ 4 - 2
hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/conf/TestGetInstances.java

@@ -18,9 +18,11 @@
 package org.apache.hadoop.conf;
 
 import java.util.List;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
 
-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;
 
 public class TestGetInstances {
   

+ 55 - 77
hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/conf/TestReconfiguration.java

@@ -23,14 +23,16 @@ import org.apache.hadoop.test.GenericTestUtils;
 import org.apache.hadoop.util.Lists;
 import org.apache.hadoop.util.Time;
 import org.apache.hadoop.conf.ReconfigurationUtil.PropertyChange;
-import org.junit.Test;
-import org.junit.Before;
-
-import static org.hamcrest.CoreMatchers.containsString;
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.Assert.*;
-import static org.junit.Assert.assertEquals;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.Timeout;
+import org.junit.jupiter.api.BeforeEach;
+
+import static org.assertj.core.api.Assertions.assertThat;
+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.ArgumentMatchers.any;
 import static org.mockito.ArgumentMatchers.anyString;
 import static org.mockito.ArgumentMatchers.eq;
@@ -60,7 +62,7 @@ public class TestReconfiguration {
   private static final String VAL1 = "val1";
   private static final String VAL2 = "val2";
 
-  @Before
+  @BeforeEach
   public void setUp () {
     conf1 = new Configuration();
     conf2 = new Configuration();
@@ -85,8 +87,7 @@ public class TestReconfiguration {
     Collection<ReconfigurationUtil.PropertyChange> changes = 
       ReconfigurationUtil.getChangedProperties(conf2, conf1);
 
-    assertTrue("expected 3 changed properties but got " + changes.size(),
-               changes.size() == 3);
+    assertEquals(3, changes.size(), "expected 3 changed properties but got " + changes.size());
 
     boolean changeFound = false;
     boolean unsetFound = false;
@@ -105,8 +106,7 @@ public class TestReconfiguration {
       } 
     }
     
-    assertTrue("not all changes have been applied",
-               changeFound && unsetFound && setFound);
+    assertTrue(changeFound && unsetFound && setFound, "not all changes have been applied");
   }
 
   /**
@@ -160,40 +160,28 @@ public class TestReconfiguration {
   public void testReconfigure() {
     ReconfigurableDummy dummy = new ReconfigurableDummy(conf1);
 
-    assertTrue(PROP1 + " set to wrong value ",
-               dummy.getConf().get(PROP1).equals(VAL1));
-    assertTrue(PROP2 + " set to wrong value ",
-               dummy.getConf().get(PROP2).equals(VAL1));
-    assertTrue(PROP3 + " set to wrong value ",
-               dummy.getConf().get(PROP3).equals(VAL1));
-    assertTrue(PROP4 + " set to wrong value ",
-               dummy.getConf().get(PROP4) == null);
-    assertTrue(PROP5 + " set to wrong value ",
-               dummy.getConf().get(PROP5) == null);
-
-    assertTrue(PROP1 + " should be reconfigurable ",
-               dummy.isPropertyReconfigurable(PROP1));
-    assertTrue(PROP2 + " should be reconfigurable ",
-               dummy.isPropertyReconfigurable(PROP2));
-    assertFalse(PROP3 + " should not be reconfigurable ",
-                dummy.isPropertyReconfigurable(PROP3));
-    assertTrue(PROP4 + " should be reconfigurable ",
-               dummy.isPropertyReconfigurable(PROP4));
-    assertFalse(PROP5 + " should not be reconfigurable ",
-                dummy.isPropertyReconfigurable(PROP5));
+    assertEquals(VAL1, dummy.getConf().get(PROP1), PROP1 + " set to wrong value ");
+    assertEquals(VAL1, dummy.getConf().get(PROP2), PROP2 + " set to wrong value ");
+    assertEquals(VAL1, dummy.getConf().get(PROP3), PROP3 + " set to wrong value ");
+    assertNull(dummy.getConf().get(PROP4), PROP4 + " set to wrong value ");
+    assertNull(dummy.getConf().get(PROP5), PROP5 + " set to wrong value ");
+
+    assertTrue(dummy.isPropertyReconfigurable(PROP1), PROP1 + " should be reconfigurable ");
+    assertTrue(dummy.isPropertyReconfigurable(PROP2), PROP2 + " should be reconfigurable ");
+    assertFalse(dummy.isPropertyReconfigurable(PROP3), PROP3 + " should not be reconfigurable ");
+    assertTrue(dummy.isPropertyReconfigurable(PROP4), PROP4 + " should be reconfigurable ");
+    assertFalse(dummy.isPropertyReconfigurable(PROP5), PROP5 + " should not be reconfigurable ");
 
     // change something to the same value as before
     {
       boolean exceptionCaught = false;
       try {
         dummy.reconfigureProperty(PROP1, VAL1);
-        assertTrue(PROP1 + " set to wrong value ",
-                   dummy.getConf().get(PROP1).equals(VAL1));
+        assertEquals(VAL1, dummy.getConf().get(PROP1), PROP1 + " set to wrong value ");
       } catch (ReconfigurationException e) {
         exceptionCaught = true;
       }
-      assertFalse("received unexpected exception",
-                  exceptionCaught);
+      assertFalse(exceptionCaught, "received unexpected exception");
     }
 
     // change something to null
@@ -201,13 +189,11 @@ public class TestReconfiguration {
       boolean exceptionCaught = false;
       try {
         dummy.reconfigureProperty(PROP1, null);
-        assertTrue(PROP1 + "set to wrong value ",
-                   dummy.getConf().get(PROP1) == null);
+        assertNull(dummy.getConf().get(PROP1), PROP1 + "set to wrong value ");
       } catch (ReconfigurationException e) {
         exceptionCaught = true;
       }
-      assertFalse("received unexpected exception",
-                  exceptionCaught);
+      assertFalse(exceptionCaught, "received unexpected exception");
     }
 
     // change something to a different value than before
@@ -215,13 +201,11 @@ public class TestReconfiguration {
       boolean exceptionCaught = false;
       try {
         dummy.reconfigureProperty(PROP1, VAL2);
-        assertTrue(PROP1 + "set to wrong value ",
-                   dummy.getConf().get(PROP1).equals(VAL2));
+        assertEquals(VAL2, dummy.getConf().get(PROP1), PROP1 + "set to wrong value ");
       } catch (ReconfigurationException e) {
         exceptionCaught = true;
       }
-      assertFalse("received unexpected exception",
-                  exceptionCaught);
+      assertFalse(exceptionCaught, "received unexpected exception");
     }
 
     // set unset property to null
@@ -229,13 +213,11 @@ public class TestReconfiguration {
       boolean exceptionCaught = false;
       try {
         dummy.reconfigureProperty(PROP4, null);
-        assertTrue(PROP4 + "set to wrong value ",
-                   dummy.getConf().get(PROP4) == null);
+        assertNull(dummy.getConf().get(PROP4), PROP4 + "set to wrong value ");
       } catch (ReconfigurationException e) {
         exceptionCaught = true;
       }
-      assertFalse("received unexpected exception",
-                  exceptionCaught);
+      assertFalse(exceptionCaught, "received unexpected exception");
     }
 
     // set unset property
@@ -243,13 +225,11 @@ public class TestReconfiguration {
       boolean exceptionCaught = false;
       try {
         dummy.reconfigureProperty(PROP4, VAL1);
-        assertTrue(PROP4 + "set to wrong value ",
-                   dummy.getConf().get(PROP4).equals(VAL1));
+        assertEquals(VAL1, dummy.getConf().get(PROP4), PROP4 + "set to wrong value ");
       } catch (ReconfigurationException e) {
         exceptionCaught = true;
       }
-      assertFalse("received unexpected exception",
-                  exceptionCaught);
+      assertFalse(exceptionCaught, "received unexpected exception");
     }
 
     // try to set unset property to null (not reconfigurable)
@@ -260,8 +240,7 @@ public class TestReconfiguration {
       } catch (ReconfigurationException e) {
         exceptionCaught = true;
       }
-      assertTrue("did not receive expected exception",
-                 exceptionCaught);
+      assertTrue(exceptionCaught, "did not receive expected exception");
     }
 
     // try to set unset property to value (not reconfigurable)
@@ -272,8 +251,7 @@ public class TestReconfiguration {
       } catch (ReconfigurationException e) {
         exceptionCaught = true;
       }
-      assertTrue("did not receive expected exception",
-                 exceptionCaught);
+      assertTrue(exceptionCaught, "did not receive expected exception");
     }
 
     // try to change property to value (not reconfigurable)
@@ -284,8 +262,7 @@ public class TestReconfiguration {
       } catch (ReconfigurationException e) {
         exceptionCaught = true;
       }
-      assertTrue("did not receive expected exception",
-                 exceptionCaught);
+      assertTrue(exceptionCaught, "did not receive expected exception");
     }
 
     // try to change property to null (not reconfigurable)
@@ -296,8 +273,7 @@ public class TestReconfiguration {
       } catch (ReconfigurationException e) {
         exceptionCaught = true;
       }
-      assertTrue("did not receive expected exception",
-                 exceptionCaught);
+      assertTrue(exceptionCaught, "did not receive expected exception");
     }
   }
 
@@ -326,17 +302,14 @@ public class TestReconfiguration {
       }
     }
 
-    assertFalse("dummy thread should not be alive",
-                dummyThread.isAlive());
+    assertFalse(dummyThread.isAlive(), "dummy thread should not be alive");
     dummy.running = false;
     try {
       dummyThread.join();
     } catch (InterruptedException ignore) {
       // do nothing
     }
-    assertTrue(PROP1 + " is set to wrong value",
-               dummy.getConf().get(PROP1).equals(VAL2));
-    
+    assertTrue(dummy.getConf().get(PROP1).equals(VAL2), PROP1 + " is set to wrong value");
   }
 
   private static class AsyncReconfigurableDummy extends ReconfigurableBase {
@@ -418,17 +391,18 @@ public class TestReconfiguration {
       if (change.prop.equals("name1")) {
         assertFalse(result.getValue().isPresent());
       } else if (change.prop.equals("name2")) {
-        assertThat(result.getValue().get(),
-            containsString("Property name2 is not reconfigurable"));
+        assertThat(result.getValue().get()).
+            contains("Property name2 is not reconfigurable");
       } else if (change.prop.equals("name3")) {
-        assertThat(result.getValue().get(), containsString("io exception"));
+        assertThat(result.getValue().get()).contains("io exception");
       } else {
         fail("Unknown property: " + change.prop);
       }
     }
   }
 
-  @Test(timeout=30000)
+  @Test
+  @Timeout(value = 30)
   public void testStartReconfigurationFailureDueToExistingRunningTask()
       throws InterruptedException, IOException {
     AsyncReconfigurableDummy dummy = spy(new AsyncReconfigurableDummy(conf1));
@@ -484,7 +458,8 @@ public class TestReconfiguration {
    * parent's cached configuration on success.
    * @throws IOException
    */
-  @Test (timeout=300000)
+  @Test
+  @Timeout(value = 300)
   public void testConfIsUpdatedOnSuccess() throws ReconfigurationException {
     final String property = "FOO";
     final String value1 = "value1";
@@ -499,7 +474,7 @@ public class TestReconfiguration {
         conf, newConf, Arrays.asList(property));
 
     reconfigurable.reconfigureProperty(property, value2);
-    assertThat(reconfigurable.getConf().get(property), is(value2));
+    assertThat(reconfigurable.getConf().get(property)).isEqualTo(value2);
   }
 
   /**
@@ -507,7 +482,8 @@ public class TestReconfiguration {
    * its parent's cached configuration on success.
    * @throws IOException
    */
-  @Test (timeout=300000)
+  @Test
+  @Timeout(value = 300)
   public void testConfIsUpdatedOnSuccessAsync() throws ReconfigurationException,
       TimeoutException, InterruptedException, IOException {
     final String property = "FOO";
@@ -530,7 +506,7 @@ public class TestReconfiguration {
         return reconfigurable.getReconfigurationTaskStatus().stopped();
       }
     }, 100, 60000);
-    assertThat(reconfigurable.getConf().get(property), is(value2));
+    assertThat(reconfigurable.getConf().get(property)).isEqualTo(value2);
   }
 
   /**
@@ -538,7 +514,8 @@ public class TestReconfiguration {
    * property in its parent's configuration when the new value is null.
    * @throws IOException
    */
-  @Test (timeout=300000)
+  @Test
+  @Timeout(value = 300)
   public void testConfIsUnset() throws ReconfigurationException {
     final String property = "FOO";
     final String value1 = "value1";
@@ -559,7 +536,8 @@ public class TestReconfiguration {
    * property in its parent's configuration when the new value is null.
    * @throws IOException
    */
-  @Test (timeout=300000)
+  @Test
+  @Timeout(value = 300)
   public void testConfIsUnsetAsync() throws ReconfigurationException,
       IOException, TimeoutException, InterruptedException {
     final String property = "FOO";

+ 114 - 120
hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/conf/TestStorageUnit.java

@@ -18,13 +18,12 @@
 
 package org.apache.hadoop.conf;
 
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
 
 import java.util.HashMap;
 import java.util.Map;
 
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.MatcherAssert.assertThat;
+import static org.assertj.core.api.Assertions.assertThat;
 
 /**
  * Tests that Storage Units work as expected.
@@ -50,7 +49,7 @@ public class TestStorageUnit {
     results.put(0.0, 0.0);
 
     for (Map.Entry<Double, Double> entry : results.entrySet()) {
-      assertThat(StorageUnit.BYTES.toKBs(entry.getKey()), is(entry.getValue()));
+      assertThat(StorageUnit.BYTES.toKBs(entry.getKey())).isEqualTo(entry.getValue());
     }
   }
 
@@ -64,7 +63,7 @@ public class TestStorageUnit {
     results.put(-35651584.0, -34.0);
     results.put(0.0, 0.0);
     for (Map.Entry<Double, Double> entry : results.entrySet()) {
-      assertThat(StorageUnit.BYTES.toMBs(entry.getKey()), is(entry.getValue()));
+      assertThat(StorageUnit.BYTES.toMBs(entry.getKey())).isEqualTo(entry.getValue());
     }
   }
 
@@ -78,7 +77,7 @@ public class TestStorageUnit {
     results.put(-36507222016.0, -34.0);
     results.put(0.0, 0.0);
     for (Map.Entry<Double, Double> entry : results.entrySet()) {
-      assertThat(StorageUnit.BYTES.toGBs(entry.getKey()), is(entry.getValue()));
+      assertThat(StorageUnit.BYTES.toGBs(entry.getKey())).isEqualTo(entry.getValue());
     }
   }
 
@@ -92,7 +91,7 @@ public class TestStorageUnit {
     results.put(-3.73834E+13, -34.0);
     results.put(0.0, 0.0);
     for (Map.Entry<Double, Double> entry : results.entrySet()) {
-      assertThat(StorageUnit.BYTES.toTBs(entry.getKey()), is(entry.getValue()));
+      assertThat(StorageUnit.BYTES.toTBs(entry.getKey())).isEqualTo(entry.getValue());
     }
   }
 
@@ -106,7 +105,7 @@ public class TestStorageUnit {
     results.put(-3.82806E+16, -34.0);
     results.put(0.0, 0.0);
     for (Map.Entry<Double, Double> entry : results.entrySet()) {
-      assertThat(StorageUnit.BYTES.toPBs(entry.getKey()), is(entry.getValue()));
+      assertThat(StorageUnit.BYTES.toPBs(entry.getKey())).isEqualTo(entry.getValue());
     }
   }
 
@@ -120,157 +119,152 @@ public class TestStorageUnit {
     results.put(-3.91993E+19, -34.0);
     results.put(0.0, 0.0);
     for (Map.Entry<Double, Double> entry : results.entrySet()) {
-      assertThat(StorageUnit.BYTES.toEBs(entry.getKey()), is(entry.getValue()));
+      assertThat(StorageUnit.BYTES.toEBs(entry.getKey())).isEqualTo(entry.getValue());
     }
   }
 
   @Test
   public void testByteConversions() {
-    assertThat(StorageUnit.BYTES.getShortName(), is("b"));
-    assertThat(StorageUnit.BYTES.getSuffixChar(), is("b"));
-
-    assertThat(StorageUnit.BYTES.getLongName(), is("bytes"));
-    assertThat(StorageUnit.BYTES.toString(), is("bytes"));
-    assertThat(StorageUnit.BYTES.toBytes(1), is(1.0));
-    assertThat(StorageUnit.BYTES.toBytes(1024),
-        is(StorageUnit.BYTES.getDefault(1024)));
-    assertThat(StorageUnit.BYTES.fromBytes(10), is(10.0));
+    assertThat(StorageUnit.BYTES.getShortName()).isEqualTo("b");
+    assertThat(StorageUnit.BYTES.getSuffixChar()).isEqualTo("b");
+
+    assertThat(StorageUnit.BYTES.getLongName()).isEqualTo("bytes");
+    assertThat(StorageUnit.BYTES.toString()).isEqualTo("bytes");
+    assertThat(StorageUnit.BYTES.toBytes(1)).isEqualTo((1.0));
+    assertThat(StorageUnit.BYTES.toBytes(1024)).
+        isEqualTo(StorageUnit.BYTES.getDefault(1024));
+    assertThat(StorageUnit.BYTES.fromBytes(10)).isEqualTo(10.0);
   }
 
   @Test
   public void testKBConversions() {
-    assertThat(StorageUnit.KB.getShortName(), is("kb"));
-    assertThat(StorageUnit.KB.getSuffixChar(), is("k"));
-    assertThat(StorageUnit.KB.getLongName(), is("kilobytes"));
-    assertThat(StorageUnit.KB.toString(), is("kilobytes"));
-    assertThat(StorageUnit.KB.toKBs(1024),
-        is(StorageUnit.KB.getDefault(1024)));
-
-
-    assertThat(StorageUnit.KB.toBytes(1), is(KB));
-    assertThat(StorageUnit.KB.fromBytes(KB), is(1.0));
-
-    assertThat(StorageUnit.KB.toKBs(10), is(10.0));
-    assertThat(StorageUnit.KB.toMBs(3.0 * 1024.0), is(3.0));
-    assertThat(StorageUnit.KB.toGBs(1073741824), is(1024.0));
-    assertThat(StorageUnit.KB.toTBs(1073741824), is(1.0));
-    assertThat(StorageUnit.KB.toPBs(1.0995116e+12), is(1.0));
-    assertThat(StorageUnit.KB.toEBs(1.1258999e+15), is(1.0));
+    assertThat(StorageUnit.KB.getShortName()).isEqualTo("kb");
+    assertThat(StorageUnit.KB.getSuffixChar()).isEqualTo(("k"));
+    assertThat(StorageUnit.KB.getLongName()).isEqualTo("kilobytes");
+    assertThat(StorageUnit.KB.toString()).isEqualTo("kilobytes");
+    assertThat(StorageUnit.KB.toKBs(1024)).
+        isEqualTo(StorageUnit.KB.getDefault(1024));
+
+
+    assertThat(StorageUnit.KB.toBytes(1)).isEqualTo(KB);
+    assertThat(StorageUnit.KB.fromBytes(KB)).isEqualTo(1.0);
+
+    assertThat(StorageUnit.KB.toKBs(10)).isEqualTo((10.0));
+    assertThat(StorageUnit.KB.toMBs(3.0 * 1024.0)).isEqualTo((3.0));
+    assertThat(StorageUnit.KB.toGBs(1073741824)).isEqualTo((1024.0));
+    assertThat(StorageUnit.KB.toTBs(1073741824)).isEqualTo(1.0);
+    assertThat(StorageUnit.KB.toPBs(1.0995116e+12)).isEqualTo((1.0));
+    assertThat(StorageUnit.KB.toEBs(1.1258999e+15)).isEqualTo((1.0));
   }
 
   @Test
   public void testMBConversions() {
-    assertThat(StorageUnit.MB.getShortName(), is("mb"));
-    assertThat(StorageUnit.MB.getSuffixChar(), is("m"));
-    assertThat(StorageUnit.MB.getLongName(), is("megabytes"));
-    assertThat(StorageUnit.MB.toString(), is("megabytes"));
-    assertThat(StorageUnit.MB.toMBs(1024),
-        is(StorageUnit.MB.getDefault(1024)));
+    assertThat(StorageUnit.MB.getShortName()).isEqualTo("mb");
+    assertThat(StorageUnit.MB.getSuffixChar()).isEqualTo("m");
+    assertThat(StorageUnit.MB.getLongName()).isEqualTo("megabytes");
+    assertThat(StorageUnit.MB.toString()).isEqualTo("megabytes");
+    assertThat(StorageUnit.MB.toMBs(1024)).
+        isEqualTo(StorageUnit.MB.getDefault(1024));
 
 
 
-    assertThat(StorageUnit.MB.toBytes(1), is(MB));
-    assertThat(StorageUnit.MB.fromBytes(MB), is(1.0));
+    assertThat(StorageUnit.MB.toBytes(1)).isEqualTo(MB);
+    assertThat(StorageUnit.MB.fromBytes(MB)).isEqualTo(1.0);
 
-    assertThat(StorageUnit.MB.toKBs(1), is(1024.0));
-    assertThat(StorageUnit.MB.toMBs(10), is(10.0));
+    assertThat(StorageUnit.MB.toKBs(1)).isEqualTo(1024.0);
+    assertThat(StorageUnit.MB.toMBs(10)).isEqualTo(10.0);
 
-    assertThat(StorageUnit.MB.toGBs(44040192), is(43008.0));
-    assertThat(StorageUnit.MB.toTBs(1073741824), is(1024.0));
-    assertThat(StorageUnit.MB.toPBs(1073741824), is(1.0));
-    assertThat(StorageUnit.MB.toEBs(1 * (EB/MB)), is(1.0));
+    assertThat(StorageUnit.MB.toGBs(44040192)).isEqualTo(43008.0);
+    assertThat(StorageUnit.MB.toTBs(1073741824)).isEqualTo(1024.0);
+    assertThat(StorageUnit.MB.toPBs(1073741824)).isEqualTo(1.0);
+    assertThat(StorageUnit.MB.toEBs(1 * (EB/MB))).isEqualTo(1.0);
   }
 
   @Test
   public void testGBConversions() {
-    assertThat(StorageUnit.GB.getShortName(), is("gb"));
-    assertThat(StorageUnit.GB.getSuffixChar(), is("g"));
-    assertThat(StorageUnit.GB.getLongName(), is("gigabytes"));
-    assertThat(StorageUnit.GB.toString(), is("gigabytes"));
-    assertThat(StorageUnit.GB.toGBs(1024),
-        is(StorageUnit.GB.getDefault(1024)));
+    assertThat(StorageUnit.GB.getShortName()).isEqualTo("gb");
+    assertThat(StorageUnit.GB.getSuffixChar()).isEqualTo("g");
+    assertThat(StorageUnit.GB.getLongName()).isEqualTo("gigabytes");
+    assertThat(StorageUnit.GB.toString()).isEqualTo("gigabytes");
+    assertThat(StorageUnit.GB.toGBs(1024)).isEqualTo(
+        StorageUnit.GB.getDefault(1024));
 
 
-    assertThat(StorageUnit.GB.toBytes(1), is(GB));
-    assertThat(StorageUnit.GB.fromBytes(GB), is(1.0));
+    assertThat(StorageUnit.GB.toBytes(1)).isEqualTo(GB);
+    assertThat(StorageUnit.GB.fromBytes(GB)).isEqualTo((1.0));
 
-    assertThat(StorageUnit.GB.toKBs(1), is(1024.0 * 1024));
-    assertThat(StorageUnit.GB.toMBs(10), is(10.0 * 1024));
+    assertThat(StorageUnit.GB.toKBs(1)).isEqualTo(1024.0 * 1024);
+    assertThat(StorageUnit.GB.toMBs(10)).isEqualTo((10.0 * 1024));
 
-    assertThat(StorageUnit.GB.toGBs(44040192.0), is(44040192.0));
-    assertThat(StorageUnit.GB.toTBs(1073741824), is(1048576.0));
-    assertThat(StorageUnit.GB.toPBs(1.07375e+9), is(1024.0078));
-    assertThat(StorageUnit.GB.toEBs(1 * (EB/GB)), is(1.0));
+    assertThat(StorageUnit.GB.toGBs(44040192.0)).isEqualTo((44040192.0));
+    assertThat(StorageUnit.GB.toTBs(1073741824)).isEqualTo((1048576.0));
+    assertThat(StorageUnit.GB.toPBs(1.07375e+9)).isEqualTo((1024.0078));
+    assertThat(StorageUnit.GB.toEBs(1 * (EB/GB))).isEqualTo((1.0));
   }
 
   @Test
   public void testTBConversions() {
-    assertThat(StorageUnit.TB.getShortName(), is("tb"));
-    assertThat(StorageUnit.TB.getSuffixChar(), is("t"));
-    assertThat(StorageUnit.TB.getLongName(), is("terabytes"));
-    assertThat(StorageUnit.TB.toString(), is("terabytes"));
-    assertThat(StorageUnit.TB.toTBs(1024),
-        is(StorageUnit.TB.getDefault(1024)));
-
-    assertThat(StorageUnit.TB.toBytes(1), is(TB));
-    assertThat(StorageUnit.TB.fromBytes(TB), is(1.0));
-
-    assertThat(StorageUnit.TB.toKBs(1), is(1024.0 * 1024* 1024));
-    assertThat(StorageUnit.TB.toMBs(10), is(10.0 * 1024 * 1024));
-
-    assertThat(StorageUnit.TB.toGBs(44040192.0), is(45097156608.0));
-    assertThat(StorageUnit.TB.toTBs(1073741824.0), is(1073741824.0));
-    assertThat(StorageUnit.TB.toPBs(1024), is(1.0));
-    assertThat(StorageUnit.TB.toEBs(1 * (EB/TB)), is(1.0));
+    assertThat(StorageUnit.TB.getShortName()).isEqualTo(("tb"));
+    assertThat(StorageUnit.TB.getSuffixChar()).isEqualTo(("t"));
+    assertThat(StorageUnit.TB.getLongName()).isEqualTo(("terabytes"));
+    assertThat(StorageUnit.TB.toString()).isEqualTo(("terabytes"));
+    assertThat(StorageUnit.TB.toTBs(1024)).isEqualTo(
+        (StorageUnit.TB.getDefault(1024)));
+
+    assertThat(StorageUnit.TB.toBytes(1)).isEqualTo((TB));
+    assertThat(StorageUnit.TB.fromBytes(TB)).isEqualTo((1.0));
+
+    assertThat(StorageUnit.TB.toKBs(1)).isEqualTo((1024.0 * 1024* 1024));
+    assertThat(StorageUnit.TB.toMBs(10)).isEqualTo((10.0 * 1024 * 1024));
+
+    assertThat(StorageUnit.TB.toGBs(44040192.0)).isEqualTo(45097156608.0);
+    assertThat(StorageUnit.TB.toTBs(1073741824.0)).isEqualTo(1073741824.0);
+    assertThat(StorageUnit.TB.toPBs(1024)).isEqualTo(1.0);
+    assertThat(StorageUnit.TB.toEBs(1 * (EB/TB))).isEqualTo(1.0);
   }
 
   @Test
   public void testPBConversions() {
-    assertThat(StorageUnit.PB.getShortName(), is("pb"));
-    assertThat(StorageUnit.PB.getSuffixChar(), is("p"));
-    assertThat(StorageUnit.PB.getLongName(), is("petabytes"));
-    assertThat(StorageUnit.PB.toString(), is("petabytes"));
-    assertThat(StorageUnit.PB.toPBs(1024),
-        is(StorageUnit.PB.getDefault(1024)));
-
-
-    assertThat(StorageUnit.PB.toBytes(1), is(PB));
-    assertThat(StorageUnit.PB.fromBytes(PB), is(1.0));
-
-    assertThat(StorageUnit.PB.toKBs(1), is(PB/KB));
-    assertThat(StorageUnit.PB.toMBs(10), is(10.0 * (PB / MB)));
-
-    assertThat(StorageUnit.PB.toGBs(44040192.0),
-        is(44040192.0 * PB/GB));
-    assertThat(StorageUnit.PB.toTBs(1073741824.0),
-        is(1073741824.0 * (PB/TB)));
-    assertThat(StorageUnit.PB.toPBs(1024.0), is(1024.0));
-    assertThat(StorageUnit.PB.toEBs(1024.0), is(1.0));
+    assertThat(StorageUnit.PB.getShortName()).isEqualTo(("pb"));
+    assertThat(StorageUnit.PB.getSuffixChar()).isEqualTo(("p"));
+    assertThat(StorageUnit.PB.getLongName()).isEqualTo(("petabytes"));
+    assertThat(StorageUnit.PB.toString()).isEqualTo(("petabytes"));
+    assertThat(StorageUnit.PB.toPBs(1024)).isEqualTo(
+        StorageUnit.PB.getDefault(1024));
+
+
+    assertThat(StorageUnit.PB.toBytes(1)).isEqualTo(PB);
+    assertThat(StorageUnit.PB.fromBytes(PB)).isEqualTo(1.0);
+
+    assertThat(StorageUnit.PB.toKBs(1)).isEqualTo(PB/KB);
+    assertThat(StorageUnit.PB.toMBs(10)).isEqualTo(10.0 * (PB / MB));
+
+    assertThat(StorageUnit.PB.toGBs(44040192.0)).isEqualTo(44040192.0 * PB/GB);
+    assertThat(StorageUnit.PB.toTBs(1073741824.0)).isEqualTo(1073741824.0 * (PB/TB));
+    assertThat(StorageUnit.PB.toPBs(1024.0)).isEqualTo(1024.0);
+    assertThat(StorageUnit.PB.toEBs(1024.0)).isEqualTo(1.0);
   }
 
 
   @Test
   public void testEBConversions() {
-    assertThat(StorageUnit.EB.getShortName(), is("eb"));
-    assertThat(StorageUnit.EB.getSuffixChar(), is("e"));
-
-    assertThat(StorageUnit.EB.getLongName(), is("exabytes"));
-    assertThat(StorageUnit.EB.toString(), is("exabytes"));
-    assertThat(StorageUnit.EB.toEBs(1024),
-        is(StorageUnit.EB.getDefault(1024)));
-
-    assertThat(StorageUnit.EB.toBytes(1), is(EB));
-    assertThat(StorageUnit.EB.fromBytes(EB), is(1.0));
-
-    assertThat(StorageUnit.EB.toKBs(1), is(EB/KB));
-    assertThat(StorageUnit.EB.toMBs(10), is(10.0 * (EB / MB)));
-
-    assertThat(StorageUnit.EB.toGBs(44040192.0),
-        is(44040192.0 * EB/GB));
-    assertThat(StorageUnit.EB.toTBs(1073741824.0),
-        is(1073741824.0 * (EB/TB)));
-    assertThat(StorageUnit.EB.toPBs(1.0), is(1024.0));
-    assertThat(StorageUnit.EB.toEBs(42.0), is(42.0));
+    assertThat(StorageUnit.EB.getShortName()).isEqualTo("eb");
+    assertThat(StorageUnit.EB.getSuffixChar()).isEqualTo("e");
+
+    assertThat(StorageUnit.EB.getLongName()).isEqualTo("exabytes");
+    assertThat(StorageUnit.EB.toString()).isEqualTo("exabytes");
+    assertThat(StorageUnit.EB.toEBs(1024)).isEqualTo(StorageUnit.EB.getDefault(1024));
+
+    assertThat(StorageUnit.EB.toBytes(1)).isEqualTo(EB);
+    assertThat(StorageUnit.EB.fromBytes(EB)).isEqualTo(1.0);
+
+    assertThat(StorageUnit.EB.toKBs(1)).isEqualTo(EB/KB);
+    assertThat(StorageUnit.EB.toMBs(10)).isEqualTo(10.0 * (EB / MB));
+
+    assertThat(StorageUnit.EB.toGBs(44040192.0)).isEqualTo(44040192.0 * EB/GB);
+    assertThat(StorageUnit.EB.toTBs(1073741824.0)).isEqualTo((1073741824.0 * (EB/TB)));
+    assertThat(StorageUnit.EB.toPBs(1.0)).isEqualTo(1024.0);
+    assertThat(StorageUnit.EB.toEBs(42.0)).isEqualTo(42.0);
   }
 
 

+ 104 - 83
hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/crypto/CryptoStreamsTestBase.java

@@ -40,13 +40,16 @@ import org.apache.hadoop.io.ByteBufferPool;
 import org.apache.hadoop.io.DataOutputBuffer;
 import org.apache.hadoop.io.RandomDatum;
 import org.apache.hadoop.test.GenericTestUtils;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.Timeout;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.fail;
 
 public abstract class CryptoStreamsTestBase {
   protected static final Logger LOG = LoggerFactory.getLogger(
@@ -64,7 +67,7 @@ public abstract class CryptoStreamsTestBase {
   private byte[] data;
   private int dataLen;
   
-  @Before
+  @BeforeEach
   public void setUp() throws IOException {
     // Generate data
     final int seed = new Random().nextInt();
@@ -126,10 +129,10 @@ public abstract class CryptoStreamsTestBase {
     byte[] result = new byte[dataLen];
     int n = preadAll(in, result, 0, dataLen);
 
-    Assert.assertEquals(dataLen, n);
+    assertEquals(dataLen, n);
     byte[] expectedData = new byte[n];
     System.arraycopy(data, 0, expectedData, 0, n);
-    Assert.assertArrayEquals(result, expectedData);
+    assertArrayEquals(result, expectedData);
   }
 
   private int byteBufferPreadAll(ByteBufferPositionedReadable in,
@@ -152,10 +155,10 @@ public abstract class CryptoStreamsTestBase {
     ByteBuffer result = ByteBuffer.allocate(dataLen);
     int n = byteBufferPreadAll(in, result);
 
-    Assert.assertEquals(dataLen, n);
+    assertEquals(dataLen, n);
     ByteBuffer expectedData = ByteBuffer.allocate(n);
     expectedData.put(data, 0, n);
-    Assert.assertArrayEquals(result.array(), expectedData.array());
+    assertArrayEquals(result.array(), expectedData.array());
   }
 
   protected OutputStream getOutputStream(int bufferSize) throws IOException {
@@ -173,7 +176,8 @@ public abstract class CryptoStreamsTestBase {
       byte[] iv) throws IOException;
   
   /** Test crypto reading with different buffer size. */
-  @Test(timeout=120000)
+  @Test
+  @Timeout(value = 120)
   public void testRead() throws Exception {
     OutputStream out = getOutputStream(defaultBufferSize);
     writeData(out);
@@ -193,10 +197,10 @@ public abstract class CryptoStreamsTestBase {
     byte[] result = new byte[dataLen];
     int n = readAll(in, result, 0, dataLen);
     
-    Assert.assertEquals(dataLen, n);
+    assertEquals(dataLen, n);
     byte[] expectedData = new byte[n];
     System.arraycopy(data, 0, expectedData, 0, n);
-    Assert.assertArrayEquals(result, expectedData);
+    assertArrayEquals(result, expectedData);
     
     // EOF
     n = in.read(result, 0, dataLen);
@@ -204,7 +208,8 @@ public abstract class CryptoStreamsTestBase {
   }
   
   /** Test crypto writing with different buffer size. */
-  @Test(timeout = 120000)
+  @Test
+  @Timeout(value = 120)
   public void testWrite() throws Exception {
     // Default buffer size
     writeCheck(defaultBufferSize);
@@ -218,12 +223,13 @@ public abstract class CryptoStreamsTestBase {
     writeData(out);
 
     if (out instanceof FSDataOutputStream) {
-      Assert.assertEquals(((FSDataOutputStream) out).getPos(), getDataLen());
+      assertEquals(((FSDataOutputStream) out).getPos(), getDataLen());
     }
   }
 
   /** Test crypto with different IV. */
-  @Test(timeout=120000)
+  @Test
+  @Timeout(value = 120)
   public void testCryptoIV() throws Exception {
     byte[] iv1 = iv.clone();
     
@@ -266,7 +272,8 @@ public abstract class CryptoStreamsTestBase {
   /**
    * Test hflush/hsync of crypto output stream, and with different buffer size.
    */
-  @Test(timeout=120000)
+  @Test
+  @Timeout(value = 120)
   public void testSyncable() throws IOException {
     syncableCheck();
   }
@@ -298,7 +305,7 @@ public abstract class CryptoStreamsTestBase {
     final byte[] readBuf = new byte[bytesToVerify];
     readAll(in, readBuf, 0, bytesToVerify);
     for (int i = 0; i < bytesToVerify; i++) {
-      Assert.assertEquals(expectedBytes[i], readBuf[i]);
+      assertEquals(expectedBytes[i], readBuf[i]);
     }
   }
   
@@ -334,7 +341,8 @@ public abstract class CryptoStreamsTestBase {
   }
   
   /** Test positioned read. */
-  @Test(timeout=120000)
+  @Test
+  @Timeout(value = 120)
   public void testPositionedRead() throws Exception {
     try (OutputStream out = getOutputStream(defaultBufferSize)) {
       writeData(out);
@@ -353,16 +361,17 @@ public abstract class CryptoStreamsTestBase {
     byte[] result = new byte[dataLen];
     int n = readAll(in, pos, result, 0, dataLen);
     
-    Assert.assertEquals(dataLen, n + pos);
+    assertEquals(dataLen, n + pos);
     byte[] readData = new byte[n];
     System.arraycopy(result, 0, readData, 0, n);
     byte[] expectedData = new byte[n];
     System.arraycopy(data, pos, expectedData, 0, n);
-    Assert.assertArrayEquals(readData, expectedData);
+    assertArrayEquals(readData, expectedData);
   }
 
   /** Test positioned read with ByteBuffers. */
-  @Test(timeout=120000)
+  @Test
+  @Timeout(value = 120)
   public void testPositionedReadWithByteBuffer() throws Exception {
     try (OutputStream out = getOutputStream(defaultBufferSize)) {
       writeData(out);
@@ -382,16 +391,17 @@ public abstract class CryptoStreamsTestBase {
     ByteBuffer result = ByteBuffer.allocate(dataLen);
     int n = readAll(in, pos, result);
 
-    Assert.assertEquals(dataLen, n + pos);
+    assertEquals(dataLen, n + pos);
     byte[] readData = new byte[n];
     System.arraycopy(result.array(), 0, readData, 0, n);
     byte[] expectedData = new byte[n];
     System.arraycopy(data, pos, expectedData, 0, n);
-    Assert.assertArrayEquals(readData, expectedData);
+    assertArrayEquals(readData, expectedData);
   }
   
   /** Test read fully. */
-  @Test(timeout=120000)
+  @Test
+  @Timeout(value = 120)
   public void testReadFully() throws Exception {
     OutputStream out = getOutputStream(defaultBufferSize);
     writeData(out);
@@ -403,7 +413,7 @@ public abstract class CryptoStreamsTestBase {
       readAll(in, readData, 0, len1);
       byte[] expectedData = new byte[len1];
       System.arraycopy(data, 0, expectedData, 0, len1);
-      Assert.assertArrayEquals(readData, expectedData);
+      assertArrayEquals(readData, expectedData);
 
       // Pos: 1/3 dataLen
       readFullyCheck(in, dataLen / 3);
@@ -413,7 +423,7 @@ public abstract class CryptoStreamsTestBase {
       readAll(in, readData, 0, len1);
       expectedData = new byte[len1];
       System.arraycopy(data, len1, expectedData, 0, len1);
-      Assert.assertArrayEquals(readData, expectedData);
+      assertArrayEquals(readData, expectedData);
 
       // Pos: 1/2 dataLen
       readFullyCheck(in, dataLen / 2);
@@ -423,7 +433,7 @@ public abstract class CryptoStreamsTestBase {
       readAll(in, readData, 0, len1);
       expectedData = new byte[len1];
       System.arraycopy(data, 2 * len1, expectedData, 0, len1);
-      Assert.assertArrayEquals(readData, expectedData);
+      assertArrayEquals(readData, expectedData);
     }
   }
   
@@ -433,18 +443,19 @@ public abstract class CryptoStreamsTestBase {
     
     byte[] expectedData = new byte[dataLen - pos];
     System.arraycopy(data, pos, expectedData, 0, dataLen - pos);
-    Assert.assertArrayEquals(result, expectedData);
+    assertArrayEquals(result, expectedData);
     
     result = new byte[dataLen]; // Exceeds maximum length 
     try {
       ((PositionedReadable) in).readFully(pos, result);
-      Assert.fail("Read fully exceeds maximum length should fail.");
+      fail("Read fully exceeds maximum length should fail.");
     } catch (EOFException e) {
     }
   }
 
   /** Test byte byffer read fully. */
-  @Test(timeout=120000)
+  @Test
+  @Timeout(value = 120)
   public void testByteBufferReadFully() throws Exception {
     OutputStream out = getOutputStream(defaultBufferSize);
     writeData(out);
@@ -456,7 +467,7 @@ public abstract class CryptoStreamsTestBase {
       readAll(in, readData, 0, len1);
       byte[] expectedData = new byte[len1];
       System.arraycopy(data, 0, expectedData, 0, len1);
-      Assert.assertArrayEquals(readData, expectedData);
+      assertArrayEquals(readData, expectedData);
 
       // Pos: 1/3 dataLen
       byteBufferReadFullyCheck(in, dataLen / 3);
@@ -466,7 +477,7 @@ public abstract class CryptoStreamsTestBase {
       readAll(in, readData, 0, len1);
       expectedData = new byte[len1];
       System.arraycopy(data, len1, expectedData, 0, len1);
-      Assert.assertArrayEquals(readData, expectedData);
+      assertArrayEquals(readData, expectedData);
 
       // Pos: 1/2 dataLen
       byteBufferReadFullyCheck(in, dataLen / 2);
@@ -476,7 +487,7 @@ public abstract class CryptoStreamsTestBase {
       readAll(in, readData, 0, len1);
       expectedData = new byte[len1];
       System.arraycopy(data, 2 * len1, expectedData, 0, len1);
-      Assert.assertArrayEquals(readData, expectedData);
+      assertArrayEquals(readData, expectedData);
     }
   }
 
@@ -487,18 +498,19 @@ public abstract class CryptoStreamsTestBase {
 
     byte[] expectedData = new byte[dataLen - pos];
     System.arraycopy(data, pos, expectedData, 0, dataLen - pos);
-    Assert.assertArrayEquals(result.array(), expectedData);
+    assertArrayEquals(result.array(), expectedData);
 
     result = ByteBuffer.allocate(dataLen); // Exceeds maximum length
     try {
       ((ByteBufferPositionedReadable) in).readFully(pos, result);
-      Assert.fail("Read fully exceeds maximum length should fail.");
+      fail("Read fully exceeds maximum length should fail.");
     } catch (EOFException e) {
     }
   }
   
   /** Test seek to different position. */
-  @Test(timeout=120000)
+  @Test
+  @Timeout(value = 120)
   public void testSeek() throws Exception {
     OutputStream out = getOutputStream(defaultBufferSize);
     writeData(out);
@@ -518,21 +530,21 @@ public abstract class CryptoStreamsTestBase {
     // Pos: -3
     try {
       seekCheck(in, -3);
-      Assert.fail("Seek to negative offset should fail.");
+      fail("Seek to negative offset should fail.");
     } catch (EOFException e) {
       GenericTestUtils.assertExceptionContains(
           FSExceptionMessages.NEGATIVE_SEEK, e);
     }
-    Assert.assertEquals(pos, ((Seekable) in).getPos());
+    assertEquals(pos, ((Seekable) in).getPos());
     
     // Pos: dataLen + 3
     try {
       seekCheck(in, dataLen + 3);
-      Assert.fail("Seek after EOF should fail.");
+      fail("Seek after EOF should fail.");
     } catch (IOException e) {
       GenericTestUtils.assertExceptionContains("Cannot seek after EOF", e);
     }
-    Assert.assertEquals(pos, ((Seekable) in).getPos());
+    assertEquals(pos, ((Seekable) in).getPos());
     
     in.close();
   }
@@ -542,16 +554,17 @@ public abstract class CryptoStreamsTestBase {
     ((Seekable) in).seek(pos);
     int n = readAll(in, result, 0, dataLen);
     
-    Assert.assertEquals(dataLen, n + pos);
+    assertEquals(dataLen, n + pos);
     byte[] readData = new byte[n];
     System.arraycopy(result, 0, readData, 0, n);
     byte[] expectedData = new byte[n];
     System.arraycopy(data, pos, expectedData, 0, n);
-    Assert.assertArrayEquals(readData, expectedData);
+    assertArrayEquals(readData, expectedData);
   }
   
   /** Test get position. */
-  @Test(timeout=120000)
+  @Test
+  @Timeout(value = 120)
   public void testGetPos() throws Exception {
     OutputStream out = getOutputStream(defaultBufferSize);
     writeData(out);
@@ -560,14 +573,15 @@ public abstract class CryptoStreamsTestBase {
     InputStream in = getInputStream(defaultBufferSize);
     byte[] result = new byte[dataLen];
     int n1 = readAll(in, result, 0, dataLen / 3);
-    Assert.assertEquals(n1, ((Seekable) in).getPos());
+    assertEquals(n1, ((Seekable) in).getPos());
     
     int n2 = readAll(in, result, n1, dataLen - n1);
-    Assert.assertEquals(n1 + n2, ((Seekable) in).getPos());
+    assertEquals(n1 + n2, ((Seekable) in).getPos());
     in.close();
   }
   
-  @Test(timeout=120000)
+  @Test
+  @Timeout(value = 120)
   public void testAvailable() throws Exception {
     OutputStream out = getOutputStream(defaultBufferSize);
     writeData(out);
@@ -576,15 +590,16 @@ public abstract class CryptoStreamsTestBase {
     InputStream in = getInputStream(defaultBufferSize);
     byte[] result = new byte[dataLen];
     int n1 = readAll(in, result, 0, dataLen / 3);
-    Assert.assertEquals(in.available(), dataLen - n1);
+    assertEquals(in.available(), dataLen - n1);
     
     int n2 = readAll(in, result, n1, dataLen - n1);
-    Assert.assertEquals(in.available(), dataLen - n1 - n2);
+    assertEquals(in.available(), dataLen - n1 - n2);
     in.close();
   }
   
   /** Test skip. */
-  @Test(timeout=120000)
+  @Test
+  @Timeout(value = 120)
   public void testSkip() throws Exception {
     OutputStream out = getOutputStream(defaultBufferSize);
     writeData(out);
@@ -593,21 +608,21 @@ public abstract class CryptoStreamsTestBase {
     InputStream in = getInputStream(defaultBufferSize);
     byte[] result = new byte[dataLen];
     int n1 = readAll(in, result, 0, dataLen / 3);
-    Assert.assertEquals(n1, ((Seekable) in).getPos());
+    assertEquals(n1, ((Seekable) in).getPos());
     
     long skipped = in.skip(dataLen / 3);
     int n2 = readAll(in, result, 0, dataLen);
     
-    Assert.assertEquals(dataLen, n1 + skipped + n2);
+    assertEquals(dataLen, n1 + skipped + n2);
     byte[] readData = new byte[n2];
     System.arraycopy(result, 0, readData, 0, n2);
     byte[] expectedData = new byte[n2];
     System.arraycopy(data, dataLen - n2, expectedData, 0, n2);
-    Assert.assertArrayEquals(readData, expectedData);
+    assertArrayEquals(readData, expectedData);
     
     try {
       skipped = in.skip(-3);
-      Assert.fail("Skip Negative length should fail.");
+      fail("Skip Negative length should fail.");
     } catch (IllegalArgumentException e) {
       GenericTestUtils.assertExceptionContains("Negative skip length", e);
     }
@@ -623,14 +638,14 @@ public abstract class CryptoStreamsTestBase {
       int bufPos) throws Exception {
     buf.position(bufPos);
     int n = ((ByteBufferReadable) in).read(buf);
-    Assert.assertEquals(bufPos + n, buf.position());
+    assertEquals(bufPos + n, buf.position());
     byte[] readData = new byte[n];
     buf.rewind();
     buf.position(bufPos);
     buf.get(readData);
     byte[] expectedData = new byte[n];
     System.arraycopy(data, 0, expectedData, 0, n);
-    Assert.assertArrayEquals(readData, expectedData);
+    assertArrayEquals(readData, expectedData);
   }
 
   private void byteBufferPreadCheck(InputStream in, ByteBuffer buf,
@@ -638,30 +653,31 @@ public abstract class CryptoStreamsTestBase {
     // Test reading from position 0
     buf.position(bufPos);
     int n = ((ByteBufferPositionedReadable) in).read(0, buf);
-    Assert.assertEquals(bufPos + n, buf.position());
+    assertEquals(bufPos + n, buf.position());
     byte[] readData = new byte[n];
     buf.rewind();
     buf.position(bufPos);
     buf.get(readData);
     byte[] expectedData = new byte[n];
     System.arraycopy(data, 0, expectedData, 0, n);
-    Assert.assertArrayEquals(readData, expectedData);
+    assertArrayEquals(readData, expectedData);
 
     // Test reading from half way through the data
     buf.position(bufPos);
     n = ((ByteBufferPositionedReadable) in).read(dataLen / 2, buf);
-    Assert.assertEquals(bufPos + n, buf.position());
+    assertEquals(bufPos + n, buf.position());
     readData = new byte[n];
     buf.rewind();
     buf.position(bufPos);
     buf.get(readData);
     expectedData = new byte[n];
     System.arraycopy(data, dataLen / 2, expectedData, 0, n);
-    Assert.assertArrayEquals(readData, expectedData);
+    assertArrayEquals(readData, expectedData);
   }
   
   /** Test byte buffer read with different buffer size. */
-  @Test(timeout=120000)
+  @Test
+  @Timeout(value = 120)
   public void testByteBufferRead() throws Exception {
     try (OutputStream out = getOutputStream(defaultBufferSize)) {
       writeData(out);
@@ -717,7 +733,8 @@ public abstract class CryptoStreamsTestBase {
   }
 
   /** Test byte buffer pread with different buffer size. */
-  @Test(timeout=120000)
+  @Test
+  @Timeout(value = 120)
   public void testByteBufferPread() throws Exception {
     try (OutputStream out = getOutputStream(defaultBufferSize)) {
       writeData(out);
@@ -763,7 +780,8 @@ public abstract class CryptoStreamsTestBase {
     }
   }
   
-  @Test(timeout=120000)
+  @Test
+  @Timeout(value = 120)
   public void testCombinedOp() throws Exception {
     OutputStream out = getOutputStream(defaultBufferSize);
     writeData(out);
@@ -777,39 +795,39 @@ public abstract class CryptoStreamsTestBase {
     readAll(in, readData, 0, len1);
     byte[] expectedData = new byte[len1];
     System.arraycopy(data, 0, expectedData, 0, len1);
-    Assert.assertArrayEquals(readData, expectedData);
+    assertArrayEquals(readData, expectedData);
     
     long pos = ((Seekable) in).getPos();
-    Assert.assertEquals(len1, pos);
+    assertEquals(len1, pos);
     
     // Seek forward len2
     ((Seekable) in).seek(pos + len2);
     // Skip forward len2
     long n = in.skip(len2);
-    Assert.assertEquals(len2, n);
+    assertEquals(len2, n);
     
     // Pos: 1/4 dataLen
     positionedReadCheck(in , dataLen / 4);
     
     // Pos should be len1 + len2 + len2
     pos = ((Seekable) in).getPos();
-    Assert.assertEquals(len1 + len2 + len2, pos);
+    assertEquals(len1 + len2 + len2, pos);
     
     // Read forward len1
     ByteBuffer buf = ByteBuffer.allocate(len1);
     int nRead = ((ByteBufferReadable) in).read(buf);
-    Assert.assertEquals(nRead, buf.position());
+    assertEquals(nRead, buf.position());
     readData = new byte[nRead];
     buf.rewind();
     buf.get(readData);
     expectedData = new byte[nRead];
     System.arraycopy(data, (int)pos, expectedData, 0, nRead);
-    Assert.assertArrayEquals(readData, expectedData);
+    assertArrayEquals(readData, expectedData);
     
     long lastPos = pos;
     // Pos should be lastPos + nRead
     pos = ((Seekable) in).getPos();
-    Assert.assertEquals(lastPos + nRead, pos);
+    assertEquals(lastPos + nRead, pos);
     
     // Pos: 1/3 dataLen
     positionedReadCheck(in , dataLen / 3);
@@ -819,28 +837,28 @@ public abstract class CryptoStreamsTestBase {
     readAll(in, readData, 0, len1);
     expectedData = new byte[len1];
     System.arraycopy(data, (int)pos, expectedData, 0, len1);
-    Assert.assertArrayEquals(readData, expectedData);
+    assertArrayEquals(readData, expectedData);
     
     lastPos = pos;
     // Pos should be lastPos + len1
     pos = ((Seekable) in).getPos();
-    Assert.assertEquals(lastPos + len1, pos);
+    assertEquals(lastPos + len1, pos);
     
     // Read forward len1
     buf = ByteBuffer.allocate(len1);
     nRead = ((ByteBufferReadable) in).read(buf);
-    Assert.assertEquals(nRead, buf.position());
+    assertEquals(nRead, buf.position());
     readData = new byte[nRead];
     buf.rewind();
     buf.get(readData);
     expectedData = new byte[nRead];
     System.arraycopy(data, (int)pos, expectedData, 0, nRead);
-    Assert.assertArrayEquals(readData, expectedData);
+    assertArrayEquals(readData, expectedData);
     
     lastPos = pos;
     // Pos should be lastPos + nRead
     pos = ((Seekable) in).getPos();
-    Assert.assertEquals(lastPos + nRead, pos);
+    assertEquals(lastPos + nRead, pos);
     
     // ByteBuffer read after EOF
     ((Seekable) in).seek(dataLen);
@@ -851,7 +869,8 @@ public abstract class CryptoStreamsTestBase {
     in.close();
   }
   
-  @Test(timeout=120000)
+  @Test
+  @Timeout(value = 120)
   public void testSeekToNewSource() throws Exception {
     OutputStream out = getOutputStream(defaultBufferSize);
     writeData(out);
@@ -874,7 +893,7 @@ public abstract class CryptoStreamsTestBase {
     // Pos: -3
     try {
       seekToNewSourceCheck(in, -3);
-      Assert.fail("Seek to negative offset should fail.");
+      fail("Seek to negative offset should fail.");
     } catch (IllegalArgumentException e) {
       GenericTestUtils.assertExceptionContains("Cannot seek to negative " +
           "offset", e);
@@ -883,7 +902,7 @@ public abstract class CryptoStreamsTestBase {
     // Pos: dataLen + 3
     try {
       seekToNewSourceCheck(in, dataLen + 3);
-      Assert.fail("Seek after EOF should fail.");
+      fail("Seek after EOF should fail.");
     } catch (IOException e) {
       GenericTestUtils.assertExceptionContains("Attempted to read past " +
           "end of file", e);
@@ -898,12 +917,12 @@ public abstract class CryptoStreamsTestBase {
     ((Seekable) in).seekToNewSource(targetPos);
     int n = readAll(in, result, 0, dataLen);
     
-    Assert.assertEquals(dataLen, n + targetPos);
+    assertEquals(dataLen, n + targetPos);
     byte[] readData = new byte[n];
     System.arraycopy(result, 0, readData, 0, n);
     byte[] expectedData = new byte[n];
     System.arraycopy(data, targetPos, expectedData, 0, n);
-    Assert.assertArrayEquals(readData, expectedData);
+    assertArrayEquals(readData, expectedData);
   }
   
   private ByteBufferPool getBufferPool() {
@@ -919,7 +938,8 @@ public abstract class CryptoStreamsTestBase {
     };
   }
   
-  @Test(timeout=120000)
+  @Test
+  @Timeout(value = 120)
   public void testHasEnhancedByteBufferAccess() throws Exception {
     OutputStream out = getOutputStream(defaultBufferSize);
     writeData(out);
@@ -934,7 +954,7 @@ public abstract class CryptoStreamsTestBase {
     buffer.get(readData);
     byte[] expectedData = new byte[n1];
     System.arraycopy(data, 0, expectedData, 0, n1);
-    Assert.assertArrayEquals(readData, expectedData);
+    assertArrayEquals(readData, expectedData);
     ((HasEnhancedByteBufferAccess) in).releaseBuffer(buffer);
     
     // Read len1 bytes
@@ -942,7 +962,7 @@ public abstract class CryptoStreamsTestBase {
     readAll(in, readData, 0, len1);
     expectedData = new byte[len1];
     System.arraycopy(data, n1, expectedData, 0, len1);
-    Assert.assertArrayEquals(readData, expectedData);
+    assertArrayEquals(readData, expectedData);
     
     // ByteBuffer size is len1
     buffer = ((HasEnhancedByteBufferAccess) in).read(
@@ -952,14 +972,15 @@ public abstract class CryptoStreamsTestBase {
     buffer.get(readData);
     expectedData = new byte[n2];
     System.arraycopy(data, n1 + len1, expectedData, 0, n2);
-    Assert.assertArrayEquals(readData, expectedData);
+    assertArrayEquals(readData, expectedData);
     ((HasEnhancedByteBufferAccess) in).releaseBuffer(buffer);
     
     in.close();
   }
 
   /** Test unbuffer. */
-  @Test(timeout=120000)
+  @Test
+  @Timeout(value = 120)
   public void testUnbuffer() throws Exception {
     OutputStream out = getOutputStream(smallBufferSize);
     writeData(out);

+ 39 - 33
hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/crypto/TestCryptoCodec.java

@@ -22,9 +22,11 @@ import static org.apache.hadoop.fs.CommonConfigurationKeysPublic.
 import static org.apache.hadoop.fs.CommonConfigurationKeysPublic.
     HADOOP_SECURITY_CRYPTO_CODEC_CLASSES_SM4_CTR_NOPADDING_KEY;
 import static org.apache.hadoop.fs.CommonConfigurationKeysPublic.
-        HADOOP_SECURITY_CRYPTO_JCE_PROVIDER_KEY;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
+    HADOOP_SECURITY_CRYPTO_JCE_PROVIDER_KEY;
+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 static org.junit.jupiter.api.Assumptions.assumeTrue;
 
 import java.io.BufferedInputStream;
 import java.io.DataInputStream;
@@ -44,10 +46,9 @@ import org.apache.hadoop.io.RandomDatum;
 import org.apache.hadoop.test.GenericTestUtils;
 import org.apache.hadoop.util.NativeCodeLoader;
 import org.apache.hadoop.util.ReflectionUtils;
-import org.junit.Assert;
-import org.junit.Assume;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.Timeout;
 
 import org.bouncycastle.jce.provider.BouncyCastleProvider;
 import org.apache.hadoop.thirdparty.com.google.common.primitives.Longs;
@@ -73,21 +74,22 @@ public class TestCryptoCodec {
   private final String opensslSm4CodecClass =
       "org.apache.hadoop.crypto.OpensslSm4CtrCryptoCodec";
   
-  @Before
+  @BeforeEach
   public void setUp() throws IOException {
     Random random = new SecureRandom();
     random.nextBytes(key);
     random.nextBytes(iv);
   }
 
-  @Test(timeout=120000)
+  @Test
+  @Timeout(value = 120)
   public void testJceAesCtrCryptoCodec() throws Exception {
     GenericTestUtils.assumeInNativeProfile();
     if (!NativeCodeLoader.buildSupportsOpenssl()) {
       LOG.warn("Skipping test since openSSL library not loaded");
-      Assume.assumeTrue(false);
+      assumeTrue(false);
     }
-    Assert.assertEquals(null, OpensslCipher.getLoadingFailureReason());
+    assertEquals(null, OpensslCipher.getLoadingFailureReason());
     cryptoCodecTest(conf, seed, 0,
         jceAesCodecClass, jceAesCodecClass, iv);
     cryptoCodecTest(conf, seed, count,
@@ -104,7 +106,8 @@ public class TestCryptoCodec {
         jceAesCodecClass, opensslAesCodecClass, iv);
   }
 
-  @Test(timeout=120000)
+  @Test
+  @Timeout(value = 120)
   public void testJceSm4CtrCryptoCodec() throws Exception {
     conf.set(HADOOP_SECURITY_CRYPTO_CIPHER_SUITE_KEY, "SM4/CTR/NoPadding");
     conf.set(HADOOP_SECURITY_CRYPTO_CODEC_CLASSES_SM4_CTR_NOPADDING_KEY,
@@ -123,14 +126,15 @@ public class TestCryptoCodec {
         jceSm4CodecClass, jceSm4CodecClass, iv);
   }
   
-  @Test(timeout=120000)
+  @Test
+  @Timeout(value = 120)
   public void testOpensslAesCtrCryptoCodec() throws Exception {
     GenericTestUtils.assumeInNativeProfile();
     if (!NativeCodeLoader.buildSupportsOpenssl()) {
       LOG.warn("Skipping test since openSSL library not loaded");
-      Assume.assumeTrue(false);
+      assumeTrue(false);
     }
-    Assert.assertEquals(null, OpensslCipher.getLoadingFailureReason());
+    assertEquals(null, OpensslCipher.getLoadingFailureReason());
     cryptoCodecTest(conf, seed, 0,
         opensslAesCodecClass, opensslAesCodecClass, iv);
     cryptoCodecTest(conf, seed, count,
@@ -147,17 +151,18 @@ public class TestCryptoCodec {
         opensslAesCodecClass, jceAesCodecClass, iv);
   }
 
-  @Test(timeout=120000)
+  @Test
+  @Timeout(value = 120)
   public void testOpensslSm4CtrCryptoCodec() throws Exception {
     GenericTestUtils.assumeInNativeProfile();
     if (!NativeCodeLoader.buildSupportsOpenssl()) {
       LOG.warn("Skipping test since openSSL library not loaded");
-      Assume.assumeTrue(false);
+      assumeTrue(false);
     }
-    Assume.assumeTrue(OpensslCipher.isSupported(CipherSuite.SM4_CTR_NOPADDING));
+    assumeTrue(OpensslCipher.isSupported(CipherSuite.SM4_CTR_NOPADDING));
     conf.set(HADOOP_SECURITY_CRYPTO_JCE_PROVIDER_KEY,
-            BouncyCastleProvider.PROVIDER_NAME);
-    Assert.assertEquals(null, OpensslCipher.getLoadingFailureReason());
+        BouncyCastleProvider.PROVIDER_NAME);
+    assertEquals(null, OpensslCipher.getLoadingFailureReason());
     cryptoCodecTest(conf, seed, 0,
         opensslSm4CodecClass, opensslSm4CodecClass, iv);
     cryptoCodecTest(conf, seed, count,
@@ -243,17 +248,17 @@ public class TestCryptoCodec {
       RandomDatum v2 = new RandomDatum();
       k2.readFields(dataIn);
       v2.readFields(dataIn);
-      assertTrue("original and encrypted-then-decrypted-output not equal",
-                 k1.equals(k2) && v1.equals(v2));
+      assertTrue(k1.equals(k2) && v1.equals(v2),
+          "original and encrypted-then-decrypted-output not equal");
       
       // original and encrypted-then-decrypted-output have the same hashCode
       Map<RandomDatum, String> m = new HashMap<RandomDatum, String>();
       m.put(k1, k1.toString());
       m.put(v1, v1.toString());
       String result = m.get(k2);
-      assertEquals("k1 and k2 hashcode not equal", result, k1.toString());
+      assertEquals(result, k1.toString(), "k1 and k2 hashcode not equal");
       result = m.get(v2);
-      assertEquals("v1 and v2 hashcode not equal", result, v1.toString());
+      assertEquals(result, v1.toString(), "v1 and v2 hashcode not equal");
     }
 
     // Decrypt data byte-at-a-time
@@ -268,8 +273,8 @@ public class TestCryptoCodec {
     int expected;
     do {
       expected = originalIn.read();
-      assertEquals("Decrypted stream read by byte does not match",
-        expected, in.read());
+      assertEquals(expected, in.read(),
+          "Decrypted stream read by byte does not match");
     } while (expected != -1);
     
     // Seek to a certain position and decrypt
@@ -287,8 +292,8 @@ public class TestCryptoCodec {
     originalInput.seek(seekPos);
     do {
       expected = originalInput.read();
-      assertEquals("Decrypted stream read by byte does not match",
-        expected, in.read());
+      assertEquals(expected, in.read(),
+          "Decrypted stream read by byte does not match");
     } while (expected != -1);
 
     LOG.info("SUCCESS! Completed checking " + count + " records");
@@ -313,15 +318,16 @@ public class TestCryptoCodec {
     codec.generateSecureRandom(rand);
     codec.generateSecureRandom(rand1);
     
-    Assert.assertEquals(len, rand.length);
-    Assert.assertEquals(len, rand1.length);
-    Assert.assertFalse(Arrays.equals(rand, rand1));
+    assertEquals(len, rand.length);
+    assertEquals(len, rand1.length);
+    assertFalse(Arrays.equals(rand, rand1));
   }
   
   /**
    * Regression test for IV calculation, see HADOOP-11343
    */
-  @Test(timeout=120000)
+  @Test
+  @Timeout(value = 120)
   public void testCalculateIV() throws Exception {
     JceAesCtrCryptoCodec codec = new JceAesCtrCryptoCodec();
     codec.setConf(conf);
@@ -369,7 +375,7 @@ public class TestCryptoCodec {
     BigInteger iv = new BigInteger(1, IV);
     BigInteger ref = calculateRef(initIV, counter);
 
-    assertTrue("Calculated IV don't match with the reference", iv.equals(ref));
+    assertEquals(iv, ref, "Calculated IV don't match with the reference");
   }
 
   private static BigInteger calculateRef(byte[] initIV, long counter) {

+ 8 - 4
hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/crypto/TestCryptoOutputStreamClosing.java

@@ -22,10 +22,14 @@ import java.io.OutputStream;
 
 import org.apache.hadoop.conf.Configuration;
 
-import org.junit.BeforeClass;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
 import static org.apache.hadoop.test.LambdaTestUtils.intercept;
-import static org.mockito.Mockito.*;
+import static org.mockito.Mockito.doThrow;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.verify;
 
 /**
  * To test proper closing of underlying stream of CryptoOutputStream.
@@ -33,7 +37,7 @@ import static org.mockito.Mockito.*;
 public class TestCryptoOutputStreamClosing {
   private static CryptoCodec codec;
 
-  @BeforeClass
+  @BeforeAll
   public static void init() throws Exception {
     codec = CryptoCodec.getInstance(new Configuration());
   }

+ 8 - 6
hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/crypto/TestCryptoStreams.java

@@ -41,9 +41,10 @@ import org.apache.hadoop.fs.Syncable;
 import org.apache.hadoop.io.ByteBufferPool;
 import org.apache.hadoop.io.DataInputBuffer;
 import org.apache.hadoop.io.DataOutputBuffer;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.Timeout;
 
 import static org.apache.hadoop.fs.contract.ContractTestUtils.assertCapabilities;
 
@@ -56,13 +57,13 @@ public class TestCryptoStreams extends CryptoStreamsTestBase {
   private byte[] buf;
   private int bufLen;
   
-  @BeforeClass
+  @BeforeAll
   public static void init() throws Exception {
     Configuration conf = new Configuration();
     codec = CryptoCodec.getInstance(conf);
   }
   
-  @AfterClass
+  @AfterAll
   public static void shutdown() throws Exception {
   }
   
@@ -466,7 +467,8 @@ public class TestCryptoStreams extends CryptoStreamsTestBase {
    * This tests {@link StreamCapabilities#hasCapability(String)} for the
    * the underlying streams.
    */
-  @Test(timeout = 120000)
+  @Test
+  @Timeout(value = 120)
   public void testHasCapability() throws Exception {
     // verify hasCapability returns what FakeOutputStream is set up for
     CryptoOutputStream cos =

+ 37 - 28
hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/crypto/TestCryptoStreamsForLocalFS.java

@@ -17,7 +17,7 @@
  */
 package org.apache.hadoop.crypto;
 
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertTrue;
 
 import java.io.File;
 import java.io.IOException;
@@ -30,12 +30,13 @@ import org.apache.hadoop.fs.FileUtil;
 import org.apache.hadoop.fs.LocalFileSystem;
 import org.apache.hadoop.fs.Path;
 import org.apache.hadoop.test.GenericTestUtils;
-import org.junit.After;
-import org.junit.AfterClass;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Ignore;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.Timeout;
 
 public class TestCryptoStreamsForLocalFS extends CryptoStreamsTestBase {
   private static final String TEST_ROOT_DIR =
@@ -45,7 +46,7 @@ public class TestCryptoStreamsForLocalFS extends CryptoStreamsTestBase {
   private final Path file = new Path(TEST_ROOT_DIR, "test-file");
   private static LocalFileSystem fileSys;
   
-  @BeforeClass
+  @BeforeAll
   public static void init() throws Exception {
     Configuration conf = new Configuration(false);
     conf.set("fs.file.impl", LocalFileSystem.class.getName());
@@ -53,18 +54,18 @@ public class TestCryptoStreamsForLocalFS extends CryptoStreamsTestBase {
     codec = CryptoCodec.getInstance(conf);
   }
   
-  @AfterClass
+  @AfterAll
   public static void shutdown() throws Exception {
   }
   
-  @Before
+  @BeforeEach
   @Override
   public void setUp() throws IOException {
     fileSys.delete(new Path(TEST_ROOT_DIR), true);
     super.setUp();
   }
   
-  @After
+  @AfterEach
   public void cleanUp() throws IOException {
     FileUtil.setWritable(base, true);
     FileUtil.fullyDelete(base);
@@ -85,49 +86,57 @@ public class TestCryptoStreamsForLocalFS extends CryptoStreamsTestBase {
         key, iv);
   }
   
-  @Ignore("ChecksumFSInputChecker doesn't support ByteBuffer read")
+  @Disabled("ChecksumFSInputChecker doesn't support ByteBuffer read")
   @Override
-  @Test(timeout=10000)
+  @Test
+  @Timeout(value = 10)
   public void testByteBufferRead() throws Exception {}
 
-  @Ignore("Wrapped stream doesn't support ByteBufferPositionedReadable")
+  @Disabled("Wrapped stream doesn't support ByteBufferPositionedReadable")
   @Override
-  @Test(timeout=10000)
+  @Test
+  @Timeout(value = 10)
   public void testPositionedReadWithByteBuffer() throws IOException {}
 
-  @Ignore("Wrapped stream doesn't support ByteBufferPositionedReadable")
+  @Disabled("Wrapped stream doesn't support ByteBufferPositionedReadable")
   @Override
-  @Test(timeout=10000)
+  @Test
+  @Timeout(value = 10)
   public void testByteBufferReadFully() throws Exception {}
   
-  @Ignore("ChecksumFSOutputSummer doesn't support Syncable")
+  @Disabled("ChecksumFSOutputSummer doesn't support Syncable")
   @Override
-  @Test(timeout=10000)
+  @Test
+  @Timeout(value = 10)
   public void testSyncable() throws IOException {}
 
-  @Ignore("Wrapped stream doesn't support ByteBufferPositionedReadable")
+  @Disabled("Wrapped stream doesn't support ByteBufferPositionedReadable")
   @Override
-  @Test(timeout=10000)
+  @Test
+  @Timeout(value = 10)
   public void testByteBufferPread() throws IOException {}
   
-  @Ignore("ChecksumFSInputChecker doesn't support ByteBuffer read")
+  @Disabled("ChecksumFSInputChecker doesn't support ByteBuffer read")
   @Override
-  @Test(timeout=10000)
+  @Test
+  @Timeout(value = 10)
   public void testCombinedOp() throws Exception {}
   
-  @Ignore("ChecksumFSInputChecker doesn't support enhanced ByteBuffer access")
+  @Disabled("ChecksumFSInputChecker doesn't support enhanced ByteBuffer access")
   @Override
-  @Test(timeout=10000)
+  @Test
+  @Timeout(value = 10)
   public void testHasEnhancedByteBufferAccess() throws Exception {
   }
   
-  @Ignore("ChecksumFSInputChecker doesn't support seekToNewSource")
+  @Disabled("ChecksumFSInputChecker doesn't support seekToNewSource")
   @Override
-  @Test(timeout=10000)
+  @Test
+  @Timeout(value = 10)
   public void testSeekToNewSource() throws Exception {
   }
 
-  @Ignore("Local file input stream does not support unbuffer")
+  @Disabled("Local file input stream does not support unbuffer")
   @Override
   @Test
   public void testUnbuffer() throws Exception {}

+ 41 - 29
hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/crypto/TestCryptoStreamsNormal.java

@@ -24,10 +24,11 @@ import java.io.InputStream;
 import java.io.OutputStream;
 
 import org.apache.hadoop.conf.Configuration;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.Ignore;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.Timeout;
 
 /**
  * Test crypto streams using normal stream which does not support the 
@@ -45,13 +46,13 @@ public class TestCryptoStreamsNormal extends CryptoStreamsTestBase {
   private byte[] buffer;
   private int bufferLen;
   
-  @BeforeClass
+  @BeforeAll
   public static void init() throws Exception {
     Configuration conf = new Configuration();
     codec = CryptoCodec.getInstance(conf);
   }
   
-  @AfterClass
+  @AfterAll
   public static void shutdown() throws Exception {
   }
 
@@ -81,62 +82,73 @@ public class TestCryptoStreamsNormal extends CryptoStreamsTestBase {
         key, iv);
   }
   
-  @Ignore("Wrapped stream doesn't support Syncable")
+  @Disabled("Wrapped stream doesn't support Syncable")
   @Override
-  @Test(timeout=10000)
+  @Test
+  @Timeout(value = 10)
   public void testSyncable() throws IOException {}
   
-  @Ignore("Wrapped stream doesn't support PositionedRead")
+  @Disabled("Wrapped stream doesn't support PositionedRead")
   @Override
-  @Test(timeout=10000)
+  @Test
+  @Timeout(value = 10)
   public void testPositionedRead() throws IOException {}
 
-  @Ignore("Wrapped stream doesn't support ByteBufferPositionedReadable")
+  @Disabled("Wrapped stream doesn't support ByteBufferPositionedReadable")
   @Override
-  @Test(timeout=10000)
+  @Test
+  @Timeout(value = 10)
   public void testPositionedReadWithByteBuffer() throws IOException {}
 
-  @Ignore("Wrapped stream doesn't support ByteBufferPositionedReadable")
+  @Disabled("Wrapped stream doesn't support ByteBufferPositionedReadable")
   @Override
-  @Test(timeout=10000)
+  @Test
+  @Timeout(value = 10)
   public void testByteBufferReadFully() throws Exception {}
 
-  @Ignore("Wrapped stream doesn't support ReadFully")
+  @Disabled("Wrapped stream doesn't support ReadFully")
   @Override
-  @Test(timeout=10000)
+  @Test
+  @Timeout(value = 10)
   public void testReadFully() throws IOException {}
   
-  @Ignore("Wrapped stream doesn't support Seek")
+  @Disabled("Wrapped stream doesn't support Seek")
   @Override
-  @Test(timeout=10000)
+  @Test
+  @Timeout(value = 10)
   public void testSeek() throws IOException {}
   
-  @Ignore("Wrapped stream doesn't support ByteBufferRead")
+  @Disabled("Wrapped stream doesn't support ByteBufferRead")
   @Override
-  @Test(timeout=10000)
+  @Test
+  @Timeout(value = 10)
   public void testByteBufferRead() throws IOException {}
 
-  @Ignore("Wrapped stream doesn't support ByteBufferPositionedReadable")
+  @Disabled("Wrapped stream doesn't support ByteBufferPositionedReadable")
   @Override
-  @Test(timeout=10000)
+  @Test
+  @Timeout(value = 10)
   public void testByteBufferPread() throws IOException {}
   
-  @Ignore("Wrapped stream doesn't support ByteBufferRead, Seek")
+  @Disabled("Wrapped stream doesn't support ByteBufferRead, Seek")
   @Override
-  @Test(timeout=10000)
+  @Test
+  @Timeout(value = 10)
   public void testCombinedOp() throws IOException {}
   
-  @Ignore("Wrapped stream doesn't support SeekToNewSource")
+  @Disabled("Wrapped stream doesn't support SeekToNewSource")
   @Override
-  @Test(timeout=10000)
+  @Test
+  @Timeout(value = 10)
   public void testSeekToNewSource() throws IOException {}
   
-  @Ignore("Wrapped stream doesn't support HasEnhancedByteBufferAccess")
+  @Disabled("Wrapped stream doesn't support HasEnhancedByteBufferAccess")
   @Override
-  @Test(timeout=10000)
+  @Test
+  @Timeout(value = 10)
   public void testHasEnhancedByteBufferAccess() throws IOException {}
 
-  @Ignore("ByteArrayInputStream does not support unbuffer")
+  @Disabled("ByteArrayInputStream does not support unbuffer")
   @Override
   @Test
   public void testUnbuffer() throws Exception {}

+ 2 - 2
hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/crypto/TestCryptoStreamsWithJceAesCtrCryptoCodec.java

@@ -19,14 +19,14 @@ package org.apache.hadoop.crypto;
 
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.fs.CommonConfigurationKeysPublic;
-import org.junit.BeforeClass;
+import org.junit.jupiter.api.BeforeAll;
 
 import static org.assertj.core.api.Assertions.assertThat;
 
 public class TestCryptoStreamsWithJceAesCtrCryptoCodec extends 
     TestCryptoStreams {
 
-  @BeforeClass
+  @BeforeAll
   public static void init() {
     Configuration conf = new Configuration();
     conf.set(

+ 2 - 2
hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/crypto/TestCryptoStreamsWithJceSm4CtrCryptoCodec.java

@@ -20,7 +20,7 @@ package org.apache.hadoop.crypto;
 import org.bouncycastle.jce.provider.BouncyCastleProvider;
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.fs.CommonConfigurationKeysPublic;
-import org.junit.BeforeClass;
+import org.junit.jupiter.api.BeforeAll;
 
 import static org.apache.hadoop.fs.CommonConfigurationKeysPublic.
     HADOOP_SECURITY_CRYPTO_CIPHER_SUITE_KEY;
@@ -31,7 +31,7 @@ import static org.apache.hadoop.fs.CommonConfigurationKeysPublic.HADOOP_SECURITY
 public class TestCryptoStreamsWithJceSm4CtrCryptoCodec extends
     TestCryptoStreams {
 
-  @BeforeClass
+  @BeforeAll
   public static void init() throws Exception {
     Configuration conf = new Configuration();
     conf.set(HADOOP_SECURITY_CRYPTO_CIPHER_SUITE_KEY, "SM4/CTR/NoPadding");

+ 11 - 12
hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/crypto/TestCryptoStreamsWithOpensslAesCtrCryptoCodec.java

@@ -21,13 +21,13 @@ import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.crypto.random.OsSecureRandom;
 import org.apache.hadoop.fs.CommonConfigurationKeysPublic;
 import org.apache.hadoop.test.GenericTestUtils;
-import org.junit.BeforeClass;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
+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.apache.hadoop.fs.CommonConfigurationKeysPublic.HADOOP_SECURITY_CRYPTO_CIPHER_SUITE_KEY;
 import static org.apache.hadoop.fs.CommonConfigurationKeysPublic.HADOOP_SECURITY_CRYPTO_CODEC_CLASSES_AES_CTR_NOPADDING_KEY;
@@ -35,16 +35,16 @@ import static org.apache.hadoop.fs.CommonConfigurationKeysPublic.HADOOP_SECURITY
 public class TestCryptoStreamsWithOpensslAesCtrCryptoCodec 
     extends TestCryptoStreams {
   
-  @BeforeClass
+  @BeforeAll
   public static void init() throws Exception {
     GenericTestUtils.assumeInNativeProfile();
     Configuration conf = new Configuration();
     conf.set(HADOOP_SECURITY_CRYPTO_CODEC_CLASSES_AES_CTR_NOPADDING_KEY,
         OpensslAesCtrCryptoCodec.class.getName());
     codec = CryptoCodec.getInstance(conf);
-    assertNotNull("Unable to instantiate codec " +
+    assertNotNull(codec, "Unable to instantiate codec " +
         OpensslAesCtrCryptoCodec.class.getName() + ", is the required "
-        + "version of OpenSSL installed?", codec);
+        + "version of OpenSSL installed?");
     assertEquals(OpensslAesCtrCryptoCodec.class.getCanonicalName(),
         codec.getClass().getCanonicalName());
   }
@@ -61,9 +61,8 @@ public class TestCryptoStreamsWithOpensslAesCtrCryptoCodec
         OsSecureRandom.class.getName());
     CryptoCodec codecWithRandom = CryptoCodec.getInstance(conf);
     assertNotNull(
-        "Unable to instantiate codec " + OpensslAesCtrCryptoCodec.class
-            .getName() + ", is the required " + "version of OpenSSL installed?",
-        codecWithRandom);
+        codecWithRandom, "Unable to instantiate codec " + OpensslAesCtrCryptoCodec.class
+        .getName() + ", is the required " + "version of OpenSSL installed?");
     OsSecureRandom random = (OsSecureRandom)
             ((OpensslAesCtrCryptoCodec) codecWithRandom).getRandom();
     // trigger the OsSecureRandom to create an internal FileInputStream

+ 16 - 16
hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/crypto/TestCryptoStreamsWithOpensslSm4CtrCryptoCodec.java

@@ -21,14 +21,14 @@ import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.crypto.random.OsSecureRandom;
 import org.apache.hadoop.fs.CommonConfigurationKeysPublic;
 import org.apache.hadoop.test.GenericTestUtils;
-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 static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
+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.Assumptions.assumeTrue;
 
 import static org.apache.hadoop.fs.CommonConfigurationKeysPublic.
     HADOOP_SECURITY_CRYPTO_CIPHER_SUITE_KEY;
@@ -38,20 +38,20 @@ import static org.apache.hadoop.fs.CommonConfigurationKeysPublic.
 public class TestCryptoStreamsWithOpensslSm4CtrCryptoCodec
     extends TestCryptoStreams {
 
-  @BeforeClass
+  @BeforeAll
   public static void init() throws Exception {
     GenericTestUtils.assumeInNativeProfile();
-    Assume.assumeTrue(OpensslCipher.isSupported(CipherSuite.SM4_CTR_NOPADDING));
+    assumeTrue(OpensslCipher.isSupported(CipherSuite.SM4_CTR_NOPADDING));
     Configuration conf = new Configuration();
     conf.set(HADOOP_SECURITY_CRYPTO_CIPHER_SUITE_KEY, "SM4/CTR/NoPadding");
     conf.set(HADOOP_SECURITY_CRYPTO_CODEC_CLASSES_SM4_CTR_NOPADDING_KEY,
             OpensslSm4CtrCryptoCodec.class.getName());
     codec = CryptoCodec.getInstance(conf);
-    assertNotNull("Unable to instantiate codec " +
-            OpensslSm4CtrCryptoCodec.class.getName() + ", is the required "
-            + "version of OpenSSL installed?", codec);
+    assertNotNull(codec, "Unable to instantiate codec " +
+        OpensslSm4CtrCryptoCodec.class.getName() + ", is the required " +
+        "version of OpenSSL installed?");
     assertEquals(OpensslSm4CtrCryptoCodec.class.getCanonicalName(),
-            codec.getClass().getCanonicalName());
+        codec.getClass().getCanonicalName());
   }
 
   @Test
@@ -66,9 +66,9 @@ public class TestCryptoStreamsWithOpensslSm4CtrCryptoCodec
                     HADOOP_SECURITY_SECURE_RANDOM_IMPL_KEY,
             OsSecureRandom.class.getName());
     CryptoCodec codecWithRandom = CryptoCodec.getInstance(conf);
-    assertNotNull("Unable to instantiate codec " +
-            OpensslSm4CtrCryptoCodec.class.getName() + ", is the required "
-            + "version of OpenSSL installed?", codecWithRandom);
+    assertNotNull(codecWithRandom, "Unable to instantiate codec " +
+        OpensslSm4CtrCryptoCodec.class.getName() + ", is the required " +
+        "version of OpenSSL installed?");
     OsSecureRandom random = (OsSecureRandom)
             ((OpensslSm4CtrCryptoCodec) codecWithRandom).getRandom();
     // trigger the OsSecureRandom to create an internal FileInputStream

+ 21 - 15
hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/crypto/TestCryptoUtils.java

@@ -19,15 +19,19 @@ package org.apache.hadoop.crypto;
 
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.test.GenericTestUtils;
-import org.assertj.core.api.Assertions;
 import org.bouncycastle.jce.provider.BouncyCastleProvider;
-import org.junit.Assert;
-import org.junit.Test;
+
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.Timeout;
 import org.slf4j.event.Level;
 
 import java.security.Provider;
 import java.security.Security;
 
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
 import static org.apache.hadoop.fs.CommonConfigurationKeysPublic.HADOOP_SECURITY_CRYPTO_JCE_PROVIDER_AUTO_ADD_DEFAULT;
 import static org.apache.hadoop.fs.CommonConfigurationKeysPublic.HADOOP_SECURITY_CRYPTO_JCE_PROVIDER_AUTO_ADD_KEY;
 import static org.apache.hadoop.fs.CommonConfigurationKeysPublic.HADOOP_SECURITY_CRYPTO_JCE_PROVIDER_KEY;
@@ -38,23 +42,25 @@ public class TestCryptoUtils {
     GenericTestUtils.setLogLevel(CryptoUtils.LOG, Level.TRACE);
   }
 
-  @Test(timeout = 1_000)
+  @Test
+  @Timeout(value = 1)
   public void testProviderName() {
-    Assert.assertEquals(CryptoUtils.BOUNCY_CASTLE_PROVIDER_NAME, BouncyCastleProvider.PROVIDER_NAME);
+    assertEquals(CryptoUtils.BOUNCY_CASTLE_PROVIDER_NAME, BouncyCastleProvider.PROVIDER_NAME);
   }
 
   static void assertRemoveProvider() {
     Security.removeProvider(BouncyCastleProvider.PROVIDER_NAME);
-    Assert.assertNull(Security.getProvider(BouncyCastleProvider.PROVIDER_NAME));
+    assertNull(Security.getProvider(BouncyCastleProvider.PROVIDER_NAME));
   }
 
   static void assertSetProvider(Configuration conf) {
     conf.set(HADOOP_SECURITY_CRYPTO_JCE_PROVIDER_KEY, CryptoUtils.BOUNCY_CASTLE_PROVIDER_NAME);
     final String providerFromConf = CryptoUtils.getJceProvider(conf);
-    Assert.assertEquals(CryptoUtils.BOUNCY_CASTLE_PROVIDER_NAME, providerFromConf);
+    assertEquals(CryptoUtils.BOUNCY_CASTLE_PROVIDER_NAME, providerFromConf);
   }
 
-  @Test(timeout = 5_000)
+  @Test
+  @Timeout(value = 5)
   public void testAutoAddDisabled() {
     assertRemoveProvider();
 
@@ -63,26 +69,26 @@ public class TestCryptoUtils {
 
     assertSetProvider(conf);
 
-    Assert.assertNull(Security.getProvider(BouncyCastleProvider.PROVIDER_NAME));
+    assertNull(Security.getProvider(BouncyCastleProvider.PROVIDER_NAME));
   }
 
-  @Test(timeout = 5_000)
+  @Test
+  @Timeout(value = 5)
   public void testAutoAddEnabled() {
     assertRemoveProvider();
 
     final Configuration conf = new Configuration();
-    Assertions.assertThat(conf.get(HADOOP_SECURITY_CRYPTO_JCE_PROVIDER_AUTO_ADD_KEY))
+    assertThat(conf.get(HADOOP_SECURITY_CRYPTO_JCE_PROVIDER_AUTO_ADD_KEY))
         .describedAs("conf: " + HADOOP_SECURITY_CRYPTO_JCE_PROVIDER_AUTO_ADD_KEY)
         .isEqualToIgnoringCase("true");
-    Assert.assertTrue(HADOOP_SECURITY_CRYPTO_JCE_PROVIDER_AUTO_ADD_DEFAULT);
+    assertTrue(HADOOP_SECURITY_CRYPTO_JCE_PROVIDER_AUTO_ADD_DEFAULT);
 
     conf.set(HADOOP_SECURITY_CRYPTO_JCE_PROVIDER_KEY, CryptoUtils.BOUNCY_CASTLE_PROVIDER_NAME);
     final String providerFromConf = CryptoUtils.getJceProvider(conf);
-    Assert.assertEquals(CryptoUtils.BOUNCY_CASTLE_PROVIDER_NAME, providerFromConf);
+    assertEquals(CryptoUtils.BOUNCY_CASTLE_PROVIDER_NAME, providerFromConf);
 
     final Provider provider = Security.getProvider(BouncyCastleProvider.PROVIDER_NAME);
-    Assertions.assertThat(provider)
-        .isInstanceOf(BouncyCastleProvider.class);
+    assertThat(provider).isInstanceOf(BouncyCastleProvider.class);
 
     assertRemoveProvider();
   }

+ 33 - 27
hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/crypto/TestOpensslCipher.java

@@ -24,9 +24,13 @@ import javax.crypto.NoSuchPaddingException;
 import javax.crypto.ShortBufferException;
 
 import org.apache.hadoop.test.GenericTestUtils;
-import org.junit.Assume;
-import org.junit.Assert;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.Timeout;
+
+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 static org.junit.jupiter.api.Assumptions.assumeTrue;
 
 public class TestOpensslCipher {
   private static final byte[] key = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 
@@ -34,32 +38,34 @@ public class TestOpensslCipher {
   private static final byte[] iv = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 
     0x07, 0x08, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08};
   
-  @Test(timeout=120000)
+  @Test
+  @Timeout(value = 120)
   public void testGetInstance() throws Exception {
-    Assume.assumeTrue(OpensslCipher.getLoadingFailureReason() == null);
+    assumeTrue(OpensslCipher.getLoadingFailureReason() == null);
     OpensslCipher cipher = OpensslCipher.getInstance("AES/CTR/NoPadding");
-    Assert.assertTrue(cipher != null);
+    assertTrue(cipher != null);
     
     try {
       cipher = OpensslCipher.getInstance("AES2/CTR/NoPadding");
-      Assert.fail("Should specify correct algorithm.");
+      fail("Should specify correct algorithm.");
     } catch (NoSuchAlgorithmException e) {
       // Expect NoSuchAlgorithmException
     }
     
     try {
       cipher = OpensslCipher.getInstance("AES/CTR/NoPadding2");
-      Assert.fail("Should specify correct padding.");
+      fail("Should specify correct padding.");
     } catch (NoSuchPaddingException e) {
       // Expect NoSuchPaddingException
     }
   }
   
-  @Test(timeout=120000)
+  @Test
+  @Timeout(value = 120)
   public void testUpdateArguments() throws Exception {
-    Assume.assumeTrue(OpensslCipher.getLoadingFailureReason() == null);
+    assumeTrue(OpensslCipher.getLoadingFailureReason() == null);
     OpensslCipher cipher = OpensslCipher.getInstance("AES/CTR/NoPadding");
-    Assert.assertTrue(cipher != null);
+    assertTrue(cipher != null);
     
     cipher.init(OpensslCipher.ENCRYPT_MODE, key, iv);
     
@@ -69,7 +75,7 @@ public class TestOpensslCipher {
     
     try {
       cipher.update(input, output);
-      Assert.fail("Input and output buffer should be direct buffer.");
+      fail("Input and output buffer should be direct buffer.");
     } catch (IllegalArgumentException e) {
       GenericTestUtils.assertExceptionContains(
           "Direct buffers are required", e);
@@ -80,19 +86,19 @@ public class TestOpensslCipher {
     output = ByteBuffer.allocateDirect(1000);
     try {
       cipher.update(input, output);
-      Assert.fail("Output buffer length should be sufficient " +
-          "to store output data");
+      fail("Output buffer length should be sufficient to store output data");
     } catch (ShortBufferException e) {
       GenericTestUtils.assertExceptionContains(
           "Output buffer is not sufficient", e);
     }
   }
   
-  @Test(timeout=120000)
+  @Test
+  @Timeout(value = 120)
   public void testDoFinalArguments() throws Exception {
-    Assume.assumeTrue(OpensslCipher.getLoadingFailureReason() == null);
+    assumeTrue(OpensslCipher.getLoadingFailureReason() == null);
     OpensslCipher cipher = OpensslCipher.getInstance("AES/CTR/NoPadding");
-    Assert.assertTrue(cipher != null);
+    assertTrue(cipher != null);
     
     cipher.init(OpensslCipher.ENCRYPT_MODE, key, iv);
     
@@ -101,20 +107,20 @@ public class TestOpensslCipher {
     
     try {
       cipher.doFinal(output);
-      Assert.fail("Output buffer should be direct buffer.");
+      fail("Output buffer should be direct buffer.");
     } catch (IllegalArgumentException e) {
-      GenericTestUtils.assertExceptionContains(
-          "Direct buffer is required", e);
+      GenericTestUtils.assertExceptionContains("Direct buffer is required", e);
     }
   }
 
-  @Test(timeout=120000)
+  @Test
+  @Timeout(value = 120)
   public void testIsSupportedSuite() throws Exception {
-    Assume.assumeTrue("Skipping due to falilure of loading OpensslCipher.",
-        OpensslCipher.getLoadingFailureReason() == null);
-    Assert.assertFalse("Unknown suite must not be supported.",
-        OpensslCipher.isSupported(CipherSuite.UNKNOWN));
-    Assert.assertTrue("AES/CTR/NoPadding is not an optional suite.",
-        OpensslCipher.isSupported(CipherSuite.AES_CTR_NOPADDING));
+    assumeTrue(OpensslCipher.getLoadingFailureReason() == null,
+        "Skipping due to failure of loading OpensslCipher.");
+    assertFalse(OpensslCipher.isSupported(CipherSuite.UNKNOWN),
+        "Unknown suite must not be supported.");
+    assertTrue(OpensslCipher.isSupported(CipherSuite.AES_CTR_NOPADDING),
+        "AES/CTR/NoPadding is not an optional suite.");
   }
 }

+ 84 - 79
hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/crypto/key/TestCachingKeyProvider.java

@@ -21,138 +21,143 @@ import java.util.Date;
 
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.crypto.key.kms.KMSClientProvider;
-import org.junit.Assert;
-import org.junit.Test;
-import org.mockito.Mockito;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.mockito.Mockito.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
 
 public class TestCachingKeyProvider {
 
   @Test
   public void testCurrentKey() throws Exception {
-    KeyProvider.KeyVersion mockKey = Mockito.mock(KeyProvider.KeyVersion.class);
-    KeyProvider mockProv = Mockito.mock(KeyProvider.class);
-    Mockito.when(mockProv.getCurrentKey(Mockito.eq("k1"))).thenReturn(mockKey);
-    Mockito.when(mockProv.getCurrentKey(Mockito.eq("k2"))).thenReturn(null);
-    Mockito.when(mockProv.getConf()).thenReturn(new Configuration());
+    KeyProvider.KeyVersion mockKey = mock(KeyProvider.KeyVersion.class);
+    KeyProvider mockProv = mock(KeyProvider.class);
+    when(mockProv.getCurrentKey(eq("k1"))).thenReturn(mockKey);
+    when(mockProv.getCurrentKey(eq("k2"))).thenReturn(null);
+    when(mockProv.getConf()).thenReturn(new Configuration());
     KeyProvider cache = new CachingKeyProvider(mockProv, 100, 100);
 
     // asserting caching
-    Assert.assertEquals(mockKey, cache.getCurrentKey("k1"));
-    Mockito.verify(mockProv, Mockito.times(1)).getCurrentKey(Mockito.eq("k1"));
-    Assert.assertEquals(mockKey, cache.getCurrentKey("k1"));
-    Mockito.verify(mockProv, Mockito.times(1)).getCurrentKey(Mockito.eq("k1"));
+    assertEquals(mockKey, cache.getCurrentKey("k1"));
+    verify(mockProv, times(1)).getCurrentKey(eq("k1"));
+    assertEquals(mockKey, cache.getCurrentKey("k1"));
+    verify(mockProv, times(1)).getCurrentKey(eq("k1"));
     Thread.sleep(1200);
-    Assert.assertEquals(mockKey, cache.getCurrentKey("k1"));
-    Mockito.verify(mockProv, Mockito.times(2)).getCurrentKey(Mockito.eq("k1"));
+    assertEquals(mockKey, cache.getCurrentKey("k1"));
+    verify(mockProv, times(2)).getCurrentKey(eq("k1"));
 
     // asserting no caching when key is not known
     cache = new CachingKeyProvider(mockProv, 100, 100);
-    Assert.assertEquals(null, cache.getCurrentKey("k2"));
-    Mockito.verify(mockProv, Mockito.times(1)).getCurrentKey(Mockito.eq("k2"));
-    Assert.assertEquals(null, cache.getCurrentKey("k2"));
-    Mockito.verify(mockProv, Mockito.times(2)).getCurrentKey(Mockito.eq("k2"));
+    assertEquals(null, cache.getCurrentKey("k2"));
+    verify(mockProv, times(1)).getCurrentKey(eq("k2"));
+    assertEquals(null, cache.getCurrentKey("k2"));
+    verify(mockProv, times(2)).getCurrentKey(eq("k2"));
   }
 
   @Test
   public void testKeyVersion() throws Exception {
-    KeyProvider.KeyVersion mockKey = Mockito.mock(KeyProvider.KeyVersion.class);
-    KeyProvider mockProv = Mockito.mock(KeyProvider.class);
-    Mockito.when(mockProv.getKeyVersion(Mockito.eq("k1@0")))
+    KeyProvider.KeyVersion mockKey = mock(KeyProvider.KeyVersion.class);
+    KeyProvider mockProv = mock(KeyProvider.class);
+    when(mockProv.getKeyVersion(eq("k1@0")))
         .thenReturn(mockKey);
-    Mockito.when(mockProv.getKeyVersion(Mockito.eq("k2@0"))).thenReturn(null);
-    Mockito.when(mockProv.getConf()).thenReturn(new Configuration());
+    when(mockProv.getKeyVersion(eq("k2@0"))).thenReturn(null);
+    when(mockProv.getConf()).thenReturn(new Configuration());
     KeyProvider cache = new CachingKeyProvider(mockProv, 100, 100);
 
     // asserting caching
-    Assert.assertEquals(mockKey, cache.getKeyVersion("k1@0"));
-    Mockito.verify(mockProv, Mockito.times(1))
-        .getKeyVersion(Mockito.eq("k1@0"));
-    Assert.assertEquals(mockKey, cache.getKeyVersion("k1@0"));
-    Mockito.verify(mockProv, Mockito.times(1))
-        .getKeyVersion(Mockito.eq("k1@0"));
+    assertEquals(mockKey, cache.getKeyVersion("k1@0"));
+    verify(mockProv, times(1))
+        .getKeyVersion(eq("k1@0"));
+    assertEquals(mockKey, cache.getKeyVersion("k1@0"));
+    verify(mockProv, times(1))
+        .getKeyVersion(eq("k1@0"));
     Thread.sleep(200);
-    Assert.assertEquals(mockKey, cache.getKeyVersion("k1@0"));
-    Mockito.verify(mockProv, Mockito.times(2))
-        .getKeyVersion(Mockito.eq("k1@0"));
+    assertEquals(mockKey, cache.getKeyVersion("k1@0"));
+    verify(mockProv, times(2))
+        .getKeyVersion(eq("k1@0"));
 
     // asserting no caching when key is not known
     cache = new CachingKeyProvider(mockProv, 100, 100);
-    Assert.assertEquals(null, cache.getKeyVersion("k2@0"));
-    Mockito.verify(mockProv, Mockito.times(1))
-        .getKeyVersion(Mockito.eq("k2@0"));
-    Assert.assertEquals(null, cache.getKeyVersion("k2@0"));
-    Mockito.verify(mockProv, Mockito.times(2))
-        .getKeyVersion(Mockito.eq("k2@0"));
+    assertEquals(null, cache.getKeyVersion("k2@0"));
+    verify(mockProv, times(1))
+        .getKeyVersion(eq("k2@0"));
+    assertEquals(null, cache.getKeyVersion("k2@0"));
+    verify(mockProv, times(2))
+        .getKeyVersion(eq("k2@0"));
   }
 
   @Test
   public void testMetadata() throws Exception {
-    KeyProvider.Metadata mockMeta = Mockito.mock(KeyProvider.Metadata.class);
-    KeyProvider mockProv = Mockito.mock(KeyProvider.class);
-    Mockito.when(mockProv.getMetadata(Mockito.eq("k1"))).thenReturn(mockMeta);
-    Mockito.when(mockProv.getMetadata(Mockito.eq("k2"))).thenReturn(null);
-    Mockito.when(mockProv.getConf()).thenReturn(new Configuration());
+    KeyProvider.Metadata mockMeta = mock(KeyProvider.Metadata.class);
+    KeyProvider mockProv = mock(KeyProvider.class);
+    when(mockProv.getMetadata(eq("k1"))).thenReturn(mockMeta);
+    when(mockProv.getMetadata(eq("k2"))).thenReturn(null);
+    when(mockProv.getConf()).thenReturn(new Configuration());
     KeyProvider cache = new CachingKeyProvider(mockProv, 100, 100);
 
     // asserting caching
-    Assert.assertEquals(mockMeta, cache.getMetadata("k1"));
-    Mockito.verify(mockProv, Mockito.times(1)).getMetadata(Mockito.eq("k1"));
-    Assert.assertEquals(mockMeta, cache.getMetadata("k1"));
-    Mockito.verify(mockProv, Mockito.times(1)).getMetadata(Mockito.eq("k1"));
+    assertEquals(mockMeta, cache.getMetadata("k1"));
+    verify(mockProv, times(1)).getMetadata(eq("k1"));
+    assertEquals(mockMeta, cache.getMetadata("k1"));
+    verify(mockProv, times(1)).getMetadata(eq("k1"));
     Thread.sleep(200);
-    Assert.assertEquals(mockMeta, cache.getMetadata("k1"));
-    Mockito.verify(mockProv, Mockito.times(2)).getMetadata(Mockito.eq("k1"));
+    assertEquals(mockMeta, cache.getMetadata("k1"));
+    verify(mockProv, times(2)).getMetadata(eq("k1"));
 
     // asserting no caching when key is not known
     cache = new CachingKeyProvider(mockProv, 100, 100);
-    Assert.assertEquals(null, cache.getMetadata("k2"));
-    Mockito.verify(mockProv, Mockito.times(1)).getMetadata(Mockito.eq("k2"));
-    Assert.assertEquals(null, cache.getMetadata("k2"));
-    Mockito.verify(mockProv, Mockito.times(2)).getMetadata(Mockito.eq("k2"));
+    assertEquals(null, cache.getMetadata("k2"));
+    verify(mockProv, times(1)).getMetadata(eq("k2"));
+    assertEquals(null, cache.getMetadata("k2"));
+    verify(mockProv, times(2)).getMetadata(eq("k2"));
   }
 
   @Test
   public void testRollNewVersion() throws Exception {
-    KeyProvider.KeyVersion mockKey = Mockito.mock(KeyProvider.KeyVersion.class);
-    KeyProvider mockProv = Mockito.mock(KeyProvider.class);
-    Mockito.when(mockProv.getCurrentKey(Mockito.eq("k1"))).thenReturn(mockKey);
-    Mockito.when(mockProv.getConf()).thenReturn(new Configuration());
+    KeyProvider.KeyVersion mockKey = mock(KeyProvider.KeyVersion.class);
+    KeyProvider mockProv = mock(KeyProvider.class);
+    when(mockProv.getCurrentKey(eq("k1"))).thenReturn(mockKey);
+    when(mockProv.getConf()).thenReturn(new Configuration());
     KeyProvider cache = new CachingKeyProvider(mockProv, 100, 100);
-    Assert.assertEquals(mockKey, cache.getCurrentKey("k1"));
-    Mockito.verify(mockProv, Mockito.times(1)).getCurrentKey(Mockito.eq("k1"));
+    assertEquals(mockKey, cache.getCurrentKey("k1"));
+    verify(mockProv, times(1)).getCurrentKey(eq("k1"));
     cache.rollNewVersion("k1");
 
     // asserting the cache is purged
-    Assert.assertEquals(mockKey, cache.getCurrentKey("k1"));
-    Mockito.verify(mockProv, Mockito.times(2)).getCurrentKey(Mockito.eq("k1"));
+    assertEquals(mockKey, cache.getCurrentKey("k1"));
+    verify(mockProv, times(2)).getCurrentKey(eq("k1"));
     cache.rollNewVersion("k1", new byte[0]);
-    Assert.assertEquals(mockKey, cache.getCurrentKey("k1"));
-    Mockito.verify(mockProv, Mockito.times(3)).getCurrentKey(Mockito.eq("k1"));
+    assertEquals(mockKey, cache.getCurrentKey("k1"));
+    verify(mockProv, times(3)).getCurrentKey(eq("k1"));
   }
 
   @Test
   public void testDeleteKey() throws Exception {
-    KeyProvider.KeyVersion mockKey = Mockito.mock(KeyProvider.KeyVersion.class);
-    KeyProvider mockProv = Mockito.mock(KeyProvider.class);
-    Mockito.when(mockProv.getCurrentKey(Mockito.eq("k1"))).thenReturn(mockKey);
-    Mockito.when(mockProv.getKeyVersion(Mockito.eq("k1@0")))
+    KeyProvider.KeyVersion mockKey = mock(KeyProvider.KeyVersion.class);
+    KeyProvider mockProv = mock(KeyProvider.class);
+    when(mockProv.getCurrentKey(eq("k1"))).thenReturn(mockKey);
+    when(mockProv.getKeyVersion(eq("k1@0")))
         .thenReturn(mockKey);
-    Mockito.when(mockProv.getMetadata(Mockito.eq("k1"))).thenReturn(
+    when(mockProv.getMetadata(eq("k1"))).thenReturn(
         new KMSClientProvider.KMSMetadata("c", 0, "l", null, new Date(), 1));
-    Mockito.when(mockProv.getConf()).thenReturn(new Configuration());
+    when(mockProv.getConf()).thenReturn(new Configuration());
     KeyProvider cache = new CachingKeyProvider(mockProv, 100, 100);
-    Assert.assertEquals(mockKey, cache.getCurrentKey("k1"));
-    Mockito.verify(mockProv, Mockito.times(1)).getCurrentKey(Mockito.eq("k1"));
-    Assert.assertEquals(mockKey, cache.getKeyVersion("k1@0"));
-    Mockito.verify(mockProv, Mockito.times(1))
-        .getKeyVersion(Mockito.eq("k1@0"));
+    assertEquals(mockKey, cache.getCurrentKey("k1"));
+    verify(mockProv, times(1)).getCurrentKey(eq("k1"));
+    assertEquals(mockKey, cache.getKeyVersion("k1@0"));
+    verify(mockProv, times(1))
+        .getKeyVersion(eq("k1@0"));
     cache.deleteKey("k1");
 
     // asserting the cache is purged
-    Assert.assertEquals(mockKey, cache.getCurrentKey("k1"));
-    Mockito.verify(mockProv, Mockito.times(2)).getCurrentKey(Mockito.eq("k1"));
-    Assert.assertEquals(mockKey, cache.getKeyVersion("k1@0"));
-    Mockito.verify(mockProv, Mockito.times(2))
-        .getKeyVersion(Mockito.eq("k1@0"));
+    assertEquals(mockKey, cache.getCurrentKey("k1"));
+    verify(mockProv, times(2)).getCurrentKey(eq("k1"));
+    assertEquals(mockKey, cache.getKeyVersion("k1@0"));
+    verify(mockProv, times(2))
+        .getKeyVersion(eq("k1@0"));
   }
 }

+ 18 - 18
hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/crypto/key/TestKeyProvider.java

@@ -17,13 +17,12 @@
  */
 package org.apache.hadoop.crypto.key;
 
-import org.junit.Assert;
 import org.apache.hadoop.conf.Configuration;
 
 import org.apache.hadoop.fs.Path;
 import org.apache.hadoop.security.ProviderUtils;
 import org.apache.hadoop.test.GenericTestUtils;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
 
 import java.io.IOException;
 import java.net.URI;
@@ -37,11 +36,12 @@ import java.util.List;
 import java.util.Map;
 
 import static org.apache.hadoop.test.LambdaTestUtils.intercept;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.assertArrayEquals;
-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.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;
 
 public class TestKeyProvider {
 
@@ -59,7 +59,7 @@ public class TestKeyProvider {
     assertEquals("/aaa", KeyProvider.getBaseName("/aaa@112"));
     try {
       KeyProvider.getBaseName("no-slashes");
-      assertTrue("should have thrown", false);
+      assertTrue(false, "should have thrown");
     } catch (IOException e) {
       assertTrue(true);
     }
@@ -249,15 +249,15 @@ public class TestKeyProvider {
     options.setCipher(CIPHER);
     options.setBitLength(128);
     kp.createKey("hello", options);
-    Assert.assertEquals(128, kp.size);
-    Assert.assertEquals(CIPHER, kp.algorithm);
-    Assert.assertNotNull(kp.material);
+    assertEquals(128, kp.size);
+    assertEquals(CIPHER, kp.algorithm);
+    assertNotNull(kp.material);
 
     kp = new MyKeyProvider(new Configuration());
     kp.rollNewVersion("hello");
-    Assert.assertEquals(128, kp.size);
-    Assert.assertEquals(CIPHER, kp.algorithm);
-    Assert.assertNotNull(kp.material);
+    assertEquals(128, kp.size);
+    assertEquals(CIPHER, kp.algorithm);
+    assertNotNull(kp.material);
   }
 
   @Test
@@ -267,9 +267,9 @@ public class TestKeyProvider {
     options.setCipher(CIPHER);
     options.setBitLength(128);
     kp.createKey("hello", options);
-    Assert.assertEquals(128, kp.size);
-    Assert.assertEquals(CIPHER, kp.algorithm);
-    Assert.assertNotNull(kp.material);
+    assertEquals(128, kp.size);
+    assertEquals(CIPHER, kp.algorithm);
+    assertNotNull(kp.material);
 
     kp = new MyKeyProvider(new Configuration());
     try {
@@ -286,7 +286,7 @@ public class TestKeyProvider {
     Configuration conf = new Configuration(false);
     conf.set("a", "A");
     MyKeyProvider kp = new MyKeyProvider(conf);
-    Assert.assertEquals("A", kp.getConf().get("a"));
+    assertEquals("A", kp.getConf().get("a"));
   }
 
 }

+ 68 - 81
hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/crypto/key/TestKeyProviderCryptoExtension.java

@@ -33,19 +33,18 @@ import javax.crypto.spec.SecretKeySpec;
 
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.crypto.key.KeyProviderCryptoExtension.EncryptedKeyVersion;
-import org.junit.Assert;
-import org.junit.BeforeClass;
+import org.junit.jupiter.api.BeforeAll;
 import org.junit.Rule;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
 import org.junit.rules.Timeout;
 
 import static org.apache.hadoop.crypto.key.KeyProvider.KeyVersion;
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-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.assertTrue;
+import static org.junit.jupiter.api.Assertions.fail;
 
 public class TestKeyProviderCryptoExtension {
 
@@ -61,7 +60,7 @@ public class TestKeyProviderCryptoExtension {
   @Rule
   public Timeout testTimeout = new Timeout(180000, TimeUnit.MILLISECONDS);
 
-  @BeforeClass
+  @BeforeAll
   public static void setup() throws Exception {
     conf = new Configuration();
     kp = new UserProvider.Factory().createProvider(new URI("user:///"), conf);
@@ -78,16 +77,14 @@ public class TestKeyProviderCryptoExtension {
     // Generate a new EEK and check it
     KeyProviderCryptoExtension.EncryptedKeyVersion ek1 = 
         kpExt.generateEncryptedKey(encryptionKey.getName());
-    assertEquals("Version name of EEK should be EEK",
-        KeyProviderCryptoExtension.EEK,
-        ek1.getEncryptedKeyVersion().getVersionName());
-    assertEquals("Name of EEK should be encryption key name",
-        ENCRYPTION_KEY_NAME, ek1.getEncryptionKeyName());
-    assertNotNull("Expected encrypted key material",
-        ek1.getEncryptedKeyVersion().getMaterial());
-    assertEquals("Length of encryption key material and EEK material should "
-            + "be the same", encryptionKey.getMaterial().length,
-        ek1.getEncryptedKeyVersion().getMaterial().length
+    assertEquals(KeyProviderCryptoExtension.EEK,
+        ek1.getEncryptedKeyVersion().getVersionName(), "Version name of EEK should be EEK");
+    assertEquals(ENCRYPTION_KEY_NAME, ek1.getEncryptionKeyName(),
+        "Name of EEK should be encryption key name");
+    assertNotNull(ek1.getEncryptedKeyVersion().getMaterial(), "Expected encrypted key material");
+    assertEquals(encryptionKey.getMaterial().length,
+        ek1.getEncryptedKeyVersion().getMaterial().length,
+        "Length of encryption key material and EEK material should be the same"
     );
 
     // Decrypt EEK into an EK and check it
@@ -137,8 +134,8 @@ public class TestKeyProviderCryptoExtension {
     KeyVersion decryptedKey = kpExt.decryptEncryptedKey(eek2);
     final byte[] apiMaterial = decryptedKey.getMaterial();
 
-    assertArrayEquals("Wrong key material from decryptEncryptedKey",
-        manualMaterial, apiMaterial);
+    assertArrayEquals(manualMaterial, apiMaterial,
+        "Wrong key material from decryptEncryptedKey");
   }
 
   @Test
@@ -158,16 +155,14 @@ public class TestKeyProviderCryptoExtension {
     // Reencrypt ek1
     final KeyProviderCryptoExtension.EncryptedKeyVersion ek2 =
         kpExt.reencryptEncryptedKey(ek1);
-    assertEquals("Version name of EEK should be EEK",
-        KeyProviderCryptoExtension.EEK,
-        ek2.getEncryptedKeyVersion().getVersionName());
-    assertEquals("Name of EEK should be encryption key name",
-        ENCRYPTION_KEY_NAME, ek2.getEncryptionKeyName());
-    assertNotNull("Expected encrypted key material",
-        ek2.getEncryptedKeyVersion().getMaterial());
-    assertEquals("Length of encryption key material and EEK material should "
-            + "be the same", encryptionKey.getMaterial().length,
-        ek2.getEncryptedKeyVersion().getMaterial().length);
+    assertEquals(KeyProviderCryptoExtension.EEK,
+        ek2.getEncryptedKeyVersion().getVersionName(), "Version name of EEK should be EEK");
+    assertEquals(ENCRYPTION_KEY_NAME, ek2.getEncryptionKeyName(),
+        "Name of EEK should be encryption key name");
+    assertNotNull(ek2.getEncryptedKeyVersion().getMaterial(), "Expected encrypted key material");
+    assertEquals(encryptionKey.getMaterial().length,
+        ek2.getEncryptedKeyVersion().getMaterial().length,
+        "Length of encryption key material and EEK material should be the same");
 
     if (Arrays.equals(ek2.getEncryptedKeyVersion().getMaterial(),
         ek1.getEncryptedKeyVersion().getMaterial())) {
@@ -182,16 +177,14 @@ public class TestKeyProviderCryptoExtension {
     // Re-encrypting the same EEK with the same EK should be deterministic
     final KeyProviderCryptoExtension.EncryptedKeyVersion ek2a =
         kpExt.reencryptEncryptedKey(ek1);
-    assertEquals("Version name of EEK should be EEK",
-        KeyProviderCryptoExtension.EEK,
-        ek2a.getEncryptedKeyVersion().getVersionName());
-    assertEquals("Name of EEK should be encryption key name",
-        ENCRYPTION_KEY_NAME, ek2a.getEncryptionKeyName());
-    assertNotNull("Expected encrypted key material",
-        ek2a.getEncryptedKeyVersion().getMaterial());
-    assertEquals("Length of encryption key material and EEK material should "
-            + "be the same", encryptionKey.getMaterial().length,
-        ek2a.getEncryptedKeyVersion().getMaterial().length);
+    assertEquals(KeyProviderCryptoExtension.EEK,
+        ek2a.getEncryptedKeyVersion().getVersionName(), "Version name of EEK should be EEK");
+    assertEquals(ENCRYPTION_KEY_NAME, ek2a.getEncryptionKeyName(),
+        "Name of EEK should be encryption key name");
+    assertNotNull(ek2a.getEncryptedKeyVersion().getMaterial(), "Expected encrypted key material");
+    assertEquals(encryptionKey.getMaterial().length,
+        ek2a.getEncryptedKeyVersion().getMaterial().length,
+        "Length of encryption key material and EEK material should be the same");
 
     if (Arrays.equals(ek2a.getEncryptedKeyVersion().getMaterial(),
         ek1.getEncryptedKeyVersion().getMaterial())) {
@@ -203,16 +196,14 @@ public class TestKeyProviderCryptoExtension {
     // Re-encrypting an EEK with the same version EK should be no-op
     final KeyProviderCryptoExtension.EncryptedKeyVersion ek3 =
         kpExt.reencryptEncryptedKey(ek2);
-    assertEquals("Version name of EEK should be EEK",
-        KeyProviderCryptoExtension.EEK,
-        ek3.getEncryptedKeyVersion().getVersionName());
-    assertEquals("Name of EEK should be encryption key name",
-        ENCRYPTION_KEY_NAME, ek3.getEncryptionKeyName());
-    assertNotNull("Expected encrypted key material",
-        ek3.getEncryptedKeyVersion().getMaterial());
-    assertEquals("Length of encryption key material and EEK material should "
-            + "be the same", encryptionKey.getMaterial().length,
-        ek3.getEncryptedKeyVersion().getMaterial().length);
+    assertEquals(KeyProviderCryptoExtension.EEK,
+        ek3.getEncryptedKeyVersion().getVersionName(), "Version name of EEK should be EEK");
+    assertEquals(ENCRYPTION_KEY_NAME, ek3.getEncryptionKeyName(),
+        "Name of EEK should be encryption key name");
+    assertNotNull(ek3.getEncryptedKeyVersion().getMaterial(), "Expected encrypted key material");
+    assertEquals(encryptionKey.getMaterial().length,
+        ek3.getEncryptedKeyVersion().getMaterial().length,
+        "Length of encryption key material and EEK material should be the same");
 
     if (Arrays.equals(ek3.getEncryptedKeyVersion().getMaterial(),
         ek1.getEncryptedKeyVersion().getMaterial())) {
@@ -254,29 +245,26 @@ public class TestKeyProviderCryptoExtension {
     for (int i = 0; i < ekvs.size(); ++i) {
       final EncryptedKeyVersion ekv = ekvs.get(i);
       final EncryptedKeyVersion orig = ekvsOrig.get(i);
-      assertEquals("Version name should be EEK",
-          KeyProviderCryptoExtension.EEK,
-          ekv.getEncryptedKeyVersion().getVersionName());
-      assertEquals("Encryption key name should be " + ENCRYPTION_KEY_NAME,
-          ENCRYPTION_KEY_NAME, ekv.getEncryptionKeyName());
-      assertNotNull("Expected encrypted key material",
-          ekv.getEncryptedKeyVersion().getMaterial());
-      assertEquals("Length of encryption key material and EEK material should "
-              + "be the same", encryptionKey.getMaterial().length,
-          ekv.getEncryptedKeyVersion().getMaterial().length);
-      assertFalse(
-          "Encrypted key material should not equal encryption key material",
-          Arrays.equals(ekv.getEncryptedKeyVersion().getMaterial(),
-              encryptionKey.getMaterial()));
+      assertEquals(KeyProviderCryptoExtension.EEK,
+          ekv.getEncryptedKeyVersion().getVersionName(), "Version name should be EEK");
+      assertEquals(ENCRYPTION_KEY_NAME, ekv.getEncryptionKeyName(),
+          "Encryption key name should be " + ENCRYPTION_KEY_NAME);
+      assertNotNull(ekv.getEncryptedKeyVersion().getMaterial(), "Expected encrypted key material");
+      assertEquals(encryptionKey.getMaterial().length,
+          ekv.getEncryptedKeyVersion().getMaterial().length,
+          "Length of encryption key material and EEK material should be the same");
+      assertFalse(Arrays.equals(ekv.getEncryptedKeyVersion().getMaterial(),
+          encryptionKey.getMaterial()),
+          "Encrypted key material should not equal encryption key material");
 
       if (i < 3) {
-        assertFalse("Re-encrypted EEK should have different material",
-            Arrays.equals(ekv.getEncryptedKeyVersion().getMaterial(),
-                orig.getEncryptedKeyVersion().getMaterial()));
+        assertFalse(Arrays.equals(ekv.getEncryptedKeyVersion().getMaterial(),
+            orig.getEncryptedKeyVersion().getMaterial()),
+            "Re-encrypted EEK should have different material");
       } else {
-        assertTrue("Re-encrypted EEK should have same material",
-            Arrays.equals(ekv.getEncryptedKeyVersion().getMaterial(),
-                orig.getEncryptedKeyVersion().getMaterial()));
+        assertTrue(Arrays.equals(ekv.getEncryptedKeyVersion().getMaterial(),
+            orig.getEncryptedKeyVersion().getMaterial()),
+            "Re-encrypted EEK should have same material");
       }
 
       // Decrypt the new EEK into an EK and check it
@@ -289,20 +277,19 @@ public class TestKeyProviderCryptoExtension {
 
       // Verify decrypting the new EEK and orig EEK gives the same material.
       final KeyVersion origKv = kpExt.decryptEncryptedKey(orig);
-      assertTrue("Returned EEK and original EEK should both decrypt to the "
-          + "same kv.", Arrays.equals(origKv.getMaterial(), kv.getMaterial()));
+      assertTrue(Arrays.equals(origKv.getMaterial(), kv.getMaterial()),
+          "Returned EEK and original EEK should both decrypt to the same kv.");
     }
   }
 
   @Test
   public void testNonDefaultCryptoExtensionSelectionWithCachingKeyProvider()
-          throws Exception {
+      throws Exception {
     Configuration config = new Configuration();
     KeyProvider localKp = new DummyCryptoExtensionKeyProvider(config);
     localKp = new CachingKeyProvider(localKp, 30000, 30000);
     EncryptedKeyVersion localEkv = getEncryptedKeyVersion(config, localKp);
-    Assert.assertEquals("dummyFakeKey@1",
-            localEkv.getEncryptionKeyVersionName());
+    assertEquals("dummyFakeKey@1", localEkv.getEncryptionKeyVersionName());
   }
 
   @Test
@@ -314,8 +301,8 @@ public class TestKeyProviderCryptoExtension {
                     createProvider(new URI("user:///"), config);
     localKp = new CachingKeyProvider(localKp, 30000, 30000);
     EncryptedKeyVersion localEkv = getEncryptedKeyVersion(config, localKp);
-    Assert.assertEquals(ENCRYPTION_KEY_NAME+"@0",
-            localEkv.getEncryptionKeyVersionName());
+    assertEquals(ENCRYPTION_KEY_NAME+"@0",
+        localEkv.getEncryptionKeyVersionName());
   }
 
   @Test
@@ -326,8 +313,8 @@ public class TestKeyProviderCryptoExtension {
             createProvider(new URI("user:///"), config);
     localKp = new DummyCachingCryptoExtensionKeyProvider(localKp, 30000, 30000);
     EncryptedKeyVersion localEkv = getEncryptedKeyVersion(config, localKp);
-    Assert.assertEquals("dummyCachingFakeKey@1",
-            localEkv.getEncryptionKeyVersionName());
+    assertEquals("dummyCachingFakeKey@1",
+        localEkv.getEncryptionKeyVersionName());
   }
 
   private EncryptedKeyVersion getEncryptedKeyVersion(Configuration config,

+ 12 - 12
hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/crypto/key/TestKeyProviderDelegationTokenExtension.java

@@ -17,6 +17,8 @@
  */
 package org.apache.hadoop.crypto.key;
 
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
@@ -27,9 +29,7 @@ import org.apache.hadoop.crypto.key.KeyProviderDelegationTokenExtension.Delegati
 import org.apache.hadoop.io.Text;
 import org.apache.hadoop.security.Credentials;
 import org.apache.hadoop.security.token.Token;
-import org.junit.Assert;
-import org.junit.Test;
-import org.mockito.Mockito;
+import org.junit.jupiter.api.Test;
 
 public class TestKeyProviderDelegationTokenExtension {
   
@@ -50,14 +50,14 @@ public class TestKeyProviderDelegationTokenExtension {
     KeyProviderDelegationTokenExtension kpDTE1 = 
         KeyProviderDelegationTokenExtension
         .createKeyProviderDelegationTokenExtension(kp);
-    Assert.assertNotNull(kpDTE1);
+    assertNotNull(kpDTE1);
     Token<?>[] tokens = kpDTE1.addDelegationTokens("user", credentials);
     // Default implementation should return no tokens.
-    Assert.assertNotNull(tokens);
-    Assert.assertEquals(0, tokens.length);
+    assertNotNull(tokens);
+    assertEquals(0, tokens.length);
     
     MockKeyProvider mock = mock(MockKeyProvider.class);
-    Mockito.when(mock.getConf()).thenReturn(new Configuration());
+    when(mock.getConf()).thenReturn(new Configuration());
     when(mock.getCanonicalServiceName()).thenReturn("cservice");
     when(mock.getDelegationToken("renewer")).thenReturn(
         new Token(null, null, new Text("kind"), new Text(
@@ -67,11 +67,11 @@ public class TestKeyProviderDelegationTokenExtension {
         KeyProviderDelegationTokenExtension
         .createKeyProviderDelegationTokenExtension(mock);
     tokens = kpDTE2.addDelegationTokens("renewer", credentials);
-    Assert.assertNotNull(tokens);
-    Assert.assertEquals(1, tokens.length);
-    Assert.assertEquals("kind", tokens[0].getKind().toString());
-    Assert.assertEquals("tservice", tokens[0].getService().toString());
-    Assert.assertNotNull(credentials.getToken(new Text("cservice")));
+    assertNotNull(tokens);
+    assertEquals(1, tokens.length);
+    assertEquals("kind", tokens[0].getKind().toString());
+    assertEquals("tservice", tokens[0].getService().toString());
+    assertNotNull(credentials.getToken(new Text("cservice")));
   }
 
 }

+ 49 - 49
hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/crypto/key/TestKeyProviderFactory.java

@@ -34,22 +34,23 @@ import org.apache.hadoop.security.Credentials;
 import org.apache.hadoop.security.ProviderUtils;
 import org.apache.hadoop.security.UserGroupInformation;
 import org.apache.hadoop.test.GenericTestUtils;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
 
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.assertNotNull;
-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.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.fail;
 
 public class TestKeyProviderFactory {
 
   private FileSystemTestHelper fsHelper;
   private File testRootDir;
 
-  @Before
+  @BeforeEach
   public void setup() {
     fsHelper = new FileSystemTestHelper();
     String testRoot = fsHelper.getTestRootDir();
@@ -79,7 +80,7 @@ public class TestKeyProviderFactory {
     conf.set(KeyProviderFactory.KEY_PROVIDER_PATH, "unknown:///");
     try {
       List<KeyProvider> providers = KeyProviderFactory.getProviders(conf);
-      assertTrue("should throw!", false);
+      assertTrue(false, "should throw!");
     } catch (IOException e) {
       assertEquals("No KeyProviderFactory for unknown:/// in " +
           KeyProviderFactory.KEY_PROVIDER_PATH,
@@ -93,7 +94,7 @@ public class TestKeyProviderFactory {
     conf.set(KeyProviderFactory.KEY_PROVIDER_PATH, "unkn@own:/x/y");
     try {
       List<KeyProvider> providers = KeyProviderFactory.getProviders(conf);
-      assertTrue("should throw!", false);
+      assertTrue(false, "should throw!");
     } catch (IOException e) {
       assertEquals("Bad configuration of " +
           KeyProviderFactory.KEY_PROVIDER_PATH +
@@ -133,14 +134,14 @@ public class TestKeyProviderFactory {
     // try recreating key3
     try {
       provider.createKey("key3", key3, KeyProvider.options(conf));
-      assertTrue("should throw", false);
+      assertTrue(false, "should throw");
     } catch (IOException e) {
       assertEquals("Key key3 already exists in " + ourUrl, e.getMessage());
     }
     provider.deleteKey("key3");
     try {
       provider.deleteKey("key3");
-      assertTrue("should throw", false);
+      assertTrue(false, "should throw");
     } catch (IOException e) {
       assertEquals("Key key3 does not exist in " + ourUrl, e.getMessage());
     }
@@ -148,7 +149,7 @@ public class TestKeyProviderFactory {
     try {
       provider.createKey("key4", key3,
           KeyProvider.options(conf).setBitLength(8));
-      assertTrue("should throw", false);
+      assertTrue(false, "should throw");
     } catch (IOException e) {
       assertEquals("Wrong key length. Required 8, but got 128", e.getMessage());
     }
@@ -164,13 +165,13 @@ public class TestKeyProviderFactory {
     assertEquals("key4@1", provider.getCurrentKey("key4").getVersionName());
     try {
       provider.rollNewVersion("key4", key1);
-      assertTrue("should throw", false);
+      assertTrue(false, "should throw");
     } catch (IOException e) {
       assertEquals("Wrong key length. Required 8, but got 128", e.getMessage());
     }
     try {
       provider.rollNewVersion("no-such-key", key1);
-      assertTrue("should throw", false);
+      assertTrue(false, "should throw");
     } catch (IOException e) {
       assertEquals("Key no-such-key not found", e.getMessage());
     }
@@ -184,15 +185,14 @@ public class TestKeyProviderFactory {
     assertEquals("key3@0", provider.getCurrentKey("key3").getVersionName());
 
     List<String> keys = provider.getKeys();
-    assertTrue("Keys should have been returned.", keys.size() == 2);
-    assertTrue("Returned Keys should have included key3.", keys.contains("key3"));
-    assertTrue("Returned Keys should have included key4.", keys.contains("key4"));
+    assertTrue(keys.size() == 2, "Keys should have been returned.");
+    assertTrue(keys.contains("key3"), "Returned Keys should have included key3.");
+    assertTrue(keys.contains("key4"), "Returned Keys should have included key4.");
 
     List<KeyVersion> kvl = provider.getKeyVersions("key3");
-    assertEquals("KeyVersions should have been returned for key3.",
-        1, kvl.size());
-    assertEquals("KeyVersions should have included key3@0.",
-        "key3@0", kvl.get(0).getVersionName());
+    assertEquals(1, kvl.size(), "KeyVersions should have been returned for key3.");
+    assertEquals("key3@0", kvl.get(0).getVersionName(),
+        "KeyVersions should have included key3@0.");
     assertArrayEquals(key3, kvl.get(0).getMaterial());
   }
 
@@ -238,12 +238,12 @@ public class TestKeyProviderFactory {
     assertNotNull(provider.getCurrentKey("key5"));
     try {
       provider.flush();
-      Assert.fail("Should not succeed");
+      fail("Should not succeed");
     } catch (Exception e) {
       // Ignore
     }
-    // SHould be reset to pre-flush state
-    Assert.assertNull(provider.getCurrentKey("key5"));
+    // Should be reset to pre-flush state
+    assertNull(provider.getCurrentKey("key5"));
     
     // Un-inject last failure and
     // inject failure during keystore backup
@@ -254,12 +254,12 @@ public class TestKeyProviderFactory {
     assertNotNull(provider.getCurrentKey("key6"));
     try {
       provider.flush();
-      Assert.fail("Should not succeed");
+      fail("Should not succeed");
     } catch (Exception e) {
       // Ignore
     }
-    // SHould be reset to pre-flush state
-    Assert.assertNull(provider.getCurrentKey("key6"));
+    // Should be reset to pre-flush state
+    assertNull(provider.getCurrentKey("key6"));
     // END : Test flush error by failure injection
 
     conf.set(KeyProviderFactory.KEY_PROVIDER_PATH, ourUrl.replace(
@@ -270,7 +270,7 @@ public class TestKeyProviderFactory {
     FileSystem fs = path.getFileSystem(conf);
     FileStatus s = fs.getFileStatus(path);
     assertEquals("rw-------", s.getPermission().toString());
-    assertTrue(file + " should exist", file.isFile());
+    assertTrue(file.isFile(), file + " should exist");
 
     // Corrupt file and Check if JKS can reload from _OLD file
     File oldFile = new File(file.getPath() + "_OLD");
@@ -280,7 +280,7 @@ public class TestKeyProviderFactory {
     assertTrue(oldFile.exists());
     provider = KeyProviderFactory.getProviders(conf).get(0);
     assertTrue(file.exists());
-    assertTrue(oldFile + "should be deleted", !oldFile.exists());
+    assertTrue(!oldFile.exists(), oldFile + "should be deleted");
     verifyAfterReload(file, provider);
     assertTrue(!oldFile.exists());
 
@@ -289,7 +289,7 @@ public class TestKeyProviderFactory {
     newFile.createNewFile();
     try {
       provider = KeyProviderFactory.getProviders(conf).get(0);
-      Assert.fail("_NEW and current file should not exist together !!");
+      fail("_NEW and current file should not exist together !!");
     } catch (Exception e) {
       // Ignore
     } finally {
@@ -303,10 +303,10 @@ public class TestKeyProviderFactory {
     file.delete();
     try {
       provider = KeyProviderFactory.getProviders(conf).get(0);
-      Assert.assertFalse(newFile.exists());
-      Assert.assertFalse(oldFile.exists());
+      assertFalse(newFile.exists());
+      assertFalse(oldFile.exists());
     } catch (Exception e) {
-      Assert.fail("JKS should load from _NEW file !!");
+      fail("JKS should load from _NEW file !!");
       // Ignore
     }
     verifyAfterReload(file, provider);
@@ -317,10 +317,10 @@ public class TestKeyProviderFactory {
     file.delete();
     try {
       provider = KeyProviderFactory.getProviders(conf).get(0);
-      Assert.assertFalse(newFile.exists());
-      Assert.assertFalse(oldFile.exists());
+      assertFalse(newFile.exists());
+      assertFalse(oldFile.exists());
     } catch (Exception e) {
-      Assert.fail("JKS should load from _OLD file !!");
+      fail("JKS should load from _OLD file !!");
       // Ignore
     } finally {
       if (newFile.exists()) {
@@ -337,7 +337,7 @@ public class TestKeyProviderFactory {
     provider = KeyProviderFactory.getProviders(conf).get(0);
     try {
       provider.createKey("UPPERCASE", KeyProvider.options(conf));
-      Assert.fail("Expected failure on creating key name with uppercase " +
+      fail("Expected failure on creating key name with uppercase " +
           "characters");
     } catch (IllegalArgumentException e) {
       GenericTestUtils.assertExceptionContains("Uppercase key names", e);
@@ -373,8 +373,8 @@ public class TestKeyProviderFactory {
 
     FileSystem fs = path.getFileSystem(conf);
     FileStatus s = fs.getFileStatus(path);
-    assertEquals("Permissions should have been retained from the preexisting "
-        + "keystore.", "rwxrwxrwx", s.getPermission().toString());
+    assertEquals("rwxrwxrwx", s.getPermission().toString(),
+        "Permissions should have been retained from the preexisting keystore.");
   }
 
   @Test
@@ -393,29 +393,29 @@ public class TestKeyProviderFactory {
       provider.createKey("key3", new byte[16], KeyProvider.options(conf));
       provider.flush();
     } catch (Exception ex) {
-      Assert.fail("could not create keystore with password file");
+      fail("could not create keystore with password file");
     }
     KeyProvider provider = KeyProviderFactory.getProviders(conf).get(0);
-    Assert.assertNotNull(provider.getCurrentKey("key3"));
+    assertNotNull(provider.getCurrentKey("key3"));
 
     try {
       conf.set(JavaKeyStoreProvider.KEYSTORE_PASSWORD_FILE_KEY, "bar");
       KeyProviderFactory.getProviders(conf).get(0);
-      Assert.fail("using non existing password file, it should fail");
+      fail("using non existing password file, it should fail");
     } catch (IOException ex) {
       //NOP
     }
     try {
       conf.set(JavaKeyStoreProvider.KEYSTORE_PASSWORD_FILE_KEY, "core-site.xml");
       KeyProviderFactory.getProviders(conf).get(0);
-      Assert.fail("using different password file, it should fail");
+      fail("using different password file, it should fail");
     } catch (IOException ex) {
       //NOP
     }
     try {
       conf.unset(JavaKeyStoreProvider.KEYSTORE_PASSWORD_FILE_KEY);
       KeyProviderFactory.getProviders(conf).get(0);
-      Assert.fail("No password file property, env not set, it should fail");
+      fail("No password file property, env not set, it should fail");
     } catch (IOException ex) {
       //NOP
     }
@@ -427,11 +427,11 @@ public class TestKeyProviderFactory {
     final Path jksPath = new Path(testRootDir.toString(), "test.jks");
     URI uri = new URI(JavaKeyStoreProvider.SCHEME_NAME + "://file" + jksPath.toUri());
     KeyProvider kp = KeyProviderFactory.get(uri, conf);
-    Assert.assertNotNull(kp);
-    Assert.assertEquals(JavaKeyStoreProvider.class, kp.getClass());
+    assertNotNull(kp);
+    assertEquals(JavaKeyStoreProvider.class, kp.getClass());
     uri = new URI("foo://bar");
     kp = KeyProviderFactory.get(uri, conf);
-    Assert.assertNull(kp);
+    assertNull(kp);
 
   }
 

+ 10 - 10
hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/crypto/key/TestKeyShell.java

@@ -27,13 +27,13 @@ import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.fs.Path;
 import org.apache.hadoop.security.ProviderUtils;
 import org.apache.hadoop.test.GenericTestUtils;
-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 static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
 
 public class TestKeyShell {
   private final ByteArrayOutputStream outContent = new ByteArrayOutputStream();
@@ -45,7 +45,7 @@ public class TestKeyShell {
   /* The default JCEKS provider - for testing purposes */
   private String jceksProvider;
 
-  @Before
+  @BeforeEach
   public void setup() throws Exception {
     outContent.reset();
     errContent.reset();
@@ -62,7 +62,7 @@ public class TestKeyShell {
     System.setErr(new PrintStream(errContent));
   }
 
-  @After
+  @AfterEach
   public void cleanUp() throws Exception {
     System.setOut(initialStdOut);
     System.setErr(initialStdErr);
@@ -115,7 +115,7 @@ public class TestKeyShell {
     rc = ks.run(args1);
     assertEquals(0, rc);
     assertTrue(outContent.toString().contains(keyName + " has been " +
-            "successfully created"));
+        "successfully created"));
     assertTrue(outContent.toString()
         .contains(ProviderUtils.NO_PASSWORD_WARN));
     assertTrue(outContent.toString()
@@ -150,7 +150,7 @@ public class TestKeyShell {
     deleteKey(ks, keyName);
 
     listOut = listKeys(ks, false);
-    assertFalse(listOut, listOut.contains(keyName));
+    assertFalse(listOut.contains(keyName), listOut);
   }
   
   /* HADOOP-10586 KeyShell didn't allow -description. */

+ 70 - 62
hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/crypto/key/TestValueQueue.java

@@ -34,13 +34,16 @@ import org.apache.hadoop.crypto.key.kms.ValueQueue.QueueRefiller;
 import org.apache.hadoop.crypto.key.kms.ValueQueue.SyncGenerationPolicy;
 import org.apache.hadoop.test.GenericTestUtils;
 import org.apache.hadoop.thirdparty.com.google.common.cache.LoadingCache;
-import org.junit.Assert;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.Timeout;
 
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
 import static org.mockito.Mockito.doThrow;
+import static org.mockito.Mockito.spy;
 import static org.mockito.Mockito.times;
 import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.spy;
 
 
 public class TestValueQueue {
@@ -86,21 +89,23 @@ public class TestValueQueue {
   /**
    * Verifies that Queue is initially filled to "numInitValues"
    */
-  @Test(timeout=30000)
+  @Test
+  @Timeout(value = 30)
   public void testInitFill() throws Exception {
     MockFiller filler = new MockFiller();
     ValueQueue<String> vq =
         new ValueQueue<String>(10, 0.1f, 30000, 1,
             SyncGenerationPolicy.ALL, filler);
-    Assert.assertEquals("test", vq.getNext("k1"));
-    Assert.assertEquals(1, filler.getTop().num);
+    assertEquals("test", vq.getNext("k1"));
+    assertEquals(1, filler.getTop().num);
     vq.shutdown();
   }
 
   /**
    * Verifies that Queue is initialized (Warmed-up) for provided keys
    */
-  @Test(timeout=30000)
+  @Test
+  @Timeout(value = 30)
   public void testWarmUp() throws Exception {
     MockFiller filler = new MockFiller();
     ValueQueue<String> vq =
@@ -109,10 +114,10 @@ public class TestValueQueue {
     vq.initializeQueuesForKeys("k1", "k2", "k3");
     FillInfo[] fillInfos =
       {filler.getTop(), filler.getTop(), filler.getTop()};
-    Assert.assertEquals(5, fillInfos[0].num);
-    Assert.assertEquals(5, fillInfos[1].num);
-    Assert.assertEquals(5, fillInfos[2].num);
-    Assert.assertEquals(new HashSet<>(Arrays.asList("k1", "k2", "k3")),
+    assertEquals(5, fillInfos[0].num);
+    assertEquals(5, fillInfos[1].num);
+    assertEquals(5, fillInfos[2].num);
+    assertEquals(new HashSet<>(Arrays.asList("k1", "k2", "k3")),
         new HashSet<>(Arrays.asList(fillInfos[0].key,
             fillInfos[1].key,
             fillInfos[2].key)));
@@ -122,7 +127,8 @@ public class TestValueQueue {
   /**
    * Verifies that Queue is initialized (Warmed-up) for partial keys.
    */
-  @Test(timeout = 30000)
+  @Test
+  @Timeout(value = 30)
   public void testPartialWarmUp() throws Exception {
     MockFiller filler = new MockFiller();
     ValueQueue<String> vq =
@@ -139,16 +145,16 @@ public class TestValueQueue {
     doThrow(new ExecutionException(new Exception())).when(kqSpy).get("k2");
     FieldUtils.writeField(vq, "keyQueues", kqSpy, true);
 
-    Assert.assertThrows(IOException.class, () -> vq.initializeQueuesForKeys("k1", "k2", "k3"));
+    assertThrows(IOException.class, () -> vq.initializeQueuesForKeys("k1", "k2", "k3"));
     verify(kqSpy, times(1)).get("k2");
 
     FillInfo[] fillInfos =
         {filler.getTop(), filler.getTop(), filler.getTop()};
-    Assert.assertEquals(5, fillInfos[0].num);
-    Assert.assertEquals(5, fillInfos[1].num);
-    Assert.assertNull(fillInfos[2]);
+    assertEquals(5, fillInfos[0].num);
+    assertEquals(5, fillInfos[1].num);
+    assertNull(fillInfos[2]);
 
-    Assert.assertEquals(new HashSet<>(Arrays.asList("k1", "k3")),
+    assertEquals(new HashSet<>(Arrays.asList("k1", "k3")),
         new HashSet<>(Arrays.asList(fillInfos[0].key,
             fillInfos[1].key)));
     vq.shutdown();
@@ -158,21 +164,22 @@ public class TestValueQueue {
    * Verifies that the refill task is executed after "checkInterval" if
    * num values below "lowWatermark"
    */
-  @Test(timeout=30000)
+  @Test
+  @Timeout(value = 30)
   public void testRefill() throws Exception {
     MockFiller filler = new MockFiller();
     ValueQueue<String> vq =
         new ValueQueue<String>(100, 0.1f, 30000, 1,
             SyncGenerationPolicy.ALL, filler);
     // Trigger a prefill (10) and an async refill (91)
-    Assert.assertEquals("test", vq.getNext("k1"));
-    Assert.assertEquals(10, filler.getTop().num);
+    assertEquals("test", vq.getNext("k1"));
+    assertEquals(10, filler.getTop().num);
 
     // Wait for the async task to finish
     waitForRefill(vq, "k1", 100);
     // Refill task should add 91 values to get to a full queue (10 produced by
     // the prefill to the low watermark, 1 consumed by getNext())
-    Assert.assertEquals(91, filler.getTop().num);
+    assertEquals(91, filler.getTop().num);
     vq.shutdown();
   }
 
@@ -180,24 +187,25 @@ public class TestValueQueue {
    * Verifies that the No refill Happens after "checkInterval" if
    * num values above "lowWatermark"
    */
-  @Test(timeout=30000)
+  @Test
+  @Timeout(value = 30)
   public void testNoRefill() throws Exception {
     MockFiller filler = new MockFiller();
     ValueQueue<String> vq =
         new ValueQueue<String>(10, 0.5f, 30000, 1,
             SyncGenerationPolicy.ALL, filler);
     // Trigger a prefill (5) and an async refill (6)
-    Assert.assertEquals("test", vq.getNext("k1"));
-    Assert.assertEquals(5, filler.getTop().num);
+    assertEquals("test", vq.getNext("k1"));
+    assertEquals(5, filler.getTop().num);
 
     // Wait for the async task to finish
     waitForRefill(vq, "k1", 10);
     // Refill task should add 6 values to get to a full queue (5 produced by
     // the prefill to the low watermark, 1 consumed by getNext())
-    Assert.assertEquals(6, filler.getTop().num);
+    assertEquals(6, filler.getTop().num);
 
     // Take another value, queue is still above the watermark
-    Assert.assertEquals("test", vq.getNext("k1"));
+    assertEquals("test", vq.getNext("k1"));
 
     // Wait a while to make sure that no async refills are triggered
     try {
@@ -205,28 +213,29 @@ public class TestValueQueue {
     } catch (TimeoutException ignored) {
       // This is the correct outcome - no refill is expected
     }
-    Assert.assertEquals(null, filler.getTop());
+    assertEquals(null, filler.getTop());
     vq.shutdown();
   }
 
   /**
    * Verify getAtMost when SyncGeneration Policy = ALL
    */
-  @Test(timeout=30000)
-  public void testgetAtMostPolicyALL() throws Exception {
+  @Test
+  @Timeout(value = 30)
+  public void testGetAtMostPolicyALL() throws Exception {
     MockFiller filler = new MockFiller();
     final ValueQueue<String> vq =
         new ValueQueue<String>(10, 0.1f, 30000, 1,
             SyncGenerationPolicy.ALL, filler);
     // Trigger a prefill (1) and an async refill (10)
-    Assert.assertEquals("test", vq.getNext("k1"));
-    Assert.assertEquals(1, filler.getTop().num);
+    assertEquals("test", vq.getNext("k1"));
+    assertEquals(1, filler.getTop().num);
 
     // Wait for the async task to finish
     waitForRefill(vq, "k1", 10);
     // Refill task should add 10 values to get to a full queue (1 produced by
     // the prefill to the low watermark, 1 consumed by getNext())
-    Assert.assertEquals(10, filler.getTop().num);
+    assertEquals(10, filler.getTop().num);
 
     // Drain completely, no further refills triggered
     vq.drain("k1");
@@ -237,114 +246,113 @@ public class TestValueQueue {
     } catch (TimeoutException ignored) {
       // This is the correct outcome - no refill is expected
     }
-    Assert.assertNull(filler.getTop());
+    assertNull(filler.getTop());
 
     // Synchronous call:
     // 1. Synchronously fill returned list
     // 2. Start another async task to fill the queue in the cache
-    Assert.assertEquals("Failed in sync call.", 10,
-        vq.getAtMost("k1", 10).size());
-    Assert.assertEquals("Sync call filler got wrong number.", 10,
-        filler.getTop().num);
+    assertEquals(10, vq.getAtMost("k1", 10).size(), "Failed in sync call.");
+    assertEquals(10, filler.getTop().num, "Sync call filler got wrong number.");
 
     // Wait for the async task to finish
     waitForRefill(vq, "k1", 10);
     // Refill task should add 10 values to get to a full queue
-    Assert.assertEquals("Failed in async call.", 10, filler.getTop().num);
+    assertEquals(10, filler.getTop().num, "Failed in async call.");
 
     // Drain completely after filled by the async thread
     vq.drain("k1");
-    Assert.assertEquals("Failed to drain completely after async.", 0,
-        vq.getSize("k1"));
+    assertEquals(0, vq.getSize("k1"), "Failed to drain completely after async.");
 
     // Synchronous call
-    Assert.assertEquals("Failed to get all 19.", 19,
-        vq.getAtMost("k1", 19).size());
-    Assert.assertEquals("Failed in sync call.", 19, filler.getTop().num);
+    assertEquals(19, vq.getAtMost("k1", 19).size(), "Failed to get all 19.");
+    assertEquals(19, filler.getTop().num, "Failed in sync call.");
     vq.shutdown();
   }
 
   /**
    * Verify getAtMost when SyncGeneration Policy = ALL
    */
-  @Test(timeout=30000)
+  @Test
+  @Timeout(value = 30)
   public void testgetAtMostPolicyATLEAST_ONE() throws Exception {
     MockFiller filler = new MockFiller();
     ValueQueue<String> vq =
         new ValueQueue<String>(10, 0.3f, 30000, 1,
             SyncGenerationPolicy.ATLEAST_ONE, filler);
     // Trigger a prefill (3) and an async refill (8)
-    Assert.assertEquals("test", vq.getNext("k1"));
-    Assert.assertEquals(3, filler.getTop().num);
+    assertEquals("test", vq.getNext("k1"));
+    assertEquals(3, filler.getTop().num);
 
     // Wait for the async task to finish
     waitForRefill(vq, "k1", 10);
     // Refill task should add 8 values to get to a full queue (3 produced by
     // the prefill to the low watermark, 1 consumed by getNext())
-    Assert.assertEquals("Failed in async call.", 8, filler.getTop().num);
+    assertEquals(8, filler.getTop().num, "Failed in async call.");
 
     // Drain completely, no further refills triggered
     vq.drain("k1");
 
     // Queue is empty, sync will return a single value and trigger a refill
-    Assert.assertEquals(1, vq.getAtMost("k1", 10).size());
-    Assert.assertEquals(1, filler.getTop().num);
+    assertEquals(1, vq.getAtMost("k1", 10).size());
+    assertEquals(1, filler.getTop().num);
 
     // Wait for the async task to finish
     waitForRefill(vq, "k1", 10);
     // Refill task should add 10 values to get to a full queue
-    Assert.assertEquals("Failed in async call.", 10, filler.getTop().num);
+    assertEquals(10, filler.getTop().num, "Failed in async call.");
     vq.shutdown();
   }
 
   /**
    * Verify getAtMost when SyncGeneration Policy = LOW_WATERMARK
    */
-  @Test(timeout=30000)
+  @Test
+  @Timeout(value = 30)
   public void testgetAtMostPolicyLOW_WATERMARK() throws Exception {
     MockFiller filler = new MockFiller();
     ValueQueue<String> vq =
         new ValueQueue<String>(10, 0.3f, 30000, 1,
             SyncGenerationPolicy.LOW_WATERMARK, filler);
     // Trigger a prefill (3) and an async refill (8)
-    Assert.assertEquals("test", vq.getNext("k1"));
-    Assert.assertEquals(3, filler.getTop().num);
+    assertEquals("test", vq.getNext("k1"));
+    assertEquals(3, filler.getTop().num);
 
     // Wait for the async task to finish
     waitForRefill(vq, "k1", 10);
     // Refill task should add 8 values to get to a full queue (3 produced by
     // the prefill to the low watermark, 1 consumed by getNext())
-    Assert.assertEquals("Failed in async call.", 8, filler.getTop().num);
+    assertEquals(8, filler.getTop().num, "Failed in async call.");
 
     // Drain completely, no further refills triggered
     vq.drain("k1");
 
     // Queue is empty, sync will return 3 values and trigger a refill
-    Assert.assertEquals(3, vq.getAtMost("k1", 10).size());
-    Assert.assertEquals(3, filler.getTop().num);
+    assertEquals(3, vq.getAtMost("k1", 10).size());
+    assertEquals(3, filler.getTop().num);
 
     // Wait for the async task to finish
     waitForRefill(vq, "k1", 10);
     // Refill task should add 10 values to get to a full queue
-    Assert.assertEquals("Failed in async call.", 10, filler.getTop().num);
+    assertEquals(10, filler.getTop().num, "Failed in async call.");
     vq.shutdown();
   }
 
-  @Test(timeout=30000)
+  @Test
+  @Timeout(value = 30)
   public void testDrain() throws Exception {
     MockFiller filler = new MockFiller();
     ValueQueue<String> vq =
         new ValueQueue<String>(10, 0.1f, 30000, 1,
             SyncGenerationPolicy.ALL, filler);
     // Trigger a prefill (1) and an async refill (10)
-    Assert.assertEquals("test", vq.getNext("k1"));
-    Assert.assertEquals(1, filler.getTop().num);
+    assertEquals("test", vq.getNext("k1"));
+    assertEquals(1, filler.getTop().num);
 
     // Wait for the async task to finish
     waitForRefill(vq, "k1", 10);
     // Refill task should add 10 values to get to a full queue (1 produced by
     // the prefill to the low watermark, 1 consumed by getNext())
-    Assert.assertEquals(10, filler.getTop().num);
+    assertEquals(10, filler.getTop().num);
 
     // Drain completely, no further refills triggered
     vq.drain("k1");
@@ -355,7 +363,7 @@ public class TestValueQueue {
     } catch (TimeoutException ignored) {
       // This is the correct outcome - no refill is expected
     }
-    Assert.assertNull(filler.getTop());
+    assertNull(filler.getTop());
     vq.shutdown();
   }
 

+ 8 - 12
hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/crypto/key/kms/TestKMSClientProvider.java

@@ -24,10 +24,9 @@ import org.apache.hadoop.security.SecurityUtil;
 import org.apache.hadoop.security.token.Token;
 import org.apache.hadoop.security.token.delegation.web.DelegationTokenAuthenticatedURL;
 import org.apache.hadoop.test.GenericTestUtils;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.Timeout;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.Timeout;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.slf4j.event.Level;
@@ -36,16 +35,16 @@ import java.io.IOException;
 import java.net.URI;
 import java.net.URISyntaxException;
 import java.net.URL;
-import java.util.concurrent.TimeUnit;
 
 import static org.apache.hadoop.crypto.key.kms.KMSDelegationToken.TOKEN_KIND;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
 
 /**
  * Unit test for {@link KMSClientProvider} class.
  */
+@Timeout(60)
 public class TestKMSClientProvider {
 
   public static final Logger LOG =
@@ -57,14 +56,11 @@ public class TestKMSClientProvider {
   private final String providerUriString = "kms://https@host:16000/kms";
   private final String oldTokenService = "host:16000";
 
-  @Rule
-  public Timeout globalTimeout = new Timeout(60000, TimeUnit.MILLISECONDS);
-
   {
     GenericTestUtils.setLogLevel(KMSClientProvider.LOG, Level.TRACE);
   }
 
-  @Before
+  @BeforeEach
   public void setup() {
     SecurityUtil.setTokenServiceUseIp(false);
     token.setKind(TOKEN_KIND);
@@ -109,7 +105,7 @@ public class TestKMSClientProvider {
       creds.addToken(token.getService(), token);
       creds.addToken(oldToken.getService(), oldToken);
       final Token t = kp.selectDelegationToken(creds);
-      assertEquals("new token should be selected when both exist", token, t);
+      assertEquals(token, t, "new token should be selected when both exist");
     } finally {
       kp.close();
     }

+ 11 - 16
hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/crypto/key/kms/TestLoadBalancingKMSClientProvider.java

@@ -20,10 +20,10 @@ package org.apache.hadoop.crypto.key.kms;
 import static org.apache.hadoop.crypto.key.KeyProviderCryptoExtension.EncryptedKeyVersion;
 import static org.apache.hadoop.crypto.key.kms.KMSDelegationToken.TOKEN_KIND;
 import static org.apache.hadoop.test.LambdaTestUtils.intercept;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotEquals;
-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.assertNotEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.fail;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 import static org.mockito.Mockito.verify;
@@ -42,7 +42,6 @@ import java.util.Arrays;
 import java.util.Collections;
 import java.util.HashSet;
 import java.util.List;
-import java.util.concurrent.TimeUnit;
 
 import javax.net.ssl.SSLException;
 import javax.net.ssl.SSLHandshakeException;
@@ -61,19 +60,15 @@ import org.apache.hadoop.security.UserGroupInformation;
 import org.apache.hadoop.security.authentication.client.AuthenticationException;
 import org.apache.hadoop.security.authorize.AuthorizationException;
 import org.apache.hadoop.security.token.Token;
-import org.junit.BeforeClass;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.Timeout;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.Timeout;
 import org.mockito.Mockito;
 
-
+@Timeout(30)
 public class TestLoadBalancingKMSClientProvider {
 
-  @Rule
-  public Timeout testTimeout = new Timeout(30, TimeUnit.SECONDS);
-
-  @BeforeClass
+  @BeforeAll
   public static void setup() throws IOException {
     SecurityUtil.setTokenServiceUseIp(false);
   }
@@ -956,9 +951,9 @@ public class TestLoadBalancingKMSClientProvider {
           }
         });
     // make sure getActualUgi() returns the current user, not login user.
-    assertEquals(
+    assertEquals(ugi, actualUgi,
         "testTokenSelectionWithConf() should return the" +
-            " current user, not login user", ugi, actualUgi);
+        " current user, not login user");
   }
 
   @Test

+ 12 - 6
hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/crypto/random/TestOpensslSecureRandom.java

@@ -19,11 +19,13 @@ package org.apache.hadoop.crypto.random;
 
 import java.util.Arrays;
 
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.Timeout;
 
 public class TestOpensslSecureRandom {
   
-  @Test(timeout=120000)
+  @Test
+  @Timeout(value = 120)
   public void testRandomBytes() throws Exception {
     OpensslSecureRandom random = new OpensslSecureRandom();
     
@@ -56,7 +58,8 @@ public class TestOpensslSecureRandom {
    * Test will timeout if secure random implementation always returns a 
    * constant value.
    */
-  @Test(timeout=120000)
+  @Test
+  @Timeout(value = 120)
   public void testRandomInt() throws Exception {
     OpensslSecureRandom random = new OpensslSecureRandom();
     
@@ -71,7 +74,8 @@ public class TestOpensslSecureRandom {
    * Test will timeout if secure random implementation always returns a 
    * constant value.
    */
-  @Test(timeout=120000)
+  @Test
+  @Timeout(value = 120)
   public void testRandomLong() throws Exception {
     OpensslSecureRandom random = new OpensslSecureRandom();
     
@@ -86,7 +90,8 @@ public class TestOpensslSecureRandom {
    * Test will timeout if secure random implementation always returns a 
    * constant value.
    */
-  @Test(timeout=120000)
+  @Test
+  @Timeout(value = 120)
   public void testRandomFloat() throws Exception {
     OpensslSecureRandom random = new OpensslSecureRandom();
     
@@ -101,7 +106,8 @@ public class TestOpensslSecureRandom {
    * Test will timeout if secure random implementation always returns a 
    * constant value.
    */
-  @Test(timeout=120000)
+  @Test
+  @Timeout(value = 120)
   public void testRandomDouble() throws Exception {
     OpensslSecureRandom random = new OpensslSecureRandom();
     

+ 17 - 9
hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/crypto/random/TestOsSecureRandom.java

@@ -23,19 +23,22 @@ import java.util.Arrays;
 import org.apache.commons.lang3.SystemUtils;
 import org.apache.hadoop.conf.Configuration;
 
-import org.junit.Assume;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.Timeout;
+
+import static org.junit.jupiter.api.Assumptions.assumeTrue;
 
 public class TestOsSecureRandom {
 
   private static OsSecureRandom getOsSecureRandom() throws IOException {
-    Assume.assumeTrue(SystemUtils.IS_OS_LINUX);
+    assumeTrue(SystemUtils.IS_OS_LINUX);
     OsSecureRandom random = new OsSecureRandom();
     random.setConf(new Configuration());
     return random;
   }
 
-  @Test(timeout=120000)
+  @Test
+  @Timeout(value = 120)
   public void testRandomBytes() throws Exception {
     OsSecureRandom random = getOsSecureRandom();
     // len = 16
@@ -68,7 +71,8 @@ public class TestOsSecureRandom {
    * Test will timeout if secure random implementation always returns a 
    * constant value.
    */
-  @Test(timeout=120000)
+  @Test
+  @Timeout(value = 120)
   public void testRandomInt() throws Exception {
     OsSecureRandom random = getOsSecureRandom();
     
@@ -84,7 +88,8 @@ public class TestOsSecureRandom {
    * Test will timeout if secure random implementation always returns a 
    * constant value.
    */
-  @Test(timeout=120000)
+  @Test
+  @Timeout(value = 120)
   public void testRandomLong() throws Exception {
     OsSecureRandom random = getOsSecureRandom();
     
@@ -100,7 +105,8 @@ public class TestOsSecureRandom {
    * Test will timeout if secure random implementation always returns a 
    * constant value.
    */
-  @Test(timeout=120000)
+  @Test
+  @Timeout(value = 120)
   public void testRandomFloat() throws Exception {
     OsSecureRandom random = getOsSecureRandom();
     
@@ -116,7 +122,8 @@ public class TestOsSecureRandom {
    * Test will timeout if secure random implementation always returns a 
    * constant value.
    */
-  @Test(timeout=120000)
+  @Test
+  @Timeout(value = 120)
   public void testRandomDouble() throws Exception {
     OsSecureRandom random = getOsSecureRandom();
     
@@ -128,7 +135,8 @@ public class TestOsSecureRandom {
     random.close();
   }
 
-  @Test(timeout=120000)
+  @Test
+  @Timeout(value = 120)
   public void testRefillReservoir() throws Exception {
     OsSecureRandom random = getOsSecureRandom();