aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test
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
parent3f06748eb6c4fe1a8d30aae118f37885c23ec984 (diff)
Global cleanup change.
-- PiperOrigin-RevId: 145473478 MOS_MIGRATED_REVID=145473478
Diffstat (limited to 'src/test')
-rw-r--r--src/test/java/com/google/devtools/build/lib/bazel/repository/downloader/HttpConnectorMultiplexerIntegrationTest.java116
-rw-r--r--src/test/java/com/google/devtools/build/lib/bazel/repository/downloader/HttpConnectorTest.java409
-rw-r--r--src/test/java/com/google/devtools/build/lib/concurrent/KeyedLockerTest.java21
-rw-r--r--src/test/java/com/google/devtools/build/lib/concurrent/MultisetSemaphoreTest.java139
4 files changed, 372 insertions, 313 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/bazel/repository/downloader/HttpConnectorMultiplexerIntegrationTest.java b/src/test/java/com/google/devtools/build/lib/bazel/repository/downloader/HttpConnectorMultiplexerIntegrationTest.java
index b5b77a28cf..61c3480c94 100644
--- a/src/test/java/com/google/devtools/build/lib/bazel/repository/downloader/HttpConnectorMultiplexerIntegrationTest.java
+++ b/src/test/java/com/google/devtools/build/lib/bazel/repository/downloader/HttpConnectorMultiplexerIntegrationTest.java
@@ -41,6 +41,7 @@ import java.util.concurrent.Callable;
import java.util.concurrent.CyclicBarrier;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
import java.util.concurrent.Phaser;
import org.junit.After;
import org.junit.Before;
@@ -94,25 +95,28 @@ public class HttpConnectorMultiplexerIntegrationTest {
try (ServerSocket server1 = new ServerSocket(0, 1, InetAddress.getByName("127.0.0.1"));
ServerSocket server2 = new ServerSocket(0, 1, InetAddress.getByName("127.0.0.1"))) {
for (final ServerSocket server : asList(server1, server2)) {
- executor.submit(
- new Callable<Object>() {
- @Override
- public Object call() throws Exception {
- for (String status : asList("503 MELTDOWN", "500 ERROR", "200 OK")) {
- phaser.arriveAndAwaitAdvance();
- try (Socket socket = server.accept()) {
- readHttpRequest(socket.getInputStream());
- sendLines(socket,
- "HTTP/1.1 " + status,
- "Date: Fri, 31 Dec 1999 23:59:59 GMT",
- "Connection: close",
- "",
- "hello");
+ @SuppressWarnings("unused")
+ Future<?> possiblyIgnoredError =
+ executor.submit(
+ new Callable<Object>() {
+ @Override
+ public Object call() throws Exception {
+ for (String status : asList("503 MELTDOWN", "500 ERROR", "200 OK")) {
+ phaser.arriveAndAwaitAdvance();
+ try (Socket socket = server.accept()) {
+ readHttpRequest(socket.getInputStream());
+ sendLines(
+ socket,
+ "HTTP/1.1 " + status,
+ "Date: Fri, 31 Dec 1999 23:59:59 GMT",
+ "Connection: close",
+ "",
+ "hello");
+ }
+ }
+ return null;
}
- }
- return null;
- }
- });
+ });
}
phaser.arriveAndAwaitAdvance();
phaser.arriveAndDeregister();
@@ -140,41 +144,47 @@ public class HttpConnectorMultiplexerIntegrationTest {
}).when(sleeper).sleepMillis(anyLong());
try (final ServerSocket server1 = new ServerSocket(0, 1, InetAddress.getByName("127.0.0.1"));
final ServerSocket server2 = new ServerSocket(0, 1, InetAddress.getByName("127.0.0.1"))) {
- executor.submit(
- new Callable<Object>() {
- @Override
- public Object call() throws Exception {
- try (Socket socket = server1.accept()) {
- readHttpRequest(socket.getInputStream());
- sendLines(socket,
- "HTTP/1.1 200 OK",
- "Date: Fri, 31 Dec 1999 23:59:59 GMT",
- "Warning: https://youtu.be/rJ6O5sTPn1k",
- "Connection: close",
- "",
- "Und wird die Welt auch in Flammen stehen",
- "Wir werden wieder auferstehen");
- }
- barrier.await();
- return null;
- }
- });
- executor.submit(
- new Callable<Object>() {
- @Override
- public Object call() throws Exception {
- try (Socket socket = server2.accept()) {
- readHttpRequest(socket.getInputStream());
- sendLines(socket,
- "HTTP/1.1 200 OK",
- "Date: Fri, 31 Dec 1999 23:59:59 GMT",
- "Connection: close",
- "",
- "hello");
- }
- return null;
- }
- });
+ @SuppressWarnings("unused")
+ Future<?> possiblyIgnoredError =
+ executor.submit(
+ new Callable<Object>() {
+ @Override
+ public Object call() throws Exception {
+ try (Socket socket = server1.accept()) {
+ readHttpRequest(socket.getInputStream());
+ sendLines(
+ socket,
+ "HTTP/1.1 200 OK",
+ "Date: Fri, 31 Dec 1999 23:59:59 GMT",
+ "Warning: https://youtu.be/rJ6O5sTPn1k",
+ "Connection: close",
+ "",
+ "Und wird die Welt auch in Flammen stehen",
+ "Wir werden wieder auferstehen");
+ }
+ barrier.await();
+ return null;
+ }
+ });
+ @SuppressWarnings("unused")
+ Future<?> possiblyIgnoredError1 =
+ executor.submit(
+ new Callable<Object>() {
+ @Override
+ public Object call() throws Exception {
+ try (Socket socket = server2.accept()) {
+ readHttpRequest(socket.getInputStream());
+ sendLines(
+ socket,
+ "HTTP/1.1 200 OK",
+ "Date: Fri, 31 Dec 1999 23:59:59 GMT",
+ "Connection: close",
+ "",
+ "hello");
+ }
+ return null;
+ }
+ });
try (HttpStream stream =
multiplexer.connect(
ImmutableList.of(
diff --git a/src/test/java/com/google/devtools/build/lib/bazel/repository/downloader/HttpConnectorTest.java b/src/test/java/com/google/devtools/build/lib/bazel/repository/downloader/HttpConnectorTest.java
index ccc50196d7..76daccad24 100644
--- a/src/test/java/com/google/devtools/build/lib/bazel/repository/downloader/HttpConnectorTest.java
+++ b/src/test/java/com/google/devtools/build/lib/bazel/repository/downloader/HttpConnectorTest.java
@@ -50,6 +50,7 @@ import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CyclicBarrier;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import org.junit.After;
@@ -116,24 +117,27 @@ public class HttpConnectorTest {
public void normalRequest() throws Exception {
final Map<String, String> headers = new ConcurrentHashMap<>();
try (ServerSocket server = new ServerSocket(0, 1, InetAddress.getByName("127.0.0.1"))) {
- executor.submit(
- new Callable<Object>() {
- @Override
- public Object call() throws Exception {
- try (Socket socket = server.accept()) {
- readHttpRequest(socket.getInputStream(), headers);
- sendLines(socket,
- "HTTP/1.1 200 OK",
- "Date: Fri, 31 Dec 1999 23:59:59 GMT",
- "Connection: close",
- "Content-Type: text/plain",
- "Content-Length: 5",
- "",
- "hello");
- }
- return null;
- }
- });
+ @SuppressWarnings("unused")
+ Future<?> possiblyIgnoredError =
+ executor.submit(
+ new Callable<Object>() {
+ @Override
+ public Object call() throws Exception {
+ try (Socket socket = server.accept()) {
+ readHttpRequest(socket.getInputStream(), headers);
+ sendLines(
+ socket,
+ "HTTP/1.1 200 OK",
+ "Date: Fri, 31 Dec 1999 23:59:59 GMT",
+ "Connection: close",
+ "Content-Type: text/plain",
+ "Content-Length: 5",
+ "",
+ "hello");
+ }
+ return null;
+ }
+ });
try (Reader payload =
new InputStreamReader(
connector.connect(
@@ -152,35 +156,39 @@ public class HttpConnectorTest {
@Test
public void serverError_retriesConnect() throws Exception {
try (ServerSocket server = new ServerSocket(0, 1, InetAddress.getByName("127.0.0.1"))) {
- executor.submit(
- new Callable<Object>() {
- @Override
- public Object call() throws Exception {
- try (Socket socket = server.accept()) {
- readHttpRequest(socket.getInputStream());
- sendLines(socket,
- "HTTP/1.1 500 Incredible Catastrophe",
- "Date: Fri, 31 Dec 1999 23:59:59 GMT",
- "Connection: close",
- "Content-Type: text/plain",
- "Content-Length: 8",
- "",
- "nononono");
- }
- try (Socket socket = server.accept()) {
- readHttpRequest(socket.getInputStream());
- sendLines(socket,
- "HTTP/1.1 200 OK",
- "Date: Fri, 31 Dec 1999 23:59:59 GMT",
- "Connection: close",
- "Content-Type: text/plain",
- "Content-Length: 5",
- "",
- "hello");
- }
- return null;
- }
- });
+ @SuppressWarnings("unused")
+ Future<?> possiblyIgnoredError =
+ executor.submit(
+ new Callable<Object>() {
+ @Override
+ public Object call() throws Exception {
+ try (Socket socket = server.accept()) {
+ readHttpRequest(socket.getInputStream());
+ sendLines(
+ socket,
+ "HTTP/1.1 500 Incredible Catastrophe",
+ "Date: Fri, 31 Dec 1999 23:59:59 GMT",
+ "Connection: close",
+ "Content-Type: text/plain",
+ "Content-Length: 8",
+ "",
+ "nononono");
+ }
+ try (Socket socket = server.accept()) {
+ readHttpRequest(socket.getInputStream());
+ sendLines(
+ socket,
+ "HTTP/1.1 200 OK",
+ "Date: Fri, 31 Dec 1999 23:59:59 GMT",
+ "Connection: close",
+ "Content-Type: text/plain",
+ "Content-Length: 5",
+ "",
+ "hello");
+ }
+ return null;
+ }
+ });
try (Reader payload =
new InputStreamReader(
connector.connect(
@@ -197,24 +205,27 @@ public class HttpConnectorTest {
@Test
public void permanentError_doesNotRetryAndThrowsIOException() throws Exception {
try (ServerSocket server = new ServerSocket(0, 1, InetAddress.getByName("127.0.0.1"))) {
- executor.submit(
- new Callable<Object>() {
- @Override
- public Object call() throws Exception {
- try (Socket socket = server.accept()) {
- readHttpRequest(socket.getInputStream());
- sendLines(socket,
- "HTTP/1.1 404 Not Here",
- "Date: Fri, 31 Dec 1999 23:59:59 GMT",
- "Connection: close",
- "Content-Type: text/plain",
- "Content-Length: 0",
- "",
- "");
- }
- return null;
- }
- });
+ @SuppressWarnings("unused")
+ Future<?> possiblyIgnoredError =
+ executor.submit(
+ new Callable<Object>() {
+ @Override
+ public Object call() throws Exception {
+ try (Socket socket = server.accept()) {
+ readHttpRequest(socket.getInputStream());
+ sendLines(
+ socket,
+ "HTTP/1.1 404 Not Here",
+ "Date: Fri, 31 Dec 1999 23:59:59 GMT",
+ "Connection: close",
+ "Content-Type: text/plain",
+ "Content-Length: 0",
+ "",
+ "");
+ }
+ return null;
+ }
+ });
thrown.expect(IOException.class);
thrown.expectMessage("404 Not Here");
connector.connect(
@@ -228,27 +239,30 @@ public class HttpConnectorTest {
final CyclicBarrier barrier = new CyclicBarrier(2);
final AtomicBoolean consumed = new AtomicBoolean();
try (ServerSocket server = new ServerSocket(0, 1, InetAddress.getByName("127.0.0.1"))) {
- executor.submit(
- new Callable<Object>() {
- @Override
- public Object call() throws Exception {
- try (Socket socket = server.accept()) {
- readHttpRequest(socket.getInputStream());
- sendLines(socket,
- "HTTP/1.1 501 Oh No",
- "Date: Fri, 31 Dec 1999 23:59:59 GMT",
- "Connection: close",
- "Content-Type: text/plain",
- "Content-Length: 1",
- "",
- "b");
- consumed.set(true);
- } finally {
- barrier.await();
- }
- return null;
- }
- });
+ @SuppressWarnings("unused")
+ Future<?> possiblyIgnoredError =
+ executor.submit(
+ new Callable<Object>() {
+ @Override
+ public Object call() throws Exception {
+ try (Socket socket = server.accept()) {
+ readHttpRequest(socket.getInputStream());
+ sendLines(
+ socket,
+ "HTTP/1.1 501 Oh No",
+ "Date: Fri, 31 Dec 1999 23:59:59 GMT",
+ "Connection: close",
+ "Content-Type: text/plain",
+ "Content-Length: 1",
+ "",
+ "b");
+ consumed.set(true);
+ } finally {
+ barrier.await();
+ }
+ return null;
+ }
+ });
connector.connect(
new URL(String.format("http://127.0.0.1:%d", server.getLocalPort())),
ImmutableMap.<String, String>of());
@@ -266,25 +280,29 @@ public class HttpConnectorTest {
public void always500_givesUpEventually() throws Exception {
final AtomicInteger tries = new AtomicInteger();
try (ServerSocket server = new ServerSocket(0, 1, InetAddress.getByName("127.0.0.1"))) {
- executor.submit(new Callable<Object>() {
- @Override
- public Object call() throws Exception {
- while (true) {
- try (Socket socket = server.accept()) {
- readHttpRequest(socket.getInputStream());
- sendLines(socket,
- "HTTP/1.1 500 Oh My",
- "Date: Fri, 31 Dec 1999 23:59:59 GMT",
- "Connection: close",
- "Content-Type: text/plain",
- "Content-Length: 0",
- "",
- "");
- tries.incrementAndGet();
+ @SuppressWarnings("unused")
+ Future<?> possiblyIgnoredError =
+ executor.submit(
+ new Callable<Object>() {
+ @Override
+ public Object call() throws Exception {
+ while (true) {
+ try (Socket socket = server.accept()) {
+ readHttpRequest(socket.getInputStream());
+ sendLines(
+ socket,
+ "HTTP/1.1 500 Oh My",
+ "Date: Fri, 31 Dec 1999 23:59:59 GMT",
+ "Connection: close",
+ "Content-Type: text/plain",
+ "Content-Length: 0",
+ "",
+ "");
+ tries.incrementAndGet();
+ }
+ }
}
- }
- }
- });
+ });
thrown.expect(IOException.class);
thrown.expectMessage("500 Oh My");
try {
@@ -301,26 +319,29 @@ public class HttpConnectorTest {
public void serverSays403_clientRetriesAnyway() throws Exception {
final AtomicInteger tries = new AtomicInteger();
try (ServerSocket server = new ServerSocket(0, 1, InetAddress.getByName("127.0.0.1"))) {
- executor.submit(
- new Callable<Object>() {
- @Override
- public Object call() throws Exception {
- while (true) {
- try (Socket socket = server.accept()) {
- readHttpRequest(socket.getInputStream());
- sendLines(socket,
- "HTTP/1.1 403 Forbidden",
- "Date: Fri, 31 Dec 1999 23:59:59 GMT",
- "Connection: close",
- "Content-Type: text/plain",
- "Content-Length: 0",
- "",
- "");
- tries.incrementAndGet();
+ @SuppressWarnings("unused")
+ Future<?> possiblyIgnoredError =
+ executor.submit(
+ new Callable<Object>() {
+ @Override
+ public Object call() throws Exception {
+ while (true) {
+ try (Socket socket = server.accept()) {
+ readHttpRequest(socket.getInputStream());
+ sendLines(
+ socket,
+ "HTTP/1.1 403 Forbidden",
+ "Date: Fri, 31 Dec 1999 23:59:59 GMT",
+ "Connection: close",
+ "Content-Type: text/plain",
+ "Content-Length: 0",
+ "",
+ "");
+ tries.incrementAndGet();
+ }
+ }
}
- }
- }
- });
+ });
thrown.expect(IOException.class);
thrown.expectMessage("403 Forbidden");
try {
@@ -338,35 +359,39 @@ public class HttpConnectorTest {
final Map<String, String> headers1 = new ConcurrentHashMap<>();
final Map<String, String> headers2 = new ConcurrentHashMap<>();
try (ServerSocket server = new ServerSocket(0, 1, InetAddress.getByName("127.0.0.1"))) {
- executor.submit(
- new Callable<Object>() {
- @Override
- public Object call() throws Exception {
- try (Socket socket = server.accept()) {
- readHttpRequest(socket.getInputStream(), headers1);
- sendLines(socket,
- "HTTP/1.1 301 Redirect",
- "Date: Fri, 31 Dec 1999 23:59:59 GMT",
- "Connection: close",
- "Location: /doodle.tar.gz",
- "Content-Length: 0",
- "",
- "");
- }
- try (Socket socket = server.accept()) {
- readHttpRequest(socket.getInputStream(), headers2);
- sendLines(socket,
- "HTTP/1.1 200 OK",
- "Date: Fri, 31 Dec 1999 23:59:59 GMT",
- "Connection: close",
- "Content-Type: text/plain",
- "Content-Length: 0",
- "",
- "");
- }
- return null;
- }
- });
+ @SuppressWarnings("unused")
+ Future<?> possiblyIgnoredError =
+ executor.submit(
+ new Callable<Object>() {
+ @Override
+ public Object call() throws Exception {
+ try (Socket socket = server.accept()) {
+ readHttpRequest(socket.getInputStream(), headers1);
+ sendLines(
+ socket,
+ "HTTP/1.1 301 Redirect",
+ "Date: Fri, 31 Dec 1999 23:59:59 GMT",
+ "Connection: close",
+ "Location: /doodle.tar.gz",
+ "Content-Length: 0",
+ "",
+ "");
+ }
+ try (Socket socket = server.accept()) {
+ readHttpRequest(socket.getInputStream(), headers2);
+ sendLines(
+ socket,
+ "HTTP/1.1 200 OK",
+ "Date: Fri, 31 Dec 1999 23:59:59 GMT",
+ "Connection: close",
+ "Content-Type: text/plain",
+ "Content-Length: 0",
+ "",
+ "");
+ }
+ return null;
+ }
+ });
URLConnection connection =
connector.connect(
new URL(String.format("http://127.0.0.1:%d", server.getLocalPort())),
@@ -385,43 +410,49 @@ public class HttpConnectorTest {
public void redirectToDifferentServer_works() throws Exception {
try (ServerSocket server1 = new ServerSocket(0, 1, InetAddress.getByName("127.0.0.1"));
ServerSocket server2 = new ServerSocket(0, 1, InetAddress.getByName("127.0.0.1"))) {
- executor.submit(
- new Callable<Object>() {
- @Override
- public Object call() throws Exception {
- try (Socket socket = server1.accept()) {
- readHttpRequest(socket.getInputStream());
- sendLines(socket,
- "HTTP/1.1 301 Redirect",
- "Date: Fri, 31 Dec 1999 23:59:59 GMT",
- "Connection: close",
- String.format("Location: http://127.0.0.1:%d/doodle.tar.gz",
- server2.getLocalPort()),
- "Content-Length: 0",
- "",
- "");
- }
- return null;
- }
- });
- executor.submit(
- new Callable<Object>() {
- @Override
- public Object call() throws Exception {
- try (Socket socket = server2.accept()) {
- readHttpRequest(socket.getInputStream());
- sendLines(socket,
- "HTTP/1.1 200 OK",
- "Date: Fri, 31 Dec 1999 23:59:59 GMT",
- "Connection: close",
- "Content-Type: text/plain",
- "Content-Length: 5",
- "",
- "hello");
- }
- return null;
- }
- });
+ @SuppressWarnings("unused")
+ Future<?> possiblyIgnoredError =
+ executor.submit(
+ new Callable<Object>() {
+ @Override
+ public Object call() throws Exception {
+ try (Socket socket = server1.accept()) {
+ readHttpRequest(socket.getInputStream());
+ sendLines(
+ socket,
+ "HTTP/1.1 301 Redirect",
+ "Date: Fri, 31 Dec 1999 23:59:59 GMT",
+ "Connection: close",
+ String.format(
+ "Location: http://127.0.0.1:%d/doodle.tar.gz", server2.getLocalPort()),
+ "Content-Length: 0",
+ "",
+ "");
+ }
+ return null;
+ }
+ });
+ @SuppressWarnings("unused")
+ Future<?> possiblyIgnoredError1 =
+ executor.submit(
+ new Callable<Object>() {
+ @Override
+ public Object call() throws Exception {
+ try (Socket socket = server2.accept()) {
+ readHttpRequest(socket.getInputStream());
+ sendLines(
+ socket,
+ "HTTP/1.1 200 OK",
+ "Date: Fri, 31 Dec 1999 23:59:59 GMT",
+ "Connection: close",
+ "Content-Type: text/plain",
+ "Content-Length: 5",
+ "",
+ "hello");
+ }
+ return null;
+ }
+ });
URLConnection connection =
connector.connect(
new URL(String.format("http://127.0.0.1:%d", server1.getLocalPort())),
diff --git a/src/test/java/com/google/devtools/build/lib/concurrent/KeyedLockerTest.java b/src/test/java/com/google/devtools/build/lib/concurrent/KeyedLockerTest.java
index c6b94615c1..9370aeafe5 100644
--- a/src/test/java/com/google/devtools/build/lib/concurrent/KeyedLockerTest.java
+++ b/src/test/java/com/google/devtools/build/lib/concurrent/KeyedLockerTest.java
@@ -24,20 +24,19 @@ import com.google.devtools.build.lib.concurrent.KeyedLocker.AutoUnlocker;
import com.google.devtools.build.lib.concurrent.KeyedLocker.AutoUnlocker.IllegalUnlockException;
import com.google.devtools.build.lib.testutil.TestUtils;
import com.google.devtools.build.lib.util.Preconditions;
-
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-
import java.util.HashSet;
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.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
/** Base class for tests for {@link KeyedLocker} implementations. */
public abstract class KeyedLockerTest {
@@ -163,7 +162,8 @@ public abstract class KeyedLockerTest {
}
};
for (int i = 0; i < NUM_EXECUTOR_THREADS; i++) {
- executorService.submit(wrapper.wrap(runnable));
+ @SuppressWarnings("unused")
+ Future<?> possiblyIgnoredError = executorService.submit(wrapper.wrap(runnable));
}
boolean interrupted = ExecutorUtil.interruptibleShutdown(executorService);
Throwables.propagateIfPossible(wrapper.getFirstThrownError());
@@ -208,8 +208,10 @@ public abstract class KeyedLockerTest {
}
}
};
- executorService.submit(wrapper.wrap(runnable1));
- executorService.submit(wrapper.wrap(runnable2));
+ @SuppressWarnings("unused")
+ Future<?> possiblyIgnoredError = executorService.submit(wrapper.wrap(runnable1));
+ @SuppressWarnings("unused")
+ Future<?> possiblyIgnoredError1 = executorService.submit(wrapper.wrap(runnable2));
boolean interrupted = ExecutorUtil.interruptibleShutdown(executorService);
Throwables.propagateIfPossible(wrapper.getFirstThrownError());
if (interrupted || runnableInterrupted.get()) {
@@ -262,7 +264,8 @@ public abstract class KeyedLockerTest {
}
};
for (int i = 0; i < NUM_EXECUTOR_THREADS; i++) {
- executorService.submit(wrapper.wrap(runnable));
+ @SuppressWarnings("unused")
+ Future<?> possiblyIgnoredError = executorService.submit(wrapper.wrap(runnable));
}
boolean interrupted = ExecutorUtil.interruptibleShutdown(executorService);
Throwables.propagateIfPossible(wrapper.getFirstThrownError());
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);