Search in sources :

Example 6 with ComponentLifecycle

use of com.adaptris.core.ComponentLifecycle in project interlok by adaptris.

the class StaticIdentitySequenceNumberServiceTest 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<Service>();
    String name = Thread.currentThread().getName();
    Thread.currentThread().setName(getName());
    JdbcPooledConnection conn = PooledConnectionHelper.createPooledConnection(PROPERTIES.getProperty(JDBC_SEQUENCENUMBER_DRIVER), PROPERTIES.getProperty(JDBC_SEQUENCENUMBER_URL), poolsize);
    try {
        for (int i = 0; i < maxServices; i++) {
            StaticIdentitySequenceNumberService service = createServiceForTests(false);
            service.setConnection(conn);
            service.setIdentity(new GuidGenerator().safeUUID());
            serviceList.add(service);
            start(service);
        }
        PooledConnectionHelper.executeTest(serviceList, iterations, new PooledConnectionHelper.MessageCreator() {

            @Override
            public AdaptrisMessage createMsgForPooledConnectionTest() throws Exception {
                return createMessageForTests();
            }
        });
        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) ServiceException(com.adaptris.core.ServiceException) ComponentLifecycle(com.adaptris.core.ComponentLifecycle) GuidGenerator(com.adaptris.util.GuidGenerator) JdbcPooledConnection(com.adaptris.core.jdbc.JdbcPooledConnection) AdvancedJdbcPooledConnection(com.adaptris.core.jdbc.AdvancedJdbcPooledConnection) Test(org.junit.Test)

Example 7 with ComponentLifecycle

use of com.adaptris.core.ComponentLifecycle in project interlok by adaptris.

the class StaticIdentitySequenceNumberServiceTest method testService_AdvancedPooledConnection.

@Test
public void testService_AdvancedPooledConnection() throws Exception {
    int maxServices = 5;
    final int iterations = 5;
    int poolsize = maxServices - 1;
    createDatabase();
    List<Service> serviceList = new ArrayList<Service>();
    String name = Thread.currentThread().getName();
    Thread.currentThread().setName(getName());
    AdvancedJdbcPooledConnection conn = PooledConnectionHelper.createAdvancedPooledConnection(PROPERTIES.getProperty(JDBC_SEQUENCENUMBER_DRIVER), PROPERTIES.getProperty(JDBC_SEQUENCENUMBER_URL), poolsize);
    try {
        for (int i = 0; i < maxServices; i++) {
            StaticIdentitySequenceNumberService service = createServiceForTests(false);
            service.setConnection(conn);
            service.setIdentity(new GuidGenerator().safeUUID());
            serviceList.add(service);
            start(service);
        }
        PooledConnectionHelper.executeTest(serviceList, iterations, new PooledConnectionHelper.MessageCreator() {

            @Override
            public AdaptrisMessage createMsgForPooledConnectionTest() throws Exception {
                return createMessageForTests();
            }
        });
        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) AdvancedJdbcPooledConnection(com.adaptris.core.jdbc.AdvancedJdbcPooledConnection) Service(com.adaptris.core.Service) PooledConnectionHelper(com.adaptris.core.jdbc.PooledConnectionHelper) ServiceException(com.adaptris.core.ServiceException) ComponentLifecycle(com.adaptris.core.ComponentLifecycle) GuidGenerator(com.adaptris.util.GuidGenerator) Test(org.junit.Test)

Example 8 with ComponentLifecycle

use of com.adaptris.core.ComponentLifecycle in project interlok by adaptris.

the class JdbcRawDataCaptureServiceTest method testService_AdvancedPooledConnection.

@Test
public void testService_AdvancedPooledConnection() 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());
    AdvancedJdbcPooledConnection conn = PooledConnectionHelper.createAdvancedPooledConnection(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) AdvancedJdbcPooledConnection(com.adaptris.core.jdbc.AdvancedJdbcPooledConnection) Service(com.adaptris.core.Service) AddTimestampMetadataService(com.adaptris.core.services.metadata.AddTimestampMetadataService) PooledConnectionHelper(com.adaptris.core.jdbc.PooledConnectionHelper) ComponentLifecycle(com.adaptris.core.ComponentLifecycle) Test(org.junit.Test)

Example 9 with ComponentLifecycle

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

use of com.adaptris.core.ComponentLifecycle in project interlok by adaptris.

the class FirstRowMetadataTranslatorTest method testService_AdvancedPooledConnection.

@Test
public void testService_AdvancedPooledConnection() 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>();
    AdvancedJdbcPooledConnection conn = PooledConnectionHelper.createAdvancedPooledConnection(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) AdvancedJdbcPooledConnection(com.adaptris.core.jdbc.AdvancedJdbcPooledConnection) Service(com.adaptris.core.Service) PooledConnectionHelper(com.adaptris.core.jdbc.PooledConnectionHelper) ComponentLifecycle(com.adaptris.core.ComponentLifecycle) 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