Search in sources :

Example 41 with MockChannel

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

the class RequestReplyWorkflowTest method testWorkflow_NullReply.

@Test
public void testWorkflow_NullReply() throws Exception {
    Channel channel = new MockChannel();
    RequestReplyWorkflow workflow = new RequestReplyWorkflow();
    workflow.setConsumer(new MockMessageConsumer());
    AdaptrisMessageProducer replier = mock(AdaptrisMessageProducer.class);
    doThrow(new ProduceException()).when(replier).produce(any(AdaptrisMessage.class));
    doThrow(new ProduceException()).when(replier).produce(any(AdaptrisMessage.class));
    when(replier.createName()).thenReturn("mock");
    when(replier.createQualifier()).thenReturn("mock");
    when(replier.isTrackingEndpoint()).thenReturn(false);
    AdaptrisMessageProducer requestor = mock(AdaptrisMessageProducer.class);
    when(requestor.request(any(AdaptrisMessage.class))).thenReturn(null);
    when(requestor.request(any(AdaptrisMessage.class))).thenReturn(null);
    when(requestor.request(any(AdaptrisMessage.class), anyLong())).thenReturn(null);
    when(requestor.request(any(AdaptrisMessage.class), anyLong())).thenReturn(null);
    when(requestor.createName()).thenReturn("mock");
    when(requestor.createQualifier()).thenReturn("mock");
    when(requestor.isTrackingEndpoint()).thenReturn(false);
    workflow.setProducer(requestor);
    workflow.setReplyProducer(replier);
    channel.getWorkflowList().add(workflow);
    try {
        start(channel);
        submitMessages(workflow, 1);
    } finally {
        stop(channel);
    }
}
Also used : MockChannel(com.adaptris.core.stubs.MockChannel) MockChannel(com.adaptris.core.stubs.MockChannel) MockMessageConsumer(com.adaptris.core.stubs.MockMessageConsumer) Test(org.junit.Test)

Example 42 with MockChannel

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

the class PoolingWorkflowTest method testWorkflowWithInterceptor.

@Test
public void testWorkflowWithInterceptor() throws Exception {
    MockChannel channel = createChannel();
    PoolingWorkflow wf = (PoolingWorkflow) channel.getWorkflowList().get(0);
    MockMessageProducer prod = (MockMessageProducer) wf.getProducer();
    MockWorkflowInterceptor interceptor = new MockWorkflowInterceptor();
    wf.addInterceptor(interceptor);
    try {
        start(channel);
        submitMessages(wf, 1);
        waitForMessages(prod, 1);
        assertMessages(prod, 1);
        assertEquals(1, interceptor.messageCount());
    } finally {
        stop(channel);
    }
}
Also used : MockChannel(com.adaptris.core.stubs.MockChannel) MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) StaticMockMessageProducer(com.adaptris.core.stubs.StaticMockMessageProducer) MockWorkflowInterceptor(com.adaptris.core.stubs.MockWorkflowInterceptor) Test(org.junit.Test)

Example 43 with MockChannel

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

the class PoolingWorkflowTest method testGreaterThanPoolSize.

@Test
public void testGreaterThanPoolSize() throws Exception {
    MockChannel channel = createChannel();
    PoolingWorkflow wf = (PoolingWorkflow) channel.getWorkflowList().get(0);
    int count = wf.poolSize() * 2;
    MockMessageProducer prod = (MockMessageProducer) wf.getProducer();
    try {
        start(channel);
        submitMessages(wf, count);
        waitForMessages(prod, count);
        assertTrue("ObjectPool > 1", wf.currentObjectPoolCount() > 1);
        assertTrue("ThreadPool > 1", wf.currentThreadPoolCount() > 1);
        assertTrue("ObjectPool >=0", wf.currentlyIdleObjects() >= 0);
        assertTrue("ThreadPool >=0", wf.currentlyActiveObjects() >= 0);
        assertMessages(prod, count);
    } finally {
        stop(channel);
    }
}
Also used : MockChannel(com.adaptris.core.stubs.MockChannel) MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) StaticMockMessageProducer(com.adaptris.core.stubs.StaticMockMessageProducer) Test(org.junit.Test)

Example 44 with MockChannel

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

the class PoolingWorkflowTest method testHandleProduceException.

@Test
public void testHandleProduceException() throws Exception {
    MockChannel channel = createChannel();
    PoolingWorkflow wf = (PoolingWorkflow) channel.getWorkflowList().get(0);
    MockMessageProducer meh = new MockMessageProducer();
    MockMessageProducer prod = new MockMessageProducer() {

        @Override
        protected void doProduce(AdaptrisMessage msg, String endpoint) throws ProduceException {
            throw new ProduceException();
        }
    };
    wf.setProducer(prod);
    channel.setMessageErrorHandler(new StandardProcessingExceptionHandler(new ServiceList(new ArrayList<Service>(Arrays.asList(new Service[] { new StandaloneProducer(meh) })))));
    try {
        start(channel);
        submitMessages(wf, 1);
        waitForMessages(meh, 1);
        assertEquals(1, meh.messageCount());
    } finally {
        stop(channel);
    }
}
Also used : MockChannel(com.adaptris.core.stubs.MockChannel) MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) StaticMockMessageProducer(com.adaptris.core.stubs.StaticMockMessageProducer) WaitService(com.adaptris.core.services.WaitService) XmlRoundTripService(com.adaptris.core.stubs.XmlRoundTripService) MockSkipProducerService(com.adaptris.core.stubs.MockSkipProducerService) ThrowExceptionService(com.adaptris.core.services.exception.ThrowExceptionService) Test(org.junit.Test)

Example 45 with MockChannel

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

the class PoolingWorkflowTest method testHandleChannelUnavailableForever.

@Test
public void testHandleChannelUnavailableForever() throws Exception {
    MockMessageProducer producer = new MockMessageProducer();
    final MockChannel channel = createChannel();
    PoolingWorkflow workflow = (PoolingWorkflow) channel.getWorkflowList().get(0);
    MockMessageProducer meh = new MockMessageProducer();
    try {
        workflow.setChannelUnavailableWaitInterval(new TimeInterval(100L, TimeUnit.MILLISECONDS));
        workflow.setMessageErrorHandler(new StandardProcessingExceptionHandler(new ServiceList(new ArrayList<Service>(Arrays.asList(new Service[] { new StandaloneProducer(meh) })))));
        AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(PAYLOAD_1);
        start(channel);
        channel.toggleAvailability(false);
        workflow.onAdaptrisMessage(msg);
        assertEquals("Make none produced", 0, producer.getMessages().size());
        assertEquals(1, meh.getMessages().size());
    } finally {
        stop(channel);
    }
}
Also used : MockChannel(com.adaptris.core.stubs.MockChannel) MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) StaticMockMessageProducer(com.adaptris.core.stubs.StaticMockMessageProducer) TimeInterval(com.adaptris.util.TimeInterval) WaitService(com.adaptris.core.services.WaitService) XmlRoundTripService(com.adaptris.core.stubs.XmlRoundTripService) MockSkipProducerService(com.adaptris.core.stubs.MockSkipProducerService) ThrowExceptionService(com.adaptris.core.services.exception.ThrowExceptionService) 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