This is an automated email from the ASF dual-hosted git repository. lburgazzoli pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git
The following commit(s) were added to refs/heads/master by this push: new c57b8a8 Do not use hard coded ports in integration-tests #508 c57b8a8 is described below commit c57b8a873f0f8d4f829698a48d144378de7658d6 Author: lburgazzoli <lburgazz...@gmail.com> AuthorDate: Wed Dec 4 14:56:17 2019 +0100 Do not use hard coded ports in integration-tests #508 --- integration-tests/hystrix/pom.xml | 7 ++ .../component/hystrix/it/HystrixRoutes.java | 4 +- .../quarkus/component/hystrix/it/HystrixTest.java | 2 + .../component/hystrix/it/HystrixTestResource.java} | 22 +++--- .../quarkus/component/jdbc/CamelJdbcTest.java | 3 + integration-tests/kafka/pom.xml | 19 +++++ .../component/kafka/CamelKafkaResource.java | 40 +++++------ .../quarkus/component/kafka/CamelKafkaSupport.java | 4 +- .../src/main/resources/application.properties | 8 +-- .../component/kafka/it/CamelKafkaTestResource.java | 36 ++++++++-- integration-tests/mongodb/pom.xml | 9 +++ .../component/mongodb/it/MongoDbResource.java | 12 +++- .../quarkus/component/mongodb/it/MongoDbTest.java | 40 ++--------- .../component/mongodb/it/MongoDbTestResource.java | 74 +++++++++++++++++++ integration-tests/netty-http/pom.xml | 7 ++ .../quarkus/component/netty/http/CamelRoute.java | 6 +- .../quarkus/component/netty/http/CamelTest.java | 12 +++- .../netty/http/NettyHttpTestResource.java} | 20 +++--- integration-tests/netty/pom.xml | 7 ++ .../camel/quarkus/component/netty/CamelRoute.java | 15 +--- .../camel/quarkus/component/netty/Poetry.java | 56 --------------- .../camel/quarkus/component/netty/NettyTest.java | 21 +++--- .../component/netty/NettyTestResource.java} | 20 ++++-- integration-tests/paho/pom.xml | 9 +++ .../component/paho/it/ActiveMQTestResource.java | 36 ++++++++-- integration-tests/pom.xml | 5 ++ integration-tests/sjms/.gitignore | 1 + integration-tests/sjms/pom.xml | 19 +++-- .../sjms/src/main/resources/application.properties | 5 -- .../quarkus/component/sjms/it/CamelSjmsTest.java | 8 ++- ...estResource.java => CamelSjmsTestResource.java} | 40 +++++++++-- integration-tests/support/core-main/pom.xml | 2 +- integration-tests/support/core/pom.xml | 2 +- integration-tests/support/pom.xml | 5 +- .../support/{ => test-support}/pom.xml | 27 ++++--- .../camel/quarkus/test/AvailablePortFinder.java | 83 ++++++++++++++++++++++ pom.xml | 8 +++ 37 files changed, 475 insertions(+), 219 deletions(-) diff --git a/integration-tests/hystrix/pom.xml b/integration-tests/hystrix/pom.xml index 086cc42..13677b0 100644 --- a/integration-tests/hystrix/pom.xml +++ b/integration-tests/hystrix/pom.xml @@ -58,6 +58,13 @@ <artifactId>rest-assured</artifactId> <scope>test</scope> </dependency> + + <!-- test dependencies - camel-quarkus --> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-integration-test-support</artifactId> + <scope>test</scope> + </dependency> </dependencies> <build> diff --git a/integration-tests/hystrix/src/main/java/org/apache/camel/quarkus/component/hystrix/it/HystrixRoutes.java b/integration-tests/hystrix/src/main/java/org/apache/camel/quarkus/component/hystrix/it/HystrixRoutes.java index 56ea292..8aa4026 100644 --- a/integration-tests/hystrix/src/main/java/org/apache/camel/quarkus/component/hystrix/it/HystrixRoutes.java +++ b/integration-tests/hystrix/src/main/java/org/apache/camel/quarkus/component/hystrix/it/HystrixRoutes.java @@ -36,14 +36,14 @@ public class HystrixRoutes extends RouteBuilder { .circuitBreaker() .throwException(new IllegalStateException("Forced exception")) .onFallbackViaNetwork() - .to("netty-http:http://localhost:8999/network/fallback") + .to("netty-http:http://localhost:{{camel.netty.test-port}}/network/fallback") .end(); from("direct:delay") .delay(simple("${header.delayMilliseconds}")) .setBody(constant("Hello Camel Quarkus Hystrix")); - from("netty-http:http://0.0.0.0:8999/network/fallback") + from("netty-http:http://0.0.0.0:{{camel.netty.test-port}}/network/fallback") .setBody(constant("Fallback via network response")); } } diff --git a/integration-tests/hystrix/src/test/java/org/apache/camel/quarkus/component/hystrix/it/HystrixTest.java b/integration-tests/hystrix/src/test/java/org/apache/camel/quarkus/component/hystrix/it/HystrixTest.java index 6056c81..1a9ef03 100644 --- a/integration-tests/hystrix/src/test/java/org/apache/camel/quarkus/component/hystrix/it/HystrixTest.java +++ b/integration-tests/hystrix/src/test/java/org/apache/camel/quarkus/component/hystrix/it/HystrixTest.java @@ -16,6 +16,7 @@ */ package org.apache.camel.quarkus.component.hystrix.it; +import io.quarkus.test.common.QuarkusTestResource; import io.quarkus.test.junit.QuarkusTest; import io.restassured.RestAssured; @@ -23,6 +24,7 @@ import org.junit.jupiter.api.Test; import static org.hamcrest.core.Is.is; @QuarkusTest +@QuarkusTestResource(HystrixTestResource.class) class HystrixTest { @Test diff --git a/integration-tests/netty-http/src/main/java/org/apache/camel/quarkus/component/netty/http/CamelRoute.java b/integration-tests/hystrix/src/test/java/org/apache/camel/quarkus/component/hystrix/it/HystrixTestResource.java similarity index 62% copy from integration-tests/netty-http/src/main/java/org/apache/camel/quarkus/component/netty/http/CamelRoute.java copy to integration-tests/hystrix/src/test/java/org/apache/camel/quarkus/component/hystrix/it/HystrixTestResource.java index 0799ebf..bf84634 100644 --- a/integration-tests/netty-http/src/main/java/org/apache/camel/quarkus/component/netty/http/CamelRoute.java +++ b/integration-tests/hystrix/src/test/java/org/apache/camel/quarkus/component/hystrix/it/HystrixTestResource.java @@ -14,20 +14,22 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.camel.quarkus.component.netty.http; +package org.apache.camel.quarkus.component.hystrix.it; -import org.apache.camel.builder.RouteBuilder; +import java.util.Map; +import java.util.Objects; -public class CamelRoute extends RouteBuilder { +import org.apache.camel.quarkus.test.AvailablePortFinder; - @Override - public void configure() { - from("netty-http:http://0.0.0.0:8999/foo") - .transform().constant("Netty Hello World"); +import io.quarkus.test.common.QuarkusTestResourceLifecycleManager; - /* /producer proxying /foo */ - from("netty-http:http://0.0.0.0:8999/producer") - .to("netty-http:http://localhost:8999/foo"); +public class HystrixTestResource implements QuarkusTestResourceLifecycleManager { + @Override + public Map<String, String> start() { + return AvailablePortFinder.reserveNetworkPorts(Objects::toString, "camel.netty.test-port"); + } + @Override + public void stop() { } } diff --git a/integration-tests/jdbc/src/test/java/org/apache/camel/quarkus/component/jdbc/CamelJdbcTest.java b/integration-tests/jdbc/src/test/java/org/apache/camel/quarkus/component/jdbc/CamelJdbcTest.java index 4571932..d14aea4 100644 --- a/integration-tests/jdbc/src/test/java/org/apache/camel/quarkus/component/jdbc/CamelJdbcTest.java +++ b/integration-tests/jdbc/src/test/java/org/apache/camel/quarkus/component/jdbc/CamelJdbcTest.java @@ -16,6 +16,8 @@ */ package org.apache.camel.quarkus.component.jdbc; +import io.quarkus.test.common.QuarkusTestResource; +import io.quarkus.test.h2.H2DatabaseTestResource; import io.quarkus.test.junit.QuarkusTest; import io.restassured.RestAssured; import io.restassured.http.ContentType; @@ -24,6 +26,7 @@ import org.junit.jupiter.api.Test; import static org.hamcrest.Matchers.is; @QuarkusTest +@QuarkusTestResource(H2DatabaseTestResource.class) public class CamelJdbcTest { @Test diff --git a/integration-tests/kafka/pom.xml b/integration-tests/kafka/pom.xml index a02282d..8349bc0 100644 --- a/integration-tests/kafka/pom.xml +++ b/integration-tests/kafka/pom.xml @@ -29,6 +29,10 @@ <name>Camel Quarkus :: Integration Tests :: Kafka</name> <description>Integration tests for Camel Quarkus Kafka extension</description> + <properties> + <rerun.failing.test.count>2</rerun.failing.test.count> + </properties> + <dependencies> <dependency> <groupId>org.apache.camel.quarkus</groupId> @@ -68,6 +72,13 @@ <scope>test</scope> </dependency> + <!-- test dependencies - camel-quarkus --> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-integration-test-support</artifactId> + <scope>test</scope> + </dependency> + <!-- test dependencies - kafka --> <dependency> <groupId>io.debezium</groupId> @@ -100,6 +111,13 @@ </execution> </executions> </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-surefire-plugin</artifactId> + <configuration> + <rerunFailingTestsCount>${rerun.failing.test.count}</rerunFailingTestsCount> + </configuration> + </plugin> </plugins> </build> @@ -123,6 +141,7 @@ <goal>verify</goal> </goals> <configuration> + <rerunFailingTestsCount>${rerun.failing.test.count}</rerunFailingTestsCount> <systemProperties> <native.image.path>${project.build.directory}/${project.build.finalName}-runner</native.image.path> </systemProperties> diff --git a/integration-tests/kafka/src/main/java/org/apache/camel/quarkus/component/kafka/CamelKafkaResource.java b/integration-tests/kafka/src/main/java/org/apache/camel/quarkus/component/kafka/CamelKafkaResource.java index 748e82d..6639e8b 100644 --- a/integration-tests/kafka/src/main/java/org/apache/camel/quarkus/component/kafka/CamelKafkaResource.java +++ b/integration-tests/kafka/src/main/java/org/apache/camel/quarkus/component/kafka/CamelKafkaResource.java @@ -29,6 +29,8 @@ import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; import org.apache.kafka.clients.consumer.ConsumerRecord; +import org.apache.kafka.clients.consumer.KafkaConsumer; +import org.apache.kafka.clients.producer.Producer; import org.apache.kafka.clients.producer.ProducerRecord; import org.apache.kafka.clients.producer.RecordMetadata; @@ -39,32 +41,30 @@ public class CamelKafkaResource { @POST @Produces(MediaType.APPLICATION_JSON) public JsonObject post(@PathParam("topicName") String topicName, String message) throws Exception { - RecordMetadata meta = CamelKafkaSupport.createProducer() - .send(new ProducerRecord<>(topicName, 1, message)) - .get(); + try (Producer<Integer, String> producer = CamelKafkaSupport.createProducer()) { + RecordMetadata meta = producer.send(new ProducerRecord<>(topicName, 1, message)).get(); - return Json.createObjectBuilder() - .add("topicName", meta.topic()) - .add("partition", meta.partition()) - .add("offset", meta.offset()) - .build(); + return Json.createObjectBuilder() + .add("topicName", meta.topic()) + .add("partition", meta.partition()) + .add("offset", meta.offset()) + .build(); + } } @Path("/kafka/{topicName}") @GET @Produces(MediaType.APPLICATION_JSON) public JsonObject get(@PathParam("topicName") String topicName) { - ConsumerRecord<Integer, String> record = CamelKafkaSupport.createConsumer(topicName) - .poll(Duration.ofSeconds(60)) - .iterator() - .next(); - - return Json.createObjectBuilder() - .add("topicName", record.topic()) - .add("partition", record.partition()) - .add("offset", record.offset()) - .add("key", record.key()) - .add("body", record.value()) - .build(); + try (KafkaConsumer<Integer, String> consumer = CamelKafkaSupport.createConsumer(topicName)) { + ConsumerRecord<Integer, String> record = consumer.poll(Duration.ofSeconds(60)).iterator().next(); + return Json.createObjectBuilder() + .add("topicName", record.topic()) + .add("partition", record.partition()) + .add("offset", record.offset()) + .add("key", record.key()) + .add("body", record.value()) + .build(); + } } } diff --git a/integration-tests/kafka/src/main/java/org/apache/camel/quarkus/component/kafka/CamelKafkaSupport.java b/integration-tests/kafka/src/main/java/org/apache/camel/quarkus/component/kafka/CamelKafkaSupport.java index baa2eee..8cba566 100644 --- a/integration-tests/kafka/src/main/java/org/apache/camel/quarkus/component/kafka/CamelKafkaSupport.java +++ b/integration-tests/kafka/src/main/java/org/apache/camel/quarkus/component/kafka/CamelKafkaSupport.java @@ -35,7 +35,7 @@ public final class CamelKafkaSupport { public static KafkaConsumer<Integer, String> createConsumer(String topicName) { Properties props = new Properties(); - props.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, "localhost:19092"); + props.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, System.getProperty("camel.component.kafka.brokers")); props.put(ConsumerConfig.GROUP_ID_CONFIG, "test"); props.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, IntegerDeserializer.class.getName()); props.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class.getName()); @@ -50,7 +50,7 @@ public final class CamelKafkaSupport { public static Producer<Integer, String> createProducer() { Properties props = new Properties(); - props.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, "localhost:19092"); + props.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, System.getProperty("camel.component.kafka.brokers")); props.put(ProducerConfig.CLIENT_ID_CONFIG, "test-consumer"); props.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, IntegerSerializer.class.getName()); props.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, StringSerializer.class.getName()); diff --git a/integration-tests/kafka/src/main/resources/application.properties b/integration-tests/kafka/src/main/resources/application.properties index a41a269..fafb51f 100644 --- a/integration-tests/kafka/src/main/resources/application.properties +++ b/integration-tests/kafka/src/main/resources/application.properties @@ -16,7 +16,7 @@ ## --------------------------------------------------------------------------- # -# Quarkus +# Quarkus - Log # quarkus.log.file.enable = false quarkus.log.category."org.apache.camel.quarkus.core.deployment".level = INFO @@ -24,7 +24,5 @@ quarkus.log.category."org.apache.camel.quarkus.component.kafka".level = DEBUG quarkus.log.category."org.apache.zookeeper".level = WARNING quarkus.log.category."org.apache.kafka".level = WARNING -# -# Camel -# -camel.component.kafka.brokers = localhost:19092 \ No newline at end of file +%quiet.quarkus.log.category."kafka".level = WARNING +%quiet.quarkus.log.category."kafka.log".level = FATAL diff --git a/integration-tests/kafka/src/test/java/org/apache/camel/quarkus/component/kafka/it/CamelKafkaTestResource.java b/integration-tests/kafka/src/test/java/org/apache/camel/quarkus/component/kafka/it/CamelKafkaTestResource.java index d33a466..a28083a 100644 --- a/integration-tests/kafka/src/test/java/org/apache/camel/quarkus/component/kafka/it/CamelKafkaTestResource.java +++ b/integration-tests/kafka/src/test/java/org/apache/camel/quarkus/component/kafka/it/CamelKafkaTestResource.java @@ -17,43 +17,67 @@ package org.apache.camel.quarkus.component.kafka.it; import java.io.File; +import java.nio.file.Files; import java.util.Collections; import java.util.Map; import java.util.Properties; import io.debezium.kafka.KafkaCluster; -import io.debezium.util.Testing; import io.quarkus.test.common.QuarkusTestResourceLifecycleManager; +import org.apache.camel.quarkus.core.CamelMain; +import org.apache.camel.quarkus.test.AvailablePortFinder; public class CamelKafkaTestResource implements QuarkusTestResourceLifecycleManager { private KafkaCluster kafka; + private CamelMain main; + + @Override + public void inject(Object testInstance) { + if (testInstance instanceof CamelKafkaTest) { + this.main = ((CamelKafkaTest) testInstance).main; + } + } @Override public Map<String, String> start() { try { + final int zkPort = AvailablePortFinder.getNextAvailable(); + final int kafkaPort = AvailablePortFinder.getNextAvailable(); + final File directory = Files.createTempDirectory("kafka-data-").toFile(); + Properties props = new Properties(); props.setProperty("zookeeper.connection.timeout.ms", "45000"); - File directory = Testing.Files.createTestingDirectory("kafka-data", true); - kafka = new KafkaCluster() - .withPorts(2182, 19092) + .withPorts(zkPort, kafkaPort) .addBrokers(1) .usingDirectory(directory) .deleteDataUponShutdown(true) .withKafkaConfiguration(props) .deleteDataPriorToStartup(true) .startup(); + + return Collections.singletonMap("camel.component.kafka.brokers", "localhost:" + kafkaPort); } catch (Exception e) { throw new RuntimeException(e); } - return Collections.emptyMap(); } @Override public void stop() { + if (main != null) { + try { + main.stop(); + } catch (Exception e) { + // ignored + } + } if (kafka != null) { - kafka.shutdown(); + try { + kafka.shutdown(); + } catch (Exception e) { + // ignored + } } } } diff --git a/integration-tests/mongodb/pom.xml b/integration-tests/mongodb/pom.xml index 2e59c13..297b5a6 100644 --- a/integration-tests/mongodb/pom.xml +++ b/integration-tests/mongodb/pom.xml @@ -54,6 +54,15 @@ <artifactId>rest-assured</artifactId> <scope>test</scope> </dependency> + + <!-- test dependencies - camel-quarkus --> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-integration-test-support</artifactId> + <scope>test</scope> + </dependency> + + <!-- test dependencies - mongodb --> <dependency> <groupId>de.flapdoodle.embed</groupId> <artifactId>de.flapdoodle.embed.mongo</artifactId> diff --git a/integration-tests/mongodb/src/main/java/org/apache/camel/quarkus/component/mongodb/it/MongoDbResource.java b/integration-tests/mongodb/src/main/java/org/apache/camel/quarkus/component/mongodb/it/MongoDbResource.java index 9022649..cc63cd4 100644 --- a/integration-tests/mongodb/src/main/java/org/apache/camel/quarkus/component/mongodb/it/MongoDbResource.java +++ b/integration-tests/mongodb/src/main/java/org/apache/camel/quarkus/component/mongodb/it/MongoDbResource.java @@ -18,9 +18,9 @@ package org.apache.camel.quarkus.component.mongodb.it; import java.net.URI; import java.net.URISyntaxException; - import javax.enterprise.context.ApplicationScoped; import javax.inject.Inject; +import javax.inject.Named; import javax.json.Json; import javax.json.JsonArray; import javax.json.JsonArrayBuilder; @@ -34,16 +34,15 @@ import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; +import com.mongodb.MongoClient; import com.mongodb.client.MongoCursor; import com.mongodb.client.MongoIterable; - import org.apache.camel.ProducerTemplate; import org.bson.Document; @Path("/mongodb") @ApplicationScoped public class MongoDbResource { - @Inject ProducerTemplate producerTemplate; @@ -65,6 +64,7 @@ public class MongoDbResource { @GET @Path("/collection/{collectionName}") @Produces(MediaType.APPLICATION_JSON) + @SuppressWarnings("unchecked") public JsonArray getCollection(@PathParam("collectionName") String collectionName) { JsonArrayBuilder arrayBuilder = Json.createArrayBuilder(); @@ -83,4 +83,10 @@ public class MongoDbResource { return arrayBuilder.build(); } + + @javax.enterprise.inject.Produces + @Named("camelMongoClient") + public MongoClient camelMongoClient() { + return new MongoClient("localhost", Integer.getInteger("camel.mongodb.test-port")); + } } diff --git a/integration-tests/mongodb/src/test/java/org/apache/camel/quarkus/component/mongodb/it/MongoDbTest.java b/integration-tests/mongodb/src/test/java/org/apache/camel/quarkus/component/mongodb/it/MongoDbTest.java index 688746f..4ed13a7 100644 --- a/integration-tests/mongodb/src/test/java/org/apache/camel/quarkus/component/mongodb/it/MongoDbTest.java +++ b/integration-tests/mongodb/src/test/java/org/apache/camel/quarkus/component/mongodb/it/MongoDbTest.java @@ -16,49 +16,21 @@ */ package org.apache.camel.quarkus.component.mongodb.it; -import de.flapdoodle.embed.mongo.MongodExecutable; -import de.flapdoodle.embed.mongo.MongodStarter; -import de.flapdoodle.embed.mongo.config.IMongodConfig; -import de.flapdoodle.embed.mongo.config.MongodConfigBuilder; -import de.flapdoodle.embed.mongo.config.Net; -import de.flapdoodle.embed.mongo.distribution.Version; -import de.flapdoodle.embed.process.runtime.Network; +import java.util.List; +import java.util.Map; + +import io.quarkus.test.common.QuarkusTestResource; import io.quarkus.test.junit.QuarkusTest; import io.restassured.RestAssured; import io.restassured.http.ContentType; import io.restassured.path.json.JsonPath; - -import java.io.IOException; -import java.util.List; -import java.util.Map; - -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; + import static org.junit.jupiter.api.Assertions.assertEquals; @QuarkusTest +@QuarkusTestResource(MongoDbTestResource.class) class MongoDbTest { - - private static MongodExecutable MONGO; - - @BeforeAll - public static void beforeAll() throws IOException { - IMongodConfig config = new MongodConfigBuilder() - .net(new Net(27017, Network.localhostIsIPv6())) - .version(Version.Main.V4_0) - .build(); - MONGO = MongodStarter.getDefaultInstance().prepare(config); - MONGO.start(); - } - - @AfterAll - public static void afterAll() { - if (MONGO != null) { - MONGO.stop(); - } - } - @Test public void testMongoDbComponent() { // Write to collection diff --git a/integration-tests/mongodb/src/test/java/org/apache/camel/quarkus/component/mongodb/it/MongoDbTestResource.java b/integration-tests/mongodb/src/test/java/org/apache/camel/quarkus/component/mongodb/it/MongoDbTestResource.java new file mode 100644 index 0000000..d64fee0 --- /dev/null +++ b/integration-tests/mongodb/src/test/java/org/apache/camel/quarkus/component/mongodb/it/MongoDbTestResource.java @@ -0,0 +1,74 @@ +/* + * 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.mongodb.it; + +import java.util.Collections; +import java.util.Map; + +import de.flapdoodle.embed.mongo.MongodExecutable; +import de.flapdoodle.embed.mongo.MongodProcess; +import de.flapdoodle.embed.mongo.MongodStarter; +import de.flapdoodle.embed.mongo.config.IMongodConfig; +import de.flapdoodle.embed.mongo.config.MongodConfigBuilder; +import de.flapdoodle.embed.mongo.config.Net; +import de.flapdoodle.embed.mongo.distribution.Version; +import de.flapdoodle.embed.process.runtime.Network; +import io.quarkus.test.common.QuarkusTestResourceLifecycleManager; +import org.apache.camel.quarkus.test.AvailablePortFinder; + +public class MongoDbTestResource implements QuarkusTestResourceLifecycleManager { + private MongodExecutable mongo; + private MongodProcess mongoProcess; + + @Override + public Map<String, String> start() { + try { + final int port = AvailablePortFinder.getNextAvailable(); + + IMongodConfig config = new MongodConfigBuilder() + .net(new Net("localhost", port, Network.localhostIsIPv6())) + .version(Version.Main.V4_0) + .build(); + + mongo = MongodStarter.getDefaultInstance().prepare(config); + mongoProcess = mongo.start(); + + return Collections.singletonMap("camel.mongodb.test-port", Integer.toString(port)); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + @Override + public void stop() { + try { + if (mongoProcess != null) { + mongoProcess.stop(); + } + } catch (Exception e) { + // ignored + } + try { + if (mongo != null) { + mongo.stop(); + } + } catch (Exception e) { + // ignored + } + } +} diff --git a/integration-tests/netty-http/pom.xml b/integration-tests/netty-http/pom.xml index a977e30..999b269 100644 --- a/integration-tests/netty-http/pom.xml +++ b/integration-tests/netty-http/pom.xml @@ -53,6 +53,13 @@ <scope>test</scope> </dependency> + <!-- test dependencies - camel-quarkus --> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-integration-test-support</artifactId> + <scope>test</scope> + </dependency> + </dependencies> <build> diff --git a/integration-tests/netty-http/src/main/java/org/apache/camel/quarkus/component/netty/http/CamelRoute.java b/integration-tests/netty-http/src/main/java/org/apache/camel/quarkus/component/netty/http/CamelRoute.java index 0799ebf..db5ea37 100644 --- a/integration-tests/netty-http/src/main/java/org/apache/camel/quarkus/component/netty/http/CamelRoute.java +++ b/integration-tests/netty-http/src/main/java/org/apache/camel/quarkus/component/netty/http/CamelRoute.java @@ -22,12 +22,12 @@ public class CamelRoute extends RouteBuilder { @Override public void configure() { - from("netty-http:http://0.0.0.0:8999/foo") + from("netty-http:http://0.0.0.0:{{camel.netty.test-port}}/foo") .transform().constant("Netty Hello World"); /* /producer proxying /foo */ - from("netty-http:http://0.0.0.0:8999/producer") - .to("netty-http:http://localhost:8999/foo"); + from("netty-http:http://0.0.0.0:{{camel.netty.test-port}}/producer") + .to("netty-http:http://localhost:{{camel.netty.test-port}}/foo"); } } diff --git a/integration-tests/netty-http/src/test/java/org/apache/camel/quarkus/component/netty/http/CamelTest.java b/integration-tests/netty-http/src/test/java/org/apache/camel/quarkus/component/netty/http/CamelTest.java index 7ac2cdd..eaba3de 100644 --- a/integration-tests/netty-http/src/test/java/org/apache/camel/quarkus/component/netty/http/CamelTest.java +++ b/integration-tests/netty-http/src/test/java/org/apache/camel/quarkus/component/netty/http/CamelTest.java @@ -18,6 +18,7 @@ package org.apache.camel.quarkus.component.netty.http; import java.net.URI; +import io.quarkus.test.common.QuarkusTestResource; import io.quarkus.test.junit.QuarkusTest; import io.restassured.RestAssured; @@ -26,17 +27,24 @@ import org.junit.jupiter.api.Test; import static org.hamcrest.Matchers.is; @QuarkusTest +@QuarkusTestResource(NettyHttpTestResource.class) public class CamelTest { @Test public void testNetty4Http() throws Exception { - RestAssured.when().get(new URI("http://localhost:8999/foo")) + final int port = Integer.getInteger("camel.netty.test-port"); + final String uri = String.format("http://localhost:%d/foo", port); + + RestAssured.when().get(new URI(uri)) .then().body(is("Netty Hello World")); } @Test public void netty4HttpProducer() throws Exception { - RestAssured.when().get(new URI("http://localhost:8999/producer")) + final int port = Integer.getInteger("camel.netty.test-port"); + final String uri = String.format("http://localhost:%d/producer", port); + + RestAssured.when().get(new URI(uri)) .then().statusCode(200).body(is("Netty Hello World")); } diff --git a/integration-tests/netty-http/src/main/java/org/apache/camel/quarkus/component/netty/http/CamelRoute.java b/integration-tests/netty-http/src/test/java/org/apache/camel/quarkus/component/netty/http/NettyHttpTestResource.java similarity index 66% copy from integration-tests/netty-http/src/main/java/org/apache/camel/quarkus/component/netty/http/CamelRoute.java copy to integration-tests/netty-http/src/test/java/org/apache/camel/quarkus/component/netty/http/NettyHttpTestResource.java index 0799ebf..fe7ead2 100644 --- a/integration-tests/netty-http/src/main/java/org/apache/camel/quarkus/component/netty/http/CamelRoute.java +++ b/integration-tests/netty-http/src/test/java/org/apache/camel/quarkus/component/netty/http/NettyHttpTestResource.java @@ -16,18 +16,20 @@ */ package org.apache.camel.quarkus.component.netty.http; -import org.apache.camel.builder.RouteBuilder; +import java.util.Map; +import java.util.Objects; -public class CamelRoute extends RouteBuilder { +import org.apache.camel.quarkus.test.AvailablePortFinder; - @Override - public void configure() { - from("netty-http:http://0.0.0.0:8999/foo") - .transform().constant("Netty Hello World"); +import io.quarkus.test.common.QuarkusTestResourceLifecycleManager; - /* /producer proxying /foo */ - from("netty-http:http://0.0.0.0:8999/producer") - .to("netty-http:http://localhost:8999/foo"); +public class NettyHttpTestResource implements QuarkusTestResourceLifecycleManager { + @Override + public Map<String, String> start() { + return AvailablePortFinder.reserveNetworkPorts(Objects::toString, "camel.netty.test-port"); + } + @Override + public void stop() { } } diff --git a/integration-tests/netty/pom.xml b/integration-tests/netty/pom.xml index 030b51e..b38a4d8 100644 --- a/integration-tests/netty/pom.xml +++ b/integration-tests/netty/pom.xml @@ -52,6 +52,13 @@ <artifactId>rest-assured</artifactId> <scope>test</scope> </dependency> + + <!-- test dependencies - camel-quarkus --> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-integration-test-support</artifactId> + <scope>test</scope> + </dependency> </dependencies> <build> diff --git a/integration-tests/netty/src/main/java/org/apache/camel/quarkus/component/netty/CamelRoute.java b/integration-tests/netty/src/main/java/org/apache/camel/quarkus/component/netty/CamelRoute.java index bfd2c58..b19ca3e 100644 --- a/integration-tests/netty/src/main/java/org/apache/camel/quarkus/component/netty/CamelRoute.java +++ b/integration-tests/netty/src/main/java/org/apache/camel/quarkus/component/netty/CamelRoute.java @@ -19,20 +19,9 @@ package org.apache.camel.quarkus.component.netty; import org.apache.camel.builder.RouteBuilder; public class CamelRoute extends RouteBuilder { - @Override public void configure() { - - from("netty:tcp://0.0.0.0:8994?textline=true&sync=true") - .process().message(message -> { - if (message.getBody() instanceof Poetry) { - Poetry poetry = (Poetry) message.getBody(); - poetry.setPoet("Dr. Sarojini Naidu"); - message.setBody(poetry); - return; - } - message.setBody("When You Go Home, Tell Them Of Us And Say, For Your Tomorrow, We Gave Our Today."); - }); - + from("netty:tcp://0.0.0.0:{{camel.netty.test-port}}?textline=true&sync=true") + .setBody().constant("When You Go Home, Tell Them Of Us And Say, For Your Tomorrow, We Gave Our Today."); } } diff --git a/integration-tests/netty/src/main/java/org/apache/camel/quarkus/component/netty/Poetry.java b/integration-tests/netty/src/main/java/org/apache/camel/quarkus/component/netty/Poetry.java deleted file mode 100644 index 593347e..0000000 --- a/integration-tests/netty/src/main/java/org/apache/camel/quarkus/component/netty/Poetry.java +++ /dev/null @@ -1,56 +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. - */ -package org.apache.camel.quarkus.component.netty; - -import java.io.Serializable; - -public class Poetry implements Serializable { - private static final long serialVersionUID = 1L; - private String poet = "?"; - private String poem = "ONCE in the dream of a night I stood\n" - + "Lone in the light of a magical wood,\n" - + "Soul-deep in visions that poppy-like sprang;\n" - + "And spirits of Truth were the birds that sang,\n" - + "And spirits of Love were the stars that glowed,\n" - + "And spirits of Peace were the streams that flowed\n" - + "In that magical wood in the land of sleep." - + "\n" - + "Lone in the light of that magical grove,\n" - + "I felt the stars of the spirits of Love\n" - + "Gather and gleam round my delicate youth,\n" - + "And I heard the song of the spirits of Truth;\n" - + "To quench my longing I bent me low\n" - + "By the streams of the spirits of Peace that flow\n" - + "In that magical wood in the land of sleep."; - - public String getPoet() { - return poet; - } - - public void setPoet(String poet) { - this.poet = poet; - } - - public String getPoem() { - return poem; - } - - public void setPoem(String poem) { - this.poem = poem; - } - -} diff --git a/integration-tests/netty/src/test/java/org/apache/camel/quarkus/component/netty/NettyTest.java b/integration-tests/netty/src/test/java/org/apache/camel/quarkus/component/netty/NettyTest.java index 6f5eb6c..1012fff 100644 --- a/integration-tests/netty/src/test/java/org/apache/camel/quarkus/component/netty/NettyTest.java +++ b/integration-tests/netty/src/test/java/org/apache/camel/quarkus/component/netty/NettyTest.java @@ -16,29 +16,34 @@ */ package org.apache.camel.quarkus.component.netty; -import java.io.*; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.PrintWriter; import java.net.Socket; -import io.quarkus.test.junit.QuarkusTest; - import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; +import io.quarkus.test.common.QuarkusTestResource; +import io.quarkus.test.junit.QuarkusTest; + @QuarkusTest +@QuarkusTestResource(NettyTestResource.class) class NettyTest { + private static final String POEM = "Epitaph in Kohima, India marking the WWII Battle of Kohima and Imphal, Burma Campaign - Attributed to John Maxwell Edmonds"; + private static final String EXPECTED_RESPONSE = "When You Go Home, Tell Them Of Us And Say, For Your Tomorrow, We Gave Our Today."; @Test public void testPoem() throws IOException { - final String poem = "Epitaph in Kohima, India marking the WWII Battle of Kohima and Imphal, Burma Campaign - Attributed to John Maxwell Edmonds"; - final String expectedResponse = "When You Go Home, Tell Them Of Us And Say, For Your Tomorrow, We Gave Our Today."; try ( - final Socket socket = new Socket("localhost", 8994); + final Socket socket = new Socket("localhost", Integer.getInteger("camel.netty.test-port")); final PrintWriter outputWriter = new PrintWriter(socket.getOutputStream(), true); final BufferedReader inputReader = new BufferedReader(new InputStreamReader(socket.getInputStream()));) { - outputWriter.println(poem); + outputWriter.println(POEM); String response = inputReader.readLine(); - Assertions.assertTrue(response.equalsIgnoreCase(expectedResponse), "Response did not match expected response"); + Assertions.assertTrue(response.equalsIgnoreCase(EXPECTED_RESPONSE), "Response did not match expected response"); } } diff --git a/integration-tests/jdbc/src/test/java/org/apache/camel/quarkus/component/jdbc/TestResources.java b/integration-tests/netty/src/test/java/org/apache/camel/quarkus/component/netty/NettyTestResource.java similarity index 61% rename from integration-tests/jdbc/src/test/java/org/apache/camel/quarkus/component/jdbc/TestResources.java rename to integration-tests/netty/src/test/java/org/apache/camel/quarkus/component/netty/NettyTestResource.java index 55cfb12..79e8452 100644 --- a/integration-tests/jdbc/src/test/java/org/apache/camel/quarkus/component/jdbc/TestResources.java +++ b/integration-tests/netty/src/test/java/org/apache/camel/quarkus/component/netty/NettyTestResource.java @@ -14,11 +14,21 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.camel.quarkus.component.jdbc; +package org.apache.camel.quarkus.component.netty; -import io.quarkus.test.common.QuarkusTestResource; -import io.quarkus.test.h2.H2DatabaseTestResource; +import java.util.Map; +import java.util.Objects; -@QuarkusTestResource(H2DatabaseTestResource.class) -public class TestResources { +import io.quarkus.test.common.QuarkusTestResourceLifecycleManager; +import org.apache.camel.quarkus.test.AvailablePortFinder; + +public class NettyTestResource implements QuarkusTestResourceLifecycleManager { + @Override + public Map<String, String> start() { + return AvailablePortFinder.reserveNetworkPorts(Objects::toString, "camel.netty.test-port"); + } + + @Override + public void stop() { + } } diff --git a/integration-tests/paho/pom.xml b/integration-tests/paho/pom.xml index 22e85e5..51368d8 100644 --- a/integration-tests/paho/pom.xml +++ b/integration-tests/paho/pom.xml @@ -50,6 +50,15 @@ <artifactId>rest-assured</artifactId> <scope>test</scope> </dependency> + + <!-- test dependencies - camel-quarkus --> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-integration-test-support</artifactId> + <scope>test</scope> + </dependency> + + <!-- test dependencies - activemq --> <dependency> <groupId>org.apache.activemq</groupId> <artifactId>activemq-kahadb-store</artifactId> diff --git a/integration-tests/paho/src/test/java/org/apache/camel/quarkus/component/paho/it/ActiveMQTestResource.java b/integration-tests/paho/src/test/java/org/apache/camel/quarkus/component/paho/it/ActiveMQTestResource.java index 9eb9e8d..aded327 100644 --- a/integration-tests/paho/src/test/java/org/apache/camel/quarkus/component/paho/it/ActiveMQTestResource.java +++ b/integration-tests/paho/src/test/java/org/apache/camel/quarkus/component/paho/it/ActiveMQTestResource.java @@ -17,16 +17,23 @@ package org.apache.camel.quarkus.component.paho.it; +import java.io.File; +import java.io.IOException; import java.net.URI; +import java.nio.file.Files; +import java.nio.file.Path; import java.util.Collections; +import java.util.Comparator; import java.util.Map; -import io.quarkus.test.common.QuarkusTestResourceLifecycleManager; import org.apache.activemq.broker.BrokerService; import org.apache.activemq.broker.TransportConnector; +import org.apache.camel.quarkus.test.AvailablePortFinder; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import io.quarkus.test.common.QuarkusTestResourceLifecycleManager; + public class ActiveMQTestResource implements QuarkusTestResourceLifecycleManager { private static final Logger LOGGER = LoggerFactory.getLogger(ActiveMQTestResource.class); private BrokerService broker; @@ -34,17 +41,24 @@ public class ActiveMQTestResource implements QuarkusTestResourceLifecycleManager @Override public Map<String, String> start() { try { - broker = new BrokerService(); + final int port = AvailablePortFinder.getNextAvailable(); + final String transportUri = String.format("mqtt://127.0.0.1:%d", port); + final String brokerUri = String.format("tcp://127.0.0.1:%d", port); + final File dataDirectory = Files.createTempDirectory("paho-data-").toFile(); + TransportConnector mqtt = new TransportConnector(); - mqtt.setUri(new URI("mqtt://127.0.0.1:1883")); + mqtt.setUri(new URI(transportUri)); + + broker = new BrokerService(); broker.addConnector(mqtt); - broker.setDataDirectory("target"); + broker.setDataDirectoryFile(dataDirectory); broker.start(); + + return Collections.singletonMap("camel.component.paho.brokerUrl", brokerUri); } catch (Exception e) { LOGGER.error("Starting the ActiveMQ broker with exception.", e); throw new RuntimeException("Starting the ActiveMQ broker with exception.", e); } - return Collections.emptyMap(); } @Override @@ -55,7 +69,17 @@ public class ActiveMQTestResource implements QuarkusTestResourceLifecycleManager } } catch (Exception e) { LOGGER.error("Stopping the ActiveMQ broker with exception.", e); - throw new RuntimeException("Stopping the ActiveMQ broker with exception.", e); + } + + try { + if (broker != null) { + Files.walk(broker.getDataDirectoryFile().toPath()) + .sorted(Comparator.reverseOrder()) + .map(Path::toFile) + .forEach(File::delete); + } + } catch (IOException e) { + LOGGER.error("Error cleaning up ActiveMQ data directory", e); } } } diff --git a/integration-tests/pom.xml b/integration-tests/pom.xml index b8223d0..5c09179 100644 --- a/integration-tests/pom.xml +++ b/integration-tests/pom.xml @@ -57,6 +57,11 @@ <artifactId>camel-quarkus-integration-test-support-core-main-ext</artifactId> <version>${project.version}</version> </dependency> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-integration-test-support</artifactId> + <version>${project.version}</version> + </dependency> <dependency> diff --git a/integration-tests/sjms/.gitignore b/integration-tests/sjms/.gitignore new file mode 100644 index 0000000..adbb97d --- /dev/null +++ b/integration-tests/sjms/.gitignore @@ -0,0 +1 @@ +data/ \ No newline at end of file diff --git a/integration-tests/sjms/pom.xml b/integration-tests/sjms/pom.xml index d01e22d..c573403 100644 --- a/integration-tests/sjms/pom.xml +++ b/integration-tests/sjms/pom.xml @@ -67,6 +67,20 @@ <scope>test</scope> </dependency> <dependency> + <groupId>org.assertj</groupId> + <artifactId>assertj-core</artifactId> + <scope>test</scope> + </dependency> + + <!-- test dependencies - camel-quarkus --> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-integration-test-support</artifactId> + <scope>test</scope> + </dependency> + + <!-- test dependencies - activemq --> + <dependency> <groupId>org.apache.activemq</groupId> <artifactId>artemis-server</artifactId> <scope>test</scope> @@ -86,11 +100,6 @@ <artifactId>commons-logging-jboss-logging</artifactId> <scope>test</scope> </dependency> - <dependency> - <groupId>org.assertj</groupId> - <artifactId>assertj-core</artifactId> - <scope>test</scope> - </dependency> </dependencies> <build> diff --git a/integration-tests/sjms/src/main/resources/application.properties b/integration-tests/sjms/src/main/resources/application.properties index 9df1630..be0a82f 100644 --- a/integration-tests/sjms/src/main/resources/application.properties +++ b/integration-tests/sjms/src/main/resources/application.properties @@ -22,8 +22,3 @@ quarkus.log.file.enable = false quarkus.log.category."org.apache.camel.quarkus.core.deployment".level = INFO quarkus.log.category."org.apache.camel.quarkus.component.sjms".level = DEBUG quarkus.log.category."org.apache.activemq.artemis".level = WARN - -# -# Quarkus - Artemis -# -quarkus.artemis.url = tcp://localhost:61616 \ No newline at end of file diff --git a/integration-tests/sjms/src/test/java/org/apache/camel/quarkus/component/sjms/it/CamelSjmsTest.java b/integration-tests/sjms/src/test/java/org/apache/camel/quarkus/component/sjms/it/CamelSjmsTest.java index 17c6da2..62b184c 100644 --- a/integration-tests/sjms/src/test/java/org/apache/camel/quarkus/component/sjms/it/CamelSjmsTest.java +++ b/integration-tests/sjms/src/test/java/org/apache/camel/quarkus/component/sjms/it/CamelSjmsTest.java @@ -18,17 +18,23 @@ package org.apache.camel.quarkus.component.sjms.it; import java.util.UUID; +import javax.inject.Inject; + import io.quarkus.test.common.QuarkusTestResource; import io.quarkus.test.junit.QuarkusTest; import io.restassured.RestAssured; import io.restassured.path.json.JsonPath; +import org.apache.camel.quarkus.core.CamelMain; import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; @QuarkusTest -@QuarkusTestResource(ArtemisTestResource.class) +@QuarkusTestResource(CamelSjmsTestResource.class) public class CamelSjmsTest { + @Inject + CamelMain main; + @Test void testQueueBridge() { String body = UUID.randomUUID().toString(); diff --git a/integration-tests/sjms/src/test/java/org/apache/camel/quarkus/component/sjms/it/ArtemisTestResource.java b/integration-tests/sjms/src/test/java/org/apache/camel/quarkus/component/sjms/it/CamelSjmsTestResource.java similarity index 59% rename from integration-tests/sjms/src/test/java/org/apache/camel/quarkus/component/sjms/it/ArtemisTestResource.java rename to integration-tests/sjms/src/test/java/org/apache/camel/quarkus/component/sjms/it/CamelSjmsTestResource.java index 17e1ecf..6338287 100644 --- a/integration-tests/sjms/src/test/java/org/apache/camel/quarkus/component/sjms/it/ArtemisTestResource.java +++ b/integration-tests/sjms/src/test/java/org/apache/camel/quarkus/component/sjms/it/CamelSjmsTestResource.java @@ -20,31 +20,59 @@ import java.nio.file.Paths; import java.util.Collections; import java.util.Map; +import io.quarkus.test.common.QuarkusTestResourceLifecycleManager; +import org.apache.activemq.artemis.core.config.impl.ConfigurationImpl; import org.apache.activemq.artemis.core.server.embedded.EmbeddedActiveMQ; +import org.apache.camel.quarkus.core.CamelMain; +import org.apache.camel.quarkus.test.AvailablePortFinder; import org.apache.commons.io.FileUtils; -import io.quarkus.test.common.QuarkusTestResourceLifecycleManager; - -public class ArtemisTestResource implements QuarkusTestResourceLifecycleManager { - +public class CamelSjmsTestResource implements QuarkusTestResourceLifecycleManager { + private CamelMain main; private EmbeddedActiveMQ embedded; @Override + public void inject(Object testInstance) { + if (testInstance instanceof CamelSjmsTest) { + this.main = ((CamelSjmsTest) testInstance).main; + } + } + + @Override public Map<String, String> start() { try { FileUtils.deleteDirectory(Paths.get("./target/artemis").toFile()); + + final int port = AvailablePortFinder.getNextAvailable(); + final String url = String.format("tcp://127.0.0.1:%d", port); + + ConfigurationImpl cfg = new ConfigurationImpl(); + cfg.addAcceptorConfiguration("activemq", url); + cfg.setSecurityEnabled(false); + embedded = new EmbeddedActiveMQ(); + embedded.setConfiguration(cfg); embedded.start(); + + return Collections.singletonMap("quarkus.artemis.url", url); } catch (Exception e) { throw new RuntimeException("Could not start embedded ActiveMQ server", e); } - return Collections.emptyMap(); } @Override public void stop() { try { - embedded.stop(); + if (main != null) { + main.stop(); + } + } catch (Exception e) { + // ignored + } + try { + if (embedded != null) { + embedded.stop(); + } } catch (Exception e) { throw new RuntimeException("Could not stop embedded ActiveMQ server", e); } diff --git a/integration-tests/support/core-main/pom.xml b/integration-tests/support/core-main/pom.xml index 423980f..426399e 100644 --- a/integration-tests/support/core-main/pom.xml +++ b/integration-tests/support/core-main/pom.xml @@ -21,8 +21,8 @@ <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.apache.camel.quarkus</groupId> - <artifactId>camel-quarkus-integration-tests-support</artifactId> <version>1.0.0-SNAPSHOT</version> + <artifactId>camel-quarkus-integration-tests-support-parent</artifactId> <relativePath>../pom.xml</relativePath> </parent> diff --git a/integration-tests/support/core/pom.xml b/integration-tests/support/core/pom.xml index a7bf042..f3c7d03 100644 --- a/integration-tests/support/core/pom.xml +++ b/integration-tests/support/core/pom.xml @@ -21,7 +21,7 @@ <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.apache.camel.quarkus</groupId> - <artifactId>camel-quarkus-integration-tests-support</artifactId> + <artifactId>camel-quarkus-integration-tests-support-parent</artifactId> <version>1.0.0-SNAPSHOT</version> <relativePath>../pom.xml</relativePath> </parent> diff --git a/integration-tests/support/pom.xml b/integration-tests/support/pom.xml index a22d218..3ae6b54 100644 --- a/integration-tests/support/pom.xml +++ b/integration-tests/support/pom.xml @@ -27,15 +27,16 @@ <relativePath>../pom.xml</relativePath> </parent> - <artifactId>camel-quarkus-integration-tests-support</artifactId> + <artifactId>camel-quarkus-integration-tests-support-parent</artifactId> <packaging>pom</packaging> - <name>Camel Quarkus :: Integration Tests :: Support</name> + <name>Camel Quarkus :: Integration Tests :: Support :: Parent</name> <description>Ancillary modules required by some integration tests. Hosted outside the integration-tests directory so that we can keep a flat hierarchy in the integration-tests directory. </description> <modules> + <module>test-support</module> <module>core</module> <module>core-main</module> </modules> diff --git a/integration-tests/support/pom.xml b/integration-tests/support/test-support/pom.xml similarity index 73% copy from integration-tests/support/pom.xml copy to integration-tests/support/test-support/pom.xml index a22d218..b903053 100644 --- a/integration-tests/support/pom.xml +++ b/integration-tests/support/test-support/pom.xml @@ -18,26 +18,25 @@ --> <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-integration-tests</artifactId> + <artifactId>camel-quarkus-integration-tests-support-parent</artifactId> <version>1.0.0-SNAPSHOT</version> <relativePath>../pom.xml</relativePath> </parent> + <modelVersion>4.0.0</modelVersion> - <artifactId>camel-quarkus-integration-tests-support</artifactId> - <packaging>pom</packaging> - + <artifactId>camel-quarkus-integration-test-support</artifactId> <name>Camel Quarkus :: Integration Tests :: Support</name> - <description>Ancillary modules required by some integration tests. Hosted outside the integration-tests directory - so that we can keep a flat hierarchy in the integration-tests directory. - </description> - - <modules> - <module>core</module> - <module>core-main</module> - </modules> + <dependencies> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-api</artifactId> + </dependency> + <dependency> + <groupId>io.quarkus</groupId> + <artifactId>quarkus-junit5</artifactId> + </dependency> + </dependencies> </project> diff --git a/integration-tests/support/test-support/src/main/java/org/apache/camel/quarkus/test/AvailablePortFinder.java b/integration-tests/support/test-support/src/main/java/org/apache/camel/quarkus/test/AvailablePortFinder.java new file mode 100644 index 0000000..6400871 --- /dev/null +++ b/integration-tests/support/test-support/src/main/java/org/apache/camel/quarkus/test/AvailablePortFinder.java @@ -0,0 +1,83 @@ +/* + * 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.test; + +import java.io.IOException; +import java.net.InetAddress; +import java.net.InetSocketAddress; +import java.net.ServerSocket; +import java.util.HashMap; +import java.util.Map; +import java.util.function.Function; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Finds currently available server ports. + */ +public final class AvailablePortFinder { + private static final Logger LOGGER = LoggerFactory.getLogger(AvailablePortFinder.class); + + /** + * Creates a new instance. + */ + private AvailablePortFinder() { + // Do nothing + } + + /** + * Gets the next available port. + * + * @throws IllegalStateException if there are no ports available + * @return the available port + */ + public static int getNextAvailable() { + try (ServerSocket ss = new ServerSocket()) { + ss.setReuseAddress(true); + ss.bind(new InetSocketAddress((InetAddress) null, 0), 1); + + int port = ss.getLocalPort(); + + LOGGER.info("getNextAvailable() -> {}", port); + + return port; + } catch (IOException e) { + throw new IllegalStateException("Cannot find free port", e); + } + } + + /** + * Reserve a list of random and not in use network ports and place them in Map. + */ + public static Map<String, Integer> reserveNetworkPorts(String... names) { + return reserveNetworkPorts(Function.identity(), names); + } + + /** + * Reserve a list of random and not in use network ports and place them in Map. + */ + public static <T> Map<String, T> reserveNetworkPorts(Function<Integer, T> converter, String... names) { + Map<String, T> reservedPorts = new HashMap<>(); + + for (String name : names) { + reservedPorts.put(name, converter.apply(getNextAvailable())); + } + + return reservedPorts; + } +} diff --git a/pom.xml b/pom.xml index 2eb5715..8a2ef1f 100644 --- a/pom.xml +++ b/pom.xml @@ -73,6 +73,7 @@ <maven-source-plugin.version>3.1.0</maven-source-plugin.version> <maven-assembly-plugin.version>3.1.1</maven-assembly-plugin.version> <maven-dependency-plugin.version>3.1.1</maven-dependency-plugin.version> + <maven-surefire-plugin.version>3.0.0-M4</maven-surefire-plugin.version> <!-- maven-release-plugin --> <tagNameFormat>@{project.version}</tagNameFormat> @@ -234,6 +235,7 @@ <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> + <version>${maven-surefire-plugin.version}</version> <configuration> <failIfNoTests>false</failIfNoTests> <systemProperties> @@ -243,6 +245,12 @@ </plugin> <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-failsafe-plugin</artifactId> + <version>${maven-surefire-plugin.version}</version> + </plugin> + + <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>exec-maven-plugin</artifactId> <version>${exec-maven-plugin.version}</version>