You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2020/11/25 12:58:29 UTC

[camel] branch master updated: Migrates google-pubsub component to the new test-infra (#4682)

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

davsclaus 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 c40fa1d  Migrates google-pubsub component to the new test-infra (#4682)
c40fa1d is described below

commit c40fa1d26e55a2b56c35e1afc31f86c5c7e086a7
Author: Otavio Rodolfo Piske <or...@users.noreply.github.com>
AuthorDate: Wed Nov 25 13:58:14 2020 +0100

    Migrates google-pubsub component to the new test-infra (#4682)
---
 components/camel-google-pubsub/pom.xml             | 24 +++++-
 .../component/google/pubsub/PubsubTestSupport.java | 29 +++----
 .../google/pubsub/integration/BodyTypesTest.java   | 10 ++-
 .../integration/GroupedExchangeRoundtripTest.java  | 10 ++-
 test-infra/camel-test-infra-google-pubsub/pom.xml  | 59 +++++++++++++++
 .../src/main/resources/META-INF/MANIFEST.MF        |  0
 .../pubsub/common/GooglePubSubProperties.java      | 28 +++++++
 .../GooglePubSubLocalContainerService.java         | 88 ++++++++++++++++++++++
 .../pubsub/services/GooglePubSubRemoteService.java | 42 +++++++++++
 .../pubsub/services/GooglePubSubService.java       | 40 ++++++++++
 .../services/GooglePubSubServiceFactory.java       | 43 +++++++++++
 test-infra/pom.xml                                 |  1 +
 12 files changed, 349 insertions(+), 25 deletions(-)

diff --git a/components/camel-google-pubsub/pom.xml b/components/camel-google-pubsub/pom.xml
index 02c6759..37aafa8 100644
--- a/components/camel-google-pubsub/pom.xml
+++ b/components/camel-google-pubsub/pom.xml
@@ -54,15 +54,33 @@
             <version>${google-pubsub-guava-version}</version>
         </dependency>
         <dependency>
+            <groupId>org.apache.logging.log4j</groupId>
+            <artifactId>log4j-slf4j-impl</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
             <groupId>org.apache.camel</groupId>
-            <artifactId>camel-testcontainers-junit5</artifactId>
+            <artifactId>camel-test-junit5</artifactId>
             <scope>test</scope>
         </dependency>
+
+        <!-- test infra -->
         <dependency>
-            <groupId>org.apache.logging.log4j</groupId>
-            <artifactId>log4j-slf4j-impl</artifactId>
+            <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-google-pubsub</artifactId>
+            <version>${project.version}</version>
+            <type>test-jar</type>
+            <scope>test</scope>
+        </dependency>
+
     </dependencies>
 
     <profiles>
diff --git a/components/camel-google-pubsub/src/test/java/org/apache/camel/component/google/pubsub/PubsubTestSupport.java b/components/camel-google-pubsub/src/test/java/org/apache/camel/component/google/pubsub/PubsubTestSupport.java
index 165f196..5489449 100644
--- a/components/camel-google-pubsub/src/test/java/org/apache/camel/component/google/pubsub/PubsubTestSupport.java
+++ b/components/camel-google-pubsub/src/test/java/org/apache/camel/component/google/pubsub/PubsubTestSupport.java
@@ -36,11 +36,14 @@ import io.grpc.ManagedChannel;
 import io.grpc.ManagedChannelBuilder;
 import org.apache.camel.BindToRegistry;
 import org.apache.camel.CamelContext;
-import org.apache.camel.test.testcontainers.junit5.ContainerAwareTestSupport;
-import org.testcontainers.containers.GenericContainer;
-import org.testcontainers.containers.wait.strategy.LogMessageWaitStrategy;
+import org.apache.camel.test.infra.google.pubsub.services.GooglePubSubService;
+import org.apache.camel.test.infra.google.pubsub.services.GooglePubSubServiceFactory;
+import org.apache.camel.test.junit5.CamelTestSupport;
+import org.junit.jupiter.api.extension.RegisterExtension;
 
-public class PubsubTestSupport extends ContainerAwareTestSupport {
+public class PubsubTestSupport extends CamelTestSupport {
+    @RegisterExtension
+    public static GooglePubSubService service = GooglePubSubServiceFactory.createService();
 
     public static final String PROJECT_ID;
 
@@ -49,13 +52,6 @@ public class PubsubTestSupport extends ContainerAwareTestSupport {
         PROJECT_ID = testProperties.getProperty("project.id");
     }
 
-    protected GenericContainer<?> container = new GenericContainer<>("google/cloud-sdk:latest")
-            .withExposedPorts(8383)
-            .withCommand("/bin/sh", "-c",
-                    String.format("gcloud beta emulators pubsub start --project %s --host-port=0.0.0.0:%d",
-                            PROJECT_ID, 8383))
-            .waitingFor(new LogMessageWaitStrategy().withRegEx("(?s).*started.*$"));
-
     private static Properties loadProperties() {
         Properties testProperties = new Properties();
         InputStream fileIn = PubsubTestSupport.class.getClassLoader().getResourceAsStream("simple.properties");
@@ -69,15 +65,10 @@ public class PubsubTestSupport extends ContainerAwareTestSupport {
         return testProperties;
     }
 
-    @Override
-    protected GenericContainer<?> createContainer() {
-        return super.createContainer();
-    }
-
     protected void addPubsubComponent(CamelContext context) {
 
         GooglePubsubComponent component = new GooglePubsubComponent();
-        component.setEndpoint(container.getContainerIpAddress() + ":" + container.getFirstMappedPort());
+        component.setEndpoint(service.getServiceAddress());
 
         context.addComponent("google-pubsub", component);
         context.getPropertiesComponent().setLocation("ref:prop");
@@ -90,7 +81,6 @@ public class PubsubTestSupport extends ContainerAwareTestSupport {
 
     @Override
     protected CamelContext createCamelContext() throws Exception {
-        container.start();
         createTopicSubscription();
         CamelContext context = super.createCamelContext();
         addPubsubComponent(context);
@@ -140,9 +130,8 @@ public class PubsubTestSupport extends ContainerAwareTestSupport {
     }
 
     private FixedTransportChannelProvider createChannelProvider() {
-        Integer port = container.getFirstMappedPort();
         ManagedChannel channel = ManagedChannelBuilder
-                .forTarget(String.format("%s:%s", "localhost", port))
+                .forTarget(String.format(service.getServiceAddress()))
                 .usePlaintext()
                 .build();
 
diff --git a/components/camel-google-pubsub/src/test/java/org/apache/camel/component/google/pubsub/integration/BodyTypesTest.java b/components/camel-google-pubsub/src/test/java/org/apache/camel/component/google/pubsub/integration/BodyTypesTest.java
index a71a15f..29fb78a 100644
--- a/components/camel-google-pubsub/src/test/java/org/apache/camel/component/google/pubsub/integration/BodyTypesTest.java
+++ b/components/camel-google-pubsub/src/test/java/org/apache/camel/component/google/pubsub/integration/BodyTypesTest.java
@@ -34,6 +34,8 @@ import org.apache.camel.component.google.pubsub.PubsubTestSupport;
 import org.apache.camel.component.mock.MockEndpoint;
 import org.apache.camel.support.DefaultExchange;
 import org.junit.jupiter.api.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertNotNull;
@@ -41,6 +43,7 @@ import static org.junit.jupiter.api.Assertions.assertSame;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 
 public class BodyTypesTest extends PubsubTestSupport {
+    private static final Logger LOG = LoggerFactory.getLogger(BodyTypesTest.class);
 
     private static final String TOPIC_NAME = "typesSend";
     private static final String SUBSCRIPTION_NAME = "TypesReceive";
@@ -65,7 +68,12 @@ public class BodyTypesTest extends PubsubTestSupport {
 
     @Override
     public void createTopicSubscription() {
-        createTopicSubscriptionPair(TOPIC_NAME, SUBSCRIPTION_NAME);
+        try {
+            createTopicSubscriptionPair(TOPIC_NAME, SUBSCRIPTION_NAME);
+        } catch (Exception e) {
+            // May be ignored because it could have been created. 
+            LOG.warn("Failed to create the subscription pair {}", e.getMessage());
+        }
     }
 
     @Override
diff --git a/components/camel-google-pubsub/src/test/java/org/apache/camel/component/google/pubsub/integration/GroupedExchangeRoundtripTest.java b/components/camel-google-pubsub/src/test/java/org/apache/camel/component/google/pubsub/integration/GroupedExchangeRoundtripTest.java
index cfded55..7f7e77e 100644
--- a/components/camel-google-pubsub/src/test/java/org/apache/camel/component/google/pubsub/integration/GroupedExchangeRoundtripTest.java
+++ b/components/camel-google-pubsub/src/test/java/org/apache/camel/component/google/pubsub/integration/GroupedExchangeRoundtripTest.java
@@ -29,10 +29,13 @@ import org.apache.camel.component.mock.MockEndpoint;
 import org.apache.camel.processor.aggregate.GroupedExchangeAggregationStrategy;
 import org.apache.camel.support.DefaultExchange;
 import org.junit.jupiter.api.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
 
 public class GroupedExchangeRoundtripTest extends PubsubTestSupport {
+    private static final Logger LOG = LoggerFactory.getLogger(GroupedExchangeRoundtripTest.class);
 
     private static final String TOPIC_NAME = "groupTopic";
     private static final String SUBSCRIPTION_NAME = "groupSubscription";
@@ -57,7 +60,12 @@ public class GroupedExchangeRoundtripTest extends PubsubTestSupport {
 
     @Override
     public void createTopicSubscription() {
-        createTopicSubscriptionPair(TOPIC_NAME, SUBSCRIPTION_NAME);
+        try {
+            createTopicSubscriptionPair(TOPIC_NAME, SUBSCRIPTION_NAME);
+        } catch (Exception e) {
+            // May be ignored because it could have been created.
+            LOG.warn("Failed to create the subscription pair {}", e.getMessage());
+        }
     }
 
     @Override
diff --git a/test-infra/camel-test-infra-google-pubsub/pom.xml b/test-infra/camel-test-infra-google-pubsub/pom.xml
new file mode 100644
index 0000000..49a9d5d
--- /dev/null
+++ b/test-infra/camel-test-infra-google-pubsub/pom.xml
@@ -0,0 +1,59 @@
+<?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-google-pubsub</artifactId>
+    <name>Camel :: Test Infra :: Google Pub/Sub</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-google-pubsub/src/main/resources/META-INF/MANIFEST.MF b/test-infra/camel-test-infra-google-pubsub/src/main/resources/META-INF/MANIFEST.MF
new file mode 100644
index 0000000..e69de29
diff --git a/test-infra/camel-test-infra-google-pubsub/src/test/java/org/apache/camel/test/infra/google/pubsub/common/GooglePubSubProperties.java b/test-infra/camel-test-infra-google-pubsub/src/test/java/org/apache/camel/test/infra/google/pubsub/common/GooglePubSubProperties.java
new file mode 100644
index 0000000..495022e
--- /dev/null
+++ b/test-infra/camel-test-infra-google-pubsub/src/test/java/org/apache/camel/test/infra/google/pubsub/common/GooglePubSubProperties.java
@@ -0,0 +1,28 @@
+/*
+ * 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.google.pubsub.common;
+
+public final class GooglePubSubProperties {
+    public static final String CONTAINER_NAME = "google.pubsub.container";
+    public static final String PROJECT_ID = "google.pubsub.project.id";
+    public static final String SERVICE_ADDRESS = "google.pubsub.service.address";
+
+    private GooglePubSubProperties() {
+
+    }
+}
diff --git a/test-infra/camel-test-infra-google-pubsub/src/test/java/org/apache/camel/test/infra/google/pubsub/services/GooglePubSubLocalContainerService.java b/test-infra/camel-test-infra-google-pubsub/src/test/java/org/apache/camel/test/infra/google/pubsub/services/GooglePubSubLocalContainerService.java
new file mode 100644
index 0000000..16d53f7
--- /dev/null
+++ b/test-infra/camel-test-infra-google-pubsub/src/test/java/org/apache/camel/test/infra/google/pubsub/services/GooglePubSubLocalContainerService.java
@@ -0,0 +1,88 @@
+/*
+ * 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.google.pubsub.services;
+
+import org.apache.camel.test.infra.common.services.ContainerService;
+import org.apache.camel.test.infra.google.pubsub.common.GooglePubSubProperties;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.testcontainers.containers.GenericContainer;
+import org.testcontainers.containers.wait.strategy.LogMessageWaitStrategy;
+
+public class GooglePubSubLocalContainerService implements GooglePubSubService, ContainerService<GenericContainer> {
+    public static final String PROJECT_ID;
+    private static final Logger LOG = LoggerFactory.getLogger(GooglePubSubLocalContainerService.class);
+    private static final String CONTAINER_NAME = "google/cloud-sdk:latest";
+    private static final String DEFAULT_PROJECT_ID = "test-project";
+    private static final int DEFAULT_PORT = 8383;
+
+    static {
+        PROJECT_ID = System.getProperty(GooglePubSubProperties.PROJECT_ID, DEFAULT_PROJECT_ID);
+    }
+
+    private GenericContainer container;
+
+    public GooglePubSubLocalContainerService() {
+        String containerName = System.getProperty(GooglePubSubProperties.CONTAINER_NAME, CONTAINER_NAME);
+        initContainer(containerName);
+    }
+
+    public GooglePubSubLocalContainerService(String containerName) {
+        initContainer(containerName);
+    }
+
+    protected void initContainer(String containerName) {
+        String command = String.format("gcloud beta emulators pubsub start --project %s --host-port=0.0.0.0:%d",
+                PROJECT_ID, DEFAULT_PORT);
+
+        container = new GenericContainer<>(containerName)
+                .withExposedPorts(DEFAULT_PORT)
+                .withCommand("/bin/sh", "-c", command)
+                .waitingFor(new LogMessageWaitStrategy().withRegEx("(?s).*started.*$"));
+    }
+
+    @Override
+    public void registerProperties() {
+
+    }
+
+    @Override
+    public void initialize() {
+        LOG.info("Trying to start the GooglePubSub container");
+        container.start();
+
+        registerProperties();
+
+        LOG.info("GooglePubSub instance running at {}", getServiceAddress());
+    }
+
+    @Override
+    public void shutdown() {
+        LOG.info("Stopping the GooglePubSub container");
+        container.stop();
+    }
+
+    @Override
+    public GenericContainer getContainer() {
+        return container;
+    }
+
+    @Override
+    public String getServiceAddress() {
+        return String.format("%s:%d", container.getContainerIpAddress(), container.getFirstMappedPort());
+    }
+}
diff --git a/test-infra/camel-test-infra-google-pubsub/src/test/java/org/apache/camel/test/infra/google/pubsub/services/GooglePubSubRemoteService.java b/test-infra/camel-test-infra-google-pubsub/src/test/java/org/apache/camel/test/infra/google/pubsub/services/GooglePubSubRemoteService.java
new file mode 100644
index 0000000..d64b01a
--- /dev/null
+++ b/test-infra/camel-test-infra-google-pubsub/src/test/java/org/apache/camel/test/infra/google/pubsub/services/GooglePubSubRemoteService.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.google.pubsub.services;
+
+import org.apache.camel.test.infra.google.pubsub.common.GooglePubSubProperties;
+
+public class GooglePubSubRemoteService implements GooglePubSubService {
+
+    @Override
+    public void registerProperties() {
+        // NO-OP
+    }
+
+    @Override
+    public void initialize() {
+        registerProperties();
+    }
+
+    @Override
+    public void shutdown() {
+        // NO-OP
+    }
+
+    @Override
+    public String getServiceAddress() {
+        return System.getProperty(GooglePubSubProperties.SERVICE_ADDRESS);
+    }
+}
diff --git a/test-infra/camel-test-infra-google-pubsub/src/test/java/org/apache/camel/test/infra/google/pubsub/services/GooglePubSubService.java b/test-infra/camel-test-infra-google-pubsub/src/test/java/org/apache/camel/test/infra/google/pubsub/services/GooglePubSubService.java
new file mode 100644
index 0000000..4796e04
--- /dev/null
+++ b/test-infra/camel-test-infra-google-pubsub/src/test/java/org/apache/camel/test/infra/google/pubsub/services/GooglePubSubService.java
@@ -0,0 +1,40 @@
+/*
+ * 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.google.pubsub.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 GooglePubSub
+ */
+public interface GooglePubSubService extends BeforeAllCallback, AfterAllCallback, TestService {
+
+    String getServiceAddress();
+
+    @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-google-pubsub/src/test/java/org/apache/camel/test/infra/google/pubsub/services/GooglePubSubServiceFactory.java b/test-infra/camel-test-infra-google-pubsub/src/test/java/org/apache/camel/test/infra/google/pubsub/services/GooglePubSubServiceFactory.java
new file mode 100644
index 0000000..fb4114f
--- /dev/null
+++ b/test-infra/camel-test-infra-google-pubsub/src/test/java/org/apache/camel/test/infra/google/pubsub/services/GooglePubSubServiceFactory.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.google.pubsub.services;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public final class GooglePubSubServiceFactory {
+    private static final Logger LOG = LoggerFactory.getLogger(GooglePubSubServiceFactory.class);
+
+    private GooglePubSubServiceFactory() {
+
+    }
+
+    public static GooglePubSubService createService() {
+        String instanceType = System.getProperty("googlepubsub.instance.type");
+
+        if (instanceType == null || instanceType.equals("local-googlepubsub-container")) {
+            return new GooglePubSubLocalContainerService();
+        }
+
+        if (instanceType.equals("remote")) {
+            return new GooglePubSubRemoteService();
+        }
+
+        LOG.error("GooglePubSub instance must be one of 'local-googlepubsub-container' or 'remote");
+        throw new UnsupportedOperationException("Invalid GooglePubSub instance type");
+    }
+}
diff --git a/test-infra/pom.xml b/test-infra/pom.xml
index 383e789..5b82089 100644
--- a/test-infra/pom.xml
+++ b/test-infra/pom.xml
@@ -54,5 +54,6 @@
         <module>camel-test-infra-jdbc</module>
         <module>camel-test-infra-arangodb</module>
         <module>camel-test-infra-consul</module>
+        <module>camel-test-infra-google-pubsub</module>
     </modules>
 </project>