This is an automated email from the ASF dual-hosted git repository.

ppalaga pushed a commit to branch 1.0.x
in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git

commit 7f6cf66fc073cd698bf617ece375efc38857006f
Author: aldettinger <aldettin...@gmail.com>
AuthorDate: Mon Aug 10 15:35:25 2020 +0200

    Fixed the VerifyError in the health example fixes #1517
---
 examples/health/README.adoc                        | 17 ++++++------
 examples/health/pom.xml                            |  4 +++
 .../main/java/org/acme/health/MyRouteBuilder.java  | 14 ++--------
 ...HealthCheck.java => RunTooLongHealthCheck.java} | 32 +++++++++-------------
 4 files changed, 28 insertions(+), 39 deletions(-)

diff --git a/examples/health/README.adoc b/examples/health/README.adoc
index 964c972..d61bc6b 100644
--- a/examples/health/README.adoc
+++ b/examples/health/README.adoc
@@ -7,16 +7,16 @@ them automatic discovered by Camel and used as parts of its 
health-check system.
 TIP: Check the 
https://camel.apache.org/camel-quarkus/latest/first-steps.html[Camel Quarkus 
User guide] for prerequisites
 and other general information.
 
-The example has two routes, a timer that calls a bean that flips a boolean that
-causes the custom health check to be in either UP or DOWN state.
+The example has two routes. The timer route performs a given task at regular 
interval. For the sake of this example we'll say
+that this task unexpectedly freezes the service from time to time. The details 
can be consulted at http://localhost:8080/health. 
+The custom health check is expected to report UNKNOWN on first consultation, 
then UP during 10 seconds, and finally DOWN so as to
+simulate that the service is frozen.
 
 The 2nd route is on purpose made to fail on startup by configuring netty to an 
unknown host.
 Camel supervising route controller will attempt to restart the route up till 
10 times before exhausting.
+The routes health check will therefore report this route as DOWN until its 
exhausted where the states are changed to UNKNOWN.
 
-The routes health check will therefore report this route as DOWN until its 
exhausted
-where the states are changed to UNKNOWN.
-
-The details can be seen at runtime from the calling the following url from a 
web browser: http://localhost:8080/health
+The details can be seen at runtime via the following url from a web browser: 
http://localhost:8080/health.
 
 === Start in the Development mode
 
@@ -44,10 +44,11 @@ 
https://camel.apache.org/camel-quarkus/latest/first-steps.html#_package_and_run_
 
 [source,shell]
 ----
+
 $ mvn clean package
 $ java -jar target/*-runner.jar
 ...
-[io.quarkus] (main) Quarkus 1.3.2 started in 1.163s. Listening on: 
http://[::]:8080
+[io.quarkus] (main) camel-quarkus-examples-... started in 0.885s. Listening 
on: http://0.0.0.0:8080
 ----
 
 === Native mode
@@ -62,7 +63,7 @@ To prepare a native executable using GraalVM, run the 
following command:
 $ mvn clean package -Pnative
 $ ./target/*-runner
 ...
-[io.quarkus] (main) Quarkus 1.3.2 started in 0.013s. Listening on: 
http://[::]:8080
+[io.quarkus] (main) camel-quarkus-examples-... started in 0.026s. Listening 
on: http://0.0.0.0:8080
 ...
 ----
 
diff --git a/examples/health/pom.xml b/examples/health/pom.xml
index c5e6df3..0ab2733 100644
--- a/examples/health/pom.xml
+++ b/examples/health/pom.xml
@@ -57,6 +57,10 @@
         </dependency>
         <dependency>
             <groupId>org.apache.camel.quarkus</groupId>
+            <artifactId>camel-quarkus-main</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.camel.quarkus</groupId>
             <artifactId>camel-quarkus-netty</artifactId>
         </dependency>
         <dependency>
diff --git a/examples/health/src/main/java/org/acme/health/MyRouteBuilder.java 
b/examples/health/src/main/java/org/acme/health/MyRouteBuilder.java
index 88288db..11dc4aa 100644
--- a/examples/health/src/main/java/org/acme/health/MyRouteBuilder.java
+++ b/examples/health/src/main/java/org/acme/health/MyRouteBuilder.java
@@ -16,23 +16,13 @@
  */
 package org.acme.health;
 
-import javax.enterprise.context.ApplicationScoped;
-import javax.inject.Inject;
-
 import org.apache.camel.builder.RouteBuilder;
 
-@ApplicationScoped
 public class MyRouteBuilder extends RouteBuilder {
 
-    // we can inject the bean via this annotation
-    @Inject
-    MonkeyHealthCheck monkey;
-
     @Override
-    public void configure() throws Exception {
-        from("timer:foo?period={{myPeriod}}").routeId("timer")
-                .bean(monkey, "chaos")
-                .log("${body}");
+    public void configure() {
+        from("timer:foo?period={{myPeriod}}").routeId("timer").log("Doing one 
more task");
 
         // this route is invalid and fails during startup
         // the supervising route controller will take over and attempt
diff --git 
a/examples/health/src/main/java/org/acme/health/MonkeyHealthCheck.java 
b/examples/health/src/main/java/org/acme/health/RunTooLongHealthCheck.java
similarity index 63%
rename from examples/health/src/main/java/org/acme/health/MonkeyHealthCheck.java
rename to 
examples/health/src/main/java/org/acme/health/RunTooLongHealthCheck.java
index 479d60c..db187d6 100644
--- a/examples/health/src/main/java/org/acme/health/MonkeyHealthCheck.java
+++ b/examples/health/src/main/java/org/acme/health/RunTooLongHealthCheck.java
@@ -18,42 +18,36 @@ package org.acme.health;
 
 import java.util.Map;
 
-import javax.enterprise.context.ApplicationScoped;
-
 import org.apache.camel.health.HealthCheckResultBuilder;
 import org.apache.camel.impl.health.AbstractHealthCheck;
 
 /**
- * A chaos monkey health check that reports UP or DOWN in a chaotic way.
- *
- * This is a custom implementation of a Camel {@link 
org.apache.camel.health.HealthCheck}
- * which is automatic discovered if bound in the {@link 
org.apache.camel.spi.Registry} and
- * used as part of Camel's health-check system.
+ * A user defined health check that reports UNKNOWN on first call, then UP for
+ * 10 seconds and finally DOWN afterward. This is a custom implementation of a
+ * Camel {@link org.apache.camel.health.HealthCheck} and used as part of 
Camel's
+ * health-check system.
  */
-@ApplicationScoped
-public class MonkeyHealthCheck extends AbstractHealthCheck {
+public class RunTooLongHealthCheck extends AbstractHealthCheck {
 
-    private boolean up = true;
+    private volatile long firstCallTimeMillis = 0;
 
-    public MonkeyHealthCheck() {
-        super("custom", "monkey");
+    public RunTooLongHealthCheck() {
+        super("custom", "toolong");
     }
 
     @Override
     protected void doCall(HealthCheckResultBuilder builder, Map<String, 
Object> options) {
-        builder.detail("monkey", "The chaos monkey was here");
-        if (up) {
+        builder.detail("toolong", "Reports DOWN when run for too long");
+        if (firstCallTimeMillis == 0) {
+            builder.unknown();
+            firstCallTimeMillis = System.currentTimeMillis();
+        } else if ((System.currentTimeMillis() - firstCallTimeMillis) < 10 * 
1000L) {
             builder.up();
         } else {
             builder.down();
         }
     }
 
-    public String chaos() {
-        up = !up;
-        return up ? "All is okay" : "Chaos monkey was here";
-    }
-
     @Override
     public boolean isReadiness() {
         // only liveness probe

Reply via email to