Java Code Examples for rx.observers.AssertableSubscriber#assertValueCount()
The following examples show how to use
rx.observers.AssertableSubscriber#assertValueCount() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DefaultReconciliationFrameworkTest.java From titus-control-plane with Apache License 2.0 | 6 votes |
@Test public void testBootstrapEngineInitialization() { InternalReconciliationEngine<SimpleReconcilerEvent> bootstrapEngine = mock(InternalReconciliationEngine.class); PublishSubject<SimpleReconcilerEvent> eventSubject = PublishSubject.create(); when(bootstrapEngine.events()).thenReturn(eventSubject); when(bootstrapEngine.triggerActions()).thenReturn(true); when(bootstrapEngine.getReferenceView()).thenReturn(EntityHolder.newRoot("myRoot1", "myEntity1")); DefaultReconciliationFramework<SimpleReconcilerEvent> framework = new DefaultReconciliationFramework<>( Collections.singletonList(bootstrapEngine), engineFactory, IDLE_TIMEOUT_MS, ACTIVE_TIMEOUT_MS, indexComparators, new DefaultRegistry(), Optional.of(testScheduler) ); framework.start(); AssertableSubscriber<SimpleReconcilerEvent> eventSubscriber = framework.events().test(); eventSubject.onNext(new SimpleReconcilerEvent(EventType.Changed, "test", Optional.empty())); eventSubscriber.assertValueCount(1); }
Example 2
Source File: AwsObservableExtTest.java From titus-control-plane with Apache License 2.0 | 6 votes |
@Test public void asyncActionSingle() throws Exception { AmazonWebServiceRequest someRequest = AmazonWebServiceRequest.NOOP; final MockAsyncClient<AmazonWebServiceRequest, String> client = new MockAsyncClient<>(someRequest, "some response"); Single<String> single = AwsObservableExt.asyncActionSingle(supplier -> client.someAsyncOperation(supplier.handler())); TestScheduler testScheduler = Schedulers.test(); final AssertableSubscriber<String> subscriber = single.subscribeOn(testScheduler).test(); testScheduler.triggerActions(); subscriber.assertNoValues(); subscriber.assertNotCompleted(); client.run(); testScheduler.triggerActions(); subscriber.assertValueCount(1); subscriber.assertValue("some response"); subscriber.assertCompleted(); }
Example 3
Source File: AggregatingHealthServiceTest.java From titus-control-plane with Apache License 2.0 | 6 votes |
@Test public void allCellsFailing() { cellOne.getServiceRegistry().addService(new CellWithHealthStatus(failing("one"))); cellTwo.getServiceRegistry().addService(new CellWithHealthStatus(failing("two"))); AssertableSubscriber<HealthCheckResponse> subscriber = service.check(HealthCheckRequest.newBuilder().build()).test(); subscriber.awaitTerminalEvent(10, TimeUnit.SECONDS); subscriber.assertNoErrors(); subscriber.assertValueCount(1); HealthCheckResponse response = subscriber.getOnNextEvents().get(0); assertThat(response.getStatus()).isEqualTo(NOT_SERVING); assertThat(response.getDetailsCount()).isEqualTo(2); assertThat(response.getDetails(0).hasDetails()).isTrue(); assertThat(response.getDetails(1).hasDetails()).isTrue(); Set<String> cellsSeen = response.getDetailsList().stream() .map(s -> s.getDetails().getCell()) .collect(Collectors.toSet()); assertThat(cellsSeen).contains("one", "two"); }
Example 4
Source File: AggregatingHealthServiceTest.java From titus-control-plane with Apache License 2.0 | 6 votes |
@Test public void grpcErrors() { cellOne.getServiceRegistry().addService(new CellWithHealthStatus(ok("one"))); cellTwo.getServiceRegistry().addService(new HealthGrpc.HealthImplBase() { @Override public void check(HealthCheckRequest request, StreamObserver<HealthCheckResponse> responseObserver) { responseObserver.onError(Status.DEADLINE_EXCEEDED.asRuntimeException()); } }); AssertableSubscriber<HealthCheckResponse> subscriber = service.check(HealthCheckRequest.newBuilder().build()).test(); subscriber.awaitTerminalEvent(10, TimeUnit.SECONDS); subscriber.assertNoErrors(); subscriber.assertValueCount(1); HealthCheckResponse response = subscriber.getOnNextEvents().get(0); assertThat(response.getStatus()).isEqualTo(NOT_SERVING); assertThat(response.getDetailsCount()).isEqualTo(2); List<ServerStatus> errors = response.getDetailsList().stream() .filter(ServerStatus::hasError) .collect(Collectors.toList()); assertThat(errors).hasSize(1); assertThat(errors.get(0).getError().getCell()).isEqualTo("two"); assertThat(errors.get(0).getError().getErrorCode()).isEqualTo(DEADLINE_EXCEEDED.toString()); }
Example 5
Source File: AggregatingHealthServiceTest.java From titus-control-plane with Apache License 2.0 | 6 votes |
@Test public void oneCellFailing() { cellOne.getServiceRegistry().addService(new CellWithHealthStatus(ok("one"))); cellTwo.getServiceRegistry().addService(new CellWithHealthStatus(failing("two"))); AssertableSubscriber<HealthCheckResponse> subscriber = service.check(HealthCheckRequest.newBuilder().build()).test(); subscriber.awaitTerminalEvent(10, TimeUnit.SECONDS); subscriber.assertNoErrors(); subscriber.assertValueCount(1); HealthCheckResponse response = subscriber.getOnNextEvents().get(0); assertThat(response.getStatus()).isEqualTo(NOT_SERVING); assertThat(response.getDetailsCount()).isEqualTo(2); assertThat(response.getDetails(0).hasDetails()).isTrue(); assertThat(response.getDetails(1).hasDetails()).isTrue(); Set<String> cellsSeen = response.getDetailsList().stream() .map(s -> s.getDetails().getCell()) .collect(Collectors.toSet()); assertThat(cellsSeen).contains("one", "two"); }
Example 6
Source File: AggregatingHealthServiceTest.java From titus-control-plane with Apache License 2.0 | 6 votes |
@Test public void allCellsOK() { cellOne.getServiceRegistry().addService(new CellWithHealthStatus(ok("one"))); cellTwo.getServiceRegistry().addService(new CellWithHealthStatus(ok("two"))); AssertableSubscriber<HealthCheckResponse> subscriber = service.check(HealthCheckRequest.newBuilder().build()).test(); subscriber.awaitTerminalEvent(10, TimeUnit.SECONDS); subscriber.assertNoErrors(); subscriber.assertValueCount(1); HealthCheckResponse response = subscriber.getOnNextEvents().get(0); assertThat(response.getStatus()).isEqualTo(SERVING); assertThat(response.getDetailsCount()).isEqualTo(2); assertThat(response.getDetails(0).hasDetails()).isTrue(); assertThat(response.getDetails(1).hasDetails()).isTrue(); Set<String> cellsSeen = response.getDetailsList().stream() .map(s -> s.getDetails().getCell()) .collect(Collectors.toSet()); assertThat(cellsSeen).contains("one", "two"); }
Example 7
Source File: AggregatingJobServiceGatewayTest.java From titus-control-plane with Apache License 2.0 | 5 votes |
@Test public void findTaskWithFailingCell() { Random random = new Random(); List<Task> cellOneSnapshot = new ArrayList<>(dataGenerator.newServiceJobWithTasks()); cellOne.getServiceRegistry().addService(new CellWithFixedTasksService(cellOneSnapshot)); cellTwo.getServiceRegistry().addService(new CellWithFailingJobManagementService(DEADLINE_EXCEEDED)); Task expected = withStackName(cellOneSnapshot.get(random.nextInt(cellOneSnapshot.size()))); AssertableSubscriber<Task> testSubscriber = service.findTask(expected.getId(), UNDEFINED_CALL_METADATA).test(); testSubscriber.awaitTerminalEvent(1, TimeUnit.SECONDS); testSubscriber.assertNoErrors(); testSubscriber.assertValueCount(1); testSubscriber.assertValue(expected); }
Example 8
Source File: AggregatingLoadBalancerServiceTest.java From titus-control-plane with Apache License 2.0 | 5 votes |
@Test public void getJobLoadBalancersNoAssociations() { cellOne.getServiceRegistry().addService(new CellWithLoadBalancers(Collections.emptyList())); cellTwo.getServiceRegistry().addService(new CellWithLoadBalancers(Collections.emptyList())); final AssertableSubscriber<GetJobLoadBalancersResult> resultSubscriber = service.getLoadBalancers( JobId.newBuilder().setId(JOB_1).build(), JUNIT_REST_CALL_METADATA ).test(); resultSubscriber.awaitTerminalEvent(1, TimeUnit.SECONDS); resultSubscriber.assertNoErrors().assertCompleted(); resultSubscriber.assertValueCount(1); assertThat(resultSubscriber.getOnNextEvents().get(0).getLoadBalancersCount()).isZero(); }
Example 9
Source File: AggregatingHealthServiceTest.java From titus-control-plane with Apache License 2.0 | 5 votes |
@Test public void singleCell() { reset(connector); when(connector.getChannels()).thenReturn(Collections.singletonMap( new Cell("one", "1"), cellOne.getChannel() )); when(connector.getChannelForCell(any())).thenReturn(Optional.of(cellOne.getChannel())); HealthCheckResponse one = HealthCheckResponse.newBuilder() .setStatus(NOT_SERVING) .addDetails(ServerStatus.newBuilder() .setDetails(Details.newBuilder() .setCell("one") .setLeader(false) .setActive(true) .setUptime(Durations.fromMillis(clock.wallTime())) .build()) .build()) .build(); cellOne.getServiceRegistry().addService(new CellWithHealthStatus(one)); AssertableSubscriber<HealthCheckResponse> subscriber = service.check(HealthCheckRequest.newBuilder().build()).test(); subscriber.awaitTerminalEvent(10, TimeUnit.SECONDS); subscriber.assertNoErrors(); subscriber.assertValueCount(1); HealthCheckResponse response = subscriber.getOnNextEvents().get(0); assertThat(response.getStatus()).isEqualTo(NOT_SERVING); assertThat(response.getDetailsCount()).isEqualTo(1); assertThat(response.getDetails(0).hasDetails()).isTrue(); assertThat(response.getDetails(0).getDetails().getCell()).isEqualTo("one"); assertThat(response.getDetails(0).getDetails().getLeader()).isFalse(); }
Example 10
Source File: AggregatingJobServiceGatewayWithSingleCellTest.java From titus-control-plane with Apache License 2.0 | 5 votes |
@Test public void findJobsAddsStackName() { Random random = new Random(); final List<Job> cellSnapshot = new ArrayList<>(); for (int i = 0; i < 5; i++) { cellSnapshot.addAll(dataGenerator.newBatchJobs(random.nextInt(10), GrpcJobManagementModelConverters::toGrpcJob)); cellSnapshot.addAll(dataGenerator.newServiceJobs(random.nextInt(10), GrpcJobManagementModelConverters::toGrpcJob)); clock.advanceTime(1, TimeUnit.MINUTES); } cell.getServiceRegistry().addService(new CellWithFixedJobsService(cellSnapshot, PublishSubject.create())); JobQuery query = JobQuery.newBuilder() .setPage(toGrpcPage(Page.unlimited())) .build(); final AssertableSubscriber<JobQueryResult> testSubscriber = service.findJobs(query, UNDEFINED_CALL_METADATA).test(); testSubscriber.awaitTerminalEvent(1, TimeUnit.SECONDS); testSubscriber.assertNoErrors().assertCompleted(); testSubscriber.assertValueCount(1); final List<JobQueryResult> results = testSubscriber.getOnNextEvents(); assertThat(results).hasSize(1); // expect stackName to have changed List<Job> expected = cellSnapshot.stream() .sorted(JobManagerCursors.jobCursorOrderComparator()) .map(this::withStackName) .collect(Collectors.toList()); assertThat(results.get(0).getItemsList()).containsExactlyElementsOf(expected); }
Example 11
Source File: AggregatingJobServiceGatewayTest.java From titus-control-plane with Apache License 2.0 | 5 votes |
@Test public void findTask() { Random random = new Random(); List<Task> cellOneSnapshot = new ArrayList<>(dataGenerator.newServiceJobWithTasks()); cellOne.getServiceRegistry().addService(new CellWithFixedTasksService(cellOneSnapshot)); cellTwo.getServiceRegistry().addService(new CellWithFixedTasksService(Collections.emptyList())); Task expected = withStackName(cellOneSnapshot.get(random.nextInt(cellOneSnapshot.size()))); AssertableSubscriber<Task> testSubscriber = service.findTask(expected.getId(), UNDEFINED_CALL_METADATA).test(); testSubscriber.awaitTerminalEvent(1, TimeUnit.SECONDS); testSubscriber.assertNoErrors(); testSubscriber.assertValueCount(1); testSubscriber.assertValue(expected); }
Example 12
Source File: AggregatingJobServiceGatewayTest.java From titus-control-plane with Apache License 2.0 | 5 votes |
@Test public void findJobWithFailingCell() { Random random = new Random(); List<Job> cellOneSnapshot = new ArrayList<>(dataGenerator.newServiceJobs(10, GrpcJobManagementModelConverters::toGrpcJob)); cellOne.getServiceRegistry().addService(new CellWithFixedJobsService(cellOneSnapshot, cellOneUpdates.serialize())); cellTwo.getServiceRegistry().addService(new CellWithFailingJobManagementService()); Job expected = withStackName(cellOneSnapshot.get(random.nextInt(cellOneSnapshot.size()))); AssertableSubscriber<Job> testSubscriber = service.findJob(expected.getId(), UNDEFINED_CALL_METADATA).test(); testSubscriber.awaitTerminalEvent(1, TimeUnit.SECONDS); testSubscriber.assertNoErrors(); testSubscriber.assertValueCount(1); testSubscriber.assertValue(expected); }
Example 13
Source File: AggregatingJobServiceGatewayTest.java From titus-control-plane with Apache License 2.0 | 5 votes |
@Test public void findJob() { Random random = new Random(); List<Job> cellOneSnapshot = new ArrayList<>(dataGenerator.newServiceJobs(10, GrpcJobManagementModelConverters::toGrpcJob)); cellOne.getServiceRegistry().addService(new CellWithFixedJobsService(cellOneSnapshot, cellOneUpdates.serialize())); cellTwo.getServiceRegistry().addService(new CellWithFixedJobsService(Collections.emptyList(), cellTwoUpdates.serialize())); Job expected = withStackName(cellOneSnapshot.get(random.nextInt(cellOneSnapshot.size()))); AssertableSubscriber<Job> testSubscriber = service.findJob(expected.getId(), UNDEFINED_CALL_METADATA).test(); testSubscriber.awaitTerminalEvent(1, TimeUnit.SECONDS); testSubscriber.assertNoErrors(); testSubscriber.assertValueCount(1); testSubscriber.assertValue(expected); }
Example 14
Source File: AggregatingJobServiceGatewayTest.java From titus-control-plane with Apache License 2.0 | 5 votes |
@Test public void findJobsEmptyPage() { Random random = new Random(); final List<Job> cellOneSnapshot = new ArrayList<>(); final List<Job> cellTwoSnapshot = new ArrayList<>(); for (int i = 0; i < 5; i++) { Iterables.addAll(cellOneSnapshot, Iterables.concat( dataGenerator.newBatchJobs(random.nextInt(10), GrpcJobManagementModelConverters::toGrpcJob), dataGenerator.newServiceJobs(random.nextInt(10), GrpcJobManagementModelConverters::toGrpcJob) )); Iterables.addAll(cellTwoSnapshot, Iterables.concat( dataGenerator.newBatchJobs(random.nextInt(10), GrpcJobManagementModelConverters::toGrpcJob), dataGenerator.newServiceJobs(random.nextInt(10), GrpcJobManagementModelConverters::toGrpcJob) )); clock.advanceTime(1, TimeUnit.MINUTES); } cellOne.getServiceRegistry().addService(new CellWithFixedJobsService(cellOneSnapshot, cellOneUpdates.serialize())); cellTwo.getServiceRegistry().addService(new CellWithFixedJobsService(cellTwoSnapshot, cellTwoUpdates.serialize())); JobQuery query = JobQuery.newBuilder() .setPage(toGrpcPage(Page.empty())) .build(); final AssertableSubscriber<JobQueryResult> testSubscriber = service.findJobs(query, UNDEFINED_CALL_METADATA).test(); testSubscriber.awaitTerminalEvent(1, TimeUnit.SECONDS); testSubscriber.assertNoErrors().assertCompleted(); testSubscriber.assertValueCount(1); final List<JobQueryResult> results = testSubscriber.getOnNextEvents(); assertThat(results).hasSize(1); assertThat(results.get(0).getItemsList()).isEmpty(); assertThat(results.get(0).getPagination().getHasMore()).isFalse(); }
Example 15
Source File: AggregatingJobServiceGatewayWithSingleCellTest.java From titus-control-plane with Apache License 2.0 | 5 votes |
@Test public void findTasksMergesAllCellsIntoSingleResult() { List<Task> cellSnapshot = new ArrayList<>(); // 10 jobs on each cell with TASKS_IN_GENERATED_JOBS tasks each for (int i = 0; i < 5; i++) { cellSnapshot.addAll(dataGenerator.newBatchJobWithTasks()); cellSnapshot.addAll(dataGenerator.newServiceJobWithTasks()); clock.advanceTime(1, TimeUnit.MINUTES); } cell.getServiceRegistry().addService(new CellWithFixedTasksService(cellSnapshot)); TaskQuery query = TaskQuery.newBuilder() .setPage(toGrpcPage(Page.unlimited())) .build(); final AssertableSubscriber<TaskQueryResult> testSubscriber = service.findTasks(query, UNDEFINED_CALL_METADATA).test(); testSubscriber.awaitTerminalEvent(1, TimeUnit.SECONDS); testSubscriber.assertNoErrors().assertCompleted(); testSubscriber.assertValueCount(1); final List<TaskQueryResult> results = testSubscriber.getOnNextEvents(); assertThat(results).hasSize(1); // expect stackName to have changed List<Task> expected = cellSnapshot.stream() .sorted(JobManagerCursors.taskCursorOrderComparator()) .map(this::withStackName) .collect(Collectors.toList()); assertThat(results.get(0).getItemsList()).containsExactlyElementsOf(expected); }
Example 16
Source File: AggregatingJobServiceGatewayTest.java From titus-control-plane with Apache License 2.0 | 4 votes |
@Test public void findJobsMergesAllCellsIntoSingleResult() { Random random = new Random(); final List<Job> cellOneSnapshot = new ArrayList<>(); final List<Job> cellTwoSnapshot = new ArrayList<>(); for (int i = 0; i < 5; i++) { cellOneSnapshot.addAll( dataGenerator.newBatchJobs(random.nextInt(10), GrpcJobManagementModelConverters::toGrpcJob) ); cellTwoSnapshot.addAll( dataGenerator.newBatchJobs(random.nextInt(10), GrpcJobManagementModelConverters::toGrpcJob) ); cellOneSnapshot.addAll( dataGenerator.newServiceJobs(random.nextInt(10), GrpcJobManagementModelConverters::toGrpcJob) ); cellTwoSnapshot.addAll( dataGenerator.newServiceJobs(random.nextInt(10), GrpcJobManagementModelConverters::toGrpcJob) ); clock.advanceTime(1, TimeUnit.MINUTES); } cellOne.getServiceRegistry().addService(new CellWithFixedJobsService(cellOneSnapshot, cellOneUpdates.serialize())); cellTwo.getServiceRegistry().addService(new CellWithFixedJobsService(cellTwoSnapshot, cellTwoUpdates.serialize())); JobQuery query = JobQuery.newBuilder() .setPage(toGrpcPage(Page.unlimited())) .build(); final AssertableSubscriber<JobQueryResult> testSubscriber = service.findJobs(query, UNDEFINED_CALL_METADATA).test(); testSubscriber.awaitTerminalEvent(1, TimeUnit.SECONDS); testSubscriber.assertNoErrors().assertCompleted(); testSubscriber.assertValueCount(1); final List<JobQueryResult> results = testSubscriber.getOnNextEvents(); assertThat(results).hasSize(1); // expect stackName to have changed List<Job> expected = Stream.concat(cellOneSnapshot.stream(), cellTwoSnapshot.stream()) .sorted(JobManagerCursors.jobCursorOrderComparator()) .map(this::withStackName) .collect(Collectors.toList()); assertThat(results.get(0).getItemsList()).containsExactlyElementsOf(expected); }
Example 17
Source File: ServiceTests.java From titus-control-plane with Apache License 2.0 | 4 votes |
/** * @param <Q> query type * @param <R> result type * @param <T> type of items in the result */ static <Q, R, T> List<T> walkAllPages(int pageWalkSize, Function<Q, Observable<R>> pageFetcher, Function<com.netflix.titus.grpc.protogen.Page, Q> queryFactory, Function<R, com.netflix.titus.grpc.protogen.Pagination> paginationGetter, Function<R, List<T>> itemsGetter) { List<T> allItems = new ArrayList<>(); Optional<R> lastResult = Optional.empty(); int currentCursorPosition = -1; int currentPageNumber = 0; while (lastResult.map(r -> paginationGetter.apply(r).getHasMore()).orElse(true)) { com.netflix.titus.grpc.protogen.Page.Builder builder = com.netflix.titus.grpc.protogen.Page.newBuilder().setPageSize(pageWalkSize); if (lastResult.isPresent()) { builder.setCursor(paginationGetter.apply(lastResult.get()).getCursor()); } else { builder.setPageNumber(0); } Q query = queryFactory.apply(builder.build()); AssertableSubscriber<R> testSubscriber = pageFetcher.apply(query).test(); testSubscriber.awaitTerminalEvent(1, TimeUnit.SECONDS); testSubscriber.assertNoErrors().assertCompleted(); testSubscriber.assertValueCount(1); final List<R> results = testSubscriber.getOnNextEvents(); assertThat(results).hasSize(1); R result = results.get(0); List<T> items = itemsGetter.apply(result); com.netflix.titus.grpc.protogen.Pagination pagination = paginationGetter.apply(result); if (pagination.getHasMore()) { assertThat(items).hasSize(pageWalkSize); } currentCursorPosition += items.size(); if (pagination.getTotalItems() > 0) { assertThat(pagination.getCursorPosition()).isEqualTo(currentCursorPosition); } else { assertThat(pagination.getCursorPosition()).isEqualTo(0); } assertThat(pagination.getCurrentPage().getPageNumber()).isEqualTo(currentPageNumber++); allItems.addAll(items); lastResult = Optional.of(result); testSubscriber.unsubscribe(); } return allItems; }