From 6c11e3c808f67f22f90679db635a06e2760eb876 Mon Sep 17 00:00:00 2001 From: rohanshah18 Date: Thu, 7 Dec 2023 14:38:52 -0500 Subject: [PATCH] address code review comments --- .../java/io/pinecone/helpers/IndexManager.java | 10 +++++----- .../integration/controlPlane/ConfigureIndexTest.java | 4 ++-- .../integration/dataplane/UpsertAndDeleteTest.java | 4 ++-- .../dataplane/UpsertAndDescribeIndexStatsTest.java | 4 ++-- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/integration/java/io/pinecone/helpers/IndexManager.java b/src/integration/java/io/pinecone/helpers/IndexManager.java index e6c27731..046b9266 100644 --- a/src/integration/java/io/pinecone/helpers/IndexManager.java +++ b/src/integration/java/io/pinecone/helpers/IndexManager.java @@ -8,14 +8,14 @@ import java.util.List; public class IndexManager { - public PineconeConnection createIndexIfNotExistsDataPlane(int dimension) throws IOException, InterruptedException { + public static PineconeConnection createIndexIfNotExistsDataPlane(int dimension) throws IOException, InterruptedException { PineconeClientConfig config = new PineconeClientConfig() .withApiKey(System.getenv("PINECONE_API_KEY")) .withEnvironment(System.getenv("PINECONE_ENVIRONMENT")); PineconeIndexOperationClient controlPlaneClient = new PineconeIndexOperationClient(config); List indexList = controlPlaneClient.listIndexes(); - String indexName = checkIfIndexExists(indexList, dimension, controlPlaneClient); + String indexName = findIndexWithDimensionAndPodType(indexList, dimension, controlPlaneClient); if(indexName.isEmpty()) indexName = createNewIndex(dimension, controlPlaneClient); PineconeClient dataPlaneClient = new PineconeClient(config); @@ -27,15 +27,15 @@ public PineconeConnection createIndexIfNotExistsDataPlane(int dimension) throws .withConnectionUrl("https://" + host)); } - public String createIndexIfNotExistsControlPlane(PineconeClientConfig config, int dimension) throws IOException, InterruptedException { + public static String createIndexIfNotExistsControlPlane(PineconeClientConfig config, int dimension) throws IOException, InterruptedException { PineconeIndexOperationClient controlPlaneClient = new PineconeIndexOperationClient(config); List indexList = controlPlaneClient.listIndexes(); - String indexName = checkIfIndexExists(indexList, dimension, controlPlaneClient); + String indexName = findIndexWithDimensionAndPodType(indexList, dimension, controlPlaneClient); return (indexName.isEmpty()) ? createNewIndex(dimension, controlPlaneClient) : indexName; } - private static String checkIfIndexExists(List indexList, int dimension, PineconeIndexOperationClient controlPlaneClient) + private static String findIndexWithDimensionAndPodType(List indexList, int dimension, PineconeIndexOperationClient controlPlaneClient) throws IOException, InterruptedException { int i = 0; while (i < indexList.size()) { diff --git a/src/integration/java/io/pinecone/integration/controlPlane/ConfigureIndexTest.java b/src/integration/java/io/pinecone/integration/controlPlane/ConfigureIndexTest.java index ed40f38e..d945c5d2 100644 --- a/src/integration/java/io/pinecone/integration/controlPlane/ConfigureIndexTest.java +++ b/src/integration/java/io/pinecone/integration/controlPlane/ConfigureIndexTest.java @@ -5,7 +5,6 @@ import io.pinecone.PineconeIndexOperationClient; import io.pinecone.exceptions.PineconeBadRequestException; import io.pinecone.exceptions.PineconeNotFoundException; -import io.pinecone.helpers.IndexManager; import io.pinecone.model.ConfigureIndexRequest; import io.pinecone.model.IndexMeta; import org.junit.jupiter.api.*; @@ -14,6 +13,7 @@ import java.io.IOException; +import static io.pinecone.helpers.IndexManager.createIndexIfNotExistsControlPlane; import static io.pinecone.helpers.IndexManager.isIndexReady; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -32,7 +32,7 @@ public static void defineConfig() { @BeforeEach public void setUp() throws IOException, InterruptedException { - indexName = new IndexManager().createIndexIfNotExistsControlPlane(config, 5); + indexName = createIndexIfNotExistsControlPlane(config, 5); indexOperationClient = new PineconeIndexOperationClient(config); } diff --git a/src/integration/java/io/pinecone/integration/dataplane/UpsertAndDeleteTest.java b/src/integration/java/io/pinecone/integration/dataplane/UpsertAndDeleteTest.java index 036d5dfb..ad87054e 100644 --- a/src/integration/java/io/pinecone/integration/dataplane/UpsertAndDeleteTest.java +++ b/src/integration/java/io/pinecone/integration/dataplane/UpsertAndDeleteTest.java @@ -3,7 +3,6 @@ import com.google.protobuf.Struct; import com.google.protobuf.Value; import io.pinecone.PineconeConnection; -import io.pinecone.helpers.IndexManager; import io.pinecone.helpers.RandomStringBuilder; import io.pinecone.proto.*; import org.junit.jupiter.api.BeforeAll; @@ -15,6 +14,7 @@ import java.util.concurrent.ExecutionException; import static io.pinecone.helpers.BuildUpsertRequest.*; +import static io.pinecone.helpers.IndexManager.createIndexIfNotExistsDataPlane; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; @@ -25,7 +25,7 @@ public class UpsertAndDeleteTest { @BeforeAll public static void setUp() throws IOException, InterruptedException { - PineconeConnection connection = new IndexManager().createIndexIfNotExistsDataPlane(dimension); + PineconeConnection connection = createIndexIfNotExistsDataPlane(dimension); blockingStub = connection.getBlockingStub(); futureStub = connection.getFutureStub(); } diff --git a/src/integration/java/io/pinecone/integration/dataplane/UpsertAndDescribeIndexStatsTest.java b/src/integration/java/io/pinecone/integration/dataplane/UpsertAndDescribeIndexStatsTest.java index 8b229eab..98668a55 100644 --- a/src/integration/java/io/pinecone/integration/dataplane/UpsertAndDescribeIndexStatsTest.java +++ b/src/integration/java/io/pinecone/integration/dataplane/UpsertAndDescribeIndexStatsTest.java @@ -1,11 +1,11 @@ package io.pinecone.integration.dataplane; import io.pinecone.*; -import io.pinecone.helpers.IndexManager; import io.pinecone.proto.*; import org.junit.jupiter.api.*; import static io.pinecone.helpers.BuildUpsertRequest.*; +import static io.pinecone.helpers.IndexManager.createIndexIfNotExistsDataPlane; import static org.junit.jupiter.api.Assertions.assertEquals; import java.io.IOException; @@ -18,7 +18,7 @@ public class UpsertAndDescribeIndexStatsTest { @BeforeAll public static void setUp() throws IOException, InterruptedException { - PineconeConnection connection = new IndexManager().createIndexIfNotExistsDataPlane(dimension); + PineconeConnection connection = createIndexIfNotExistsDataPlane(dimension); blockingStub = connection.getBlockingStub(); futureStub = connection.getFutureStub(); }