This is an automated email from the ASF dual-hosted git repository. rombert pushed a commit to annotated tag org.apache.sling.performance.base-0.0.2 in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-performance.git
commit 19f3f8444599d06b888b292d0fb307d08bc7ca01 Author: Bertrand Delacretaz <[email protected]> AuthorDate: Fri Jun 27 13:40:59 2014 +0000 Add some simple performance test examples git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/performance/base@1606095 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/sling/performance/ReportLogger.java | 21 ++++++++++-- .../performance/samples/SimplePerformanceTest.java | 37 ++++++++++++++++++++ .../performance/samples/WithParametersTest.java | 39 ++++++++++++++++++++++ 3 files changed, 94 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/apache/sling/performance/ReportLogger.java b/src/main/java/org/apache/sling/performance/ReportLogger.java index aea8bfc..6e3161e 100644 --- a/src/main/java/org/apache/sling/performance/ReportLogger.java +++ b/src/main/java/org/apache/sling/performance/ReportLogger.java @@ -9,9 +9,14 @@ import java.util.Date; import org.apache.commons.io.output.FileWriterWithEncoding; import org.apache.commons.math.stat.descriptive.DescriptiveStatistics; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class ReportLogger { + private static boolean reportFolderLogged = false; + private static final Logger logger = LoggerFactory.getLogger(ReportLogger.class); + public static final String REPORTS_DIR = "performance-reports"; public enum ReportType { @@ -93,7 +98,7 @@ public class ReportLogger { private static void writeReportClassLevel(String resultFileName, String testSuiteName, DescriptiveStatistics statistics) throws IOException { - File report = new File("target/" + REPORTS_DIR, resultFileName + ".txt"); + File report = getReportFile(resultFileName, ".txt"); boolean needsPrefix = !report.exists(); PrintWriter writer = new PrintWriter( new FileWriterWithEncoding(report, "UTF-8", true)); @@ -129,7 +134,7 @@ public class ReportLogger { */ private static void writeReportMethodLevel(String resultFileName, String testSuiteName, String testCaseName, String className, String methodName, DescriptiveStatistics statistics) throws IOException { - File report = new File("target/" + REPORTS_DIR, resultFileName + ".txt"); + File report = getReportFile(resultFileName, ".txt"); boolean needsPrefix = !report.exists(); PrintWriter writer = new PrintWriter( @@ -171,5 +176,15 @@ public class ReportLogger { return dateFormat.format(date); } + + private static File getReportFile(String resultFileName, String extension) { + final String folder = "target/" + REPORTS_DIR; + final String filename = resultFileName + extension; + if(!reportFolderLogged) { + logger.info("Writing performance test results under {}", folder); + reportFolderLogged = true; + } + return new File(folder, filename); + } -} +} \ No newline at end of file diff --git a/src/test/java/org/apache/sling/performance/samples/SimplePerformanceTest.java b/src/test/java/org/apache/sling/performance/samples/SimplePerformanceTest.java new file mode 100644 index 0000000..2f8efdc --- /dev/null +++ b/src/test/java/org/apache/sling/performance/samples/SimplePerformanceTest.java @@ -0,0 +1,37 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.sling.performance.samples; + +import org.apache.sling.performance.PerformanceRunner; +import org.apache.sling.performance.annotation.PerformanceTest; +import org.junit.Test; +import org.junit.runner.RunWith; + +/** Simple performance test example */ +@RunWith(PerformanceRunner.class) +public class SimplePerformanceTest { + + @Test + public void notPerformanceTest() throws InterruptedException { + Thread.sleep((long)(Math.random() * 10)); + } + + @PerformanceTest + public void randomDurationPerformanceTest() throws InterruptedException { + Thread.sleep((long)(Math.random() * 12)); + } +} diff --git a/src/test/java/org/apache/sling/performance/samples/WithParametersTest.java b/src/test/java/org/apache/sling/performance/samples/WithParametersTest.java new file mode 100644 index 0000000..8311281 --- /dev/null +++ b/src/test/java/org/apache/sling/performance/samples/WithParametersTest.java @@ -0,0 +1,39 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.sling.performance.samples; + +import org.apache.sling.performance.PerformanceRunner; +import org.apache.sling.performance.PerformanceRunner.Parameters; +import org.apache.sling.performance.PerformanceRunner.ReportLevel; +import org.apache.sling.performance.annotation.PerformanceTest; +import org.junit.runner.RunWith; + +/** Demonstrate the Parameters annotation */ +@RunWith(PerformanceRunner.class) +@Parameters(reportLevel=ReportLevel.MethodLevel) +public class WithParametersTest { + + @PerformanceTest + public void PerformanceTestA() throws InterruptedException { + Thread.sleep((long)(Math.random() * 13)); + } + + @PerformanceTest(warmuptime=0,runinvocations=5) + public void PerformanceTestB() throws InterruptedException { + Thread.sleep((long)(Math.random() * 11)); + } +} -- To stop receiving notification emails like this one, please contact "[email protected]" <[email protected]>.
