Java Code Examples for org.springframework.tests.Assume#group()

The following examples show how to use org.springframework.tests.Assume#group() . 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: GenericConversionServiceTests.java    From spring4-understanding with Apache License 2.0 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<String, String>();
	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<String, Integer>(source.size());
		for (Map.Entry<String, String> entry : source.entrySet()) {
			target.put(entry.getKey(), Integer.valueOf(entry.getValue()));
		}
	}
	watch.stop();
	// System.out.println(watch.prettyPrint());
}
 
Example 2
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 3
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 4
Source File: DefaultListableBeanFactoryTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
/**
 * @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
@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);
	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 java-technology-stack 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 6
Source File: MapAccessTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void testGetValuePerformance() throws Exception {
	Assume.group(TestGroup.PERFORMANCE);
	Map<String, String> map = new HashMap<>();
	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 7
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 8
Source File: ApplicationContextExpressionTests.java    From spring-analysis-note with MIT License 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);
}
 
Example 9
Source File: DefaultLifecycleProcessorTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void singleSmartLifecycleShutdown() throws Exception {
	Assume.group(TestGroup.PERFORMANCE);

	CopyOnWriteArrayList<Lifecycle> stoppedBeans = new CopyOnWriteArrayList<Lifecycle>();
	TestSmartLifecycleBean bean = TestSmartLifecycleBean.forShutdownTests(99, 300, stoppedBeans);
	StaticApplicationContext context = new StaticApplicationContext();
	context.getBeanFactory().registerSingleton("bean", bean);
	context.refresh();
	assertTrue(bean.isRunning());
	context.stop();
	assertEquals(1, stoppedBeans.size());
	assertFalse(bean.isRunning());
	assertEquals(bean, stoppedBeans.get(0));
}
 
Example 10
Source File: QuartzSupportTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void schedulerWithSpringBeanJobFactory() 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("param", "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();
	bean.setJobFactory(new SpringBeanJobFactory());
	bean.setTriggers(trigger.getObject());
	bean.setJobDetails(jobDetail);
	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 11
Source File: QuartzSupportTests.java    From spring4-understanding with Apache License 2.0 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 12
Source File: DefaultListableBeanFactoryTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test(timeout = 1000)
public void testRegistrationOfManySingletonsIsFastEnough() {
	Assume.group(TestGroup.PERFORMANCE);
	DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
	bf.registerBeanDefinition("b", new RootBeanDefinition(B.class));
	// bf.getBean("b");

	for (int i = 0; i < 100000; i++) {
		bf.registerSingleton("a" + i, new A());
	}
}
 
Example 13
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 14
Source File: DefaultLifecycleProcessorTests.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@Test
public void dependentShutdownFirstEvenIfItsPhaseIsLower() throws Exception {
	Assume.group(TestGroup.PERFORMANCE);

	CopyOnWriteArrayList<Lifecycle> stoppedBeans = new CopyOnWriteArrayList<Lifecycle>();
	TestSmartLifecycleBean beanMin = TestSmartLifecycleBean.forShutdownTests(Integer.MIN_VALUE, 100, stoppedBeans);
	TestSmartLifecycleBean bean1 = TestSmartLifecycleBean.forShutdownTests(1, 200, stoppedBeans);
	TestSmartLifecycleBean bean99 = TestSmartLifecycleBean.forShutdownTests(99, 100, stoppedBeans);
	TestSmartLifecycleBean bean2 = TestSmartLifecycleBean.forShutdownTests(2, 300, stoppedBeans);
	TestSmartLifecycleBean bean7 = TestSmartLifecycleBean.forShutdownTests(7, 400, stoppedBeans);
	TestSmartLifecycleBean beanMax = TestSmartLifecycleBean.forShutdownTests(Integer.MAX_VALUE, 400, stoppedBeans);
	StaticApplicationContext context = new StaticApplicationContext();
	context.getBeanFactory().registerSingleton("beanMin", beanMin);
	context.getBeanFactory().registerSingleton("bean1", bean1);
	context.getBeanFactory().registerSingleton("bean2", bean2);
	context.getBeanFactory().registerSingleton("bean7", bean7);
	context.getBeanFactory().registerSingleton("bean99", bean99);
	context.getBeanFactory().registerSingleton("beanMax", beanMax);
	context.getBeanFactory().registerDependentBean("bean99", "bean2");
	context.refresh();
	assertTrue(beanMin.isRunning());
	assertTrue(bean1.isRunning());
	assertTrue(bean2.isRunning());
	assertTrue(bean7.isRunning());
	assertTrue(bean99.isRunning());
	assertTrue(beanMax.isRunning());
	context.stop();
	assertFalse(beanMin.isRunning());
	assertFalse(bean1.isRunning());
	assertFalse(bean2.isRunning());
	assertFalse(bean7.isRunning());
	assertFalse(bean99.isRunning());
	assertFalse(beanMax.isRunning());
	assertEquals(6, stoppedBeans.size());
	assertEquals(Integer.MAX_VALUE, getPhase(stoppedBeans.get(0)));
	assertEquals(2, getPhase(stoppedBeans.get(1)));
	assertEquals(bean2, stoppedBeans.get(1));
	assertEquals(99, getPhase(stoppedBeans.get(2)));
	assertEquals(bean99, stoppedBeans.get(2));
	assertEquals(7, getPhase(stoppedBeans.get(3)));
	assertEquals(1, getPhase(stoppedBeans.get(4)));
	assertEquals(Integer.MIN_VALUE, getPhase(stoppedBeans.get(5)));
}
 
Example 15
Source File: DefaultLifecycleProcessorTests.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Test
public void dependentShutdownFirstEvenIfItsPhaseIsLower() throws Exception {
	Assume.group(TestGroup.PERFORMANCE);

	CopyOnWriteArrayList<Lifecycle> stoppedBeans = new CopyOnWriteArrayList<>();
	TestSmartLifecycleBean beanMin = TestSmartLifecycleBean.forShutdownTests(Integer.MIN_VALUE, 100, stoppedBeans);
	TestSmartLifecycleBean bean1 = TestSmartLifecycleBean.forShutdownTests(1, 200, stoppedBeans);
	TestSmartLifecycleBean bean99 = TestSmartLifecycleBean.forShutdownTests(99, 100, stoppedBeans);
	TestSmartLifecycleBean bean2 = TestSmartLifecycleBean.forShutdownTests(2, 300, stoppedBeans);
	TestSmartLifecycleBean bean7 = TestSmartLifecycleBean.forShutdownTests(7, 400, stoppedBeans);
	TestSmartLifecycleBean beanMax = TestSmartLifecycleBean.forShutdownTests(Integer.MAX_VALUE, 400, stoppedBeans);
	StaticApplicationContext context = new StaticApplicationContext();
	context.getBeanFactory().registerSingleton("beanMin", beanMin);
	context.getBeanFactory().registerSingleton("bean1", bean1);
	context.getBeanFactory().registerSingleton("bean2", bean2);
	context.getBeanFactory().registerSingleton("bean7", bean7);
	context.getBeanFactory().registerSingleton("bean99", bean99);
	context.getBeanFactory().registerSingleton("beanMax", beanMax);
	context.getBeanFactory().registerDependentBean("bean99", "bean2");
	context.refresh();
	assertTrue(beanMin.isRunning());
	assertTrue(bean1.isRunning());
	assertTrue(bean2.isRunning());
	assertTrue(bean7.isRunning());
	assertTrue(bean99.isRunning());
	assertTrue(beanMax.isRunning());
	context.stop();
	assertFalse(beanMin.isRunning());
	assertFalse(bean1.isRunning());
	assertFalse(bean2.isRunning());
	assertFalse(bean7.isRunning());
	assertFalse(bean99.isRunning());
	assertFalse(beanMax.isRunning());
	assertEquals(6, stoppedBeans.size());
	assertEquals(Integer.MAX_VALUE, getPhase(stoppedBeans.get(0)));
	assertEquals(2, getPhase(stoppedBeans.get(1)));
	assertEquals(bean2, stoppedBeans.get(1));
	assertEquals(99, getPhase(stoppedBeans.get(2)));
	assertEquals(bean99, stoppedBeans.get(2));
	assertEquals(7, getPhase(stoppedBeans.get(3)));
	assertEquals(1, getPhase(stoppedBeans.get(4)));
	assertEquals(Integer.MIN_VALUE, getPhase(stoppedBeans.get(5)));
}
 
Example 16
Source File: DefaultLifecycleProcessorTests.java    From java-technology-stack with MIT License 4 votes vote down vote up
@Test
public void dependentShutdownFirstAndIsSmartLifecycle() throws Exception {
	Assume.group(TestGroup.PERFORMANCE);

	CopyOnWriteArrayList<Lifecycle> stoppedBeans = new CopyOnWriteArrayList<>();
	TestSmartLifecycleBean beanMin = TestSmartLifecycleBean.forShutdownTests(Integer.MIN_VALUE, 400, stoppedBeans);
	TestSmartLifecycleBean beanNegative = TestSmartLifecycleBean.forShutdownTests(-99, 100, stoppedBeans);
	TestSmartLifecycleBean bean1 = TestSmartLifecycleBean.forShutdownTests(1, 200, stoppedBeans);
	TestSmartLifecycleBean bean2 = TestSmartLifecycleBean.forShutdownTests(2, 300, stoppedBeans);
	TestSmartLifecycleBean bean7 = TestSmartLifecycleBean.forShutdownTests(7, 400, stoppedBeans);
	TestLifecycleBean simpleBean = TestLifecycleBean.forShutdownTests(stoppedBeans);
	StaticApplicationContext context = new StaticApplicationContext();
	context.getBeanFactory().registerSingleton("beanMin", beanMin);
	context.getBeanFactory().registerSingleton("beanNegative", beanNegative);
	context.getBeanFactory().registerSingleton("bean1", bean1);
	context.getBeanFactory().registerSingleton("bean2", bean2);
	context.getBeanFactory().registerSingleton("bean7", bean7);
	context.getBeanFactory().registerSingleton("simpleBean", simpleBean);
	context.getBeanFactory().registerDependentBean("simpleBean", "beanNegative");
	context.refresh();
	assertTrue(beanMin.isRunning());
	assertTrue(beanNegative.isRunning());
	assertTrue(bean1.isRunning());
	assertTrue(bean2.isRunning());
	assertTrue(bean7.isRunning());
	// should start since it's a dependency of an auto-started bean
	assertTrue(simpleBean.isRunning());
	context.stop();
	assertFalse(beanMin.isRunning());
	assertFalse(beanNegative.isRunning());
	assertFalse(bean1.isRunning());
	assertFalse(bean2.isRunning());
	assertFalse(bean7.isRunning());
	assertFalse(simpleBean.isRunning());
	assertEquals(6, stoppedBeans.size());
	assertEquals(7, getPhase(stoppedBeans.get(0)));
	assertEquals(2, getPhase(stoppedBeans.get(1)));
	assertEquals(1, getPhase(stoppedBeans.get(2)));
	assertEquals(-99, getPhase(stoppedBeans.get(3)));
	assertEquals(0, getPhase(stoppedBeans.get(4)));
	assertEquals(Integer.MIN_VALUE, getPhase(stoppedBeans.get(5)));
}
 
Example 17
Source File: AnnotationProcessorPerformanceTests.java    From java-technology-stack with MIT License 4 votes vote down vote up
@BeforeClass
public static void commonAssumptions() {
	Assume.group(TestGroup.PERFORMANCE);
	Assume.notLogging(factoryLog);
}
 
Example 18
Source File: DefaultLifecycleProcessorTests.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@Test
public void dependentShutdownFirstAndIsSmartLifecycle() throws Exception {
	Assume.group(TestGroup.PERFORMANCE);

	CopyOnWriteArrayList<Lifecycle> stoppedBeans = new CopyOnWriteArrayList<Lifecycle>();
	TestSmartLifecycleBean beanMin = TestSmartLifecycleBean.forShutdownTests(Integer.MIN_VALUE, 400, stoppedBeans);
	TestSmartLifecycleBean beanNegative = TestSmartLifecycleBean.forShutdownTests(-99, 100, stoppedBeans);
	TestSmartLifecycleBean bean1 = TestSmartLifecycleBean.forShutdownTests(1, 200, stoppedBeans);
	TestSmartLifecycleBean bean2 = TestSmartLifecycleBean.forShutdownTests(2, 300, stoppedBeans);
	TestSmartLifecycleBean bean7 = TestSmartLifecycleBean.forShutdownTests(7, 400, stoppedBeans);
	TestLifecycleBean simpleBean = TestLifecycleBean.forShutdownTests(stoppedBeans);
	StaticApplicationContext context = new StaticApplicationContext();
	context.getBeanFactory().registerSingleton("beanMin", beanMin);
	context.getBeanFactory().registerSingleton("beanNegative", beanNegative);
	context.getBeanFactory().registerSingleton("bean1", bean1);
	context.getBeanFactory().registerSingleton("bean2", bean2);
	context.getBeanFactory().registerSingleton("bean7", bean7);
	context.getBeanFactory().registerSingleton("simpleBean", simpleBean);
	context.getBeanFactory().registerDependentBean("simpleBean", "beanNegative");
	context.refresh();
	assertTrue(beanMin.isRunning());
	assertTrue(beanNegative.isRunning());
	assertTrue(bean1.isRunning());
	assertTrue(bean2.isRunning());
	assertTrue(bean7.isRunning());
	// should start since it's a dependency of an auto-started bean
	assertTrue(simpleBean.isRunning());
	context.stop();
	assertFalse(beanMin.isRunning());
	assertFalse(beanNegative.isRunning());
	assertFalse(bean1.isRunning());
	assertFalse(bean2.isRunning());
	assertFalse(bean7.isRunning());
	assertFalse(simpleBean.isRunning());
	assertEquals(6, stoppedBeans.size());
	assertEquals(7, getPhase(stoppedBeans.get(0)));
	assertEquals(2, getPhase(stoppedBeans.get(1)));
	assertEquals(1, getPhase(stoppedBeans.get(2)));
	assertEquals(-99, getPhase(stoppedBeans.get(3)));
	assertEquals(0, getPhase(stoppedBeans.get(4)));
	assertEquals(Integer.MIN_VALUE, getPhase(stoppedBeans.get(5)));
}
 
Example 19
Source File: AbstractPropertyAccessorTests.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@Test
public void setPrimitiveArrayPropertyLargeMatching() {
	Assume.group(TestGroup.PERFORMANCE);
	Assume.notLogging(LogFactory.getLog(AbstractPropertyAccessorTests.class));

	PrimitiveArrayBean target = new PrimitiveArrayBean();
	AbstractPropertyAccessor accessor = createAccessor(target);
	int[] input = new int[1024];
	StopWatch sw = new StopWatch();
	sw.start("array1");
	for (int i = 0; i < 1000; i++) {
		accessor.setPropertyValue("array", input);
	}
	sw.stop();
	assertEquals(1024, target.getArray().length);
	assertEquals(0, target.getArray()[0]);
	long time1 = sw.getLastTaskTimeMillis();
	assertTrue("Took too long", sw.getLastTaskTimeMillis() < 100);

	accessor.registerCustomEditor(String.class, new StringTrimmerEditor(false));
	sw.start("array2");
	for (int i = 0; i < 1000; i++) {
		accessor.setPropertyValue("array", input);
	}
	sw.stop();
	assertTrue("Took too long", sw.getLastTaskTimeMillis() < 125);

	accessor.registerCustomEditor(int.class, "array.somePath", new CustomNumberEditor(Integer.class, false));
	sw.start("array3");
	for (int i = 0; i < 1000; i++) {
		accessor.setPropertyValue("array", input);
	}
	sw.stop();
	assertTrue("Took too long", sw.getLastTaskTimeMillis() < 100);

	accessor.registerCustomEditor(int.class, "array[0].somePath", new CustomNumberEditor(Integer.class, false));
	sw.start("array3");
	for (int i = 0; i < 1000; i++) {
		accessor.setPropertyValue("array", input);
	}
	sw.stop();
	assertTrue("Took too long", sw.getLastTaskTimeMillis() < 100);

	accessor.registerCustomEditor(int.class, new CustomNumberEditor(Integer.class, false));
	sw.start("array4");
	for (int i = 0; i < 100; i++) {
		accessor.setPropertyValue("array", input);
	}
	sw.stop();
	assertEquals(1024, target.getArray().length);
	assertEquals(0, target.getArray()[0]);
	assertTrue("Took too long", sw.getLastTaskTimeMillis() > time1);
}
 
Example 20
Source File: AbstractSockJsIntegrationTests.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@BeforeClass
public static void performanceTestGroupAssumption() throws Exception {
	Assume.group(TestGroup.PERFORMANCE);
}