You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by bd...@apache.org on 2014/06/27 15:40:59 UTC

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...

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));
+    }
+}