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));
}
}
Aggregations