Package org.springframework.util

Examples of org.springframework.util.StopWatch


    rbd.setScope(RootBeanDefinition.SCOPE_PROTOTYPE);
    rbd.getPropertyValues().addPropertyValue("spouse", new RuntimeBeanReference("spouse"));
    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();
    //System.out.println(sw.getTotalTimeMillis());
    assertTrue("Prototype creation took too long: " + sw.getTotalTimeMillis(), sw.getTotalTimeMillis() < 4000);
  }
View Full Code Here


  public OrderServiceClient(ListableBeanFactory beanFactory) {
    this.beanFactory = beanFactory;
  }

  public void invokeOrderServices(int orderId, int nrOfCalls) {
    StopWatch stopWatch = new StopWatch(nrOfCalls + " OrderService call(s)");
    Map orderServices = this.beanFactory.getBeansOfType(OrderService.class);
    for (Iterator it = orderServices.keySet().iterator(); it.hasNext();) {
      String beanName = (String) it.next();
      OrderService orderService = (OrderService) orderServices.get(beanName);
      System.out.println("Calling OrderService '" + beanName + "' with order ID " + orderId);
      stopWatch.start(beanName);
      Order order = null;
      for (int i = 0; i < nrOfCalls; i++) {
        order = orderService.getOrder(orderId);
      }
      stopWatch.stop();
      if (order != null) {
        printOrder(order);
      }
      else {
        System.out.println("Order with ID " + orderId + " not found");
      }
      System.out.println();
    }
    System.out.println(stopWatch.prettyPrint());
  }
View Full Code Here

   * usage of CGLIB. If we create too many classes with
   * CGLIB this will be slow or will run out of memory.
   */
  public void testManyProxies() {
    int howMany = 10000;
    StopWatch sw = new StopWatch();
    sw.start("Create " + howMany + " proxies");
    testManyProxies(howMany);
    sw.stop();
    System.out.println(sw.getTotalTimeMillis());
    assertTrue("Proxy creation was too slow",  sw.getTotalTimeMillis() < 5000);
  }
View Full Code Here

  }

  private long testRepeatedAroundAdviceInvocations(String file, int howmany, String technology) {
    ClassPathXmlApplicationContext bf = new ClassPathXmlApplicationContext(file);

    StopWatch sw = new StopWatch();
    sw.start(howmany + " repeated around advice invocations with " + technology);
    ITestBean adrian = (ITestBean) bf.getBean("adrian");
   
    assertTrue(AopUtils.isAopProxy(adrian));
    assertEquals(68, adrian.getAge());
   
    for (int i = 0; i < howmany; i++) {
      adrian.getAge();
    }
   
    sw.stop();
    System.out.println(sw.prettyPrint());
    return sw.getLastTaskTimeMillis();
  }
View Full Code Here

  }
 
  private long testBeforeAdviceWithoutJoinPoint(String file, int howmany, String technology) {
    ClassPathXmlApplicationContext bf = new ClassPathXmlApplicationContext(file);

    StopWatch sw = new StopWatch();
    sw.start(howmany + " repeated before advice invocations with " + technology);
    ITestBean adrian = (ITestBean) bf.getBean("adrian");
   
    assertTrue(AopUtils.isAopProxy(adrian));
    Advised a = (Advised) adrian;
    assertTrue(a.getAdvisors().length >= 3);
    assertEquals("adrian", adrian.getName());
   
    for (int i = 0; i < howmany; i++) {
      adrian.getName();
    }
   
    sw.stop();
    System.out.println(sw.prettyPrint());
    return sw.getLastTaskTimeMillis();
  }
View Full Code Here

  }
 
  private long testAfterReturningAdviceWithoutJoinPoint(String file, int howmany, String technology) {
    ClassPathXmlApplicationContext bf = new ClassPathXmlApplicationContext(file);

    StopWatch sw = new StopWatch();
    sw.start(howmany + " repeated after returning advice invocations with " + technology);
    ITestBean adrian = (ITestBean) bf.getBean("adrian");
   
    assertTrue(AopUtils.isAopProxy(adrian));
    Advised a = (Advised) adrian;
    assertTrue(a.getAdvisors().length >= 3);
    // 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();
  }
View Full Code Here

  }
 
  private long testMix(String file, int howmany, String technology) {
    ClassPathXmlApplicationContext bf = new ClassPathXmlApplicationContext(file);

    StopWatch sw = new StopWatch();
    sw.start(howmany + " repeated mixed invocations with " + technology);
    ITestBean adrian = (ITestBean) bf.getBean("adrian");
   
    assertTrue(AopUtils.isAopProxy(adrian));
    Advised a = (Advised) adrian;
    assertTrue(a.getAdvisors().length >= 3);
   
    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();
  }
View Full Code Here

      // Skip this test: Trace logging blows the time limit.
      return;
    }
    ClassPathXmlApplicationContext ac = new ClassPathXmlApplicationContext(
        "/org/springframework/aop/aspectj/autoproxy/aspectsPlusAdvisor.xml");
    StopWatch sw = new StopWatch();
    sw.start("prototype");
    for (int i = 0; i < 100000; i++) {
      INestedTestBean shouldNotBeWeaved = (INestedTestBean) ac.getBean("i21");
      if (i < 10) {
        assertFalse(AopUtils.isAopProxy(shouldNotBeWeaved));
      }
    }
    sw.stop();
    System.out.println(sw.getTotalTimeMillis());
    assertTrue("Prototype creation took too long: " + sw.getTotalTimeMillis(), sw.getTotalTimeMillis() < 3000);
  }
View Full Code Here

    new XmlBeanDefinitionReader(ac).loadBeanDefinitions(
        "/org/springframework/aop/aspectj/autoproxy/aspectsPlusAdvisor.xml");
    for (int i = 0; i < 10000; i++) {
      ac.registerBeanDefinition("singleton" + i, new RootBeanDefinition(NestedTestBean.class));
    }
    StopWatch sw = new StopWatch();
    sw.start("singleton");
    ac.refresh();
    sw.stop();
    System.out.println(sw.getTotalTimeMillis());
    assertTrue("Singleton creation took too long: " + sw.getTotalTimeMillis(), sw.getTotalTimeMillis() < 4000);
  }
View Full Code Here

  public static interface Counter {
    int getCount();
  }
 
  protected long 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());
        return sw.getLastTaskTimeMillis();
    }
View Full Code Here

TOP

Related Classes of org.springframework.util.StopWatch

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.