Search in sources :

Example 1 with UndeliverableException

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);
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Arrays(java.util.Arrays) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) UndeliverableException(io.reactivex.exceptions.UndeliverableException) AtomicReference(java.util.concurrent.atomic.AtomicReference) ArrayList(java.util.ArrayList) SQLException(java.sql.SQLException) Scheduler(io.reactivex.Scheduler) Flowable(io.reactivex.Flowable) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Schedulers(io.reactivex.schedulers.Schedulers) TestSubscriber(io.reactivex.subscribers.TestSubscriber) FlowableSingleDeferUntilRequest(org.davidmoten.rx.internal.FlowableSingleDeferUntilRequest) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) TestObserver(io.reactivex.observers.TestObserver) RxJavaPlugins(io.reactivex.plugins.RxJavaPlugins) Consumer(io.reactivex.functions.Consumer) Executors(java.util.concurrent.Executors) TimeUnit(java.util.concurrent.TimeUnit) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) Disposable(io.reactivex.disposables.Disposable) Assert.assertNull(org.junit.Assert.assertNull) SingleObserver(io.reactivex.SingleObserver) Assert.assertFalse(org.junit.Assert.assertFalse) TestScheduler(io.reactivex.schedulers.TestScheduler) Assert.assertEquals(org.junit.Assert.assertEquals) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AtomicReference(java.util.concurrent.atomic.AtomicReference) TestScheduler(io.reactivex.schedulers.TestScheduler) UndeliverableException(io.reactivex.exceptions.UndeliverableException) Test(org.junit.Test)

Aggregations

Flowable (io.reactivex.Flowable)1 Scheduler (io.reactivex.Scheduler)1 SingleObserver (io.reactivex.SingleObserver)1 Disposable (io.reactivex.disposables.Disposable)1 UndeliverableException (io.reactivex.exceptions.UndeliverableException)1 Consumer (io.reactivex.functions.Consumer)1 TestObserver (io.reactivex.observers.TestObserver)1 RxJavaPlugins (io.reactivex.plugins.RxJavaPlugins)1 Schedulers (io.reactivex.schedulers.Schedulers)1 TestScheduler (io.reactivex.schedulers.TestScheduler)1 TestSubscriber (io.reactivex.subscribers.TestSubscriber)1 SQLException (java.sql.SQLException)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 List (java.util.List)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 Executors (java.util.concurrent.Executors)1 TimeUnit (java.util.concurrent.TimeUnit)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1