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/04 14:19:04 UTC

[camel] 03/04: CAMEL-18347: fix MongoDB services in test infra not being singleton

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 efd464b1f2e414cddadafac040046728e7ff41e3
Author: Otavio Rodolfo Piske <an...@gmail.com>
AuthorDate: Thu Aug 4 14:57:16 2022 +0200

    CAMEL-18347: fix MongoDB services in test infra not being singleton
---
 .../infra/mongodb/services/MongoDBServiceFactory.java  | 18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)

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 52762a95ac2..dfd97aece4e 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
@@ -48,6 +48,9 @@ public final class MongoDBServiceFactory {
         }
     }
 
+    private static SimpleTestServiceBuilder<MongoDBService> instance;
+    private static MongoDBService service;
+
     private MongoDBServiceFactory() {
 
     }
@@ -64,9 +67,16 @@ public final class MongoDBServiceFactory {
     }
 
     public static MongoDBService createSingletonService() {
-        return builder()
-                .addLocalMapping(() -> new SingletonMongoDBService(new MongoDBLocalContainerService(), "mongo-db"))
-                .addRemoteMapping(MongoDBRemoteService::new)
-                .build();
+        if (service == null) {
+            if (instance == null) {
+                instance = builder();
+                instance.addLocalMapping(() -> new SingletonMongoDBService(new MongoDBLocalContainerService(), "mongo-db"))
+                        .addRemoteMapping(MongoDBRemoteService::new);
+            }
+
+            service = instance.build();
+        }
+
+        return service;
     }
 }