AggregatingJobServiceGateway implements JobServiceGateway { @Override public Completable killTask(TaskKillRequest request, CallMetadata callMetadata) { Observable<Empty> result = findTaskInAllCells(request.getTaskId(), callMetadata) .flatMap(response -> singleCellCall(response.getCell(), (client, streamObserver) -> client.killTask(request, streamObserver), callMetadata) ); return result.toCompletable(); } @Inject  AggregatingJobServiceGateway(GrpcConfiguration grpcConfiguration,
                                        TitusFederationConfiguration federationConfiguration,
                                        CellConnector connector,
                                        CellRouter router,
                                        AggregatingCellClient aggregatingClient,
                                        AggregatingJobManagementServiceHelper jobManagementServiceHelper); @Override Observable<String> createJob(JobDescriptor jobDescriptor, CallMetadata callMetadata); @Override Completable updateJobCapacity(JobCapacityUpdate request, CallMetadata callMetadata); @Override Completable updateJobCapacityWithOptionalAttributes(JobCapacityUpdateWithOptionalAttributes request, CallMetadata callMetadata); @Override Completable updateJobProcesses(JobProcessesUpdate request, CallMetadata callMetadata); @Override Completable updateJobStatus(JobStatusUpdate request, CallMetadata callMetadata); @Override Mono<Void> updateJobDisruptionBudget(JobDisruptionBudgetUpdate request, CallMetadata callMetadata); @Override Mono<Void> updateJobAttributes(JobAttributesUpdate request, CallMetadata callMetadata); @Override Mono<Void> deleteJobAttributes(JobAttributesDeleteRequest request, CallMetadata callMetadata); @Override Observable<Job> findJob(String jobId, CallMetadata callMetadata); @Override Observable<JobQueryResult> findJobs(JobQuery request, CallMetadata callMetadata); @Override Observable<JobChangeNotification> observeJob(String jobId, CallMetadata callMetadata); @Override Observable<JobChangeNotification> observeJobs(ObserveJobsQuery query, CallMetadata callMetadata); @Override Completable killJob(String jobId, CallMetadata callMetadata); @Override Observable<Task> findTask(String taskId, CallMetadata callMetadata); @Override Observable<TaskQueryResult> findTasks(TaskQuery request, CallMetadata callMetadata); @Override Completable killTask(TaskKillRequest request, CallMetadata callMetadata); @Override Completable updateTaskAttributes(TaskAttributesUpdate attributesUpdate, CallMetadata callMetadata); @Override Completable deleteTaskAttributes(TaskAttributesDeleteRequest deleteRequest, CallMetadata callMetadata); @Override Completable moveTask(TaskMoveRequest taskMoveRequest, CallMetadata callMetadata);  }
@Test public void killTask() { Random random = new Random(); List<Task> cellOneSnapshot = new ArrayList<>(dataGenerator.newServiceJobWithTasks()); List<Task> cellTwoSnapshot = new ArrayList<>(dataGenerator.newBatchJobWithTasks()); CellWithFixedTasksService cellOneService = new CellWithFixedTasksService(cellOneSnapshot); CellWithFixedTasksService cellTwoService = new CellWithFixedTasksService(cellTwoSnapshot); cellOne.getServiceRegistry().addService(cellOneService); cellTwo.getServiceRegistry().addService(cellTwoService); Task killInCellOne = cellOneSnapshot.get(random.nextInt(cellOneSnapshot.size())); Task killInCellTwo = cellTwoSnapshot.get(random.nextInt(cellTwoSnapshot.size())); assertThat(cellOneService.currentTasks()).containsKey(killInCellOne.getId()); assertThat(cellTwoService.currentTasks()).containsKey(killInCellTwo.getId()); TaskKillRequest cellOneRequest = TaskKillRequest.newBuilder() .setTaskId(killInCellOne.getId()) .setShrink(false) .build(); AssertableSubscriber<Void> testSubscriber = service.killTask(cellOneRequest, UNDEFINED_CALL_METADATA).test(); testSubscriber.awaitTerminalEvent(1, TimeUnit.SECONDS); testSubscriber.assertNoErrors(); testSubscriber.assertNoValues(); testSubscriber.assertCompleted(); assertThat(cellOneService.currentTasks()).doesNotContainKey(killInCellOne.getId()); assertThat(cellTwoService.currentTasks()).doesNotContainKey(killInCellOne.getId()); testSubscriber.unsubscribe(); TaskKillRequest cellTwoRequest = TaskKillRequest.newBuilder() .setTaskId(killInCellTwo.getId()) .setShrink(false) .build(); testSubscriber = service.killTask(cellTwoRequest, UNDEFINED_CALL_METADATA).test(); testSubscriber.awaitTerminalEvent(1, TimeUnit.SECONDS); testSubscriber.assertNoErrors(); testSubscriber.assertNoValues(); testSubscriber.assertCompleted(); assertThat(cellOneService.currentTasks()).doesNotContainKey(killInCellTwo.getId()); assertThat(cellTwoService.currentTasks()).doesNotContainKey(killInCellTwo.getId()); testSubscriber.unsubscribe(); }