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();
}
});
}
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();
}
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));
}
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");
}
Aggregations