Skip to content

Commit d2f80c0

Browse files
committed
HADOOP-19434. [JDK17] Upgrade JUnit from 4 to 5 in hadoop-federation-balance.
1 parent 0984bbd commit d2f80c0

File tree

4 files changed

+53
-41
lines changed

4 files changed

+53
-41
lines changed

hadoop-tools/hadoop-federation-balance/src/test/java/org/apache/hadoop/tools/fedbalance/TestDistCpProcedure.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@
3131
import org.apache.hadoop.tools.fedbalance.procedure.BalanceJob;
3232
import org.apache.hadoop.tools.fedbalance.procedure.BalanceProcedure.RetryException;
3333
import org.apache.hadoop.tools.fedbalance.procedure.BalanceProcedureScheduler;
34-
import org.junit.AfterClass;
35-
import org.junit.BeforeClass;
34+
import org.junit.jupiter.api.AfterAll;
35+
import org.junit.jupiter.api.BeforeAll;
3636
import org.junit.Rule;
37-
import org.junit.Test;
37+
import org.junit.jupiter.api.Test;
3838
import org.junit.rules.Timeout;
3939

4040
import java.io.IOException;
@@ -48,17 +48,17 @@
4848
import java.util.Random;
4949
import java.util.concurrent.TimeUnit;
5050

51-
import static junit.framework.TestCase.assertTrue;
51+
import static org.junit.jupiter.api.Assertions.assertTrue;
5252
import static org.apache.hadoop.tools.fedbalance.FedBalanceConfigs.SCHEDULER_JOURNAL_URI;
5353
import static org.apache.hadoop.test.GenericTestUtils.getMethodName;
5454
import static org.apache.hadoop.test.LambdaTestUtils.intercept;
5555
import static org.apache.hadoop.tools.fedbalance.FedBalanceConfigs.CURRENT_SNAPSHOT_NAME;
5656
import static org.apache.hadoop.tools.fedbalance.FedBalanceConfigs.LAST_SNAPSHOT_NAME;
5757
import static org.apache.hadoop.tools.fedbalance.FedBalanceConfigs.TrashOption;
58-
import static org.junit.Assert.assertNull;
59-
import static org.junit.Assert.assertFalse;
60-
import static org.junit.Assert.assertEquals;
61-
import static org.junit.Assert.assertNotEquals;
58+
import static org.junit.jupiter.api.Assertions.assertNull;
59+
import static org.junit.jupiter.api.Assertions.assertFalse;
60+
import static org.junit.jupiter.api.Assertions.assertEquals;
61+
import static org.junit.jupiter.api.Assertions.assertNotEquals;
6262

6363
/**
6464
* Test DistCpProcedure.
@@ -82,7 +82,7 @@ public class TestDistCpProcedure {
8282
// DataStreamer#waitAndQueuePacket, so we set a larger global timeout.
8383
public Timeout globalTimeout = new Timeout(180000, TimeUnit.MILLISECONDS);
8484

85-
@BeforeClass
85+
@BeforeAll
8686
public static void beforeClass() throws IOException {
8787
DistCpProcedure.enableForTest();
8888
conf = new Configuration();
@@ -98,7 +98,7 @@ public static void beforeClass() throws IOException {
9898
nnUri = FileSystem.getDefaultUri(conf).toString();
9999
}
100100

101-
@AfterClass
101+
@AfterAll
102102
public static void afterClass() {
103103
DistCpProcedure.disableForTest();
104104
if (cluster != null) {

hadoop-tools/hadoop-federation-balance/src/test/java/org/apache/hadoop/tools/fedbalance/TestFedBalance.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818
package org.apache.hadoop.tools.fedbalance;
1919

2020
import org.apache.hadoop.conf.Configuration;
21-
import org.junit.Test;
21+
import org.junit.jupiter.api.Test;
2222

23-
import static junit.framework.TestCase.assertNotNull;
23+
import static org.junit.jupiter.api.Assertions.assertNotNull;
2424
import static org.apache.hadoop.tools.fedbalance.FedBalanceConfigs.SCHEDULER_JOURNAL_URI;
2525
import static org.apache.hadoop.tools.fedbalance.FedBalanceConfigs.WORK_THREAD_NUM;
2626

hadoop-tools/hadoop-federation-balance/src/test/java/org/apache/hadoop/tools/fedbalance/TestTrashProcedure.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121
import org.apache.hadoop.fs.FileSystem;
2222
import org.apache.hadoop.fs.Path;
2323
import org.apache.hadoop.hdfs.MiniDFSCluster;
24-
import org.junit.AfterClass;
25-
import org.junit.BeforeClass;
26-
import org.junit.Test;
24+
import org.junit.jupiter.api.AfterAll;
25+
import org.junit.jupiter.api.BeforeAll;
26+
import org.junit.jupiter.api.Test;
2727

2828
import java.io.ByteArrayOutputStream;
2929
import java.io.DataOutput;
@@ -34,9 +34,9 @@
3434

3535
import static org.apache.hadoop.tools.fedbalance.FedBalanceConfigs.TrashOption;
3636
import static org.apache.hadoop.test.GenericTestUtils.getMethodName;
37-
import static org.junit.Assert.assertFalse;
38-
import static org.junit.Assert.assertTrue;
39-
import static org.junit.Assert.assertEquals;
37+
import static org.junit.jupiter.api.Assertions.assertFalse;
38+
import static org.junit.jupiter.api.Assertions.assertTrue;
39+
import static org.junit.jupiter.api.Assertions.assertEquals;
4040

4141
/**
4242
* Test TrashProcedure.
@@ -47,15 +47,15 @@ public class TestTrashProcedure {
4747
private static MiniDFSCluster cluster;
4848
private static String nnUri;
4949

50-
@BeforeClass
50+
@BeforeAll
5151
public static void beforeClass() throws IOException {
5252
conf = new Configuration();
5353
cluster = new MiniDFSCluster.Builder(conf).numDataNodes(2).build();
5454
cluster.waitActive();
5555
nnUri = FileSystem.getDefaultUri(conf).toString();
5656
}
5757

58-
@AfterClass
58+
@AfterAll
5959
public static void afterClass() {
6060
if (cluster != null) {
6161
cluster.shutdown();

hadoop-tools/hadoop-federation-balance/src/test/java/org/apache/hadoop/tools/fedbalance/procedure/TestBalanceProcedureScheduler.java

Lines changed: 33 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,10 @@
2626
import org.apache.hadoop.test.GenericTestUtils;
2727
import org.apache.hadoop.util.ReflectionUtils;
2828
import org.apache.hadoop.util.Time;
29-
import org.junit.BeforeClass;
30-
import org.junit.AfterClass;
31-
import org.junit.Test;
29+
import org.junit.jupiter.api.BeforeAll;
30+
import org.junit.jupiter.api.AfterAll;
31+
import org.junit.jupiter.api.Test;
32+
import org.junit.jupiter.api.Timeout;
3233
import org.mockito.Mockito;
3334

3435
import java.io.IOException;
@@ -46,11 +47,11 @@
4647
import static org.apache.hadoop.tools.fedbalance.FedBalanceConfigs.SCHEDULER_JOURNAL_URI;
4748
import static org.apache.hadoop.tools.fedbalance.FedBalanceConfigs.WORK_THREAD_NUM;
4849
import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_NAMENODE_ACLS_ENABLED_KEY;
49-
import static org.junit.Assert.assertNull;
50-
import static org.junit.Assert.assertEquals;
51-
import static org.junit.Assert.assertTrue;
52-
import static org.junit.Assert.assertFalse;
53-
import static org.junit.Assert.assertNotSame;
50+
import static org.junit.jupiter.api.Assertions.assertNull;
51+
import static org.junit.jupiter.api.Assertions.assertEquals;
52+
import static org.junit.jupiter.api.Assertions.assertTrue;
53+
import static org.junit.jupiter.api.Assertions.assertFalse;
54+
import static org.junit.jupiter.api.Assertions.assertNotSame;
5455
import static org.mockito.ArgumentMatchers.any;
5556

5657
/**
@@ -63,7 +64,7 @@ public class TestBalanceProcedureScheduler {
6364
private static DistributedFileSystem fs;
6465
private static final int DEFAULT_BLOCK_SIZE = 512;
6566

66-
@BeforeClass
67+
@BeforeAll
6768
public static void setup() throws IOException {
6869
CONF.setBoolean(DFSConfigKeys.DFS_NAMENODE_DELEGATION_TOKEN_ALWAYS_USE_KEY,
6970
true);
@@ -84,7 +85,7 @@ public static void setup() throws IOException {
8485
fs.mkdirs(new Path(workPath));
8586
}
8687

87-
@AfterClass
88+
@AfterAll
8889
public static void close() {
8990
if (cluster != null) {
9091
cluster.shutdown();
@@ -94,7 +95,8 @@ public static void close() {
9495
/**
9596
* Test the scheduler could be shutdown correctly.
9697
*/
97-
@Test(timeout = 60000)
98+
@Test
99+
@Timeout(value = 60)
98100
public void testShutdownScheduler() throws Exception {
99101
BalanceProcedureScheduler scheduler = new BalanceProcedureScheduler(CONF);
100102
scheduler.init(true);
@@ -115,7 +117,8 @@ public void testShutdownScheduler() throws Exception {
115117
/**
116118
* Test a successful job.
117119
*/
118-
@Test(timeout = 60000)
120+
@Test
121+
@Timeout(value = 60)
119122
public void testSuccessfulJob() throws Exception {
120123
BalanceProcedureScheduler scheduler = new BalanceProcedureScheduler(CONF);
121124
scheduler.init(true);
@@ -146,7 +149,8 @@ public void testSuccessfulJob() throws Exception {
146149
/**
147150
* Test a job fails and the error can be got.
148151
*/
149-
@Test(timeout = 60000)
152+
@Test
153+
@Timeout(value = 60)
150154
public void testFailedJob() throws Exception {
151155
BalanceProcedureScheduler scheduler = new BalanceProcedureScheduler(CONF);
152156
scheduler.init(true);
@@ -174,7 +178,8 @@ public void testFailedJob() throws Exception {
174178
* the last unfinished procedure, which is the first procedure without
175179
* journal.
176180
*/
177-
@Test(timeout = 60000)
181+
@Test
182+
@Timeout(value = 60)
178183
public void testGetJobAfterRecover() throws Exception {
179184
BalanceProcedureScheduler scheduler = new BalanceProcedureScheduler(CONF);
180185
scheduler.init(true);
@@ -238,7 +243,8 @@ public void testGetJobAfterRecover() throws Exception {
238243
/**
239244
* Test RetryException is handled correctly.
240245
*/
241-
@Test(timeout = 60000)
246+
@Test
247+
@Timeout(value = 60)
242248
public void testRetry() throws Exception {
243249
BalanceProcedureScheduler scheduler = new BalanceProcedureScheduler(CONF);
244250
scheduler.init(true);
@@ -265,7 +271,8 @@ public void testRetry() throws Exception {
265271
/**
266272
* Test schedule an empty job.
267273
*/
268-
@Test(timeout = 60000)
274+
@Test
275+
@Timeout(value = 60)
269276
public void testEmptyJob() throws Exception {
270277
BalanceProcedureScheduler scheduler = new BalanceProcedureScheduler(CONF);
271278
scheduler.init(true);
@@ -281,7 +288,8 @@ public void testEmptyJob() throws Exception {
281288
/**
282289
* Test serialization and deserialization of Job.
283290
*/
284-
@Test(timeout = 60000)
291+
@Test
292+
@Timeout(value = 60)
285293
public void testJobSerializeAndDeserialize() throws Exception {
286294
BalanceJob.Builder builder = new BalanceJob.Builder<RecordProcedure>();
287295
for (int i = 0; i < 5; i++) {
@@ -305,7 +313,8 @@ public void testJobSerializeAndDeserialize() throws Exception {
305313
/**
306314
* Test scheduler crashes and recovers.
307315
*/
308-
@Test(timeout = 180000)
316+
@Test
317+
@Timeout(value = 180)
309318
public void testSchedulerDownAndRecoverJob() throws Exception {
310319
BalanceProcedureScheduler scheduler = new BalanceProcedureScheduler(CONF);
311320
scheduler.init(true);
@@ -347,7 +356,8 @@ public void testSchedulerDownAndRecoverJob() throws Exception {
347356
}
348357
}
349358

350-
@Test(timeout = 60000)
359+
@Test
360+
@Timeout(value = 60)
351361
public void testRecoverJobFromJournal() throws Exception {
352362
BalanceJournal journal =
353363
ReflectionUtils.newInstance(BalanceJournalInfoHDFS.class, CONF);
@@ -374,7 +384,8 @@ public void testRecoverJobFromJournal() throws Exception {
374384
}
375385
}
376386

377-
@Test(timeout = 60000)
387+
@Test
388+
@Timeout(value = 60)
378389
public void testClearJournalFail() throws Exception {
379390
BalanceProcedureScheduler scheduler = new BalanceProcedureScheduler(CONF);
380391
scheduler.init(true);
@@ -404,7 +415,8 @@ public void testClearJournalFail() throws Exception {
404415
/**
405416
* Test the job will be recovered if writing journal fails.
406417
*/
407-
@Test(timeout = 60000)
418+
@Test
419+
@Timeout(value = 60)
408420
public void testJobRecoveryWhenWriteJournalFail() throws Exception {
409421
BalanceProcedureScheduler scheduler = new BalanceProcedureScheduler(CONF);
410422
scheduler.init(true);

0 commit comments

Comments
 (0)