Search in sources :

Example 11 with ReadRequest

use of com.google.bytestream.ByteStreamProto.ReadRequest in project bazel-buildfarm by bazelbuild.

the class GrpcCAS method get.

@Override
public void get(Digest digest, long offset, long count, ServerCallStreamObserver<ByteString> blobObserver, RequestMetadata requestMetadata) {
    ReadRequest request = ReadRequest.newBuilder().setResourceName(getBlobName(digest)).setReadOffset(offset).setReadLimit(count).build();
    ByteStreamGrpc.newStub(channel).withInterceptors(attachMetadataInterceptor(requestMetadata)).read(request, new DelegateServerCallStreamObserver<ReadResponse, ByteString>(blobObserver) {

        @Override
        public void onNext(ReadResponse response) {
            blobObserver.onNext(response.getData());
        }

        @Override
        public void onError(Throwable t) {
            blobObserver.onError(t);
        }

        @Override
        public void onCompleted() {
            blobObserver.onCompleted();
        }
    });
}
Also used : ReadResponse(com.google.bytestream.ByteStreamProto.ReadResponse) ByteString(com.google.protobuf.ByteString) ReadRequest(com.google.bytestream.ByteStreamProto.ReadRequest)

Example 12 with ReadRequest

use of com.google.bytestream.ByteStreamProto.ReadRequest in project bazel-buildfarm by bazelbuild.

the class GrpcCASTest method getHandlesNotFound.

@Test
public void getHandlesNotFound() {
    Digest digest = DIGEST_UTIL.compute(ByteString.copyFromUtf8("nonexistent"));
    String instanceName = "test";
    final AtomicReference<Boolean> readCalled = new AtomicReference<>(false);
    serviceRegistry.addService(new ByteStreamImplBase() {

        @Override
        public void read(ReadRequest request, StreamObserver<ReadResponse> responseObserver) {
            assertThat(request.getResourceName()).isEqualTo(String.format("%s/blobs/%s", instanceName, DigestUtil.toString(digest)));
            readCalled.compareAndSet(false, true);
            responseObserver.onError(Status.NOT_FOUND.asException());
        }
    });
    GrpcCAS cas = new GrpcCAS(instanceName, InProcessChannelBuilder.forName(fakeServerName).directExecutor().build(), mock(ByteStreamUploader.class), onExpirations);
    assertThat(cas.get(digest)).isNull();
    assertThat(readCalled.get()).isTrue();
}
Also used : ByteStreamUploader(build.buildfarm.instance.stub.ByteStreamUploader) Digest(build.bazel.remote.execution.v2.Digest) ReadResponse(com.google.bytestream.ByteStreamProto.ReadResponse) ByteStreamImplBase(com.google.bytestream.ByteStreamGrpc.ByteStreamImplBase) AtomicReference(java.util.concurrent.atomic.AtomicReference) ByteString(com.google.protobuf.ByteString) ReadRequest(com.google.bytestream.ByteStreamProto.ReadRequest) Test(org.junit.Test)

Example 13 with ReadRequest

use of com.google.bytestream.ByteStreamProto.ReadRequest in project bazel-buildfarm by bazelbuild.

the class ByteStreamHelperTest method newInputThrowsOnNotFound.

@SuppressWarnings("unchecked")
@Test
public void newInputThrowsOnNotFound() {
    String resourceName = "not/found/resource";
    ReadRequest readRequest = ReadRequest.newBuilder().setResourceName(resourceName).build();
    doAnswer(invocation -> {
        StreamObserver<ReadResponse> observer = invocation.getArgument(1);
        observer.onError(Status.NOT_FOUND.asException());
        return null;
    }).when(serviceImpl).read(eq(readRequest), any(StreamObserver.class));
    try (InputStream in = ByteStreamHelper.newInput(resourceName, /* offset=*/
    0, Suppliers.ofInstance(ByteStreamGrpc.newStub(channel)), NO_RETRIES::newBackoff, NO_RETRIES::isRetriable, /* retryService=*/
    null)) {
        fail("should not get here");
    } catch (IOException e) {
        assertThat(e).isInstanceOf(NoSuchFileException.class);
    }
    verify(serviceImpl, times(1)).read(eq(readRequest), any(StreamObserver.class));
}
Also used : StreamObserver(io.grpc.stub.StreamObserver) ReadResponse(com.google.bytestream.ByteStreamProto.ReadResponse) InputStream(java.io.InputStream) NoSuchFileException(java.nio.file.NoSuchFileException) NO_RETRIES(build.buildfarm.common.grpc.Retrier.NO_RETRIES) IOException(java.io.IOException) ReadRequest(com.google.bytestream.ByteStreamProto.ReadRequest) Test(org.junit.Test)

Example 14 with ReadRequest

use of com.google.bytestream.ByteStreamProto.ReadRequest in project tools_remote by bazelbuild.

the class GrpcRemoteCacheTest method testDownloadBlobMultipleChunks.

@Test
public void testDownloadBlobMultipleChunks() throws Exception {
    final GrpcRemoteCache client = newClient();
    final Digest digest = DIGEST_UTIL.computeAsUtf8("abcdefg");
    serviceRegistry.addService(new ByteStreamImplBase() {

        @Override
        public void read(ReadRequest request, StreamObserver<ReadResponse> responseObserver) {
            assertThat(request.getResourceName().contains(digest.getHash())).isTrue();
            responseObserver.onNext(ReadResponse.newBuilder().setData(ByteString.copyFromUtf8("abc")).build());
            responseObserver.onNext(ReadResponse.newBuilder().setData(ByteString.copyFromUtf8("def")).build());
            responseObserver.onNext(ReadResponse.newBuilder().setData(ByteString.copyFromUtf8("g")).build());
            responseObserver.onCompleted();
        }
    });
    assertThat(new String(client.downloadBlob(digest), UTF_8)).isEqualTo("abcdefg");
}
Also used : Digest(build.bazel.remote.execution.v2.Digest) ReadResponse(com.google.bytestream.ByteStreamProto.ReadResponse) ByteStreamImplBase(com.google.bytestream.ByteStreamGrpc.ByteStreamImplBase) ByteString(com.google.protobuf.ByteString) ReadRequest(com.google.bytestream.ByteStreamProto.ReadRequest) Test(org.junit.Test)

Aggregations

ReadRequest (com.google.bytestream.ByteStreamProto.ReadRequest)14 ReadResponse (com.google.bytestream.ByteStreamProto.ReadResponse)12 Test (org.junit.Test)12 ByteString (com.google.protobuf.ByteString)11 Digest (build.bazel.remote.execution.v2.Digest)10 ByteStreamImplBase (com.google.bytestream.ByteStreamGrpc.ByteStreamImplBase)7 IOException (java.io.IOException)5 InputStream (java.io.InputStream)5 Instance (build.buildfarm.instance.Instance)4 Status (io.grpc.Status)4 OutputStream (java.io.OutputStream)4 ByteStreamUploader (build.buildfarm.instance.stub.ByteStreamUploader)3 Channel (io.grpc.Channel)3 StreamObserver (io.grpc.stub.StreamObserver)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 ByteStreamStub (com.google.bytestream.ByteStreamGrpc.ByteStreamStub)2 NoSuchFileException (java.nio.file.NoSuchFileException)2 RequestMetadata (build.bazel.remote.execution.v2.RequestMetadata)1 DigestUtil (build.buildfarm.common.DigestUtil)1 SHA256 (build.buildfarm.common.DigestUtil.HashFunction.SHA256)1