use of com.carrotsearch.randomizedtesting.annotations.SuppressForbidden in project randomizedtesting by randomizedtesting.
the class JUnit4 method forkProcess.
/**
* Execute a slave process. Pump events to the given event bus.
*/
@SuppressForbidden("legitimate sysstreams.")
private Execute forkProcess(ForkedJvmInfo slaveInfo, EventBus eventBus, CommandlineJava commandline, InputStream eventStream, OutputStream sysout, OutputStream syserr, RandomAccessFile streamsBuffer) {
try {
final LocalSlaveStreamHandler streamHandler = new LocalSlaveStreamHandler(eventBus, testsClassLoader, System.err, eventStream, sysout, syserr, heartbeat, streamsBuffer);
// Add certain properties to allow identification of the forked JVM from within
// the subprocess. This can be used for policy files etc.
final Path cwd = getWorkingDirectory(slaveInfo);
Variable v = new Variable();
v.setKey(CHILDVM_SYSPROP_CWD);
v.setFile(cwd.toAbsolutePath().normalize().toFile());
commandline.addSysproperty(v);
v = new Variable();
v.setKey(SysGlobals.CHILDVM_SYSPROP_JVM_ID);
v.setValue(Integer.toString(slaveInfo.id));
commandline.addSysproperty(v);
v = new Variable();
v.setKey(SysGlobals.CHILDVM_SYSPROP_JVM_COUNT);
v.setValue(Integer.toString(slaveInfo.slaves));
commandline.addSysproperty(v);
// Emit command line before -stdin to avoid confusion.
slaveInfo.slaveCommandLine = escapeAndJoin(commandline.getCommandline());
log("Forked child JVM at '" + cwd.toAbsolutePath().normalize() + "', command (may need escape sequences for your shell):\n" + slaveInfo.slaveCommandLine, Project.MSG_VERBOSE);
final Execute execute = new Execute();
execute.setCommandline(commandline.getCommandline());
execute.setVMLauncher(true);
execute.setWorkingDirectory(cwd.toFile());
execute.setStreamHandler(streamHandler);
execute.setNewenvironment(newEnvironment);
if (env.getVariables() != null)
execute.setEnvironment(env.getVariables());
log("Starting JVM J" + slaveInfo.id, Project.MSG_DEBUG);
execute.execute();
return execute;
} catch (IOException e) {
throw new BuildException("Could not start the child process. Run ant with -verbose to get" + " the execution details.", e);
}
}
use of com.carrotsearch.randomizedtesting.annotations.SuppressForbidden in project randomizedtesting by randomizedtesting.
the class SlaveMain method redirectStreams.
/**
* Redirect standard streams so that the output can be passed to listeners.
*/
@SuppressForbidden("legitimate sysstreams.")
private static void redirectStreams(final Serializer serializer, final boolean flushFrequently) {
final PrintStream origSysOut = System.out;
final PrintStream origSysErr = System.err;
// Set warnings stream to System.err.
warnings = System.err;
AccessController.doPrivileged(new PrivilegedAction<Void>() {
@SuppressForbidden("legitimate PrintStream with default charset.")
@Override
public Void run() {
System.setOut(new PrintStream(new BufferedOutputStream(new ChunkedStream() {
@Override
public void write(byte[] b, int off, int len) throws IOException {
if (multiplexStdStreams) {
origSysOut.write(b, off, len);
}
serializer.serialize(new AppendStdOutEvent(b, off, len));
if (flushFrequently)
serializer.flush();
}
})));
System.setErr(new PrintStream(new BufferedOutputStream(new ChunkedStream() {
@Override
public void write(byte[] b, int off, int len) throws IOException {
if (multiplexStdStreams) {
origSysErr.write(b, off, len);
}
serializer.serialize(new AppendStdErrEvent(b, off, len));
if (flushFrequently)
serializer.flush();
}
})));
return null;
}
});
}
Aggregations