use of com.facebook.buck.testutil.TestConsole in project buck by facebook.
the class ShellStepTest method testStdErrNotPrintedOnSuccessIfNotShouldPrintStdErr.
@Test
public void testStdErrNotPrintedOnSuccessIfNotShouldPrintStdErr() throws Exception {
ShellStep command = createCommand(/*shouldPrintStdErr*/
false, /*shouldPrintStdOut*/
false);
ProcessExecutorParams params = createParams();
FakeProcess process = new FakeProcess(EXIT_SUCCESS, OUTPUT_MSG, ERROR_MSG);
TestConsole console = new TestConsole(Verbosity.STANDARD_INFORMATION);
ExecutionContext context = createContext(ImmutableMap.of(params, process), console);
command.launchAndInteractWithProcess(context, params);
assertEquals("", console.getTextWrittenToStdErr());
}
use of com.facebook.buck.testutil.TestConsole in project buck by facebook.
the class WorkerShellStepTest method createExecutionContextWith.
private ExecutionContext createExecutionContextWith(final ImmutableMap<String, WorkerJobResult> jobArgs, final int poolCapacity) {
WorkerProcessPool workerProcessPool = new WorkerProcessPool(poolCapacity, Hashing.sha1().hashString(fakeWorkerStartupCommand, Charsets.UTF_8)) {
@Override
protected WorkerProcess startWorkerProcess() throws IOException {
return new FakeWorkerProcess(jobArgs);
}
};
ConcurrentHashMap<String, WorkerProcessPool> workerProcessMap = new ConcurrentHashMap<>();
workerProcessMap.put(fakeWorkerStartupCommand, workerProcessPool);
WorkerProcessPool persistentWorkerProcessPool = new WorkerProcessPool(poolCapacity, Hashing.sha1().hashString(fakePersistentWorkerStartupCommand, Charsets.UTF_8)) {
@Override
protected WorkerProcess startWorkerProcess() throws IOException {
return new FakeWorkerProcess(jobArgs);
}
};
ConcurrentHashMap<String, WorkerProcessPool> persistentWorkerProcessMap = new ConcurrentHashMap<>();
persistentWorkerProcessMap.put(persistentWorkerKey, persistentWorkerProcessPool);
ExecutionContext context = TestExecutionContext.newBuilder().setPlatform(Platform.LINUX).setWorkerProcessPools(workerProcessMap).setPersistentWorkerPools(persistentWorkerProcessMap).setConsole(new TestConsole(Verbosity.ALL)).setBuckEventBus(BuckEventBusFactory.newInstance()).build();
return context;
}
use of com.facebook.buck.testutil.TestConsole in project buck by facebook.
the class WorkerShellStepTest method testMultipleWorkerProcesses.
@Test
public void testMultipleWorkerProcesses() throws IOException, InterruptedException {
String jobArgsA = "jobArgsA";
String jobArgsB = "jobArgsB";
final ImmutableMap<String, WorkerJobResult> jobResults = ImmutableMap.of(jobArgsA, WorkerJobResult.of(0, Optional.of("stdout A"), Optional.of("stderr A")), jobArgsB, WorkerJobResult.of(0, Optional.of("stdout B"), Optional.of("stderr B")));
class WorkerShellStepWithFakeProcesses extends WorkerShellStep {
WorkerShellStepWithFakeProcesses(WorkerJobParams jobParams) {
super(Optional.ofNullable(jobParams), Optional.empty(), Optional.empty(), new WorkerProcessPoolFactory(new FakeProjectFilesystem()) {
@Override
WorkerProcess createWorkerProcess(ProcessExecutorParams processParams, ExecutionContext context, Path tmpDir) throws IOException {
try {
sleep(5);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
return new FakeWorkerProcess(jobResults);
}
});
}
}
ExecutionContext context = TestExecutionContext.newBuilder().setPlatform(Platform.LINUX).setConsole(new TestConsole(Verbosity.ALL)).setBuckEventBus(BuckEventBusFactory.newInstance()).build();
WorkerJobParams jobParamsA = createJobParams(ImmutableList.of(startupCommand), startupArgs, ImmutableMap.of(), jobArgsA, 2);
WorkerShellStep stepA = new WorkerShellStepWithFakeProcesses(jobParamsA);
WorkerShellStep stepB = new WorkerShellStepWithFakeProcesses(jobParamsA.withJobArgs(jobArgsB));
Thread[] threads = { new ConcurrentExecution(stepA, context), new ConcurrentExecution(stepB, context) };
for (Thread t : threads) {
t.start();
}
for (Thread t : threads) {
t.join();
}
Collection<WorkerProcessPool> pools = context.getWorkerProcessPools().values();
assertThat(pools.size(), Matchers.equalTo(1));
WorkerProcessPool pool = pools.iterator().next();
assertThat(pool.getCapacity(), Matchers.equalTo(2));
}
use of com.facebook.buck.testutil.TestConsole in project buck by facebook.
the class ShellStepTest method testStdErrPrintedOnErrorIfShouldPrintStdErrEvenIfSilent.
@Test
public void testStdErrPrintedOnErrorIfShouldPrintStdErrEvenIfSilent() throws Exception {
ShellStep command = createCommand(/*shouldPrintStdErr*/
true, /*shouldPrintStdOut*/
false);
ProcessExecutorParams params = createParams();
FakeProcess process = new FakeProcess(EXIT_FAILURE, OUTPUT_MSG, ERROR_MSG);
TestConsole console = new TestConsole(Verbosity.SILENT);
ExecutionContext context = createContext(ImmutableMap.of(params, process), console);
command.launchAndInteractWithProcess(context, params);
assertEquals(ERROR_MSG, console.getTextWrittenToStdErr());
}
use of com.facebook.buck.testutil.TestConsole in project buck by facebook.
the class StepFailedExceptionTest method setUp.
@Before
public void setUp() {
ExecutionContext context = TestExecutionContext.newInstance();
TestConsole verboseConsole = new TestConsole(Verbosity.ALL);
TestConsole silentConsole = new TestConsole(Verbosity.SILENT);
verboseContext = ExecutionContext.builder().from(context).setConsole(verboseConsole).setExecutors(context.getExecutors()).build();
silentContext = ExecutionContext.builder().from(context).setConsole(silentConsole).setExecutors(context.getExecutors()).build();
}
Aggregations