diff --git a/.github/workflows/integration.yml b/.github/workflows/integration.yml index fd651fa6a4..5b78b3124b 100644 --- a/.github/workflows/integration.yml +++ b/.github/workflows/integration.yml @@ -51,28 +51,10 @@ jobs: mvn javadoc:jar - name: Run tests run: | - TEST="" make test + make test env: JVM_OPTS: -Xmx3200m TERM: dumb - - name: sleep 10s - run: sleep 10s - - name: Make - start - run: | - make start - sleep 2s - - name: Docker - mod or stack - run: docker run -p 52567:6379 -d redis/redis-stack-server:edge - - name: Test commands - default protocol - run: mvn -Dtest="redis.clients.jedis.commands.**" test - - name: Test commands - RESP3 protocol - run: mvn -DjedisProtocol=3 -Dtest="redis.clients.jedis.commands.**" test - - name: Test module commands - default protocol - run: mvn -DmodulesDocker="localhost:52567" -Dtest="redis.clients.jedis.modules.**" test - - name: Test module commands - RESP3 protocol - run: mvn -DjedisProtocol=3 -DmodulesDocker="localhost:52567" -Dtest="redis.clients.jedis.modules.**" test - - name: Make - stop - run: make stop - name: Codecov run: | bash <(curl -s https://codecov.io/bash) diff --git a/Makefile b/Makefile index 96d106b000..1800f00d7e 100644 --- a/Makefile +++ b/Makefile @@ -413,7 +413,7 @@ ifndef STUNNEL_BIN endif export SKIP_SSL -start: stunnel cleanup +start: stunnel cleanup compile-module echo "$$REDIS1_CONF" | redis-server - echo "$$REDIS2_CONF" | redis-server - echo "$$REDIS3_CONF" | redis-server - @@ -446,6 +446,7 @@ start: stunnel cleanup echo "$$REDIS_UDS" | redis-server - echo "$$REDIS_UNAVAILABLE_CONF" | redis-server - redis-cli -a cluster --cluster create 127.0.0.1:7479 127.0.0.1:7480 127.0.0.1:7481 --cluster-yes + docker run -p 6479:6379 --name jedis-stack -d redis/redis-stack-server:edge cleanup: - rm -vf /tmp/redis_cluster_node*.conf 2>/dev/null @@ -455,6 +456,7 @@ stunnel: @if [ -e "$$STUNNEL_BIN" ]; then\ echo "$$STUNNEL_CONF" | stunnel -fd 0;\ fi + stop: kill `cat /tmp/redis1.pid` kill `cat /tmp/redis2.pid` @@ -496,29 +498,32 @@ stop: rm -f /tmp/redis_stable_cluster_node1.conf rm -f /tmp/redis_stable_cluster_node2.conf rm -f /tmp/redis_stable_cluster_node3.conf + docker rm -f jedis-stack + +test: | start mvn-test stop -test: compile-module start - sleep 2 +mvn-test: mvn -Dtest=${SKIP_SSL}${TEST} clean compile test - make stop -package: start +package: | start mvn-package stop + +mvn-package: mvn clean package - make stop -deploy: start +deploy: | start mvn-deploy stop + +mvn-deploy: mvn clean deploy - make stop format: mvn java-formatter:format -release: - make start +release: | start mvn-release stop + +mvn-release: mvn release:clean mvn release:prepare mvn release:perform -DskipTests - make stop system-setup: sudo apt install -y gcc g++ diff --git a/src/test/java/redis/clients/jedis/ACLJedisTest.java b/src/test/java/redis/clients/jedis/ACLJedisTest.java index 81517b5556..a6a9deff77 100644 --- a/src/test/java/redis/clients/jedis/ACLJedisTest.java +++ b/src/test/java/redis/clients/jedis/ACLJedisTest.java @@ -6,6 +6,8 @@ import java.net.URISyntaxException; import org.junit.BeforeClass; import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; import redis.clients.jedis.commands.jedis.JedisCommandsTestBase; import redis.clients.jedis.util.RedisVersionUtil; @@ -15,6 +17,7 @@ *

* This test is only executed when the server/cluster is Redis 6. or more. */ +@RunWith(Parameterized.class) public class ACLJedisTest extends JedisCommandsTestBase { /** @@ -27,6 +30,10 @@ public static void prepare() throws Exception { RedisVersionUtil.checkRedisMajorVersionNumber(6)); } + public ACLJedisTest(RedisProtocol redisProtocol) { + super(redisProtocol); + } + @Test public void useWithoutConnecting() { try (Jedis j = new Jedis()) { diff --git a/src/test/java/redis/clients/jedis/JedisShardedPubSubBaseTest.java b/src/test/java/redis/clients/jedis/JedisShardedPubSubBaseTest.java index fb1ecdd87a..68d8455392 100644 --- a/src/test/java/redis/clients/jedis/JedisShardedPubSubBaseTest.java +++ b/src/test/java/redis/clients/jedis/JedisShardedPubSubBaseTest.java @@ -50,7 +50,7 @@ protected String encode(byte[] raw) { }); thread.start(); - assertTrue(countDownLatch.await(10, TimeUnit.MILLISECONDS)); + assertTrue(countDownLatch.await(20, TimeUnit.MILLISECONDS)); } } \ No newline at end of file diff --git a/src/test/java/redis/clients/jedis/JedisTest.java b/src/test/java/redis/clients/jedis/JedisTest.java index e9520ff394..52d8c80c02 100644 --- a/src/test/java/redis/clients/jedis/JedisTest.java +++ b/src/test/java/redis/clients/jedis/JedisTest.java @@ -17,6 +17,8 @@ import java.util.Map; import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; import redis.clients.jedis.exceptions.InvalidURIException; import redis.clients.jedis.exceptions.JedisConnectionException; @@ -24,8 +26,13 @@ import redis.clients.jedis.commands.jedis.JedisCommandsTestBase; import redis.clients.jedis.util.SafeEncoder; +@RunWith(Parameterized.class) public class JedisTest extends JedisCommandsTestBase { + public JedisTest(RedisProtocol protocol) { + super(protocol); + } + @Test public void useWithoutConnecting() { try (Jedis j = new Jedis()) { diff --git a/src/test/java/redis/clients/jedis/MigratePipeliningTest.java b/src/test/java/redis/clients/jedis/MigratePipeliningTest.java index ebd4b31eb9..f8e7d8278c 100644 --- a/src/test/java/redis/clients/jedis/MigratePipeliningTest.java +++ b/src/test/java/redis/clients/jedis/MigratePipeliningTest.java @@ -14,10 +14,14 @@ import org.junit.After; import org.junit.Before; import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; + import redis.clients.jedis.commands.jedis.JedisCommandsTestBase; import redis.clients.jedis.exceptions.JedisDataException; import redis.clients.jedis.params.MigrateParams; +@RunWith(Parameterized.class) public class MigratePipeliningTest extends JedisCommandsTestBase { private static final byte[] bfoo = { 0x01, 0x02, 0x03 }; @@ -39,6 +43,10 @@ public class MigratePipeliningTest extends JedisCommandsTestBase { private Jedis dest; private Jedis destAuth; + public MigratePipeliningTest(RedisProtocol protocol) { + super(protocol); + } + @Before @Override public void setUp() throws Exception { diff --git a/src/test/java/redis/clients/jedis/PipeliningTest.java b/src/test/java/redis/clients/jedis/PipeliningTest.java index 527b9dfc6d..fffaa06a89 100644 --- a/src/test/java/redis/clients/jedis/PipeliningTest.java +++ b/src/test/java/redis/clients/jedis/PipeliningTest.java @@ -24,6 +24,9 @@ import org.hamcrest.Matcher; import org.hamcrest.Matchers; import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; + import redis.clients.jedis.commands.ProtocolCommand; import redis.clients.jedis.commands.jedis.JedisCommandsTestBase; import redis.clients.jedis.exceptions.JedisDataException; @@ -31,6 +34,7 @@ import redis.clients.jedis.resps.Tuple; import redis.clients.jedis.util.SafeEncoder; +@RunWith(Parameterized.class) public class PipeliningTest extends JedisCommandsTestBase { private static final byte[] bfoo = { 0x01, 0x02, 0x03, 0x04 }; @@ -38,6 +42,10 @@ public class PipeliningTest extends JedisCommandsTestBase { private static final byte[] bbar = { 0x05, 0x06, 0x07, 0x08 }; private static final byte[] bbaz = { 0x09, 0x0A, 0x0B, 0x0C }; + public PipeliningTest(RedisProtocol protocol) { + super(protocol); + } + @Test public void pipeline() { Pipeline p = jedis.pipelined(); diff --git a/src/test/java/redis/clients/jedis/TupleSortedSetTest.java b/src/test/java/redis/clients/jedis/TupleSortedSetTest.java index 676a19ffa5..59efcb3435 100644 --- a/src/test/java/redis/clients/jedis/TupleSortedSetTest.java +++ b/src/test/java/redis/clients/jedis/TupleSortedSetTest.java @@ -6,9 +6,13 @@ import java.util.Collections; import java.util.List; import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; + import redis.clients.jedis.resps.Tuple; import redis.clients.jedis.commands.jedis.JedisCommandsTestBase; +@RunWith(Parameterized.class) public class TupleSortedSetTest extends JedisCommandsTestBase { final byte[] bfoo = { 0x01, 0x02, 0x03, 0x04 }; final byte[] ba = { 0x0A }; @@ -18,6 +22,10 @@ public class TupleSortedSetTest extends JedisCommandsTestBase { final byte[] be = { 0x0E }; final byte[] bf = { 0x0F }; + public TupleSortedSetTest(RedisProtocol protocol) { + super(protocol); + } + @Test public void testBinary() { List array = new ArrayList(); diff --git a/src/test/java/redis/clients/jedis/commands/CommandsTestsParameters.java b/src/test/java/redis/clients/jedis/commands/CommandsTestsParameters.java new file mode 100644 index 0000000000..701ed06b08 --- /dev/null +++ b/src/test/java/redis/clients/jedis/commands/CommandsTestsParameters.java @@ -0,0 +1,22 @@ +package redis.clients.jedis.commands; + +import java.util.Arrays; +import java.util.Collection; + +import redis.clients.jedis.RedisProtocol; + +public class CommandsTestsParameters { + + /** + * RESP protocol versions we want our commands related tests to run against. + * {@code null} means to use the default protocol which is assumed to be RESP2. + */ + public static Collection respVersions() { + return Arrays.asList( + new Object[]{ null }, + new Object[]{ RedisProtocol.RESP2 }, + new Object[]{ RedisProtocol.RESP3 } + ); + } + +} diff --git a/src/test/java/redis/clients/jedis/commands/jedis/AccessControlListCommandsTest.java b/src/test/java/redis/clients/jedis/commands/jedis/AccessControlListCommandsTest.java index 9d4f3c6568..c8f56bc7eb 100644 --- a/src/test/java/redis/clients/jedis/commands/jedis/AccessControlListCommandsTest.java +++ b/src/test/java/redis/clients/jedis/commands/jedis/AccessControlListCommandsTest.java @@ -18,10 +18,13 @@ import org.junit.After; import org.junit.BeforeClass; import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; import redis.clients.jedis.CommandArguments; import redis.clients.jedis.Jedis; import redis.clients.jedis.Protocol; +import redis.clients.jedis.RedisProtocol; import redis.clients.jedis.Transaction; import redis.clients.jedis.exceptions.JedisAccessControlException; import redis.clients.jedis.exceptions.JedisDataException; @@ -33,6 +36,7 @@ /** * TODO: properly define and test exceptions */ +@RunWith(Parameterized.class) public class AccessControlListCommandsTest extends JedisCommandsTestBase { public static final String USER_NAME = "newuser"; @@ -45,6 +49,10 @@ public static void prepare() throws Exception { RedisVersionUtil.checkRedisMajorVersionNumber(6)); } + public AccessControlListCommandsTest(RedisProtocol protocol) { + super(protocol); + } + @After @Override public void tearDown() throws Exception { diff --git a/src/test/java/redis/clients/jedis/commands/jedis/AllKindOfValuesCommandsTest.java b/src/test/java/redis/clients/jedis/commands/jedis/AllKindOfValuesCommandsTest.java index a681d4f4d8..e7381a7440 100644 --- a/src/test/java/redis/clients/jedis/commands/jedis/AllKindOfValuesCommandsTest.java +++ b/src/test/java/redis/clients/jedis/commands/jedis/AllKindOfValuesCommandsTest.java @@ -18,6 +18,8 @@ import org.hamcrest.Matchers; import org.junit.Assume; import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; import redis.clients.jedis.HostAndPort; import redis.clients.jedis.Jedis; @@ -35,8 +37,8 @@ import redis.clients.jedis.params.SetParams; import redis.clients.jedis.util.AssertUtil; import redis.clients.jedis.util.KeyValue; -import redis.clients.jedis.util.RedisProtocolUtil; +@RunWith(Parameterized.class) public class AllKindOfValuesCommandsTest extends JedisCommandsTestBase { final byte[] bfoo = { 0x01, 0x02, 0x03, 0x04 }; final byte[] bfoo1 = { 0x01, 0x02, 0x03, 0x04, 0x0A }; @@ -57,6 +59,10 @@ public class AllKindOfValuesCommandsTest extends JedisCommandsTestBase { private static final HostAndPort lfuHnp = HostAndPorts.getRedisServers().get(7); + public AllKindOfValuesCommandsTest(RedisProtocol redisProtocol) { + super(redisProtocol); + } + @Test public void ping() { String status = jedis.ping(); @@ -984,7 +990,7 @@ public void encodeCompleteResponsePing() { @Test public void encodeCompleteResponseHgetall() { - Assume.assumeFalse(RedisProtocolUtil.getRedisProtocol() == RedisProtocol.RESP3); + Assume.assumeFalse(protocol == RedisProtocol.RESP3); HashMap entries = new HashMap<>(); entries.put("foo", "bar"); @@ -1002,7 +1008,7 @@ public void encodeCompleteResponseHgetall() { @Test public void encodeCompleteResponseHgetallResp3() { - Assume.assumeTrue(RedisProtocolUtil.getRedisProtocol() == RedisProtocol.RESP3); + Assume.assumeTrue(protocol == RedisProtocol.RESP3); HashMap entries = new HashMap<>(); entries.put("foo", "bar"); @@ -1019,7 +1025,7 @@ public void encodeCompleteResponseHgetallResp3() { @Test public void encodeCompleteResponseXinfoStream() { - Assume.assumeFalse(RedisProtocolUtil.getRedisProtocol() == RedisProtocol.RESP3); + Assume.assumeFalse(protocol == RedisProtocol.RESP3); HashMap entry = new HashMap<>(); entry.put("foo", "bar"); @@ -1046,7 +1052,7 @@ public void encodeCompleteResponseXinfoStream() { @Test public void encodeCompleteResponseXinfoStreamResp3() { - Assume.assumeTrue(RedisProtocolUtil.getRedisProtocol() == RedisProtocol.RESP3); + Assume.assumeTrue(protocol == RedisProtocol.RESP3); HashMap entry = new HashMap<>(); entry.put("foo", "bar"); diff --git a/src/test/java/redis/clients/jedis/commands/jedis/BinaryValuesCommandsTest.java b/src/test/java/redis/clients/jedis/commands/jedis/BinaryValuesCommandsTest.java index 00c6def7c2..3a348fecc9 100644 --- a/src/test/java/redis/clients/jedis/commands/jedis/BinaryValuesCommandsTest.java +++ b/src/test/java/redis/clients/jedis/commands/jedis/BinaryValuesCommandsTest.java @@ -18,12 +18,16 @@ import org.junit.Before; import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; import redis.clients.jedis.Protocol; +import redis.clients.jedis.RedisProtocol; import redis.clients.jedis.exceptions.JedisDataException; import redis.clients.jedis.params.GetExParams; import redis.clients.jedis.util.SafeEncoder; +@RunWith(Parameterized.class) public class BinaryValuesCommandsTest extends JedisCommandsTestBase { byte[] bfoo = { 0x01, 0x02, 0x03, 0x04 }; byte[] bbar = { 0x05, 0x06, 0x07, 0x08 }; @@ -35,6 +39,10 @@ public class BinaryValuesCommandsTest extends JedisCommandsTestBase { long expireMillis = expireSeconds * 1000; byte[] binaryValue; + public BinaryValuesCommandsTest(RedisProtocol protocol) { + super(protocol); + } + @Before public void startUp() { StringBuilder sb = new StringBuilder(); diff --git a/src/test/java/redis/clients/jedis/commands/jedis/BitCommandsTest.java b/src/test/java/redis/clients/jedis/commands/jedis/BitCommandsTest.java index ab137c7edc..01cc61b3c9 100644 --- a/src/test/java/redis/clients/jedis/commands/jedis/BitCommandsTest.java +++ b/src/test/java/redis/clients/jedis/commands/jedis/BitCommandsTest.java @@ -8,16 +8,24 @@ import java.util.List; import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; import redis.clients.jedis.Protocol; +import redis.clients.jedis.RedisProtocol; import redis.clients.jedis.args.BitCountOption; import redis.clients.jedis.args.BitOP; import redis.clients.jedis.exceptions.JedisDataException; import redis.clients.jedis.params.BitPosParams; import redis.clients.jedis.util.SafeEncoder; +@RunWith(Parameterized.class) public class BitCommandsTest extends JedisCommandsTestBase { + public BitCommandsTest(RedisProtocol protocol) { + super(protocol); + } + @Test public void setAndgetbit() { assertFalse(jedis.setbit("foo", 0, true)); diff --git a/src/test/java/redis/clients/jedis/commands/jedis/ClientCommandsTest.java b/src/test/java/redis/clients/jedis/commands/jedis/ClientCommandsTest.java index 40aff1045c..2a4657ecd5 100644 --- a/src/test/java/redis/clients/jedis/commands/jedis/ClientCommandsTest.java +++ b/src/test/java/redis/clients/jedis/commands/jedis/ClientCommandsTest.java @@ -18,6 +18,8 @@ import org.junit.After; import org.junit.Before; import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; import redis.clients.jedis.DefaultJedisClientConfig; import redis.clients.jedis.Jedis; @@ -29,6 +31,7 @@ import redis.clients.jedis.params.ClientKillParams; import redis.clients.jedis.resps.TrackingInfo; +@RunWith(Parameterized.class) public class ClientCommandsTest extends JedisCommandsTestBase { private final String clientName = "fancy_jedis_name"; @@ -36,6 +39,10 @@ public class ClientCommandsTest extends JedisCommandsTestBase { private Jedis client; + public ClientCommandsTest(RedisProtocol protocol) { + super(protocol); + } + @Before @Override public void setUp() throws Exception { diff --git a/src/test/java/redis/clients/jedis/commands/jedis/ControlCommandsTest.java b/src/test/java/redis/clients/jedis/commands/jedis/ControlCommandsTest.java index cb95a9489b..0287095e4c 100644 --- a/src/test/java/redis/clients/jedis/commands/jedis/ControlCommandsTest.java +++ b/src/test/java/redis/clients/jedis/commands/jedis/ControlCommandsTest.java @@ -24,11 +24,14 @@ import org.hamcrest.MatcherAssert; import org.hamcrest.Matchers; import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; import redis.clients.jedis.DefaultJedisClientConfig; import redis.clients.jedis.Jedis; import redis.clients.jedis.JedisMonitor; import redis.clients.jedis.Protocol; +import redis.clients.jedis.RedisProtocol; import redis.clients.jedis.args.ClientPauseMode; import redis.clients.jedis.args.LatencyEvent; import redis.clients.jedis.exceptions.JedisDataException; @@ -43,8 +46,13 @@ import redis.clients.jedis.util.KeyValue; import redis.clients.jedis.util.SafeEncoder; +@RunWith(Parameterized.class) public class ControlCommandsTest extends JedisCommandsTestBase { + public ControlCommandsTest(RedisProtocol redisProtocol) { + super(redisProtocol); + } + @Test public void save() { try { diff --git a/src/test/java/redis/clients/jedis/commands/jedis/GeoCommandsTest.java b/src/test/java/redis/clients/jedis/commands/jedis/GeoCommandsTest.java index ab8d85558a..04fe32ee84 100644 --- a/src/test/java/redis/clients/jedis/commands/jedis/GeoCommandsTest.java +++ b/src/test/java/redis/clients/jedis/commands/jedis/GeoCommandsTest.java @@ -8,8 +8,11 @@ import java.util.List; import java.util.Map; import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; import redis.clients.jedis.GeoCoordinate; +import redis.clients.jedis.RedisProtocol; import redis.clients.jedis.args.GeoUnit; import redis.clients.jedis.params.GeoSearchParam; import redis.clients.jedis.resps.GeoRadiusResponse; @@ -18,6 +21,7 @@ import redis.clients.jedis.params.GeoRadiusStoreParam; import redis.clients.jedis.util.SafeEncoder; +@RunWith(Parameterized.class) public class GeoCommandsTest extends JedisCommandsTestBase { final byte[] bfoo = { 0x01, 0x02, 0x03, 0x04 }; final byte[] bA = { 0x0A }; @@ -28,6 +32,10 @@ public class GeoCommandsTest extends JedisCommandsTestBase { private static final double EPSILON = 1e-5; + public GeoCommandsTest(RedisProtocol protocol) { + super(protocol); + } + @Test public void geoadd() { assertEquals(1, jedis.geoadd("foo", 1, 2, "a")); diff --git a/src/test/java/redis/clients/jedis/commands/jedis/HashesCommandsTest.java b/src/test/java/redis/clients/jedis/commands/jedis/HashesCommandsTest.java index a30740dcf6..c07adc86b4 100644 --- a/src/test/java/redis/clients/jedis/commands/jedis/HashesCommandsTest.java +++ b/src/test/java/redis/clients/jedis/commands/jedis/HashesCommandsTest.java @@ -23,14 +23,18 @@ import java.util.stream.Collectors; import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; import redis.clients.jedis.Pipeline; +import redis.clients.jedis.RedisProtocol; import redis.clients.jedis.Response; import redis.clients.jedis.params.ScanParams; import redis.clients.jedis.resps.ScanResult; import redis.clients.jedis.util.AssertUtil; import redis.clients.jedis.util.JedisByteHashMap; +@RunWith(Parameterized.class) public class HashesCommandsTest extends JedisCommandsTestBase { final byte[] bfoo = { 0x01, 0x02, 0x03, 0x04 }; final byte[] bbar = { 0x05, 0x06, 0x07, 0x08 }; @@ -41,6 +45,10 @@ public class HashesCommandsTest extends JedisCommandsTestBase { final byte[] bbar3 = { 0x05, 0x06, 0x07, 0x08, 0x0C }; final byte[] bbarstar = { 0x05, 0x06, 0x07, 0x08, '*' }; + public HashesCommandsTest(RedisProtocol protocol) { + super(protocol); + } + @Test public void hset() { assertEquals(1, jedis.hset("foo", "bar", "car")); diff --git a/src/test/java/redis/clients/jedis/commands/jedis/HyperLogLogCommandsTest.java b/src/test/java/redis/clients/jedis/commands/jedis/HyperLogLogCommandsTest.java index 9b989cf9e1..3367070707 100644 --- a/src/test/java/redis/clients/jedis/commands/jedis/HyperLogLogCommandsTest.java +++ b/src/test/java/redis/clients/jedis/commands/jedis/HyperLogLogCommandsTest.java @@ -3,11 +3,19 @@ import static org.junit.Assert.assertEquals; import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import redis.clients.jedis.RedisProtocol; import redis.clients.jedis.util.SafeEncoder; +@RunWith(Parameterized.class) public class HyperLogLogCommandsTest extends JedisCommandsTestBase { + public HyperLogLogCommandsTest(RedisProtocol protocol) { + super(protocol); + } + @Test public void pfadd() { long status = jedis.pfadd("foo", "a"); diff --git a/src/test/java/redis/clients/jedis/commands/jedis/JedisCommandsTestBase.java b/src/test/java/redis/clients/jedis/commands/jedis/JedisCommandsTestBase.java index c69302d3c5..1d40a22b5f 100644 --- a/src/test/java/redis/clients/jedis/commands/jedis/JedisCommandsTestBase.java +++ b/src/test/java/redis/clients/jedis/commands/jedis/JedisCommandsTestBase.java @@ -1,29 +1,54 @@ package redis.clients.jedis.commands.jedis; +import java.util.Collection; + import org.junit.After; import org.junit.Before; - +import org.junit.runners.Parameterized.Parameters; import redis.clients.jedis.DefaultJedisClientConfig; import redis.clients.jedis.HostAndPort; -import redis.clients.jedis.Jedis; import redis.clients.jedis.HostAndPorts; -import redis.clients.jedis.util.RedisProtocolUtil; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.RedisProtocol; +import redis.clients.jedis.commands.CommandsTestsParameters; public abstract class JedisCommandsTestBase { + /** + * Input data for parameterized tests. In principle all subclasses of this + * class should be parameterized tests, to run with several versions of RESP. + * + * @see CommandsTestsParameters#respVersions() + */ + @Parameters + public static Collection data() { + return CommandsTestsParameters.respVersions(); + } + protected static final HostAndPort hnp = HostAndPorts.getRedisServers().get(0); + protected final RedisProtocol protocol; + protected Jedis jedis; - public JedisCommandsTestBase() { - super(); + /** + * The RESP protocol is to be injected by the subclasses, usually via JUnit + * parameterized tests, because most of the subclassed tests are meant to be + * executed against multiple RESP versions. For the special cases where a single + * RESP version is relevant, we still force the subclass to be explicit and + * call this constructor. + * + * @param protocol The RESP protocol to use during the tests. + */ + public JedisCommandsTestBase(RedisProtocol protocol) { + this.protocol = protocol; } @Before public void setUp() throws Exception { // jedis = new Jedis(hnp, DefaultJedisClientConfig.builder().timeoutMillis(500).password("foobared").build()); jedis = new Jedis(hnp, DefaultJedisClientConfig.builder() - .protocol(RedisProtocolUtil.getRedisProtocol()).timeoutMillis(500).password("foobared").build()); + .protocol(protocol).timeoutMillis(500).password("foobared").build()); jedis.flushAll(); } @@ -35,6 +60,6 @@ public void tearDown() throws Exception { protected Jedis createJedis() { // return new Jedis(hnp, DefaultJedisClientConfig.builder().password("foobared").build()); return new Jedis(hnp, DefaultJedisClientConfig.builder() - .protocol(RedisProtocolUtil.getRedisProtocol()).password("foobared").build()); + .protocol(protocol).password("foobared").build()); } } diff --git a/src/test/java/redis/clients/jedis/commands/jedis/ListCommandsTest.java b/src/test/java/redis/clients/jedis/commands/jedis/ListCommandsTest.java index 6f6fa80749..194bed29ae 100644 --- a/src/test/java/redis/clients/jedis/commands/jedis/ListCommandsTest.java +++ b/src/test/java/redis/clients/jedis/commands/jedis/ListCommandsTest.java @@ -14,16 +14,20 @@ import java.util.List; import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import redis.clients.jedis.Jedis; +import redis.clients.jedis.RedisProtocol; import redis.clients.jedis.args.ListPosition; import redis.clients.jedis.args.ListDirection; import redis.clients.jedis.exceptions.JedisDataException; import redis.clients.jedis.params.LPosParams; import redis.clients.jedis.util.KeyValue; +@RunWith(Parameterized.class) public class ListCommandsTest extends JedisCommandsTestBase { private final Logger logger = LoggerFactory.getLogger(getClass()); @@ -42,6 +46,10 @@ public class ListCommandsTest extends JedisCommandsTestBase { final byte[] bx = { 0x02, 0x04 }; final byte[] bdst = { 0x11, 0x12, 0x13, 0x14 }; + public ListCommandsTest(RedisProtocol protocol) { + super(protocol); + } + @Test public void rpush() { assertEquals(1, jedis.rpush("foo", "bar")); diff --git a/src/test/java/redis/clients/jedis/commands/jedis/MigrateTest.java b/src/test/java/redis/clients/jedis/commands/jedis/MigrateTest.java index 1a0f7a0b6e..529d64ebbf 100644 --- a/src/test/java/redis/clients/jedis/commands/jedis/MigrateTest.java +++ b/src/test/java/redis/clients/jedis/commands/jedis/MigrateTest.java @@ -9,12 +9,16 @@ import org.junit.After; import org.junit.Before; import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; import redis.clients.jedis.Jedis; import redis.clients.jedis.Protocol; +import redis.clients.jedis.RedisProtocol; import redis.clients.jedis.exceptions.JedisDataException; import redis.clients.jedis.params.MigrateParams; +@RunWith(Parameterized.class) public class MigrateTest extends JedisCommandsTestBase { private static final byte[] bfoo = { 0x01, 0x02, 0x03 }; @@ -35,6 +39,10 @@ public class MigrateTest extends JedisCommandsTestBase { private static final int dbAuth = 3; private static final int timeout = Protocol.DEFAULT_TIMEOUT; + public MigrateTest(RedisProtocol protocol) { + super(protocol); + } + @Before @Override public void setUp() throws Exception { diff --git a/src/test/java/redis/clients/jedis/commands/jedis/ModuleTest.java b/src/test/java/redis/clients/jedis/commands/jedis/ModuleTest.java index 1d4a9d981b..bef13001ef 100644 --- a/src/test/java/redis/clients/jedis/commands/jedis/ModuleTest.java +++ b/src/test/java/redis/clients/jedis/commands/jedis/ModuleTest.java @@ -6,11 +6,15 @@ import java.util.Collections; import java.util.List; import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; import redis.clients.jedis.Module; +import redis.clients.jedis.RedisProtocol; import redis.clients.jedis.commands.ProtocolCommand; import redis.clients.jedis.util.SafeEncoder; +@RunWith(Parameterized.class) public class ModuleTest extends JedisCommandsTestBase { static enum ModuleCommand implements ProtocolCommand { @@ -29,6 +33,10 @@ public byte[] getRaw() { } } + public ModuleTest(RedisProtocol protocol) { + super(protocol); + } + @Test public void testModules() { try { diff --git a/src/test/java/redis/clients/jedis/commands/jedis/ObjectCommandsTest.java b/src/test/java/redis/clients/jedis/commands/jedis/ObjectCommandsTest.java index 79b30ced9c..0f4cf70b15 100644 --- a/src/test/java/redis/clients/jedis/commands/jedis/ObjectCommandsTest.java +++ b/src/test/java/redis/clients/jedis/commands/jedis/ObjectCommandsTest.java @@ -10,13 +10,17 @@ import org.junit.After; import org.junit.Before; import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; import redis.clients.jedis.HostAndPort; import redis.clients.jedis.Jedis; +import redis.clients.jedis.RedisProtocol; import redis.clients.jedis.exceptions.JedisDataException; import redis.clients.jedis.HostAndPorts; import redis.clients.jedis.util.SafeEncoder; +@RunWith(Parameterized.class) public class ObjectCommandsTest extends JedisCommandsTestBase { private final String key = "mylist"; @@ -24,6 +28,10 @@ public class ObjectCommandsTest extends JedisCommandsTestBase { private final HostAndPort lfuHnp = HostAndPorts.getRedisServers().get(7); private Jedis lfuJedis; + public ObjectCommandsTest(RedisProtocol protocol) { + super(protocol); + } + @Before @Override public void setUp() throws Exception { diff --git a/src/test/java/redis/clients/jedis/commands/jedis/PublishSubscribeCommandsTest.java b/src/test/java/redis/clients/jedis/commands/jedis/PublishSubscribeCommandsTest.java index 7b11d323ca..75968fdc04 100644 --- a/src/test/java/redis/clients/jedis/commands/jedis/PublishSubscribeCommandsTest.java +++ b/src/test/java/redis/clients/jedis/commands/jedis/PublishSubscribeCommandsTest.java @@ -17,14 +17,23 @@ import java.util.concurrent.atomic.AtomicBoolean; import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; import redis.clients.jedis.BinaryJedisPubSub; import redis.clients.jedis.Jedis; import redis.clients.jedis.JedisPubSub; +import redis.clients.jedis.RedisProtocol; import redis.clients.jedis.exceptions.JedisException; import redis.clients.jedis.util.SafeEncoder; +@RunWith(Parameterized.class) public class PublishSubscribeCommandsTest extends JedisCommandsTestBase { + + public PublishSubscribeCommandsTest(RedisProtocol protocol) { + super(protocol); + } + private void publishOne(final String channel, final String message) { Thread t = new Thread(new Runnable() { public void run() { diff --git a/src/test/java/redis/clients/jedis/commands/jedis/ScriptingCommandsTest.java b/src/test/java/redis/clients/jedis/commands/jedis/ScriptingCommandsTest.java index 1e258dbad3..5f26baec58 100644 --- a/src/test/java/redis/clients/jedis/commands/jedis/ScriptingCommandsTest.java +++ b/src/test/java/redis/clients/jedis/commands/jedis/ScriptingCommandsTest.java @@ -12,6 +12,8 @@ import org.hamcrest.Matchers; import org.junit.Before; import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; import redis.clients.jedis.Jedis; import redis.clients.jedis.RedisProtocol; @@ -24,11 +26,15 @@ import redis.clients.jedis.resps.LibraryInfo; import redis.clients.jedis.util.ClientKillerUtil; import redis.clients.jedis.util.KeyValue; -import redis.clients.jedis.util.RedisProtocolUtil; import redis.clients.jedis.util.SafeEncoder; +@RunWith(Parameterized.class) public class ScriptingCommandsTest extends JedisCommandsTestBase { + public ScriptingCommandsTest(RedisProtocol redisProtocol) { + super(redisProtocol); + } + @Before @Override public void setUp() throws Exception { @@ -390,7 +396,7 @@ public void functionList() { assertEquals(functionCode, response.getLibraryCode()); // Binary - if (RedisProtocolUtil.getRedisProtocol() != RedisProtocol.RESP3) { + if (protocol != RedisProtocol.RESP3) { List bresponse = (List) jedis.functionListBinary().get(0); assertArrayEquals(library.getBytes(), (byte[]) bresponse.get(1)); diff --git a/src/test/java/redis/clients/jedis/commands/jedis/SetCommandsTest.java b/src/test/java/redis/clients/jedis/commands/jedis/SetCommandsTest.java index 4d29392fce..d2b660b5b4 100644 --- a/src/test/java/redis/clients/jedis/commands/jedis/SetCommandsTest.java +++ b/src/test/java/redis/clients/jedis/commands/jedis/SetCommandsTest.java @@ -20,10 +20,14 @@ import java.util.Set; import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import redis.clients.jedis.RedisProtocol; import redis.clients.jedis.params.ScanParams; import redis.clients.jedis.resps.ScanResult; +@RunWith(Parameterized.class) public class SetCommandsTest extends JedisCommandsTestBase { final byte[] bfoo = { 0x01, 0x02, 0x03, 0x04 }; final byte[] bbar = { 0x05, 0x06, 0x07, 0x08 }; @@ -39,6 +43,10 @@ public class SetCommandsTest extends JedisCommandsTestBase { final byte[] bbar3 = { 0x05, 0x06, 0x07, 0x08, 0x0C }; final byte[] bbarstar = { 0x05, 0x06, 0x07, 0x08, '*' }; + public SetCommandsTest(RedisProtocol protocol) { + super(protocol); + } + @Test public void sadd() { long status = jedis.sadd("foo", "a"); diff --git a/src/test/java/redis/clients/jedis/commands/jedis/SlowlogCommandsTest.java b/src/test/java/redis/clients/jedis/commands/jedis/SlowlogCommandsTest.java index 66806b933a..c62daa4aa1 100644 --- a/src/test/java/redis/clients/jedis/commands/jedis/SlowlogCommandsTest.java +++ b/src/test/java/redis/clients/jedis/commands/jedis/SlowlogCommandsTest.java @@ -11,11 +11,15 @@ import org.junit.After; import org.junit.Before; import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; import redis.clients.jedis.Protocol; +import redis.clients.jedis.RedisProtocol; import redis.clients.jedis.resps.Slowlog; import redis.clients.jedis.util.SafeEncoder; +@RunWith(Parameterized.class) public class SlowlogCommandsTest extends JedisCommandsTestBase { private static final List LOCAL_IPS = Arrays.asList("127.0.0.1", "[::1]"); @@ -25,6 +29,10 @@ public class SlowlogCommandsTest extends JedisCommandsTestBase { private String slowlogTimeValue; + public SlowlogCommandsTest(RedisProtocol protocol) { + super(protocol); + } + @Before @Override public void setUp() throws Exception { @@ -84,7 +92,7 @@ public void slowlogObjectDetails() { Slowlog log = logs.get(0); assertThat(log.getId(), Matchers.greaterThan(0L)); assertThat(log.getTimeStamp(), Matchers.greaterThan(0L)); - assertThat(log.getExecutionTime(), Matchers.greaterThan(0L)); + assertThat(log.getExecutionTime(), Matchers.greaterThanOrEqualTo(0L)); assertEquals(4, log.getArgs().size()); assertEquals(SafeEncoder.encode(Protocol.Command.CONFIG.getRaw()), log.getArgs().get(0)); assertEquals(SafeEncoder.encode(Protocol.Keyword.SET.getRaw()), log.getArgs().get(1)); diff --git a/src/test/java/redis/clients/jedis/commands/jedis/SortedSetCommandsTest.java b/src/test/java/redis/clients/jedis/commands/jedis/SortedSetCommandsTest.java index 8b5711cb70..6860684028 100644 --- a/src/test/java/redis/clients/jedis/commands/jedis/SortedSetCommandsTest.java +++ b/src/test/java/redis/clients/jedis/commands/jedis/SortedSetCommandsTest.java @@ -8,7 +8,10 @@ import java.util.*; import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import redis.clients.jedis.RedisProtocol; import redis.clients.jedis.args.SortedSetOption; import redis.clients.jedis.params.*; import redis.clients.jedis.resps.ScanResult; @@ -17,6 +20,7 @@ import redis.clients.jedis.util.KeyValue; import redis.clients.jedis.util.SafeEncoder; +@RunWith(Parameterized.class) public class SortedSetCommandsTest extends JedisCommandsTestBase { final byte[] bfoo = { 0x01, 0x02, 0x03, 0x04 }; final byte[] bbar = { 0x05, 0x06, 0x07, 0x08 }; @@ -34,6 +38,10 @@ public class SortedSetCommandsTest extends JedisCommandsTestBase { final byte[] bbar3 = { 0x05, 0x06, 0x07, 0x08, 0x0C }; final byte[] bbarstar = { 0x05, 0x06, 0x07, 0x08, '*' }; + public SortedSetCommandsTest(RedisProtocol protocol) { + super(protocol); + } + @Test public void zadd() { assertEquals(1, jedis.zadd("foo", 1d, "a")); diff --git a/src/test/java/redis/clients/jedis/commands/jedis/SortingCommandsTest.java b/src/test/java/redis/clients/jedis/commands/jedis/SortingCommandsTest.java index e56fa6447a..1d0a976f41 100644 --- a/src/test/java/redis/clients/jedis/commands/jedis/SortingCommandsTest.java +++ b/src/test/java/redis/clients/jedis/commands/jedis/SortingCommandsTest.java @@ -7,9 +7,13 @@ import java.util.List; import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import redis.clients.jedis.RedisProtocol; import redis.clients.jedis.params.SortingParams; +@RunWith(Parameterized.class) public class SortingCommandsTest extends JedisCommandsTestBase { final byte[] bfoo = { 0x01, 0x02, 0x03, 0x04 }; final byte[] bfoodest = { 0x01, 0x02, 0x03, 0x04, 0x05 }; @@ -27,6 +31,10 @@ public class SortingCommandsTest extends JedisCommandsTestBase { final byte[] b3 = { '3' }; final byte[] b10 = { '1', '0' }; + public SortingCommandsTest(RedisProtocol protocol) { + super(protocol); + } + @Test public void sort() { jedis.lpush("foo", "3"); diff --git a/src/test/java/redis/clients/jedis/commands/jedis/StreamsCommandsTest.java b/src/test/java/redis/clients/jedis/commands/jedis/StreamsCommandsTest.java index 6b28f9ed19..acadc0b75d 100644 --- a/src/test/java/redis/clients/jedis/commands/jedis/StreamsCommandsTest.java +++ b/src/test/java/redis/clients/jedis/commands/jedis/StreamsCommandsTest.java @@ -18,10 +18,13 @@ import org.hamcrest.MatcherAssert; import org.hamcrest.Matchers; import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; import redis.clients.jedis.BuilderFactory; import redis.clients.jedis.Jedis; import redis.clients.jedis.Pipeline; +import redis.clients.jedis.RedisProtocol; import redis.clients.jedis.Response; import redis.clients.jedis.StreamEntryID; import redis.clients.jedis.Transaction; @@ -31,8 +34,13 @@ import redis.clients.jedis.resps.*; import redis.clients.jedis.util.SafeEncoder; +@RunWith(Parameterized.class) public class StreamsCommandsTest extends JedisCommandsTestBase { + public StreamsCommandsTest(RedisProtocol protocol) { + super(protocol); + } + @Test public void xadd() { diff --git a/src/test/java/redis/clients/jedis/commands/jedis/StringValuesCommandsTest.java b/src/test/java/redis/clients/jedis/commands/jedis/StringValuesCommandsTest.java index fb58569e82..44525e072f 100644 --- a/src/test/java/redis/clients/jedis/commands/jedis/StringValuesCommandsTest.java +++ b/src/test/java/redis/clients/jedis/commands/jedis/StringValuesCommandsTest.java @@ -7,13 +7,22 @@ import java.util.ArrayList; import java.util.List; import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import redis.clients.jedis.RedisProtocol; import redis.clients.jedis.params.LCSParams; import redis.clients.jedis.resps.LCSMatchResult; import redis.clients.jedis.exceptions.JedisDataException; import redis.clients.jedis.params.GetExParams; +@RunWith(Parameterized.class) public class StringValuesCommandsTest extends JedisCommandsTestBase { + + public StringValuesCommandsTest(RedisProtocol protocol) { + super(protocol); + } + @Test public void setAndGet() { String status = jedis.set("foo", "bar"); diff --git a/src/test/java/redis/clients/jedis/commands/jedis/TransactionCommandsTest.java b/src/test/java/redis/clients/jedis/commands/jedis/TransactionCommandsTest.java index a2153e6862..5130552009 100644 --- a/src/test/java/redis/clients/jedis/commands/jedis/TransactionCommandsTest.java +++ b/src/test/java/redis/clients/jedis/commands/jedis/TransactionCommandsTest.java @@ -15,18 +15,22 @@ import org.junit.After; import org.junit.Before; import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; import org.mockito.MockedStatic; import org.mockito.Mockito; import redis.clients.jedis.DefaultJedisClientConfig; import redis.clients.jedis.Jedis; import redis.clients.jedis.Protocol; +import redis.clients.jedis.RedisProtocol; import redis.clients.jedis.Response; import redis.clients.jedis.Transaction; import redis.clients.jedis.exceptions.JedisConnectionException; import redis.clients.jedis.exceptions.JedisDataException; import redis.clients.jedis.util.SafeEncoder; +@RunWith(Parameterized.class) public class TransactionCommandsTest extends JedisCommandsTestBase { final byte[] bfoo = { 0x01, 0x02, 0x03, 0x04 }; final byte[] bbar = { 0x05, 0x06, 0x07, 0x08 }; @@ -37,6 +41,10 @@ public class TransactionCommandsTest extends JedisCommandsTestBase { Jedis nj; + public TransactionCommandsTest(RedisProtocol protocol) { + super(protocol); + } + @Before @Override public void setUp() throws Exception { diff --git a/src/test/java/redis/clients/jedis/commands/jedis/VariadicCommandsTest.java b/src/test/java/redis/clients/jedis/commands/jedis/VariadicCommandsTest.java index 35c3127cc9..337aceab7b 100644 --- a/src/test/java/redis/clients/jedis/commands/jedis/VariadicCommandsTest.java +++ b/src/test/java/redis/clients/jedis/commands/jedis/VariadicCommandsTest.java @@ -9,7 +9,12 @@ import java.util.List; import java.util.Map; import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import redis.clients.jedis.RedisProtocol; + +@RunWith(Parameterized.class) public class VariadicCommandsTest extends JedisCommandsTestBase { final byte[] bfoo = { 0x01, 0x02, 0x03, 0x04 }; final byte[] bbar = { 0x05, 0x06, 0x07, 0x08 }; @@ -17,6 +22,10 @@ public class VariadicCommandsTest extends JedisCommandsTestBase { final byte[] bfoo1 = { 0x01, 0x02, 0x03, 0x04, 0x0A }; final byte[] bfoo2 = { 0x01, 0x02, 0x03, 0x04, 0x0B }; + public VariadicCommandsTest(RedisProtocol protocol) { + super(protocol); + } + @Test public void hdel() { Map hash = new HashMap(); diff --git a/src/test/java/redis/clients/jedis/commands/unified/AllKindOfValuesCommandsTestBase.java b/src/test/java/redis/clients/jedis/commands/unified/AllKindOfValuesCommandsTestBase.java index 25ecad1eea..f31c100988 100644 --- a/src/test/java/redis/clients/jedis/commands/unified/AllKindOfValuesCommandsTestBase.java +++ b/src/test/java/redis/clients/jedis/commands/unified/AllKindOfValuesCommandsTestBase.java @@ -44,7 +44,6 @@ import redis.clients.jedis.params.SetParams; import redis.clients.jedis.util.AssertUtil; import redis.clients.jedis.util.KeyValue; -import redis.clients.jedis.util.RedisProtocolUtil; import redis.clients.jedis.util.SafeEncoder; public abstract class AllKindOfValuesCommandsTestBase extends UnifiedJedisCommandsTestBase { @@ -66,6 +65,10 @@ public abstract class AllKindOfValuesCommandsTestBase extends UnifiedJedisComman protected final byte[] bex = { 0x65, 0x78 }; final int expireSeconds = 2; + public AllKindOfValuesCommandsTestBase(RedisProtocol protocol) { + super(protocol); + } + @Test public void exists() { String status = jedis.set("foo", "bar"); @@ -801,7 +804,7 @@ public void encodeCompleteResponsePing() { @Test public void encodeCompleteResponseHgetall() { - Assume.assumeFalse(RedisProtocolUtil.getRedisProtocol() == RedisProtocol.RESP3); + Assume.assumeFalse(protocol == RedisProtocol.RESP3); HashMap entries = new HashMap<>(); entries.put("foo", "bar"); @@ -819,7 +822,7 @@ public void encodeCompleteResponseHgetall() { @Test public void encodeCompleteResponseHgetallResp3() { - Assume.assumeTrue(RedisProtocolUtil.getRedisProtocol() == RedisProtocol.RESP3); + Assume.assumeTrue(protocol == RedisProtocol.RESP3); HashMap entries = new HashMap<>(); entries.put("foo", "bar"); @@ -836,7 +839,7 @@ public void encodeCompleteResponseHgetallResp3() { @Test public void encodeCompleteResponseXinfoStream() { - Assume.assumeFalse(RedisProtocolUtil.getRedisProtocol() == RedisProtocol.RESP3); + Assume.assumeFalse(protocol == RedisProtocol.RESP3); HashMap entry = new HashMap<>(); entry.put("foo", "bar"); @@ -863,7 +866,7 @@ public void encodeCompleteResponseXinfoStream() { @Test public void encodeCompleteResponseXinfoStreamResp3() { - Assume.assumeTrue(RedisProtocolUtil.getRedisProtocol() == RedisProtocol.RESP3); + Assume.assumeTrue(protocol == RedisProtocol.RESP3); HashMap entry = new HashMap<>(); entry.put("foo", "bar"); diff --git a/src/test/java/redis/clients/jedis/commands/unified/BinaryValuesCommandsTestBase.java b/src/test/java/redis/clients/jedis/commands/unified/BinaryValuesCommandsTestBase.java index 941d70c383..48a3ef7e6d 100644 --- a/src/test/java/redis/clients/jedis/commands/unified/BinaryValuesCommandsTestBase.java +++ b/src/test/java/redis/clients/jedis/commands/unified/BinaryValuesCommandsTestBase.java @@ -20,6 +20,7 @@ import org.junit.Test; import redis.clients.jedis.Protocol; +import redis.clients.jedis.RedisProtocol; import redis.clients.jedis.exceptions.JedisDataException; import redis.clients.jedis.params.GetExParams; import redis.clients.jedis.util.SafeEncoder; @@ -35,6 +36,10 @@ public abstract class BinaryValuesCommandsTestBase extends UnifiedJedisCommandsT protected long expireMillis = expireSeconds * 1000; protected byte[] binaryValue; + public BinaryValuesCommandsTestBase(RedisProtocol protocol) { + super(protocol); + } + @Before public void startUp() { StringBuilder sb = new StringBuilder(); diff --git a/src/test/java/redis/clients/jedis/commands/unified/BitCommandsTestBase.java b/src/test/java/redis/clients/jedis/commands/unified/BitCommandsTestBase.java index 8cf5caf3f0..2101900889 100644 --- a/src/test/java/redis/clients/jedis/commands/unified/BitCommandsTestBase.java +++ b/src/test/java/redis/clients/jedis/commands/unified/BitCommandsTestBase.java @@ -10,6 +10,7 @@ import org.junit.Test; import redis.clients.jedis.Protocol; +import redis.clients.jedis.RedisProtocol; import redis.clients.jedis.args.BitCountOption; import redis.clients.jedis.args.BitOP; import redis.clients.jedis.exceptions.JedisDataException; @@ -18,6 +19,10 @@ public abstract class BitCommandsTestBase extends UnifiedJedisCommandsTestBase { + public BitCommandsTestBase(RedisProtocol protocol) { + super(protocol); + } + @Test public void setAndgetbit() { assertFalse(jedis.setbit("foo", 0, true)); diff --git a/src/test/java/redis/clients/jedis/commands/unified/GeoCommandsTestBase.java b/src/test/java/redis/clients/jedis/commands/unified/GeoCommandsTestBase.java index e93042eed9..63cd661ccb 100644 --- a/src/test/java/redis/clients/jedis/commands/unified/GeoCommandsTestBase.java +++ b/src/test/java/redis/clients/jedis/commands/unified/GeoCommandsTestBase.java @@ -10,6 +10,7 @@ import org.junit.Test; import redis.clients.jedis.GeoCoordinate; +import redis.clients.jedis.RedisProtocol; import redis.clients.jedis.args.GeoUnit; import redis.clients.jedis.params.GeoSearchParam; import redis.clients.jedis.resps.GeoRadiusResponse; @@ -28,6 +29,10 @@ public abstract class GeoCommandsTestBase extends UnifiedJedisCommandsTestBase { private static final double EPSILON = 1e-5; + public GeoCommandsTestBase(RedisProtocol protocol) { + super(protocol); + } + @Test public void geoadd() { assertEquals(1, jedis.geoadd("foo", 1, 2, "a")); diff --git a/src/test/java/redis/clients/jedis/commands/unified/HashesCommandsTestBase.java b/src/test/java/redis/clients/jedis/commands/unified/HashesCommandsTestBase.java index d06edf38ec..401f29dbe3 100644 --- a/src/test/java/redis/clients/jedis/commands/unified/HashesCommandsTestBase.java +++ b/src/test/java/redis/clients/jedis/commands/unified/HashesCommandsTestBase.java @@ -24,6 +24,7 @@ import org.junit.Test; +import redis.clients.jedis.RedisProtocol; import redis.clients.jedis.params.ScanParams; import redis.clients.jedis.resps.ScanResult; import redis.clients.jedis.util.AssertUtil; @@ -40,6 +41,10 @@ public abstract class HashesCommandsTestBase extends UnifiedJedisCommandsTestBas final byte[] bbar3 = { 0x05, 0x06, 0x07, 0x08, 0x0C }; final byte[] bbarstar = { 0x05, 0x06, 0x07, 0x08, '*' }; + public HashesCommandsTestBase(RedisProtocol protocol) { + super(protocol); + } + @Test public void hset() { assertEquals(1, jedis.hset("foo", "bar", "car")); diff --git a/src/test/java/redis/clients/jedis/commands/unified/HyperLogLogCommandsTestBase.java b/src/test/java/redis/clients/jedis/commands/unified/HyperLogLogCommandsTestBase.java index 79a82f69f2..06b6d312df 100644 --- a/src/test/java/redis/clients/jedis/commands/unified/HyperLogLogCommandsTestBase.java +++ b/src/test/java/redis/clients/jedis/commands/unified/HyperLogLogCommandsTestBase.java @@ -4,10 +4,15 @@ import org.junit.Test; +import redis.clients.jedis.RedisProtocol; import redis.clients.jedis.util.SafeEncoder; public abstract class HyperLogLogCommandsTestBase extends UnifiedJedisCommandsTestBase { + public HyperLogLogCommandsTestBase(RedisProtocol protocol) { + super(protocol); + } + @Test public void pfadd() { long status = jedis.pfadd("foo", "a"); diff --git a/src/test/java/redis/clients/jedis/commands/unified/ListCommandsTestBase.java b/src/test/java/redis/clients/jedis/commands/unified/ListCommandsTestBase.java index ddbe7f779a..05c741de41 100644 --- a/src/test/java/redis/clients/jedis/commands/unified/ListCommandsTestBase.java +++ b/src/test/java/redis/clients/jedis/commands/unified/ListCommandsTestBase.java @@ -17,6 +17,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import redis.clients.jedis.RedisProtocol; import redis.clients.jedis.args.ListPosition; import redis.clients.jedis.args.ListDirection; import redis.clients.jedis.exceptions.JedisDataException; @@ -41,6 +42,10 @@ public abstract class ListCommandsTestBase extends UnifiedJedisCommandsTestBase protected final byte[] bx = { 0x02, 0x04 }; protected final byte[] bdst = { 0x11, 0x12, 0x13, 0x14 }; + public ListCommandsTestBase(RedisProtocol protocol) { + super(protocol); + } + @Test public void rpush() { assertEquals(1, jedis.rpush("foo", "bar")); diff --git a/src/test/java/redis/clients/jedis/commands/unified/SetCommandsTestBase.java b/src/test/java/redis/clients/jedis/commands/unified/SetCommandsTestBase.java index eed0801a86..d4c1456218 100644 --- a/src/test/java/redis/clients/jedis/commands/unified/SetCommandsTestBase.java +++ b/src/test/java/redis/clients/jedis/commands/unified/SetCommandsTestBase.java @@ -21,6 +21,7 @@ import org.junit.Test; +import redis.clients.jedis.RedisProtocol; import redis.clients.jedis.params.ScanParams; import redis.clients.jedis.resps.ScanResult; @@ -39,6 +40,10 @@ public abstract class SetCommandsTestBase extends UnifiedJedisCommandsTestBase { final byte[] bbar3 = { 0x05, 0x06, 0x07, 0x08, 0x0C }; final byte[] bbarstar = { 0x05, 0x06, 0x07, 0x08, '*' }; + public SetCommandsTestBase(RedisProtocol protocol) { + super(protocol); + } + @Test public void sadd() { long status = jedis.sadd("foo", "a"); @@ -549,7 +554,7 @@ public void srandmember() { member = jedis.srandmember("bar"); assertNull(member); - + members = jedis.srandmember("bar", 2); assertEquals(0, members.size()); @@ -561,13 +566,13 @@ public void srandmember() { assertTrue(Arrays.equals(ba, bmember) || Arrays.equals(bb, bmember)); assertEquals(2, jedis.smembers(bfoo).size()); - + List bmembers = jedis.srandmember(bfoo, 2); assertEquals(2, bmembers.size()); bmember = jedis.srandmember(bbar); assertNull(bmember); - + members = jedis.srandmember("bbar", 2); assertEquals(0, members.size()); } diff --git a/src/test/java/redis/clients/jedis/commands/unified/SortedSetCommandsTestBase.java b/src/test/java/redis/clients/jedis/commands/unified/SortedSetCommandsTestBase.java index fed8fb2603..3f56a91459 100644 --- a/src/test/java/redis/clients/jedis/commands/unified/SortedSetCommandsTestBase.java +++ b/src/test/java/redis/clients/jedis/commands/unified/SortedSetCommandsTestBase.java @@ -9,6 +9,7 @@ import java.util.*; import org.junit.Test; +import redis.clients.jedis.RedisProtocol; import redis.clients.jedis.args.SortedSetOption; import redis.clients.jedis.params.*; import redis.clients.jedis.resps.ScanResult; @@ -34,6 +35,10 @@ public abstract class SortedSetCommandsTestBase extends UnifiedJedisCommandsTest final byte[] bbar3 = { 0x05, 0x06, 0x07, 0x08, 0x0C }; final byte[] bbarstar = { 0x05, 0x06, 0x07, 0x08, '*' }; + public SortedSetCommandsTestBase(RedisProtocol protocol) { + super(protocol); + } + @Test public void zadd() { assertEquals(1, jedis.zadd("foo", 1d, "a")); diff --git a/src/test/java/redis/clients/jedis/commands/unified/StringValuesCommandsTestBase.java b/src/test/java/redis/clients/jedis/commands/unified/StringValuesCommandsTestBase.java index a666671a15..8309978fad 100644 --- a/src/test/java/redis/clients/jedis/commands/unified/StringValuesCommandsTestBase.java +++ b/src/test/java/redis/clients/jedis/commands/unified/StringValuesCommandsTestBase.java @@ -8,12 +8,18 @@ import java.util.List; import org.junit.Test; +import redis.clients.jedis.RedisProtocol; import redis.clients.jedis.params.LCSParams; import redis.clients.jedis.resps.LCSMatchResult; import redis.clients.jedis.exceptions.JedisDataException; import redis.clients.jedis.params.GetExParams; public abstract class StringValuesCommandsTestBase extends UnifiedJedisCommandsTestBase { + + public StringValuesCommandsTestBase(RedisProtocol protocol) { + super(protocol); + } + @Test public void setAndGet() { String status = jedis.set("foo", "bar"); diff --git a/src/test/java/redis/clients/jedis/commands/unified/UnifiedJedisCommandsTestBase.java b/src/test/java/redis/clients/jedis/commands/unified/UnifiedJedisCommandsTestBase.java index cbd046231d..c4aabad5a3 100644 --- a/src/test/java/redis/clients/jedis/commands/unified/UnifiedJedisCommandsTestBase.java +++ b/src/test/java/redis/clients/jedis/commands/unified/UnifiedJedisCommandsTestBase.java @@ -1,11 +1,39 @@ package redis.clients.jedis.commands.unified; +import java.util.Collection; + +import org.junit.runners.Parameterized; +import redis.clients.jedis.RedisProtocol; import redis.clients.jedis.UnifiedJedis; +import redis.clients.jedis.commands.CommandsTestsParameters; public abstract class UnifiedJedisCommandsTestBase { - protected static UnifiedJedis jedis; + /** + * Input data for parameterized tests. In principle all subclasses of this + * class should be parameterized tests, to run with several versions of RESP. + * + * @see CommandsTestsParameters#respVersions() + */ + @Parameterized.Parameters + public static Collection data() { + return CommandsTestsParameters.respVersions(); + } + + protected final RedisProtocol protocol; + + protected UnifiedJedis jedis; - public UnifiedJedisCommandsTestBase() { + /** + * The RESP protocol is to be injected by the subclasses, usually via JUnit + * parameterized tests, because most of the subclassed tests are meant to be + * executed against multiple RESP versions. For the special cases where a single + * RESP version is relevant, we still force the subclass to be explicit and + * call this constructor. + * + * @param protocol The RESP protocol to use during the tests. + */ + public UnifiedJedisCommandsTestBase(RedisProtocol protocol) { + this.protocol = protocol; } } diff --git a/src/test/java/redis/clients/jedis/commands/unified/cluster/ClusterAllKindOfValuesCommandsTest.java b/src/test/java/redis/clients/jedis/commands/unified/cluster/ClusterAllKindOfValuesCommandsTest.java index c71d5eb7cf..e0f5c7af26 100644 --- a/src/test/java/redis/clients/jedis/commands/unified/cluster/ClusterAllKindOfValuesCommandsTest.java +++ b/src/test/java/redis/clients/jedis/commands/unified/cluster/ClusterAllKindOfValuesCommandsTest.java @@ -13,15 +13,23 @@ import org.junit.After; import org.junit.Before; import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import redis.clients.jedis.RedisProtocol; import redis.clients.jedis.commands.unified.AllKindOfValuesCommandsTestBase; import redis.clients.jedis.params.ScanParams; import redis.clients.jedis.resps.ScanResult; +@RunWith(Parameterized.class) public class ClusterAllKindOfValuesCommandsTest extends AllKindOfValuesCommandsTestBase { + public ClusterAllKindOfValuesCommandsTest(RedisProtocol protocol) { + super(protocol); + } + @Before public void setUp() { - jedis = ClusterCommandsTestHelper.getCleanCluster(); + jedis = ClusterCommandsTestHelper.getCleanCluster(protocol); } @After diff --git a/src/test/java/redis/clients/jedis/commands/unified/cluster/ClusterBinaryValuesCommandsTest.java b/src/test/java/redis/clients/jedis/commands/unified/cluster/ClusterBinaryValuesCommandsTest.java index 8b70e29271..78521a7add 100644 --- a/src/test/java/redis/clients/jedis/commands/unified/cluster/ClusterBinaryValuesCommandsTest.java +++ b/src/test/java/redis/clients/jedis/commands/unified/cluster/ClusterBinaryValuesCommandsTest.java @@ -3,13 +3,21 @@ import org.junit.After; import org.junit.Before; import org.junit.Ignore; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import redis.clients.jedis.RedisProtocol; import redis.clients.jedis.commands.unified.BinaryValuesCommandsTestBase; +@RunWith(Parameterized.class) public class ClusterBinaryValuesCommandsTest extends BinaryValuesCommandsTestBase { + public ClusterBinaryValuesCommandsTest(RedisProtocol protocol) { + super(protocol); + } + @Before public void setUp() { - jedis = ClusterCommandsTestHelper.getCleanCluster(); + jedis = ClusterCommandsTestHelper.getCleanCluster(protocol); } @After diff --git a/src/test/java/redis/clients/jedis/commands/unified/cluster/ClusterBitCommandsTest.java b/src/test/java/redis/clients/jedis/commands/unified/cluster/ClusterBitCommandsTest.java index 64f4f8376c..078e8d8851 100644 --- a/src/test/java/redis/clients/jedis/commands/unified/cluster/ClusterBitCommandsTest.java +++ b/src/test/java/redis/clients/jedis/commands/unified/cluster/ClusterBitCommandsTest.java @@ -6,15 +6,23 @@ import org.junit.Before; import org.junit.Ignore; import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import redis.clients.jedis.RedisProtocol; import redis.clients.jedis.args.BitOP; import redis.clients.jedis.commands.unified.BitCommandsTestBase; import redis.clients.jedis.exceptions.JedisDataException; +@RunWith(Parameterized.class) public class ClusterBitCommandsTest extends BitCommandsTestBase { + public ClusterBitCommandsTest(RedisProtocol protocol) { + super(protocol); + } + @Before public void setUp() { - jedis = ClusterCommandsTestHelper.getCleanCluster(); + jedis = ClusterCommandsTestHelper.getCleanCluster(protocol); } @After diff --git a/src/test/java/redis/clients/jedis/commands/unified/cluster/ClusterCommandsTestHelper.java b/src/test/java/redis/clients/jedis/commands/unified/cluster/ClusterCommandsTestHelper.java index 238f3044e2..6c8f3e25cc 100644 --- a/src/test/java/redis/clients/jedis/commands/unified/cluster/ClusterCommandsTestHelper.java +++ b/src/test/java/redis/clients/jedis/commands/unified/cluster/ClusterCommandsTestHelper.java @@ -6,15 +6,15 @@ import redis.clients.jedis.HostAndPorts; import redis.clients.jedis.Jedis; import redis.clients.jedis.JedisCluster; -import redis.clients.jedis.util.RedisProtocolUtil; +import redis.clients.jedis.RedisProtocol; public class ClusterCommandsTestHelper { - static JedisCluster getCleanCluster() { + static JedisCluster getCleanCluster(RedisProtocol protocol) { clearClusterData(); return new JedisCluster( Collections.singleton(HostAndPorts.getStableClusterServers().get(0)), - DefaultJedisClientConfig.builder().password("cluster").protocol(RedisProtocolUtil.getRedisProtocol()).build()); + DefaultJedisClientConfig.builder().password("cluster").protocol(protocol).build()); } static void clearClusterData() { diff --git a/src/test/java/redis/clients/jedis/commands/unified/cluster/ClusterGeoCommandsTest.java b/src/test/java/redis/clients/jedis/commands/unified/cluster/ClusterGeoCommandsTest.java index 76ef6d1c73..75d5902a8e 100644 --- a/src/test/java/redis/clients/jedis/commands/unified/cluster/ClusterGeoCommandsTest.java +++ b/src/test/java/redis/clients/jedis/commands/unified/cluster/ClusterGeoCommandsTest.java @@ -11,17 +11,25 @@ import org.junit.Before; import org.junit.Ignore; import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; import redis.clients.jedis.GeoCoordinate; +import redis.clients.jedis.RedisProtocol; import redis.clients.jedis.args.GeoUnit; import redis.clients.jedis.commands.unified.GeoCommandsTestBase; import redis.clients.jedis.params.GeoRadiusParam; import redis.clients.jedis.params.GeoRadiusStoreParam; +@RunWith(Parameterized.class) public class ClusterGeoCommandsTest extends GeoCommandsTestBase { + public ClusterGeoCommandsTest(RedisProtocol protocol) { + super(protocol); + } + @Before public void setUp() { - jedis = ClusterCommandsTestHelper.getCleanCluster(); + jedis = ClusterCommandsTestHelper.getCleanCluster(protocol); } @After diff --git a/src/test/java/redis/clients/jedis/commands/unified/cluster/ClusterHyperLogLogCommandsTest.java b/src/test/java/redis/clients/jedis/commands/unified/cluster/ClusterHyperLogLogCommandsTest.java index 49da95e026..461ac873c4 100644 --- a/src/test/java/redis/clients/jedis/commands/unified/cluster/ClusterHyperLogLogCommandsTest.java +++ b/src/test/java/redis/clients/jedis/commands/unified/cluster/ClusterHyperLogLogCommandsTest.java @@ -6,13 +6,21 @@ import org.junit.Before; import org.junit.Ignore; import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import redis.clients.jedis.RedisProtocol; import redis.clients.jedis.commands.unified.HyperLogLogCommandsTestBase; +@RunWith(Parameterized.class) public class ClusterHyperLogLogCommandsTest extends HyperLogLogCommandsTestBase { + public ClusterHyperLogLogCommandsTest(RedisProtocol protocol) { + super(protocol); + } + @Before public void setUp() { - jedis = ClusterCommandsTestHelper.getCleanCluster(); + jedis = ClusterCommandsTestHelper.getCleanCluster(protocol); } @After diff --git a/src/test/java/redis/clients/jedis/commands/unified/cluster/ClusterListCommandsTest.java b/src/test/java/redis/clients/jedis/commands/unified/cluster/ClusterListCommandsTest.java index 10af17a110..666752050b 100644 --- a/src/test/java/redis/clients/jedis/commands/unified/cluster/ClusterListCommandsTest.java +++ b/src/test/java/redis/clients/jedis/commands/unified/cluster/ClusterListCommandsTest.java @@ -13,19 +13,27 @@ import org.junit.After; import org.junit.Before; import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import redis.clients.jedis.RedisProtocol; import redis.clients.jedis.args.ListDirection; import redis.clients.jedis.commands.unified.ListCommandsTestBase; import redis.clients.jedis.util.KeyValue; +@RunWith(Parameterized.class) public class ClusterListCommandsTest extends ListCommandsTestBase { private final Logger logger = LoggerFactory.getLogger(getClass()); + public ClusterListCommandsTest(RedisProtocol protocol) { + super(protocol); + } + @Before public void setUp() { - jedis = ClusterCommandsTestHelper.getCleanCluster(); + jedis = ClusterCommandsTestHelper.getCleanCluster(protocol); } @After diff --git a/src/test/java/redis/clients/jedis/commands/unified/cluster/ClusterSetCommandsTest.java b/src/test/java/redis/clients/jedis/commands/unified/cluster/ClusterSetCommandsTest.java index cd0bc2234f..75d2b6bbdc 100644 --- a/src/test/java/redis/clients/jedis/commands/unified/cluster/ClusterSetCommandsTest.java +++ b/src/test/java/redis/clients/jedis/commands/unified/cluster/ClusterSetCommandsTest.java @@ -8,8 +8,12 @@ import org.junit.After; import org.junit.Before; import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import redis.clients.jedis.RedisProtocol; import redis.clients.jedis.commands.unified.SetCommandsTestBase; +@RunWith(Parameterized.class) public class ClusterSetCommandsTest extends SetCommandsTestBase { final byte[] bfoo = { 0x01, 0x02, 0x03, 0x04 }; @@ -18,9 +22,13 @@ public class ClusterSetCommandsTest extends SetCommandsTestBase { final byte[] bb = { 0x0B }; final byte[] bc = { 0x0C }; + public ClusterSetCommandsTest(RedisProtocol protocol) { + super(protocol); + } + @Before public void setUp() { - jedis = ClusterCommandsTestHelper.getCleanCluster(); + jedis = ClusterCommandsTestHelper.getCleanCluster(protocol); } @After diff --git a/src/test/java/redis/clients/jedis/commands/unified/cluster/ClusterSortedSetCommandsTest.java b/src/test/java/redis/clients/jedis/commands/unified/cluster/ClusterSortedSetCommandsTest.java index 84748693f3..9151b0c52b 100644 --- a/src/test/java/redis/clients/jedis/commands/unified/cluster/ClusterSortedSetCommandsTest.java +++ b/src/test/java/redis/clients/jedis/commands/unified/cluster/ClusterSortedSetCommandsTest.java @@ -12,6 +12,9 @@ import org.junit.After; import org.junit.Before; import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import redis.clients.jedis.RedisProtocol; import redis.clients.jedis.commands.unified.SortedSetCommandsTestBase; import redis.clients.jedis.params.ZAddParams; import redis.clients.jedis.params.ZParams; @@ -19,6 +22,7 @@ import redis.clients.jedis.resps.Tuple; import redis.clients.jedis.util.KeyValue; +@RunWith(Parameterized.class) public class ClusterSortedSetCommandsTest extends SortedSetCommandsTestBase { final byte[] bfoo = { 0x01, 0x02, 0x03, 0x04 }; @@ -27,9 +31,13 @@ public class ClusterSortedSetCommandsTest extends SortedSetCommandsTestBase { final byte[] bb = { 0x0B }; final byte[] bc = { 0x0C }; + public ClusterSortedSetCommandsTest(RedisProtocol protocol) { + super(protocol); + } + @Before public void setUp() { - jedis = ClusterCommandsTestHelper.getCleanCluster(); + jedis = ClusterCommandsTestHelper.getCleanCluster(protocol); } @After diff --git a/src/test/java/redis/clients/jedis/commands/unified/cluster/ClusterStringValuesCommandsTest.java b/src/test/java/redis/clients/jedis/commands/unified/cluster/ClusterStringValuesCommandsTest.java index c7b743f5e4..a8f980bd9a 100644 --- a/src/test/java/redis/clients/jedis/commands/unified/cluster/ClusterStringValuesCommandsTest.java +++ b/src/test/java/redis/clients/jedis/commands/unified/cluster/ClusterStringValuesCommandsTest.java @@ -8,15 +8,23 @@ import org.junit.After; import org.junit.Before; import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import redis.clients.jedis.RedisProtocol; import redis.clients.jedis.commands.unified.StringValuesCommandsTestBase; import redis.clients.jedis.params.LCSParams; import redis.clients.jedis.resps.LCSMatchResult; +@RunWith(Parameterized.class) public class ClusterStringValuesCommandsTest extends StringValuesCommandsTestBase { + public ClusterStringValuesCommandsTest(RedisProtocol protocol) { + super(protocol); + } + @Before public void setUp() { - jedis = ClusterCommandsTestHelper.getCleanCluster(); + jedis = ClusterCommandsTestHelper.getCleanCluster(protocol); } @After diff --git a/src/test/java/redis/clients/jedis/commands/unified/pipeline/GeoPipelineCommandsTest.java b/src/test/java/redis/clients/jedis/commands/unified/pipeline/GeoPipelineCommandsTest.java index cbab082b7e..ccfd70bc8f 100644 --- a/src/test/java/redis/clients/jedis/commands/unified/pipeline/GeoPipelineCommandsTest.java +++ b/src/test/java/redis/clients/jedis/commands/unified/pipeline/GeoPipelineCommandsTest.java @@ -16,13 +16,13 @@ import java.util.Map; import java.util.stream.Collectors; -import org.junit.AfterClass; -import org.junit.BeforeClass; import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; import redis.clients.jedis.GeoCoordinate; +import redis.clients.jedis.RedisProtocol; import redis.clients.jedis.Response; import redis.clients.jedis.args.GeoUnit; -import redis.clients.jedis.commands.unified.pooled.PooledCommandsTestHelper; import redis.clients.jedis.exceptions.JedisDataException; import redis.clients.jedis.params.GeoAddParams; import redis.clients.jedis.params.GeoRadiusParam; @@ -31,6 +31,7 @@ import redis.clients.jedis.resps.GeoRadiusResponse; import redis.clients.jedis.util.SafeEncoder; +@RunWith(Parameterized.class) public class GeoPipelineCommandsTest extends PipelineCommandsTestBase { protected final byte[] bfoo = { 0x01, 0x02, 0x03, 0x04 }; @@ -41,14 +42,8 @@ public class GeoPipelineCommandsTest extends PipelineCommandsTestBase { private static final double EPSILON = 1e-5; - @BeforeClass - public static void prepare() throws InterruptedException { - jedis = PooledCommandsTestHelper.getPooled(); - } - - @AfterClass - public static void cleanUp() { - jedis.close(); + public GeoPipelineCommandsTest(RedisProtocol protocol) { + super(protocol); } @Test diff --git a/src/test/java/redis/clients/jedis/commands/unified/pipeline/HashesPipelineCommandsTest.java b/src/test/java/redis/clients/jedis/commands/unified/pipeline/HashesPipelineCommandsTest.java index e276441e17..d8d9f031bd 100644 --- a/src/test/java/redis/clients/jedis/commands/unified/pipeline/HashesPipelineCommandsTest.java +++ b/src/test/java/redis/clients/jedis/commands/unified/pipeline/HashesPipelineCommandsTest.java @@ -4,34 +4,15 @@ import java.util.*; -import org.junit.AfterClass; -import org.junit.BeforeClass; import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; -import redis.clients.jedis.commands.unified.pooled.PooledCommandsTestHelper; +import redis.clients.jedis.RedisProtocol; +@RunWith(Parameterized.class) public class HashesPipelineCommandsTest extends PipelineCommandsTestBase { - @BeforeClass - public static void prepare() throws InterruptedException { - jedis = PooledCommandsTestHelper.getPooled(); - } - - @AfterClass - public static void cleanUp() { - jedis.close(); - } -// -// @Before -// public void setUp() { -// PooledCommandsTestHelper.clearData(); -// } -// -// @After -// public void tearDown() { -// PooledCommandsTestHelper.clearData(); -// } - final byte[] bfoo = { 0x01, 0x02, 0x03, 0x04 }; final byte[] bbar = { 0x05, 0x06, 0x07, 0x08 }; final byte[] bcar = { 0x09, 0x0A, 0x0B, 0x0C }; @@ -41,6 +22,10 @@ public static void cleanUp() { final byte[] bbar3 = { 0x05, 0x06, 0x07, 0x08, 0x0C }; final byte[] bbarstar = { 0x05, 0x06, 0x07, 0x08, '*' }; + public HashesPipelineCommandsTest(RedisProtocol protocol) { + super(protocol); + } + @Test public void hset() { pipe.hset("foo", "bar", "car"); diff --git a/src/test/java/redis/clients/jedis/commands/unified/pipeline/PipelineCommandsTestBase.java b/src/test/java/redis/clients/jedis/commands/unified/pipeline/PipelineCommandsTestBase.java index c162954509..55dfec6e98 100644 --- a/src/test/java/redis/clients/jedis/commands/unified/pipeline/PipelineCommandsTestBase.java +++ b/src/test/java/redis/clients/jedis/commands/unified/pipeline/PipelineCommandsTestBase.java @@ -1,22 +1,50 @@ package redis.clients.jedis.commands.unified.pipeline; +import java.util.Collection; + import org.junit.After; import org.junit.Before; - +import org.junit.runners.Parameterized; import redis.clients.jedis.JedisPooled; import redis.clients.jedis.Pipeline; +import redis.clients.jedis.RedisProtocol; +import redis.clients.jedis.commands.CommandsTestsParameters; import redis.clients.jedis.commands.unified.pooled.PooledCommandsTestHelper; public abstract class PipelineCommandsTestBase { - protected static JedisPooled jedis; + /** + * Input data for parameterized tests. In principle all subclasses of this + * class should be parameterized tests, to run with several versions of RESP. + * + * @see CommandsTestsParameters#respVersions() + */ + @Parameterized.Parameters + public static Collection data() { + return CommandsTestsParameters.respVersions(); + } + + protected JedisPooled jedis; protected Pipeline pipe; - public PipelineCommandsTestBase() { + protected final RedisProtocol protocol; + + /** + * The RESP protocol is to be injected by the subclasses, usually via JUnit + * parameterized tests, because most of the subclassed tests are meant to be + * executed against multiple RESP versions. For the special cases where a single + * RESP version is relevant, we still force the subclass to be explicit and + * call this constructor. + * + * @param protocol The RESP protocol to use during the tests. + */ + public PipelineCommandsTestBase(RedisProtocol protocol) { + this.protocol = protocol; } @Before public void setUp() { + jedis = PooledCommandsTestHelper.getPooled(protocol); PooledCommandsTestHelper.clearData(); pipe = jedis.pipelined(); } @@ -24,5 +52,6 @@ public void setUp() { @After public void tearDown() { pipe.close(); + jedis.close(); } } diff --git a/src/test/java/redis/clients/jedis/commands/unified/pipeline/SortedSetPipelineCommandsTest.java b/src/test/java/redis/clients/jedis/commands/unified/pipeline/SortedSetPipelineCommandsTest.java index 12a2282e27..a6915ce3a7 100644 --- a/src/test/java/redis/clients/jedis/commands/unified/pipeline/SortedSetPipelineCommandsTest.java +++ b/src/test/java/redis/clients/jedis/commands/unified/pipeline/SortedSetPipelineCommandsTest.java @@ -20,12 +20,12 @@ import java.util.Map; import java.util.stream.Collectors; -import org.junit.AfterClass; -import org.junit.BeforeClass; import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import redis.clients.jedis.RedisProtocol; import redis.clients.jedis.Response; import redis.clients.jedis.args.SortedSetOption; -import redis.clients.jedis.commands.unified.pooled.PooledCommandsTestHelper; import redis.clients.jedis.params.ScanParams; import redis.clients.jedis.params.ZAddParams; import redis.clients.jedis.params.ZIncrByParams; @@ -37,7 +37,9 @@ import redis.clients.jedis.util.KeyValue; import redis.clients.jedis.util.SafeEncoder; +@RunWith(Parameterized.class) public class SortedSetPipelineCommandsTest extends PipelineCommandsTestBase { + final byte[] bfoo = { 0x01, 0x02, 0x03, 0x04 }; final byte[] bbar = { 0x05, 0x06, 0x07, 0x08 }; final byte[] bcar = { 0x09, 0x0A, 0x0B, 0x0C }; @@ -54,14 +56,8 @@ public class SortedSetPipelineCommandsTest extends PipelineCommandsTestBase { final byte[] bbar3 = { 0x05, 0x06, 0x07, 0x08, 0x0C }; final byte[] bbarstar = { 0x05, 0x06, 0x07, 0x08, '*' }; - @BeforeClass - public static void prepare() throws InterruptedException { - jedis = PooledCommandsTestHelper.getPooled(); - } - - @AfterClass - public static void cleanUp() { - jedis.close(); + public SortedSetPipelineCommandsTest(RedisProtocol protocol) { + super(protocol); } @Test diff --git a/src/test/java/redis/clients/jedis/commands/unified/pipeline/StreamsPipelineCommandsTest.java b/src/test/java/redis/clients/jedis/commands/unified/pipeline/StreamsPipelineCommandsTest.java index 066ca98fb0..119f233198 100644 --- a/src/test/java/redis/clients/jedis/commands/unified/pipeline/StreamsPipelineCommandsTest.java +++ b/src/test/java/redis/clients/jedis/commands/unified/pipeline/StreamsPipelineCommandsTest.java @@ -28,14 +28,14 @@ import java.util.stream.Collectors; import org.hamcrest.Matchers; -import org.junit.AfterClass; -import org.junit.BeforeClass; import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; import redis.clients.jedis.BuilderFactory; import redis.clients.jedis.Pipeline; +import redis.clients.jedis.RedisProtocol; import redis.clients.jedis.Response; import redis.clients.jedis.StreamEntryID; -import redis.clients.jedis.commands.unified.pooled.PooledCommandsTestHelper; import redis.clients.jedis.exceptions.JedisDataException; import redis.clients.jedis.params.XAddParams; import redis.clients.jedis.params.XAutoClaimParams; @@ -55,16 +55,11 @@ import redis.clients.jedis.resps.StreamPendingEntry; import redis.clients.jedis.util.SafeEncoder; +@RunWith(Parameterized.class) public class StreamsPipelineCommandsTest extends PipelineCommandsTestBase { - @BeforeClass - public static void prepare() throws InterruptedException { - jedis = PooledCommandsTestHelper.getPooled(); - } - - @AfterClass - public static void cleanUp() { - jedis.close(); + public StreamsPipelineCommandsTest(RedisProtocol protocol) { + super(protocol); } @Test diff --git a/src/test/java/redis/clients/jedis/commands/unified/pooled/PooledAllKindOfValuesCommandsTest.java b/src/test/java/redis/clients/jedis/commands/unified/pooled/PooledAllKindOfValuesCommandsTest.java index 3e1d8a0c39..a1b53de023 100644 --- a/src/test/java/redis/clients/jedis/commands/unified/pooled/PooledAllKindOfValuesCommandsTest.java +++ b/src/test/java/redis/clients/jedis/commands/unified/pooled/PooledAllKindOfValuesCommandsTest.java @@ -1,24 +1,28 @@ package redis.clients.jedis.commands.unified.pooled; -import org.junit.AfterClass; +import org.junit.After; import org.junit.Before; -import org.junit.BeforeClass; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; + +import redis.clients.jedis.RedisProtocol; import redis.clients.jedis.commands.unified.AllKindOfValuesCommandsTestBase; +@RunWith(Parameterized.class) public class PooledAllKindOfValuesCommandsTest extends AllKindOfValuesCommandsTestBase { - @BeforeClass - public static void prepare() throws InterruptedException { - jedis = PooledCommandsTestHelper.getPooled(); - } - - @AfterClass - public static void closeCluster() { - jedis.close(); + public PooledAllKindOfValuesCommandsTest(RedisProtocol protocol) { + super(protocol); } @Before public void setUp() { + jedis = PooledCommandsTestHelper.getPooled(protocol); PooledCommandsTestHelper.clearData(); } + + @After + public void cleanUp() { + jedis.close(); + } } diff --git a/src/test/java/redis/clients/jedis/commands/unified/pooled/PooledBinaryValuesCommandsTest.java b/src/test/java/redis/clients/jedis/commands/unified/pooled/PooledBinaryValuesCommandsTest.java index 7c94f0165a..04a5778fcc 100644 --- a/src/test/java/redis/clients/jedis/commands/unified/pooled/PooledBinaryValuesCommandsTest.java +++ b/src/test/java/redis/clients/jedis/commands/unified/pooled/PooledBinaryValuesCommandsTest.java @@ -1,24 +1,28 @@ package redis.clients.jedis.commands.unified.pooled; -import org.junit.AfterClass; +import org.junit.After; import org.junit.Before; -import org.junit.BeforeClass; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; + +import redis.clients.jedis.RedisProtocol; import redis.clients.jedis.commands.unified.BinaryValuesCommandsTestBase; +@RunWith(Parameterized.class) public class PooledBinaryValuesCommandsTest extends BinaryValuesCommandsTestBase { - @BeforeClass - public static void prepare() throws InterruptedException { - jedis = PooledCommandsTestHelper.getPooled(); - } - - @AfterClass - public static void cleanUp() { - jedis.close(); + public PooledBinaryValuesCommandsTest(RedisProtocol protocol) { + super(protocol); } @Before public void setUp() { + jedis = PooledCommandsTestHelper.getPooled(protocol); PooledCommandsTestHelper.clearData(); } + + @After + public void cleanUp() { + jedis.close(); + } } diff --git a/src/test/java/redis/clients/jedis/commands/unified/pooled/PooledBitCommandsTest.java b/src/test/java/redis/clients/jedis/commands/unified/pooled/PooledBitCommandsTest.java index 60ce669cd2..5764a1bbfa 100644 --- a/src/test/java/redis/clients/jedis/commands/unified/pooled/PooledBitCommandsTest.java +++ b/src/test/java/redis/clients/jedis/commands/unified/pooled/PooledBitCommandsTest.java @@ -1,24 +1,28 @@ package redis.clients.jedis.commands.unified.pooled; -import org.junit.AfterClass; +import org.junit.After; import org.junit.Before; -import org.junit.BeforeClass; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; + +import redis.clients.jedis.RedisProtocol; import redis.clients.jedis.commands.unified.BitCommandsTestBase; +@RunWith(Parameterized.class) public class PooledBitCommandsTest extends BitCommandsTestBase { - @BeforeClass - public static void prepare() throws InterruptedException { - jedis = PooledCommandsTestHelper.getPooled(); - } - - @AfterClass - public static void cleanUp() { - jedis.close(); + public PooledBitCommandsTest(RedisProtocol protocol) { + super(protocol); } @Before public void setUp() { + jedis = PooledCommandsTestHelper.getPooled(protocol); PooledCommandsTestHelper.clearData(); } + + @After + public void cleanUp() { + jedis.close(); + } } diff --git a/src/test/java/redis/clients/jedis/commands/unified/pooled/PooledCommandsTestHelper.java b/src/test/java/redis/clients/jedis/commands/unified/pooled/PooledCommandsTestHelper.java index 82ecc600c8..82c84f8890 100644 --- a/src/test/java/redis/clients/jedis/commands/unified/pooled/PooledCommandsTestHelper.java +++ b/src/test/java/redis/clients/jedis/commands/unified/pooled/PooledCommandsTestHelper.java @@ -5,26 +5,21 @@ import redis.clients.jedis.Jedis; import redis.clients.jedis.JedisPooled; import redis.clients.jedis.HostAndPorts; -import redis.clients.jedis.util.RedisProtocolUtil; +import redis.clients.jedis.RedisProtocol; public class PooledCommandsTestHelper { private static final HostAndPort nodeInfo = HostAndPorts.getRedisServers().get(0); - private static Jedis node; - - public static JedisPooled getPooled() throws InterruptedException { - - node = new Jedis(nodeInfo); - node.auth("foobared"); - //node.flushAll(); - - //return new JedisPooled(nodeInfo.getHost(), nodeInfo.getPort(), null, "foobared"); + public static JedisPooled getPooled(RedisProtocol redisProtocol) { return new JedisPooled(nodeInfo, DefaultJedisClientConfig.builder() - .protocol(RedisProtocolUtil.getRedisProtocol()).password("foobared").build()); + .protocol(redisProtocol).password("foobared").build()); } public static void clearData() { - node.flushAll(); + try (Jedis node = new Jedis(nodeInfo)) { + node.auth("foobared"); + node.flushAll(); + } } } diff --git a/src/test/java/redis/clients/jedis/commands/unified/pooled/PooledGeoCommandsTest.java b/src/test/java/redis/clients/jedis/commands/unified/pooled/PooledGeoCommandsTest.java index d94753f32e..3affb40afa 100644 --- a/src/test/java/redis/clients/jedis/commands/unified/pooled/PooledGeoCommandsTest.java +++ b/src/test/java/redis/clients/jedis/commands/unified/pooled/PooledGeoCommandsTest.java @@ -1,24 +1,28 @@ package redis.clients.jedis.commands.unified.pooled; -import org.junit.AfterClass; +import org.junit.After; import org.junit.Before; -import org.junit.BeforeClass; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; + +import redis.clients.jedis.RedisProtocol; import redis.clients.jedis.commands.unified.GeoCommandsTestBase; +@RunWith(Parameterized.class) public class PooledGeoCommandsTest extends GeoCommandsTestBase { - @BeforeClass - public static void prepare() throws InterruptedException { - jedis = PooledCommandsTestHelper.getPooled(); - } - - @AfterClass - public static void cleanUp() { - jedis.close(); + public PooledGeoCommandsTest(RedisProtocol protocol) { + super(protocol); } @Before public void setUp() { + jedis = PooledCommandsTestHelper.getPooled(protocol); PooledCommandsTestHelper.clearData(); } + + @After + public void cleanUp() { + jedis.close(); + } } diff --git a/src/test/java/redis/clients/jedis/commands/unified/pooled/PooledHashesCommandsTest.java b/src/test/java/redis/clients/jedis/commands/unified/pooled/PooledHashesCommandsTest.java index a628336a97..bb5741d967 100644 --- a/src/test/java/redis/clients/jedis/commands/unified/pooled/PooledHashesCommandsTest.java +++ b/src/test/java/redis/clients/jedis/commands/unified/pooled/PooledHashesCommandsTest.java @@ -1,24 +1,28 @@ package redis.clients.jedis.commands.unified.pooled; -import org.junit.AfterClass; +import org.junit.After; import org.junit.Before; -import org.junit.BeforeClass; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; + +import redis.clients.jedis.RedisProtocol; import redis.clients.jedis.commands.unified.HashesCommandsTestBase; +@RunWith(Parameterized.class) public class PooledHashesCommandsTest extends HashesCommandsTestBase { - @BeforeClass - public static void prepare() throws InterruptedException { - jedis = PooledCommandsTestHelper.getPooled(); - } - - @AfterClass - public static void cleanUp() { - jedis.close(); + public PooledHashesCommandsTest(RedisProtocol protocol) { + super(protocol); } @Before public void setUp() { + jedis = PooledCommandsTestHelper.getPooled(protocol); PooledCommandsTestHelper.clearData(); } + + @After + public void cleanUp() { + jedis.close(); + } } diff --git a/src/test/java/redis/clients/jedis/commands/unified/pooled/PooledHyperLogLogCommandsTest.java b/src/test/java/redis/clients/jedis/commands/unified/pooled/PooledHyperLogLogCommandsTest.java index aca21523da..6b2b2f3dd2 100644 --- a/src/test/java/redis/clients/jedis/commands/unified/pooled/PooledHyperLogLogCommandsTest.java +++ b/src/test/java/redis/clients/jedis/commands/unified/pooled/PooledHyperLogLogCommandsTest.java @@ -1,24 +1,28 @@ package redis.clients.jedis.commands.unified.pooled; -import org.junit.AfterClass; +import org.junit.After; import org.junit.Before; -import org.junit.BeforeClass; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; + +import redis.clients.jedis.RedisProtocol; import redis.clients.jedis.commands.unified.HyperLogLogCommandsTestBase; +@RunWith(Parameterized.class) public class PooledHyperLogLogCommandsTest extends HyperLogLogCommandsTestBase { - @BeforeClass - public static void prepare() throws InterruptedException { - jedis = PooledCommandsTestHelper.getPooled(); - } - - @AfterClass - public static void cleanUp() { - jedis.close(); + public PooledHyperLogLogCommandsTest(RedisProtocol protocol) { + super(protocol); } @Before public void setUp() { + jedis = PooledCommandsTestHelper.getPooled(protocol); PooledCommandsTestHelper.clearData(); } + + @After + public void cleanUp() { + jedis.close(); + } } diff --git a/src/test/java/redis/clients/jedis/commands/unified/pooled/PooledListCommandsTest.java b/src/test/java/redis/clients/jedis/commands/unified/pooled/PooledListCommandsTest.java index 4ccd3de00a..5d38fe43d5 100644 --- a/src/test/java/redis/clients/jedis/commands/unified/pooled/PooledListCommandsTest.java +++ b/src/test/java/redis/clients/jedis/commands/unified/pooled/PooledListCommandsTest.java @@ -1,24 +1,28 @@ package redis.clients.jedis.commands.unified.pooled; -import org.junit.AfterClass; +import org.junit.After; import org.junit.Before; -import org.junit.BeforeClass; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; + +import redis.clients.jedis.RedisProtocol; import redis.clients.jedis.commands.unified.ListCommandsTestBase; +@RunWith(Parameterized.class) public class PooledListCommandsTest extends ListCommandsTestBase { - @BeforeClass - public static void prepare() throws InterruptedException { - jedis = PooledCommandsTestHelper.getPooled(); - } - - @AfterClass - public static void cleanUp() { - jedis.close(); + public PooledListCommandsTest(RedisProtocol protocol) { + super(protocol); } @Before public void setUp() { + jedis = PooledCommandsTestHelper.getPooled(protocol); PooledCommandsTestHelper.clearData(); } + + @After + public void cleanUp() { + jedis.close(); + } } diff --git a/src/test/java/redis/clients/jedis/commands/unified/pooled/PooledMiscellaneousTest.java b/src/test/java/redis/clients/jedis/commands/unified/pooled/PooledMiscellaneousTest.java index fc917e4e47..6f2f42e754 100644 --- a/src/test/java/redis/clients/jedis/commands/unified/pooled/PooledMiscellaneousTest.java +++ b/src/test/java/redis/clients/jedis/commands/unified/pooled/PooledMiscellaneousTest.java @@ -7,40 +7,42 @@ import java.util.Arrays; import java.util.List; import org.junit.After; -import org.junit.AfterClass; import org.junit.Before; -import org.junit.BeforeClass; import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; import redis.clients.jedis.JedisPooled; import redis.clients.jedis.Pipeline; +import redis.clients.jedis.RedisProtocol; import redis.clients.jedis.Response; import redis.clients.jedis.AbstractTransaction; import redis.clients.jedis.commands.unified.UnifiedJedisCommandsTestBase; import redis.clients.jedis.exceptions.JedisDataException; +@RunWith(Parameterized.class) public class PooledMiscellaneousTest extends UnifiedJedisCommandsTestBase { protected Pipeline pipeline; protected AbstractTransaction transaction; - @BeforeClass - public static void prepare() throws InterruptedException { - jedis = PooledCommandsTestHelper.getPooled(); - } - - @AfterClass - public static void cleanUp() { - jedis.close(); + public PooledMiscellaneousTest(RedisProtocol protocol) { + super(protocol); } @Before public void setUp() { + jedis = PooledCommandsTestHelper.getPooled(protocol); PooledCommandsTestHelper.clearData(); pipeline = ((JedisPooled) jedis).pipelined(); transaction = jedis.multi(); } + @After + public void cleanUp() { + jedis.close(); + } + @After public void tearDown() { pipeline.close(); diff --git a/src/test/java/redis/clients/jedis/commands/unified/pooled/PooledSetCommandsTest.java b/src/test/java/redis/clients/jedis/commands/unified/pooled/PooledSetCommandsTest.java index 00b7420e11..2be9dbbf1c 100644 --- a/src/test/java/redis/clients/jedis/commands/unified/pooled/PooledSetCommandsTest.java +++ b/src/test/java/redis/clients/jedis/commands/unified/pooled/PooledSetCommandsTest.java @@ -1,24 +1,28 @@ package redis.clients.jedis.commands.unified.pooled; -import org.junit.AfterClass; +import org.junit.After; import org.junit.Before; -import org.junit.BeforeClass; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; + +import redis.clients.jedis.RedisProtocol; import redis.clients.jedis.commands.unified.SetCommandsTestBase; +@RunWith(Parameterized.class) public class PooledSetCommandsTest extends SetCommandsTestBase { - @BeforeClass - public static void prepare() throws InterruptedException { - jedis = PooledCommandsTestHelper.getPooled(); - } - - @AfterClass - public static void cleanUp() { - jedis.close(); + public PooledSetCommandsTest(RedisProtocol protocol) { + super(protocol); } @Before public void setUp() { + jedis = PooledCommandsTestHelper.getPooled(protocol); PooledCommandsTestHelper.clearData(); } + + @After + public void cleanUp() { + jedis.close(); + } } diff --git a/src/test/java/redis/clients/jedis/commands/unified/pooled/PooledSortedSetCommandsTest.java b/src/test/java/redis/clients/jedis/commands/unified/pooled/PooledSortedSetCommandsTest.java index 38b4f95450..c3d0b76ece 100644 --- a/src/test/java/redis/clients/jedis/commands/unified/pooled/PooledSortedSetCommandsTest.java +++ b/src/test/java/redis/clients/jedis/commands/unified/pooled/PooledSortedSetCommandsTest.java @@ -1,24 +1,28 @@ package redis.clients.jedis.commands.unified.pooled; -import org.junit.AfterClass; +import org.junit.After; import org.junit.Before; -import org.junit.BeforeClass; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; + +import redis.clients.jedis.RedisProtocol; import redis.clients.jedis.commands.unified.SortedSetCommandsTestBase; +@RunWith(Parameterized.class) public class PooledSortedSetCommandsTest extends SortedSetCommandsTestBase { - @BeforeClass - public static void prepare() throws InterruptedException { - jedis = PooledCommandsTestHelper.getPooled(); - } - - @AfterClass - public static void cleanUp() { - jedis.close(); + public PooledSortedSetCommandsTest(RedisProtocol protocol) { + super(protocol); } @Before public void setUp() { + jedis = PooledCommandsTestHelper.getPooled(protocol); PooledCommandsTestHelper.clearData(); } + + @After + public void cleanUp() { + jedis.close(); + } } diff --git a/src/test/java/redis/clients/jedis/commands/unified/pooled/PooledStringValuesCommandsTest.java b/src/test/java/redis/clients/jedis/commands/unified/pooled/PooledStringValuesCommandsTest.java index 34fd50c776..c9a1c39ae1 100644 --- a/src/test/java/redis/clients/jedis/commands/unified/pooled/PooledStringValuesCommandsTest.java +++ b/src/test/java/redis/clients/jedis/commands/unified/pooled/PooledStringValuesCommandsTest.java @@ -1,24 +1,28 @@ package redis.clients.jedis.commands.unified.pooled; -import org.junit.AfterClass; +import org.junit.After; import org.junit.Before; -import org.junit.BeforeClass; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; + +import redis.clients.jedis.RedisProtocol; import redis.clients.jedis.commands.unified.StringValuesCommandsTestBase; +@RunWith(Parameterized.class) public class PooledStringValuesCommandsTest extends StringValuesCommandsTestBase { - @BeforeClass - public static void prepare() throws InterruptedException { - jedis = PooledCommandsTestHelper.getPooled(); - } - - @AfterClass - public static void cleanUp() { - jedis.close(); + public PooledStringValuesCommandsTest(RedisProtocol protocol) { + super(protocol); } @Before public void setUp() { + jedis = PooledCommandsTestHelper.getPooled(protocol); PooledCommandsTestHelper.clearData(); } + + @After + public void cleanUp() { + jedis.close(); + } } diff --git a/src/test/java/redis/clients/jedis/modules/RedisModuleCommandsTestBase.java b/src/test/java/redis/clients/jedis/modules/RedisModuleCommandsTestBase.java index 20bbe9ae92..9e21fba23f 100644 --- a/src/test/java/redis/clients/jedis/modules/RedisModuleCommandsTestBase.java +++ b/src/test/java/redis/clients/jedis/modules/RedisModuleCommandsTestBase.java @@ -2,37 +2,59 @@ import static org.junit.Assume.assumeTrue; +import java.util.Collection; + import org.junit.After; import org.junit.Before; +import org.junit.runners.Parameterized.Parameters; import redis.clients.jedis.Connection; - import redis.clients.jedis.DefaultJedisClientConfig; import redis.clients.jedis.HostAndPort; import redis.clients.jedis.Jedis; import redis.clients.jedis.Protocol; import redis.clients.jedis.RedisProtocol; import redis.clients.jedis.UnifiedJedis; +import redis.clients.jedis.commands.CommandsTestsParameters; import redis.clients.jedis.exceptions.JedisConnectionException; -import redis.clients.jedis.util.RedisProtocolUtil; public abstract class RedisModuleCommandsTestBase { + /** + * Input data for parameterized tests. In principle all subclasses of this + * class should be parameterized tests, to run with several versions of RESP. + * + * @see CommandsTestsParameters#respVersions() + */ + @Parameters + public static Collection data() { + return CommandsTestsParameters.respVersions(); + } + private static final String address = System.getProperty("modulesDocker", Protocol.DEFAULT_HOST + ':' + 6479); protected static final HostAndPort hnp = HostAndPort.from(address); - protected final RedisProtocol protocol = RedisProtocolUtil.getRedisProtocol(); + protected final RedisProtocol protocol; protected UnifiedJedis client; - public RedisModuleCommandsTestBase() { - super(); + /** + * The RESP protocol is to be injected by the subclasses, usually via JUnit + * parameterized tests, because most of the subclassed tests are meant to be + * executed against multiple RESP versions. For the special cases where a single + * RESP version is relevant, we still force the subclass to be explicit and + * call this constructor. + * + * @param protocol The RESP protocol to use during the tests. + */ + public RedisModuleCommandsTestBase(RedisProtocol protocol) { + this.protocol = protocol; } // BeforeClass public static void prepare() { try (Connection connection = new Connection(hnp)) { - assumeTrue("No Redis running on 6479 port.", connection.ping()); + assumeTrue("No Redis running on " + hnp.getPort() + " port.", connection.ping()); } catch (JedisConnectionException jce) { - assumeTrue("Could not connect to Redis running on 6479 port.", false); + assumeTrue("Could not connect to Redis running on " + hnp.getPort() + " port.", false); } } diff --git a/src/test/java/redis/clients/jedis/modules/RedisModulesPipelineTest.java b/src/test/java/redis/clients/jedis/modules/RedisModulesPipelineTest.java index 50b48854da..db0ba8223c 100644 --- a/src/test/java/redis/clients/jedis/modules/RedisModulesPipelineTest.java +++ b/src/test/java/redis/clients/jedis/modules/RedisModulesPipelineTest.java @@ -17,6 +17,8 @@ import org.junit.Assume; import org.junit.BeforeClass; import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; import redis.clients.jedis.Pipeline; import redis.clients.jedis.RedisProtocol; @@ -26,8 +28,8 @@ import redis.clients.jedis.json.Path2; import redis.clients.jedis.search.*; import redis.clients.jedis.search.aggr.*; -import redis.clients.jedis.util.RedisProtocolUtil; +@RunWith(Parameterized.class) public class RedisModulesPipelineTest extends RedisModuleCommandsTestBase { private static final Gson gson = new Gson(); @@ -37,6 +39,10 @@ public static void prepare() { RedisModuleCommandsTestBase.prepare(); } + public RedisModulesPipelineTest(RedisProtocol protocol) { + super(protocol); + } + @Test public void search() { Schema sc = new Schema().addTextField("title", 1.0).addTextField("body", 1.0); @@ -91,7 +97,7 @@ public void search() { @Test public void jsonV1() { - Assume.assumeFalse(RedisProtocolUtil.getRedisProtocol() == RedisProtocol.RESP3); + Assume.assumeFalse(protocol == RedisProtocol.RESP3); Map hm1 = new HashMap<>(); hm1.put("hello", "world"); diff --git a/src/test/java/redis/clients/jedis/modules/bloom/BloomTest.java b/src/test/java/redis/clients/jedis/modules/bloom/BloomTest.java index 8a8917b8c8..c97eabd63f 100644 --- a/src/test/java/redis/clients/jedis/modules/bloom/BloomTest.java +++ b/src/test/java/redis/clients/jedis/modules/bloom/BloomTest.java @@ -10,12 +10,16 @@ import java.util.Map; import org.junit.BeforeClass; import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import redis.clients.jedis.RedisProtocol; import redis.clients.jedis.bloom.BFInsertParams; import redis.clients.jedis.bloom.BFReserveParams; import redis.clients.jedis.exceptions.JedisDataException; import redis.clients.jedis.modules.RedisModuleCommandsTestBase; +@RunWith(Parameterized.class) public class BloomTest extends RedisModuleCommandsTestBase { @BeforeClass @@ -28,6 +32,10 @@ public static void prepare() { //// RedisModuleCommandsTestBase.tearDown(); // } + public BloomTest(RedisProtocol protocol) { + super(protocol); + } + @Test public void reserveBasic() { client.bfReserve("myBloom", 0.001, 100L); diff --git a/src/test/java/redis/clients/jedis/modules/bloom/CMSTest.java b/src/test/java/redis/clients/jedis/modules/bloom/CMSTest.java index 6604ba6cbc..2ff7fd9a0a 100644 --- a/src/test/java/redis/clients/jedis/modules/bloom/CMSTest.java +++ b/src/test/java/redis/clients/jedis/modules/bloom/CMSTest.java @@ -10,13 +10,17 @@ import java.util.Map; import org.junit.BeforeClass; import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import redis.clients.jedis.RedisProtocol; import redis.clients.jedis.exceptions.JedisException; import redis.clients.jedis.modules.RedisModuleCommandsTestBase; /** * Tests for the Count-Min-Sketch Implementation */ +@RunWith(Parameterized.class) public class CMSTest extends RedisModuleCommandsTestBase { @BeforeClass @@ -29,6 +33,10 @@ public static void prepare() { //// RedisModuleCommandsTestBase.tearDown(); // } + public CMSTest(RedisProtocol protocol) { + super(protocol); + } + @Test public void testInitByDim() { client.cmsInitByDim("cms1", 16L, 4L); diff --git a/src/test/java/redis/clients/jedis/modules/bloom/CuckooTest.java b/src/test/java/redis/clients/jedis/modules/bloom/CuckooTest.java index d46145c378..8d6027acbe 100644 --- a/src/test/java/redis/clients/jedis/modules/bloom/CuckooTest.java +++ b/src/test/java/redis/clients/jedis/modules/bloom/CuckooTest.java @@ -11,7 +11,10 @@ import java.util.Map; import org.junit.BeforeClass; import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import redis.clients.jedis.RedisProtocol; import redis.clients.jedis.bloom.CFInsertParams; import redis.clients.jedis.bloom.CFReserveParams; import redis.clients.jedis.exceptions.JedisDataException; @@ -20,6 +23,7 @@ /** * Tests for the Cuckoo Filter Implementation */ +@RunWith(Parameterized.class) public class CuckooTest extends RedisModuleCommandsTestBase { @BeforeClass @@ -32,6 +36,10 @@ public static void prepare() { //// RedisModuleCommandsTestBase.tearDown(); // } + public CuckooTest(RedisProtocol protocol) { + super(protocol); + } + @Test public void testReservationCapacityOnly() { client.cfReserve("cuckoo1", 10); diff --git a/src/test/java/redis/clients/jedis/modules/bloom/TDigestTest.java b/src/test/java/redis/clients/jedis/modules/bloom/TDigestTest.java index 586b544ab1..36d85018ef 100644 --- a/src/test/java/redis/clients/jedis/modules/bloom/TDigestTest.java +++ b/src/test/java/redis/clients/jedis/modules/bloom/TDigestTest.java @@ -8,10 +8,14 @@ import java.util.Random; import org.junit.BeforeClass; import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import redis.clients.jedis.RedisProtocol; import redis.clients.jedis.bloom.TDigestMergeParams; import redis.clients.jedis.modules.RedisModuleCommandsTestBase; +@RunWith(Parameterized.class) public class TDigestTest extends RedisModuleCommandsTestBase { private static final Random random = new Random(); @@ -26,6 +30,10 @@ public static void prepare() { //// RedisModuleCommandsTestBase.tearDown(); // } + public TDigestTest(RedisProtocol protocol) { + super(protocol); + } + private void assertMergedUnmergedNodes(String key, int mergedNodes, int unmergedNodes) { Map info = client.tdigestInfo(key); assertEquals(Long.valueOf(mergedNodes), info.get("Merged nodes")); diff --git a/src/test/java/redis/clients/jedis/modules/bloom/TopKTest.java b/src/test/java/redis/clients/jedis/modules/bloom/TopKTest.java index 706d57ef82..29a8a5738a 100644 --- a/src/test/java/redis/clients/jedis/modules/bloom/TopKTest.java +++ b/src/test/java/redis/clients/jedis/modules/bloom/TopKTest.java @@ -8,9 +8,13 @@ import java.util.Map; import org.junit.BeforeClass; import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import redis.clients.jedis.RedisProtocol; import redis.clients.jedis.modules.RedisModuleCommandsTestBase; +@RunWith(Parameterized.class) public class TopKTest extends RedisModuleCommandsTestBase { @BeforeClass @@ -23,6 +27,10 @@ public static void prepare() { //// RedisModuleCommandsTestBase.tearDown(); // } + public TopKTest(RedisProtocol protocol) { + super(protocol); + } + @Test public void createTopKFilter() { client.topkReserve("aaa", 30, 2000, 7, 0.925); diff --git a/src/test/java/redis/clients/jedis/modules/gears/GearsTest.java b/src/test/java/redis/clients/jedis/modules/gears/GearsTest.java index e4dc10a82d..117094b9b8 100644 --- a/src/test/java/redis/clients/jedis/modules/gears/GearsTest.java +++ b/src/test/java/redis/clients/jedis/modules/gears/GearsTest.java @@ -5,6 +5,8 @@ import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; import redis.clients.jedis.RedisProtocol; import redis.clients.jedis.exceptions.JedisDataException; @@ -29,6 +31,7 @@ import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; +@RunWith(Parameterized.class) public class GearsTest extends RedisModuleCommandsTestBase { private static final String BAD_FUNCTION = "All Your Base Are Belong to Us"; @@ -41,6 +44,10 @@ public static void prepare() { RedisModuleCommandsTestBase.prepare(); } + public GearsTest(RedisProtocol protocol) { + super(protocol); + } + @After @Override public void tearDown() throws Exception { diff --git a/src/test/java/redis/clients/jedis/modules/graph/GraphAPITest.java b/src/test/java/redis/clients/jedis/modules/graph/GraphAPITest.java index 694a1ddf78..46b135070c 100644 --- a/src/test/java/redis/clients/jedis/modules/graph/GraphAPITest.java +++ b/src/test/java/redis/clients/jedis/modules/graph/GraphAPITest.java @@ -13,7 +13,10 @@ import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import redis.clients.jedis.RedisProtocol; import redis.clients.jedis.graph.Header; import redis.clients.jedis.graph.Record; import redis.clients.jedis.graph.ResultSet; @@ -22,6 +25,7 @@ import redis.clients.jedis.modules.RedisModuleCommandsTestBase; +@RunWith(Parameterized.class) public class GraphAPITest extends RedisModuleCommandsTestBase { @BeforeClass @@ -29,6 +33,10 @@ public static void prepare() { RedisModuleCommandsTestBase.prepare(); } + public GraphAPITest(RedisProtocol protocol) { + super(protocol); + } + @After @Override public void tearDown() throws Exception { diff --git a/src/test/java/redis/clients/jedis/modules/graph/GraphPipelineTest.java b/src/test/java/redis/clients/jedis/modules/graph/GraphPipelineTest.java index 22d6894333..f69dd06712 100644 --- a/src/test/java/redis/clients/jedis/modules/graph/GraphPipelineTest.java +++ b/src/test/java/redis/clients/jedis/modules/graph/GraphPipelineTest.java @@ -13,9 +13,12 @@ import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; import redis.clients.jedis.Connection; import redis.clients.jedis.Pipeline; +import redis.clients.jedis.RedisProtocol; import redis.clients.jedis.graph.Header; import redis.clients.jedis.graph.Record; import redis.clients.jedis.graph.ResultSet; @@ -23,6 +26,7 @@ import redis.clients.jedis.graph.entities.Property; import redis.clients.jedis.modules.RedisModuleCommandsTestBase; +@RunWith(Parameterized.class) public class GraphPipelineTest extends RedisModuleCommandsTestBase { // private Connection c; @@ -31,6 +35,11 @@ public class GraphPipelineTest extends RedisModuleCommandsTestBase { public static void prepare() { RedisModuleCommandsTestBase.prepare(); } + + public GraphPipelineTest(RedisProtocol protocol) { + super(protocol); + } + // // @Before // public void createApi() { diff --git a/src/test/java/redis/clients/jedis/modules/graph/GraphTransactionTest.java b/src/test/java/redis/clients/jedis/modules/graph/GraphTransactionTest.java index c63996e7b5..9a7a8e502c 100644 --- a/src/test/java/redis/clients/jedis/modules/graph/GraphTransactionTest.java +++ b/src/test/java/redis/clients/jedis/modules/graph/GraphTransactionTest.java @@ -11,8 +11,11 @@ import org.junit.BeforeClass; import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; import redis.clients.jedis.AbstractTransaction; +import redis.clients.jedis.RedisProtocol; import redis.clients.jedis.graph.Header; import redis.clients.jedis.graph.Record; import redis.clients.jedis.graph.ResultSet; @@ -20,6 +23,7 @@ import redis.clients.jedis.graph.entities.Property; import redis.clients.jedis.modules.RedisModuleCommandsTestBase; +@RunWith(Parameterized.class) public class GraphTransactionTest extends RedisModuleCommandsTestBase { // private Connection c; @@ -28,6 +32,11 @@ public class GraphTransactionTest extends RedisModuleCommandsTestBase { public static void prepare() { RedisModuleCommandsTestBase.prepare(); } + + public GraphTransactionTest(RedisProtocol protocol) { + super(protocol); + } + // // @Before // public void createApi() { diff --git a/src/test/java/redis/clients/jedis/modules/graph/GraphValuesTest.java b/src/test/java/redis/clients/jedis/modules/graph/GraphValuesTest.java index 8761e0f786..ea9c6a7799 100644 --- a/src/test/java/redis/clients/jedis/modules/graph/GraphValuesTest.java +++ b/src/test/java/redis/clients/jedis/modules/graph/GraphValuesTest.java @@ -4,10 +4,15 @@ import org.junit.BeforeClass; import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; + +import redis.clients.jedis.RedisProtocol; import redis.clients.jedis.graph.Record; import redis.clients.jedis.graph.ResultSet; import redis.clients.jedis.modules.RedisModuleCommandsTestBase; +@RunWith(Parameterized.class) public class GraphValuesTest extends RedisModuleCommandsTestBase { @BeforeClass @@ -15,6 +20,10 @@ public static void prepare() { RedisModuleCommandsTestBase.prepare(); } + public GraphValuesTest(RedisProtocol protocol) { + super(protocol); + } + @Test public void parseInfinity() { ResultSet rs = client.graphQuery("db", "RETURN 10^100000"); diff --git a/src/test/java/redis/clients/jedis/modules/json/RedisJsonV1Test.java b/src/test/java/redis/clients/jedis/modules/json/RedisJsonV1Test.java index 5843b6e06a..d281b33265 100644 --- a/src/test/java/redis/clients/jedis/modules/json/RedisJsonV1Test.java +++ b/src/test/java/redis/clients/jedis/modules/json/RedisJsonV1Test.java @@ -14,7 +14,6 @@ import java.util.Collections; import java.util.List; -import org.junit.Assume; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; @@ -26,8 +25,10 @@ import redis.clients.jedis.json.commands.RedisJsonV1Commands; import redis.clients.jedis.modules.RedisModuleCommandsTestBase; import redis.clients.jedis.util.JsonObjectMapperTestUtil; -import redis.clients.jedis.util.RedisProtocolUtil; +/** + * V1 of the RedisJSON is only supported with RESP2, hence this test is not parameterized. + */ public class RedisJsonV1Test extends RedisModuleCommandsTestBase { private final Gson gson = new Gson(); @@ -36,10 +37,13 @@ public class RedisJsonV1Test extends RedisModuleCommandsTestBase { @BeforeClass public static void prepare() { - Assume.assumeFalse(RedisProtocolUtil.getRedisProtocol() == RedisProtocol.RESP3); RedisModuleCommandsTestBase.prepare(); } + public RedisJsonV1Test() { + super(RedisProtocol.RESP2); + } + @Before @Override public void setUp() { diff --git a/src/test/java/redis/clients/jedis/modules/json/RedisJsonV2Test.java b/src/test/java/redis/clients/jedis/modules/json/RedisJsonV2Test.java index f36832da51..6168c2e2de 100644 --- a/src/test/java/redis/clients/jedis/modules/json/RedisJsonV2Test.java +++ b/src/test/java/redis/clients/jedis/modules/json/RedisJsonV2Test.java @@ -15,6 +15,8 @@ import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; import redis.clients.jedis.RedisProtocol; import redis.clients.jedis.exceptions.JedisDataException; @@ -22,8 +24,8 @@ import redis.clients.jedis.json.Path2; import redis.clients.jedis.json.commands.RedisJsonV2Commands; import redis.clients.jedis.modules.RedisModuleCommandsTestBase; -import redis.clients.jedis.util.RedisProtocolUtil; +@RunWith(Parameterized.class) public class RedisJsonV2Test extends RedisModuleCommandsTestBase { private static final Gson gson = new Gson(); @@ -35,6 +37,10 @@ public static void prepare() { RedisModuleCommandsTestBase.prepare(); } + public RedisJsonV2Test(RedisProtocol protocol) { + super(protocol); + } + @Before @Override public void setUp() { @@ -44,7 +50,7 @@ public void setUp() { @Test public void basicSetGetShouldSucceed() { - Assume.assumeFalse(RedisProtocolUtil.getRedisProtocol() == RedisProtocol.RESP3); + Assume.assumeFalse(protocol == RedisProtocol.RESP3); // naive set with a path jsonV2.jsonSetWithEscape("null", ROOT_PATH, (Object) null); @@ -68,7 +74,7 @@ public void basicSetGetShouldSucceed() { @Test public void basicSetGetShouldSucceedResp3() { - Assume.assumeTrue(RedisProtocolUtil.getRedisProtocol() == RedisProtocol.RESP3); + Assume.assumeTrue(protocol == RedisProtocol.RESP3); // naive set with a path jsonV2.jsonSetWithEscape("null", ROOT_PATH, (Object) null); @@ -467,7 +473,7 @@ public void strLen() { @Test public void numIncrBy() { - Assume.assumeFalse(RedisProtocolUtil.getRedisProtocol() == RedisProtocol.RESP3); + Assume.assumeFalse(protocol == RedisProtocol.RESP3); jsonV2.jsonSet("doc", "{\"a\":\"b\",\"b\":[{\"a\":2}, {\"a\":5}, {\"a\":\"c\"}]}"); assertJsonArrayEquals(jsonArray((Object) null), jsonV2.jsonNumIncrBy("doc", Path2.of(".a"), 1d)); assertJsonArrayEquals(jsonArray(null, 4, 7, null), jsonV2.jsonNumIncrBy("doc", Path2.of("..a"), 2d)); @@ -477,7 +483,7 @@ public void numIncrBy() { @Test public void numIncrByResp3() { - Assume.assumeTrue(RedisProtocolUtil.getRedisProtocol() == RedisProtocol.RESP3); + Assume.assumeTrue(protocol == RedisProtocol.RESP3); jsonV2.jsonSet("doc", "{\"a\":\"b\",\"b\":[{\"a\":2}, {\"a\":5}, {\"a\":\"c\"}]}"); assertEquals(singletonList((Object) null), jsonV2.jsonNumIncrBy("doc", Path2.of(".a"), 1d)); assertEquals(Arrays.asList(null, 4d, 7d, null), jsonV2.jsonNumIncrBy("doc", Path2.of("..a"), 2d)); diff --git a/src/test/java/redis/clients/jedis/modules/search/AggregationTest.java b/src/test/java/redis/clients/jedis/modules/search/AggregationTest.java index b594f28dd1..cefdfbe5d3 100644 --- a/src/test/java/redis/clients/jedis/modules/search/AggregationTest.java +++ b/src/test/java/redis/clients/jedis/modules/search/AggregationTest.java @@ -9,6 +9,8 @@ import org.hamcrest.Matchers; import org.junit.BeforeClass; import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; import java.util.ArrayList; import java.util.Arrays; @@ -35,6 +37,7 @@ import redis.clients.jedis.search.schemafields.NumericField; import redis.clients.jedis.search.schemafields.TextField; +@RunWith(Parameterized.class) public class AggregationTest extends RedisModuleCommandsTestBase { private static final String index = "aggbindex"; @@ -49,6 +52,10 @@ public static void prepare() { //// RedisModuleCommandsTestBase.tearDown(); // } + public AggregationTest(RedisProtocol redisProtocol) { + super(redisProtocol); + } + private void addDocument(Document doc) { String key = doc.getId(); Map map = new LinkedHashMap<>(); diff --git a/src/test/java/redis/clients/jedis/modules/search/JsonSearchTest.java b/src/test/java/redis/clients/jedis/modules/search/JsonSearchTest.java index 79485634d7..822f7bc804 100644 --- a/src/test/java/redis/clients/jedis/modules/search/JsonSearchTest.java +++ b/src/test/java/redis/clients/jedis/modules/search/JsonSearchTest.java @@ -5,10 +5,13 @@ import org.json.JSONObject; import org.junit.BeforeClass; import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; + import redis.clients.jedis.BuilderFactory; import redis.clients.jedis.CommandArguments; import redis.clients.jedis.CommandObject; - +import redis.clients.jedis.RedisProtocol; import redis.clients.jedis.json.JsonProtocol; import redis.clients.jedis.json.Path2; import redis.clients.jedis.search.*; @@ -16,6 +19,7 @@ import redis.clients.jedis.search.SearchResult; import redis.clients.jedis.modules.RedisModuleCommandsTestBase; +@RunWith(Parameterized.class) public class JsonSearchTest extends RedisModuleCommandsTestBase { public static final String JSON_ROOT = "$"; @@ -32,6 +36,10 @@ public static void prepare() { //// RedisModuleCommandsTestBase.tearDown(); // } + public JsonSearchTest(RedisProtocol protocol) { + super(protocol); + } + private void setJson(String key, JSONObject json) { CommandObject command = new CommandObject<>( new CommandArguments(JsonProtocol.JsonCommand.SET).key(key).add(Path2.ROOT_PATH).add(json), diff --git a/src/test/java/redis/clients/jedis/modules/search/JsonSearchWithGsonTest.java b/src/test/java/redis/clients/jedis/modules/search/JsonSearchWithGsonTest.java index 00ccada3bd..5ef29679fd 100644 --- a/src/test/java/redis/clients/jedis/modules/search/JsonSearchWithGsonTest.java +++ b/src/test/java/redis/clients/jedis/modules/search/JsonSearchWithGsonTest.java @@ -8,9 +8,14 @@ import com.google.gson.GsonBuilder; import org.junit.BeforeClass; import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; + +import redis.clients.jedis.RedisProtocol; import redis.clients.jedis.search.*; import redis.clients.jedis.modules.RedisModuleCommandsTestBase; +@RunWith(Parameterized.class) public class JsonSearchWithGsonTest extends RedisModuleCommandsTestBase { private static final String index = "gson-index"; @@ -25,6 +30,10 @@ public static void prepare() { //// RedisModuleCommandsTestBase.tearDown(); // } + public JsonSearchWithGsonTest(RedisProtocol protocol) { + super(protocol); + } + class Account { String name; diff --git a/src/test/java/redis/clients/jedis/modules/search/SearchConfigTest.java b/src/test/java/redis/clients/jedis/modules/search/SearchConfigTest.java index bda3cbe4d1..4e93303a4a 100644 --- a/src/test/java/redis/clients/jedis/modules/search/SearchConfigTest.java +++ b/src/test/java/redis/clients/jedis/modules/search/SearchConfigTest.java @@ -7,8 +7,13 @@ import java.util.Map; import org.junit.BeforeClass; import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; + +import redis.clients.jedis.RedisProtocol; import redis.clients.jedis.modules.RedisModuleCommandsTestBase; +@RunWith(Parameterized.class) public class SearchConfigTest extends RedisModuleCommandsTestBase { @BeforeClass @@ -21,6 +26,10 @@ public static void prepare() { //// RedisModuleCommandsTestBase.tearDown(); // } + public SearchConfigTest(RedisProtocol protocol) { + super(protocol); + } + @Test public void config() { Map map = client.ftConfigGet("TIMEOUT"); diff --git a/src/test/java/redis/clients/jedis/modules/search/SearchDefaultDialectTest.java b/src/test/java/redis/clients/jedis/modules/search/SearchDefaultDialectTest.java index b803b1eceb..34adccf1d5 100644 --- a/src/test/java/redis/clients/jedis/modules/search/SearchDefaultDialectTest.java +++ b/src/test/java/redis/clients/jedis/modules/search/SearchDefaultDialectTest.java @@ -10,7 +10,10 @@ import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import redis.clients.jedis.RedisProtocol; import redis.clients.jedis.exceptions.JedisDataException; import redis.clients.jedis.search.*; import redis.clients.jedis.search.schemafields.NumericField; @@ -21,6 +24,7 @@ import redis.clients.jedis.search.aggr.Reducers; import redis.clients.jedis.search.aggr.Row; +@RunWith(Parameterized.class) public class SearchDefaultDialectTest extends RedisModuleCommandsTestBase { private static final String INDEX = "dialect-INDEX"; @@ -31,6 +35,10 @@ public static void prepare() { RedisModuleCommandsTestBase.prepare(); } + public SearchDefaultDialectTest(RedisProtocol protocol) { + super(protocol); + } + @Override public void setUp() { super.setUp(); diff --git a/src/test/java/redis/clients/jedis/modules/search/SearchTest.java b/src/test/java/redis/clients/jedis/modules/search/SearchTest.java index b8656ff344..1bc6cb345d 100644 --- a/src/test/java/redis/clients/jedis/modules/search/SearchTest.java +++ b/src/test/java/redis/clients/jedis/modules/search/SearchTest.java @@ -8,6 +8,8 @@ import org.junit.Assume; import org.junit.BeforeClass; import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; import redis.clients.jedis.RedisProtocol; import redis.clients.jedis.exceptions.JedisDataException; @@ -17,6 +19,7 @@ import redis.clients.jedis.modules.RedisModuleCommandsTestBase; import redis.clients.jedis.util.SafeEncoder; +@RunWith(Parameterized.class) public class SearchTest extends RedisModuleCommandsTestBase { private static final String index = "testindex"; @@ -31,6 +34,10 @@ public static void prepare() { //// RedisModuleCommandsTestBase.tearDown(); // } + public SearchTest(RedisProtocol protocol) { + super(protocol); + } + private void addDocument(String key, Map map) { client.hset(key, RediSearchUtil.toStringMap(map)); } diff --git a/src/test/java/redis/clients/jedis/modules/search/SearchWithParamsTest.java b/src/test/java/redis/clients/jedis/modules/search/SearchWithParamsTest.java index a81ceb7821..897da8eece 100644 --- a/src/test/java/redis/clients/jedis/modules/search/SearchWithParamsTest.java +++ b/src/test/java/redis/clients/jedis/modules/search/SearchWithParamsTest.java @@ -10,6 +10,8 @@ import org.hamcrest.Matchers; import org.junit.BeforeClass; import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; import org.locationtech.jts.geom.Coordinate; import org.locationtech.jts.geom.GeometryFactory; @@ -29,6 +31,7 @@ import redis.clients.jedis.search.schemafields.VectorField.VectorAlgorithm; import redis.clients.jedis.modules.RedisModuleCommandsTestBase; +@RunWith(Parameterized.class) public class SearchWithParamsTest extends RedisModuleCommandsTestBase { private static final String index = "testindex"; @@ -43,6 +46,10 @@ public static void prepare() { //// RedisModuleCommandsTestBase.tearDown(); // } + public SearchWithParamsTest(RedisProtocol protocol) { + super(protocol); + } + private void addDocument(String key, Map map) { client.hset(key, RediSearchUtil.toStringMap(map)); } diff --git a/src/test/java/redis/clients/jedis/modules/search/SpellCheckTest.java b/src/test/java/redis/clients/jedis/modules/search/SpellCheckTest.java index 508ff4441a..bd7e529c55 100644 --- a/src/test/java/redis/clients/jedis/modules/search/SpellCheckTest.java +++ b/src/test/java/redis/clients/jedis/modules/search/SpellCheckTest.java @@ -13,12 +13,16 @@ import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import redis.clients.jedis.RedisProtocol; import redis.clients.jedis.exceptions.JedisDataException; import redis.clients.jedis.modules.RedisModuleCommandsTestBase; import redis.clients.jedis.search.FTSpellCheckParams; import redis.clients.jedis.search.schemafields.TextField; +@RunWith(Parameterized.class) public class SpellCheckTest extends RedisModuleCommandsTestBase { private static final String index = "spellcheck"; @@ -33,6 +37,10 @@ public static void prepare() { //// RedisModuleCommandsTestBase.tearDown(); // } + public SpellCheckTest(RedisProtocol protocol) { + super(protocol); + } + private static Map toMap(String... values) { Map map = new HashMap<>(); for (int i = 0; i < values.length; i += 2) { diff --git a/src/test/java/redis/clients/jedis/modules/search/SuggestionTest.java b/src/test/java/redis/clients/jedis/modules/search/SuggestionTest.java index 626b26966e..2341b835cd 100644 --- a/src/test/java/redis/clients/jedis/modules/search/SuggestionTest.java +++ b/src/test/java/redis/clients/jedis/modules/search/SuggestionTest.java @@ -9,10 +9,14 @@ import org.junit.BeforeClass; import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import redis.clients.jedis.RedisProtocol; import redis.clients.jedis.modules.RedisModuleCommandsTestBase; import redis.clients.jedis.resps.Tuple; +@RunWith(Parameterized.class) public class SuggestionTest extends RedisModuleCommandsTestBase { private static final String key = "suggest"; @@ -27,6 +31,10 @@ public static void prepare() { //// RedisModuleCommandsTestBase.tearDown(); // } + public SuggestionTest(RedisProtocol protocol) { + super(protocol); + } + @Test public void addSuggestionAndGetSuggestion() { String suggestion = "ANOTHER_WORD"; diff --git a/src/test/java/redis/clients/jedis/modules/timeseries/TimeSeriesTest.java b/src/test/java/redis/clients/jedis/modules/timeseries/TimeSeriesTest.java index 12c424f9e1..fe0f7d1604 100644 --- a/src/test/java/redis/clients/jedis/modules/timeseries/TimeSeriesTest.java +++ b/src/test/java/redis/clients/jedis/modules/timeseries/TimeSeriesTest.java @@ -11,13 +11,16 @@ import java.util.*; import org.junit.BeforeClass; import org.junit.Test; -import redis.clients.jedis.RedisProtocol; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import redis.clients.jedis.RedisProtocol; import redis.clients.jedis.exceptions.JedisDataException; import redis.clients.jedis.modules.RedisModuleCommandsTestBase; import redis.clients.jedis.timeseries.*; import redis.clients.jedis.util.KeyValue; +@RunWith(Parameterized.class) public class TimeSeriesTest extends RedisModuleCommandsTestBase { @BeforeClass @@ -30,6 +33,10 @@ public static void prepare() { //// RedisModuleCommandsTestBase.tearDown(); // } + public TimeSeriesTest(RedisProtocol protocol) { + super(protocol); + } + @Test public void testCreate() { Map labels = new HashMap<>(); diff --git a/src/test/java/redis/clients/jedis/util/RedisProtocolUtil.java b/src/test/java/redis/clients/jedis/util/RedisProtocolUtil.java deleted file mode 100644 index 71f52b42a3..0000000000 --- a/src/test/java/redis/clients/jedis/util/RedisProtocolUtil.java +++ /dev/null @@ -1,21 +0,0 @@ -package redis.clients.jedis.util; - -import redis.clients.jedis.RedisProtocol; - -public class RedisProtocolUtil { - - public static RedisProtocol getRedisProtocol() { -// return RedisProtocol.RESP2; -// return RedisProtocol.RESP3; - String ver = System.getProperty("jedisProtocol"); - if (ver != null && !ver.isEmpty()) { - for (RedisProtocol proto : RedisProtocol.values()) { - if (proto.version().equals(ver)) { - return proto; - } - } - throw new IllegalArgumentException("Unknown protocol " + ver); - } - return null; - } -}