Search in sources :

Example 1 with WatchmanStatusEvent

use of com.facebook.buck.event.WatchmanStatusEvent in project buck by facebook.

the class MachineReadableLogJsonViewTest method testWatchmanEvents.

@Test
public void testWatchmanEvents() throws Exception {
    WatchmanStatusEvent createEvent = WatchmanStatusEvent.fileCreation("filename_new");
    WatchmanStatusEvent deleteEvent = WatchmanStatusEvent.fileDeletion("filename_del");
    WatchmanStatusEvent overflowEvent = WatchmanStatusEvent.overflow("reason");
    // Configure the events so timestamps etc are there.
    createEvent.configure(timestamp, nanoTime, threadUserNanoTime, threadId, buildId);
    deleteEvent.configure(timestamp, nanoTime, threadUserNanoTime, threadId, buildId);
    overflowEvent.configure(timestamp, nanoTime, threadUserNanoTime, threadId, buildId);
    assertJsonEquals("{%s,\"filename\":\"filename_new\"}", WRITER.writeValueAsString(createEvent));
    assertJsonEquals("{%s,\"filename\":\"filename_del\"}", WRITER.writeValueAsString(deleteEvent));
    assertJsonEquals("{%s,\"reason\":\"reason\"}", WRITER.writeValueAsString(overflowEvent));
}
Also used : WatchmanStatusEvent(com.facebook.buck.event.WatchmanStatusEvent) Test(org.junit.Test)

Example 2 with WatchmanStatusEvent

use of com.facebook.buck.event.WatchmanStatusEvent 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 3 with WatchmanStatusEvent

use of com.facebook.buck.event.WatchmanStatusEvent in project buck by facebook.

the class WatchmanWatcherTest method whenWatchmanReportsZeroFilesChangedThenPostEvent.

@Test
public void whenWatchmanReportsZeroFilesChangedThenPostEvent() throws IOException, InterruptedException {
    ImmutableMap<String, Object> watchmanOutput = ImmutableMap.of("files", ImmutableList.of());
    WatchmanWatcher watcher = createWatcher(new EventBus("watchman test"), watchmanOutput);
    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) {
        zeroFilesChangedSeen |= event.getEventName().equals("WatchmanZeroFileChanges");
    }
    assertTrue(zeroFilesChangedSeen);
}
Also used : BuckEventBus(com.facebook.buck.event.BuckEventBus) WatchmanStatusEvent(com.facebook.buck.event.WatchmanStatusEvent) FakeClock(com.facebook.buck.timing.FakeClock) EasyMock.anyObject(org.easymock.EasyMock.anyObject) BuckEventBus(com.facebook.buck.event.BuckEventBus) EventBus(com.google.common.eventbus.EventBus) Subscribe(com.google.common.eventbus.Subscribe) BuckEvent(com.facebook.buck.event.BuckEvent) Test(org.junit.Test)

Aggregations

WatchmanStatusEvent (com.facebook.buck.event.WatchmanStatusEvent)3 Test (org.junit.Test)3 BuckEvent (com.facebook.buck.event.BuckEvent)2 BuckEventBus (com.facebook.buck.event.BuckEventBus)2 FakeClock (com.facebook.buck.timing.FakeClock)2 EventBus (com.google.common.eventbus.EventBus)2 Subscribe (com.google.common.eventbus.Subscribe)2 EasyMock.anyObject (org.easymock.EasyMock.anyObject)2 FakeWatchmanClient (com.facebook.buck.io.FakeWatchmanClient)1 WatchmanCursor (com.facebook.buck.io.WatchmanCursor)1