Search in sources :

Example 11 with SharedConnection

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

the class JmsConnectionErrorHandlerTest method testRestartSharedConnection.

@Test
public void testRestartSharedConnection() throws Exception {
    Adapter adapter = new Adapter();
    adapter.setUniqueId(testName.getMethodName());
    JmsConnection connection = activeMqBroker.getJmsConnection(new BasicActiveMqImplementation(), true);
    connection.setConnectionErrorHandler(new JmsConnectionErrorHandler());
    connection.setUniqueId(testName.getMethodName());
    connection.setConnectionRetryInterval(new TimeInterval(5L, "SECONDS"));
    connection.setConnectionAttempts(null);
    adapter.getSharedComponents().addConnection(connection);
    MockChannel channel = createChannel(activeMqBroker, new SharedConnection(testName.getMethodName()), testName.getMethodName());
    MockMessageProducer producer = (MockMessageProducer) channel.getWorkflowList().get(0).getProducer();
    adapter.getChannelList().add(channel);
    try {
        adapter.requestStart();
        assertEquals(StartedState.getInstance(), channel.retrieveComponentState());
        // Now try and send a message
        ExampleServiceCase.execute(createProducer(activeMqBroker, testName.getMethodName()), AdaptrisMessageFactory.getDefaultInstance().newMessage("ABC"));
        waitForMessages(producer, 1);
        activeMqBroker.stop();
        log.trace(testName.getMethodName() + ": Waiting for channel death (i.e. !StartedState)");
        long totalWaitTime = waitForChannelToChangeState(StartedState.getInstance(), channel);
        log.trace(testName.getMethodName() + ": Channel appears to be not started now, and I waited for " + totalWaitTime);
        activeMqBroker.start();
        totalWaitTime = waitForChannelToMatchState(StartedState.getInstance(), channel);
        log.trace(testName.getMethodName() + ": Channel now started now, and I waited for " + totalWaitTime);
        waitForChannelToMatchState(StartedState.getInstance(), channel);
        assertEquals(StartedState.getInstance(), channel.retrieveComponentState());
        // Now try and send a message
        ExampleServiceCase.execute(createProducer(activeMqBroker, testName.getMethodName()), AdaptrisMessageFactory.getDefaultInstance().newMessage("ABC"));
        waitForMessages(producer, 2);
    } finally {
        adapter.requestClose();
    }
}
Also used : SharedConnection(com.adaptris.core.SharedConnection) MockChannel(com.adaptris.core.stubs.MockChannel) TimeInterval(com.adaptris.util.TimeInterval) MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) Adapter(com.adaptris.core.Adapter) JmsConnection(com.adaptris.core.jms.JmsConnection) JmsConnectionErrorHandler(com.adaptris.core.jms.JmsConnectionErrorHandler) Test(org.junit.Test)

Example 12 with SharedConnection

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

the class ActiveJmsConnectionErrorHandlerTest method testActiveRestartSharedConnection_ChannelNotStarted.

@Test
public void testActiveRestartSharedConnection_ChannelNotStarted() throws Exception {
    Adapter adapter = new Adapter();
    adapter.setUniqueId(testName.getMethodName());
    JmsConnection connection = activeMqBroker.getJmsConnection(new BasicActiveMqImplementation(), true);
    connection.setConnectionErrorHandler(createErrorHandler());
    connection.setConnectionAttempts(null);
    connection.setUniqueId(testName.getMethodName());
    connection.setConnectionRetryInterval(new TimeInterval(5L, "SECONDS"));
    adapter.getSharedComponents().addConnection(connection);
    MockChannel started = createChannel(activeMqBroker, new SharedConnection(testName.getMethodName()), testName.getMethodName());
    MockChannel neverStarted = createChannel(activeMqBroker, new SharedConnection(testName.getMethodName()), testName.getMethodName() + "_2");
    neverStarted.setAutoStart(false);
    MockMessageProducer producer = (MockMessageProducer) started.getWorkflowList().get(0).getProducer();
    adapter.getChannelList().add(started);
    adapter.getChannelList().add(neverStarted);
    try {
        adapter.requestStart();
        assertEquals(StartedState.getInstance(), started.retrieveComponentState());
        assertEquals(ClosedState.getInstance(), neverStarted.retrieveComponentState());
        // Now try and send a message
        ExampleServiceCase.execute(createProducer(activeMqBroker, testName.getMethodName()), AdaptrisMessageFactory.getDefaultInstance().newMessage("ABC"));
        waitForMessages(producer, 1);
        activeMqBroker.stop();
        log.trace(testName.getMethodName() + ": Waiting for channel death (i.e. !StartedState)");
        long totalWaitTime = waitForChannelToChangeState(StartedState.getInstance(), started);
        log.trace(testName.getMethodName() + ": Channel appears to be not started now, and I waited for " + totalWaitTime);
        activeMqBroker.start();
        totalWaitTime = waitForChannelToMatchState(StartedState.getInstance(), started);
        log.trace(testName.getMethodName() + ": Channel now started now, and I waited for " + totalWaitTime);
        assertEquals(StartedState.getInstance(), started.retrieveComponentState());
        // Now try and send a message
        ExampleServiceCase.execute(createProducer(activeMqBroker, testName.getMethodName()), AdaptrisMessageFactory.getDefaultInstance().newMessage("ABC"));
        waitForMessages(producer, 2);
        assertEquals(ClosedState.getInstance(), neverStarted.retrieveComponentState());
        assertEquals(0, neverStarted.getInitCount());
    } finally {
        adapter.requestClose();
    }
}
Also used : SharedConnection(com.adaptris.core.SharedConnection) MockChannel(com.adaptris.core.stubs.MockChannel) TimeInterval(com.adaptris.util.TimeInterval) MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) Adapter(com.adaptris.core.Adapter) JmsConnection(com.adaptris.core.jms.JmsConnection) Test(org.junit.Test)

Example 13 with SharedConnection

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

the class SharedConnectionConfigurationCheckerTest method testProduceConnectionNoShared.

@Test
public void testProduceConnectionNoShared() throws Exception {
    BootstrapProperties mockBootProperties = new MockBootProperties(createAdapterConfig(null, null, new SharedConnection("DoesNotExist"), null));
    ConfigurationCheckReport report = checker.performConfigCheck(mockBootProperties);
    assertFalse(report.isCheckPassed());
    assertTrue(report.getFailureExceptions().size() > 0);
}
Also used : SharedConnection(com.adaptris.core.SharedConnection) BootstrapProperties(com.adaptris.core.management.BootstrapProperties) Test(org.junit.Test)

Aggregations

SharedConnection (com.adaptris.core.SharedConnection)13 Test (org.junit.Test)12 Adapter (com.adaptris.core.Adapter)7 NullConnection (com.adaptris.core.NullConnection)6 BootstrapProperties (com.adaptris.core.management.BootstrapProperties)5 JmsConnection (com.adaptris.core.jms.JmsConnection)4 MockChannel (com.adaptris.core.stubs.MockChannel)4 MockMessageProducer (com.adaptris.core.stubs.MockMessageProducer)4 TimeInterval (com.adaptris.util.TimeInterval)4 ArrayList (java.util.ArrayList)4 AdaptrisMarshaller (com.adaptris.core.AdaptrisMarshaller)3 Channel (com.adaptris.core.Channel)3 StandardWorkflow (com.adaptris.core.StandardWorkflow)3 MockServiceWithConnection (com.adaptris.core.stubs.MockServiceWithConnection)3 ObjectName (javax.management.ObjectName)3 JmsConnectionErrorHandler (com.adaptris.core.jms.JmsConnectionErrorHandler)2 MetadataElement (com.adaptris.core.MetadataElement)1 NullMessageProducer (com.adaptris.core.NullMessageProducer)1 ServiceList (com.adaptris.core.ServiceList)1 StandaloneProducer (com.adaptris.core.StandaloneProducer)1