org.springframework.tests.Assume Java Examples

The following examples show how to use org.springframework.tests.Assume. 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: MapAccessTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetValuePerformance() throws Exception {
	Assume.group(TestGroup.PERFORMANCE);
	Map<String, String> map = new HashMap<String, String>();
	map.put("key", "value");
	EvaluationContext context = new StandardEvaluationContext(map);

	ExpressionParser spelExpressionParser = new SpelExpressionParser();
	Expression expr = spelExpressionParser.parseExpression("#root['key']");

	StopWatch s = new StopWatch();
	s.start();
	for (int i = 0; i < 10000; i++) {
		expr.getValue(context);
	}
	s.stop();
	assertThat(s.getTotalTimeMillis(), lessThan(200L));
}
 
Example #2
Source File: ScheduledExecutorFactoryBeanTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Test
public void testFixedRepeatedExecutionIsSetUpAndFiresCorrectlyAfterException() throws Exception {
	Assume.group(TestGroup.PERFORMANCE);

	Runnable runnable = mock(Runnable.class);
	willThrow(new IllegalStateException()).given(runnable).run();

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

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

	verify(runnable, atLeast(2)).run();
}
 
Example #3
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 #4
Source File: DefaultListableBeanFactoryTests.java    From java-technology-stack 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: QuartzSupportTests.java    From spring4-understanding with Apache License 2.0 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();
}
 
Example #6
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 #7
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 #8
Source File: JasperReportsMultiFormatViewTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Test
@Override
public void overrideContentDisposition() throws Exception {
	Assume.group(TestGroup.CUSTOM_COMPILATION);
	assumeTrue(canCompileReport);

	AbstractJasperReportsView view = getView(UNCOMPILED_REPORT);

	Map<String, Object> model = getBaseModel();
	model.put(getDiscriminatorKey(), "csv");

	String headerValue = "inline; filename=foo.txt";

	Properties mappings = new Properties();
	mappings.put("csv", headerValue);

	((JasperReportsMultiFormatView) view).setContentDispositionMappings(mappings);

	view.render(model, request, response);

	assertEquals("Invalid Content-Disposition header value", headerValue,
			response.getHeader("Content-Disposition"));
}
 
Example #9
Source File: MBeanServerConnectionFactoryBeanTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Test
public void testTestWithLazyConnection() throws Exception {
	Assume.group(TestGroup.JMXMP);
	MBeanServerConnectionFactoryBean bean = new MBeanServerConnectionFactoryBean();
	bean.setServiceUrl(serviceUrl);
	bean.setConnectOnStartup(false);
	bean.afterPropertiesSet();

	MBeanServerConnection connection = bean.getObject();
	assertTrue(AopUtils.isAopProxy(connection));

	JMXConnectorServer connector = null;
	try {
		connector = getConnectorServer();
		connector.start();
		assertEquals("Incorrect MBean count", getServer().getMBeanCount(), connection.getMBeanCount());
	} finally {
		bean.destroy();
		if (connector != null) {
			connector.stop();
		}
	}
}
 
Example #10
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 #11
Source File: ScheduledExecutorFactoryBeanTests.java    From spring-analysis-note 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 #12
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 #13
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 #14
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 #15
Source File: AspectJAutoProxyCreatorTests.java    From spring-analysis-note 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 #16
Source File: DefaultListableBeanFactoryTests.java    From spring4-understanding with Apache License 2.0 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());
	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 #17
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 #18
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 #19
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 #20
Source File: DefaultConversionServiceTests.java    From java-technology-stack 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: 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 #22
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 #23
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 #24
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();
}
 
Example #25
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 #26
Source File: DefaultListableBeanFactoryTests.java    From spring4-understanding with Apache License 2.0 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);
	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: AspectJAutoProxyCreatorTests.java    From spring4-understanding with Apache License 2.0 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 #28
Source File: QuartzSupportTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void schedulerWithSpringBeanJobFactoryAndQuartzJobBean() throws Exception {
	Assume.group(TestGroup.PERFORMANCE);
	DummyJobBean.param = 0;
	DummyJobBean.count = 0;

	JobDetailImpl jobDetail = new JobDetailImpl();
	jobDetail.setDurability(true);
	jobDetail.setJobClass(DummyJobBean.class);
	jobDetail.setName("myJob");
	jobDetail.getJobDataMap().put("param", "10");

	SimpleTriggerFactoryBean trigger = new SimpleTriggerFactoryBean();
	trigger.setName("myTrigger");
	trigger.setJobDetail(jobDetail);
	trigger.setStartDelay(1);
	trigger.setRepeatInterval(500);
	trigger.setRepeatCount(1);
	trigger.afterPropertiesSet();

	SchedulerFactoryBean bean = new SchedulerFactoryBean();
	bean.setJobFactory(new SpringBeanJobFactory());
	bean.setTriggers(trigger.getObject());
	bean.setJobDetails(jobDetail);
	bean.afterPropertiesSet();
	bean.start();

	Thread.sleep(500);
	assertEquals(10, DummyJobBean.param);
	assertTrue(DummyJobBean.count > 0);

	bean.destroy();
}
 
Example #29
Source File: QuartzSupportTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void schedulerWithSpringBeanJobFactoryAndParamMismatchNotIgnored() throws Exception {
	Assume.group(TestGroup.PERFORMANCE);

	DummyJob.param = 0;
	DummyJob.count = 0;

	JobDetailImpl jobDetail = new JobDetailImpl();
	jobDetail.setDurability(true);
	jobDetail.setJobClass(DummyJob.class);
	jobDetail.setName("myJob");
	jobDetail.getJobDataMap().put("para", "10");
	jobDetail.getJobDataMap().put("ignoredParam", "10");

	SimpleTriggerFactoryBean trigger = new SimpleTriggerFactoryBean();
	trigger.setName("myTrigger");
	trigger.setJobDetail(jobDetail);
	trigger.setStartDelay(1);
	trigger.setRepeatInterval(500);
	trigger.setRepeatCount(1);
	trigger.afterPropertiesSet();

	SchedulerFactoryBean bean = new SchedulerFactoryBean();
	SpringBeanJobFactory jobFactory = new SpringBeanJobFactory();
	jobFactory.setIgnoredUnknownProperties("ignoredParam");
	bean.setJobFactory(jobFactory);
	bean.setTriggers(trigger.getObject());
	bean.setJobDetails(jobDetail);
	bean.afterPropertiesSet();

	Thread.sleep(500);
	assertEquals(0, DummyJob.param);
	assertTrue(DummyJob.count == 0);

	bean.destroy();
}
 
Example #30
Source File: ApplicationContextExpressionTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@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);
}