Search in sources :

Example 1 with NO_RETRIES

use of build.buildfarm.common.grpc.Retrier.NO_RETRIES 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)

Aggregations

NO_RETRIES (build.buildfarm.common.grpc.Retrier.NO_RETRIES)1 ReadRequest (com.google.bytestream.ByteStreamProto.ReadRequest)1 ReadResponse (com.google.bytestream.ByteStreamProto.ReadResponse)1 StreamObserver (io.grpc.stub.StreamObserver)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 NoSuchFileException (java.nio.file.NoSuchFileException)1 Test (org.junit.Test)1