*/
@Test
public void testStdoutIsolation()
throws NodeException, InterruptedException, ExecutionException, TimeoutException
{
NodeEnvironment env = new NodeEnvironment();
ByteArrayOutputStream out1 = new ByteArrayOutputStream();
ByteArrayOutputStream out2 = new ByteArrayOutputStream();
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 });
ns1.setSandbox(new Sandbox().setStdout(out1));
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 });
ns2.setSandbox(new Sandbox().setStdout(out2));
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 stream1 = new String(out1.toByteArray(), UTF8);
String stream2 = new String(out2.toByteArray(), UTF8);
assertEquals(msg1 + '\n', stream1);
assertEquals(msg2 + '\n', stream2);
} finally {
ns1.close();
ns2.close();
env.close();
}
}