use of com.adaptris.core.services.exception.ThrowExceptionService in project interlok by adaptris.
the class LargeMessageWorkflowTest method testServiceException.
@Override
@Test
public void testServiceException() throws Exception {
MockMessageProducer producer = new MockMessageProducer();
MockMessageProducer meh = 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), new ThrowExceptionService(new ConfiguredException("Fail")) }));
try {
LargeMessageWorkflow workflow = (LargeMessageWorkflow) 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 (AdaptrisMessage m : meh.getMessages()) {
assertEquals(PAYLOAD_2, m.getContent());
assertTrue("Contains correct metadata key", m.containsKey(METADATA_KEY));
assertEquals(METADATA_VALUE, m.getMetadataValue(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);
}
}
use of com.adaptris.core.services.exception.ThrowExceptionService in project interlok by adaptris.
the class StandardMessageErrorDigestTest method testMBean_GetMessageDigestMultipleWorkflow.
@Test
public void testMBean_GetMessageDigestMultipleWorkflow() throws Exception {
String adapterName = this.getClass().getSimpleName() + "." + getName();
Adapter adapter = createAdapter(adapterName);
adapter.setMessageErrorDigester(new StandardMessageErrorDigester(getName()));
Channel channel1 = createChannel("channel1");
StandardWorkflow workflow1 = createWorkflow("workflow1");
StandardWorkflow workflow2 = createWorkflow("workflow2");
workflow1.getServiceCollection().add(new ThrowExceptionService(new ConfiguredException("fail1")));
workflow2.getServiceCollection().add(new ThrowExceptionService(new ConfiguredException("fail2")));
channel1.getWorkflowList().add(workflow1);
channel1.getWorkflowList().add(workflow2);
adapter.getChannelList().add(channel1);
List<BaseComponentMBean> mBeans = createJmxManagers(adapter);
try {
start(adapter);
register(mBeans);
ObjectName adapterObj = createAdapterObjectName(adapterName);
ObjectName digesterObj = createMessageErrorDigestObjectName(adapterName, getName());
StandardMessageErrorDigesterJmxMBean errDigester = JMX.newMBeanProxy(mBeanServer, digesterObj, StandardMessageErrorDigesterJmxMBean.class);
workflow1.onAdaptrisMessage(new DefaultMessageFactory().newMessage("Hello Workflow1"));
workflow2.onAdaptrisMessage(new DefaultMessageFactory().newMessage("Hello Workflow2"));
// They should have failed.
assertNotNull(errDigester.getDigest());
assertEquals(2, errDigester.getDigest().size());
assertEquals(2, errDigester.getTotalErrorCount());
MessageDigestErrorEntry entry1 = errDigester.getDigest().get(0);
MessageDigestErrorEntry entry2 = errDigester.getDigest().get(1);
assertEquals("workflow1@channel1", entry1.getWorkflowId());
assertEquals("workflow2@channel1", entry2.getWorkflowId());
} finally {
stop(adapter);
}
}
use of com.adaptris.core.services.exception.ThrowExceptionService in project interlok by adaptris.
the class AdvancedMessageSplitterServiceTest method testDoServiceWithFailuresIgnored.
@Test
public void testDoServiceWithFailuresIgnored() throws Exception {
MockMessageProducer producer = new MockMessageProducer();
AdaptrisMessage msg = createMessage(REGEXP_DATA);
AdvancedMessageSplitterService service = createAdvanced(new SimpleRegexpMessageSplitter("\\|"), new Service[] { new ThrowExceptionService(new ConfiguredException("Fail")), new StandaloneProducer(producer) });
service.setIgnoreSplitMessageFailures(true);
execute(service, msg);
assertEquals("Number of messages", 0, producer.getMessages().size());
// We should still get 4 messages as the splitCount. They may not have been successfully
// processed, but they were still results from the split!
assertEquals("splitCount metadata", 4, Integer.parseInt(msg.getMetadataValue(MessageSplitterServiceImp.KEY_SPLIT_MESSAGE_COUNT)));
int count = 0;
for (AdaptrisMessage m : producer.getMessages()) {
count++;
assertEquals(count, Integer.parseInt(m.getMetadataValue(KEY_CURRENT_SPLIT_MESSAGE_COUNT)));
}
}
use of com.adaptris.core.services.exception.ThrowExceptionService in project interlok by adaptris.
the class AdvancedMessageSplitterServiceTest method testDoServiceWithFailures_NullEventHandler_SendEvents.
@Test
public void testDoServiceWithFailures_NullEventHandler_SendEvents() throws Exception {
MockMessageProducer producer = new MockMessageProducer();
AdaptrisMessage msg = createMessage(REGEXP_DATA);
AdvancedMessageSplitterService service = createAdvanced(new SimpleRegexpMessageSplitter("\\|"), new Service[] { new ThrowExceptionService(new ConfiguredException("Fail")), new StandaloneProducer(producer) });
service.registerEventHandler(null);
service.setSendEvents(true);
try {
ExampleServiceCase.execute(service, msg);
fail("Expecting failure from AlwaysFailService");
} catch (ServiceException expected) {
;
}
}
use of com.adaptris.core.services.exception.ThrowExceptionService in project interlok by adaptris.
the class AdvancedMessageSplitterServiceTest method testDoServiceWithFailures_SendEventsTrue.
@Test
public void testDoServiceWithFailures_SendEventsTrue() throws Exception {
MockMessageProducer producer = new MockMessageProducer();
AdaptrisMessage msg = createMessage(REGEXP_DATA);
AdvancedMessageSplitterService service = createAdvanced(new SimpleRegexpMessageSplitter("\\|"), new Service[] { new ThrowExceptionService(new ConfiguredException("Fail")), new StandaloneProducer(producer) });
DefaultEventHandler eh = new DefaultEventHandler();
MockMessageProducer ehp = new MockMessageProducer();
eh.setProducer(ehp);
LifecycleHelper.initAndStart(eh);
service.registerEventHandler(eh);
service.setSendEvents(true);
try {
ExampleServiceCase.execute(service, msg);
fail("Expecting failure from AlwaysFailService");
} catch (ServiceException expected) {
;
}
LifecycleHelper.stopAndClose(eh);
assertEvents(ehp, 1, MessageLifecycleEvent.class);
}
Aggregations