use of com.adaptris.util.TimeInterval in project interlok by adaptris.
the class JmsConnectionErrorHandlerTest method createChannel.
private MockChannel createChannel(String channelName, EmbeddedActiveMq mq, JmsConnection con, String destinationName, JmsConnectionErrorHandler handler) throws Exception {
MockChannel result = new MockChannel();
result.setUniqueId(channelName);
con.setConnectionRetryInterval(new TimeInterval(1L, TimeUnit.SECONDS.name()));
con.setConnectionAttempts(50);
con.setConnectionErrorHandler(handler);
result.setConsumeConnection(con);
Workflow workflow = createWorkflow(mq, destinationName);
result.getWorkflowList().add(workflow);
return result;
}
use of com.adaptris.util.TimeInterval 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.util.TimeInterval in project interlok by adaptris.
the class WorkflowRetryAndFailTest method testFailedStart_ExceedsMax.
@Override
@Test
public void testFailedStart_ExceedsMax() throws Exception {
WorkflowList wfl = new WorkflowList();
WorkflowRetryAndFail strategy = new WorkflowRetryAndFail(2, new TimeInterval(10L, TimeUnit.MILLISECONDS.name()));
FailStart workflow = new FailStart(3);
wfl.add(workflow);
wfl.setLifecycleStrategy(strategy);
Channel c = createChannel(wfl);
c.requestInit();
try {
c.requestStart();
} catch (CoreException expected) {
}
// That's right 1 + 2 retries.
assertEquals(3, workflow.getAttempts());
assertEquals(InitialisedState.getInstance(), workflow.retrieveComponentState());
}
use of com.adaptris.util.TimeInterval in project interlok by adaptris.
the class WorkflowRetryAndFailTest method testFailedInitialise_ExceedsMax.
@Override
@Test
public void testFailedInitialise_ExceedsMax() throws Exception {
WorkflowList wfl = new WorkflowList();
WorkflowRetryAndFail strategy = new WorkflowRetryAndFail(2, new TimeInterval(10L, TimeUnit.MILLISECONDS.name()));
FailInit workflow = new FailInit(3);
wfl.add(workflow);
wfl.setLifecycleStrategy(strategy);
Channel c = createChannel(wfl);
try {
c.requestInit();
} catch (CoreException expected) {
}
// That's right 1 + 2 retries.
assertEquals(3, workflow.getAttempts());
assertEquals(ClosedState.getInstance(), workflow.retrieveComponentState());
}
use of com.adaptris.util.TimeInterval in project interlok by adaptris.
the class JmxConnectionTest method testRemoteJmx_Retry.
@Test
public void testRemoteJmx_Retry() throws Exception {
Integer port = PortManager.nextUnusedPort(23456);
final JmxRemoteComponent jmxr = new JmxRemoteComponent();
JmxConnection conn = new JmxConnection();
try {
jmxr.init(createProperties(port));
conn.withJmxServiceUrl(JMXMP_PREFIX + port);
conn.setConnectionRetryInterval(new TimeInterval(1L, TimeUnit.SECONDS));
conn.setConnectionAttempts(10);
Executors.newSingleThreadScheduledExecutor().schedule(new Runnable() {
@Override
public void run() {
try {
jmxr.start();
} catch (Exception e) {
throw new RuntimeException();
}
}
}, 2, TimeUnit.SECONDS);
LifecycleHelper.prepare(conn);
LifecycleHelper.init(conn);
assertNotNull(conn.mbeanServerConnection());
} finally {
LifecycleHelper.stopAndClose(conn);
PortManager.release(port);
destroy(jmxr);
}
}
Aggregations