in base/src/main/java/org/apache/sling/performance/FrameworkPerformanceMethod.java [68:219]
public Object invokeExplosively(Object target, Object... params)
throws Throwable {
// Executes the test method on the supplied target
// Check if this is the first test running from this specific
// PerformanceSuite
// and run the BeforeSuite methods
if ((performanceSuiteState != null)
&& (performanceSuiteState.getBeforeSuiteMethod() != null)
&& (performanceSuiteState.getTargetObjectSuite() != null)
&& (performanceSuiteState.getNumberOfExecutedMethods() == 0)
&& !performanceSuiteState.testSuiteName
.equals(ParameterizedTestList.TEST_CASE_ONLY)) {
performanceSuiteState.getBeforeSuiteMethod().invoke(
performanceSuiteState.getTargetObjectSuite());
}
// In case of a PerformanceSuite we need to run the methods annotated
// with Before and After
// ourselves as JUnit can't find them (JUnit is looking for them in the
// test suite class);
// in case we don't have to deal with a PerformanceSuite just skip this
// as JUnit will run the methods itself
if ((performanceSuiteState != null)
&& !performanceSuiteState.testSuiteName.equals(ParameterizedTestList.TEST_CASE_ONLY)) {
recursiveCallSpecificMethod(this.target.getClass(), this.target, Before.class);
}
// Need to count the number of tests run from the PerformanceSuite
// so that we can call the AfterSuite method after the last test from
// the suite
// has run and the AfterSuite needs to run
performanceSuiteState.incrementNumberOfExecutedTestMethods();
Object response = null;
Method testMethodToInvoke = this.getMethod();
PerformanceTest performanceAnnotation = testMethodToInvoke
.getAnnotation(PerformanceTest.class);
// retrieve the test configuration options
int warmuptime = performanceAnnotation.warmuptime();
int runtime = performanceAnnotation.runtime();
int warmupinvocations = performanceAnnotation.warmupinvocations();
int runinvocations = performanceAnnotation.runinvocations();
double threshold = performanceAnnotation.threshold();
DescriptiveStatistics statistics = new DescriptiveStatistics();
if (warmupinvocations != 0) {
// Run the number of invocation specified in the annotation
// for warming up the system
for (int invocationIndex = 0; invocationIndex < warmupinvocations; invocationIndex++) {
recursiveCallSpecificMethod(this.target.getClass(), this.target, BeforeMethodInvocation.class);
// TODO: implement the method to run a before a specific test
// method
// recursiveCallSpecificMethod(this.target.getClass(),
// this.target, BeforeSpecificTest.class);
response = super.invokeExplosively(this.target, params);
// TODO: implement the method to run a after a specific test
// method
// recursiveCallSpecificMethod(this.target.getClass(),
// this.target, AfterSpecificTest.class);
recursiveCallSpecificMethod(this.target.getClass(),
this.target, AfterMethodInvocation.class);
}
} else {
// Run a few iterations to warm up the system
long warmupEnd = System.currentTimeMillis() + warmuptime * 1000;
while (System.currentTimeMillis() < warmupEnd) {
recursiveCallSpecificMethod(this.target.getClass(),
this.target, BeforeMethodInvocation.class);
// TODO: implement the method to run a before a specific test
// method
// recursiveCallSpecificMethod(this.target.getClass(),
// this.target, BeforeSpecificTest.class);
response = super.invokeExplosively(this.target, params);
// recursiveCallSpecificMethod(this.target.getClass(),
// this.target, AfterSpecificTest.class);
// TODO: implement the method to run a after a specific test
// method
recursiveCallSpecificMethod(this.target.getClass(),
this.target, AfterMethodInvocation.class);
}
}
// System.out.println("Warmup ended - test :" +
// testMethodToInvoke.getName());
if (runinvocations != 0) {
// Run the specified number of iterations and capture the execution
// times
for (int invocationIndex = 0; invocationIndex < runinvocations; invocationIndex++) {
response = this.invokeTimedTestMethod(testMethodToInvoke,
statistics, params);
}
} else {
// Run test iterations and capture the execution times
long runtimeEnd = System.currentTimeMillis() + runtime * 1000;
while (System.currentTimeMillis() < runtimeEnd) {
response = this.invokeTimedTestMethod(testMethodToInvoke,
statistics, params);
}
}
if (statistics.getN() > 0) {
if (referenceMethod == null) {
ReportLogger.writeReport(this.performanceSuiteState.testSuiteName, testCaseName, className, getMethod().getName(),
statistics, ReportLogger.ReportType.TXT, reportLevel);
} else {
ReportLogger reportLogger = ReportLogger.getOrCreate(this.performanceSuiteState.testSuiteName, testCaseName, getMethod().getDeclaringClass().getName(), referenceMethod);
reportLogger.recordStatistics(getMethod().getName(), statistics, threshold);
}
}
// In case of a PerformanceSuite we need to run the methods annotated
// with Before and After
// ourselves as JUnit can't find them; in case we don't have to deal
// with a PerformanceSuite
// just skip this as JUnit will run the methods itself
if ((performanceSuiteState != null)
&& !performanceSuiteState.testSuiteName.equals(ParameterizedTestList.TEST_CASE_ONLY)) {
recursiveCallSpecificMethod(this.target.getClass(), this.target, After.class);
}
// Check if this is the last test running from a PerformanceSuite
// and run the AfterSuite method
if ((performanceSuiteState != null)
&& (performanceSuiteState.getAfterSuiteMethod() != null)
&& (performanceSuiteState.getTargetObjectSuite() != null)
&& (performanceSuiteState.getNumberOfExecutedMethods() == performanceSuiteState.getNumberOfMethodsInSuite())
&& !performanceSuiteState.testSuiteName.equals(ParameterizedTestList.TEST_CASE_ONLY)) {
performanceSuiteState.getAfterSuiteMethod().invoke(performanceSuiteState.getTargetObjectSuite());
}
return response;
}