use of com.google.devtools.build.skyframe.GraphTester.ValueComputer 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]);
}
use of com.google.devtools.build.skyframe.GraphTester.ValueComputer in project bazel by bazelbuild.
the class MemoizingEvaluatorTest method checkNotComparableNotPruned.
private void checkNotComparableNotPruned(boolean hasEvent) throws Exception {
initializeTester();
SkyKey parent = GraphTester.toSkyKey("parent");
SkyKey child = GraphTester.toSkyKey("child");
NotComparableStringValue notComparableString = new NotComparableStringValue("not comparable");
if (hasEvent) {
tester.getOrCreate(child).setConstantValue(notComparableString).setWarning("shmoop");
} else {
tester.getOrCreate(child).setConstantValue(notComparableString);
}
final AtomicInteger parentEvaluated = new AtomicInteger();
final String val = "some val";
tester.getOrCreate(parent).addDependency(child).setComputedValue(new ValueComputer() {
@Override
public SkyValue compute(Map<SkyKey, SkyValue> deps, Environment env) throws InterruptedException {
parentEvaluated.incrementAndGet();
return new StringValue(val);
}
});
assertStringValue(val, tester.evalAndGet(/*keepGoing=*/
false, parent));
assertThat(parentEvaluated.get()).isEqualTo(1);
if (hasEvent) {
assertContainsEvent(eventCollector, "shmoop");
} else {
assertEventCount(0, eventCollector);
}
tester.resetPlayedEvents();
tester.getOrCreate(child, /*markAsModified=*/
true);
tester.invalidate();
assertStringValue(val, tester.evalAndGet(/*keepGoing=*/
false, parent));
assertThat(parentEvaluated.get()).isEqualTo(2);
if (hasEvent) {
assertContainsEvent(eventCollector, "shmoop");
} else {
assertEventCount(0, eventCollector);
}
}
use of com.google.devtools.build.skyframe.GraphTester.ValueComputer 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();
}
Aggregations