Search in sources :

Example 6 with WriteResponse

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

the class ByteStreamUploaderTest method uploadBlobPropagatesIOExceptionFromIncompleteUpload.

@Test(expected = IOException.class)
public void uploadBlobPropagatesIOExceptionFromIncompleteUpload() throws IOException, InterruptedException {
    serviceRegistry.addService(new ByteStreamImplBase() {

        @Override
        public StreamObserver<WriteRequest> write(StreamObserver<WriteResponse> responseObserver) {
            responseObserver.onNext(WriteResponse.newBuilder().setCommittedSize(1).build());
            responseObserver.onCompleted();
            return new StreamObserver<WriteRequest>() {

                @Override
                public void onNext(WriteRequest request) {
                }

                @Override
                public void onError(Throwable t) {
                }

                @Override
                public void onCompleted() {
                }
            };
        }
    });
    ByteStreamUploader uploader = new ByteStreamUploader(/* instanceName=*/
    null, InProcessChannelBuilder.forName(fakeServerName).directExecutor().build(), /* callCredentials=*/
    null, /* callTimeoutSecs=*/
    1, NO_RETRIES);
    Chunker chunker = Chunker.builder().setInput(ByteString.copyFromUtf8("Hello, World!")).build();
    uploader.uploadBlob(HashCode.fromInt(42), chunker);
}
Also used : StreamObserver(io.grpc.stub.StreamObserver) WriteRequest(com.google.bytestream.ByteStreamProto.WriteRequest) ByteStreamImplBase(com.google.bytestream.ByteStreamGrpc.ByteStreamImplBase) WriteResponse(com.google.bytestream.ByteStreamProto.WriteResponse) Test(org.junit.Test)

Example 7 with WriteResponse

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

the class StubInstanceTest method outputStreamWrites.

@Test
public void outputStreamWrites() throws IOException, InterruptedException {
    AtomicReference<ByteString> writtenContent = new AtomicReference<>();
    serviceRegistry.addService(new ByteStreamImplBase() {

        ByteString content = ByteString.EMPTY;

        boolean finished = false;

        public void queryWriteStatus(QueryWriteStatusRequest request, StreamObserver<QueryWriteStatusResponse> responseObserver) {
            responseObserver.onNext(QueryWriteStatusResponse.newBuilder().setCommittedSize(content.size()).setComplete(finished).build());
            responseObserver.onCompleted();
        }

        @Override
        public StreamObserver<WriteRequest> write(StreamObserver<WriteResponse> responseObserver) {
            return new StreamObserver<WriteRequest>() {

                @Override
                public void onNext(WriteRequest request) {
                    checkState(!finished);
                    if (request.getData().size() != 0) {
                        checkState(request.getWriteOffset() == content.size());
                        content = content.concat(request.getData());
                    }
                    finished = request.getFinishWrite();
                    if (finished) {
                        writtenContent.set(content);
                        responseObserver.onNext(WriteResponse.newBuilder().setCommittedSize(content.size()).build());
                    }
                }

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

                @Override
                public void onCompleted() {
                    responseObserver.onCompleted();
                }
            };
        }
    });
    Instance instance = newStubInstance("outputStream-test");
    String resourceName = "output-stream-test";
    ByteString content = ByteString.copyFromUtf8("test-content");
    Write operationStreamWrite = instance.getOperationStreamWrite(resourceName);
    try (OutputStream out = operationStreamWrite.getOutput(1, SECONDS, () -> {
    })) {
        content.writeTo(out);
    }
    assertThat(writtenContent.get()).isEqualTo(content);
    instance.stop();
}
Also used : StreamObserver(io.grpc.stub.StreamObserver) ServerCallStreamObserver(io.grpc.stub.ServerCallStreamObserver) ClientCallStreamObserver(io.grpc.stub.ClientCallStreamObserver) Write(build.buildfarm.common.Write) Instance(build.buildfarm.instance.Instance) ByteString(com.google.protobuf.ByteString) WriteRequest(com.google.bytestream.ByteStreamProto.WriteRequest) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) ByteStreamImplBase(com.google.bytestream.ByteStreamGrpc.ByteStreamImplBase) WriteResponse(com.google.bytestream.ByteStreamProto.WriteResponse) AtomicReference(java.util.concurrent.atomic.AtomicReference) ByteString(com.google.protobuf.ByteString) QueryWriteStatusResponse(com.google.bytestream.ByteStreamProto.QueryWriteStatusResponse) QueryWriteStatusRequest(com.google.bytestream.ByteStreamProto.QueryWriteStatusRequest) Test(org.junit.Test)

Aggregations

WriteResponse (com.google.bytestream.ByteStreamProto.WriteResponse)7 WriteRequest (com.google.bytestream.ByteStreamProto.WriteRequest)6 ByteString (com.google.protobuf.ByteString)5 Test (org.junit.Test)5 StreamObserver (io.grpc.stub.StreamObserver)4 Digest (build.bazel.remote.execution.v2.Digest)3 ByteStreamImplBase (com.google.bytestream.ByteStreamGrpc.ByteStreamImplBase)3 QueryWriteStatusResponse (com.google.bytestream.ByteStreamProto.QueryWriteStatusResponse)3 Channel (io.grpc.Channel)3 IOException (java.io.IOException)3 InputStream (java.io.InputStream)3 Write (build.buildfarm.common.Write)2 Instance (build.buildfarm.instance.Instance)2 QueryWriteStatusRequest (com.google.bytestream.ByteStreamProto.QueryWriteStatusRequest)2 BatchUpdateBlobsRequest (build.bazel.remote.execution.v2.BatchUpdateBlobsRequest)1 Request (build.bazel.remote.execution.v2.BatchUpdateBlobsRequest.Request)1 BatchUpdateBlobsResponse (build.bazel.remote.execution.v2.BatchUpdateBlobsResponse)1 ContentAddressableStorageGrpc (build.bazel.remote.execution.v2.ContentAddressableStorageGrpc)1 ContentAddressableStorageBlockingStub (build.bazel.remote.execution.v2.ContentAddressableStorageGrpc.ContentAddressableStorageBlockingStub)1 ExecuteOperationMetadata (build.bazel.remote.execution.v2.ExecuteOperationMetadata)1