Skip to content

Commit 1e139d5

Browse files
slfan1989cnaurothzhtttylz
authored
YARN-11258. [JDK17] Upgrade JUnit from 4 to 5 in hadoop-yarn-server-common. (#7437)
[JDK17] Upgrade JUnit from 4 to 5 in hadoop-yarn-server-common. Co-authored-by: Chris Nauroth <[email protected]> Co-authored-by: Hualong Zhang <[email protected]> Reviewed-by: Chris Nauroth <[email protected]> Reviewed-by: Hualong Zhang <[email protected]> Signed-off-by: Shilun Fan <[email protected]>
1 parent f1f27e1 commit 1e139d5

File tree

63 files changed

+1238
-1066
lines changed

Some content is hidden

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

63 files changed

+1238
-1066
lines changed

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/federation/store/impl/ZKFederationStateStoreOpDurations.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import org.apache.hadoop.classification.InterfaceAudience;
2020
import org.apache.hadoop.classification.InterfaceStability;
21+
import org.apache.hadoop.classification.VisibleForTesting;
2122
import org.apache.hadoop.metrics2.MetricsCollector;
2223
import org.apache.hadoop.metrics2.MetricsInfo;
2324
import org.apache.hadoop.metrics2.MetricsSource;
@@ -236,4 +237,9 @@ public void removeStoredTokenDuration(long startTime, long endTime) {
236237
public void getTokenByRouterStoreTokenDuration(long startTime, long endTime) {
237238
getTokenByRouterStoreToken.add(endTime - startTime);
238239
}
240+
241+
@VisibleForTesting
242+
protected ZKFederationStateStoreOpDurations resetOpDurations() {
243+
return new ZKFederationStateStoreOpDurations();
244+
}
239245
}

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/federation/store/impl/ZookeeperFederationStateStore.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2095,4 +2095,9 @@ private List<ApplicationHomeSubCluster> loadRouterApplications() throws Exceptio
20952095
}
20962096
return applicationHomeSubClusters;
20972097
}
2098+
2099+
@VisibleForTesting
2100+
public void resetOpDurations() {
2101+
opDurations = opDurations.resetOpDurations();
2102+
}
20982103
}

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/test/java/org/apache/hadoop/yarn/TestRPC.java

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,12 @@
8383
import org.apache.hadoop.yarn.server.api.protocolrecords.ReportNewCollectorInfoResponse;
8484
import org.apache.hadoop.yarn.server.api.records.AppCollectorData;
8585
import org.apache.hadoop.yarn.util.Records;
86-
import org.junit.Assert;
87-
import org.junit.Test;
86+
import org.junit.jupiter.api.Test;
87+
88+
import static org.junit.jupiter.api.Assertions.assertEquals;
89+
import static org.junit.jupiter.api.Assertions.assertNotNull;
90+
import static org.junit.jupiter.api.Assertions.assertTrue;
91+
import static org.junit.jupiter.api.Assertions.fail;
8892

8993
public class TestRPC {
9094

@@ -136,9 +140,9 @@ public void testUnknownCall() {
136140
try {
137141
proxy.getNewApplication(Records
138142
.newRecord(GetNewApplicationRequest.class));
139-
Assert.fail("Excepted RPC call to fail with unknown method.");
143+
fail("Excepted RPC call to fail with unknown method.");
140144
} catch (YarnException e) {
141-
Assert.assertTrue(e.getMessage().matches(
145+
assertTrue(e.getMessage().matches(
142146
"Unknown method getNewApplication called on.*"
143147
+ "org.apache.hadoop.yarn.proto.ApplicationClientProtocol"
144148
+ "\\$ApplicationClientProtocolService\\$BlockingInterface "
@@ -171,9 +175,9 @@ public void testRPCOnCollectorNodeManagerProtocol() throws IOException {
171175
try {
172176
unknownProxy.getNewApplication(Records
173177
.newRecord(GetNewApplicationRequest.class));
174-
Assert.fail("Excepted RPC call to fail with unknown method.");
178+
fail("Excepted RPC call to fail with unknown method.");
175179
} catch (YarnException e) {
176-
Assert.assertTrue(e.getMessage().matches(
180+
assertTrue(e.getMessage().matches(
177181
"Unknown method getNewApplication called on.*"
178182
+ "org.apache.hadoop.yarn.proto.ApplicationClientProtocol"
179183
+ "\\$ApplicationClientProtocolService\\$BlockingInterface "
@@ -195,7 +199,7 @@ public void testRPCOnCollectorNodeManagerProtocol() throws IOException {
195199
DEFAULT_APP_ID, DEFAULT_COLLECTOR_ADDR, null);
196200
proxy.reportNewCollectorInfo(request);
197201
} catch (YarnException e) {
198-
Assert.fail("RPC call failured is not expected here.");
202+
fail("RPC call failured is not expected here.");
199203
}
200204

201205
try {
@@ -204,17 +208,17 @@ public void testRPCOnCollectorNodeManagerProtocol() throws IOException {
204208
DEFAULT_APP_ID, DEFAULT_COLLECTOR_ADDR, DEFAULT_COLLECTOR_TOKEN);
205209
proxy.reportNewCollectorInfo(request);
206210
} catch (YarnException e) {
207-
Assert.fail("RPC call failured is not expected here.");
211+
fail("RPC call failured is not expected here.");
208212
}
209213

210214
// Verify empty request get YarnException back (by design in
211215
// DummyNMCollectorService)
212216
try {
213217
proxy.reportNewCollectorInfo(Records
214218
.newRecord(ReportNewCollectorInfoRequest.class));
215-
Assert.fail("Excepted RPC call to fail with YarnException.");
219+
fail("Excepted RPC call to fail with YarnException.");
216220
} catch (YarnException e) {
217-
Assert.assertTrue(e.getMessage().contains(ILLEGAL_NUMBER_MESSAGE));
221+
assertTrue(e.getMessage().contains(ILLEGAL_NUMBER_MESSAGE));
218222
}
219223

220224
// Verify request with a valid app ID
@@ -224,12 +228,12 @@ public void testRPCOnCollectorNodeManagerProtocol() throws IOException {
224228
ApplicationId.newInstance(0, 1));
225229
GetTimelineCollectorContextResponse response =
226230
proxy.getTimelineCollectorContext(request);
227-
Assert.assertEquals("test_user_id", response.getUserId());
228-
Assert.assertEquals("test_flow_name", response.getFlowName());
229-
Assert.assertEquals("test_flow_version", response.getFlowVersion());
230-
Assert.assertEquals(12345678L, response.getFlowRunId());
231+
assertEquals("test_user_id", response.getUserId());
232+
assertEquals("test_flow_name", response.getFlowName());
233+
assertEquals("test_flow_version", response.getFlowVersion());
234+
assertEquals(12345678L, response.getFlowRunId());
231235
} catch (YarnException | IOException e) {
232-
Assert.fail("RPC call failured is not expected here.");
236+
fail("RPC call failured is not expected here.");
233237
}
234238

235239
// Verify request with an invalid app ID
@@ -238,10 +242,10 @@ public void testRPCOnCollectorNodeManagerProtocol() throws IOException {
238242
GetTimelineCollectorContextRequest.newInstance(
239243
ApplicationId.newInstance(0, 2));
240244
proxy.getTimelineCollectorContext(request);
241-
Assert.fail("RPC call failured is expected here.");
245+
fail("RPC call failured is expected here.");
242246
} catch (YarnException | IOException e) {
243-
Assert.assertTrue(e instanceof YarnException);
244-
Assert.assertTrue(e.getMessage().contains(
247+
assertTrue(e instanceof YarnException);
248+
assertTrue(e.getMessage().contains(
245249
"The application is not found."));
246250
}
247251
server.stop();
@@ -309,17 +313,17 @@ private void test(String rpcClass) throws Exception {
309313
proxy.stopContainers(stopRequest);
310314
} catch (YarnException e) {
311315
exception = true;
312-
Assert.assertTrue(e.getMessage().contains(EXCEPTION_MSG));
313-
Assert.assertTrue(e.getMessage().contains(EXCEPTION_CAUSE));
316+
assertTrue(e.getMessage().contains(EXCEPTION_MSG));
317+
assertTrue(e.getMessage().contains(EXCEPTION_CAUSE));
314318
System.out.println("Test Exception is " + e.getMessage());
315319
} catch (Exception ex) {
316320
ex.printStackTrace();
317321
} finally {
318322
server.stop();
319323
}
320-
Assert.assertTrue(exception);
321-
Assert.assertNotNull(statuses.get(0));
322-
Assert.assertEquals(ContainerState.RUNNING, statuses.get(0).getState());
324+
assertTrue(exception);
325+
assertNotNull(statuses.get(0));
326+
assertEquals(ContainerState.RUNNING, statuses.get(0).getState());
323327
}
324328

325329
public class DummyContainerManager implements ContainerManagementProtocol {
@@ -468,11 +472,11 @@ public ReportNewCollectorInfoResponse reportNewCollectorInfo(
468472
if (appCollectors.size() == 1) {
469473
// check default appID and collectorAddr
470474
AppCollectorData appCollector = appCollectors.get(0);
471-
Assert.assertEquals(appCollector.getApplicationId(),
475+
assertEquals(appCollector.getApplicationId(),
472476
DEFAULT_APP_ID);
473-
Assert.assertEquals(appCollector.getCollectorAddr(),
477+
assertEquals(appCollector.getCollectorAddr(),
474478
DEFAULT_COLLECTOR_ADDR);
475-
Assert.assertTrue(appCollector.getCollectorToken() == null ||
479+
assertTrue(appCollector.getCollectorToken() == null ||
476480
appCollector.getCollectorToken().equals(DEFAULT_COLLECTOR_TOKEN));
477481
} else {
478482
throw new YarnException(ILLEGAL_NUMBER_MESSAGE);

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/test/java/org/apache/hadoop/yarn/TestResourceTrackerPBClientImpl.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,13 @@
3535
import org.apache.hadoop.yarn.server.api.protocolrecords.RegisterNodeManagerResponse;
3636
import org.apache.hadoop.yarn.server.api.protocolrecords.UnRegisterNodeManagerRequest;
3737
import org.apache.hadoop.yarn.server.api.protocolrecords.UnRegisterNodeManagerResponse;
38-
import org.junit.AfterClass;
39-
import org.junit.BeforeClass;
40-
import org.junit.Test;
38+
import org.junit.jupiter.api.AfterAll;
39+
import org.junit.jupiter.api.BeforeAll;
40+
import org.junit.jupiter.api.Test;
4141

42-
import static org.junit.Assert.*;
42+
import static org.junit.jupiter.api.Assertions.assertNotNull;
43+
import static org.junit.jupiter.api.Assertions.assertTrue;
44+
import static org.junit.jupiter.api.Assertions.fail;
4345

4446
/**
4547
* Test ResourceTrackerPBClientImpl. this class should have methods
@@ -52,7 +54,7 @@ public class TestResourceTrackerPBClientImpl {
5254
private final static org.apache.hadoop.yarn.factories.RecordFactory recordFactory = RecordFactoryProvider
5355
.getRecordFactory(null);
5456

55-
@BeforeClass
57+
@BeforeAll
5658
public static void start() {
5759
InetSocketAddress address = new InetSocketAddress(0);
5860
Configuration configuration = new Configuration();
@@ -67,7 +69,7 @@ public static void start() {
6769

6870
}
6971

70-
@AfterClass
72+
@AfterAll
7173
public static void stop() {
7274
if (server != null) {
7375
server.stop();

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/test/java/org/apache/hadoop/yarn/TestYSCRPCFactories.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@
2121
import java.io.IOException;
2222
import java.net.InetSocketAddress;
2323

24-
import org.junit.Assert;
25-
2624
import org.apache.hadoop.conf.Configuration;
2725
import org.apache.hadoop.ipc.Server;
2826
import org.apache.hadoop.net.NetUtils;
@@ -37,7 +35,9 @@
3735
import org.apache.hadoop.yarn.server.api.protocolrecords.RegisterNodeManagerResponse;
3836
import org.apache.hadoop.yarn.server.api.protocolrecords.UnRegisterNodeManagerRequest;
3937
import org.apache.hadoop.yarn.server.api.protocolrecords.UnRegisterNodeManagerResponse;
40-
import org.junit.Test;
38+
import org.junit.jupiter.api.Test;
39+
40+
import static org.junit.jupiter.api.Assertions.fail;
4141

4242
public class TestYSCRPCFactories {
4343

@@ -64,7 +64,7 @@ private void testPbServerFactory() {
6464
server.start();
6565
} catch (YarnRuntimeException e) {
6666
e.printStackTrace();
67-
Assert.fail("Failed to create server");
67+
fail("Failed to create server");
6868
} finally {
6969
server.stop();
7070
}
@@ -90,12 +90,12 @@ private void testPbClientFactory() {
9090
client = (ResourceTracker) RpcClientFactoryPBImpl.get().getClient(ResourceTracker.class, 1, NetUtils.getConnectAddress(server), conf);
9191
} catch (YarnRuntimeException e) {
9292
e.printStackTrace();
93-
Assert.fail("Failed to create client");
93+
fail("Failed to create client");
9494
}
9595

9696
} catch (YarnRuntimeException e) {
9797
e.printStackTrace();
98-
Assert.fail("Failed to create server");
98+
fail("Failed to create server");
9999
} finally {
100100
server.stop();
101101
}

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/test/java/org/apache/hadoop/yarn/TestYSCRecordFactory.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,15 @@
1818

1919
package org.apache.hadoop.yarn;
2020

21-
import org.junit.Assert;
22-
2321
import org.apache.hadoop.yarn.exceptions.YarnRuntimeException;
2422
import org.apache.hadoop.yarn.factories.RecordFactory;
2523
import org.apache.hadoop.yarn.factories.impl.pb.RecordFactoryPBImpl;
2624
import org.apache.hadoop.yarn.server.api.protocolrecords.NodeHeartbeatRequest;
2725
import org.apache.hadoop.yarn.server.api.protocolrecords.impl.pb.NodeHeartbeatRequestPBImpl;
28-
import org.junit.Test;
26+
import org.junit.jupiter.api.Test;
27+
28+
import static org.junit.jupiter.api.Assertions.assertEquals;
29+
import static org.junit.jupiter.api.Assertions.fail;
2930

3031
public class TestYSCRecordFactory {
3132

@@ -34,10 +35,10 @@ public void testPbRecordFactory() {
3435
RecordFactory pbRecordFactory = RecordFactoryPBImpl.get();
3536
try {
3637
NodeHeartbeatRequest request = pbRecordFactory.newRecordInstance(NodeHeartbeatRequest.class);
37-
Assert.assertEquals(NodeHeartbeatRequestPBImpl.class, request.getClass());
38+
assertEquals(NodeHeartbeatRequestPBImpl.class, request.getClass());
3839
} catch (YarnRuntimeException e) {
3940
e.printStackTrace();
40-
Assert.fail("Failed to crete record");
41+
fail("Failed to crete record");
4142
}
4243

4344
}

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/test/java/org/apache/hadoop/yarn/TestYarnServerApiClasses.java

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,11 @@
1818

1919
package org.apache.hadoop.yarn;
2020

21-
import static org.junit.Assert.assertEquals;
22-
import static org.junit.Assert.assertFalse;
23-
import static org.junit.Assert.assertTrue;
21+
import static org.junit.jupiter.api.Assertions.assertEquals;
22+
import static org.junit.jupiter.api.Assertions.assertFalse;
23+
import static org.junit.jupiter.api.Assertions.assertNotNull;
24+
import static org.junit.jupiter.api.Assertions.assertNull;
25+
import static org.junit.jupiter.api.Assertions.assertTrue;
2426

2527
import java.io.IOException;
2628
import java.nio.ByteBuffer;
@@ -63,8 +65,7 @@
6365
import org.apache.hadoop.yarn.server.api.records.impl.pb.MasterKeyPBImpl;
6466
import org.apache.hadoop.yarn.server.api.records.impl.pb.NodeStatusPBImpl;
6567
import org.apache.hadoop.yarn.server.utils.YarnServerBuilderUtils;
66-
import org.junit.Assert;
67-
import org.junit.Test;
68+
import org.junit.jupiter.api.Test;
6869

6970
/**
7071
* Simple test classes from org.apache.hadoop.yarn.server.api
@@ -127,14 +128,14 @@ public void testNodeHeartbeatRequestPBImpl() {
127128
assertEquals("localhost", copy.getNodeStatus().getNodeId().getHost());
128129
assertEquals(collectors, copy.getRegisteringCollectors());
129130
// check labels are coming with valid values
130-
Assert.assertTrue(original.getNodeLabels()
131+
assertTrue(original.getNodeLabels()
131132
.containsAll(copy.getNodeLabels()));
132133
// check for empty labels
133134
original.setNodeLabels(new HashSet<NodeLabel> ());
134135
copy = new NodeHeartbeatRequestPBImpl(
135136
original.getProto());
136-
Assert.assertNotNull(copy.getNodeLabels());
137-
Assert.assertEquals(0, copy.getNodeLabels().size());
137+
assertNotNull(copy.getNodeLabels());
138+
assertEquals(0, copy.getNodeLabels().size());
138139
}
139140

140141
@Test
@@ -155,7 +156,7 @@ public void testNodeHeartbeatRequestPBImplWithNullLabels() {
155156
NodeHeartbeatRequestPBImpl original = new NodeHeartbeatRequestPBImpl();
156157
NodeHeartbeatRequestPBImpl copy =
157158
new NodeHeartbeatRequestPBImpl(original.getProto());
158-
Assert.assertNull(copy.getNodeLabels());
159+
assertNull(copy.getNodeLabels());
159160
}
160161

161162
/**
@@ -218,7 +219,7 @@ public void testNodeHeartbeatResponsePBImpl() throws IOException {
218219
YarnServerBuilderUtils
219220
.convertFromProtoFormat(copy.getSystemCredentialsForApps())
220221
.get(getApplicationId(1));
221-
Assert.assertNotNull(buffer);
222+
assertNotNull(buffer);
222223
buffer.rewind();
223224
buf.reset(buffer);
224225
credentials1Out.readTokenStorageStream(buf);
@@ -370,7 +371,7 @@ public void testRegisterNodeManagerRequestWithNullLabels() {
370371
((RegisterNodeManagerRequestPBImpl) request).getProto());
371372

372373
// check labels are coming with no values
373-
Assert.assertNull(request1.getNodeLabels());
374+
assertNull(request1.getNodeLabels());
374375
}
375376

376377
@Test
@@ -387,14 +388,14 @@ public void testRegisterNodeManagerRequestWithValidLabels() {
387388
((RegisterNodeManagerRequestPBImpl) request).getProto());
388389

389390
// check labels are coming with valid values
390-
Assert.assertEquals(true, nodeLabels.containsAll(copy.getNodeLabels()));
391+
assertEquals(true, nodeLabels.containsAll(copy.getNodeLabels()));
391392

392393
// check for empty labels
393394
request.setNodeLabels(new HashSet<NodeLabel> ());
394395
copy = new RegisterNodeManagerRequestPBImpl(
395396
((RegisterNodeManagerRequestPBImpl) request).getProto());
396-
Assert.assertNotNull(copy.getNodeLabels());
397-
Assert.assertEquals(0, copy.getNodeLabels().size());
397+
assertNotNull(copy.getNodeLabels());
398+
assertEquals(0, copy.getNodeLabels().size());
398399
}
399400

400401
@Test
@@ -405,7 +406,7 @@ public void testUnRegisterNodeManagerRequestPBImpl() throws Exception {
405406

406407
UnRegisterNodeManagerRequestPBImpl copy = new UnRegisterNodeManagerRequestPBImpl(
407408
request.getProto());
408-
Assert.assertEquals(nodeId, copy.getNodeId());
409+
assertEquals(nodeId, copy.getNodeId());
409410
}
410411

411412
private HashSet<NodeLabel> getValidNodeLabels() {

0 commit comments

Comments
 (0)