use of com.adaptris.core.services.exception.ThrowExceptionService in project interlok by adaptris.
the class RetryMessageErrorHandlerTest method testMultipleErrorHandlers_AlwaysHandle_True.
@Test
public void testMultipleErrorHandlers_AlwaysHandle_True() throws Exception {
MockMessageProducer aep = new MockMessageProducer();
MockMessageProducer wep = new MockMessageProducer();
MockMessageProducer cep = new MockMessageProducer();
RetryMessageErrorHandler aeh = new RetryMessageErrorHandler(1, DEFAULT_RETRY_INTERVAL, new StandaloneProducer(aep));
aeh.setAlwaysHandleException(true);
RetryMessageErrorHandler ceh = new RetryMessageErrorHandler(1, DEFAULT_RETRY_INTERVAL, new StandaloneProducer(cep));
ceh.setAlwaysHandleException(true);
RetryMessageErrorHandler weh = new RetryMessageErrorHandler(1, DEFAULT_RETRY_INTERVAL, new StandaloneProducer(wep));
Adapter adapter = AdapterTest.createAdapter(getName());
adapter.setMessageErrorHandler(aeh);
MockMessageConsumer consumer = new MockMessageConsumer();
adapter.getChannelList().clear();
adapter.getChannelList().add(createChannel(consumer, ceh, weh, new ThrowExceptionService(new ConfiguredException(getName()))));
try {
start(adapter);
consumer.submitMessage(AdaptrisMessageFactory.getDefaultInstance().newMessage());
waitForMessages(wep, 1, 1000);
waitForMessages(cep, 1, 1000);
waitForMessages(aep, 1, 1000);
assertEquals(1, aep.messageCount());
assertEquals(1, cep.messageCount());
assertEquals(1, wep.messageCount());
} finally {
stop(adapter);
}
}
use of com.adaptris.core.services.exception.ThrowExceptionService in project interlok by adaptris.
the class RetryMessageErrorHandlerTest method testMultipleErrorHandlers_AlwaysHandle_False.
@Test
public void testMultipleErrorHandlers_AlwaysHandle_False() throws Exception {
MockMessageProducer aep = new MockMessageProducer();
MockMessageProducer wep = new MockMessageProducer();
MockMessageProducer cep = new MockMessageProducer();
RetryMessageErrorHandler aeh = new RetryMessageErrorHandler(1, DEFAULT_RETRY_INTERVAL, new StandaloneProducer(aep));
aeh.setAlwaysHandleException(false);
RetryMessageErrorHandler weh = new RetryMessageErrorHandler(1, DEFAULT_RETRY_INTERVAL, new StandaloneProducer(wep));
RetryMessageErrorHandler ceh = new RetryMessageErrorHandler(1, DEFAULT_RETRY_INTERVAL, new StandaloneProducer(cep));
Adapter adapter = AdapterTest.createAdapter(getName());
adapter.setMessageErrorHandler(aeh);
MockMessageConsumer consumer = new MockMessageConsumer();
adapter.getChannelList().clear();
adapter.getChannelList().add(createChannel(consumer, ceh, weh, new ThrowExceptionService(new ConfiguredException(getName()))));
try {
start(adapter);
consumer.submitMessage(AdaptrisMessageFactory.getDefaultInstance().newMessage());
waitForMessages(wep, 1, 1000);
assertEquals(0, aep.messageCount());
assertEquals(0, cep.messageCount());
assertEquals(1, wep.messageCount());
} finally {
stop(adapter);
}
}
use of com.adaptris.core.services.exception.ThrowExceptionService in project interlok by adaptris.
the class SharedServiceTest method testDoService_WithFailure.
@Test
public void testDoService_WithFailure() throws Exception {
ThrowExceptionService mockService = new ThrowExceptionService(getName(), new ConfiguredException("Fail"));
SharedService sharedService = new SharedService(getName());
Adapter adapter = createAdapterForSharedService(sharedService, mockService);
AdaptrisMessage msg = DefaultMessageFactory.getDefaultInstance().newMessage();
try {
LifecycleHelper.initAndStart(adapter);
sharedService.doService(msg);
fail();
} catch (ServiceException expected) {
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 ServiceListTest method testFail_NestedServiceList_ObjectMetadata.
@Test
public void testFail_NestedServiceList_ObjectMetadata() throws Exception {
ServiceList services = createServiceList(false);
ThrowExceptionService errorService = new ThrowExceptionService(new ConfiguredException("Fail"));
errorService.setUniqueId(getName());
services.addService(new ServiceList(new Service[] { errorService }));
AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage();
String expectedName = String.format("%s(%s)", ThrowExceptionService.class.getSimpleName(), getName());
try {
execute(services, msg);
fail("Expected Service Exception");
} catch (ServiceException e) {
assertEquals("Fail", e.getMessage());
Exception captured = (Exception) msg.getObjectHeaders().get(CoreConstants.OBJ_METADATA_EXCEPTION);
String problemComponent = (String) msg.getObjectHeaders().get(CoreConstants.OBJ_METADATA_EXCEPTION_CAUSE);
assertNotNull(captured);
assertEquals(captured, e);
assertNotNull(problemComponent);
assertEquals(expectedName, problemComponent);
}
}
use of com.adaptris.core.services.exception.ThrowExceptionService in project interlok by adaptris.
the class ServiceListTest method testFailWithNoContinueOnFail.
@Test
public void testFailWithNoContinueOnFail() throws Exception {
ServiceList services = createServiceList(false);
services.addService(new ThrowExceptionService(new ConfiguredException("Fail")));
AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage();
try {
execute(services, msg);
fail("Expected Service Exception");
} catch (ServiceException e) {
assertEquals("Fail", e.getMessage());
}
}
Aggregations