org.springframework.tests.TestGroup Java Examples

The following examples show how to use org.springframework.tests.TestGroup. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ScheduledExecutorFactoryBeanTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void testFixedRepeatedExecutionIsSetUpAndFiresCorrectly() throws Exception {
	Assume.group(TestGroup.PERFORMANCE);

	Runnable runnable = mock(Runnable.class);

	ScheduledExecutorTask task = new ScheduledExecutorTask(runnable);
	task.setPeriod(500);
	task.setFixedRate(true);

	ScheduledExecutorFactoryBean factory = new ScheduledExecutorFactoryBean();
	factory.setScheduledExecutorTasks(new ScheduledExecutorTask[]{task});
	factory.afterPropertiesSet();
	pauseToLetTaskStart(2);
	factory.destroy();

	verify(runnable, atLeast(2)).run();
}
 
Example #2
Source File: DefaultListableBeanFactoryTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void testPrototypeCreationWithResolvedConstructorArgumentsIsFastEnough() {
	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(new RuntimeBeanReference("spouse"));
	lbf.registerBeanDefinition("test", rbd);
	lbf.registerBeanDefinition("spouse", new RootBeanDefinition(TestBean.class));
	lbf.freezeConfiguration();
	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);
}
 
Example #3
Source File: AspectJAutoProxyCreatorTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@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);
}
 
Example #4
Source File: DefaultListableBeanFactoryTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
@Ignore  // TODO re-enable when ConstructorResolver TODO sorted out
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);
	lbf.freezeConfiguration();
	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);
}
 
Example #5
Source File: DefaultListableBeanFactoryTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void testPrototypeCreationIsFastEnough() {
	Assume.group(TestGroup.PERFORMANCE);
	Assume.notLogging(factoryLog);
	DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
	RootBeanDefinition rbd = new RootBeanDefinition(TestBean.class);
	rbd.setScope(RootBeanDefinition.SCOPE_PROTOTYPE);
	lbf.registerBeanDefinition("test", rbd);
	lbf.freezeConfiguration();
	StopWatch sw = new StopWatch();
	sw.start("prototype");
	for (int i = 0; i < 100000; i++) {
		lbf.getBean("test");
	}
	sw.stop();
	// System.out.println(sw.getTotalTimeMillis());
	assertTrue("Prototype creation took too long: " + sw.getTotalTimeMillis(), sw.getTotalTimeMillis() < 3000);
}
 
Example #6
Source File: ScheduledExecutorFactoryBeanTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void testOneTimeExecutionIsSetUpAndFiresCorrectly() throws Exception {
	Assume.group(TestGroup.PERFORMANCE);

	Runnable runnable = mock(Runnable.class);

	ScheduledExecutorFactoryBean factory = new ScheduledExecutorFactoryBean();
	factory.setScheduledExecutorTasks(new ScheduledExecutorTask[]{
		new ScheduledExecutorTask(runnable)
	});
	factory.afterPropertiesSet();
	pauseToLetTaskStart(1);
	factory.destroy();

	verify(runnable).run();
}
 
Example #7
Source File: DefaultListableBeanFactoryTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void testPrototypeCreationWithPropertiesIsFastEnough() {
	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("name", "juergen");
	rbd.getPropertyValues().add("age", "99");
	lbf.registerBeanDefinition("test", rbd);
	lbf.freezeConfiguration();
	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() < 4000);
}
 
Example #8
Source File: DefaultListableBeanFactoryTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@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));
	lbf.freezeConfiguration();
	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);
}
 
Example #9
Source File: DefaultListableBeanFactoryTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void testSingletonLookupByNameIsFastEnough() {
	Assume.group(TestGroup.PERFORMANCE);
	Assume.notLogging(factoryLog);
	DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
	lbf.registerBeanDefinition("test", new RootBeanDefinition(TestBean.class));
	lbf.freezeConfiguration();
	StopWatch sw = new StopWatch();
	sw.start("singleton");
	for (int i = 0; i < 1000000; i++) {
		lbf.getBean("test");
	}
	sw.stop();
	// System.out.println(sw.getTotalTimeMillis());
	assertTrue("Singleton lookup took too long: " + sw.getTotalTimeMillis(), sw.getTotalTimeMillis() < 1000);
}
 
Example #10
Source File: DefaultListableBeanFactoryTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void testSingletonLookupByTypeIsFastEnough() {
	Assume.group(TestGroup.PERFORMANCE);
	Assume.notLogging(factoryLog);
	DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
	lbf.registerBeanDefinition("test", new RootBeanDefinition(TestBean.class));
	lbf.freezeConfiguration();
	StopWatch sw = new StopWatch();
	sw.start("singleton");
	for (int i = 0; i < 1000000; i++) {
		lbf.getBean(TestBean.class);
	}
	sw.stop();
	// System.out.println(sw.getTotalTimeMillis());
	assertTrue("Singleton lookup took too long: " + sw.getTotalTimeMillis(), sw.getTotalTimeMillis() < 1000);
}
 
Example #11
Source File: DefaultListableBeanFactoryTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
/**
 * Test that by-type bean lookup caching is working effectively by searching for a
 * bean of type B 10K times within a container having 1K additional beans of type A.
 * Prior to by-type caching, each bean lookup would traverse the entire container
 * (all 1001 beans), performing expensive assignability checks, etc. Now these
 * operations are necessary only once, providing a dramatic performance improvement.
 * On load-free modern hardware (e.g. an 8-core MPB), this method should complete well
 * under the 1000 ms timeout, usually ~= 300ms. With caching removed and on the same
 * hardware the method will take ~13000 ms. See SPR-6870.
 */
@Test(timeout = 1000)
public void testByTypeLookupIsFastEnough() {
	Assume.group(TestGroup.PERFORMANCE);
	DefaultListableBeanFactory bf = new DefaultListableBeanFactory();

	for (int i = 0; i < 1000; i++) {
		bf.registerBeanDefinition("a" + i, new RootBeanDefinition(A.class));
	}
	bf.registerBeanDefinition("b", new RootBeanDefinition(B.class));

	bf.freezeConfiguration();

	for (int i = 0; i < 10000; i++) {
		bf.getBean(B.class);
	}
}
 
Example #12
Source File: DefaultListableBeanFactoryTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void testPrototypeCreationWithResolvedConstructorArgumentsIsFastEnough() {
	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(new RuntimeBeanReference("spouse"));
	lbf.registerBeanDefinition("test", rbd);
	lbf.registerBeanDefinition("spouse", new RootBeanDefinition(TestBean.class));
	lbf.freezeConfiguration();
	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);
}
 
Example #13
Source File: GenericConversionServiceTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void testPerformance2() throws Exception {
	Assume.group(TestGroup.PERFORMANCE);
	StopWatch watch = new StopWatch("list<string> -> list<integer> conversionPerformance");
	watch.start("convert 4,000,000 with conversion service");
	List<String> source = new LinkedList<>();
	source.add("1");
	source.add("2");
	source.add("3");
	TypeDescriptor td = new TypeDescriptor(getClass().getField("list"));
	for (int i = 0; i < 1000000; i++) {
		conversionService.convert(source, TypeDescriptor.forObject(source), td);
	}
	watch.stop();
	watch.start("convert 4,000,000 manually");
	for (int i = 0; i < 4000000; i++) {
		List<Integer> target = new ArrayList<>(source.size());
		for (String element : source) {
			target.add(Integer.valueOf(element));
		}
	}
	watch.stop();
	// System.out.println(watch.prettyPrint());
}
 
Example #14
Source File: DefaultListableBeanFactoryTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void testSingletonLookupByTypeIsFastEnough() {
	Assume.group(TestGroup.PERFORMANCE);
	Assume.notLogging(factoryLog);
	DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
	lbf.registerBeanDefinition("test", new RootBeanDefinition(TestBean.class));
	lbf.freezeConfiguration();
	StopWatch sw = new StopWatch();
	sw.start("singleton");
	for (int i = 0; i < 1000000; i++) {
		lbf.getBean(TestBean.class);
	}
	sw.stop();
	// System.out.println(sw.getTotalTimeMillis());
	assertTrue("Singleton lookup took too long: " + sw.getTotalTimeMillis(), sw.getTotalTimeMillis() < 1000);
}
 
Example #15
Source File: QuartzSupportTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void schedulerAccessorBean() throws Exception {
	Assume.group(TestGroup.PERFORMANCE);
	ClassPathXmlApplicationContext ctx = context("schedulerAccessorBean.xml");
	Thread.sleep(3000);
	try {
		QuartzTestBean exportService = (QuartzTestBean) ctx.getBean("exportService");
		QuartzTestBean importService = (QuartzTestBean) ctx.getBean("importService");

		assertEquals("doImport called exportService", 0, exportService.getImportCount());
		assertEquals("doExport not called on exportService", 2, exportService.getExportCount());
		assertEquals("doImport not called on importService", 2, importService.getImportCount());
		assertEquals("doExport called on importService", 0, importService.getExportCount());
	}
	finally {
		ctx.close();
	}
}
 
Example #16
Source File: DelegatingWebConnectionTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void verifyExampleInClassLevelJavadoc() throws Exception {
	Assume.group(TestGroup.PERFORMANCE);

	WebClient webClient = new WebClient();

	MockMvc mockMvc = MockMvcBuilders.standaloneSetup().build();
	MockMvcWebConnection mockConnection = new MockMvcWebConnection(mockMvc, webClient);

	WebRequestMatcher cdnMatcher = new UrlRegexRequestMatcher(".*?//code.jquery.com/.*");
	WebConnection httpConnection = new HttpWebConnection(webClient);
	webClient.setWebConnection(
			new DelegatingWebConnection(mockConnection, new DelegateWebConnection(cdnMatcher, httpConnection)));

	Page page = webClient.getPage("https://code.jquery.com/jquery-1.11.0.min.js");
	assertThat(page.getWebResponse().getStatusCode(), equalTo(200));
	assertThat(page.getWebResponse().getContentAsString(), not(isEmptyString()));
}
 
Example #17
Source File: AspectJAutoProxyCreatorTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@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);
}
 
Example #18
Source File: AspectJAutoProxyCreatorTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@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);
}
 
Example #19
Source File: MBeanServerConnectionFactoryBeanTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void testTestValidConnection() throws Exception {
	Assume.group(TestGroup.JMXMP);
	JMXConnectorServer connectorServer = getConnectorServer();
	connectorServer.start();

	try {
		MBeanServerConnectionFactoryBean bean = new MBeanServerConnectionFactoryBean();
		bean.setServiceUrl(serviceUrl);
		bean.afterPropertiesSet();

		try {
			MBeanServerConnection connection = bean.getObject();
			assertNotNull("Connection should not be null", connection);

			// perform simple MBean count test
			assertEquals("MBean count should be the same", getServer().getMBeanCount(), connection.getMBeanCount());
		}
		finally {
			bean.destroy();
		}
	}
	finally {
		connectorServer.stop();
	}
}
 
Example #20
Source File: DefaultConversionServiceTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void testPerformance1() {
	Assume.group(TestGroup.PERFORMANCE);
	StopWatch watch = new StopWatch("integer->string conversionPerformance");
	watch.start("convert 4,000,000 with conversion service");
	for (int i = 0; i < 4000000; i++) {
		conversionService.convert(3, String.class);
	}
	watch.stop();
	watch.start("convert 4,000,000 manually");
	for (int i = 0; i < 4000000; i++) {
		Integer.valueOf(3).toString();
	}
	watch.stop();
	// System.out.println(watch.prettyPrint());
}
 
Example #21
Source File: GenericConversionServiceTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void testPerformance2() throws Exception {
	Assume.group(TestGroup.PERFORMANCE);
	StopWatch watch = new StopWatch("list<string> -> list<integer> conversionPerformance");
	watch.start("convert 4,000,000 with conversion service");
	List<String> source = new LinkedList<>();
	source.add("1");
	source.add("2");
	source.add("3");
	TypeDescriptor td = new TypeDescriptor(getClass().getField("list"));
	for (int i = 0; i < 1000000; i++) {
		conversionService.convert(source, TypeDescriptor.forObject(source), td);
	}
	watch.stop();
	watch.start("convert 4,000,000 manually");
	for (int i = 0; i < 4000000; i++) {
		List<Integer> target = new ArrayList<>(source.size());
		for (String element : source) {
			target.add(Integer.valueOf(element));
		}
	}
	watch.stop();
	// System.out.println(watch.prettyPrint());
}
 
Example #22
Source File: GenericConversionServiceTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void testPerformance3() throws Exception {
	Assume.group(TestGroup.PERFORMANCE);
	StopWatch watch = new StopWatch("map<string, string> -> map<string, integer> conversionPerformance");
	watch.start("convert 4,000,000 with conversion service");
	Map<String, String> source = new HashMap<>();
	source.put("1", "1");
	source.put("2", "2");
	source.put("3", "3");
	TypeDescriptor td = new TypeDescriptor(getClass().getField("map"));
	for (int i = 0; i < 1000000; i++) {
		conversionService.convert(source, TypeDescriptor.forObject(source), td);
	}
	watch.stop();
	watch.start("convert 4,000,000 manually");
	for (int i = 0; i < 4000000; i++) {
		Map<String, Integer> target = new HashMap<>(source.size());
		source.forEach((k, v) -> target.put(k, Integer.valueOf(v)));
	}
	watch.stop();
	// System.out.println(watch.prettyPrint());
}
 
Example #23
Source File: DefaultListableBeanFactoryTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@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));
	lbf.freezeConfiguration();
	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);
}
 
Example #24
Source File: EhCacheCacheTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void testExpiredElements() throws Exception {
	Assume.group(TestGroup.LONG_RUNNING);

	String key = "brancusi";
	String value = "constantin";
	Element brancusi = new Element(key, value);
	// ttl = 10s
	brancusi.setTimeToLive(3);
	nativeCache.put(brancusi);

	assertEquals(value, cache.get(key).get());
	// wait for the entry to expire
	Thread.sleep(5 * 1000);
	assertNull(cache.get(key));
}
 
Example #25
Source File: AspectJAutoProxyCreatorTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@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);
}
 
Example #26
Source File: DefaultListableBeanFactoryTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void testPrototypeCreationIsFastEnough() {
	Assume.group(TestGroup.PERFORMANCE);
	Assume.notLogging(factoryLog);
	DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
	RootBeanDefinition rbd = new RootBeanDefinition(TestBean.class);
	rbd.setScope(RootBeanDefinition.SCOPE_PROTOTYPE);
	lbf.registerBeanDefinition("test", rbd);
	lbf.freezeConfiguration();
	StopWatch sw = new StopWatch();
	sw.start("prototype");
	for (int i = 0; i < 100000; i++) {
		lbf.getBean("test");
	}
	sw.stop();
	// System.out.println(sw.getTotalTimeMillis());
	assertTrue("Prototype creation took too long: " + sw.getTotalTimeMillis(), sw.getTotalTimeMillis() < 3000);
}
 
Example #27
Source File: GenericConversionServiceTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void testPerformance3() throws Exception {
	Assume.group(TestGroup.PERFORMANCE);
	StopWatch watch = new StopWatch("map<string, string> -> map<string, integer> conversionPerformance");
	watch.start("convert 4,000,000 with conversion service");
	Map<String, String> source = new HashMap<>();
	source.put("1", "1");
	source.put("2", "2");
	source.put("3", "3");
	TypeDescriptor td = new TypeDescriptor(getClass().getField("map"));
	for (int i = 0; i < 1000000; i++) {
		conversionService.convert(source, TypeDescriptor.forObject(source), td);
	}
	watch.stop();
	watch.start("convert 4,000,000 manually");
	for (int i = 0; i < 4000000; i++) {
		Map<String, Integer> target = new HashMap<>(source.size());
		source.forEach((k, v) -> target.put(k, Integer.valueOf(v)));
	}
	watch.stop();
	// System.out.println(watch.prettyPrint());
}
 
Example #28
Source File: QuartzSupportTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void twoAnonymousMethodInvokingJobDetailFactoryBeans() throws Exception {
	Assume.group(TestGroup.PERFORMANCE);
	ClassPathXmlApplicationContext ctx = context("multipleAnonymousMethodInvokingJobDetailFB.xml");
	Thread.sleep(3000);
	try {
		QuartzTestBean exportService = (QuartzTestBean) ctx.getBean("exportService");
		QuartzTestBean importService = (QuartzTestBean) ctx.getBean("importService");

		assertEquals("doImport called exportService", 0, exportService.getImportCount());
		assertEquals("doExport not called on exportService", 2, exportService.getExportCount());
		assertEquals("doImport not called on importService", 2, importService.getImportCount());
		assertEquals("doExport called on importService", 0, importService.getExportCount());
	}
	finally {
		ctx.close();
	}
}
 
Example #29
Source File: DefaultListableBeanFactoryTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void testPrototypeCreationWithDependencyCheckIsFastEnough() {
	Assume.group(TestGroup.PERFORMANCE);
	Assume.notLogging(factoryLog);
	DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
	RootBeanDefinition rbd = new RootBeanDefinition(LifecycleBean.class);
	rbd.setScope(RootBeanDefinition.SCOPE_PROTOTYPE);
	rbd.setDependencyCheck(RootBeanDefinition.DEPENDENCY_CHECK_OBJECTS);
	lbf.registerBeanDefinition("test", rbd);
	lbf.addBeanPostProcessor(new LifecycleBean.PostProcessor());
	lbf.freezeConfiguration();
	StopWatch sw = new StopWatch();
	sw.start("prototype");
	for (int i = 0; i < 100000; i++) {
		lbf.getBean("test");
	}
	sw.stop();
	// System.out.println(sw.getTotalTimeMillis());
	assertTrue("Prototype creation took too long: " + sw.getTotalTimeMillis(), sw.getTotalTimeMillis() < 3000);
}
 
Example #30
Source File: QuartzSupportTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void schedulerWithSpringBeanJobFactoryAndJobSchedulingData() throws Exception {
	Assume.group(TestGroup.PERFORMANCE);
	DummyJob.param = 0;
	DummyJob.count = 0;

	SchedulerFactoryBean bean = new SchedulerFactoryBean();
	bean.setJobFactory(new SpringBeanJobFactory());
	bean.setJobSchedulingDataLocation("org/springframework/scheduling/quartz/job-scheduling-data.xml");
	bean.afterPropertiesSet();
	bean.start();

	Thread.sleep(500);
	assertEquals(10, DummyJob.param);
	assertTrue("DummyJob should have been executed at least once.", DummyJob.count > 0);

	bean.destroy();
}