use of java.util.concurrent.ThreadPoolExecutor in project camel by apache.
the class DefaultExecutorServiceStrategyTest method testNewThreadPoolProfile.
public void testNewThreadPoolProfile() throws Exception {
assertNull(context.getExecutorServiceStrategy().getThreadPoolProfile("foo"));
ThreadPoolProfileSupport foo = new ThreadPoolProfileSupport("foo");
foo.setKeepAliveTime(20L);
foo.setMaxPoolSize(40);
foo.setPoolSize(5);
foo.setMaxQueueSize(2000);
context.getExecutorServiceStrategy().registerThreadPoolProfile(foo);
ExecutorService pool = context.getExecutorServiceStrategy().newThreadPool(this, "Cool", "foo");
assertNotNull(pool);
ThreadPoolExecutor tp = assertIsInstanceOf(ThreadPoolExecutor.class, pool);
assertEquals(20, tp.getKeepAliveTime(TimeUnit.SECONDS));
assertEquals(40, tp.getMaximumPoolSize());
assertEquals(5, tp.getCorePoolSize());
assertFalse(tp.isShutdown());
context.stop();
assertTrue(tp.isShutdown());
}
use of java.util.concurrent.ThreadPoolExecutor in project camel by apache.
the class DefaultExecutorServiceManagerTest method testNewSingleThreadExecutor.
public void testNewSingleThreadExecutor() throws Exception {
ExecutorService pool = context.getExecutorServiceManager().newSingleThreadExecutor(this, "Cool");
assertNotNull(pool);
ThreadPoolExecutor tp = assertIsInstanceOf(ThreadPoolExecutor.class, pool);
// a single dont use keep alive
assertEquals("keepAliveTime", 0, tp.getKeepAliveTime(TimeUnit.SECONDS));
assertEquals("maximumPoolSize", 1, tp.getMaximumPoolSize());
assertEquals(1, tp.getCorePoolSize());
assertFalse(tp.isShutdown());
context.stop();
assertTrue(tp.isShutdown());
}
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());
}
Aggregations