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.
This commit is contained in:
Akira Ajisaka 2022-12-24 04:33:35 +09:00 committed by GitHub
parent bf8ab83cd0
commit 049d1762bd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 38 deletions

View File

@ -124,26 +124,6 @@
<artifactId>assertj-core</artifactId> <artifactId>assertj-core</artifactId>
<scope>test</scope> <scope>test</scope>
</dependency> </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> </dependencies>
<build> <build>

View File

@ -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.LogAggregationFileControllerContext;
import org.apache.hadoop.yarn.logaggregation.filecontroller.LogAggregationFileControllerFactory; 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. * 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 { public final class TestContainerLogsUtils {
@ -75,13 +75,16 @@ public final class TestContainerLogsUtils {
if (fs.exists(rootLogDirPath)) { if (fs.exists(rootLogDirPath)) {
fs.delete(rootLogDirPath, true); 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()); Path appLogsDir = new Path(rootLogDirPath, appId.toString());
if (fs.exists(appLogsDir)) { if (fs.exists(appLogsDir)) {
fs.delete(appLogsDir, true); 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); createContainerLogInLocalDir(appLogsDir, containerToContent, fs, fileName);
// upload container logs to remote log dir // upload container logs to remote log dir
@ -95,7 +98,9 @@ public final class TestContainerLogsUtils {
if (fs.exists(path) && deleteRemoteLogDir) { if (fs.exists(path) && deleteRemoteLogDir) {
fs.delete(path, true); 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, uploadContainerLogIntoRemoteDir(ugi, conf, rootLogDirList, nodeId, appId,
containerToContent.keySet(), path); containerToContent.keySet(), path);
} }
@ -111,7 +116,9 @@ public final class TestContainerLogsUtils {
if (fs.exists(containerLogsDir)) { if (fs.exists(containerLogsDir)) {
fs.delete(containerLogsDir, true); 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 = Writer writer =
new FileWriter(new File(containerLogsDir.toString(), fileName)); new FileWriter(new File(containerLogsDir.toString(), fileName));
writer.write(content); writer.write(content);

View File

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