Skip to content

HADOOP-19415. [JDK17] Upgrade JUnit from 4 to 5 in hadoop-common Part2. #7347

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 6 commits into from
Feb 5, 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
20 changes: 20 additions & 0 deletions hadoop-common-project/hadoop-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,26 @@
<artifactId>lz4-java</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-launcher</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@
import org.apache.hadoop.fs.Options.ChecksumOpt;
import org.apache.hadoop.security.AccessControlException;
import org.apache.hadoop.util.Progressable;
import org.junit.Test;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertThrows;

public class TestAfsCheckPath {

Expand Down Expand Up @@ -56,11 +58,13 @@ public void testCheckPathWithTheSameNonDefaultPort()
afs.checkPath(new Path("dummy://dummy-host:" + OTHER_PORT));
}

@Test(expected=InvalidPathException.class)
@Test
public void testCheckPathWithDifferentPorts() throws URISyntaxException {
URI uri = new URI("dummy://dummy-host:" + DEFAULT_PORT);
AbstractFileSystem afs = new DummyFileSystem(uri);
afs.checkPath(new Path("dummy://dummy-host:" + OTHER_PORT));
assertThrows(InvalidPathException.class, () -> {
URI uri = new URI("dummy://dummy-host:" + DEFAULT_PORT);
AbstractFileSystem afs = new DummyFileSystem(uri);
afs.checkPath(new Path("dummy://dummy-host:" + OTHER_PORT));
});
}

private static class DummyFileSystem extends AbstractFileSystem {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.test.GenericTestUtils;

import org.junit.Test;
import static org.junit.Assert.*;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;

public class TestAvroFSInput {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@
*/
package org.apache.hadoop.fs;

import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;

import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;

public class TestBlockLocation {

Expand Down Expand Up @@ -70,7 +71,8 @@ private static void checkBlockLocation(final BlockLocation loc,
/**
* Call all the constructors and verify the delegation is working properly
*/
@Test(timeout = 5000)
@Test
@Timeout(value = 5)
public void testBlockLocationConstructors() throws Exception {
//
BlockLocation loc;
Expand All @@ -91,7 +93,8 @@ public void testBlockLocationConstructors() throws Exception {
/**
* Call each of the setters and verify
*/
@Test(timeout = 5000)
@Test
@Timeout(value = 5)
public void testBlockLocationSetters() throws Exception {
BlockLocation loc;
loc = new BlockLocation();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,22 @@
import static org.apache.hadoop.fs.FileSystemTestHelper.*;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.test.GenericTestUtils;
import org.junit.*;
import static org.junit.Assert.*;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;

public class TestChecksumFileSystem {
static final String TEST_ROOT_DIR =
GenericTestUtils.getTempPath("work-dir/localfs");

static LocalFileSystem localFs;

@Before
@BeforeEach
public void resetLocalFs() throws Exception {
localFs = FileSystem.getLocal(new Configuration());
localFs.setVerifyChecksum(true);
Expand Down Expand Up @@ -77,25 +83,25 @@ public void testVerifyChecksum() throws Exception {
readFile(localFs, testPath, 1025);

localFs.delete(localFs.getChecksumFile(testPath), true);
assertTrue("checksum deleted", !localFs.exists(localFs.getChecksumFile(testPath)));
assertTrue(!localFs.exists(localFs.getChecksumFile(testPath)), "checksum deleted");

//copying the wrong checksum file
FileUtil.copy(localFs, localFs.getChecksumFile(testPath11), localFs,
localFs.getChecksumFile(testPath),false,true,localFs.getConf());
assertTrue("checksum exists", localFs.exists(localFs.getChecksumFile(testPath)));
assertTrue(localFs.exists(localFs.getChecksumFile(testPath)), "checksum exists");

boolean errorRead = false;
try {
readFile(localFs, testPath, 1024);
}catch(ChecksumException ie) {
errorRead = true;
}
assertTrue("error reading", errorRead);
assertTrue(errorRead, "error reading");

//now setting verify false, the read should succeed
localFs.setVerifyChecksum(false);
String str = readFile(localFs, testPath, 1024).toString();
assertTrue("read", "testing".equals(str));
assertTrue("testing".equals(str), "read");
}

@Test
Expand Down Expand Up @@ -153,7 +159,7 @@ public void testTruncatedChecksum() throws Exception {
// telling it not to verify checksums, should avoid issue.
localFs.setVerifyChecksum(false);
String str = readFile(localFs, testPath, 1024).toString();
assertTrue("read", "testing truncation".equals(str));
assertTrue("testing truncation".equals(str), "read");
}

@Test
Expand All @@ -164,13 +170,11 @@ public void testStreamType() throws Exception {

localFs.setVerifyChecksum(true);
in = localFs.open(testPath);
assertTrue("stream is input checker",
in.getWrappedStream() instanceof FSInputChecker);
assertTrue(in.getWrappedStream() instanceof FSInputChecker, "stream is input checker");

localFs.setVerifyChecksum(false);
in = localFs.open(testPath);
assertFalse("stream is not input checker",
in.getWrappedStream() instanceof FSInputChecker);
assertFalse(in.getWrappedStream() instanceof FSInputChecker, "stream is not input checker");
}

@Test
Expand Down Expand Up @@ -200,7 +204,7 @@ public void testCorruptedChecksum() throws Exception {
} catch (ChecksumException ce) {
e = ce;
} finally {
assertNotNull("got checksum error", e);
assertNotNull(e, "got checksum error");
}

localFs.setVerifyChecksum(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
*/
package org.apache.hadoop.fs;


import static org.junit.Assert.*;
import static org.junit.jupiter.api.Assertions.assertEquals;

import java.util.ArrayList;
import java.util.Arrays;
Expand All @@ -30,8 +29,8 @@
import org.apache.hadoop.fs.shell.CommandFormat.NotEnoughArgumentsException;
import org.apache.hadoop.fs.shell.CommandFormat.TooManyArgumentsException;
import org.apache.hadoop.fs.shell.CommandFormat.UnknownOptionException;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

/**
* This class tests the command line parsing
Expand All @@ -41,7 +40,7 @@ public class TestCommandFormat {
private static List<String> expectedArgs;
private static Set<String> expectedOpts;

@Before
@BeforeEach
public void setUp() {
args = new ArrayList<>();
expectedOpts = new HashSet<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,16 @@
*/
package org.apache.hadoop.fs;

import static org.junit.Assert.*;
import static org.mockito.Mockito.*;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.inOrder;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.mockito.InOrder;

public class TestContentSummary {
Expand All @@ -33,12 +35,12 @@ public class TestContentSummary {
@Test
public void testConstructorEmpty() {
ContentSummary contentSummary = new ContentSummary.Builder().build();
assertEquals("getLength", 0, contentSummary.getLength());
assertEquals("getFileCount", 0, contentSummary.getFileCount());
assertEquals("getDirectoryCount", 0, contentSummary.getDirectoryCount());
assertEquals("getQuota", -1, contentSummary.getQuota());
assertEquals("getSpaceConsumed", 0, contentSummary.getSpaceConsumed());
assertEquals("getSpaceQuota", -1, contentSummary.getSpaceQuota());
assertEquals(0, contentSummary.getLength(), "getLength");
assertEquals(0, contentSummary.getFileCount(), "getFileCount");
assertEquals(0, contentSummary.getDirectoryCount(), "getDirectoryCount");
assertEquals(-1, contentSummary.getQuota(), "getQuota");
assertEquals(0, contentSummary.getSpaceConsumed(), "getSpaceConsumed");
assertEquals(-1, contentSummary.getSpaceQuota(), "getSpaceQuota");
}

// check the full constructor with quota information
Expand All @@ -54,14 +56,13 @@ public void testConstructorWithQuota() {
ContentSummary contentSummary = new ContentSummary.Builder().length(length).
fileCount(fileCount).directoryCount(directoryCount).quota(quota).
spaceConsumed(spaceConsumed).spaceQuota(spaceQuota).build();
assertEquals("getLength", length, contentSummary.getLength());
assertEquals("getFileCount", fileCount, contentSummary.getFileCount());
assertEquals("getDirectoryCount", directoryCount,
contentSummary.getDirectoryCount());
assertEquals("getQuota", quota, contentSummary.getQuota());
assertEquals("getSpaceConsumed", spaceConsumed,
contentSummary.getSpaceConsumed());
assertEquals("getSpaceQuota", spaceQuota, contentSummary.getSpaceQuota());
assertEquals(length, contentSummary.getLength(), "getLength");
assertEquals(fileCount, contentSummary.getFileCount(), "getFileCount");
assertEquals(directoryCount, contentSummary.getDirectoryCount(), "getDirectoryCount");
assertEquals(quota, contentSummary.getQuota(), "getQuota");
assertEquals(spaceConsumed,
contentSummary.getSpaceConsumed(), "getSpaceConsumed");
assertEquals(spaceQuota, contentSummary.getSpaceQuota(), "getSpaceQuota");
}

// check the constructor with quota information
Expand All @@ -74,13 +75,13 @@ public void testConstructorNoQuota() {
ContentSummary contentSummary = new ContentSummary.Builder().length(length).
fileCount(fileCount).directoryCount(directoryCount).
spaceConsumed(length).build();
assertEquals("getLength", length, contentSummary.getLength());
assertEquals("getFileCount", fileCount, contentSummary.getFileCount());
assertEquals("getDirectoryCount", directoryCount,
contentSummary.getDirectoryCount());
assertEquals("getQuota", -1, contentSummary.getQuota());
assertEquals("getSpaceConsumed", length, contentSummary.getSpaceConsumed());
assertEquals("getSpaceQuota", -1, contentSummary.getSpaceQuota());
assertEquals(length, contentSummary.getLength(), "getLength");
assertEquals(fileCount, contentSummary.getFileCount(), "getFileCount");
assertEquals(directoryCount,
contentSummary.getDirectoryCount(), "getDirectoryCount");
assertEquals(-1, contentSummary.getQuota(), "getQuota");
assertEquals(length, contentSummary.getSpaceConsumed(), "getSpaceConsumed");
assertEquals(-1, contentSummary.getSpaceQuota(), "getSpaceQuota");
}

// check the write method
Expand Down Expand Up @@ -127,14 +128,12 @@ public void testReadFields() throws IOException {
.thenReturn(spaceQuota);

contentSummary.readFields(in);
assertEquals("getLength", length, contentSummary.getLength());
assertEquals("getFileCount", fileCount, contentSummary.getFileCount());
assertEquals("getDirectoryCount", directoryCount,
contentSummary.getDirectoryCount());
assertEquals("getQuota", quota, contentSummary.getQuota());
assertEquals("getSpaceConsumed", spaceConsumed,
contentSummary.getSpaceConsumed());
assertEquals("getSpaceQuota", spaceQuota, contentSummary.getSpaceQuota());
assertEquals(length, contentSummary.getLength(), "getLength");
assertEquals(fileCount, contentSummary.getFileCount(), "getFileCount");
assertEquals(directoryCount, contentSummary.getDirectoryCount(), "getDirectoryCount");
assertEquals(quota, contentSummary.getQuota(), "getQuota");
assertEquals(spaceConsumed, contentSummary.getSpaceConsumed(), "getSpaceConsumed");
assertEquals(spaceQuota, contentSummary.getSpaceQuota(), "getSpaceQuota");
}

// check the header with quotas
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@

import org.apache.commons.lang3.RandomStringUtils;
import org.apache.hadoop.test.GenericTestUtils;
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 java.io.File;
import java.io.IOException;
import java.io.RandomAccessFile;


import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertTrue;

/**
* Test to make sure df can run and work.
Expand All @@ -37,13 +37,13 @@ public class TestDFCachingGetSpaceUsed {
final static private File DF_DIR = GenericTestUtils.getTestDir("testdfspace");
public static final int FILE_SIZE = 1024;

@Before
@BeforeEach
public void setUp() {
FileUtil.fullyDelete(DF_DIR);
assertTrue(DF_DIR.mkdirs());
}

@After
@AfterEach
public void tearDown() throws IOException {
FileUtil.fullyDelete(DF_DIR);
}
Expand Down
Loading