use of com.facebook.buck.io.WatchmanCursor 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.io.WatchmanCursor in project buck by facebook.
the class WatchmanWatcher method postEvents.
/**
* Query Watchman for file change events. If too many events are pending or an error occurs
* an overflow event is posted to the EventBus signalling that events may have been lost
* (and so typically caches must be cleared to avoid inconsistency). Interruptions and
* IOExceptions are propagated to callers, but typically if overflow events are handled
* conservatively by subscribers then no other remedial action is required.
*
* Any diagnostics posted by Watchman are added to watchmanDiagnosticCache.
*/
public void postEvents(BuckEventBus buckEventBus, FreshInstanceAction freshInstanceAction) throws IOException, InterruptedException {
// Speculatively set to false
AtomicBoolean filesHaveChanged = new AtomicBoolean(false);
for (Path cellPath : queries.keySet()) {
WatchmanQuery query = queries.get(cellPath);
WatchmanCursor cursor = cursors.get(cellPath);
if (query != null && cursor != null) {
postEvents(buckEventBus, freshInstanceAction, query, cursor, filesHaveChanged);
}
}
if (!filesHaveChanged.get()) {
buckEventBus.post(WatchmanStatusEvent.zeroFileChanges());
}
}
use of com.facebook.buck.io.WatchmanCursor in project buck by facebook.
the class WatchmanWatcherIntegrationTest method createWatchmanWatcher.
// Create a watcher for the given ignore paths, clearing the initial overflow event before
// returning it.
private WatchmanWatcher createWatchmanWatcher(PathOrGlobMatcher... ignorePaths) throws IOException, InterruptedException {
WatchmanWatcher watcher = new WatchmanWatcher(ImmutableMap.of(tmp.getRoot(), ProjectWatch.of(tmp.getRoot().toString(), Optional.empty())), eventBus, ImmutableSet.copyOf(ignorePaths), watchman, ImmutableMap.of(tmp.getRoot(), new WatchmanCursor(new StringBuilder("n:buckd").append(UUID.randomUUID()).toString())));
// Clear out the initial overflow event.
watcher.postEvents(new BuckEventBus(new FakeClock(0), new BuildId()), WatchmanWatcher.FreshInstanceAction.NONE);
watchmanEventCollector.clear();
return watcher;
}
Aggregations