Skip to content

Commit 90a6f92

Browse files
slfan1989jojochuangzhtttylz
authored
HADOOP-19422. [JDK17] Upgrade JUnit from 4 to 5 in hadoop-archive-logs. (#7621)
* HADOOP-19422. Upgrade JUnit from 4 to 5 in hadoop-archive-logs. Co-authored-by: Wei-Chiu Chuang <[email protected]> Co-authored-by: Hualong Zhang <[email protected]> Reviewed-by: Wei-Chiu Chuang <[email protected]> Reviewed-by: Hualong Zhang <[email protected]> Signed-off-by: Shilun Fan <[email protected]>
1 parent caf8af0 commit 90a6f92

File tree

2 files changed

+109
-100
lines changed

2 files changed

+109
-100
lines changed

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

Lines changed: 88 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@
1818

1919
package org.apache.hadoop.tools;
2020

21+
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
22+
import static org.junit.jupiter.api.Assertions.assertEquals;
23+
import static org.junit.jupiter.api.Assertions.assertFalse;
24+
import static org.junit.jupiter.api.Assertions.assertTrue;
25+
2126
import org.apache.commons.io.IOUtils;
2227
import org.apache.hadoop.conf.Configuration;
2328
import org.apache.hadoop.fs.FSDataOutputStream;
@@ -37,8 +42,8 @@
3742
import org.apache.hadoop.yarn.server.resourcemanager.RMContext;
3843
import org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMApp;
3944
import org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMAppImpl;
40-
import org.junit.Assert;
41-
import org.junit.Test;
45+
import org.junit.jupiter.api.Test;
46+
import org.junit.jupiter.api.Timeout;
4247

4348
import java.io.File;
4449
import java.io.IOException;
@@ -55,7 +60,8 @@ public class TestHadoopArchiveLogs {
5560
new Random().nextBytes(DUMMY_DATA);
5661
}
5762

58-
@Test(timeout = 10000)
63+
@Test
64+
@Timeout(value = 10)
5965
public void testCheckFilesAndSeedApps() throws Exception {
6066
Configuration conf = new Configuration();
6167
HadoopArchiveLogs hal = new HadoopArchiveLogs(conf);
@@ -64,7 +70,7 @@ public void testCheckFilesAndSeedApps() throws Exception {
6470
String suffix = "logs";
6571
Path logDir = new Path(rootLogDir, new Path(USER, suffix));
6672
fs.delete(logDir, true);
67-
Assert.assertFalse(fs.exists(logDir));
73+
assertFalse(fs.exists(logDir));
6874
fs.mkdirs(logDir);
6975

7076
// no files found
@@ -96,15 +102,16 @@ public void testCheckFilesAndSeedApps() throws Exception {
96102
createFile(fs, new Path(app5Path, "file1"), 2);
97103
createFile(fs, new Path(app5Path, "file2"), 3);
98104

99-
Assert.assertEquals(0, hal.eligibleApplications.size());
105+
assertEquals(0, hal.eligibleApplications.size());
100106
hal.checkFilesAndSeedApps(fs, rootLogDir, suffix, new Path(rootLogDir,
101107
"archive-logs-work"));
102-
Assert.assertEquals(1, hal.eligibleApplications.size());
103-
Assert.assertEquals(appId5.toString(),
108+
assertEquals(1, hal.eligibleApplications.size());
109+
assertEquals(appId5.toString(),
104110
hal.eligibleApplications.iterator().next().getAppId());
105111
}
106112

107-
@Test(timeout = 10000)
113+
@Test
114+
@Timeout(value = 10)
108115
public void testCheckMaxEligible() throws Exception {
109116
Configuration conf = new Configuration();
110117
HadoopArchiveLogs.AppInfo app1 = new HadoopArchiveLogs.AppInfo(
@@ -129,46 +136,47 @@ public void testCheckMaxEligible() throws Exception {
129136
ApplicationId.newInstance(CLUSTER_TIMESTAMP, 7).toString(), USER);
130137
app7.setFinishTime(CLUSTER_TIMESTAMP);
131138
HadoopArchiveLogs hal = new HadoopArchiveLogs(conf);
132-
Assert.assertEquals(0, hal.eligibleApplications.size());
139+
assertEquals(0, hal.eligibleApplications.size());
133140
hal.eligibleApplications.add(app1);
134141
hal.eligibleApplications.add(app2);
135142
hal.eligibleApplications.add(app3);
136143
hal.eligibleApplications.add(app4);
137144
hal.eligibleApplications.add(app5);
138145
hal.eligibleApplications.add(app6);
139146
hal.eligibleApplications.add(app7);
140-
Assert.assertEquals(7, hal.eligibleApplications.size());
147+
assertEquals(7, hal.eligibleApplications.size());
141148
hal.maxEligible = -1;
142149
hal.checkMaxEligible();
143-
Assert.assertEquals(7, hal.eligibleApplications.size());
150+
assertEquals(7, hal.eligibleApplications.size());
144151
hal.maxEligible = 6;
145152
hal.checkMaxEligible();
146-
Assert.assertEquals(6, hal.eligibleApplications.size());
147-
Assert.assertFalse(hal.eligibleApplications.contains(app5));
153+
assertEquals(6, hal.eligibleApplications.size());
154+
assertFalse(hal.eligibleApplications.contains(app5));
148155
hal.maxEligible = 5;
149156
hal.checkMaxEligible();
150-
Assert.assertEquals(5, hal.eligibleApplications.size());
151-
Assert.assertFalse(hal.eligibleApplications.contains(app4));
157+
assertEquals(5, hal.eligibleApplications.size());
158+
assertFalse(hal.eligibleApplications.contains(app4));
152159
hal.maxEligible = 4;
153160
hal.checkMaxEligible();
154-
Assert.assertEquals(4, hal.eligibleApplications.size());
155-
Assert.assertFalse(hal.eligibleApplications.contains(app7));
161+
assertEquals(4, hal.eligibleApplications.size());
162+
assertFalse(hal.eligibleApplications.contains(app7));
156163
hal.maxEligible = 3;
157164
hal.checkMaxEligible();
158-
Assert.assertEquals(3, hal.eligibleApplications.size());
159-
Assert.assertFalse(hal.eligibleApplications.contains(app1));
165+
assertEquals(3, hal.eligibleApplications.size());
166+
assertFalse(hal.eligibleApplications.contains(app1));
160167
hal.maxEligible = 2;
161168
hal.checkMaxEligible();
162-
Assert.assertEquals(2, hal.eligibleApplications.size());
163-
Assert.assertFalse(hal.eligibleApplications.contains(app2));
169+
assertEquals(2, hal.eligibleApplications.size());
170+
assertFalse(hal.eligibleApplications.contains(app2));
164171
hal.maxEligible = 1;
165172
hal.checkMaxEligible();
166-
Assert.assertEquals(1, hal.eligibleApplications.size());
167-
Assert.assertFalse(hal.eligibleApplications.contains(app6));
168-
Assert.assertTrue(hal.eligibleApplications.contains(app3));
173+
assertEquals(1, hal.eligibleApplications.size());
174+
assertFalse(hal.eligibleApplications.contains(app6));
175+
assertTrue(hal.eligibleApplications.contains(app3));
169176
}
170177

171-
@Test(timeout = 30000)
178+
@Test
179+
@Timeout(value = 30)
172180
public void testFilterAppsByAggregatedStatus() throws Exception {
173181
try (MiniYARNCluster yarnCluster =
174182
new MiniYARNCluster(TestHadoopArchiveLogs.class.getSimpleName(),
@@ -206,7 +214,7 @@ public void testFilterAppsByAggregatedStatus() throws Exception {
206214
// appImpl8 is not in the RM
207215

208216
HadoopArchiveLogs hal = new HadoopArchiveLogs(conf);
209-
Assert.assertEquals(0, hal.eligibleApplications.size());
217+
assertEquals(0, hal.eligibleApplications.size());
210218
hal.eligibleApplications.add(
211219
new HadoopArchiveLogs.AppInfo(appImpl1.getApplicationId().toString(),
212220
USER));
@@ -234,16 +242,17 @@ public void testFilterAppsByAggregatedStatus() throws Exception {
234242
new HadoopArchiveLogs.AppInfo(appImpl8.getApplicationId().toString(),
235243
USER);
236244
hal.eligibleApplications.add(app8);
237-
Assert.assertEquals(8, hal.eligibleApplications.size());
245+
assertEquals(8, hal.eligibleApplications.size());
238246
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));
247+
assertEquals(3, hal.eligibleApplications.size());
248+
assertTrue(hal.eligibleApplications.contains(app4));
249+
assertTrue(hal.eligibleApplications.contains(app7));
250+
assertTrue(hal.eligibleApplications.contains(app8));
243251
}
244252
}
245253

246-
@Test(timeout = 10000)
254+
@Test
255+
@Timeout(value = 10)
247256
public void testGenerateScript() throws Exception {
248257
_testGenerateScript(false);
249258
_testGenerateScript(true);
@@ -276,59 +285,59 @@ private void _testGenerateScript(boolean proxy) throws Exception {
276285

277286
File localScript = new File("target", "script.sh");
278287
localScript.delete();
279-
Assert.assertFalse(localScript.exists());
288+
assertFalse(localScript.exists());
280289
hal.generateScript(localScript);
281-
Assert.assertTrue(localScript.exists());
290+
assertTrue(localScript.exists());
282291
String script = IOUtils.toString(localScript.toURI(), StandardCharsets.UTF_8);
283292
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]);
293+
assertEquals(22, lines.length);
294+
assertEquals("#!/bin/bash", lines[0]);
295+
assertEquals("set -e", lines[1]);
296+
assertEquals("set -x", lines[2]);
297+
assertEquals("if [ \"$YARN_SHELL_ID\" == \"1\" ]; then", lines[3]);
289298
boolean oneBefore = true;
290299
if (lines[4].contains(app1.toString())) {
291-
Assert.assertEquals("\tappId=\"" + app1.toString() + "\"", lines[4]);
292-
Assert.assertEquals("\tappId=\"" + app2.toString() + "\"", lines[10]);
300+
assertEquals("\tappId=\"" + app1.toString() + "\"", lines[4]);
301+
assertEquals("\tappId=\"" + app2.toString() + "\"", lines[10]);
293302
} else {
294303
oneBefore = false;
295-
Assert.assertEquals("\tappId=\"" + app2.toString() + "\"", lines[4]);
296-
Assert.assertEquals("\tappId=\"" + app1.toString() + "\"", lines[10]);
304+
assertEquals("\tappId=\"" + app2.toString() + "\"", lines[4]);
305+
assertEquals("\tappId=\"" + app1.toString() + "\"", lines[10]);
297306
}
298-
Assert.assertEquals("\tuser=\"" + USER + "\"", lines[5]);
299-
Assert.assertEquals("\tworkingDir=\"" + (oneBefore ? workingDir.toString()
307+
assertEquals("\tuser=\"" + USER + "\"", lines[5]);
308+
assertEquals("\tworkingDir=\"" + (oneBefore ? workingDir.toString()
300309
: workingDir2.toString()) + "\"", lines[6]);
301-
Assert.assertEquals("\tremoteRootLogDir=\"" + (oneBefore
310+
assertEquals("\tremoteRootLogDir=\"" + (oneBefore
302311
? remoteRootLogDir.toString() : remoteRootLogDir2.toString())
303312
+ "\"", lines[7]);
304-
Assert.assertEquals("\tsuffix=\"" + (oneBefore ? suffix : suffix2)
313+
assertEquals("\tsuffix=\"" + (oneBefore ? suffix : suffix2)
305314
+ "\"", lines[8]);
306-
Assert.assertEquals("elif [ \"$YARN_SHELL_ID\" == \"2\" ]; then",
315+
assertEquals("elif [ \"$YARN_SHELL_ID\" == \"2\" ]; then",
307316
lines[9]);
308-
Assert.assertEquals("\tuser=\"" + USER + "\"", lines[11]);
309-
Assert.assertEquals("\tworkingDir=\"" + (oneBefore
317+
assertEquals("\tuser=\"" + USER + "\"", lines[11]);
318+
assertEquals("\tworkingDir=\"" + (oneBefore
310319
? workingDir2.toString() : workingDir.toString()) + "\"",
311320
lines[12]);
312-
Assert.assertEquals("\tremoteRootLogDir=\"" + (oneBefore
321+
assertEquals("\tremoteRootLogDir=\"" + (oneBefore
313322
? remoteRootLogDir2.toString() : remoteRootLogDir.toString())
314323
+ "\"", lines[13]);
315-
Assert.assertEquals("\tsuffix=\"" + (oneBefore ? suffix2 : suffix)
324+
assertEquals("\tsuffix=\"" + (oneBefore ? suffix2 : suffix)
316325
+ "\"", 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="));
326+
assertEquals("else", lines[15]);
327+
assertEquals("\techo \"Unknown Mapping!\"", lines[16]);
328+
assertEquals("\texit 1", lines[17]);
329+
assertEquals("fi", lines[18]);
330+
assertEquals("export HADOOP_CLIENT_OPTS=\"-Xmx1024m\"", lines[19]);
331+
assertTrue(lines[20].startsWith("export HADOOP_CLASSPATH="));
323332
if (proxy) {
324-
Assert.assertEquals(
333+
assertEquals(
325334
"\"$HADOOP_HOME\"/bin/hadoop org.apache.hadoop.tools." +
326335
"HadoopArchiveLogsRunner -appId \"$appId\" -user \"$user\" " +
327336
"-workingDir \"$workingDir\" -remoteRootLogDir " +
328337
"\"$remoteRootLogDir\" -suffix \"$suffix\"",
329338
lines[21]);
330339
} else {
331-
Assert.assertEquals(
340+
assertEquals(
332341
"\"$HADOOP_HOME\"/bin/hadoop org.apache.hadoop.tools." +
333342
"HadoopArchiveLogsRunner -appId \"$appId\" -user \"$user\" " +
334343
"-workingDir \"$workingDir\" -remoteRootLogDir " +
@@ -343,7 +352,8 @@ private void _testGenerateScript(boolean proxy) throws Exception {
343352
* are updated as well, if necessary.
344353
* @throws Exception
345354
*/
346-
@Test(timeout = 5000)
355+
@Test
356+
@Timeout(value = 5)
347357
public void testStatuses() throws Exception {
348358
LogAggregationStatus[] statuses = new LogAggregationStatus[7];
349359
statuses[0] = LogAggregationStatus.DISABLED;
@@ -353,51 +363,52 @@ public void testStatuses() throws Exception {
353363
statuses[4] = LogAggregationStatus.SUCCEEDED;
354364
statuses[5] = LogAggregationStatus.FAILED;
355365
statuses[6] = LogAggregationStatus.TIME_OUT;
356-
Assert.assertArrayEquals(statuses, LogAggregationStatus.values());
366+
assertArrayEquals(statuses, LogAggregationStatus.values());
357367
}
358368

359-
@Test(timeout = 5000)
369+
@Test
370+
@Timeout(value = 5)
360371
public void testPrepareWorkingDir() throws Exception {
361372
Configuration conf = new Configuration();
362373
HadoopArchiveLogs hal = new HadoopArchiveLogs(conf);
363374
FileSystem fs = FileSystem.getLocal(conf);
364375
Path workingDir = new Path("target", "testPrepareWorkingDir");
365376
fs.delete(workingDir, true);
366-
Assert.assertFalse(fs.exists(workingDir));
377+
assertFalse(fs.exists(workingDir));
367378
// -force is false and the dir doesn't exist so it will create one
368379
hal.force = false;
369380
boolean dirPrepared = hal.prepareWorkingDir(fs, workingDir);
370-
Assert.assertTrue(dirPrepared);
371-
Assert.assertTrue(fs.exists(workingDir));
372-
Assert.assertEquals(
381+
assertTrue(dirPrepared);
382+
assertTrue(fs.exists(workingDir));
383+
assertEquals(
373384
new FsPermission(FsAction.ALL, FsAction.ALL, FsAction.ALL,
374385
!Shell.WINDOWS),
375386
fs.getFileStatus(workingDir).getPermission());
376387
// Throw a file in the dir
377388
Path dummyFile = new Path(workingDir, "dummy.txt");
378389
fs.createNewFile(dummyFile);
379-
Assert.assertTrue(fs.exists(dummyFile));
390+
assertTrue(fs.exists(dummyFile));
380391
// -force is false and the dir exists, so nothing will happen and the dummy
381392
// still exists
382393
dirPrepared = hal.prepareWorkingDir(fs, workingDir);
383-
Assert.assertFalse(dirPrepared);
384-
Assert.assertTrue(fs.exists(workingDir));
385-
Assert.assertTrue(fs.exists(dummyFile));
386-
Assert.assertEquals(
394+
assertFalse(dirPrepared);
395+
assertTrue(fs.exists(workingDir));
396+
assertTrue(fs.exists(dummyFile));
397+
assertEquals(
387398
new FsPermission(FsAction.ALL, FsAction.ALL, FsAction.ALL,
388399
!Shell.WINDOWS),
389400
fs.getFileStatus(workingDir).getPermission());
390401
// -force is true and the dir exists, so it will recreate it and the dummy
391402
// won't exist anymore
392403
hal.force = true;
393404
dirPrepared = hal.prepareWorkingDir(fs, workingDir);
394-
Assert.assertTrue(dirPrepared);
395-
Assert.assertTrue(fs.exists(workingDir));
396-
Assert.assertEquals(
405+
assertTrue(dirPrepared);
406+
assertTrue(fs.exists(workingDir));
407+
assertEquals(
397408
new FsPermission(FsAction.ALL, FsAction.ALL, FsAction.ALL,
398409
!Shell.WINDOWS),
399410
fs.getFileStatus(workingDir).getPermission());
400-
Assert.assertFalse(fs.exists(dummyFile));
411+
assertFalse(fs.exists(dummyFile));
401412
}
402413

403414
private static void createFile(FileSystem fs, Path p, long sizeMultiple)
@@ -413,7 +424,7 @@ private static void createFile(FileSystem fs, Path p, long sizeMultiple)
413424
out.close();
414425
}
415426
}
416-
Assert.assertTrue(fs.exists(p));
427+
assertTrue(fs.exists(p));
417428
}
418429

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

0 commit comments

Comments
 (0)