Search in sources :

Example 31 with MockChannel

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

the class PoolingWorkflowTest method testOnMessage_SkipProducer.

@Test
public void testOnMessage_SkipProducer() throws Exception {
    StaticMockMessageProducer serviceProducer = new StaticMockMessageProducer();
    serviceProducer.getMessages().clear();
    MockChannel channel = createAndPrepareChannel(Arrays.asList(new Service[] { createService(), new StandaloneProducer(serviceProducer), new MockSkipProducerService() }));
    try {
        PoolingWorkflow workflow = (PoolingWorkflow) channel.getWorkflowList().get(0);
        MockMessageProducer workflowProducer = (MockMessageProducer) workflow.getProducer();
        start(channel);
        submitMessages(workflow, 10);
        waitForMessages(serviceProducer, 10);
        // assertEquals(10, serviceProducer.messageCount());
        assertEquals(0, workflowProducer.messageCount());
    } finally {
        stop(channel);
    }
}
Also used : MockChannel(com.adaptris.core.stubs.MockChannel) MockSkipProducerService(com.adaptris.core.stubs.MockSkipProducerService) 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) StaticMockMessageProducer(com.adaptris.core.stubs.StaticMockMessageProducer) Test(org.junit.Test)

Example 32 with MockChannel

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

the class PoolingWorkflowTest method testLessThanPoolSize.

@Test
public void testLessThanPoolSize() throws Exception {
    MockChannel channel = createChannel();
    PoolingWorkflow wf = (PoolingWorkflow) channel.getWorkflowList().get(0);
    int count = wf.poolSize() - 1;
    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 33 with MockChannel

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

the class PoolingWorkflowTest method testHandleRuntimeException.

@Test
public void testHandleRuntimeException() 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 RuntimeException();
        }
    };
    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 34 with MockChannel

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

the class PoolingWorkflowTest method createAndPrepareChannel.

private MockChannel createAndPrepareChannel(List<Service> services) throws Exception {
    MockChannel channel = buildChannel(services);
    LifecycleHelper.prepare(channel);
    return channel;
}
Also used : MockChannel(com.adaptris.core.stubs.MockChannel)

Example 35 with MockChannel

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

the class PoolingWorkflowTest method testSingleMessage.

@Test
public void testSingleMessage() throws Exception {
    MockChannel channel = createChannel();
    PoolingWorkflow wf = (PoolingWorkflow) channel.getWorkflowList().get(0);
    MockMessageProducer prod = (MockMessageProducer) wf.getProducer();
    try {
        start(channel);
        submitMessages(wf, 1);
        waitForMessages(prod, 1);
        assertMessages(prod, 1);
    } 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)

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