Skip to content

Commit eefbe52

Browse files
authored
Merge pull request #392 from weaviate/v6-fix-async-handle
v6: fix async toolchain
2 parents cbafc67 + 86f20b6 commit eefbe52

3 files changed

Lines changed: 38 additions & 4 deletions

File tree

src/it/java/io/weaviate/integration/SearchITest.java

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import java.util.HashMap;
77
import java.util.List;
88
import java.util.Map;
9+
import java.util.concurrent.ExecutionException;
910

1011
import org.assertj.core.api.Assertions;
1112
import org.assertj.core.api.InstanceOfAssertFactories;
@@ -258,7 +259,7 @@ public void testFetchObjectsWithFilters() throws IOException {
258259
}
259260

260261
@Test
261-
public void testBm25() throws IOException {
262+
public void testBm25() throws IOException, InterruptedException, ExecutionException {
262263
var nsWords = ns("Words");
263264

264265
client.collections.create(nsWords,
@@ -281,4 +282,37 @@ public void testBm25() throws IOException {
281282
.extracting(WeaviateObject::metadata).extracting(QueryMetadata::uuid)
282283
.containsOnly(want.metadata().uuid());
283284
}
285+
286+
/**
287+
* Minimal test to verify async functionality works as expected.
288+
* We will extend our testing framework at a later stage to automatically
289+
* test both sync/async clients.
290+
*/
291+
@Test
292+
public void testBm25_async() throws IOException, InterruptedException, ExecutionException {
293+
var nsWords = ns("Words");
294+
295+
try (final var async = client.async()) {
296+
async.collections.create(nsWords,
297+
collection -> collection
298+
.properties(
299+
Property.text("relevant"),
300+
Property.text("irrelevant")))
301+
.get();
302+
303+
var words = async.collections.use(nsWords);
304+
305+
/* notWant */ words.data.insert(Map.of("relevant", "elefant", "irrelevant", "dollar bill")).get();
306+
var want = words.data.insert(Map.of("relevant", "a dime a dollar", "irrelevant", "euro")).get();
307+
308+
var dollarWorlds = words.query.bm25(
309+
"dollar",
310+
bm25 -> bm25.queryProperties("relevant")).get();
311+
312+
Assertions.assertThat(dollarWorlds.objects())
313+
.hasSize(1)
314+
.extracting(WeaviateObject::metadata).extracting(QueryMetadata::uuid)
315+
.containsOnly(want.metadata().uuid());
316+
}
317+
}
284318
}

src/main/java/io/weaviate/client6/v1/api/collections/WeaviateCollectionsClientAsync.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ public WeaviateCollectionsClientAsync(RestTransport restTransport, GrpcTransport
1919
this.grpcTransport = grpcTransport;
2020
}
2121

22-
public CollectionHandle<Map<String, Object>> use(String collectionName) {
23-
return new CollectionHandle<>(restTransport, grpcTransport,
22+
public CollectionHandleAsync<Map<String, Object>> use(String collectionName) {
23+
return new CollectionHandleAsync<>(restTransport, grpcTransport,
2424
CollectionDescriptor.ofMap(collectionName));
2525
}
2626

src/main/java/io/weaviate/client6/v1/internal/rest/DefaultRestTransport.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public void cancelled() {
8383

8484
});
8585
// FIXME: we need to differentiate between "no body" and "soumething's wrong"
86-
return completable.thenApply(r -> r.getBody() == null
86+
return completable.thenApply(r -> r.getBody() != null
8787
? endpoint.deserializeResponse(gson, r.getBody().getBodyText())
8888
: null);
8989
}

0 commit comments

Comments
 (0)