use of com.adaptris.core.services.exception.ConfiguredException in project interlok by adaptris.
the class ServiceListTest method testFailWithContinueOnFail.
@Test
public void testFailWithContinueOnFail() throws Exception {
ServiceList services = createServiceList(true);
ThrowExceptionService service3 = new ThrowExceptionService(new ConfiguredException("Fail"));
service3.setContinueOnFail(true);
services.addService(service3);
services.addService(new AddMetadataService(Arrays.asList(new MetadataElement(KEY4, VAL4))));
AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage();
execute(services, msg);
assertTrue(msg.getMetadataValue(KEY4).equals(VAL4));
}
use of com.adaptris.core.services.exception.ConfiguredException in project interlok by adaptris.
the class CloneMessageServiceListTest method testFailWithContinueOnFail.
@Test
public void testFailWithContinueOnFail() throws Exception {
CloneMessageServiceList services = createServiceList();
ServiceImp service3 = new ThrowExceptionService(new ConfiguredException("Fail"));
service3.setContinueOnFail(true);
services.addService(service3);
AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage();
execute(services, msg);
}
use of com.adaptris.core.services.exception.ConfiguredException 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);
}
}
use of com.adaptris.core.services.exception.ConfiguredException 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.services.exception.ConfiguredException in project interlok by adaptris.
the class ThreadContextWorkflowTest method testServiceException.
@Test
public void testServiceException() throws Exception {
MockMessageProducer producer = new MockMessageProducer();
MockMessageProducer meh = new MockMessageProducer();
MockChannel channel = createChannel(producer, Arrays.asList(new Service[] { new ThrowExceptionService(new ConfiguredException("Fail")) }));
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);
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));
assertNotNull(m.getObjectHeaders().get(CoreConstants.OBJ_METADATA_EXCEPTION));
assertNotNull(m.getObjectHeaders().get(CoreConstants.OBJ_METADATA_EXCEPTION_CAUSE));
assertEquals(ThrowExceptionService.class.getSimpleName(), m.getObjectHeaders().get(CoreConstants.OBJ_METADATA_EXCEPTION_CAUSE));
}
} finally {
stop(channel);
}
}
Aggregations