aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test/java/com/google/devtools
diff options
context:
space:
mode:
authorGravatar Eric Fellheimer <felly@google.com>2015-11-19 02:16:24 +0000
committerGravatar Damien Martin-Guillerez <dmarting@google.com>2015-11-19 10:04:36 +0000
commit26b3d8532cda8e38244b33222935e5c478d25ad0 (patch)
tree85becd59cc73bbcff56365a59fb41bfaf24c1b3c /src/test/java/com/google/devtools
parent3ac42bf4a979c96e73fd79fb8f5416ae7d7621eb (diff)
Allow SkyValues to be marked not "comparable". Such values are not compared for the purpose of change pruning.
-- MOS_MIGRATED_REVID=108203369
Diffstat (limited to 'src/test/java/com/google/devtools')
-rw-r--r--src/test/java/com/google/devtools/build/skyframe/GraphTester.java20
-rw-r--r--src/test/java/com/google/devtools/build/skyframe/InMemoryNodeEntryTest.java5
-rw-r--r--src/test/java/com/google/devtools/build/skyframe/MemoizingEvaluatorTest.java59
3 files changed, 81 insertions, 3 deletions
diff --git a/src/test/java/com/google/devtools/build/skyframe/GraphTester.java b/src/test/java/com/google/devtools/build/skyframe/GraphTester.java
index 2d44e9ddc5..2a3fc1b4af 100644
--- a/src/test/java/com/google/devtools/build/skyframe/GraphTester.java
+++ b/src/test/java/com/google/devtools/build/skyframe/GraphTester.java
@@ -291,7 +291,7 @@ public class GraphTester {
* Simple value class that stores strings.
*/
public static class StringValue implements SkyValue {
- private final String value;
+ protected final String value;
public StringValue(String value) {
this.value = value;
@@ -329,6 +329,24 @@ public class GraphTester {
}
}
+ /** A StringValue that is also a NotComparableSkyValue. */
+ public static class NotComparableStringValue extends StringValue
+ implements NotComparableSkyValue {
+ public NotComparableStringValue(String value) {
+ super(value);
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ throw new UnsupportedOperationException(value + " is incomparable - what are you doing?");
+ }
+
+ @Override
+ public int hashCode() {
+ throw new UnsupportedOperationException(value + " is incomparable - what are you doing?");
+ }
+ }
+
/**
* A callback interface to provide the value computation.
*/
diff --git a/src/test/java/com/google/devtools/build/skyframe/InMemoryNodeEntryTest.java b/src/test/java/com/google/devtools/build/skyframe/InMemoryNodeEntryTest.java
index 8b7c0d2c8c..0304513344 100644
--- a/src/test/java/com/google/devtools/build/skyframe/InMemoryNodeEntryTest.java
+++ b/src/test/java/com/google/devtools/build/skyframe/InMemoryNodeEntryTest.java
@@ -492,7 +492,7 @@ public class InMemoryNodeEntryTest {
}
@Test
- public void pruneErrorValue() {
+ public void errorInfoCannotBePruned() {
NodeEntry entry = new InMemoryNodeEntry();
entry.addReverseDepAndCheckIfDone(null); // Start evaluation.
SkyKey dep = key("dep");
@@ -514,7 +514,8 @@ public class InMemoryNodeEntryTest {
assertThat(entry.markRebuildingAndGetAllRemainingDirtyDirectDeps()).isEmpty();
setValue(entry, /*value=*/null, errorInfo, /*graphVersion=*/1L);
assertTrue(entry.isDone());
- assertEquals(new IntVersion(0L), entry.getVersion());
+ // ErrorInfo is treated as a NotComparableSkyValue, so it is not pruned.
+ assertEquals(new IntVersion(1L), entry.getVersion());
}
@Test
diff --git a/src/test/java/com/google/devtools/build/skyframe/MemoizingEvaluatorTest.java b/src/test/java/com/google/devtools/build/skyframe/MemoizingEvaluatorTest.java
index fdae6b25c0..a24e93cff1 100644
--- a/src/test/java/com/google/devtools/build/skyframe/MemoizingEvaluatorTest.java
+++ b/src/test/java/com/google/devtools/build/skyframe/MemoizingEvaluatorTest.java
@@ -45,12 +45,14 @@ import com.google.devtools.build.lib.events.EventHandler;
import com.google.devtools.build.lib.events.EventKind;
import com.google.devtools.build.lib.testutil.TestThread;
import com.google.devtools.build.lib.testutil.TestUtils;
+import com.google.devtools.build.skyframe.GraphTester.NotComparableStringValue;
import com.google.devtools.build.skyframe.GraphTester.StringValue;
import com.google.devtools.build.skyframe.GraphTester.TestFunction;
import com.google.devtools.build.skyframe.GraphTester.ValueComputer;
import com.google.devtools.build.skyframe.NotifyingInMemoryGraph.EventType;
import com.google.devtools.build.skyframe.NotifyingInMemoryGraph.Listener;
import com.google.devtools.build.skyframe.NotifyingInMemoryGraph.Order;
+import com.google.devtools.build.skyframe.SkyFunction.Environment;
import com.google.devtools.build.skyframe.SkyFunctionException.Transience;
import org.junit.After;
@@ -3113,6 +3115,63 @@ public class MemoizingEvaluatorTest {
}
@Test
+ public void notComparableNotPrunedNoEvent() throws Exception {
+ checkNotComparableNotPruned(false);
+ }
+
+ @Test
+ public void notComparableNotPrunedEvent() throws Exception {
+ checkNotComparableNotPruned(true);
+ }
+
+ 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);
+ }
+ }
+
+ private static void assertStringValue(String expected, SkyValue val) {
+ assertThat(((StringValue) val).getValue()).isEqualTo(expected);
+ }
+
+ @Test
public void changePruningWithEvent() throws Exception {
initializeTester();
SkyKey parent = GraphTester.toSkyKey("parent");