use of com.google.devtools.build.skyframe.GraphTester.StringValue in project bazel by bazelbuild.
the class MemoizingEvaluatorTest method transientErrorTurningGoodHasNoError.
@Test
public void transientErrorTurningGoodHasNoError() throws Exception {
initializeTester();
SkyKey errorKey = GraphTester.toSkyKey("my_error_value");
tester.getOrCreate(errorKey).setHasTransientError(true);
ErrorInfo errorInfo = tester.evalAndGetError(errorKey);
assertNotNull(errorInfo);
assertThat(errorInfo.getRootCauses()).containsExactly(errorKey);
// Re-evaluates to same thing when errors are invalidated
tester.invalidateTransientErrors();
errorInfo = tester.evalAndGetError(errorKey);
assertNotNull(errorInfo);
StringValue value = new StringValue("reformed");
assertThat(errorInfo.getRootCauses()).containsExactly(errorKey);
tester.getOrCreate(errorKey, /*markAsModified=*/
false).setHasTransientError(false).setConstantValue(value);
tester.invalidateTransientErrors();
StringValue stringValue = (StringValue) tester.evalAndGet(/*keepGoing=*/
true, errorKey);
assertSame(stringValue, value);
// Value builder will now throw, but we should never get to it because it isn't dirty.
tester.getOrCreate(errorKey, /*markAsModified=*/
false).setHasTransientError(true);
tester.invalidateTransientErrors();
stringValue = (StringValue) tester.evalAndGet(/*keepGoing=*/
true, errorKey);
assertThat(stringValue).isEqualTo(value);
}
use of com.google.devtools.build.skyframe.GraphTester.StringValue in project bazel by bazelbuild.
the class MemoizingEvaluatorTest method valueInjectionOverExistingEqualEntryDoesNotInvalidate.
@Test
public void valueInjectionOverExistingEqualEntryDoesNotInvalidate() throws Exception {
SkyKey childKey = GraphTester.toSkyKey("child");
SkyKey parentKey = GraphTester.toSkyKey("parent");
SkyValue val = new StringValue("same_val");
tester.getOrCreate(parentKey).addDependency("child").setComputedValue(COPY);
tester.getOrCreate(childKey).setConstantValue(new StringValue("same_val"));
assertEquals(val, tester.evalAndGet("parent"));
tester.differencer.inject(ImmutableMap.of(childKey, val));
assertEquals(val, tester.getExistingValue("child"));
// Since we are injecting an equal value, the parent should not have been invalidated.
assertEquals(val, tester.getExistingValue("parent"));
}
use of com.google.devtools.build.skyframe.GraphTester.StringValue in project bazel by bazelbuild.
the class MemoizingEvaluatorTest method changedChildChangesDepOfParent.
@Test
public void changedChildChangesDepOfParent() throws Exception {
initializeTester();
final SkyKey buildFile = GraphTester.toSkyKey("buildFile");
ValueComputer authorDrink = new ValueComputer() {
@Override
public SkyValue compute(Map<SkyKey, SkyValue> deps, SkyFunction.Environment env) throws InterruptedException {
String author = ((StringValue) deps.get(buildFile)).getValue();
StringValue beverage;
switch(author) {
case "hemingway":
beverage = (StringValue) env.getValue(GraphTester.toSkyKey("absinthe"));
break;
case "joyce":
beverage = (StringValue) env.getValue(GraphTester.toSkyKey("whiskey"));
break;
default:
throw new IllegalStateException(author);
}
if (beverage == null) {
return null;
}
return new StringValue(author + " drank " + beverage.getValue());
}
};
tester.set(buildFile, new StringValue("hemingway"));
SkyKey absinthe = GraphTester.toSkyKey("absinthe");
tester.set(absinthe, new StringValue("absinthe"));
SkyKey whiskey = GraphTester.toSkyKey("whiskey");
tester.set(whiskey, new StringValue("whiskey"));
SkyKey top = GraphTester.toSkyKey("top");
tester.getOrCreate(top).addDependency(buildFile).setComputedValue(authorDrink);
StringValue topValue = (StringValue) tester.evalAndGet("top");
assertEquals("hemingway drank absinthe", topValue.getValue());
tester.set(buildFile, new StringValue("joyce"));
// Don't evaluate absinthe successfully anymore.
tester.getOrCreate(absinthe).setHasError(true);
tester.invalidate();
topValue = (StringValue) tester.evalAndGet("top");
assertEquals("joyce drank whiskey", topValue.getValue());
assertThat(tester.getDirtyKeys()).containsExactly(buildFile, top);
assertThat(tester.getDeletedKeys()).isEmpty();
}
use of com.google.devtools.build.skyframe.GraphTester.StringValue in project bazel by bazelbuild.
the class MemoizingEvaluatorTest method diamondDependency.
@Test
public void diamondDependency() throws Exception {
setupDiamondDependency();
tester.set("d", new StringValue("me"));
StringValue value = (StringValue) tester.evalAndGet("a");
assertEquals("meme", value.getValue());
}
use of com.google.devtools.build.skyframe.GraphTester.StringValue in project bazel by bazelbuild.
the class MemoizingEvaluatorTest method valueInjectionOverValueWithDeps.
@Test
public void valueInjectionOverValueWithDeps() throws Exception {
SkyKey key = GraphTester.toSkyKey("value");
SkyValue val = new StringValue("val");
StringValue prevVal = new StringValue("foo");
tester.getOrCreate("other").setConstantValue(prevVal);
tester.getOrCreate(key).addDependency("other").setComputedValue(COPY);
assertEquals(prevVal, tester.evalAndGet("value"));
tester.differencer.inject(ImmutableMap.of(key, val));
try {
tester.evalAndGet("value");
Assert.fail("injection over value with deps should have failed");
} catch (IllegalStateException e) {
assertThat(e).hasMessage("existing entry for " + NODE_TYPE.getName() + ":value has deps: " + "[" + NODE_TYPE.getName() + ":other]");
}
}
Aggregations