Search in sources :

Example 11 with StopWatch

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

the class DefaultListableBeanFactoryTests method testPrototypeCreationWithResolvedPropertiesIsFastEnough.

@Test
public void testPrototypeCreationWithResolvedPropertiesIsFastEnough() {
    Assume.group(TestGroup.PERFORMANCE);
    Assume.notLogging(factoryLog);
    DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
    RootBeanDefinition rbd = new RootBeanDefinition(TestBean.class);
    rbd.setScope(RootBeanDefinition.SCOPE_PROTOTYPE);
    rbd.getPropertyValues().add("spouse", new RuntimeBeanReference("spouse"));
    lbf.registerBeanDefinition("test", rbd);
    lbf.registerBeanDefinition("spouse", new RootBeanDefinition(TestBean.class));
    TestBean spouse = (TestBean) lbf.getBean("spouse");
    StopWatch sw = new StopWatch();
    sw.start("prototype");
    for (int i = 0; i < 100000; i++) {
        TestBean tb = (TestBean) lbf.getBean("test");
        assertSame(spouse, tb.getSpouse());
    }
    sw.stop();
    // System.out.println(sw.getTotalTimeMillis());
    assertTrue("Prototype creation took too long: " + sw.getTotalTimeMillis(), sw.getTotalTimeMillis() < 4000);
}
Also used : ITestBean(org.springframework.tests.sample.beans.ITestBean) DerivedTestBean(org.springframework.tests.sample.beans.DerivedTestBean) TestBean(org.springframework.tests.sample.beans.TestBean) NestedTestBean(org.springframework.tests.sample.beans.NestedTestBean) DefaultListableBeanFactory(org.springframework.beans.factory.support.DefaultListableBeanFactory) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) RuntimeBeanReference(org.springframework.beans.factory.config.RuntimeBeanReference) StopWatch(org.springframework.util.StopWatch) Test(org.junit.Test)

Example 12 with StopWatch

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

the class TestBeanAdvisor method testAspectsAndAdvisorNotAppliedToPrototypeIsFastEnough.

@Test
public void testAspectsAndAdvisorNotAppliedToPrototypeIsFastEnough() {
    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 < 100000; i++) {
        INestedTestBean shouldNotBeWeaved = (INestedTestBean) ac.getBean("i21");
        if (i < 10) {
            assertFalse(AopUtils.isAopProxy(shouldNotBeWeaved));
        }
    }
    sw.stop();
    // What's a reasonable expectation for _any_ server or developer machine load?
    // 3 seconds?
    assertStopWatchTimeLimit(sw, 6000);
}
Also used : INestedTestBean(org.springframework.tests.sample.beans.INestedTestBean) 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)

Example 13 with StopWatch

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

the class ApplicationContextExpressionTests method prototypeCreationIsFastEnough.

@Test
public void prototypeCreationIsFastEnough() {
    Assume.group(TestGroup.PERFORMANCE);
    Assume.notLogging(factoryLog);
    GenericApplicationContext ac = new GenericApplicationContext();
    RootBeanDefinition rbd = new RootBeanDefinition(TestBean.class);
    rbd.setScope(RootBeanDefinition.SCOPE_PROTOTYPE);
    rbd.getConstructorArgumentValues().addGenericArgumentValue("#{systemProperties.name}");
    rbd.getPropertyValues().add("country", "#{systemProperties.country}");
    ac.registerBeanDefinition("test", rbd);
    ac.refresh();
    StopWatch sw = new StopWatch();
    sw.start("prototype");
    System.getProperties().put("name", "juergen");
    System.getProperties().put("country", "UK");
    try {
        for (int i = 0; i < 100000; i++) {
            TestBean tb = (TestBean) ac.getBean("test");
            assertEquals("juergen", tb.getName());
            assertEquals("UK", tb.getCountry());
        }
        sw.stop();
    } finally {
        System.getProperties().remove("country");
        System.getProperties().remove("name");
    }
    assertTrue("Prototype creation took too long: " + sw.getTotalTimeMillis(), sw.getTotalTimeMillis() < 6000);
}
Also used : GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) TestBean(org.springframework.tests.sample.beans.TestBean) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) StopWatch(org.springframework.util.StopWatch) Test(org.junit.Test)

Example 14 with StopWatch

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

the class ClientApplication method invokeContactManager.

// ~ Methods
// ========================================================================================================
public void invokeContactManager(Authentication authentication, int nrOfCalls) {
    StopWatch stopWatch = new StopWatch(nrOfCalls + " ContactManager call(s)");
    Map<String, ContactManager> contactServices = this.beanFactory.getBeansOfType(ContactManager.class, true, true);
    SecurityContextHolder.getContext().setAuthentication(authentication);
    for (String beanName : contactServices.keySet()) {
        Object object = this.beanFactory.getBean("&" + beanName);
        try {
            System.out.println("Trying to find setUsername(String) method on: " + object.getClass().getName());
            Method method = object.getClass().getMethod("setUsername", new Class[] { String.class });
            System.out.println("Found; Trying to setUsername(String) to " + authentication.getPrincipal());
            method.invoke(object, authentication.getPrincipal());
        } catch (NoSuchMethodException ignored) {
            System.out.println("This client proxy factory does not have a setUsername(String) method");
        } catch (IllegalAccessException ignored) {
            ignored.printStackTrace();
        } catch (InvocationTargetException ignored) {
            ignored.printStackTrace();
        }
        try {
            System.out.println("Trying to find setPassword(String) method on: " + object.getClass().getName());
            Method method = object.getClass().getMethod("setPassword", new Class[] { String.class });
            method.invoke(object, authentication.getCredentials());
            System.out.println("Found; Trying to setPassword(String) to " + authentication.getCredentials());
        } catch (NoSuchMethodException ignored) {
            System.out.println("This client proxy factory does not have a setPassword(String) method");
        } catch (IllegalAccessException ignored) {
        } catch (InvocationTargetException ignored) {
        }
        ContactManager remoteContactManager = contactServices.get(beanName);
        System.out.println("Calling ContactManager '" + beanName + "'");
        stopWatch.start(beanName);
        List<Contact> contacts = null;
        for (int i = 0; i < nrOfCalls; i++) {
            contacts = remoteContactManager.getAll();
        }
        stopWatch.stop();
        if (contacts.size() != 0) {
            for (Contact contact : contacts) {
                System.out.println("Contact: " + contact);
            }
        } else {
            System.out.println("No contacts found which this user has permission to");
        }
        System.out.println();
        System.out.println(stopWatch.prettyPrint());
    }
    SecurityContextHolder.clearContext();
}
Also used : Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException) StopWatch(org.springframework.util.StopWatch)

Example 15 with StopWatch

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

the class DefaultListableBeanFactoryTests method testPrototypeCreationWithConstructorArgumentsIsFastEnough.

/**
	 * @Test
	 * public void testPrototypeCreationIsFastEnough2() throws Exception {
	 * if (factoryLog.isTraceEnabled() || factoryLog.isDebugEnabled()) {
	 * // Skip this test: Trace logging blows the time limit.
	 * return;
	 * }
	 * DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
	 * Method setBeanNameMethod = TestBean.class.getMethod("setBeanName", String.class);
	 * Method setBeanFactoryMethod = TestBean.class.getMethod("setBeanFactory", BeanFactory.class);
	 * StopWatch sw = new StopWatch();
	 * sw.start("prototype");
	 * for (int i = 0; i < 100000; i++) {
	 * TestBean tb = TestBean.class.newInstance();
	 * setBeanNameMethod.invoke(tb, "test");
	 * setBeanFactoryMethod.invoke(tb, lbf);
	 * }
	 * sw.stop();
	 * // System.out.println(sw.getTotalTimeMillis());
	 * assertTrue("Prototype creation took too long: " + sw.getTotalTimeMillis(), sw.getTotalTimeMillis() < 500);
	 * }
	 */
@Test
// TODO re-enable when ConstructorResolver TODO sorted out
@Ignore
public void testPrototypeCreationWithConstructorArgumentsIsFastEnough() {
    Assume.group(TestGroup.PERFORMANCE);
    Assume.notLogging(factoryLog);
    DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
    RootBeanDefinition rbd = new RootBeanDefinition(TestBean.class);
    rbd.setScope(RootBeanDefinition.SCOPE_PROTOTYPE);
    rbd.getConstructorArgumentValues().addGenericArgumentValue("juergen");
    rbd.getConstructorArgumentValues().addGenericArgumentValue("99");
    lbf.registerBeanDefinition("test", rbd);
    StopWatch sw = new StopWatch();
    sw.start("prototype");
    for (int i = 0; i < 100000; i++) {
        TestBean tb = (TestBean) lbf.getBean("test");
        assertEquals("juergen", tb.getName());
        assertEquals(99, tb.getAge());
    }
    sw.stop();
    // System.out.println(sw.getTotalTimeMillis());
    assertTrue("Prototype creation took too long: " + sw.getTotalTimeMillis(), sw.getTotalTimeMillis() < 3000);
}
Also used : ITestBean(org.springframework.tests.sample.beans.ITestBean) DerivedTestBean(org.springframework.tests.sample.beans.DerivedTestBean) TestBean(org.springframework.tests.sample.beans.TestBean) NestedTestBean(org.springframework.tests.sample.beans.NestedTestBean) DefaultListableBeanFactory(org.springframework.beans.factory.support.DefaultListableBeanFactory) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) StopWatch(org.springframework.util.StopWatch) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

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