Skip to content

Commit 18f7617

Browse files
zhtttylzcnauroth
authored andcommitted
HDFS-17720.[JDK17] Upgrade JUnit from 4 to 5 in hadoop-hdfs-rbf Part2.
Closes #7531 Signed-off-by: Shilun Fan <slfan1989@apache.org> Signed-off-by: Chris Nauroth <cnauroth@apache.org>
1 parent 9f7aa72 commit 18f7617

File tree

70 files changed

+867
-918
lines changed

Some content is hidden

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

70 files changed

+867
-918
lines changed

hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/fairness/TestRouterAsyncRpcFairnessPolicyController.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
import org.apache.hadoop.hdfs.server.federation.router.RBFConfigKeys;
2525
import org.apache.hadoop.test.GenericTestUtils;
2626
import org.apache.hadoop.util.Time;
27-
import org.junit.Test;
27+
import org.junit.jupiter.api.Test;
2828
import org.slf4j.LoggerFactory;
2929

3030
import java.util.concurrent.TimeUnit;
@@ -34,9 +34,9 @@
3434
import static org.apache.hadoop.hdfs.server.federation.router.RBFConfigKeys.DFS_ROUTER_ASYNC_RPC_MAX_ASYNC_CALL_PERMIT_DEFAULT;
3535
import static org.apache.hadoop.hdfs.server.federation.router.RBFConfigKeys.DFS_ROUTER_FAIRNESS_ACQUIRE_TIMEOUT;
3636
import static org.apache.hadoop.hdfs.server.federation.router.RBFConfigKeys.DFS_ROUTER_MONITOR_NAMENODE;
37-
import static org.junit.Assert.assertEquals;
38-
import static org.junit.Assert.assertFalse;
39-
import static org.junit.Assert.assertTrue;
37+
import static org.junit.jupiter.api.Assertions.assertEquals;
38+
import static org.junit.jupiter.api.Assertions.assertFalse;
39+
import static org.junit.jupiter.api.Assertions.assertTrue;
4040

4141
/**
4242
* Test functionality of {@link RouterAsyncRpcFairnessPolicyController).
@@ -116,8 +116,8 @@ private void verifyInstantiationStatus(Configuration conf, int permits) {
116116
}
117117
String infoMsg = String.format(
118118
RouterAsyncRpcFairnessPolicyController.INIT_MSG, permits);
119-
assertTrue("Should contain info message: " + infoMsg,
120-
logs.getOutput().contains(infoMsg));
119+
assertTrue(logs.getOutput().contains(infoMsg), "Should contain info message: " +
120+
infoMsg);
121121
}
122122

123123
private RouterRpcFairnessPolicyController getFairnessPolicyController(

hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/router/TestConnectionManager.java

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -27,23 +27,22 @@
2727
import org.apache.hadoop.security.UserGroupInformation;
2828
import org.apache.hadoop.test.GenericTestUtils;
2929
import org.apache.hadoop.test.LambdaTestUtils;
30-
import org.junit.After;
31-
import org.junit.Before;
32-
import org.junit.Test;
33-
import org.junit.Rule;
34-
import org.junit.rules.ExpectedException;
30+
import org.junit.jupiter.api.AfterEach;
31+
import org.junit.jupiter.api.BeforeEach;
32+
import org.junit.jupiter.api.Test;
3533

3634
import java.io.IOException;
3735
import java.util.HashMap;
3836
import java.util.Map;
3937
import java.util.concurrent.ArrayBlockingQueue;
4038
import java.util.concurrent.BlockingQueue;
4139

42-
import static org.junit.Assert.assertEquals;
43-
import static org.junit.Assert.assertFalse;
44-
import static org.junit.Assert.assertTrue;
45-
import static org.junit.Assert.fail;
46-
import static org.junit.Assert.assertNotNull;
40+
import static org.junit.jupiter.api.Assertions.assertEquals;
41+
import static org.junit.jupiter.api.Assertions.assertFalse;
42+
import static org.junit.jupiter.api.Assertions.assertThrows;
43+
import static org.junit.jupiter.api.Assertions.assertTrue;
44+
import static org.junit.jupiter.api.Assertions.fail;
45+
import static org.junit.jupiter.api.Assertions.assertNotNull;
4746

4847
/**
4948
* Test functionalities of {@link ConnectionManager}, which manages a pool
@@ -62,7 +61,7 @@ public class TestConnectionManager {
6261
private static final String TEST_NN_ADDRESS = "nn1:8080";
6362
private static final String UNRESOLVED_TEST_NN_ADDRESS = "unknownhost:8080";
6463

65-
@Before
64+
@BeforeEach
6665
public void setup() throws Exception {
6766
conf = new Configuration();
6867
connManager = new ConnectionManager(conf);
@@ -71,10 +70,7 @@ public void setup() throws Exception {
7170
connManager.start();
7271
}
7372

74-
@Rule
75-
public ExpectedException exceptionRule = ExpectedException.none();
76-
77-
@After
73+
@AfterEach
7874
public void shutdown() {
7975
if (connManager != null) {
8076
connManager.close();
@@ -199,13 +195,13 @@ public void testConnectionCreatorWithException() throws Exception {
199195
@Test
200196
public void testGetConnectionWithException() throws Exception {
201197
String exceptionCause = "java.net.UnknownHostException: unknownhost";
202-
exceptionRule.expect(IllegalArgumentException.class);
203-
exceptionRule.expectMessage(exceptionCause);
204198

205-
// Create a bad connection pool pointing to unresolvable namenode address.
206-
ConnectionPool badPool = new ConnectionPool(
207-
conf, UNRESOLVED_TEST_NN_ADDRESS, TEST_USER1, 1, 10, 0.5f,
208-
ClientProtocol.class, null);
199+
assertThrows(IllegalArgumentException.class, () -> {
200+
// Create a bad connection pool pointing to unresolvable namenode address.
201+
ConnectionPool badPool = new ConnectionPool(
202+
conf, UNRESOLVED_TEST_NN_ADDRESS, TEST_USER1, 1, 10, 0.5f,
203+
ClientProtocol.class, null);
204+
}, exceptionCause);
209205
}
210206

211207
@Test

hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/router/TestDFSRouter.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
*/
1818
package org.apache.hadoop.hdfs.server.federation.router;
1919

20-
import org.junit.Assert;
21-
import org.junit.Test;
20+
import org.junit.jupiter.api.Assertions;
21+
import org.junit.jupiter.api.Test;
2222

2323
import org.apache.hadoop.conf.Configuration;
2424
import org.apache.hadoop.ha.HAServiceProtocol;
@@ -29,7 +29,7 @@
2929

3030
import static org.apache.hadoop.hdfs.server.federation.FederationTestUtils.createNamenodeReport;
3131
import static org.apache.hadoop.hdfs.server.federation.router.RBFConfigKeys.FEDERATION_STORE_MEMBERSHIP_EXPIRATION_MS;
32-
import static org.junit.Assert.assertEquals;
32+
import static org.junit.jupiter.api.Assertions.assertEquals;
3333

3434
public class TestDFSRouter {
3535

@@ -40,8 +40,8 @@ public void testDefaultConfigs() {
4040
configuration.get(FedBalanceConfigs.SCHEDULER_JOURNAL_URI);
4141
int workerThreads =
4242
configuration.getInt(FedBalanceConfigs.WORK_THREAD_NUM, -1);
43-
Assert.assertEquals("hdfs://localhost:8020/tmp/procedure", journalUri);
44-
Assert.assertEquals(10, workerThreads);
43+
Assertions.assertEquals("hdfs://localhost:8020/tmp/procedure", journalUri);
44+
Assertions.assertEquals(10, workerThreads);
4545
}
4646

4747
@Test

hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/router/TestDisableNameservices.java

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919

2020
import static org.apache.hadoop.hdfs.server.federation.FederationTestUtils.simulateSlowNamenode;
2121
import static org.apache.hadoop.util.Time.monotonicNow;
22-
import static org.junit.Assert.assertEquals;
23-
import static org.junit.Assert.assertTrue;
22+
import static org.junit.jupiter.api.Assertions.assertEquals;
23+
import static org.junit.jupiter.api.Assertions.assertTrue;
2424

2525
import java.io.IOException;
2626
import java.util.Iterator;
@@ -50,10 +50,10 @@
5050
import org.apache.hadoop.hdfs.server.federation.store.records.MountTable;
5151
import org.apache.hadoop.hdfs.server.namenode.NameNode;
5252
import org.codehaus.jettison.json.JSONObject;
53-
import org.junit.After;
54-
import org.junit.AfterClass;
55-
import org.junit.BeforeClass;
56-
import org.junit.Test;
53+
import org.junit.jupiter.api.AfterEach;
54+
import org.junit.jupiter.api.AfterAll;
55+
import org.junit.jupiter.api.BeforeAll;
56+
import org.junit.jupiter.api.Test;
5757

5858
/**
5959
* Test the behavior when disabling name services.
@@ -65,7 +65,7 @@ public class TestDisableNameservices {
6565
private static RouterClient routerAdminClient;
6666
private static ClientProtocol routerProtocol;
6767

68-
@BeforeClass
68+
@BeforeAll
6969
public static void setUp() throws Exception {
7070
// Build and start a federated cluster
7171
cluster = new StateStoreDFSCluster(false, 2);
@@ -131,7 +131,7 @@ private static void setupNamespace() throws IOException {
131131
nn1.getFileSystem().mkdirs(new Path("/dirns1/1"));
132132
}
133133

134-
@AfterClass
134+
@AfterAll
135135
public static void tearDown() {
136136
if (cluster != null) {
137137
cluster.stopRouter(routerContext);
@@ -140,7 +140,7 @@ public static void tearDown() {
140140
}
141141
}
142142

143-
@After
143+
@AfterEach
144144
public void cleanup() throws IOException {
145145
Router router = routerContext.getRouter();
146146
StateStoreService stateStore = router.getStateStore();
@@ -161,8 +161,7 @@ public void testWithoutDisabling() throws IOException {
161161
long t0 = monotonicNow();
162162
routerProtocol.renewLease("client0", null);
163163
long t = monotonicNow() - t0;
164-
assertTrue("It took too little: " + t + "ms",
165-
t > TimeUnit.SECONDS.toMillis(1));
164+
assertTrue(t > TimeUnit.SECONDS.toMillis(1), "It took too little: " + t + "ms");
166165
// Return the results from all subclusters even if slow
167166
FileSystem routerFs = routerContext.getFileSystem();
168167
FileStatus[] filesStatus = routerFs.listStatus(new Path("/"));
@@ -180,8 +179,7 @@ public void testDisabling() throws Exception {
180179
long t0 = monotonicNow();
181180
routerProtocol.renewLease("client0", null);
182181
long t = monotonicNow() - t0;
183-
assertTrue("It took too long: " + t + "ms",
184-
t < TimeUnit.SECONDS.toMillis(1));
182+
assertTrue(t < TimeUnit.SECONDS.toMillis(1), "It took too long: " + t + "ms");
185183
// We should not report anything from ns0
186184
FileSystem routerFs = routerContext.getFileSystem();
187185

hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/router/TestDisableRouterQuota.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@
2424

2525
import org.apache.hadoop.test.GenericTestUtils;
2626
import org.apache.hadoop.test.LambdaTestUtils;
27-
import org.junit.AfterClass;
28-
import org.junit.Before;
29-
import org.junit.BeforeClass;
30-
import org.junit.Test;
27+
import org.junit.jupiter.api.AfterAll;
28+
import org.junit.jupiter.api.BeforeEach;
29+
import org.junit.jupiter.api.BeforeAll;
30+
import org.junit.jupiter.api.Test;
3131

32-
import static org.junit.Assert.assertFalse;
33-
import static org.junit.Assert.fail;
32+
import static org.junit.jupiter.api.Assertions.assertFalse;
33+
import static org.junit.jupiter.api.Assertions.fail;
3434

3535
/**
3636
* Test the behavior when disabling the Router quota.
@@ -39,7 +39,7 @@ public class TestDisableRouterQuota {
3939

4040
private static Router router;
4141

42-
@BeforeClass
42+
@BeforeAll
4343
public static void setUp() throws Exception {
4444
// Build and start a router
4545
router = new Router();
@@ -53,15 +53,15 @@ public static void setUp() throws Exception {
5353
router.start();
5454
}
5555

56-
@AfterClass
56+
@AfterAll
5757
public static void tearDown() throws IOException {
5858
if (router != null) {
5959
router.stop();
6060
router.close();
6161
}
6262
}
6363

64-
@Before
64+
@BeforeEach
6565
public void checkDisableQuota() {
6666
assertFalse(router.isQuotaEnabled());
6767
}

hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/router/TestFederationUtil.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@
2424
import org.apache.hadoop.hdfs.server.federation.resolver.ActiveNamenodeResolver;
2525
import org.apache.hadoop.hdfs.server.federation.resolver.FileSubclusterResolver;
2626
import org.apache.hadoop.hdfs.server.federation.store.StateStoreService;
27-
import org.junit.Test;
27+
import org.junit.jupiter.api.Test;
2828

29-
import static org.junit.Assert.assertNotNull;
29+
import static org.junit.jupiter.api.Assertions.assertNotNull;
3030
import static org.apache.hadoop.hdfs.server.federation.router.RBFConfigKeys.FEDERATION_FILE_RESOLVER_CLIENT_CLASS;
3131
import static org.apache.hadoop.hdfs.server.federation.router.RBFConfigKeys.FEDERATION_NAMENODE_RESOLVER_CLIENT_CLASS;
3232

hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/router/TestNoNamenodesAvailableLongTime.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@
3636
import org.apache.hadoop.hdfs.server.namenode.NameNode;
3737
import org.apache.hadoop.ipc.RemoteException;
3838
import org.apache.hadoop.util.Lists;
39-
import org.junit.After;
40-
import org.junit.Test;
39+
import org.junit.jupiter.api.AfterEach;
40+
import org.junit.jupiter.api.Test;
4141

4242

4343
import java.io.IOException;
@@ -47,9 +47,9 @@
4747
import static org.apache.hadoop.ha.HAServiceProtocol.HAServiceState.ACTIVE;
4848
import static org.apache.hadoop.hdfs.server.federation.MiniRouterDFSCluster.DEFAULT_HEARTBEAT_INTERVAL_MS;
4949
import static org.apache.hadoop.hdfs.server.namenode.AclTestHelpers.aclEntry;
50-
import static org.junit.Assert.assertEquals;
51-
import static org.junit.Assert.assertNotEquals;
52-
import static org.junit.Assert.assertTrue;
50+
import static org.junit.jupiter.api.Assertions.assertEquals;
51+
import static org.junit.jupiter.api.Assertions.assertNotEquals;
52+
import static org.junit.jupiter.api.Assertions.assertTrue;
5353

5454
/**
5555
* When failover occurs, the router may record that the ns has no active namenode
@@ -68,7 +68,7 @@ public class TestNoNamenodesAvailableLongTime {
6868
private RouterContext routerContext;
6969
private FederationRPCMetrics rpcMetrics;
7070

71-
@After
71+
@AfterEach
7272
public void cleanup() throws IOException {
7373
rpcMetrics = null;
7474
routerContext = null;

0 commit comments

Comments
 (0)