|
36 | 36 | import org.apache.kafka.metadata.authorizer.StandardAcl;
|
37 | 37 | import org.apache.kafka.metadata.authorizer.StandardAuthorizer;
|
38 | 38 | import org.apache.kafka.server.authorizer.Action;
|
| 39 | +import org.apache.kafka.server.authorizer.AuthorizationResult; |
39 | 40 |
|
40 | 41 | import org.openjdk.jmh.annotations.Benchmark;
|
41 | 42 | import org.openjdk.jmh.annotations.BenchmarkMode;
|
@@ -87,13 +88,19 @@ public class AuthorizerBenchmark {
|
87 | 88 | private List<Action> actions = new ArrayList<>();
|
88 | 89 | private RequestContext authorizeContext;
|
89 | 90 | private RequestContext authorizeByResourceTypeContext;
|
| 91 | + private AclBindingFilter filter; |
| 92 | + private AclOperation op; |
| 93 | + private ResourceType resourceType; |
90 | 94 |
|
91 | 95 | Random rand = new Random(System.currentTimeMillis());
|
92 | 96 | double eps = 1e-9;
|
93 | 97 |
|
94 | 98 | @Setup(Level.Trial)
|
95 | 99 | public void setup() throws Exception {
|
96 | 100 | authorizer = new StandardAuthorizer();
|
| 101 | + filter = AclBindingFilter.ANY; |
| 102 | + op = AclOperation.READ; |
| 103 | + resourceType = ResourceType.TOPIC; |
97 | 104 | prepareAclCache();
|
98 | 105 | // By adding `-95` to the resource name prefix, we cause the `TreeMap.from/to` call to return
|
99 | 106 | // most map entries. In such cases, we rely on the filtering based on `String.startsWith`
|
@@ -196,17 +203,17 @@ public void tearDown() throws IOException {
|
196 | 203 | }
|
197 | 204 |
|
198 | 205 | @Benchmark
|
199 |
| - public void testAclsIterator() { |
200 |
| - authorizer.acls(AclBindingFilter.ANY); |
| 206 | + public Iterable<AclBinding> testAclsIterator() { |
| 207 | + return authorizer.acls(filter); |
201 | 208 | }
|
202 | 209 |
|
203 | 210 | @Benchmark
|
204 |
| - public void testAuthorizer() { |
205 |
| - authorizer.authorize(authorizeContext, actions); |
| 211 | + public List<AuthorizationResult> testAuthorizer() { |
| 212 | + return authorizer.authorize(authorizeContext, actions); |
206 | 213 | }
|
207 | 214 |
|
208 | 215 | @Benchmark
|
209 |
| - public void testAuthorizeByResourceType() { |
210 |
| - authorizer.authorizeByResourceType(authorizeByResourceTypeContext, AclOperation.READ, ResourceType.TOPIC); |
| 216 | + public AuthorizationResult testAuthorizeByResourceType() { |
| 217 | + return authorizer.authorizeByResourceType(authorizeByResourceTypeContext, op, resourceType); |
211 | 218 | }
|
212 | 219 | }
|
0 commit comments