Search in sources :

Example 6 with FailFirstMockMessageProducer

use of com.adaptris.core.stubs.FailFirstMockMessageProducer in project interlok by adaptris.

the class DefaultFailedMessageRetrierTest method testRoundTrip_AdapterRetry.

@Test
public void testRoundTrip_AdapterRetry() throws Exception {
    AdaptrisMarshaller marshaller = DefaultMarshaller.getDefaultMarshaller();
    Adapter adapter = (Adapter) marshaller.unmarshal(marshaller.marshal(createAdapterForRetry(create(), new StandardProcessingExceptionHandler(new StandaloneProducer(new MockMessageProducer())))));
    DefaultFailedMessageRetrier retrier = (DefaultFailedMessageRetrier) adapter.getFailedMessageRetrier();
    MockMessageProducer errProd = getErrorHandler(adapter);
    try {
        FailFirstMockMessageProducer workflowProducer = (FailFirstMockMessageProducer) adapter.getChannelList().get(0).getWorkflowList().get(0).getProducer();
        MockMessageConsumer consumer = (MockMessageConsumer) adapter.getChannelList().get(0).getWorkflowList().get(0).getConsumer();
        AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage("ABCDEF");
        start(adapter);
        consumer.submitMessage(msg);
        // SHould have failed
        assertEquals(1, errProd.messageCount());
        retrier.onAdaptrisMessage(errProd.getMessages().get(0));
        assertTrue(msg.containsKey(CoreConstants.RETRY_COUNT_KEY));
        assertEquals("1", msg.getMetadataValue(CoreConstants.RETRY_COUNT_KEY));
        assertEquals(1, workflowProducer.getMessages().size());
    } finally {
        stop(adapter);
    }
}
Also used : FailFirstMockMessageProducer(com.adaptris.core.stubs.FailFirstMockMessageProducer) FailFirstMockMessageProducer(com.adaptris.core.stubs.FailFirstMockMessageProducer) MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) MockMessageConsumer(com.adaptris.core.stubs.MockMessageConsumer) Test(org.junit.Test)

Example 7 with FailFirstMockMessageProducer

use of com.adaptris.core.stubs.FailFirstMockMessageProducer in project interlok by adaptris.

the class DefaultFailedMessageRetrierTest method createAdapterForRetry.

private Adapter createAdapterForRetry(FailedMessageRetrier retrier, ProcessingExceptionHandler errorHandler) throws Exception {
    Adapter adapter = AdapterTest.createAdapter(getName());
    adapter.setFailedMessageRetrier(retrier);
    adapter.setMessageErrorHandler(errorHandler);
    adapter.getChannelList().clear();
    Channel c = new Channel();
    c.setUniqueId(getName());
    StandardWorkflow wf = new StandardWorkflow();
    wf.setUniqueId(getName());
    wf.setConsumer(new MockMessageConsumer());
    wf.setProducer(new FailFirstMockMessageProducer());
    c.getWorkflowList().add(wf);
    adapter.getChannelList().add(c);
    return adapter;
}
Also used : FailFirstMockMessageProducer(com.adaptris.core.stubs.FailFirstMockMessageProducer) MockMessageConsumer(com.adaptris.core.stubs.MockMessageConsumer)

Example 8 with FailFirstMockMessageProducer

use of com.adaptris.core.stubs.FailFirstMockMessageProducer in project interlok by adaptris.

the class StandardWorkflowTest method testOnMessage_ProducerFailsWithRetryHandlerFailureCallback.

@Test
public void testOnMessage_ProducerFailsWithRetryHandlerFailureCallback() throws Exception {
    AtomicBoolean onSuccess = new AtomicBoolean(false);
    MockChannel channel = createChannel(new FailFirstMockMessageProducer(5), Arrays.asList(new Service[] { new NullService() }));
    channel.setMessageErrorHandler(new RetryMessageErrorHandler(4, new TimeInterval(100l, TimeUnit.MILLISECONDS), new NullService()));
    AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(PAYLOAD_1);
    StandardWorkflow workflow = (StandardWorkflow) channel.getWorkflowList().get(0);
    try {
        start(channel);
        workflow.onAdaptrisMessage(msg, (m) -> {
            onSuccess.set(true);
        }, (m) -> {
            onSuccess.set(false);
        });
        assertFalse(onSuccess.get());
    } finally {
        stop(channel);
    }
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) FailFirstMockMessageProducer(com.adaptris.core.stubs.FailFirstMockMessageProducer) MockChannel(com.adaptris.core.stubs.MockChannel) TimeInterval(com.adaptris.util.TimeInterval) PayloadFromTemplateService(com.adaptris.core.services.metadata.PayloadFromTemplateService) EventHandlerAwareService(com.adaptris.core.stubs.EventHandlerAwareService) MockSkipProducerService(com.adaptris.core.stubs.MockSkipProducerService) ThrowExceptionService(com.adaptris.core.services.exception.ThrowExceptionService) AddMetadataService(com.adaptris.core.services.metadata.AddMetadataService) Test(org.junit.Test)

Example 9 with FailFirstMockMessageProducer

use of com.adaptris.core.stubs.FailFirstMockMessageProducer in project interlok by adaptris.

the class StandardWorkflowTest method testOnMessage_ProducerFailsFailureCallback.

@Test
public void testOnMessage_ProducerFailsFailureCallback() throws Exception {
    AtomicBoolean onSuccess = new AtomicBoolean(false);
    MockChannel channel = createChannel(new FailFirstMockMessageProducer(1), Arrays.asList(new Service[] { new NullService() }));
    AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(PAYLOAD_1);
    StandardWorkflow workflow = (StandardWorkflow) channel.getWorkflowList().get(0);
    try {
        start(channel);
        workflow.onAdaptrisMessage(msg, (m) -> {
            onSuccess.set(true);
        }, (m) -> {
            onSuccess.set(false);
        });
        assertFalse(onSuccess.get());
    } finally {
        stop(channel);
    }
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) FailFirstMockMessageProducer(com.adaptris.core.stubs.FailFirstMockMessageProducer) MockChannel(com.adaptris.core.stubs.MockChannel) PayloadFromTemplateService(com.adaptris.core.services.metadata.PayloadFromTemplateService) EventHandlerAwareService(com.adaptris.core.stubs.EventHandlerAwareService) MockSkipProducerService(com.adaptris.core.stubs.MockSkipProducerService) ThrowExceptionService(com.adaptris.core.services.exception.ThrowExceptionService) AddMetadataService(com.adaptris.core.services.metadata.AddMetadataService) Test(org.junit.Test)

Example 10 with FailFirstMockMessageProducer

use of com.adaptris.core.stubs.FailFirstMockMessageProducer in project interlok by adaptris.

the class ThreadContextWorkflowTest method testOnMessage_ProducerFailsWithRetryHandlerFailureCallback.

@Test
public void testOnMessage_ProducerFailsWithRetryHandlerFailureCallback() throws Exception {
    AtomicBoolean onSuccess = new AtomicBoolean(false);
    MockChannel channel = createChannel(new FailFirstMockMessageProducer(5), Arrays.asList(new Service[] { new NullService() }));
    channel.setMessageErrorHandler(new RetryMessageErrorHandler(4, new TimeInterval(100l, TimeUnit.MILLISECONDS), new NullService()));
    AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(PAYLOAD_1);
    ThreadContextWorkflow workflow = (ThreadContextWorkflow) channel.getWorkflowList().get(0);
    try {
        start(channel);
        workflow.onAdaptrisMessage(msg, (m) -> {
            onSuccess.set(true);
        }, (m) -> {
            onSuccess.set(false);
        });
        assertFalse(onSuccess.get());
    } finally {
        stop(channel);
    }
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) FailFirstMockMessageProducer(com.adaptris.core.stubs.FailFirstMockMessageProducer) MockChannel(com.adaptris.core.stubs.MockChannel) TimeInterval(com.adaptris.util.TimeInterval) PayloadFromTemplateService(com.adaptris.core.services.metadata.PayloadFromTemplateService) MockSkipProducerService(com.adaptris.core.stubs.MockSkipProducerService) ThrowExceptionService(com.adaptris.core.services.exception.ThrowExceptionService) AddMetadataService(com.adaptris.core.services.metadata.AddMetadataService) Test(org.junit.Test)

Aggregations

FailFirstMockMessageProducer (com.adaptris.core.stubs.FailFirstMockMessageProducer)15 Test (org.junit.Test)14 MockChannel (com.adaptris.core.stubs.MockChannel)8 ThrowExceptionService (com.adaptris.core.services.exception.ThrowExceptionService)6 AddMetadataService (com.adaptris.core.services.metadata.AddMetadataService)6 PayloadFromTemplateService (com.adaptris.core.services.metadata.PayloadFromTemplateService)6 MockSkipProducerService (com.adaptris.core.stubs.MockSkipProducerService)6 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)6 MockMessageProducer (com.adaptris.core.stubs.MockMessageProducer)4 TimeInterval (com.adaptris.util.TimeInterval)4 EventHandlerAwareService (com.adaptris.core.stubs.EventHandlerAwareService)3 MockMessageConsumer (com.adaptris.core.stubs.MockMessageConsumer)3 StaticCounterFailFirstMockMessageProducer (com.adaptris.core.stubs.StaticCounterFailFirstMockMessageProducer)2 AdapterCloseEvent (com.adaptris.core.event.AdapterCloseEvent)1 ChannelRestartConnectionErrorHandler (com.adaptris.core.stubs.ChannelRestartConnectionErrorHandler)1 MockConnection (com.adaptris.core.stubs.MockConnection)1 SimpleIdGenerator (com.adaptris.util.SimpleIdGenerator)1