Skip to content

Commit 520af68

Browse files
zhtttylzslfan1989
andauthored
HDFS-12431. [JDK17] Upgrade JUnit from 4 to 5 in hadoop-hdfs Part17. (#7934)
* HDFS-12431. [JDK17] Upgrade JUnit from 4 to 5 in hadoop-hdfs Part17. Co-authored-by: Shilun Fan <[email protected]> Reviewed-by: Shilun Fan <[email protected]> Signed-off-by: Shilun Fan <[email protected]>
1 parent e739c76 commit 520af68

File tree

50 files changed

+1487
-1310
lines changed

Some content is hidden

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

50 files changed

+1487
-1310
lines changed

hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/balancer/TestBalancer.java

Lines changed: 99 additions & 66 deletions
Large diffs are not rendered by default.

hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/balancer/TestBalancerHttpServer.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@
2222
import java.net.URL;
2323
import java.net.URLConnection;
2424

25-
import org.junit.AfterClass;
26-
import org.junit.BeforeClass;
27-
import org.junit.Test;
25+
import org.junit.jupiter.api.AfterAll;
26+
import org.junit.jupiter.api.BeforeAll;
27+
import org.junit.jupiter.api.Test;
2828

2929
import org.apache.hadoop.conf.Configuration;
3030
import org.apache.hadoop.fs.FileUtil;
@@ -35,7 +35,7 @@
3535
import org.apache.hadoop.security.ssl.KeyStoreTestUtil;
3636
import org.apache.hadoop.test.GenericTestUtils;
3737

38-
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
38+
import static org.assertj.core.api.Assertions.assertThat;
3939

4040
public class TestBalancerHttpServer {
4141
private static final String BASEDIR =
@@ -45,7 +45,7 @@ public class TestBalancerHttpServer {
4545
private static Configuration conf;
4646
private static URLConnectionFactory connectionFactory;
4747

48-
@BeforeClass
48+
@BeforeAll
4949
public static void setUp() throws Exception {
5050
conf = new Configuration();
5151
conf.set(DFSConfigKeys.DFS_HTTP_POLICY_KEY, HttpConfig.Policy.HTTP_ONLY.name());
@@ -60,7 +60,7 @@ public static void setUp() throws Exception {
6060
connectionFactory = URLConnectionFactory.newDefaultURLConnectionFactory(conf);
6161
}
6262

63-
@AfterClass
63+
@AfterAll
6464
public static void tearDown() throws Exception {
6565
FileUtil.fullyDelete(new File(BASEDIR));
6666
KeyStoreTestUtil.cleanupSSLConfig(keystoresDir, sslConfDir);

hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/balancer/TestBalancerLongRunningTasks.java

Lines changed: 34 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,9 @@
5050
import org.apache.hadoop.metrics2.MetricsSystem;
5151
import org.apache.hadoop.metrics2.lib.DefaultMetricsSystem;
5252
import org.apache.hadoop.test.GenericTestUtils;
53-
import org.junit.After;
54-
import org.junit.Test;
53+
import org.junit.jupiter.api.AfterEach;
54+
import org.junit.jupiter.api.Test;
55+
import org.junit.jupiter.api.Timeout;
5556
import org.slf4j.Logger;
5657
import org.slf4j.LoggerFactory;
5758
import org.slf4j.event.Level;
@@ -77,8 +78,8 @@
7778
import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_NAMENODE_HEARTBEAT_RECHECK_INTERVAL_KEY;
7879
import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_NAMENODE_LAZY_PERSIST_FILE_SCRUB_INTERVAL_SEC;
7980
import static org.apache.hadoop.test.PlatformAssumptions.assumeNotWindows;
80-
import static org.junit.Assert.assertEquals;
81-
import static org.junit.Assert.assertTrue;
81+
import static org.junit.jupiter.api.Assertions.assertEquals;
82+
import static org.junit.jupiter.api.Assertions.assertTrue;
8283

8384
/**
8485
* Some long running Balancer tasks.
@@ -101,7 +102,7 @@ public class TestBalancerLongRunningTasks {
101102
private final static Path FILE_PATH = new Path(FILE_NAME);
102103
private MiniDFSCluster cluster;
103104

104-
@After
105+
@AfterEach
105106
public void shutdown() throws Exception {
106107
if (cluster != null) {
107108
cluster.shutdown();
@@ -159,7 +160,8 @@ static void initConfWithRamDisk(Configuration conf,
159160
* Replica in (DN0,SSD) should not be moved to (DN1,SSD).
160161
* Otherwise DN1 has 2 replicas.
161162
*/
162-
@Test(timeout = 100000)
163+
@Test
164+
@Timeout(value = 100)
163165
public void testTwoReplicaShouldNotInSameDN() throws Exception {
164166
final Configuration conf = new HdfsConfiguration();
165167

@@ -218,7 +220,8 @@ public void testTwoReplicaShouldNotInSameDN() throws Exception {
218220
* One DN has two files on RAM_DISK, other DN has no files on RAM_DISK.
219221
* Then verify that the balancer does not migrate files on RAM_DISK across DN.
220222
*/
221-
@Test(timeout = 300000)
223+
@Test
224+
@Timeout(value = 300)
222225
public void testBalancerWithRamDisk() throws Exception {
223226
final int seed = 0xFADED;
224227
final short replicationFactor = 1;
@@ -285,7 +288,8 @@ public void testBalancerWithRamDisk() throws Exception {
285288
/**
286289
* Balancer should not move blocks with size < minBlockSize.
287290
*/
288-
@Test(timeout = 60000)
291+
@Test
292+
@Timeout(value = 60)
289293
public void testMinBlockSizeAndSourceNodes() throws Exception {
290294
final Configuration conf = new HdfsConfiguration();
291295
initConf(conf);
@@ -405,7 +409,8 @@ public void testMinBlockSizeAndSourceNodes() throws Exception {
405409
*
406410
* @throws Exception
407411
*/
408-
@Test(timeout = 100000)
412+
@Test
413+
@Timeout(value = 100)
409414
public void testUpgradeDomainPolicyAfterBalance() throws Exception {
410415
final Configuration conf = new HdfsConfiguration();
411416
initConf(conf);
@@ -425,7 +430,8 @@ public void testUpgradeDomainPolicyAfterBalance() throws Exception {
425430
*
426431
* @throws Exception
427432
*/
428-
@Test(timeout = 100000)
433+
@Test
434+
@Timeout(value = 100)
429435
public void testRackPolicyAfterBalance() throws Exception {
430436
final Configuration conf = new HdfsConfiguration();
431437
initConf(conf);
@@ -505,7 +511,8 @@ private void runBalancerAndVerifyBlockPlacmentPolicy(Configuration conf,
505511
*
506512
* @throws Exception
507513
*/
508-
@Test(timeout = 100000)
514+
@Test
515+
@Timeout(value = 100)
509516
public void testBalancerWithPinnedBlocks() throws Exception {
510517
// This test assumes stick-bit based block pin mechanism available only
511518
// in Linux/Unix. It can be unblocked on Windows when HDFS-7759 is ready to
@@ -559,7 +566,8 @@ public void testBalancerWithPinnedBlocks() throws Exception {
559566
assertEquals(ExitStatus.NO_MOVE_PROGRESS.getExitCode(), r);
560567
}
561568

562-
@Test(timeout = 60000)
569+
@Test
570+
@Timeout(value = 60)
563571
public void testBalancerWithSortTopNodes() throws Exception {
564572
final Configuration conf = new HdfsConfiguration();
565573
initConf(conf);
@@ -666,16 +674,17 @@ public void testBalancerWithSortTopNodes() throws Exception {
666674
// Hence, overall total blocks moved by HDFS balancer would be either of these 2 options:
667675
// a) 2 blocks of total size (100B + 100B)
668676
// b) 3 blocks of total size (50B + 100B + 100B)
669-
assertTrue("BalancerResult is not as expected. " + balancerResult,
670-
(balancerResult.getBytesAlreadyMoved() == 200
677+
assertTrue((balancerResult.getBytesAlreadyMoved() == 200
671678
&& balancerResult.getBlocksMoved() == 2)
672679
|| (balancerResult.getBytesAlreadyMoved() == 250
673-
&& balancerResult.getBlocksMoved() == 3));
680+
&& balancerResult.getBlocksMoved() == 3),
681+
"BalancerResult is not as expected. " + balancerResult);
674682
// 100% and 95% used nodes will be balanced, so top used will be 900
675683
assertEquals(900, maxUsage);
676684
}
677685

678-
@Test(timeout = 60000)
686+
@Test
687+
@Timeout(value = 60)
679688
public void testBalancerWithLimitOverUtilizedNum() throws Exception {
680689
final Configuration conf = new HdfsConfiguration();
681690
// Init the config (block size to 100)
@@ -762,12 +771,14 @@ public void testBalancerWithLimitOverUtilizedNum() throws Exception {
762771
}
763772
// The maxUsage value is 950, only 100% of the nodes will be balanced
764773
assertEquals(950, maxUsage);
765-
assertTrue("BalancerResult is not as expected. " + balancerResult,
766-
(balancerResult.getBytesAlreadyMoved() == 100 && balancerResult.getBlocksMoved() == 1));
774+
assertTrue(
775+
(balancerResult.getBytesAlreadyMoved() == 100 && balancerResult.getBlocksMoved() == 1),
776+
"BalancerResult is not as expected. " + balancerResult);
767777
}
768778
}
769779

770-
@Test(timeout = 60000)
780+
@Test
781+
@Timeout(value = 60)
771782
public void testBalancerMetricsDuplicate() throws Exception {
772783
final Configuration conf = new HdfsConfiguration();
773784
// Init the config (block size to 100)
@@ -824,7 +835,8 @@ public void testBalancerMetricsDuplicate() throws Exception {
824835
}
825836
}
826837

827-
@Test(timeout = 100000)
838+
@Test
839+
@Timeout(value = 100)
828840
public void testMaxIterationTime() throws Exception {
829841
final Configuration conf = new HdfsConfiguration();
830842
initConf(conf);
@@ -881,8 +893,8 @@ public void testMaxIterationTime() throws Exception {
881893
// (highly unlikely) and then a block is moved unexpectedly,
882894
// IN_PROGRESS will be reported. This is highly unlikely unexpected
883895
// case. See HDFS-15989.
884-
assertEquals("We expect ExitStatus.NO_MOVE_PROGRESS to be reported.",
885-
ExitStatus.NO_MOVE_PROGRESS, r.getExitStatus());
896+
assertEquals(ExitStatus.NO_MOVE_PROGRESS, r.getExitStatus(),
897+
"We expect ExitStatus.NO_MOVE_PROGRESS to be reported.");
886898
assertEquals(0, r.getBlocksMoved());
887899
}
888900
} finally {

hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/balancer/TestBalancerRPCDelay.java

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,29 +18,27 @@
1818
package org.apache.hadoop.hdfs.server.balancer;
1919

2020
import org.apache.hadoop.hdfs.DFSConfigKeys;
21-
import org.junit.After;
22-
import org.junit.Before;
23-
import org.junit.Rule;
24-
import org.junit.Test;
25-
import org.junit.rules.Timeout;
21+
import org.junit.jupiter.api.AfterEach;
22+
import org.junit.jupiter.api.BeforeEach;
23+
import org.junit.jupiter.api.Test;
24+
import org.junit.jupiter.api.Timeout;
2625

2726
/**
2827
* The Balancer ensures that it disperses RPCs to the NameNode
2928
* in order to avoid NN's RPC queue saturation.
3029
*/
30+
@Timeout(100)
3131
public class TestBalancerRPCDelay {
32-
@Rule
33-
public Timeout globalTimeout = Timeout.seconds(100);
3432

3533
private TestBalancer testBalancer;
3634

37-
@Before
35+
@BeforeEach
3836
public void setup() {
3937
testBalancer = new TestBalancer();
4038
testBalancer.setup();
4139
}
4240

43-
@After
41+
@AfterEach
4442
public void teardown() throws Exception {
4543
if (testBalancer != null) {
4644
testBalancer.shutdown();

hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/balancer/TestBalancerService.java

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,18 @@
3535
import org.apache.hadoop.util.Tool;
3636
import org.apache.hadoop.util.VersionInfo;
3737

38-
import org.junit.Test;
38+
import org.junit.jupiter.api.Test;
39+
import org.junit.jupiter.api.Timeout;
3940

4041
import java.lang.management.ManagementFactory;
4142
import java.util.concurrent.TimeUnit;
4243

4344
import javax.management.MBeanServer;
4445
import javax.management.ObjectName;
4546

46-
import static org.junit.Assert.assertEquals;
47-
import static org.junit.Assert.assertTrue;
48-
import static org.junit.Assert.fail;
47+
import static org.junit.jupiter.api.Assertions.assertEquals;
48+
import static org.junit.jupiter.api.Assertions.assertTrue;
49+
import static org.junit.jupiter.api.Assertions.fail;
4950

5051
/**
5152
* Test balancer run as a service.
@@ -124,7 +125,8 @@ public void run() {
124125
* should balance succeed but not exit, then make the cluster imbalanced and
125126
* wait for balancer to balance it again
126127
*/
127-
@Test(timeout = 60000)
128+
@Test
129+
@Timeout(value = 60)
128130
public void testBalancerServiceBalanceTwice() throws Exception {
129131
Configuration conf = new HdfsConfiguration();
130132
conf.setTimeDuration(DFSConfigKeys.DFS_BALANCER_SERVICE_INTERVAL_KEY, 5,
@@ -174,7 +176,8 @@ public void testBalancerServiceBalanceTwice() throws Exception {
174176
}
175177
}
176178

177-
@Test(timeout = 120000)
179+
@Test
180+
@Timeout(value = 120)
178181
public void testBalancerServiceOnError() throws Exception {
179182
Configuration conf = new HdfsConfiguration();
180183
// retry for every 5 seconds
@@ -217,7 +220,8 @@ public void testBalancerServiceOnError() throws Exception {
217220
}
218221
}
219222

220-
@Test(timeout = 60000)
223+
@Test
224+
@Timeout(value = 60)
221225
public void testBalancerServiceMetrics() throws Exception {
222226
Configuration conf = new HdfsConfiguration();
223227
conf.setTimeDuration(DFSConfigKeys.DFS_BALANCER_SERVICE_INTERVAL_KEY, 5, TimeUnit.SECONDS);

hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/balancer/TestBalancerWithEncryptedTransfer.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,30 +20,34 @@
2020
import org.apache.hadoop.conf.Configuration;
2121
import org.apache.hadoop.hdfs.DFSConfigKeys;
2222
import org.apache.hadoop.hdfs.HdfsConfiguration;
23-
import org.junit.Before;
24-
import org.junit.Test;
23+
import org.junit.jupiter.api.BeforeEach;
24+
import org.junit.jupiter.api.Test;
25+
import org.junit.jupiter.api.Timeout;
2526

2627
public class TestBalancerWithEncryptedTransfer {
2728

2829
private final Configuration conf = new HdfsConfiguration();
2930

30-
@Before
31+
@BeforeEach
3132
public void setUpConf() {
3233
conf.setBoolean(DFSConfigKeys.DFS_ENCRYPT_DATA_TRANSFER_KEY, true);
3334
conf.setBoolean(DFSConfigKeys.DFS_BLOCK_ACCESS_TOKEN_ENABLE_KEY, true);
3435
}
3536

36-
@Test(timeout=60000)
37+
@Test
38+
@Timeout(value = 60)
3739
public void testEncryptedBalancer0() throws Exception {
3840
new TestBalancer().testBalancer0Internal(conf);
3941
}
4042

41-
@Test(timeout=60000)
43+
@Test
44+
@Timeout(value = 60)
4245
public void testEncryptedBalancer1() throws Exception {
4346
new TestBalancer().testBalancer1Internal(conf);
4447
}
4548

46-
@Test(timeout=60000)
49+
@Test
50+
@Timeout(value = 60)
4751
public void testEncryptedBalancer2() throws Exception {
4852
new TestBalancer().testBalancer2Internal(conf);
4953
}

0 commit comments

Comments
 (0)