Search in sources :

Example 6 with FlowableSingleDeferUntilRequest

use of org.davidmoten.rx.internal.FlowableSingleDeferUntilRequest in project rxjava2-jdbc by davidmoten.

the class NonBlockingPoolTest method testConnectionPoolRecylesMany.

@Test
public void testConnectionPoolRecylesMany() throws SQLException {
    TestScheduler s = new TestScheduler();
    AtomicInteger count = new AtomicInteger();
    Pool<Integer> pool = // 
    NonBlockingPool.factory(// 
    () -> count.incrementAndGet()).healthCheck(// 
    n -> true).maxSize(// 
    2).maxIdleTime(1, // 
    TimeUnit.MINUTES).scheduler(// 
    s).build();
    TestSubscriber<Member<Integer>> ts = // 
    new FlowableSingleDeferUntilRequest<>(pool.member()).repeat().test(// 
    4);
    s.triggerActions();
    // 
    ts.assertNoErrors().assertValueCount(// 
    2).assertNotTerminated();
    List<Member<Integer>> list = new ArrayList<>(ts.values());
    // should release a connection
    list.get(1).checkin();
    s.triggerActions();
    {
        List<Object> values = // 
        ts.assertValueCount(3).assertNotTerminated().getEvents().get(0);
        assertEquals(list.get(0).hashCode(), values.get(0).hashCode());
        assertEquals(list.get(1).hashCode(), values.get(1).hashCode());
        assertEquals(list.get(1).hashCode(), values.get(2).hashCode());
    }
    // .assertValues(list.get(0), list.get(1), list.get(1));
    list.get(0).checkin();
    s.triggerActions();
    {
        List<Object> values = // 
        ts.assertValueCount(4).assertNotTerminated().getEvents().get(0);
        assertEquals(list.get(0), values.get(0));
        assertEquals(list.get(1), values.get(1));
        assertEquals(list.get(1), values.get(2));
        assertEquals(list.get(0), values.get(3));
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ArrayList(java.util.ArrayList) FlowableSingleDeferUntilRequest(org.davidmoten.rx.internal.FlowableSingleDeferUntilRequest) ArrayList(java.util.ArrayList) List(java.util.List) TestScheduler(io.reactivex.schedulers.TestScheduler) Test(org.junit.Test)

Aggregations

TestScheduler (io.reactivex.schedulers.TestScheduler)6 ArrayList (java.util.ArrayList)6 List (java.util.List)6 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)6 FlowableSingleDeferUntilRequest (org.davidmoten.rx.internal.FlowableSingleDeferUntilRequest)6 Test (org.junit.Test)6 Flowable (io.reactivex.Flowable)5 Scheduler (io.reactivex.Scheduler)5 SingleObserver (io.reactivex.SingleObserver)5 Disposable (io.reactivex.disposables.Disposable)5 UndeliverableException (io.reactivex.exceptions.UndeliverableException)5 Consumer (io.reactivex.functions.Consumer)5 TestObserver (io.reactivex.observers.TestObserver)5 RxJavaPlugins (io.reactivex.plugins.RxJavaPlugins)5 Schedulers (io.reactivex.schedulers.Schedulers)5 TestSubscriber (io.reactivex.subscribers.TestSubscriber)5 SQLException (java.sql.SQLException)5 Arrays (java.util.Arrays)5 CountDownLatch (java.util.concurrent.CountDownLatch)5 Executors (java.util.concurrent.Executors)5