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));
}
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();
}
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"));
}
}
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)));
}
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));
}
Aggregations