Search in sources :

Example 56 with MockChannel

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

the class ConnectionErrorHandlerTest method testChannelChannelCloseConnectionErrorHandler.

@Test
public void testChannelChannelCloseConnectionErrorHandler() throws Exception {
    MockChannel c = new MockChannel();
    TriggeredFailingConnection con = new TriggeredFailingConnection(new ChannelCloseErrorHandler());
    c.setConsumeConnection(con);
    start(c);
    con.triggerError();
    assertEquals(1, c.getInitCount());
    assertEquals(1, c.getStartCount());
    assertEquals(1, c.getStopCount());
    assertEquals(1, c.getCloseCount());
    assertEquals(ClosedState.getInstance(), c.retrieveComponentState());
    stop(c);
}
Also used : MockChannel(com.adaptris.core.stubs.MockChannel) Test(org.junit.Test)

Example 57 with MockChannel

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

the class ConnectionErrorHandlerTest method testChannelStopped_ConnectionErrorHandler.

@Test
public void testChannelStopped_ConnectionErrorHandler() throws Exception {
    MockChannel started = new MockChannel();
    MockChannel stopped = new MockChannel();
    TriggeredFailingConnection con = new TriggeredFailingConnection();
    started.setConsumeConnection(con);
    stopped.setConsumeConnection(con);
    start(started);
    start(stopped);
    stopped.requestStop();
    con.triggerError();
    assertEquals(2, started.getInitCount());
    assertEquals(2, started.getStartCount());
    assertEquals(1, started.getStopCount());
    assertEquals(1, started.getCloseCount());
    assertEquals(1, stopped.getInitCount());
    assertEquals(1, stopped.getStartCount());
    assertEquals(1, stopped.getStopCount());
    assertEquals(1, stopped.getCloseCount());
    assertEquals(ClosedState.getInstance(), stopped.retrieveComponentState());
    stop(started);
}
Also used : MockChannel(com.adaptris.core.stubs.MockChannel) Test(org.junit.Test)

Example 58 with MockChannel

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

the class ConnectionErrorHandlerTest method testChannelClosed_ConnectionErrorHandler.

@Test
public void testChannelClosed_ConnectionErrorHandler() throws Exception {
    MockChannel started = new MockChannel();
    MockChannel neverStarted = new MockChannel();
    TriggeredFailingConnection con = new TriggeredFailingConnection();
    started.setConsumeConnection(con);
    neverStarted.setConsumeConnection(con);
    start(started);
    con.triggerError();
    assertEquals(2, started.getInitCount());
    assertEquals(2, started.getStartCount());
    assertEquals(1, started.getStopCount());
    assertEquals(1, started.getCloseCount());
    // ID 167 - Previously neverStarted would have been started as the CEH would always restart all exception listeners.
    assertEquals(0, neverStarted.getInitCount());
    assertEquals(0, neverStarted.getStartCount());
    assertEquals(0, neverStarted.getStopCount());
    assertEquals(0, neverStarted.getCloseCount());
    stop(started);
}
Also used : MockChannel(com.adaptris.core.stubs.MockChannel) Test(org.junit.Test)

Example 59 with MockChannel

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

the class FixedIntervalPollerTest method testLifecycle.

@Test
public void testLifecycle() throws Exception {
    PollingTrigger consumer = new PollingTrigger();
    consumer.setPoller(new FixedIntervalPoller(new TimeInterval(100L, TimeUnit.MILLISECONDS)));
    MockMessageProducer producer = new MockMessageProducer();
    MockChannel channel = new MockChannel();
    StandardWorkflow workflow = new StandardWorkflow();
    workflow.setConsumer(consumer);
    workflow.setProducer(producer);
    channel.getWorkflowList().add(workflow);
    try {
        channel.requestClose();
        channel.requestStart();
        waitForMessages(producer, 1);
        channel.requestStop();
        producer.getMessages().clear();
        channel.requestStart();
        waitForMessages(producer, 1);
        channel.requestClose();
        producer.getMessages().clear();
        channel.requestStart();
        waitForMessages(producer, 1);
    } finally {
        channel.requestClose();
    }
}
Also used : MockChannel(com.adaptris.core.stubs.MockChannel) TimeInterval(com.adaptris.util.TimeInterval) MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) Test(org.junit.Test)

Example 60 with MockChannel

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

the class ThreadContextWorkflowTest method testOnMessage_ServiceFailsFailureCallback.

@Test
public void testOnMessage_ServiceFailsFailureCallback() throws Exception {
    AtomicBoolean onSuccess = new AtomicBoolean(false);
    MockChannel channel = createChannel(new MockMessageProducer(), Arrays.asList(new Service[] { new ThrowExceptionService(new ConfiguredException("expected")) }));
    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);
    }
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) MockChannel(com.adaptris.core.stubs.MockChannel) FailFirstMockMessageProducer(com.adaptris.core.stubs.FailFirstMockMessageProducer) MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) StaticMockMessageProducer(com.adaptris.core.stubs.StaticMockMessageProducer) ThrowExceptionService(com.adaptris.core.services.exception.ThrowExceptionService) ConfiguredException(com.adaptris.core.services.exception.ConfiguredException) 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)

Aggregations

MockChannel (com.adaptris.core.stubs.MockChannel)145 Test (org.junit.Test)125 MockMessageProducer (com.adaptris.core.stubs.MockMessageProducer)92 ThrowExceptionService (com.adaptris.core.services.exception.ThrowExceptionService)62 MockSkipProducerService (com.adaptris.core.stubs.MockSkipProducerService)59 PayloadFromTemplateService (com.adaptris.core.services.metadata.PayloadFromTemplateService)56 AddMetadataService (com.adaptris.core.services.metadata.AddMetadataService)44 FailFirstMockMessageProducer (com.adaptris.core.stubs.FailFirstMockMessageProducer)40 StaticMockMessageProducer (com.adaptris.core.stubs.StaticMockMessageProducer)32 TimeInterval (com.adaptris.util.TimeInterval)28 EventHandlerAwareService (com.adaptris.core.stubs.EventHandlerAwareService)22 Iterator (java.util.Iterator)17 StandardWorkflow (com.adaptris.core.StandardWorkflow)13 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)13 ConfiguredException (com.adaptris.core.services.exception.ConfiguredException)11 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)10 Channel (com.adaptris.core.Channel)10 JmsConnectionErrorHandler (com.adaptris.core.jms.JmsConnectionErrorHandler)9 MockMessageConsumer (com.adaptris.core.stubs.MockMessageConsumer)9 JmsConnection (com.adaptris.core.jms.JmsConnection)8