aboutsummaryrefslogtreecommitdiffhomepage
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
parent3f06748eb6c4fe1a8d30aae118f37885c23ec984 (diff)
Global cleanup change.
-- PiperOrigin-RevId: 145473478 MOS_MIGRATED_REVID=145473478
-rw-r--r--src/main/java/com/google/devtools/build/lib/bazel/dash/DashModule.java49
-rw-r--r--src/main/java/com/google/devtools/build/lib/concurrent/ForkJoinQuiescingExecutor.java4
-rw-r--r--src/main/java/com/google/devtools/build/lib/packages/GlobCache.java3
-rw-r--r--src/main/java/com/google/devtools/build/lib/packages/PackageFactory.java4
-rw-r--r--src/main/java/com/google/devtools/build/lib/query2/engine/ParallelQueryUtils.java4
-rw-r--r--src/main/java/com/google/devtools/build/lib/server/IdleServerTasks.java21
-rw-r--r--src/main/java/com/google/devtools/build/lib/windows/WindowsSubprocess.java15
-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
11 files changed, 432 insertions, 353 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/dash/DashModule.java b/src/main/java/com/google/devtools/build/lib/bazel/dash/DashModule.java
index 192dc60b40..01e8830086 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/dash/DashModule.java
+++ b/src/main/java/com/google/devtools/build/lib/bazel/dash/DashModule.java
@@ -36,19 +36,6 @@ import com.google.devtools.common.options.OptionsBase;
import com.google.devtools.common.options.OptionsParser.UnparsedOptionValueDescription;
import com.google.devtools.common.options.OptionsProvider;
import com.google.protobuf.ByteString;
-
-import org.apache.http.HttpEntity;
-import org.apache.http.HttpHeaders;
-import org.apache.http.HttpStatus;
-import org.apache.http.StatusLine;
-import org.apache.http.client.HttpClient;
-import org.apache.http.client.methods.HttpPost;
-import org.apache.http.entity.ByteArrayEntity;
-import org.apache.http.impl.client.DefaultHttpClient;
-import org.apache.http.params.BasicHttpParams;
-import org.apache.http.params.HttpConnectionParams;
-import org.apache.http.params.HttpParams;
-
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
@@ -60,7 +47,19 @@ import java.nio.file.Path;
import java.nio.file.attribute.PosixFilePermission;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
import java.util.concurrent.ThreadFactory;
+import org.apache.http.HttpEntity;
+import org.apache.http.HttpHeaders;
+import org.apache.http.HttpStatus;
+import org.apache.http.StatusLine;
+import org.apache.http.client.HttpClient;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.entity.ByteArrayEntity;
+import org.apache.http.impl.client.DefaultHttpClient;
+import org.apache.http.params.BasicHttpParams;
+import org.apache.http.params.HttpConnectionParams;
+import org.apache.http.params.HttpParams;
/**
* Dashboard for a build.
@@ -347,17 +346,19 @@ public class DashModule extends BlazeModule {
@Override
public void send(final String suffix, final BuildData message) {
- executorService.submit(new Runnable() {
- @Override
- public void run() {
- try {
- sendMessage(suffix, new ByteArrayEntity(message.toByteArray()));
- } catch (SenderException ex) {
- reporter.handle(ex.toEvent());
- }
- }
-
- });
+ @SuppressWarnings("unused")
+ Future<?> possiblyIgnoredError =
+ executorService.submit(
+ new Runnable() {
+ @Override
+ public void run() {
+ try {
+ sendMessage(suffix, new ByteArrayEntity(message.toByteArray()));
+ } catch (SenderException ex) {
+ reporter.handle(ex.toEvent());
+ }
+ }
+ });
}
}
diff --git a/src/main/java/com/google/devtools/build/lib/concurrent/ForkJoinQuiescingExecutor.java b/src/main/java/com/google/devtools/build/lib/concurrent/ForkJoinQuiescingExecutor.java
index b012ac18ef..ca2b38da44 100644
--- a/src/main/java/com/google/devtools/build/lib/concurrent/ForkJoinQuiescingExecutor.java
+++ b/src/main/java/com/google/devtools/build/lib/concurrent/ForkJoinQuiescingExecutor.java
@@ -16,6 +16,7 @@ package com.google.devtools.build.lib.concurrent;
import com.google.devtools.build.lib.util.Preconditions;
import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.ForkJoinTask;
+import java.util.concurrent.Future;
/** A {@link QuiescingExecutor} implementation that wraps a {@link ForkJoinPool}. */
// TODO(bazel-team): This extends AQV to ensure that they share the same semantics for interrupt
@@ -94,7 +95,8 @@ public class ForkJoinQuiescingExecutor extends AbstractQueueVisitor {
@Override
protected void executeRunnable(Runnable runnable) {
if (ForkJoinTask.inForkJoinPool()) {
- ForkJoinTask.adapt(runnable).fork();
+ @SuppressWarnings("unused")
+ Future<?> possiblyIgnoredError = ForkJoinTask.adapt(runnable).fork();
} else {
super.executeRunnable(runnable);
}
diff --git a/src/main/java/com/google/devtools/build/lib/packages/GlobCache.java b/src/main/java/com/google/devtools/build/lib/packages/GlobCache.java
index 56df73c58b..aecf43f94f 100644
--- a/src/main/java/com/google/devtools/build/lib/packages/GlobCache.java
+++ b/src/main/java/com/google/devtools/build/lib/packages/GlobCache.java
@@ -238,7 +238,8 @@ public class GlobCache {
// block on an individual pattern's results, but the other globs can
// continue in the background.
for (String pattern : Iterables.concat(includes, excludes)) {
- getGlobUnsortedAsync(pattern, excludeDirs);
+ @SuppressWarnings("unused")
+ Future<?> possiblyIgnoredError = getGlobUnsortedAsync(pattern, excludeDirs);
}
HashSet<String> results = new HashSet<>();
diff --git a/src/main/java/com/google/devtools/build/lib/packages/PackageFactory.java b/src/main/java/com/google/devtools/build/lib/packages/PackageFactory.java
index 33da991636..311987377e 100644
--- a/src/main/java/com/google/devtools/build/lib/packages/PackageFactory.java
+++ b/src/main/java/com/google/devtools/build/lib/packages/PackageFactory.java
@@ -77,6 +77,7 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
+import java.util.concurrent.Future;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
@@ -293,7 +294,8 @@ public final class PackageFactory {
public Token runAsync(List<String> includes, List<String> excludes, boolean excludeDirs)
throws BadGlobException {
for (String pattern : Iterables.concat(includes, excludes)) {
- globCache.getGlobUnsortedAsync(pattern, excludeDirs);
+ @SuppressWarnings("unused")
+ Future<?> possiblyIgnoredError = globCache.getGlobUnsortedAsync(pattern, excludeDirs);
}
return new Token(includes, excludes, excludeDirs);
}
diff --git a/src/main/java/com/google/devtools/build/lib/query2/engine/ParallelQueryUtils.java b/src/main/java/com/google/devtools/build/lib/query2/engine/ParallelQueryUtils.java
index ac5a621749..6e22709deb 100644
--- a/src/main/java/com/google/devtools/build/lib/query2/engine/ParallelQueryUtils.java
+++ b/src/main/java/com/google/devtools/build/lib/query2/engine/ParallelQueryUtils.java
@@ -22,6 +22,7 @@ import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.ForkJoinTask;
+import java.util.concurrent.Future;
/** Several utilities to aid in writing {@link QueryExpression#parEvalImpl} implementations. */
public class ParallelQueryUtils {
@@ -58,7 +59,8 @@ public class ParallelQueryUtils {
for (QueryTask queryTask : queryTasks) {
QueryTaskForkJoinTask forkJoinTask = adaptAsForkJoinTask(queryTask, failFastLatch);
forkJoinTasks.add(forkJoinTask);
- forkJoinPool.submit(forkJoinTask);
+ @SuppressWarnings("unused")
+ Future<?> possiblyIgnoredError = forkJoinPool.submit(forkJoinTask);
}
failFastLatch.await();
try {
diff --git a/src/main/java/com/google/devtools/build/lib/server/IdleServerTasks.java b/src/main/java/com/google/devtools/build/lib/server/IdleServerTasks.java
index 231210dfc5..f37e97ae9f 100644
--- a/src/main/java/com/google/devtools/build/lib/server/IdleServerTasks.java
+++ b/src/main/java/com/google/devtools/build/lib/server/IdleServerTasks.java
@@ -22,6 +22,7 @@ import com.google.devtools.build.lib.vfs.FileStatus;
import com.google.devtools.build.lib.vfs.Path;
import com.google.devtools.build.lib.vfs.Symlinks;
import java.io.IOException;
+import java.util.concurrent.Future;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
@@ -56,13 +57,19 @@ class IdleServerTasks {
Preconditions.checkState(!executor.isShutdown());
// Do a GC cycle while the server is idle.
- executor.schedule(new Runnable() {
- @Override public void run() {
- try (AutoProfiler p = AutoProfiler.logged("Idle GC", LOG)) {
- System.gc();
- }
- }
- }, 10, TimeUnit.SECONDS);
+ @SuppressWarnings("unused")
+ Future<?> possiblyIgnoredError =
+ executor.schedule(
+ new Runnable() {
+ @Override
+ public void run() {
+ try (AutoProfiler p = AutoProfiler.logged("Idle GC", LOG)) {
+ System.gc();
+ }
+ }
+ },
+ 10,
+ TimeUnit.SECONDS);
}
/**
diff --git a/src/main/java/com/google/devtools/build/lib/windows/WindowsSubprocess.java b/src/main/java/com/google/devtools/build/lib/windows/WindowsSubprocess.java
index e0009d52fd..16f05e47e6 100644
--- a/src/main/java/com/google/devtools/build/lib/windows/WindowsSubprocess.java
+++ b/src/main/java/com/google/devtools/build/lib/windows/WindowsSubprocess.java
@@ -21,6 +21,7 @@ import java.io.OutputStream;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
@@ -144,11 +145,15 @@ public class WindowsSubprocess implements Subprocess {
waitLatch = new CountDownLatch(1);
// Every Windows process we start consumes a thread here. This is suboptimal, but seems to be
// the sanest way to reconcile WaitForMultipleObjects() and Java-style interruption.
- WAITER_POOL.submit(new Runnable() {
- @Override public void run() {
- waiterThreadFunc();
- }
- });
+ @SuppressWarnings("unused")
+ Future<?> possiblyIgnoredError =
+ WAITER_POOL.submit(
+ new Runnable() {
+ @Override
+ public void run() {
+ waiterThreadFunc();
+ }
+ });
}
private void waiterThreadFunc() {
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);