Skip to content

Commit a43510e

Browse files
author
Inigo Goiri
committed
YARN-10161. TestRouterWebServicesREST is corrupting STDOUT. Contributed by Jim Brennan.
1 parent b420dde commit a43510e

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/src/test/java/org/apache/hadoop/yarn/server/router/webapp/JavaProcess.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,12 @@ public class JavaProcess {
2929

3030
private Process process = null;
3131

32-
public JavaProcess(Class<?> clazz) throws IOException, InterruptedException {
33-
this(clazz, null);
32+
public JavaProcess(Class<?> clazz, File output)
33+
throws IOException, InterruptedException {
34+
this(clazz, null, output);
3435
}
3536

36-
public JavaProcess(Class<?> clazz, List<String> addClasspaths)
37+
public JavaProcess(Class<?> clazz, List<String> addClasspaths, File output)
3738
throws IOException, InterruptedException {
3839
String javaHome = System.getProperty("java.home");
3940
String javaBin =
@@ -48,7 +49,9 @@ public JavaProcess(Class<?> clazz, List<String> addClasspaths)
4849
String className = clazz.getCanonicalName();
4950
ProcessBuilder builder =
5051
new ProcessBuilder(javaBin, "-cp", classpath, className);
51-
builder.inheritIO();
52+
builder.redirectInput(ProcessBuilder.Redirect.INHERIT);
53+
builder.redirectOutput(output);
54+
builder.redirectError(output);
5255
process = builder.start();
5356
}
5457

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/src/test/java/org/apache/hadoop/yarn/server/router/webapp/TestRouterWebServicesREST.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
import static org.junit.Assert.assertNotNull;
7373
import static org.junit.Assert.fail;
7474

75+
import java.io.File;
7576
import java.io.IOException;
7677
import java.security.PrivilegedExceptionAction;
7778
import java.util.ArrayList;
@@ -203,17 +204,27 @@ public Boolean get() {
203204
public static void setUp() throws Exception {
204205
conf = new YarnConfiguration();
205206

207+
File baseDir = GenericTestUtils.getTestDir("processes");
208+
baseDir.mkdirs();
209+
String baseName = TestRouterWebServicesREST.class.getSimpleName();
210+
211+
File rmOutput = new File(baseDir, baseName + "-rm.log");
212+
rmOutput.createNewFile();
206213
List<String> addClasspath = new LinkedList<>();
207214
addClasspath.add("../hadoop-yarn-server-timelineservice/target/classes");
208-
rm = new JavaProcess(ResourceManager.class, addClasspath);
215+
rm = new JavaProcess(ResourceManager.class, addClasspath, rmOutput);
209216
rmAddress = getRMWebAppURLWithScheme(conf);
210217
waitWebAppRunning(rmAddress, RM_WEB_SERVICE_PATH);
211218

212-
router = new JavaProcess(Router.class);
219+
File routerOutput = new File(baseDir, baseName + "-router.log");
220+
routerOutput.createNewFile();
221+
router = new JavaProcess(Router.class, routerOutput);
213222
routerAddress = getRouterWebAppURLWithScheme(conf);
214223
waitWebAppRunning(routerAddress, RM_WEB_SERVICE_PATH);
215224

216-
nm = new JavaProcess(NodeManager.class);
225+
File nmOutput = new File(baseDir, baseName + "-nm.log");
226+
nmOutput.createNewFile();
227+
nm = new JavaProcess(NodeManager.class, nmOutput);
217228
nmAddress = "http://" + getNMWebAppURLWithoutScheme(conf);
218229
waitWebAppRunning(nmAddress, "/ws/v1/node");
219230
}

0 commit comments

Comments
 (0)