Search in sources :

Example 26 with JmsConnection

use of com.adaptris.core.jms.JmsConnection in project interlok by adaptris.

the class ActiveMqJmsTransactedWorkflowTest method createPollingWorkflow.

private JmsTransactedWorkflow createPollingWorkflow(EmbeddedActiveMq mq, String threadName, String target) throws CoreException {
    JmsTransactedWorkflow workflow = new JmsTransactedWorkflow();
    workflow.setProducer(new MockMessageProducer());
    workflow.setWaitPeriodAfterRollback(new TimeInterval(10L, TimeUnit.MILLISECONDS.name()));
    JmsPollingConsumerImpl jmsCons = new PtpPollingConsumer().withQueue(target);
    jmsCons.setReacquireLockBetweenMessages(true);
    jmsCons.setAdditionalDebug(true);
    jmsCons.setPoller(new FixedIntervalPoller(new TimeInterval(2L, TimeUnit.SECONDS)));
    BasicActiveMqImplementation vendorImpl = new BasicActiveMqImplementation();
    JmsConnection jmsConn = mq.getJmsConnection(vendorImpl, true);
    jmsCons.setVendorImplementation(jmsConn.getVendorImplementation());
    jmsCons.setMessageTranslator(new TextMessageTranslator().withMoveJmsHeaders(true));
    jmsCons.setClientId(jmsConn.getClientId());
    workflow.setConsumer(jmsCons);
    return workflow;
}
Also used : JmsPollingConsumerImpl(com.adaptris.core.jms.JmsPollingConsumerImpl) MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) TimeInterval(com.adaptris.util.TimeInterval) TextMessageTranslator(com.adaptris.core.jms.TextMessageTranslator) PtpPollingConsumer(com.adaptris.core.jms.PtpPollingConsumer) JmsTransactedWorkflow(com.adaptris.core.jms.JmsTransactedWorkflow) JmsConnection(com.adaptris.core.jms.JmsConnection) FixedIntervalPoller(com.adaptris.core.FixedIntervalPoller)

Example 27 with JmsConnection

use of com.adaptris.core.jms.JmsConnection 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 28 with JmsConnection

use of com.adaptris.core.jms.JmsConnection in project interlok by adaptris.

the class ActiveJmsConnectionErrorHandlerTest method testConnectionErrorHandler.

@Test
public void testConnectionErrorHandler() throws Exception {
    String topicName = testName.getMethodName() + "_topic";
    JmsConnection jmsCon = activeMqBroker.getJmsConnection(new BasicActiveMqImplementation(), true);
    jmsCon.setConnectionAttempts(null);
    MockChannel channel = createChannel(activeMqBroker, jmsCon, topicName);
    try {
        channel.requestStart();
        assertEquals(StartedState.getInstance(), channel.retrieveComponentState());
        activeMqBroker.stop();
        log.trace("Waiting for channel death (i.e. !StartedState)");
        long totalWaitTime = waitForChannelToChangeState(StartedState.getInstance(), channel);
        log.trace("Channel appears to be not started now, and I waited for " + totalWaitTime);
        activeMqBroker.start();
        waitForChannelToMatchState(StartedState.getInstance(), channel);
        assertEquals(StartedState.getInstance(), channel.retrieveComponentState());
        assertEquals(2, channel.getStartCount());
    } finally {
        channel.requestClose();
    }
}
Also used : MockChannel(com.adaptris.core.stubs.MockChannel) JmsConnection(com.adaptris.core.jms.JmsConnection) Test(org.junit.Test)

Example 29 with JmsConnection

use of com.adaptris.core.jms.JmsConnection in project interlok by adaptris.

the class ActiveJmsConnectionErrorHandlerTest method createProducer.

private StandaloneProducer createProducer(EmbeddedActiveMq mq, String dest) {
    JmsConnection conn = mq.getJmsConnection(new BasicActiveMqImplementation(), true);
    conn.setConnectionErrorHandler(createErrorHandler());
    PasProducer producer = new PasProducer().withTopic(dest);
    return new StandaloneProducer(conn, producer);
}
Also used : JmsConnection(com.adaptris.core.jms.JmsConnection) PasProducer(com.adaptris.core.jms.PasProducer) StandaloneProducer(com.adaptris.core.StandaloneProducer)

Example 30 with JmsConnection

use of com.adaptris.core.jms.JmsConnection in project interlok by adaptris.

the class ActiveJmsConnectionErrorHandlerTest method testConnectionErrorHandlerWithJndi.

@Test
public void testConnectionErrorHandlerWithJndi() throws Exception {
    String oldName = Thread.currentThread().getName();
    Thread.currentThread().setName(testName.getMethodName());
    String queueName = testName.getMethodName() + "_queue";
    String topicName = testName.getMethodName() + "_topic";
    JmsConnection conn = activeMqBroker.getJndiPasConnection(new MyStandardJndiImpl(testName.getMethodName()), false, queueName, topicName);
    conn.setUniqueId(testName.getMethodName());
    conn.setConnectionAttempts(null);
    MockChannel channel = createChannel(activeMqBroker, conn, topicName);
    try {
        channel.requestStart();
        assertEquals(StartedState.getInstance(), channel.retrieveComponentState());
        activeMqBroker.stop();
        // Give the ErrorHandler time to check that it's stopped
        log.trace("Waiting for channel death (i.e. !StartedState)");
        long totalWaitTime = waitForChannelToChangeState(StartedState.getInstance(), channel);
        // assertNotSame(StartedState.getInstance(), channel.retrieveComponentState());
        log.trace("Channel appears to be not started now, and I waited for " + totalWaitTime);
        activeMqBroker.start();
        waitForChannelToMatchState(StartedState.getInstance(), channel);
        assertEquals(StartedState.getInstance(), channel.retrieveComponentState());
        assertEquals(2, channel.getStartCount());
    } finally {
        channel.requestClose();
        Thread.currentThread().setName(oldName);
    }
}
Also used : MockChannel(com.adaptris.core.stubs.MockChannel) JmsConnection(com.adaptris.core.jms.JmsConnection) Test(org.junit.Test)

Aggregations

JmsConnection (com.adaptris.core.jms.JmsConnection)47 Test (org.junit.Test)25 StandaloneProducer (com.adaptris.core.StandaloneProducer)17 StandardJndiImplementation (com.adaptris.core.jms.jndi.StandardJndiImplementation)14 TimeInterval (com.adaptris.util.TimeInterval)14 PasProducer (com.adaptris.core.jms.PasProducer)12 MockChannel (com.adaptris.core.stubs.MockChannel)10 StandaloneConsumer (com.adaptris.core.StandaloneConsumer)8 PtpProducer (com.adaptris.core.jms.PtpProducer)8 KeyValuePair (com.adaptris.util.KeyValuePair)6 Adapter (com.adaptris.core.Adapter)5 PtpConsumer (com.adaptris.core.jms.PtpConsumer)5 MockMessageProducer (com.adaptris.core.stubs.MockMessageProducer)5 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)4 DefaultMessageFactory (com.adaptris.core.DefaultMessageFactory)4 SharedConnection (com.adaptris.core.SharedConnection)4 MessageTypeTranslatorImp (com.adaptris.core.jms.MessageTypeTranslatorImp)4 UrlVendorImplementation (com.adaptris.core.jms.UrlVendorImplementation)4 MockMessageListener (com.adaptris.core.stubs.MockMessageListener)4 Message (javax.jms.Message)4