diff --git a/hadoop-cloud-storage-project/hadoop-cos/src/test/java/org/apache/hadoop/fs/cosn/TestCosCredentials.java b/hadoop-cloud-storage-project/hadoop-cos/src/test/java/org/apache/hadoop/fs/cosn/TestCosCredentials.java index 8b74f3639ddbd..6dfd32b2d3ef6 100644 --- a/hadoop-cloud-storage-project/hadoop-cos/src/test/java/org/apache/hadoop/fs/cosn/TestCosCredentials.java +++ b/hadoop-cloud-storage-project/hadoop-cos/src/test/java/org/apache/hadoop/fs/cosn/TestCosCredentials.java @@ -20,7 +20,7 @@ import com.qcloud.cos.auth.COSCredentials; import com.qcloud.cos.auth.COSCredentialsProvider; import org.apache.hadoop.conf.Configuration; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -28,8 +28,8 @@ import java.net.URI; 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 { private static final Logger LOG = @@ -76,7 +76,7 @@ private void validateCredentials(URI uri, Configuration configuration) COSCredentialsProvider credentialsProvider = CosNUtils.createCosCredentialsProviderSet(uri, configuration); COSCredentials cosCredentials = credentialsProvider.getCredentials(); - assertNotNull("The cos credentials obtained is null.", cosCredentials); + assertNotNull(cosCredentials, "The cos credentials obtained is null."); if (configuration.get( CosNConfigKeys.COSN_CREDENTIALS_PROVIDER).compareToIgnoreCase( "org.apache.hadoop.fs.cosn.EnvironmentVariableCredentialsProvider") diff --git a/hadoop-cloud-storage-project/hadoop-cos/src/test/java/org/apache/hadoop/fs/cosn/TestCosNInputStream.java b/hadoop-cloud-storage-project/hadoop-cos/src/test/java/org/apache/hadoop/fs/cosn/TestCosNInputStream.java index 79884bad070c2..e5d05b120d525 100644 --- a/hadoop-cloud-storage-project/hadoop-cos/src/test/java/org/apache/hadoop/fs/cosn/TestCosNInputStream.java +++ b/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.Path; import org.apache.hadoop.fs.contract.ContractTestUtils; 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.LoggerFactory; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.IOException; import java.util.Random; @@ -43,7 +46,7 @@ public class TestCosNInputStream { private Path testRootDir; - @Before + @BeforeEach public void setUp() throws IOException { Configuration configuration = new Configuration(); this.fs = CosNTestUtils.createTestFileSystem(configuration); @@ -51,7 +54,7 @@ public void setUp() throws IOException { LOG.info("test root dir: " + this.testRootDir); } - @After + @AfterEach public void tearDown() throws IOException { if (null != this.fs) { this.fs.delete(this.testRootDir, true); @@ -76,9 +79,9 @@ public void testSeek() throws Exception { for (int i = 0; i != seekTimes; i++) { long pos = fileSize / (seekTimes - i) - 1; 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("begin to random position seeking test..."); @@ -87,9 +90,9 @@ public void testSeek() throws Exception { long pos = Math.abs(random.nextLong()) % fileSize; LOG.info("seeking for pos: " + 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()); } } @@ -110,16 +113,16 @@ public void testGetPos() throws Exception { Random random = new Random(); long pos = Math.abs(random.nextLong()) % fileSize; 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."); } /** * Method: seekToNewSource(long targetPos). */ - @Ignore("Not ready yet") + @Disabled("Not ready yet") public void testSeekToNewSource() throws Exception { LOG.info("Currently it is not supported to " + "seek the offset in a new source."); @@ -154,8 +157,9 @@ public void testRead() throws Exception { if (bytesRead % (1 * Unit.MB) == 0) { 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: " + Math.round((double) bytesRead / Unit.MB) + "MB"); } diff --git a/hadoop-cloud-storage-project/hadoop-cos/src/test/java/org/apache/hadoop/fs/cosn/TestCosNOutputStream.java b/hadoop-cloud-storage-project/hadoop-cos/src/test/java/org/apache/hadoop/fs/cosn/TestCosNOutputStream.java index 7fd88976d62ae..d71408aab37bb 100644 --- a/hadoop-cloud-storage-project/hadoop-cos/src/test/java/org/apache/hadoop/fs/cosn/TestCosNOutputStream.java +++ b/hadoop-cloud-storage-project/hadoop-cos/src/test/java/org/apache/hadoop/fs/cosn/TestCosNOutputStream.java @@ -21,11 +21,10 @@ import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; 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; @@ -34,14 +33,12 @@ *

* If the test.fs.cosn.name property is not set, all test case will fail. */ +@Timeout(3600) public class TestCosNOutputStream { private FileSystem fs; private Path testRootDir; - @Rule - public Timeout timeout = new Timeout(3600 * 1000); - - @Before + @BeforeEach public void setUp() throws Exception { Configuration configuration = new Configuration(); configuration.setInt( @@ -53,7 +50,7 @@ public void setUp() throws Exception { this.testRootDir = new Path("/test"); } - @After + @AfterEach public void tearDown() throws Exception { }