This is an automated email from the ASF dual-hosted git repository. davsclaus 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 eea833996d6 More test fixes and improvements (#8111) eea833996d6 is described below commit eea833996d6cb8aebc98add7a511ccb3c2b0787f Author: Otavio Rodolfo Piske <orpi...@users.noreply.github.com> AuthorDate: Fri Aug 5 07:25:40 2022 +0200 More test fixes and improvements (#8111) * (chores) camel-couchbase: let JUnit manage service lifecycle * (chores) camel-test-infra-couchdb: add support for singleton services * (chores) camel-couchdb: use singleton services for a small performance gain --- .../integration/CouchbaseIntegrationTestBase.java | 1 - .../couchdb/integration/CouchDbTestSupport.java | 2 +- .../couchdb/services/CouchDbServiceFactory.java | 52 ++++++++++++++++++++++ 3 files changed, 53 insertions(+), 2 deletions(-) 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 2432ae8282d..be5342975ac 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 @@ -61,7 +61,6 @@ public class CouchbaseIntegrationTestBase extends CamelTestSupport { public static void tearDownCouchbase() { cluster.buckets().dropBucket(bucketName); cluster.disconnect(); - service.shutdown(); } public String getConnectionUri() { diff --git a/components/camel-couchdb/src/test/java/org/apache/camel/component/couchdb/integration/CouchDbTestSupport.java b/components/camel-couchdb/src/test/java/org/apache/camel/component/couchdb/integration/CouchDbTestSupport.java index 9b2486d2b9f..56073dd01a7 100644 --- a/components/camel-couchdb/src/test/java/org/apache/camel/component/couchdb/integration/CouchDbTestSupport.java +++ b/components/camel-couchdb/src/test/java/org/apache/camel/component/couchdb/integration/CouchDbTestSupport.java @@ -24,6 +24,6 @@ import org.junit.jupiter.api.extension.RegisterExtension; public class CouchDbTestSupport extends CamelTestSupport { @SuppressWarnings("unused") @RegisterExtension - static CouchDbService service = CouchDbServiceFactory.createService(); + static CouchDbService service = CouchDbServiceFactory.createSingletonService(); } diff --git a/test-infra/camel-test-infra-couchdb/src/test/java/org/apache/camel/test/infra/couchdb/services/CouchDbServiceFactory.java b/test-infra/camel-test-infra-couchdb/src/test/java/org/apache/camel/test/infra/couchdb/services/CouchDbServiceFactory.java index 68899e0aaae..e247270f860 100644 --- a/test-infra/camel-test-infra-couchdb/src/test/java/org/apache/camel/test/infra/couchdb/services/CouchDbServiceFactory.java +++ b/test-infra/camel-test-infra-couchdb/src/test/java/org/apache/camel/test/infra/couchdb/services/CouchDbServiceFactory.java @@ -17,8 +17,44 @@ package org.apache.camel.test.infra.couchdb.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 CouchDbServiceFactory { + static class SingletonCouchDbService extends SingletonService<CouchDbService> implements CouchDbService { + public SingletonCouchDbService(CouchDbService 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 host() { + return getService().host(); + } + + @Override + public int port() { + return getService().port(); + } + + @Override + public String getServiceAddress() { + return getService().getServiceAddress(); + } + } + + private static SimpleTestServiceBuilder<CouchDbService> instance; + private static CouchDbService service; + private CouchDbServiceFactory() { } @@ -33,4 +69,20 @@ public final class CouchDbServiceFactory { .addRemoteMapping(CouchDbRemoteService::new) .build(); } + + public static CouchDbService createSingletonService() { + if (service == null) { + if (instance == null) { + instance = builder(); + + instance.addLocalMapping(() -> new SingletonCouchDbService(new CouchDbLocalContainerService(), "couchdb")) + .addRemoteMapping(CouchDbRemoteService::new); + + } + + service = instance.build(); + } + + return service; + } }