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 f009310188 add file cluster service automatic configuration itest #4262
f009310188 is described below
commit f009310188dcf38befac5b9fae8721fea62d1fa2
Author: aldettinger <[email protected]>
AuthorDate: Wed Nov 9 12:40:57 2022 +0100
add file cluster service automatic configuration itest #4262
---
.../ROOT/pages/reference/extensions/file.adoc | 1 +
.../file/runtime/src/main/doc/configuration.adoc | 1 +
integration-tests/master-file/pom.xml | 231 +++++++++++++++++++++
.../component/master/it/MasterResource.java | 36 ++++
.../quarkus/component/master/it/MasterRoutes.java | 41 ++++
.../src/main/resources/application.properties | 23 ++
.../quarkus/component/master/it/MasterFileIT.java | 24 +++
.../component/master/it/MasterFileTest.java | 106 ++++++++++
integration-tests/pom.xml | 1 +
tooling/scripts/test-categories.yaml | 1 +
tooling/test-list/pom.xml | 1 +
11 files changed, 466 insertions(+)
diff --git a/docs/modules/ROOT/pages/reference/extensions/file.adoc
b/docs/modules/ROOT/pages/reference/extensions/file.adoc
index 90f69ee3e3..39f1d45907 100644
--- a/docs/modules/ROOT/pages/reference/extensions/file.adoc
+++ b/docs/modules/ROOT/pages/reference/extensions/file.adoc
@@ -65,6 +65,7 @@ It's possible to enable the file cluster service with a
property like below:
```
quarkus.camel.cluster.file.enabled = true
+quarkus.camel.cluster.file.root =
target/cluster-folder-where-lock-file-will-be-held
```
As a result, a single consumer will be active across the `ns` camel master
namespace.
diff --git a/extensions/file/runtime/src/main/doc/configuration.adoc
b/extensions/file/runtime/src/main/doc/configuration.adoc
index 194f451d48..fc379d6044 100644
--- a/extensions/file/runtime/src/main/doc/configuration.adoc
+++ b/extensions/file/runtime/src/main/doc/configuration.adoc
@@ -14,6 +14,7 @@ It's possible to enable the file cluster service with a
property like below:
```
quarkus.camel.cluster.file.enabled = true
+quarkus.camel.cluster.file.root =
target/cluster-folder-where-lock-file-will-be-held
```
As a result, a single consumer will be active across the `ns` camel master
namespace.
diff --git a/integration-tests/master-file/pom.xml
b/integration-tests/master-file/pom.xml
new file mode 100644
index 0000000000..b054c4423a
--- /dev/null
+++ b/integration-tests/master-file/pom.xml
@@ -0,0 +1,231 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ 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.
+
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.apache.camel.quarkus</groupId>
+ <artifactId>camel-quarkus-build-parent-it</artifactId>
+ <version>2.15.0-SNAPSHOT</version>
+ <relativePath>../../poms/build-parent-it/pom.xml</relativePath>
+ </parent>
+
+ <artifactId>camel-quarkus-integration-test-master-file</artifactId>
+ <name>Camel Quarkus :: Integration Tests :: Master With File</name>
+ <description>Integration tests for Camel Quarkus Master extension with
File</description>
+
+ <properties>
+
<quarkus.runner>${project.build.directory}/quarkus-app/quarkus-run.jar</quarkus.runner>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.camel.quarkus</groupId>
+ <artifactId>camel-quarkus-file</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel.quarkus</groupId>
+ <artifactId>camel-quarkus-log</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel.quarkus</groupId>
+ <artifactId>camel-quarkus-master</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel.quarkus</groupId>
+ <artifactId>camel-quarkus-microprofile-health</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel.quarkus</groupId>
+ <artifactId>camel-quarkus-timer</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>io.quarkus</groupId>
+ <artifactId>quarkus-resteasy</artifactId>
+ </dependency>
+
+ <!-- test dependencies -->
+ <dependency>
+ <groupId>io.quarkus</groupId>
+ <artifactId>quarkus-junit5</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>io.rest-assured</groupId>
+ <artifactId>rest-assured</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel.quarkus</groupId>
+
<artifactId>camel-quarkus-integration-tests-process-executor-support</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.awaitility</groupId>
+ <artifactId>awaitility</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <profiles>
+
+ <profile>
+ <id>full</id>
+ <activation>
+ <property>
+ <name>!quickly</name>
+ </property>
+ </activation>
+ <build>
+ <plugins>
+ <plugin>
+ <!-- Move surefire:test to integration-test phase to
be able to run
+ java -jar target/*runner.jar from a test -->
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>default-test</id>
+ <goals>
+ <goal>test</goal>
+ </goals>
+ <phase>integration-test</phase>
+ <configuration>
+ <systemProperties>
+
<quarkus.runner>${quarkus.runner}</quarkus.runner>
+ </systemProperties>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
+ <profile>
+ <id>native</id>
+ <activation>
+ <property>
+ <name>native</name>
+ </property>
+ </activation>
+ <properties>
+ <quarkus.package.type>native</quarkus.package.type>
+
<quarkus.runner>${project.build.directory}/${project.artifactId}-${project.version}-runner</quarkus.runner>
+ </properties>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-failsafe-plugin</artifactId>
+ <executions>
+ <execution>
+ <goals>
+ <goal>integration-test</goal>
+ <goal>verify</goal>
+ </goals>
+ </execution>
+ </executions>
+ <configuration>
+ <systemProperties>
+
<quarkus.runner>${quarkus.runner}</quarkus.runner>
+ </systemProperties>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
+ <profile>
+ <id>virtualDependencies</id>
+ <activation>
+ <property>
+ <name>!noVirtualDependencies</name>
+ </property>
+ </activation>
+ <dependencies>
+ <!-- The following dependencies guarantee that this module is
built after them. You can update them by running `mvn process-resources
-Pformat -N` from the source tree root directory -->
+ <dependency>
+ <groupId>org.apache.camel.quarkus</groupId>
+ <artifactId>camel-quarkus-file-deployment</artifactId>
+ <version>${project.version}</version>
+ <type>pom</type>
+ <scope>test</scope>
+ <exclusions>
+ <exclusion>
+ <groupId>*</groupId>
+ <artifactId>*</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel.quarkus</groupId>
+ <artifactId>camel-quarkus-log-deployment</artifactId>
+ <version>${project.version}</version>
+ <type>pom</type>
+ <scope>test</scope>
+ <exclusions>
+ <exclusion>
+ <groupId>*</groupId>
+ <artifactId>*</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel.quarkus</groupId>
+ <artifactId>camel-quarkus-master-deployment</artifactId>
+ <version>${project.version}</version>
+ <type>pom</type>
+ <scope>test</scope>
+ <exclusions>
+ <exclusion>
+ <groupId>*</groupId>
+ <artifactId>*</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel.quarkus</groupId>
+
<artifactId>camel-quarkus-microprofile-health-deployment</artifactId>
+ <version>${project.version}</version>
+ <type>pom</type>
+ <scope>test</scope>
+ <exclusions>
+ <exclusion>
+ <groupId>*</groupId>
+ <artifactId>*</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel.quarkus</groupId>
+ <artifactId>camel-quarkus-timer-deployment</artifactId>
+ <version>${project.version}</version>
+ <type>pom</type>
+ <scope>test</scope>
+ <exclusions>
+ <exclusion>
+ <groupId>*</groupId>
+ <artifactId>*</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ </dependencies>
+ </profile>
+ </profiles>
+
+</project>
diff --git
a/integration-tests/master-file/src/main/java/org/apache/camel/quarkus/component/master/it/MasterResource.java
b/integration-tests/master-file/src/main/java/org/apache/camel/quarkus/component/master/it/MasterResource.java
new file mode 100644
index 0000000000..c9eb6c9a84
--- /dev/null
+++
b/integration-tests/master-file/src/main/java/org/apache/camel/quarkus/component/master/it/MasterResource.java
@@ -0,0 +1,36 @@
+/*
+ * 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.
+ */
+package org.apache.camel.quarkus.component.master.it;
+
+import javax.inject.Inject;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+
+import org.apache.camel.CamelContext;
+
+@Path("/master")
+public class MasterResource {
+
+ @Inject
+ CamelContext camelContext;
+
+ @Path("/camel/stop/leader")
+ @GET
+ public void stopLeaderRoute() throws Exception {
+ camelContext.getRouteController().stopRoute("leader");
+ }
+}
diff --git
a/integration-tests/master-file/src/main/java/org/apache/camel/quarkus/component/master/it/MasterRoutes.java
b/integration-tests/master-file/src/main/java/org/apache/camel/quarkus/component/master/it/MasterRoutes.java
new file mode 100644
index 0000000000..8c4f744f62
--- /dev/null
+++
b/integration-tests/master-file/src/main/java/org/apache/camel/quarkus/component/master/it/MasterRoutes.java
@@ -0,0 +1,41 @@
+/*
+ * 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.
+ */
+package org.apache.camel.quarkus.component.master.it;
+
+import javax.enterprise.context.ApplicationScoped;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.builder.RouteBuilder;
+import org.eclipse.microprofile.config.inject.ConfigProperty;
+
+@ApplicationScoped
+public class MasterRoutes extends RouteBuilder {
+
+ @ConfigProperty(name = "application.id")
+ String applicationId;
+
+ @Override
+ public void configure() {
+ // Output the id of the application into a file
+ from("master:ns:timer:test?period=100")
+ .id("leader")
+ .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-file/src/main/resources/application.properties
b/integration-tests/master-file/src/main/resources/application.properties
new file mode 100644
index 0000000000..04061f086d
--- /dev/null
+++ b/integration-tests/master-file/src/main/resources/application.properties
@@ -0,0 +1,23 @@
+## ---------------------------------------------------------------------------
+## 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.
+## ---------------------------------------------------------------------------
+
+application.id = leader
+
+quarkus.camel.cluster.file.enabled = true
+quarkus.camel.cluster.file.root = target/cluster
+quarkus.camel.cluster.file.acquire-lock-delay = 1s
+quarkus.camel.cluster.file.acquire-lock-interval = 1000
diff --git
a/integration-tests/master-file/src/test/java/org/apache/camel/quarkus/component/master/it/MasterFileIT.java
b/integration-tests/master-file/src/test/java/org/apache/camel/quarkus/component/master/it/MasterFileIT.java
new file mode 100644
index 0000000000..c0d3dd44ea
--- /dev/null
+++
b/integration-tests/master-file/src/test/java/org/apache/camel/quarkus/component/master/it/MasterFileIT.java
@@ -0,0 +1,24 @@
+/*
+ * 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.
+ */
+package org.apache.camel.quarkus.component.master.it;
+
+import io.quarkus.test.junit.QuarkusIntegrationTest;
+
+@QuarkusIntegrationTest
+class MasterFileIT extends MasterFileTest {
+
+}
diff --git
a/integration-tests/master-file/src/test/java/org/apache/camel/quarkus/component/master/it/MasterFileTest.java
b/integration-tests/master-file/src/test/java/org/apache/camel/quarkus/component/master/it/MasterFileTest.java
new file mode 100644
index 0000000000..229c3731d7
--- /dev/null
+++
b/integration-tests/master-file/src/test/java/org/apache/camel/quarkus/component/master/it/MasterFileTest.java
@@ -0,0 +1,106 @@
+/*
+ * 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.
+ */
+package org.apache.camel.quarkus.component.master.it;
+
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.TimeUnit;
+
+import io.quarkus.test.junit.QuarkusTest;
+import io.restassured.RestAssured;
+import org.apache.camel.quarkus.test.support.process.QuarkusProcessExecutor;
+import org.apache.commons.io.FileUtils;
+import org.awaitility.Awaitility;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+import org.zeroturnaround.exec.StartedProcess;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.emptyString;
+
+@QuarkusTest
+class MasterFileTest {
+
+ @BeforeAll
+ public static void deleteClusterFiles() throws IOException {
+ FileUtils.deleteDirectory(Paths.get("target/cluster/").toFile());
+ }
+
+ @Test
+ public void testFailover() throws IOException {
+
+ List<String> jvmArgs = new ArrayList<>();
+ jvmArgs.add("-Dapplication.id=follower");
+
+ // Start secondary application process
+ QuarkusProcessExecutor quarkusProcessExecutor = new
QuarkusProcessExecutor(jvmArgs.toArray(String[]::new));
+ StartedProcess process = quarkusProcessExecutor.start();
+
+ // Wait until the process is fully initialized
+ awaitStartup(quarkusProcessExecutor);
+
+ try {
+ // Verify that this process is the cluster leader
+ Awaitility.await().atMost(10, TimeUnit.SECONDS).with().until(() ->
{
+ return readLeaderFile("leader").equals("leader");
+ });
+
+ // Verify the follower hasn't took leader role
+ assertThat(readLeaderFile("follower"), emptyString());
+
+ // Stop camel leader route to trigger fail-over
+
RestAssured.given().get("/master/camel/stop/leader").then().statusCode(204);
+
+ // Verify that the secondary application has been elected as the
+ // cluster leader
+ Awaitility.await().atMost(10, TimeUnit.SECONDS).until(() -> {
+ return readLeaderFile("follower").equals("leader");
+ });
+ } finally {
+ if (process != null && process.getProcess().isAlive()) {
+ process.getProcess().destroy();
+ }
+ }
+ }
+
+ private void awaitStartup(QuarkusProcessExecutor quarkusProcessExecutor) {
+ Awaitility.await().atMost(10, TimeUnit.SECONDS).pollDelay(1,
TimeUnit.SECONDS).until(() -> {
+ return isApplicationHealthy(quarkusProcessExecutor.getHttpPort());
+ });
+ }
+
+ private boolean isApplicationHealthy(int port) {
+ try {
+ int status =
RestAssured.given().port(port).get("/q/health").then().extract().statusCode();
+ return status == 200;
+ } catch (Exception e) {
+ return false;
+ }
+ }
+
+ private String readLeaderFile(String fileName) throws IOException {
+ Path path = Paths.get(String.format("target/cluster/%s.txt",
fileName));
+ if (path.toFile().exists()) {
+ return FileUtils.readFileToString(path.toFile(),
StandardCharsets.UTF_8);
+ }
+ return "";
+ }
+}
diff --git a/integration-tests/pom.xml b/integration-tests/pom.xml
index 15f1ec09b7..bdc08896ac 100644
--- a/integration-tests/pom.xml
+++ b/integration-tests/pom.xml
@@ -149,6 +149,7 @@
<module>lumberjack</module>
<module>mail</module>
<module>master</module>
+ <module>master-file</module>
<module>master-openshift</module>
<module>messaging</module>
<module>micrometer</module>
diff --git a/tooling/scripts/test-categories.yaml
b/tooling/scripts/test-categories.yaml
index 7a7b29847c..0a9de36fa0 100644
--- a/tooling/scripts/test-categories.yaml
+++ b/tooling/scripts/test-categories.yaml
@@ -128,6 +128,7 @@ group-08:
- dozer
- jq
- master
+ - master-file
- master-openshift
- pdf
- saxon
diff --git a/tooling/test-list/pom.xml b/tooling/test-list/pom.xml
index b5af2d21e9..a5c0bd53c0 100644
--- a/tooling/test-list/pom.xml
+++ b/tooling/test-list/pom.xml
@@ -58,6 +58,7 @@
<exclude>support/**/*</exclude>
<exclude>master/pom.xml</exclude>
<exclude>master-openshift/pom.xml</exclude>
+ <exclude>master-file/pom.xml</exclude>
<exclude>main-command-mode/pom.xml</exclude>
<exclude>main-unknown-args-fail/pom.xml</exclude>
<exclude>main-unknown-args-ignore/pom.xml</exclude>