Search in sources :

Example 6 with ConsoleEvent

use of com.facebook.buck.event.ConsoleEvent 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 7 with ConsoleEvent

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

the class SuperConsoleEventBusListener method createLogRenderLines.

/**
   * Adds log messages for rendering.
   */
@VisibleForTesting
ImmutableList<String> createLogRenderLines() {
    ImmutableList.Builder<String> logEventLinesBuilder = ImmutableList.builder();
    ConsoleEvent logEvent;
    while ((logEvent = logEvents.poll()) != null) {
        formatConsoleEvent(logEvent, logEventLinesBuilder);
        if (logEvent.getLevel().equals(Level.WARNING)) {
            anyWarningsPrinted.set(true);
        } else if (logEvent.getLevel().equals(Level.SEVERE)) {
            anyErrorsPrinted.set(true);
        }
    }
    return logEventLinesBuilder.build();
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) ConsoleEvent(com.facebook.buck.event.ConsoleEvent) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 8 with ConsoleEvent

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

the class ProjectBuildFileParserTest method whenSubprocessReturnsSyntaxErrorInDifferentFileThenExceptionContainsTwoFileNames.

@Test
public void whenSubprocessReturnsSyntaxErrorInDifferentFileThenExceptionContainsTwoFileNames() throws IOException, BuildFileParseException, InterruptedException {
    // This test depends on unix utilities that don't exist on Windows.
    assumeTrue(Platform.detect() != Platform.WINDOWS);
    TestProjectBuildFileParserFactory buildFileParserFactory = new TestProjectBuildFileParserFactory(cell.getRoot(), cell.getKnownBuildRuleTypes());
    BuckEventBus buckEventBus = BuckEventBusFactory.newInstance(new FakeClock(0));
    final List<ConsoleEvent> consoleEvents = new ArrayList<>();
    class EventListener {

        @Subscribe
        public void onConsoleEvent(ConsoleEvent consoleEvent) {
            consoleEvents.add(consoleEvent);
        }
    }
    EventListener eventListener = new EventListener();
    buckEventBus.register(eventListener);
    thrown.expect(BuildFileParseException.class);
    thrown.expectMessage("Parse error for build file foo/BUCK:\n" + "Syntax error in bar/BUCK\n" + "Line 42, column 24:\n" + "def some_helper_method(!@87*@!#\n" + "                       ^");
    try (ProjectBuildFileParser buildFileParser = buildFileParserFactory.createNoopParserThatAlwaysReturnsErrorWithException(buckEventBus, "This is an error", "parser", ImmutableMap.<String, Object>builder().put("type", "SyntaxError").put("value", "You messed up").put("filename", "bar/BUCK").put("lineno", 42).put("offset", 24).put("text", "def some_helper_method(!@87*@!#\n").put("traceback", ImmutableList.of(ImmutableMap.of("filename", "bar/BUCK", "line_number", 42, "function_name", "<module>", "text", "def some_helper_method(!@87*@!#\n"), ImmutableMap.of("filename", "foo/BUCK", "line_number", 23, "function_name", "<module>", "text", "some_helper_method(name=*@!&#(!@&*()\n"))).build())) {
        buildFileParser.initIfNeeded();
        buildFileParser.getAllRulesAndMetaRules(Paths.get("foo/BUCK"));
    }
}
Also used : BuckEventBus(com.facebook.buck.event.BuckEventBus) FakeClock(com.facebook.buck.timing.FakeClock) ProjectBuildFileParser(com.facebook.buck.json.ProjectBuildFileParser) ConsoleEvent(com.facebook.buck.event.ConsoleEvent) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 9 with ConsoleEvent

use of com.facebook.buck.event.ConsoleEvent 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 10 with ConsoleEvent

use of com.facebook.buck.event.ConsoleEvent 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)

Aggregations

ConsoleEvent (com.facebook.buck.event.ConsoleEvent)10 Test (org.junit.Test)8 BuckEventBus (com.facebook.buck.event.BuckEventBus)5 BuckEvent (com.facebook.buck.event.BuckEvent)4 ProjectBuildFileParser (com.facebook.buck.json.ProjectBuildFileParser)4 ExecutionContext (com.facebook.buck.step.ExecutionContext)4 TestExecutionContext (com.facebook.buck.step.TestExecutionContext)4 FakeClock (com.facebook.buck.timing.FakeClock)4 ArrayList (java.util.ArrayList)4 FakeBuckEventListener (com.facebook.buck.event.FakeBuckEventListener)3 IOException (java.io.IOException)2 LazyPath (com.facebook.buck.io.LazyPath)1 WatchmanDiagnosticEvent (com.facebook.buck.io.WatchmanDiagnosticEvent)1 BuildId (com.facebook.buck.model.BuildId)1 RuleKey (com.facebook.buck.rules.RuleKey)1 HttpResponse (com.facebook.buck.slb.HttpResponse)1 HttpService (com.facebook.buck.slb.HttpService)1 OkHttpResponseWrapper (com.facebook.buck.slb.OkHttpResponseWrapper)1 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)1 IncrementingFakeClock (com.facebook.buck.timing.IncrementingFakeClock)1