From cc80878381d589bce3b299eb2e5b538631c82d14 Mon Sep 17 00:00:00 2001 From: Shreya Bhattarai Date: Wed, 10 Feb 2016 22:17:00 +0000 Subject: Allow for more flexibility in choices of Version for the GraphConcurrencyTest by allowing us to set an initial version, as well as a method to return the version's successor. -- MOS_MIGRATED_REVID=114367424 --- .../build/skyframe/GraphConcurrencyTest.java | 22 ++++++++++++++-------- .../skyframe/InMemoryGraphConcurrencyTest.java | 13 +++++++++++++ 2 files changed, 27 insertions(+), 8 deletions(-) (limited to 'src/test/java') diff --git a/src/test/java/com/google/devtools/build/skyframe/GraphConcurrencyTest.java b/src/test/java/com/google/devtools/build/skyframe/GraphConcurrencyTest.java index e0d877e97e..68e30461df 100644 --- a/src/test/java/com/google/devtools/build/skyframe/GraphConcurrencyTest.java +++ b/src/test/java/com/google/devtools/build/skyframe/GraphConcurrencyTest.java @@ -50,6 +50,7 @@ public abstract class GraphConcurrencyTest { private static final SkyFunctionName SKY_FUNCTION_NAME = SkyFunctionName.FOR_TESTING; protected ProcessableGraph graph; protected TestRunnableWrapper wrapper; + private final Version startingVersion = getStartingVersion(); // This code should really be in a @Before method, but @Before methods are executed from the // top down, and this class's @Before method calls #getGraph, so makeGraph must have already @@ -58,11 +59,14 @@ public abstract class GraphConcurrencyTest { protected abstract ProcessableGraph getGraph(Version version) throws Exception; - private static final IntVersion startingVersion = IntVersion.of(42); + protected abstract Version getStartingVersion(); + + protected abstract Version getNextVersion(Version version); @Before public void init() throws Exception { makeGraph(); + Version startingVersion = getStartingVersion(); this.graph = getGraph(startingVersion); this.wrapper = new TestRunnableWrapper("GraphConcurrencyTest"); } @@ -161,13 +165,13 @@ public abstract class GraphConcurrencyTest { assertEquals(new StringValue("foo1"), graph.get(key).getValue()); assertEquals(numKeys + 1, Iterables.size(graph.get(key).getReverseDeps())); - graph = getGraph(startingVersion.next()); + graph = getGraph(getNextVersion(startingVersion)); NodeEntry sameEntry = Preconditions.checkNotNull(graph.get(key)); // Mark the node as dirty again and check that the reverse deps have been preserved. sameEntry.markDirty(true); startEvaluation(sameEntry); sameEntry.markRebuildingAndGetAllRemainingDirtyDirectDeps(); - sameEntry.setValue(new StringValue("foo2"), startingVersion.next()); + sameEntry.setValue(new StringValue("foo2"), getNextVersion(startingVersion)); assertEquals(new StringValue("foo2"), graph.get(key).getValue()); assertEquals(numKeys + 1, Iterables.size(graph.get(key).getReverseDeps())); } @@ -254,7 +258,7 @@ public abstract class GraphConcurrencyTest { } assertNotNull(graph.get(key("foo" + 0))); - graph = getGraph(startingVersion.next()); + graph = getGraph(getNextVersion(startingVersion)); assertNotNull(graph.get(key("foo" + 0))); ExecutorService pool1 = Executors.newFixedThreadPool(numThreads); ExecutorService pool2 = Executors.newFixedThreadPool(numThreads); @@ -288,7 +292,7 @@ public abstract class GraphConcurrencyTest { addTemporaryDirectDep(entry, key("dep")); entry.signalDep(); // Move node from dirty back to done. - entry.setValue(new StringValue("bar" + keyNum), startingVersion.next()); + entry.setValue(new StringValue("bar" + keyNum), getNextVersion(startingVersion)); } }; @@ -307,7 +311,8 @@ public abstract class GraphConcurrencyTest { // Requests for the value are made at the same time that the version increments from // the base. Check that there is no problem in requesting the version and that the // number is sane. - assertThat(entry.getVersion()).isAnyOf(startingVersion, startingVersion.next()); + assertThat(entry.getVersion()).isAnyOf(startingVersion, + getNextVersion(startingVersion)); getCountDownLatch.countDown(); } }; @@ -341,7 +346,8 @@ public abstract class GraphConcurrencyTest { // Batch requests are made at the same time that the version increments from the // base. Check that there is no problem in requesting the version and that the // number is sane. - assertThat(entry.getVersion()).isAnyOf(startingVersion, startingVersion.next()); + assertThat(entry.getVersion()).isAnyOf(startingVersion, + getNextVersion(startingVersion)); } } }; @@ -354,7 +360,7 @@ public abstract class GraphConcurrencyTest { for (int i = 0; i < numKeys; i++) { NodeEntry entry = graph.get(key("foo" + i)); assertThat(entry.getValue()).isEqualTo(new StringValue("bar" + i)); - assertThat(entry.getVersion()).isEqualTo(startingVersion.next()); + assertThat(entry.getVersion()).isEqualTo(getNextVersion(startingVersion)); for (SkyKey key : entry.getReverseDeps()) { assertEquals(key("rdep"), key); } diff --git a/src/test/java/com/google/devtools/build/skyframe/InMemoryGraphConcurrencyTest.java b/src/test/java/com/google/devtools/build/skyframe/InMemoryGraphConcurrencyTest.java index d02200e775..28f0da30e6 100644 --- a/src/test/java/com/google/devtools/build/skyframe/InMemoryGraphConcurrencyTest.java +++ b/src/test/java/com/google/devtools/build/skyframe/InMemoryGraphConcurrencyTest.java @@ -13,6 +13,8 @@ // limitations under the License. package com.google.devtools.build.skyframe; +import com.google.devtools.build.lib.util.Preconditions; + import org.junit.runner.RunWith; import org.junit.runners.JUnit4; @@ -21,6 +23,17 @@ import org.junit.runners.JUnit4; public class InMemoryGraphConcurrencyTest extends GraphConcurrencyTest { private ProcessableGraph graph; + @Override + protected Version getStartingVersion() { + return IntVersion.of(0); + } + + @Override + protected Version getNextVersion(Version v) { + Preconditions.checkState(v instanceof IntVersion); + return ((IntVersion) v).next(); + } + @Override protected void makeGraph() { graph = new InMemoryGraph(); -- cgit v1.2.3