Search in sources :

Example 1 with PerformanceTest

use of org.apache.sling.performance.annotation.PerformanceTest in project sling by apache.

the class FrameworkPerformanceMethod method invokeExplosively.

@Override
public Object invokeExplosively(Object target, Object... params) throws Throwable {
    // 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());
    }
    // 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) {
        // 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);
        }
    }
    // testMethodToInvoke.getName());
    if (runinvocations != 0) {
        // 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);
        }
    }
    // 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);
    }
    // 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;
}
Also used : DescriptiveStatistics(org.apache.commons.math.stat.descriptive.DescriptiveStatistics) FrameworkMethod(org.junit.runners.model.FrameworkMethod) Method(java.lang.reflect.Method) PerformanceTest(org.apache.sling.performance.annotation.PerformanceTest)

Example 2 with PerformanceTest

use of org.apache.sling.performance.annotation.PerformanceTest in project sling by apache.

the class ResolveNonExistingWithManyAliasTest method runTest.

@PerformanceTest
public void runTest() throws Exception {
    String path = ResourceUtil.normalize(ResourceUtil.getParent(rootPath) + "/" + "testNonExistingAlias" + ".print.html");
    HttpServletRequest request = new ResourceResolverTestRequest(path);
    Resource res = resResolver.resolve(request, path);
    Assert.assertNotNull(res);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) Resource(org.apache.sling.api.resource.Resource) ResourceResolverTestRequest(org.apache.sling.performance.ResourceResolverTestRequest) PerformanceTest(org.apache.sling.performance.annotation.PerformanceTest)

Example 3 with PerformanceTest

use of org.apache.sling.performance.annotation.PerformanceTest in project sling by apache.

the class ResolveNonExistingWithManyVanityPathTest method runTest.

@PerformanceTest
public void runTest() throws Exception {
    String path = ResourceUtil.normalize(ResourceUtil.getParent(rootPath) + "/" + "testNonExistingVanity" + ".print.html");
    HttpServletRequest request = new ResourceResolverTestRequest(path);
    Resource res = resResolver.resolve(request, path);
    Assert.assertNotNull(res);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) Resource(org.apache.sling.api.resource.Resource) ResourceResolverTestRequest(org.apache.sling.performance.ResourceResolverTestRequest) PerformanceTest(org.apache.sling.performance.annotation.PerformanceTest)

Aggregations

PerformanceTest (org.apache.sling.performance.annotation.PerformanceTest)3 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 Resource (org.apache.sling.api.resource.Resource)2 ResourceResolverTestRequest (org.apache.sling.performance.ResourceResolverTestRequest)2 Method (java.lang.reflect.Method)1 DescriptiveStatistics (org.apache.commons.math.stat.descriptive.DescriptiveStatistics)1 FrameworkMethod (org.junit.runners.model.FrameworkMethod)1