use of com.google.copybara.util.CommandRunner 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\\)");
}
use of com.google.copybara.util.CommandRunner in project copybara by google.
the class CommandRunnerTest method testMaxCommandLength.
@Test
public void testMaxCommandLength() throws Exception {
String[] args = new String[10000];
args[0] = "echo";
for (int i = 1; i < 10000; i++) {
args[i] = "hello world!";
}
Command command = new Command(args);
CommandOutputWithStatus result = runCommand(new CommandRunner(command).withVerbose(true));
assertThat(result.getTerminationStatus().success()).isTrue();
assertLogContains("...", "'echo' STDOUT: hello world!", "Command 'echo' finished");
}
use of com.google.copybara.util.CommandRunner in project copybara by google.
the class CommandRunnerTest method testCommandWithCustomRunner.
@Test
public void testCommandWithCustomRunner() throws Exception {
Command command = bashCommand("");
CommandException e = assertThrows(CommandException.class, () -> runCommand(new CommandRunner(command).withCommandExecutor(new CommandExecutor() {
@Override
public TerminationStatus getCommandOutputWithStatus(Command cmd, byte[] input, KillableObserver cmdMonitor, OutputStream stdoutStream, OutputStream stderrStream) throws CommandException {
throw new CommandException(cmd, "OH NOES!");
}
})));
assertThat(e).hasMessageThat().contains("OH NOES!");
}
Aggregations