Search in sources :

Example 6 with ContentDigest

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;
}
Also used : ContentDigest(com.google.devtools.build.lib.remote.RemoteProtocol.ContentDigest)

Example 7 with ContentDigest

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());
}
Also used : Path(com.google.devtools.build.lib.vfs.Path) ActionResult(com.google.devtools.build.lib.remote.RemoteProtocol.ActionResult) ContentDigest(com.google.devtools.build.lib.remote.RemoteProtocol.ContentDigest) Test(org.junit.Test)

Example 8 with ContentDigest

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");
}
Also used : ByteString(com.google.protobuf.ByteString) ContentDigest(com.google.devtools.build.lib.remote.RemoteProtocol.ContentDigest) Test(org.junit.Test)

Example 9 with ContentDigest

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();
}
Also used : ByteString(com.google.protobuf.ByteString) ContentDigest(com.google.devtools.build.lib.remote.RemoteProtocol.ContentDigest) Test(org.junit.Test)

Example 10 with ContentDigest

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);
}
Also used : 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