Skip to content

Commit 0984bbd

Browse files
authored
HADOOP-19440. [JDK17] Upgrade JUnit from 4 to 5 in hadoop-sls. (#7553)
1 parent 32929eb commit 0984bbd

File tree

13 files changed

+311
-260
lines changed

13 files changed

+311
-260
lines changed

hadoop-tools/hadoop-sls/src/test/java/org/apache/hadoop/yarn/sls/BaseSLSRunnerTest.java

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,11 @@
2222
import org.apache.hadoop.conf.Configuration;
2323
import org.apache.hadoop.yarn.conf.YarnConfiguration;
2424
import org.apache.hadoop.yarn.server.resourcemanager.monitor.invariants.MetricsInvariantChecker;
25-
import org.junit.After;
26-
import org.junit.Assert;
25+
import org.junit.jupiter.api.AfterEach;
26+
import org.junit.jupiter.api.Assertions;
2727
import org.junit.Assume;
28-
import org.junit.Before;
29-
import org.junit.BeforeClass;
30-
import org.junit.runner.RunWith;
31-
import org.junit.runners.Parameterized;
32-
import org.junit.runners.Parameterized.Parameter;
28+
import org.junit.jupiter.api.BeforeEach;
29+
import org.junit.jupiter.api.BeforeAll;
3330

3431
import java.io.File;
3532
import java.util.ArrayList;
@@ -42,37 +39,32 @@
4239
/**
4340
* This is a base class to ease the implementation of SLS-based tests.
4441
*/
45-
@RunWith(value = Parameterized.class)
4642
@NotThreadSafe
4743
@SuppressWarnings("VisibilityModifier")
4844
public abstract class BaseSLSRunnerTest {
4945

50-
@Parameter(value = 0)
5146
public String schedulerType;
5247

53-
@Parameter(value = 1)
5448
public String traceType;
5549

56-
@Parameter(value = 2)
5750
public String traceLocation;
5851

59-
@Parameter(value = 3)
6052
public String nodeFile;
6153

6254
protected SLSRunner sls;
6355
protected String ongoingInvariantFile;
6456
protected String exitInvariantFile;
6557

66-
@BeforeClass
58+
@BeforeAll
6759
public static void checkForJavaScript() {
6860
Assume.assumeNotNull("JavaScript engine not available (JEP 372)",
6961
new ScriptEngineManager().getEngineByName("JavaScript"));
7062
}
7163

72-
@Before
64+
@BeforeEach
7365
public abstract void setup();
7466

75-
@After
67+
@AfterEach
7668
public void tearDown() throws InterruptedException {
7769
if (sls != null) {
7870
sls.stop();
@@ -136,7 +128,7 @@ public void uncaughtException(Thread t, Throwable e) {
136128

137129
if (!exceptionList.isEmpty()) {
138130
sls.stop();
139-
Assert.fail("TestSLSRunner caught exception from child thread "
131+
Assertions.fail("TestSLSRunner caught exception from child thread "
140132
+ "(TaskRunner.TaskDefinition): " + exceptionList);
141133
break;
142134
}

hadoop-tools/hadoop-sls/src/test/java/org/apache/hadoop/yarn/sls/TestDagAMSimulator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@
2020

2121
import org.apache.hadoop.yarn.sls.appmaster.DAGAMSimulator;
2222
import org.apache.hadoop.yarn.sls.scheduler.ContainerSimulator;
23-
import org.junit.Test;
23+
import org.junit.jupiter.api.Test;
2424

2525
import java.util.ArrayList;
2626
import java.util.List;
2727

28-
import static org.junit.Assert.assertEquals;
28+
import static org.junit.jupiter.api.Assertions.assertEquals;
2929
import static org.mockito.Mockito.mock;
3030
import static org.mockito.Mockito.when;
3131

hadoop-tools/hadoop-sls/src/test/java/org/apache/hadoop/yarn/sls/TestReservationSystemInvariants.java

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,22 +27,19 @@
2727
import org.apache.hadoop.yarn.server.resourcemanager.monitor.invariants.ReservationInvariantsChecker;
2828
import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacityScheduler;
2929
import org.apache.hadoop.yarn.server.resourcemanager.scheduler.fair.FairScheduler;
30-
import org.junit.Test;
31-
import org.junit.runner.RunWith;
32-
import org.junit.runners.Parameterized;
33-
import org.junit.runners.Parameterized.Parameters;
30+
import org.junit.jupiter.api.Timeout;
31+
import org.junit.jupiter.params.ParameterizedTest;
32+
import org.junit.jupiter.params.provider.MethodSource;
3433

3534
import net.jcip.annotations.NotThreadSafe;
3635

3736
/**
3837
* This test performs an SLS run enabling a
3938
* {@code ReservationInvariantsChecker}.
4039
*/
41-
@RunWith(value = Parameterized.class)
4240
@NotThreadSafe
4341
public class TestReservationSystemInvariants extends BaseSLSRunnerTest {
4442

45-
@Parameters(name = "Testing with: {1}, {0}, (nodeFile {3})")
4643
public static Collection<Object[]> data() {
4744
// Test with both schedulers, and all three trace types
4845
return Arrays.asList(new Object[][] {
@@ -53,10 +50,22 @@ public static Collection<Object[]> data() {
5350
});
5451
}
5552

56-
@Test(timeout = 120000)
57-
@SuppressWarnings("all")
58-
public void testSimulatorRunning() throws Exception {
53+
public void initTestReservationSystemInvariants(String pSchedulerType,
54+
String pTraceType, String pTraceLocation, String pNodeFile) {
55+
this.schedulerType = pSchedulerType;
56+
this.traceType = pTraceType;
57+
this.traceLocation = pTraceLocation;
58+
this.nodeFile = pNodeFile;
59+
setup();
60+
}
5961

62+
@ParameterizedTest(name = "Testing with: {1}, {0}, (nodeFile {3})")
63+
@MethodSource("data")
64+
@Timeout(value = 120)
65+
@SuppressWarnings("all")
66+
public void testSimulatorRunning(String pSchedulerType,
67+
String pTraceType, String pTraceLocation, String pNodeFile) throws Exception {
68+
initTestReservationSystemInvariants(pSchedulerType, pTraceType, pTraceLocation, pNodeFile);
6069
Configuration conf = new Configuration(false);
6170
conf.set(YarnConfiguration.RM_SCHEDULER, schedulerType);
6271
conf.setBoolean(YarnConfiguration.RM_SCHEDULER_ENABLE_MONITORS, true);

hadoop-tools/hadoop-sls/src/test/java/org/apache/hadoop/yarn/sls/TestSLSDagAMSimulator.java

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,23 +22,20 @@
2222
import org.apache.hadoop.conf.Configuration;
2323
import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacityScheduler;
2424
import org.apache.hadoop.yarn.server.resourcemanager.scheduler.fair.FairScheduler;
25-
import org.junit.Before;
26-
import org.junit.Test;
27-
import org.junit.runner.RunWith;
28-
import org.junit.runners.Parameterized;
29-
import org.junit.runners.Parameterized.Parameters;
25+
import org.junit.jupiter.api.BeforeEach;
26+
import org.junit.jupiter.api.Timeout;
27+
import org.junit.jupiter.params.ParameterizedTest;
28+
import org.junit.jupiter.params.provider.MethodSource;
3029

3130
import java.util.Arrays;
3231
import java.util.Collection;
3332

3433
/**
3534
* This test performs simple runs of the SLS with the generic syn json format.
3635
*/
37-
@RunWith(value = Parameterized.class)
3836
@NotThreadSafe
3937
public class TestSLSDagAMSimulator extends BaseSLSRunnerTest {
4038

41-
@Parameters(name = "Testing with: {1}, {0}, (nodeFile {3})")
4239
public static Collection<Object[]> data() {
4340

4441
String capScheduler = CapacityScheduler.class.getCanonicalName();
@@ -60,15 +57,28 @@ public static Collection<Object[]> data() {
6057
});
6158
}
6259

63-
@Before
60+
public void initTestSLSDagAMSimulator(String pSchedulerType,
61+
String pTraceType, String pTraceLocation, String pNodeFile) {
62+
this.schedulerType = pSchedulerType;
63+
this.traceType = pTraceType;
64+
this.traceLocation = pTraceLocation;
65+
this.nodeFile = pNodeFile;
66+
setup();
67+
}
68+
69+
@BeforeEach
6470
public void setup() {
6571
ongoingInvariantFile = "src/test/resources/ongoing-invariants.txt";
6672
exitInvariantFile = "src/test/resources/exit-invariants.txt";
6773
}
6874

69-
@Test(timeout = 90000)
75+
@ParameterizedTest(name = "Testing with: {1}, {0}, (nodeFile {3})")
76+
@Timeout(value = 90)
77+
@MethodSource("data")
7078
@SuppressWarnings("all")
71-
public void testSimulatorRunning() throws Exception {
79+
public void testSimulatorRunning(String pSchedulerType,
80+
String pTraceType, String pTraceLocation, String pNodeFile) throws Exception {
81+
initTestSLSDagAMSimulator(pSchedulerType, pTraceType, pTraceLocation, pNodeFile);
7282
Configuration conf = new Configuration(false);
7383
long timeTillShutdownInsec = 20L;
7484
runSLS(conf, timeTillShutdownInsec);

hadoop-tools/hadoop-sls/src/test/java/org/apache/hadoop/yarn/sls/TestSLSGenericSynth.java

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,23 +22,20 @@
2222
import org.apache.hadoop.conf.Configuration;
2323
import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacityScheduler;
2424
import org.apache.hadoop.yarn.server.resourcemanager.scheduler.fair.FairScheduler;
25-
import org.junit.Before;
26-
import org.junit.Test;
27-
import org.junit.runner.RunWith;
28-
import org.junit.runners.Parameterized;
29-
import org.junit.runners.Parameterized.Parameters;
25+
import org.junit.jupiter.api.BeforeEach;
26+
import org.junit.jupiter.api.Timeout;
27+
import org.junit.jupiter.params.ParameterizedTest;
28+
import org.junit.jupiter.params.provider.MethodSource;
3029

3130
import java.util.Arrays;
3231
import java.util.Collection;
3332

3433
/**
3534
* This test performs simple runs of the SLS with the generic syn json format.
3635
*/
37-
@RunWith(value = Parameterized.class)
3836
@NotThreadSafe
3937
public class TestSLSGenericSynth extends BaseSLSRunnerTest {
4038

41-
@Parameters(name = "Testing with: {1}, {0}, (nodeFile {3})")
4239
public static Collection<Object[]> data() {
4340

4441
String capScheduler = CapacityScheduler.class.getCanonicalName();
@@ -60,15 +57,28 @@ public static Collection<Object[]> data() {
6057
});
6158
}
6259

63-
@Before
60+
@BeforeEach
6461
public void setup() {
6562
ongoingInvariantFile = "src/test/resources/ongoing-invariants.txt";
6663
exitInvariantFile = "src/test/resources/exit-invariants.txt";
6764
}
6865

69-
@Test(timeout = 90000)
66+
public void initTestSLSGenericSynth(String pSchedulerType,
67+
String pTraceType, String pTraceLocation, String pNodeFile) {
68+
this.schedulerType = pSchedulerType;
69+
this.traceType = pTraceType;
70+
this.traceLocation = pTraceLocation;
71+
this.nodeFile = pNodeFile;
72+
setup();
73+
}
74+
75+
@ParameterizedTest(name = "Testing with: {1}, {0}, (nodeFile {3})")
76+
@Timeout(value = 90)
7077
@SuppressWarnings("all")
71-
public void testSimulatorRunning() throws Exception {
78+
@MethodSource("data")
79+
public void testSimulatorRunning(String pSchedulerType,
80+
String pTraceType, String pTraceLocation, String pNodeFile) throws Exception {
81+
initTestSLSGenericSynth(pSchedulerType, pTraceType, pTraceLocation, pNodeFile);
7282
Configuration conf = new Configuration(false);
7383
long timeTillShutdownInsec = 20L;
7484
runSLS(conf, timeTillShutdownInsec);

hadoop-tools/hadoop-sls/src/test/java/org/apache/hadoop/yarn/sls/TestSLSRunner.java

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,26 +23,22 @@
2323
import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacityScheduler;
2424
import org.apache.hadoop.yarn.server.resourcemanager.scheduler.fair.FairScheduler;
2525
import org.apache.hadoop.yarn.sls.conf.SLSConfiguration;
26-
import org.junit.Before;
27-
import org.junit.Test;
28-
import org.junit.runner.RunWith;
29-
import org.junit.runners.Parameterized;
30-
import org.junit.runners.Parameterized.*;
26+
import org.junit.jupiter.api.Timeout;
27+
import org.junit.jupiter.params.ParameterizedTest;
28+
import org.junit.jupiter.params.provider.MethodSource;
3129

3230
import java.security.Security;
3331
import java.util.*;
3432

35-
import static org.junit.Assert.assertEquals;
33+
import static org.junit.jupiter.api.Assertions.assertEquals;
3634

3735
/**
3836
* This test performs simple runs of the SLS with different trace types and
3937
* schedulers.
4038
*/
41-
@RunWith(value = Parameterized.class)
4239
@NotThreadSafe
4340
public class TestSLSRunner extends BaseSLSRunnerTest {
4441

45-
@Parameters(name = "Testing with: {1}, {0}, (nodeFile {3})")
4642
public static Collection<Object[]> data() {
4743

4844
String capScheduler = CapacityScheduler.class.getCanonicalName();
@@ -76,15 +72,27 @@ public static Collection<Object[]> data() {
7672
});
7773
}
7874

79-
@Before
8075
public void setup() {
8176
ongoingInvariantFile = "src/test/resources/ongoing-invariants.txt";
8277
exitInvariantFile = "src/test/resources/exit-invariants.txt";
8378
}
8479

85-
@Test(timeout = 90000)
80+
public void initTestSLSRunner(String pSchedulerType,
81+
String pTraceType, String pTraceLocation, String pNodeFile) {
82+
this.schedulerType = pSchedulerType;
83+
this.traceType = pTraceType;
84+
this.traceLocation = pTraceLocation;
85+
this.nodeFile = pNodeFile;
86+
setup();
87+
}
88+
89+
@ParameterizedTest(name = "Testing with: {1}, {0}, (nodeFile {3})")
90+
@Timeout(value = 90)
91+
@MethodSource("data")
8692
@SuppressWarnings("all")
87-
public void testSimulatorRunning() throws Exception {
93+
public void testSimulatorRunning(String pSchedulerType,
94+
String pTraceType, String pTraceLocation, String pNodeFile) throws Exception {
95+
initTestSLSRunner(pSchedulerType, pTraceType, pTraceLocation, pNodeFile);
8896
Configuration conf = new Configuration(false);
8997
long timeTillShutdownInsec = 20L;
9098
runSLS(conf, timeTillShutdownInsec);
@@ -93,8 +101,11 @@ public void testSimulatorRunning() throws Exception {
93101
/**
94102
* Test to check whether caching is enabled based on config.
95103
*/
96-
@Test
97-
public void testEnableCaching() {
104+
@ParameterizedTest(name = "Testing with: {1}, {0}, (nodeFile {3})")
105+
@MethodSource("data")
106+
public void testEnableCaching(String pSchedulerType,
107+
String pTraceType, String pTraceLocation, String pNodeFile) {
108+
initTestSLSRunner(pSchedulerType, pTraceType, pTraceLocation, pNodeFile);
98109
String networkCacheDefault = Security.getProperty(
99110
SLSRunner.NETWORK_CACHE_TTL);
100111
String networkNegativeCacheDefault =

0 commit comments

Comments
 (0)