aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test
diff options
context:
space:
mode:
authorGravatar buchgr <buchgr@google.com>2017-12-20 14:08:34 -0800
committerGravatar Copybara-Service <copybara-piper@google.com>2017-12-20 14:10:44 -0800
commit243c0a84948d666ebfcf05a090e28e379d4273ca (patch)
tree41383dec43705f7b43df3adf7fdb44500e1c6aa9 /src/test
parentac2cd35438e13504336ced63b6a06581445b66a5 (diff)
remote: fix download of output directories
Fix a bug where Bazel would crash if two Directory protos had the same hash. RELNOTES: Remote Caching and Execution support output directories. PiperOrigin-RevId: 179731040
Diffstat (limited to 'src/test')
-rw-r--r--src/test/java/com/google/devtools/build/lib/remote/SimpleBlobStoreActionCacheTest.java43
1 files changed, 43 insertions, 0 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/remote/SimpleBlobStoreActionCacheTest.java b/src/test/java/com/google/devtools/build/lib/remote/SimpleBlobStoreActionCacheTest.java
index 4088a83bfc..f173c2e1b1 100644
--- a/src/test/java/com/google/devtools/build/lib/remote/SimpleBlobStoreActionCacheTest.java
+++ b/src/test/java/com/google/devtools/build/lib/remote/SimpleBlobStoreActionCacheTest.java
@@ -203,6 +203,49 @@ public class SimpleBlobStoreActionCacheTest {
}
@Test
+ public void testDownloadDirectoriesWithSameHash() throws Exception {
+ // Test that downloading an output directory works when two Directory
+ // protos have the same hash i.e. because they have the same name and contents or are empty.
+
+ /*
+ * /bar/foo/file
+ * /foo/file
+ */
+ Digest fileDigest = DIGEST_UTIL.computeAsUtf8("file");
+ FileNode file =
+ FileNode.newBuilder().setName("file").setDigest(fileDigest).build();
+ Directory fooDir = Directory.newBuilder().addFiles(file).build();
+ Digest fooDigest = DIGEST_UTIL.compute(fooDir);
+ DirectoryNode fooDirNode =
+ DirectoryNode.newBuilder().setName("foo").setDigest(fooDigest).build();
+ Directory barDir = Directory.newBuilder().addDirectories(fooDirNode).build();
+ Digest barDigest = DIGEST_UTIL.compute(barDir);
+ DirectoryNode barDirNode =
+ DirectoryNode.newBuilder().setName("bar").setDigest(barDigest).build();
+ Directory rootDir =
+ Directory.newBuilder().addDirectories(fooDirNode).addDirectories(barDirNode).build();
+
+ Tree tree = Tree.newBuilder()
+ .setRoot(rootDir)
+ .addChildren(barDir)
+ .addChildren(fooDir)
+ .addChildren(fooDir)
+ .build();
+ Digest treeDigest = DIGEST_UTIL.compute(tree);
+
+ final ConcurrentMap<String, byte[]> map = new ConcurrentHashMap<>();
+ map.put(fileDigest.getHash(), "file".getBytes(Charsets.UTF_8));
+ map.put(treeDigest.getHash(), tree.toByteArray());
+ SimpleBlobStoreActionCache client = newClient(map);
+ ActionResult.Builder result = ActionResult.newBuilder();
+ result.addOutputDirectoriesBuilder().setPath("a/").setTreeDigest(treeDigest);
+ client.download(result.build(), execRoot, null);
+
+ assertThat(DIGEST_UTIL.compute(execRoot.getRelative("a/bar/foo/file"))).isEqualTo(fileDigest);
+ assertThat(DIGEST_UTIL.compute(execRoot.getRelative("a/foo/file"))).isEqualTo(fileDigest);
+ }
+
+ @Test
public void testUploadBlob() throws Exception {
final Digest digest = DIGEST_UTIL.computeAsUtf8("abcdefg");