Add some simple performance test examples

git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1606095 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/base/src/main/java/org/apache/sling/performance/ReportLogger.java b/base/src/main/java/org/apache/sling/performance/ReportLogger.java
index aea8bfc..6e3161e 100644
--- a/base/src/main/java/org/apache/sling/performance/ReportLogger.java
+++ b/base/src/main/java/org/apache/sling/performance/ReportLogger.java
@@ -9,9 +9,14 @@
 
 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 @@
     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 @@
      */
     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 @@
 
 		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/base/src/test/java/org/apache/sling/performance/samples/SimplePerformanceTest.java b/base/src/test/java/org/apache/sling/performance/samples/SimplePerformanceTest.java
new file mode 100644
index 0000000..2f8efdc
--- /dev/null
+++ b/base/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/base/src/test/java/org/apache/sling/performance/samples/WithParametersTest.java b/base/src/test/java/org/apache/sling/performance/samples/WithParametersTest.java
new file mode 100644
index 0000000..8311281
--- /dev/null
+++ b/base/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));
+    }
+}