This is an automated email from the ASF dual-hosted git repository. jamesnetherton pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/master by this push: new a17555b CAMEL-16395: Fix unpredictable configuration for camel main routes health check a17555b is described below commit a17555b622e04283806c4b4e5dff3d61fe666809 Author: James Netherton <jamesnether...@gmail.com> AuthorDate: Thu Mar 25 13:47:19 2021 +0000 CAMEL-16395: Fix unpredictable configuration for camel main routes health check --- core/camel-main/pom.xml | 5 ++ .../org/apache/camel/main/BaseMainSupport.java | 1 - .../camel/main/MainHealthCheckConfigTest.java | 85 ++++++++++++++++++++++ 3 files changed, 90 insertions(+), 1 deletion(-) diff --git a/core/camel-main/pom.xml b/core/camel-main/pom.xml index 7c30cf0..2b5553d 100644 --- a/core/camel-main/pom.xml +++ b/core/camel-main/pom.xml @@ -101,6 +101,11 @@ </dependency> <dependency> <groupId>org.apache.camel</groupId> + <artifactId>camel-health</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.apache.camel</groupId> <artifactId>camel-log</artifactId> <scope>test</scope> </dependency> diff --git a/core/camel-main/src/main/java/org/apache/camel/main/BaseMainSupport.java b/core/camel-main/src/main/java/org/apache/camel/main/BaseMainSupport.java index 122a8e7..0b74bc0 100644 --- a/core/camel-main/src/main/java/org/apache/camel/main/BaseMainSupport.java +++ b/core/camel-main/src/main/java/org/apache/camel/main/BaseMainSupport.java @@ -986,7 +986,6 @@ public abstract class BaseMainSupport extends BaseService { ((HealthCheck) hc).getConfiguration().setFailureThreshold(hcc.getFailureThreshold()); ((HealthCheck) hc).getConfiguration().setInterval(hcc.getInterval()); } else if (hc instanceof HealthCheckRepository) { - ((HealthCheckRepository) hc).setEnabled(hcc.isEnabled()); ((HealthCheckRepository) hc).addConfiguration(id, hcc); } } diff --git a/core/camel-main/src/test/java/org/apache/camel/main/MainHealthCheckConfigTest.java b/core/camel-main/src/test/java/org/apache/camel/main/MainHealthCheckConfigTest.java new file mode 100644 index 0000000..97e5a40 --- /dev/null +++ b/core/camel-main/src/test/java/org/apache/camel/main/MainHealthCheckConfigTest.java @@ -0,0 +1,85 @@ +/* + * 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.main; + +import java.util.Map; +import java.util.Optional; + +import org.apache.camel.CamelContext; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.health.HealthCheckConfiguration; +import org.apache.camel.health.HealthCheckRegistry; +import org.apache.camel.health.HealthCheckRepository; +import org.apache.camel.impl.health.RoutesHealthCheckRepository; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class MainHealthCheckConfigTest { + + @Test + public void testMainRoutesHealthCheckConfiguration() { + Main main = new Main(); + main.configure().addRoutesBuilder(new Routes()); + main.addInitialProperty("camel.health.config[direct].parent", "routes"); + main.addInitialProperty("camel.health.config[direct].enabled", "true"); + main.addInitialProperty("camel.health.config[seda].parent", "routes"); + main.addInitialProperty("camel.health.config[seda].enabled", "false"); + main.addInitialProperty("camel.health.routes-enabled", "true"); + + main.start(); + try { + CamelContext camelContext = main.getCamelContext(); + assertNotNull(camelContext); + + HealthCheckRegistry healthCheckRegistry = camelContext.getExtension(HealthCheckRegistry.class); + assertNotNull(healthCheckRegistry); + + Optional<HealthCheckRepository> routes = healthCheckRegistry.getRepository("routes"); + assertTrue(routes.isPresent()); + + RoutesHealthCheckRepository routesRepository = (RoutesHealthCheckRepository) routes.get(); + assertTrue(routesRepository.isEnabled()); + + Map<String, HealthCheckConfiguration> configurations = routesRepository.getConfigurations(); + assertNotNull(configurations); + assertEquals(2, configurations.size()); + + HealthCheckConfiguration direct = configurations.get("direct"); + assertNotNull(direct); + assertTrue(direct.isEnabled()); + + HealthCheckConfiguration seda = configurations.get("seda"); + assertNotNull(seda); + assertFalse(seda.isEnabled()); + } finally { + main.stop(); + } + } + + static class Routes extends RouteBuilder { + + @Override + public void configure() throws Exception { + from("direct:start").to("log:direct"); + from("seda:start").to("log:seda"); + } + } +}