Search in sources :

Example 1 with FakeBuckEventListener

use of com.facebook.buck.event.FakeBuckEventListener in project buck by facebook.

the class WorkerShellStepTest method testStdErrIsPrintedAsErrorIfJobFails.

@Test
public void testStdErrIsPrintedAsErrorIfJobFails() throws IOException, InterruptedException {
    String stderr = "my stderr";
    ExecutionContext context = createExecutionContextWith(1, "", stderr);
    WorkerShellStep step = createWorkerShellStep(createJobParams(ImmutableList.of(startupCommand), startupArgs, ImmutableMap.of(), "myJobArgs"), null, null);
    FakeBuckEventListener listener = new FakeBuckEventListener();
    context.getBuckEventBus().register(listener);
    int exitCode = step.execute(context).getExitCode();
    assertThat(exitCode, Matchers.equalTo(1));
    // assert that the job's stderr was written to the console as error, not as warning
    BuckEvent firstEvent = listener.getEvents().get(0);
    assertTrue(firstEvent instanceof ConsoleEvent);
    assertThat(((ConsoleEvent) firstEvent).getLevel(), Matchers.is(Level.SEVERE));
    assertThat(((ConsoleEvent) firstEvent).getMessage(), Matchers.is(stderr));
}
Also used : ExecutionContext(com.facebook.buck.step.ExecutionContext) TestExecutionContext(com.facebook.buck.step.TestExecutionContext) ConsoleEvent(com.facebook.buck.event.ConsoleEvent) FakeBuckEventListener(com.facebook.buck.event.FakeBuckEventListener) BuckEvent(com.facebook.buck.event.BuckEvent) Test(org.junit.Test)

Example 2 with FakeBuckEventListener

use of com.facebook.buck.event.FakeBuckEventListener in project buck by facebook.

the class ParserTest method testParseBuildFilesForTargetsWithOverlappingTargets.

@Test
@SuppressWarnings("unchecked")
public void testParseBuildFilesForTargetsWithOverlappingTargets() throws Exception {
    // Execute buildTargetGraphForBuildTargets() with multiple targets that require parsing the same
    // build file.
    BuildTarget fooTarget = BuildTarget.builder(cellRoot, "//java/com/facebook", "foo").build();
    BuildTarget barTarget = BuildTarget.builder(cellRoot, "//java/com/facebook", "bar").build();
    Iterable<BuildTarget> buildTargets = ImmutableList.of(fooTarget, barTarget);
    // The EventBus should be updated with events indicating how parsing ran.
    FakeBuckEventListener listener = new FakeBuckEventListener();
    eventBus.register(listener);
    TargetGraph targetGraph = parser.buildTargetGraph(eventBus, cell, false, executorService, buildTargets);
    BuildRuleResolver resolver = buildActionGraph(eventBus, targetGraph);
    BuildRule fooRule = resolver.requireRule(fooTarget);
    assertNotNull(fooRule);
    BuildRule barRule = resolver.requireRule(barTarget);
    assertNotNull(barRule);
    Iterable<ParseEvent> events = Iterables.filter(listener.getEvents(), ParseEvent.class);
    assertThat(events, Matchers.contains(Matchers.hasProperty("buildTargets", equalTo(buildTargets)), Matchers.allOf(Matchers.hasProperty("buildTargets", equalTo(buildTargets)), Matchers.hasProperty("graph", equalTo(Optional.of(targetGraph))))));
}
Also used : BuildTarget(com.facebook.buck.model.BuildTarget) UnflavoredBuildTarget(com.facebook.buck.model.UnflavoredBuildTarget) BuildRule(com.facebook.buck.rules.BuildRule) TargetGraph(com.facebook.buck.rules.TargetGraph) FakeBuckEventListener(com.facebook.buck.event.FakeBuckEventListener) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) Test(org.junit.Test)

Example 3 with FakeBuckEventListener

use of com.facebook.buck.event.FakeBuckEventListener in project buck by facebook.

the class WorkerShellStepTest method testWarningIsPrintedForIdenticalWorkerToolsWithDifferentCapacity.

@Test
public void testWarningIsPrintedForIdenticalWorkerToolsWithDifferentCapacity() throws InterruptedException {
    int existingPoolSize = 2;
    int stepPoolSize = 4;
    ExecutionContext context = createExecutionContextWith(ImmutableMap.of("jobArgs", WorkerJobResult.of(0, Optional.of(""), Optional.of(""))), existingPoolSize);
    FakeBuckEventListener listener = new FakeBuckEventListener();
    context.getBuckEventBus().register(listener);
    WorkerJobParams params = createJobParams(ImmutableList.of(startupCommand), startupArgs, ImmutableMap.of(), "jobArgs", stepPoolSize);
    WorkerShellStep step = createWorkerShellStep(params, null, null);
    step.execute(context);
    BuckEvent firstEvent = listener.getEvents().get(0);
    assertThat(firstEvent, Matchers.instanceOf(ConsoleEvent.class));
    ConsoleEvent consoleEvent = (ConsoleEvent) firstEvent;
    assertThat(consoleEvent.getLevel(), Matchers.is(Level.WARNING));
    assertThat(consoleEvent.getMessage(), Matchers.is(String.format("There are two 'worker_tool' targets declared with the same command (%s), but different " + "'max_worker' settings (%d and %d). Only the first capacity is applied. Consolidate " + "these workers to avoid this warning.", fakeWorkerStartupCommand, existingPoolSize, stepPoolSize)));
}
Also used : ExecutionContext(com.facebook.buck.step.ExecutionContext) TestExecutionContext(com.facebook.buck.step.TestExecutionContext) ConsoleEvent(com.facebook.buck.event.ConsoleEvent) FakeBuckEventListener(com.facebook.buck.event.FakeBuckEventListener) BuckEvent(com.facebook.buck.event.BuckEvent) Test(org.junit.Test)

Example 4 with FakeBuckEventListener

use of com.facebook.buck.event.FakeBuckEventListener in project buck by facebook.

the class WorkerShellStepTest method testJobIsExecutedAndResultIsReceived.

@Test
public void testJobIsExecutedAndResultIsReceived() throws IOException, InterruptedException {
    String stdout = "my stdout";
    String stderr = "my stderr";
    ExecutionContext context = createExecutionContextWith(0, stdout, stderr);
    WorkerShellStep step = createWorkerShellStep(createJobParams(ImmutableList.of(startupCommand), startupArgs, ImmutableMap.of(), "myJobArgs"), null, null);
    FakeBuckEventListener listener = new FakeBuckEventListener();
    context.getBuckEventBus().register(listener);
    int exitCode = step.execute(context).getExitCode();
    assertThat(exitCode, Matchers.equalTo(0));
    // assert that the job's stdout and stderr were written to the console
    BuckEvent firstEvent = listener.getEvents().get(0);
    assertTrue(firstEvent instanceof ConsoleEvent);
    assertThat(((ConsoleEvent) firstEvent).getLevel(), Matchers.is(Level.INFO));
    assertThat(((ConsoleEvent) firstEvent).getMessage(), Matchers.is(stdout));
    BuckEvent secondEvent = listener.getEvents().get(1);
    assertTrue(secondEvent instanceof ConsoleEvent);
    assertThat(((ConsoleEvent) secondEvent).getLevel(), Matchers.is(Level.WARNING));
    assertThat(((ConsoleEvent) secondEvent).getMessage(), Matchers.is(stderr));
}
Also used : ExecutionContext(com.facebook.buck.step.ExecutionContext) TestExecutionContext(com.facebook.buck.step.TestExecutionContext) ConsoleEvent(com.facebook.buck.event.ConsoleEvent) FakeBuckEventListener(com.facebook.buck.event.FakeBuckEventListener) BuckEvent(com.facebook.buck.event.BuckEvent) Test(org.junit.Test)

Example 5 with FakeBuckEventListener

use of com.facebook.buck.event.FakeBuckEventListener in project buck by facebook.

the class DefaultStepRunnerTest method testEventsFired.

@Test
public void testEventsFired() throws StepFailedException, InterruptedException, IOException {
    Step passingStep = new FakeStep("step1", "fake step 1", 0);
    Step failingStep = new FakeStep("step1", "fake step 1", 1);
    // The EventBus should be updated with events indicating how the steps were run.
    BuckEventBus eventBus = BuckEventBusFactory.newInstance();
    FakeBuckEventListener listener = new FakeBuckEventListener();
    eventBus.register(listener);
    ExecutionContext context = TestExecutionContext.newBuilder().setBuckEventBus(eventBus).build();
    DefaultStepRunner runner = new DefaultStepRunner();
    runner.runStepForBuildTarget(context, passingStep, Optional.empty());
    try {
        runner.runStepForBuildTarget(context, failingStep, Optional.empty());
        fail("Failing step should have thrown an exception");
    } catch (StepFailedException e) {
        assertEquals(e.getStep(), failingStep);
    }
    ImmutableList<StepEvent> events = FluentIterable.from(listener.getEvents()).filter(StepEvent.class).toList();
    assertEquals(4, events.size());
    assertTrue(events.get(0) instanceof StepEvent.Started);
    assertEquals(events.get(0).getShortStepName(), "step1");
    assertEquals(events.get(0).getDescription(), "fake step 1");
    assertTrue(events.get(1) instanceof StepEvent.Finished);
    assertEquals(events.get(1).getShortStepName(), "step1");
    assertEquals(events.get(1).getDescription(), "fake step 1");
    assertTrue(events.get(2) instanceof StepEvent.Started);
    assertEquals(events.get(2).getShortStepName(), "step1");
    assertEquals(events.get(2).getDescription(), "fake step 1");
    assertTrue(events.get(3) instanceof StepEvent.Finished);
    assertEquals(events.get(3).getShortStepName(), "step1");
    assertEquals(events.get(3).getDescription(), "fake step 1");
    assertTrue(events.get(0).isRelatedTo(events.get(1)));
    assertTrue(events.get(2).isRelatedTo(events.get(3)));
    assertFalse(events.get(0).isRelatedTo(events.get(2)));
    assertFalse(events.get(0).isRelatedTo(events.get(3)));
    assertFalse(events.get(1).isRelatedTo(events.get(2)));
    assertFalse(events.get(1).isRelatedTo(events.get(3)));
}
Also used : BuckEventBus(com.facebook.buck.event.BuckEventBus) FakeBuckEventListener(com.facebook.buck.event.FakeBuckEventListener) Test(org.junit.Test)

Aggregations

FakeBuckEventListener (com.facebook.buck.event.FakeBuckEventListener)5 Test (org.junit.Test)5 BuckEvent (com.facebook.buck.event.BuckEvent)3 ConsoleEvent (com.facebook.buck.event.ConsoleEvent)3 ExecutionContext (com.facebook.buck.step.ExecutionContext)3 TestExecutionContext (com.facebook.buck.step.TestExecutionContext)3 BuckEventBus (com.facebook.buck.event.BuckEventBus)1 BuildTarget (com.facebook.buck.model.BuildTarget)1 UnflavoredBuildTarget (com.facebook.buck.model.UnflavoredBuildTarget)1 BuildRule (com.facebook.buck.rules.BuildRule)1 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)1 TargetGraph (com.facebook.buck.rules.TargetGraph)1