use of com.google.devtools.build.lib.remote.RemoteProtocol.ContentDigest in project bazel by bazelbuild.
the class TreeNodeRepository method getOrComputeActionInputDigest.
private synchronized ContentDigest getOrComputeActionInputDigest(ActionInput actionInput) throws IOException {
ContentDigest digest = fileContentsDigestCache.get(actionInput);
if (digest == null) {
digest = ContentDigests.computeDigest(execRoot.getRelative(actionInput.getExecPathString()));
fileContentsDigestCache.put(actionInput, digest);
digestFileContentsCache.put(digest, actionInput);
}
return digest;
}
use of com.google.devtools.build.lib.remote.RemoteProtocol.ContentDigest in project bazel by bazelbuild.
the class GrpcActionCacheTest method testUploadAllResults.
@Test
public void testUploadAllResults() throws Exception {
GrpcActionCache client = new GrpcActionCache(channel, Options.getDefaults(RemoteOptions.class));
byte[] foo = "foo".getBytes(UTF_8);
byte[] bar = "bar".getBytes(UTF_8);
Path fooFile = scratch.file("/exec/root/a/foo", foo);
Path emptyFile = scratch.file("/exec/root/b/empty");
Path barFile = scratch.file("/exec/root/a/bar", bar);
ContentDigest fooDigest = ContentDigests.computeDigest(fooFile);
ContentDigest barDigest = ContentDigests.computeDigest(barFile);
ContentDigest emptyDigest = ContentDigests.computeDigest(new byte[0]);
ActionResult.Builder result = ActionResult.newBuilder();
client.uploadAllResults(rootDir.getPath(), ImmutableList.<Path>of(fooFile, emptyFile, barFile), result);
assertThat(fakeRemoteCacheService.get(fooDigest)).isEqualTo(foo);
assertThat(fakeRemoteCacheService.get(barDigest)).isEqualTo(bar);
ActionResult.Builder expectedResult = ActionResult.newBuilder();
expectedResult.addOutputBuilder().setPath("a/foo").getFileMetadataBuilder().setDigest(fooDigest);
expectedResult.addOutputBuilder().setPath("b/empty").getFileMetadataBuilder().setDigest(emptyDigest);
expectedResult.addOutputBuilder().setPath("a/bar").getFileMetadataBuilder().setDigest(barDigest);
assertThat(result.build()).isEqualTo(expectedResult.build());
}
use of com.google.devtools.build.lib.remote.RemoteProtocol.ContentDigest in project bazel by bazelbuild.
the class GrpcActionCacheTest method testDownloadBlobs.
@Test
public void testDownloadBlobs() throws Exception {
GrpcActionCache client = new GrpcActionCache(channel, Options.getDefaults(RemoteOptions.class));
ContentDigest fooDigest = fakeRemoteCacheService.put("foo".getBytes(UTF_8));
ContentDigest barDigest = fakeRemoteCacheService.put("bar".getBytes(UTF_8));
ImmutableList<byte[]> results = client.downloadBlobs(ImmutableList.<ContentDigest>of(fooDigest, barDigest));
assertThat(new String(results.get(0), UTF_8)).isEqualTo("foo");
assertThat(new String(results.get(1), UTF_8)).isEqualTo("bar");
}
use of com.google.devtools.build.lib.remote.RemoteProtocol.ContentDigest in project bazel by bazelbuild.
the class GrpcActionCacheTest method testDownloadEmptyBlobs.
@Test
public void testDownloadEmptyBlobs() throws Exception {
GrpcActionCache client = new GrpcActionCache(channel, Options.getDefaults(RemoteOptions.class));
ContentDigest fooDigest = fakeRemoteCacheService.put("foo".getBytes(UTF_8));
ContentDigest emptyDigest = ContentDigests.computeDigest(new byte[0]);
ImmutableList<byte[]> results = client.downloadBlobs(ImmutableList.<ContentDigest>of(emptyDigest, fooDigest, emptyDigest));
// Will not query the server for empty blobs.
assertThat(new String(results.get(0), UTF_8)).isEmpty();
assertThat(new String(results.get(1), UTF_8)).isEqualTo("foo");
assertThat(new String(results.get(2), UTF_8)).isEmpty();
// Will not call the server at all.
assertThat(new String(client.downloadBlob(emptyDigest), UTF_8)).isEmpty();
}
use of com.google.devtools.build.lib.remote.RemoteProtocol.ContentDigest in project bazel by bazelbuild.
the class GrpcActionCacheTest method testUploadBlobs.
@Test
public void testUploadBlobs() throws Exception {
GrpcActionCache client = new GrpcActionCache(channel, Options.getDefaults(RemoteOptions.class));
byte[] foo = "foo".getBytes(UTF_8);
byte[] bar = "bar".getBytes(UTF_8);
ContentDigest fooDigest = ContentDigests.computeDigest(foo);
ContentDigest barDigest = ContentDigests.computeDigest(bar);
ImmutableList<ContentDigest> digests = client.uploadBlobs(ImmutableList.<byte[]>of(foo, bar));
assertThat(digests).containsExactly(fooDigest, barDigest);
assertThat(fakeRemoteCacheService.get(fooDigest)).isEqualTo(foo);
assertThat(fakeRemoteCacheService.get(barDigest)).isEqualTo(bar);
}
Aggregations