Add profile with performance tests

This commit is contained in:
Dominik Przybysz 2015-12-28 09:18:02 +01:00
parent 951a0f1b56
commit 7a13cb2ce5
2 changed files with 47 additions and 37 deletions

View file

@ -35,33 +35,38 @@
<exec-maven-plugin.version>1.4.0</exec-maven-plugin.version> <exec-maven-plugin.version>1.4.0</exec-maven-plugin.version>
</properties> </properties>
<build> <profiles>
<plugins> <profile>
<plugin> <id>performance-test</id>
<groupId>org.codehaus.mojo</groupId> <build>
<artifactId>exec-maven-plugin</artifactId> <plugins>
<version>${exec-maven-plugin.version}</version> <plugin>
<executions> <groupId>org.codehaus.mojo</groupId>
<execution> <artifactId>exec-maven-plugin</artifactId>
<id>run-benchmarks</id> <version>${exec-maven-plugin.version}</version>
<phase>integration-test</phase> <executions>
<goals> <execution>
<goal>exec</goal> <id>run-benchmarks</id>
</goals> <phase>integration-test</phase>
<configuration> <goals>
<classpathScope>test</classpathScope> <goal>exec</goal>
<executable>java</executable> </goals>
<arguments> <configuration>
<argument>-classpath</argument> <classpathScope>test</classpathScope>
<classpath/> <executable>java</executable>
<argument>org.openjdk.jmh.Main</argument> <arguments>
<argument>.*</argument> <argument>-classpath</argument>
</arguments> <classpath/>
</configuration> <argument>org.openjdk.jmh.Main</argument>
</execution> <argument>.*</argument>
</executions> </arguments>
</plugin> </configuration>
</plugins> </execution>
</build> </executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project> </project>

View file

@ -6,8 +6,16 @@ import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.ContentType; import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity; import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.HttpClients; import org.apache.http.impl.client.HttpClients;
import org.openjdk.jmh.annotations.*; import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.infra.BenchmarkParams; import org.openjdk.jmh.annotations.BenchmarkMode;
import org.openjdk.jmh.annotations.Measurement;
import org.openjdk.jmh.annotations.Mode;
import org.openjdk.jmh.annotations.OutputTimeUnit;
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.Setup;
import org.openjdk.jmh.annotations.State;
import org.openjdk.jmh.annotations.TearDown;
import org.openjdk.jmh.annotations.Warmup;
import org.openjdk.jmh.infra.Blackhole; import org.openjdk.jmh.infra.Blackhole;
import org.openjdk.jmh.infra.ThreadParams; import org.openjdk.jmh.infra.ThreadParams;
import pl.touk.mockserver.api.request.AddMock; import pl.touk.mockserver.api.request.AddMock;
@ -21,11 +29,10 @@ import java.util.concurrent.TimeUnit;
public class MockserverTest { public class MockserverTest {
HttpMockServer httpMockServer; HttpMockServer httpMockServer;
@Param({"9000", "8000"}) int initialPort = 9000;
int initialPort;
@Setup @Setup
public void prepareMockServer(BenchmarkParams params) { public void prepareMockServer() {
httpMockServer = new HttpMockServer(9999); httpMockServer = new HttpMockServer(9999);
} }
@ -49,11 +56,9 @@ public class MockserverTest {
} }
@Benchmark @Benchmark
@Measurement(iterations = 10) @Measurement(iterations = 20)
@Fork(value = 2)
@BenchmarkMode({Mode.AverageTime, Mode.Throughput, Mode.SampleTime}) @BenchmarkMode({Mode.AverageTime, Mode.Throughput, Mode.SampleTime})
@Warmup(iterations = 5) @Warmup(iterations = 10)
@Threads(4)
public void shouldHandleManyRequestsSimultaneously(TestState testState, Blackhole bh) throws IOException { public void shouldHandleManyRequestsSimultaneously(TestState testState, Blackhole bh) throws IOException {
int current = testState.current; int current = testState.current;
int endpointNumber = current % 10; int endpointNumber = current % 10;