use of build.buildfarm.ac.ActionCache in project bazel-buildfarm by bazelbuild.
the class AbstractServerInstanceTest method outputDirectoriesFilesAreEnsuredPresent.
@SuppressWarnings("unchecked")
@Test
public void outputDirectoriesFilesAreEnsuredPresent() throws Exception {
// our test subjects - these should appear in the findMissingBlobs request
Digest fileDigest = DIGEST_UTIL.compute(ByteString.copyFromUtf8("Output Directory Root File Content"));
Digest childFileDigest = DIGEST_UTIL.compute(ByteString.copyFromUtf8("Output Directory Child File Content"));
Digest otherFileDigest = DIGEST_UTIL.compute(ByteString.copyFromUtf8("Another Output Directory File Content"));
// setup block and ensureOutputsPresent trigger
RequestMetadata requestMetadata = RequestMetadata.newBuilder().setCorrelatedInvocationsId("https://localhost:12345/test/build?ENSURE_OUTPUTS_PRESENT=true#92af266a-c5bf-48ca-a723-344ae516a786").build();
ContentAddressableStorage contentAddressableStorage = mock(ContentAddressableStorage.class);
ActionCache actionCache = mock(ActionCache.class);
AbstractServerInstance instance = new DummyServerInstance(contentAddressableStorage, actionCache);
Tree tree = Tree.newBuilder().setRoot(Directory.newBuilder().addFiles(FileNode.newBuilder().setDigest(fileDigest)).build()).addChildren(Directory.newBuilder().addFiles(FileNode.newBuilder().setDigest(childFileDigest)).build()).build();
Tree otherTree = Tree.newBuilder().setRoot(Directory.newBuilder().addFiles(FileNode.newBuilder().setDigest(otherFileDigest)).build()).build();
Digest treeDigest = DIGEST_UTIL.compute(tree);
doBlob(contentAddressableStorage, treeDigest, tree.toByteString(), requestMetadata);
Digest otherTreeDigest = DIGEST_UTIL.compute(otherTree);
doBlob(contentAddressableStorage, otherTreeDigest, otherTree.toByteString(), requestMetadata);
ActionKey actionKey = DigestUtil.asActionKey(DIGEST_UTIL.compute(ByteString.copyFromUtf8("action")));
ActionResult actionResult = ActionResult.newBuilder().addOutputDirectories(OutputDirectory.newBuilder().setTreeDigest(treeDigest).build()).addOutputDirectories(OutputDirectory.newBuilder().setTreeDigest(otherTreeDigest).build()).build();
when(actionCache.get(actionKey)).thenReturn(immediateFuture(actionResult));
// invocation
assertThat(instance.getActionResult(actionKey, requestMetadata).get()).isEqualTo(actionResult);
// validation
ArgumentCaptor<Iterable<Digest>> findMissingBlobsCaptor = ArgumentCaptor.forClass(Iterable.class);
verify(contentAddressableStorage, times(1)).get(eq(treeDigest), /* offset=*/
eq(0L), eq(treeDigest.getSizeBytes()), any(ServerCallStreamObserver.class), eq(requestMetadata));
verify(contentAddressableStorage, times(1)).findMissingBlobs(findMissingBlobsCaptor.capture());
assertThat(findMissingBlobsCaptor.getValue()).containsAtLeast(fileDigest, childFileDigest, otherFileDigest);
}
Aggregations