Java Code Examples for rx.observers.AssertableSubscriber#assertCompleted()
The following examples show how to use
rx.observers.AssertableSubscriber#assertCompleted() .
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: AwsObservableExtTest.java From titus-control-plane with Apache License 2.0 | 6 votes |
@Test public void asyncActionCompletable() throws Exception { AmazonWebServiceRequest someRequest = AmazonWebServiceRequest.NOOP; final MockAsyncClient<AmazonWebServiceRequest, String> client = new MockAsyncClient<>(someRequest, "some response"); final Completable completable = AwsObservableExt.asyncActionCompletable(factory -> client.someAsyncOperation(factory.handler( (req, resp) -> { assertEquals(someRequest, req); assertEquals("some response", resp); }, (t) -> { throw new IllegalStateException("Should never be here"); } ))); TestScheduler testScheduler = Schedulers.test(); final AssertableSubscriber<Void> subscriber = completable.subscribeOn(testScheduler).test(); testScheduler.triggerActions(); subscriber.assertNotCompleted(); client.run(); testScheduler.triggerActions(); subscriber.assertCompleted(); }
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: TransformersTest.java From mobius with Apache License 2.0 | 5 votes |
@Test public void consumerTransformerShouldPropagateCompletion() throws Exception { AssertableSubscriber<Object> subscriber = upstream.compose(Transformers.fromConsumer(consumer, scheduler)).test(); upstream.onNext("hi"); upstream.onCompleted(); scheduler.triggerActions(); subscriber.awaitTerminalEvent(1, TimeUnit.SECONDS); subscriber.assertCompleted(); }
Example 4
Source File: RxConnectablesTest.java From mobius with Apache License 2.0 | 5 votes |
@Test public void shouldPropagateCompletion() throws Exception { AssertableSubscriber<Integer> subscriber = input.compose(RxConnectables.toTransformer(connectable)).test(); input.onNext("hi"); input.onCompleted(); subscriber.awaitTerminalEvent(1, TimeUnit.SECONDS); subscriber.assertCompleted(); }
Example 5
Source File: AggregatingJobServiceGatewayTest.java From titus-control-plane with Apache License 2.0 | 5 votes |
@Test public void killJob() { Random random = new Random(); List<Job> cellOneSnapshot = new ArrayList<>(dataGenerator.newServiceJobs(12, GrpcJobManagementModelConverters::toGrpcJob)); List<Job> cellTwoSnapshot = new ArrayList<>(dataGenerator.newBatchJobs(7, GrpcJobManagementModelConverters::toGrpcJob)); CellWithFixedJobsService cellOneService = new CellWithFixedJobsService(cellOneSnapshot, cellOneUpdates.serialize()); CellWithFixedJobsService cellTwoService = new CellWithFixedJobsService(cellTwoSnapshot, cellTwoUpdates.serialize()); cellOne.getServiceRegistry().addService(cellOneService); cellTwo.getServiceRegistry().addService(cellTwoService); Job killInCellOne = cellOneSnapshot.get(random.nextInt(cellOneSnapshot.size())); Job killInCellTwo = cellTwoSnapshot.get(random.nextInt(cellTwoSnapshot.size())); assertThat(cellOneService.currentJobs()).containsKey(killInCellOne.getId()); assertThat(cellTwoService.currentJobs()).containsKey(killInCellTwo.getId()); AssertableSubscriber<Void> testSubscriber = service.killJob(killInCellOne.getId(), UNDEFINED_CALL_METADATA).test(); testSubscriber.awaitTerminalEvent(1, TimeUnit.SECONDS); testSubscriber.assertNoErrors(); testSubscriber.assertNoValues(); testSubscriber.assertCompleted(); assertThat(cellOneService.currentJobs()).doesNotContainKey(killInCellOne.getId()); assertThat(cellTwoService.currentJobs()).doesNotContainKey(killInCellOne.getId()); testSubscriber.unsubscribe(); testSubscriber = service.killJob(killInCellTwo.getId(), UNDEFINED_CALL_METADATA).test(); testSubscriber.awaitTerminalEvent(1, TimeUnit.SECONDS); testSubscriber.assertNoErrors(); testSubscriber.assertNoValues(); testSubscriber.assertCompleted(); assertThat(cellOneService.currentJobs()).doesNotContainKey(killInCellTwo.getId()); assertThat(cellTwoService.currentJobs()).doesNotContainKey(killInCellTwo.getId()); testSubscriber.unsubscribe(); }
Example 6
Source File: AggregatingLoadBalancerServiceTest.java From titus-control-plane with Apache License 2.0 | 5 votes |
@Test public void addLoadBalancer() { JobLoadBalancer jobLoadBalancer1 = new JobLoadBalancer(JOB_1, LB_1); JobLoadBalancer jobLoadBalancer2 = new JobLoadBalancer(JOB_2, LB_2); final CellWithLoadBalancers cellWithLoadBalancersOne = new CellWithLoadBalancers(singletonList(jobLoadBalancer1)); final CellWithLoadBalancers cellWithLoadBalancersTwo = new CellWithLoadBalancers(new ArrayList<>(singletonList(jobLoadBalancer2))); final CellWithJobIds cellWithJobIdsOne = new CellWithJobIds(singletonList(JOB_1)); final CellWithJobIds cellWithJobIdsTwo = new CellWithJobIds(singletonList(JOB_2)); cellOne.getServiceRegistry().addService(cellWithLoadBalancersOne); cellOne.getServiceRegistry().addService(cellWithJobIdsOne); cellTwo.getServiceRegistry().addService(cellWithLoadBalancersTwo); cellTwo.getServiceRegistry().addService(cellWithJobIdsTwo); final AssertableSubscriber<Void> resultSubscriber = service.addLoadBalancer( AddLoadBalancerRequest.newBuilder().setJobId(JOB_2).setLoadBalancerId(LoadBalancerId.newBuilder().setId(LB_3).build()).build(), JUNIT_REST_CALL_METADATA ).test(); resultSubscriber.awaitTerminalEvent(1, TimeUnit.SECONDS); resultSubscriber.assertNoErrors(); resultSubscriber.assertNoValues(); resultSubscriber.assertCompleted(); final AssertableSubscriber<GetJobLoadBalancersResult> jobResults = service.getLoadBalancers( JobId.newBuilder().setId(JOB_2).build(), JUNIT_REST_CALL_METADATA ).test(); jobResults.assertNoErrors(); final List<GetJobLoadBalancersResult> onNextEvents = jobResults.getOnNextEvents(); assertThat(onNextEvents.size()).isEqualTo(1); final List<LoadBalancerId> loadBalancersList = onNextEvents.get(0).getLoadBalancersList(); assertThat(loadBalancersList.size()).isEqualTo(2); final List<String> resultLoadBalancerIds = loadBalancersList.stream().map(LoadBalancerId::getId).collect(Collectors.toList()); assertThat(resultLoadBalancerIds).contains(LB_2, LB_3); }
Example 7
Source File: AggregatingLoadBalancerServiceTest.java From titus-control-plane with Apache License 2.0 | 5 votes |
@Test public void removeLoadBalancer() { JobLoadBalancer jobLoadBalancer1 = new JobLoadBalancer(JOB_1, LB_1); JobLoadBalancer jobLoadBalancer2 = new JobLoadBalancer(JOB_2, LB_2); JobLoadBalancer jobLoadBalancer3 = new JobLoadBalancer(JOB_2, LB_3); final CellWithLoadBalancers cellWithLoadBalancersOne = new CellWithLoadBalancers(singletonList(jobLoadBalancer1)); final CellWithLoadBalancers cellWithLoadBalancersTwo = new CellWithLoadBalancers(new ArrayList<>(Arrays.asList(jobLoadBalancer2, jobLoadBalancer3))); final CellWithJobIds cellWithJobIdsOne = new CellWithJobIds(singletonList(JOB_1)); final CellWithJobIds cellWithJobIdsTwo = new CellWithJobIds(singletonList(JOB_2)); cellOne.getServiceRegistry().addService(cellWithLoadBalancersOne); cellOne.getServiceRegistry().addService(cellWithJobIdsOne); cellTwo.getServiceRegistry().addService(cellWithLoadBalancersTwo); cellTwo.getServiceRegistry().addService(cellWithJobIdsTwo); final AssertableSubscriber<Void> resultSubscriber = service.removeLoadBalancer( RemoveLoadBalancerRequest.newBuilder().setJobId(JOB_2).setLoadBalancerId(LoadBalancerId.newBuilder().setId(LB_2).build()).build(), JUNIT_REST_CALL_METADATA ).test(); resultSubscriber.awaitTerminalEvent(1, TimeUnit.SECONDS); resultSubscriber.assertNoErrors(); resultSubscriber.assertNoValues(); resultSubscriber.assertCompleted(); final AssertableSubscriber<GetJobLoadBalancersResult> jobResults = service.getLoadBalancers( JobId.newBuilder().setId(JOB_2).build(), JUNIT_REST_CALL_METADATA ).test(); jobResults.awaitValueCount(1, 1, TimeUnit.SECONDS); jobResults.assertNoErrors(); final List<GetJobLoadBalancersResult> onNextEvents = jobResults.getOnNextEvents(); assertThat(onNextEvents.size()).isEqualTo(1); final List<LoadBalancerId> loadBalancersList = onNextEvents.get(0).getLoadBalancersList(); assertThat(loadBalancersList.size()).isEqualTo(1); assertThat(loadBalancersList.get(0).getId()).isEqualTo(LB_3); }
Example 8
Source File: AggregatingJobServiceGatewayTest.java From titus-control-plane with Apache License 2.0 | 4 votes |
@Test public void singleJobUpdates() { Random random = new Random(); List<String> cellOneSnapshot = new ArrayList<>(dataGenerator.newServiceJobs(12)).stream() .map(job -> job.getId()) .collect(Collectors.toList()); List<String> cellTwoSnapshot = new ArrayList<>(dataGenerator.newBatchJobs(7)).stream() .map(job -> job.getId()) .collect(Collectors.toList()); CellWithJobIds cellOneService = new CellWithJobIds(cellOneSnapshot); CellWithJobIds cellTwoService = new CellWithJobIds(cellTwoSnapshot); cellOne.getServiceRegistry().addService(cellOneService); cellTwo.getServiceRegistry().addService(cellTwoService); String cellOneJobId = cellOneSnapshot.get(random.nextInt(cellOneSnapshot.size())); String cellTwoJobId = cellTwoSnapshot.get(random.nextInt(cellTwoSnapshot.size())); assertThat(cellOneService.containsCapacityUpdates(cellOneJobId)).isFalse(); assertThat(cellTwoService.containsCapacityUpdates(cellOneJobId)).isFalse(); JobCapacityUpdate cellOneUpdate = JobCapacityUpdate.newBuilder() .setJobId(cellOneJobId) .setCapacity(Capacity.newBuilder() .setMax(1).setDesired(2).setMax(3) .build()) .build(); AssertableSubscriber<Void> testSubscriber = service.updateJobCapacity(cellOneUpdate, UNDEFINED_CALL_METADATA).test(); testSubscriber.awaitTerminalEvent(1, TimeUnit.SECONDS); testSubscriber.assertNoErrors(); testSubscriber.assertNoValues(); testSubscriber.assertCompleted(); assertThat(cellOneService.containsCapacityUpdates(cellOneJobId)).isTrue(); assertThat(cellTwoService.containsCapacityUpdates(cellOneJobId)).isFalse(); testSubscriber.unsubscribe(); JobCapacityUpdate cellTwoUpdate = JobCapacityUpdate.newBuilder() .setJobId(cellTwoJobId) .setCapacity(Capacity.newBuilder() .setMax(2).setDesired(2).setMax(2) .build()) .build(); testSubscriber = service.updateJobCapacity(cellTwoUpdate, UNDEFINED_CALL_METADATA).test(); testSubscriber.awaitTerminalEvent(1, TimeUnit.SECONDS); testSubscriber.assertNoErrors(); testSubscriber.assertNoValues(); testSubscriber.assertCompleted(); assertThat(cellOneService.containsCapacityUpdates(cellTwoJobId)).isFalse(); assertThat(cellTwoService.containsCapacityUpdates(cellTwoJobId)).isTrue(); testSubscriber.unsubscribe(); }
Example 9
Source File: AggregatingJobServiceGatewayTest.java From titus-control-plane with Apache License 2.0 | 4 votes |
@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(); }
Example 10
Source File: AWSAppAutoScalingClientTest.java From titus-control-plane with Apache License 2.0 | 4 votes |
@Test public void deleteScalingPolicyIsIdempotent() { String jobId = UUID.randomUUID().toString(); String policyId = UUID.randomUUID().toString(); AWSApplicationAutoScalingAsync clientAsync = mock(AWSApplicationAutoScalingAsync.class); AWSAppScalingConfig config = mock(AWSAppScalingConfig.class); AWSAppAutoScalingClient autoScalingClient = new AWSAppAutoScalingClient(clientAsync, config, new NoopRegistry()); // delete happens successfully on the first attempt AtomicBoolean isDeleted = new AtomicBoolean(false); when(clientAsync.deleteScalingPolicyAsync(any(), any())).thenAnswer(invocation -> { DeleteScalingPolicyRequest request = invocation.getArgument(0); AsyncHandler<DeleteScalingPolicyRequest, DeleteScalingPolicyResult> handler = invocation.getArgument(1); if (isDeleted.get()) { ObjectNotFoundException notFoundException = new ObjectNotFoundException(policyId + " does not exist"); handler.onError(notFoundException); return Future.failed(notFoundException); } DeleteScalingPolicyResult resultSuccess = new DeleteScalingPolicyResult(); HttpResponse successResponse = new HttpResponse(null, null); successResponse.setStatusCode(200); resultSuccess.setSdkHttpMetadata(SdkHttpMetadata.from(successResponse)); isDeleted.set(true); handler.onSuccess(request, resultSuccess); return Future.successful(resultSuccess); }); AssertableSubscriber<Void> firstCall = autoScalingClient.deleteScalingPolicy(policyId, jobId).test(); firstCall.awaitTerminalEvent(2, TimeUnit.SECONDS); firstCall.assertNoErrors(); firstCall.assertCompleted(); verify(clientAsync, times(1)).deleteScalingPolicyAsync(any(), any()); // second should complete fast when NotFound and not retry with exponential backoff AssertableSubscriber<Void> secondCall = autoScalingClient.deleteScalingPolicy(policyId, jobId).test(); secondCall.awaitTerminalEvent(2, TimeUnit.SECONDS); secondCall.assertNoErrors(); secondCall.assertCompleted(); verify(clientAsync, times(2)).deleteScalingPolicyAsync(any(), any()); }
Example 11
Source File: AWSAppAutoScalingClientTest.java From titus-control-plane with Apache License 2.0 | 4 votes |
@Test public void deleteScalableTargetIsIdempotent() { String jobId = UUID.randomUUID().toString(); String policyId = UUID.randomUUID().toString(); AWSApplicationAutoScalingAsync clientAsync = mock(AWSApplicationAutoScalingAsync.class); AWSAppScalingConfig config = mock(AWSAppScalingConfig.class); AWSAppAutoScalingClient autoScalingClient = new AWSAppAutoScalingClient(clientAsync, config, new NoopRegistry()); AtomicBoolean isDeleted = new AtomicBoolean(false); when(clientAsync.deregisterScalableTargetAsync(any(), any())).thenAnswer(invocation -> { DeregisterScalableTargetRequest request = invocation.getArgument(0); AsyncHandler<DeregisterScalableTargetRequest, DeregisterScalableTargetResult> handler = invocation.getArgument(1); if (isDeleted.get()) { ObjectNotFoundException notFoundException = new ObjectNotFoundException(policyId + " does not exist"); handler.onError(notFoundException); return Future.failed(notFoundException); } DeregisterScalableTargetResult resultSuccess = new DeregisterScalableTargetResult(); HttpResponse successResponse = new HttpResponse(null, null); successResponse.setStatusCode(200); resultSuccess.setSdkHttpMetadata(SdkHttpMetadata.from(successResponse)); isDeleted.set(true); handler.onSuccess(request, resultSuccess); return Future.successful(resultSuccess); }); AssertableSubscriber<Void> firstCall = autoScalingClient.deleteScalableTarget(jobId).test(); firstCall.awaitTerminalEvent(2, TimeUnit.SECONDS); firstCall.assertNoErrors(); firstCall.assertCompleted(); verify(clientAsync, times(1)).deregisterScalableTargetAsync(any(), any()); // second should complete fast when NotFound and not retry with exponential backoff AssertableSubscriber<Void> secondCall = autoScalingClient.deleteScalableTarget(jobId).test(); secondCall.awaitTerminalEvent(2, TimeUnit.SECONDS); secondCall.assertNoErrors(); secondCall.assertCompleted(); verify(clientAsync, times(2)).deregisterScalableTargetAsync(any(), any()); }