Search in sources :

Example 51 with TestConsole

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());
}
Also used : ProcessExecutorParams(com.facebook.buck.util.ProcessExecutorParams) ExecutionContext(com.facebook.buck.step.ExecutionContext) TestExecutionContext(com.facebook.buck.step.TestExecutionContext) FakeProcess(com.facebook.buck.util.FakeProcess) TestConsole(com.facebook.buck.testutil.TestConsole) Test(org.junit.Test)

Example 52 with TestConsole

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;
}
Also used : ExecutionContext(com.facebook.buck.step.ExecutionContext) TestExecutionContext(com.facebook.buck.step.TestExecutionContext) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) TestConsole(com.facebook.buck.testutil.TestConsole)

Example 53 with TestConsole

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));
}
Also used : Path(java.nio.file.Path) ProcessExecutorParams(com.facebook.buck.util.ProcessExecutorParams) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ExecutionContext(com.facebook.buck.step.ExecutionContext) TestExecutionContext(com.facebook.buck.step.TestExecutionContext) TestConsole(com.facebook.buck.testutil.TestConsole) Test(org.junit.Test)

Example 54 with TestConsole

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());
}
Also used : ProcessExecutorParams(com.facebook.buck.util.ProcessExecutorParams) ExecutionContext(com.facebook.buck.step.ExecutionContext) TestExecutionContext(com.facebook.buck.step.TestExecutionContext) FakeProcess(com.facebook.buck.util.FakeProcess) TestConsole(com.facebook.buck.testutil.TestConsole) Test(org.junit.Test)

Example 55 with TestConsole

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();
}
Also used : TestConsole(com.facebook.buck.testutil.TestConsole) Before(org.junit.Before)

Aggregations

TestConsole (com.facebook.buck.testutil.TestConsole)100 Test (org.junit.Test)74 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)27 DefaultProcessExecutor (com.facebook.buck.util.DefaultProcessExecutor)27 ExecutionContext (com.facebook.buck.step.ExecutionContext)25 TestExecutionContext (com.facebook.buck.step.TestExecutionContext)25 Path (java.nio.file.Path)21 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)16 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)16 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)16 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)16 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)16 BuckEventBus (com.facebook.buck.event.BuckEventBus)15 FakeProcess (com.facebook.buck.util.FakeProcess)14 ProcessExecutor (com.facebook.buck.util.ProcessExecutor)13 ProcessExecutorParams (com.facebook.buck.util.ProcessExecutorParams)12 ProjectWorkspace (com.facebook.buck.testutil.integration.ProjectWorkspace)11 Clock (com.facebook.buck.timing.Clock)10 FakeProcessExecutor (com.facebook.buck.util.FakeProcessExecutor)9 BuildTarget (com.facebook.buck.model.BuildTarget)8