Search in sources :

Example 6 with StopWatch

use of cn.taketoday.util.StopWatch in project today-framework 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();
}
Also used : ITestBean(cn.taketoday.beans.testfixture.beans.ITestBean) ClassPathXmlApplicationContext(cn.taketoday.context.support.ClassPathXmlApplicationContext) Advised(cn.taketoday.aop.framework.Advised) StopWatch(cn.taketoday.util.StopWatch)

Example 7 with StopWatch

use of cn.taketoday.util.StopWatch in project today-framework by TAKETODAY.

the class IntroductionBenchmarkTests method timeManyInvocations.

@Test
public void timeManyInvocations() {
    StopWatch sw = new StopWatch();
    TestBean target = new TestBean();
    ProxyFactory pf = new ProxyFactory(target);
    pf.setProxyTargetClass(false);
    pf.addAdvice(new SimpleCounterIntroduction());
    ITestBean proxy = (ITestBean) pf.getProxy();
    Counter counter = (Counter) proxy;
    sw.start(INVOCATIONS + " invocations on proxy, not hitting introduction");
    for (int i = 0; i < INVOCATIONS; i++) {
        proxy.getAge();
    }
    sw.stop();
    sw.start(INVOCATIONS + " invocations on proxy, hitting introduction");
    for (int i = 0; i < INVOCATIONS; i++) {
        counter.getCount();
    }
    sw.stop();
    sw.start(INVOCATIONS + " invocations on target");
    for (int i = 0; i < INVOCATIONS; i++) {
        target.getAge();
    }
    sw.stop();
    System.out.println(sw.prettyPrint());
}
Also used : ITestBean(cn.taketoday.beans.testfixture.beans.ITestBean) TestBean(cn.taketoday.beans.testfixture.beans.TestBean) ITestBean(cn.taketoday.beans.testfixture.beans.ITestBean) StopWatch(cn.taketoday.util.StopWatch) Test(org.junit.jupiter.api.Test)

Example 8 with StopWatch

use of cn.taketoday.util.StopWatch in project today-framework by TAKETODAY.

the class TraceBeforeAdvice method testBeforeAdviceWithoutJoinPoint.

private long testBeforeAdviceWithoutJoinPoint(String file, int howmany, String technology) {
    ClassPathXmlApplicationContext bf = new ClassPathXmlApplicationContext(file, CLASS);
    StopWatch sw = new StopWatch();
    sw.start(howmany + " repeated before 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();
    assertThat(adrian.getName()).isEqualTo("adrian");
    for (int i = 0; i < howmany; i++) {
        adrian.getName();
    }
    sw.stop();
    System.out.println(sw.prettyPrint());
    return sw.getLastTaskTimeMillis();
}
Also used : ITestBean(cn.taketoday.beans.testfixture.beans.ITestBean) ClassPathXmlApplicationContext(cn.taketoday.context.support.ClassPathXmlApplicationContext) Advised(cn.taketoday.aop.framework.Advised) StopWatch(cn.taketoday.util.StopWatch)

Example 9 with StopWatch

use of cn.taketoday.util.StopWatch in project today-framework 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();
}
Also used : ITestBean(cn.taketoday.beans.testfixture.beans.ITestBean) ClassPathXmlApplicationContext(cn.taketoday.context.support.ClassPathXmlApplicationContext) StopWatch(cn.taketoday.util.StopWatch)

Example 10 with StopWatch

use of cn.taketoday.util.StopWatch in project today-framework 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();
}
Also used : ITestBean(cn.taketoday.beans.testfixture.beans.ITestBean) ClassPathXmlApplicationContext(cn.taketoday.context.support.ClassPathXmlApplicationContext) Advised(cn.taketoday.aop.framework.Advised) StopWatch(cn.taketoday.util.StopWatch)

Aggregations

StopWatch (cn.taketoday.util.StopWatch)22 ITestBean (cn.taketoday.beans.testfixture.beans.ITestBean)12 ClassPathXmlApplicationContext (cn.taketoday.context.support.ClassPathXmlApplicationContext)8 Advised (cn.taketoday.aop.framework.Advised)6 TestBean (cn.taketoday.beans.testfixture.beans.TestBean)4 Test (org.junit.jupiter.api.Test)4 StandardBeanFactory (cn.taketoday.beans.factory.support.StandardBeanFactory)2 DerivedTestBean (cn.taketoday.beans.testfixture.beans.DerivedTestBean)2 IndexedTestBean (cn.taketoday.beans.testfixture.beans.IndexedTestBean)2 ResourceTestBean (cn.taketoday.tests.sample.beans.ResourceTestBean)2