use of io.reactivex.exceptions.UndeliverableException 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);
}
}
Aggregations