From fb187869769dbc4ca5fbbe94677c81b16c403890 Mon Sep 17 00:00:00 2001 From: Calum Murray Date: Mon, 31 Jul 2023 12:22:49 -0400 Subject: [PATCH] Implemented exact filter benchmark Signed-off-by: Calum Murray --- .../impl/filter/ExactFilterBenchmark.java | 73 +++++++++++++++++++ .../impl/filter/FilterBenchmark.java | 2 +- 2 files changed, 74 insertions(+), 1 deletion(-) create mode 100644 data-plane/benchmarks/src/main/java/dev/knative/eventing/kafka/broker/dispatcher/impl/filter/ExactFilterBenchmark.java diff --git a/data-plane/benchmarks/src/main/java/dev/knative/eventing/kafka/broker/dispatcher/impl/filter/ExactFilterBenchmark.java b/data-plane/benchmarks/src/main/java/dev/knative/eventing/kafka/broker/dispatcher/impl/filter/ExactFilterBenchmark.java new file mode 100644 index 0000000000..acfefb759c --- /dev/null +++ b/data-plane/benchmarks/src/main/java/dev/knative/eventing/kafka/broker/dispatcher/impl/filter/ExactFilterBenchmark.java @@ -0,0 +1,73 @@ +package dev.knative.eventing.kafka.broker.dispatcher.impl.filter; + +import dev.knative.eventing.kafka.broker.dispatcher.Filter; +import dev.knative.eventing.kafka.broker.dispatcher.impl.filter.subscriptionsapi.ExactFilter; +import io.cloudevents.CloudEvent; +import io.cloudevents.core.builder.CloudEventBuilder; +import io.cloudevents.core.v1.CloudEventV1; + +import java.net.URI; +import java.util.Map; + +public class ExactFilterBenchmark { + + public static CloudEvent event() { + return CloudEventBuilder.v1() + .withId("abc") + .withSource(URI.create("http://localhost")) + .withType("test") + .withDataSchema(URI.create("/api/schema")) + .withDataContentType("testContentType") + .withSubject("testSubject") + .build(); + } + + public static class ExactFilterBenchmarkExactMatchID extends FilterBenchmark { + + @Override + protected Filter createFilter() { + return new ExactFilter(Map.of(CloudEventV1.ID, "abc")); + } + + @Override + protected CloudEvent createEvent() { + return event(); + } + } + + public static class ExactFilterBenchmarkAllAttributes extends FilterBenchmark { + + @Override + protected Filter createFilter() { + return new ExactFilter(Map.of( + CloudEventV1.ID, "abc", + CloudEventV1.SOURCE, "http://localhost", + CloudEventV1.TYPE, "test", + CloudEventV1.DATASCHEMA,"/api/schema", + CloudEventV1.DATACONTENTTYPE, "testContentType", + CloudEventV1.SUBJECT, "testSubject" + )); + } + + @Override + protected CloudEvent createEvent() { + return event(); + } + } + + public static class ExactFilterBenchmarkNoMatch extends FilterBenchmark { + + @Override + protected Filter createFilter() { + return new ExactFilter(Map.of( + CloudEventV1.ID, "qwertyuiopasdfghjklzxcvbnm", + CloudEventV1.SOURCE, "qwertyuiopasdfghjklzxcvbnm" + )); + } + + @Override + protected CloudEvent createEvent() { + return event(); + } + } +} diff --git a/data-plane/benchmarks/src/main/java/dev/knative/eventing/kafka/broker/dispatcher/impl/filter/FilterBenchmark.java b/data-plane/benchmarks/src/main/java/dev/knative/eventing/kafka/broker/dispatcher/impl/filter/FilterBenchmark.java index 61ebe25a9c..696b78e617 100644 --- a/data-plane/benchmarks/src/main/java/dev/knative/eventing/kafka/broker/dispatcher/impl/filter/FilterBenchmark.java +++ b/data-plane/benchmarks/src/main/java/dev/knative/eventing/kafka/broker/dispatcher/impl/filter/FilterBenchmark.java @@ -22,7 +22,7 @@ import org.openjdk.jmh.annotations.Benchmark; import org.openjdk.jmh.infra.Blackhole; -public abstract class FilterBenchmark{ +public abstract class FilterBenchmark { Filter filter; CloudEvent cloudEvent;