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");
}
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;
}
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);
}
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);
}
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);
}
Aggregations