Skip to content

Commit 4581d5e

Browse files
authored
Add data plane tests for serverless index (#83)
## Problem Not all of the dataplane operations for serverless index are covered as a part of current test suite. ## Solution Add integration and error tests for data plane operations for serverless index. As a part of this PR, I have added: 1. Error tests for query and upsert data plane operations. 2. Integration tests for all data plane operations for both async and blocking stubs. ## Type of Change - [ ] Bug fix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected) - [ ] This change requires a documentation update - [ ] Infrastructure change (CI configs, etc) - [ ] Non-code change (docs, etc) - [X] None of the above: Added more tests ## Test Plan Ran integration tests locally and on CI
1 parent 7a26bde commit 4581d5e

7 files changed

+1045
-134
lines changed

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

-120
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
package io.pinecone.integration.dataPlane;
2+
3+
import com.google.common.util.concurrent.ListenableFuture;
4+
import io.grpc.StatusRuntimeException;
5+
import io.pinecone.clients.AsyncIndex;
6+
import io.pinecone.clients.Index;
7+
import io.pinecone.configs.PineconeConnection;
8+
import io.pinecone.exceptions.PineconeValidationException;
9+
import io.pinecone.helpers.RandomStringBuilder;
10+
import io.pinecone.proto.DescribeIndexStatsResponse;
11+
import io.pinecone.proto.VectorServiceGrpc;
12+
import io.pinecone.unsigned_indices_model.QueryResponseWithUnsignedIndices;
13+
import org.junit.jupiter.api.BeforeAll;
14+
import org.junit.jupiter.api.Disabled;
15+
import org.junit.jupiter.api.Test;
16+
17+
import java.io.IOException;
18+
import java.util.Arrays;
19+
import java.util.List;
20+
import java.util.concurrent.ExecutionException;
21+
import java.util.concurrent.TimeUnit;
22+
import java.util.concurrent.TimeoutException;
23+
24+
import static io.pinecone.helpers.BuildUpsertRequest.generateSparseIndicesByDimension;
25+
import static io.pinecone.helpers.BuildUpsertRequest.generateVectorValuesByDimension;
26+
import static org.junit.jupiter.api.Assertions.*;
27+
import static org.mockito.Mockito.mock;
28+
import static org.mockito.Mockito.when;
29+
30+
public class QueryErrorTest {
31+
32+
private static Index index;
33+
private static AsyncIndex asyncIndex;
34+
35+
@BeforeAll
36+
public static void setUp() throws IOException, InterruptedException {
37+
PineconeConnection connectionMock = mock(PineconeConnection.class);
38+
39+
VectorServiceGrpc.VectorServiceBlockingStub stubMock = mock(VectorServiceGrpc.VectorServiceBlockingStub.class);
40+
VectorServiceGrpc.VectorServiceFutureStub asyncStubMock = mock(VectorServiceGrpc.VectorServiceFutureStub.class);
41+
42+
when(connectionMock.getBlockingStub()).thenReturn(stubMock);
43+
when(connectionMock.getFutureStub()).thenReturn(asyncStubMock);
44+
45+
index = new Index(connectionMock);
46+
asyncIndex = new AsyncIndex(connectionMock);
47+
}
48+
49+
@Test
50+
public void queryWithVectorAndIdSyncTest() {
51+
List<Float> values = generateVectorValuesByDimension(3);
52+
try {
53+
index.query(5, values, null, null, "some_vector_id", "namespace", null, true, true);
54+
55+
fail("Expected to throw PineconeValidationException");
56+
} catch (PineconeValidationException expected) {
57+
assertTrue(expected.getLocalizedMessage().contains("Cannot query with both vector id and vector values."));
58+
}
59+
}
60+
61+
@Test
62+
public void queryWithNullSparseIndicesNotNullSparseValuesSyncTest() {
63+
List<Float> sparseValues = generateVectorValuesByDimension(3);
64+
65+
try {
66+
index.query(5, null, null, sparseValues, "some_vector_id", "namespace", null, false, false);
67+
68+
fail("Expected to throw PineconeValidationException");
69+
} catch (PineconeValidationException expected) {
70+
assertTrue(expected.getLocalizedMessage().contains("ensure that both sparse indices and values are present"));
71+
}
72+
}
73+
74+
@Test
75+
public void queryWithNotNullSparseIndicesNullSparseValuesSyncTest() {
76+
List<Long> sparseIndices = generateSparseIndicesByDimension(3);
77+
78+
try {
79+
index.query(5, null, sparseIndices, null, "some_vector_id", "namespace", null, false, false);
80+
81+
fail("Expected to throw PineconeValidationException");
82+
} catch (PineconeValidationException expected) {
83+
assertTrue(expected.getLocalizedMessage().contains("ensure that both sparse indices and values are present"));
84+
}
85+
}
86+
87+
@Test
88+
public void queryWithVectorAndIdFutureTest() {
89+
List<Float> values = generateVectorValuesByDimension(3);
90+
try {
91+
index.query(5, values, null, null, "some_vector_id", "namespace", null, true, true);
92+
93+
fail("Expected to throw PineconeValidationException");
94+
} catch (PineconeValidationException expected) {
95+
assertTrue(expected.getLocalizedMessage().contains("Cannot query with both vector id and vector values."));
96+
}
97+
}
98+
99+
@Test
100+
public void queryWithNullSparseIndicesNotNullSparseValuesFutureTest() {
101+
List<Float> sparseValues = generateVectorValuesByDimension(3);
102+
103+
try {
104+
asyncIndex.query(5, null, null, sparseValues, "some_vector_id", "namespace", null, false, false);
105+
106+
fail("Expected to throw PineconeValidationException");
107+
} catch (PineconeValidationException expected) {
108+
assertTrue(expected.getLocalizedMessage().contains("ensure that both sparse indices and values are present"));
109+
}
110+
}
111+
112+
@Test
113+
public void queryWithNotNullSparseIndicesNullSparseValuesFutureTest() {
114+
List<Long> sparseIndices = generateSparseIndicesByDimension(3);
115+
116+
try {
117+
asyncIndex.query(5, null, sparseIndices, null, "some_vector_id", "namespace", null, false, false);
118+
119+
fail("Expected to throw PineconeValidationException");
120+
} catch (PineconeValidationException expected) {
121+
assertTrue(expected.getLocalizedMessage().contains("ensure that both sparse indices and values are present"));
122+
}
123+
}
124+
}

0 commit comments

Comments
 (0)