use of build.bazel.remote.execution.v2.ContentAddressableStorageGrpc.ContentAddressableStorageImplBase in project bazel-buildfarm by bazelbuild.
the class GrpcCASTest method findMissingBlobsSwallowsFilteredList.
@Test
public void findMissingBlobsSwallowsFilteredList() throws Exception {
Channel channel = InProcessChannelBuilder.forName(fakeServerName).directExecutor().build();
Runnable onExpiration = mock(Runnable.class);
GrpcCAS cas = new GrpcCAS("test", channel, null, onExpirations);
ContentAddressableStorageImplBase casService = mock(ContentAddressableStorageImplBase.class);
serviceRegistry.addService(casService);
Digest emptyDigest = Digest.getDefaultInstance();
assertThat(cas.findMissingBlobs(ImmutableList.of(emptyDigest))).isEmpty();
verifyZeroInteractions(casService);
verifyZeroInteractions(onExpiration);
}
use of build.bazel.remote.execution.v2.ContentAddressableStorageGrpc.ContentAddressableStorageImplBase in project bazel-buildfarm by bazelbuild.
the class StubInstanceTest method putAllBlobsUploadsBlobs.
@Test
public void putAllBlobsUploadsBlobs() throws Exception {
String instanceName = "putAllBlobs-test";
serviceRegistry.addService(new ContentAddressableStorageImplBase() {
@Override
public void batchUpdateBlobs(BatchUpdateBlobsRequest batchRequest, StreamObserver<BatchUpdateBlobsResponse> responseObserver) {
checkState(batchRequest.getInstanceName().equals(instanceName));
responseObserver.onNext(BatchUpdateBlobsResponse.newBuilder().addAllResponses(batchRequest.getRequestsList().stream().map(request -> Response.newBuilder().setDigest(request.getDigest()).build()).collect(Collectors.toList())).build());
responseObserver.onCompleted();
}
});
Instance instance = newStubInstance("putAllBlobs-test");
ByteString first = ByteString.copyFromUtf8("first");
ByteString last = ByteString.copyFromUtf8("last");
ImmutableList<ByteString> blobs = ImmutableList.of(first, last);
ImmutableList<Digest> digests = ImmutableList.of(DIGEST_UTIL.compute(first), DIGEST_UTIL.compute(last));
assertThat(instance.putAllBlobs(blobs, RequestMetadata.getDefaultInstance())).containsAllIn(digests);
}
use of build.bazel.remote.execution.v2.ContentAddressableStorageGrpc.ContentAddressableStorageImplBase in project bazel-buildfarm by bazelbuild.
the class StubInstanceTest method findMissingBlobsCallsFindMissingBlobs.
@Test
public void findMissingBlobsCallsFindMissingBlobs() throws ExecutionException, InterruptedException {
AtomicReference<FindMissingBlobsRequest> reference = new AtomicReference<>();
serviceRegistry.addService(new ContentAddressableStorageImplBase() {
@Override
public void findMissingBlobs(FindMissingBlobsRequest request, StreamObserver<FindMissingBlobsResponse> responseObserver) {
reference.set(request);
responseObserver.onNext(FindMissingBlobsResponse.getDefaultInstance());
responseObserver.onCompleted();
}
});
Instance instance = newStubInstance("findMissingBlobs-test");
Iterable<Digest> digests = ImmutableList.of(Digest.newBuilder().setHash("present").setSizeBytes(1).build());
assertThat(instance.findMissingBlobs(digests, RequestMetadata.getDefaultInstance()).get()).isEmpty();
instance.stop();
}
use of build.bazel.remote.execution.v2.ContentAddressableStorageGrpc.ContentAddressableStorageImplBase in project tools_remote by bazelbuild.
the class GrpcRemoteCacheTest method testDownloadDirectory.
@Test
public void testDownloadDirectory() throws Exception {
GrpcRemoteCache client = newClient();
Digest fooDigest = DIGEST_UTIL.computeAsUtf8("foo-contents");
Directory barMessage = Directory.newBuilder().addFiles(FileNode.newBuilder().setDigest(fooDigest).setName("foo").setDigest(fooDigest)).build();
Digest barDigest = DIGEST_UTIL.compute(barMessage);
Directory dirMessage = Directory.newBuilder().addDirectories(DirectoryNode.newBuilder().setDigest(barDigest).setName("bar")).addFiles(FileNode.newBuilder().setDigest(fooDigest).setName("foo").setIsExecutable(true)).build();
Digest dirDigest = DIGEST_UTIL.compute(dirMessage);
serviceRegistry.addService(new FakeImmutableCacheByteStreamImpl(ImmutableMap.of(dirDigest, dirMessage.toByteString(), fooDigest, "foo-contents")));
serviceRegistry.addService(new ContentAddressableStorageImplBase() {
@Override
public void getTree(GetTreeRequest request, StreamObserver<GetTreeResponse> responseObserver) {
assertThat(request.getRootDigest()).isEqualTo(dirDigest);
responseObserver.onNext(GetTreeResponse.newBuilder().addDirectories(dirMessage).addDirectories(barMessage).build());
responseObserver.onCompleted();
}
});
client.downloadDirectory(execRoot.resolve("test"), dirDigest);
assertThat(Files.exists(execRoot.resolve("test"))).isTrue();
assertThat(Files.exists(execRoot.resolve("test/foo"))).isTrue();
assertThat(Files.exists(execRoot.resolve("test/bar"))).isTrue();
assertThat(Files.exists(execRoot.resolve("test/bar/foo"))).isTrue();
assertThat(Files.isRegularFile(execRoot.resolve("test/foo"))).isTrue();
assertThat(Files.isDirectory(execRoot.resolve("test/bar"))).isTrue();
assertThat(Files.isRegularFile(execRoot.resolve("test/bar/foo"))).isTrue();
if (!System.getProperty("os.name").startsWith("Windows")) {
assertThat(isExecutable(execRoot.resolve("test/foo"))).isTrue();
assertThat(isExecutable(execRoot.resolve("test/bar/foo"))).isFalse();
}
}
use of build.bazel.remote.execution.v2.ContentAddressableStorageGrpc.ContentAddressableStorageImplBase in project tools_remote by bazelbuild.
the class GrpcRemoteCacheTest method testDownloadDirectoryEmpty.
@Test
public void testDownloadDirectoryEmpty() throws Exception {
GrpcRemoteCache client = newClient();
Directory dirMessage = Directory.getDefaultInstance();
Digest dirDigest = DIGEST_UTIL.compute(dirMessage);
serviceRegistry.addService(new FakeImmutableCacheByteStreamImpl(ImmutableMap.of(dirDigest, dirMessage.toByteString())));
serviceRegistry.addService(new ContentAddressableStorageImplBase() {
@Override
public void getTree(GetTreeRequest request, StreamObserver<GetTreeResponse> responseObserver) {
assertThat(request.getRootDigest()).isEqualTo(dirDigest);
responseObserver.onNext(GetTreeResponse.newBuilder().addDirectories(dirMessage).build());
responseObserver.onCompleted();
}
});
client.downloadDirectory(execRoot.resolve("test"), dirDigest);
assertThat(Files.exists(execRoot.resolve("test"))).isTrue();
}
Aggregations