Search in sources :

Example 16 with Service

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

the class JdbcServiceListTest method testServiceList_PooledConnection.

@Test
public void testServiceList_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(CFG_JDBC_DRIVER), PROPERTIES.getProperty(CFG_JDBC_URL), poolsize);
    try {
        GuidGenerator guid = new GuidGenerator();
        for (int i = 0; i < maxServices; i++) {
            // The Connection should never be used by the wrappedService, as it will exist in objectMetadata.
            JdbcServiceList service = createServiceCollection(createSequenceNumberService(conn, guid.safeUUID()), createSequenceNumberService(conn, guid.safeUUID()));
            service.setConnection(conn);
            serviceList.add(service);
            start(service);
        }
        PooledConnectionHelper.executeTest(serviceList, iterations, new PooledConnectionHelper.MessageCreator() {

            @Override
            public AdaptrisMessage createMsgForPooledConnectionTest() throws Exception {
                return AdaptrisMessageFactory.getDefaultInstance().newMessage();
            }
        });
        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) NullService(com.adaptris.core.NullService) 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) AdvancedJdbcPooledConnection(com.adaptris.core.jdbc.AdvancedJdbcPooledConnection) JdbcPooledConnection(com.adaptris.core.jdbc.JdbcPooledConnection) Test(org.junit.Test)

Example 17 with Service

use of com.adaptris.core.Service 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 18 with Service

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

the class JdbcDataCaptureServiceCase 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 = createPooledJdbcConnection(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) ComponentLifecycle(com.adaptris.core.ComponentLifecycle) Service(com.adaptris.core.Service) JdbcService(com.adaptris.core.jdbc.JdbcService) PooledConnectionHelper(com.adaptris.core.jdbc.PooledConnectionHelper) AdvancedJdbcPooledConnection(com.adaptris.core.jdbc.AdvancedJdbcPooledConnection) JdbcPooledConnection(com.adaptris.core.jdbc.JdbcPooledConnection) Test(org.junit.Test)

Example 19 with Service

use of com.adaptris.core.Service 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 20 with Service

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

Aggregations

Service (com.adaptris.core.Service)49 Test (org.junit.Test)38 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)28 ServiceList (com.adaptris.core.ServiceList)16 ArrayList (java.util.ArrayList)16 ComponentLifecycle (com.adaptris.core.ComponentLifecycle)14 AdvancedJdbcPooledConnection (com.adaptris.core.jdbc.AdvancedJdbcPooledConnection)12 PooledConnectionHelper (com.adaptris.core.jdbc.PooledConnectionHelper)12 ServiceException (com.adaptris.core.ServiceException)11 MetadataElement (com.adaptris.core.MetadataElement)10 NullService (com.adaptris.core.NullService)10 StandaloneProducer (com.adaptris.core.StandaloneProducer)10 AddMetadataService (com.adaptris.core.services.metadata.AddMetadataService)10 MockMessageProducer (com.adaptris.core.stubs.MockMessageProducer)9 LogMessageService (com.adaptris.core.services.LogMessageService)8 ThrowExceptionService (com.adaptris.core.services.exception.ThrowExceptionService)7 MockChannel (com.adaptris.core.stubs.MockChannel)7 StandardProcessingExceptionHandler (com.adaptris.core.StandardProcessingExceptionHandler)6 JdbcPooledConnection (com.adaptris.core.jdbc.JdbcPooledConnection)6 GuidGenerator (com.adaptris.util.GuidGenerator)6