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>
<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>

View File

@ -38,10 +38,10 @@
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 static void createContainerLogFileInRemoteFS(Configuration conf,
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 static void createContainerLogFileInRemoteFS(Configuration conf,
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 @@ private static void createContainerLogInLocalDir(Path appLogsDir,
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);

View File

@ -27,8 +27,7 @@
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 static String getXmlAttrString(Element element, String name) {
}
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());
}
}