From cd5e89c20fe192318f2ca0f2edc9737a6871bd00 Mon Sep 17 00:00:00 2001 From: Jakub Vrubel <52706818+jvrubel@users.noreply.github.com> Date: Tue, 24 Sep 2024 14:15:09 +0200 Subject: [PATCH] CAMEL-20367: Adds observability tests (#15668) --- .../jbang/it/MetricsObservabilityITCase.java | 45 +++++++++++++++++++ .../jbang/it/support/JBangTestSupport.java | 3 +- .../jbang/it/CircuitBreakerRoute.java | 30 +++++++++++++ 3 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 dsl/camel-jbang/camel-jbang-it/src/test/java/org/apache/camel/dsl/jbang/it/MetricsObservabilityITCase.java create mode 100644 dsl/camel-jbang/camel-jbang-it/src/test/resources/jbang/it/CircuitBreakerRoute.java diff --git a/dsl/camel-jbang/camel-jbang-it/src/test/java/org/apache/camel/dsl/jbang/it/MetricsObservabilityITCase.java b/dsl/camel-jbang/camel-jbang-it/src/test/java/org/apache/camel/dsl/jbang/it/MetricsObservabilityITCase.java new file mode 100644 index 0000000000000..d8720080d1aa4 --- /dev/null +++ b/dsl/camel-jbang/camel-jbang-it/src/test/java/org/apache/camel/dsl/jbang/it/MetricsObservabilityITCase.java @@ -0,0 +1,45 @@ +/* + * 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.dsl.jbang.it; + +import java.io.IOException; + +import org.apache.camel.dsl.jbang.it.support.JBangTestSupport; +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.Test; + +public class MetricsObservabilityITCase extends JBangTestSupport { + + @Test + public void metricsTest() throws IOException { + copyResourceInDataFolder(TestResources.SERVER_ROUTE); + executeBackground(String.format("run %s/server.yaml --metrics", mountPoint())); + checkLogContains("http://0.0.0.0:8080/q/metrics"); + Assertions.assertThat( + execInHost(String.format("curl http://localhost:%s/q/metrics", containerService.getDevConsolePort()))) + .as("server should list metrics") + .contains("# HELP camel_exchanges_total Total number of processed exchanges"); + } + + @Test + public void circuitBreakerTest() throws IOException { + copyResourceInDataFolder(TestResources.CIRCUIT_BREAKER); + executeBackground(String.format("run %s/CircuitBreakerRoute.java --dep=camel-resilience4j", mountPoint())); + checkLogContains("(CircuitBreakerRoute) started"); + checkCommandOutputs("get circuit-breaker", "resilience4j"); + } +} diff --git a/dsl/camel-jbang/camel-jbang-it/src/test/java/org/apache/camel/dsl/jbang/it/support/JBangTestSupport.java b/dsl/camel-jbang/camel-jbang-it/src/test/java/org/apache/camel/dsl/jbang/it/support/JBangTestSupport.java index 8beda53be59d4..b6d96afe9af98 100644 --- a/dsl/camel-jbang/camel-jbang-it/src/test/java/org/apache/camel/dsl/jbang/it/support/JBangTestSupport.java +++ b/dsl/camel-jbang/camel-jbang-it/src/test/java/org/apache/camel/dsl/jbang/it/support/JBangTestSupport.java @@ -99,7 +99,8 @@ protected enum TestResources { MQQT_CONSUMER("mqttConsumer.yaml", "/jbang/it/mqttConsumer.yaml"), BUILD_GRADLE("build.gradle", "/jbang/it/maven-gradle/build.gradle"), DIR_ROUTE("FromDirectoryRoute.java", "/jbang/it/from-source-dir/FromDirectoryRoute.java"), - SERVER_ROUTE("server.yaml", "/jbang/it/server.yaml"); + SERVER_ROUTE("server.yaml", "/jbang/it/server.yaml"), + CIRCUIT_BREAKER("CircuitBreakerRoute.java", "/jbang/it/CircuitBreakerRoute.java"); private String name; private String resPath; diff --git a/dsl/camel-jbang/camel-jbang-it/src/test/resources/jbang/it/CircuitBreakerRoute.java b/dsl/camel-jbang/camel-jbang-it/src/test/resources/jbang/it/CircuitBreakerRoute.java new file mode 100644 index 0000000000000..61c73526fa525 --- /dev/null +++ b/dsl/camel-jbang/camel-jbang-it/src/test/resources/jbang/it/CircuitBreakerRoute.java @@ -0,0 +1,30 @@ +/* + * 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. + */ +import org.apache.camel.builder.RouteBuilder; + +public class CircuitBreakerRoute extends RouteBuilder { + @Override + public void configure() { + from("direct:start") + .circuitBreaker() + .to("http://localhost:8080/faulty") + .onFallback() + .transform().constant("Fallback message") + .end() + .to("mock:result"); + } +}