Skip to content

Commit cdf03b8

Browse files
committed
HDFS-17718. [JDK17] Upgrade JUnit from 4 to 5 in hadoop-hdfs-client.
1 parent 6ff352f commit cdf03b8

28 files changed

+359
-345
lines changed

hadoop-hdfs-project/hadoop-hdfs-client/pom.xml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,31 @@ https://maven.apache.org/xsd/maven-4.0.0.xsd">
128128
<groupId>com.fasterxml.jackson.core</groupId>
129129
<artifactId>jackson-databind</artifactId>
130130
</dependency>
131+
<dependency>
132+
<groupId>org.junit.jupiter</groupId>
133+
<artifactId>junit-jupiter-api</artifactId>
134+
<scope>test</scope>
135+
</dependency>
136+
<dependency>
137+
<groupId>org.junit.jupiter</groupId>
138+
<artifactId>junit-jupiter-engine</artifactId>
139+
<scope>test</scope>
140+
</dependency>
141+
<dependency>
142+
<groupId>org.junit.jupiter</groupId>
143+
<artifactId>junit-jupiter-params</artifactId>
144+
<scope>test</scope>
145+
</dependency>
146+
<dependency>
147+
<groupId>org.junit.platform</groupId>
148+
<artifactId>junit-platform-launcher</artifactId>
149+
<scope>test</scope>
150+
</dependency>
151+
<dependency>
152+
<groupId>org.junit.vintage</groupId>
153+
<artifactId>junit-vintage-engine</artifactId>
154+
<scope>test</scope>
155+
</dependency>
131156
</dependencies>
132157

133158
<build>

hadoop-hdfs-project/hadoop-hdfs-client/src/test/java/org/apache/hadoop/fs/TestUrlStreamHandlerFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
import org.apache.hadoop.test.GenericTestUtils;
2222
import org.junit.Rule;
23-
import org.junit.Test;
23+
import org.junit.jupiter.api.Test;
2424
import org.junit.rules.Timeout;
2525

2626
import java.io.File;

hadoop-hdfs-project/hadoop-hdfs-client/src/test/java/org/apache/hadoop/fs/TestXAttr.java

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

1919
package org.apache.hadoop.fs;
2020

21-
import static org.junit.Assert.assertEquals;
22-
import static org.junit.Assert.assertNotSame;
23-
import static org.junit.Assert.assertNotEquals;
21+
import static org.junit.jupiter.api.Assertions.assertEquals;
22+
import static org.junit.jupiter.api.Assertions.assertNotSame;
23+
import static org.junit.jupiter.api.Assertions.assertNotEquals;
2424

25-
import org.junit.BeforeClass;
26-
import org.junit.Test;
25+
import org.junit.jupiter.api.BeforeAll;
26+
import org.junit.jupiter.api.Test;
2727

2828
/**
2929
* Tests for <code>XAttr</code> objects.
3030
*/
3131
public class TestXAttr {
3232
private static XAttr XATTR, XATTR1, XATTR2, XATTR3, XATTR4, XATTR5;
3333

34-
@BeforeClass
34+
@BeforeAll
3535
public static void setUp() throws Exception {
3636
byte[] value = {0x31, 0x32, 0x33};
3737
XATTR = new XAttr.Builder()

hadoop-hdfs-project/hadoop-hdfs-client/src/test/java/org/apache/hadoop/hdfs/TestDFSOpsCountStatistics.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@
2323

2424
import org.apache.hadoop.hdfs.DFSOpsCountStatistics.OpType;
2525

26-
import org.junit.Before;
26+
import org.junit.jupiter.api.BeforeEach;
2727
import org.junit.Rule;
28-
import org.junit.Test;
28+
import org.junit.jupiter.api.Test;
2929

3030
import org.junit.rules.ExpectedException;
3131
import org.junit.rules.Timeout;
@@ -44,11 +44,11 @@
4444
import java.util.concurrent.atomic.AtomicReference;
4545

4646
import static org.apache.hadoop.util.concurrent.HadoopExecutors.newFixedThreadPool;
47-
import static org.junit.Assert.assertEquals;
48-
import static org.junit.Assert.assertFalse;
49-
import static org.junit.Assert.assertNotNull;
50-
import static org.junit.Assert.assertNull;
51-
import static org.junit.Assert.assertTrue;
47+
import static org.junit.jupiter.api.Assertions.assertEquals;
48+
import static org.junit.jupiter.api.Assertions.assertFalse;
49+
import static org.junit.jupiter.api.Assertions.assertNotNull;
50+
import static org.junit.jupiter.api.Assertions.assertNull;
51+
import static org.junit.jupiter.api.Assertions.assertTrue;
5252

5353
/**
5454
* This tests basic operations of {@link DFSOpsCountStatistics} class.
@@ -68,7 +68,7 @@ public class TestDFSOpsCountStatistics {
6868
@Rule
6969
public final ExpectedException exception = ExpectedException.none();
7070

71-
@Before
71+
@BeforeEach
7272
public void setup() {
7373
for (OpType opType : OpType.values()) {
7474
expectedOpsCountMap.put(opType, new AtomicLong());
@@ -178,7 +178,7 @@ public void run() {
178178
startBlocker.countDown(); // all threads start making directories
179179
allDone.await(); // wait until all threads are done
180180

181-
assertNull("Child failed with exception.", childError.get());
181+
assertNull(childError.get(), "Child failed with exception.");
182182
verifyStatistics();
183183
} finally {
184184
threadPool.shutdownNow();
@@ -207,9 +207,9 @@ private void verifyStatistics() {
207207
for (OpType opType : OpType.values()) {
208208
assertNotNull(expectedOpsCountMap.get(opType));
209209
assertNotNull(statistics.getLong(opType.getSymbol()));
210-
assertEquals("Not expected count for operation " + opType.getSymbol(),
211-
expectedOpsCountMap.get(opType).longValue(),
212-
statistics.getLong(opType.getSymbol()).longValue());
210+
assertEquals(expectedOpsCountMap.get(opType).longValue(),
211+
statistics.getLong(opType.getSymbol()).longValue(),
212+
"Not expected count for operation " + opType.getSymbol());
213213
}
214214
}
215215

hadoop-hdfs-project/hadoop-hdfs-client/src/test/java/org/apache/hadoop/hdfs/TestDFSPacket.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
import java.util.Random;
2121
import org.apache.hadoop.hdfs.protocol.datatransfer.PacketHeader;
2222
import org.apache.hadoop.io.DataOutputBuffer;
23-
import org.junit.Assert;
24-
import org.junit.Test;
23+
import org.junit.jupiter.api.Assertions;
24+
import org.junit.jupiter.api.Test;
2525

2626
public class TestDFSPacket {
2727
private static final int chunkSize = 512;
@@ -59,7 +59,7 @@ public static void assertArrayRegionsEqual(byte []buf1, int off1, byte []buf2,
5959
int off2, int len) {
6060
for (int i = 0; i < len; i++) {
6161
if (buf1[off1 + i] != buf2[off2 + i]) {
62-
Assert.fail("arrays differ at byte " + i + ". " +
62+
Assertions.fail("arrays differ at byte " + i + ". " +
6363
"The first array has " + (int) buf1[off1 + i] +
6464
", but the second array has " + (int) buf2[off2 + i]);
6565
}

hadoop-hdfs-project/hadoop-hdfs-client/src/test/java/org/apache/hadoop/hdfs/TestDefaultNameNodePort.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@
2020
import org.apache.hadoop.conf.Configuration;
2121
import org.apache.hadoop.fs.FileSystem;
2222
import org.apache.hadoop.hdfs.client.HdfsClientConfigKeys;
23-
import org.junit.Test;
23+
import org.junit.jupiter.api.Test;
2424

2525
import java.net.InetSocketAddress;
2626
import java.net.URI;
2727

28-
import static org.junit.Assert.assertEquals;
28+
import static org.junit.jupiter.api.Assertions.assertEquals;
2929

3030
/** Test NameNode port defaulting code. */
3131
public class TestDefaultNameNodePort {

hadoop-hdfs-project/hadoop-hdfs-client/src/test/java/org/apache/hadoop/hdfs/TestPeerCache.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import org.apache.hadoop.hdfs.net.Peer;
2222
import org.apache.hadoop.hdfs.protocol.DatanodeID;
2323
import org.apache.hadoop.net.unix.DomainSocket;
24-
import org.junit.Test;
24+
import org.junit.jupiter.api.Test;
2525
import org.mockito.Mockito;
2626
import org.mockito.invocation.InvocationOnMock;
2727
import org.mockito.stubbing.Answer;
@@ -33,9 +33,9 @@
3333
import java.io.OutputStream;
3434
import java.nio.channels.ReadableByteChannel;
3535

36-
import static org.junit.Assert.assertEquals;
37-
import static org.junit.Assert.assertSame;
38-
import static org.junit.Assert.assertTrue;
36+
import static org.junit.jupiter.api.Assertions.assertEquals;
37+
import static org.junit.jupiter.api.Assertions.assertSame;
38+
import static org.junit.jupiter.api.Assertions.assertTrue;
3939

4040
public class TestPeerCache {
4141
static final Logger LOG = LoggerFactory.getLogger(TestPeerCache.class);

hadoop-hdfs-project/hadoop-hdfs-client/src/test/java/org/apache/hadoop/hdfs/client/impl/TestLeaseRenewer.java

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@
2323
import org.apache.hadoop.security.UserGroupInformation;
2424
import org.apache.hadoop.test.GenericTestUtils;
2525
import org.apache.hadoop.util.Time;
26-
import org.junit.Assert;
27-
import org.junit.Before;
28-
import org.junit.Test;
26+
import org.junit.jupiter.api.Assertions;
27+
import org.junit.jupiter.api.BeforeEach;
28+
import org.junit.jupiter.api.Test;
2929
import org.mockito.Mockito;
3030
import org.mockito.invocation.InvocationOnMock;
3131
import org.mockito.stubbing.Answer;
@@ -37,7 +37,12 @@
3737
import java.util.concurrent.atomic.AtomicInteger;
3838
import java.util.regex.Pattern;
3939

40-
import static org.junit.Assert.assertSame;
40+
import static org.junit.jupiter.api.Assertions.assertEquals;
41+
import static org.junit.jupiter.api.Assertions.assertFalse;
42+
import static org.junit.jupiter.api.Assertions.assertNotSame;
43+
import static org.junit.jupiter.api.Assertions.assertSame;
44+
import static org.junit.jupiter.api.Assertions.assertTrue;
45+
import static org.junit.jupiter.api.Assertions.fail;
4146

4247
public class TestLeaseRenewer {
4348
private final String FAKE_AUTHORITY="hdfs://nn1/";
@@ -54,7 +59,7 @@ public class TestLeaseRenewer {
5459
/** Cause renewals often so test runs quickly. */
5560
private static final long FAST_GRACE_PERIOD = 100L;
5661

57-
@Before
62+
@BeforeEach
5863
public void setupMocksAndRenewer() throws IOException {
5964
MOCK_DFSCLIENT = createMockClient();
6065

@@ -82,19 +87,19 @@ public void testInstanceSharing() throws IOException {
8287
FAKE_AUTHORITY, FAKE_UGI_A, MOCK_DFSCLIENT);
8388
LeaseRenewer lr2 = LeaseRenewer.getInstance(
8489
FAKE_AUTHORITY, FAKE_UGI_A, MOCK_DFSCLIENT);
85-
Assert.assertSame(lr, lr2);
90+
assertSame(lr, lr2);
8691

8792
// But a different UGI should return a different instance
8893
LeaseRenewer lr3 = LeaseRenewer.getInstance(
8994
FAKE_AUTHORITY, FAKE_UGI_B, MOCK_DFSCLIENT);
90-
Assert.assertNotSame(lr, lr3);
95+
assertNotSame(lr, lr3);
9196

9297
// A different authority with same UGI should also be a different
9398
// instance.
9499
LeaseRenewer lr4 = LeaseRenewer.getInstance(
95100
"someOtherAuthority", FAKE_UGI_B, MOCK_DFSCLIENT);
96-
Assert.assertNotSame(lr, lr4);
97-
Assert.assertNotSame(lr3, lr4);
101+
assertNotSame(lr, lr4);
102+
assertNotSame(lr3, lr4);
98103
}
99104

100105
@Test
@@ -122,7 +127,7 @@ public Boolean answer(InvocationOnMock invocation) throws Throwable {
122127
Thread.sleep(50);
123128
}
124129
if (leaseRenewalCount.get() == 0) {
125-
Assert.fail("Did not renew lease at all!");
130+
fail("Did not renew lease at all!");
126131
}
127132

128133
renewer.closeClient(MOCK_DFSCLIENT);
@@ -176,23 +181,21 @@ public Boolean get() {
176181

177182
// Make sure renewer is not running due to expiration.
178183
Thread.sleep(FAST_GRACE_PERIOD * 2);
179-
Assert.assertTrue(!renewer.isRunning());
184+
assertTrue(!renewer.isRunning());
180185
}
181186

182187
@Test
183188
public void testThreadName() throws Exception {
184-
Assert.assertFalse("Renewer not initially running",
185-
renewer.isRunning());
189+
assertFalse(renewer.isRunning(), "Renewer not initially running");
186190

187191
// Pretend to open a file
188192
renewer.put(MOCK_DFSCLIENT);
189193

190-
Assert.assertTrue("Renewer should have started running",
191-
renewer.isRunning());
194+
assertTrue(renewer.isRunning(), "Renewer should have started running");
192195

193196
// Check the thread name is reasonable
194197
String threadName = renewer.getDaemonName();
195-
Assert.assertEquals("LeaseRenewer:myuser@hdfs://nn1/", threadName);
198+
assertEquals("LeaseRenewer:myuser@hdfs://nn1/", threadName);
196199

197200
// Pretend to close the file
198201
renewer.closeClient(MOCK_DFSCLIENT);
@@ -203,7 +206,7 @@ public void testThreadName() throws Exception {
203206
while (renewer.isRunning() && Time.monotonicNow() < failTime) {
204207
Thread.sleep(50);
205208
}
206-
Assert.assertFalse(renewer.isRunning());
209+
assertFalse(renewer.isRunning());
207210
}
208211

209212
/**
@@ -213,24 +216,23 @@ public void testThreadName() throws Exception {
213216
*/
214217
@Test
215218
public void testDaemonThreadLeak() throws Exception {
216-
Assert.assertFalse("Renewer not initially running", renewer.isRunning());
219+
assertFalse(renewer.isRunning(), "Renewer not initially running");
217220

218221
// Pretend to create a file#1, daemon#1 starts
219222
renewer.put(MOCK_DFSCLIENT);
220-
Assert.assertTrue("Renewer should have started running",
221-
renewer.isRunning());
223+
assertTrue(renewer.isRunning(), "Renewer should have started running");
222224
Pattern daemonThreadNamePattern = Pattern.compile("LeaseRenewer:\\S+");
223-
Assert.assertEquals(1, countThreadMatching(daemonThreadNamePattern));
225+
assertEquals(1, countThreadMatching(daemonThreadNamePattern));
224226

225227
// Pretend to create file#2, daemon#2 starts due to expiration
226228
LeaseRenewer lastRenewer = renewer;
227229
renewer =
228230
LeaseRenewer.getInstance(FAKE_AUTHORITY, FAKE_UGI_A, MOCK_DFSCLIENT);
229-
Assert.assertEquals(lastRenewer, renewer);
231+
assertEquals(lastRenewer, renewer);
230232

231233
// Pretend to close file#1
232234
renewer.closeClient(MOCK_DFSCLIENT);
233-
Assert.assertEquals(1, countThreadMatching(daemonThreadNamePattern));
235+
assertEquals(1, countThreadMatching(daemonThreadNamePattern));
234236

235237
// Pretend to be expired
236238
renewer.setEmptyTime(0);
@@ -249,7 +251,7 @@ public void testDaemonThreadLeak() throws Exception {
249251

250252
int threadCount = countThreadMatching(daemonThreadNamePattern);
251253
//Sometimes old LR#Daemon gets closed and lead to count 1 (rare scenario)
252-
Assert.assertTrue(1 == threadCount || 2 == threadCount);
254+
assertTrue(1 == threadCount || 2 == threadCount);
253255

254256
// After grace period, both daemon#1 and renewer#1 will be removed due to
255257
// expiration, then daemon#2 will leak before HDFS-14575.
@@ -259,14 +261,14 @@ public void testDaemonThreadLeak() throws Exception {
259261
lastRenewer = renewer;
260262
renewer =
261263
LeaseRenewer.getInstance(FAKE_AUTHORITY, FAKE_UGI_A, MOCK_DFSCLIENT);
262-
Assert.assertEquals(lastRenewer, renewer);
264+
assertEquals(lastRenewer, renewer);
263265
renewer.setGraceSleepPeriod(FAST_GRACE_PERIOD);
264266
renewer.closeClient(MOCK_DFSCLIENT);
265267
renewer.setEmptyTime(0);
266268
// Make sure LeaseRenewer#daemon threads will terminate after grace period
267269
Thread.sleep(FAST_GRACE_PERIOD * 2);
268-
Assert.assertEquals("LeaseRenewer#daemon thread leaks", 0,
269-
countThreadMatching(daemonThreadNamePattern));
270+
assertEquals(0, countThreadMatching(daemonThreadNamePattern),
271+
"LeaseRenewer#daemon thread leaks");
270272
}
271273

272274
private static int countThreadMatching(Pattern pattern) {

hadoop-hdfs-project/hadoop-hdfs-client/src/test/java/org/apache/hadoop/hdfs/protocol/TestBlockType.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@
1717
*/
1818
package org.apache.hadoop.hdfs.protocol;
1919

20-
import org.junit.Test;
20+
import org.junit.jupiter.api.Test;
2121

2222
import static org.apache.hadoop.hdfs.protocol.BlockType.CONTIGUOUS;
2323
import static org.apache.hadoop.hdfs.protocol.BlockType.STRIPED;
24-
import static org.junit.Assert.*;
24+
import static org.junit.jupiter.api.Assertions.*;
2525

2626
/**
2727
* Test the BlockType class.

hadoop-hdfs-project/hadoop-hdfs-client/src/test/java/org/apache/hadoop/hdfs/protocol/TestErasureCodingPolicy.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@
1919

2020
import org.apache.hadoop.io.erasurecode.ECSchema;
2121
import org.apache.hadoop.test.GenericTestUtils;
22-
import org.junit.Test;
22+
import org.junit.jupiter.api.Test;
2323

24-
import static org.junit.Assert.assertEquals;
25-
import static org.junit.Assert.assertNotEquals;
26-
import static org.junit.Assert.fail;
24+
import static org.junit.jupiter.api.Assertions.assertEquals;
25+
import static org.junit.jupiter.api.Assertions.assertNotEquals;
26+
import static org.junit.jupiter.api.Assertions.fail;
2727

2828
/**
2929
* Test ErasureCodingPolicy.

0 commit comments

Comments
 (0)