Skip to content

Commit

Permalink
address code review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
rohanshah18 committed Dec 7, 2023
1 parent 9c6ccb6 commit 6c11e3c
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
10 changes: 5 additions & 5 deletions src/integration/java/io/pinecone/helpers/IndexManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> 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);
Expand All @@ -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<String> 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<String> indexList, int dimension, PineconeIndexOperationClient controlPlaneClient)
private static String findIndexWithDimensionAndPodType(List<String> indexList, int dimension, PineconeIndexOperationClient controlPlaneClient)
throws IOException, InterruptedException {
int i = 0;
while (i < indexList.size()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;
Expand All @@ -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;

Expand All @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand All @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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();
}
Expand Down

0 comments on commit 6c11e3c

Please sign in to comment.