-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathRequestScopedProxyInvocationBenchmark.java
64 lines (51 loc) · 1.81 KB
/
RequestScopedProxyInvocationBenchmark.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
53
54
55
56
57
58
59
60
61
62
63
64
package io.quarkus.arc.benchmarks;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.Measurement;
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 io.quarkus.arc.Arc;
import io.quarkus.arc.ArcContainer;
import io.quarkus.arc.ManagedContext;
@Warmup(batchSize = 8192)
@Measurement(batchSize = 8192)
public class RequestScopedProxyInvocationBenchmark extends BenchmarkBase {
private SimpleReqScopedBean1 reqBean;
// this state object ensures that the request context is activate for each run
// we do not want to activate/terminate the request contex per each run but merely test the proxy invocation itself
@State(Scope.Thread)
public static class ContextActivator {
private ManagedContext requestContext;
@Setup
public void doSetup() {
requestContext = Arc.container().requestContext();
requestContext.activate();
}
@TearDown
public void doTearDown() {
requestContext.terminate();
}
}
@Setup
public void setup() {
ArcContainer container = Arc.initialize();
reqBean = container.instance(SimpleReqScopedBean1.class).get();
if (reqBean == null) {
throw new IllegalStateException("SimpleReqScopedBean not found");
}
}
@TearDown
public void tearDown() {
Arc.shutdown();
}
@Benchmark
public String run(ContextActivator contextActivator) throws InterruptedException {
String ret = reqBean.ping();
if (!ret.equals("ok")) {
throw new IllegalStateException("Incorrect result: " + ret);
}
return ret;
}
}