Search in sources :

Example 86 with Digest

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()));
}
Also used : Digest(build.bazel.remote.execution.v2.Digest) ByteString(com.google.protobuf.ByteString) Channel(io.grpc.Channel) ByteStreamBlockingStub(com.google.bytestream.ByteStreamGrpc.ByteStreamBlockingStub) QueryWriteStatusResponse(com.google.bytestream.ByteStreamProto.QueryWriteStatusResponse) ByteString(com.google.protobuf.ByteString) Test(org.junit.Test)

Example 87 with Digest

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));
}
Also used : Digest(build.bazel.remote.execution.v2.Digest) ByteString(com.google.protobuf.ByteString) ByteStreamStub(com.google.bytestream.ByteStreamGrpc.ByteStreamStub) Channel(io.grpc.Channel) OutputStream(java.io.OutputStream) ReadResponse(com.google.bytestream.ByteStreamProto.ReadResponse) ReadRequest(com.google.bytestream.ByteStreamProto.ReadRequest) Test(org.junit.Test)

Example 88 with Digest

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);
}
Also used : HashCode(com.google.common.hash.HashCode) Digest(build.bazel.remote.execution.v2.Digest) ByteString(com.google.protobuf.ByteString) WriteRequest(com.google.bytestream.ByteStreamProto.WriteRequest) ByteString(com.google.protobuf.ByteString) DigestUtil(build.buildfarm.common.DigestUtil) UUID(java.util.UUID) Test(org.junit.Test)

Example 89 with Digest

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);
}
Also used : Violation(com.google.rpc.PreconditionFailure.Violation) PreconditionFailure(com.google.rpc.PreconditionFailure) OperationsGrpc(com.google.longrunning.OperationsGrpc) ByteStreamGrpc(com.google.bytestream.ByteStreamGrpc) OperationQueueGrpc(build.buildfarm.v1test.OperationQueueGrpc) ExecutionGrpc(build.bazel.remote.execution.v2.ExecutionGrpc) ActionCacheGrpc(build.bazel.remote.execution.v2.ActionCacheGrpc) ContentAddressableStorageGrpc(build.bazel.remote.execution.v2.ContentAddressableStorageGrpc) Digest(build.bazel.remote.execution.v2.Digest) ExecuteOperationMetadata(build.bazel.remote.execution.v2.ExecuteOperationMetadata) ExecuteResponse(build.bazel.remote.execution.v2.ExecuteResponse) Operation(com.google.longrunning.Operation) Test(org.junit.Test)

Example 90 with Digest

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);
}
Also used : Digest(build.bazel.remote.execution.v2.Digest) ByteString(com.google.protobuf.ByteString) Operation(com.google.longrunning.Operation) MatchListener(build.buildfarm.instance.MatchListener) QueueEntry(build.buildfarm.v1test.QueueEntry) Test(org.junit.Test)

Aggregations

Digest (build.bazel.remote.execution.v2.Digest)191 ByteString (com.google.protobuf.ByteString)110 Test (org.junit.Test)99 IOException (java.io.IOException)55 Directory (build.bazel.remote.execution.v2.Directory)42 ImmutableList (com.google.common.collect.ImmutableList)35 Path (java.nio.file.Path)33 Status (io.grpc.Status)30 ExecutionException (java.util.concurrent.ExecutionException)29 RequestMetadata (build.bazel.remote.execution.v2.RequestMetadata)27 InputStream (java.io.InputStream)25 Instance (build.buildfarm.instance.Instance)24 Action (build.bazel.remote.execution.v2.Action)22 DigestUtil (build.buildfarm.common.DigestUtil)22 OutputStream (java.io.OutputStream)22 Write (build.buildfarm.common.Write)21 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)21 Operation (com.google.longrunning.Operation)21 UUID (java.util.UUID)20 ExecuteResponse (build.bazel.remote.execution.v2.ExecuteResponse)19