Skip to content

Commit

Permalink
Fix test build
Browse files Browse the repository at this point in the history
  • Loading branch information
aherrmann committed Nov 11, 2021
1 parent 1b1f374 commit 2a7f94d
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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() {
Expand All @@ -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);
}
Expand All @@ -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();
Expand All @@ -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
Expand All @@ -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);
}
Expand All @@ -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");
}
Expand All @@ -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);
}
Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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");
Expand All @@ -272,6 +284,7 @@ private HttpCacheClient createHttpBlobStore(
remoteVerifyDownloads,
ImmutableList.of(),
DIGEST_UTIL,
retrier,
creds);
} else if (socketAddress instanceof InetSocketAddress) {
InetSocketAddress inetSocketAddress = (InetSocketAddress) socketAddress;
Expand All @@ -283,6 +296,7 @@ private HttpCacheClient createHttpBlobStore(
remoteVerifyDownloads,
ImmutableList.of(),
DIGEST_UTIL,
retrier,
creds);
} else {
throw new IllegalStateException(
Expand Down

0 comments on commit 2a7f94d

Please sign in to comment.