Search in sources :

Example 11 with ComponentLifecycle

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

the class JdbcServiceListTest method testServiceList_AdvancedPooledConnection.

@Test
public void testServiceList_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(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) AdvancedJdbcPooledConnection(com.adaptris.core.jdbc.AdvancedJdbcPooledConnection) 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) Test(org.junit.Test)

Example 12 with ComponentLifecycle

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

the class MetadataIdentitySequenceNumberServiceTest 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++) {
            MetadataIdentitySequenceNumberService service = configureForTests(createService(), false);
            service.setConnection(conn);
            serviceList.add(service);
            start(service);
        }
        PooledConnectionHelper.executeTest(serviceList, iterations, new PooledConnectionHelper.MessageCreator() {

            @Override
            public AdaptrisMessage createMsgForPooledConnectionTest() throws Exception {
                AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage();
                msg.addMetadata(DEFAULT_IDENTITY_METADATA_KEY, new GuidGenerator().safeUUID());
                return msg;
            }
        });
        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) SQLException(java.sql.SQLException) ComponentLifecycle(com.adaptris.core.ComponentLifecycle) GuidGenerator(com.adaptris.util.GuidGenerator) Test(org.junit.Test)

Example 13 with ComponentLifecycle

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

the class LifecycleHelperTest method testLifecycle.

@Test
public void testLifecycle() throws Exception {
    StateManagedComponent stateManaged = new NullService();
    ComponentLifecycle noState = new ChannelList();
    try {
        initAndStart(stateManaged);
        initAndStart(noState);
        initAndStart(null);
        stopAndClose(null);
    } finally {
        stopAndClose(stateManaged);
        stopAndClose(noState);
    }
}
Also used : NullService(com.adaptris.core.NullService) ComponentLifecycle(com.adaptris.core.ComponentLifecycle) StateManagedComponent(com.adaptris.core.StateManagedComponent) ChannelList(com.adaptris.core.ChannelList) Test(org.junit.Test)

Example 14 with ComponentLifecycle

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

the class LoggingHelperTest method testFriendlyNameComponentLifecycle.

@Test
public void testFriendlyNameComponentLifecycle() throws Exception {
    assertEquals("", friendlyName((ComponentLifecycle) null));
    NullService service = new NullService();
    assertEquals("NullService", friendlyName((ComponentLifecycle) service));
    service.setUniqueId("testFriendlyNameService");
    assertEquals("NullService(testFriendlyNameService)", friendlyName((ComponentLifecycle) service));
    ComponentLifecycle mock = mock(ComponentLifecycle.class);
    assertNotNull(friendlyName(mock));
}
Also used : NullService(com.adaptris.core.NullService) ComponentLifecycle(com.adaptris.core.ComponentLifecycle) Test(org.junit.Test)

Example 15 with ComponentLifecycle

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

the class StoredProcedureProducerTest method testProduce_AdvancedPooledConnection.

@Test
public void testProduce_AdvancedPooledConnection() throws Exception {
    int maxServices = 5;
    final int iterations = 5;
    int poolsize = maxServices - 1;
    if (areTestsEnabled()) {
        List<Service> serviceList = new ArrayList<Service>();
        String name = Thread.currentThread().getName();
        Thread.currentThread().setName(getName());
        AdvancedJdbcPooledConnection conn = PooledConnectionHelper.createAdvancedPooledConnection(PROPERTIES.getProperty(JDBC_DRIVER), PROPERTIES.getProperty(JDBC_URL), poolsize);
        conn.setUsername(PROPERTIES.getProperty(JDBC_USER));
        conn.setPassword(PROPERTIES.getProperty(JDBC_PASSWORD));
        try {
            for (int i = 0; i < maxServices; i++) {
                JdbcStoredProcedureProducer spp = new JdbcStoredProcedureProducer();
                spp.setProcedureName(("one_in"));
                JdbcStringPayloadParameter inParameter = new JdbcStringPayloadParameter();
                inParameter.setName("xType");
                inParameter.setType(ParameterValueType.VARCHAR);
                AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage("Sold");
                InParameters inParameters = new InParameters();
                inParameters.add(inParameter);
                spp.setInParameters(inParameters);
                StandaloneProducer service = configureForTests(spp, false);
                service.setConnection(conn);
                serviceList.add(service);
                start(service);
            }
            PooledConnectionHelper.executeTest(serviceList, iterations, new PooledConnectionHelper.MessageCreator() {

                @Override
                public AdaptrisMessage createMsgForPooledConnectionTest() throws Exception {
                    return createMessage("Sold");
                }
            });
            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) ServiceException(com.adaptris.core.ServiceException) XPathExpressionException(javax.xml.xpath.XPathExpressionException) IOException(java.io.IOException) ComponentLifecycle(com.adaptris.core.ComponentLifecycle) StandaloneProducer(com.adaptris.core.StandaloneProducer) 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