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 384edbc1536dbdb210a7624cee7863e3aa7144aa Author: Antonio Sanso <[email protected]> AuthorDate: Wed Oct 3 11:29:19 2012 +0000 SLING-2593 - Improvement for the Sling performance tools. Removed XML Report type since is not implemented. Changed getenv with getProperty. Removed 2 unused classes (AbstractPerformanceTest, AbstractTest) git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/performance/base@1393426 13f79535-47bb-0310-9956-ffa450edef68 --- .../sling/performance/AbstractPerformanceTest.java | 91 -------------- .../org/apache/sling/performance/AbstractTest.java | 134 --------------------- .../org/apache/sling/performance/ReportLogger.java | 8 +- 3 files changed, 3 insertions(+), 230 deletions(-) diff --git a/src/main/java/org/apache/sling/performance/AbstractPerformanceTest.java b/src/main/java/org/apache/sling/performance/AbstractPerformanceTest.java deleted file mode 100644 index 1540cf7..0000000 --- a/src/main/java/org/apache/sling/performance/AbstractPerformanceTest.java +++ /dev/null @@ -1,91 +0,0 @@ -/* - * 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; - -import java.io.File; -import java.io.IOException; -import java.io.PrintWriter; -import java.util.List; -import junit.framework.TestCase; -import org.apache.commons.io.output.FileWriterWithEncoding; -import org.apache.commons.math.stat.descriptive.DescriptiveStatistics; - -public abstract class AbstractPerformanceTest extends TestCase { - - private final int runtime = 5; - - private final int warmup = 1; - - private void runTest(String name, AbstractTest test) throws Exception { - DescriptiveStatistics statistics = new DescriptiveStatistics(); - - test.setUp(); - try { - // Run a few iterations to warm up the system - long warmupEnd = System.currentTimeMillis() + warmup * 1000; - while (System.currentTimeMillis() < warmupEnd) { - test.execute(); - } - - // Run test iterations, and capture the execution times - long runtimeEnd = System.currentTimeMillis() + runtime * 1000; - while (System.currentTimeMillis() < runtimeEnd) { - statistics.addValue(test.execute()); - } - } finally { - test.tearDown(); - } - - if (statistics.getN() > 0) { - writeReport(test.toString(), name, statistics); - } - } - - protected void testPerformance(String name, List <AbstractTest> tests) throws Exception { - for (AbstractTest test:tests){ - runTest(name,test); - } - } - - private void writeReport(String test, String name, DescriptiveStatistics statistics) - throws IOException { - File report = new File("target", test + ".txt"); - - boolean needsPrefix = !report.exists(); - PrintWriter writer = new PrintWriter( - new FileWriterWithEncoding(report, "UTF-8", true)); - try { - if (needsPrefix) { - writer.format( - "# %-34.34s min 10%% 50%% 90%% max%n", - test); - } - - writer.format( - "%-36.36s %6.0f %6.0f %6.0f %6.0f %6.0f%n", - name, - statistics.getMin(), - statistics.getPercentile(10.0), - statistics.getPercentile(50.0), - statistics.getPercentile(90.0), - statistics.getMax()); - } finally { - writer.close(); - } - } - -} diff --git a/src/main/java/org/apache/sling/performance/AbstractTest.java b/src/main/java/org/apache/sling/performance/AbstractTest.java deleted file mode 100644 index 7cdaca2..0000000 --- a/src/main/java/org/apache/sling/performance/AbstractTest.java +++ /dev/null @@ -1,134 +0,0 @@ -/* - * 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; - -import java.util.LinkedList; -import java.util.List; - -/** - * Abstract base class for individual performance benchmarks. - */ -public abstract class AbstractTest { - - protected static int getScale(int def) { - int scale = Integer.getInteger("scale", 0); - if (scale == 0) { - scale = def; - } - return scale; - } - - private volatile boolean running; - - private List<Thread> threads; - - /** - * Adds a background thread that repeatedly executes the given job - * until all the iterations of this test have been executed. - * - * @param job background job - */ - protected void addBackgroundJob(final Runnable job) { - Thread thread = new Thread() { - @Override - public void run() { - while (running) { - job.run(); - } - } - }; - thread.start(); - threads.add(thread); - } - - /** - * Run after all iterations of this test have been executed. Subclasses can - * override this method to clean up static test content. - * - * @throws Exception if an error occurs - */ - protected void afterSuite() throws Exception { - } - - protected void afterTest() throws Exception { - } - - - /** - * Run before any iterations of this test get executed. Subclasses can - * override this method to set up static test content. - * - * @throws Exception if an error occurs - */ - protected void beforeSuite() throws Exception { - } - - protected void beforeTest() throws Exception { - } - - /** - * Executes a single iteration of this test. - * - * @return number of milliseconds spent in this iteration - * @throws Exception if an error occurs - */ - public long execute() throws Exception { - beforeTest(); - try { - long start = System.currentTimeMillis(); - runTest(); - return System.currentTimeMillis() - start; - } finally { - afterTest(); - } - } - - protected abstract void runTest() throws Exception; - - /** - * Prepares this performance benchmark. - * - * @param repository the repository to use - * @param credentials credentials of a user with write access - * @throws Exception if the benchmark can not be prepared - */ - public void setUp() - throws Exception { - this.threads = new LinkedList<Thread>(); - this.running = true; - beforeSuite(); - } - - /** - * Cleans up after this performance benchmark. - * - * @throws Exception if the benchmark can not be cleaned up - */ - public void tearDown() throws Exception { - this.running = false; - for (Thread thread : threads) { - thread.join(); - } - afterSuite(); - this.threads = null; - } - - public String toString() { - String name = getClass().getName(); - return name.substring(name.lastIndexOf('.') + 1); - } - } diff --git a/src/main/java/org/apache/sling/performance/ReportLogger.java b/src/main/java/org/apache/sling/performance/ReportLogger.java index f0822f1..d43f455 100644 --- a/src/main/java/org/apache/sling/performance/ReportLogger.java +++ b/src/main/java/org/apache/sling/performance/ReportLogger.java @@ -13,7 +13,7 @@ import org.apache.commons.math.stat.descriptive.DescriptiveStatistics; public class ReportLogger { public enum ReportType { - TXT, XML + TXT } public static void writeReport(String test, String testSuiteName, @@ -23,8 +23,6 @@ public class ReportLogger { case TXT: writeReportTxt(test, testSuiteName, name, statistics); break; - case XML: - throw new Exception("The XML reporting format is not yet supported"); default: throw new Exception( "The specified reporting format is not yet supported"); @@ -60,8 +58,8 @@ public class ReportLogger { // useful if we run the test cases from the command line for example // by using maven if (testSuiteName.equals(ParameterizedTestList.TEST_CASE_ONLY)) { - if (System.getenv("testsuitename") != null) { - testSuiteName = System.getenv("testsuitename"); + if (System.getProperty("testsuitename") != null) { + testSuiteName = System.getProperty("testsuitename"); } } -- To stop receiving notification emails like this one, please contact "[email protected]" <[email protected]>.
