25
25
import java .io .File ;
26
26
import java .net .URI ;
27
27
import java .util .Arrays ;
28
+ import java .util .Optional ;
28
29
import java .util .Set ;
29
30
import java .util .UUID ;
30
31
import java .util .concurrent .CompletionException ;
@@ -128,11 +129,11 @@ private Object[][] allImplementations() {
128
129
// The new connection string won't be available to the test method unless a
129
130
// Supplier<String> lambda is used for providing the value.
130
131
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 )},
136
137
};
137
138
}
138
139
@@ -165,16 +166,29 @@ private synchronized String getEtcdClusterConnectString() {
165
166
return etcdCluster .clientEndpoints ().stream ().map (URI ::toString ).collect (Collectors .joining ("," ));
166
167
}
167
168
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 ));
170
178
}
171
179
172
180
// 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 > {
174
182
private final Supplier <String > supplier ;
183
+ private final Optional <String > toStringValue ;
184
+
185
+ ProviderUrlSupplier (Supplier <String > supplier ) {
186
+ this (supplier , Optional .empty ());
187
+ }
175
188
176
- public StringSupplier (Supplier <String > supplier ) {
189
+ ProviderUrlSupplier (Supplier <String > supplier , Optional < String > toStringValue ) {
177
190
this .supplier = supplier ;
191
+ this .toStringValue = toStringValue ;
178
192
}
179
193
180
194
@ Override
@@ -184,7 +198,9 @@ public String get() {
184
198
185
199
@ Override
186
200
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 );
188
204
}
189
205
}
190
206
0 commit comments