Search in sources :

Example 56 with StopWatch

use of org.springframework.util.StopWatch in project spring-framework by spring-projects.

the class XmlBeanFactoryTests method lookupOverrideMethodsWithSetterInjection.

@Test
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);
    }
    sw.stop();
    // System.out.println(sw);
    if (!LogFactory.getLog(DefaultListableBeanFactory.class).isDebugEnabled()) {
        assertThat(sw.getTotalTimeMillis() < 2000).isTrue();
    }
    // 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();
    assertThat(tb.getName()).isEqualTo("David");
    tb = swappedOom.protectedOverrideSingleton();
    assertThat(tb.getName()).isEqualTo("Jenny");
}
Also used : DerivedTestBean(org.springframework.beans.testfixture.beans.DerivedTestBean) TestBean(org.springframework.beans.testfixture.beans.TestBean) IndexedTestBean(org.springframework.beans.testfixture.beans.IndexedTestBean) ITestBean(org.springframework.beans.testfixture.beans.ITestBean) ResourceTestBean(org.springframework.tests.sample.beans.ResourceTestBean) DefaultListableBeanFactory(org.springframework.beans.factory.support.DefaultListableBeanFactory) StopWatch(org.springframework.util.StopWatch) Test(org.junit.jupiter.api.Test)

Example 57 with StopWatch

use of org.springframework.util.StopWatch in project weixin-java-pay-demo by binarywang.

the class SwaggerConfig method docket.

@Bean
public Docket docket() {
    // 最重要的就是这里,定义了/test/.*开头的rest接口都分在了test分组里,可以通过/v2/api-docs?group=test得到定义的json
    log.info("Starting Swagger");
    StopWatch watch = new StopWatch();
    watch.start();
    Docket docket = new Docket(DocumentationType.SWAGGER_2).groupName("pay").apiInfo(this.apiInfo()).select().apis(RequestHandlerSelectors.any()).paths(regex("/pay/.*")).build();
    watch.stop();
    log.info("Started Swagger in {} ms", watch.getTotalTimeMillis());
    return docket;
}
Also used : Docket(springfox.documentation.spring.web.plugins.Docket) StopWatch(org.springframework.util.StopWatch) Bean(org.springframework.context.annotation.Bean)

Example 58 with StopWatch

use of org.springframework.util.StopWatch in project spring-framework by spring-projects.

the class TestBeanAdvisor method testAspectsAndAdvisorNotAppliedToManySingletonsIsFastEnough.

@Test
public void testAspectsAndAdvisorNotAppliedToManySingletonsIsFastEnough() {
    Assume.group(TestGroup.PERFORMANCE);
    Assume.notLogging(factoryLog);
    GenericApplicationContext ac = new GenericApplicationContext();
    new XmlBeanDefinitionReader(ac).loadBeanDefinitions(new ClassPathResource(qName("aspectsPlusAdvisor.xml"), getClass()));
    for (int i = 0; i < 10000; i++) {
        ac.registerBeanDefinition("singleton" + i, new RootBeanDefinition(NestedTestBean.class));
    }
    StopWatch sw = new StopWatch();
    sw.start("Singleton Creation");
    ac.refresh();
    sw.stop();
    // What's a reasonable expectation for _any_ server or developer machine load?
    // 8 seconds?
    assertStopWatchTimeLimit(sw, 8000);
}
Also used : GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) XmlBeanDefinitionReader(org.springframework.beans.factory.xml.XmlBeanDefinitionReader) INestedTestBean(org.springframework.tests.sample.beans.INestedTestBean) NestedTestBean(org.springframework.tests.sample.beans.NestedTestBean) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) ClassPathResource(org.springframework.core.io.ClassPathResource) JoinPoint(org.aspectj.lang.JoinPoint) ProceedingJoinPoint(org.aspectj.lang.ProceedingJoinPoint) StopWatch(org.springframework.util.StopWatch) Test(org.junit.Test)

Example 59 with StopWatch

use of org.springframework.util.StopWatch in project spring-framework by spring-projects.

the class AbstractAopProxyTests method testManyProxies.

/**
	 * This is primarily a test for the efficiency of our
	 * usage of CGLIB. If we create too many classes with
	 * CGLIB this will be slow or will run out of memory.
	 */
@Test
public void testManyProxies() {
    Assume.group(TestGroup.PERFORMANCE);
    int howMany = 10000;
    StopWatch sw = new StopWatch();
    sw.start("Create " + howMany + " proxies");
    testManyProxies(howMany);
    sw.stop();
    assertTrue("Proxy creation was too slow", sw.getTotalTimeMillis() < 5000);
}
Also used : StopWatch(org.springframework.util.StopWatch) Test(org.junit.Test)

Example 60 with StopWatch

use of org.springframework.util.StopWatch in project spring-framework by spring-projects.

the class TestBeanAdvisor method testAspectsAndAdvisorAppliedToPrototypeIsFastEnough.

@Test
public void testAspectsAndAdvisorAppliedToPrototypeIsFastEnough() {
    Assume.group(TestGroup.PERFORMANCE);
    Assume.notLogging(factoryLog);
    ClassPathXmlApplicationContext ac = newContext("aspectsPlusAdvisor.xml");
    StopWatch sw = new StopWatch();
    sw.start("Prototype Creation");
    for (int i = 0; i < 10000; i++) {
        ITestBean shouldBeWeaved = (ITestBean) ac.getBean("adrian2");
        if (i < 10) {
            doTestAspectsAndAdvisorAreApplied(ac, shouldBeWeaved);
        }
    }
    sw.stop();
    // What's a reasonable expectation for _any_ server or developer machine load?
    // 9 seconds?
    assertStopWatchTimeLimit(sw, 9000);
}
Also used : ITestBean(org.springframework.tests.sample.beans.ITestBean) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) JoinPoint(org.aspectj.lang.JoinPoint) ProceedingJoinPoint(org.aspectj.lang.ProceedingJoinPoint) StopWatch(org.springframework.util.StopWatch) Test(org.junit.Test)

Aggregations

StopWatch (org.springframework.util.StopWatch)112 Test (org.junit.Test)44 RootBeanDefinition (org.springframework.beans.factory.support.RootBeanDefinition)12 ArrayList (java.util.ArrayList)9 Test (org.junit.jupiter.api.Test)9 ITestBean (org.springframework.tests.sample.beans.ITestBean)9 TestBean (org.springframework.tests.sample.beans.TestBean)9 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)8 List (java.util.List)7 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)7 HashMap (java.util.HashMap)6 Map (java.util.Map)6 ITestBean (org.springframework.beans.testfixture.beans.ITestBean)6 MockHttpServletRequest (org.springframework.mock.web.test.MockHttpServletRequest)6 ApplicationMap (com.navercorp.pinpoint.web.applicationmap.ApplicationMap)5 Ignore (org.junit.Ignore)5 DefaultListableBeanFactory (org.springframework.beans.factory.support.DefaultListableBeanFactory)5 NestedTestBean (org.springframework.tests.sample.beans.NestedTestBean)5 Range (com.navercorp.pinpoint.web.vo.Range)4 Dataset (org.apache.jena.query.Dataset)4