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