Skip to content

Commit 6a4e80b

Browse files
committed
HADOOP-19422. Upgrade JUnit from 4 to 5 in hadoop-archive-logs.
1 parent 71aa0e4 commit 6a4e80b

File tree

2 files changed

+101
-94
lines changed

2 files changed

+101
-94
lines changed

hadoop-tools/hadoop-archive-logs/src/test/java/org/apache/hadoop/tools/TestHadoopArchiveLogs.java

Lines changed: 84 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,9 @@
3737
import org.apache.hadoop.yarn.server.resourcemanager.RMContext;
3838
import org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMApp;
3939
import org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMAppImpl;
40-
import org.junit.Assert;
41-
import org.junit.Test;
40+
import org.junit.jupiter.api.Assertions;
41+
import org.junit.jupiter.api.Test;
42+
import org.junit.jupiter.api.Timeout;
4243

4344
import java.io.File;
4445
import java.io.IOException;
@@ -55,7 +56,8 @@ public class TestHadoopArchiveLogs {
5556
new Random().nextBytes(DUMMY_DATA);
5657
}
5758

58-
@Test(timeout = 10000)
59+
@Test
60+
@Timeout(value = 10)
5961
public void testCheckFilesAndSeedApps() throws Exception {
6062
Configuration conf = new Configuration();
6163
HadoopArchiveLogs hal = new HadoopArchiveLogs(conf);
@@ -64,7 +66,7 @@ public void testCheckFilesAndSeedApps() throws Exception {
6466
String suffix = "logs";
6567
Path logDir = new Path(rootLogDir, new Path(USER, suffix));
6668
fs.delete(logDir, true);
67-
Assert.assertFalse(fs.exists(logDir));
69+
Assertions.assertFalse(fs.exists(logDir));
6870
fs.mkdirs(logDir);
6971

7072
// no files found
@@ -96,15 +98,16 @@ public void testCheckFilesAndSeedApps() throws Exception {
9698
createFile(fs, new Path(app5Path, "file1"), 2);
9799
createFile(fs, new Path(app5Path, "file2"), 3);
98100

99-
Assert.assertEquals(0, hal.eligibleApplications.size());
101+
Assertions.assertEquals(0, hal.eligibleApplications.size());
100102
hal.checkFilesAndSeedApps(fs, rootLogDir, suffix, new Path(rootLogDir,
101103
"archive-logs-work"));
102-
Assert.assertEquals(1, hal.eligibleApplications.size());
103-
Assert.assertEquals(appId5.toString(),
104+
Assertions.assertEquals(1, hal.eligibleApplications.size());
105+
Assertions.assertEquals(appId5.toString(),
104106
hal.eligibleApplications.iterator().next().getAppId());
105107
}
106108

107-
@Test(timeout = 10000)
109+
@Test
110+
@Timeout(value = 10)
108111
public void testCheckMaxEligible() throws Exception {
109112
Configuration conf = new Configuration();
110113
HadoopArchiveLogs.AppInfo app1 = new HadoopArchiveLogs.AppInfo(
@@ -129,46 +132,47 @@ public void testCheckMaxEligible() throws Exception {
129132
ApplicationId.newInstance(CLUSTER_TIMESTAMP, 7).toString(), USER);
130133
app7.setFinishTime(CLUSTER_TIMESTAMP);
131134
HadoopArchiveLogs hal = new HadoopArchiveLogs(conf);
132-
Assert.assertEquals(0, hal.eligibleApplications.size());
135+
Assertions.assertEquals(0, hal.eligibleApplications.size());
133136
hal.eligibleApplications.add(app1);
134137
hal.eligibleApplications.add(app2);
135138
hal.eligibleApplications.add(app3);
136139
hal.eligibleApplications.add(app4);
137140
hal.eligibleApplications.add(app5);
138141
hal.eligibleApplications.add(app6);
139142
hal.eligibleApplications.add(app7);
140-
Assert.assertEquals(7, hal.eligibleApplications.size());
143+
Assertions.assertEquals(7, hal.eligibleApplications.size());
141144
hal.maxEligible = -1;
142145
hal.checkMaxEligible();
143-
Assert.assertEquals(7, hal.eligibleApplications.size());
146+
Assertions.assertEquals(7, hal.eligibleApplications.size());
144147
hal.maxEligible = 6;
145148
hal.checkMaxEligible();
146-
Assert.assertEquals(6, hal.eligibleApplications.size());
147-
Assert.assertFalse(hal.eligibleApplications.contains(app5));
149+
Assertions.assertEquals(6, hal.eligibleApplications.size());
150+
Assertions.assertFalse(hal.eligibleApplications.contains(app5));
148151
hal.maxEligible = 5;
149152
hal.checkMaxEligible();
150-
Assert.assertEquals(5, hal.eligibleApplications.size());
151-
Assert.assertFalse(hal.eligibleApplications.contains(app4));
153+
Assertions.assertEquals(5, hal.eligibleApplications.size());
154+
Assertions.assertFalse(hal.eligibleApplications.contains(app4));
152155
hal.maxEligible = 4;
153156
hal.checkMaxEligible();
154-
Assert.assertEquals(4, hal.eligibleApplications.size());
155-
Assert.assertFalse(hal.eligibleApplications.contains(app7));
157+
Assertions.assertEquals(4, hal.eligibleApplications.size());
158+
Assertions.assertFalse(hal.eligibleApplications.contains(app7));
156159
hal.maxEligible = 3;
157160
hal.checkMaxEligible();
158-
Assert.assertEquals(3, hal.eligibleApplications.size());
159-
Assert.assertFalse(hal.eligibleApplications.contains(app1));
161+
Assertions.assertEquals(3, hal.eligibleApplications.size());
162+
Assertions.assertFalse(hal.eligibleApplications.contains(app1));
160163
hal.maxEligible = 2;
161164
hal.checkMaxEligible();
162-
Assert.assertEquals(2, hal.eligibleApplications.size());
163-
Assert.assertFalse(hal.eligibleApplications.contains(app2));
165+
Assertions.assertEquals(2, hal.eligibleApplications.size());
166+
Assertions.assertFalse(hal.eligibleApplications.contains(app2));
164167
hal.maxEligible = 1;
165168
hal.checkMaxEligible();
166-
Assert.assertEquals(1, hal.eligibleApplications.size());
167-
Assert.assertFalse(hal.eligibleApplications.contains(app6));
168-
Assert.assertTrue(hal.eligibleApplications.contains(app3));
169+
Assertions.assertEquals(1, hal.eligibleApplications.size());
170+
Assertions.assertFalse(hal.eligibleApplications.contains(app6));
171+
Assertions.assertTrue(hal.eligibleApplications.contains(app3));
169172
}
170173

171-
@Test(timeout = 30000)
174+
@Test
175+
@Timeout(value = 30)
172176
public void testFilterAppsByAggregatedStatus() throws Exception {
173177
try (MiniYARNCluster yarnCluster =
174178
new MiniYARNCluster(TestHadoopArchiveLogs.class.getSimpleName(),
@@ -206,7 +210,7 @@ public void testFilterAppsByAggregatedStatus() throws Exception {
206210
// appImpl8 is not in the RM
207211

208212
HadoopArchiveLogs hal = new HadoopArchiveLogs(conf);
209-
Assert.assertEquals(0, hal.eligibleApplications.size());
213+
Assertions.assertEquals(0, hal.eligibleApplications.size());
210214
hal.eligibleApplications.add(
211215
new HadoopArchiveLogs.AppInfo(appImpl1.getApplicationId().toString(),
212216
USER));
@@ -234,16 +238,17 @@ public void testFilterAppsByAggregatedStatus() throws Exception {
234238
new HadoopArchiveLogs.AppInfo(appImpl8.getApplicationId().toString(),
235239
USER);
236240
hal.eligibleApplications.add(app8);
237-
Assert.assertEquals(8, hal.eligibleApplications.size());
241+
Assertions.assertEquals(8, hal.eligibleApplications.size());
238242
hal.filterAppsByAggregatedStatus();
239-
Assert.assertEquals(3, hal.eligibleApplications.size());
240-
Assert.assertTrue(hal.eligibleApplications.contains(app4));
241-
Assert.assertTrue(hal.eligibleApplications.contains(app7));
242-
Assert.assertTrue(hal.eligibleApplications.contains(app8));
243+
Assertions.assertEquals(3, hal.eligibleApplications.size());
244+
Assertions.assertTrue(hal.eligibleApplications.contains(app4));
245+
Assertions.assertTrue(hal.eligibleApplications.contains(app7));
246+
Assertions.assertTrue(hal.eligibleApplications.contains(app8));
243247
}
244248
}
245249

246-
@Test(timeout = 10000)
250+
@Test
251+
@Timeout(value = 10)
247252
public void testGenerateScript() throws Exception {
248253
_testGenerateScript(false);
249254
_testGenerateScript(true);
@@ -276,59 +281,59 @@ private void _testGenerateScript(boolean proxy) throws Exception {
276281

277282
File localScript = new File("target", "script.sh");
278283
localScript.delete();
279-
Assert.assertFalse(localScript.exists());
284+
Assertions.assertFalse(localScript.exists());
280285
hal.generateScript(localScript);
281-
Assert.assertTrue(localScript.exists());
286+
Assertions.assertTrue(localScript.exists());
282287
String script = IOUtils.toString(localScript.toURI(), StandardCharsets.UTF_8);
283288
String[] lines = script.split("\n");
284-
Assert.assertEquals(22, lines.length);
285-
Assert.assertEquals("#!/bin/bash", lines[0]);
286-
Assert.assertEquals("set -e", lines[1]);
287-
Assert.assertEquals("set -x", lines[2]);
288-
Assert.assertEquals("if [ \"$YARN_SHELL_ID\" == \"1\" ]; then", lines[3]);
289+
Assertions.assertEquals(22, lines.length);
290+
Assertions.assertEquals("#!/bin/bash", lines[0]);
291+
Assertions.assertEquals("set -e", lines[1]);
292+
Assertions.assertEquals("set -x", lines[2]);
293+
Assertions.assertEquals("if [ \"$YARN_SHELL_ID\" == \"1\" ]; then", lines[3]);
289294
boolean oneBefore = true;
290295
if (lines[4].contains(app1.toString())) {
291-
Assert.assertEquals("\tappId=\"" + app1.toString() + "\"", lines[4]);
292-
Assert.assertEquals("\tappId=\"" + app2.toString() + "\"", lines[10]);
296+
Assertions.assertEquals("\tappId=\"" + app1.toString() + "\"", lines[4]);
297+
Assertions.assertEquals("\tappId=\"" + app2.toString() + "\"", lines[10]);
293298
} else {
294299
oneBefore = false;
295-
Assert.assertEquals("\tappId=\"" + app2.toString() + "\"", lines[4]);
296-
Assert.assertEquals("\tappId=\"" + app1.toString() + "\"", lines[10]);
300+
Assertions.assertEquals("\tappId=\"" + app2.toString() + "\"", lines[4]);
301+
Assertions.assertEquals("\tappId=\"" + app1.toString() + "\"", lines[10]);
297302
}
298-
Assert.assertEquals("\tuser=\"" + USER + "\"", lines[5]);
299-
Assert.assertEquals("\tworkingDir=\"" + (oneBefore ? workingDir.toString()
303+
Assertions.assertEquals("\tuser=\"" + USER + "\"", lines[5]);
304+
Assertions.assertEquals("\tworkingDir=\"" + (oneBefore ? workingDir.toString()
300305
: workingDir2.toString()) + "\"", lines[6]);
301-
Assert.assertEquals("\tremoteRootLogDir=\"" + (oneBefore
306+
Assertions.assertEquals("\tremoteRootLogDir=\"" + (oneBefore
302307
? remoteRootLogDir.toString() : remoteRootLogDir2.toString())
303308
+ "\"", lines[7]);
304-
Assert.assertEquals("\tsuffix=\"" + (oneBefore ? suffix : suffix2)
309+
Assertions.assertEquals("\tsuffix=\"" + (oneBefore ? suffix : suffix2)
305310
+ "\"", lines[8]);
306-
Assert.assertEquals("elif [ \"$YARN_SHELL_ID\" == \"2\" ]; then",
311+
Assertions.assertEquals("elif [ \"$YARN_SHELL_ID\" == \"2\" ]; then",
307312
lines[9]);
308-
Assert.assertEquals("\tuser=\"" + USER + "\"", lines[11]);
309-
Assert.assertEquals("\tworkingDir=\"" + (oneBefore
313+
Assertions.assertEquals("\tuser=\"" + USER + "\"", lines[11]);
314+
Assertions.assertEquals("\tworkingDir=\"" + (oneBefore
310315
? workingDir2.toString() : workingDir.toString()) + "\"",
311316
lines[12]);
312-
Assert.assertEquals("\tremoteRootLogDir=\"" + (oneBefore
317+
Assertions.assertEquals("\tremoteRootLogDir=\"" + (oneBefore
313318
? remoteRootLogDir2.toString() : remoteRootLogDir.toString())
314319
+ "\"", lines[13]);
315-
Assert.assertEquals("\tsuffix=\"" + (oneBefore ? suffix2 : suffix)
320+
Assertions.assertEquals("\tsuffix=\"" + (oneBefore ? suffix2 : suffix)
316321
+ "\"", lines[14]);
317-
Assert.assertEquals("else", lines[15]);
318-
Assert.assertEquals("\techo \"Unknown Mapping!\"", lines[16]);
319-
Assert.assertEquals("\texit 1", lines[17]);
320-
Assert.assertEquals("fi", lines[18]);
321-
Assert.assertEquals("export HADOOP_CLIENT_OPTS=\"-Xmx1024m\"", lines[19]);
322-
Assert.assertTrue(lines[20].startsWith("export HADOOP_CLASSPATH="));
322+
Assertions.assertEquals("else", lines[15]);
323+
Assertions.assertEquals("\techo \"Unknown Mapping!\"", lines[16]);
324+
Assertions.assertEquals("\texit 1", lines[17]);
325+
Assertions.assertEquals("fi", lines[18]);
326+
Assertions.assertEquals("export HADOOP_CLIENT_OPTS=\"-Xmx1024m\"", lines[19]);
327+
Assertions.assertTrue(lines[20].startsWith("export HADOOP_CLASSPATH="));
323328
if (proxy) {
324-
Assert.assertEquals(
329+
Assertions.assertEquals(
325330
"\"$HADOOP_HOME\"/bin/hadoop org.apache.hadoop.tools." +
326331
"HadoopArchiveLogsRunner -appId \"$appId\" -user \"$user\" " +
327332
"-workingDir \"$workingDir\" -remoteRootLogDir " +
328333
"\"$remoteRootLogDir\" -suffix \"$suffix\"",
329334
lines[21]);
330335
} else {
331-
Assert.assertEquals(
336+
Assertions.assertEquals(
332337
"\"$HADOOP_HOME\"/bin/hadoop org.apache.hadoop.tools." +
333338
"HadoopArchiveLogsRunner -appId \"$appId\" -user \"$user\" " +
334339
"-workingDir \"$workingDir\" -remoteRootLogDir " +
@@ -343,7 +348,8 @@ private void _testGenerateScript(boolean proxy) throws Exception {
343348
* are updated as well, if necessary.
344349
* @throws Exception
345350
*/
346-
@Test(timeout = 5000)
351+
@Test
352+
@Timeout(value = 5)
347353
public void testStatuses() throws Exception {
348354
LogAggregationStatus[] statuses = new LogAggregationStatus[7];
349355
statuses[0] = LogAggregationStatus.DISABLED;
@@ -353,51 +359,52 @@ public void testStatuses() throws Exception {
353359
statuses[4] = LogAggregationStatus.SUCCEEDED;
354360
statuses[5] = LogAggregationStatus.FAILED;
355361
statuses[6] = LogAggregationStatus.TIME_OUT;
356-
Assert.assertArrayEquals(statuses, LogAggregationStatus.values());
362+
Assertions.assertArrayEquals(statuses, LogAggregationStatus.values());
357363
}
358364

359-
@Test(timeout = 5000)
365+
@Test
366+
@Timeout(value = 5)
360367
public void testPrepareWorkingDir() throws Exception {
361368
Configuration conf = new Configuration();
362369
HadoopArchiveLogs hal = new HadoopArchiveLogs(conf);
363370
FileSystem fs = FileSystem.getLocal(conf);
364371
Path workingDir = new Path("target", "testPrepareWorkingDir");
365372
fs.delete(workingDir, true);
366-
Assert.assertFalse(fs.exists(workingDir));
373+
Assertions.assertFalse(fs.exists(workingDir));
367374
// -force is false and the dir doesn't exist so it will create one
368375
hal.force = false;
369376
boolean dirPrepared = hal.prepareWorkingDir(fs, workingDir);
370-
Assert.assertTrue(dirPrepared);
371-
Assert.assertTrue(fs.exists(workingDir));
372-
Assert.assertEquals(
377+
Assertions.assertTrue(dirPrepared);
378+
Assertions.assertTrue(fs.exists(workingDir));
379+
Assertions.assertEquals(
373380
new FsPermission(FsAction.ALL, FsAction.ALL, FsAction.ALL,
374381
!Shell.WINDOWS),
375382
fs.getFileStatus(workingDir).getPermission());
376383
// Throw a file in the dir
377384
Path dummyFile = new Path(workingDir, "dummy.txt");
378385
fs.createNewFile(dummyFile);
379-
Assert.assertTrue(fs.exists(dummyFile));
386+
Assertions.assertTrue(fs.exists(dummyFile));
380387
// -force is false and the dir exists, so nothing will happen and the dummy
381388
// still exists
382389
dirPrepared = hal.prepareWorkingDir(fs, workingDir);
383-
Assert.assertFalse(dirPrepared);
384-
Assert.assertTrue(fs.exists(workingDir));
385-
Assert.assertTrue(fs.exists(dummyFile));
386-
Assert.assertEquals(
390+
Assertions.assertFalse(dirPrepared);
391+
Assertions.assertTrue(fs.exists(workingDir));
392+
Assertions.assertTrue(fs.exists(dummyFile));
393+
Assertions.assertEquals(
387394
new FsPermission(FsAction.ALL, FsAction.ALL, FsAction.ALL,
388395
!Shell.WINDOWS),
389396
fs.getFileStatus(workingDir).getPermission());
390397
// -force is true and the dir exists, so it will recreate it and the dummy
391398
// won't exist anymore
392399
hal.force = true;
393400
dirPrepared = hal.prepareWorkingDir(fs, workingDir);
394-
Assert.assertTrue(dirPrepared);
395-
Assert.assertTrue(fs.exists(workingDir));
396-
Assert.assertEquals(
401+
Assertions.assertTrue(dirPrepared);
402+
Assertions.assertTrue(fs.exists(workingDir));
403+
Assertions.assertEquals(
397404
new FsPermission(FsAction.ALL, FsAction.ALL, FsAction.ALL,
398405
!Shell.WINDOWS),
399406
fs.getFileStatus(workingDir).getPermission());
400-
Assert.assertFalse(fs.exists(dummyFile));
407+
Assertions.assertFalse(fs.exists(dummyFile));
401408
}
402409

403410
private static void createFile(FileSystem fs, Path p, long sizeMultiple)
@@ -413,7 +420,7 @@ private static void createFile(FileSystem fs, Path p, long sizeMultiple)
413420
out.close();
414421
}
415422
}
416-
Assert.assertTrue(fs.exists(p));
423+
Assertions.assertTrue(fs.exists(p));
417424
}
418425

419426
private static RMApp createRMApp(int id, Configuration conf, RMContext rmContext,

0 commit comments

Comments
 (0)