Skip to content

Commit f4c3520

Browse files
committed
HADOOP-19431. [JDK17] Upgrade JUnit from 4 to 5 in hadoop-distcp Part2.
1 parent c4abdd7 commit f4c3520

File tree

1 file changed

+25
-21
lines changed

1 file changed

+25
-21
lines changed

hadoop-tools/hadoop-distcp/src/test/java/org/apache/hadoop/tools/mapred/TestCopyCommitter.java

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,11 @@
4848
import org.apache.hadoop.tools.util.DistCpUtils;
4949
import org.apache.hadoop.tools.util.TestDistCpUtils;
5050
import org.apache.hadoop.security.Credentials;
51-
import org.junit.*;
51+
import org.junit.jupiter.api.AfterAll;
52+
import org.junit.jupiter.api.AfterEach;
53+
import org.junit.jupiter.api.BeforeAll;
54+
import org.junit.jupiter.api.BeforeEach;
55+
import org.junit.jupiter.api.Test;
5256

5357
import java.io.IOException;
5458
import java.util.*;
@@ -82,7 +86,7 @@ private static Job getJobForClient() throws IOException {
8286
return job;
8387
}
8488

85-
@BeforeClass
89+
@BeforeAll
8690
public static void create() throws IOException {
8791
clusterConfig = getJobForClient().getConfiguration();
8892
clusterConfig.setLong(
@@ -97,27 +101,27 @@ public static void create() throws IOException {
97101
.build();
98102
}
99103

100-
@AfterClass
104+
@AfterAll
101105
public static void destroy() {
102106
if (cluster != null) {
103107
cluster.shutdown();
104108
}
105109
}
106110

107-
@Before
111+
@BeforeEach
108112
public void createMetaFolder() throws IOException {
109113
config = new Configuration(clusterConfig);
110114
config.set(DistCpConstants.CONF_LABEL_META_FOLDER, "/meta");
111115
Path meta = new Path("/meta");
112116
cluster.getFileSystem().mkdirs(meta);
113117
}
114118

115-
@After
119+
@AfterEach
116120
public void cleanupMetaFolder() throws IOException {
117121
Path meta = new Path("/meta");
118122
if (cluster.getFileSystem().exists(meta)) {
119123
cluster.getFileSystem().delete(meta, true);
120-
Assert.fail("Expected meta folder to be deleted");
124+
fail("Expected meta folder to be deleted");
121125
}
122126
}
123127

@@ -129,11 +133,11 @@ public void testNoCommitAction() throws IOException {
129133
taskAttemptContext.getTaskAttemptID().getJobID());
130134
OutputCommitter committer = new CopyCommitter(null, taskAttemptContext);
131135
committer.commitJob(jobContext);
132-
Assert.assertEquals("Commit Successful", taskAttemptContext.getStatus());
136+
assertEquals("Commit Successful", taskAttemptContext.getStatus());
133137

134138
//Test for idempotent commit
135139
committer.commitJob(jobContext);
136-
Assert.assertEquals("Commit Successful", taskAttemptContext.getStatus());
140+
assertEquals("Commit Successful", taskAttemptContext.getStatus());
137141
}
138142

139143
@Test
@@ -412,12 +416,12 @@ public void testDeleteMissingFlatInterleavedFiles() throws IOException {
412416

413417
committer.commitJob(jobContext);
414418
verifyFoldersAreInSync(fs, targetBase, sourceBase);
415-
Assert.assertEquals(4, fs.listStatus(new Path(targetBase)).length);
419+
assertEquals(4, fs.listStatus(new Path(targetBase)).length);
416420

417421
//Test for idempotent commit
418422
committer.commitJob(jobContext);
419423
verifyFoldersAreInSync(fs, targetBase, sourceBase);
420-
Assert.assertEquals(4, fs.listStatus(new Path(targetBase)).length);
424+
assertEquals(4, fs.listStatus(new Path(targetBase)).length);
421425
} finally {
422426
TestDistCpUtils.delete(fs, "/tmp1");
423427
conf.set(DistCpConstants.CONF_LABEL_DELETE_MISSING, "false");
@@ -486,7 +490,7 @@ public void testAtomicCommitExistingFinal() throws IOException {
486490
assertPathExists(fs, "Final path", new Path(finalPath));
487491
try {
488492
committer.commitJob(jobContext);
489-
Assert.fail("Should not be able to atomic-commit to pre-existing path.");
493+
fail("Should not be able to atomic-commit to pre-existing path.");
490494
} catch(Exception exception) {
491495
assertPathExists(fs, "Work path", new Path(workPath));
492496
assertPathExists(fs, "Final path", new Path(finalPath));
@@ -558,17 +562,17 @@ private void testCommitWithChecksumMismatch(boolean skipCrc)
558562
try {
559563
committer.commitJob(jobContext);
560564
if (!skipCrc) {
561-
Assert.fail("Expected commit to fail");
565+
fail("Expected commit to fail");
562566
}
563567
Path sourcePath = new Path(sourceBase + srcFilename);
564568
CopyListingFileStatus sourceCurrStatus =
565-
new CopyListingFileStatus(fs.getFileStatus(sourcePath));
566-
Assert.assertEquals("Checksum should not be equal",
567-
CopyMapper.ChecksumComparison.FALSE,
569+
new CopyListingFileStatus(fs.getFileStatus(sourcePath));
570+
assertEquals(CopyMapper.ChecksumComparison.FALSE,
568571
DistCpUtils.checksumsAreEqual(
569572
fs, new Path(sourceBase + srcFilename), null,
570573
fs, new Path(targetBase + srcFilename),
571-
sourceCurrStatus.getLen()));
574+
sourceCurrStatus.getLen()),
575+
"Checksum should not be equal");
572576
} catch(IOException exception) {
573577
if (skipCrc) {
574578
LOG.error("Unexpected exception is found", exception);
@@ -729,7 +733,7 @@ private void checkDirectoryPermissions(FileSystem fs, String targetBase,
729733
for (FileStatus status : fStatus) {
730734
if (status.isDirectory()) {
731735
stack.push(status.getPath());
732-
Assert.assertEquals(sourcePerm, status.getPermission());
736+
assertEquals(sourcePerm, status.getPermission());
733737
}
734738
}
735739
}
@@ -746,10 +750,10 @@ private void checkDirectoryTimes(
746750
while (sourceReader.next(srcRelPath, srcFileStatus)) {
747751
Path targetFile = new Path(targetRoot.toString() + "/" + srcRelPath);
748752
FileStatus targetStatus = fs.getFileStatus(targetFile);
749-
Assert.assertEquals(srcFileStatus.getModificationTime(),
750-
targetStatus.getModificationTime());
751-
Assert.assertEquals(srcFileStatus.getAccessTime(),
752-
targetStatus.getAccessTime());
753+
assertEquals(srcFileStatus.getModificationTime(),
754+
targetStatus.getModificationTime());
755+
assertEquals(srcFileStatus.getAccessTime(),
756+
targetStatus.getAccessTime());
753757
}
754758
} finally {
755759
IOUtils.closeStream(sourceReader);

0 commit comments

Comments
 (0)