-
Notifications
You must be signed in to change notification settings - Fork 117
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added any filter benchmarks which mirror those in eventing core (#3361)
* Added any filter benchmarks to mirror those in eventing core Signed-off-by: Calum Murray <cmurray@redhat.com> * Fixed Any filter benchmarks to use static classes only Signed-off-by: Calum Murray <cmurray@redhat.com> --------- Signed-off-by: Calum Murray <cmurray@redhat.com>
- Loading branch information
Showing
4 changed files
with
242 additions
and
70 deletions.
There are no files selected for viewing
131 changes: 131 additions & 0 deletions
131
...ain/java/dev/knative/eventing/kafka/broker/dispatcher/impl/filter/AnyFilterBenchmark.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
/* | ||
* Copyright © 2018 Knative Authors (knative-dev@googlegroups.com) | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
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.*; | ||
import io.cloudevents.CloudEvent; | ||
import java.util.Map; | ||
import java.util.Set; | ||
|
||
public class AnyFilterBenchmark { | ||
public static CloudEvent event() { | ||
final var returnFirst = Math.random() > 0.5; | ||
if (returnFirst) { | ||
return SampleEvent.event(); | ||
} else { | ||
return SampleEvent.otherEvent(); | ||
} | ||
} | ||
|
||
public static ExactFilter makeExactFilter() { | ||
return new ExactFilter(Map.of("id", "com.github.pull.create")); | ||
} | ||
|
||
public static PrefixFilter makePrefixFilter() { | ||
return new PrefixFilter(Map.of("type", "com.g")); | ||
} | ||
|
||
public static SuffixFilter makeSuffixFilter() { | ||
return new SuffixFilter(Map.of("source", "lhost")); | ||
} | ||
|
||
public static PrefixFilter makePrefixFilterNoMatch() { | ||
return new PrefixFilter(Map.of("type", "other.event")); | ||
} | ||
|
||
public static SuffixFilter makeSufficFilterNoMatch() { | ||
return new SuffixFilter(Map.of("source", "qwertyuiop")); | ||
} | ||
|
||
public static class AnyFilterWithExactFilterBenchmark extends FilterBenchmark { | ||
|
||
@Override | ||
protected Filter createFilter() { | ||
return new AnyFilter(Set.of(makeExactFilter())); | ||
} | ||
|
||
@Override | ||
protected CloudEvent createEvent() { | ||
return SampleEvent.event(); | ||
} | ||
} | ||
|
||
public static class AnyFilterMatchAllSubfilters extends FilterBenchmark { | ||
|
||
@Override | ||
protected Filter createFilter() { | ||
return new AnyFilter(Set.of(makeExactFilter(), makePrefixFilter(), makeSuffixFilter())); | ||
} | ||
|
||
@Override | ||
protected CloudEvent createEvent() { | ||
return SampleEvent.event(); | ||
} | ||
} | ||
|
||
public static class AnyFilterFirstMatchAtEnd extends FilterBenchmark { | ||
|
||
@Override | ||
protected Filter createFilter() { | ||
return new AnyFilter(Set.of(makePrefixFilterNoMatch(), makeSufficFilterNoMatch(), makeExactFilter())); | ||
} | ||
|
||
@Override | ||
protected CloudEvent createEvent() { | ||
return SampleEvent.event(); | ||
} | ||
} | ||
|
||
public static class AnyFilterFirstMatchAtStart extends FilterBenchmark { | ||
|
||
@Override | ||
protected Filter createFilter() { | ||
return new AnyFilter(Set.of(makeExactFilter(), makePrefixFilterNoMatch(), makeSufficFilterNoMatch())); | ||
} | ||
|
||
@Override | ||
protected CloudEvent createEvent() { | ||
return SampleEvent.event(); | ||
} | ||
} | ||
|
||
public static class AnyFilter2EventsMatch2DifferentFilters extends FilterBenchmark { | ||
|
||
@Override | ||
protected Filter createFilter() { | ||
return new AnyFilter(Set.of(makePrefixFilter(), makePrefixFilterNoMatch())); | ||
} | ||
|
||
@Override | ||
protected CloudEvent createEvent() { | ||
return event(); | ||
} | ||
} | ||
|
||
public static class AnyFilter2EventsMatch2DifferentFiltersOneFilterMatchesNeither extends FilterBenchmark { | ||
@Override | ||
protected Filter createFilter() { | ||
return new AnyFilter(Set.of(makeSufficFilterNoMatch(), makePrefixFilter(), makePrefixFilterNoMatch())); | ||
} | ||
|
||
@Override | ||
protected CloudEvent createEvent() { | ||
return event(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
...s/src/main/java/dev/knative/eventing/kafka/broker/dispatcher/impl/filter/SampleEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* Copyright © 2018 Knative Authors (knative-dev@googlegroups.com) | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package dev.knative.eventing.kafka.broker.dispatcher.impl.filter; | ||
|
||
import io.cloudevents.CloudEvent; | ||
import io.cloudevents.core.builder.CloudEventBuilder; | ||
import java.net.URI; | ||
|
||
public class SampleEvent { | ||
public static CloudEvent event() { | ||
return CloudEventBuilder.v1() | ||
.withId("abcdefghijklmnop") | ||
.withSource(URI.create("http://localhost")) | ||
.withType("com.github.pull.create") | ||
.withDataSchema(URI.create("/api/schema")) | ||
.withDataContentType("testContentType") | ||
.withSubject("testSubject") | ||
.build(); | ||
} | ||
|
||
public static CloudEvent otherEvent() { | ||
return CloudEventBuilder.v1() | ||
.withId("abcdefghijklmnop") | ||
.withSource(URI.create("http://localhost")) | ||
.withType("other.event.type") | ||
.withDataSchema(URI.create("/api/schema")) | ||
.withDataContentType("testContentType") | ||
.withSubject("testSubject") | ||
.build(); | ||
} | ||
} |