Search in sources :

Example 11 with FailFirstMockMessageProducer

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

the class ThreadContextWorkflowTest 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);
    ThreadContextWorkflow workflow = (ThreadContextWorkflow) 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) 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 12 with FailFirstMockMessageProducer

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

the class RetryMessageErrorHandlerTest method testRetryWithSuccess.

@Test
public void testRetryWithSuccess() throws Exception {
    String name = renameThread("testRetryWithSuccess");
    try {
        MockMessageProducer failProducer = new MockMessageProducer();
        RetryMessageErrorHandler meh = createMessageErrorHandler(failProducer);
        meh.setRetryInterval(DEFAULT_RETRY_INTERVAL);
        meh.setRetryLimit(2);
        FailFirstMockMessageProducer workflowProducer = new FailFirstMockMessageProducer(1);
        StandardWorkflow workflow = createWorkflow(workflowProducer);
        Channel channel = createChannel(workflow, meh);
        workflow.setServiceCollection(new ServiceList());
        channel.prepare();
        channel.requestStart();
        AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage("XXXX");
        workflow.onAdaptrisMessage(msg);
        waitForMessages(workflowProducer, 1);
        channel.requestClose();
        assertEquals("Ensure producer success", 1, workflowProducer.getMessages().size());
    } finally {
        renameThread(name);
    }
}
Also used : FailFirstMockMessageProducer(com.adaptris.core.stubs.FailFirstMockMessageProducer) FailFirstMockMessageProducer(com.adaptris.core.stubs.FailFirstMockMessageProducer) MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) MockChannel(com.adaptris.core.stubs.MockChannel) Test(org.junit.Test)

Example 13 with FailFirstMockMessageProducer

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

the class RetryMessageErrorHandlerTest method testBug854.

@Test
@SuppressWarnings("deprecation")
public void testBug854() throws Exception {
    String name = renameThread("testBug854");
    try {
        MockMessageProducer failProducer = new MockMessageProducer();
        RetryMessageErrorHandler meh = createMessageErrorHandler(failProducer);
        meh.setRetryInterval(DEFAULT_RETRY_INTERVAL);
        meh.setRetryLimit(0);
        FailFirstMockMessageProducer workflowProducer = new FailFirstMockMessageProducer(1);
        StandardWorkflow workflow = createWorkflow(workflowProducer);
        workflow.setServiceCollection(new ServiceList());
        workflow.setProduceExceptionHandler(new RestartProduceExceptionHandler());
        Channel channel = new Channel();
        channel.getWorkflowList().add(workflow);
        channel.setProduceConnection(new MockConnection());
        channel.getProduceConnection().setConnectionErrorHandler(new ChannelRestartConnectionErrorHandler());
        Adapter adapter = new Adapter();
        adapter.setUniqueId(new SimpleIdGenerator().create(this));
        adapter.setMessageErrorHandler(meh);
        adapter.getChannelList().addChannel(channel);
        // adapter.prepare();
        adapter.requestStart();
        workflow.onAdaptrisMessage(AdaptrisMessageFactory.getDefaultInstance().newMessage("XXXX"));
        waitForMessages(workflowProducer, 1);
        adapter.requestClose();
        assertEquals("Ensure producer success", 1, workflowProducer.getMessages().size());
        assertEquals("Should not have produced to failProducer", 0, failProducer.getMessages().size());
    } finally {
        renameThread(name);
    }
}
Also used : FailFirstMockMessageProducer(com.adaptris.core.stubs.FailFirstMockMessageProducer) ChannelRestartConnectionErrorHandler(com.adaptris.core.stubs.ChannelRestartConnectionErrorHandler) FailFirstMockMessageProducer(com.adaptris.core.stubs.FailFirstMockMessageProducer) MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) MockChannel(com.adaptris.core.stubs.MockChannel) SimpleIdGenerator(com.adaptris.util.SimpleIdGenerator) MockConnection(com.adaptris.core.stubs.MockConnection) Test(org.junit.Test)

Example 14 with FailFirstMockMessageProducer

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

the class RetryOnceStandaloneProducerTest method testProducerFailsTwiceAsService.

@Test
public void testProducerFailsTwiceAsService() {
    FailFirstMockMessageProducer producer = new FailFirstMockMessageProducer();
    producer.setFailUntilCount(2);
    service.setProducer(producer);
    try {
        service.doService(AdaptrisMessageFactory.getDefaultInstance().newMessage());
        fail();
    } catch (Exception e) {
    // expected
    }
}
Also used : FailFirstMockMessageProducer(com.adaptris.core.stubs.FailFirstMockMessageProducer) StaticCounterFailFirstMockMessageProducer(com.adaptris.core.stubs.StaticCounterFailFirstMockMessageProducer) Test(org.junit.Test)

Example 15 with FailFirstMockMessageProducer

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

the class RetryOnceStandaloneProducerTest method testProducerFailsTwiceAsProducer.

@Test
public void testProducerFailsTwiceAsProducer() {
    FailFirstMockMessageProducer producer = new FailFirstMockMessageProducer();
    producer.setFailUntilCount(2);
    service.setProducer(producer);
    try {
        service.doService(AdaptrisMessageFactory.getDefaultInstance().newMessage());
        fail();
    } catch (Exception e) {
    // expected
    }
}
Also used : FailFirstMockMessageProducer(com.adaptris.core.stubs.FailFirstMockMessageProducer) StaticCounterFailFirstMockMessageProducer(com.adaptris.core.stubs.StaticCounterFailFirstMockMessageProducer) 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