Skip to content

Commit

Permalink
[ARQ-147]
Browse files Browse the repository at this point in the history
rewrote to use TestContextAppender.
note: do not work yet because of defects in start/stop measuerement
  • Loading branch information
Ståle W. Pedersen committed Jul 20, 2010
1 parent acf2994 commit e5d47dd
Show file tree
Hide file tree
Showing 12 changed files with 197 additions and 74 deletions.
76 changes: 15 additions & 61 deletions pom.xml
Expand Up @@ -24,7 +24,11 @@

<!-- Properties -->
<properties>
<!-- Versioning -->
<maven.test.failure.ignore>true</maven.test.failure.ignore>
<!-- Versioning -->
<!--
<version.weld_core>1.0.2-SNAPSHOT</version.weld_core>
-->
<version.weld_core>1.0.1-SP1</version.weld_core>
<version.org.apache.openejb_openejb.core>3.1.2</version.org.apache.openejb_openejb.core>
<version.openwebbeans>1.0.0-M4</version.openwebbeans>
Expand All @@ -37,10 +41,7 @@

<profiles>
<profile>
<id>default</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<id>not-used</id>
<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>
Expand All @@ -63,11 +64,14 @@
</build>
</profile>
<profile>
<id>weld-embedded</id>
<id>default</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<dependencies>
<dependency>
<groupId>org.jboss.arquillian.container</groupId>
<artifactId>arquillian-weld-se-embedded</artifactId>
<artifactId>arquillian-weld-se-embedded-1</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
Expand All @@ -91,7 +95,7 @@
<dependency>
<groupId>javax.el</groupId>
<artifactId>el-api</artifactId>
<version>1.2</version>
<version>2.2</version>
</dependency>
</dependencies>
<dependencyManagement>
Expand Down Expand Up @@ -120,63 +124,14 @@
</plugins>
</build>
</profile>
<profile>
<id>jbossas-remote-60</id>
<dependencies>
<dependency>
<groupId>org.jboss.arquillian.container</groupId>
<artifactId>arquillian-jbossas-remote-6</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>${version.jboss_ejb3}</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>${version.jboss_ejb3}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.enterprise</groupId>
<artifactId>cdi-api</artifactId>
Expand All @@ -195,27 +150,26 @@
<version>1.0</version>
<scope>test</scope>
</dependency>

<dependency>
<dependency>
<groupId>org.jboss.arquillian</groupId>
<artifactId>arquillian-junit</artifactId>
<version>${project.version}</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>
Expand Down
Expand Up @@ -31,5 +31,10 @@
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface Performance {
/**
* Specify how long the method maximum should take i ms
*
* @return
*/
double time();
}
@@ -1,13 +1,18 @@
package org.jboss.arquillian.performance.event;

import java.io.File;
import java.io.FileFilter;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

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.EventHandler;
Expand All @@ -26,14 +31,12 @@
public class PerformanceResultStore implements EventHandler<SuiteEvent>
{
private final String folder = "arq-perf";
private static final SimpleDateFormat fileFormat = new SimpleDateFormat("dd.MM.yy.mm.ss");
// private final String filename = ""
private final SimpleDateFormat fileFormat = new SimpleDateFormat("dd.MM.yy.mm.ss");

public void callback(Context context, SuiteEvent event) throws Exception
{
PerformanceSuiteResult suiteResult = (PerformanceSuiteResult) context.get(PerformanceSuiteResult.class);



if(suiteResult != null)
{
//TODO: compare, fetch, save.
Expand All @@ -46,13 +49,80 @@ public void callback(Context context, SuiteEvent event) throws Exception

private void comparePerformanceSuiteResults(PerformanceSuiteResult suiteResult)
{
List<PerformanceSuiteResult> prevResults = findEarlierResults(suiteResult);

for(PerformanceSuiteResult result : prevResults)
{
if(!doCompareResults(result, suiteResult))
//throw some exception
System.out.println("the new result wasnt within the specified delta");
else
System.out.println("the new result is OK");
}

//everything went well, now we just store the new result and we're done
storePerformanceSuiteResult(suiteResult);
}

private List<PerformanceSuiteResult> findEarlierResults(PerformanceSuiteResult suiteResult)
private boolean doCompareResults(PerformanceSuiteResult oldResult, PerformanceSuiteResult newResult)
{

return null;
for(String className : oldResult.getResults().keySet())
{
PerformanceClassResult oldClassResult = oldResult.getResult(className);
PerformanceClassResult newClassResult = newResult.getResult(className);
oldClassResult.compareResults(newClassResult);
}
// TODO Auto-generated method stub
return true;
}

/**
*
* @param suiteResult
* @return
*/
private List<PerformanceSuiteResult> findEarlierResults(final PerformanceSuiteResult currentResult)
{
File perfDir = new File(System.getProperty("user.dir")+File.separator+folder);
File[] files = perfDir.listFiles(new FileFilter() {

public boolean accept(File pathname)
{
if(pathname.getName().startsWith(currentResult.getName()))
return true;
else
return false;
}

});
List<PerformanceSuiteResult> prevResults = new ArrayList<PerformanceSuiteResult>();
for(File f : files)
{
System.out.println("THESE ARE OUR PREV STORED TESTS: "+f.getName());
PerformanceSuiteResult result = getResultFromFile(f);
if(result != null)
prevResults.add(result);
}
return prevResults;
}

private PerformanceSuiteResult getResultFromFile(File file)
{
try
{
FileInputStream fis = new FileInputStream(file);
ObjectInputStream ois = new ObjectInputStream(fis);
return (PerformanceSuiteResult) ois.readObject();
}
catch(IOException ioe)
{
return null;
}
catch (ClassNotFoundException e)
{
e.printStackTrace();
return null;
}
}

/**
Expand Down
@@ -0,0 +1,39 @@
/*
* 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.spi.Context;
import org.jboss.arquillian.spi.TestContextAppender;
import org.jboss.arquillian.spi.event.suite.Test;

/**
*
* A PerformanceTestContextAppender.
*
* @author <a href="mailto:stale.pedersen@jboss.org">Stale W. Pedersen</a>
* @version $Revision: 1.1 $
*/
public class PerformanceTestContextAppender implements TestContextAppender
{

public void append(Context context)
{
context.register(Test.class, new TestPerformanceVerifier());

}

}
Expand Up @@ -20,6 +20,7 @@
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.TestClass;
import org.jboss.arquillian.spi.event.suite.ClassEvent;
import org.jboss.arquillian.spi.event.suite.EventHandler;

Expand All @@ -40,7 +41,7 @@ public void callback(Context context, ClassEvent event) throws Exception
parsePerformanceRules(context, event.getTestClass());
}

public void parsePerformanceRules(Context context, Class testClass)
public void parsePerformanceRules(Context context, TestClass testClass)
{
PerformanceTest performanceTest = (PerformanceTest) testClass.getAnnotation(PerformanceTest.class);
if(performanceTest != null)
Expand Down
Expand Up @@ -60,8 +60,11 @@ public void callback(Context context, Test event) throws Exception
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"));
result.setThrowable(
new PerformanceException("The test didnt finish within the specified time: "
+performance.time()+"ms, it took "+(result.getEnd()-result.getStart())+"ms."));
}
System.out.println("The test took "+(result.getEnd()-result.getStart())+"ms.");

// fetch suiteResult, get the correct classResult and append the test to that
// classResult.
Expand Down
Expand Up @@ -48,6 +48,15 @@ public List<PerformanceMethodResult> getMethodResults()
{
return methodResults;
}

public PerformanceMethodResult getMethodResult(String methodName)
{
for(PerformanceMethodResult pmr : methodResults)
if(pmr.getTestMethod().equals(methodName))
return pmr;

return null;
}

public void addMethodResult(PerformanceMethodResult methodResult)
{
Expand All @@ -73,6 +82,17 @@ private void setTestClassName(String testClassName)
{
this.testClassName = testClassName;
}

public void compareResults(PerformanceClassResult pcr)
{
if(pcr == null)
throw new NullPointerException("Compared class is null!");

for(PerformanceMethodResult pmr : getMethodResults())
{
pmr.compareResults(pcr.getMethodResult(pmr.getTestMethod()), performanceSpecs.resultsThreshold());
}
}


}
Expand Up @@ -65,4 +65,18 @@ private void setTestMethod(String testMethod)
{
this.testMethod = testMethod;
}
public void compareResults(PerformanceMethodResult methodResult, double resultsThreshold)
{
System.out.println("methods compared: "+testMethod+", and: "+methodResult.getTestMethod());
System.out.println("Comparing: "+actualTime+" to: "+methodResult.getActualTime());
System.out.println("Threshold is: "+resultsThreshold);
if((resultsThreshold +1) * actualTime < methodResult.getActualTime())
{
System.out.println("WE FAILED");
throw new RuntimeException("Method1 actual time: "+actualTime+
", Method2: "+methodResult.getActualTime()+
", threshold: "+resultsThreshold);
}

}
}

0 comments on commit e5d47dd

Please sign in to comment.