Search in sources :

Example 16 with EventBus

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

the class EventSensorTest method sensorNoticesEventsInItsMask.

@Test
public void sensorNoticesEventsInItsMask() {
    EventSensor sensor = new EventSensor(EventKind.ERRORS);
    Reporter reporter = new Reporter(new EventBus(), sensor);
    reporter.handle(Event.error(location, "An ERROR event."));
    assertTrue(sensor.wasTriggered());
}
Also used : EventBus(com.google.common.eventbus.EventBus) Test(org.junit.Test)

Example 17 with EventBus

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

the class EventSensorTest method sensorNoticesEventsInItsMask2.

@Test
public void sensorNoticesEventsInItsMask2() {
    EventSensor sensor = new EventSensor(EventKind.ALL_EVENTS);
    Reporter reporter = new Reporter(new EventBus(), sensor);
    reporter.handle(Event.error(location, "An ERROR event."));
    reporter.handle(Event.warn(location, "A warning event."));
    assertTrue(sensor.wasTriggered());
}
Also used : EventBus(com.google.common.eventbus.EventBus) Test(org.junit.Test)

Example 18 with EventBus

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

the class BlazeExecutorTest method testDebugPrintActionContexts.

@Test
public void testDebugPrintActionContexts() throws Exception {
    TestExecutorBuilder builder = new TestExecutorBuilder(directories, binTools);
    OptionsParser parser = OptionsParser.newOptionsParser(TestExecutorBuilder.DEFAULT_OPTIONS);
    parser.parse("--debug_print_action_contexts");
    Reporter reporter = new Reporter(new EventBus());
    StoredEventHandler storedEventHandler = new StoredEventHandler();
    reporter.addHandler(storedEventHandler);
    SpawnActionContext mockStrategy = Mockito.mock(SpawnActionContext.class);
    builder.setReporter(reporter).setOptionsParser(parser).setExecution("mock", mockStrategy);
    builder.build();
    Event event = Iterables.find(storedEventHandler.getEvents(), new Predicate<Event>() {

        @Override
        public boolean apply(@Nullable Event event) {
            return event.getMessage().contains("SpawnActionContextMap: \"mock\" = ");
        }
    });
    assertThat(event).isNotNull();
    assertThat(event.getMessage()).contains("\"mock\" = " + mockStrategy.getClass().getSimpleName());
}
Also used : TestExecutorBuilder(com.google.devtools.build.lib.exec.util.TestExecutorBuilder) StoredEventHandler(com.google.devtools.build.lib.events.StoredEventHandler) Reporter(com.google.devtools.build.lib.events.Reporter) Event(com.google.devtools.build.lib.events.Event) EventBus(com.google.common.eventbus.EventBus) OptionsParser(com.google.devtools.common.options.OptionsParser) SpawnActionContext(com.google.devtools.build.lib.actions.SpawnActionContext) Test(org.junit.Test)

Example 19 with EventBus

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

the class RuleFactoryTest method testWorkspaceRuleFailsInBuildFile.

@Test
public void testWorkspaceRuleFailsInBuildFile() throws Exception {
    Path myPkgPath = scratch.resolve("/foo/workspace/mypkg/BUILD");
    Package.Builder pkgBuilder = packageFactory.newPackageBuilder(PackageIdentifier.createInMainRepo("mypkg"), "TESTING").setFilename(myPkgPath).setMakeEnv(new MakeEnvironment.Builder());
    Map<String, Object> attributeValues = new HashMap<>();
    attributeValues.put("name", "foo");
    attributeValues.put("actual", "//bar:baz");
    RuleClass ruleClass = provider.getRuleClassMap().get("bind");
    try {
        RuleFactory.createAndAddRule(pkgBuilder, ruleClass, new BuildLangTypedAttributeValuesMap(attributeValues), new Reporter(new EventBus()), /*ast=*/
        null, LOCATION_42, /*env=*/
        null, new AttributeContainer(ruleClass));
        fail();
    } catch (RuleFactory.InvalidRuleException e) {
        assertThat(e.getMessage()).contains("must be in the WORKSPACE file");
    }
}
Also used : Path(com.google.devtools.build.lib.vfs.Path) HashMap(java.util.HashMap) Reporter(com.google.devtools.build.lib.events.Reporter) EventBus(com.google.common.eventbus.EventBus) BuildLangTypedAttributeValuesMap(com.google.devtools.build.lib.packages.RuleFactory.BuildLangTypedAttributeValuesMap) Test(org.junit.Test)

Example 20 with EventBus

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

the class PackageFactoryTest method testCreatePackageIsolatedFromOuterErrors.

@Test
public void testCreatePackageIsolatedFromOuterErrors() throws Exception {
    ExecutorService e = Executors.newCachedThreadPool();
    final Semaphore beforeError = new Semaphore(0);
    final Semaphore afterError = new Semaphore(0);
    Reporter reporter = new Reporter(new EventBus());
    ParsingTracker parser = new ParsingTracker(beforeError, afterError, reporter);
    final Logger log = Logger.getLogger(PackageFactory.class.getName());
    log.addHandler(parser);
    Level originalLevel = log.getLevel();
    log.setLevel(Level.FINE);
    e.execute(new ErrorReporter(reporter, beforeError, afterError));
    e.execute(parser);
    // wait for all to finish
    e.shutdown();
    assertTrue(e.awaitTermination(TestUtils.WAIT_TIMEOUT_MILLISECONDS, TimeUnit.MILLISECONDS));
    log.removeHandler(parser);
    log.setLevel(originalLevel);
    assertTrue(parser.hasParsed());
}
Also used : Reporter(com.google.devtools.build.lib.events.Reporter) ExecutorService(java.util.concurrent.ExecutorService) Level(java.util.logging.Level) Semaphore(java.util.concurrent.Semaphore) EventBus(com.google.common.eventbus.EventBus) Logger(java.util.logging.Logger) Test(org.junit.Test)

Aggregations

EventBus (com.google.common.eventbus.EventBus)84 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