This is an automated email from the ASF dual-hosted git repository.
orpiske pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/master by this push:
new 8adbb77 Migrates camel-nsq to the new test infra (#4710)
8adbb77 is described below
commit 8adbb7723e0f2351cbc3b2830222ac43b0f05da2
Author: Otavio Rodolfo Piske <[email protected]>
AuthorDate: Wed Dec 2 12:35:30 2020 +0100
Migrates camel-nsq to the new test infra (#4710)
---
components/camel-nsq/pom.xml | 20 +++-
.../apache/camel/component/nsq/NsqTestSupport.java | 50 ++--------
test-infra/camel-test-infra-nsq/pom.xml | 60 ++++++++++++
.../src/main/resources/META-INF/MANIFEST.MF | 0
.../camel/test/infra/nsq/common/NsqProperties.java | 27 ++++++
.../nsq/services/NsqLocalContainerService.java | 102 +++++++++++++++++++++
.../test/infra/nsq/services/NsqRemoteService.java | 47 ++++++++++
.../camel/test/infra/nsq/services/NsqService.java | 41 +++++++++
.../test/infra/nsq/services/NsqServiceFactory.java | 43 +++++++++
test-infra/pom.xml | 1 +
10 files changed, 346 insertions(+), 45 deletions(-)
diff --git a/components/camel-nsq/pom.xml b/components/camel-nsq/pom.xml
index 70e8289..a48a01f 100644
--- a/components/camel-nsq/pom.xml
+++ b/components/camel-nsq/pom.xml
@@ -49,15 +49,27 @@
<artifactId>camel-test-junit5</artifactId>
<scope>test</scope>
</dependency>
+ <!-- logging -->
+ <dependency>
+ <groupId>org.apache.logging.log4j</groupId>
+ <artifactId>log4j-slf4j-impl</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <!-- test infra -->
<dependency>
<groupId>org.apache.camel</groupId>
- <artifactId>camel-testcontainers-junit5</artifactId>
+ <artifactId>camel-test-infra-common</artifactId>
+ <version>${project.version}</version>
+ <type>test-jar</type>
<scope>test</scope>
</dependency>
- <!-- logging -->
+
<dependency>
- <groupId>org.apache.logging.log4j</groupId>
- <artifactId>log4j-slf4j-impl</artifactId>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-test-infra-nsq</artifactId>
+ <version>${project.version}</version>
+ <type>test-jar</type>
<scope>test</scope>
</dependency>
</dependencies>
diff --git
a/components/camel-nsq/src/test/java/org/apache/camel/component/nsq/NsqTestSupport.java
b/components/camel-nsq/src/test/java/org/apache/camel/component/nsq/NsqTestSupport.java
index 0fc8c69..0dca974 100644
---
a/components/camel-nsq/src/test/java/org/apache/camel/component/nsq/NsqTestSupport.java
+++
b/components/camel-nsq/src/test/java/org/apache/camel/component/nsq/NsqTestSupport.java
@@ -16,52 +16,20 @@
*/
package org.apache.camel.component.nsq;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
+import org.apache.camel.test.infra.nsq.services.NsqService;
+import org.apache.camel.test.infra.nsq.services.NsqServiceFactory;
+import org.apache.camel.test.junit5.CamelTestSupport;
+import org.junit.jupiter.api.extension.RegisterExtension;
-import org.apache.camel.test.testcontainers.junit5.ContainerAwareTestSupport;
-import org.apache.camel.test.testcontainers.junit5.Wait;
-import org.testcontainers.containers.FixedHostPortGenericContainer;
-import org.testcontainers.containers.GenericContainer;
-import org.testcontainers.containers.Network;
-
-public class NsqTestSupport extends ContainerAwareTestSupport {
-
- public static final String CONTAINER_NSQLOOKUPD_IMAGE = "nsqio/nsq:v1.2.0";
- public static final String CONTAINER_NSQLOOKUPD_NAME = "nsqlookupd";
-
- public static final String CONTAINER_NSQD_IMAGE = "nsqio/nsq:v1.2.0";
- public static final String CONTAINER_NSQD_NAME = "nsqd";
-
- Network network;
-
- @Override
- protected List<GenericContainer<?>> createContainers() {
- network = Network.newNetwork();
- return new ArrayList<>(Arrays.asList(nsqlookupdContainer(network),
nsqdContainer(network)));
- }
-
- public static GenericContainer<?> nsqlookupdContainer(Network network) {
- return new
FixedHostPortGenericContainer<>(CONTAINER_NSQLOOKUPD_IMAGE).withFixedExposedPort(4160,
4160)
- .withFixedExposedPort(4161, 4161)
-
.withNetworkAliases(CONTAINER_NSQLOOKUPD_NAME).withCommand("/nsqlookupd").withNetwork(network)
- .waitingFor(Wait.forLogMessageContaining("TCP: listening on",
1));
- }
-
- public static GenericContainer<?> nsqdContainer(Network network) {
- return new
FixedHostPortGenericContainer<>(CONTAINER_NSQD_IMAGE).withFixedExposedPort(4150,
4150)
- .withFixedExposedPort(4151,
4151).withNetworkAliases(CONTAINER_NSQD_NAME)
- .withCommand(String.format("/nsqd --broadcast-address=%s
--lookupd-tcp-address=%s:4160", "localhost",
- CONTAINER_NSQLOOKUPD_NAME))
-
.withNetwork(network).waitingFor(Wait.forLogMessageContaining("TCP: listening
on", 1));
- }
+public class NsqTestSupport extends CamelTestSupport {
+ @RegisterExtension
+ static NsqService service = NsqServiceFactory.createService();
public String getNsqConsumerUrl() {
- return String.format("%s:%d", "localhost", 4161);
+ return service.getNsqConsumerUrl();
}
public String getNsqProducerUrl() {
- return String.format("%s:%d", "localhost", 4150);
+ return service.getNsqProducerUrl();
}
}
diff --git a/test-infra/camel-test-infra-nsq/pom.xml
b/test-infra/camel-test-infra-nsq/pom.xml
new file mode 100644
index 0000000..b98d43e
--- /dev/null
+++ b/test-infra/camel-test-infra-nsq/pom.xml
@@ -0,0 +1,60 @@
+<?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">
+ <parent>
+ <artifactId>camel-test-infra-parent</artifactId>
+ <groupId>org.apache.camel</groupId>
+ <relativePath>../camel-test-infra-parent/pom.xml</relativePath>
+ <version>3.7.0-SNAPSHOT</version>
+ </parent>
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <artifactId>camel-test-infra-nsq</artifactId>
+ <name>Camel :: Test Infra :: Nsq</name>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-test-infra-common</artifactId>
+ <version>${project.version}</version>
+ <type>test-jar</type>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.testcontainers</groupId>
+ <artifactId>testcontainers</artifactId>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-jar-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </build>
+
+
+</project>
\ No newline at end of file
diff --git
a/test-infra/camel-test-infra-nsq/src/main/resources/META-INF/MANIFEST.MF
b/test-infra/camel-test-infra-nsq/src/main/resources/META-INF/MANIFEST.MF
new file mode 100644
index 0000000..e69de29
diff --git
a/test-infra/camel-test-infra-nsq/src/test/java/org/apache/camel/test/infra/nsq/common/NsqProperties.java
b/test-infra/camel-test-infra-nsq/src/test/java/org/apache/camel/test/infra/nsq/common/NsqProperties.java
new file mode 100644
index 0000000..724d12a
--- /dev/null
+++
b/test-infra/camel-test-infra-nsq/src/test/java/org/apache/camel/test/infra/nsq/common/NsqProperties.java
@@ -0,0 +1,27 @@
+/*
+ * 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.test.infra.nsq.common;
+
+public final class NsqProperties {
+ public static final String PRODUCER_URL = "nsq.producer.url";
+ public static final String CONSUMER_URL = "nsq.consumer.url";
+
+ private NsqProperties() {
+
+ }
+}
diff --git
a/test-infra/camel-test-infra-nsq/src/test/java/org/apache/camel/test/infra/nsq/services/NsqLocalContainerService.java
b/test-infra/camel-test-infra-nsq/src/test/java/org/apache/camel/test/infra/nsq/services/NsqLocalContainerService.java
new file mode 100644
index 0000000..e4ceb75
--- /dev/null
+++
b/test-infra/camel-test-infra-nsq/src/test/java/org/apache/camel/test/infra/nsq/services/NsqLocalContainerService.java
@@ -0,0 +1,102 @@
+/*
+ * 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.test.infra.nsq.services;
+
+import org.apache.camel.test.infra.common.services.ContainerService;
+import org.apache.camel.test.infra.nsq.common.NsqProperties;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.testcontainers.containers.FixedHostPortGenericContainer;
+import org.testcontainers.containers.GenericContainer;
+import org.testcontainers.containers.Network;
+import org.testcontainers.containers.wait.strategy.Wait;
+
+public class NsqLocalContainerService implements NsqService,
ContainerService<GenericContainer> {
+ protected static final String CONTAINER_NSQLOOKUPD_IMAGE =
"nsqio/nsq:v1.2.0";
+ protected static final String CONTAINER_NSQLOOKUPD_NAME = "nsqlookupd";
+
+ protected static final String CONTAINER_NSQD_IMAGE = "nsqio/nsq:v1.2.0";
+ protected static final String CONTAINER_NSQD_NAME = "nsqd";
+
+ private static final Logger LOG =
LoggerFactory.getLogger(NsqLocalContainerService.class);
+
+ private GenericContainer nsqContainer;
+ private GenericContainer nsqLookupContainer;
+ private Network network = Network.newNetwork();
+
+ public NsqLocalContainerService() {
+ initContainers();
+ }
+
+ protected void initContainers() {
+ nsqLookupContainer = new
FixedHostPortGenericContainer<>(CONTAINER_NSQLOOKUPD_IMAGE)
+ .withFixedExposedPort(4160, 4160)
+ .withFixedExposedPort(4161, 4161)
+ .withNetworkAliases(CONTAINER_NSQLOOKUPD_NAME)
+ .withCommand("/nsqlookupd").withNetwork(network)
+ .waitingFor(Wait.forLogMessage(".*TCP: listening on.*", 1));
+
+ nsqContainer = new
FixedHostPortGenericContainer<>(CONTAINER_NSQD_IMAGE)
+ .withFixedExposedPort(4150, 4150)
+ .withFixedExposedPort(4151, 4151)
+ .withNetworkAliases(CONTAINER_NSQD_NAME)
+ .withCommand(String.format("/nsqd --broadcast-address=%s
--lookupd-tcp-address=%s:4160", "localhost",
+ CONTAINER_NSQLOOKUPD_NAME))
+ .withNetwork(network)
+ .waitingFor(Wait.forLogMessage(".*TCP: listening on.*", 1));
+ }
+
+ @Override
+ public void registerProperties() {
+ System.getProperty(NsqProperties.PRODUCER_URL, getNsqProducerUrl());
+ System.getProperty(NsqProperties.CONSUMER_URL, getNsqConsumerUrl());
+ }
+
+ @Override
+ public void initialize() {
+ LOG.info("Trying to start the Nsq container");
+ nsqLookupContainer.start();
+ nsqContainer.start();
+
+ registerProperties();
+
+ LOG.info("Nsq producer accessible via {}", getNsqProducerUrl());
+ LOG.info("Nsq consumer accessible via {}", getNsqConsumerUrl());
+ }
+
+ @Override
+ public void shutdown() {
+ LOG.info("Stopping the Nsq container");
+ nsqContainer.stop();
+ nsqLookupContainer.stop();
+ }
+
+ @Override
+ public GenericContainer getContainer() {
+ return nsqContainer;
+ }
+
+ @Override
+ public String getNsqProducerUrl() {
+ return String.format("%s:%d", nsqContainer.getHost(),
nsqContainer.getMappedPort(4150));
+ }
+
+ @Override
+ public String getNsqConsumerUrl() {
+ return String.format("%s:%d", nsqLookupContainer.getHost(),
nsqLookupContainer.getMappedPort(4161));
+ }
+}
diff --git
a/test-infra/camel-test-infra-nsq/src/test/java/org/apache/camel/test/infra/nsq/services/NsqRemoteService.java
b/test-infra/camel-test-infra-nsq/src/test/java/org/apache/camel/test/infra/nsq/services/NsqRemoteService.java
new file mode 100644
index 0000000..611b452
--- /dev/null
+++
b/test-infra/camel-test-infra-nsq/src/test/java/org/apache/camel/test/infra/nsq/services/NsqRemoteService.java
@@ -0,0 +1,47 @@
+/*
+ * 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.test.infra.nsq.services;
+
+import org.apache.camel.test.infra.nsq.common.NsqProperties;
+
+public class NsqRemoteService implements NsqService {
+
+ @Override
+ public void registerProperties() {
+ // NO-OP
+ }
+
+ @Override
+ public void initialize() {
+ registerProperties();
+ }
+
+ @Override
+ public void shutdown() {
+ // NO-OP
+ }
+
+ @Override
+ public String getNsqProducerUrl() {
+ return System.getProperty(NsqProperties.PRODUCER_URL);
+ }
+
+ @Override
+ public String getNsqConsumerUrl() {
+ return System.getProperty(NsqProperties.CONSUMER_URL);
+ }
+}
diff --git
a/test-infra/camel-test-infra-nsq/src/test/java/org/apache/camel/test/infra/nsq/services/NsqService.java
b/test-infra/camel-test-infra-nsq/src/test/java/org/apache/camel/test/infra/nsq/services/NsqService.java
new file mode 100644
index 0000000..38c2770
--- /dev/null
+++
b/test-infra/camel-test-infra-nsq/src/test/java/org/apache/camel/test/infra/nsq/services/NsqService.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.test.infra.nsq.services;
+
+import org.apache.camel.test.infra.common.services.TestService;
+import org.junit.jupiter.api.extension.AfterAllCallback;
+import org.junit.jupiter.api.extension.BeforeAllCallback;
+import org.junit.jupiter.api.extension.ExtensionContext;
+
+/**
+ * Test infra service for Nsq
+ */
+public interface NsqService extends BeforeAllCallback, AfterAllCallback,
TestService {
+ String getNsqProducerUrl();
+
+ String getNsqConsumerUrl();
+
+ @Override
+ default void beforeAll(ExtensionContext extensionContext) throws Exception
{
+ initialize();
+ }
+
+ @Override
+ default void afterAll(ExtensionContext extensionContext) throws Exception {
+ shutdown();
+ }
+}
diff --git
a/test-infra/camel-test-infra-nsq/src/test/java/org/apache/camel/test/infra/nsq/services/NsqServiceFactory.java
b/test-infra/camel-test-infra-nsq/src/test/java/org/apache/camel/test/infra/nsq/services/NsqServiceFactory.java
new file mode 100644
index 0000000..f163190
--- /dev/null
+++
b/test-infra/camel-test-infra-nsq/src/test/java/org/apache/camel/test/infra/nsq/services/NsqServiceFactory.java
@@ -0,0 +1,43 @@
+/*
+ * 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.test.infra.nsq.services;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public final class NsqServiceFactory {
+ private static final Logger LOG =
LoggerFactory.getLogger(NsqServiceFactory.class);
+
+ private NsqServiceFactory() {
+
+ }
+
+ public static NsqService createService() {
+ String instanceType = System.getProperty("nsq.instance.type");
+
+ if (instanceType == null ||
instanceType.equals("local-nsq-container")) {
+ return new NsqLocalContainerService();
+ }
+
+ if (instanceType.equals("remote")) {
+ return new NsqRemoteService();
+ }
+
+ LOG.error("Nsq instance must be one of 'local-nsq-container' or
'remote");
+ throw new UnsupportedOperationException("Invalid Nsq instance type");
+ }
+}
diff --git a/test-infra/pom.xml b/test-infra/pom.xml
index 7d96ca6..81b5f83 100644
--- a/test-infra/pom.xml
+++ b/test-infra/pom.xml
@@ -60,5 +60,6 @@
<module>camel-test-infra-infinispan</module>
<module>camel-test-infra-minio</module>
<module>camel-test-infra-nats</module>
+ <module>camel-test-infra-nsq</module>
</modules>
</project>