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();
}
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());
}
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);
}
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);
}
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");
}
Aggregations