Search in sources :

Example 36 with MockChannel

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

the class PoolingWorkflowTest method testHandleChannelUnavailable.

@Test
public void testHandleChannelUnavailable() throws Exception {
    final MockChannel channel = createChannel();
    PoolingWorkflow wf = (PoolingWorkflow) channel.getWorkflowList().get(0);
    MockMessageProducer prod = (MockMessageProducer) wf.getProducer();
    try {
        wf.setChannelUnavailableWaitInterval(new TimeInterval(1200L, TimeUnit.MILLISECONDS));
        start(channel);
        AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage("");
        Timer t = new Timer(true);
        channel.toggleAvailability(false);
        t.schedule(new TimerTask() {

            @Override
            public void run() {
                channel.toggleAvailability(true);
            }
        }, 500);
        wf.onAdaptrisMessage(msg);
        waitForMessages(prod, 1);
        assertEquals(1, prod.messageCount());
    } 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) Timer(java.util.Timer) TimerTask(java.util.TimerTask) Test(org.junit.Test)

Example 37 with MockChannel

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

the class PoolingWorkflowTest method testMaxIdle_CannotExceed_Poolsize.

@Test
public void testMaxIdle_CannotExceed_Poolsize() throws Exception {
    MockChannel channel = createChannel();
    PoolingWorkflow wf = (PoolingWorkflow) channel.getWorkflowList().get(0);
    wf.setMaxIdle(100);
    wf.setThreadKeepAlive(new TimeInterval(100L, TimeUnit.MILLISECONDS));
    LifecycleHelper.init(channel);
    assertEquals(10, wf.poolSize());
    assertEquals(10, wf.maxIdle());
    assertEquals(DEFAULT_MIN_IDLE, wf.minIdle());
    LifecycleHelper.close(channel);
}
Also used : MockChannel(com.adaptris.core.stubs.MockChannel) TimeInterval(com.adaptris.util.TimeInterval) Test(org.junit.Test)

Example 38 with MockChannel

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

the class PoolingWorkflowTest method testFixedPoolsizeAfterProcessing.

@Test
public void testFixedPoolsizeAfterProcessing() throws Exception {
    MockChannel channel = createChannel();
    PoolingWorkflow wf = (PoolingWorkflow) channel.getWorkflowList().get(0);
    wf.setMaxIdle(DEFAULT_MAX_POOLSIZE);
    wf.setMinIdle(DEFAULT_MAX_POOLSIZE);
    wf.setThreadKeepAlive(new TimeInterval(100L, TimeUnit.MILLISECONDS));
    int count = wf.poolSize() * 2;
    MockMessageProducer prod = (MockMessageProducer) wf.getProducer();
    try {
        start(channel);
        submitMessages(wf, count);
        waitForMessages(prod, count);
        Thread.sleep(200);
        assertTrue("ObjectPool >= 10", wf.currentObjectPoolCount() >= 1);
        assertTrue("ObjectPool idle >= 1", wf.currentlyIdleObjects() >= 1);
        assertMessages(prod, count);
    } finally {
        stop(channel);
    }
}
Also used : MockChannel(com.adaptris.core.stubs.MockChannel) TimeInterval(com.adaptris.util.TimeInterval) MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) StaticMockMessageProducer(com.adaptris.core.stubs.StaticMockMessageProducer) Test(org.junit.Test)

Example 39 with MockChannel

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

the class GaussianIntervalPollerTest method testLifecycle.

@Test
public void testLifecycle() throws Exception {
    PollingTrigger consumer = new PollingTrigger();
    consumer.setPoller(new GaussianIntervalPoller(new TimeInterval(0L, TimeUnit.SECONDS), 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 40 with MockChannel

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

the class RequestReplyWorkflowTest method createChannel.

// private RequestReplyWorkflow workFlow;
// private MockMessageConsumer consumer;
// private MockRequestReplyProducer producer;
// private MockMessageProducer replyProducer;
private Channel createChannel() throws Exception {
    Channel channel = new MockChannel();
    MockMessageConsumer consumer = new MockMessageConsumer();
    MockRequestReplyProducer producer = new MockRequestReplyProducer();
    MockMessageProducer replyProducer = new MockMessageProducer();
    RequestReplyWorkflow workFlow = new RequestReplyWorkflow();
    workFlow.setConsumer(consumer);
    workFlow.setProducer(producer);
    workFlow.setReplyProducer(replyProducer);
    channel.getWorkflowList().addWorkflow(workFlow);
    channel.prepare();
    return channel;
}
Also used : MockChannel(com.adaptris.core.stubs.MockChannel) MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) MockChannel(com.adaptris.core.stubs.MockChannel) MockMessageConsumer(com.adaptris.core.stubs.MockMessageConsumer) MockRequestReplyProducer(com.adaptris.core.stubs.MockRequestReplyProducer)

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