public void terminate_if_unexpected_shutdown() throws Exception {
Props props = new Props(new Properties());
props.set(ProcessEntryPoint.PROPERTY_PROCESS_KEY, "foo");
props.set(ProcessEntryPoint.PROPERTY_TERMINATION_TIMEOUT, "30000");
final ProcessEntryPoint entryPoint = new ProcessEntryPoint(props, exit, mock(ProcessCommands.class));
final StandardProcess process = new StandardProcess();
Thread runner = new Thread() {
@Override
public void run() {
// starts and waits until terminated
entryPoint.launch(process);
}
};
runner.start();
while (process.getState() != State.STARTED) {
Thread.sleep(10L);
}
// emulate signal to shutdown process
entryPoint.getShutdownHook().start();
while (process.getState() != State.STOPPED) {
Thread.sleep(10L);
}
// exit before test timeout, ok !
}