Skip to content

Commit e9e0549

Browse files
author
fanshilun
committed
YARN-11258. [JDK17] Upgrade JUnit from 4 to 5 in hadoop-yarn-server-common.
1 parent c42469e commit e9e0549

File tree

61 files changed

+1082
-1004
lines changed

Some content is hidden

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

61 files changed

+1082
-1004
lines changed

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

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@
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.Assertions;
87+
import org.junit.jupiter.api.Test;
8888

8989
public class TestRPC {
9090

@@ -136,9 +136,9 @@ public void testUnknownCall() {
136136
try {
137137
proxy.getNewApplication(Records
138138
.newRecord(GetNewApplicationRequest.class));
139-
Assert.fail("Excepted RPC call to fail with unknown method.");
139+
Assertions.fail("Excepted RPC call to fail with unknown method.");
140140
} catch (YarnException e) {
141-
Assert.assertTrue(e.getMessage().matches(
141+
Assertions.assertTrue(e.getMessage().matches(
142142
"Unknown method getNewApplication called on.*"
143143
+ "org.apache.hadoop.yarn.proto.ApplicationClientProtocol"
144144
+ "\\$ApplicationClientProtocolService\\$BlockingInterface "
@@ -171,9 +171,9 @@ public void testRPCOnCollectorNodeManagerProtocol() throws IOException {
171171
try {
172172
unknownProxy.getNewApplication(Records
173173
.newRecord(GetNewApplicationRequest.class));
174-
Assert.fail("Excepted RPC call to fail with unknown method.");
174+
Assertions.fail("Excepted RPC call to fail with unknown method.");
175175
} catch (YarnException e) {
176-
Assert.assertTrue(e.getMessage().matches(
176+
Assertions.assertTrue(e.getMessage().matches(
177177
"Unknown method getNewApplication called on.*"
178178
+ "org.apache.hadoop.yarn.proto.ApplicationClientProtocol"
179179
+ "\\$ApplicationClientProtocolService\\$BlockingInterface "
@@ -195,7 +195,7 @@ public void testRPCOnCollectorNodeManagerProtocol() throws IOException {
195195
DEFAULT_APP_ID, DEFAULT_COLLECTOR_ADDR, null);
196196
proxy.reportNewCollectorInfo(request);
197197
} catch (YarnException e) {
198-
Assert.fail("RPC call failured is not expected here.");
198+
Assertions.fail("RPC call failured is not expected here.");
199199
}
200200

201201
try {
@@ -204,17 +204,17 @@ public void testRPCOnCollectorNodeManagerProtocol() throws IOException {
204204
DEFAULT_APP_ID, DEFAULT_COLLECTOR_ADDR, DEFAULT_COLLECTOR_TOKEN);
205205
proxy.reportNewCollectorInfo(request);
206206
} catch (YarnException e) {
207-
Assert.fail("RPC call failured is not expected here.");
207+
Assertions.fail("RPC call failured is not expected here.");
208208
}
209209

210210
// Verify empty request get YarnException back (by design in
211211
// DummyNMCollectorService)
212212
try {
213213
proxy.reportNewCollectorInfo(Records
214214
.newRecord(ReportNewCollectorInfoRequest.class));
215-
Assert.fail("Excepted RPC call to fail with YarnException.");
215+
Assertions.fail("Excepted RPC call to fail with YarnException.");
216216
} catch (YarnException e) {
217-
Assert.assertTrue(e.getMessage().contains(ILLEGAL_NUMBER_MESSAGE));
217+
Assertions.assertTrue(e.getMessage().contains(ILLEGAL_NUMBER_MESSAGE));
218218
}
219219

220220
// Verify request with a valid app ID
@@ -224,12 +224,12 @@ public void testRPCOnCollectorNodeManagerProtocol() throws IOException {
224224
ApplicationId.newInstance(0, 1));
225225
GetTimelineCollectorContextResponse response =
226226
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());
227+
Assertions.assertEquals("test_user_id", response.getUserId());
228+
Assertions.assertEquals("test_flow_name", response.getFlowName());
229+
Assertions.assertEquals("test_flow_version", response.getFlowVersion());
230+
Assertions.assertEquals(12345678L, response.getFlowRunId());
231231
} catch (YarnException | IOException e) {
232-
Assert.fail("RPC call failured is not expected here.");
232+
Assertions.fail("RPC call failured is not expected here.");
233233
}
234234

235235
// Verify request with an invalid app ID
@@ -238,10 +238,10 @@ public void testRPCOnCollectorNodeManagerProtocol() throws IOException {
238238
GetTimelineCollectorContextRequest.newInstance(
239239
ApplicationId.newInstance(0, 2));
240240
proxy.getTimelineCollectorContext(request);
241-
Assert.fail("RPC call failured is expected here.");
241+
Assertions.fail("RPC call failured is expected here.");
242242
} catch (YarnException | IOException e) {
243-
Assert.assertTrue(e instanceof YarnException);
244-
Assert.assertTrue(e.getMessage().contains(
243+
Assertions.assertTrue(e instanceof YarnException);
244+
Assertions.assertTrue(e.getMessage().contains(
245245
"The application is not found."));
246246
}
247247
server.stop();
@@ -309,17 +309,17 @@ private void test(String rpcClass) throws Exception {
309309
proxy.stopContainers(stopRequest);
310310
} catch (YarnException e) {
311311
exception = true;
312-
Assert.assertTrue(e.getMessage().contains(EXCEPTION_MSG));
313-
Assert.assertTrue(e.getMessage().contains(EXCEPTION_CAUSE));
312+
Assertions.assertTrue(e.getMessage().contains(EXCEPTION_MSG));
313+
Assertions.assertTrue(e.getMessage().contains(EXCEPTION_CAUSE));
314314
System.out.println("Test Exception is " + e.getMessage());
315315
} catch (Exception ex) {
316316
ex.printStackTrace();
317317
} finally {
318318
server.stop();
319319
}
320-
Assert.assertTrue(exception);
321-
Assert.assertNotNull(statuses.get(0));
322-
Assert.assertEquals(ContainerState.RUNNING, statuses.get(0).getState());
320+
Assertions.assertTrue(exception);
321+
Assertions.assertNotNull(statuses.get(0));
322+
Assertions.assertEquals(ContainerState.RUNNING, statuses.get(0).getState());
323323
}
324324

325325
public class DummyContainerManager implements ContainerManagementProtocol {
@@ -468,11 +468,11 @@ public ReportNewCollectorInfoResponse reportNewCollectorInfo(
468468
if (appCollectors.size() == 1) {
469469
// check default appID and collectorAddr
470470
AppCollectorData appCollector = appCollectors.get(0);
471-
Assert.assertEquals(appCollector.getApplicationId(),
471+
Assertions.assertEquals(appCollector.getApplicationId(),
472472
DEFAULT_APP_ID);
473-
Assert.assertEquals(appCollector.getCollectorAddr(),
473+
Assertions.assertEquals(appCollector.getCollectorAddr(),
474474
DEFAULT_COLLECTOR_ADDR);
475-
Assert.assertTrue(appCollector.getCollectorToken() == null ||
475+
Assertions.assertTrue(appCollector.getCollectorToken() == null ||
476476
appCollector.getCollectorToken().equals(DEFAULT_COLLECTOR_TOKEN));
477477
} else {
478478
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: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@
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.*;
4343

4444
/**
4545
* Test ResourceTrackerPBClientImpl. this class should have methods
@@ -52,7 +52,7 @@ public class TestResourceTrackerPBClientImpl {
5252
private final static org.apache.hadoop.yarn.factories.RecordFactory recordFactory = RecordFactoryProvider
5353
.getRecordFactory(null);
5454

55-
@BeforeClass
55+
@BeforeAll
5656
public static void start() {
5757
InetSocketAddress address = new InetSocketAddress(0);
5858
Configuration configuration = new Configuration();
@@ -67,7 +67,7 @@ public static void start() {
6767

6868
}
6969

70-
@AfterClass
70+
@AfterAll
7171
public static void stop() {
7272
if (server != null) {
7373
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: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import java.io.IOException;
2222
import java.net.InetSocketAddress;
2323

24-
import org.junit.Assert;
24+
import org.junit.jupiter.api.Assertions;
2525

2626
import org.apache.hadoop.conf.Configuration;
2727
import org.apache.hadoop.ipc.Server;
@@ -37,7 +37,7 @@
3737
import org.apache.hadoop.yarn.server.api.protocolrecords.RegisterNodeManagerResponse;
3838
import org.apache.hadoop.yarn.server.api.protocolrecords.UnRegisterNodeManagerRequest;
3939
import org.apache.hadoop.yarn.server.api.protocolrecords.UnRegisterNodeManagerResponse;
40-
import org.junit.Test;
40+
import org.junit.jupiter.api.Test;
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+
Assertions.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+
Assertions.fail("Failed to create client");
9494
}
9595

9696
} catch (YarnRuntimeException e) {
9797
e.printStackTrace();
98-
Assert.fail("Failed to create server");
98+
Assertions.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: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@
1818

1919
package org.apache.hadoop.yarn;
2020

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

2323
import org.apache.hadoop.yarn.exceptions.YarnRuntimeException;
2424
import org.apache.hadoop.yarn.factories.RecordFactory;
2525
import org.apache.hadoop.yarn.factories.impl.pb.RecordFactoryPBImpl;
2626
import org.apache.hadoop.yarn.server.api.protocolrecords.NodeHeartbeatRequest;
2727
import org.apache.hadoop.yarn.server.api.protocolrecords.impl.pb.NodeHeartbeatRequestPBImpl;
28-
import org.junit.Test;
28+
import org.junit.jupiter.api.Test;
2929

3030
public class TestYSCRecordFactory {
3131

@@ -34,10 +34,10 @@ public void testPbRecordFactory() {
3434
RecordFactory pbRecordFactory = RecordFactoryPBImpl.get();
3535
try {
3636
NodeHeartbeatRequest request = pbRecordFactory.newRecordInstance(NodeHeartbeatRequest.class);
37-
Assert.assertEquals(NodeHeartbeatRequestPBImpl.class, request.getClass());
37+
Assertions.assertEquals(NodeHeartbeatRequestPBImpl.class, request.getClass());
3838
} catch (YarnRuntimeException e) {
3939
e.printStackTrace();
40-
Assert.fail("Failed to crete record");
40+
Assertions.fail("Failed to crete record");
4141
}
4242

4343
}

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

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
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.assertTrue;
2424

2525
import java.io.IOException;
2626
import java.nio.ByteBuffer;
@@ -63,8 +63,8 @@
6363
import org.apache.hadoop.yarn.server.api.records.impl.pb.MasterKeyPBImpl;
6464
import org.apache.hadoop.yarn.server.api.records.impl.pb.NodeStatusPBImpl;
6565
import org.apache.hadoop.yarn.server.utils.YarnServerBuilderUtils;
66-
import org.junit.Assert;
67-
import org.junit.Test;
66+
import org.junit.jupiter.api.Assertions;
67+
import org.junit.jupiter.api.Test;
6868

6969
/**
7070
* Simple test classes from org.apache.hadoop.yarn.server.api
@@ -127,14 +127,14 @@ public void testNodeHeartbeatRequestPBImpl() {
127127
assertEquals("localhost", copy.getNodeStatus().getNodeId().getHost());
128128
assertEquals(collectors, copy.getRegisteringCollectors());
129129
// check labels are coming with valid values
130-
Assert.assertTrue(original.getNodeLabels()
130+
Assertions.assertTrue(original.getNodeLabels()
131131
.containsAll(copy.getNodeLabels()));
132132
// check for empty labels
133133
original.setNodeLabels(new HashSet<NodeLabel> ());
134134
copy = new NodeHeartbeatRequestPBImpl(
135135
original.getProto());
136-
Assert.assertNotNull(copy.getNodeLabels());
137-
Assert.assertEquals(0, copy.getNodeLabels().size());
136+
Assertions.assertNotNull(copy.getNodeLabels());
137+
Assertions.assertEquals(0, copy.getNodeLabels().size());
138138
}
139139

140140
@Test
@@ -155,7 +155,7 @@ public void testNodeHeartbeatRequestPBImplWithNullLabels() {
155155
NodeHeartbeatRequestPBImpl original = new NodeHeartbeatRequestPBImpl();
156156
NodeHeartbeatRequestPBImpl copy =
157157
new NodeHeartbeatRequestPBImpl(original.getProto());
158-
Assert.assertNull(copy.getNodeLabels());
158+
Assertions.assertNull(copy.getNodeLabels());
159159
}
160160

161161
/**
@@ -218,7 +218,7 @@ public void testNodeHeartbeatResponsePBImpl() throws IOException {
218218
YarnServerBuilderUtils
219219
.convertFromProtoFormat(copy.getSystemCredentialsForApps())
220220
.get(getApplicationId(1));
221-
Assert.assertNotNull(buffer);
221+
Assertions.assertNotNull(buffer);
222222
buffer.rewind();
223223
buf.reset(buffer);
224224
credentials1Out.readTokenStorageStream(buf);
@@ -370,7 +370,7 @@ public void testRegisterNodeManagerRequestWithNullLabels() {
370370
((RegisterNodeManagerRequestPBImpl) request).getProto());
371371

372372
// check labels are coming with no values
373-
Assert.assertNull(request1.getNodeLabels());
373+
Assertions.assertNull(request1.getNodeLabels());
374374
}
375375

376376
@Test
@@ -387,14 +387,14 @@ public void testRegisterNodeManagerRequestWithValidLabels() {
387387
((RegisterNodeManagerRequestPBImpl) request).getProto());
388388

389389
// check labels are coming with valid values
390-
Assert.assertEquals(true, nodeLabels.containsAll(copy.getNodeLabels()));
390+
Assertions.assertEquals(true, nodeLabels.containsAll(copy.getNodeLabels()));
391391

392392
// check for empty labels
393393
request.setNodeLabels(new HashSet<NodeLabel> ());
394394
copy = new RegisterNodeManagerRequestPBImpl(
395395
((RegisterNodeManagerRequestPBImpl) request).getProto());
396-
Assert.assertNotNull(copy.getNodeLabels());
397-
Assert.assertEquals(0, copy.getNodeLabels().size());
396+
Assertions.assertNotNull(copy.getNodeLabels());
397+
Assertions.assertEquals(0, copy.getNodeLabels().size());
398398
}
399399

400400
@Test
@@ -405,7 +405,7 @@ public void testUnRegisterNodeManagerRequestPBImpl() throws Exception {
405405

406406
UnRegisterNodeManagerRequestPBImpl copy = new UnRegisterNodeManagerRequestPBImpl(
407407
request.getProto());
408-
Assert.assertEquals(nodeId, copy.getNodeId());
408+
Assertions.assertEquals(nodeId, copy.getNodeId());
409409
}
410410

411411
private HashSet<NodeLabel> getValidNodeLabels() {

0 commit comments

Comments
 (0)