use of com.adaptris.core.stubs.MockMessageProducer 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.stubs.MockMessageProducer 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.stubs.MockMessageProducer in project interlok by adaptris.
the class BasicActiveMqConsumerTest method testQueue_ProduceWhenConsumerStopped.
@Test
public void testQueue_ProduceWhenConsumerStopped() throws Exception {
PtpConsumer consumer = new PtpConsumer().withQueue(getName());
consumer.setAcknowledgeMode("AUTO_ACKNOWLEDGE");
StandardWorkflow workflow = new StandardWorkflow();
MockMessageProducer producer = new MockMessageProducer();
workflow.setConsumer(consumer);
workflow.setProducer(producer);
Channel channel = createChannel(activeMqBroker.getJmsConnection(createVendorImpl()), workflow);
try {
StandaloneProducer standaloneProducer = new StandaloneProducer(activeMqBroker.getJmsConnection(createVendorImpl()), new PtpProducer().withQueue((getName())));
channel.requestStart();
workflow.requestStop();
start(standaloneProducer);
AdaptrisMessage msg = createMessage(null);
standaloneProducer.produce(msg);
Thread.sleep(250);
assertEquals(0, producer.messageCount());
stop(standaloneProducer);
} finally {
channel.requestClose();
}
}
use of com.adaptris.core.stubs.MockMessageProducer in project interlok by adaptris.
the class ActiveJmsConnectionErrorHandlerTest method testActiveRestartSharedConnection.
@Test
public void testActiveRestartSharedConnection() throws Exception {
Adapter adapter = new Adapter();
adapter.setUniqueId(testName.getMethodName());
JmsConnection connection = activeMqBroker.getJmsConnection(new BasicActiveMqImplementation(), true);
connection.setConnectionErrorHandler(createErrorHandler());
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);
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();
}
}
use of com.adaptris.core.stubs.MockMessageProducer in project interlok by adaptris.
the class ActiveJmsConnectionErrorHandlerTest method createWorkflow.
private Workflow createWorkflow(EmbeddedActiveMq mq, String destName) throws Exception {
StandardWorkflow wf = new StandardWorkflow();
PasConsumer consumer = new PasConsumer().withTopic(destName);
wf.setProducer(new MockMessageProducer());
wf.setConsumer(consumer);
return wf;
}
Aggregations