Java Code Examples for rx.observers.AssertableSubscriber#assertError()

The following examples show how to use rx.observers.AssertableSubscriber#assertError() . 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: AggregatingJobServiceGatewayTest.java    From titus-control-plane with Apache License 2.0 6 votes vote down vote up
@Test
public void findJobsWithFailingCell() {
    List<Job> cellTwoSnapshot = new ArrayList<>();
    for (int i = 0; i < 5; i++) {
        cellTwoSnapshot.addAll(dataGenerator.newBatchJobs(5, GrpcJobManagementModelConverters::toGrpcJob));
        cellTwoSnapshot.addAll(dataGenerator.newServiceJobs(5, GrpcJobManagementModelConverters::toGrpcJob));
        clock.advanceTime(1, TimeUnit.MINUTES);
    }
    cellOne.getServiceRegistry().addService(new CellWithFailingJobManagementService());
    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.assertError(Status.INTERNAL.asRuntimeException().getClass());
    testSubscriber.assertNoValues();
}
 
Example 2
Source File: AggregatingAutoScalingServiceTest.java    From titus-control-plane with Apache License 2.0 6 votes vote down vote up
@Test
public void getPoliciesFromTwoCellsWithOneFailing() {
    ScalingPolicyID policy1 = ScalingPolicyID.newBuilder().setId(POLICY_1).build();
    ScalingPolicyResult policyOneResult = ScalingPolicyResult.newBuilder().setId(policy1).build();

    CellWithPolicies cellOneService = new CellWithPolicies(Collections.singletonList(policyOneResult));
    CellWithFailingAutoscalingService badCell = new CellWithFailingAutoscalingService();

    cellOne.getServiceRegistry().addService(cellOneService);
    cellTwo.getServiceRegistry().addService(badCell);

    final AssertableSubscriber<GetPolicyResult> testSubscriber = service.getAllScalingPolicies(JUNIT_REST_CALL_METADATA).test();
    testSubscriber.awaitTerminalEvent(1, TimeUnit.SECONDS);
    testSubscriber.assertNoValues();
    testSubscriber.assertError(StatusRuntimeException.class);
    List<Throwable> onErrorEvents = testSubscriber.getOnErrorEvents();
    assertThat(onErrorEvents.size()).isEqualTo(1);
}
 
Example 3
Source File: TransformersTest.java    From mobius with Apache License 2.0 5 votes vote down vote up
@Test
public void effectPerformerInvokesFunctionWithReceivedEffectAndErrorsForUnhandledExceptions() {
  PublishSubject<String> upstream = PublishSubject.create();
  TestScheduler scheduler = new TestScheduler();
  Function<String, Integer> function =
      s -> {
        throw new RuntimeException("Something bad happened");
      };
  AssertableSubscriber<Integer> observer =
      upstream.compose(Transformers.fromFunction(function, scheduler)).test();

  upstream.onNext("Hello");
  scheduler.triggerActions();
  observer.assertError(RuntimeException.class);
}
 
Example 4
Source File: RxMobiusLoopTest.java    From mobius with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldPropagateIncomingErrorsAsUnrecoverable() throws Exception {
  RxMobiusLoop<Integer, String, Boolean> loop =
      new RxMobiusLoop<>(builder, "", Collections.emptySet());
  PublishSubject<Integer> input = PublishSubject.create();

  AssertableSubscriber<String> subscriber = input.compose(loop).test();

  Exception expected = new RuntimeException("expected");
  input.onError(expected);
  subscriber.awaitTerminalEvent(1, TimeUnit.SECONDS);
  subscriber.assertError(new UnrecoverableIncomingException(expected));
  assertEquals(0, connection.valueCount());
}
 
Example 5
Source File: RxConnectablesTest.java    From mobius with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldPropagateErrorsFromUpstream() throws Exception {
  final Throwable expected = new RuntimeException("expected");

  AssertableSubscriber<Integer> subscriber =
      input.compose(RxConnectables.toTransformer(connectable)).test();

  input.onError(expected);

  subscriber.awaitTerminalEvent(1, TimeUnit.SECONDS);
  subscriber.assertError(expected);
}
 
Example 6
Source File: AggregatingJobServiceGatewayTest.java    From titus-control-plane with Apache License 2.0 5 votes vote down vote up
@Test
public void findJobErrors() {
    cellOne.getServiceRegistry().addService(new CellWithFailingJobManagementService(NOT_FOUND));
    cellTwo.getServiceRegistry().addService(new CellWithFailingJobManagementService(UNAVAILABLE));

    AssertableSubscriber<Job> testSubscriber = service.findJob("any", UNDEFINED_CALL_METADATA).test();
    testSubscriber.awaitTerminalEvent(1, TimeUnit.SECONDS);
    // transient errors have higher precedence than not found
    testSubscriber.assertError(StatusRuntimeException.class);
    assertThat(Status.fromThrowable(testSubscriber.getOnErrorEvents().get(0))).isEqualTo(UNAVAILABLE);
}
 
Example 7
Source File: AggregatingJobServiceGatewayTest.java    From titus-control-plane with Apache License 2.0 5 votes vote down vote up
@Test
public void findTaskErrors() {
    cellOne.getServiceRegistry().addService(new CellWithFailingJobManagementService(INTERNAL));
    cellTwo.getServiceRegistry().addService(new CellWithFailingJobManagementService(UNAVAILABLE));

    AssertableSubscriber<Task> testSubscriber = service.findTask("any", UNDEFINED_CALL_METADATA).test();
    testSubscriber.awaitTerminalEvent(1, TimeUnit.SECONDS);
    // unexpected errors have higher precedence than transient
    testSubscriber.assertError(StatusRuntimeException.class);
    assertThat(Status.fromThrowable(testSubscriber.getOnErrorEvents().get(0))).isEqualTo(INTERNAL);
}
 
Example 8
Source File: AggregatingAutoScalingServiceTest.java    From titus-control-plane with Apache License 2.0 5 votes vote down vote up
@Test
public void getPolicyByIdFromTwoCells() {
    ScalingPolicyID policy1 = ScalingPolicyID.newBuilder().setId(POLICY_1).build();
    ScalingPolicyID policy2 = ScalingPolicyID.newBuilder().setId(POLICY_2).build();

    ScalingPolicyResult policyOneResult = ScalingPolicyResult.newBuilder().setId(policy1).build();
    ScalingPolicyResult policyTwoResult = ScalingPolicyResult.newBuilder().setId(policy2).build();

    CellWithPolicies cellOneService = new CellWithPolicies(Collections.singletonList(policyOneResult));
    CellWithPolicies cellTwoService = new CellWithPolicies(Collections.singletonList(policyTwoResult));

    cellOne.getServiceRegistry().addService(cellOneService);
    cellTwo.getServiceRegistry().addService(cellTwoService);

    AssertableSubscriber<GetPolicyResult> testSubscriber = service.getScalingPolicy(
            ScalingPolicyID.newBuilder().setId(POLICY_2).build(), JUNIT_REST_CALL_METADATA).test();

    testSubscriber.awaitValueCount(1, 1, TimeUnit.SECONDS);

    List<GetPolicyResult> onNextEvents = testSubscriber.getOnNextEvents();
    assertThat(onNextEvents).isNotNull();
    assertThat(onNextEvents.size()).isEqualTo(1);
    assertThat(onNextEvents.get(0).getItemsCount()).isEqualTo(1);

    // Bad id. The current behavior is "INTERNAL: Completed without a response", but it will change to NOT_FOUND someday
    testSubscriber = service.getScalingPolicy(ScalingPolicyID.newBuilder().setId("badID").build(), JUNIT_REST_CALL_METADATA).test();
    testSubscriber.awaitTerminalEvent(1, TimeUnit.SECONDS);
    testSubscriber.assertError(StatusRuntimeException.class);
    testSubscriber.assertNoValues();
    List<Throwable> onErrorEvents = testSubscriber.getOnErrorEvents();
    assertThat(onErrorEvents).isNotNull();
    assertThat(onErrorEvents).hasSize(1);
    assertThat(Status.fromThrowable(onErrorEvents.get(0)).getCode()).isEqualTo(Status.CANCELLED.getCode());
}
 
Example 9
Source File: AwsObservableExtTest.java    From titus-control-plane with Apache License 2.0 5 votes vote down vote up
@Test
public void asyncActionCompletableErrors() {
    AmazonWebServiceRequest someRequest = AmazonWebServiceRequest.NOOP;
    final MockAsyncClient<AmazonWebServiceRequest, String> client = new MockAsyncClient<>(someRequest, "some response");
    RuntimeException exception = new RuntimeException("error when initiating an async operation");
    final Completable completable = AwsObservableExt.asyncActionCompletable(factory -> client.throwException(exception));

    TestScheduler testScheduler = Schedulers.test();
    final AssertableSubscriber<Void> subscriber = completable.subscribeOn(testScheduler).test();

    testScheduler.triggerActions();
    subscriber.assertError(exception);
}
 
Example 10
Source File: AwsObservableExtTest.java    From titus-control-plane with Apache License 2.0 5 votes vote down vote up
@Test
public void asyncActionSingleErrors() {
    AmazonWebServiceRequest someRequest = AmazonWebServiceRequest.NOOP;
    final MockAsyncClient<AmazonWebServiceRequest, String> client = new MockAsyncClient<>(someRequest, "some response");
    RuntimeException exception = new RuntimeException("error when initiating an async operation");
    final Single<String> completable = AwsObservableExt.asyncActionSingle(supplier -> client.throwException(exception));

    TestScheduler testScheduler = Schedulers.test();
    final AssertableSubscriber<String> subscriber = completable.subscribeOn(testScheduler).test();

    testScheduler.triggerActions();
    subscriber.assertError(exception);
}