Search in sources :

Example 11 with EventHandler

use of com.google.devtools.build.lib.events.EventHandler in project bazel by bazelbuild.

the class ParallelEvaluatorTest method signalValueEnqueuedAndEvaluated.

@Test
public void signalValueEnqueuedAndEvaluated() throws Exception {
    final Set<SkyKey> enqueuedValues = Sets.newConcurrentHashSet();
    final Set<SkyKey> evaluatedValues = Sets.newConcurrentHashSet();
    EvaluationProgressReceiver progressReceiver = new EvaluationProgressReceiver() {

        @Override
        public void invalidated(SkyKey skyKey, InvalidationState state) {
            throw new IllegalStateException();
        }

        @Override
        public void enqueueing(SkyKey skyKey) {
            enqueuedValues.add(skyKey);
        }

        @Override
        public void computed(SkyKey skyKey, long elapsedTimeNanos) {
        }

        @Override
        public void evaluated(SkyKey skyKey, Supplier<SkyValue> skyValueSupplier, EvaluationState state) {
            evaluatedValues.add(skyKey);
        }
    };
    ExtendedEventHandler reporter = new Reporter(new EventBus(), new EventHandler() {

        @Override
        public void handle(Event e) {
            throw new IllegalStateException();
        }
    });
    MemoizingEvaluator aug = new InMemoryMemoizingEvaluator(ImmutableMap.of(GraphTester.NODE_TYPE, tester.getFunction()), new RecordingDifferencer(), progressReceiver);
    SequentialBuildDriver driver = new SequentialBuildDriver(aug);
    tester.getOrCreate("top1").setComputedValue(CONCATENATE).addDependency("d1").addDependency("d2");
    tester.getOrCreate("top2").setComputedValue(CONCATENATE).addDependency("d3");
    tester.getOrCreate("top3");
    assertThat(enqueuedValues).isEmpty();
    assertThat(evaluatedValues).isEmpty();
    tester.set("d1", new StringValue("1"));
    tester.set("d2", new StringValue("2"));
    tester.set("d3", new StringValue("3"));
    driver.evaluate(ImmutableList.of(GraphTester.toSkyKey("top1")), false, 200, reporter);
    assertThat(enqueuedValues).containsExactlyElementsIn(Arrays.asList(GraphTester.toSkyKeys("top1", "d1", "d2")));
    assertThat(evaluatedValues).containsExactlyElementsIn(Arrays.asList(GraphTester.toSkyKeys("top1", "d1", "d2")));
    enqueuedValues.clear();
    evaluatedValues.clear();
    driver.evaluate(ImmutableList.of(GraphTester.toSkyKey("top2")), false, 200, reporter);
    assertThat(enqueuedValues).containsExactlyElementsIn(Arrays.asList(GraphTester.toSkyKeys("top2", "d3")));
    assertThat(evaluatedValues).containsExactlyElementsIn(Arrays.asList(GraphTester.toSkyKeys("top2", "d3")));
    enqueuedValues.clear();
    evaluatedValues.clear();
    driver.evaluate(ImmutableList.of(GraphTester.toSkyKey("top1")), false, 200, reporter);
    assertThat(enqueuedValues).isEmpty();
    assertThat(evaluatedValues).containsExactlyElementsIn(Arrays.asList(GraphTester.toSkyKeys("top1")));
}
Also used : Reporter(com.google.devtools.build.lib.events.Reporter) ExtendedEventHandler(com.google.devtools.build.lib.events.ExtendedEventHandler) EventHandler(com.google.devtools.build.lib.events.EventHandler) EventBus(com.google.common.eventbus.EventBus) ExtendedEventHandler(com.google.devtools.build.lib.events.ExtendedEventHandler) MoreAsserts.assertContainsEvent(com.google.devtools.build.lib.testutil.MoreAsserts.assertContainsEvent) Event(com.google.devtools.build.lib.events.Event) Supplier(com.google.common.base.Supplier) StringValue(com.google.devtools.build.skyframe.GraphTester.StringValue) Test(org.junit.Test)

Aggregations

EventHandler (com.google.devtools.build.lib.events.EventHandler)11 Event (com.google.devtools.build.lib.events.Event)4 IOException (java.io.IOException)4 UserExecException (com.google.devtools.build.lib.actions.UserExecException)3 Reporter (com.google.devtools.build.lib.events.Reporter)3 ArrayList (java.util.ArrayList)3 EventBus (com.google.common.eventbus.EventBus)2 ActionInput (com.google.devtools.build.lib.actions.ActionInput)2 Executor (com.google.devtools.build.lib.actions.Executor)2 PrintingEventHandler (com.google.devtools.build.lib.events.PrintingEventHandler)2 OutErr (com.google.devtools.build.lib.util.io.OutErr)2 Path (com.google.devtools.build.lib.vfs.Path)2 PathFragment (com.google.devtools.build.lib.vfs.PathFragment)2 Test (org.junit.Test)2 Supplier (com.google.common.base.Supplier)1 HashCode (com.google.common.hash.HashCode)1 ActionExecutedEvent (com.google.devtools.build.lib.actions.ActionExecutedEvent)1 ActionInputFileCache (com.google.devtools.build.lib.actions.ActionInputFileCache)1 Artifact (com.google.devtools.build.lib.actions.Artifact)1 EnvironmentalExecException (com.google.devtools.build.lib.actions.EnvironmentalExecException)1