Skip to content

Commit a44b5fe

Browse files
committed
HADOOP-19422. Fix CheckStyle Issue.
1 parent 6a4e80b commit a44b5fe

File tree

2 files changed

+90
-88
lines changed

2 files changed

+90
-88
lines changed

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

Lines changed: 74 additions & 70 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,7 +42,6 @@
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.jupiter.api.Assertions;
4145
import org.junit.jupiter.api.Test;
4246
import org.junit.jupiter.api.Timeout;
4347

@@ -66,7 +70,7 @@ public void testCheckFilesAndSeedApps() throws Exception {
6670
String suffix = "logs";
6771
Path logDir = new Path(rootLogDir, new Path(USER, suffix));
6872
fs.delete(logDir, true);
69-
Assertions.assertFalse(fs.exists(logDir));
73+
assertFalse(fs.exists(logDir));
7074
fs.mkdirs(logDir);
7175

7276
// no files found
@@ -98,11 +102,11 @@ public void testCheckFilesAndSeedApps() throws Exception {
98102
createFile(fs, new Path(app5Path, "file1"), 2);
99103
createFile(fs, new Path(app5Path, "file2"), 3);
100104

101-
Assertions.assertEquals(0, hal.eligibleApplications.size());
105+
assertEquals(0, hal.eligibleApplications.size());
102106
hal.checkFilesAndSeedApps(fs, rootLogDir, suffix, new Path(rootLogDir,
103107
"archive-logs-work"));
104-
Assertions.assertEquals(1, hal.eligibleApplications.size());
105-
Assertions.assertEquals(appId5.toString(),
108+
assertEquals(1, hal.eligibleApplications.size());
109+
assertEquals(appId5.toString(),
106110
hal.eligibleApplications.iterator().next().getAppId());
107111
}
108112

@@ -132,43 +136,43 @@ public void testCheckMaxEligible() throws Exception {
132136
ApplicationId.newInstance(CLUSTER_TIMESTAMP, 7).toString(), USER);
133137
app7.setFinishTime(CLUSTER_TIMESTAMP);
134138
HadoopArchiveLogs hal = new HadoopArchiveLogs(conf);
135-
Assertions.assertEquals(0, hal.eligibleApplications.size());
139+
assertEquals(0, hal.eligibleApplications.size());
136140
hal.eligibleApplications.add(app1);
137141
hal.eligibleApplications.add(app2);
138142
hal.eligibleApplications.add(app3);
139143
hal.eligibleApplications.add(app4);
140144
hal.eligibleApplications.add(app5);
141145
hal.eligibleApplications.add(app6);
142146
hal.eligibleApplications.add(app7);
143-
Assertions.assertEquals(7, hal.eligibleApplications.size());
147+
assertEquals(7, hal.eligibleApplications.size());
144148
hal.maxEligible = -1;
145149
hal.checkMaxEligible();
146-
Assertions.assertEquals(7, hal.eligibleApplications.size());
150+
assertEquals(7, hal.eligibleApplications.size());
147151
hal.maxEligible = 6;
148152
hal.checkMaxEligible();
149-
Assertions.assertEquals(6, hal.eligibleApplications.size());
150-
Assertions.assertFalse(hal.eligibleApplications.contains(app5));
153+
assertEquals(6, hal.eligibleApplications.size());
154+
assertFalse(hal.eligibleApplications.contains(app5));
151155
hal.maxEligible = 5;
152156
hal.checkMaxEligible();
153-
Assertions.assertEquals(5, hal.eligibleApplications.size());
154-
Assertions.assertFalse(hal.eligibleApplications.contains(app4));
157+
assertEquals(5, hal.eligibleApplications.size());
158+
assertFalse(hal.eligibleApplications.contains(app4));
155159
hal.maxEligible = 4;
156160
hal.checkMaxEligible();
157-
Assertions.assertEquals(4, hal.eligibleApplications.size());
158-
Assertions.assertFalse(hal.eligibleApplications.contains(app7));
161+
assertEquals(4, hal.eligibleApplications.size());
162+
assertFalse(hal.eligibleApplications.contains(app7));
159163
hal.maxEligible = 3;
160164
hal.checkMaxEligible();
161-
Assertions.assertEquals(3, hal.eligibleApplications.size());
162-
Assertions.assertFalse(hal.eligibleApplications.contains(app1));
165+
assertEquals(3, hal.eligibleApplications.size());
166+
assertFalse(hal.eligibleApplications.contains(app1));
163167
hal.maxEligible = 2;
164168
hal.checkMaxEligible();
165-
Assertions.assertEquals(2, hal.eligibleApplications.size());
166-
Assertions.assertFalse(hal.eligibleApplications.contains(app2));
169+
assertEquals(2, hal.eligibleApplications.size());
170+
assertFalse(hal.eligibleApplications.contains(app2));
167171
hal.maxEligible = 1;
168172
hal.checkMaxEligible();
169-
Assertions.assertEquals(1, hal.eligibleApplications.size());
170-
Assertions.assertFalse(hal.eligibleApplications.contains(app6));
171-
Assertions.assertTrue(hal.eligibleApplications.contains(app3));
173+
assertEquals(1, hal.eligibleApplications.size());
174+
assertFalse(hal.eligibleApplications.contains(app6));
175+
assertTrue(hal.eligibleApplications.contains(app3));
172176
}
173177

174178
@Test
@@ -210,7 +214,7 @@ public void testFilterAppsByAggregatedStatus() throws Exception {
210214
// appImpl8 is not in the RM
211215

212216
HadoopArchiveLogs hal = new HadoopArchiveLogs(conf);
213-
Assertions.assertEquals(0, hal.eligibleApplications.size());
217+
assertEquals(0, hal.eligibleApplications.size());
214218
hal.eligibleApplications.add(
215219
new HadoopArchiveLogs.AppInfo(appImpl1.getApplicationId().toString(),
216220
USER));
@@ -238,12 +242,12 @@ public void testFilterAppsByAggregatedStatus() throws Exception {
238242
new HadoopArchiveLogs.AppInfo(appImpl8.getApplicationId().toString(),
239243
USER);
240244
hal.eligibleApplications.add(app8);
241-
Assertions.assertEquals(8, hal.eligibleApplications.size());
245+
assertEquals(8, hal.eligibleApplications.size());
242246
hal.filterAppsByAggregatedStatus();
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));
247+
assertEquals(3, hal.eligibleApplications.size());
248+
assertTrue(hal.eligibleApplications.contains(app4));
249+
assertTrue(hal.eligibleApplications.contains(app7));
250+
assertTrue(hal.eligibleApplications.contains(app8));
247251
}
248252
}
249253

@@ -281,59 +285,59 @@ private void _testGenerateScript(boolean proxy) throws Exception {
281285

282286
File localScript = new File("target", "script.sh");
283287
localScript.delete();
284-
Assertions.assertFalse(localScript.exists());
288+
assertFalse(localScript.exists());
285289
hal.generateScript(localScript);
286-
Assertions.assertTrue(localScript.exists());
290+
assertTrue(localScript.exists());
287291
String script = IOUtils.toString(localScript.toURI(), StandardCharsets.UTF_8);
288292
String[] lines = script.split("\n");
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]);
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]);
294298
boolean oneBefore = true;
295299
if (lines[4].contains(app1.toString())) {
296-
Assertions.assertEquals("\tappId=\"" + app1.toString() + "\"", lines[4]);
297-
Assertions.assertEquals("\tappId=\"" + app2.toString() + "\"", lines[10]);
300+
assertEquals("\tappId=\"" + app1.toString() + "\"", lines[4]);
301+
assertEquals("\tappId=\"" + app2.toString() + "\"", lines[10]);
298302
} else {
299303
oneBefore = false;
300-
Assertions.assertEquals("\tappId=\"" + app2.toString() + "\"", lines[4]);
301-
Assertions.assertEquals("\tappId=\"" + app1.toString() + "\"", lines[10]);
304+
assertEquals("\tappId=\"" + app2.toString() + "\"", lines[4]);
305+
assertEquals("\tappId=\"" + app1.toString() + "\"", lines[10]);
302306
}
303-
Assertions.assertEquals("\tuser=\"" + USER + "\"", lines[5]);
304-
Assertions.assertEquals("\tworkingDir=\"" + (oneBefore ? workingDir.toString()
307+
assertEquals("\tuser=\"" + USER + "\"", lines[5]);
308+
assertEquals("\tworkingDir=\"" + (oneBefore ? workingDir.toString()
305309
: workingDir2.toString()) + "\"", lines[6]);
306-
Assertions.assertEquals("\tremoteRootLogDir=\"" + (oneBefore
310+
assertEquals("\tremoteRootLogDir=\"" + (oneBefore
307311
? remoteRootLogDir.toString() : remoteRootLogDir2.toString())
308312
+ "\"", lines[7]);
309-
Assertions.assertEquals("\tsuffix=\"" + (oneBefore ? suffix : suffix2)
313+
assertEquals("\tsuffix=\"" + (oneBefore ? suffix : suffix2)
310314
+ "\"", lines[8]);
311-
Assertions.assertEquals("elif [ \"$YARN_SHELL_ID\" == \"2\" ]; then",
315+
assertEquals("elif [ \"$YARN_SHELL_ID\" == \"2\" ]; then",
312316
lines[9]);
313-
Assertions.assertEquals("\tuser=\"" + USER + "\"", lines[11]);
314-
Assertions.assertEquals("\tworkingDir=\"" + (oneBefore
317+
assertEquals("\tuser=\"" + USER + "\"", lines[11]);
318+
assertEquals("\tworkingDir=\"" + (oneBefore
315319
? workingDir2.toString() : workingDir.toString()) + "\"",
316320
lines[12]);
317-
Assertions.assertEquals("\tremoteRootLogDir=\"" + (oneBefore
321+
assertEquals("\tremoteRootLogDir=\"" + (oneBefore
318322
? remoteRootLogDir2.toString() : remoteRootLogDir.toString())
319323
+ "\"", lines[13]);
320-
Assertions.assertEquals("\tsuffix=\"" + (oneBefore ? suffix2 : suffix)
324+
assertEquals("\tsuffix=\"" + (oneBefore ? suffix2 : suffix)
321325
+ "\"", lines[14]);
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="));
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="));
328332
if (proxy) {
329-
Assertions.assertEquals(
333+
assertEquals(
330334
"\"$HADOOP_HOME\"/bin/hadoop org.apache.hadoop.tools." +
331335
"HadoopArchiveLogsRunner -appId \"$appId\" -user \"$user\" " +
332336
"-workingDir \"$workingDir\" -remoteRootLogDir " +
333337
"\"$remoteRootLogDir\" -suffix \"$suffix\"",
334338
lines[21]);
335339
} else {
336-
Assertions.assertEquals(
340+
assertEquals(
337341
"\"$HADOOP_HOME\"/bin/hadoop org.apache.hadoop.tools." +
338342
"HadoopArchiveLogsRunner -appId \"$appId\" -user \"$user\" " +
339343
"-workingDir \"$workingDir\" -remoteRootLogDir " +
@@ -359,7 +363,7 @@ public void testStatuses() throws Exception {
359363
statuses[4] = LogAggregationStatus.SUCCEEDED;
360364
statuses[5] = LogAggregationStatus.FAILED;
361365
statuses[6] = LogAggregationStatus.TIME_OUT;
362-
Assertions.assertArrayEquals(statuses, LogAggregationStatus.values());
366+
assertArrayEquals(statuses, LogAggregationStatus.values());
363367
}
364368

365369
@Test
@@ -370,41 +374,41 @@ public void testPrepareWorkingDir() throws Exception {
370374
FileSystem fs = FileSystem.getLocal(conf);
371375
Path workingDir = new Path("target", "testPrepareWorkingDir");
372376
fs.delete(workingDir, true);
373-
Assertions.assertFalse(fs.exists(workingDir));
377+
assertFalse(fs.exists(workingDir));
374378
// -force is false and the dir doesn't exist so it will create one
375379
hal.force = false;
376380
boolean dirPrepared = hal.prepareWorkingDir(fs, workingDir);
377-
Assertions.assertTrue(dirPrepared);
378-
Assertions.assertTrue(fs.exists(workingDir));
379-
Assertions.assertEquals(
381+
assertTrue(dirPrepared);
382+
assertTrue(fs.exists(workingDir));
383+
assertEquals(
380384
new FsPermission(FsAction.ALL, FsAction.ALL, FsAction.ALL,
381385
!Shell.WINDOWS),
382386
fs.getFileStatus(workingDir).getPermission());
383387
// Throw a file in the dir
384388
Path dummyFile = new Path(workingDir, "dummy.txt");
385389
fs.createNewFile(dummyFile);
386-
Assertions.assertTrue(fs.exists(dummyFile));
390+
assertTrue(fs.exists(dummyFile));
387391
// -force is false and the dir exists, so nothing will happen and the dummy
388392
// still exists
389393
dirPrepared = hal.prepareWorkingDir(fs, workingDir);
390-
Assertions.assertFalse(dirPrepared);
391-
Assertions.assertTrue(fs.exists(workingDir));
392-
Assertions.assertTrue(fs.exists(dummyFile));
393-
Assertions.assertEquals(
394+
assertFalse(dirPrepared);
395+
assertTrue(fs.exists(workingDir));
396+
assertTrue(fs.exists(dummyFile));
397+
assertEquals(
394398
new FsPermission(FsAction.ALL, FsAction.ALL, FsAction.ALL,
395399
!Shell.WINDOWS),
396400
fs.getFileStatus(workingDir).getPermission());
397401
// -force is true and the dir exists, so it will recreate it and the dummy
398402
// won't exist anymore
399403
hal.force = true;
400404
dirPrepared = hal.prepareWorkingDir(fs, workingDir);
401-
Assertions.assertTrue(dirPrepared);
402-
Assertions.assertTrue(fs.exists(workingDir));
403-
Assertions.assertEquals(
405+
assertTrue(dirPrepared);
406+
assertTrue(fs.exists(workingDir));
407+
assertEquals(
404408
new FsPermission(FsAction.ALL, FsAction.ALL, FsAction.ALL,
405409
!Shell.WINDOWS),
406410
fs.getFileStatus(workingDir).getPermission());
407-
Assertions.assertFalse(fs.exists(dummyFile));
411+
assertFalse(fs.exists(dummyFile));
408412
}
409413

410414
private static void createFile(FileSystem fs, Path p, long sizeMultiple)
@@ -420,7 +424,7 @@ private static void createFile(FileSystem fs, Path p, long sizeMultiple)
420424
out.close();
421425
}
422426
}
423-
Assertions.assertTrue(fs.exists(p));
427+
assertTrue(fs.exists(p));
424428
}
425429

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

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

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -33,21 +33,22 @@
3333
import org.apache.hadoop.yarn.conf.YarnConfiguration;
3434
import org.apache.hadoop.yarn.server.MiniYARNCluster;
3535
import org.junit.jupiter.api.AfterEach;
36-
import org.junit.jupiter.api.Assertions;
3736
import org.junit.jupiter.api.BeforeEach;
38-
import org.junit.Rule;
3937
import org.junit.jupiter.api.Test;
40-
import org.junit.rules.Timeout;
38+
import org.junit.jupiter.api.Timeout;
4139
import org.mockito.Mockito;
4240

4341
import java.io.IOException;
4442
import java.util.Arrays;
4543
import java.util.Comparator;
4644
import java.util.Random;
4745

48-
import static org.junit.jupiter.api.Assertions.*;
49-
import static org.mockito.Mockito.*;
46+
import static org.junit.jupiter.api.Assertions.assertEquals;
47+
import static org.junit.jupiter.api.Assertions.assertNotEquals;
48+
import static org.mockito.Mockito.mock;
49+
import static org.mockito.Mockito.when;
5050

51+
@Timeout(50)
5152
public class TestHadoopArchiveLogsRunner {
5253

5354
private static final int FILE_SIZE_INCREMENT = 4096;
@@ -68,9 +69,6 @@ public class TestHadoopArchiveLogsRunner {
6869
private Path remoteRootLogDir;
6970
private String suffix;
7071

71-
@Rule
72-
public Timeout globalTimeout = new Timeout(50000);
73-
7472
@BeforeEach
7573
public void setup() throws Exception {
7674
yarnCluster = new MiniYARNCluster(
@@ -100,7 +98,7 @@ public void setup() throws Exception {
10098
createFile(fs, new Path(app1Path, "log" + (i + 1)), FILE_SIZES[i]);
10199
}
102100
FileStatus[] app1Files = fs.listStatus(app1Path);
103-
Assertions.assertEquals(FILE_COUNT, app1Files.length);
101+
assertEquals(FILE_COUNT, app1Files.length);
104102
}
105103

106104
@AfterEach
@@ -124,12 +122,12 @@ public void testHadoopArchiveLogs() throws Exception {
124122

125123
fs = FileSystem.get(conf);
126124
FileStatus[] app1Files = fs.listStatus(app1Path);
127-
Assertions.assertEquals(1, app1Files.length);
125+
assertEquals(1, app1Files.length);
128126
FileStatus harFile = app1Files[0];
129-
Assertions.assertEquals(app1.toString() + ".har", harFile.getPath().getName());
127+
assertEquals(app1.toString() + ".har", harFile.getPath().getName());
130128
Path harPath = new Path("har:///" + harFile.getPath().toUri().getRawPath());
131129
FileStatus[] harLogs = HarFs.get(harPath.toUri(), conf).listStatus(harPath);
132-
Assertions.assertEquals(FILE_COUNT, harLogs.length);
130+
assertEquals(FILE_COUNT, harLogs.length);
133131
Arrays.sort(harLogs, new Comparator<FileStatus>() {
134132
@Override
135133
public int compare(FileStatus o1, FileStatus o2) {
@@ -138,15 +136,15 @@ public int compare(FileStatus o1, FileStatus o2) {
138136
});
139137
for (int i = 0; i < FILE_COUNT; i++) {
140138
FileStatus harLog = harLogs[i];
141-
Assertions.assertEquals("log" + (i + 1), harLog.getPath().getName());
142-
Assertions.assertEquals(FILE_SIZES[i] * FILE_SIZE_INCREMENT, harLog.getLen());
143-
Assertions.assertEquals(
139+
assertEquals("log" + (i + 1), harLog.getPath().getName());
140+
assertEquals(FILE_SIZES[i] * FILE_SIZE_INCREMENT, harLog.getLen());
141+
assertEquals(
144142
new FsPermission(FsAction.READ_WRITE, FsAction.READ, FsAction.NONE),
145143
harLog.getPermission());
146-
Assertions.assertEquals(System.getProperty("user.name"),
144+
assertEquals(System.getProperty("user.name"),
147145
harLog.getOwner());
148146
}
149-
Assertions.assertEquals(0, fs.listStatus(workingDir).length);
147+
assertEquals(0, fs.listStatus(workingDir).length);
150148
}
151149

152150
@Test
@@ -162,7 +160,7 @@ public void testHadoopArchiveLogsWithArchiveError() throws Exception {
162160
FileStatus[] app1Files = fs.listStatus(app1Path);
163161
assertEquals(FILE_COUNT, app1Files.length);
164162
for (int i = 0; i < FILE_COUNT; i++) {
165-
Assertions.assertEquals(FILE_SIZES[i] * FILE_SIZE_INCREMENT,
163+
assertEquals(FILE_SIZES[i] * FILE_SIZE_INCREMENT,
166164
app1Files[i].getLen());
167165
}
168166
}

0 commit comments

Comments
 (0)