🤬
  • Add process execution without output and error stream collection to CommandExecutor.

    PiperOrigin-RevId: 465390656
    Change-Id: Ib919b779dd7f6c1376684f033e9ae1aa03f9880d
  • Loading...
  • John Y. Kim committed with Copybara-Service 2 years ago
    6772e481
    1 parent f349bbac
Revision indexing in progress... (symbol navigation in revisions will be accurate after indexed)
  • ■ ■ ■ ■ ■ ■
    common/src/main/java/com/google/tsunami/common/command/CommandExecutor.java
    skipped 90 lines
    91 91   return process;
    92 92   }
    93 93   
     94 + /**
     95 + * Starts the command without collecting output and error streams.
     96 + *
     97 + * @return Started {@link Process} object.
     98 + * @throws IOException if an I/O error occurs when starting the command executing process.
     99 + * @throws InterruptedException if interrupted while starting the command executing process.
     100 + * @throws ExecutionException if the command execution failed.
     101 + */
     102 + public Process executeWithNoStreamCollection()
     103 + throws IOException, InterruptedException, ExecutionException {
     104 + logger.atInfo().log("Executing the following command: '%s'", COMMAND_ARGS_JOINER.join(args));
     105 + process = processBuilder.start();
     106 + return process;
     107 + }
     108 + 
    94 109   @Nullable
    95 110   public String getOutput() {
    96 111   return output;
    skipped 23 lines
  • ■ ■ ■ ■ ■ ■
    common/src/test/java/com/google/tsunami/common/command/CommandExecutorTest.java
    skipped 38 lines
    39 39   }
    40 40   
    41 41   @Test
     42 + public void executeWithNoStreamCollection_always_startsProcessAndReturnsProcessInstance()
     43 + throws IOException, InterruptedException, ExecutionException {
     44 + CommandExecutor executor = new CommandExecutor("/bin/sh", "-c", "echo 1");
     45 + 
     46 + Process process = executor.executeWithNoStreamCollection();
     47 + process.waitFor();
     48 + 
     49 + assertThat(process.exitValue()).isEqualTo(0);
     50 + }
     51 + 
     52 + @Test
    42 53   public void getOutput_always_returnsExpect()
    43 54   throws IOException, InterruptedException, ExecutionException {
    44 55   CommandExecutor executor = new CommandExecutor("/bin/sh", "-c", "echo 1");
    skipped 43 lines
Please wait...
Page is in error, reload to recover