Search in sources :

Example 96 with EventBus

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

use of com.google.common.eventbus.EventBus in project buck by facebook.

the class WatchmanWatcherTest method whenFilesListIsEmptyThenNoEventsAreGenerated.

@Test
public void whenFilesListIsEmptyThenNoEventsAreGenerated() throws IOException, InterruptedException {
    ImmutableMap<String, Object> watchmanOutput = ImmutableMap.of("version", "2.9.2", "clock", "c:1386170113:26390:5:50273", "is_fresh_instance", false, "files", ImmutableList.of());
    EventBus eventBus = createStrictMock(EventBus.class);
    replay(eventBus);
    WatchmanWatcher watcher = createWatcher(eventBus, watchmanOutput);
    watcher.postEvents(BuckEventBusFactory.newInstance(new FakeClock(0)), WatchmanWatcher.FreshInstanceAction.NONE);
    verify(eventBus);
}
Also used : FakeClock(com.facebook.buck.timing.FakeClock) EasyMock.anyObject(org.easymock.EasyMock.anyObject) BuckEventBus(com.facebook.buck.event.BuckEventBus) EventBus(com.google.common.eventbus.EventBus) Test(org.junit.Test)

Example 98 with EventBus

use of com.google.common.eventbus.EventBus in project buck by facebook.

the class WatchmanWatcherTest method whenNewIsTrueThenCreateEventIsGenerated.

@Test
public void whenNewIsTrueThenCreateEventIsGenerated() throws IOException, InterruptedException {
    ImmutableMap<String, Object> watchmanOutput = ImmutableMap.of("files", ImmutableList.of(ImmutableMap.<String, Object>of("name", "foo/bar/baz", "new", true)));
    Capture<WatchEvent<Path>> eventCapture = newCapture();
    EventBus eventBus = createStrictMock(EventBus.class);
    eventBus.post(capture(eventCapture));
    replay(eventBus);
    WatchmanWatcher watcher = createWatcher(eventBus, watchmanOutput);
    watcher.postEvents(BuckEventBusFactory.newInstance(new FakeClock(0)), WatchmanWatcher.FreshInstanceAction.NONE);
    verify(eventBus);
    assertEquals("Should be create event.", StandardWatchEventKinds.ENTRY_CREATE, 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 99 with EventBus

use of com.google.common.eventbus.EventBus in project buck by facebook.

the class WatchmanWatcherTest method whenNewAndNotExistsThenDeleteEventIsGenerated.

@Test
public void whenNewAndNotExistsThenDeleteEventIsGenerated() throws IOException, InterruptedException {
    ImmutableMap<String, Object> watchmanOutput = ImmutableMap.of("files", ImmutableList.of(ImmutableMap.<String, Object>of("name", "foo/bar/baz", "new", true, "exists", false)));
    Capture<WatchEvent<Path>> eventCapture = newCapture();
    EventBus eventBus = createStrictMock(EventBus.class);
    eventBus.post(capture(eventCapture));
    replay(eventBus);
    WatchmanWatcher watcher = createWatcher(eventBus, watchmanOutput);
    watcher.postEvents(BuckEventBusFactory.newInstance(new FakeClock(0)), WatchmanWatcher.FreshInstanceAction.NONE);
    verify(eventBus);
    assertEquals("Should be delete event.", StandardWatchEventKinds.ENTRY_DELETE, 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 100 with EventBus

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

EventBus (com.google.common.eventbus.EventBus)163 Test (org.junit.Test)73 Before (org.junit.Before)24 BuckEventBus (com.facebook.buck.event.BuckEventBus)21 HashMap (java.util.HashMap)20 FakeClock (com.facebook.buck.timing.FakeClock)19 Subscribe (com.google.common.eventbus.Subscribe)19 ArrayList (java.util.ArrayList)19 EasyMock.anyObject (org.easymock.EasyMock.anyObject)18 Reporter (com.google.devtools.build.lib.events.Reporter)15 List (java.util.List)14 WatchEvent (java.nio.file.WatchEvent)12 Test (org.junit.jupiter.api.Test)11 RefreshEndpointEvent (org.apache.servicecomb.http.client.event.RefreshEndpointEvent)10 AnalysisResult (com.google.devtools.build.lib.analysis.BuildView.AnalysisResult)8 Expectations (mockit.Expectations)8 Microservice (org.apache.servicecomb.registry.api.registry.Microservice)8 MicroserviceInstance (org.apache.servicecomb.registry.api.registry.MicroserviceInstance)8 Test (org.testng.annotations.Test)8 Path (com.google.devtools.build.lib.vfs.Path)7