JBoss Community Archive (Read Only)

Arquillian Old

Performance

The performance extension to Arquillian is a simple way of checking that the code you want to test performs within the range you want it to. It's can also automatically catch any performance regressions that might be added to your applications. - and as Arquillian itself, its very easy to use.

Code example

// include other arquillian imports here...
import org.jboss.arquillian.performance.annotation.Performance;
import org.jboss.arquillian.performance.annotation.PerformanceTest;

@PerformanceTest(resultsThreshold=2)
@RunWith(Arquillian.class)
public class WorkHardCdiTestCase
{
   @Deployment
   public static JavaArchive createDeployment() {
       return ShrinkWrap.create(JavaArchive.class ,"test.jar")
               .addPackage( WorkHard.class.getPackage())
               .addAsManifestResource(
                       EmptyAsset.INSTANCE,
                       ArchivePaths.create("beans.xml"));
   }
   
   @Inject HardWorker worker;
   
   @Test
   @Performance(time=20)
   public void doHardWork() throws Exception 
   {
      Assert.assertEquals(21, worker.workingHard(), 0d);
   }
}

As you can see the only two additions needed are @Performance and @PerformanceTest. They do different things and can be used seperately or combined.

@Performance require one argument, time (a double) which set the required maximum time that the test is allowed to spend in milliseconds. If the test exceeds that time it will fail with an exception explaining the cause.

@PerformanceTest will cause every testrun of that test to be saved and every new run will compare results with previous runs. If the new testrun exceeds the previous runs with a defined threshold an exception will be thrown. The threshold can be set with the parameter resultsThreshold. It is by default set to 1d.

How threshold is calculated: resultsThreshold * newTime < oldTime.

Maven setup exampleThe only extra dependency needed is to add arquillian-performance to your pom.xml. Take a look at the Getting started to see how you set up arquillian using maven.

<dependency>
   <groupId>org.jboss.arquillian.extension</groupId>
   <artifactId>arquillian-performance</artifactId>
   <version>${arquillian.version}</version>
   <scope>test</scope>
</dependency>
JBoss.org Content Archive (Read Only), exported from JBoss Community Documentation Editor at 2020-03-10 12:19:01 UTC, last content change 2011-04-16 15:43:46 UTC.