Search in sources :

Example 1 with ActionResult

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

the class ShardInstance method deliverCachedActionResult.

private void deliverCachedActionResult(ActionResult actionResult, ActionKey actionKey, Operation operation, RequestMetadata requestMetadata) throws Exception {
    recentCacheServedExecutions.put(requestMetadata, true);
    ExecuteOperationMetadata completeMetadata = ExecuteOperationMetadata.newBuilder().setActionDigest(actionKey.getDigest()).setStage(ExecutionStage.Value.COMPLETED).build();
    Operation completedOperation = operation.toBuilder().setDone(true).setResponse(Any.pack(ExecuteResponse.newBuilder().setResult(actionResult).setStatus(com.google.rpc.Status.newBuilder().setCode(Code.OK.value()).build()).setCachedResult(true).build())).setMetadata(Any.pack(completeMetadata)).build();
    backplane.putOperation(completedOperation, completeMetadata.getStage());
}
Also used : ExecuteOperationMetadata(build.bazel.remote.execution.v2.ExecuteOperationMetadata) QueuedOperation(build.buildfarm.v1test.QueuedOperation) Operation(com.google.longrunning.Operation)

Example 2 with ActionResult

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

the class ShardWorkerInstanceTest method putActionResultDelegatesToBackplane.

@Test
public void putActionResultDelegatesToBackplane() throws IOException {
    DigestUtil.ActionKey key = DigestUtil.asActionKey(DIGEST_UTIL.compute(ByteString.copyFromUtf8("Hello, World")));
    ActionResult result = ActionResult.getDefaultInstance();
    instance.putActionResult(key, result);
    verify(backplane, times(1)).putActionResult(key, result);
}
Also used : ActionResult(build.bazel.remote.execution.v2.ActionResult) DigestUtil(build.buildfarm.common.DigestUtil) Test(org.junit.Test)

Example 3 with ActionResult

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

the class MemoryInstanceTest method actionCacheRetrievableByActionKey.

@Test
public void actionCacheRetrievableByActionKey() throws Exception {
    ActionResult result = ActionResult.getDefaultInstance();
    storage.put(DIGEST_UTIL.compute(result).getHash(), result.toByteString());
    Action action = Action.getDefaultInstance();
    instance.putActionResult(instance.getDigestUtil().computeActionKey(action), result);
    assertThat(instance.getActionResult(instance.getDigestUtil().computeActionKey(action), RequestMetadata.getDefaultInstance()).get()).isEqualTo(result);
}
Also used : Action(build.bazel.remote.execution.v2.Action) ActionResult(build.bazel.remote.execution.v2.ActionResult) Test(org.junit.Test)

Example 4 with ActionResult

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

the class ShardInstanceTest method duplicateExecutionsServedFromCacheAreForcedToSkipLookup.

@Test
public void duplicateExecutionsServedFromCacheAreForcedToSkipLookup() throws Exception {
    ActionKey actionKey = DigestUtil.asActionKey(Digest.newBuilder().setHash("test").build());
    ActionResult actionResult = ActionResult.newBuilder().addOutputFiles(OutputFile.newBuilder().setPath("does-not-exist").setDigest(Digest.newBuilder().setHash("dne").setSizeBytes(1))).setStdoutDigest(Digest.newBuilder().setHash("stdout").setSizeBytes(1)).setStderrDigest(Digest.newBuilder().setHash("stderr").setSizeBytes(1)).build();
    when(mockBackplane.canQueue()).thenReturn(true);
    when(mockBackplane.canPrequeue()).thenReturn(true);
    when(mockBackplane.getActionResult(actionKey)).thenReturn(actionResult);
    Digest actionDigest = actionKey.getDigest();
    RequestMetadata requestMetadata = RequestMetadata.newBuilder().setToolDetails(ToolDetails.newBuilder().setToolName("buildfarm-test").setToolVersion("0.1")).setCorrelatedInvocationsId(UUID.randomUUID().toString()).setToolInvocationId(UUID.randomUUID().toString()).setActionId(actionDigest.getHash()).build();
    String operationName = "cache-served-operation";
    ExecuteEntry cacheServedExecuteEntry = ExecuteEntry.newBuilder().setOperationName(operationName).setActionDigest(actionDigest).setRequestMetadata(requestMetadata).build();
    Poller poller = mock(Poller.class);
    instance.queue(cacheServedExecuteEntry, poller, DEFAULT_TIMEOUT).get(QUEUE_TEST_TIMEOUT_SECONDS, SECONDS);
    verify(poller, times(1)).pause();
    verify(mockBackplane, never()).queue(any(QueueEntry.class), any(Operation.class));
    ArgumentCaptor<Operation> cacheCheckOperationCaptor = ArgumentCaptor.forClass(Operation.class);
    verify(mockBackplane, times(1)).putOperation(cacheCheckOperationCaptor.capture(), eq(CACHE_CHECK));
    Operation cacheCheckOperation = cacheCheckOperationCaptor.getValue();
    assertThat(cacheCheckOperation.getName()).isEqualTo(operationName);
    ArgumentCaptor<Operation> completedOperationCaptor = ArgumentCaptor.forClass(Operation.class);
    verify(mockBackplane, times(1)).putOperation(completedOperationCaptor.capture(), eq(COMPLETED));
    Operation completedOperation = completedOperationCaptor.getValue();
    assertThat(completedOperation.getName()).isEqualTo(operationName);
    ExecuteResponse executeResponse = completedOperation.getResponse().unpack(ExecuteResponse.class);
    assertThat(executeResponse.getResult()).isEqualTo(actionResult);
    assertThat(executeResponse.getCachedResult()).isTrue();
    Watcher mockWatcher = mock(Watcher.class);
    instance.execute(actionDigest, /* skipCacheLookup=*/
    false, ExecutionPolicy.getDefaultInstance(), ResultsCachePolicy.getDefaultInstance(), requestMetadata, /* watcher=*/
    mockWatcher);
    verify(mockWatcher, times(1)).observe(any(Operation.class));
    ArgumentCaptor<ExecuteEntry> executeEntryCaptor = ArgumentCaptor.forClass(ExecuteEntry.class);
    verify(mockBackplane, times(1)).prequeue(executeEntryCaptor.capture(), any(Operation.class));
    ExecuteEntry executeEntry = executeEntryCaptor.getValue();
    assertThat(executeEntry.getSkipCacheLookup()).isTrue();
}
Also used : Digest(build.bazel.remote.execution.v2.Digest) ExecuteEntry(build.buildfarm.v1test.ExecuteEntry) Watcher(build.buildfarm.common.Watcher) ActionKey(build.buildfarm.common.DigestUtil.ActionKey) ExecuteResponse(build.bazel.remote.execution.v2.ExecuteResponse) ByteString(com.google.protobuf.ByteString) QueuedOperation(build.buildfarm.v1test.QueuedOperation) Operation(com.google.longrunning.Operation) QueueEntry(build.buildfarm.v1test.QueueEntry) RequestMetadata(build.bazel.remote.execution.v2.RequestMetadata) ActionResult(build.bazel.remote.execution.v2.ActionResult) Poller(build.buildfarm.common.Poller) Test(org.junit.Test)

Example 5 with ActionResult

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

the class ShardInstanceTest method actionResultWatcherDiscardsUncacheableResult.

@Test
public void actionResultWatcherDiscardsUncacheableResult() throws Exception {
    ActionKey actionKey = DigestUtil.asActionKey(Digest.newBuilder().setHash("test").build());
    Watcher mockWatcher = mock(Watcher.class);
    Watcher actionResultWatcher = instance.newActionResultWatcher(actionKey, mockWatcher);
    Action uncacheableAction = Action.newBuilder().setDoNotCache(true).build();
    Operation operation = Operation.newBuilder().setMetadata(Any.pack(uncacheableAction)).build();
    ExecuteResponse executeResponse = ExecuteResponse.newBuilder().setCachedResult(true).build();
    Operation completedOperation = Operation.newBuilder().setDone(true).setResponse(Any.pack(executeResponse)).build();
    actionResultWatcher.observe(operation);
    actionResultWatcher.observe(completedOperation);
    verify(mockWatcher, never()).observe(operation);
    ListenableFuture<ActionResult> resultFuture = instance.getActionResult(actionKey, RequestMetadata.getDefaultInstance());
    ActionResult result = resultFuture.get();
    assertThat(result).isNull();
    verify(mockWatcher, times(1)).observe(completedOperation);
}
Also used : Action(build.bazel.remote.execution.v2.Action) ActionResult(build.bazel.remote.execution.v2.ActionResult) Watcher(build.buildfarm.common.Watcher) ActionKey(build.buildfarm.common.DigestUtil.ActionKey) ExecuteResponse(build.bazel.remote.execution.v2.ExecuteResponse) QueuedOperation(build.buildfarm.v1test.QueuedOperation) Operation(com.google.longrunning.Operation) Test(org.junit.Test)

Aggregations

ActionResult (build.bazel.remote.execution.v2.ActionResult)22 Test (org.junit.Test)15 ActionKey (build.buildfarm.common.DigestUtil.ActionKey)9 QueuedOperation (build.buildfarm.v1test.QueuedOperation)7 Operation (com.google.longrunning.Operation)7 Digest (build.bazel.remote.execution.v2.Digest)6 ActionCacheImplBase (build.bazel.remote.execution.v2.ActionCacheGrpc.ActionCacheImplBase)5 ExecuteResponse (build.bazel.remote.execution.v2.ExecuteResponse)5 Instance (build.buildfarm.instance.Instance)5 ExecuteOperationMetadata (build.bazel.remote.execution.v2.ExecuteOperationMetadata)4 UpdateActionResultRequest (build.bazel.remote.execution.v2.UpdateActionResultRequest)4 Watcher (build.buildfarm.common.Watcher)4 ByteString (com.google.protobuf.ByteString)4 Action (build.bazel.remote.execution.v2.Action)3 GetActionResultRequest (build.bazel.remote.execution.v2.GetActionResultRequest)3 RequestMetadata (build.bazel.remote.execution.v2.RequestMetadata)3 OutputDirectory (build.bazel.remote.execution.v2.OutputDirectory)2 OutputFile (build.bazel.remote.execution.v2.OutputFile)2 ActionCache (build.buildfarm.ac.ActionCache)2 Actions.asExecutionStatus (build.buildfarm.common.Actions.asExecutionStatus)2