AggregatingJobServiceGateway implements JobServiceGateway { @Override public Observable<TaskQueryResult> findTasks(TaskQuery request, CallMetadata callMetadata) { if (request.getPage().getPageSize() <= 0) { return Observable.just(TaskQueryResult.newBuilder() .setPagination(emptyGrpcPagination(request.getPage())) .build()); } Set<String> fieldsFilter = Collections.emptySet(); if (request.getFieldsCount() > 0) { fieldsFilter = new HashSet<>(request.getFieldsList()); fieldsFilter.addAll(TASK_MINIMUM_FIELD_SET); request = request.toBuilder() .addAllFields(fieldsFilter) .addAllFields(TASK_FEDERATION_MINIMUM_FIELD_SET) .build(); } if (StringExt.isNotEmpty(request.getPage().getCursor()) || request.getPage().getPageNumber() == 0) { return findTasksWithCursorPagination(request, fieldsFilter, callMetadata); } return Observable.error(TitusServiceException.invalidArgument("pageNumbers are not supported, please use cursors")); } @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 findTasksWithFieldFiltering() { Pair<List<Task>, List<Task>> cellSnapshots = generateTestJobsWithTasks(); List<Task> allTasks = walkAllPages( 6, request -> service.findTasks(request, UNDEFINED_CALL_METADATA), page -> TaskQuery.newBuilder() .setPage(page) .addFields("jobId") .build(), TaskQueryResult::getPagination, TaskQueryResult::getItemsList ); assertThat(allTasks).hasSize(cellSnapshots.getLeft().size() + cellSnapshots.getRight().size()); for (Task task : allTasks) { assertThat(task.getId()).isNotEmpty(); assertThat(task.getJobId()).isNotEmpty(); assertThat(task.getStatus().getReasonMessage()).isEmpty(); assertThat(task.getStatusHistoryList()).isEmpty(); } }