Search in sources :

Example 86 with TimeInterval

use of com.adaptris.util.TimeInterval 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 87 with TimeInterval

use of com.adaptris.util.TimeInterval in project interlok by adaptris.

the class PoolingWorkflowTest method testSetThreadLifetime.

@Test
public void testSetThreadLifetime() throws Exception {
    PoolingWorkflow workflow = new PoolingWorkflow();
    TimeInterval defaultInterval = new TimeInterval(60L, TimeUnit.SECONDS.name());
    assertNull(workflow.getThreadKeepAlive());
    assertEquals(defaultInterval.toMilliseconds(), workflow.threadLifetimeMs());
    TimeInterval interval = new TimeInterval(200L, TimeUnit.MILLISECONDS.name());
    workflow.setThreadKeepAlive(interval);
    assertEquals(interval, workflow.getThreadKeepAlive());
    assertNotSame(defaultInterval.toMilliseconds(), workflow.threadLifetimeMs());
    assertEquals(interval.toMilliseconds(), workflow.threadLifetimeMs());
    workflow.setThreadKeepAlive(null);
    assertNull(workflow.getThreadKeepAlive());
    assertEquals(defaultInterval.toMilliseconds(), workflow.threadLifetimeMs());
}
Also used : TimeInterval(com.adaptris.util.TimeInterval) Test(org.junit.Test)

Example 88 with TimeInterval

use of com.adaptris.util.TimeInterval 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 89 with TimeInterval

use of com.adaptris.util.TimeInterval 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 90 with TimeInterval

use of com.adaptris.util.TimeInterval 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)

Aggregations

TimeInterval (com.adaptris.util.TimeInterval)310 Test (org.junit.Test)249 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)86 StandaloneConsumer (com.adaptris.core.StandaloneConsumer)49 MockMessageListener (com.adaptris.core.stubs.MockMessageListener)42 MockMessageProducer (com.adaptris.core.stubs.MockMessageProducer)40 FixedIntervalPoller (com.adaptris.core.FixedIntervalPoller)38 Channel (com.adaptris.core.Channel)36 MockChannel (com.adaptris.core.stubs.MockChannel)32 File (java.io.File)28 StandardWorkflow (com.adaptris.core.StandardWorkflow)27 Adapter (com.adaptris.core.Adapter)26 GuidGenerator (com.adaptris.util.GuidGenerator)25 FilenameFilter (java.io.FilenameFilter)24 Perl5FilenameFilter (org.apache.oro.io.Perl5FilenameFilter)24 StandaloneProducer (com.adaptris.core.StandaloneProducer)23 CoreException (com.adaptris.core.CoreException)22 WaitService (com.adaptris.core.services.WaitService)22 RandomAccessFile (java.io.RandomAccessFile)21 ObjectName (javax.management.ObjectName)21