[jboss-svn-commits] JBoss Common SVN: r4449 - in arquillian/trunk: extensions and 21 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Thu May 27 02:05:19 EDT 2010
Author: stalep
Date: 2010-05-27 02:05:16 -0400 (Thu, 27 May 2010)
New Revision: 4449
Added:
arquillian/trunk/extensions/
arquillian/trunk/extensions/performance/
arquillian/trunk/extensions/performance/README
arquillian/trunk/extensions/performance/pom.xml
arquillian/trunk/extensions/performance/src/
arquillian/trunk/extensions/performance/src/main/
arquillian/trunk/extensions/performance/src/main/java/
arquillian/trunk/extensions/performance/src/main/java/org/
arquillian/trunk/extensions/performance/src/main/java/org/jboss/
arquillian/trunk/extensions/performance/src/main/java/org/jboss/arquillian/
arquillian/trunk/extensions/performance/src/main/java/org/jboss/arquillian/performance/
arquillian/trunk/extensions/performance/src/main/java/org/jboss/arquillian/performance/annotation/
arquillian/trunk/extensions/performance/src/main/java/org/jboss/arquillian/performance/annotation/Performance.java
arquillian/trunk/extensions/performance/src/main/java/org/jboss/arquillian/performance/annotation/PerformanceTest.java
arquillian/trunk/extensions/performance/src/main/java/org/jboss/arquillian/performance/event/
arquillian/trunk/extensions/performance/src/main/java/org/jboss/arquillian/performance/event/PerformanceResultStore.java
arquillian/trunk/extensions/performance/src/main/java/org/jboss/arquillian/performance/event/PerformanceTestParser.java
arquillian/trunk/extensions/performance/src/main/java/org/jboss/arquillian/performance/event/ResultComparator.java
arquillian/trunk/extensions/performance/src/main/java/org/jboss/arquillian/performance/event/TestPerformanceVerifier.java
arquillian/trunk/extensions/performance/src/main/java/org/jboss/arquillian/performance/exception/
arquillian/trunk/extensions/performance/src/main/java/org/jboss/arquillian/performance/exception/PerformanceException.java
arquillian/trunk/extensions/performance/src/main/java/org/jboss/arquillian/performance/meta/
arquillian/trunk/extensions/performance/src/main/java/org/jboss/arquillian/performance/meta/PerformanceClassResult.java
arquillian/trunk/extensions/performance/src/main/java/org/jboss/arquillian/performance/meta/PerformanceMethodResult.java
arquillian/trunk/extensions/performance/src/main/java/org/jboss/arquillian/performance/meta/PerformanceSuiteResult.java
arquillian/trunk/extensions/performance/src/test/
arquillian/trunk/extensions/performance/src/test/java/
arquillian/trunk/extensions/performance/src/test/java/org/
arquillian/trunk/extensions/performance/src/test/java/org/jboss/
arquillian/trunk/extensions/performance/src/test/java/org/jboss/arquillian/
arquillian/trunk/extensions/performance/src/test/java/org/jboss/arquillian/performance/
arquillian/trunk/extensions/performance/src/test/java/org/jboss/arquillian/performance/cdi/
arquillian/trunk/extensions/performance/src/test/java/org/jboss/arquillian/performance/cdi/HardWorker.java
arquillian/trunk/extensions/performance/src/test/java/org/jboss/arquillian/performance/cdi/WorkHard.java
arquillian/trunk/extensions/performance/src/test/java/org/jboss/arquillian/performance/cdi/WorkHardCdiTestCase.java
arquillian/trunk/extensions/performance/src/test/java/org/jboss/arquillian/performance/ejb/
arquillian/trunk/extensions/performance/src/test/java/org/jboss/arquillian/performance/ejb/WorkHard.java
arquillian/trunk/extensions/performance/src/test/java/org/jboss/arquillian/performance/ejb/WorkHardBean.java
arquillian/trunk/extensions/performance/src/test/java/org/jboss/arquillian/performance/ejb/WorkHardEjbTestCase.java
arquillian/trunk/extensions/performance/src/test/jboss-resources/
arquillian/trunk/extensions/performance/src/test/jboss-resources/jndi.properties
Log:
[ARQ-147]
Initial upload, simple performance checks on methods should work.
Notice the README since nothing works without hacking ClientProfileBuilder
and StandaloneClientProfileBuilder.
Added: arquillian/trunk/extensions/performance/README
===================================================================
--- arquillian/trunk/extensions/performance/README (rev 0)
+++ arquillian/trunk/extensions/performance/README 2010-05-27 06:05:16 UTC (rev 4449)
@@ -0,0 +1,34 @@
+Arquillian Performance Module
+..............................
+Arquillian Performance Module (apm) is a simple extension to
+Arquillian that will allow users to measure the duration of a
+test method and throw an exception if the duration is above our
+specified threshold.
+
+Arquillian performance module (apm) will atm not work without
+a few changes to ProfileBuilder and StandardProfileBuilder:
+- also add performance as a dependency for the impl-base module.
+
+
+$ svn diff src/main/java/org/jboss/arquillian/impl/context/StandaloneProfileBuilder.java
+Index: src/main/java/org/jboss/arquillian/impl/context/StandaloneProfileBuilder.java
+===================================================================
+--- src/main/java/org/jboss/arquillian/impl/context/StandaloneProfileBuilder.java (revision 4398)
++++ src/main/java/org/jboss/arquillian/impl/context/StandaloneProfileBuilder.java (working copy)
+@@ -18,6 +18,8 @@
+
+ import org.jboss.arquillian.impl.handler.ContainerTestExecuter;
+ import org.jboss.arquillian.impl.handler.TestCaseEnricher;
+ +import org.jboss.arquillian.performance.event.TestPerformanceVerifier;
+ +import org.jboss.arquillian.spi.event.suite.After;
+ import org.jboss.arquillian.spi.event.suite.Before;
+ import org.jboss.arquillian.spi.event.suite.Test;
+
+@@ -37,5 +39,6 @@
+ {
+ context.register(Before.class, new TestCaseEnricher());
+ context.register(Test.class, new ContainerTestExecuter());
+ + context.register(Test.class, new TestPerformanceVerifier());
+ }
+ }
+
Added: arquillian/trunk/extensions/performance/pom.xml
===================================================================
--- arquillian/trunk/extensions/performance/pom.xml (rev 0)
+++ arquillian/trunk/extensions/performance/pom.xml 2010-05-27 06:05:16 UTC (rev 4449)
@@ -0,0 +1,213 @@
+<?xml version="1.0" encoding="UTF-8"?>
+ <!--
+ vi:ts=2:sw=2:expandtab:
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+ <!-- Parent -->
+ <parent>
+ <groupId>org.jboss.arquillian</groupId>
+ <artifactId>arquillian-build</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ <relativePath>../../build/pom.xml</relativePath>
+ </parent>
+
+ <!-- Model Version -->
+ <modelVersion>4.0.0</modelVersion>
+
+ <!-- Artifact Configuration -->
+ <artifactId>arquillian-performance</artifactId>
+ <name>Arquillian Performance</name>
+ <description>Extension to add performance measurement to Arquillian</description>
+
+
+ <!-- Properties -->
+ <properties>
+
+
+ </properties>
+
+ <profiles>
+ <profile>
+ <id>default</id>
+ <activation>
+ <activeByDefault>true</activeByDefault>
+ </activation>
+ <dependencies>
+ <dependency> <!-- Need on all profiles except Glassfish to compile, api is not 100% up to date with final spec -->
+ <groupId>org.jboss.ejb3</groupId>
+ <artifactId>jboss-ejb3-api</artifactId>
+ <version>3.1.0</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+ <build>
+ <plugins>
+ <!-- Surefire -->
+ <plugin>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <!-- ARQ-60 -->
+ <skip>true</skip>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
+ <profile>
+ <id>weld-embedded</id>
+ <dependencies>
+ <dependency>
+ <groupId>org.jboss.arquillian.container</groupId>
+ <artifactId>arquillian-weld-embedded</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.ejb3</groupId>
+ <artifactId>jboss-ejb3-api</artifactId>
+ <version>3.1.0</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <includes>
+ <include>org/jboss/arquillian/performance/cdi/WorkHardCdiTestCase.class</include>
+ </includes>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
+ <profile>
+ <id>jbossas-remote-60</id>
+ <dependencies>
+ <dependency>
+ <groupId>org.jboss.arquillian.container</groupId>
+ <artifactId>arquillian-jbossas-remote-60</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency> <!-- Need on all profiles except Glassfish to compile, api is not 100% up to date with final spec -->
+ <groupId>org.jboss.ejb3</groupId>
+ <artifactId>jboss-ejb3-api</artifactId>
+ <version>3.1.0</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+ <build>
+ <testResources>
+ <testResource>
+ <directory>src/test/jboss-resources</directory>
+ </testResource>
+ </testResources>
+ </build>
+ </profile>
+
+ </profiles>
+ <!-- Dependencies -->
+ <dependencies>
+
+ <!--
+ org.jboss.arquillian
+ -->
+ <dependency>
+ <groupId>org.jboss.arquillian</groupId>
+ <artifactId>arquillian-api</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.arquillian</groupId>
+ <artifactId>arquillian-spi</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.jboss.shrinkwrap</groupId>
+ <artifactId>shrinkwrap-impl-base</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.shrinkwrap</groupId>
+ <artifactId>shrinkwrap-spi</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.jboss.ejb3</groupId>
+ <artifactId>jboss-ejb3-api</artifactId>
+ <version>3.1.0</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>javax.enterprise</groupId>
+ <artifactId>cdi-api</artifactId>
+ <version>1.0-SP1</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>javax.annotation</groupId>
+ <artifactId>jsr250-api</artifactId>
+ <version>1.0</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>javax.persistence</groupId>
+ <artifactId>persistence-api</artifactId>
+ <version>1.0</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.jboss.arquillian</groupId>
+ <artifactId>arquillian-junit</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.jboss.arquillian.container</groupId>
+ <artifactId>arquillian-weld-embedded</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.ejb3</groupId>
+ <artifactId>jboss-ejb3-api</artifactId>
+ <version>3.1.0</version>
+ <scope>test</scope>
+ </dependency>
+
+ <!-- External Projects -->
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-all</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-jar-plugin</artifactId>
+ <executions>
+ <execution>
+ <goals>
+ <goal>test-jar</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+</project>
+
Added: arquillian/trunk/extensions/performance/src/main/java/org/jboss/arquillian/performance/annotation/Performance.java
===================================================================
--- arquillian/trunk/extensions/performance/src/main/java/org/jboss/arquillian/performance/annotation/Performance.java (rev 0)
+++ arquillian/trunk/extensions/performance/src/main/java/org/jboss/arquillian/performance/annotation/Performance.java 2010-05-27 06:05:16 UTC (rev 4449)
@@ -0,0 +1,35 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed 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.jboss.arquillian.performance.annotation;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * Specifies the maximum execution time allowed for a test method.
+ * If the test method exceeds the specified time it throws an exception.
+ *
+ * @author <a href="mailto:stale.pedersen at jboss.org">Stale W. Pedersen</a>
+ * @version $Revision: 1.1 $
+ */
+ at Retention(RetentionPolicy.RUNTIME)
+ at Target(ElementType.METHOD)
+public @interface Performance {
+ double time();
+}
Added: arquillian/trunk/extensions/performance/src/main/java/org/jboss/arquillian/performance/annotation/PerformanceTest.java
===================================================================
--- arquillian/trunk/extensions/performance/src/main/java/org/jboss/arquillian/performance/annotation/PerformanceTest.java (rev 0)
+++ arquillian/trunk/extensions/performance/src/main/java/org/jboss/arquillian/performance/annotation/PerformanceTest.java 2010-05-27 06:05:16 UTC (rev 4449)
@@ -0,0 +1,45 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed 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.jboss.arquillian.performance.annotation;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Inherited;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * PerformanceTest defines a way of storing test results and compare them
+ * with previously stored tests. If newer tests results are worse than a
+ * specified threshold an exception will be thrown.
+ *
+ * It is possible to specify if you want to compare each test method or
+ * the combined total time of all the test methods.
+ *
+ *
+ * @author <a href="mailto:stale.pedersen at jboss.org">Stale W. Pedersen</a>
+ * @version $Revision: 1.1 $
+ */
+ at Retention(RetentionPolicy.RUNTIME)
+ at Target(ElementType.TYPE)
+ at Inherited
+public @interface PerformanceTest {
+
+ boolean reportDegradingResults() default true;
+ double resultsThreshold() default 1d;
+ boolean mergeTestResults() default false;
+}
Added: arquillian/trunk/extensions/performance/src/main/java/org/jboss/arquillian/performance/event/PerformanceResultStore.java
===================================================================
--- arquillian/trunk/extensions/performance/src/main/java/org/jboss/arquillian/performance/event/PerformanceResultStore.java (rev 0)
+++ arquillian/trunk/extensions/performance/src/main/java/org/jboss/arquillian/performance/event/PerformanceResultStore.java 2010-05-27 06:05:16 UTC (rev 4449)
@@ -0,0 +1,33 @@
+package org.jboss.arquillian.performance.event;
+
+import org.jboss.arquillian.performance.meta.PerformanceSuiteResult;
+import org.jboss.arquillian.spi.Context;
+import org.jboss.arquillian.spi.event.suite.EventHandler;
+import org.jboss.arquillian.spi.event.suite.SuiteEvent;
+
+/**
+ *
+ *
+ *
+ * fired during afterSuite
+ *
+ * @author <a href="mailto:stale.pedersen at jboss.org">Stale W. Pedersen</a>
+ * @version $Revision: 1.1 $
+ */
+
+public class PerformanceResultStore implements EventHandler<SuiteEvent>
+{
+
+
+ public void callback(Context context, SuiteEvent event) throws Exception
+ {
+ PerformanceSuiteResult suiteResult = (PerformanceSuiteResult) context.get(PerformanceSuiteResult.class);
+
+ if(suiteResult != null)
+ {
+ //TODO: compare, fetch, save.
+ System.out.println("SuiteResult is ON!!!");
+ }
+ }
+
+}
Added: arquillian/trunk/extensions/performance/src/main/java/org/jboss/arquillian/performance/event/PerformanceTestParser.java
===================================================================
--- arquillian/trunk/extensions/performance/src/main/java/org/jboss/arquillian/performance/event/PerformanceTestParser.java (rev 0)
+++ arquillian/trunk/extensions/performance/src/main/java/org/jboss/arquillian/performance/event/PerformanceTestParser.java 2010-05-27 06:05:16 UTC (rev 4449)
@@ -0,0 +1,67 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed 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.jboss.arquillian.performance.event;
+
+import org.jboss.arquillian.performance.annotation.*;
+import org.jboss.arquillian.performance.meta.PerformanceClassResult;
+import org.jboss.arquillian.performance.meta.PerformanceSuiteResult;
+import org.jboss.arquillian.spi.Context;
+import org.jboss.arquillian.spi.event.suite.ClassEvent;
+import org.jboss.arquillian.spi.event.suite.EventHandler;
+
+/**
+ *
+ * A PerformanceRuleParser.
+ *
+ * @author <a href="mailto:stale.pedersen at jboss.org">Stale W. Pedersen</a>
+ * @version $Revision: 1.1 $
+ */
+public class PerformanceTestParser implements EventHandler<ClassEvent>
+{
+ /**
+ * @see org.jboss.arquillian.spi.event.suite.EventHandler#callback(org.jboss.arquillian.spi.Context, java.lang.Object)
+ */
+ public void callback(Context context, ClassEvent event) throws Exception
+ {
+ parsePerformanceRules(context, event.getTestClass());
+ }
+
+ public void parsePerformanceRules(Context context, Class testClass)
+ {
+ PerformanceTest performanceTest = (PerformanceTest) testClass.getAnnotation(PerformanceTest.class);
+ if(performanceTest != null)
+ {
+ PerformanceClassResult classPerformance =
+ new PerformanceClassResult(performanceTest, testClass.getName());
+
+ PerformanceSuiteResult suitePerformance =
+ context.getParentContext().get(PerformanceSuiteResult.class);
+ if(suitePerformance == null)
+ {
+ suitePerformance = new PerformanceSuiteResult();
+ context.getParentContext().add(PerformanceSuiteResult.class, suitePerformance);
+ }
+
+ suitePerformance.addClassResult(testClass.getName(), classPerformance);
+// setThreshold(performanceTest.resultsThreshold());
+ System.out.println("PerformanceTest is: "+performanceTest.resultsThreshold());
+ }
+ else
+ System.out.println("PerformanceTest is NULL!");
+
+ }
+}
Added: arquillian/trunk/extensions/performance/src/main/java/org/jboss/arquillian/performance/event/ResultComparator.java
===================================================================
--- arquillian/trunk/extensions/performance/src/main/java/org/jboss/arquillian/performance/event/ResultComparator.java (rev 0)
+++ arquillian/trunk/extensions/performance/src/main/java/org/jboss/arquillian/performance/event/ResultComparator.java 2010-05-27 06:05:16 UTC (rev 4449)
@@ -0,0 +1,23 @@
+package org.jboss.arquillian.performance.event;
+
+import org.jboss.arquillian.spi.Context;
+import org.jboss.arquillian.spi.event.suite.EventHandler;
+import org.jboss.arquillian.spi.event.suite.SuiteEvent;
+
+/**
+ *
+ *
+ *
+ * fired in afterSuite.
+ *
+ * @author <a href="mailto:stale.pedersen at jboss.org">Stale W. Pedersen</a>
+ * @version $Revision: 1.1 $
+ */
+public class ResultComparator implements EventHandler<SuiteEvent>
+{
+
+ public void callback(Context context, SuiteEvent event) throws Exception
+ {
+ System.out.println("resultComparator");
+ }
+}
Added: arquillian/trunk/extensions/performance/src/main/java/org/jboss/arquillian/performance/event/TestPerformanceVerifier.java
===================================================================
--- arquillian/trunk/extensions/performance/src/main/java/org/jboss/arquillian/performance/event/TestPerformanceVerifier.java (rev 0)
+++ arquillian/trunk/extensions/performance/src/main/java/org/jboss/arquillian/performance/event/TestPerformanceVerifier.java 2010-05-27 06:05:16 UTC (rev 4449)
@@ -0,0 +1,77 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed 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.jboss.arquillian.performance.event;
+
+import java.lang.annotation.Annotation;
+
+import org.jboss.arquillian.performance.annotation.Performance;
+import org.jboss.arquillian.performance.exception.PerformanceException;
+import org.jboss.arquillian.performance.meta.PerformanceClassResult;
+import org.jboss.arquillian.performance.meta.PerformanceMethodResult;
+import org.jboss.arquillian.performance.meta.PerformanceSuiteResult;
+import org.jboss.arquillian.spi.Context;
+import org.jboss.arquillian.spi.TestResult;
+import org.jboss.arquillian.spi.TestResult.Status;
+import org.jboss.arquillian.spi.event.suite.EventHandler;
+import org.jboss.arquillian.spi.event.suite.Test;
+
+/**
+ *
+ * TestPerformanceVerifier.
+ * Verify that the test method execution time isnt longer that specified in the
+ * Performance annotation.
+ * @see org.jboss.arquillian.performance.annotation.Performance
+ *
+ * @author <a href="mailto:stale.pedersen at jboss.org">Stale W. Pedersen</a>
+ * @version $Revision: 1.1 $
+ */
+public class TestPerformanceVerifier implements EventHandler<Test>
+{
+
+ public void callback(Context context, Test event) throws Exception
+ {
+ TestResult result = context.get(TestResult.class);
+ if(result != null)
+ {
+ //check if we have set a threshold
+ Performance performance = null;
+ Annotation[] annotations = event.getTestMethod().getDeclaredAnnotations();
+ for(Annotation a : annotations)
+ if(a.annotationType().getName().equals(Performance.class.getCanonicalName()))
+ performance = (Performance) a;
+
+ if(performance != null)
+ {
+ if(performance.time() > 0 &&
+ performance.time() < (result.getEnd()-result.getStart()))
+ {
+ result.setStatus(Status.FAILED);
+ result.setThrowable(new PerformanceException("The test didnt finish within the specified time: "+performance.time()+"ms"));
+ }
+
+ // fetch suiteResult, get the correct classResult and append the test to that
+ // classResult.
+ PerformanceSuiteResult suiteResult = context.getParentContext().getParentContext().get(PerformanceSuiteResult.class);
+ suiteResult.getResult(event.getTestClass().getName()).addMethodResult(
+ new PerformanceMethodResult(
+ performance.time(),
+ (result.getEnd()-result.getStart()),
+ event.getTestMethod()));
+ }
+ }
+ }
+}
Added: arquillian/trunk/extensions/performance/src/main/java/org/jboss/arquillian/performance/exception/PerformanceException.java
===================================================================
--- arquillian/trunk/extensions/performance/src/main/java/org/jboss/arquillian/performance/exception/PerformanceException.java (rev 0)
+++ arquillian/trunk/extensions/performance/src/main/java/org/jboss/arquillian/performance/exception/PerformanceException.java 2010-05-27 06:05:16 UTC (rev 4449)
@@ -0,0 +1,33 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed 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.jboss.arquillian.performance.exception;
+
+/**
+ * A PerformanceException.
+ *
+ * @author <a href="mailto:stale.pedersen at jboss.org">Stale W. Pedersen</a>
+ * @version $Revision: 1.1 $
+ */
+ at SuppressWarnings("serial")
+public class PerformanceException extends Exception
+{
+ public PerformanceException(String msg)
+ {
+ super(msg);
+ }
+
+}
Added: arquillian/trunk/extensions/performance/src/main/java/org/jboss/arquillian/performance/meta/PerformanceClassResult.java
===================================================================
--- arquillian/trunk/extensions/performance/src/main/java/org/jboss/arquillian/performance/meta/PerformanceClassResult.java (rev 0)
+++ arquillian/trunk/extensions/performance/src/main/java/org/jboss/arquillian/performance/meta/PerformanceClassResult.java 2010-05-27 06:05:16 UTC (rev 4449)
@@ -0,0 +1,73 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed 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.jboss.arquillian.performance.meta;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.jboss.arquillian.performance.annotation.PerformanceTest;
+
+/**
+ * A PerformanceClassResult.
+ *
+ * @author <a href="mailto:stale.pedersen at jboss.org">Stale W. Pedersen</a>
+ * @version $Revision: 1.1 $
+ */
+public class PerformanceClassResult
+{
+ private List<PerformanceMethodResult> methodResults;
+ private PerformanceTest performanceSpecs;
+ private String testClassName;
+ public PerformanceClassResult(PerformanceTest performanceSpecs, String testClassName)
+ {
+ setPerformanceSpecs(performanceSpecs);
+ setTestClassName(testClassName);
+ methodResults = new ArrayList<PerformanceMethodResult>();
+ }
+
+ public List<PerformanceMethodResult> getMethodResults()
+ {
+ return methodResults;
+ }
+
+ public void addMethodResult(PerformanceMethodResult methodResult)
+ {
+ methodResults.add(methodResult);
+ }
+
+ public PerformanceTest getPerformanceSpecs()
+ {
+ return performanceSpecs;
+ }
+
+ private void setPerformanceSpecs(PerformanceTest performanceSpecs)
+ {
+ this.performanceSpecs = performanceSpecs;
+ }
+
+ public String getTestClassName()
+ {
+ return testClassName;
+ }
+
+ private void setTestClassName(String testClassName)
+ {
+ this.testClassName = testClassName;
+ }
+
+
+}
Added: arquillian/trunk/extensions/performance/src/main/java/org/jboss/arquillian/performance/meta/PerformanceMethodResult.java
===================================================================
--- arquillian/trunk/extensions/performance/src/main/java/org/jboss/arquillian/performance/meta/PerformanceMethodResult.java (rev 0)
+++ arquillian/trunk/extensions/performance/src/main/java/org/jboss/arquillian/performance/meta/PerformanceMethodResult.java 2010-05-27 06:05:16 UTC (rev 4449)
@@ -0,0 +1,64 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed 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.jboss.arquillian.performance.meta;
+
+import java.lang.reflect.Method;
+
+/**
+ * A PerformanceMethodResult.
+ *
+ * @author <a href="mailto:stale.pedersen at jboss.org">Stale W. Pedersen</a>
+ * @version $Revision: 1.1 $
+ */
+public class PerformanceMethodResult
+{
+
+ private double maxTime;
+ private double actualTime;
+ private Method testMethod;
+
+ public PerformanceMethodResult(double maxTime, double actualTime, Method testMethod)
+ {
+ setMaxTime(maxTime);
+ setActualTime(actualTime);
+ setTestMethod(testMethod);
+ }
+ public double getMaxTime()
+ {
+ return maxTime;
+ }
+ private void setMaxTime(double maxTime)
+ {
+ this.maxTime = maxTime;
+ }
+ public double getActualTime()
+ {
+ return actualTime;
+ }
+ private void setActualTime(double actualTime)
+ {
+ this.actualTime = actualTime;
+ }
+ public Method getTestMethod()
+ {
+ return testMethod;
+ }
+ private void setTestMethod(Method testMethod)
+ {
+ this.testMethod = testMethod;
+ }
+}
Added: arquillian/trunk/extensions/performance/src/main/java/org/jboss/arquillian/performance/meta/PerformanceSuiteResult.java
===================================================================
--- arquillian/trunk/extensions/performance/src/main/java/org/jboss/arquillian/performance/meta/PerformanceSuiteResult.java (rev 0)
+++ arquillian/trunk/extensions/performance/src/main/java/org/jboss/arquillian/performance/meta/PerformanceSuiteResult.java 2010-05-27 06:05:16 UTC (rev 4449)
@@ -0,0 +1,53 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed 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.jboss.arquillian.performance.meta;
+
+import java.io.Serializable;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * A PerformanceSuiteResult.
+ *
+ * @author <a href="mailto:stale.pedersen at jboss.org">Stale W. Pedersen</a>
+ * @version $Revision: 1.1 $
+ */
+public class PerformanceSuiteResult implements Serializable
+{
+ private Map<String, PerformanceClassResult> classResults;
+
+ public PerformanceSuiteResult()
+ {
+ classResults = new HashMap<String, PerformanceClassResult>();
+ }
+
+ public Map<String, PerformanceClassResult> getResults()
+ {
+ return classResults;
+ }
+
+ public PerformanceClassResult getResult(String className)
+ {
+ return classResults.get(className);
+ }
+
+ public void addClassResult(String className, PerformanceClassResult result)
+ {
+ classResults.put(className, result);
+ }
+
+}
Added: arquillian/trunk/extensions/performance/src/test/java/org/jboss/arquillian/performance/cdi/HardWorker.java
===================================================================
--- arquillian/trunk/extensions/performance/src/test/java/org/jboss/arquillian/performance/cdi/HardWorker.java (rev 0)
+++ arquillian/trunk/extensions/performance/src/test/java/org/jboss/arquillian/performance/cdi/HardWorker.java 2010-05-27 06:05:16 UTC (rev 4449)
@@ -0,0 +1,15 @@
+package org.jboss.arquillian.performance.cdi;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.enterprise.inject.Produces;
+import javax.inject.Named;
+
+ at ApplicationScoped
+public class HardWorker
+{
+
+ @Produces @Named @WorkHard double workingHard()
+ {
+ return 21;
+ }
+}
Added: arquillian/trunk/extensions/performance/src/test/java/org/jboss/arquillian/performance/cdi/WorkHard.java
===================================================================
--- arquillian/trunk/extensions/performance/src/test/java/org/jboss/arquillian/performance/cdi/WorkHard.java (rev 0)
+++ arquillian/trunk/extensions/performance/src/test/java/org/jboss/arquillian/performance/cdi/WorkHard.java 2010-05-27 06:05:16 UTC (rev 4449)
@@ -0,0 +1,15 @@
+package org.jboss.arquillian.performance.cdi;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+import javax.inject.Qualifier;
+
+ at Qualifier
+ at Retention(RetentionPolicy.RUNTIME)
+ at Target({ElementType.TYPE, ElementType.METHOD, ElementType.PARAMETER, ElementType.FIELD})
+public @interface WorkHard {
+
+}
Added: arquillian/trunk/extensions/performance/src/test/java/org/jboss/arquillian/performance/cdi/WorkHardCdiTestCase.java
===================================================================
--- arquillian/trunk/extensions/performance/src/test/java/org/jboss/arquillian/performance/cdi/WorkHardCdiTestCase.java (rev 0)
+++ arquillian/trunk/extensions/performance/src/test/java/org/jboss/arquillian/performance/cdi/WorkHardCdiTestCase.java 2010-05-27 06:05:16 UTC (rev 4449)
@@ -0,0 +1,53 @@
+package org.jboss.arquillian.performance.cdi;
+
+import javax.inject.Inject;
+
+import org.jboss.arquillian.api.Deployment;
+import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.arquillian.performance.annotation.PerformanceTest;
+import org.jboss.arquillian.performance.annotation.Performance;
+import org.jboss.shrinkwrap.api.ArchivePaths;
+import org.jboss.shrinkwrap.api.ShrinkWrap;
+import org.jboss.shrinkwrap.api.spec.JavaArchive;
+import org.jboss.shrinkwrap.impl.base.asset.ByteArrayAsset;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+ at PerformanceTest(reportDegradingResults=true)
+ at RunWith(Arquillian.class)
+public class WorkHardCdiTestCase
+{
+
+ @Deployment
+ public static JavaArchive createDeployment() {
+ return ShrinkWrap.create("test.jar", JavaArchive.class)
+ .addPackage(
+ WorkHard.class.getPackage()
+ )
+ .addManifestResource(
+ new ByteArrayAsset("<beans/>".getBytes()),
+ ArchivePaths.create("beans.xml"));
+ }
+
+ @Inject @WorkHard double hardWorker;
+
+ @Test
+ @Performance(time=20)
+ public void doHardWork() throws Exception
+ {
+ Assert.assertEquals(21, hardWorker, 0d);
+ }
+
+ /**
+ * This method is supposed to fail!
+ *
+ * @throws Exception
+ */
+ @Test
+ @Performance(time=0.01)
+ public void doHardWorkThatFails() throws Exception
+ {
+ Assert.assertEquals(21, hardWorker, 0d);
+ }
+}
Added: arquillian/trunk/extensions/performance/src/test/java/org/jboss/arquillian/performance/ejb/WorkHard.java
===================================================================
--- arquillian/trunk/extensions/performance/src/test/java/org/jboss/arquillian/performance/ejb/WorkHard.java (rev 0)
+++ arquillian/trunk/extensions/performance/src/test/java/org/jboss/arquillian/performance/ejb/WorkHard.java 2010-05-27 06:05:16 UTC (rev 4449)
@@ -0,0 +1,11 @@
+package org.jboss.arquillian.performance.ejb;
+
+import javax.ejb.Local;
+
+public @Local
+interface WorkHard
+{
+ double workHard();
+
+ double workVeryHard();
+}
Added: arquillian/trunk/extensions/performance/src/test/java/org/jboss/arquillian/performance/ejb/WorkHardBean.java
===================================================================
--- arquillian/trunk/extensions/performance/src/test/java/org/jboss/arquillian/performance/ejb/WorkHardBean.java (rev 0)
+++ arquillian/trunk/extensions/performance/src/test/java/org/jboss/arquillian/performance/ejb/WorkHardBean.java 2010-05-27 06:05:16 UTC (rev 4449)
@@ -0,0 +1,27 @@
+package org.jboss.arquillian.performance.ejb;
+
+import javax.annotation.Resource;
+import javax.ejb.EJBContext;
+import javax.ejb.Stateless;
+
+public @Stateless class WorkHardBean implements WorkHard
+{
+ @Resource EJBContext ctx;
+
+ public double workHard()
+ {
+ System.out.println("doing some hard work here...");
+ return 21;
+ }
+
+ public double workVeryHard()
+ {
+ System.out.println("doing some harder work here...");
+ return 42;
+ }
+
+ public boolean isTransactional() {
+ ctx.setRollbackOnly();
+ return ctx.getRollbackOnly();
+ }
+}
Added: arquillian/trunk/extensions/performance/src/test/java/org/jboss/arquillian/performance/ejb/WorkHardEjbTestCase.java
===================================================================
--- arquillian/trunk/extensions/performance/src/test/java/org/jboss/arquillian/performance/ejb/WorkHardEjbTestCase.java (rev 0)
+++ arquillian/trunk/extensions/performance/src/test/java/org/jboss/arquillian/performance/ejb/WorkHardEjbTestCase.java 2010-05-27 06:05:16 UTC (rev 4449)
@@ -0,0 +1,30 @@
+package org.jboss.arquillian.performance.ejb;
+
+import javax.ejb.EJB;
+
+import org.jboss.arquillian.api.Deployment;
+import org.jboss.shrinkwrap.api.ShrinkWrap;
+import org.jboss.shrinkwrap.api.spec.JavaArchive;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+ at RunWith(org.jboss.arquillian.junit.Arquillian.class)
+public class WorkHardEjbTestCase
+{
+
+ @EJB
+ private WorkHard hardWorker;
+
+ @Deployment
+ public static JavaArchive createTestArchive() {
+ return ShrinkWrap.create("test.jar", JavaArchive.class)
+ .addClasses(WorkHard.class, WorkHardBean.class);
+ }
+
+ @Test
+ public void testHardWorker()
+ {
+ Assert.assertEquals(21d, hardWorker.workHard(), 0d);
+ }
+}
Added: arquillian/trunk/extensions/performance/src/test/jboss-resources/jndi.properties
===================================================================
--- arquillian/trunk/extensions/performance/src/test/jboss-resources/jndi.properties (rev 0)
+++ arquillian/trunk/extensions/performance/src/test/jboss-resources/jndi.properties 2010-05-27 06:05:16 UTC (rev 4449)
@@ -0,0 +1,3 @@
+java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
+java.naming.factory.url.pkgs=org.jboss.naming\:org.jnp.interfaces
+java.naming.provider.url=jnp://localhost:1099
\ No newline at end of file
More information about the jboss-svn-commits
mailing list