@@ -21,25 +21,15 @@ public class Weaviate extends WeaviateContainer {
2121
2222 private volatile SharedClient clientInstance ;
2323
24- public WeaviateClient getClient () {
25- return getClient (ObjectBuilder .identity ());
26- }
27-
2824 /**
2925 * Create a new instance of WeaviateClient connected to this container if none
3026 * exist. Get an existing client otherwise.
3127 *
3228 * The lifetime of this client is tied to that of its container, which means
3329 * that you do not need to {@code close} it manually. It will only truly close
3430 * after the parent Testcontainer is stopped.
35- *
36- * FIXME: we cannot return the same client for 2 different sets of
37- * configurations.
38- * What we should do is: {@link #getClient()} returns the shared client, while
39- * this one always constructs a new instance.
40- * Otherwise we'll get a race condition once the tests are parallelized.
4131 */
42- public WeaviateClient getClient (Function < Config . Custom , ObjectBuilder < Config >> fn ) {
32+ public WeaviateClient getClient () {
4333 if (!isRunning ()) {
4434 start ();
4535 }
@@ -49,19 +39,8 @@ public WeaviateClient getClient(Function<Config.Custom, ObjectBuilder<Config>> f
4939
5040 synchronized (this ) {
5141 if (clientInstance == null ) {
52- var host = getHost ();
53- var customFn = ObjectBuilder .partial (fn ,
54- conn -> conn
55- .scheme ("http" )
56- .httpHost (host )
57- .grpcHost (host )
58- .httpPort (getMappedPort (8080 ))
59- .grpcPort (getMappedPort (50051 )));
60- var config = customFn .apply (new Config .Custom ()).build ();
61- if (config .authentication () != null ) {
62- }
6342 try {
64- clientInstance = new SharedClient (config , this );
43+ clientInstance = new SharedClient (Config . of ( defaultConfigFn ()) , this );
6544 } catch (Exception e ) {
6645 throw new RuntimeException ("create WeaviateClient for Weaviate container" , e );
6746 }
@@ -75,19 +54,26 @@ public WeaviateClient getClient(Function<Config.Custom, ObjectBuilder<Config>> f
7554 * Prefer using {@link #getClient} unless your test needs the initialization
7655 * steps to run, e.g. OIDC authorization grant exchange.
7756 */
78- public WeaviateClient getNewClient (Function <Config .Custom , ObjectBuilder <Config >> fn ) {
57+ public WeaviateClient getClient (Function <Config .Custom , ObjectBuilder <Config >> fn ) {
7958 if (!isRunning ()) {
8059 start ();
8160 }
61+
62+ var customFn = ObjectBuilder .partial (fn , defaultConfigFn ());
63+ var config = customFn .apply (new Config .Custom ()).build ();
64+ try {
65+ return new WeaviateClient (config );
66+ } catch (Exception e ) {
67+ throw new RuntimeException ("create WeaviateClient for Weaviate container" , e );
68+ }
69+ }
70+
71+ private Function <Config .Custom , ObjectBuilder <Config >> defaultConfigFn () {
8272 var host = getHost ();
83- var customFn = ObjectBuilder .partial (fn ,
84- conn -> conn
85- .scheme ("http" )
86- .httpHost (host )
87- .grpcHost (host )
88- .httpPort (getMappedPort (8080 ))
89- .grpcPort (getMappedPort (50051 )));
90- return WeaviateClient .connectToCustom (customFn );
73+ return conn -> conn
74+ .scheme ("http" )
75+ .httpHost (host ).httpPort (getMappedPort (8080 ))
76+ .grpcHost (host ).grpcPort (getMappedPort (50051 ));
9177 }
9278
9379 public static Weaviate createDefault () {
0 commit comments