Search in sources :

Example 46 with FakeClock

use of com.facebook.buck.timing.FakeClock in project buck by facebook.

the class WatchmanWatcherTest method whenWatchmanInstanceIsFreshAndActionIsNoneThenCachesNotCleared.

@Test
public void whenWatchmanInstanceIsFreshAndActionIsNoneThenCachesNotCleared() 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, watchmanOutput);
    watcher.postEvents(BuckEventBusFactory.newInstance(new FakeClock(0)), WatchmanWatcher.FreshInstanceAction.NONE);
    boolean overflowSeen = false;
    for (WatchEvent<?> event : events) {
        overflowSeen |= event.kind().equals(StandardWatchEventKinds.OVERFLOW);
    }
    assertFalse(overflowSeen);
}
Also used : 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 47 with FakeClock

use of com.facebook.buck.timing.FakeClock 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 48 with FakeClock

use of com.facebook.buck.timing.FakeClock in project buck by facebook.

the class WatchmanWatcherTest method whenQueryResultContainsErrorThenOverflowEventGenerated.

@Test(expected = WatchmanWatcherException.class)
public void whenQueryResultContainsErrorThenOverflowEventGenerated() throws IOException, InterruptedException {
    ImmutableMap<String, Object> watchmanOutput = ImmutableMap.of("version", "2.9.2", "error", "Watch does not exist.");
    Capture<WatchEvent<Path>> eventCapture = newCapture();
    EventBus eventBus = createStrictMock(EventBus.class);
    eventBus.post(capture(eventCapture));
    replay(eventBus);
    WatchmanWatcher watcher = createWatcher(eventBus, watchmanOutput);
    try {
        watcher.postEvents(BuckEventBusFactory.newInstance(new FakeClock(0)), WatchmanWatcher.FreshInstanceAction.NONE);
    } finally {
        assertEquals("Should be overflow event.", StandardWatchEventKinds.OVERFLOW, eventCapture.getValue().kind());
    }
}
Also used : 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) Test(org.junit.Test)

Example 49 with FakeClock

use of com.facebook.buck.timing.FakeClock in project buck by facebook.

the class WatchmanWatcherTest method whenWatchmanInstanceIsFreshAndActionIsPostThenAllCachesAreCleared.

@Test
public void whenWatchmanInstanceIsFreshAndActionIsPostThenAllCachesAreCleared() 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, watchmanOutput);
    watcher.postEvents(BuckEventBusFactory.newInstance(new FakeClock(0)), WatchmanWatcher.FreshInstanceAction.POST_OVERFLOW_EVENT);
    boolean overflowSeen = false;
    for (WatchEvent<?> event : events) {
        overflowSeen |= event.kind().equals(StandardWatchEventKinds.OVERFLOW);
    }
    assertTrue(overflowSeen);
}
Also used : 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 50 with FakeClock

use of com.facebook.buck.timing.FakeClock 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

FakeClock (com.facebook.buck.timing.FakeClock)54 Test (org.junit.Test)48 BuckEventBus (com.facebook.buck.event.BuckEventBus)36 EventBus (com.google.common.eventbus.EventBus)19 EasyMock.anyObject (org.easymock.EasyMock.anyObject)17 WatchEvent (java.nio.file.WatchEvent)13 BuildId (com.facebook.buck.model.BuildId)12 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)9 ProjectBuildFileParser (com.facebook.buck.json.ProjectBuildFileParser)8 Path (java.nio.file.Path)8 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)7 FakeWatchmanClient (com.facebook.buck.io.FakeWatchmanClient)6 Subscribe (com.google.common.eventbus.Subscribe)6 ArrayList (java.util.ArrayList)6 IncrementingFakeClock (com.facebook.buck.timing.IncrementingFakeClock)5 SettableFakeClock (com.facebook.buck.timing.SettableFakeClock)5 ConsoleEvent (com.facebook.buck.event.ConsoleEvent)4 FakeExecutor (com.facebook.buck.testutil.FakeExecutor)4 BuckEvent (com.facebook.buck.event.BuckEvent)3 WatchmanStatusEvent (com.facebook.buck.event.WatchmanStatusEvent)2