use of com.adaptris.core.ServiceException in project interlok by adaptris.
the class StatelessServiceWrapperTest method testServiceThatFailsToStart.
@Test
public void testServiceThatFailsToStart() throws Exception {
AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage("ABC");
StatelessServiceWrapper service = new StatelessServiceWrapper(new NullService() {
@Override
public void start() throws CoreException {
throw new CoreException("testServiceThatFailsToStart");
}
});
try {
execute(service, msg);
fail();
} catch (ServiceException e) {
assertNotNull(e.getCause());
assertEquals(CoreException.class, e.getCause().getClass());
assertEquals("testServiceThatFailsToStart", e.getCause().getMessage());
}
}
use of com.adaptris.core.ServiceException in project interlok by adaptris.
the class RetryingServiceWrapperTest method testFailsOnceNoRestarts.
@Test
public void testFailsOnceNoRestarts() throws Exception {
// Fail once, then pass
doThrow(new ServiceException("Expected fail.")).doNothing().when(wrappedService).doService(any(AdaptrisMessage.class));
// now setup the retrying service wrapper;
retryingServiceWrapper.setDelayBetweenRetries(new TimeInterval(1L, TimeUnit.SECONDS));
retryingServiceWrapper.setNumRetries(3);
retryingServiceWrapper.setService(wrappedService);
retryingServiceWrapper.setRestartOnFailure(false);
LifecycleHelper.init(retryingServiceWrapper);
LifecycleHelper.start(retryingServiceWrapper);
retryingServiceWrapper.doService(DefaultMessageFactory.getDefaultInstance().newMessage());
verify(wrappedService, times(2)).doService(any(AdaptrisMessage.class));
// init and start will be called once at RetryServiceWrapper init and start and then again on the restart.
verify(wrappedService, times(1)).requestInit();
verify(wrappedService, times(1)).requestStart();
}
use of com.adaptris.core.ServiceException in project interlok by adaptris.
the class DoWhileTest method testInnerServiceExceptionPropagated.
@Test
public void testInnerServiceExceptionPropagated() throws Exception {
when(mockCondition.evaluate(message)).thenReturn(true);
doThrow(new ServiceException()).when(mockService).doService(message);
try {
doWhile.doService(message);
fail("Expected a service exception");
} catch (ServiceException ex) {
// expected.
}
}
use of com.adaptris.core.ServiceException in project interlok by adaptris.
the class ForEachTest method testBadThenService.
@Test
public void testBadThenService() throws Exception {
doThrow(new ServiceException()).when(mock).doService(any(AdaptrisMessage.class));
forEach.doService(message);
verify(mock, times(2)).doService(any(AdaptrisMessage.class));
}
use of com.adaptris.core.ServiceException in project interlok by adaptris.
the class DynamicServiceExecutorTest method testDoService_MimeServiceExtractor_ByContentId_NotFound.
@Test
public void testDoService_MimeServiceExtractor_ByContentId_NotFound() throws Exception {
AddMetadataService metadataService = new AddMetadataService();
metadataService.addMetadataElement(new MetadataElement(getName(), getName()));
DynamicServiceExecutor dynamicService = createService();
dynamicService.setServiceExtractor(new MimeServiceExtractor(new SelectByContentId("Blah")));
AdaptrisMessage msg = createMimeMessage(new ServiceList(new Service[] { metadataService }), ENCODING_BASE64);
try {
execute(dynamicService, msg);
fail();
} catch (ServiceException expected) {
}
}
Aggregations