diff --git a/src/it/java/io/weaviate/integration/SearchITest.java b/src/it/java/io/weaviate/integration/SearchITest.java index fe6dbc63a..2c895a906 100644 --- a/src/it/java/io/weaviate/integration/SearchITest.java +++ b/src/it/java/io/weaviate/integration/SearchITest.java @@ -6,6 +6,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.concurrent.ExecutionException; import org.assertj.core.api.Assertions; import org.assertj.core.api.InstanceOfAssertFactories; @@ -258,7 +259,7 @@ public void testFetchObjectsWithFilters() throws IOException { } @Test - public void testBm25() throws IOException { + public void testBm25() throws IOException, InterruptedException, ExecutionException { var nsWords = ns("Words"); client.collections.create(nsWords, @@ -281,4 +282,37 @@ public void testBm25() throws IOException { .extracting(WeaviateObject::metadata).extracting(QueryMetadata::uuid) .containsOnly(want.metadata().uuid()); } + + /** + * Minimal test to verify async functionality works as expected. + * We will extend our testing framework at a later stage to automatically + * test both sync/async clients. + */ + @Test + public void testBm25_async() throws IOException, InterruptedException, ExecutionException { + var nsWords = ns("Words"); + + try (final var async = client.async()) { + async.collections.create(nsWords, + collection -> collection + .properties( + Property.text("relevant"), + Property.text("irrelevant"))) + .get(); + + var words = async.collections.use(nsWords); + + /* notWant */ words.data.insert(Map.of("relevant", "elefant", "irrelevant", "dollar bill")).get(); + var want = words.data.insert(Map.of("relevant", "a dime a dollar", "irrelevant", "euro")).get(); + + var dollarWorlds = words.query.bm25( + "dollar", + bm25 -> bm25.queryProperties("relevant")).get(); + + Assertions.assertThat(dollarWorlds.objects()) + .hasSize(1) + .extracting(WeaviateObject::metadata).extracting(QueryMetadata::uuid) + .containsOnly(want.metadata().uuid()); + } + } } diff --git a/src/main/java/io/weaviate/client6/v1/api/collections/WeaviateCollectionsClientAsync.java b/src/main/java/io/weaviate/client6/v1/api/collections/WeaviateCollectionsClientAsync.java index 14f900484..e90f7d6d4 100644 --- a/src/main/java/io/weaviate/client6/v1/api/collections/WeaviateCollectionsClientAsync.java +++ b/src/main/java/io/weaviate/client6/v1/api/collections/WeaviateCollectionsClientAsync.java @@ -19,8 +19,8 @@ public WeaviateCollectionsClientAsync(RestTransport restTransport, GrpcTransport this.grpcTransport = grpcTransport; } - public CollectionHandle> use(String collectionName) { - return new CollectionHandle<>(restTransport, grpcTransport, + public CollectionHandleAsync> use(String collectionName) { + return new CollectionHandleAsync<>(restTransport, grpcTransport, CollectionDescriptor.ofMap(collectionName)); } diff --git a/src/main/java/io/weaviate/client6/v1/internal/rest/DefaultRestTransport.java b/src/main/java/io/weaviate/client6/v1/internal/rest/DefaultRestTransport.java index f2b12f3b3..99206aac4 100644 --- a/src/main/java/io/weaviate/client6/v1/internal/rest/DefaultRestTransport.java +++ b/src/main/java/io/weaviate/client6/v1/internal/rest/DefaultRestTransport.java @@ -83,7 +83,7 @@ public void cancelled() { }); // FIXME: we need to differentiate between "no body" and "soumething's wrong" - return completable.thenApply(r -> r.getBody() == null + return completable.thenApply(r -> r.getBody() != null ? endpoint.deserializeResponse(gson, r.getBody().getBodyText()) : null); }