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