use of com.adaptris.util.TimeInterval in project interlok by adaptris.
the class ActiveMqPasPollingConsumerTest method createStandalone.
private StandaloneConsumer createStandalone(EmbeddedActiveMq mq, String threadName, String destinationName) throws Exception {
PasPollingConsumer consumer = new PasPollingConsumer().withTopic(destinationName);
consumer.setPoller(new Sometime());
JmsConnection c = mq.getJmsConnection();
consumer.setVendorImplementation(c.getVendorImplementation());
consumer.setClientId(c.getClientId());
consumer.setSubscriptionId(MY_SUBSCRIPTION_ID);
consumer.setReacquireLockBetweenMessages(true);
consumer.setAdditionalDebug(true);
consumer.setReceiveTimeout(new TimeInterval(Integer.valueOf(new Random().nextInt(100) + 100).longValue(), TimeUnit.MILLISECONDS));
StandaloneConsumer sc = new StandaloneConsumer(consumer);
return sc;
}
use of com.adaptris.util.TimeInterval in project interlok by adaptris.
the class ActiveJmsConnectionErrorHandlerTest method createErrorHandler.
private ActiveJmsConnectionErrorHandler createErrorHandler() {
ActiveJmsConnectionErrorHandler handler = new ActiveJmsConnectionErrorHandler();
handler.setAdditionalLogging(true);
handler.setCheckInterval(new TimeInterval(500L, TimeUnit.MILLISECONDS));
return handler;
}
use of com.adaptris.util.TimeInterval in project interlok by adaptris.
the class ActiveJmsConnectionErrorHandlerTest method createChannel.
private MockChannel createChannel(EmbeddedActiveMq mq, JmsConnection con, String destName) throws Exception {
MockChannel result = new MockChannel();
result.setUniqueId(testName.getMethodName() + "_channel");
con.setConnectionRetryInterval(new TimeInterval(100L, TimeUnit.MILLISECONDS.name()));
con.setConnectionAttempts(50);
con.setConnectionErrorHandler(createErrorHandler());
result.setConsumeConnection(con);
Workflow workflow = createWorkflow(mq, destName);
result.getWorkflowList().add(workflow);
return result;
}
use of com.adaptris.util.TimeInterval 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.util.TimeInterval in project interlok by adaptris.
the class ActiveJmsConnectionErrorHandlerTest method testConnectionErrorHandlerWhileConnectionIsClosed.
@Test
public void testConnectionErrorHandlerWhileConnectionIsClosed() throws Exception {
String queueName = testName.getMethodName() + "_queue";
String topicName = testName.getMethodName() + "_topic";
JmsConnection jmsCon = activeMqBroker.getJndiPasConnection(new StandardJndiImplementation(), false, queueName, topicName);
jmsCon.setConnectionAttempts(null);
MockChannel channel = createChannel(activeMqBroker, jmsCon, topicName);
try {
ActiveJmsConnectionErrorHandler handler = new ActiveJmsConnectionErrorHandler();
handler.setCheckInterval(new TimeInterval(100L, TimeUnit.MILLISECONDS));
handler.setAdditionalLogging(Boolean.TRUE);
channel.getConsumeConnection().setConnectionErrorHandler(handler);
channel.requestStart();
assertEquals(StartedState.getInstance(), channel.retrieveComponentState());
channel.requestClose();
activeMqBroker.stop();
activeMqBroker.start();
assertEquals(ClosedState.getInstance(), channel.retrieveComponentState());
} finally {
channel.requestClose();
}
}
Aggregations