diff options
author | nharmata <nharmata@google.com> | 2017-10-31 14:11:56 -0400 |
---|---|---|
committer | John Cater <jcater@google.com> | 2017-11-01 09:58:50 -0400 |
commit | f411e2ef94e7268286a810741fff2ba324fe72c3 (patch) | |
tree | 83becf5809341c7a21e97fc6d433e842faaa09e9 /src/test/java/com/google/devtools/build/lib/concurrent/MultisetSemaphoreTest.java | |
parent | 18462d516727ce3b43773506bca4b2e4424d43b2 (diff) |
Add a 'estimateCurrentNumUniqueValues' method to MultisetSemaphore.
RELNOTES: None
PiperOrigin-RevId: 174062560
Diffstat (limited to 'src/test/java/com/google/devtools/build/lib/concurrent/MultisetSemaphoreTest.java')
-rw-r--r-- | src/test/java/com/google/devtools/build/lib/concurrent/MultisetSemaphoreTest.java | 31 |
1 files changed, 21 insertions, 10 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/concurrent/MultisetSemaphoreTest.java b/src/test/java/com/google/devtools/build/lib/concurrent/MultisetSemaphoreTest.java index 6e75c0d26b..8d659fd0f5 100644 --- a/src/test/java/com/google/devtools/build/lib/concurrent/MultisetSemaphoreTest.java +++ b/src/test/java/com/google/devtools/build/lib/concurrent/MultisetSemaphoreTest.java @@ -45,17 +45,27 @@ public class MultisetSemaphoreTest { .maxNumUniqueValues(3) .build(); - // And we serially acquire permits for 3 unique values + // And we serially acquire permits for 3 unique values, multisetSemaphore.acquireAll(ImmutableSet.of("a", "b", "c")); + // Then the MultisetSemaphore thinks it currently has 3 unique values. + assertThat(multisetSemaphore.estimateCurrentNumUniqueValues()).isEqualTo(3); // And then attempt to acquire permits for 2 of those same unique values, - // Then we don't deadlock. + // Then we don't deadlock, multisetSemaphore.acquireAll(ImmutableSet.of("b", "c")); + // And the MultisetSemaphore still thinks it currently has 3 unique values. + assertThat(multisetSemaphore.estimateCurrentNumUniqueValues()).isEqualTo(3); // And then we release one of the permit for one of those unique values, multisetSemaphore.releaseAll(ImmutableSet.of("c")); - // And then we release the other permit, + // Then the MultisetSemaphore still thinks it currently has 3 unique values. + assertThat(multisetSemaphore.estimateCurrentNumUniqueValues()).isEqualTo(3); + // And then we release the final permit for that unique value, multisetSemaphore.releaseAll(ImmutableSet.of("c")); - // We are able to acquire a permit for a 4th unique value. + // Then the MultisetSemaphore thinks it currently has 2 unique values. + assertThat(multisetSemaphore.estimateCurrentNumUniqueValues()).isEqualTo(2); + // And we are able to acquire a permit for a 4th unique value, multisetSemaphore.acquireAll(ImmutableSet.of("d")); + // And the MultisetSemaphore thinks it currently has 3 unique values. + assertThat(multisetSemaphore.estimateCurrentNumUniqueValues()).isEqualTo(3); } @Test @@ -171,12 +181,13 @@ public class MultisetSemaphoreTest { public void run() { try { Set<String> vals = ImmutableSet.of(sameVal, differentVal); - // Tries to acquire a permit for a set of two values, one of which is the same for all - // the N Runnables and one of which is unique across all N Runnables. + // Tries to acquire a permit for a set of two values, one of which is the + // same for all the N Runnables and one of which is unique across all N + // Runnables, multisetSemaphore.acquireAll(vals); - // And then sleeps + // And then sleeps, Thread.sleep(napTimeMs); - // And then releases its permits + // And then releases its permits, multisetSemaphore.releaseAll(vals); // And then counts down the done latch, allDoneLatch.countDown(); @@ -230,8 +241,8 @@ public class MultisetSemaphoreTest { @Override public void run() { try { - // Tries to acquire a permit for the set of N values, with a unique iteration order - // (across all the N! different permutations) + // Tries to acquire a permit for the set of N values, with a unique + // iteration order (across all the N! different permutations), multisetSemaphore.acquireAll(orderedSet); // And then immediately releases the permit. multisetSemaphore.releaseAll(orderedSet); |