Search in sources :

Example 1 with KeepaliveWatcher

use of build.buildfarm.server.ExecutionService.KeepaliveWatcher 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);
}
Also used : ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) KeepaliveWatcher(build.buildfarm.server.ExecutionService.KeepaliveWatcher) LogMetricsPublisher(build.buildfarm.metrics.log.LogMetricsPublisher) Operation(com.google.longrunning.Operation) RequestMetadata(build.bazel.remote.execution.v2.RequestMetadata) Test(org.junit.Test)

Aggregations

RequestMetadata (build.bazel.remote.execution.v2.RequestMetadata)1 LogMetricsPublisher (build.buildfarm.metrics.log.LogMetricsPublisher)1 KeepaliveWatcher (build.buildfarm.server.ExecutionService.KeepaliveWatcher)1 Operation (com.google.longrunning.Operation)1 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)1 Test (org.junit.Test)1