Skip to content

Commit 26a0fda

Browse files
slfan1989cnauroth
andauthored
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 <[email protected]> Reviewed-by: Chris Nauroth <[email protected]> Signed-off-by: Shilun Fan <[email protected]>
1 parent e442a32 commit 26a0fda

File tree

8 files changed

+143
-150
lines changed

8 files changed

+143
-150
lines changed

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

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
import org.apache.hadoop.conf.Configuration;
2222
import org.apache.hadoop.fs.FileStatus;
2323
import org.apache.hadoop.fs.Path;
24-
import org.junit.Before;
25-
import org.junit.Test;
24+
import org.junit.jupiter.api.BeforeEach;
25+
import org.junit.jupiter.api.Test;
2626
import org.slf4j.Logger;
2727
import org.slf4j.LoggerFactory;
2828

@@ -33,8 +33,9 @@
3333
import static org.apache.hadoop.fs.aliyun.oss.Constants.SIGNATURE_VERSION_KEY;
3434
import static org.apache.hadoop.fs.contract.ContractTestUtils.createFile;
3535
import static org.apache.hadoop.fs.contract.ContractTestUtils.dataset;
36-
import static org.junit.Assert.*;
37-
import static org.junit.Assume.assumeNotNull;
36+
import static org.junit.jupiter.api.Assertions.assertEquals;
37+
import static org.junit.jupiter.api.Assertions.assertNotNull;
38+
import static org.junit.jupiter.api.Assumptions.assumeTrue;
3839

3940
/**
4041
* Tests Aliyun OSS system.
@@ -45,7 +46,7 @@ public class ITAliyunOSSSignatureV4 {
4546
private URI testURI;
4647
private Path testFile = new Path("ITAliyunOSSSignatureV4/atestr");
4748

48-
@Before
49+
@BeforeEach
4950
public void setUp() throws Exception {
5051
conf = new Configuration();
5152
String bucketUri = conf.get("test.fs.oss.name");
@@ -59,7 +60,7 @@ public void testV4() throws IOException {
5960
conf.set(REGION_KEY, "cn-hongkong");
6061
AliyunOSSFileSystem fs = new AliyunOSSFileSystem();
6162
fs.initialize(testURI, conf);
62-
assumeNotNull(fs);
63+
assumeTrue(fs != null);
6364

6465
createFile(fs, testFile, true, dataset(256, 0, 255));
6566
FileStatus status = fs.getFileStatus(testFile);
@@ -71,7 +72,7 @@ public void testV4() throws IOException {
7172
public void testDefaultSignatureVersion() throws IOException {
7273
AliyunOSSFileSystem fs = new AliyunOSSFileSystem();
7374
fs.initialize(testURI, conf);
74-
assumeNotNull(fs);
75+
assumeTrue(fs != null);
7576

7677
Path testFile2 = new Path("/test/atestr");
7778
createFile(fs, testFile2, true, dataset(256, 0, 255));

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
import org.apache.hadoop.fs.aliyun.oss.contract.AliyunOSSContract;
2626
import org.apache.hadoop.fs.contract.AbstractFSContract;
2727
import org.apache.hadoop.fs.contract.AbstractFSContractTestBase;
28-
import org.junit.Test;
28+
import org.junit.jupiter.api.Test;
2929

3030
import java.io.IOException;
3131
import java.lang.reflect.InvocationTargetException;

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

Lines changed: 42 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,10 @@
2626
import org.apache.hadoop.fs.aliyun.oss.statistics.BlockOutputStreamStatistics;
2727
import org.apache.hadoop.fs.contract.ContractTestUtils;
2828
import org.apache.hadoop.test.GenericTestUtils;
29-
import org.junit.After;
30-
import org.junit.Before;
31-
import org.junit.Rule;
32-
import org.junit.Test;
33-
import org.junit.rules.Timeout;
29+
import org.junit.jupiter.api.AfterEach;
30+
import org.junit.jupiter.api.BeforeEach;
31+
import org.junit.jupiter.api.Test;
32+
import org.junit.jupiter.api.Timeout;
3433

3534
import java.io.File;
3635
import java.io.IOException;
@@ -48,27 +47,25 @@
4847
import static org.apache.hadoop.fs.aliyun.oss.Constants.MULTIPART_UPLOAD_PART_SIZE_DEFAULT;
4948
import static org.apache.hadoop.fs.aliyun.oss.Constants.MULTIPART_UPLOAD_PART_SIZE_KEY;
5049
import static org.apache.hadoop.fs.contract.ContractTestUtils.IO_CHUNK_BUFFER_SIZE;
51-
import static org.junit.Assert.assertEquals;
52-
import static org.junit.Assert.assertFalse;
53-
import static org.junit.Assert.assertNotEquals;
54-
import static org.junit.Assert.assertNotNull;
55-
import static org.junit.Assert.assertTrue;
50+
import static org.junit.jupiter.api.Assertions.assertEquals;
51+
import static org.junit.jupiter.api.Assertions.assertFalse;
52+
import static org.junit.jupiter.api.Assertions.assertNotEquals;
53+
import static org.junit.jupiter.api.Assertions.assertNotNull;
54+
import static org.junit.jupiter.api.Assertions.assertTrue;
5655

5756
/**
5857
* Tests regular and multi-part upload functionality for
5958
* AliyunOSSBlockOutputStream.
6059
*/
60+
@Timeout(30 * 60)
6161
public class TestAliyunOSSBlockOutputStream {
6262
private FileSystem fs;
6363
private static final int PART_SIZE = 1024 * 1024;
6464
private static String testRootPath =
6565
AliyunOSSTestUtils.generateUniqueTestPath();
6666
private static final long MEMORY_LIMIT = 10 * 1024 * 1024;
6767

68-
@Rule
69-
public Timeout testTimeout = new Timeout(30 * 60 * 1000);
70-
71-
@Before
68+
@BeforeEach
7269
public void setUp() throws Exception {
7370
Configuration conf = new Configuration();
7471
conf.setInt(MULTIPART_UPLOAD_PART_SIZE_KEY, PART_SIZE);
@@ -79,7 +76,7 @@ public void setUp() throws Exception {
7976
fs = AliyunOSSTestUtils.createTestFileSystem(conf);
8077
}
8178

82-
@After
79+
@AfterEach
8380
public void tearDown() throws Exception {
8481
if (fs != null) {
8582
fs.delete(new Path(testRootPath), true);
@@ -237,8 +234,8 @@ private void bufferShouldReleased(boolean zeroSizeFile) throws IOException {
237234
OSSDataBlocks.ByteBufferBlockFactory
238235
blockFactory = (OSSDataBlocks.ByteBufferBlockFactory)
239236
((AliyunOSSFileSystem)fs).getBlockFactory();
240-
assertEquals("outstanding buffers in " + blockFactory,
241-
0, blockFactory.getOutstandingBufferCount());
237+
assertEquals(0, blockFactory.getOutstandingBufferCount(),
238+
"outstanding buffers in " + blockFactory);
242239
}
243240
}
244241
BlockOutputStreamStatistics statistics =
@@ -258,7 +255,7 @@ private void bufferShouldReleased(boolean zeroSizeFile) throws IOException {
258255
public void testDirectoryAllocator() throws Throwable {
259256
Configuration conf = fs.getConf();
260257
File tmp = AliyunOSSUtils.createTmpFileForWrite("out-", 1024, conf);
261-
assertTrue("not found: " + tmp, tmp.exists());
258+
assertTrue(tmp.exists(), "not found: " + tmp);
262259
tmp.delete();
263260

264261
// tmp should not in DeleteOnExitHook
@@ -268,9 +265,9 @@ public void testDirectoryAllocator() throws Throwable {
268265
field.setAccessible(true);
269266
String name = field.getName();
270267
LinkedHashSet<String> files = (LinkedHashSet<String>)field.get(name);
271-
assertTrue("in DeleteOnExitHook", files.isEmpty());
272-
assertFalse("in DeleteOnExitHook",
273-
(new ArrayList<>(files)).contains(tmp.getPath()));
268+
assertTrue(files.isEmpty(), "in DeleteOnExitHook");
269+
assertFalse(
270+
(new ArrayList<>(files)).contains(tmp.getPath()), "in DeleteOnExitHook");
274271
} catch (Exception e) {
275272
e.printStackTrace();
276273
}
@@ -290,8 +287,8 @@ public void testDirectoryAllocatorRR() throws Throwable {
290287
tmp1.delete();
291288
File tmp2 = AliyunOSSUtils.createTmpFileForWrite("out-", 1024, conf);
292289
tmp2.delete();
293-
assertNotEquals("round robin not working",
294-
tmp1.getParent(), tmp2.getParent());
290+
assertNotEquals(tmp1.getParent(), tmp2.getParent(),
291+
"round robin not working");
295292
}
296293

297294
@Test
@@ -301,37 +298,36 @@ public void testByteBufferIO() throws IOException {
301298
int limit = 128;
302299
OSSDataBlocks.ByteBufferBlockFactory.ByteBufferBlock block
303300
= factory.create(1, limit, null);
304-
assertEquals("outstanding buffers in " + factory,
305-
1, factory.getOutstandingBufferCount());
301+
assertEquals(1, factory.getOutstandingBufferCount(),
302+
"outstanding buffers in " + factory);
306303

307304
byte[] buffer = ContractTestUtils.toAsciiByteArray("test data");
308305
int bufferLen = buffer.length;
309306
block.write(buffer, 0, bufferLen);
310307
assertEquals(bufferLen, block.dataSize());
311-
assertEquals("capacity in " + block,
312-
limit - bufferLen, block.remainingCapacity());
313-
assertTrue("hasCapacity(64) in " + block, block.hasCapacity(64));
314-
assertTrue("No capacity in " + block,
315-
block.hasCapacity(limit - bufferLen));
308+
assertEquals(limit - bufferLen, block.remainingCapacity(),
309+
"capacity in " + block);
310+
assertTrue(block.hasCapacity(64), "hasCapacity(64) in " + block);
311+
assertTrue(block.hasCapacity(limit - bufferLen), "No capacity in " + block);
316312

317313
// now start the write
318314
OSSDataBlocks.BlockUploadData blockUploadData = block.startUpload();
319315
ByteBufferBlockFactory.ByteBufferBlock.ByteBufferInputStream
320316
stream =
321317
(ByteBufferBlockFactory.ByteBufferBlock.ByteBufferInputStream)
322318
blockUploadData.getUploadStream();
323-
assertTrue("Mark not supported in " + stream, stream.markSupported());
324-
assertTrue("!hasRemaining() in " + stream, stream.hasRemaining());
319+
assertTrue(stream.markSupported(), "Mark not supported in " + stream);
320+
assertTrue(stream.hasRemaining(), "!hasRemaining() in " + stream);
325321

326322
int expected = bufferLen;
327-
assertEquals("wrong available() in " + stream,
328-
expected, stream.available());
323+
assertEquals(expected, stream.available(),
324+
"wrong available() in " + stream);
329325

330326
assertEquals('t', stream.read());
331327
stream.mark(limit);
332328
expected--;
333-
assertEquals("wrong available() in " + stream,
334-
expected, stream.available());
329+
assertEquals(expected, stream.available(),
330+
"wrong available() in " + stream);
335331

336332
// read into a byte array with an offset
337333
int offset = 5;
@@ -340,8 +336,8 @@ public void testByteBufferIO() throws IOException {
340336
assertEquals('e', in[offset]);
341337
assertEquals('s', in[offset + 1]);
342338
expected -= 2;
343-
assertEquals("wrong available() in " + stream,
344-
expected, stream.available());
339+
assertEquals(expected, stream.available(),
340+
"wrong available() in " + stream);
345341

346342
// read to end
347343
byte[] remainder = new byte[limit];
@@ -353,24 +349,23 @@ public void testByteBufferIO() throws IOException {
353349
assertEquals(expected, index);
354350
assertEquals('a', remainder[--index]);
355351

356-
assertEquals("wrong available() in " + stream,
357-
0, stream.available());
358-
assertTrue("hasRemaining() in " + stream, !stream.hasRemaining());
352+
assertEquals(0, stream.available(), "wrong available() in " + stream);
353+
assertTrue(!stream.hasRemaining(), "hasRemaining() in " + stream);
359354

360355
// go the mark point
361356
stream.reset();
362357
assertEquals('e', stream.read());
363358

364359
// when the stream is closed, the data should be returned
365360
stream.close();
366-
assertEquals("outstanding buffers in " + factory,
367-
1, factory.getOutstandingBufferCount());
361+
assertEquals(1, factory.getOutstandingBufferCount(),
362+
"outstanding buffers in " + factory);
368363
block.close();
369-
assertEquals("outstanding buffers in " + factory,
370-
0, factory.getOutstandingBufferCount());
364+
assertEquals(0, factory.getOutstandingBufferCount(),
365+
"outstanding buffers in " + factory);
371366
stream.close();
372-
assertEquals("outstanding buffers in " + factory,
373-
0, factory.getOutstandingBufferCount());
367+
assertEquals(0, factory.getOutstandingBufferCount(),
368+
"outstanding buffers in " + factory);
374369
}
375370
}
376371

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

Lines changed: 30 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,19 @@
2626
import org.apache.hadoop.fs.Path;
2727

2828
import org.apache.hadoop.security.UserGroupInformation;
29-
import org.junit.Before;
30-
import org.junit.Test;
29+
import org.junit.jupiter.api.BeforeEach;
30+
import org.junit.jupiter.api.Test;
3131

3232
import java.io.FileNotFoundException;
3333
import java.io.IOException;
3434
import java.util.Arrays;
3535

36-
import static org.junit.Assert.assertFalse;
37-
import static org.junit.Assert.assertTrue;
38-
import static org.junit.Assert.fail;
39-
import static org.junit.Assert.assertEquals;
40-
import static org.junit.Assume.assumeFalse;
41-
import static org.junit.Assume.assumeNotNull;
42-
import static org.junit.Assume.assumeTrue;
36+
import static org.junit.jupiter.api.Assertions.assertFalse;
37+
import static org.junit.jupiter.api.Assertions.assertTrue;
38+
import static org.junit.jupiter.api.Assertions.fail;
39+
import static org.junit.jupiter.api.Assertions.assertEquals;
40+
import static org.junit.jupiter.api.Assumptions.assumeFalse;
41+
import static org.junit.jupiter.api.Assumptions.assumeTrue;
4342

4443
/**
4544
* Tests a live Aliyun OSS system.
@@ -52,11 +51,11 @@ public class TestAliyunOSSFileSystemContract
5251
private static Path testRootPath =
5352
new Path(AliyunOSSTestUtils.generateUniqueTestPath());
5453

55-
@Before
54+
@BeforeEach
5655
public void setUp() throws Exception {
5756
Configuration conf = new Configuration();
5857
fs = AliyunOSSTestUtils.createTestFileSystem(conf);
59-
assumeNotNull(fs);
58+
assumeTrue(fs != null);
6059
}
6160

6261
@Override
@@ -75,8 +74,8 @@ public void testRootDirAlwaysExists() throws Exception {
7574
fs.getFileStatus(super.path("/"));
7675
//this catches overrides of the base exists() method that don't
7776
//use getFileStatus() as an existence probe
78-
assertTrue("FileSystem.exists() fails for root",
79-
fs.exists(super.path("/")));
77+
assertTrue(
78+
fs.exists(super.path("/")), "FileSystem.exists() fails for root");
8079
}
8180

8281
@Test
@@ -91,7 +90,7 @@ public void testRenameRootDirForbidden() throws Exception {
9190
public void testListStatus() throws IOException {
9291
Path file = this.path("/test/hadoop/file");
9392
this.createFile(file);
94-
assertTrue("File exists", this.fs.exists(file));
93+
assertTrue(this.fs.exists(file), "File exists");
9594
FileStatus fs = this.fs.getFileStatus(file);
9695
assertEquals(fs.getOwner(),
9796
UserGroupInformation.getCurrentUser().getShortUserName());
@@ -105,7 +104,7 @@ public void testGetFileStatusInVersioningBucket() throws Exception {
105104
for (int i = 1; i <= 30; ++i) {
106105
this.createFile(new Path(file, "sub" + i));
107106
}
108-
assertTrue("File exists", this.fs.exists(file));
107+
assertTrue(this.fs.exists(file), "File exists");
109108
FileStatus fs = this.fs.getFileStatus(file);
110109
assertEquals(fs.getOwner(),
111110
UserGroupInformation.getCurrentUser().getShortUserName());
@@ -128,16 +127,16 @@ public void testDeleteSubdir() throws IOException {
128127
Path subdir = this.path("/test/hadoop/subdir");
129128
this.createFile(file);
130129

131-
assertTrue("Created subdir", this.fs.mkdirs(subdir));
132-
assertTrue("File exists", this.fs.exists(file));
133-
assertTrue("Parent dir exists", this.fs.exists(parentDir));
134-
assertTrue("Subdir exists", this.fs.exists(subdir));
130+
assertTrue(this.fs.mkdirs(subdir), "Created subdir");
131+
assertTrue(this.fs.exists(file), "File exists");
132+
assertTrue(this.fs.exists(parentDir), "Parent dir exists");
133+
assertTrue(this.fs.exists(subdir), "Subdir exists");
135134

136-
assertTrue("Deleted subdir", this.fs.delete(subdir, true));
137-
assertTrue("Parent should exist", this.fs.exists(parentDir));
135+
assertTrue(this.fs.delete(subdir, true), "Deleted subdir");
136+
assertTrue(this.fs.exists(parentDir), "Parent should exist");
138137

139-
assertTrue("Deleted file", this.fs.delete(file, false));
140-
assertTrue("Parent should exist", this.fs.exists(parentDir));
138+
assertTrue(this.fs.delete(file, false), "Deleted file");
139+
assertTrue(this.fs.exists(parentDir), "Parent should exist");
141140
}
142141

143142

@@ -354,20 +353,20 @@ public void testRenameDirectoryAsExistingFile() throws Exception {
354353
public void testGetFileStatusFileAndDirectory() throws Exception {
355354
Path filePath = this.path("/test/oss/file1");
356355
this.createFile(filePath);
357-
assertTrue("Should be file", this.fs.getFileStatus(filePath).isFile());
358-
assertFalse("Should not be directory",
359-
this.fs.getFileStatus(filePath).isDirectory());
356+
assertTrue(this.fs.getFileStatus(filePath).isFile(), "Should be file");
357+
assertFalse(
358+
this.fs.getFileStatus(filePath).isDirectory(), "Should not be directory");
360359

361360
Path dirPath = this.path("/test/oss/dir");
362361
this.fs.mkdirs(dirPath);
363-
assertTrue("Should be directory",
364-
this.fs.getFileStatus(dirPath).isDirectory());
365-
assertFalse("Should not be file", this.fs.getFileStatus(dirPath).isFile());
362+
assertTrue(
363+
this.fs.getFileStatus(dirPath).isDirectory(), "Should be directory");
364+
assertFalse(this.fs.getFileStatus(dirPath).isFile(), "Should not be file");
366365

367366
Path parentPath = this.path("/test/oss");
368367
for (FileStatus fileStatus: fs.listStatus(parentPath)) {
369-
assertTrue("file and directory should be new",
370-
fileStatus.getModificationTime() > 0L);
368+
assertTrue(
369+
fileStatus.getModificationTime() > 0L, "file and directory should be new");
371370
}
372371
}
373372

0 commit comments

Comments
 (0)