Search in sources :

Example 1 with TestFunction

use of com.google.devtools.build.skyframe.GraphTester.TestFunction 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)

Example 2 with TestFunction

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

the class MemoizingEvaluatorTest method singleValueDependsOnManyValues.

@Test
public void singleValueDependsOnManyValues() throws Exception {
    initializeTester();
    String[] values = new String[TEST_NODE_COUNT];
    StringBuilder expected = new StringBuilder();
    for (int i = 0; i < values.length; i++) {
        values[i] = Integer.toString(i);
        tester.set(values[i], new StringValue(values[i]));
        expected.append(values[i]);
    }
    SkyKey rootKey = toSkyKey("root");
    TestFunction value = tester.getOrCreate(rootKey).setComputedValue(CONCATENATE);
    for (int i = 0; i < values.length; i++) {
        value.addDependency(values[i]);
    }
    EvaluationResult<StringValue> result = tester.eval(/*keep_going=*/
    false, rootKey);
    assertEquals(new StringValue(expected.toString()), result.get(rootKey));
    for (int j = 0; j < 10; j++) {
        expected.setLength(0);
        for (int i = 0; i < values.length; i++) {
            String s = "other" + i + " " + j;
            tester.set(values[i], new StringValue(s));
            expected.append(s);
        }
        tester.invalidate();
        result = tester.eval(/*keep_going=*/
        false, rootKey);
        assertEquals(new StringValue(expected.toString()), result.get(rootKey));
    }
}
Also used : TestFunction(com.google.devtools.build.skyframe.GraphTester.TestFunction) NotComparableStringValue(com.google.devtools.build.skyframe.GraphTester.NotComparableStringValue) StringValue(com.google.devtools.build.skyframe.GraphTester.StringValue) Test(org.junit.Test)

Example 3 with TestFunction

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

the class MemoizingEvaluatorTest method singleValueDependsOnManyDirtyValues.

@Test
public void singleValueDependsOnManyDirtyValues() throws Exception {
    initializeTester();
    SkyKey[] values = new SkyKey[TEST_NODE_COUNT];
    StringBuilder expected = new StringBuilder();
    for (int i = 0; i < values.length; i++) {
        String valueName = Integer.toString(i);
        values[i] = GraphTester.toSkyKey(valueName);
        tester.set(values[i], new StringValue(valueName));
        expected.append(valueName);
    }
    SkyKey topKey = toSkyKey("top");
    TestFunction value = tester.getOrCreate(topKey).setComputedValue(CONCATENATE);
    for (int i = 0; i < values.length; i++) {
        value.addDependency(values[i]);
    }
    EvaluationResult<StringValue> result = tester.eval(/*keepGoing=*/
    false, topKey);
    assertEquals(new StringValue(expected.toString()), result.get(topKey));
    for (int j = 0; j < RUNS; j++) {
        for (int i = 0; i < values.length; i++) {
            tester.getOrCreate(values[i], /*markAsModified=*/
            true);
        }
        // This value has an error, but we should never discover it because it is not marked changed
        // and all of its dependencies re-evaluate to the same thing.
        tester.getOrCreate(topKey, /*markAsModified=*/
        false).setHasError(true);
        tester.invalidate();
        result = tester.eval(/*keep_going=*/
        false, topKey);
        assertEquals(new StringValue(expected.toString()), result.get(topKey));
    }
}
Also used : TestFunction(com.google.devtools.build.skyframe.GraphTester.TestFunction) NotComparableStringValue(com.google.devtools.build.skyframe.GraphTester.NotComparableStringValue) StringValue(com.google.devtools.build.skyframe.GraphTester.StringValue) Test(org.junit.Test)

Aggregations

NotComparableStringValue (com.google.devtools.build.skyframe.GraphTester.NotComparableStringValue)3 StringValue (com.google.devtools.build.skyframe.GraphTester.StringValue)3 TestFunction (com.google.devtools.build.skyframe.GraphTester.TestFunction)3 Test (org.junit.Test)3 ValueComputer (com.google.devtools.build.skyframe.GraphTester.ValueComputer)1 Environment (com.google.devtools.build.skyframe.SkyFunction.Environment)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1