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

jamesnetherton 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 2be4733daf [closes #3927] Improve camel quarkus master integration test
2be4733daf is described below

commit 2be4733daf3615d4f92d54498f08288ef3c4a6f1
Author: Lukas Lowinger <[email protected]>
AuthorDate: Wed Jul 20 09:11:51 2022 +0200

    [closes #3927] Improve camel quarkus master integration test
---
 .../camel/quarkus/component/master/it/MasterRoutes.java      |  5 +++--
 .../apache/camel/quarkus/component/master/it/MasterTest.java | 12 ++++++++----
 2 files changed, 11 insertions(+), 6 deletions(-)

diff --git 
a/integration-tests/master/src/main/java/org/apache/camel/quarkus/component/master/it/MasterRoutes.java
 
b/integration-tests/master/src/main/java/org/apache/camel/quarkus/component/master/it/MasterRoutes.java
index 226e1f86b3..fd83c85310 100644
--- 
a/integration-tests/master/src/main/java/org/apache/camel/quarkus/component/master/it/MasterRoutes.java
+++ 
b/integration-tests/master/src/main/java/org/apache/camel/quarkus/component/master/it/MasterRoutes.java
@@ -41,8 +41,9 @@ public class MasterRoutes extends RouteBuilder {
 
         // Output the id of the application into a file
         from("master:ns:timer:test?period=100").id("leader")
-                .setBody(constant(applicationId))
-                .setHeader(Exchange.FILE_NAME, constant("leader.txt"))
+                .setBody(constant("leader"))
+                .setHeader(Exchange.FILE_NAME, 
constant(String.format("%s.txt", applicationId)))
+                .log(String.format("Application %s is writing into file", 
applicationId))
                 .to("file:target/cluster/");
     }
 }
diff --git 
a/integration-tests/master/src/test/java/org/apache/camel/quarkus/component/master/it/MasterTest.java
 
b/integration-tests/master/src/test/java/org/apache/camel/quarkus/component/master/it/MasterTest.java
index e7465a2c2b..ef48bda2d2 100644
--- 
a/integration-tests/master/src/test/java/org/apache/camel/quarkus/component/master/it/MasterTest.java
+++ 
b/integration-tests/master/src/test/java/org/apache/camel/quarkus/component/master/it/MasterTest.java
@@ -27,6 +27,7 @@ import io.quarkus.test.junit.QuarkusTest;
 import io.restassured.RestAssured;
 import org.apache.camel.quarkus.test.support.process.QuarkusProcessExecutor;
 import org.awaitility.Awaitility;
+import org.junit.jupiter.api.Assertions;
 import org.junit.jupiter.api.Test;
 import org.zeroturnaround.exec.StartedProcess;
 
@@ -45,9 +46,12 @@ class MasterTest {
         try {
             // Verify that this process is the cluster leader
             Awaitility.await().atMost(10, TimeUnit.SECONDS).with().until(() -> 
{
-                return readLeaderFile().equals("leader");
+                return readLeaderFile("leader").equals("leader");
             });
 
+            // Verify the follower hasn't took leader role
+            Assertions.assertTrue(readLeaderFile("follower").isEmpty());
+
             // Stop camel to trigger failover
             RestAssured.given()
                     .get("/master/camel/stop/leader")
@@ -56,7 +60,7 @@ class MasterTest {
 
             // Verify that the secondary application has been elected as the 
cluster leader
             Awaitility.await().atMost(10, TimeUnit.SECONDS).until(() -> {
-                return readLeaderFile().equals("follower");
+                return readLeaderFile("follower").equals("leader");
             });
         } finally {
             if (process != null && process.getProcess().isAlive()) {
@@ -85,8 +89,8 @@ class MasterTest {
         }
     }
 
-    private String readLeaderFile() throws IOException {
-        Path path = Paths.get("target/cluster/leader.txt");
+    private String readLeaderFile(String fileName) throws IOException {
+        Path path = Paths.get(String.format("target/cluster/%s.txt", 
fileName));
         if (path.toFile().exists()) {
             byte[] bytes = Files.readAllBytes(path);
             return new String(bytes, StandardCharsets.UTF_8);

Reply via email to