sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bdelacre...@apache.org
Subject svn commit: r1610715 [1/2] - in /sling/trunk/testing/junit/performance/src: main/java/org/apache/sling/junit/performance/impl/ main/java/org/apache/sling/junit/performance/runner/ test/java/org/apache/sling/junit/performance/runner/
Date Tue, 15 Jul 2014 14:27:08 GMT
Author: bdelacretaz
Date: Tue Jul 15 14:27:08 2014
New Revision: 1610715

URL: http://svn.apache.org/r1610715
Log:
SLING-3762 - add annotations support to PerformanceRunner. Contributed by Francesco Mari, thanks!

Added:
    sling/trunk/testing/junit/performance/src/main/java/org/apache/sling/junit/performance/impl/RunAfters.java
    sling/trunk/testing/junit/performance/src/main/java/org/apache/sling/junit/performance/impl/RunBefores.java
    sling/trunk/testing/junit/performance/src/main/java/org/apache/sling/junit/performance/impl/RunExecutionFinishedEvents.java
    sling/trunk/testing/junit/performance/src/main/java/org/apache/sling/junit/performance/impl/RunExecutionIterationFinishedEvents.java
    sling/trunk/testing/junit/performance/src/main/java/org/apache/sling/junit/performance/impl/RunExecutionIterationStartedEvents.java
    sling/trunk/testing/junit/performance/src/main/java/org/apache/sling/junit/performance/impl/RunExecutionStartedEvents.java
    sling/trunk/testing/junit/performance/src/main/java/org/apache/sling/junit/performance/impl/RunIterations.java
    sling/trunk/testing/junit/performance/src/main/java/org/apache/sling/junit/performance/impl/RunSerial.java
    sling/trunk/testing/junit/performance/src/main/java/org/apache/sling/junit/performance/impl/RunWarmUpFinishedEvents.java
    sling/trunk/testing/junit/performance/src/main/java/org/apache/sling/junit/performance/impl/RunWarmUpIterationFinishedEvents.java
    sling/trunk/testing/junit/performance/src/main/java/org/apache/sling/junit/performance/impl/RunWarmUpIterationStartedEvents.java
    sling/trunk/testing/junit/performance/src/main/java/org/apache/sling/junit/performance/impl/RunWarmUpStartedEvents.java
    sling/trunk/testing/junit/performance/src/main/java/org/apache/sling/junit/performance/runner/AfterPerformanceIteration.java
    sling/trunk/testing/junit/performance/src/main/java/org/apache/sling/junit/performance/runner/AfterPerformanceTest.java
    sling/trunk/testing/junit/performance/src/main/java/org/apache/sling/junit/performance/runner/AfterWarmUp.java
    sling/trunk/testing/junit/performance/src/main/java/org/apache/sling/junit/performance/runner/AfterWarmUpIteration.java
    sling/trunk/testing/junit/performance/src/main/java/org/apache/sling/junit/performance/runner/BeforePerformanceIteration.java
    sling/trunk/testing/junit/performance/src/main/java/org/apache/sling/junit/performance/runner/BeforePerformanceTest.java
    sling/trunk/testing/junit/performance/src/main/java/org/apache/sling/junit/performance/runner/BeforeWarmUp.java
    sling/trunk/testing/junit/performance/src/main/java/org/apache/sling/junit/performance/runner/BeforeWarmUpIteration.java
    sling/trunk/testing/junit/performance/src/test/java/org/apache/sling/junit/performance/runner/PerformanceRunnerDynamicsTest.java
Removed:
    sling/trunk/testing/junit/performance/src/main/java/org/apache/sling/junit/performance/impl/InvokePerformanceBlock.java
    sling/trunk/testing/junit/performance/src/main/java/org/apache/sling/junit/performance/impl/InvokePerformanceMethod.java
    sling/trunk/testing/junit/performance/src/main/java/org/apache/sling/junit/performance/impl/PerformanceMethod.java
Modified:
    sling/trunk/testing/junit/performance/src/main/java/org/apache/sling/junit/performance/impl/Listeners.java
    sling/trunk/testing/junit/performance/src/main/java/org/apache/sling/junit/performance/runner/PerformanceRunner.java
    sling/trunk/testing/junit/performance/src/test/java/org/apache/sling/junit/performance/runner/PerformanceRunnerTest.java

Modified: sling/trunk/testing/junit/performance/src/main/java/org/apache/sling/junit/performance/impl/Listeners.java
URL: http://svn.apache.org/viewvc/sling/trunk/testing/junit/performance/src/main/java/org/apache/sling/junit/performance/impl/Listeners.java?rev=1610715&r1=1610714&r2=1610715&view=diff
==============================================================================
--- sling/trunk/testing/junit/performance/src/main/java/org/apache/sling/junit/performance/impl/Listeners.java (original)
+++ sling/trunk/testing/junit/performance/src/main/java/org/apache/sling/junit/performance/impl/Listeners.java Tue Jul 15 14:27:08 2014
@@ -19,12 +19,11 @@ package org.apache.sling.junit.performan
 
 import org.apache.sling.junit.performance.runner.Listener;
 
+import java.util.ArrayList;
 import java.util.List;
 
 public class Listeners {
 
-    private boolean isWarmUp;
-
     private final List<Listener> listeners;
 
     public Listeners(List<Listener> listeners) {
@@ -37,17 +36,22 @@ public class Listeners {
 
     }
 
-    private void invoke(Invoker invoker) throws Exception {
+    private List<Throwable> invoke(Invoker invoker) {
+        List<Throwable> errors = new ArrayList<Throwable>();
+
         for (Listener listener : listeners) {
-            invoker.invoke(listener);
+            try {
+                invoker.invoke(listener);
+            } catch (Throwable t) {
+                errors.add(t);
+            }
         }
 
+        return errors;
     }
 
-    public void warmUpStarted(final String className, final String testName) throws Exception {
-        isWarmUp = true;
-
-        invoke(new Invoker() {
+    public List<Throwable> warmUpStarted(final String className, final String testName) {
+        return invoke(new Invoker() {
 
             public void invoke(Listener listener) throws Exception {
                 listener.warmUpStarted(className, testName);
@@ -56,10 +60,8 @@ public class Listeners {
         });
     }
 
-    public void warmUpFinished(final String className, final String testName) throws Exception {
-        isWarmUp = false;
-
-        invoke(new Invoker() {
+    public List<Throwable> warmUpFinished(final String className, final String testName) {
+        return invoke(new Invoker() {
 
             public void invoke(Listener listener) throws Exception {
                 listener.warmUpFinished(className, testName);
@@ -68,8 +70,8 @@ public class Listeners {
         });
     }
 
-    public void executionStarted(final String className, final String testName) throws Exception {
-        invoke(new Invoker() {
+    public List<Throwable> executionStarted(final String className, final String testName) {
+        return invoke(new Invoker() {
 
             public void invoke(Listener listener) throws Exception {
                 listener.executionStarted(className, testName);
@@ -78,8 +80,8 @@ public class Listeners {
         });
     }
 
-    public void executionFinished(final String className, final String testName) throws Exception {
-        invoke(new Invoker() {
+    public List<Throwable> executionFinished(final String className, final String testName) {
+        return invoke(new Invoker() {
 
             public void invoke(Listener listener) throws Exception {
                 listener.executionFinished(className, testName);
@@ -88,29 +90,41 @@ public class Listeners {
         });
     }
 
-    public void iterationStarted(final String className, final String testName) throws Exception {
-        invoke(new Invoker() {
+    public List<Throwable> warmUpIterationStarted(final String className, final String testName) {
+        return invoke(new Invoker() {
+
+            public void invoke(Listener listener) throws Exception {
+                listener.warmUpIterationStarted(className, testName);
+            }
+
+        });
+    }
+
+    public List<Throwable> warmUpIterationFinished(final String className, final String testName) {
+        return invoke(new Invoker() {
+
+            public void invoke(Listener listener) throws Exception {
+                listener.warmUpIterationFinished(className, testName);
+            }
+
+        });
+    }
+
+    public List<Throwable> executionIterationStarted(final String className, final String testName) {
+        return invoke(new Invoker() {
 
             public void invoke(Listener listener) throws Exception {
-                if (isWarmUp) {
-                    listener.warmUpIterationStarted(className, testName);
-                } else {
-                    listener.executionIterationStarted(className, testName);
-                }
+                listener.executionIterationStarted(className, testName);
             }
 
         });
     }
 
-    public void iterationFinished(final String className, final String testName) throws Exception {
-        invoke(new Invoker() {
+    public List<Throwable> executionIterationFinished(final String className, final String testName) {
+        return invoke(new Invoker() {
 
             public void invoke(Listener listener) throws Exception {
-                if (isWarmUp) {
-                    listener.warmUpIterationFinished(className, testName);
-                } else {
-                    listener.executionIterationFinished(className, testName);
-                }
+                listener.executionIterationFinished(className, testName);
             }
 
         });

Added: sling/trunk/testing/junit/performance/src/main/java/org/apache/sling/junit/performance/impl/RunAfters.java
URL: http://svn.apache.org/viewvc/sling/trunk/testing/junit/performance/src/main/java/org/apache/sling/junit/performance/impl/RunAfters.java?rev=1610715&view=auto
==============================================================================
--- sling/trunk/testing/junit/performance/src/main/java/org/apache/sling/junit/performance/impl/RunAfters.java (added)
+++ sling/trunk/testing/junit/performance/src/main/java/org/apache/sling/junit/performance/impl/RunAfters.java Tue Jul 15 14:27:08 2014
@@ -0,0 +1,62 @@
+/*
+ * 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.junit.performance.impl;
+
+import org.junit.runners.model.FrameworkMethod;
+import org.junit.runners.model.MultipleFailureException;
+import org.junit.runners.model.Statement;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class RunAfters extends Statement {
+
+    private final Statement next;
+
+    private final Object target;
+
+    private final List<FrameworkMethod> afters;
+
+    public RunAfters(Statement next, List<FrameworkMethod> afters, Object target) {
+        this.next = next;
+        this.afters = afters;
+        this.target = target;
+    }
+
+    @Override
+    public void evaluate() throws Throwable {
+        List<Throwable> errors = new ArrayList<Throwable>();
+
+        try {
+            next.evaluate();
+        } catch (Throwable e) {
+            errors.add(e);
+        } finally {
+            for (FrameworkMethod each : afters) {
+                try {
+                    each.invokeExplosively(target);
+                } catch (Throwable e) {
+                    errors.add(e);
+                }
+            }
+        }
+
+        MultipleFailureException.assertEmpty(errors);
+    }
+
+}
\ No newline at end of file

Added: sling/trunk/testing/junit/performance/src/main/java/org/apache/sling/junit/performance/impl/RunBefores.java
URL: http://svn.apache.org/viewvc/sling/trunk/testing/junit/performance/src/main/java/org/apache/sling/junit/performance/impl/RunBefores.java?rev=1610715&view=auto
==============================================================================
--- sling/trunk/testing/junit/performance/src/main/java/org/apache/sling/junit/performance/impl/RunBefores.java (added)
+++ sling/trunk/testing/junit/performance/src/main/java/org/apache/sling/junit/performance/impl/RunBefores.java Tue Jul 15 14:27:08 2014
@@ -0,0 +1,48 @@
+/*
+ * 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.junit.performance.impl;
+
+import org.junit.runners.model.FrameworkMethod;
+import org.junit.runners.model.Statement;
+
+import java.util.List;
+
+public class RunBefores extends Statement {
+
+    private final Statement next;
+
+    private final Object target;
+
+    private final List<FrameworkMethod> befores;
+
+    public RunBefores(Statement next, List<FrameworkMethod> befores, Object target) {
+        this.next = next;
+        this.befores = befores;
+        this.target = target;
+    }
+
+    @Override
+    public void evaluate() throws Throwable {
+        for (FrameworkMethod before : befores) {
+            before.invokeExplosively(target);
+        }
+
+        next.evaluate();
+    }
+
+}

Added: sling/trunk/testing/junit/performance/src/main/java/org/apache/sling/junit/performance/impl/RunExecutionFinishedEvents.java
URL: http://svn.apache.org/viewvc/sling/trunk/testing/junit/performance/src/main/java/org/apache/sling/junit/performance/impl/RunExecutionFinishedEvents.java?rev=1610715&view=auto
==============================================================================
--- sling/trunk/testing/junit/performance/src/main/java/org/apache/sling/junit/performance/impl/RunExecutionFinishedEvents.java (added)
+++ sling/trunk/testing/junit/performance/src/main/java/org/apache/sling/junit/performance/impl/RunExecutionFinishedEvents.java Tue Jul 15 14:27:08 2014
@@ -0,0 +1,60 @@
+/*
+ * 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.junit.performance.impl;
+
+import org.junit.runners.model.FrameworkMethod;
+import org.junit.runners.model.MultipleFailureException;
+import org.junit.runners.model.Statement;
+import org.junit.runners.model.TestClass;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class RunExecutionFinishedEvents extends Statement {
+
+    private final Listeners listeners;
+
+    private final TestClass test;
+
+    private final FrameworkMethod method;
+
+    private final Statement statement;
+
+    public RunExecutionFinishedEvents(Listeners listeners, TestClass test, FrameworkMethod method, Statement statement) {
+        this.listeners = listeners;
+        this.test = test;
+        this.method = method;
+        this.statement = statement;
+    }
+
+    @Override
+    public void evaluate() throws Throwable {
+        List<Throwable> errors = new ArrayList<Throwable>();
+
+        try {
+            statement.evaluate();
+        } catch (Throwable t) {
+            errors.add(t);
+        } finally {
+            errors.addAll(listeners.executionFinished(test.getName(), method.getName()));
+        }
+
+        MultipleFailureException.assertEmpty(errors);
+    }
+
+}

Added: sling/trunk/testing/junit/performance/src/main/java/org/apache/sling/junit/performance/impl/RunExecutionIterationFinishedEvents.java
URL: http://svn.apache.org/viewvc/sling/trunk/testing/junit/performance/src/main/java/org/apache/sling/junit/performance/impl/RunExecutionIterationFinishedEvents.java?rev=1610715&view=auto
==============================================================================
--- sling/trunk/testing/junit/performance/src/main/java/org/apache/sling/junit/performance/impl/RunExecutionIterationFinishedEvents.java (added)
+++ sling/trunk/testing/junit/performance/src/main/java/org/apache/sling/junit/performance/impl/RunExecutionIterationFinishedEvents.java Tue Jul 15 14:27:08 2014
@@ -0,0 +1,60 @@
+/*
+ * 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.junit.performance.impl;
+
+import org.junit.runners.model.FrameworkMethod;
+import org.junit.runners.model.MultipleFailureException;
+import org.junit.runners.model.Statement;
+import org.junit.runners.model.TestClass;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class RunExecutionIterationFinishedEvents extends Statement {
+
+    private final Listeners listeners;
+
+    private final TestClass test;
+
+    private final FrameworkMethod method;
+
+    private final Statement statement;
+
+    public RunExecutionIterationFinishedEvents(Listeners listeners, TestClass test, FrameworkMethod method, Statement statement) {
+        this.listeners = listeners;
+        this.test = test;
+        this.method = method;
+        this.statement = statement;
+    }
+
+    @Override
+    public void evaluate() throws Throwable {
+        List<Throwable> errors = new ArrayList<Throwable>();
+
+        try {
+            statement.evaluate();
+        } catch (Throwable t) {
+            errors.add(t);
+        } finally {
+            errors.addAll(listeners.executionIterationFinished(test.getName(), method.getName()));
+        }
+
+        MultipleFailureException.assertEmpty(errors);
+    }
+
+}

Added: sling/trunk/testing/junit/performance/src/main/java/org/apache/sling/junit/performance/impl/RunExecutionIterationStartedEvents.java
URL: http://svn.apache.org/viewvc/sling/trunk/testing/junit/performance/src/main/java/org/apache/sling/junit/performance/impl/RunExecutionIterationStartedEvents.java?rev=1610715&view=auto
==============================================================================
--- sling/trunk/testing/junit/performance/src/main/java/org/apache/sling/junit/performance/impl/RunExecutionIterationStartedEvents.java (added)
+++ sling/trunk/testing/junit/performance/src/main/java/org/apache/sling/junit/performance/impl/RunExecutionIterationStartedEvents.java Tue Jul 15 14:27:08 2014
@@ -0,0 +1,51 @@
+/*
+ * 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.junit.performance.impl;
+
+import org.junit.runners.model.FrameworkMethod;
+import org.junit.runners.model.MultipleFailureException;
+import org.junit.runners.model.Statement;
+import org.junit.runners.model.TestClass;
+
+import java.util.List;
+
+public class RunExecutionIterationStartedEvents extends Statement {
+
+    private final Listeners listeners;
+
+    private final TestClass test;
+
+    private final FrameworkMethod method;
+
+    private final Statement statement;
+
+    public RunExecutionIterationStartedEvents(Listeners listeners, TestClass test, FrameworkMethod method, Statement statement) {
+        this.listeners = listeners;
+        this.test = test;
+        this.method = method;
+        this.statement = statement;
+    }
+
+    @Override
+    public void evaluate() throws Throwable {
+        List<Throwable> errors = listeners.executionIterationStarted(test.getName(), method.getName());
+        MultipleFailureException.assertEmpty(errors);
+        statement.evaluate();
+    }
+
+}

Added: sling/trunk/testing/junit/performance/src/main/java/org/apache/sling/junit/performance/impl/RunExecutionStartedEvents.java
URL: http://svn.apache.org/viewvc/sling/trunk/testing/junit/performance/src/main/java/org/apache/sling/junit/performance/impl/RunExecutionStartedEvents.java?rev=1610715&view=auto
==============================================================================
--- sling/trunk/testing/junit/performance/src/main/java/org/apache/sling/junit/performance/impl/RunExecutionStartedEvents.java (added)
+++ sling/trunk/testing/junit/performance/src/main/java/org/apache/sling/junit/performance/impl/RunExecutionStartedEvents.java Tue Jul 15 14:27:08 2014
@@ -0,0 +1,51 @@
+/*
+ * 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.junit.performance.impl;
+
+import org.junit.runners.model.FrameworkMethod;
+import org.junit.runners.model.MultipleFailureException;
+import org.junit.runners.model.Statement;
+import org.junit.runners.model.TestClass;
+
+import java.util.List;
+
+public class RunExecutionStartedEvents extends Statement {
+
+    private final Listeners listeners;
+
+    private final TestClass test;
+
+    private final FrameworkMethod method;
+
+    private final Statement statement;
+
+    public RunExecutionStartedEvents(Listeners listeners, TestClass test, FrameworkMethod method, Statement statement) {
+        this.listeners = listeners;
+        this.test = test;
+        this.method = method;
+        this.statement = statement;
+    }
+
+    @Override
+    public void evaluate() throws Throwable {
+        List<Throwable> errors = listeners.executionStarted(test.getName(), method.getName());
+        MultipleFailureException.assertEmpty(errors);
+        statement.evaluate();
+    }
+
+}

Added: sling/trunk/testing/junit/performance/src/main/java/org/apache/sling/junit/performance/impl/RunIterations.java
URL: http://svn.apache.org/viewvc/sling/trunk/testing/junit/performance/src/main/java/org/apache/sling/junit/performance/impl/RunIterations.java?rev=1610715&view=auto
==============================================================================
--- sling/trunk/testing/junit/performance/src/main/java/org/apache/sling/junit/performance/impl/RunIterations.java (added)
+++ sling/trunk/testing/junit/performance/src/main/java/org/apache/sling/junit/performance/impl/RunIterations.java Tue Jul 15 14:27:08 2014
@@ -0,0 +1,65 @@
+/*
+ * 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.junit.performance.impl;
+
+import org.junit.runners.model.Statement;
+
+public class RunIterations extends Statement {
+
+    private final int invocations;
+
+    private final int seconds;
+
+    private final Statement iteration;
+
+    public RunIterations(int invocations, int seconds, Statement iteration) {
+        this.invocations = invocations;
+        this.seconds = seconds;
+        this.iteration = iteration;
+    }
+
+    @Override
+    public void evaluate() throws Throwable {
+        if (invocations > 0) {
+            runByInvocations();
+            return;
+        }
+
+        if (seconds > 0) {
+            runByTime();
+            return;
+        }
+
+        throw new IllegalArgumentException("Number of invocations or seconds not provided");
+    }
+
+    private void runByTime() throws Throwable {
+        long end = System.currentTimeMillis() + seconds * 1000;
+
+        while (System.currentTimeMillis() < end) {
+            iteration.evaluate();
+        }
+    }
+
+    private void runByInvocations() throws Throwable {
+        for (int i = 0; i < invocations; i++) {
+            iteration.evaluate();
+        }
+    }
+
+}

Added: sling/trunk/testing/junit/performance/src/main/java/org/apache/sling/junit/performance/impl/RunSerial.java
URL: http://svn.apache.org/viewvc/sling/trunk/testing/junit/performance/src/main/java/org/apache/sling/junit/performance/impl/RunSerial.java?rev=1610715&view=auto
==============================================================================
--- sling/trunk/testing/junit/performance/src/main/java/org/apache/sling/junit/performance/impl/RunSerial.java (added)
+++ sling/trunk/testing/junit/performance/src/main/java/org/apache/sling/junit/performance/impl/RunSerial.java Tue Jul 15 14:27:08 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.junit.performance.impl;
+
+import org.junit.runners.model.Statement;
+
+public class RunSerial extends Statement {
+
+    private final Statement[] statements;
+
+    public RunSerial(Statement... statements) {
+        this.statements = statements;
+    }
+
+    @Override
+    public void evaluate() throws Throwable {
+        for (Statement statement : statements) {
+            statement.evaluate();
+        }
+    }
+
+}

Added: sling/trunk/testing/junit/performance/src/main/java/org/apache/sling/junit/performance/impl/RunWarmUpFinishedEvents.java
URL: http://svn.apache.org/viewvc/sling/trunk/testing/junit/performance/src/main/java/org/apache/sling/junit/performance/impl/RunWarmUpFinishedEvents.java?rev=1610715&view=auto
==============================================================================
--- sling/trunk/testing/junit/performance/src/main/java/org/apache/sling/junit/performance/impl/RunWarmUpFinishedEvents.java (added)
+++ sling/trunk/testing/junit/performance/src/main/java/org/apache/sling/junit/performance/impl/RunWarmUpFinishedEvents.java Tue Jul 15 14:27:08 2014
@@ -0,0 +1,60 @@
+/*
+ * 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.junit.performance.impl;
+
+import org.junit.runners.model.FrameworkMethod;
+import org.junit.runners.model.MultipleFailureException;
+import org.junit.runners.model.Statement;
+import org.junit.runners.model.TestClass;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class RunWarmUpFinishedEvents extends Statement {
+
+    private final Listeners listeners;
+
+    private final TestClass test;
+
+    private final FrameworkMethod method;
+
+    private final Statement statement;
+
+    public RunWarmUpFinishedEvents(Listeners listeners, TestClass test, FrameworkMethod method, Statement statement) {
+        this.listeners = listeners;
+        this.test = test;
+        this.method = method;
+        this.statement = statement;
+    }
+
+    @Override
+    public void evaluate() throws Throwable {
+        List<Throwable> errors = new ArrayList<Throwable>();
+
+        try {
+            statement.evaluate();
+        } catch (Throwable t) {
+            errors.add(t);
+        } finally {
+            errors.addAll(listeners.warmUpFinished(test.getName(), method.getName()));
+        }
+
+        MultipleFailureException.assertEmpty(errors);
+    }
+
+}

Added: sling/trunk/testing/junit/performance/src/main/java/org/apache/sling/junit/performance/impl/RunWarmUpIterationFinishedEvents.java
URL: http://svn.apache.org/viewvc/sling/trunk/testing/junit/performance/src/main/java/org/apache/sling/junit/performance/impl/RunWarmUpIterationFinishedEvents.java?rev=1610715&view=auto
==============================================================================
--- sling/trunk/testing/junit/performance/src/main/java/org/apache/sling/junit/performance/impl/RunWarmUpIterationFinishedEvents.java (added)
+++ sling/trunk/testing/junit/performance/src/main/java/org/apache/sling/junit/performance/impl/RunWarmUpIterationFinishedEvents.java Tue Jul 15 14:27:08 2014
@@ -0,0 +1,60 @@
+/*
+ * 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.junit.performance.impl;
+
+import org.junit.runners.model.FrameworkMethod;
+import org.junit.runners.model.MultipleFailureException;
+import org.junit.runners.model.Statement;
+import org.junit.runners.model.TestClass;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class RunWarmUpIterationFinishedEvents extends Statement {
+
+    private final Listeners listeners;
+
+    private final TestClass test;
+
+    private final FrameworkMethod method;
+
+    private final Statement statement;
+
+    public RunWarmUpIterationFinishedEvents(Listeners listeners, TestClass test, FrameworkMethod method, Statement statement) {
+        this.listeners = listeners;
+        this.test = test;
+        this.method = method;
+        this.statement = statement;
+    }
+
+    @Override
+    public void evaluate() throws Throwable {
+        List<Throwable> errors = new ArrayList<Throwable>();
+
+        try {
+            statement.evaluate();
+        } catch (Throwable t) {
+            errors.add(t);
+        } finally {
+            errors.addAll(listeners.warmUpIterationFinished(test.getName(), method.getName()));
+        }
+
+        MultipleFailureException.assertEmpty(errors);
+    }
+
+}

Added: sling/trunk/testing/junit/performance/src/main/java/org/apache/sling/junit/performance/impl/RunWarmUpIterationStartedEvents.java
URL: http://svn.apache.org/viewvc/sling/trunk/testing/junit/performance/src/main/java/org/apache/sling/junit/performance/impl/RunWarmUpIterationStartedEvents.java?rev=1610715&view=auto
==============================================================================
--- sling/trunk/testing/junit/performance/src/main/java/org/apache/sling/junit/performance/impl/RunWarmUpIterationStartedEvents.java (added)
+++ sling/trunk/testing/junit/performance/src/main/java/org/apache/sling/junit/performance/impl/RunWarmUpIterationStartedEvents.java Tue Jul 15 14:27:08 2014
@@ -0,0 +1,51 @@
+/*
+ * 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.junit.performance.impl;
+
+import org.junit.runners.model.FrameworkMethod;
+import org.junit.runners.model.MultipleFailureException;
+import org.junit.runners.model.Statement;
+import org.junit.runners.model.TestClass;
+
+import java.util.List;
+
+public class RunWarmUpIterationStartedEvents extends Statement {
+
+    private final Listeners listeners;
+
+    private final TestClass test;
+
+    private final FrameworkMethod method;
+
+    private final Statement statement;
+
+    public RunWarmUpIterationStartedEvents(Listeners listeners, TestClass test, FrameworkMethod method, Statement statement) {
+        this.listeners = listeners;
+        this.test = test;
+        this.method = method;
+        this.statement = statement;
+    }
+
+    @Override
+    public void evaluate() throws Throwable {
+        List<Throwable> errors = listeners.warmUpIterationStarted(test.getName(), method.getName());
+        MultipleFailureException.assertEmpty(errors);
+        statement.evaluate();
+    }
+
+}

Added: sling/trunk/testing/junit/performance/src/main/java/org/apache/sling/junit/performance/impl/RunWarmUpStartedEvents.java
URL: http://svn.apache.org/viewvc/sling/trunk/testing/junit/performance/src/main/java/org/apache/sling/junit/performance/impl/RunWarmUpStartedEvents.java?rev=1610715&view=auto
==============================================================================
--- sling/trunk/testing/junit/performance/src/main/java/org/apache/sling/junit/performance/impl/RunWarmUpStartedEvents.java (added)
+++ sling/trunk/testing/junit/performance/src/main/java/org/apache/sling/junit/performance/impl/RunWarmUpStartedEvents.java Tue Jul 15 14:27:08 2014
@@ -0,0 +1,51 @@
+/*
+ * 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.junit.performance.impl;
+
+import org.junit.runners.model.FrameworkMethod;
+import org.junit.runners.model.MultipleFailureException;
+import org.junit.runners.model.Statement;
+import org.junit.runners.model.TestClass;
+
+import java.util.List;
+
+public class RunWarmUpStartedEvents extends Statement {
+
+    private final Listeners listeners;
+
+    private final TestClass test;
+
+    private final FrameworkMethod method;
+
+    private final Statement statement;
+
+    public RunWarmUpStartedEvents(Listeners listeners, TestClass test, FrameworkMethod method, Statement statement) {
+        this.listeners = listeners;
+        this.test = test;
+        this.method = method;
+        this.statement = statement;
+    }
+
+    @Override
+    public void evaluate() throws Throwable {
+        List<Throwable> errors = listeners.warmUpStarted(test.getName(), method.getName());
+        MultipleFailureException.assertEmpty(errors);
+        statement.evaluate();
+    }
+
+}

Added: sling/trunk/testing/junit/performance/src/main/java/org/apache/sling/junit/performance/runner/AfterPerformanceIteration.java
URL: http://svn.apache.org/viewvc/sling/trunk/testing/junit/performance/src/main/java/org/apache/sling/junit/performance/runner/AfterPerformanceIteration.java?rev=1610715&view=auto
==============================================================================
--- sling/trunk/testing/junit/performance/src/main/java/org/apache/sling/junit/performance/runner/AfterPerformanceIteration.java (added)
+++ sling/trunk/testing/junit/performance/src/main/java/org/apache/sling/junit/performance/runner/AfterPerformanceIteration.java Tue Jul 15 14:27:08 2014
@@ -0,0 +1,28 @@
+/*
+ * 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.junit.performance.runner;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+
+/**
+ * Execute the annotated method after each performance execution of the performance test.
+ */
+@Retention(RetentionPolicy.RUNTIME)
+public @interface AfterPerformanceIteration {
+}

Added: sling/trunk/testing/junit/performance/src/main/java/org/apache/sling/junit/performance/runner/AfterPerformanceTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/testing/junit/performance/src/main/java/org/apache/sling/junit/performance/runner/AfterPerformanceTest.java?rev=1610715&view=auto
==============================================================================
--- sling/trunk/testing/junit/performance/src/main/java/org/apache/sling/junit/performance/runner/AfterPerformanceTest.java (added)
+++ sling/trunk/testing/junit/performance/src/main/java/org/apache/sling/junit/performance/runner/AfterPerformanceTest.java Tue Jul 15 14:27:08 2014
@@ -0,0 +1,28 @@
+/*
+ * 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.junit.performance.runner;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+
+/**
+ * Execute the annotated method after every performance iteration of the performance test.
+ */
+@Retention(RetentionPolicy.RUNTIME)
+public @interface AfterPerformanceTest {
+}

Added: sling/trunk/testing/junit/performance/src/main/java/org/apache/sling/junit/performance/runner/AfterWarmUp.java
URL: http://svn.apache.org/viewvc/sling/trunk/testing/junit/performance/src/main/java/org/apache/sling/junit/performance/runner/AfterWarmUp.java?rev=1610715&view=auto
==============================================================================
--- sling/trunk/testing/junit/performance/src/main/java/org/apache/sling/junit/performance/runner/AfterWarmUp.java (added)
+++ sling/trunk/testing/junit/performance/src/main/java/org/apache/sling/junit/performance/runner/AfterWarmUp.java Tue Jul 15 14:27:08 2014
@@ -0,0 +1,28 @@
+/*
+ * 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.junit.performance.runner;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+
+/**
+ * Execute the annotated method after each warm up iteration of the performance test.
+ */
+@Retention(RetentionPolicy.RUNTIME)
+public @interface AfterWarmUp {
+}

Added: sling/trunk/testing/junit/performance/src/main/java/org/apache/sling/junit/performance/runner/AfterWarmUpIteration.java
URL: http://svn.apache.org/viewvc/sling/trunk/testing/junit/performance/src/main/java/org/apache/sling/junit/performance/runner/AfterWarmUpIteration.java?rev=1610715&view=auto
==============================================================================
--- sling/trunk/testing/junit/performance/src/main/java/org/apache/sling/junit/performance/runner/AfterWarmUpIteration.java (added)
+++ sling/trunk/testing/junit/performance/src/main/java/org/apache/sling/junit/performance/runner/AfterWarmUpIteration.java Tue Jul 15 14:27:08 2014
@@ -0,0 +1,28 @@
+/*
+ * 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.junit.performance.runner;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+
+/**
+ * Execute the annotated method after each warm up iteration of the performance test.
+ */
+@Retention(RetentionPolicy.RUNTIME)
+public @interface AfterWarmUpIteration {
+}

Added: sling/trunk/testing/junit/performance/src/main/java/org/apache/sling/junit/performance/runner/BeforePerformanceIteration.java
URL: http://svn.apache.org/viewvc/sling/trunk/testing/junit/performance/src/main/java/org/apache/sling/junit/performance/runner/BeforePerformanceIteration.java?rev=1610715&view=auto
==============================================================================
--- sling/trunk/testing/junit/performance/src/main/java/org/apache/sling/junit/performance/runner/BeforePerformanceIteration.java (added)
+++ sling/trunk/testing/junit/performance/src/main/java/org/apache/sling/junit/performance/runner/BeforePerformanceIteration.java Tue Jul 15 14:27:08 2014
@@ -0,0 +1,28 @@
+/*
+ * 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.junit.performance.runner;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+
+/**
+ * Execute the annotated method before each performance iteration of the performance test.
+ */
+@Retention(RetentionPolicy.RUNTIME)
+public @interface BeforePerformanceIteration {
+}

Added: sling/trunk/testing/junit/performance/src/main/java/org/apache/sling/junit/performance/runner/BeforePerformanceTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/testing/junit/performance/src/main/java/org/apache/sling/junit/performance/runner/BeforePerformanceTest.java?rev=1610715&view=auto
==============================================================================
--- sling/trunk/testing/junit/performance/src/main/java/org/apache/sling/junit/performance/runner/BeforePerformanceTest.java (added)
+++ sling/trunk/testing/junit/performance/src/main/java/org/apache/sling/junit/performance/runner/BeforePerformanceTest.java Tue Jul 15 14:27:08 2014
@@ -0,0 +1,25 @@
+/*
+ * 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.junit.performance.runner;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+
+@Retention(RetentionPolicy.RUNTIME)
+public @interface BeforePerformanceTest {
+}

Added: sling/trunk/testing/junit/performance/src/main/java/org/apache/sling/junit/performance/runner/BeforeWarmUp.java
URL: http://svn.apache.org/viewvc/sling/trunk/testing/junit/performance/src/main/java/org/apache/sling/junit/performance/runner/BeforeWarmUp.java?rev=1610715&view=auto
==============================================================================
--- sling/trunk/testing/junit/performance/src/main/java/org/apache/sling/junit/performance/runner/BeforeWarmUp.java (added)
+++ sling/trunk/testing/junit/performance/src/main/java/org/apache/sling/junit/performance/runner/BeforeWarmUp.java Tue Jul 15 14:27:08 2014
@@ -0,0 +1,28 @@
+/*
+ * 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.junit.performance.runner;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+
+/**
+ * Execute the annotated method before every warm up iterations of the performance test.
+ */
+@Retention(RetentionPolicy.RUNTIME)
+public @interface BeforeWarmUp {
+}

Added: sling/trunk/testing/junit/performance/src/main/java/org/apache/sling/junit/performance/runner/BeforeWarmUpIteration.java
URL: http://svn.apache.org/viewvc/sling/trunk/testing/junit/performance/src/main/java/org/apache/sling/junit/performance/runner/BeforeWarmUpIteration.java?rev=1610715&view=auto
==============================================================================
--- sling/trunk/testing/junit/performance/src/main/java/org/apache/sling/junit/performance/runner/BeforeWarmUpIteration.java (added)
+++ sling/trunk/testing/junit/performance/src/main/java/org/apache/sling/junit/performance/runner/BeforeWarmUpIteration.java Tue Jul 15 14:27:08 2014
@@ -0,0 +1,25 @@
+/*
+ * 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.junit.performance.runner;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+
+@Retention(RetentionPolicy.RUNTIME)
+public @interface BeforeWarmUpIteration {
+}

Modified: sling/trunk/testing/junit/performance/src/main/java/org/apache/sling/junit/performance/runner/PerformanceRunner.java
URL: http://svn.apache.org/viewvc/sling/trunk/testing/junit/performance/src/main/java/org/apache/sling/junit/performance/runner/PerformanceRunner.java?rev=1610715&r1=1610714&r2=1610715&view=diff
==============================================================================
--- sling/trunk/testing/junit/performance/src/main/java/org/apache/sling/junit/performance/runner/PerformanceRunner.java (original)
+++ sling/trunk/testing/junit/performance/src/main/java/org/apache/sling/junit/performance/runner/PerformanceRunner.java Tue Jul 15 14:27:08 2014
@@ -17,9 +17,7 @@
 
 package org.apache.sling.junit.performance.runner;
 
-import org.apache.sling.junit.performance.impl.InvokePerformanceBlock;
-import org.apache.sling.junit.performance.impl.InvokePerformanceMethod;
-import org.apache.sling.junit.performance.impl.Listeners;
+import org.apache.sling.junit.performance.impl.*;
 import org.junit.runners.BlockJUnit4ClassRunner;
 import org.junit.runners.model.FrameworkField;
 import org.junit.runners.model.FrameworkMethod;
@@ -40,6 +38,11 @@ import java.util.List;
  * The runner can also invoke one or more {@link Listener}. The listener is specified as a static variable of the test
  * class or as the result of a static method. The listeners are made available to the runner by annotating them with the
  * {@link Listen} annotation.
+ * <p/>
+ * The runner support lifecycle methods which are executed at various stages of the performance test. These methods are
+ * annotated with {@link BeforePerformanceIteration}, {@link AfterPerformanceIteration}, {@link BeforePerformanceTest},
+ * {@link AfterPerformanceTest}, {@link BeforeWarmUpIteration}, {@link AfterWarmUpIteration}, {@link BeforeWarmUp} and
+ * {@link AfterWarmUp}. Every other standard JUnit annotation is also supported.
  */
 public class PerformanceRunner extends BlockJUnit4ClassRunner {
 
@@ -49,28 +52,278 @@ public class PerformanceRunner extends B
         super(testClass);
 
         try {
-            listeners = new Listeners(readListeners());
-        } catch (Exception e) {
+            listeners = new Listeners(getListeners());
+        } catch (Throwable e) {
             throw new InitializationError(e);
         }
     }
 
     @Override
-    protected List<FrameworkMethod> computeTestMethods() {
-        return getTestClass().getAnnotatedMethods(PerformanceTest.class);
+    protected void collectInitializationErrors(List<Throwable> errors) {
+        super.collectInitializationErrors(errors);
+
+        validatePublicVoidNoArgMethods(PerformanceTest.class, false, errors);
+        validatePublicVoidNoArgMethods(BeforeWarmUpIteration.class, false, errors);
+        validatePublicVoidNoArgMethods(AfterWarmUpIteration.class, false, errors);
+        validatePublicVoidNoArgMethods(BeforeWarmUp.class, false, errors);
+        validatePublicVoidNoArgMethods(AfterWarmUp.class, false, errors);
+        validatePublicVoidNoArgMethods(BeforePerformanceIteration.class, false, errors);
+        validatePublicVoidNoArgMethods(AfterPerformanceIteration.class, false, errors);
+        validatePublicVoidNoArgMethods(BeforePerformanceTest.class, false, errors);
+        validatePublicVoidNoArgMethods(AfterPerformanceTest.class, false, errors);
+        validatePerformanceTestsExecutionStrategy(errors);
+        validateListenMethodsReturnType(errors);
+        validateListenMethodsStatic(errors);
+        validateListenMethodPublic(errors);
+        validateListenFieldsType(errors);
+        validateListenFieldsStatic(errors);
+        validateListenFieldPublic(errors);
+    }
+
+    private void validatePerformanceTestsExecutionStrategy(List<Throwable> errors) {
+        for (FrameworkMethod method : getTestClass().getAnnotatedMethods(PerformanceTest.class)) {
+            int warmUpInvocations = getWarmUpInvocations(method);
+            int warmUpTime = getWarmUpTime(method);
+
+            if (warmUpInvocations <= 0 && warmUpTime <= 0) {
+                errors.add(new Error("Method " + method.getName() + "() should provide a valid warmUpInvocations or warmUpTime"));
+            }
+
+            if (warmUpInvocations > 0 && warmUpTime > 0) {
+                errors.add(new Error("Method " + method.getName() + "() provides both a valid warmUpInvocations and a warmUpTime"));
+            }
+
+            int runInvocations = getRunInvocations(method);
+            int runTime = getRunTime(method);
+
+            if (runInvocations <= 0 && runTime <= 0) {
+                errors.add(new Error("Method " + method.getName() + "() should provide a valid runInvocations or runTime"));
+            }
+
+            if (runInvocations > 0 && runTime > 0) {
+                errors.add(new Error("Method " + method.getName() + "() provides both a valid runInvocations or runTime"));
+            }
+        }
+    }
+
+    private void validateListenMethodsReturnType(List<Throwable> errors) {
+        for (FrameworkMethod method : getTestClass().getAnnotatedMethods(Listen.class)) {
+            if (Listener.class.isAssignableFrom(method.getReturnType())) {
+                continue;
+            }
+
+            errors.add(new Error("Method " + method.getName() + "() should return an object of type Listener"));
+        }
+    }
+
+    private void validateListenMethodsStatic(List<Throwable> errors) {
+        for (FrameworkMethod method : getTestClass().getAnnotatedMethods(Listen.class)) {
+            if (method.isStatic()) {
+                continue;
+            }
+
+            errors.add(new Error("Method " + method.getName() + "() should be static"));
+        }
+    }
+
+    private void validateListenMethodPublic(List<Throwable> errors) {
+        for (FrameworkMethod method : getTestClass().getAnnotatedMethods(Listen.class)) {
+            if (method.isPublic()) {
+                continue;
+            }
+
+            errors.add(new Error("Method " + method.getName() + "() should be public"));
+        }
+    }
+
+    private void validateListenFieldsType(List<Throwable> errors) {
+        for (FrameworkField field : getTestClass().getAnnotatedFields(Listen.class)) {
+            if (Listener.class.isAssignableFrom(field.getType())) {
+                continue;
+            }
+
+            errors.add(new Error("Field " + field.getName() + " should be of type Listener"));
+        }
+    }
+
+    private void validateListenFieldsStatic(List<Throwable> errors) {
+        for (FrameworkField field : getTestClass().getAnnotatedFields(Listen.class)) {
+            if (field.isStatic()) {
+                continue;
+            }
+
+            errors.add(new Error("Field " + field.getName() + " should be static"));
+        }
+    }
+
+    private void validateListenFieldPublic(List<Throwable> errors) {
+        for (FrameworkField field : getTestClass().getAnnotatedFields(Listen.class)) {
+            if (field.isPublic()) {
+                continue;
+            }
+
+            errors.add(new Error("Field " + field.getName() + " should be public"));
+        }
     }
 
     @Override
-    protected Statement methodBlock(FrameworkMethod method) {
-        return new InvokePerformanceBlock(getTestClass(), method, super.methodBlock(method), listeners);
+    protected List<FrameworkMethod> computeTestMethods() {
+        return getTestClass().getAnnotatedMethods(PerformanceTest.class);
     }
 
     @Override
     protected Statement methodInvoker(FrameworkMethod method, Object test) {
-        return new InvokePerformanceMethod(getTestClass(), method, super.methodInvoker(method, test), listeners);
+        Statement methodInvoker = super.methodInvoker(method, test);
+
+        Statement invokeWarmUp = methodInvoker;
+
+        invokeWarmUp = withWarmUpIterationStartedEvents(method, test, invokeWarmUp);
+        invokeWarmUp = withWarmUpIterationFinishedEvents(method, test, invokeWarmUp);
+        invokeWarmUp = withBeforeWarmUpIterations(method, test, invokeWarmUp);
+        invokeWarmUp = withAfterWarmUpIterations(method, test, invokeWarmUp);
+        invokeWarmUp = withWarmUpIterations(method, test, invokeWarmUp);
+        invokeWarmUp = withWarmUpStartedEvents(method, test, invokeWarmUp);
+        invokeWarmUp = withWarmUpFinishedEvents(method, test, invokeWarmUp);
+        invokeWarmUp = withBeforeWarmUps(method, test, invokeWarmUp);
+        invokeWarmUp = withAfterWarmUps(method, test, invokeWarmUp);
+
+        Statement invokePerformanceTest = methodInvoker;
+
+        invokePerformanceTest = withExecutionIterationStartedEvents(method, test, invokePerformanceTest);
+        invokePerformanceTest = withExecutionIterationFinishedEvents(method, test, invokePerformanceTest);
+        invokePerformanceTest = withBeforePerformanceIterations(method, test, invokePerformanceTest);
+        invokePerformanceTest = withAfterPerformanceIterations(method, test, invokePerformanceTest);
+        invokePerformanceTest = withPerformanceIterations(method, test, invokePerformanceTest);
+        invokePerformanceTest = withExecutionStartedEvents(method, test, invokePerformanceTest);
+        invokePerformanceTest = withExecutionFinishedEvents(method, test, invokePerformanceTest);
+        invokePerformanceTest = withBeforePerformanceTests(method, test, invokePerformanceTest);
+        invokePerformanceTest = withAfterPerformanceTests(method, test, invokePerformanceTest);
+
+        return new RunSerial(invokeWarmUp, invokePerformanceTest);
+    }
+
+
+    protected Statement withBeforeWarmUpIterations(FrameworkMethod method, Object test, Statement next) {
+        List<FrameworkMethod> methods = getTestClass().getAnnotatedMethods(BeforeWarmUpIteration.class);
+
+        if (methods.size() == 0) {
+            return next;
+        }
+
+        return new RunBefores(next, methods, test);
     }
 
-    private List<Listener> readListeners() throws Exception {
+    protected Statement withAfterWarmUpIterations(FrameworkMethod method, Object test, Statement next) {
+        List<FrameworkMethod> methods = getTestClass().getAnnotatedMethods(AfterWarmUpIteration.class);
+
+        if (methods.size() == 0) {
+            return next;
+        }
+
+        return new RunAfters(next, methods, test);
+    }
+
+    protected Statement withWarmUpIterations(FrameworkMethod method, Object test, Statement iteration) {
+        return new RunIterations(getWarmUpInvocations(method), getWarmUpTime(method), iteration);
+    }
+
+    protected Statement withBeforeWarmUps(FrameworkMethod method, Object test, Statement next) {
+        List<FrameworkMethod> methods = getTestClass().getAnnotatedMethods(BeforeWarmUp.class);
+
+        if (methods.size() == 0) {
+            return next;
+        }
+
+        return new RunBefores(next, methods, test);
+    }
+
+    protected Statement withAfterWarmUps(FrameworkMethod method, Object test, Statement next) {
+        List<FrameworkMethod> methods = getTestClass().getAnnotatedMethods(AfterWarmUp.class);
+
+        if (methods.size() == 0) {
+            return next;
+        }
+
+        return new RunAfters(next, methods, test);
+    }
+
+    protected Statement withBeforePerformanceIterations(FrameworkMethod method, Object test, Statement next) {
+        List<FrameworkMethod> methods = getTestClass().getAnnotatedMethods(BeforePerformanceIteration.class);
+
+        if (methods.size() == 0) {
+            return next;
+        }
+
+        return new RunBefores(next, methods, test);
+    }
+
+    protected Statement withAfterPerformanceIterations(FrameworkMethod method, Object test, Statement next) {
+        List<FrameworkMethod> methods = getTestClass().getAnnotatedMethods(AfterPerformanceIteration.class);
+
+        if (methods.size() == 0) {
+            return next;
+        }
+
+        return new RunAfters(next, methods, test);
+    }
+
+    protected Statement withPerformanceIterations(FrameworkMethod method, Object test, Statement iteration) {
+        return new RunIterations(getRunInvocations(method), getRunTime(method), iteration);
+    }
+
+    protected Statement withBeforePerformanceTests(FrameworkMethod method, Object test, Statement next) {
+        List<FrameworkMethod> methods = getTestClass().getAnnotatedMethods(BeforePerformanceTest.class);
+
+        if (methods.size() == 0) {
+            return next;
+        }
+
+        return new RunBefores(next, methods, test);
+    }
+
+    protected Statement withAfterPerformanceTests(FrameworkMethod method, Object test, Statement next) {
+        List<FrameworkMethod> methods = getTestClass().getAnnotatedMethods(AfterPerformanceTest.class);
+
+        if (methods.size() == 0) {
+            return next;
+        }
+
+        return new RunAfters(next, methods, test);
+    }
+
+    protected Statement withWarmUpIterationStartedEvents(FrameworkMethod method, Object test, Statement next) {
+        return new RunWarmUpIterationStartedEvents(listeners, getTestClass(), method, next);
+    }
+
+    protected Statement withWarmUpIterationFinishedEvents(FrameworkMethod method, Object test, Statement next) {
+        return new RunWarmUpIterationFinishedEvents(listeners, getTestClass(), method, next);
+    }
+
+    protected Statement withWarmUpStartedEvents(FrameworkMethod method, Object test, Statement next) {
+        return new RunWarmUpStartedEvents(listeners, getTestClass(), method, next);
+    }
+
+    protected Statement withWarmUpFinishedEvents(FrameworkMethod method, Object test, Statement next) {
+        return new RunWarmUpFinishedEvents(listeners, getTestClass(), method, next);
+    }
+
+    protected Statement withExecutionIterationStartedEvents(FrameworkMethod method, Object test, Statement next) {
+        return new RunExecutionIterationStartedEvents(listeners, getTestClass(), method, next);
+    }
+
+    protected Statement withExecutionIterationFinishedEvents(FrameworkMethod method, Object test, Statement next) {
+        return new RunExecutionIterationFinishedEvents(listeners, getTestClass(), method, next);
+    }
+
+    protected Statement withExecutionStartedEvents(FrameworkMethod method, Object test, Statement next) {
+        return new RunExecutionStartedEvents(listeners, getTestClass(), method, next);
+    }
+
+    protected Statement withExecutionFinishedEvents(FrameworkMethod method, Object test, Statement next) {
+        return new RunExecutionFinishedEvents(listeners, getTestClass(), method, next);
+    }
+
+    private List<Listener> getListeners() throws Throwable {
         List<Listener> listeners = new ArrayList<Listener>();
 
         listeners.addAll(readListenersFromStaticFields());
@@ -79,32 +332,14 @@ public class PerformanceRunner extends B
         return listeners;
     }
 
-    private List<Listener> readListenersFromStaticMethods() throws Exception {
+    private List<Listener> readListenersFromStaticMethods() throws Throwable {
         List<Listener> listeners = new ArrayList<Listener>();
 
         for (FrameworkMethod method : getTestClass().getAnnotatedMethods(Listen.class)) {
-            if (!method.isPublic()) {
-                throw new IllegalArgumentException("a @Listen method must be public");
-            }
-
-            if (!method.isStatic()) {
-                throw new IllegalArgumentException("a @Listen method must be static");
-            }
-
-            if (!Listener.class.isAssignableFrom(method.getReturnType())) {
-                throw new IllegalArgumentException("a @Listen method must be of type Listener");
-            }
-
-            Listener listener = null;
-
-            try {
-                listener = (Listener) method.invokeExplosively(null);
-            } catch (Throwable throwable) {
-                throw new RuntimeException("error while invoking the @Listen method", throwable);
-            }
+            Listener listener = (Listener) method.invokeExplosively(null);
 
             if (listener == null) {
-                throw new IllegalArgumentException("a @Listen method must return a non-null value");
+                throw new IllegalArgumentException("Method " + method.getName() + "() should not return null");
             }
 
             listeners.add(listener);
@@ -114,31 +349,35 @@ public class PerformanceRunner extends B
     }
 
     private List<Listener> readListenersFromStaticFields() throws Exception {
-        List<Listener> reporters = new ArrayList<Listener>();
+        List<Listener> listeners = new ArrayList<Listener>();
 
         for (FrameworkField field : getTestClass().getAnnotatedFields(Listen.class)) {
-            if (!field.isPublic()) {
-                throw new IllegalArgumentException("a @Listen field must be public");
-            }
-
-            if (!field.isStatic()) {
-                throw new IllegalArgumentException("a @Listen field must be static");
-            }
-
-            if (!Listener.class.isAssignableFrom(field.getType())) {
-                throw new IllegalArgumentException("a @Listen field must be of type Listener");
-            }
-
             Listener listener = (Listener) field.get(null);
 
             if (listener == null) {
-                throw new IllegalArgumentException("a @Listen field must not be null");
+                throw new IllegalArgumentException("Field " + field.getName() + " should not be null");
             }
 
-            reporters.add(listener);
+            listeners.add(listener);
         }
 
-        return reporters;
+        return listeners;
+    }
+
+    private int getWarmUpInvocations(FrameworkMethod method) {
+        return method.getAnnotation(PerformanceTest.class).warmUpInvocations();
+    }
+
+    private int getWarmUpTime(FrameworkMethod method) {
+        return method.getAnnotation(PerformanceTest.class).warmUpTime();
+    }
+
+    private int getRunInvocations(FrameworkMethod method) {
+        return method.getAnnotation(PerformanceTest.class).runInvocations();
+    }
+
+    private int getRunTime(FrameworkMethod method) {
+        return method.getAnnotation(PerformanceTest.class).runTime();
     }
 
 }

Added: sling/trunk/testing/junit/performance/src/test/java/org/apache/sling/junit/performance/runner/PerformanceRunnerDynamicsTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/testing/junit/performance/src/test/java/org/apache/sling/junit/performance/runner/PerformanceRunnerDynamicsTest.java?rev=1610715&view=auto
==============================================================================
--- sling/trunk/testing/junit/performance/src/test/java/org/apache/sling/junit/performance/runner/PerformanceRunnerDynamicsTest.java (added)
+++ sling/trunk/testing/junit/performance/src/test/java/org/apache/sling/junit/performance/runner/PerformanceRunnerDynamicsTest.java Tue Jul 15 14:27:08 2014
@@ -0,0 +1,323 @@
+/*
+ * 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.junit.performance.runner;
+
+import org.junit.*;
+import org.junit.runner.JUnitCore;
+import org.junit.runner.RunWith;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class PerformanceRunnerDynamicsTest {
+
+    @RunWith(PerformanceRunner.class)
+    public static class AnnotationOrder {
+
+        public static List<String> executions = new ArrayList<String>();
+
+        @BeforeWarmUpIteration
+        public void beforeWarmUpIteration() {
+            executions.add("before warm up iteration");
+        }
+
+        @AfterWarmUpIteration
+        public void afterWarmUpIteration() {
+            executions.add("after warm up iteration");
+        }
+
+        @BeforeWarmUp
+        public void beforeWarmUp() {
+            executions.add("before warm up");
+        }
+
+        @AfterWarmUp
+        public void afterWarmUp() {
+            executions.add("after warm up");
+        }
+
+        @BeforePerformanceIteration
+        public void beforePerformanceIteration() {
+            executions.add("before performance iteration");
+        }
+
+        @AfterPerformanceIteration
+        public void afterPerformanceIteration() {
+            executions.add("after performance iteration");
+        }
+
+        @BeforePerformanceTest
+        public void beforePerformanceTest() {
+            executions.add("before performance test");
+        }
+
+        @AfterPerformanceTest
+        public void afterPerformanceTest() {
+            executions.add("after performance test");
+        }
+
+        @PerformanceTest(warmUpInvocations = 1, runInvocations = 1)
+        public void performanceTest() {
+            executions.add("performance test");
+        }
+
+    }
+
+    @Test
+    public void testAnnotationOrder() {
+        List<String> expected = new ArrayList<String>();
+
+        expected.add("before warm up");
+        expected.add("before warm up iteration");
+        expected.add("performance test");
+        expected.add("after warm up iteration");
+        expected.add("after warm up");
+        expected.add("before performance test");
+        expected.add("before performance iteration");
+        expected.add("performance test");
+        expected.add("after performance iteration");
+        expected.add("after performance test");
+
+        JUnitCore.runClasses(AnnotationOrder.class);
+
+        Assert.assertEquals(expected, AnnotationOrder.executions);
+    }
+
+    @RunWith(PerformanceRunner.class)
+    public static class ExistingJUnitAnnotations {
+
+        public static List<String> executions = new ArrayList<String>();
+
+        @BeforeClass
+        public static void beforeClass() {
+            executions.add("junit before class");
+        }
+
+        @AfterClass
+        public static void afterClass() {
+            executions.add("junit after class");
+        }
+
+        @Before
+        public void before() {
+            executions.add("junit before");
+        }
+
+        @After
+        public void after() {
+            executions.add("junit after");
+        }
+
+        @BeforeWarmUpIteration
+        public void beforeWarmUpIteration() {
+            executions.add("before warm up iteration");
+        }
+
+        @AfterWarmUpIteration
+        public void afterWarmUpIteration() {
+            executions.add("after warm up iteration");
+        }
+
+        @BeforeWarmUp
+        public void beforeWarmUp() {
+            executions.add("before warm up");
+        }
+
+        @AfterWarmUp
+        public void afterWarmUp() {
+            executions.add("after warm up");
+        }
+
+        @BeforePerformanceIteration
+        public void beforePerformanceIteration() {
+            executions.add("before performance iteration");
+        }
+
+        @AfterPerformanceIteration
+        public void afterPerformanceIteration() {
+            executions.add("after performance iteration");
+        }
+
+        @BeforePerformanceTest
+        public void beforePerformanceTest() {
+            executions.add("before performance test");
+        }
+
+        @AfterPerformanceTest
+        public void afterPerformanceTest() {
+            executions.add("after performance test");
+        }
+
+        @PerformanceTest(warmUpInvocations = 1, runInvocations = 1)
+        public void performanceTest() {
+            executions.add("performance test");
+        }
+
+    }
+
+    @Test
+    public void testExistingJUnitAnnotations() {
+        List<String> expected = new ArrayList<String>();
+
+        expected.add("junit before class");
+        expected.add("junit before");
+        expected.add("before warm up");
+        expected.add("before warm up iteration");
+        expected.add("performance test");
+        expected.add("after warm up iteration");
+        expected.add("after warm up");
+        expected.add("before performance test");
+        expected.add("before performance iteration");
+        expected.add("performance test");
+        expected.add("after performance iteration");
+        expected.add("after performance test");
+        expected.add("junit after");
+        expected.add("junit after class");
+
+        JUnitCore.runClasses(ExistingJUnitAnnotations.class);
+
+        Assert.assertEquals(expected, ExistingJUnitAnnotations.executions);
+    }
+
+    @RunWith(PerformanceRunner.class)
+    public static class PerformanceListeners {
+
+        public static List<String> executions = new ArrayList<String>();
+
+        @Listen
+        public static Listener listener = new Listener() {
+
+            @Override
+            public void warmUpStarted(String className, String testName) throws Exception {
+                executions.add("warm up started event");
+            }
+
+            @Override
+            public void warmUpFinished(String className, String testName) throws Exception {
+                executions.add("warm up finished event");
+            }
+
+            @Override
+            public void executionStarted(String className, String testName) throws Exception {
+                executions.add("execution started event");
+            }
+
+            @Override
+            public void executionFinished(String className, String testName) throws Exception {
+                executions.add("execution finished event");
+            }
+
+            @Override
+            public void warmUpIterationStarted(String className, String testName) throws Exception {
+                executions.add("warm up iteration started event");
+            }
+
+            @Override
+            public void executionIterationStarted(String className, String testName) throws Exception {
+                executions.add("execution iteration started event");
+            }
+
+            @Override
+            public void warmUpIterationFinished(String className, String testName) throws Exception {
+                executions.add("warm up iteration finished event");
+            }
+
+            @Override
+            public void executionIterationFinished(String className, String testName) throws Exception {
+                executions.add("execution iteration finished event");
+            }
+
+        };
+
+        @BeforeWarmUpIteration
+        public void beforeWarmUpIteration() {
+            executions.add("before warm up iteration");
+        }
+
+        @AfterWarmUpIteration
+        public void afterWarmUpIteration() {
+            executions.add("after warm up iteration");
+        }
+
+        @BeforeWarmUp
+        public void beforeWarmUp() {
+            executions.add("before warm up");
+        }
+
+        @AfterWarmUp
+        public void afterWarmUp() {
+            executions.add("after warm up");
+        }
+
+        @BeforePerformanceIteration
+        public void beforePerformanceIteration() {
+            executions.add("before performance iteration");
+        }
+
+        @AfterPerformanceIteration
+        public void afterPerformanceIteration() {
+            executions.add("after performance iteration");
+        }
+
+        @BeforePerformanceTest
+        public void beforePerformanceTest() {
+            executions.add("before performance test");
+        }
+
+        @AfterPerformanceTest
+        public void afterPerformanceTest() {
+            executions.add("after performance test");
+        }
+
+        @PerformanceTest(warmUpInvocations = 1, runInvocations = 1)
+        public void performanceTest() {
+            executions.add("performance test");
+        }
+
+    }
+
+    @Test
+    public void testPerformanceListeners() {
+        List<String> expected = new ArrayList<String>();
+
+        expected.add("before warm up");
+        expected.add("warm up started event");
+        expected.add("before warm up iteration");
+        expected.add("warm up iteration started event");
+        expected.add("performance test");
+        expected.add("warm up iteration finished event");
+        expected.add("after warm up iteration");
+        expected.add("warm up finished event");
+        expected.add("after warm up");
+
+        expected.add("before performance test");
+        expected.add("execution started event");
+        expected.add("before performance iteration");
+        expected.add("execution iteration started event");
+        expected.add("performance test");
+        expected.add("execution iteration finished event");
+        expected.add("after performance iteration");
+        expected.add("execution finished event");
+        expected.add("after performance test");
+
+        JUnitCore.runClasses(PerformanceListeners.class);
+
+        Assert.assertEquals(expected, PerformanceListeners.executions);
+    }
+
+}



Mime
View raw message