Skip to content

Commit 9c1ddec

Browse files
zhtttylzslfan1989
andauthored
HDFS-12431. [JDK17] Upgrade JUnit from 4 to 5 in hadoop-hdfs Part14. (#7895)
* HDFS-12431. [JDK17] Upgrade JUnit from 4 to 5 in hadoop-hdfs Part14. Co-authored-by: Shilun Fan <[email protected]> Reviewed-by: Shilun Fan <[email protected]> Signed-off-by: Shilun Fan <[email protected]>
1 parent 960a2ef commit 9c1ddec

File tree

50 files changed

+1241
-1072
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

+1241
-1072
lines changed

hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestAddOverReplicatedStripedBlocks.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ public void testProcessOverReplicatedAndCorruptStripedBlock()
201201
// let a internal block be corrupt
202202
BlockManager bm = cluster.getNamesystem().getBlockManager();
203203
List<DatanodeInfo> infos = Arrays.asList(bg.getLocations());
204+
cluster.stopDataNode(infos.get(0).getXferAddr());
204205
List<String> storages = Arrays.asList(bg.getStorageIDs());
205206
cluster.getNamesystem().writeLock(RwLockMode.BM);
206207
try {

hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestSecureNameNodeWithExternalKdc.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@
3535
import org.apache.hadoop.security.UserGroupInformation;
3636
import org.apache.hadoop.security.UserGroupInformation.AuthenticationMethod;
3737
import static org.apache.hadoop.security.SecurityUtilTestHelper.isExternalKdcRunning;
38-
import org.junit.Assume;
38+
import static org.junit.jupiter.api.Assumptions.assumeTrue;
39+
3940
import org.junit.jupiter.api.BeforeEach;
4041
import org.junit.jupiter.api.Test;
4142

@@ -59,7 +60,7 @@ public class TestSecureNameNodeWithExternalKdc {
5960
@BeforeEach
6061
public void testExternalKdcRunning() {
6162
// Tests are skipped if external KDC is not running.
62-
Assume.assumeTrue(isExternalKdcRunning());
63+
assumeTrue(isExternalKdcRunning());
6364
}
6465

6566
@Test

hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/fgl/TestFSNLockBenchmarkThroughput.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@
2525
import org.apache.hadoop.hdfs.MiniDFSCluster;
2626
import org.apache.hadoop.hdfs.qjournal.MiniQJMHACluster;
2727
import org.apache.hadoop.util.ToolRunner;
28-
import org.junit.Assert;
29-
import org.junit.Test;
28+
import org.junit.jupiter.api.Test;
29+
30+
import static org.junit.jupiter.api.Assertions.assertEquals;
3031

3132
/**
3233
* To test {@link FSNLockBenchmarkThroughput}.
@@ -93,8 +94,8 @@ private void testBenchmarkThroughput(boolean enableFGL, int readWriteRatio,
9394
String.valueOf(readWriteRatio), String.valueOf(testingCount),
9495
String.valueOf(numClients)};
9596

96-
Assert.assertEquals(0, ToolRunner.run(conf,
97-
new FSNLockBenchmarkThroughput(fileSystem), args));
97+
assertEquals(0,
98+
ToolRunner.run(conf, new FSNLockBenchmarkThroughput(fileSystem), args));
9899
} finally {
99100
if (qjmhaCluster != null) {
100101
qjmhaCluster.shutdown();

hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/fgl/TestFineGrainedFSNamesystemLock.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
import org.apache.hadoop.hdfs.util.RwLockMode;
2121
import org.apache.hadoop.conf.Configuration;
2222
import org.apache.hadoop.util.concurrent.HadoopExecutors;
23-
import org.junit.Test;
23+
import org.junit.jupiter.api.Test;
24+
import org.junit.jupiter.api.Timeout;
2425
import org.slf4j.Logger;
2526
import org.slf4j.LoggerFactory;
2627

@@ -44,7 +45,8 @@ private int getLoopNumber() {
4445
/**
4546
* Test read/write lock of Global, FS and BM model through multi-threading.
4647
*/
47-
@Test(timeout=120000)
48+
@Test
49+
@Timeout(value = 120)
4850
public void testMultipleThreadsUsingLocks()
4951
throws InterruptedException, ExecutionException {
5052
FineGrainedFSNamesystemLock fsn = new FineGrainedFSNamesystemLock(new Configuration(), null);

hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/ha/TestHAConfiguration.java

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

2020
import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_NAMENODE_EDITS_DIR_KEY;
2121
import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_NAMENODE_SHARED_EDITS_DIR_KEY;
22-
import static org.junit.Assert.assertEquals;
23-
import static org.junit.Assert.assertNull;
24-
import static org.junit.Assert.assertTrue;
25-
import static org.junit.Assert.fail;
22+
import static org.junit.jupiter.api.Assertions.assertEquals;
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;
2626

2727
import java.io.IOException;
2828
import java.net.MalformedURLException;
@@ -40,7 +40,7 @@
4040
import org.apache.hadoop.hdfs.server.namenode.NameNode;
4141
import org.apache.hadoop.hdfs.server.namenode.SecondaryNameNode;
4242
import org.apache.hadoop.test.GenericTestUtils;
43-
import org.junit.Test;
43+
import org.junit.jupiter.api.Test;
4444
import org.mockito.Mockito;
4545

4646
/**
@@ -107,8 +107,8 @@ public void testGetOtherNNHttpAddress() throws IOException {
107107
NameNode.initializeGenericKeys(conf, "ns1", "nn1");
108108

109109
checkpointer = new StandbyCheckpointer(conf, fsn);
110-
assertEquals("Got an unexpected number of possible active NNs", 2, checkpointer
111-
.getActiveNNAddresses().size());
110+
assertEquals(2, checkpointer.getActiveNNAddresses().size(),
111+
"Got an unexpected number of possible active NNs");
112112
assertEquals(new URL("http", "1.2.3.2", DFSConfigKeys.DFS_NAMENODE_HTTP_PORT_DEFAULT, ""),
113113
checkpointer.getActiveNNAddresses().get(0));
114114
assertAddressMatches("1.2.3.2", checkpointer.getActiveNNAddresses().get(0));

hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/metrics/TestNNMetricFilesInGetListingOps.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@
3131
import org.apache.hadoop.hdfs.HdfsConfiguration;
3232
import org.apache.hadoop.hdfs.MiniDFSCluster;
3333
import org.apache.hadoop.hdfs.protocol.HdfsFileStatus;
34-
import org.junit.After;
35-
import org.junit.Before;
36-
import org.junit.Test;
34+
import org.junit.jupiter.api.AfterEach;
35+
import org.junit.jupiter.api.BeforeEach;
36+
import org.junit.jupiter.api.Test;
3737

3838
/**
3939
* Test case for FilesInGetListingOps metric in Namenode
@@ -52,15 +52,15 @@ public class TestNNMetricFilesInGetListingOps {
5252
private DistributedFileSystem fs;
5353
private final Random rand = new Random();
5454

55-
@Before
55+
@BeforeEach
5656
public void setUp() throws Exception {
5757
cluster = new MiniDFSCluster.Builder(CONF).build();
5858
cluster.waitActive();
5959
cluster.getNameNode();
6060
fs = cluster.getFileSystem();
6161
}
6262

63-
@After
63+
@AfterEach
6464
public void tearDown() throws Exception {
6565
if (cluster != null) {
6666
cluster.shutdown();

hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/metrics/TestNameNodeMetrics.java

Lines changed: 48 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@
3737
import static org.apache.hadoop.test.MetricsAsserts.assertGauge;
3838
import static org.apache.hadoop.test.MetricsAsserts.assertQuantileGauges;
3939
import static org.apache.hadoop.test.MetricsAsserts.getMetrics;
40-
import static org.junit.Assert.assertEquals;
41-
import static org.junit.Assert.assertTrue;
40+
import static org.junit.jupiter.api.Assertions.assertEquals;
41+
import static org.junit.jupiter.api.Assertions.assertTrue;
4242

4343
import java.io.DataInputStream;
4444
import java.io.File;
@@ -94,9 +94,10 @@
9494
import org.apache.hadoop.test.GenericTestUtils;
9595
import org.apache.hadoop.test.MetricsAsserts;
9696
import org.slf4j.event.Level;
97-
import org.junit.After;
98-
import org.junit.Before;
99-
import org.junit.Test;
97+
import org.junit.jupiter.api.AfterEach;
98+
import org.junit.jupiter.api.BeforeEach;
99+
import org.junit.jupiter.api.Test;
100+
import org.junit.jupiter.api.Timeout;
100101

101102
/**
102103
* Test for metrics published by the Namenode
@@ -162,7 +163,7 @@ private static Path getTestPath(String fileName) {
162163
return new Path(TEST_ROOT_DIR_PATH, fileName);
163164
}
164165

165-
@Before
166+
@BeforeEach
166167
public void setUp() throws Exception {
167168
hostsFileWriter = new HostsFileWriter();
168169
hostsFileWriter.initialize(CONF, "temp/decommission");
@@ -178,7 +179,7 @@ public void setUp() throws Exception {
178179
fs.setErasureCodingPolicy(ecDir, EC_POLICY.getName());
179180
}
180181

181-
@After
182+
@AfterEach
182183
public void tearDown() throws Exception {
183184
MetricsSource source = DefaultMetricsSystem.instance().getSource("UgiMetrics");
184185
if (source != null) {
@@ -213,7 +214,8 @@ private void readFile(FileSystem fileSys,Path name) throws IOException {
213214
* Test that capacity metrics are exported and pass
214215
* basic sanity tests.
215216
*/
216-
@Test (timeout = 10000)
217+
@Test
218+
@Timeout(value = 10)
217219
public void testCapacityMetrics() throws Exception {
218220
MetricsRecordBuilder rb = getMetrics(NS_METRICS);
219221
long capacityTotal = MetricsAsserts.getLongGauge("CapacityTotal", rb);
@@ -443,35 +445,34 @@ private void verifyZeroMetrics() throws Exception {
443445
*/
444446
private void verifyAggregatedMetricsTally() throws Exception {
445447
BlockManagerTestUtil.updateState(bm);
446-
assertEquals("Under replicated metrics not matching!",
447-
namesystem.getLowRedundancyBlocks(),
448-
namesystem.getUnderReplicatedBlocks());
449-
assertEquals("Low redundancy metrics not matching!",
450-
namesystem.getLowRedundancyBlocks(),
448+
assertEquals(namesystem.getLowRedundancyBlocks(),
449+
namesystem.getUnderReplicatedBlocks(),
450+
"Under replicated metrics not matching!");
451+
assertEquals(namesystem.getLowRedundancyBlocks(),
451452
namesystem.getLowRedundancyReplicatedBlocks() +
452-
namesystem.getLowRedundancyECBlockGroups());
453-
assertEquals("Corrupt blocks metrics not matching!",
454-
namesystem.getCorruptReplicaBlocks(),
453+
namesystem.getLowRedundancyECBlockGroups(),
454+
"Low redundancy metrics not matching!");
455+
assertEquals(namesystem.getCorruptReplicaBlocks(),
455456
namesystem.getCorruptReplicatedBlocks() +
456-
namesystem.getCorruptECBlockGroups());
457-
assertEquals("Missing blocks metrics not matching!",
458-
namesystem.getMissingBlocksCount(),
457+
namesystem.getCorruptECBlockGroups(),
458+
"Corrupt blocks metrics not matching!");
459+
assertEquals(namesystem.getMissingBlocksCount(),
459460
namesystem.getMissingReplicatedBlocks() +
460-
namesystem.getMissingECBlockGroups());
461-
assertEquals("Missing blocks with replication factor one not matching!",
462-
namesystem.getMissingReplOneBlocksCount(),
463-
namesystem.getMissingReplicationOneBlocks());
464-
assertEquals("Blocks with badly distributed are not matching!",
465-
namesystem.getBadlyDistributedBlocksCount(),
466-
namesystem.getBadlyDistributedBlocks());
467-
assertEquals("Bytes in future blocks metrics not matching!",
468-
namesystem.getBytesInFuture(),
461+
namesystem.getMissingECBlockGroups(),
462+
"Missing blocks metrics not matching!");
463+
assertEquals(namesystem.getMissingReplOneBlocksCount(),
464+
namesystem.getMissingReplicationOneBlocks(),
465+
"Missing blocks with replication factor one not matching!");
466+
assertEquals(namesystem.getBadlyDistributedBlocksCount(),
467+
namesystem.getBadlyDistributedBlocks(), "Blocks with badly distributed are not matching!");
468+
assertEquals(namesystem.getBytesInFuture(),
469469
namesystem.getBytesInFutureReplicatedBlocks() +
470-
namesystem.getBytesInFutureECBlockGroups());
471-
assertEquals("Pending deletion blocks metrics not matching!",
472-
namesystem.getPendingDeletionBlocks(),
470+
namesystem.getBytesInFutureECBlockGroups(),
471+
"Bytes in future blocks metrics not matching!");
472+
assertEquals(namesystem.getPendingDeletionBlocks(),
473473
namesystem.getPendingDeletionReplicatedBlocks() +
474-
namesystem.getPendingDeletionECBlocks());
474+
namesystem.getPendingDeletionECBlocks(),
475+
"Pending deletion blocks metrics not matching!");
475476
}
476477

477478
/** Corrupt a block and ensure metrics reflects it */
@@ -567,7 +568,8 @@ public void testCorruptBlock() throws Exception {
567568
verifyAggregatedMetricsTally();
568569
}
569570

570-
@Test (timeout = 90000L)
571+
@Test
572+
@Timeout(90)
571573
public void testStripedFileCorruptBlocks() throws Exception {
572574
final long fileLen = BLOCK_SIZE * 4;
573575
final Path ecFile = new Path(ecDir, "ecFile.log");
@@ -810,7 +812,8 @@ public void testGetBlockLocationMetric() throws Exception {
810812
* Testing TransactionsSinceLastCheckpoint. Need a new cluster as
811813
* the other tests in here don't use HA. See HDFS-7501.
812814
*/
813-
@Test(timeout = 300000)
815+
@Test
816+
@Timeout(value = 300)
814817
public void testTransactionSinceLastCheckpointMetrics() throws Exception {
815818
Random random = new Random();
816819
int retryCount = 0;
@@ -845,10 +848,10 @@ public void testTransactionSinceLastCheckpointMetrics() throws Exception {
845848
HATestUtil.waitForStandbyToCatchUp(nn0, nn1);
846849
// Test to ensure tracking works before the first-ever
847850
// checkpoint.
848-
assertEquals("SBN failed to track 2 transactions pre-checkpoint.",
849-
4L, // 2 txns added further when catch-up is called.
851+
assertEquals(4L, // 2 txns added further when catch-up is called.
850852
cluster2.getNameNode(1).getNamesystem()
851-
.getTransactionsSinceLastCheckpoint());
853+
.getTransactionsSinceLastCheckpoint(),
854+
"SBN failed to track 2 transactions pre-checkpoint.");
852855
// Complete up to the boundary required for
853856
// an auto-checkpoint. Using 94 to expect fsimage
854857
// rounded at 100, as 4 + 94 + 2 (catch-up call) = 100.
@@ -861,19 +864,19 @@ public void testTransactionSinceLastCheckpointMetrics() throws Exception {
861864
// Test to ensure number tracks the right state of
862865
// uncheckpointed edits, and does not go negative
863866
// (as fixed in HDFS-7501).
864-
assertEquals("Should be zero right after the checkpoint.",
865-
0L,
867+
assertEquals(0L,
866868
cluster2.getNameNode(1).getNamesystem()
867-
.getTransactionsSinceLastCheckpoint());
869+
.getTransactionsSinceLastCheckpoint(),
870+
"Should be zero right after the checkpoint.");
868871
fs2.mkdirs(new Path("/tmp-t3"));
869872
fs2.mkdirs(new Path("/tmp-t4"));
870873
HATestUtil.waitForStandbyToCatchUp(nn0, nn1);
871874
// Test to ensure we track the right numbers after
872875
// the checkpoint resets it to zero again.
873-
assertEquals("SBN failed to track 2 added txns after the ckpt.",
874-
4L,
876+
assertEquals(4L,
875877
cluster2.getNameNode(1).getNamesystem()
876-
.getTransactionsSinceLastCheckpoint());
878+
.getTransactionsSinceLastCheckpoint(),
879+
"SBN failed to track 2 added txns after the ckpt.");
877880
cluster2.shutdown();
878881
break;
879882
} catch (Exception e) {
@@ -966,7 +969,8 @@ public void testReadWriteOps() throws Exception {
966969
* Test metrics indicating the number of active clients and the files under
967970
* construction
968971
*/
969-
@Test(timeout = 60000)
972+
@Test
973+
@Timeout(value = 60)
970974
public void testNumActiveClientsAndFilesUnderConstructionMetrics()
971975
throws Exception {
972976
final Path file1 = getTestPath("testFileAdd1");

hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/metrics/TestTopMetrics.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
import org.apache.hadoop.metrics2.MetricsCollector;
2424
import org.apache.hadoop.metrics2.MetricsRecordBuilder;
2525
import org.apache.hadoop.metrics2.lib.Interns;
26-
import org.junit.Test;
26+
import org.junit.jupiter.api.Test;
2727

2828
import static org.apache.hadoop.hdfs.server.namenode.top.metrics.TopMetrics.TOPMETRICS_METRICS_SOURCE_NAME;
2929
import static org.apache.hadoop.test.MetricsAsserts.getMetrics;

hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/snapshot/SnapshotTestHelper.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@
5050
import org.apache.log4j.LogManager;
5151
import org.apache.log4j.PatternLayout;
5252
import org.apache.log4j.WriterAppender;
53-
import org.junit.Assert;
5453
import org.slf4j.Logger;
5554
import org.slf4j.LoggerFactory;
5655

@@ -59,8 +58,9 @@
5958
import java.util.concurrent.atomic.AtomicBoolean;
6059
import java.util.concurrent.atomic.AtomicInteger;
6160

62-
import static org.junit.Assert.assertEquals;
63-
import static org.junit.Assert.assertTrue;
61+
import static org.junit.jupiter.api.Assertions.assertEquals;
62+
import static org.junit.jupiter.api.Assertions.assertNull;
63+
import static org.junit.jupiter.api.Assertions.assertTrue;
6464

6565
/**
6666
* Helper for writing snapshot related tests
@@ -210,7 +210,7 @@ Path mkdirs(Path dir) throws Exception {
210210
final String label = "mkdirs " + dir;
211211
LOG.info(label);
212212
hdfs.mkdirs(dir);
213-
Assert.assertTrue(label, hdfs.exists(dir));
213+
assertTrue(hdfs.exists(dir), label);
214214
return dir;
215215
}
216216

@@ -222,7 +222,7 @@ Path createFile(Path file) throws Exception {
222222
final String label = "createFile " + file;
223223
LOG.info(label);
224224
DFSTestUtil.createFile(hdfs, file, 0, (short)1, 0L);
225-
Assert.assertTrue(label, hdfs.exists(file));
225+
assertTrue(hdfs.exists(file), label);
226226
return file;
227227
}
228228

@@ -233,7 +233,7 @@ String rename(Path src, Path dst) throws Exception {
233233
final String label = "rename " + src + " -> " + dst;
234234
final boolean renamed = hdfs.rename(src, dst);
235235
LOG.info("{}: success? {}", label, renamed);
236-
Assert.assertTrue(label, renamed);
236+
assertTrue(renamed, label);
237237
return snapshot;
238238
}
239239

@@ -355,9 +355,9 @@ public static void checkSnapshotCreation(DistributedFileSystem hdfs,
355355
// Compare the snapshot with the current dir
356356
FileStatus[] currentFiles = hdfs.listStatus(snapshottedDir);
357357
FileStatus[] snapshotFiles = hdfs.listStatus(snapshotRoot);
358-
assertEquals("snapshottedDir=" + snapshottedDir
359-
+ ", snapshotRoot=" + snapshotRoot,
360-
currentFiles.length, snapshotFiles.length);
358+
assertEquals(currentFiles.length, snapshotFiles.length,
359+
"snapshottedDir=" + snapshottedDir
360+
+ ", snapshotRoot=" + snapshotRoot);
361361
}
362362

363363
/**
@@ -449,8 +449,8 @@ private static void compareDumpedTreeInFile(File file1, File file2,
449449
}
450450
assertEquals(line1.trim(), line2.trim());
451451
}
452-
Assert.assertNull(reader1.readLine());
453-
Assert.assertNull(reader2.readLine());
452+
assertNull(reader1.readLine());
453+
assertNull(reader2.readLine());
454454
} finally {
455455
reader1.close();
456456
reader2.close();

0 commit comments

Comments
 (0)