2525import java .io .File ;
2626import java .net .URI ;
2727import java .util .Arrays ;
28+ import java .util .Optional ;
2829import java .util .Set ;
2930import java .util .UUID ;
3031import java .util .concurrent .CompletionException ;
@@ -128,11 +129,11 @@ private Object[][] allImplementations() {
128129 // The new connection string won't be available to the test method unless a
129130 // Supplier<String> lambda is used for providing the value.
130131 return new Object [][]{
131- {"ZooKeeper" , stringSupplier (() -> zksConnectionString )},
132- {"Memory" , stringSupplier (() -> memoryConnectionString )},
133- {"RocksDB" , stringSupplier (() -> rocksdbConnectionString )},
134- {"Etcd" , stringSupplier (() -> "etcd:" + getEtcdClusterConnectString ())},
135- {"MockZooKeeper" , stringSupplier (() -> mockZkUrl )},
132+ {"ZooKeeper" , providerUrlSupplier (() -> zksConnectionString )},
133+ {"Memory" , providerUrlSupplier (() -> memoryConnectionString )},
134+ {"RocksDB" , providerUrlSupplier (() -> rocksdbConnectionString )},
135+ {"Etcd" , providerUrlSupplier (() -> "etcd:" + getEtcdClusterConnectString (), "etcd:..." )},
136+ {"MockZooKeeper" , providerUrlSupplier (() -> mockZkUrl )},
136137 };
137138 }
138139
@@ -165,16 +166,29 @@ private synchronized String getEtcdClusterConnectString() {
165166 return etcdCluster .clientEndpoints ().stream ().map (URI ::toString ).collect (Collectors .joining ("," ));
166167 }
167168
168- public static Supplier <String > stringSupplier (Supplier <String > supplier ) {
169- return new StringSupplier (supplier );
169+ private static Supplier <String > providerUrlSupplier (Supplier <String > supplier ) {
170+ return new ProviderUrlSupplier (supplier );
171+ }
172+
173+ // Use this method to provide a custom toString value for the Supplier<String>. Use this when Testcontainers is used
174+ // so that a toString call doesn't eagerly trigger container initialization which could cause a deadlock
175+ // with Gradle Develocity Maven Extension.
176+ private static Supplier <String > providerUrlSupplier (Supplier <String > supplier , String toStringValue ) {
177+ return new ProviderUrlSupplier (supplier , Optional .ofNullable (toStringValue ));
170178 }
171179
172180 // Implements toString() so that the test name is more descriptive
173- private static class StringSupplier implements Supplier <String > {
181+ private static class ProviderUrlSupplier implements Supplier <String > {
174182 private final Supplier <String > supplier ;
183+ private final Optional <String > toStringValue ;
184+
185+ ProviderUrlSupplier (Supplier <String > supplier ) {
186+ this (supplier , Optional .empty ());
187+ }
175188
176- public StringSupplier (Supplier <String > supplier ) {
189+ ProviderUrlSupplier (Supplier <String > supplier , Optional < String > toStringValue ) {
177190 this .supplier = supplier ;
191+ this .toStringValue = toStringValue ;
178192 }
179193
180194 @ Override
@@ -184,7 +198,9 @@ public String get() {
184198
185199 @ Override
186200 public String toString () {
187- return get ();
201+ // toStringValue is used to prevent deadlocks which could occur if toString method call eagerly triggers
202+ // Testcontainers initialization. This is the case when Gradle Develocity Maven Extension is used.
203+ return toStringValue .orElseGet (this ::get );
188204 }
189205 }
190206
0 commit comments