Skip to content

Commit b5b9ca7

Browse files
authored
Test default protocol (RESP2) and RESP3 in same workflow (#3409)
* Test default protocol (RESP2) and RESP3 in same workflow * make start separately as make test does make stop when successful * Refine step names
1 parent 6306c98 commit b5b9ca7

File tree

8 files changed

+96
-52
lines changed

8 files changed

+96
-52
lines changed

.github/workflows/integration.yml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,20 @@ jobs:
5454
env:
5555
JVM_OPTS: -Xmx3200m
5656
TERM: dumb
57-
- name: redismod docker
57+
- name: Make - start
58+
run: make start
59+
- name: Docker - mod or stack
5860
run: docker run -p 52567:6379 -d redis/redis-stack-server:edge
59-
- name: Run tests
61+
- name: Test commands - default protocol
62+
run: mvn -Dtest="redis.clients.jedis.commands.**" test
63+
- name: Test commands - RESP3 protocol
64+
run: mvn -DjedisProtocol=3 -Dtest="redis.clients.jedis.commands.**" test
65+
- name: Test module commands - default protocol
6066
run: mvn -DmodulesDocker="localhost:52567" -Dtest="redis.clients.jedis.modules.**" test
67+
- name: Test module commands - RESP3 protocol
68+
run: mvn -DjedisProtocol=3 -DmodulesDocker="localhost:52567" -Dtest="redis.clients.jedis.modules.**" test
69+
- name: Make - stop
70+
run: make stop
6171
- name: Codecov
6272
run: |
6373
bash <(curl -s https://codecov.io/bash)

src/test/java/redis/clients/jedis/commands/jedis/JedisCommandsTestBase.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import redis.clients.jedis.HostAndPort;
88
import redis.clients.jedis.Jedis;
99
import redis.clients.jedis.HostAndPorts;
10+
import redis.clients.jedis.util.RedisProtocolUtil;
1011

1112
public abstract class JedisCommandsTestBase {
1213

@@ -20,8 +21,10 @@ public JedisCommandsTestBase() {
2021

2122
@Before
2223
public void setUp() throws Exception {
23-
//jedis = new Jedis(hnp, DefaultJedisClientConfig.builder().timeoutMillis(500).password("foobared").build());
24-
jedis = new Jedis(hnp, DefaultJedisClientConfig.builder().resp3().timeoutMillis(500).password("foobared").build());
24+
// jedis = new Jedis(hnp, DefaultJedisClientConfig.builder().timeoutMillis(500).password("foobared").build());
25+
jedis = new Jedis(hnp, DefaultJedisClientConfig.builder()
26+
.protocol(RedisProtocolUtil.getRedisProtocol())
27+
.timeoutMillis(500).password("foobared").build());
2528
jedis.flushAll();
2629
}
2730

@@ -31,6 +34,9 @@ public void tearDown() throws Exception {
3134
}
3235

3336
protected Jedis createJedis() {
34-
return new Jedis(hnp, DefaultJedisClientConfig.builder().password("foobared").build());
37+
// return new Jedis(hnp, DefaultJedisClientConfig.builder().password("foobared").build());
38+
return new Jedis(hnp, DefaultJedisClientConfig.builder()
39+
.protocol(RedisProtocolUtil.getRedisProtocol())
40+
.password("foobared").build());
3541
}
3642
}

src/test/java/redis/clients/jedis/commands/unified/pooled/PooledCommandsTestHelper.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import redis.clients.jedis.Jedis;
66
import redis.clients.jedis.JedisPooled;
77
import redis.clients.jedis.HostAndPorts;
8+
import redis.clients.jedis.util.RedisProtocolUtil;
89

910
public class PooledCommandsTestHelper {
1011

@@ -19,7 +20,8 @@ static JedisPooled getPooled() throws InterruptedException {
1920
node.flushAll();
2021

2122
//return new JedisPooled(nodeInfo.getHost(), nodeInfo.getPort(), null, "foobared");
22-
return new JedisPooled(nodeInfo, DefaultJedisClientConfig.builder().resp3().password("foobared").build());
23+
return new JedisPooled(nodeInfo, DefaultJedisClientConfig.builder()
24+
.protocol(RedisProtocolUtil.getRedisProtocol()).password("foobared").build());
2325
}
2426

2527
static void clearData() {

src/test/java/redis/clients/jedis/modules/RedisModuleCommandsTestBase.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import redis.clients.jedis.Protocol;
1313
import redis.clients.jedis.UnifiedJedis;
1414
import redis.clients.jedis.exceptions.JedisConnectionException;
15+
import redis.clients.jedis.util.RedisProtocolUtil;
1516

1617
public abstract class RedisModuleCommandsTestBase {
1718

@@ -38,7 +39,8 @@ public void setUp() {
3839
try (Jedis jedis = new Jedis(hnp)) {
3940
jedis.flushAll();
4041
}
41-
client = new UnifiedJedis(hnp, DefaultJedisClientConfig.builder().resp3().build());
42+
client = new UnifiedJedis(hnp, DefaultJedisClientConfig.builder()
43+
.protocol(RedisProtocolUtil.getRedisProtocol()).build());
4244
}
4345

4446
@After
@@ -49,8 +51,8 @@ public void tearDown() throws Exception {
4951
// public static void tearDown() {
5052
// client.close();
5153
// }
52-
53-
protected static Connection createConnection() {
54-
return new Connection(hnp);
55-
}
54+
//
55+
// protected static Connection createConnection() {
56+
// return new Connection(hnp);
57+
// }
5658
}

src/test/java/redis/clients/jedis/modules/RedisModulesPipelineTest.java

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import org.junit.BeforeClass;
1818
import org.junit.Test;
1919

20-
import redis.clients.jedis.Connection;
2120
import redis.clients.jedis.Pipeline;
2221
import redis.clients.jedis.Response;
2322
import redis.clients.jedis.json.JsonSetParams;
@@ -44,8 +43,9 @@ public void search() {
4443
fields.put("title", "hello world");
4544
fields.put("body", "lorem ipsum");
4645

47-
Connection c = createConnection();
48-
Pipeline p = new Pipeline(c);
46+
// Connection c = createConnection();
47+
// Pipeline p = new Pipeline(c);
48+
Pipeline p = (Pipeline) client.pipelined();
4949

5050
Response<String> create = p.ftCreate(index, IndexOptions.defaultOptions(), sc);
5151
Response<String> alter = p.ftAlter(index, new Schema().addTextField("foo", 1.0));
@@ -65,7 +65,7 @@ public void search() {
6565
Response<Map<String, List<String>>> synDump = p.ftSynDump(index);
6666

6767
p.sync();
68-
c.close();
68+
// c.close();
6969

7070
assertEquals("OK", create.get());
7171
assertEquals("OK", alter.get());
@@ -101,8 +101,9 @@ public void jsonV1() {
101101
Baz baz2 = new Baz("quuz2", "grault2", "waldo2");
102102
Baz baz3 = new Baz("quuz3", "grault3", "waldo3");
103103

104-
Connection c = createConnection();
105-
Pipeline p = new Pipeline(c);
104+
// Connection c = createConnection();
105+
// Pipeline p = new Pipeline(c);
106+
Pipeline p = (Pipeline) client.pipelined();
106107

107108
Response<String> set1 = p.jsonSet("foo", Path.ROOT_PATH, hm1);
108109
Response<Object> get = p.jsonGet("foo");
@@ -142,7 +143,7 @@ public void jsonV1() {
142143
Response<Baz> popClassWithIndex = p.jsonArrPop("baz", Baz.class, Path.ROOT_PATH, 0);
143144

144145
p.sync();
145-
c.close();
146+
// c.close();
146147

147148
assertEquals("OK", set1.get());
148149
assertEquals(hm1, get.get());
@@ -190,8 +191,9 @@ public void jsonV2() {
190191
hm2.put("boolean", true);
191192
hm2.put("number", 3);
192193

193-
Connection c = createConnection();
194-
Pipeline p = new Pipeline(c);
194+
// Connection c = createConnection();
195+
// Pipeline p = new Pipeline(c);
196+
Pipeline p = (Pipeline) client.pipelined();
195197

196198
Response<String> setWithEscape = p.jsonSetWithEscape("foo", Path2.ROOT_PATH, hm1);
197199
Response<Object> get = p.jsonGet("foo", Path2.ROOT_PATH);
@@ -217,7 +219,7 @@ public void jsonV2() {
217219
Response<Long> clear = p.jsonClear("foo", new Path2("array"));
218220

219221
p.sync();
220-
c.close();
222+
// c.close();
221223

222224
assertEquals("OK", setWithEscape.get());
223225
assertNotNull(get.get());

src/test/java/redis/clients/jedis/modules/graph/GraphPipelineTest.java

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
public class GraphPipelineTest extends RedisModuleCommandsTestBase {
2727

28-
private Connection c;
28+
// private Connection c;
2929

3030
@BeforeClass
3131
public static void prepare() {
@@ -42,20 +42,21 @@ public static void prepare() {
4242
// api.deleteGraph("social");
4343
// api.close();
4444
// }
45-
46-
@Before
47-
public void createApi() {
48-
c = createConnection();
49-
}
50-
51-
@After
52-
public void deleteGraph() {
53-
c.close();
54-
}
45+
//
46+
// @Before
47+
// public void createApi() {
48+
// c = createConnection();
49+
// }
50+
//
51+
// @After
52+
// public void deleteGraph() {
53+
// c.close();
54+
// }
5555

5656
@Test
5757
public void testSync() {
58-
Pipeline pipeline = new Pipeline(c);
58+
// Pipeline pipeline = new Pipeline(c);
59+
Pipeline pipeline = (Pipeline) client.pipelined();
5960

6061
pipeline.set("x", "1");
6162
pipeline.graphQuery("social", "CREATE (:Person {name:'a'})");
@@ -140,7 +141,8 @@ record = iterator.next();
140141

141142
@Test
142143
public void testReadOnlyQueries() {
143-
Pipeline pipeline = new Pipeline(c);
144+
// Pipeline pipeline = new Pipeline(c);
145+
Pipeline pipeline = (Pipeline) client.pipelined();
144146

145147
pipeline.set("x", "1");
146148
pipeline.graphQuery("social", "CREATE (:Person {name:'a'})");
@@ -215,7 +217,8 @@ record = iterator.next();
215217

216218
@Test
217219
public void testWaitReplicas() {
218-
Pipeline pipeline = new Pipeline(c);
220+
// Pipeline pipeline = new Pipeline(c);
221+
Pipeline pipeline = (Pipeline) client.pipelined();
219222
pipeline.set("x", "1");
220223
pipeline.graphProfile("social", "CREATE (:Person {name:'a'})");
221224
pipeline.graphProfile("g", "CREATE (:Person {name:'a'})");
@@ -227,7 +230,8 @@ public void testWaitReplicas() {
227230
@Test
228231
@org.junit.Ignore
229232
public void testWaitAof() {
230-
Pipeline pipeline = new Pipeline(c);
233+
// Pipeline pipeline = new Pipeline(c);
234+
Pipeline pipeline = (Pipeline) client.pipelined();
231235
pipeline.set("x", "1");
232236
pipeline.graphProfile("social", "CREATE (:Person {name:'a'})");
233237
pipeline.graphProfile("g", "CREATE (:Person {name:'a'})");

src/test/java/redis/clients/jedis/modules/graph/GraphTransactionTest.java

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,9 @@
99
import java.util.Iterator;
1010
import java.util.List;
1111

12-
import org.junit.After;
13-
import org.junit.Before;
1412
import org.junit.BeforeClass;
1513
import org.junit.Test;
1614

17-
import redis.clients.jedis.Connection;
1815
import redis.clients.jedis.Transaction;
1916
import redis.clients.jedis.graph.Header;
2017
import redis.clients.jedis.graph.Record;
@@ -25,7 +22,7 @@
2522

2623
public class GraphTransactionTest extends RedisModuleCommandsTestBase {
2724

28-
private Connection c;
25+
// private Connection c;
2926

3027
@BeforeClass
3128
public static void prepare() {
@@ -42,20 +39,21 @@ public static void prepare() {
4239
// api.deleteGraph("social");
4340
// api.close();
4441
// }
45-
46-
@Before
47-
public void createApi() {
48-
c = createConnection();
49-
}
50-
51-
@After
52-
public void deleteGraph() {
53-
c.close();
54-
}
42+
//
43+
// @Before
44+
// public void createApi() {
45+
// c = createConnection();
46+
// }
47+
//
48+
// @After
49+
// public void deleteGraph() {
50+
// c.close();
51+
// }
5552

5653
@Test
5754
public void testMultiExec() {
58-
Transaction transaction = new Transaction(c);
55+
// Transaction transaction = new Transaction(c);
56+
Transaction transaction = client.multi();
5957

6058
transaction.set("x", "1");
6159
transaction.graphQuery("social", "CREATE (:Person {name:'a'})");
@@ -178,7 +176,8 @@ record = iterator.next();
178176

179177
@Test
180178
public void testMultiExecWithReadOnlyQueries() {
181-
Transaction transaction = new Transaction(c);
179+
// Transaction transaction = new Transaction(c);
180+
Transaction transaction = client.multi();
182181

183182
transaction.set("x", "1");
184183
transaction.graphQuery("social", "CREATE (:Person {name:'a'})");
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package redis.clients.jedis.util;
2+
3+
import redis.clients.jedis.RedisProtocol;
4+
5+
public class RedisProtocolUtil {
6+
7+
public static RedisProtocol getRedisProtocol() {
8+
String ver = System.getProperty("jedisProtocol");
9+
if (ver != null && !ver.isEmpty()) {
10+
for (RedisProtocol proto : RedisProtocol.values()) {
11+
if (proto.version().equals(ver)) {
12+
return proto;
13+
}
14+
}
15+
throw new IllegalArgumentException("Unknown protocol " + ver);
16+
}
17+
return null;
18+
}
19+
}

0 commit comments

Comments
 (0)