Search in sources :

Example 21 with ConfiguredException

use of com.adaptris.core.services.exception.ConfiguredException 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));
}
Also used : MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) ThrowExceptionService(com.adaptris.core.services.exception.ThrowExceptionService) ServiceList(com.adaptris.core.ServiceList) MockChannel(com.adaptris.core.stubs.MockChannel) Channel(com.adaptris.core.Channel) JmsTransactedWorkflow(com.adaptris.core.jms.JmsTransactedWorkflow) ConfiguredException(com.adaptris.core.services.exception.ConfiguredException) Service(com.adaptris.core.Service) MockSkipProducerService(com.adaptris.core.stubs.MockSkipProducerService) ThrowExceptionService(com.adaptris.core.services.exception.ThrowExceptionService) PtpProducer(com.adaptris.core.jms.PtpProducer) StandardProcessingExceptionHandler(com.adaptris.core.StandardProcessingExceptionHandler) StandaloneProducer(com.adaptris.core.StandaloneProducer) Test(org.junit.Test)

Example 22 with ConfiguredException

use of com.adaptris.core.services.exception.ConfiguredException 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));
}
Also used : TimeInterval(com.adaptris.util.TimeInterval) ThrowExceptionService(com.adaptris.core.services.exception.ThrowExceptionService) MockChannel(com.adaptris.core.stubs.MockChannel) Channel(com.adaptris.core.Channel) JmsTransactedWorkflow(com.adaptris.core.jms.JmsTransactedWorkflow) ConfiguredException(com.adaptris.core.services.exception.ConfiguredException) PtpProducer(com.adaptris.core.jms.PtpProducer) Timer(java.util.Timer) TimerTask(java.util.TimerTask) StandaloneProducer(com.adaptris.core.StandaloneProducer) Test(org.junit.Test)

Example 23 with ConfiguredException

use of com.adaptris.core.services.exception.ConfiguredException 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...
    }
}
Also used : ThrowExceptionService(com.adaptris.core.services.exception.ThrowExceptionService) ConfiguredException(com.adaptris.core.services.exception.ConfiguredException) ConfiguredException(com.adaptris.core.services.exception.ConfiguredException) Test(org.junit.Test)

Example 24 with ConfiguredException

use of com.adaptris.core.services.exception.ConfiguredException 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);
    }
}
Also used : ThrowExceptionService(com.adaptris.core.services.exception.ThrowExceptionService) ConfiguredException(com.adaptris.core.services.exception.ConfiguredException) Test(org.junit.Test)

Example 25 with ConfiguredException

use of com.adaptris.core.services.exception.ConfiguredException 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;
    }
}
Also used : TimeInterval(com.adaptris.util.TimeInterval) ServiceException(com.adaptris.core.ServiceException) DefaultEventHandler(com.adaptris.core.DefaultEventHandler) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) ThrowExceptionService(com.adaptris.core.services.exception.ThrowExceptionService) AppendingMessageAggregator(com.adaptris.core.services.aggregator.AppendingMessageAggregator) ConfiguredException(com.adaptris.core.services.exception.ConfiguredException) Test(org.junit.Test)

Aggregations

ConfiguredException (com.adaptris.core.services.exception.ConfiguredException)45 ThrowExceptionService (com.adaptris.core.services.exception.ThrowExceptionService)45 Test (org.junit.Test)41 MockMessageProducer (com.adaptris.core.stubs.MockMessageProducer)26 MockChannel (com.adaptris.core.stubs.MockChannel)18 StandaloneProducer (com.adaptris.core.StandaloneProducer)13 AddMetadataService (com.adaptris.core.services.metadata.AddMetadataService)13 MockSkipProducerService (com.adaptris.core.stubs.MockSkipProducerService)12 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)10 PayloadFromTemplateService (com.adaptris.core.services.metadata.PayloadFromTemplateService)10 FailFirstMockMessageProducer (com.adaptris.core.stubs.FailFirstMockMessageProducer)10 Channel (com.adaptris.core.Channel)8 ServiceException (com.adaptris.core.ServiceException)7 JmsTransactedWorkflow (com.adaptris.core.jms.JmsTransactedWorkflow)6 EventHandlerAwareService (com.adaptris.core.stubs.EventHandlerAwareService)6 PtpProducer (com.adaptris.core.jms.PtpProducer)5 StaticMockMessageProducer (com.adaptris.core.stubs.StaticMockMessageProducer)5 TimeInterval (com.adaptris.util.TimeInterval)5 Iterator (java.util.Iterator)5 MockMessageConsumer (com.adaptris.core.stubs.MockMessageConsumer)4