Search in sources :

Example 1 with Database

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

the class PoolTest method testConnectionPoolRecylesMany.

@Test
public void testConnectionPoolRecylesMany() throws SQLException {
    Database db = DatabaseCreator.create(2);
    TestSubscriber<Connection> ts = //
    db.connections().test(//
    4);
    //
    ts.assertNoErrors().assertValueCount(//
    2).assertNotTerminated();
    List<Connection> list = new ArrayList<>(ts.values());
    // should release a connection
    list.get(1).close();
    //
    ts.assertValueCount(3).assertNotTerminated().assertValues(list.get(0), list.get(1), list.get(1));
    list.get(0).close();
    //
    ts.assertValues(list.get(0), list.get(1), list.get(1), list.get(0)).assertValueCount(//
    4).assertNotTerminated();
}
Also used : Database(org.davidmoten.rx.jdbc.Database) Connection(java.sql.Connection) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 2 with Database

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

the class PoolTest method testConnectionPoolRecylesFirst.

@Test
public void testConnectionPoolRecylesFirst() {
    Database db = DatabaseCreator.create(2);
    TestSubscriber<Connection> ts = //
    db.connections().doOnNext(//
    System.out::println).doOnNext(c -> {
        c.close();
    }).test(//
    4);
    //
    ts.assertValueCount(4).assertNotTerminated();
    List<Object> list = ts.getEvents().get(0);
    // all 4 connections released were the same
    assertTrue(list.get(0) == list.get(1));
    assertTrue(list.get(0) == list.get(2));
    assertTrue(list.get(0) == list.get(3));
}
Also used : NonBlockingPool(org.davidmoten.rx.pool.NonBlockingPool) Arrays(java.util.Arrays) Connection(java.sql.Connection) Database(org.davidmoten.rx.jdbc.Database) Pool(org.davidmoten.rx.pool.Pool) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) MemberFactory(org.davidmoten.rx.pool.MemberFactory) ArrayList(java.util.ArrayList) SQLException(java.sql.SQLException) List(java.util.List) NonBlockingMember(org.davidmoten.rx.pool.NonBlockingMember) Flowable(io.reactivex.Flowable) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Schedulers(io.reactivex.schedulers.Schedulers) TestSubscriber(io.reactivex.subscribers.TestSubscriber) Database(org.davidmoten.rx.jdbc.Database) Connection(java.sql.Connection) Test(org.junit.Test)

Aggregations

Connection (java.sql.Connection)2 ArrayList (java.util.ArrayList)2 Database (org.davidmoten.rx.jdbc.Database)2 Test (org.junit.Test)2 Flowable (io.reactivex.Flowable)1 Schedulers (io.reactivex.schedulers.Schedulers)1 TestSubscriber (io.reactivex.subscribers.TestSubscriber)1 SQLException (java.sql.SQLException)1 Arrays (java.util.Arrays)1 List (java.util.List)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 MemberFactory (org.davidmoten.rx.pool.MemberFactory)1 NonBlockingMember (org.davidmoten.rx.pool.NonBlockingMember)1 NonBlockingPool (org.davidmoten.rx.pool.NonBlockingPool)1 Pool (org.davidmoten.rx.pool.Pool)1 Assert.assertTrue (org.junit.Assert.assertTrue)1