use of com.google.cloud.kms.v1.Digest in project bazel-buildfarm by bazelbuild.
the class ByteStreamServiceTest method completedWriteQueryIsFound.
@Test
public void completedWriteQueryIsFound() throws IOException, InterruptedException {
ByteString helloWorld = ByteString.copyFromUtf8("Hello, World!");
Digest digest = DIGEST_UTIL.compute(helloWorld);
String uuid = UUID.randomUUID().toString();
String resourceName = createBlobUploadResourceName(uuid, digest);
when(simpleBlobStore.containsKey(digest.getHash())).thenReturn(true);
Channel channel = InProcessChannelBuilder.forName(fakeServerName).directExecutor().build();
ByteStreamBlockingStub service = ByteStreamGrpc.newBlockingStub(channel);
QueryWriteStatusResponse response = service.queryWriteStatus(QueryWriteStatusRequest.newBuilder().setResourceName(resourceName).build());
assertThat(response).isEqualTo(QueryWriteStatusResponse.newBuilder().setCommittedSize(digest.getSizeBytes()).setComplete(true).build());
verify(simpleBlobStore, times(1)).containsKey(eq(digest.getHash()));
}
use of com.google.cloud.kms.v1.Digest in project bazel-buildfarm by bazelbuild.
the class ByteStreamServiceTest method skippedInputIsNotInResponse.
@Test
public void skippedInputIsNotInResponse() throws ExecutionException, IOException, InterruptedException {
ByteString helloWorld = ByteString.copyFromUtf8("Hello, World!");
Digest digest = DIGEST_UTIL.compute(helloWorld);
Channel channel = InProcessChannelBuilder.forName(fakeServerName).directExecutor().build();
ByteStreamStub service = ByteStreamGrpc.newStub(channel);
SettableFuture<Boolean> getComplete = SettableFuture.create();
when(simpleBlobStore.get(eq(digest.getHash()), any(OutputStream.class))).thenReturn(getComplete);
ArgumentCaptor<OutputStream> outputStreamCaptor = ArgumentCaptor.forClass(OutputStream.class);
ReadRequest request = ReadRequest.newBuilder().setResourceName(createBlobDownloadResourceName(digest)).setReadOffset(6).build();
SettableFuture<ByteString> readComplete = SettableFuture.create();
service.read(request, new StreamObserver<ReadResponse>() {
ByteString content = ByteString.EMPTY;
@Override
public void onNext(ReadResponse response) {
content = content.concat(response.getData());
}
@Override
public void onError(Throwable t) {
readComplete.setException(t);
}
@Override
public void onCompleted() {
readComplete.set(content);
}
});
verify(simpleBlobStore, times(1)).get(eq(digest.getHash()), outputStreamCaptor.capture());
try (OutputStream outputStream = outputStreamCaptor.getValue()) {
outputStream.write(helloWorld.toByteArray());
getComplete.set(true);
}
assertThat(readComplete.get()).isEqualTo(helloWorld.substring(6));
}
use of com.google.cloud.kms.v1.Digest in project bazel-buildfarm by bazelbuild.
the class BuildFarmServerTest method progressiveUploadCompletes.
@Test
public void progressiveUploadCompletes() throws Exception {
DigestUtil digestUtil = new DigestUtil(HashFunction.SHA256);
ByteString content = ByteString.copyFromUtf8("Hello, World!");
Digest digest = digestUtil.compute(content);
HashCode hash = HashCode.fromString(digest.getHash());
UUID uuid = UUID.randomUUID();
String resourceName = ByteStreamUploader.uploadResourceName(INSTANCE_NAME, uuid, hash, content.size());
assertThat(getBlob(digest)).isNull();
FutureWriteResponseObserver futureResponder = new FutureWriteResponseObserver();
StreamObserver<WriteRequest> requestObserver = ByteStreamGrpc.newStub(inProcessChannel).write(futureResponder);
ByteString shortContent = content.substring(0, 6);
requestObserver.onNext(WriteRequest.newBuilder().setWriteOffset(0).setResourceName(resourceName).setData(shortContent).build());
requestObserver.onError(Status.CANCELLED.asException());
// should be done
assertThat(futureResponder.isDone()).isTrue();
futureResponder = new FutureWriteResponseObserver();
requestObserver = ByteStreamGrpc.newStub(inProcessChannel).write(futureResponder);
requestObserver.onNext(WriteRequest.newBuilder().setWriteOffset(6).setResourceName(resourceName).setData(content.substring(6)).setFinishWrite(true).build());
requestObserver.onCompleted();
assertThat(futureResponder.get()).isEqualTo(WriteResponse.newBuilder().setCommittedSize(content.size()).build());
assertThat(getBlob(digest)).isEqualTo(content);
}
use of com.google.cloud.kms.v1.Digest in project bazel-buildfarm by bazelbuild.
the class BuildFarmServerTest method actionWithExcessiveTimeoutFailsValidation.
@Test
public void actionWithExcessiveTimeoutFailsValidation() throws IOException, InterruptedException {
Digest actionDigestWithExcessiveTimeout = createAction(Action.newBuilder().setTimeout(Duration.newBuilder().setSeconds(9000)));
Operation failedOperation = executeAction(actionDigestWithExcessiveTimeout);
assertThat(failedOperation.getDone()).isTrue();
assertThat(failedOperation.getMetadata().unpack(ExecuteOperationMetadata.class).getStage()).isEqualTo(COMPLETED);
ExecuteResponse executeResponse = failedOperation.getResponse().unpack(ExecuteResponse.class);
com.google.rpc.Status status = executeResponse.getStatus();
assertThat(status.getCode()).isEqualTo(Code.FAILED_PRECONDITION.getNumber());
assertThat(status.getDetailsCount()).isEqualTo(1);
PreconditionFailure preconditionFailure = status.getDetailsList().get(0).unpack(PreconditionFailure.class);
assertThat(preconditionFailure.getViolationsCount()).isEqualTo(1);
Violation violation = preconditionFailure.getViolationsList().get(0);
assertThat(violation.getType()).isEqualTo(VIOLATION_TYPE_INVALID);
}
use of com.google.cloud.kms.v1.Digest in project bazel-buildfarm by bazelbuild.
the class MemoryInstanceTest method requeueRemovesRequeuers.
@Test
public void requeueRemovesRequeuers() throws InterruptedException {
Digest actionDigest = createAction(Action.newBuilder());
instance.execute(actionDigest, /* skipCacheLookup=*/
true, ExecutionPolicy.getDefaultInstance(), ResultsCachePolicy.getDefaultInstance(), RequestMetadata.getDefaultInstance(), (operation) -> {
});
MatchListener listener = mock(MatchListener.class);
when(listener.onEntry(any(QueueEntry.class))).thenReturn(true);
instance.match(Platform.getDefaultInstance(), listener);
ArgumentCaptor<QueueEntry> queueEntryCaptor = ArgumentCaptor.forClass(QueueEntry.class);
verify(listener, times(1)).onEntry(queueEntryCaptor.capture());
QueueEntry queueEntry = queueEntryCaptor.getValue();
assertThat(queueEntry).isNotNull();
String operationName = queueEntry.getExecuteEntry().getOperationName();
assertThat(requeuers).isNotEmpty();
Operation queuedOperation = outstandingOperations.get(operationName);
assertThat(AbstractServerInstance.isQueued(queuedOperation)).isTrue();
// requeue
instance.putOperation(queuedOperation);
assertThat(requeuers).isEmpty();
assertThat(outstandingOperations.get(operationName)).isEqualTo(queuedOperation);
}
Aggregations