Skip to content

Commit 2d6d7e4

Browse files
slfan1989Hexiaoqiao
authored andcommitted
HADOOP-19411. [JDK17] Upgrade JUnit from 4 to 5 in hadoop-cos. (apache#7640)
* HADOOP-19411. [JDK17] Upgrade JUnit from 4 to 5 in hadoop-cos. Co-authored-by: He Xiaoqiao <[email protected]> Reviewed-by: He Xiaoqiao <[email protected]> Signed-off-by: Shilun Fan <[email protected]>
1 parent d42a359 commit 2d6d7e4

File tree

3 files changed

+31
-30
lines changed

3 files changed

+31
-30
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,16 @@
2020
import com.qcloud.cos.auth.COSCredentials;
2121
import com.qcloud.cos.auth.COSCredentialsProvider;
2222
import org.apache.hadoop.conf.Configuration;
23-
import org.junit.Test;
23+
import org.junit.jupiter.api.Test;
2424
import org.slf4j.Logger;
2525
import org.slf4j.LoggerFactory;
2626

2727
import java.io.IOException;
2828
import java.net.URI;
2929
import java.net.URISyntaxException;
3030

31-
import static org.junit.Assert.assertNotNull;
32-
import static org.junit.Assert.fail;
31+
import static org.junit.jupiter.api.Assertions.assertNotNull;
32+
import static org.junit.jupiter.api.Assertions.fail;
3333

3434
public class TestCosCredentials {
3535
private static final Logger LOG =
@@ -76,7 +76,7 @@ private void validateCredentials(URI uri, Configuration configuration)
7676
COSCredentialsProvider credentialsProvider =
7777
CosNUtils.createCosCredentialsProviderSet(uri, configuration);
7878
COSCredentials cosCredentials = credentialsProvider.getCredentials();
79-
assertNotNull("The cos credentials obtained is null.", cosCredentials);
79+
assertNotNull(cosCredentials, "The cos credentials obtained is null.");
8080
if (configuration.get(
8181
CosNConfigKeys.COSN_CREDENTIALS_PROVIDER).compareToIgnoreCase(
8282
"org.apache.hadoop.fs.cosn.EnvironmentVariableCredentialsProvider")

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

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,14 @@
2323
import org.apache.hadoop.fs.Path;
2424
import org.apache.hadoop.fs.contract.ContractTestUtils;
2525
import org.apache.hadoop.io.IOUtils;
26-
import org.junit.*;
26+
import org.junit.jupiter.api.AfterEach;
27+
import org.junit.jupiter.api.BeforeEach;
28+
import org.junit.jupiter.api.Disabled;
29+
import org.junit.jupiter.api.Test;
2730
import org.slf4j.Logger;
2831
import org.slf4j.LoggerFactory;
2932

30-
import static org.junit.Assert.assertTrue;
33+
import static org.junit.jupiter.api.Assertions.assertTrue;
3134

3235
import java.io.IOException;
3336
import java.util.Random;
@@ -43,15 +46,15 @@ public class TestCosNInputStream {
4346

4447
private Path testRootDir;
4548

46-
@Before
49+
@BeforeEach
4750
public void setUp() throws IOException {
4851
Configuration configuration = new Configuration();
4952
this.fs = CosNTestUtils.createTestFileSystem(configuration);
5053
this.testRootDir = CosNTestUtils.createTestPath(new Path("/test"));
5154
LOG.info("test root dir: " + this.testRootDir);
5255
}
5356

54-
@After
57+
@AfterEach
5558
public void tearDown() throws IOException {
5659
if (null != this.fs) {
5760
this.fs.delete(this.testRootDir, true);
@@ -76,9 +79,9 @@ public void testSeek() throws Exception {
7679
for (int i = 0; i != seekTimes; i++) {
7780
long pos = fileSize / (seekTimes - i) - 1;
7881
inputStream.seek(pos);
79-
assertTrue("expected position at: " +
80-
pos + ", but got: " + inputStream.getPos(),
81-
inputStream.getPos() == pos);
82+
assertTrue(inputStream.getPos() == pos,
83+
"expected position at: " +
84+
pos + ", but got: " + inputStream.getPos());
8285
LOG.info("completed seeking at pos: " + inputStream.getPos());
8386
}
8487
LOG.info("begin to random position seeking test...");
@@ -87,9 +90,9 @@ public void testSeek() throws Exception {
8790
long pos = Math.abs(random.nextLong()) % fileSize;
8891
LOG.info("seeking for pos: " + pos);
8992
inputStream.seek(pos);
90-
assertTrue("expected position at: " +
91-
pos + ", but got: " + inputStream.getPos(),
92-
inputStream.getPos() == pos);
93+
assertTrue(inputStream.getPos() == pos,
94+
"expected position at: " +
95+
pos + ", but got: " + inputStream.getPos());
9396
LOG.info("completed seeking at pos: " + inputStream.getPos());
9497
}
9598
}
@@ -110,16 +113,16 @@ public void testGetPos() throws Exception {
110113
Random random = new Random();
111114
long pos = Math.abs(random.nextLong()) % fileSize;
112115
inputStream.seek(pos);
113-
assertTrue("expected position at: " +
114-
pos + ", but got: " + inputStream.getPos(),
115-
inputStream.getPos() == pos);
116+
assertTrue(inputStream.getPos() == pos,
117+
"expected position at: " +
118+
pos + ", but got: " + inputStream.getPos());
116119
LOG.info("completed get pos tests.");
117120
}
118121

119122
/**
120123
* Method: seekToNewSource(long targetPos).
121124
*/
122-
@Ignore("Not ready yet")
125+
@Disabled("Not ready yet")
123126
public void testSeekToNewSource() throws Exception {
124127
LOG.info("Currently it is not supported to " +
125128
"seek the offset in a new source.");
@@ -154,8 +157,9 @@ public void testRead() throws Exception {
154157

155158
if (bytesRead % (1 * Unit.MB) == 0) {
156159
int available = inputStream.available();
157-
assertTrue("expected remaining: " + (fileSize - bytesRead) +
158-
" but got: " + available, (fileSize - bytesRead) == available);
160+
assertTrue((fileSize - bytesRead) == available,
161+
"expected remaining: " + (fileSize - bytesRead) +
162+
" but got: " + available);
159163
LOG.info("Bytes read: " +
160164
Math.round((double) bytesRead / Unit.MB) + "MB");
161165
}

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

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,10 @@
2121
import org.apache.hadoop.fs.FileSystem;
2222
import org.apache.hadoop.fs.Path;
2323
import org.apache.hadoop.fs.contract.ContractTestUtils;
24-
import org.junit.Rule;
25-
import org.junit.Test;
26-
import org.junit.Before;
27-
import org.junit.After;
28-
import org.junit.rules.Timeout;
24+
import org.junit.jupiter.api.AfterEach;
25+
import org.junit.jupiter.api.BeforeEach;
26+
import org.junit.jupiter.api.Test;
27+
import org.junit.jupiter.api.Timeout;
2928

3029
import java.io.IOException;
3130

@@ -34,14 +33,12 @@
3433
* <p>
3534
* If the test.fs.cosn.name property is not set, all test case will fail.
3635
*/
36+
@Timeout(3600)
3737
public class TestCosNOutputStream {
3838
private FileSystem fs;
3939
private Path testRootDir;
4040

41-
@Rule
42-
public Timeout timeout = new Timeout(3600 * 1000);
43-
44-
@Before
41+
@BeforeEach
4542
public void setUp() throws Exception {
4643
Configuration configuration = new Configuration();
4744
configuration.setInt(
@@ -53,7 +50,7 @@ public void setUp() throws Exception {
5350
this.testRootDir = new Path("/test");
5451
}
5552

56-
@After
53+
@AfterEach
5754
public void tearDown() throws Exception {
5855
}
5956

0 commit comments

Comments
 (0)