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);
}
Aggregations