use of com.adaptris.core.stubs.MockChannel in project interlok by adaptris.
the class ThreadContextWorkflowTest method createChannel.
protected MockChannel createChannel(AdaptrisMessageProducer producer, List<Service> services) throws Exception {
MockChannel channel = new MockChannel();
ThreadContextWorkflow workflow = createWorkflowForGenericTests();
workflow.setProducer(producer);
workflow.getServiceCollection().addAll(services);
channel.getWorkflowList().add(workflow);
return channel;
}
use of com.adaptris.core.stubs.MockChannel in project interlok by adaptris.
the class ThreadContextWorkflowTest method testOnMessage_ServiceFailsWithRetryHandlerFailureCallback.
@Test
public void testOnMessage_ServiceFailsWithRetryHandlerFailureCallback() throws Exception {
AtomicBoolean onSuccess = new AtomicBoolean(false);
MockChannel channel = createChannel(new MockMessageProducer(), Arrays.asList(new Service[] { new ThrowExceptionService(new ConfiguredException("expected")) }));
channel.setMessageErrorHandler(new RetryMessageErrorHandler(3, new TimeInterval(100l, TimeUnit.MILLISECONDS), new NullService()));
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);
}
}
use of com.adaptris.core.stubs.MockChannel in project interlok by adaptris.
the class ThreadContextWorkflowTest method testOnMessage_ProducerFailsFailureCallback.
@Test
public void testOnMessage_ProducerFailsFailureCallback() throws Exception {
AtomicBoolean onSuccess = new AtomicBoolean(false);
MockChannel channel = createChannel(new FailFirstMockMessageProducer(1), Arrays.asList(new Service[] { new NullService() }));
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);
}
}
use of com.adaptris.core.stubs.MockChannel in project interlok by adaptris.
the class ThreadContextWorkflowTest method testBrokenPool.
@Test
public void testBrokenPool() throws Exception {
MockMessageProducer producer = new MockMessageProducer();
MockMessageProducer eventProd = new MockMessageProducer();
DefaultEventHandler evtHandler = new DefaultEventHandler(eventProd);
MockChannel channel = createChannel(producer, Arrays.asList(new Service[] { new AddMetadataService(Arrays.asList(new MetadataElement[] { new MetadataElement(METADATA_KEY, METADATA_VALUE) })), new PayloadFromTemplateService().withTemplate(PAYLOAD_2) }));
MockMessageProducer meh = new MockMessageProducer();
try {
ThreadContextWorkflow workflow = (ThreadContextWorkflow) channel.getWorkflowList().get(0);
channel.setMessageErrorHandler(new StandardProcessingExceptionHandler(new ServiceList(new ArrayList<Service>(Arrays.asList(new Service[] { new StandaloneProducer(meh) })))));
channel.prepare();
AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(PAYLOAD_1);
start(channel);
// close the pool which should cause an IllegalStateException
workflow.getObjectPool().close();
workflow.onAdaptrisMessage(msg);
assertEquals("Make none produced", 0, producer.getMessages().size());
assertEquals(1, meh.getMessages().size());
for (Iterator i = meh.getMessages().iterator(); i.hasNext(); ) {
AdaptrisMessage m = (AdaptrisMessage) i.next();
assertEquals(PAYLOAD_1, m.getContent());
assertFalse("Does not contains correct metadata key", m.headersContainsKey(METADATA_KEY));
}
} finally {
stop(channel);
}
}
use of com.adaptris.core.stubs.MockChannel in project interlok by adaptris.
the class ThreadContextWorkflowTest method testOnMessageWithInterceptors.
@Test
public void testOnMessageWithInterceptors() throws Exception {
MockWorkflowInterceptor interceptor = new MockWorkflowInterceptor();
MockMessageProducer producer = new MockMessageProducer();
MockChannel channel = createChannel(producer, Arrays.asList(new Service[] { new AddMetadataService(Arrays.asList(new MetadataElement[] { new MetadataElement(METADATA_KEY, METADATA_VALUE) })), new PayloadFromTemplateService().withTemplate(PAYLOAD_2) }));
int count = 10;
try {
ThreadContextWorkflow workflow = (ThreadContextWorkflow) channel.getWorkflowList().get(0);
workflow.setAdditionalDebug(Boolean.TRUE);
workflow.addInterceptor(interceptor);
channel.prepare();
start(channel);
for (int i = 0; i < count; i++) {
AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(PAYLOAD_1);
workflow.onAdaptrisMessage(msg);
}
assertEquals("Make sure all produced", count, producer.messageCount());
assertEquals("Make sure all intercepted", count, interceptor.messageCount());
for (AdaptrisMessage m : producer.getMessages()) {
assertEquals(PAYLOAD_2, m.getContent());
assertTrue("Contains correct metadata key", m.headersContainsKey(METADATA_KEY));
assertEquals(METADATA_VALUE, m.getMetadataValue(METADATA_KEY));
}
} finally {
stop(channel);
}
}
Aggregations