Search in sources :

Example 1 with StringValue

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

the class MemoizingEvaluatorTest method changePruningWithEvent.

@Test
public void changePruningWithEvent() throws Exception {
    initializeTester();
    SkyKey parent = GraphTester.toSkyKey("parent");
    SkyKey child = GraphTester.toSkyKey("child");
    tester.getOrCreate(child).setConstantValue(new StringValue("child")).setWarning("bloop");
    // Restart once because child isn't ready.
    CountDownLatch parentEvaluated = new CountDownLatch(3);
    StringValue parentVal = new StringValue("parent");
    tester.getOrCreate(parent).setBuilder(new ChainedFunction(parentEvaluated, null, null, false, parentVal, ImmutableList.of(child)));
    assertThat(tester.evalAndGet(/*keepGoing=*/
    false, parent)).isEqualTo(parentVal);
    assertThat(parentEvaluated.getCount()).isEqualTo(1);
    assertContainsEvent(eventCollector, "bloop");
    tester.resetPlayedEvents();
    tester.getOrCreate(child, /*markAsModified=*/
    true);
    tester.invalidate();
    assertThat(tester.evalAndGet(/*keepGoing=*/
    false, parent)).isEqualTo(parentVal);
    assertContainsEvent(eventCollector, "bloop");
    assertThat(parentEvaluated.getCount()).isEqualTo(1);
}
Also used : NotComparableStringValue(com.google.devtools.build.skyframe.GraphTester.NotComparableStringValue) StringValue(com.google.devtools.build.skyframe.GraphTester.StringValue) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 2 with StringValue

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

the class MemoizingEvaluatorTest method incrementalAddedDependency.

@Test
public void incrementalAddedDependency() throws Exception {
    tester.getOrCreate("a").addDependency("b").setComputedValue(CONCATENATE);
    tester.set("b", new StringValue("first"));
    tester.set("c", new StringValue("second"));
    tester.evalAndGet("a");
    tester.getOrCreate("a").addDependency("c");
    tester.set("b", new StringValue("now"));
    tester.invalidate();
    StringValue value = (StringValue) tester.evalAndGet("a");
    assertEquals("nowsecond", value.getValue());
}
Also used : NotComparableStringValue(com.google.devtools.build.skyframe.GraphTester.NotComparableStringValue) StringValue(com.google.devtools.build.skyframe.GraphTester.StringValue) Test(org.junit.Test)

Example 3 with StringValue

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

the class MemoizingEvaluatorTest method cycleAboveIndependentCycle.

/** @see ParallelEvaluatorTest#cycleAboveIndependentCycle() */
@Test
public void cycleAboveIndependentCycle() throws Exception {
    makeGraphDeterministic();
    SkyKey aKey = GraphTester.toSkyKey("a");
    final SkyKey bKey = GraphTester.toSkyKey("b");
    SkyKey cKey = GraphTester.toSkyKey("c");
    final SkyKey leafKey = GraphTester.toSkyKey("leaf");
    // When aKey depends on leafKey and bKey,
    tester.getOrCreate(aKey).setBuilder(new SkyFunction() {

        @Nullable
        @Override
        public SkyValue compute(SkyKey skyKey, Environment env) throws InterruptedException {
            env.getValues(ImmutableList.of(leafKey, bKey));
            return null;
        }

        @Nullable
        @Override
        public String extractTag(SkyKey skyKey) {
            return null;
        }
    });
    // And bKey depends on cKey,
    tester.getOrCreate(bKey).addDependency(cKey);
    // And cKey depends on aKey and bKey in that order,
    tester.getOrCreate(cKey).addDependency(aKey).addDependency(bKey);
    // And leafKey is a leaf node,
    tester.set(leafKey, new StringValue("leafy"));
    // Then when we evaluate,
    EvaluationResult<StringValue> result = tester.eval(/*keepGoing=*/
    true, aKey);
    // aKey has an error,
    assertEquals(null, result.get(aKey));
    if (cyclesDetected()) {
        // And both cycles were found underneath aKey: the (aKey->bKey->cKey) cycle, and the
        // aKey->(bKey->cKey) cycle. This is because cKey depended on aKey and then bKey, so it pushed
        // them down on the stack in that order, so bKey was processed first. It found its cycle, then
        // popped off the stack, and then aKey was processed and found its cycle.
        assertThatEvaluationResult(result).hasErrorEntryForKeyThat(aKey).hasCycleInfoThat().containsExactly(new CycleInfo(ImmutableList.of(aKey, bKey, cKey)), new CycleInfo(ImmutableList.of(aKey), ImmutableList.of(bKey, cKey)));
    } else {
        assertThatEvaluationResult(result).hasErrorEntryForKeyThat(aKey).hasCycleInfoThat().hasSize(1);
    }
    // When leafKey is changed, so that aKey will be marked as NEEDS_REBUILDING,
    tester.set(leafKey, new StringValue("crunchy"));
    // And cKey is invalidated, so that cycle checking will have to explore the full graph,
    tester.getOrCreate(cKey, /*markAsModified=*/
    true);
    tester.invalidate();
    // Then when we evaluate,
    EvaluationResult<StringValue> result2 = tester.eval(/*keepGoing=*/
    true, aKey);
    // Things are just as before.
    assertEquals(null, result2.get(aKey));
    if (cyclesDetected()) {
        assertThatEvaluationResult(result).hasErrorEntryForKeyThat(aKey).hasCycleInfoThat().containsExactly(new CycleInfo(ImmutableList.of(aKey, bKey, cKey)), new CycleInfo(ImmutableList.of(aKey), ImmutableList.of(bKey, cKey)));
    } else {
        assertThatEvaluationResult(result).hasErrorEntryForKeyThat(aKey).hasCycleInfoThat().hasSize(1);
    }
}
Also used : Environment(com.google.devtools.build.skyframe.SkyFunction.Environment) NotComparableStringValue(com.google.devtools.build.skyframe.GraphTester.NotComparableStringValue) StringValue(com.google.devtools.build.skyframe.GraphTester.StringValue) Nullable(javax.annotation.Nullable) Test(org.junit.Test)

Example 4 with StringValue

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

the class MemoizingEvaluatorTest method cycleWithDirtyValue.

/** Regression test: "crash in cycle checker with dirty values". */
@Test
public void cycleWithDirtyValue() throws Exception {
    initializeTester();
    SkyKey cycleKey1 = GraphTester.toSkyKey("cycleKey1");
    SkyKey cycleKey2 = GraphTester.toSkyKey("cycleKey2");
    tester.getOrCreate(cycleKey1).addDependency(cycleKey2).setComputedValue(COPY);
    tester.getOrCreate(cycleKey2).addDependency(cycleKey1).setComputedValue(COPY);
    EvaluationResult<StringValue> result = tester.eval(/*keepGoing=*/
    true, cycleKey1);
    assertEquals(null, result.get(cycleKey1));
    ErrorInfo errorInfo = result.getError(cycleKey1);
    CycleInfo cycleInfo = Iterables.getOnlyElement(errorInfo.getCycleInfo());
    if (cyclesDetected()) {
        assertThat(cycleInfo.getCycle()).containsExactly(cycleKey1, cycleKey2).inOrder();
        assertThat(cycleInfo.getPathToCycle()).isEmpty();
    }
    tester.getOrCreate(cycleKey1, /*markAsModified=*/
    true);
    tester.invalidate();
    result = tester.eval(/*keepGoing=*/
    true, cycleKey1);
    assertEquals(null, result.get(cycleKey1));
    errorInfo = result.getError(cycleKey1);
    cycleInfo = Iterables.getOnlyElement(errorInfo.getCycleInfo());
    if (cyclesDetected()) {
        assertThat(cycleInfo.getCycle()).containsExactly(cycleKey1, cycleKey2).inOrder();
        assertThat(cycleInfo.getPathToCycle()).isEmpty();
    }
}
Also used : ErrorInfoSubjectFactory.assertThatErrorInfo(com.google.devtools.build.skyframe.ErrorInfoSubjectFactory.assertThatErrorInfo) NotComparableStringValue(com.google.devtools.build.skyframe.GraphTester.NotComparableStringValue) StringValue(com.google.devtools.build.skyframe.GraphTester.StringValue) Test(org.junit.Test)

Example 5 with StringValue

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

the class MemoizingEvaluatorTest method limitEvaluatorThreads.

@Test
public void limitEvaluatorThreads() throws Exception {
    initializeTester();
    int numKeys = 10;
    final Object lock = new Object();
    final AtomicInteger inProgressCount = new AtomicInteger();
    final int[] maxValue = { 0 };
    SkyKey topLevel = GraphTester.toSkyKey("toplevel");
    TestFunction topLevelBuilder = tester.getOrCreate(topLevel);
    for (int i = 0; i < numKeys; i++) {
        topLevelBuilder.addDependency("subKey" + i);
        tester.getOrCreate("subKey" + i).setComputedValue(new ValueComputer() {

            @Override
            public SkyValue compute(Map<SkyKey, SkyValue> deps, SkyFunction.Environment env) {
                int val = inProgressCount.incrementAndGet();
                synchronized (lock) {
                    if (val > maxValue[0]) {
                        maxValue[0] = val;
                    }
                }
                Uninterruptibles.sleepUninterruptibly(5, TimeUnit.SECONDS);
                inProgressCount.decrementAndGet();
                return new StringValue("abc");
            }
        });
    }
    topLevelBuilder.setConstantValue(new StringValue("xyz"));
    EvaluationResult<StringValue> result = tester.eval(/*keepGoing=*/
    true, /*numThreads=*/
    5, topLevel);
    assertFalse(result.hasError());
    assertEquals(5, maxValue[0]);
}
Also used : TestFunction(com.google.devtools.build.skyframe.GraphTester.TestFunction) ValueComputer(com.google.devtools.build.skyframe.GraphTester.ValueComputer) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Environment(com.google.devtools.build.skyframe.SkyFunction.Environment) NotComparableStringValue(com.google.devtools.build.skyframe.GraphTester.NotComparableStringValue) 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