瀏覽代碼

HADOOP-19411. [JDK17] Upgrade JUnit from 4 to 5 in hadoop-cos. (#7640)

* HADOOP-19411. [JDK17] Upgrade JUnit from 4 to 5 in hadoop-cos.

Co-authored-by: He Xiaoqiao <hexiaoqiao@apache.org>
Reviewed-by: He Xiaoqiao <hexiaoqiao@apache.org>
Signed-off-by: Shilun Fan <slfan1989@apache.org>
slfan1989 1 周之前
父節點
當前提交
1293a0ec28

+ 4 - 4
hadoop-cloud-storage-project/hadoop-cos/src/test/java/org/apache/hadoop/fs/cosn/TestCosCredentials.java

@@ -20,7 +20,7 @@ package org.apache.hadoop.fs.cosn;
 import com.qcloud.cos.auth.COSCredentials;
 import com.qcloud.cos.auth.COSCredentials;
 import com.qcloud.cos.auth.COSCredentialsProvider;
 import com.qcloud.cos.auth.COSCredentialsProvider;
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.conf.Configuration;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
 import org.slf4j.Logger;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.slf4j.LoggerFactory;
 
 
@@ -28,8 +28,8 @@ import java.io.IOException;
 import java.net.URI;
 import java.net.URI;
 import java.net.URISyntaxException;
 import java.net.URISyntaxException;
 
 
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.fail;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.fail;
 
 
 public class TestCosCredentials {
 public class TestCosCredentials {
   private static final Logger LOG =
   private static final Logger LOG =
@@ -76,7 +76,7 @@ public class TestCosCredentials {
       COSCredentialsProvider credentialsProvider =
       COSCredentialsProvider credentialsProvider =
           CosNUtils.createCosCredentialsProviderSet(uri, configuration);
           CosNUtils.createCosCredentialsProviderSet(uri, configuration);
       COSCredentials cosCredentials = credentialsProvider.getCredentials();
       COSCredentials cosCredentials = credentialsProvider.getCredentials();
-      assertNotNull("The cos credentials obtained is null.", cosCredentials);
+      assertNotNull(cosCredentials, "The cos credentials obtained is null.");
       if (configuration.get(
       if (configuration.get(
           CosNConfigKeys.COSN_CREDENTIALS_PROVIDER).compareToIgnoreCase(
           CosNConfigKeys.COSN_CREDENTIALS_PROVIDER).compareToIgnoreCase(
           "org.apache.hadoop.fs.cosn.EnvironmentVariableCredentialsProvider")
           "org.apache.hadoop.fs.cosn.EnvironmentVariableCredentialsProvider")

+ 20 - 16
hadoop-cloud-storage-project/hadoop-cos/src/test/java/org/apache/hadoop/fs/cosn/TestCosNInputStream.java

@@ -23,11 +23,14 @@ import org.apache.hadoop.fs.FileSystem;
 import org.apache.hadoop.fs.Path;
 import org.apache.hadoop.fs.Path;
 import org.apache.hadoop.fs.contract.ContractTestUtils;
 import org.apache.hadoop.fs.contract.ContractTestUtils;
 import org.apache.hadoop.io.IOUtils;
 import org.apache.hadoop.io.IOUtils;
-import org.junit.*;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.Test;
 import org.slf4j.Logger;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.slf4j.LoggerFactory;
 
 
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertTrue;
 
 
 import java.io.IOException;
 import java.io.IOException;
 import java.util.Random;
 import java.util.Random;
@@ -43,7 +46,7 @@ public class TestCosNInputStream {
 
 
   private Path testRootDir;
   private Path testRootDir;
 
 
-  @Before
+  @BeforeEach
   public void setUp() throws IOException {
   public void setUp() throws IOException {
     Configuration configuration = new Configuration();
     Configuration configuration = new Configuration();
     this.fs = CosNTestUtils.createTestFileSystem(configuration);
     this.fs = CosNTestUtils.createTestFileSystem(configuration);
@@ -51,7 +54,7 @@ public class TestCosNInputStream {
     LOG.info("test root dir: " + this.testRootDir);
     LOG.info("test root dir: " + this.testRootDir);
   }
   }
 
 
-  @After
+  @AfterEach
   public void tearDown() throws IOException {
   public void tearDown() throws IOException {
     if (null != this.fs) {
     if (null != this.fs) {
       this.fs.delete(this.testRootDir, true);
       this.fs.delete(this.testRootDir, true);
@@ -76,9 +79,9 @@ public class TestCosNInputStream {
     for (int i = 0; i != seekTimes; i++) {
     for (int i = 0; i != seekTimes; i++) {
       long pos = fileSize / (seekTimes - i) - 1;
       long pos = fileSize / (seekTimes - i) - 1;
       inputStream.seek(pos);
       inputStream.seek(pos);
-      assertTrue("expected position at: " +
-              pos + ", but got: " + inputStream.getPos(),
-          inputStream.getPos() == pos);
+      assertTrue(inputStream.getPos() == pos,
+          "expected position at: " +
+          pos + ", but got: " + inputStream.getPos());
       LOG.info("completed seeking at pos: " + inputStream.getPos());
       LOG.info("completed seeking at pos: " + inputStream.getPos());
     }
     }
     LOG.info("begin to random position seeking test...");
     LOG.info("begin to random position seeking test...");
@@ -87,9 +90,9 @@ public class TestCosNInputStream {
       long pos = Math.abs(random.nextLong()) % fileSize;
       long pos = Math.abs(random.nextLong()) % fileSize;
       LOG.info("seeking for pos: " + pos);
       LOG.info("seeking for pos: " + pos);
       inputStream.seek(pos);
       inputStream.seek(pos);
-      assertTrue("expected position at: " +
-              pos + ", but got: " + inputStream.getPos(),
-          inputStream.getPos() == pos);
+      assertTrue(inputStream.getPos() == pos,
+          "expected position at: " +
+          pos + ", but got: " + inputStream.getPos());
       LOG.info("completed seeking at pos: " + inputStream.getPos());
       LOG.info("completed seeking at pos: " + inputStream.getPos());
     }
     }
   }
   }
@@ -110,16 +113,16 @@ public class TestCosNInputStream {
     Random random = new Random();
     Random random = new Random();
     long pos = Math.abs(random.nextLong()) % fileSize;
     long pos = Math.abs(random.nextLong()) % fileSize;
     inputStream.seek(pos);
     inputStream.seek(pos);
-    assertTrue("expected position at: " +
-            pos + ", but got: " + inputStream.getPos(),
-        inputStream.getPos() == pos);
+    assertTrue(inputStream.getPos() == pos,
+        "expected position at: " +
+        pos + ", but got: " + inputStream.getPos());
     LOG.info("completed get pos tests.");
     LOG.info("completed get pos tests.");
   }
   }
 
 
   /**
   /**
    * Method: seekToNewSource(long targetPos).
    * Method: seekToNewSource(long targetPos).
    */
    */
-  @Ignore("Not ready yet")
+  @Disabled("Not ready yet")
   public void testSeekToNewSource() throws Exception {
   public void testSeekToNewSource() throws Exception {
     LOG.info("Currently it is not supported to " +
     LOG.info("Currently it is not supported to " +
         "seek the offset in a new source.");
         "seek the offset in a new source.");
@@ -154,8 +157,9 @@ public class TestCosNInputStream {
 
 
       if (bytesRead % (1 * Unit.MB) == 0) {
       if (bytesRead % (1 * Unit.MB) == 0) {
         int available = inputStream.available();
         int available = inputStream.available();
-        assertTrue("expected remaining: " + (fileSize - bytesRead) +
-            " but got: " + available, (fileSize - bytesRead) == available);
+        assertTrue((fileSize - bytesRead) == available,
+            "expected remaining: " + (fileSize - bytesRead) +
+            " but got: " + available);
         LOG.info("Bytes read: " +
         LOG.info("Bytes read: " +
             Math.round((double) bytesRead / Unit.MB) + "MB");
             Math.round((double) bytesRead / Unit.MB) + "MB");
       }
       }

+ 7 - 10
hadoop-cloud-storage-project/hadoop-cos/src/test/java/org/apache/hadoop/fs/cosn/TestCosNOutputStream.java

@@ -21,11 +21,10 @@ import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.fs.FileSystem;
 import org.apache.hadoop.fs.FileSystem;
 import org.apache.hadoop.fs.Path;
 import org.apache.hadoop.fs.Path;
 import org.apache.hadoop.fs.contract.ContractTestUtils;
 import org.apache.hadoop.fs.contract.ContractTestUtils;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.Before;
-import org.junit.After;
-import org.junit.rules.Timeout;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.Timeout;
 
 
 import java.io.IOException;
 import java.io.IOException;
 
 
@@ -34,14 +33,12 @@ import java.io.IOException;
  * <p>
  * <p>
  * If the test.fs.cosn.name property is not set, all test case will fail.
  * If the test.fs.cosn.name property is not set, all test case will fail.
  */
  */
+@Timeout(3600)
 public class TestCosNOutputStream {
 public class TestCosNOutputStream {
   private FileSystem fs;
   private FileSystem fs;
   private Path testRootDir;
   private Path testRootDir;
 
 
-  @Rule
-  public Timeout timeout = new Timeout(3600 * 1000);
-
-  @Before
+  @BeforeEach
   public void setUp() throws Exception {
   public void setUp() throws Exception {
     Configuration configuration = new Configuration();
     Configuration configuration = new Configuration();
     configuration.setInt(
     configuration.setInt(
@@ -53,7 +50,7 @@ public class TestCosNOutputStream {
     this.testRootDir = new Path("/test");
     this.testRootDir = new Path("/test");
   }
   }
 
 
-  @After
+  @AfterEach
   public void tearDown() throws Exception {
   public void tearDown() throws Exception {
   }
   }