瀏覽代碼

HADOOP-19431. [JDK17] Upgrade JUnit from 4 to 5 in hadoop-distcp Part2. (#7747)

Co-authored-by: Chris Nauroth <cnauroth@apache.org>
Co-authored-by: Hualong Zhang <hualong.z@hotmail.com>
Reviewed-by: Chris Nauroth <cnauroth@apache.org>
Reviewed-by: Hualong Zhang <hualong.z@hotmail.com>
Signed-off-by: Shilun Fan <slfan1989@apache.org>
slfan1989 2 周之前
父節點
當前提交
bf244eab30

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

@@ -48,7 +48,11 @@ import org.apache.hadoop.tools.GlobbedCopyListing;
 import org.apache.hadoop.tools.util.DistCpUtils;
 import org.apache.hadoop.tools.util.TestDistCpUtils;
 import org.apache.hadoop.security.Credentials;
-import org.junit.*;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
 
 import java.io.IOException;
 import java.util.*;
@@ -82,7 +86,7 @@ public class TestCopyCommitter {
     return job;
   }
 
-  @BeforeClass
+  @BeforeAll
   public static void create() throws IOException {
     clusterConfig = getJobForClient().getConfiguration();
     clusterConfig.setLong(
@@ -97,14 +101,14 @@ public class TestCopyCommitter {
         .build();
   }
 
-  @AfterClass
+  @AfterAll
   public static void destroy() {
     if (cluster != null) {
       cluster.shutdown();
     }
   }
 
-  @Before
+  @BeforeEach
   public void createMetaFolder() throws IOException {
     config = new Configuration(clusterConfig);
     config.set(DistCpConstants.CONF_LABEL_META_FOLDER, "/meta");
@@ -112,12 +116,12 @@ public class TestCopyCommitter {
     cluster.getFileSystem().mkdirs(meta);
   }
 
-  @After
+  @AfterEach
   public void cleanupMetaFolder() throws IOException {
     Path meta = new Path("/meta");
     if (cluster.getFileSystem().exists(meta)) {
       cluster.getFileSystem().delete(meta, true);
-      Assert.fail("Expected meta folder to be deleted");
+      fail("Expected meta folder to be deleted");
     }
   }
 
@@ -129,11 +133,11 @@ public class TestCopyCommitter {
         taskAttemptContext.getTaskAttemptID().getJobID());
     OutputCommitter committer = new CopyCommitter(null, taskAttemptContext);
     committer.commitJob(jobContext);
-    Assert.assertEquals("Commit Successful", taskAttemptContext.getStatus());
+    assertEquals("Commit Successful", taskAttemptContext.getStatus());
 
     //Test for idempotent commit
     committer.commitJob(jobContext);
-    Assert.assertEquals("Commit Successful", taskAttemptContext.getStatus());
+    assertEquals("Commit Successful", taskAttemptContext.getStatus());
   }
 
   @Test
@@ -412,12 +416,12 @@ public class TestCopyCommitter {
 
       committer.commitJob(jobContext);
       verifyFoldersAreInSync(fs, targetBase, sourceBase);
-      Assert.assertEquals(4, fs.listStatus(new Path(targetBase)).length);
+      assertEquals(4, fs.listStatus(new Path(targetBase)).length);
 
       //Test for idempotent commit
       committer.commitJob(jobContext);
       verifyFoldersAreInSync(fs, targetBase, sourceBase);
-      Assert.assertEquals(4, fs.listStatus(new Path(targetBase)).length);
+      assertEquals(4, fs.listStatus(new Path(targetBase)).length);
     } finally {
       TestDistCpUtils.delete(fs, "/tmp1");
       conf.set(DistCpConstants.CONF_LABEL_DELETE_MISSING, "false");
@@ -486,7 +490,7 @@ public class TestCopyCommitter {
       assertPathExists(fs, "Final path", new Path(finalPath));
       try {
         committer.commitJob(jobContext);
-        Assert.fail("Should not be able to atomic-commit to pre-existing path.");
+        fail("Should not be able to atomic-commit to pre-existing path.");
       } catch(Exception exception) {
         assertPathExists(fs, "Work path", new Path(workPath));
         assertPathExists(fs, "Final path", new Path(finalPath));
@@ -558,17 +562,17 @@ public class TestCopyCommitter {
       try {
         committer.commitJob(jobContext);
         if (!skipCrc) {
-          Assert.fail("Expected commit to fail");
+          fail("Expected commit to fail");
         }
         Path sourcePath = new Path(sourceBase + srcFilename);
         CopyListingFileStatus sourceCurrStatus =
-                new CopyListingFileStatus(fs.getFileStatus(sourcePath));
-        Assert.assertEquals("Checksum should not be equal",
-            CopyMapper.ChecksumComparison.FALSE,
+            new CopyListingFileStatus(fs.getFileStatus(sourcePath));
+        assertEquals(CopyMapper.ChecksumComparison.FALSE,
             DistCpUtils.checksumsAreEqual(
                 fs, new Path(sourceBase + srcFilename), null,
                 fs, new Path(targetBase + srcFilename),
-                sourceCurrStatus.getLen()));
+                sourceCurrStatus.getLen()),
+            "Checksum should not be equal");
       } catch(IOException exception) {
         if (skipCrc) {
           LOG.error("Unexpected exception is found", exception);
@@ -729,7 +733,7 @@ public class TestCopyCommitter {
       for (FileStatus status : fStatus) {
         if (status.isDirectory()) {
           stack.push(status.getPath());
-          Assert.assertEquals(sourcePerm, status.getPermission());
+          assertEquals(sourcePerm, status.getPermission());
         }
       }
     }
@@ -746,10 +750,10 @@ public class TestCopyCommitter {
       while (sourceReader.next(srcRelPath, srcFileStatus)) {
         Path targetFile = new Path(targetRoot.toString() + "/" + srcRelPath);
         FileStatus targetStatus = fs.getFileStatus(targetFile);
-        Assert.assertEquals(srcFileStatus.getModificationTime(),
-                targetStatus.getModificationTime());
-        Assert.assertEquals(srcFileStatus.getAccessTime(),
-                targetStatus.getAccessTime());
+        assertEquals(srcFileStatus.getModificationTime(),
+            targetStatus.getModificationTime());
+        assertEquals(srcFileStatus.getAccessTime(),
+            targetStatus.getAccessTime());
       }
     } finally {
       IOUtils.closeStream(sourceReader);