Search in sources :

Example 21 with EventBus

use of com.google.common.eventbus.EventBus in project bazel by bazelbuild.

the class SkylarkJavaLiteProtoLibraryTest method testJavaProtosExposeSkylarkProviders.

/**
   * Verify that a java_lite_proto_library exposes Skylark providers for the Java code it generates.
   */
@Test
public void testJavaProtosExposeSkylarkProviders() throws Exception {
    scratch.file("proto/extensions.bzl", "def _impl(ctx):", "  print (ctx.attr.dep[java_common.provider])", "custom_rule = rule(", "  implementation=_impl,", "  attrs={", "    'dep': attr.label()", "  },", ")");
    scratch.file("proto/BUILD", "load('/proto/extensions', 'custom_rule')", "load('//tools/build_rules/java_lite_proto_library:java_lite_proto_library.bzl',", "      'java_lite_proto_library')", "proto_library(", "    name = 'proto',", "    srcs = [ 'file.proto' ],", ")", "java_lite_proto_library(name = 'lite_pb2', deps = [':proto'])", "custom_rule(name = 'custom', dep = ':lite_pb2')");
    update(ImmutableList.of("//proto:custom"), false, /* keepGoing */
    1, /* loadingPhaseThreads */
    true, /* doAnalysis */
    new EventBus());
// Implicitly check that `update()` above didn't throw an exception. This implicitly checks that
// ctx.attr.dep.java.{transitive_deps, outputs}, above, is defined.
}
Also used : EventBus(com.google.common.eventbus.EventBus) Test(org.junit.Test)

Example 22 with EventBus

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

the class WatchmanWatcherTest method whenExistsIsFalseThenDeleteEventIsGenerated.

@Test
public void whenExistsIsFalseThenDeleteEventIsGenerated() throws IOException, InterruptedException {
    ImmutableMap<String, Object> watchmanOutput = ImmutableMap.of("files", ImmutableList.of(ImmutableMap.<String, Object>of("name", "foo/bar/baz", "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 23 with EventBus

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

the class WatchmanWatcherTest method whenQueryResultContainsErrorThenHumanReadableExceptionThrown.

@Test
public void whenQueryResultContainsErrorThenHumanReadableExceptionThrown() throws IOException, InterruptedException {
    String watchmanError = "Watch does not exist.";
    ImmutableMap<String, Object> watchmanOutput = ImmutableMap.of("version", "2.9.2", "error", watchmanError);
    EventBus eventBus = createStrictMock(EventBus.class);
    eventBus.post(anyObject());
    replay(eventBus);
    WatchmanWatcher watcher = createWatcher(eventBus, watchmanOutput);
    try {
        watcher.postEvents(BuckEventBusFactory.newInstance(new FakeClock(0)), WatchmanWatcher.FreshInstanceAction.NONE);
        fail("Should have thrown RuntimeException");
    } catch (RuntimeException e) {
        assertThat("Should contain watchman error.", e.getMessage(), Matchers.containsString(watchmanError));
    }
}
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 24 with EventBus

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

the class WatchmanWatcherTest method whenNameThenModifyEventIsGenerated.

@Test
public void whenNameThenModifyEventIsGenerated() throws IOException, InterruptedException {
    ImmutableMap<String, Object> watchmanOutput = ImmutableMap.of("files", ImmutableList.of(ImmutableMap.<String, Object>of("name", "foo/bar/baz")));
    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 modify event.", StandardWatchEventKinds.ENTRY_MODIFY, eventCapture.getValue().kind());
    assertEquals("Path should match watchman output.", MorePaths.pathWithPlatformSeparators("foo/bar/baz"), eventCapture.getValue().context().toString());
}
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 25 with EventBus

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

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