Skip to content

Commit

Permalink
CAMEL-20367: Adds observability tests (#15668)
Browse files Browse the repository at this point in the history
  • Loading branch information
jvrubel authored Sep 24, 2024
1 parent 125cc92 commit cd5e89c
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -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");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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");
}
}

0 comments on commit cd5e89c

Please sign in to comment.