This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push:
new b1cf528349c CAMEL-18514: camel-health - health check for not
automatically started routes should always be up (#8384)
b1cf528349c is described below
commit b1cf528349c74e48e31a1c7b4ac142b6dec8cb52
Author: Steven Dürrenmatt <[email protected]>
AuthorDate: Fri Sep 16 07:16:49 2022 +0200
CAMEL-18514: camel-health - health check for not automatically started
routes should always be up (#8384)
---
.../camel/impl/health/RouteHealthCheckTest.java | 26 ++++++++++++++++++++++
.../apache/camel/impl/health/RouteHealthCheck.java | 3 +--
2 files changed, 27 insertions(+), 2 deletions(-)
diff --git
a/core/camel-core/src/test/java/org/apache/camel/impl/health/RouteHealthCheckTest.java
b/core/camel-core/src/test/java/org/apache/camel/impl/health/RouteHealthCheckTest.java
index bbf07e86d95..c21e6d7e310 100644
---
a/core/camel-core/src/test/java/org/apache/camel/impl/health/RouteHealthCheckTest.java
+++
b/core/camel-core/src/test/java/org/apache/camel/impl/health/RouteHealthCheckTest.java
@@ -21,8 +21,10 @@ import java.util.Collections;
import org.apache.camel.CamelContext;
import org.apache.camel.Route;
import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.health.HealthCheck;
import org.apache.camel.health.HealthCheckResultBuilder;
import org.apache.camel.impl.DefaultCamelContext;
+import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
public class RouteHealthCheckTest {
@@ -50,4 +52,28 @@ public class RouteHealthCheckTest {
context.stop();
}
+ @Test
+ public void testHealthCheckIsUpWhenRouteIsNotAutoStartup() throws
Exception {
+ CamelContext context = new DefaultCamelContext();
+ context.addRoutes(new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+
from("direct:input").id(TEST_ROUTE_ID).autoStartup(false).log("Message");
+ }
+ });
+ context.start();
+
+ Route route = context.getRoute(TEST_ROUTE_ID);
+
+ RouteHealthCheck healthCheck = new RouteHealthCheck(route);
+ final HealthCheckResultBuilder builder =
HealthCheckResultBuilder.on(healthCheck);
+
+ healthCheck.doCall(builder, Collections.emptyMap());
+ HealthCheck.Result result = builder.build();
+
+ Assertions.assertEquals(HealthCheck.State.UP, result.getState());
+
+ context.stop();
+ }
+
}
diff --git
a/core/camel-health/src/main/java/org/apache/camel/impl/health/RouteHealthCheck.java
b/core/camel-health/src/main/java/org/apache/camel/impl/health/RouteHealthCheck.java
index e6584736e00..8e09f570d3a 100644
---
a/core/camel-health/src/main/java/org/apache/camel/impl/health/RouteHealthCheck.java
+++
b/core/camel-health/src/main/java/org/apache/camel/impl/health/RouteHealthCheck.java
@@ -21,7 +21,6 @@ import java.util.Map;
import org.apache.camel.CamelContext;
import org.apache.camel.Route;
import org.apache.camel.ServiceStatus;
-import org.apache.camel.health.HealthCheck;
import org.apache.camel.health.HealthCheckResultBuilder;
/**
@@ -63,7 +62,7 @@ public class RouteHealthCheck extends AbstractHealthCheck {
builder.message(String.format("Route %s has status %s",
route.getId(), status.name()));
}
} else {
- if (route.isAutoStartup()) {
+ if (!route.isAutoStartup()) {
// if a route is configured to not to automatically start,
then the
// route is always up as it is externally managed.
builder.up();