Search in sources :

Example 1 with Killable

use of com.google.copybara.shell.Killable in project copybara by google.

the class CommandRunnerTest method testObserverCanTerminate.

@Test
public void testObserverCanTerminate() throws Exception {
    KillableObserver tester = new KillableObserver() {

        @Override
        public void startObserving(Killable killable) {
            try {
                Thread.sleep(1000);
            } catch (InterruptedException ignored) {
            // ignored
            }
            killable.kill();
        }

        @Override
        public void stopObserving(Killable killable) {
        }
    };
    Command command = bashCommand("" + "echo stdout msg\n" + ">&2 echo stderr msg\n" + "sleep 10\n");
    AbnormalTerminationException e = assertThrows(AbnormalTerminationException.class, () -> runCommand(new CommandRunner(command, Duration.ofSeconds(90)).withObserver(tester)));
    assertThat(e).hasMessageThat().containsMatch("Process terminated by signal 15");
    assertThat(e).hasMessageThat().doesNotContainMatch("Command '.*' killed by Copybara after timeout \\(1s\\)");
}
Also used : KillableObserver(com.google.copybara.shell.KillableObserver) Command(com.google.copybara.shell.Command) Killable(com.google.copybara.shell.Killable) AbnormalTerminationException(com.google.copybara.shell.AbnormalTerminationException) CommandRunner(com.google.copybara.util.CommandRunner) Test(org.junit.Test)

Aggregations

AbnormalTerminationException (com.google.copybara.shell.AbnormalTerminationException)1 Command (com.google.copybara.shell.Command)1 Killable (com.google.copybara.shell.Killable)1 KillableObserver (com.google.copybara.shell.KillableObserver)1 CommandRunner (com.google.copybara.util.CommandRunner)1 Test (org.junit.Test)1