use of cn.taketoday.util.StopWatch in project today-framework by TAKETODAY.
the class XmlBeanFactoryTests method lookupOverrideMethodsWithSetterInjection.
@Test
void lookupOverrideMethodsWithSetterInjection() {
StandardBeanFactory xbf = new StandardBeanFactory();
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 (!LoggerFactory.getLogger(StandardBeanFactory.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 cn.taketoday.util.StopWatch in project today-framework by TAKETODAY.
the class CustomizableTraceInterceptor method invokeUnderTrace.
/**
* Writes a log message before the invocation based on the value of {@code enterMessage}.
* If the invocation succeeds, then a log message is written on exit based on the value
* {@code exitMessage}. If an exception occurs during invocation, then a message is
* written based on the value of {@code exceptionMessage}.
*
* @see #setEnterMessage
* @see #setExitMessage
* @see #setExceptionMessage
*/
@Override
protected Object invokeUnderTrace(MethodInvocation invocation, Logger logger) throws Throwable {
String name = ClassUtils.getQualifiedMethodName(invocation.getMethod());
StopWatch stopWatch = new StopWatch(name);
Object returnValue = null;
boolean exitThroughException = false;
try {
stopWatch.start(name);
writeToLog(logger, replacePlaceholders(this.enterMessage, invocation, null, null, -1));
returnValue = invocation.proceed();
return returnValue;
} catch (Throwable ex) {
if (stopWatch.isRunning()) {
stopWatch.stop();
}
exitThroughException = true;
writeToLog(logger, replacePlaceholders(this.exceptionMessage, invocation, null, ex, stopWatch.getTotalTimeMillis()), ex);
throw ex;
} finally {
if (!exitThroughException) {
if (stopWatch.isRunning()) {
stopWatch.stop();
}
writeToLog(logger, replacePlaceholders(this.exitMessage, invocation, returnValue, null, stopWatch.getTotalTimeMillis()));
}
}
}
use of cn.taketoday.util.StopWatch in project today-infrastructure by TAKETODAY.
the class TraceBeforeAdvice method testRepeatedAroundAdviceInvocations.
private long testRepeatedAroundAdviceInvocations(String file, int howmany, String technology) {
ClassPathXmlApplicationContext bf = new ClassPathXmlApplicationContext(file, CLASS);
StopWatch sw = new StopWatch();
sw.start(howmany + " repeated around advice invocations with " + technology);
ITestBean adrian = (ITestBean) bf.getBean("adrian");
assertThat(AopUtils.isAopProxy(adrian)).isTrue();
assertThat(adrian.getAge()).isEqualTo(68);
for (int i = 0; i < howmany; i++) {
adrian.getAge();
}
sw.stop();
System.out.println(sw.prettyPrint());
return sw.getLastTaskTimeMillis();
}
use of cn.taketoday.util.StopWatch in project today-infrastructure by TAKETODAY.
the class TraceBeforeAdvice method testAfterReturningAdviceWithoutJoinPoint.
private long testAfterReturningAdviceWithoutJoinPoint(String file, int howmany, String technology) {
ClassPathXmlApplicationContext bf = new ClassPathXmlApplicationContext(file, CLASS);
StopWatch sw = new StopWatch();
sw.start(howmany + " repeated after returning advice invocations with " + technology);
ITestBean adrian = (ITestBean) bf.getBean("adrian");
assertThat(AopUtils.isAopProxy(adrian)).isTrue();
Advised a = (Advised) adrian;
assertThat(a.getAdvisors().length >= 3).isTrue();
// Hits joinpoint
adrian.setAge(25);
for (int i = 0; i < howmany; i++) {
adrian.setAge(i);
}
sw.stop();
System.out.println(sw.prettyPrint());
return sw.getLastTaskTimeMillis();
}
use of cn.taketoday.util.StopWatch in project today-infrastructure by TAKETODAY.
the class TraceBeforeAdvice method testMix.
private long testMix(String file, int howmany, String technology) {
ClassPathXmlApplicationContext bf = new ClassPathXmlApplicationContext(file, CLASS);
StopWatch sw = new StopWatch();
sw.start(howmany + " repeated mixed invocations with " + technology);
ITestBean adrian = (ITestBean) bf.getBean("adrian");
assertThat(AopUtils.isAopProxy(adrian)).isTrue();
Advised a = (Advised) adrian;
assertThat(a.getAdvisors().length >= 3).isTrue();
for (int i = 0; i < howmany; i++) {
// Hit all 3 joinpoints
adrian.getAge();
adrian.getName();
adrian.setAge(i);
// Invoke three non-advised methods
adrian.getDoctor();
adrian.getLawyer();
adrian.getSpouse();
}
sw.stop();
System.out.println(sw.prettyPrint());
return sw.getLastTaskTimeMillis();
}
Aggregations