use of com.google.devtools.build.skyframe.GraphTester.StringValue in project bazel by bazelbuild.
the class ParallelEvaluatorTest method valueNotUsedInFailFastErrorRecovery.
@Test
public void valueNotUsedInFailFastErrorRecovery() throws Exception {
graph = new InMemoryGraphImpl();
SkyKey topKey = GraphTester.toSkyKey("top");
SkyKey recoveryKey = GraphTester.toSkyKey("midRecovery");
SkyKey badKey = GraphTester.toSkyKey("bad");
tester.getOrCreate(topKey).addDependency(recoveryKey).setComputedValue(CONCATENATE);
tester.getOrCreate(recoveryKey).addErrorDependency(badKey, new StringValue("i recovered")).setComputedValue(CONCATENATE);
tester.getOrCreate(badKey).setHasError(true);
EvaluationResult<SkyValue> result = eval(/*keepGoing=*/
true, ImmutableList.of(recoveryKey));
assertThat(result.errorMap()).isEmpty();
assertThatEvaluationResult(result).hasNoError();
assertEquals(new StringValue("i recovered"), result.get(recoveryKey));
result = eval(/*keepGoing=*/
false, ImmutableList.of(topKey));
assertThatEvaluationResult(result).hasError();
assertThat(result.keyNames()).isEmpty();
assertEquals(1, result.errorMap().size());
assertNotNull(result.getError(topKey).getException());
}
use of com.google.devtools.build.skyframe.GraphTester.StringValue in project bazel by bazelbuild.
the class ParallelEvaluatorTest method cycleWithKeepGoing.
@Test
public void cycleWithKeepGoing() throws Exception {
graph = new InMemoryGraphImpl();
SkyKey aKey = GraphTester.toSkyKey("a");
SkyKey bKey = GraphTester.toSkyKey("b");
SkyKey topKey = GraphTester.toSkyKey("top");
SkyKey midKey = GraphTester.toSkyKey("mid");
SkyKey goodKey = GraphTester.toSkyKey("good");
StringValue goodValue = new StringValue("good");
tester.set(goodKey, goodValue);
tester.getOrCreate(topKey).addDependency(midKey);
tester.getOrCreate(midKey).addDependency(aKey);
tester.getOrCreate(aKey).addDependency(bKey);
tester.getOrCreate(bKey).addDependency(aKey);
EvaluationResult<StringValue> result = eval(true, topKey, goodKey);
assertEquals(goodValue, result.get(goodKey));
assertEquals(null, result.get(topKey));
ErrorInfo errorInfo = result.getError(topKey);
CycleInfo cycleInfo = Iterables.getOnlyElement(errorInfo.getCycleInfo());
assertThat(cycleInfo.getCycle()).containsExactly(aKey, bKey).inOrder();
assertThat(cycleInfo.getPathToCycle()).containsExactly(topKey, midKey).inOrder();
}
use of com.google.devtools.build.skyframe.GraphTester.StringValue in project bazel by bazelbuild.
the class ParallelEvaluatorTest method smoke.
@Test
public void smoke() throws Exception {
graph = new InMemoryGraphImpl();
set("a", "a");
set("b", "b");
tester.getOrCreate("ab").addDependency("a").addDependency("b").setComputedValue(CONCATENATE);
StringValue value = (StringValue) eval(false, GraphTester.toSkyKey("ab"));
assertEquals("ab", value.getValue());
assertNoEvents(eventCollector);
}
use of com.google.devtools.build.skyframe.GraphTester.StringValue in project bazel by bazelbuild.
the class ParallelEvaluatorTest method sameDepInTwoGroups.
/**
* Exercises various situations involving groups of deps that overlap -- request one group, then
* request another group that has a dep in common with the first group.
*
* @param sameFirst whether the dep in common in the two groups should be the first dep.
* @param twoCalls whether the two groups should be requested in two different builder calls.
* @param valuesOrThrow whether the deps should be requested using getValuesOrThrow.
*/
private void sameDepInTwoGroups(final boolean sameFirst, final boolean twoCalls, final boolean valuesOrThrow) throws Exception {
graph = new InMemoryGraphImpl();
SkyKey topKey = GraphTester.toSkyKey("top");
final List<SkyKey> leaves = new ArrayList<>();
for (int i = 1; i <= 3; i++) {
SkyKey leaf = GraphTester.toSkyKey("leaf" + i);
leaves.add(leaf);
tester.set(leaf, new StringValue("leaf" + i));
}
final SkyKey leaf4 = GraphTester.toSkyKey("leaf4");
tester.set(leaf4, new StringValue("leaf" + 4));
tester.getOrCreate(topKey).setBuilder(new SkyFunction() {
@Override
public SkyValue compute(SkyKey skyKey, Environment env) throws SkyFunctionException, InterruptedException {
if (valuesOrThrow) {
env.getValuesOrThrow(leaves, SomeErrorException.class);
} else {
env.getValues(leaves);
}
if (twoCalls && env.valuesMissing()) {
return null;
}
SkyKey first = sameFirst ? leaves.get(0) : leaf4;
SkyKey second = sameFirst ? leaf4 : leaves.get(2);
List<SkyKey> secondRequest = ImmutableList.of(first, second);
if (valuesOrThrow) {
env.getValuesOrThrow(secondRequest, SomeErrorException.class);
} else {
env.getValues(secondRequest);
}
if (env.valuesMissing()) {
return null;
}
return new StringValue("top");
}
@Override
public String extractTag(SkyKey skyKey) {
return null;
}
});
eval(/*keepGoing=*/
false, topKey);
assertEquals(new StringValue("top"), eval(/*keepGoing=*/
false, topKey));
}
use of com.google.devtools.build.skyframe.GraphTester.StringValue in project bazel by bazelbuild.
the class ParallelEvaluatorTest method getValuesOrThrowWithErrors.
private void getValuesOrThrowWithErrors(boolean keepGoing) throws Exception {
graph = new InMemoryGraphImpl();
SkyKey parentKey = GraphTester.toSkyKey("parent");
final SkyKey errorDep = GraphTester.toSkyKey("errorChild");
final SomeErrorException childExn = new SomeErrorException("child error");
tester.getOrCreate(errorDep).setBuilder(new SkyFunction() {
@Override
public SkyValue compute(SkyKey skyKey, Environment env) throws SkyFunctionException {
throw new GenericFunctionException(childExn, Transience.PERSISTENT);
}
@Override
public String extractTag(SkyKey skyKey) {
return null;
}
});
final List<SkyKey> deps = new ArrayList<>();
for (int i = 1; i <= 3; i++) {
SkyKey dep = GraphTester.toSkyKey("child" + i);
deps.add(dep);
tester.set(dep, new StringValue("child" + i));
}
final SomeErrorException parentExn = new SomeErrorException("parent error");
tester.getOrCreate(parentKey).setBuilder(new SkyFunction() {
@Override
public SkyValue compute(SkyKey skyKey, Environment env) throws SkyFunctionException, InterruptedException {
try {
SkyValue value = env.getValueOrThrow(errorDep, SomeErrorException.class);
if (value == null) {
return null;
}
} catch (SomeErrorException e) {
// Recover from the child error.
}
env.getValues(deps);
if (env.valuesMissing()) {
return null;
}
throw new GenericFunctionException(parentExn, Transience.PERSISTENT);
}
@Override
public String extractTag(SkyKey skyKey) {
return null;
}
});
EvaluationResult<StringValue> evaluationResult = eval(keepGoing, ImmutableList.of(parentKey));
assertTrue(evaluationResult.hasError());
assertEquals(keepGoing ? parentExn : childExn, evaluationResult.getError().getException());
}
Aggregations