Search in sources :

Example 1 with FailFirstMockMessageProducer

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

the class DefaultFailedMessageRetrierTest method testMultipleRetries.

@Test
public void testMultipleRetries() throws Exception {
    DefaultFailedMessageRetrier retrier = create();
    StandardWorkflow wf = createWorkflow();
    try {
        wf.setProducer(new FailFirstMockMessageProducer());
        FailFirstMockMessageProducer p = (FailFirstMockMessageProducer) wf.getProducer();
        retrier.addWorkflow(wf);
        retrier.addWorkflow(createWorkflow());
        AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage("ABCDEF");
        msg.addMetadata(Workflow.WORKFLOW_ID_KEY, wf.obtainWorkflowId());
        start(retrier);
        start(wf);
        retrier.onAdaptrisMessage(msg);
        assertTrue(msg.containsKey(CoreConstants.RETRY_COUNT_KEY));
        assertEquals("1", msg.getMetadataValue(CoreConstants.RETRY_COUNT_KEY));
        retrier.onAdaptrisMessage(msg);
        assertEquals(1, p.getMessages().size());
        assertEquals("2", msg.getMetadataValue(CoreConstants.RETRY_COUNT_KEY));
    } finally {
        stop(retrier);
        stop(wf);
    }
}
Also used : FailFirstMockMessageProducer(com.adaptris.core.stubs.FailFirstMockMessageProducer) Test(org.junit.Test)

Example 2 with FailFirstMockMessageProducer

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

the class DefaultFailedMessageRetrierTest method testAdapterRetry.

@Test
public void testAdapterRetry() throws Exception {
    DefaultFailedMessageRetrier retrier = create();
    MockMessageProducer errProd = new MockMessageProducer();
    StandardProcessingExceptionHandler speh = new StandardProcessingExceptionHandler(new StandaloneProducer(errProd));
    Adapter adapter = createAdapterForRetry(retrier, speh);
    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 3 with FailFirstMockMessageProducer

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

the class DefaultEventHandlerTest method testSendEventWithException.

@Test
public void testSendEventWithException() throws Exception {
    Event e = EventFactory.create(AdapterCloseEvent.class);
    DefaultEventHandler eh = applyConfiguration(newEventHandler("testSendEventWithException"));
    eh.setProducer(new FailFirstMockMessageProducer(2));
    try {
        LifecycleHelper.initAndStart(eh);
        eh.send(e);
        eh.setLogAllExceptions(true);
        eh.send(e);
    } finally {
        eh.requestClose();
    }
    doAssertions(eh, 0, e.getClass());
}
Also used : FailFirstMockMessageProducer(com.adaptris.core.stubs.FailFirstMockMessageProducer) AdapterCloseEvent(com.adaptris.core.event.AdapterCloseEvent) Test(org.junit.Test)

Example 4 with FailFirstMockMessageProducer

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

the class ThreadContextWorkflowTest 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);
    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) 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)

Example 5 with FailFirstMockMessageProducer

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

the class StandardWorkflowTest method testOnMessage_ProducerFailsWithRetryHandlerSuccessCallback.

@Test
public void testOnMessage_ProducerFailsWithRetryHandlerSuccessCallback() throws Exception {
    AtomicBoolean onSuccess = new AtomicBoolean(false);
    MockChannel channel = createChannel(new FailFirstMockMessageProducer(1), Arrays.asList(new Service[] { new NullService() }));
    channel.setMessageErrorHandler(new RetryMessageErrorHandler(2, 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);
        });
        Awaitility.await().atMost(Duration.ofSeconds(2)).with().pollInterval(Duration.ofMillis(100)).until(onSuccess::get);
        assertTrue(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)

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