-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathRestImplementationsBenchmark.java
52 lines (41 loc) · 1.46 KB
/
RestImplementationsBenchmark.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package psamolysov.demo.restws.benchmark;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.WebTarget;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.BenchmarkMode;
import org.openjdk.jmh.annotations.Mode;
import org.openjdk.jmh.annotations.Param;
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.Setup;
import org.openjdk.jmh.annotations.State;
@State(Scope.Benchmark)
@BenchmarkMode(Mode.Throughput)
public class RestImplementationsBenchmark {
@Param("localhost")
private String server;
@Param("9080")
private int port;
@Param("/message")
private String path;
@State(Scope.Thread)
public static class BenchmarkContext {
private static final String MAIN_URL_FMT =
"http://{host}:{port}/rest-ws-{implementation}/api";
@Param({"ejb", "cdi", "spring"})
private String implementation;
private WebTarget target;
@Setup
public void initClient() {
target = ClientBuilder.newClient().target(MAIN_URL_FMT);
}
}
@Benchmark
public void messages(BenchmarkContext ctx) {
ctx.target.resolveTemplate("host", server)
.resolveTemplate("port", port)
.resolveTemplate("implementation", ctx.implementation)
.path(path)
.request()
.get(String.class);
}
}