use of com.google.cloud.kms.v1.Digest in project bazel-buildfarm by bazelbuild.
the class ShardInstanceTest method createAction.
private Action createAction(boolean provideAction, boolean provideCommand, Command command) throws Exception {
Directory inputRoot = Directory.getDefaultInstance();
ByteString inputRootBlob = inputRoot.toByteString();
Digest inputRootDigest = DIGEST_UTIL.compute(inputRootBlob);
provideBlob(inputRootDigest, inputRootBlob);
return createAction(provideAction, provideCommand, inputRootDigest, command);
}
use of com.google.cloud.kms.v1.Digest in project bazel-buildfarm by bazelbuild.
the class ShardInstanceTest method createAction.
@SuppressWarnings("unchecked")
private Action createAction(boolean provideAction, boolean provideCommand, Digest inputRootDigest, Command command) throws Exception {
String workerName = "worker";
when(mockInstanceLoader.load(eq(workerName))).thenReturn(mockWorkerInstance);
ImmutableSet<String> workers = ImmutableSet.of(workerName);
when(mockBackplane.getWorkers()).thenReturn(workers);
ByteString commandBlob = command.toByteString();
Digest commandDigest = DIGEST_UTIL.compute(commandBlob);
if (provideCommand) {
provideBlob(commandDigest, commandBlob);
when(mockBackplane.getBlobLocationSet(eq(commandDigest))).thenReturn(workers);
}
doAnswer((Answer<ListenableFuture<Iterable<Digest>>>) invocation -> {
Iterable<Digest> digests = (Iterable<Digest>) invocation.getArguments()[0];
return immediateFuture(StreamSupport.stream(digests.spliterator(), false).filter((digest) -> !blobDigests.contains(digest)).collect(Collectors.toList()));
}).when(mockWorkerInstance).findMissingBlobs(any(Iterable.class), any(RequestMetadata.class));
Action action = Action.newBuilder().setCommandDigest(commandDigest).setInputRootDigest(inputRootDigest).build();
ByteString actionBlob = action.toByteString();
Digest actionDigest = DIGEST_UTIL.compute(actionBlob);
if (provideAction) {
provideBlob(actionDigest, actionBlob);
}
doAnswer((Answer<Void>) invocation -> {
StreamObserver<ByteString> blobObserver = (StreamObserver) invocation.getArguments()[3];
if (provideAction) {
blobObserver.onNext(action.toByteString());
blobObserver.onCompleted();
} else {
blobObserver.onError(Status.NOT_FOUND.asException());
}
return null;
}).when(mockWorkerInstance).getBlob(eq(actionDigest), eq(0L), eq(actionDigest.getSizeBytes()), any(ServerCallStreamObserver.class), any(RequestMetadata.class));
when(mockBackplane.getBlobLocationSet(eq(actionDigest))).thenReturn(provideAction ? workers : ImmutableSet.of());
when(mockWorkerInstance.findMissingBlobs(eq(ImmutableList.of(actionDigest)), any(RequestMetadata.class))).thenReturn(immediateFuture(ImmutableList.of()));
return action;
}
use of com.google.cloud.kms.v1.Digest 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();
}
use of com.google.cloud.kms.v1.Digest 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();
}
use of com.google.cloud.kms.v1.Digest in project bazel-buildfarm by bazelbuild.
the class ShardInstanceTest method requeueSucceedsForValidOperation.
@Test
public void requeueSucceedsForValidOperation() throws Exception {
String operationName = "valid-operation";
when(mockBackplane.getOperation(eq(operationName))).thenReturn(Operation.newBuilder().setName(operationName).build());
Action action = createAction();
QueuedOperation queuedOperation = QueuedOperation.newBuilder().setAction(action).setCommand(SIMPLE_COMMAND).build();
ByteString queuedOperationBlob = queuedOperation.toByteString();
Digest queuedOperationDigest = DIGEST_UTIL.compute(queuedOperationBlob);
provideBlob(queuedOperationDigest, queuedOperationBlob);
Digest actionDigest = DIGEST_UTIL.compute(action);
QueueEntry queueEntry = QueueEntry.newBuilder().setExecuteEntry(ExecuteEntry.newBuilder().setOperationName(operationName).setSkipCacheLookup(true).setActionDigest(actionDigest)).setQueuedOperationDigest(queuedOperationDigest).build();
instance.requeueOperation(queueEntry, Durations.fromSeconds(60)).get();
}
Aggregations