From 2a7f94d5d9cbbe3197ff78ae27fea6f701bd3f90 Mon Sep 17 00:00:00 2001 From: Andreas Herrmann Date: Fri, 8 Oct 2021 17:33:32 +0200 Subject: [PATCH] Fix test build --- .../remote/RemoteCacheClientFactoryTest.java | 25 +++++++++++++------ .../devtools/build/lib/remote/http/BUILD | 1 + .../lib/remote/http/HttpCacheClientTest.java | 14 +++++++++++ 3 files changed, 33 insertions(+), 7 deletions(-) diff --git a/src/test/java/com/google/devtools/build/lib/remote/RemoteCacheClientFactoryTest.java b/src/test/java/com/google/devtools/build/lib/remote/RemoteCacheClientFactoryTest.java index 66d74d76335c03..cd50c9c97e660b 100644 --- a/src/test/java/com/google/devtools/build/lib/remote/RemoteCacheClientFactoryTest.java +++ b/src/test/java/com/google/devtools/build/lib/remote/RemoteCacheClientFactoryTest.java @@ -17,6 +17,8 @@ import static com.google.common.truth.Truth.assertThat; import static org.junit.Assert.assertThrows; +import com.google.common.util.concurrent.ListeningScheduledExecutorService; +import com.google.common.util.concurrent.MoreExecutors; import com.google.devtools.build.lib.clock.JavaClock; import com.google.devtools.build.lib.remote.common.RemoteCacheClient; import com.google.devtools.build.lib.remote.disk.DiskAndRemoteCacheClient; @@ -30,6 +32,8 @@ import com.google.devtools.build.lib.vfs.inmemoryfs.InMemoryFileSystem; import com.google.devtools.common.options.Options; import java.io.IOException; +import java.util.concurrent.Executors; + import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -44,6 +48,13 @@ public class RemoteCacheClientFactoryTest { private RemoteOptions remoteOptions; private Path workingDirectory; private InMemoryFileSystem fs; + private ListeningScheduledExecutorService retryScheduler = + MoreExecutors.listeningDecorator(Executors.newScheduledThreadPool(1)); + private RemoteRetrier retrier = new RemoteRetrier( + () -> RemoteRetrier.RETRIES_DISABLED, + (e) -> false, + retryScheduler, + Retrier.ALLOW_ALL_CALLS); @Before public final void setUp() { @@ -60,7 +71,7 @@ public void createCombinedCacheWithExistingWorkingDirectory() throws IOException RemoteCacheClient blobStore = RemoteCacheClientFactory.create( - remoteOptions, /* creds= */ null, workingDirectory, digestUtil); + remoteOptions, /* creds= */ null, workingDirectory, digestUtil, retrier); assertThat(blobStore).isInstanceOf(DiskAndRemoteCacheClient.class); } @@ -73,7 +84,7 @@ public void createCombinedCacheWithNotExistingWorkingDirectory() throws IOExcept RemoteCacheClient blobStore = RemoteCacheClientFactory.create( - remoteOptions, /* creds= */ null, workingDirectory, digestUtil); + remoteOptions, /* creds= */ null, workingDirectory, digestUtil, retrier); assertThat(blobStore).isInstanceOf(DiskAndRemoteCacheClient.class); assertThat(workingDirectory.exists()).isTrue(); @@ -89,7 +100,7 @@ public void createCombinedCacheWithMissingWorkingDirectoryShouldThrowException() NullPointerException.class, () -> RemoteCacheClientFactory.create( - remoteOptions, /* creds= */ null, /* workingDirectory= */ null, digestUtil)); + remoteOptions, /* creds= */ null, /* workingDirectory= */ null, digestUtil, retrier)); } @Test @@ -99,7 +110,7 @@ public void createHttpCacheWithProxy() throws IOException { RemoteCacheClient blobStore = RemoteCacheClientFactory.create( - remoteOptions, /* creds= */ null, workingDirectory, digestUtil); + remoteOptions, /* creds= */ null, workingDirectory, digestUtil, retrier); assertThat(blobStore).isInstanceOf(HttpCacheClient.class); } @@ -114,7 +125,7 @@ public void createHttpCacheFailsWithUnsupportedProxyProtocol() { RuntimeException.class, () -> RemoteCacheClientFactory.create( - remoteOptions, /* creds= */ null, workingDirectory, digestUtil))) + remoteOptions, /* creds= */ null, workingDirectory, digestUtil, retrier))) .hasMessageThat() .contains("Remote cache proxy unsupported: bad-proxy"); } @@ -125,7 +136,7 @@ public void createHttpCacheWithoutProxy() throws IOException { RemoteCacheClient blobStore = RemoteCacheClientFactory.create( - remoteOptions, /* creds= */ null, workingDirectory, digestUtil); + remoteOptions, /* creds= */ null, workingDirectory, digestUtil, retrier); assertThat(blobStore).isInstanceOf(HttpCacheClient.class); } @@ -136,7 +147,7 @@ public void createDiskCache() throws IOException { RemoteCacheClient blobStore = RemoteCacheClientFactory.create( - remoteOptions, /* creds= */ null, workingDirectory, digestUtil); + remoteOptions, /* creds= */ null, workingDirectory, digestUtil, retrier); assertThat(blobStore).isInstanceOf(DiskCacheClient.class); } diff --git a/src/test/java/com/google/devtools/build/lib/remote/http/BUILD b/src/test/java/com/google/devtools/build/lib/remote/http/BUILD index ff7064f423318f..fc8d2762fd5e5f 100644 --- a/src/test/java/com/google/devtools/build/lib/remote/http/BUILD +++ b/src/test/java/com/google/devtools/build/lib/remote/http/BUILD @@ -22,6 +22,7 @@ java_test( ], test_class = "com.google.devtools.build.lib.AllTests", deps = [ + "//src/main/java/com/google/devtools/build/lib/remote:Retrier", "//src/main/java/com/google/devtools/build/lib/remote/common", "//src/main/java/com/google/devtools/build/lib/remote/http", "//src/main/java/com/google/devtools/build/lib/remote/util", diff --git a/src/test/java/com/google/devtools/build/lib/remote/http/HttpCacheClientTest.java b/src/test/java/com/google/devtools/build/lib/remote/http/HttpCacheClientTest.java index c41921b684ea15..102da5f53af3d3 100644 --- a/src/test/java/com/google/devtools/build/lib/remote/http/HttpCacheClientTest.java +++ b/src/test/java/com/google/devtools/build/lib/remote/http/HttpCacheClientTest.java @@ -32,6 +32,10 @@ import com.google.common.base.Charsets; import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; +import com.google.common.util.concurrent.ListeningScheduledExecutorService; +import com.google.common.util.concurrent.MoreExecutors; +import com.google.devtools.build.lib.remote.RemoteRetrier; +import com.google.devtools.build.lib.remote.Retrier; import com.google.devtools.build.lib.remote.common.RemoteActionExecutionContext; import com.google.devtools.build.lib.remote.util.DigestUtil; import com.google.devtools.build.lib.remote.util.TracingMetadataUtils; @@ -87,6 +91,7 @@ import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.Executors; import java.util.function.IntFunction; import javax.annotation.Nullable; import org.junit.Before; @@ -261,6 +266,13 @@ private HttpCacheClient createHttpBlobStore( @Nullable final Credentials creds) throws Exception { SocketAddress socketAddress = serverChannel.localAddress(); + ListeningScheduledExecutorService retryScheduler = + MoreExecutors.listeningDecorator(Executors.newScheduledThreadPool(1)); + RemoteRetrier retrier = new RemoteRetrier( + () -> RemoteRetrier.RETRIES_DISABLED, + (e) -> false, + retryScheduler, + Retrier.ALLOW_ALL_CALLS); if (socketAddress instanceof DomainSocketAddress) { DomainSocketAddress domainSocketAddress = (DomainSocketAddress) socketAddress; URI uri = new URI("http://localhost"); @@ -272,6 +284,7 @@ private HttpCacheClient createHttpBlobStore( remoteVerifyDownloads, ImmutableList.of(), DIGEST_UTIL, + retrier, creds); } else if (socketAddress instanceof InetSocketAddress) { InetSocketAddress inetSocketAddress = (InetSocketAddress) socketAddress; @@ -283,6 +296,7 @@ private HttpCacheClient createHttpBlobStore( remoteVerifyDownloads, ImmutableList.of(), DIGEST_UTIL, + retrier, creds); } else { throw new IllegalStateException(