Skip to content

Commit 1b56a9a

Browse files
committed
HADOOP-19440. Upgrade JUnit from 4 to 5 in hadoop-sls.
1 parent 5ccb0dc commit 1b56a9a

13 files changed

+194
-184
lines changed

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +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;
28+
import org.junit.jupiter.api.BeforeEach;
29+
import org.junit.jupiter.api.BeforeAll;
3030
import org.junit.runner.RunWith;
3131
import org.junit.runners.Parameterized;
3232
import org.junit.runners.Parameterized.Parameter;
@@ -63,16 +63,16 @@ public abstract class BaseSLSRunnerTest {
6363
protected String ongoingInvariantFile;
6464
protected String exitInvariantFile;
6565

66-
@BeforeClass
66+
@BeforeAll
6767
public static void checkForJavaScript() {
6868
Assume.assumeNotNull("JavaScript engine not available (JEP 372)",
6969
new ScriptEngineManager().getEngineByName("JavaScript"));
7070
}
7171

72-
@Before
72+
@BeforeEach
7373
public abstract void setup();
7474

75-
@After
75+
@AfterEach
7676
public void tearDown() throws InterruptedException {
7777
if (sls != null) {
7878
sls.stop();
@@ -136,7 +136,7 @@ public void uncaughtException(Thread t, Throwable e) {
136136

137137
if (!exceptionList.isEmpty()) {
138138
sls.stop();
139-
Assert.fail("TestSLSRunner caught exception from child thread "
139+
Assertions.fail("TestSLSRunner caught exception from child thread "
140140
+ "(TaskRunner.TaskDefinition): " + exceptionList);
141141
break;
142142
}

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: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@
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;
30+
import org.junit.jupiter.api.Test;
31+
import org.junit.jupiter.api.Timeout;
3132
import org.junit.runner.RunWith;
3233
import org.junit.runners.Parameterized;
3334
import org.junit.runners.Parameterized.Parameters;
@@ -53,7 +54,8 @@ public static Collection<Object[]> data() {
5354
});
5455
}
5556

56-
@Test(timeout = 120000)
57+
@Test
58+
@Timeout(value = 120)
5759
@SuppressWarnings("all")
5860
public void testSimulatorRunning() throws Exception {
5961

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@
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;
25+
import org.junit.jupiter.api.BeforeEach;
26+
import org.junit.jupiter.api.Test;
27+
import org.junit.jupiter.api.Timeout;
2728
import org.junit.runner.RunWith;
2829
import org.junit.runners.Parameterized;
2930
import org.junit.runners.Parameterized.Parameters;
@@ -60,13 +61,14 @@ public static Collection<Object[]> data() {
6061
});
6162
}
6263

63-
@Before
64+
@BeforeEach
6465
public void setup() {
6566
ongoingInvariantFile = "src/test/resources/ongoing-invariants.txt";
6667
exitInvariantFile = "src/test/resources/exit-invariants.txt";
6768
}
6869

69-
@Test(timeout = 90000)
70+
@Test
71+
@Timeout(value = 90)
7072
@SuppressWarnings("all")
7173
public void testSimulatorRunning() throws Exception {
7274
Configuration conf = new Configuration(false);

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@
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;
25+
import org.junit.jupiter.api.BeforeEach;
26+
import org.junit.jupiter.api.Test;
27+
import org.junit.jupiter.api.Timeout;
2728
import org.junit.runner.RunWith;
2829
import org.junit.runners.Parameterized;
2930
import org.junit.runners.Parameterized.Parameters;
@@ -60,13 +61,14 @@ public static Collection<Object[]> data() {
6061
});
6162
}
6263

63-
@Before
64+
@BeforeEach
6465
public void setup() {
6566
ongoingInvariantFile = "src/test/resources/ongoing-invariants.txt";
6667
exitInvariantFile = "src/test/resources/exit-invariants.txt";
6768
}
6869

69-
@Test(timeout = 90000)
70+
@Test
71+
@Timeout(value = 90)
7072
@SuppressWarnings("all")
7173
public void testSimulatorRunning() throws Exception {
7274
Configuration conf = new Configuration(false);

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,17 @@
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;
26+
import org.junit.jupiter.api.BeforeEach;
27+
import org.junit.jupiter.api.Test;
28+
import org.junit.jupiter.api.Timeout;
2829
import org.junit.runner.RunWith;
2930
import org.junit.runners.Parameterized;
3031
import org.junit.runners.Parameterized.*;
3132

3233
import java.security.Security;
3334
import java.util.*;
3435

35-
import static org.junit.Assert.assertEquals;
36+
import static org.junit.jupiter.api.Assertions.assertEquals;
3637

3738
/**
3839
* This test performs simple runs of the SLS with different trace types and
@@ -76,13 +77,14 @@ public static Collection<Object[]> data() {
7677
});
7778
}
7879

79-
@Before
80+
@BeforeEach
8081
public void setup() {
8182
ongoingInvariantFile = "src/test/resources/ongoing-invariants.txt";
8283
exitInvariantFile = "src/test/resources/exit-invariants.txt";
8384
}
8485

85-
@Test(timeout = 90000)
86+
@Test
87+
@Timeout(value = 90)
8688
@SuppressWarnings("all")
8789
public void testSimulatorRunning() throws Exception {
8890
Configuration conf = new Configuration(false);

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@
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;
25+
import org.junit.jupiter.api.BeforeEach;
26+
import org.junit.jupiter.api.Test;
27+
import org.junit.jupiter.api.Timeout;
2728
import org.junit.runner.RunWith;
2829
import org.junit.runners.Parameterized;
2930
import org.junit.runners.Parameterized.Parameters;
@@ -60,13 +61,14 @@ public static Collection<Object[]> data() {
6061
});
6162
}
6263

63-
@Before
64+
@BeforeEach
6465
public void setup() {
6566
ongoingInvariantFile = "src/test/resources/ongoing-invariants.txt";
6667
exitInvariantFile = "src/test/resources/exit-invariants.txt";
6768
}
6869

69-
@Test(timeout = 90000)
70+
@Test
71+
@Timeout(value = 90)
7072
@SuppressWarnings("all")
7173
public void testSimulatorRunning() throws Exception {
7274
Configuration conf = new Configuration(false);

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

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,18 @@
2727
import com.fasterxml.jackson.core.JsonFactoryBuilder;
2828
import com.fasterxml.jackson.databind.JsonMappingException;
2929
import com.fasterxml.jackson.databind.ObjectMapper;
30-
import org.junit.Assert;
31-
import org.junit.Test;
30+
import org.junit.jupiter.api.Assertions;
31+
import org.junit.jupiter.api.Test;
3232
import org.slf4j.Logger;
3333
import org.slf4j.LoggerFactory;
3434

3535
import java.io.IOException;
3636
import java.util.Arrays;
3737

3838
import static com.fasterxml.jackson.databind.DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES;
39-
import static org.junit.Assert.assertEquals;
40-
import static org.junit.Assert.assertNotNull;
41-
import static org.junit.Assert.assertTrue;
39+
import static org.junit.jupiter.api.Assertions.assertEquals;
40+
import static org.junit.jupiter.api.Assertions.assertNotNull;
41+
import static org.junit.jupiter.api.Assertions.assertTrue;
4242

4343
/**
4444
* Simple test class driving the {@code SynthTraceJobProducer}, and validating
@@ -88,12 +88,12 @@ public void testWorkloadGenerateTime()
8888
}
8989
}
9090

91-
Assert.assertTrue(bucket0 > 0);
91+
Assertions.assertTrue(bucket0 > 0);
9292
assertEquals(0, bucket1);
93-
Assert.assertTrue(bucket2 > 0);
94-
Assert.assertTrue(bucket3 > 0);
95-
Assert.assertTrue(bucket2 > bucket0);
96-
Assert.assertTrue(bucket2 > bucket3);
93+
Assertions.assertTrue(bucket2 > 0);
94+
Assertions.assertTrue(bucket3 > 0);
95+
Assertions.assertTrue(bucket2 > bucket0);
96+
Assertions.assertTrue(bucket2 > bucket3);
9797

9898
LOG.info("bucket0 {}, bucket1 {}, bucket2 {}, bucket3 {}", bucket0, bucket1,
9999
bucket2, bucket3);
@@ -123,7 +123,7 @@ public void testMapReduce() throws IllegalArgumentException, IOException {
123123
jobCount++;
124124
}
125125

126-
Assert.assertEquals(stjp.getNumJobs(), jobCount);
126+
Assertions.assertEquals(stjp.getNumJobs(), jobCount);
127127
}
128128

129129
@Test
@@ -148,7 +148,7 @@ public void testGeneric() throws IllegalArgumentException, IOException {
148148
jobCount++;
149149
}
150150

151-
Assert.assertEquals(stjp.getNumJobs(), jobCount);
151+
Assertions.assertEquals(stjp.getNumJobs(), jobCount);
152152
}
153153

154154
@Test
@@ -173,7 +173,7 @@ public void testStream() throws IllegalArgumentException, IOException {
173173
jobCount++;
174174
}
175175

176-
Assert.assertEquals(stjp.getNumJobs(), jobCount);
176+
Assertions.assertEquals(stjp.getNumJobs(), jobCount);
177177
}
178178

179179
@Test
@@ -192,28 +192,28 @@ public void testSample() throws IOException {
192192
mapper.readValue(valJson, SynthTraceJobProducer.Sample.class);
193193
valSample.init(rand);
194194
int val = valSample.getInt();
195-
Assert.assertEquals(5, val);
195+
Assertions.assertEquals(5, val);
196196

197197
String distJson = "{\"val\" : 5, \"std\" : 1 }";
198198
SynthTraceJobProducer.Sample distSample =
199199
mapper.readValue(distJson, SynthTraceJobProducer.Sample.class);
200200
distSample.init(rand);
201201
double dist = distSample.getDouble();
202-
Assert.assertTrue(dist > 2 && dist < 8);
202+
Assertions.assertTrue(dist > 2 && dist < 8);
203203

204204
String normdistJson = "{\"val\" : 5, \"std\" : 1, \"dist\": \"NORM\" }";
205205
SynthTraceJobProducer.Sample normdistSample =
206206
mapper.readValue(normdistJson, SynthTraceJobProducer.Sample.class);
207207
normdistSample.init(rand);
208208
double normdist = normdistSample.getDouble();
209-
Assert.assertTrue(normdist > 2 && normdist < 8);
209+
Assertions.assertTrue(normdist > 2 && normdist < 8);
210210

211211
String discreteJson = "{\"discrete\" : [2, 4, 6, 8]}";
212212
SynthTraceJobProducer.Sample discreteSample =
213213
mapper.readValue(discreteJson, SynthTraceJobProducer.Sample.class);
214214
discreteSample.init(rand);
215215
int discrete = discreteSample.getInt();
216-
Assert.assertTrue(
216+
Assertions.assertTrue(
217217
Arrays.asList(new Integer[] {2, 4, 6, 8}).contains(discrete));
218218

219219
String discreteWeightsJson =
@@ -222,24 +222,24 @@ public void testSample() throws IOException {
222222
.readValue(discreteWeightsJson, SynthTraceJobProducer.Sample.class);
223223
discreteWeightsSample.init(rand);
224224
int discreteWeights = discreteWeightsSample.getInt();
225-
Assert.assertEquals(8, discreteWeights);
225+
Assertions.assertEquals(8, discreteWeights);
226226

227227
String invalidJson = "{\"val\" : 5, \"discrete\" : [2, 4, 6, 8], "
228228
+ "\"weights\": [0, 0, 0, 1]}";
229229
try {
230230
mapper.readValue(invalidJson, SynthTraceJobProducer.Sample.class);
231-
Assert.fail();
231+
Assertions.fail();
232232
} catch (JsonMappingException e) {
233-
Assert.assertTrue(e.getMessage().startsWith("Instantiation of"));
233+
Assertions.assertTrue(e.getMessage().startsWith("Instantiation of"));
234234
}
235235

236236
String invalidDistJson =
237237
"{\"val\" : 5, \"std\" : 1, " + "\"dist\": \"INVALID\" }";
238238
try {
239239
mapper.readValue(invalidDistJson, SynthTraceJobProducer.Sample.class);
240-
Assert.fail();
240+
Assertions.fail();
241241
} catch (JsonMappingException e) {
242-
Assert.assertTrue(e.getMessage().startsWith("Cannot construct instance of"));
242+
Assertions.assertTrue(e.getMessage().startsWith("Cannot construct instance of"));
243243
}
244244
}
245245

0 commit comments

Comments
 (0)