Skip to content

Commit 50fd99a

Browse files
refine how we handle failures of future operations
1 parent 5543580 commit 50fd99a

File tree

6 files changed

+33
-26
lines changed

6 files changed

+33
-26
lines changed

src/integration/java/io/pinecone/integration/controlPlane/pod/CollectionTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ public void testCreateCollectionFromInvalidIndex() {
186186
CreateCollectionRequest createCollectionRequest = new CreateCollectionRequest().name(RandomStringBuilder.build("coll1", 8)).source("invalid-index");
187187
pineconeClient.createCollection(createCollectionRequest);
188188

189-
fail("testCreateCollectionFromInvalidIndex should have thrown PineconeException");
189+
fail("Expected to throw PineconeException");
190190
} catch (PineconeException expected) {
191191
assertTrue(expected.getMessage().contains("invalid-index not found"));
192192
}
@@ -199,7 +199,7 @@ public void testIndexFromNonExistentCollection() {
199199
CreateIndexRequest newCreateIndexRequest = new CreateIndexRequest().name(RandomStringBuilder.build("from-nonexistent-coll", 8)).dimension(dimension).metric(IndexMetric.COSINE).spec(spec);
200200
pineconeClient.createIndex(newCreateIndexRequest);
201201

202-
fail("testIndexFromNonExistentCollection should have thrown PineconeException");
202+
fail("Expected to throw PineconeException");
203203
} catch (PineconeException expected) {
204204
assertTrue(expected.getMessage().contains("non-existent-collection not found"));
205205
}
@@ -230,7 +230,7 @@ public void testCreateIndexInMismatchedEnvironment() {
230230
CreateIndexRequest createIndexRequest = new CreateIndexRequest().name(RandomStringBuilder.build("from-coll", 8)).dimension(dimension).metric(IndexMetric.COSINE).spec(spec);
231231
pineconeClient.createIndex(createIndexRequest);
232232

233-
fail("testCreateIndexInMismatchedEnvironment should have thrown PineconeException");
233+
fail("Expected to throw PineconeException");
234234
} catch (PineconeException expected) {
235235
assertTrue(expected.getMessage().contains("collection must be in the same environment as the index"));
236236
}
@@ -245,7 +245,7 @@ public void testCreateIndexWithMismatchedDimension() {
245245
CreateIndexRequest createIndexRequest = new CreateIndexRequest().name(RandomStringBuilder.build("from-coll", 8)).dimension(dimension + 1).metric(IndexMetric.COSINE).spec(spec);
246246
pineconeClient.createIndex(createIndexRequest);
247247

248-
fail("testCreateIndexWithMismatchedDimension should have thrown PineconeException");
248+
fail("Expected to throw PineconeException");
249249
} catch (PineconeException expected) {
250250
assertTrue(expected.getMessage().contains("collection must have the same dimension"));
251251
}
@@ -263,7 +263,7 @@ public void testCreateCollectionFromNotReadyIndex() throws InterruptedException
263263
indexesToCleanUp.add(notReadyIndexName);
264264
createCollection(pineconeClient, newCollectionName, notReadyIndexName, false);
265265

266-
fail("testCreateCollectionFromNotReadyIndex should have thrown PineconeException");
266+
fail("Expected to throw PineconeException");
267267
} catch (PineconeException expected) {
268268
assertTrue(expected.getMessage().contains("index is not ready"));
269269
}

src/integration/java/io/pinecone/integration/controlPlane/pod/ConfigureIndexTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public void configureIndexWithInvalidIndexName() {
4444
try {
4545
controlPlaneClient.configureIndex("non-existent-index", configureIndexRequest);
4646

47-
fail("configureIndexWithInvalidIndexName should have thrown PineconeNotFoundException");
47+
fail("Expected to throw PineconeNotFoundException");
4848
} catch (PineconeNotFoundException expected) {
4949
assertTrue(expected.getLocalizedMessage().toLowerCase().contains("not found"));
5050
}
@@ -58,7 +58,7 @@ public void configureIndexExceedingQuota() {
5858
try {
5959
controlPlaneClient.configureIndex(indexName, configureIndexRequest);
6060

61-
fail("configureIndexExceedingQuota should have thrown PineconeForbiddenException");
61+
fail("Expected to throw PineconeForbiddenException");
6262
} catch (PineconeForbiddenException expected) {
6363
assertTrue(expected.getLocalizedMessage().contains("quota"));
6464
}
@@ -112,7 +112,7 @@ public void changingBasePodType() throws InterruptedException {
112112
ConfigureIndexRequest configureIndexRequest = new ConfigureIndexRequest().spec(spec);
113113
controlPlaneClient.configureIndex(indexName, configureIndexRequest);
114114

115-
fail("changingBasePodType should have thrown PineconeBadRequestException");
115+
fail("Expected to throw PineconeBadRequestException");
116116
} catch (PineconeBadRequestException expected) {
117117
assertTrue(expected.getMessage().contains("change pod"));
118118
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public void queryWithIncorrectVectorDimensionSync() {
5454
List<Float> vector = Arrays.asList(100F);
5555
indexClient.query(5, vector, null, null, null, namespace, null, true, true);
5656

57-
fail("queryWithIncorrectVectorDimensionSync should have thrown StatusRuntimeException");
57+
fail("Expected to throw StatusRuntimeException");
5858
} catch (StatusRuntimeException expected) {
5959
assertTrue(expected.getLocalizedMessage().contains("grpc-status=3"));
6060
assertTrue(expected.getLocalizedMessage().contains("grpc-message=Query vector dimension 1 does not match the dimension of the index 3"));
@@ -73,7 +73,7 @@ public void QueryWithNullSparseIndicesNotNullSparseValuesSyncTest() {
7373
null,
7474
generateVectorValuesByDimension(dimension));
7575

76-
fail("QueryWithNullSparseIndicesNotNullSparseValuesSyncTest should have thrown PineconeValidationException");
76+
fail("Expected to throw PineconeValidationException");
7777
} catch (PineconeValidationException expected) {
7878
assertTrue(expected.getLocalizedMessage().contains( "ensure that both sparse indices and values are present"));
7979
}
@@ -91,7 +91,7 @@ public void queryWithIncorrectVectorDimensionFuture() throws ExecutionException,
9191
ListenableFuture<QueryResponseWithUnsignedIndices> queryFuture = asyncIndexClient.query(5, vector, null, null, null, namespace, null, true, true);
9292
queryFuture.get(10, TimeUnit.SECONDS);
9393

94-
fail("queryWithIncorrectVectorDimensionFuture should have thrown ExecutionException");
94+
fail("Expected to throw ExecutionException");
9595
} catch (ExecutionException expected) {
9696
assertTrue(expected.getLocalizedMessage().contains("grpc-status=3"));
9797
assertTrue(expected.getLocalizedMessage().contains("grpc-message=Query vector dimension 1 does not match the dimension of the index 3"));
@@ -112,7 +112,7 @@ public void QueryWithNullSparseIndicesNotNullSparseValuesFutureTest() throws Exe
112112

113113
updateFuture.get(10, TimeUnit.SECONDS);
114114

115-
fail("QueryWithNullSparseIndicesNotNullSparseValuesFutureTest should have thrown PineconeValidationException");
115+
fail("Expected to throw PineconeValidationException");
116116
} catch (PineconeValidationException expected) {
117117
assertTrue(expected.getLocalizedMessage().contains("ensure that both sparse indices and values are present"));
118118
}

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

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ public void addIncorrectDimensionalValuesSyncTest() throws InterruptedException
197197
try {
198198
indexClient.update(idToUpdate, updatedValues, null, namespace, null, null);
199199

200-
fail("addIncorrectDimensionalValuesSyncTest should have thrown StatusRuntimeException");
200+
fail("Expected to throw StatusRuntimeException");
201201
} catch (StatusRuntimeException expected) {
202202
assertTrue(expected.getTrailers().toString().contains("grpc-status=3"));
203203
assertTrue(expected.getTrailers().toString().contains("dimension 1 does not match the dimension of the index 3"));
@@ -260,7 +260,7 @@ public void updateNullSparseIndicesNotNullSparseValuesSyncTest() {
260260
null,
261261
generateVectorValuesByDimension(dimension));
262262

263-
fail("updateNullSparseIndicesNotNullSparseValuesSyncTest should have thrown PineconeValidationException");
263+
fail("Expected to throw PineconeValidationException");
264264
} catch (PineconeValidationException expected) {
265265
assertTrue(expected.getLocalizedMessage().contains("ensure that both sparse indices and values are present"));
266266
}
@@ -388,7 +388,7 @@ public void updateAllParamsFetchAndQueryFutureTest() throws InterruptedException
388388
}
389389

390390
@Test
391-
public void addIncorrectDimensionalValuesFutureTest() throws ExecutionException, InterruptedException, TimeoutException {
391+
public void addIncorrectDimensionalValuesFutureTest() throws InterruptedException, TimeoutException {
392392
// Upsert vectors with required parameters
393393
int numOfVectors = 3;
394394
String namespace = RandomStringBuilder.build("ns", 8);
@@ -418,10 +418,17 @@ public void addIncorrectDimensionalValuesFutureTest() throws ExecutionException,
418418
ListenableFuture<UpdateResponse> updateFuture = asyncIndexClient.update(idToUpdate, updatedValues, null, namespace, null, null);
419419
updateFuture.get(10, TimeUnit.SECONDS);
420420

421-
fail("addIncorrectDimensionalValuesFutureTest should have thrown StatusRuntimeException");
422-
} catch (StatusRuntimeException expected) {
423-
assertTrue(expected.getTrailers().toString().contains("grpc-status=3"));
424-
assertTrue(expected.getTrailers().toString().contains("dimension 1 does not match the dimension of the index 3"));
421+
fail("Expected to throw StatusRuntimeException");
422+
} catch (ExecutionException exception) {
423+
Throwable cause = exception.getCause();
424+
425+
if (cause instanceof StatusRuntimeException) {
426+
StatusRuntimeException expected = (StatusRuntimeException) cause;
427+
assertTrue(expected.getTrailers().toString().contains("grpc-status=3"));
428+
assertTrue(expected.getTrailers().toString().contains("dimension 1 does not match the dimension of the index 3"));
429+
} else {
430+
fail("Expected to throw StatusRuntimeException, instead threw: " + cause);
431+
}
425432
}
426433
}
427434

@@ -482,9 +489,9 @@ public void updateNullSparseIndicesNotNullSparseValuesFutureTest() throws Execut
482489
generateVectorValuesByDimension(dimension));
483490
updateFuture.get(10, TimeUnit.SECONDS);
484491

485-
486-
fail("updateNullSparseIndicesNotNullSparseValuesFutureTest should have thrown PineconeValidationException");
487-
} catch (PineconeValidationException expected) {
492+
fail("Expected to throw PineconeValidationException");
493+
}
494+
catch (PineconeValidationException expected) {
488495
assertTrue(expected.getLocalizedMessage().contains("ensure that both sparse indices and values are present"));
489496
}
490497
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ public void upsertNullSparseIndicesNotNullSparseValuesSyncTest() {
113113
null,
114114
null);
115115

116-
fail("upsertNullSparseIndicesNotNullSparseValuesSyncTest should have thrown PineconeValidationException");
116+
fail("Expected to throw PineconeValidationException");
117117
} catch (PineconeValidationException expected) {
118118
assertTrue(expected.getLocalizedMessage().contains("ensure that both sparse indices and values are present"));
119119
}
@@ -195,7 +195,7 @@ public void upsertNullSparseIndicesNotNullSparseValuesFutureTest() throws Execut
195195
null,
196196
null).get();
197197

198-
fail("upsertNullSparseIndicesNotNullSparseValuesFutureTest should have thrown PineconeValidationException");
198+
fail("Expected to throw PineconeValidationException");
199199
} catch (PineconeValidationException expected) {
200200
assertTrue(expected.getLocalizedMessage().contains("ensure that both sparse indices and values are present"));
201201
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ public void upsertNullSparseIndicesNotNullSparseValuesSyncTest() {
135135
null,
136136
null);
137137

138-
fail("upsertNullSparseIndicesNotNullSparseValuesSyncTest should have thrown PineconeValidationException");
138+
fail("Expected to throw PineconeValidationException");
139139
} catch (PineconeValidationException expected) {
140140
assertTrue(expected.getLocalizedMessage().contains("ensure that both sparse indices and values are present"));
141141
}
@@ -224,7 +224,7 @@ public void upsertNullSparseIndicesNotNullSparseValuesFutureTest() throws Execut
224224
null,
225225
null).get();
226226

227-
fail("upsertNullSparseIndicesNotNullSparseValuesFutureTest should have thrown PineconeValidationException");
227+
fail("Expected to throw PineconeValidationException");
228228
} catch (PineconeValidationException expected) {
229229
assertTrue(expected.getLocalizedMessage().contains("ensure that both sparse indices and values are present"));
230230
}

0 commit comments

Comments
 (0)