use of java.util.concurrent.ThreadPoolExecutor in project camel by apache.
the class DefaultExecutorServiceManagerTest method testDefaultUnboundedQueueThreadPool.
public void testDefaultUnboundedQueueThreadPool() throws Exception {
ThreadPoolProfile custom = new ThreadPoolProfile("custom");
custom.setPoolSize(10);
custom.setMaxPoolSize(30);
custom.setKeepAliveTime(50L);
custom.setMaxQueueSize(Integer.MAX_VALUE);
context.getExecutorServiceManager().setDefaultThreadPoolProfile(custom);
assertEquals(true, custom.isDefaultProfile().booleanValue());
ExecutorService myPool = context.getExecutorServiceManager().newDefaultThreadPool(this, "myPool");
assertEquals(false, myPool.isShutdown());
// should use default settings
ThreadPoolExecutor executor = (ThreadPoolExecutor) myPool;
assertEquals(10, executor.getCorePoolSize());
assertEquals(30, executor.getMaximumPoolSize());
assertEquals(50, executor.getKeepAliveTime(TimeUnit.SECONDS));
assertEquals(Integer.MAX_VALUE, executor.getQueue().remainingCapacity());
context.stop();
assertEquals(true, myPool.isShutdown());
}
use of java.util.concurrent.ThreadPoolExecutor in project camel by apache.
the class DefaultExecutorServiceManagerTest method testGetThreadPoolProfileInheritCustomDefaultValues2.
public void testGetThreadPoolProfileInheritCustomDefaultValues2() throws Exception {
ThreadPoolProfile newDefault = new ThreadPoolProfile("newDefault");
// just change the max pool as the default profile should then inherit the old default profile
newDefault.setMaxPoolSize(50);
context.getExecutorServiceManager().setDefaultThreadPoolProfile(newDefault);
assertNull(context.getExecutorServiceManager().getThreadPoolProfile("foo"));
ThreadPoolProfile foo = new ThreadPoolProfile("foo");
foo.setPoolSize(1);
context.getExecutorServiceManager().registerThreadPoolProfile(foo);
assertSame(foo, context.getExecutorServiceManager().getThreadPoolProfile("foo"));
ExecutorService executor = context.getExecutorServiceManager().newThreadPool(this, "MyPool", "foo");
ThreadPoolExecutor tp = assertIsInstanceOf(ThreadPoolExecutor.class, executor);
assertEquals(1, tp.getCorePoolSize());
// should inherit the default values
assertEquals(50, tp.getMaximumPoolSize());
assertEquals(60, tp.getKeepAliveTime(TimeUnit.SECONDS));
assertEquals("CallerRuns", tp.getRejectedExecutionHandler().toString());
}
use of java.util.concurrent.ThreadPoolExecutor in project camel by apache.
the class DefaultExecutorServiceManagerTest method testCustomDefaultThreadPool.
public void testCustomDefaultThreadPool() throws Exception {
ThreadPoolProfile custom = new ThreadPoolProfile("custom");
custom.setKeepAliveTime(20L);
custom.setMaxPoolSize(40);
custom.setPoolSize(5);
custom.setMaxQueueSize(2000);
context.getExecutorServiceManager().setDefaultThreadPoolProfile(custom);
assertEquals(true, custom.isDefaultProfile().booleanValue());
ExecutorService myPool = context.getExecutorServiceManager().newDefaultThreadPool(this, "myPool");
assertEquals(false, myPool.isShutdown());
// should use default settings
ThreadPoolExecutor executor = (ThreadPoolExecutor) myPool;
assertEquals(5, executor.getCorePoolSize());
assertEquals(40, executor.getMaximumPoolSize());
assertEquals(20, executor.getKeepAliveTime(TimeUnit.SECONDS));
assertEquals(2000, executor.getQueue().remainingCapacity());
context.stop();
assertEquals(true, myPool.isShutdown());
}
use of java.util.concurrent.ThreadPoolExecutor in project camel by apache.
the class ThreadsRejectedExecutionTest method testThreadsRejectedExecution.
public void testThreadsRejectedExecution() throws Exception {
context.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
// use a custom pool which rejects any new tasks while currently in progress
// this should force the ThreadsProcessor to run the tasks itself
ExecutorService pool = new ThreadPoolExecutor(1, 1, 0, TimeUnit.SECONDS, new SynchronousQueue<Runnable>());
from("seda:start").to("log:before").threads().executorService(pool).delay(1000).to("log:after").to("mock:result");
}
});
context.start();
getMockEndpoint("mock:result").expectedMessageCount(3);
template.sendBody("seda:start", "Hello World");
template.sendBody("seda:start", "Hi World");
template.sendBody("seda:start", "Bye World");
assertMockEndpointsSatisfied();
}
use of java.util.concurrent.ThreadPoolExecutor in project camel by apache.
the class ThreadsRejectedExecutionTest method testThreadsRejectedExecutionCallerNotRuns.
public void testThreadsRejectedExecutionCallerNotRuns() throws Exception {
context.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
// use a custom pool which rejects any new tasks while currently in progress
// this should force the ThreadsProcessor to run the tasks itself
ExecutorService pool = new ThreadPoolExecutor(1, 1, 0, TimeUnit.SECONDS, new SynchronousQueue<Runnable>());
from("seda:start").to("log:before").threads().executorService(pool).callerRunsWhenRejected(false).delay(1000).to("log:after").to("mock:result");
}
});
context.start();
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedMessageCount(3);
// wait at most 5 seconds
mock.setResultWaitTime(5000);
template.sendBody("seda:start", "Hello World");
template.sendBody("seda:start", "Hi World");
template.sendBody("seda:start", "Bye World");
// should not be possible to route all 3
mock.assertIsNotSatisfied();
// only 1 should arrive
assertEquals(1, mock.getReceivedCounter());
}
Aggregations