use of com.adaptris.core.SharedConnection 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.SharedConnection in project interlok by adaptris.
the class JmsConnectionErrorHandlerTest method testRestartSharedConnection_ChannelNotStarted.
@Test
public void testRestartSharedConnection_ChannelNotStarted() 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 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 ConfigurationCheckRunnerTest method testSuccessRunner.
@Test
@SuppressWarnings("deprecation")
public void testSuccessRunner() throws Exception {
String xml = this.createAdapterConfig(new NullConnection("SharedNullConnection"), new SharedConnection("SharedNullConnection"), new SharedConnection("SharedNullConnection"));
BootstrapProperties mockProp = new MockBootProperties(xml);
List<ConfigurationCheckReport> reports = checkRunner.runChecks(mockProp, mockUnifiedBootstrap);
assertEquals(configurationCheckersCount(), reports.size());
for (ConfigurationCheckReport report : reports) {
if (report.getCheckName().equals(SHARED_CONN_TEST_FRIENDLY_NAME)) {
assertTrue(report.isCheckPassed());
assertEquals(0, report.getFailureExceptions().size());
}
}
}
use of com.adaptris.core.SharedConnection in project interlok by adaptris.
the class SharedConnectionConfigurationCheckerTest method testProduceAndConsumeConnectionsExist.
@Test
public void testProduceAndConsumeConnectionsExist() throws Exception {
BootstrapProperties mockBootProperties = new MockBootProperties(createAdapterConfig(new NullConnection("SharedNullConnection"), new SharedConnection("SharedNullConnection"), new SharedConnection("SharedNullConnection"), null));
ConfigurationCheckReport report = checker.performConfigCheck(mockBootProperties);
assertTrue(report.isCheckPassed());
assertNotNull(report.toString());
}
use of com.adaptris.core.SharedConnection in project interlok by adaptris.
the class SharedConnectionConfigurationCheckerTest method testConsumeConnectionNoShared.
@Test
public void testConsumeConnectionNoShared() throws Exception {
BootstrapProperties mockBootProperties = new MockBootProperties(createAdapterConfig(null, new SharedConnection("DoesNotExist"), null, null));
ConfigurationCheckReport report = checker.performConfigCheck(mockBootProperties);
assertFalse(report.isCheckPassed());
assertTrue(report.getFailureExceptions().size() > 0);
}
Aggregations