@Test(expected=IllegalStateException.class) public void testRedirectTwiceFails() throws Exception { launcher.setAppResource("fake-resource.jar") .setMainClass("my.fake.class.Fake") .redirectError() .redirectError(ProcessBuilder.Redirect.PIPE) .launch(); }
@Test public void testRedirectErrorToOutput() throws Exception { launcher.redirectError(); assertTrue(launcher.redirectErrorStream); }
@Test public void testRedirectLastWins() throws Exception { launcher.redirectError(ProcessBuilder.Redirect.PIPE) .redirectError(ProcessBuilder.Redirect.INHERIT); assertEquals(launcher.errorStream.type(), ProcessBuilder.Redirect.Type.INHERIT); launcher.redirectOutput(ProcessBuilder.Redirect.PIPE) .redirectOutput(ProcessBuilder.Redirect.INHERIT); assertEquals(launcher.outputStream.type(), ProcessBuilder.Redirect.Type.INHERIT); }
@Test(expected=IllegalStateException.class) public void testRedirectToLogWithOthersFails() throws Exception { launcher.setAppResource("fake-resource.jar") .setMainClass("my.fake.class.Fake") .redirectToLog("fakeLog") .redirectError(ProcessBuilder.Redirect.PIPE) .launch(); }
@Test public void testChildProcLauncher() throws Exception { // This test is failed on Windows due to the failure of initiating executors // by the path length limitation. See SPARK-18718. assumeTrue(!Utils.isWindows()); SparkSubmitOptionParser opts = new SparkSubmitOptionParser(); Map<String, String> env = new HashMap<>(); env.put("SPARK_PRINT_LAUNCH_COMMAND", "1"); launcher .setMaster("local") .setAppResource(SparkLauncher.NO_RESOURCE) .addSparkArg(opts.CONF, String.format("%s=-Dfoo=ShouldBeOverriddenBelow", SparkLauncher.DRIVER_EXTRA_JAVA_OPTIONS)) .setConf(SparkLauncher.DRIVER_EXTRA_JAVA_OPTIONS, "-Dfoo=bar -Dtest.appender=console") .setConf(SparkLauncher.DRIVER_EXTRA_CLASSPATH, System.getProperty("java.class.path")) .addSparkArg(opts.CLASS, "ShouldBeOverriddenBelow") .setMainClass(SparkLauncherTestApp.class.getName()) .redirectError() .addAppArgs("proc"); final Process app = launcher.launch(); new OutputRedirector(app.getInputStream(), getClass().getName() + ".child", TF); assertEquals(0, app.waitFor()); }
@Test public void testChildProcLauncher() throws Exception { // This test is failed on Windows due to the failure of initiating executors // by the path length limitation. See SPARK-18718. assumeTrue(!Utils.isWindows()); SparkSubmitOptionParser opts = new SparkSubmitOptionParser(); Map<String, String> env = new HashMap<>(); env.put("SPARK_PRINT_LAUNCH_COMMAND", "1"); launcher .setMaster("local") .setAppResource(SparkLauncher.NO_RESOURCE) .addSparkArg(opts.CONF, String.format("%s=-Dfoo=ShouldBeOverriddenBelow", SparkLauncher.DRIVER_EXTRA_JAVA_OPTIONS)) .setConf(SparkLauncher.DRIVER_EXTRA_JAVA_OPTIONS, "-Dfoo=bar -Dtest.appender=console") .setConf(SparkLauncher.DRIVER_EXTRA_CLASSPATH, System.getProperty("java.class.path")) .addSparkArg(opts.CLASS, "ShouldBeOverriddenBelow") .setMainClass(SparkLauncherTestApp.class.getName()) .redirectError() .addAppArgs("proc"); final Process app = launcher.launch(); new OutputRedirector(app.getInputStream(), getClass().getName() + ".child", TF); assertEquals(0, app.waitFor()); }
@Test public void testRedirectsSimple() throws Exception { launcher.redirectError(ProcessBuilder.Redirect.PIPE); assertNotNull(launcher.errorStream); assertEquals(launcher.errorStream.type(), ProcessBuilder.Redirect.Type.PIPE); launcher.redirectOutput(ProcessBuilder.Redirect.PIPE); assertNotNull(launcher.outputStream); assertEquals(launcher.outputStream.type(), ProcessBuilder.Redirect.Type.PIPE); }
@Test(expected = IllegalArgumentException.class) public void testRedirectErrorTwiceFails() throws Exception { File err = Files.createTempFile("stderr", "txt").toFile(); err.deleteOnExit(); new SparkLauncher() .redirectError() .redirectError(err) .launch() .waitFor(); }
@Test(expected = IllegalArgumentException.class) public void testBadLogRedirect() throws Exception { File out = Files.createTempFile("stdout", "txt").toFile(); out.deleteOnExit(); new SparkLauncher() .redirectError() .redirectOutput(out) .redirectToLog("foo") .launch() .waitFor(); }
@Test public void testRedirectLastWins() throws Exception { SparkLauncher launcher = new SparkLauncher(); launcher.redirectError(ProcessBuilder.Redirect.PIPE) .redirectError(ProcessBuilder.Redirect.INHERIT); assertEquals(launcher.errorStream.type(), ProcessBuilder.Redirect.Type.INHERIT); launcher.redirectOutput(ProcessBuilder.Redirect.PIPE) .redirectOutput(ProcessBuilder.Redirect.INHERIT); assertEquals(launcher.outputStream.type(), ProcessBuilder.Redirect.Type.INHERIT); }
@Test public void testRedirectsSimple() throws Exception { SparkLauncher launcher = new SparkLauncher(); launcher.redirectError(ProcessBuilder.Redirect.PIPE); assertNotNull(launcher.errorStream); assertEquals(launcher.errorStream.type(), ProcessBuilder.Redirect.Type.PIPE); launcher.redirectOutput(ProcessBuilder.Redirect.PIPE); assertNotNull(launcher.outputStream); assertEquals(launcher.outputStream.type(), ProcessBuilder.Redirect.Type.PIPE); }