aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test/java/com/google
diff options
context:
space:
mode:
authorGravatar Janak Ramakrishnan <janakr@google.com>2017-03-23 20:50:08 +0000
committerGravatar Yue Gan <yueg@google.com>2017-03-24 12:18:01 +0000
commitcb8a97dff9218de0b32fc54ac465efbe41315bfa (patch)
treed3016403ab7cbf29f8aa9bda134796b4ac88bebc /src/test/java/com/google
parent7bb3ba00d231399a4ffcbf2b22753eed1e249a30 (diff)
Stop storing reverse deps to signal in BuildingState. Instead, re-use the reverseDepsToConsolidate field in InMemoryNodeEntry. As part of that, revamp our logic of how we store pending operations: store adds bare on initial evaluations, and checks bare on incremental evaluations and operations on done nodes.
This should improve performance in two ways: BuildingState loses two fields, saving working memory intra-build. Storing pending reverse dep operations bare also saves memory intra-build. Note that neither of these changes helps resting memory state, only while a node is still evaluating. Because of this, we can simplify ReverseDepsUtil a bit, making ReverseDepsUtilImpl a static class, which it always wanted to be (what it really wants to be is a superclass of InMemoryNodeEntry, but I don't want to spend the object alignment bits). Finally, this makes it pretty tempting to get rid of BuildingState altogether on initial evaluations. We'd still keep DirtyBuildingState, but we could save another ~24 bytes by storing BuildingState's one remaining field, signaledDeps, directly inside InMemoryNodeEntry. -- PiperOrigin-RevId: 151048879 MOS_MIGRATED_REVID=151048879
Diffstat (limited to 'src/test/java/com/google')
-rw-r--r--src/test/java/com/google/devtools/build/skyframe/DeterministicHelper.java5
-rw-r--r--src/test/java/com/google/devtools/build/skyframe/EagerInvalidatorTest.java24
-rw-r--r--src/test/java/com/google/devtools/build/skyframe/GraphTest.java12
-rw-r--r--src/test/java/com/google/devtools/build/skyframe/InMemoryNodeEntryTest.java14
-rw-r--r--src/test/java/com/google/devtools/build/skyframe/ReverseDepsUtilImplTest.java199
-rw-r--r--src/test/java/com/google/devtools/build/skyframe/ReverseDepsUtilityTest.java162
6 files changed, 192 insertions, 224 deletions
diff --git a/src/test/java/com/google/devtools/build/skyframe/DeterministicHelper.java b/src/test/java/com/google/devtools/build/skyframe/DeterministicHelper.java
index 49db9cdc0b..7876d57100 100644
--- a/src/test/java/com/google/devtools/build/skyframe/DeterministicHelper.java
+++ b/src/test/java/com/google/devtools/build/skyframe/DeterministicHelper.java
@@ -135,9 +135,10 @@ public class DeterministicHelper extends NotifyingHelper {
}
@Override
- public synchronized Collection<SkyKey> getReverseDeps() throws InterruptedException {
+ public synchronized Collection<SkyKey> getReverseDepsForDoneEntry()
+ throws InterruptedException {
TreeSet<SkyKey> result = new TreeSet<>(ALPHABETICAL_SKYKEY_COMPARATOR);
- Iterables.addAll(result, super.getReverseDeps());
+ Iterables.addAll(result, super.getReverseDepsForDoneEntry());
return result;
}
diff --git a/src/test/java/com/google/devtools/build/skyframe/EagerInvalidatorTest.java b/src/test/java/com/google/devtools/build/skyframe/EagerInvalidatorTest.java
index cfb656bf56..2ab03467ba 100644
--- a/src/test/java/com/google/devtools/build/skyframe/EagerInvalidatorTest.java
+++ b/src/test/java/com/google/devtools/build/skyframe/EagerInvalidatorTest.java
@@ -337,12 +337,12 @@ public class EagerInvalidatorTest {
.setComputedValue(CONCATENATE);
eval(false, skyKey("ab_c"), skyKey("bc"));
- assertThat(graph.get(null, Reason.OTHER, skyKey("a"))
- .getReverseDeps()).containsExactly(skyKey("ab"));
- assertThat(graph.get(null, Reason.OTHER, skyKey("b"))
- .getReverseDeps()).containsExactly(skyKey("ab"), skyKey("bc"));
- assertThat(graph.get(null, Reason.OTHER, skyKey("c"))
- .getReverseDeps()).containsExactly(skyKey("ab_c"), skyKey("bc"));
+ assertThat(graph.get(null, Reason.OTHER, skyKey("a")).getReverseDepsForDoneEntry())
+ .containsExactly(skyKey("ab"));
+ assertThat(graph.get(null, Reason.OTHER, skyKey("b")).getReverseDepsForDoneEntry())
+ .containsExactly(skyKey("ab"), skyKey("bc"));
+ assertThat(graph.get(null, Reason.OTHER, skyKey("c")).getReverseDepsForDoneEntry())
+ .containsExactly(skyKey("ab_c"), skyKey("bc"));
invalidateWithoutError(new DirtyTrackingProgressReceiver(null), skyKey("ab"));
eval(false);
@@ -356,18 +356,18 @@ public class EagerInvalidatorTest {
if (reverseDepsPresent()) {
reverseDeps.add(skyKey("ab"));
}
- assertThat(graph.get(null, Reason.OTHER, skyKey("a"))
- .getReverseDeps()).containsExactlyElementsIn(reverseDeps);
+ assertThat(graph.get(null, Reason.OTHER, skyKey("a")).getReverseDepsForDoneEntry())
+ .containsExactlyElementsIn(reverseDeps);
reverseDeps.add(skyKey("bc"));
- assertThat(graph.get(null, Reason.OTHER, skyKey("b"))
- .getReverseDeps()).containsExactlyElementsIn(reverseDeps);
+ assertThat(graph.get(null, Reason.OTHER, skyKey("b")).getReverseDepsForDoneEntry())
+ .containsExactlyElementsIn(reverseDeps);
reverseDeps.clear();
if (reverseDepsPresent()) {
reverseDeps.add(skyKey("ab_c"));
}
reverseDeps.add(skyKey("bc"));
- assertThat(graph.get(null, Reason.OTHER, skyKey("c"))
- .getReverseDeps()).containsExactlyElementsIn(reverseDeps);
+ assertThat(graph.get(null, Reason.OTHER, skyKey("c")).getReverseDepsForDoneEntry())
+ .containsExactlyElementsIn(reverseDeps);
}
@Test
diff --git a/src/test/java/com/google/devtools/build/skyframe/GraphTest.java b/src/test/java/com/google/devtools/build/skyframe/GraphTest.java
index 0510523cbe..932878fbe2 100644
--- a/src/test/java/com/google/devtools/build/skyframe/GraphTest.java
+++ b/src/test/java/com/google/devtools/build/skyframe/GraphTest.java
@@ -197,7 +197,7 @@ public abstract class GraphTest {
for (int k = chunkSize; k <= numIterations; k++) {
entry.removeReverseDep(key("rdep" + j));
entry.addReverseDepAndCheckIfDone(key("rdep" + j));
- entry.getReverseDeps();
+ entry.getReverseDepsForDoneEntry();
}
} catch (InterruptedException e) {
fail("Test failed: " + e.toString());
@@ -213,7 +213,9 @@ public abstract class GraphTest {
wrapper.waitForTasksAndMaybeThrow();
assertFalse(ExecutorUtil.interruptibleShutdown(pool));
assertEquals(new StringValue("foo1"), graph.get(null, Reason.OTHER, key).getValue());
- assertEquals(numKeys + 1, Iterables.size(graph.get(null, Reason.OTHER, key).getReverseDeps()));
+ assertEquals(
+ numKeys + 1,
+ Iterables.size(graph.get(null, Reason.OTHER, key).getReverseDepsForDoneEntry()));
graph = getGraph(getNextVersion(startingVersion));
NodeEntry sameEntry = Preconditions.checkNotNull(graph.get(null, Reason.OTHER, key));
@@ -223,7 +225,9 @@ public abstract class GraphTest {
sameEntry.markRebuilding();
sameEntry.setValue(new StringValue("foo2"), getNextVersion(startingVersion));
assertEquals(new StringValue("foo2"), graph.get(null, Reason.OTHER, key).getValue());
- assertEquals(numKeys + 1, Iterables.size(graph.get(null, Reason.OTHER, key).getReverseDeps()));
+ assertEquals(
+ numKeys + 1,
+ Iterables.size(graph.get(null, Reason.OTHER, key).getReverseDepsForDoneEntry()));
}
// Tests adding inflight nodes with a given key while an existing node with the same key
@@ -451,7 +455,7 @@ public abstract class GraphTest {
NodeEntry entry = graph.get(null, Reason.OTHER, key("foo" + i));
assertThat(entry.getValue()).isEqualTo(new StringValue("bar" + i));
assertThat(entry.getVersion()).isEqualTo(getNextVersion(startingVersion));
- for (SkyKey key : entry.getReverseDeps()) {
+ for (SkyKey key : entry.getReverseDepsForDoneEntry()) {
assertEquals(key("rdep"), key);
}
for (SkyKey key : entry.getDirectDeps()) {
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 8b8fb81c8c..5829329452 100644
--- a/src/test/java/com/google/devtools/build/skyframe/InMemoryNodeEntryTest.java
+++ b/src/test/java/com/google/devtools/build/skyframe/InMemoryNodeEntryTest.java
@@ -101,10 +101,10 @@ public class InMemoryNodeEntryTest {
assertEquals(DependencyState.ALREADY_EVALUATING, entry.addReverseDepAndCheckIfDone(father));
assertThat(setValue(entry, new SkyValue() {},
/*errorInfo=*/null, /*graphVersion=*/0L)).containsExactly(mother, father);
- assertThat(entry.getReverseDeps()).containsExactly(mother, father);
+ assertThat(entry.getReverseDepsForDoneEntry()).containsExactly(mother, father);
assertTrue(entry.isDone());
entry.removeReverseDep(mother);
- assertFalse(Iterables.contains(entry.getReverseDeps(), mother));
+ assertFalse(Iterables.contains(entry.getReverseDepsForDoneEntry(), mother));
}
@Test
@@ -337,7 +337,7 @@ public class InMemoryNodeEntryTest {
try {
entry.addReverseDepAndCheckIfDone(parent);
// We only check for duplicates when we request all the reverse deps.
- entry.getReverseDeps();
+ entry.getReverseDepsForDoneEntry();
fail("Cannot add same dep twice");
} catch (IllegalStateException e) {
// Expected.
@@ -353,7 +353,7 @@ public class InMemoryNodeEntryTest {
try {
entry.addReverseDepAndCheckIfDone(parent);
// We only check for duplicates when we request all the reverse deps.
- entry.getReverseDeps();
+ entry.getReverseDepsForDoneEntry();
fail("Cannot add same dep twice");
} catch (IllegalStateException e) {
// Expected.
@@ -692,9 +692,9 @@ public class InMemoryNodeEntryTest {
assertThat(clone1.getDirectDeps()).containsExactly(originalChild);
assertThat(clone2.getDirectDeps()).containsExactly(newChild);
- assertThat(entry.getReverseDeps()).hasSize(0);
- assertThat(clone1.getReverseDeps()).containsExactly(key("parent1"));
- assertThat(clone2.getReverseDeps()).containsExactly(key("parent1"), key("parent2"));
+ assertThat(entry.getReverseDepsForDoneEntry()).hasSize(0);
+ assertThat(clone1.getReverseDepsForDoneEntry()).containsExactly(key("parent1"));
+ assertThat(clone2.getReverseDepsForDoneEntry()).containsExactly(key("parent1"), key("parent2"));
}
@Test
diff --git a/src/test/java/com/google/devtools/build/skyframe/ReverseDepsUtilImplTest.java b/src/test/java/com/google/devtools/build/skyframe/ReverseDepsUtilImplTest.java
deleted file mode 100644
index d66dc6762a..0000000000
--- a/src/test/java/com/google/devtools/build/skyframe/ReverseDepsUtilImplTest.java
+++ /dev/null
@@ -1,199 +0,0 @@
-// Copyright 2014 The Bazel Authors. All rights reserved.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-package com.google.devtools.build.skyframe;
-
-import static com.google.common.truth.Truth.assertThat;
-
-import com.google.common.collect.ImmutableList;
-
-import org.junit.Assert;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
-import org.junit.runners.Parameterized.Parameters;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-
-/**
- * Test for {@code ReverseDepsUtilImpl}.
- */
-@RunWith(Parameterized.class)
-public class ReverseDepsUtilImplTest {
-
- private static final SkyFunctionName NODE_TYPE = SkyFunctionName.create("Type");
- private final int numElements;
-
- @Parameters(name = "numElements-{0}")
- public static List<Object[]> paramenters() {
- List<Object[]> params = new ArrayList<>();
- for (int i = 0; i < 20; i++) {
- params.add(new Object[] {i});
- }
- return params;
- }
-
- public ReverseDepsUtilImplTest(int numElements) {
- this.numElements = numElements;
- }
-
- private static final ReverseDepsUtil<Example> REVERSE_DEPS_UTIL =
- new ReverseDepsUtilImpl<Example>() {
- @Override
- void setReverseDepsObject(Example container, Object object) {
- container.reverseDeps = object;
- }
-
- @Override
- void setDataToConsolidate(Example container, List<Object> dataToConsolidate) {
- container.dataToConsolidate = dataToConsolidate;
- }
-
- @Override
- Object getReverseDepsObject(Example container) {
- return container.reverseDeps;
- }
-
- @Override
- List<Object> getDataToConsolidate(Example container) {
- return container.dataToConsolidate;
- }
- };
-
- private class Example {
-
- Object reverseDeps = ImmutableList.of();
- boolean single;
- List<Object> dataToConsolidate;
-
- @Override
- public String toString() {
- return "Example: " + reverseDeps + ", " + single + ", " + dataToConsolidate;
- }
- }
-
- @Test
- public void testAddAndRemove() {
- for (int numRemovals = 0; numRemovals <= numElements; numRemovals++) {
- Example example = new Example();
- for (int j = 0; j < numElements; j++) {
- REVERSE_DEPS_UTIL.addReverseDeps(
- example, Collections.singleton(SkyKey.create(NODE_TYPE, j)));
- }
- // Not a big test but at least check that it does not blow up.
- assertThat(REVERSE_DEPS_UTIL.toString(example)).isNotEmpty();
- assertThat(REVERSE_DEPS_UTIL.getReverseDeps(example)).hasSize(numElements);
- for (int i = 0; i < numRemovals; i++) {
- REVERSE_DEPS_UTIL.removeReverseDep(example, SkyKey.create(NODE_TYPE, i));
- }
- assertThat(REVERSE_DEPS_UTIL.getReverseDeps(example)).hasSize(numElements - numRemovals);
- assertThat(example.dataToConsolidate).isNull();
- }
- }
-
- // Same as testAdditionAndRemoval but we add all the reverse deps in one call.
- @Test
- public void testAddAllAndRemove() {
- for (int numRemovals = 0; numRemovals <= numElements; numRemovals++) {
- Example example = new Example();
- List<SkyKey> toAdd = new ArrayList<>();
- for (int j = 0; j < numElements; j++) {
- toAdd.add(SkyKey.create(NODE_TYPE, j));
- }
- REVERSE_DEPS_UTIL.addReverseDeps(example, toAdd);
- assertThat(REVERSE_DEPS_UTIL.getReverseDeps(example)).hasSize(numElements);
- for (int i = 0; i < numRemovals; i++) {
- REVERSE_DEPS_UTIL.removeReverseDep(example, SkyKey.create(NODE_TYPE, i));
- }
- assertThat(REVERSE_DEPS_UTIL.getReverseDeps(example)).hasSize(numElements - numRemovals);
- assertThat(example.dataToConsolidate).isNull();
- }
- }
-
- @Test
- public void testDuplicateCheckOnGetReverseDeps() {
- Example example = new Example();
- for (int i = 0; i < numElements; i++) {
- REVERSE_DEPS_UTIL.addReverseDeps(example, Collections.singleton(SkyKey.create(NODE_TYPE, i)));
- }
- // Should only fail when we call getReverseDeps().
- REVERSE_DEPS_UTIL.addReverseDeps(example, Collections.singleton(SkyKey.create(NODE_TYPE, 0)));
- try {
- REVERSE_DEPS_UTIL.getReverseDeps(example);
- assertThat(numElements).isEqualTo(0);
- } catch (Exception expected) {
- }
- }
-
- @Test
- public void doubleAddThenRemove() {
- Example example = new Example();
- SkyKey key = SkyKey.create(NODE_TYPE, 0);
- REVERSE_DEPS_UTIL.addReverseDeps(example, Collections.singleton(key));
- // Should only fail when we call getReverseDeps().
- REVERSE_DEPS_UTIL.addReverseDeps(example, Collections.singleton(key));
- REVERSE_DEPS_UTIL.removeReverseDep(example, key);
- try {
- REVERSE_DEPS_UTIL.getReverseDeps(example);
- Assert.fail();
- } catch (IllegalStateException expected) {
- }
- }
-
- @Test
- public void doubleAddThenRemoveCheckedOnSize() {
- Example example = new Example();
- SkyKey fixedKey = SkyKey.create(NODE_TYPE, 0);
- SkyKey key = SkyKey.create(NODE_TYPE, 1);
- REVERSE_DEPS_UTIL.addReverseDeps(example, ImmutableList.of(fixedKey, key));
- // Should only fail when we reach the limit.
- REVERSE_DEPS_UTIL.addReverseDeps(example, Collections.singleton(key));
- REVERSE_DEPS_UTIL.removeReverseDep(example, key);
- REVERSE_DEPS_UTIL.checkReverseDep(example, fixedKey);
- try {
- REVERSE_DEPS_UTIL.checkReverseDep(example, fixedKey);
- Assert.fail();
- } catch (IllegalStateException expected) {
- }
- }
-
- @Test
- public void addRemoveAdd() {
- Example example = new Example();
- SkyKey fixedKey = SkyKey.create(NODE_TYPE, 0);
- SkyKey key = SkyKey.create(NODE_TYPE, 1);
- REVERSE_DEPS_UTIL.addReverseDeps(example, ImmutableList.of(fixedKey, key));
- REVERSE_DEPS_UTIL.removeReverseDep(example, key);
- REVERSE_DEPS_UTIL.addReverseDeps(example, Collections.singleton(key));
- assertThat(REVERSE_DEPS_UTIL.getReverseDeps(example)).containsExactly(fixedKey, key);
- }
-
- @Test
- public void testMaybeCheck() {
- Example example = new Example();
- for (int i = 0; i < numElements; i++) {
- REVERSE_DEPS_UTIL.addReverseDeps(example, Collections.singleton(SkyKey.create(NODE_TYPE, i)));
- // This should always succeed, since the next element is still not present.
- REVERSE_DEPS_UTIL.maybeCheckReverseDepNotPresent(example, SkyKey.create(NODE_TYPE, i + 1));
- }
- try {
- REVERSE_DEPS_UTIL.maybeCheckReverseDepNotPresent(example, SkyKey.create(NODE_TYPE, 0));
- // Should only fail if empty or above the checking threshold.
- assertThat(numElements == 0 || numElements >= ReverseDepsUtilImpl.MAYBE_CHECK_THRESHOLD)
- .isTrue();
- } catch (Exception expected) {
- }
- }
-}
diff --git a/src/test/java/com/google/devtools/build/skyframe/ReverseDepsUtilityTest.java b/src/test/java/com/google/devtools/build/skyframe/ReverseDepsUtilityTest.java
new file mode 100644
index 0000000000..3001c2a43f
--- /dev/null
+++ b/src/test/java/com/google/devtools/build/skyframe/ReverseDepsUtilityTest.java
@@ -0,0 +1,162 @@
+// Copyright 2014 The Bazel Authors. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+package com.google.devtools.build.skyframe;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import com.google.common.collect.ImmutableList;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
+
+/** Test for {@code ReverseDepsUtility}. */
+@RunWith(Parameterized.class)
+public class ReverseDepsUtilityTest {
+
+ private static final SkyFunctionName NODE_TYPE = SkyFunctionName.create("Type");
+ private final int numElements;
+
+ @Parameters(name = "numElements-{0}")
+ public static List<Object[]> paramenters() {
+ List<Object[]> params = new ArrayList<>();
+ for (int i = 0; i < 20; i++) {
+ params.add(new Object[] {i});
+ }
+ return params;
+ }
+
+ public ReverseDepsUtilityTest(int numElements) {
+ this.numElements = numElements;
+ }
+
+ @Test
+ public void testAddAndRemove() {
+ for (int numRemovals = 0; numRemovals <= numElements; numRemovals++) {
+ InMemoryNodeEntry example = new InMemoryNodeEntry();
+ for (int j = 0; j < numElements; j++) {
+ ReverseDepsUtility.addReverseDeps(
+ example, Collections.singleton(SkyKey.create(NODE_TYPE, j)));
+ }
+ // Not a big test but at least check that it does not blow up.
+ assertThat(ReverseDepsUtility.toString(example)).isNotEmpty();
+ assertThat(ReverseDepsUtility.getReverseDeps(example)).hasSize(numElements);
+ for (int i = 0; i < numRemovals; i++) {
+ ReverseDepsUtility.removeReverseDep(example, SkyKey.create(NODE_TYPE, i));
+ }
+ assertThat(ReverseDepsUtility.getReverseDeps(example)).hasSize(numElements - numRemovals);
+ assertThat(example.getReverseDepsDataToConsolidateForReverseDepsUtil()).isNull();
+ }
+ }
+
+ // Same as testAdditionAndRemoval but we add all the reverse deps in one call.
+ @Test
+ public void testAddAllAndRemove() {
+ for (int numRemovals = 0; numRemovals <= numElements; numRemovals++) {
+ InMemoryNodeEntry example = new InMemoryNodeEntry();
+ List<SkyKey> toAdd = new ArrayList<>();
+ for (int j = 0; j < numElements; j++) {
+ toAdd.add(SkyKey.create(NODE_TYPE, j));
+ }
+ ReverseDepsUtility.addReverseDeps(example, toAdd);
+ assertThat(ReverseDepsUtility.getReverseDeps(example)).hasSize(numElements);
+ for (int i = 0; i < numRemovals; i++) {
+ ReverseDepsUtility.removeReverseDep(example, SkyKey.create(NODE_TYPE, i));
+ }
+ assertThat(ReverseDepsUtility.getReverseDeps(example)).hasSize(numElements - numRemovals);
+ assertThat(example.getReverseDepsDataToConsolidateForReverseDepsUtil()).isNull();
+ }
+ }
+
+ @Test
+ public void testDuplicateCheckOnGetReverseDeps() {
+ InMemoryNodeEntry example = new InMemoryNodeEntry();
+ for (int i = 0; i < numElements; i++) {
+ ReverseDepsUtility.addReverseDeps(
+ example, Collections.singleton(SkyKey.create(NODE_TYPE, i)));
+ }
+ // Should only fail when we call getReverseDeps().
+ ReverseDepsUtility.addReverseDeps(example, Collections.singleton(SkyKey.create(NODE_TYPE, 0)));
+ try {
+ ReverseDepsUtility.getReverseDeps(example);
+ assertThat(numElements).isEqualTo(0);
+ } catch (Exception expected) {
+ }
+ }
+
+ @Test
+ public void doubleAddThenRemove() {
+ InMemoryNodeEntry example = new InMemoryNodeEntry();
+ SkyKey key = SkyKey.create(NODE_TYPE, 0);
+ ReverseDepsUtility.addReverseDeps(example, Collections.singleton(key));
+ // Should only fail when we call getReverseDeps().
+ ReverseDepsUtility.addReverseDeps(example, Collections.singleton(key));
+ ReverseDepsUtility.removeReverseDep(example, key);
+ try {
+ ReverseDepsUtility.getReverseDeps(example);
+ Assert.fail();
+ } catch (IllegalStateException expected) {
+ }
+ }
+
+ @Test
+ public void doubleAddThenRemoveCheckedOnSize() {
+ InMemoryNodeEntry example = new InMemoryNodeEntry();
+ SkyKey fixedKey = SkyKey.create(NODE_TYPE, 0);
+ SkyKey key = SkyKey.create(NODE_TYPE, 1);
+ ReverseDepsUtility.addReverseDeps(example, ImmutableList.of(fixedKey, key));
+ // Should only fail when we reach the limit.
+ ReverseDepsUtility.addReverseDeps(example, Collections.singleton(key));
+ ReverseDepsUtility.removeReverseDep(example, key);
+ ReverseDepsUtility.checkReverseDep(example, fixedKey);
+ try {
+ ReverseDepsUtility.checkReverseDep(example, fixedKey);
+ Assert.fail();
+ } catch (IllegalStateException expected) {
+ }
+ }
+
+ @Test
+ public void addRemoveAdd() {
+ InMemoryNodeEntry example = new InMemoryNodeEntry();
+ SkyKey fixedKey = SkyKey.create(NODE_TYPE, 0);
+ SkyKey key = SkyKey.create(NODE_TYPE, 1);
+ ReverseDepsUtility.addReverseDeps(example, ImmutableList.of(fixedKey, key));
+ ReverseDepsUtility.removeReverseDep(example, key);
+ ReverseDepsUtility.addReverseDeps(example, Collections.singleton(key));
+ assertThat(ReverseDepsUtility.getReverseDeps(example)).containsExactly(fixedKey, key);
+ }
+
+ @Test
+ public void testMaybeCheck() {
+ InMemoryNodeEntry example = new InMemoryNodeEntry();
+ for (int i = 0; i < numElements; i++) {
+ ReverseDepsUtility.addReverseDeps(
+ example, Collections.singleton(SkyKey.create(NODE_TYPE, i)));
+ // This should always succeed, since the next element is still not present.
+ ReverseDepsUtility.maybeCheckReverseDepNotPresent(example, SkyKey.create(NODE_TYPE, i + 1));
+ }
+ try {
+ ReverseDepsUtility.maybeCheckReverseDepNotPresent(example, SkyKey.create(NODE_TYPE, 0));
+ // Should only fail if empty or above the checking threshold.
+ assertThat(numElements == 0 || numElements >= ReverseDepsUtility.MAYBE_CHECK_THRESHOLD)
+ .isTrue();
+ } catch (Exception expected) {
+ }
+ }
+}