|
| 1 | +package com.redis.vl.storage; |
| 2 | + |
| 3 | +import static org.assertj.core.api.Assertions.assertThat; |
| 4 | + |
| 5 | +import com.redis.vl.BaseIntegrationTest; |
| 6 | +import com.redis.vl.schema.IndexSchema; |
| 7 | +import java.util.*; |
| 8 | +import org.junit.jupiter.api.DisplayName; |
| 9 | +import org.junit.jupiter.api.Test; |
| 10 | +import redis.clients.jedis.AbstractPipeline; |
| 11 | + |
| 12 | +/** |
| 13 | + * Integration tests for AbstractPipeline compatibility in storage classes. |
| 14 | + * |
| 15 | + * <p>Tests the fix for issue #365: Ensures BaseStorage uses AbstractPipeline instead of Pipeline to |
| 16 | + * support both regular Pipeline and MultiClusterPipeline objects, matching Python's graceful |
| 17 | + * handling of both Pipeline and ClusterPipeline types. |
| 18 | + * |
| 19 | + * <p>Python port: Matches Python's isinstance() checks for (AsyncPipeline, AsyncClusterPipeline) by |
| 20 | + * using the common base class AbstractPipeline in Java. |
| 21 | + */ |
| 22 | +@DisplayName("AbstractPipeline Compatibility Tests") |
| 23 | +class AbstractPipelineIntegrationTest extends BaseIntegrationTest { |
| 24 | + |
| 25 | + @Test |
| 26 | + @DisplayName("Should accept AbstractPipeline in HashStorage.set()") |
| 27 | + void testHashStorageAcceptsAbstractPipeline() { |
| 28 | + // Create a simple schema |
| 29 | + Map<String, Object> schemaDict = |
| 30 | + Map.of( |
| 31 | + "index", |
| 32 | + Map.of("name", "test-index", "prefix", "test", "storage_type", "hash"), |
| 33 | + "fields", |
| 34 | + List.of(Map.of("name", "field1", "type", "text"))); |
| 35 | + |
| 36 | + IndexSchema schema = IndexSchema.fromDict(schemaDict); |
| 37 | + HashStorage storage = new HashStorage(schema); |
| 38 | + |
| 39 | + // Verify the set() method signature accepts AbstractPipeline |
| 40 | + Map<String, Object> testData = Map.of("field1", "value1"); |
| 41 | + |
| 42 | + // Use the unifiedJedis from BaseIntegrationTest (Testcontainers) |
| 43 | + try (AbstractPipeline pipeline = unifiedJedis.pipelined()) { |
| 44 | + // This should compile without ClassCastException |
| 45 | + storage.set(pipeline, "test:key", testData); |
| 46 | + pipeline.sync(); |
| 47 | + } |
| 48 | + |
| 49 | + assertThat(true).as("Method signature accepts AbstractPipeline").isTrue(); |
| 50 | + } |
| 51 | + |
| 52 | + @Test |
| 53 | + @DisplayName("Should accept AbstractPipeline in JsonStorage.set()") |
| 54 | + void testJsonStorageAcceptsAbstractPipeline() { |
| 55 | + // Create a simple schema |
| 56 | + Map<String, Object> schemaDict = |
| 57 | + Map.of( |
| 58 | + "index", |
| 59 | + Map.of("name", "test-index", "prefix", "test", "storage_type", "json"), |
| 60 | + "fields", |
| 61 | + List.of(Map.of("name", "field1", "type", "text", "path", "$.field1"))); |
| 62 | + |
| 63 | + IndexSchema schema = IndexSchema.fromDict(schemaDict); |
| 64 | + JsonStorage storage = new JsonStorage(schema); |
| 65 | + |
| 66 | + // Verify the set() method signature accepts AbstractPipeline |
| 67 | + Map<String, Object> testData = Map.of("field1", "value1"); |
| 68 | + |
| 69 | + // Use the unifiedJedis from BaseIntegrationTest (Testcontainers) |
| 70 | + try (AbstractPipeline pipeline = unifiedJedis.pipelined()) { |
| 71 | + // This should compile without ClassCastException |
| 72 | + storage.set(pipeline, "test:key", testData); |
| 73 | + pipeline.sync(); |
| 74 | + } |
| 75 | + |
| 76 | + assertThat(true).as("Method signature accepts AbstractPipeline").isTrue(); |
| 77 | + } |
| 78 | + |
| 79 | + @Test |
| 80 | + @DisplayName("Should accept AbstractPipeline in HashStorage.getResponse()") |
| 81 | + void testHashStorageGetResponseAcceptsAbstractPipeline() { |
| 82 | + // Create a simple schema |
| 83 | + Map<String, Object> schemaDict = |
| 84 | + Map.of( |
| 85 | + "index", |
| 86 | + Map.of("name", "test-index", "prefix", "test", "storage_type", "hash"), |
| 87 | + "fields", |
| 88 | + List.of(Map.of("name", "field1", "type", "text"))); |
| 89 | + |
| 90 | + IndexSchema schema = IndexSchema.fromDict(schemaDict); |
| 91 | + HashStorage storage = new HashStorage(schema); |
| 92 | + |
| 93 | + // Use the unifiedJedis from BaseIntegrationTest (Testcontainers) |
| 94 | + try (AbstractPipeline pipeline = unifiedJedis.pipelined()) { |
| 95 | + // This should compile without ClassCastException |
| 96 | + storage.getResponse(pipeline, "test:key"); |
| 97 | + pipeline.sync(); |
| 98 | + } |
| 99 | + |
| 100 | + assertThat(true).as("Method signature accepts AbstractPipeline").isTrue(); |
| 101 | + } |
| 102 | + |
| 103 | + @Test |
| 104 | + @DisplayName("Should accept AbstractPipeline in JsonStorage.getResponse()") |
| 105 | + void testJsonStorageGetResponseAcceptsAbstractPipeline() { |
| 106 | + // Create a simple schema |
| 107 | + Map<String, Object> schemaDict = |
| 108 | + Map.of( |
| 109 | + "index", |
| 110 | + Map.of("name", "test-index", "prefix", "test", "storage_type", "json"), |
| 111 | + "fields", |
| 112 | + List.of(Map.of("name", "field1", "type", "text", "path", "$.field1"))); |
| 113 | + |
| 114 | + IndexSchema schema = IndexSchema.fromDict(schemaDict); |
| 115 | + JsonStorage storage = new JsonStorage(schema); |
| 116 | + |
| 117 | + // Use the unifiedJedis from BaseIntegrationTest (Testcontainers) |
| 118 | + try (AbstractPipeline pipeline = unifiedJedis.pipelined()) { |
| 119 | + // This should compile without ClassCastException |
| 120 | + storage.getResponse(pipeline, "test:key"); |
| 121 | + pipeline.sync(); |
| 122 | + } |
| 123 | + |
| 124 | + assertThat(true).as("Method signature accepts AbstractPipeline").isTrue(); |
| 125 | + } |
| 126 | +} |
0 commit comments