use of com.adaptris.core.Adapter in project interlok by adaptris.
the class BasicActiveMqConsumerTest method createDurableSubsAdapter.
private Adapter createDurableSubsAdapter(String adapterName, EmbeddedActiveMq activeMqBroker) throws Exception {
Adapter adapter = new Adapter();
adapter.setUniqueId(adapterName);
Channel c = new Channel();
JmsConnection conn = activeMqBroker.getJmsConnection(createVendorImpl());
conn.setClientId(MY_CLIENT_ID);
c.setConsumeConnection(conn);
StandardWorkflow swf = new StandardWorkflow();
PasConsumer pasConsumer = new PasConsumer().withTopic(new GuidGenerator().safeUUID());
pasConsumer.setSubscriptionId(MY_SUBSCRIPTION_ID);
swf.setConsumer(pasConsumer);
c.getWorkflowList().add(swf);
ChannelList cl = new ChannelList();
cl.addChannel(c);
adapter.setChannelList(cl);
return adapter;
}
use of com.adaptris.core.Adapter in project interlok by adaptris.
the class BasicActiveMqConsumerTest method testStartWithDurableSubscribers_WithNonBlockingChannelStrategy.
@Test
public void testStartWithDurableSubscribers_WithNonBlockingChannelStrategy() throws Exception {
Adapter adapter = createDurableSubsAdapter(getName(), activeMqBroker);
adapter.requestStart();
assertEquals(StartedState.getInstance(), adapter.retrieveComponentState());
adapter.requestClose();
assertEquals(ClosedState.getInstance(), adapter.retrieveComponentState());
adapter.getChannelList().setLifecycleStrategy(new NonBlockingChannelStartStrategy());
adapter.requestStart();
// Thread.sleep(1000);
Channel c = adapter.getChannelList().getChannel(0);
int maxAttempts = 100;
int attempts = 0;
while (attempts < maxAttempts && c.retrieveComponentState() != StartedState.getInstance()) {
Thread.sleep(500);
attempts++;
}
assertEquals(StartedState.getInstance(), c.retrieveComponentState());
adapter.requestClose();
}
use of com.adaptris.core.Adapter 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.Adapter 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.Adapter in project interlok by adaptris.
the class FilteredSharedComponentStartTest method testNonBlockingStart.
@Test
public void testNonBlockingStart() throws Exception {
Adapter adapter = new Adapter();
adapter.setUniqueId(getName());
TriggeredMockConnection sharedConnection = new TriggeredMockConnection(getName());
try {
adapter.getSharedComponents().addConnection(sharedConnection);
adapter.getSharedComponents().setLifecycleStrategy(new FilteredSharedComponentStart(true));
adapter.requestInit();
// Will return straight away.
assertEquals(InitialisedState.getInstance(), adapter.retrieveComponentState());
assertNotSame(InitialisedState.getInstance(), sharedConnection.retrieveComponentState());
sharedConnection.wakeup = true;
waitFor(sharedConnection, InitialisedState.getInstance());
assertEquals(InitialisedState.getInstance(), sharedConnection.retrieveComponentState());
sharedConnection.wakeup = false;
adapter.requestStart();
assertEquals(StartedState.getInstance(), adapter.retrieveComponentState());
assertNotSame(StartedState.getInstance(), sharedConnection.retrieveComponentState());
sharedConnection.wakeup = true;
waitFor(sharedConnection, StartedState.getInstance());
assertEquals(StartedState.getInstance(), sharedConnection.retrieveComponentState());
stop(adapter);
// Initialise again, to make sure that we can.
sharedConnection.wakeup = false;
adapter.requestInit();
// Will return straight away.
assertEquals(InitialisedState.getInstance(), adapter.retrieveComponentState());
assertNotSame(InitialisedState.getInstance(), sharedConnection.retrieveComponentState());
sharedConnection.wakeup = true;
waitFor(sharedConnection, InitialisedState.getInstance());
assertEquals(InitialisedState.getInstance(), sharedConnection.retrieveComponentState());
} finally {
stop(adapter);
}
}
Aggregations