Search in sources :

Example 56 with StringValue

use of com.google.devtools.build.skyframe.GraphTester.StringValue in project bazel by bazelbuild.

the class ParallelEvaluatorTest method errorValueStored.

@Test
public void errorValueStored() throws Exception {
    graph = new InMemoryGraphImpl();
    SkyKey errorKey = GraphTester.toSkyKey("my_error_value");
    tester.getOrCreate(errorKey).setHasError(true);
    EvaluationResult<StringValue> result = eval(false, ImmutableList.of(errorKey));
    assertThat(result.keyNames()).isEmpty();
    assertThat(result.errorMap().keySet()).containsExactly(errorKey);
    ErrorInfo errorInfo = result.getError();
    assertThat(errorInfo.getRootCauses()).containsExactly(errorKey);
    // Update value. But builder won't rebuild it.
    tester.getOrCreate(errorKey).setHasError(false);
    tester.set(errorKey, new StringValue("no error?"));
    result = eval(false, ImmutableList.of(errorKey));
    assertThat(result.keyNames()).isEmpty();
    assertThat(result.errorMap().keySet()).containsExactly(errorKey);
    errorInfo = result.getError();
    assertThat(errorInfo.getRootCauses()).containsExactly(errorKey);
}
Also used : StringValue(com.google.devtools.build.skyframe.GraphTester.StringValue) Test(org.junit.Test)

Example 57 with StringValue

use of com.google.devtools.build.skyframe.GraphTester.StringValue in project bazel by bazelbuild.

the class ParallelEvaluatorTest method transformErrorDepOneLevelDownKeepGoing.

@Test
public void transformErrorDepOneLevelDownKeepGoing() throws Exception {
    graph = new InMemoryGraphImpl();
    SkyKey errorKey = GraphTester.toSkyKey("my_error_value");
    tester.getOrCreate(errorKey).setHasError(true);
    tester.set("after", new StringValue("after"));
    SkyKey parentErrorKey = GraphTester.toSkyKey("parent");
    tester.getOrCreate(parentErrorKey).addErrorDependency(errorKey, new StringValue("recovered"));
    tester.set(parentErrorKey, new StringValue("parent value"));
    SkyKey topKey = GraphTester.toSkyKey("top");
    tester.getOrCreate(topKey).addDependency(parentErrorKey).addDependency("after").setComputedValue(CONCATENATE);
    EvaluationResult<StringValue> result = eval(/*keepGoing=*/
    true, ImmutableList.of(topKey));
    assertThat(ImmutableList.<String>copyOf(result.<String>keyNames())).containsExactly("top");
    assertEquals("parent valueafter", result.get(topKey).getValue());
    assertThat(result.errorMap()).isEmpty();
}
Also used : StringValue(com.google.devtools.build.skyframe.GraphTester.StringValue) Test(org.junit.Test)

Example 58 with StringValue

use of com.google.devtools.build.skyframe.GraphTester.StringValue in project bazel by bazelbuild.

the class ParallelEvaluatorTest method storedEventFilter.

@Test
public void storedEventFilter() throws Exception {
    graph = new InMemoryGraphImpl();
    SkyKey a = GraphTester.toSkyKey("a");
    final AtomicBoolean evaluated = new AtomicBoolean(false);
    tester.getOrCreate(a).setBuilder(new SkyFunction() {

        @Nullable
        @Override
        public SkyValue compute(SkyKey skyKey, Environment env) {
            evaluated.set(true);
            env.getListener().handle(Event.error(null, "boop"));
            env.getListener().handle(Event.warn(null, "beep"));
            return new StringValue("a");
        }

        @Nullable
        @Override
        public String extractTag(SkyKey skyKey) {
            return null;
        }
    });
    ParallelEvaluator evaluator = makeEvaluator(graph, tester.getSkyFunctionMap(), /*keepGoing=*/
    false, new EventFilter() {

        @Override
        public boolean apply(Event event) {
            return event.getKind() == EventKind.ERROR;
        }

        @Override
        public boolean storeEvents() {
            return true;
        }
    });
    evaluator.eval(ImmutableList.of(a));
    assertTrue(evaluated.get());
    assertEventCount(2, eventCollector);
    assertContainsEvent(eventCollector, "boop");
    assertContainsEvent(eventCollector, "beep");
    eventCollector.clear();
    evaluator = makeEvaluator(graph, tester.getSkyFunctionMap(), /*keepGoing=*/
    false);
    evaluated.set(false);
    evaluator.eval(ImmutableList.of(a));
    assertFalse(evaluated.get());
    assertEventCount(1, eventCollector);
    assertContainsEvent(eventCollector, "boop");
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) MoreAsserts.assertContainsEvent(com.google.devtools.build.lib.testutil.MoreAsserts.assertContainsEvent) Event(com.google.devtools.build.lib.events.Event) StringValue(com.google.devtools.build.skyframe.GraphTester.StringValue) Nullable(javax.annotation.Nullable) Test(org.junit.Test)

Example 59 with StringValue

use of com.google.devtools.build.skyframe.GraphTester.StringValue in project bazel by bazelbuild.

the class ParallelEvaluatorTest method runDepOnErrorHaltsNoKeepGoingBuildEagerly.

public void runDepOnErrorHaltsNoKeepGoingBuildEagerly(boolean childErrorCached, final boolean handleChildError) throws Exception {
    graph = new InMemoryGraphImpl();
    SkyKey parentKey = GraphTester.toSkyKey("parent");
    final SkyKey childKey = GraphTester.toSkyKey("child");
    tester.getOrCreate(childKey).setHasError(/*hasError=*/
    true);
    // The parent should be built exactly twice: once during normal evaluation and once
    // during error bubbling.
    final AtomicInteger numParentInvocations = new AtomicInteger(0);
    tester.getOrCreate(parentKey).setBuilder(new SkyFunction() {

        @Override
        public SkyValue compute(SkyKey skyKey, Environment env) throws SkyFunctionException, InterruptedException {
            int invocations = numParentInvocations.incrementAndGet();
            if (handleChildError) {
                try {
                    SkyValue value = env.getValueOrThrow(childKey, SomeErrorException.class);
                    // On the first invocation, either the child error should already be cached and
                    // not propagated, or it should be computed freshly and not propagated. On the
                    // second build (error bubbling), the child error should be propagated.
                    assertTrue("bogus non-null value " + value, value == null);
                    assertEquals("parent incorrectly re-computed during normal evaluation", 1, invocations);
                    assertFalse("child error not propagated during error bubbling", env.inErrorBubblingForTesting());
                    return value;
                } catch (SomeErrorException e) {
                    assertTrue("child error propagated during normal evaluation", env.inErrorBubblingForTesting());
                    assertEquals(2, invocations);
                    return null;
                }
            } else {
                if (invocations == 1) {
                    assertFalse("parent's first computation should be during normal evaluation", env.inErrorBubblingForTesting());
                    return env.getValue(childKey);
                } else {
                    assertEquals(2, invocations);
                    assertTrue("parent incorrectly re-computed during normal evaluation", env.inErrorBubblingForTesting());
                    return env.getValue(childKey);
                }
            }
        }

        @Override
        public String extractTag(SkyKey skyKey) {
            return null;
        }
    });
    if (childErrorCached) {
        // Ensure that the child is already in the graph.
        evalValueInError(childKey);
    }
    EvaluationResult<StringValue> result = eval(/*keepGoing=*/
    false, ImmutableList.of(parentKey));
    assertEquals(2, numParentInvocations.get());
    assertTrue(result.hasError());
    assertEquals(childKey, result.getError().getRootCauseOfException());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) StringValue(com.google.devtools.build.skyframe.GraphTester.StringValue)

Example 60 with StringValue

use of com.google.devtools.build.skyframe.GraphTester.StringValue in project bazel by bazelbuild.

the class ParallelEvaluatorTest method twoErrors.

@Test
public void twoErrors() throws Exception {
    graph = new InMemoryGraphImpl();
    SkyKey firstError = GraphTester.toSkyKey("error1");
    SkyKey secondError = GraphTester.toSkyKey("error2");
    CountDownLatch firstStart = new CountDownLatch(1);
    CountDownLatch secondStart = new CountDownLatch(1);
    tester.getOrCreate(firstError).setBuilder(new ChainedFunction(firstStart, secondStart, /*notifyFinish=*/
    null, /*waitForException=*/
    false, /*value=*/
    null, ImmutableList.<SkyKey>of()));
    tester.getOrCreate(secondError).setBuilder(new ChainedFunction(secondStart, firstStart, /*notifyFinish=*/
    null, /*waitForException=*/
    false, /*value=*/
    null, ImmutableList.<SkyKey>of()));
    EvaluationResult<StringValue> result = eval(/*keepGoing=*/
    false, firstError, secondError);
    assertTrue(result.toString(), result.hasError());
    // With keepGoing=false, the eval call will terminate with exactly one error (the first one
    // thrown). But the first one thrown here is non-deterministic since we synchronize the
    // builders so that they run at roughly the same time.
    assertThat(ImmutableSet.of(firstError, secondError)).contains(Iterables.getOnlyElement(result.errorMap().keySet()));
}
Also used : CountDownLatch(java.util.concurrent.CountDownLatch) StringValue(com.google.devtools.build.skyframe.GraphTester.StringValue) Test(org.junit.Test)

Aggregations

StringValue (com.google.devtools.build.skyframe.GraphTester.StringValue)130 Test (org.junit.Test)114 NotComparableStringValue (com.google.devtools.build.skyframe.GraphTester.NotComparableStringValue)97 CountDownLatch (java.util.concurrent.CountDownLatch)30 Environment (com.google.devtools.build.skyframe.SkyFunction.Environment)22 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)14 EventType (com.google.devtools.build.skyframe.NotifyingHelper.EventType)11 Listener (com.google.devtools.build.skyframe.NotifyingHelper.Listener)11 Order (com.google.devtools.build.skyframe.NotifyingHelper.Order)11 Nullable (javax.annotation.Nullable)10 ErrorInfoSubjectFactory.assertThatErrorInfo (com.google.devtools.build.skyframe.ErrorInfoSubjectFactory.assertThatErrorInfo)9 ArrayList (java.util.ArrayList)7 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)7 ImmutableMap (com.google.common.collect.ImmutableMap)6 Map (java.util.Map)6 TestThread (com.google.devtools.build.lib.testutil.TestThread)5 Supplier (com.google.common.base.Supplier)3 Event (com.google.devtools.build.lib.events.Event)3 MoreAsserts.assertContainsEvent (com.google.devtools.build.lib.testutil.MoreAsserts.assertContainsEvent)3 TestFunction (com.google.devtools.build.skyframe.GraphTester.TestFunction)3