Skip to content

Commit 00f548e

Browse files
author
fanshilun
committed
MAPREDUCE-7420. Fix CheckStyle & Junit Test.
1 parent d7ae783 commit 00f548e

File tree

57 files changed

+598
-564
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+598
-564
lines changed

hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/test/java/org/apache/hadoop/mapred/TestCounters.java

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@
1717
*/
1818
package org.apache.hadoop.mapred;
1919

20+
import static org.junit.jupiter.api.Assertions.assertEquals;
21+
import static org.junit.jupiter.api.Assertions.assertFalse;
22+
import static org.junit.jupiter.api.Assertions.assertNotNull;
23+
import static org.junit.jupiter.api.Assertions.assertNull;
24+
import static org.junit.jupiter.api.Assertions.assertTrue;
25+
import static org.junit.jupiter.api.Assertions.fail;
26+
2027
import java.io.IOException;
2128
import java.text.ParseException;
2229
import java.util.HashSet;
@@ -36,18 +43,11 @@
3643
import org.slf4j.Logger;
3744
import org.slf4j.LoggerFactory;
3845

39-
import static org.junit.jupiter.api.Assertions.assertEquals;
40-
import static org.junit.jupiter.api.Assertions.assertFalse;
41-
import static org.junit.jupiter.api.Assertions.assertNotNull;
42-
import static org.junit.jupiter.api.Assertions.assertNull;
43-
import static org.junit.jupiter.api.Assertions.assertTrue;
44-
import static org.junit.jupiter.api.Assertions.fail;
45-
4646
/**
4747
* TestCounters checks the sanity and recoverability of {@code Counters}
4848
*/
4949
public class TestCounters {
50-
enum myCounters {TEST1, TEST2}
50+
enum myCounters {TEST1, TEST2};
5151
private static final long MAX_VALUE = 10;
5252
private static final Logger LOG = LoggerFactory.getLogger(TestCounters.class);
5353

@@ -110,7 +110,7 @@ public void testCounters() throws IOException {
110110
// I. Check enum counters that have resource bundler
111111
testCounter(getEnumCounters(keysWithResource));
112112

113-
// II. Check enum counters that don't have resource bundler
113+
// II. Check enum counters that dont have resource bundler
114114
testCounter(getEnumCounters(keysWithoutResource));
115115

116116
// III. Check string counters
@@ -247,8 +247,8 @@ public void testLegacyGetGroupNames() {
247247
counters.findCounter("fs2", FileSystemCounter.BYTES_READ).increment(1);
248248
counters.incrCounter("group1", "counter1", 1);
249249

250-
HashSet<String> groups = new HashSet<>(counters.getGroupNames());
251-
HashSet<String> expectedGroups = new HashSet<>();
250+
HashSet<String> groups = new HashSet<String>(counters.getGroupNames());
251+
HashSet<String> expectedGroups = new HashSet<String>();
252252
expectedGroups.add("group1");
253253
expectedGroups.add("FileSystemCounters"); //Legacy Name
254254
expectedGroups.add("org.apache.hadoop.mapreduce.FileSystemCounter");
@@ -265,8 +265,8 @@ public void testMakeCompactString() {
265265
assertEquals("group1.counter1:1", counters.makeCompactString());
266266
counters.incrCounter("group2", "counter2", 3);
267267
String cs = counters.makeCompactString();
268-
assertTrue(
269-
cs.equals(GC1 + ',' + GC2) || cs.equals(GC2 + ',' + GC1), "Bad compact string");
268+
assertTrue(cs.equals(GC1 + ',' + GC2) || cs.equals(GC2 + ',' + GC1),
269+
"Bad compact string");
270270
}
271271

272272
@Test
@@ -280,7 +280,11 @@ private void testMaxCountersLimits(final Counters counters) {
280280
counters.findCounter("test", "test" + i);
281281
}
282282
setExpected(counters);
283-
shouldThrow(CountersExceededException.class, () -> counters.findCounter("test", "bad"));
283+
shouldThrow(CountersExceededException.class, new Runnable() {
284+
public void run() {
285+
counters.findCounter("test", "bad");
286+
}
287+
});
284288
checkExpected(counters);
285289
}
286290

@@ -290,7 +294,11 @@ private void testMaxGroupsLimits(final Counters counters) {
290294
counters.findCounter("test" + i, "test");
291295
}
292296
setExpected(counters);
293-
shouldThrow(CountersExceededException.class, () -> counters.findCounter("bad", "test"));
297+
shouldThrow(CountersExceededException.class, new Runnable() {
298+
public void run() {
299+
counters.findCounter("bad", "test");
300+
}
301+
});
294302
checkExpected(counters);
295303
}
296304

hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/test/java/org/apache/hadoop/mapred/TestFileInputFormat.java

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public class TestFileInputFormat {
6161

6262
public void initTestFileInputFormat(int numThreads) {
6363
this.numThreads = numThreads;
64-
LOG.info("Running with numThreads: {}.", numThreads);
64+
LOG.info("Running with numThreads: " + numThreads);
6565
}
6666

6767
public static Collection<Object[]> data() {
@@ -71,7 +71,7 @@ public static Collection<Object[]> data() {
7171

7272
@BeforeEach
7373
public void setup() throws IOException {
74-
LOG.info("Using Test Dir: {}.", TEST_ROOT_DIR);
74+
LOG.info("Using Test Dir: " + TEST_ROOT_DIR);
7575
localFs = FileSystem.getLocal(new Configuration());
7676
localFs.delete(TEST_ROOT_DIR, true);
7777
localFs.mkdirs(TEST_ROOT_DIR);
@@ -93,15 +93,14 @@ public void testListLocatedStatus(int numThreads) throws Exception {
9393
"test:///a1/a2");
9494
MockFileSystem mockFs =
9595
(MockFileSystem) new Path("test:///").getFileSystem(conf);
96-
assertEquals(
97-
0, mockFs.numListLocatedStatusCalls, "listLocatedStatus already called");
96+
assertEquals(0, mockFs.numListLocatedStatusCalls,
97+
"listLocatedStatus already called");
9898
JobConf job = new JobConf(conf);
9999
TextInputFormat fileInputFormat = new TextInputFormat();
100100
fileInputFormat.configure(job);
101101
InputSplit[] splits = fileInputFormat.getSplits(job, 1);
102102
assertEquals(2, splits.length, "Input splits are not correct");
103-
assertEquals(
104-
1, mockFs.numListLocatedStatusCalls, "listLocatedStatus calls");
103+
assertEquals(1, mockFs.numListLocatedStatusCalls, "listLocatedStatus calls");
105104
FileSystem.closeAll();
106105
}
107106

@@ -250,9 +249,9 @@ public FileStatus[] listStatus(Path f) throws FileNotFoundException,
250249
} else if (f.toString().equals("test:/a1/a2")) {
251250
return new FileStatus[] {
252251
new FileStatus(10, false, 1, 150, 150,
253-
new Path("test:/a1/a2/file2")),
252+
new Path("test:/a1/a2/file2")),
254253
new FileStatus(10, false, 1, 151, 150,
255-
new Path("test:/a1/a2/file3")) };
254+
new Path("test:/a1/a2/file3")) };
256255
}
257256
return new FileStatus[0];
258257
}
@@ -275,8 +274,8 @@ public BlockLocation[] getFileBlockLocations(FileStatus file, long start, long l
275274
throws IOException {
276275
return new BlockLocation[] {
277276
new BlockLocation(new String[] { "localhost:9866", "otherhost:9866" },
278-
new String[] { "localhost", "otherhost" }, new String[] { "localhost" },
279-
new String[0], 0, len, false) };
277+
new String[] { "localhost", "otherhost" }, new String[] { "localhost" },
278+
new String[0], 0, len, false) };
280279
}
281280

282281
@Override

hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/test/java/org/apache/hadoop/mapred/TestFileOutputCommitter.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
import static org.junit.jupiter.api.Assertions.assertNotNull;
3232
import static org.junit.jupiter.api.Assertions.assertTrue;
3333
import static org.junit.jupiter.api.Assertions.fail;
34-
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
3534

3635
import org.apache.hadoop.fs.FileStatus;
3736
import org.apache.hadoop.fs.FileSystem;
@@ -151,8 +150,8 @@ private void testRecoveryInternal(int commitVersion, int recoveryVersion)
151150
} else {
152151
assertFalse(jtd2.exists(), "Version 2 commits to output dir " + jtd2);
153152
if (commitVersion == 1) {
154-
assertEquals(0, jtd1.list().length, "Version 2 recovery moves to output dir from "
155-
+ jtd1);
153+
assertEquals(0, jtd1.list().length,
154+
"Version 2 recovery moves to output dir from " + jtd1);
156155
}
157156
}
158157

@@ -543,7 +542,7 @@ private void testFailAbortInternal(int version)
543542
th = ie;
544543
}
545544
assertNotNull(th);
546-
assertInstanceOf(IOException.class, th);
545+
assertTrue(th instanceof IOException);
547546
assertTrue(th.getMessage().contains("fake delete failed"));
548547
assertTrue(expectedFile.exists(), expectedFile + " does not exists");
549548

@@ -554,7 +553,7 @@ private void testFailAbortInternal(int version)
554553
th = ie;
555554
}
556555
assertNotNull(th);
557-
assertInstanceOf(IOException.class, th);
556+
assertTrue(th instanceof IOException);
558557
assertTrue(th.getMessage().contains("fake delete failed"));
559558
assertTrue(jobTmpDir.exists(), "job temp dir does not exists");
560559
FileUtil.fullyDelete(new File(outDir.toString()));
@@ -573,7 +572,7 @@ public static String slurp(File f) throws IOException {
573572
int len = (int) f.length();
574573
byte[] buf = new byte[len];
575574
FileInputStream in = new FileInputStream(f);
576-
String contents;
575+
String contents = null;
577576
try {
578577
in.read(buf, 0, len);
579578
contents = new String(buf, StandardCharsets.UTF_8);
@@ -584,7 +583,7 @@ public static String slurp(File f) throws IOException {
584583
}
585584

586585
/**
587-
* The class provides a override implementation of commitJobInternal which
586+
* The class provides a overrided implementation of commitJobInternal which
588587
* causes the commit failed for the first time then succeed.
589588
*/
590589
public static class CommitterWithFailedThenSucceed extends

hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/test/java/org/apache/hadoop/mapred/TestIndexCache.java

Lines changed: 40 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,8 @@ public void testInvalidReduceNumberOrLength() throws Exception {
176176
try {
177177
// Number of reducers equal to partsPerMap
178178
cache.getIndexInformation("reduceEqualPartsPerMap",
179-
partsPerMap, // reduce number == partsPerMap
180-
feq, UserGroupInformation.getCurrentUser().getShortUserName());
179+
partsPerMap, // reduce number == partsPerMap
180+
feq, UserGroupInformation.getCurrentUser().getShortUserName());
181181
fail("Number of reducers equal to partsPerMap did not fail");
182182
} catch (Exception e) {
183183
if (!(e instanceof IOException)) {
@@ -216,20 +216,28 @@ public void testRemoveMap() throws Exception {
216216

217217
final Path big = new Path(p, "bigIndex");
218218
final String user =
219-
UserGroupInformation.getCurrentUser().getShortUserName();
219+
UserGroupInformation.getCurrentUser().getShortUserName();
220220
writeFile(fs, big, bytesPerFile, partsPerMap);
221221

222222
// run multiple times
223223
for (int i = 0; i < 20; ++i) {
224-
Thread getInfoThread = new Thread(() -> {
225-
try {
226-
cache.getIndexInformation("bigIndex", partsPerMap, big, user);
227-
} catch (Exception e) {
228-
// should not be here
224+
Thread getInfoThread = new Thread() {
225+
@Override
226+
public void run() {
227+
try {
228+
cache.getIndexInformation("bigIndex", partsPerMap, big, user);
229+
} catch (Exception e) {
230+
// should not be here
231+
}
232+
}
233+
};
234+
Thread removeMapThread = new Thread() {
235+
@Override
236+
public void run() {
237+
cache.removeMap("bigIndex");
229238
}
230-
});
231-
Thread removeMapThread = new Thread(() -> cache.removeMap("bigIndex"));
232-
if (i % 2 == 0) {
239+
};
240+
if (i%2==0) {
233241
getInfoThread.start();
234242
removeMapThread.start();
235243
} else {
@@ -252,20 +260,23 @@ public void testCreateRace() throws Exception {
252260

253261
final Path racy = new Path(p, "racyIndex");
254262
final String user =
255-
UserGroupInformation.getCurrentUser().getShortUserName();
263+
UserGroupInformation.getCurrentUser().getShortUserName();
256264
writeFile(fs, racy, bytesPerFile, partsPerMap);
257265

258266
// run multiple instances
259267
Thread[] getInfoThreads = new Thread[50];
260268
for (int i = 0; i < 50; i++) {
261-
getInfoThreads[i] = new Thread(() -> {
262-
try {
263-
cache.getIndexInformation("racyIndex", partsPerMap, racy, user);
264-
cache.removeMap("racyIndex");
265-
} catch (Exception e) {
266-
// should not be here
269+
getInfoThreads[i] = new Thread() {
270+
@Override
271+
public void run() {
272+
try {
273+
cache.getIndexInformation("racyIndex", partsPerMap, racy, user);
274+
cache.removeMap("racyIndex");
275+
} catch (Exception e) {
276+
// should not be here
277+
}
267278
}
268-
});
279+
};
269280
}
270281

271282
for (int i = 0; i < 50; i++) {
@@ -274,14 +285,17 @@ public void testCreateRace() throws Exception {
274285

275286
final Thread mainTestThread = Thread.currentThread();
276287

277-
Thread timeoutThread = new Thread(() -> {
278-
try {
279-
Thread.sleep(15000);
280-
mainTestThread.interrupt();
281-
} catch (InterruptedException ie) {
282-
// we are done;
288+
Thread timeoutThread = new Thread() {
289+
@Override
290+
public void run() {
291+
try {
292+
Thread.sleep(15000);
293+
mainTestThread.interrupt();
294+
} catch (InterruptedException ie) {
295+
// we are done;
296+
}
283297
}
284-
});
298+
};
285299

286300
for (int i = 0; i < 50; i++) {
287301
try {

hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/test/java/org/apache/hadoop/mapred/TestJobAclsManager.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import static org.junit.jupiter.api.Assertions.assertFalse;
2121
import static org.junit.jupiter.api.Assertions.assertTrue;
2222

23+
import java.util.HashMap;
2324
import java.util.Map;
2425

2526
import org.apache.hadoop.conf.Configuration;
@@ -36,7 +37,7 @@ public class TestJobAclsManager {
3637

3738
@Test
3839
public void testClusterAdmins() {
39-
Map<JobACL, AccessControlList> tmpJobACLs;
40+
Map<JobACL, AccessControlList> tmpJobACLs = new HashMap<JobACL, AccessControlList>();
4041
Configuration conf = new Configuration();
4142
String jobOwner = "testuser";
4243
conf.set(JobACL.VIEW_JOB.getAclName(), jobOwner);
@@ -63,7 +64,7 @@ public void testClusterAdmins() {
6364

6465
@Test
6566
public void testClusterNoAdmins() {
66-
Map<JobACL, AccessControlList> tmpJobACLs;
67+
Map<JobACL, AccessControlList> tmpJobACLs = new HashMap<JobACL, AccessControlList>();
6768
Configuration conf = new Configuration();
6869
String jobOwner = "testuser";
6970
conf.set(JobACL.VIEW_JOB.getAclName(), "");
@@ -97,7 +98,7 @@ public void testClusterNoAdmins() {
9798

9899
@Test
99100
public void testAclsOff() {
100-
Map<JobACL, AccessControlList> tmpJobACLs;
101+
Map<JobACL, AccessControlList> tmpJobACLs = new HashMap<JobACL, AccessControlList>();
101102
Configuration conf = new Configuration();
102103
String jobOwner = "testuser";
103104
conf.set(JobACL.VIEW_JOB.getAclName(), jobOwner);
@@ -118,7 +119,7 @@ public void testAclsOff() {
118119

119120
@Test
120121
public void testGroups() {
121-
Map<JobACL, AccessControlList> tmpJobACLs;
122+
Map<JobACL, AccessControlList> tmpJobACLs = new HashMap<JobACL, AccessControlList>();
122123
Configuration conf = new Configuration();
123124
String jobOwner = "testuser";
124125
conf.set(JobACL.VIEW_JOB.getAclName(), jobOwner);

hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/test/java/org/apache/hadoop/mapred/TestJobConf.java

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -158,10 +158,10 @@ public void testJobConf() {
158158

159159
// make sure mapreduce.map|reduce.java.opts are not set by default
160160
// so that they won't override mapred.child.java.opts
161-
assertNull(
162-
conf.get(JobConf.MAPRED_MAP_TASK_JAVA_OPTS), "mapreduce.map.java.opts should not be set by default");
163-
assertNull(
164-
conf.get(JobConf.MAPRED_REDUCE_TASK_JAVA_OPTS), "mapreduce.reduce.java.opts should not be set by default");
161+
assertNull(conf.get(JobConf.MAPRED_MAP_TASK_JAVA_OPTS),
162+
"mapreduce.map.java.opts should not be set by default");
163+
assertNull(conf.get(JobConf.MAPRED_REDUCE_TASK_JAVA_OPTS),
164+
"mapreduce.reduce.java.opts should not be set by default");
165165
}
166166

167167
/**
@@ -363,11 +363,10 @@ public void testMaxVirtualMemoryForTask() {
363363
@Test
364364
public void testMaxTaskFailuresPerTracker() {
365365
JobConf jobConf = new JobConf(true);
366-
assertTrue(
367-
jobConf.getMaxTaskFailuresPerTracker() < jobConf.getMaxMapAttempts() &&
368-
jobConf.getMaxTaskFailuresPerTracker() < jobConf.getMaxReduceAttempts(), "By default JobContext.MAX_TASK_FAILURES_PER_TRACKER was "
369-
+ "not less than JobContext.MAP_MAX_ATTEMPTS and REDUCE_MAX_ATTEMPTS"
370-
);
366+
assertTrue(jobConf.getMaxTaskFailuresPerTracker() < jobConf.getMaxMapAttempts() &&
367+
jobConf.getMaxTaskFailuresPerTracker() < jobConf.getMaxReduceAttempts(),
368+
"By default JobContext.MAX_TASK_FAILURES_PER_TRACKER was "
369+
+ "not less than JobContext.MAP_MAX_ATTEMPTS and REDUCE_MAX_ATTEMPTS");
371370
}
372371

373372
/**

0 commit comments

Comments
 (0)