use of com.adaptris.core.stubs.MockChannel in project interlok by adaptris.
the class RequestReplyWorkflowTest method testWorkflow_NullReply.
@Test
public void testWorkflow_NullReply() throws Exception {
Channel channel = new MockChannel();
RequestReplyWorkflow workflow = new RequestReplyWorkflow();
workflow.setConsumer(new MockMessageConsumer());
AdaptrisMessageProducer replier = mock(AdaptrisMessageProducer.class);
doThrow(new ProduceException()).when(replier).produce(any(AdaptrisMessage.class));
doThrow(new ProduceException()).when(replier).produce(any(AdaptrisMessage.class));
when(replier.createName()).thenReturn("mock");
when(replier.createQualifier()).thenReturn("mock");
when(replier.isTrackingEndpoint()).thenReturn(false);
AdaptrisMessageProducer requestor = mock(AdaptrisMessageProducer.class);
when(requestor.request(any(AdaptrisMessage.class))).thenReturn(null);
when(requestor.request(any(AdaptrisMessage.class))).thenReturn(null);
when(requestor.request(any(AdaptrisMessage.class), anyLong())).thenReturn(null);
when(requestor.request(any(AdaptrisMessage.class), anyLong())).thenReturn(null);
when(requestor.createName()).thenReturn("mock");
when(requestor.createQualifier()).thenReturn("mock");
when(requestor.isTrackingEndpoint()).thenReturn(false);
workflow.setProducer(requestor);
workflow.setReplyProducer(replier);
channel.getWorkflowList().add(workflow);
try {
start(channel);
submitMessages(workflow, 1);
} finally {
stop(channel);
}
}
use of com.adaptris.core.stubs.MockChannel in project interlok by adaptris.
the class PoolingWorkflowTest method testWorkflowWithInterceptor.
@Test
public void testWorkflowWithInterceptor() throws Exception {
MockChannel channel = createChannel();
PoolingWorkflow wf = (PoolingWorkflow) channel.getWorkflowList().get(0);
MockMessageProducer prod = (MockMessageProducer) wf.getProducer();
MockWorkflowInterceptor interceptor = new MockWorkflowInterceptor();
wf.addInterceptor(interceptor);
try {
start(channel);
submitMessages(wf, 1);
waitForMessages(prod, 1);
assertMessages(prod, 1);
assertEquals(1, interceptor.messageCount());
} finally {
stop(channel);
}
}
use of com.adaptris.core.stubs.MockChannel in project interlok by adaptris.
the class PoolingWorkflowTest method testGreaterThanPoolSize.
@Test
public void testGreaterThanPoolSize() throws Exception {
MockChannel channel = createChannel();
PoolingWorkflow wf = (PoolingWorkflow) channel.getWorkflowList().get(0);
int count = wf.poolSize() * 2;
MockMessageProducer prod = (MockMessageProducer) wf.getProducer();
try {
start(channel);
submitMessages(wf, count);
waitForMessages(prod, count);
assertTrue("ObjectPool > 1", wf.currentObjectPoolCount() > 1);
assertTrue("ThreadPool > 1", wf.currentThreadPoolCount() > 1);
assertTrue("ObjectPool >=0", wf.currentlyIdleObjects() >= 0);
assertTrue("ThreadPool >=0", wf.currentlyActiveObjects() >= 0);
assertMessages(prod, count);
} finally {
stop(channel);
}
}
use of com.adaptris.core.stubs.MockChannel in project interlok by adaptris.
the class PoolingWorkflowTest method testHandleProduceException.
@Test
public void testHandleProduceException() throws Exception {
MockChannel channel = createChannel();
PoolingWorkflow wf = (PoolingWorkflow) channel.getWorkflowList().get(0);
MockMessageProducer meh = new MockMessageProducer();
MockMessageProducer prod = new MockMessageProducer() {
@Override
protected void doProduce(AdaptrisMessage msg, String endpoint) throws ProduceException {
throw new ProduceException();
}
};
wf.setProducer(prod);
channel.setMessageErrorHandler(new StandardProcessingExceptionHandler(new ServiceList(new ArrayList<Service>(Arrays.asList(new Service[] { new StandaloneProducer(meh) })))));
try {
start(channel);
submitMessages(wf, 1);
waitForMessages(meh, 1);
assertEquals(1, meh.messageCount());
} finally {
stop(channel);
}
}
use of com.adaptris.core.stubs.MockChannel in project interlok by adaptris.
the class PoolingWorkflowTest method testHandleChannelUnavailableForever.
@Test
public void testHandleChannelUnavailableForever() throws Exception {
MockMessageProducer producer = new MockMessageProducer();
final MockChannel channel = createChannel();
PoolingWorkflow workflow = (PoolingWorkflow) channel.getWorkflowList().get(0);
MockMessageProducer meh = new MockMessageProducer();
try {
workflow.setChannelUnavailableWaitInterval(new TimeInterval(100L, TimeUnit.MILLISECONDS));
workflow.setMessageErrorHandler(new StandardProcessingExceptionHandler(new ServiceList(new ArrayList<Service>(Arrays.asList(new Service[] { new StandaloneProducer(meh) })))));
AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(PAYLOAD_1);
start(channel);
channel.toggleAvailability(false);
workflow.onAdaptrisMessage(msg);
assertEquals("Make none produced", 0, producer.getMessages().size());
assertEquals(1, meh.getMessages().size());
} finally {
stop(channel);
}
}
Aggregations