浏览代码

HADOOP-19421. [JDK17] Upgrade JUnit from 4 to 5 in hadoop-aliyun. (#7634)

* HADOOP-19421. [JDK17] Upgrade JUnit from 4 to 5 in hadoop-aliyun.

Co-authored-by: Chris Nauroth <cnauroth@apache.org>
Reviewed-by: Chris Nauroth <cnauroth@apache.org>
Signed-off-by: Shilun Fan <slfan1989@apache.org>
slfan1989 1 月之前
父节点
当前提交
26a0fdaa75

+ 8 - 7
hadoop-tools/hadoop-aliyun/src/test/java/org/apache/hadoop/fs/aliyun/oss/ITAliyunOSSSignatureV4.java

@@ -21,8 +21,8 @@ package org.apache.hadoop.fs.aliyun.oss;
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.fs.FileStatus;
 import org.apache.hadoop.fs.Path;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -33,8 +33,9 @@ import static org.apache.hadoop.fs.aliyun.oss.Constants.REGION_KEY;
 import static org.apache.hadoop.fs.aliyun.oss.Constants.SIGNATURE_VERSION_KEY;
 import static org.apache.hadoop.fs.contract.ContractTestUtils.createFile;
 import static org.apache.hadoop.fs.contract.ContractTestUtils.dataset;
-import static org.junit.Assert.*;
-import static org.junit.Assume.assumeNotNull;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assumptions.assumeTrue;
 
 /**
  * Tests Aliyun OSS system.
@@ -45,7 +46,7 @@ public class ITAliyunOSSSignatureV4 {
   private URI testURI;
   private Path testFile = new Path("ITAliyunOSSSignatureV4/atestr");
 
-  @Before
+  @BeforeEach
   public void setUp() throws Exception {
     conf = new Configuration();
     String bucketUri = conf.get("test.fs.oss.name");
@@ -59,7 +60,7 @@ public class ITAliyunOSSSignatureV4 {
     conf.set(REGION_KEY, "cn-hongkong");
     AliyunOSSFileSystem fs = new AliyunOSSFileSystem();
     fs.initialize(testURI, conf);
-    assumeNotNull(fs);
+    assumeTrue(fs != null);
 
     createFile(fs, testFile, true, dataset(256, 0, 255));
     FileStatus status = fs.getFileStatus(testFile);
@@ -71,7 +72,7 @@ public class ITAliyunOSSSignatureV4 {
   public void testDefaultSignatureVersion() throws IOException {
     AliyunOSSFileSystem fs = new AliyunOSSFileSystem();
     fs.initialize(testURI, conf);
-    assumeNotNull(fs);
+    assumeTrue(fs != null);
 
     Path testFile2 = new Path("/test/atestr");
     createFile(fs, testFile2, true, dataset(256, 0, 255));

+ 1 - 1
hadoop-tools/hadoop-aliyun/src/test/java/org/apache/hadoop/fs/aliyun/oss/TestAliyunCredentials.java

@@ -25,7 +25,7 @@ import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.fs.aliyun.oss.contract.AliyunOSSContract;
 import org.apache.hadoop.fs.contract.AbstractFSContract;
 import org.apache.hadoop.fs.contract.AbstractFSContractTestBase;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
 
 import java.io.IOException;
 import java.lang.reflect.InvocationTargetException;

+ 42 - 47
hadoop-tools/hadoop-aliyun/src/test/java/org/apache/hadoop/fs/aliyun/oss/TestAliyunOSSBlockOutputStream.java

@@ -26,11 +26,10 @@ import org.apache.hadoop.fs.aliyun.oss.OSSDataBlocks.ByteBufferBlockFactory;
 import org.apache.hadoop.fs.aliyun.oss.statistics.BlockOutputStreamStatistics;
 import org.apache.hadoop.fs.contract.ContractTestUtils;
 import org.apache.hadoop.test.GenericTestUtils;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.Timeout;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.Timeout;
 
 import java.io.File;
 import java.io.IOException;
@@ -48,16 +47,17 @@ import static org.apache.hadoop.fs.aliyun.oss.Constants.FAST_UPLOAD_BYTEBUFFER_D
 import static org.apache.hadoop.fs.aliyun.oss.Constants.MULTIPART_UPLOAD_PART_SIZE_DEFAULT;
 import static org.apache.hadoop.fs.aliyun.oss.Constants.MULTIPART_UPLOAD_PART_SIZE_KEY;
 import static org.apache.hadoop.fs.contract.ContractTestUtils.IO_CHUNK_BUFFER_SIZE;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
 
 /**
  * Tests regular and multi-part upload functionality for
  * AliyunOSSBlockOutputStream.
  */
+@Timeout(30 * 60)
 public class TestAliyunOSSBlockOutputStream {
   private FileSystem fs;
   private static final int PART_SIZE = 1024 * 1024;
@@ -65,10 +65,7 @@ public class TestAliyunOSSBlockOutputStream {
       AliyunOSSTestUtils.generateUniqueTestPath();
   private static final long MEMORY_LIMIT = 10 * 1024 * 1024;
 
-  @Rule
-  public Timeout testTimeout = new Timeout(30 * 60 * 1000);
-
-  @Before
+  @BeforeEach
   public void setUp() throws Exception {
     Configuration conf = new Configuration();
     conf.setInt(MULTIPART_UPLOAD_PART_SIZE_KEY, PART_SIZE);
@@ -79,7 +76,7 @@ public class TestAliyunOSSBlockOutputStream {
     fs = AliyunOSSTestUtils.createTestFileSystem(conf);
   }
 
-  @After
+  @AfterEach
   public void tearDown() throws Exception {
     if (fs != null) {
       fs.delete(new Path(testRootPath), true);
@@ -237,8 +234,8 @@ public class TestAliyunOSSBlockOutputStream {
         OSSDataBlocks.ByteBufferBlockFactory
             blockFactory = (OSSDataBlocks.ByteBufferBlockFactory)
                 ((AliyunOSSFileSystem)fs).getBlockFactory();
-        assertEquals("outstanding buffers in " + blockFactory,
-            0, blockFactory.getOutstandingBufferCount());
+        assertEquals(0, blockFactory.getOutstandingBufferCount(),
+            "outstanding buffers in " + blockFactory);
       }
     }
     BlockOutputStreamStatistics statistics =
@@ -258,7 +255,7 @@ public class TestAliyunOSSBlockOutputStream {
   public void testDirectoryAllocator() throws Throwable {
     Configuration conf = fs.getConf();
     File tmp = AliyunOSSUtils.createTmpFileForWrite("out-", 1024, conf);
-    assertTrue("not found: " + tmp, tmp.exists());
+    assertTrue(tmp.exists(), "not found: " + tmp);
     tmp.delete();
 
     // tmp should not in DeleteOnExitHook
@@ -268,9 +265,9 @@ public class TestAliyunOSSBlockOutputStream {
       field.setAccessible(true);
       String name = field.getName();
       LinkedHashSet<String> files = (LinkedHashSet<String>)field.get(name);
-      assertTrue("in DeleteOnExitHook", files.isEmpty());
-      assertFalse("in DeleteOnExitHook",
-          (new ArrayList<>(files)).contains(tmp.getPath()));
+      assertTrue(files.isEmpty(), "in DeleteOnExitHook");
+      assertFalse(
+          (new ArrayList<>(files)).contains(tmp.getPath()), "in DeleteOnExitHook");
     } catch (Exception e) {
       e.printStackTrace();
     }
@@ -290,8 +287,8 @@ public class TestAliyunOSSBlockOutputStream {
     tmp1.delete();
     File tmp2 = AliyunOSSUtils.createTmpFileForWrite("out-", 1024, conf);
     tmp2.delete();
-    assertNotEquals("round robin not working",
-        tmp1.getParent(), tmp2.getParent());
+    assertNotEquals(tmp1.getParent(), tmp2.getParent(),
+        "round robin not working");
   }
 
   @Test
@@ -301,18 +298,17 @@ public class TestAliyunOSSBlockOutputStream {
       int limit = 128;
       OSSDataBlocks.ByteBufferBlockFactory.ByteBufferBlock block
           = factory.create(1, limit, null);
-      assertEquals("outstanding buffers in " + factory,
-          1, factory.getOutstandingBufferCount());
+      assertEquals(1, factory.getOutstandingBufferCount(),
+          "outstanding buffers in " + factory);
 
       byte[] buffer = ContractTestUtils.toAsciiByteArray("test data");
       int bufferLen = buffer.length;
       block.write(buffer, 0, bufferLen);
       assertEquals(bufferLen, block.dataSize());
-      assertEquals("capacity in " + block,
-          limit - bufferLen, block.remainingCapacity());
-      assertTrue("hasCapacity(64) in " + block, block.hasCapacity(64));
-      assertTrue("No capacity in " + block,
-          block.hasCapacity(limit - bufferLen));
+      assertEquals(limit - bufferLen, block.remainingCapacity(),
+          "capacity in " + block);
+      assertTrue(block.hasCapacity(64), "hasCapacity(64) in " + block);
+      assertTrue(block.hasCapacity(limit - bufferLen), "No capacity in " + block);
 
       // now start the write
       OSSDataBlocks.BlockUploadData blockUploadData = block.startUpload();
@@ -320,18 +316,18 @@ public class TestAliyunOSSBlockOutputStream {
           stream =
           (ByteBufferBlockFactory.ByteBufferBlock.ByteBufferInputStream)
               blockUploadData.getUploadStream();
-      assertTrue("Mark not supported in " + stream, stream.markSupported());
-      assertTrue("!hasRemaining() in " + stream, stream.hasRemaining());
+      assertTrue(stream.markSupported(), "Mark not supported in " + stream);
+      assertTrue(stream.hasRemaining(), "!hasRemaining() in " + stream);
 
       int expected = bufferLen;
-      assertEquals("wrong available() in " + stream,
-          expected, stream.available());
+      assertEquals(expected, stream.available(),
+          "wrong available() in " + stream);
 
       assertEquals('t', stream.read());
       stream.mark(limit);
       expected--;
-      assertEquals("wrong available() in " + stream,
-          expected, stream.available());
+      assertEquals(expected, stream.available(),
+          "wrong available() in " + stream);
 
       // read into a byte array with an offset
       int offset = 5;
@@ -340,8 +336,8 @@ public class TestAliyunOSSBlockOutputStream {
       assertEquals('e', in[offset]);
       assertEquals('s', in[offset + 1]);
       expected -= 2;
-      assertEquals("wrong available() in " + stream,
-          expected, stream.available());
+      assertEquals(expected, stream.available(),
+          "wrong available() in " + stream);
 
       // read to end
       byte[] remainder = new byte[limit];
@@ -353,9 +349,8 @@ public class TestAliyunOSSBlockOutputStream {
       assertEquals(expected, index);
       assertEquals('a', remainder[--index]);
 
-      assertEquals("wrong available() in " + stream,
-          0, stream.available());
-      assertTrue("hasRemaining() in " + stream, !stream.hasRemaining());
+      assertEquals(0, stream.available(), "wrong available() in " + stream);
+      assertTrue(!stream.hasRemaining(), "hasRemaining() in " + stream);
 
       // go the mark point
       stream.reset();
@@ -363,14 +358,14 @@ public class TestAliyunOSSBlockOutputStream {
 
       // when the stream is closed, the data should be returned
       stream.close();
-      assertEquals("outstanding buffers in " + factory,
-          1, factory.getOutstandingBufferCount());
+      assertEquals(1, factory.getOutstandingBufferCount(),
+          "outstanding buffers in " + factory);
       block.close();
-      assertEquals("outstanding buffers in " + factory,
-          0, factory.getOutstandingBufferCount());
+      assertEquals(0, factory.getOutstandingBufferCount(),
+          "outstanding buffers in " + factory);
       stream.close();
-      assertEquals("outstanding buffers in " + factory,
-          0, factory.getOutstandingBufferCount());
+      assertEquals(0, factory.getOutstandingBufferCount(),
+          "outstanding buffers in " + factory);
     }
   }
 

+ 30 - 31
hadoop-tools/hadoop-aliyun/src/test/java/org/apache/hadoop/fs/aliyun/oss/TestAliyunOSSFileSystemContract.java

@@ -26,20 +26,19 @@ import org.apache.hadoop.fs.FileSystemContractBaseTest;
 import org.apache.hadoop.fs.Path;
 
 import org.apache.hadoop.security.UserGroupInformation;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
 
 import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.util.Arrays;
 
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assume.assumeFalse;
-import static org.junit.Assume.assumeNotNull;
-import static org.junit.Assume.assumeTrue;
+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.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assumptions.assumeFalse;
+import static org.junit.jupiter.api.Assumptions.assumeTrue;
 
 /**
  * Tests a live Aliyun OSS system.
@@ -52,11 +51,11 @@ public class TestAliyunOSSFileSystemContract
   private static Path testRootPath =
       new Path(AliyunOSSTestUtils.generateUniqueTestPath());
 
-  @Before
+  @BeforeEach
   public void setUp() throws Exception {
     Configuration conf = new Configuration();
     fs = AliyunOSSTestUtils.createTestFileSystem(conf);
-    assumeNotNull(fs);
+    assumeTrue(fs != null);
   }
 
   @Override
@@ -75,8 +74,8 @@ public class TestAliyunOSSFileSystemContract
     fs.getFileStatus(super.path("/"));
     //this catches overrides of the base exists() method that don't
     //use getFileStatus() as an existence probe
-    assertTrue("FileSystem.exists() fails for root",
-        fs.exists(super.path("/")));
+    assertTrue(
+        fs.exists(super.path("/")), "FileSystem.exists() fails for root");
   }
 
   @Test
@@ -91,7 +90,7 @@ public class TestAliyunOSSFileSystemContract
   public void testListStatus() throws IOException {
     Path file = this.path("/test/hadoop/file");
     this.createFile(file);
-    assertTrue("File exists", this.fs.exists(file));
+    assertTrue(this.fs.exists(file), "File exists");
     FileStatus fs = this.fs.getFileStatus(file);
     assertEquals(fs.getOwner(),
         UserGroupInformation.getCurrentUser().getShortUserName());
@@ -105,7 +104,7 @@ public class TestAliyunOSSFileSystemContract
     for (int i = 1; i <= 30; ++i) {
       this.createFile(new Path(file, "sub" + i));
     }
-    assertTrue("File exists", this.fs.exists(file));
+    assertTrue(this.fs.exists(file), "File exists");
     FileStatus fs = this.fs.getFileStatus(file);
     assertEquals(fs.getOwner(),
         UserGroupInformation.getCurrentUser().getShortUserName());
@@ -128,16 +127,16 @@ public class TestAliyunOSSFileSystemContract
     Path subdir = this.path("/test/hadoop/subdir");
     this.createFile(file);
 
-    assertTrue("Created subdir", this.fs.mkdirs(subdir));
-    assertTrue("File exists", this.fs.exists(file));
-    assertTrue("Parent dir exists", this.fs.exists(parentDir));
-    assertTrue("Subdir exists", this.fs.exists(subdir));
+    assertTrue(this.fs.mkdirs(subdir), "Created subdir");
+    assertTrue(this.fs.exists(file), "File exists");
+    assertTrue(this.fs.exists(parentDir), "Parent dir exists");
+    assertTrue(this.fs.exists(subdir), "Subdir exists");
 
-    assertTrue("Deleted subdir", this.fs.delete(subdir, true));
-    assertTrue("Parent should exist", this.fs.exists(parentDir));
+    assertTrue(this.fs.delete(subdir, true), "Deleted subdir");
+    assertTrue(this.fs.exists(parentDir), "Parent should exist");
 
-    assertTrue("Deleted file", this.fs.delete(file, false));
-    assertTrue("Parent should exist", this.fs.exists(parentDir));
+    assertTrue(this.fs.delete(file, false), "Deleted file");
+    assertTrue(this.fs.exists(parentDir), "Parent should exist");
   }
 
 
@@ -354,20 +353,20 @@ public class TestAliyunOSSFileSystemContract
   public void testGetFileStatusFileAndDirectory() throws Exception {
     Path filePath = this.path("/test/oss/file1");
     this.createFile(filePath);
-    assertTrue("Should be file", this.fs.getFileStatus(filePath).isFile());
-    assertFalse("Should not be directory",
-        this.fs.getFileStatus(filePath).isDirectory());
+    assertTrue(this.fs.getFileStatus(filePath).isFile(), "Should be file");
+    assertFalse(
+        this.fs.getFileStatus(filePath).isDirectory(), "Should not be directory");
 
     Path dirPath = this.path("/test/oss/dir");
     this.fs.mkdirs(dirPath);
-    assertTrue("Should be directory",
-        this.fs.getFileStatus(dirPath).isDirectory());
-    assertFalse("Should not be file", this.fs.getFileStatus(dirPath).isFile());
+    assertTrue(
+        this.fs.getFileStatus(dirPath).isDirectory(), "Should be directory");
+    assertFalse(this.fs.getFileStatus(dirPath).isFile(), "Should not be file");
 
     Path parentPath = this.path("/test/oss");
     for (FileStatus fileStatus: fs.listStatus(parentPath)) {
-      assertTrue("file and directory should be new",
-          fileStatus.getModificationTime() > 0L);
+      assertTrue(
+          fileStatus.getModificationTime() > 0L, "file and directory should be new");
     }
   }
 

+ 18 - 18
hadoop-tools/hadoop-aliyun/src/test/java/org/apache/hadoop/fs/aliyun/oss/TestAliyunOSSFileSystemStore.java

@@ -24,10 +24,10 @@ import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.fs.Path;
 import org.apache.hadoop.fs.contract.ContractTestUtils;
 
-import org.junit.After;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
 
 import java.io.BufferedInputStream;
 import java.io.BufferedOutputStream;
@@ -43,10 +43,10 @@ import java.util.ArrayList;
 import java.util.List;
 
 import static org.apache.hadoop.fs.aliyun.oss.Constants.MAX_PAGING_KEYS_DEFAULT;
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assume.assumeNotNull;
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assumptions.assumeTrue;
 
 /**
  * Test the bridging logic between Hadoop's abstract filesystem and
@@ -57,7 +57,7 @@ public class TestAliyunOSSFileSystemStore {
   private AliyunOSSFileSystemStore store;
   private AliyunOSSFileSystem fs;
 
-  @Before
+  @BeforeEach
   public void setUp() throws Exception {
     conf = new Configuration();
     fs = new AliyunOSSFileSystem();
@@ -65,7 +65,7 @@ public class TestAliyunOSSFileSystemStore {
     store = fs.getStore();
   }
 
-  @After
+  @AfterEach
   public void tearDown() throws Exception {
     try {
       store.purge("test");
@@ -75,12 +75,12 @@ public class TestAliyunOSSFileSystemStore {
     }
   }
 
-  @BeforeClass
+  @BeforeAll
   public static void checkSettings() throws Exception {
     Configuration conf = new Configuration();
-    assumeNotNull(conf.get(Constants.ACCESS_KEY_ID));
-    assumeNotNull(conf.get(Constants.ACCESS_KEY_SECRET));
-    assumeNotNull(conf.get("test.fs.oss.name"));
+    assumeTrue(conf.get(Constants.ACCESS_KEY_ID) != null);
+    assumeTrue(conf.get(Constants.ACCESS_KEY_SECRET) != null);
+    assumeTrue(conf.get("test.fs.oss.name") != null);
   }
 
   protected void writeRenameReadCompare(Path path, long len)
@@ -94,7 +94,7 @@ public class TestAliyunOSSFileSystemStore {
     out.flush();
     out.close();
 
-    assertTrue("Exists", fs.exists(path));
+    assertTrue(fs.exists(path), "Exists");
 
     ObjectMetadata srcMeta = fs.getStore().getObjectMetadata(
         path.toUri().getPath().substring(1));
@@ -102,7 +102,7 @@ public class TestAliyunOSSFileSystemStore {
     Path copyPath = path.suffix(".copy");
     fs.rename(path, copyPath);
 
-    assertTrue("Copy exists", fs.exists(copyPath));
+    assertTrue(fs.exists(copyPath), "Copy exists");
     // file type should not change
     ObjectMetadata dstMeta = fs.getStore().getObjectMetadata(
         copyPath.toUri().getPath().substring(1));
@@ -117,8 +117,8 @@ public class TestAliyunOSSFileSystemStore {
     }
     in.close();
 
-    assertEquals("Copy length matches original", len, copyLen);
-    assertArrayEquals("Digests match", digest.digest(), digest2.digest());
+    assertEquals(len, copyLen, "Copy length matches original");
+    assertArrayEquals(digest.digest(), digest2.digest(), "Digests match");
   }
 
   @Test

+ 25 - 29
hadoop-tools/hadoop-aliyun/src/test/java/org/apache/hadoop/fs/aliyun/oss/TestAliyunOSSInputStream.java

@@ -25,23 +25,23 @@ import org.apache.hadoop.fs.Path;
 import org.apache.hadoop.fs.contract.ContractTestUtils;
 import org.apache.hadoop.io.IOUtils;
 import org.apache.hadoop.fs.FileStatus;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.Timeout;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.Timeout;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import java.util.Random;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
 
 /**
  * Tests basic functionality for AliyunOSSInputStream, including seeking and
  * reading files.
  */
+@Timeout(30 * 60)
 public class TestAliyunOSSInputStream {
 
   private FileSystem fs;
@@ -52,16 +52,13 @@ public class TestAliyunOSSInputStream {
   private static String testRootPath =
       AliyunOSSTestUtils.generateUniqueTestPath();
 
-  @Rule
-  public Timeout testTimeout = new Timeout(30 * 60 * 1000);
-
-  @Before
+  @BeforeEach
   public void setUp() throws Exception {
     Configuration conf = new Configuration();
     fs = AliyunOSSTestUtils.createTestFileSystem(conf);
   }
 
-  @After
+  @AfterEach
   public void tearDown() throws Exception {
     if (fs != null) {
       fs.delete(new Path(testRootPath), true);
@@ -91,8 +88,8 @@ public class TestAliyunOSSInputStream {
       long pos = size / (seekTimes - i) - 1;
       LOG.info("begin seeking for pos: " + pos);
       instream.seek(pos);
-      assertTrue("expected position at:" + pos + ", but got:"
-          + instream.getPos(), instream.getPos() == pos);
+      assertTrue(instream.getPos() == pos, "expected position at:" + pos + ", but got:"
+          + instream.getPos());
       LOG.info("completed seeking at pos: " + instream.getPos());
     }
     LOG.info("random position seeking test...:");
@@ -101,8 +98,8 @@ public class TestAliyunOSSInputStream {
       long pos = Math.abs(rand.nextLong()) % size;
       LOG.info("begin seeking for pos: " + pos);
       instream.seek(pos);
-      assertTrue("expected position at:" + pos + ", but got:"
-          + instream.getPos(), instream.getPos() == pos);
+      assertTrue(instream.getPos() == pos, "expected position at:" + pos + ", but got:"
+          + instream.getPos());
       LOG.info("completed seeking at pos: " + instream.getPos());
     }
     IOUtils.closeStream(instream);
@@ -119,19 +116,18 @@ public class TestAliyunOSSInputStream {
     FSDataInputStream fsDataInputStream = this.fs.open(smallSeekFile);
     AliyunOSSInputStream in =
         (AliyunOSSInputStream)fsDataInputStream.getWrappedStream();
-    assertTrue("expected position at:" + 0 + ", but got:"
-        + fsDataInputStream.getPos(), fsDataInputStream.getPos() == 0);
+    assertTrue(fsDataInputStream.getPos() == 0, "expected position at:" + 0 + ", but got:"
+        + fsDataInputStream.getPos());
 
-    assertTrue("expected position at:"
+    assertTrue(in.getExpectNextPos() == Constants.MULTIPART_DOWNLOAD_SIZE_DEFAULT,
+        "expected position at:"
         + Constants.MULTIPART_DOWNLOAD_SIZE_DEFAULT + ", but got:"
-        + in.getExpectNextPos(),
-        in.getExpectNextPos() == Constants.MULTIPART_DOWNLOAD_SIZE_DEFAULT);
+        + in.getExpectNextPos());
     fsDataInputStream.seek(4 * 1024 * 1024);
-    assertTrue("expected position at:" + 4 * 1024 * 1024
+    assertTrue(in.getExpectNextPos() == 4 * 1024 * 1024
+        + Constants.MULTIPART_DOWNLOAD_SIZE_DEFAULT, "expected position at:" + 4 * 1024 * 1024
         + Constants.MULTIPART_DOWNLOAD_SIZE_DEFAULT + ", but got:"
-        + in.getExpectNextPos(),
-        in.getExpectNextPos() == 4 * 1024 * 1024
-        + Constants.MULTIPART_DOWNLOAD_SIZE_DEFAULT);
+        + in.getExpectNextPos());
     IOUtils.closeStream(fsDataInputStream);
   }
 
@@ -183,8 +179,8 @@ public class TestAliyunOSSInputStream {
       if (bytesRead % (1024 * 1024) == 0) {
         int available = instream.available();
         int remaining = (int)(size - bytesRead);
-        assertTrue("expected remaining:" + remaining + ", but got:" + available,
-            remaining == available);
+        assertTrue(remaining == available,
+            "expected remaining:" + remaining + ", but got:" + available);
         LOG.info("Bytes read: " + Math.round((double)bytesRead / (1024 * 1024))
             + " MB");
       }
@@ -197,7 +193,7 @@ public class TestAliyunOSSInputStream {
     Path emptyDirPath = setPath("/test/emptyDirectory");
     fs.mkdirs(emptyDirPath);
     FileStatus dirFileStatus = fs.getFileStatus(emptyDirPath);
-    assertTrue("expected the empty dir is new",
-        dirFileStatus.getModificationTime() > 0L);
+    assertTrue(dirFileStatus.getModificationTime() > 0L,
+        "expected the empty dir is new");
   }
 }

+ 2 - 2
hadoop-tools/hadoop-aliyun/src/test/java/org/apache/hadoop/fs/aliyun/oss/fileContext/TestOSSFileContextUtil.java

@@ -22,7 +22,7 @@ package org.apache.hadoop.fs.aliyun.oss.fileContext;
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.fs.FileContextUtilBase;
 import org.apache.hadoop.fs.aliyun.oss.AliyunOSSTestUtils;
-import org.junit.Before;
+import org.junit.jupiter.api.BeforeEach;
 
 import java.io.IOException;
 
@@ -31,7 +31,7 @@ import java.io.IOException;
  */
 public class TestOSSFileContextUtil extends FileContextUtilBase {
 
-  @Before
+  @BeforeEach
   public void setUp() throws IOException, Exception {
     Configuration conf = new Configuration();
     fc = AliyunOSSTestUtils.createTestFileContext(conf);

+ 17 - 15
hadoop-tools/hadoop-aliyun/src/test/java/org/apache/hadoop/fs/aliyun/oss/yarn/TestOSS.java

@@ -25,14 +25,15 @@ import org.apache.hadoop.fs.FileContext;
 import org.apache.hadoop.fs.FsStatus;
 import org.apache.hadoop.fs.Path;
 import org.apache.hadoop.fs.aliyun.oss.AliyunOSSTestUtils;
-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 java.util.EnumSet;
 
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
 
 /**
  * OSS tests through the {@link FileContext} API.
@@ -40,13 +41,13 @@ import static org.junit.Assert.assertTrue;
 public class TestOSS {
   private FileContext fc;
 
-  @Before
+  @BeforeEach
   public void setUp() throws Exception {
     Configuration conf = new Configuration();
     fc = AliyunOSSTestUtils.createTestFileContext(conf);
   }
 
-  @After
+  @AfterEach
   public void tearDown() throws Exception {
     if (fc != null) {
       fc.delete(getTestPath(), true);
@@ -61,16 +62,17 @@ public class TestOSS {
   public void testOSSStatus() throws Exception {
     FsStatus fsStatus = fc.getFsStatus(null);
     assertNotNull(fsStatus);
-    assertTrue("Used capacity should be positive: " + fsStatus.getUsed(),
-        fsStatus.getUsed() >= 0);
-    assertTrue("Remaining capacity should be positive: " + fsStatus
-        .getRemaining(),
-        fsStatus.getRemaining() >= 0);
-    assertTrue("Capacity should be positive: " + fsStatus.getCapacity(),
-        fsStatus.getCapacity() >= 0);
+    assertTrue(
+        fsStatus.getUsed() >= 0, "Used capacity should be positive: " + fsStatus.getUsed());
+    assertTrue(
+        fsStatus.getRemaining() >= 0, "Remaining capacity should be positive: " + fsStatus
+        .getRemaining());
+    assertTrue(
+        fsStatus.getCapacity() >= 0, "Capacity should be positive: " + fsStatus.getCapacity());
   }
 
-  @Test(timeout = 90000L)
+  @Test
+  @Timeout(90)
   public void testOSSCreateFileInSubDir() throws Exception {
     Path dirPath = getTestPath();
     fc.mkdir(dirPath, FileContext.DIR_DEFAULT_PERM, true);