@Override public int execute( final OverthereExecutionOutputHandler stdoutHandler, final OverthereExecutionOutputHandler stderrHandler, final CmdLine commandLine) { final OverthereProcess process = startProcess(commandLine); Thread stdoutReaderThread = null; Thread stderrReaderThread = null; final CountDownLatch latch = new CountDownLatch(2); try { stdoutReaderThread = getThread("stdout", commandLine.toString(), stdoutHandler, process.getStdout(), latch); stdoutReaderThread.start(); stderrReaderThread = getThread("stderr", commandLine.toString(), stderrHandler, process.getStderr(), latch); stderrReaderThread.start(); try { latch.await(); return process.waitFor(); } catch (InterruptedException exc) { Thread.currentThread().interrupt(); logger.info("Execution interrupted, destroying the process."); process.destroy(); throw new RuntimeIOException("Execution interrupted", exc); } } finally { quietlyJoinThread(stdoutReaderThread); quietlyJoinThread(stderrReaderThread); } }
private void assertCorrectValues() { assertEquals(Boolean.TRUE, b1.getValue()); assertEquals(B2_DEFAULT, b2.value()); assertEquals(B3_DEFAULT, b3.value()); assertEquals(1, i1.value()); assertEquals(I2_DEFAULT, i2.value()); assertEquals(I3_DEFAULT, i3.value()); assertEquals(Arrays.asList(new String[] {"hello", "world"}), Arrays.asList(sa1.value())); assertEquals(Arrays.asList(SA2_DEFAULT), Arrays.asList(sa2.value())); assertEquals(s1.value(), "goodnight"); assertEquals(s2.value(), S2_DEFAULT); assertEquals(cmdLine.getArguments(), Arrays.asList(new String[] {"arg1", "arg2"})); assertEquals(Boolean.TRUE.toString(), b1.toString()); assertEquals(S2_DEFAULT, s2.toString()); final String expected = getClass().getName() + "{?=false" + ", b1=true, b2=true, b3=false" + ", i1=1, i2=2, i3=-1" + ", s1=goodnight, s2=s2-default" + ", sa1=[hello, world], sa2=[1, 2, 3]}" + "[arg1, arg2]"; assertEquals(expected, cmdLine.toString()); }