Search in sources :

Example 6 with MockMessageConsumer

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;
}
Also used : StubAdapterStartUpEvent(com.adaptris.core.stubs.StubAdapterStartUpEvent) MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) MockMessageConsumer(com.adaptris.core.stubs.MockMessageConsumer)

Example 7 with MockMessageConsumer

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;
}
Also used : Random(java.util.Random) ArrayList(java.util.ArrayList) MockMessageConsumer(com.adaptris.core.stubs.MockMessageConsumer)

Example 8 with MockMessageConsumer

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);
    }
}
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 9 with MockMessageConsumer

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);
}
Also used : StateManagedStandaloneConsumer(com.adaptris.core.stubs.StateManagedStandaloneConsumer) MockStandaloneConsumer(com.adaptris.core.stubs.MockStandaloneConsumer) MockMessageConsumer(com.adaptris.core.stubs.MockMessageConsumer) MockMessageListener(com.adaptris.core.stubs.MockMessageListener) Test(org.junit.Test)

Example 10 with MockMessageConsumer

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);
    }
}
Also used : MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) ThrowExceptionService(com.adaptris.core.services.exception.ThrowExceptionService) ConfiguredException(com.adaptris.core.services.exception.ConfiguredException) MockMessageConsumer(com.adaptris.core.stubs.MockMessageConsumer) Test(org.junit.Test)

Aggregations

MockMessageConsumer (com.adaptris.core.stubs.MockMessageConsumer)31 Test (org.junit.Test)20 MockMessageProducer (com.adaptris.core.stubs.MockMessageProducer)18 MockChannel (com.adaptris.core.stubs.MockChannel)10 FailFirstMockMessageProducer (com.adaptris.core.stubs.FailFirstMockMessageProducer)5 ConfiguredException (com.adaptris.core.services.exception.ConfiguredException)4 ThrowExceptionService (com.adaptris.core.services.exception.ThrowExceptionService)4 MockMessageListener (com.adaptris.core.stubs.MockMessageListener)4 MockStandaloneConsumer (com.adaptris.core.stubs.MockStandaloneConsumer)4 MockConnection (com.adaptris.core.stubs.MockConnection)3 StaticMockMessageProducer (com.adaptris.core.stubs.StaticMockMessageProducer)3 StandardWorkflow (com.adaptris.core.StandardWorkflow)2 MockRequestReplyProducer (com.adaptris.core.stubs.MockRequestReplyProducer)2 StateManagedStandaloneConsumer (com.adaptris.core.stubs.StateManagedStandaloneConsumer)2 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)1 AdaptrisMessageConsumer (com.adaptris.core.AdaptrisMessageConsumer)1 AdaptrisMessageProducer (com.adaptris.core.AdaptrisMessageProducer)1 Channel (com.adaptris.core.Channel)1 Service (com.adaptris.core.Service)1 ServiceImp (com.adaptris.core.ServiceImp)1