You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by al...@apache.org on 2022/01/04 18:58:36 UTC

[camel-quarkus] branch main updated: Setup a reproducer showing that camel.main.durationMaxSeconds is not honoured #3394

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

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


The following commit(s) were added to refs/heads/main by this push:
     new 288bcd0  Setup a reproducer showing that camel.main.durationMaxSeconds is not honoured #3394
288bcd0 is described below

commit 288bcd051b33c5c0419455ff5f2ce92625933ad4
Author: aldettinger <al...@gmail.com>
AuthorDate: Mon Jan 3 17:23:05 2022 +0100

    Setup a reproducer showing that camel.main.durationMaxSeconds is not honoured #3394
---
 .../apache/camel/quarkus/main/cmd/CamelRoute.java  |  5 ++--
 .../src/main/resources/application.properties      | 18 ------------
 .../camel/quarkus/main/cmd/it/CommandModeTest.java | 34 ++++++++++++++++++----
 3 files changed, 32 insertions(+), 25 deletions(-)

diff --git a/integration-tests/main-command-mode/src/main/java/org/apache/camel/quarkus/main/cmd/CamelRoute.java b/integration-tests/main-command-mode/src/main/java/org/apache/camel/quarkus/main/cmd/CamelRoute.java
index 9ac5cb6..77f491e 100644
--- a/integration-tests/main-command-mode/src/main/java/org/apache/camel/quarkus/main/cmd/CamelRoute.java
+++ b/integration-tests/main-command-mode/src/main/java/org/apache/camel/quarkus/main/cmd/CamelRoute.java
@@ -18,6 +18,7 @@ package org.apache.camel.quarkus.main.cmd;
 
 import javax.enterprise.context.ApplicationScoped;
 
+import org.apache.camel.Exchange;
 import org.apache.camel.builder.RouteBuilder;
 import org.eclipse.microprofile.config.inject.ConfigProperty;
 
@@ -29,8 +30,8 @@ public class CamelRoute extends RouteBuilder {
 
     @Override
     public void configure() {
-        from("timer:hello?delay=-1&repeatCount=1")
+        from("timer:hello?delay=-1&repeatCount=3")
                 .setBody().constant("Hello " + greetedSubject + "!")
-                .to("log:hello");
+                .log("Logging ${body} - from timer named ${headers." + Exchange.TIMER_NAME + "}");
     }
 }
diff --git a/integration-tests/main-command-mode/src/main/resources/application.properties b/integration-tests/main-command-mode/src/main/resources/application.properties
deleted file mode 100644
index ade6fba..0000000
--- a/integration-tests/main-command-mode/src/main/resources/application.properties
+++ /dev/null
@@ -1,18 +0,0 @@
-## ---------------------------------------------------------------------------
-## 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.
-## ---------------------------------------------------------------------------
-
-camel.main.duration-max-messages = 1
diff --git a/integration-tests/main-command-mode/src/test/java/org/apache/camel/quarkus/main/cmd/it/CommandModeTest.java b/integration-tests/main-command-mode/src/test/java/org/apache/camel/quarkus/main/cmd/it/CommandModeTest.java
index d3a8c8e..ff128aa 100644
--- a/integration-tests/main-command-mode/src/test/java/org/apache/camel/quarkus/main/cmd/it/CommandModeTest.java
+++ b/integration-tests/main-command-mode/src/test/java/org/apache/camel/quarkus/main/cmd/it/CommandModeTest.java
@@ -17,25 +17,32 @@
 package org.apache.camel.quarkus.main.cmd.it;
 
 import java.io.IOException;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.TimeUnit;
 import java.util.concurrent.TimeoutException;
 
 import org.apache.camel.quarkus.test.support.process.QuarkusProcessExecutor;
 import org.apache.camel.util.StringHelper;
 import org.assertj.core.api.Assertions;
+import org.junit.jupiter.api.Disabled;
 import org.junit.jupiter.api.Test;
 import org.zeroturnaround.exec.InvalidExitValueException;
 import org.zeroturnaround.exec.ProcessResult;
+import org.zeroturnaround.exec.StartedProcess;
 
 import static org.assertj.core.api.Assertions.assertThat;
 
 public class CommandModeTest {
 
     @Test
-    void hello() throws InvalidExitValueException, IOException, InterruptedException, TimeoutException {
-        final ProcessResult result = new QuarkusProcessExecutor("-Dgreeted.subject=Joe").execute();
+    void testMainStopsAfterFirstMessage()
+            throws InvalidExitValueException, IOException, InterruptedException, TimeoutException {
+        final ProcessResult result = new QuarkusProcessExecutor("-Dgreeted.subject=Joe", "-Dcamel.main.duration-max-messages=1")
+                .execute();
 
         Assertions.assertThat(result.getExitValue()).isEqualTo(0);
-        Assertions.assertThat(result.outputUTF8()).contains("Hello Joe!");
+        Assertions.assertThat(result.outputUTF8()).contains("Logging Hello Joe! - from timer named hello");
+        Assertions.assertThat(result.outputUTF8()).contains("Duration max messages triggering shutdown of the JVM");
     }
 
     @Test
@@ -47,7 +54,7 @@ public class CommandModeTest {
         }
         String classpathArg = builder.toString();
 
-        final String[] jvmArgs = new String[] { "-Dgreeted.subject=Joe" };
+        final String[] jvmArgs = new String[] { "-Dgreeted.subject=Jane", "-Dcamel.main.duration-max-messages=1" };
         final String[] applicationArgs = new String[] {
                 "-d",
                 "10",
@@ -60,11 +67,28 @@ public class CommandModeTest {
 
         // Verify the application ran successfully
         assertThat(result.getExitValue()).isEqualTo(0);
-        assertThat(result.outputUTF8()).contains("Hello Joe!");
+        Assertions.assertThat(result.outputUTF8()).contains("Logging Hello Jane! - from timer named hello");
+        Assertions.assertThat(result.outputUTF8()).contains("Duration max messages triggering shutdown of the JVM");
 
         // Verify warning for unknown arguments was printed to the console
         String truncatedCpArg = String.format("%s...", StringHelper.limitLength(classpathArg, 97));
         assertThat(result.outputUTF8()).contains("Unknown option: -cp " + truncatedCpArg);
         assertThat(result.outputUTF8()).contains("Apache Camel Runner takes the following options");
     }
+
+    @Disabled("https://github.com/apache/camel-quarkus/issues/3394")
+    @Test
+    void testMainStopsAfterMaxSeconds() throws IOException, InterruptedException, ExecutionException {
+        final StartedProcess process = new QuarkusProcessExecutor("-Dgreeted.subject=Jade",
+                "-Dcamel.main.duration-max-seconds=3").start();
+        try {
+            ProcessResult result = process.getFuture().get(4, TimeUnit.SECONDS);
+            Assertions.assertThat(result.getExitValue()).isEqualTo(0);
+            Assertions.assertThat(result.outputUTF8()).contains("Waiting until complete: Duration max 3 seconds");
+            Assertions.assertThat(result.outputUTF8()).contains("Logging Hello Jade! - from timer named hello");
+            Assertions.assertThat(result.outputUTF8()).contains("Duration max seconds triggering shutdown of the JVM");
+        } catch (TimeoutException e) {
+            Assertions.fail("The process should not take so long as camel.main.duration-max-seconds is set");
+        }
+    }
 }