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);
}
use of com.google.common.eventbus.EventBus in project buck by facebook.
the class WatchmanWatcherTest method whenWatchmanProducesAWarningThenDiagnosticEventGenerated.
@Test
public void whenWatchmanProducesAWarningThenDiagnosticEventGenerated() throws IOException, InterruptedException {
String message = "Find me!";
ImmutableMap<String, Object> watchmanOutput = ImmutableMap.of("files", ImmutableList.of(), "warning", message);
Capture<WatchmanDiagnosticEvent> eventCapture = newCapture();
EventBus eventBus = new EventBus("watchman test");
BuckEventBus buckEventBus = createStrictMock(BuckEventBus.class);
buckEventBus.post(capture(eventCapture));
replay(buckEventBus);
WatchmanWatcher watcher = createWatcher(eventBus, watchmanOutput);
watcher.postEvents(buckEventBus, WatchmanWatcher.FreshInstanceAction.NONE);
verify(buckEventBus);
assertThat(eventCapture.getValue().getDiagnostic().getMessage(), Matchers.containsString(message));
}
use of com.google.common.eventbus.EventBus in project buck by facebook.
the class WatchmanWatcherTest method whenWatchmanProducesAWarningThenOverflowEventNotGenerated.
@Test
public void whenWatchmanProducesAWarningThenOverflowEventNotGenerated() throws IOException, InterruptedException {
ImmutableMap<String, Object> watchmanOutput = ImmutableMap.of("files", ImmutableList.of(), "warning", "message");
EventBus eventBus = createStrictMock(EventBus.class);
replay(eventBus);
WatchmanWatcher watcher = createWatcher(eventBus, watchmanOutput);
watcher.postEvents(BuckEventBusFactory.newInstance(new FakeClock(0)), WatchmanWatcher.FreshInstanceAction.NONE);
verify(eventBus);
}
Aggregations