use of build.bazel.remote.execution.v2.ExecutionStage.Value.CACHE_CHECK 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();
}
use of build.bazel.remote.execution.v2.ExecutionStage.Value.CACHE_CHECK in project bazel-buildfarm by bazelbuild.
the class ShardInstanceTest method queueWithFailedCacheCheckContinues.
@Test
public void queueWithFailedCacheCheckContinues() throws Exception {
Action action = createAction();
ActionKey actionKey = DIGEST_UTIL.computeActionKey(action);
ExecuteEntry executeEntry = ExecuteEntry.newBuilder().setOperationName("operation-with-erroring-action-result").setActionDigest(actionKey.getDigest()).build();
when(mockBackplane.propertiesEligibleForQueue(Matchers.anyList())).thenReturn(true);
when(mockBackplane.canQueue()).thenReturn(true);
when(mockBackplane.getActionResult(eq(actionKey))).thenThrow(new IOException(Status.UNAVAILABLE.asException()));
doAnswer(answer((digest, uuid) -> new NullWrite())).when(mockWorkerInstance).getBlobWrite(any(Digest.class), any(UUID.class), any(RequestMetadata.class));
Poller poller = mock(Poller.class);
instance.queue(executeEntry, poller, DEFAULT_TIMEOUT).get(QUEUE_TEST_TIMEOUT_SECONDS, SECONDS);
verify(mockBackplane, times(1)).queue(any(QueueEntry.class), any(Operation.class));
verify(mockBackplane, times(1)).putOperation(any(Operation.class), eq(CACHE_CHECK));
verify(poller, atLeastOnce()).pause();
}
use of build.bazel.remote.execution.v2.ExecutionStage.Value.CACHE_CHECK in project bazel-buildfarm by bazelbuild.
the class ShardInstanceTest method queueOperationCompletesOperationWithCachedActionResult.
@Test
public void queueOperationCompletesOperationWithCachedActionResult() throws Exception {
ActionKey actionKey = DigestUtil.asActionKey(Digest.newBuilder().setHash("test").build());
ExecuteEntry executeEntry = ExecuteEntry.newBuilder().setOperationName("operation-with-cached-action-result").setActionDigest(actionKey.getDigest()).build();
ActionResult actionResult = ActionResult.getDefaultInstance();
when(mockBackplane.getActionResult(eq(actionKey))).thenReturn(actionResult);
Poller poller = mock(Poller.class);
instance.queue(executeEntry, poller, DEFAULT_TIMEOUT).get();
verify(mockBackplane, times(1)).putOperation(any(Operation.class), eq(CACHE_CHECK));
verify(mockBackplane, never()).putOperation(any(Operation.class), eq(QUEUED));
verify(mockBackplane, times(1)).putOperation(any(Operation.class), eq(COMPLETED));
verify(poller, atLeastOnce()).pause();
}
Aggregations