aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test/java/com/google/devtools/build/lib/concurrent/MultisetSemaphoreTest.java
diff options
context:
space:
mode:
authorGravatar Googler <noreply@google.com>2017-01-24 23:07:40 +0000
committerGravatar Laszlo Csomor <laszlocsomor@google.com>2017-01-25 10:10:42 +0000
commit78cae6dd66b4c7ce348039c8956a6b2b758e1307 (patch)
tree6d4b9d33721d7d33bf2e25539a5ea78c4223c2cb /src/test/java/com/google/devtools/build/lib/concurrent/MultisetSemaphoreTest.java
parent3f06748eb6c4fe1a8d30aae118f37885c23ec984 (diff)
Global cleanup change.
-- PiperOrigin-RevId: 145473478 MOS_MIGRATED_REVID=145473478
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.java139
1 files changed, 77 insertions, 62 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 4a1abe5a2c..3c87569007 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
@@ -27,6 +27,7 @@ import java.util.Set;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
import java.util.concurrent.atomic.AtomicInteger;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -84,37 +85,43 @@ public class MultisetSemaphoreTest {
for (int i = 0; i < m; i++) {
final String val = "val" + i;
// And we submit M Runnables, each of which
- executorService.submit(wrapper.wrap(new Runnable() {
- @Override
- public void run() {
- try {
- // Has two rounds
+ @SuppressWarnings("unused")
+ Future<?> possiblyIgnoredError =
+ executorService.submit(
+ wrapper.wrap(
+ new Runnable() {
+ @Override
+ public void run() {
+ try {
+ // Has two rounds
- // Wherein the first round
- // The Runnable acquire a permit for a unique value (among M values),
- ImmutableSet<String> valSet = ImmutableSet.of(val);
- multisetSemaphore.acquireAll(valSet);
- assertThat(numThreadsJustAfterAcquireInFirstRound.getAndIncrement()).isLessThan(n);
- // And then sleeps,
- Thread.sleep(napTimeMs);
- numThreadsJustAfterAcquireInFirstRound.decrementAndGet();
- multisetSemaphore.releaseAll(valSet);
+ // Wherein the first round
+ // The Runnable acquire a permit for a unique value (among M values),
+ ImmutableSet<String> valSet = ImmutableSet.of(val);
+ multisetSemaphore.acquireAll(valSet);
+ assertThat(numThreadsJustAfterAcquireInFirstRound.getAndIncrement())
+ .isLessThan(n);
+ // And then sleeps,
+ Thread.sleep(napTimeMs);
+ numThreadsJustAfterAcquireInFirstRound.decrementAndGet();
+ multisetSemaphore.releaseAll(valSet);
- // And wherein the second round
- // The Runnable again acquires a permit for its unique value,
- multisetSemaphore.acquireAll(valSet);
- assertThat(numThreadsJustAfterAcquireInSecondRound.getAndIncrement()).isLessThan(n);
- // And then sleeps,
- Thread.sleep(napTimeMs);
- numThreadsJustAfterAcquireInSecondRound.decrementAndGet();
- // And notes that it has completed the second round,
- secondRoundCompleted.incrementAndGet();
- multisetSemaphore.releaseAll(valSet);
- } catch (InterruptedException e) {
- throw new IllegalStateException(e);
- }
- }
- }));
+ // And wherein the second round
+ // The Runnable again acquires a permit for its unique value,
+ multisetSemaphore.acquireAll(valSet);
+ assertThat(numThreadsJustAfterAcquireInSecondRound.getAndIncrement())
+ .isLessThan(n);
+ // And then sleeps,
+ Thread.sleep(napTimeMs);
+ numThreadsJustAfterAcquireInSecondRound.decrementAndGet();
+ // And notes that it has completed the second round,
+ secondRoundCompleted.incrementAndGet();
+ multisetSemaphore.releaseAll(valSet);
+ } catch (InterruptedException e) {
+ throw new IllegalStateException(e);
+ }
+ }
+ }));
}
// And we wait for all M Runnables to complete (that is, none of them were deadlocked),
boolean interrupted = ExecutorUtil.interruptibleShutdown(executorService);
@@ -160,25 +167,29 @@ public class MultisetSemaphoreTest {
for (int i = 0; i < n; i++) {
final String differentVal = "different-val" + i;
// And we submit N Runnables, each of which
- executorService.submit(wrapper.wrap(new Runnable() {
- @Override
- 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.
- multisetSemaphore.acquireAll(vals);
- // And then sleeps
- Thread.sleep(napTimeMs);
- // And then releases its permits
- multisetSemaphore.releaseAll(vals);
- // And then counts down the done latch,
- allDoneLatch.countDown();
- } catch (InterruptedException e) {
- throw new IllegalStateException(e);
- }
- }
- }));
+ @SuppressWarnings("unused")
+ Future<?> possiblyIgnoredError =
+ executorService.submit(
+ wrapper.wrap(
+ new Runnable() {
+ @Override
+ 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.
+ multisetSemaphore.acquireAll(vals);
+ // And then sleeps
+ Thread.sleep(napTimeMs);
+ // And then releases its permits
+ multisetSemaphore.releaseAll(vals);
+ // And then counts down the done latch,
+ allDoneLatch.countDown();
+ } catch (InterruptedException e) {
+ throw new IllegalStateException(e);
+ }
+ }
+ }));
}
// Then all of our Runnables completed (without deadlock!), as expected,
boolean interrupted = ExecutorUtil.interruptibleShutdown(executorService);
@@ -218,20 +229,24 @@ public class MultisetSemaphoreTest {
for (List<String> orderedVals : permutations) {
final Set<String> orderedSet = new LinkedHashSet<>(orderedVals);
// And we submit N! Runnables, each of which
- executorService.submit(wrapper.wrap(new Runnable() {
- @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)
- multisetSemaphore.acquireAll(orderedSet);
- // And then immediately releases the permit.
- multisetSemaphore.releaseAll(orderedSet);
- } catch (InterruptedException e) {
- throw new IllegalStateException(e);
- }
- }
- }));
+ @SuppressWarnings("unused")
+ Future<?> possiblyIgnoredError =
+ executorService.submit(
+ wrapper.wrap(
+ new Runnable() {
+ @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)
+ multisetSemaphore.acquireAll(orderedSet);
+ // And then immediately releases the permit.
+ multisetSemaphore.releaseAll(orderedSet);
+ } catch (InterruptedException e) {
+ throw new IllegalStateException(e);
+ }
+ }
+ }));
}
// Then all of our Runnables completed (without deadlock!), as expected,
boolean interrupted = ExecutorUtil.interruptibleShutdown(executorService);