Search in sources :

Example 76 with Digest

use of com.google.cloud.kms.v1.Digest in project bazel-buildfarm by bazelbuild.

the class UtilTest method correctMissingBlobFailsImmediatelyOnUnretriable.

@Test
public void correctMissingBlobFailsImmediatelyOnUnretriable() throws InterruptedException {
    String workerName = "worker";
    Backplane backplane = mock(Backplane.class);
    Set<String> workerSet = ImmutableSet.of(workerName);
    Digest digest = Digest.newBuilder().setHash("digest-throws-exception-on-find-missing").setSizeBytes(1).build();
    ImmutableList<Digest> digests = ImmutableList.of(digest);
    Instance instance = mock(Instance.class);
    when(instance.findMissingBlobs(eq(digests), any(RequestMetadata.class))).thenReturn(immediateFailedFuture(Status.INVALID_ARGUMENT.asRuntimeException()));
    Function<String, Instance> workerInstanceFactory = worker -> {
        if (worker.equals(workerName)) {
            return instance;
        }
        return null;
    };
    ListenableFuture<Set<String>> correctFuture = correctMissingBlob(backplane, workerSet, /* originalLocationSet=*/
    ImmutableSet.of(), workerInstanceFactory, digest, directExecutor(), RequestMetadata.getDefaultInstance());
    boolean caughtException = false;
    try {
        correctFuture.get();
    } catch (ExecutionException e) {
        caughtException = true;
        Status status = Status.fromThrowable(e.getCause());
        assertThat(status.getCode()).isEqualTo(Code.INVALID_ARGUMENT);
    }
    verify(instance, times(1)).findMissingBlobs(eq(digests), any(RequestMetadata.class));
    assertThat(caughtException).isTrue();
    verifyZeroInteractions(backplane);
}
Also used : ListenableFuture(com.google.common.util.concurrent.ListenableFuture) RunWith(org.junit.runner.RunWith) RequestMetadata(build.bazel.remote.execution.v2.RequestMetadata) Util.correctMissingBlob(build.buildfarm.instance.shard.Util.correctMissingBlob) Function(java.util.function.Function) Mockito.verifyZeroInteractions(org.mockito.Mockito.verifyZeroInteractions) Mockito.doThrow(org.mockito.Mockito.doThrow) Code(io.grpc.Status.Code) ImmutableList(com.google.common.collect.ImmutableList) Digest(build.bazel.remote.execution.v2.Digest) Status(io.grpc.Status) Backplane(build.buildfarm.backplane.Backplane) Futures.immediateFuture(com.google.common.util.concurrent.Futures.immediateFuture) ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) Mockito.times(org.mockito.Mockito.times) IOException(java.io.IOException) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) JUnit4(org.junit.runners.JUnit4) Truth.assertThat(com.google.common.truth.Truth.assertThat) Instance(build.buildfarm.instance.Instance) MoreExecutors.directExecutor(com.google.common.util.concurrent.MoreExecutors.directExecutor) Mockito.verify(org.mockito.Mockito.verify) ExecutionException(java.util.concurrent.ExecutionException) Futures.immediateFailedFuture(com.google.common.util.concurrent.Futures.immediateFailedFuture) Mockito.any(org.mockito.Mockito.any) Mockito.eq(org.mockito.Mockito.eq) Mockito.mock(org.mockito.Mockito.mock) Status(io.grpc.Status) ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) Digest(build.bazel.remote.execution.v2.Digest) Instance(build.buildfarm.instance.Instance) Backplane(build.buildfarm.backplane.Backplane) RequestMetadata(build.bazel.remote.execution.v2.RequestMetadata) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test)

Example 77 with Digest

use of com.google.cloud.kms.v1.Digest in project bazel-buildfarm by bazelbuild.

the class UtilTest method correctMissingBlobIgnoresUnavailableWorkers.

@Test
public void correctMissingBlobIgnoresUnavailableWorkers() throws Exception {
    String workerName = "worker";
    String unavailableWorkerName = "unavailableWorker";
    Backplane backplane = mock(Backplane.class);
    Set<String> workerSet = ImmutableSet.of(workerName, unavailableWorkerName);
    Digest digest = Digest.newBuilder().setHash("digest").setSizeBytes(1).build();
    ImmutableList<Digest> digests = ImmutableList.of(digest);
    Instance instance = mock(Instance.class);
    when(instance.findMissingBlobs(eq(digests), any(RequestMetadata.class))).thenReturn(immediateFuture(ImmutableList.of()));
    Instance unavailableInstance = mock(Instance.class);
    when(unavailableInstance.findMissingBlobs(eq(digests), any(RequestMetadata.class))).thenReturn(immediateFailedFuture(Status.UNAVAILABLE.asRuntimeException()));
    Function<String, Instance> workerInstanceFactory = worker -> {
        if (worker.equals(workerName)) {
            return instance;
        }
        if (worker.equals(unavailableWorkerName)) {
            return unavailableInstance;
        }
        return null;
    };
    ListenableFuture<Set<String>> correctFuture = correctMissingBlob(backplane, workerSet, /* originalLocationSet=*/
    ImmutableSet.of(), workerInstanceFactory, digest, directExecutor(), RequestMetadata.getDefaultInstance());
    assertThat(correctFuture.get()).isEqualTo(ImmutableSet.of(workerName));
    verify(instance, times(1)).findMissingBlobs(eq(digests), any(RequestMetadata.class));
    verify(unavailableInstance, times(1)).findMissingBlobs(eq(digests), any(RequestMetadata.class));
    verify(backplane, times(1)).adjustBlobLocations(eq(digest), eq(ImmutableSet.of(workerName)), eq(ImmutableSet.of()));
}
Also used : ListenableFuture(com.google.common.util.concurrent.ListenableFuture) RunWith(org.junit.runner.RunWith) RequestMetadata(build.bazel.remote.execution.v2.RequestMetadata) Util.correctMissingBlob(build.buildfarm.instance.shard.Util.correctMissingBlob) Function(java.util.function.Function) Mockito.verifyZeroInteractions(org.mockito.Mockito.verifyZeroInteractions) Mockito.doThrow(org.mockito.Mockito.doThrow) Code(io.grpc.Status.Code) ImmutableList(com.google.common.collect.ImmutableList) Digest(build.bazel.remote.execution.v2.Digest) Status(io.grpc.Status) Backplane(build.buildfarm.backplane.Backplane) Futures.immediateFuture(com.google.common.util.concurrent.Futures.immediateFuture) ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) Mockito.times(org.mockito.Mockito.times) IOException(java.io.IOException) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) JUnit4(org.junit.runners.JUnit4) Truth.assertThat(com.google.common.truth.Truth.assertThat) Instance(build.buildfarm.instance.Instance) MoreExecutors.directExecutor(com.google.common.util.concurrent.MoreExecutors.directExecutor) Mockito.verify(org.mockito.Mockito.verify) ExecutionException(java.util.concurrent.ExecutionException) Futures.immediateFailedFuture(com.google.common.util.concurrent.Futures.immediateFailedFuture) Mockito.any(org.mockito.Mockito.any) Mockito.eq(org.mockito.Mockito.eq) Mockito.mock(org.mockito.Mockito.mock) ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) Digest(build.bazel.remote.execution.v2.Digest) Instance(build.buildfarm.instance.Instance) Backplane(build.buildfarm.backplane.Backplane) RequestMetadata(build.bazel.remote.execution.v2.RequestMetadata) Test(org.junit.Test)

Example 78 with Digest

use of com.google.cloud.kms.v1.Digest in project bazel-buildfarm by bazelbuild.

the class StubInstanceTest method inputStreamRetriesOnDeadlineExceededWithProgress.

@Test
public void inputStreamRetriesOnDeadlineExceededWithProgress() throws IOException, InterruptedException {
    ByteString content = ByteString.copyFromUtf8("1");
    serviceRegistry.addService(new ByteStreamImplBase() {

        boolean first = true;

        @Override
        public void read(ReadRequest request, StreamObserver<ReadResponse> responseObserver) {
            if (first && request.getReadOffset() == 0) {
                first = false;
                responseObserver.onNext(ReadResponse.newBuilder().setData(content).build());
                responseObserver.onError(Status.DEADLINE_EXCEEDED.asException());
            } else if (request.getReadOffset() == 1) {
                responseObserver.onCompleted();
            } else {
                // all others fail with unimplemented
                responseObserver.onError(Status.UNIMPLEMENTED.asException());
            }
        }
    });
    Instance instance = newStubInstance("input-stream-stalled");
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    Digest delayedDigest = Digest.newBuilder().setHash("delayed-blob-name").setSizeBytes(1).build();
    try (InputStream in = instance.newBlobInput(delayedDigest, 0, 1, SECONDS, RequestMetadata.getDefaultInstance())) {
        ByteStreams.copy(in, out);
    }
    assertThat(ByteString.copyFrom(out.toByteArray())).isEqualTo(content);
    instance.stop();
}
Also used : ReadResponse(com.google.bytestream.ByteStreamProto.ReadResponse) Instance(build.buildfarm.instance.Instance) Digest(build.bazel.remote.execution.v2.Digest) ByteString(com.google.protobuf.ByteString) InputStream(java.io.InputStream) ByteStreamImplBase(com.google.bytestream.ByteStreamGrpc.ByteStreamImplBase) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ReadRequest(com.google.bytestream.ByteStreamProto.ReadRequest) Test(org.junit.Test)

Example 79 with Digest

use of com.google.cloud.kms.v1.Digest in project bazel-buildfarm by bazelbuild.

the class StubInstanceTest method inputStreamThrowsNonDeadlineExceededCausal.

@Test
public void inputStreamThrowsNonDeadlineExceededCausal() throws IOException, InterruptedException {
    serviceRegistry.addService(new ByteStreamImplBase() {

        @Override
        public void read(ReadRequest request, StreamObserver<ReadResponse> responseObserver) {
            responseObserver.onError(Status.UNAVAILABLE.asException());
        }
    });
    OutputStream out = mock(OutputStream.class);
    IOException ioException = null;
    Instance instance = newStubInstance("input-stream-non-deadline-exceeded");
    Digest unavailableDigest = Digest.newBuilder().setHash("unavailable-blob-name").setSizeBytes(1).build();
    try (InputStream in = instance.newBlobInput(unavailableDigest, 0, 1, SECONDS, RequestMetadata.getDefaultInstance())) {
        ByteStreams.copy(in, out);
    } catch (IOException e) {
        ioException = e;
    }
    assertThat(ioException).isNotNull();
    Status status = Status.fromThrowable(ioException);
    assertThat(status.getCode()).isEqualTo(Code.UNAVAILABLE);
    verifyZeroInteractions(out);
    instance.stop();
}
Also used : Status(io.grpc.Status) ReadResponse(com.google.bytestream.ByteStreamProto.ReadResponse) Instance(build.buildfarm.instance.Instance) Digest(build.bazel.remote.execution.v2.Digest) InputStream(java.io.InputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) ByteStreamImplBase(com.google.bytestream.ByteStreamGrpc.ByteStreamImplBase) IOException(java.io.IOException) ReadRequest(com.google.bytestream.ByteStreamProto.ReadRequest) Test(org.junit.Test)

Example 80 with Digest

use of com.google.cloud.kms.v1.Digest in project bazel-buildfarm by bazelbuild.

the class StubInstanceTest method putAllBlobsUploadsBlobs.

@Test
public void putAllBlobsUploadsBlobs() throws Exception {
    String instanceName = "putAllBlobs-test";
    serviceRegistry.addService(new ContentAddressableStorageImplBase() {

        @Override
        public void batchUpdateBlobs(BatchUpdateBlobsRequest batchRequest, StreamObserver<BatchUpdateBlobsResponse> responseObserver) {
            checkState(batchRequest.getInstanceName().equals(instanceName));
            responseObserver.onNext(BatchUpdateBlobsResponse.newBuilder().addAllResponses(batchRequest.getRequestsList().stream().map(request -> Response.newBuilder().setDigest(request.getDigest()).build()).collect(Collectors.toList())).build());
            responseObserver.onCompleted();
        }
    });
    Instance instance = newStubInstance("putAllBlobs-test");
    ByteString first = ByteString.copyFromUtf8("first");
    ByteString last = ByteString.copyFromUtf8("last");
    ImmutableList<ByteString> blobs = ImmutableList.of(first, last);
    ImmutableList<Digest> digests = ImmutableList.of(DIGEST_UTIL.compute(first), DIGEST_UTIL.compute(last));
    assertThat(instance.putAllBlobs(blobs, RequestMetadata.getDefaultInstance())).containsAllIn(digests);
}
Also used : RequestMetadata(build.bazel.remote.execution.v2.RequestMetadata) ActionKey(build.buildfarm.common.DigestUtil.ActionKey) ReadBlobInterchange(build.buildfarm.instance.stub.StubInstance.ReadBlobInterchange) StreamObserver(io.grpc.stub.StreamObserver) Digest(build.bazel.remote.execution.v2.Digest) ReadRequest(com.google.bytestream.ByteStreamProto.ReadRequest) After(org.junit.After) Status(io.grpc.Status) InProcessChannelBuilder(io.grpc.inprocess.InProcessChannelBuilder) ServerCallStreamObserver(io.grpc.stub.ServerCallStreamObserver) BatchUpdateBlobsRequest(build.bazel.remote.execution.v2.BatchUpdateBlobsRequest) ByteStreamImplBase(com.google.bytestream.ByteStreamGrpc.ByteStreamImplBase) ClientCallStreamObserver(io.grpc.stub.ClientCallStreamObserver) Collectors(java.util.stream.Collectors) Instance(build.buildfarm.instance.Instance) Preconditions.checkState(com.google.common.base.Preconditions.checkState) ByteString(com.google.protobuf.ByteString) MutableHandlerRegistry(io.grpc.util.MutableHandlerRegistry) ByteStreams(com.google.common.io.ByteStreams) QueryWriteStatusResponse(com.google.bytestream.ByteStreamProto.QueryWriteStatusResponse) Mockito.mock(org.mockito.Mockito.mock) GetActionResultRequest(build.bazel.remote.execution.v2.GetActionResultRequest) ContentAddressableStorageImplBase(build.bazel.remote.execution.v2.ContentAddressableStorageGrpc.ContentAddressableStorageImplBase) ByteArrayOutputStream(java.io.ByteArrayOutputStream) FindMissingBlobsRequest(build.bazel.remote.execution.v2.FindMissingBlobsRequest) RunWith(org.junit.runner.RunWith) QueryWriteStatusRequest(com.google.bytestream.ByteStreamProto.QueryWriteStatusRequest) AtomicReference(java.util.concurrent.atomic.AtomicReference) DigestUtil(build.buildfarm.common.DigestUtil) Mockito.verifyZeroInteractions(org.mockito.Mockito.verifyZeroInteractions) InProcessServerBuilder(io.grpc.inprocess.InProcessServerBuilder) Code(io.grpc.Status.Code) Action(build.bazel.remote.execution.v2.Action) ArgumentCaptor(org.mockito.ArgumentCaptor) ImmutableList(com.google.common.collect.ImmutableList) ActionResult(build.bazel.remote.execution.v2.ActionResult) ReadResponse(com.google.bytestream.ByteStreamProto.ReadResponse) FindMissingBlobsResponse(build.bazel.remote.execution.v2.FindMissingBlobsResponse) Server(io.grpc.Server) Before(org.junit.Before) OutputStream(java.io.OutputStream) UpdateActionResultRequest(build.bazel.remote.execution.v2.UpdateActionResultRequest) ActionCacheImplBase(build.bazel.remote.execution.v2.ActionCacheGrpc.ActionCacheImplBase) Mockito.times(org.mockito.Mockito.times) IOException(java.io.IOException) Test(org.junit.Test) JUnit4(org.junit.runners.JUnit4) Truth.assertThat(com.google.common.truth.Truth.assertThat) BatchUpdateBlobsResponse(build.bazel.remote.execution.v2.BatchUpdateBlobsResponse) Write(build.buildfarm.common.Write) Mockito.verify(org.mockito.Mockito.verify) WriteResponse(com.google.bytestream.ByteStreamProto.WriteResponse) ExecutionException(java.util.concurrent.ExecutionException) Response(build.bazel.remote.execution.v2.BatchUpdateBlobsResponse.Response) WriteRequest(com.google.bytestream.ByteStreamProto.WriteRequest) SECONDS(java.util.concurrent.TimeUnit.SECONDS) InputStream(java.io.InputStream) BatchUpdateBlobsResponse(build.bazel.remote.execution.v2.BatchUpdateBlobsResponse) Instance(build.buildfarm.instance.Instance) Digest(build.bazel.remote.execution.v2.Digest) ByteString(com.google.protobuf.ByteString) ContentAddressableStorageImplBase(build.bazel.remote.execution.v2.ContentAddressableStorageGrpc.ContentAddressableStorageImplBase) ByteString(com.google.protobuf.ByteString) BatchUpdateBlobsRequest(build.bazel.remote.execution.v2.BatchUpdateBlobsRequest) Test(org.junit.Test)

Aggregations

Digest (build.bazel.remote.execution.v2.Digest)191 ByteString (com.google.protobuf.ByteString)110 Test (org.junit.Test)99 IOException (java.io.IOException)55 Directory (build.bazel.remote.execution.v2.Directory)42 ImmutableList (com.google.common.collect.ImmutableList)35 Path (java.nio.file.Path)33 Status (io.grpc.Status)30 ExecutionException (java.util.concurrent.ExecutionException)29 RequestMetadata (build.bazel.remote.execution.v2.RequestMetadata)27 InputStream (java.io.InputStream)25 Instance (build.buildfarm.instance.Instance)24 Action (build.bazel.remote.execution.v2.Action)22 DigestUtil (build.buildfarm.common.DigestUtil)22 OutputStream (java.io.OutputStream)22 Write (build.buildfarm.common.Write)21 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)21 Operation (com.google.longrunning.Operation)21 UUID (java.util.UUID)20 ExecuteResponse (build.bazel.remote.execution.v2.ExecuteResponse)19