Jelajahi Sumber

MAPREDUCE-7428. Fix failing MapReduce tests due to the JUnit upgrades in WebServicesTestUtils (#5243)

Removed JUnit APIs from WebServicesTestUtils and TestContainerLogsUtils.
They are used by MapReduce modules as well as YARN modules, so the
APIs need to be removed to upgrade the JUnit version on a per-module basis.
Also, this effectively reverts the prior fix in #5209 because it didn't actually
fix the issue.
Akira Ajisaka 2 tahun lalu
induk
melakukan
049d1762bd

+ 0 - 20
hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-app/pom.xml

@@ -124,26 +124,6 @@
       <artifactId>assertj-core</artifactId>
       <scope>test</scope>
     </dependency>
-    <dependency>
-      <groupId>org.junit.platform</groupId>
-      <artifactId>junit-platform-launcher</artifactId>
-      <scope>test</scope>
-    </dependency>
-    <dependency>
-      <groupId>org.junit.jupiter</groupId>
-      <artifactId>junit-jupiter-api</artifactId>
-      <scope>test</scope>
-    </dependency>
-    <dependency>
-      <groupId>org.junit.jupiter</groupId>
-      <artifactId>junit-jupiter-engine</artifactId>
-      <scope>test</scope>
-    </dependency>
-    <dependency>
-      <groupId>org.junit.platform</groupId>
-      <artifactId>junit-platform-launcher</artifactId>
-      <scope>test</scope>
-    </dependency>
   </dependencies>
 
   <build>

+ 14 - 7
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/logaggregation/TestContainerLogsUtils.java

@@ -38,10 +38,10 @@ import org.apache.hadoop.yarn.logaggregation.filecontroller.LogAggregationFileCo
 import org.apache.hadoop.yarn.logaggregation.filecontroller.LogAggregationFileControllerContext;
 import org.apache.hadoop.yarn.logaggregation.filecontroller.LogAggregationFileControllerFactory;
 
-import static org.junit.jupiter.api.Assertions.assertTrue;
-
 /**
  * This class contains several utility functions for log aggregation tests.
+ * Any assertion libraries shouldn't be used here because this class is used by
+ * multiple modules including MapReduce.
  */
 public final class TestContainerLogsUtils {
 
@@ -75,13 +75,16 @@ public final class TestContainerLogsUtils {
     if (fs.exists(rootLogDirPath)) {
       fs.delete(rootLogDirPath, true);
     }
-    assertTrue(fs.mkdirs(rootLogDirPath));
+    fs.mkdirs(rootLogDirPath);
+    // Make sure the target dir is created. If not, FileNotFoundException is thrown
+    fs.getFileStatus(rootLogDirPath);
     Path appLogsDir = new Path(rootLogDirPath, appId.toString());
     if (fs.exists(appLogsDir)) {
       fs.delete(appLogsDir, true);
     }
-    assertTrue(fs.mkdirs(appLogsDir));
-
+    fs.mkdirs(appLogsDir);
+    // Make sure the target dir is created. If not, FileNotFoundException is thrown
+    fs.getFileStatus(appLogsDir);
     createContainerLogInLocalDir(appLogsDir, containerToContent, fs, fileName);
     // upload container logs to remote log dir
 
@@ -95,7 +98,9 @@ public final class TestContainerLogsUtils {
     if (fs.exists(path) && deleteRemoteLogDir) {
       fs.delete(path, true);
     }
-    assertTrue(fs.mkdirs(path));
+    fs.mkdirs(path);
+    // Make sure the target dir is created. If not, FileNotFoundException is thrown
+    fs.getFileStatus(path);
     uploadContainerLogIntoRemoteDir(ugi, conf, rootLogDirList, nodeId, appId,
         containerToContent.keySet(), path);
   }
@@ -111,7 +116,9 @@ public final class TestContainerLogsUtils {
       if (fs.exists(containerLogsDir)) {
         fs.delete(containerLogsDir, true);
       }
-      assertTrue(fs.mkdirs(containerLogsDir));
+      fs.mkdirs(containerLogsDir);
+      // Make sure the target dir is created. If not, FileNotFoundException is thrown
+      fs.getFileStatus(containerLogsDir);
       Writer writer =
           new FileWriter(new File(containerLogsDir.toString(), fileName));
       writer.write(content);

+ 6 - 11
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/webapp/WebServicesTestUtils.java

@@ -27,8 +27,7 @@ import org.w3c.dom.Element;
 import org.w3c.dom.Node;
 import org.w3c.dom.NodeList;
 
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.assertj.core.api.Assertions.assertThat;
 
 public class WebServicesTestUtils {
   public static long getXmlLong(Element element, String name) {
@@ -121,28 +120,24 @@ public class WebServicesTestUtils {
   }
 
   public static void checkStringMatch(String print, String expected, String got) {
-    assertTrue(
-        got.matches(expected),
-        print + " doesn't match, got: " + got + " expected: " + expected);
+    assertThat(got).as(print).matches(expected);
   }
 
   public static void checkStringContains(String print, String expected, String got) {
-    assertTrue(
-        got.contains(expected),
-        print + " doesn't contain expected string, got: " + got + " expected: " + expected);
+    assertThat(got).as(print).contains(expected);
   }
 
   public static void checkStringEqual(String print, String expected, String got) {
-    assertEquals(got, expected);
+    assertThat(got).as(print).isEqualTo(expected);
   }
 
   public static void assertResponseStatusCode(StatusType expected,
       StatusType actual) {
-    assertResponseStatusCode(null, expected, actual);
+    assertThat(expected.getStatusCode()).isEqualTo(actual.getStatusCode());
   }
 
   public static void assertResponseStatusCode(String errmsg,
       StatusType expected, StatusType actual) {
-    assertEquals(expected.getStatusCode(), actual.getStatusCode(), errmsg);
+    assertThat(expected.getStatusCode()).withFailMessage(errmsg).isEqualTo(actual.getStatusCode());
   }
 }