Search in sources :

Example 56 with EventBus

use of com.google.common.eventbus.EventBus 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 57 with EventBus

use of com.google.common.eventbus.EventBus 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 58 with EventBus

use of com.google.common.eventbus.EventBus 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 59 with EventBus

use of com.google.common.eventbus.EventBus 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 60 with EventBus

use of com.google.common.eventbus.EventBus 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)

Aggregations

EventBus (com.google.common.eventbus.EventBus)85 Test (org.junit.Test)56 BuckEventBus (com.facebook.buck.event.BuckEventBus)21 FakeClock (com.facebook.buck.timing.FakeClock)19 EasyMock.anyObject (org.easymock.EasyMock.anyObject)18 Reporter (com.google.devtools.build.lib.events.Reporter)15 WatchEvent (java.nio.file.WatchEvent)12 Subscribe (com.google.common.eventbus.Subscribe)11 AnalysisResult (com.google.devtools.build.lib.analysis.BuildView.AnalysisResult)8 Before (org.junit.Before)8 Path (com.google.devtools.build.lib.vfs.Path)7 FakeWatchmanClient (com.facebook.buck.io.FakeWatchmanClient)6 ActionExecutionMetadata (com.google.devtools.build.lib.actions.ActionExecutionMetadata)4 ResourceHandle (com.google.devtools.build.lib.actions.ResourceManager.ResourceHandle)4 BuildLangTypedAttributeValuesMap (com.google.devtools.build.lib.packages.RuleFactory.BuildLangTypedAttributeValuesMap)4 HashMap (java.util.HashMap)4 Executor (com.google.devtools.build.lib.actions.Executor)3 Event (com.google.devtools.build.lib.events.Event)3 SuiteHint (com.carrotsearch.ant.tasks.junit4.balancers.SuiteHint)2 AggregatedQuitEvent (com.carrotsearch.ant.tasks.junit4.events.aggregated.AggregatedQuitEvent)2