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:40 UTC

[camel-performance-tests] branch main updated: Added a simple test for the EndpointHelper (#130)

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 23caae6  Added a simple test for the EndpointHelper (#130)
23caae6 is described below

commit 23caae699a0955b5e4370e18d85f89436c3952e4
Author: Otavio Rodolfo Piske <or...@users.noreply.github.com>
AuthorDate: Mon Oct 16 17:49:35 2023 +0200

    Added a simple test for the EndpointHelper (#130)
---
 .../apache/camel/itest/jmh/EndpointHelperTest.java | 103 +++++++++++++++++++++
 1 file changed, 103 insertions(+)

diff --git a/tests/camel-jmh/src/test/java/org/apache/camel/itest/jmh/EndpointHelperTest.java b/tests/camel-jmh/src/test/java/org/apache/camel/itest/jmh/EndpointHelperTest.java
new file mode 100644
index 0000000..d3bbb3b
--- /dev/null
+++ b/tests/camel-jmh/src/test/java/org/apache/camel/itest/jmh/EndpointHelperTest.java
@@ -0,0 +1,103 @@
+package org.apache.camel.itest.jmh;
+
+import java.util.concurrent.TimeUnit;
+
+import org.apache.camel.Endpoint;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.ServiceStatus;
+import org.apache.camel.impl.DefaultCamelContext;
+import org.apache.camel.spi.EndpointRegistry;
+import org.apache.camel.support.EndpointHelper;
+import org.apache.camel.support.NormalizedUri;
+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.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;
+
+/**
+ * These tests specific operations of the EndpointHelper in single-thread scenarios.
+ */
+public class EndpointHelperTest {
+
+    @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();
+    }
+
+    @State(Scope.Benchmark)
+    public static class BenchmarkState {
+        DefaultCamelContext context;
+        ProducerTemplate producerTemplate;
+        EndpointRegistry<NormalizedUri> endpointRegistry;
+
+        String[] stringRoutes = new String[500];
+        NormalizedUri[] routes = new NormalizedUri[500];
+        NormalizedUri[] nonExistentRoutes = new NormalizedUri[500];
+        Endpoint[] endpoints = new Endpoint[500];
+
+        @Setup(Level.Trial)
+        public void initialize() throws Exception {
+            context = new DefaultCamelContext();
+
+            context.start();
+            producerTemplate = context.createProducerTemplate();
+            endpointRegistry = context.getEndpointRegistry();
+
+            for (int i = 0; i < routes.length; i++) {
+                final String route = "controlbus:route?routeId=route" + i + "&action=status&loggingLevel=off";
+
+                stringRoutes[i] = route;
+                routes[i] = NormalizedUri.newNormalizedUri(route, false);
+
+                endpoints[i] = context.getEndpoint(route);
+                producerTemplate.requestBody(endpoints[i], null, ServiceStatus.class);
+
+                nonExistentRoutes[i] = NormalizedUri.newNormalizedUri("controlbus:route?routeId=nonExistentRoutes" + i + "&action=status&loggingLevel=off",
+                    false);
+
+            }
+        }
+    }
+
+    @OutputTimeUnit(TimeUnit.MICROSECONDS)
+    @BenchmarkMode(Mode.AverageTime)
+    @Benchmark
+    public void testMatchEndpointSame(BenchmarkState state, Blackhole bh) {
+        for (String route : state.stringRoutes) {
+            bh.consume(EndpointHelper.matchEndpoint(state.context, route, route));
+        }
+    }
+
+
+    @OutputTimeUnit(TimeUnit.MICROSECONDS)
+    @BenchmarkMode(Mode.AverageTime)
+    @Benchmark
+    public void testMatchEndpointNotSame(BenchmarkState state, Blackhole bh) {
+        for (int i = 0; i < state.routes.length; i++) {
+            bh.consume(EndpointHelper.matchEndpoint(state.context, state.routes[i].toString(), state.stringRoutes[i]));
+        }
+    }
+
+}