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);
}
}
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);
}
}
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());
}
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);
}
}
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);
}
}
Aggregations