Skip to content

Commit

Permalink
HADOOP-19415. [JDK17] Upgrade JUnit from 4 to 5 in hadoop-common Part5.
Browse files Browse the repository at this point in the history
  • Loading branch information
fanshilun committed Feb 7, 2025
1 parent 50f43c6 commit dab978e
Show file tree
Hide file tree
Showing 14 changed files with 95 additions and 102 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public void testAddWithSleepForCacheTimeout() throws IOException, InterruptedExc
new FileBasedIPList("ips.txt"),100);

assertFalse(cipl.isIn("10.113.221.222"), "10.113.221.222 is in the list");
assertFalse (cipl.isIn("10.222.103.121"), "10.222.103.121 is in the list");
assertFalse(cipl.isIn("10.222.103.121"), "10.222.103.121 is in the list");

TestFileBasedIPList.removeFile("ips.txt");
String[]ips2 = {"10.119.103.112", "10.221.102.0/23",
Expand All @@ -56,7 +56,7 @@ public void testAddWithSleepForCacheTimeout() throws IOException, InterruptedExc
Thread.sleep(101);

assertTrue(cipl.isIn("10.113.221.222"), "10.113.221.222 is not in the list");
assertTrue (cipl.isIn("10.222.103.121"), "10.222.103.121 is not in the list");
assertTrue(cipl.isIn("10.222.103.121"), "10.222.103.121 is not in the list");

TestFileBasedIPList.removeFile("ips.txt");
}
Expand All @@ -83,7 +83,7 @@ public void testRemovalWithSleepForCacheTimeout() throws IOException, Interrupte
new FileBasedIPList("ips.txt"),100);

assertTrue(cipl.isIn("10.113.221.222"), "10.113.221.222 is not in the list");
assertTrue (cipl.isIn("10.222.103.121"), "10.222.103.121 is not in the list");
assertTrue(cipl.isIn("10.222.103.121"), "10.222.103.121 is not in the list");

TestFileBasedIPList.removeFile("ips.txt");
String[]ips2 = {"10.119.103.112", "10.221.102.0/23", "10.113.221.221"};
Expand All @@ -92,7 +92,7 @@ public void testRemovalWithSleepForCacheTimeout() throws IOException, Interrupte
Thread.sleep(1005);

assertFalse(cipl.isIn("10.113.221.222"), "10.113.221.222 is in the list");
assertFalse (cipl.isIn("10.222.103.121"), "10.222.103.121 is in the list");
assertFalse(cipl.isIn("10.222.103.121"), "10.222.103.121 is in the list");

TestFileBasedIPList.removeFile("ips.txt");
}
Expand All @@ -118,7 +118,7 @@ public void testAddWithRefresh() throws IOException, InterruptedException {
new FileBasedIPList("ips.txt"),100);

assertFalse(cipl.isIn("10.113.221.222"), "10.113.221.222 is in the list");
assertFalse (cipl.isIn("10.222.103.121"), "10.222.103.121 is in the list");
assertFalse(cipl.isIn("10.222.103.121"), "10.222.103.121 is in the list");

TestFileBasedIPList.removeFile("ips.txt");
String[]ips2 = {"10.119.103.112", "10.221.102.0/23",
Expand All @@ -128,7 +128,7 @@ public void testAddWithRefresh() throws IOException, InterruptedException {
cipl.refresh();

assertTrue(cipl.isIn("10.113.221.222"), "10.113.221.222 is not in the list");
assertTrue (cipl.isIn("10.222.103.121"), "10.222.103.121 is not in the list");
assertTrue(cipl.isIn("10.222.103.121"), "10.222.103.121 is not in the list");

TestFileBasedIPList.removeFile("ips.txt");
}
Expand All @@ -155,7 +155,7 @@ public void testRemovalWithRefresh() throws IOException, InterruptedException {
new FileBasedIPList("ips.txt"),100);

assertTrue(cipl.isIn("10.113.221.222"), "10.113.221.222 is not in the list");
assertTrue (cipl.isIn("10.222.103.121"), "10.222.103.121 is not in the list");
assertTrue(cipl.isIn("10.222.103.121"), "10.222.103.121 is not in the list");

TestFileBasedIPList.removeFile("ips.txt");
String[]ips2 = {"10.119.103.112", "10.221.102.0/23", "10.113.221.221"};
Expand All @@ -164,7 +164,7 @@ public void testRemovalWithRefresh() throws IOException, InterruptedException {
cipl.refresh();

assertFalse(cipl.isIn("10.113.221.222"), "10.113.221.222 is in the list");
assertFalse (cipl.isIn("10.222.103.121"), "10.222.103.121 is in the list");
assertFalse(cipl.isIn("10.222.103.121"), "10.222.103.121 is in the list");

TestFileBasedIPList.removeFile("ips.txt");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.attribute.PosixFilePermissions;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;

import static org.junit.jupiter.api.Assertions.assertThrows;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public void testVerifyChunkedSumsFail(DataChecksum.Type pChecksumType) {
@ParameterizedTest
@MethodSource("data")
public void testVerifyChunkedSumsSuccessOddSize(DataChecksum.Type pChecksumType)
throws ChecksumException {
throws ChecksumException {
initTestNativeCrc32(pChecksumType);
// Test checksum with an odd number of bytes. This is a corner case that
// is often broken in checksum calculation, because there is an loop which
Expand All @@ -113,7 +113,7 @@ public void testVerifyChunkedSumsSuccessOddSize(DataChecksum.Type pChecksumType)
@ParameterizedTest
@MethodSource("data")
public void testVerifyChunkedSumsByteArraySuccess(DataChecksum.Type pChecksumType)
throws ChecksumException {
throws ChecksumException {
initTestNativeCrc32(pChecksumType);
allocateArrayByteBuffers();
fillDataAndValidChecksums();
Expand All @@ -138,7 +138,7 @@ public void testVerifyChunkedSumsByteArrayFail(DataChecksum.Type pChecksumType)
@ParameterizedTest
@MethodSource("data")
public void testCalculateChunkedSumsSuccess(DataChecksum.Type pChecksumType)
throws ChecksumException {
throws ChecksumException {
initTestNativeCrc32(pChecksumType);
allocateDirectByteBuffers();
fillDataAndValidChecksums();
Expand All @@ -149,7 +149,7 @@ public void testCalculateChunkedSumsSuccess(DataChecksum.Type pChecksumType)
@ParameterizedTest
@MethodSource("data")
public void testCalculateChunkedSumsFail(DataChecksum.Type pChecksumType)
throws ChecksumException {
throws ChecksumException {
initTestNativeCrc32(pChecksumType);
allocateDirectByteBuffers();
fillDataAndInvalidChecksums();
Expand All @@ -160,7 +160,7 @@ public void testCalculateChunkedSumsFail(DataChecksum.Type pChecksumType)
@ParameterizedTest
@MethodSource("data")
public void testCalculateChunkedSumsByteArraySuccess(DataChecksum.Type pChecksumType)
throws ChecksumException {
throws ChecksumException {
initTestNativeCrc32(pChecksumType);
allocateArrayByteBuffers();
fillDataAndValidChecksums();
Expand All @@ -172,7 +172,7 @@ public void testCalculateChunkedSumsByteArraySuccess(DataChecksum.Type pChecksum
@ParameterizedTest
@MethodSource("data")
public void testCalculateChunkedSumsByteArrayFail(DataChecksum.Type pChecksumType)
throws ChecksumException {
throws ChecksumException {
initTestNativeCrc32(pChecksumType);
allocateArrayByteBuffers();
fillDataAndInvalidChecksums();
Expand All @@ -185,7 +185,7 @@ public void testCalculateChunkedSumsByteArrayFail(DataChecksum.Type pChecksumTyp
@MethodSource("data")
@SuppressWarnings("deprecation")
public void testNativeVerifyChunkedSumsSuccess(DataChecksum.Type pChecksumType)
throws ChecksumException {
throws ChecksumException {
initTestNativeCrc32(pChecksumType);
allocateDirectByteBuffers();
fillDataAndValidChecksums();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public void testAppend() throws Exception {
assertArrayEquals(new String[]{"Dr.", "Who", "hi", "there"},
Options.prependOptions(new String[]{"hi", "there"},
"Dr.", "Who"), "first append");
assertArrayEquals(new String[]{"aa","bb","cc","dd","ee","ff"},
assertArrayEquals(new String[]{"aa", "bb", "cc", "dd", "ee", "ff"},
Options.prependOptions(new String[]{"dd", "ee", "ff"},
"aa", "bb", "cc"), "second append");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ public void testSet(){
assertEquals(0, progress.getProgress(), 0.0);

progress.set(Float.NEGATIVE_INFINITY);
assertEquals(0,progress.getProgress(),0.0);
assertEquals(0, progress.getProgress(), 0.0);

progress.set(-1);
assertEquals(0,progress.getProgress(),0.0);
assertEquals(0, progress.getProgress(), 0.0);

progress.set((float) 1.1);
assertEquals(1,progress.getProgress(),0.0);
assertEquals(1, progress.getProgress(), 0.0);

progress.set(Float.POSITIVE_INFINITY);
assertEquals(1,progress.getProgress(),0.0);
assertEquals(1, progress.getProgress(), 0.0);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,10 @@ public void testUnJarDoesNotLooseLastModify() throws Exception {
unjarDir, MATCH_ANY);

String failureMessage = "Last modify time was lost during unJar";
assertEquals(MOCKED_NOW, new File(unjarDir, TestRunJar.FOOBAR_TXT).lastModified(), failureMessage);
assertEquals(MOCKED_NOW_PLUS_TWO_SEC, new File(unjarDir, FOOBAZ_TXT).lastModified(), failureMessage);
assertEquals(MOCKED_NOW, new File(unjarDir, TestRunJar.FOOBAR_TXT).lastModified(),
failureMessage);
assertEquals(MOCKED_NOW_PLUS_TWO_SEC, new File(unjarDir, FOOBAZ_TXT).lastModified(),
failureMessage);
}

private File getUnjarDir(String dirName) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public void testShellCommandTimeout() throws Throwable {
//When timing out exception is thrown.
}
shellFile.delete();
assertTrue( shexc.isTimedOut(), "Script did not timeout");
assertTrue(shexc.isTimedOut(), "Script did not timeout");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,8 @@ public void testSimpleSplit() throws Exception {
"/",
"////"};
for (String testSubject : TO_TEST) {
assertArrayEquals(
testSubject.split("/")
, StringUtils.split(testSubject, '/'), "Testing '" + testSubject + "'");
assertArrayEquals(testSubject.split("/"),
StringUtils.split(testSubject, '/'), "Testing '" + testSubject + "'");
}
}

Expand Down Expand Up @@ -383,7 +382,7 @@ public void testStringToURI() {
@Timeout(value = 30)
public void testSimpleHostName() {
assertEquals("hadoop01", StringUtils.simpleHostname("hadoop01.domain.com"),
"Should return hostname when FQDN is specified");
"Should return hostname when FQDN is specified");
assertEquals("hadoop01", StringUtils.simpleHostname("hadoop01"),
"Should return hostname when only hostname is specified");
assertEquals("10.10.5.68", StringUtils.simpleHostname("10.10.5.68"),
Expand Down Expand Up @@ -481,8 +480,8 @@ public void run() {
FAST_DATE_FORMAT, start, end);
String formattedTime2 = StringUtils.getFormattedTimeWithDiff(
FAST_DATE_FORMAT, start, end);
assertTrue(formattedTime1.equals(formattedTime2), "Method returned inconsistent results indicative of"
+ " a race condition");
assertTrue(formattedTime1.equals(formattedTime2),
"Method returned inconsistent results indicative of a race condition");

}
});
Expand All @@ -497,25 +496,23 @@ public void testFormatTimeSortable() {
long timeDiff = 523452311;
String timeDiffStr = "99hrs, 59mins, 59sec";

assertEquals(timeDiffStr
, StringUtils.formatTimeSortable(timeDiff), "Incorrect time diff string returned");
assertEquals(timeDiffStr, StringUtils.formatTimeSortable(timeDiff),
"Incorrect time diff string returned");
}

@Test
public void testIsAlpha() {
assertTrue(
StringUtils.isAlpha("hello"), "Reported hello as non-alpha string");
assertFalse(
StringUtils.isAlpha("hello1"), "Reported hello1 as alpha string");
assertTrue(StringUtils.isAlpha("hello"), "Reported hello as non-alpha string");
assertFalse(StringUtils.isAlpha("hello1"), "Reported hello1 as alpha string");
}

@Test
public void testEscapeHTML() {
String htmlStr = "<p>Hello. How are you?</p>";
String escapedStr = "&lt;p&gt;Hello. How are you?&lt;/p&gt;";

assertEquals(
escapedStr, StringUtils.escapeHTML(htmlStr), "Incorrect escaped HTML string returned");
assertEquals(escapedStr, StringUtils.escapeHTML(htmlStr),
"Incorrect escaped HTML string returned");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ public void setUp() throws IOException {
// Not supported on non-Windows platforms
assumeWindows();
TEST_DIR.mkdirs();
assertTrue(
TEST_DIR.isDirectory(), "Failed to create Test directory " + TEST_DIR );
assertTrue(TEST_DIR.isDirectory(),
"Failed to create Test directory " + TEST_DIR );
winutils = Shell.getWinUtilsPath();
}

Expand Down Expand Up @@ -342,11 +342,12 @@ public void testBasicChmodOnDir() throws IOException {
// Deleting a file will succeed even if write permissions are not present
// on the parent dir. Check the following link for additional details:
// http://support.microsoft.com/kb/238018
assertTrue(
b.delete(), "Special behavior: deleting a file will succeed on Windows "
assertTrue(b.delete(),
"Special behavior: deleting a file will succeed on Windows "
+ "even if a user does not have write permissions on the parent dir");

assertFalse(b.renameTo(new File(a, "d")), "Renaming a file should fail on the dir where a user does "
assertFalse(b.renameTo(new File(a, "d")),
"Renaming a file should fail on the dir where a user does "
+ "not have write permissions");

// restore permissions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ public void testExternalDtdWithSecureTransformerFactory() throws Exception {
assertThrows(TransformerException.class, () -> {
Transformer transformer = XMLUtils.newSecureTransformerFactory().newTransformer();
try (
InputStream stream = getResourceStream("/xml/external-dtd.xml");
StringWriter stringWriter = new StringWriter()
InputStream stream = getResourceStream("/xml/external-dtd.xml");
StringWriter stringWriter = new StringWriter()
) {
transformer.transform(new StreamSource(stream), new StreamResult(stringWriter));
}
Expand All @@ -139,8 +139,8 @@ public void testExternalDtdWithSecureSAXTransformerFactory() throws Exception {
assertThrows(TransformerException.class, () -> {
Transformer transformer = XMLUtils.newSecureSAXTransformerFactory().newTransformer();
try (
InputStream stream = getResourceStream("/xml/external-dtd.xml");
StringWriter stringWriter = new StringWriter()
InputStream stream = getResourceStream("/xml/external-dtd.xml");
StringWriter stringWriter = new StringWriter()
) {
transformer.transform(new StreamSource(stream), new StreamResult(stringWriter));
}
Expand Down
Loading

0 comments on commit dab978e

Please sign in to comment.