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));
}
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));
}
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;
}
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)));
}
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));
}
Aggregations