use of com.facebook.buck.event.ConsoleEvent in project buck by facebook.
the class HttpArtifactCacheTest method errorTextReplaced.
@Test
public void errorTextReplaced() throws InterruptedException {
FakeProjectFilesystem filesystem = new FakeProjectFilesystem();
final String cacheName = "http cache";
final RuleKey ruleKey = new RuleKey("00000000000000000000000000000000");
final RuleKey otherRuleKey = new RuleKey("11111111111111111111111111111111");
final String data = "data";
final AtomicBoolean consoleEventReceived = new AtomicBoolean(false);
argsBuilder.setCacheName(cacheName).setProjectFilesystem(filesystem).setBuckEventBus(new BuckEventBus(new IncrementingFakeClock(), new BuildId()) {
@Override
public void post(BuckEvent event) {
if (event instanceof ConsoleEvent) {
consoleEventReceived.set(true);
ConsoleEvent consoleEvent = (ConsoleEvent) event;
assertThat(consoleEvent.getMessage(), Matchers.containsString(cacheName));
assertThat(consoleEvent.getMessage(), Matchers.containsString("incorrect key name"));
}
}
}).setFetchClient(withMakeRequest((path, requestBuilder) -> {
Request request = requestBuilder.url(SERVER + path).build();
Response response = new Response.Builder().request(request).protocol(Protocol.HTTP_1_1).code(HttpURLConnection.HTTP_OK).body(createResponseBody(ImmutableSet.of(otherRuleKey), ImmutableMap.of(), ByteSource.wrap(data.getBytes(Charsets.UTF_8)), data)).build();
return new OkHttpResponseWrapper(response);
}));
HttpArtifactCache cache = new HttpArtifactCache(argsBuilder.build());
Path output = Paths.get("output/file");
CacheResult result = cache.fetch(ruleKey, LazyPath.ofInstance(output));
assertEquals(CacheResultType.ERROR, result.getType());
assertEquals(Optional.empty(), filesystem.readFileIfItExists(output));
assertTrue(consoleEventReceived.get());
cache.close();
}
use of com.facebook.buck.event.ConsoleEvent in project buck by facebook.
the class ProjectBuildFileParserTest method whenSubprocessReturnsWarningThenConsoleEventPublished.
@Test
public void whenSubprocessReturnsWarningThenConsoleEventPublished() 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<>();
final List<WatchmanDiagnosticEvent> watchmanDiagnosticEvents = new ArrayList<>();
class EventListener {
@Subscribe
public void on(ConsoleEvent consoleEvent) {
consoleEvents.add(consoleEvent);
}
@Subscribe
public void on(WatchmanDiagnosticEvent event) {
watchmanDiagnosticEvents.add(event);
}
}
EventListener eventListener = new EventListener();
buckEventBus.register(eventListener);
try (ProjectBuildFileParser buildFileParser = buildFileParserFactory.createNoopParserThatAlwaysReturnsSuccessWithWarning(buckEventBus, "This is a warning", "parser")) {
buildFileParser.initIfNeeded();
buildFileParser.getAllRulesAndMetaRules(Paths.get("foo"));
}
assertThat(consoleEvents, Matchers.contains(Matchers.hasToString("Warning raised by BUCK file parser: This is a warning")));
assertThat("Should not receive any watchman diagnostic events", watchmanDiagnosticEvents, Matchers.empty());
}
use of com.facebook.buck.event.ConsoleEvent in project buck by facebook.
the class ProjectBuildFileParserTest method whenSubprocessPrintsWarningToStderrThenConsoleEventPublished.
@Test
public void whenSubprocessPrintsWarningToStderrThenConsoleEventPublished() 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);
try (ProjectBuildFileParser buildFileParser = buildFileParserFactory.createNoopParserThatAlwaysReturnsSuccessAndPrintsToStderr(buckEventBus)) {
buildFileParser.initIfNeeded();
buildFileParser.getAllRulesAndMetaRules(Paths.get("foo"));
}
assertThat(consoleEvents, Matchers.contains(Matchers.hasToString("Warning raised by BUCK file parser: Don't Panic!")));
}
use of com.facebook.buck.event.ConsoleEvent in project buck by facebook.
the class ProjectBuildFileParserTest method whenSubprocessReturnsErrorThenConsoleEventPublished.
@Test
public void whenSubprocessReturnsErrorThenConsoleEventPublished() 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);
try (ProjectBuildFileParser buildFileParser = buildFileParserFactory.createNoopParserThatAlwaysReturnsSuccessWithError(buckEventBus, "This is an error", "parser")) {
buildFileParser.initIfNeeded();
buildFileParser.getAllRulesAndMetaRules(Paths.get("foo"));
}
assertThat(consoleEvents, Matchers.contains(Matchers.hasToString("Error raised by BUCK file parser: This is an error")));
}
use of com.facebook.buck.event.ConsoleEvent in project buck by facebook.
the class ShellStepTest method createContext.
private static ExecutionContext createContext(ImmutableMap<ProcessExecutorParams, FakeProcess> processes, final Console console) throws IOException {
ExecutionContext context = TestExecutionContext.newBuilder().setConsole(console).setProcessExecutor(new FakeProcessExecutor(processes, console)).build();
context.getBuckEventBus().register(new Object() {
@Subscribe
public void logEvent(ConsoleEvent event) throws IOException {
if (event.getLevel().equals(Level.WARNING)) {
console.getStdErr().write(event.getMessage().getBytes(Charsets.UTF_8));
}
}
});
return context;
}
Aggregations