aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test
diff options
context:
space:
mode:
authorGravatar tomlu <tomlu@google.com>2018-08-02 11:44:26 -0700
committerGravatar Copybara-Service <copybara-piper@google.com>2018-08-02 11:46:47 -0700
commitd1a203bbdd2033ec8049b39242189e1cc76a9e8e (patch)
tree44a286b58e717f5f8fe43c07ca99c4e9540d1edf /src/test
parent6d07c367fc912819312834267a6ba7e28b05ac0e (diff)
Add support for VirtualActionInputs to the remote cache.
RELNOTES: None PiperOrigin-RevId: 207137932
Diffstat (limited to 'src/test')
-rw-r--r--src/test/java/com/google/devtools/build/lib/remote/GrpcRemoteCacheTest.java100
1 files changed, 100 insertions, 0 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/remote/GrpcRemoteCacheTest.java b/src/test/java/com/google/devtools/build/lib/remote/GrpcRemoteCacheTest.java
index 3c61fd149d..de453b3e68 100644
--- a/src/test/java/com/google/devtools/build/lib/remote/GrpcRemoteCacheTest.java
+++ b/src/test/java/com/google/devtools/build/lib/remote/GrpcRemoteCacheTest.java
@@ -28,12 +28,15 @@ import com.google.bytestream.ByteStreamProto.WriteRequest;
import com.google.bytestream.ByteStreamProto.WriteResponse;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.ImmutableSortedMap;
import com.google.common.util.concurrent.ListeningScheduledExecutorService;
import com.google.common.util.concurrent.MoreExecutors;
import com.google.devtools.build.lib.actions.ActionInputHelper;
+import com.google.devtools.build.lib.actions.cache.VirtualActionInput;
import com.google.devtools.build.lib.authandtls.AuthAndTLSOptions;
import com.google.devtools.build.lib.authandtls.GoogleAuthUtils;
import com.google.devtools.build.lib.clock.JavaClock;
+import com.google.devtools.build.lib.remote.TreeNodeRepository.TreeNode;
import com.google.devtools.build.lib.remote.util.DigestUtil;
import com.google.devtools.build.lib.remote.util.DigestUtil.ActionKey;
import com.google.devtools.build.lib.remote.util.TracingMetadataUtils;
@@ -43,11 +46,13 @@ import com.google.devtools.build.lib.vfs.DigestHashFunction;
import com.google.devtools.build.lib.vfs.FileSystem;
import com.google.devtools.build.lib.vfs.FileSystemUtils;
import com.google.devtools.build.lib.vfs.Path;
+import com.google.devtools.build.lib.vfs.PathFragment;
import com.google.devtools.build.lib.vfs.inmemoryfs.InMemoryFileSystem;
import com.google.devtools.common.options.Options;
import com.google.devtools.remoteexecution.v1test.Action;
import com.google.devtools.remoteexecution.v1test.ActionCacheGrpc.ActionCacheImplBase;
import com.google.devtools.remoteexecution.v1test.ActionResult;
+import com.google.devtools.remoteexecution.v1test.Command;
import com.google.devtools.remoteexecution.v1test.ContentAddressableStorageGrpc.ContentAddressableStorageImplBase;
import com.google.devtools.remoteexecution.v1test.Digest;
import com.google.devtools.remoteexecution.v1test.Directory;
@@ -74,7 +79,10 @@ import io.grpc.stub.StreamObserver;
import io.grpc.util.MutableHandlerRegistry;
import java.io.IOException;
import java.io.InputStream;
+import java.io.OutputStream;
+import java.nio.charset.StandardCharsets;
import java.util.concurrent.Executors;
+import java.util.concurrent.atomic.AtomicBoolean;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
@@ -201,6 +209,98 @@ public class GrpcRemoteCacheTest {
uploader);
}
+ static class StringVirtualActionInput implements VirtualActionInput {
+ private final String contents;
+ private final PathFragment execPath;
+
+ StringVirtualActionInput(String contents, PathFragment execPath) {
+ this.contents = contents;
+ this.execPath = execPath;
+ }
+
+ @Override
+ public void writeTo(OutputStream out) throws IOException {
+ out.write(contents.getBytes(StandardCharsets.UTF_8));
+ }
+
+ @Override
+ public ByteString getBytes() throws IOException {
+ ByteString.Output out = ByteString.newOutput();
+ writeTo(out);
+ return out.toByteString();
+ }
+
+ @Override
+ public String getExecPathString() {
+ return execPath.getPathString();
+ }
+
+ @Override
+ public PathFragment getExecPath() {
+ return execPath;
+ }
+ }
+
+ @Test
+ public void testVirtualActionInputSupport() throws Exception {
+ GrpcRemoteCache client = newClient();
+ TreeNodeRepository treeNodeRepository =
+ new TreeNodeRepository(execRoot, fakeFileCache, DIGEST_UTIL);
+ PathFragment execPath = PathFragment.create("my/exec/path");
+ VirtualActionInput virtualActionInput = new StringVirtualActionInput("hello", execPath);
+ Digest digest = DIGEST_UTIL.compute(virtualActionInput.getBytes().toByteArray());
+ TreeNode root =
+ treeNodeRepository.buildFromActionInputs(
+ ImmutableSortedMap.of(execPath, virtualActionInput));
+
+ // Add a fake CAS that responds saying that the above virtual action input is missing
+ serviceRegistry.addService(
+ new ContentAddressableStorageImplBase() {
+ @Override
+ public void findMissingBlobs(
+ FindMissingBlobsRequest request,
+ StreamObserver<FindMissingBlobsResponse> responseObserver) {
+ responseObserver.onNext(
+ FindMissingBlobsResponse.newBuilder().addMissingBlobDigests(digest).build());
+ responseObserver.onCompleted();
+ }
+ });
+
+ // Mock a byte stream and assert that we see the virtual action input with contents 'hello'
+ AtomicBoolean writeOccurred = new AtomicBoolean();
+ serviceRegistry.addService(
+ new ByteStreamImplBase() {
+ @Override
+ public StreamObserver<WriteRequest> write(
+ final StreamObserver<WriteResponse> responseObserver) {
+ return new StreamObserver<WriteRequest>() {
+ @Override
+ public void onNext(WriteRequest request) {
+ assertThat(request.getResourceName()).contains(digest.getHash());
+ assertThat(request.getFinishWrite()).isTrue();
+ assertThat(request.getData().toStringUtf8()).isEqualTo("hello");
+ writeOccurred.set(true);
+ }
+
+ @Override
+ public void onCompleted() {
+ responseObserver.onNext(WriteResponse.newBuilder().setCommittedSize(5).build());
+ responseObserver.onCompleted();
+ }
+
+ @Override
+ public void onError(Throwable t) {
+ fail("An error occurred: " + t);
+ }
+ };
+ }
+ });
+
+ // Upload all missing inputs (that is, the virtual action input from above)
+ client.ensureInputsPresent(treeNodeRepository, execRoot, root, Command.getDefaultInstance());
+ assertThat(writeOccurred.get()).named("WriteOccurred").isTrue();
+ }
+
@Test
public void testDownloadEmptyBlob() throws Exception {
GrpcRemoteCache client = newClient();