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