@@ -78,59 +78,44 @@ public void testMultipleIndexesWithMultipleClients() throws InterruptedException
7878
7979 // Create config2 for getting index connection and set the host
8080 PineconeConfig config2 = new PineconeConfig (System .getenv ("PINECONE_API_KEY" ));
81- config1 .setHost (host2 );
81+ config2 .setHost (host2 );
8282
8383
8484 // Establish grpc connection for index-1
8585 Index index1_1 = pinecone1 .getIndexConnection (indexName1 );
8686 // Get connections map
87- ConcurrentHashMap <String , PineconeConnection > connectionsMap1_1 = pinecone1 .getConnectionsMap ();
87+ ConcurrentHashMap <String , PineconeConnection > connectionsMap = pinecone1 .getConnectionsMap ();
8888
89- // Verify connectionsMap contains only one <indexName, connection> pair i.e. for index1 and its connection
90- assertEquals (pinecone1 .getConnectionsMap ().size (), 1 );
91- // Verify the value for index1 by comparing its value with host1 in the connectionsMap
92- assertEquals (host1 , connectionsMap1_1 .get (indexName1 ).toString ());
89+ // Verify indexName1 is in the map with the correct host
90+ assertEquals (host1 , connectionsMap .get (indexName1 ).toString ());
9391
9492 // Establish grpc connection for index-2
9593 Index index1_2 = pinecone1 .getIndexConnection (indexName2 );
96- // Get connections map after establishing second connection
97- ConcurrentHashMap <String , PineconeConnection > connectionsMap1_2 = pinecone1 .getConnectionsMap ();
9894
99- // Verify connectionsMap contains two <indexName, connection> pairs i.e. for index1 and index2
100- assertEquals (connectionsMap1_2 .size (), 2 );
101- // Verify the values by checking host for both indexName1 and indexName2
102- assertEquals (host1 , connectionsMap1_2 .get (indexName1 ).toString ());
103- assertEquals (host2 , connectionsMap1_2 .get (indexName2 ).toString ());
95+ // Verify both indexes are now in the map with the correct hosts
96+ assertEquals (host1 , connectionsMap .get (indexName1 ).toString ());
97+ assertEquals (host2 , connectionsMap .get (indexName2 ).toString ());
10498
105- // Establishing connections with index1 and index2 using another pinecone client
99+ // Connecting a second client to the same indexes should reuse the existing map entries
100+ int sizeBeforeSecondClient = connectionsMap .size ();
106101 pinecone2 .getConnection (indexName1 , config1 );
107- ConcurrentHashMap <String , PineconeConnection > connectionsMap2_1 = pinecone1 .getConnectionsMap ();
108- // Verify the new connections map is pointing to the same reference
109- assert connectionsMap2_1 == connectionsMap1_2 ;
110- // Verify the size of connections map is still 2 since the connection for index2 was not closed
111- assertEquals (2 , connectionsMap2_1 .size ());
112- // Verify the connection value for index1 is host1
113- assertEquals (host1 , connectionsMap2_1 .get (indexName1 ).toString ());
102+ // Verify the map is the same reference and the size did not grow
103+ assert pinecone2 .getConnectionsMap () == connectionsMap ;
104+ assertEquals (sizeBeforeSecondClient , connectionsMap .size ());
105+ assertEquals (host1 , connectionsMap .get (indexName1 ).toString ());
114106
115107 pinecone2 .getConnection (indexName2 , config2 );
116- ConcurrentHashMap <String , PineconeConnection > connectionsMap2_2 = pinecone1 .getConnectionsMap ();
117- // Verify the new connections map is pointing to the same reference
118- assert connectionsMap2_1 == connectionsMap2_2 ;
119- // Verify the size of connections map is still 2 since the connections are not closed
120- assertEquals (2 , connectionsMap2_2 .size ());
121- // Verify the values by checking host for both indexName1 and indexName2
122- assertEquals (host1 , connectionsMap2_2 .get (indexName1 ).toString ());
123- assertEquals (host2 , connectionsMap2_2 .get (indexName2 ).toString ());
108+ assertEquals (sizeBeforeSecondClient , connectionsMap .size ());
109+ assertEquals (host1 , connectionsMap .get (indexName1 ).toString ());
110+ assertEquals (host2 , connectionsMap .get (indexName2 ).toString ());
124111
125112 // Close the connections
126113 index1_1 .close ();
127114 index1_2 .close ();
128115
129- // Verify the map size is now 0
130- assertEquals (connectionsMap1_1 .size (), 0 );
131- assertEquals (connectionsMap1_2 .size (), 0 );
132- assertEquals (connectionsMap2_1 .size (), 0 );
133- assertEquals (connectionsMap2_2 .size (), 0 );
116+ // Verify the specific entries for this test's indexes were removed
117+ assert !connectionsMap .containsKey (indexName1 );
118+ assert !connectionsMap .containsKey (indexName2 );
134119
135120 // Delete the indexes
136121 pinecone1 .deleteIndex (indexName1 );
0 commit comments