Skip to content

Commit 02f64f5

Browse files
gnodetclaude
andcommitted
Add createSingletonService() to 27 test-infra service factories
Add singleton service support to test-infra service factories that were missing it. This allows test classes to share a single container instance per JVM, reducing Docker overhead and preparing the infrastructure for safe within-JVM parallel test execution. Each factory now provides: - A SingletonXxxService inner class extending SingletonService<T> - A lazy-init SingletonServiceHolder using static initializer - A createSingletonService() factory method Factories updated: AzureStorageBlob, AzureStorageQueue, Cassandra, Consul, Docling, GooglePubSub, Hashicorp, Hazelcast, IbmMQ, Iggy, Ignite, Keycloak, McpEverything, McpEverythingSse, MicroprofileLRA, Minio, Mosquitto, Nats, Openldap, Postgres, PostgresVector, RabbitMQ, Redis, Solr, TensorFlowServing, Triton, Xmpp. ZooKeeper excluded: requires unique container naming (PR #22287) first, since camel-zookeeper and camel-zookeeper-master both create containers named "camel-zookeeper" and collide in parallel CI builds. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent f60e3da commit 02f64f5

File tree

27 files changed

+1033
-0
lines changed

27 files changed

+1033
-0
lines changed

test-infra/camel-test-infra-azure-storage-blob/src/main/java/org/apache/camel/test/infra/azure/storage/blob/services/AzureStorageBlobServiceFactory.java

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,45 @@
1717

1818
package org.apache.camel.test.infra.azure.storage.blob.services;
1919

20+
import org.apache.camel.test.infra.azure.common.AzureCredentialsHolder;
2021
import org.apache.camel.test.infra.azure.common.services.AzureService;
2122
import org.apache.camel.test.infra.common.services.SimpleTestServiceBuilder;
23+
import org.apache.camel.test.infra.common.services.SingletonService;
2224

2325
public final class AzureStorageBlobServiceFactory {
26+
27+
private static class SingletonAzureStorageBlobService extends SingletonService<AzureService>
28+
implements AzureService {
29+
public SingletonAzureStorageBlobService(AzureService service, String name) {
30+
super(service, name);
31+
}
32+
33+
@Override
34+
public AzureCredentialsHolder azureCredentials() {
35+
return getService().azureCredentials();
36+
}
37+
38+
@Override
39+
public String accountName() {
40+
return getService().accountName();
41+
}
42+
43+
@Override
44+
public String accessKey() {
45+
return getService().accessKey();
46+
}
47+
48+
@Override
49+
public String host() {
50+
return getService().host();
51+
}
52+
53+
@Override
54+
public int port() {
55+
return getService().port();
56+
}
57+
}
58+
2459
private AzureStorageBlobServiceFactory() {
2560

2661
}
@@ -36,6 +71,21 @@ public static AzureService createService() {
3671
.build();
3772
}
3873

74+
public static AzureService createSingletonService() {
75+
return SingletonServiceHolder.INSTANCE;
76+
}
77+
78+
private static class SingletonServiceHolder {
79+
static final AzureService INSTANCE;
80+
static {
81+
SimpleTestServiceBuilder<AzureService> instance = builder();
82+
instance.addLocalMapping(
83+
() -> new SingletonAzureStorageBlobService(new AzureStorageBlobLocalContainerService(), "azure"))
84+
.addRemoteMapping(AzureStorageBlobRemoteService::new);
85+
INSTANCE = instance.build();
86+
}
87+
}
88+
3989
static class AzureStorageBlobLocalContainerService extends AzureStorageBlobLocalContainerInfraService
4090
implements AzureService {
4191
}

test-infra/camel-test-infra-azure-storage-queue/src/main/java/org/apache/camel/test/infra/azure/storage/queue/services/AzureStorageQueueServiceFactory.java

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,45 @@
1717

1818
package org.apache.camel.test.infra.azure.storage.queue.services;
1919

20+
import org.apache.camel.test.infra.azure.common.AzureCredentialsHolder;
2021
import org.apache.camel.test.infra.azure.common.services.AzureService;
2122
import org.apache.camel.test.infra.common.services.SimpleTestServiceBuilder;
23+
import org.apache.camel.test.infra.common.services.SingletonService;
2224

2325
public final class AzureStorageQueueServiceFactory {
26+
27+
private static class SingletonAzureStorageQueueService extends SingletonService<AzureService>
28+
implements AzureService {
29+
public SingletonAzureStorageQueueService(AzureService service, String name) {
30+
super(service, name);
31+
}
32+
33+
@Override
34+
public AzureCredentialsHolder azureCredentials() {
35+
return getService().azureCredentials();
36+
}
37+
38+
@Override
39+
public String accountName() {
40+
return getService().accountName();
41+
}
42+
43+
@Override
44+
public String accessKey() {
45+
return getService().accessKey();
46+
}
47+
48+
@Override
49+
public String host() {
50+
return getService().host();
51+
}
52+
53+
@Override
54+
public int port() {
55+
return getService().port();
56+
}
57+
}
58+
2459
private AzureStorageQueueServiceFactory() {
2560

2661
}
@@ -36,6 +71,21 @@ public static AzureService createService() {
3671
.build();
3772
}
3873

74+
public static AzureService createSingletonService() {
75+
return SingletonServiceHolder.INSTANCE;
76+
}
77+
78+
private static class SingletonServiceHolder {
79+
static final AzureService INSTANCE;
80+
static {
81+
SimpleTestServiceBuilder<AzureService> instance = builder();
82+
instance.addLocalMapping(
83+
() -> new SingletonAzureStorageQueueService(new AzureStorageQueueLocalContainerService(), "azure"))
84+
.addRemoteMapping(AzureStorageQueueRemoteService::new);
85+
INSTANCE = instance.build();
86+
}
87+
}
88+
3989
public static class AzureStorageQueueLocalContainerService extends AzureStorageQueueLocalContainerInfraService
4090
implements AzureService {
4191
}

test-infra/camel-test-infra-cassandra/src/main/java/org/apache/camel/test/infra/cassandra/services/CassandraServiceFactory.java

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,36 @@
1717
package org.apache.camel.test.infra.cassandra.services;
1818

1919
import org.apache.camel.test.infra.common.services.SimpleTestServiceBuilder;
20+
import org.apache.camel.test.infra.common.services.SingletonService;
2021

2122
public final class CassandraServiceFactory {
23+
24+
private static class SingletonCassandraService extends SingletonService<CassandraService> implements CassandraService {
25+
public SingletonCassandraService(CassandraService service, String name) {
26+
super(service, name);
27+
}
28+
29+
@Override
30+
public int getCQL3Port() {
31+
return getService().getCQL3Port();
32+
}
33+
34+
@Override
35+
public String getCassandraHost() {
36+
return getService().getCassandraHost();
37+
}
38+
39+
@Override
40+
public String hosts() {
41+
return getService().hosts();
42+
}
43+
44+
@Override
45+
public int port() {
46+
return getService().port();
47+
}
48+
}
49+
2250
private CassandraServiceFactory() {
2351

2452
}
@@ -43,6 +71,21 @@ public static CassandraService createService() {
4371
.build();
4472
}
4573

74+
public static CassandraService createSingletonService() {
75+
return SingletonServiceHolder.INSTANCE;
76+
}
77+
78+
private static class SingletonServiceHolder {
79+
static final CassandraService INSTANCE;
80+
static {
81+
SimpleTestServiceBuilder<CassandraService> instance = builder();
82+
instance.addLocalMapping(
83+
() -> new SingletonCassandraService(new CassandraLocalContainerService(), "cassandra"))
84+
.addRemoteMapping(RemoteCassandraService::new);
85+
INSTANCE = instance.build();
86+
}
87+
}
88+
4689
public static class RemoteCassandraService extends RemoteCassandraInfraService implements CassandraService {
4790
}
4891
}

test-infra/camel-test-infra-consul/src/main/java/org/apache/camel/test/infra/consul/services/ConsulServiceFactory.java

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,31 @@
1717
package org.apache.camel.test.infra.consul.services;
1818

1919
import org.apache.camel.test.infra.common.services.SimpleTestServiceBuilder;
20+
import org.apache.camel.test.infra.common.services.SingletonService;
2021

2122
public final class ConsulServiceFactory {
2223

24+
private static class SingletonConsulService extends SingletonService<ConsulService> implements ConsulService {
25+
public SingletonConsulService(ConsulService service, String name) {
26+
super(service, name);
27+
}
28+
29+
@Override
30+
public String getConsulUrl() {
31+
return getService().getConsulUrl();
32+
}
33+
34+
@Override
35+
public String host() {
36+
return getService().host();
37+
}
38+
39+
@Override
40+
public int port() {
41+
return getService().port();
42+
}
43+
}
44+
2345
private ConsulServiceFactory() {
2446
}
2547

@@ -34,6 +56,21 @@ public static ConsulService createService() {
3456
.build();
3557
}
3658

59+
public static ConsulService createSingletonService() {
60+
return SingletonServiceHolder.INSTANCE;
61+
}
62+
63+
private static class SingletonServiceHolder {
64+
static final ConsulService INSTANCE;
65+
static {
66+
SimpleTestServiceBuilder<ConsulService> instance = builder();
67+
instance.addLocalMapping(
68+
() -> new SingletonConsulService(new ConsulLocalContainerTestService(), "consul"))
69+
.addRemoteMapping(ConsulRemoteTestService::new);
70+
INSTANCE = instance.build();
71+
}
72+
}
73+
3774
public static class ConsulLocalContainerTestService extends ConsulLocalContainerInfraService implements ConsulService {
3875
}
3976

test-infra/camel-test-infra-docling/src/main/java/org/apache/camel/test/infra/docling/services/DoclingServiceFactory.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,21 @@
1717
package org.apache.camel.test.infra.docling.services;
1818

1919
import org.apache.camel.test.infra.common.services.SimpleTestServiceBuilder;
20+
import org.apache.camel.test.infra.common.services.SingletonService;
2021

2122
public final class DoclingServiceFactory {
23+
24+
private static class SingletonDoclingService extends SingletonService<DoclingService> implements DoclingService {
25+
public SingletonDoclingService(DoclingService service, String name) {
26+
super(service, name);
27+
}
28+
29+
@Override
30+
public String doclingServerUrl() {
31+
return getService().doclingServerUrl();
32+
}
33+
}
34+
2235
private DoclingServiceFactory() {
2336

2437
}
@@ -33,6 +46,20 @@ public static DoclingService createService() {
3346
.build();
3447
}
3548

49+
public static DoclingService createSingletonService() {
50+
return SingletonServiceHolder.INSTANCE;
51+
}
52+
53+
private static class SingletonServiceHolder {
54+
static final DoclingService INSTANCE;
55+
static {
56+
SimpleTestServiceBuilder<DoclingService> instance = builder();
57+
instance.addLocalMapping(
58+
() -> new SingletonDoclingService(new DoclingLocalContainerService(), "docling"));
59+
INSTANCE = instance.build();
60+
}
61+
}
62+
3663
public static class DoclingLocalContainerService extends DoclingLocalContainerInfraService
3764
implements DoclingService {
3865
}

test-infra/camel-test-infra-google-pubsub/src/main/java/org/apache/camel/test/infra/google/pubsub/services/GooglePubSubServiceFactory.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,22 @@
1717
package org.apache.camel.test.infra.google.pubsub.services;
1818

1919
import org.apache.camel.test.infra.common.services.SimpleTestServiceBuilder;
20+
import org.apache.camel.test.infra.common.services.SingletonService;
2021

2122
public final class GooglePubSubServiceFactory {
23+
24+
private static class SingletonGooglePubSubService extends SingletonService<GooglePubSubService>
25+
implements GooglePubSubService {
26+
public SingletonGooglePubSubService(GooglePubSubService service, String name) {
27+
super(service, name);
28+
}
29+
30+
@Override
31+
public String getServiceAddress() {
32+
return getService().getServiceAddress();
33+
}
34+
}
35+
2236
private GooglePubSubServiceFactory() {
2337

2438
}
@@ -34,6 +48,21 @@ public static GooglePubSubService createService() {
3448
.build();
3549
}
3650

51+
public static GooglePubSubService createSingletonService() {
52+
return SingletonServiceHolder.INSTANCE;
53+
}
54+
55+
private static class SingletonServiceHolder {
56+
static final GooglePubSubService INSTANCE;
57+
static {
58+
SimpleTestServiceBuilder<GooglePubSubService> instance = builder();
59+
instance.addLocalMapping(
60+
() -> new SingletonGooglePubSubService(new GooglePubSubLocalContainerService(), "google"))
61+
.addRemoteMapping(GooglePubSubRemoteService::new);
62+
INSTANCE = instance.build();
63+
}
64+
}
65+
3766
public static class GooglePubSubLocalContainerService extends GooglePubSubLocalContainerInfraService
3867
implements GooglePubSubService {
3968
}

test-infra/camel-test-infra-hashicorp-vault/src/main/java/org/apache/camel/test/infra/hashicorp/vault/services/HashicorpServiceFactory.java

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,32 @@
1717
package org.apache.camel.test.infra.hashicorp.vault.services;
1818

1919
import org.apache.camel.test.infra.common.services.SimpleTestServiceBuilder;
20+
import org.apache.camel.test.infra.common.services.SingletonService;
2021

2122
public final class HashicorpServiceFactory {
23+
24+
private static class SingletonHashicorpVaultService extends SingletonService<HashicorpVaultService>
25+
implements HashicorpVaultService {
26+
public SingletonHashicorpVaultService(HashicorpVaultService service, String name) {
27+
super(service, name);
28+
}
29+
30+
@Override
31+
public String token() {
32+
return getService().token();
33+
}
34+
35+
@Override
36+
public int port() {
37+
return getService().port();
38+
}
39+
40+
@Override
41+
public String host() {
42+
return getService().host();
43+
}
44+
}
45+
2246
private HashicorpServiceFactory() {
2347

2448
}
@@ -33,6 +57,20 @@ public static HashicorpVaultService createService() {
3357
.build();
3458
}
3559

60+
public static HashicorpVaultService createSingletonService() {
61+
return SingletonServiceHolder.INSTANCE;
62+
}
63+
64+
private static class SingletonServiceHolder {
65+
static final HashicorpVaultService INSTANCE;
66+
static {
67+
SimpleTestServiceBuilder<HashicorpVaultService> instance = builder();
68+
instance.addLocalMapping(
69+
() -> new SingletonHashicorpVaultService(new HashicorpVaultLocalContainerService(), "hashicorp-vault"));
70+
INSTANCE = instance.build();
71+
}
72+
}
73+
3674
public static class HashicorpVaultLocalContainerService extends HashicorpVaultLocalContainerInfraService
3775
implements HashicorpVaultService {
3876
}

0 commit comments

Comments
 (0)