use of com.adaptris.core.jms.JmsConnectionErrorHandler in project interlok by adaptris.
the class JmsConnectionErrorHandlerTest method testConnectionErrorHandler_WithRuntimeException.
// Tests INTERLOK-2063
@Test
public void testConnectionErrorHandler_WithRuntimeException() throws Exception {
MockChannel channel = createChannel(activeMqBroker, new JmsConnectionCloseWithRuntimeException(activeMqBroker.getJmsConnection(new BasicActiveMqImplementation(), true)), testName.getMethodName(), new JmsConnectionErrorHandler() {
@Override
protected long retryWaitTimeMs() {
return 500L;
}
});
try {
channel.requestStart();
assertEquals(StartedState.getInstance(), channel.retrieveComponentState());
activeMqBroker.stop();
Thread.sleep(1000);
activeMqBroker.start();
waitForChannelToMatchState(StartedState.getInstance(), channel);
assertEquals(StartedState.getInstance(), channel.retrieveComponentState());
assertEquals(2, channel.getStartCount());
} finally {
channel.requestClose();
}
}
use of com.adaptris.core.jms.JmsConnectionErrorHandler in project interlok by adaptris.
the class JmsConnectionErrorHandlerTest method testConnectionErrorHandler_NotSingleExecution.
@Test
public void testConnectionErrorHandler_NotSingleExecution() throws Exception {
MockChannel channel = createChannel(activeMqBroker, activeMqBroker.getJmsConnection(new BasicActiveMqImplementation(), true), testName.getMethodName(), new JmsConnectionErrorHandler(false));
try {
channel.requestStart();
assertEquals(StartedState.getInstance(), channel.retrieveComponentState());
activeMqBroker.stop();
Thread.sleep(1000);
activeMqBroker.start();
waitForChannelToMatchState(StartedState.getInstance(), channel);
assertEquals(StartedState.getInstance(), channel.retrieveComponentState());
assertEquals(2, channel.getStartCount());
} finally {
channel.requestClose();
}
}
use of com.adaptris.core.jms.JmsConnectionErrorHandler in project interlok by adaptris.
the class JmsConnectionErrorHandlerTest method testConnectionErrorHandler_WithStartException.
@Test
public void testConnectionErrorHandler_WithStartException() throws Exception {
MockChannel channel = new MockChannelFail(createChannel(activeMqBroker, activeMqBroker.getJmsConnection(new BasicActiveMqImplementation(), true), testName.getMethodName(), new JmsConnectionErrorHandler()), MockChannelFail.WhenToFail.START_AFTER_CLOSE);
try {
channel.requestStart();
assertEquals(StartedState.getInstance(), channel.retrieveComponentState());
activeMqBroker.stop();
Thread.sleep(1000);
activeMqBroker.start();
waitForChannelToMatchState(InitialisedState.getInstance(), channel);
assertEquals(InitialisedState.getInstance(), channel.retrieveComponentState());
assertEquals(1, channel.getStartCount());
assertEquals(2, channel.getInitCount());
} finally {
channel.requestClose();
}
}
use of com.adaptris.core.jms.JmsConnectionErrorHandler in project interlok by adaptris.
the class JmsConnectionErrorHandlerTest method testConnectionErrorHandler_WithInitialiseException.
@Test
public void testConnectionErrorHandler_WithInitialiseException() throws Exception {
MockChannel channel = new MockChannelFail(createChannel(activeMqBroker, activeMqBroker.getJmsConnection(new BasicActiveMqImplementation(), true), testName.getMethodName(), new JmsConnectionErrorHandler()), MockChannelFail.WhenToFail.INIT_AFTER_CLOSE);
try {
channel.requestStart();
assertEquals(StartedState.getInstance(), channel.retrieveComponentState());
activeMqBroker.stop();
Thread.sleep(1000);
activeMqBroker.start();
// This is a bit artificial, but we shouldn't ever transition from ClosedState.
Thread.sleep(1000);
waitForChannelToMatchState(ClosedState.getInstance(), channel);
assertEquals(ClosedState.getInstance(), channel.retrieveComponentState());
assertEquals(1, channel.getStartCount());
assertEquals(1, channel.getInitCount());
} finally {
channel.requestClose();
}
}
use of com.adaptris.core.jms.JmsConnectionErrorHandler 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();
}
}
Aggregations