Search in sources :

Example 71 with Digest

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

the class ShardInstanceTest method duplicateExecutionsServedFromCacheAreForcedToSkipLookup.

@Test
public void duplicateExecutionsServedFromCacheAreForcedToSkipLookup() throws Exception {
    ActionKey actionKey = DigestUtil.asActionKey(Digest.newBuilder().setHash("test").build());
    ActionResult actionResult = ActionResult.newBuilder().addOutputFiles(OutputFile.newBuilder().setPath("does-not-exist").setDigest(Digest.newBuilder().setHash("dne").setSizeBytes(1))).setStdoutDigest(Digest.newBuilder().setHash("stdout").setSizeBytes(1)).setStderrDigest(Digest.newBuilder().setHash("stderr").setSizeBytes(1)).build();
    when(mockBackplane.canQueue()).thenReturn(true);
    when(mockBackplane.canPrequeue()).thenReturn(true);
    when(mockBackplane.getActionResult(actionKey)).thenReturn(actionResult);
    Digest actionDigest = actionKey.getDigest();
    RequestMetadata requestMetadata = RequestMetadata.newBuilder().setToolDetails(ToolDetails.newBuilder().setToolName("buildfarm-test").setToolVersion("0.1")).setCorrelatedInvocationsId(UUID.randomUUID().toString()).setToolInvocationId(UUID.randomUUID().toString()).setActionId(actionDigest.getHash()).build();
    String operationName = "cache-served-operation";
    ExecuteEntry cacheServedExecuteEntry = ExecuteEntry.newBuilder().setOperationName(operationName).setActionDigest(actionDigest).setRequestMetadata(requestMetadata).build();
    Poller poller = mock(Poller.class);
    instance.queue(cacheServedExecuteEntry, poller, DEFAULT_TIMEOUT).get(QUEUE_TEST_TIMEOUT_SECONDS, SECONDS);
    verify(poller, times(1)).pause();
    verify(mockBackplane, never()).queue(any(QueueEntry.class), any(Operation.class));
    ArgumentCaptor<Operation> cacheCheckOperationCaptor = ArgumentCaptor.forClass(Operation.class);
    verify(mockBackplane, times(1)).putOperation(cacheCheckOperationCaptor.capture(), eq(CACHE_CHECK));
    Operation cacheCheckOperation = cacheCheckOperationCaptor.getValue();
    assertThat(cacheCheckOperation.getName()).isEqualTo(operationName);
    ArgumentCaptor<Operation> completedOperationCaptor = ArgumentCaptor.forClass(Operation.class);
    verify(mockBackplane, times(1)).putOperation(completedOperationCaptor.capture(), eq(COMPLETED));
    Operation completedOperation = completedOperationCaptor.getValue();
    assertThat(completedOperation.getName()).isEqualTo(operationName);
    ExecuteResponse executeResponse = completedOperation.getResponse().unpack(ExecuteResponse.class);
    assertThat(executeResponse.getResult()).isEqualTo(actionResult);
    assertThat(executeResponse.getCachedResult()).isTrue();
    Watcher mockWatcher = mock(Watcher.class);
    instance.execute(actionDigest, /* skipCacheLookup=*/
    false, ExecutionPolicy.getDefaultInstance(), ResultsCachePolicy.getDefaultInstance(), requestMetadata, /* watcher=*/
    mockWatcher);
    verify(mockWatcher, times(1)).observe(any(Operation.class));
    ArgumentCaptor<ExecuteEntry> executeEntryCaptor = ArgumentCaptor.forClass(ExecuteEntry.class);
    verify(mockBackplane, times(1)).prequeue(executeEntryCaptor.capture(), any(Operation.class));
    ExecuteEntry executeEntry = executeEntryCaptor.getValue();
    assertThat(executeEntry.getSkipCacheLookup()).isTrue();
}
Also used : Digest(build.bazel.remote.execution.v2.Digest) ExecuteEntry(build.buildfarm.v1test.ExecuteEntry) Watcher(build.buildfarm.common.Watcher) ActionKey(build.buildfarm.common.DigestUtil.ActionKey) ExecuteResponse(build.bazel.remote.execution.v2.ExecuteResponse) ByteString(com.google.protobuf.ByteString) QueuedOperation(build.buildfarm.v1test.QueuedOperation) Operation(com.google.longrunning.Operation) QueueEntry(build.buildfarm.v1test.QueueEntry) RequestMetadata(build.bazel.remote.execution.v2.RequestMetadata) ActionResult(build.bazel.remote.execution.v2.ActionResult) Poller(build.buildfarm.common.Poller) Test(org.junit.Test)

Example 72 with Digest

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

the class ShardInstanceTest method queueWithFailedCacheCheckContinues.

@Test
public void queueWithFailedCacheCheckContinues() throws Exception {
    Action action = createAction();
    ActionKey actionKey = DIGEST_UTIL.computeActionKey(action);
    ExecuteEntry executeEntry = ExecuteEntry.newBuilder().setOperationName("operation-with-erroring-action-result").setActionDigest(actionKey.getDigest()).build();
    when(mockBackplane.propertiesEligibleForQueue(Matchers.anyList())).thenReturn(true);
    when(mockBackplane.canQueue()).thenReturn(true);
    when(mockBackplane.getActionResult(eq(actionKey))).thenThrow(new IOException(Status.UNAVAILABLE.asException()));
    doAnswer(answer((digest, uuid) -> new NullWrite())).when(mockWorkerInstance).getBlobWrite(any(Digest.class), any(UUID.class), any(RequestMetadata.class));
    Poller poller = mock(Poller.class);
    instance.queue(executeEntry, poller, DEFAULT_TIMEOUT).get(QUEUE_TEST_TIMEOUT_SECONDS, SECONDS);
    verify(mockBackplane, times(1)).queue(any(QueueEntry.class), any(Operation.class));
    verify(mockBackplane, times(1)).putOperation(any(Operation.class), eq(CACHE_CHECK));
    verify(poller, atLeastOnce()).pause();
}
Also used : ExecuteOperationMetadata(build.bazel.remote.execution.v2.ExecuteOperationMetadata) AsyncCache(com.github.benmanes.caffeine.cache.AsyncCache) ArgumentMatchers.argThat(org.mockito.ArgumentMatchers.argThat) DirectoryNode(build.bazel.remote.execution.v2.DirectoryNode) ExecuteEntry(build.buildfarm.v1test.ExecuteEntry) RequestMetadata(build.bazel.remote.execution.v2.RequestMetadata) Actions.invalidActionVerboseMessage(build.buildfarm.common.Actions.invalidActionVerboseMessage) ActionKey(build.buildfarm.common.DigestUtil.ActionKey) Durations(com.google.protobuf.util.Durations) MISSING_ACTION(build.buildfarm.instance.server.AbstractServerInstance.MISSING_ACTION) ArgumentMatcher(org.mockito.ArgumentMatcher) MockitoAnnotations(org.mockito.MockitoAnnotations) StreamObserver(io.grpc.stub.StreamObserver) StatusProto(io.grpc.protobuf.StatusProto) Digest(build.bazel.remote.execution.v2.Digest) Mockito.doAnswer(org.mockito.Mockito.doAnswer) After(org.junit.After) COMPLETED(build.bazel.remote.execution.v2.ExecutionStage.Value.COMPLETED) Status(io.grpc.Status) INVALID_PLATFORM(build.buildfarm.instance.server.AbstractServerInstance.INVALID_PLATFORM) ServerCallStreamObserver(io.grpc.stub.ServerCallStreamObserver) ImmutableSet(com.google.common.collect.ImmutableSet) Mockito.atLeastOnce(org.mockito.Mockito.atLeastOnce) Set(java.util.Set) Executors.newSingleThreadExecutor(java.util.concurrent.Executors.newSingleThreadExecutor) OutputFile(build.bazel.remote.execution.v2.OutputFile) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) Instance(build.buildfarm.instance.Instance) Sets(com.google.common.collect.Sets) CacheLoader(com.google.common.cache.CacheLoader) ByteString(com.google.protobuf.ByteString) List(java.util.List) VIOLATION_TYPE_MISSING(build.buildfarm.common.Errors.VIOLATION_TYPE_MISSING) HashFunction(build.buildfarm.common.DigestUtil.HashFunction) QueueEntry(build.buildfarm.v1test.QueueEntry) Any(com.google.protobuf.Any) CacheBuilder(com.google.common.cache.CacheBuilder) CACHE_CHECK(build.bazel.remote.execution.v2.ExecutionStage.Value.CACHE_CHECK) Mockito.any(org.mockito.Mockito.any) Mockito.eq(org.mockito.Mockito.eq) Mockito.mock(org.mockito.Mockito.mock) Directory(build.bazel.remote.execution.v2.Directory) MoreExecutors.listeningDecorator(com.google.common.util.concurrent.MoreExecutors.listeningDecorator) Iterables(com.google.common.collect.Iterables) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) Command(build.bazel.remote.execution.v2.Command) ToolDetails(build.bazel.remote.execution.v2.ToolDetails) Matchers(org.mockito.Matchers) Mock(org.mockito.Mock) MoreExecutors.newDirectExecutorService(com.google.common.util.concurrent.MoreExecutors.newDirectExecutorService) RunWith(org.junit.runner.RunWith) MISSING_COMMAND(build.buildfarm.instance.server.AbstractServerInstance.MISSING_COMMAND) CompletableFuture(java.util.concurrent.CompletableFuture) QueuedOperation(build.buildfarm.v1test.QueuedOperation) ResultsCachePolicy(build.bazel.remote.execution.v2.ResultsCachePolicy) Operation(com.google.longrunning.Operation) Function(java.util.function.Function) DigestUtil(build.buildfarm.common.DigestUtil) QUEUED(build.bazel.remote.execution.v2.ExecutionStage.Value.QUEUED) Answer(org.mockito.stubbing.Answer) Action(build.bazel.remote.execution.v2.Action) NullWrite(build.buildfarm.common.Write.NullWrite) ArgumentCaptor(org.mockito.ArgumentCaptor) ImmutableList(com.google.common.collect.ImmutableList) Watcher(build.buildfarm.common.Watcher) VIOLATION_TYPE_INVALID(build.buildfarm.common.Errors.VIOLATION_TYPE_INVALID) ActionResult(build.bazel.remote.execution.v2.ActionResult) AdditionalAnswers.answer(org.mockito.AdditionalAnswers.answer) StreamSupport(java.util.stream.StreamSupport) Code(com.google.rpc.Code) Before(org.junit.Before) Backplane(build.buildfarm.backplane.Backplane) Violation(com.google.rpc.PreconditionFailure.Violation) Futures.immediateFuture(com.google.common.util.concurrent.Futures.immediateFuture) Caffeine(com.github.benmanes.caffeine.cache.Caffeine) ExecutionPolicy(build.bazel.remote.execution.v2.ExecutionPolicy) Poller(build.buildfarm.common.Poller) PreconditionFailure(com.google.rpc.PreconditionFailure) 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) Mockito.verify(org.mockito.Mockito.verify) StatusRuntimeException(io.grpc.StatusRuntimeException) ExecutionException(java.util.concurrent.ExecutionException) Mockito.never(org.mockito.Mockito.never) Duration(com.google.protobuf.Duration) ExecuteResponse(build.bazel.remote.execution.v2.ExecuteResponse) SECONDS(java.util.concurrent.TimeUnit.SECONDS) CompletedOperationMetadata(build.buildfarm.v1test.CompletedOperationMetadata) Action(build.bazel.remote.execution.v2.Action) Digest(build.bazel.remote.execution.v2.Digest) ExecuteEntry(build.buildfarm.v1test.ExecuteEntry) NullWrite(build.buildfarm.common.Write.NullWrite) ActionKey(build.buildfarm.common.DigestUtil.ActionKey) IOException(java.io.IOException) QueuedOperation(build.buildfarm.v1test.QueuedOperation) Operation(com.google.longrunning.Operation) UUID(java.util.UUID) QueueEntry(build.buildfarm.v1test.QueueEntry) Poller(build.buildfarm.common.Poller) RequestMetadata(build.bazel.remote.execution.v2.RequestMetadata) Test(org.junit.Test)

Example 73 with Digest

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

the class ShardInstanceTest method queueActionFailsQueueEligibility.

@Test
public void queueActionFailsQueueEligibility() throws Exception {
    Directory inputRoot = Directory.newBuilder().build();
    ByteString inputRootContent = inputRoot.toByteString();
    Digest inputRootDigest = DIGEST_UTIL.compute(inputRootContent);
    provideBlob(inputRootDigest, inputRootContent);
    Action action = createAction(true, true, inputRootDigest, SIMPLE_COMMAND);
    Digest actionDigest = DIGEST_UTIL.compute(action);
    ExecuteEntry executeEntry = ExecuteEntry.newBuilder().setOperationName("missing-directory-operation").setActionDigest(actionDigest).setSkipCacheLookup(true).build();
    when(mockBackplane.propertiesEligibleForQueue(Matchers.anyList())).thenReturn(false);
    when(mockBackplane.canQueue()).thenReturn(true);
    Poller poller = mock(Poller.class);
    boolean failedPreconditionExceptionCaught = false;
    try {
        instance.queue(executeEntry, poller, DEFAULT_TIMEOUT).get(QUEUE_TEST_TIMEOUT_SECONDS, SECONDS);
    } catch (ExecutionException e) {
        com.google.rpc.Status status = StatusProto.fromThrowable(e);
        if (status.getCode() == Code.FAILED_PRECONDITION.getNumber()) {
            failedPreconditionExceptionCaught = true;
        } else {
            e.getCause().printStackTrace();
        }
    }
    assertThat(failedPreconditionExceptionCaught).isTrue();
    PreconditionFailure preconditionFailure = PreconditionFailure.newBuilder().addViolations(Violation.newBuilder().setType(VIOLATION_TYPE_INVALID).setSubject(INVALID_PLATFORM).setDescription("properties are not valid for queue eligibility: []")).build();
    ExecuteResponse executeResponse = ExecuteResponse.newBuilder().setStatus(com.google.rpc.Status.newBuilder().setCode(Code.FAILED_PRECONDITION.getNumber()).setMessage(invalidActionVerboseMessage(actionDigest, preconditionFailure)).addDetails(Any.pack(preconditionFailure))).build();
    assertResponse(executeResponse);
    verify(poller, atLeastOnce()).pause();
}
Also used : Status(io.grpc.Status) Action(build.bazel.remote.execution.v2.Action) PreconditionFailure(com.google.rpc.PreconditionFailure) Digest(build.bazel.remote.execution.v2.Digest) ByteString(com.google.protobuf.ByteString) ExecuteEntry(build.buildfarm.v1test.ExecuteEntry) ExecuteResponse(build.bazel.remote.execution.v2.ExecuteResponse) ExecutionException(java.util.concurrent.ExecutionException) Poller(build.buildfarm.common.Poller) Directory(build.bazel.remote.execution.v2.Directory) Test(org.junit.Test)

Example 74 with Digest

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

the class UtilTest method correctMissingBlobChecksAllWorkers.

@Test
public void correctMissingBlobChecksAllWorkers() throws Exception {
    String worker1Name = "worker1";
    String worker2Name = "worker2";
    String worker3Name = "worker3";
    Set<String> workerSet = ImmutableSet.of(worker1Name, worker2Name, worker3Name);
    Digest digest = Digest.newBuilder().setHash("digest").setSizeBytes(1).build();
    ImmutableList<Digest> digests = ImmutableList.of(digest);
    Instance foundInstance = mock(Instance.class);
    when(foundInstance.findMissingBlobs(eq(digests), any(RequestMetadata.class))).thenReturn(immediateFuture(ImmutableList.of()));
    Instance missingInstance = mock(Instance.class);
    when(missingInstance.findMissingBlobs(eq(digests), any(RequestMetadata.class))).thenReturn(immediateFuture(ImmutableList.of(digest)));
    Backplane backplane = mock(Backplane.class);
    Function<String, Instance> workerInstanceFactory = worker -> {
        if (worker.equals(worker1Name)) {
            return missingInstance;
        }
        if (worker.equals(worker2Name) || worker.equals(worker3Name)) {
            return foundInstance;
        }
        return null;
    };
    ListenableFuture<Set<String>> correctFuture = correctMissingBlob(backplane, workerSet, /* originalLocationSet=*/
    ImmutableSet.of(), workerInstanceFactory, digest, directExecutor(), RequestMetadata.getDefaultInstance());
    assertThat(correctFuture.get()).isEqualTo(ImmutableSet.of(worker2Name, worker3Name));
    verify(foundInstance, times(2)).findMissingBlobs(eq(digests), any(RequestMetadata.class));
    verify(missingInstance, times(1)).findMissingBlobs(eq(digests), any(RequestMetadata.class));
    verify(backplane, times(1)).adjustBlobLocations(eq(digest), eq(ImmutableSet.of(worker2Name, worker3Name)), 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 75 with Digest

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

the class UtilTest method correctMissingBlobIgnoresBackplaneException.

@Test
public void correctMissingBlobIgnoresBackplaneException() throws Exception {
    String workerName = "worker";
    Set<String> workerSet = ImmutableSet.of(workerName);
    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(immediateFailedFuture(Status.UNKNOWN.asRuntimeException())).thenReturn(immediateFuture(ImmutableList.of()));
    Backplane backplane = mock(Backplane.class);
    doThrow(new IOException("failed to adjustBlobLocations")).when(backplane).adjustBlobLocations(eq(digest), eq(ImmutableSet.of(workerName)), eq(ImmutableSet.of()));
    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());
    assertThat(correctFuture.get()).isEqualTo(ImmutableSet.of(workerName));
    verify(instance, times(2)).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) IOException(java.io.IOException) RequestMetadata(build.bazel.remote.execution.v2.RequestMetadata) 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