1 20 package org.apache.mina.integration.spring; 21 22 import junit.framework.TestCase; 23 24 import org.apache.mina.common.ExecutorThreadModel; 25 26 import java.util.concurrent.Executor ; 27 import java.util.concurrent.SynchronousQueue ; 28 import java.util.concurrent.ThreadPoolExecutor ; 29 import java.util.concurrent.TimeUnit ; 30 31 37 public class ExecutorThreadModelFactoryBeanTest extends TestCase { 38 public void testSuccessfulCreationWithExecutor() throws Exception { 39 Executor executor = new ThreadPoolExecutor (1, 10, 3600, 40 TimeUnit.SECONDS, new SynchronousQueue <Runnable >()); 41 ExecutorThreadModelFactoryBean factory = new ExecutorThreadModelFactoryBean(); 42 factory.setServiceName("foo"); 43 factory.setExecutor(executor); 44 factory.afterPropertiesSet(); 45 ExecutorThreadModel threadModel = (ExecutorThreadModel) factory 46 .getObject(); 47 assertSame(executor, threadModel.getExecutor()); 48 } 49 50 public void testSuccessfulCreationWithoutExecutor() throws Exception { 51 ExecutorThreadModelFactoryBean factory = new ExecutorThreadModelFactoryBean(); 52 factory.setServiceName("foo"); 53 factory.afterPropertiesSet(); 54 ExecutorThreadModel threadModel = (ExecutorThreadModel) factory 55 .getObject(); 56 assertTrue(threadModel.getExecutor() instanceof ThreadPoolExecutor ); 57 } 58 59 public void testUnsuccessfulCreation() throws Exception { 60 ExecutorThreadModelFactoryBean factory = new ExecutorThreadModelFactoryBean(); 61 try { 62 factory.afterPropertiesSet(); 63 fail("No serviceName set. IllegalArgumentException expected."); 64 } catch (IllegalArgumentException iae) { 65 } 66 } 67 } 68 | Popular Tags |