26
26
import java .io .File ;
27
27
import java .net .URI ;
28
28
import java .util .Arrays ;
29
+ import java .util .Optional ;
29
30
import java .util .Set ;
30
31
import java .util .UUID ;
31
32
import java .util .concurrent .CompletionException ;
@@ -136,12 +137,12 @@ private Object[][] allImplementations() {
136
137
// The new connection string won't be available to the test method unless a
137
138
// Supplier<String> lambda is used for providing the value.
138
139
return new Object [][]{
139
- {"ZooKeeper" , stringSupplier (() -> zksConnectionString )},
140
- {"Memory" , stringSupplier (() -> memoryConnectionString )},
141
- {"RocksDB" , stringSupplier (() -> rocksdbConnectionString )},
142
- {"Etcd" , stringSupplier (() -> "etcd:" + getEtcdClusterConnectString ())},
143
- {"Oxia" , stringSupplier (() -> "oxia://" + getOxiaServerConnectString ())},
144
- {"MockZooKeeper" , stringSupplier (() -> mockZkUrl )},
140
+ {"ZooKeeper" , providerUrlSupplier (() -> zksConnectionString )},
141
+ {"Memory" , providerUrlSupplier (() -> memoryConnectionString )},
142
+ {"RocksDB" , providerUrlSupplier (() -> rocksdbConnectionString )},
143
+ {"Etcd" , providerUrlSupplier (() -> "etcd:" + getEtcdClusterConnectString (), "etcd:..." )},
144
+ {"Oxia" , providerUrlSupplier (() -> "oxia://" + getOxiaServerConnectString (), "oxia://..." )},
145
+ {"MockZooKeeper" , providerUrlSupplier (() -> mockZkUrl )},
145
146
};
146
147
}
147
148
@@ -185,16 +186,29 @@ private synchronized String getEtcdClusterConnectString() {
185
186
return etcdCluster .clientEndpoints ().stream ().map (URI ::toString ).collect (Collectors .joining ("," ));
186
187
}
187
188
188
- public static Supplier <String > stringSupplier (Supplier <String > supplier ) {
189
- return new StringSupplier (supplier );
189
+ private static Supplier <String > providerUrlSupplier (Supplier <String > supplier ) {
190
+ return new ProviderUrlSupplier (supplier );
191
+ }
192
+
193
+ // Use this method to provide a custom toString value for the Supplier<String>. Use this when Testcontainers is used
194
+ // so that a toString call doesn't eagerly trigger container initialization which could cause a deadlock
195
+ // with Gradle Develocity Maven Extension.
196
+ private static Supplier <String > providerUrlSupplier (Supplier <String > supplier , String toStringValue ) {
197
+ return new ProviderUrlSupplier (supplier , Optional .ofNullable (toStringValue ));
190
198
}
191
199
192
200
// Implements toString() so that the test name is more descriptive
193
- private static class StringSupplier implements Supplier <String > {
201
+ private static class ProviderUrlSupplier implements Supplier <String > {
194
202
private final Supplier <String > supplier ;
203
+ private final Optional <String > toStringValue ;
204
+
205
+ ProviderUrlSupplier (Supplier <String > supplier ) {
206
+ this (supplier , Optional .empty ());
207
+ }
195
208
196
- public StringSupplier (Supplier <String > supplier ) {
209
+ ProviderUrlSupplier (Supplier <String > supplier , Optional < String > toStringValue ) {
197
210
this .supplier = supplier ;
211
+ this .toStringValue = toStringValue ;
198
212
}
199
213
200
214
@ Override
@@ -204,7 +218,9 @@ public String get() {
204
218
205
219
@ Override
206
220
public String toString () {
207
- return get ();
221
+ // toStringValue is used to prevent deadlocks which could occur if toString method call eagerly triggers
222
+ // Testcontainers initialization. This is the case when Gradle Develocity Maven Extension is used.
223
+ return toStringValue .orElseGet (this ::get );
208
224
}
209
225
}
210
226
0 commit comments