use of com.google.common.eventbus.EventBus in project buck by facebook.
the class WatchmanWatcherTest method whenParseTimesOutThenOverflowGenerated.
@Test
public void whenParseTimesOutThenOverflowGenerated() throws IOException, InterruptedException {
ImmutableMap<String, Object> watchmanOutput = ImmutableMap.of("version", "2.9.2", "clock", "c:1386170113:26390:5:50273", "is_fresh_instance", true, "files", ImmutableList.of());
final Set<WatchEvent<?>> events = Sets.newHashSet();
EventBus bus = new EventBus("watchman test");
bus.register(new Object() {
@Subscribe
public void listen(WatchEvent<?> event) {
events.add(event);
}
});
WatchmanWatcher watcher = createWatcher(bus, new FakeWatchmanClient(10000000000L, /* queryElapsedTimeNanos */
ImmutableMap.of(FAKE_UUID_QUERY, watchmanOutput)), -1);
watcher.postEvents(BuckEventBusFactory.newInstance(new FakeClock(0)), WatchmanWatcher.FreshInstanceAction.NONE);
boolean overflowSeen = false;
for (WatchEvent<?> event : events) {
overflowSeen |= event.kind().equals(StandardWatchEventKinds.OVERFLOW);
}
assertTrue(overflowSeen);
}
use of com.google.common.eventbus.EventBus in project buck by facebook.
the class WatchmanWatcherTest method whenWatchmanInstanceIsFreshAndActionIsNoneThenCachesNotCleared.
@Test
public void whenWatchmanInstanceIsFreshAndActionIsNoneThenCachesNotCleared() throws IOException, InterruptedException {
ImmutableMap<String, Object> watchmanOutput = ImmutableMap.of("version", "2.9.2", "clock", "c:1386170113:26390:5:50273", "is_fresh_instance", true, "files", ImmutableList.of());
final Set<WatchEvent<?>> events = Sets.newHashSet();
EventBus bus = new EventBus("watchman test");
bus.register(new Object() {
@Subscribe
public void listen(WatchEvent<?> event) {
events.add(event);
}
});
WatchmanWatcher watcher = createWatcher(bus, watchmanOutput);
watcher.postEvents(BuckEventBusFactory.newInstance(new FakeClock(0)), WatchmanWatcher.FreshInstanceAction.NONE);
boolean overflowSeen = false;
for (WatchEvent<?> event : events) {
overflowSeen |= event.kind().equals(StandardWatchEventKinds.OVERFLOW);
}
assertFalse(overflowSeen);
}
use of com.google.common.eventbus.EventBus in project buck by facebook.
the class WatchmanWatcherTest method whenWatchmanFailsThenOverflowEventGenerated.
@Test
public void whenWatchmanFailsThenOverflowEventGenerated() throws IOException, InterruptedException {
Capture<WatchEvent<Path>> eventCapture = newCapture();
EventBus eventBus = createStrictMock(EventBus.class);
eventBus.post(capture(eventCapture));
replay(eventBus);
WatchmanWatcher watcher = createWatcher(eventBus, new FakeWatchmanClient(0, /* queryElapsedTimeNanos */
ImmutableMap.of(FAKE_UUID_QUERY, ImmutableMap.of()), new IOException("oops")), 10000);
try {
watcher.postEvents(BuckEventBusFactory.newInstance(new FakeClock(0)), WatchmanWatcher.FreshInstanceAction.NONE);
fail("Should have thrown IOException.");
} catch (IOException e) {
assertTrue("Should be expected error", e.getMessage().startsWith("oops"));
}
verify(eventBus);
assertEquals("Should be overflow event.", StandardWatchEventKinds.OVERFLOW, eventCapture.getValue().kind());
}
use of com.google.common.eventbus.EventBus in project buck by facebook.
the class WatchmanWatcherTest method whenQueryResultContainsErrorThenOverflowEventGenerated.
@Test(expected = WatchmanWatcherException.class)
public void whenQueryResultContainsErrorThenOverflowEventGenerated() throws IOException, InterruptedException {
ImmutableMap<String, Object> watchmanOutput = ImmutableMap.of("version", "2.9.2", "error", "Watch does not exist.");
Capture<WatchEvent<Path>> eventCapture = newCapture();
EventBus eventBus = createStrictMock(EventBus.class);
eventBus.post(capture(eventCapture));
replay(eventBus);
WatchmanWatcher watcher = createWatcher(eventBus, watchmanOutput);
try {
watcher.postEvents(BuckEventBusFactory.newInstance(new FakeClock(0)), WatchmanWatcher.FreshInstanceAction.NONE);
} finally {
assertEquals("Should be overflow event.", StandardWatchEventKinds.OVERFLOW, eventCapture.getValue().kind());
}
}
use of com.google.common.eventbus.EventBus in project buck by facebook.
the class WatchmanWatcherTest method whenWatchmanInstanceIsFreshAndActionIsPostThenAllCachesAreCleared.
@Test
public void whenWatchmanInstanceIsFreshAndActionIsPostThenAllCachesAreCleared() throws IOException, InterruptedException {
ImmutableMap<String, Object> watchmanOutput = ImmutableMap.of("version", "2.9.2", "clock", "c:1386170113:26390:5:50273", "is_fresh_instance", true, "files", ImmutableList.of());
final Set<WatchEvent<?>> events = Sets.newHashSet();
EventBus bus = new EventBus("watchman test");
bus.register(new Object() {
@Subscribe
public void listen(WatchEvent<?> event) {
events.add(event);
}
});
WatchmanWatcher watcher = createWatcher(bus, watchmanOutput);
watcher.postEvents(BuckEventBusFactory.newInstance(new FakeClock(0)), WatchmanWatcher.FreshInstanceAction.POST_OVERFLOW_EVENT);
boolean overflowSeen = false;
for (WatchEvent<?> event : events) {
overflowSeen |= event.kind().equals(StandardWatchEventKinds.OVERFLOW);
}
assertTrue(overflowSeen);
}
Aggregations