Search in sources :

Example 1 with ActionKey

use of build.buildfarm.common.DigestUtil.ActionKey in project bazel-buildfarm by bazelbuild.

the class ShardInstance method requeueOperation.

@VisibleForTesting
public ListenableFuture<Void> requeueOperation(QueueEntry queueEntry, Duration timeout) {
    ListenableFuture<Void> future;
    ExecuteEntry executeEntry = queueEntry.getExecuteEntry();
    Operation operation = getOperation(executeEntry.getOperationName());
    try {
        // check preconditions before trying to requeue.
        boolean canRequeue = canOperationBeRequeued(queueEntry, executeEntry, operation);
        if (!canRequeue) {
            return IMMEDIATE_VOID_FUTURE;
        }
        // Requeue the action as long as the result is not already cached.
        ActionKey actionKey = DigestUtil.asActionKey(executeEntry.getActionDigest());
        ListenableFuture<Boolean> cachedResultFuture;
        if (executeEntry.getSkipCacheLookup()) {
            cachedResultFuture = immediateFuture(false);
        } else {
            cachedResultFuture = checkCacheFuture(actionKey, operation, executeEntry.getRequestMetadata());
        }
        future = transformAsync(cachedResultFuture, (cachedResult) -> {
            if (cachedResult) {
                return IMMEDIATE_VOID_FUTURE;
            }
            return validateAndRequeueOperation(operation, queueEntry, timeout);
        }, operationTransformService);
    } catch (IOException | StatusRuntimeException e) {
        return immediateFailedFuture(e);
    }
    return future;
}
Also used : ExecuteOperationMetadata(build.bazel.remote.execution.v2.ExecuteOperationMetadata) AsyncCache(com.github.benmanes.caffeine.cache.AsyncCache) LoadingCache(com.google.common.cache.LoadingCache) DirectoryNode(build.bazel.remote.execution.v2.DirectoryNode) ExecuteEntry(build.buildfarm.v1test.ExecuteEntry) ExecutionStage(build.bazel.remote.execution.v2.ExecutionStage) Durations(com.google.protobuf.util.Durations) Executors.newSingleThreadScheduledExecutor(java.util.concurrent.Executors.newSingleThreadScheduledExecutor) StatusProto(io.grpc.protobuf.StatusProto) Tree(build.buildfarm.v1test.Tree) Map(java.util.Map) Status(io.grpc.Status) ServerCallStreamObserver(io.grpc.stub.ServerCallStreamObserver) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) Futures.allAsList(com.google.common.util.concurrent.Futures.allAsList) EntryLimitException(build.buildfarm.common.EntryLimitException) Set(java.util.Set) BlockingQueue(java.util.concurrent.BlockingQueue) MoreExecutors.directExecutor(com.google.common.util.concurrent.MoreExecutors.directExecutor) MatchListener(build.buildfarm.instance.MatchListener) AbstractServerInstance(build.buildfarm.instance.server.AbstractServerInstance) VIOLATION_TYPE_MISSING(build.buildfarm.common.Errors.VIOLATION_TYPE_MISSING) DirectoryEntry(build.buildfarm.common.TreeIterator.DirectoryEntry) OperationIteratorToken(build.buildfarm.v1test.OperationIteratorToken) QueueEntry(build.buildfarm.v1test.QueueEntry) Any(com.google.protobuf.Any) MICROSECONDS(java.util.concurrent.TimeUnit.MICROSECONDS) ListeningExecutorService(com.google.common.util.concurrent.ListeningExecutorService) Actions.checkPreconditionFailure(build.buildfarm.common.Actions.checkPreconditionFailure) Directory(build.bazel.remote.execution.v2.Directory) ShardInstanceConfig(build.buildfarm.v1test.ShardInstanceConfig) Iterables(com.google.common.collect.Iterables) Command(build.bazel.remote.execution.v2.Command) MINUTES(java.util.concurrent.TimeUnit.MINUTES) QueuedOperation(build.buildfarm.v1test.QueuedOperation) Util.correctMissingBlob(build.buildfarm.instance.shard.Util.correctMissingBlob) ResultsCachePolicy(build.bazel.remote.execution.v2.ResultsCachePolicy) Cache(com.github.benmanes.caffeine.cache.Cache) Supplier(java.util.function.Supplier) DigestUtil(build.buildfarm.common.DigestUtil) ArrayList(java.util.ArrayList) Code(io.grpc.Status.Code) Action(build.bazel.remote.execution.v2.Action) UniformDelegateServerCallStreamObserver(build.buildfarm.common.grpc.UniformDelegateServerCallStreamObserver) Futures.addCallback(com.google.common.util.concurrent.Futures.addCallback) Actions.asExecutionStatus(build.buildfarm.common.Actions.asExecutionStatus) Watcher(build.buildfarm.common.Watcher) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) VIOLATION_TYPE_INVALID(build.buildfarm.common.Errors.VIOLATION_TYPE_INVALID) Nullable(javax.annotation.Nullable) Backplane(build.buildfarm.backplane.Backplane) Futures.immediateFuture(com.google.common.util.concurrent.Futures.immediateFuture) Caffeine(com.github.benmanes.caffeine.cache.Caffeine) BaseEncoding(com.google.common.io.BaseEncoding) Executor(java.util.concurrent.Executor) Poller(build.buildfarm.common.Poller) Throwables(com.google.common.base.Throwables) PreconditionFailure(com.google.rpc.PreconditionFailure) IOException(java.io.IOException) QueueStatus(build.buildfarm.v1test.QueueStatus) FutureCallback(com.google.common.util.concurrent.FutureCallback) StatusRuntimeException(io.grpc.StatusRuntimeException) ExecutionException(java.util.concurrent.ExecutionException) Futures(com.google.common.util.concurrent.Futures) Duration(com.google.protobuf.Duration) FutureConverter.toCompletableFuture(net.javacrumbs.futureconverter.java8guava.FutureConverter.toCompletableFuture) ExecuteResponse(build.bazel.remote.execution.v2.ExecuteResponse) ArrayDeque(java.util.ArrayDeque) Futures.transform(com.google.common.util.concurrent.Futures.transform) Context(io.grpc.Context) Futures.transformAsync(com.google.common.util.concurrent.Futures.transformAsync) BiFunction(java.util.function.BiFunction) RequestMetadata(build.bazel.remote.execution.v2.RequestMetadata) Random(java.util.Random) Actions.invalidActionVerboseMessage(build.buildfarm.common.Actions.invalidActionVerboseMessage) ActionKey(build.buildfarm.common.DigestUtil.ActionKey) SettableFuture(com.google.common.util.concurrent.SettableFuture) ExecutionProperties(build.buildfarm.common.ExecutionProperties) TokenizableIterator(build.buildfarm.common.TokenizableIterator) Digest(build.bazel.remote.execution.v2.Digest) CasIndexResults(build.buildfarm.common.CasIndexResults) Gauge(io.prometheus.client.Gauge) Histogram(io.prometheus.client.Histogram) Executors.newSingleThreadExecutor(java.util.concurrent.Executors.newSingleThreadExecutor) Timestamps(com.google.protobuf.util.Timestamps) BackplaneStatus(build.buildfarm.v1test.BackplaneStatus) UUID(java.util.UUID) Logger(java.util.logging.Logger) Platform(build.bazel.remote.execution.v2.Platform) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) String.format(java.lang.String.format) Instance(build.buildfarm.instance.Instance) Sets(com.google.common.collect.Sets) Parser(com.google.protobuf.Parser) Preconditions.checkState(com.google.common.base.Preconditions.checkState) ByteString(com.google.protobuf.ByteString) QueuedOperationMetadata(build.buildfarm.v1test.QueuedOperationMetadata) List(java.util.List) Queue(java.util.Queue) FutureConverter.toListenableFuture(net.javacrumbs.futureconverter.java8guava.FutureConverter.toListenableFuture) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) MoreExecutors.listeningDecorator(com.google.common.util.concurrent.MoreExecutors.listeningDecorator) GetClientStartTimeRequest(build.buildfarm.v1test.GetClientStartTimeRequest) TreeIterator(build.buildfarm.common.TreeIterator) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) Deadline(io.grpc.Deadline) Property(build.bazel.remote.execution.v2.Platform.Property) Stopwatch(com.google.common.base.Stopwatch) StatusException(io.grpc.StatusException) ProfiledQueuedOperationMetadata(build.buildfarm.v1test.ProfiledQueuedOperationMetadata) CompletableFuture(java.util.concurrent.CompletableFuture) ConfigurationException(javax.naming.ConfigurationException) Operation(com.google.longrunning.Operation) Deque(java.util.Deque) Counter(io.prometheus.client.Counter) Level(java.util.logging.Level) SHARD_IS_RETRIABLE(build.buildfarm.instance.shard.Util.SHARD_IS_RETRIABLE) ImmutableList(com.google.common.collect.ImmutableList) GetClientStartTimeResult(build.buildfarm.v1test.GetClientStartTimeResult) UncheckedExecutionException(com.google.common.util.concurrent.UncheckedExecutionException) FindOperationsResults(build.buildfarm.operations.FindOperationsResults) ActionResult(build.bazel.remote.execution.v2.ActionResult) ExecutorService(java.util.concurrent.ExecutorService) OutputStream(java.io.OutputStream) Iterator(java.util.Iterator) Futures.catching(com.google.common.util.concurrent.Futures.catching) ExecutionPolicy(build.bazel.remote.execution.v2.ExecutionPolicy) Executors.newFixedThreadPool(java.util.concurrent.Executors.newFixedThreadPool) Write(build.buildfarm.common.Write) Futures.catchingAsync(com.google.common.util.concurrent.Futures.catchingAsync) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) Futures.immediateFailedFuture(com.google.common.util.concurrent.Futures.immediateFailedFuture) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Collections(java.util.Collections) SECONDS(java.util.concurrent.TimeUnit.SECONDS) InputStream(java.io.InputStream) ExecuteEntry(build.buildfarm.v1test.ExecuteEntry) StatusRuntimeException(io.grpc.StatusRuntimeException) ActionKey(build.buildfarm.common.DigestUtil.ActionKey) QueuedOperation(build.buildfarm.v1test.QueuedOperation) Operation(com.google.longrunning.Operation) IOException(java.io.IOException) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 2 with ActionKey

use of build.buildfarm.common.DigestUtil.ActionKey in project bazel-buildfarm by bazelbuild.

the class ShardInstance method queue.

@VisibleForTesting
public ListenableFuture<Void> queue(ExecuteEntry executeEntry, Poller poller, Duration timeout) {
    ExecuteOperationMetadata metadata = ExecuteOperationMetadata.newBuilder().setActionDigest(executeEntry.getActionDigest()).setStdoutStreamName(executeEntry.getStdoutStreamName()).setStderrStreamName(executeEntry.getStderrStreamName()).build();
    Operation operation = Operation.newBuilder().setName(executeEntry.getOperationName()).setMetadata(Any.pack(metadata)).build();
    Digest actionDigest = executeEntry.getActionDigest();
    ActionKey actionKey = DigestUtil.asActionKey(actionDigest);
    Stopwatch stopwatch = Stopwatch.createStarted();
    ListenableFuture<Boolean> cachedResultFuture;
    if (executeEntry.getSkipCacheLookup()) {
        cachedResultFuture = immediateFuture(false);
    } else {
        cachedResultFuture = checkCacheFuture(actionKey, operation, executeEntry.getRequestMetadata());
    }
    return transformAsync(cachedResultFuture, (cachedResult) -> {
        if (cachedResult) {
            poller.pause();
            long checkCacheUSecs = stopwatch.elapsed(MICROSECONDS);
            logger.log(Level.FINE, format("ShardInstance(%s): checkCache(%s): %sus elapsed", getName(), operation.getName(), checkCacheUSecs));
            return IMMEDIATE_VOID_FUTURE;
        }
        return transformAndQueue(executeEntry, poller, operation, stopwatch, timeout);
    }, operationTransformService);
}
Also used : Digest(build.bazel.remote.execution.v2.Digest) ExecuteOperationMetadata(build.bazel.remote.execution.v2.ExecuteOperationMetadata) Stopwatch(com.google.common.base.Stopwatch) ActionKey(build.buildfarm.common.DigestUtil.ActionKey) QueuedOperation(build.buildfarm.v1test.QueuedOperation) Operation(com.google.longrunning.Operation) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 3 with ActionKey

use of build.buildfarm.common.DigestUtil.ActionKey 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();
}
Also used : Digest(build.bazel.remote.execution.v2.Digest) ExecuteEntry(build.buildfarm.v1test.ExecuteEntry) Watcher(build.buildfarm.common.Watcher) ActionKey(build.buildfarm.common.DigestUtil.ActionKey) ExecuteResponse(build.bazel.remote.execution.v2.ExecuteResponse) ByteString(com.google.protobuf.ByteString) QueuedOperation(build.buildfarm.v1test.QueuedOperation) Operation(com.google.longrunning.Operation) QueueEntry(build.buildfarm.v1test.QueueEntry) RequestMetadata(build.bazel.remote.execution.v2.RequestMetadata) ActionResult(build.bazel.remote.execution.v2.ActionResult) Poller(build.buildfarm.common.Poller) Test(org.junit.Test)

Example 4 with ActionKey

use of build.buildfarm.common.DigestUtil.ActionKey in project bazel-buildfarm by bazelbuild.

the class ShardInstanceTest method queueWithFailedCacheCheckContinues.

@Test
public void queueWithFailedCacheCheckContinues() throws Exception {
    Action action = createAction();
    ActionKey actionKey = DIGEST_UTIL.computeActionKey(action);
    ExecuteEntry executeEntry = ExecuteEntry.newBuilder().setOperationName("operation-with-erroring-action-result").setActionDigest(actionKey.getDigest()).build();
    when(mockBackplane.propertiesEligibleForQueue(Matchers.anyList())).thenReturn(true);
    when(mockBackplane.canQueue()).thenReturn(true);
    when(mockBackplane.getActionResult(eq(actionKey))).thenThrow(new IOException(Status.UNAVAILABLE.asException()));
    doAnswer(answer((digest, uuid) -> new NullWrite())).when(mockWorkerInstance).getBlobWrite(any(Digest.class), any(UUID.class), any(RequestMetadata.class));
    Poller poller = mock(Poller.class);
    instance.queue(executeEntry, poller, DEFAULT_TIMEOUT).get(QUEUE_TEST_TIMEOUT_SECONDS, SECONDS);
    verify(mockBackplane, times(1)).queue(any(QueueEntry.class), any(Operation.class));
    verify(mockBackplane, times(1)).putOperation(any(Operation.class), eq(CACHE_CHECK));
    verify(poller, atLeastOnce()).pause();
}
Also used : ExecuteOperationMetadata(build.bazel.remote.execution.v2.ExecuteOperationMetadata) AsyncCache(com.github.benmanes.caffeine.cache.AsyncCache) ArgumentMatchers.argThat(org.mockito.ArgumentMatchers.argThat) DirectoryNode(build.bazel.remote.execution.v2.DirectoryNode) ExecuteEntry(build.buildfarm.v1test.ExecuteEntry) RequestMetadata(build.bazel.remote.execution.v2.RequestMetadata) Actions.invalidActionVerboseMessage(build.buildfarm.common.Actions.invalidActionVerboseMessage) ActionKey(build.buildfarm.common.DigestUtil.ActionKey) Durations(com.google.protobuf.util.Durations) MISSING_ACTION(build.buildfarm.instance.server.AbstractServerInstance.MISSING_ACTION) ArgumentMatcher(org.mockito.ArgumentMatcher) MockitoAnnotations(org.mockito.MockitoAnnotations) StreamObserver(io.grpc.stub.StreamObserver) StatusProto(io.grpc.protobuf.StatusProto) Digest(build.bazel.remote.execution.v2.Digest) Mockito.doAnswer(org.mockito.Mockito.doAnswer) After(org.junit.After) COMPLETED(build.bazel.remote.execution.v2.ExecutionStage.Value.COMPLETED) Status(io.grpc.Status) INVALID_PLATFORM(build.buildfarm.instance.server.AbstractServerInstance.INVALID_PLATFORM) ServerCallStreamObserver(io.grpc.stub.ServerCallStreamObserver) ImmutableSet(com.google.common.collect.ImmutableSet) Mockito.atLeastOnce(org.mockito.Mockito.atLeastOnce) Set(java.util.Set) Executors.newSingleThreadExecutor(java.util.concurrent.Executors.newSingleThreadExecutor) OutputFile(build.bazel.remote.execution.v2.OutputFile) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) Instance(build.buildfarm.instance.Instance) Sets(com.google.common.collect.Sets) CacheLoader(com.google.common.cache.CacheLoader) ByteString(com.google.protobuf.ByteString) List(java.util.List) VIOLATION_TYPE_MISSING(build.buildfarm.common.Errors.VIOLATION_TYPE_MISSING) HashFunction(build.buildfarm.common.DigestUtil.HashFunction) QueueEntry(build.buildfarm.v1test.QueueEntry) Any(com.google.protobuf.Any) CacheBuilder(com.google.common.cache.CacheBuilder) CACHE_CHECK(build.bazel.remote.execution.v2.ExecutionStage.Value.CACHE_CHECK) Mockito.any(org.mockito.Mockito.any) Mockito.eq(org.mockito.Mockito.eq) Mockito.mock(org.mockito.Mockito.mock) Directory(build.bazel.remote.execution.v2.Directory) MoreExecutors.listeningDecorator(com.google.common.util.concurrent.MoreExecutors.listeningDecorator) Iterables(com.google.common.collect.Iterables) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) Command(build.bazel.remote.execution.v2.Command) ToolDetails(build.bazel.remote.execution.v2.ToolDetails) Matchers(org.mockito.Matchers) Mock(org.mockito.Mock) MoreExecutors.newDirectExecutorService(com.google.common.util.concurrent.MoreExecutors.newDirectExecutorService) RunWith(org.junit.runner.RunWith) MISSING_COMMAND(build.buildfarm.instance.server.AbstractServerInstance.MISSING_COMMAND) CompletableFuture(java.util.concurrent.CompletableFuture) QueuedOperation(build.buildfarm.v1test.QueuedOperation) ResultsCachePolicy(build.bazel.remote.execution.v2.ResultsCachePolicy) Operation(com.google.longrunning.Operation) Function(java.util.function.Function) DigestUtil(build.buildfarm.common.DigestUtil) QUEUED(build.bazel.remote.execution.v2.ExecutionStage.Value.QUEUED) Answer(org.mockito.stubbing.Answer) Action(build.bazel.remote.execution.v2.Action) NullWrite(build.buildfarm.common.Write.NullWrite) ArgumentCaptor(org.mockito.ArgumentCaptor) ImmutableList(com.google.common.collect.ImmutableList) Watcher(build.buildfarm.common.Watcher) VIOLATION_TYPE_INVALID(build.buildfarm.common.Errors.VIOLATION_TYPE_INVALID) ActionResult(build.bazel.remote.execution.v2.ActionResult) AdditionalAnswers.answer(org.mockito.AdditionalAnswers.answer) StreamSupport(java.util.stream.StreamSupport) Code(com.google.rpc.Code) Before(org.junit.Before) Backplane(build.buildfarm.backplane.Backplane) Violation(com.google.rpc.PreconditionFailure.Violation) Futures.immediateFuture(com.google.common.util.concurrent.Futures.immediateFuture) Caffeine(com.github.benmanes.caffeine.cache.Caffeine) ExecutionPolicy(build.bazel.remote.execution.v2.ExecutionPolicy) Poller(build.buildfarm.common.Poller) PreconditionFailure(com.google.rpc.PreconditionFailure) Mockito.times(org.mockito.Mockito.times) IOException(java.io.IOException) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) JUnit4(org.junit.runners.JUnit4) Truth.assertThat(com.google.common.truth.Truth.assertThat) Mockito.verify(org.mockito.Mockito.verify) StatusRuntimeException(io.grpc.StatusRuntimeException) ExecutionException(java.util.concurrent.ExecutionException) Mockito.never(org.mockito.Mockito.never) Duration(com.google.protobuf.Duration) ExecuteResponse(build.bazel.remote.execution.v2.ExecuteResponse) SECONDS(java.util.concurrent.TimeUnit.SECONDS) CompletedOperationMetadata(build.buildfarm.v1test.CompletedOperationMetadata) Action(build.bazel.remote.execution.v2.Action) Digest(build.bazel.remote.execution.v2.Digest) ExecuteEntry(build.buildfarm.v1test.ExecuteEntry) NullWrite(build.buildfarm.common.Write.NullWrite) ActionKey(build.buildfarm.common.DigestUtil.ActionKey) IOException(java.io.IOException) QueuedOperation(build.buildfarm.v1test.QueuedOperation) Operation(com.google.longrunning.Operation) UUID(java.util.UUID) QueueEntry(build.buildfarm.v1test.QueueEntry) Poller(build.buildfarm.common.Poller) RequestMetadata(build.bazel.remote.execution.v2.RequestMetadata) Test(org.junit.Test)

Example 5 with ActionKey

use of build.buildfarm.common.DigestUtil.ActionKey in project bazel-buildfarm by bazelbuild.

the class ShardInstanceTest method actionResultWatcherDiscardsUncacheableResult.

@Test
public void actionResultWatcherDiscardsUncacheableResult() throws Exception {
    ActionKey actionKey = DigestUtil.asActionKey(Digest.newBuilder().setHash("test").build());
    Watcher mockWatcher = mock(Watcher.class);
    Watcher actionResultWatcher = instance.newActionResultWatcher(actionKey, mockWatcher);
    Action uncacheableAction = Action.newBuilder().setDoNotCache(true).build();
    Operation operation = Operation.newBuilder().setMetadata(Any.pack(uncacheableAction)).build();
    ExecuteResponse executeResponse = ExecuteResponse.newBuilder().setCachedResult(true).build();
    Operation completedOperation = Operation.newBuilder().setDone(true).setResponse(Any.pack(executeResponse)).build();
    actionResultWatcher.observe(operation);
    actionResultWatcher.observe(completedOperation);
    verify(mockWatcher, never()).observe(operation);
    ListenableFuture<ActionResult> resultFuture = instance.getActionResult(actionKey, RequestMetadata.getDefaultInstance());
    ActionResult result = resultFuture.get();
    assertThat(result).isNull();
    verify(mockWatcher, times(1)).observe(completedOperation);
}
Also used : Action(build.bazel.remote.execution.v2.Action) ActionResult(build.bazel.remote.execution.v2.ActionResult) Watcher(build.buildfarm.common.Watcher) ActionKey(build.buildfarm.common.DigestUtil.ActionKey) ExecuteResponse(build.bazel.remote.execution.v2.ExecuteResponse) QueuedOperation(build.buildfarm.v1test.QueuedOperation) Operation(com.google.longrunning.Operation) Test(org.junit.Test)

Aggregations

ActionKey (build.buildfarm.common.DigestUtil.ActionKey)13 ActionResult (build.bazel.remote.execution.v2.ActionResult)10 Test (org.junit.Test)10 QueuedOperation (build.buildfarm.v1test.QueuedOperation)8 Operation (com.google.longrunning.Operation)8 Watcher (build.buildfarm.common.Watcher)6 Digest (build.bazel.remote.execution.v2.Digest)5 ExecuteResponse (build.bazel.remote.execution.v2.ExecuteResponse)5 ExecuteOperationMetadata (build.bazel.remote.execution.v2.ExecuteOperationMetadata)4 RequestMetadata (build.bazel.remote.execution.v2.RequestMetadata)4 Poller (build.buildfarm.common.Poller)4 Instance (build.buildfarm.instance.Instance)4 ExecuteEntry (build.buildfarm.v1test.ExecuteEntry)4 ByteString (com.google.protobuf.ByteString)4 Action (build.bazel.remote.execution.v2.Action)3 QueueEntry (build.buildfarm.v1test.QueueEntry)3 ServerCallStreamObserver (io.grpc.stub.ServerCallStreamObserver)3 Command (build.bazel.remote.execution.v2.Command)2 Directory (build.bazel.remote.execution.v2.Directory)2 DirectoryNode (build.bazel.remote.execution.v2.DirectoryNode)2