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());
}
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());
}
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());
}
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");
}
}
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());
}
Aggregations