@Test
public void testStdoutSharing()
throws NodeException, InterruptedException, ExecutionException, TimeoutException
{
ByteArrayOutputStream out = new ByteArrayOutputStream();
NodeEnvironment env = new NodeEnvironment();
env.setSandbox(new Sandbox().setStdout(out));
String msg1 = "This is script number 1";
NodeScript ns1 =
env.createScript("consolelogtest.js", new File("./target/test-classes/tests/consolelogtest.js"),
new String[] { "stdout", msg1 });
String msg2 = "This is script number two";
NodeScript ns2 =
env.createScript("consolelogtest.js", new File("./target/test-classes/tests/consolelogtest.js"),
new String[] { "stdout", msg2 });
try {
ScriptFuture f1 = ns1.execute();
ScriptFuture f2 = ns2.execute();
ScriptStatus result1 = f1.get(SCRIPT_TIMEOUT_SECS, TimeUnit.SECONDS);
assertEquals(0, result1.getExitCode());
ScriptStatus result2 = f2.get(SCRIPT_TIMEOUT_SECS, TimeUnit.SECONDS);
assertEquals(0, result2.getExitCode());
String stream = new String(out.toByteArray(), UTF8);
assertTrue(stream.equals(msg1 + '\n' + msg2 + '\n') ||
stream.equals(msg2 + '\n' + msg1 + '\n'));
} finally {
ns1.close();
ns2.close();
env.close();
}
}