Search in sources :

Example 11 with JmsTransactedWorkflow

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

the class ActiveMqJmsTransactedWorkflowTest method testMessagesCommittedUsingTopic.

@Test
public void testMessagesCommittedUsingTopic() throws Exception {
    int msgCount = 10;
    String destination = createSafeUniqueId(new Object());
    Channel channel = createStartableChannel(activeMqBroker, false, "testMessagesCommittedUsingTopic", destination);
    JmsTransactedWorkflow workflow = (JmsTransactedWorkflow) channel.getWorkflowList().get(0);
    try {
        channel.requestStart();
        StandaloneProducer sender = new StandaloneProducer(activeMqBroker.getJmsConnection(), new PasProducer().withTopic(destination));
        send(sender, msgCount);
        waitForMessages((MockMessageProducer) workflow.getProducer(), msgCount);
        assertEquals(msgCount, ((MockMessageProducer) workflow.getProducer()).getMessages().size());
    } finally {
        channel.requestClose();
    }
}
Also used : MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) MockChannel(com.adaptris.core.stubs.MockChannel) Channel(com.adaptris.core.Channel) JmsTransactedWorkflow(com.adaptris.core.jms.JmsTransactedWorkflow) PasProducer(com.adaptris.core.jms.PasProducer) StandaloneProducer(com.adaptris.core.StandaloneProducer) Test(org.junit.Test)

Example 12 with JmsTransactedWorkflow

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

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

the class ActiveMqJmsTransactedWorkflowTest method testProduceException.

@Test
public void testProduceException() throws Exception {
    int msgCount = 10;
    String destination = createSafeUniqueId(new Object());
    Channel channel = createStartableChannel(activeMqBroker, true, "testProduceException", destination);
    JmsTransactedWorkflow workflow = (JmsTransactedWorkflow) channel.getWorkflowList().get(0);
    workflow.setProducer(new MockMessageProducer() {

        @Override
        protected void doProduce(AdaptrisMessage msg, String endpoint) throws ProduceException {
            throw new ProduceException();
        }
    });
    try {
        channel.requestStart();
        StandaloneProducer sender = new StandaloneProducer(activeMqBroker.getJmsConnection(), new PtpProducer().withQueue((destination)));
        send(sender, msgCount);
    } finally {
        channel.requestClose();
    }
    assertEquals(msgCount, activeMqBroker.messagesOnQueue(destination));
}
Also used : MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) MockChannel(com.adaptris.core.stubs.MockChannel) Channel(com.adaptris.core.Channel) JmsTransactedWorkflow(com.adaptris.core.jms.JmsTransactedWorkflow) PtpProducer(com.adaptris.core.jms.PtpProducer) StandaloneProducer(com.adaptris.core.StandaloneProducer) ProduceException(com.adaptris.core.ProduceException) Test(org.junit.Test)

Example 14 with JmsTransactedWorkflow

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

the class ActiveMqJmsTransactedWorkflowTest method testWorkflowWithInterceptor.

@Test
public void testWorkflowWithInterceptor() throws Exception {
    int msgCount = 10;
    String destination = createSafeUniqueId(new Object());
    Channel channel = createStartableChannel(activeMqBroker, false, "testMessagesCommittedUsingTopic", destination);
    JmsTransactedWorkflow workflow = (JmsTransactedWorkflow) channel.getWorkflowList().get(0);
    MockWorkflowInterceptor interceptor = new MockWorkflowInterceptor();
    workflow.addInterceptor(interceptor);
    try {
        channel.requestStart();
        StandaloneProducer sender = new StandaloneProducer(activeMqBroker.getJmsConnection(), new PasProducer().withTopic(destination));
        send(sender, msgCount);
        waitForMessages((MockMessageProducer) workflow.getProducer(), msgCount);
        assertEquals(msgCount, ((MockMessageProducer) workflow.getProducer()).getMessages().size());
        assertEquals(msgCount, interceptor.messageCount());
    } finally {
        channel.requestClose();
    }
}
Also used : MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) MockChannel(com.adaptris.core.stubs.MockChannel) Channel(com.adaptris.core.Channel) JmsTransactedWorkflow(com.adaptris.core.jms.JmsTransactedWorkflow) PasProducer(com.adaptris.core.jms.PasProducer) MockWorkflowInterceptor(com.adaptris.core.stubs.MockWorkflowInterceptor) StandaloneProducer(com.adaptris.core.StandaloneProducer) Test(org.junit.Test)

Example 15 with JmsTransactedWorkflow

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

the class ActiveMqJmsTransactedWorkflowTest method testMessagesOrderedUsingTopic.

@Test
public void testMessagesOrderedUsingTopic() throws Exception {
    int msgCount = 10;
    String destination = createSafeUniqueId(new Object());
    Channel channel = createStartableChannel(activeMqBroker, false, "testMessagesOrderedUsingTopic", destination);
    JmsTransactedWorkflow workflow = (JmsTransactedWorkflow) channel.getWorkflowList().get(0);
    workflow.getServiceCollection().addService(new RandomlyFail());
    try {
        channel.requestStart();
        StandaloneProducer sender = new StandaloneProducer(activeMqBroker.getJmsConnection(), new PasProducer().withTopic(destination));
        start(sender);
        for (int i = 0; i < msgCount; i++) {
            sender.doService(AdaptrisMessageFactory.getDefaultInstance().newMessage("" + i));
        }
        stop(sender);
        waitForMessages((MockMessageProducer) workflow.getProducer(), msgCount);
        List<AdaptrisMessage> receivedList = ((MockMessageProducer) workflow.getProducer()).getMessages();
        assertEquals(msgCount, receivedList.size());
        for (int i = 0; i < msgCount; i++) {
            assertEquals(String.valueOf(i), receivedList.get(i).getContent());
        }
    } finally {
        channel.requestClose();
    }
}
Also used : MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) MockChannel(com.adaptris.core.stubs.MockChannel) Channel(com.adaptris.core.Channel) JmsTransactedWorkflow(com.adaptris.core.jms.JmsTransactedWorkflow) PasProducer(com.adaptris.core.jms.PasProducer) StandaloneProducer(com.adaptris.core.StandaloneProducer) Test(org.junit.Test)

Aggregations

JmsTransactedWorkflow (com.adaptris.core.jms.JmsTransactedWorkflow)18 Channel (com.adaptris.core.Channel)16 StandaloneProducer (com.adaptris.core.StandaloneProducer)16 MockChannel (com.adaptris.core.stubs.MockChannel)16 Test (org.junit.Test)16 MockMessageProducer (com.adaptris.core.stubs.MockMessageProducer)15 PtpProducer (com.adaptris.core.jms.PtpProducer)12 ThrowExceptionService (com.adaptris.core.services.exception.ThrowExceptionService)7 ConfiguredException (com.adaptris.core.services.exception.ConfiguredException)6 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)5 PasProducer (com.adaptris.core.jms.PasProducer)4 TimeInterval (com.adaptris.util.TimeInterval)4 Service (com.adaptris.core.Service)3 MockSkipProducerService (com.adaptris.core.stubs.MockSkipProducerService)3 ProduceException (com.adaptris.core.ProduceException)2 ServiceList (com.adaptris.core.ServiceList)2 StandardProcessingExceptionHandler (com.adaptris.core.StandardProcessingExceptionHandler)2 TextMessageTranslator (com.adaptris.core.jms.TextMessageTranslator)2 Timer (java.util.Timer)2 TimerTask (java.util.TimerTask)2