Search in sources :

Example 1 with InputStreamAwaiter

use of org.neo4j.test.InputStreamAwaiter 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();
        }
    }
}
Also used : OutputStream(java.io.OutputStream) ProcessStreamHandler(org.neo4j.test.ProcessStreamHandler) InputStreamAwaiter(org.neo4j.test.InputStreamAwaiter)

Aggregations

OutputStream (java.io.OutputStream)1 InputStreamAwaiter (org.neo4j.test.InputStreamAwaiter)1 ProcessStreamHandler (org.neo4j.test.ProcessStreamHandler)1