|
|||||
|
|||||
SpringTest.java
package tests.jfun.yan.benchmark; import junit.framework.TestCase; import org.springframework.beans.factory.xml.XmlBeanFactory; import org.springframework.core.io.ClassPathResource; import tests.jfun.yan.benchmark.models.Foo; import tests.jfun.yan.benchmark.models.Soo; public class SpringTest extends TestCase { private static final long LOOP = 200000; private XmlBeanFactory factory = null; protected void setUp() throws Exception { super.setUp(); ClassPathResource res = new ClassPathResource("/tests/jfun/yan/benchmark/spring_component_config.xml"); factory = new XmlBeanFactory(res); assertNotNull(factory); Thread.sleep(100); System.gc(); Thread.sleep(100); System.gc(); Thread.sleep(100); } protected void tearDown() throws Exception { super.tearDown(); } public void testBenchCreateComponentInstance() throws Exception{ new Benchmark("Spring: Create bean without injection", LOOP){ public void run() throws Exception { factory.getBean("bar"); } }.start(true); Soo soo = (Soo)factory.getBean("soo"); assertNotNull(soo.getBar()); } public void testBenchConstructorInjection() throws Exception{ new Benchmark("Spring: Create bean with Constructor Dependency Injection", LOOP){ public void run() throws Exception { factory.getBean("foo"); } }.start(true); Foo foo = (Foo)factory.getBean("foo"); assertNotNull(foo.getBar()); } public void testBenchSetterInjectio() throws Exception{ new Benchmark("Spring: Create bean with Setter Dependency Injection", LOOP){ public void run() throws Exception { factory.getBean("soo"); } }.start(true); Soo soo = (Soo)factory.getBean("soo"); assertNotNull(soo.getBar()); } public void testBenchAutowiredSetterInjection() throws Exception{ new Benchmark("Spring: Create bean with bytype autowiring and Setter Dependency Injection", LOOP){ public void run() throws Exception { factory.getBean("auto_soo"); } }.start(true); Soo soo = (Soo)factory.getBean("auto_soo"); assertNotNull(soo.getBar()); } public void testBenchSingleton() throws Exception{ new Benchmark("Spring: Create singleton bean with Setter Dependency Injection", LOOP*10){ public void run() throws Exception { factory.getBean("ssoo"); } }.start(true); Soo soo = (Soo)factory.getBean("ssoo"); assertNotNull(soo.getBar()); } public void testBenchEmptyInterceptor() throws Exception{ Benchmark bench = new Benchmark("Spring: Bean method invocation with empty interceptor applied", LOOP * 100){ Soo soo = (Soo)factory.getBean("sooProxy"); public void run() throws Exception { soo.noop(); } }; bench.start(true); } public void testBenchCreateAsectizedBean() throws Exception{ new Benchmark("Spring: Create aspectized bean", LOOP/10 ){ public void run() throws Exception { factory.getBean("sooProxy"); } }.start(true); } } |
|||||
|
Copyright 2003-2006 - The Codehaus. All rights reserved unless otherwise noted.
Powered by Atlassian Confluence
|
|||||