Search in sources :

Example 1 with ExecuteResponse

use of build.bazel.remote.execution.v2.ExecuteResponse in project bazel-buildfarm by bazelbuild.

the class MemoryInstanceTest method requeueFailureNotifiesWatchers.

@Test
public void requeueFailureNotifiesWatchers() throws Exception {
    ExecuteOperationMetadata metadata = ExecuteOperationMetadata.newBuilder().setActionDigest(simpleActionDigest).setStage(QUEUED).build();
    Operation queuedOperation = createOperation("missing-action-operation", metadata);
    outstandingOperations.put(queuedOperation.getName(), queuedOperation);
    Watcher watcher = mock(Watcher.class);
    ListenableFuture<Void> watchFuture = instance.watchOperation(queuedOperation.getName(), watcher);
    assertThat(instance.requeueOperation(queuedOperation)).isFalse();
    watchFuture.get();
    ArgumentCaptor<Operation> operationCaptor = ArgumentCaptor.forClass(Operation.class);
    verify(watcher, atLeastOnce()).observe(operationCaptor.capture());
    List<Operation> operations = operationCaptor.getAllValues();
    Operation erroredOperation = operations.get(operations.size() - 1);
    assertThat(erroredOperation.getDone()).isTrue();
    CompletedOperationMetadata completedMetadata = erroredOperation.getMetadata().unpack(CompletedOperationMetadata.class);
    assertThat(completedMetadata.getExecuteOperationMetadata().getStage()).isEqualTo(COMPLETED);
    PreconditionFailure preconditionFailure = PreconditionFailure.newBuilder().addViolations(Violation.newBuilder().setType(VIOLATION_TYPE_MISSING).setSubject("blobs/" + DigestUtil.toString(simpleActionDigest)).setDescription(MISSING_ACTION)).build();
    ExecuteResponse executeResponse = ExecuteResponse.newBuilder().setStatus(Status.newBuilder().setCode(Code.FAILED_PRECONDITION.getNumber()).setMessage(invalidActionVerboseMessage(simpleActionDigest, preconditionFailure)).addDetails(Any.pack(preconditionFailure))).build();
    assertThat(erroredOperation.getResponse().unpack(ExecuteResponse.class)).isEqualTo(executeResponse);
}
Also used : PreconditionFailure(com.google.rpc.PreconditionFailure) ExecuteOperationMetadata(build.bazel.remote.execution.v2.ExecuteOperationMetadata) Watcher(build.buildfarm.common.Watcher) ExecuteResponse(build.bazel.remote.execution.v2.ExecuteResponse) Operation(com.google.longrunning.Operation) CompletedOperationMetadata(build.buildfarm.v1test.CompletedOperationMetadata) Test(org.junit.Test)

Example 2 with ExecuteResponse

use of build.bazel.remote.execution.v2.ExecuteResponse in project bazel-buildfarm by bazelbuild.

the class ShardInstanceTest method requeueFailsOnMissingDirectory.

@Test
public void requeueFailsOnMissingDirectory() throws Exception {
    String operationName = "missing-directory-operation";
    Digest missingDirectoryDigest = Digest.newBuilder().setHash("missing-directory").setSizeBytes(1).build();
    when(mockBackplane.propertiesEligibleForQueue(Matchers.anyList())).thenReturn(true);
    when(mockBackplane.getOperation(eq(operationName))).thenReturn(Operation.newBuilder().setName(operationName).setMetadata(Any.pack(ExecuteOperationMetadata.newBuilder().setStage(QUEUED).build())).build());
    Action action = createAction(true, true, missingDirectoryDigest, SIMPLE_COMMAND);
    Digest actionDigest = DIGEST_UTIL.compute(action);
    QueueEntry queueEntry = QueueEntry.newBuilder().setExecuteEntry(ExecuteEntry.newBuilder().setOperationName(operationName).setSkipCacheLookup(true).setActionDigest(actionDigest)).build();
    instance.requeueOperation(queueEntry, Durations.fromSeconds(60)).get();
    ArgumentCaptor<Operation> operationCaptor = ArgumentCaptor.forClass(Operation.class);
    verify(mockBackplane, times(1)).putOperation(operationCaptor.capture(), eq(COMPLETED));
    Operation operation = operationCaptor.getValue();
    assertThat(operation.getResponse().is(ExecuteResponse.class)).isTrue();
    ExecuteResponse executeResponse = operation.getResponse().unpack(ExecuteResponse.class);
    com.google.rpc.Status status = executeResponse.getStatus();
    PreconditionFailure preconditionFailure = PreconditionFailure.newBuilder().addViolations(Violation.newBuilder().setType(VIOLATION_TYPE_MISSING).setSubject("blobs/" + DigestUtil.toString(missingDirectoryDigest)).setDescription("The directory `/` was not found in the CAS.")).build();
    com.google.rpc.Status expectedStatus = com.google.rpc.Status.newBuilder().setCode(Code.FAILED_PRECONDITION.getNumber()).setMessage(invalidActionVerboseMessage(actionDigest, preconditionFailure)).addDetails(Any.pack(preconditionFailure)).build();
    assertThat(status).isEqualTo(expectedStatus);
}
Also used : Action(build.bazel.remote.execution.v2.Action) PreconditionFailure(com.google.rpc.PreconditionFailure) Digest(build.bazel.remote.execution.v2.Digest) 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) Test(org.junit.Test)

Example 3 with ExecuteResponse

use of build.bazel.remote.execution.v2.ExecuteResponse in project bazel-buildfarm by bazelbuild.

the class ShardInstanceTest method queueActionMissingErrorsOperation.

@Test
public void queueActionMissingErrorsOperation() throws Exception {
    Action action = createAction(false);
    Digest actionDigest = DIGEST_UTIL.compute(action);
    ExecuteEntry executeEntry = ExecuteEntry.newBuilder().setOperationName("missing-action-operation").setActionDigest(actionDigest).setSkipCacheLookup(true).build();
    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_MISSING).setSubject("blobs/" + DigestUtil.toString(actionDigest)).setDescription(MISSING_ACTION)).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) ExecuteEntry(build.buildfarm.v1test.ExecuteEntry) ExecuteResponse(build.bazel.remote.execution.v2.ExecuteResponse) ExecutionException(java.util.concurrent.ExecutionException) Poller(build.buildfarm.common.Poller) Test(org.junit.Test)

Example 4 with ExecuteResponse

use of build.bazel.remote.execution.v2.ExecuteResponse in project bazel-buildfarm by bazelbuild.

the class ShardInstanceTest method queueDirectoryMissingErrorsOperation.

@Test
public void queueDirectoryMissingErrorsOperation() throws Exception {
    ByteString foo = ByteString.copyFromUtf8("foo");
    Digest subdirDigest = DIGEST_UTIL.compute(foo);
    Directory inputRoot = Directory.newBuilder().addDirectories(DirectoryNode.newBuilder().setName("missing-subdir").setDigest(subdirDigest)).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(true);
    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_MISSING).setSubject("blobs/" + DigestUtil.toString(subdirDigest)).setDescription("The directory `/missing-subdir` was not found in the CAS.")).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 5 with ExecuteResponse

use of build.bazel.remote.execution.v2.ExecuteResponse 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)

Aggregations

ExecuteResponse (build.bazel.remote.execution.v2.ExecuteResponse)14 Test (org.junit.Test)12 Operation (com.google.longrunning.Operation)9 Digest (build.bazel.remote.execution.v2.Digest)8 PreconditionFailure (com.google.rpc.PreconditionFailure)8 Action (build.bazel.remote.execution.v2.Action)7 ActionResult (build.bazel.remote.execution.v2.ActionResult)6 Poller (build.buildfarm.common.Poller)6 ExecuteEntry (build.buildfarm.v1test.ExecuteEntry)6 ExecuteOperationMetadata (build.bazel.remote.execution.v2.ExecuteOperationMetadata)5 Watcher (build.buildfarm.common.Watcher)5 QueuedOperation (build.buildfarm.v1test.QueuedOperation)5 Status (io.grpc.Status)5 ExecutionException (java.util.concurrent.ExecutionException)5 ActionKey (build.buildfarm.common.DigestUtil.ActionKey)4 ByteString (com.google.protobuf.ByteString)4 Directory (build.bazel.remote.execution.v2.Directory)3 CompletedOperationMetadata (build.buildfarm.v1test.CompletedOperationMetadata)3 RequestMetadata (build.bazel.remote.execution.v2.RequestMetadata)2 QueueEntry (build.buildfarm.v1test.QueueEntry)2