Search in sources :

Example 6 with JdbcPooledConnection

use of com.adaptris.core.jdbc.JdbcPooledConnection in project interlok by adaptris.

the class FirstRowMetadataTranslatorTest method testService_PooledConnection.

@Test
public void testService_PooledConnection() throws Exception {
    int maxServices = 5;
    final int iterations = 5;
    int poolsize = maxServices - 1;
    String name = Thread.currentThread().getName();
    Thread.currentThread().setName(getName());
    createDatabase();
    List<AdapterTypeVersion> dbItems = generate(10);
    final AdapterTypeVersion entry = dbItems.get(0);
    populateDatabase(dbItems, false);
    List<Service> serviceList = new ArrayList<Service>();
    JdbcPooledConnection conn = PooledConnectionHelper.createPooledConnection(PROPERTIES.getProperty(JDBC_QUERYSERVICE_DRIVER), PROPERTIES.getProperty(JDBC_QUERYSERVICE_URL), poolsize);
    try {
        for (int i = 0; i < maxServices; i++) {
            JdbcDataQueryService service = createMetadataService(false);
            service.setConnection(conn);
            serviceList.add(service);
            start(service);
        }
        PooledConnectionHelper.executeTest(serviceList, iterations, new PooledConnectionHelper.MessageCreator() {

            @Override
            public AdaptrisMessage createMsgForPooledConnectionTest() throws Exception {
                return createMessage(entry);
            }
        });
        assertEquals(0, conn.currentBusyConnectionCount());
        assertEquals(poolsize, conn.currentIdleConnectionCount());
        assertEquals(poolsize, conn.currentConnectionCount());
    } finally {
        stop(serviceList.toArray(new ComponentLifecycle[0]));
        Thread.currentThread().setName(name);
    }
}
Also used : AdaptrisMessage(com.adaptris.core.AdaptrisMessage) ArrayList(java.util.ArrayList) Service(com.adaptris.core.Service) PooledConnectionHelper(com.adaptris.core.jdbc.PooledConnectionHelper) ComponentLifecycle(com.adaptris.core.ComponentLifecycle) AdvancedJdbcPooledConnection(com.adaptris.core.jdbc.AdvancedJdbcPooledConnection) JdbcPooledConnection(com.adaptris.core.jdbc.JdbcPooledConnection) Test(org.junit.Test)

Example 7 with JdbcPooledConnection

use of com.adaptris.core.jdbc.JdbcPooledConnection in project interlok by adaptris.

the class JdbcBatchingDataCaptureServiceTest method createPooledJdbcConnection.

@Override
protected JdbcPooledConnection createPooledJdbcConnection(int poolsize) {
    JdbcPooledConnection conn = PooledConnectionHelper.createPooledConnection(PROPERTIES.getProperty(JDBC_CAPTURE_SERVICE_DRIVER), PROPERTIES.getProperty(JDBC_CAPTURE_SERVICE_URL), poolsize);
    conn.setAutoCommit(false);
    return conn;
}
Also used : JdbcPooledConnection(com.adaptris.core.jdbc.JdbcPooledConnection) AdvancedJdbcPooledConnection(com.adaptris.core.jdbc.AdvancedJdbcPooledConnection)

Example 8 with JdbcPooledConnection

use of com.adaptris.core.jdbc.JdbcPooledConnection in project interlok by adaptris.

the class JndiHelperTest method testBindJdbcConnection.

@Test
public void testBindJdbcConnection() throws Exception {
    JdbcPooledConnection connection = new JdbcPooledConnection();
    connection.setConnectUrl("jdbc:derby:memory:" + new GuidGenerator().safeUUID() + ";create=true");
    connection.setDriverImp("org.apache.derby.jdbc.EmbeddedDriver");
    connection.setMinimumPoolSize(1);
    connection.setAcquireIncrement(1);
    connection.setMaximumPoolSize(7);
    connection.setUniqueId(getName());
    InitialContext initialContext = new InitialContext(env);
    try {
        JndiHelper.bind(initialContext, connection, true);
        JdbcPooledConnection lookedup = (JdbcPooledConnection) initialContext.lookup("adapter:comp/env/" + getName());
        assertEquals(getName(), lookedup.getUniqueId());
        assertNotNull(initialContext.lookup("adapter:comp/env/jdbc/" + getName()));
    } finally {
        JndiHelper.unbindQuietly(initialContext, connection, true);
    }
    try {
        JndiHelper.bind(initialContext, connection, false);
        JdbcPooledConnection lookedup = (JdbcPooledConnection) initialContext.lookup("adapter:comp/env/" + getName());
        assertEquals(getName(), lookedup.getUniqueId());
        assertNotNull(initialContext.lookup("adapter:comp/env/jdbc/" + getName()));
    } finally {
        JndiHelper.unbindQuietly(initialContext, connection, false);
    }
}
Also used : GuidGenerator(com.adaptris.util.GuidGenerator) InitialContext(javax.naming.InitialContext) JdbcPooledConnection(com.adaptris.core.jdbc.JdbcPooledConnection) Test(org.junit.Test)

Example 9 with JdbcPooledConnection

use of com.adaptris.core.jdbc.JdbcPooledConnection in project interlok by adaptris.

the class JdbcRawDataCaptureServiceTest method testService_PooledConnection.

@Test
public void testService_PooledConnection() throws Exception {
    int maxServices = 5;
    final int iterations = 5;
    int poolsize = maxServices - 1;
    createDatabase();
    List<Service> serviceList = new ArrayList<>();
    String name = Thread.currentThread().getName();
    Thread.currentThread().setName(getName());
    JdbcPooledConnection conn = PooledConnectionHelper.createPooledConnection(PROPERTIES.getProperty(JDBC_CAPTURE_SERVICE_DRIVER), PROPERTIES.getProperty(JDBC_CAPTURE_SERVICE_URL), poolsize);
    try {
        for (int i = 0; i < maxServices; i++) {
            JdbcRawDataCaptureService service = createService(false);
            service.setConnection(conn);
            serviceList.add(service);
            start(service);
        }
        PooledConnectionHelper.executeTest(serviceList, iterations, new PooledConnectionHelper.MessageCreator() {

            @Override
            public AdaptrisMessage createMsgForPooledConnectionTest() throws Exception {
                return createMessage();
            }
        });
        assertEquals(0, conn.currentBusyConnectionCount());
        assertEquals(poolsize, conn.currentIdleConnectionCount());
        assertEquals(poolsize, conn.currentConnectionCount());
        doBasicCaptureAsserts(iterations * maxServices);
    } finally {
        stop(serviceList.toArray(new ComponentLifecycle[0]));
        Thread.currentThread().setName(name);
    }
}
Also used : AdaptrisMessage(com.adaptris.core.AdaptrisMessage) ArrayList(java.util.ArrayList) Service(com.adaptris.core.Service) AddTimestampMetadataService(com.adaptris.core.services.metadata.AddTimestampMetadataService) PooledConnectionHelper(com.adaptris.core.jdbc.PooledConnectionHelper) ComponentLifecycle(com.adaptris.core.ComponentLifecycle) AdvancedJdbcPooledConnection(com.adaptris.core.jdbc.AdvancedJdbcPooledConnection) JdbcPooledConnection(com.adaptris.core.jdbc.JdbcPooledConnection) Test(org.junit.Test)

Aggregations

JdbcPooledConnection (com.adaptris.core.jdbc.JdbcPooledConnection)9 Test (org.junit.Test)8 AdvancedJdbcPooledConnection (com.adaptris.core.jdbc.AdvancedJdbcPooledConnection)7 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)6 ComponentLifecycle (com.adaptris.core.ComponentLifecycle)6 Service (com.adaptris.core.Service)6 PooledConnectionHelper (com.adaptris.core.jdbc.PooledConnectionHelper)6 ArrayList (java.util.ArrayList)6 GuidGenerator (com.adaptris.util.GuidGenerator)5 ServiceException (com.adaptris.core.ServiceException)3 InitialContext (javax.naming.InitialContext)2 NullService (com.adaptris.core.NullService)1 JdbcService (com.adaptris.core.jdbc.JdbcService)1 AddTimestampMetadataService (com.adaptris.core.services.metadata.AddTimestampMetadataService)1 SQLException (java.sql.SQLException)1