use of com.google.common.eventbus.EventBus in project bazel by bazelbuild.
the class SkylarkJavaLiteProtoLibraryTest method testJavaProtosExposeSkylarkProviders.
/**
* Verify that a java_lite_proto_library exposes Skylark providers for the Java code it generates.
*/
@Test
public void testJavaProtosExposeSkylarkProviders() throws Exception {
scratch.file("proto/extensions.bzl", "def _impl(ctx):", " print (ctx.attr.dep[java_common.provider])", "custom_rule = rule(", " implementation=_impl,", " attrs={", " 'dep': attr.label()", " },", ")");
scratch.file("proto/BUILD", "load('/proto/extensions', 'custom_rule')", "load('//tools/build_rules/java_lite_proto_library:java_lite_proto_library.bzl',", " 'java_lite_proto_library')", "proto_library(", " name = 'proto',", " srcs = [ 'file.proto' ],", ")", "java_lite_proto_library(name = 'lite_pb2', deps = [':proto'])", "custom_rule(name = 'custom', dep = ':lite_pb2')");
update(ImmutableList.of("//proto:custom"), false, /* keepGoing */
1, /* loadingPhaseThreads */
true, /* doAnalysis */
new EventBus());
// Implicitly check that `update()` above didn't throw an exception. This implicitly checks that
// ctx.attr.dep.java.{transitive_deps, outputs}, above, is defined.
}
use of com.google.common.eventbus.EventBus in project buck by facebook.
the class WatchmanWatcherTest method whenExistsIsFalseThenDeleteEventIsGenerated.
@Test
public void whenExistsIsFalseThenDeleteEventIsGenerated() throws IOException, InterruptedException {
ImmutableMap<String, Object> watchmanOutput = ImmutableMap.of("files", ImmutableList.of(ImmutableMap.<String, Object>of("name", "foo/bar/baz", "exists", false)));
Capture<WatchEvent<Path>> eventCapture = newCapture();
EventBus eventBus = createStrictMock(EventBus.class);
eventBus.post(capture(eventCapture));
replay(eventBus);
WatchmanWatcher watcher = createWatcher(eventBus, watchmanOutput);
watcher.postEvents(BuckEventBusFactory.newInstance(new FakeClock(0)), WatchmanWatcher.FreshInstanceAction.NONE);
verify(eventBus);
assertEquals("Should be delete event.", StandardWatchEventKinds.ENTRY_DELETE, eventCapture.getValue().kind());
}
use of com.google.common.eventbus.EventBus in project buck by facebook.
the class WatchmanWatcherTest method whenQueryResultContainsErrorThenHumanReadableExceptionThrown.
@Test
public void whenQueryResultContainsErrorThenHumanReadableExceptionThrown() throws IOException, InterruptedException {
String watchmanError = "Watch does not exist.";
ImmutableMap<String, Object> watchmanOutput = ImmutableMap.of("version", "2.9.2", "error", watchmanError);
EventBus eventBus = createStrictMock(EventBus.class);
eventBus.post(anyObject());
replay(eventBus);
WatchmanWatcher watcher = createWatcher(eventBus, watchmanOutput);
try {
watcher.postEvents(BuckEventBusFactory.newInstance(new FakeClock(0)), WatchmanWatcher.FreshInstanceAction.NONE);
fail("Should have thrown RuntimeException");
} catch (RuntimeException e) {
assertThat("Should contain watchman error.", e.getMessage(), Matchers.containsString(watchmanError));
}
}
use of com.google.common.eventbus.EventBus in project buck by facebook.
the class WatchmanWatcherTest method whenNameThenModifyEventIsGenerated.
@Test
public void whenNameThenModifyEventIsGenerated() throws IOException, InterruptedException {
ImmutableMap<String, Object> watchmanOutput = ImmutableMap.of("files", ImmutableList.of(ImmutableMap.<String, Object>of("name", "foo/bar/baz")));
Capture<WatchEvent<Path>> eventCapture = newCapture();
EventBus eventBus = createStrictMock(EventBus.class);
eventBus.post(capture(eventCapture));
replay(eventBus);
WatchmanWatcher watcher = createWatcher(eventBus, watchmanOutput);
watcher.postEvents(BuckEventBusFactory.newInstance(new FakeClock(0)), WatchmanWatcher.FreshInstanceAction.NONE);
verify(eventBus);
assertEquals("Should be modify event.", StandardWatchEventKinds.ENTRY_MODIFY, eventCapture.getValue().kind());
assertEquals("Path should match watchman output.", MorePaths.pathWithPlatformSeparators("foo/bar/baz"), eventCapture.getValue().context().toString());
}
use of com.google.common.eventbus.EventBus in project buck by facebook.
the class WatchmanWatcherTest method whenWatchmanCellReportsFilesChangedThenPostEvent.
@Test
public void whenWatchmanCellReportsFilesChangedThenPostEvent() throws IOException, InterruptedException {
ImmutableMap<String, Object> watchmanRootOutput = ImmutableMap.of("files", ImmutableList.of());
ImmutableMap<String, Object> watchmanSecondaryOutput = ImmutableMap.of("files", ImmutableList.of(ImmutableMap.<String, Object>of("name", "foo/bar/baz")));
WatchmanWatcher watcher = new WatchmanWatcher(new EventBus("watchman test"), new FakeWatchmanClient(0, ImmutableMap.of(FAKE_CLOCK_QUERY, watchmanRootOutput, FAKE_SECONDARY_QUERY.toList("c:0:0"), watchmanSecondaryOutput)), 10000, ImmutableMap.of(FAKE_ROOT, FAKE_QUERY, FAKE_SECONDARY_ROOT, FAKE_SECONDARY_QUERY), ImmutableMap.of(FAKE_ROOT, new WatchmanCursor("c:0:0"), FAKE_SECONDARY_ROOT, new WatchmanCursor("c:0:0")));
final Set<BuckEvent> events = Sets.newHashSet();
BuckEventBus bus = BuckEventBusFactory.newInstance(new FakeClock(0));
bus.register(new Object() {
@Subscribe
public void listen(WatchmanStatusEvent event) {
events.add(event);
}
});
watcher.postEvents(bus, WatchmanWatcher.FreshInstanceAction.POST_OVERFLOW_EVENT);
boolean zeroFilesChangedSeen = false;
System.err.println(String.format("Events: %d", events.size()));
for (BuckEvent event : events) {
System.err.println(String.format("Event: %s", event));
zeroFilesChangedSeen |= event.getEventName().equals("WatchmanZeroFileChanges");
}
assertFalse(zeroFilesChangedSeen);
}
Aggregations