Search in sources :

Example 1 with ContentAddressableStorageImplBase

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);
}
Also used : Digest(build.bazel.remote.execution.v2.Digest) Channel(io.grpc.Channel) ContentAddressableStorageImplBase(build.bazel.remote.execution.v2.ContentAddressableStorageGrpc.ContentAddressableStorageImplBase) Test(org.junit.Test)

Example 2 with ContentAddressableStorageImplBase

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);
}
Also used : RequestMetadata(build.bazel.remote.execution.v2.RequestMetadata) ActionKey(build.buildfarm.common.DigestUtil.ActionKey) ReadBlobInterchange(build.buildfarm.instance.stub.StubInstance.ReadBlobInterchange) StreamObserver(io.grpc.stub.StreamObserver) Digest(build.bazel.remote.execution.v2.Digest) ReadRequest(com.google.bytestream.ByteStreamProto.ReadRequest) After(org.junit.After) Status(io.grpc.Status) InProcessChannelBuilder(io.grpc.inprocess.InProcessChannelBuilder) ServerCallStreamObserver(io.grpc.stub.ServerCallStreamObserver) BatchUpdateBlobsRequest(build.bazel.remote.execution.v2.BatchUpdateBlobsRequest) ByteStreamImplBase(com.google.bytestream.ByteStreamGrpc.ByteStreamImplBase) ClientCallStreamObserver(io.grpc.stub.ClientCallStreamObserver) Collectors(java.util.stream.Collectors) Instance(build.buildfarm.instance.Instance) Preconditions.checkState(com.google.common.base.Preconditions.checkState) ByteString(com.google.protobuf.ByteString) MutableHandlerRegistry(io.grpc.util.MutableHandlerRegistry) ByteStreams(com.google.common.io.ByteStreams) QueryWriteStatusResponse(com.google.bytestream.ByteStreamProto.QueryWriteStatusResponse) Mockito.mock(org.mockito.Mockito.mock) GetActionResultRequest(build.bazel.remote.execution.v2.GetActionResultRequest) ContentAddressableStorageImplBase(build.bazel.remote.execution.v2.ContentAddressableStorageGrpc.ContentAddressableStorageImplBase) ByteArrayOutputStream(java.io.ByteArrayOutputStream) FindMissingBlobsRequest(build.bazel.remote.execution.v2.FindMissingBlobsRequest) RunWith(org.junit.runner.RunWith) QueryWriteStatusRequest(com.google.bytestream.ByteStreamProto.QueryWriteStatusRequest) AtomicReference(java.util.concurrent.atomic.AtomicReference) DigestUtil(build.buildfarm.common.DigestUtil) Mockito.verifyZeroInteractions(org.mockito.Mockito.verifyZeroInteractions) InProcessServerBuilder(io.grpc.inprocess.InProcessServerBuilder) Code(io.grpc.Status.Code) Action(build.bazel.remote.execution.v2.Action) ArgumentCaptor(org.mockito.ArgumentCaptor) ImmutableList(com.google.common.collect.ImmutableList) ActionResult(build.bazel.remote.execution.v2.ActionResult) ReadResponse(com.google.bytestream.ByteStreamProto.ReadResponse) FindMissingBlobsResponse(build.bazel.remote.execution.v2.FindMissingBlobsResponse) Server(io.grpc.Server) Before(org.junit.Before) OutputStream(java.io.OutputStream) UpdateActionResultRequest(build.bazel.remote.execution.v2.UpdateActionResultRequest) ActionCacheImplBase(build.bazel.remote.execution.v2.ActionCacheGrpc.ActionCacheImplBase) Mockito.times(org.mockito.Mockito.times) IOException(java.io.IOException) Test(org.junit.Test) JUnit4(org.junit.runners.JUnit4) Truth.assertThat(com.google.common.truth.Truth.assertThat) BatchUpdateBlobsResponse(build.bazel.remote.execution.v2.BatchUpdateBlobsResponse) Write(build.buildfarm.common.Write) Mockito.verify(org.mockito.Mockito.verify) WriteResponse(com.google.bytestream.ByteStreamProto.WriteResponse) ExecutionException(java.util.concurrent.ExecutionException) Response(build.bazel.remote.execution.v2.BatchUpdateBlobsResponse.Response) WriteRequest(com.google.bytestream.ByteStreamProto.WriteRequest) SECONDS(java.util.concurrent.TimeUnit.SECONDS) InputStream(java.io.InputStream) BatchUpdateBlobsResponse(build.bazel.remote.execution.v2.BatchUpdateBlobsResponse) Instance(build.buildfarm.instance.Instance) Digest(build.bazel.remote.execution.v2.Digest) ByteString(com.google.protobuf.ByteString) ContentAddressableStorageImplBase(build.bazel.remote.execution.v2.ContentAddressableStorageGrpc.ContentAddressableStorageImplBase) ByteString(com.google.protobuf.ByteString) BatchUpdateBlobsRequest(build.bazel.remote.execution.v2.BatchUpdateBlobsRequest) Test(org.junit.Test)

Example 3 with ContentAddressableStorageImplBase

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();
}
Also used : FindMissingBlobsResponse(build.bazel.remote.execution.v2.FindMissingBlobsResponse) Instance(build.buildfarm.instance.Instance) Digest(build.bazel.remote.execution.v2.Digest) ContentAddressableStorageImplBase(build.bazel.remote.execution.v2.ContentAddressableStorageGrpc.ContentAddressableStorageImplBase) AtomicReference(java.util.concurrent.atomic.AtomicReference) FindMissingBlobsRequest(build.bazel.remote.execution.v2.FindMissingBlobsRequest) Test(org.junit.Test)

Example 4 with ContentAddressableStorageImplBase

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();
    }
}
Also used : GetTreeResponse(build.bazel.remote.execution.v2.GetTreeResponse) Digest(build.bazel.remote.execution.v2.Digest) ContentAddressableStorageImplBase(build.bazel.remote.execution.v2.ContentAddressableStorageGrpc.ContentAddressableStorageImplBase) GetTreeRequest(build.bazel.remote.execution.v2.GetTreeRequest) Directory(build.bazel.remote.execution.v2.Directory) OutputDirectory(build.bazel.remote.execution.v2.OutputDirectory) Test(org.junit.Test)

Example 5 with ContentAddressableStorageImplBase

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();
}
Also used : GetTreeResponse(build.bazel.remote.execution.v2.GetTreeResponse) Digest(build.bazel.remote.execution.v2.Digest) ContentAddressableStorageImplBase(build.bazel.remote.execution.v2.ContentAddressableStorageGrpc.ContentAddressableStorageImplBase) GetTreeRequest(build.bazel.remote.execution.v2.GetTreeRequest) Directory(build.bazel.remote.execution.v2.Directory) OutputDirectory(build.bazel.remote.execution.v2.OutputDirectory) Test(org.junit.Test)

Aggregations

ContentAddressableStorageImplBase (build.bazel.remote.execution.v2.ContentAddressableStorageGrpc.ContentAddressableStorageImplBase)6 Digest (build.bazel.remote.execution.v2.Digest)6 Test (org.junit.Test)6 Directory (build.bazel.remote.execution.v2.Directory)3 GetTreeRequest (build.bazel.remote.execution.v2.GetTreeRequest)3 GetTreeResponse (build.bazel.remote.execution.v2.GetTreeResponse)3 OutputDirectory (build.bazel.remote.execution.v2.OutputDirectory)3 FindMissingBlobsRequest (build.bazel.remote.execution.v2.FindMissingBlobsRequest)2 FindMissingBlobsResponse (build.bazel.remote.execution.v2.FindMissingBlobsResponse)2 Instance (build.buildfarm.instance.Instance)2 Action (build.bazel.remote.execution.v2.Action)1 ActionCacheImplBase (build.bazel.remote.execution.v2.ActionCacheGrpc.ActionCacheImplBase)1 ActionResult (build.bazel.remote.execution.v2.ActionResult)1 BatchUpdateBlobsRequest (build.bazel.remote.execution.v2.BatchUpdateBlobsRequest)1 BatchUpdateBlobsResponse (build.bazel.remote.execution.v2.BatchUpdateBlobsResponse)1 Response (build.bazel.remote.execution.v2.BatchUpdateBlobsResponse.Response)1 GetActionResultRequest (build.bazel.remote.execution.v2.GetActionResultRequest)1 RequestMetadata (build.bazel.remote.execution.v2.RequestMetadata)1 Tree (build.bazel.remote.execution.v2.Tree)1 UpdateActionResultRequest (build.bazel.remote.execution.v2.UpdateActionResultRequest)1