Skip to content

Commit 1fc7a1d

Browse files
author
fanshilun
committed
HADOOP-19415. Fix CheckStyle & Fix Unit Test.
1 parent 0a6f4cc commit 1fc7a1d

35 files changed

+499
-480
lines changed

hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestApplicationClassLoader.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,8 @@ public void testGetResource() throws IOException {
130130
ClassLoader appClassloader = new ApplicationClassLoader(
131131
new URL[] { testJar }, currentClassLoader, null);
132132

133-
assertNull(
134-
currentClassLoader.getResourceAsStream("resource.txt"), "Resource should be null for current classloader");
133+
assertNull(currentClassLoader.getResourceAsStream("resource.txt"),
134+
"Resource should be null for current classloader");
135135

136136
InputStream in = appClassloader.getResourceAsStream("resource.txt");
137137
assertNotNull(in, "Resource should not be null for app classloader");

hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestAsyncDiskService.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@
1818
package org.apache.hadoop.util;
1919

2020
import org.junit.jupiter.api.Test;
21-
import static org.junit.jupiter.api.Assertions.*;
21+
import static org.junit.jupiter.api.Assertions.assertEquals;
22+
import static org.junit.jupiter.api.Assertions.assertNotNull;
23+
import static org.junit.jupiter.api.Assertions.fail;
2224
import org.slf4j.Logger;
2325
import org.slf4j.LoggerFactory;
2426

hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestCacheableIPList.java

Lines changed: 18 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
import java.io.IOException;
2121
import org.junit.jupiter.api.Test;
2222

23-
import static org.junit.jupiter.api.Assertions.*;
23+
import static org.junit.jupiter.api.Assertions.assertFalse;
24+
import static org.junit.jupiter.api.Assertions.assertTrue;
2425

2526
public class TestCacheableIPList {
2627

@@ -44,10 +45,8 @@ public void testAddWithSleepForCacheTimeout() throws IOException, InterruptedExc
4445
CacheableIPList cipl = new CacheableIPList(
4546
new FileBasedIPList("ips.txt"),100);
4647

47-
assertFalse(
48-
cipl.isIn("10.113.221.222"), "10.113.221.222 is in the list");
49-
assertFalse (
50-
cipl.isIn("10.222.103.121"), "10.222.103.121 is in the list");
48+
assertFalse(cipl.isIn("10.113.221.222"), "10.113.221.222 is in the list");
49+
assertFalse (cipl.isIn("10.222.103.121"), "10.222.103.121 is in the list");
5150

5251
TestFileBasedIPList.removeFile("ips.txt");
5352
String[]ips2 = {"10.119.103.112", "10.221.102.0/23",
@@ -56,10 +55,8 @@ public void testAddWithSleepForCacheTimeout() throws IOException, InterruptedExc
5655
TestFileBasedIPList.createFileWithEntries ("ips.txt", ips2);
5756
Thread.sleep(101);
5857

59-
assertTrue(
60-
cipl.isIn("10.113.221.222"), "10.113.221.222 is not in the list");
61-
assertTrue (
62-
cipl.isIn("10.222.103.121"), "10.222.103.121 is not in the list");
58+
assertTrue(cipl.isIn("10.113.221.222"), "10.113.221.222 is not in the list");
59+
assertTrue (cipl.isIn("10.222.103.121"), "10.222.103.121 is not in the list");
6360

6461
TestFileBasedIPList.removeFile("ips.txt");
6562
}
@@ -85,21 +82,17 @@ public void testRemovalWithSleepForCacheTimeout() throws IOException, Interrupte
8582
CacheableIPList cipl = new CacheableIPList(
8683
new FileBasedIPList("ips.txt"),100);
8784

88-
assertTrue(
89-
cipl.isIn("10.113.221.222"), "10.113.221.222 is not in the list");
90-
assertTrue (
91-
cipl.isIn("10.222.103.121"), "10.222.103.121 is not in the list");
85+
assertTrue(cipl.isIn("10.113.221.222"), "10.113.221.222 is not in the list");
86+
assertTrue (cipl.isIn("10.222.103.121"), "10.222.103.121 is not in the list");
9287

9388
TestFileBasedIPList.removeFile("ips.txt");
9489
String[]ips2 = {"10.119.103.112", "10.221.102.0/23", "10.113.221.221"};
9590

9691
TestFileBasedIPList.createFileWithEntries ("ips.txt", ips2);
9792
Thread.sleep(1005);
9893

99-
assertFalse(
100-
cipl.isIn("10.113.221.222"), "10.113.221.222 is in the list");
101-
assertFalse (
102-
cipl.isIn("10.222.103.121"), "10.222.103.121 is in the list");
94+
assertFalse(cipl.isIn("10.113.221.222"), "10.113.221.222 is in the list");
95+
assertFalse (cipl.isIn("10.222.103.121"), "10.222.103.121 is in the list");
10396

10497
TestFileBasedIPList.removeFile("ips.txt");
10598
}
@@ -124,10 +117,8 @@ public void testAddWithRefresh() throws IOException, InterruptedException {
124117
CacheableIPList cipl = new CacheableIPList(
125118
new FileBasedIPList("ips.txt"),100);
126119

127-
assertFalse(
128-
cipl.isIn("10.113.221.222"), "10.113.221.222 is in the list");
129-
assertFalse (
130-
cipl.isIn("10.222.103.121"), "10.222.103.121 is in the list");
120+
assertFalse(cipl.isIn("10.113.221.222"), "10.113.221.222 is in the list");
121+
assertFalse (cipl.isIn("10.222.103.121"), "10.222.103.121 is in the list");
131122

132123
TestFileBasedIPList.removeFile("ips.txt");
133124
String[]ips2 = {"10.119.103.112", "10.221.102.0/23",
@@ -136,10 +127,8 @@ public void testAddWithRefresh() throws IOException, InterruptedException {
136127
TestFileBasedIPList.createFileWithEntries ("ips.txt", ips2);
137128
cipl.refresh();
138129

139-
assertTrue(
140-
cipl.isIn("10.113.221.222"), "10.113.221.222 is not in the list");
141-
assertTrue (
142-
cipl.isIn("10.222.103.121"), "10.222.103.121 is not in the list");
130+
assertTrue(cipl.isIn("10.113.221.222"), "10.113.221.222 is not in the list");
131+
assertTrue (cipl.isIn("10.222.103.121"), "10.222.103.121 is not in the list");
143132

144133
TestFileBasedIPList.removeFile("ips.txt");
145134
}
@@ -165,21 +154,17 @@ public void testRemovalWithRefresh() throws IOException, InterruptedException {
165154
CacheableIPList cipl = new CacheableIPList(
166155
new FileBasedIPList("ips.txt"),100);
167156

168-
assertTrue(
169-
cipl.isIn("10.113.221.222"), "10.113.221.222 is not in the list");
170-
assertTrue (
171-
cipl.isIn("10.222.103.121"), "10.222.103.121 is not in the list");
157+
assertTrue(cipl.isIn("10.113.221.222"), "10.113.221.222 is not in the list");
158+
assertTrue (cipl.isIn("10.222.103.121"), "10.222.103.121 is not in the list");
172159

173160
TestFileBasedIPList.removeFile("ips.txt");
174161
String[]ips2 = {"10.119.103.112", "10.221.102.0/23", "10.113.221.221"};
175162

176163
TestFileBasedIPList.createFileWithEntries ("ips.txt", ips2);
177164
cipl.refresh();
178165

179-
assertFalse(
180-
cipl.isIn("10.113.221.222"), "10.113.221.222 is in the list");
181-
assertFalse (
182-
cipl.isIn("10.222.103.121"), "10.222.103.121 is in the list");
166+
assertFalse(cipl.isIn("10.113.221.222"), "10.113.221.222 is in the list");
167+
assertFalse (cipl.isIn("10.222.103.121"), "10.222.103.121 is in the list");
183168

184169
TestFileBasedIPList.removeFile("ips.txt");
185170
}

hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestChunkedArrayList.java

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

20-
import static org.junit.jupiter.api.Assertions.*;
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.assertTrue;
2123

2224
import java.util.ArrayList;
2325
import java.util.Iterator;
2426
import java.util.concurrent.TimeUnit;
2527

26-
import org.junit.jupiter.api.Assertions;
2728
import org.junit.jupiter.api.Test;
2829

2930
public class TestChunkedArrayList {
@@ -103,41 +104,41 @@ public void testRemovals() throws Exception {
103104
// Iterate through all list elements.
104105
Iterator<Integer> iter = list.iterator();
105106
for (int i = 0; i < NUM_ELEMS; i++) {
106-
Assertions.assertTrue(iter.hasNext());
107+
assertTrue(iter.hasNext());
107108
Integer val = iter.next();
108-
Assertions.assertEquals(Integer.valueOf(i), val);
109+
assertEquals(Integer.valueOf(i), val);
109110
}
110-
Assertions.assertFalse(iter.hasNext());
111-
Assertions.assertEquals(NUM_ELEMS, list.size());
111+
assertFalse(iter.hasNext());
112+
assertEquals(NUM_ELEMS, list.size());
112113

113114
// Remove even elements.
114115
iter = list.iterator();
115116
for (int i = 0; i < NUM_ELEMS; i++) {
116-
Assertions.assertTrue(iter.hasNext());
117+
assertTrue(iter.hasNext());
117118
Integer val = iter.next();
118-
Assertions.assertEquals(Integer.valueOf(i), val);
119+
assertEquals(Integer.valueOf(i), val);
119120
if (i % 2 == 0) {
120121
iter.remove();
121122
}
122123
}
123-
Assertions.assertFalse(iter.hasNext());
124-
Assertions.assertEquals(NUM_ELEMS / 2, list.size());
124+
assertFalse(iter.hasNext());
125+
assertEquals(NUM_ELEMS / 2, list.size());
125126

126127
// Iterate through all odd list elements.
127128
iter = list.iterator();
128129
for (int i = 0; i < NUM_ELEMS / 2; i++) {
129-
Assertions.assertTrue(iter.hasNext());
130+
assertTrue(iter.hasNext());
130131
Integer val = iter.next();
131-
Assertions.assertEquals(Integer.valueOf(1 + (2 * i)), val);
132+
assertEquals(Integer.valueOf(1 + (2 * i)), val);
132133
iter.remove();
133134
}
134-
Assertions.assertFalse(iter.hasNext());
135+
assertFalse(iter.hasNext());
135136

136137
// Check that list is now empty.
137-
Assertions.assertEquals(0, list.size());
138-
Assertions.assertTrue(list.isEmpty());
138+
assertEquals(0, list.size());
139+
assertTrue(list.isEmpty());
139140
iter = list.iterator();
140-
Assertions.assertFalse(iter.hasNext());
141+
assertFalse(iter.hasNext());
141142
}
142143

143144
@Test
@@ -148,23 +149,23 @@ public void testGet() throws Exception {
148149
list.add(i);
149150
}
150151

151-
Assertions.assertEquals(Integer.valueOf(100), list.get(100));
152-
Assertions.assertEquals(Integer.valueOf(1000), list.get(1000));
153-
Assertions.assertEquals(Integer.valueOf(10000), list.get(10000));
154-
Assertions.assertEquals(Integer.valueOf(100000), list.get(100000));
152+
assertEquals(Integer.valueOf(100), list.get(100));
153+
assertEquals(Integer.valueOf(1000), list.get(1000));
154+
assertEquals(Integer.valueOf(10000), list.get(10000));
155+
assertEquals(Integer.valueOf(100000), list.get(100000));
155156

156157
Iterator<Integer> iter = list.iterator();
157158
iter.next();
158159
iter.remove();
159-
Assertions.assertEquals(Integer.valueOf(1), list.get(0));
160+
assertEquals(Integer.valueOf(1), list.get(0));
160161

161162
iter = list.iterator();
162163
for (int i = 0; i < 500; i++) {
163164
iter.next();
164165
}
165166
iter.remove();
166167

167-
Assertions.assertEquals(Integer.valueOf(502), list.get(500));
168-
Assertions.assertEquals(Integer.valueOf(602), list.get(600));
168+
assertEquals(Integer.valueOf(502), list.get(500));
169+
assertEquals(Integer.valueOf(602), list.get(600));
169170
}
170171
}

hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestClassUtil.java

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,23 +26,22 @@
2626
import org.junit.jupiter.api.Test;
2727
import org.junit.jupiter.api.Timeout;
2828

29+
import static org.assertj.core.api.Assertions.assertThat;
30+
2931
public class TestClassUtil {
3032

3133
@Test
3234
@Timeout(value = 10)
3335
public void testFindContainingJar() {
3436
String containingJar = ClassUtil.findContainingJar(Assertions.class);
35-
Assertions
36-
.assertThat(containingJar)
37+
assertThat(containingJar)
3738
.describedAs("Containing jar for %s", Assertions.class)
3839
.isNotNull();
3940
File jarFile = new File(containingJar);
40-
Assertions
41-
.assertThat(jarFile)
41+
assertThat(jarFile)
4242
.describedAs("Containing jar %s", jarFile)
4343
.exists();
44-
Assertions
45-
.assertThat(jarFile.getName())
44+
assertThat(jarFile.getName())
4645
.describedAs("Containing jar name %s", jarFile.getName())
4746
.matches("assertj-core.*[.]jar");
4847
}
@@ -51,17 +50,14 @@ public void testFindContainingJar() {
5150
@Timeout(value = 10)
5251
public void testFindContainingClass() {
5352
String classFileLocation = ClassUtil.findClassLocation(ViewFileSystem.class);
54-
Assertions
55-
.assertThat(classFileLocation)
53+
assertThat(classFileLocation)
5654
.describedAs("Class path for %s", ViewFileSystem.class)
5755
.isNotNull();
5856
File classFile = new File(classFileLocation);
59-
Assertions
60-
.assertThat(classFile)
57+
assertThat(classFile)
6158
.describedAs("Containing class file %s", classFile)
6259
.exists();
63-
Assertions
64-
.assertThat(classFile.getName())
60+
assertThat(classFile.getName())
6561
.describedAs("Containing class file name %s", classFile.getName())
6662
.matches("ViewFileSystem.class");
6763
}

hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestClasspath.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@
1717
*/
1818
package org.apache.hadoop.util;
1919

20-
import static org.junit.jupiter.api.Assertions.*;
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.assertTrue;
24+
import static org.junit.jupiter.api.Assertions.fail;
2125

2226
import java.io.ByteArrayOutputStream;
2327
import java.io.File;

hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestConfTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818

1919
package org.apache.hadoop.util;
2020

21-
import static org.junit.jupiter.api.Assertions.*;
21+
import static org.junit.jupiter.api.Assertions.assertEquals;
22+
import static org.junit.jupiter.api.Assertions.assertTrue;
2223

2324
import java.io.ByteArrayInputStream;
2425
import java.util.List;

hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestCpuTimeTracker.java

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,24 +29,18 @@ public void test() throws InterruptedException {
2929
BigInteger.valueOf(100),
3030
System.currentTimeMillis());
3131
float val1 = tracker.getCpuTrackerUsagePercent();
32-
assertTrue(
33-
34-
val1 == -1.0, "Not invalid CPU usage");
32+
assertTrue(val1 == -1.0, "Not invalid CPU usage");
3533
Thread.sleep(1000);
3634
tracker.updateElapsedJiffies(
3735
BigInteger.valueOf(200),
3836
System.currentTimeMillis());
3937
float val2 = tracker.getCpuTrackerUsagePercent();
40-
assertTrue(
41-
42-
val2 > 0, "Not positive CPU usage");
38+
assertTrue(val2 > 0, "Not positive CPU usage");
4339
Thread.sleep(1000);
4440
tracker.updateElapsedJiffies(
4541
BigInteger.valueOf(0),
4642
System.currentTimeMillis());
4743
float val3 = tracker.getCpuTrackerUsagePercent();
48-
assertTrue(
49-
50-
val3 == 0.0, "Not positive CPU usage");
44+
assertTrue(val3 == 0.0, "Not positive CPU usage");
5145
}
5246
}

hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestCrcComposer.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,21 @@
2222
import java.io.IOException;
2323
import java.util.Objects;
2424
import java.util.Random;
25-
import java.util.concurrent.TimeUnit;
2625

2726
import org.apache.hadoop.test.LambdaTestUtils;
2827
import org.junit.jupiter.api.BeforeEach;
29-
import org.junit.Rule;
3028
import org.junit.jupiter.api.Test;
31-
import org.junit.rules.Timeout;
29+
import org.junit.jupiter.api.Timeout;
3230

33-
import static org.junit.jupiter.api.Assertions.*;
31+
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
32+
import static org.junit.jupiter.api.Assertions.assertEquals;
33+
import static org.junit.jupiter.api.Assertions.assertNotEquals;
3434

3535
/**
3636
* Unittests for CrcComposer.
3737
*/
38+
@Timeout(10)
3839
public class TestCrcComposer {
39-
@Rule
40-
public Timeout globalTimeout = new Timeout(10000, TimeUnit.MILLISECONDS);
4140

4241
private final Random rand = new Random(1234);
4342

0 commit comments

Comments
 (0)