Return-Path: X-Original-To: apmail-sling-commits-archive@www.apache.org Delivered-To: apmail-sling-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 67F5311E37 for ; Fri, 27 Jun 2014 13:41:21 +0000 (UTC) Received: (qmail 97665 invoked by uid 500); 27 Jun 2014 13:41:21 -0000 Delivered-To: apmail-sling-commits-archive@sling.apache.org Received: (qmail 97604 invoked by uid 500); 27 Jun 2014 13:41:21 -0000 Mailing-List: contact commits-help@sling.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@sling.apache.org Delivered-To: mailing list commits@sling.apache.org Received: (qmail 97595 invoked by uid 99); 27 Jun 2014 13:41:21 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 27 Jun 2014 13:41:21 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 27 Jun 2014 13:41:19 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id C830E23889E1; Fri, 27 Jun 2014 13:40:59 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1606095 - in /sling/trunk/performance/base/src: main/java/org/apache/sling/performance/ test/ test/java/ test/java/org/ test/java/org/apache/ test/java/org/apache/sling/ test/java/org/apache/sling/performance/ test/java/org/apache/sling/pe... Date: Fri, 27 Jun 2014 13:40:59 -0000 To: commits@sling.apache.org From: bdelacretaz@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20140627134059.C830E23889E1@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: bdelacretaz Date: Fri Jun 27 13:40:59 2014 New Revision: 1606095 URL: http://svn.apache.org/r1606095 Log: Add some simple performance test examples Added: sling/trunk/performance/base/src/test/ sling/trunk/performance/base/src/test/java/ sling/trunk/performance/base/src/test/java/org/ sling/trunk/performance/base/src/test/java/org/apache/ sling/trunk/performance/base/src/test/java/org/apache/sling/ sling/trunk/performance/base/src/test/java/org/apache/sling/performance/ sling/trunk/performance/base/src/test/java/org/apache/sling/performance/samples/ sling/trunk/performance/base/src/test/java/org/apache/sling/performance/samples/SimplePerformanceTest.java sling/trunk/performance/base/src/test/java/org/apache/sling/performance/samples/WithParametersTest.java Modified: sling/trunk/performance/base/src/main/java/org/apache/sling/performance/ReportLogger.java Modified: sling/trunk/performance/base/src/main/java/org/apache/sling/performance/ReportLogger.java URL: http://svn.apache.org/viewvc/sling/trunk/performance/base/src/main/java/org/apache/sling/performance/ReportLogger.java?rev=1606095&r1=1606094&r2=1606095&view=diff ============================================================================== --- sling/trunk/performance/base/src/main/java/org/apache/sling/performance/ReportLogger.java (original) +++ sling/trunk/performance/base/src/main/java/org/apache/sling/performance/ReportLogger.java Fri Jun 27 13:40:59 2014 @@ -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 Added: sling/trunk/performance/base/src/test/java/org/apache/sling/performance/samples/SimplePerformanceTest.java URL: http://svn.apache.org/viewvc/sling/trunk/performance/base/src/test/java/org/apache/sling/performance/samples/SimplePerformanceTest.java?rev=1606095&view=auto ============================================================================== --- sling/trunk/performance/base/src/test/java/org/apache/sling/performance/samples/SimplePerformanceTest.java (added) +++ sling/trunk/performance/base/src/test/java/org/apache/sling/performance/samples/SimplePerformanceTest.java Fri Jun 27 13:40:59 2014 @@ -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)); + } +} Added: sling/trunk/performance/base/src/test/java/org/apache/sling/performance/samples/WithParametersTest.java URL: http://svn.apache.org/viewvc/sling/trunk/performance/base/src/test/java/org/apache/sling/performance/samples/WithParametersTest.java?rev=1606095&view=auto ============================================================================== --- sling/trunk/performance/base/src/test/java/org/apache/sling/performance/samples/WithParametersTest.java (added) +++ sling/trunk/performance/base/src/test/java/org/apache/sling/performance/samples/WithParametersTest.java Fri Jun 27 13:40:59 2014 @@ -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)); + } +}