Made fragile tests a little less fragile: increased max times.

This commit is contained in:
Sam Brannen 2009-07-02 18:02:58 +00:00
parent 0c2fa5208d
commit 0bbca8624f
1 changed files with 23 additions and 19 deletions

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2008 the original author or authors. * Copyright 2002-2009 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -65,11 +65,18 @@ import org.springframework.util.StopWatch;
* @author Rod Johnson * @author Rod Johnson
* @author Juergen Hoeller * @author Juergen Hoeller
* @author Chris Beams * @author Chris Beams
* @author Sam Brannen
*/ */
public final class AspectJAutoProxyCreatorTests { public final class AspectJAutoProxyCreatorTests {
private static final Log factoryLog = LogFactory.getLog(DefaultListableBeanFactory.class); private static final Log factoryLog = LogFactory.getLog(DefaultListableBeanFactory.class);
private static void assertStopWatchTimeLimit(final StopWatch sw, final long maxTimeMillis) {
final long totalTimeMillis = sw.getTotalTimeMillis();
assertTrue("'" + sw.getLastTaskName() + "' took too long: expected less than<" + maxTimeMillis
+ "> ms, actual<" + totalTimeMillis + "> ms.", totalTimeMillis < maxTimeMillis);
}
@Test @Test
public void testAspectsAreApplied() { public void testAspectsAreApplied() {
ClassPathXmlApplicationContext bf = newContext("aspects.xml"); ClassPathXmlApplicationContext bf = newContext("aspects.xml");
@ -110,7 +117,7 @@ public final class AspectJAutoProxyCreatorTests {
} }
ClassPathXmlApplicationContext ac = newContext("aspectsPlusAdvisor.xml"); ClassPathXmlApplicationContext ac = newContext("aspectsPlusAdvisor.xml");
StopWatch sw = new StopWatch(); StopWatch sw = new StopWatch();
sw.start("prototype"); sw.start("Prototype Creation");
for (int i = 0; i < 10000; i++) { for (int i = 0; i < 10000; i++) {
ITestBean shouldBeWeaved = (ITestBean) ac.getBean("adrian2"); ITestBean shouldBeWeaved = (ITestBean) ac.getBean("adrian2");
if (i < 10) { if (i < 10) {
@ -118,11 +125,10 @@ public final class AspectJAutoProxyCreatorTests {
} }
} }
sw.stop(); sw.stop();
long totalTimeMillis = sw.getTotalTimeMillis();
// System.out.println(totalTimeMillis); // What's a reasonable expectation for _any_ server load?
// How was it decided that 4 seconds is a reasonable maximum time? // 4 seconds? 7 seconds?
int maxTimeMillis = 5000; // 4000; assertStopWatchTimeLimit(sw, 7000);
assertTrue("Prototype creation took too long: " + totalTimeMillis, totalTimeMillis < maxTimeMillis);
} }
@Test @Test
@ -133,7 +139,7 @@ public final class AspectJAutoProxyCreatorTests {
} }
ClassPathXmlApplicationContext ac = newContext("aspectsPlusAdvisor.xml"); ClassPathXmlApplicationContext ac = newContext("aspectsPlusAdvisor.xml");
StopWatch sw = new StopWatch(); StopWatch sw = new StopWatch();
sw.start("prototype"); sw.start("Prototype Creation");
for (int i = 0; i < 100000; i++) { for (int i = 0; i < 100000; i++) {
INestedTestBean shouldNotBeWeaved = (INestedTestBean) ac.getBean("i21"); INestedTestBean shouldNotBeWeaved = (INestedTestBean) ac.getBean("i21");
if (i < 10) { if (i < 10) {
@ -141,11 +147,10 @@ public final class AspectJAutoProxyCreatorTests {
} }
} }
sw.stop(); sw.stop();
long totalTimeMillis = sw.getTotalTimeMillis();
// System.out.println(totalTimeMillis); // What's a reasonable expectation for _any_ server load?
// How was it decided that 3 seconds is a reasonable maximum time? // 3 seconds? 7 seconds?
int maxTimeMillis = 3000; assertStopWatchTimeLimit(sw, 3000);
assertTrue("Prototype creation took too long: " + totalTimeMillis, totalTimeMillis < maxTimeMillis);
} }
@Test @Test
@ -161,14 +166,13 @@ public final class AspectJAutoProxyCreatorTests {
ac.registerBeanDefinition("singleton" + i, new RootBeanDefinition(NestedTestBean.class)); ac.registerBeanDefinition("singleton" + i, new RootBeanDefinition(NestedTestBean.class));
} }
StopWatch sw = new StopWatch(); StopWatch sw = new StopWatch();
sw.start("singleton"); sw.start("Singleton Creation");
ac.refresh(); ac.refresh();
sw.stop(); sw.stop();
long totalTimeMillis = sw.getTotalTimeMillis();
// System.out.println(totalTimeMillis); // What's a reasonable expectation for _any_ server load?
// How was it decided that 4 seconds is a reasonable maximum time? // 4 seconds? 7 seconds?
int maxTimeMillis = 5000; // 4000; assertStopWatchTimeLimit(sw, 7000);
assertTrue("Singleton creation took too long: " + totalTimeMillis, totalTimeMillis < maxTimeMillis);
} }
@Test @Test