YARN-10161. TestRouterWebServicesREST is corrupting STDOUT. Contributed by Jim Brennan.

(cherry picked from commit a43510e21d)
This commit is contained in:
Inigo Goiri 2020-02-27 13:18:30 -08:00
parent b5022b0515
commit 4924622e6e
2 changed files with 21 additions and 7 deletions

View File

@ -29,11 +29,12 @@ public class JavaProcess {
private Process process = null; private Process process = null;
public JavaProcess(Class<?> clazz) throws IOException, InterruptedException { public JavaProcess(Class<?> clazz, File output)
this(clazz, null); throws IOException, InterruptedException {
this(clazz, null, output);
} }
public JavaProcess(Class<?> clazz, List<String> addClasspaths) public JavaProcess(Class<?> clazz, List<String> addClasspaths, File output)
throws IOException, InterruptedException { throws IOException, InterruptedException {
String javaHome = System.getProperty("java.home"); String javaHome = System.getProperty("java.home");
String javaBin = String javaBin =
@ -48,7 +49,9 @@ public class JavaProcess {
String className = clazz.getCanonicalName(); String className = clazz.getCanonicalName();
ProcessBuilder builder = ProcessBuilder builder =
new ProcessBuilder(javaBin, "-cp", classpath, className); new ProcessBuilder(javaBin, "-cp", classpath, className);
builder.inheritIO(); builder.redirectInput(ProcessBuilder.Redirect.INHERIT);
builder.redirectOutput(output);
builder.redirectError(output);
process = builder.start(); process = builder.start();
} }

View File

@ -70,6 +70,7 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail; import static org.junit.Assert.fail;
import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.security.PrivilegedExceptionAction; import java.security.PrivilegedExceptionAction;
import java.util.ArrayList; import java.util.ArrayList;
@ -196,17 +197,27 @@ public class TestRouterWebServicesREST {
public static void setUp() throws Exception { public static void setUp() throws Exception {
conf = new YarnConfiguration(); conf = new YarnConfiguration();
File baseDir = GenericTestUtils.getTestDir("processes");
baseDir.mkdirs();
String baseName = TestRouterWebServicesREST.class.getSimpleName();
File rmOutput = new File(baseDir, baseName + "-rm.log");
rmOutput.createNewFile();
List<String> addClasspath = new LinkedList<>(); List<String> addClasspath = new LinkedList<>();
addClasspath.add("../hadoop-yarn-server-timelineservice/target/classes"); addClasspath.add("../hadoop-yarn-server-timelineservice/target/classes");
rm = new JavaProcess(ResourceManager.class, addClasspath); rm = new JavaProcess(ResourceManager.class, addClasspath, rmOutput);
rmAddress = getRMWebAppURLWithScheme(conf); rmAddress = getRMWebAppURLWithScheme(conf);
waitWebAppRunning(rmAddress, RM_WEB_SERVICE_PATH); waitWebAppRunning(rmAddress, RM_WEB_SERVICE_PATH);
router = new JavaProcess(Router.class); File routerOutput = new File(baseDir, baseName + "-router.log");
routerOutput.createNewFile();
router = new JavaProcess(Router.class, routerOutput);
routerAddress = getRouterWebAppURLWithScheme(conf); routerAddress = getRouterWebAppURLWithScheme(conf);
waitWebAppRunning(routerAddress, RM_WEB_SERVICE_PATH); waitWebAppRunning(routerAddress, RM_WEB_SERVICE_PATH);
nm = new JavaProcess(NodeManager.class); File nmOutput = new File(baseDir, baseName + "-nm.log");
nmOutput.createNewFile();
nm = new JavaProcess(NodeManager.class, nmOutput);
nmAddress = "http://" + getNMWebAppURLWithoutScheme(conf); nmAddress = "http://" + getNMWebAppURLWithoutScheme(conf);
waitWebAppRunning(nmAddress, "/ws/v1/node"); waitWebAppRunning(nmAddress, "/ws/v1/node");
} }