You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2021/11/30 20:30:53 UTC

[camel] 02/10: CAMEL-15133: camel-health - Resolve health-checks from classpath and make it friendlier to provide custom health checks.

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

commit e0c1e96a9b86c6b4ca58fb4432975278cf3f8e60
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Tue Nov 30 11:58:03 2021 +0100

    CAMEL-15133: camel-health - Resolve health-checks from classpath and make it friendlier to provide custom health checks.
---
 .../camel/impl/health/MyFooHealthCheckTest.java    | 24 ++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/core/camel-core/src/test/java/org/apache/camel/impl/health/MyFooHealthCheckTest.java b/core/camel-core/src/test/java/org/apache/camel/impl/health/MyFooHealthCheckTest.java
index 1e3b506..e2f5147 100644
--- a/core/camel-core/src/test/java/org/apache/camel/impl/health/MyFooHealthCheckTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/impl/health/MyFooHealthCheckTest.java
@@ -16,9 +16,13 @@
  */
 package org.apache.camel.impl.health;
 
+import java.util.Collection;
+
 import org.apache.camel.ContextTestSupport;
 import org.apache.camel.ExtendedCamelContext;
 import org.apache.camel.health.HealthCheck;
+import org.apache.camel.health.HealthCheckHelper;
+import org.apache.camel.health.HealthCheckRegistry;
 import org.junit.jupiter.api.Assertions;
 import org.junit.jupiter.api.Test;
 
@@ -45,4 +49,24 @@ public class MyFooHealthCheckTest extends ContextTestSupport {
         Assertions.assertEquals(HealthCheck.State.DOWN, r.getState());
         Assertions.assertEquals("Chaos Monkey was here", r.getMessage().get());
     }
+
+    @Test
+    public void testAddToRegistry() throws Exception {
+        context.start();
+
+        HealthCheck hc
+                = context.adapt(ExtendedCamelContext.class).getHealthCheckResolver().resolveHealthCheck("myfoo", context);
+        Assertions.assertNotNull(hc);
+
+        HealthCheckRegistry hcr = context.getExtension(HealthCheckRegistry.class);
+        hcr.register(hc);
+
+        Collection<HealthCheck.Result> col = HealthCheckHelper.invoke(context);
+        Assertions.assertEquals(1, col.size());
+
+        HealthCheck.Result r = col.iterator().next();
+        Assertions.assertEquals(HealthCheck.State.DOWN, r.getState());
+        Assertions.assertEquals("Chaos Monkey was here", r.getMessage().get());
+    }
+
 }