Search in sources :

Example 6 with FakeWatchmanClient

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

Example 7 with FakeWatchmanClient

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

Example 8 with FakeWatchmanClient

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());
}
Also used : FakeWatchmanClient(com.facebook.buck.io.FakeWatchmanClient) FakeClock(com.facebook.buck.timing.FakeClock) WatchEvent(java.nio.file.WatchEvent) BuckEventBus(com.facebook.buck.event.BuckEventBus) EventBus(com.google.common.eventbus.EventBus) IOException(java.io.IOException) Test(org.junit.Test)

Example 9 with FakeWatchmanClient

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());
}
Also used : FakeWatchmanClient(com.facebook.buck.io.FakeWatchmanClient) FakeClock(com.facebook.buck.timing.FakeClock) WatchEvent(java.nio.file.WatchEvent) BuckEventBus(com.facebook.buck.event.BuckEventBus) EventBus(com.google.common.eventbus.EventBus) Test(org.junit.Test)

Aggregations

FakeWatchmanClient (com.facebook.buck.io.FakeWatchmanClient)9 Test (org.junit.Test)9 BuckEventBus (com.facebook.buck.event.BuckEventBus)6 FakeClock (com.facebook.buck.timing.FakeClock)6 EventBus (com.google.common.eventbus.EventBus)6 WatchEvent (java.nio.file.WatchEvent)4 EasyMock.anyObject (org.easymock.EasyMock.anyObject)4 Watchman (com.facebook.buck.io.Watchman)3 Cell (com.facebook.buck.rules.Cell)3 TestCellBuilder (com.facebook.buck.rules.TestCellBuilder)3 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)3 Subscribe (com.google.common.eventbus.Subscribe)3 Path (java.nio.file.Path)3 IOException (java.io.IOException)2 BuckEvent (com.facebook.buck.event.BuckEvent)1 WatchmanStatusEvent (com.facebook.buck.event.WatchmanStatusEvent)1 WatchmanCursor (com.facebook.buck.io.WatchmanCursor)1