Search in sources :

Example 1 with AdvancedJdbcPooledConnection

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

the class JdbcDataCaptureServiceCase 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 = createAdvancedPooledJdbcConnection(poolsize);
    try {
        for (int i = 0; i < maxServices; i++) {
            JdbcIteratingDataCaptureServiceImpl service = createBasicService(false);
            service.setConnection(conn);
            serviceList.add(service);
            start(service);
        }
        PooledConnectionHelper.executeTest(serviceList, iterations, new PooledConnectionHelper.MessageCreator() {

            @Override
            public AdaptrisMessage createMsgForPooledConnectionTest() {
                AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(XML_DOCUMENT);
                msg.addMetadata(METADATA_KEY, METADATA_VALUE);
                return msg;
            }
        });
        assertEquals(0, conn.currentBusyConnectionCount());
        assertEquals(poolsize, conn.currentIdleConnectionCount());
        assertEquals(poolsize, conn.currentConnectionCount());
        doBasicCaptureAsserts(maxServices * iterations);
    } 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) ComponentLifecycle(com.adaptris.core.ComponentLifecycle) Service(com.adaptris.core.Service) JdbcService(com.adaptris.core.jdbc.JdbcService) PooledConnectionHelper(com.adaptris.core.jdbc.PooledConnectionHelper) Test(org.junit.Test)

Example 2 with AdvancedJdbcPooledConnection

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

the class JdbcBatchingDataCaptureServiceTest method createAdvancedPooledJdbcConnection.

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

Example 3 with AdvancedJdbcPooledConnection

use of com.adaptris.core.jdbc.AdvancedJdbcPooledConnection 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 4 with AdvancedJdbcPooledConnection

use of com.adaptris.core.jdbc.AdvancedJdbcPooledConnection 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 5 with AdvancedJdbcPooledConnection

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

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 Test (org.junit.Test)6 ServiceException (com.adaptris.core.ServiceException)3 GuidGenerator (com.adaptris.util.GuidGenerator)3 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