Skip to content

Commit 5543580

Browse files
handle future listenables properly in error tests
1 parent c5f4e16 commit 5543580

File tree

2 files changed

+25
-12
lines changed

2 files changed

+25
-12
lines changed

src/integration/java/io/pinecone/integration/dataPlane/QueryErrorPodTest.java

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
package io.pinecone.integration.dataPlane;
22

3+
import com.google.common.util.concurrent.ListenableFuture;
34
import io.grpc.StatusRuntimeException;
45
import io.pinecone.clients.Index;
56
import io.pinecone.clients.Pinecone;
67
import io.pinecone.clients.AsyncIndex;
78
import io.pinecone.exceptions.PineconeValidationException;
89
import io.pinecone.helpers.RandomStringBuilder;
910
import io.pinecone.proto.*;
11+
import io.pinecone.unsigned_indices_model.QueryResponseWithUnsignedIndices;
1012
import org.junit.jupiter.api.BeforeAll;
1113
import org.junit.jupiter.api.Test;
1214
import org.openapitools.client.model.IndexModelSpec;
@@ -16,6 +18,8 @@
1618
import java.util.Arrays;
1719
import java.util.List;
1820
import java.util.concurrent.ExecutionException;
21+
import java.util.concurrent.TimeUnit;
22+
import java.util.concurrent.TimeoutException;
1923

2024
import static io.pinecone.helpers.BuildUpsertRequest.*;
2125
import static io.pinecone.helpers.IndexManager.createIndexIfNotExistsDataPlane;
@@ -76,15 +80,16 @@ public void QueryWithNullSparseIndicesNotNullSparseValuesSyncTest() {
7680
}
7781

7882
@Test
79-
public void queryWithIncorrectVectorDimensionFuture() throws ExecutionException, InterruptedException {
83+
public void queryWithIncorrectVectorDimensionFuture() throws ExecutionException, InterruptedException, TimeoutException {
8084
String namespace = RandomStringBuilder.build("ns", 8);
8185
DescribeIndexStatsResponse describeIndexStatsResponse1 = asyncIndexClient.describeIndexStats(null).get();
8286
assertEquals(describeIndexStatsResponse1.getDimension(), dimension);
8387

8488
// Query with incorrect dimensions
8589
try {
8690
List<Float> vector = Arrays.asList(100F);
87-
asyncIndexClient.query(5, vector, null, null, null, namespace, null, true, true).get();
91+
ListenableFuture<QueryResponseWithUnsignedIndices> queryFuture = asyncIndexClient.query(5, vector, null, null, null, namespace, null, true, true);
92+
queryFuture.get(10, TimeUnit.SECONDS);
8893

8994
fail("queryWithIncorrectVectorDimensionFuture should have thrown ExecutionException");
9095
} catch (ExecutionException expected) {
@@ -94,20 +99,22 @@ public void queryWithIncorrectVectorDimensionFuture() throws ExecutionException,
9499
}
95100

96101
@Test
97-
public void QueryWithNullSparseIndicesNotNullSparseValuesFutureTest() throws ExecutionException, InterruptedException {
102+
public void QueryWithNullSparseIndicesNotNullSparseValuesFutureTest() throws ExecutionException, InterruptedException, TimeoutException {
98103
String id = RandomStringBuilder.build(3);
99104

100105
try {
101-
asyncIndexClient.update(id,
106+
ListenableFuture<UpdateResponse> updateFuture = asyncIndexClient.update(id,
102107
generateVectorValuesByDimension(dimension),
103108
null,
104109
null,
105110
null,
106-
generateVectorValuesByDimension(dimension)).get();
111+
generateVectorValuesByDimension(dimension));
112+
113+
updateFuture.get(10, TimeUnit.SECONDS);
107114

108115
fail("QueryWithNullSparseIndicesNotNullSparseValuesFutureTest should have thrown PineconeValidationException");
109116
} catch (PineconeValidationException expected) {
110-
assertEquals(expected.getLocalizedMessage(), "ensure that both sparse indices and values are present");
117+
assertTrue(expected.getLocalizedMessage().contains("ensure that both sparse indices and values are present"));
111118
}
112119
}
113120
}

src/integration/java/io/pinecone/integration/dataPlane/UpdateFetchAndQueryPodTest.java

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package io.pinecone.integration.dataPlane;
22

3+
import com.google.common.util.concurrent.ListenableFuture;
34
import com.google.protobuf.Struct;
45
import com.google.protobuf.Value;
56
import io.grpc.StatusRuntimeException;
@@ -21,6 +22,8 @@
2122
import java.util.HashMap;
2223
import java.util.List;
2324
import java.util.concurrent.ExecutionException;
25+
import java.util.concurrent.TimeUnit;
26+
import java.util.concurrent.TimeoutException;
2427

2528
import static io.pinecone.helpers.AssertRetry.assertWithRetry;
2629
import static io.pinecone.helpers.BuildUpsertRequest.*;
@@ -259,7 +262,7 @@ public void updateNullSparseIndicesNotNullSparseValuesSyncTest() {
259262

260263
fail("updateNullSparseIndicesNotNullSparseValuesSyncTest should have thrown PineconeValidationException");
261264
} catch (PineconeValidationException expected) {
262-
assertEquals(expected.getLocalizedMessage(), "ensure that both sparse indices and values are present");
265+
assertTrue(expected.getLocalizedMessage().contains("ensure that both sparse indices and values are present"));
263266
}
264267
}
265268

@@ -385,7 +388,7 @@ public void updateAllParamsFetchAndQueryFutureTest() throws InterruptedException
385388
}
386389

387390
@Test
388-
public void addIncorrectDimensionalValuesFutureTest() throws InterruptedException {
391+
public void addIncorrectDimensionalValuesFutureTest() throws ExecutionException, InterruptedException, TimeoutException {
389392
// Upsert vectors with required parameters
390393
int numOfVectors = 3;
391394
String namespace = RandomStringBuilder.build("ns", 8);
@@ -412,7 +415,8 @@ public void addIncorrectDimensionalValuesFutureTest() throws InterruptedExceptio
412415

413416
// Should fail since only 1 value is added for the vector of dimension 3
414417
try {
415-
asyncIndexClient.update(idToUpdate, updatedValues, null, namespace, null, null);
418+
ListenableFuture<UpdateResponse> updateFuture = asyncIndexClient.update(idToUpdate, updatedValues, null, namespace, null, null);
419+
updateFuture.get(10, TimeUnit.SECONDS);
416420

417421
fail("addIncorrectDimensionalValuesFutureTest should have thrown StatusRuntimeException");
418422
} catch (StatusRuntimeException expected) {
@@ -466,20 +470,22 @@ public void queryWithFilersFutureTest() throws ExecutionException, InterruptedEx
466470
}
467471

468472
@Test
469-
public void updateNullSparseIndicesNotNullSparseValuesFutureTest() {
473+
public void updateNullSparseIndicesNotNullSparseValuesFutureTest() throws ExecutionException, InterruptedException, TimeoutException {
470474
String id = RandomStringBuilder.build(3);
471475

472476
try {
473-
asyncIndexClient.update(id,
477+
ListenableFuture<UpdateResponse> updateFuture = asyncIndexClient.update(id,
474478
generateVectorValuesByDimension(dimension),
475479
null,
476480
null,
477481
null,
478482
generateVectorValuesByDimension(dimension));
483+
updateFuture.get(10, TimeUnit.SECONDS);
484+
479485

480486
fail("updateNullSparseIndicesNotNullSparseValuesFutureTest should have thrown PineconeValidationException");
481487
} catch (PineconeValidationException expected) {
482-
assertEquals(expected.getLocalizedMessage(), "ensure that both sparse indices and values are present");
488+
assertTrue(expected.getLocalizedMessage().contains("ensure that both sparse indices and values are present"));
483489
}
484490
}
485491
}

0 commit comments

Comments
 (0)