Search in sources :

Example 16 with PreconditionFailure

use of com.google.rpc.PreconditionFailure in project bazel-buildfarm by bazelbuild.

the class ShardInstanceTest method queueCommandMissingErrorsOperation.

@Test
public void queueCommandMissingErrorsOperation() throws Exception {
    Action action = createAction(true, false);
    Digest actionDigest = DIGEST_UTIL.compute(action);
    ExecuteEntry executeEntry = ExecuteEntry.newBuilder().setOperationName("missing-command-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(action.getCommandDigest())).setDescription(MISSING_COMMAND)).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 17 with PreconditionFailure

use of com.google.rpc.PreconditionFailure in project bazel-buildfarm by bazelbuild.

the class MemoryInstanceTest method actionWithExcessiveTimeoutFailsValidation.

@Test
public void actionWithExcessiveTimeoutFailsValidation() throws InterruptedException, InvalidProtocolBufferException {
    Duration timeout = Durations.fromSeconds(9000);
    Digest actionDigestWithExcessiveTimeout = createAction(Action.newBuilder().setTimeout(timeout));
    Watcher watcher = mock(Watcher.class);
    instance.execute(actionDigestWithExcessiveTimeout, /* skipCacheLookup=*/
    true, ExecutionPolicy.getDefaultInstance(), ResultsCachePolicy.getDefaultInstance(), RequestMetadata.getDefaultInstance(), watcher);
    ArgumentCaptor<Operation> watchCaptor = ArgumentCaptor.forClass(Operation.class);
    verify(watcher, times(1)).observe(watchCaptor.capture());
    Operation watchOperation = watchCaptor.getValue();
    assertThat(watchOperation.getResponse().is(ExecuteResponse.class)).isTrue();
    Status status = watchOperation.getResponse().unpack(ExecuteResponse.class).getStatus();
    assertThat(status.getCode()).isEqualTo(Code.FAILED_PRECONDITION.getNumber());
    assertThat(status.getDetailsCount()).isEqualTo(1);
    assertThat(status.getDetails(0).is(PreconditionFailure.class)).isTrue();
    PreconditionFailure preconditionFailure = status.getDetails(0).unpack(PreconditionFailure.class);
    assertThat(preconditionFailure.getViolationsList()).contains(Violation.newBuilder().setType(VIOLATION_TYPE_INVALID).setSubject(Durations.toString(timeout) + " > " + Durations.toString(MAXIMUM_ACTION_TIMEOUT)).setDescription(TIMEOUT_OUT_OF_BOUNDS).build());
}
Also used : Status(com.google.rpc.Status) PreconditionFailure(com.google.rpc.PreconditionFailure) Digest(build.bazel.remote.execution.v2.Digest) Watcher(build.buildfarm.common.Watcher) Duration(com.google.protobuf.Duration) ExecuteResponse(build.bazel.remote.execution.v2.ExecuteResponse) Operation(com.google.longrunning.Operation) Test(org.junit.Test)

Example 18 with PreconditionFailure

use of com.google.rpc.PreconditionFailure in project bazel-buildfarm by bazelbuild.

the class AbstractServerInstanceTest method outputFilesAsOutputDirectoryAncestorsAreInvalid.

@Test
public void outputFilesAsOutputDirectoryAncestorsAreInvalid() {
    PreconditionFailure.Builder preconditionFailureBuilder = PreconditionFailure.newBuilder();
    AbstractServerInstance.validateOutputs(ImmutableSet.of(), ImmutableSet.of(), ImmutableSet.of("foo"), ImmutableSet.of("foo/bar"), preconditionFailureBuilder);
    PreconditionFailure preconditionFailure = preconditionFailureBuilder.build();
    assertThat(preconditionFailure.getViolationsCount()).isEqualTo(1);
    Violation violation = preconditionFailure.getViolationsList().get(0);
    assertThat(violation.getType()).isEqualTo(VIOLATION_TYPE_INVALID);
    assertThat(violation.getSubject()).isEqualTo("foo");
    assertThat(violation.getDescription()).isEqualTo(OUTPUT_FILE_IS_OUTPUT_ANCESTOR);
}
Also used : Violation(com.google.rpc.PreconditionFailure.Violation) PreconditionFailure(com.google.rpc.PreconditionFailure) Test(org.junit.Test)

Example 19 with PreconditionFailure

use of com.google.rpc.PreconditionFailure in project bazel-buildfarm by bazelbuild.

the class AbstractServerInstanceTest method unsortedFileInputIsInvalid.

@Test
public void unsortedFileInputIsInvalid() {
    PreconditionFailure.Builder preconditionFailure = PreconditionFailure.newBuilder();
    AbstractServerInstance.validateActionInputDirectory(ACTION_INPUT_ROOT_DIRECTORY_PATH, Directory.newBuilder().addAllFiles(ImmutableList.of(FileNode.newBuilder().setName("foo").build(), FileNode.newBuilder().setName("bar").build())).build(), /* pathDigests=*/
    new Stack<>(), /* visited=*/
    Sets.newHashSet(), /* directoriesIndex=*/
    Maps.newHashMap(), /* onInputFiles=*/
    file -> {
    }, /* onInputDirectories=*/
    directory -> {
    }, /* onInputDigests=*/
    digest -> {
    }, preconditionFailure);
    assertThat(preconditionFailure.getViolationsCount()).isEqualTo(1);
    Violation violation = preconditionFailure.getViolationsList().get(0);
    assertThat(violation.getType()).isEqualTo(VIOLATION_TYPE_INVALID);
    assertThat(violation.getSubject()).isEqualTo("/: foo > bar");
    assertThat(violation.getDescription()).isEqualTo(DIRECTORY_NOT_SORTED);
}
Also used : Violation(com.google.rpc.PreconditionFailure.Violation) PreconditionFailure(com.google.rpc.PreconditionFailure) Test(org.junit.Test)

Example 20 with PreconditionFailure

use of com.google.rpc.PreconditionFailure in project bazel-buildfarm by bazelbuild.

the class AbstractServerInstanceTest method emptyArgumentListIsInvalid.

@Test
public void emptyArgumentListIsInvalid() {
    AbstractServerInstance instance = new DummyServerInstance();
    PreconditionFailure.Builder preconditionFailureBuilder = PreconditionFailure.newBuilder();
    instance.validateCommand(Command.getDefaultInstance(), DIGEST_UTIL.empty(), ImmutableSet.of(), ImmutableSet.of(), ImmutableMap.of(), preconditionFailureBuilder);
    PreconditionFailure preconditionFailure = preconditionFailureBuilder.build();
    assertThat(preconditionFailure.getViolationsCount()).isEqualTo(1);
    Violation violation = preconditionFailure.getViolationsList().get(0);
    assertThat(violation.getType()).isEqualTo(VIOLATION_TYPE_INVALID);
    assertThat(violation.getSubject()).isEqualTo(INVALID_COMMAND);
    assertThat(violation.getDescription()).isEqualTo("argument list is empty");
}
Also used : Violation(com.google.rpc.PreconditionFailure.Violation) PreconditionFailure(com.google.rpc.PreconditionFailure) Test(org.junit.Test)

Aggregations

PreconditionFailure (com.google.rpc.PreconditionFailure)26 Test (org.junit.Test)18 Digest (build.bazel.remote.execution.v2.Digest)13 Violation (com.google.rpc.PreconditionFailure.Violation)12 ExecuteResponse (build.bazel.remote.execution.v2.ExecuteResponse)10 ByteString (com.google.protobuf.ByteString)9 Action (build.bazel.remote.execution.v2.Action)8 Directory (build.bazel.remote.execution.v2.Directory)6 Actions.checkPreconditionFailure (build.buildfarm.common.Actions.checkPreconditionFailure)6 Poller (build.buildfarm.common.Poller)6 ExecuteEntry (build.buildfarm.v1test.ExecuteEntry)6 Operation (com.google.longrunning.Operation)6 Status (io.grpc.Status)6 ExecutionException (java.util.concurrent.ExecutionException)6 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)5 ExecuteOperationMetadata (build.bazel.remote.execution.v2.ExecuteOperationMetadata)4 Watcher (build.buildfarm.common.Watcher)4 Any (com.google.protobuf.Any)4 QueueEntry (build.buildfarm.v1test.QueueEntry)3 QueuedOperation (build.buildfarm.v1test.QueuedOperation)3