Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
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;

Expand All @@ -33,8 +33,9 @@
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.
Expand All @@ -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");
Expand All @@ -59,7 +60,7 @@ public void testV4() throws IOException {
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);
Expand All @@ -71,7 +72,7 @@ public void testV4() throws IOException {
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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,10 @@
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;
Expand All @@ -48,27 +47,25 @@
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;
private static String testRootPath =
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);
Expand All @@ -79,7 +76,7 @@ public void setUp() throws Exception {
fs = AliyunOSSTestUtils.createTestFileSystem(conf);
}

@After
@AfterEach
public void tearDown() throws Exception {
if (fs != null) {
fs.delete(new Path(testRootPath), true);
Expand Down Expand Up @@ -237,8 +234,8 @@ private void bufferShouldReleased(boolean zeroSizeFile) throws IOException {
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 =
Expand All @@ -258,7 +255,7 @@ private void bufferShouldReleased(boolean zeroSizeFile) throws IOException {
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
Expand All @@ -268,9 +265,9 @@ public void testDirectoryAllocator() throws Throwable {
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();
}
Expand All @@ -290,8 +287,8 @@ public void testDirectoryAllocatorRR() throws Throwable {
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
Expand All @@ -301,37 +298,36 @@ public void testByteBufferIO() throws IOException {
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();
ByteBufferBlockFactory.ByteBufferBlock.ByteBufferInputStream
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;
Expand All @@ -340,8 +336,8 @@ public void testByteBufferIO() throws IOException {
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];
Expand All @@ -353,24 +349,23 @@ public void testByteBufferIO() throws IOException {
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();
assertEquals('e', stream.read());

// 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);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,19 @@
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.
Expand All @@ -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
Expand All @@ -75,8 +74,8 @@ public void testRootDirAlwaysExists() throws Exception {
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
Expand All @@ -91,7 +90,7 @@ public void testRenameRootDirForbidden() throws Exception {
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());
Expand All @@ -105,7 +104,7 @@ public void testGetFileStatusInVersioningBucket() throws Exception {
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());
Expand All @@ -128,16 +127,16 @@ public void testDeleteSubdir() throws IOException {
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");
}


Expand Down Expand Up @@ -354,20 +353,20 @@ public void testRenameDirectoryAsExistingFile() throws Exception {
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");
}
}

Expand Down
Loading