use of com.adaptris.core.services.exception.ThrowExceptionService in project interlok by adaptris.
the class ActiveMqJmsTransactedWorkflowTest method testServiceExceptionStrictWithErrorHandler.
// In Strict Mode, Then even if you have configured an error handler, then
// the transaction is unsucessful if we have an exception, leading to msgs on
// the queue.
@Test
public void testServiceExceptionStrictWithErrorHandler() throws Exception {
int msgCount = 10;
String destination = createSafeUniqueId(new Object());
MockMessageProducer meh = new MockMessageProducer();
Channel channel = createStartableChannel(activeMqBroker, true, "testServiceExceptionStrictWithErrorHandler", destination);
JmsTransactedWorkflow workflow = (JmsTransactedWorkflow) channel.getWorkflowList().get(0);
workflow.setStrict(Boolean.TRUE);
workflow.getServiceCollection().addService(new ThrowExceptionService(new ConfiguredException("Fail")));
channel.setMessageErrorHandler(new StandardProcessingExceptionHandler(new ServiceList(new ArrayList<Service>(Arrays.asList(new Service[] { new StandaloneProducer(meh) })))));
try {
channel.requestStart();
StandaloneProducer sender = new StandaloneProducer(activeMqBroker.getJmsConnection(), new PtpProducer().withQueue((destination)));
send(sender, msgCount);
} finally {
channel.requestClose();
}
assertEquals(msgCount, activeMqBroker.messagesOnQueue(destination));
}
use of com.adaptris.core.services.exception.ThrowExceptionService in project interlok by adaptris.
the class ActiveMqJmsTransactedWorkflowTest method testHandleChannelUnavailableWithException_Bug2343.
@Test
public void testHandleChannelUnavailableWithException_Bug2343() throws Exception {
int msgCount = 10;
String destination = createSafeUniqueId(new Object());
final Channel channel = createStartableChannel(activeMqBroker, true, "testHandleChannelUnavailableWithException_Bug2343", destination);
JmsTransactedWorkflow workflow = (JmsTransactedWorkflow) channel.getWorkflowList().get(0);
workflow.setChannelUnavailableWaitInterval(new TimeInterval(1L, TimeUnit.SECONDS));
workflow.getServiceCollection().addService(new ThrowExceptionService(new ConfiguredException("Fail")));
try {
channel.requestStart();
channel.toggleAvailability(false);
Timer t = new Timer();
t.schedule(new TimerTask() {
@Override
public void run() {
channel.toggleAvailability(true);
}
}, 666);
StandaloneProducer sender = new StandaloneProducer(activeMqBroker.getJmsConnection(), new PtpProducer().withQueue(destination));
send(sender, msgCount);
} finally {
channel.requestClose();
}
assertEquals(msgCount, activeMqBroker.messagesOnQueue(destination));
}
use of com.adaptris.core.services.exception.ThrowExceptionService in project interlok by adaptris.
the class CloneMessageServiceListTest method testFailWithNoContinueOnFail.
@Test
public void testFailWithNoContinueOnFail() throws Exception {
CloneMessageServiceList services = createServiceList();
services.addService(new ThrowExceptionService(new ConfiguredException("Fail")));
AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage();
try {
execute(services, msg);
fail("Expected Service Exception");
} catch (Exception e) {
// expected...
}
}
use of com.adaptris.core.services.exception.ThrowExceptionService in project interlok by adaptris.
the class DynamicSharedServiceTest method testDoService_WithFailure.
@Test
public void testDoService_WithFailure() throws Exception {
ThrowExceptionService mockService = new ThrowExceptionService(getName(), new ConfiguredException("Fail"));
DynamicSharedService sharedService = new DynamicSharedService(getName());
Adapter adapter = createAdapterForSharedService(sharedService, mockService);
AdaptrisMessage msg = DefaultMessageFactory.getDefaultInstance().newMessage();
try {
LifecycleHelper.initAndStart(adapter);
sharedService.doService(msg);
fail();
} catch (ServiceException expected) {
assertEquals(1, sharedService.getCache().size());
MleMarker marker = msg.getMessageLifecycleEvent().getMleMarkers().get(0);
assertEquals(ThrowExceptionService.class.getName(), marker.getName());
assertEquals(getName(), marker.getQualifier());
assertEquals(false, marker.getWasSuccessful());
} finally {
LifecycleHelper.stopAndClose(adapter);
}
}
use of com.adaptris.core.services.exception.ThrowExceptionService in project interlok by adaptris.
the class PooledSplitJoinServiceTest method testService_WithException.
@Test(expected = ServiceException.class)
public void testService_WithException() throws Exception {
PooledSplitJoinService service = new PooledSplitJoinService();
service.setAggregator(new AppendingMessageAggregator());
service.setSplitter(new LineCountSplitter(1));
service.setPoolsize(10);
service.setTimeout(new TimeInterval(5L, TimeUnit.SECONDS));
service.setService(new ThrowExceptionService(new ConfiguredException("always-fail")));
service.registerEventHandler(LifecycleHelper.initAndStart(new DefaultEventHandler()));
AdaptrisMessage msg = createLineCountMessageInput(50);
try {
ExampleServiceCase.execute(service, msg);
} catch (ServiceException e) {
assertEquals("always-fail", e.getMessage());
throw e;
}
}
Aggregations