use of com.facebook.buck.timing.FakeClock in project buck by facebook.
the class WatchmanWatcherIntegrationTest method ignoreDotFileInGlob.
@Test
public void ignoreDotFileInGlob() throws IOException, InterruptedException {
WatchmanWatcher watcher = createWatchmanWatcher(new PathOrGlobMatcher("**/*.swp"));
// Create a dot-file which should be ignored by the above glob.
Path path = tmp.getRoot().getFileSystem().getPath("foo/bar/.hello.swp");
Files.createDirectories(tmp.getRoot().resolve(path).getParent());
Files.write(tmp.getRoot().resolve(path), new byte[0]);
// Verify we don't get an event for the path.
watcher.postEvents(new BuckEventBus(new FakeClock(0), new BuildId()), WatchmanWatcher.FreshInstanceAction.NONE);
assertThat(watchmanEventCollector.getEvents(), Matchers.empty());
}
use of com.facebook.buck.timing.FakeClock 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.facebook.buck.timing.FakeClock 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.facebook.buck.timing.FakeClock 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.facebook.buck.timing.FakeClock 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