You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by or...@apache.org on 2023/10/16 15:49:51 UTC
[camel-performance-tests] branch main updated: Added a simple test with fixed dynamic resolution (#129)
This is an automated email from the ASF dual-hosted git repository.
orpiske pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-performance-tests.git
The following commit(s) were added to refs/heads/main by this push:
new f9801ef Added a simple test with fixed dynamic resolution (#129)
f9801ef is described below
commit f9801ef75a0e6123601b23403cb4bbe76e52213c
Author: Otavio Rodolfo Piske <or...@users.noreply.github.com>
AuthorDate: Mon Oct 16 17:49:47 2023 +0200
Added a simple test with fixed dynamic resolution (#129)
---
.../apache/camel/itest/jmh/eip/ToDHeaderTest.java | 133 +++++++++++++++++++++
1 file changed, 133 insertions(+)
diff --git a/tests/camel-jmh/src/test/java/org/apache/camel/itest/jmh/eip/ToDHeaderTest.java b/tests/camel-jmh/src/test/java/org/apache/camel/itest/jmh/eip/ToDHeaderTest.java
new file mode 100644
index 0000000..ce0bed5
--- /dev/null
+++ b/tests/camel-jmh/src/test/java/org/apache/camel/itest/jmh/eip/ToDHeaderTest.java
@@ -0,0 +1,133 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.camel.itest.jmh.eip;
+
+import java.util.concurrent.TimeUnit;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.ConsumerTemplate;
+import org.apache.camel.Endpoint;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.impl.DefaultCamelContext;
+import org.junit.jupiter.api.Test;
+import org.openjdk.jmh.annotations.Benchmark;
+import org.openjdk.jmh.annotations.BenchmarkMode;
+import org.openjdk.jmh.annotations.Level;
+import org.openjdk.jmh.annotations.Mode;
+import org.openjdk.jmh.annotations.OutputTimeUnit;
+import org.openjdk.jmh.annotations.Scope;
+import org.openjdk.jmh.annotations.Setup;
+import org.openjdk.jmh.annotations.State;
+import org.openjdk.jmh.annotations.Threads;
+import org.openjdk.jmh.infra.Blackhole;
+import org.openjdk.jmh.results.format.ResultFormatType;
+import org.openjdk.jmh.runner.Runner;
+import org.openjdk.jmh.runner.options.Options;
+import org.openjdk.jmh.runner.options.OptionsBuilder;
+
+/**
+ * This tests the toD when using a header for the routing decision.
+ */
+public class ToDHeaderTest {
+ private static String DATA = "HELLO";
+ private static final String HEADER = "name";
+ private static final String POSITIVE = "positive";
+
+ @Test
+ public void launchBenchmark() throws Exception {
+ Options opt = new OptionsBuilder()
+ // Specify which benchmarks to run.
+ // You can be more specific if you'd like to run only one benchmark per test.
+ .include(this.getClass().getName() + ".*")
+ // Set the following options as needed
+ .measurementIterations(10)
+ .warmupIterations(5)
+ .forks(1)
+ .resultFormat(ResultFormatType.JSON)
+ .result(this.getClass().getSimpleName() + ".jmh.json")
+ .build();
+
+ new Runner(opt).run();
+ }
+
+ // The JMH samples are the best documentation for how to use it
+ // http://hg.openjdk.java.net/code-tools/jmh/file/tip/jmh-samples/src/main/java/org/openjdk/jmh/samples/
+ @State(Scope.Benchmark)
+ public static class BenchmarkState {
+ CamelContext context;
+ ProducerTemplate producerTemplate;
+ ConsumerTemplate consumerTemplate;
+
+ Endpoint endpoint;
+ Endpoint consumerPositiveEndpoint;
+
+ @Setup(Level.Trial)
+ public void initialize() throws Exception {
+ context = new DefaultCamelContext();
+
+ producerTemplate = context.createProducerTemplate();
+ consumerTemplate = context.createConsumerTemplate();
+
+ endpoint = context.getEndpoint("disruptor:test");
+ consumerPositiveEndpoint = context.getEndpoint("disruptor:positive");
+
+ context.addRoutes(new RouteBuilder() {
+ @Override
+ public void configure() {
+ from(endpoint)
+ .toD("disruptor:${header[\"name\"]}");
+
+ }
+ });
+
+ context.start();
+ }
+ }
+
+
+ @OutputTimeUnit(TimeUnit.MICROSECONDS)
+ @BenchmarkMode(Mode.AverageTime)
+ @Benchmark
+ @Threads(1)
+ public void send_1(Blackhole bh, BenchmarkState state) {
+ state.producerTemplate.sendBodyAndHeader(state.endpoint, DATA, HEADER, POSITIVE);
+
+ bh.consume(state.consumerTemplate.receive(state.consumerPositiveEndpoint));
+ }
+
+ @OutputTimeUnit(TimeUnit.MICROSECONDS)
+ @BenchmarkMode(Mode.AverageTime)
+ @Benchmark
+ @Threads(2)
+ public void send_2(Blackhole bh, BenchmarkState state) {
+ state.producerTemplate.sendBodyAndHeader(state.endpoint, DATA, HEADER, POSITIVE);
+
+ bh.consume(state.consumerTemplate.receive(state.consumerPositiveEndpoint));
+ }
+
+ @OutputTimeUnit(TimeUnit.MICROSECONDS)
+ @BenchmarkMode(Mode.AverageTime)
+ @Benchmark
+ @Threads(4)
+ public void send_4(Blackhole bh, BenchmarkState state) {
+ state.producerTemplate.sendBodyAndHeader(state.endpoint, DATA, HEADER, POSITIVE);
+
+ bh.consume(state.consumerTemplate.receive(state.consumerPositiveEndpoint));
+ }
+}