List of usage examples for org.springframework.util StopWatch stop
public void stop() throws IllegalStateException
From source file:org.springframework.beans.factory.DefaultListableBeanFactoryTests.java
@Test public void testPrototypeCreationWithDependencyCheckIsFastEnough() { Assume.group(TestGroup.PERFORMANCE); Assume.notLogging(factoryLog);// w ww .ja va 2 s .c o m DefaultListableBeanFactory lbf = new DefaultListableBeanFactory(); RootBeanDefinition rbd = new RootBeanDefinition(LifecycleBean.class); rbd.setScope(RootBeanDefinition.SCOPE_PROTOTYPE); rbd.setDependencyCheck(RootBeanDefinition.DEPENDENCY_CHECK_OBJECTS); lbf.registerBeanDefinition("test", rbd); lbf.addBeanPostProcessor(new LifecycleBean.PostProcessor()); StopWatch sw = new StopWatch(); sw.start("prototype"); for (int i = 0; i < 100000; i++) { lbf.getBean("test"); } sw.stop(); // System.out.println(sw.getTotalTimeMillis()); assertTrue("Prototype creation took too long: " + sw.getTotalTimeMillis(), sw.getTotalTimeMillis() < 3000); }
From source file:org.springframework.beans.factory.DefaultListableBeanFactoryTests.java
/** * @Test/*from w ww. java 2 s . co m*/ * public void testPrototypeCreationIsFastEnough2() throws Exception { * if (factoryLog.isTraceEnabled() || factoryLog.isDebugEnabled()) { * // Skip this test: Trace logging blows the time limit. * return; * } * DefaultListableBeanFactory lbf = new DefaultListableBeanFactory(); * Method setBeanNameMethod = TestBean.class.getMethod("setBeanName", String.class); * Method setBeanFactoryMethod = TestBean.class.getMethod("setBeanFactory", BeanFactory.class); * StopWatch sw = new StopWatch(); * sw.start("prototype"); * for (int i = 0; i < 100000; i++) { * TestBean tb = TestBean.class.newInstance(); * setBeanNameMethod.invoke(tb, "test"); * setBeanFactoryMethod.invoke(tb, lbf); * } * sw.stop(); * // System.out.println(sw.getTotalTimeMillis()); * assertTrue("Prototype creation took too long: " + sw.getTotalTimeMillis(), sw.getTotalTimeMillis() < 500); * } */ @Test @Ignore // TODO re-enable when ConstructorResolver TODO sorted out public void testPrototypeCreationWithConstructorArgumentsIsFastEnough() { Assume.group(TestGroup.PERFORMANCE); Assume.notLogging(factoryLog); DefaultListableBeanFactory lbf = new DefaultListableBeanFactory(); RootBeanDefinition rbd = new RootBeanDefinition(TestBean.class); rbd.setScope(RootBeanDefinition.SCOPE_PROTOTYPE); rbd.getConstructorArgumentValues().addGenericArgumentValue("juergen"); rbd.getConstructorArgumentValues().addGenericArgumentValue("99"); lbf.registerBeanDefinition("test", rbd); StopWatch sw = new StopWatch(); sw.start("prototype"); for (int i = 0; i < 100000; i++) { TestBean tb = (TestBean) lbf.getBean("test"); assertEquals("juergen", tb.getName()); assertEquals(99, tb.getAge()); } sw.stop(); // System.out.println(sw.getTotalTimeMillis()); assertTrue("Prototype creation took too long: " + sw.getTotalTimeMillis(), sw.getTotalTimeMillis() < 3000); }
From source file:org.springframework.beans.factory.DefaultListableBeanFactoryTests.java
@Test public void testPrototypeCreationWithResolvedConstructorArgumentsIsFastEnough() { Assume.group(TestGroup.PERFORMANCE); Assume.notLogging(factoryLog);//www . j av a 2s .c o m DefaultListableBeanFactory lbf = new DefaultListableBeanFactory(); RootBeanDefinition rbd = new RootBeanDefinition(TestBean.class); rbd.setScope(RootBeanDefinition.SCOPE_PROTOTYPE); rbd.getConstructorArgumentValues().addGenericArgumentValue(new RuntimeBeanReference("spouse")); lbf.registerBeanDefinition("test", rbd); lbf.registerBeanDefinition("spouse", new RootBeanDefinition(TestBean.class)); TestBean spouse = (TestBean) lbf.getBean("spouse"); StopWatch sw = new StopWatch(); sw.start("prototype"); for (int i = 0; i < 100000; i++) { TestBean tb = (TestBean) lbf.getBean("test"); assertSame(spouse, tb.getSpouse()); } sw.stop(); // System.out.println(sw.getTotalTimeMillis()); assertTrue("Prototype creation took too long: " + sw.getTotalTimeMillis(), sw.getTotalTimeMillis() < 4000); }
From source file:org.springframework.beans.factory.DefaultListableBeanFactoryTests.java
@Test public void testPrototypeCreationWithPropertiesIsFastEnough() { Assume.group(TestGroup.PERFORMANCE); Assume.notLogging(factoryLog);//from w w w. ja v a 2 s . c om DefaultListableBeanFactory lbf = new DefaultListableBeanFactory(); RootBeanDefinition rbd = new RootBeanDefinition(TestBean.class); rbd.setScope(RootBeanDefinition.SCOPE_PROTOTYPE); rbd.getPropertyValues().add("name", "juergen"); rbd.getPropertyValues().add("age", "99"); lbf.registerBeanDefinition("test", rbd); StopWatch sw = new StopWatch(); sw.start("prototype"); for (int i = 0; i < 100000; i++) { TestBean tb = (TestBean) lbf.getBean("test"); assertEquals("juergen", tb.getName()); assertEquals(99, tb.getAge()); } sw.stop(); // System.out.println(sw.getTotalTimeMillis()); assertTrue("Prototype creation took too long: " + sw.getTotalTimeMillis(), sw.getTotalTimeMillis() < 3000); }
From source file:org.springframework.beans.factory.DefaultListableBeanFactoryTests.java
@Test public void testPrototypeCreationWithResolvedPropertiesIsFastEnough() { Assume.group(TestGroup.PERFORMANCE); Assume.notLogging(factoryLog);/*from ww w . j a va2 s. c o m*/ DefaultListableBeanFactory lbf = new DefaultListableBeanFactory(); RootBeanDefinition rbd = new RootBeanDefinition(TestBean.class); rbd.setScope(RootBeanDefinition.SCOPE_PROTOTYPE); rbd.getPropertyValues().add("spouse", new RuntimeBeanReference("spouse")); lbf.registerBeanDefinition("test", rbd); lbf.registerBeanDefinition("spouse", new RootBeanDefinition(TestBean.class)); TestBean spouse = (TestBean) lbf.getBean("spouse"); StopWatch sw = new StopWatch(); sw.start("prototype"); for (int i = 0; i < 100000; i++) { TestBean tb = (TestBean) lbf.getBean("test"); assertSame(spouse, tb.getSpouse()); } sw.stop(); // System.out.println(sw.getTotalTimeMillis()); assertTrue("Prototype creation took too long: " + sw.getTotalTimeMillis(), sw.getTotalTimeMillis() < 4000); }
From source file:org.springframework.beans.factory.xml.XmlBeanFactoryTests.java
@Test public void lookupOverrideMethodsWithSetterInjection() { DefaultListableBeanFactory xbf = new DefaultListableBeanFactory(); XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(xbf); reader.loadBeanDefinitions(OVERRIDES_CONTEXT); lookupOverrideMethodsWithSetterInjection(xbf, "overrideOneMethod", true); // Should work identically on subclass definition, in which lookup // methods are inherited lookupOverrideMethodsWithSetterInjection(xbf, "overrideInheritedMethod", true); // Check cost of repeated construction of beans with method overrides // Will pick up misuse of CGLIB int howMany = 100; StopWatch sw = new StopWatch(); sw.start("Look up " + howMany + " prototype bean instances with method overrides"); for (int i = 0; i < howMany; i++) { lookupOverrideMethodsWithSetterInjection(xbf, "overrideOnPrototype", false); }/*from w w w . j a v a 2 s . c om*/ sw.stop(); // System.out.println(sw); if (!LogFactory.getLog(DefaultListableBeanFactory.class).isDebugEnabled()) { assertTrue(sw.getTotalTimeMillis() < 2000); } // Now test distinct bean with swapped value in factory, to ensure the two are independent OverrideOneMethod swappedOom = (OverrideOneMethod) xbf.getBean("overrideOneMethodSwappedReturnValues"); TestBean tb = swappedOom.getPrototypeDependency(); assertEquals("David", tb.getName()); tb = swappedOom.protectedOverrideSingleton(); assertEquals("Jenny", tb.getName()); }
From source file:org.springframework.boot.actuate.autoconfigure.MetricsFilter.java
@Override protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws ServletException, IOException { StopWatch stopWatch = createStopWatchIfNecessary(request); String path = new UrlPathHelper().getPathWithinApplication(request); int status = HttpStatus.INTERNAL_SERVER_ERROR.value(); try {//from w w w . j av a 2s . c om chain.doFilter(request, response); status = getStatus(response); } finally { if (!request.isAsyncStarted()) { stopWatch.stop(); request.removeAttribute(ATTRIBUTE_STOP_WATCH); recordMetrics(request, path, status, stopWatch.getTotalTimeMillis()); } } }
From source file:org.springframework.boot.actuate.metrics.web.servlet.MetricsFilter.java
@Override protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws ServletException, IOException { StopWatch stopWatch = createStopWatchIfNecessary(request); String path = new UrlPathHelper().getPathWithinApplication(request); int status = HttpStatus.INTERNAL_SERVER_ERROR.value(); try {//from ww w. j av a 2s .co m chain.doFilter(request, response); status = getStatus(response); } finally { if (!request.isAsyncStarted()) { if (response.isCommitted()) { status = getStatus(response); } stopWatch.stop(); request.removeAttribute(ATTRIBUTE_STOP_WATCH); recordMetrics(request, path, status, stopWatch.getTotalTimeMillis()); } } }
From source file:org.springframework.boot.SpringApplication.java
/** * Run the Spring application, creating and refreshing a new * {@link ApplicationContext}.//from ww w .j av a 2s . c om * @param args the application arguments (usually passed from a Java main method) * @return a running {@link ApplicationContext} */ public ConfigurableApplicationContext run(String... args) { StopWatch stopWatch = new StopWatch(); stopWatch.start(); ConfigurableApplicationContext context = null; configureHeadlessProperty(); SpringApplicationRunListeners listeners = getRunListeners(args); listeners.started(); try { context = doRun(listeners, args); stopWatch.stop(); if (this.logStartupInfo) { new StartupInfoLogger(this.mainApplicationClass).logStarted(getApplicationLog(), stopWatch); } return context; } catch (Throwable ex) { try { listeners.finished(context, ex); this.log.error("Application startup failed", ex); } finally { if (context != null) { context.close(); } } ReflectionUtils.rethrowRuntimeException(ex); return context; } }
From source file:org.springframework.context.annotation.AnnotationProcessorPerformanceTests.java
@Test public void testPrototypeCreationWithResourcePropertiesIsFastEnough() { GenericApplicationContext ctx = new GenericApplicationContext(); AnnotationConfigUtils.registerAnnotationConfigProcessors(ctx); ctx.refresh();//from ww w.ja v a2 s . co m RootBeanDefinition rbd = new RootBeanDefinition(ResourceAnnotatedTestBean.class); rbd.setScope(RootBeanDefinition.SCOPE_PROTOTYPE); ctx.registerBeanDefinition("test", rbd); ctx.registerBeanDefinition("spouse", new RootBeanDefinition(TestBean.class)); TestBean spouse = (TestBean) ctx.getBean("spouse"); StopWatch sw = new StopWatch(); sw.start("prototype"); for (int i = 0; i < 100000; i++) { TestBean tb = (TestBean) ctx.getBean("test"); assertSame(spouse, tb.getSpouse()); } sw.stop(); assertTrue("Prototype creation took too long: " + sw.getTotalTimeMillis(), sw.getTotalTimeMillis() < 4000); }