use of com.adaptris.core.SharedConnection 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.SharedConnection in project interlok by adaptris.
the class ActiveJmsConnectionErrorHandlerTest method testActiveRestartSharedConnection_ChannelNotStarted.
@Test
public void testActiveRestartSharedConnection_ChannelNotStarted() throws Exception {
Adapter adapter = new Adapter();
adapter.setUniqueId(testName.getMethodName());
JmsConnection connection = activeMqBroker.getJmsConnection(new BasicActiveMqImplementation(), true);
connection.setConnectionErrorHandler(createErrorHandler());
connection.setConnectionAttempts(null);
connection.setUniqueId(testName.getMethodName());
connection.setConnectionRetryInterval(new TimeInterval(5L, "SECONDS"));
adapter.getSharedComponents().addConnection(connection);
MockChannel started = createChannel(activeMqBroker, new SharedConnection(testName.getMethodName()), testName.getMethodName());
MockChannel neverStarted = createChannel(activeMqBroker, new SharedConnection(testName.getMethodName()), testName.getMethodName() + "_2");
neverStarted.setAutoStart(false);
MockMessageProducer producer = (MockMessageProducer) started.getWorkflowList().get(0).getProducer();
adapter.getChannelList().add(started);
adapter.getChannelList().add(neverStarted);
try {
adapter.requestStart();
assertEquals(StartedState.getInstance(), started.retrieveComponentState());
assertEquals(ClosedState.getInstance(), neverStarted.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(), started);
log.trace(testName.getMethodName() + ": Channel appears to be not started now, and I waited for " + totalWaitTime);
activeMqBroker.start();
totalWaitTime = waitForChannelToMatchState(StartedState.getInstance(), started);
log.trace(testName.getMethodName() + ": Channel now started now, and I waited for " + totalWaitTime);
assertEquals(StartedState.getInstance(), started.retrieveComponentState());
// Now try and send a message
ExampleServiceCase.execute(createProducer(activeMqBroker, testName.getMethodName()), AdaptrisMessageFactory.getDefaultInstance().newMessage("ABC"));
waitForMessages(producer, 2);
assertEquals(ClosedState.getInstance(), neverStarted.retrieveComponentState());
assertEquals(0, neverStarted.getInitCount());
} finally {
adapter.requestClose();
}
}
use of com.adaptris.core.SharedConnection in project interlok by adaptris.
the class SharedConnectionConfigurationCheckerTest method testProduceConnectionNoShared.
@Test
public void testProduceConnectionNoShared() throws Exception {
BootstrapProperties mockBootProperties = new MockBootProperties(createAdapterConfig(null, null, new SharedConnection("DoesNotExist"), null));
ConfigurationCheckReport report = checker.performConfigCheck(mockBootProperties);
assertFalse(report.isCheckPassed());
assertTrue(report.getFailureExceptions().size() > 0);
}
Aggregations