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);
}
}
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());
}
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);
}
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);
}
}
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();
}
}
Aggregations