@Test public void getJobLoadBalancersWithTwoFailingCell() { cellOne.getServiceRegistry().addService(new CellWithFailingLoadBalancers(Status.NOT_FOUND)); cellTwo.getServiceRegistry().addService(new CellWithFailingLoadBalancers(Status.INTERNAL)); final AssertableSubscriber<GetJobLoadBalancersResult> resultSubscriber = service.getLoadBalancers( JobId.newBuilder().setId(JOB_1).build(), JUNIT_REST_CALL_METADATA ).test(); resultSubscriber.awaitTerminalEvent(1, TimeUnit.SECONDS); resultSubscriber.assertNoValues(); final List<Throwable> onErrorEvents = resultSubscriber.getOnErrorEvents(); assertThat(onErrorEvents).hasSize(1); assertThat(Status.fromThrowable(onErrorEvents.get(0))).isEqualTo(Status.INTERNAL); }
@Override public Observable<GetJobLoadBalancersResult> getLoadBalancers(JobId jobId, CallMetadata callMetadata) { ClientCall<GetJobLoadBalancersResult> getLoadBalancersForJob = (client, responseObserver) -> wrap(client, callMetadata).getJobLoadBalancers(jobId, responseObserver); return aggregatingClient.callExpectingErrors(LoadBalancerServiceGrpc::newStub, getLoadBalancersForJob) .filter(response -> response.getResult().hasError() || response.getResult().getValue().getLoadBalancersCount() > 0) .reduce(ResponseMerger.emptyResponseMarker(), ResponseMerger.singleValue()) .filter(ResponseMerger::isNotEmptyResponseMarker) .flatMap(response -> response.getResult().map(Observable::just).onErrorGet(Observable::error)) .switchIfEmpty(Observable.just(GetJobLoadBalancersResult.newBuilder().setJobId(jobId.getId()).build())); }
AggregatingLoadbalancerService implements LoadBalancerService { @Override public Observable<GetJobLoadBalancersResult> getLoadBalancers(JobId jobId, CallMetadata callMetadata) { ClientCall<GetJobLoadBalancersResult> getLoadBalancersForJob = (client, responseObserver) -> wrap(client, callMetadata).getJobLoadBalancers(jobId, responseObserver); return aggregatingClient.callExpectingErrors(LoadBalancerServiceGrpc::newStub, getLoadBalancersForJob) .filter(response -> response.getResult().hasError() || response.getResult().getValue().getLoadBalancersCount() > 0) .reduce(ResponseMerger.emptyResponseMarker(), ResponseMerger.singleValue()) .filter(ResponseMerger::isNotEmptyResponseMarker) .flatMap(response -> response.getResult().map(Observable::just).onErrorGet(Observable::error)) .switchIfEmpty(Observable.just(GetJobLoadBalancersResult.newBuilder().setJobId(jobId.getId()).build())); } }
AggregatingLoadbalancerService implements LoadBalancerService { @Override public Observable<GetJobLoadBalancersResult> getLoadBalancers(JobId jobId, CallMetadata callMetadata) { ClientCall<GetJobLoadBalancersResult> getLoadBalancersForJob = (client, responseObserver) -> wrap(client, callMetadata).getJobLoadBalancers(jobId, responseObserver); return aggregatingClient.callExpectingErrors(LoadBalancerServiceGrpc::newStub, getLoadBalancersForJob) .filter(response -> response.getResult().hasError() || response.getResult().getValue().getLoadBalancersCount() > 0) .reduce(ResponseMerger.emptyResponseMarker(), ResponseMerger.singleValue()) .filter(ResponseMerger::isNotEmptyResponseMarker) .flatMap(response -> response.getResult().map(Observable::just).onErrorGet(Observable::error)) .switchIfEmpty(Observable.just(GetJobLoadBalancersResult.newBuilder().setJobId(jobId.getId()).build())); } @Inject  AggregatingLoadbalancerService(CellConnector connector,
                                          CallMetadataResolver callMetadataResolver,
                                          GrpcConfiguration grpcConfiguration,
                                          AggregatingCellClient aggregatingClient,
                                          AggregatingJobManagementServiceHelper jobManagementServiceHelper); }
AggregatingLoadbalancerService implements LoadBalancerService { @Override public Observable<GetJobLoadBalancersResult> getLoadBalancers(JobId jobId, CallMetadata callMetadata) { ClientCall<GetJobLoadBalancersResult> getLoadBalancersForJob = (client, responseObserver) -> wrap(client, callMetadata).getJobLoadBalancers(jobId, responseObserver); return aggregatingClient.callExpectingErrors(LoadBalancerServiceGrpc::newStub, getLoadBalancersForJob) .filter(response -> response.getResult().hasError() || response.getResult().getValue().getLoadBalancersCount() > 0) .reduce(ResponseMerger.emptyResponseMarker(), ResponseMerger.singleValue()) .filter(ResponseMerger::isNotEmptyResponseMarker) .flatMap(response -> response.getResult().map(Observable::just).onErrorGet(Observable::error)) .switchIfEmpty(Observable.just(GetJobLoadBalancersResult.newBuilder().setJobId(jobId.getId()).build())); } @Inject  AggregatingLoadbalancerService(CellConnector connector,
                                          CallMetadataResolver callMetadataResolver,
                                          GrpcConfiguration grpcConfiguration,
                                          AggregatingCellClient aggregatingClient,
                                          AggregatingJobManagementServiceHelper jobManagementServiceHelper); @Override Observable<GetAllLoadBalancersResult> getAllLoadBalancers(GetAllLoadBalancersRequest request, CallMetadata callMetadata); @Override Observable<GetJobLoadBalancersResult> getLoadBalancers(JobId jobId, CallMetadata callMetadata); @Override Completable addLoadBalancer(AddLoadBalancerRequest request, CallMetadata callMetadata); @Override Completable removeLoadBalancer(RemoveLoadBalancerRequest removeLoadBalancerRequest, CallMetadata callMetadata); }
AggregatingLoadbalancerService implements LoadBalancerService { @Override public Observable<GetJobLoadBalancersResult> getLoadBalancers(JobId jobId, CallMetadata callMetadata) { ClientCall<GetJobLoadBalancersResult> getLoadBalancersForJob = (client, responseObserver) -> wrap(client, callMetadata).getJobLoadBalancers(jobId, responseObserver); return aggregatingClient.callExpectingErrors(LoadBalancerServiceGrpc::newStub, getLoadBalancersForJob) .filter(response -> response.getResult().hasError() || response.getResult().getValue().getLoadBalancersCount() > 0) .reduce(ResponseMerger.emptyResponseMarker(), ResponseMerger.singleValue()) .filter(ResponseMerger::isNotEmptyResponseMarker) .flatMap(response -> response.getResult().map(Observable::just).onErrorGet(Observable::error)) .switchIfEmpty(Observable.just(GetJobLoadBalancersResult.newBuilder().setJobId(jobId.getId()).build())); } @Inject  AggregatingLoadbalancerService(CellConnector connector,
                                          CallMetadataResolver callMetadataResolver,
                                          GrpcConfiguration grpcConfiguration,
                                          AggregatingCellClient aggregatingClient,
                                          AggregatingJobManagementServiceHelper jobManagementServiceHelper); @Override Observable<GetAllLoadBalancersResult> getAllLoadBalancers(GetAllLoadBalancersRequest request, CallMetadata callMetadata); @Override Observable<GetJobLoadBalancersResult> getLoadBalancers(JobId jobId, CallMetadata callMetadata); @Override Completable addLoadBalancer(AddLoadBalancerRequest request, CallMetadata callMetadata); @Override Completable removeLoadBalancer(RemoveLoadBalancerRequest removeLoadBalancerRequest, CallMetadata callMetadata);  }