You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by or...@apache.org on 2022/08/11 09:08:39 UTC

[camel] branch main updated: CAMEL-18381: added support for singleton services for camel-test-infra-couchbase

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

orpiske pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/main by this push:
     new 5d769db1408 CAMEL-18381: added support for singleton services for camel-test-infra-couchbase
5d769db1408 is described below

commit 5d769db1408270339b9825168ce50bd60da5b3cb
Author: Otavio Rodolfo Piske <an...@gmail.com>
AuthorDate: Thu Aug 11 10:03:34 2022 +0200

    CAMEL-18381: added support for singleton services for camel-test-infra-couchbase
---
 .../integration/CouchbaseIntegrationTestBase.java  |  2 +-
 .../services/CouchbaseServiceFactory.java          | 61 ++++++++++++++++++++++
 2 files changed, 62 insertions(+), 1 deletion(-)

diff --git a/components/camel-couchbase/src/test/java/org/apache/camel/component/couchbase/integration/CouchbaseIntegrationTestBase.java b/components/camel-couchbase/src/test/java/org/apache/camel/component/couchbase/integration/CouchbaseIntegrationTestBase.java
index be5342975ac..2306dcc4069 100644
--- a/components/camel-couchbase/src/test/java/org/apache/camel/component/couchbase/integration/CouchbaseIntegrationTestBase.java
+++ b/components/camel-couchbase/src/test/java/org/apache/camel/component/couchbase/integration/CouchbaseIntegrationTestBase.java
@@ -36,7 +36,7 @@ import org.junit.jupiter.api.extension.RegisterExtension;
 
 public class CouchbaseIntegrationTestBase extends CamelTestSupport {
     @RegisterExtension
-    public static CouchbaseService service = CouchbaseServiceFactory.createService();
+    public static CouchbaseService service = CouchbaseServiceFactory.createSingletonService();
 
     protected static String bucketName;
     protected static Cluster cluster;
diff --git a/test-infra/camel-test-infra-couchbase/src/test/java/org/apache/camel/test/infra/couchbase/services/CouchbaseServiceFactory.java b/test-infra/camel-test-infra-couchbase/src/test/java/org/apache/camel/test/infra/couchbase/services/CouchbaseServiceFactory.java
index 752ba6f5f79..be16203a917 100644
--- a/test-infra/camel-test-infra-couchbase/src/test/java/org/apache/camel/test/infra/couchbase/services/CouchbaseServiceFactory.java
+++ b/test-infra/camel-test-infra-couchbase/src/test/java/org/apache/camel/test/infra/couchbase/services/CouchbaseServiceFactory.java
@@ -18,8 +18,54 @@
 package org.apache.camel.test.infra.couchbase.services;
 
 import org.apache.camel.test.infra.common.services.SimpleTestServiceBuilder;
+import org.apache.camel.test.infra.common.services.SingletonService;
+import org.junit.jupiter.api.extension.ExtensionContext;
 
 public final class CouchbaseServiceFactory {
+    static class SingletonCouchbaseService extends SingletonService<CouchbaseService> implements CouchbaseService {
+        public SingletonCouchbaseService(CouchbaseService service, String name) {
+            super(service, name);
+        }
+
+        @Override
+        public void beforeAll(ExtensionContext extensionContext) {
+            addToStore(extensionContext);
+        }
+
+        @Override
+        public String getConnectionString() {
+            return getService().getConnectionString();
+        }
+
+        @Override
+        public String getUsername() {
+            return getService().getUsername();
+        }
+
+        @Override
+        public String getPassword() {
+            return getService().getPassword();
+        }
+
+        @Override
+        public String getHostname() {
+            return getService().getHostname();
+        }
+
+        @Override
+        public int getPort() {
+            return getService().getPort();
+        }
+
+        @Override
+        public void afterAll(ExtensionContext extensionContext) {
+            // NO-OP
+        }
+    }
+
+    private static SimpleTestServiceBuilder<CouchbaseService> instance;
+    private static CouchbaseService service;
+
     private CouchbaseServiceFactory() {
 
     }
@@ -35,6 +81,21 @@ public final class CouchbaseServiceFactory {
                 .build();
     }
 
+    public static synchronized CouchbaseService createSingletonService() {
+        if (service == null) {
+            if (instance == null) {
+                instance = builder();
+
+                instance.addLocalMapping(() -> new SingletonCouchbaseService(new CouchbaseLocalContainerService(), "couchbase"))
+                        .addRemoteMapping(CouchbaseRemoteService::new);
+            }
+
+            service = instance.build();
+        }
+
+        return service;
+    }
+
     @Deprecated
     public static CouchbaseService getService() {
         return createService();