use of org.neo4j.test.ProcessStreamHandler in project neo4j by neo4j.
the class LegacyDatabaseImpl method start.
public static Future<LegacyDatabase> start(String classpath, File storeDir, Map<String, String> config) throws Exception {
List<String> args = new ArrayList<String>();
args.add(storeDir.getAbsolutePath());
int rmiPort = 7000 + parseInt(config.get("ha.server_id"));
args.add("" + rmiPort);
args.addAll(asList(new Args(config).asArgs()));
final Process process = execJava(appendNecessaryTestClasses(classpath), LegacyDatabaseImpl.class.getName(), args.toArray(new String[0]));
new ProcessStreamHandler(process, false).launch();
final RmiLocation rmiLocation = rmiLocation(rmiPort);
ExecutorService executor = newSingleThreadExecutor();
Future<LegacyDatabase> future = executor.submit(new Callable<LegacyDatabase>() {
@Override
public LegacyDatabase call() throws Exception {
long endTime = currentTimeMillis() + SECONDS.toMillis(10000);
while (currentTimeMillis() < endTime) {
try {
return (LegacyDatabase) rmiLocation.getBoundObject();
} catch (RemoteException e) {
// OK
sleep(100);
}
}
process.destroy();
throw new IllegalStateException("Couldn't get remote to legacy database");
}
});
executor.shutdown();
return future;
}
use of org.neo4j.test.ProcessStreamHandler in project neo4j by neo4j.
the class RmiPublicationIT method waitForExit.
private int waitForExit(Process process, int maxSeconds) throws InterruptedException {
try {
long endTime = System.currentTimeMillis() + maxSeconds * 1000;
ProcessStreamHandler streamHandler = new ProcessStreamHandler(process, false);
streamHandler.launch();
try {
while (System.currentTimeMillis() < endTime) {
try {
return process.exitValue();
} catch (IllegalThreadStateException e) {
// OK, not exited yet
Thread.sleep(100);
}
}
tempHackToGetThreadDump(process);
throw new RuntimeException("Process didn't exit on its own.");
} finally {
streamHandler.cancel();
}
} finally {
process.destroy();
}
}
use of org.neo4j.test.ProcessStreamHandler in project neo4j by neo4j.
the class RmiPublicationIT method tempHackToGetThreadDump.
private void tempHackToGetThreadDump(Process process) {
try {
Field pidField = process.getClass().getDeclaredField("pid");
pidField.setAccessible(true);
int pid = (int) pidField.get(process);
ProcessBuilder processBuilder = new ProcessBuilder("/bin/sh", "-c", "kill -3 " + pid);
processBuilder.redirectErrorStream(true);
Process dumpProc = processBuilder.start();
ProcessStreamHandler streamHandler = new ProcessStreamHandler(dumpProc, false);
streamHandler.launch();
try {
process.waitFor();
} finally {
streamHandler.cancel();
}
} catch (Throwable e) {
e.printStackTrace();
}
}
use of org.neo4j.test.ProcessStreamHandler in project neo4j by neo4j.
the class HardKillIT method run.
private Process run(int machineId) throws IOException {
List<String> allArgs = new ArrayList<>(Arrays.asList("java", "-cp", System.getProperty("java.class.path"), "-Djava.awt.headless=true", HardKillIT.class.getName()));
allArgs.add("" + machineId);
allArgs.add(path(machineId).getAbsolutePath());
Process process = Runtime.getRuntime().exec(allArgs.toArray(new String[allArgs.size()]));
processHandler = new ProcessStreamHandler(process, false);
processHandler.launch();
return process;
}
use of org.neo4j.test.ProcessStreamHandler in project neo4j by neo4j.
the class ArbiterBootstrapperIT method startArbiter.
private boolean startArbiter(File configDir, CountDownLatch latch) throws Exception {
Process process = null;
ProcessStreamHandler handler = null;
try {
process = startArbiterProcess(configDir);
new InputStreamAwaiter(process.getInputStream()).awaitLine(START_SIGNAL, 20, SECONDS);
handler = new ProcessStreamHandler(process, false, "", IGNORE_FAILURES);
handler.launch();
// being able to start is assumed in this test to be that the specified port already is in use.
return latch.await(10, SECONDS);
} finally {
if (process != null) {
// Tell it to leave the cluster and shut down now
try (OutputStream inputToOtherProcess = process.getOutputStream()) {
inputToOtherProcess.write(0);
inputToOtherProcess.flush();
}
if (!process.waitFor(10, SECONDS)) {
kill(process);
}
}
if (handler != null) {
handler.done();
}
}
}
Aggregations