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/03/29 14:25:45 UTC

[camel] 03/03: CAMEL-17855: enable singleton services for MongoDB

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

commit eb0e0de1706c6eb18d31126df234ed770de58862
Author: Otavio Rodolfo Piske <an...@gmail.com>
AuthorDate: Fri Mar 25 12:50:32 2022 +0100

    CAMEL-17855: enable singleton services for MongoDB
---
 .../integration/AbstractMongoDbITSupport.java      |  2 +-
 .../mongodb/services/MongoDBServiceFactory.java    | 34 ++++++++++++++++++++++
 2 files changed, 35 insertions(+), 1 deletion(-)

diff --git a/components/camel-mongodb/src/test/java/org/apache/camel/component/mongodb/integration/AbstractMongoDbITSupport.java b/components/camel-mongodb/src/test/java/org/apache/camel/component/mongodb/integration/AbstractMongoDbITSupport.java
index 0e79a39..04017b7 100644
--- a/components/camel-mongodb/src/test/java/org/apache/camel/component/mongodb/integration/AbstractMongoDbITSupport.java
+++ b/components/camel-mongodb/src/test/java/org/apache/camel/component/mongodb/integration/AbstractMongoDbITSupport.java
@@ -45,7 +45,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
 public abstract class AbstractMongoDbITSupport extends CamelTestSupport {
 
     @RegisterExtension
-    public static MongoDBService service = MongoDBServiceFactory.createService();
+    public static MongoDBService service = MongoDBServiceFactory.createSingletonService();
 
     protected static final String SCHEME = "mongodb";
     protected static final String USER = "test-user";
diff --git a/test-infra/camel-test-infra-mongodb/src/test/java/org/apache/camel/test/infra/mongodb/services/MongoDBServiceFactory.java b/test-infra/camel-test-infra-mongodb/src/test/java/org/apache/camel/test/infra/mongodb/services/MongoDBServiceFactory.java
index 125cbbf..ba0c8f5 100644
--- a/test-infra/camel-test-infra-mongodb/src/test/java/org/apache/camel/test/infra/mongodb/services/MongoDBServiceFactory.java
+++ b/test-infra/camel-test-infra-mongodb/src/test/java/org/apache/camel/test/infra/mongodb/services/MongoDBServiceFactory.java
@@ -18,8 +18,35 @@
 package org.apache.camel.test.infra.mongodb.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 MongoDBServiceFactory {
+    static class SingletonMongoDBService extends SingletonService<MongoDBService> implements MongoDBService {
+        public SingletonMongoDBService(MongoDBService service, String name) {
+            super(service, name);
+        }
+
+        @Override
+        public void beforeAll(ExtensionContext extensionContext) {
+            addToStore(extensionContext);
+        }
+
+        @Override
+        public void afterAll(ExtensionContext extensionContext) {
+            // NO-OP
+        }
+
+        @Override
+        public String getReplicaSetUrl() {
+            return getService().getReplicaSetUrl();
+        }
+
+        @Override
+        public String getConnectionAddress() {
+            return getService().getConnectionAddress();
+        }
+    }
     private MongoDBServiceFactory() {
 
     }
@@ -34,4 +61,11 @@ public final class MongoDBServiceFactory {
                 .addRemoteMapping(MongoDBRemoteService::new)
                 .build();
     }
+
+    public static MongoDBService createSingletonService() {
+        return builder()
+                .addLocalMapping(() -> new SingletonMongoDBService(new MongoDBLocalContainerService(), "mongo-db"))
+                .addRemoteMapping(MongoDBRemoteService::new)
+                .build();
+    }
 }