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 4e53f5b Migrates camel-pulsar to the new test infra (#4715) 4e53f5b is described below commit 4e53f5bda9c536cc7b1f03ca2f5102caa38f196f Author: Otavio Rodolfo Piske <orpi...@users.noreply.github.com> AuthorDate: Thu Dec 3 13:08:36 2020 +0100 Migrates camel-pulsar to the new test infra (#4715) --- components/camel-pulsar/pom.xml | 22 ++++-- .../pulsar/PulsarConsumerAcknowledgementTest.java | 36 ++++++++-- .../pulsar/PulsarConsumerDeadLetterPolicyTest.java | 19 ++++- .../pulsar/PulsarConsumerReadCompactedTest.java | 21 ++++-- .../camel/component/pulsar/PulsarTestSupport.java | 45 +++--------- parent/pom.xml | 5 ++ test-infra/camel-test-infra-pulsar/pom.xml | 65 +++++++++++++++++ .../src/main/resources/META-INF/MANIFEST.MF | 0 .../test/infra/pulsar/common/PulsarProperties.java | 27 +++++++ .../services/PulsarLocalContainerService.java | 83 ++++++++++++++++++++++ .../infra/pulsar/services/PulsarRemoteService.java | 47 ++++++++++++ .../test/infra/pulsar/services/PulsarService.java | 42 +++++++++++ .../pulsar/services/PulsarServiceFactory.java | 43 +++++++++++ test-infra/pom.xml | 1 + 14 files changed, 402 insertions(+), 54 deletions(-) diff --git a/components/camel-pulsar/pom.xml b/components/camel-pulsar/pom.xml index 1844f00..849efc4 100644 --- a/components/camel-pulsar/pom.xml +++ b/components/camel-pulsar/pom.xml @@ -55,11 +55,6 @@ <scope>test</scope> </dependency> <dependency> - <groupId>org.apache.camel</groupId> - <artifactId>camel-testcontainers-junit5</artifactId> - <scope>test</scope> - </dependency> - <dependency> <groupId>org.mockito</groupId> <artifactId>mockito-junit-jupiter</artifactId> <scope>test</scope> @@ -70,6 +65,23 @@ <scope>test</scope> </dependency> + <!-- test infra --> + <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.apache.camel</groupId> + <artifactId>camel-test-infra-pulsar</artifactId> + <version>${project.version}</version> + <type>test-jar</type> + <scope>test</scope> + </dependency> + <!-- logging --> <dependency> <groupId>org.apache.logging.log4j</groupId> diff --git a/components/camel-pulsar/src/test/java/org/apache/camel/component/pulsar/PulsarConsumerAcknowledgementTest.java b/components/camel-pulsar/src/test/java/org/apache/camel/component/pulsar/PulsarConsumerAcknowledgementTest.java index 7c7d5c0..3019e8c 100644 --- a/components/camel-pulsar/src/test/java/org/apache/camel/component/pulsar/PulsarConsumerAcknowledgementTest.java +++ b/components/camel-pulsar/src/test/java/org/apache/camel/component/pulsar/PulsarConsumerAcknowledgementTest.java @@ -27,24 +27,31 @@ import org.apache.camel.component.pulsar.utils.AutoConfiguration; import org.apache.camel.component.pulsar.utils.message.PulsarMessageHeaders; import org.apache.camel.spi.Registry; import org.apache.camel.support.SimpleRegistry; +import org.apache.camel.test.infra.common.TestUtils; +import org.apache.camel.test.infra.pulsar.services.PulsarService; +import org.apache.camel.test.infra.pulsar.services.PulsarServiceFactory; +import org.apache.camel.test.junit5.CamelTestSupport; import org.apache.pulsar.client.api.Producer; import org.apache.pulsar.client.api.PulsarClient; import org.apache.pulsar.client.api.PulsarClientException; import org.apache.pulsar.client.api.Schema; import org.apache.pulsar.client.impl.ClientBuilderImpl; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import static org.apache.camel.test.junit5.TestSupport.body; -public class PulsarConsumerAcknowledgementTest extends PulsarTestSupport { +public class PulsarConsumerAcknowledgementTest extends CamelTestSupport { - private static final Logger LOGGER = LoggerFactory.getLogger(PulsarConsumerAcknowledgementTest.class); + @RegisterExtension + static PulsarService service = PulsarServiceFactory.createService(); - private static final String TOPIC_URI = "persistent://public/default/camel-topic"; - private static final String PRODUCER = "camel-producer-1"; + private static final Logger LOGGER = LoggerFactory.getLogger(PulsarConsumerAcknowledgementTest.class); + private static final String TOPIC_URI = "persistent://public/default/camel-topic-1"; @EndpointInject("pulsar:" + TOPIC_URI + "?numberOfConsumers=1&subscriptionType=Exclusive" + "&subscriptionName=camel-subscription&consumerQueueSize=1&consumerName=camel-consumer" @@ -57,10 +64,29 @@ public class PulsarConsumerAcknowledgementTest extends PulsarTestSupport { private Producer<String> producer; + public String getPulsarBrokerUrl() { + return service.getPulsarBrokerUrl(); + } + + public String getPulsarAdminUrl() { + return service.getPulsarAdminUrl(); + } + @BeforeEach public void setup() throws Exception { context.removeRoute("myRoute"); - producer = givenPulsarClient().newProducer(Schema.STRING).producerName(PRODUCER).topic(TOPIC_URI).create(); + String producerName = this.getClass().getSimpleName() + TestUtils.randomWithRange(1, 100); + + producer = givenPulsarClient().newProducer(Schema.STRING).producerName(producerName).topic(TOPIC_URI).create(); + } + + @AfterEach + public void tearDownProducer() { + try { + producer.close(); + } catch (PulsarClientException e) { + LOGGER.warn("Failed to close client: {}", e.getMessage(), e); + } } @Override diff --git a/components/camel-pulsar/src/test/java/org/apache/camel/component/pulsar/PulsarConsumerDeadLetterPolicyTest.java b/components/camel-pulsar/src/test/java/org/apache/camel/component/pulsar/PulsarConsumerDeadLetterPolicyTest.java index 0d2d896..a5a7ad7 100644 --- a/components/camel-pulsar/src/test/java/org/apache/camel/component/pulsar/PulsarConsumerDeadLetterPolicyTest.java +++ b/components/camel-pulsar/src/test/java/org/apache/camel/component/pulsar/PulsarConsumerDeadLetterPolicyTest.java @@ -25,20 +25,23 @@ import org.apache.camel.component.pulsar.utils.AutoConfiguration; import org.apache.camel.component.pulsar.utils.message.PulsarMessageHeaders; import org.apache.camel.spi.Registry; import org.apache.camel.support.SimpleRegistry; +import org.apache.camel.test.infra.common.TestUtils; import org.apache.pulsar.client.api.Producer; import org.apache.pulsar.client.api.PulsarClient; import org.apache.pulsar.client.api.PulsarClientException; import org.apache.pulsar.client.api.Schema; import org.apache.pulsar.client.impl.ClientBuilderImpl; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import static org.junit.jupiter.api.Assertions.assertNull; public class PulsarConsumerDeadLetterPolicyTest extends PulsarTestSupport { - + private static final Logger LOGGER = LoggerFactory.getLogger(PulsarConsumerDeadLetterPolicyTest.class); private static final String TOPIC_URI = "persistent://public/default/camel-topic"; - private static final String PRODUCER = "camel-producer-1"; @EndpointInject("mock:result") private MockEndpoint to; @@ -76,8 +79,18 @@ public class PulsarConsumerDeadLetterPolicyTest extends PulsarTestSupport { } catch (Exception ignored) { } - producer = givenPulsarClient().newProducer(Schema.STRING).producerName(PRODUCER).topic(TOPIC_URI).create(); + String producerName = this.getClass().getSimpleName() + TestUtils.randomWithRange(1, 100); + + producer = givenPulsarClient().newProducer(Schema.STRING).producerName(producerName).topic(TOPIC_URI).create(); + } + @AfterEach + public void tearDownProducer() { + try { + producer.close(); + } catch (PulsarClientException e) { + LOGGER.warn("Failed to close client: {}", e.getMessage(), e); + } } @Test diff --git a/components/camel-pulsar/src/test/java/org/apache/camel/component/pulsar/PulsarConsumerReadCompactedTest.java b/components/camel-pulsar/src/test/java/org/apache/camel/component/pulsar/PulsarConsumerReadCompactedTest.java index 39be95e..a219724 100644 --- a/components/camel-pulsar/src/test/java/org/apache/camel/component/pulsar/PulsarConsumerReadCompactedTest.java +++ b/components/camel-pulsar/src/test/java/org/apache/camel/component/pulsar/PulsarConsumerReadCompactedTest.java @@ -27,6 +27,7 @@ import org.apache.camel.component.pulsar.utils.AutoConfiguration; import org.apache.camel.component.pulsar.utils.message.PulsarMessageHeaders; import org.apache.camel.spi.Registry; import org.apache.camel.support.SimpleRegistry; +import org.apache.camel.test.infra.common.TestUtils; import org.apache.pulsar.client.admin.LongRunningProcessStatus; import org.apache.pulsar.client.admin.PulsarAdmin; import org.apache.pulsar.client.admin.PulsarAdminException; @@ -37,17 +38,16 @@ import org.apache.pulsar.client.api.PulsarClient; import org.apache.pulsar.client.api.PulsarClientException; import org.apache.pulsar.client.api.Schema; import org.apache.pulsar.client.impl.ClientBuilderImpl; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class PulsarConsumerReadCompactedTest extends PulsarTestSupport { - private static final Logger LOGGER = LoggerFactory.getLogger(PulsarConsumerReadCompactedTest.class); private static final String TOPIC_URI = "persistent://public/default/camel-topic"; - private static final String PRODUCER = "camel-producer-1"; @EndpointInject("pulsar:" + TOPIC_URI + "?numberOfConsumers=1&subscriptionType=Exclusive" + "&subscriptionName=camel-subscription&consumerQueueSize=1&consumerName=camel-consumer" @@ -64,7 +64,18 @@ public class PulsarConsumerReadCompactedTest extends PulsarTestSupport { @BeforeEach public void setup() throws Exception { context.removeRoute("myRoute"); - producer = givenPulsarClient().newProducer(Schema.STRING).producerName(PRODUCER).topic(TOPIC_URI).create(); + + String producerName = this.getClass().getSimpleName() + TestUtils.randomWithRange(1, 100); + producer = givenPulsarClient().newProducer(Schema.STRING).producerName(producerName).topic(TOPIC_URI).create(); + } + + @AfterEach + public void tearDownProducer() { + try { + producer.close(); + } catch (PulsarClientException e) { + LOGGER.warn("Failed to close client: {}", e.getMessage(), e); + } } @Override @@ -88,11 +99,11 @@ public class PulsarConsumerReadCompactedTest extends PulsarTestSupport { } private PulsarClient givenPulsarClient() throws PulsarClientException { - return new ClientBuilderImpl().serviceUrl(getPulsarBrokerUrl()).ioThreads(1).listenerThreads(1).build(); + return new ClientBuilderImpl().serviceUrl(service.getPulsarBrokerUrl()).ioThreads(1).listenerThreads(1).build(); } private PulsarAdmin givenPulsarAdmin() throws PulsarClientException { - return new PulsarAdminBuilderImpl().serviceHttpUrl(getPulsarAdminUrl()).build(); + return new PulsarAdminBuilderImpl().serviceHttpUrl(service.getPulsarAdminUrl()).build(); } private void triggerCompaction() throws PulsarAdminException, PulsarClientException { diff --git a/components/camel-pulsar/src/test/java/org/apache/camel/component/pulsar/PulsarTestSupport.java b/components/camel-pulsar/src/test/java/org/apache/camel/component/pulsar/PulsarTestSupport.java index c11da4f..9503f3a 100644 --- a/components/camel-pulsar/src/test/java/org/apache/camel/component/pulsar/PulsarTestSupport.java +++ b/components/camel-pulsar/src/test/java/org/apache/camel/component/pulsar/PulsarTestSupport.java @@ -16,47 +16,20 @@ */ package org.apache.camel.component.pulsar; -import java.util.concurrent.TimeUnit; +import org.apache.camel.test.infra.pulsar.services.PulsarService; +import org.apache.camel.test.infra.pulsar.services.PulsarServiceFactory; +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.GenericContainer; - -public class PulsarTestSupport extends ContainerAwareTestSupport { - - public static final String CONTAINER_IMAGE = "apachepulsar/pulsar:2.6.2"; - public static final String CONTAINER_NAME = "pulsar"; - public static final int BROKER_PORT = 6650; - public static final int BROKER_HTTP_PORT = 8080; - public static final String WAIT_FOR_ENDPOINT = "/admin/v2/namespaces/public"; - - @Override - protected GenericContainer<?> createContainer() { - return pulsarContainer(); - } - - public static GenericContainer pulsarContainer() { - return new GenericContainer(CONTAINER_IMAGE).withNetworkAliases(CONTAINER_NAME) - .withExposedPorts(BROKER_PORT, BROKER_HTTP_PORT) - .withCommand("/pulsar/bin/pulsar", "standalone", "--no-functions-worker", "-nss") - .waitingFor(Wait.forHttp(WAIT_FOR_ENDPOINT).forStatusCode(200).forPort(BROKER_HTTP_PORT)); - } +public class PulsarTestSupport extends CamelTestSupport { + @RegisterExtension + static PulsarService service = PulsarServiceFactory.createService(); public String getPulsarBrokerUrl() { - return String.format("pulsar://%s:%s", getContainer(CONTAINER_NAME).getContainerIpAddress(), - getContainer(CONTAINER_NAME).getMappedPort(BROKER_PORT)); + return service.getPulsarBrokerUrl(); } public String getPulsarAdminUrl() { - return String.format("http://%s:%s", getContainer(CONTAINER_NAME).getContainerIpAddress(), - getContainer(CONTAINER_NAME).getMappedPort(BROKER_HTTP_PORT)); - } - - protected long containerShutdownTimeout() { - return TimeUnit.SECONDS.toSeconds(10); - } - - protected void cleanupResources() throws Exception { - super.cleanupResources(); + return service.getPulsarAdminUrl(); } } diff --git a/parent/pom.xml b/parent/pom.xml index 071e0c2..208e550 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -3532,6 +3532,11 @@ <version>${testcontainers-version}</version> </dependency> <dependency> + <groupId>org.testcontainers</groupId> + <artifactId>pulsar</artifactId> + <version>${testcontainers-version}</version> + </dependency> + <dependency> <groupId>org.assertj</groupId> <artifactId>assertj-core</artifactId> <version>${assertj-version}</version> diff --git a/test-infra/camel-test-infra-pulsar/pom.xml b/test-infra/camel-test-infra-pulsar/pom.xml new file mode 100644 index 0000000..aee8f5c --- /dev/null +++ b/test-infra/camel-test-infra-pulsar/pom.xml @@ -0,0 +1,65 @@ +<?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-pulsar</artifactId> + <name>Camel :: Test Infra :: Pulsar</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> + + <dependency> + <groupId>org.testcontainers</groupId> + <artifactId>pulsar</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-pulsar/src/main/resources/META-INF/MANIFEST.MF b/test-infra/camel-test-infra-pulsar/src/main/resources/META-INF/MANIFEST.MF new file mode 100644 index 0000000..e69de29 diff --git a/test-infra/camel-test-infra-pulsar/src/test/java/org/apache/camel/test/infra/pulsar/common/PulsarProperties.java b/test-infra/camel-test-infra-pulsar/src/test/java/org/apache/camel/test/infra/pulsar/common/PulsarProperties.java new file mode 100644 index 0000000..5711f3b --- /dev/null +++ b/test-infra/camel-test-infra-pulsar/src/test/java/org/apache/camel/test/infra/pulsar/common/PulsarProperties.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.pulsar.common; + +public final class PulsarProperties { + public static final String PULSAR_BROKER_URL = "pulsar.broker.url"; + public static final String PULSAR_ADMIN_URL = "pulsar.admin.url"; + + private PulsarProperties() { + + } +} diff --git a/test-infra/camel-test-infra-pulsar/src/test/java/org/apache/camel/test/infra/pulsar/services/PulsarLocalContainerService.java b/test-infra/camel-test-infra-pulsar/src/test/java/org/apache/camel/test/infra/pulsar/services/PulsarLocalContainerService.java new file mode 100644 index 0000000..ef626bc --- /dev/null +++ b/test-infra/camel-test-infra-pulsar/src/test/java/org/apache/camel/test/infra/pulsar/services/PulsarLocalContainerService.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.test.infra.pulsar.services; + +import org.apache.camel.test.infra.common.services.ContainerService; +import org.apache.camel.test.infra.pulsar.common.PulsarProperties; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.testcontainers.containers.PulsarContainer; +import org.testcontainers.utility.DockerImageName; + +public class PulsarLocalContainerService implements PulsarService, ContainerService<PulsarContainer> { + protected static final String CONTAINER_IMAGE = "apachepulsar/pulsar:2.6.2"; + + private static final Logger LOG = LoggerFactory.getLogger(PulsarLocalContainerService.class); + + private PulsarContainer container; + + public PulsarLocalContainerService() { + String imageName = System.getProperty("pulsar.container", CONTAINER_IMAGE); + + initContainer(imageName); + } + + public PulsarLocalContainerService(String imageName) { + initContainer(imageName); + } + + protected void initContainer(String imageName) { + container = new PulsarContainer(DockerImageName.parse(imageName)); + } + + @Override + public void registerProperties() { + System.setProperty(PulsarProperties.PULSAR_ADMIN_URL, getPulsarAdminUrl()); + System.setProperty(PulsarProperties.PULSAR_BROKER_URL, getPulsarBrokerUrl()); + } + + @Override + public void initialize() { + LOG.info("Trying to start the Pulsar container"); + container.start(); + + registerProperties(); + LOG.info("Pulsar instance running at {}", getPulsarAdminUrl()); + LOG.info("Pulsar admin URL available at {}", getPulsarAdminUrl()); + } + + @Override + public void shutdown() { + LOG.info("Stopping the Pulsar container"); + container.stop(); + } + + @Override + public PulsarContainer getContainer() { + return container; + } + + @Override + public String getPulsarAdminUrl() { + return container.getHttpServiceUrl(); + } + + @Override + public String getPulsarBrokerUrl() { + return container.getPulsarBrokerUrl(); + } +} diff --git a/test-infra/camel-test-infra-pulsar/src/test/java/org/apache/camel/test/infra/pulsar/services/PulsarRemoteService.java b/test-infra/camel-test-infra-pulsar/src/test/java/org/apache/camel/test/infra/pulsar/services/PulsarRemoteService.java new file mode 100644 index 0000000..bb30497 --- /dev/null +++ b/test-infra/camel-test-infra-pulsar/src/test/java/org/apache/camel/test/infra/pulsar/services/PulsarRemoteService.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.pulsar.services; + +import org.apache.camel.test.infra.pulsar.common.PulsarProperties; + +public class PulsarRemoteService implements PulsarService { + + @Override + public void registerProperties() { + // NO-OP + } + + @Override + public void initialize() { + registerProperties(); + } + + @Override + public void shutdown() { + // NO-OP + } + + @Override + public String getPulsarAdminUrl() { + return System.getProperty(PulsarProperties.PULSAR_ADMIN_URL); + } + + @Override + public String getPulsarBrokerUrl() { + return System.getProperty(PulsarProperties.PULSAR_BROKER_URL); + } +} diff --git a/test-infra/camel-test-infra-pulsar/src/test/java/org/apache/camel/test/infra/pulsar/services/PulsarService.java b/test-infra/camel-test-infra-pulsar/src/test/java/org/apache/camel/test/infra/pulsar/services/PulsarService.java new file mode 100644 index 0000000..e396f49 --- /dev/null +++ b/test-infra/camel-test-infra-pulsar/src/test/java/org/apache/camel/test/infra/pulsar/services/PulsarService.java @@ -0,0 +1,42 @@ +/* + * 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.pulsar.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 Pulsar + */ +public interface PulsarService extends BeforeAllCallback, AfterAllCallback, TestService { + + String getPulsarAdminUrl(); + + String getPulsarBrokerUrl(); + + @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-pulsar/src/test/java/org/apache/camel/test/infra/pulsar/services/PulsarServiceFactory.java b/test-infra/camel-test-infra-pulsar/src/test/java/org/apache/camel/test/infra/pulsar/services/PulsarServiceFactory.java new file mode 100644 index 0000000..91a75ba --- /dev/null +++ b/test-infra/camel-test-infra-pulsar/src/test/java/org/apache/camel/test/infra/pulsar/services/PulsarServiceFactory.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.pulsar.services; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public final class PulsarServiceFactory { + private static final Logger LOG = LoggerFactory.getLogger(PulsarServiceFactory.class); + + private PulsarServiceFactory() { + + } + + public static PulsarService createService() { + String instanceType = System.getProperty("pulsar.instance.type"); + + if (instanceType == null || instanceType.equals("local-pulsar-container")) { + return new PulsarLocalContainerService(); + } + + if (instanceType.equals("remote")) { + return new PulsarRemoteService(); + } + + LOG.error("Pulsar instance must be one of 'local-pulsar-container' or 'remote"); + throw new UnsupportedOperationException("Invalid Pulsar instance type"); + } +} diff --git a/test-infra/pom.xml b/test-infra/pom.xml index 81b5f83..2e41de1 100644 --- a/test-infra/pom.xml +++ b/test-infra/pom.xml @@ -61,5 +61,6 @@ <module>camel-test-infra-minio</module> <module>camel-test-infra-nats</module> <module>camel-test-infra-nsq</module> + <module>camel-test-infra-pulsar</module> </modules> </project>