Search in sources :

Example 1 with JmsTransactedWorkflow

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

the class ActiveMqJmsTransactedWorkflowTest method testHandleChannelUnavailable_Bug2343.

@Test
public void testHandleChannelUnavailable_Bug2343() throws Exception {
    int msgCount = 10;
    String destination = createSafeUniqueId(new Object());
    final Channel channel = createStartableChannel(activeMqBroker, true, "testHandleChannelUnavailable_Bug2343", destination);
    JmsTransactedWorkflow workflow = (JmsTransactedWorkflow) channel.getWorkflowList().get(0);
    workflow.setChannelUnavailableWaitInterval(new TimeInterval(1L, TimeUnit.SECONDS));
    try {
        channel.requestStart();
        channel.toggleAvailability(false);
        Timer t = new Timer();
        t.schedule(new TimerTask() {

            @Override
            public void run() {
                channel.toggleAvailability(true);
            }
        }, 666);
        StandaloneProducer sender = new StandaloneProducer(activeMqBroker.getJmsConnection(), new PtpProducer().withQueue((destination)));
        send(sender, msgCount);
        waitForMessages((MockMessageProducer) workflow.getProducer(), msgCount);
        assertEquals(msgCount, ((MockMessageProducer) workflow.getProducer()).getMessages().size());
    } finally {
        channel.requestClose();
    }
    assertEquals(0, activeMqBroker.messagesOnQueue(destination));
}
Also used : TimeInterval(com.adaptris.util.TimeInterval) Timer(java.util.Timer) TimerTask(java.util.TimerTask) MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) 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) Test(org.junit.Test)

Example 2 with JmsTransactedWorkflow

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

the class ActiveMqJmsTransactedWorkflowTest method testServiceExceptionNonStrictWithErrorHandler.

// In Non-Strict Mode, if you have configured an error handler, then
// the transaction is successful.
@Test
public void testServiceExceptionNonStrictWithErrorHandler() throws Exception {
    int msgCount = 10;
    String destination = createSafeUniqueId(new Object());
    MockMessageProducer meh = new MockMessageProducer();
    Channel channel = createStartableChannel(activeMqBroker, true, "testServiceExceptionNonStrictWithErrorHandler", destination);
    JmsTransactedWorkflow workflow = (JmsTransactedWorkflow) channel.getWorkflowList().get(0);
    workflow.setStrict(Boolean.FALSE);
    workflow.getServiceCollection().addService(new ThrowExceptionService(new ConfiguredException("Fail")));
    channel.setMessageErrorHandler(new StandardProcessingExceptionHandler(new ServiceList(new ArrayList<Service>(Arrays.asList(new Service[] { new StandaloneProducer(meh) })))));
    channel.prepare();
    try {
        channel.requestStart();
        StandaloneProducer sender = new StandaloneProducer(activeMqBroker.getJmsConnection(), new PtpProducer().withQueue((destination)));
        send(sender, msgCount);
        waitForMessages(meh, msgCount);
        assertEquals(0, ((MockMessageProducer) workflow.getProducer()).getMessages().size());
    } finally {
        channel.requestClose();
    }
    assertEquals(0, activeMqBroker.messagesOnQueue(destination));
}
Also used : MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) ThrowExceptionService(com.adaptris.core.services.exception.ThrowExceptionService) ServiceList(com.adaptris.core.ServiceList) MockChannel(com.adaptris.core.stubs.MockChannel) Channel(com.adaptris.core.Channel) JmsTransactedWorkflow(com.adaptris.core.jms.JmsTransactedWorkflow) ConfiguredException(com.adaptris.core.services.exception.ConfiguredException) Service(com.adaptris.core.Service) MockSkipProducerService(com.adaptris.core.stubs.MockSkipProducerService) ThrowExceptionService(com.adaptris.core.services.exception.ThrowExceptionService) PtpProducer(com.adaptris.core.jms.PtpProducer) StandardProcessingExceptionHandler(com.adaptris.core.StandardProcessingExceptionHandler) StandaloneProducer(com.adaptris.core.StandaloneProducer) Test(org.junit.Test)

Example 3 with JmsTransactedWorkflow

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

the class ActiveMqJmsTransactedWorkflowTest method createWorkflow.

private JmsTransactedWorkflow createWorkflow(boolean isPtp, String threadName, String target) throws CoreException {
    JmsTransactedWorkflow workflow = new JmsTransactedWorkflow();
    workflow.setWaitPeriodAfterRollback(new TimeInterval(10L, TimeUnit.MILLISECONDS.name()));
    workflow.setProducer(new MockMessageProducer());
    JmsConsumerImpl jmsCons = isPtp ? new PtpConsumer().withQueue(target) : new PasConsumer().withTopic(target);
    jmsCons.setMessageTranslator(new TextMessageTranslator().withMoveJmsHeaders(true));
    workflow.setConsumer(jmsCons);
    return workflow;
}
Also used : PtpConsumer(com.adaptris.core.jms.PtpConsumer) TimeInterval(com.adaptris.util.TimeInterval) MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) PasConsumer(com.adaptris.core.jms.PasConsumer) TextMessageTranslator(com.adaptris.core.jms.TextMessageTranslator) JmsTransactedWorkflow(com.adaptris.core.jms.JmsTransactedWorkflow) JmsConsumerImpl(com.adaptris.core.jms.JmsConsumerImpl)

Example 4 with JmsTransactedWorkflow

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

the class ActiveMqJmsTransactedWorkflowTest method testMessagesRolledBackUsingTopic.

@Test
public void testMessagesRolledBackUsingTopic() throws Exception {
    int msgCount = 10;
    String destination = createSafeUniqueId(new Object());
    Channel channel = createStartableChannel(activeMqBroker, false, "testMessagesRolledBackUsingTopic", destination);
    JmsTransactedWorkflow workflow = (JmsTransactedWorkflow) channel.getWorkflowList().get(0);
    workflow.getServiceCollection().addService(new ThrowExceptionService(new ConfiguredException("Fail")));
    try {
        channel.requestStart();
        StandaloneProducer sender = new StandaloneProducer(activeMqBroker.getJmsConnection(), new PasProducer().withTopic(destination));
        send(sender, msgCount);
        assertEquals(0, ((MockMessageProducer) workflow.getProducer()).getMessages().size());
    } finally {
        channel.requestClose();
    }
// can't actually check the count of messsages on a topic, that's a trifle
// silly; you might check per-subscription...
// assertEquals(msgCount, activeMqBroker.messageCount(get(TOPIC)));
}
Also used : MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) ThrowExceptionService(com.adaptris.core.services.exception.ThrowExceptionService) MockChannel(com.adaptris.core.stubs.MockChannel) Channel(com.adaptris.core.Channel) JmsTransactedWorkflow(com.adaptris.core.jms.JmsTransactedWorkflow) ConfiguredException(com.adaptris.core.services.exception.ConfiguredException) PasProducer(com.adaptris.core.jms.PasProducer) StandaloneProducer(com.adaptris.core.StandaloneProducer) Test(org.junit.Test)

Example 5 with JmsTransactedWorkflow

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

the class ActiveMqJmsTransactedWorkflowTest method testMessagesRolledBackUsingQueue.

@Test
public void testMessagesRolledBackUsingQueue() throws Exception {
    int msgCount = 10;
    String destination = createSafeUniqueId(new Object());
    Channel channel = createStartableChannel(activeMqBroker, true, "testMessagesRolledBackUsingQueue", destination);
    JmsTransactedWorkflow workflow = (JmsTransactedWorkflow) channel.getWorkflowList().get(0);
    workflow.getServiceCollection().addService(new ThrowExceptionService(new ConfiguredException("Fail")));
    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 : ThrowExceptionService(com.adaptris.core.services.exception.ThrowExceptionService) MockChannel(com.adaptris.core.stubs.MockChannel) Channel(com.adaptris.core.Channel) JmsTransactedWorkflow(com.adaptris.core.jms.JmsTransactedWorkflow) ConfiguredException(com.adaptris.core.services.exception.ConfiguredException) PtpProducer(com.adaptris.core.jms.PtpProducer) 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