Search in sources :

Example 1 with UpdateActionResultRequest

use of build.bazel.remote.execution.v2.UpdateActionResultRequest in project bazel-buildfarm by bazelbuild.

the class StubInstanceTest method putActionResultCallsUpdateActionResult.

@Test
public void putActionResultCallsUpdateActionResult() throws InterruptedException {
    AtomicReference<UpdateActionResultRequest> reference = new AtomicReference<>();
    serviceRegistry.addService(new ActionCacheImplBase() {

        @Override
        public void updateActionResult(UpdateActionResultRequest request, StreamObserver<ActionResult> responseObserver) {
            reference.set(request);
            responseObserver.onNext(request.getActionResult());
            responseObserver.onCompleted();
        }
    });
    String instanceName = "putActionResult-test";
    Instance instance = newStubInstance(instanceName);
    ActionKey actionKey = DigestUtil.asActionKey(Digest.newBuilder().setHash("action-digest").setSizeBytes(1).build());
    ActionResult actionResult = ActionResult.getDefaultInstance();
    instance.putActionResult(actionKey, actionResult);
    UpdateActionResultRequest request = reference.get();
    assertThat(request.getInstanceName()).isEqualTo(instanceName);
    assertThat(request.getActionDigest()).isEqualTo(actionKey.getDigest());
    assertThat(request.getActionResult()).isEqualTo(actionResult);
    instance.stop();
}
Also used : UpdateActionResultRequest(build.bazel.remote.execution.v2.UpdateActionResultRequest) ActionResult(build.bazel.remote.execution.v2.ActionResult) Instance(build.buildfarm.instance.Instance) AtomicReference(java.util.concurrent.atomic.AtomicReference) ActionCacheImplBase(build.bazel.remote.execution.v2.ActionCacheGrpc.ActionCacheImplBase) ActionKey(build.buildfarm.common.DigestUtil.ActionKey) ByteString(com.google.protobuf.ByteString) Test(org.junit.Test)

Example 2 with UpdateActionResultRequest

use of build.bazel.remote.execution.v2.UpdateActionResultRequest in project bazel-buildfarm by bazelbuild.

the class ActionCacheServiceTest method writeSucceedsWhenActionCacheIsWritable.

@Test
public void writeSucceedsWhenActionCacheIsWritable() throws Exception {
    // If the ActionCache is configured to be read and write,
    // then attempting to write to it should succeed.
    // ARRANGE
    Instance instance = mock(Instance.class);
    ActionCacheService service = new ActionCacheService(instance, ActionCacheAccessPolicy.READ_AND_WRITE);
    // ACT
    StreamObserver<ActionResult> response = mock(StreamObserver.class);
    UpdateActionResultRequest request = UpdateActionResultRequest.newBuilder().build();
    service.updateActionResult(request, response);
    // ASSERT
    verify(response, times(0)).onError(any(Throwable.class));
}
Also used : UpdateActionResultRequest(build.bazel.remote.execution.v2.UpdateActionResultRequest) ActionResult(build.bazel.remote.execution.v2.ActionResult) Instance(build.buildfarm.instance.Instance) Test(org.junit.Test)

Example 3 with UpdateActionResultRequest

use of build.bazel.remote.execution.v2.UpdateActionResultRequest in project bazel-buildfarm by bazelbuild.

the class ActionCacheService method updateActionResult.

@Override
public void updateActionResult(UpdateActionResultRequest request, StreamObserver<ActionResult> responseObserver) {
    ActionResult actionResult = request.getActionResult();
    try {
        simpleBlobStore.putActionResult(request.getActionDigest().getHash(), actionResult.toByteArray());
        responseObserver.onNext(actionResult);
        responseObserver.onCompleted();
    } catch (IOException e) {
        responseObserver.onError(Status.fromThrowable(e).asException());
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
    }
}
Also used : ActionResult(build.bazel.remote.execution.v2.ActionResult) IOException(java.io.IOException)

Example 4 with UpdateActionResultRequest

use of build.bazel.remote.execution.v2.UpdateActionResultRequest in project bazel-buildfarm by bazelbuild.

the class ActionCacheServiceTest method writeFailsWhenActionCacheIsReadOnly.

@Test
public void writeFailsWhenActionCacheIsReadOnly() throws Exception {
    // If the ActionCache is configured to be read-only,
    // then attempting to write to it should result in an error.
    // ARRANGE
    Instance instance = mock(Instance.class);
    ActionCacheService service = new ActionCacheService(instance, ActionCacheAccessPolicy.READ_ONLY);
    // ACT
    StreamObserver<ActionResult> response = mock(StreamObserver.class);
    UpdateActionResultRequest request = UpdateActionResultRequest.newBuilder().build();
    service.updateActionResult(request, response);
    // ASSERT
    verify(response, times(1)).onError(any(Throwable.class));
}
Also used : UpdateActionResultRequest(build.bazel.remote.execution.v2.UpdateActionResultRequest) ActionResult(build.bazel.remote.execution.v2.ActionResult) Instance(build.buildfarm.instance.Instance) Test(org.junit.Test)

Example 5 with UpdateActionResultRequest

use of build.bazel.remote.execution.v2.UpdateActionResultRequest in project bazel-buildfarm by bazelbuild.

the class GrpcActionCacheTest method putUpdatesResult.

@Test
public void putUpdatesResult() throws InterruptedException {
    ActionResult result = ActionResult.newBuilder().setStdoutRaw(ByteString.copyFromUtf8("out")).build();
    Digest actionDigest = DIGEST_UTIL.compute(ByteString.copyFromUtf8("in"));
    serviceRegistry.addService(new ActionCacheImplBase() {

        @Override
        public void updateActionResult(UpdateActionResultRequest request, StreamObserver<ActionResult> responseObserver) {
            if (request.getInstanceName().equals(instanceName) && request.getActionDigest().equals(actionDigest) && request.getActionResult().equals(result)) {
                responseObserver.onNext(result);
                responseObserver.onCompleted();
            } else {
                responseObserver.onError(Status.UNAVAILABLE.asException());
            }
        }
    });
    ac.put(DigestUtil.asActionKey(actionDigest), result);
}
Also used : UpdateActionResultRequest(build.bazel.remote.execution.v2.UpdateActionResultRequest) ActionResult(build.bazel.remote.execution.v2.ActionResult) Digest(build.bazel.remote.execution.v2.Digest) ActionCacheImplBase(build.bazel.remote.execution.v2.ActionCacheGrpc.ActionCacheImplBase) Test(org.junit.Test)

Aggregations

ActionResult (build.bazel.remote.execution.v2.ActionResult)6 UpdateActionResultRequest (build.bazel.remote.execution.v2.UpdateActionResultRequest)4 Test (org.junit.Test)4 Instance (build.buildfarm.instance.Instance)3 ActionCacheImplBase (build.bazel.remote.execution.v2.ActionCacheGrpc.ActionCacheImplBase)2 Digest (build.bazel.remote.execution.v2.Digest)1 ActionKey (build.buildfarm.common.DigestUtil.ActionKey)1 ByteString (com.google.protobuf.ByteString)1 IOException (java.io.IOException)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1