use of com.google.cloud.talent.v4.RequestMetadata in project bazel-buildfarm by bazelbuild.
the class GrpcCASTest method writeIsResumable.
@Test
public void writeIsResumable() throws Exception {
UUID uuid = UUID.randomUUID();
ByteString writeContent = ByteString.copyFromUtf8("written");
Digest digest = DIGEST_UTIL.compute(writeContent);
String instanceName = "test";
HashCode hash = HashCode.fromString(digest.getHash());
String resourceName = ByteStreamUploader.uploadResourceName(instanceName, uuid, hash, digest.getSizeBytes());
// better test might just put a full gRPC CAS behind an in-process and validate state
SettableFuture<ByteString> content = SettableFuture.create();
serviceRegistry.addService(new ByteStreamServiceWriter(resourceName, content, (int) digest.getSizeBytes()));
Channel channel = InProcessChannelBuilder.forName(fakeServerName).directExecutor().build();
GrpcCAS cas = new GrpcCAS(instanceName, channel, /* uploader=*/
null, onExpirations);
RequestMetadata requestMetadata = RequestMetadata.getDefaultInstance();
Write initialWrite = cas.getWrite(digest, uuid, requestMetadata);
try (OutputStream writeOut = initialWrite.getOutput(1, SECONDS, () -> {
})) {
writeContent.substring(0, 4).writeTo(writeOut);
}
Write finalWrite = cas.getWrite(digest, uuid, requestMetadata);
try (OutputStream writeOut = finalWrite.getOutput(1, SECONDS, () -> {
})) {
writeContent.substring(4).writeTo(writeOut);
}
assertThat(content.get(1, TimeUnit.SECONDS)).isEqualTo(writeContent);
}
use of com.google.cloud.talent.v4.RequestMetadata in project bazel-buildfarm by bazelbuild.
the class ShardInstanceTest method duplicateExecutionsServedFromCacheAreForcedToSkipLookup.
@Test
public void duplicateExecutionsServedFromCacheAreForcedToSkipLookup() throws Exception {
ActionKey actionKey = DigestUtil.asActionKey(Digest.newBuilder().setHash("test").build());
ActionResult actionResult = ActionResult.newBuilder().addOutputFiles(OutputFile.newBuilder().setPath("does-not-exist").setDigest(Digest.newBuilder().setHash("dne").setSizeBytes(1))).setStdoutDigest(Digest.newBuilder().setHash("stdout").setSizeBytes(1)).setStderrDigest(Digest.newBuilder().setHash("stderr").setSizeBytes(1)).build();
when(mockBackplane.canQueue()).thenReturn(true);
when(mockBackplane.canPrequeue()).thenReturn(true);
when(mockBackplane.getActionResult(actionKey)).thenReturn(actionResult);
Digest actionDigest = actionKey.getDigest();
RequestMetadata requestMetadata = RequestMetadata.newBuilder().setToolDetails(ToolDetails.newBuilder().setToolName("buildfarm-test").setToolVersion("0.1")).setCorrelatedInvocationsId(UUID.randomUUID().toString()).setToolInvocationId(UUID.randomUUID().toString()).setActionId(actionDigest.getHash()).build();
String operationName = "cache-served-operation";
ExecuteEntry cacheServedExecuteEntry = ExecuteEntry.newBuilder().setOperationName(operationName).setActionDigest(actionDigest).setRequestMetadata(requestMetadata).build();
Poller poller = mock(Poller.class);
instance.queue(cacheServedExecuteEntry, poller, DEFAULT_TIMEOUT).get(QUEUE_TEST_TIMEOUT_SECONDS, SECONDS);
verify(poller, times(1)).pause();
verify(mockBackplane, never()).queue(any(QueueEntry.class), any(Operation.class));
ArgumentCaptor<Operation> cacheCheckOperationCaptor = ArgumentCaptor.forClass(Operation.class);
verify(mockBackplane, times(1)).putOperation(cacheCheckOperationCaptor.capture(), eq(CACHE_CHECK));
Operation cacheCheckOperation = cacheCheckOperationCaptor.getValue();
assertThat(cacheCheckOperation.getName()).isEqualTo(operationName);
ArgumentCaptor<Operation> completedOperationCaptor = ArgumentCaptor.forClass(Operation.class);
verify(mockBackplane, times(1)).putOperation(completedOperationCaptor.capture(), eq(COMPLETED));
Operation completedOperation = completedOperationCaptor.getValue();
assertThat(completedOperation.getName()).isEqualTo(operationName);
ExecuteResponse executeResponse = completedOperation.getResponse().unpack(ExecuteResponse.class);
assertThat(executeResponse.getResult()).isEqualTo(actionResult);
assertThat(executeResponse.getCachedResult()).isTrue();
Watcher mockWatcher = mock(Watcher.class);
instance.execute(actionDigest, /* skipCacheLookup=*/
false, ExecutionPolicy.getDefaultInstance(), ResultsCachePolicy.getDefaultInstance(), requestMetadata, /* watcher=*/
mockWatcher);
verify(mockWatcher, times(1)).observe(any(Operation.class));
ArgumentCaptor<ExecuteEntry> executeEntryCaptor = ArgumentCaptor.forClass(ExecuteEntry.class);
verify(mockBackplane, times(1)).prequeue(executeEntryCaptor.capture(), any(Operation.class));
ExecuteEntry executeEntry = executeEntryCaptor.getValue();
assertThat(executeEntry.getSkipCacheLookup()).isTrue();
}
use of com.google.cloud.talent.v4.RequestMetadata in project bazel-buildfarm by bazelbuild.
the class ExecutionServiceTest method keepaliveIsCancelledWithContext.
@SuppressWarnings("unchecked")
@Test
public void keepaliveIsCancelledWithContext() throws Exception {
ScheduledExecutorService keepaliveScheduler = newSingleThreadScheduledExecutor();
ExecutionService service = new ExecutionService(instance, /* keepaliveAfter=*/
1, // far enough in the future that we'll get scheduled and
SECONDS, /* keepaliveUnit=*/
keepaliveScheduler, new LogMetricsPublisher(// cancelled without executing
MetricsConfig.getDefaultInstance()));
ServerCallStreamObserver<Operation> response = mock(ServerCallStreamObserver.class);
RequestMetadata requestMetadata = RequestMetadata.newBuilder().build();
Operation operation = Operation.newBuilder().setName("immediately-cancelled-watch-operation").build();
KeepaliveWatcher watcher = service.createWatcher(response, requestMetadata);
watcher.observe(operation);
ListenableFuture<?> future = watcher.getFuture();
assertThat(future).isNotNull();
ArgumentCaptor<Runnable> onCancelHandlerCaptor = ArgumentCaptor.forClass(Runnable.class);
verify(response, times(1)).setOnCancelHandler(onCancelHandlerCaptor.capture());
Runnable onCancelHandler = onCancelHandlerCaptor.getValue();
onCancelHandler.run();
assertThat(future.isCancelled()).isTrue();
assertThat(shutdownAndAwaitTermination(keepaliveScheduler, 1, SECONDS)).isTrue();
// should only get one call for the real operation
verify(response, times(1)).onNext(operation);
}
use of com.google.cloud.talent.v4.RequestMetadata in project bazel-buildfarm by bazelbuild.
the class AbstractServerInstanceTest method outputDirectoriesFilesAreEnsuredPresent.
@SuppressWarnings("unchecked")
@Test
public void outputDirectoriesFilesAreEnsuredPresent() throws Exception {
// our test subjects - these should appear in the findMissingBlobs request
Digest fileDigest = DIGEST_UTIL.compute(ByteString.copyFromUtf8("Output Directory Root File Content"));
Digest childFileDigest = DIGEST_UTIL.compute(ByteString.copyFromUtf8("Output Directory Child File Content"));
Digest otherFileDigest = DIGEST_UTIL.compute(ByteString.copyFromUtf8("Another Output Directory File Content"));
// setup block and ensureOutputsPresent trigger
RequestMetadata requestMetadata = RequestMetadata.newBuilder().setCorrelatedInvocationsId("https://localhost:12345/test/build?ENSURE_OUTPUTS_PRESENT=true#92af266a-c5bf-48ca-a723-344ae516a786").build();
ContentAddressableStorage contentAddressableStorage = mock(ContentAddressableStorage.class);
ActionCache actionCache = mock(ActionCache.class);
AbstractServerInstance instance = new DummyServerInstance(contentAddressableStorage, actionCache);
Tree tree = Tree.newBuilder().setRoot(Directory.newBuilder().addFiles(FileNode.newBuilder().setDigest(fileDigest)).build()).addChildren(Directory.newBuilder().addFiles(FileNode.newBuilder().setDigest(childFileDigest)).build()).build();
Tree otherTree = Tree.newBuilder().setRoot(Directory.newBuilder().addFiles(FileNode.newBuilder().setDigest(otherFileDigest)).build()).build();
Digest treeDigest = DIGEST_UTIL.compute(tree);
doBlob(contentAddressableStorage, treeDigest, tree.toByteString(), requestMetadata);
Digest otherTreeDigest = DIGEST_UTIL.compute(otherTree);
doBlob(contentAddressableStorage, otherTreeDigest, otherTree.toByteString(), requestMetadata);
ActionKey actionKey = DigestUtil.asActionKey(DIGEST_UTIL.compute(ByteString.copyFromUtf8("action")));
ActionResult actionResult = ActionResult.newBuilder().addOutputDirectories(OutputDirectory.newBuilder().setTreeDigest(treeDigest).build()).addOutputDirectories(OutputDirectory.newBuilder().setTreeDigest(otherTreeDigest).build()).build();
when(actionCache.get(actionKey)).thenReturn(immediateFuture(actionResult));
// invocation
assertThat(instance.getActionResult(actionKey, requestMetadata).get()).isEqualTo(actionResult);
// validation
ArgumentCaptor<Iterable<Digest>> findMissingBlobsCaptor = ArgumentCaptor.forClass(Iterable.class);
verify(contentAddressableStorage, times(1)).get(eq(treeDigest), /* offset=*/
eq(0L), eq(treeDigest.getSizeBytes()), any(ServerCallStreamObserver.class), eq(requestMetadata));
verify(contentAddressableStorage, times(1)).findMissingBlobs(findMissingBlobsCaptor.capture());
assertThat(findMissingBlobsCaptor.getValue()).containsAtLeast(fileDigest, childFileDigest, otherFileDigest);
}
use of com.google.cloud.talent.v4.RequestMetadata in project bazel-buildfarm by bazelbuild.
the class ExecutionService method execute.
@Override
public void execute(ExecuteRequest request, StreamObserver<Operation> responseObserver) {
ServerCallStreamObserver<Operation> serverCallStreamObserver = (ServerCallStreamObserver<Operation>) responseObserver;
try {
RequestMetadata requestMetadata = TracingMetadataUtils.fromCurrentContext();
withCancellation(serverCallStreamObserver, instance.execute(request.getActionDigest(), request.getSkipCacheLookup(), request.getExecutionPolicy(), request.getResultsCachePolicy(), requestMetadata, createWatcher(serverCallStreamObserver, requestMetadata)));
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
}
Aggregations