Search in sources :

Example 16 with ComponentLifecycle

use of com.adaptris.core.ComponentLifecycle 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

ComponentLifecycle (com.adaptris.core.ComponentLifecycle)16 Test (org.junit.Test)16 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)14 Service (com.adaptris.core.Service)14 ArrayList (java.util.ArrayList)14 AdvancedJdbcPooledConnection (com.adaptris.core.jdbc.AdvancedJdbcPooledConnection)12 PooledConnectionHelper (com.adaptris.core.jdbc.PooledConnectionHelper)12 ServiceException (com.adaptris.core.ServiceException)8 JdbcPooledConnection (com.adaptris.core.jdbc.JdbcPooledConnection)6 GuidGenerator (com.adaptris.util.GuidGenerator)6 NullService (com.adaptris.core.NullService)4 StandaloneProducer (com.adaptris.core.StandaloneProducer)2 JdbcService (com.adaptris.core.jdbc.JdbcService)2 AddTimestampMetadataService (com.adaptris.core.services.metadata.AddTimestampMetadataService)2 IOException (java.io.IOException)2 SQLException (java.sql.SQLException)2 XPathExpressionException (javax.xml.xpath.XPathExpressionException)2 ChannelList (com.adaptris.core.ChannelList)1 StateManagedComponent (com.adaptris.core.StateManagedComponent)1