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);
}
Aggregations