use of com.adaptris.core.stubs.MockChannel in project interlok by adaptris.
the class ConnectionErrorHandlerTest method testChannelChannelCloseConnectionErrorHandler.
@Test
public void testChannelChannelCloseConnectionErrorHandler() throws Exception {
MockChannel c = new MockChannel();
TriggeredFailingConnection con = new TriggeredFailingConnection(new ChannelCloseErrorHandler());
c.setConsumeConnection(con);
start(c);
con.triggerError();
assertEquals(1, c.getInitCount());
assertEquals(1, c.getStartCount());
assertEquals(1, c.getStopCount());
assertEquals(1, c.getCloseCount());
assertEquals(ClosedState.getInstance(), c.retrieveComponentState());
stop(c);
}
use of com.adaptris.core.stubs.MockChannel in project interlok by adaptris.
the class ConnectionErrorHandlerTest method testChannelStopped_ConnectionErrorHandler.
@Test
public void testChannelStopped_ConnectionErrorHandler() throws Exception {
MockChannel started = new MockChannel();
MockChannel stopped = new MockChannel();
TriggeredFailingConnection con = new TriggeredFailingConnection();
started.setConsumeConnection(con);
stopped.setConsumeConnection(con);
start(started);
start(stopped);
stopped.requestStop();
con.triggerError();
assertEquals(2, started.getInitCount());
assertEquals(2, started.getStartCount());
assertEquals(1, started.getStopCount());
assertEquals(1, started.getCloseCount());
assertEquals(1, stopped.getInitCount());
assertEquals(1, stopped.getStartCount());
assertEquals(1, stopped.getStopCount());
assertEquals(1, stopped.getCloseCount());
assertEquals(ClosedState.getInstance(), stopped.retrieveComponentState());
stop(started);
}
use of com.adaptris.core.stubs.MockChannel in project interlok by adaptris.
the class ConnectionErrorHandlerTest method testChannelClosed_ConnectionErrorHandler.
@Test
public void testChannelClosed_ConnectionErrorHandler() throws Exception {
MockChannel started = new MockChannel();
MockChannel neverStarted = new MockChannel();
TriggeredFailingConnection con = new TriggeredFailingConnection();
started.setConsumeConnection(con);
neverStarted.setConsumeConnection(con);
start(started);
con.triggerError();
assertEquals(2, started.getInitCount());
assertEquals(2, started.getStartCount());
assertEquals(1, started.getStopCount());
assertEquals(1, started.getCloseCount());
// ID 167 - Previously neverStarted would have been started as the CEH would always restart all exception listeners.
assertEquals(0, neverStarted.getInitCount());
assertEquals(0, neverStarted.getStartCount());
assertEquals(0, neverStarted.getStopCount());
assertEquals(0, neverStarted.getCloseCount());
stop(started);
}
use of com.adaptris.core.stubs.MockChannel in project interlok by adaptris.
the class FixedIntervalPollerTest method testLifecycle.
@Test
public void testLifecycle() throws Exception {
PollingTrigger consumer = new PollingTrigger();
consumer.setPoller(new FixedIntervalPoller(new TimeInterval(100L, TimeUnit.MILLISECONDS)));
MockMessageProducer producer = new MockMessageProducer();
MockChannel channel = new MockChannel();
StandardWorkflow workflow = new StandardWorkflow();
workflow.setConsumer(consumer);
workflow.setProducer(producer);
channel.getWorkflowList().add(workflow);
try {
channel.requestClose();
channel.requestStart();
waitForMessages(producer, 1);
channel.requestStop();
producer.getMessages().clear();
channel.requestStart();
waitForMessages(producer, 1);
channel.requestClose();
producer.getMessages().clear();
channel.requestStart();
waitForMessages(producer, 1);
} finally {
channel.requestClose();
}
}
use of com.adaptris.core.stubs.MockChannel in project interlok by adaptris.
the class ThreadContextWorkflowTest method testOnMessage_ServiceFailsFailureCallback.
@Test
public void testOnMessage_ServiceFailsFailureCallback() throws Exception {
AtomicBoolean onSuccess = new AtomicBoolean(false);
MockChannel channel = createChannel(new MockMessageProducer(), Arrays.asList(new Service[] { new ThrowExceptionService(new ConfiguredException("expected")) }));
AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(PAYLOAD_1);
ThreadContextWorkflow workflow = (ThreadContextWorkflow) channel.getWorkflowList().get(0);
try {
start(channel);
workflow.onAdaptrisMessage(msg, (m) -> {
onSuccess.set(true);
}, (m) -> {
onSuccess.set(false);
});
assertFalse(onSuccess.get());
} finally {
stop(channel);
}
}
Aggregations