use of com.google.devtools.build.skyframe.GraphTester.StringValue in project bazel by bazelbuild.
the class MemoizingEvaluatorTest method deleteValues.
@Test
public void deleteValues() throws Exception {
tester.getOrCreate("top").setComputedValue(CONCATENATE).addDependency("d1").addDependency("d2").addDependency("d3");
tester.set("d1", new StringValue("1"));
StringValue d2 = new StringValue("2");
tester.set("d2", d2);
StringValue d3 = new StringValue("3");
tester.set("d3", d3);
tester.eval(true, "top");
tester.delete("d1");
tester.eval(true, "d3");
assertThat(tester.getDirtyKeys()).isEmpty();
assertEquals(ImmutableSet.of(skyKey("d1"), skyKey("top")), tester.getDeletedKeys());
assertEquals(null, tester.getExistingValue("top"));
assertEquals(null, tester.getExistingValue("d1"));
assertEquals(d2, tester.getExistingValue("d2"));
assertEquals(d3, tester.getExistingValue("d3"));
}
use of com.google.devtools.build.skyframe.GraphTester.StringValue 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));
}
}
use of com.google.devtools.build.skyframe.GraphTester.StringValue in project bazel by bazelbuild.
the class MemoizingEvaluatorTest method deleteNonexistentValues.
@Test
public void deleteNonexistentValues() throws Exception {
tester.getOrCreate("d1").setConstantValue(new StringValue("1"));
tester.delete("d1");
tester.delete("d2");
tester.eval(true, "d1");
}
use of com.google.devtools.build.skyframe.GraphTester.StringValue in project bazel by bazelbuild.
the class MemoizingEvaluatorTest method continueWithErrorDepTurnedGood.
@Test
public void continueWithErrorDepTurnedGood() throws Exception {
initializeTester();
SkyKey errorKey = GraphTester.toSkyKey("my_error_value");
tester.getOrCreate(errorKey).setHasError(true);
tester.set("after", new StringValue("after"));
SkyKey parentKey = GraphTester.toSkyKey("parent");
tester.getOrCreate(parentKey).addErrorDependency(errorKey, new StringValue("recovered")).setComputedValue(CONCATENATE).addDependency("after");
EvaluationResult<StringValue> result = tester.eval(/*keepGoing=*/
true, parentKey);
assertThat(result.errorMap()).isEmpty();
assertEquals("recoveredafter", result.get(parentKey).getValue());
tester.set(errorKey, new StringValue("reformed")).setHasError(false);
tester.invalidate();
result = tester.eval(/*keepGoing=*/
true, parentKey);
assertThat(result.errorMap()).isEmpty();
assertEquals("reformedafter", result.get(parentKey).getValue());
}
use of com.google.devtools.build.skyframe.GraphTester.StringValue in project bazel by bazelbuild.
the class ParallelEvaluatorTest method errorDepDoesntStopOtherDep.
@Test
public void errorDepDoesntStopOtherDep() throws Exception {
graph = new InMemoryGraphImpl();
final SkyKey errorKey = GraphTester.toSkyKey("error");
tester.getOrCreate(errorKey).setHasError(true);
EvaluationResult<StringValue> result1 = eval(/*keepGoing=*/
true, ImmutableList.of(errorKey));
assertThatEvaluationResult(result1).hasError();
assertThatEvaluationResult(result1).hasErrorEntryForKeyThat(errorKey).hasExceptionThat().isNotNull();
final SkyKey otherKey = GraphTester.toSkyKey("other");
tester.getOrCreate(otherKey).setConstantValue(new StringValue("other"));
SkyKey topKey = GraphTester.toSkyKey("top");
final Exception topException = new SomeErrorException("top exception");
final AtomicInteger numComputes = new AtomicInteger(0);
tester.getOrCreate(topKey).setBuilder(new SkyFunction() {
@Nullable
@Override
public SkyValue compute(SkyKey skyKey, Environment env) throws SkyFunctionException, InterruptedException {
Map<SkyKey, ValueOrException<SomeErrorException>> values = env.getValuesOrThrow(ImmutableList.of(errorKey, otherKey), SomeErrorException.class);
if (numComputes.incrementAndGet() == 1) {
assertThat(env.valuesMissing()).isTrue();
} else {
assertThat(numComputes.get()).isEqualTo(2);
assertThat(env.valuesMissing()).isFalse();
}
try {
values.get(errorKey).get();
throw new AssertionError("Should have thrown");
} catch (SomeErrorException e) {
throw new SkyFunctionException(topException, Transience.PERSISTENT) {
};
}
}
@Nullable
@Override
public String extractTag(SkyKey skyKey) {
return null;
}
});
EvaluationResult<StringValue> result2 = eval(/*keepGoing=*/
true, ImmutableList.of(topKey));
assertThatEvaluationResult(result2).hasError();
assertThatEvaluationResult(result2).hasErrorEntryForKeyThat(topKey).hasExceptionThat().isSameAs(topException);
assertThat(numComputes.get()).isEqualTo(2);
}
Aggregations