Search in sources :

Example 1 with WatchmanCursor

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);
}
Also used : BuckEventBus(com.facebook.buck.event.BuckEventBus) FakeWatchmanClient(com.facebook.buck.io.FakeWatchmanClient) WatchmanStatusEvent(com.facebook.buck.event.WatchmanStatusEvent) FakeClock(com.facebook.buck.timing.FakeClock) WatchmanCursor(com.facebook.buck.io.WatchmanCursor) BuckEventBus(com.facebook.buck.event.BuckEventBus) EventBus(com.google.common.eventbus.EventBus) Subscribe(com.google.common.eventbus.Subscribe) BuckEvent(com.facebook.buck.event.BuckEvent) EasyMock.anyObject(org.easymock.EasyMock.anyObject) Test(org.junit.Test)

Example 2 with WatchmanCursor

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());
    }
}
Also used : Path(java.nio.file.Path) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) WatchmanQuery(com.facebook.buck.io.WatchmanQuery) WatchmanCursor(com.facebook.buck.io.WatchmanCursor)

Example 3 with WatchmanCursor

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;
}
Also used : BuckEventBus(com.facebook.buck.event.BuckEventBus) BuildId(com.facebook.buck.model.BuildId) FakeClock(com.facebook.buck.timing.FakeClock) WatchmanCursor(com.facebook.buck.io.WatchmanCursor)

Aggregations

WatchmanCursor (com.facebook.buck.io.WatchmanCursor)3 BuckEventBus (com.facebook.buck.event.BuckEventBus)2 FakeClock (com.facebook.buck.timing.FakeClock)2 BuckEvent (com.facebook.buck.event.BuckEvent)1 WatchmanStatusEvent (com.facebook.buck.event.WatchmanStatusEvent)1 FakeWatchmanClient (com.facebook.buck.io.FakeWatchmanClient)1 WatchmanQuery (com.facebook.buck.io.WatchmanQuery)1 BuildId (com.facebook.buck.model.BuildId)1 EventBus (com.google.common.eventbus.EventBus)1 Subscribe (com.google.common.eventbus.Subscribe)1 Path (java.nio.file.Path)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 EasyMock.anyObject (org.easymock.EasyMock.anyObject)1 Test (org.junit.Test)1