Search in sources :

Example 1 with ActionCacheImplBase

use of build.bazel.remote.execution.v2.ActionCacheGrpc.ActionCacheImplBase 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 ActionCacheImplBase

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

the class StubInstanceTest method getActionResultReturnsNullForNotFound.

@Test
public void getActionResultReturnsNullForNotFound() throws Exception {
    AtomicReference<GetActionResultRequest> reference = new AtomicReference<>();
    serviceRegistry.addService(new ActionCacheImplBase() {

        @Override
        public void getActionResult(GetActionResultRequest request, StreamObserver<ActionResult> responseObserver) {
            reference.set(request);
            responseObserver.onError(Status.NOT_FOUND.asException());
        }
    });
    Instance instance = newStubInstance("test");
    ActionKey actionKey = DIGEST_UTIL.computeActionKey(Action.getDefaultInstance());
    assertThat(instance.getActionResult(actionKey, RequestMetadata.getDefaultInstance()).get()).isNull();
    GetActionResultRequest request = reference.get();
    assertThat(request.getInstanceName()).isEqualTo(instance.getName());
    assertThat(request.getActionDigest()).isEqualTo(actionKey.getDigest());
    instance.stop();
}
Also used : 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) GetActionResultRequest(build.bazel.remote.execution.v2.GetActionResultRequest) Test(org.junit.Test)

Example 3 with ActionCacheImplBase

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

the class GrpcActionCacheTest method getNotFoundIsNull.

@Test
public void getNotFoundIsNull() throws Exception {
    Digest actionDigest = DIGEST_UTIL.compute(ByteString.copyFromUtf8("not-found"));
    serviceRegistry.addService(new ActionCacheImplBase() {

        @Override
        public void getActionResult(GetActionResultRequest request, StreamObserver<ActionResult> responseObserver) {
            responseObserver.onError(Status.NOT_FOUND.asException());
        }
    });
    assertThat(ac.get(DigestUtil.asActionKey(actionDigest)).get()).isNull();
}
Also used : ActionResult(build.bazel.remote.execution.v2.ActionResult) Digest(build.bazel.remote.execution.v2.Digest) ActionCacheImplBase(build.bazel.remote.execution.v2.ActionCacheGrpc.ActionCacheImplBase) GetActionResultRequest(build.bazel.remote.execution.v2.GetActionResultRequest) Test(org.junit.Test)

Example 4 with ActionCacheImplBase

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

the class GrpcActionCacheTest method getSuppliesResponse.

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

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

Example 5 with ActionCacheImplBase

use of build.bazel.remote.execution.v2.ActionCacheGrpc.ActionCacheImplBase 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

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