use of io.reactivex.observers.TestObserver in project rxjava2-jdbc by davidmoten.
the class NonBlockingPoolTest method testPoolFactoryWhenFailsThenRecovers.
@Test
public void testPoolFactoryWhenFailsThenRecovers() {
AtomicReference<Throwable> ex = new AtomicReference<>();
Consumer<? super Throwable> handler = RxJavaPlugins.getErrorHandler();
RxJavaPlugins.setErrorHandler(t -> ex.set(t));
try {
TestScheduler s = new TestScheduler();
AtomicInteger c = new AtomicInteger();
NonBlockingPool<Integer> pool = NonBlockingPool.factory(() -> {
if (c.getAndIncrement() == 0) {
throw new TestException();
} else {
return c.get();
}
}).maxSize(//
1).scheduler(//
s).createRetryInterval(10, //
TimeUnit.SECONDS).build();
TestObserver<Integer> ts = //
pool.member().map(//
m -> m.value()).test().assertNotTerminated().assertNoValues();
s.triggerActions();
assertTrue(ex.get() instanceof UndeliverableException);
assertTrue(((UndeliverableException) ex.get()).getCause() instanceof TestException);
s.advanceTimeBy(10, TimeUnit.SECONDS);
s.triggerActions();
ts.assertComplete();
ts.assertValue(2);
} finally {
RxJavaPlugins.setErrorHandler(handler);
}
}
use of io.reactivex.observers.TestObserver in project quran_android by quran.
the class RecentPageModelTest method testUpdateLatestPageWithSlowRecents.
@Test
public void testUpdateLatestPageWithSlowRecents() {
final TestScheduler testScheduler = new TestScheduler();
RecentPageModel recentPageModel = new RecentPageModel(bookmarksAdapter) {
@Override
Single<List<RecentPage>> getRecentPagesObservable() {
// testScheduler simulates the passing of 5 seconds (the timer time).
return Single.timer(5, TimeUnit.SECONDS, testScheduler).map(aLong -> SAMPLE_RECENT_PAGES).subscribeOn(Schedulers.trampoline());
}
};
TestObserver<Integer> testObserver = new TestObserver<>();
recentPageModel.getLatestPageObservable().take(2).subscribe(testObserver);
// write before the mock data from getRecentPagesObservable comes back
recentPageModel.updateLatestPage(51);
// now let's pretend the recent page came back - we expect that this page should be ignored.
testScheduler.advanceTimeBy(5, TimeUnit.SECONDS);
// and that another page afterwards was written
recentPageModel.updateLatestPage(23);
testObserver.awaitTerminalEvent();
testObserver.assertValues(51, 23);
}
use of io.reactivex.observers.TestObserver in project quran_android by quran.
the class TranslationManagerPresenterTest method getRemoteTranslationListObservableIssue.
@Test
public void getRemoteTranslationListObservableIssue() throws Exception {
MockResponse mockResponse = new MockResponse();
mockResponse.setResponseCode(500);
this.mockWebServer.enqueue(mockResponse);
TestObserver<TranslationList> testObserver = new TestObserver<>();
this.translationManager.getRemoteTranslationListObservable().subscribe(testObserver);
testObserver.awaitTerminalEvent();
testObserver.assertNoValues();
testObserver.assertError(IOException.class);
}
use of io.reactivex.observers.TestObserver in project quran_android by quran.
the class BookmarkImportExportModelTest method testReadInvalidBookmarks.
@Test
public void testReadInvalidBookmarks() {
TestObserver<BookmarkData> testObserver = new TestObserver<>();
Buffer source = new Buffer();
source.writeUtf8(")");
bookmarkImportExportModel.readBookmarks(source).subscribe(testObserver);
testObserver.awaitTerminalEvent();
testObserver.assertValueCount(0);
testObserver.assertError(IOException.class);
}
use of io.reactivex.observers.TestObserver in project tutorials by eugenp.
the class ExceptionHandlingTest method givenSubscriberAndError_whenChangeStateOnError_thenErrorThrown.
@Test
public void givenSubscriberAndError_whenChangeStateOnError_thenErrorThrown() {
TestObserver<String> testObserver = new TestObserver<>();
final AtomicBoolean state = new AtomicBoolean(false);
Observable.<String>error(UNKNOWN_ERROR).doOnError(throwable -> state.set(true)).subscribe(testObserver);
testObserver.assertError(UNKNOWN_ERROR);
testObserver.assertNotComplete();
testObserver.assertNoValues();
assertTrue("state should be changed", state.get());
}
Aggregations