Skip to content

Commit 649099a

Browse files
author
Milder Hernandez Cagua
committed
Add sleep to guarantee indexed data in tests
1 parent 87e9e4d commit 649099a

File tree

5 files changed

+115
-66
lines changed

5 files changed

+115
-66
lines changed

api-test/integration-tests/src/test/java/com/microsoft/semantickernel/tests/connectors/memory/redis/RedisHashSetVectorStoreRecordCollectionTest.java

Lines changed: 54 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import com.microsoft.semantickernel.connectors.data.redis.RedisHashSetVectorStoreRecordCollection;
44
import com.microsoft.semantickernel.connectors.data.redis.RedisHashSetVectorStoreRecordCollectionOptions;
5-
import com.microsoft.semantickernel.connectors.data.redis.RedisJsonVectorStoreRecordCollection;
65
import com.microsoft.semantickernel.data.vectorsearch.VectorSearchResult;
76
import com.microsoft.semantickernel.data.vectorstorage.definition.VectorStoreRecordDataField;
87
import com.microsoft.semantickernel.data.vectorstorage.definition.VectorStoreRecordDefinition;
@@ -41,7 +40,7 @@
4140
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
4241
public class RedisHashSetVectorStoreRecordCollectionTest {
4342

44-
@Container private static final RedisContainer redisContainer = new RedisContainer("redis/redis-stack:7.4.0-v0");
43+
@Container private static final RedisContainer redisContainer = new RedisContainer("redis/redis-stack:latest");
4544

4645
private static final Map<RecordCollectionOptions, RedisHashSetVectorStoreRecordCollectionOptions<Hotel>> optionsMap = new HashMap<>();
4746

@@ -101,9 +100,29 @@ static void setup() {
101100
.withRecordClass(Hotel.class)
102101
.withRecordDefinition(recordDefinition)
103102
.build());
103+
104+
// Search configuration
105+
List<Hotel> hotels = getHotels();
106+
107+
for (RecordCollectionOptions options : RecordCollectionOptions.values()) {
108+
String collectionName = getCollectionName("search", options);
109+
RedisHashSetVectorStoreRecordCollection<Hotel> recordCollection = createCollection(optionsMap.get(options), collectionName);
110+
111+
recordCollection.createCollectionAsync().block();
112+
assertEquals(true, recordCollection.collectionExistsAsync().block());
113+
114+
recordCollection.upsertBatchAsync(hotels, null).block();
115+
}
116+
117+
// Wait for data to be indexed
118+
try {
119+
Thread.sleep(1000);
120+
} catch (InterruptedException e) {
121+
throw new RuntimeException(e);
122+
}
104123
}
105124

106-
private RedisHashSetVectorStoreRecordCollection<Hotel> buildRecordCollection(@Nonnull RedisHashSetVectorStoreRecordCollectionOptions<Hotel> options, @Nonnull String collectionName) {
125+
private static RedisHashSetVectorStoreRecordCollection<Hotel> createCollection(@Nonnull RedisHashSetVectorStoreRecordCollectionOptions<Hotel> options, @Nonnull String collectionName) {
107126
return new RedisHashSetVectorStoreRecordCollection<>(new JedisPooled(redisContainer.getRedisURI()), collectionName, RedisHashSetVectorStoreRecordCollectionOptions.<Hotel>builder()
108127
.withRecordClass(options.getRecordClass())
109128
.withVectorStoreRecordMapper(options.getVectorStoreRecordMapper())
@@ -112,7 +131,7 @@ private RedisHashSetVectorStoreRecordCollection<Hotel> buildRecordCollection(@No
112131
.build());
113132
}
114133

115-
private List<Hotel> getHotels() {
134+
private static List<Hotel> getHotels() {
116135
return List.of(
117136
new Hotel("id_1", "Hotel 1", 1, "Hotel 1 description", Arrays.asList(0.5f, 3.2f, 7.1f, -4.0f, 2.8f, 10.0f, -1.3f, 5.5f),null, null, 4.0),
118137
new Hotel("id_2", "Hotel 2", 2, "Hotel 2 description", Arrays.asList(-2.0f, 8.1f, 0.9f, 5.4f, -3.3f, 2.2f, 9.9f, -4.5f),null, null, 4.0),
@@ -131,18 +150,16 @@ private List<Hotel> getHotels() {
131150
*/
132151
private static final List<Float> SEARCH_EMBEDDINGS = Arrays.asList(4.5f, -6.2f, 3.1f, 7.7f, -0.8f, 1.1f, -2.2f, 8.2f);
133152

134-
@Order(1)
135-
@ParameterizedTest
136-
@EnumSource(RecordCollectionOptions.class)
137-
public void buildRecordCollection(RecordCollectionOptions options) {
138-
assertNotNull(buildRecordCollection(optionsMap.get(options), options.name()));
153+
private static String getCollectionName(String id, RecordCollectionOptions options) {
154+
return id + options.name();
139155
}
140156

141-
@Order(2)
157+
@Order(1)
142158
@ParameterizedTest
143159
@EnumSource(RecordCollectionOptions.class)
144160
public void createCollectionAsync(RecordCollectionOptions options) {
145-
RedisHashSetVectorStoreRecordCollection<Hotel> recordCollection = buildRecordCollection(optionsMap.get(options), options.name());
161+
String collectionName = getCollectionName("createCollectionAsync", options);
162+
RedisHashSetVectorStoreRecordCollection<Hotel> recordCollection = createCollection(optionsMap.get(options), collectionName);
146163

147164
assertEquals(false, recordCollection.collectionExistsAsync().block());
148165
recordCollection.createCollectionAsync().block();
@@ -151,7 +168,8 @@ public void createCollectionAsync(RecordCollectionOptions options) {
151168

152169
@Test
153170
public void deleteCollectionAsync() {
154-
RedisHashSetVectorStoreRecordCollection<Hotel> recordCollection = buildRecordCollection(optionsMap.get(RecordCollectionOptions.DEFAULT), "deleteCollectionAsync");
171+
String collectionName = getCollectionName("deleteCollectionAsync", RecordCollectionOptions.DEFAULT);
172+
RedisHashSetVectorStoreRecordCollection<Hotel> recordCollection = createCollection(optionsMap.get(RecordCollectionOptions.DEFAULT), collectionName);
155173

156174
assertEquals(false, recordCollection.collectionExistsAsync().block());
157175
recordCollection.createCollectionAsync().block();
@@ -162,7 +180,8 @@ public void deleteCollectionAsync() {
162180
@ParameterizedTest
163181
@EnumSource(RecordCollectionOptions.class)
164182
public void upsertAndGetRecordAsync(RecordCollectionOptions options) {
165-
RedisHashSetVectorStoreRecordCollection<Hotel> recordCollection = buildRecordCollection(optionsMap.get(options), options.name());
183+
String collectionName = getCollectionName("upsertAndGetRecordAsync", options);
184+
RedisHashSetVectorStoreRecordCollection<Hotel> recordCollection = createCollection(optionsMap.get(options), collectionName);
166185

167186
List<Hotel> hotels = getHotels();
168187
for (Hotel hotel : hotels) {
@@ -179,7 +198,8 @@ public void upsertAndGetRecordAsync(RecordCollectionOptions options) {
179198
@ParameterizedTest
180199
@EnumSource(RecordCollectionOptions.class)
181200
public void getBatchAsync(RecordCollectionOptions options) {
182-
RedisHashSetVectorStoreRecordCollection<Hotel> recordCollection = buildRecordCollection(optionsMap.get(options), options.name());
201+
String collectionName = getCollectionName("getBatchAsync", options);
202+
RedisHashSetVectorStoreRecordCollection<Hotel> recordCollection = createCollection(optionsMap.get(options), collectionName);
183203

184204
List<Hotel> hotels = getHotels();
185205
for (Hotel hotel : hotels) {
@@ -201,7 +221,8 @@ public void getBatchAsync(RecordCollectionOptions options) {
201221
@ParameterizedTest
202222
@EnumSource(RecordCollectionOptions.class)
203223
public void upsertBatchAsync(RecordCollectionOptions options) {
204-
RedisHashSetVectorStoreRecordCollection<Hotel> recordCollection = buildRecordCollection(optionsMap.get(options), options.name());
224+
String collectionName = getCollectionName("upsertBatchAsync", options);
225+
RedisHashSetVectorStoreRecordCollection<Hotel> recordCollection = createCollection(optionsMap.get(options), collectionName);
205226

206227
List<Hotel> hotels = getHotels();
207228
List<String> keys = recordCollection.upsertBatchAsync(hotels, null).block();
@@ -219,7 +240,8 @@ public void upsertBatchAsync(RecordCollectionOptions options) {
219240
@ParameterizedTest
220241
@EnumSource(RecordCollectionOptions.class)
221242
public void deleteAsync(RecordCollectionOptions options) {
222-
RedisHashSetVectorStoreRecordCollection<Hotel> recordCollection = buildRecordCollection(optionsMap.get(options), options.name());
243+
String collectionName = getCollectionName("deleteAsync", options);
244+
RedisHashSetVectorStoreRecordCollection<Hotel> recordCollection = createCollection(optionsMap.get(options), collectionName);
223245

224246
List<Hotel> hotels = getHotels();
225247
recordCollection.upsertBatchAsync(hotels, null).block();
@@ -234,7 +256,8 @@ public void deleteAsync(RecordCollectionOptions options) {
234256
@ParameterizedTest
235257
@EnumSource(RecordCollectionOptions.class)
236258
public void deleteBatchAsync(RecordCollectionOptions options) {
237-
RedisHashSetVectorStoreRecordCollection<Hotel> recordCollection = buildRecordCollection(optionsMap.get(options), options.name());
259+
String collectionName = getCollectionName("deleteBatchAsync", options);
260+
RedisHashSetVectorStoreRecordCollection<Hotel> recordCollection = createCollection(optionsMap.get(options), collectionName);
238261

239262
List<Hotel> hotels = getHotels();
240263
recordCollection.upsertBatchAsync(hotels, null).block();
@@ -253,7 +276,8 @@ public void deleteBatchAsync(RecordCollectionOptions options) {
253276
@ParameterizedTest
254277
@EnumSource(RecordCollectionOptions.class)
255278
public void getAsyncWithVectors(RecordCollectionOptions options) {
256-
RedisHashSetVectorStoreRecordCollection<Hotel> recordCollection = buildRecordCollection(optionsMap.get(options), options.name());
279+
String collectionName = getCollectionName("getAsyncWithVectors", options);
280+
RedisHashSetVectorStoreRecordCollection<Hotel> recordCollection = createCollection(optionsMap.get(options), collectionName);
257281

258282
List<Hotel> hotels = getHotels();
259283
recordCollection.upsertBatchAsync(hotels, null).block();
@@ -270,7 +294,8 @@ public void getAsyncWithVectors(RecordCollectionOptions options) {
270294
@ParameterizedTest
271295
@EnumSource(RecordCollectionOptions.class)
272296
public void getBatchAsyncWithVectors(RecordCollectionOptions options) {
273-
RedisHashSetVectorStoreRecordCollection<Hotel> recordCollection = buildRecordCollection(optionsMap.get(options), options.name());
297+
String collectionName = getCollectionName("getBatchAsyncWithVectors", options);
298+
RedisHashSetVectorStoreRecordCollection<Hotel> recordCollection = createCollection(optionsMap.get(options), collectionName);
274299

275300
List<Hotel> hotels = getHotels();
276301
recordCollection.upsertBatchAsync(hotels, null).block();
@@ -292,7 +317,8 @@ public void getBatchAsyncWithVectors(RecordCollectionOptions options) {
292317
@ParameterizedTest
293318
@EnumSource(RecordCollectionOptions.class)
294319
public void getAsyncWithNoVectors(RecordCollectionOptions options) {
295-
RedisHashSetVectorStoreRecordCollection<Hotel> recordCollection = buildRecordCollection(optionsMap.get(options), options.name());
320+
String collectionName = getCollectionName("getAsyncWithNoVectors", options);
321+
RedisHashSetVectorStoreRecordCollection<Hotel> recordCollection = createCollection(optionsMap.get(options), collectionName);
296322

297323
List<Hotel> hotels = getHotels();
298324
recordCollection.upsertBatchAsync(hotels, null).block();
@@ -310,7 +336,8 @@ public void getAsyncWithNoVectors(RecordCollectionOptions options) {
310336
@ParameterizedTest
311337
@EnumSource(RecordCollectionOptions.class)
312338
public void getBatchAsyncWithNoVectors(RecordCollectionOptions options) {
313-
RedisHashSetVectorStoreRecordCollection<Hotel> recordCollection = buildRecordCollection(optionsMap.get(options), options.name());
339+
String collectionName = getCollectionName("getBatchAsyncWithNoVectors", options);
340+
RedisHashSetVectorStoreRecordCollection<Hotel> recordCollection = createCollection(optionsMap.get(options), collectionName);
314341

315342
List<Hotel> hotels = getHotels();
316343
recordCollection.upsertBatchAsync(hotels, null).block();
@@ -344,8 +371,8 @@ private static Stream<Arguments> provideSearchParameters() {
344371
@ParameterizedTest
345372
@MethodSource("provideSearchParameters")
346373
public void search(RecordCollectionOptions options, String embeddingName) {
347-
String collectionName = "search";
348-
RedisHashSetVectorStoreRecordCollection<Hotel> recordCollection = buildRecordCollection(optionsMap.get(options), collectionName);
374+
String collectionName = getCollectionName("search", options);
375+
RedisHashSetVectorStoreRecordCollection<Hotel> recordCollection = createCollection(optionsMap.get(options), collectionName);
349376

350377
List<Hotel> hotels = getHotels();
351378
recordCollection.upsertBatchAsync(hotels, null).block();
@@ -366,8 +393,8 @@ public void search(RecordCollectionOptions options, String embeddingName) {
366393
@ParameterizedTest
367394
@MethodSource("provideSearchParameters")
368395
public void searchWithVectors(RecordCollectionOptions options, String embeddingName) {
369-
String collectionName = "search";
370-
RedisHashSetVectorStoreRecordCollection<Hotel> recordCollection = buildRecordCollection(optionsMap.get(options), collectionName);
396+
String collectionName = getCollectionName("search", options);
397+
RedisHashSetVectorStoreRecordCollection<Hotel> recordCollection = createCollection(optionsMap.get(options), collectionName);
371398

372399
List<Hotel> hotels = getHotels();
373400
recordCollection.upsertBatchAsync(hotels, null).block();
@@ -389,8 +416,8 @@ public void searchWithVectors(RecordCollectionOptions options, String embeddingN
389416
@ParameterizedTest
390417
@MethodSource("provideSearchParameters")
391418
public void searchWithOffSet(RecordCollectionOptions options, String embeddingName) {
392-
String collectionName = "search";
393-
RedisHashSetVectorStoreRecordCollection<Hotel> recordCollection = buildRecordCollection(optionsMap.get(options), collectionName);
419+
String collectionName = getCollectionName("search", options);
420+
RedisHashSetVectorStoreRecordCollection<Hotel> recordCollection = createCollection(optionsMap.get(options), collectionName);
394421

395422
List<Hotel> hotels = getHotels();
396423
recordCollection.upsertBatchAsync(hotels, null).block();

0 commit comments

Comments
 (0)