use of com.adaptris.core.stubs.MockMessageConsumer in project interlok by adaptris.
the class AdapterTest method createAdapter.
/**
* <p>
* Creates a valid Adapter to use in tests. Uese Mock aka Memory MessageConsumer / Producer.
* </p>
*
* @param uniqueId a uniqure identifier for this <code>Adapter</code>
*/
public static Adapter createAdapter(String uniqueId) throws Exception {
// Yes that's right we use the no-arg constructor due to
// what happens if you use the unique-id constructor...
// Behaviour is changed when it calls setEventHandler();
Adapter result = new Adapter();
// XStream sometimes throws a java.util.ConcurrentModificationException when
// marshalling, in DefaultAdapterStartupEvent#setAdapter()
// This *works* round the symptom; but it's not clear as to exactly why it occurs;
// It's clearly a timing issue, but I don't really understand why, as it is single threaded; so the lists shouldn't be
// being modified by anything else.
// So, let's use a StubAdapterStartupEvent that does nothing, doesn't even save the adapter. as we don't care about it.
// redmineID #2557
result.setStartUpEventImp(StubAdapterStartUpEvent.class.getCanonicalName());
StandardWorkflow workflow1 = createWorkflow(uniqueId + "_workflow");
workflow1.setConsumer(new MockMessageConsumer());
workflow1.setProducer(new MockMessageProducer());
Channel channel = new Channel();
channel.setUniqueId(uniqueId + "_channel1");
channel.getWorkflowList().add(workflow1);
result.getChannelList().add(channel);
result.setUniqueId(uniqueId);
return result;
}
use of com.adaptris.core.stubs.MockMessageConsumer in project interlok by adaptris.
the class AdaptrisConnectionTest method createConsumers.
private List<MockMessageConsumer> createConsumers() {
List<MockMessageConsumer> result = new ArrayList<MockMessageConsumer>();
int rnd = new Random().nextInt(20) + 1;
for (int i = 0; i < rnd; i++) {
result.add(new MockMessageConsumer());
}
return result;
}
use of com.adaptris.core.stubs.MockMessageConsumer 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.MockMessageConsumer in project interlok by adaptris.
the class ConnectionErrorHandlerTest method testStateManagedComponentConnectionErrorHandler.
@Test
public void testStateManagedComponentConnectionErrorHandler() throws Exception {
MockStandaloneConsumer c = new StateManagedStandaloneConsumer(new TriggeredFailingConnection(), new MockMessageConsumer(new MockMessageListener()));
start(c);
((TriggeredFailingConnection) c.getConnection()).triggerError();
assertEquals(2, c.getInitCount());
assertEquals(2, c.getStartCount());
assertEquals(1, c.getStopCount());
assertEquals(1, c.getCloseCount());
stop(c);
}
use of com.adaptris.core.stubs.MockMessageConsumer in project interlok by adaptris.
the class StandardProcessingExceptionHandlerTest method testMultipleErrorHandlers_AlwaysHandle_False.
@Test
public void testMultipleErrorHandlers_AlwaysHandle_False() throws Exception {
MockMessageProducer aep = new MockMessageProducer();
MockMessageProducer wep = new MockMessageProducer();
MockMessageProducer cep = new MockMessageProducer();
StandardProcessingExceptionHandler aeh = new StandardProcessingExceptionHandler(new StandaloneProducer(aep));
aeh.setAlwaysHandleException(false);
StandardProcessingExceptionHandler weh = new StandardProcessingExceptionHandler(new StandaloneProducer(wep));
StandardProcessingExceptionHandler ceh = new StandardProcessingExceptionHandler(new StandaloneProducer(cep));
Adapter adapter = AdapterTest.createAdapter(getName());
adapter.setMessageErrorHandler(aeh);
MockMessageConsumer consumer = new MockMessageConsumer();
adapter.getChannelList().clear();
adapter.getChannelList().add(createChannel(consumer, ceh, weh, new ThrowExceptionService(new ConfiguredException(getName()))));
try {
start(adapter);
consumer.submitMessage(AdaptrisMessageFactory.getDefaultInstance().newMessage());
assertEquals(0, aep.messageCount());
assertEquals(0, cep.messageCount());
assertEquals(1, wep.messageCount());
} finally {
stop(adapter);
}
}
Aggregations