use of com.facebook.buck.io.FakeWatchmanClient in project buck by facebook.
the class WatchmanWatcherTest method watcherOverflowUpdatesClockId.
@Test
public void watcherOverflowUpdatesClockId() throws IOException, InterruptedException {
ImmutableMap<String, Object> watchmanOutput = ImmutableMap.<String, Object>of("clock", "c:1:0", "is_fresh_instance", true);
final Set<WatchEvent<?>> events = Sets.newHashSet();
EventBus eventBus = new EventBus("watchman test");
eventBus.register(new Object() {
@Subscribe
public void listen(WatchEvent<?> event) {
events.add(event);
}
});
WatchmanWatcher watcher = createWatcher(eventBus, new FakeWatchmanClient(0, /* queryElapsedTimeNanos */
ImmutableMap.of(FAKE_CLOCK_QUERY, watchmanOutput)), 10000, /* timeout */
"c:0:0");
assertThat(watcher.getWatchmanQuery(FAKE_ROOT), hasItem(hasEntry("since", "c:0:0")));
watcher.postEvents(BuckEventBusFactory.newInstance(new FakeClock(0)), WatchmanWatcher.FreshInstanceAction.POST_OVERFLOW_EVENT);
assertThat(watcher.getWatchmanQuery(FAKE_ROOT), hasItem(hasEntry("since", "c:1:0")));
boolean overflowSeen = false;
for (WatchEvent<?> event : events) {
overflowSeen |= event.kind().equals(StandardWatchEventKinds.OVERFLOW);
}
assertTrue(overflowSeen);
}
use of com.facebook.buck.io.FakeWatchmanClient 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.facebook.buck.io.FakeWatchmanClient 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.facebook.buck.io.FakeWatchmanClient in project buck by facebook.
the class WatchmanWatcherTest method whenWatchmanInterruptedThenOverflowEventGenerated.
@Test
public void whenWatchmanInterruptedThenOverflowEventGenerated() throws IOException, InterruptedException {
String message = "Boo!";
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 InterruptedException(message)), 10000);
try {
watcher.postEvents(BuckEventBusFactory.newInstance(new FakeClock(0)), WatchmanWatcher.FreshInstanceAction.NONE);
} catch (InterruptedException e) {
assertEquals("Should be test interruption.", e.getMessage(), message);
}
verify(eventBus);
assertTrue(Thread.currentThread().isInterrupted());
assertEquals("Should be overflow event.", StandardWatchEventKinds.OVERFLOW, eventCapture.getValue().kind());
}
Aggregations