Search in sources :

Example 21 with ContentDigest

use of com.google.devtools.build.lib.remote.RemoteProtocol.ContentDigest in project bazel by bazelbuild.

the class TreeNodeRepositoryTest method testMerkleDigests.

@Test
public void testMerkleDigests() throws Exception {
    Artifact foo = new Artifact(scratch.file("/exec/root/a/foo", "1"), rootDir);
    Artifact bar = new Artifact(scratch.file("/exec/root/a/bar", "11"), rootDir);
    TreeNodeRepository repo = new TreeNodeRepository(rootDir.getPath());
    TreeNode root = repo.buildFromActionInputs(ImmutableList.<ActionInput>of(foo, bar));
    TreeNode aNode = root.getChildEntries().get(0).getChild();
    // foo > bar in sort order!
    TreeNode fooNode = aNode.getChildEntries().get(1).getChild();
    TreeNode barNode = aNode.getChildEntries().get(0).getChild();
    repo.computeMerkleDigests(root);
    ImmutableCollection<ContentDigest> digests = repo.getAllDigests(root);
    ContentDigest rootDigest = repo.getMerkleDigest(root);
    ContentDigest aDigest = repo.getMerkleDigest(aNode);
    ContentDigest fooDigest = repo.getMerkleDigest(fooNode);
    ContentDigest fooContentsDigest = ContentDigests.computeDigest(foo.getPath());
    ContentDigest barDigest = repo.getMerkleDigest(barNode);
    ContentDigest barContentsDigest = ContentDigests.computeDigest(bar.getPath());
    assertThat(digests).containsExactly(rootDigest, aDigest, barDigest, barContentsDigest, fooDigest, fooContentsDigest);
    ArrayList<FileNode> fileNodes = new ArrayList<>();
    ArrayList<ActionInput> actionInputs = new ArrayList<>();
    repo.getDataFromDigests(digests, actionInputs, fileNodes);
    assertThat(actionInputs).containsExactly(bar, foo);
    assertThat(fileNodes).hasSize(4);
    FileNode rootFileNode = fileNodes.get(0);
    assertThat(rootFileNode.getChild(0).getPath()).isEqualTo("a");
    assertThat(rootFileNode.getChild(0).getDigest()).isEqualTo(aDigest);
    FileNode aFileNode = fileNodes.get(1);
    assertThat(aFileNode.getChild(0).getPath()).isEqualTo("bar");
    assertThat(aFileNode.getChild(0).getDigest()).isEqualTo(barDigest);
    assertThat(aFileNode.getChild(1).getPath()).isEqualTo("foo");
    assertThat(aFileNode.getChild(1).getDigest()).isEqualTo(fooDigest);
    FileNode barFileNode = fileNodes.get(2);
    assertThat(barFileNode.getFileMetadata().getDigest()).isEqualTo(barContentsDigest);
    FileNode fooFileNode = fileNodes.get(3);
    assertThat(fooFileNode.getFileMetadata().getDigest()).isEqualTo(fooContentsDigest);
}
Also used : ActionInput(com.google.devtools.build.lib.actions.ActionInput) TreeNode(com.google.devtools.build.lib.remote.TreeNodeRepository.TreeNode) ArrayList(java.util.ArrayList) Artifact(com.google.devtools.build.lib.actions.Artifact) FileNode(com.google.devtools.build.lib.remote.RemoteProtocol.FileNode) ContentDigest(com.google.devtools.build.lib.remote.RemoteProtocol.ContentDigest) Test(org.junit.Test)

Aggregations

ContentDigest (com.google.devtools.build.lib.remote.RemoteProtocol.ContentDigest)21 Test (org.junit.Test)8 Path (com.google.devtools.build.lib.vfs.Path)7 ByteString (com.google.protobuf.ByteString)5 ArrayList (java.util.ArrayList)5 CasDownloadReply (com.google.devtools.build.lib.remote.RemoteProtocol.CasDownloadReply)4 CasDownloadBlobRequest (com.google.devtools.build.lib.remote.RemoteProtocol.CasDownloadBlobRequest)3 FileMetadata (com.google.devtools.build.lib.remote.RemoteProtocol.FileMetadata)3 FileNode (com.google.devtools.build.lib.remote.RemoteProtocol.FileNode)3 StatusRuntimeException (io.grpc.StatusRuntimeException)3 HashMap (java.util.HashMap)3 ActionInput (com.google.devtools.build.lib.actions.ActionInput)2 ActionResult (com.google.devtools.build.lib.remote.RemoteProtocol.ActionResult)2 BlobChunk (com.google.devtools.build.lib.remote.RemoteProtocol.BlobChunk)2 Pair (com.google.devtools.build.lib.util.Pair)2 IOException (java.io.IOException)2 Artifact (com.google.devtools.build.lib.actions.Artifact)1 CasUploadTreeMetadataReply (com.google.devtools.build.lib.remote.RemoteProtocol.CasUploadTreeMetadataReply)1 CasUploadTreeMetadataRequest (com.google.devtools.build.lib.remote.RemoteProtocol.CasUploadTreeMetadataRequest)1 Output (com.google.devtools.build.lib.remote.RemoteProtocol.Output)1