Skip to content

Commit ba07c66

Browse files
zhtttylzcnauroth
authored andcommitted
HDFS-12431. [JDK17] Upgrade JUnit from 4 to 5 in hadoop-hdfs Part15.
Closes #7908 Signed-off-by: Shilun Fan <[email protected]> Signed-off-by: Chris Nauroth <[email protected]>
1 parent 9c1ddec commit ba07c66

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+848
-796
lines changed

hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/test/MetricsAsserts.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -449,8 +449,8 @@ public static void assertInverseQuantileGauges(String prefix,
449449
*/
450450
public static void assertTag(String name, String expected,
451451
MetricsRecordBuilder rb) {
452-
assertEquals("Bad Tag for metric " + name,
453-
expected, getStringTag(name, rb));
452+
assertEquals(expected, getStringTag(name, rb),
453+
"Bad Tag for metric " + name);
454454
}
455455

456456
/**

hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/qjournal/client/TestQJMWithFaults.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
import static org.apache.hadoop.hdfs.qjournal.QJMTestUtil.FAKE_NSINFO;
2121
import static org.apache.hadoop.hdfs.qjournal.QJMTestUtil.JID;
2222
import static org.apache.hadoop.hdfs.qjournal.QJMTestUtil.writeSegment;
23-
import static org.junit.Assert.assertEquals;
24-
import static org.junit.Assert.assertTrue;
23+
import static org.junit.jupiter.api.Assertions.assertEquals;
24+
import static org.junit.jupiter.api.Assertions.assertTrue;
2525
import static org.junit.jupiter.api.Assertions.assertThrows;
2626

2727
import java.io.Closeable;
@@ -257,9 +257,8 @@ public void testRandomized() throws Exception {
257257
checkException(t);
258258
continue;
259259
}
260-
assertTrue("Recovered only up to txnid " + recovered +
261-
" but had gotten an ack for " + lastAcked,
262-
recovered >= lastAcked);
260+
assertTrue(recovered >= lastAcked, "Recovered only up to txnid " + recovered
261+
+ " but had gotten an ack for " + lastAcked);
263262

264263
txid = recovered + 1;
265264

hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/qjournal/client/TestQuorumJournalManager.java

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@
2424
import static org.apache.hadoop.hdfs.qjournal.QJMTestUtil.writeTxns;
2525
import static org.apache.hadoop.hdfs.qjournal.client.SpyQJournalUtil.spyGetJournaledEdits;
2626
import static org.apache.hadoop.hdfs.qjournal.client.TestQuorumJournalManagerUnit.futureThrows;
27-
import static org.junit.Assert.assertEquals;
28-
import static org.junit.Assert.assertFalse;
29-
import static org.junit.Assert.assertNull;
30-
import static org.junit.Assert.assertTrue;
31-
import static org.junit.Assert.fail;
27+
import static org.junit.jupiter.api.Assertions.assertEquals;
28+
import static org.junit.jupiter.api.Assertions.assertFalse;
29+
import static org.junit.jupiter.api.Assertions.assertNull;
30+
import static org.junit.jupiter.api.Assertions.assertTrue;
31+
import static org.junit.jupiter.api.Assertions.fail;
3232
import static org.mockito.ArgumentMatchers.eq;
3333
import java.io.Closeable;
3434
import java.io.File;
@@ -46,9 +46,11 @@
4646
import org.apache.hadoop.hdfs.server.common.Util;
4747
import org.apache.hadoop.hdfs.server.protocol.RemoteEditLogManifest;
4848
import org.apache.hadoop.net.MockDomainNameResolver;
49+
import org.apache.hadoop.test.TestName;
4950
import org.apache.hadoop.thirdparty.com.google.common.util.concurrent.ListenableFuture;
5051
import org.apache.hadoop.thirdparty.com.google.common.util.concurrent.SettableFuture;
5152
import org.apache.hadoop.util.Lists;
53+
import org.junit.jupiter.api.extension.RegisterExtension;
5254
import org.mockito.stubbing.Answer;
5355
import org.slf4j.Logger;
5456
import org.slf4j.LoggerFactory;
@@ -69,11 +71,10 @@
6971
import org.apache.hadoop.io.IOUtils;
7072
import org.apache.hadoop.ipc.ProtobufRpcEngine2;
7173
import org.apache.hadoop.test.GenericTestUtils;
72-
import org.junit.After;
73-
import org.junit.Before;
74-
import org.junit.Rule;
75-
import org.junit.Test;
76-
import org.junit.rules.TestName;
74+
import org.junit.jupiter.api.AfterEach;
75+
import org.junit.jupiter.api.BeforeEach;
76+
import org.junit.jupiter.api.Test;
77+
import org.junit.jupiter.api.Timeout;
7778
import org.mockito.Mockito;
7879
import org.mockito.stubbing.Stubber;
7980

@@ -98,10 +99,11 @@ public class TestQuorumJournalManager {
9899
GenericTestUtils.setLogLevel(ProtobufRpcEngine2.LOG, Level.TRACE);
99100
}
100101

101-
@Rule
102+
@SuppressWarnings("checkstyle:VisibilityModifier")
103+
@RegisterExtension
102104
public TestName name = new TestName();
103105

104-
@Before
106+
@BeforeEach
105107
public void setup() throws Exception {
106108
conf = new Configuration();
107109
if (!name.getMethodName().equals("testSelectThreadCounts")) {
@@ -127,7 +129,7 @@ public void setup() throws Exception {
127129
assertEquals(1, qjm.getLoggerSetForTests().getEpoch());
128130
}
129131

130-
@After
132+
@AfterEach
131133
public void shutdown() throws IOException, InterruptedException,
132134
TimeoutException {
133135
IOUtils.cleanupWithLogger(LOG, toClose.toArray(new Closeable[0]));
@@ -808,7 +810,8 @@ public void testNewerVersionOfSegmentWins2() throws Exception {
808810
}
809811
}
810812

811-
@Test(timeout=20000)
813+
@Test
814+
@Timeout(value = 20)
812815
public void testCrashBetweenSyncLogAndPersistPaxosData() throws Exception {
813816
JournalFaultInjector faultInjector =
814817
JournalFaultInjector.instance = Mockito.mock(JournalFaultInjector.class);
@@ -1073,8 +1076,8 @@ public void testSelectThreadCounts() throws Exception {
10731076
.filter((t) -> t.getName().contains(expectedName)).count();
10741077
// The number of threads for the stopped jn shouldn't be more than the
10751078
// configured value.
1076-
assertTrue("Number of threads are : " + num,
1077-
num <= DFSConfigKeys.DFS_QJOURNAL_PARALLEL_READ_NUM_THREADS_DEFAULT);
1079+
assertTrue(num <= DFSConfigKeys.DFS_QJOURNAL_PARALLEL_READ_NUM_THREADS_DEFAULT,
1080+
"Number of threads are : " + num);
10781081
}
10791082

10801083
@Test

0 commit comments

Comments
 (0)