Search in sources :

Example 1 with ActionCache

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);
}
Also used : ActionCache(build.buildfarm.ac.ActionCache) ServerCallStreamObserver(io.grpc.stub.ServerCallStreamObserver) ActionResult(build.bazel.remote.execution.v2.ActionResult) Digest(build.bazel.remote.execution.v2.Digest) ContentAddressableStorage(build.buildfarm.cas.ContentAddressableStorage) Tree(build.bazel.remote.execution.v2.Tree) ActionKey(build.buildfarm.common.DigestUtil.ActionKey) RequestMetadata(build.bazel.remote.execution.v2.RequestMetadata) Test(org.junit.Test)

Aggregations

ActionResult (build.bazel.remote.execution.v2.ActionResult)1 Digest (build.bazel.remote.execution.v2.Digest)1 RequestMetadata (build.bazel.remote.execution.v2.RequestMetadata)1 Tree (build.bazel.remote.execution.v2.Tree)1 ActionCache (build.buildfarm.ac.ActionCache)1 ContentAddressableStorage (build.buildfarm.cas.ContentAddressableStorage)1 ActionKey (build.buildfarm.common.DigestUtil.ActionKey)1 ServerCallStreamObserver (io.grpc.stub.ServerCallStreamObserver)1 Test (org.junit.Test)1