Java Code Examples for rx.observers.TestSubscriber#assertTerminalEvent()

The following examples show how to use rx.observers.TestSubscriber#assertTerminalEvent() . 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: ObservableQueueTest.java    From Jockey with Apache License 2.0 6 votes vote down vote up
@Test
public void testEarlyUnsubscribeDoesNotDestroyQueue() {
    TestSubscriber<String> subscriber1 = new TestSubscriber<>();
    TestSubscriber<String> subscriber2 = new TestSubscriber<>();

    mSubject.enqueue("Thing 1");
    mSubject.enqueue("Thing 2");
    mSubject.enqueue("Thing 3");
    mSubject.enqueue("Thing 4");

    mSubject.toObservable().take(1).subscribe(subscriber1);

    subscriber1.assertTerminalEvent();
    subscriber1.assertValue("Thing 1");

    mSubject.toObservable().subscribe(subscriber2);
    subscriber2.assertNoTerminalEvent();
    subscriber2.assertValues("Thing 2", "Thing 3", "Thing 4");
}
 
Example 2
Source File: RetryWhenTest.java    From rxjava-extras with Apache License 2.0 6 votes vote down vote up
@Test
public void testRetryWhenMultipleRetriesWorkOnSingleDelay() {
    AtomicInteger count = new AtomicInteger();
    TestSubscriber<Object> ts = TestSubscriber.create();
    Exception exception = new Exception("boo");
    Observable.error(exception) //
            .doOnSubscribe(Actions.increment0(count)) //
            .retryWhen(RetryWhen //
                    .delay(1, TimeUnit.MILLISECONDS) //
                    .scheduler(Schedulers.trampoline()) //
                    .maxRetries(10).build()) //
            .subscribe(ts);
    ts.assertTerminalEvent();
    assertFalse(ts.getOnErrorEvents().isEmpty());
    assertEquals(exception, ts.getOnErrorEvents().get(0));
    assertEquals(11, count.get());
}
 
Example 3
Source File: RxGatewayStoreModelTest.java    From azure-cosmosdb-java with MIT License 5 votes vote down vote up
public static void validateFailure(Observable<RxDocumentServiceResponse> observable,
                                   FailureValidator validator,
                                   long timeout) {
    TestSubscriber<RxDocumentServiceResponse> testSubscriber = new TestSubscriber<>();

    observable.subscribe(testSubscriber);
    testSubscriber.awaitTerminalEvent(timeout, TimeUnit.MILLISECONDS);
    testSubscriber.assertNotCompleted();
    testSubscriber.assertTerminalEvent();
    assertThat(testSubscriber.getOnErrorEvents()).hasSize(1);
    validator.validate(testSubscriber.getOnErrorEvents().get(0));
}
 
Example 4
Source File: ReplicatedResourceClientTest.java    From azure-cosmosdb-java with MIT License 5 votes vote down vote up
public static void validateFailure(Single<StoreResponse> single, FailureValidator validator, long timeout) {

        TestSubscriber<StoreResponse> testSubscriber = new TestSubscriber<>();
        single.toObservable().subscribe(testSubscriber);
        testSubscriber.awaitTerminalEvent(timeout, TimeUnit.MILLISECONDS);
        testSubscriber.assertNotCompleted();
        testSubscriber.assertTerminalEvent();
        Assertions.assertThat(testSubscriber.getOnErrorEvents()).hasSize(1);
        validator.validate(testSubscriber.getOnErrorEvents().get(0));
    }
 
Example 5
Source File: ReplicatedResourceClientPartitionSplitTest.java    From azure-cosmosdb-java with MIT License 5 votes vote down vote up
public static void validateFailure(Single<StoreResponse> single, FailureValidator validator, long timeout) {

        TestSubscriber<StoreResponse> testSubscriber = new TestSubscriber<>();
        single.toObservable().subscribe(testSubscriber);
        testSubscriber.awaitTerminalEvent(timeout, TimeUnit.MILLISECONDS);
        testSubscriber.assertNotCompleted();
        testSubscriber.assertTerminalEvent();
        Assertions.assertThat(testSubscriber.getOnErrorEvents()).hasSize(1);
        validator.validate(testSubscriber.getOnErrorEvents().get(0));
    }
 
Example 6
Source File: StoreReaderTest.java    From azure-cosmosdb-java with MIT License 5 votes vote down vote up
public static <T> void validateException(Single<T> single,
                                         FailureValidator validator, long timeout) {
    TestSubscriber<T> testSubscriber = new TestSubscriber<>();

    single.toObservable().subscribe(testSubscriber);
    testSubscriber.awaitTerminalEvent(timeout, TimeUnit.MILLISECONDS);
    testSubscriber.assertNotCompleted();
    testSubscriber.assertTerminalEvent();
    assertThat(testSubscriber.getOnErrorEvents()).hasSize(1);
    validator.validate(testSubscriber.getOnErrorEvents().get(0));
}
 
Example 7
Source File: ConsistencyReaderTest.java    From azure-cosmosdb-java with MIT License 5 votes vote down vote up
public static <T> void validateException(Single<T> single,
                                         FailureValidator validator,
                                         long timeout) {
    TestSubscriber<T> testSubscriber = new TestSubscriber<>();

    single.toObservable().subscribe(testSubscriber);
    testSubscriber.awaitTerminalEvent(timeout, TimeUnit.MILLISECONDS);
    testSubscriber.assertNotCompleted();
    testSubscriber.assertTerminalEvent();
    assertThat(testSubscriber.getOnErrorEvents()).hasSize(1);
    validator.validate(testSubscriber.getOnErrorEvents().get(0));
}
 
Example 8
Source File: StoreReaderDotNetTest.java    From azure-cosmosdb-java with MIT License 5 votes vote down vote up
public static void validateException(Single<StoreResult> single,
                                     FailureValidator validator, long timeout) {
    TestSubscriber<StoreResult> testSubscriber = new TestSubscriber<>();

    single.toObservable().subscribe(testSubscriber);
    testSubscriber.awaitTerminalEvent(timeout, TimeUnit.MILLISECONDS);
    testSubscriber.assertNotCompleted();
    testSubscriber.assertTerminalEvent();
    assertThat(testSubscriber.getOnErrorEvents()).hasSize(1);
    validator.validate(testSubscriber.getOnErrorEvents().get(0));
}
 
Example 9
Source File: HttpTransportClientTest.java    From azure-cosmosdb-java with MIT License 5 votes vote down vote up
public static void validateFailure(Single<StoreResponse> single,
                                   FailureValidator validator, long timeout) {

    TestSubscriber<StoreResponse> testSubscriber = new TestSubscriber<>();
    single.toObservable().subscribe(testSubscriber);
    testSubscriber.awaitTerminalEvent(timeout, TimeUnit.MILLISECONDS);
    testSubscriber.assertNotCompleted();
    testSubscriber.assertTerminalEvent();
    Assertions.assertThat(testSubscriber.getOnErrorEvents()).hasSize(1);
    validator.validate(testSubscriber.getOnErrorEvents().get(0));
}
 
Example 10
Source File: RntbdTransportClientTest.java    From azure-cosmosdb-java with MIT License 5 votes vote down vote up
private static void validateFailure(
    final Single<? extends StoreResponse> single, final FailureValidator validator, final long timeout
) {

    final TestSubscriber<StoreResponse> testSubscriber = new TestSubscriber<>();
    single.toObservable().subscribe(testSubscriber);
    testSubscriber.awaitTerminalEvent(timeout, TimeUnit.MILLISECONDS);
    testSubscriber.assertNotCompleted();
    testSubscriber.assertTerminalEvent();
    Assertions.assertThat(testSubscriber.getOnErrorEvents()).hasSize(1);
    validator.validate(testSubscriber.getOnErrorEvents().get(0));
}
 
Example 11
Source File: RetryUtilsTest.java    From azure-cosmosdb-java with MIT License 5 votes vote down vote up
private void validateFailure(Single<StoreResponse> single, long timeout, Class<? extends Throwable> class1) {

        TestSubscriber<StoreResponse> testSubscriber = new TestSubscriber<>();
        single.toObservable().subscribe(testSubscriber);
        testSubscriber.awaitTerminalEvent(timeout, TimeUnit.MILLISECONDS);
        testSubscriber.assertNotCompleted();
        testSubscriber.assertTerminalEvent();
        assertThat(testSubscriber.getOnErrorEvents()).hasSize(1);
        if (!(testSubscriber.getOnErrorEvents().get(0).getClass().equals(class1))) {
            fail("Not expecting " + testSubscriber.getOnErrorEvents().get(0));
        }
    }
 
Example 12
Source File: OAuthInteractorTest.java    From Forage with Mozilla Public License 2.0 5 votes vote down vote up
@Test
public void retrieveAccessToken_error() throws OAuthCommunicationException, OAuthExpectationFailedException, OAuthNotAuthorizedException, OAuthMessageSignerException {
    Uri uri = mock(Uri.class);
    when(uri.getQueryParameter(OAuth.OAUTH_VERIFIER)).thenReturn(null);

    TestSubscriber testSubscriber = new TestSubscriber();
    oAuthInteractor.retrieveAccessToken(uri)
            .subscribe(testSubscriber);

    // We don't really care what the error is just that we have one
    // Hacky way to see if there is an error (terminal event) but not success (completion)
    testSubscriber.assertTerminalEvent();
    testSubscriber.assertNotCompleted();
}
 
Example 13
Source File: OnSubscribeDoOnEmptyTest.java    From rxjava-extras with Apache License 2.0 5 votes vote down vote up
@Test
public void ifOnEmptyActionThrowsNonFatalRuntimeExceptionThenErrorEmitted() {
    TestSubscriber<Object> ts = TestSubscriber.create();
    Observable.empty() //
         .compose(Transformers.doOnEmpty(Actions.throw0(new NumberFormatException()))) //
         .subscribe(ts);
    ts.assertNoValues();
    ts.assertTerminalEvent();
    ts.assertError(NumberFormatException.class);
}