From ab6f0581323adf9ef7e0ca1c9f55c03b3c90eb00 Mon Sep 17 00:00:00 2001 From: M Sazzadul Hoque <7600764+sazzad16@users.noreply.github.com> Date: Wed, 28 Feb 2024 23:02:25 +0600 Subject: [PATCH 01/33] Polish #3741 (#3746) Add HSCAN NOVALUES in pipelines and transactions --- src/main/java/redis/clients/jedis/PipeliningBase.java | 10 ++++++++++ .../clients/jedis/commands/HashBinaryCommands.java | 4 ++-- .../redis/clients/jedis/commands/HashCommands.java | 4 ++-- .../jedis/commands/HashPipelineBinaryCommands.java | 6 ++++++ .../clients/jedis/commands/HashPipelineCommands.java | 6 ++++++ 5 files changed, 26 insertions(+), 4 deletions(-) diff --git a/src/main/java/redis/clients/jedis/PipeliningBase.java b/src/main/java/redis/clients/jedis/PipeliningBase.java index 5c6cd45f07a..bf6711b6325 100644 --- a/src/main/java/redis/clients/jedis/PipeliningBase.java +++ b/src/main/java/redis/clients/jedis/PipeliningBase.java @@ -706,6 +706,11 @@ public Response>> hscan(String key, String return appendCommand(commandObjects.hscan(key, cursor, params)); } + @Override + public Response> hscanNoValues(String key, String cursor, ScanParams params) { + return appendCommand(commandObjects.hscanNoValues(key, cursor, params)); + } + @Override public Response hstrlen(String key, String field) { return appendCommand(commandObjects.hstrlen(key, field)); @@ -1972,6 +1977,11 @@ public Response>> hscan(byte[] key, byte[] return appendCommand(commandObjects.hscan(key, cursor, params)); } + @Override + public Response> hscanNoValues(byte[] key, byte[] cursor, ScanParams params) { + return appendCommand(commandObjects.hscanNoValues(key, cursor, params)); + } + @Override public Response hstrlen(byte[] key, byte[] field) { return appendCommand(commandObjects.hstrlen(key, field)); diff --git a/src/main/java/redis/clients/jedis/commands/HashBinaryCommands.java b/src/main/java/redis/clients/jedis/commands/HashBinaryCommands.java index d0695302b30..15a462c9b79 100644 --- a/src/main/java/redis/clients/jedis/commands/HashBinaryCommands.java +++ b/src/main/java/redis/clients/jedis/commands/HashBinaryCommands.java @@ -47,12 +47,12 @@ default ScanResult> hscan(byte[] key, byte[] cursor) { return hscan(key, cursor, new ScanParams()); } + ScanResult> hscan(byte[] key, byte[] cursor, ScanParams params); + default ScanResult hscanNoValues(byte[] key, byte[] cursor) { return hscanNoValues(key, cursor, new ScanParams()); } - ScanResult> hscan(byte[] key, byte[] cursor, ScanParams params); - ScanResult hscanNoValues(byte[] key, byte[] cursor, ScanParams params); long hstrlen(byte[] key, byte[] field); diff --git a/src/main/java/redis/clients/jedis/commands/HashCommands.java b/src/main/java/redis/clients/jedis/commands/HashCommands.java index ad3bed4e32c..ef18e34aee0 100644 --- a/src/main/java/redis/clients/jedis/commands/HashCommands.java +++ b/src/main/java/redis/clients/jedis/commands/HashCommands.java @@ -47,12 +47,12 @@ default ScanResult> hscan(String key, String cursor) { return hscan(key, cursor, new ScanParams()); } + ScanResult> hscan(String key, String cursor, ScanParams params); + default ScanResult hscanNoValues(String key, String cursor) { return hscanNoValues(key, cursor, new ScanParams()); } - ScanResult> hscan(String key, String cursor, ScanParams params); - ScanResult hscanNoValues(String key, String cursor, ScanParams params); long hstrlen(String key, String field); diff --git a/src/main/java/redis/clients/jedis/commands/HashPipelineBinaryCommands.java b/src/main/java/redis/clients/jedis/commands/HashPipelineBinaryCommands.java index e87dcacdb3f..cf104f7a338 100644 --- a/src/main/java/redis/clients/jedis/commands/HashPipelineBinaryCommands.java +++ b/src/main/java/redis/clients/jedis/commands/HashPipelineBinaryCommands.java @@ -50,6 +50,12 @@ default Response>> hscan(byte[] key, byte[] Response>> hscan(byte[] key, byte[] cursor, ScanParams params); + default Response> hscanNoValues(byte[] key, byte[] cursor) { + return hscanNoValues(key, cursor, new ScanParams()); + } + + Response> hscanNoValues(byte[] key, byte[] cursor, ScanParams params); + Response hstrlen(byte[] key, byte[] field); } diff --git a/src/main/java/redis/clients/jedis/commands/HashPipelineCommands.java b/src/main/java/redis/clients/jedis/commands/HashPipelineCommands.java index 3aa256cb78e..dabcac4e901 100644 --- a/src/main/java/redis/clients/jedis/commands/HashPipelineCommands.java +++ b/src/main/java/redis/clients/jedis/commands/HashPipelineCommands.java @@ -50,5 +50,11 @@ default Response>> hscan(String key, String Response>> hscan(String key, String cursor, ScanParams params); + default Response> hscanNoValues(String key, String cursor) { + return hscanNoValues(key, cursor, new ScanParams()); + } + + Response> hscanNoValues(String key, String cursor, ScanParams params); + Response hstrlen(String key, String field); } From 3dfa82d4432d2ed8442f66d5416e0269fd9de4f3 Mon Sep 17 00:00:00 2001 From: M Sazzadul Hoque <7600764+sazzad16@users.noreply.github.com> Date: Thu, 29 Feb 2024 19:14:24 +0600 Subject: [PATCH 02/33] Reduce the log level of validateObject to WARN (#3750) - Reduce the log level of `JedisFactory#validateObject` to `WARN` - Reduce the log level of `ConnectionFactory#validateObject` to `WARN` --- src/main/java/redis/clients/jedis/ConnectionFactory.java | 2 +- src/main/java/redis/clients/jedis/JedisFactory.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/redis/clients/jedis/ConnectionFactory.java b/src/main/java/redis/clients/jedis/ConnectionFactory.java index d2864623476..3500a211722 100644 --- a/src/main/java/redis/clients/jedis/ConnectionFactory.java +++ b/src/main/java/redis/clients/jedis/ConnectionFactory.java @@ -76,7 +76,7 @@ public boolean validateObject(PooledObject pooledConnection) { // check HostAndPort ?? return jedis.isConnected() && jedis.ping(); } catch (final Exception e) { - logger.error("Error while validating pooled Connection object.", e); + logger.warn("Error while validating pooled Connection object.", e); return false; } } diff --git a/src/main/java/redis/clients/jedis/JedisFactory.java b/src/main/java/redis/clients/jedis/JedisFactory.java index b84e2b05aec..0e07ccc2860 100644 --- a/src/main/java/redis/clients/jedis/JedisFactory.java +++ b/src/main/java/redis/clients/jedis/JedisFactory.java @@ -197,7 +197,7 @@ public boolean validateObject(PooledObject pooledJedis) { && jedis.getConnection().isConnected() && jedis.ping().equals("PONG"); } catch (final Exception e) { - logger.error("Error while validating pooled Jedis object.", e); + logger.warn("Error while validating pooled Jedis object.", e); return false; } } From 25acc8d5b1519d1404fd04b094638a794a054caf Mon Sep 17 00:00:00 2001 From: M Sazzadul Hoque <7600764+sazzad16@users.noreply.github.com> Date: Wed, 6 Mar 2024 13:29:41 +0600 Subject: [PATCH 03/33] Stop connection fetching before sync/exec (#3756) in multi cluster failover mode --- .../clients/jedis/AbstractTransaction.java | 4 +++ .../jedis/MultiClusterClientConfig.java | 3 +- .../redis/clients/jedis/TransactionBase.java | 4 +++ .../redis/clients/jedis/UnifiedJedis.java | 4 +-- .../jedis/mcf/MultiClusterPipeline.java | 6 ++++ .../jedis/mcf/MultiClusterTransaction.java | 17 ++++++++++ .../jedis/misc/AutomaticFailoverTest.java | 32 +++++++++++++------ 7 files changed, 57 insertions(+), 13 deletions(-) diff --git a/src/main/java/redis/clients/jedis/AbstractTransaction.java b/src/main/java/redis/clients/jedis/AbstractTransaction.java index ed6f397caa9..2a551224fa7 100644 --- a/src/main/java/redis/clients/jedis/AbstractTransaction.java +++ b/src/main/java/redis/clients/jedis/AbstractTransaction.java @@ -9,6 +9,10 @@ protected AbstractTransaction() { super(new CommandObjects()); } + protected AbstractTransaction(CommandObjects commandObjects) { + super(commandObjects); + } + public abstract void multi(); /** diff --git a/src/main/java/redis/clients/jedis/MultiClusterClientConfig.java b/src/main/java/redis/clients/jedis/MultiClusterClientConfig.java index 980bbb91f92..15956ebed48 100644 --- a/src/main/java/redis/clients/jedis/MultiClusterClientConfig.java +++ b/src/main/java/redis/clients/jedis/MultiClusterClientConfig.java @@ -40,8 +40,7 @@ public final class MultiClusterClientConfig { private static final float CIRCUIT_BREAKER_SLOW_CALL_RATE_THRESHOLD_DEFAULT = 100.0f; // measured as percentage private static final List CIRCUIT_BREAKER_INCLUDED_EXCEPTIONS_DEFAULT = Arrays.asList(JedisConnectionException.class); - private static final List> FALLBACK_EXCEPTIONS_DEFAULT = - Arrays.asList(CallNotPermittedException.class, JedisConnectionException.class); + private static final List> FALLBACK_EXCEPTIONS_DEFAULT = Arrays.asList(CallNotPermittedException.class); private final ClusterConfig[] clusterConfigs; diff --git a/src/main/java/redis/clients/jedis/TransactionBase.java b/src/main/java/redis/clients/jedis/TransactionBase.java index 805a1120c4c..efdf332700b 100644 --- a/src/main/java/redis/clients/jedis/TransactionBase.java +++ b/src/main/java/redis/clients/jedis/TransactionBase.java @@ -9,4 +9,8 @@ public abstract class TransactionBase extends AbstractTransaction { protected TransactionBase() { super(); } + + protected TransactionBase(CommandObjects commandObjects) { + super(commandObjects); + } } diff --git a/src/main/java/redis/clients/jedis/UnifiedJedis.java b/src/main/java/redis/clients/jedis/UnifiedJedis.java index eab452a1f1d..a43ffc10906 100644 --- a/src/main/java/redis/clients/jedis/UnifiedJedis.java +++ b/src/main/java/redis/clients/jedis/UnifiedJedis.java @@ -4849,7 +4849,7 @@ public PipelineBase pipelined() { if (provider == null) { throw new IllegalStateException("It is not allowed to create Pipeline from this " + getClass()); } else if (provider instanceof MultiClusterPooledConnectionProvider) { - return new MultiClusterPipeline((MultiClusterPooledConnectionProvider) provider); + return new MultiClusterPipeline((MultiClusterPooledConnectionProvider) provider, commandObjects); } else { return new Pipeline(provider.getConnection(), true); } @@ -4859,7 +4859,7 @@ public AbstractTransaction multi() { if (provider == null) { throw new IllegalStateException("It is not allowed to create Pipeline from this " + getClass()); } else if (provider instanceof MultiClusterPooledConnectionProvider) { - return new MultiClusterTransaction((MultiClusterPooledConnectionProvider) provider); + return new MultiClusterTransaction((MultiClusterPooledConnectionProvider) provider, true, commandObjects); } else { return new Transaction(provider.getConnection(), true, true); } diff --git a/src/main/java/redis/clients/jedis/mcf/MultiClusterPipeline.java b/src/main/java/redis/clients/jedis/mcf/MultiClusterPipeline.java index d4052dae7bd..00c0ba1d911 100644 --- a/src/main/java/redis/clients/jedis/mcf/MultiClusterPipeline.java +++ b/src/main/java/redis/clients/jedis/mcf/MultiClusterPipeline.java @@ -20,6 +20,7 @@ public class MultiClusterPipeline extends PipelineBase implements Closeable { private final CircuitBreakerFailoverConnectionProvider failoverProvider; private final Queue>> commands = new LinkedList<>(); + @Deprecated public MultiClusterPipeline(MultiClusterPooledConnectionProvider pooledProvider) { super(new CommandObjects()); @@ -31,6 +32,11 @@ public MultiClusterPipeline(MultiClusterPooledConnectionProvider pooledProvider) } } + public MultiClusterPipeline(MultiClusterPooledConnectionProvider pooledProvider, CommandObjects commandObjects) { + super(commandObjects); + this.failoverProvider = new CircuitBreakerFailoverConnectionProvider(pooledProvider); + } + @Override protected final Response appendCommand(CommandObject commandObject) { CommandArguments args = commandObject.getArguments(); diff --git a/src/main/java/redis/clients/jedis/mcf/MultiClusterTransaction.java b/src/main/java/redis/clients/jedis/mcf/MultiClusterTransaction.java index 540911f2d66..d759ce1da0a 100644 --- a/src/main/java/redis/clients/jedis/mcf/MultiClusterTransaction.java +++ b/src/main/java/redis/clients/jedis/mcf/MultiClusterTransaction.java @@ -38,6 +38,7 @@ public class MultiClusterTransaction extends TransactionBase { * called with this object. * @param provider */ + @Deprecated public MultiClusterTransaction(MultiClusterPooledConnectionProvider provider) { this(provider, true); } @@ -49,6 +50,7 @@ public MultiClusterTransaction(MultiClusterPooledConnectionProvider provider) { * @param provider * @param doMulti {@code false} should be set to enable manual WATCH, UNWATCH and MULTI */ + @Deprecated public MultiClusterTransaction(MultiClusterPooledConnectionProvider provider, boolean doMulti) { this.failoverProvider = new CircuitBreakerFailoverConnectionProvider(provider); @@ -60,6 +62,21 @@ public MultiClusterTransaction(MultiClusterPooledConnectionProvider provider, bo if (doMulti) multi(); } + /** + * A user wanting to WATCH/UNWATCH keys followed by a call to MULTI ({@link #multi()}) it should + * be {@code doMulti=false}. + * + * @param provider + * @param doMulti {@code false} should be set to enable manual WATCH, UNWATCH and MULTI + * @param commandObjects command objects + */ + public MultiClusterTransaction(MultiClusterPooledConnectionProvider provider, boolean doMulti, CommandObjects commandObjects) { + super(commandObjects); + this.failoverProvider = new CircuitBreakerFailoverConnectionProvider(provider); + + if (doMulti) multi(); + } + @Override public final void multi() { appendCommand(new CommandObject<>(new CommandArguments(MULTI), NO_OP_BUILDER)); diff --git a/src/test/java/redis/clients/jedis/misc/AutomaticFailoverTest.java b/src/test/java/redis/clients/jedis/misc/AutomaticFailoverTest.java index dc03c52f390..c6b25d764b0 100644 --- a/src/test/java/redis/clients/jedis/misc/AutomaticFailoverTest.java +++ b/src/test/java/redis/clients/jedis/misc/AutomaticFailoverTest.java @@ -26,6 +26,7 @@ import redis.clients.jedis.MultiClusterClientConfig; import redis.clients.jedis.UnifiedJedis; import redis.clients.jedis.exceptions.JedisAccessControlException; +import redis.clients.jedis.exceptions.JedisConnectionException; import redis.clients.jedis.providers.MultiClusterPooledConnectionProvider; import redis.clients.jedis.util.IOUtils; @@ -68,7 +69,7 @@ public void pipelineWithSwitch() { AbstractPipeline pipe = client.pipelined(); pipe.set("pstr", "foobar"); pipe.hset("phash", "foo", "bar"); - //provider.incrementActiveMultiClusterIndex(); + provider.incrementActiveMultiClusterIndex(); pipe.sync(); } @@ -85,7 +86,7 @@ public void transactionWithSwitch() { AbstractTransaction tx = client.multi(); tx.set("tstr", "foobar"); tx.hset("thash", "foo", "bar"); - //provider.incrementActiveMultiClusterIndex(); + provider.incrementActiveMultiClusterIndex(); assertEquals(Arrays.asList("OK", Long.valueOf(1L)), tx.exec()); } @@ -109,9 +110,19 @@ public void commandFailover() { UnifiedJedis jedis = new UnifiedJedis(cacheProvider); - assertFalse(failoverReporter.failedOver); - log.info("Starting calls to Redis"); String key = "hash-" + System.nanoTime(); + log.info("Starting calls to Redis"); + assertFalse(failoverReporter.failedOver); + for (int attempt = 0; attempt < 10; attempt++) { + try { + jedis.hset(key, "f1", "v1"); + } catch (JedisConnectionException jce) { + // + } + assertFalse(failoverReporter.failedOver); + } + + // should failover now jedis.hset(key, "f1", "v1"); assertTrue(failoverReporter.failedOver); @@ -129,7 +140,8 @@ public void pipelineFailover() { MultiClusterClientConfig.Builder builder = new MultiClusterClientConfig.Builder( getClusterConfigs(clientConfig, hostPort_1, hostPort_2)) .circuitBreakerSlidingWindowMinCalls(slidingWindowMinCalls) - .circuitBreakerSlidingWindowSize(slidingWindowSize); + .circuitBreakerSlidingWindowSize(slidingWindowSize) + .fallbackExceptionList(Arrays.asList(JedisConnectionException.class)); RedisFailoverReporter failoverReporter = new RedisFailoverReporter(); MultiClusterPooledConnectionProvider cacheProvider = new MultiClusterPooledConnectionProvider(builder.build()); @@ -137,11 +149,13 @@ public void pipelineFailover() { UnifiedJedis jedis = new UnifiedJedis(cacheProvider); - assertFalse(failoverReporter.failedOver); + String key = "hash-" + System.nanoTime(); log.info("Starting calls to Redis"); + assertFalse(failoverReporter.failedOver); AbstractPipeline pipe = jedis.pipelined(); - String key = "hash-" + System.nanoTime(); + assertFalse(failoverReporter.failedOver); pipe.hset(key, "f1", "v1"); + assertFalse(failoverReporter.failedOver); pipe.sync(); assertTrue(failoverReporter.failedOver); @@ -168,9 +182,9 @@ public void failoverFromAuthError() { UnifiedJedis jedis = new UnifiedJedis(cacheProvider); - assertFalse(failoverReporter.failedOver); - log.info("Starting calls to Redis"); String key = "hash-" + System.nanoTime(); + log.info("Starting calls to Redis"); + assertFalse(failoverReporter.failedOver); jedis.hset(key, "f1", "v1"); assertTrue(failoverReporter.failedOver); From 3dd2dd29e0480dbc7c0846928553fc17ab9115ea Mon Sep 17 00:00:00 2001 From: Gabriel Erzse Date: Thu, 7 Mar 2024 19:36:16 +0200 Subject: [PATCH 04/33] Support the MAXAGE option for CLIENT KILL (#3754) * Support the MAXAGE option for CLIENT KILL Starting with Redis 7.6, the CLIENT KILL command has a new option, called MAXAGE, to kill clients older than a given age. Add support for this new option. * Ensure clients are closed in some tests * More concise unit test code Co-authored-by: M Sazzadul Hoque <7600764+sazzad16@users.noreply.github.com> --------- Co-authored-by: Gabriel Erzse Co-authored-by: M Sazzadul Hoque <7600764+sazzad16@users.noreply.github.com> --- .../java/redis/clients/jedis/Protocol.java | 2 +- .../jedis/commands/ClientCommands.java | 6 ++-- .../jedis/params/ClientKillParams.java | 10 +++++++ .../commands/jedis/ClientCommandsTest.java | 29 +++++++++++++++++-- 4 files changed, 41 insertions(+), 6 deletions(-) diff --git a/src/main/java/redis/clients/jedis/Protocol.java b/src/main/java/redis/clients/jedis/Protocol.java index 31a93e3ebbd..531ee768c9d 100644 --- a/src/main/java/redis/clients/jedis/Protocol.java +++ b/src/main/java/redis/clients/jedis/Protocol.java @@ -301,7 +301,7 @@ public static enum Keyword implements Rawable { DELETE, LIBRARYNAME, WITHCODE, DESCRIPTION, GETKEYS, GETKEYSANDFLAGS, DOCS, FILTERBY, DUMP, MODULE, ACLCAT, PATTERN, DOCTOR, LATEST, HISTORY, USAGE, SAMPLES, PURGE, STATS, LOADEX, CONFIG, ARGS, RANK, NOW, VERSION, ADDR, SKIPME, USER, LADDR, - CHANNELS, NUMPAT, NUMSUB, SHARDCHANNELS, SHARDNUMSUB, NOVALUES; + CHANNELS, NUMPAT, NUMSUB, SHARDCHANNELS, SHARDNUMSUB, NOVALUES, MAXAGE; private final byte[] raw; diff --git a/src/main/java/redis/clients/jedis/commands/ClientCommands.java b/src/main/java/redis/clients/jedis/commands/ClientCommands.java index edcfbd602e7..75bda24a30c 100644 --- a/src/main/java/redis/clients/jedis/commands/ClientCommands.java +++ b/src/main/java/redis/clients/jedis/commands/ClientCommands.java @@ -30,10 +30,10 @@ public interface ClientCommands { String clientKill(String ip, int port); /** - * Close a given client connection. + * Close client connections based on certain selection parameters. * - * @param params Connection info will be closed - * @return Close success return OK + * @param params Parameters defining what client connections to close. + * @return The number of client connections that were closed. */ long clientKill(ClientKillParams params); diff --git a/src/main/java/redis/clients/jedis/params/ClientKillParams.java b/src/main/java/redis/clients/jedis/params/ClientKillParams.java index 12c65be882d..0082ef33408 100644 --- a/src/main/java/redis/clients/jedis/params/ClientKillParams.java +++ b/src/main/java/redis/clients/jedis/params/ClientKillParams.java @@ -67,6 +67,16 @@ public ClientKillParams laddr(String ip, int port) { return addParam(Keyword.LADDR, ip + ':' + port); } + /** + * Kill clients older than {@code maxAge} seconds. + * + * @param maxAge Clients older than this number of seconds will be killed. + * @return The {@code ClientKillParams} instance, for call chaining. + */ + public ClientKillParams maxAge(long maxAge) { + return addParam(Keyword.MAXAGE, maxAge); + } + @Override public void addParams(CommandArguments args) { params.forEach(kv -> args.add(kv.getKey()).add(kv.getValue())); 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 8c3f35db49c..cf7760dbf4b 100644 --- a/src/test/java/redis/clients/jedis/commands/jedis/ClientCommandsTest.java +++ b/src/test/java/redis/clients/jedis/commands/jedis/ClientCommandsTest.java @@ -222,10 +222,10 @@ public void killAddrIpPort() { @Test public void killUser() { - Jedis client2 = new Jedis(hnp.getHost(), hnp.getPort(), 500); client.aclSetUser("test_kill", "on", "+acl", ">password1"); - try { + try (Jedis client2 = new Jedis(hnp.getHost(), hnp.getPort(), 500)) { client2.auth("test_kill", "password1"); + assertEquals(1, jedis.clientKill(new ClientKillParams().user("test_kill"))); assertDisconnected(client2); } finally { @@ -233,6 +233,27 @@ public void killUser() { } } + @Test + public void killMaxAge() throws InterruptedException { + long maxAge = 2; + + // sleep twice the maxAge, to be sure + Thread.sleep(maxAge * 2 * 1000); + + try (Jedis client2 = new Jedis(hnp.getHost(), hnp.getPort(), 500)) { + client2.auth("foobared"); + + long killedClients = jedis.clientKill(new ClientKillParams().maxAge(maxAge)); + + // The reality is that some tests leak clients, so we can't assert + // on the exact number of killed clients. + assertTrue(killedClients > 0); + + assertDisconnected(client); + assertConnected(client2); + } + } + @Test public void clientInfo() { String info = client.clientInfo(); @@ -267,6 +288,10 @@ private void assertDisconnected(Jedis j) { } } + private void assertConnected(Jedis j) { + assertEquals("PONG", j.ping()); + } + private String findInClientList() { for (String clientInfo : jedis.clientList().split("\n")) { if (pattern.matcher(clientInfo).find()) { From ea76b84d1dfd5eada31468e166be1f47f93b86f7 Mon Sep 17 00:00:00 2001 From: Gabriel Erzse Date: Thu, 7 Mar 2024 19:40:50 +0200 Subject: [PATCH 05/33] Add unit tests for pipelining - migrate and db commands (#3759) * Add unit tests for pipelining * Rename test class according to convention --------- Co-authored-by: Gabriel Erzse --- .../clients/jedis/MigratePipeliningTest.java | 398 ++++++++++++++ .../redis/clients/jedis/PipeliningTest.java | 499 ++++++------------ 2 files changed, 560 insertions(+), 337 deletions(-) create mode 100644 src/test/java/redis/clients/jedis/MigratePipeliningTest.java diff --git a/src/test/java/redis/clients/jedis/MigratePipeliningTest.java b/src/test/java/redis/clients/jedis/MigratePipeliningTest.java new file mode 100644 index 00000000000..b7942fc140d --- /dev/null +++ b/src/test/java/redis/clients/jedis/MigratePipeliningTest.java @@ -0,0 +1,398 @@ +package redis.clients.jedis; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.both; +import static org.hamcrest.Matchers.containsString; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.hasItems; +import static org.hamcrest.Matchers.hasToString; +import static org.hamcrest.Matchers.instanceOf; +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import redis.clients.jedis.commands.jedis.JedisCommandsTestBase; +import redis.clients.jedis.exceptions.JedisDataException; +import redis.clients.jedis.params.MigrateParams; + +public class MigratePipeliningTest extends JedisCommandsTestBase { + + private static final byte[] bfoo = { 0x01, 0x02, 0x03 }; + private static final byte[] bbar = { 0x04, 0x05, 0x06 }; + private static final byte[] bfoo1 = { 0x07, 0x08, 0x01 }; + private static final byte[] bbar1 = { 0x09, 0x00, 0x01 }; + private static final byte[] bfoo2 = { 0x07, 0x08, 0x02 }; + private static final byte[] bbar2 = { 0x09, 0x00, 0x02 }; + private static final byte[] bfoo3 = { 0x07, 0x08, 0x03 }; + private static final byte[] bbar3 = { 0x09, 0x00, 0x03 }; + + private static final String host = hnp.getHost(); + private static final int port = 6386; + private static final int portAuth = hnp.getPort() + 1; + private static final int db = 2; + private static final int dbAuth = 3; + private static final int timeout = Protocol.DEFAULT_TIMEOUT; + + private Jedis dest; + private Jedis destAuth; + + @Before + @Override + public void setUp() throws Exception { + super.setUp(); + + dest = new Jedis(host, port, 500); + dest.flushAll(); + dest.select(db); + + destAuth = new Jedis(host, portAuth, 500); + destAuth.auth("foobared"); + destAuth.flushAll(); + destAuth.select(dbAuth); + } + + @After + @Override + public void tearDown() throws Exception { + dest.close(); + destAuth.close(); + super.tearDown(); + } + + @Test + public void noKey() { + Pipeline p = jedis.pipelined(); + + p.migrate(host, port, "foo", db, timeout); + p.migrate(host, port, bfoo, db, timeout); + p.migrate(host, port, db, timeout, new MigrateParams(), "foo1", "foo2", "foo3"); + p.migrate(host, port, db, timeout, new MigrateParams(), bfoo1, bfoo2, bfoo3); + + assertThat(p.syncAndReturnAll(), + hasItems("NOKEY", "NOKEY", "NOKEY", "NOKEY")); + } + + @Test + public void migrate() { + assertNull(dest.get("foo")); + + Pipeline p = jedis.pipelined(); + + p.set("foo", "bar"); + p.migrate(host, port, "foo", db, timeout); + p.get("foo"); + + assertThat(p.syncAndReturnAll(), + hasItems("OK", "OK", null)); + + assertEquals("bar", dest.get("foo")); + } + + @Test + public void migrateBinary() { + assertNull(dest.get(bfoo)); + + Pipeline p = jedis.pipelined(); + + p.set(bfoo, bbar); + p.migrate(host, port, bfoo, db, timeout); + p.get(bfoo); + + assertThat(p.syncAndReturnAll(), + hasItems("OK", "OK", null)); + + assertArrayEquals(bbar, dest.get(bfoo)); + } + + @Test + public void migrateEmptyParams() { + assertNull(dest.get("foo")); + + Pipeline p = jedis.pipelined(); + + p.set("foo", "bar"); + p.migrate(host, port, db, timeout, new MigrateParams(), "foo"); + p.get("foo"); + + assertThat(p.syncAndReturnAll(), + hasItems("OK", "OK", null)); + + assertEquals("bar", dest.get("foo")); + } + + @Test + public void migrateEmptyParamsBinary() { + assertNull(dest.get(bfoo)); + + Pipeline p = jedis.pipelined(); + + p.set(bfoo, bbar); + p.migrate(host, port, db, timeout, new MigrateParams(), bfoo); + p.get(bfoo); + + assertThat(p.syncAndReturnAll(), + hasItems("OK", "OK", null)); + + assertArrayEquals(bbar, dest.get(bfoo)); + } + + @Test + public void migrateCopy() { + assertNull(dest.get("foo")); + + Pipeline p = jedis.pipelined(); + + p.set("foo", "bar"); + p.migrate(host, port, db, timeout, new MigrateParams().copy(), "foo"); + p.get("foo"); + + assertThat(p.syncAndReturnAll(), + hasItems("OK", "OK", "bar")); + + assertEquals("bar", dest.get("foo")); + } + + @Test + public void migrateCopyBinary() { + assertNull(dest.get(bfoo)); + + Pipeline p = jedis.pipelined(); + + p.set(bfoo, bbar); + p.migrate(host, port, db, timeout, new MigrateParams().copy(), bfoo); + p.get(bfoo); + + assertThat(p.syncAndReturnAll(), + hasItems("OK", "OK", bbar)); + + assertArrayEquals(bbar, dest.get(bfoo)); + } + + @Test + public void migrateReplace() { + dest.set("foo", "bar2"); + + assertEquals("bar2", dest.get("foo")); + + Pipeline p = jedis.pipelined(); + + p.set("foo", "bar1"); + p.migrate(host, port, db, timeout, new MigrateParams().replace(), "foo"); + p.get("foo"); + + assertThat(p.syncAndReturnAll(), + hasItems("OK", "OK", null)); + + assertEquals("bar1", dest.get("foo")); + } + + @Test + public void migrateReplaceBinary() { + dest.set(bfoo, bbar2); + + assertArrayEquals(bbar2, dest.get(bfoo)); + + Pipeline p = jedis.pipelined(); + + p.set(bfoo, bbar1); + p.migrate(host, port, db, timeout, new MigrateParams().replace(), bfoo); + p.get(bfoo); + + assertThat(p.syncAndReturnAll(), + hasItems("OK", "OK", null)); + + assertArrayEquals(bbar1, dest.get(bfoo)); + } + + @Test + public void migrateCopyReplace() { + dest.set("foo", "bar2"); + + assertEquals("bar2", dest.get("foo")); + + Pipeline p = jedis.pipelined(); + + p.set("foo", "bar1"); + p.migrate(host, port, db, timeout, new MigrateParams().copy().replace(), "foo"); + p.get("foo"); + + assertThat(p.syncAndReturnAll(), + hasItems("OK", "OK", "bar1")); + + assertEquals("bar1", dest.get("foo")); + } + + @Test + public void migrateCopyReplaceBinary() { + dest.set(bfoo, bbar2); + + assertArrayEquals(bbar2, dest.get(bfoo)); + + Pipeline p = jedis.pipelined(); + + p.set(bfoo, bbar1); + p.migrate(host, port, db, timeout, new MigrateParams().copy().replace(), bfoo); + p.get(bfoo); + + assertThat(p.syncAndReturnAll(), + hasItems("OK", "OK", bbar1)); + + assertArrayEquals(bbar1, dest.get(bfoo)); + } + + @Test + public void migrateAuth() { + assertNull(dest.get("foo")); + + Pipeline p = jedis.pipelined(); + + p.set("foo", "bar"); + p.migrate(host, portAuth, dbAuth, timeout, new MigrateParams().auth("foobared"), "foo"); + p.get("foo"); + + assertThat(p.syncAndReturnAll(), + hasItems("OK", "OK", null)); + + assertEquals("bar", destAuth.get("foo")); + } + + @Test + public void migrateAuthBinary() { + assertNull(dest.get(bfoo)); + + Pipeline p = jedis.pipelined(); + + p.set(bfoo, bbar); + p.migrate(host, portAuth, dbAuth, timeout, new MigrateParams().auth("foobared"), bfoo); + p.get(bfoo); + + assertThat(p.syncAndReturnAll(), + hasItems("OK", "OK", null)); + + assertArrayEquals(bbar, destAuth.get(bfoo)); + } + + @Test + public void migrateAuth2() { + assertNull(jedis.get("foo")); + + Pipeline p = destAuth.pipelined(); + + p.set("foo", "bar"); + p.migrate(host, hnp.getPort(), 0, timeout, + new MigrateParams().auth2("acljedis", "fizzbuzz"), "foo"); + p.get("foo"); + + assertThat(p.syncAndReturnAll(), + hasItems("OK", "OK", null)); + + assertEquals("bar", jedis.get("foo")); + } + + @Test + public void migrateAuth2Binary() { + assertNull(jedis.get(bfoo)); + + Pipeline p = dest.pipelined(); + + p.set(bfoo, bbar); + p.migrate(host, hnp.getPort(), 0, timeout, + new MigrateParams().auth2("acljedis", "fizzbuzz"), bfoo); + p.get(bfoo); + + assertThat(p.syncAndReturnAll(), + hasItems("OK", "OK", null)); + + assertArrayEquals(bbar, jedis.get(bfoo)); + } + + @Test + public void migrateMulti() { + assertNull(dest.get("foo1")); + assertNull(dest.get("foo2")); + assertNull(dest.get("foo3")); + + Pipeline p = jedis.pipelined(); + + p.mset("foo1", "bar1", "foo2", "bar2", "foo3", "bar3"); + p.migrate(host, port, db, timeout, new MigrateParams(), "foo1", "foo2", "foo3"); + + assertThat(p.syncAndReturnAll(), + hasItems("OK", "OK")); + + assertEquals("bar1", dest.get("foo1")); + assertEquals("bar2", dest.get("foo2")); + assertEquals("bar3", dest.get("foo3")); + } + + @Test + public void migrateMultiBinary() { + assertNull(dest.get(bfoo1)); + assertNull(dest.get(bfoo2)); + assertNull(dest.get(bfoo3)); + + Pipeline p = jedis.pipelined(); + + p.mset(bfoo1, bbar1, bfoo2, bbar2, bfoo3, bbar3); + p.migrate(host, port, db, timeout, new MigrateParams(), bfoo1, bfoo2, bfoo3); + + assertThat(p.syncAndReturnAll(), + hasItems("OK", "OK")); + + assertArrayEquals(bbar1, dest.get(bfoo1)); + assertArrayEquals(bbar2, dest.get(bfoo2)); + assertArrayEquals(bbar3, dest.get(bfoo3)); + } + + @Test + public void migrateConflict() { + dest.set("foo2", "bar"); + + assertNull(dest.get("foo1")); + assertEquals("bar", dest.get("foo2")); + assertNull(dest.get("foo3")); + + Pipeline p = jedis.pipelined(); + + p.mset("foo1", "bar1", "foo2", "bar2", "foo3", "bar3"); + p.migrate(host, port, db, timeout, new MigrateParams(), "foo1", "foo2", "foo3"); + + assertThat(p.syncAndReturnAll(), + hasItems( + equalTo("OK"), + both(instanceOf(JedisDataException.class)).and(hasToString(containsString("BUSYKEY"))) + )); + + assertEquals("bar1", dest.get("foo1")); + assertEquals("bar", dest.get("foo2")); + assertEquals("bar3", dest.get("foo3")); + } + + @Test + public void migrateConflictBinary() { + dest.set(bfoo2, bbar); + + assertNull(dest.get(bfoo1)); + assertArrayEquals(bbar, dest.get(bfoo2)); + assertNull(dest.get(bfoo3)); + + Pipeline p = jedis.pipelined(); + + p.mset(bfoo1, bbar1, bfoo2, bbar2, bfoo3, bbar3); + p.migrate(host, port, db, timeout, new MigrateParams(), bfoo1, bfoo2, bfoo3); + + assertThat(p.syncAndReturnAll(), + hasItems( + equalTo("OK"), + both(instanceOf(JedisDataException.class)).and(hasToString(containsString("BUSYKEY"))) + )); + + assertArrayEquals(bbar1, dest.get(bfoo1)); + assertArrayEquals(bbar, dest.get(bfoo2)); + assertArrayEquals(bbar3, dest.get(bfoo3)); + } + +} diff --git a/src/test/java/redis/clients/jedis/PipeliningTest.java b/src/test/java/redis/clients/jedis/PipeliningTest.java index bb9834c8d62..527b9dfc6d5 100644 --- a/src/test/java/redis/clients/jedis/PipeliningTest.java +++ b/src/test/java/redis/clients/jedis/PipeliningTest.java @@ -1,5 +1,10 @@ package redis.clients.jedis; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.hasItems; +import static org.hamcrest.Matchers.instanceOf; +import static org.hamcrest.Matchers.matchesPattern; import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; @@ -16,18 +21,23 @@ import java.util.Set; import java.util.UUID; -import org.hamcrest.MatcherAssert; +import org.hamcrest.Matcher; import org.hamcrest.Matchers; import org.junit.Test; - -import redis.clients.jedis.exceptions.JedisDataException; -import redis.clients.jedis.resps.Tuple; +import redis.clients.jedis.commands.ProtocolCommand; import redis.clients.jedis.commands.jedis.JedisCommandsTestBase; +import redis.clients.jedis.exceptions.JedisDataException; import redis.clients.jedis.params.SetParams; +import redis.clients.jedis.resps.Tuple; import redis.clients.jedis.util.SafeEncoder; public class PipeliningTest extends JedisCommandsTestBase { + private static final byte[] bfoo = { 0x01, 0x02, 0x03, 0x04 }; + private static final byte[] bfoo1 = { 0x01, 0x02, 0x03, 0x04, 0x11, 0x12, 0x13, 0x14 }; + private static final byte[] bbar = { 0x05, 0x06, 0x07, 0x08 }; + private static final byte[] bbaz = { 0x09, 0x0A, 0x0B, 0x0C }; + @Test public void pipeline() { Pipeline p = jedis.pipelined(); @@ -271,150 +281,6 @@ public void piplineWithError() { } assertEquals(r.get(), "bar"); } -// -// @Test -// public void multi() { -// Pipeline p = jedis.pipelined(); -// p.multi(); -// Response r1 = p.hincrBy("a", "f1", -1); -// Response r2 = p.hincrBy("a", "f1", -2); -// Response> r3 = p.exec(); -// List result = p.syncAndReturnAll(); -// -// assertEquals(Long.valueOf(-1), r1.get()); -// assertEquals(Long.valueOf(-3), r2.get()); -// -// assertEquals(4, result.size()); -// -// assertEquals("OK", result.get(0)); -// assertEquals("QUEUED", result.get(1)); -// assertEquals("QUEUED", result.get(2)); -// -// // 4th result is a list with the results from the multi -// @SuppressWarnings("unchecked") -// List multiResult = (List) result.get(3); -// assertEquals(Long.valueOf(-1), multiResult.get(0)); -// assertEquals(Long.valueOf(-3), multiResult.get(1)); -// -// assertEquals(Long.valueOf(-1), r3.get().get(0)); -// assertEquals(Long.valueOf(-3), r3.get().get(1)); -// -// } -// -// @Test -// public void multiWithMassiveRequests() { -// Pipeline p = jedis.pipelined(); -// p.multi(); -// -// List> responseList = new ArrayList>(); -// for (int i = 0; i < 100000; i++) { -// // any operation should be ok, but shouldn't forget about timeout -// responseList.add(p.setbit("test", 1, true)); -// } -// -// Response> exec = p.exec(); -// p.sync(); -// -// // we don't need to check return value -// // if below codes run without throwing Exception, we're ok -// exec.get(); -// -// for (Response resp : responseList) { -// resp.get(); -// } -// } -// -// @Test -// public void multiWithSync() { -// jedis.set("foo", "314"); -// jedis.set("bar", "foo"); -// jedis.set("hello", "world"); -// Pipeline p = jedis.pipelined(); -// Response r1 = p.get("bar"); -// p.multi(); -// Response r2 = p.get("foo"); -// p.exec(); -// Response r3 = p.get("hello"); -// p.sync(); -// -// // before multi -// assertEquals("foo", r1.get()); -// // It should be readable whether exec's response was built or not -// assertEquals("314", r2.get()); -// // after multi -// assertEquals("world", r3.get()); -// } -// -// @Test -// public void multiWatch() { -// final String key = "foo"; -// assertEquals(5L, jedis.incrBy(key, 5L)); -// -// List expect = new ArrayList<>(); -// List expMulti = null; // MULTI will fail -// -// Pipeline pipe = jedis.pipelined(); -// pipe.watch(key); expect.add("OK"); -// pipe.incrBy(key, 3L); expect.add(8L); -// pipe.multi(); expect.add("OK"); -// pipe.incrBy(key, 6L); expect.add("QUEUED"); -// assertEquals(expect, pipe.syncAndReturnAll()); expect.clear(); -// -// try (Jedis tweak = createJedis()) { -// assertEquals(10L, tweak.incrBy(key, 2L)); -// } -// -// pipe.incrBy(key, 4L); expect.add("QUEUED"); -// pipe.exec(); expect.add(expMulti); // failed MULTI -// pipe.incrBy(key, 7L); expect.add(17L); -// assertEquals(expect, pipe.syncAndReturnAll()); -// } -// -// @Test -// public void multiUnwatch() { -// final String key = "foo"; -// assertEquals(5L, jedis.incrBy(key, 5L)); -// -// List expect = new ArrayList<>(); -// List expMulti = new ArrayList<>(); -// -// Pipeline pipe = jedis.pipelined(); -// pipe.watch(key); expect.add("OK"); -// pipe.incrBy(key, 3L); expect.add(8L); -// pipe.unwatch(); expect.add("OK"); -// pipe.multi(); expect.add("OK"); -// pipe.incrBy(key, 6L); expect.add("QUEUED"); expMulti.add(16L); -// assertEquals(expect, pipe.syncAndReturnAll()); expect.clear(); -// -// try (Jedis tweak = createJedis()) { -// assertEquals(10L, tweak.incrBy(key, 2L)); -// } -// -// pipe.incrBy(key, 4L); expect.add("QUEUED"); expMulti.add(20L); -// pipe.exec(); expect.add(expMulti); // successful MULTI -// pipe.incrBy(key, 7L); expect.add(27L); -// assertEquals(expect, pipe.syncAndReturnAll()); -// } -// -// @Test(expected = IllegalStateException.class) -// public void pipelineExecWhenNotInMulti() { -// Pipeline pipeline = jedis.pipelined(); -// pipeline.exec(); -// } -// -// @Test(expected = IllegalStateException.class) -// public void pipelineDiscardWhenNotInMulti() { -// Pipeline pipeline = jedis.pipelined(); -// pipeline.discard(); -// } -// -// @Test(expected = IllegalStateException.class) -// public void pipelineMultiWhenAlreadyInMulti() { -// Pipeline pipeline = jedis.pipelined(); -// pipeline.multi(); -// pipeline.set("foo", "3"); -// pipeline.multi(); -// } @Test(expected = IllegalStateException.class) public void testJedisThrowExceptionWhenInPipeline() { @@ -441,18 +307,6 @@ public void testResetStateWhenInPipeline() { String result = jedis.get("foo"); assertEquals(result, "3"); } -// -// @Test -// public void testDiscardInPipeline() { -// Pipeline pipeline = jedis.pipelined(); -// pipeline.multi(); -// pipeline.set("foo", "bar"); -// Response discard = pipeline.discard(); -// Response get = pipeline.get("foo"); -// pipeline.sync(); -// discard.get(); -// get.get(); -// } @Test public void waitReplicas() { @@ -581,8 +435,8 @@ public void testEvalNestedLists() { p.sync(); List results = (List) result.get(); - MatcherAssert.assertThat((List) results.get(0), Matchers.hasItem("key1")); - MatcherAssert.assertThat((List) results.get(1), Matchers.hasItem(2L)); + assertThat((List) results.get(0), Matchers.hasItem("key1")); + assertThat((List) results.get(1), Matchers.hasItem(2L)); } @Test @@ -595,8 +449,8 @@ public void testEvalNestedListsWithBinary() { p.sync(); List results = (List) result.get(); - MatcherAssert.assertThat((List) results.get(0), Matchers.hasItem(bKey)); - MatcherAssert.assertThat((List) results.get(1), Matchers.hasItem(2L)); + assertThat((List) results.get(0), Matchers.hasItem(bKey)); + assertThat((List) results.get(1), Matchers.hasItem(2L)); } @Test @@ -657,72 +511,6 @@ public void testEvalshaKeyAndArgWithBinary() { assertNull(result1.get()); assertArrayEquals(SafeEncoder.encode("13"), result2.get()); } -// -// @Test -// public void testPipelinedTransactionResponse() { -// -// String key1 = "key1"; -// String val1 = "val1"; -// -// String key2 = "key2"; -// String val2 = "val2"; -// -// String key3 = "key3"; -// String field1 = "field1"; -// String field2 = "field2"; -// String field3 = "field3"; -// String field4 = "field4"; -// -// String value1 = "value1"; -// String value2 = "value2"; -// String value3 = "value3"; -// String value4 = "value4"; -// -// Map hashMap = new HashMap(); -// hashMap.put(field1, value1); -// hashMap.put(field2, value2); -// -// String key4 = "key4"; -// Map hashMap1 = new HashMap(); -// hashMap1.put(field3, value3); -// hashMap1.put(field4, value4); -// -// jedis.set(key1, val1); -// jedis.set(key2, val2); -// jedis.hmset(key3, hashMap); -// jedis.hmset(key4, hashMap1); -// -// Pipeline pipeline = jedis.pipelined(); -// pipeline.multi(); -// -// pipeline.get(key1); -// pipeline.hgetAll(key2); -// pipeline.hgetAll(key3); -// pipeline.get(key4); -// -// Response> response = pipeline.exec(); -// pipeline.sync(); -// -// List result = response.get(); -// -// assertEquals(4, result.size()); -// -// assertEquals("val1", result.get(0)); -// -// assertTrue(result.get(1) instanceof JedisDataException); -// -// Map hashMapReceived = (Map) result.get(2); -// Iterator iterator = hashMapReceived.keySet().iterator(); -// String mapKey1 = iterator.next(); -// String mapKey2 = iterator.next(); -// assertFalse(iterator.hasNext()); -// verifyHasBothValues(mapKey1, mapKey2, field1, field2); -// String mapValue1 = hashMapReceived.get(mapKey1); -// String mapValue2 = hashMapReceived.get(mapKey2); -// verifyHasBothValues(mapValue1, mapValue2, value1, value2); -// -// assertTrue(result.get(3) instanceof JedisDataException); -// } @Test public void testSyncWithNoCommandQueued() { @@ -760,111 +548,148 @@ public void testCloseable() throws IOException { retFuture2.get(); jedis2.close(); } -// -// @Test -// public void testCloseableWithMulti() throws IOException { -// // we need to test with fresh instance of Jedis -// Jedis jedis2 = new Jedis(hnp.getHost(), hnp.getPort(), 500); -// jedis2.auth("foobared"); -// -// Pipeline pipeline = jedis2.pipelined(); -// Response retFuture1 = pipeline.set("a", "1"); -// Response retFuture2 = pipeline.set("b", "2"); -// -// pipeline.multi(); -// -// pipeline.set("a", "a"); -// pipeline.set("b", "b"); -// -// pipeline.close(); -// -// try { -// pipeline.exec(); -// fail("close should discard transaction"); -// } catch (IllegalStateException e) { -// assertTrue(e.getMessage().contains("EXEC without MULTI")); -// // pass -// } -// -// // it shouldn't meet any exception -// retFuture1.get(); -// retFuture2.get(); -// jedis2.close(); -// } -// -// @Test -// public void execAbort() { -// final String luaTimeLimitKey = "lua-time-limit"; -// final String luaTimeLimit = jedis.configGet(luaTimeLimitKey).get(1); -// jedis.configSet(luaTimeLimitKey, "10"); -// -// Thread thread = new Thread(() -> { -// try (Jedis blocker = createJedis()) { -// blocker.eval("while true do end"); -// } catch (Exception ex) { -// // swallow any exception -// } -// }); -// -// Pipeline pipe = jedis.pipelined(); -// pipe.incr("foo"); -// pipe.multi(); -// pipe.incr("foo"); -// pipe.sync(); -// -// thread.start(); -// try { -// Thread.sleep(12); // allow Redis to be busy with the script and 'lua-time-limit' to exceed -// } catch (InterruptedException ex) { } -// -// pipe.incr("foo"); -// Response> txResp = pipe.exec(); -// pipe.sync(); -// try { -// txResp.get(); -// } catch (Exception ex) { -// assertSame(AbortedTransactionException.class, ex.getClass()); -// } finally { -// try { -// String status = jedis.scriptKill(); -// // https://github.com/redis/jedis/issues/2656 -// if ("OK".equalsIgnoreCase(status)) { -// scriptKillWait(); -// } else { -// // #2656: Checking if this status is actually 'OK' when error occurs in next command. -// org.apache.logging.log4j.LogManager.getLogger().error( -// String.format("Status if SCRIPT KILL command is \"%s\"", status)); -// } -// } finally { -// jedis.configSet(luaTimeLimitKey, luaTimeLimit); -// } -// } -// } -// -// private void scriptKillWait() { -// int attemptLeft = 10; -// while (attemptLeft > 0) { -// try (Jedis pingJedis = createJedis()) { -// while (attemptLeft > 0) { -// try { -// pingJedis.ping(); -// return; // wait is over -// } catch (JedisBusyException busy) { -// Thread.sleep(10); // BUSY, waiting for some time -// --attemptLeft; // doing this later; otherwise any exception in Thread.sleep() -// // would cause decrement twice for the same turn. -// } -// } -// } catch (Exception any) { -// --attemptLeft; -// // try new connection -// } -// } -// } -// -// private void verifyHasBothValues(String firstKey, String secondKey, String value1, String value2) { -// assertFalse(firstKey.equals(secondKey)); -// assertTrue(firstKey.equals(value1) || firstKey.equals(value2)); -// assertTrue(secondKey.equals(value1) || secondKey.equals(value2)); -// } + + @Test + public void time() { + Pipeline p = jedis.pipelined(); + + p.time(); + + // we get back one result, with two components: the seconds, and the microseconds, but encoded as strings + Matcher timeResponseMatcher = hasItems(matchesPattern("\\d+"), matchesPattern("\\d+")); + assertThat(p.syncAndReturnAll(), + hasItems(timeResponseMatcher)); + } + + @Test + public void dbSize() { + Pipeline p = jedis.pipelined(); + + p.dbSize(); + p.set("foo", "bar"); + p.dbSize(); + + assertThat(p.syncAndReturnAll(), + hasItems(0L, "OK", 1L)); + } + + @Test + public void move() { + Pipeline p = jedis.pipelined(); + + p.move("foo", 1); + p.set("foo", "bar"); + p.move("foo", 1); + p.get("foo"); + p.select(1); + p.get("foo"); + + assertThat(p.syncAndReturnAll(), + hasItems(0L, "OK", 1L, null, "OK", "bar")); + } + + @Test + public void moveBinary() { + Pipeline p = jedis.pipelined(); + + p.move(bfoo, 1); + p.set(bfoo, bbar); + p.move(bfoo, 1); + p.get(bfoo); + p.select(1); + p.get(bfoo); + + assertThat(p.syncAndReturnAll(), + hasItems(0L, "OK", 1L, null, "OK", bbar)); + } + + @Test + public void swapDb() { + Pipeline p = jedis.pipelined(); + + p.set("foo", "bar"); + p.get("foo"); + p.select(1); + p.get("foo"); + p.swapDB(0, 1); + p.select(0); + p.get("foo"); + p.select(1); + p.get("foo"); + + assertThat(p.syncAndReturnAll(), + hasItems("OK", "bar", "OK", null, "OK", "OK", null, "OK", "bar")); + } + + @Test + public void copyToAnotherDb() { + Pipeline p = jedis.pipelined(); + + p.copy("foo", "foo-copy", 1, false); + p.set("foo", "bar"); + p.copy("foo", "foo-copy", 1, false); + p.get("foo"); + p.select(1); + p.get("foo-copy"); + p.select(0); + p.set("foo", "baz"); + p.copy("foo", "foo-copy", 1, false); + p.get("foo"); + p.select(1); + p.get("foo-copy"); + + assertThat(p.syncAndReturnAll(), + hasItems(false, "OK", true, "bar", "OK", "bar", "OK", "OK", false, "baz", "bar")); + } + + @Test + public void copyToAnotherDbBinary() { + Pipeline p = jedis.pipelined(); + + + p.copy(bfoo, bfoo1, 1, false); + p.set(bfoo, bbar); + p.copy(bfoo, bfoo1, 1, false); + p.get(bfoo); + p.select(1); + p.get(bfoo1); + p.select(0); + p.set(bfoo, bbaz); + p.copy(bfoo, bfoo1, 1, false); + p.get(bfoo); + p.select(1); + p.get(bfoo1); + + assertThat(p.syncAndReturnAll(), + hasItems(false, "OK", true, bbar, "OK", bbar, "OK", "OK", false, bbaz, bbar)); + } + + enum Foo implements ProtocolCommand { + FOO; + + @Override + public byte[] getRaw() { + return SafeEncoder.encode(name()); + } + } + + @Test + public void errorInTheMiddle() { + CommandObject invalidCommand = + new CommandObject<>(new CommandObjects().commandArguments(Foo.FOO), BuilderFactory.STRING); + + Pipeline p = jedis.pipelined(); + + p.set("foo", "bar"); + p.appendCommand(invalidCommand); + p.get("foo"); + + assertThat(p.syncAndReturnAll(), + hasItems( + equalTo("OK"), + instanceOf(JedisDataException.class), + equalTo("bar") + )); + } + } From dea371d9cc45b676199d64a5c3d3d54b3efd9749 Mon Sep 17 00:00:00 2001 From: M Sazzadul Hoque <7600764+sazzad16@users.noreply.github.com> Date: Fri, 8 Mar 2024 01:42:36 +0600 Subject: [PATCH 06/33] Add Hashes pipeline commands unit tests (#3288) --- .../pipeline/HashesPipelineCommandsTest.java | 391 ++++++++++++++++++ .../pipeline/PipelineCommandsTestBase.java | 28 ++ .../pooled/PooledCommandsTestHelper.java | 8 +- .../redis/clients/jedis/util/AssertUtil.java | 44 ++ 4 files changed, 467 insertions(+), 4 deletions(-) create mode 100644 src/test/java/redis/clients/jedis/commands/unified/pipeline/HashesPipelineCommandsTest.java create mode 100644 src/test/java/redis/clients/jedis/commands/unified/pipeline/PipelineCommandsTestBase.java 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 new file mode 100644 index 00000000000..e276441e176 --- /dev/null +++ b/src/test/java/redis/clients/jedis/commands/unified/pipeline/HashesPipelineCommandsTest.java @@ -0,0 +1,391 @@ +package redis.clients.jedis.commands.unified.pipeline; + +import static redis.clients.jedis.util.AssertUtil.assertPipelineSyncAll; + +import java.util.*; + +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; + +import redis.clients.jedis.commands.unified.pooled.PooledCommandsTestHelper; + +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 }; + + final byte[] bbar1 = { 0x05, 0x06, 0x07, 0x08, 0x0A }; + final byte[] bbar2 = { 0x05, 0x06, 0x07, 0x08, 0x0B }; + final byte[] bbar3 = { 0x05, 0x06, 0x07, 0x08, 0x0C }; + final byte[] bbarstar = { 0x05, 0x06, 0x07, 0x08, '*' }; + + @Test + public void hset() { + pipe.hset("foo", "bar", "car"); + pipe.hset("foo", "bar", "foo"); + + // Binary + pipe.hset(bfoo, bbar, bcar); + pipe.hset(bfoo, bbar, bfoo); + + assertPipelineSyncAll( + Arrays.asList(1L, 0L, 1L, 0L), + pipe.syncAndReturnAll()); + } + + @Test + public void hget() { + pipe.hset("foo", "bar", "car"); + pipe.hget("bar", "foo"); + pipe.hget("foo", "car"); + pipe.hget("foo", "bar"); + + // Binary + pipe.hset(bfoo, bbar, bcar); + pipe.hget(bbar, bfoo); + pipe.hget(bfoo, bcar); + pipe.hget(bfoo, bbar); + + assertPipelineSyncAll( + Arrays.asList( + 1L, null, null, "car", + 1L, null, null, bcar), + pipe.syncAndReturnAll()); + } + + @Test + public void hsetnx() { + pipe.hsetnx("foo", "bar", "car"); + pipe.hget("foo", "bar"); + + pipe.hsetnx("foo", "bar", "foo"); + pipe.hget("foo", "bar"); + + pipe.hsetnx("foo", "car", "bar"); + pipe.hget("foo", "car"); + + // Binary + pipe.hsetnx(bfoo, bbar, bcar); + pipe.hget(bfoo, bbar); + + pipe.hsetnx(bfoo, bbar, bfoo); + pipe.hget(bfoo, bbar); + + pipe.hsetnx(bfoo, bcar, bbar); + pipe.hget(bfoo, bcar); + + assertPipelineSyncAll( + Arrays.asList( + 1L, "car", 0L, "car", 1L, "bar", + 1L, bcar, 0L, bcar, 1L, bbar), + pipe.syncAndReturnAll()); + } + + @Test + public void hmset() { + Map hash = new HashMap<>(); + hash.put("bar", "car"); + hash.put("car", "bar"); + pipe.hmset("foo", hash); + pipe.hget("foo", "bar"); + pipe.hget("foo", "car"); + + // Binary + Map bhash = new HashMap<>(); + bhash.put(bbar, bcar); + bhash.put(bcar, bbar); + pipe.hmset(bfoo, bhash); + pipe.hget(bfoo, bbar); + pipe.hget(bfoo, bcar); + + assertPipelineSyncAll( + Arrays.asList("OK", "car", "bar", "OK", bcar, bbar), + pipe.syncAndReturnAll()); + } + + @Test + public void hsetVariadic() { + Map hash = new HashMap<>(); + hash.put("bar", "car"); + hash.put("car", "bar"); + pipe.hset("foo", hash); + pipe.hget("foo", "bar"); + pipe.hget("foo", "car"); + + // Binary + Map bhash = new HashMap<>(); + bhash.put(bbar, bcar); + bhash.put(bcar, bbar); + pipe.hset(bfoo, bhash); + pipe.hget(bfoo, bbar); + pipe.hget(bfoo, bcar); + + assertPipelineSyncAll( + Arrays.asList(2L, "car", "bar", 2L, bcar, bbar), + pipe.syncAndReturnAll()); + } + + @Test + public void hmget() { + Map hash = new HashMap<>(); + hash.put("bar", "car"); + hash.put("car", "bar"); + pipe.hmset("foo", hash); + + pipe.hmget("foo", "bar", "car", "foo"); + List expected = new ArrayList<>(); + expected.add("car"); + expected.add("bar"); + expected.add(null); + + // Binary + Map bhash = new HashMap<>(); + bhash.put(bbar, bcar); + bhash.put(bcar, bbar); + pipe.hmset(bfoo, bhash); + + pipe.hmget(bfoo, bbar, bcar, bfoo); + List bexpected = new ArrayList<>(); + bexpected.add(bcar); + bexpected.add(bbar); + bexpected.add(null); + + assertPipelineSyncAll( + Arrays.asList( + "OK", Arrays.asList("car", "bar", null), + "OK", Arrays.asList(bcar, bbar, null)), + pipe.syncAndReturnAll()); + } + + @Test + public void hincrBy() { + pipe.hincrBy("foo", "bar", 1); + pipe.hincrBy("foo", "bar", -1); + pipe.hincrBy("foo", "bar", -10); + + // Binary + pipe.hincrBy(bfoo, bbar, 1); + pipe.hincrBy(bfoo, bbar, -1); + pipe.hincrBy(bfoo, bbar, -10); + + assertPipelineSyncAll( + Arrays.asList(1L, 0L, -10L, 1L, 0L, -10L), + pipe.syncAndReturnAll()); + } + + @Test + public void hincrByFloat() { + pipe.hincrByFloat("foo", "bar", 1.5d); + pipe.hincrByFloat("foo", "bar", -1.5d); + pipe.hincrByFloat("foo", "bar", -10.7d); + + // Binary + pipe.hincrByFloat(bfoo, bbar, 1.5d); + pipe.hincrByFloat(bfoo, bbar, -1.5d); + pipe.hincrByFloat(bfoo, bbar, -10.7d); + + assertPipelineSyncAll( + Arrays.asList(1.5, 0d, -10.7, 1.5, 0d, -10.7), + pipe.syncAndReturnAll()); + } + + @Test + public void hexists() { + Map hash = new HashMap<>(); + hash.put("bar", "car"); + hash.put("car", "bar"); + pipe.hset("foo", hash); + + pipe.hexists("bar", "foo"); + pipe.hexists("foo", "foo"); + pipe.hexists("foo", "bar"); + + // Binary + Map bhash = new HashMap<>(); + bhash.put(bbar, bcar); + bhash.put(bcar, bbar); + pipe.hset(bfoo, bhash); + + pipe.hexists(bbar, bfoo); + pipe.hexists(bfoo, bfoo); + pipe.hexists(bfoo, bbar); + + assertPipelineSyncAll( + Arrays.asList( + 2L, false, false, true, + 2L, false, false, true), + pipe.syncAndReturnAll()); + } + + @Test + public void hdel() { + Map hash = new HashMap<>(); + hash.put("bar", "car"); + hash.put("car", "bar"); + pipe.hset("foo", hash); + + pipe.hdel("bar", "foo"); + pipe.hdel("foo", "foo"); + pipe.hdel("foo", "bar"); + pipe.hget("foo", "bar"); + + // Binary + Map bhash = new HashMap<>(); + bhash.put(bbar, bcar); + bhash.put(bcar, bbar); + pipe.hset(bfoo, bhash); + + pipe.hdel(bbar, bfoo); + pipe.hdel(bfoo, bfoo); + pipe.hdel(bfoo, bbar); + pipe.hget(bfoo, bbar); + + assertPipelineSyncAll( + Arrays.asList( + 2L, 0L, 0L, 1L, null, + 2L, 0L, 0L, 1L, null), + pipe.syncAndReturnAll()); + } + + @Test + public void hlen() { + Map hash = new HashMap<>(); + hash.put("bar", "car"); + hash.put("car", "bar"); + pipe.hset("foo", hash); + + pipe.hlen("bar"); + pipe.hlen("foo"); + + // Binary + Map bhash = new HashMap<>(); + bhash.put(bbar, bcar); + bhash.put(bcar, bbar); + pipe.hset(bfoo, bhash); + + pipe.hlen(bbar); + pipe.hlen(bfoo); + + assertPipelineSyncAll( + Arrays.asList(2L, 0L, 2L, 2L, 0L, 2L), + pipe.syncAndReturnAll()); + } + + @Test + public void hkeys() { + Map hash = new LinkedHashMap<>(); + hash.put("bar", "car"); + hash.put("car", "bar"); + pipe.hset("foo", hash); + + pipe.hkeys("foo"); + Set expected = new LinkedHashSet<>(); + expected.add("bar"); + expected.add("car"); + + // Binary + Map bhash = new LinkedHashMap<>(); + bhash.put(bbar, bcar); + bhash.put(bcar, bbar); + pipe.hset(bfoo, bhash); + + pipe.hkeys(bfoo); + Set bexpected = new LinkedHashSet<>(); + bexpected.add(bbar); + bexpected.add(bcar); + + assertPipelineSyncAll( + Arrays.asList( + 2L, new HashSet<>(Arrays.asList("bar", "car")), + 2L, new HashSet<>(Arrays.asList(bbar, bcar))), + pipe.syncAndReturnAll()); + } + + @Test + public void hvals() { + Map hash = new LinkedHashMap<>(); + hash.put("bar", "car"); + //hash.put("car", "bar"); + pipe.hset("foo", hash); + + pipe.hvals("foo"); + + // Binary + Map bhash = new LinkedHashMap<>(); + bhash.put(bbar, bcar); + //bhash.put(bcar, bbar); + pipe.hset(bfoo, bhash); + + pipe.hvals(bfoo); + + assertPipelineSyncAll( + Arrays.asList( + //2L, Arrays.asList("bar", "car"), + //2L, Arrays.asList(bbar, bcar)), + 1L, Arrays.asList("car"), + 1L, Arrays.asList(bcar)), + pipe.syncAndReturnAll()); + } + + @Test + public void hgetAll() { + Map hash = new HashMap<>(); + hash.put("bar", "car"); + //hash.put("car", "bar"); + pipe.hset("foo", hash); + + pipe.hgetAll("foo"); + + // Binary + Map bhash = new HashMap<>(); + bhash.put(bbar, bcar); + //bhash.put(bcar, bbar); + pipe.hset(bfoo, bhash); + + pipe.hgetAll(bfoo); + +// assertPipelineSyncAll( +// Arrays.asList( +// 1L, hash, +// 1L, bhash), +// pipe.syncAndReturnAll()); + pipe.syncAndReturnAll(); + } + + @Test + public void hstrlen() { + pipe.hstrlen("foo", "key"); + pipe.hset("foo", "key", "value"); + pipe.hstrlen("foo", "key"); + + pipe.hstrlen(bfoo, bbar); + pipe.hset(bfoo, bbar, bcar); + pipe.hstrlen(bfoo, bbar); + + assertPipelineSyncAll( + Arrays.asList(0L, 1L, 5L, 0L, 1L, 4L), + pipe.syncAndReturnAll()); + } +} 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 new file mode 100644 index 00000000000..c162954509c --- /dev/null +++ b/src/test/java/redis/clients/jedis/commands/unified/pipeline/PipelineCommandsTestBase.java @@ -0,0 +1,28 @@ +package redis.clients.jedis.commands.unified.pipeline; + +import org.junit.After; +import org.junit.Before; + +import redis.clients.jedis.JedisPooled; +import redis.clients.jedis.Pipeline; +import redis.clients.jedis.commands.unified.pooled.PooledCommandsTestHelper; + +public abstract class PipelineCommandsTestBase { + + protected static JedisPooled jedis; + protected Pipeline pipe; + + public PipelineCommandsTestBase() { + } + + @Before + public void setUp() { + PooledCommandsTestHelper.clearData(); + pipe = jedis.pipelined(); + } + + @After + public void tearDown() { + pipe.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 42a1e20b79c..82ecc600c83 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 @@ -13,18 +13,18 @@ public class PooledCommandsTestHelper { private static Jedis node; - static JedisPooled getPooled() throws InterruptedException { + public static JedisPooled getPooled() throws InterruptedException { node = new Jedis(nodeInfo); node.auth("foobared"); - node.flushAll(); + //node.flushAll(); //return new JedisPooled(nodeInfo.getHost(), nodeInfo.getPort(), null, "foobared"); return new JedisPooled(nodeInfo, DefaultJedisClientConfig.builder() .protocol(RedisProtocolUtil.getRedisProtocol()).password("foobared").build()); } - static void clearData() { - node.flushDB(); + public static void clearData() { + node.flushAll(); } } diff --git a/src/test/java/redis/clients/jedis/util/AssertUtil.java b/src/test/java/redis/clients/jedis/util/AssertUtil.java index 5d2ca5518d9..110be7e48e7 100644 --- a/src/test/java/redis/clients/jedis/util/AssertUtil.java +++ b/src/test/java/redis/clients/jedis/util/AssertUtil.java @@ -7,6 +7,7 @@ import java.util.Collection; import java.util.Iterator; import java.util.List; +import java.util.Map; import java.util.Objects; import java.util.Set; @@ -105,4 +106,47 @@ public static void assertByteArrayCollectionContainsAll(Collection all, } } + public static void assertPipelineSyncAll(List expected, List actual) { + assertEquals(expected.size(), actual.size()); + for (int n = 0; n < expected.size(); n++) { + Object expObj = expected.get(n); + Object actObj = actual.get(n); + if (expObj instanceof List) { + if (!(actObj instanceof List)) { + throw new ComparisonFailure(n + "'th element is not a list", + expObj.getClass().toString(), actObj.getClass().toString()); + } + assertPipelineSyncAll((List) expObj, (List) actObj); + } else if (expObj instanceof List) { + if (!(actObj instanceof List)) { + throw new ComparisonFailure(n + "'th element is not a list", + expObj.getClass().toString(), actObj.getClass().toString()); + } + assertPipelineSyncAll((List) expObj, (List) actObj); + } else if (expObj instanceof Set) { + if (!(actObj instanceof Set)) { + throw new ComparisonFailure(n + "'th element is not a set", + expObj.getClass().toString(), actObj.getClass().toString()); + } + assertPipelineSyncAllSet((Set) expObj, (Set) actObj); + } else if (expObj instanceof byte[]) { + if (!(actObj instanceof byte[])) { + throw new ComparisonFailure(n + "'th element is not byte array", + expObj.getClass().toString(), actObj.getClass().toString()); + } + assertArrayEquals((byte[]) expObj, (byte[]) actObj); + } else { + assertEquals(n + "'th element mismatched", expObj, actObj); + } + } + } + + private static void assertPipelineSyncAllSet(Set expected, Set actual) { + assertEquals(expected.size(), actual.size()); + if (expected.iterator().next() instanceof byte[]) { + assertByteArraySetEquals((Set) expected, (Set) actual); + } else { + assertEquals(expected, actual); + } + } } From a2386fe68974f62acfa45b1f4d43ddd54b31f4e8 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sun, 10 Mar 2024 20:21:36 +0600 Subject: [PATCH 07/33] Bump org.json:json from 20240205 to 20240303 (#3752) Bumps [org.json:json](https://github.com/douglascrockford/JSON-java) from 20240205 to 20240303. - [Release notes](https://github.com/douglascrockford/JSON-java/releases) - [Changelog](https://github.com/stleary/JSON-java/blob/master/docs/RELEASES.md) - [Commits](https://github.com/douglascrockford/JSON-java/commits) --- updated-dependencies: - dependency-name: org.json:json dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index a90614bd36a..a438a775a1f 100644 --- a/pom.xml +++ b/pom.xml @@ -67,7 +67,7 @@ org.json json - 20240205 + 20240303 com.google.code.gson From f692aa50cec176ff97f5ffa33c46c4ada630a520 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 11 Mar 2024 09:04:53 +0600 Subject: [PATCH 08/33] Bump jackson.version from 2.16.1 to 2.16.2 (#3762) Bumps `jackson.version` from 2.16.1 to 2.16.2. Updates `com.fasterxml.jackson.core:jackson-databind` from 2.16.1 to 2.16.2 - [Commits](https://github.com/FasterXML/jackson/commits) Updates `com.fasterxml.jackson.datatype:jackson-datatype-jsr310` from 2.16.1 to 2.16.2 --- updated-dependencies: - dependency-name: com.fasterxml.jackson.core:jackson-databind dependency-type: direct:development update-type: version-update:semver-patch - dependency-name: com.fasterxml.jackson.datatype:jackson-datatype-jsr310 dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index a438a775a1f..5007f12e311 100644 --- a/pom.xml +++ b/pom.xml @@ -49,7 +49,7 @@ redis.clients.jedis 1.7.36 1.7.1 - 2.16.1 + 2.16.2 3.2.5 From 23943800fbc47bcadbc6d7f17c4b32d442a637fb Mon Sep 17 00:00:00 2001 From: Cem Asma Date: Mon, 11 Mar 2024 16:25:28 +0300 Subject: [PATCH 09/33] Add support for redis command: CLIENT TRACKINGINFO (#3751) Co-authored-by: Cem Asma --- src/main/java/redis/clients/jedis/Jedis.java | 7 ++ .../jedis/commands/ClientCommands.java | 3 + .../clients/jedis/resps/TrackingInfo.java | 70 +++++++++++++++++++ .../commands/jedis/ClientCommandsTest.java | 23 ++++++ 4 files changed, 103 insertions(+) create mode 100644 src/main/java/redis/clients/jedis/resps/TrackingInfo.java diff --git a/src/main/java/redis/clients/jedis/Jedis.java b/src/main/java/redis/clients/jedis/Jedis.java index 1e25f2ffcb0..4e91ed1ca26 100644 --- a/src/main/java/redis/clients/jedis/Jedis.java +++ b/src/main/java/redis/clients/jedis/Jedis.java @@ -4325,6 +4325,13 @@ public String clientNoTouchOff() { return connection.getStatusCodeReply(); } + @Override + public TrackingInfo clientTrackingInfo() { + checkIsInMultiOrPipeline(); + connection.sendCommand(CLIENT, "TRACKINGINFO"); + return TrackingInfo.TRACKING_INFO_BUILDER.build(connection.getOne()); + } + public List time() { checkIsInMultiOrPipeline(); connection.sendCommand(Command.TIME); diff --git a/src/main/java/redis/clients/jedis/commands/ClientCommands.java b/src/main/java/redis/clients/jedis/commands/ClientCommands.java index 75bda24a30c..912b1b9d08d 100644 --- a/src/main/java/redis/clients/jedis/commands/ClientCommands.java +++ b/src/main/java/redis/clients/jedis/commands/ClientCommands.java @@ -5,6 +5,7 @@ import redis.clients.jedis.args.ClientType; import redis.clients.jedis.args.UnblockType; import redis.clients.jedis.params.ClientKillParams; +import redis.clients.jedis.resps.TrackingInfo; /** * The interface contain all the commands about client. @@ -170,4 +171,6 @@ public interface ClientCommands { * @return OK */ String clientNoTouchOff(); + + TrackingInfo clientTrackingInfo(); } diff --git a/src/main/java/redis/clients/jedis/resps/TrackingInfo.java b/src/main/java/redis/clients/jedis/resps/TrackingInfo.java new file mode 100644 index 00000000000..d87276a2b5e --- /dev/null +++ b/src/main/java/redis/clients/jedis/resps/TrackingInfo.java @@ -0,0 +1,70 @@ +package redis.clients.jedis.resps; + +import redis.clients.jedis.Builder; +import redis.clients.jedis.util.KeyValue; + +import java.util.Collections; +import java.util.List; + +import static redis.clients.jedis.BuilderFactory.*; + +public class TrackingInfo { + + private final List flags; + private final long redirect; + private final List prefixes; + + public TrackingInfo(List flags, long redirect, List prefixes) { + this.flags = flags; + this.redirect = redirect; + this.prefixes = prefixes; + } + + + public List getFlags() { + return flags; + } + + public long getRedirect() { + return redirect; + } + + public List getPrefixes() { + return prefixes; + } + + public static final Builder TRACKING_INFO_BUILDER = new Builder() { + @Override + public TrackingInfo build(Object data) { + List commandData = (List) data; + + if (commandData.get(0) instanceof KeyValue) { + List flags = Collections.emptyList(); + long redirect = -1; + List prefixes = Collections.emptyList(); + + for (KeyValue kv : (List) commandData) { + switch (STRING.build(kv.getKey())) { + case "flags": + flags = STRING_LIST.build(kv.getValue()); + break; + case "redirect": + redirect = LONG.build(kv.getValue()); + break; + case "prefixes": + prefixes = STRING_LIST.build(kv.getValue()); + break; + } + } + + return new TrackingInfo(flags, redirect, prefixes); + } else { + List flags = STRING_LIST.build(commandData.get(1)); + long redirect = LONG.build(commandData.get(3)); + List prefixes = STRING_LIST.build(commandData.get(5)); + + return new TrackingInfo(flags, redirect, prefixes); + } + } + }; +} 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 cf7760dbf4b..40aff1045cb 100644 --- a/src/test/java/redis/clients/jedis/commands/jedis/ClientCommandsTest.java +++ b/src/test/java/redis/clients/jedis/commands/jedis/ClientCommandsTest.java @@ -19,12 +19,15 @@ import org.junit.Before; import org.junit.Test; +import redis.clients.jedis.DefaultJedisClientConfig; import redis.clients.jedis.Jedis; +import redis.clients.jedis.RedisProtocol; import redis.clients.jedis.args.ClientAttributeOption; import redis.clients.jedis.args.ClientType; import redis.clients.jedis.args.UnblockType; import redis.clients.jedis.exceptions.JedisConnectionException; import redis.clients.jedis.params.ClientKillParams; +import redis.clients.jedis.resps.TrackingInfo; public class ClientCommandsTest extends JedisCommandsTestBase { @@ -279,6 +282,26 @@ public void listWithType() { assertEquals(1, client.clientList(ClientType.PUBSUB).split("\\n").length); } + @Test + public void trackingInfo() { + TrackingInfo trackingInfo = client.clientTrackingInfo(); + + assertEquals(1, trackingInfo.getFlags().size()); + assertEquals(-1, trackingInfo.getRedirect()); + assertEquals(0, trackingInfo.getPrefixes().size()); + } + + @Test + public void trackingInfoResp3() { + Jedis clientResp3 = new Jedis(hnp, DefaultJedisClientConfig.builder() + .protocol(RedisProtocol.RESP3).password("foobared").build()); + TrackingInfo trackingInfo = clientResp3.clientTrackingInfo(); + + assertEquals(1, trackingInfo.getFlags().size()); + assertEquals(-1, trackingInfo.getRedirect()); + assertEquals(0, trackingInfo.getPrefixes().size()); + } + private void assertDisconnected(Jedis j) { try { j.ping(); From 7515d5a35c9f595dd124d56c7e40806cf86cf430 Mon Sep 17 00:00:00 2001 From: Gabriel Erzse Date: Mon, 11 Mar 2024 16:51:27 +0200 Subject: [PATCH 10/33] Add tests for Stream pipelined commands (#3763) * Add tests for Stream pipelined commands Also adapt some migration pipelined tests, to assert the exact content of collections, not just subsets. * Simplify one test case --------- Co-authored-by: Gabriel Erzse --- .../clients/jedis/MigratePipeliningTest.java | 40 +- .../pipeline/StreamsPipelineCommandsTest.java | 1314 +++++++++++++++++ 2 files changed, 1334 insertions(+), 20 deletions(-) create mode 100644 src/test/java/redis/clients/jedis/commands/unified/pipeline/StreamsPipelineCommandsTest.java diff --git a/src/test/java/redis/clients/jedis/MigratePipeliningTest.java b/src/test/java/redis/clients/jedis/MigratePipeliningTest.java index b7942fc140d..ebd4b31eb96 100644 --- a/src/test/java/redis/clients/jedis/MigratePipeliningTest.java +++ b/src/test/java/redis/clients/jedis/MigratePipeliningTest.java @@ -2,9 +2,9 @@ import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.both; +import static org.hamcrest.Matchers.contains; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.hasItems; import static org.hamcrest.Matchers.hasToString; import static org.hamcrest.Matchers.instanceOf; import static org.junit.Assert.assertArrayEquals; @@ -72,7 +72,7 @@ public void noKey() { p.migrate(host, port, db, timeout, new MigrateParams(), bfoo1, bfoo2, bfoo3); assertThat(p.syncAndReturnAll(), - hasItems("NOKEY", "NOKEY", "NOKEY", "NOKEY")); + contains("NOKEY", "NOKEY", "NOKEY", "NOKEY")); } @Test @@ -86,7 +86,7 @@ public void migrate() { p.get("foo"); assertThat(p.syncAndReturnAll(), - hasItems("OK", "OK", null)); + contains("OK", "OK", null)); assertEquals("bar", dest.get("foo")); } @@ -102,7 +102,7 @@ public void migrateBinary() { p.get(bfoo); assertThat(p.syncAndReturnAll(), - hasItems("OK", "OK", null)); + contains("OK", "OK", null)); assertArrayEquals(bbar, dest.get(bfoo)); } @@ -118,7 +118,7 @@ public void migrateEmptyParams() { p.get("foo"); assertThat(p.syncAndReturnAll(), - hasItems("OK", "OK", null)); + contains("OK", "OK", null)); assertEquals("bar", dest.get("foo")); } @@ -134,7 +134,7 @@ public void migrateEmptyParamsBinary() { p.get(bfoo); assertThat(p.syncAndReturnAll(), - hasItems("OK", "OK", null)); + contains("OK", "OK", null)); assertArrayEquals(bbar, dest.get(bfoo)); } @@ -150,7 +150,7 @@ public void migrateCopy() { p.get("foo"); assertThat(p.syncAndReturnAll(), - hasItems("OK", "OK", "bar")); + contains("OK", "OK", "bar")); assertEquals("bar", dest.get("foo")); } @@ -166,7 +166,7 @@ public void migrateCopyBinary() { p.get(bfoo); assertThat(p.syncAndReturnAll(), - hasItems("OK", "OK", bbar)); + contains("OK", "OK", bbar)); assertArrayEquals(bbar, dest.get(bfoo)); } @@ -184,7 +184,7 @@ public void migrateReplace() { p.get("foo"); assertThat(p.syncAndReturnAll(), - hasItems("OK", "OK", null)); + contains("OK", "OK", null)); assertEquals("bar1", dest.get("foo")); } @@ -202,7 +202,7 @@ public void migrateReplaceBinary() { p.get(bfoo); assertThat(p.syncAndReturnAll(), - hasItems("OK", "OK", null)); + contains("OK", "OK", null)); assertArrayEquals(bbar1, dest.get(bfoo)); } @@ -220,7 +220,7 @@ public void migrateCopyReplace() { p.get("foo"); assertThat(p.syncAndReturnAll(), - hasItems("OK", "OK", "bar1")); + contains("OK", "OK", "bar1")); assertEquals("bar1", dest.get("foo")); } @@ -238,7 +238,7 @@ public void migrateCopyReplaceBinary() { p.get(bfoo); assertThat(p.syncAndReturnAll(), - hasItems("OK", "OK", bbar1)); + contains("OK", "OK", bbar1)); assertArrayEquals(bbar1, dest.get(bfoo)); } @@ -254,7 +254,7 @@ public void migrateAuth() { p.get("foo"); assertThat(p.syncAndReturnAll(), - hasItems("OK", "OK", null)); + contains("OK", "OK", null)); assertEquals("bar", destAuth.get("foo")); } @@ -270,7 +270,7 @@ public void migrateAuthBinary() { p.get(bfoo); assertThat(p.syncAndReturnAll(), - hasItems("OK", "OK", null)); + contains("OK", "OK", null)); assertArrayEquals(bbar, destAuth.get(bfoo)); } @@ -287,7 +287,7 @@ public void migrateAuth2() { p.get("foo"); assertThat(p.syncAndReturnAll(), - hasItems("OK", "OK", null)); + contains("OK", "OK", null)); assertEquals("bar", jedis.get("foo")); } @@ -304,7 +304,7 @@ public void migrateAuth2Binary() { p.get(bfoo); assertThat(p.syncAndReturnAll(), - hasItems("OK", "OK", null)); + contains("OK", "OK", null)); assertArrayEquals(bbar, jedis.get(bfoo)); } @@ -321,7 +321,7 @@ public void migrateMulti() { p.migrate(host, port, db, timeout, new MigrateParams(), "foo1", "foo2", "foo3"); assertThat(p.syncAndReturnAll(), - hasItems("OK", "OK")); + contains("OK", "OK")); assertEquals("bar1", dest.get("foo1")); assertEquals("bar2", dest.get("foo2")); @@ -340,7 +340,7 @@ public void migrateMultiBinary() { p.migrate(host, port, db, timeout, new MigrateParams(), bfoo1, bfoo2, bfoo3); assertThat(p.syncAndReturnAll(), - hasItems("OK", "OK")); + contains("OK", "OK")); assertArrayEquals(bbar1, dest.get(bfoo1)); assertArrayEquals(bbar2, dest.get(bfoo2)); @@ -361,7 +361,7 @@ public void migrateConflict() { p.migrate(host, port, db, timeout, new MigrateParams(), "foo1", "foo2", "foo3"); assertThat(p.syncAndReturnAll(), - hasItems( + contains( equalTo("OK"), both(instanceOf(JedisDataException.class)).and(hasToString(containsString("BUSYKEY"))) )); @@ -385,7 +385,7 @@ public void migrateConflictBinary() { p.migrate(host, port, db, timeout, new MigrateParams(), bfoo1, bfoo2, bfoo3); assertThat(p.syncAndReturnAll(), - hasItems( + contains( equalTo("OK"), both(instanceOf(JedisDataException.class)).and(hasToString(containsString("BUSYKEY"))) )); 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 new file mode 100644 index 00000000000..066ca98fb06 --- /dev/null +++ b/src/test/java/redis/clients/jedis/commands/unified/pipeline/StreamsPipelineCommandsTest.java @@ -0,0 +1,1314 @@ +package redis.clients.jedis.commands.unified.pipeline; + +import static java.util.Collections.singletonMap; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.both; +import static org.hamcrest.Matchers.contains; +import static org.hamcrest.Matchers.containsString; +import static org.hamcrest.Matchers.empty; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.greaterThan; +import static org.hamcrest.Matchers.hasSize; +import static org.hamcrest.Matchers.hasToString; +import static org.hamcrest.Matchers.instanceOf; +import static org.hamcrest.Matchers.notNullValue; +import static org.hamcrest.Matchers.nullValue; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import java.time.Duration; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.concurrent.atomic.AtomicReference; +import java.util.stream.Collectors; + +import org.hamcrest.Matchers; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; +import redis.clients.jedis.BuilderFactory; +import redis.clients.jedis.Pipeline; +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; +import redis.clients.jedis.params.XClaimParams; +import redis.clients.jedis.params.XPendingParams; +import redis.clients.jedis.params.XReadGroupParams; +import redis.clients.jedis.params.XReadParams; +import redis.clients.jedis.params.XTrimParams; +import redis.clients.jedis.resps.StreamConsumerFullInfo; +import redis.clients.jedis.resps.StreamConsumerInfo; +import redis.clients.jedis.resps.StreamConsumersInfo; +import redis.clients.jedis.resps.StreamEntry; +import redis.clients.jedis.resps.StreamFullInfo; +import redis.clients.jedis.resps.StreamGroupFullInfo; +import redis.clients.jedis.resps.StreamGroupInfo; +import redis.clients.jedis.resps.StreamInfo; +import redis.clients.jedis.resps.StreamPendingEntry; +import redis.clients.jedis.util.SafeEncoder; + +public class StreamsPipelineCommandsTest extends PipelineCommandsTestBase { + + @BeforeClass + public static void prepare() throws InterruptedException { + jedis = PooledCommandsTestHelper.getPooled(); + } + + @AfterClass + public static void cleanUp() { + jedis.close(); + } + + @Test + public void xaddWrongNumberOfArguments() { + Map map1 = new HashMap<>(); + pipe.xadd("stream1", (StreamEntryID) null, map1); + + assertThat(pipe.syncAndReturnAll(), + contains( + both(instanceOf(JedisDataException.class)).and(hasToString(containsString("wrong number of arguments"))) + )); + } + + @Test + public void xadd() { + Map map1 = new HashMap<>(); + map1.put("f1", "v1"); + pipe.xadd("xadd-stream1", (StreamEntryID) null, map1); + + Map map2 = new HashMap<>(); + map2.put("f1", "v1"); + map2.put("f2", "v2"); + pipe.xadd("xadd-stream1", (StreamEntryID) null, map2); + + List results = pipe.syncAndReturnAll(); + + assertThat(results, contains( + instanceOf(StreamEntryID.class), + instanceOf(StreamEntryID.class) + )); + + assertThat((StreamEntryID) results.get(1), + greaterThan((StreamEntryID) results.get(0))); + } + + @Test + public void xaddMaxLen() { + Map map4 = new HashMap<>(); + map4.put("f2", "v2"); + map4.put("f3", "v3"); + StreamEntryID idIn = new StreamEntryID(1000, 1L); + pipe.xadd("xadd-stream2", idIn, map4); + + Map map5 = new HashMap<>(); + map5.put("f4", "v4"); + map5.put("f5", "v5"); + pipe.xadd("xadd-stream2", (StreamEntryID) null, map5); + + pipe.xlen("xadd-stream2"); + + Map map6 = new HashMap<>(); + map6.put("f4", "v4"); + map6.put("f5", "v5"); + pipe.xadd("xadd-stream2", map6, XAddParams.xAddParams().maxLen(2)); + + pipe.xlen("xadd-stream2"); + + List results = pipe.syncAndReturnAll(); + + assertThat(results, contains( + equalTo(idIn), + instanceOf(StreamEntryID.class), + equalTo(2L), + instanceOf(StreamEntryID.class), + equalTo(2L) + )); + + assertThat((StreamEntryID) results.get(1), + greaterThan((StreamEntryID) results.get(0))); + + assertThat((StreamEntryID) results.get(3), + greaterThan((StreamEntryID) results.get(1))); + } + + @Test + public void xaddWithParamsWrongNumberOfArguments() { + pipe.xadd("stream1", new HashMap<>(), XAddParams.xAddParams()); + pipe.xadd("stream1", XAddParams.xAddParams(), new HashMap<>()); + + assertThat(pipe.syncAndReturnAll(), + contains( + both(instanceOf(JedisDataException.class)).and(hasToString(containsString("wrong number of arguments"))), + both(instanceOf(JedisDataException.class)).and(hasToString(containsString("wrong number of arguments"))) + )); + } + + @Test + public void xaddWithParams() { + pipe.xadd("xadd-stream1", (StreamEntryID) null, singletonMap("f1", "v1")); + + Map map2 = new HashMap<>(); + map2.put("f1", "v1"); + map2.put("f2", "v2"); + pipe.xadd("xadd-stream1", map2, XAddParams.xAddParams()); + + List results = pipe.syncAndReturnAll(); + + assertThat(results, contains( + instanceOf(StreamEntryID.class), + instanceOf(StreamEntryID.class) + )); + + assertThat((StreamEntryID) results.get(1), + greaterThan((StreamEntryID) results.get(0))); + } + + @Test + public void xaddWithParamsTrim() { + Map map3 = new HashMap<>(); + map3.put("f2", "v2"); + map3.put("f3", "v3"); + StreamEntryID idIn = new StreamEntryID(1000, 1L); + pipe.xadd("xadd-stream2", XAddParams.xAddParams().id(idIn), map3); + + Map map4 = new HashMap<>(); + map4.put("f2", "v2"); + map4.put("f3", "v3"); + StreamEntryID idIn2 = new StreamEntryID(2000, 1L); + pipe.xadd("xadd-stream2", map4, XAddParams.xAddParams().id(idIn2)); + + Map map5 = new HashMap<>(); + map5.put("f4", "v4"); + map5.put("f5", "v5"); + pipe.xadd("xadd-stream2", XAddParams.xAddParams(), map5); + + pipe.xlen("xadd-stream2"); + + Map map6 = new HashMap<>(); + map6.put("f4", "v4"); + map6.put("f5", "v5"); + pipe.xadd("xadd-stream2", map6, XAddParams.xAddParams().maxLen(3).exactTrimming()); + + pipe.xlen("xadd-stream2"); + + List results = pipe.syncAndReturnAll(); + + assertThat(results, contains( + equalTo(idIn), + equalTo(idIn2), + instanceOf(StreamEntryID.class), + equalTo(3L), + instanceOf(StreamEntryID.class), + equalTo(3L) + )); + + assertThat((StreamEntryID) results.get(2), + greaterThan((StreamEntryID) results.get(1))); + + assertThat((StreamEntryID) results.get(4), + greaterThan((StreamEntryID) results.get(2))); + } + + @Test + public void xaddWithParamsNoMkStream() { + pipe.xadd("xadd-stream3", XAddParams.xAddParams().noMkStream().maxLen(3).exactTrimming(), singletonMap("f1", "v1")); + + assertThat(pipe.syncAndReturnAll(), + contains( + nullValue() + )); + + assertFalse(jedis.exists("xadd-stream3")); + } + + @Test + public void xaddWithParamsMinId() { + Map map6 = new HashMap<>(); + map6.put("f4", "v4"); + map6.put("f5", "v5"); + + StreamEntryID id = new StreamEntryID(2); + pipe.xadd("xadd-stream3", map6, XAddParams.xAddParams().minId("2").id(id)); + + pipe.xlen("xadd-stream3"); + + StreamEntryID id1 = new StreamEntryID(3); + pipe.xadd("xadd-stream3", XAddParams.xAddParams().minId("4").id(id1), map6); + + pipe.xlen("xadd-stream3"); + + List results = pipe.syncAndReturnAll(); + + assertThat(results, contains( + equalTo(id), + equalTo(1L), + equalTo(id1), + equalTo(0L) + )); + } + + @Test + public void xaddParamsId() { + String key = "kk"; + Map map = singletonMap("ff", "vv"); + + pipe.xadd(key, XAddParams.xAddParams().id(new StreamEntryID(0, 1)), map); + pipe.xadd(key, XAddParams.xAddParams().id(2, 3), map); + pipe.xadd(key, XAddParams.xAddParams().id(4), map); + pipe.xadd(key, XAddParams.xAddParams().id("5-6"), map); + pipe.xadd(key, XAddParams.xAddParams().id("7-8".getBytes()), map); + pipe.xadd(key, XAddParams.xAddParams(), map); + + List results = pipe.syncAndReturnAll(); + + assertThat(results, contains( + equalTo(new StreamEntryID(0, 1)), + equalTo(new StreamEntryID(2, 3)), + equalTo(new StreamEntryID(4, 0)), + equalTo(new StreamEntryID(5, 6)), + equalTo(new StreamEntryID(7, 8)), + instanceOf(StreamEntryID.class) + )); + + assertThat((StreamEntryID) results.get(5), + greaterThan((StreamEntryID) results.get(4))); + } + + @Test + public void xdel() { + Map map1 = new HashMap<>(); + map1.put("f1", "v1"); + + pipe.xadd("xdel-stream", (StreamEntryID) null, map1); + pipe.xadd("xdel-stream", (StreamEntryID) null, map1); + + List results = pipe.syncAndReturnAll(); + + assertThat(results, contains( + instanceOf(StreamEntryID.class), + instanceOf(StreamEntryID.class) + )); + + StreamEntryID id1 = (StreamEntryID) results.get(1); + + pipe.xlen("xdel-stream"); + pipe.xdel("xdel-stream", id1); + pipe.xlen("xdel-stream"); + + assertThat(pipe.syncAndReturnAll(), contains( + 2L, + 1L, + 1L + )); + } + + @Test + public void xlen() { + pipe.xlen("xlen-stream"); + + Map map = new HashMap<>(); + map.put("f1", "v1"); + pipe.xadd("xlen-stream", (StreamEntryID) null, map); + + pipe.xlen("xlen-stream"); + + pipe.xadd("xlen-stream", (StreamEntryID) null, map); + + pipe.xlen("xlen-stream"); + + assertThat(pipe.syncAndReturnAll(), contains( + equalTo(0L), + instanceOf(StreamEntryID.class), + equalTo(1L), + instanceOf(StreamEntryID.class), + equalTo(2L) + )); + } + + @Test + public void xrange() { + Response> range = pipe.xrange("xrange-stream", null, (StreamEntryID) null, Integer.MAX_VALUE); + + Map map1 = singletonMap("f1", "v1"); + Map map2 = singletonMap("f2", "v2"); + Map map3 = singletonMap("f3", "v3"); + + Response id1Response = pipe.xadd("xrange-stream", (StreamEntryID) null, map1); + + Response id2Response = pipe.xadd("xrange-stream", (StreamEntryID) null, map2); + + pipe.sync(); + + assertThat(range.get(), empty()); + assertThat(id1Response.get(), notNullValue()); + assertThat(id2Response.get(), notNullValue()); + + StreamEntryID id1 = id1Response.get(); + StreamEntryID id2 = id2Response.get(); + + Response> range2 = pipe.xrange("xrange-stream", null, (StreamEntryID) null, 3); + Response> range3 = pipe.xrange("xrange-stream", id1, null, 2); + Response> range4 = pipe.xrange("xrange-stream", id1, id2, 2); + Response> range5 = pipe.xrange("xrange-stream", id1, id2, 1); + Response> range6 = pipe.xrange("xrange-stream", id2, null, 4); + + Response id3Response = pipe.xadd("xrange-stream", (StreamEntryID) null, map3); + + pipe.sync(); + + assertThat(range2.get().stream().map(StreamEntry::getID).collect(Collectors.toList()), contains(id1, id2)); + assertThat(range3.get().stream().map(StreamEntry::getID).collect(Collectors.toList()), contains(id1, id2)); + assertThat(range4.get().stream().map(StreamEntry::getID).collect(Collectors.toList()), contains(id1, id2)); + assertThat(range5.get().stream().map(StreamEntry::getID).collect(Collectors.toList()), contains(id1)); + assertThat(range6.get().stream().map(StreamEntry::getID).collect(Collectors.toList()), contains(id2)); + + assertThat(id3Response.get(), notNullValue()); + + StreamEntryID id3 = id3Response.get(); + + Response> range7 = pipe.xrange("xrange-stream", id3, id3, 4); + Response> range8 = pipe.xrange("xrange-stream", null, (StreamEntryID) null); + Response> range9 = pipe.xrange("xrange-stream", StreamEntryID.MINIMUM_ID, StreamEntryID.MAXIMUM_ID); + + pipe.sync(); + + assertThat(range7.get().stream().map(StreamEntry::getID).collect(Collectors.toList()), contains(id3)); + assertThat(range8.get().stream().map(StreamEntry::getID).collect(Collectors.toList()), contains(id1, id2, id3)); + assertThat(range9.get().stream().map(StreamEntry::getID).collect(Collectors.toList()), contains(id1, id2, id3)); + } + + @Test + public void xrangeExclusive() { + StreamEntryID id1 = jedis.xadd("xrange-stream", (StreamEntryID) null, singletonMap("f1", "v1")); + StreamEntryID id2 = jedis.xadd("xrange-stream", (StreamEntryID) null, singletonMap("f2", "v2")); + + Response> range1 = pipe.xrange("xrange-stream", id1.toString(), "+", 2); + Response> range2 = pipe.xrange("xrange-stream", "(" + id1, "+", 2); + + pipe.sync(); + + assertThat(range1.get().stream().map(StreamEntry::getID).collect(Collectors.toList()), contains(id1, id2)); + assertThat(range2.get().stream().map(StreamEntry::getID).collect(Collectors.toList()), contains(id2)); + } + + @Test + public void xreadWithParams() { + Map streamQuery1 = singletonMap("xread-stream1", new StreamEntryID()); + + // Before creating Stream + pipe.xread(XReadParams.xReadParams().block(1), streamQuery1); + pipe.xread(XReadParams.xReadParams(), streamQuery1); + + assertThat(pipe.syncAndReturnAll(), contains( + nullValue(), + nullValue() + )); + + Map map1 = singletonMap("f1", "v1"); + StreamEntryID id1 = jedis.xadd("xread-stream1", (StreamEntryID) null, map1); + + Map map2 = singletonMap("f2", "v2"); + StreamEntryID id2 = jedis.xadd("xread-stream2", (StreamEntryID) null, map2); + + // Read only a single Stream + Response>>> streams1 = + pipe.xread(XReadParams.xReadParams().count(1).block(1), streamQuery1); + + Response>>> streams2 = + pipe.xread(XReadParams.xReadParams().block(1), singletonMap("xread-stream1", id1)); + + Response>>> streams3 = + pipe.xread(XReadParams.xReadParams(), singletonMap("xread-stream1", id1)); + + pipe.sync(); + + assertThat(streams1.get().stream().map(Entry::getKey).collect(Collectors.toList()), + contains("xread-stream1")); + + assertThat(streams1.get().stream().map(Entry::getValue).flatMap(List::stream) + .map(StreamEntry::getID).collect(Collectors.toList()), contains(id1)); + + assertThat(streams1.get().stream().map(Entry::getValue).flatMap(List::stream) + .map(StreamEntry::getFields).collect(Collectors.toList()), contains(map1)); + + assertThat(streams2.get(), nullValue()); + + assertThat(streams3.get(), nullValue()); + + // Read from two Streams + Map streamQuery2 = new LinkedHashMap<>(); + streamQuery2.put("xread-stream1", new StreamEntryID()); + streamQuery2.put("xread-stream2", new StreamEntryID()); + + Response>>> streams4 = + pipe.xread(XReadParams.xReadParams().count(2).block(1), streamQuery2); + + pipe.sync(); + + assertThat(streams4.get().stream().map(Entry::getKey).collect(Collectors.toList()), + contains("xread-stream1", "xread-stream2")); + + assertThat(streams4.get().stream().map(Entry::getValue).flatMap(List::stream) + .map(StreamEntry::getID).collect(Collectors.toList()), contains(id1, id2)); + + assertThat(streams4.get().stream().map(Entry::getValue).flatMap(List::stream) + .map(StreamEntry::getFields).collect(Collectors.toList()), contains(map1, map2)); + } + + @Test + public void xreadBlockZero() throws InterruptedException { + final AtomicReference>>> readRef = new AtomicReference<>(); + Thread t = new Thread(new Runnable() { + @Override + public void run() { + long startTime = System.currentTimeMillis(); + Pipeline blockPipe = jedis.pipelined(); + Map streamQuery = singletonMap("block0-stream", new StreamEntryID()); + Response>>> read = + blockPipe.xread(XReadParams.xReadParams().block(0), streamQuery); + blockPipe.sync(); + long endTime = System.currentTimeMillis(); + assertTrue(endTime - startTime > 500); + assertNotNull(read); + readRef.set(read.get()); + } + }, "xread-block-0-thread"); + t.start(); + Thread.sleep(1000); + StreamEntryID addedId = jedis.xadd("block0-stream", (StreamEntryID) null, singletonMap("foo", "bar")); + t.join(); + + assertThat(readRef.get().stream().map(Entry::getKey).collect(Collectors.toList()), + contains("block0-stream")); + + assertThat(readRef.get().stream().map(Entry::getValue).flatMap(List::stream) + .map(StreamEntry::getID).collect(Collectors.toList()), contains(addedId)); + } + + @Test + public void xtrim() { + Map map1 = new HashMap(); + map1.put("f1", "v1"); + + for (int i = 1; i <= 5; i++) { + pipe.xadd("xtrim-stream", (StreamEntryID) null, map1); + } + + pipe.xlen("xtrim-stream"); + + pipe.xtrim("xtrim-stream", 3, false); + + pipe.xlen("xtrim-stream"); + + assertThat(pipe.syncAndReturnAll(), contains( + instanceOf(StreamEntryID.class), + instanceOf(StreamEntryID.class), + instanceOf(StreamEntryID.class), + instanceOf(StreamEntryID.class), + instanceOf(StreamEntryID.class), + equalTo(5L), + equalTo(2L), + equalTo(3L) + )); + } + + @Test + public void xtrimWithParams() { + Map map1 = new HashMap<>(); + map1.put("f1", "v1"); + for (int i = 1; i <= 5; i++) { + pipe.xadd("xtrim-stream", new StreamEntryID("0-" + i), map1); + } + + pipe.xlen("xtrim-stream"); + + pipe.xtrim("xtrim-stream", XTrimParams.xTrimParams().maxLen(3).exactTrimming()); + + pipe.xlen("xtrim-stream"); + + // minId + pipe.xtrim("xtrim-stream", XTrimParams.xTrimParams().minId("0-4").exactTrimming()); + + pipe.xlen("xtrim-stream"); + + assertThat(pipe.syncAndReturnAll(), contains( + instanceOf(StreamEntryID.class), + instanceOf(StreamEntryID.class), + instanceOf(StreamEntryID.class), + instanceOf(StreamEntryID.class), + instanceOf(StreamEntryID.class), + equalTo(5L), + equalTo(2L), + equalTo(3L), + equalTo(1L), + equalTo(2L) + )); + } + + @Test + public void xrevrange() { + Response> range = pipe.xrevrange("xrevrange-stream", null, (StreamEntryID) null, Integer.MAX_VALUE); + + Map map1 = singletonMap("f1", "v1"); + Response id1Response = pipe.xadd("xrevrange-stream", (StreamEntryID) null, map1); + Map map2 = singletonMap("f2", "v2"); + Response id2Response = pipe.xadd("xrevrange-stream", (StreamEntryID) null, map2); + + pipe.sync(); + + assertThat(range.get(), empty()); + assertThat(id1Response.get(), notNullValue()); + assertThat(id2Response.get(), notNullValue()); + + StreamEntryID id1 = id1Response.get(); + StreamEntryID id2 = id2Response.get(); + + Response> range2 = pipe.xrevrange("xrevrange-stream", null, (StreamEntryID) null, 3); + Response> range3 = pipe.xrevrange("xrevrange-stream", null, id1, 2); + Response> range4 = pipe.xrevrange("xrevrange-stream", id2, id1, 2); + Response> range5 = pipe.xrevrange("xrevrange-stream", id2, id1, 1); + Response> range6 = pipe.xrevrange("xrevrange-stream", null, id2, 4); + + Map map3 = singletonMap("f3", "v3"); + Response id3Response = pipe.xadd("xrevrange-stream", (StreamEntryID) null, map3); + + pipe.sync(); + + assertThat(range2.get().stream().map(StreamEntry::getID).collect(Collectors.toList()), contains(id2, id1)); + assertThat(range3.get().stream().map(StreamEntry::getID).collect(Collectors.toList()), contains(id2, id1)); + assertThat(range4.get().stream().map(StreamEntry::getID).collect(Collectors.toList()), contains(id2, id1)); + assertThat(range5.get().stream().map(StreamEntry::getID).collect(Collectors.toList()), contains(id2)); + assertThat(range6.get().stream().map(StreamEntry::getID).collect(Collectors.toList()), contains(id2)); + + assertThat(id3Response.get(), notNullValue()); + + StreamEntryID id3 = id3Response.get(); + + Response> range7 = pipe.xrevrange("xrevrange-stream", id3, id3, 4); + Response> range8 = pipe.xrevrange("xrevrange-stream", null, (StreamEntryID) null); + Response> range9 = pipe.xrevrange("xrevrange-stream", StreamEntryID.MAXIMUM_ID, StreamEntryID.MINIMUM_ID); + + pipe.sync(); + + assertThat(range7.get().stream().map(StreamEntry::getID).collect(Collectors.toList()), contains(id3)); + assertThat(range8.get().stream().map(StreamEntry::getID).collect(Collectors.toList()), contains(id3, id2, id1)); + assertThat(range9.get().stream().map(StreamEntry::getID).collect(Collectors.toList()), contains(id3, id2, id1)); + } + + @Test + public void xrevrangeExclusive() { + StreamEntryID id1 = jedis.xadd("xrange-stream", (StreamEntryID) null, singletonMap("f1", "v1")); + StreamEntryID id2 = jedis.xadd("xrange-stream", (StreamEntryID) null, singletonMap("f2", "v2")); + + Response> range1 = pipe.xrevrange("xrange-stream", "+", id1.toString(), 2); + Response> range2 = pipe.xrevrange("xrange-stream", "+", "(" + id1, 2); + + pipe.sync(); + + assertThat(range1.get().stream().map(StreamEntry::getID).collect(Collectors.toList()), contains(id2, id1)); + assertThat(range2.get().stream().map(StreamEntry::getID).collect(Collectors.toList()), contains(id2)); + } + + @Test + public void xgroup() { + StreamEntryID id1 = jedis.xadd("xgroup-stream", (StreamEntryID) null, singletonMap("f1", "v1")); + + pipe.xgroupCreate("xgroup-stream", "consumer-group-name", null, false); + pipe.xgroupSetID("xgroup-stream", "consumer-group-name", id1); + pipe.xgroupCreate("xgroup-stream", "consumer-group-name1", StreamEntryID.LAST_ENTRY, false); + + pipe.xgroupDestroy("xgroup-stream", "consumer-group-name"); + pipe.xgroupDelConsumer("xgroup-stream", "consumer-group-name1", "myconsumer1"); + pipe.xgroupCreateConsumer("xgroup-stream", "consumer-group-name1", "myconsumer2"); + pipe.xgroupDelConsumer("xgroup-stream", "consumer-group-name1", "myconsumer2"); + + assertThat(pipe.syncAndReturnAll(), contains( + "OK", + "OK", + "OK", + 1L, + 0L, + true, + 0L + )); + } + + @Test + public void xreadGroupWithParams() { + // Simple xreadGroup with NOACK + Map map1 = singletonMap("f1", "v1"); + StreamEntryID id1 = jedis.xadd("xreadGroup-stream1", (StreamEntryID) null, map1); + + jedis.xgroupCreate("xreadGroup-stream1", "xreadGroup-group", null, false); + + Map streamQuery1 = singletonMap("xreadGroup-stream1", StreamEntryID.UNRECEIVED_ENTRY); + + Response>>> streams1 = + pipe.xreadGroup("xreadGroup-group", "xreadGroup-consumer", + XReadGroupParams.xReadGroupParams().count(1).noAck(), streamQuery1); + + pipe.sync(); + + assertThat(streams1.get().stream().map(Entry::getKey).collect(Collectors.toList()), + contains("xreadGroup-stream1")); + + assertThat(streams1.get().stream().map(Entry::getValue).flatMap(List::stream) + .map(StreamEntry::getID).collect(Collectors.toList()), contains(id1)); + + assertThat(streams1.get().stream().map(Entry::getValue).flatMap(List::stream) + .map(StreamEntry::getFields).collect(Collectors.toList()), contains(map1)); + + Map map2 = singletonMap("f2", "v2"); + StreamEntryID id2 = jedis.xadd("xreadGroup-stream1", (StreamEntryID) null, map2); + + Map map3 = singletonMap("f3", "v3"); + StreamEntryID id3 = jedis.xadd("xreadGroup-stream2", (StreamEntryID) null, map3); + + jedis.xgroupCreate("xreadGroup-stream2", "xreadGroup-group", null, false); + + // Read only a single Stream + Response>>> streams2 = pipe.xreadGroup("xreadGroup-group", "xreadGroup-consumer", + XReadGroupParams.xReadGroupParams().count(1).block(1).noAck(), streamQuery1); + + // Read from two Streams + Map streamQuery2 = new LinkedHashMap<>(); + streamQuery2.put("xreadGroup-stream1", StreamEntryID.UNRECEIVED_ENTRY); + streamQuery2.put("xreadGroup-stream2", StreamEntryID.UNRECEIVED_ENTRY); + + Response>>> streams3 = pipe.xreadGroup("xreadGroup-group", "xreadGroup-consumer", + XReadGroupParams.xReadGroupParams().count(1).noAck(), streamQuery2); + + pipe.sync(); + + assertThat(streams2.get().stream().map(Entry::getKey).collect(Collectors.toList()), + contains("xreadGroup-stream1")); + + assertThat(streams2.get().stream().map(Entry::getValue).flatMap(List::stream) + .map(StreamEntry::getID).collect(Collectors.toList()), contains(id2)); + + assertThat(streams2.get().stream().map(Entry::getValue).flatMap(List::stream) + .map(StreamEntry::getFields).collect(Collectors.toList()), contains(map2)); + + assertThat(streams3.get().stream().map(Entry::getKey).collect(Collectors.toList()), + contains("xreadGroup-stream2")); + + assertThat(streams3.get().stream().map(Entry::getValue).flatMap(List::stream) + .map(StreamEntry::getID).collect(Collectors.toList()), contains(id3)); + + assertThat(streams3.get().stream().map(Entry::getValue).flatMap(List::stream) + .map(StreamEntry::getFields).collect(Collectors.toList()), contains(map3)); + + // Read only fresh messages + Map map4 = singletonMap("f4", "v4"); + StreamEntryID id4 = jedis.xadd("xreadGroup-stream1", (StreamEntryID) null, map4); + + Map streamQueryFresh = singletonMap("xreadGroup-stream1", StreamEntryID.UNRECEIVED_ENTRY); + Response>>> streams4 = pipe.xreadGroup("xreadGroup-group", "xreadGroup-consumer", + XReadGroupParams.xReadGroupParams().count(4).block(100).noAck(), streamQueryFresh); + + pipe.sync(); + + assertThat(streams4.get().stream().map(Entry::getKey).collect(Collectors.toList()), + contains("xreadGroup-stream1")); + + assertThat(streams4.get().stream().map(Entry::getValue).flatMap(List::stream) + .map(StreamEntry::getID).collect(Collectors.toList()), contains(id4)); + + assertThat(streams4.get().stream().map(Entry::getValue).flatMap(List::stream) + .map(StreamEntry::getFields).collect(Collectors.toList()), contains(map4)); + } + + @Test + public void xreadGroupWithParamsWhenPendingMessageIsDiscarded() { + // Add two message to stream + Map map1 = singletonMap("f1", "v1"); + + XAddParams xAddParams = XAddParams.xAddParams().id(StreamEntryID.NEW_ENTRY).maxLen(2); + StreamEntryID firstMessageEntryId = jedis.xadd("xreadGroup-discard-stream1", xAddParams, map1); + + jedis.xadd("xreadGroup-discard-stream1", xAddParams, singletonMap("f2", "v2")); + + pipe.xgroupCreate("xreadGroup-discard-stream1", "xreadGroup-group", null, false); + + Map streamQuery1 = singletonMap("xreadGroup-discard-stream1", StreamEntryID.UNRECEIVED_ENTRY); + + Response>>> streams1 = + pipe.xreadGroup("xreadGroup-group", "xreadGroup-consumer", + XReadGroupParams.xReadGroupParams().count(1), streamQuery1); + + pipe.sync(); + + assertThat(streams1.get().stream().map(Entry::getKey).collect(Collectors.toList()), + contains("xreadGroup-discard-stream1")); + + assertThat(streams1.get().stream().map(Entry::getValue).flatMap(List::stream) + .map(StreamEntry::getID).collect(Collectors.toList()), contains(firstMessageEntryId)); + + assertThat(streams1.get().stream().map(Entry::getValue).flatMap(List::stream) + .map(StreamEntry::getFields).collect(Collectors.toList()), contains(map1)); + + // Add third message, the fields of pending message1 will be discarded by redis-server + jedis.xadd("xreadGroup-discard-stream1", xAddParams, singletonMap("f3", "v3")); + + Map streamQueryPending = singletonMap("xreadGroup-discard-stream1", new StreamEntryID()); + + Response>>> pendingMessages = + pipe.xreadGroup("xreadGroup-group", "xreadGroup-consumer", + XReadGroupParams.xReadGroupParams().count(1).noAck(), streamQueryPending); + + pipe.sync(); + + assertThat(pendingMessages.get().stream().map(Entry::getKey).collect(Collectors.toList()), + contains("xreadGroup-discard-stream1")); + + assertThat(pendingMessages.get().stream().map(Entry::getValue).flatMap(List::stream) + .map(StreamEntry::getID).collect(Collectors.toList()), contains(firstMessageEntryId)); + + assertThat(pendingMessages.get().stream().map(Entry::getValue).flatMap(List::stream) + .map(StreamEntry::getFields).collect(Collectors.toList()), contains(nullValue())); + } + + @Test + public void xack() { + pipe.xadd("xack-stream", (StreamEntryID) null, singletonMap("f1", "v1")); + + pipe.xgroupCreate("xack-stream", "xack-group", null, false); + + Map streamQuery1 = singletonMap("xack-stream", StreamEntryID.UNRECEIVED_ENTRY); + + // Empty Stream + Response>>> streams1 = + pipe.xreadGroup("xack-group", "xack-consumer", + XReadGroupParams.xReadGroupParams().count(1).block(1), streamQuery1); + + pipe.sync(); + + List ids = streams1.get().stream().map(Entry::getValue).flatMap(List::stream) + .map(StreamEntry::getID).collect(Collectors.toList()); + assertThat(ids, hasSize(1)); + + Response xackResponse = pipe.xack("xack-stream", "xack-group", ids.get(0)); + + pipe.sync(); + + assertThat(xackResponse.get(), equalTo(1L)); + } + + @Test + public void xpendingWithParams() { + Map map = singletonMap("f1", "v1"); + + StreamEntryID id1 = jedis.xadd("xpending-stream", (StreamEntryID) null, map); + + assertEquals("OK", jedis.xgroupCreate("xpending-stream", "xpending-group", null, false)); + + Map streamQeury1 = singletonMap("xpending-stream", StreamEntryID.UNRECEIVED_ENTRY); + + // Read the event from Stream put it on pending + Response>>> range = pipe.xreadGroup("xpending-group", + "xpending-consumer", XReadGroupParams.xReadGroupParams().count(1).block(1), streamQeury1); + + // Get the pending event + Response> pending1 = + pipe.xpending("xpending-stream", "xpending-group", + new XPendingParams().count(3).consumer("xpending-consumer")); + + // Without consumer + Response> pending2 = + pipe.xpending("xpending-stream", "xpending-group", + new XPendingParams().count(3)); + + // with idle + Response> pending3 = + pipe.xpending("xpending-stream", "xpending-group", + new XPendingParams().idle(Duration.ofMinutes(1).toMillis()).count(3)); + + pipe.sync(); + + assertThat(pending1.get().stream().map(StreamPendingEntry::getConsumerName).collect(Collectors.toList()), + contains("xpending-consumer")); + + assertThat(pending1.get().stream().map(StreamPendingEntry::getID).collect(Collectors.toList()), + contains(id1)); + + assertThat(pending1.get().stream().map(StreamPendingEntry::getDeliveredTimes).collect(Collectors.toList()), + contains(1L)); + + assertThat(pending2.get().stream().map(StreamPendingEntry::getConsumerName).collect(Collectors.toList()), + contains("xpending-consumer")); + + assertThat(pending2.get().stream().map(StreamPendingEntry::getID).collect(Collectors.toList()), + contains(id1)); + + assertThat(pending2.get().stream().map(StreamPendingEntry::getDeliveredTimes).collect(Collectors.toList()), + contains(1L)); + + assertThat(pending3.get(), empty()); + } + + @Test + public void xpendingRange() { + StreamEntryID id1 = jedis.xadd("xpending-stream", (StreamEntryID) null, singletonMap("f1", "v1")); + StreamEntryID id2 = jedis.xadd("xpending-stream", (StreamEntryID) null, singletonMap("f2", "v2")); + + pipe.xgroupCreate("xpending-stream", "xpending-group", null, false); + + // read 1 message from the group with each consumer + Map streamQeury = singletonMap("xpending-stream", StreamEntryID.UNRECEIVED_ENTRY); + pipe.xreadGroup("xpending-group", "consumer1", XReadGroupParams.xReadGroupParams().count(1), streamQeury); + pipe.xreadGroup("xpending-group", "consumer2", XReadGroupParams.xReadGroupParams().count(1), streamQeury); + + Response> pending1 = pipe.xpending("xpending-stream", "xpending-group", + XPendingParams.xPendingParams("(0", "+", 5)); + + Response> pending2 = pipe.xpending("xpending-stream", "xpending-group", + XPendingParams.xPendingParams(StreamEntryID.MINIMUM_ID, StreamEntryID.MAXIMUM_ID, 5)); + + pipe.sync(); + + assertThat(pending1.get().stream().map(StreamPendingEntry::getConsumerName).collect(Collectors.toList()), + contains("consumer1", "consumer2")); + + assertThat(pending1.get().stream().map(StreamPendingEntry::getID).collect(Collectors.toList()), + contains(id1, id2)); + + assertThat(pending2.get().stream().map(StreamPendingEntry::getConsumerName).collect(Collectors.toList()), + contains("consumer1", "consumer2")); + + assertThat(pending2.get().stream().map(StreamPendingEntry::getID).collect(Collectors.toList()), + contains(id1, id2)); + } + + @Test + public void xclaimWithParams() throws InterruptedException { + Map map1 = singletonMap("f1", "v1"); + StreamEntryID id1 = jedis.xadd("xpending-stream", (StreamEntryID) null, map1); + + pipe.xgroupCreate("xpending-stream", "xpending-group", null, false); + + // Read the event from Stream put it on pending + pipe.xreadGroup("xpending-group", "xpending-consumer", + XReadGroupParams.xReadGroupParams().count(1).block(1), + singletonMap("xpending-stream", StreamEntryID.UNRECEIVED_ENTRY)); + + // Get the pending event + Response> pending = + pipe.xpending("xpending-stream", "xpending-group", + XPendingParams.xPendingParams().count(3).consumer("xpending-consumer")); + + // must sync before the sleep + pipe.sync(); + + // Sleep a bit so we can claim events pending for more than 50ms + Thread.sleep(100); + + Response> claimed = + pipe.xclaim("xpending-stream", "xpending-group", "xpending-consumer2", 50, + XClaimParams.xClaimParams().idle(0).retryCount(0), id1); + + pipe.sync(); + + assertThat(pending.get().stream().map(StreamPendingEntry::getConsumerName).collect(Collectors.toList()), + contains("xpending-consumer")); + + assertThat(pending.get().stream().map(StreamPendingEntry::getID).collect(Collectors.toList()), + contains(id1)); + + assertThat(claimed.get().stream().map(StreamEntry::getID).collect(Collectors.toList()), + contains(id1)); + + assertThat(claimed.get().stream().map(StreamEntry::getFields).collect(Collectors.toList()), + contains(map1)); + } + + @Test + public void xclaimJustId() throws InterruptedException { + Map map1 = singletonMap("f1", "v1"); + StreamEntryID id1 = jedis.xadd("xpending-stream", (StreamEntryID) null, map1); + + pipe.xgroupCreate("xpending-stream", "xpending-group", null, false); + + // Read the event from Stream put it on pending + pipe.xreadGroup("xpending-group", "xpending-consumer", + XReadGroupParams.xReadGroupParams().count(1).block(1), + singletonMap("xpending-stream", StreamEntryID.UNRECEIVED_ENTRY)); + + // Get the pending event + Response> pending = + pipe.xpending("xpending-stream", "xpending-group", + XPendingParams.xPendingParams().count(3).consumer("xpending-consumer")); + + // must sync before the sleep + pipe.sync(); + + // Sleep for 100ms so we can claim events pending for more than 50ms + Thread.sleep(100); + + Response> claimedIds = + pipe.xclaimJustId("xpending-stream", "xpending-group", "xpending-consumer2", 50, + XClaimParams.xClaimParams().idle(0).retryCount(0), id1); + + pipe.sync(); + + assertThat(pending.get().stream().map(StreamPendingEntry::getConsumerName).collect(Collectors.toList()), + contains("xpending-consumer")); + + assertThat(pending.get().stream().map(StreamPendingEntry::getID).collect(Collectors.toList()), + contains(id1)); + + assertThat(claimedIds.get(), contains(id1)); + } + + @Test + public void xautoclaim() throws InterruptedException { + Map map1 = singletonMap("f1", "v1"); + StreamEntryID id1 = jedis.xadd("xpending-stream", (StreamEntryID) null, map1); + + pipe.xgroupCreate("xpending-stream", "xpending-group", null, false); + + // Read the event from Stream put it on pending + pipe.xreadGroup("xpending-group", "xpending-consumer", + XReadGroupParams.xReadGroupParams().count(1).block(1), + singletonMap("xpending-stream", StreamEntryID.UNRECEIVED_ENTRY)); + + // Get the pending event + Response> pending = pipe.xpending("xpending-stream", "xpending-group", + XPendingParams.xPendingParams().count(3).consumer("xpending-consumer")); + + pipe.sync(); + + // Sleep for 100ms so we can auto claim events pending for more than 50ms + Thread.sleep(100); + + // Auto claim pending events to different consumer + Response>> autoclaimed = pipe.xautoclaim("xpending-stream", "xpending-group", + "xpending-consumer2", 50, new StreamEntryID(), new XAutoClaimParams().count(1)); + + pipe.sync(); + + assertThat(pending.get().stream().map(StreamPendingEntry::getConsumerName).collect(Collectors.toList()), + contains("xpending-consumer")); + + assertThat(pending.get().stream().map(StreamPendingEntry::getID).collect(Collectors.toList()), + contains(id1)); + + assertThat(autoclaimed.get().getValue().stream().map(StreamEntry::getID).collect(Collectors.toList()), + contains(id1)); + + assertThat(autoclaimed.get().getValue().stream().map(StreamEntry::getFields).collect(Collectors.toList()), + contains(map1)); + } + + @Test + public void xautoclaimBinary() throws InterruptedException { + Map map1 = singletonMap("f1", "v1"); + StreamEntryID id1 = jedis.xadd("xpending-stream", XAddParams.xAddParams(), map1); + + pipe.xgroupCreate("xpending-stream", "xpending-group", null, false); + + // Read the event from Stream put it on pending + pipe.xreadGroup("xpending-group", "xpending-consumer", + XReadGroupParams.xReadGroupParams().count(1).block(1), + singletonMap("xpending-stream", StreamEntryID.UNRECEIVED_ENTRY)); + + // Get the pending event + Response> pending = pipe.xpending("xpending-stream", "xpending-group", + XPendingParams.xPendingParams().count(3).consumer("xpending-consumer")); + + pipe.sync(); + + // Sleep for 100ms so we can auto claim events pending for more than 50ms + Thread.sleep(100); + + // Auto claim pending events to different consumer + Response> autoclaimed = pipe.xautoclaim(SafeEncoder.encode("xpending-stream"), + SafeEncoder.encode("xpending-group"), SafeEncoder.encode("xpending-consumer2"), + 50, SafeEncoder.encode(new StreamEntryID().toString()), new XAutoClaimParams().count(1)); + + pipe.sync(); + + assertThat(pending.get().stream().map(StreamPendingEntry::getConsumerName).collect(Collectors.toList()), + contains("xpending-consumer")); + + assertThat(pending.get().stream().map(StreamPendingEntry::getID).collect(Collectors.toList()), + contains(id1)); + + Map.Entry> autoclaimedParsed = + BuilderFactory.STREAM_AUTO_CLAIM_RESPONSE.build(autoclaimed.get()); + + assertThat(autoclaimedParsed.getValue().stream().map(StreamEntry::getID).collect(Collectors.toList()), + contains(id1)); + + assertThat(autoclaimedParsed.getValue().stream().map(StreamEntry::getFields).collect(Collectors.toList()), + contains(map1)); + } + + @Test + public void xautoclaimJustId() throws InterruptedException { + Map map1 = singletonMap("f1", "v1"); + StreamEntryID id1 = jedis.xadd("xpending-stream", XAddParams.xAddParams(), map1); + + pipe.xgroupCreate("xpending-stream", "xpending-group", null, false); + + // Read the event from Stream put it on pending + pipe.xreadGroup("xpending-group", "xpending-consumer", XReadGroupParams.xReadGroupParams().count(1).block(1), + singletonMap("xpending-stream", StreamEntryID.UNRECEIVED_ENTRY)); + + // Get the pending event + Response> pending = pipe.xpending("xpending-stream", "xpending-group", + XPendingParams.xPendingParams().count(3).consumer("xpending-consumer")); + + pipe.sync(); + + // Sleep for 100ms so we can auto claim events pending for more than 50ms + Thread.sleep(100); + + // Auto claim pending events to different consumer + Response>> claimedIds = pipe.xautoclaimJustId("xpending-stream", "xpending-group", + "xpending-consumer2", 50, new StreamEntryID(), new XAutoClaimParams().count(1)); + + pipe.sync(); + + assertThat(pending.get().stream().map(StreamPendingEntry::getConsumerName).collect(Collectors.toList()), + contains("xpending-consumer")); + + assertThat(pending.get().stream().map(StreamPendingEntry::getID).collect(Collectors.toList()), + contains(id1)); + + assertThat(claimedIds.get().getValue(), contains(id1)); + } + + @Test + public void xautoclaimJustIdBinary() throws InterruptedException { + Map map1 = singletonMap("f1", "v1"); + StreamEntryID id1 = jedis.xadd("xpending-stream", XAddParams.xAddParams(), map1); + + pipe.xgroupCreate("xpending-stream", "xpending-group", null, false); + + // Read the event from Stream put it on pending + pipe.xreadGroup("xpending-group", "xpending-consumer", + XReadGroupParams.xReadGroupParams().count(1).block(1), + singletonMap("xpending-stream", StreamEntryID.UNRECEIVED_ENTRY)); + + // Get the pending event + Response> pending = pipe.xpending("xpending-stream", "xpending-group", + XPendingParams.xPendingParams().count(3).consumer("xpending-consumer")); + + pipe.sync(); + + // Sleep for 100ms so we can auto claim events pending for more than 50ms + Thread.sleep(100); + + // Auto claim pending events to different consumer + Response> autoclaimed = pipe.xautoclaimJustId(SafeEncoder.encode("xpending-stream"), + SafeEncoder.encode("xpending-group"), SafeEncoder.encode("xpending-consumer2"), + 50, SafeEncoder.encode(new StreamEntryID().toString()), new XAutoClaimParams().count(1)); + + pipe.sync(); + + assertThat(pending.get().stream().map(StreamPendingEntry::getConsumerName).collect(Collectors.toList()), + contains("xpending-consumer")); + + assertThat(pending.get().stream().map(StreamPendingEntry::getID).collect(Collectors.toList()), + contains(id1)); + + Entry> autoclaimedParsed = + BuilderFactory.STREAM_AUTO_CLAIM_JUSTID_RESPONSE.build(autoclaimed.get()); + + assertThat(autoclaimedParsed.getValue(), contains(id1)); + } + + @Test + public void xinfo() throws InterruptedException { + final String STREAM_NAME = "xadd-stream1"; + final String F1 = "f1"; + final String V1 = "v1"; + final String V2 = "v2"; + final String G1 = "G1"; + final String G2 = "G2"; + final String MY_CONSUMER = "myConsumer"; + final String MY_CONSUMER2 = "myConsumer2"; + + Map map1 = new HashMap<>(); + map1.put(F1, V1); + StreamEntryID id1 = jedis.xadd(STREAM_NAME, (StreamEntryID) null, map1); + map1.put(F1, V2); + StreamEntryID id2 = jedis.xadd(STREAM_NAME, (StreamEntryID) null, map1); + + Response streamInfoResponse = pipe.xinfoStream(STREAM_NAME); + + pipe.xgroupCreate(STREAM_NAME, G1, StreamEntryID.LAST_ENTRY, false); + + Map streamQuery1 = singletonMap(STREAM_NAME, new StreamEntryID("0-0")); + + pipe.xreadGroup(G1, MY_CONSUMER, XReadGroupParams.xReadGroupParams().count(1), streamQuery1); + + pipe.sync(); + + Thread.sleep(1); + + Response> groupInfoResponse = pipe.xinfoGroups(STREAM_NAME); + Response> consumersInfoResponse = pipe.xinfoConsumers(STREAM_NAME, G1); + Response> consumerInfoResponse = pipe.xinfoConsumers2(STREAM_NAME, G1); + + pipe.sync(); + + // Stream info test + StreamInfo streamInfo = streamInfoResponse.get(); + + assertEquals(2L, streamInfo.getStreamInfo().get(StreamInfo.LENGTH)); + assertEquals(1L, streamInfo.getStreamInfo().get(StreamInfo.RADIX_TREE_KEYS)); + assertEquals(2L, streamInfo.getStreamInfo().get(StreamInfo.RADIX_TREE_NODES)); + assertEquals(0L, streamInfo.getStreamInfo().get(StreamInfo.GROUPS)); + assertEquals(V1, ((StreamEntry) streamInfo.getStreamInfo().get(StreamInfo.FIRST_ENTRY)).getFields().get(F1)); + assertEquals(V2, ((StreamEntry) streamInfo.getStreamInfo().get(StreamInfo.LAST_ENTRY)).getFields().get(F1)); + assertEquals(id2, streamInfo.getStreamInfo().get(StreamInfo.LAST_GENERATED_ID)); + + // Using getters + assertEquals(2, streamInfo.getLength()); + assertEquals(1, streamInfo.getRadixTreeKeys()); + assertEquals(2, streamInfo.getRadixTreeNodes()); + assertEquals(0, streamInfo.getGroups()); + assertEquals(V1, streamInfo.getFirstEntry().getFields().get(F1)); + assertEquals(V2, streamInfo.getLastEntry().getFields().get(F1)); + assertEquals(id2, streamInfo.getLastGeneratedId()); + + // Group info test + List groupInfo = groupInfoResponse.get(); + + assertEquals(1, groupInfo.size()); + assertEquals(G1, groupInfo.get(0).getGroupInfo().get(StreamGroupInfo.NAME)); + assertEquals(1L, groupInfo.get(0).getGroupInfo().get(StreamGroupInfo.CONSUMERS)); + assertEquals(0L, groupInfo.get(0).getGroupInfo().get(StreamGroupInfo.PENDING)); + assertEquals(id2, groupInfo.get(0).getGroupInfo().get(StreamGroupInfo.LAST_DELIVERED)); + + // Using getters + assertEquals(1, groupInfo.size()); + assertEquals(G1, groupInfo.get(0).getName()); + assertEquals(1, groupInfo.get(0).getConsumers()); + assertEquals(0, groupInfo.get(0).getPending()); + assertEquals(id2, groupInfo.get(0).getLastDeliveredId()); + + // Consumers info test + List consumersInfo = consumersInfoResponse.get(); + + assertEquals(MY_CONSUMER, + consumersInfo.get(0).getConsumerInfo().get(StreamConsumersInfo.NAME)); + assertEquals(0L, consumersInfo.get(0).getConsumerInfo().get(StreamConsumersInfo.PENDING)); + assertTrue((Long) consumersInfo.get(0).getConsumerInfo().get(StreamConsumersInfo.IDLE) > 0); + + // Using getters + assertEquals(MY_CONSUMER, consumersInfo.get(0).getName()); + assertEquals(0L, consumersInfo.get(0).getPending()); + assertThat(consumersInfo.get(0).getIdle(), Matchers.greaterThanOrEqualTo(0L)); + assertThat(consumersInfo.get(0).getInactive(), Matchers.any(Long.class)); + + // Consumer info test + List consumerInfo = consumerInfoResponse.get(); + + assertEquals(MY_CONSUMER, + consumerInfo.get(0).getConsumerInfo().get(StreamConsumerInfo.NAME)); + assertEquals(0L, consumerInfo.get(0).getConsumerInfo().get(StreamConsumerInfo.PENDING)); + assertTrue((Long) consumerInfo.get(0).getConsumerInfo().get(StreamConsumerInfo.IDLE) > 0); + + // Using getters + assertEquals(MY_CONSUMER, consumerInfo.get(0).getName()); + assertEquals(0L, consumerInfo.get(0).getPending()); + assertThat(consumerInfo.get(0).getIdle(), Matchers.greaterThanOrEqualTo(0L)); + assertThat(consumerInfo.get(0).getInactive(), Matchers.any(Long.class)); + + // test with more groups and consumers + pipe.xgroupCreate(STREAM_NAME, G2, StreamEntryID.LAST_ENTRY, false); + pipe.xreadGroup(G1, MY_CONSUMER2, XReadGroupParams.xReadGroupParams().count(1), streamQuery1); + pipe.xreadGroup(G2, MY_CONSUMER, XReadGroupParams.xReadGroupParams().count(1), streamQuery1); + pipe.xreadGroup(G2, MY_CONSUMER2, XReadGroupParams.xReadGroupParams().count(1), streamQuery1); + + Response> manyGroupsInfoResponse = pipe.xinfoGroups(STREAM_NAME); + Response> manyConsumersInfoResponse = pipe.xinfoConsumers(STREAM_NAME, G2); + Response> manyConsumerInfoResponse = pipe.xinfoConsumers2(STREAM_NAME, G2); + Response streamInfoFullResponse = pipe.xinfoStreamFull(STREAM_NAME); + Response streamInfoFull10Response = pipe.xinfoStreamFull(STREAM_NAME, 10); + + pipe.sync(); + + List manyGroupsInfo = manyGroupsInfoResponse.get(); + List manyConsumersInfo = manyConsumersInfoResponse.get(); + List manyConsumerInfo = manyConsumerInfoResponse.get(); + StreamFullInfo streamInfoFull = streamInfoFullResponse.get(); + StreamFullInfo streamInfoFull10 = streamInfoFull10Response.get(); + + assertEquals(2, manyGroupsInfo.size()); + assertEquals(2, manyConsumersInfo.size()); + assertEquals(2, manyConsumerInfo.size()); + + assertEquals(2, streamInfoFull.getEntries().size()); + assertEquals(2, streamInfoFull.getGroups().size()); + assertEquals(2, streamInfoFull.getLength()); + assertEquals(1, streamInfoFull.getRadixTreeKeys()); + assertEquals(2, streamInfoFull.getRadixTreeNodes()); + assertEquals(0, streamInfo.getGroups()); + assertEquals(G1, streamInfoFull.getGroups().get(0).getName()); + assertEquals(G2, streamInfoFull.getGroups().get(1).getName()); + assertEquals(V1, streamInfoFull.getEntries().get(0).getFields().get(F1)); + assertEquals(V2, streamInfoFull.getEntries().get(1).getFields().get(F1)); + assertEquals(id2, streamInfoFull.getLastGeneratedId()); + + assertEquals(G1, streamInfoFull10.getGroups().get(0).getName()); + assertEquals(G2, streamInfoFull10.getGroups().get(1).getName()); + assertEquals(V1, streamInfoFull10.getEntries().get(0).getFields().get(F1)); + assertEquals(V2, streamInfoFull10.getEntries().get(1).getFields().get(F1)); + assertEquals(id2, streamInfoFull10.getLastGeneratedId()); + + // Not existing key - redis cli return error so we expect exception + pipe.xinfoStream("random"); + + assertThat(pipe.syncAndReturnAll(), contains( + both(instanceOf(JedisDataException.class)).and(hasToString(containsString("ERR no such key"))) + )); + } + + @Test + public void xinfoStreamFullWithPending() { + Map map = singletonMap("f1", "v1"); + StreamEntryID id1 = jedis.xadd("streamfull2", (StreamEntryID) null, map); + StreamEntryID id2 = jedis.xadd("streamfull2", (StreamEntryID) null, map); + jedis.xgroupCreate("streamfull2", "xreadGroup-group", null, false); + + Map streamQeury1 = singletonMap("streamfull2", StreamEntryID.UNRECEIVED_ENTRY); + Response>>> pending = pipe.xreadGroup("xreadGroup-group", "xreadGroup-consumer", + XReadGroupParams.xReadGroupParams().count(1), streamQeury1); + + Response fullResult = pipe.xinfoStreamFull("streamfull2"); + + pipe.sync(); + + assertThat(pending.get(), hasSize(1)); + + StreamFullInfo full = fullResult.get(); + assertEquals(1, full.getGroups().size()); + StreamGroupFullInfo group = full.getGroups().get(0); + assertEquals("xreadGroup-group", group.getName()); + + assertEquals(1, group.getPending().size()); + List groupPendingEntry = group.getPending().get(0); + assertEquals(id1, groupPendingEntry.get(0)); + assertEquals("xreadGroup-consumer", groupPendingEntry.get(1)); + + assertEquals(1, group.getConsumers().size()); + StreamConsumerFullInfo consumer = group.getConsumers().get(0); + assertEquals("xreadGroup-consumer", consumer.getName()); + assertThat(consumer.getSeenTime(), Matchers.greaterThanOrEqualTo(0L)); + assertThat(consumer.getActiveTime(), Matchers.greaterThanOrEqualTo(0L)); + assertEquals(1, consumer.getPending().size()); + List consumerPendingEntry = consumer.getPending().get(0); + assertEquals(id1, consumerPendingEntry.get(0)); + } +} From 5733cd677cb918c3f4d774688d379382afa90dff Mon Sep 17 00:00:00 2001 From: M Sazzadul Hoque <7600764+sazzad16@users.noreply.github.com> Date: Tue, 12 Mar 2024 22:36:41 +0600 Subject: [PATCH 11/33] GETSET command is deprecated since Redis 6.2.0 (#3768) --- .../redis/clients/jedis/CommandObjects.java | 16 ++++++++++++---- src/main/java/redis/clients/jedis/Jedis.java | 4 ++++ .../redis/clients/jedis/PipeliningBase.java | 18 ++++++++++++++++++ .../java/redis/clients/jedis/UnifiedJedis.java | 8 ++++++++ .../jedis/commands/StringBinaryCommands.java | 4 ++++ .../clients/jedis/commands/StringCommands.java | 2 ++ .../commands/StringPipelineBinaryCommands.java | 6 ++++++ .../jedis/commands/StringPipelineCommands.java | 6 ++++++ 8 files changed, 60 insertions(+), 4 deletions(-) diff --git a/src/main/java/redis/clients/jedis/CommandObjects.java b/src/main/java/redis/clients/jedis/CommandObjects.java index 2f5e4d16a09..1de7affa6a8 100644 --- a/src/main/java/redis/clients/jedis/CommandObjects.java +++ b/src/main/java/redis/clients/jedis/CommandObjects.java @@ -447,8 +447,8 @@ public final CommandObject setGet(String key, String value) { } public final CommandObject setGet(String key, String value, SetParams params) { - return new CommandObject<>(commandArguments(Command.SET).key(key).add(value).addParams(params) - .add(Keyword.GET), BuilderFactory.STRING); + return new CommandObject<>(commandArguments(Command.SET).key(key).add(value).addParams(params).add(Keyword.GET), + BuilderFactory.STRING); } public final CommandObject getDel(String key) { @@ -468,8 +468,8 @@ public final CommandObject setGet(byte[] key, byte[] value) { } public final CommandObject setGet(byte[] key, byte[] value, SetParams params) { - return new CommandObject<>(commandArguments(Command.SET).key(key).add(value).addParams(params) - .add(Keyword.GET), BuilderFactory.BINARY); + return new CommandObject<>(commandArguments(Command.SET).key(key).add(value).addParams(params).add(Keyword.GET), + BuilderFactory.BINARY); } public final CommandObject getDel(byte[] key) { @@ -480,10 +480,18 @@ public final CommandObject getEx(byte[] key, GetExParams params) { return new CommandObject<>(commandArguments(Command.GETEX).key(key).addParams(params), BuilderFactory.BINARY); } + /** + * @deprecated Use {@link CommandObjects#setGet(java.lang.String, java.lang.String)}. + */ + @Deprecated public final CommandObject getSet(String key, String value) { return new CommandObject<>(commandArguments(Command.GETSET).key(key).add(value), BuilderFactory.STRING); } + /** + * @deprecated Use {@link CommandObjects#setGet(byte[], byte[])}. + */ + @Deprecated public final CommandObject getSet(byte[] key, byte[] value) { return new CommandObject<>(commandArguments(Command.GETSET).key(key).add(value), BuilderFactory.BINARY); } diff --git a/src/main/java/redis/clients/jedis/Jedis.java b/src/main/java/redis/clients/jedis/Jedis.java index 4e91ed1ca26..a9f6ceafe7c 100644 --- a/src/main/java/redis/clients/jedis/Jedis.java +++ b/src/main/java/redis/clients/jedis/Jedis.java @@ -871,7 +871,9 @@ public long move(final byte[] key, final int dbIndex) { * @param key * @param value * @return Bulk reply + * @deprecated Use {@link Jedis#setGet(byte[], byte[])}. */ + @Deprecated @Override public byte[] getSet(final byte[] key, final byte[] value) { checkIsInMultiOrPipeline(); @@ -5316,7 +5318,9 @@ public long move(final String key, final int dbIndex) { * @param key * @param value * @return Bulk reply + * @deprecated Use {@link Jedis#setGet(java.lang.String, java.lang.String)}. */ + @Deprecated @Override public String getSet(final String key, final String value) { checkIsInMultiOrPipeline(); diff --git a/src/main/java/redis/clients/jedis/PipeliningBase.java b/src/main/java/redis/clients/jedis/PipeliningBase.java index bf6711b6325..e9b6d49b736 100644 --- a/src/main/java/redis/clients/jedis/PipeliningBase.java +++ b/src/main/java/redis/clients/jedis/PipeliningBase.java @@ -280,6 +280,11 @@ public Response get(String key) { return appendCommand(commandObjects.get(key)); } + @Override + public Response setGet(String key, String value) { + return appendCommand(commandObjects.setGet(key, value)); + } + @Override public Response setGet(String key, String value, SetParams params) { return appendCommand(commandObjects.setGet(key, value, params)); @@ -315,6 +320,10 @@ public Response getrange(String key, long startOffset, long endOffset) { return appendCommand(commandObjects.getrange(key, startOffset, endOffset)); } + /** + * @deprecated Use {@link PipeliningBase#setGet(java.lang.String, java.lang.String)}. + */ + @Deprecated @Override public Response getSet(String key, String value) { return appendCommand(commandObjects.getSet(key, value)); @@ -3114,6 +3123,11 @@ public Response get(byte[] key) { return appendCommand(commandObjects.get(key)); } + @Override + public Response setGet(byte[] key, byte[] value) { + return appendCommand(commandObjects.setGet(key, value)); + } + @Override public Response setGet(byte[] key, byte[] value, SetParams params) { return appendCommand(commandObjects.setGet(key, value, params)); @@ -3149,6 +3163,10 @@ public Response getrange(byte[] key, long startOffset, long endOffset) { return appendCommand(commandObjects.getrange(key, startOffset, endOffset)); } + /** + * @deprecated Use {@link PipeliningBase#setGet(byte[], byte[])}. + */ + @Deprecated @Override public Response getSet(byte[] key, byte[] value) { return appendCommand(commandObjects.getSet(key, value)); diff --git a/src/main/java/redis/clients/jedis/UnifiedJedis.java b/src/main/java/redis/clients/jedis/UnifiedJedis.java index a43ffc10906..14e67a0fa17 100644 --- a/src/main/java/redis/clients/jedis/UnifiedJedis.java +++ b/src/main/java/redis/clients/jedis/UnifiedJedis.java @@ -825,6 +825,10 @@ public byte[] getrange(byte[] key, long startOffset, long endOffset) { return executeCommand(commandObjects.getrange(key, startOffset, endOffset)); } + /** + * @deprecated Use {@link UnifiedJedis#setGet(java.lang.String, java.lang.String)}. + */ + @Deprecated @Override public String getSet(String key, String value) { return executeCommand(commandObjects.getSet(key, value)); @@ -845,6 +849,10 @@ public String psetex(String key, long milliseconds, String value) { return executeCommand(commandObjects.psetex(key, milliseconds, value)); } + /** + * @deprecated Use {@link UnifiedJedis#setGet(byte[], byte[])}. + */ + @Deprecated @Override public byte[] getSet(byte[] key, byte[] value) { return executeCommand(commandObjects.getSet(key, value)); diff --git a/src/main/java/redis/clients/jedis/commands/StringBinaryCommands.java b/src/main/java/redis/clients/jedis/commands/StringBinaryCommands.java index ca51b1a1afe..0d087bc1b34 100644 --- a/src/main/java/redis/clients/jedis/commands/StringBinaryCommands.java +++ b/src/main/java/redis/clients/jedis/commands/StringBinaryCommands.java @@ -27,6 +27,10 @@ public interface StringBinaryCommands extends BitBinaryCommands { byte[] getrange(byte[] key, long startOffset, long endOffset); + /** + * @deprecated Use {@link StringBinaryCommands#setGet(byte[], byte[])}. + */ + @Deprecated byte[] getSet(byte[] key, byte[] value); long setnx(byte[] key, byte[] value); diff --git a/src/main/java/redis/clients/jedis/commands/StringCommands.java b/src/main/java/redis/clients/jedis/commands/StringCommands.java index 0621bc9334c..c4ea21fea7a 100644 --- a/src/main/java/redis/clients/jedis/commands/StringCommands.java +++ b/src/main/java/redis/clients/jedis/commands/StringCommands.java @@ -116,7 +116,9 @@ public interface StringCommands extends BitCommands { * @param key * @param value * @return The old value that was stored in key + * @deprecated Use {@link StringCommands#setGet(java.lang.String, java.lang.String)}. */ + @Deprecated String getSet(String key, String value); /** diff --git a/src/main/java/redis/clients/jedis/commands/StringPipelineBinaryCommands.java b/src/main/java/redis/clients/jedis/commands/StringPipelineBinaryCommands.java index b4a114d5658..13a40759869 100644 --- a/src/main/java/redis/clients/jedis/commands/StringPipelineBinaryCommands.java +++ b/src/main/java/redis/clients/jedis/commands/StringPipelineBinaryCommands.java @@ -16,6 +16,8 @@ public interface StringPipelineBinaryCommands extends BitPipelineBinaryCommands Response get(byte[] key); + Response setGet(byte[] key, byte[] value); + Response setGet(byte[] key, byte[] value, SetParams params); Response getDel(byte[] key); @@ -26,6 +28,10 @@ public interface StringPipelineBinaryCommands extends BitPipelineBinaryCommands Response getrange(byte[] key, long startOffset, long endOffset); + /** + * @deprecated {@link StringPipelineBinaryCommands#setGet(byte[], byte[], redis.clients.jedis.params.SetParams)}. + */ + @Deprecated Response getSet(byte[] key, byte[] value); Response setnx(byte[] key, byte[] value); diff --git a/src/main/java/redis/clients/jedis/commands/StringPipelineCommands.java b/src/main/java/redis/clients/jedis/commands/StringPipelineCommands.java index 6af9968ebe0..c037ed6fdef 100644 --- a/src/main/java/redis/clients/jedis/commands/StringPipelineCommands.java +++ b/src/main/java/redis/clients/jedis/commands/StringPipelineCommands.java @@ -16,6 +16,8 @@ public interface StringPipelineCommands extends BitPipelineCommands { Response get(String key); + Response setGet(String key, String value); + Response setGet(String key, String value, SetParams params); Response getDel(String key); @@ -26,6 +28,10 @@ public interface StringPipelineCommands extends BitPipelineCommands { Response getrange(String key, long startOffset, long endOffset); + /** + * @deprecated Use {@link StringPipelineCommands#setGet(java.lang.String, java.lang.String)}. + */ + @Deprecated Response getSet(String key, String value); Response setnx(String key, String value); From d41dbe978ce1409ef6ecca979399a1aba88c814c Mon Sep 17 00:00:00 2001 From: Gabriel Erzse Date: Wed, 13 Mar 2024 10:43:18 +0200 Subject: [PATCH 12/33] Reenable clustering tests (#3764) * Reenable clustering tests Uncomment clustering tests and adapt the code in the minimum possible way to make these tests run. * Include RESP protocol in cluster tests The cluster tests were not using the configured RESP protocol, so adjust that. * Use a separate cluster for the bulk of clustering tests Most of the clustering tests don't need to change the structure of the cluster. Use for these tests a stable cluster, that is configured outside the Java code and keeps its structure. The tests only flush the data on the cluster nodes, which is safe and fast. * Don't stunnel the stable cluster nodes Co-authored-by: M Sazzadul Hoque <7600764+sazzad16@users.noreply.github.com> * Move port range for stable cluster * Move some tests into subclasses The goal is to leave unchanged the top level test classes. --------- Co-authored-by: Gabriel Erzse Co-authored-by: M Sazzadul Hoque <7600764+sazzad16@users.noreply.github.com> --- Makefile | 57 ++ .../redis/clients/jedis/HostAndPorts.java | 9 + .../ClusterAllKindOfValuesCommandsTest.java | 521 ++++++++-------- .../ClusterBinaryValuesCommandsTest.java | 80 ++- .../cluster/ClusterBitCommandsTest.java | 145 +++-- .../cluster/ClusterCommandsTestHelper.java | 110 +--- .../cluster/ClusterGeoCommandsTest.java | 177 +++--- .../ClusterHyperLogLogCommandsTest.java | 146 +++-- .../cluster/ClusterListCommandsTest.java | 568 ++++++++++-------- .../cluster/ClusterSetCommandsTest.java | 375 ++++++------ .../cluster/ClusterSortedSetCommandsTest.java | 433 +++++++------ .../ClusterStringValuesCommandsTest.java | 181 +++--- 12 files changed, 1448 insertions(+), 1354 deletions(-) diff --git a/Makefile b/Makefile index 6e63f1b6ce0..96d106b0009 100644 --- a/Makefile +++ b/Makefile @@ -274,6 +274,50 @@ cluster-enabled yes cluster-config-file /tmp/redis_cluster_node5.conf endef +# STABLE CLUSTER REDIS NODES +# The structure of this cluster is not changed by the tests! +define REDIS_STABLE_CLUSTER_NODE1_CONF +daemonize yes +protected-mode no +requirepass cluster +port 7479 +cluster-node-timeout 15000 +pidfile /tmp/redis_stable_cluster_node1.pid +logfile /tmp/redis_stable_cluster_node1.log +save "" +appendonly no +cluster-enabled yes +cluster-config-file /tmp/redis_stable_cluster_node1.conf +endef + +define REDIS_STABLE_CLUSTER_NODE2_CONF +daemonize yes +protected-mode no +requirepass cluster +port 7480 +cluster-node-timeout 15000 +pidfile /tmp/redis_stable_cluster_node2.pid +logfile /tmp/redis_stable_cluster_node2.log +save "" +appendonly no +cluster-enabled yes +cluster-config-file /tmp/redis_stable_cluster_node2.conf +endef + +define REDIS_STABLE_CLUSTER_NODE3_CONF +daemonize yes +protected-mode no +requirepass cluster +port 7481 +cluster-node-timeout 15000 +pidfile /tmp/redis_stable_cluster_node3.pid +logfile /tmp/redis_stable_cluster_node3.log +save "" +appendonly no +cluster-enabled yes +cluster-config-file /tmp/redis_stable_cluster_node3.conf +endef + # UDS REDIS NODES define REDIS_UDS daemonize yes @@ -355,6 +399,9 @@ export REDIS_CLUSTER_NODE2_CONF export REDIS_CLUSTER_NODE3_CONF export REDIS_CLUSTER_NODE4_CONF export REDIS_CLUSTER_NODE5_CONF +export REDIS_STABLE_CLUSTER_NODE1_CONF +export REDIS_STABLE_CLUSTER_NODE2_CONF +export REDIS_STABLE_CLUSTER_NODE3_CONF export REDIS_UDS export REDIS_UNAVAILABLE_CONF export STUNNEL_CONF @@ -393,8 +440,12 @@ start: stunnel cleanup echo "$$REDIS_CLUSTER_NODE3_CONF" | redis-server - echo "$$REDIS_CLUSTER_NODE4_CONF" | redis-server - echo "$$REDIS_CLUSTER_NODE5_CONF" | redis-server - + echo "$$REDIS_STABLE_CLUSTER_NODE1_CONF" | redis-server - + echo "$$REDIS_STABLE_CLUSTER_NODE2_CONF" | redis-server - + echo "$$REDIS_STABLE_CLUSTER_NODE3_CONF" | redis-server - 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 cleanup: - rm -vf /tmp/redis_cluster_node*.conf 2>/dev/null @@ -426,6 +477,9 @@ stop: kill `cat /tmp/redis_cluster_node3.pid` || true kill `cat /tmp/redis_cluster_node4.pid` || true kill `cat /tmp/redis_cluster_node5.pid` || true + kill `cat /tmp/redis_stable_cluster_node1.pid` + kill `cat /tmp/redis_stable_cluster_node2.pid` + kill `cat /tmp/redis_stable_cluster_node3.pid` kill `cat /tmp/redis_uds.pid` || true kill `cat /tmp/stunnel.pid` || true [ -f /tmp/redis_unavailable.pid ] && kill `cat /tmp/redis_unavailable.pid` || true @@ -439,6 +493,9 @@ stop: rm -f /tmp/redis_cluster_node3.conf rm -f /tmp/redis_cluster_node4.conf rm -f /tmp/redis_cluster_node5.conf + rm -f /tmp/redis_stable_cluster_node1.conf + rm -f /tmp/redis_stable_cluster_node2.conf + rm -f /tmp/redis_stable_cluster_node3.conf test: compile-module start sleep 2 diff --git a/src/test/java/redis/clients/jedis/HostAndPorts.java b/src/test/java/redis/clients/jedis/HostAndPorts.java index 0ce0269f2a2..1f919117bb1 100644 --- a/src/test/java/redis/clients/jedis/HostAndPorts.java +++ b/src/test/java/redis/clients/jedis/HostAndPorts.java @@ -8,6 +8,7 @@ public final class HostAndPorts { private static List redisHostAndPortList = new ArrayList<>(); private static List sentinelHostAndPortList = new ArrayList<>(); private static List clusterHostAndPortList = new ArrayList<>(); + private static List stableClusterHostAndPortList = new ArrayList<>(); static { redisHostAndPortList.add(new HostAndPort("localhost", Protocol.DEFAULT_PORT)); @@ -34,6 +35,10 @@ public final class HostAndPorts { clusterHostAndPortList.add(new HostAndPort("localhost", 7382)); clusterHostAndPortList.add(new HostAndPort("localhost", 7383)); clusterHostAndPortList.add(new HostAndPort("localhost", 7384)); + + stableClusterHostAndPortList.add(new HostAndPort("localhost", 7479)); + stableClusterHostAndPortList.add(new HostAndPort("localhost", 7480)); + stableClusterHostAndPortList.add(new HostAndPort("localhost", 7481)); } public static List parseHosts(String envHosts, @@ -71,6 +76,10 @@ public static List getClusterServers() { return clusterHostAndPortList; } + public static List getStableClusterServers() { + return stableClusterHostAndPortList; + } + private HostAndPorts() { throw new InstantiationError("Must not instantiate this class"); } 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 80898ccd716..c71d5eb7cf4 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 @@ -1,266 +1,255 @@ -//package redis.clients.jedis.commands.unified.cluster; -// -//import static org.junit.Assert.assertEquals; -//import static org.junit.Assert.assertFalse; -//import static org.junit.Assert.assertNull; -//import static org.junit.Assert.assertTrue; -//import static redis.clients.jedis.params.ScanParams.SCAN_POINTER_START; -// -//import java.util.Collections; -//import java.util.HashSet; -//import java.util.Set; -// -//import org.junit.AfterClass; -//import org.junit.Before; -//import org.junit.BeforeClass; -//import org.junit.Test; -// -//import redis.clients.jedis.params.ScanParams; -//import redis.clients.jedis.resps.ScanResult; -//import redis.clients.jedis.commands.unified.AllKindOfValuesCommandsTestBase; -// -//public class ClusterAllKindOfValuesCommandsTest extends AllKindOfValuesCommandsTestBase { -// -// @BeforeClass -// public static void prepare() throws InterruptedException { -// jedis = ClusterCommandsTestHelper.initAndGetCluster(); -// } -// -// @AfterClass -// public static void closeCluster() { -// jedis.close(); -// } -// -// @AfterClass -// public static void resetCluster() { -// ClusterCommandsTestHelper.tearClusterDown(); -// } -// -// @Before -// public void setUp() { -// ClusterCommandsTestHelper.clearClusterData(); -// } -// -// @Test -// @Override -// public void existsMany() { -// String status = jedis.set("{foo}1", "bar1"); -// assertEquals("OK", status); -// -// status = jedis.set("{foo}2", "bar2"); -// assertEquals("OK", status); -// -// assertEquals(2L, jedis.exists("{foo}1", "{foo}2")); -// -// assertEquals(1L, jedis.del("{foo}1")); -// -// assertEquals(1L, jedis.exists("{foo}1", "{foo}2")); -// } -// -// @Test -// @Override -// public void del() { -// jedis.set("{foo}1", "bar1"); -// jedis.set("{foo}2", "bar2"); -// jedis.set("{foo}3", "bar3"); -// -// assertEquals(3L, jedis.del("{foo}1", "{foo}2", "{foo}3")); -// -// assertFalse(jedis.exists("{foo}1")); -// assertFalse(jedis.exists("{foo}2")); -// assertFalse(jedis.exists("{foo}3")); -// -// jedis.set("{foo}1", "bar1"); -// -// assertEquals(1L, jedis.del("{foo}1", "{foo}2")); -// -// assertEquals(0L, jedis.del("{foo}1", "{foo}2")); -// } -// -// @Test -// @Override -// public void unlink() { -// jedis.set("{foo}1", "bar1"); -// jedis.set("{foo}2", "bar2"); -// jedis.set("{foo}3", "bar3"); -// -// assertEquals(3, jedis.unlink("{foo}1", "{foo}2", "{foo}3")); -// -// assertEquals(0, jedis.exists("{foo}1", "{foo}2", "{foo}3")); -// -// jedis.set("{foo}1", "bar1"); -// -// assertEquals(1, jedis.unlink("{foo}1", "{foo}2")); -// -// assertEquals(0, jedis.unlink("{foo}1", "{foo}2")); -// -// jedis.set("{foo}", "bar"); -// assertEquals(1, jedis.unlink("{foo}")); -// assertFalse(jedis.exists("{foo}")); -// } -// -// @Test -// @Override -// public void keys() { -// jedis.set("{foo}", "bar"); -// jedis.set("{foo}bar", "bar"); -// -// Set keys = jedis.keys("{foo}*"); -// Set expected = new HashSet<>(); -// expected.add("{foo}"); -// expected.add("{foo}bar"); -// assertEquals(expected, keys); -// -// expected.clear(); -// keys = jedis.keys("{bar}*"); -// -// assertEquals(expected, keys); -// } -// -// @Test -// @Override -// public void rename() { -// jedis.set("foo{#}", "bar"); -// String status = jedis.rename("foo{#}", "bar{#}"); -// assertEquals("OK", status); -// -// assertNull(jedis.get("foo{#}")); -// -// assertEquals("bar", jedis.get("bar{#}")); -// } -// -// @Test -// @Override -// public void renamenx() { -// jedis.set("foo{&}", "bar"); -// assertEquals(1, jedis.renamenx("foo{&}", "bar{&}")); -// -// jedis.set("foo{&}", "bar"); -// assertEquals(0, jedis.renamenx("foo{&}", "bar{&}")); -// } -// -// @Test(expected = UnsupportedOperationException.class) -// @Override -// public void dbSize() { -// super.dbSize(); -// } -// -// @Test -// @Override -// public void touch() throws Exception { -// assertEquals(0, jedis.touch("{foo}1", "{foo}2", "{foo}3")); -// -// jedis.set("{foo}1", "bar1"); -// -// Thread.sleep(1100); // little over 1 sec -// assertTrue(jedis.objectIdletime("{foo}1") > 0); -// -// assertEquals(1, jedis.touch("{foo}1")); -// assertEquals(0L, jedis.objectIdletime("{foo}1").longValue()); -// -// assertEquals(1, jedis.touch("{foo}1", "{foo}2", "{foo}3")); -// -// jedis.set("{foo}2", "bar2"); -// -// jedis.set("{foo}3", "bar3"); -// -// assertEquals(3, jedis.touch("{foo}1", "{foo}2", "{foo}3")); -// } -// -// @Test -// @Override -// public void scan() { -// jedis.set("{%}b", "b"); -// jedis.set("a{%}", "a"); -// -// ScanResult result = jedis.scan(SCAN_POINTER_START, new ScanParams().match("*{%}*")); -// -// assertEquals(SCAN_POINTER_START, result.getCursor()); -// assertFalse(result.getResult().isEmpty()); -// } -// -// @Test -// @Override -// public void scanMatch() { -// ScanParams params = new ScanParams(); -// params.match("a{-}*"); -// -// jedis.set("b{-}", "b"); -// jedis.set("a{-}", "a"); -// jedis.set("a{-}a", "aa"); -// ScanResult result = jedis.scan(SCAN_POINTER_START, params); -// -// assertEquals(SCAN_POINTER_START, result.getCursor()); -// assertFalse(result.getResult().isEmpty()); -// } -// -// @Test -// @Override -// public void scanCount() { -// ScanParams params = new ScanParams(); -// params.match("{a}*"); -// params.count(2); -// -// for (int i = 0; i < 10; i++) { -// jedis.set("{a}" + i, "a" + i); -// } -// -// ScanResult result = jedis.scan(SCAN_POINTER_START, params); -// assertTrue(result.getResult().size() >= 2); -// } -// -// @Test -// @Override -// public void scanType() { -// ScanParams noCount = new ScanParams().match("*{+}*"); -// ScanParams pagingParams = new ScanParams().match("*{+}*").count(4); -// -// jedis.set("{+}a", "a"); -// jedis.hset("{+}b", "b", "b"); -// jedis.set("c{+}", "c"); -// jedis.sadd("d{+}", "d"); -// jedis.set("e{+}", "e"); -// jedis.zadd("{+}f", 0d, "f"); -// jedis.set("{+}g", "g"); -// -// // string -// ScanResult scanResult; -// -// scanResult = jedis.scan(SCAN_POINTER_START, pagingParams, "string"); -// assertFalse(scanResult.isCompleteIteration()); -// int page1Count = scanResult.getResult().size(); -// scanResult = jedis.scan(scanResult.getCursor(), pagingParams, "string"); -// assertTrue(scanResult.isCompleteIteration()); -// int page2Count = scanResult.getResult().size(); -// assertEquals(4, page1Count + page2Count); -// -// -// scanResult = jedis.scan(SCAN_POINTER_START, noCount, "hash"); -// assertEquals(Collections.singletonList("{+}b"), scanResult.getResult()); -// scanResult = jedis.scan(SCAN_POINTER_START, noCount, "set"); -// assertEquals(Collections.singletonList("d{+}"), scanResult.getResult()); -// scanResult = jedis.scan(SCAN_POINTER_START, noCount, "zset"); -// assertEquals(Collections.singletonList("{+}f"), scanResult.getResult()); -// } -// -// @Test(expected = IllegalArgumentException.class) -// @Override -// public void scanIsCompleteIteration() { -// super.scanIsCompleteIteration(); -// } -// -// @Test -// @Override -// public void copy() { -// assertFalse(jedis.copy("unkn{o}wn", "f{o}o", false)); -// -// jedis.set("{foo}1", "bar"); -// assertTrue(jedis.copy("{foo}1", "{foo}2", false)); -// assertEquals("bar", jedis.get("{foo}2")); -// -// // replace -// jedis.set("{foo}1", "bar1"); -// assertTrue(jedis.copy("{foo}1", "{foo}2", true)); -// assertEquals("bar1", jedis.get("{foo}2")); -// } -//} +package redis.clients.jedis.commands.unified.cluster; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static redis.clients.jedis.params.ScanParams.SCAN_POINTER_START; + +import java.util.Collections; +import java.util.HashSet; +import java.util.Set; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import redis.clients.jedis.commands.unified.AllKindOfValuesCommandsTestBase; +import redis.clients.jedis.params.ScanParams; +import redis.clients.jedis.resps.ScanResult; + +public class ClusterAllKindOfValuesCommandsTest extends AllKindOfValuesCommandsTestBase { + + @Before + public void setUp() { + jedis = ClusterCommandsTestHelper.getCleanCluster(); + } + + @After + public void tearDown() { + jedis.close(); + ClusterCommandsTestHelper.clearClusterData(); + } + + @Test + @Override + public void existsMany() { + String status = jedis.set("{foo}1", "bar1"); + assertEquals("OK", status); + + status = jedis.set("{foo}2", "bar2"); + assertEquals("OK", status); + + assertEquals(2L, jedis.exists("{foo}1", "{foo}2")); + + assertEquals(1L, jedis.del("{foo}1")); + + assertEquals(1L, jedis.exists("{foo}1", "{foo}2")); + } + + @Test + @Override + public void del() { + jedis.set("{foo}1", "bar1"); + jedis.set("{foo}2", "bar2"); + jedis.set("{foo}3", "bar3"); + + assertEquals(3L, jedis.del("{foo}1", "{foo}2", "{foo}3")); + + assertFalse(jedis.exists("{foo}1")); + assertFalse(jedis.exists("{foo}2")); + assertFalse(jedis.exists("{foo}3")); + + jedis.set("{foo}1", "bar1"); + + assertEquals(1L, jedis.del("{foo}1", "{foo}2")); + + assertEquals(0L, jedis.del("{foo}1", "{foo}2")); + } + + @Test + @Override + public void unlink() { + jedis.set("{foo}1", "bar1"); + jedis.set("{foo}2", "bar2"); + jedis.set("{foo}3", "bar3"); + + assertEquals(3, jedis.unlink("{foo}1", "{foo}2", "{foo}3")); + + assertEquals(0, jedis.exists("{foo}1", "{foo}2", "{foo}3")); + + jedis.set("{foo}1", "bar1"); + + assertEquals(1, jedis.unlink("{foo}1", "{foo}2")); + + assertEquals(0, jedis.unlink("{foo}1", "{foo}2")); + + jedis.set("{foo}", "bar"); + assertEquals(1, jedis.unlink("{foo}")); + assertFalse(jedis.exists("{foo}")); + } + + @Test + @Override + public void keys() { + jedis.set("{foo}", "bar"); + jedis.set("{foo}bar", "bar"); + + Set keys = jedis.keys("{foo}*"); + Set expected = new HashSet<>(); + expected.add("{foo}"); + expected.add("{foo}bar"); + assertEquals(expected, keys); + + expected.clear(); + keys = jedis.keys("{bar}*"); + + assertEquals(expected, keys); + } + + @Test + @Override + public void rename() { + jedis.set("foo{#}", "bar"); + String status = jedis.rename("foo{#}", "bar{#}"); + assertEquals("OK", status); + + assertNull(jedis.get("foo{#}")); + + assertEquals("bar", jedis.get("bar{#}")); + } + + @Test + @Override + public void renamenx() { + jedis.set("foo{&}", "bar"); + assertEquals(1, jedis.renamenx("foo{&}", "bar{&}")); + + jedis.set("foo{&}", "bar"); + assertEquals(0, jedis.renamenx("foo{&}", "bar{&}")); + } + + @Test(expected = UnsupportedOperationException.class) + @Override + public void dbSize() { + super.dbSize(); + } + + @Test + @Override + public void touch() throws Exception { + assertEquals(0, jedis.touch("{foo}1", "{foo}2", "{foo}3")); + + jedis.set("{foo}1", "bar1"); + + Thread.sleep(1100); // little over 1 sec + assertTrue(jedis.objectIdletime("{foo}1") > 0); + + assertEquals(1, jedis.touch("{foo}1")); + assertEquals(0L, jedis.objectIdletime("{foo}1").longValue()); + + assertEquals(1, jedis.touch("{foo}1", "{foo}2", "{foo}3")); + + jedis.set("{foo}2", "bar2"); + + jedis.set("{foo}3", "bar3"); + + assertEquals(3, jedis.touch("{foo}1", "{foo}2", "{foo}3")); + } + + @Test + @Override + public void scan() { + jedis.set("{%}b", "b"); + jedis.set("a{%}", "a"); + + ScanResult result = jedis.scan(SCAN_POINTER_START, new ScanParams().match("*{%}*")); + + assertEquals(SCAN_POINTER_START, result.getCursor()); + assertFalse(result.getResult().isEmpty()); + } + + @Test + @Override + public void scanMatch() { + ScanParams params = new ScanParams(); + params.match("a{-}*"); + + jedis.set("b{-}", "b"); + jedis.set("a{-}", "a"); + jedis.set("a{-}a", "aa"); + ScanResult result = jedis.scan(SCAN_POINTER_START, params); + + assertEquals(SCAN_POINTER_START, result.getCursor()); + assertFalse(result.getResult().isEmpty()); + } + + @Test + @Override + public void scanCount() { + ScanParams params = new ScanParams(); + params.match("{a}*"); + params.count(2); + + for (int i = 0; i < 10; i++) { + jedis.set("{a}" + i, "a" + i); + } + + ScanResult result = jedis.scan(SCAN_POINTER_START, params); + assertTrue(result.getResult().size() >= 2); + } + + @Test + @Override + public void scanType() { + ScanParams noCount = new ScanParams().match("*{+}*"); + ScanParams pagingParams = new ScanParams().match("*{+}*").count(4); + + jedis.set("{+}a", "a"); + jedis.hset("{+}b", "b", "b"); + jedis.set("c{+}", "c"); + jedis.sadd("d{+}", "d"); + jedis.set("e{+}", "e"); + jedis.zadd("{+}f", 0d, "f"); + jedis.set("{+}g", "g"); + + // string + ScanResult scanResult; + + scanResult = jedis.scan(SCAN_POINTER_START, pagingParams, "string"); + assertFalse(scanResult.isCompleteIteration()); + int page1Count = scanResult.getResult().size(); + scanResult = jedis.scan(scanResult.getCursor(), pagingParams, "string"); + assertTrue(scanResult.isCompleteIteration()); + int page2Count = scanResult.getResult().size(); + assertEquals(4, page1Count + page2Count); + + + scanResult = jedis.scan(SCAN_POINTER_START, noCount, "hash"); + assertEquals(Collections.singletonList("{+}b"), scanResult.getResult()); + scanResult = jedis.scan(SCAN_POINTER_START, noCount, "set"); + assertEquals(Collections.singletonList("d{+}"), scanResult.getResult()); + scanResult = jedis.scan(SCAN_POINTER_START, noCount, "zset"); + assertEquals(Collections.singletonList("{+}f"), scanResult.getResult()); + } + + @Test(expected = IllegalArgumentException.class) + @Override + public void scanIsCompleteIteration() { + super.scanIsCompleteIteration(); + } + + @Test + @Override + public void copy() { + assertFalse(jedis.copy("unkn{o}wn", "f{o}o", false)); + + jedis.set("{foo}1", "bar"); + assertTrue(jedis.copy("{foo}1", "{foo}2", false)); + assertEquals("bar", jedis.get("{foo}2")); + + // replace + jedis.set("{foo}1", "bar1"); + assertTrue(jedis.copy("{foo}1", "{foo}2", true)); + assertEquals("bar1", jedis.get("{foo}2")); + } +} 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 6dcbbd823bd..8b70e29271b 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 @@ -1,45 +1,35 @@ -//package redis.clients.jedis.commands.unified.cluster; -// -//import org.junit.AfterClass; -//import org.junit.Before; -//import org.junit.BeforeClass; -//import org.junit.Ignore; -//import redis.clients.jedis.commands.unified.BinaryValuesCommandsTestBase; -// -//public class ClusterBinaryValuesCommandsTest extends BinaryValuesCommandsTestBase { -// -// @BeforeClass -// public static void prepare() throws InterruptedException { -// jedis = ClusterCommandsTestHelper.initAndGetCluster(); -// } -// -// @AfterClass -// public static void closeCluster() { -// jedis.close(); -// } -// -// @AfterClass -// public static void resetCluster() { -// ClusterCommandsTestHelper.tearClusterDown(); -// } -// -// @Before -// public void setUp() { -// ClusterCommandsTestHelper.clearClusterData(); -// } -// -// @Ignore -// @Override -// public void mget() { -// } -// -// @Ignore -// @Override -// public void mset() { -// } -// -// @Ignore -// @Override -// public void msetnx() { -// } -//} +package redis.clients.jedis.commands.unified.cluster; + +import org.junit.After; +import org.junit.Before; +import org.junit.Ignore; +import redis.clients.jedis.commands.unified.BinaryValuesCommandsTestBase; + +public class ClusterBinaryValuesCommandsTest extends BinaryValuesCommandsTestBase { + + @Before + public void setUp() { + jedis = ClusterCommandsTestHelper.getCleanCluster(); + } + + @After + public void tearDown() { + jedis.close(); + ClusterCommandsTestHelper.clearClusterData(); + } + + @Ignore + @Override + public void mget() { + } + + @Ignore + @Override + public void mset() { + } + + @Ignore + @Override + public void msetnx() { + } +} 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 47804941fc7..64f4f8376cc 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 @@ -1,78 +1,67 @@ -//package redis.clients.jedis.commands.unified.cluster; -// -//import static org.junit.Assert.assertEquals; -// -//import org.junit.AfterClass; -//import org.junit.Before; -//import org.junit.BeforeClass; -//import org.junit.Ignore; -//import org.junit.Test; -// -//import redis.clients.jedis.args.BitOP; -//import redis.clients.jedis.exceptions.JedisDataException; -//import redis.clients.jedis.commands.unified.BitCommandsTestBase; -// -//public class ClusterBitCommandsTest extends BitCommandsTestBase { -// -// @BeforeClass -// public static void prepare() throws InterruptedException { -// jedis = ClusterCommandsTestHelper.initAndGetCluster(); -// } -// -// @AfterClass -// public static void closeCluster() { -// jedis.close(); -// } -// -// @AfterClass -// public static void resetCluster() { -// ClusterCommandsTestHelper.tearClusterDown(); -// } -// -// @Before -// public void setUp() { -// ClusterCommandsTestHelper.clearClusterData(); -// } -// -// @Test -// @Override -// public void bitOp() { -// jedis.set("{key}1", "\u0060"); -// jedis.set("{key}2", "\u0044"); -// -// jedis.bitop(BitOP.AND, "resultAnd{key}", "{key}1", "{key}2"); -// String resultAnd = jedis.get("resultAnd{key}"); -// assertEquals("\u0040", resultAnd); -// -// jedis.bitop(BitOP.OR, "resultOr{key}", "{key}1", "{key}2"); -// String resultOr = jedis.get("resultOr{key}"); -// assertEquals("\u0064", resultOr); -// -// jedis.bitop(BitOP.XOR, "resultXor{key}", "{key}1", "{key}2"); -// String resultXor = jedis.get("resultXor{key}"); -// assertEquals("\u0024", resultXor); -// } -// -// @Test -// @Override -// public void bitOpNot() { -// jedis.setbit("key", 0, true); -// jedis.setbit("key", 4, true); -// -// jedis.bitop(BitOP.NOT, "resultNot{key}", "key"); -// String resultNot = jedis.get("resultNot{key}"); -// assertEquals("\u0077", resultNot); -// } -// -// @Ignore -// @Override -// public void bitOpBinary() { -// } -// -// @Test(expected = JedisDataException.class) -// @Override -// public void bitOpNotMultiSourceShouldFail() { -// jedis.bitop(BitOP.NOT, "{!}dest", "{!}src1", "{!}src2"); -// } -// -//} +package redis.clients.jedis.commands.unified.cluster; + +import static org.junit.Assert.assertEquals; + +import org.junit.After; +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Test; +import redis.clients.jedis.args.BitOP; +import redis.clients.jedis.commands.unified.BitCommandsTestBase; +import redis.clients.jedis.exceptions.JedisDataException; + +public class ClusterBitCommandsTest extends BitCommandsTestBase { + + @Before + public void setUp() { + jedis = ClusterCommandsTestHelper.getCleanCluster(); + } + + @After + public void tearDown() { + jedis.close(); + ClusterCommandsTestHelper.clearClusterData(); + } + + @Test + @Override + public void bitOp() { + jedis.set("{key}1", "\u0060"); + jedis.set("{key}2", "\u0044"); + + jedis.bitop(BitOP.AND, "resultAnd{key}", "{key}1", "{key}2"); + String resultAnd = jedis.get("resultAnd{key}"); + assertEquals("\u0040", resultAnd); + + jedis.bitop(BitOP.OR, "resultOr{key}", "{key}1", "{key}2"); + String resultOr = jedis.get("resultOr{key}"); + assertEquals("\u0064", resultOr); + + jedis.bitop(BitOP.XOR, "resultXor{key}", "{key}1", "{key}2"); + String resultXor = jedis.get("resultXor{key}"); + assertEquals("\u0024", resultXor); + } + + @Test + @Override + public void bitOpNot() { + jedis.setbit("key", 0, true); + jedis.setbit("key", 4, true); + + jedis.bitop(BitOP.NOT, "resultNot{key}", "key"); + String resultNot = jedis.get("resultNot{key}"); + assertEquals("\u0077", resultNot); + } + + @Ignore + @Override + public void bitOpBinary() { + } + + @Test(expected = JedisDataException.class) + @Override + public void bitOpNotMultiSourceShouldFail() { + jedis.bitop(BitOP.NOT, "{!}dest", "{!}src1", "{!}src2"); + } + +} 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 e5dc2508f36..238f3044e2a 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 @@ -1,82 +1,28 @@ -//package redis.clients.jedis.commands.unified.cluster; -// -//import static redis.clients.jedis.Protocol.CLUSTER_HASHSLOTS; -// -//import java.util.Collections; -// -//import redis.clients.jedis.HostAndPort; -//import redis.clients.jedis.Jedis; -//import redis.clients.jedis.JedisCluster; -//import redis.clients.jedis.args.ClusterResetType; -//import redis.clients.jedis.HostAndPorts; -//import redis.clients.jedis.util.JedisClusterTestUtil; -// -//public class ClusterCommandsTestHelper { -// -// private static final HostAndPort nodeInfo1 = HostAndPorts.getClusterServers().get(0); -// private static final HostAndPort nodeInfo2 = HostAndPorts.getClusterServers().get(1); -// private static final HostAndPort nodeInfo3 = HostAndPorts.getClusterServers().get(2); -// -// private static Jedis node1; -// private static Jedis node2; -// private static Jedis node3; -// -// static JedisCluster initAndGetCluster() throws InterruptedException { -// -// node1 = new Jedis(nodeInfo1); -// node1.auth("cluster"); -// node1.flushAll(); -// -// node2 = new Jedis(nodeInfo2); -// node2.auth("cluster"); -// node2.flushAll(); -// -// node3 = new Jedis(nodeInfo3); -// node3.auth("cluster"); -// node3.flushAll(); -// -// // ---- configure cluster -// // add nodes to cluster -// node1.clusterMeet("127.0.0.1", nodeInfo2.getPort()); -// node1.clusterMeet("127.0.0.1", nodeInfo3.getPort()); -// -// // split available slots across the three nodes -// int slotsPerNode = CLUSTER_HASHSLOTS / 3; -// int[] node1Slots = new int[slotsPerNode]; -// int[] node2Slots = new int[slotsPerNode + 1]; -// int[] node3Slots = new int[slotsPerNode]; -// for (int i = 0, slot1 = 0, slot2 = 0, slot3 = 0; i < CLUSTER_HASHSLOTS; i++) { -// if (i < slotsPerNode) { -// node1Slots[slot1++] = i; -// } else if (i > slotsPerNode * 2) { -// node3Slots[slot3++] = i; -// } else { -// node2Slots[slot2++] = i; -// } -// } -// -// node1.clusterAddSlots(node1Slots); -// node2.clusterAddSlots(node2Slots); -// node3.clusterAddSlots(node3Slots); -// -// JedisClusterTestUtil.waitForClusterReady(node1, node2, node2); -// -// return new JedisCluster(Collections.singleton( -// new HostAndPort("127.0.0.1", nodeInfo1.getPort())), null, "cluster"); -// } -// -// static void tearClusterDown() { -// node1.flushDB(); -// node2.flushDB(); -// node3.flushDB(); -// node1.clusterReset(ClusterResetType.SOFT); -// node2.clusterReset(ClusterResetType.SOFT); -// node3.clusterReset(ClusterResetType.SOFT); -// } -// -// static void clearClusterData() { -// node1.flushDB(); -// node2.flushDB(); -// node3.flushDB(); -// } -//} +package redis.clients.jedis.commands.unified.cluster; + +import java.util.Collections; + +import redis.clients.jedis.DefaultJedisClientConfig; +import redis.clients.jedis.HostAndPorts; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisCluster; +import redis.clients.jedis.util.RedisProtocolUtil; + +public class ClusterCommandsTestHelper { + + static JedisCluster getCleanCluster() { + clearClusterData(); + return new JedisCluster( + Collections.singleton(HostAndPorts.getStableClusterServers().get(0)), + DefaultJedisClientConfig.builder().password("cluster").protocol(RedisProtocolUtil.getRedisProtocol()).build()); + } + + static void clearClusterData() { + for (int i = 0; i < 3; i++) { + try (Jedis jedis = new Jedis(HostAndPorts.getStableClusterServers().get(i))) { + jedis.auth("cluster"); + jedis.flushAll(); + } + } + } +} 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 31a400b7757..76ef6d1c736 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 @@ -1,89 +1,88 @@ -//package redis.clients.jedis.commands.unified.cluster; -// -//import static org.junit.Assert.assertEquals; -// -//import java.util.ArrayList; -//import java.util.HashMap; -//import java.util.List; -//import java.util.Map; -// -//import org.junit.AfterClass; -//import org.junit.Before; -//import org.junit.BeforeClass; -//import org.junit.Ignore; -//import org.junit.Test; -// -//import redis.clients.jedis.GeoCoordinate; -//import redis.clients.jedis.args.GeoUnit; -//import redis.clients.jedis.params.GeoRadiusParam; -//import redis.clients.jedis.params.GeoRadiusStoreParam; -//import redis.clients.jedis.commands.unified.GeoCommandsTestBase; -// -//public class ClusterGeoCommandsTest extends GeoCommandsTestBase { -// -// @BeforeClass -// public static void prepare() throws InterruptedException { -// jedis = ClusterCommandsTestHelper.initAndGetCluster(); -// } -// -// @AfterClass -// public static void closeCluster() { -// jedis.close(); -// } -// -// @AfterClass -// public static void resetCluster() { -// ClusterCommandsTestHelper.tearClusterDown(); -// } -// -// @Before -// public void setUp() { -// ClusterCommandsTestHelper.clearClusterData(); -// } -// -// @Test -// @Override -// public void georadiusStore() { -// // prepare datas -// Map coordinateMap = new HashMap<>(); -// coordinateMap.put("Palermo", new GeoCoordinate(13.361389, 38.115556)); -// coordinateMap.put("Catania", new GeoCoordinate(15.087269, 37.502669)); -// jedis.geoadd("Sicily {ITA}", coordinateMap); -// -// long size = jedis.georadiusStore("Sicily {ITA}", 15, 37, 200, GeoUnit.KM, -// GeoRadiusParam.geoRadiusParam(), -// GeoRadiusStoreParam.geoRadiusStoreParam().store("{ITA} SicilyStore")); -// assertEquals(2, size); -// List expected = new ArrayList<>(); -// expected.add("Palermo"); -// expected.add("Catania"); -// assertEquals(expected, jedis.zrange("{ITA} SicilyStore", 0, -1)); -// } -// -// @Ignore -// @Override -// public void georadiusStoreBinary() { -// } -// -// @Test -// @Override -// public void georadiusByMemberStore() { -// jedis.geoadd("Sicily {ITA}", 13.583333, 37.316667, "Agrigento"); -// jedis.geoadd("Sicily {ITA}", 13.361389, 38.115556, "Palermo"); -// jedis.geoadd("Sicily {ITA}", 15.087269, 37.502669, "Catania"); -// -// long size = jedis.georadiusByMemberStore("Sicily {ITA}", "Agrigento", 100, GeoUnit.KM, -// GeoRadiusParam.geoRadiusParam(), -// GeoRadiusStoreParam.geoRadiusStoreParam().store("{ITA} SicilyStore")); -// assertEquals(2, size); -// List expected = new ArrayList<>(); -// expected.add("Agrigento"); -// expected.add("Palermo"); -// assertEquals(expected, jedis.zrange("{ITA} SicilyStore", 0, -1)); -// } -// -// @Ignore -// @Override -// public void georadiusByMemberStoreBinary() { -// } -//} +package redis.clients.jedis.commands.unified.cluster; + +import static org.junit.Assert.assertEquals; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.junit.After; +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Test; +import redis.clients.jedis.GeoCoordinate; +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; + +public class ClusterGeoCommandsTest extends GeoCommandsTestBase { + + @Before + public void setUp() { + jedis = ClusterCommandsTestHelper.getCleanCluster(); + } + + @After + public void tearDown() { + jedis.close(); + ClusterCommandsTestHelper.clearClusterData(); + } + + @Test + @Override + public void georadiusStore() { + // prepare datas + Map coordinateMap = new HashMap<>(); + coordinateMap.put("Palermo", new GeoCoordinate(13.361389, 38.115556)); + coordinateMap.put("Catania", new GeoCoordinate(15.087269, 37.502669)); + jedis.geoadd("Sicily {ITA}", coordinateMap); + + long size = jedis.georadiusStore("Sicily {ITA}", 15, 37, 200, GeoUnit.KM, + GeoRadiusParam.geoRadiusParam(), + GeoRadiusStoreParam.geoRadiusStoreParam().store("{ITA} SicilyStore")); + assertEquals(2, size); + List expected = new ArrayList<>(); + expected.add("Palermo"); + expected.add("Catania"); + assertEquals(expected, jedis.zrange("{ITA} SicilyStore", 0, -1)); + } + + @Ignore + @Override + public void georadiusStoreBinary() { + } + + @Test + @Override + public void georadiusByMemberStore() { + jedis.geoadd("Sicily {ITA}", 13.583333, 37.316667, "Agrigento"); + jedis.geoadd("Sicily {ITA}", 13.361389, 38.115556, "Palermo"); + jedis.geoadd("Sicily {ITA}", 15.087269, 37.502669, "Catania"); + + long size = jedis.georadiusByMemberStore("Sicily {ITA}", "Agrigento", 100, GeoUnit.KM, + GeoRadiusParam.geoRadiusParam(), + GeoRadiusStoreParam.geoRadiusStoreParam().store("{ITA} SicilyStore")); + assertEquals(2, size); + List expected = new ArrayList<>(); + expected.add("Agrigento"); + expected.add("Palermo"); + assertEquals(expected, jedis.zrange("{ITA} SicilyStore", 0, -1)); + } + + @Ignore + @Override + public void georadiusByMemberStoreBinary() { + } + + @Test + @Ignore + public void geosearchstore() { + } + + @Test + @Ignore + public void geosearchstoreWithdist() { + } +} 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 911e40396d0..49da95e0264 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 @@ -1,78 +1,68 @@ -//package redis.clients.jedis.commands.unified.cluster; -// -//import static org.junit.Assert.assertEquals; -// -//import org.junit.AfterClass; -//import org.junit.Before; -//import org.junit.BeforeClass; -//import org.junit.Ignore; -//import org.junit.Test; -//import redis.clients.jedis.commands.unified.HyperLogLogCommandsTestBase; -// -//public class ClusterHyperLogLogCommandsTest extends HyperLogLogCommandsTestBase { -// -// @BeforeClass -// public static void prepare() throws InterruptedException { -// jedis = ClusterCommandsTestHelper.initAndGetCluster(); -// } -// -// @AfterClass -// public static void closeCluster() { -// jedis.close(); -// } -// -// @AfterClass -// public static void resetCluster() { -// ClusterCommandsTestHelper.tearClusterDown(); -// } -// -// @Before -// public void setUp() { -// ClusterCommandsTestHelper.clearClusterData(); -// } -// -// @Test -// @Override -// public void pfcounts() { -// long status = jedis.pfadd("{hll}_1", "foo", "bar", "zap"); -// assertEquals(1, status); -// status = jedis.pfadd("{hll}_2", "foo", "bar", "zap"); -// assertEquals(1, status); -// -// status = jedis.pfadd("{hll}_3", "foo", "bar", "baz"); -// assertEquals(1, status); -// status = jedis.pfcount("{hll}_1"); -// assertEquals(3, status); -// status = jedis.pfcount("{hll}_2"); -// assertEquals(3, status); -// status = jedis.pfcount("{hll}_3"); -// assertEquals(3, status); -// -// status = jedis.pfcount("{hll}_1", "{hll}_2"); -// assertEquals(3, status); -// -// status = jedis.pfcount("{hll}_1", "{hll}_2", "{hll}_3"); -// assertEquals(4, status); -// } -// -// @Test -// @Override -// public void pfmerge() { -// long status = jedis.pfadd("{hll}1", "foo", "bar", "zap", "a"); -// assertEquals(1, status); -// -// status = jedis.pfadd("{hll}2", "a", "b", "c", "foo"); -// assertEquals(1, status); -// -// String mergeStatus = jedis.pfmerge("{hll}3", "{hll}1", "{hll}2"); -// assertEquals("OK", mergeStatus); -// -// status = jedis.pfcount("{hll}3"); -// assertEquals(6, status); -// } -// -// @Ignore -// @Override -// public void pfmergeBinary() { -// } -//} +package redis.clients.jedis.commands.unified.cluster; + +import static org.junit.Assert.assertEquals; + +import org.junit.After; +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Test; +import redis.clients.jedis.commands.unified.HyperLogLogCommandsTestBase; + +public class ClusterHyperLogLogCommandsTest extends HyperLogLogCommandsTestBase { + + @Before + public void setUp() { + jedis = ClusterCommandsTestHelper.getCleanCluster(); + } + + @After + public void tearDown() { + jedis.close(); + ClusterCommandsTestHelper.clearClusterData(); + } + + @Test + @Override + public void pfcounts() { + long status = jedis.pfadd("{hll}_1", "foo", "bar", "zap"); + assertEquals(1, status); + status = jedis.pfadd("{hll}_2", "foo", "bar", "zap"); + assertEquals(1, status); + + status = jedis.pfadd("{hll}_3", "foo", "bar", "baz"); + assertEquals(1, status); + status = jedis.pfcount("{hll}_1"); + assertEquals(3, status); + status = jedis.pfcount("{hll}_2"); + assertEquals(3, status); + status = jedis.pfcount("{hll}_3"); + assertEquals(3, status); + + status = jedis.pfcount("{hll}_1", "{hll}_2"); + assertEquals(3, status); + + status = jedis.pfcount("{hll}_1", "{hll}_2", "{hll}_3"); + assertEquals(4, status); + } + + @Test + @Override + public void pfmerge() { + long status = jedis.pfadd("{hll}1", "foo", "bar", "zap", "a"); + assertEquals(1, status); + + status = jedis.pfadd("{hll}2", "a", "b", "c", "foo"); + assertEquals(1, status); + + String mergeStatus = jedis.pfmerge("{hll}3", "{hll}1", "{hll}2"); + assertEquals("OK", mergeStatus); + + status = jedis.pfcount("{hll}3"); + assertEquals(6, status); + } + + @Ignore + @Override + public void pfmergeBinary() { + } +} 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 4560a85be47..10af17a110b 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 @@ -1,266 +1,302 @@ -//package redis.clients.jedis.commands.unified.cluster; -// -//import static org.junit.Assert.assertArrayEquals; -//import static org.junit.Assert.assertEquals; -//import static org.junit.Assert.assertNotNull; -//import static org.junit.Assert.assertNull; -// -//import java.util.ArrayList; -//import java.util.Arrays; -//import java.util.Collections; -//import java.util.List; -// -//import org.slf4j.Logger; -//import org.slf4j.LoggerFactory; -// -//import org.junit.AfterClass; -//import org.junit.Before; -//import org.junit.BeforeClass; -//import org.junit.Test; -// -//import redis.clients.jedis.args.ListDirection; -//import redis.clients.jedis.resps.KeyedListElement; -//import redis.clients.jedis.commands.unified.ListCommandsTestBase; -// -//public class ClusterListCommandsTest extends ListCommandsTestBase { -// -// private final Logger logger = LoggerFactory.getLogger(getClass()); -// -// @BeforeClass -// public static void prepare() throws InterruptedException { -// jedis = ClusterCommandsTestHelper.initAndGetCluster(); -// } -// -// @AfterClass -// public static void closeCluster() { -// jedis.close(); -// } -// -// @AfterClass -// public static void resetCluster() { -// ClusterCommandsTestHelper.tearClusterDown(); -// } -// -// @Before -// public void setUp() { -// ClusterCommandsTestHelper.clearClusterData(); -// } -// -// @Test -// @Override -// public void rpoplpush() { -// jedis.rpush("foo{|}", "a"); -// jedis.rpush("foo{|}", "b"); -// jedis.rpush("foo{|}", "c"); -// -// jedis.rpush("dst{|}", "foo"); -// jedis.rpush("dst{|}", "bar"); -// -// String element = jedis.rpoplpush("foo{|}", "dst{|}"); -// -// assertEquals("c", element); -// -// List srcExpected = new ArrayList<>(); -// srcExpected.add("a"); -// srcExpected.add("b"); -// -// List dstExpected = new ArrayList<>(); -// dstExpected.add("c"); -// dstExpected.add("foo"); -// dstExpected.add("bar"); -// -// assertEquals(srcExpected, jedis.lrange("foo{|}", 0, 1000)); -// assertEquals(dstExpected, jedis.lrange("dst{|}", 0, 1000)); -// } -// -// @Test -// @Override -// public void blpop() throws InterruptedException { -// List result = jedis.blpop(1, "foo"); -// assertNull(result); -// -// jedis.lpush("foo", "bar"); -// result = jedis.blpop(1, "foo"); -// -// assertNotNull(result); -// assertEquals(2, result.size()); -// assertEquals("foo", result.get(0)); -// assertEquals("bar", result.get(1)); -// -// // Multi keys -// result = jedis.blpop(1, "{foo}", "{foo}1"); -// assertNull(result); -// -// jedis.lpush("{foo}", "bar"); -// jedis.lpush("{foo}1", "bar1"); -// result = jedis.blpop(1, "{foo}1", "{foo}"); -// -// assertNotNull(result); -// assertEquals(2, result.size()); -// assertEquals("{foo}1", result.get(0)); -// assertEquals("bar1", result.get(1)); -// -// // Binary -// jedis.lpush(bfoo, bbar); -// List bresult = jedis.blpop(1, bfoo); -// -// assertNotNull(bresult); -// assertEquals(2, bresult.size()); -// assertArrayEquals(bfoo, bresult.get(0)); -// assertArrayEquals(bbar, bresult.get(1)); -// } -// -// @Test -// @Override -// public void blpopDouble() throws InterruptedException { -// KeyedListElement result = jedis.blpop(0.1, "foo"); -// assertNull(result); -// -// jedis.lpush("foo", "bar"); -// result = jedis.blpop(3.2, "foo"); -// -// assertNotNull(result); -// assertEquals("foo", result.getKey()); -// assertEquals("bar", result.getElement()); -// -// // Multi keys -// result = jedis.blpop(0.18, "{foo}", "{foo}1"); -// assertNull(result); -// -// jedis.lpush("{foo}", "bar"); -// jedis.lpush("{foo}1", "bar1"); -// result = jedis.blpop(1d, "{foo}1", "{foo}"); -// -// assertNotNull(result); -// assertEquals("{foo}1", result.getKey()); -// assertEquals("bar1", result.getElement()); -// -// // Binary -// jedis.lpush(bfoo, bbar); -// List bresult = jedis.blpop(3.12, bfoo); -// -// assertNotNull(bresult); -// assertEquals(2, bresult.size()); -// assertArrayEquals(bfoo, bresult.get(0)); -// assertArrayEquals(bbar, bresult.get(1)); -// } -// -// @Test -// @Override -// public void brpop() throws InterruptedException { -// List result = jedis.brpop(1, "foo"); -// assertNull(result); -// -// jedis.lpush("foo", "bar"); -// result = jedis.brpop(1, "foo"); -// assertNotNull(result); -// assertEquals(2, result.size()); -// assertEquals("foo", result.get(0)); -// assertEquals("bar", result.get(1)); -// -// // Multi keys -// result = jedis.brpop(1, "{foo}", "{foo}1"); -// assertNull(result); -// -// jedis.lpush("{foo}", "bar"); -// jedis.lpush("{foo}1", "bar1"); -// result = jedis.brpop(1, "{foo}1", "{foo}"); -// -// assertNotNull(result); -// assertEquals(2, result.size()); -// assertEquals("{foo}1", result.get(0)); -// assertEquals("bar1", result.get(1)); -// -// // Binary -// jedis.lpush(bfoo, bbar); -// List bresult = jedis.brpop(1, bfoo); -// assertNotNull(bresult); -// assertEquals(2, bresult.size()); -// assertArrayEquals(bfoo, bresult.get(0)); -// assertArrayEquals(bbar, bresult.get(1)); -// } -// -// @Test -// @Override -// public void brpopDouble() throws InterruptedException { -// KeyedListElement result = jedis.brpop(0.1, "foo"); -// assertNull(result); -// -// jedis.lpush("foo", "bar"); -// result = jedis.brpop(3.2, "foo"); -// -// assertNotNull(result); -// assertEquals("foo", result.getKey()); -// assertEquals("bar", result.getElement()); -// -// // Multi keys -// result = jedis.brpop(0.18, "{foo}", "{foo}1"); -// assertNull(result); -// -// jedis.lpush("{foo}", "bar"); -// jedis.lpush("{foo}1", "bar1"); -// result = jedis.brpop(1d, "{foo}1", "{foo}"); -// -// assertNotNull(result); -// assertEquals("{foo}1", result.getKey()); -// assertEquals("bar1", result.getElement()); -// -// // Binary -// jedis.lpush(bfoo, bbar); -// List bresult = jedis.brpop(3.12, bfoo); -// -// assertNotNull(bresult); -// assertEquals(2, bresult.size()); -// assertArrayEquals(bfoo, bresult.get(0)); -// assertArrayEquals(bbar, bresult.get(1)); -// } -// -// @Test -// @Override -// public void brpoplpush() { -// -// new Thread(new Runnable() { -// @Override -// public void run() { -// try { -// Thread.sleep(100); -// } catch (InterruptedException e) { -// logger.error("", e); -// } -// jedis.lpush("foo{|}", "a"); -// } -// }).start(); -// -// String element = jedis.brpoplpush("foo{|}", "bar{|}", 0); -// -// assertEquals("a", element); -// assertEquals(1, jedis.llen("bar{|}")); -// assertEquals("a", jedis.lrange("bar{|}", 0, -1).get(0)); -// } -// -// @Test -// @Override -// public void lmove() { -// jedis.rpush("{|}foo", "bar1", "bar2", "bar3"); -// assertEquals("bar3", jedis.lmove("{|}foo", "{|}bar", ListDirection.RIGHT, ListDirection.LEFT)); -// assertEquals(Collections.singletonList("bar3"), jedis.lrange("{|}bar", 0, -1)); -// assertEquals(Arrays.asList("bar1", "bar2"), jedis.lrange("{|}foo", 0, -1)); -// } -// -// @Test -// @Override -// public void blmove() { -// new Thread(() -> { -// try { -// Thread.sleep(100); -// } catch (InterruptedException e) { -// logger.error("", e); -// } -// jedis.rpush("{|}foo", "bar1", "bar2", "bar3"); -// }).start(); -// -// assertEquals("bar3", jedis.blmove("{|}foo", "{|}bar", ListDirection.RIGHT, ListDirection.LEFT, 0)); -// assertEquals(Collections.singletonList("bar3"), jedis.lrange("{|}bar", 0, -1)); -// assertEquals(Arrays.asList("bar1", "bar2"), jedis.lrange("{|}foo", 0, -1)); -// } -//} +package redis.clients.jedis.commands.unified.cluster; + +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import redis.clients.jedis.args.ListDirection; +import redis.clients.jedis.commands.unified.ListCommandsTestBase; +import redis.clients.jedis.util.KeyValue; + +public class ClusterListCommandsTest extends ListCommandsTestBase { + + private final Logger logger = LoggerFactory.getLogger(getClass()); + + @Before + public void setUp() { + jedis = ClusterCommandsTestHelper.getCleanCluster(); + } + + @After + public void tearDown() { + jedis.close(); + ClusterCommandsTestHelper.clearClusterData(); + } + + @Test + @Override + public void rpoplpush() { + jedis.rpush("foo{|}", "a"); + jedis.rpush("foo{|}", "b"); + jedis.rpush("foo{|}", "c"); + + jedis.rpush("dst{|}", "foo"); + jedis.rpush("dst{|}", "bar"); + + String element = jedis.rpoplpush("foo{|}", "dst{|}"); + + assertEquals("c", element); + + List srcExpected = new ArrayList<>(); + srcExpected.add("a"); + srcExpected.add("b"); + + List dstExpected = new ArrayList<>(); + dstExpected.add("c"); + dstExpected.add("foo"); + dstExpected.add("bar"); + + assertEquals(srcExpected, jedis.lrange("foo{|}", 0, 1000)); + assertEquals(dstExpected, jedis.lrange("dst{|}", 0, 1000)); + } + + @Test + @Override + public void blpop() throws InterruptedException { + List result = jedis.blpop(1, "foo"); + assertNull(result); + + jedis.lpush("foo", "bar"); + result = jedis.blpop(1, "foo"); + + assertNotNull(result); + assertEquals(2, result.size()); + assertEquals("foo", result.get(0)); + assertEquals("bar", result.get(1)); + + // Multi keys + result = jedis.blpop(1, "{foo}", "{foo}1"); + assertNull(result); + + jedis.lpush("{foo}", "bar"); + jedis.lpush("{foo}1", "bar1"); + result = jedis.blpop(1, "{foo}1", "{foo}"); + + assertNotNull(result); + assertEquals(2, result.size()); + assertEquals("{foo}1", result.get(0)); + assertEquals("bar1", result.get(1)); + + // Binary + jedis.lpush(bfoo, bbar); + List bresult = jedis.blpop(1, bfoo); + + assertNotNull(bresult); + assertEquals(2, bresult.size()); + assertArrayEquals(bfoo, bresult.get(0)); + assertArrayEquals(bbar, bresult.get(1)); + } + + @Test + @Override + public void blpopDouble() throws InterruptedException { + KeyValue result = jedis.blpop(0.1, "foo"); + assertNull(result); + + jedis.lpush("foo", "bar"); + result = jedis.blpop(3.2, "foo"); + + assertNotNull(result); + assertEquals("foo", result.getKey()); + assertEquals("bar", result.getValue()); + + // Multi keys + result = jedis.blpop(0.18, "{foo}", "{foo}1"); + assertNull(result); + + jedis.lpush("{foo}", "bar"); + jedis.lpush("{foo}1", "bar1"); + result = jedis.blpop(1d, "{foo}1", "{foo}"); + + assertNotNull(result); + assertEquals("{foo}1", result.getKey()); + assertEquals("bar1", result.getValue()); + + // Binary + jedis.lpush(bfoo, bbar); + KeyValue bresult = jedis.blpop(3.12, bfoo); + + assertNotNull(bresult); + assertArrayEquals(bfoo, bresult.getKey()); + assertArrayEquals(bbar, bresult.getValue()); + } + + @Test + @Override + public void brpop() throws InterruptedException { + List result = jedis.brpop(1, "foo"); + assertNull(result); + + jedis.lpush("foo", "bar"); + result = jedis.brpop(1, "foo"); + assertNotNull(result); + assertEquals(2, result.size()); + assertEquals("foo", result.get(0)); + assertEquals("bar", result.get(1)); + + // Multi keys + result = jedis.brpop(1, "{foo}", "{foo}1"); + assertNull(result); + + jedis.lpush("{foo}", "bar"); + jedis.lpush("{foo}1", "bar1"); + result = jedis.brpop(1, "{foo}1", "{foo}"); + + assertNotNull(result); + assertEquals(2, result.size()); + assertEquals("{foo}1", result.get(0)); + assertEquals("bar1", result.get(1)); + + // Binary + jedis.lpush(bfoo, bbar); + List bresult = jedis.brpop(1, bfoo); + assertNotNull(bresult); + assertEquals(2, bresult.size()); + assertArrayEquals(bfoo, bresult.get(0)); + assertArrayEquals(bbar, bresult.get(1)); + } + + @Test + @Override + public void brpopDouble() throws InterruptedException { + KeyValue result = jedis.brpop(0.1, "foo"); + assertNull(result); + + jedis.lpush("foo", "bar"); + result = jedis.brpop(3.2, "foo"); + + assertNotNull(result); + assertEquals("foo", result.getKey()); + assertEquals("bar", result.getValue()); + + // Multi keys + result = jedis.brpop(0.18, "{foo}", "{foo}1"); + assertNull(result); + + jedis.lpush("{foo}", "bar"); + jedis.lpush("{foo}1", "bar1"); + result = jedis.brpop(1d, "{foo}1", "{foo}"); + + assertNotNull(result); + assertEquals("{foo}1", result.getKey()); + assertEquals("bar1", result.getValue()); + + // Binary + jedis.lpush(bfoo, bbar); + KeyValue bresult = jedis.brpop(3.12, bfoo); + + assertNotNull(bresult); + assertArrayEquals(bfoo, bresult.getKey()); + assertArrayEquals(bbar, bresult.getValue()); + } + + @Test + @Override + public void brpoplpush() { + + new Thread(new Runnable() { + @Override + public void run() { + try { + Thread.sleep(100); + } catch (InterruptedException e) { + logger.error("", e); + } + jedis.lpush("foo{|}", "a"); + } + }).start(); + + String element = jedis.brpoplpush("foo{|}", "bar{|}", 0); + + assertEquals("a", element); + assertEquals(1, jedis.llen("bar{|}")); + assertEquals("a", jedis.lrange("bar{|}", 0, -1).get(0)); + } + + @Test + @Override + public void lmove() { + jedis.rpush("{|}foo", "bar1", "bar2", "bar3"); + assertEquals("bar3", jedis.lmove("{|}foo", "{|}bar", ListDirection.RIGHT, ListDirection.LEFT)); + assertEquals(Collections.singletonList("bar3"), jedis.lrange("{|}bar", 0, -1)); + assertEquals(Arrays.asList("bar1", "bar2"), jedis.lrange("{|}foo", 0, -1)); + } + + @Test + @Override + public void blmove() { + new Thread(() -> { + try { + Thread.sleep(100); + } catch (InterruptedException e) { + logger.error("", e); + } + jedis.rpush("{|}foo", "bar1", "bar2", "bar3"); + }).start(); + + assertEquals("bar3", jedis.blmove("{|}foo", "{|}bar", ListDirection.RIGHT, ListDirection.LEFT, 0)); + assertEquals(Collections.singletonList("bar3"), jedis.lrange("{|}bar", 0, -1)); + assertEquals(Arrays.asList("bar1", "bar2"), jedis.lrange("{|}foo", 0, -1)); + } + + @Test + public void lmpop() { + String mylist1 = "mylist1{.}"; + String mylist2 = "mylist2{.}"; + + // add elements to list + jedis.lpush(mylist1, "one", "two", "three", "four", "five"); + jedis.lpush(mylist2, "one", "two", "three", "four", "five"); + + KeyValue> elements = jedis.lmpop(ListDirection.LEFT, mylist1, mylist2); + assertEquals(mylist1, elements.getKey()); + assertEquals(1, elements.getValue().size()); + + elements = jedis.lmpop(ListDirection.LEFT, 5, mylist1, mylist2); + assertEquals(mylist1, elements.getKey()); + assertEquals(4, elements.getValue().size()); + + elements = jedis.lmpop(ListDirection.RIGHT, 100, mylist1, mylist2); + assertEquals(mylist2, elements.getKey()); + assertEquals(5, elements.getValue().size()); + + elements = jedis.lmpop(ListDirection.RIGHT, mylist1, mylist2); + assertNull(elements); + } + + @Test + public void blmpopSimple() { + String mylist1 = "mylist1{.}"; + String mylist2 = "mylist2{.}"; + + // add elements to list + jedis.lpush(mylist1, "one", "two", "three", "four", "five"); + jedis.lpush(mylist2, "one", "two", "three", "four", "five"); + + KeyValue> elements = jedis.blmpop(1L, ListDirection.LEFT, mylist1, mylist2); + assertEquals(mylist1, elements.getKey()); + assertEquals(1, elements.getValue().size()); + + elements = jedis.blmpop(1L, ListDirection.LEFT, 5, mylist1, mylist2); + assertEquals(mylist1, elements.getKey()); + assertEquals(4, elements.getValue().size()); + + elements = jedis.blmpop(1L, ListDirection.RIGHT, 100, mylist1, mylist2); + assertEquals(mylist2, elements.getKey()); + assertEquals(5, elements.getValue().size()); + + elements = jedis.blmpop(1L, ListDirection.RIGHT, mylist1, mylist2); + assertNull(elements); + } +} 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 80a21dedb84..cd0bc2234fd 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 @@ -1,175 +1,200 @@ -//package redis.clients.jedis.commands.unified.cluster; -// -//import static org.junit.Assert.assertEquals; -// -//import java.util.HashSet; -//import java.util.Set; -//import org.junit.AfterClass; -//import org.junit.Before; -//import org.junit.BeforeClass; -//import org.junit.Test; -//import redis.clients.jedis.commands.unified.SetCommandsTestBase; -// -//public class ClusterSetCommandsTest extends SetCommandsTestBase { -// -// @BeforeClass -// public static void prepare() throws InterruptedException { -// jedis = ClusterCommandsTestHelper.initAndGetCluster(); -// } -// -// @AfterClass -// public static void closeCluster() { -// jedis.close(); -// } -// -// @AfterClass -// public static void resetCluster() { -// ClusterCommandsTestHelper.tearClusterDown(); -// } -// -// @Before -// public void setUp() { -// ClusterCommandsTestHelper.clearClusterData(); -// } -// -// @Test -// @Override -// public void smove() { -// jedis.sadd("{.}foo", "a"); -// jedis.sadd("{.}foo", "b"); -// -// jedis.sadd("{.}bar", "c"); -// -// long status = jedis.smove("{.}foo", "{.}bar", "a"); -// assertEquals(status, 1); -// -// Set expectedSrc = new HashSet<>(); -// expectedSrc.add("b"); -// -// Set expectedDst = new HashSet<>(); -// expectedDst.add("c"); -// expectedDst.add("a"); -// -// assertEquals(expectedSrc, jedis.smembers("{.}foo")); -// assertEquals(expectedDst, jedis.smembers("{.}bar")); -// -// status = jedis.smove("{.}foo", "{.}bar", "a"); -// assertEquals(status, 0); -// } -// -// @Test -// @Override -// public void sinter() { -// jedis.sadd("foo{.}", "a"); -// jedis.sadd("foo{.}", "b"); -// -// jedis.sadd("bar{.}", "b"); -// jedis.sadd("bar{.}", "c"); -// -// Set expected = new HashSet<>(); -// expected.add("b"); -// -// Set intersection = jedis.sinter("foo{.}", "bar{.}"); -// assertEquals(expected, intersection); -// } -// -// @Test -// @Override -// public void sinterstore() { -// jedis.sadd("foo{.}", "a"); -// jedis.sadd("foo{.}", "b"); -// -// jedis.sadd("bar{.}", "b"); -// jedis.sadd("bar{.}", "c"); -// -// Set expected = new HashSet<>(); -// expected.add("b"); -// -// long status = jedis.sinterstore("car{.}", "foo{.}", "bar{.}"); -// assertEquals(1, status); -// -// assertEquals(expected, jedis.smembers("car{.}")); -// } -// -// @Test -// @Override -// public void sunion() { -// jedis.sadd("{.}foo", "a"); -// jedis.sadd("{.}foo", "b"); -// -// jedis.sadd("{.}bar", "b"); -// jedis.sadd("{.}bar", "c"); -// -// Set expected = new HashSet<>(); -// expected.add("a"); -// expected.add("b"); -// expected.add("c"); -// -// Set union = jedis.sunion("{.}foo", "{.}bar"); -// assertEquals(expected, union); -// } -// -// @Test -// @Override -// public void sunionstore() { -// jedis.sadd("{.}foo", "a"); -// jedis.sadd("{.}foo", "b"); -// -// jedis.sadd("{.}bar", "b"); -// jedis.sadd("{.}bar", "c"); -// -// Set expected = new HashSet<>(); -// expected.add("a"); -// expected.add("b"); -// expected.add("c"); -// -// long status = jedis.sunionstore("{.}car", "{.}foo", "{.}bar"); -// assertEquals(3, status); -// -// assertEquals(expected, jedis.smembers("{.}car")); -// } -// -// @Test -// @Override -// public void sdiff() { -// jedis.sadd("foo{.}", "x"); -// jedis.sadd("foo{.}", "a"); -// jedis.sadd("foo{.}", "b"); -// jedis.sadd("foo{.}", "c"); -// -// jedis.sadd("bar{.}", "c"); -// -// jedis.sadd("car{.}", "a"); -// jedis.sadd("car{.}", "d"); -// -// Set expected = new HashSet<>(); -// expected.add("x"); -// expected.add("b"); -// -// Set diff = jedis.sdiff("foo{.}", "bar{.}", "car{.}"); -// assertEquals(expected, diff); -// } -// -// @Test -// @Override -// public void sdiffstore() { -// jedis.sadd("foo{.}", "x"); -// jedis.sadd("foo{.}", "a"); -// jedis.sadd("foo{.}", "b"); -// jedis.sadd("foo{.}", "c"); -// -// jedis.sadd("bar{.}", "c"); -// -// jedis.sadd("car{.}", "a"); -// jedis.sadd("car{.}", "d"); -// -// Set expected = new HashSet<>(); -// expected.add("x"); -// expected.add("b"); -// -// long status = jedis.sdiffstore("tar{.}", "foo{.}", "bar{.}", "car{.}"); -// assertEquals(2, status); -// assertEquals(expected, jedis.smembers("tar{.}")); -// } -// -//} +package redis.clients.jedis.commands.unified.cluster; + +import static org.junit.Assert.assertEquals; + +import java.util.HashSet; +import java.util.Set; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import redis.clients.jedis.commands.unified.SetCommandsTestBase; + +public class ClusterSetCommandsTest extends SetCommandsTestBase { + + final byte[] bfoo = { 0x01, 0x02, 0x03, 0x04 }; + final byte[] bfoo_same_hashslot = { 0x01, 0x02, 0x03, 0x04, 0x03, 0x00, 0x03, 0x1b }; + final byte[] ba = { 0x0A }; + final byte[] bb = { 0x0B }; + final byte[] bc = { 0x0C }; + + @Before + public void setUp() { + jedis = ClusterCommandsTestHelper.getCleanCluster(); + } + + @After + public void tearDown() { + jedis.close(); + ClusterCommandsTestHelper.clearClusterData(); + } + + @Test + @Override + public void smove() { + jedis.sadd("{.}foo", "a"); + jedis.sadd("{.}foo", "b"); + + jedis.sadd("{.}bar", "c"); + + long status = jedis.smove("{.}foo", "{.}bar", "a"); + assertEquals(status, 1); + + Set expectedSrc = new HashSet<>(); + expectedSrc.add("b"); + + Set expectedDst = new HashSet<>(); + expectedDst.add("c"); + expectedDst.add("a"); + + assertEquals(expectedSrc, jedis.smembers("{.}foo")); + assertEquals(expectedDst, jedis.smembers("{.}bar")); + + status = jedis.smove("{.}foo", "{.}bar", "a"); + assertEquals(status, 0); + } + + @Test + @Override + public void sinter() { + jedis.sadd("foo{.}", "a"); + jedis.sadd("foo{.}", "b"); + + jedis.sadd("bar{.}", "b"); + jedis.sadd("bar{.}", "c"); + + Set expected = new HashSet<>(); + expected.add("b"); + + Set intersection = jedis.sinter("foo{.}", "bar{.}"); + assertEquals(expected, intersection); + } + + @Test + @Override + public void sinterstore() { + jedis.sadd("foo{.}", "a"); + jedis.sadd("foo{.}", "b"); + + jedis.sadd("bar{.}", "b"); + jedis.sadd("bar{.}", "c"); + + Set expected = new HashSet<>(); + expected.add("b"); + + long status = jedis.sinterstore("car{.}", "foo{.}", "bar{.}"); + assertEquals(1, status); + + assertEquals(expected, jedis.smembers("car{.}")); + } + + @Test + @Override + public void sunion() { + jedis.sadd("{.}foo", "a"); + jedis.sadd("{.}foo", "b"); + + jedis.sadd("{.}bar", "b"); + jedis.sadd("{.}bar", "c"); + + Set expected = new HashSet<>(); + expected.add("a"); + expected.add("b"); + expected.add("c"); + + Set union = jedis.sunion("{.}foo", "{.}bar"); + assertEquals(expected, union); + } + + @Test + @Override + public void sunionstore() { + jedis.sadd("{.}foo", "a"); + jedis.sadd("{.}foo", "b"); + + jedis.sadd("{.}bar", "b"); + jedis.sadd("{.}bar", "c"); + + Set expected = new HashSet<>(); + expected.add("a"); + expected.add("b"); + expected.add("c"); + + long status = jedis.sunionstore("{.}car", "{.}foo", "{.}bar"); + assertEquals(3, status); + + assertEquals(expected, jedis.smembers("{.}car")); + } + + @Test + @Override + public void sdiff() { + jedis.sadd("foo{.}", "x"); + jedis.sadd("foo{.}", "a"); + jedis.sadd("foo{.}", "b"); + jedis.sadd("foo{.}", "c"); + + jedis.sadd("bar{.}", "c"); + + jedis.sadd("car{.}", "a"); + jedis.sadd("car{.}", "d"); + + Set expected = new HashSet<>(); + expected.add("x"); + expected.add("b"); + + Set diff = jedis.sdiff("foo{.}", "bar{.}", "car{.}"); + assertEquals(expected, diff); + } + + @Test + @Override + public void sdiffstore() { + jedis.sadd("foo{.}", "x"); + jedis.sadd("foo{.}", "a"); + jedis.sadd("foo{.}", "b"); + jedis.sadd("foo{.}", "c"); + + jedis.sadd("bar{.}", "c"); + + jedis.sadd("car{.}", "a"); + jedis.sadd("car{.}", "d"); + + Set expected = new HashSet<>(); + expected.add("x"); + expected.add("b"); + + long status = jedis.sdiffstore("tar{.}", "foo{.}", "bar{.}", "car{.}"); + assertEquals(2, status); + assertEquals(expected, jedis.smembers("tar{.}")); + } + + @Test + public void sintercard() { + jedis.sadd("foo{.}", "a"); + jedis.sadd("foo{.}", "b"); + + jedis.sadd("bar{.}", "a"); + jedis.sadd("bar{.}", "b"); + jedis.sadd("bar{.}", "c"); + + long card = jedis.sintercard("foo{.}", "bar{.}"); + assertEquals(2, card); + long limitedCard = jedis.sintercard(1, "foo{.}", "bar{.}"); + assertEquals(1, limitedCard); + + // Binary + jedis.sadd(bfoo, ba); + jedis.sadd(bfoo, bb); + + jedis.sadd(bfoo_same_hashslot, ba); + jedis.sadd(bfoo_same_hashslot, bb); + jedis.sadd(bfoo_same_hashslot, bc); + + long bcard = jedis.sintercard(bfoo, bfoo_same_hashslot); + assertEquals(2, bcard); + long blimitedCard = jedis.sintercard(1, bfoo, bfoo_same_hashslot); + assertEquals(1, blimitedCard); + } + +} 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 589c7359598..84748693f38 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 @@ -1,190 +1,243 @@ -//package redis.clients.jedis.commands.unified.cluster; -// -//import static org.junit.Assert.assertEquals; -// -//import java.util.ArrayList; -//import java.util.Collections; -//import java.util.LinkedHashSet; -//import java.util.List; -//import java.util.Set; -// -//import org.junit.AfterClass; -//import org.junit.Before; -//import org.junit.BeforeClass; -//import org.junit.Test; -// -//import redis.clients.jedis.params.ZAddParams; -//import redis.clients.jedis.params.ZParams; -//import redis.clients.jedis.resps.KeyedZSetElement; -//import redis.clients.jedis.resps.Tuple; -//import redis.clients.jedis.commands.unified.SortedSetCommandsTestBase; -// -//public class ClusterSortedSetCommandsTest extends SortedSetCommandsTestBase { -// -// @BeforeClass -// public static void prepare() throws InterruptedException { -// jedis = ClusterCommandsTestHelper.initAndGetCluster(); -// } -// -// @AfterClass -// public static void closeCluster() { -// jedis.close(); -// } -// -// @AfterClass -// public static void resetCluster() { -// ClusterCommandsTestHelper.tearClusterDown(); -// } -// -// @Before -// public void setUp() { -// ClusterCommandsTestHelper.clearClusterData(); -// } -// -// @Test -// @Override -// public void zunion() { -// jedis.zadd("{:}foo", 1, "a"); -// jedis.zadd("{:}foo", 2, "b"); -// jedis.zadd("{:}bar", 2, "a"); -// jedis.zadd("{:}bar", 2, "b"); -// -// ZParams params = new ZParams(); -// params.weights(2, 2.5); -// params.aggregate(ZParams.Aggregate.SUM); -// Set expected = new LinkedHashSet<>(); -// expected.add("a"); -// expected.add("b"); -// assertEquals(expected, jedis.zunion(params, "{:}foo", "{:}bar")); -// -// Set expectedTuple = new LinkedHashSet<>(); -// expectedTuple.add(new Tuple("b", new Double(9))); -// expectedTuple.add(new Tuple("a", new Double(7))); -// assertEquals(expectedTuple, jedis.zunionWithScores(params, "{:}foo", "{:}bar")); -// } -// -// @Test -// @Override -// public void zunionstore() { -// jedis.zadd("{:}foo", 1, "a"); -// jedis.zadd("{:}foo", 2, "b"); -// jedis.zadd("{:}bar", 2, "a"); -// jedis.zadd("{:}bar", 2, "b"); -// -// assertEquals(2, jedis.zunionstore("{:}dst", "{:}foo", "{:}bar")); -// -// List expected = new ArrayList<>(); -// expected.add(new Tuple("a", new Double(3))); -// expected.add(new Tuple("b", new Double(4))); -// assertEquals(expected, jedis.zrangeWithScores("{:}dst", 0, 100)); -// } -// -// @Test -// @Override -// public void zunionstoreParams() { -// jedis.zadd("{:}foo", 1, "a"); -// jedis.zadd("{:}foo", 2, "b"); -// jedis.zadd("{:}bar", 2, "a"); -// jedis.zadd("{:}bar", 2, "b"); -// -// ZParams params = new ZParams(); -// params.weights(2, 2.5); -// params.aggregate(ZParams.Aggregate.SUM); -// -// assertEquals(2, jedis.zunionstore("{:}dst", params, "{:}foo", "{:}bar")); -// -// List expected = new ArrayList<>(); -// expected.add(new Tuple("a", new Double(7))); -// expected.add(new Tuple("b", new Double(9))); -// assertEquals(expected, jedis.zrangeWithScores("{:}dst", 0, 100)); -// } -// -// @Test -// @Override -// public void zinter() { -// jedis.zadd("foo{:}", 1, "a"); -// jedis.zadd("foo{:}", 2, "b"); -// jedis.zadd("bar{:}", 2, "a"); -// -// ZParams params = new ZParams(); -// params.weights(2, 2.5); -// params.aggregate(ZParams.Aggregate.SUM); -// assertEquals(Collections.singleton("a"), jedis.zinter(params, "foo{:}", "bar{:}")); -// -// assertEquals(Collections.singleton(new Tuple("a", new Double(7))), -// jedis.zinterWithScores(params, "foo{:}", "bar{:}")); -// } -// -// @Test -// @Override -// public void zinterstore() { -// jedis.zadd("foo{:}", 1, "a"); -// jedis.zadd("foo{:}", 2, "b"); -// jedis.zadd("bar{:}", 2, "a"); -// -// assertEquals(1, jedis.zinterstore("dst{:}", "foo{:}", "bar{:}")); -// -// assertEquals(Collections.singletonList(new Tuple("a", new Double(3))), -// jedis.zrangeWithScores("dst{:}", 0, 100)); -// } -// -// @Test -// @Override -// public void zintertoreParams() { -// jedis.zadd("foo{:}", 1, "a"); -// jedis.zadd("foo{:}", 2, "b"); -// jedis.zadd("bar{:}", 2, "a"); -// -// ZParams params = new ZParams(); -// params.weights(2, 2.5); -// params.aggregate(ZParams.Aggregate.SUM); -// -// assertEquals(1, jedis.zinterstore("dst{:}", params, "foo{:}", "bar{:}")); -// -// assertEquals(Collections.singletonList(new Tuple("a", new Double(7))), -// jedis.zrangeWithScores("dst{:}", 0, 100)); -// } -// -// @Test -// @Override -// public void bzpopmax() { -// jedis.zadd("f{:}oo", 1d, "a", ZAddParams.zAddParams().nx()); -// jedis.zadd("f{:}oo", 10d, "b", ZAddParams.zAddParams().nx()); -// jedis.zadd("b{:}ar", 0.1d, "c", ZAddParams.zAddParams().nx()); -// assertEquals(new KeyedZSetElement("f{:}oo", "b", 10d), jedis.bzpopmax(0, "f{:}oo", "b{:}ar")); -// } -// -// @Test -// @Override -// public void bzpopmin() { -// jedis.zadd("fo{:}o", 1d, "a", ZAddParams.zAddParams().nx()); -// jedis.zadd("fo{:}o", 10d, "b", ZAddParams.zAddParams().nx()); -// jedis.zadd("ba{:}r", 0.1d, "c", ZAddParams.zAddParams().nx()); -// assertEquals(new KeyedZSetElement("ba{:}r", "c", 0.1d), jedis.bzpopmin(0, "ba{:}r", "fo{:}o")); -// } -// -// @Test -// @Override -// public void zdiff() { -// jedis.zadd("{:}foo", 1.0, "a"); -// jedis.zadd("{:}foo", 2.0, "b"); -// jedis.zadd("{:}bar", 1.0, "a"); -// -// assertEquals(0, jedis.zdiff("{bar}1", "{bar}2").size()); -// assertEquals(Collections.singleton("b"), jedis.zdiff("{:}foo", "{:}bar")); -// assertEquals(Collections.singleton(new Tuple("b", 2.0d)), jedis.zdiffWithScores("{:}foo", "{:}bar")); -// } -// -// @Test -// @Override -// public void zdiffstore() { -// jedis.zadd("foo{:}", 1.0, "a"); -// jedis.zadd("foo{:}", 2.0, "b"); -// jedis.zadd("bar{:}", 1.0, "a"); -// -// assertEquals(0, jedis.zdiffstore("{bar}3", "{bar}1", "{bar}2")); -// assertEquals(1, jedis.zdiffstore("bar{:}3", "foo{:}", "bar{:}")); -// assertEquals(Collections.singletonList("b"), jedis.zrange("bar{:}3", 0, -1)); -// } -// -//} +package redis.clients.jedis.commands.unified.cluster; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.containsInAnyOrder; +import static org.junit.Assert.assertEquals; +import static redis.clients.jedis.util.AssertUtil.assertByteArrayListEquals; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import redis.clients.jedis.commands.unified.SortedSetCommandsTestBase; +import redis.clients.jedis.params.ZAddParams; +import redis.clients.jedis.params.ZParams; +import redis.clients.jedis.params.ZRangeParams; +import redis.clients.jedis.resps.Tuple; +import redis.clients.jedis.util.KeyValue; + +public class ClusterSortedSetCommandsTest extends SortedSetCommandsTestBase { + + final byte[] bfoo = { 0x01, 0x02, 0x03, 0x04 }; + final byte[] bfoo_same_hashslot = { 0x01, 0x02, 0x03, 0x04, 0x03, 0x00, 0x03, 0x1b }; + final byte[] ba = { 0x0A }; + final byte[] bb = { 0x0B }; + final byte[] bc = { 0x0C }; + + @Before + public void setUp() { + jedis = ClusterCommandsTestHelper.getCleanCluster(); + } + + @After + public void tearDown() { + jedis.close(); + ClusterCommandsTestHelper.clearClusterData(); + } + + @Test + @Override + public void zunion() { + jedis.zadd("{:}foo", 1, "a"); + jedis.zadd("{:}foo", 2, "b"); + jedis.zadd("{:}bar", 2, "a"); + jedis.zadd("{:}bar", 2, "b"); + + ZParams params = new ZParams(); + params.weights(2, 2.5); + params.aggregate(ZParams.Aggregate.SUM); + + assertThat(jedis.zunion(params, "{:}foo", "{:}bar"), + containsInAnyOrder("a", "b")); + + assertThat(jedis.zunionWithScores(params, "{:}foo", "{:}bar"), + containsInAnyOrder( + new Tuple("b", new Double(9)), + new Tuple("a", new Double(7)) + )); + } + + @Test + @Override + public void zunionstore() { + jedis.zadd("{:}foo", 1, "a"); + jedis.zadd("{:}foo", 2, "b"); + jedis.zadd("{:}bar", 2, "a"); + jedis.zadd("{:}bar", 2, "b"); + + assertEquals(2, jedis.zunionstore("{:}dst", "{:}foo", "{:}bar")); + + List expected = new ArrayList<>(); + expected.add(new Tuple("a", new Double(3))); + expected.add(new Tuple("b", new Double(4))); + assertEquals(expected, jedis.zrangeWithScores("{:}dst", 0, 100)); + } + + @Test + @Override + public void zunionstoreParams() { + jedis.zadd("{:}foo", 1, "a"); + jedis.zadd("{:}foo", 2, "b"); + jedis.zadd("{:}bar", 2, "a"); + jedis.zadd("{:}bar", 2, "b"); + + ZParams params = new ZParams(); + params.weights(2, 2.5); + params.aggregate(ZParams.Aggregate.SUM); + + assertEquals(2, jedis.zunionstore("{:}dst", params, "{:}foo", "{:}bar")); + + List expected = new ArrayList<>(); + expected.add(new Tuple("a", new Double(7))); + expected.add(new Tuple("b", new Double(9))); + assertEquals(expected, jedis.zrangeWithScores("{:}dst", 0, 100)); + } + + @Test + @Override + public void zinter() { + jedis.zadd("foo{:}", 1, "a"); + jedis.zadd("foo{:}", 2, "b"); + jedis.zadd("bar{:}", 2, "a"); + + ZParams params = new ZParams(); + params.weights(2, 2.5); + params.aggregate(ZParams.Aggregate.SUM); + assertThat(jedis.zinter(params, "foo{:}", "bar{:}"), + containsInAnyOrder("a")); + + assertThat(jedis.zinterWithScores(params, "foo{:}", "bar{:}"), + containsInAnyOrder(new Tuple("a", new Double(7)))); + } + + @Test + @Override + public void zinterstore() { + jedis.zadd("foo{:}", 1, "a"); + jedis.zadd("foo{:}", 2, "b"); + jedis.zadd("bar{:}", 2, "a"); + + assertEquals(1, jedis.zinterstore("dst{:}", "foo{:}", "bar{:}")); + + assertEquals(Collections.singletonList(new Tuple("a", new Double(3))), + jedis.zrangeWithScores("dst{:}", 0, 100)); + } + + @Test + @Override + public void zintertoreParams() { + jedis.zadd("foo{:}", 1, "a"); + jedis.zadd("foo{:}", 2, "b"); + jedis.zadd("bar{:}", 2, "a"); + + ZParams params = new ZParams(); + params.weights(2, 2.5); + params.aggregate(ZParams.Aggregate.SUM); + + assertEquals(1, jedis.zinterstore("dst{:}", params, "foo{:}", "bar{:}")); + + assertEquals(Collections.singletonList(new Tuple("a", new Double(7))), + jedis.zrangeWithScores("dst{:}", 0, 100)); + } + + @Test + @Override + public void bzpopmax() { + jedis.zadd("f{:}oo", 1d, "a", ZAddParams.zAddParams().nx()); + jedis.zadd("f{:}oo", 10d, "b", ZAddParams.zAddParams().nx()); + jedis.zadd("b{:}ar", 0.1d, "c", ZAddParams.zAddParams().nx()); + assertEquals(new KeyValue<>("f{:}oo", new Tuple("b", 10d)), jedis.bzpopmax(0, "f{:}oo", "b{:}ar")); + } + + @Test + @Override + public void bzpopmin() { + jedis.zadd("fo{:}o", 1d, "a", ZAddParams.zAddParams().nx()); + jedis.zadd("fo{:}o", 10d, "b", ZAddParams.zAddParams().nx()); + jedis.zadd("ba{:}r", 0.1d, "c", ZAddParams.zAddParams().nx()); + assertEquals(new KeyValue<>("ba{:}r", new Tuple("c", 0.1d)), jedis.bzpopmin(0, "ba{:}r", "fo{:}o")); + } + + @Test + @Override + public void zdiff() { + jedis.zadd("{:}foo", 1.0, "a"); + jedis.zadd("{:}foo", 2.0, "b"); + jedis.zadd("{:}bar", 1.0, "a"); + + assertEquals(0, jedis.zdiff("{bar}1", "{bar}2").size()); + + assertThat(jedis.zdiff("{:}foo", "{:}bar"), + containsInAnyOrder("b")); + + assertThat(jedis.zdiffWithScores("{:}foo", "{:}bar"), + containsInAnyOrder(new Tuple("b", 2.0d))); + } + + @Test + @Override + public void zdiffstore() { + jedis.zadd("foo{:}", 1.0, "a"); + jedis.zadd("foo{:}", 2.0, "b"); + jedis.zadd("bar{:}", 1.0, "a"); + + assertEquals(0, jedis.zdiffstore("{bar}3", "{bar}1", "{bar}2")); + assertEquals(1, jedis.zdiffstore("bar{:}3", "foo{:}", "bar{:}")); + assertEquals(Collections.singletonList("b"), jedis.zrange("bar{:}3", 0, -1)); + } + + @Test + public void zrangestore() { + jedis.zadd("foo{.}", 1, "aa"); + jedis.zadd("foo{.}", 2, "c"); + jedis.zadd("foo{.}", 3, "bb"); + + long stored = jedis.zrangestore("bar{.}", "foo{.}", ZRangeParams.zrangeByScoreParams(1, 2)); + assertEquals(2, stored); + + List range = jedis.zrange("bar{.}", 0, -1); + List expected = new ArrayList<>(); + expected.add("aa"); + expected.add("c"); + assertEquals(expected, range); + + // Binary + jedis.zadd(bfoo, 1d, ba); + jedis.zadd(bfoo, 10d, bb); + jedis.zadd(bfoo, 0.1d, bc); + jedis.zadd(bfoo, 2d, ba); + + long bstored = jedis.zrangestore(bfoo_same_hashslot, bfoo, ZRangeParams.zrangeParams(0, 1).rev()); + assertEquals(2, bstored); + + List brange = jedis.zrevrange(bfoo_same_hashslot, 0, 1); + List bexpected = new ArrayList<>(); + bexpected.add(bb); + bexpected.add(ba); + assertByteArrayListEquals(bexpected, brange); + } + + @Test + public void zintercard() { + jedis.zadd("foo{.}", 1, "a"); + jedis.zadd("foo{.}", 2, "b"); + jedis.zadd("bar{.}", 2, "a"); + jedis.zadd("bar{.}", 1, "b"); + + assertEquals(2, jedis.zintercard("foo{.}", "bar{.}")); + assertEquals(1, jedis.zintercard(1, "foo{.}", "bar{.}")); + + // Binary + jedis.zadd(bfoo, 1, ba); + jedis.zadd(bfoo, 2, bb); + jedis.zadd(bfoo_same_hashslot, 2, ba); + jedis.zadd(bfoo_same_hashslot, 2, bb); + + assertEquals(2, jedis.zintercard(bfoo, bfoo_same_hashslot)); + assertEquals(1, jedis.zintercard(1, bfoo, bfoo_same_hashslot)); + } + +} 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 1df7b892c64..c7b743f5e44 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 @@ -1,85 +1,96 @@ -//package redis.clients.jedis.commands.unified.cluster; -// -//import static org.junit.Assert.assertEquals; -// -//import java.util.ArrayList; -//import java.util.List; -//import org.junit.AfterClass; -//import org.junit.Before; -//import org.junit.BeforeClass; -//import org.junit.Test; -//import redis.clients.jedis.commands.unified.StringValuesCommandsTestBase; -// -//public class ClusterStringValuesCommandsTest extends StringValuesCommandsTestBase { -// -// @BeforeClass -// public static void prepare() throws InterruptedException { -// jedis = ClusterCommandsTestHelper.initAndGetCluster(); -// } -// -// @AfterClass -// public static void closeCluster() { -// jedis.close(); -// } -// -// @AfterClass -// public static void resetCluster() { -// ClusterCommandsTestHelper.tearClusterDown(); -// } -// -// @Before -// public void setUp() { -// ClusterCommandsTestHelper.clearClusterData(); -// } -// -// @Test -// @Override -// public void mget() { -// List values = jedis.mget("foo{^}", "bar{^}"); -// List expected = new ArrayList<>(); -// expected.add(null); -// expected.add(null); -// -// assertEquals(expected, values); -// -// jedis.set("foo{^}", "bar"); -// -// expected = new ArrayList<>(); -// expected.add("bar"); -// expected.add(null); -// values = jedis.mget("foo{^}", "bar{^}"); -// -// assertEquals(expected, values); -// -// jedis.set("bar{^}", "foo"); -// -// expected = new ArrayList<>(); -// expected.add("bar"); -// expected.add("foo"); -// values = jedis.mget("foo{^}", "bar{^}"); -// -// assertEquals(expected, values); -// } -// -// @Test -// @Override -// public void mset() { -// String status = jedis.mset("{^}foo", "bar", "{^}bar", "foo"); -// assertEquals("OK", status); -// assertEquals("bar", jedis.get("{^}foo")); -// assertEquals("foo", jedis.get("{^}bar")); -// } -// -// @Test -// @Override -// public void msetnx() { -// assertEquals(1, jedis.msetnx("{^}foo", "bar", "{^}bar", "foo")); -// assertEquals("bar", jedis.get("{^}foo")); -// assertEquals("foo", jedis.get("{^}bar")); -// -// assertEquals(0, jedis.msetnx("{^}foo", "bar1", "{^}bar2", "foo2")); -// assertEquals("bar", jedis.get("{^}foo")); -// assertEquals("foo", jedis.get("{^}bar")); -// } -// -//} +package redis.clients.jedis.commands.unified.cluster; + +import static org.junit.Assert.assertEquals; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import redis.clients.jedis.commands.unified.StringValuesCommandsTestBase; +import redis.clients.jedis.params.LCSParams; +import redis.clients.jedis.resps.LCSMatchResult; + +public class ClusterStringValuesCommandsTest extends StringValuesCommandsTestBase { + + @Before + public void setUp() { + jedis = ClusterCommandsTestHelper.getCleanCluster(); + } + + @After + public void tearDown() { + jedis.close(); + ClusterCommandsTestHelper.clearClusterData(); + } + + @Test + @Override + public void mget() { + List values = jedis.mget("foo{^}", "bar{^}"); + List expected = new ArrayList<>(); + expected.add(null); + expected.add(null); + + assertEquals(expected, values); + + jedis.set("foo{^}", "bar"); + + expected = new ArrayList<>(); + expected.add("bar"); + expected.add(null); + values = jedis.mget("foo{^}", "bar{^}"); + + assertEquals(expected, values); + + jedis.set("bar{^}", "foo"); + + expected = new ArrayList<>(); + expected.add("bar"); + expected.add("foo"); + values = jedis.mget("foo{^}", "bar{^}"); + + assertEquals(expected, values); + } + + @Test + @Override + public void mset() { + String status = jedis.mset("{^}foo", "bar", "{^}bar", "foo"); + assertEquals("OK", status); + assertEquals("bar", jedis.get("{^}foo")); + assertEquals("foo", jedis.get("{^}bar")); + } + + @Test + @Override + public void msetnx() { + assertEquals(1, jedis.msetnx("{^}foo", "bar", "{^}bar", "foo")); + assertEquals("bar", jedis.get("{^}foo")); + assertEquals("foo", jedis.get("{^}bar")); + + assertEquals(0, jedis.msetnx("{^}foo", "bar1", "{^}bar2", "foo2")); + assertEquals("bar", jedis.get("{^}foo")); + assertEquals("foo", jedis.get("{^}bar")); + } + + @Test + public void lcs() { + jedis.mset("key1{.}", "ohmytext", "key2{.}", "mynewtext"); + + LCSMatchResult stringMatchResult = jedis.lcs("key1{.}", "key2{.}", + LCSParams.LCSParams()); + assertEquals("mytext", stringMatchResult.getMatchString()); + + stringMatchResult = jedis.lcs("key1{.}", "key2{.}", + LCSParams.LCSParams().idx().withMatchLen()); + assertEquals(stringMatchResult.getLen(), 6); + assertEquals(2, stringMatchResult.getMatches().size()); + + stringMatchResult = jedis.lcs("key1{.}", "key2{.}", + LCSParams.LCSParams().idx().minMatchLen(10)); + assertEquals(0, stringMatchResult.getMatches().size()); + } + +} From 7096d74a127ffa53892c9d4316413387d4e7fa4a Mon Sep 17 00:00:00 2001 From: Gabriel Erzse Date: Wed, 13 Mar 2024 13:45:31 +0200 Subject: [PATCH 13/33] Geo pipelined tests (#3767) --- .../pipeline/GeoPipelineCommandsTest.java | 901 ++++++++++++++++++ .../jedis/util/GeoCoordinateMatcher.java | 34 + 2 files changed, 935 insertions(+) create mode 100644 src/test/java/redis/clients/jedis/commands/unified/pipeline/GeoPipelineCommandsTest.java create mode 100644 src/test/java/redis/clients/jedis/util/GeoCoordinateMatcher.java 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 new file mode 100644 index 00000000000..cbab082b7e8 --- /dev/null +++ b/src/test/java/redis/clients/jedis/commands/unified/pipeline/GeoPipelineCommandsTest.java @@ -0,0 +1,901 @@ +package redis.clients.jedis.commands.unified.pipeline; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.anyOf; +import static org.hamcrest.Matchers.closeTo; +import static org.hamcrest.Matchers.contains; +import static org.hamcrest.Matchers.containsInAnyOrder; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.instanceOf; +import static org.hamcrest.Matchers.nullValue; +import static org.junit.Assert.assertEquals; +import static redis.clients.jedis.util.GeoCoordinateMatcher.atCoordinates; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; +import redis.clients.jedis.GeoCoordinate; +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; +import redis.clients.jedis.params.GeoRadiusStoreParam; +import redis.clients.jedis.params.GeoSearchParam; +import redis.clients.jedis.resps.GeoRadiusResponse; +import redis.clients.jedis.util.SafeEncoder; + +public class GeoPipelineCommandsTest extends PipelineCommandsTestBase { + + protected final byte[] bfoo = { 0x01, 0x02, 0x03, 0x04 }; + protected final byte[] bA = { 0x0A }; + protected final byte[] bB = { 0x0B }; + protected final byte[] bC = { 0x0C }; + protected final byte[] bNotexist = { 0x0F }; + + private static final double EPSILON = 1e-5; + + @BeforeClass + public static void prepare() throws InterruptedException { + jedis = PooledCommandsTestHelper.getPooled(); + } + + @AfterClass + public static void cleanUp() { + jedis.close(); + } + + @Test + public void geoadd() { + pipe.geoadd("foo", 1, 2, "a"); + pipe.geoadd("foo", 2, 3, "a"); + + Map coordinateMap = new HashMap<>(); + coordinateMap.put("a", new GeoCoordinate(3, 4)); + coordinateMap.put("b", new GeoCoordinate(2, 3)); + coordinateMap.put("c", new GeoCoordinate(3.314, 2.3241)); + + pipe.geoadd("foo", coordinateMap); + + // binary + pipe.geoadd(bfoo, 1, 2, bA); + pipe.geoadd(bfoo, 2, 3, bA); + + Map bcoordinateMap = new HashMap<>(); + bcoordinateMap.put(bA, new GeoCoordinate(3, 4)); + bcoordinateMap.put(bB, new GeoCoordinate(2, 3)); + bcoordinateMap.put(bC, new GeoCoordinate(3.314, 2.3241)); + + pipe.geoadd(bfoo, bcoordinateMap); + + assertThat(pipe.syncAndReturnAll(), contains( + 1L, + 0L, + 2L, + 1L, + 0L, + 2L + )); + } + + @Test + public void geoaddWithParams() { + pipe.geoadd("foo", 1, 2, "a"); + + Map coordinateMap = new HashMap<>(); + coordinateMap.put("a", new GeoCoordinate(3, 4)); + pipe.geoadd("foo", GeoAddParams.geoAddParams().nx(), coordinateMap); + pipe.geoadd("foo", GeoAddParams.geoAddParams().xx().ch(), coordinateMap); + + coordinateMap.clear(); + coordinateMap.put("b", new GeoCoordinate(6, 7)); + // never add elements. + pipe.geoadd("foo", GeoAddParams.geoAddParams().xx(), coordinateMap); + pipe.geoadd("foo", GeoAddParams.geoAddParams().nx(), coordinateMap); + + // binary + pipe.geoadd(bfoo, 1, 2, bA); + + Map bcoordinateMap = new HashMap<>(); + bcoordinateMap.put(bA, new GeoCoordinate(3, 4)); + pipe.geoadd(bfoo, GeoAddParams.geoAddParams().nx(), bcoordinateMap); + pipe.geoadd(bfoo, GeoAddParams.geoAddParams().xx().ch(), bcoordinateMap); + + bcoordinateMap.clear(); + bcoordinateMap.put(bB, new GeoCoordinate(6, 7)); + // never add elements. + pipe.geoadd(bfoo, GeoAddParams.geoAddParams().xx(), bcoordinateMap); + pipe.geoadd(bfoo, GeoAddParams.geoAddParams().nx(), bcoordinateMap); + + assertThat(pipe.syncAndReturnAll(), contains( + 1L, + 0L, + 1L, + 0L, + 1L, + 1L, + 0L, + 1L, + 0L, + 1L + )); + } + + @Test + public void geodist() { + prepareGeoData(); + + Response dist1 = pipe.geodist("foo", "a", "b"); + Response dist2 = pipe.geodist("foo", "a", "b", GeoUnit.KM); + Response dist3 = pipe.geodist("foo", "a", "b", GeoUnit.MI); + Response dist4 = pipe.geodist("foo", "a", "b", GeoUnit.FT); + + // binary + Response dist5 = pipe.geodist(bfoo, bA, bB); + Response dist6 = pipe.geodist(bfoo, bA, bB, GeoUnit.KM); + Response dist7 = pipe.geodist(bfoo, bA, bB, GeoUnit.MI); + Response dist8 = pipe.geodist(bfoo, bA, bB, GeoUnit.FT); + + pipe.sync(); + + assertThat(dist1.get(), closeTo(157149.0, 1.0)); + assertThat(dist2.get(), closeTo(157.0, 1.0)); + assertThat(dist3.get(), closeTo(97.0, 1.0)); + assertThat(dist4.get(), closeTo(515583.0, 1.0)); + assertThat(dist5.get(), closeTo(157149.0, 1.0)); + assertThat(dist6.get(), closeTo(157.0, 1.0)); + assertThat(dist7.get(), closeTo(97.0, 1.0)); + assertThat(dist8.get(), closeTo(515583.0, 1.0)); + } + + @Test + public void geohash() { + prepareGeoData(); + + Response> hashes = pipe.geohash("foo", "a", "b", "notexist"); + Response> bhashes = pipe.geohash(bfoo, bA, bB, bNotexist); + + pipe.sync(); + + assertThat(hashes.get(), contains( + "s0dnu20t9j0", + "s093jd0k720", + null + )); + + assertThat(bhashes.get(), contains( + SafeEncoder.encode("s0dnu20t9j0"), + SafeEncoder.encode("s093jd0k720"), + null + )); + } + + @Test + public void geopos() { + prepareGeoData(); + + Response> coordinates = pipe.geopos("foo", "a", "b", "notexist"); + Response> bcoordinates = pipe.geopos(bfoo, bA, bB, bNotexist); + + pipe.sync(); + + assertThat(coordinates.get(), contains( + atCoordinates(3.0, 4.0), + atCoordinates(2.0, 3.0), + null + )); + + assertThat(bcoordinates.get(), contains( + atCoordinates(3.0, 4.0), + atCoordinates(2.0, 3.0), + null + )); + } + + @Test + public void georadius() { + // prepare data + Map coordinateMap = new HashMap<>(); + coordinateMap.put("Palermo", new GeoCoordinate(13.361389, 38.115556)); + coordinateMap.put("Catania", new GeoCoordinate(15.087269, 37.502669)); + jedis.geoadd("Sicily", coordinateMap); + + Response> members1 = pipe.georadius("Sicily", 15, 37, 200, GeoUnit.KM); + + // sort + Response> members2 = pipe.georadius("Sicily", 15, 37, 200, + GeoUnit.KM, GeoRadiusParam.geoRadiusParam().sortDescending()); + + // sort, count 1 + Response> members3 = pipe.georadius("Sicily", 15, 37, 200, + GeoUnit.KM, GeoRadiusParam.geoRadiusParam().sortAscending().count(1)); + + // sort, count 1, withdist, withcoord + Response> members4 = pipe.georadius("Sicily", 15, 37, 200, + GeoUnit.KM, GeoRadiusParam.geoRadiusParam().sortAscending().count(1).withCoord().withDist().withHash()); + + // sort, count 1, with hash + Response> members5 = pipe.georadius("Sicily", 15, 37, 200, + GeoUnit.KM, GeoRadiusParam.geoRadiusParam().sortAscending().count(1).withHash()); + + // sort, count 1, any + Response> members6 = pipe.georadius("Sicily", 15, 37, 200, + GeoUnit.KM, GeoRadiusParam.geoRadiusParam().sortDescending().count(1, true)); + + pipe.sync(); + + assertThat(members1.get().stream().map(GeoRadiusResponse::getMemberByString).collect(Collectors.toList()), + containsInAnyOrder("Palermo", "Catania")); + assertThat(members1.get().stream().map(GeoRadiusResponse::getDistance).collect(Collectors.toList()), + contains(closeTo(0.0, EPSILON), closeTo(0.0, EPSILON))); + assertThat(members1.get().stream().map(GeoRadiusResponse::getCoordinate).collect(Collectors.toList()), + contains(nullValue(), nullValue())); + assertThat(members1.get().stream().map(GeoRadiusResponse::getRawScore).collect(Collectors.toList()), + contains(0L, 0L)); + + assertThat(members2.get().stream().map(GeoRadiusResponse::getMemberByString).collect(Collectors.toList()), + contains("Palermo", "Catania")); + assertThat(members2.get().stream().map(GeoRadiusResponse::getDistance).collect(Collectors.toList()), + contains(closeTo(0.0, EPSILON), closeTo(0.0, EPSILON))); + assertThat(members2.get().stream().map(GeoRadiusResponse::getCoordinate).collect(Collectors.toList()), + contains(nullValue(), nullValue())); + assertThat(members2.get().stream().map(GeoRadiusResponse::getRawScore).collect(Collectors.toList()), + contains(0L, 0L)); + + assertThat(members3.get().stream().map(GeoRadiusResponse::getMemberByString).collect(Collectors.toList()), + contains("Catania")); + assertThat(members3.get().stream().map(GeoRadiusResponse::getDistance).collect(Collectors.toList()), + contains(closeTo(0.0, EPSILON))); + assertThat(members3.get().stream().map(GeoRadiusResponse::getCoordinate).collect(Collectors.toList()), + contains(nullValue())); + assertThat(members3.get().stream().map(GeoRadiusResponse::getRawScore).collect(Collectors.toList()), + contains(0L)); + + assertThat(members4.get().stream().map(GeoRadiusResponse::getMemberByString).collect(Collectors.toList()), + contains("Catania")); + assertThat(members4.get().stream().map(GeoRadiusResponse::getDistance).collect(Collectors.toList()), + contains(closeTo(56.4413, EPSILON))); + assertThat(members4.get().stream().map(GeoRadiusResponse::getCoordinate).collect(Collectors.toList()), + contains(atCoordinates(15.087269, 37.502669))); + assertThat(members4.get().stream().map(GeoRadiusResponse::getRawScore).collect(Collectors.toList()), + contains(3479447370796909L)); + + assertThat(members5.get().stream().map(GeoRadiusResponse::getMemberByString).collect(Collectors.toList()), + contains("Catania")); + assertThat(members5.get().stream().map(GeoRadiusResponse::getDistance).collect(Collectors.toList()), + contains(closeTo(0.0, EPSILON))); + assertThat(members5.get().stream().map(GeoRadiusResponse::getCoordinate).collect(Collectors.toList()), + contains(nullValue())); + assertThat(members5.get().stream().map(GeoRadiusResponse::getRawScore).collect(Collectors.toList()), + contains(3479447370796909L)); + + assertThat(members6.get().stream().map(GeoRadiusResponse::getMemberByString).collect(Collectors.toList()), + anyOf(contains("Catania"), contains("Palermo"))); + assertThat(members6.get().stream().map(GeoRadiusResponse::getDistance).collect(Collectors.toList()), + contains(closeTo(0.0, EPSILON))); + assertThat(members6.get().stream().map(GeoRadiusResponse::getCoordinate).collect(Collectors.toList()), + contains(nullValue())); + assertThat(members6.get().stream().map(GeoRadiusResponse::getRawScore).collect(Collectors.toList()), + contains(0L)); + } + + @Test + public void georadiusStore() { + // prepare data + Map coordinateMap = new HashMap<>(); + coordinateMap.put("Palermo", new GeoCoordinate(13.361389, 38.115556)); + coordinateMap.put("Catania", new GeoCoordinate(15.087269, 37.502669)); + jedis.geoadd("Sicily", coordinateMap); + + Response size = pipe.georadiusStore("Sicily", 15, 37, 200, GeoUnit.KM, + GeoRadiusParam.geoRadiusParam(), + GeoRadiusStoreParam.geoRadiusStoreParam().store("SicilyStore")); + + Response> items = pipe.zrange("SicilyStore", 0, -1); + + pipe.sync(); + + assertThat(size.get(), equalTo(2L)); + assertThat(items.get(), contains("Palermo", "Catania")); + } + + @Test + public void georadiusReadonly() { + // prepare data + Map coordinateMap = new HashMap<>(); + coordinateMap.put("Palermo", new GeoCoordinate(13.361389, 38.115556)); + coordinateMap.put("Catania", new GeoCoordinate(15.087269, 37.502669)); + jedis.geoadd("Sicily", coordinateMap); + + Response> members1 = pipe.georadiusReadonly("Sicily", 15, 37, 200, GeoUnit.KM); + + // sort + Response> members2 = pipe.georadiusReadonly("Sicily", 15, 37, 200, GeoUnit.KM, + GeoRadiusParam.geoRadiusParam().sortAscending()); + + // sort, count 1 + Response> members3 = pipe.georadiusReadonly("Sicily", 15, 37, 200, GeoUnit.KM, + GeoRadiusParam.geoRadiusParam().sortAscending().count(1)); + + // sort, count 1, withdist, withcoord + Response> members4 = pipe.georadiusReadonly("Sicily", 15, 37, 200, GeoUnit.KM, + GeoRadiusParam.geoRadiusParam().sortAscending().count(1).withCoord().withDist()); + + pipe.sync(); + + assertThat(members1.get().stream().map(GeoRadiusResponse::getMemberByString).collect(Collectors.toList()), + containsInAnyOrder("Palermo", "Catania")); + assertThat(members1.get().stream().map(GeoRadiusResponse::getDistance).collect(Collectors.toList()), + contains(closeTo(0.0, EPSILON), closeTo(0.0, EPSILON))); + assertThat(members1.get().stream().map(GeoRadiusResponse::getCoordinate).collect(Collectors.toList()), + contains(nullValue(), nullValue())); + assertThat(members1.get().stream().map(GeoRadiusResponse::getRawScore).collect(Collectors.toList()), + contains(0L, 0L)); + + assertThat(members2.get().stream().map(GeoRadiusResponse::getMemberByString).collect(Collectors.toList()), + contains("Catania", "Palermo")); + assertThat(members2.get().stream().map(GeoRadiusResponse::getDistance).collect(Collectors.toList()), + contains(closeTo(0.0, EPSILON), closeTo(0.0, EPSILON))); + assertThat(members2.get().stream().map(GeoRadiusResponse::getCoordinate).collect(Collectors.toList()), + contains(nullValue(), nullValue())); + assertThat(members2.get().stream().map(GeoRadiusResponse::getRawScore).collect(Collectors.toList()), + contains(0L, 0L)); + + assertThat(members3.get().stream().map(GeoRadiusResponse::getMemberByString).collect(Collectors.toList()), + contains("Catania")); + assertThat(members3.get().stream().map(GeoRadiusResponse::getDistance).collect(Collectors.toList()), + contains(closeTo(0.0, EPSILON))); + assertThat(members3.get().stream().map(GeoRadiusResponse::getCoordinate).collect(Collectors.toList()), + contains(nullValue())); + assertThat(members3.get().stream().map(GeoRadiusResponse::getRawScore).collect(Collectors.toList()), + contains(0L)); + + assertThat(members4.get().stream().map(GeoRadiusResponse::getMemberByString).collect(Collectors.toList()), + contains("Catania")); + assertThat(members4.get().stream().map(GeoRadiusResponse::getDistance).collect(Collectors.toList()), + contains(closeTo(56.4413, EPSILON))); + assertThat(members4.get().stream().map(GeoRadiusResponse::getCoordinate).collect(Collectors.toList()), + contains(atCoordinates(15.087269, 37.502669))); + assertThat(members4.get().stream().map(GeoRadiusResponse::getRawScore).collect(Collectors.toList()), + contains(0L)); + } + + @Test + public void georadiusBinary() { + // prepare data + Map bcoordinateMap = new HashMap<>(); + bcoordinateMap.put(bA, new GeoCoordinate(13.361389, 38.115556)); + bcoordinateMap.put(bB, new GeoCoordinate(15.087269, 37.502669)); + jedis.geoadd(bfoo, bcoordinateMap); + + Response> members1 = pipe.georadius(bfoo, 15, 37, 200, GeoUnit.KM); + + // sort + Response> members2 = pipe.georadius(bfoo, 15, 37, 200, GeoUnit.KM, + GeoRadiusParam.geoRadiusParam().sortAscending()); + + // sort, count 1 + Response> members3 = pipe.georadius(bfoo, 15, 37, 200, GeoUnit.KM, + GeoRadiusParam.geoRadiusParam().sortAscending().count(1)); + + // sort, count 1, withdist, withcoord + Response> members4 = pipe.georadius(bfoo, 15, 37, 200, GeoUnit.KM, + GeoRadiusParam.geoRadiusParam().sortAscending().count(1).withCoord().withDist()); + + pipe.sync(); + + assertThat(members1.get().stream().map(GeoRadiusResponse::getMember).collect(Collectors.toList()), + containsInAnyOrder(bA, bB)); + assertThat(members1.get().stream().map(GeoRadiusResponse::getDistance).collect(Collectors.toList()), + contains(closeTo(0.0, EPSILON), closeTo(0.0, EPSILON))); + assertThat(members1.get().stream().map(GeoRadiusResponse::getCoordinate).collect(Collectors.toList()), + contains(nullValue(), nullValue())); + assertThat(members1.get().stream().map(GeoRadiusResponse::getRawScore).collect(Collectors.toList()), + contains(0L, 0L)); + + assertThat(members2.get().stream().map(GeoRadiusResponse::getMember).collect(Collectors.toList()), + contains(bB, bA)); + assertThat(members2.get().stream().map(GeoRadiusResponse::getDistance).collect(Collectors.toList()), + contains(closeTo(0.0, EPSILON), closeTo(0.0, EPSILON))); + assertThat(members2.get().stream().map(GeoRadiusResponse::getCoordinate).collect(Collectors.toList()), + contains(nullValue(), nullValue())); + assertThat(members2.get().stream().map(GeoRadiusResponse::getRawScore).collect(Collectors.toList()), + contains(0L, 0L)); + + assertThat(members3.get().stream().map(GeoRadiusResponse::getMember).collect(Collectors.toList()), + contains(bB)); + assertThat(members3.get().stream().map(GeoRadiusResponse::getDistance).collect(Collectors.toList()), + contains(closeTo(0.0, EPSILON))); + assertThat(members3.get().stream().map(GeoRadiusResponse::getCoordinate).collect(Collectors.toList()), + contains(nullValue())); + assertThat(members3.get().stream().map(GeoRadiusResponse::getRawScore).collect(Collectors.toList()), + contains(0L)); + + assertThat(members4.get().stream().map(GeoRadiusResponse::getMember).collect(Collectors.toList()), + contains(bB)); + assertThat(members4.get().stream().map(GeoRadiusResponse::getDistance).collect(Collectors.toList()), + contains(closeTo(56.4413, EPSILON))); + assertThat(members4.get().stream().map(GeoRadiusResponse::getCoordinate).collect(Collectors.toList()), + contains(atCoordinates(15.087269, 37.502669))); + assertThat(members4.get().stream().map(GeoRadiusResponse::getRawScore).collect(Collectors.toList()), + contains(0L)); + } + + @Test + public void georadiusStoreBinary() { + // prepare data + Map bcoordinateMap = new HashMap<>(); + bcoordinateMap.put(bA, new GeoCoordinate(13.361389, 38.115556)); + bcoordinateMap.put(bB, new GeoCoordinate(15.087269, 37.502669)); + jedis.geoadd(bfoo, bcoordinateMap); + + Response size = pipe.georadiusStore(bfoo, 15, 37, 200, GeoUnit.KM, + GeoRadiusParam.geoRadiusParam(), + GeoRadiusStoreParam.geoRadiusStoreParam().store("SicilyStore")); + + Response> items = pipe.zrange("SicilyStore".getBytes(), 0, -1); + + pipe.sync(); + + assertThat(size.get(), equalTo(2L)); + assertThat(items.get(), contains(bA, bB)); + } + + @Test + public void georadiusReadonlyBinary() { + // prepare data + Map bcoordinateMap = new HashMap<>(); + bcoordinateMap.put(bA, new GeoCoordinate(13.361389, 38.115556)); + bcoordinateMap.put(bB, new GeoCoordinate(15.087269, 37.502669)); + jedis.geoadd(bfoo, bcoordinateMap); + + Response> members1 = pipe.georadiusReadonly(bfoo, 15, 37, 200, GeoUnit.KM); + + // sort + Response> members2 = pipe.georadiusReadonly(bfoo, 15, 37, 200, GeoUnit.KM, + GeoRadiusParam.geoRadiusParam().sortAscending()); + + // sort, count 1 + Response> members3 = pipe.georadiusReadonly(bfoo, 15, 37, 200, GeoUnit.KM, + GeoRadiusParam.geoRadiusParam().sortAscending().count(1)); + + // sort, count 1, withdist, withcoord + Response> members4 = pipe.georadiusReadonly(bfoo, 15, 37, 200, GeoUnit.KM, + GeoRadiusParam.geoRadiusParam().sortAscending().count(1).withCoord().withDist()); + + pipe.sync(); + + assertThat(members1.get().stream().map(GeoRadiusResponse::getMember).collect(Collectors.toList()), + containsInAnyOrder(bA, bB)); + assertThat(members1.get().stream().map(GeoRadiusResponse::getDistance).collect(Collectors.toList()), + contains(closeTo(0.0, EPSILON), closeTo(0.0, EPSILON))); + assertThat(members1.get().stream().map(GeoRadiusResponse::getCoordinate).collect(Collectors.toList()), + contains(nullValue(), nullValue())); + assertThat(members1.get().stream().map(GeoRadiusResponse::getRawScore).collect(Collectors.toList()), + contains(0L, 0L)); + + assertThat(members2.get().stream().map(GeoRadiusResponse::getMember).collect(Collectors.toList()), + contains(bB, bA)); + assertThat(members2.get().stream().map(GeoRadiusResponse::getDistance).collect(Collectors.toList()), + contains(closeTo(0.0, EPSILON), closeTo(0.0, EPSILON))); + assertThat(members2.get().stream().map(GeoRadiusResponse::getCoordinate).collect(Collectors.toList()), + contains(nullValue(), nullValue())); + assertThat(members2.get().stream().map(GeoRadiusResponse::getRawScore).collect(Collectors.toList()), + contains(0L, 0L)); + + assertThat(members3.get().stream().map(GeoRadiusResponse::getMember).collect(Collectors.toList()), + contains(bB)); + assertThat(members3.get().stream().map(GeoRadiusResponse::getDistance).collect(Collectors.toList()), + contains(closeTo(0.0, EPSILON))); + assertThat(members3.get().stream().map(GeoRadiusResponse::getCoordinate).collect(Collectors.toList()), + contains(nullValue())); + assertThat(members3.get().stream().map(GeoRadiusResponse::getRawScore).collect(Collectors.toList()), + contains(0L)); + + assertThat(members4.get().stream().map(GeoRadiusResponse::getMember).collect(Collectors.toList()), + contains(bB)); + assertThat(members4.get().stream().map(GeoRadiusResponse::getDistance).collect(Collectors.toList()), + contains(closeTo(56.4413, EPSILON))); + assertThat(members4.get().stream().map(GeoRadiusResponse::getCoordinate).collect(Collectors.toList()), + contains(atCoordinates(15.087269, 37.502669))); + assertThat(members4.get().stream().map(GeoRadiusResponse::getRawScore).collect(Collectors.toList()), + contains(0L)); + } + + @Test + public void georadiusByMember() { + jedis.geoadd("Sicily", 13.583333, 37.316667, "Agrigento"); + jedis.geoadd("Sicily", 13.361389, 38.115556, "Palermo"); + jedis.geoadd("Sicily", 15.087269, 37.502669, "Catania"); + + Response> members1 = pipe.georadiusByMember("Sicily", "Agrigento", 100, + GeoUnit.KM); + + Response> members2 = pipe.georadiusByMember("Sicily", "Agrigento", 100, GeoUnit.KM, + GeoRadiusParam.geoRadiusParam().sortAscending()); + + Response> members3 = pipe.georadiusByMember("Sicily", "Agrigento", 100, GeoUnit.KM, + GeoRadiusParam.geoRadiusParam().sortAscending().count(1).withCoord().withDist()); + + pipe.sync(); + + assertThat(members1.get().stream().map(GeoRadiusResponse::getMemberByString).collect(Collectors.toList()), + containsInAnyOrder("Agrigento", "Palermo")); + assertThat(members1.get().stream().map(GeoRadiusResponse::getDistance).collect(Collectors.toList()), + contains(closeTo(0.0, EPSILON), closeTo(0.0, EPSILON))); + assertThat(members1.get().stream().map(GeoRadiusResponse::getCoordinate).collect(Collectors.toList()), + contains(nullValue(), nullValue())); + assertThat(members1.get().stream().map(GeoRadiusResponse::getRawScore).collect(Collectors.toList()), + contains(0L, 0L)); + + assertThat(members2.get().stream().map(GeoRadiusResponse::getMemberByString).collect(Collectors.toList()), + contains("Agrigento", "Palermo")); + assertThat(members2.get().stream().map(GeoRadiusResponse::getDistance).collect(Collectors.toList()), + contains(closeTo(0.0, EPSILON), closeTo(0.0, EPSILON))); + assertThat(members2.get().stream().map(GeoRadiusResponse::getCoordinate).collect(Collectors.toList()), + contains(nullValue(), nullValue())); + assertThat(members2.get().stream().map(GeoRadiusResponse::getRawScore).collect(Collectors.toList()), + contains(0L, 0L)); + + assertThat(members3.get().stream().map(GeoRadiusResponse::getMemberByString).collect(Collectors.toList()), + contains("Agrigento")); + assertThat(members3.get().stream().map(GeoRadiusResponse::getDistance).collect(Collectors.toList()), + contains(closeTo(0.0, EPSILON))); + assertThat(members3.get().stream().map(GeoRadiusResponse::getCoordinate).collect(Collectors.toList()), + contains(atCoordinates(13.583333, 37.316667))); + assertThat(members3.get().stream().map(GeoRadiusResponse::getRawScore).collect(Collectors.toList()), + contains(0L)); + } + + @Test + public void georadiusByMemberStore() { + jedis.geoadd("Sicily", 13.583333, 37.316667, "Agrigento"); + jedis.geoadd("Sicily", 13.361389, 38.115556, "Palermo"); + jedis.geoadd("Sicily", 15.087269, 37.502669, "Catania"); + + Response size = pipe.georadiusByMemberStore("Sicily", "Agrigento", 100, GeoUnit.KM, + GeoRadiusParam.geoRadiusParam(), + GeoRadiusStoreParam.geoRadiusStoreParam().store("SicilyStore")); + + Response> items = pipe.zrange("SicilyStore", 0, -1); + + pipe.sync(); + + assertThat(size.get(), equalTo(2L)); + assertThat(items.get(), contains("Agrigento", "Palermo")); + } + + @Test + public void georadiusByMemberReadonly() { + jedis.geoadd("Sicily", 13.583333, 37.316667, "Agrigento"); + jedis.geoadd("Sicily", 13.361389, 38.115556, "Palermo"); + jedis.geoadd("Sicily", 15.087269, 37.502669, "Catania"); + + Response> members1 = pipe.georadiusByMemberReadonly("Sicily", "Agrigento", 100, + GeoUnit.KM); + + Response> members2 = pipe.georadiusByMemberReadonly("Sicily", "Agrigento", 100, GeoUnit.KM, + GeoRadiusParam.geoRadiusParam().sortAscending()); + + Response> members3 = pipe.georadiusByMemberReadonly("Sicily", "Agrigento", 100, GeoUnit.KM, + GeoRadiusParam.geoRadiusParam().sortAscending().count(1).withCoord().withDist()); + + pipe.sync(); + + assertThat(members1.get().stream().map(GeoRadiusResponse::getMemberByString).collect(Collectors.toList()), + containsInAnyOrder("Agrigento", "Palermo")); + assertThat(members1.get().stream().map(GeoRadiusResponse::getDistance).collect(Collectors.toList()), + contains(closeTo(0.0, EPSILON), closeTo(0.0, EPSILON))); + assertThat(members1.get().stream().map(GeoRadiusResponse::getCoordinate).collect(Collectors.toList()), + contains(nullValue(), nullValue())); + assertThat(members1.get().stream().map(GeoRadiusResponse::getRawScore).collect(Collectors.toList()), + contains(0L, 0L)); + + assertThat(members2.get().stream().map(GeoRadiusResponse::getMemberByString).collect(Collectors.toList()), + contains("Agrigento", "Palermo")); + assertThat(members2.get().stream().map(GeoRadiusResponse::getDistance).collect(Collectors.toList()), + contains(closeTo(0.0, EPSILON), closeTo(0.0, EPSILON))); + assertThat(members2.get().stream().map(GeoRadiusResponse::getCoordinate).collect(Collectors.toList()), + contains(nullValue(), nullValue())); + assertThat(members2.get().stream().map(GeoRadiusResponse::getRawScore).collect(Collectors.toList()), + contains(0L, 0L)); + + assertThat(members3.get().stream().map(GeoRadiusResponse::getMemberByString).collect(Collectors.toList()), + contains("Agrigento")); + assertThat(members3.get().stream().map(GeoRadiusResponse::getDistance).collect(Collectors.toList()), + contains(closeTo(0.0, EPSILON))); + assertThat(members3.get().stream().map(GeoRadiusResponse::getCoordinate).collect(Collectors.toList()), + contains(atCoordinates(13.583333, 37.316667))); + assertThat(members3.get().stream().map(GeoRadiusResponse::getRawScore).collect(Collectors.toList()), + contains(0L)); + } + + @Test + public void georadiusByMemberBinary() { + jedis.geoadd(bfoo, 13.583333, 37.316667, bA); + jedis.geoadd(bfoo, 13.361389, 38.115556, bB); + jedis.geoadd(bfoo, 15.087269, 37.502669, bC); + + Response> members1 = pipe.georadiusByMember(bfoo, bA, 100, GeoUnit.KM); + + Response> members2 = pipe.georadiusByMember(bfoo, bA, 100, GeoUnit.KM, + GeoRadiusParam.geoRadiusParam().sortAscending()); + + Response> members3 = pipe.georadiusByMember(bfoo, bA, 100, GeoUnit.KM, + GeoRadiusParam.geoRadiusParam().sortAscending().count(1).withCoord().withDist()); + + pipe.sync(); + + assertThat(members1.get().stream().map(GeoRadiusResponse::getMember).collect(Collectors.toList()), + containsInAnyOrder(bA, bB)); + assertThat(members1.get().stream().map(GeoRadiusResponse::getDistance).collect(Collectors.toList()), + contains(closeTo(0.0, EPSILON), closeTo(0.0, EPSILON))); + assertThat(members1.get().stream().map(GeoRadiusResponse::getCoordinate).collect(Collectors.toList()), + contains(nullValue(), nullValue())); + assertThat(members1.get().stream().map(GeoRadiusResponse::getRawScore).collect(Collectors.toList()), + contains(0L, 0L)); + + assertThat(members2.get().stream().map(GeoRadiusResponse::getMember).collect(Collectors.toList()), + contains(bA, bB)); + assertThat(members2.get().stream().map(GeoRadiusResponse::getDistance).collect(Collectors.toList()), + contains(closeTo(0.0, EPSILON), closeTo(0.0, EPSILON))); + assertThat(members2.get().stream().map(GeoRadiusResponse::getCoordinate).collect(Collectors.toList()), + contains(nullValue(), nullValue())); + assertThat(members2.get().stream().map(GeoRadiusResponse::getRawScore).collect(Collectors.toList()), + contains(0L, 0L)); + + assertThat(members3.get().stream().map(GeoRadiusResponse::getMember).collect(Collectors.toList()), + contains(bA)); + assertThat(members3.get().stream().map(GeoRadiusResponse::getDistance).collect(Collectors.toList()), + contains(closeTo(0.0, EPSILON))); + assertThat(members3.get().stream().map(GeoRadiusResponse::getCoordinate).collect(Collectors.toList()), + contains(atCoordinates(13.583333, 37.316667))); + assertThat(members3.get().stream().map(GeoRadiusResponse::getRawScore).collect(Collectors.toList()), + contains(0L)); + } + + @Test + public void georadiusByMemberStoreBinary() { + jedis.geoadd(bfoo, 13.583333, 37.316667, bA); + jedis.geoadd(bfoo, 13.361389, 38.115556, bB); + jedis.geoadd(bfoo, 15.087269, 37.502669, bC); + + Response size = pipe.georadiusByMemberStore(bfoo, bA, 100, GeoUnit.KM, + GeoRadiusParam.geoRadiusParam(), + GeoRadiusStoreParam.geoRadiusStoreParam().store("SicilyStore")); + + Response> items = pipe.zrange("SicilyStore".getBytes(), 0, -1); + + pipe.sync(); + + assertThat(size.get(), equalTo(2L)); + assertThat(items.get(), contains(bA, bB)); + } + + @Test + public void georadiusByMemberReadonlyBinary() { + jedis.geoadd(bfoo, 13.583333, 37.316667, bA); + jedis.geoadd(bfoo, 13.361389, 38.115556, bB); + jedis.geoadd(bfoo, 15.087269, 37.502669, bC); + + Response> members1 = pipe.georadiusByMemberReadonly(bfoo, bA, 100, GeoUnit.KM); + + Response> members2 = pipe.georadiusByMemberReadonly(bfoo, bA, 100, GeoUnit.KM, + GeoRadiusParam.geoRadiusParam().sortAscending()); + + Response> members3 = pipe.georadiusByMemberReadonly(bfoo, bA, 100, GeoUnit.KM, + GeoRadiusParam.geoRadiusParam().sortAscending().count(1).withCoord().withDist()); + + pipe.sync(); + + assertThat(members1.get().stream().map(GeoRadiusResponse::getMember).collect(Collectors.toList()), + containsInAnyOrder(bA, bB)); + assertThat(members1.get().stream().map(GeoRadiusResponse::getDistance).collect(Collectors.toList()), + contains(closeTo(0.0, EPSILON), closeTo(0.0, EPSILON))); + assertThat(members1.get().stream().map(GeoRadiusResponse::getCoordinate).collect(Collectors.toList()), + contains(nullValue(), nullValue())); + assertThat(members1.get().stream().map(GeoRadiusResponse::getRawScore).collect(Collectors.toList()), + contains(0L, 0L)); + + assertThat(members2.get().stream().map(GeoRadiusResponse::getMember).collect(Collectors.toList()), + contains(bA, bB)); + assertThat(members2.get().stream().map(GeoRadiusResponse::getDistance).collect(Collectors.toList()), + contains(closeTo(0.0, EPSILON), closeTo(0.0, EPSILON))); + assertThat(members2.get().stream().map(GeoRadiusResponse::getCoordinate).collect(Collectors.toList()), + contains(nullValue(), nullValue())); + assertThat(members2.get().stream().map(GeoRadiusResponse::getRawScore).collect(Collectors.toList()), + contains(0L, 0L)); + + assertThat(members3.get().stream().map(GeoRadiusResponse::getMember).collect(Collectors.toList()), + contains(bA)); + assertThat(members3.get().stream().map(GeoRadiusResponse::getDistance).collect(Collectors.toList()), + contains(closeTo(0.0, EPSILON))); + assertThat(members3.get().stream().map(GeoRadiusResponse::getCoordinate).collect(Collectors.toList()), + contains(atCoordinates(13.583333, 37.316667))); + assertThat(members3.get().stream().map(GeoRadiusResponse::getRawScore).collect(Collectors.toList()), + contains(0L)); + } + + @Test + public void geosearch() { + jedis.geoadd("barcelona", 2.1909389952632d, 41.433791470673d, "place1"); + jedis.geoadd("barcelona", 2.1873744593677d, 41.406342043777d, "place2"); + jedis.geoadd("barcelona", 2.583333d, 41.316667d, "place3"); + + // FROMLONLAT and BYRADIUS + Response> members1 = pipe.geosearch("barcelona", + new GeoCoordinate(2.191d, 41.433d), 1000, GeoUnit.M); + + // using Params + Response> members2 = pipe.geosearch("barcelona", new GeoSearchParam().byRadius(3000, GeoUnit.M) + .fromLonLat(2.191d, 41.433d).desc()); + + // FROMMEMBER and BYRADIUS + Response> members3 = pipe.geosearch("barcelona", "place3", 100, GeoUnit.KM); + + // using Params + Response> members4 = pipe.geosearch("barcelona", new GeoSearchParam().fromMember("place1") + .byRadius(100, GeoUnit.KM).withDist().withCoord().withHash().count(2)); + + // FROMMEMBER and BYBOX + Response> members5 = pipe.geosearch("barcelona", "place3", 100, 100, GeoUnit.KM); + + // using Params + Response> members6 = pipe.geosearch("barcelona", new GeoSearchParam().fromMember("place3") + .byBox(100, 100, GeoUnit.KM).asc().count(1, true)); + + // FROMLONLAT and BYBOX + Response> members7 = pipe.geosearch("barcelona", new GeoCoordinate(2.191, 41.433), + 1, 1, GeoUnit.KM); + + // using Params + Response> members8 = pipe.geosearch("barcelona", new GeoSearchParam().byBox(1, 1, GeoUnit.KM) + .fromLonLat(2.191, 41.433).withDist().withCoord()); + + pipe.sync(); + + assertThat(members1.get().stream().map(GeoRadiusResponse::getMemberByString).collect(Collectors.toList()), + contains("place1")); + assertThat(members1.get().stream().map(GeoRadiusResponse::getDistance).collect(Collectors.toList()), + contains(closeTo(0.0, EPSILON))); + assertThat(members1.get().stream().map(GeoRadiusResponse::getCoordinate).collect(Collectors.toList()), + contains(nullValue())); + assertThat(members1.get().stream().map(GeoRadiusResponse::getRawScore).collect(Collectors.toList()), + contains(0L)); + + assertThat(members2.get().stream().map(GeoRadiusResponse::getMemberByString).collect(Collectors.toList()), + contains("place2", "place1")); + + assertThat(members3.get().stream().map(GeoRadiusResponse::getMemberByString).collect(Collectors.toList()), + contains("place2", "place1", "place3")); + + assertThat(members4.get().stream().map(GeoRadiusResponse::getMemberByString).collect(Collectors.toList()), + contains("place1", "place2")); + assertThat(members4.get().stream().map(GeoRadiusResponse::getDistance).collect(Collectors.toList()), + contains(closeTo(0.0, EPSILON), closeTo(3.0674, EPSILON))); + assertThat(members4.get().stream().map(GeoRadiusResponse::getCoordinate).collect(Collectors.toList()), + contains(atCoordinates(2.1909389952632d, 41.433791470673d), atCoordinates(2.1873744593677d, 41.406342043777d))); + assertThat(members4.get().stream().map(GeoRadiusResponse::getRawScore).collect(Collectors.toList()), + contains(3471609698139488L, 3471609625421029L)); + + assertThat(members5.get().stream().map(GeoRadiusResponse::getMemberByString).collect(Collectors.toList()), + contains("place2", "place1", "place3")); + + assertThat(members6.get().stream().map(GeoRadiusResponse::getMemberByString).collect(Collectors.toList()), + contains("place2")); + + assertThat(members7.get().stream().map(GeoRadiusResponse::getMemberByString).collect(Collectors.toList()), + contains("place1")); + + assertThat(members8.get().stream().map(GeoRadiusResponse::getMemberByString).collect(Collectors.toList()), + contains("place1")); + assertThat(members8.get().stream().map(GeoRadiusResponse::getDistance).collect(Collectors.toList()), + contains(closeTo(0.0881, EPSILON))); + assertThat(members8.get().stream().map(GeoRadiusResponse::getCoordinate).collect(Collectors.toList()), + contains(atCoordinates(2.1909389952632d, 41.433791470673d))); + assertThat(members8.get().stream().map(GeoRadiusResponse::getRawScore).collect(Collectors.toList()), + contains(0L)); + } + + @Test + public void geosearchNegative() { + // combine byradius and bybox + pipe.geosearch("barcelona", + new GeoSearchParam().byRadius(3000, GeoUnit.M).byBox(300, 300, GeoUnit.M)); + + // without frommember and without fromlonlat + pipe.geosearch("barcelona", + new GeoSearchParam().byRadius(10, GeoUnit.MI)); + + assertThat(pipe.syncAndReturnAll(), contains( + instanceOf(JedisDataException.class), + instanceOf(JedisDataException.class) + )); + } + + @Test(expected = IllegalArgumentException.class) + public void geosearchSearchParamWithoutRadiousAndWithoutBox() { + pipe.geosearch("barcelona", + new GeoSearchParam().fromMember("foobar")); + } + + @Test(expected = IllegalArgumentException.class) + public void geosearchSearchParamCombineMemberAndLonLat() { + pipe.geosearch("barcelona", + new GeoSearchParam().fromMember("foobar").fromLonLat(10, 10)); + } + + @Test + public void geosearchstore() { + jedis.geoadd("barcelona", 2.1909389952632d, 41.433791470673d, "place1"); + jedis.geoadd("barcelona", 2.1873744593677d, 41.406342043777d, "place2"); + jedis.geoadd("barcelona", 2.583333d, 41.316667d, "place3"); + + // FROMLONLAT and BYRADIUS + Response membersCount1 = pipe.geosearchStore("tel-aviv", "barcelona", + new GeoCoordinate(2.191d, 41.433d), 1000, GeoUnit.M); + + Response> members1 = pipe.zrange("tel-aviv", 0, -1); + + Response membersCount2 = pipe.geosearchStore("tel-aviv", "barcelona", new GeoSearchParam() + .byRadius(3000, GeoUnit.M) + .fromLonLat(new GeoCoordinate(2.191d, 41.433d))); + + // FROMMEMBER and BYRADIUS + Response membersCount3 = pipe.geosearchStore("tel-aviv", "barcelona", "place3", 100, GeoUnit.KM); + + // FROMMEMBER and BYBOX + Response membersCount4 = pipe.geosearchStore("tel-aviv", "barcelona", "place3", 100, 100, GeoUnit.KM); + + // FROMLONLAT and BYBOX + Response membersCount5 = pipe.geosearchStore("tel-aviv", "barcelona", + new GeoCoordinate(2.191, 41.433), 1, 1, GeoUnit.KM); + + pipe.sync(); + + assertThat(membersCount1.get(), equalTo(1L)); + assertThat(members1.get(), contains("place1")); + assertThat(membersCount2.get(), equalTo(2L)); + assertThat(membersCount3.get(), equalTo(3L)); + assertThat(membersCount4.get(), equalTo(3L)); + assertThat(membersCount5.get(), equalTo(1L)); + } + + @Test + public void geosearchstoreWithdist() { + jedis.geoadd("barcelona", 2.1909389952632d, 41.433791470673d, "place1"); + jedis.geoadd("barcelona", 2.1873744593677d, 41.406342043777d, "place2"); + + Response members = pipe.geosearchStoreStoreDist("tel-aviv", "barcelona", + new GeoSearchParam().byRadius(3000, GeoUnit.M).fromLonLat(2.191d, 41.433d)); + + Response score = pipe.zscore("tel-aviv", "place1"); + + pipe.sync(); + + assertThat(members.get(), equalTo(2L)); + assertThat(score.get(), closeTo(88.05060698409301, 5)); + } + + private void prepareGeoData() { + Map coordinateMap = new HashMap<>(); + coordinateMap.put("a", new GeoCoordinate(3, 4)); + coordinateMap.put("b", new GeoCoordinate(2, 3)); + coordinateMap.put("c", new GeoCoordinate(3.314, 2.3241)); + + assertEquals(3, jedis.geoadd("foo", coordinateMap)); + + Map bcoordinateMap = new HashMap<>(); + bcoordinateMap.put(bA, new GeoCoordinate(3, 4)); + bcoordinateMap.put(bB, new GeoCoordinate(2, 3)); + bcoordinateMap.put(bC, new GeoCoordinate(3.314, 2.3241)); + + assertEquals(3, jedis.geoadd(bfoo, bcoordinateMap)); + } +} diff --git a/src/test/java/redis/clients/jedis/util/GeoCoordinateMatcher.java b/src/test/java/redis/clients/jedis/util/GeoCoordinateMatcher.java new file mode 100644 index 00000000000..5b21d3d427d --- /dev/null +++ b/src/test/java/redis/clients/jedis/util/GeoCoordinateMatcher.java @@ -0,0 +1,34 @@ +package redis.clients.jedis.util; + +import org.hamcrest.Description; +import org.hamcrest.TypeSafeMatcher; +import redis.clients.jedis.GeoCoordinate; + +public class GeoCoordinateMatcher extends TypeSafeMatcher { + + public static GeoCoordinateMatcher atCoordinates(double longitude, double latitude) { + return new GeoCoordinateMatcher(longitude, latitude); + } + + private static final double EPSILON = 1e-5; + + private final double longitude; + private final double latitude; + + public GeoCoordinateMatcher(double longitude, double latitude) { + this.longitude = longitude; + this.latitude = latitude; + } + + @Override + protected boolean matchesSafely(GeoCoordinate item) { + return item != null && + Math.abs(longitude - item.getLongitude()) < EPSILON && + Math.abs(latitude - item.getLatitude()) < EPSILON; + } + + @Override + public void describeTo(Description description) { + description.appendText("matches " + longitude + " longitude " + latitude + " latitude with precision " + EPSILON); + } +} From f7699b19420bc2171c35359ba975e2a211e1a728 Mon Sep 17 00:00:00 2001 From: Gabriel Erzse Date: Wed, 13 Mar 2024 16:04:07 +0200 Subject: [PATCH 14/33] Add pipelined tests for sorted sets (#3771) Co-authored-by: Gabriel Erzse --- .../SortedSetPipelineCommandsTest.java | 1891 +++++++++++++++++ 1 file changed, 1891 insertions(+) create mode 100644 src/test/java/redis/clients/jedis/commands/unified/pipeline/SortedSetPipelineCommandsTest.java 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 new file mode 100644 index 00000000000..12a2282e277 --- /dev/null +++ b/src/test/java/redis/clients/jedis/commands/unified/pipeline/SortedSetPipelineCommandsTest.java @@ -0,0 +1,1891 @@ +package redis.clients.jedis.commands.unified.pipeline; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.closeTo; +import static org.hamcrest.Matchers.contains; +import static org.hamcrest.Matchers.containsInAnyOrder; +import static org.hamcrest.Matchers.empty; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.hasSize; +import static org.hamcrest.Matchers.in; +import static org.hamcrest.Matchers.not; +import static org.hamcrest.Matchers.nullValue; +import static org.junit.Assert.assertEquals; +import static redis.clients.jedis.params.ScanParams.SCAN_POINTER_START; +import static redis.clients.jedis.params.ScanParams.SCAN_POINTER_START_BINARY; + +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; +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; +import redis.clients.jedis.params.ZParams; +import redis.clients.jedis.params.ZRangeParams; +import redis.clients.jedis.resps.ScanResult; +import redis.clients.jedis.resps.Tuple; +import redis.clients.jedis.util.AssertUtil; +import redis.clients.jedis.util.KeyValue; +import redis.clients.jedis.util.SafeEncoder; + +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 }; + final byte[] ba = { 0x0A }; + final byte[] bb = { 0x0B }; + final byte[] bc = { 0x0C }; + final byte[] bInclusiveB = { 0x5B, 0x0B }; + final byte[] bExclusiveC = { 0x28, 0x0C }; + final byte[] bLexMinusInf = { 0x2D }; + final byte[] bLexPlusInf = { 0x2B }; + + final byte[] bbar1 = { 0x05, 0x06, 0x07, 0x08, 0x0A }; + final byte[] bbar2 = { 0x05, 0x06, 0x07, 0x08, 0x0B }; + 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(); + } + + @Test + public void zadd() { + pipe.zadd("foo", 1d, "a"); + pipe.zadd("foo", 10d, "b"); + pipe.zadd("foo", 0.1d, "c"); + pipe.zadd("foo", 2d, "a"); + + // Binary + pipe.zadd(bfoo, 1d, ba); + pipe.zadd(bfoo, 10d, bb); + pipe.zadd(bfoo, 0.1d, bc); + pipe.zadd(bfoo, 2d, ba); + + assertThat(pipe.syncAndReturnAll(), contains( + 1L, + 1L, + 1L, + 0L, + 1L, + 1L, + 1L, + 0L + )); + } + + @Test + public void zaddWithParams() { + pipe.del("foo"); + + // xx: never add new member + pipe.zadd("foo", 1d, "a", ZAddParams.zAddParams().xx()); + + pipe.zadd("foo", 1d, "a"); + + // nx: never update current member + pipe.zadd("foo", 2d, "a", ZAddParams.zAddParams().nx()); + pipe.zscore("foo", "a"); + + Map scoreMembers = new HashMap(); + scoreMembers.put("a", 2d); + scoreMembers.put("b", 1d); + // ch: return count of members not only added, but also updated + pipe.zadd("foo", scoreMembers, ZAddParams.zAddParams().ch()); + + assertThat(pipe.syncAndReturnAll(), contains( + 0L, + 0L, + 1L, + 0L, + 1d, + 2L + )); + + // lt: only update existing elements if the new score is less than the current score. + pipe.zadd("foo", 3d, "a", ZAddParams.zAddParams().lt()); + pipe.zscore("foo", "a"); + pipe.zadd("foo", 1d, "a", ZAddParams.zAddParams().lt()); + pipe.zscore("foo", "a"); + + assertThat(pipe.syncAndReturnAll(), contains( + 0L, + 2d, + 0L, + 1d + )); + + // gt: only update existing elements if the new score is greater than the current score. + pipe.zadd("foo", 0d, "b", ZAddParams.zAddParams().gt()); + pipe.zscore("foo", "b"); + pipe.zadd("foo", 2d, "b", ZAddParams.zAddParams().gt()); + pipe.zscore("foo", "b"); + + assertThat(pipe.syncAndReturnAll(), contains( + 0L, + 1d, + 0L, + 2d + )); + + // incr: don't update already existing elements. + pipe.zaddIncr("foo", 1d, "b", ZAddParams.zAddParams().nx()); + pipe.zscore("foo", "b"); + // incr: update elements that already exist. + pipe.zaddIncr("foo", 1d, "b", ZAddParams.zAddParams().xx()); + pipe.zscore("foo", "b"); + + assertThat(pipe.syncAndReturnAll(), contains( + nullValue(), + equalTo(2d), + equalTo(3d), + equalTo(3d) + )); + + // binary + pipe.del(bfoo); + + // xx: never add new member + pipe.zadd(bfoo, 1d, ba, ZAddParams.zAddParams().xx()); + + pipe.zadd(bfoo, 1d, ba); + + // nx: never update current member + pipe.zadd(bfoo, 2d, ba, ZAddParams.zAddParams().nx()); + pipe.zscore(bfoo, ba); + + Map binaryScoreMembers = new HashMap<>(); + binaryScoreMembers.put(ba, 2d); + binaryScoreMembers.put(bb, 1d); + // ch: return count of members not only added, but also updated + pipe.zadd(bfoo, binaryScoreMembers, ZAddParams.zAddParams().ch()); + + assertThat(pipe.syncAndReturnAll(), contains( + 0L, + 0L, + 1L, + 0L, + 1d, + 2L + )); + + // lt: only update existing elements if the new score is less than the current score. + pipe.zadd(bfoo, 3d, ba, ZAddParams.zAddParams().lt()); + pipe.zscore(bfoo, ba); + pipe.zadd(bfoo, 1d, ba, ZAddParams.zAddParams().lt()); + pipe.zscore(bfoo, ba); + + assertThat(pipe.syncAndReturnAll(), contains( + 0L, + 2d, + 0L, + 1d + )); + + // gt: only update existing elements if the new score is greater than the current score. + pipe.zadd(bfoo, 0d, bb, ZAddParams.zAddParams().gt()); + pipe.zscore(bfoo, bb); + pipe.zadd(bfoo, 2d, bb, ZAddParams.zAddParams().gt()); + pipe.zscore(bfoo, bb); + + assertThat(pipe.syncAndReturnAll(), contains( + 0L, + 1d, + 0L, + 2d + )); + + // incr: don't update already existing elements. + pipe.zaddIncr(bfoo, 1d, bb, ZAddParams.zAddParams().nx()); + pipe.zscore(bfoo, bb); + // incr: update elements that already exist. + pipe.zaddIncr(bfoo, 1d, bb, ZAddParams.zAddParams().xx()); + pipe.zscore(bfoo, bb); + + assertThat(pipe.syncAndReturnAll(), contains( + nullValue(), + equalTo(2d), + equalTo(3d), + equalTo(3d) + )); + } + + @Test + public void zrange() { + pipe.zadd("foo", 1d, "a"); + pipe.zadd("foo", 10d, "b"); + pipe.zadd("foo", 0.1d, "c"); + pipe.zadd("foo", 2d, "a"); + + Response> range1 = pipe.zrange("foo", 0, 1); + Response> range2 = pipe.zrange("foo", 0, 100); + + pipe.sync(); + + assertThat(range1.get(), contains("c", "a")); + assertThat(range2.get(), contains("c", "a", "b")); + + // Binary + pipe.zadd(bfoo, 1d, ba); + pipe.zadd(bfoo, 10d, bb); + pipe.zadd(bfoo, 0.1d, bc); + pipe.zadd(bfoo, 2d, ba); + + Response> brange1 = pipe.zrange(bfoo, 0, 1); + Response> brange2 = pipe.zrange(bfoo, 0, 100); + + pipe.sync(); + + assertThat(brange1.get(), contains(bc, ba)); + assertThat(brange2.get(), contains(bc, ba, bb)); + } + + @Test + public void zrangeByLex() { + pipe.zadd("foo", 1, "aa"); + pipe.zadd("foo", 1, "c"); + pipe.zadd("foo", 1, "bb"); + pipe.zadd("foo", 1, "d"); + + // exclusive aa ~ inclusive c + Response> range1 = pipe.zrangeByLex("foo", "(aa", "[c"); + + // with LIMIT + Response> range2 = pipe.zrangeByLex("foo", "-", "+", 1, 2); + + pipe.sync(); + + assertThat(range1.get(), contains("bb", "c")); + assertThat(range2.get(), contains("bb", "c")); + } + + @Test + public void zrangeByLexBinary() { + pipe.zadd(bfoo, 1, ba); + pipe.zadd(bfoo, 1, bc); + pipe.zadd(bfoo, 1, bb); + + Response> brange1 = pipe.zrangeByLex(bfoo, bInclusiveB, bExclusiveC); + + // with LIMIT + Response> brange2 = pipe.zrangeByLex(bfoo, bLexMinusInf, bLexPlusInf, 0, 2); + + pipe.sync(); + + assertThat(brange1.get(), contains(bb)); + assertThat(brange2.get(), contains(ba, bb)); + } + + @Test + public void zrevrangeByLex() { + pipe.zadd("foo", 1, "aa"); + pipe.zadd("foo", 1, "c"); + pipe.zadd("foo", 1, "bb"); + pipe.zadd("foo", 1, "d"); + + // exclusive aa ~ inclusive c + Response> range1 = pipe.zrevrangeByLex("foo", "[c", "(aa"); + + // with LIMIT + Response> range2 = pipe.zrevrangeByLex("foo", "+", "-", 1, 2); + + pipe.sync(); + + assertThat(range1.get(), contains("c", "bb")); + assertThat(range2.get(), contains("c", "bb")); + } + + @Test + public void zrevrangeByLexBinary() { + // binary + pipe.zadd(bfoo, 1, ba); + pipe.zadd(bfoo, 1, bc); + pipe.zadd(bfoo, 1, bb); + + Response> brange1 = pipe.zrevrangeByLex(bfoo, bExclusiveC, bInclusiveB); + + // with LIMIT + Response> brange2 = pipe.zrevrangeByLex(bfoo, bLexPlusInf, bLexMinusInf, 0, 2); + + pipe.sync(); + + assertThat(brange1.get(), contains(bb)); + assertThat(brange2.get(), contains(bc, bb)); + } + + @Test + public void zrevrange() { + pipe.zadd("foo", 1d, "a"); + pipe.zadd("foo", 10d, "b"); + pipe.zadd("foo", 0.1d, "c"); + pipe.zadd("foo", 2d, "a"); + + Response> range1 = pipe.zrevrange("foo", 0, 1); + Response> range2 = pipe.zrevrange("foo", 0, 100); + + pipe.sync(); + + assertThat(range1.get(), contains("b", "a")); + assertThat(range2.get(), contains("b", "a", "c")); + + // Binary + pipe.zadd(bfoo, 1d, ba); + pipe.zadd(bfoo, 10d, bb); + pipe.zadd(bfoo, 0.1d, bc); + pipe.zadd(bfoo, 2d, ba); + + Response> brange1 = pipe.zrevrange(bfoo, 0, 1); + Response> brange2 = pipe.zrevrange(bfoo, 0, 100); + + pipe.sync(); + + assertThat(brange1.get(), contains(bb, ba)); + assertThat(brange2.get(), contains(bb, ba, bc)); + } + + @Test + public void zrangeParams() { + pipe.zadd("foo", 1, "aa"); + pipe.zadd("foo", 1, "c"); + pipe.zadd("foo", 1, "bb"); + pipe.zadd("foo", 1, "d"); + + Response> range1 = pipe.zrange("foo", ZRangeParams.zrangeByLexParams("[c", "(aa").rev()); + Response> range2 = pipe.zrangeWithScores("foo", ZRangeParams.zrangeByScoreParams(0, 1)); + + pipe.sync(); + + assertThat(range1.get(), contains("c", "bb")); + assertThat(range2.get().stream().map(Tuple::getElement).collect(Collectors.toList()), contains("aa", "bb", "c", "d")); + + // Binary + pipe.zadd(bfoo, 1, ba); + pipe.zadd(bfoo, 1, bc); + pipe.zadd(bfoo, 1, bb); + + Response> brange1 = pipe.zrange(bfoo, ZRangeParams.zrangeByLexParams(bExclusiveC, bInclusiveB).rev()); + Response> brange2 = pipe.zrangeWithScores(bfoo, ZRangeParams.zrangeByScoreParams(0, 1).limit(0, 3)); + + pipe.sync(); + + assertThat(brange1.get(), contains(bb)); + assertThat(brange2.get().stream().map(Tuple::getBinaryElement).collect(Collectors.toList()), contains(ba, bb, bc)); + } + + @Test + public void zrangestore() { + pipe.zadd("foo", 1, "aa"); + pipe.zadd("foo", 2, "c"); + pipe.zadd("foo", 3, "bb"); + + Response stored = pipe.zrangestore("bar", "foo", ZRangeParams.zrangeByScoreParams(1, 2)); + Response> range = pipe.zrange("bar", 0, -1); + + pipe.sync(); + + assertThat(stored.get(), equalTo(2L)); + assertThat(range.get(), contains("aa", "c")); + + // Binary + pipe.zadd(bfoo, 1d, ba); + pipe.zadd(bfoo, 10d, bb); + pipe.zadd(bfoo, 0.1d, bc); + pipe.zadd(bfoo, 2d, ba); + + Response bstored = pipe.zrangestore(bbar, bfoo, ZRangeParams.zrangeParams(0, 1).rev()); + Response> brange = pipe.zrevrange(bbar, 0, 1); + + pipe.sync(); + + assertThat(bstored.get(), equalTo(2L)); + assertThat(brange.get(), contains(bb, ba)); + } + + @Test + public void zrem() { + pipe.zadd("foo", 1d, "a"); + pipe.zadd("foo", 2d, "b"); + + Response result1 = pipe.zrem("foo", "a"); + Response> range = pipe.zrange("foo", 0, 100); + Response result2 = pipe.zrem("foo", "bar"); + + pipe.sync(); + + assertThat(result1.get(), equalTo(1L)); + assertThat(range.get(), contains("b")); + assertThat(result2.get(), equalTo(0L)); + + // Binary + pipe.zadd(bfoo, 1d, ba); + pipe.zadd(bfoo, 2d, bb); + + Response bresult1 = pipe.zrem(bfoo, ba); + Response> brange = pipe.zrange(bfoo, 0, 100); + Response bresult2 = pipe.zrem(bfoo, bbar); + + pipe.sync(); + + assertThat(bresult1.get(), equalTo(1L)); + assertThat(brange.get(), contains(bb)); + assertThat(bresult2.get(), equalTo(0L)); + } + + @Test + public void zincrby() { + pipe.zadd("foo", 1d, "a"); + pipe.zadd("foo", 2d, "b"); + + Response result = pipe.zincrby("foo", 2d, "a"); + Response> range = pipe.zrange("foo", 0, 100); + + pipe.sync(); + + assertThat(result.get(), closeTo(3d, 0.001)); + assertThat(range.get(), contains("b", "a")); + + // Binary + pipe.zadd(bfoo, 1d, ba); + pipe.zadd(bfoo, 2d, bb); + + Response bresult = pipe.zincrby(bfoo, 2d, ba); + Response> brange = pipe.zrange(bfoo, 0, 100); + + pipe.sync(); + + assertThat(bresult.get(), closeTo(3d, 0.001)); + assertThat(brange.get(), contains(bb, ba)); + } + + @Test + public void zincrbyWithParams() { + pipe.del("foo"); + + // xx: never add new member + Response result1 = pipe.zincrby("foo", 2d, "a", ZIncrByParams.zIncrByParams().xx()); + + pipe.zadd("foo", 2d, "a"); + + // nx: never update current member + Response result2 = pipe.zincrby("foo", 1d, "a", ZIncrByParams.zIncrByParams().nx()); + Response result3 = pipe.zscore("foo", "a"); + + pipe.sync(); + + assertThat(result1.get(), nullValue()); + assertThat(result2.get(), nullValue()); + assertThat(result3.get(), closeTo(2d, 0.001)); + + // Binary + + pipe.del(bfoo); + + // xx: never add new member + Response bresult1 = pipe.zincrby(bfoo, 2d, ba, ZIncrByParams.zIncrByParams().xx()); + + pipe.zadd(bfoo, 2d, ba); + + // nx: never update current member + Response bresult2 = pipe.zincrby(bfoo, 1d, ba, ZIncrByParams.zIncrByParams().nx()); + Response bresult3 = pipe.zscore(bfoo, ba); + + pipe.sync(); + + assertThat(bresult1.get(), nullValue()); + assertThat(bresult2.get(), nullValue()); + assertThat(bresult3.get(), closeTo(2d, 0.001)); + } + + @Test + public void zrank() { + pipe.zadd("foo", 1d, "a"); + pipe.zadd("foo", 2d, "b"); + + pipe.zrank("foo", "a"); + pipe.zrank("foo", "b"); + pipe.zrank("car", "b"); + + assertThat(pipe.syncAndReturnAll(), contains( + equalTo(1L), + equalTo(1L), + equalTo(0L), + equalTo(1L), + nullValue() + )); + + // Binary + pipe.zadd(bfoo, 1d, ba); + pipe.zadd(bfoo, 2d, bb); + + pipe.zrank(bfoo, ba); + pipe.zrank(bfoo, bb); + pipe.zrank(bcar, bb); + + assertThat(pipe.syncAndReturnAll(), contains( + equalTo(1L), + equalTo(1L), + equalTo(0L), + equalTo(1L), + nullValue() + )); + } + + @Test + public void zrankWithScore() { + pipe.zadd("foo", 1d, "a"); + pipe.zadd("foo", 2d, "b"); + + Response> keyValue1 = pipe.zrankWithScore("foo", "a"); + Response> keyValue2 = pipe.zrankWithScore("foo", "b"); + Response> keyValue3 = pipe.zrankWithScore("car", "b"); + + pipe.sync(); + + assertThat(keyValue1.get(), equalTo(new KeyValue<>(0L, 1d))); + assertThat(keyValue2.get(), equalTo(new KeyValue<>(1L, 2d))); + assertThat(keyValue3.get(), nullValue()); + + // Binary + pipe.zadd(bfoo, 1d, ba); + pipe.zadd(bfoo, 2d, bb); + + Response> bKeyValue1 = pipe.zrankWithScore(bfoo, ba); + Response> bKeyValue2 = pipe.zrankWithScore(bfoo, bb); + Response> bKeyValue3 = pipe.zrankWithScore(bcar, bb); + + pipe.sync(); + + assertThat(bKeyValue1.get(), equalTo(new KeyValue<>(0L, 1d))); + assertThat(bKeyValue2.get(), equalTo(new KeyValue<>(1L, 2d))); + assertThat(bKeyValue3.get(), nullValue()); + } + + @Test + public void zrevrank() { + pipe.zadd("foo", 1d, "a"); + pipe.zadd("foo", 2d, "b"); + + pipe.zrevrank("foo", "a"); + pipe.zrevrank("foo", "b"); + + assertThat(pipe.syncAndReturnAll(), contains( + equalTo(1L), + equalTo(1L), + equalTo(1L), + equalTo(0L) + )); + + // Binary + pipe.zadd(bfoo, 1d, ba); + pipe.zadd(bfoo, 2d, bb); + pipe.zrevrank(bfoo, ba); + pipe.zrevrank(bfoo, bb); + + assertThat(pipe.syncAndReturnAll(), contains( + equalTo(1L), + equalTo(1L), + equalTo(1L), + equalTo(0L) + )); + } + + @Test + public void zrangeWithScores() { + pipe.zadd("foo", 1d, "a"); + pipe.zadd("foo", 10d, "b"); + pipe.zadd("foo", 0.1d, "c"); + pipe.zadd("foo", 2d, "a"); + + Response> range1 = pipe.zrangeWithScores("foo", 0, 1); + Response> range2 = pipe.zrangeWithScores("foo", 0, 100); + + pipe.sync(); + + assertThat(range1.get(), contains( + new Tuple("c", 0.1d), + new Tuple("a", 2d) + )); + assertThat(range2.get(), contains( + new Tuple("c", 0.1d), + new Tuple("a", 2d), + new Tuple("b", 10d) + )); + + // Binary + pipe.zadd(bfoo, 1d, ba); + pipe.zadd(bfoo, 10d, bb); + pipe.zadd(bfoo, 0.1d, bc); + pipe.zadd(bfoo, 2d, ba); + + Response> brange1 = pipe.zrangeWithScores(bfoo, 0, 1); + Response> brange2 = pipe.zrangeWithScores(bfoo, 0, 100); + + pipe.sync(); + + assertThat(brange1.get(), contains( + new Tuple(bc, 0.1d), + new Tuple(ba, 2d) + )); + assertThat(brange2.get(), contains( + new Tuple(bc, 0.1d), + new Tuple(ba, 2d), + new Tuple(bb, 10d) + )); + } + + @Test + public void zrevrangeWithScores() { + pipe.zadd("foo", 1d, "a"); + pipe.zadd("foo", 10d, "b"); + pipe.zadd("foo", 0.1d, "c"); + pipe.zadd("foo", 2d, "a"); + + Response> range1 = pipe.zrevrangeWithScores("foo", 0, 1); + Response> range2 = pipe.zrevrangeWithScores("foo", 0, 100); + + pipe.sync(); + + assertThat(range1.get(), contains( + new Tuple("b", 10d), + new Tuple("a", 2d) + )); + assertThat(range2.get(), contains( + new Tuple("b", 10d), + new Tuple("a", 2d), + new Tuple("c", 0.1d) + )); + + // Binary + pipe.zadd(bfoo, 1d, ba); + pipe.zadd(bfoo, 10d, bb); + pipe.zadd(bfoo, 0.1d, bc); + pipe.zadd(bfoo, 2d, ba); + + Response> brange1 = pipe.zrevrangeWithScores(bfoo, 0, 1); + Response> brange2 = pipe.zrevrangeWithScores(bfoo, 0, 100); + + pipe.sync(); + + assertThat(brange1.get(), contains( + new Tuple(bb, 10d), + new Tuple(ba, 2d) + )); + assertThat(brange2.get(), contains( + new Tuple(bb, 10d), + new Tuple(ba, 2d), + new Tuple(bc, 0.1d) + )); + } + + @Test + public void zcard() { + pipe.zadd("foo", 1d, "a"); + pipe.zadd("foo", 10d, "b"); + pipe.zadd("foo", 0.1d, "c"); + pipe.zadd("foo", 2d, "a"); + + Response result = pipe.zcard("foo"); + + pipe.sync(); + + assertThat(result.get(), equalTo(3L)); + + // Binary + pipe.zadd(bfoo, 1d, ba); + pipe.zadd(bfoo, 10d, bb); + pipe.zadd(bfoo, 0.1d, bc); + pipe.zadd(bfoo, 2d, ba); + + Response bresult = pipe.zcard(bfoo); + + pipe.sync(); + + assertThat(bresult.get(), equalTo(3L)); + } + + @Test + public void zscore() { + pipe.zadd("foo", 1d, "a"); + pipe.zadd("foo", 10d, "b"); + pipe.zadd("foo", 0.1d, "c"); + pipe.zadd("foo", 2d, "a"); + + Response result1 = pipe.zscore("foo", "b"); + Response result2 = pipe.zscore("foo", "c"); + Response result3 = pipe.zscore("foo", "s"); + + pipe.sync(); + + assertThat(result1.get(), closeTo(10d, 0.001)); + assertThat(result2.get(), closeTo(0.1d, 0.001)); + assertThat(result3.get(), nullValue()); + + // Binary + pipe.zadd(bfoo, 1d, ba); + pipe.zadd(bfoo, 10d, bb); + pipe.zadd(bfoo, 0.1d, bc); + pipe.zadd(bfoo, 2d, ba); + + Response bresult1 = pipe.zscore(bfoo, bb); + Response bresult2 = pipe.zscore(bfoo, bc); + Response bresult3 = pipe.zscore(bfoo, SafeEncoder.encode("s")); + + pipe.sync(); + + assertThat(bresult1.get(), closeTo(10d, 0.001)); + assertThat(bresult2.get(), closeTo(0.1d, 0.001)); + assertThat(bresult3.get(), nullValue()); + } + + @Test + public void zmscore() { + pipe.zadd("foo", 1d, "a"); + pipe.zadd("foo", 10d, "b"); + pipe.zadd("foo", 0.1d, "c"); + pipe.zadd("foo", 2d, "a"); + + Response> score = pipe.zmscore("foo", "b", "c", "s"); + + pipe.sync(); + + assertThat(score.get(), contains(10d, 0.1d, null)); + + // Binary + pipe.zadd(bfoo, 1d, ba); + pipe.zadd(bfoo, 10d, bb); + pipe.zadd(bfoo, 0.1d, bc); + pipe.zadd(bfoo, 2d, ba); + + Response> bscore = pipe.zmscore(bfoo, bb, bc, SafeEncoder.encode("s")); + + pipe.sync(); + + assertThat(bscore.get(), contains(10d, 0.1d, null)); + } + + @Test + public void zpopmax() { + pipe.zadd("foo", 1d, "a"); + pipe.zadd("foo", 10d, "b"); + pipe.zadd("foo", 0.1d, "c"); + pipe.zadd("foo", 2d, "d"); + + pipe.sync(); + + pipe.zpopmax("foo"); + pipe.zpopmax("foo"); + pipe.zpopmax("foo"); + pipe.zpopmax("foo"); + pipe.zpopmax("foo"); + + assertThat(pipe.syncAndReturnAll(), contains( + equalTo(new Tuple("b", 10d)), + equalTo(new Tuple("d", 2d)), + equalTo(new Tuple("a", 1d)), + equalTo(new Tuple("c", 0.1d)), + nullValue() + )); + + // Binary + pipe.zadd(bfoo, 1d, ba); + pipe.zadd(bfoo, 10d, bb); + pipe.zadd(bfoo, 0.1d, bc); + pipe.zadd(bfoo, 2d, ba); + + pipe.sync(); + + pipe.zpopmax(bfoo); + pipe.zpopmax(bfoo); + pipe.zpopmax(bfoo); + pipe.zpopmax(bfoo); + + assertThat(pipe.syncAndReturnAll(), contains( + equalTo(new Tuple(bb, 10d)), + equalTo(new Tuple(ba, 2d)), + equalTo(new Tuple(bc, 0.1d)), + nullValue() + )); + } + + @Test + public void zpopmaxWithCount() { + pipe.zadd("foo", 1d, "a"); + pipe.zadd("foo", 10d, "b"); + pipe.zadd("foo", 0.1d, "c"); + pipe.zadd("foo", 2d, "d"); + pipe.zadd("foo", 0.03, "e"); + + Response> actual1 = pipe.zpopmax("foo", 2); + Response> actual2 = pipe.zpopmax("foo", 3); + Response> actual3 = pipe.zpopmax("foo", 1); + + pipe.sync(); + + assertThat(actual1.get(), contains( + new Tuple("b", 10d), + new Tuple("d", 2d) + )); + + assertThat(actual2.get(), contains( + new Tuple("a", 1d), + new Tuple("c", 0.1d), + new Tuple("e", 0.03d) + )); + + assertThat(actual3.get(), empty()); + + // Binary + pipe.zadd(bfoo, 1d, ba); + pipe.zadd(bfoo, 10d, bb); + pipe.zadd(bfoo, 0.1d, bc); + pipe.zadd(bfoo, 2d, ba); + + Response> bactual1 = pipe.zpopmax(bfoo, 1); + Response> bactual2 = pipe.zpopmax(bfoo, 1); + Response> bactual3 = pipe.zpopmax(bfoo, 1); + Response> bactual4 = pipe.zpopmax(bfoo, 1); + + pipe.sync(); + + assertThat(bactual1.get(), contains( + new Tuple(bb, 10d) + )); + + assertThat(bactual2.get(), contains( + new Tuple(ba, 2d) + )); + + assertThat(bactual3.get(), contains( + new Tuple(bc, 0.1d) + )); + + assertThat(bactual4.get(), empty()); + } + + @Test + public void zpopmin() { + pipe.zadd("foo", 1d, "a", ZAddParams.zAddParams().nx()); + pipe.zadd("foo", 10d, "b", ZAddParams.zAddParams().nx()); + pipe.zadd("foo", 0.1d, "c", ZAddParams.zAddParams().nx()); + pipe.zadd("foo", 2d, "a", ZAddParams.zAddParams().nx()); + + Response> range = pipe.zpopmin("foo", 2); + Response item = pipe.zpopmin("foo"); + + pipe.sync(); + + assertThat(range.get(), contains( + new Tuple("c", 0.1d), + new Tuple("a", 1d) + )); + + assertThat(item.get(), equalTo(new Tuple("b", 10d))); + + // Binary + + pipe.zadd(bfoo, 1d, ba); + pipe.zadd(bfoo, 10d, bb); + pipe.zadd(bfoo, 0.1d, bc); + pipe.zadd(bfoo, 2d, ba); + + Response> brange = pipe.zpopmin(bfoo, 2); + Response bitem = pipe.zpopmin(bfoo); + + pipe.sync(); + + assertThat(brange.get(), contains( + new Tuple(bc, 0.1d), + new Tuple(ba, 2d) + )); + + assertThat(bitem.get(), equalTo(new Tuple(bb, 10d))); + } + + @Test + public void zcount() { + pipe.zadd("foo", 1d, "a"); + pipe.zadd("foo", 10d, "b"); + pipe.zadd("foo", 0.1d, "c"); + pipe.zadd("foo", 2d, "a"); + + pipe.sync(); + + pipe.zcount("foo", 0.01d, 2.1d); + pipe.zcount("foo", "(0.01", "+inf"); + + assertThat(pipe.syncAndReturnAll(), contains( + 2L, + 3L + )); + + // Binary + pipe.zadd(bfoo, 1d, ba); + pipe.zadd(bfoo, 10d, bb); + pipe.zadd(bfoo, 0.1d, bc); + pipe.zadd(bfoo, 2d, ba); + + pipe.sync(); + + pipe.zcount(bfoo, 0.01d, 2.1d); + pipe.zcount(bfoo, SafeEncoder.encode("(0.01"), SafeEncoder.encode("+inf")); + + assertThat(pipe.syncAndReturnAll(), contains( + 2L, + 3L + )); + } + + @Test + public void zlexcount() { + pipe.zadd("foo", 1, "a"); + pipe.zadd("foo", 1, "b"); + pipe.zadd("foo", 1, "c"); + pipe.zadd("foo", 1, "aa"); + + pipe.sync(); + + pipe.zlexcount("foo", "[aa", "(c"); + pipe.zlexcount("foo", "-", "+"); + pipe.zlexcount("foo", "-", "(c"); + pipe.zlexcount("foo", "[aa", "+"); + + assertThat(pipe.syncAndReturnAll(), contains( + 2L, + 4L, + 3L, + 3L + )); + } + + @Test + public void zlexcountBinary() { + // Binary + pipe.zadd(bfoo, 1, ba); + pipe.zadd(bfoo, 1, bc); + pipe.zadd(bfoo, 1, bb); + + pipe.sync(); + + pipe.zlexcount(bfoo, bInclusiveB, bExclusiveC); + pipe.zlexcount(bfoo, bLexMinusInf, bLexPlusInf); + + assertThat(pipe.syncAndReturnAll(), contains( + 1L, + 3L + )); + } + + @Test + public void zrangebyscore() { + pipe.zadd("foo", 1d, "a"); + pipe.zadd("foo", 10d, "b"); + pipe.zadd("foo", 0.1d, "c"); + pipe.zadd("foo", 2d, "a"); + + Response> range1 = pipe.zrangeByScore("foo", 0d, 2d); + Response> range2 = pipe.zrangeByScore("foo", 0d, 2d, 0, 1); + Response> range3 = pipe.zrangeByScore("foo", 0d, 2d, 1, 1); + Response> range4 = pipe.zrangeByScore("foo", "-inf", "(2"); + + pipe.sync(); + + assertThat(range1.get(), contains("c", "a")); + assertThat(range2.get(), contains("c")); + assertThat(range3.get(), contains("a")); + assertThat(range4.get(), contains("c")); + + // Binary + pipe.zadd(bfoo, 1d, ba); + pipe.zadd(bfoo, 10d, bb); + pipe.zadd(bfoo, 0.1d, bc); + pipe.zadd(bfoo, 2d, ba); + + Response> brange1 = pipe.zrangeByScore(bfoo, 0d, 2d); + Response> brange2 = pipe.zrangeByScore(bfoo, 0d, 2d, 0, 1); + Response> brange3 = pipe.zrangeByScore(bfoo, 0d, 2d, 1, 1); + Response> brange4 = pipe.zrangeByScore(bfoo, SafeEncoder.encode("-inf"), SafeEncoder.encode("(2")); + + pipe.sync(); + + assertThat(brange1.get(), contains(bc, ba)); + assertThat(brange2.get(), contains(bc)); + assertThat(brange3.get(), contains(ba)); + assertThat(brange4.get(), contains(bc)); + } + + @Test + public void zrevrangebyscore() { + pipe.zadd("foo", 1.0d, "a"); + pipe.zadd("foo", 2.0d, "b"); + pipe.zadd("foo", 3.0d, "c"); + pipe.zadd("foo", 4.0d, "d"); + pipe.zadd("foo", 5.0d, "e"); + + Response> range1 = pipe.zrevrangeByScore("foo", 3d, Double.NEGATIVE_INFINITY, 0, 1); + Response> range2 = pipe.zrevrangeByScore("foo", 3.5d, Double.NEGATIVE_INFINITY, 0, 2); + Response> range3 = pipe.zrevrangeByScore("foo", 3.5d, Double.NEGATIVE_INFINITY, 1, 1); + Response> range4 = pipe.zrevrangeByScore("foo", 4d, 2d); + Response> range5 = pipe.zrevrangeByScore("foo", "4", "2", 0, 2); + Response> range6 = pipe.zrevrangeByScore("foo", "+inf", "(4"); + + pipe.sync(); + + assertThat(range1.get(), contains("c")); + assertThat(range2.get(), contains("c", "b")); + assertThat(range3.get(), contains("b")); + assertThat(range4.get(), contains("d", "c", "b")); + assertThat(range5.get(), contains("d", "c")); + assertThat(range6.get(), contains("e")); + + // Binary + pipe.zadd(bfoo, 1d, ba); + pipe.zadd(bfoo, 10d, bb); + pipe.zadd(bfoo, 0.1d, bc); + pipe.zadd(bfoo, 2d, ba); + + Response> brange1 = pipe.zrevrangeByScore(bfoo, 2d, 0d); + Response> brange2 = pipe.zrevrangeByScore(bfoo, 2d, 0d, 0, 1); + Response> brange3 = pipe.zrevrangeByScore(bfoo, SafeEncoder.encode("+inf"), SafeEncoder.encode("(2")); + Response> brange4 = pipe.zrevrangeByScore(bfoo, 2d, 0d, 1, 1); + + pipe.sync(); + + assertThat(brange1.get(), contains(ba, bc)); + assertThat(brange2.get(), contains(ba)); + assertThat(brange3.get(), contains(bb)); + assertThat(brange4.get(), contains(bc)); + } + + @Test + public void zrangebyscoreWithScores() { + pipe.zadd("foo", 1d, "a"); + pipe.zadd("foo", 10d, "b"); + pipe.zadd("foo", 0.1d, "c"); + pipe.zadd("foo", 2d, "a"); + + Response> range1 = pipe.zrangeByScoreWithScores("foo", 0d, 2d); + Response> range2 = pipe.zrangeByScoreWithScores("foo", 0d, 2d, 0, 1); + Response> range3 = pipe.zrangeByScoreWithScores("foo", 0d, 2d, 1, 1); + + pipe.sync(); + + assertThat(range1.get(), contains( + new Tuple("c", 0.1d), + new Tuple("a", 2d) + )); + + assertThat(range2.get(), contains( + new Tuple("c", 0.1d) + )); + + assertThat(range3.get(), contains( + new Tuple("a", 2d) + )); + + // Binary + + pipe.zadd(bfoo, 1d, ba); + pipe.zadd(bfoo, 10d, bb); + pipe.zadd(bfoo, 0.1d, bc); + pipe.zadd(bfoo, 2d, ba); + + Response> brange1 = pipe.zrangeByScoreWithScores(bfoo, 0d, 2d); + Response> brange2 = pipe.zrangeByScoreWithScores(bfoo, 0d, 2d, 0, 1); + Response> brange3 = pipe.zrangeByScoreWithScores(bfoo, 0d, 2d, 1, 1); + + pipe.sync(); + + assertThat(brange1.get(), contains( + new Tuple(bc, 0.1d), + new Tuple(ba, 2d) + )); + + assertThat(brange2.get(), contains( + new Tuple(bc, 0.1d) + )); + + assertThat(brange3.get(), contains( + new Tuple(ba, 2d) + )); + } + + @Test + public void zrevrangebyscoreWithScores() { + pipe.zadd("foo", 1.0d, "a"); + pipe.zadd("foo", 2.0d, "b"); + pipe.zadd("foo", 3.0d, "c"); + pipe.zadd("foo", 4.0d, "d"); + pipe.zadd("foo", 5.0d, "e"); + + Response> range1 = pipe.zrevrangeByScoreWithScores("foo", 3d, Double.NEGATIVE_INFINITY, 0, 1); + Response> range2 = pipe.zrevrangeByScoreWithScores("foo", 3.5d, Double.NEGATIVE_INFINITY, 0, 2); + Response> range3 = pipe.zrevrangeByScoreWithScores("foo", 3.5d, Double.NEGATIVE_INFINITY, 1, 1); + Response> range4 = pipe.zrevrangeByScoreWithScores("foo", 4d, 2d); + + pipe.sync(); + + assertThat(range1.get(), contains( + new Tuple("c", 3.0d) + )); + + assertThat(range2.get(), contains( + new Tuple("c", 3.0d), + new Tuple("b", 2.0d) + )); + + assertThat(range3.get(), contains( + new Tuple("b", 2.0d) + )); + + assertThat(range4.get(), contains( + new Tuple("d", 4.0d), + new Tuple("c", 3.0d), + new Tuple("b", 2.0d) + )); + + // Binary + pipe.zadd(bfoo, 1d, ba); + pipe.zadd(bfoo, 10d, bb); + pipe.zadd(bfoo, 0.1d, bc); + pipe.zadd(bfoo, 2d, ba); + + Response> brange1 = pipe.zrevrangeByScoreWithScores(bfoo, 2d, 0d); + Response> brange2 = pipe.zrevrangeByScoreWithScores(bfoo, 2d, 0d, 0, 1); + Response> brange3 = pipe.zrevrangeByScoreWithScores(bfoo, 2d, 0d, 1, 1); + + pipe.sync(); + + assertThat(brange1.get(), contains( + new Tuple(ba, 2d), + new Tuple(bc, 0.1d) + )); + + assertThat(brange2.get(), contains( + new Tuple(ba, 2d) + )); + + assertThat(brange3.get(), contains( + new Tuple(bc, 0.1d) + )); + } + + @Test + public void zremrangeByRank() { + pipe.zadd("foo", 1d, "a"); + pipe.zadd("foo", 10d, "b"); + pipe.zadd("foo", 0.1d, "c"); + pipe.zadd("foo", 2d, "a"); + + Response result = pipe.zremrangeByRank("foo", 0, 0); + Response> items = pipe.zrange("foo", 0, 100); + + pipe.sync(); + + assertThat(result.get(), equalTo(1L)); + assertThat(items.get(), contains("a", "b")); + + // Binary + pipe.zadd(bfoo, 1d, ba); + pipe.zadd(bfoo, 10d, bb); + pipe.zadd(bfoo, 0.1d, bc); + pipe.zadd(bfoo, 2d, ba); + + Response bresult = pipe.zremrangeByRank(bfoo, 0, 0); + Response> bitems = pipe.zrange(bfoo, 0, 100); + + pipe.sync(); + + assertThat(bresult.get(), equalTo(1L)); + assertThat(bitems.get(), contains(ba, bb)); + } + + @Test + public void zremrangeByScore() { + pipe.zadd("foo", 1d, "a"); + pipe.zadd("foo", 10d, "b"); + pipe.zadd("foo", 0.1d, "c"); + pipe.zadd("foo", 2d, "a"); + + Response result = pipe.zremrangeByScore("foo", 0, 2); + Response> items = pipe.zrange("foo", 0, 100); + + pipe.sync(); + + assertThat(result.get(), equalTo(2L)); + assertThat(items.get(), contains("b")); + + // Binary + pipe.zadd(bfoo, 1d, ba); + pipe.zadd(bfoo, 10d, bb); + pipe.zadd(bfoo, 0.1d, bc); + pipe.zadd(bfoo, 2d, ba); + + Response bresult = pipe.zremrangeByScore(bfoo, 0, 2); + Response> bitems = pipe.zrange(bfoo, 0, 100); + + pipe.sync(); + + assertThat(bresult.get(), equalTo(2L)); + assertThat(bitems.get(), contains(bb)); + } + + @Test + public void zremrangeByScoreExclusive() { + pipe.zadd("foo", 1d, "a"); + pipe.zadd("foo", 0d, "c"); + pipe.zadd("foo", 2d, "b"); + + Response result = pipe.zremrangeByScore("foo", "(0", "(2"); + + pipe.sync(); + + assertThat(result.get(), equalTo(1L)); + + // Binary + pipe.zadd(bfoo, 1d, ba); + pipe.zadd(bfoo, 0d, bc); + pipe.zadd(bfoo, 2d, bb); + + Response bresult = pipe.zremrangeByScore(bfoo, "(0".getBytes(), "(2".getBytes()); + + pipe.sync(); + + assertThat(bresult.get(), equalTo(1L)); + } + + @Test + public void zremrangeByLex() { + pipe.zadd("foo", 1, "a"); + pipe.zadd("foo", 1, "b"); + pipe.zadd("foo", 1, "c"); + pipe.zadd("foo", 1, "aa"); + + Response result = pipe.zremrangeByLex("foo", "[aa", "(c"); + Response> items = pipe.zrangeByLex("foo", "-", "+"); + + pipe.sync(); + + assertThat(result.get(), equalTo(2L)); + assertThat(items.get(), contains("a", "c")); + } + + @Test + public void zremrangeByLexBinary() { + pipe.zadd(bfoo, 1, ba); + pipe.zadd(bfoo, 1, bc); + pipe.zadd(bfoo, 1, bb); + + Response bresult = pipe.zremrangeByLex(bfoo, bInclusiveB, bExclusiveC); + Response> bitems = pipe.zrangeByLex(bfoo, bLexMinusInf, bLexPlusInf); + + pipe.sync(); + + assertThat(bresult.get(), equalTo(1L)); + assertThat(bitems.get(), contains(ba, bc)); + } + + @Test + public void zunion() { + pipe.zadd("foo", 1, "a"); + pipe.zadd("foo", 2, "b"); + pipe.zadd("bar", 2, "a"); + pipe.zadd("bar", 2, "b"); + + ZParams params = new ZParams(); + params.weights(2, 2.5); + params.aggregate(ZParams.Aggregate.SUM); + + Response> union1 = pipe.zunion(params, "foo", "bar"); + Response> union2 = pipe.zunionWithScores(params, "foo", "bar"); + + pipe.sync(); + + assertThat(union1.get(), contains("a", "b")); + assertThat(union2.get(), contains( + new Tuple("a", new Double(7)), + new Tuple("b", new Double(9)) + )); + + // Binary + pipe.zadd(bfoo, 1, ba); + pipe.zadd(bfoo, 2, bb); + pipe.zadd(bbar, 2, ba); + pipe.zadd(bbar, 2, bb); + + Response> bunion1 = pipe.zunion(params, bfoo, bbar); + Response> bunion2 = pipe.zunionWithScores(params, bfoo, bbar); + + pipe.sync(); + + assertThat(bunion1.get(), contains(ba, bb)); + assertThat(bunion2.get(), contains( + new Tuple(ba, new Double(7)), + new Tuple(bb, new Double(9)) + )); + } + + @Test + public void zunionstore() { + pipe.zadd("foo", 1, "a"); + pipe.zadd("foo", 2, "b"); + pipe.zadd("bar", 2, "a"); + pipe.zadd("bar", 2, "b"); + + Response result = pipe.zunionstore("dst", "foo", "bar"); + Response> items = pipe.zrangeWithScores("dst", 0, 100); + + pipe.sync(); + + assertThat(result.get(), equalTo(2L)); + assertThat(items.get(), contains( + new Tuple("a", new Double(3)), + new Tuple("b", new Double(4)) + )); + + // Binary + pipe.zadd(bfoo, 1, ba); + pipe.zadd(bfoo, 2, bb); + pipe.zadd(bbar, 2, ba); + pipe.zadd(bbar, 2, bb); + + Response bresult = pipe.zunionstore(SafeEncoder.encode("dst"), bfoo, bbar); + Response> bitems = pipe.zrangeWithScores(SafeEncoder.encode("dst"), 0, 100); + + pipe.sync(); + + assertThat(bresult.get(), equalTo(2L)); + assertThat(bitems.get(), contains( + new Tuple(ba, new Double(3)), + new Tuple(bb, new Double(4)) + )); + } + + @Test + public void zunionstoreParams() { + pipe.zadd("foo", 1, "a"); + pipe.zadd("foo", 2, "b"); + pipe.zadd("bar", 2, "a"); + pipe.zadd("bar", 2, "b"); + + ZParams params = new ZParams(); + params.weights(2, 2.5); + params.aggregate(ZParams.Aggregate.SUM); + + Response result = pipe.zunionstore("dst", params, "foo", "bar"); + Response> items = pipe.zrangeWithScores("dst", 0, 100); + + pipe.sync(); + + assertThat(result.get(), equalTo(2L)); + assertThat(items.get(), contains( + new Tuple("a", new Double(7)), + new Tuple("b", new Double(9)) + )); + + // Binary + pipe.zadd(bfoo, 1, ba); + pipe.zadd(bfoo, 2, bb); + pipe.zadd(bbar, 2, ba); + pipe.zadd(bbar, 2, bb); + + ZParams bparams = new ZParams(); + bparams.weights(2, 2.5); + bparams.aggregate(ZParams.Aggregate.SUM); + + Response bresult = pipe.zunionstore(SafeEncoder.encode("dst"), bparams, bfoo, bbar); + Response> bitems = pipe.zrangeWithScores(SafeEncoder.encode("dst"), 0, 100); + + pipe.sync(); + + assertThat(bresult.get(), equalTo(2L)); + assertThat(bitems.get(), contains( + new Tuple(ba, new Double(7)), + new Tuple(bb, new Double(9)) + )); + } + + @Test + public void zinter() { + pipe.zadd("foo", 1, "a"); + pipe.zadd("foo", 2, "b"); + pipe.zadd("bar", 2, "a"); + + ZParams params = new ZParams(); + params.weights(2, 2.5); + params.aggregate(ZParams.Aggregate.SUM); + Response> inter1 = pipe.zinter(params, "foo", "bar"); + + Response> inter2 = pipe.zinterWithScores(params, "foo", "bar"); + + pipe.sync(); + + assertThat(inter1.get(), contains("a")); + assertThat(inter2.get(), contains(new Tuple("a", new Double(7)))); + + // Binary + pipe.zadd(bfoo, 1, ba); + pipe.zadd(bfoo, 2, bb); + pipe.zadd(bbar, 2, ba); + + ZParams bparams = new ZParams(); + bparams.weights(2, 2.5); + bparams.aggregate(ZParams.Aggregate.SUM); + Response> binter1 = pipe.zinter(params, bfoo, bbar); + + Response> binter2 = pipe.zinterWithScores(bparams, bfoo, bbar); + + pipe.sync(); + + assertThat(binter1.get(), contains(ba)); + assertThat(binter2.get(), contains(new Tuple(ba, new Double(7)))); + } + + @Test + public void zinterstore() { + pipe.zadd("foo", 1, "a"); + pipe.zadd("foo", 2, "b"); + pipe.zadd("bar", 2, "a"); + + Response result1 = pipe.zinterstore("dst", "foo", "bar"); + Response> items1 = pipe.zrangeWithScores("dst", 0, 100); + + pipe.sync(); + + assertThat(result1.get(), equalTo(1L)); + assertThat(items1.get(), contains(new Tuple("a", new Double(3)))); + + // Binary + pipe.zadd(bfoo, 1, ba); + pipe.zadd(bfoo, 2, bb); + pipe.zadd(bbar, 2, ba); + + Response bresult1 = pipe.zinterstore(SafeEncoder.encode("dst"), bfoo, bbar); + Response> bitems1 = pipe.zrangeWithScores(SafeEncoder.encode("dst"), 0, 100); + + pipe.sync(); + + assertThat(bresult1.get(), equalTo(1L)); + assertThat(bitems1.get(), contains(new Tuple(ba, new Double(3)))); + } + + @Test + public void zintertoreParams() { + pipe.zadd("foo", 1, "a"); + pipe.zadd("foo", 2, "b"); + pipe.zadd("bar", 2, "a"); + + ZParams params = new ZParams(); + params.weights(2, 2.5); + params.aggregate(ZParams.Aggregate.SUM); + Response result1 = pipe.zinterstore("dst", params, "foo", "bar"); + + Response> items1 = pipe.zrangeWithScores("dst", 0, 100); + + pipe.sync(); + + assertThat(result1.get(), equalTo(1L)); + assertThat(items1.get(), contains(new Tuple("a", new Double(7)))); + + // Binary + pipe.zadd(bfoo, 1, ba); + pipe.zadd(bfoo, 2, bb); + pipe.zadd(bbar, 2, ba); + + ZParams bparams = new ZParams(); + bparams.weights(2, 2.5); + bparams.aggregate(ZParams.Aggregate.SUM); + Response bresult1 = pipe.zinterstore(SafeEncoder.encode("dst"), bparams, bfoo, bbar); + + Response> bitems1 = pipe.zrangeWithScores(SafeEncoder.encode("dst"), 0, 100); + + pipe.sync(); + + assertThat(bresult1.get(), equalTo(1L)); + assertThat(bitems1.get(), contains(new Tuple(ba, new Double(7)))); + } + + @Test + public void zintercard() { + pipe.zadd("foo", 1, "a"); + pipe.zadd("foo", 2, "b"); + pipe.zadd("bar", 2, "a"); + pipe.zadd("bar", 1, "b"); + + Response result1 = pipe.zintercard("foo", "bar"); + Response result2 = pipe.zintercard(1, "foo", "bar"); + + pipe.sync(); + + assertThat(result1.get(), equalTo(2L)); + assertThat(result2.get(), equalTo(1L)); + + // Binary + pipe.zadd(bfoo, 1, ba); + pipe.zadd(bfoo, 2, bb); + pipe.zadd(bbar, 2, ba); + pipe.zadd(bbar, 2, bb); + + Response bresult1 = pipe.zintercard(bfoo, bbar); + Response bresult2 = pipe.zintercard(1, bfoo, bbar); + + pipe.sync(); + + assertThat(bresult1.get(), equalTo(2L)); + assertThat(bresult2.get(), equalTo(1L)); + } + + @Test + public void zscan() { + pipe.zadd("foo", 1, "a"); + pipe.zadd("foo", 2, "b"); + + Response> result = pipe.zscan("foo", SCAN_POINTER_START); + + pipe.sync(); + + assertThat(result.get().getCursor(), equalTo(SCAN_POINTER_START)); + assertThat(result.get().getResult().stream().map(Tuple::getElement).collect(Collectors.toList()), + containsInAnyOrder("a", "b")); + + // binary + pipe.zadd(bfoo, 1, ba); + pipe.zadd(bfoo, 1, bb); + + Response> bResult = pipe.zscan(bfoo, SCAN_POINTER_START_BINARY); + + pipe.sync(); + + assertThat(bResult.get().getCursor(), equalTo(SCAN_POINTER_START)); + assertThat(bResult.get().getResult().stream().map(Tuple::getBinaryElement).collect(Collectors.toList()), + containsInAnyOrder(ba, bb)); + } + + @Test + public void zscanMatch() { + ScanParams params = new ScanParams(); + params.match("a*"); + + pipe.zadd("foo", 2, "b"); + pipe.zadd("foo", 1, "a"); + pipe.zadd("foo", 11, "aa"); + Response> result = pipe.zscan("foo", SCAN_POINTER_START, params); + + pipe.sync(); + + assertThat(result.get().getCursor(), equalTo(SCAN_POINTER_START)); + assertThat(result.get().getResult().stream().map(Tuple::getElement).collect(Collectors.toList()), + containsInAnyOrder("a", "aa")); + + // binary + params = new ScanParams(); + params.match(bbarstar); + + pipe.zadd(bfoo, 2, bbar1); + pipe.zadd(bfoo, 1, bbar2); + pipe.zadd(bfoo, 11, bbar3); + Response> bResult = pipe.zscan(bfoo, SCAN_POINTER_START_BINARY, params); + + pipe.sync(); + + assertThat(bResult.get().getCursor(), equalTo(SCAN_POINTER_START)); + assertThat(bResult.get().getResult().stream().map(Tuple::getBinaryElement).collect(Collectors.toList()), + containsInAnyOrder(bbar1, bbar2, bbar3)); + } + + @Test + public void zscanCount() { + ScanParams params = new ScanParams(); + params.count(2); + + pipe.zadd("foo", 1, "a1"); + pipe.zadd("foo", 2, "a2"); + pipe.zadd("foo", 3, "a3"); + pipe.zadd("foo", 4, "a4"); + pipe.zadd("foo", 5, "a5"); + + Response> result = pipe.zscan("foo", SCAN_POINTER_START, params); + + pipe.sync(); + + assertThat(result.get().getResult(), not(empty())); + + // binary + params = new ScanParams(); + params.count(2); + + pipe.zadd(bfoo, 2, bbar1); + pipe.zadd(bfoo, 1, bbar2); + pipe.zadd(bfoo, 11, bbar3); + + Response> bResult = pipe.zscan(bfoo, SCAN_POINTER_START_BINARY, params); + + pipe.sync(); + + assertThat(bResult.get().getResult(), not(empty())); + } + + @Test + public void infinity() { + pipe.zadd("key", Double.POSITIVE_INFINITY, "pos"); + + Response score1 = pipe.zscore("key", "pos"); + + pipe.zadd("key", Double.NEGATIVE_INFINITY, "neg"); + + Response score2 = pipe.zscore("key", "neg"); + + pipe.zadd("key", 0d, "zero"); + + Response> set = pipe.zrangeWithScores("key", 0, -1); + + pipe.sync(); + + assertThat(score1.get(), equalTo(Double.POSITIVE_INFINITY)); + assertThat(score2.get(), equalTo(Double.NEGATIVE_INFINITY)); + assertThat(set.get().stream().map(Tuple::getScore).collect(Collectors.toList()), + contains(Double.NEGATIVE_INFINITY, 0d, Double.POSITIVE_INFINITY)); + } + + @Test + public void bzpopmax() { + pipe.zadd("foo", 1d, "a", ZAddParams.zAddParams().nx()); + pipe.zadd("foo", 10d, "b", ZAddParams.zAddParams().nx()); + pipe.zadd("bar", 0.1d, "c", ZAddParams.zAddParams().nx()); + + Response> item1 = pipe.bzpopmax(0, "foo", "bar"); + + pipe.sync(); + + assertThat(item1.get().getKey(), equalTo("foo")); + assertThat(item1.get().getValue(), equalTo(new Tuple("b", 10d))); + + // Binary + pipe.zadd(bfoo, 1d, ba); + pipe.zadd(bfoo, 10d, bb); + pipe.zadd(bbar, 0.1d, bc); + + Response> bitem1 = pipe.bzpopmax(0, bfoo, bbar); + + pipe.sync(); + + assertThat(bitem1.get().getKey(), equalTo(bfoo)); + assertThat(bitem1.get().getValue(), equalTo(new Tuple(bb, 10d))); + } + + @Test + public void bzpopmin() { + pipe.zadd("foo", 1d, "a", ZAddParams.zAddParams().nx()); + pipe.zadd("foo", 10d, "b", ZAddParams.zAddParams().nx()); + pipe.zadd("bar", 0.1d, "c", ZAddParams.zAddParams().nx()); + + Response> item1 = pipe.bzpopmin(0, "bar", "foo"); + + pipe.sync(); + + assertThat(item1.get(), equalTo(new KeyValue<>("bar", new Tuple("c", 0.1)))); + + // Binary + pipe.zadd(bfoo, 1d, ba); + pipe.zadd(bfoo, 10d, bb); + pipe.zadd(bbar, 0.1d, bc); + + Response> bitem1 = pipe.bzpopmin(0, bbar, bfoo); + + pipe.sync(); + + assertThat(bitem1.get().getKey(), equalTo(bbar)); + assertThat(bitem1.get().getValue(), equalTo(new Tuple(bc, 0.1))); + } + + @Test + public void zdiff() { + pipe.zadd("foo", 1.0, "a"); + pipe.zadd("foo", 2.0, "b"); + pipe.zadd("bar", 1.0, "a"); + + Response> diff1 = pipe.zdiff("bar1", "bar2"); + Response> diff2 = pipe.zdiff("foo", "bar"); + Response> diff3 = pipe.zdiffWithScores("foo", "bar"); + + pipe.sync(); + + assertThat(diff1.get(), empty()); + assertThat(diff2.get(), contains("b")); + assertThat(diff3.get(), contains(new Tuple("b", 2.0d))); + + // binary + pipe.zadd(bfoo, 1.0, ba); + pipe.zadd(bfoo, 2.0, bb); + pipe.zadd(bbar, 1.0, ba); + + Response> bdiff1 = pipe.zdiff(bbar1, bbar2); + Response> bdiff2 = pipe.zdiff(bfoo, bbar); + Response> bdiff3 = pipe.zdiffWithScores(bfoo, bbar); + + pipe.sync(); + + assertThat(bdiff1.get(), empty()); + assertThat(bdiff2.get(), contains(bb)); + assertThat(bdiff3.get(), contains(new Tuple(bb, 2.0d))); + } + + @Test + public void zdiffstore() { + pipe.zadd("foo", 1.0, "a"); + pipe.zadd("foo", 2.0, "b"); + pipe.zadd("bar", 1.0, "a"); + + Response result1 = pipe.zdiffstore("bar3", "bar1", "bar2"); + Response result2 = pipe.zdiffstore("bar3", "foo", "bar"); + Response> items = pipe.zrange("bar3", 0, -1); + + pipe.sync(); + + assertThat(result1.get(), equalTo(0L)); + assertThat(result2.get(), equalTo(1L)); + assertThat(items.get(), contains("b")); + + // binary + pipe.zadd(bfoo, 1.0, ba); + pipe.zadd(bfoo, 2.0, bb); + pipe.zadd(bbar, 1.0, ba); + + Response bresult1 = pipe.zdiffstore(bbar3, bbar1, bbar2); + Response bresult2 = pipe.zdiffstore(bbar3, bfoo, bbar); + Response> bitems = pipe.zrange(bbar3, 0, -1); + + pipe.sync(); + + assertThat(bresult1.get(), equalTo(0L)); + assertThat(bresult2.get(), equalTo(1L)); + assertThat(bitems.get(), contains(bb)); + } + + @Test + public void zrandmember() { + Response item1 = pipe.zrandmember("foo"); + Response> items1 = pipe.zrandmember("foo", 1); + Response> items2 = pipe.zrandmemberWithScores("foo", 1); + + pipe.sync(); + + assertThat(item1.get(), nullValue()); + assertThat(items1.get(), empty()); + assertThat(items2.get(), empty()); + + Map hash = new HashMap<>(); + hash.put("bar1", 1d); + hash.put("bar2", 10d); + hash.put("bar3", 0.1d); + pipe.zadd("foo", hash); + + Response item2 = pipe.zrandmember("foo"); + Response> items3 = pipe.zrandmember("foo", 2); + Response> items4 = pipe.zrandmemberWithScores("foo", 2); + + pipe.sync(); + + assertThat(item2.get(), in(hash.keySet())); + assertThat(items3.get(), hasSize(2)); + assertThat(items4.get(), hasSize(2)); + items4.get().forEach(t -> assertEquals(hash.get(t.getElement()), t.getScore(), 0d)); + + // Binary + Response bitem1 = pipe.zrandmember(bfoo); + Response> bitems1 = pipe.zrandmember(bfoo, 1); + Response> bitems2 = pipe.zrandmemberWithScores(bfoo, 1); + + pipe.sync(); + + assertThat(bitem1.get(), nullValue()); + assertThat(bitems1.get(), empty()); + assertThat(bitems2.get(), empty()); + + Map bhash = new HashMap<>(); + bhash.put(bbar1, 1d); + bhash.put(bbar2, 10d); + bhash.put(bbar3, 0.1d); + pipe.zadd(bfoo, bhash); + + Response bitem2 = pipe.zrandmember(bfoo); + Response> bitems3 = pipe.zrandmember(bfoo, 2); + Response> bitems4 = pipe.zrandmemberWithScores(bfoo, 2); + + pipe.sync(); + + AssertUtil.assertByteArrayCollectionContains(bhash.keySet(), bitem2.get()); + assertThat(bitems3.get(), hasSize(2)); + assertThat(bitems4.get(), hasSize(2)); + bitems4.get().forEach(t -> assertEquals(getScoreFromByteMap(bhash, t.getBinaryElement()), t.getScore(), 0d)); + } + + private Double getScoreFromByteMap(Map bhash, byte[] key) { + for (Map.Entry en : bhash.entrySet()) { + if (Arrays.equals(en.getKey(), key)) { + return en.getValue(); + } + } + return null; + } + + @Test + public void zmpop() { + pipe.zadd("foo", 1d, "a", ZAddParams.zAddParams().nx()); + pipe.zadd("foo", 10d, "b", ZAddParams.zAddParams().nx()); + pipe.zadd("foo", 0.1d, "c", ZAddParams.zAddParams().nx()); + pipe.zadd("foo", 2d, "a", ZAddParams.zAddParams().nx()); + + Response>> single = pipe.zmpop(SortedSetOption.MAX, "foo"); + Response>> range = pipe.zmpop(SortedSetOption.MIN, 2, "foo"); + Response>> nullRange = pipe.zmpop(SortedSetOption.MAX, "foo"); + + pipe.sync(); + + assertThat(single.get().getValue(), contains(new Tuple("b", 10d))); + + assertThat(range.get().getValue(), contains( + new Tuple("c", 0.1d), + new Tuple("a", 1d) + )); + + assertThat(nullRange.get(), nullValue()); + } + + @Test + public void bzmpopSimple() { + pipe.zadd("foo", 1d, "a", ZAddParams.zAddParams().nx()); + pipe.zadd("foo", 10d, "b", ZAddParams.zAddParams().nx()); + pipe.zadd("foo", 0.1d, "c", ZAddParams.zAddParams().nx()); + pipe.zadd("foo", 2d, "a", ZAddParams.zAddParams().nx()); + + Response>> single = pipe.bzmpop(1L, SortedSetOption.MAX, "foo"); + Response>> range = pipe.bzmpop(1L, SortedSetOption.MIN, 2, "foo"); + Response>> nullRange = pipe.bzmpop(1L, SortedSetOption.MAX, "foo"); + + pipe.sync(); + + assertThat(single.get().getValue(), contains(new Tuple("b", 10d))); + + assertThat(range.get().getValue(), contains( + new Tuple("c", 0.1d), + new Tuple("a", 1d) + )); + + assertThat(nullRange.get(), nullValue()); + } +} From 24653e048b6f555295697791f72883cf435b4283 Mon Sep 17 00:00:00 2001 From: Gabriel Erzse Date: Thu, 14 Mar 2024 17:28:41 +0200 Subject: [PATCH 15/33] Streamline test execution (#3760) * Fix a flaky test It turns out that sometimes the slow log entry has a duration of zero, so cover for this case too. * Try to fix a flaky test * Streamline unit test execution in CI vs. locally The current way of running JUnit tests has some drawbacks. The CI executes tests by running multiple `mvn` commands. When running tests locally, it is tedious to run the same multiple commands, in order, for example, to get the same coverage as the CI gets. Ideally the tests are configured in the project itself, in the pom.xml file and by annotations on the tests, so that simply running `mvn test` will do everything needed. In order to achieve this, adapt the tests to be parameterized, so that JUnit takes care of running them with different RESP protocols. It is OK to use environment variables in general, for example for injecting connection details. But it is not OK to use environment variables for driving test execution, by injecting a RESP version and running the tests multiple times. If I have to run more than `mvn test`, it does not feel right. Some tests rely on static fields and @BeforeClass and @AfterClass annotations. These do not work well with parameterized tests, so remove the static and switch to @Before and @After annotations. The Makefile is a bit unpolished, i.e. the sequence of tasks is controlled manually when it could be controlled declaratively, and the `start` and `stop` tasks do not cover starting and stopping the Redis Stack docker. Take care of these aspects. All in all, now if I run `make test` I know I get the correct coverage in the JaCoCo report. And the CI can also just run `make test`, without additional work. * React to code review Add comments to clarify the intentions. Make more tests parameterized. Use a friendlier port number for Redis Stack. * Remove unnecessary Jedis object. Jedis object is now being created in every clearData() call. That removes the necessity of this object. * Comment of RedisJsonV1Test class protocol limit * Comment about default protocol * Polish a bit some documentation --------- Co-authored-by: Gabriel Erzse Co-authored-by: M Sazzadul Hoque <7600764+sazzad16@users.noreply.github.com> --- .github/workflows/integration.yml | 20 +--------- Makefile | 27 +++++++------ .../redis/clients/jedis/ACLJedisTest.java | 7 ++++ .../jedis/JedisShardedPubSubBaseTest.java | 2 +- .../java/redis/clients/jedis/JedisTest.java | 7 ++++ .../clients/jedis/MigratePipeliningTest.java | 8 ++++ .../redis/clients/jedis/PipeliningTest.java | 8 ++++ .../clients/jedis/TupleSortedSetTest.java | 8 ++++ .../commands/CommandsTestsParameters.java | 22 +++++++++++ .../jedis/AccessControlListCommandsTest.java | 8 ++++ .../jedis/AllKindOfValuesCommandsTest.java | 16 +++++--- .../jedis/BinaryValuesCommandsTest.java | 8 ++++ .../jedis/commands/jedis/BitCommandsTest.java | 8 ++++ .../commands/jedis/ClientCommandsTest.java | 7 ++++ .../commands/jedis/ControlCommandsTest.java | 8 ++++ .../jedis/commands/jedis/GeoCommandsTest.java | 8 ++++ .../commands/jedis/HashesCommandsTest.java | 8 ++++ .../jedis/HyperLogLogCommandsTest.java | 8 ++++ .../commands/jedis/JedisCommandsTestBase.java | 39 +++++++++++++++---- .../commands/jedis/ListCommandsTest.java | 8 ++++ .../jedis/commands/jedis/MigrateTest.java | 8 ++++ .../jedis/commands/jedis/ModuleTest.java | 8 ++++ .../commands/jedis/ObjectCommandsTest.java | 8 ++++ .../jedis/PublishSubscribeCommandsTest.java | 9 +++++ .../commands/jedis/ScriptingCommandsTest.java | 10 ++++- .../jedis/commands/jedis/SetCommandsTest.java | 8 ++++ .../commands/jedis/SlowlogCommandsTest.java | 10 ++++- .../commands/jedis/SortedSetCommandsTest.java | 8 ++++ .../commands/jedis/SortingCommandsTest.java | 8 ++++ .../commands/jedis/StreamsCommandsTest.java | 8 ++++ .../jedis/StringValuesCommandsTest.java | 9 +++++ .../jedis/TransactionCommandsTest.java | 8 ++++ .../commands/jedis/VariadicCommandsTest.java | 9 +++++ .../AllKindOfValuesCommandsTestBase.java | 13 ++++--- .../unified/BinaryValuesCommandsTestBase.java | 5 +++ .../commands/unified/BitCommandsTestBase.java | 5 +++ .../commands/unified/GeoCommandsTestBase.java | 5 +++ .../unified/HashesCommandsTestBase.java | 5 +++ .../unified/HyperLogLogCommandsTestBase.java | 5 +++ .../unified/ListCommandsTestBase.java | 5 +++ .../commands/unified/SetCommandsTestBase.java | 11 ++++-- .../unified/SortedSetCommandsTestBase.java | 5 +++ .../unified/StringValuesCommandsTestBase.java | 6 +++ .../unified/UnifiedJedisCommandsTestBase.java | 32 ++++++++++++++- .../ClusterAllKindOfValuesCommandsTest.java | 10 ++++- .../ClusterBinaryValuesCommandsTest.java | 10 ++++- .../cluster/ClusterBitCommandsTest.java | 10 ++++- .../cluster/ClusterCommandsTestHelper.java | 6 +-- .../cluster/ClusterGeoCommandsTest.java | 10 ++++- .../ClusterHyperLogLogCommandsTest.java | 10 ++++- .../cluster/ClusterListCommandsTest.java | 10 ++++- .../cluster/ClusterSetCommandsTest.java | 10 ++++- .../cluster/ClusterSortedSetCommandsTest.java | 10 ++++- .../ClusterStringValuesCommandsTest.java | 10 ++++- .../pipeline/GeoPipelineCommandsTest.java | 17 +++----- .../pipeline/HashesPipelineCommandsTest.java | 31 ++++----------- .../pipeline/PipelineCommandsTestBase.java | 35 +++++++++++++++-- .../SortedSetPipelineCommandsTest.java | 18 ++++----- .../pipeline/StreamsPipelineCommandsTest.java | 17 +++----- .../PooledAllKindOfValuesCommandsTest.java | 24 +++++++----- .../PooledBinaryValuesCommandsTest.java | 24 +++++++----- .../unified/pooled/PooledBitCommandsTest.java | 24 +++++++----- .../pooled/PooledCommandsTestHelper.java | 19 ++++----- .../unified/pooled/PooledGeoCommandsTest.java | 24 +++++++----- .../pooled/PooledHashesCommandsTest.java | 24 +++++++----- .../pooled/PooledHyperLogLogCommandsTest.java | 24 +++++++----- .../pooled/PooledListCommandsTest.java | 24 +++++++----- .../pooled/PooledMiscellaneousTest.java | 22 ++++++----- .../unified/pooled/PooledSetCommandsTest.java | 24 +++++++----- .../pooled/PooledSortedSetCommandsTest.java | 24 +++++++----- .../PooledStringValuesCommandsTest.java | 24 +++++++----- .../modules/RedisModuleCommandsTestBase.java | 36 +++++++++++++---- .../modules/RedisModulesPipelineTest.java | 10 ++++- .../jedis/modules/bloom/BloomTest.java | 8 ++++ .../clients/jedis/modules/bloom/CMSTest.java | 8 ++++ .../jedis/modules/bloom/CuckooTest.java | 8 ++++ .../jedis/modules/bloom/TDigestTest.java | 8 ++++ .../clients/jedis/modules/bloom/TopKTest.java | 8 ++++ .../jedis/modules/gears/GearsTest.java | 7 ++++ .../jedis/modules/graph/GraphAPITest.java | 8 ++++ .../modules/graph/GraphPipelineTest.java | 9 +++++ .../modules/graph/GraphTransactionTest.java | 9 +++++ .../jedis/modules/graph/GraphValuesTest.java | 9 +++++ .../jedis/modules/json/RedisJsonV1Test.java | 10 +++-- .../jedis/modules/json/RedisJsonV2Test.java | 16 +++++--- .../jedis/modules/search/AggregationTest.java | 7 ++++ .../jedis/modules/search/JsonSearchTest.java | 10 ++++- .../search/JsonSearchWithGsonTest.java | 9 +++++ .../modules/search/SearchConfigTest.java | 9 +++++ .../search/SearchDefaultDialectTest.java | 8 ++++ .../jedis/modules/search/SearchTest.java | 7 ++++ .../modules/search/SearchWithParamsTest.java | 7 ++++ .../jedis/modules/search/SpellCheckTest.java | 8 ++++ .../jedis/modules/search/SuggestionTest.java | 8 ++++ .../modules/timeseries/TimeSeriesTest.java | 9 ++++- .../clients/jedis/util/RedisProtocolUtil.java | 21 ---------- 96 files changed, 906 insertions(+), 289 deletions(-) create mode 100644 src/test/java/redis/clients/jedis/commands/CommandsTestsParameters.java delete mode 100644 src/test/java/redis/clients/jedis/util/RedisProtocolUtil.java diff --git a/.github/workflows/integration.yml b/.github/workflows/integration.yml index fd651fa6a41..5b78b3124b3 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 96d106b0009..1800f00d7e5 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 81517b55569..a6a9deff771 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 fb1ecdd87a5..68d84553920 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 e9520ff3948..52d8c80c02a 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 ebd4b31eb96..f8e7d8278c1 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 527b9dfc6d5..fffaa06a89d 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 676a19ffa5e..59efcb3435c 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 00000000000..701ed06b087 --- /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 9d4f3c65684..c8f56bc7eb9 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 a681d4f4d81..e7381a7440b 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 00c6def7c2d..3a348fecc99 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 ab137c7edc2..01cc61b3c98 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 40aff1045cb..2a4657ecd5a 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 cb95a9489b6..0287095e4c1 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 ab8d85558a5..04fe32ee84b 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 a30740dcf65..c07adc86b4e 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 9b989cf9e14..33670707079 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 c69302d3c5a..1d40a22b5fc 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 6f6fa807497..194bed29ae3 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 1a0f7a0b6e0..529d64ebbf6 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 1d4a9d981b5..bef13001ef7 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 79b30ced9cf..0f4cf70b150 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 7b11d323ca7..75968fdc041 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 1e258dbad3b..5f26baec587 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 4d29392fcef..d2b660b5b4a 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 66806b933ab..c62daa4aa1c 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 8b5711cb705..68606840287 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 e56fa6447af..1d0a976f417 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 6b28f9ed19f..acadc0b75d8 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 fb58569e828..44525e072fd 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 a2153e6862b..5130552009b 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 35c3127cc9f..337aceab7b4 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 25ecad1eea9..f31c100988e 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 941d70c3831..48a3ef7e6d8 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 8cf5caf3f03..21019008892 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 e93042eed93..63cd661ccb4 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 d06edf38ecb..401f29dbe3b 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 79a82f69f26..06b6d312dfc 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 ddbe7f779a3..05c741de41b 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 eed0801a864..d4c14562185 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 fed8fb26035..3f56a91459e 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 a666671a156..8309978fad7 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 cbd046231db..c4aabad5a3e 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 c71d5eb7cf4..e0f5c7af26d 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 8b70e29271b..78521a7addd 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 64f4f8376cc..078e8d88513 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 238f3044e2a..6c8f3e25ccd 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 76ef6d1c736..75d5902a8ea 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 49da95e0264..461ac873c41 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 10af17a110b..666752050b5 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 cd0bc2234fd..75d2b6bbdce 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 84748693f38..9151b0c52b0 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 c7b743f5e44..a8f980bd9a2 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 cbab082b7e8..ccfd70bc8fc 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 e276441e176..d8d9f031bd6 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 c162954509c..55dfec6e98c 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 12a2282e277..a6915ce3a75 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 066ca98fb06..119f2331982 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 3e1d8a0c393..a1b53de023e 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 7c94f0165a7..04a5778fcca 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 60ce669cd2c..5764a1bbfa1 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 82ecc600c83..82c84f8890c 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 d94753f32e4..3affb40afa9 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 a628336a975..bb5741d967b 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 aca21523da6..6b2b2f3dd2c 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 4ccd3de00a0..5d38fe43d58 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 fc917e4e47c..6f2f42e7542 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 00b7420e11b..2be9dbbf1cc 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 38b4f954508..c3d0b76ecea 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 34fd50c776b..c9a1c39ae18 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 20bbe9ae924..9e21fba23fd 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 50b48854da5..db0ba8223c1 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 8a8917b8c82..c97eabd63f8 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 6604ba6cbc7..2ff7fd9a0a7 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 d46145c3789..8d6027acbeb 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 586b544ab1c..36d85018ef5 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 706d57ef82d..29a8a5738a4 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 e4dc10a82d5..117094b9b8d 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 694a1ddf788..46b135070c9 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 22d6894333a..f69dd06712c 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 c63996e7b58..9a7a8e502c9 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 8761e0f7862..ea9c6a77991 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 5843b6e06a5..d281b332659 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 f36832da518..6168c2e2de8 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 b594f28dd1c..cefdfbe5d34 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 79485634d78..822f7bc8041 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 00ccada3bd6..5ef29679fd6 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 bda3cbe4d15..4e93303a4a9 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 b803b1eceb0..34adccf1d56 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 b8656ff3445..1bc6cb345db 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 a81ceb78217..897da8eece9 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 508ff4441af..bd7e529c55f 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 626b26966ea..2341b835cdd 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 12c424f9e1e..fe0f7d1604a 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 71f52b42a3a..00000000000 --- 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; - } -} From 33b43cffa05eefb7e81a757e6a97eb51a8371824 Mon Sep 17 00:00:00 2001 From: Gabriel Erzse Date: Fri, 15 Mar 2024 19:40:46 +0200 Subject: [PATCH 16/33] Fix typo in SetPipelineCommands method name (#3773) * Fix typo in SetPipelineCommands method name One method in the SetPipelineCommands interface does not respect the general naming pattern. Add a new method that respects naming, and deprecate the other one. * Refine javadoc for the deprecated method Co-authored-by: M Sazzadul Hoque <7600764+sazzad16@users.noreply.github.com> --------- Co-authored-by: Gabriel Erzse Co-authored-by: M Sazzadul Hoque <7600764+sazzad16@users.noreply.github.com> --- src/main/java/redis/clients/jedis/PipeliningBase.java | 2 +- .../clients/jedis/commands/SetPipelineCommands.java | 10 +++++++++- .../redis/clients/jedis/ClusterPipeliningTest.java | 4 +++- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/main/java/redis/clients/jedis/PipeliningBase.java b/src/main/java/redis/clients/jedis/PipeliningBase.java index e9b6d49b736..62b773cdab2 100644 --- a/src/main/java/redis/clients/jedis/PipeliningBase.java +++ b/src/main/java/redis/clients/jedis/PipeliningBase.java @@ -786,7 +786,7 @@ public Response> sdiff(String... keys) { } @Override - public Response sdiffStore(String dstKey, String... keys) { + public Response sdiffstore(String dstKey, String... keys) { return appendCommand(commandObjects.sdiffstore(dstKey, keys)); } diff --git a/src/main/java/redis/clients/jedis/commands/SetPipelineCommands.java b/src/main/java/redis/clients/jedis/commands/SetPipelineCommands.java index 4d915e31e7e..948c04ad69d 100644 --- a/src/main/java/redis/clients/jedis/commands/SetPipelineCommands.java +++ b/src/main/java/redis/clients/jedis/commands/SetPipelineCommands.java @@ -37,7 +37,15 @@ default Response> sscan(String key, String cursor) { Response> sdiff(String... keys); - Response sdiffStore(String dstKey, String... keys); + Response sdiffstore(String dstKey, String... keys); + + /** + * @deprecated Use {@link SetPipelineCommands#sdiffstore(java.lang.String, java.lang.String...)}. + */ + @Deprecated + default Response sdiffStore(String dstKey, String... keys) { + return sdiffstore(dstKey, keys); + } Response> sinter(String... keys); diff --git a/src/test/java/redis/clients/jedis/ClusterPipeliningTest.java b/src/test/java/redis/clients/jedis/ClusterPipeliningTest.java index 3ed45bae63e..ff196ec4ea6 100644 --- a/src/test/java/redis/clients/jedis/ClusterPipeliningTest.java +++ b/src/test/java/redis/clients/jedis/ClusterPipeliningTest.java @@ -527,7 +527,8 @@ public void clusterPipelineSet() { Response r1 = p.sadd("my{set}", "hello", "hello", "world", "foo", "bar"); p.sadd("mynew{set}", "hello", "hello", "world"); Response> r2 = p.sdiff("my{set}", "mynew{set}"); - Response r3 = p.sdiffStore("diffset{set}", "my{set}", "mynew{set}"); + Response r3deprecated = p.sdiffStore("diffset{set}deprecated", "my{set}", "mynew{set}"); + Response r3 = p.sdiffstore("diffset{set}", "my{set}", "mynew{set}"); Response> r4 = p.smembers("diffset{set}"); Response> r5 = p.sinter("my{set}", "mynew{set}"); Response r6 = p.sinterstore("interset{set}", "my{set}", "mynew{set}"); @@ -547,6 +548,7 @@ public void clusterPipelineSet() { p.sync(); assertEquals(Long.valueOf(4), r1.get()); assertEquals(diff, r2.get()); + assertEquals(Long.valueOf(diff.size()), r3deprecated.get()); assertEquals(Long.valueOf(diff.size()), r3.get()); assertEquals(diff, r4.get()); assertEquals(inter, r5.get()); From 3aadb28cb4c0bb8a328e7f0b9af999860c574ff7 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 18 Mar 2024 13:38:54 +0600 Subject: [PATCH 17/33] Bump org.apache.maven.plugins:maven-gpg-plugin from 3.1.0 to 3.2.0 (#3775) Bumps [org.apache.maven.plugins:maven-gpg-plugin](https://github.com/apache/maven-gpg-plugin) from 3.1.0 to 3.2.0. - [Release notes](https://github.com/apache/maven-gpg-plugin/releases) - [Commits](https://github.com/apache/maven-gpg-plugin/compare/maven-gpg-plugin-3.1.0...maven-gpg-plugin-3.2.0) --- updated-dependencies: - dependency-name: org.apache.maven.plugins:maven-gpg-plugin dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 5007f12e311..5e7b9ceff84 100644 --- a/pom.xml +++ b/pom.xml @@ -300,7 +300,7 @@ maven-gpg-plugin - 3.1.0 + 3.2.0 --pinentry-mode From a9d3d3e4b37dc48a8cc9bfac053b4ba6c96df4ca Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 18 Mar 2024 13:39:04 +0600 Subject: [PATCH 18/33] Bump jackson.version from 2.16.2 to 2.17.0 (#3776) Bumps `jackson.version` from 2.16.2 to 2.17.0. Updates `com.fasterxml.jackson.core:jackson-databind` from 2.16.2 to 2.17.0 - [Commits](https://github.com/FasterXML/jackson/commits) Updates `com.fasterxml.jackson.datatype:jackson-datatype-jsr310` from 2.16.2 to 2.17.0 --- updated-dependencies: - dependency-name: com.fasterxml.jackson.core:jackson-databind dependency-type: direct:development update-type: version-update:semver-minor - dependency-name: com.fasterxml.jackson.datatype:jackson-datatype-jsr310 dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 5e7b9ceff84..71595dc211f 100644 --- a/pom.xml +++ b/pom.xml @@ -49,7 +49,7 @@ redis.clients.jedis 1.7.36 1.7.1 - 2.16.2 + 2.17.0 3.2.5 From 56ef26aed653aefad4bcb93f439b5b1c61f11bcc Mon Sep 17 00:00:00 2001 From: Gabriel Erzse Date: Mon, 18 Mar 2024 13:06:41 +0200 Subject: [PATCH 19/33] Use expiryOption in PipelineBase.expireAt (#3777) One of the expireAt methods in PipelineBase is not using its ExpiryOption argument. Fix this by forwarding that argument too to the commandObjects. Co-authored-by: Gabriel Erzse --- src/main/java/redis/clients/jedis/PipeliningBase.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/redis/clients/jedis/PipeliningBase.java b/src/main/java/redis/clients/jedis/PipeliningBase.java index 62b773cdab2..945d34f615d 100644 --- a/src/main/java/redis/clients/jedis/PipeliningBase.java +++ b/src/main/java/redis/clients/jedis/PipeliningBase.java @@ -2088,7 +2088,7 @@ public Response expireAt(byte[] key, long unixTime) { @Override public Response expireAt(byte[] key, long unixTime, ExpiryOption expiryOption) { - return appendCommand(commandObjects.expireAt(key, unixTime)); + return appendCommand(commandObjects.expireAt(key, unixTime, expiryOption)); } @Override From 812a291e415bc747606dd89e8e0f40f8096acbe3 Mon Sep 17 00:00:00 2001 From: Gabriel Erzse Date: Tue, 19 Mar 2024 11:01:49 +0200 Subject: [PATCH 20/33] Extensive unit tests for PipeliningBase (#3778) * Extensive unit tests for PipeliningBase Add extensive unit tests for the PipeliningBase abstract class. Since this class holds a lot of functionality for its subclasses, it makes sense to test it in isolation. And since the functionality is very repetitive, it makes sense to use mocking. Basically this abstract class just shuffles commands around from a CommandObjects to its subclasses, and this can be covered very well with mocked tests. * Fix flaky test A slow log test seems to sometimes get a duration of zero for an operation. Cover this case too in the assertion. --------- Co-authored-by: Gabriel Erzse --- .../clients/jedis/PipeliningBaseTest.java | 10502 ++++++++++++++++ .../commands/jedis/SlowlogCommandsTest.java | 2 +- 2 files changed, 10503 insertions(+), 1 deletion(-) create mode 100644 src/test/java/redis/clients/jedis/PipeliningBaseTest.java diff --git a/src/test/java/redis/clients/jedis/PipeliningBaseTest.java b/src/test/java/redis/clients/jedis/PipeliningBaseTest.java new file mode 100644 index 00000000000..2d096ba5700 --- /dev/null +++ b/src/test/java/redis/clients/jedis/PipeliningBaseTest.java @@ -0,0 +1,10502 @@ +package redis.clients.jedis; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.contains; +import static org.hamcrest.Matchers.hasSize; +import static org.hamcrest.Matchers.is; +import static org.mockito.Mockito.doNothing; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import java.util.AbstractMap; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.stream.Collectors; + +import com.google.gson.JsonObject; +import org.json.JSONArray; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.junit.MockitoJUnitRunner; +import redis.clients.jedis.args.BitCountOption; +import redis.clients.jedis.args.BitOP; +import redis.clients.jedis.args.ExpiryOption; +import redis.clients.jedis.args.FlushMode; +import redis.clients.jedis.args.FunctionRestorePolicy; +import redis.clients.jedis.args.GeoUnit; +import redis.clients.jedis.args.ListDirection; +import redis.clients.jedis.args.ListPosition; +import redis.clients.jedis.args.Rawable; +import redis.clients.jedis.args.SortedSetOption; +import redis.clients.jedis.bloom.BFInsertParams; +import redis.clients.jedis.bloom.BFReserveParams; +import redis.clients.jedis.bloom.CFInsertParams; +import redis.clients.jedis.bloom.CFReserveParams; +import redis.clients.jedis.bloom.TDigestMergeParams; +import redis.clients.jedis.commands.ProtocolCommand; +import redis.clients.jedis.graph.GraphCommandObjects; +import redis.clients.jedis.graph.ResultSet; +import redis.clients.jedis.json.JsonObjectMapper; +import redis.clients.jedis.json.JsonSetParams; +import redis.clients.jedis.json.Path; +import redis.clients.jedis.json.Path2; +import redis.clients.jedis.params.BitPosParams; +import redis.clients.jedis.params.GeoAddParams; +import redis.clients.jedis.params.GeoRadiusParam; +import redis.clients.jedis.params.GeoRadiusStoreParam; +import redis.clients.jedis.params.GeoSearchParam; +import redis.clients.jedis.params.GetExParams; +import redis.clients.jedis.params.LCSParams; +import redis.clients.jedis.params.LPosParams; +import redis.clients.jedis.params.MigrateParams; +import redis.clients.jedis.params.RestoreParams; +import redis.clients.jedis.params.ScanParams; +import redis.clients.jedis.params.SetParams; +import redis.clients.jedis.params.SortingParams; +import redis.clients.jedis.params.XAddParams; +import redis.clients.jedis.params.XAutoClaimParams; +import redis.clients.jedis.params.XClaimParams; +import redis.clients.jedis.params.XPendingParams; +import redis.clients.jedis.params.XReadGroupParams; +import redis.clients.jedis.params.XReadParams; +import redis.clients.jedis.params.XTrimParams; +import redis.clients.jedis.params.ZAddParams; +import redis.clients.jedis.params.ZIncrByParams; +import redis.clients.jedis.params.ZParams; +import redis.clients.jedis.params.ZRangeParams; +import redis.clients.jedis.resps.FunctionStats; +import redis.clients.jedis.resps.GeoRadiusResponse; +import redis.clients.jedis.resps.LCSMatchResult; +import redis.clients.jedis.resps.LibraryInfo; +import redis.clients.jedis.resps.ScanResult; +import redis.clients.jedis.resps.StreamConsumerInfo; +import redis.clients.jedis.resps.StreamConsumersInfo; +import redis.clients.jedis.resps.StreamEntry; +import redis.clients.jedis.resps.StreamFullInfo; +import redis.clients.jedis.resps.StreamGroupInfo; +import redis.clients.jedis.resps.StreamInfo; +import redis.clients.jedis.resps.StreamPendingEntry; +import redis.clients.jedis.resps.StreamPendingSummary; +import redis.clients.jedis.resps.Tuple; +import redis.clients.jedis.search.FTCreateParams; +import redis.clients.jedis.search.FTSearchParams; +import redis.clients.jedis.search.FTSpellCheckParams; +import redis.clients.jedis.search.IndexOptions; +import redis.clients.jedis.search.Query; +import redis.clients.jedis.search.Schema; +import redis.clients.jedis.search.SearchResult; +import redis.clients.jedis.search.aggr.AggregationBuilder; +import redis.clients.jedis.search.aggr.AggregationResult; +import redis.clients.jedis.search.schemafields.SchemaField; +import redis.clients.jedis.search.schemafields.TextField; +import redis.clients.jedis.timeseries.AggregationType; +import redis.clients.jedis.timeseries.TSAlterParams; +import redis.clients.jedis.timeseries.TSCreateParams; +import redis.clients.jedis.timeseries.TSElement; +import redis.clients.jedis.timeseries.TSGetParams; +import redis.clients.jedis.timeseries.TSMGetElement; +import redis.clients.jedis.timeseries.TSMGetParams; +import redis.clients.jedis.timeseries.TSMRangeElements; +import redis.clients.jedis.timeseries.TSMRangeParams; +import redis.clients.jedis.timeseries.TSRangeParams; +import redis.clients.jedis.util.KeyValue; + +/** + * Exhaustive unit tests for {@link PipeliningBase}, using Mockito. Given that {@link PipeliningBase} + * is, essentially, only requesting commands from a {@link CommandObjects} instance and sending them + * to its subclasses via {@link PipeliningBase#appendCommand(CommandObject)}, and given that it has + * many methods, using mocks is the most convenient and reliable way to completely test it. + */ +@RunWith(MockitoJUnitRunner.class) +public class PipeliningBaseTest { + + /** + * Used for JSON tests. + */ + @SuppressWarnings("unused") + private static class MyBean { + String field1; + String field2; + } + + /** + * {@link PipeliningBase} under-test. Given that it is an abstract class, an in-place implementation + * is used, that collects commands in a list. + */ + private PipeliningBase pipeliningBase; + + /** + * Accumulates commands sent by the {@link PipeliningBase} under-test to its subclass. + */ + private final List> commands = new ArrayList<>(); + + /** + * {@link CommandObjects} instance used by the {@link PipeliningBase} under-test. Depending on + * the test case, it is trained to return one of the mock {@link CommandObject} instances below. + */ + @Mock + private CommandObjects commandObjects; + + /** + * The {@link GraphCommandObjects} instance used by the {@link PipeliningBase} under-test. + */ + @Mock + private GraphCommandObjects graphCommandObjects; + + /** + * Mock {@link Response} that is returned by {@link PipeliningBase} from the + * {@link PipeliningBase#appendCommand(CommandObject)} method. Using such a mock makes + * it easy to assert. + */ + @Mock + private Response predefinedResponse; + + // Below follows a list of mocked CommandObjects, one per type. This is the cleanest way to create + // mocks, given that CommandObject is a generic class. Using {@code Mockito.mock(...)} yields too + // many warnings related to generics. + // To make the code more readable, try to keep the list sorted alphabetically, and without automatic + // reformatting. + + // @formatter:off + @Mock private CommandObject aggregationResultCommandObject; + @Mock private CommandObject booleanCommandObject; + @Mock private CommandObject> classCommandObject; + @Mock private CommandObject doubleCommandObject; + @Mock private CommandObject functionStatsCommandObject; + @Mock private CommandObject> keyValueLongDoubleCommandObject; + @Mock private CommandObject> keyValueLongLongCommandObject; + @Mock private CommandObject>> keyValueStringListStringCommandObject; + @Mock private CommandObject>> keyValueStringListTupleCommandObject; + @Mock private CommandObject> keyValueStringStringCommandObject; + @Mock private CommandObject> keyValueStringTupleCommandObject; + @Mock private CommandObject>> keyValueBytesListTupleCommandObject; + @Mock private CommandObject>> keyValueBytesListBytesCommandObject; + @Mock private CommandObject> keyValueBytesTupleCommandObject; + @Mock private CommandObject> keyValueBytesBytesCommandObject; + @Mock private CommandObject lcsMatchResultCommandObject; + @Mock private CommandObject> listBooleanCommandObject; + @Mock private CommandObject>> listClassCommandObject; + @Mock private CommandObject> listDoubleCommandObject; + @Mock private CommandObject> listGeoCoordinateCommandObject; + @Mock private CommandObject> listGeoRadiusResponseCommandObject; + @Mock private CommandObject> listJsonArrayCommandObject; + @Mock private CommandObject> listLibraryInfoCommandObject; + @Mock private CommandObject> listLongCommandObject; + @Mock private CommandObject>>> listEntryStringListStreamEntryCommandObject; + @Mock private CommandObject>> listEntryStringStringCommandObject; + @Mock private CommandObject>> listEntryBytesBytesCommandObject; + @Mock private CommandObject> listMyBeanCommandObject; + @Mock private CommandObject> listObjectCommandObject; + @Mock private CommandObject> listStreamConsumerInfoCommandObject; + @Mock private CommandObject> listStreamConsumersInfoCommandObject; + @Mock private CommandObject> listStreamEntryCommandObject; + @Mock private CommandObject> listStreamEntryIdCommandObject; + @Mock private CommandObject> listStreamGroupInfoCommandObject; + @Mock private CommandObject> listStreamPendingEntryCommandObject; + @Mock private CommandObject> listStringCommandObject; + @Mock private CommandObject> listTsElementCommandObject; + @Mock private CommandObject> listTupleCommandObject; + @Mock private CommandObject> listBytesCommandObject; + @Mock private CommandObject longCommandObject; + @Mock private CommandObject> entryLongBytesCommandObject; + @Mock private CommandObject>> entryStreamEntryIdListStreamEntryCommandObject; + @Mock private CommandObject>> entryStreamEntryIdListStreamEntryIdCommandObject; + @Mock private CommandObject>> mapStringListStringCommandObject; + @Mock private CommandObject> mapStringLongCommandObject; + @Mock private CommandObject>> mapStringMapStringDoubleCommandObject; + @Mock private CommandObject> mapStringObjectCommandObject; + @Mock private CommandObject> mapStringStringCommandObject; + @Mock private CommandObject> mapStringTsmGetElementCommandObject; + @Mock private CommandObject> mapStringTsmRangeElementsCommandObject; + @Mock private CommandObject> mapBytesBytesCommandObject; + @Mock private CommandObject myBeanCommandObject; + @Mock private CommandObject objectCommandObject; + @Mock private CommandObject resultSetCommandObject; + @Mock private CommandObject>> scanResultEntryStringStringCommandObject; + @Mock private CommandObject>> scanResultEntryBytesBytesCommandObject; + @Mock private CommandObject> scanResultStringCommandObject; + @Mock private CommandObject> scanResultTupleCommandObject; + @Mock private CommandObject> scanResultBytesCommandObject; + @Mock private CommandObject searchResultCommandObject; + @Mock private CommandObject> setStringCommandObject; + @Mock private CommandObject> setBytesCommandObject; + @Mock private CommandObject streamEntryIdCommandObject; + @Mock private CommandObject streamFullInfoCommandObject; + @Mock private CommandObject streamInfoCommandObject; + @Mock private CommandObject streamPendingSummaryCommandObject; + @Mock private CommandObject stringCommandObject; + @Mock private CommandObject tsElementCommandObject; + @Mock private CommandObject tupleCommandObject; + @Mock private CommandObject bytesCommandObject; + // @formatter:on + + /** + * Prepare a concrete implementation of {@link PipeliningBase} that collects all commands + * in a list, so that asserts can be run on the content of the list. + *

+ * Most of the test methods will only test one specific method of {@link PipeliningBase}, + * so only one command will be collected. + *

+ * At the end of this test class there are tests that check multiple methods of + * {@link PipeliningBase}. + */ + @Before + public void setUp() { + pipeliningBase = new PipeliningBase(commandObjects) { + + @Override + @SuppressWarnings("unchecked") + protected Response appendCommand(CommandObject commandObject) { + // Collect the command in the list. + commands.add(commandObject); + // Return a well known response, that can be asserted in the test cases. + return (Response) predefinedResponse; + } + }; + + pipeliningBase.setGraphCommands(graphCommandObjects); + } + + @Test + public void testExists() { + when(commandObjects.exists("key")).thenReturn(booleanCommandObject); + + Response result = pipeliningBase.exists("key"); + + assertThat(commands, contains(booleanCommandObject)); + assertThat(result, is(predefinedResponse)); + } + + @Test + public void testExistsMultipleKeys() { + when(commandObjects.exists("key1", "key2", "key3")).thenReturn(longCommandObject); + + Response response = pipeliningBase.exists("key1", "key2", "key3"); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testPersist() { + when(commandObjects.persist("key")).thenReturn(longCommandObject); + + Response response = pipeliningBase.persist("key"); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testType() { + when(commandObjects.type("key")).thenReturn(stringCommandObject); + + Response response = pipeliningBase.type("key"); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testDump() { + when(commandObjects.dump("key")).thenReturn(bytesCommandObject); + + Response response = pipeliningBase.dump("key"); + + assertThat(commands, contains(bytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testRestore() { + byte[] serializedValue = new byte[]{ 1, 2, 3 }; + long ttl = 1000L; + + when(commandObjects.restore("key", ttl, serializedValue)).thenReturn(stringCommandObject); + + Response response = pipeliningBase.restore("key", ttl, serializedValue); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testRestoreWithParams() { + byte[] serializedValue = new byte[]{ 1, 2, 3 }; + long ttl = 1000L; + RestoreParams params = new RestoreParams(); + + when(commandObjects.restore("key", ttl, serializedValue, params)).thenReturn(stringCommandObject); + + Response response = pipeliningBase.restore("key", ttl, serializedValue, params); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testExpire() { + when(commandObjects.expire("key", 60)).thenReturn(longCommandObject); + + Response response = pipeliningBase.expire("key", 60); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testExpireWithExpiryOption() { + when(commandObjects.expire("key", 60, ExpiryOption.NX)).thenReturn(longCommandObject); + + Response response = pipeliningBase.expire("key", 60, ExpiryOption.NX); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testPexpire() { + when(commandObjects.pexpire("key", 100000)).thenReturn(longCommandObject); + + Response response = pipeliningBase.pexpire("key", 100000); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testPexpireWithExpiryOption() { + when(commandObjects.pexpire("key", 100000, ExpiryOption.NX)).thenReturn(longCommandObject); + + Response response = pipeliningBase.pexpire("key", 100000, ExpiryOption.NX); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testExpireTime() { + when(commandObjects.expireTime("key")).thenReturn(longCommandObject); + + Response response = pipeliningBase.expireTime("key"); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testPexpireTime() { + when(commandObjects.pexpireTime("key")).thenReturn(longCommandObject); + + Response response = pipeliningBase.pexpireTime("key"); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testExpireAt() { + int unixTime = 1609459200; + + when(commandObjects.expireAt("key", unixTime)).thenReturn(longCommandObject); + + Response response = pipeliningBase.expireAt("key", unixTime); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testExpireAtWithExpiryOption() { + int unixTime = 1609459200; + + when(commandObjects.expireAt("key", unixTime, ExpiryOption.NX)).thenReturn(longCommandObject); + + Response response = pipeliningBase.expireAt("key", unixTime, ExpiryOption.NX); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testPexpireAt() { + long millisecondsTimestamp = 1609459200000L; + + when(commandObjects.pexpireAt("key", millisecondsTimestamp)).thenReturn(longCommandObject); + + Response response = pipeliningBase.pexpireAt("key", millisecondsTimestamp); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testPexpireAtWithExpiryOption() { + long millisecondsTimestamp = 1609459200000L; + + when(commandObjects.pexpireAt("key", millisecondsTimestamp, ExpiryOption.NX)).thenReturn(longCommandObject); + + Response response = pipeliningBase.pexpireAt("key", millisecondsTimestamp, ExpiryOption.NX); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testTtl() { + when(commandObjects.ttl("key")).thenReturn(longCommandObject); + + Response response = pipeliningBase.ttl("key"); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testPttl() { + when(commandObjects.pttl("key")).thenReturn(longCommandObject); + + Response response = pipeliningBase.pttl("key"); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testTouchSingleKey() { + when(commandObjects.touch("key")).thenReturn(longCommandObject); + + Response response = pipeliningBase.touch("key"); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testTouchMultipleKeys() { + String[] keys = { "key1", "key2", "key3" }; + + when(commandObjects.touch(keys)).thenReturn(longCommandObject); + + Response response = pipeliningBase.touch(keys); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testSortSingleKey() { + when(commandObjects.sort("key")).thenReturn(listStringCommandObject); + + Response> response = pipeliningBase.sort("key"); + + assertThat(commands, contains(listStringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testSortSingleKeyStore() { + when(commandObjects.sort("key", "dstKey")).thenReturn(longCommandObject); + + Response response = pipeliningBase.sort("key", "dstKey"); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testSortWithParams() { + SortingParams sortingParams = new SortingParams(); + + when(commandObjects.sort("key", sortingParams)).thenReturn(listStringCommandObject); + + Response> response = pipeliningBase.sort("key", sortingParams); + + assertThat(commands, contains(listStringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testSortWithParamsStore() { + SortingParams sortingParams = new SortingParams(); + + when(commandObjects.sort("key", sortingParams, "dstKey")).thenReturn(longCommandObject); + + Response response = pipeliningBase.sort("key", sortingParams, "dstKey"); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testSortReadonly() { + SortingParams sortingParams = new SortingParams(); + + when(commandObjects.sortReadonly("key", sortingParams)).thenReturn(listStringCommandObject); + + Response> response = pipeliningBase.sortReadonly("key", sortingParams); + + assertThat(commands, contains(listStringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testDelSingleKey() { + when(commandObjects.del("key")).thenReturn(longCommandObject); + + Response response = pipeliningBase.del("key"); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testDelMultipleKeys() { + String[] keys = { "key1", "key2", "key3" }; + + when(commandObjects.del(keys)).thenReturn(longCommandObject); + + Response response = pipeliningBase.del(keys); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testUnlinkSingleKey() { + when(commandObjects.unlink("key")).thenReturn(longCommandObject); + + Response response = pipeliningBase.unlink("key"); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testUnlinkMultipleKeys() { + String[] keys = { "key1", "key2", "key3" }; + + when(commandObjects.unlink(keys)).thenReturn(longCommandObject); + + Response response = pipeliningBase.unlink(keys); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testCopy() { + when(commandObjects.copy("srcKey", "dstKey", true)).thenReturn(booleanCommandObject); + + Response response = pipeliningBase.copy("srcKey", "dstKey", true); + + assertThat(commands, contains(booleanCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testRename() { + when(commandObjects.rename("oldkey", "newkey")).thenReturn(stringCommandObject); + + Response response = pipeliningBase.rename("oldkey", "newkey"); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testRenamenx() { + when(commandObjects.renamenx("oldkey", "newkey")).thenReturn(longCommandObject); + + Response response = pipeliningBase.renamenx("oldkey", "newkey"); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testMemoryUsageSingleKey() { + when(commandObjects.memoryUsage("key")).thenReturn(longCommandObject); + + Response response = pipeliningBase.memoryUsage("key"); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testMemoryUsageWithSamples() { + when(commandObjects.memoryUsage("key", 10)).thenReturn(longCommandObject); + + Response response = pipeliningBase.memoryUsage("key", 10); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testObjectRefcount() { + when(commandObjects.objectRefcount("key")).thenReturn(longCommandObject); + + Response response = pipeliningBase.objectRefcount("key"); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testObjectEncoding() { + when(commandObjects.objectEncoding("key")).thenReturn(stringCommandObject); + + Response response = pipeliningBase.objectEncoding("key"); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testObjectIdletime() { + when(commandObjects.objectIdletime("key")).thenReturn(longCommandObject); + + Response response = pipeliningBase.objectIdletime("key"); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testObjectFreq() { + when(commandObjects.objectFreq("key")).thenReturn(longCommandObject); + + Response response = pipeliningBase.objectFreq("key"); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testMigrateSingleKey() { + when(commandObjects.migrate("host", 6379, "key", 5000)).thenReturn(stringCommandObject); + + Response response = pipeliningBase.migrate("host", 6379, "key", 5000); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testMigrateMultipleKeys() { + MigrateParams params = new MigrateParams(); + String[] keys = { "key1", "key2" }; + + when(commandObjects.migrate("host", 6379, 5000, params, keys)).thenReturn(stringCommandObject); + + Response response = pipeliningBase.migrate("host", 6379, 5000, params, keys); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testKeys() { + when(commandObjects.keys("pattern")).thenReturn(setStringCommandObject); + + Response> response = pipeliningBase.keys("pattern"); + + assertThat(commands, contains(setStringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testScan() { + when(commandObjects.scan("0")).thenReturn(scanResultStringCommandObject); + + Response> response = pipeliningBase.scan("0"); + + assertThat(commands, contains(scanResultStringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testScanWithParams() { + ScanParams scanParams = new ScanParams(); + + when(commandObjects.scan("0", scanParams)).thenReturn(scanResultStringCommandObject); + + Response> response = pipeliningBase.scan("0", scanParams); + + assertThat(commands, contains(scanResultStringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testScanWithType() { + ScanParams scanParams = new ScanParams(); + + when(commandObjects.scan("0", scanParams, "type")).thenReturn(scanResultStringCommandObject); + + Response> response = pipeliningBase.scan("0", scanParams, "type"); + + assertThat(commands, contains(scanResultStringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testRandomKey() { + when(commandObjects.randomKey()).thenReturn(stringCommandObject); + + Response response = pipeliningBase.randomKey(); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testGet() { + when(commandObjects.get("key")).thenReturn(stringCommandObject); + + Response response = pipeliningBase.get("key"); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testSetGet() { + when(commandObjects.setGet("key", "value")).thenReturn(stringCommandObject); + + Response response = pipeliningBase.setGet("key", "value"); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testSetGetWithParams() { + SetParams setParams = new SetParams(); + + when(commandObjects.setGet("key", "value", setParams)).thenReturn(stringCommandObject); + + Response response = pipeliningBase.setGet("key", "value", setParams); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testGetDel() { + when(commandObjects.getDel("key")).thenReturn(stringCommandObject); + + Response response = pipeliningBase.getDel("key"); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testGetEx() { + GetExParams params = new GetExParams(); + + when(commandObjects.getEx("key", params)).thenReturn(stringCommandObject); + + Response response = pipeliningBase.getEx("key", params); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testSetbit() { + when(commandObjects.setbit("key", 100, true)).thenReturn(booleanCommandObject); + + Response response = pipeliningBase.setbit("key", 100, true); + + assertThat(commands, contains(booleanCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testGetbit() { + when(commandObjects.getbit("key", 100)).thenReturn(booleanCommandObject); + + Response response = pipeliningBase.getbit("key", 100); + + assertThat(commands, contains(booleanCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testSetrange() { + when(commandObjects.setrange("key", 100, "value")).thenReturn(longCommandObject); + + Response response = pipeliningBase.setrange("key", 100, "value"); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testGetrange() { + when(commandObjects.getrange("key", 0, 100)).thenReturn(stringCommandObject); + + Response response = pipeliningBase.getrange("key", 0, 100); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testGetSet() { + when(commandObjects.getSet("key", "value")).thenReturn(stringCommandObject); + + Response response = pipeliningBase.getSet("key", "value"); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testSetnx() { + when(commandObjects.setnx("key", "value")).thenReturn(longCommandObject); + + Response response = pipeliningBase.setnx("key", "value"); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testSetex() { + when(commandObjects.setex("key", 60, "value")).thenReturn(stringCommandObject); + + Response response = pipeliningBase.setex("key", 60, "value"); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testPsetex() { + when(commandObjects.psetex("key", 100000, "value")).thenReturn(stringCommandObject); + + Response response = pipeliningBase.psetex("key", 100000, "value"); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testMget() { + String[] keys = { "key1", "key2", "key3" }; + + when(commandObjects.mget(keys)).thenReturn(listStringCommandObject); + + Response> response = pipeliningBase.mget(keys); + + assertThat(commands, contains(listStringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testMset() { + String[] keysvalues = { "key1", "value1", "key2", "value2" }; + + when(commandObjects.mset(keysvalues)).thenReturn(stringCommandObject); + + Response response = pipeliningBase.mset(keysvalues); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testMsetnx() { + String[] keysvalues = { "key1", "value1", "key2", "value2" }; + + when(commandObjects.msetnx(keysvalues)).thenReturn(longCommandObject); + + Response response = pipeliningBase.msetnx(keysvalues); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testIncr() { + when(commandObjects.incr("key")).thenReturn(longCommandObject); + + Response response = pipeliningBase.incr("key"); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testIncrBy() { + when(commandObjects.incrBy("key", 10L)).thenReturn(longCommandObject); + + Response response = pipeliningBase.incrBy("key", 10L); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testIncrByFloat() { + when(commandObjects.incrByFloat("key", 1.5)).thenReturn(doubleCommandObject); + + Response response = pipeliningBase.incrByFloat("key", 1.5); + + assertThat(commands, contains(doubleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testDecr() { + when(commandObjects.decr("key")).thenReturn(longCommandObject); + + Response response = pipeliningBase.decr("key"); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testDecrBy() { + when(commandObjects.decrBy("key", 10L)).thenReturn(longCommandObject); + + Response response = pipeliningBase.decrBy("key", 10L); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testAppend() { + when(commandObjects.append("key", "value")).thenReturn(longCommandObject); + + Response response = pipeliningBase.append("key", "value"); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testSubstr() { + when(commandObjects.substr("key", 0, 10)).thenReturn(stringCommandObject); + + Response response = pipeliningBase.substr("key", 0, 10); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testStrlen() { + when(commandObjects.strlen("key")).thenReturn(longCommandObject); + + Response response = pipeliningBase.strlen("key"); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testBitcount() { + when(commandObjects.bitcount("key")).thenReturn(longCommandObject); + + Response response = pipeliningBase.bitcount("key"); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testBitcountRange() { + when(commandObjects.bitcount("key", 0, 10)).thenReturn(longCommandObject); + + Response response = pipeliningBase.bitcount("key", 0, 10); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testBitcountRangeOption() { + BitCountOption option = BitCountOption.BYTE; + + when(commandObjects.bitcount("key", 0, 10, option)).thenReturn(longCommandObject); + + Response response = pipeliningBase.bitcount("key", 0, 10, option); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testBitpos() { + when(commandObjects.bitpos("key", true)).thenReturn(longCommandObject); + + Response response = pipeliningBase.bitpos("key", true); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testBitposParams() { + BitPosParams params = new BitPosParams(0, -1); + + when(commandObjects.bitpos("key", true, params)).thenReturn(longCommandObject); + + Response response = pipeliningBase.bitpos("key", true, params); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testBitfield() { + String[] arguments = { "INCRBY", "mykey", "2", "1" }; + + when(commandObjects.bitfield("key", arguments)).thenReturn(listLongCommandObject); + + Response> response = pipeliningBase.bitfield("key", arguments); + + assertThat(commands, contains(listLongCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testBitfieldReadonly() { + String[] arguments = { "GET", "u4", "0" }; + + when(commandObjects.bitfieldReadonly("key", arguments)).thenReturn(listLongCommandObject); + + Response> response = pipeliningBase.bitfieldReadonly("key", arguments); + + assertThat(commands, contains(listLongCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testBitop() { + BitOP op = BitOP.AND; + + when(commandObjects.bitop(op, "destKey", "srckey1", "srckey2")).thenReturn(longCommandObject); + + Response response = pipeliningBase.bitop(op, "destKey", "srckey1", "srckey2"); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testLcs() { + LCSParams params = new LCSParams(); + + when(commandObjects.lcs("keyA", "keyB", params)).thenReturn(lcsMatchResultCommandObject); + + Response response = pipeliningBase.lcs("keyA", "keyB", params); + + assertThat(commands, contains(lcsMatchResultCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testSet() { + when(commandObjects.set("key", "value")).thenReturn(stringCommandObject); + + Response response = pipeliningBase.set("key", "value"); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testSetWithParams() { + SetParams params = new SetParams(); + + when(commandObjects.set("key", "value", params)).thenReturn(stringCommandObject); + + Response response = pipeliningBase.set("key", "value", params); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testRpush() { + when(commandObjects.rpush("key", "value1", "value2")).thenReturn(longCommandObject); + + Response response = pipeliningBase.rpush("key", "value1", "value2"); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testLpush() { + when(commandObjects.lpush("key", "value1", "value2")).thenReturn(longCommandObject); + + Response response = pipeliningBase.lpush("key", "value1", "value2"); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testLlen() { + when(commandObjects.llen("key")).thenReturn(longCommandObject); + + Response response = pipeliningBase.llen("key"); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testLrange() { + when(commandObjects.lrange("key", 0, -1)).thenReturn(listStringCommandObject); + + Response> response = pipeliningBase.lrange("key", 0, -1); + + assertThat(commands, contains(listStringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testLtrim() { + when(commandObjects.ltrim("key", 1, -1)).thenReturn(stringCommandObject); + + Response response = pipeliningBase.ltrim("key", 1, -1); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testLindex() { + when(commandObjects.lindex("key", 1)).thenReturn(stringCommandObject); + + Response response = pipeliningBase.lindex("key", 1); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testLset() { + when(commandObjects.lset("key", 1, "value")).thenReturn(stringCommandObject); + + Response response = pipeliningBase.lset("key", 1, "value"); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testLrem() { + when(commandObjects.lrem("key", 2, "value")).thenReturn(longCommandObject); + + Response response = pipeliningBase.lrem("key", 2, "value"); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testLpop() { + when(commandObjects.lpop("key")).thenReturn(stringCommandObject); + + Response response = pipeliningBase.lpop("key"); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testLpopCount() { + when(commandObjects.lpop("key", 2)).thenReturn(listStringCommandObject); + + Response> response = pipeliningBase.lpop("key", 2); + + assertThat(commands, contains(listStringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testLpos() { + when(commandObjects.lpos("key", "element")).thenReturn(longCommandObject); + + Response response = pipeliningBase.lpos("key", "element"); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testLposWithParams() { + LPosParams params = new LPosParams(); + + when(commandObjects.lpos("key", "element", params)).thenReturn(longCommandObject); + + Response response = pipeliningBase.lpos("key", "element", params); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testLposWithParamsCount() { + LPosParams params = new LPosParams(); + + when(commandObjects.lpos("key", "element", params, 3)).thenReturn(listLongCommandObject); + + Response> response = pipeliningBase.lpos("key", "element", params, 3); + + assertThat(commands, contains(listLongCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testRpop() { + when(commandObjects.rpop("key")).thenReturn(stringCommandObject); + + Response response = pipeliningBase.rpop("key"); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testRpopCount() { + when(commandObjects.rpop("key", 2)).thenReturn(listStringCommandObject); + + Response> response = pipeliningBase.rpop("key", 2); + + assertThat(commands, contains(listStringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testLinsert() { + ListPosition where = ListPosition.BEFORE; + + when(commandObjects.linsert("key", where, "pivot", "value")).thenReturn(longCommandObject); + + Response response = pipeliningBase.linsert("key", where, "pivot", "value"); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testLpushx() { + when(commandObjects.lpushx("key", "value1", "value2")).thenReturn(longCommandObject); + + Response response = pipeliningBase.lpushx("key", "value1", "value2"); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testRpushx() { + when(commandObjects.rpushx("key", "value1", "value2")).thenReturn(longCommandObject); + + Response response = pipeliningBase.rpushx("key", "value1", "value2"); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testBlpop() { + when(commandObjects.blpop(30, "key")).thenReturn(listStringCommandObject); + + Response> response = pipeliningBase.blpop(30, "key"); + + assertThat(commands, contains(listStringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testBlpopDoubleTimeoutKey() { + when(commandObjects.blpop(30.0, "key")).thenReturn(keyValueStringStringCommandObject); + + Response> response = pipeliningBase.blpop(30.0, "key"); + + assertThat(commands, contains(keyValueStringStringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testBrpop() { + when(commandObjects.brpop(30, "key")).thenReturn(listStringCommandObject); + + Response> response = pipeliningBase.brpop(30, "key"); + + assertThat(commands, contains(listStringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testBrpopDoubleTimeoutKey() { + when(commandObjects.brpop(30.0, "key")).thenReturn(keyValueStringStringCommandObject); + + Response> response = pipeliningBase.brpop(30.0, "key"); + + assertThat(commands, contains(keyValueStringStringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testBlpopMultipleKeys() { + when(commandObjects.blpop(30, "key1", "key2")).thenReturn(listStringCommandObject); + + Response> response = pipeliningBase.blpop(30, "key1", "key2"); + + assertThat(commands, contains(listStringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testBlpopDoubleTimeoutKeys() { + when(commandObjects.blpop(30.0, "key1", "key2")).thenReturn(keyValueStringStringCommandObject); + + Response> response = pipeliningBase.blpop(30.0, "key1", "key2"); + + assertThat(commands, contains(keyValueStringStringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testBrpopMultipleKeys() { + when(commandObjects.brpop(30, "key1", "key2")).thenReturn(listStringCommandObject); + + Response> response = pipeliningBase.brpop(30, "key1", "key2"); + + assertThat(commands, contains(listStringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testBrpopDoubleTimeoutKeys() { + when(commandObjects.brpop(30.0, "key1", "key2")).thenReturn(keyValueStringStringCommandObject); + + Response> response = pipeliningBase.brpop(30.0, "key1", "key2"); + + assertThat(commands, contains(keyValueStringStringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testRpoplpush() { + when(commandObjects.rpoplpush("srcKey", "dstKey")).thenReturn(stringCommandObject); + + Response response = pipeliningBase.rpoplpush("srcKey", "dstKey"); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testBrpoplpush() { + when(commandObjects.brpoplpush("source", "destination", 30)).thenReturn(stringCommandObject); + + Response response = pipeliningBase.brpoplpush("source", "destination", 30); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testLmove() { + ListDirection from = ListDirection.LEFT; + ListDirection to = ListDirection.RIGHT; + + when(commandObjects.lmove("srcKey", "dstKey", from, to)).thenReturn(stringCommandObject); + + Response response = pipeliningBase.lmove("srcKey", "dstKey", from, to); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testBlmove() { + ListDirection from = ListDirection.LEFT; + ListDirection to = ListDirection.RIGHT; + double timeout = 1.0; + + when(commandObjects.blmove("srcKey", "dstKey", from, to, timeout)).thenReturn(stringCommandObject); + + Response response = pipeliningBase.blmove("srcKey", "dstKey", from, to, timeout); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testLmpop() { + ListDirection direction = ListDirection.LEFT; + + when(commandObjects.lmpop(direction, "key1", "key2")).thenReturn(keyValueStringListStringCommandObject); + + Response>> response = pipeliningBase.lmpop(direction, "key1", "key2"); + + assertThat(commands, contains(keyValueStringListStringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testLmpopCount() { + ListDirection direction = ListDirection.LEFT; + int count = 2; + + when(commandObjects.lmpop(direction, count, "key1", "key2")).thenReturn(keyValueStringListStringCommandObject); + + Response>> response = pipeliningBase.lmpop(direction, count, "key1", "key2"); + + assertThat(commands, contains(keyValueStringListStringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testBlmpop() { + double timeout = 1.0; + ListDirection direction = ListDirection.LEFT; + + when(commandObjects.blmpop(timeout, direction, "key1", "key2")).thenReturn(keyValueStringListStringCommandObject); + + Response>> response = pipeliningBase.blmpop(timeout, direction, "key1", "key2"); + + assertThat(commands, contains(keyValueStringListStringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testBlmpopCount() { + double timeout = 1.0; + ListDirection direction = ListDirection.LEFT; + int count = 2; + + when(commandObjects.blmpop(timeout, direction, count, "key1", "key2")).thenReturn(keyValueStringListStringCommandObject); + + Response>> response = pipeliningBase.blmpop(timeout, direction, count, "key1", "key2"); + + assertThat(commands, contains(keyValueStringListStringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testHset() { + when(commandObjects.hset("key", "field", "value")).thenReturn(longCommandObject); + + Response response = pipeliningBase.hset("key", "field", "value"); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testHsetMap() { + Map hash = new HashMap<>(); + hash.put("field1", "value1"); + hash.put("field2", "value2"); + + when(commandObjects.hset("key", hash)).thenReturn(longCommandObject); + + Response response = pipeliningBase.hset("key", hash); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testHget() { + when(commandObjects.hget("key", "field")).thenReturn(stringCommandObject); + + Response response = pipeliningBase.hget("key", "field"); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testHsetnx() { + when(commandObjects.hsetnx("key", "field", "value")).thenReturn(longCommandObject); + + Response response = pipeliningBase.hsetnx("key", "field", "value"); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testHmset() { + Map hash = new HashMap<>(); + hash.put("field1", "value1"); + hash.put("field2", "value2"); + + when(commandObjects.hmset("key", hash)).thenReturn(stringCommandObject); + + Response response = pipeliningBase.hmset("key", hash); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testHmget() { + when(commandObjects.hmget("key", "field1", "field2")).thenReturn(listStringCommandObject); + + Response> response = pipeliningBase.hmget("key", "field1", "field2"); + + assertThat(commands, contains(listStringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testHincrBy() { + when(commandObjects.hincrBy("key", "field", 1L)).thenReturn(longCommandObject); + + Response response = pipeliningBase.hincrBy("key", "field", 1L); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testHincrByFloat() { + when(commandObjects.hincrByFloat("key", "field", 1.0)).thenReturn(doubleCommandObject); + + Response response = pipeliningBase.hincrByFloat("key", "field", 1.0); + + assertThat(commands, contains(doubleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testHexists() { + when(commandObjects.hexists("key", "field")).thenReturn(booleanCommandObject); + + Response response = pipeliningBase.hexists("key", "field"); + + assertThat(commands, contains(booleanCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testHdel() { + when(commandObjects.hdel("key", "field1", "field2")).thenReturn(longCommandObject); + + Response response = pipeliningBase.hdel("key", "field1", "field2"); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testHlen() { + when(commandObjects.hlen("key")).thenReturn(longCommandObject); + + Response response = pipeliningBase.hlen("key"); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testHkeys() { + when(commandObjects.hkeys("key")).thenReturn(setStringCommandObject); + + Response> response = pipeliningBase.hkeys("key"); + + assertThat(commands, contains(setStringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testHvals() { + when(commandObjects.hvals("key")).thenReturn(listStringCommandObject); + + Response> response = pipeliningBase.hvals("key"); + + assertThat(commands, contains(listStringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testHgetAll() { + when(commandObjects.hgetAll("key")).thenReturn(mapStringStringCommandObject); + + Response> response = pipeliningBase.hgetAll("key"); + + assertThat(commands, contains(mapStringStringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testHrandfield() { + when(commandObjects.hrandfield("key")).thenReturn(stringCommandObject); + + Response response = pipeliningBase.hrandfield("key"); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testHrandfieldCount() { + long count = 2; + + when(commandObjects.hrandfield("key", count)).thenReturn(listStringCommandObject); + + Response> response = pipeliningBase.hrandfield("key", count); + + assertThat(commands, contains(listStringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testHrandfieldWithValues() { + long count = 2; + + when(commandObjects.hrandfieldWithValues("key", count)).thenReturn(listEntryStringStringCommandObject); + + Response>> response = pipeliningBase.hrandfieldWithValues("key", count); + + assertThat(commands, contains(listEntryStringStringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testHscan() { + String cursor = "0"; + ScanParams params = new ScanParams(); + + when(commandObjects.hscan("key", cursor, params)).thenReturn(scanResultEntryStringStringCommandObject); + + Response>> response = pipeliningBase.hscan("key", cursor, params); + + assertThat(commands, contains(scanResultEntryStringStringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testHscanNoValues() { + String cursor = "0"; + ScanParams params = new ScanParams(); + + when(commandObjects.hscanNoValues("key", cursor, params)).thenReturn(scanResultStringCommandObject); + + Response> response = pipeliningBase.hscanNoValues("key", cursor, params); + + assertThat(commands, contains(scanResultStringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testHstrlen() { + when(commandObjects.hstrlen("key", "field")).thenReturn(longCommandObject); + + Response response = pipeliningBase.hstrlen("key", "field"); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testSadd() { + when(commandObjects.sadd("key", "member1", "member2")).thenReturn(longCommandObject); + + Response response = pipeliningBase.sadd("key", "member1", "member2"); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testSmembers() { + when(commandObjects.smembers("key")).thenReturn(setStringCommandObject); + + Response> response = pipeliningBase.smembers("key"); + + assertThat(commands, contains(setStringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testSrem() { + when(commandObjects.srem("key", "member1", "member2")).thenReturn(longCommandObject); + + Response response = pipeliningBase.srem("key", "member1", "member2"); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testSpop() { + when(commandObjects.spop("key")).thenReturn(stringCommandObject); + + Response response = pipeliningBase.spop("key"); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testSpopCount() { + long count = 2; + + when(commandObjects.spop("key", count)).thenReturn(setStringCommandObject); + + Response> response = pipeliningBase.spop("key", count); + + assertThat(commands, contains(setStringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testScard() { + when(commandObjects.scard("key")).thenReturn(longCommandObject); + + Response response = pipeliningBase.scard("key"); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testSismember() { + when(commandObjects.sismember("key", "member")).thenReturn(booleanCommandObject); + + Response response = pipeliningBase.sismember("key", "member"); + + assertThat(commands, contains(booleanCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testSmismember() { + when(commandObjects.smismember("key", "member1", "member2")).thenReturn(listBooleanCommandObject); + + Response> response = pipeliningBase.smismember("key", "member1", "member2"); + + assertThat(commands, contains(listBooleanCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testSrandmember() { + when(commandObjects.srandmember("key")).thenReturn(stringCommandObject); + + Response response = pipeliningBase.srandmember("key"); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testSrandmemberCount() { + int count = 2; + + when(commandObjects.srandmember("key", count)).thenReturn(listStringCommandObject); + + Response> response = pipeliningBase.srandmember("key", count); + + assertThat(commands, contains(listStringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testSscan() { + String cursor = "0"; + ScanParams params = new ScanParams(); + + when(commandObjects.sscan("key", cursor, params)).thenReturn(scanResultStringCommandObject); + + Response> response = pipeliningBase.sscan("key", cursor, params); + + assertThat(commands, contains(scanResultStringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testSdiff() { + when(commandObjects.sdiff("key1", "key2")).thenReturn(setStringCommandObject); + + Response> response = pipeliningBase.sdiff("key1", "key2"); + + assertThat(commands, contains(setStringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testSdiffstore() { + when(commandObjects.sdiffstore("dstKey", "key1", "key2")).thenReturn(longCommandObject); + + Response response = pipeliningBase.sdiffstore("dstKey", "key1", "key2"); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testSinter() { + when(commandObjects.sinter("key1", "key2")).thenReturn(setStringCommandObject); + + Response> response = pipeliningBase.sinter("key1", "key2"); + + assertThat(commands, contains(setStringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testSinterstore() { + when(commandObjects.sinterstore("dstKey", "key1", "key2")).thenReturn(longCommandObject); + + Response response = pipeliningBase.sinterstore("dstKey", "key1", "key2"); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testSintercard() { + when(commandObjects.sintercard("key1", "key2")).thenReturn(longCommandObject); + + Response response = pipeliningBase.sintercard("key1", "key2"); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testSintercardWithLimit() { + int limit = 1; + + when(commandObjects.sintercard(limit, "key1", "key2")).thenReturn(longCommandObject); + + Response response = pipeliningBase.sintercard(limit, "key1", "key2"); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testSunion() { + when(commandObjects.sunion("key1", "key2")).thenReturn(setStringCommandObject); + + Response> response = pipeliningBase.sunion("key1", "key2"); + + assertThat(commands, contains(setStringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testSunionstore() { + when(commandObjects.sunionstore("dstKey", "key1", "key2")).thenReturn(longCommandObject); + + Response response = pipeliningBase.sunionstore("dstKey", "key1", "key2"); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testSmove() { + when(commandObjects.smove("srcKey", "dstKey", "member")).thenReturn(longCommandObject); + + Response response = pipeliningBase.smove("srcKey", "dstKey", "member"); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZaddSingle() { + when(commandObjects.zadd("key", 1.0, "member")).thenReturn(longCommandObject); + + Response response = pipeliningBase.zadd("key", 1.0, "member"); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZaddSingleWithParams() { + ZAddParams params = new ZAddParams(); + + when(commandObjects.zadd("key", 1.0, "member", params)).thenReturn(longCommandObject); + + Response response = pipeliningBase.zadd("key", 1.0, "member", params); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZaddMultiple() { + Map scoreMembers = new HashMap<>(); + scoreMembers.put("member1", 1.0); + scoreMembers.put("member2", 2.0); + + when(commandObjects.zadd("key", scoreMembers)).thenReturn(longCommandObject); + + Response response = pipeliningBase.zadd("key", scoreMembers); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZaddMultipleWithParams() { + Map scoreMembers = new HashMap<>(); + scoreMembers.put("member1", 1.0); + scoreMembers.put("member2", 2.0); + + ZAddParams params = new ZAddParams(); + + when(commandObjects.zadd("key", scoreMembers, params)).thenReturn(longCommandObject); + + Response response = pipeliningBase.zadd("key", scoreMembers, params); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZaddIncr() { + ZAddParams params = new ZAddParams(); + + when(commandObjects.zaddIncr("key", 1.0, "member", params)).thenReturn(doubleCommandObject); + + Response response = pipeliningBase.zaddIncr("key", 1.0, "member", params); + + assertThat(commands, contains(doubleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZrem() { + when(commandObjects.zrem("key", "member1", "member2")).thenReturn(longCommandObject); + + Response response = pipeliningBase.zrem("key", "member1", "member2"); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZincrby() { + when(commandObjects.zincrby("key", 1.0, "member")).thenReturn(doubleCommandObject); + + Response response = pipeliningBase.zincrby("key", 1.0, "member"); + + assertThat(commands, contains(doubleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZincrbyWithParams() { + ZIncrByParams params = new ZIncrByParams(); + + when(commandObjects.zincrby("key", 1.0, "member", params)).thenReturn(doubleCommandObject); + + Response response = pipeliningBase.zincrby("key", 1.0, "member", params); + + assertThat(commands, contains(doubleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZrank() { + when(commandObjects.zrank("key", "member")).thenReturn(longCommandObject); + + Response response = pipeliningBase.zrank("key", "member"); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZrevrank() { + when(commandObjects.zrevrank("key", "member")).thenReturn(longCommandObject); + + Response response = pipeliningBase.zrevrank("key", "member"); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZrankWithScore() { + when(commandObjects.zrankWithScore("key", "member")).thenReturn(keyValueLongDoubleCommandObject); + + Response> response = pipeliningBase.zrankWithScore("key", "member"); + + assertThat(commands, contains(keyValueLongDoubleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZrevrankWithScore() { + when(commandObjects.zrevrankWithScore("key", "member")).thenReturn(keyValueLongDoubleCommandObject); + + Response> response = pipeliningBase.zrevrankWithScore("key", "member"); + + assertThat(commands, contains(keyValueLongDoubleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZrange() { + when(commandObjects.zrange("key", 0, -1)).thenReturn(listStringCommandObject); + + Response> response = pipeliningBase.zrange("key", 0, -1); + + assertThat(commands, contains(listStringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZrevrange() { + when(commandObjects.zrevrange("key", 0, -1)).thenReturn(listStringCommandObject); + + Response> response = pipeliningBase.zrevrange("key", 0, -1); + + assertThat(commands, contains(listStringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZrangeWithScores() { + when(commandObjects.zrangeWithScores("key", 0, -1)).thenReturn(listTupleCommandObject); + + Response> response = pipeliningBase.zrangeWithScores("key", 0, -1); + + assertThat(commands, contains(listTupleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZrevrangeWithScores() { + when(commandObjects.zrevrangeWithScores("key", 0, -1)).thenReturn(listTupleCommandObject); + + Response> response = pipeliningBase.zrevrangeWithScores("key", 0, -1); + + assertThat(commands, contains(listTupleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZrandmember() { + when(commandObjects.zrandmember("key")).thenReturn(stringCommandObject); + + Response response = pipeliningBase.zrandmember("key"); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZrandmemberCount() { + long count = 2; + + when(commandObjects.zrandmember("key", count)).thenReturn(listStringCommandObject); + + Response> response = pipeliningBase.zrandmember("key", count); + + assertThat(commands, contains(listStringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZrandmemberWithScores() { + long count = 2; + + when(commandObjects.zrandmemberWithScores("key", count)).thenReturn(listTupleCommandObject); + + Response> response = pipeliningBase.zrandmemberWithScores("key", count); + + assertThat(commands, contains(listTupleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZcard() { + when(commandObjects.zcard("key")).thenReturn(longCommandObject); + + Response response = pipeliningBase.zcard("key"); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZscore() { + when(commandObjects.zscore("key", "member")).thenReturn(doubleCommandObject); + + Response response = pipeliningBase.zscore("key", "member"); + + assertThat(commands, contains(doubleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZmscore() { + when(commandObjects.zmscore("key", "member1", "member2")).thenReturn(listDoubleCommandObject); + + Response> response = pipeliningBase.zmscore("key", "member1", "member2"); + + assertThat(commands, contains(listDoubleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZpopmax() { + when(commandObjects.zpopmax("key")).thenReturn(tupleCommandObject); + + Response response = pipeliningBase.zpopmax("key"); + + assertThat(commands, contains(tupleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZpopmaxCount() { + int count = 2; + + when(commandObjects.zpopmax("key", count)).thenReturn(listTupleCommandObject); + + Response> response = pipeliningBase.zpopmax("key", count); + + assertThat(commands, contains(listTupleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZpopmin() { + when(commandObjects.zpopmin("key")).thenReturn(tupleCommandObject); + + Response response = pipeliningBase.zpopmin("key"); + + assertThat(commands, contains(tupleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZpopminCount() { + int count = 2; + + when(commandObjects.zpopmin("key", count)).thenReturn(listTupleCommandObject); + + Response> response = pipeliningBase.zpopmin("key", count); + + assertThat(commands, contains(listTupleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZcountDouble() { + when(commandObjects.zcount("key", 1.0, 2.0)).thenReturn(longCommandObject); + + Response response = pipeliningBase.zcount("key", 1.0, 2.0); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZcountString() { + when(commandObjects.zcount("key", "1", "2")).thenReturn(longCommandObject); + + Response response = pipeliningBase.zcount("key", "1", "2"); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZrangeByScoreDouble() { + when(commandObjects.zrangeByScore("key", 1.0, 2.0)).thenReturn(listStringCommandObject); + + Response> response = pipeliningBase.zrangeByScore("key", 1.0, 2.0); + + assertThat(commands, contains(listStringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZrangeByScoreString() { + when(commandObjects.zrangeByScore("key", "1", "2")).thenReturn(listStringCommandObject); + + Response> response = pipeliningBase.zrangeByScore("key", "1", "2"); + + assertThat(commands, contains(listStringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZrevrangeByScoreDouble() { + when(commandObjects.zrevrangeByScore("key", 2.0, 1.0)).thenReturn(listStringCommandObject); + + Response> response = pipeliningBase.zrevrangeByScore("key", 2.0, 1.0); + + assertThat(commands, contains(listStringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZrangeByScoreDoubleWithLimit() { + when(commandObjects.zrangeByScore("key", 1.0, 2.0, 0, 1)).thenReturn(listStringCommandObject); + + Response> response = pipeliningBase.zrangeByScore("key", 1.0, 2.0, 0, 1); + + assertThat(commands, contains(listStringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZrevrangeByScoreString() { + when(commandObjects.zrevrangeByScore("key", "2", "1")).thenReturn(listStringCommandObject); + + Response> response = pipeliningBase.zrevrangeByScore("key", "2", "1"); + + assertThat(commands, contains(listStringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZrangeByScoreStringWithLimit() { + when(commandObjects.zrangeByScore("key", "1", "2", 0, 1)).thenReturn(listStringCommandObject); + + Response> response = pipeliningBase.zrangeByScore("key", "1", "2", 0, 1); + + assertThat(commands, contains(listStringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZrevrangeByScoreDoubleWithLimit() { + when(commandObjects.zrevrangeByScore("key", 2.0, 1.0, 0, 1)).thenReturn(listStringCommandObject); + + Response> response = pipeliningBase.zrevrangeByScore("key", 2.0, 1.0, 0, 1); + + assertThat(commands, contains(listStringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZrangeByScoreWithScores() { + when(commandObjects.zrangeByScoreWithScores("key", 1.0, 2.0)).thenReturn(listTupleCommandObject); + + Response> response = pipeliningBase.zrangeByScoreWithScores("key", 1.0, 2.0); + + assertThat(commands, contains(listTupleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZrevrangeByScoreWithScoresDouble() { + when(commandObjects.zrevrangeByScoreWithScores("key", 2.0, 1.0)).thenReturn(listTupleCommandObject); + + Response> response = pipeliningBase.zrevrangeByScoreWithScores("key", 2.0, 1.0); + + assertThat(commands, contains(listTupleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZrangeByScoreWithScoresDoubleWithLimit() { + when(commandObjects.zrangeByScoreWithScores("key", 1.0, 2.0, 0, 1)).thenReturn(listTupleCommandObject); + + Response> response = pipeliningBase.zrangeByScoreWithScores("key", 1.0, 2.0, 0, 1); + + assertThat(commands, contains(listTupleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZrevrangeByScoreStringWithLimit() { + when(commandObjects.zrevrangeByScore("key", "2", "1", 0, 1)).thenReturn(listStringCommandObject); + + Response> response = pipeliningBase.zrevrangeByScore("key", "2", "1", 0, 1); + + assertThat(commands, contains(listStringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZrangeByScoreWithScoresString() { + when(commandObjects.zrangeByScoreWithScores("key", "1", "2")).thenReturn(listTupleCommandObject); + + Response> response = pipeliningBase.zrangeByScoreWithScores("key", "1", "2"); + + assertThat(commands, contains(listTupleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZrevrangeByScoreWithScoresString() { + when(commandObjects.zrevrangeByScoreWithScores("key", "2", "1")).thenReturn(listTupleCommandObject); + + Response> response = pipeliningBase.zrevrangeByScoreWithScores("key", "2", "1"); + + assertThat(commands, contains(listTupleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZrangeByScoreWithScoresStringWithLimit() { + when(commandObjects.zrangeByScoreWithScores("key", "1", "2", 0, 1)).thenReturn(listTupleCommandObject); + + Response> response = pipeliningBase.zrangeByScoreWithScores("key", "1", "2", 0, 1); + + assertThat(commands, contains(listTupleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZrevrangeByScoreWithScoresDoubleWithLimit() { + when(commandObjects.zrevrangeByScoreWithScores("key", 2.0, 1.0, 0, 1)).thenReturn(listTupleCommandObject); + + Response> response = pipeliningBase.zrevrangeByScoreWithScores("key", 2.0, 1.0, 0, 1); + + assertThat(commands, contains(listTupleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZrevrangeByScoreWithScoresStringWithLimit() { + when(commandObjects.zrevrangeByScoreWithScores("key", "2", "1", 0, 1)).thenReturn(listTupleCommandObject); + + Response> response = pipeliningBase.zrevrangeByScoreWithScores("key", "2", "1", 0, 1); + + assertThat(commands, contains(listTupleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZrangeZRangeParams() { + ZRangeParams zRangeParams = new ZRangeParams(1, 2); + + when(commandObjects.zrange("key", zRangeParams)).thenReturn(listStringCommandObject); + + Response> response = pipeliningBase.zrange("key", zRangeParams); + + assertThat(commands, contains(listStringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZrangeWithScoresZRangeParams() { + ZRangeParams zRangeParams = new ZRangeParams(1, 2); + + when(commandObjects.zrangeWithScores("key", zRangeParams)).thenReturn(listTupleCommandObject); + + Response> response = pipeliningBase.zrangeWithScores("key", zRangeParams); + + assertThat(commands, contains(listTupleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZrangestore() { + ZRangeParams zRangeParams = new ZRangeParams(1, 2); + + when(commandObjects.zrangestore("dest", "src", zRangeParams)).thenReturn(longCommandObject); + + Response response = pipeliningBase.zrangestore("dest", "src", zRangeParams); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZremrangeByRank() { + when(commandObjects.zremrangeByRank("key", 0, 1)).thenReturn(longCommandObject); + + Response response = pipeliningBase.zremrangeByRank("key", 0, 1); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZremrangeByScoreDouble() { + when(commandObjects.zremrangeByScore("key", 1.0, 2.0)).thenReturn(longCommandObject); + + Response response = pipeliningBase.zremrangeByScore("key", 1.0, 2.0); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZremrangeByScoreString() { + when(commandObjects.zremrangeByScore("key", "1", "2")).thenReturn(longCommandObject); + + Response response = pipeliningBase.zremrangeByScore("key", "1", "2"); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZlexcount() { + when(commandObjects.zlexcount("key", "[a", "[z")).thenReturn(longCommandObject); + + Response response = pipeliningBase.zlexcount("key", "[a", "[z"); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZrangeByLex() { + when(commandObjects.zrangeByLex("key", "[a", "[z")).thenReturn(listStringCommandObject); + + Response> response = pipeliningBase.zrangeByLex("key", "[a", "[z"); + + assertThat(commands, contains(listStringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZrangeByLexWithLimit() { + when(commandObjects.zrangeByLex("key", "[a", "[z", 0, 10)).thenReturn(listStringCommandObject); + + Response> response = pipeliningBase.zrangeByLex("key", "[a", "[z", 0, 10); + + assertThat(commands, contains(listStringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZrevrangeByLex() { + when(commandObjects.zrevrangeByLex("key", "[z", "[a")).thenReturn(listStringCommandObject); + + Response> response = pipeliningBase.zrevrangeByLex("key", "[z", "[a"); + + assertThat(commands, contains(listStringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZrevrangeByLexWithLimit() { + when(commandObjects.zrevrangeByLex("key", "[z", "[a", 0, 10)).thenReturn(listStringCommandObject); + + Response> response = pipeliningBase.zrevrangeByLex("key", "[z", "[a", 0, 10); + + assertThat(commands, contains(listStringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZremrangeByLex() { + when(commandObjects.zremrangeByLex("key", "[a", "[z")).thenReturn(longCommandObject); + + Response response = pipeliningBase.zremrangeByLex("key", "[a", "[z"); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZscan() { + ScanParams params = new ScanParams(); + + when(commandObjects.zscan("key", "0", params)).thenReturn(scanResultTupleCommandObject); + + Response> response = pipeliningBase.zscan("key", "0", params); + + assertThat(commands, contains(scanResultTupleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testBzpopmax() { + when(commandObjects.bzpopmax(1.0, "key1", "key2")).thenReturn(keyValueStringTupleCommandObject); + + Response> response = pipeliningBase.bzpopmax(1.0, "key1", "key2"); + + assertThat(commands, contains(keyValueStringTupleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testBzpopmin() { + when(commandObjects.bzpopmin(1.0, "key1", "key2")).thenReturn(keyValueStringTupleCommandObject); + + Response> response = pipeliningBase.bzpopmin(1.0, "key1", "key2"); + + assertThat(commands, contains(keyValueStringTupleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZmpop() { + SortedSetOption option = SortedSetOption.MAX; + + when(commandObjects.zmpop(option, "key1", "key2")).thenReturn(keyValueStringListTupleCommandObject); + + Response>> response = pipeliningBase.zmpop(option, "key1", "key2"); + + assertThat(commands, contains(keyValueStringListTupleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZmpopWithCount() { + SortedSetOption option = SortedSetOption.MAX; + int count = 2; + + when(commandObjects.zmpop(option, count, "key1", "key2")).thenReturn(keyValueStringListTupleCommandObject); + + Response>> response = pipeliningBase.zmpop(option, count, "key1", "key2"); + + assertThat(commands, contains(keyValueStringListTupleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testBzmpop() { + SortedSetOption option = SortedSetOption.MAX; + + when(commandObjects.bzmpop(1.0, option, "key1", "key2")).thenReturn(keyValueStringListTupleCommandObject); + + Response>> response = pipeliningBase.bzmpop(1.0, option, "key1", "key2"); + + assertThat(commands, contains(keyValueStringListTupleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testBzmpopWithCount() { + SortedSetOption option = SortedSetOption.MAX; + int count = 2; + + when(commandObjects.bzmpop(1.0, option, count, "key1", "key2")).thenReturn(keyValueStringListTupleCommandObject); + + Response>> response = pipeliningBase.bzmpop(1.0, option, count, "key1", "key2"); + + assertThat(commands, contains(keyValueStringListTupleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZdiff() { + when(commandObjects.zdiff("key1", "key2")).thenReturn(listStringCommandObject); + + Response> response = pipeliningBase.zdiff("key1", "key2"); + + assertThat(commands, contains(listStringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZdiffWithScores() { + when(commandObjects.zdiffWithScores("key1", "key2")).thenReturn(listTupleCommandObject); + + Response> response = pipeliningBase.zdiffWithScores("key1", "key2"); + + assertThat(commands, contains(listTupleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZdiffStore() { + when(commandObjects.zdiffStore("dstKey", "key1", "key2")).thenReturn(longCommandObject); + + Response response = pipeliningBase.zdiffStore("dstKey", "key1", "key2"); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZdiffstore() { + when(commandObjects.zdiffstore("dstKey", "key1", "key2")).thenReturn(longCommandObject); + + Response response = pipeliningBase.zdiffstore("dstKey", "key1", "key2"); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZinterstore() { + when(commandObjects.zinterstore("dstKey", "set1", "set2")).thenReturn(longCommandObject); + + Response response = pipeliningBase.zinterstore("dstKey", "set1", "set2"); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZinterstoreWithParams() { + ZParams params = new ZParams(); + + when(commandObjects.zinterstore("dstKey", params, "set1", "set2")).thenReturn(longCommandObject); + + Response response = pipeliningBase.zinterstore("dstKey", params, "set1", "set2"); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZinter() { + ZParams params = new ZParams(); + + when(commandObjects.zinter(params, "key1", "key2")).thenReturn(listStringCommandObject); + + Response> response = pipeliningBase.zinter(params, "key1", "key2"); + + assertThat(commands, contains(listStringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZinterWithScores() { + ZParams params = new ZParams(); + + when(commandObjects.zinterWithScores(params, "key1", "key2")).thenReturn(listTupleCommandObject); + + Response> response = pipeliningBase.zinterWithScores(params, "key1", "key2"); + + assertThat(commands, contains(listTupleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZintercard() { + when(commandObjects.zintercard("key1", "key2")).thenReturn(longCommandObject); + + Response response = pipeliningBase.zintercard("key1", "key2"); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZintercardWithLimit() { + long limit = 2; + + when(commandObjects.zintercard(limit, "key1", "key2")).thenReturn(longCommandObject); + + Response response = pipeliningBase.zintercard(limit, "key1", "key2"); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZunion() { + ZParams params = new ZParams(); + + when(commandObjects.zunion(params, "key1", "key2")).thenReturn(listStringCommandObject); + + Response> response = pipeliningBase.zunion(params, "key1", "key2"); + + assertThat(commands, contains(listStringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZunionWithScores() { + ZParams params = new ZParams(); + + when(commandObjects.zunionWithScores(params, "key1", "key2")).thenReturn(listTupleCommandObject); + + Response> response = pipeliningBase.zunionWithScores(params, "key1", "key2"); + + assertThat(commands, contains(listTupleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZunionstore() { + when(commandObjects.zunionstore("dstKey", "set1", "set2")).thenReturn(longCommandObject); + + Response response = pipeliningBase.zunionstore("dstKey", "set1", "set2"); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZunionstoreWithParams() { + ZParams params = new ZParams(); + + when(commandObjects.zunionstore("dstKey", params, "set1", "set2")).thenReturn(longCommandObject); + + Response response = pipeliningBase.zunionstore("dstKey", params, "set1", "set2"); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testGeoaddSingle() { + when(commandObjects.geoadd("key", 13.361389, 38.115556, "member")).thenReturn(longCommandObject); + + Response response = pipeliningBase.geoadd("key", 13.361389, 38.115556, "member"); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testGeoaddMap() { + Map memberCoordinateMap = new HashMap<>(); + memberCoordinateMap.put("member", new GeoCoordinate(13.361389, 38.115556)); + + when(commandObjects.geoadd("key", memberCoordinateMap)).thenReturn(longCommandObject); + + Response response = pipeliningBase.geoadd("key", memberCoordinateMap); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testGeoaddMapWithParams() { + GeoAddParams params = new GeoAddParams(); + + Map memberCoordinateMap = new HashMap<>(); + memberCoordinateMap.put("member", new GeoCoordinate(13.361389, 38.115556)); + + when(commandObjects.geoadd("key", params, memberCoordinateMap)).thenReturn(longCommandObject); + + Response response = pipeliningBase.geoadd("key", params, memberCoordinateMap); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testGeodist() { + when(commandObjects.geodist("key", "member1", "member2")).thenReturn(doubleCommandObject); + + Response response = pipeliningBase.geodist("key", "member1", "member2"); + + assertThat(commands, contains(doubleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testGeodistWithUnit() { + GeoUnit unit = GeoUnit.KM; + + when(commandObjects.geodist("key", "member1", "member2", unit)).thenReturn(doubleCommandObject); + + Response response = pipeliningBase.geodist("key", "member1", "member2", unit); + + assertThat(commands, contains(doubleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testGeohash() { + when(commandObjects.geohash("key", "member1", "member2")).thenReturn(listStringCommandObject); + + Response> response = pipeliningBase.geohash("key", "member1", "member2"); + + assertThat(commands, contains(listStringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testGeopos() { + when(commandObjects.geopos("key", "member1", "member2")).thenReturn(listGeoCoordinateCommandObject); + + Response> response = pipeliningBase.geopos("key", "member1", "member2"); + + assertThat(commands, contains(listGeoCoordinateCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testGeoradius() { + when(commandObjects.georadius("key", 15.0, 37.0, 100.0, GeoUnit.KM)) + .thenReturn(listGeoRadiusResponseCommandObject); + + Response> response = + pipeliningBase.georadius("key", 15.0, 37.0, 100.0, GeoUnit.KM); + + assertThat(commands, contains(listGeoRadiusResponseCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testGeoradiusReadonly() { + when(commandObjects.georadiusReadonly("key", 15.0, 37.0, 100.0, GeoUnit.KM)) + .thenReturn(listGeoRadiusResponseCommandObject); + + Response> response = + pipeliningBase.georadiusReadonly("key", 15.0, 37.0, 100.0, GeoUnit.KM); + + assertThat(commands, contains(listGeoRadiusResponseCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testGeoradiusWithParam() { + GeoRadiusParam param = GeoRadiusParam.geoRadiusParam(); + + when(commandObjects.georadius("key", 15.0, 37.0, 100.0, GeoUnit.KM, param)) + .thenReturn(listGeoRadiusResponseCommandObject); + + Response> response = + pipeliningBase.georadius("key", 15.0, 37.0, 100.0, GeoUnit.KM, param); + + assertThat(commands, contains(listGeoRadiusResponseCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testGeoradiusReadonlyWithParam() { + GeoRadiusParam param = GeoRadiusParam.geoRadiusParam(); + + when(commandObjects.georadiusReadonly("key", 15.0, 37.0, 100.0, GeoUnit.KM, param)) + .thenReturn(listGeoRadiusResponseCommandObject); + + Response> response = + pipeliningBase.georadiusReadonly("key", 15.0, 37.0, 100.0, GeoUnit.KM, param); + + assertThat(commands, contains(listGeoRadiusResponseCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testGeoradiusByMember() { + when(commandObjects.georadiusByMember("key", "member", 100.0, GeoUnit.KM)) + .thenReturn(listGeoRadiusResponseCommandObject); + + Response> response = + pipeliningBase.georadiusByMember("key", "member", 100.0, GeoUnit.KM); + + assertThat(commands, contains(listGeoRadiusResponseCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testGeoradiusByMemberReadonly() { + when(commandObjects.georadiusByMemberReadonly("key", "member", 100.0, GeoUnit.KM)) + .thenReturn(listGeoRadiusResponseCommandObject); + + Response> response = + pipeliningBase.georadiusByMemberReadonly("key", "member", 100.0, GeoUnit.KM); + + assertThat(commands, contains(listGeoRadiusResponseCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testGeoradiusByMemberWithParam() { + GeoRadiusParam param = GeoRadiusParam.geoRadiusParam(); + + when(commandObjects.georadiusByMember("key", "member", 100.0, GeoUnit.KM, param)) + .thenReturn(listGeoRadiusResponseCommandObject); + + Response> response = pipeliningBase + .georadiusByMember("key", "member", 100.0, GeoUnit.KM, param); + + assertThat(commands, contains(listGeoRadiusResponseCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testGeoradiusByMemberReadonlyWithParam() { + GeoRadiusParam param = GeoRadiusParam.geoRadiusParam(); + + when(commandObjects.georadiusByMemberReadonly("key", "member", 100.0, GeoUnit.KM, param)) + .thenReturn(listGeoRadiusResponseCommandObject); + + Response> response = pipeliningBase + .georadiusByMemberReadonly("key", "member", 100.0, GeoUnit.KM, param); + + assertThat(commands, contains(listGeoRadiusResponseCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testGeoradiusStore() { + GeoRadiusParam param = GeoRadiusParam.geoRadiusParam(); + GeoRadiusStoreParam storeParam = GeoRadiusStoreParam.geoRadiusStoreParam().store("storeKey"); + + when(commandObjects.georadiusStore("key", 15.0, 37.0, 100.0, GeoUnit.KM, param, storeParam)) + .thenReturn(longCommandObject); + + Response response = pipeliningBase + .georadiusStore("key", 15.0, 37.0, 100.0, GeoUnit.KM, param, storeParam); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testGeoradiusByMemberStore() { + GeoRadiusParam param = GeoRadiusParam.geoRadiusParam(); + GeoRadiusStoreParam storeParam = GeoRadiusStoreParam.geoRadiusStoreParam().store("storeKey"); + + when(commandObjects.georadiusByMemberStore("key", "member", 100.0, GeoUnit.KM, param, storeParam)) + .thenReturn(longCommandObject); + + Response response = pipeliningBase + .georadiusByMemberStore("key", "member", 100.0, GeoUnit.KM, param, storeParam); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testGeosearchByMemberRadius() { + when(commandObjects.geosearch("key", "member", 100.0, GeoUnit.KM)) + .thenReturn(listGeoRadiusResponseCommandObject); + + Response> response = pipeliningBase + .geosearch("key", "member", 100.0, GeoUnit.KM); + + assertThat(commands, contains(listGeoRadiusResponseCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testGeosearchByCoordRadius() { + GeoCoordinate coord = new GeoCoordinate(15.0, 37.0); + + when(commandObjects.geosearch("key", coord, 100.0, GeoUnit.KM)) + .thenReturn(listGeoRadiusResponseCommandObject); + + Response> response = pipeliningBase.geosearch("key", coord, 100.0, GeoUnit.KM); + + assertThat(commands, contains(listGeoRadiusResponseCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testGeosearchByMemberBox() { + when(commandObjects.geosearch("key", "member", 50.0, 50.0, GeoUnit.KM)) + .thenReturn(listGeoRadiusResponseCommandObject); + + Response> response = pipeliningBase + .geosearch("key", "member", 50.0, 50.0, GeoUnit.KM); + + assertThat(commands, contains(listGeoRadiusResponseCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testGeosearchByCoordBox() { + GeoCoordinate coord = new GeoCoordinate(15.0, 37.0); + + when(commandObjects.geosearch("key", coord, 50.0, 50.0, GeoUnit.KM)) + .thenReturn(listGeoRadiusResponseCommandObject); + + Response> response = pipeliningBase + .geosearch("key", coord, 50.0, 50.0, GeoUnit.KM); + + assertThat(commands, contains(listGeoRadiusResponseCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testGeosearchWithParams() { + GeoSearchParam params = new GeoSearchParam(); + + when(commandObjects.geosearch("key", params)).thenReturn(listGeoRadiusResponseCommandObject); + + Response> response = pipeliningBase.geosearch("key", params); + + assertThat(commands, contains(listGeoRadiusResponseCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testGeosearchStoreByMemberRadius() { + when(commandObjects.geosearchStore("dest", "src", "member", 100.0, GeoUnit.KM)) + .thenReturn(longCommandObject); + + Response response = pipeliningBase + .geosearchStore("dest", "src", "member", 100.0, GeoUnit.KM); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testGeosearchStoreByCoordRadius() { + GeoCoordinate coord = new GeoCoordinate(15.0, 37.0); + + when(commandObjects.geosearchStore("dest", "src", coord, 100.0, GeoUnit.KM)) + .thenReturn(longCommandObject); + + Response response = pipeliningBase.geosearchStore("dest", "src", coord, 100.0, GeoUnit.KM); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testGeosearchStoreByMemberBox() { + when(commandObjects.geosearchStore("dest", "src", "member", 50.0, 50.0, GeoUnit.KM)) + .thenReturn(longCommandObject); + + Response response = pipeliningBase + .geosearchStore("dest", "src", "member", 50.0, 50.0, GeoUnit.KM); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testGeosearchStoreByCoordBox() { + GeoCoordinate coord = new GeoCoordinate(15.0, 37.0); + + when(commandObjects.geosearchStore("dest", "src", coord, 50.0, 50.0, GeoUnit.KM)) + .thenReturn(longCommandObject); + + Response response = pipeliningBase + .geosearchStore("dest", "src", coord, 50.0, 50.0, GeoUnit.KM); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testGeosearchStoreWithParams() { + GeoSearchParam params = new GeoSearchParam(); + + when(commandObjects.geosearchStore("dest", "src", params)).thenReturn(longCommandObject); + + Response response = pipeliningBase.geosearchStore("dest", "src", params); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testGeosearchStoreStoreDist() { + GeoSearchParam params = new GeoSearchParam(); + + when(commandObjects.geosearchStoreStoreDist("dest", "src", params)).thenReturn(longCommandObject); + + Response response = pipeliningBase.geosearchStoreStoreDist("dest", "src", params); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testPfadd() { + when(commandObjects.pfadd("key", "element1", "element2")).thenReturn(longCommandObject); + + Response response = pipeliningBase.pfadd("key", "element1", "element2"); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testPfmerge() { + when(commandObjects.pfmerge("destkey", "sourcekey1", "sourcekey2")).thenReturn(stringCommandObject); + + Response response = pipeliningBase.pfmerge("destkey", "sourcekey1", "sourcekey2"); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testPfcountSingleKey() { + when(commandObjects.pfcount("key")).thenReturn(longCommandObject); + + Response response = pipeliningBase.pfcount("key"); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testPfcountMultipleKeys() { + when(commandObjects.pfcount("key1", "key2")).thenReturn(longCommandObject); + + Response response = pipeliningBase.pfcount("key1", "key2"); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testXadd() { + StreamEntryID id = new StreamEntryID(); + + Map hash = new HashMap<>(); + hash.put("field1", "value1"); + + when(commandObjects.xadd("key", id, hash)).thenReturn(streamEntryIdCommandObject); + + Response response = pipeliningBase.xadd("key", id, hash); + + assertThat(commands, contains(streamEntryIdCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testXaddWithParams() { + XAddParams params = new XAddParams(); + + Map hash = new HashMap<>(); + hash.put("field1", "value1"); + + when(commandObjects.xadd("key", params, hash)).thenReturn(streamEntryIdCommandObject); + + Response response = pipeliningBase.xadd("key", params, hash); + + assertThat(commands, contains(streamEntryIdCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testXlen() { + when(commandObjects.xlen("key")).thenReturn(longCommandObject); + + Response response = pipeliningBase.xlen("key"); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testXrange() { + StreamEntryID start = new StreamEntryID("0-0"); + StreamEntryID end = new StreamEntryID("9999999999999-0"); + + when(commandObjects.xrange("key", start, end)).thenReturn(listStreamEntryCommandObject); + + Response> response = pipeliningBase.xrange("key", start, end); + + assertThat(commands, contains(listStreamEntryCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testXrangeWithCount() { + StreamEntryID start = new StreamEntryID("0-0"); + StreamEntryID end = new StreamEntryID("9999999999999-0"); + int count = 10; + + when(commandObjects.xrange("key", start, end, count)).thenReturn(listStreamEntryCommandObject); + + Response> response = pipeliningBase.xrange("key", start, end, count); + + assertThat(commands, contains(listStreamEntryCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testXrevrange() { + StreamEntryID end = new StreamEntryID("9999999999999-0"); + StreamEntryID start = new StreamEntryID("0-0"); + + when(commandObjects.xrevrange("key", end, start)).thenReturn(listStreamEntryCommandObject); + + Response> response = pipeliningBase.xrevrange("key", end, start); + + assertThat(commands, contains(listStreamEntryCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testXrevrangeWithCount() { + StreamEntryID end = new StreamEntryID("9999999999999-0"); + StreamEntryID start = new StreamEntryID("0-0"); + int count = 10; + + when(commandObjects.xrevrange("key", end, start, count)).thenReturn(listStreamEntryCommandObject); + + Response> response = pipeliningBase.xrevrange("key", end, start, count); + + assertThat(commands, contains(listStreamEntryCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testXrangeWithStringIDs() { + String start = "-"; + String end = "+"; + + when(commandObjects.xrange("key", start, end)).thenReturn(listStreamEntryCommandObject); + + Response> response = pipeliningBase.xrange("key", start, end); + + assertThat(commands, contains(listStreamEntryCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testXrangeWithStringIDsAndCount() { + String start = "-"; + String end = "+"; + int count = 10; + + when(commandObjects.xrange("key", start, end, count)).thenReturn(listStreamEntryCommandObject); + + Response> response = pipeliningBase.xrange("key", start, end, count); + + assertThat(commands, contains(listStreamEntryCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testXrevrangeWithStringIDs() { + String end = "+"; + String start = "-"; + + when(commandObjects.xrevrange("key", end, start)).thenReturn(listStreamEntryCommandObject); + + Response> response = pipeliningBase.xrevrange("key", end, start); + + assertThat(commands, contains(listStreamEntryCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testXrevrangeWithStringIDsAndCount() { + String end = "+"; + String start = "-"; + int count = 10; + + when(commandObjects.xrevrange("key", end, start, count)).thenReturn(listStreamEntryCommandObject); + + Response> response = pipeliningBase.xrevrange("key", end, start, count); + + assertThat(commands, contains(listStreamEntryCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testXack() { + StreamEntryID[] ids = { new StreamEntryID("1526999352406-0"), new StreamEntryID("1526999352406-1") }; + + when(commandObjects.xack("key", "group", ids)).thenReturn(longCommandObject); + + Response response = pipeliningBase.xack("key", "group", ids); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testXgroupCreate() { + StreamEntryID id = new StreamEntryID("0-0"); + + when(commandObjects.xgroupCreate("key", "groupName", id, true)).thenReturn(stringCommandObject); + + Response response = pipeliningBase.xgroupCreate("key", "groupName", id, true); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testXgroupSetID() { + StreamEntryID id = new StreamEntryID("0-0"); + + when(commandObjects.xgroupSetID("key", "groupName", id)).thenReturn(stringCommandObject); + + Response response = pipeliningBase.xgroupSetID("key", "groupName", id); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testXgroupDestroy() { + when(commandObjects.xgroupDestroy("key", "groupName")).thenReturn(longCommandObject); + + Response response = pipeliningBase.xgroupDestroy("key", "groupName"); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testXgroupCreateConsumer() { + when(commandObjects.xgroupCreateConsumer("key", "groupName", "consumerName")) + .thenReturn(booleanCommandObject); + + Response response = pipeliningBase.xgroupCreateConsumer("key", "groupName", "consumerName"); + + assertThat(commands, contains(booleanCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testXgroupDelConsumer() { + when(commandObjects.xgroupDelConsumer("key", "groupName", "consumerName")) + .thenReturn(longCommandObject); + + Response response = pipeliningBase.xgroupDelConsumer("key", "groupName", "consumerName"); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testXpendingSummary() { + when(commandObjects.xpending("key", "groupName")).thenReturn(streamPendingSummaryCommandObject); + + Response response = pipeliningBase.xpending("key", "groupName"); + + assertThat(commands, contains(streamPendingSummaryCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testXpendingRange() { + XPendingParams params = new XPendingParams(); + + when(commandObjects.xpending("key", "groupName", params)).thenReturn(listStreamPendingEntryCommandObject); + + Response> response = pipeliningBase.xpending("key", "groupName", params); + + assertThat(commands, contains(listStreamPendingEntryCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testXdel() { + StreamEntryID[] ids = { new StreamEntryID("1526999352406-0"), new StreamEntryID("1526999352406-1") }; + + when(commandObjects.xdel("key", ids)).thenReturn(longCommandObject); + + Response response = pipeliningBase.xdel("key", ids); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testXtrim() { + when(commandObjects.xtrim("key", 1000L, true)).thenReturn(longCommandObject); + + Response response = pipeliningBase.xtrim("key", 1000L, true); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testXtrimWithParams() { + XTrimParams params = new XTrimParams().maxLen(1000L); + when(commandObjects.xtrim("key", params)).thenReturn(longCommandObject); + + Response response = pipeliningBase.xtrim("key", params); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testXclaim() { + StreamEntryID[] ids = { new StreamEntryID("1526999352406-0"), new StreamEntryID("1526999352406-1") }; + XClaimParams params = new XClaimParams().idle(10000L); + + when(commandObjects.xclaim("key", "group", "consumerName", 10000L, params, ids)) + .thenReturn(listStreamEntryCommandObject); + + Response> response = pipeliningBase + .xclaim("key", "group", "consumerName", 10000L, params, ids); + + assertThat(commands, contains(listStreamEntryCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testXclaimJustId() { + StreamEntryID[] ids = { new StreamEntryID("1526999352406-0"), new StreamEntryID("1526999352406-1") }; + XClaimParams params = new XClaimParams().idle(10000L); + + when(commandObjects.xclaimJustId("key", "group", "consumerName", 10000L, params, ids)) + .thenReturn(listStreamEntryIdCommandObject); + + Response> response = pipeliningBase + .xclaimJustId("key", "group", "consumerName", 10000L, params, ids); + + assertThat(commands, contains(listStreamEntryIdCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testXautoclaim() { + StreamEntryID start = new StreamEntryID("0-0"); + XAutoClaimParams params = new XAutoClaimParams(); + + when(commandObjects.xautoclaim("key", "group", "consumerName", 10000L, start, params)) + .thenReturn(entryStreamEntryIdListStreamEntryCommandObject); + + Response>> response = pipeliningBase + .xautoclaim("key", "group", "consumerName", 10000L, start, params); + + assertThat(commands, contains(entryStreamEntryIdListStreamEntryCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testXautoclaimJustId() { + StreamEntryID start = new StreamEntryID("0-0"); + XAutoClaimParams params = new XAutoClaimParams(); + + when(commandObjects.xautoclaimJustId("key", "group", "consumerName", 10000L, start, params)) + .thenReturn(entryStreamEntryIdListStreamEntryIdCommandObject); + + Response>> response = pipeliningBase + .xautoclaimJustId("key", "group", "consumerName", 10000L, start, params); + + assertThat(commands, contains(entryStreamEntryIdListStreamEntryIdCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testXinfoStream() { + when(commandObjects.xinfoStream("key")).thenReturn(streamInfoCommandObject); + + Response response = pipeliningBase.xinfoStream("key"); + + assertThat(commands, contains(streamInfoCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testXinfoStreamFull() { + when(commandObjects.xinfoStreamFull("key")).thenReturn(streamFullInfoCommandObject); + + Response response = pipeliningBase.xinfoStreamFull("key"); + + assertThat(commands, contains(streamFullInfoCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testXinfoStreamFullWithCount() { + int count = 10; + when(commandObjects.xinfoStreamFull("key", count)).thenReturn(streamFullInfoCommandObject); + + Response response = pipeliningBase.xinfoStreamFull("key", count); + + assertThat(commands, contains(streamFullInfoCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testXinfoGroups() { + when(commandObjects.xinfoGroups("key")).thenReturn(listStreamGroupInfoCommandObject); + + Response> response = pipeliningBase.xinfoGroups("key"); + + assertThat(commands, contains(listStreamGroupInfoCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testXinfoConsumers() { + when(commandObjects.xinfoConsumers("key", "group")).thenReturn(listStreamConsumersInfoCommandObject); + + Response> response = pipeliningBase.xinfoConsumers("key", "group"); + + assertThat(commands, contains(listStreamConsumersInfoCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testXinfoConsumers2() { + when(commandObjects.xinfoConsumers2("key", "group")).thenReturn(listStreamConsumerInfoCommandObject); + + Response> response = pipeliningBase.xinfoConsumers2("key", "group"); + + assertThat(commands, contains(listStreamConsumerInfoCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testXread() { + XReadParams xReadParams = new XReadParams(); + + Map streams = new HashMap<>(); + streams.put("key1", new StreamEntryID("0-0")); + streams.put("key2", new StreamEntryID("0-0")); + + when(commandObjects.xread(xReadParams, streams)).thenReturn(listEntryStringListStreamEntryCommandObject); + + Response>>> response = pipeliningBase.xread(xReadParams, streams); + + assertThat(commands, contains(listEntryStringListStreamEntryCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testXreadGroup() { + XReadGroupParams xReadGroupParams = new XReadGroupParams(); + + Map streams = new HashMap<>(); + streams.put("stream1", new StreamEntryID("0-0")); + + when(commandObjects.xreadGroup("groupName", "consumer", xReadGroupParams, streams)) + .thenReturn(listEntryStringListStreamEntryCommandObject); + + Response>>> response = pipeliningBase + .xreadGroup("groupName", "consumer", xReadGroupParams, streams); + + assertThat(commands, contains(listEntryStringListStreamEntryCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testEval() { + String script = "return 'Hello, world!'"; + when(commandObjects.eval(script)).thenReturn(objectCommandObject); + + Response response = pipeliningBase.eval(script); + + assertThat(commands, contains(objectCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testEvalWithKeysAndParams() { + String script = "return KEYS[1] .. ARGV[1]"; + int keyCount = 1; + + when(commandObjects.eval(script, keyCount, "key", "arg")).thenReturn(objectCommandObject); + + Response response = pipeliningBase.eval(script, keyCount, "key", "arg"); + + assertThat(commands, contains(objectCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testEvalWithLists() { + String script = "return KEYS[1] .. ARGV[1]"; + List keys = Collections.singletonList("key"); + List args = Collections.singletonList("arg"); + + when(commandObjects.eval(script, keys, args)).thenReturn(objectCommandObject); + + Response response = pipeliningBase.eval(script, keys, args); + + assertThat(commands, contains(objectCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testEvalReadonlyWithLists() { + String script = "return KEYS[1] .. ARGV[1]"; + List keys = Collections.singletonList("key"); + List args = Collections.singletonList("arg"); + + when(commandObjects.evalReadonly(script, keys, args)).thenReturn(objectCommandObject); + + Response response = pipeliningBase.evalReadonly(script, keys, args); + + assertThat(commands, contains(objectCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testEvalsha() { + String sha1 = "somehash"; + + when(commandObjects.evalsha(sha1)).thenReturn(objectCommandObject); + + Response response = pipeliningBase.evalsha(sha1); + + assertThat(commands, contains(objectCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testEvalshaWithKeysAndParams() { + String sha1 = "somehash"; + int keyCount = 1; + + when(commandObjects.evalsha(sha1, keyCount, "key", "arg")).thenReturn(objectCommandObject); + + Response response = pipeliningBase.evalsha(sha1, keyCount, "key", "arg"); + + assertThat(commands, contains(objectCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testEvalshaWithLists() { + String sha1 = "somehash"; + List keys = Collections.singletonList("key"); + List args = Collections.singletonList("arg"); + + when(commandObjects.evalsha(sha1, keys, args)).thenReturn(objectCommandObject); + + Response response = pipeliningBase.evalsha(sha1, keys, args); + + assertThat(commands, contains(objectCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testEvalshaReadonlyWithLists() { + String sha1 = "somehash"; + List keys = Collections.singletonList("key"); + List args = Collections.singletonList("arg"); + + when(commandObjects.evalshaReadonly(sha1, keys, args)).thenReturn(objectCommandObject); + + Response response = pipeliningBase.evalshaReadonly(sha1, keys, args); + + assertThat(commands, contains(objectCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testWaitReplicas() { + int replicas = 2; + long timeout = 1000L; + + when(commandObjects.waitReplicas("key", replicas, timeout)).thenReturn(longCommandObject); + + Response response = pipeliningBase.waitReplicas("key", replicas, timeout); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testWaitAOF() { + long numLocal = 1L; + long numReplicas = 1L; + long timeout = 1000L; + + when(commandObjects.waitAOF("key", numLocal, numReplicas, timeout)).thenReturn(keyValueLongLongCommandObject); + + Response> response = pipeliningBase.waitAOF("key", numLocal, numReplicas, timeout); + + assertThat(commands, contains(keyValueLongLongCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testEvalWithSampleKey() { + String script = "return 'Hello, world!'"; + + when(commandObjects.eval(script, "key")).thenReturn(objectCommandObject); + + Response response = pipeliningBase.eval(script, "key"); + + assertThat(commands, contains(objectCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testEvalshaWithSampleKey() { + String sha1 = "somehash"; + + when(commandObjects.evalsha(sha1, "key")).thenReturn(objectCommandObject); + + Response response = pipeliningBase.evalsha(sha1, "key"); + + assertThat(commands, contains(objectCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testScriptExists() { + String[] sha1 = { "somehash1", "somehash2" }; + + when(commandObjects.scriptExists("key", sha1)).thenReturn(listBooleanCommandObject); + + Response> response = pipeliningBase.scriptExists("key", sha1); + + assertThat(commands, contains(listBooleanCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testScriptLoad() { + String script = "return 'Hello, world!'"; + + when(commandObjects.scriptLoad(script, "key")).thenReturn(stringCommandObject); + + Response response = pipeliningBase.scriptLoad(script, "key"); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testScriptFlush() { + when(commandObjects.scriptFlush("key")).thenReturn(stringCommandObject); + + Response response = pipeliningBase.scriptFlush("key"); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testScriptFlushWithFlushMode() { + FlushMode flushMode = FlushMode.SYNC; + + when(commandObjects.scriptFlush("key", flushMode)).thenReturn(stringCommandObject); + + Response response = pipeliningBase.scriptFlush("key", flushMode); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testScriptKill() { + when(commandObjects.scriptKill("key")).thenReturn(stringCommandObject); + + Response response = pipeliningBase.scriptKill("key"); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testFcallBytes() { + byte[] name = "functionName".getBytes(); + List keys = Collections.singletonList("key".getBytes()); + List args = Collections.singletonList("arg".getBytes()); + + when(commandObjects.fcall(name, keys, args)).thenReturn(objectCommandObject); + + Response response = pipeliningBase.fcall(name, keys, args); + + assertThat(commands, contains(objectCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testFcallStrings() { + String name = "functionName"; + List keys = Collections.singletonList("key"); + List args = Collections.singletonList("arg"); + + when(commandObjects.fcall(name, keys, args)).thenReturn(objectCommandObject); + + Response response = pipeliningBase.fcall(name, keys, args); + + assertThat(commands, contains(objectCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testFcallReadonlyBytes() { + byte[] name = "functionName".getBytes(); + List keys = Collections.singletonList("key".getBytes()); + List args = Collections.singletonList("arg".getBytes()); + + when(commandObjects.fcallReadonly(name, keys, args)).thenReturn(objectCommandObject); + + Response response = pipeliningBase.fcallReadonly(name, keys, args); + + assertThat(commands, contains(objectCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testFcallReadonlyStrings() { + String name = "functionName"; + List keys = Collections.singletonList("key"); + List args = Collections.singletonList("arg"); + + when(commandObjects.fcallReadonly(name, keys, args)).thenReturn(objectCommandObject); + + Response response = pipeliningBase.fcallReadonly(name, keys, args); + + assertThat(commands, contains(objectCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testFunctionDeleteBytes() { + byte[] libraryName = "libraryName".getBytes(); + + when(commandObjects.functionDelete(libraryName)).thenReturn(stringCommandObject); + + Response response = pipeliningBase.functionDelete(libraryName); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testFunctionDeleteStrings() { + String libraryName = "libraryName"; + + when(commandObjects.functionDelete(libraryName)).thenReturn(stringCommandObject); + + Response response = pipeliningBase.functionDelete(libraryName); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testFunctionDump() { + when(commandObjects.functionDump()).thenReturn(bytesCommandObject); + + Response response = pipeliningBase.functionDump(); + + assertThat(commands, contains(bytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testFunctionListWithPattern() { + String libraryNamePattern = "lib*"; + + when(commandObjects.functionList(libraryNamePattern)).thenReturn(listLibraryInfoCommandObject); + + Response> response = pipeliningBase.functionList(libraryNamePattern); + + assertThat(commands, contains(listLibraryInfoCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testFunctionList() { + when(commandObjects.functionList()).thenReturn(listLibraryInfoCommandObject); + + Response> response = pipeliningBase.functionList(); + + assertThat(commands, contains(listLibraryInfoCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testFunctionListWithCodeWithPattern() { + String libraryNamePattern = "lib*"; + + when(commandObjects.functionListWithCode(libraryNamePattern)).thenReturn(listLibraryInfoCommandObject); + + Response> response = pipeliningBase.functionListWithCode(libraryNamePattern); + + assertThat(commands, contains(listLibraryInfoCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testFunctionListWithCode() { + when(commandObjects.functionListWithCode()).thenReturn(listLibraryInfoCommandObject); + + Response> response = pipeliningBase.functionListWithCode(); + + assertThat(commands, contains(listLibraryInfoCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testFunctionListByteArray() { + when(commandObjects.functionListBinary()).thenReturn(listObjectCommandObject); + + Response> response = pipeliningBase.functionListBinary(); + + assertThat(commands, contains(listObjectCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testFunctionListBytes() { + byte[] libraryNamePattern = "lib*".getBytes(); + + when(commandObjects.functionList(libraryNamePattern)).thenReturn(listObjectCommandObject); + + Response> response = pipeliningBase.functionList(libraryNamePattern); + + assertThat(commands, contains(listObjectCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testFunctionListWithCodeByteArray() { + when(commandObjects.functionListWithCodeBinary()).thenReturn(listObjectCommandObject); + + Response> response = pipeliningBase.functionListWithCodeBinary(); + + assertThat(commands, contains(listObjectCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testFunctionListWithCodeBytes() { + byte[] libraryNamePattern = "lib*".getBytes(); + + when(commandObjects.functionListWithCode(libraryNamePattern)).thenReturn(listObjectCommandObject); + + Response> response = pipeliningBase.functionListWithCode(libraryNamePattern); + + assertThat(commands, contains(listObjectCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testFunctionLoadBytes() { + byte[] functionCode = "return 'Hello, world!'".getBytes(); + + when(commandObjects.functionLoad(functionCode)).thenReturn(stringCommandObject); + + Response response = pipeliningBase.functionLoad(functionCode); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testFunctionLoadStrings() { + String functionCode = "return 'Hello, world!'"; + + when(commandObjects.functionLoad(functionCode)).thenReturn(stringCommandObject); + + Response response = pipeliningBase.functionLoad(functionCode); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testFunctionLoadReplaceBytes() { + byte[] functionCode = "return 'Hello, world!'".getBytes(); + + when(commandObjects.functionLoadReplace(functionCode)).thenReturn(stringCommandObject); + + Response response = pipeliningBase.functionLoadReplace(functionCode); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testFunctionLoadReplaceStrings() { + String functionCode = "return 'Hello, world!'"; + + when(commandObjects.functionLoadReplace(functionCode)).thenReturn(stringCommandObject); + + Response response = pipeliningBase.functionLoadReplace(functionCode); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testFunctionRestoreBytes() { + byte[] serializedValue = "serialized".getBytes(); + + when(commandObjects.functionRestore(serializedValue)).thenReturn(stringCommandObject); + + Response response = pipeliningBase.functionRestore(serializedValue); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testFunctionRestoreBytesWithPolicy() { + byte[] serializedValue = "serialized".getBytes(); + FunctionRestorePolicy policy = FunctionRestorePolicy.FLUSH; + + when(commandObjects.functionRestore(serializedValue, policy)).thenReturn(stringCommandObject); + + Response response = pipeliningBase.functionRestore(serializedValue, policy); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testFunctionFlush() { + when(commandObjects.functionFlush()).thenReturn(stringCommandObject); + + Response response = pipeliningBase.functionFlush(); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testFunctionFlushWithMode() { + FlushMode mode = FlushMode.SYNC; + + when(commandObjects.functionFlush(mode)).thenReturn(stringCommandObject); + + Response response = pipeliningBase.functionFlush(mode); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testFunctionKill() { + when(commandObjects.functionKill()).thenReturn(stringCommandObject); + + Response response = pipeliningBase.functionKill(); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testFunctionStats() { + when(commandObjects.functionStats()).thenReturn(functionStatsCommandObject); + + Response response = pipeliningBase.functionStats(); + + assertThat(commands, contains(functionStatsCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testFunctionStatsByteArray() { + when(commandObjects.functionStatsBinary()).thenReturn(objectCommandObject); + + Response response = pipeliningBase.functionStatsBinary(); + + assertThat(commands, contains(objectCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testGeoaddSingleMember() { + byte[] key = "location".getBytes(); + double longitude = 13.361389; + double latitude = 38.115556; + byte[] member = "Sicily".getBytes(); + + when(commandObjects.geoadd(key, longitude, latitude, member)).thenReturn(longCommandObject); + + Response response = pipeliningBase.geoadd(key, longitude, latitude, member); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testGeoaddMemberCoordinateMap() { + byte[] key = "location".getBytes(); + + Map memberCoordinateMap = new HashMap<>(); + memberCoordinateMap.put("Palermo".getBytes(), new GeoCoordinate(13.361389, 38.115556)); + + when(commandObjects.geoadd(key, memberCoordinateMap)).thenReturn(longCommandObject); + + Response response = pipeliningBase.geoadd(key, memberCoordinateMap); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testGeoaddWithParams() { + byte[] key = "location".getBytes(); + GeoAddParams params = GeoAddParams.geoAddParams(); + + Map memberCoordinateMap = new HashMap<>(); + memberCoordinateMap.put("Palermo".getBytes(), new GeoCoordinate(13.361389, 38.115556)); + + when(commandObjects.geoadd(key, params, memberCoordinateMap)).thenReturn(longCommandObject); + + Response response = pipeliningBase.geoadd(key, params, memberCoordinateMap); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testGeodistByteArray() { + byte[] key = "location".getBytes(); + byte[] member1 = "Palermo".getBytes(); + byte[] member2 = "Catania".getBytes(); + + when(commandObjects.geodist(key, member1, member2)).thenReturn(doubleCommandObject); + + Response response = pipeliningBase.geodist(key, member1, member2); + + assertThat(commands, contains(doubleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testGeodistWithUnitByteArray() { + byte[] key = "location".getBytes(); + byte[] member1 = "Palermo".getBytes(); + byte[] member2 = "Catania".getBytes(); + GeoUnit unit = GeoUnit.KM; + + when(commandObjects.geodist(key, member1, member2, unit)).thenReturn(doubleCommandObject); + + Response response = pipeliningBase.geodist(key, member1, member2, unit); + + assertThat(commands, contains(doubleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testGeohashByteArray() { + byte[] key = "location".getBytes(); + byte[] member = "Palermo".getBytes(); + + when(commandObjects.geohash(key, member)).thenReturn(listBytesCommandObject); + + Response> response = pipeliningBase.geohash(key, member); + + assertThat(commands, contains(listBytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testGeoposByteArray() { + byte[] key = "location".getBytes(); + byte[] member = "Palermo".getBytes(); + + when(commandObjects.geopos(key, member)).thenReturn(listGeoCoordinateCommandObject); + + Response> response = pipeliningBase.geopos(key, member); + + assertThat(commands, contains(listGeoCoordinateCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testGeoradiusByteArray() { + byte[] key = "location".getBytes(); + double longitude = 13.361389; + double latitude = 38.115556; + double radius = 100; + GeoUnit unit = GeoUnit.KM; + + when(commandObjects.georadius(key, longitude, latitude, radius, unit)).thenReturn(listGeoRadiusResponseCommandObject); + + Response> response = pipeliningBase.georadius(key, longitude, latitude, radius, unit); + + assertThat(commands, contains(listGeoRadiusResponseCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testGeoradiusReadonlyByteArray() { + byte[] key = "location".getBytes(); + double longitude = 13.361389; + double latitude = 38.115556; + double radius = 100; + GeoUnit unit = GeoUnit.KM; + + when(commandObjects.georadiusReadonly(key, longitude, latitude, radius, unit)).thenReturn(listGeoRadiusResponseCommandObject); + + Response> response = pipeliningBase.georadiusReadonly(key, longitude, latitude, radius, unit); + + assertThat(commands, contains(listGeoRadiusResponseCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testGeoradiusWithParamByteArray() { + byte[] key = "location".getBytes(); + double longitude = 13.361389; + double latitude = 38.115556; + double radius = 100; + GeoUnit unit = GeoUnit.KM; + GeoRadiusParam param = GeoRadiusParam.geoRadiusParam(); + + when(commandObjects.georadius(key, longitude, latitude, radius, unit, param)).thenReturn(listGeoRadiusResponseCommandObject); + + Response> response = pipeliningBase.georadius(key, longitude, latitude, radius, unit, param); + + assertThat(commands, contains(listGeoRadiusResponseCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testGeoradiusReadonlyWithParamByteArray() { + byte[] key = "location".getBytes(); + double longitude = 13.361389; + double latitude = 38.115556; + double radius = 100; + GeoUnit unit = GeoUnit.KM; + GeoRadiusParam param = GeoRadiusParam.geoRadiusParam(); + + when(commandObjects.georadiusReadonly(key, longitude, latitude, radius, unit, param)).thenReturn(listGeoRadiusResponseCommandObject); + + Response> response = pipeliningBase.georadiusReadonly(key, longitude, latitude, radius, unit, param); + + assertThat(commands, contains(listGeoRadiusResponseCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testGeoradiusByMemberByteArray() { + byte[] key = "location".getBytes(); + byte[] member = "Palermo".getBytes(); + double radius = 100; + GeoUnit unit = GeoUnit.KM; + + when(commandObjects.georadiusByMember(key, member, radius, unit)).thenReturn(listGeoRadiusResponseCommandObject); + + Response> response = pipeliningBase.georadiusByMember(key, member, radius, unit); + + assertThat(commands, contains(listGeoRadiusResponseCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testGeoradiusByMemberReadonlyByteArray() { + byte[] key = "location".getBytes(); + byte[] member = "Palermo".getBytes(); + double radius = 100; + GeoUnit unit = GeoUnit.KM; + + when(commandObjects.georadiusByMemberReadonly(key, member, radius, unit)).thenReturn(listGeoRadiusResponseCommandObject); + + Response> response = pipeliningBase.georadiusByMemberReadonly(key, member, radius, unit); + + assertThat(commands, contains(listGeoRadiusResponseCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testGeoradiusByMemberWithParamByteArray() { + byte[] key = "location".getBytes(); + byte[] member = "Palermo".getBytes(); + double radius = 100; + GeoUnit unit = GeoUnit.KM; + GeoRadiusParam param = GeoRadiusParam.geoRadiusParam(); + + when(commandObjects.georadiusByMember(key, member, radius, unit, param)).thenReturn(listGeoRadiusResponseCommandObject); + + Response> response = pipeliningBase.georadiusByMember(key, member, radius, unit, param); + + assertThat(commands, contains(listGeoRadiusResponseCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testGeoradiusByMemberReadonlyWithParamByteArray() { + byte[] key = "location".getBytes(); + byte[] member = "Palermo".getBytes(); + double radius = 100; + GeoUnit unit = GeoUnit.KM; + GeoRadiusParam param = GeoRadiusParam.geoRadiusParam(); + + when(commandObjects.georadiusByMemberReadonly(key, member, radius, unit, param)).thenReturn(listGeoRadiusResponseCommandObject); + + Response> response = pipeliningBase.georadiusByMemberReadonly(key, member, radius, unit, param); + + assertThat(commands, contains(listGeoRadiusResponseCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testGeoradiusStoreByteArray() { + byte[] key = "location".getBytes(); + double longitude = 13.361389; + double latitude = 38.115556; + double radius = 100; + GeoUnit unit = GeoUnit.KM; + GeoRadiusParam param = GeoRadiusParam.geoRadiusParam(); + GeoRadiusStoreParam storeParam = GeoRadiusStoreParam.geoRadiusStoreParam().store("storeKey"); + + when(commandObjects.georadiusStore(key, longitude, latitude, radius, unit, param, storeParam)).thenReturn(longCommandObject); + + Response response = pipeliningBase.georadiusStore(key, longitude, latitude, radius, unit, param, storeParam); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testGeoradiusByMemberStoreByteArray() { + byte[] key = "location".getBytes(); + byte[] member = "Palermo".getBytes(); + double radius = 100; + GeoUnit unit = GeoUnit.KM; + GeoRadiusParam param = GeoRadiusParam.geoRadiusParam(); + GeoRadiusStoreParam storeParam = GeoRadiusStoreParam.geoRadiusStoreParam().store("storeKey"); + + when(commandObjects.georadiusByMemberStore(key, member, radius, unit, param, storeParam)).thenReturn(longCommandObject); + + Response response = pipeliningBase.georadiusByMemberStore(key, member, radius, unit, param, storeParam); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testGeosearchByMemberRadiusByteArray() { + byte[] key = "location".getBytes(); + byte[] member = "Palermo".getBytes(); + double radius = 100; + GeoUnit unit = GeoUnit.KM; + + when(commandObjects.geosearch(key, member, radius, unit)).thenReturn(listGeoRadiusResponseCommandObject); + + Response> response = pipeliningBase.geosearch(key, member, radius, unit); + + assertThat(commands, contains(listGeoRadiusResponseCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testGeosearchByCoordinateRadiusByteArray() { + byte[] key = "location".getBytes(); + GeoCoordinate coord = new GeoCoordinate(13.361389, 38.115556); + double radius = 100; + GeoUnit unit = GeoUnit.KM; + + when(commandObjects.geosearch(key, coord, radius, unit)).thenReturn(listGeoRadiusResponseCommandObject); + + Response> response = pipeliningBase.geosearch(key, coord, radius, unit); + + assertThat(commands, contains(listGeoRadiusResponseCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testGeosearchByMemberBoxByteArray() { + byte[] key = "location".getBytes(); + byte[] member = "Palermo".getBytes(); + double width = 200; + double height = 100; + GeoUnit unit = GeoUnit.KM; + + when(commandObjects.geosearch(key, member, width, height, unit)).thenReturn(listGeoRadiusResponseCommandObject); + + Response> response = pipeliningBase.geosearch(key, member, width, height, unit); + + assertThat(commands, contains(listGeoRadiusResponseCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testGeosearchByCoordinateBoxByteArray() { + byte[] key = "location".getBytes(); + GeoCoordinate coord = new GeoCoordinate(13.361389, 38.115556); + double width = 200; + double height = 100; + GeoUnit unit = GeoUnit.KM; + + when(commandObjects.geosearch(key, coord, width, height, unit)).thenReturn(listGeoRadiusResponseCommandObject); + + Response> response = pipeliningBase.geosearch(key, coord, width, height, unit); + + assertThat(commands, contains(listGeoRadiusResponseCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testGeosearchWithParamsByteArray() { + byte[] key = "location".getBytes(); + GeoSearchParam params = GeoSearchParam.geoSearchParam().byRadius(100, GeoUnit.KM); + + when(commandObjects.geosearch(key, params)).thenReturn(listGeoRadiusResponseCommandObject); + + Response> response = pipeliningBase.geosearch(key, params); + + assertThat(commands, contains(listGeoRadiusResponseCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testGeosearchStore() { + byte[] dest = "destination".getBytes(); + byte[] src = "location".getBytes(); + byte[] member = "Palermo".getBytes(); + double radius = 100; + GeoUnit unit = GeoUnit.KM; + + when(commandObjects.geosearchStore(dest, src, member, radius, unit)).thenReturn(longCommandObject); + + Response response = pipeliningBase.geosearchStore(dest, src, member, radius, unit); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testGeosearchStoreByCoordinateRadius() { + byte[] dest = "destination".getBytes(); + byte[] src = "location".getBytes(); + GeoCoordinate coord = new GeoCoordinate(13.361389, 38.115556); + double radius = 100; + GeoUnit unit = GeoUnit.KM; + + when(commandObjects.geosearchStore(dest, src, coord, radius, unit)).thenReturn(longCommandObject); + + Response response = pipeliningBase.geosearchStore(dest, src, coord, radius, unit); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testGeosearchStoreByMemberBoxByteArray() { + byte[] dest = "destination".getBytes(); + byte[] src = "location".getBytes(); + byte[] member = "Palermo".getBytes(); + double width = 200; + double height = 100; + GeoUnit unit = GeoUnit.KM; + + when(commandObjects.geosearchStore(dest, src, member, width, height, unit)).thenReturn(longCommandObject); + + Response response = pipeliningBase.geosearchStore(dest, src, member, width, height, unit); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testGeosearchStoreByCoordinateBox() { + byte[] dest = "destination".getBytes(); + byte[] src = "location".getBytes(); + GeoCoordinate coord = new GeoCoordinate(13.361389, 38.115556); + double width = 200; + double height = 100; + GeoUnit unit = GeoUnit.KM; + + when(commandObjects.geosearchStore(dest, src, coord, width, height, unit)).thenReturn(longCommandObject); + + Response response = pipeliningBase.geosearchStore(dest, src, coord, width, height, unit); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testGeosearchStoreWithParamsByteArray() { + byte[] dest = "destination".getBytes(); + byte[] src = "location".getBytes(); + GeoSearchParam params = GeoSearchParam.geoSearchParam().byRadius(100, GeoUnit.KM); + + when(commandObjects.geosearchStore(dest, src, params)).thenReturn(longCommandObject); + + Response response = pipeliningBase.geosearchStore(dest, src, params); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testGeosearchStoreStoreDistByteArray() { + byte[] dest = "destination".getBytes(); + byte[] src = "location".getBytes(); + GeoSearchParam params = GeoSearchParam.geoSearchParam().byRadius(100, GeoUnit.KM); + + when(commandObjects.geosearchStoreStoreDist(dest, src, params)).thenReturn(longCommandObject); + + Response response = pipeliningBase.geosearchStoreStoreDist(dest, src, params); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testHsetKeyValue() { + byte[] key = "hash".getBytes(); + byte[] field = "field1".getBytes(); + byte[] value = "value1".getBytes(); + + when(commandObjects.hset(key, field, value)).thenReturn(longCommandObject); + + Response response = pipeliningBase.hset(key, field, value); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testHsetMapByteArray() { + byte[] key = "hash".getBytes(); + + Map hash = new HashMap<>(); + hash.put("field1".getBytes(), "value1".getBytes()); + + when(commandObjects.hset(key, hash)).thenReturn(longCommandObject); + + Response response = pipeliningBase.hset(key, hash); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testHgetByteArray() { + byte[] key = "hash".getBytes(); + byte[] field = "field1".getBytes(); + + when(commandObjects.hget(key, field)).thenReturn(bytesCommandObject); + + Response response = pipeliningBase.hget(key, field); + + assertThat(commands, contains(bytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testHsetnxByteArray() { + byte[] key = "hash".getBytes(); + byte[] field = "field1".getBytes(); + byte[] value = "value1".getBytes(); + + when(commandObjects.hsetnx(key, field, value)).thenReturn(longCommandObject); + + Response response = pipeliningBase.hsetnx(key, field, value); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testHmsetByteArray() { + byte[] key = "hash".getBytes(); + + Map hash = new HashMap<>(); + hash.put("field1".getBytes(), "value1".getBytes()); + + when(commandObjects.hmset(key, hash)).thenReturn(stringCommandObject); + + Response response = pipeliningBase.hmset(key, hash); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testHmgetByteArray() { + byte[] key = "hash".getBytes(); + byte[] field1 = "field1".getBytes(); + byte[] field2 = "field2".getBytes(); + + when(commandObjects.hmget(key, field1, field2)).thenReturn(listBytesCommandObject); + + Response> response = pipeliningBase.hmget(key, field1, field2); + + assertThat(commands, contains(listBytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testHincrByByteArray() { + byte[] key = "hash".getBytes(); + byte[] field = "field1".getBytes(); + long increment = 2L; + + when(commandObjects.hincrBy(key, field, increment)).thenReturn(longCommandObject); + + Response response = pipeliningBase.hincrBy(key, field, increment); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testHincrByFloatByteArray() { + byte[] key = "hash".getBytes(); + byte[] field = "field1".getBytes(); + double increment = 2.5; + + when(commandObjects.hincrByFloat(key, field, increment)).thenReturn(doubleCommandObject); + + Response response = pipeliningBase.hincrByFloat(key, field, increment); + + assertThat(commands, contains(doubleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testHexistsByteArray() { + byte[] key = "hash".getBytes(); + byte[] field = "field1".getBytes(); + + when(commandObjects.hexists(key, field)).thenReturn(booleanCommandObject); + + Response response = pipeliningBase.hexists(key, field); + + assertThat(commands, contains(booleanCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testHdelByteArray() { + byte[] key = "hash".getBytes(); + byte[] field1 = "field1".getBytes(); + byte[] field2 = "field2".getBytes(); + + when(commandObjects.hdel(key, field1, field2)).thenReturn(longCommandObject); + + Response response = pipeliningBase.hdel(key, field1, field2); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testHlenByteArray() { + byte[] key = "hash".getBytes(); + + when(commandObjects.hlen(key)).thenReturn(longCommandObject); + + Response response = pipeliningBase.hlen(key); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testHkeysByteArray() { + byte[] key = "hash".getBytes(); + + when(commandObjects.hkeys(key)).thenReturn(setBytesCommandObject); + + Response> response = pipeliningBase.hkeys(key); + + assertThat(commands, contains(setBytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testHvalsByteArray() { + byte[] key = "hash".getBytes(); + + when(commandObjects.hvals(key)).thenReturn(listBytesCommandObject); + + Response> response = pipeliningBase.hvals(key); + + assertThat(commands, contains(listBytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testHgetAllByteArray() { + byte[] key = "hash".getBytes(); + + when(commandObjects.hgetAll(key)).thenReturn(mapBytesBytesCommandObject); + + Response> response = pipeliningBase.hgetAll(key); + + assertThat(commands, contains(mapBytesBytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testHrandfieldByteArray() { + byte[] key = "hash".getBytes(); + + when(commandObjects.hrandfield(key)).thenReturn(bytesCommandObject); + + Response response = pipeliningBase.hrandfield(key); + + assertThat(commands, contains(bytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testHrandfieldWithCountByteArray() { + byte[] key = "hash".getBytes(); + long count = 2; + + when(commandObjects.hrandfield(key, count)).thenReturn(listBytesCommandObject); + + Response> response = pipeliningBase.hrandfield(key, count); + + assertThat(commands, contains(listBytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testHrandfieldWithValuesByteArray() { + byte[] key = "hash".getBytes(); + long count = 2; + + when(commandObjects.hrandfieldWithValues(key, count)).thenReturn(listEntryBytesBytesCommandObject); + + Response>> response = pipeliningBase.hrandfieldWithValues(key, count); + + assertThat(commands, contains(listEntryBytesBytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testHscanByteArray() { + byte[] key = "hash".getBytes(); + byte[] cursor = "0".getBytes(); + ScanParams params = new ScanParams().match("*").count(10); + + when(commandObjects.hscan(key, cursor, params)).thenReturn(scanResultEntryBytesBytesCommandObject); + + Response>> response = pipeliningBase.hscan(key, cursor, params); + + assertThat(commands, contains(scanResultEntryBytesBytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testHscanNoValuesByteArray() { + byte[] key = "hash".getBytes(); + byte[] cursor = "0".getBytes(); + ScanParams params = new ScanParams().match("*").count(10); + + when(commandObjects.hscanNoValues(key, cursor, params)).thenReturn(scanResultBytesCommandObject); + + Response> response = pipeliningBase.hscanNoValues(key, cursor, params); + + assertThat(commands, contains(scanResultBytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testHstrlenByteArray() { + byte[] key = "hash".getBytes(); + byte[] field = "field1".getBytes(); + + when(commandObjects.hstrlen(key, field)).thenReturn(longCommandObject); + + Response response = pipeliningBase.hstrlen(key, field); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testPfaddByteArray() { + byte[] key = "hll".getBytes(); + byte[] element1 = "element1".getBytes(); + byte[] element2 = "element2".getBytes(); + + when(commandObjects.pfadd(key, element1, element2)).thenReturn(longCommandObject); + + Response response = pipeliningBase.pfadd(key, element1, element2); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testPfmergeByteArray() { + byte[] destkey = "hll_dest".getBytes(); + byte[] sourcekey1 = "hll1".getBytes(); + byte[] sourcekey2 = "hll2".getBytes(); + + when(commandObjects.pfmerge(destkey, sourcekey1, sourcekey2)).thenReturn(stringCommandObject); + + Response response = pipeliningBase.pfmerge(destkey, sourcekey1, sourcekey2); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testPfcountSingleKeyByteArray() { + byte[] key = "hll".getBytes(); + + when(commandObjects.pfcount(key)).thenReturn(longCommandObject); + + Response response = pipeliningBase.pfcount(key); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testPfcountMultipleKeysByteArray() { + byte[] key1 = "hll1".getBytes(); + byte[] key2 = "hll2".getBytes(); + + when(commandObjects.pfcount(key1, key2)).thenReturn(longCommandObject); + + Response response = pipeliningBase.pfcount(key1, key2); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testExistsByteArray() { + byte[] key = "key".getBytes(); + + when(commandObjects.exists(key)).thenReturn(booleanCommandObject); + + Response response = pipeliningBase.exists(key); + + assertThat(commands, contains(booleanCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testExistsMultipleKeysByteArray() { + byte[] key1 = "key1".getBytes(); + byte[] key2 = "key2".getBytes(); + + when(commandObjects.exists(key1, key2)).thenReturn(longCommandObject); + + Response response = pipeliningBase.exists(key1, key2); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testPersistByteArray() { + byte[] key = "key".getBytes(); + + when(commandObjects.persist(key)).thenReturn(longCommandObject); + + Response response = pipeliningBase.persist(key); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testTypeByteArray() { + byte[] key = "key".getBytes(); + + when(commandObjects.type(key)).thenReturn(stringCommandObject); + + Response response = pipeliningBase.type(key); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testDumpByteArray() { + byte[] key = "key".getBytes(); + + when(commandObjects.dump(key)).thenReturn(bytesCommandObject); + + Response response = pipeliningBase.dump(key); + + assertThat(commands, contains(bytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testRestoreByteArray() { + byte[] key = "key".getBytes(); + long ttl = 0L; + byte[] serializedValue = "serialized".getBytes(); + + when(commandObjects.restore(key, ttl, serializedValue)).thenReturn(stringCommandObject); + + Response response = pipeliningBase.restore(key, ttl, serializedValue); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testRestoreWithParamsByteArray() { + byte[] key = "key".getBytes(); + long ttl = 0L; + byte[] serializedValue = "serialized".getBytes(); + RestoreParams params = RestoreParams.restoreParams().replace(); + + when(commandObjects.restore(key, ttl, serializedValue, params)).thenReturn(stringCommandObject); + + Response response = pipeliningBase.restore(key, ttl, serializedValue, params); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testExpireByteArray() { + byte[] key = "key".getBytes(); + long seconds = 60L; + + when(commandObjects.expire(key, seconds)).thenReturn(longCommandObject); + + Response response = pipeliningBase.expire(key, seconds); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testExpireWithOptionByteArray() { + byte[] key = "key".getBytes(); + long seconds = 60L; + ExpiryOption expiryOption = ExpiryOption.NX; + + when(commandObjects.expire(key, seconds, expiryOption)).thenReturn(longCommandObject); + + Response response = pipeliningBase.expire(key, seconds, expiryOption); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testPexpireByteArray() { + byte[] key = "key".getBytes(); + long milliseconds = 60000L; + + when(commandObjects.pexpire(key, milliseconds)).thenReturn(longCommandObject); + + Response response = pipeliningBase.pexpire(key, milliseconds); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testPexpireWithOptionByteArray() { + byte[] key = "key".getBytes(); + long milliseconds = 60000L; + ExpiryOption expiryOption = ExpiryOption.NX; + + when(commandObjects.pexpire(key, milliseconds, expiryOption)).thenReturn(longCommandObject); + + Response response = pipeliningBase.pexpire(key, milliseconds, expiryOption); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testExpireTimeByteArray() { + byte[] key = "key".getBytes(); + + when(commandObjects.expireTime(key)).thenReturn(longCommandObject); + + Response response = pipeliningBase.expireTime(key); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testPexpireTimeByteArray() { + byte[] key = "key".getBytes(); + + when(commandObjects.pexpireTime(key)).thenReturn(longCommandObject); + + Response response = pipeliningBase.pexpireTime(key); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testExpireAtByteArray() { + byte[] key = "key".getBytes(); + long unixTime = 1625097600L; + + when(commandObjects.expireAt(key, unixTime)).thenReturn(longCommandObject); + + Response response = pipeliningBase.expireAt(key, unixTime); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testExpireAtWithOptionByteArray() { + byte[] key = "key".getBytes(); + long unixTime = 1625097600L; + ExpiryOption expiryOption = ExpiryOption.NX; + + when(commandObjects.expireAt(key, unixTime, expiryOption)).thenReturn(longCommandObject); + + Response response = pipeliningBase.expireAt(key, unixTime, expiryOption); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testPexpireAtByteArray() { + byte[] key = "key".getBytes(); + long millisecondsTimestamp = 1625097600000L; + + when(commandObjects.pexpireAt(key, millisecondsTimestamp)).thenReturn(longCommandObject); + + Response response = pipeliningBase.pexpireAt(key, millisecondsTimestamp); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testPexpireAtWithOptionByteArray() { + byte[] key = "key".getBytes(); + long millisecondsTimestamp = 1625097600000L; + ExpiryOption expiryOption = ExpiryOption.NX; + + when(commandObjects.pexpireAt(key, millisecondsTimestamp, expiryOption)).thenReturn(longCommandObject); + + Response response = pipeliningBase.pexpireAt(key, millisecondsTimestamp, expiryOption); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testTtlByteArray() { + byte[] key = "key".getBytes(); + + when(commandObjects.ttl(key)).thenReturn(longCommandObject); + + Response response = pipeliningBase.ttl(key); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testPttlByteArray() { + byte[] key = "key".getBytes(); + + when(commandObjects.pttl(key)).thenReturn(longCommandObject); + + Response response = pipeliningBase.pttl(key); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testTouchSingleKeyByteArray() { + byte[] key = "key".getBytes(); + + when(commandObjects.touch(key)).thenReturn(longCommandObject); + + Response response = pipeliningBase.touch(key); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testTouchMultipleKeysByteArray() { + byte[] key1 = "key1".getBytes(); + byte[] key2 = "key2".getBytes(); + + when(commandObjects.touch(key1, key2)).thenReturn(longCommandObject); + + Response response = pipeliningBase.touch(key1, key2); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testSortDefaultByteArray() { + byte[] key = "key".getBytes(); + + when(commandObjects.sort(key)).thenReturn(listBytesCommandObject); + + Response> response = pipeliningBase.sort(key); + + assertThat(commands, contains(listBytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testSortWithParamsByteArray() { + byte[] key = "key".getBytes(); + SortingParams sortingParams = new SortingParams().alpha().limit(0, 10); + + when(commandObjects.sort(key, sortingParams)).thenReturn(listBytesCommandObject); + + Response> response = pipeliningBase.sort(key, sortingParams); + + assertThat(commands, contains(listBytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testSortReadonlyByteArray() { + byte[] key = "key".getBytes(); + SortingParams sortingParams = new SortingParams().alpha().limit(0, 10); + + when(commandObjects.sortReadonly(key, sortingParams)).thenReturn(listBytesCommandObject); + + Response> response = pipeliningBase.sortReadonly(key, sortingParams); + + assertThat(commands, contains(listBytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testDelSingleKeyByteArray() { + byte[] key = "key".getBytes(); + + when(commandObjects.del(key)).thenReturn(longCommandObject); + + Response response = pipeliningBase.del(key); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testDelMultipleKeysByteArray() { + byte[] key1 = "key1".getBytes(); + byte[] key2 = "key2".getBytes(); + + when(commandObjects.del(key1, key2)).thenReturn(longCommandObject); + + Response response = pipeliningBase.del(key1, key2); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testUnlinkSingleKeyByteArray() { + byte[] key = "key".getBytes(); + + when(commandObjects.unlink(key)).thenReturn(longCommandObject); + + Response response = pipeliningBase.unlink(key); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testUnlinkMultipleKeysByteArray() { + byte[] key1 = "key1".getBytes(); + byte[] key2 = "key2".getBytes(); + + when(commandObjects.unlink(key1, key2)).thenReturn(longCommandObject); + + Response response = pipeliningBase.unlink(key1, key2); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testCopyByteArray() { + byte[] srcKey = "sourceKey".getBytes(); + byte[] dstKey = "destinationKey".getBytes(); + boolean replace = true; + + when(commandObjects.copy(srcKey, dstKey, replace)).thenReturn(booleanCommandObject); + + Response response = pipeliningBase.copy(srcKey, dstKey, replace); + + assertThat(commands, contains(booleanCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testRenameByteArray() { + byte[] oldkey = "oldKey".getBytes(); + byte[] newkey = "newKey".getBytes(); + + when(commandObjects.rename(oldkey, newkey)).thenReturn(stringCommandObject); + + Response response = pipeliningBase.rename(oldkey, newkey); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testRenamenxByteArray() { + byte[] oldkey = "oldKey".getBytes(); + byte[] newkey = "newKey".getBytes(); + + when(commandObjects.renamenx(oldkey, newkey)).thenReturn(longCommandObject); + + Response response = pipeliningBase.renamenx(oldkey, newkey); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testSortToDstKeyWithParamsByteArray() { + byte[] key = "key".getBytes(); + byte[] dstkey = "dstkey".getBytes(); + SortingParams sortingParams = new SortingParams().alpha().limit(0, 10); + + when(commandObjects.sort(key, sortingParams, dstkey)).thenReturn(longCommandObject); + + Response response = pipeliningBase.sort(key, sortingParams, dstkey); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testSortToDstKeyByteArray() { + byte[] key = "key".getBytes(); + byte[] dstkey = "dstkey".getBytes(); + + when(commandObjects.sort(key, dstkey)).thenReturn(longCommandObject); + + Response response = pipeliningBase.sort(key, dstkey); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testMemoryUsageByteArray() { + byte[] key = "key".getBytes(); + + when(commandObjects.memoryUsage(key)).thenReturn(longCommandObject); + + Response response = pipeliningBase.memoryUsage(key); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testMemoryUsageWithSamplesByteArray() { + byte[] key = "key".getBytes(); + int samples = 5; + + when(commandObjects.memoryUsage(key, samples)).thenReturn(longCommandObject); + + Response response = pipeliningBase.memoryUsage(key, samples); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testObjectRefcountByteArray() { + byte[] key = "key".getBytes(); + + when(commandObjects.objectRefcount(key)).thenReturn(longCommandObject); + + Response response = pipeliningBase.objectRefcount(key); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testObjectEncodingByteArray() { + byte[] key = "key".getBytes(); + + when(commandObjects.objectEncoding(key)).thenReturn(bytesCommandObject); + + Response response = pipeliningBase.objectEncoding(key); + + assertThat(commands, contains(bytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testObjectIdletimeByteArray() { + byte[] key = "key".getBytes(); + + when(commandObjects.objectIdletime(key)).thenReturn(longCommandObject); + + Response response = pipeliningBase.objectIdletime(key); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testObjectFreqByteArray() { + byte[] key = "key".getBytes(); + + when(commandObjects.objectFreq(key)).thenReturn(longCommandObject); + + Response response = pipeliningBase.objectFreq(key); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testMigrateSingleKeyByteArray() { + String host = "localhost"; + int port = 6379; + byte[] key = "key".getBytes(); + int timeout = 1000; + + when(commandObjects.migrate(host, port, key, timeout)).thenReturn(stringCommandObject); + + Response response = pipeliningBase.migrate(host, port, key, timeout); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testMigrateMultipleKeysByteArray() { + String host = "localhost"; + int port = 6379; + int timeout = 1000; + MigrateParams params = MigrateParams.migrateParams().copy().replace(); + byte[] key1 = "key1".getBytes(); + byte[] key2 = "key2".getBytes(); + + when(commandObjects.migrate(host, port, timeout, params, key1, key2)).thenReturn(stringCommandObject); + + Response response = pipeliningBase.migrate(host, port, timeout, params, key1, key2); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testKeysByteArray() { + byte[] pattern = "*".getBytes(); + + when(commandObjects.keys(pattern)).thenReturn(setBytesCommandObject); + + Response> response = pipeliningBase.keys(pattern); + + assertThat(commands, contains(setBytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testScanByteArray() { + byte[] cursor = "0".getBytes(); + + when(commandObjects.scan(cursor)).thenReturn(scanResultBytesCommandObject); + + Response> response = pipeliningBase.scan(cursor); + + assertThat(commands, contains(scanResultBytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testScanWithParamsByteArray() { + byte[] cursor = "0".getBytes(); + ScanParams params = new ScanParams().match("*").count(10); + + when(commandObjects.scan(cursor, params)).thenReturn(scanResultBytesCommandObject); + + Response> response = pipeliningBase.scan(cursor, params); + + assertThat(commands, contains(scanResultBytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testScanWithTypeByteArray() { + byte[] cursor = "0".getBytes(); + ScanParams params = new ScanParams().match("*").count(10); + byte[] type = "string".getBytes(); + + when(commandObjects.scan(cursor, params, type)).thenReturn(scanResultBytesCommandObject); + + Response> response = pipeliningBase.scan(cursor, params, type); + + assertThat(commands, contains(scanResultBytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testRandomBinaryKeyByteArray() { + when(commandObjects.randomBinaryKey()).thenReturn(bytesCommandObject); + + Response response = pipeliningBase.randomBinaryKey(); + + assertThat(commands, contains(bytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testRpushByteArray() { + byte[] key = "key".getBytes(); + byte[] arg1 = "value1".getBytes(); + byte[] arg2 = "value2".getBytes(); + + when(commandObjects.rpush(key, arg1, arg2)).thenReturn(longCommandObject); + + Response response = pipeliningBase.rpush(key, arg1, arg2); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testLpushByteArray() { + byte[] key = "key".getBytes(); + byte[] arg1 = "value1".getBytes(); + byte[] arg2 = "value2".getBytes(); + + when(commandObjects.lpush(key, arg1, arg2)).thenReturn(longCommandObject); + + Response response = pipeliningBase.lpush(key, arg1, arg2); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testLlenByteArray() { + byte[] key = "key".getBytes(); + + when(commandObjects.llen(key)).thenReturn(longCommandObject); + + Response response = pipeliningBase.llen(key); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testLrangeByteArray() { + byte[] key = "key".getBytes(); + long start = 0; + long stop = -1; + + when(commandObjects.lrange(key, start, stop)).thenReturn(listBytesCommandObject); + + Response> response = pipeliningBase.lrange(key, start, stop); + + assertThat(commands, contains(listBytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testLtrimByteArray() { + byte[] key = "key".getBytes(); + long start = 1; + long stop = -1; + + when(commandObjects.ltrim(key, start, stop)).thenReturn(stringCommandObject); + + Response response = pipeliningBase.ltrim(key, start, stop); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testLindexByteArray() { + byte[] key = "key".getBytes(); + long index = 0; + + when(commandObjects.lindex(key, index)).thenReturn(bytesCommandObject); + + Response response = pipeliningBase.lindex(key, index); + + assertThat(commands, contains(bytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testLsetByteArray() { + byte[] key = "key".getBytes(); + long index = 0; + byte[] value = "value".getBytes(); + + when(commandObjects.lset(key, index, value)).thenReturn(stringCommandObject); + + Response response = pipeliningBase.lset(key, index, value); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testLremByteArray() { + byte[] key = "key".getBytes(); + long count = 1; + byte[] value = "value".getBytes(); + + when(commandObjects.lrem(key, count, value)).thenReturn(longCommandObject); + + Response response = pipeliningBase.lrem(key, count, value); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testLpopByteArray() { + byte[] key = "key".getBytes(); + + when(commandObjects.lpop(key)).thenReturn(bytesCommandObject); + + Response response = pipeliningBase.lpop(key); + + assertThat(commands, contains(bytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testLpopWithCountByteArray() { + byte[] key = "key".getBytes(); + int count = 2; + + when(commandObjects.lpop(key, count)).thenReturn(listBytesCommandObject); + + Response> response = pipeliningBase.lpop(key, count); + + assertThat(commands, contains(listBytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testLposSingleByteArray() { + byte[] key = "key".getBytes(); + byte[] element = "element".getBytes(); + + when(commandObjects.lpos(key, element)).thenReturn(longCommandObject); + + Response response = pipeliningBase.lpos(key, element); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testLposWithParamsByteArray() { + byte[] key = "key".getBytes(); + byte[] element = "element".getBytes(); + LPosParams params = new LPosParams().rank(1); + + when(commandObjects.lpos(key, element, params)).thenReturn(longCommandObject); + + Response response = pipeliningBase.lpos(key, element, params); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testLposWithParamsAndCountByteArray() { + byte[] key = "key".getBytes(); + byte[] element = "element".getBytes(); + LPosParams params = new LPosParams().rank(1); + long count = 2; + + when(commandObjects.lpos(key, element, params, count)).thenReturn(listLongCommandObject); + + Response> response = pipeliningBase.lpos(key, element, params, count); + + assertThat(commands, contains(listLongCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testRpopByteArray() { + byte[] key = "key".getBytes(); + + when(commandObjects.rpop(key)).thenReturn(bytesCommandObject); + + Response response = pipeliningBase.rpop(key); + + assertThat(commands, contains(bytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testRpopWithCountByteArray() { + byte[] key = "key".getBytes(); + int count = 2; + + when(commandObjects.rpop(key, count)).thenReturn(listBytesCommandObject); + + Response> response = pipeliningBase.rpop(key, count); + + assertThat(commands, contains(listBytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testLinsertByteArray() { + byte[] key = "key".getBytes(); + ListPosition where = ListPosition.BEFORE; + byte[] pivot = "pivot".getBytes(); + byte[] value = "value".getBytes(); + + when(commandObjects.linsert(key, where, pivot, value)).thenReturn(longCommandObject); + + Response response = pipeliningBase.linsert(key, where, pivot, value); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testLpushxByteArray() { + byte[] key = "key".getBytes(); + byte[] arg = "value".getBytes(); + + when(commandObjects.lpushx(key, arg)).thenReturn(longCommandObject); + + Response response = pipeliningBase.lpushx(key, arg); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testRpushxByteArray() { + byte[] key = "key".getBytes(); + byte[] arg = "value".getBytes(); + + when(commandObjects.rpushx(key, arg)).thenReturn(longCommandObject); + + Response response = pipeliningBase.rpushx(key, arg); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testBlpopWithTimeoutByteArray() { + int timeout = 10; + byte[] key1 = "key1".getBytes(); + byte[] key2 = "key2".getBytes(); + + when(commandObjects.blpop(timeout, key1, key2)).thenReturn(listBytesCommandObject); + + Response> response = pipeliningBase.blpop(timeout, key1, key2); + + assertThat(commands, contains(listBytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testBlpopWithDoubleTimeoutByteArray() { + double timeout = 10.5; + byte[] key1 = "key1".getBytes(); + byte[] key2 = "key2".getBytes(); + + when(commandObjects.blpop(timeout, key1, key2)).thenReturn(keyValueBytesBytesCommandObject); + + Response> response = pipeliningBase.blpop(timeout, key1, key2); + + assertThat(commands, contains(keyValueBytesBytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testBrpopWithTimeoutByteArray() { + int timeout = 10; + byte[] key1 = "key1".getBytes(); + byte[] key2 = "key2".getBytes(); + + when(commandObjects.brpop(timeout, key1, key2)).thenReturn(listBytesCommandObject); + + Response> response = pipeliningBase.brpop(timeout, key1, key2); + + assertThat(commands, contains(listBytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testBrpopWithDoubleTimeoutByteArray() { + double timeout = 10.5; + byte[] key1 = "key1".getBytes(); + byte[] key2 = "key2".getBytes(); + + when(commandObjects.brpop(timeout, key1, key2)).thenReturn(keyValueBytesBytesCommandObject); + + Response> response = pipeliningBase.brpop(timeout, key1, key2); + + assertThat(commands, contains(keyValueBytesBytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testRpoplpushByteArray() { + byte[] srckey = "srckey".getBytes(); + byte[] dstkey = "dstkey".getBytes(); + + when(commandObjects.rpoplpush(srckey, dstkey)).thenReturn(bytesCommandObject); + + Response response = pipeliningBase.rpoplpush(srckey, dstkey); + + assertThat(commands, contains(bytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testBrpoplpushByteArray() { + byte[] source = "source".getBytes(); + byte[] destination = "destination".getBytes(); + int timeout = 10; + + when(commandObjects.brpoplpush(source, destination, timeout)).thenReturn(bytesCommandObject); + + Response response = pipeliningBase.brpoplpush(source, destination, timeout); + + assertThat(commands, contains(bytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testLmoveByteArray() { + byte[] srcKey = "srcKey".getBytes(); + byte[] dstKey = "dstKey".getBytes(); + ListDirection from = ListDirection.LEFT; + ListDirection to = ListDirection.RIGHT; + + when(commandObjects.lmove(srcKey, dstKey, from, to)).thenReturn(bytesCommandObject); + + Response response = pipeliningBase.lmove(srcKey, dstKey, from, to); + + assertThat(commands, contains(bytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testBlmoveByteArray() { + byte[] srcKey = "srcKey".getBytes(); + byte[] dstKey = "dstKey".getBytes(); + ListDirection from = ListDirection.LEFT; + ListDirection to = ListDirection.RIGHT; + double timeout = 10.5; + + when(commandObjects.blmove(srcKey, dstKey, from, to, timeout)).thenReturn(bytesCommandObject); + + Response response = pipeliningBase.blmove(srcKey, dstKey, from, to, timeout); + + assertThat(commands, contains(bytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testLmpopByteArray() { + ListDirection direction = ListDirection.LEFT; + byte[] key1 = "key1".getBytes(); + byte[] key2 = "key2".getBytes(); + + when(commandObjects.lmpop(direction, key1, key2)).thenReturn(keyValueBytesListBytesCommandObject); + + Response>> response = pipeliningBase.lmpop(direction, key1, key2); + + assertThat(commands, contains(keyValueBytesListBytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testLmpopWithCountByteArray() { + ListDirection direction = ListDirection.LEFT; + int count = 2; + byte[] key1 = "key1".getBytes(); + byte[] key2 = "key2".getBytes(); + + when(commandObjects.lmpop(direction, count, key1, key2)).thenReturn(keyValueBytesListBytesCommandObject); + + Response>> response = pipeliningBase.lmpop(direction, count, key1, key2); + + assertThat(commands, contains(keyValueBytesListBytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testBlmpopByteArray() { + double timeout = 10.5; + ListDirection direction = ListDirection.LEFT; + byte[] key1 = "key1".getBytes(); + byte[] key2 = "key2".getBytes(); + + when(commandObjects.blmpop(timeout, direction, key1, key2)).thenReturn(keyValueBytesListBytesCommandObject); + + Response>> response = pipeliningBase.blmpop(timeout, direction, key1, key2); + + assertThat(commands, contains(keyValueBytesListBytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testBlmpopWithCountByteArray() { + double timeout = 10.5; + ListDirection direction = ListDirection.LEFT; + int count = 2; + byte[] key1 = "key1".getBytes(); + byte[] key2 = "key2".getBytes(); + + when(commandObjects.blmpop(timeout, direction, count, key1, key2)).thenReturn(keyValueBytesListBytesCommandObject); + + Response>> response = pipeliningBase.blmpop(timeout, direction, count, key1, key2); + + assertThat(commands, contains(keyValueBytesListBytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testWaitReplicasByteArray() { + byte[] sampleKey = "sampleKey".getBytes(); + int replicas = 1; + long timeout = 1000; + + when(commandObjects.waitReplicas(sampleKey, replicas, timeout)).thenReturn(longCommandObject); + + Response response = pipeliningBase.waitReplicas(sampleKey, replicas, timeout); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testWaitAOFByteArray() { + byte[] sampleKey = "sampleKey".getBytes(); + long numLocal = 1; + long numReplicas = 1; + long timeout = 1000; + + when(commandObjects.waitAOF(sampleKey, numLocal, numReplicas, timeout)).thenReturn(keyValueLongLongCommandObject); + + Response> response = pipeliningBase.waitAOF(sampleKey, numLocal, numReplicas, timeout); + + assertThat(commands, contains(keyValueLongLongCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testEvalByteArray() { + byte[] script = "return 'Hello, world!'".getBytes(); + byte[] sampleKey = "sampleKey".getBytes(); + + when(commandObjects.eval(script, sampleKey)).thenReturn(objectCommandObject); + + Response response = pipeliningBase.eval(script, sampleKey); + + assertThat(commands, contains(objectCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testEvalshaByteArray() { + byte[] sha1 = "abcdef1234567890".getBytes(); + byte[] sampleKey = "sampleKey".getBytes(); + + when(commandObjects.evalsha(sha1, sampleKey)).thenReturn(objectCommandObject); + + Response response = pipeliningBase.evalsha(sha1, sampleKey); + + assertThat(commands, contains(objectCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testScriptExistsByteArray() { + byte[] sampleKey = "sampleKey".getBytes(); + byte[] sha1 = "abcdef1234567890".getBytes(); + + when(commandObjects.scriptExists(sampleKey, sha1)).thenReturn(listBooleanCommandObject); + + Response> response = pipeliningBase.scriptExists(sampleKey, sha1); + + assertThat(commands, contains(listBooleanCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testScriptLoadByteArray() { + byte[] script = "return 'Hello, world!'".getBytes(); + byte[] sampleKey = "sampleKey".getBytes(); + + when(commandObjects.scriptLoad(script, sampleKey)).thenReturn(bytesCommandObject); + + Response response = pipeliningBase.scriptLoad(script, sampleKey); + + assertThat(commands, contains(bytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testScriptFlushByteArray() { + byte[] sampleKey = "sampleKey".getBytes(); + + when(commandObjects.scriptFlush(sampleKey)).thenReturn(stringCommandObject); + + Response response = pipeliningBase.scriptFlush(sampleKey); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testScriptFlushWithFlushModeByteArray() { + byte[] sampleKey = "sampleKey".getBytes(); + FlushMode flushMode = FlushMode.SYNC; + + when(commandObjects.scriptFlush(sampleKey, flushMode)).thenReturn(stringCommandObject); + + Response response = pipeliningBase.scriptFlush(sampleKey, flushMode); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testScriptKillByteArray() { + byte[] sampleKey = "sampleKey".getBytes(); + + when(commandObjects.scriptKill(sampleKey)).thenReturn(stringCommandObject); + + Response response = pipeliningBase.scriptKill(sampleKey); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testEvalNoKeysByteArray() { + byte[] script = "return 'Hello, world!'".getBytes(); + + when(commandObjects.eval(script)).thenReturn(objectCommandObject); + + Response response = pipeliningBase.eval(script); + + assertThat(commands, contains(objectCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testEvalWithKeyCountAndParamsByteArray() { + byte[] script = "return KEYS[1]".getBytes(); + int keyCount = 1; + byte[] param1 = "key1".getBytes(); + + when(commandObjects.eval(script, keyCount, param1)).thenReturn(objectCommandObject); + + Response response = pipeliningBase.eval(script, keyCount, param1); + + assertThat(commands, contains(objectCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testEvalWithKeysAndArgsByteArray() { + byte[] script = "return {KEYS[1], ARGV[1]}".getBytes(); + List keys = Collections.singletonList("key1".getBytes()); + List args = Collections.singletonList("arg1".getBytes()); + + when(commandObjects.eval(script, keys, args)).thenReturn(objectCommandObject); + + Response response = pipeliningBase.eval(script, keys, args); + + assertThat(commands, contains(objectCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testEvalReadonlyWithKeysAndArgsByteArray() { + byte[] script = "return {KEYS[1], ARGV[1]}".getBytes(); + List keys = Collections.singletonList("key1".getBytes()); + List args = Collections.singletonList("arg1".getBytes()); + + when(commandObjects.evalReadonly(script, keys, args)).thenReturn(objectCommandObject); + + Response response = pipeliningBase.evalReadonly(script, keys, args); + + assertThat(commands, contains(objectCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testEvalshaNoKeysByteArray() { + byte[] sha1 = "abcdef1234567890".getBytes(); + + when(commandObjects.evalsha(sha1)).thenReturn(objectCommandObject); + + Response response = pipeliningBase.evalsha(sha1); + + assertThat(commands, contains(objectCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testEvalshaWithKeyCountAndParamsByteArray() { + byte[] sha1 = "abcdef1234567890".getBytes(); + int keyCount = 1; + byte[] param1 = "key1".getBytes(); + + when(commandObjects.evalsha(sha1, keyCount, param1)).thenReturn(objectCommandObject); + + Response response = pipeliningBase.evalsha(sha1, keyCount, param1); + + assertThat(commands, contains(objectCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testEvalshaWithKeysAndArgsByteArray() { + byte[] sha1 = "abcdef1234567890".getBytes(); + List keys = Collections.singletonList("key1".getBytes()); + List args = Collections.singletonList("arg1".getBytes()); + + when(commandObjects.evalsha(sha1, keys, args)).thenReturn(objectCommandObject); + + Response response = pipeliningBase.evalsha(sha1, keys, args); + + assertThat(commands, contains(objectCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testEvalshaReadonlyWithKeysAndArgsByteArray() { + byte[] sha1 = "abcdef1234567890".getBytes(); + List keys = Collections.singletonList("key1".getBytes()); + List args = Collections.singletonList("arg1".getBytes()); + + when(commandObjects.evalshaReadonly(sha1, keys, args)).thenReturn(objectCommandObject); + + Response response = pipeliningBase.evalshaReadonly(sha1, keys, args); + + assertThat(commands, contains(objectCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testSaddByteArray() { + byte[] key = "key".getBytes(); + byte[] member1 = "member1".getBytes(); + byte[] member2 = "member2".getBytes(); + + when(commandObjects.sadd(key, member1, member2)).thenReturn(longCommandObject); + + Response response = pipeliningBase.sadd(key, member1, member2); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testSmembersByteArray() { + byte[] key = "key".getBytes(); + + when(commandObjects.smembers(key)).thenReturn(setBytesCommandObject); + + Response> response = pipeliningBase.smembers(key); + + assertThat(commands, contains(setBytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testSremByteArray() { + byte[] key = "key".getBytes(); + byte[] member1 = "member1".getBytes(); + byte[] member2 = "member2".getBytes(); + + when(commandObjects.srem(key, member1, member2)).thenReturn(longCommandObject); + + Response response = pipeliningBase.srem(key, member1, member2); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testSpopSingleByteArray() { + byte[] key = "key".getBytes(); + + when(commandObjects.spop(key)).thenReturn(bytesCommandObject); + + Response response = pipeliningBase.spop(key); + + assertThat(commands, contains(bytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testSpopMultipleByteArray() { + byte[] key = "key".getBytes(); + long count = 2; + + when(commandObjects.spop(key, count)).thenReturn(setBytesCommandObject); + + Response> response = pipeliningBase.spop(key, count); + + assertThat(commands, contains(setBytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testScardByteArray() { + byte[] key = "key".getBytes(); + + when(commandObjects.scard(key)).thenReturn(longCommandObject); + + Response response = pipeliningBase.scard(key); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testSismemberByteArray() { + byte[] key = "key".getBytes(); + byte[] member = "member".getBytes(); + + when(commandObjects.sismember(key, member)).thenReturn(booleanCommandObject); + + Response response = pipeliningBase.sismember(key, member); + + assertThat(commands, contains(booleanCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testSmismemberByteArray() { + byte[] key = "key".getBytes(); + byte[] member1 = "member1".getBytes(); + byte[] member2 = "member2".getBytes(); + + when(commandObjects.smismember(key, member1, member2)).thenReturn(listBooleanCommandObject); + + Response> response = pipeliningBase.smismember(key, member1, member2); + + assertThat(commands, contains(listBooleanCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testSrandmemberSingleByteArray() { + byte[] key = "key".getBytes(); + + when(commandObjects.srandmember(key)).thenReturn(bytesCommandObject); + + Response response = pipeliningBase.srandmember(key); + + assertThat(commands, contains(bytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testSrandmemberMultipleByteArray() { + byte[] key = "key".getBytes(); + int count = 2; + + when(commandObjects.srandmember(key, count)).thenReturn(listBytesCommandObject); + + Response> response = pipeliningBase.srandmember(key, count); + + assertThat(commands, contains(listBytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testSscanByteArray() { + byte[] key = "key".getBytes(); + byte[] cursor = "0".getBytes(); + ScanParams params = new ScanParams().match("pattern*").count(10); + + when(commandObjects.sscan(key, cursor, params)).thenReturn(scanResultBytesCommandObject); + + Response> response = pipeliningBase.sscan(key, cursor, params); + + assertThat(commands, contains(scanResultBytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testSdiffByteArray() { + byte[][] keys = { "key1".getBytes(), "key2".getBytes(), "key3".getBytes() }; + + when(commandObjects.sdiff(keys)).thenReturn(setBytesCommandObject); + + Response> response = pipeliningBase.sdiff(keys); + + assertThat(commands, contains(setBytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testSdiffstoreByteArray() { + byte[] dstkey = "destination".getBytes(); + byte[][] keys = { "key1".getBytes(), "key2".getBytes() }; + + when(commandObjects.sdiffstore(dstkey, keys)).thenReturn(longCommandObject); + + Response response = pipeliningBase.sdiffstore(dstkey, keys); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testSinterByteArray() { + byte[][] keys = { "key1".getBytes(), "key2".getBytes() }; + + when(commandObjects.sinter(keys)).thenReturn(setBytesCommandObject); + + Response> response = pipeliningBase.sinter(keys); + + assertThat(commands, contains(setBytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testSinterstoreByteArray() { + byte[] dstkey = "destination".getBytes(); + byte[][] keys = { "key1".getBytes(), "key2".getBytes() }; + + when(commandObjects.sinterstore(dstkey, keys)).thenReturn(longCommandObject); + + Response response = pipeliningBase.sinterstore(dstkey, keys); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testSintercardByteArray() { + byte[][] keys = { "key1".getBytes(), "key2".getBytes() }; + + when(commandObjects.sintercard(keys)).thenReturn(longCommandObject); + + Response response = pipeliningBase.sintercard(keys); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testSintercardWithLimitByteArray() { + int limit = 2; + byte[][] keys = { "key1".getBytes(), "key2".getBytes() }; + + when(commandObjects.sintercard(limit, keys)).thenReturn(longCommandObject); + + Response response = pipeliningBase.sintercard(limit, keys); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testSunionByteArray() { + byte[][] keys = { "key1".getBytes(), "key2".getBytes() }; + + when(commandObjects.sunion(keys)).thenReturn(setBytesCommandObject); + + Response> response = pipeliningBase.sunion(keys); + + assertThat(commands, contains(setBytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testSunionstoreByteArray() { + byte[] dstkey = "destination".getBytes(); + byte[][] keys = { "key1".getBytes(), "key2".getBytes() }; + + when(commandObjects.sunionstore(dstkey, keys)).thenReturn(longCommandObject); + + Response response = pipeliningBase.sunionstore(dstkey, keys); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testSmoveByteArray() { + byte[] srckey = "source".getBytes(); + byte[] dstkey = "destination".getBytes(); + byte[] member = "member".getBytes(); + + when(commandObjects.smove(srckey, dstkey, member)).thenReturn(longCommandObject); + + Response response = pipeliningBase.smove(srckey, dstkey, member); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZaddByteArray() { + byte[] key = "zset".getBytes(); + double score = 1.0; + byte[] member = "member".getBytes(); + + when(commandObjects.zadd(key, score, member)).thenReturn(longCommandObject); + + Response response = pipeliningBase.zadd(key, score, member); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZaddWithParamsByteArray() { + byte[] key = "zset".getBytes(); + double score = 1.0; + byte[] member = "member".getBytes(); + ZAddParams params = ZAddParams.zAddParams().nx(); + + when(commandObjects.zadd(key, score, member, params)).thenReturn(longCommandObject); + + Response response = pipeliningBase.zadd(key, score, member, params); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZaddWithScoreMembersByteArray() { + byte[] key = "zset".getBytes(); + + Map scoreMembers = new HashMap<>(); + scoreMembers.put("member1".getBytes(), 1.0); + scoreMembers.put("member2".getBytes(), 2.0); + + when(commandObjects.zadd(key, scoreMembers)).thenReturn(longCommandObject); + + Response response = pipeliningBase.zadd(key, scoreMembers); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZaddWithScoreMembersAndParamsByteArray() { + byte[] key = "zset".getBytes(); + + Map scoreMembers = new HashMap<>(); + scoreMembers.put("member1".getBytes(), 1.0); + scoreMembers.put("member2".getBytes(), 2.0); + + ZAddParams params = ZAddParams.zAddParams().nx(); + + when(commandObjects.zadd(key, scoreMembers, params)).thenReturn(longCommandObject); + + Response response = pipeliningBase.zadd(key, scoreMembers, params); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZaddIncrByteArray() { + byte[] key = "zset".getBytes(); + double score = 1.0; + byte[] member = "member".getBytes(); + ZAddParams params = ZAddParams.zAddParams().xx(); + + when(commandObjects.zaddIncr(key, score, member, params)).thenReturn(doubleCommandObject); + + Response response = pipeliningBase.zaddIncr(key, score, member, params); + + assertThat(commands, contains(doubleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZremByteArray() { + byte[] key = "zset".getBytes(); + byte[][] members = { "member1".getBytes(), "member2".getBytes() }; + + when(commandObjects.zrem(key, members)).thenReturn(longCommandObject); + + Response response = pipeliningBase.zrem(key, members); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZincrbyByteArray() { + byte[] key = "zset".getBytes(); + double increment = 2.0; + byte[] member = "member".getBytes(); + + when(commandObjects.zincrby(key, increment, member)).thenReturn(doubleCommandObject); + + Response response = pipeliningBase.zincrby(key, increment, member); + + assertThat(commands, contains(doubleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZincrbyWithParamsByteArray() { + byte[] key = "zset".getBytes(); + double increment = 2.0; + byte[] member = "member".getBytes(); + ZIncrByParams params = ZIncrByParams.zIncrByParams().xx(); + + when(commandObjects.zincrby(key, increment, member, params)).thenReturn(doubleCommandObject); + + Response response = pipeliningBase.zincrby(key, increment, member, params); + + assertThat(commands, contains(doubleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZrankByteArray() { + byte[] key = "zset".getBytes(); + byte[] member = "member".getBytes(); + + when(commandObjects.zrank(key, member)).thenReturn(longCommandObject); + + Response response = pipeliningBase.zrank(key, member); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZrevrankByteArray() { + byte[] key = "zset".getBytes(); + byte[] member = "member".getBytes(); + + when(commandObjects.zrevrank(key, member)).thenReturn(longCommandObject); + + Response response = pipeliningBase.zrevrank(key, member); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZrankWithScoreByteArray() { + byte[] key = "zset".getBytes(); + byte[] member = "member".getBytes(); + + when(commandObjects.zrankWithScore(key, member)).thenReturn(keyValueLongDoubleCommandObject); + + Response> response = pipeliningBase.zrankWithScore(key, member); + + assertThat(commands, contains(keyValueLongDoubleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZrevrankWithScoreByteArray() { + byte[] key = "zset".getBytes(); + byte[] member = "member".getBytes(); + + when(commandObjects.zrevrankWithScore(key, member)).thenReturn(keyValueLongDoubleCommandObject); + + Response> response = pipeliningBase.zrevrankWithScore(key, member); + + assertThat(commands, contains(keyValueLongDoubleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZrangeByteArray() { + byte[] key = "zset".getBytes(); + long start = 0; + long stop = 1; + + when(commandObjects.zrange(key, start, stop)).thenReturn(listBytesCommandObject); + + Response> response = pipeliningBase.zrange(key, start, stop); + + assertThat(commands, contains(listBytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZrevrangeByteArray() { + byte[] key = "zset".getBytes(); + long start = 0; + long stop = 1; + + when(commandObjects.zrevrange(key, start, stop)).thenReturn(listBytesCommandObject); + + Response> response = pipeliningBase.zrevrange(key, start, stop); + + assertThat(commands, contains(listBytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZrangeWithScoresByteArray() { + byte[] key = "zset".getBytes(); + long start = 0; + long stop = 1; + + when(commandObjects.zrangeWithScores(key, start, stop)).thenReturn(listTupleCommandObject); + + Response> response = pipeliningBase.zrangeWithScores(key, start, stop); + + assertThat(commands, contains(listTupleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZrevrangeWithScoresByteArray() { + byte[] key = "zset".getBytes(); + long start = 0; + long stop = 1; + + when(commandObjects.zrevrangeWithScores(key, start, stop)).thenReturn(listTupleCommandObject); + + Response> response = pipeliningBase.zrevrangeWithScores(key, start, stop); + + assertThat(commands, contains(listTupleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZrandmemberByteArray() { + byte[] key = "zset".getBytes(); + + when(commandObjects.zrandmember(key)).thenReturn(bytesCommandObject); + + Response response = pipeliningBase.zrandmember(key); + + assertThat(commands, contains(bytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZrandmemberWithCountByteArray() { + byte[] key = "zset".getBytes(); + long count = 2; + + when(commandObjects.zrandmember(key, count)).thenReturn(listBytesCommandObject); + + Response> response = pipeliningBase.zrandmember(key, count); + + assertThat(commands, contains(listBytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZrandmemberWithScoresByteArray() { + byte[] key = "zset".getBytes(); + long count = 2; + + when(commandObjects.zrandmemberWithScores(key, count)).thenReturn(listTupleCommandObject); + + Response> response = pipeliningBase.zrandmemberWithScores(key, count); + + assertThat(commands, contains(listTupleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZcardByteArray() { + byte[] key = "zset".getBytes(); + + when(commandObjects.zcard(key)).thenReturn(longCommandObject); + + Response response = pipeliningBase.zcard(key); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZscoreByteArray() { + byte[] key = "zset".getBytes(); + byte[] member = "member".getBytes(); + + when(commandObjects.zscore(key, member)).thenReturn(doubleCommandObject); + + Response response = pipeliningBase.zscore(key, member); + + assertThat(commands, contains(doubleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZmscoreByteArray() { + byte[] key = "zset".getBytes(); + byte[][] members = { "member1".getBytes(), "member2".getBytes() }; + + when(commandObjects.zmscore(key, members)).thenReturn(listDoubleCommandObject); + + Response> response = pipeliningBase.zmscore(key, members); + + assertThat(commands, contains(listDoubleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZpopmaxByteArray() { + byte[] key = "zset".getBytes(); + + when(commandObjects.zpopmax(key)).thenReturn(tupleCommandObject); + + Response response = pipeliningBase.zpopmax(key); + + assertThat(commands, contains(tupleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZpopmaxWithCountByteArray() { + byte[] key = "zset".getBytes(); + int count = 2; + + when(commandObjects.zpopmax(key, count)).thenReturn(listTupleCommandObject); + + Response> response = pipeliningBase.zpopmax(key, count); + + assertThat(commands, contains(listTupleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZpopminByteArray() { + byte[] key = "zset".getBytes(); + + when(commandObjects.zpopmin(key)).thenReturn(tupleCommandObject); + + Response response = pipeliningBase.zpopmin(key); + + assertThat(commands, contains(tupleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZpopminWithCountByteArray() { + byte[] key = "zset".getBytes(); + int count = 2; + + when(commandObjects.zpopmin(key, count)).thenReturn(listTupleCommandObject); + + Response> response = pipeliningBase.zpopmin(key, count); + + assertThat(commands, contains(listTupleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZcountWithScoreRangeByteArray() { + byte[] key = "zset".getBytes(); + double min = 1.0; + double max = 2.0; + + when(commandObjects.zcount(key, min, max)).thenReturn(longCommandObject); + + Response response = pipeliningBase.zcount(key, min, max); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZcountWithLexRangeByteArray() { + byte[] key = "zset".getBytes(); + byte[] min = "min".getBytes(); + byte[] max = "max".getBytes(); + + when(commandObjects.zcount(key, min, max)).thenReturn(longCommandObject); + + Response response = pipeliningBase.zcount(key, min, max); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZrangeByScoreByteArray() { + byte[] key = "zset".getBytes(); + double min = 1.0; + double max = 2.0; + + when(commandObjects.zrangeByScore(key, min, max)).thenReturn(listBytesCommandObject); + + Response> response = pipeliningBase.zrangeByScore(key, min, max); + + assertThat(commands, contains(listBytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZrangeByScoreWithMinMaxBytesByteArray() { + byte[] key = "zset".getBytes(); + byte[] min = "1".getBytes(); + byte[] max = "2".getBytes(); + + when(commandObjects.zrangeByScore(key, min, max)).thenReturn(listBytesCommandObject); + + Response> response = pipeliningBase.zrangeByScore(key, min, max); + + assertThat(commands, contains(listBytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZrevrangeByScoreByteArray() { + byte[] key = "zset".getBytes(); + double max = 2.0; + double min = 1.0; + + when(commandObjects.zrevrangeByScore(key, max, min)).thenReturn(listBytesCommandObject); + + Response> response = pipeliningBase.zrevrangeByScore(key, max, min); + + assertThat(commands, contains(listBytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZrangeByScoreWithOffsetCountByteArray() { + byte[] key = "zset".getBytes(); + double min = 1.0; + double max = 2.0; + int offset = 0; + int count = 2; + + when(commandObjects.zrangeByScore(key, min, max, offset, count)).thenReturn(listBytesCommandObject); + + Response> response = pipeliningBase.zrangeByScore(key, min, max, offset, count); + + assertThat(commands, contains(listBytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZrevrangeByScoreWithMinMaxBytesByteArray() { + byte[] key = "zset".getBytes(); + byte[] max = "2".getBytes(); + byte[] min = "1".getBytes(); + + when(commandObjects.zrevrangeByScore(key, max, min)).thenReturn(listBytesCommandObject); + + Response> response = pipeliningBase.zrevrangeByScore(key, max, min); + + assertThat(commands, contains(listBytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZrangeByScoreWithMinMaxBytesOffsetCountByteArray() { + byte[] key = "zset".getBytes(); + byte[] min = "1".getBytes(); + byte[] max = "2".getBytes(); + int offset = 0; + int count = 2; + + when(commandObjects.zrangeByScore(key, min, max, offset, count)).thenReturn(listBytesCommandObject); + + Response> response = pipeliningBase.zrangeByScore(key, min, max, offset, count); + + assertThat(commands, contains(listBytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZrevrangeByScoreWithOffsetCountByteArray() { + byte[] key = "zset".getBytes(); + double max = 2.0; + double min = 1.0; + int offset = 0; + int count = 2; + + when(commandObjects.zrevrangeByScore(key, max, min, offset, count)).thenReturn(listBytesCommandObject); + + Response> response = pipeliningBase.zrevrangeByScore(key, max, min, offset, count); + + assertThat(commands, contains(listBytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZrangeByScoreWithScoresByteArray() { + byte[] key = "zset".getBytes(); + double min = 1.0; + double max = 2.0; + + when(commandObjects.zrangeByScoreWithScores(key, min, max)).thenReturn(listTupleCommandObject); + + Response> response = pipeliningBase.zrangeByScoreWithScores(key, min, max); + + assertThat(commands, contains(listTupleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZrevrangeByScoreWithScoresByteArray() { + byte[] key = "zset".getBytes(); + double max = 2.0; + double min = 1.0; + + when(commandObjects.zrevrangeByScoreWithScores(key, max, min)).thenReturn(listTupleCommandObject); + + Response> response = pipeliningBase.zrevrangeByScoreWithScores(key, max, min); + + assertThat(commands, contains(listTupleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZrangeByScoreWithScoresOffsetCountByteArray() { + byte[] key = "zset".getBytes(); + double min = 1.0; + double max = 2.0; + int offset = 0; + int count = 2; + + when(commandObjects.zrangeByScoreWithScores(key, min, max, offset, count)).thenReturn(listTupleCommandObject); + + Response> response = pipeliningBase.zrangeByScoreWithScores(key, min, max, offset, count); + + assertThat(commands, contains(listTupleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZrevrangeByScoreBytesOffsetCountByteArray() { + byte[] key = "zset".getBytes(); + byte[] max = "2".getBytes(); + byte[] min = "1".getBytes(); + int offset = 0; + int count = 2; + + when(commandObjects.zrevrangeByScore(key, max, min, offset, count)).thenReturn(listBytesCommandObject); + + Response> response = pipeliningBase.zrevrangeByScore(key, max, min, offset, count); + + assertThat(commands, contains(listBytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZrangeByScoreWithScoresBytesByteArray() { + byte[] key = "zset".getBytes(); + byte[] min = "1".getBytes(); + byte[] max = "2".getBytes(); + + when(commandObjects.zrangeByScoreWithScores(key, min, max)).thenReturn(listTupleCommandObject); + + Response> response = pipeliningBase.zrangeByScoreWithScores(key, min, max); + + assertThat(commands, contains(listTupleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZrevrangeByScoreWithScoresBytesByteArray() { + byte[] key = "zset".getBytes(); + byte[] max = "2".getBytes(); + byte[] min = "1".getBytes(); + + when(commandObjects.zrevrangeByScoreWithScores(key, max, min)).thenReturn(listTupleCommandObject); + + Response> response = pipeliningBase.zrevrangeByScoreWithScores(key, max, min); + + assertThat(commands, contains(listTupleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZrangeByScoreWithScoresBytesOffsetCountByteArray() { + byte[] key = "zset".getBytes(); + byte[] min = "1".getBytes(); + byte[] max = "2".getBytes(); + int offset = 0; + int count = 2; + + when(commandObjects.zrangeByScoreWithScores(key, min, max, offset, count)).thenReturn(listTupleCommandObject); + + Response> response = pipeliningBase.zrangeByScoreWithScores(key, min, max, offset, count); + + assertThat(commands, contains(listTupleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZrevrangeByScoreWithScoresOffsetCountByteArray() { + byte[] key = "zset".getBytes(); + double max = 2.0; + double min = 1.0; + int offset = 0; + int count = 2; + + when(commandObjects.zrevrangeByScoreWithScores(key, max, min, offset, count)).thenReturn(listTupleCommandObject); + + Response> response = pipeliningBase.zrevrangeByScoreWithScores(key, max, min, offset, count); + + assertThat(commands, contains(listTupleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZrevrangeByScoreWithScoresBytesOffsetCountByteArray() { + byte[] key = "zset".getBytes(); + byte[] max = "2".getBytes(); + byte[] min = "1".getBytes(); + int offset = 0; + int count = 2; + + when(commandObjects.zrevrangeByScoreWithScores(key, max, min, offset, count)).thenReturn(listTupleCommandObject); + + Response> response = pipeliningBase.zrevrangeByScoreWithScores(key, max, min, offset, count); + + assertThat(commands, contains(listTupleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZremrangeByRankByteArray() { + byte[] key = "zset".getBytes(); + long start = 0; + long stop = 1; + + when(commandObjects.zremrangeByRank(key, start, stop)).thenReturn(longCommandObject); + + Response response = pipeliningBase.zremrangeByRank(key, start, stop); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZremrangeByScoreByteArray() { + byte[] key = "zset".getBytes(); + double min = 1.0; + double max = 2.0; + + when(commandObjects.zremrangeByScore(key, min, max)).thenReturn(longCommandObject); + + Response response = pipeliningBase.zremrangeByScore(key, min, max); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZremrangeByScoreBytesByteArray() { + byte[] key = "zset".getBytes(); + byte[] min = "1".getBytes(); + byte[] max = "2".getBytes(); + + when(commandObjects.zremrangeByScore(key, min, max)).thenReturn(longCommandObject); + + Response response = pipeliningBase.zremrangeByScore(key, min, max); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZlexcountByteArray() { + byte[] key = "zset".getBytes(); + byte[] min = "[a".getBytes(); + byte[] max = "[z".getBytes(); + + when(commandObjects.zlexcount(key, min, max)).thenReturn(longCommandObject); + + Response response = pipeliningBase.zlexcount(key, min, max); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZrangeByLexByteArray() { + byte[] key = "zset".getBytes(); + byte[] min = "[a".getBytes(); + byte[] max = "[z".getBytes(); + + when(commandObjects.zrangeByLex(key, min, max)).thenReturn(listBytesCommandObject); + + Response> response = pipeliningBase.zrangeByLex(key, min, max); + + assertThat(commands, contains(listBytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZrangeByLexWithLimitByteArray() { + byte[] key = "zset".getBytes(); + byte[] min = "[a".getBytes(); + byte[] max = "[z".getBytes(); + int offset = 0; + int count = 10; + + when(commandObjects.zrangeByLex(key, min, max, offset, count)).thenReturn(listBytesCommandObject); + + Response> response = pipeliningBase.zrangeByLex(key, min, max, offset, count); + + assertThat(commands, contains(listBytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZrevrangeByLexByteArray() { + byte[] key = "zset".getBytes(); + byte[] max = "[z".getBytes(); + byte[] min = "[a".getBytes(); + + when(commandObjects.zrevrangeByLex(key, max, min)).thenReturn(listBytesCommandObject); + + Response> response = pipeliningBase.zrevrangeByLex(key, max, min); + + assertThat(commands, contains(listBytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZrevrangeByLexWithLimitByteArray() { + byte[] key = "zset".getBytes(); + byte[] max = "[z".getBytes(); + byte[] min = "[a".getBytes(); + int offset = 0; + int count = 10; + + when(commandObjects.zrevrangeByLex(key, max, min, offset, count)).thenReturn(listBytesCommandObject); + + Response> response = pipeliningBase.zrevrangeByLex(key, max, min, offset, count); + + assertThat(commands, contains(listBytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZrangeWithZRangeParamsByteArray() { + byte[] key = "zset".getBytes(); + ZRangeParams zRangeParams = ZRangeParams.zrangeParams(0, 1); + + when(commandObjects.zrange(key, zRangeParams)).thenReturn(listBytesCommandObject); + + Response> response = pipeliningBase.zrange(key, zRangeParams); + + assertThat(commands, contains(listBytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZrangeWithScoresWithZRangeParamsByteArray() { + byte[] key = "zset".getBytes(); + ZRangeParams zRangeParams = ZRangeParams.zrangeParams(0, 1); + + when(commandObjects.zrangeWithScores(key, zRangeParams)).thenReturn(listTupleCommandObject); + + Response> response = pipeliningBase.zrangeWithScores(key, zRangeParams); + + assertThat(commands, contains(listTupleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZrangestoreByteArray() { + byte[] dest = "destZset".getBytes(); + byte[] src = "srcZset".getBytes(); + ZRangeParams zRangeParams = ZRangeParams.zrangeParams(0, 1); + + when(commandObjects.zrangestore(dest, src, zRangeParams)).thenReturn(longCommandObject); + + Response response = pipeliningBase.zrangestore(dest, src, zRangeParams); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZremrangeByLexByteArray() { + byte[] key = "zset".getBytes(); + byte[] min = "[a".getBytes(); + byte[] max = "[z".getBytes(); + + when(commandObjects.zremrangeByLex(key, min, max)).thenReturn(longCommandObject); + + Response response = pipeliningBase.zremrangeByLex(key, min, max); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZscanByteArray() { + byte[] key = "zset".getBytes(); + byte[] cursor = "0".getBytes(); + ScanParams params = new ScanParams(); + + when(commandObjects.zscan(key, cursor, params)).thenReturn(scanResultTupleCommandObject); + + Response> response = pipeliningBase.zscan(key, cursor, params); + + assertThat(commands, contains(scanResultTupleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testBzpopmaxByteArray() { + double timeout = 1.0; + byte[][] keys = { "zset1".getBytes(), "zset2".getBytes() }; + + when(commandObjects.bzpopmax(timeout, keys)).thenReturn(keyValueBytesTupleCommandObject); + + Response> response = pipeliningBase.bzpopmax(timeout, keys); + + assertThat(commands, contains(keyValueBytesTupleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testBzpopminByteArray() { + double timeout = 1.0; + byte[][] keys = { "zset1".getBytes(), "zset2".getBytes() }; + + when(commandObjects.bzpopmin(timeout, keys)).thenReturn(keyValueBytesTupleCommandObject); + + Response> response = pipeliningBase.bzpopmin(timeout, keys); + + assertThat(commands, contains(keyValueBytesTupleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZmpopByteArray() { + SortedSetOption option = SortedSetOption.MAX; + byte[][] keys = { "zset1".getBytes(), "zset2".getBytes() }; + + when(commandObjects.zmpop(option, keys)).thenReturn(keyValueBytesListTupleCommandObject); + + Response>> response = pipeliningBase.zmpop(option, keys); + + assertThat(commands, contains(keyValueBytesListTupleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZmpopWithCountByteArray() { + SortedSetOption option = SortedSetOption.MAX; + int count = 2; + byte[][] keys = { "zset1".getBytes(), "zset2".getBytes() }; + + when(commandObjects.zmpop(option, count, keys)).thenReturn(keyValueBytesListTupleCommandObject); + + Response>> response = pipeliningBase.zmpop(option, count, keys); + + assertThat(commands, contains(keyValueBytesListTupleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testBzmpopByteArray() { + double timeout = 1.0; + SortedSetOption option = SortedSetOption.MAX; + byte[][] keys = { "zset1".getBytes(), "zset2".getBytes() }; + + when(commandObjects.bzmpop(timeout, option, keys)).thenReturn(keyValueBytesListTupleCommandObject); + + Response>> response = pipeliningBase.bzmpop(timeout, option, keys); + + assertThat(commands, contains(keyValueBytesListTupleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testBzmpopWithCountByteArray() { + double timeout = 1.0; + SortedSetOption option = SortedSetOption.MAX; + int count = 2; + byte[][] keys = { "zset1".getBytes(), "zset2".getBytes() }; + + when(commandObjects.bzmpop(timeout, option, count, keys)).thenReturn(keyValueBytesListTupleCommandObject); + + Response>> response = pipeliningBase.bzmpop(timeout, option, count, keys); + + assertThat(commands, contains(keyValueBytesListTupleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZdiffByteArray() { + byte[][] keys = { "zset1".getBytes(), "zset2".getBytes() }; + + when(commandObjects.zdiff(keys)).thenReturn(listBytesCommandObject); + + Response> response = pipeliningBase.zdiff(keys); + + assertThat(commands, contains(listBytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZdiffWithScoresByteArray() { + byte[][] keys = { "zset1".getBytes(), "zset2".getBytes() }; + + when(commandObjects.zdiffWithScores(keys)).thenReturn(listTupleCommandObject); + + Response> response = pipeliningBase.zdiffWithScores(keys); + + assertThat(commands, contains(listTupleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZdiffStoreByteArray() { + byte[] dstkey = "destZset".getBytes(); + byte[][] keys = { "zset1".getBytes(), "zset2".getBytes() }; + + when(commandObjects.zdiffStore(dstkey, keys)).thenReturn(longCommandObject); + + Response response = pipeliningBase.zdiffStore(dstkey, keys); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZdifftoreByteArray() { + byte[] dstkey = "destZset".getBytes(); + byte[][] keys = { "zset1".getBytes(), "zset2".getBytes() }; + + when(commandObjects.zdiffstore(dstkey, keys)).thenReturn(longCommandObject); + + Response response = pipeliningBase.zdiffstore(dstkey, keys); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZinterByteArray() { + ZParams params = new ZParams(); + byte[][] keys = { "zset1".getBytes(), "zset2".getBytes() }; + + when(commandObjects.zinter(params, keys)).thenReturn(listBytesCommandObject); + + Response> response = pipeliningBase.zinter(params, keys); + + assertThat(commands, contains(listBytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZinterWithScoresByteArray() { + ZParams params = new ZParams(); + byte[][] keys = { "zset1".getBytes(), "zset2".getBytes() }; + + when(commandObjects.zinterWithScores(params, keys)).thenReturn(listTupleCommandObject); + + Response> response = pipeliningBase.zinterWithScores(params, keys); + + assertThat(commands, contains(listTupleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZinterstoreByteArray() { + byte[] dstkey = "destZset".getBytes(); + byte[][] sets = { "zset1".getBytes(), "zset2".getBytes() }; + + when(commandObjects.zinterstore(dstkey, sets)).thenReturn(longCommandObject); + + Response response = pipeliningBase.zinterstore(dstkey, sets); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZinterstoreWithParamsByteArray() { + byte[] dstkey = "destZset".getBytes(); + ZParams params = new ZParams(); + byte[][] sets = { "zset1".getBytes(), "zset2".getBytes() }; + + when(commandObjects.zinterstore(dstkey, params, sets)).thenReturn(longCommandObject); + + Response response = pipeliningBase.zinterstore(dstkey, params, sets); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZintercardByteArray() { + byte[][] keys = { "zset1".getBytes(), "zset2".getBytes() }; + + when(commandObjects.zintercard(keys)).thenReturn(longCommandObject); + + Response response = pipeliningBase.zintercard(keys); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZintercardWithLimitByteArray() { + long limit = 2; + byte[][] keys = { "zset1".getBytes(), "zset2".getBytes() }; + + when(commandObjects.zintercard(limit, keys)).thenReturn(longCommandObject); + + Response response = pipeliningBase.zintercard(limit, keys); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZunionByteArray() { + ZParams params = new ZParams(); + byte[][] keys = { "zset1".getBytes(), "zset2".getBytes() }; + + when(commandObjects.zunion(params, keys)).thenReturn(listBytesCommandObject); + + Response> response = pipeliningBase.zunion(params, keys); + + assertThat(commands, contains(listBytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZunionWithScoresByteArray() { + ZParams params = new ZParams(); + byte[][] keys = { "zset1".getBytes(), "zset2".getBytes() }; + + when(commandObjects.zunionWithScores(params, keys)).thenReturn(listTupleCommandObject); + + Response> response = pipeliningBase.zunionWithScores(params, keys); + + assertThat(commands, contains(listTupleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZunionstoreByteArray() { + byte[] dstkey = "destZset".getBytes(); + byte[][] sets = { "zset1".getBytes(), "zset2".getBytes() }; + + when(commandObjects.zunionstore(dstkey, sets)).thenReturn(longCommandObject); + + Response response = pipeliningBase.zunionstore(dstkey, sets); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZunionstoreWithParamsByteArray() { + byte[] dstkey = "destZset".getBytes(); + ZParams params = new ZParams(); + byte[][] sets = { "zset1".getBytes(), "zset2".getBytes() }; + + when(commandObjects.zunionstore(dstkey, params, sets)).thenReturn(longCommandObject); + + Response response = pipeliningBase.zunionstore(dstkey, params, sets); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testXaddByteArray() { + byte[] key = "stream".getBytes(); + XAddParams params = new XAddParams(); + + Map hash = new HashMap<>(); + hash.put("field1".getBytes(), "value1".getBytes()); + + when(commandObjects.xadd(key, params, hash)).thenReturn(bytesCommandObject); + + Response response = pipeliningBase.xadd(key, params, hash); + + assertThat(commands, contains(bytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testXlenByteArray() { + byte[] key = "stream".getBytes(); + + when(commandObjects.xlen(key)).thenReturn(longCommandObject); + + Response response = pipeliningBase.xlen(key); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testXrangeByteArray() { + byte[] key = "stream".getBytes(); + byte[] start = "startId".getBytes(); + byte[] end = "endId".getBytes(); + + when(commandObjects.xrange(key, start, end)).thenReturn(listObjectCommandObject); + + Response> response = pipeliningBase.xrange(key, start, end); + + assertThat(commands, contains(listObjectCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testXrangeWithCountByteArray() { + byte[] key = "stream".getBytes(); + byte[] start = "startId".getBytes(); + byte[] end = "endId".getBytes(); + int count = 10; + + when(commandObjects.xrange(key, start, end, count)).thenReturn(listObjectCommandObject); + + Response> response = pipeliningBase.xrange(key, start, end, count); + + assertThat(commands, contains(listObjectCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testXrevrangeByteArray() { + byte[] key = "stream".getBytes(); + byte[] end = "endId".getBytes(); + byte[] start = "startId".getBytes(); + + when(commandObjects.xrevrange(key, end, start)).thenReturn(listObjectCommandObject); + + Response> response = pipeliningBase.xrevrange(key, end, start); + + assertThat(commands, contains(listObjectCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testXrevrangeWithCountByteArray() { + byte[] key = "stream".getBytes(); + byte[] end = "endId".getBytes(); + byte[] start = "startId".getBytes(); + int count = 10; + + when(commandObjects.xrevrange(key, end, start, count)).thenReturn(listObjectCommandObject); + + Response> response = pipeliningBase.xrevrange(key, end, start, count); + + assertThat(commands, contains(listObjectCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testXackByteArray() { + byte[] key = "stream".getBytes(); + byte[] group = "group".getBytes(); + byte[] id1 = "id1".getBytes(); + byte[] id2 = "id2".getBytes(); + + when(commandObjects.xack(key, group, id1, id2)).thenReturn(longCommandObject); + + Response response = pipeliningBase.xack(key, group, id1, id2); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testXgroupCreateByteArray() { + byte[] key = "stream".getBytes(); + byte[] groupName = "group".getBytes(); + byte[] id = "id".getBytes(); + boolean makeStream = true; + + when(commandObjects.xgroupCreate(key, groupName, id, makeStream)).thenReturn(stringCommandObject); + + Response response = pipeliningBase.xgroupCreate(key, groupName, id, makeStream); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testXgroupSetIDByteArray() { + byte[] key = "stream".getBytes(); + byte[] groupName = "group".getBytes(); + byte[] id = "id".getBytes(); + + when(commandObjects.xgroupSetID(key, groupName, id)).thenReturn(stringCommandObject); + + Response response = pipeliningBase.xgroupSetID(key, groupName, id); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testXgroupDestroyByteArray() { + byte[] key = "stream".getBytes(); + byte[] groupName = "group".getBytes(); + + when(commandObjects.xgroupDestroy(key, groupName)).thenReturn(longCommandObject); + + Response response = pipeliningBase.xgroupDestroy(key, groupName); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testXgroupCreateConsumerByteArray() { + byte[] key = "stream".getBytes(); + byte[] groupName = "group".getBytes(); + byte[] consumerName = "consumer".getBytes(); + + when(commandObjects.xgroupCreateConsumer(key, groupName, consumerName)).thenReturn(booleanCommandObject); + + Response response = pipeliningBase.xgroupCreateConsumer(key, groupName, consumerName); + + assertThat(commands, contains(booleanCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testXgroupDelConsumerByteArray() { + byte[] key = "stream".getBytes(); + byte[] groupName = "group".getBytes(); + byte[] consumerName = "consumer".getBytes(); + + when(commandObjects.xgroupDelConsumer(key, groupName, consumerName)).thenReturn(longCommandObject); + + Response response = pipeliningBase.xgroupDelConsumer(key, groupName, consumerName); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testXdelByteArray() { + byte[] key = "stream".getBytes(); + byte[] id1 = "id1".getBytes(); + byte[] id2 = "id2".getBytes(); + + when(commandObjects.xdel(key, id1, id2)).thenReturn(longCommandObject); + + Response response = pipeliningBase.xdel(key, id1, id2); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testXtrimByteArray() { + byte[] key = "stream".getBytes(); + long maxLen = 1000L; + boolean approximateLength = true; + + when(commandObjects.xtrim(key, maxLen, approximateLength)).thenReturn(longCommandObject); + + Response response = pipeliningBase.xtrim(key, maxLen, approximateLength); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testXtrimWithParamsByteArray() { + byte[] key = "stream".getBytes(); + XTrimParams params = new XTrimParams().maxLen(1000L); + + when(commandObjects.xtrim(key, params)).thenReturn(longCommandObject); + + Response response = pipeliningBase.xtrim(key, params); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testXpendingByteArray() { + byte[] key = "stream".getBytes(); + byte[] groupName = "group".getBytes(); + + when(commandObjects.xpending(key, groupName)).thenReturn(objectCommandObject); + + Response response = pipeliningBase.xpending(key, groupName); + + assertThat(commands, contains(objectCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testXpendingWithParamsByteArray() { + byte[] key = "stream".getBytes(); + byte[] groupName = "group".getBytes(); + XPendingParams params = new XPendingParams().count(10); + + when(commandObjects.xpending(key, groupName, params)).thenReturn(listObjectCommandObject); + + Response> response = pipeliningBase.xpending(key, groupName, params); + + assertThat(commands, contains(listObjectCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testXclaimByteArray() { + byte[] key = "stream".getBytes(); + byte[] group = "group".getBytes(); + byte[] consumerName = "consumer".getBytes(); + long minIdleTime = 10000L; + XClaimParams params = new XClaimParams(); + byte[] id1 = "id1".getBytes(); + byte[] id2 = "id2".getBytes(); + + when(commandObjects.xclaim(key, group, consumerName, minIdleTime, params, id1, id2)).thenReturn(listBytesCommandObject); + + Response> response = pipeliningBase.xclaim(key, group, consumerName, minIdleTime, params, id1, id2); + + assertThat(commands, contains(listBytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testXclaimJustIdByteArray() { + byte[] key = "stream".getBytes(); + byte[] group = "group".getBytes(); + byte[] consumerName = "consumer".getBytes(); + long minIdleTime = 10000L; + XClaimParams params = new XClaimParams(); + byte[] id1 = "id1".getBytes(); + byte[] id2 = "id2".getBytes(); + + when(commandObjects.xclaimJustId(key, group, consumerName, minIdleTime, params, id1, id2)).thenReturn(listBytesCommandObject); + + Response> response = pipeliningBase.xclaimJustId(key, group, consumerName, minIdleTime, params, id1, id2); + + assertThat(commands, contains(listBytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testXautoclaimByteArray() { + byte[] key = "stream".getBytes(); + byte[] groupName = "group".getBytes(); + byte[] consumerName = "consumer".getBytes(); + long minIdleTime = 10000L; + byte[] start = "startId".getBytes(); + XAutoClaimParams params = new XAutoClaimParams(); + + when(commandObjects.xautoclaim(key, groupName, consumerName, minIdleTime, start, params)).thenReturn(listObjectCommandObject); + + Response> response = pipeliningBase.xautoclaim(key, groupName, consumerName, minIdleTime, start, params); + + assertThat(commands, contains(listObjectCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testXautoclaimJustIdByteArray() { + byte[] key = "stream".getBytes(); + byte[] groupName = "group".getBytes(); + byte[] consumerName = "consumer".getBytes(); + long minIdleTime = 10000L; + byte[] start = "startId".getBytes(); + XAutoClaimParams params = new XAutoClaimParams(); + + when(commandObjects.xautoclaimJustId(key, groupName, consumerName, minIdleTime, start, params)).thenReturn(listObjectCommandObject); + + Response> response = pipeliningBase.xautoclaimJustId(key, groupName, consumerName, minIdleTime, start, params); + + assertThat(commands, contains(listObjectCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testXinfoStreamByteArray() { + byte[] key = "stream".getBytes(); + + when(commandObjects.xinfoStream(key)).thenReturn(objectCommandObject); + + Response response = pipeliningBase.xinfoStream(key); + + assertThat(commands, contains(objectCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testXinfoStreamFullByteArray() { + byte[] key = "stream".getBytes(); + + when(commandObjects.xinfoStreamFull(key)).thenReturn(objectCommandObject); + + Response response = pipeliningBase.xinfoStreamFull(key); + + assertThat(commands, contains(objectCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testXinfoStreamFullWithCountByteArray() { + byte[] key = "stream".getBytes(); + int count = 10; + + when(commandObjects.xinfoStreamFull(key, count)).thenReturn(objectCommandObject); + + Response response = pipeliningBase.xinfoStreamFull(key, count); + + assertThat(commands, contains(objectCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testXinfoGroupsByteArray() { + byte[] key = "stream".getBytes(); + + when(commandObjects.xinfoGroups(key)).thenReturn(listObjectCommandObject); + + Response> response = pipeliningBase.xinfoGroups(key); + + assertThat(commands, contains(listObjectCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testXinfoConsumersByteArray() { + byte[] key = "stream".getBytes(); + byte[] group = "group".getBytes(); + + when(commandObjects.xinfoConsumers(key, group)).thenReturn(listObjectCommandObject); + + Response> response = pipeliningBase.xinfoConsumers(key, group); + + assertThat(commands, contains(listObjectCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testXreadByteArray() { + XReadParams xReadParams = new XReadParams(); + Map.Entry stream1 = new AbstractMap.SimpleImmutableEntry<>("stream1".getBytes(), "id1".getBytes()); + + when(commandObjects.xread(xReadParams, stream1)).thenReturn(listObjectCommandObject); + + Response> response = pipeliningBase.xread(xReadParams, stream1); + + assertThat(commands, contains(listObjectCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testXreadGroupByteArray() { + byte[] groupName = "group".getBytes(); + byte[] consumer = "consumer".getBytes(); + XReadGroupParams xReadGroupParams = new XReadGroupParams(); + Map.Entry stream1 = new AbstractMap.SimpleImmutableEntry<>("stream1".getBytes(), "id1".getBytes()); + + when(commandObjects.xreadGroup(groupName, consumer, xReadGroupParams, stream1)).thenReturn(listObjectCommandObject); + + Response> response = pipeliningBase.xreadGroup(groupName, consumer, xReadGroupParams, stream1); + + assertThat(commands, contains(listObjectCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testSetByteArray() { + byte[] key = "key".getBytes(); + byte[] value = "value".getBytes(); + + when(commandObjects.set(key, value)).thenReturn(stringCommandObject); + + Response response = pipeliningBase.set(key, value); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testSetWithParamsByteArray() { + byte[] key = "key".getBytes(); + byte[] value = "value".getBytes(); + SetParams params = new SetParams().nx().ex(10); + + when(commandObjects.set(key, value, params)).thenReturn(stringCommandObject); + + Response response = pipeliningBase.set(key, value, params); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testGetByteArray() { + byte[] key = "key".getBytes(); + + when(commandObjects.get(key)).thenReturn(bytesCommandObject); + + Response response = pipeliningBase.get(key); + + assertThat(commands, contains(bytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testSetGetByteArray() { + byte[] key = "key".getBytes(); + byte[] value = "value".getBytes(); + + when(commandObjects.setGet(key, value)).thenReturn(bytesCommandObject); + + Response response = pipeliningBase.setGet(key, value); + + assertThat(commands, contains(bytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testSetGetWithParamsByteArray() { + byte[] key = "key".getBytes(); + byte[] value = "value".getBytes(); + SetParams params = new SetParams().nx().ex(10); + + when(commandObjects.setGet(key, value, params)).thenReturn(bytesCommandObject); + + Response response = pipeliningBase.setGet(key, value, params); + + assertThat(commands, contains(bytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testGetDelByteArray() { + byte[] key = "key".getBytes(); + + when(commandObjects.getDel(key)).thenReturn(bytesCommandObject); + + Response response = pipeliningBase.getDel(key); + + assertThat(commands, contains(bytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testGetExByteArray() { + byte[] key = "key".getBytes(); + GetExParams params = new GetExParams().ex(10); + + when(commandObjects.getEx(key, params)).thenReturn(bytesCommandObject); + + Response response = pipeliningBase.getEx(key, params); + + assertThat(commands, contains(bytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testSetbitByteArray() { + byte[] key = "key".getBytes(); + long offset = 10L; + boolean value = true; + + when(commandObjects.setbit(key, offset, value)).thenReturn(booleanCommandObject); + + Response response = pipeliningBase.setbit(key, offset, value); + + assertThat(commands, contains(booleanCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testGetbitByteArray() { + byte[] key = "key".getBytes(); + long offset = 10L; + + when(commandObjects.getbit(key, offset)).thenReturn(booleanCommandObject); + + Response response = pipeliningBase.getbit(key, offset); + + assertThat(commands, contains(booleanCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testSetrangeByteArray() { + byte[] key = "key".getBytes(); + long offset = 10L; + byte[] value = "value".getBytes(); + + when(commandObjects.setrange(key, offset, value)).thenReturn(longCommandObject); + + Response response = pipeliningBase.setrange(key, offset, value); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testGetrangeByteArray() { + byte[] key = "key".getBytes(); + long startOffset = 0L; + long endOffset = 10L; + + when(commandObjects.getrange(key, startOffset, endOffset)).thenReturn(bytesCommandObject); + + Response response = pipeliningBase.getrange(key, startOffset, endOffset); + + assertThat(commands, contains(bytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testGetSetByteArray() { + byte[] key = "key".getBytes(); + byte[] value = "value".getBytes(); + + when(commandObjects.getSet(key, value)).thenReturn(bytesCommandObject); + + Response response = pipeliningBase.getSet(key, value); + + assertThat(commands, contains(bytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testSetnxByteArray() { + byte[] key = "key".getBytes(); + byte[] value = "value".getBytes(); + + when(commandObjects.setnx(key, value)).thenReturn(longCommandObject); + + Response response = pipeliningBase.setnx(key, value); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testSetexByteArray() { + byte[] key = "key".getBytes(); + long seconds = 60L; + byte[] value = "value".getBytes(); + + when(commandObjects.setex(key, seconds, value)).thenReturn(stringCommandObject); + + Response response = pipeliningBase.setex(key, seconds, value); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testPsetexByteArray() { + byte[] key = "key".getBytes(); + long milliseconds = 5000L; + byte[] value = "value".getBytes(); + + when(commandObjects.psetex(key, milliseconds, value)).thenReturn(stringCommandObject); + + Response response = pipeliningBase.psetex(key, milliseconds, value); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testMgetByteArray() { + byte[] key1 = "key1".getBytes(); + byte[] key2 = "key2".getBytes(); + + when(commandObjects.mget(key1, key2)).thenReturn(listBytesCommandObject); + + Response> response = pipeliningBase.mget(key1, key2); + + assertThat(commands, contains(listBytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testMsetByteArray() { + byte[] key1 = "key1".getBytes(); + byte[] value1 = "value1".getBytes(); + byte[] key2 = "key2".getBytes(); + byte[] value2 = "value2".getBytes(); + + when(commandObjects.mset(key1, value1, key2, value2)).thenReturn(stringCommandObject); + + Response response = pipeliningBase.mset(key1, value1, key2, value2); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testMsetnxByteArray() { + byte[] key1 = "key1".getBytes(); + byte[] value1 = "value1".getBytes(); + byte[] key2 = "key2".getBytes(); + byte[] value2 = "value2".getBytes(); + + when(commandObjects.msetnx(key1, value1, key2, value2)).thenReturn(longCommandObject); + + Response response = pipeliningBase.msetnx(key1, value1, key2, value2); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testIncrByteArray() { + byte[] key = "key".getBytes(); + + when(commandObjects.incr(key)).thenReturn(longCommandObject); + + Response response = pipeliningBase.incr(key); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testIncrByByteArray() { + byte[] key = "key".getBytes(); + long increment = 2L; + + when(commandObjects.incrBy(key, increment)).thenReturn(longCommandObject); + + Response response = pipeliningBase.incrBy(key, increment); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testIncrByFloatByteArray() { + byte[] key = "key".getBytes(); + double increment = 2.5; + + when(commandObjects.incrByFloat(key, increment)).thenReturn(doubleCommandObject); + + Response response = pipeliningBase.incrByFloat(key, increment); + + assertThat(commands, contains(doubleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testDecrByteArray() { + byte[] key = "key".getBytes(); + + when(commandObjects.decr(key)).thenReturn(longCommandObject); + + Response response = pipeliningBase.decr(key); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testDecrByByteArray() { + byte[] key = "key".getBytes(); + long decrement = 2L; + + when(commandObjects.decrBy(key, decrement)).thenReturn(longCommandObject); + + Response response = pipeliningBase.decrBy(key, decrement); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testAppendByteArray() { + byte[] key = "key".getBytes(); + byte[] value = "value".getBytes(); + + when(commandObjects.append(key, value)).thenReturn(longCommandObject); + + Response response = pipeliningBase.append(key, value); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testSubstrByteArray() { + byte[] key = "key".getBytes(); + int start = 0; + int end = 5; + + when(commandObjects.substr(key, start, end)).thenReturn(bytesCommandObject); + + Response response = pipeliningBase.substr(key, start, end); + + assertThat(commands, contains(bytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testStrlenByteArray() { + byte[] key = "key".getBytes(); + + when(commandObjects.strlen(key)).thenReturn(longCommandObject); + + Response response = pipeliningBase.strlen(key); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testBitcountByteArray() { + byte[] key = "key".getBytes(); + + when(commandObjects.bitcount(key)).thenReturn(longCommandObject); + + Response response = pipeliningBase.bitcount(key); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testBitcountWithRangeByteArray() { + byte[] key = "key".getBytes(); + long start = 0L; + long end = 10L; + + when(commandObjects.bitcount(key, start, end)).thenReturn(longCommandObject); + + Response response = pipeliningBase.bitcount(key, start, end); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testBitcountWithRangeAndOptionByteArray() { + byte[] key = "key".getBytes(); + long start = 0L; + long end = 10L; + BitCountOption option = BitCountOption.BYTE; + + when(commandObjects.bitcount(key, start, end, option)).thenReturn(longCommandObject); + + Response response = pipeliningBase.bitcount(key, start, end, option); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testBitposByteArray() { + byte[] key = "key".getBytes(); + boolean value = true; + + when(commandObjects.bitpos(key, value)).thenReturn(longCommandObject); + + Response response = pipeliningBase.bitpos(key, value); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testBitposWithParamsByteArray() { + byte[] key = "key".getBytes(); + boolean value = true; + BitPosParams params = new BitPosParams(0); + + when(commandObjects.bitpos(key, value, params)).thenReturn(longCommandObject); + + Response response = pipeliningBase.bitpos(key, value, params); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testBitfieldByteArray() { + byte[] key = "key".getBytes(); + byte[] arguments = "INCRBY i5 100 1".getBytes(); + + when(commandObjects.bitfield(key, arguments)).thenReturn(listLongCommandObject); + + Response> response = pipeliningBase.bitfield(key, arguments); + + assertThat(commands, contains(listLongCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testBitfieldReadonlyByteArray() { + byte[] key = "key".getBytes(); + byte[] arguments = "GET i5 100".getBytes(); + + when(commandObjects.bitfieldReadonly(key, arguments)).thenReturn(listLongCommandObject); + + Response> response = pipeliningBase.bitfieldReadonly(key, arguments); + + assertThat(commands, contains(listLongCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testBitopByteArray() { + BitOP op = BitOP.AND; + byte[] destKey = "destKey".getBytes(); + byte[] srcKey1 = "srcKey1".getBytes(); + byte[] srcKey2 = "srcKey2".getBytes(); + + when(commandObjects.bitop(op, destKey, srcKey1, srcKey2)).thenReturn(longCommandObject); + + Response response = pipeliningBase.bitop(op, destKey, srcKey1, srcKey2); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testFtCreateByteArray() { + IndexOptions indexOptions = IndexOptions.defaultOptions(); + Schema schema = new Schema().addField(new Schema.Field("myField", Schema.FieldType.TEXT)); + + when(commandObjects.ftCreate("myIndex", indexOptions, schema)).thenReturn(stringCommandObject); + + Response response = pipeliningBase.ftCreate("myIndex", indexOptions, schema); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testFtCreateWithParamsByteArray() { + FTCreateParams createParams = FTCreateParams.createParams(); + Iterable schemaFields = Collections.singletonList(new TextField("myField")); + + when(commandObjects.ftCreate("myIndex", createParams, schemaFields)).thenReturn(stringCommandObject); + + Response response = pipeliningBase.ftCreate("myIndex", createParams, schemaFields); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testFtAlterByteArray() { + Schema schema = new Schema().addField(new Schema.Field("newField", Schema.FieldType.TEXT)); + + when(commandObjects.ftAlter("myIndex", schema)).thenReturn(stringCommandObject); + + Response response = pipeliningBase.ftAlter("myIndex", schema); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testFtAlterWithFieldsByteArray() { + Iterable schemaFields = Collections.singletonList(new TextField("newField")); + + when(commandObjects.ftAlter("myIndex", schemaFields)).thenReturn(stringCommandObject); + + Response response = pipeliningBase.ftAlter("myIndex", schemaFields); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testFtAliasAddByteArray() { + when(commandObjects.ftAliasAdd("myAlias", "myIndex")).thenReturn(stringCommandObject); + + Response response = pipeliningBase.ftAliasAdd("myAlias", "myIndex"); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testFtAliasUpdateByteArray() { + when(commandObjects.ftAliasUpdate("myAlias", "myIndex")).thenReturn(stringCommandObject); + + Response response = pipeliningBase.ftAliasUpdate("myAlias", "myIndex"); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testFtAliasDelByteArray() { + when(commandObjects.ftAliasDel("myAlias")).thenReturn(stringCommandObject); + + Response response = pipeliningBase.ftAliasDel("myAlias"); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testFtDropIndexByteArray() { + when(commandObjects.ftDropIndex("myIndex")).thenReturn(stringCommandObject); + + Response response = pipeliningBase.ftDropIndex("myIndex"); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testFtDropIndexDDByteArray() { + when(commandObjects.ftDropIndexDD("myIndex")).thenReturn(stringCommandObject); + + Response response = pipeliningBase.ftDropIndexDD("myIndex"); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testFtSearchByteArray() { + String query = "hello world"; + + when(commandObjects.ftSearch("myIndex", query)).thenReturn(searchResultCommandObject); + + Response response = pipeliningBase.ftSearch("myIndex", query); + + assertThat(commands, contains(searchResultCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testFtSearchWithParamsByteArray() { + String query = "hello world"; + FTSearchParams searchParams = FTSearchParams.searchParams().limit(0, 10); + + when(commandObjects.ftSearch("myIndex", query, searchParams)).thenReturn(searchResultCommandObject); + + Response response = pipeliningBase.ftSearch("myIndex", query, searchParams); + + assertThat(commands, contains(searchResultCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testFtSearchWithQueryByteArray() { + Query query = new Query("hello world").limit(0, 10); + + when(commandObjects.ftSearch("myIndex", query)).thenReturn(searchResultCommandObject); + + Response response = pipeliningBase.ftSearch("myIndex", query); + + assertThat(commands, contains(searchResultCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testFtSearchWithQueryBytesByteArray() { + byte[] indexName = "myIndex".getBytes(); + Query query = new Query("hello world").limit(0, 10); + + when(commandObjects.ftSearch(indexName, query)).thenReturn(searchResultCommandObject); + + Response response = pipeliningBase.ftSearch(indexName, query); + + assertThat(commands, contains(searchResultCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testFtExplainByteArray() { + Query query = new Query("hello world"); + + when(commandObjects.ftExplain("myIndex", query)).thenReturn(stringCommandObject); + + Response response = pipeliningBase.ftExplain("myIndex", query); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testFtExplainCLIByteArray() { + Query query = new Query("hello world"); + + when(commandObjects.ftExplainCLI("myIndex", query)).thenReturn(listStringCommandObject); + + Response> response = pipeliningBase.ftExplainCLI("myIndex", query); + + assertThat(commands, contains(listStringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testFtAggregateByteArray() { + AggregationBuilder aggr = new AggregationBuilder().groupBy("@field"); + + when(commandObjects.ftAggregate("myIndex", aggr)).thenReturn(aggregationResultCommandObject); + + Response response = pipeliningBase.ftAggregate("myIndex", aggr); + + assertThat(commands, contains(aggregationResultCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testFtSynUpdateByteArray() { + String synonymGroupId = "group1"; + String[] terms = { "term1", "term2" }; + + when(commandObjects.ftSynUpdate("myIndex", synonymGroupId, terms)).thenReturn(stringCommandObject); + + Response response = pipeliningBase.ftSynUpdate("myIndex", synonymGroupId, terms); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testFtSynDump() { + when(commandObjects.ftSynDump("myIndex")).thenReturn(mapStringListStringCommandObject); + + Response>> response = pipeliningBase.ftSynDump("myIndex"); + + assertThat(commands, contains(mapStringListStringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testFtDictAdd() { + String[] terms = { "term1", "term2" }; + + when(commandObjects.ftDictAdd("myDict", terms)).thenReturn(longCommandObject); + + Response response = pipeliningBase.ftDictAdd("myDict", terms); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testFtDictDel() { + String[] terms = { "term1", "term2" }; + + when(commandObjects.ftDictDel("myDict", terms)).thenReturn(longCommandObject); + + Response response = pipeliningBase.ftDictDel("myDict", terms); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testFtDictDump() { + when(commandObjects.ftDictDump("myDict")).thenReturn(setStringCommandObject); + + Response> response = pipeliningBase.ftDictDump("myDict"); + + assertThat(commands, contains(setStringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testFtDictAddBySampleKey() { + String[] terms = { "term1", "term2" }; + + when(commandObjects.ftDictAddBySampleKey("myIndex", "myDict", terms)).thenReturn(longCommandObject); + + Response response = pipeliningBase.ftDictAddBySampleKey("myIndex", "myDict", terms); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testFtDictDelBySampleKey() { + String[] terms = { "term1", "term2" }; + + when(commandObjects.ftDictDelBySampleKey("myIndex", "myDict", terms)).thenReturn(longCommandObject); + + Response response = pipeliningBase.ftDictDelBySampleKey("myIndex", "myDict", terms); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testFtDictDumpBySampleKey() { + when(commandObjects.ftDictDumpBySampleKey("myIndex", "myDict")).thenReturn(setStringCommandObject); + + Response> response = pipeliningBase.ftDictDumpBySampleKey("myIndex", "myDict"); + + assertThat(commands, contains(setStringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testFtSpellCheck() { + String query = "hello world"; + + when(commandObjects.ftSpellCheck("myIndex", query)).thenReturn(mapStringMapStringDoubleCommandObject); + + Response>> response = pipeliningBase.ftSpellCheck("myIndex", query); + + assertThat(commands, contains(mapStringMapStringDoubleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testFtSpellCheckWithParams() { + String query = "hello world"; + FTSpellCheckParams spellCheckParams = new FTSpellCheckParams().distance(1); + + when(commandObjects.ftSpellCheck("myIndex", query, spellCheckParams)).thenReturn(mapStringMapStringDoubleCommandObject); + + Response>> response = pipeliningBase.ftSpellCheck("myIndex", query, spellCheckParams); + + assertThat(commands, contains(mapStringMapStringDoubleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testFtInfo() { + when(commandObjects.ftInfo("myIndex")).thenReturn(mapStringObjectCommandObject); + + Response> response = pipeliningBase.ftInfo("myIndex"); + + assertThat(commands, contains(mapStringObjectCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testFtTagVals() { + when(commandObjects.ftTagVals("myIndex", "myField")).thenReturn(setStringCommandObject); + + Response> response = pipeliningBase.ftTagVals("myIndex", "myField"); + + assertThat(commands, contains(setStringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testFtConfigGet() { + when(commandObjects.ftConfigGet("TIMEOUT")).thenReturn(mapStringObjectCommandObject); + + Response> response = pipeliningBase.ftConfigGet("TIMEOUT"); + + assertThat(commands, contains(mapStringObjectCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testFtConfigGetWithIndexName() { + when(commandObjects.ftConfigGet("myIndex", "TIMEOUT")).thenReturn(mapStringObjectCommandObject); + + Response> response = pipeliningBase.ftConfigGet("myIndex", "TIMEOUT"); + + assertThat(commands, contains(mapStringObjectCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testFtConfigSet() { + when(commandObjects.ftConfigSet("TIMEOUT", "100")).thenReturn(stringCommandObject); + + Response response = pipeliningBase.ftConfigSet("TIMEOUT", "100"); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testFtConfigSetWithIndexName() { + when(commandObjects.ftConfigSet("myIndex", "TIMEOUT", "100")).thenReturn(stringCommandObject); + + Response response = pipeliningBase.ftConfigSet("myIndex", "TIMEOUT", "100"); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testFtSugAdd() { + when(commandObjects.ftSugAdd("mySug", "hello", 1.0)).thenReturn(longCommandObject); + + Response response = pipeliningBase.ftSugAdd("mySug", "hello", 1.0); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testFtSugAddIncr() { + when(commandObjects.ftSugAddIncr("mySug", "hello", 1.0)).thenReturn(longCommandObject); + + Response response = pipeliningBase.ftSugAddIncr("mySug", "hello", 1.0); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testFtSugGet() { + when(commandObjects.ftSugGet("mySug", "he")).thenReturn(listStringCommandObject); + + Response> response = pipeliningBase.ftSugGet("mySug", "he"); + + assertThat(commands, contains(listStringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testFtSugGetWithFuzzyAndMax() { + when(commandObjects.ftSugGet("mySug", "he", true, 10)).thenReturn(listStringCommandObject); + + Response> response = pipeliningBase.ftSugGet("mySug", "he", true, 10); + + assertThat(commands, contains(listStringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testFtSugGetWithScores() { + when(commandObjects.ftSugGetWithScores("mySug", "he")).thenReturn(listTupleCommandObject); + + Response> response = pipeliningBase.ftSugGetWithScores("mySug", "he"); + + assertThat(commands, contains(listTupleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testFtSugGetWithScoresFuzzyMax() { + when(commandObjects.ftSugGetWithScores("mySug", "he", true, 10)).thenReturn(listTupleCommandObject); + + Response> response = pipeliningBase.ftSugGetWithScores("mySug", "he", true, 10); + + assertThat(commands, contains(listTupleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testFtSugDel() { + when(commandObjects.ftSugDel("mySug", "hello")).thenReturn(booleanCommandObject); + + Response response = pipeliningBase.ftSugDel("mySug", "hello"); + + assertThat(commands, contains(booleanCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testFtSugLen() { + when(commandObjects.ftSugLen("mySug")).thenReturn(longCommandObject); + + Response response = pipeliningBase.ftSugLen("mySug"); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testLcsByteArray() { + byte[] keyA = "keyA".getBytes(); + byte[] keyB = "keyB".getBytes(); + LCSParams params = new LCSParams().withMatchLen(); + + when(commandObjects.lcs(keyA, keyB, params)).thenReturn(lcsMatchResultCommandObject); + + Response response = pipeliningBase.lcs(keyA, keyB, params); + + assertThat(commands, contains(lcsMatchResultCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testJsonSet() { + Path2 path = Path2.of("$.field"); + Object object = new JsonObject(); + + when(commandObjects.jsonSet("myJson", path, object)).thenReturn(stringCommandObject); + + Response response = pipeliningBase.jsonSet("myJson", path, object); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testJsonSetWithEscape() { + Path2 path = Path2.of("$.field"); + Object object = new JsonObject(); + + when(commandObjects.jsonSetWithEscape("myJson", path, object)).thenReturn(stringCommandObject); + + Response response = pipeliningBase.jsonSetWithEscape("myJson", path, object); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testJsonSetOldPath() { + Path path = Path.of("$.field"); + Object object = new JsonObject(); + + when(commandObjects.jsonSet("myJson", path, object)).thenReturn(stringCommandObject); + + Response response = pipeliningBase.jsonSet("myJson", path, object); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testJsonSetWithParams() { + Path2 path = Path2.of("$.field"); + Object object = new JsonObject(); + JsonSetParams params = new JsonSetParams().nx(); + + when(commandObjects.jsonSet("myJson", path, object, params)).thenReturn(stringCommandObject); + + Response response = pipeliningBase.jsonSet("myJson", path, object, params); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testJsonSetWithEscapeAndParams() { + Path2 path = Path2.of("$.field"); + Object object = new JsonObject(); + JsonSetParams params = new JsonSetParams().nx(); + + when(commandObjects.jsonSetWithEscape("myJson", path, object, params)).thenReturn(stringCommandObject); + + Response response = pipeliningBase.jsonSetWithEscape("myJson", path, object, params); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testJsonSetWithPathAndParams() { + Path path = new Path("$.field"); + Object object = new JsonObject(); + JsonSetParams params = new JsonSetParams().nx(); + + when(commandObjects.jsonSet("myJson", path, object, params)).thenReturn(stringCommandObject); + + Response response = pipeliningBase.jsonSet("myJson", path, object, params); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testJsonMergeWithPath2() { + Path2 path = Path2.of("$.field"); + Object object = new JsonObject(); + + when(commandObjects.jsonMerge("myJson", path, object)).thenReturn(stringCommandObject); + + Response response = pipeliningBase.jsonMerge("myJson", path, object); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testJsonMergeWithPath() { + Path path = new Path("$.field"); + Object object = new JsonObject(); + + when(commandObjects.jsonMerge("myJson", path, object)).thenReturn(stringCommandObject); + + Response response = pipeliningBase.jsonMerge("myJson", path, object); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testJsonGet() { + when(commandObjects.jsonGet("myJson")).thenReturn(objectCommandObject); + + Response response = pipeliningBase.jsonGet("myJson"); + + assertThat(commands, contains(objectCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testJsonGetWithClass() { + when(commandObjects.jsonGet("myJson", MyBean.class)).thenReturn(myBeanCommandObject); + + Response response = pipeliningBase.jsonGet("myJson", MyBean.class); + + assertThat(commands, contains(myBeanCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testJsonGetWithPaths2() { + Path2[] paths = { Path2.of("$.field1"), Path2.of("$.field2") }; + + when(commandObjects.jsonGet("myJson", paths)).thenReturn(objectCommandObject); + + Response response = pipeliningBase.jsonGet("myJson", paths); + + assertThat(commands, contains(objectCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testJsonGetWithPaths() { + Path[] paths = { new Path("$.field1"), new Path("$.field2") }; + + when(commandObjects.jsonGet("myJson", paths)).thenReturn(objectCommandObject); + + Response response = pipeliningBase.jsonGet("myJson", paths); + + assertThat(commands, contains(objectCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testJsonGetWithClassAndPaths() { + Path[] paths = { new Path("$.field1"), new Path("$.field2") }; + + when(commandObjects.jsonGet("myJson", MyBean.class, paths)).thenReturn(myBeanCommandObject); + + Response response = pipeliningBase.jsonGet("myJson", MyBean.class, paths); + + assertThat(commands, contains(myBeanCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testJsonMGetWithPath2() { + Path2 path = Path2.of("$.field"); + + when(commandObjects.jsonMGet(path, "key1", "key2")).thenReturn(listJsonArrayCommandObject); + + Response> response = pipeliningBase.jsonMGet(path, "key1", "key2"); + + assertThat(commands, contains(listJsonArrayCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testJsonMGetWithPathAndClass() { + Path path = new Path("$.field"); + + when(commandObjects.jsonMGet(path, MyBean.class, "key1", "key2")).thenReturn(listMyBeanCommandObject); + + Response> response = pipeliningBase.jsonMGet(path, MyBean.class, "key1", "key2"); + + assertThat(commands, contains(listMyBeanCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testJsonDelWithKey() { + when(commandObjects.jsonDel("myJson")).thenReturn(longCommandObject); + + Response response = pipeliningBase.jsonDel("myJson"); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testJsonDelWithKeyAndPath2() { + Path2 path = Path2.of("$.field"); + + when(commandObjects.jsonDel("myJson", path)).thenReturn(longCommandObject); + + Response response = pipeliningBase.jsonDel("myJson", path); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testJsonDelWithKeyAndPath() { + Path path = new Path("$.field"); + + when(commandObjects.jsonDel("myJson", path)).thenReturn(longCommandObject); + + Response response = pipeliningBase.jsonDel("myJson", path); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testJsonClearWithKey() { + when(commandObjects.jsonClear("myJson")).thenReturn(longCommandObject); + + Response response = pipeliningBase.jsonClear("myJson"); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testJsonClearWithKeyAndPath2() { + Path2 path = Path2.of("$.field"); + + when(commandObjects.jsonClear("myJson", path)).thenReturn(longCommandObject); + + Response response = pipeliningBase.jsonClear("myJson", path); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testJsonClearWithKeyAndPath() { + Path path = new Path("$.field"); + + when(commandObjects.jsonClear("myJson", path)).thenReturn(longCommandObject); + + Response response = pipeliningBase.jsonClear("myJson", path); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testJsonToggleWithPath2() { + Path2 path = Path2.of("$.field"); + + when(commandObjects.jsonToggle("myJson", path)).thenReturn(listBooleanCommandObject); + + Response> response = pipeliningBase.jsonToggle("myJson", path); + + assertThat(commands, contains(listBooleanCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testJsonToggleWithPath() { + Path path = new Path("$.field"); + + when(commandObjects.jsonToggle("myJson", path)).thenReturn(stringCommandObject); + + Response response = pipeliningBase.jsonToggle("myJson", path); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testJsonTypeWithKey() { + when(commandObjects.jsonType("myJson")).thenReturn(classCommandObject); + + Response> response = pipeliningBase.jsonType("myJson"); + + assertThat(commands, contains(classCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testJsonTypeWithKeyAndPath2() { + Path2 path = Path2.of("$.field"); + + when(commandObjects.jsonType("myJson", path)).thenReturn(listClassCommandObject); + + Response>> response = pipeliningBase.jsonType("myJson", path); + + assertThat(commands, contains(listClassCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testJsonTypeWithKeyAndPath() { + Path path = new Path("$.field"); + + when(commandObjects.jsonType("myJson", path)).thenReturn(classCommandObject); + + Response> response = pipeliningBase.jsonType("myJson", path); + + assertThat(commands, contains(classCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testJsonStrAppendWithKey() { + when(commandObjects.jsonStrAppend("myJson", "append")).thenReturn(longCommandObject); + + Response response = pipeliningBase.jsonStrAppend("myJson", "append"); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testJsonStrAppendWithKeyAndPath2() { + Path2 path = Path2.of("$.field"); + + when(commandObjects.jsonStrAppend("myJson", path, "append")).thenReturn(listLongCommandObject); + + Response> response = pipeliningBase.jsonStrAppend("myJson", path, "append"); + + assertThat(commands, contains(listLongCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testJsonStrAppendWithKeyAndPath() { + Path path = new Path("$.field"); + + when(commandObjects.jsonStrAppend("myJson", path, "append")).thenReturn(longCommandObject); + + Response response = pipeliningBase.jsonStrAppend("myJson", path, "append"); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testJsonStrLenWithKey() { + when(commandObjects.jsonStrLen("myJson")).thenReturn(longCommandObject); + + Response response = pipeliningBase.jsonStrLen("myJson"); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testJsonStrLenWithKeyAndPath2() { + Path2 path = Path2.of("$.field"); + + when(commandObjects.jsonStrLen("myJson", path)).thenReturn(listLongCommandObject); + + Response> response = pipeliningBase.jsonStrLen("myJson", path); + + assertThat(commands, contains(listLongCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testJsonStrLenWithKeyAndPath() { + Path path = new Path("$.field"); + + when(commandObjects.jsonStrLen("myJson", path)).thenReturn(longCommandObject); + + Response response = pipeliningBase.jsonStrLen("myJson", path); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testJsonNumIncrByWithPath2() { + Path2 path = Path2.of("$.number"); + + when(commandObjects.jsonNumIncrBy("myJson", path, 42.0)).thenReturn(objectCommandObject); + + Response response = pipeliningBase.jsonNumIncrBy("myJson", path, 42.0); + + assertThat(commands, contains(objectCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testJsonNumIncrByWithPath() { + Path path = new Path("$.number"); + + when(commandObjects.jsonNumIncrBy("myJson", path, 42.0)).thenReturn(doubleCommandObject); + + Response response = pipeliningBase.jsonNumIncrBy("myJson", path, 42.0); + + assertThat(commands, contains(doubleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testJsonArrAppendWithPath2() { + Path2 path = Path2.of("$.array"); + Object[] objects = { "one", "two", "three" }; + + when(commandObjects.jsonArrAppend("myJson", path, objects)).thenReturn(listLongCommandObject); + + Response> response = pipeliningBase.jsonArrAppend("myJson", path, objects); + + assertThat(commands, contains(listLongCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testJsonArrAppendWithPath2WithEscape() { + Path2 path = Path2.of("$.array"); + Object[] objects = { "one", "two", "three" }; + + when(commandObjects.jsonArrAppendWithEscape("myJson", path, objects)).thenReturn(listLongCommandObject); + + Response> response = pipeliningBase.jsonArrAppendWithEscape("myJson", path, objects); + + assertThat(commands, contains(listLongCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testJsonArrAppendWithPath() { + Path path = new Path("$.array"); + Object[] objects = { "one", "two", "three" }; + + when(commandObjects.jsonArrAppend("myJson", path, objects)).thenReturn(longCommandObject); + + Response response = pipeliningBase.jsonArrAppend("myJson", path, objects); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testJsonArrIndexWithPath2() { + Path2 path = Path2.of("$.array"); + Object scalar = "two"; + + when(commandObjects.jsonArrIndex("myJson", path, scalar)).thenReturn(listLongCommandObject); + + Response> response = pipeliningBase.jsonArrIndex("myJson", path, scalar); + + assertThat(commands, contains(listLongCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testJsonArrIndexWithPath2WithEscape() { + Path2 path = Path2.of("$.array"); + Object scalar = "two"; + + when(commandObjects.jsonArrIndexWithEscape("myJson", path, scalar)).thenReturn(listLongCommandObject); + + Response> response = pipeliningBase.jsonArrIndexWithEscape("myJson", path, scalar); + + assertThat(commands, contains(listLongCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testJsonArrIndexWithPath() { + Path path = new Path("$.array"); + Object scalar = "two"; + + when(commandObjects.jsonArrIndex("myJson", path, scalar)).thenReturn(longCommandObject); + + Response response = pipeliningBase.jsonArrIndex("myJson", path, scalar); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testJsonArrInsertWithPath2() { + Path2 path = Path2.of("$.array"); + Object[] objects = { "one", "two", "three" }; + + when(commandObjects.jsonArrInsert("myJson", path, 1, objects)).thenReturn(listLongCommandObject); + + Response> response = pipeliningBase.jsonArrInsert("myJson", path, 1, objects); + + assertThat(commands, contains(listLongCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testJsonArrInsertWithPath2WithEscape() { + Path2 path = Path2.of("$.array"); + Object[] objects = { "one", "two", "three" }; + + when(commandObjects.jsonArrInsertWithEscape("myJson", path, 1, objects)).thenReturn(listLongCommandObject); + + Response> response = pipeliningBase.jsonArrInsertWithEscape("myJson", path, 1, objects); + + assertThat(commands, contains(listLongCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testJsonArrInsertWithPath() { + Path path = new Path("$.array"); + Object[] pojos = { "one", "two", "three" }; + + when(commandObjects.jsonArrInsert("myJson", path, 1, pojos)).thenReturn(longCommandObject); + + Response response = pipeliningBase.jsonArrInsert("myJson", path, 1, pojos); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testJsonArrPopWithKey() { + when(commandObjects.jsonArrPop("myJson")).thenReturn(objectCommandObject); + + Response response = pipeliningBase.jsonArrPop("myJson"); + + assertThat(commands, contains(objectCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testJsonArrLenWithKeyAndPath() { + Path path = new Path("$.array"); + + when(commandObjects.jsonArrLen("myJson", path)).thenReturn(longCommandObject); + + Response response = pipeliningBase.jsonArrLen("myJson", path); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testJsonArrTrimWithPath2() { + Path2 path = Path2.of("$.array"); + + when(commandObjects.jsonArrTrim("myJson", path, 1, 2)).thenReturn(listLongCommandObject); + + Response> response = pipeliningBase.jsonArrTrim("myJson", path, 1, 2); + + assertThat(commands, contains(listLongCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testJsonArrTrimWithPath() { + Path path = new Path("$.array"); + + when(commandObjects.jsonArrTrim("myJson", path, 1, 2)).thenReturn(longCommandObject); + + Response response = pipeliningBase.jsonArrTrim("myJson", path, 1, 2); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testJsonArrPopWithKeyClassAndPath() { + Path path = new Path("$.array"); + + when(commandObjects.jsonArrPop("myJson", MyBean.class, path)).thenReturn(myBeanCommandObject); + + Response response = pipeliningBase.jsonArrPop("myJson", MyBean.class, path); + + assertThat(commands, contains(myBeanCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testJsonArrPopWithKeyPath2AndIndex() { + Path2 path = Path2.of("$.array"); + + when(commandObjects.jsonArrPop("myJson", path, 1)).thenReturn(listObjectCommandObject); + + Response> response = pipeliningBase.jsonArrPop("myJson", path, 1); + + assertThat(commands, contains(listObjectCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testJsonArrPopWithKeyPathAndIndex() { + Path path = new Path("$.array"); + + when(commandObjects.jsonArrPop("myJson", path, 1)).thenReturn(objectCommandObject); + + Response response = pipeliningBase.jsonArrPop("myJson", path, 1); + + assertThat(commands, contains(objectCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testJsonArrPopWithKeyClassPathAndIndex() { + Path path = new Path("$.array"); + + when(commandObjects.jsonArrPop("myJson", MyBean.class, path, 1)).thenReturn(myBeanCommandObject); + + Response response = pipeliningBase.jsonArrPop("myJson", MyBean.class, path, 1); + + assertThat(commands, contains(myBeanCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testJsonArrLenWithKey() { + when(commandObjects.jsonArrLen("myJson")).thenReturn(longCommandObject); + + Response response = pipeliningBase.jsonArrLen("myJson"); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testJsonArrLenWithKeyAndPath2() { + Path2 path = Path2.of("$.array"); + + when(commandObjects.jsonArrLen("myJson", path)).thenReturn(listLongCommandObject); + + Response> response = pipeliningBase.jsonArrLen("myJson", path); + + assertThat(commands, contains(listLongCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testJsonArrPopWithKeyAndClass() { + when(commandObjects.jsonArrPop("myJson", MyBean.class)).thenReturn(myBeanCommandObject); + + Response response = pipeliningBase.jsonArrPop("myJson", MyBean.class); + + assertThat(commands, contains(myBeanCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testJsonArrPopWithKeyAndPath2() { + Path2 path = Path2.of("$.array"); + + when(commandObjects.jsonArrPop("myJson", path)).thenReturn(listObjectCommandObject); + + Response> response = pipeliningBase.jsonArrPop("myJson", path); + + assertThat(commands, contains(listObjectCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testJsonArrPopWithKeyAndPath() { + Path path = new Path("$.array"); + + when(commandObjects.jsonArrPop("myJson", path)).thenReturn(objectCommandObject); + + Response response = pipeliningBase.jsonArrPop("myJson", path); + + assertThat(commands, contains(objectCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testTsCreate() { + when(commandObjects.tsCreate("myTimeSeries")).thenReturn(stringCommandObject); + + Response response = pipeliningBase.tsCreate("myTimeSeries"); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testTsCreateWithParams() { + TSCreateParams createParams = TSCreateParams.createParams(); + + when(commandObjects.tsCreate("myTimeSeries", createParams)).thenReturn(stringCommandObject); + + Response response = pipeliningBase.tsCreate("myTimeSeries", createParams); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testTsDel() { + when(commandObjects.tsDel("myTimeSeries", 1000L, 2000L)).thenReturn(longCommandObject); + + Response response = pipeliningBase.tsDel("myTimeSeries", 1000L, 2000L); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testTsAlter() { + TSAlterParams alterParams = TSAlterParams.alterParams(); + + when(commandObjects.tsAlter("myTimeSeries", alterParams)).thenReturn(stringCommandObject); + + Response response = pipeliningBase.tsAlter("myTimeSeries", alterParams); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testTsAdd() { + when(commandObjects.tsAdd("myTimeSeries", 42.0)).thenReturn(longCommandObject); + + Response response = pipeliningBase.tsAdd("myTimeSeries", 42.0); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testTsAddWithTimestamp() { + when(commandObjects.tsAdd("myTimeSeries", 1000L, 42.0)).thenReturn(longCommandObject); + + Response response = pipeliningBase.tsAdd("myTimeSeries", 1000L, 42.0); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testTsAddWithTimestampAndParams() { + TSCreateParams createParams = TSCreateParams.createParams(); + + when(commandObjects.tsAdd("myTimeSeries", 1000L, 42.0, createParams)).thenReturn(longCommandObject); + + Response response = pipeliningBase.tsAdd("myTimeSeries", 1000L, 42.0, createParams); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testTsMAdd() { + Map.Entry entry1 = new AbstractMap.SimpleEntry<>("ts1", new TSElement(1000L, 1.0)); + Map.Entry entry2 = new AbstractMap.SimpleEntry<>("ts2", new TSElement(2000L, 2.0)); + + when(commandObjects.tsMAdd(entry1, entry2)).thenReturn(listLongCommandObject); + + Response> response = pipeliningBase.tsMAdd(entry1, entry2); + + assertThat(commands, contains(listLongCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testTsIncrBy() { + when(commandObjects.tsIncrBy("myTimeSeries", 1.0)).thenReturn(longCommandObject); + + Response response = pipeliningBase.tsIncrBy("myTimeSeries", 1.0); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testTsIncrByWithTimestamp() { + when(commandObjects.tsIncrBy("myTimeSeries", 1.0, 1000L)).thenReturn(longCommandObject); + + Response response = pipeliningBase.tsIncrBy("myTimeSeries", 1.0, 1000L); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testTsDecrBy() { + when(commandObjects.tsDecrBy("myTimeSeries", 1.0)).thenReturn(longCommandObject); + + Response response = pipeliningBase.tsDecrBy("myTimeSeries", 1.0); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testTsDecrByWithTimestamp() { + when(commandObjects.tsDecrBy("myTimeSeries", 1.0, 1000L)).thenReturn(longCommandObject); + + Response response = pipeliningBase.tsDecrBy("myTimeSeries", 1.0, 1000L); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testTsRange() { + when(commandObjects.tsRange("myTimeSeries", 1000L, 2000L)).thenReturn(listTsElementCommandObject); + + Response> response = pipeliningBase.tsRange("myTimeSeries", 1000L, 2000L); + + assertThat(commands, contains(listTsElementCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testTsRangeWithParams() { + TSRangeParams rangeParams = TSRangeParams.rangeParams(); + + when(commandObjects.tsRange("myTimeSeries", rangeParams)).thenReturn(listTsElementCommandObject); + + Response> response = pipeliningBase.tsRange("myTimeSeries", rangeParams); + + assertThat(commands, contains(listTsElementCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testTsRevRange() { + when(commandObjects.tsRevRange("myTimeSeries", 1000L, 2000L)).thenReturn(listTsElementCommandObject); + + Response> response = pipeliningBase.tsRevRange("myTimeSeries", 1000L, 2000L); + + assertThat(commands, contains(listTsElementCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testTsRevRangeWithParams() { + TSRangeParams rangeParams = TSRangeParams.rangeParams(); + + when(commandObjects.tsRevRange("myTimeSeries", rangeParams)).thenReturn(listTsElementCommandObject); + + Response> response = pipeliningBase.tsRevRange("myTimeSeries", rangeParams); + + assertThat(commands, contains(listTsElementCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testTsMRange() { + String[] filters = { "sensor_id=123" }; + + when(commandObjects.tsMRange(1000L, 2000L, filters)).thenReturn(mapStringTsmRangeElementsCommandObject); + + Response> response = pipeliningBase.tsMRange(1000L, 2000L, filters); + + assertThat(commands, contains(mapStringTsmRangeElementsCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testTsMRangeWithParams() { + TSMRangeParams multiRangeParams = TSMRangeParams.multiRangeParams(); + + when(commandObjects.tsMRange(multiRangeParams)).thenReturn(mapStringTsmRangeElementsCommandObject); + + Response> response = pipeliningBase.tsMRange(multiRangeParams); + + assertThat(commands, contains(mapStringTsmRangeElementsCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testTsMRevRange() { + String[] filters = { "sensor_id=123" }; + + when(commandObjects.tsMRevRange(1000L, 2000L, filters)).thenReturn(mapStringTsmRangeElementsCommandObject); + + Response> response = pipeliningBase.tsMRevRange(1000L, 2000L, filters); + + assertThat(commands, contains(mapStringTsmRangeElementsCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testTsMRevRangeWithParams() { + TSMRangeParams multiRangeParams = TSMRangeParams.multiRangeParams(); + + when(commandObjects.tsMRevRange(multiRangeParams)).thenReturn(mapStringTsmRangeElementsCommandObject); + + Response> response = pipeliningBase.tsMRevRange(multiRangeParams); + + assertThat(commands, contains(mapStringTsmRangeElementsCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testTsGet() { + when(commandObjects.tsGet("myTimeSeries")).thenReturn(tsElementCommandObject); + + Response response = pipeliningBase.tsGet("myTimeSeries"); + + assertThat(commands, contains(tsElementCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testTsGetWithParams() { + TSGetParams getParams = TSGetParams.getParams(); + + when(commandObjects.tsGet("myTimeSeries", getParams)).thenReturn(tsElementCommandObject); + + Response response = pipeliningBase.tsGet("myTimeSeries", getParams); + + assertThat(commands, contains(tsElementCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testTsMGet() { + TSMGetParams multiGetParams = TSMGetParams.multiGetParams(); + String[] filters = { "sensor_id=123" }; + + when(commandObjects.tsMGet(multiGetParams, filters)).thenReturn(mapStringTsmGetElementCommandObject); + + Response> response = pipeliningBase.tsMGet(multiGetParams, filters); + + assertThat(commands, contains(mapStringTsmGetElementCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testTsCreateRule() { + AggregationType aggregationType = AggregationType.AVG; + long timeBucket = 60; + + when(commandObjects.tsCreateRule("sourceTimeSeries", "destTimeSeries", aggregationType, timeBucket)).thenReturn(stringCommandObject); + + Response response = pipeliningBase.tsCreateRule("sourceTimeSeries", "destTimeSeries", aggregationType, timeBucket); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testTsCreateRuleWithAlignTimestamp() { + AggregationType aggregationType = AggregationType.AVG; + long bucketDuration = 60; + long alignTimestamp = 0; + + when(commandObjects.tsCreateRule("sourceTimeSeries", "destTimeSeries", aggregationType, bucketDuration, alignTimestamp)).thenReturn(stringCommandObject); + + Response response = pipeliningBase.tsCreateRule("sourceTimeSeries", "destTimeSeries", aggregationType, bucketDuration, alignTimestamp); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testTsDeleteRule() { + when(commandObjects.tsDeleteRule("sourceTimeSeries", "destTimeSeries")).thenReturn(stringCommandObject); + + Response response = pipeliningBase.tsDeleteRule("sourceTimeSeries", "destTimeSeries"); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testTsQueryIndex() { + String[] filters = { "sensor_id=123" }; + + when(commandObjects.tsQueryIndex(filters)).thenReturn(listStringCommandObject); + + Response> response = pipeliningBase.tsQueryIndex(filters); + + assertThat(commands, contains(listStringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testBfReserve() { + double errorRate = 0.01; + long capacity = 10000L; + + when(commandObjects.bfReserve("myBloomFilter", errorRate, capacity)).thenReturn(stringCommandObject); + + Response response = pipeliningBase.bfReserve("myBloomFilter", errorRate, capacity); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testBfReserveWithParams() { + double errorRate = 0.01; + long capacity = 10000L; + + BFReserveParams reserveParams = new BFReserveParams().expansion(2); + when(commandObjects.bfReserve("myBloomFilter", errorRate, capacity, reserveParams)).thenReturn(stringCommandObject); + + Response response = pipeliningBase.bfReserve("myBloomFilter", errorRate, capacity, reserveParams); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testBfAdd() { + when(commandObjects.bfAdd("myBloomFilter", "item1")).thenReturn(booleanCommandObject); + + Response response = pipeliningBase.bfAdd("myBloomFilter", "item1"); + + assertThat(commands, contains(booleanCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testBfMAdd() { + when(commandObjects.bfMAdd("myBloomFilter", "item1", "item2")).thenReturn(listBooleanCommandObject); + + Response> response = pipeliningBase.bfMAdd("myBloomFilter", "item1", "item2"); + + assertThat(commands, contains(listBooleanCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testBfInsert() { + when(commandObjects.bfInsert("myBloomFilter", "item1", "item2")).thenReturn(listBooleanCommandObject); + + Response> response = pipeliningBase.bfInsert("myBloomFilter", "item1", "item2"); + + assertThat(commands, contains(listBooleanCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testBfInsertWithParams() { + BFInsertParams insertParams = new BFInsertParams().capacity(10000L).error(0.01); + + when(commandObjects.bfInsert("myBloomFilter", insertParams, "item1", "item2")).thenReturn(listBooleanCommandObject); + + Response> response = pipeliningBase.bfInsert("myBloomFilter", insertParams, "item1", "item2"); + + assertThat(commands, contains(listBooleanCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testBfExists() { + when(commandObjects.bfExists("myBloomFilter", "item1")).thenReturn(booleanCommandObject); + + Response response = pipeliningBase.bfExists("myBloomFilter", "item1"); + + assertThat(commands, contains(booleanCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testBfMExists() { + when(commandObjects.bfMExists("myBloomFilter", "item1", "item2")).thenReturn(listBooleanCommandObject); + + Response> response = pipeliningBase.bfMExists("myBloomFilter", "item1", "item2"); + + assertThat(commands, contains(listBooleanCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testBfScanDump() { + when(commandObjects.bfScanDump("myBloomFilter", 0L)).thenReturn(entryLongBytesCommandObject); + + Response> response = pipeliningBase.bfScanDump("myBloomFilter", 0L); + + assertThat(commands, contains(entryLongBytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testBfLoadChunk() { + byte[] data = { 1, 2, 3, 4 }; + + when(commandObjects.bfLoadChunk("myBloomFilter", 0L, data)).thenReturn(stringCommandObject); + + Response response = pipeliningBase.bfLoadChunk("myBloomFilter", 0L, data); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testBfCard() { + when(commandObjects.bfCard("myBloomFilter")).thenReturn(longCommandObject); + + Response response = pipeliningBase.bfCard("myBloomFilter"); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testBfInfo() { + when(commandObjects.bfInfo("myBloomFilter")).thenReturn(mapStringObjectCommandObject); + + Response> response = pipeliningBase.bfInfo("myBloomFilter"); + + assertThat(commands, contains(mapStringObjectCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testCfReserve() { + when(commandObjects.cfReserve("myCuckooFilter", 10000L)).thenReturn(stringCommandObject); + + Response response = pipeliningBase.cfReserve("myCuckooFilter", 10000L); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testCfReserveWithParams() { + CFReserveParams reserveParams = new CFReserveParams().bucketSize(2).maxIterations(500).expansion(2); + + when(commandObjects.cfReserve("myCuckooFilter", 10000L, reserveParams)).thenReturn(stringCommandObject); + + Response response = pipeliningBase.cfReserve("myCuckooFilter", 10000L, reserveParams); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testCfAdd() { + when(commandObjects.cfAdd("myCuckooFilter", "item1")).thenReturn(booleanCommandObject); + + Response response = pipeliningBase.cfAdd("myCuckooFilter", "item1"); + + assertThat(commands, contains(booleanCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testCfAddNx() { + when(commandObjects.cfAddNx("myCuckooFilter", "item1")).thenReturn(booleanCommandObject); + + Response response = pipeliningBase.cfAddNx("myCuckooFilter", "item1"); + + assertThat(commands, contains(booleanCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testCfInsert() { + when(commandObjects.cfInsert("myCuckooFilter", "item1", "item2")).thenReturn(listBooleanCommandObject); + + Response> response = pipeliningBase.cfInsert("myCuckooFilter", "item1", "item2"); + + assertThat(commands, contains(listBooleanCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testCfInsertWithParams() { + CFInsertParams insertParams = new CFInsertParams().capacity(10000L).noCreate(); + + when(commandObjects.cfInsert("myCuckooFilter", insertParams, "item1", "item2")).thenReturn(listBooleanCommandObject); + + Response> response = pipeliningBase.cfInsert("myCuckooFilter", insertParams, "item1", "item2"); + + assertThat(commands, contains(listBooleanCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testCfInsertNx() { + when(commandObjects.cfInsertNx("myCuckooFilter", "item1", "item2")).thenReturn(listBooleanCommandObject); + + Response> response = pipeliningBase.cfInsertNx("myCuckooFilter", "item1", "item2"); + + assertThat(commands, contains(listBooleanCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testCfInsertNxWithParams() { + CFInsertParams insertParams = new CFInsertParams().capacity(10000L).noCreate(); + + when(commandObjects.cfInsertNx("myCuckooFilter", insertParams, "item1", "item2")).thenReturn(listBooleanCommandObject); + + Response> response = pipeliningBase.cfInsertNx("myCuckooFilter", insertParams, "item1", "item2"); + + assertThat(commands, contains(listBooleanCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testCfExists() { + when(commandObjects.cfExists("myCuckooFilter", "item1")).thenReturn(booleanCommandObject); + + Response response = pipeliningBase.cfExists("myCuckooFilter", "item1"); + + assertThat(commands, contains(booleanCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testCfDel() { + when(commandObjects.cfDel("myCuckooFilter", "item1")).thenReturn(booleanCommandObject); + + Response response = pipeliningBase.cfDel("myCuckooFilter", "item1"); + + assertThat(commands, contains(booleanCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testCfCount() { + when(commandObjects.cfCount("myCuckooFilter", "item1")).thenReturn(longCommandObject); + + Response response = pipeliningBase.cfCount("myCuckooFilter", "item1"); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testCfScanDump() { + when(commandObjects.cfScanDump("myCuckooFilter", 0L)).thenReturn(entryLongBytesCommandObject); + + Response> response = pipeliningBase.cfScanDump("myCuckooFilter", 0L); + + assertThat(commands, contains(entryLongBytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testCfLoadChunk() { + byte[] data = { 1, 2, 3, 4 }; + + when(commandObjects.cfLoadChunk("myCuckooFilter", 0L, data)).thenReturn(stringCommandObject); + + Response response = pipeliningBase.cfLoadChunk("myCuckooFilter", 0L, data); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testCfInfo() { + when(commandObjects.cfInfo("myCuckooFilter")).thenReturn(mapStringObjectCommandObject); + + Response> response = pipeliningBase.cfInfo("myCuckooFilter"); + + assertThat(commands, contains(mapStringObjectCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testCmsInitByDim() { + when(commandObjects.cmsInitByDim("myCountMinSketch", 1000L, 5L)).thenReturn(stringCommandObject); + + Response response = pipeliningBase.cmsInitByDim("myCountMinSketch", 1000L, 5L); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testCmsInitByProb() { + double error = 0.01; + double probability = 0.99; + + when(commandObjects.cmsInitByProb("myCountMinSketch", error, probability)).thenReturn(stringCommandObject); + + Response response = pipeliningBase.cmsInitByProb("myCountMinSketch", error, probability); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testCmsIncrBy() { + Map itemIncrements = new HashMap<>(); + itemIncrements.put("item1", 1L); + itemIncrements.put("item2", 2L); + + when(commandObjects.cmsIncrBy("myCountMinSketch", itemIncrements)).thenReturn(listLongCommandObject); + + Response> response = pipeliningBase.cmsIncrBy("myCountMinSketch", itemIncrements); + + assertThat(commands, contains(listLongCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testCmsQuery() { + when(commandObjects.cmsQuery("myCountMinSketch", "item1", "item2")).thenReturn(listLongCommandObject); + + Response> response = pipeliningBase.cmsQuery("myCountMinSketch", "item1", "item2"); + + assertThat(commands, contains(listLongCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testCmsMerge() { + when(commandObjects.cmsMerge("mergedCountMinSketch", "cms1", "cms2")).thenReturn(stringCommandObject); + + Response response = pipeliningBase.cmsMerge("mergedCountMinSketch", "cms1", "cms2"); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testCmsMergeWithWeights() { + Map keysAndWeights = new HashMap<>(); + keysAndWeights.put("cms1", 1L); + keysAndWeights.put("cms2", 2L); + + when(commandObjects.cmsMerge("mergedCountMinSketch", keysAndWeights)).thenReturn(stringCommandObject); + + Response response = pipeliningBase.cmsMerge("mergedCountMinSketch", keysAndWeights); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testCmsInfo() { + when(commandObjects.cmsInfo("myCountMinSketch")).thenReturn(mapStringObjectCommandObject); + + Response> response = pipeliningBase.cmsInfo("myCountMinSketch"); + + assertThat(commands, contains(mapStringObjectCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testTopkReserve() { + when(commandObjects.topkReserve("myTopK", 3L)).thenReturn(stringCommandObject); + + Response response = pipeliningBase.topkReserve("myTopK", 3L); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testTopkReserveWithParams() { + long width = 50L; + long depth = 5L; + double decay = 0.9; + + when(commandObjects.topkReserve("myTopK", 3L, width, depth, decay)).thenReturn(stringCommandObject); + + Response response = pipeliningBase.topkReserve("myTopK", 3L, width, depth, decay); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testTopkAdd() { + when(commandObjects.topkAdd("myTopK", "item1", "item2")).thenReturn(listStringCommandObject); + + Response> response = pipeliningBase.topkAdd("myTopK", "item1", "item2"); + + assertThat(commands, contains(listStringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testTopkIncrBy() { + Map itemIncrements = new HashMap<>(); + itemIncrements.put("item1", 1L); + itemIncrements.put("item2", 2L); + + when(commandObjects.topkIncrBy("myTopK", itemIncrements)).thenReturn(listStringCommandObject); + + Response> response = pipeliningBase.topkIncrBy("myTopK", itemIncrements); + + assertThat(commands, contains(listStringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testTopkQuery() { + when(commandObjects.topkQuery("myTopK", "item1", "item2")).thenReturn(listBooleanCommandObject); + + Response> response = pipeliningBase.topkQuery("myTopK", "item1", "item2"); + + assertThat(commands, contains(listBooleanCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testTopkList() { + when(commandObjects.topkList("myTopK")).thenReturn(listStringCommandObject); + + Response> response = pipeliningBase.topkList("myTopK"); + + assertThat(commands, contains(listStringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testTopkListWithCount() { + when(commandObjects.topkListWithCount("myTopK")).thenReturn(mapStringLongCommandObject); + + Response> response = pipeliningBase.topkListWithCount("myTopK"); + + assertThat(commands, contains(mapStringLongCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testTopkInfo() { + when(commandObjects.topkInfo("myTopK")).thenReturn(mapStringObjectCommandObject); + + Response> response = pipeliningBase.topkInfo("myTopK"); + + assertThat(commands, contains(mapStringObjectCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testTdigestCreate() { + when(commandObjects.tdigestCreate("myTDigest")).thenReturn(stringCommandObject); + + Response response = pipeliningBase.tdigestCreate("myTDigest"); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testTdigestCreateWithCompression() { + when(commandObjects.tdigestCreate("myTDigest", 100)).thenReturn(stringCommandObject); + + Response response = pipeliningBase.tdigestCreate("myTDigest", 100); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testTdigestReset() { + when(commandObjects.tdigestReset("myTDigest")).thenReturn(stringCommandObject); + + Response response = pipeliningBase.tdigestReset("myTDigest"); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testTdigestMerge() { + when(commandObjects.tdigestMerge("destinationTDigest", "sourceTDigest1", "sourceTDigest2")) + .thenReturn(stringCommandObject); + + Response response = + pipeliningBase.tdigestMerge("destinationTDigest", "sourceTDigest1", "sourceTDigest2"); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testTdigestMergeWithParams() { + TDigestMergeParams mergeParams = new TDigestMergeParams().compression(100); + + when(commandObjects.tdigestMerge(mergeParams, "destinationTDigest", "sourceTDigest1", "sourceTDigest2")) + .thenReturn(stringCommandObject); + + Response response = + pipeliningBase.tdigestMerge(mergeParams, "destinationTDigest", "sourceTDigest1", "sourceTDigest2"); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testTdigestInfo() { + when(commandObjects.tdigestInfo("myTDigest")).thenReturn(mapStringObjectCommandObject); + + Response> response = pipeliningBase.tdigestInfo("myTDigest"); + + assertThat(commands, contains(mapStringObjectCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testTdigestAdd() { + when(commandObjects.tdigestAdd("myTDigest", 1.0, 2.0, 3.0)).thenReturn(stringCommandObject); + + Response response = pipeliningBase.tdigestAdd("myTDigest", 1.0, 2.0, 3.0); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testTdigestCDF() { + when(commandObjects.tdigestCDF("myTDigest", 1.0, 2.0)).thenReturn(listDoubleCommandObject); + + Response> response = pipeliningBase.tdigestCDF("myTDigest", 1.0, 2.0); + + assertThat(commands, contains(listDoubleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testTdigestQuantile() { + when(commandObjects.tdigestQuantile("myTDigest", 0.5, 0.9)).thenReturn(listDoubleCommandObject); + + Response> response = pipeliningBase.tdigestQuantile("myTDigest", 0.5, 0.9); + + assertThat(commands, contains(listDoubleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testTdigestMin() { + when(commandObjects.tdigestMin("myTDigest")).thenReturn(doubleCommandObject); + + Response response = pipeliningBase.tdigestMin("myTDigest"); + + assertThat(commands, contains(doubleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testTdigestMax() { + when(commandObjects.tdigestMax("myTDigest")).thenReturn(doubleCommandObject); + + Response response = pipeliningBase.tdigestMax("myTDigest"); + + assertThat(commands, contains(doubleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testTdigestTrimmedMean() { + when(commandObjects.tdigestTrimmedMean("myTDigest", 0.1, 0.9)).thenReturn(doubleCommandObject); + + Response response = pipeliningBase.tdigestTrimmedMean("myTDigest", 0.1, 0.9); + + assertThat(commands, contains(doubleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testTdigestRank() { + when(commandObjects.tdigestRank("myTDigest", 1.0, 2.0)).thenReturn(listLongCommandObject); + + Response> response = pipeliningBase.tdigestRank("myTDigest", 1.0, 2.0); + + assertThat(commands, contains(listLongCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testTdigestRevRank() { + when(commandObjects.tdigestRevRank("myTDigest", 1.0, 2.0)).thenReturn(listLongCommandObject); + + Response> response = pipeliningBase.tdigestRevRank("myTDigest", 1.0, 2.0); + + assertThat(commands, contains(listLongCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testTdigestByRank() { + when(commandObjects.tdigestByRank("myTDigest", 1, 2)).thenReturn(listDoubleCommandObject); + + Response> response = pipeliningBase.tdigestByRank("myTDigest", 1, 2); + + assertThat(commands, contains(listDoubleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testTdigestByRevRank() { + when(commandObjects.tdigestByRevRank("myTDigest", 1, 2)).thenReturn(listDoubleCommandObject); + + Response> response = pipeliningBase.tdigestByRevRank("myTDigest", 1, 2); + + assertThat(commands, contains(listDoubleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testGraphQuery() { + String query = "MATCH (n) RETURN n"; + + when(graphCommandObjects.graphQuery("myGraph", query)).thenReturn(resultSetCommandObject); + + Response response = pipeliningBase.graphQuery("myGraph", query); + + assertThat(commands, contains(resultSetCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testGraphReadonlyQuery() { + String query = "MATCH (n) RETURN n"; + + when(graphCommandObjects.graphReadonlyQuery("myGraph", query)).thenReturn(resultSetCommandObject); + + Response response = pipeliningBase.graphReadonlyQuery("myGraph", query); + + assertThat(commands, contains(resultSetCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testGraphQueryWithTimeout() { + String query = "MATCH (n) RETURN n"; + + when(graphCommandObjects.graphQuery("myGraph", query, 1000L)).thenReturn(resultSetCommandObject); + + Response response = pipeliningBase.graphQuery("myGraph", query, 1000L); + + assertThat(commands, contains(resultSetCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testGraphReadonlyQueryWithTimeout() { + String query = "MATCH (n) RETURN n"; + + when(graphCommandObjects.graphReadonlyQuery("myGraph", query, 1000L)).thenReturn(resultSetCommandObject); + + Response response = pipeliningBase.graphReadonlyQuery("myGraph", query, 1000L); + + assertThat(commands, contains(resultSetCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testGraphQueryWithParams() { + String query = "MATCH (n) WHERE n.name = $name RETURN n"; + Map params = Collections.singletonMap("name", "Alice"); + + when(graphCommandObjects.graphQuery("myGraph", query, params)).thenReturn(resultSetCommandObject); + + Response response = pipeliningBase.graphQuery("myGraph", query, params); + + assertThat(commands, contains(resultSetCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testGraphReadonlyQueryWithParams() { + String query = "MATCH (n) WHERE n.name = $name RETURN n"; + Map params = Collections.singletonMap("name", "Alice"); + + when(graphCommandObjects.graphReadonlyQuery("myGraph", query, params)).thenReturn(resultSetCommandObject); + + Response response = pipeliningBase.graphReadonlyQuery("myGraph", query, params); + + assertThat(commands, contains(resultSetCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testGraphQueryWithParamsAndTimeout() { + String query = "MATCH (n) WHERE n.name = $name RETURN n"; + Map params = Collections.singletonMap("name", "Alice"); + + when(graphCommandObjects.graphQuery("myGraph", query, params, 1000L)).thenReturn(resultSetCommandObject); + + Response response = pipeliningBase.graphQuery("myGraph", query, params, 1000L); + + assertThat(commands, contains(resultSetCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testGraphReadonlyQueryWithParamsAndTimeout() { + String query = "MATCH (n) WHERE n.name = $name RETURN n"; + Map params = Collections.singletonMap("name", "Alice"); + + when(graphCommandObjects.graphReadonlyQuery("myGraph", query, params, 1000L)).thenReturn(resultSetCommandObject); + + Response response = pipeliningBase.graphReadonlyQuery("myGraph", query, params, 1000L); + + assertThat(commands, contains(resultSetCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testGraphDelete() { + when(graphCommandObjects.graphDelete("myGraph")).thenReturn(stringCommandObject); + + Response response = pipeliningBase.graphDelete("myGraph"); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testGraphProfile() { + String query = "PROFILE MATCH (n) RETURN n"; + + when(commandObjects.graphProfile("myGraph", query)).thenReturn(listStringCommandObject); + + Response> response = pipeliningBase.graphProfile("myGraph", query); + + assertThat(commands, contains(listStringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testSendCommandWithStringArgs() { + ProtocolCommand cmd = Protocol.Command.GET; + String arg1 = "key1"; + String arg2 = "key2"; + + Response response = pipeliningBase.sendCommand(cmd, arg1, arg2); + + assertThat(commands, hasSize(1)); + + List arguments = new ArrayList<>(); + commands.get(0).getArguments().forEach(arguments::add); + + assertThat(arguments.stream().map(Rawable::getRaw).collect(Collectors.toList()), contains( + Protocol.Command.GET.getRaw(), + arg1.getBytes(), + arg2.getBytes() + )); + + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testSendCommandWithByteArgs() { + ProtocolCommand cmd = Protocol.Command.SET; + byte[] arg1 = "key1".getBytes(); + byte[] arg2 = "value1".getBytes(); + + Response response = pipeliningBase.sendCommand(cmd, arg1, arg2); + + assertThat(commands, hasSize(1)); + + List arguments = new ArrayList<>(); + commands.get(0).getArguments().forEach(arguments::add); + + assertThat(arguments.stream().map(Rawable::getRaw).collect(Collectors.toList()), contains( + Protocol.Command.SET.getRaw(), + arg1, + arg2 + )); + + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testExecuteCommand() { + CommandArguments commandArguments = new CommandArguments(Protocol.Command.GET).key("key1"); + CommandObject commandObject = new CommandObject<>(commandArguments, BuilderFactory.STRING); + + Response response = pipeliningBase.executeCommand(commandObject); + + assertThat(commands, contains(commandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testSetJsonObjectMapper() { + JsonObjectMapper jsonObjectMapper = mock(JsonObjectMapper.class); + doNothing().when(commandObjects).setJsonObjectMapper(jsonObjectMapper); + + pipeliningBase.setJsonObjectMapper(jsonObjectMapper); + + verify(commandObjects).setJsonObjectMapper(jsonObjectMapper); + } + + @Test + public void testMultipleCommands() { + when(commandObjects.exists("key1")).thenReturn(booleanCommandObject); + when(commandObjects.exists("key2")).thenReturn(booleanCommandObject); + + Response result1 = pipeliningBase.exists("key1"); + Response result2 = pipeliningBase.exists("key2"); + + assertThat(commands, contains( + booleanCommandObject, + booleanCommandObject + )); + + assertThat(result1, is(predefinedResponse)); + assertThat(result2, is(predefinedResponse)); + } + +} 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 c62daa4aa1c..0377c481b4d 100644 --- a/src/test/java/redis/clients/jedis/commands/jedis/SlowlogCommandsTest.java +++ b/src/test/java/redis/clients/jedis/commands/jedis/SlowlogCommandsTest.java @@ -116,7 +116,7 @@ public void slowlogBinaryObjectDetails() { List log = (List) logs.get(0); assertThat((Long) log.get(0), Matchers.greaterThan(0L)); assertThat((Long) log.get(1), Matchers.greaterThan(0L)); - assertThat((Long) log.get(2), Matchers.greaterThan(0L)); + assertThat((Long) log.get(2), Matchers.greaterThanOrEqualTo(0L)); List args = (List) log.get(3); assertEquals(4, args.size()); assertArrayEquals(Protocol.Command.CONFIG.getRaw(), (byte[]) args.get(0)); From 8b4f42145ba390eb6a5d9c11a104b79131e6b6d4 Mon Sep 17 00:00:00 2001 From: Gabriel Erzse Date: Tue, 19 Mar 2024 19:39:49 +0200 Subject: [PATCH 21/33] Pipelined tests for lists and sets, and API typo fix (#3772) * Add unit tests for pipelined list operations * Add tests for set pipelined operations Also detected a typo in one of the method names, mark that method as deprecated and add a new one that respects the naming convention. * Fix flaky test Sometimes the slow log operation in the binary test actually takes 0 time, so adapt the assert to cover that case too. --------- Co-authored-by: Gabriel Erzse Co-authored-by: M Sazzadul Hoque <7600764+sazzad16@users.noreply.github.com> --- .../pipeline/ListPipelineCommandsTest.java | 1033 +++++++++++++++++ .../pipeline/SetPipelineCommandsTest.java | 659 +++++++++++ 2 files changed, 1692 insertions(+) create mode 100644 src/test/java/redis/clients/jedis/commands/unified/pipeline/ListPipelineCommandsTest.java create mode 100644 src/test/java/redis/clients/jedis/commands/unified/pipeline/SetPipelineCommandsTest.java diff --git a/src/test/java/redis/clients/jedis/commands/unified/pipeline/ListPipelineCommandsTest.java b/src/test/java/redis/clients/jedis/commands/unified/pipeline/ListPipelineCommandsTest.java new file mode 100644 index 00000000000..36313c24cae --- /dev/null +++ b/src/test/java/redis/clients/jedis/commands/unified/pipeline/ListPipelineCommandsTest.java @@ -0,0 +1,1033 @@ +package redis.clients.jedis.commands.unified.pipeline; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.contains; +import static org.hamcrest.Matchers.empty; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.instanceOf; +import static org.hamcrest.Matchers.nullValue; +import static org.junit.Assert.assertTrue; + +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.RedisProtocol; +import redis.clients.jedis.Response; +import redis.clients.jedis.args.ListDirection; +import redis.clients.jedis.args.ListPosition; +import redis.clients.jedis.exceptions.JedisDataException; +import redis.clients.jedis.params.LPosParams; +import redis.clients.jedis.util.KeyValue; + +@RunWith(Parameterized.class) +public class ListPipelineCommandsTest extends PipelineCommandsTestBase { + + private final Logger logger = LoggerFactory.getLogger(getClass()); + + protected final byte[] bfoo = { 0x01, 0x02, 0x03, 0x04 }; + protected final byte[] bfoo1 = { 0x01, 0x02, 0x03, 0x04, 0x05 }; + protected final byte[] bbar = { 0x05, 0x06, 0x07, 0x08 }; + protected final byte[] bcar = { 0x09, 0x0A, 0x0B, 0x0C }; + protected final byte[] bA = { 0x0A }; + protected final byte[] bB = { 0x0B }; + protected final byte[] bC = { 0x0C }; + protected final byte[] b1 = { 0x01 }; + protected final byte[] b2 = { 0x02 }; + protected final byte[] b3 = { 0x03 }; + protected final byte[] bhello = { 0x04, 0x02 }; + protected final byte[] bx = { 0x02, 0x04 }; + protected final byte[] bdst = { 0x11, 0x12, 0x13, 0x14 }; + + public ListPipelineCommandsTest(RedisProtocol protocol) { + super(protocol); + } + + @Test + public void rpush() { + pipe.rpush("foo", "bar"); + pipe.rpush("foo", "foo"); + pipe.rpush("foo", "bar", "foo"); + + assertThat(pipe.syncAndReturnAll(), contains( + 1L, + 2L, + 4L + )); + + // Binary + pipe.rpush(bfoo, bbar); + pipe.rpush(bfoo, bfoo); + pipe.rpush(bfoo, bbar, bfoo); + + assertThat(pipe.syncAndReturnAll(), contains( + 1L, + 2L, + 4L + )); + } + + @Test + public void lpush() { + pipe.lpush("foo", "bar"); + pipe.lpush("foo", "foo"); + pipe.lpush("foo", "bar", "foo"); + + assertThat(pipe.syncAndReturnAll(), contains( + 1L, + 2L, + 4L + )); + + // Binary + pipe.lpush(bfoo, bbar); + pipe.lpush(bfoo, bfoo); + pipe.lpush(bfoo, bbar, bfoo); + + assertThat(pipe.syncAndReturnAll(), contains( + 1L, + 2L, + 4L + )); + } + + @Test + public void llen() { + pipe.llen("foo"); + pipe.lpush("foo", "bar"); + pipe.lpush("foo", "car"); + pipe.llen("foo"); + + assertThat(pipe.syncAndReturnAll(), contains( + 0L, + 1L, + 2L, + 2L + )); + + // Binary + pipe.llen(bfoo); + pipe.lpush(bfoo, bbar); + pipe.lpush(bfoo, bcar); + pipe.llen(bfoo); + + assertThat(pipe.syncAndReturnAll(), contains( + 0L, + 1L, + 2L, + 2L + )); + } + + @Test + public void llenNotOnList() { + pipe.set("foo", "bar"); + pipe.llen("foo"); + + assertThat(pipe.syncAndReturnAll(), contains( + equalTo("OK"), + instanceOf(JedisDataException.class) + )); + + // Binary + pipe.set(bfoo, bbar); + pipe.llen(bfoo); + + assertThat(pipe.syncAndReturnAll(), contains( + equalTo("OK"), + instanceOf(JedisDataException.class) + )); + } + + @Test + public void lrange() { + pipe.rpush("foo", "a"); + pipe.rpush("foo", "b"); + pipe.rpush("foo", "c"); + + Response> range1 = pipe.lrange("foo", 0, 2); + Response> range2 = pipe.lrange("foo", 0, 20); + Response> range3 = pipe.lrange("foo", 1, 2); + Response> range4 = pipe.lrange("foo", 2, 1); + + pipe.sync(); + + assertThat(range1.get(), contains("a", "b", "c")); + assertThat(range2.get(), contains("a", "b", "c")); + assertThat(range3.get(), contains("b", "c")); + assertThat(range4.get(), empty()); + + // Binary + pipe.rpush(bfoo, bA); + pipe.rpush(bfoo, bB); + pipe.rpush(bfoo, bC); + + Response> brange1 = pipe.lrange(bfoo, 0, 2); + Response> brange2 = pipe.lrange(bfoo, 0, 20); + Response> brange3 = pipe.lrange(bfoo, 1, 2); + Response> brange4 = pipe.lrange(bfoo, 2, 1); + + pipe.sync(); + + assertThat(brange1.get(), contains(bA, bB, bC)); + assertThat(brange2.get(), contains(bA, bB, bC)); + assertThat(brange3.get(), contains(bB, bC)); + assertThat(brange4.get(), empty()); + } + + @Test + public void ltrim() { + pipe.lpush("foo", "1"); + pipe.lpush("foo", "2"); + pipe.lpush("foo", "3"); + + Response status = pipe.ltrim("foo", 0, 1); + Response len = pipe.llen("foo"); + Response> range = pipe.lrange("foo", 0, 100); + + pipe.sync(); + + assertThat(status.get(), equalTo("OK")); + assertThat(len.get(), equalTo(2L)); + assertThat(range.get(), contains("3", "2")); + + // Binary + pipe.lpush(bfoo, b1); + pipe.lpush(bfoo, b2); + pipe.lpush(bfoo, b3); + + Response bstatus = pipe.ltrim(bfoo, 0, 1); + Response blen = pipe.llen(bfoo); + Response> brange = pipe.lrange(bfoo, 0, 100); + + pipe.sync(); + + assertThat(bstatus.get(), equalTo("OK")); + assertThat(blen.get(), equalTo(2L)); + assertThat(brange.get(), contains(b3, b2)); + } + + @Test + public void lset() { + pipe.lpush("foo", "1"); + pipe.lpush("foo", "2"); + pipe.lpush("foo", "3"); + + Response status = pipe.lset("foo", 1, "bar"); + Response> range = pipe.lrange("foo", 0, 100); + + pipe.sync(); + + assertThat(status.get(), equalTo("OK")); + assertThat(range.get(), contains("3", "bar", "1")); + + // Binary + pipe.lpush(bfoo, b1); + pipe.lpush(bfoo, b2); + pipe.lpush(bfoo, b3); + + Response bstatus = pipe.lset(bfoo, 1, bbar); + Response> brange = pipe.lrange(bfoo, 0, 100); + + pipe.sync(); + + assertThat(bstatus.get(), equalTo("OK")); + assertThat(brange.get(), contains(b3, bbar, b1)); + } + + @Test + public void lindex() { + pipe.lpush("foo", "1"); + pipe.lpush("foo", "2"); + pipe.lpush("foo", "3"); + + Response index1 = pipe.lindex("foo", 0); + Response index2 = pipe.lindex("foo", 100); + + pipe.sync(); + + assertThat(index1.get(), equalTo("3")); + assertThat(index2.get(), nullValue()); + + // Binary + pipe.lpush(bfoo, b1); + pipe.lpush(bfoo, b2); + pipe.lpush(bfoo, b3); + + Response bindex1 = pipe.lindex(bfoo, 0); + Response bindex2 = pipe.lindex(bfoo, 100); + + pipe.sync(); + + assertThat(bindex1.get(), equalTo(b3)); + assertThat(bindex2.get(), nullValue()); + } + + @Test + public void lrem() { + pipe.lpush("foo", "hello"); + pipe.lpush("foo", "hello"); + pipe.lpush("foo", "x"); + pipe.lpush("foo", "hello"); + pipe.lpush("foo", "c"); + pipe.lpush("foo", "b"); + pipe.lpush("foo", "a"); + + Response result1 = pipe.lrem("foo", -2, "hello"); + Response> range = pipe.lrange("foo", 0, 1000); + Response result2 = pipe.lrem("bar", 100, "foo"); + + pipe.sync(); + + assertThat(result1.get(), equalTo(2L)); + assertThat(range.get(), contains("a", "b", "c", "hello", "x")); + assertThat(result2.get(), equalTo(0L)); + + // Binary + pipe.lpush(bfoo, bhello); + pipe.lpush(bfoo, bhello); + pipe.lpush(bfoo, bx); + pipe.lpush(bfoo, bhello); + pipe.lpush(bfoo, bC); + pipe.lpush(bfoo, bB); + pipe.lpush(bfoo, bA); + + Response bresult1 = pipe.lrem(bfoo, -2, bhello); + Response> brange = pipe.lrange(bfoo, 0, 1000); + Response bresult2 = pipe.lrem(bbar, 100, bfoo); + + pipe.sync(); + + assertThat(bresult1.get(), equalTo(2L)); + assertThat(brange.get(), contains(bA, bB, bC, bhello, bx)); + assertThat(bresult2.get(), equalTo(0L)); + } + + @Test + public void lpop() { + Response response1 = pipe.lpop("foo"); + Response> response2 = pipe.lpop("foo", 0); + + pipe.rpush("foo", "a"); + pipe.rpush("foo", "b"); + pipe.rpush("foo", "c"); + + Response response3 = pipe.lpop("foo"); + Response> response4 = pipe.lpop("foo", 10); + Response response5 = pipe.lpop("foo"); + Response> response6 = pipe.lpop("foo", 1); + + pipe.sync(); + + assertThat(response1.get(), nullValue()); + assertThat(response2.get(), nullValue()); + assertThat(response3.get(), equalTo("a")); + assertThat(response4.get(), contains("b", "c")); + assertThat(response5.get(), nullValue()); + assertThat(response6.get(), nullValue()); + + // Binary + Response bresponse1 = pipe.lpop(bfoo); + Response> bresponse2 = pipe.lpop(bfoo, 0); + + pipe.rpush(bfoo, bA); + pipe.rpush(bfoo, bB); + pipe.rpush(bfoo, bC); + + Response bresponse3 = pipe.lpop(bfoo); + Response> bresponse4 = pipe.lpop(bfoo, 10); + Response bresponse5 = pipe.lpop(bfoo); + Response> bresponse6 = pipe.lpop(bfoo, 1); + + pipe.sync(); + + assertThat(bresponse1.get(), nullValue()); + assertThat(bresponse2.get(), nullValue()); + assertThat(bresponse3.get(), equalTo(bA)); + assertThat(bresponse4.get(), contains(bB, bC)); + assertThat(bresponse5.get(), nullValue()); + assertThat(bresponse6.get(), nullValue()); + } + + @Test + public void rpop() { + Response response1 = pipe.rpop("foo"); + Response> response2 = pipe.rpop("foo", 0); + + pipe.rpush("foo", "a"); + pipe.rpush("foo", "b"); + pipe.rpush("foo", "c"); + + Response response3 = pipe.rpop("foo"); + Response> response4 = pipe.rpop("foo", 10); + Response response5 = pipe.rpop("foo"); + Response> response6 = pipe.rpop("foo", 1); + + pipe.sync(); + + assertThat(response1.get(), nullValue()); + assertThat(response2.get(), nullValue()); + assertThat(response3.get(), equalTo("c")); + assertThat(response4.get(), contains("b", "a")); + assertThat(response5.get(), nullValue()); + assertThat(response6.get(), nullValue()); + + // Binary + Response bresponse1 = pipe.rpop(bfoo); + Response> bresponse2 = pipe.rpop(bfoo, 0); + + pipe.rpush(bfoo, bA); + pipe.rpush(bfoo, bB); + pipe.rpush(bfoo, bC); + + Response bresponse3 = pipe.rpop(bfoo); + Response> bresponse4 = pipe.rpop(bfoo, 10); + Response bresponse5 = pipe.rpop(bfoo); + Response> bresponse6 = pipe.rpop(bfoo, 1); + + pipe.sync(); + + assertThat(bresponse1.get(), nullValue()); + assertThat(bresponse2.get(), nullValue()); + assertThat(bresponse3.get(), equalTo(bC)); + assertThat(bresponse4.get(), contains(bB, bA)); + assertThat(bresponse5.get(), nullValue()); + assertThat(bresponse6.get(), nullValue()); + } + + @Test + public void rpoplpush() { + pipe.rpush("foo", "a"); + pipe.rpush("foo", "b"); + pipe.rpush("foo", "c"); + + pipe.rpush("dst", "foo"); + pipe.rpush("dst", "bar"); + + Response element = pipe.rpoplpush("foo", "dst"); + Response> srcRange = pipe.lrange("foo", 0, 1000); + Response> dstRange = pipe.lrange("dst", 0, 1000); + + pipe.sync(); + + assertThat(element.get(), equalTo("c")); + assertThat(srcRange.get(), contains("a", "b")); + assertThat(dstRange.get(), contains("c", "foo", "bar")); + + // Binary + pipe.rpush(bfoo, bA); + pipe.rpush(bfoo, bB); + pipe.rpush(bfoo, bC); + + pipe.rpush(bdst, bfoo); + pipe.rpush(bdst, bbar); + + Response belement = pipe.rpoplpush(bfoo, bdst); + Response> bsrcRange = pipe.lrange(bfoo, 0, 1000); + Response> bdstRange = pipe.lrange(bdst, 0, 1000); + + pipe.sync(); + + assertThat(belement.get(), equalTo(bC)); + assertThat(bsrcRange.get(), contains(bA, bB)); + assertThat(bdstRange.get(), contains(bC, bfoo, bbar)); + } + + @Test + public void blpop() throws InterruptedException { + Response> result1 = pipe.blpop(1, "foo"); + + pipe.lpush("foo", "bar"); + + Response> result2 = pipe.blpop(1, "foo"); + + // Multi keys + Response> result3 = pipe.blpop(1, "foo", "foo1"); + + pipe.lpush("foo", "bar"); + pipe.lpush("foo1", "bar1"); + + Response> result4 = pipe.blpop(1, "foo1", "foo"); + + pipe.sync(); + + assertThat(result1.get(), nullValue()); + assertThat(result2.get(), contains("foo", "bar")); + assertThat(result3.get(), nullValue()); + assertThat(result4.get(), contains("foo1", "bar1")); + + // Binary + pipe.lpush(bfoo, bbar); + + Response> bresult1 = pipe.blpop(1, bfoo); + + // Binary Multi keys + Response> bresult2 = pipe.blpop(1, bfoo, bfoo1); + + pipe.lpush(bfoo, bbar); + pipe.lpush(bfoo1, bcar); + + Response> bresult3 = pipe.blpop(1, bfoo1, bfoo); + + pipe.sync(); + + assertThat(bresult1.get(), contains(bfoo, bbar)); + assertThat(bresult2.get(), nullValue()); + assertThat(bresult3.get(), contains(bfoo1, bcar)); + } + + @Test + public void blpopDouble() { + Response> result1 = pipe.blpop(0.1, "foo"); + + pipe.lpush("foo", "bar"); + + Response> result2 = pipe.blpop(3.2, "foo"); + + // Multi keys + Response> result3 = pipe.blpop(0.18, "foo", "foo1"); + + pipe.lpush("foo", "bar"); + pipe.lpush("foo1", "bar1"); + + Response> result4 = pipe.blpop(1d, "foo1", "foo"); + + pipe.sync(); + + assertThat(result1.get(), nullValue()); + assertThat(result2.get(), equalTo(new KeyValue<>("foo", "bar"))); + assertThat(result3.get(), nullValue()); + assertThat(result4.get(), equalTo(new KeyValue<>("foo1", "bar1"))); + + // Binary + pipe.lpush(bfoo, bbar); + + Response> bresult1 = pipe.blpop(3.12, bfoo); + + // Binary Multi keys + Response> bresult2 = pipe.blpop(0.11, bfoo, bfoo1); + + pipe.lpush(bfoo, bbar); + pipe.lpush(bfoo1, bcar); + + Response> bresult3 = pipe.blpop(1d, bfoo1, bfoo); + + pipe.sync(); + + assertThat(bresult1.get().getKey(), equalTo(bfoo)); + assertThat(bresult1.get().getValue(), equalTo(bbar)); + assertThat(bresult2.get(), nullValue()); + assertThat(bresult3.get().getKey(), equalTo(bfoo1)); + assertThat(bresult3.get().getValue(), equalTo(bcar)); + } + + @Test + public void blpopDoubleWithSleep() { + long startMillis, totalMillis; + + startMillis = System.currentTimeMillis(); + + Response> result = pipe.blpop(0.04, "foo"); + pipe.sync(); + + totalMillis = System.currentTimeMillis() - startMillis; + assertTrue("TotalMillis=" + totalMillis, totalMillis < 200); + + assertThat(result.get(), nullValue()); + + startMillis = System.currentTimeMillis(); + new Thread(() -> { + try { + Thread.sleep(30); + } catch (InterruptedException e) { + logger.error("", e); + } + jedis.lpush("foo", "bar"); + }).start(); + + result = pipe.blpop(1.2, "foo"); + pipe.sync(); + + totalMillis = System.currentTimeMillis() - startMillis; + assertTrue("TotalMillis=" + totalMillis, totalMillis < 200); + + assertThat(result.get().getKey(), equalTo("foo")); + assertThat(result.get().getValue(), equalTo("bar")); + } + + @Test + public void brpop() { + Response> result1 = pipe.brpop(1, "foo"); + + pipe.lpush("foo", "bar"); + + Response> result2 = pipe.brpop(1, "foo"); + + // Multi keys + Response> result3 = pipe.brpop(1, "foo", "foo1"); + + pipe.lpush("foo", "bar"); + pipe.lpush("foo1", "bar1"); + + Response> result4 = pipe.brpop(1, "foo1", "foo"); + + pipe.sync(); + + assertThat(result1.get(), nullValue()); + assertThat(result2.get(), contains("foo", "bar")); + assertThat(result3.get(), nullValue()); + assertThat(result4.get(), contains("foo1", "bar1")); + + // Binary + pipe.lpush(bfoo, bbar); + + Response> bresult1 = pipe.brpop(1, bfoo); + + // Binary Multi keys + Response> bresult2 = pipe.brpop(1, bfoo, bfoo1); + + pipe.lpush(bfoo, bbar); + pipe.lpush(bfoo1, bcar); + + Response> bresult3 = pipe.brpop(1, bfoo1, bfoo); + + pipe.sync(); + + assertThat(bresult1.get(), contains(bfoo, bbar)); + assertThat(bresult2.get(), nullValue()); + assertThat(bresult3.get(), contains(bfoo1, bcar)); + } + + @Test + public void brpopDouble() { + Response> result1 = pipe.brpop(0.1, "foo"); + + pipe.lpush("foo", "bar"); + + Response> result2 = pipe.brpop(3.2, "foo"); + + // Multi keys + Response> result3 = pipe.brpop(0.18, "foo", "foo1"); + + pipe.lpush("foo", "bar"); + pipe.lpush("foo1", "bar1"); + + Response> result4 = pipe.brpop(1d, "foo1", "foo"); + + pipe.sync(); + + assertThat(result1.get(), nullValue()); + assertThat(result2.get(), equalTo(new KeyValue<>("foo", "bar"))); + assertThat(result3.get(), nullValue()); + assertThat(result4.get(), equalTo(new KeyValue<>("foo1", "bar1"))); + + // Binary + pipe.lpush(bfoo, bbar); + + Response> bresult1 = pipe.brpop(3.12, bfoo); + + // Binary Multi keys + Response> bresult2 = pipe.brpop(0.11, bfoo, bfoo1); + + pipe.lpush(bfoo, bbar); + pipe.lpush(bfoo1, bcar); + + Response> bresult3 = pipe.brpop(1d, bfoo1, bfoo); + + pipe.sync(); + + assertThat(bresult1.get().getKey(), equalTo(bfoo)); + assertThat(bresult1.get().getValue(), equalTo(bbar)); + assertThat(bresult2.get(), nullValue()); + assertThat(bresult3.get().getKey(), equalTo(bfoo1)); + assertThat(bresult3.get().getValue(), equalTo(bcar)); + } + + @Test + public void brpopDoubleWithSleep() { + long startMillis, totalMillis; + + startMillis = System.currentTimeMillis(); + + Response> result = pipe.brpop(0.04, "foo"); + pipe.sync(); + + totalMillis = System.currentTimeMillis() - startMillis; + assertTrue("TotalMillis=" + totalMillis, totalMillis < 200); + + assertThat(result.get(), nullValue()); + + startMillis = System.currentTimeMillis(); + new Thread(() -> { + try { + Thread.sleep(30); + } catch (InterruptedException e) { + logger.error("", e); + } + jedis.lpush("foo", "bar"); + }).start(); + + result = pipe.brpop(1.2, "foo"); + pipe.sync(); + + totalMillis = System.currentTimeMillis() - startMillis; + assertTrue("TotalMillis=" + totalMillis, totalMillis < 200); + + assertThat(result.get().getKey(), equalTo("foo")); + assertThat(result.get().getValue(), equalTo("bar")); + } + + @Test + public void lpushx() { + pipe.lpushx("foo", "bar"); + pipe.lpush("foo", "a"); + pipe.lpushx("foo", "b"); + + assertThat(pipe.syncAndReturnAll(), contains( + 0L, + 1L, + 2L + )); + + // Binary + pipe.lpushx(bfoo, bbar); + pipe.lpush(bfoo, bA); + pipe.lpushx(bfoo, bB); + + assertThat(pipe.syncAndReturnAll(), contains( + 0L, + 1L, + 2L + )); + } + + @Test + public void rpushx() { + pipe.rpushx("foo", "bar"); + pipe.lpush("foo", "a"); + pipe.rpushx("foo", "b"); + + assertThat(pipe.syncAndReturnAll(), contains( + 0L, + 1L, + 2L + )); + + // Binary + pipe.rpushx(bfoo, bbar); + pipe.lpush(bfoo, bA); + pipe.rpushx(bfoo, bB); + + assertThat(pipe.syncAndReturnAll(), contains( + 0L, + 1L, + 2L + )); + } + + @Test + public void linsert() { + Response result1 = pipe.linsert("foo", ListPosition.BEFORE, "bar", "car"); + + pipe.lpush("foo", "a"); + + Response result2 = pipe.linsert("foo", ListPosition.AFTER, "a", "b"); + + Response> range = pipe.lrange("foo", 0, 100); + + Response result3 = pipe.linsert("foo", ListPosition.BEFORE, "bar", "car"); + + pipe.sync(); + + assertThat(result1.get(), equalTo(0L)); + assertThat(result2.get(), equalTo(2L)); + assertThat(range.get(), contains("a", "b")); + assertThat(result3.get(), equalTo(-1L)); + + // Binary + Response bresult1 = pipe.linsert(bfoo, ListPosition.BEFORE, bbar, bcar); + + pipe.lpush(bfoo, bA); + + Response bresult2 = pipe.linsert(bfoo, ListPosition.AFTER, bA, bB); + + Response> brange = pipe.lrange(bfoo, 0, 100); + + Response bresult3 = pipe.linsert(bfoo, ListPosition.BEFORE, bbar, bcar); + + pipe.sync(); + + assertThat(bresult1.get(), equalTo(0L)); + assertThat(bresult2.get(), equalTo(2L)); + assertThat(brange.get(), contains(bA, bB)); + assertThat(bresult3.get(), equalTo(-1L)); + } + + @Test + public void brpoplpush() { + new Thread(new Runnable() { + @Override + public void run() { + try { + Thread.sleep(100); + } catch (InterruptedException e) { + logger.error("", e); + } + jedis.lpush("foo", "a"); + } + }).start(); + + Response element = pipe.brpoplpush("foo", "bar", 0); + Response len = pipe.llen("bar"); + Response> range = pipe.lrange("bar", 0, -1); + + pipe.sync(); + + assertThat(element.get(), equalTo("a")); + assertThat(len.get(), equalTo(1L)); + assertThat(range.get(), contains("a")); + + // Binary + + new Thread(new Runnable() { + @Override + public void run() { + try { + Thread.sleep(100); + } catch (InterruptedException e) { + logger.error("", e); + } + jedis.lpush(bfoo, bA); + } + }).start(); + + Response belement = pipe.brpoplpush(bfoo, bbar, 0); + Response blen = pipe.llen(bbar); + Response> brange = pipe.lrange(bbar, 0, -1); + + pipe.sync(); + + assertThat(belement.get(), equalTo(bA)); + assertThat(blen.get(), equalTo(1L)); + assertThat(brange.get(), contains(bA)); + } + + @Test + public void lpos() { + pipe.rpush("foo", "a"); + pipe.rpush("foo", "b"); + pipe.rpush("foo", "c"); + pipe.sync(); + + pipe.lpos("foo", "b"); + pipe.lpos("foo", "d"); + + assertThat(pipe.syncAndReturnAll(), contains( + equalTo(1L), + nullValue() + )); + + pipe.rpush("foo", "a"); + pipe.rpush("foo", "b"); + pipe.rpush("foo", "b"); + pipe.sync(); + + pipe.lpos("foo", "b", LPosParams.lPosParams()); + pipe.lpos("foo", "b", LPosParams.lPosParams().rank(3)); + pipe.lpos("foo", "b", LPosParams.lPosParams().rank(-2)); + pipe.lpos("foo", "b", LPosParams.lPosParams().rank(-5)); + pipe.lpos("foo", "b", LPosParams.lPosParams().rank(1).maxlen(2)); + pipe.lpos("foo", "b", LPosParams.lPosParams().rank(2).maxlen(2)); + pipe.lpos("foo", "b", LPosParams.lPosParams().rank(-2).maxlen(2)); + + assertThat(pipe.syncAndReturnAll(), contains( + equalTo(1L), + equalTo(5L), + equalTo(4L), + nullValue(), + equalTo(1L), + nullValue(), + equalTo(4L) + )); + + Response> posList1 = pipe.lpos("foo", "b", LPosParams.lPosParams(), 2); + Response> posList2 = pipe.lpos("foo", "b", LPosParams.lPosParams(), 0); + Response> posList3 = pipe.lpos("foo", "b", LPosParams.lPosParams().rank(2), 0); + Response> posList4 = pipe.lpos("foo", "b", LPosParams.lPosParams().rank(2).maxlen(5), 0); + Response> posList5 = pipe.lpos("foo", "b", LPosParams.lPosParams().rank(-2), 0); + Response> posList6 = pipe.lpos("foo", "b", LPosParams.lPosParams().rank(-1).maxlen(5), 2); + + pipe.sync(); + + assertThat(posList1.get(), contains(1L, 4L)); + assertThat(posList2.get(), contains(1L, 4L, 5L)); + assertThat(posList3.get(), contains(4L, 5L)); + assertThat(posList4.get(), contains(4L)); + assertThat(posList5.get(), contains(4L, 1L)); + assertThat(posList6.get(), contains(5L, 4L)); + + // Binary + pipe.rpush(bfoo, bA); + pipe.rpush(bfoo, bB); + pipe.rpush(bfoo, bC); + pipe.sync(); + + pipe.lpos(bfoo, bB); + pipe.lpos(bfoo, b3); + + assertThat(pipe.syncAndReturnAll(), contains( + equalTo(1L), + nullValue() + )); + + pipe.rpush(bfoo, bA); + pipe.rpush(bfoo, bB); + pipe.rpush(bfoo, bA); + pipe.sync(); + + pipe.lpos(bfoo, bB, LPosParams.lPosParams().rank(2)); + pipe.lpos(bfoo, bB, LPosParams.lPosParams().rank(-2).maxlen(5)); + + assertThat(pipe.syncAndReturnAll(), contains( + equalTo(4L), + equalTo(1L) + )); + + Response> bposList1 = pipe.lpos(bfoo, bA, LPosParams.lPosParams().maxlen(6), 0); + Response> bposList2 = pipe.lpos(bfoo, bA, LPosParams.lPosParams().maxlen(6).rank(2), 1); + + pipe.sync(); + + assertThat(bposList1.get(), contains(0L, 3L, 5L)); + assertThat(bposList2.get(), contains(3L)); + } + + @Test + public void lmove() { + pipe.rpush("foo", "bar1", "bar2", "bar3"); + + Response item1 = pipe.lmove("foo", "bar", ListDirection.RIGHT, ListDirection.LEFT); + Response> range1 = pipe.lrange("bar", 0, -1); + Response> range2 = pipe.lrange("foo", 0, -1); + + pipe.sync(); + + assertThat(item1.get(), equalTo("bar3")); + assertThat(range1.get(), contains("bar3")); + assertThat(range2.get(), contains("bar1", "bar2")); + + // Binary + pipe.rpush(bfoo, b1, b2, b3); + + Response bitem1 = pipe.lmove(bfoo, bbar, ListDirection.RIGHT, ListDirection.LEFT); + Response> brange1 = pipe.lrange(bbar, 0, -1); + Response> brange2 = pipe.lrange(bfoo, 0, -1); + + pipe.sync(); + + assertThat(bitem1.get(), equalTo(b3)); + assertThat(brange1.get(), contains(b3)); + assertThat(brange2.get(), contains(b1, b2)); + } + + @Test + public void blmove() { + new Thread(() -> { + try { + Thread.sleep(100); + } catch (InterruptedException e) { + logger.error("", e); + } + jedis.rpush("foo", "bar1", "bar2", "bar3"); + }).start(); + + Response response = pipe.blmove("foo", "bar", ListDirection.RIGHT, ListDirection.LEFT, 0); + Response> range1 = pipe.lrange("bar", 0, -1); + Response> range2 = pipe.lrange("foo", 0, -1); + + pipe.sync(); + + assertThat(response.get(), equalTo("bar3")); + assertThat(range1.get(), contains("bar3")); + assertThat(range2.get(), contains("bar1", "bar2")); + + // Binary + new Thread(() -> { + try { + Thread.sleep(100); + } catch (InterruptedException e) { + logger.error("", e); + } + jedis.rpush(bfoo, b1, b2, b3); + }).start(); + + Response bresponse = pipe.blmove(bfoo, bbar, ListDirection.RIGHT, ListDirection.LEFT, 0); + Response> brange1 = pipe.lrange(bbar, 0, -1); + Response> brange2 = pipe.lrange(bfoo, 0, -1); + + pipe.sync(); + + assertThat(bresponse.get(), equalTo(b3)); + assertThat(brange1.get(), contains(b3)); + assertThat(brange2.get(), contains(b1, b2)); + } + + @Test + public void lmpop() { + String mylist1 = "mylist1"; + String mylist2 = "mylist2"; + + // add elements to list + pipe.lpush(mylist1, "one1", "two1", "three1", "four1", "five1"); + pipe.lpush(mylist2, "one2", "two2", "three2", "four2", "five2"); + + Response>> elements1 = pipe.lmpop(ListDirection.LEFT, mylist1, mylist2); + Response>> elements2 = pipe.lmpop(ListDirection.LEFT, 5, mylist1, mylist2); + Response>> elements3 = pipe.lmpop(ListDirection.RIGHT, 100, mylist1, mylist2); + Response>> elements4 = pipe.lmpop(ListDirection.RIGHT, mylist1, mylist2); + + pipe.sync(); + + assertThat(elements1.get().getKey(), equalTo(mylist1)); + assertThat(elements1.get().getValue(), contains("five1")); + + assertThat(elements2.get().getKey(), equalTo(mylist1)); + assertThat(elements2.get().getValue(), contains("four1", "three1", "two1", "one1")); + + assertThat(elements3.get().getKey(), equalTo(mylist2)); + assertThat(elements3.get().getValue(), contains("one2", "two2", "three2", "four2", "five2")); + + assertThat(elements4.get(), nullValue()); + } + + @Test + public void blmpopSimple() { + String mylist1 = "mylist1"; + String mylist2 = "mylist2"; + + // add elements to list + pipe.lpush(mylist1, "one1", "two1", "three1", "four1", "five1"); + pipe.lpush(mylist2, "one2", "two2", "three2", "four2", "five2"); + + Response>> elements1 = pipe.blmpop(1L, ListDirection.LEFT, mylist1, mylist2); + Response>> elements2 = pipe.blmpop(1L, ListDirection.LEFT, 5, mylist1, mylist2); + Response>> elements3 = pipe.blmpop(1L, ListDirection.RIGHT, 100, mylist1, mylist2); + Response>> elements4 = pipe.blmpop(1L, ListDirection.RIGHT, mylist1, mylist2); + + pipe.sync(); + + assertThat(elements1.get().getKey(), equalTo(mylist1)); + assertThat(elements1.get().getValue(), contains("five1")); + + assertThat(elements2.get().getKey(), equalTo(mylist1)); + assertThat(elements2.get().getValue(), contains("four1", "three1", "two1", "one1")); + + assertThat(elements3.get().getKey(), equalTo(mylist2)); + assertThat(elements3.get().getValue(), contains("one2", "two2", "three2", "four2", "five2")); + + assertThat(elements4.get(), nullValue()); + } +} diff --git a/src/test/java/redis/clients/jedis/commands/unified/pipeline/SetPipelineCommandsTest.java b/src/test/java/redis/clients/jedis/commands/unified/pipeline/SetPipelineCommandsTest.java new file mode 100644 index 00000000000..0dd0a185596 --- /dev/null +++ b/src/test/java/redis/clients/jedis/commands/unified/pipeline/SetPipelineCommandsTest.java @@ -0,0 +1,659 @@ +package redis.clients.jedis.commands.unified.pipeline; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.anyOf; +import static org.hamcrest.Matchers.contains; +import static org.hamcrest.Matchers.containsInAnyOrder; +import static org.hamcrest.Matchers.empty; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.hasSize; +import static org.hamcrest.Matchers.not; +import static org.hamcrest.Matchers.nullValue; +import static redis.clients.jedis.params.ScanParams.SCAN_POINTER_START; +import static redis.clients.jedis.params.ScanParams.SCAN_POINTER_START_BINARY; +import static redis.clients.jedis.util.AssertUtil.assertByteArrayCollectionContainsAll; +import static redis.clients.jedis.util.AssertUtil.assertByteArraySetEquals; +import static redis.clients.jedis.util.AssertUtil.assertCollectionContainsAll; +import static redis.clients.jedis.util.ByteArrayUtil.byteArrayCollectionRemoveAll; + +import java.util.HashSet; +import java.util.List; +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.Response; +import redis.clients.jedis.params.ScanParams; +import redis.clients.jedis.resps.ScanResult; + +@RunWith(Parameterized.class) +public class SetPipelineCommandsTest extends PipelineCommandsTestBase { + + final byte[] bfoo = { 0x01, 0x02, 0x03, 0x04 }; + final byte[] bbar = { 0x05, 0x06, 0x07, 0x08 }; + final byte[] bcar = { 0x09, 0x0A, 0x0B, 0x0C }; + final byte[] ba = { 0x0A }; + final byte[] bb = { 0x0B }; + final byte[] bc = { 0x0C }; + final byte[] bd = { 0x0D }; + final byte[] bx = { 0x42 }; + + final byte[] bbar1 = { 0x05, 0x06, 0x07, 0x08, 0x0A }; + final byte[] bbar2 = { 0x05, 0x06, 0x07, 0x08, 0x0B }; + final byte[] bbar3 = { 0x05, 0x06, 0x07, 0x08, 0x0C }; + final byte[] bbarstar = { 0x05, 0x06, 0x07, 0x08, '*' }; + + public SetPipelineCommandsTest(RedisProtocol protocol) { + super(protocol); + } + + @Test + public void sadd() { + pipe.sadd("foo", "a"); + pipe.sadd("foo", "a"); + + assertThat(pipe.syncAndReturnAll(), contains( + 1L, + 0L + )); + + pipe.sadd(bfoo, ba); + pipe.sadd(bfoo, ba); + + assertThat(pipe.syncAndReturnAll(), contains( + 1L, + 0L + )); + } + + @Test + public void smembers() { + pipe.sadd("foo", "a"); + pipe.sadd("foo", "b"); + + Response> members = pipe.smembers("foo"); + + pipe.sync(); + + assertThat(members.get(), containsInAnyOrder("a", "b")); + + // Binary + pipe.sadd(bfoo, ba); + pipe.sadd(bfoo, bb); + + Response> bmembers = pipe.smembers(bfoo); + + pipe.sync(); + + assertThat(bmembers.get(), containsInAnyOrder(ba, bb)); + } + + @Test + public void srem() { + pipe.sadd("foo", "a"); + pipe.sadd("foo", "b"); + + Response status1 = pipe.srem("foo", "a"); + Response> members = pipe.smembers("foo"); + Response status2 = pipe.srem("foo", "bar"); + + pipe.sync(); + + assertThat(status1.get(), equalTo(1L)); + assertThat(members.get(), containsInAnyOrder("b")); + assertThat(status2.get(), equalTo(0L)); + + // Binary + + pipe.sadd(bfoo, ba); + pipe.sadd(bfoo, bb); + + Response bstatus1 = pipe.srem(bfoo, ba); + Response> bmembers = pipe.smembers(bfoo); + Response bstatus2 = pipe.srem(bfoo, bbar); + + pipe.sync(); + + assertThat(bstatus1.get(), equalTo(1L)); + assertThat(bmembers.get(), containsInAnyOrder(bb)); + assertThat(bstatus2.get(), equalTo(0L)); + } + + @Test + public void spop() { + pipe.sadd("foo", "a"); + pipe.sadd("foo", "b"); + + Response member1 = pipe.spop("foo"); + Response> members = pipe.smembers("foo"); + Response member2 = pipe.spop("bar"); + + pipe.sync(); + + assertThat(member1.get(), anyOf(equalTo("a"), equalTo("b"))); + assertThat(members.get(), hasSize(1)); + assertThat(member2.get(), nullValue()); + + // Binary + pipe.sadd(bfoo, ba); + pipe.sadd(bfoo, bb); + + Response bmember1 = pipe.spop(bfoo); + Response> bmembers = pipe.smembers(bfoo); + Response bmember2 = pipe.spop(bbar); + + pipe.sync(); + + assertThat(bmember1.get(), anyOf(equalTo(ba), equalTo(bb))); + assertThat(bmembers.get(), hasSize(1)); + assertThat(bmember2.get(), nullValue()); + } + + @Test + public void spopWithCount() { + pipe.sadd("foo", "a"); + pipe.sadd("foo", "b"); + pipe.sadd("foo", "c"); + + Response> members1 = pipe.spop("foo", 2); + Response> members2 = pipe.spop("foo", 2); + Response> members3 = pipe.spop("foo", 2); + + pipe.sync(); + + assertThat(members1.get(), hasSize(2)); + assertThat(members2.get(), hasSize(1)); + assertThat(members3.get(), empty()); + + Set superSet = new HashSet<>(); + superSet.add("c"); + superSet.add("b"); + superSet.add("a"); + + assertCollectionContainsAll(superSet, members1.get()); + superSet.removeAll(members1.get()); + + assertThat(members2.get(), equalTo(superSet)); + + // Binary + pipe.sadd(bfoo, ba); + pipe.sadd(bfoo, bb); + pipe.sadd(bfoo, bc); + + Response> bmembers1 = pipe.spop(bfoo, 2); + Response> bmembers2 = pipe.spop(bfoo, 2); + Response> bmembers3 = pipe.spop(bfoo, 2); + + pipe.sync(); + + assertThat(bmembers1.get(), hasSize(2)); + assertThat(bmembers2.get(), hasSize(1)); + assertThat(bmembers3.get(), empty()); + + Set bsuperSet = new HashSet<>(); + bsuperSet.add(bc); + bsuperSet.add(bb); + bsuperSet.add(ba); + + assertByteArrayCollectionContainsAll(bsuperSet, bmembers1.get()); + byteArrayCollectionRemoveAll(bsuperSet, bmembers1.get()); + + assertByteArraySetEquals(bsuperSet, bmembers2.get()); + } + + @Test + public void smove() { + pipe.sadd("foo", "a"); + pipe.sadd("foo", "b"); + + pipe.sadd("bar", "c"); + + Response status1 = pipe.smove("foo", "bar", "a"); + Response> srcMembers = pipe.smembers("foo"); + Response> dstMembers = pipe.smembers("bar"); + Response status2 = pipe.smove("foo", "bar", "a"); + + pipe.sync(); + + assertThat(status1.get(), equalTo(1L)); + assertThat(srcMembers.get(), containsInAnyOrder("b")); + assertThat(dstMembers.get(), containsInAnyOrder("a", "c")); + assertThat(status2.get(), equalTo(0L)); + + // Binary + pipe.sadd(bfoo, ba); + pipe.sadd(bfoo, bb); + + pipe.sadd(bbar, bc); + + Response bstatus1 = pipe.smove(bfoo, bbar, ba); + Response> bsrcMembers = pipe.smembers(bfoo); + Response> bdstMembers = pipe.smembers(bbar); + Response bstatus2 = pipe.smove(bfoo, bbar, ba); + + pipe.sync(); + + assertThat(bstatus1.get(), equalTo(1L)); + assertThat(bsrcMembers.get(), containsInAnyOrder(bb)); + assertThat(bdstMembers.get(), containsInAnyOrder(ba, bc)); + assertThat(bstatus2.get(), equalTo(0L)); + } + + @Test + public void scard() { + pipe.sadd("foo", "a"); + pipe.sadd("foo", "b"); + pipe.sync(); + + pipe.scard("foo"); + pipe.scard("bar"); + + assertThat(pipe.syncAndReturnAll(), contains( + 2L, + 0L + )); + + // Binary + pipe.sadd(bfoo, ba); + pipe.sadd(bfoo, bb); + pipe.sync(); + + pipe.scard(bfoo); + pipe.scard(bbar); + + assertThat(pipe.syncAndReturnAll(), contains( + 2L, + 0L + )); + } + + @Test + public void sismember() { + pipe.sadd("foo", "a"); + pipe.sadd("foo", "b"); + pipe.sync(); + + pipe.sismember("foo", "a"); + pipe.sismember("foo", "c"); + + assertThat(pipe.syncAndReturnAll(), contains( + true, + false + )); + + // Binary + pipe.sadd(bfoo, ba); + pipe.sadd(bfoo, bb); + pipe.sync(); + + pipe.sismember(bfoo, ba); + pipe.sismember(bfoo, bc); + + assertThat(pipe.syncAndReturnAll(), contains( + true, + false + )); + } + + @Test + public void smismember() { + pipe.sadd("foo", "a", "b"); + + Response> response = pipe.smismember("foo", "a", "c"); + + pipe.sync(); + + assertThat(response.get(), contains(true, false)); + + // Binary + pipe.sadd(bfoo, ba, bb); + + Response> bresponse = pipe.smismember(bfoo, ba, bc); + + pipe.sync(); + + assertThat(bresponse.get(), contains(true, false)); + } + + @Test + public void sinter() { + pipe.sadd("foo", "a"); + pipe.sadd("foo", "b"); + + pipe.sadd("bar", "b"); + pipe.sadd("bar", "c"); + + Response> intersection = pipe.sinter("foo", "bar"); + + pipe.sync(); + + assertThat(intersection.get(), containsInAnyOrder("b")); + + // Binary + pipe.sadd(bfoo, ba); + pipe.sadd(bfoo, bb); + + pipe.sadd(bbar, bb); + pipe.sadd(bbar, bc); + + Response> bintersection = pipe.sinter(bfoo, bbar); + + pipe.sync(); + + assertThat(bintersection.get(), containsInAnyOrder(bb)); + } + + @Test + public void sinterstore() { + pipe.sadd("foo", "a"); + pipe.sadd("foo", "b"); + + pipe.sadd("bar", "b"); + pipe.sadd("bar", "c"); + + Response status = pipe.sinterstore("car", "foo", "bar"); + Response> members = pipe.smembers("car"); + + pipe.sync(); + + assertThat(status.get(), equalTo(1L)); + assertThat(members.get(), containsInAnyOrder("b")); + + // Binary + pipe.sadd(bfoo, ba); + pipe.sadd(bfoo, bb); + + pipe.sadd(bbar, bb); + pipe.sadd(bbar, bc); + + Response bstatus = pipe.sinterstore(bcar, bfoo, bbar); + Response> bmembers = pipe.smembers(bcar); + + pipe.sync(); + + assertThat(bstatus.get(), equalTo(1L)); + assertThat(bmembers.get(), containsInAnyOrder(bb)); + } + + @Test + public void sintercard() { + pipe.sadd("foo", "a"); + pipe.sadd("foo", "b"); + + pipe.sadd("bar", "a"); + pipe.sadd("bar", "b"); + pipe.sadd("bar", "c"); + + Response card = pipe.sintercard("foo", "bar"); + Response limitedCard = pipe.sintercard(1, "foo", "bar"); + + pipe.sync(); + + assertThat(card.get(), equalTo(2L)); + assertThat(limitedCard.get(), equalTo(1L)); + + // Binary + pipe.sadd(bfoo, ba); + pipe.sadd(bfoo, bb); + + pipe.sadd(bbar, ba); + pipe.sadd(bbar, bb); + pipe.sadd(bbar, bc); + + Response bcard = pipe.sintercard(bfoo, bbar); + Response blimitedCard = pipe.sintercard(1, bfoo, bbar); + + pipe.sync(); + + assertThat(bcard.get(), equalTo(2L)); + assertThat(blimitedCard.get(), equalTo(1L)); + } + + @Test + public void sunion() { + pipe.sadd("foo", "a"); + pipe.sadd("foo", "b"); + + pipe.sadd("bar", "b"); + pipe.sadd("bar", "c"); + + Response> union = pipe.sunion("foo", "bar"); + + pipe.sync(); + + assertThat(union.get(), containsInAnyOrder("a", "b", "c")); + + // Binary + pipe.sadd(bfoo, ba); + pipe.sadd(bfoo, bb); + + pipe.sadd(bbar, bb); + pipe.sadd(bbar, bc); + + Response> bunion = pipe.sunion(bfoo, bbar); + + pipe.sync(); + + assertThat(bunion.get(), containsInAnyOrder(ba, bb, bc)); + } + + @Test + public void sunionstore() { + pipe.sadd("foo", "a"); + pipe.sadd("foo", "b"); + + pipe.sadd("bar", "b"); + pipe.sadd("bar", "c"); + + Response status = pipe.sunionstore("car", "foo", "bar"); + Response> members = pipe.smembers("car"); + + pipe.sync(); + + assertThat(status.get(), equalTo(3L)); + assertThat(members.get(), containsInAnyOrder("a", "b", "c")); + + // Binary + pipe.sadd(bfoo, ba); + pipe.sadd(bfoo, bb); + + pipe.sadd(bbar, bb); + pipe.sadd(bbar, bc); + + Response bstatus = pipe.sunionstore(bcar, bfoo, bbar); + Response> bmembers = pipe.smembers(bcar); + + pipe.sync(); + + assertThat(bstatus.get(), equalTo(3L)); + assertThat(bmembers.get(), containsInAnyOrder(ba, bb, bc)); + } + + @Test + public void sdiff() { + pipe.sadd("foo", "x"); + pipe.sadd("foo", "a"); + pipe.sadd("foo", "b"); + pipe.sadd("foo", "c"); + + pipe.sadd("bar", "c"); + + pipe.sadd("car", "a"); + pipe.sadd("car", "d"); + + Response> diff = pipe.sdiff("foo", "bar", "car"); + + pipe.sync(); + + assertThat(diff.get(), containsInAnyOrder("b", "x")); + + // Binary + pipe.sadd(bfoo, bx); + pipe.sadd(bfoo, ba); + pipe.sadd(bfoo, bb); + pipe.sadd(bfoo, bc); + + pipe.sadd(bbar, bc); + + pipe.sadd(bcar, ba); + pipe.sadd(bcar, bd); + + Response> bdiff = pipe.sdiff(bfoo, bbar, bcar); + + pipe.sync(); + + assertThat(bdiff.get(), containsInAnyOrder(bb, bx)); + } + + @Test + public void sdiffstore() { + pipe.sadd("foo", "x"); + pipe.sadd("foo", "a"); + pipe.sadd("foo", "b"); + pipe.sadd("foo", "c"); + + pipe.sadd("bar", "c"); + + pipe.sadd("car", "a"); + pipe.sadd("car", "d"); + + Response status = pipe.sdiffstore("tar", "foo", "bar", "car"); + Response> members = pipe.smembers("tar"); + + pipe.sync(); + + assertThat(status.get(), equalTo(2L)); + assertThat(members.get(), containsInAnyOrder("b", "x")); + + // Binary + pipe.sadd(bfoo, bx); + pipe.sadd(bfoo, ba); + pipe.sadd(bfoo, bb); + pipe.sadd(bfoo, bc); + + pipe.sadd(bbar, bc); + + pipe.sadd(bcar, ba); + pipe.sadd(bcar, bd); + + Response bstatus = pipe.sdiffstore("tar".getBytes(), bfoo, bbar, bcar); + Response> bmembers = pipe.smembers("tar".getBytes()); + + pipe.sync(); + + assertThat(bstatus.get(), equalTo(2L)); + assertThat(bmembers.get(), containsInAnyOrder(bb, bx)); + } + + @Test + public void srandmember() { + pipe.sadd("foo", "a"); + pipe.sadd("foo", "b"); + + Response member1 = pipe.srandmember("foo"); + Response> allMembers = pipe.smembers("foo"); + Response> members1 = pipe.srandmember("foo", 2); + Response member2 = pipe.srandmember("bar"); + Response> members2 = pipe.srandmember("bar", 2); + + pipe.sync(); + + assertThat(member1.get(), anyOf(equalTo("a"), equalTo("b"))); + assertThat(allMembers.get(), containsInAnyOrder("a", "b")); + assertThat(members1.get(), containsInAnyOrder("a", "b")); + assertThat(member2.get(), nullValue()); + assertThat(members2.get(), empty()); + + // Binary + pipe.sadd(bfoo, ba); + pipe.sadd(bfoo, bb); + + Response bmember1 = pipe.srandmember(bfoo); + Response> bmembers1 = pipe.srandmember(bfoo, 2); + Response bmember2 = pipe.srandmember(bbar); + Response> bmembers2 = pipe.srandmember("bbar", 2); + + pipe.sync(); + + assertThat(bmember1.get(), anyOf(equalTo(ba), equalTo(bb))); + assertThat(bmembers1.get(), containsInAnyOrder(ba, bb)); + assertThat(bmember2.get(), nullValue()); + assertThat(bmembers2.get(), empty()); + } + + @Test + public void sscan() { + pipe.sadd("foo", "a", "b"); + + Response> result = pipe.sscan("foo", SCAN_POINTER_START); + + pipe.sync(); + + assertThat(result.get().getCursor(), equalTo(SCAN_POINTER_START)); + assertThat(result.get().getResult(), not(empty())); + + // binary + pipe.sadd(bfoo, ba, bb); + + Response> bResult = pipe.sscan(bfoo, SCAN_POINTER_START_BINARY); + + pipe.sync(); + + assertThat(bResult.get().getCursor(), equalTo(SCAN_POINTER_START)); + assertThat(bResult.get().getResult(), not(empty())); + } + + @Test + public void sscanMatch() { + ScanParams params = new ScanParams(); + params.match("a*"); + + pipe.sadd("foo", "b", "a", "aa"); + Response> result = pipe.sscan("foo", SCAN_POINTER_START, params); + + pipe.sync(); + + assertThat(result.get().getCursor(), equalTo(SCAN_POINTER_START)); + assertThat(result.get().getResult(), not(empty())); + + // binary + pipe.sadd(bfoo, bbar1, bbar2, bbar3); + + params = new ScanParams(); + params.match(bbarstar); + + Response> bResult = pipe.sscan(bfoo, SCAN_POINTER_START_BINARY, params); + + pipe.sync(); + + assertThat(bResult.get().getCursor(), equalTo(SCAN_POINTER_START)); + assertThat(bResult.get().getResult(), not(empty())); + } + + @Test + public void sscanCount() { + ScanParams params = new ScanParams(); + params.count(2); + + pipe.sadd("foo", "a1", "a2", "a3", "a4", "a5"); + + Response> result = pipe.sscan("foo", SCAN_POINTER_START, params); + + pipe.sync(); + + assertThat(result.get().getResult(), not(empty())); + + // binary + pipe.sadd(bfoo, bbar1, bbar2, bbar3); + + params = new ScanParams(); + params.count(2); + + Response> bResult = pipe.sscan(bfoo, SCAN_POINTER_START_BINARY, params); + + pipe.sync(); + assertThat(bResult.get().getResult(), not(empty())); + } +} From 47df10ec1b62156787352e7a1aa95953e84e07f4 Mon Sep 17 00:00:00 2001 From: Gabriel Erzse Date: Fri, 22 Mar 2024 15:07:43 +0200 Subject: [PATCH 22/33] Fix UnifiedJedis pexpireAt glitch (#3782) One of the versions of UnifiedJedis.pexpireAt methods is calling the wrong method on CommandObjects. Co-authored-by: Gabriel Erzse --- src/main/java/redis/clients/jedis/UnifiedJedis.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/redis/clients/jedis/UnifiedJedis.java b/src/main/java/redis/clients/jedis/UnifiedJedis.java index 14e67a0fa17..138300c451e 100644 --- a/src/main/java/redis/clients/jedis/UnifiedJedis.java +++ b/src/main/java/redis/clients/jedis/UnifiedJedis.java @@ -457,7 +457,7 @@ public long pexpireAt(byte[] key, long millisecondsTimestamp) { @Override public long pexpireAt(byte[] key, long millisecondsTimestamp, ExpiryOption expiryOption) { - return executeCommand(commandObjects.expireAt(key, millisecondsTimestamp, expiryOption)); + return executeCommand(commandObjects.pexpireAt(key, millisecondsTimestamp, expiryOption)); } @Override From e0d600c94e0b87f6da9aac7476afcbbc4e11daf6 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 25 Mar 2024 11:26:35 +0600 Subject: [PATCH 23/33] Bump org.apache.maven.plugins:maven-gpg-plugin from 3.2.0 to 3.2.1 (#3785) Bumps [org.apache.maven.plugins:maven-gpg-plugin](https://github.com/apache/maven-gpg-plugin) from 3.2.0 to 3.2.1. - [Release notes](https://github.com/apache/maven-gpg-plugin/releases) - [Commits](https://github.com/apache/maven-gpg-plugin/compare/maven-gpg-plugin-3.2.0...maven-gpg-plugin-3.2.1) --- updated-dependencies: - dependency-name: org.apache.maven.plugins:maven-gpg-plugin dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 71595dc211f..3314c506b18 100644 --- a/pom.xml +++ b/pom.xml @@ -300,7 +300,7 @@ maven-gpg-plugin - 3.2.0 + 3.2.1 --pinentry-mode From 89b1ac486c8781db5ad4cc5874602c0f08722143 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 25 Mar 2024 11:26:57 +0600 Subject: [PATCH 24/33] Bump org.apache.maven.plugins:maven-compiler-plugin from 3.12.1 to 3.13.0 (#3786) Bump org.apache.maven.plugins:maven-compiler-plugin Bumps [org.apache.maven.plugins:maven-compiler-plugin](https://github.com/apache/maven-compiler-plugin) from 3.12.1 to 3.13.0. - [Release notes](https://github.com/apache/maven-compiler-plugin/releases) - [Commits](https://github.com/apache/maven-compiler-plugin/compare/maven-compiler-plugin-3.12.1...maven-compiler-plugin-3.13.0) --- updated-dependencies: - dependency-name: org.apache.maven.plugins:maven-compiler-plugin dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 3314c506b18..823fd4d6ef1 100644 --- a/pom.xml +++ b/pom.xml @@ -189,7 +189,7 @@ maven-compiler-plugin - 3.12.1 + 3.13.0 1.8 1.8 From b5308044a14428563526faf69050abf8bd2cb56d Mon Sep 17 00:00:00 2001 From: Tyshchenko Leonid <32874828+Lcarrot@users.noreply.github.com> Date: Mon, 25 Mar 2024 08:33:35 +0300 Subject: [PATCH 25/33] SetParams should implement equals and hashcode issue #2687 (#3728) --- .../clients/jedis/args/RawableFactory.java | 12 +++++ .../clients/jedis/params/BitPosParams.java | 15 ++++++ .../jedis/params/ClientKillParams.java | 14 +++++ .../params/CommandListFilterByParams.java | 15 ++++++ .../clients/jedis/params/FailoverParams.java | 15 ++++++ .../clients/jedis/params/GeoAddParams.java | 14 +++++ .../clients/jedis/params/GetExParams.java | 15 ++++++ .../redis/clients/jedis/params/LCSParams.java | 15 ++++++ .../clients/jedis/params/LPosParams.java | 14 +++++ .../clients/jedis/params/LolwutParams.java | 18 +++++++ .../clients/jedis/params/MigrateParams.java | 15 ++++++ .../jedis/params/ModuleLoadExParams.java | 14 +++++ .../clients/jedis/params/RestoreParams.java | 15 ++++++ .../clients/jedis/params/ScanParams.java | 14 +++++ .../redis/clients/jedis/params/SetParams.java | 16 ++++++ .../clients/jedis/params/ShutdownParams.java | 15 ++++++ .../clients/jedis/params/SortingParams.java | 18 +++++-- .../clients/jedis/params/XAddParams.java | 15 ++++++ .../jedis/params/XAutoClaimParams.java | 14 +++++ .../clients/jedis/params/XClaimParams.java | 15 ++++++ .../clients/jedis/params/XPendingParams.java | 15 ++++++ .../jedis/params/XReadGroupParams.java | 15 ++++++ .../clients/jedis/params/XReadParams.java | 15 ++++++ .../clients/jedis/params/XTrimParams.java | 15 ++++++ .../clients/jedis/params/ZAddParams.java | 14 +++++ .../clients/jedis/params/ZIncrByParams.java | 14 +++++ .../redis/clients/jedis/params/ZParams.java | 14 +++++ .../clients/jedis/params/ZRangeParams.java | 15 ++++++ .../jedis/params/BitPosParamsTest.java | 49 +++++++++++++++++ .../jedis/params/ClientKillParamsTest.java | 52 +++++++++++++++++++ .../params/CommandListFilterByParamsTest.java | 51 ++++++++++++++++++ .../jedis/params/FailoverParamsTest.java | 51 ++++++++++++++++++ .../jedis/params/GeoAddParamsTest.java | 51 ++++++++++++++++++ .../clients/jedis/params/GetExParamsTest.java | 51 ++++++++++++++++++ .../clients/jedis/params/LCSParamsTest.java | 51 ++++++++++++++++++ .../clients/jedis/params/LPosParamsTest.java | 51 ++++++++++++++++++ .../jedis/params/LolwutParamsTest.java | 51 ++++++++++++++++++ .../jedis/params/MigrateParamsTest.java | 51 ++++++++++++++++++ .../jedis/params/ModuleLoadExParamsTest.java | 51 ++++++++++++++++++ .../jedis/params/RestoreParamsTest.java | 51 ++++++++++++++++++ .../clients/jedis/params/ScanParamsTest.java | 51 ++++++++++++++++++ .../clients/jedis/params/SetParamsTest.java | 51 ++++++++++++++++++ .../jedis/params/ShutdownParamsTest.java | 51 ++++++++++++++++++ .../jedis/params/SortingParamsTest.java | 51 ++++++++++++++++++ .../clients/jedis/params/XAddParamsTest.java | 51 ++++++++++++++++++ .../jedis/params/XAutoClaimParamsTest.java | 51 ++++++++++++++++++ .../jedis/params/XClaimParamsTest.java | 51 ++++++++++++++++++ .../jedis/params/XPendingParamsTest.java | 52 +++++++++++++++++++ .../jedis/params/XReadGroupParamsTest.java | 51 ++++++++++++++++++ .../clients/jedis/params/XReadParamsTest.java | 51 ++++++++++++++++++ .../clients/jedis/params/XTrimParamsTest.java | 51 ++++++++++++++++++ .../clients/jedis/params/ZAddParamsTest.java | 51 ++++++++++++++++++ .../jedis/params/ZIncrByParamsTest.java | 51 ++++++++++++++++++ .../clients/jedis/params/ZParamsTest.java | 51 ++++++++++++++++++ .../jedis/params/ZRangeParamsTest.java | 51 ++++++++++++++++++ 55 files changed, 1788 insertions(+), 4 deletions(-) create mode 100644 src/test/java/redis/clients/jedis/params/BitPosParamsTest.java create mode 100644 src/test/java/redis/clients/jedis/params/ClientKillParamsTest.java create mode 100644 src/test/java/redis/clients/jedis/params/CommandListFilterByParamsTest.java create mode 100644 src/test/java/redis/clients/jedis/params/FailoverParamsTest.java create mode 100644 src/test/java/redis/clients/jedis/params/GeoAddParamsTest.java create mode 100644 src/test/java/redis/clients/jedis/params/GetExParamsTest.java create mode 100644 src/test/java/redis/clients/jedis/params/LCSParamsTest.java create mode 100644 src/test/java/redis/clients/jedis/params/LPosParamsTest.java create mode 100644 src/test/java/redis/clients/jedis/params/LolwutParamsTest.java create mode 100644 src/test/java/redis/clients/jedis/params/MigrateParamsTest.java create mode 100644 src/test/java/redis/clients/jedis/params/ModuleLoadExParamsTest.java create mode 100644 src/test/java/redis/clients/jedis/params/RestoreParamsTest.java create mode 100644 src/test/java/redis/clients/jedis/params/ScanParamsTest.java create mode 100644 src/test/java/redis/clients/jedis/params/SetParamsTest.java create mode 100644 src/test/java/redis/clients/jedis/params/ShutdownParamsTest.java create mode 100644 src/test/java/redis/clients/jedis/params/SortingParamsTest.java create mode 100644 src/test/java/redis/clients/jedis/params/XAddParamsTest.java create mode 100644 src/test/java/redis/clients/jedis/params/XAutoClaimParamsTest.java create mode 100644 src/test/java/redis/clients/jedis/params/XClaimParamsTest.java create mode 100644 src/test/java/redis/clients/jedis/params/XPendingParamsTest.java create mode 100644 src/test/java/redis/clients/jedis/params/XReadGroupParamsTest.java create mode 100644 src/test/java/redis/clients/jedis/params/XReadParamsTest.java create mode 100644 src/test/java/redis/clients/jedis/params/XTrimParamsTest.java create mode 100644 src/test/java/redis/clients/jedis/params/ZAddParamsTest.java create mode 100644 src/test/java/redis/clients/jedis/params/ZIncrByParamsTest.java create mode 100644 src/test/java/redis/clients/jedis/params/ZParamsTest.java create mode 100644 src/test/java/redis/clients/jedis/params/ZRangeParamsTest.java diff --git a/src/main/java/redis/clients/jedis/args/RawableFactory.java b/src/main/java/redis/clients/jedis/args/RawableFactory.java index 90bcc3c2973..8bce7f0e78d 100644 --- a/src/main/java/redis/clients/jedis/args/RawableFactory.java +++ b/src/main/java/redis/clients/jedis/args/RawableFactory.java @@ -61,6 +61,18 @@ public Raw(byte[] raw) { public byte[] getRaw() { return raw; } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + return Arrays.equals(raw, ((Raw) o).raw); + } + + @Override + public int hashCode() { + return Arrays.hashCode(raw); + } } /** diff --git a/src/main/java/redis/clients/jedis/params/BitPosParams.java b/src/main/java/redis/clients/jedis/params/BitPosParams.java index dc9d3ceea1c..c9d3ce32ddc 100644 --- a/src/main/java/redis/clients/jedis/params/BitPosParams.java +++ b/src/main/java/redis/clients/jedis/params/BitPosParams.java @@ -3,6 +3,8 @@ import redis.clients.jedis.CommandArguments; import redis.clients.jedis.args.BitCountOption; +import java.util.Objects; + public class BitPosParams implements IParams { private Long start; @@ -62,4 +64,17 @@ public void addParams(CommandArguments args) { } } } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + BitPosParams that = (BitPosParams) o; + return Objects.equals(start, that.start) && Objects.equals(end, that.end) && Objects.equals(modifier, that.modifier); + } + + @Override + public int hashCode() { + return Objects.hash(start, end, modifier); + } } diff --git a/src/main/java/redis/clients/jedis/params/ClientKillParams.java b/src/main/java/redis/clients/jedis/params/ClientKillParams.java index 0082ef33408..997d084bdf3 100644 --- a/src/main/java/redis/clients/jedis/params/ClientKillParams.java +++ b/src/main/java/redis/clients/jedis/params/ClientKillParams.java @@ -1,6 +1,7 @@ package redis.clients.jedis.params; import java.util.ArrayList; +import java.util.Objects; import redis.clients.jedis.CommandArguments; import redis.clients.jedis.Protocol.Keyword; @@ -81,4 +82,17 @@ public ClientKillParams maxAge(long maxAge) { public void addParams(CommandArguments args) { params.forEach(kv -> args.add(kv.getKey()).add(kv.getValue())); } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + ClientKillParams that = (ClientKillParams) o; + return Objects.equals(params, that.params); + } + + @Override + public int hashCode() { + return Objects.hash(params); + } } diff --git a/src/main/java/redis/clients/jedis/params/CommandListFilterByParams.java b/src/main/java/redis/clients/jedis/params/CommandListFilterByParams.java index cce880fadab..9127670b3e9 100644 --- a/src/main/java/redis/clients/jedis/params/CommandListFilterByParams.java +++ b/src/main/java/redis/clients/jedis/params/CommandListFilterByParams.java @@ -3,6 +3,8 @@ import redis.clients.jedis.CommandArguments; import redis.clients.jedis.Protocol.Keyword; +import java.util.Objects; + public class CommandListFilterByParams implements IParams { private String moduleName; @@ -46,4 +48,17 @@ public void addParams(CommandArguments args) { + getClass().getSimpleName()); } } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + CommandListFilterByParams that = (CommandListFilterByParams) o; + return Objects.equals(moduleName, that.moduleName) && Objects.equals(category, that.category) && Objects.equals(pattern, that.pattern); + } + + @Override + public int hashCode() { + return Objects.hash(moduleName, category, pattern); + } } diff --git a/src/main/java/redis/clients/jedis/params/FailoverParams.java b/src/main/java/redis/clients/jedis/params/FailoverParams.java index d1afbe368cd..4219a9ff22f 100644 --- a/src/main/java/redis/clients/jedis/params/FailoverParams.java +++ b/src/main/java/redis/clients/jedis/params/FailoverParams.java @@ -4,6 +4,8 @@ import redis.clients.jedis.HostAndPort; import redis.clients.jedis.Protocol.Keyword; +import java.util.Objects; + public class FailoverParams implements IParams { private HostAndPort to; @@ -59,4 +61,17 @@ public void addParams(CommandArguments args) { } } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + FailoverParams that = (FailoverParams) o; + return force == that.force && Objects.equals(to, that.to) && Objects.equals(timeout, that.timeout); + } + + @Override + public int hashCode() { + return Objects.hash(to, force, timeout); + } } diff --git a/src/main/java/redis/clients/jedis/params/GeoAddParams.java b/src/main/java/redis/clients/jedis/params/GeoAddParams.java index 6dbcf99b945..633923f9b84 100644 --- a/src/main/java/redis/clients/jedis/params/GeoAddParams.java +++ b/src/main/java/redis/clients/jedis/params/GeoAddParams.java @@ -3,6 +3,8 @@ import redis.clients.jedis.CommandArguments; import redis.clients.jedis.Protocol.Keyword; +import java.util.Objects; + public class GeoAddParams implements IParams { private boolean nx = false; @@ -57,4 +59,16 @@ public void addParams(CommandArguments args) { } } + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + GeoAddParams that = (GeoAddParams) o; + return nx == that.nx && xx == that.xx && ch == that.ch; + } + + @Override + public int hashCode() { + return Objects.hash(nx, xx, ch); + } } diff --git a/src/main/java/redis/clients/jedis/params/GetExParams.java b/src/main/java/redis/clients/jedis/params/GetExParams.java index 27c875e83a4..521d4c50929 100644 --- a/src/main/java/redis/clients/jedis/params/GetExParams.java +++ b/src/main/java/redis/clients/jedis/params/GetExParams.java @@ -3,6 +3,8 @@ import redis.clients.jedis.CommandArguments; import redis.clients.jedis.Protocol.Keyword; +import java.util.Objects; + public class GetExParams implements IParams { private Keyword expiration; @@ -74,4 +76,17 @@ public void addParams(CommandArguments args) { } } } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + GetExParams that = (GetExParams) o; + return persist == that.persist && expiration == that.expiration && Objects.equals(expirationValue, that.expirationValue); + } + + @Override + public int hashCode() { + return Objects.hash(expiration, expirationValue, persist); + } } diff --git a/src/main/java/redis/clients/jedis/params/LCSParams.java b/src/main/java/redis/clients/jedis/params/LCSParams.java index be3152aefc3..a1cc0a208fe 100644 --- a/src/main/java/redis/clients/jedis/params/LCSParams.java +++ b/src/main/java/redis/clients/jedis/params/LCSParams.java @@ -3,6 +3,8 @@ import redis.clients.jedis.CommandArguments; import redis.clients.jedis.Protocol.Keyword; +import java.util.Objects; + public class LCSParams implements IParams { private boolean len = false; @@ -65,4 +67,17 @@ public void addParams(CommandArguments args) { args.add(Keyword.WITHMATCHLEN); } } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + LCSParams lcsParams = (LCSParams) o; + return len == lcsParams.len && idx == lcsParams.idx && withMatchLen == lcsParams.withMatchLen && Objects.equals(minMatchLen, lcsParams.minMatchLen); + } + + @Override + public int hashCode() { + return Objects.hash(len, idx, minMatchLen, withMatchLen); + } } diff --git a/src/main/java/redis/clients/jedis/params/LPosParams.java b/src/main/java/redis/clients/jedis/params/LPosParams.java index 257e97d1ba8..b13ba4f81ae 100644 --- a/src/main/java/redis/clients/jedis/params/LPosParams.java +++ b/src/main/java/redis/clients/jedis/params/LPosParams.java @@ -3,6 +3,8 @@ import redis.clients.jedis.CommandArguments; import redis.clients.jedis.Protocol.Keyword; +import java.util.Objects; + public class LPosParams implements IParams { private Integer rank; @@ -33,4 +35,16 @@ public void addParams(CommandArguments args) { } } + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + LPosParams that = (LPosParams) o; + return Objects.equals(rank, that.rank) && Objects.equals(maxlen, that.maxlen); + } + + @Override + public int hashCode() { + return Objects.hash(rank, maxlen); + } } diff --git a/src/main/java/redis/clients/jedis/params/LolwutParams.java b/src/main/java/redis/clients/jedis/params/LolwutParams.java index 9b8c9967931..70fcca405c1 100644 --- a/src/main/java/redis/clients/jedis/params/LolwutParams.java +++ b/src/main/java/redis/clients/jedis/params/LolwutParams.java @@ -3,6 +3,9 @@ import redis.clients.jedis.CommandArguments; import redis.clients.jedis.Protocol.Keyword; +import java.util.Arrays; +import java.util.Objects; + public class LolwutParams implements IParams { private Integer version; @@ -33,4 +36,19 @@ public void addParams(CommandArguments args) { } } } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + LolwutParams that = (LolwutParams) o; + return Objects.equals(version, that.version) && Arrays.equals(opargs, that.opargs); + } + + @Override + public int hashCode() { + int result = Objects.hash(version); + result = 31 * result + Arrays.hashCode(opargs); + return result; + } } diff --git a/src/main/java/redis/clients/jedis/params/MigrateParams.java b/src/main/java/redis/clients/jedis/params/MigrateParams.java index a75251e0e40..08a2f401c23 100644 --- a/src/main/java/redis/clients/jedis/params/MigrateParams.java +++ b/src/main/java/redis/clients/jedis/params/MigrateParams.java @@ -3,6 +3,8 @@ import redis.clients.jedis.CommandArguments; import redis.clients.jedis.Protocol.Keyword; +import java.util.Objects; + public class MigrateParams implements IParams { private boolean copy = false; @@ -52,4 +54,17 @@ public void addParams(CommandArguments args) { args.add(Keyword.AUTH).add(password); } } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + MigrateParams that = (MigrateParams) o; + return copy == that.copy && replace == that.replace && Objects.equals(username, that.username) && Objects.equals(password, that.password); + } + + @Override + public int hashCode() { + return Objects.hash(copy, replace, username, password); + } } diff --git a/src/main/java/redis/clients/jedis/params/ModuleLoadExParams.java b/src/main/java/redis/clients/jedis/params/ModuleLoadExParams.java index 9866d8f4dc4..21a4f5ad837 100644 --- a/src/main/java/redis/clients/jedis/params/ModuleLoadExParams.java +++ b/src/main/java/redis/clients/jedis/params/ModuleLoadExParams.java @@ -2,6 +2,7 @@ import java.util.ArrayList; import java.util.List; +import java.util.Objects; import redis.clients.jedis.CommandArguments; import redis.clients.jedis.Protocol.Keyword; @@ -38,4 +39,17 @@ public void addParams(CommandArguments args) { args.add(Keyword.ARGS).addObjects(this.args); } } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + ModuleLoadExParams that = (ModuleLoadExParams) o; + return Objects.equals(configs, that.configs) && Objects.equals(args, that.args); + } + + @Override + public int hashCode() { + return Objects.hash(configs, args); + } } diff --git a/src/main/java/redis/clients/jedis/params/RestoreParams.java b/src/main/java/redis/clients/jedis/params/RestoreParams.java index 499bad7302e..5a2af6316e4 100644 --- a/src/main/java/redis/clients/jedis/params/RestoreParams.java +++ b/src/main/java/redis/clients/jedis/params/RestoreParams.java @@ -3,6 +3,8 @@ import redis.clients.jedis.CommandArguments; import redis.clients.jedis.Protocol.Keyword; +import java.util.Objects; + public class RestoreParams implements IParams { private boolean replace; @@ -55,4 +57,17 @@ public void addParams(CommandArguments args) { args.add(Keyword.FREQ).add(frequency); } } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + RestoreParams that = (RestoreParams) o; + return replace == that.replace && absTtl == that.absTtl && Objects.equals(idleTime, that.idleTime) && Objects.equals(frequency, that.frequency); + } + + @Override + public int hashCode() { + return Objects.hash(replace, absTtl, idleTime, frequency); + } } diff --git a/src/main/java/redis/clients/jedis/params/ScanParams.java b/src/main/java/redis/clients/jedis/params/ScanParams.java index ad22a5778c1..6fc162cf200 100644 --- a/src/main/java/redis/clients/jedis/params/ScanParams.java +++ b/src/main/java/redis/clients/jedis/params/ScanParams.java @@ -5,6 +5,7 @@ import java.nio.ByteBuffer; import java.util.EnumMap; import java.util.Map; +import java.util.Objects; import redis.clients.jedis.CommandArguments; import redis.clients.jedis.Protocol.Keyword; @@ -63,4 +64,17 @@ public String match() { return null; } } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + ScanParams that = (ScanParams) o; + return Objects.equals(params, that.params); + } + + @Override + public int hashCode() { + return Objects.hash(params); + } } diff --git a/src/main/java/redis/clients/jedis/params/SetParams.java b/src/main/java/redis/clients/jedis/params/SetParams.java index b0e43103277..11f368f3dea 100644 --- a/src/main/java/redis/clients/jedis/params/SetParams.java +++ b/src/main/java/redis/clients/jedis/params/SetParams.java @@ -3,6 +3,8 @@ import redis.clients.jedis.CommandArguments; import redis.clients.jedis.Protocol.Keyword; +import java.util.Objects; + public class SetParams implements IParams { private Keyword existance; @@ -106,4 +108,18 @@ public void addParams(CommandArguments args) { } } } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + SetParams setParams = (SetParams) o; + return Objects.equals(existance, setParams.existance) && Objects.equals(expiration, setParams.expiration) + && Objects.equals(expirationValue, setParams.expirationValue); + } + + @Override + public int hashCode() { + return Objects.hash(existance, expiration, expirationValue); + } } diff --git a/src/main/java/redis/clients/jedis/params/ShutdownParams.java b/src/main/java/redis/clients/jedis/params/ShutdownParams.java index 0c35943abe2..d07fd26f10c 100644 --- a/src/main/java/redis/clients/jedis/params/ShutdownParams.java +++ b/src/main/java/redis/clients/jedis/params/ShutdownParams.java @@ -4,6 +4,8 @@ import redis.clients.jedis.Protocol.Keyword; import redis.clients.jedis.args.SaveMode; +import java.util.Objects; + public class ShutdownParams implements IParams { private SaveMode saveMode; @@ -49,4 +51,17 @@ public void addParams(CommandArguments args) { args.add(Keyword.FORCE); } } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + ShutdownParams that = (ShutdownParams) o; + return now == that.now && force == that.force && saveMode == that.saveMode; + } + + @Override + public int hashCode() { + return Objects.hash(saveMode, now, force); + } } diff --git a/src/main/java/redis/clients/jedis/params/SortingParams.java b/src/main/java/redis/clients/jedis/params/SortingParams.java index 6762acf3010..ad9b596bc0d 100644 --- a/src/main/java/redis/clients/jedis/params/SortingParams.java +++ b/src/main/java/redis/clients/jedis/params/SortingParams.java @@ -1,9 +1,6 @@ package redis.clients.jedis.params; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.List; +import java.util.*; import redis.clients.jedis.CommandArguments; import redis.clients.jedis.Protocol; @@ -163,4 +160,17 @@ public SortingParams get(byte[]... patterns) { public void addParams(CommandArguments args) { args.addObjects(params); } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + SortingParams that = (SortingParams) o; + return Objects.equals(params, that.params); + } + + @Override + public int hashCode() { + return Objects.hash(params); + } } diff --git a/src/main/java/redis/clients/jedis/params/XAddParams.java b/src/main/java/redis/clients/jedis/params/XAddParams.java index 8c8d09141d1..3575c6e5d27 100644 --- a/src/main/java/redis/clients/jedis/params/XAddParams.java +++ b/src/main/java/redis/clients/jedis/params/XAddParams.java @@ -7,6 +7,8 @@ import redis.clients.jedis.args.Rawable; import redis.clients.jedis.args.RawableFactory; +import java.util.Objects; + public class XAddParams implements IParams { private Rawable id; @@ -114,4 +116,17 @@ public void addParams(CommandArguments args) { args.add(id != null ? id : StreamEntryID.NEW_ENTRY); } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + XAddParams that = (XAddParams) o; + return approximateTrimming == that.approximateTrimming && exactTrimming == that.exactTrimming && nomkstream == that.nomkstream && Objects.equals(id, that.id) && Objects.equals(maxLen, that.maxLen) && Objects.equals(minId, that.minId) && Objects.equals(limit, that.limit); + } + + @Override + public int hashCode() { + return Objects.hash(id, maxLen, approximateTrimming, exactTrimming, nomkstream, minId, limit); + } } diff --git a/src/main/java/redis/clients/jedis/params/XAutoClaimParams.java b/src/main/java/redis/clients/jedis/params/XAutoClaimParams.java index ce20d8652df..3834dd3804f 100644 --- a/src/main/java/redis/clients/jedis/params/XAutoClaimParams.java +++ b/src/main/java/redis/clients/jedis/params/XAutoClaimParams.java @@ -3,6 +3,8 @@ import redis.clients.jedis.CommandArguments; import redis.clients.jedis.Protocol.Keyword; +import java.util.Objects; + public class XAutoClaimParams implements IParams { private Integer count; @@ -31,4 +33,16 @@ public void addParams(CommandArguments args) { } } + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + XAutoClaimParams that = (XAutoClaimParams) o; + return Objects.equals(count, that.count); + } + + @Override + public int hashCode() { + return Objects.hash(count); + } } diff --git a/src/main/java/redis/clients/jedis/params/XClaimParams.java b/src/main/java/redis/clients/jedis/params/XClaimParams.java index 977e825ff27..944e57087d4 100644 --- a/src/main/java/redis/clients/jedis/params/XClaimParams.java +++ b/src/main/java/redis/clients/jedis/params/XClaimParams.java @@ -3,6 +3,8 @@ import redis.clients.jedis.CommandArguments; import redis.clients.jedis.Protocol.Keyword; +import java.util.Objects; + public class XClaimParams implements IParams { private Long idleTime; @@ -72,4 +74,17 @@ public void addParams(CommandArguments args) { args.add(Keyword.FORCE); } } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + XClaimParams that = (XClaimParams) o; + return force == that.force && Objects.equals(idleTime, that.idleTime) && Objects.equals(idleUnixTime, that.idleUnixTime) && Objects.equals(retryCount, that.retryCount); + } + + @Override + public int hashCode() { + return Objects.hash(idleTime, idleUnixTime, retryCount, force); + } } diff --git a/src/main/java/redis/clients/jedis/params/XPendingParams.java b/src/main/java/redis/clients/jedis/params/XPendingParams.java index 5985ed3f7e8..647aa1e9524 100644 --- a/src/main/java/redis/clients/jedis/params/XPendingParams.java +++ b/src/main/java/redis/clients/jedis/params/XPendingParams.java @@ -7,6 +7,8 @@ import redis.clients.jedis.StreamEntryID; import redis.clients.jedis.args.Rawable; +import java.util.Objects; + public class XPendingParams implements IParams { private Long idle; @@ -103,4 +105,17 @@ public void addParams(CommandArguments args) { args.add(consumer); } } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + XPendingParams that = (XPendingParams) o; + return Objects.equals(idle, that.idle) && Objects.equals(start, that.start) && Objects.equals(end, that.end) && Objects.equals(count, that.count) && Objects.equals(consumer, that.consumer); + } + + @Override + public int hashCode() { + return Objects.hash(idle, start, end, count, consumer); + } } diff --git a/src/main/java/redis/clients/jedis/params/XReadGroupParams.java b/src/main/java/redis/clients/jedis/params/XReadGroupParams.java index 07f878fb99c..a761f166b24 100644 --- a/src/main/java/redis/clients/jedis/params/XReadGroupParams.java +++ b/src/main/java/redis/clients/jedis/params/XReadGroupParams.java @@ -3,6 +3,8 @@ import redis.clients.jedis.CommandArguments; import redis.clients.jedis.Protocol.Keyword; +import java.util.Objects; + public class XReadGroupParams implements IParams { private Integer count = null; @@ -40,4 +42,17 @@ public void addParams(CommandArguments args) { args.add(Keyword.NOACK); } } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + XReadGroupParams that = (XReadGroupParams) o; + return noack == that.noack && Objects.equals(count, that.count) && Objects.equals(block, that.block); + } + + @Override + public int hashCode() { + return Objects.hash(count, block, noack); + } } diff --git a/src/main/java/redis/clients/jedis/params/XReadParams.java b/src/main/java/redis/clients/jedis/params/XReadParams.java index a64d3c1afae..3c19446e78f 100644 --- a/src/main/java/redis/clients/jedis/params/XReadParams.java +++ b/src/main/java/redis/clients/jedis/params/XReadParams.java @@ -3,6 +3,8 @@ import redis.clients.jedis.CommandArguments; import redis.clients.jedis.Protocol.Keyword; +import java.util.Objects; + public class XReadParams implements IParams { private Integer count = null; @@ -31,4 +33,17 @@ public void addParams(CommandArguments args) { args.add(Keyword.BLOCK).add(block).blocking(); } } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + XReadParams that = (XReadParams) o; + return Objects.equals(count, that.count) && Objects.equals(block, that.block); + } + + @Override + public int hashCode() { + return Objects.hash(count, block); + } } diff --git a/src/main/java/redis/clients/jedis/params/XTrimParams.java b/src/main/java/redis/clients/jedis/params/XTrimParams.java index a7c7a055624..af77ba81b3b 100644 --- a/src/main/java/redis/clients/jedis/params/XTrimParams.java +++ b/src/main/java/redis/clients/jedis/params/XTrimParams.java @@ -4,6 +4,8 @@ import redis.clients.jedis.Protocol; import redis.clients.jedis.Protocol.Keyword; +import java.util.Objects; + public class XTrimParams implements IParams { private Long maxLen; @@ -74,4 +76,17 @@ public void addParams(CommandArguments args) { args.add(Keyword.LIMIT).add(limit); } } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + XTrimParams that = (XTrimParams) o; + return approximateTrimming == that.approximateTrimming && exactTrimming == that.exactTrimming && Objects.equals(maxLen, that.maxLen) && Objects.equals(minId, that.minId) && Objects.equals(limit, that.limit); + } + + @Override + public int hashCode() { + return Objects.hash(maxLen, approximateTrimming, exactTrimming, minId, limit); + } } diff --git a/src/main/java/redis/clients/jedis/params/ZAddParams.java b/src/main/java/redis/clients/jedis/params/ZAddParams.java index 8194c041a66..8781e3e87b5 100644 --- a/src/main/java/redis/clients/jedis/params/ZAddParams.java +++ b/src/main/java/redis/clients/jedis/params/ZAddParams.java @@ -3,6 +3,8 @@ import redis.clients.jedis.CommandArguments; import redis.clients.jedis.Protocol.Keyword; +import java.util.Objects; + public class ZAddParams implements IParams { private Keyword existence; @@ -75,4 +77,16 @@ public void addParams(CommandArguments args) { } } + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + ZAddParams that = (ZAddParams) o; + return change == that.change && existence == that.existence && comparison == that.comparison; + } + + @Override + public int hashCode() { + return Objects.hash(existence, comparison, change); + } } diff --git a/src/main/java/redis/clients/jedis/params/ZIncrByParams.java b/src/main/java/redis/clients/jedis/params/ZIncrByParams.java index 6d5b5a411d7..cc0ebb6d3f3 100644 --- a/src/main/java/redis/clients/jedis/params/ZIncrByParams.java +++ b/src/main/java/redis/clients/jedis/params/ZIncrByParams.java @@ -3,6 +3,8 @@ import redis.clients.jedis.CommandArguments; import redis.clients.jedis.Protocol.Keyword; +import java.util.Objects; + /** * Parameters for ZINCRBY commands. In fact, Redis doesn't have parameters for ZINCRBY. Instead * Redis has INCR parameter for ZADD. @@ -51,4 +53,16 @@ public void addParams(CommandArguments args) { args.add(Keyword.INCR); } + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + ZIncrByParams that = (ZIncrByParams) o; + return existance == that.existance; + } + + @Override + public int hashCode() { + return Objects.hash(existance); + } } diff --git a/src/main/java/redis/clients/jedis/params/ZParams.java b/src/main/java/redis/clients/jedis/params/ZParams.java index ea45cc93277..15f2b35ea28 100644 --- a/src/main/java/redis/clients/jedis/params/ZParams.java +++ b/src/main/java/redis/clients/jedis/params/ZParams.java @@ -2,6 +2,7 @@ import java.util.ArrayList; import java.util.List; +import java.util.Objects; import redis.clients.jedis.CommandArguments; import redis.clients.jedis.Protocol.Keyword; @@ -46,4 +47,17 @@ public ZParams aggregate(final Aggregate aggregate) { public void addParams(CommandArguments args) { args.addObjects(params); } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + ZParams zParams = (ZParams) o; + return Objects.equals(params, zParams.params); + } + + @Override + public int hashCode() { + return Objects.hash(params); + } } diff --git a/src/main/java/redis/clients/jedis/params/ZRangeParams.java b/src/main/java/redis/clients/jedis/params/ZRangeParams.java index 7d990c6198d..fc73c9141e2 100644 --- a/src/main/java/redis/clients/jedis/params/ZRangeParams.java +++ b/src/main/java/redis/clients/jedis/params/ZRangeParams.java @@ -8,6 +8,8 @@ import redis.clients.jedis.Protocol.Keyword; import redis.clients.jedis.args.Rawable; +import java.util.Objects; + public class ZRangeParams implements IParams { private final Keyword by; @@ -98,4 +100,17 @@ public void addParams(CommandArguments args) { args.add(Keyword.LIMIT).add(offset).add(count); } } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + ZRangeParams that = (ZRangeParams) o; + return rev == that.rev && limit == that.limit && offset == that.offset && count == that.count && by == that.by && Objects.equals(min, that.min) && Objects.equals(max, that.max); + } + + @Override + public int hashCode() { + return Objects.hash(by, min, max, rev, limit, offset, count); + } } diff --git a/src/test/java/redis/clients/jedis/params/BitPosParamsTest.java b/src/test/java/redis/clients/jedis/params/BitPosParamsTest.java new file mode 100644 index 00000000000..4a38018c368 --- /dev/null +++ b/src/test/java/redis/clients/jedis/params/BitPosParamsTest.java @@ -0,0 +1,49 @@ +package redis.clients.jedis.params; + +import org.junit.Test; + +import static org.junit.Assert.*; + +public class BitPosParamsTest { + + @Test + public void checkEqualsIdenticalParams() { + BitPosParams firstParam = getDefaultValue(); + BitPosParams secondParam = getDefaultValue(); + assertTrue(firstParam.equals(secondParam)); + } + + @Test + public void checkHashCodeIdenticalParams() { + BitPosParams firstParam = getDefaultValue(); + BitPosParams secondParam = getDefaultValue(); + assertEquals(firstParam.hashCode(), secondParam.hashCode()); + } + + @Test + public void checkEqualsVariousParams() { + BitPosParams firstParam = getDefaultValue(); + BitPosParams secondParam = getDefaultValue(); + secondParam.end(15); + assertFalse(firstParam.equals(secondParam)); + } + + @Test + public void checkHashCodeVariousParams() { + BitPosParams firstParam = getDefaultValue(); + BitPosParams secondParam = getDefaultValue(); + secondParam.start(15); + assertNotEquals(firstParam.hashCode(), secondParam.hashCode()); + } + + @Test + public void checkEqualsWithNull() { + BitPosParams firstParam = getDefaultValue(); + BitPosParams secondParam = null; + assertFalse(firstParam.equals(secondParam)); + } + + private BitPosParams getDefaultValue() { + return new BitPosParams(); + } +} diff --git a/src/test/java/redis/clients/jedis/params/ClientKillParamsTest.java b/src/test/java/redis/clients/jedis/params/ClientKillParamsTest.java new file mode 100644 index 00000000000..6a9a75c8d80 --- /dev/null +++ b/src/test/java/redis/clients/jedis/params/ClientKillParamsTest.java @@ -0,0 +1,52 @@ +package redis.clients.jedis.params; + +import org.junit.Test; +import redis.clients.jedis.args.ClientType; + +import static org.junit.Assert.*; + +public class ClientKillParamsTest { + + @Test + public void checkEqualsIdenticalParams() { + ClientKillParams firstParam = getDefaultValue(); + ClientKillParams secondParam = getDefaultValue(); + assertTrue(firstParam.equals(secondParam)); + } + + @Test + public void checkHashCodeIdenticalParams() { + ClientKillParams firstParam = getDefaultValue(); + ClientKillParams secondParam = getDefaultValue(); + assertEquals(firstParam.hashCode(), secondParam.hashCode()); + } + + @Test + public void checkEqualsVariousParams() { + ClientKillParams firstParam = getDefaultValue(); + firstParam.type(ClientType.NORMAL); + ClientKillParams secondParam = getDefaultValue(); + secondParam.skipMe(ClientKillParams.SkipMe.NO); + assertFalse(firstParam.equals(secondParam)); + } + + @Test + public void checkHashCodeVariousParams() { + ClientKillParams firstParam = getDefaultValue(); + firstParam.type(ClientType.NORMAL); + ClientKillParams secondParam = getDefaultValue(); + secondParam.skipMe(ClientKillParams.SkipMe.NO); + assertNotEquals(firstParam.hashCode(), secondParam.hashCode()); + } + + @Test + public void checkEqualsWithNull() { + ClientKillParams firstParam = getDefaultValue(); + ClientKillParams secondParam = null; + assertFalse(firstParam.equals(secondParam)); + } + + private ClientKillParams getDefaultValue() { + return new ClientKillParams(); + } +} diff --git a/src/test/java/redis/clients/jedis/params/CommandListFilterByParamsTest.java b/src/test/java/redis/clients/jedis/params/CommandListFilterByParamsTest.java new file mode 100644 index 00000000000..dff749febc2 --- /dev/null +++ b/src/test/java/redis/clients/jedis/params/CommandListFilterByParamsTest.java @@ -0,0 +1,51 @@ +package redis.clients.jedis.params; + +import org.junit.Test; + +import static org.junit.Assert.*; + +public class CommandListFilterByParamsTest { + + @Test + public void checkEqualsIdenticalParams() { + CommandListFilterByParams firstParam = getDefaultValue(); + CommandListFilterByParams secondParam = getDefaultValue(); + assertTrue(firstParam.equals(secondParam)); + } + + @Test + public void checkHashCodeIdenticalParams() { + CommandListFilterByParams firstParam = getDefaultValue(); + CommandListFilterByParams secondParam = getDefaultValue(); + assertEquals(firstParam.hashCode(), secondParam.hashCode()); + } + + @Test + public void checkEqualsVariousParams() { + CommandListFilterByParams firstParam = getDefaultValue(); + firstParam.filterByAclCat("admin"); + CommandListFilterByParams secondParam = getDefaultValue(); + secondParam.filterByModule("JSON"); + assertFalse(firstParam.equals(secondParam)); + } + + @Test + public void checkHashCodeVariousParams() { + CommandListFilterByParams firstParam = getDefaultValue(); + firstParam.filterByAclCat("admin"); + CommandListFilterByParams secondParam = getDefaultValue(); + secondParam.filterByModule("JSON"); + assertNotEquals(firstParam.hashCode(), secondParam.hashCode()); + } + + @Test + public void checkEqualsWithNull() { + CommandListFilterByParams firstParam = getDefaultValue(); + CommandListFilterByParams secondParam = null; + assertFalse(firstParam.equals(secondParam)); + } + + private CommandListFilterByParams getDefaultValue() { + return new CommandListFilterByParams(); + } +} diff --git a/src/test/java/redis/clients/jedis/params/FailoverParamsTest.java b/src/test/java/redis/clients/jedis/params/FailoverParamsTest.java new file mode 100644 index 00000000000..80d9bb1137a --- /dev/null +++ b/src/test/java/redis/clients/jedis/params/FailoverParamsTest.java @@ -0,0 +1,51 @@ +package redis.clients.jedis.params; + +import org.junit.Test; + +import static org.junit.Assert.*; + +public class FailoverParamsTest { + + @Test + public void checkEqualsIdenticalParams() { + FailoverParams firstParam = getDefaultValue(); + FailoverParams secondParam = getDefaultValue(); + assertTrue(firstParam.equals(secondParam)); + } + + @Test + public void checkHashCodeIdenticalParams() { + FailoverParams firstParam = getDefaultValue(); + FailoverParams secondParam = getDefaultValue(); + assertEquals(firstParam.hashCode(), secondParam.hashCode()); + } + + @Test + public void checkEqualsVariousParams() { + FailoverParams firstParam = getDefaultValue(); + firstParam.timeout(15); + FailoverParams secondParam = getDefaultValue(); + secondParam.timeout(20); + assertFalse(firstParam.equals(secondParam)); + } + + @Test + public void checkHashCodeVariousParams() { + FailoverParams firstParam = getDefaultValue(); + firstParam.timeout(15); + FailoverParams secondParam = getDefaultValue(); + secondParam.timeout(20); + assertNotEquals(firstParam.hashCode(), secondParam.hashCode()); + } + + @Test + public void checkEqualsWithNull() { + FailoverParams firstParam = getDefaultValue(); + FailoverParams secondParam = null; + assertFalse(firstParam.equals(secondParam)); + } + + private FailoverParams getDefaultValue() { + return new FailoverParams(); + } +} diff --git a/src/test/java/redis/clients/jedis/params/GeoAddParamsTest.java b/src/test/java/redis/clients/jedis/params/GeoAddParamsTest.java new file mode 100644 index 00000000000..cf3b5a33054 --- /dev/null +++ b/src/test/java/redis/clients/jedis/params/GeoAddParamsTest.java @@ -0,0 +1,51 @@ +package redis.clients.jedis.params; + +import org.junit.Test; + +import static org.junit.Assert.*; + +public class GeoAddParamsTest { + + @Test + public void checkEqualsIdenticalParams() { + GeoAddParams firstParam = getDefaultValue(); + GeoAddParams secondParam = getDefaultValue(); + assertTrue(firstParam.equals(secondParam)); + } + + @Test + public void checkHashCodeIdenticalParams() { + GeoAddParams firstParam = getDefaultValue(); + GeoAddParams secondParam = getDefaultValue(); + assertEquals(firstParam.hashCode(), secondParam.hashCode()); + } + + @Test + public void checkEqualsVariousParams() { + GeoAddParams firstParam = getDefaultValue(); + firstParam.nx(); + GeoAddParams secondParam = getDefaultValue(); + secondParam.xx(); + assertFalse(firstParam.equals(secondParam)); + } + + @Test + public void checkHashCodeVariousParams() { + GeoAddParams firstParam = getDefaultValue(); + firstParam.nx(); + GeoAddParams secondParam = getDefaultValue(); + secondParam.xx(); + assertNotEquals(firstParam.hashCode(), secondParam.hashCode()); + } + + @Test + public void checkEqualsWithNull() { + GeoAddParams firstParam = getDefaultValue(); + GeoAddParams secondParam = null; + assertFalse(firstParam.equals(secondParam)); + } + + private GeoAddParams getDefaultValue() { + return new GeoAddParams(); + } +} diff --git a/src/test/java/redis/clients/jedis/params/GetExParamsTest.java b/src/test/java/redis/clients/jedis/params/GetExParamsTest.java new file mode 100644 index 00000000000..0774bfde54d --- /dev/null +++ b/src/test/java/redis/clients/jedis/params/GetExParamsTest.java @@ -0,0 +1,51 @@ +package redis.clients.jedis.params; + +import org.junit.Test; + +import static org.junit.Assert.*; + +public class GetExParamsTest { + + @Test + public void checkEqualsIdenticalParams() { + GetExParams firstParam = getDefaultValue(); + GetExParams secondParam = getDefaultValue(); + assertTrue(firstParam.equals(secondParam)); + } + + @Test + public void checkHashCodeIdenticalParams() { + GetExParams firstParam = getDefaultValue(); + GetExParams secondParam = getDefaultValue(); + assertEquals(firstParam.hashCode(), secondParam.hashCode()); + } + + @Test + public void checkEqualsVariousParams() { + GetExParams firstParam = getDefaultValue(); + firstParam.ex(15); + GetExParams secondParam = getDefaultValue(); + secondParam.px(20); + assertFalse(firstParam.equals(secondParam)); + } + + @Test + public void checkHashCodeVariousParams() { + GetExParams firstParam = getDefaultValue(); + firstParam.ex(15); + GetExParams secondParam = getDefaultValue(); + secondParam.px(20); + assertNotEquals(firstParam.hashCode(), secondParam.hashCode()); + } + + @Test + public void checkEqualsWithNull() { + GetExParams firstParam = getDefaultValue(); + GetExParams secondParam = null; + assertFalse(firstParam.equals(secondParam)); + } + + private GetExParams getDefaultValue() { + return new GetExParams(); + } +} diff --git a/src/test/java/redis/clients/jedis/params/LCSParamsTest.java b/src/test/java/redis/clients/jedis/params/LCSParamsTest.java new file mode 100644 index 00000000000..a3f759304c8 --- /dev/null +++ b/src/test/java/redis/clients/jedis/params/LCSParamsTest.java @@ -0,0 +1,51 @@ +package redis.clients.jedis.params; + +import org.junit.Test; + +import static org.junit.Assert.*; + +public class LCSParamsTest { + + @Test + public void checkEqualsIdenticalParams() { + LCSParams firstParam = getDefaultValue(); + LCSParams secondParam = getDefaultValue(); + assertTrue(firstParam.equals(secondParam)); + } + + @Test + public void checkHashCodeIdenticalParams() { + LCSParams firstParam = getDefaultValue(); + LCSParams secondParam = getDefaultValue(); + assertEquals(firstParam.hashCode(), secondParam.hashCode()); + } + + @Test + public void checkEqualsVariousParams() { + LCSParams firstParam = getDefaultValue(); + firstParam.idx(); + LCSParams secondParam = getDefaultValue(); + secondParam.len(); + assertFalse(firstParam.equals(secondParam)); + } + + @Test + public void checkHashCodeVariousParams() { + LCSParams firstParam = getDefaultValue(); + firstParam.idx(); + LCSParams secondParam = getDefaultValue(); + secondParam.len(); + assertNotEquals(firstParam.hashCode(), secondParam.hashCode()); + } + + @Test + public void checkEqualsWithNull() { + LCSParams firstParam = getDefaultValue(); + LCSParams secondParam = null; + assertFalse(firstParam.equals(secondParam)); + } + + private LCSParams getDefaultValue() { + return new LCSParams(); + } +} diff --git a/src/test/java/redis/clients/jedis/params/LPosParamsTest.java b/src/test/java/redis/clients/jedis/params/LPosParamsTest.java new file mode 100644 index 00000000000..73e23b77989 --- /dev/null +++ b/src/test/java/redis/clients/jedis/params/LPosParamsTest.java @@ -0,0 +1,51 @@ +package redis.clients.jedis.params; + +import org.junit.Test; + +import static org.junit.Assert.*; + +public class LPosParamsTest { + + @Test + public void checkEqualsIdenticalParams() { + LPosParams firstParam = getDefaultValue(); + LPosParams secondParam = getDefaultValue(); + assertTrue(firstParam.equals(secondParam)); + } + + @Test + public void checkHashCodeIdenticalParams() { + LPosParams firstParam = getDefaultValue(); + LPosParams secondParam = getDefaultValue(); + assertEquals(firstParam.hashCode(), secondParam.hashCode()); + } + + @Test + public void checkEqualsVariousParams() { + LPosParams firstParam = getDefaultValue(); + firstParam.rank(1); + LPosParams secondParam = getDefaultValue(); + secondParam.rank(2); + assertFalse(firstParam.equals(secondParam)); + } + + @Test + public void checkHashCodeVariousParams() { + LPosParams firstParam = getDefaultValue(); + firstParam.rank(1); + LPosParams secondParam = getDefaultValue(); + secondParam.rank(2); + assertNotEquals(firstParam.hashCode(), secondParam.hashCode()); + } + + @Test + public void checkEqualsWithNull() { + LPosParams firstParam = getDefaultValue(); + LPosParams secondParam = null; + assertFalse(firstParam.equals(secondParam)); + } + + private LPosParams getDefaultValue() { + return new LPosParams(); + } +} diff --git a/src/test/java/redis/clients/jedis/params/LolwutParamsTest.java b/src/test/java/redis/clients/jedis/params/LolwutParamsTest.java new file mode 100644 index 00000000000..0e49f8686c4 --- /dev/null +++ b/src/test/java/redis/clients/jedis/params/LolwutParamsTest.java @@ -0,0 +1,51 @@ +package redis.clients.jedis.params; + +import org.junit.Test; + +import static org.junit.Assert.*; + +public class LolwutParamsTest { + + @Test + public void checkEqualsIdenticalParams() { + LolwutParams firstParam = getDefaultValue(); + LolwutParams secondParam = getDefaultValue(); + assertTrue(firstParam.equals(secondParam)); + } + + @Test + public void checkHashCodeIdenticalParams() { + LolwutParams firstParam = getDefaultValue(); + LolwutParams secondParam = getDefaultValue(); + assertEquals(firstParam.hashCode(), secondParam.hashCode()); + } + + @Test + public void checkEqualsVariousParams() { + LolwutParams firstParam = getDefaultValue(); + firstParam.version(1); + LolwutParams secondParam = getDefaultValue(); + secondParam.version(2); + assertFalse(firstParam.equals(secondParam)); + } + + @Test + public void checkHashCodeVariousParams() { + LolwutParams firstParam = getDefaultValue(); + firstParam.version(1); + LolwutParams secondParam = getDefaultValue(); + secondParam.version(2); + assertNotEquals(firstParam.hashCode(), secondParam.hashCode()); + } + + @Test + public void checkEqualsWithNull() { + LolwutParams firstParam = getDefaultValue(); + LolwutParams secondParam = null; + assertFalse(firstParam.equals(secondParam)); + } + + private LolwutParams getDefaultValue() { + return new LolwutParams(); + } +} diff --git a/src/test/java/redis/clients/jedis/params/MigrateParamsTest.java b/src/test/java/redis/clients/jedis/params/MigrateParamsTest.java new file mode 100644 index 00000000000..eab24f6f71e --- /dev/null +++ b/src/test/java/redis/clients/jedis/params/MigrateParamsTest.java @@ -0,0 +1,51 @@ +package redis.clients.jedis.params; + +import org.junit.Test; + +import static org.junit.Assert.*; + +public class MigrateParamsTest { + + @Test + public void checkEqualsIdenticalParams() { + MigrateParams firstParam = getDefaultValue(); + MigrateParams secondParam = getDefaultValue(); + assertTrue(firstParam.equals(secondParam)); + } + + @Test + public void checkHashCodeIdenticalParams() { + MigrateParams firstParam = getDefaultValue(); + MigrateParams secondParam = getDefaultValue(); + assertEquals(firstParam.hashCode(), secondParam.hashCode()); + } + + @Test + public void checkEqualsVariousParams() { + MigrateParams firstParam = getDefaultValue(); + firstParam.auth("123"); + MigrateParams secondParam = getDefaultValue(); + secondParam.auth("234"); + assertFalse(firstParam.equals(secondParam)); + } + + @Test + public void checkHashCodeVariousParams() { + MigrateParams firstParam = getDefaultValue(); + firstParam.auth("123"); + MigrateParams secondParam = getDefaultValue(); + secondParam.auth("234"); + assertNotEquals(firstParam.hashCode(), secondParam.hashCode()); + } + + @Test + public void checkEqualsWithNull() { + MigrateParams firstParam = getDefaultValue(); + MigrateParams secondParam = null; + assertFalse(firstParam.equals(secondParam)); + } + + private MigrateParams getDefaultValue() { + return new MigrateParams(); + } +} diff --git a/src/test/java/redis/clients/jedis/params/ModuleLoadExParamsTest.java b/src/test/java/redis/clients/jedis/params/ModuleLoadExParamsTest.java new file mode 100644 index 00000000000..08f8034bd25 --- /dev/null +++ b/src/test/java/redis/clients/jedis/params/ModuleLoadExParamsTest.java @@ -0,0 +1,51 @@ +package redis.clients.jedis.params; + +import org.junit.Test; + +import static org.junit.Assert.*; + +public class ModuleLoadExParamsTest { + + @Test + public void checkEqualsIdenticalParams() { + ModuleLoadExParams firstParam = getDefaultValue(); + ModuleLoadExParams secondParam = getDefaultValue(); + assertTrue(firstParam.equals(secondParam)); + } + + @Test + public void checkHashCodeIdenticalParams() { + ModuleLoadExParams firstParam = getDefaultValue(); + ModuleLoadExParams secondParam = getDefaultValue(); + assertEquals(firstParam.hashCode(), secondParam.hashCode()); + } + + @Test + public void checkEqualsVariousParams() { + ModuleLoadExParams firstParam = getDefaultValue(); + firstParam.arg("123"); + ModuleLoadExParams secondParam = getDefaultValue(); + secondParam.arg("234"); + assertFalse(firstParam.equals(secondParam)); + } + + @Test + public void checkHashCodeVariousParams() { + ModuleLoadExParams firstParam = getDefaultValue(); + firstParam.arg("123"); + ModuleLoadExParams secondParam = getDefaultValue(); + secondParam.arg("234"); + assertNotEquals(firstParam.hashCode(), secondParam.hashCode()); + } + + @Test + public void checkEqualsWithNull() { + ModuleLoadExParams firstParam = getDefaultValue(); + ModuleLoadExParams secondParam = null; + assertFalse(firstParam.equals(secondParam)); + } + + private ModuleLoadExParams getDefaultValue() { + return new ModuleLoadExParams(); + } +} diff --git a/src/test/java/redis/clients/jedis/params/RestoreParamsTest.java b/src/test/java/redis/clients/jedis/params/RestoreParamsTest.java new file mode 100644 index 00000000000..05f328bc41b --- /dev/null +++ b/src/test/java/redis/clients/jedis/params/RestoreParamsTest.java @@ -0,0 +1,51 @@ +package redis.clients.jedis.params; + +import org.junit.Test; + +import static org.junit.Assert.*; + +public class RestoreParamsTest { + + @Test + public void checkEqualsIdenticalParams() { + RestoreParams firstParam = getDefaultValue(); + RestoreParams secondParam = getDefaultValue(); + assertTrue(firstParam.equals(secondParam)); + } + + @Test + public void checkHashCodeIdenticalParams() { + RestoreParams firstParam = getDefaultValue(); + RestoreParams secondParam = getDefaultValue(); + assertEquals(firstParam.hashCode(), secondParam.hashCode()); + } + + @Test + public void checkEqualsVariousParams() { + RestoreParams firstParam = getDefaultValue(); + firstParam.idleTime(14); + RestoreParams secondParam = getDefaultValue(); + secondParam.idleTime(15); + assertFalse(firstParam.equals(secondParam)); + } + + @Test + public void checkHashCodeVariousParams() { + RestoreParams firstParam = getDefaultValue(); + firstParam.idleTime(14); + RestoreParams secondParam = getDefaultValue(); + secondParam.idleTime(15); + assertNotEquals(firstParam.hashCode(), secondParam.hashCode()); + } + + @Test + public void checkEqualsWithNull() { + RestoreParams firstParam = getDefaultValue(); + RestoreParams secondParam = null; + assertFalse(firstParam.equals(secondParam)); + } + + private RestoreParams getDefaultValue() { + return new RestoreParams(); + } +} diff --git a/src/test/java/redis/clients/jedis/params/ScanParamsTest.java b/src/test/java/redis/clients/jedis/params/ScanParamsTest.java new file mode 100644 index 00000000000..111f953b2fa --- /dev/null +++ b/src/test/java/redis/clients/jedis/params/ScanParamsTest.java @@ -0,0 +1,51 @@ +package redis.clients.jedis.params; + +import org.junit.Test; + +import static org.junit.Assert.*; + +public class ScanParamsTest { + + @Test + public void checkEqualsIdenticalParams() { + ScanParams firstParam = getDefaultValue(); + ScanParams secondParam = getDefaultValue(); + assertTrue(firstParam.equals(secondParam)); + } + + @Test + public void checkHashCodeIdenticalParams() { + ScanParams firstParam = getDefaultValue(); + ScanParams secondParam = getDefaultValue(); + assertEquals(firstParam.hashCode(), secondParam.hashCode()); + } + + @Test + public void checkEqualsVariousParams() { + ScanParams firstParam = getDefaultValue(); + firstParam.count(15); + ScanParams secondParam = getDefaultValue(); + secondParam.count(16); + assertFalse(firstParam.equals(secondParam)); + } + + @Test + public void checkHashCodeVariousParams() { + ScanParams firstParam = getDefaultValue(); + firstParam.count(15); + ScanParams secondParam = getDefaultValue(); + secondParam.count(16); + assertNotEquals(firstParam.hashCode(), secondParam.hashCode()); + } + + @Test + public void checkEqualsWithNull() { + ScanParams firstParam = getDefaultValue(); + ScanParams secondParam = null; + assertFalse(firstParam.equals(secondParam)); + } + + private ScanParams getDefaultValue() { + return new ScanParams(); + } +} diff --git a/src/test/java/redis/clients/jedis/params/SetParamsTest.java b/src/test/java/redis/clients/jedis/params/SetParamsTest.java new file mode 100644 index 00000000000..14b81deeb43 --- /dev/null +++ b/src/test/java/redis/clients/jedis/params/SetParamsTest.java @@ -0,0 +1,51 @@ +package redis.clients.jedis.params; + +import org.junit.Test; + +import static org.junit.Assert.*; + +public class SetParamsTest { + + @Test + public void checkEqualsIdenticalParams() { + SetParams firstParam = getDefaultValue(); + SetParams secondParam = getDefaultValue(); + assertTrue(firstParam.equals(secondParam)); + } + + @Test + public void checkHashCodeIdenticalParams() { + SetParams firstParam = getDefaultValue(); + SetParams secondParam = getDefaultValue(); + assertEquals(firstParam.hashCode(), secondParam.hashCode()); + } + + @Test + public void checkEqualsVariousParams() { + SetParams firstParam = getDefaultValue(); + firstParam.nx(); + SetParams secondParam = getDefaultValue(); + secondParam.xx(); + assertFalse(firstParam.equals(secondParam)); + } + + @Test + public void checkHashCodeVariousParams() { + SetParams firstParam = getDefaultValue(); + firstParam.nx(); + SetParams secondParam = getDefaultValue(); + secondParam.xx(); + assertNotEquals(firstParam.hashCode(), secondParam.hashCode()); + } + + @Test + public void checkEqualsWithNull() { + SetParams firstParam = getDefaultValue(); + SetParams secondParam = null; + assertFalse(firstParam.equals(secondParam)); + } + + private SetParams getDefaultValue() { + return new SetParams(); + } +} diff --git a/src/test/java/redis/clients/jedis/params/ShutdownParamsTest.java b/src/test/java/redis/clients/jedis/params/ShutdownParamsTest.java new file mode 100644 index 00000000000..625e98b2958 --- /dev/null +++ b/src/test/java/redis/clients/jedis/params/ShutdownParamsTest.java @@ -0,0 +1,51 @@ +package redis.clients.jedis.params; + +import org.junit.Test; + +import static org.junit.Assert.*; + +public class ShutdownParamsTest { + + @Test + public void checkEqualsIdenticalParams() { + ShutdownParams firstParam = getDefaultValue(); + ShutdownParams secondParam = getDefaultValue(); + assertTrue(firstParam.equals(secondParam)); + } + + @Test + public void checkHashCodeIdenticalParams() { + ShutdownParams firstParam = getDefaultValue(); + ShutdownParams secondParam = getDefaultValue(); + assertEquals(firstParam.hashCode(), secondParam.hashCode()); + } + + @Test + public void checkEqualsVariousParams() { + ShutdownParams firstParam = getDefaultValue(); + firstParam.force(); + ShutdownParams secondParam = getDefaultValue(); + secondParam.nosave(); + assertFalse(firstParam.equals(secondParam)); + } + + @Test + public void checkHashCodeVariousParams() { + ShutdownParams firstParam = getDefaultValue(); + firstParam.force(); + ShutdownParams secondParam = getDefaultValue(); + secondParam.nosave(); + assertNotEquals(firstParam.hashCode(), secondParam.hashCode()); + } + + @Test + public void checkEqualsWithNull() { + ShutdownParams firstParam = getDefaultValue(); + ShutdownParams secondParam = null; + assertFalse(firstParam.equals(secondParam)); + } + + private ShutdownParams getDefaultValue() { + return new ShutdownParams(); + } +} diff --git a/src/test/java/redis/clients/jedis/params/SortingParamsTest.java b/src/test/java/redis/clients/jedis/params/SortingParamsTest.java new file mode 100644 index 00000000000..a66669584f3 --- /dev/null +++ b/src/test/java/redis/clients/jedis/params/SortingParamsTest.java @@ -0,0 +1,51 @@ +package redis.clients.jedis.params; + +import org.junit.Test; + +import static org.junit.Assert.*; + +public class SortingParamsTest { + + @Test + public void checkEqualsIdenticalParams() { + SortingParams firstParam = getDefaultValue(); + SortingParams secondParam = getDefaultValue(); + assertTrue(firstParam.equals(secondParam)); + } + + @Test + public void checkHashCodeIdenticalParams() { + SortingParams firstParam = getDefaultValue(); + SortingParams secondParam = getDefaultValue(); + assertEquals(firstParam.hashCode(), secondParam.hashCode()); + } + + @Test + public void checkEqualsVariousParams() { + SortingParams firstParam = getDefaultValue(); + firstParam.limit(15, 20); + SortingParams secondParam = getDefaultValue(); + secondParam.limit(10, 15); + assertFalse(firstParam.equals(secondParam)); + } + + @Test + public void checkHashCodeVariousParams() { + SortingParams firstParam = getDefaultValue(); + firstParam.limit(15, 20); + SortingParams secondParam = getDefaultValue(); + secondParam.limit(10, 15); + assertNotEquals(firstParam.hashCode(), secondParam.hashCode()); + } + + @Test + public void checkEqualsWithNull() { + SortingParams firstParam = getDefaultValue(); + SortingParams secondParam = null; + assertFalse(firstParam.equals(secondParam)); + } + + private SortingParams getDefaultValue() { + return new SortingParams(); + } +} diff --git a/src/test/java/redis/clients/jedis/params/XAddParamsTest.java b/src/test/java/redis/clients/jedis/params/XAddParamsTest.java new file mode 100644 index 00000000000..db3cac5e56f --- /dev/null +++ b/src/test/java/redis/clients/jedis/params/XAddParamsTest.java @@ -0,0 +1,51 @@ +package redis.clients.jedis.params; + +import org.junit.Test; + +import static org.junit.Assert.*; + +public class XAddParamsTest { + + @Test + public void checkEqualsIdenticalParams() { + XAddParams firstParam = getDefaultValue(); + XAddParams secondParam = getDefaultValue(); + assertTrue(firstParam.equals(secondParam)); + } + + @Test + public void checkHashCodeIdenticalParams() { + XAddParams firstParam = getDefaultValue(); + XAddParams secondParam = getDefaultValue(); + assertEquals(firstParam.hashCode(), secondParam.hashCode()); + } + + @Test + public void checkEqualsVariousParams() { + XAddParams firstParam = getDefaultValue(); + firstParam.id(15); + XAddParams secondParam = getDefaultValue(); + secondParam.id(20); + assertFalse(firstParam.equals(secondParam)); + } + + @Test + public void checkHashCodeVariousParams() { + XAddParams firstParam = getDefaultValue(); + firstParam.id(15); + XAddParams secondParam = getDefaultValue(); + secondParam.id(20); + assertNotEquals(firstParam.hashCode(), secondParam.hashCode()); + } + + @Test + public void checkEqualsWithNull() { + XAddParams firstParam = getDefaultValue(); + XAddParams secondParam = null; + assertFalse(firstParam.equals(secondParam)); + } + + private XAddParams getDefaultValue() { + return new XAddParams(); + } +} diff --git a/src/test/java/redis/clients/jedis/params/XAutoClaimParamsTest.java b/src/test/java/redis/clients/jedis/params/XAutoClaimParamsTest.java new file mode 100644 index 00000000000..eeb9aeb38a1 --- /dev/null +++ b/src/test/java/redis/clients/jedis/params/XAutoClaimParamsTest.java @@ -0,0 +1,51 @@ +package redis.clients.jedis.params; + +import org.junit.Test; + +import static org.junit.Assert.*; + +public class XAutoClaimParamsTest { + + @Test + public void checkEqualsIdenticalParams() { + XAutoClaimParams firstParam = getDefaultValue(); + XAutoClaimParams secondParam = getDefaultValue(); + assertTrue(firstParam.equals(secondParam)); + } + + @Test + public void checkHashCodeIdenticalParams() { + XAutoClaimParams firstParam = getDefaultValue(); + XAutoClaimParams secondParam = getDefaultValue(); + assertEquals(firstParam.hashCode(), secondParam.hashCode()); + } + + @Test + public void checkEqualsVariousParams() { + XAutoClaimParams firstParam = getDefaultValue(); + firstParam.count(15); + XAutoClaimParams secondParam = getDefaultValue(); + secondParam.count(20); + assertFalse(firstParam.equals(secondParam)); + } + + @Test + public void checkHashCodeVariousParams() { + XAutoClaimParams firstParam = getDefaultValue(); + firstParam.count(15); + XAutoClaimParams secondParam = getDefaultValue(); + secondParam.count(20); + assertNotEquals(firstParam.hashCode(), secondParam.hashCode()); + } + + @Test + public void checkEqualsWithNull() { + XAutoClaimParams firstParam = getDefaultValue(); + XAutoClaimParams secondParam = null; + assertFalse(firstParam.equals(secondParam)); + } + + private XAutoClaimParams getDefaultValue() { + return new XAutoClaimParams(); + } +} diff --git a/src/test/java/redis/clients/jedis/params/XClaimParamsTest.java b/src/test/java/redis/clients/jedis/params/XClaimParamsTest.java new file mode 100644 index 00000000000..1cef5b8dbea --- /dev/null +++ b/src/test/java/redis/clients/jedis/params/XClaimParamsTest.java @@ -0,0 +1,51 @@ +package redis.clients.jedis.params; + +import org.junit.Test; + +import static org.junit.Assert.*; + +public class XClaimParamsTest { + + @Test + public void checkEqualsIdenticalParams() { + XClaimParams firstParam = getDefaultValue(); + XClaimParams secondParam = getDefaultValue(); + assertTrue(firstParam.equals(secondParam)); + } + + @Test + public void checkHashCodeIdenticalParams() { + XClaimParams firstParam = getDefaultValue(); + XClaimParams secondParam = getDefaultValue(); + assertEquals(firstParam.hashCode(), secondParam.hashCode()); + } + + @Test + public void checkEqualsVariousParams() { + XClaimParams firstParam = getDefaultValue(); + firstParam.time(20); + XClaimParams secondParam = getDefaultValue(); + secondParam.time(21); + assertFalse(firstParam.equals(secondParam)); + } + + @Test + public void checkHashCodeVariousParams() { + XClaimParams firstParam = getDefaultValue(); + firstParam.time(20); + XClaimParams secondParam = getDefaultValue(); + secondParam.time(21); + assertNotEquals(firstParam.hashCode(), secondParam.hashCode()); + } + + @Test + public void checkEqualsWithNull() { + XClaimParams firstParam = getDefaultValue(); + XClaimParams secondParam = null; + assertFalse(firstParam.equals(secondParam)); + } + + private XClaimParams getDefaultValue() { + return new XClaimParams(); + } +} diff --git a/src/test/java/redis/clients/jedis/params/XPendingParamsTest.java b/src/test/java/redis/clients/jedis/params/XPendingParamsTest.java new file mode 100644 index 00000000000..b6698d875f7 --- /dev/null +++ b/src/test/java/redis/clients/jedis/params/XPendingParamsTest.java @@ -0,0 +1,52 @@ +package redis.clients.jedis.params; + +import org.junit.Test; +import redis.clients.jedis.StreamEntryID; + +import static org.junit.Assert.*; + +public class XPendingParamsTest { + + @Test + public void checkEqualsIdenticalParams() { + XPendingParams firstParam = getDefaultValue(); + XPendingParams secondParam = getDefaultValue(); + assertTrue(firstParam.equals(secondParam)); + } + + @Test + public void checkHashCodeIdenticalParams() { + XPendingParams firstParam = getDefaultValue(); + XPendingParams secondParam = getDefaultValue(); + assertEquals(firstParam.hashCode(), secondParam.hashCode()); + } + + @Test + public void checkEqualsVariousParams() { + XPendingParams firstParam = getDefaultValue(); + firstParam.start(StreamEntryID.LAST_ENTRY); + XPendingParams secondParam = getDefaultValue(); + secondParam.start(StreamEntryID.NEW_ENTRY); + assertFalse(firstParam.equals(secondParam)); + } + + @Test + public void checkHashCodeVariousParams() { + XPendingParams firstParam = getDefaultValue(); + firstParam.start(StreamEntryID.LAST_ENTRY); + XPendingParams secondParam = getDefaultValue(); + secondParam.start(StreamEntryID.NEW_ENTRY); + assertNotEquals(firstParam.hashCode(), secondParam.hashCode()); + } + + @Test + public void checkEqualsWithNull() { + XPendingParams firstParam = getDefaultValue(); + XPendingParams secondParam = null; + assertFalse(firstParam.equals(secondParam)); + } + + private XPendingParams getDefaultValue() { + return new XPendingParams(); + } +} diff --git a/src/test/java/redis/clients/jedis/params/XReadGroupParamsTest.java b/src/test/java/redis/clients/jedis/params/XReadGroupParamsTest.java new file mode 100644 index 00000000000..a489d50648a --- /dev/null +++ b/src/test/java/redis/clients/jedis/params/XReadGroupParamsTest.java @@ -0,0 +1,51 @@ +package redis.clients.jedis.params; + +import org.junit.Test; + +import static org.junit.Assert.*; + +public class XReadGroupParamsTest { + + @Test + public void checkEqualsIdenticalParams() { + XReadGroupParams firstParam = getDefaultValue(); + XReadGroupParams secondParam = getDefaultValue(); + assertTrue(firstParam.equals(secondParam)); + } + + @Test + public void checkHashCodeIdenticalParams() { + XReadGroupParams firstParam = getDefaultValue(); + XReadGroupParams secondParam = getDefaultValue(); + assertEquals(firstParam.hashCode(), secondParam.hashCode()); + } + + @Test + public void checkEqualsVariousParams() { + XReadGroupParams firstParam = getDefaultValue(); + firstParam.block(14); + XReadGroupParams secondParam = getDefaultValue(); + secondParam.block(15); + assertFalse(firstParam.equals(secondParam)); + } + + @Test + public void checkHashCodeVariousParams() { + XReadGroupParams firstParam = getDefaultValue(); + firstParam.block(14); + XReadGroupParams secondParam = getDefaultValue(); + secondParam.block(15); + assertNotEquals(firstParam.hashCode(), secondParam.hashCode()); + } + + @Test + public void checkEqualsWithNull() { + XReadGroupParams firstParam = getDefaultValue(); + XReadGroupParams secondParam = null; + assertFalse(firstParam.equals(secondParam)); + } + + private XReadGroupParams getDefaultValue() { + return new XReadGroupParams(); + } +} diff --git a/src/test/java/redis/clients/jedis/params/XReadParamsTest.java b/src/test/java/redis/clients/jedis/params/XReadParamsTest.java new file mode 100644 index 00000000000..d3277cd70f4 --- /dev/null +++ b/src/test/java/redis/clients/jedis/params/XReadParamsTest.java @@ -0,0 +1,51 @@ +package redis.clients.jedis.params; + +import org.junit.Test; + +import static org.junit.Assert.*; + +public class XReadParamsTest { + + @Test + public void checkEqualsIdenticalParams() { + XReadParams firstParam = getDefaultValue(); + XReadParams secondParam = getDefaultValue(); + assertTrue(firstParam.equals(secondParam)); + } + + @Test + public void checkHashCodeIdenticalParams() { + XReadParams firstParam = getDefaultValue(); + XReadParams secondParam = getDefaultValue(); + assertEquals(firstParam.hashCode(), secondParam.hashCode()); + } + + @Test + public void checkEqualsVariousParams() { + XReadParams firstParam = getDefaultValue(); + firstParam.block(14); + XReadParams secondParam = getDefaultValue(); + secondParam.block(15); + assertFalse(firstParam.equals(secondParam)); + } + + @Test + public void checkHashCodeVariousParams() { + XReadParams firstParam = getDefaultValue(); + firstParam.block(14); + XReadParams secondParam = getDefaultValue(); + secondParam.block(15); + assertNotEquals(firstParam.hashCode(), secondParam.hashCode()); + } + + @Test + public void checkEqualsWithNull() { + XReadParams firstParam = getDefaultValue(); + XReadParams secondParam = null; + assertFalse(firstParam.equals(secondParam)); + } + + private XReadParams getDefaultValue() { + return new XReadParams(); + } +} diff --git a/src/test/java/redis/clients/jedis/params/XTrimParamsTest.java b/src/test/java/redis/clients/jedis/params/XTrimParamsTest.java new file mode 100644 index 00000000000..dcd344816da --- /dev/null +++ b/src/test/java/redis/clients/jedis/params/XTrimParamsTest.java @@ -0,0 +1,51 @@ +package redis.clients.jedis.params; + +import org.junit.Test; + +import static org.junit.Assert.*; + +public class XTrimParamsTest { + + @Test + public void checkEqualsIdenticalParams() { + XTrimParams firstParam = getDefaultValue(); + XTrimParams secondParam = getDefaultValue(); + assertTrue(firstParam.equals(secondParam)); + } + + @Test + public void checkHashCodeIdenticalParams() { + XTrimParams firstParam = getDefaultValue(); + XTrimParams secondParam = getDefaultValue(); + assertEquals(firstParam.hashCode(), secondParam.hashCode()); + } + + @Test + public void checkEqualsVariousParams() { + XTrimParams firstParam = getDefaultValue(); + firstParam.maxLen(15); + XTrimParams secondParam = getDefaultValue(); + secondParam.maxLen(16); + assertFalse(firstParam.equals(secondParam)); + } + + @Test + public void checkHashCodeVariousParams() { + XTrimParams firstParam = getDefaultValue(); + firstParam.maxLen(15); + XTrimParams secondParam = getDefaultValue(); + secondParam.maxLen(16); + assertNotEquals(firstParam.hashCode(), secondParam.hashCode()); + } + + @Test + public void checkEqualsWithNull() { + XTrimParams firstParam = getDefaultValue(); + XTrimParams secondParam = null; + assertFalse(firstParam.equals(secondParam)); + } + + private XTrimParams getDefaultValue() { + return new XTrimParams(); + } +} diff --git a/src/test/java/redis/clients/jedis/params/ZAddParamsTest.java b/src/test/java/redis/clients/jedis/params/ZAddParamsTest.java new file mode 100644 index 00000000000..5d3148e415f --- /dev/null +++ b/src/test/java/redis/clients/jedis/params/ZAddParamsTest.java @@ -0,0 +1,51 @@ +package redis.clients.jedis.params; + +import org.junit.Test; + +import static org.junit.Assert.*; + +public class ZAddParamsTest { + + @Test + public void checkEqualsIdenticalParams() { + ZAddParams firstParam = getDefaultValue(); + ZAddParams secondParam = getDefaultValue(); + assertTrue(firstParam.equals(secondParam)); + } + + @Test + public void checkHashCodeIdenticalParams() { + ZAddParams firstParam = getDefaultValue(); + ZAddParams secondParam = getDefaultValue(); + assertEquals(firstParam.hashCode(), secondParam.hashCode()); + } + + @Test + public void checkEqualsVariousParams() { + ZAddParams firstParam = getDefaultValue(); + firstParam.nx(); + ZAddParams secondParam = getDefaultValue(); + secondParam.xx(); + assertFalse(firstParam.equals(secondParam)); + } + + @Test + public void checkHashCodeVariousParams() { + ZAddParams firstParam = getDefaultValue(); + firstParam.nx(); + ZAddParams secondParam = getDefaultValue(); + secondParam.xx(); + assertNotEquals(firstParam.hashCode(), secondParam.hashCode()); + } + + @Test + public void checkEqualsWithNull() { + ZAddParams firstParam = getDefaultValue(); + ZAddParams secondParam = null; + assertFalse(firstParam.equals(secondParam)); + } + + private ZAddParams getDefaultValue() { + return new ZAddParams(); + } +} diff --git a/src/test/java/redis/clients/jedis/params/ZIncrByParamsTest.java b/src/test/java/redis/clients/jedis/params/ZIncrByParamsTest.java new file mode 100644 index 00000000000..7e68e93cbea --- /dev/null +++ b/src/test/java/redis/clients/jedis/params/ZIncrByParamsTest.java @@ -0,0 +1,51 @@ +package redis.clients.jedis.params; + +import org.junit.Test; + +import static org.junit.Assert.*; + +public class ZIncrByParamsTest { + + @Test + public void checkEqualsIdenticalParams() { + ZIncrByParams firstParam = getDefaultValue(); + ZIncrByParams secondParam = getDefaultValue(); + assertTrue(firstParam.equals(secondParam)); + } + + @Test + public void checkHashCodeIdenticalParams() { + ZIncrByParams firstParam = getDefaultValue(); + ZIncrByParams secondParam = getDefaultValue(); + assertEquals(firstParam.hashCode(), secondParam.hashCode()); + } + + @Test + public void checkEqualsVariousParams() { + ZIncrByParams firstParam = getDefaultValue(); + firstParam.nx(); + ZIncrByParams secondParam = getDefaultValue(); + secondParam.xx(); + assertFalse(firstParam.equals(secondParam)); + } + + @Test + public void checkHashCodeVariousParams() { + ZIncrByParams firstParam = getDefaultValue(); + firstParam.nx(); + ZIncrByParams secondParam = getDefaultValue(); + secondParam.xx(); + assertNotEquals(firstParam.hashCode(), secondParam.hashCode()); + } + + @Test + public void checkEqualsWithNull() { + ZIncrByParams firstParam = getDefaultValue(); + ZIncrByParams secondParam = null; + assertFalse(firstParam.equals(secondParam)); + } + + private ZIncrByParams getDefaultValue() { + return new ZIncrByParams(); + } +} diff --git a/src/test/java/redis/clients/jedis/params/ZParamsTest.java b/src/test/java/redis/clients/jedis/params/ZParamsTest.java new file mode 100644 index 00000000000..902748a0544 --- /dev/null +++ b/src/test/java/redis/clients/jedis/params/ZParamsTest.java @@ -0,0 +1,51 @@ +package redis.clients.jedis.params; + +import org.junit.Test; + +import static org.junit.Assert.*; + +public class ZParamsTest { + + @Test + public void checkEqualsIdenticalParams() { + ZParams firstParam = getDefaultValue(); + ZParams secondParam = getDefaultValue(); + assertTrue(firstParam.equals(secondParam)); + } + + @Test + public void checkHashCodeIdenticalParams() { + ZParams firstParam = getDefaultValue(); + ZParams secondParam = getDefaultValue(); + assertEquals(firstParam.hashCode(), secondParam.hashCode()); + } + + @Test + public void checkEqualsVariousParams() { + ZParams firstParam = getDefaultValue(); + firstParam.aggregate(ZParams.Aggregate.MIN); + ZParams secondParam = getDefaultValue(); + secondParam.aggregate(ZParams.Aggregate.MAX); + assertFalse(firstParam.equals(secondParam)); + } + + @Test + public void checkHashCodeVariousParams() { + ZParams firstParam = getDefaultValue(); + firstParam.aggregate(ZParams.Aggregate.MIN); + ZParams secondParam = getDefaultValue(); + secondParam.aggregate(ZParams.Aggregate.MAX); + assertNotEquals(firstParam.hashCode(), secondParam.hashCode()); + } + + @Test + public void checkEqualsWithNull() { + ZParams firstParam = getDefaultValue(); + ZParams secondParam = null; + assertFalse(firstParam.equals(secondParam)); + } + + private ZParams getDefaultValue() { + return new ZParams(); + } +} diff --git a/src/test/java/redis/clients/jedis/params/ZRangeParamsTest.java b/src/test/java/redis/clients/jedis/params/ZRangeParamsTest.java new file mode 100644 index 00000000000..a2f5e02105d --- /dev/null +++ b/src/test/java/redis/clients/jedis/params/ZRangeParamsTest.java @@ -0,0 +1,51 @@ +package redis.clients.jedis.params; + +import org.junit.Test; + +import static org.junit.Assert.*; + +public class ZRangeParamsTest { + + @Test + public void checkEqualsIdenticalParams() { + ZRangeParams firstParam = getDefaultValue(); + ZRangeParams secondParam = getDefaultValue(); + assertTrue(firstParam.equals(secondParam)); + } + + @Test + public void checkHashCodeIdenticalParams() { + ZRangeParams firstParam = getDefaultValue(); + ZRangeParams secondParam = getDefaultValue(); + assertEquals(firstParam.hashCode(), secondParam.hashCode()); + } + + @Test + public void checkEqualsVariousParams() { + ZRangeParams firstParam = getDefaultValue(); + firstParam.limit(15, 20); + ZRangeParams secondParam = getDefaultValue(); + secondParam.limit(16, 21); + assertFalse(firstParam.equals(secondParam)); + } + + @Test + public void checkHashCodeVariousParams() { + ZRangeParams firstParam = getDefaultValue(); + firstParam.limit(15, 20); + ZRangeParams secondParam = getDefaultValue(); + secondParam.limit(16, 21); + assertNotEquals(firstParam.hashCode(), secondParam.hashCode()); + } + + @Test + public void checkEqualsWithNull() { + ZRangeParams firstParam = getDefaultValue(); + ZRangeParams secondParam = null; + assertFalse(firstParam.equals(secondParam)); + } + + private ZRangeParams getDefaultValue() { + return new ZRangeParams(0, 0); + } +} From 845a01f375975131283ff8d005e7d29493eb295d Mon Sep 17 00:00:00 2001 From: Gabriel Erzse Date: Mon, 25 Mar 2024 15:08:55 +0200 Subject: [PATCH 26/33] Align Pipelined commands with UnifiedJedis (#3787) * Align Pipelined commands with UnifiedJedis Add some Pipelined commands that are available in UnifiedJedis but are missing the pipelined version. * Pipeline does not need scriptKill Co-authored-by: M Sazzadul Hoque <7600764+sazzad16@users.noreply.github.com> * Undo script commands changes --------- Co-authored-by: Gabriel Erzse Co-authored-by: M Sazzadul Hoque <7600764+sazzad16@users.noreply.github.com> --- .../java/redis/clients/jedis/PipeliningBase.java | 15 +++++++++++++++ .../commands/CuckooFilterPipelineCommands.java | 2 ++ .../RedisTimeSeriesPipelineCommands.java | 4 ++++ 3 files changed, 21 insertions(+) diff --git a/src/main/java/redis/clients/jedis/PipeliningBase.java b/src/main/java/redis/clients/jedis/PipeliningBase.java index 945d34f615d..b35d1fd4234 100644 --- a/src/main/java/redis/clients/jedis/PipeliningBase.java +++ b/src/main/java/redis/clients/jedis/PipeliningBase.java @@ -3907,6 +3907,16 @@ public Response tsDeleteRule(String sourceKey, String destKey) { public Response> tsQueryIndex(String... filters) { return appendCommand(commandObjects.tsQueryIndex(filters)); } + + @Override + public Response tsInfo(String key) { + return appendCommand(commandObjects.tsInfo(key)); + } + + @Override + public Response tsInfoDebug(String key) { + return appendCommand(commandObjects.tsInfoDebug(key)); + } // RedisTimeSeries commands // RedisBloom commands @@ -4015,6 +4025,11 @@ public Response cfExists(String key, String item) { return appendCommand(commandObjects.cfExists(key, item)); } + @Override + public Response> cfMExists(String key, String... items) { + return appendCommand(commandObjects.cfMExists(key, items)); + } + @Override public Response cfDel(String key, String item) { return appendCommand(commandObjects.cfDel(key, item)); diff --git a/src/main/java/redis/clients/jedis/bloom/commands/CuckooFilterPipelineCommands.java b/src/main/java/redis/clients/jedis/bloom/commands/CuckooFilterPipelineCommands.java index b911d741ea1..c40d6a861b4 100644 --- a/src/main/java/redis/clients/jedis/bloom/commands/CuckooFilterPipelineCommands.java +++ b/src/main/java/redis/clients/jedis/bloom/commands/CuckooFilterPipelineCommands.java @@ -26,6 +26,8 @@ public interface CuckooFilterPipelineCommands { Response cfExists(String key, String item); + Response> cfMExists(String key, String... items); + Response cfDel(String key, String item); Response cfCount(String key, String item); diff --git a/src/main/java/redis/clients/jedis/timeseries/RedisTimeSeriesPipelineCommands.java b/src/main/java/redis/clients/jedis/timeseries/RedisTimeSeriesPipelineCommands.java index 85ad9e0b1e4..288b3f195e9 100644 --- a/src/main/java/redis/clients/jedis/timeseries/RedisTimeSeriesPipelineCommands.java +++ b/src/main/java/redis/clients/jedis/timeseries/RedisTimeSeriesPipelineCommands.java @@ -59,4 +59,8 @@ public interface RedisTimeSeriesPipelineCommands { Response tsDeleteRule(String sourceKey, String destKey); Response> tsQueryIndex(String... filters); + + Response tsInfo(String key); + + Response tsInfoDebug(String key); } From bad18b916bc9c30aa58edb4676c6d6c8f571ab63 Mon Sep 17 00:00:00 2001 From: M Sazzadul Hoque <7600764+sazzad16@users.noreply.github.com> Date: Tue, 26 Mar 2024 12:48:17 +0600 Subject: [PATCH 27/33] Add Experimental, Internal and VisibleForTesting annotations (#3790) * Add Experimental, Internal and VisibleForTesting annotations * Use VisibleForTesting annotation * Use Internal annotation * Use Experimental annotation --- .../clients/jedis/JedisClusterInfoCache.java | 6 +++++- .../clients/jedis/MultiClusterClientConfig.java | 2 ++ .../java/redis/clients/jedis/UnifiedJedis.java | 2 ++ .../clients/jedis/annots/Experimental.java | 17 +++++++++++++++++ .../redis/clients/jedis/annots/Internal.java | 17 +++++++++++++++++ .../clients/jedis/annots/VisibleForTesting.java | 12 ++++++++++++ .../jedis/executors/ClusterCommandExecutor.java | 3 +++ .../executors/RetryableCommandExecutor.java | 3 +++ .../mcf/CircuitBreakerCommandExecutor.java | 2 ++ .../jedis/mcf/CircuitBreakerFailoverBase.java | 2 ++ ...ircuitBreakerFailoverConnectionProvider.java | 2 ++ .../clients/jedis/mcf/MultiClusterPipeline.java | 2 ++ .../jedis/mcf/MultiClusterTransaction.java | 2 ++ .../MultiClusterPooledConnectionProvider.java | 2 ++ 14 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 src/main/java/redis/clients/jedis/annots/Experimental.java create mode 100644 src/main/java/redis/clients/jedis/annots/Internal.java create mode 100644 src/main/java/redis/clients/jedis/annots/VisibleForTesting.java diff --git a/src/main/java/redis/clients/jedis/JedisClusterInfoCache.java b/src/main/java/redis/clients/jedis/JedisClusterInfoCache.java index bea4982fd4e..da88462ef49 100644 --- a/src/main/java/redis/clients/jedis/JedisClusterInfoCache.java +++ b/src/main/java/redis/clients/jedis/JedisClusterInfoCache.java @@ -11,22 +11,26 @@ import java.util.Map; import java.util.Map.Entry; import java.util.Set; + import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock; import java.util.concurrent.locks.ReentrantReadWriteLock; -import org.apache.commons.pool2.impl.GenericObjectPoolConfig; +import org.apache.commons.pool2.impl.GenericObjectPoolConfig; import org.slf4j.Logger; import org.slf4j.LoggerFactory; + +import redis.clients.jedis.annots.Internal; import redis.clients.jedis.exceptions.JedisClusterOperationException; import redis.clients.jedis.exceptions.JedisException; import redis.clients.jedis.util.SafeEncoder; import static redis.clients.jedis.JedisCluster.INIT_NO_ERROR_PROPERTY; +@Internal public class JedisClusterInfoCache { private static final Logger logger = LoggerFactory.getLogger(JedisClusterInfoCache.class); diff --git a/src/main/java/redis/clients/jedis/MultiClusterClientConfig.java b/src/main/java/redis/clients/jedis/MultiClusterClientConfig.java index 15956ebed48..10dff9ef642 100644 --- a/src/main/java/redis/clients/jedis/MultiClusterClientConfig.java +++ b/src/main/java/redis/clients/jedis/MultiClusterClientConfig.java @@ -7,6 +7,7 @@ import java.util.Arrays; import java.util.List; +import redis.clients.jedis.annots.Experimental; import redis.clients.jedis.exceptions.JedisConnectionException; import redis.clients.jedis.exceptions.JedisValidationException; @@ -25,6 +26,7 @@ *

*/ // TODO: move +@Experimental public final class MultiClusterClientConfig { private static final int RETRY_MAX_ATTEMPTS_DEFAULT = 3; diff --git a/src/main/java/redis/clients/jedis/UnifiedJedis.java b/src/main/java/redis/clients/jedis/UnifiedJedis.java index 138300c451e..b8137d35363 100644 --- a/src/main/java/redis/clients/jedis/UnifiedJedis.java +++ b/src/main/java/redis/clients/jedis/UnifiedJedis.java @@ -9,6 +9,7 @@ import org.apache.commons.pool2.impl.GenericObjectPoolConfig; import org.json.JSONArray; +import redis.clients.jedis.annots.Experimental; import redis.clients.jedis.args.*; import redis.clients.jedis.bloom.*; import redis.clients.jedis.commands.JedisCommands; @@ -192,6 +193,7 @@ public UnifiedJedis(ConnectionProvider provider, int maxAttempts, Duration maxTo * by using simple configuration which is passed through from Resilience4j - https://resilience4j.readme.io/docs *

*/ + @Experimental public UnifiedJedis(MultiClusterPooledConnectionProvider provider) { this(new CircuitBreakerCommandExecutor(provider), provider); } diff --git a/src/main/java/redis/clients/jedis/annots/Experimental.java b/src/main/java/redis/clients/jedis/annots/Experimental.java new file mode 100644 index 00000000000..e0c642e6309 --- /dev/null +++ b/src/main/java/redis/clients/jedis/annots/Experimental.java @@ -0,0 +1,17 @@ +package redis.clients.jedis.annots; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Target; + +/** + * Annotation to mark classes for experimental development. + *

+ * Classes with this annotation may be renamed, changed or even removed in a future version. This + * annotation doesn't mean that the implementation has an 'experimental' quality. + *

+ * If a type is marked with this annotation, all its members are considered experimental. + */ +@Documented +@Target({ElementType.TYPE, ElementType.METHOD, ElementType.FIELD, ElementType.CONSTRUCTOR}) +public @interface Experimental { } diff --git a/src/main/java/redis/clients/jedis/annots/Internal.java b/src/main/java/redis/clients/jedis/annots/Internal.java new file mode 100644 index 00000000000..551460e834e --- /dev/null +++ b/src/main/java/redis/clients/jedis/annots/Internal.java @@ -0,0 +1,17 @@ +package redis.clients.jedis.annots; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Target; + +/** + * Annotation to mark classes or methods as an internal development API. It indicates that the + * annotated element must not be considered as a public API. + *

+ * Classes or methods with this annotation may change across releases. + *

+ * If a type is marked with this annotation, all its members are considered internal. + */ +@Documented +@Target({ElementType.TYPE, ElementType.METHOD, ElementType.CONSTRUCTOR, ElementType.FIELD}) +public @interface Internal { } \ No newline at end of file diff --git a/src/main/java/redis/clients/jedis/annots/VisibleForTesting.java b/src/main/java/redis/clients/jedis/annots/VisibleForTesting.java new file mode 100644 index 00000000000..e9aac5c7b3d --- /dev/null +++ b/src/main/java/redis/clients/jedis/annots/VisibleForTesting.java @@ -0,0 +1,12 @@ +package redis.clients.jedis.annots; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Target; + +/** + * A member or type annotated with {@link VisibleForTesting} declares that it is only visible for testing purposes. + */ +@Documented +@Target({ElementType.METHOD, ElementType.CONSTRUCTOR, ElementType.FIELD, ElementType.TYPE}) +public @interface VisibleForTesting { } diff --git a/src/main/java/redis/clients/jedis/executors/ClusterCommandExecutor.java b/src/main/java/redis/clients/jedis/executors/ClusterCommandExecutor.java index 4cc25c42a9d..375db99e140 100644 --- a/src/main/java/redis/clients/jedis/executors/ClusterCommandExecutor.java +++ b/src/main/java/redis/clients/jedis/executors/ClusterCommandExecutor.java @@ -13,6 +13,7 @@ import redis.clients.jedis.ConnectionPool; import redis.clients.jedis.HostAndPort; import redis.clients.jedis.Protocol; +import redis.clients.jedis.annots.VisibleForTesting; import redis.clients.jedis.exceptions.*; import redis.clients.jedis.providers.ClusterConnectionProvider; import redis.clients.jedis.util.IOUtils; @@ -135,6 +136,7 @@ public final T executeCommand(CommandObject commandObject) { * WARNING: This method is accessible for the purpose of testing. * This should not be used or overriden. */ + @VisibleForTesting protected T execute(Connection connection, CommandObject commandObject) { return connection.executeCommand(commandObject); } @@ -193,6 +195,7 @@ private static long getBackoffSleepMillis(int attemptsLeft, Instant deadline) { * WARNING: This method is accessible for the purpose of testing. * This should not be used or overriden. */ + @VisibleForTesting protected void sleep(long sleepMillis) { try { TimeUnit.MILLISECONDS.sleep(sleepMillis); diff --git a/src/main/java/redis/clients/jedis/executors/RetryableCommandExecutor.java b/src/main/java/redis/clients/jedis/executors/RetryableCommandExecutor.java index f4f90025391..4351f3fab46 100644 --- a/src/main/java/redis/clients/jedis/executors/RetryableCommandExecutor.java +++ b/src/main/java/redis/clients/jedis/executors/RetryableCommandExecutor.java @@ -8,6 +8,7 @@ import redis.clients.jedis.CommandObject; import redis.clients.jedis.Connection; +import redis.clients.jedis.annots.VisibleForTesting; import redis.clients.jedis.exceptions.JedisConnectionException; import redis.clients.jedis.exceptions.JedisException; import redis.clients.jedis.util.IOUtils; @@ -75,6 +76,7 @@ public final T executeCommand(CommandObject commandObject) { * WARNING: This method is accessible for the purpose of testing. * This should not be used or overriden. */ + @VisibleForTesting protected T execute(Connection connection, CommandObject commandObject) { return connection.executeCommand(commandObject); } @@ -115,6 +117,7 @@ private static long getBackoffSleepMillis(int attemptsLeft, Instant deadline) { * WARNING: This method is accessible for the purpose of testing. * This should not be used or overriden. */ + @VisibleForTesting protected void sleep(long sleepMillis) { try { TimeUnit.MILLISECONDS.sleep(sleepMillis); diff --git a/src/main/java/redis/clients/jedis/mcf/CircuitBreakerCommandExecutor.java b/src/main/java/redis/clients/jedis/mcf/CircuitBreakerCommandExecutor.java index 38b32bbad08..5d54b67d171 100644 --- a/src/main/java/redis/clients/jedis/mcf/CircuitBreakerCommandExecutor.java +++ b/src/main/java/redis/clients/jedis/mcf/CircuitBreakerCommandExecutor.java @@ -6,6 +6,7 @@ import redis.clients.jedis.CommandObject; import redis.clients.jedis.Connection; +import redis.clients.jedis.annots.Experimental; import redis.clients.jedis.executors.CommandExecutor; import redis.clients.jedis.providers.MultiClusterPooledConnectionProvider; import redis.clients.jedis.providers.MultiClusterPooledConnectionProvider.Cluster; @@ -18,6 +19,7 @@ * by using simple configuration which is passed through from Resilience4j - https://resilience4j.readme.io/docs *

*/ +@Experimental public class CircuitBreakerCommandExecutor extends CircuitBreakerFailoverBase implements CommandExecutor { public CircuitBreakerCommandExecutor(MultiClusterPooledConnectionProvider provider) { diff --git a/src/main/java/redis/clients/jedis/mcf/CircuitBreakerFailoverBase.java b/src/main/java/redis/clients/jedis/mcf/CircuitBreakerFailoverBase.java index b06d7b96042..4ef383e6494 100644 --- a/src/main/java/redis/clients/jedis/mcf/CircuitBreakerFailoverBase.java +++ b/src/main/java/redis/clients/jedis/mcf/CircuitBreakerFailoverBase.java @@ -1,6 +1,7 @@ package redis.clients.jedis.mcf; import io.github.resilience4j.circuitbreaker.CircuitBreaker; +import redis.clients.jedis.annots.Experimental; import redis.clients.jedis.exceptions.JedisConnectionException; import redis.clients.jedis.providers.MultiClusterPooledConnectionProvider; import redis.clients.jedis.util.IOUtils; @@ -14,6 +15,7 @@ * Resilience4j - https://resilience4j.readme.io/docs *

*/ +@Experimental public class CircuitBreakerFailoverBase implements AutoCloseable { protected final MultiClusterPooledConnectionProvider provider; diff --git a/src/main/java/redis/clients/jedis/mcf/CircuitBreakerFailoverConnectionProvider.java b/src/main/java/redis/clients/jedis/mcf/CircuitBreakerFailoverConnectionProvider.java index 10a0823973d..cd0e91015a3 100644 --- a/src/main/java/redis/clients/jedis/mcf/CircuitBreakerFailoverConnectionProvider.java +++ b/src/main/java/redis/clients/jedis/mcf/CircuitBreakerFailoverConnectionProvider.java @@ -5,6 +5,7 @@ import io.github.resilience4j.decorators.Decorators.DecorateSupplier; import redis.clients.jedis.Connection; +import redis.clients.jedis.annots.Experimental; import redis.clients.jedis.providers.MultiClusterPooledConnectionProvider; import redis.clients.jedis.providers.MultiClusterPooledConnectionProvider.Cluster; @@ -13,6 +14,7 @@ * With this executor users can seamlessly failover to Disaster Recovery (DR), Backup, and Active-Active cluster(s) * by using simple configuration which is passed through from Resilience4j - https://resilience4j.readme.io/docs */ +@Experimental public class CircuitBreakerFailoverConnectionProvider extends CircuitBreakerFailoverBase { public CircuitBreakerFailoverConnectionProvider(MultiClusterPooledConnectionProvider provider) { diff --git a/src/main/java/redis/clients/jedis/mcf/MultiClusterPipeline.java b/src/main/java/redis/clients/jedis/mcf/MultiClusterPipeline.java index 00c0ba1d911..d7f1416e346 100644 --- a/src/main/java/redis/clients/jedis/mcf/MultiClusterPipeline.java +++ b/src/main/java/redis/clients/jedis/mcf/MultiClusterPipeline.java @@ -7,6 +7,7 @@ import java.util.Queue; import redis.clients.jedis.*; +import redis.clients.jedis.annots.Experimental; import redis.clients.jedis.graph.ResultSet; import redis.clients.jedis.providers.MultiClusterPooledConnectionProvider; import redis.clients.jedis.util.KeyValue; @@ -15,6 +16,7 @@ * This is high memory dependent solution as all the appending commands will be hold in memory until * {@link MultiClusterPipeline#sync() SYNC} (or {@link MultiClusterPipeline#close() CLOSE}) gets called. */ +@Experimental public class MultiClusterPipeline extends PipelineBase implements Closeable { private final CircuitBreakerFailoverConnectionProvider failoverProvider; diff --git a/src/main/java/redis/clients/jedis/mcf/MultiClusterTransaction.java b/src/main/java/redis/clients/jedis/mcf/MultiClusterTransaction.java index d759ce1da0a..f39cdf36b69 100644 --- a/src/main/java/redis/clients/jedis/mcf/MultiClusterTransaction.java +++ b/src/main/java/redis/clients/jedis/mcf/MultiClusterTransaction.java @@ -14,6 +14,7 @@ import java.util.concurrent.atomic.AtomicInteger; import redis.clients.jedis.*; +import redis.clients.jedis.annots.Experimental; import redis.clients.jedis.exceptions.JedisDataException; import redis.clients.jedis.graph.ResultSet; import redis.clients.jedis.providers.MultiClusterPooledConnectionProvider; @@ -22,6 +23,7 @@ /** * This is high memory dependent solution as all the appending commands will be hold in memory. */ +@Experimental public class MultiClusterTransaction extends TransactionBase { private static final Builder NO_OP_BUILDER = BuilderFactory.RAW_OBJECT; diff --git a/src/main/java/redis/clients/jedis/providers/MultiClusterPooledConnectionProvider.java b/src/main/java/redis/clients/jedis/providers/MultiClusterPooledConnectionProvider.java index e6013a2c585..f26716086ee 100644 --- a/src/main/java/redis/clients/jedis/providers/MultiClusterPooledConnectionProvider.java +++ b/src/main/java/redis/clients/jedis/providers/MultiClusterPooledConnectionProvider.java @@ -19,6 +19,7 @@ import redis.clients.jedis.*; import redis.clients.jedis.MultiClusterClientConfig.ClusterConfig; +import redis.clients.jedis.annots.Experimental; import redis.clients.jedis.exceptions.JedisConnectionException; import redis.clients.jedis.exceptions.JedisValidationException; import redis.clients.jedis.util.Pool; @@ -35,6 +36,7 @@ *

*/ // TODO: move? +@Experimental public class MultiClusterPooledConnectionProvider implements ConnectionProvider { private final Logger log = LoggerFactory.getLogger(getClass()); From a02b2eb2dcb1c9ff31afe3fa91ebdd3fad8cad7e Mon Sep 17 00:00:00 2001 From: M Sazzadul Hoque <7600764+sazzad16@users.noreply.github.com> Date: Wed, 27 Mar 2024 19:15:58 +0600 Subject: [PATCH 28/33] Add last entry id for XREADs and support XREADs reply as map (#3791) --- .../redis/clients/jedis/BuilderFactory.java | 37 +++- .../redis/clients/jedis/CommandObjects.java | 21 +++ src/main/java/redis/clients/jedis/Jedis.java | 18 +- .../redis/clients/jedis/PipeliningBase.java | 10 ++ .../redis/clients/jedis/StreamEntryID.java | 57 ++++++- .../redis/clients/jedis/UnifiedJedis.java | 11 ++ .../jedis/commands/StreamCommands.java | 12 ++ .../commands/StreamPipelineCommands.java | 12 ++ .../commands/jedis/StreamsCommandsTest.java | 161 +++++++++++++----- .../pipeline/StreamsPipelineCommandsTest.java | 58 ++++--- .../jedis/params/XPendingParamsTest.java | 4 +- 11 files changed, 310 insertions(+), 91 deletions(-) diff --git a/src/main/java/redis/clients/jedis/BuilderFactory.java b/src/main/java/redis/clients/jedis/BuilderFactory.java index 18bcc5a31c2..83e552de839 100644 --- a/src/main/java/redis/clients/jedis/BuilderFactory.java +++ b/src/main/java/redis/clients/jedis/BuilderFactory.java @@ -1420,10 +1420,10 @@ public List>> build(Object data) { .collect(Collectors.toList()); } else { List>> result = new ArrayList<>(list.size()); - for (Object streamObj : list) { - List stream = (List) streamObj; - String streamKey = STRING.build(stream.get(0)); - List streamEntries = STREAM_ENTRY_LIST.build(stream.get(1)); + for (Object anObj : list) { + List streamObj = (List) anObj; + String streamKey = STRING.build(streamObj.get(0)); + List streamEntries = STREAM_ENTRY_LIST.build(streamObj.get(1)); result.add(KeyValue.of(streamKey, streamEntries)); } return result; @@ -1436,6 +1436,35 @@ public String toString() { } }; + public static final Builder>> STREAM_READ_MAP_RESPONSE + = new Builder>>() { + @Override + public Map> build(Object data) { + if (data == null) return null; + List list = (List) data; + if (list.isEmpty()) return Collections.emptyMap(); + + if (list.get(0) instanceof KeyValue) { + return ((List) list).stream() + .collect(Collectors.toMap(kv -> STRING.build(kv.getKey()), kv -> STREAM_ENTRY_LIST.build(kv.getValue()))); + } else { + Map> result = new HashMap<>(list.size()); + for (Object anObj : list) { + List streamObj = (List) anObj; + String streamKey = STRING.build(streamObj.get(0)); + List streamEntries = STREAM_ENTRY_LIST.build(streamObj.get(1)); + result.put(streamKey, streamEntries); + } + return result; + } + } + + @Override + public String toString() { + return "Map>"; + } + }; + public static final Builder> STREAM_PENDING_ENTRY_LIST = new Builder>() { @Override @SuppressWarnings("unchecked") diff --git a/src/main/java/redis/clients/jedis/CommandObjects.java b/src/main/java/redis/clients/jedis/CommandObjects.java index 1de7affa6a8..139fa78ae8f 100644 --- a/src/main/java/redis/clients/jedis/CommandObjects.java +++ b/src/main/java/redis/clients/jedis/CommandObjects.java @@ -2666,6 +2666,15 @@ public final CommandObject>>> xread( return new CommandObject<>(args, BuilderFactory.STREAM_READ_RESPONSE); } + public final CommandObject>> xreadAsMap( + XReadParams xReadParams, Map streams) { + CommandArguments args = commandArguments(XREAD).addParams(xReadParams).add(STREAMS); + Set> entrySet = streams.entrySet(); + entrySet.forEach(entry -> args.key(entry.getKey())); + entrySet.forEach(entry -> args.add(entry.getValue())); + return new CommandObject<>(args, BuilderFactory.STREAM_READ_MAP_RESPONSE); + } + public final CommandObject>>> xreadGroup( String groupName, String consumer, XReadGroupParams xReadGroupParams, Map streams) { @@ -2678,6 +2687,18 @@ public final CommandObject>>> xreadGrou return new CommandObject<>(args, BuilderFactory.STREAM_READ_RESPONSE); } + public final CommandObject>> xreadGroupAsMap( + String groupName, String consumer, XReadGroupParams xReadGroupParams, + Map streams) { + CommandArguments args = commandArguments(XREADGROUP) + .add(GROUP).add(groupName).add(consumer) + .addParams(xReadGroupParams).add(STREAMS); + Set> entrySet = streams.entrySet(); + entrySet.forEach(entry -> args.key(entry.getKey())); + entrySet.forEach(entry -> args.add(entry.getValue())); + return new CommandObject<>(args, BuilderFactory.STREAM_READ_MAP_RESPONSE); + } + public final CommandObject> xread(XReadParams xReadParams, Map.Entry... streams) { CommandArguments args = commandArguments(XREAD).addParams(xReadParams).add(STREAMS); for (Map.Entry entry : streams) { diff --git a/src/main/java/redis/clients/jedis/Jedis.java b/src/main/java/redis/clients/jedis/Jedis.java index a9f6ceafe7c..03a2bc1ed18 100644 --- a/src/main/java/redis/clients/jedis/Jedis.java +++ b/src/main/java/redis/clients/jedis/Jedis.java @@ -9394,6 +9394,12 @@ public List>> xread(final XReadParams xReadP return connection.executeCommand(commandObjects.xread(xReadParams, streams)); } + @Override + public Map> xreadAsMap(final XReadParams xReadParams, final Map streams) { + checkIsInMultiOrPipeline(); + return connection.executeCommand(commandObjects.xreadAsMap(xReadParams, streams)); + } + @Override public long xack(final String key, final String group, final StreamEntryID... ids) { checkIsInMultiOrPipeline(); @@ -9450,13 +9456,19 @@ public long xtrim(final String key, final XTrimParams params) { } @Override - public List>> xreadGroup(final String groupName, - final String consumer, final XReadGroupParams xReadGroupParams, - final Map streams) { + public List>> xreadGroup(final String groupName, final String consumer, + final XReadGroupParams xReadGroupParams, final Map streams) { checkIsInMultiOrPipeline(); return connection.executeCommand(commandObjects.xreadGroup(groupName, consumer, xReadGroupParams, streams)); } + @Override + public Map> xreadGroupAsMap(final String groupName, final String consumer, + final XReadGroupParams xReadGroupParams, final Map streams) { + checkIsInMultiOrPipeline(); + return connection.executeCommand(commandObjects.xreadGroupAsMap(groupName, consumer, xReadGroupParams, streams)); + } + @Override public StreamPendingSummary xpending(final String key, final String groupName) { checkIsInMultiOrPipeline(); diff --git a/src/main/java/redis/clients/jedis/PipeliningBase.java b/src/main/java/redis/clients/jedis/PipeliningBase.java index b35d1fd4234..2dac5af7120 100644 --- a/src/main/java/redis/clients/jedis/PipeliningBase.java +++ b/src/main/java/redis/clients/jedis/PipeliningBase.java @@ -1536,11 +1536,21 @@ public Response>>> xread(XReadParams xR return appendCommand(commandObjects.xread(xReadParams, streams)); } + @Override + public Response>> xreadAsMap(XReadParams xReadParams, Map streams) { + return appendCommand(commandObjects.xreadAsMap(xReadParams, streams)); + } + @Override public Response>>> xreadGroup(String groupName, String consumer, XReadGroupParams xReadGroupParams, Map streams) { return appendCommand(commandObjects.xreadGroup(groupName, consumer, xReadGroupParams, streams)); } + @Override + public Response>> xreadGroupAsMap(String groupName, String consumer, XReadGroupParams xReadGroupParams, Map streams) { + return appendCommand(commandObjects.xreadGroupAsMap(groupName, consumer, xReadGroupParams, streams)); + } + @Override public Response eval(String script) { return appendCommand(commandObjects.eval(script)); diff --git a/src/main/java/redis/clients/jedis/StreamEntryID.java b/src/main/java/redis/clients/jedis/StreamEntryID.java index 9644010d7c9..5381638b5a0 100644 --- a/src/main/java/redis/clients/jedis/StreamEntryID.java +++ b/src/main/java/redis/clients/jedis/StreamEntryID.java @@ -80,9 +80,7 @@ private void readObject(java.io.ObjectInputStream in) throws IOException, ClassN /** * Should be used only with XADD * - * - * XADD mystream * field1 value1 - * + * {@code XADD mystream * field1 value1} */ public static final StreamEntryID NEW_ENTRY = new StreamEntryID() { @@ -97,11 +95,31 @@ public String toString() { /** * Should be used only with XGROUP CREATE * - * - * XGROUP CREATE mystream consumer-group-name $ - * + * {@code XGROUP CREATE mystream consumer-group-name $} */ - public static final StreamEntryID LAST_ENTRY = new StreamEntryID() { + public static final StreamEntryID XGROUP_LAST_ENTRY = new StreamEntryID() { + + private static final long serialVersionUID = 1L; + + @Override + public String toString() { + return "$"; + } + }; + + /** + * @deprecated Use {@link StreamEntryID#XGROUP_LAST_ENTRY} for XGROUP CREATE command or + * {@link StreamEntryID#XREAD_NEW_ENTRY} for XREAD command. + */ + @Deprecated + public static final StreamEntryID LAST_ENTRY = XGROUP_LAST_ENTRY; + + /** + * Should be used only with XREAD + * + * {@code XREAD BLOCK 5000 COUNT 100 STREAMS mystream $} + */ + public static final StreamEntryID XREAD_NEW_ENTRY = new StreamEntryID() { private static final long serialVersionUID = 1L; @@ -114,9 +132,9 @@ public String toString() { /** * Should be used only with XREADGROUP *

- * {@code XREADGROUP $GroupName $ConsumerName BLOCK 2000 COUNT 10 STREAMS mystream >} + * {@code XREADGROUP GROUP mygroup myconsumer STREAMS mystream >} */ - public static final StreamEntryID UNRECEIVED_ENTRY = new StreamEntryID() { + public static final StreamEntryID XREADGROUP_UNDELIVERED_ENTRY = new StreamEntryID() { private static final long serialVersionUID = 1L; @@ -126,6 +144,12 @@ public String toString() { } }; + /** + * @deprecated Use {@link StreamEntryID#XREADGROUP_UNDELIVERED_ENTRY}. + */ + @Deprecated + public static final StreamEntryID UNRECEIVED_ENTRY = XREADGROUP_UNDELIVERED_ENTRY; + /** * Can be used in XRANGE, XREVRANGE and XPENDING commands. */ @@ -151,4 +175,19 @@ public String toString() { return "+"; } }; + + /** + * Should be used only with XREAD + * + * {@code XREAD STREAMS mystream +} + */ + public static final StreamEntryID XREAD_LAST_ENTRY = new StreamEntryID() { + + private static final long serialVersionUID = 1L; + + @Override + public String toString() { + return "+"; + } + }; } diff --git a/src/main/java/redis/clients/jedis/UnifiedJedis.java b/src/main/java/redis/clients/jedis/UnifiedJedis.java index b8137d35363..42aa67ae74b 100644 --- a/src/main/java/redis/clients/jedis/UnifiedJedis.java +++ b/src/main/java/redis/clients/jedis/UnifiedJedis.java @@ -3066,12 +3066,23 @@ public List>> xread(XReadParams xReadParams, return executeCommand(commandObjects.xread(xReadParams, streams)); } + @Override + public Map> xreadAsMap(XReadParams xReadParams, Map streams) { + return executeCommand(commandObjects.xreadAsMap(xReadParams, streams)); + } + @Override public List>> xreadGroup(String groupName, String consumer, XReadGroupParams xReadGroupParams, Map streams) { return executeCommand(commandObjects.xreadGroup(groupName, consumer, xReadGroupParams, streams)); } + @Override + public Map> xreadGroupAsMap(String groupName, String consumer, + XReadGroupParams xReadGroupParams, Map streams) { + return executeCommand(commandObjects.xreadGroupAsMap(groupName, consumer, xReadGroupParams, streams)); + } + @Override public byte[] xadd(byte[] key, XAddParams params, Map hash) { return executeCommand(commandObjects.xadd(key, params, hash)); diff --git a/src/main/java/redis/clients/jedis/commands/StreamCommands.java b/src/main/java/redis/clients/jedis/commands/StreamCommands.java index 9c34cbc6a69..163e11050ed 100644 --- a/src/main/java/redis/clients/jedis/commands/StreamCommands.java +++ b/src/main/java/redis/clients/jedis/commands/StreamCommands.java @@ -250,7 +250,19 @@ List>> xread(XReadParams xReadParams, /** * XREAD [COUNT count] [BLOCK milliseconds] STREAMS key [key ...] ID [ID ...] */ + Map> xreadAsMap(XReadParams xReadParams, + Map streams); + + /** + * XREADGROUP GROUP group consumer [COUNT count] [BLOCK milliseconds] [NOACK] STREAMS key [key ...] id [id ...] + */ List>> xreadGroup(String groupName, String consumer, XReadGroupParams xReadGroupParams, Map streams); + /** + * XREADGROUP GROUP group consumer [COUNT count] [BLOCK milliseconds] [NOACK] STREAMS key [key ...] id [id ...] + */ + Map> xreadGroupAsMap(String groupName, String consumer, + XReadGroupParams xReadGroupParams, Map streams); + } diff --git a/src/main/java/redis/clients/jedis/commands/StreamPipelineCommands.java b/src/main/java/redis/clients/jedis/commands/StreamPipelineCommands.java index e435c023414..d4bda0fb986 100644 --- a/src/main/java/redis/clients/jedis/commands/StreamPipelineCommands.java +++ b/src/main/java/redis/clients/jedis/commands/StreamPipelineCommands.java @@ -243,7 +243,19 @@ Response>>> xread(XReadParams xReadPara /** * XREAD [COUNT count] [BLOCK milliseconds] STREAMS key [key ...] ID [ID ...] */ + Response>> xreadAsMap(XReadParams xReadParams, + Map streams); + + /** + * XREADGROUP GROUP group consumer [COUNT count] [BLOCK milliseconds] [NOACK] STREAMS key [key ...] id [id ...] + */ Response>>> xreadGroup(String groupName, String consumer, XReadGroupParams xReadGroupParams, Map streams); + /** + * XREADGROUP GROUP group consumer [COUNT count] [BLOCK milliseconds] [NOACK] STREAMS key [key ...] id [id ...] + */ + Response>> xreadGroupAsMap(String groupName, String consumer, + XReadGroupParams xReadGroupParams, Map streams); + } 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 acadc0b75d8..552c8ac1f6a 100644 --- a/src/test/java/redis/clients/jedis/commands/jedis/StreamsCommandsTest.java +++ b/src/test/java/redis/clients/jedis/commands/jedis/StreamsCommandsTest.java @@ -1,6 +1,8 @@ package redis.clients.jedis.commands.jedis; +import static java.util.Collections.singleton; import static java.util.Collections.singletonMap; +import static org.hamcrest.MatcherAssert.assertThat; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; @@ -15,7 +17,7 @@ import java.util.Map; import java.util.Map.Entry; import java.util.concurrent.atomic.AtomicReference; -import org.hamcrest.MatcherAssert; + import org.hamcrest.Matchers; import org.junit.Test; import org.junit.runner.RunWith; @@ -273,7 +275,10 @@ public void xrangeExclusive() { @Test public void xreadWithParams() { - Map streamQeury1 = singletonMap("xread-stream1", new StreamEntryID()); + final String key1 = "xread-stream1"; + final String key2 = "xread-stream2"; + + Map streamQeury1 = singletonMap(key1, new StreamEntryID()); // Before creating Stream assertNull(jedis.xread(XReadParams.xReadParams().block(1), streamQeury1)); @@ -281,28 +286,78 @@ public void xreadWithParams() { Map map = new HashMap<>(); map.put("f1", "v1"); - StreamEntryID id1 = jedis.xadd("xread-stream1", (StreamEntryID) null, map); - StreamEntryID id2 = jedis.xadd("xread-stream2", (StreamEntryID) null, map); + StreamEntryID id1 = jedis.xadd(key1, (StreamEntryID) null, map); + StreamEntryID id2 = jedis.xadd(key2, (StreamEntryID) null, map); // Read only a single Stream List>> streams1 = jedis.xread(XReadParams.xReadParams().count(1).block(1), streamQeury1); assertEquals(1, streams1.size()); - assertEquals("xread-stream1", streams1.get(0).getKey()); + assertEquals(key1, streams1.get(0).getKey()); assertEquals(1, streams1.get(0).getValue().size()); assertEquals(id1, streams1.get(0).getValue().get(0).getID()); assertEquals(map, streams1.get(0).getValue().get(0).getFields()); - assertNull(jedis.xread(XReadParams.xReadParams().block(1), singletonMap("xread-stream1", id1))); - assertNull(jedis.xread(XReadParams.xReadParams(), singletonMap("xread-stream1", id1))); + assertNull(jedis.xread(XReadParams.xReadParams().block(1), singletonMap(key1, id1))); + assertNull(jedis.xread(XReadParams.xReadParams(), singletonMap(key1, id1))); // Read from two Streams - Map streamQuery23 = new LinkedHashMap<>(); - streamQuery23.put("xread-stream1", new StreamEntryID()); - streamQuery23.put("xread-stream2", new StreamEntryID()); - List>> streams2 = jedis.xread(XReadParams.xReadParams().count(2).block(1), streamQuery23); + Map streamQuery2 = new LinkedHashMap<>(); + streamQuery2.put(key1, new StreamEntryID()); + streamQuery2.put(key2, new StreamEntryID()); + List>> streams2 = jedis.xread(XReadParams.xReadParams().count(2).block(1), streamQuery2); assertEquals(2, streams2.size()); } + @Test + public void xreadAsMap() { + + final String stream1 = "xread-stream1"; + final String stream2 = "xread-stream2"; + + Map streamQeury1 = singletonMap(stream1, new StreamEntryID()); + + // Before creating Stream + assertNull(jedis.xreadAsMap(XReadParams.xReadParams().block(1), streamQeury1)); + assertNull(jedis.xreadAsMap(XReadParams.xReadParams(), streamQeury1)); + + Map map = new HashMap<>(); + map.put("f1", "v1"); + StreamEntryID id1 = new StreamEntryID(1); + StreamEntryID id2 = new StreamEntryID(2); + StreamEntryID id3 = new StreamEntryID(3); + + assertEquals(id1, jedis.xadd(stream1, id1, map)); + assertEquals(id2, jedis.xadd(stream2, id2, map)); + assertEquals(id3, jedis.xadd(stream1, id3, map)); + + // Read only a single Stream + Map> streams1 = jedis.xreadAsMap(XReadParams.xReadParams().count(2), streamQeury1); + assertEquals(singleton(stream1), streams1.keySet()); + List list1 = streams1.get(stream1); + assertEquals(2, list1.size()); + assertEquals(id1, list1.get(0).getID()); + assertEquals(map, list1.get(0).getFields()); + assertEquals(id3, list1.get(1).getID()); + assertEquals(map, list1.get(1).getFields()); + + // Read from two Streams + Map streamQuery2 = new LinkedHashMap<>(); + streamQuery2.put(stream1, new StreamEntryID()); + streamQuery2.put(stream2, new StreamEntryID()); + Map> streams2 = jedis.xreadAsMap(XReadParams.xReadParams().count(1), streamQuery2); + assertEquals(2, streams2.size()); + assertEquals(id1, streams2.get(stream1).get(0).getID()); + assertEquals(id2, streams2.get(stream2).get(0).getID()); + + // Read from last entry + Map streamQueryLE = singletonMap(stream1, StreamEntryID.XREAD_LAST_ENTRY); + Map> streamsLE = jedis.xreadAsMap(XReadParams.xReadParams().count(1), streamQueryLE); + assertEquals(singleton(stream1), streamsLE.keySet()); + assertEquals(1, streamsLE.get(stream1).size()); + assertEquals(id3, streamsLE.get(stream1).get(0).getID()); + assertEquals(map, streamsLE.get(stream1).get(0).getFields()); + } + @Test public void xreadBlockZero() throws InterruptedException { final AtomicReference readId = new AtomicReference<>(); @@ -411,13 +466,13 @@ public void xrevrangeExclusive() { @Test public void xgroup() { - Map map = new HashMap(); + Map map = new HashMap<>(); map.put("f1", "v1"); StreamEntryID id1 = jedis.xadd("xgroup-stream", (StreamEntryID) null, map); assertEquals("OK", jedis.xgroupCreate("xgroup-stream", "consumer-group-name", null, false)); assertEquals("OK", jedis.xgroupSetID("xgroup-stream", "consumer-group-name", id1)); - assertEquals("OK", jedis.xgroupCreate("xgroup-stream", "consumer-group-name1", StreamEntryID.LAST_ENTRY, false)); + assertEquals("OK", jedis.xgroupCreate("xgroup-stream", "consumer-group-name1", StreamEntryID.XGROUP_LAST_ENTRY, false)); jedis.xgroupDestroy("xgroup-stream", "consumer-group-name"); assertEquals(0L, jedis.xgroupDelConsumer("xgroup-stream", "consumer-group-name1","myconsumer1")); @@ -433,7 +488,7 @@ public void xreadGroupWithParams() { map.put("f1", "v1"); jedis.xadd("xreadGroup-stream1", (StreamEntryID) null, map); jedis.xgroupCreate("xreadGroup-stream1", "xreadGroup-group", null, false); - Map streamQeury1 = singletonMap("xreadGroup-stream1", StreamEntryID.UNRECEIVED_ENTRY); + Map streamQeury1 = singletonMap("xreadGroup-stream1", StreamEntryID.XREADGROUP_UNDELIVERED_ENTRY); List>> range = jedis.xreadGroup("xreadGroup-group", "xreadGroup-consumer", XReadGroupParams.xReadGroupParams().count(1).noAck(), streamQeury1); assertEquals(1, range.size()); @@ -444,27 +499,44 @@ public void xreadGroupWithParams() { jedis.xgroupCreate("xreadGroup-stream2", "xreadGroup-group", null, false); // Read only a single Stream - Map streamQeury11 = singletonMap("xreadGroup-stream1", StreamEntryID.UNRECEIVED_ENTRY); List>> streams1 = jedis.xreadGroup("xreadGroup-group", "xreadGroup-consumer", - XReadGroupParams.xReadGroupParams().count(1).block(1).noAck(), streamQeury11); + XReadGroupParams.xReadGroupParams().count(1).block(1).noAck(), streamQeury1); assertEquals(1, streams1.size()); assertEquals(1, streams1.get(0).getValue().size()); // Read from two Streams - Map streamQuery23 = new LinkedHashMap<>(); - streamQuery23.put("xreadGroup-stream1", new StreamEntryID()); - streamQuery23.put("xreadGroup-stream2", new StreamEntryID()); + Map streamQuery2 = new LinkedHashMap<>(); + streamQuery2.put("xreadGroup-stream1", new StreamEntryID()); + streamQuery2.put("xreadGroup-stream2", new StreamEntryID()); List>> streams2 = jedis.xreadGroup("xreadGroup-group", "xreadGroup-consumer", - XReadGroupParams.xReadGroupParams().count(1).block(1).noAck(), streamQuery23); + XReadGroupParams.xReadGroupParams().count(1).block(1).noAck(), streamQuery2); assertEquals(2, streams2.size()); // Read only fresh messages StreamEntryID id4 = jedis.xadd("xreadGroup-stream1", (StreamEntryID) null, map); - Map streamQeuryFresh = singletonMap("xreadGroup-stream1", StreamEntryID.UNRECEIVED_ENTRY); - List>> streams3 = jedis.xreadGroup("xreadGroup-group", "xreadGroup-consumer", + Map streamQeuryFresh = singletonMap("xreadGroup-stream1", StreamEntryID.XREADGROUP_UNDELIVERED_ENTRY); + List>> streamsFresh = jedis.xreadGroup("xreadGroup-group", "xreadGroup-consumer", XReadGroupParams.xReadGroupParams().count(4).block(100).noAck(), streamQeuryFresh); - assertEquals(1, streams3.size()); - assertEquals(id4, streams3.get(0).getValue().get(0).getID()); + assertEquals(1, streamsFresh.size()); + assertEquals(id4, streamsFresh.get(0).getValue().get(0).getID()); + } + + @Test + public void xreadGroupAsMap() { + + final String stream1 = "xreadGroup-stream1"; + Map map = singletonMap("f1", "v1"); + + StreamEntryID id1 = jedis.xadd(stream1, StreamEntryID.NEW_ENTRY, map); + jedis.xgroupCreate(stream1, "xreadGroup-group", null, false); + Map streamQeury1 = singletonMap(stream1, StreamEntryID.XREADGROUP_UNDELIVERED_ENTRY); + Map> range = jedis.xreadGroupAsMap("xreadGroup-group", "xreadGroup-consumer", + XReadGroupParams.xReadGroupParams().noAck(), streamQeury1); + assertEquals(singleton(stream1), range.keySet()); + List list = range.get(stream1); + assertEquals(1, list.size()); + assertEquals(id1, list.get(0).getID()); + assertEquals(map, list.get(0).getFields()); } @Test @@ -481,7 +553,7 @@ public void xreadGroupWithParamsWhenPendingMessageIsDiscarded() { jedis.xadd("xreadGroup-discard-stream1", xAddParams, map2); jedis.xgroupCreate("xreadGroup-discard-stream1", "xreadGroup-group", null, false); - Map streamQuery1 = singletonMap("xreadGroup-discard-stream1", StreamEntryID.UNRECEIVED_ENTRY); + Map streamQuery1 = singletonMap("xreadGroup-discard-stream1", StreamEntryID.XREADGROUP_UNDELIVERED_ENTRY); List>> range = jedis.xreadGroup("xreadGroup-group", "xreadGroup-consumer", XReadGroupParams.xReadGroupParams().count(1), streamQuery1); assertEquals(1, range.size()); @@ -514,8 +586,7 @@ public void xack() { jedis.xgroupCreate("xack-stream", "xack-group", null, false); - Map streamQeury1 = singletonMap( - "xack-stream", StreamEntryID.UNRECEIVED_ENTRY); + Map streamQeury1 = singletonMap("xack-stream", StreamEntryID.XREADGROUP_UNDELIVERED_ENTRY); // Empty Stream List>> range = jedis.xreadGroup("xack-group", "xack-consumer", @@ -534,8 +605,7 @@ public void xpendingWithParams() { assertEquals("OK", jedis.xgroupCreate("xpendeing-stream", "xpendeing-group", null, false)); - Map streamQeury1 = singletonMap( - "xpendeing-stream", StreamEntryID.UNRECEIVED_ENTRY); + Map streamQeury1 = singletonMap("xpendeing-stream", StreamEntryID.XREADGROUP_UNDELIVERED_ENTRY); // Read the event from Stream put it on pending List>> range = jedis.xreadGroup("xpendeing-group", @@ -575,8 +645,7 @@ public void xpendingRange() { jedis.xgroupCreate("xpendeing-stream", "xpendeing-group", null, false); // read 1 message from the group with each consumer - Map streamQeury = singletonMap( - "xpendeing-stream", StreamEntryID.UNRECEIVED_ENTRY); + Map streamQeury = singletonMap("xpendeing-stream", StreamEntryID.XREADGROUP_UNDELIVERED_ENTRY); jedis.xreadGroup("xpendeing-group", "consumer1", XReadGroupParams.xReadGroupParams().count(1), streamQeury); jedis.xreadGroup("xpendeing-group", "consumer2", XReadGroupParams.xReadGroupParams().count(1), streamQeury); @@ -607,7 +676,7 @@ public void xclaimWithParams() { // Read the event from Stream put it on pending jedis.xreadGroup("xpendeing-group", "xpendeing-consumer", XReadGroupParams.xReadGroupParams().count(1).block(1), - singletonMap("xpendeing-stream", StreamEntryID.UNRECEIVED_ENTRY)); + singletonMap("xpendeing-stream", StreamEntryID.XREADGROUP_UNDELIVERED_ENTRY)); // Get the pending event List pendingRange = jedis.xpending("xpendeing-stream", "xpendeing-group", @@ -638,7 +707,7 @@ public void xclaimJustId() { // Read the event from Stream put it on pending jedis.xreadGroup("xpendeing-group", "xpendeing-consumer", XReadGroupParams.xReadGroupParams().count(1).block(1), - singletonMap("xpendeing-stream", StreamEntryID.UNRECEIVED_ENTRY)); + singletonMap("xpendeing-stream", StreamEntryID.XREADGROUP_UNDELIVERED_ENTRY)); // Get the pending event List pendingRange = jedis.xpending("xpendeing-stream", "xpendeing-group", @@ -667,7 +736,7 @@ public void xautoclaim() { // Read the event from Stream put it on pending jedis.xreadGroup("xpending-group", "xpending-consumer", XReadGroupParams.xReadGroupParams().count(1).block(1), - singletonMap("xpending-stream", StreamEntryID.UNRECEIVED_ENTRY)); + singletonMap("xpending-stream", StreamEntryID.XREADGROUP_UNDELIVERED_ENTRY)); // Get the pending event List pendingRange = jedis.xpending("xpending-stream", "xpending-group", @@ -697,7 +766,7 @@ public void xautoclaimBinary() { // Read the event from Stream put it on pending jedis.xreadGroup("xpending-group", "xpending-consumer", XReadGroupParams.xReadGroupParams().count(1).block(1), - singletonMap("xpending-stream", StreamEntryID.UNRECEIVED_ENTRY)); + singletonMap("xpending-stream", StreamEntryID.XREADGROUP_UNDELIVERED_ENTRY)); // Get the pending event List pendingRange = jedis.xpending("xpending-stream", "xpending-group", @@ -729,7 +798,7 @@ public void xautoclaimJustId() { // Read the event from Stream put it on pending jedis.xreadGroup("xpending-group", "xpending-consumer", XReadGroupParams.xReadGroupParams().count(1).block(1), - singletonMap("xpending-stream", StreamEntryID.UNRECEIVED_ENTRY)); + singletonMap("xpending-stream", StreamEntryID.XREADGROUP_UNDELIVERED_ENTRY)); // Get the pending event List pendingRange = jedis.xpending("xpending-stream", "xpending-group", @@ -759,7 +828,7 @@ public void xautoclaimJustIdBinary() { // Read the event from Stream put it on pending jedis.xreadGroup("xpending-group", "xpending-consumer", XReadGroupParams.xReadGroupParams().count(1).block(1), - singletonMap("xpending-stream", StreamEntryID.UNRECEIVED_ENTRY)); + singletonMap("xpending-stream", StreamEntryID.XREADGROUP_UNDELIVERED_ENTRY)); // Get the pending event List pendingRange = jedis.xpending("xpending-stream", "xpending-group", @@ -802,7 +871,7 @@ public void xinfo() throws InterruptedException { StreamInfo streamInfo = jedis.xinfoStream(STREAM_NAME); assertNotNull(id2); - jedis.xgroupCreate(STREAM_NAME, G1, StreamEntryID.LAST_ENTRY, false); + jedis.xgroupCreate(STREAM_NAME, G1, StreamEntryID.XGROUP_LAST_ENTRY, false); Map streamQeury11 = singletonMap( STREAM_NAME, new StreamEntryID("0-0")); jedis.xreadGroup(G1, MY_CONSUMER, XReadGroupParams.xReadGroupParams().count(1), streamQeury11); @@ -854,8 +923,8 @@ public void xinfo() throws InterruptedException { // Using getters assertEquals(MY_CONSUMER, consumersInfo.get(0).getName()); assertEquals(0L, consumersInfo.get(0).getPending()); - MatcherAssert.assertThat(consumersInfo.get(0).getIdle(), Matchers.greaterThanOrEqualTo(0L)); - MatcherAssert.assertThat(consumersInfo.get(0).getInactive(), Matchers.any(Long.class)); + assertThat(consumersInfo.get(0).getIdle(), Matchers.greaterThanOrEqualTo(0L)); + assertThat(consumersInfo.get(0).getInactive(), Matchers.any(Long.class)); // Consumer info test assertEquals(MY_CONSUMER, @@ -866,11 +935,11 @@ public void xinfo() throws InterruptedException { // Using getters assertEquals(MY_CONSUMER, consumerInfo.get(0).getName()); assertEquals(0L, consumerInfo.get(0).getPending()); - MatcherAssert.assertThat(consumerInfo.get(0).getIdle(), Matchers.greaterThanOrEqualTo(0L)); - MatcherAssert.assertThat(consumerInfo.get(0).getInactive(), Matchers.any(Long.class)); + assertThat(consumerInfo.get(0).getIdle(), Matchers.greaterThanOrEqualTo(0L)); + assertThat(consumerInfo.get(0).getInactive(), Matchers.any(Long.class)); // test with more groups and consumers - jedis.xgroupCreate(STREAM_NAME, G2, StreamEntryID.LAST_ENTRY, false); + jedis.xgroupCreate(STREAM_NAME, G2, StreamEntryID.XGROUP_LAST_ENTRY, false); jedis.xreadGroup(G1, MY_CONSUMER2, XReadGroupParams.xReadGroupParams().count(1), streamQeury11); jedis.xreadGroup(G2, MY_CONSUMER, XReadGroupParams.xReadGroupParams().count(1), streamQeury11); jedis.xreadGroup(G2, MY_CONSUMER2, XReadGroupParams.xReadGroupParams().count(1), streamQeury11); @@ -921,7 +990,7 @@ public void xinfoStreamFullWithPending() { StreamEntryID id2 = jedis.xadd("streamfull2", (StreamEntryID) null, map); jedis.xgroupCreate("streamfull2", "xreadGroup-group", null, false); - Map streamQeury1 = singletonMap("streamfull2", StreamEntryID.UNRECEIVED_ENTRY); + Map streamQeury1 = singletonMap("streamfull2", StreamEntryID.XREADGROUP_UNDELIVERED_ENTRY); List>> range = jedis.xreadGroup("xreadGroup-group", "xreadGroup-consumer", XReadGroupParams.xReadGroupParams().count(1), streamQeury1); assertEquals(1, range.size()); @@ -940,8 +1009,8 @@ public void xinfoStreamFullWithPending() { assertEquals(1, group.getConsumers().size()); StreamConsumerFullInfo consumer = group.getConsumers().get(0); assertEquals("xreadGroup-consumer", consumer.getName()); - MatcherAssert.assertThat(consumer.getSeenTime(), Matchers.greaterThanOrEqualTo(0L)); - MatcherAssert.assertThat(consumer.getActiveTime(), Matchers.greaterThanOrEqualTo(0L)); + assertThat(consumer.getSeenTime(), Matchers.greaterThanOrEqualTo(0L)); + assertThat(consumer.getActiveTime(), Matchers.greaterThanOrEqualTo(0L)); assertEquals(1, consumer.getPending().size()); List consumerPendingEntry = consumer.getPending().get(0); assertEquals(id1, consumerPendingEntry.get(0)); 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 119f2331982..af64b175768 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 @@ -396,7 +396,11 @@ public void xrangeExclusive() { @Test public void xreadWithParams() { - Map streamQuery1 = singletonMap("xread-stream1", new StreamEntryID()); + + final String stream1 = "xread-stream1"; + final String stream2 = "xread-stream2"; + + Map streamQuery1 = singletonMap(stream1, new StreamEntryID()); // Before creating Stream pipe.xread(XReadParams.xReadParams().block(1), streamQuery1); @@ -408,25 +412,25 @@ public void xreadWithParams() { )); Map map1 = singletonMap("f1", "v1"); - StreamEntryID id1 = jedis.xadd("xread-stream1", (StreamEntryID) null, map1); + StreamEntryID id1 = jedis.xadd(stream1, (StreamEntryID) null, map1); Map map2 = singletonMap("f2", "v2"); - StreamEntryID id2 = jedis.xadd("xread-stream2", (StreamEntryID) null, map2); + StreamEntryID id2 = jedis.xadd(stream2, (StreamEntryID) null, map2); // Read only a single Stream Response>>> streams1 = pipe.xread(XReadParams.xReadParams().count(1).block(1), streamQuery1); Response>>> streams2 = - pipe.xread(XReadParams.xReadParams().block(1), singletonMap("xread-stream1", id1)); + pipe.xread(XReadParams.xReadParams().block(1), singletonMap(stream1, id1)); Response>>> streams3 = - pipe.xread(XReadParams.xReadParams(), singletonMap("xread-stream1", id1)); + pipe.xread(XReadParams.xReadParams(), singletonMap(stream1, id1)); pipe.sync(); assertThat(streams1.get().stream().map(Entry::getKey).collect(Collectors.toList()), - contains("xread-stream1")); + contains(stream1)); assertThat(streams1.get().stream().map(Entry::getValue).flatMap(List::stream) .map(StreamEntry::getID).collect(Collectors.toList()), contains(id1)); @@ -440,8 +444,8 @@ public void xreadWithParams() { // Read from two Streams Map streamQuery2 = new LinkedHashMap<>(); - streamQuery2.put("xread-stream1", new StreamEntryID()); - streamQuery2.put("xread-stream2", new StreamEntryID()); + streamQuery2.put(stream1, new StreamEntryID()); + streamQuery2.put(stream2, new StreamEntryID()); Response>>> streams4 = pipe.xread(XReadParams.xReadParams().count(2).block(1), streamQuery2); @@ -449,7 +453,7 @@ public void xreadWithParams() { pipe.sync(); assertThat(streams4.get().stream().map(Entry::getKey).collect(Collectors.toList()), - contains("xread-stream1", "xread-stream2")); + contains(stream1, stream2)); assertThat(streams4.get().stream().map(Entry::getValue).flatMap(List::stream) .map(StreamEntry::getID).collect(Collectors.toList()), contains(id1, id2)); @@ -618,7 +622,7 @@ public void xgroup() { pipe.xgroupCreate("xgroup-stream", "consumer-group-name", null, false); pipe.xgroupSetID("xgroup-stream", "consumer-group-name", id1); - pipe.xgroupCreate("xgroup-stream", "consumer-group-name1", StreamEntryID.LAST_ENTRY, false); + pipe.xgroupCreate("xgroup-stream", "consumer-group-name1", StreamEntryID.XGROUP_LAST_ENTRY, false); pipe.xgroupDestroy("xgroup-stream", "consumer-group-name"); pipe.xgroupDelConsumer("xgroup-stream", "consumer-group-name1", "myconsumer1"); @@ -644,7 +648,7 @@ public void xreadGroupWithParams() { jedis.xgroupCreate("xreadGroup-stream1", "xreadGroup-group", null, false); - Map streamQuery1 = singletonMap("xreadGroup-stream1", StreamEntryID.UNRECEIVED_ENTRY); + Map streamQuery1 = singletonMap("xreadGroup-stream1", StreamEntryID.XREADGROUP_UNDELIVERED_ENTRY); Response>>> streams1 = pipe.xreadGroup("xreadGroup-group", "xreadGroup-consumer", @@ -675,8 +679,8 @@ public void xreadGroupWithParams() { // Read from two Streams Map streamQuery2 = new LinkedHashMap<>(); - streamQuery2.put("xreadGroup-stream1", StreamEntryID.UNRECEIVED_ENTRY); - streamQuery2.put("xreadGroup-stream2", StreamEntryID.UNRECEIVED_ENTRY); + streamQuery2.put("xreadGroup-stream1", StreamEntryID.XREADGROUP_UNDELIVERED_ENTRY); + streamQuery2.put("xreadGroup-stream2", StreamEntryID.XREADGROUP_UNDELIVERED_ENTRY); Response>>> streams3 = pipe.xreadGroup("xreadGroup-group", "xreadGroup-consumer", XReadGroupParams.xReadGroupParams().count(1).noAck(), streamQuery2); @@ -705,7 +709,7 @@ public void xreadGroupWithParams() { Map map4 = singletonMap("f4", "v4"); StreamEntryID id4 = jedis.xadd("xreadGroup-stream1", (StreamEntryID) null, map4); - Map streamQueryFresh = singletonMap("xreadGroup-stream1", StreamEntryID.UNRECEIVED_ENTRY); + Map streamQueryFresh = singletonMap("xreadGroup-stream1", StreamEntryID.XREADGROUP_UNDELIVERED_ENTRY); Response>>> streams4 = pipe.xreadGroup("xreadGroup-group", "xreadGroup-consumer", XReadGroupParams.xReadGroupParams().count(4).block(100).noAck(), streamQueryFresh); @@ -733,7 +737,7 @@ public void xreadGroupWithParamsWhenPendingMessageIsDiscarded() { pipe.xgroupCreate("xreadGroup-discard-stream1", "xreadGroup-group", null, false); - Map streamQuery1 = singletonMap("xreadGroup-discard-stream1", StreamEntryID.UNRECEIVED_ENTRY); + Map streamQuery1 = singletonMap("xreadGroup-discard-stream1", StreamEntryID.XREADGROUP_UNDELIVERED_ENTRY); Response>>> streams1 = pipe.xreadGroup("xreadGroup-group", "xreadGroup-consumer", @@ -777,7 +781,7 @@ public void xack() { pipe.xgroupCreate("xack-stream", "xack-group", null, false); - Map streamQuery1 = singletonMap("xack-stream", StreamEntryID.UNRECEIVED_ENTRY); + Map streamQuery1 = singletonMap("xack-stream", StreamEntryID.XREADGROUP_UNDELIVERED_ENTRY); // Empty Stream Response>>> streams1 = @@ -805,7 +809,7 @@ public void xpendingWithParams() { assertEquals("OK", jedis.xgroupCreate("xpending-stream", "xpending-group", null, false)); - Map streamQeury1 = singletonMap("xpending-stream", StreamEntryID.UNRECEIVED_ENTRY); + Map streamQeury1 = singletonMap("xpending-stream", StreamEntryID.XREADGROUP_UNDELIVERED_ENTRY); // Read the event from Stream put it on pending Response>>> range = pipe.xreadGroup("xpending-group", @@ -857,7 +861,7 @@ public void xpendingRange() { pipe.xgroupCreate("xpending-stream", "xpending-group", null, false); // read 1 message from the group with each consumer - Map streamQeury = singletonMap("xpending-stream", StreamEntryID.UNRECEIVED_ENTRY); + Map streamQeury = singletonMap("xpending-stream", StreamEntryID.XREADGROUP_UNDELIVERED_ENTRY); pipe.xreadGroup("xpending-group", "consumer1", XReadGroupParams.xReadGroupParams().count(1), streamQeury); pipe.xreadGroup("xpending-group", "consumer2", XReadGroupParams.xReadGroupParams().count(1), streamQeury); @@ -892,7 +896,7 @@ public void xclaimWithParams() throws InterruptedException { // Read the event from Stream put it on pending pipe.xreadGroup("xpending-group", "xpending-consumer", XReadGroupParams.xReadGroupParams().count(1).block(1), - singletonMap("xpending-stream", StreamEntryID.UNRECEIVED_ENTRY)); + singletonMap("xpending-stream", StreamEntryID.XREADGROUP_UNDELIVERED_ENTRY)); // Get the pending event Response> pending = @@ -934,7 +938,7 @@ public void xclaimJustId() throws InterruptedException { // Read the event from Stream put it on pending pipe.xreadGroup("xpending-group", "xpending-consumer", XReadGroupParams.xReadGroupParams().count(1).block(1), - singletonMap("xpending-stream", StreamEntryID.UNRECEIVED_ENTRY)); + singletonMap("xpending-stream", StreamEntryID.XREADGROUP_UNDELIVERED_ENTRY)); // Get the pending event Response> pending = @@ -972,7 +976,7 @@ public void xautoclaim() throws InterruptedException { // Read the event from Stream put it on pending pipe.xreadGroup("xpending-group", "xpending-consumer", XReadGroupParams.xReadGroupParams().count(1).block(1), - singletonMap("xpending-stream", StreamEntryID.UNRECEIVED_ENTRY)); + singletonMap("xpending-stream", StreamEntryID.XREADGROUP_UNDELIVERED_ENTRY)); // Get the pending event Response> pending = pipe.xpending("xpending-stream", "xpending-group", @@ -1012,7 +1016,7 @@ public void xautoclaimBinary() throws InterruptedException { // Read the event from Stream put it on pending pipe.xreadGroup("xpending-group", "xpending-consumer", XReadGroupParams.xReadGroupParams().count(1).block(1), - singletonMap("xpending-stream", StreamEntryID.UNRECEIVED_ENTRY)); + singletonMap("xpending-stream", StreamEntryID.XREADGROUP_UNDELIVERED_ENTRY)); // Get the pending event Response> pending = pipe.xpending("xpending-stream", "xpending-group", @@ -1055,7 +1059,7 @@ public void xautoclaimJustId() throws InterruptedException { // Read the event from Stream put it on pending pipe.xreadGroup("xpending-group", "xpending-consumer", XReadGroupParams.xReadGroupParams().count(1).block(1), - singletonMap("xpending-stream", StreamEntryID.UNRECEIVED_ENTRY)); + singletonMap("xpending-stream", StreamEntryID.XREADGROUP_UNDELIVERED_ENTRY)); // Get the pending event Response> pending = pipe.xpending("xpending-stream", "xpending-group", @@ -1091,7 +1095,7 @@ public void xautoclaimJustIdBinary() throws InterruptedException { // Read the event from Stream put it on pending pipe.xreadGroup("xpending-group", "xpending-consumer", XReadGroupParams.xReadGroupParams().count(1).block(1), - singletonMap("xpending-stream", StreamEntryID.UNRECEIVED_ENTRY)); + singletonMap("xpending-stream", StreamEntryID.XREADGROUP_UNDELIVERED_ENTRY)); // Get the pending event Response> pending = pipe.xpending("xpending-stream", "xpending-group", @@ -1140,7 +1144,7 @@ public void xinfo() throws InterruptedException { Response streamInfoResponse = pipe.xinfoStream(STREAM_NAME); - pipe.xgroupCreate(STREAM_NAME, G1, StreamEntryID.LAST_ENTRY, false); + pipe.xgroupCreate(STREAM_NAME, G1, StreamEntryID.XGROUP_LAST_ENTRY, false); Map streamQuery1 = singletonMap(STREAM_NAME, new StreamEntryID("0-0")); @@ -1221,7 +1225,7 @@ public void xinfo() throws InterruptedException { assertThat(consumerInfo.get(0).getInactive(), Matchers.any(Long.class)); // test with more groups and consumers - pipe.xgroupCreate(STREAM_NAME, G2, StreamEntryID.LAST_ENTRY, false); + pipe.xgroupCreate(STREAM_NAME, G2, StreamEntryID.XGROUP_LAST_ENTRY, false); pipe.xreadGroup(G1, MY_CONSUMER2, XReadGroupParams.xReadGroupParams().count(1), streamQuery1); pipe.xreadGroup(G2, MY_CONSUMER, XReadGroupParams.xReadGroupParams().count(1), streamQuery1); pipe.xreadGroup(G2, MY_CONSUMER2, XReadGroupParams.xReadGroupParams().count(1), streamQuery1); @@ -1277,7 +1281,7 @@ public void xinfoStreamFullWithPending() { StreamEntryID id2 = jedis.xadd("streamfull2", (StreamEntryID) null, map); jedis.xgroupCreate("streamfull2", "xreadGroup-group", null, false); - Map streamQeury1 = singletonMap("streamfull2", StreamEntryID.UNRECEIVED_ENTRY); + Map streamQeury1 = singletonMap("streamfull2", StreamEntryID.XREADGROUP_UNDELIVERED_ENTRY); Response>>> pending = pipe.xreadGroup("xreadGroup-group", "xreadGroup-consumer", XReadGroupParams.xReadGroupParams().count(1), streamQeury1); diff --git a/src/test/java/redis/clients/jedis/params/XPendingParamsTest.java b/src/test/java/redis/clients/jedis/params/XPendingParamsTest.java index b6698d875f7..c7c95da4243 100644 --- a/src/test/java/redis/clients/jedis/params/XPendingParamsTest.java +++ b/src/test/java/redis/clients/jedis/params/XPendingParamsTest.java @@ -24,7 +24,7 @@ public void checkHashCodeIdenticalParams() { @Test public void checkEqualsVariousParams() { XPendingParams firstParam = getDefaultValue(); - firstParam.start(StreamEntryID.LAST_ENTRY); + firstParam.start(StreamEntryID.XGROUP_LAST_ENTRY); XPendingParams secondParam = getDefaultValue(); secondParam.start(StreamEntryID.NEW_ENTRY); assertFalse(firstParam.equals(secondParam)); @@ -33,7 +33,7 @@ public void checkEqualsVariousParams() { @Test public void checkHashCodeVariousParams() { XPendingParams firstParam = getDefaultValue(); - firstParam.start(StreamEntryID.LAST_ENTRY); + firstParam.start(StreamEntryID.XGROUP_LAST_ENTRY); XPendingParams secondParam = getDefaultValue(); secondParam.start(StreamEntryID.NEW_ENTRY); assertNotEquals(firstParam.hashCode(), secondParam.hashCode()); From a3b710becceeb77dbf6ed5c5cad63cc6585d558e Mon Sep 17 00:00:00 2001 From: M Sazzadul Hoque <7600764+sazzad16@users.noreply.github.com> Date: Fri, 29 Mar 2024 19:13:49 +0600 Subject: [PATCH 29/33] Consider null values in empty StreamPendingSummary (#3793) * Consider null values in empty StreamPendingSummary * java stream --- .../redis/clients/jedis/BuilderFactory.java | 17 +++-- .../commands/jedis/StreamsCommandsTest.java | 64 ++++++++++++------- 2 files changed, 49 insertions(+), 32 deletions(-) diff --git a/src/main/java/redis/clients/jedis/BuilderFactory.java b/src/main/java/redis/clients/jedis/BuilderFactory.java index 83e552de839..26d5b5c384b 100644 --- a/src/main/java/redis/clients/jedis/BuilderFactory.java +++ b/src/main/java/redis/clients/jedis/BuilderFactory.java @@ -1812,15 +1812,14 @@ public StreamPendingSummary build(Object data) { } List objectList = (List) data; - long total = BuilderFactory.LONG.build(objectList.get(0)); - String minId = SafeEncoder.encode((byte[]) objectList.get(1)); - String maxId = SafeEncoder.encode((byte[]) objectList.get(2)); - List> consumerObjList = (List>) objectList.get(3); - Map map = new HashMap<>(consumerObjList.size()); - for (List consumerObj : consumerObjList) { - map.put(SafeEncoder.encode((byte[]) consumerObj.get(0)), Long.parseLong(SafeEncoder.encode((byte[]) consumerObj.get(1)))); - } - return new StreamPendingSummary(total, new StreamEntryID(minId), new StreamEntryID(maxId), map); + long total = LONG.build(objectList.get(0)); + StreamEntryID minId = STREAM_ENTRY_ID.build(objectList.get(1)); + StreamEntryID maxId = STREAM_ENTRY_ID.build(objectList.get(2)); + Map map = objectList.get(3) == null ? null + : ((List>) objectList.get(3)).stream().collect( + Collectors.toMap(pair -> STRING.build(pair.get(0)), + pair -> Long.parseLong(STRING.build(pair.get(1))))); + return new StreamPendingSummary(total, minId, maxId, map); } @Override 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 552c8ac1f6a..0ac12f9d05c 100644 --- a/src/test/java/redis/clients/jedis/commands/jedis/StreamsCommandsTest.java +++ b/src/test/java/redis/clients/jedis/commands/jedis/StreamsCommandsTest.java @@ -599,13 +599,22 @@ public void xack() { @Test public void xpendingWithParams() { + final String stream = "xpendeing-stream"; + + assertEquals("OK", jedis.xgroupCreate(stream, "xpendeing-group", null, true)); + + // Get the summary from empty stream + StreamPendingSummary emptySummary = jedis.xpending(stream, "xpendeing-group"); + assertEquals(0, emptySummary.getTotal()); + assertNull(emptySummary.getMinId()); + assertNull(emptySummary.getMaxId()); + assertNull(emptySummary.getConsumerMessageCount()); + Map map = new HashMap<>(); map.put("f1", "v1"); - StreamEntryID id1 = jedis.xadd("xpendeing-stream", (StreamEntryID) null, map); + StreamEntryID id1 = jedis.xadd(stream, (StreamEntryID) null, map); - assertEquals("OK", jedis.xgroupCreate("xpendeing-stream", "xpendeing-group", null, false)); - - Map streamQeury1 = singletonMap("xpendeing-stream", StreamEntryID.XREADGROUP_UNDELIVERED_ENTRY); + Map streamQeury1 = singletonMap(stream, StreamEntryID.XREADGROUP_UNDELIVERED_ENTRY); // Read the event from Stream put it on pending List>> range = jedis.xreadGroup("xpendeing-group", @@ -614,8 +623,14 @@ public void xpendingWithParams() { assertEquals(1, range.get(0).getValue().size()); assertEquals(map, range.get(0).getValue().get(0).getFields()); + // Get the summary about the pending messages + StreamPendingSummary pendingSummary = jedis.xpending(stream, "xpendeing-group"); + assertEquals(1, pendingSummary.getTotal()); + assertEquals(id1, pendingSummary.getMinId()); + assertEquals(1l, pendingSummary.getConsumerMessageCount().get("xpendeing-consumer").longValue()); + // Get the pending event - List pendingRange = jedis.xpending("xpendeing-stream", "xpendeing-group", + List pendingRange = jedis.xpending(stream, "xpendeing-group", new XPendingParams().count(3).consumer("xpendeing-consumer")); assertEquals(1, pendingRange.size()); assertEquals(id1, pendingRange.get(0).getID()); @@ -624,32 +639,33 @@ public void xpendingWithParams() { assertTrue(pendingRange.get(0).toString().contains("xpendeing-consumer")); // Without consumer - pendingRange = jedis.xpending("xpendeing-stream", "xpendeing-group", new XPendingParams().count(3)); + pendingRange = jedis.xpending(stream, "xpendeing-group", new XPendingParams().count(3)); assertEquals(1, pendingRange.size()); assertEquals(id1, pendingRange.get(0).getID()); assertEquals(1, pendingRange.get(0).getDeliveredTimes()); assertEquals("xpendeing-consumer", pendingRange.get(0).getConsumerName()); // with idle - pendingRange = jedis.xpending("xpendeing-stream", "xpendeing-group", + pendingRange = jedis.xpending(stream, "xpendeing-group", new XPendingParams().idle(Duration.ofMinutes(1).toMillis()).count(3)); assertEquals(0, pendingRange.size()); } @Test public void xpendingRange() { + final String stream = "xpendeing-stream"; Map map = new HashMap<>(); map.put("foo", "bar"); - StreamEntryID m1 = jedis.xadd("xpendeing-stream", (StreamEntryID) null, map); - StreamEntryID m2 = jedis.xadd("xpendeing-stream", (StreamEntryID) null, map); - jedis.xgroupCreate("xpendeing-stream", "xpendeing-group", null, false); + StreamEntryID m1 = jedis.xadd(stream, (StreamEntryID) null, map); + StreamEntryID m2 = jedis.xadd(stream, (StreamEntryID) null, map); + jedis.xgroupCreate(stream, "xpendeing-group", null, false); // read 1 message from the group with each consumer - Map streamQeury = singletonMap("xpendeing-stream", StreamEntryID.XREADGROUP_UNDELIVERED_ENTRY); + Map streamQeury = singletonMap(stream, StreamEntryID.XREADGROUP_UNDELIVERED_ENTRY); jedis.xreadGroup("xpendeing-group", "consumer1", XReadGroupParams.xReadGroupParams().count(1), streamQeury); jedis.xreadGroup("xpendeing-group", "consumer2", XReadGroupParams.xReadGroupParams().count(1), streamQeury); - List response = jedis.xpending("xpendeing-stream", "xpendeing-group", + List response = jedis.xpending(stream, "xpendeing-group", XPendingParams.xPendingParams("(0", "+", 5)); assertEquals(2, response.size()); assertEquals(m1, response.get(0).getID()); @@ -657,7 +673,7 @@ public void xpendingRange() { assertEquals(m2, response.get(1).getID()); assertEquals("consumer2", response.get(1).getConsumerName()); - response = jedis.xpending("xpendeing-stream", "xpendeing-group", + response = jedis.xpending(stream, "xpendeing-group", XPendingParams.xPendingParams(StreamEntryID.MINIMUM_ID, StreamEntryID.MAXIMUM_ID, 5)); assertEquals(2, response.size()); assertEquals(m1, response.get(0).getID()); @@ -668,18 +684,19 @@ public void xpendingRange() { @Test public void xclaimWithParams() { + final String stream = "xpendeing-stream"; Map map = new HashMap<>(); map.put("f1", "v1"); - jedis.xadd("xpendeing-stream", (StreamEntryID) null, map); + jedis.xadd(stream, (StreamEntryID) null, map); - assertEquals("OK", jedis.xgroupCreate("xpendeing-stream", "xpendeing-group", null, false)); + assertEquals("OK", jedis.xgroupCreate(stream, "xpendeing-group", null, false)); // Read the event from Stream put it on pending jedis.xreadGroup("xpendeing-group", "xpendeing-consumer", XReadGroupParams.xReadGroupParams().count(1).block(1), - singletonMap("xpendeing-stream", StreamEntryID.XREADGROUP_UNDELIVERED_ENTRY)); + singletonMap(stream, StreamEntryID.XREADGROUP_UNDELIVERED_ENTRY)); // Get the pending event - List pendingRange = jedis.xpending("xpendeing-stream", "xpendeing-group", + List pendingRange = jedis.xpending(stream, "xpendeing-group", XPendingParams.xPendingParams().count(3).consumer("xpendeing-consumer")); // Sleep for 100ms so we can claim events pending for more than 50ms @@ -689,7 +706,7 @@ public void xclaimWithParams() { e.printStackTrace(); } - List streamEntrys = jedis.xclaim("xpendeing-stream", "xpendeing-group", + List streamEntrys = jedis.xclaim(stream, "xpendeing-group", "xpendeing-consumer2", 50, XClaimParams.xClaimParams().idle(0).retryCount(0), pendingRange.get(0).getID()); assertEquals(1, streamEntrys.size()); @@ -699,18 +716,19 @@ public void xclaimWithParams() { @Test public void xclaimJustId() { + final String stream = "xpendeing-stream"; Map map = new HashMap<>(); map.put("f1", "v1"); - jedis.xadd("xpendeing-stream", (StreamEntryID) null, map); + jedis.xadd(stream, (StreamEntryID) null, map); - assertEquals("OK", jedis.xgroupCreate("xpendeing-stream", "xpendeing-group", null, false)); + assertEquals("OK", jedis.xgroupCreate(stream, "xpendeing-group", null, false)); // Read the event from Stream put it on pending jedis.xreadGroup("xpendeing-group", "xpendeing-consumer", XReadGroupParams.xReadGroupParams().count(1).block(1), - singletonMap("xpendeing-stream", StreamEntryID.XREADGROUP_UNDELIVERED_ENTRY)); + singletonMap(stream, StreamEntryID.XREADGROUP_UNDELIVERED_ENTRY)); // Get the pending event - List pendingRange = jedis.xpending("xpendeing-stream", "xpendeing-group", + List pendingRange = jedis.xpending(stream, "xpendeing-group", XPendingParams.xPendingParams().count(3).consumer("xpendeing-consumer")); // Sleep for 100ms so we can claim events pending for more than 50ms try { @@ -719,7 +737,7 @@ public void xclaimJustId() { e.printStackTrace(); } - List streamEntryIDS = jedis.xclaimJustId("xpendeing-stream", "xpendeing-group", + List streamEntryIDS = jedis.xclaimJustId(stream, "xpendeing-group", "xpendeing-consumer2", 50, XClaimParams.xClaimParams().idle(0).retryCount(0), pendingRange.get(0).getID()); assertEquals(1, streamEntryIDS.size()); From fac0ae9fc8b71b7fa5a15159c52919c97c144cbf Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 1 Apr 2024 11:50:32 +0600 Subject: [PATCH 30/33] Bump org.apache.maven.plugins:maven-gpg-plugin from 3.2.1 to 3.2.2 (#3794) Bumps [org.apache.maven.plugins:maven-gpg-plugin](https://github.com/apache/maven-gpg-plugin) from 3.2.1 to 3.2.2. - [Release notes](https://github.com/apache/maven-gpg-plugin/releases) - [Commits](https://github.com/apache/maven-gpg-plugin/compare/maven-gpg-plugin-3.2.1...maven-gpg-plugin-3.2.2) --- updated-dependencies: - dependency-name: org.apache.maven.plugins:maven-gpg-plugin dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 823fd4d6ef1..aee4077c836 100644 --- a/pom.xml +++ b/pom.xml @@ -300,7 +300,7 @@ maven-gpg-plugin - 3.2.1 + 3.2.2 --pinentry-mode From c7a1687cc9b2e9c5964a7ddb61c06e28fb3f0cac Mon Sep 17 00:00:00 2001 From: Gabriel Erzse Date: Wed, 3 Apr 2024 16:03:45 +0300 Subject: [PATCH 31/33] Add extensive tests for UnifiedJedis (#3788) * Align Pipelined commands with UnifiedJedis Add some Pipelined commands that are available in UnifiedJedis but are missing the pipelined version. * Add extensive tests for UnifiedJedis Add mocked tests for UnifiedJedis. Most of the code is covered, except the constructors and some iterator methods. Those are left for later. Take the opportunity to split PipeliningTests into smaller test classes. The idea is to have one superclass (MockCommandObjectsTest) that exposes a variety of mocked CommandObjects. From there we branch in two directions: towards PipeliningBase and towards UnifiedJedis. Each has a test superclass that prepares mocked instances, and a set of concrete test classes that contain the actual tests. The tests are grouped in categories. The names of the categories are the same as used on the redis.io website in the commands documentation page. Inside each section (i.e. test class), the tested commands are ordered alphabetically. The tests run in pairs, one for the string-based command, and one for the equivalent byte-array-based command. Hopefully this gives a good structure for following the code. A new public constructor is needed in UnifiedJedis, in order to inject the mocks. Also, due to method visibility, one test class for UnifiedJedis must reside in the same package as the class itself. * Rename to subject under test to jedis * Undo script commands changes * Remove tests for removed code * Mark new constructor as visible for testing * React to code review Rename classes as suggested. Move some tests into better suited classed. Remove everything Graph related. * Fix unit tests And add two tests for recently added code. --------- Co-authored-by: Gabriel Erzse Co-authored-by: M Sazzadul Hoque <7600764+sazzad16@users.noreply.github.com> --- .../redis/clients/jedis/UnifiedJedis.java | 4 +- .../clients/jedis/PipeliningBaseTest.java | 10502 ---------------- .../jedis/UnifiedJedisCustomCommandsTest.java | 263 + .../mocked/MockedCommandObjectsTestBase.java | 140 + .../PipeliningBaseBitmapCommandsTest.java | 264 + ...PipeliningBaseBloomFilterCommandsTest.java | 149 + ...eliningBaseCountMinSketchCommandsTest.java | 98 + ...ipeliningBaseCuckooFilterCommandsTest.java | 176 + .../PipeliningBaseGenericCommandsTest.java | 1120 ++ .../PipeliningBaseGeospatialCommandsTest.java | 809 ++ .../PipeliningBaseGraphCommandsTest.java | 140 + .../PipeliningBaseHashCommandsTest.java | 505 + ...PipeliningBaseHyperloglogCommandsTest.java | 106 + .../PipeliningBaseJsonCommandsTest.java | 706 ++ .../PipeliningBaseListCommandsTest.java | 800 ++ .../PipeliningBaseMiscellaneousTest.java | 99 + .../PipeliningBaseMockedTestBase.java | 87 + ...BaseScriptingAndFunctionsCommandsTest.java | 705 ++ ...eliningBaseSearchAndQueryCommandsTest.java | 472 + ...iningBaseServerManagementCommandsTest.java | 58 + .../PipeliningBaseSetCommandsTest.java | 484 + .../PipeliningBaseSortedSetCommandsTest.java | 1921 +++ .../PipeliningBaseStreamCommandsTest.java | 858 ++ .../PipeliningBaseStringCommandsTest.java | 615 + .../PipeliningBaseTDigestCommandsTest.java | 183 + .../PipeliningBaseTimeSeriesCommandsTest.java | 353 + .../PipeliningBaseTopKCommandsTest.java | 105 + .../UnifiedJedisBitmapCommandsTest.java | 368 + .../UnifiedJedisBloomFilterCommandsTest.java | 230 + ...JedisConnectionManagementCommandsTest.java | 25 + ...nifiedJedisCountMinSketchCommandsTest.java | 144 + .../UnifiedJedisCuckooFilterCommandsTest.java | 281 + .../UnifiedJedisGenericCommandsTest.java | 1582 +++ .../UnifiedJedisGeospatialCommandsTest.java | 1145 ++ .../unified/UnifiedJedisHashCommandsTest.java | 767 ++ .../UnifiedJedisHyperloglogCommandsTest.java | 143 + .../unified/UnifiedJedisJsonCommandsTest.java | 1211 ++ .../unified/UnifiedJedisListCommandsTest.java | 1135 ++ .../unified/UnifiedJedisMockedTestBase.java | 66 + .../UnifiedJedisPubSubCommandsTest.java | 46 + ...edisScriptingAndFunctionsCommandsTest.java | 1049 ++ ...nifiedJedisSearchAndQueryCommandsTest.java | 838 ++ ...fiedJedisServerManagementCommandsTest.java | 149 + .../unified/UnifiedJedisSetCommandsTest.java | 688 + .../UnifiedJedisSortedSetCommandsTest.java | 2886 +++++ .../UnifiedJedisStreamCommandsTest.java | 1233 ++ .../UnifiedJedisStringCommandsTest.java | 869 ++ .../UnifiedJedisTDigestCommandsTest.java | 277 + .../UnifiedJedisTimeSeriesCommandsTest.java | 538 + .../unified/UnifiedJedisTopKCommandsTest.java | 161 + ...JedisTriggersAndFunctionsCommandsTest.java | 108 + 51 files changed, 27158 insertions(+), 10503 deletions(-) delete mode 100644 src/test/java/redis/clients/jedis/PipeliningBaseTest.java create mode 100644 src/test/java/redis/clients/jedis/UnifiedJedisCustomCommandsTest.java create mode 100644 src/test/java/redis/clients/jedis/mocked/MockedCommandObjectsTestBase.java create mode 100644 src/test/java/redis/clients/jedis/mocked/pipeline/PipeliningBaseBitmapCommandsTest.java create mode 100644 src/test/java/redis/clients/jedis/mocked/pipeline/PipeliningBaseBloomFilterCommandsTest.java create mode 100644 src/test/java/redis/clients/jedis/mocked/pipeline/PipeliningBaseCountMinSketchCommandsTest.java create mode 100644 src/test/java/redis/clients/jedis/mocked/pipeline/PipeliningBaseCuckooFilterCommandsTest.java create mode 100644 src/test/java/redis/clients/jedis/mocked/pipeline/PipeliningBaseGenericCommandsTest.java create mode 100644 src/test/java/redis/clients/jedis/mocked/pipeline/PipeliningBaseGeospatialCommandsTest.java create mode 100644 src/test/java/redis/clients/jedis/mocked/pipeline/PipeliningBaseGraphCommandsTest.java create mode 100644 src/test/java/redis/clients/jedis/mocked/pipeline/PipeliningBaseHashCommandsTest.java create mode 100644 src/test/java/redis/clients/jedis/mocked/pipeline/PipeliningBaseHyperloglogCommandsTest.java create mode 100644 src/test/java/redis/clients/jedis/mocked/pipeline/PipeliningBaseJsonCommandsTest.java create mode 100644 src/test/java/redis/clients/jedis/mocked/pipeline/PipeliningBaseListCommandsTest.java create mode 100644 src/test/java/redis/clients/jedis/mocked/pipeline/PipeliningBaseMiscellaneousTest.java create mode 100644 src/test/java/redis/clients/jedis/mocked/pipeline/PipeliningBaseMockedTestBase.java create mode 100644 src/test/java/redis/clients/jedis/mocked/pipeline/PipeliningBaseScriptingAndFunctionsCommandsTest.java create mode 100644 src/test/java/redis/clients/jedis/mocked/pipeline/PipeliningBaseSearchAndQueryCommandsTest.java create mode 100644 src/test/java/redis/clients/jedis/mocked/pipeline/PipeliningBaseServerManagementCommandsTest.java create mode 100644 src/test/java/redis/clients/jedis/mocked/pipeline/PipeliningBaseSetCommandsTest.java create mode 100644 src/test/java/redis/clients/jedis/mocked/pipeline/PipeliningBaseSortedSetCommandsTest.java create mode 100644 src/test/java/redis/clients/jedis/mocked/pipeline/PipeliningBaseStreamCommandsTest.java create mode 100644 src/test/java/redis/clients/jedis/mocked/pipeline/PipeliningBaseStringCommandsTest.java create mode 100644 src/test/java/redis/clients/jedis/mocked/pipeline/PipeliningBaseTDigestCommandsTest.java create mode 100644 src/test/java/redis/clients/jedis/mocked/pipeline/PipeliningBaseTimeSeriesCommandsTest.java create mode 100644 src/test/java/redis/clients/jedis/mocked/pipeline/PipeliningBaseTopKCommandsTest.java create mode 100644 src/test/java/redis/clients/jedis/mocked/unified/UnifiedJedisBitmapCommandsTest.java create mode 100644 src/test/java/redis/clients/jedis/mocked/unified/UnifiedJedisBloomFilterCommandsTest.java create mode 100644 src/test/java/redis/clients/jedis/mocked/unified/UnifiedJedisConnectionManagementCommandsTest.java create mode 100644 src/test/java/redis/clients/jedis/mocked/unified/UnifiedJedisCountMinSketchCommandsTest.java create mode 100644 src/test/java/redis/clients/jedis/mocked/unified/UnifiedJedisCuckooFilterCommandsTest.java create mode 100644 src/test/java/redis/clients/jedis/mocked/unified/UnifiedJedisGenericCommandsTest.java create mode 100644 src/test/java/redis/clients/jedis/mocked/unified/UnifiedJedisGeospatialCommandsTest.java create mode 100644 src/test/java/redis/clients/jedis/mocked/unified/UnifiedJedisHashCommandsTest.java create mode 100644 src/test/java/redis/clients/jedis/mocked/unified/UnifiedJedisHyperloglogCommandsTest.java create mode 100644 src/test/java/redis/clients/jedis/mocked/unified/UnifiedJedisJsonCommandsTest.java create mode 100644 src/test/java/redis/clients/jedis/mocked/unified/UnifiedJedisListCommandsTest.java create mode 100644 src/test/java/redis/clients/jedis/mocked/unified/UnifiedJedisMockedTestBase.java create mode 100644 src/test/java/redis/clients/jedis/mocked/unified/UnifiedJedisPubSubCommandsTest.java create mode 100644 src/test/java/redis/clients/jedis/mocked/unified/UnifiedJedisScriptingAndFunctionsCommandsTest.java create mode 100644 src/test/java/redis/clients/jedis/mocked/unified/UnifiedJedisSearchAndQueryCommandsTest.java create mode 100644 src/test/java/redis/clients/jedis/mocked/unified/UnifiedJedisServerManagementCommandsTest.java create mode 100644 src/test/java/redis/clients/jedis/mocked/unified/UnifiedJedisSetCommandsTest.java create mode 100644 src/test/java/redis/clients/jedis/mocked/unified/UnifiedJedisSortedSetCommandsTest.java create mode 100644 src/test/java/redis/clients/jedis/mocked/unified/UnifiedJedisStreamCommandsTest.java create mode 100644 src/test/java/redis/clients/jedis/mocked/unified/UnifiedJedisStringCommandsTest.java create mode 100644 src/test/java/redis/clients/jedis/mocked/unified/UnifiedJedisTDigestCommandsTest.java create mode 100644 src/test/java/redis/clients/jedis/mocked/unified/UnifiedJedisTimeSeriesCommandsTest.java create mode 100644 src/test/java/redis/clients/jedis/mocked/unified/UnifiedJedisTopKCommandsTest.java create mode 100644 src/test/java/redis/clients/jedis/mocked/unified/UnifiedJedisTriggersAndFunctionsCommandsTest.java diff --git a/src/main/java/redis/clients/jedis/UnifiedJedis.java b/src/main/java/redis/clients/jedis/UnifiedJedis.java index 42aa67ae74b..5c7b6e161f7 100644 --- a/src/main/java/redis/clients/jedis/UnifiedJedis.java +++ b/src/main/java/redis/clients/jedis/UnifiedJedis.java @@ -10,6 +10,7 @@ import org.json.JSONArray; import redis.clients.jedis.annots.Experimental; +import redis.clients.jedis.annots.VisibleForTesting; import redis.clients.jedis.args.*; import redis.clients.jedis.bloom.*; import redis.clients.jedis.commands.JedisCommands; @@ -213,7 +214,8 @@ private UnifiedJedis(CommandExecutor executor, ConnectionProvider provider) { } // Uses a fetched connection to process protocol. Should be avoided if possible. - private UnifiedJedis(CommandExecutor executor, ConnectionProvider provider, CommandObjects commandObjects) { + @VisibleForTesting + public UnifiedJedis(CommandExecutor executor, ConnectionProvider provider, CommandObjects commandObjects) { this(executor, provider, commandObjects, null); if (this.provider != null) { try (Connection conn = this.provider.getConnection()) { diff --git a/src/test/java/redis/clients/jedis/PipeliningBaseTest.java b/src/test/java/redis/clients/jedis/PipeliningBaseTest.java deleted file mode 100644 index 2d096ba5700..00000000000 --- a/src/test/java/redis/clients/jedis/PipeliningBaseTest.java +++ /dev/null @@ -1,10502 +0,0 @@ -package redis.clients.jedis; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.contains; -import static org.hamcrest.Matchers.hasSize; -import static org.hamcrest.Matchers.is; -import static org.mockito.Mockito.doNothing; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -import java.util.AbstractMap; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.stream.Collectors; - -import com.google.gson.JsonObject; -import org.json.JSONArray; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; -import redis.clients.jedis.args.BitCountOption; -import redis.clients.jedis.args.BitOP; -import redis.clients.jedis.args.ExpiryOption; -import redis.clients.jedis.args.FlushMode; -import redis.clients.jedis.args.FunctionRestorePolicy; -import redis.clients.jedis.args.GeoUnit; -import redis.clients.jedis.args.ListDirection; -import redis.clients.jedis.args.ListPosition; -import redis.clients.jedis.args.Rawable; -import redis.clients.jedis.args.SortedSetOption; -import redis.clients.jedis.bloom.BFInsertParams; -import redis.clients.jedis.bloom.BFReserveParams; -import redis.clients.jedis.bloom.CFInsertParams; -import redis.clients.jedis.bloom.CFReserveParams; -import redis.clients.jedis.bloom.TDigestMergeParams; -import redis.clients.jedis.commands.ProtocolCommand; -import redis.clients.jedis.graph.GraphCommandObjects; -import redis.clients.jedis.graph.ResultSet; -import redis.clients.jedis.json.JsonObjectMapper; -import redis.clients.jedis.json.JsonSetParams; -import redis.clients.jedis.json.Path; -import redis.clients.jedis.json.Path2; -import redis.clients.jedis.params.BitPosParams; -import redis.clients.jedis.params.GeoAddParams; -import redis.clients.jedis.params.GeoRadiusParam; -import redis.clients.jedis.params.GeoRadiusStoreParam; -import redis.clients.jedis.params.GeoSearchParam; -import redis.clients.jedis.params.GetExParams; -import redis.clients.jedis.params.LCSParams; -import redis.clients.jedis.params.LPosParams; -import redis.clients.jedis.params.MigrateParams; -import redis.clients.jedis.params.RestoreParams; -import redis.clients.jedis.params.ScanParams; -import redis.clients.jedis.params.SetParams; -import redis.clients.jedis.params.SortingParams; -import redis.clients.jedis.params.XAddParams; -import redis.clients.jedis.params.XAutoClaimParams; -import redis.clients.jedis.params.XClaimParams; -import redis.clients.jedis.params.XPendingParams; -import redis.clients.jedis.params.XReadGroupParams; -import redis.clients.jedis.params.XReadParams; -import redis.clients.jedis.params.XTrimParams; -import redis.clients.jedis.params.ZAddParams; -import redis.clients.jedis.params.ZIncrByParams; -import redis.clients.jedis.params.ZParams; -import redis.clients.jedis.params.ZRangeParams; -import redis.clients.jedis.resps.FunctionStats; -import redis.clients.jedis.resps.GeoRadiusResponse; -import redis.clients.jedis.resps.LCSMatchResult; -import redis.clients.jedis.resps.LibraryInfo; -import redis.clients.jedis.resps.ScanResult; -import redis.clients.jedis.resps.StreamConsumerInfo; -import redis.clients.jedis.resps.StreamConsumersInfo; -import redis.clients.jedis.resps.StreamEntry; -import redis.clients.jedis.resps.StreamFullInfo; -import redis.clients.jedis.resps.StreamGroupInfo; -import redis.clients.jedis.resps.StreamInfo; -import redis.clients.jedis.resps.StreamPendingEntry; -import redis.clients.jedis.resps.StreamPendingSummary; -import redis.clients.jedis.resps.Tuple; -import redis.clients.jedis.search.FTCreateParams; -import redis.clients.jedis.search.FTSearchParams; -import redis.clients.jedis.search.FTSpellCheckParams; -import redis.clients.jedis.search.IndexOptions; -import redis.clients.jedis.search.Query; -import redis.clients.jedis.search.Schema; -import redis.clients.jedis.search.SearchResult; -import redis.clients.jedis.search.aggr.AggregationBuilder; -import redis.clients.jedis.search.aggr.AggregationResult; -import redis.clients.jedis.search.schemafields.SchemaField; -import redis.clients.jedis.search.schemafields.TextField; -import redis.clients.jedis.timeseries.AggregationType; -import redis.clients.jedis.timeseries.TSAlterParams; -import redis.clients.jedis.timeseries.TSCreateParams; -import redis.clients.jedis.timeseries.TSElement; -import redis.clients.jedis.timeseries.TSGetParams; -import redis.clients.jedis.timeseries.TSMGetElement; -import redis.clients.jedis.timeseries.TSMGetParams; -import redis.clients.jedis.timeseries.TSMRangeElements; -import redis.clients.jedis.timeseries.TSMRangeParams; -import redis.clients.jedis.timeseries.TSRangeParams; -import redis.clients.jedis.util.KeyValue; - -/** - * Exhaustive unit tests for {@link PipeliningBase}, using Mockito. Given that {@link PipeliningBase} - * is, essentially, only requesting commands from a {@link CommandObjects} instance and sending them - * to its subclasses via {@link PipeliningBase#appendCommand(CommandObject)}, and given that it has - * many methods, using mocks is the most convenient and reliable way to completely test it. - */ -@RunWith(MockitoJUnitRunner.class) -public class PipeliningBaseTest { - - /** - * Used for JSON tests. - */ - @SuppressWarnings("unused") - private static class MyBean { - String field1; - String field2; - } - - /** - * {@link PipeliningBase} under-test. Given that it is an abstract class, an in-place implementation - * is used, that collects commands in a list. - */ - private PipeliningBase pipeliningBase; - - /** - * Accumulates commands sent by the {@link PipeliningBase} under-test to its subclass. - */ - private final List> commands = new ArrayList<>(); - - /** - * {@link CommandObjects} instance used by the {@link PipeliningBase} under-test. Depending on - * the test case, it is trained to return one of the mock {@link CommandObject} instances below. - */ - @Mock - private CommandObjects commandObjects; - - /** - * The {@link GraphCommandObjects} instance used by the {@link PipeliningBase} under-test. - */ - @Mock - private GraphCommandObjects graphCommandObjects; - - /** - * Mock {@link Response} that is returned by {@link PipeliningBase} from the - * {@link PipeliningBase#appendCommand(CommandObject)} method. Using such a mock makes - * it easy to assert. - */ - @Mock - private Response predefinedResponse; - - // Below follows a list of mocked CommandObjects, one per type. This is the cleanest way to create - // mocks, given that CommandObject is a generic class. Using {@code Mockito.mock(...)} yields too - // many warnings related to generics. - // To make the code more readable, try to keep the list sorted alphabetically, and without automatic - // reformatting. - - // @formatter:off - @Mock private CommandObject aggregationResultCommandObject; - @Mock private CommandObject booleanCommandObject; - @Mock private CommandObject> classCommandObject; - @Mock private CommandObject doubleCommandObject; - @Mock private CommandObject functionStatsCommandObject; - @Mock private CommandObject> keyValueLongDoubleCommandObject; - @Mock private CommandObject> keyValueLongLongCommandObject; - @Mock private CommandObject>> keyValueStringListStringCommandObject; - @Mock private CommandObject>> keyValueStringListTupleCommandObject; - @Mock private CommandObject> keyValueStringStringCommandObject; - @Mock private CommandObject> keyValueStringTupleCommandObject; - @Mock private CommandObject>> keyValueBytesListTupleCommandObject; - @Mock private CommandObject>> keyValueBytesListBytesCommandObject; - @Mock private CommandObject> keyValueBytesTupleCommandObject; - @Mock private CommandObject> keyValueBytesBytesCommandObject; - @Mock private CommandObject lcsMatchResultCommandObject; - @Mock private CommandObject> listBooleanCommandObject; - @Mock private CommandObject>> listClassCommandObject; - @Mock private CommandObject> listDoubleCommandObject; - @Mock private CommandObject> listGeoCoordinateCommandObject; - @Mock private CommandObject> listGeoRadiusResponseCommandObject; - @Mock private CommandObject> listJsonArrayCommandObject; - @Mock private CommandObject> listLibraryInfoCommandObject; - @Mock private CommandObject> listLongCommandObject; - @Mock private CommandObject>>> listEntryStringListStreamEntryCommandObject; - @Mock private CommandObject>> listEntryStringStringCommandObject; - @Mock private CommandObject>> listEntryBytesBytesCommandObject; - @Mock private CommandObject> listMyBeanCommandObject; - @Mock private CommandObject> listObjectCommandObject; - @Mock private CommandObject> listStreamConsumerInfoCommandObject; - @Mock private CommandObject> listStreamConsumersInfoCommandObject; - @Mock private CommandObject> listStreamEntryCommandObject; - @Mock private CommandObject> listStreamEntryIdCommandObject; - @Mock private CommandObject> listStreamGroupInfoCommandObject; - @Mock private CommandObject> listStreamPendingEntryCommandObject; - @Mock private CommandObject> listStringCommandObject; - @Mock private CommandObject> listTsElementCommandObject; - @Mock private CommandObject> listTupleCommandObject; - @Mock private CommandObject> listBytesCommandObject; - @Mock private CommandObject longCommandObject; - @Mock private CommandObject> entryLongBytesCommandObject; - @Mock private CommandObject>> entryStreamEntryIdListStreamEntryCommandObject; - @Mock private CommandObject>> entryStreamEntryIdListStreamEntryIdCommandObject; - @Mock private CommandObject>> mapStringListStringCommandObject; - @Mock private CommandObject> mapStringLongCommandObject; - @Mock private CommandObject>> mapStringMapStringDoubleCommandObject; - @Mock private CommandObject> mapStringObjectCommandObject; - @Mock private CommandObject> mapStringStringCommandObject; - @Mock private CommandObject> mapStringTsmGetElementCommandObject; - @Mock private CommandObject> mapStringTsmRangeElementsCommandObject; - @Mock private CommandObject> mapBytesBytesCommandObject; - @Mock private CommandObject myBeanCommandObject; - @Mock private CommandObject objectCommandObject; - @Mock private CommandObject resultSetCommandObject; - @Mock private CommandObject>> scanResultEntryStringStringCommandObject; - @Mock private CommandObject>> scanResultEntryBytesBytesCommandObject; - @Mock private CommandObject> scanResultStringCommandObject; - @Mock private CommandObject> scanResultTupleCommandObject; - @Mock private CommandObject> scanResultBytesCommandObject; - @Mock private CommandObject searchResultCommandObject; - @Mock private CommandObject> setStringCommandObject; - @Mock private CommandObject> setBytesCommandObject; - @Mock private CommandObject streamEntryIdCommandObject; - @Mock private CommandObject streamFullInfoCommandObject; - @Mock private CommandObject streamInfoCommandObject; - @Mock private CommandObject streamPendingSummaryCommandObject; - @Mock private CommandObject stringCommandObject; - @Mock private CommandObject tsElementCommandObject; - @Mock private CommandObject tupleCommandObject; - @Mock private CommandObject bytesCommandObject; - // @formatter:on - - /** - * Prepare a concrete implementation of {@link PipeliningBase} that collects all commands - * in a list, so that asserts can be run on the content of the list. - *

- * Most of the test methods will only test one specific method of {@link PipeliningBase}, - * so only one command will be collected. - *

- * At the end of this test class there are tests that check multiple methods of - * {@link PipeliningBase}. - */ - @Before - public void setUp() { - pipeliningBase = new PipeliningBase(commandObjects) { - - @Override - @SuppressWarnings("unchecked") - protected Response appendCommand(CommandObject commandObject) { - // Collect the command in the list. - commands.add(commandObject); - // Return a well known response, that can be asserted in the test cases. - return (Response) predefinedResponse; - } - }; - - pipeliningBase.setGraphCommands(graphCommandObjects); - } - - @Test - public void testExists() { - when(commandObjects.exists("key")).thenReturn(booleanCommandObject); - - Response result = pipeliningBase.exists("key"); - - assertThat(commands, contains(booleanCommandObject)); - assertThat(result, is(predefinedResponse)); - } - - @Test - public void testExistsMultipleKeys() { - when(commandObjects.exists("key1", "key2", "key3")).thenReturn(longCommandObject); - - Response response = pipeliningBase.exists("key1", "key2", "key3"); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testPersist() { - when(commandObjects.persist("key")).thenReturn(longCommandObject); - - Response response = pipeliningBase.persist("key"); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testType() { - when(commandObjects.type("key")).thenReturn(stringCommandObject); - - Response response = pipeliningBase.type("key"); - - assertThat(commands, contains(stringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testDump() { - when(commandObjects.dump("key")).thenReturn(bytesCommandObject); - - Response response = pipeliningBase.dump("key"); - - assertThat(commands, contains(bytesCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testRestore() { - byte[] serializedValue = new byte[]{ 1, 2, 3 }; - long ttl = 1000L; - - when(commandObjects.restore("key", ttl, serializedValue)).thenReturn(stringCommandObject); - - Response response = pipeliningBase.restore("key", ttl, serializedValue); - - assertThat(commands, contains(stringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testRestoreWithParams() { - byte[] serializedValue = new byte[]{ 1, 2, 3 }; - long ttl = 1000L; - RestoreParams params = new RestoreParams(); - - when(commandObjects.restore("key", ttl, serializedValue, params)).thenReturn(stringCommandObject); - - Response response = pipeliningBase.restore("key", ttl, serializedValue, params); - - assertThat(commands, contains(stringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testExpire() { - when(commandObjects.expire("key", 60)).thenReturn(longCommandObject); - - Response response = pipeliningBase.expire("key", 60); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testExpireWithExpiryOption() { - when(commandObjects.expire("key", 60, ExpiryOption.NX)).thenReturn(longCommandObject); - - Response response = pipeliningBase.expire("key", 60, ExpiryOption.NX); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testPexpire() { - when(commandObjects.pexpire("key", 100000)).thenReturn(longCommandObject); - - Response response = pipeliningBase.pexpire("key", 100000); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testPexpireWithExpiryOption() { - when(commandObjects.pexpire("key", 100000, ExpiryOption.NX)).thenReturn(longCommandObject); - - Response response = pipeliningBase.pexpire("key", 100000, ExpiryOption.NX); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testExpireTime() { - when(commandObjects.expireTime("key")).thenReturn(longCommandObject); - - Response response = pipeliningBase.expireTime("key"); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testPexpireTime() { - when(commandObjects.pexpireTime("key")).thenReturn(longCommandObject); - - Response response = pipeliningBase.pexpireTime("key"); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testExpireAt() { - int unixTime = 1609459200; - - when(commandObjects.expireAt("key", unixTime)).thenReturn(longCommandObject); - - Response response = pipeliningBase.expireAt("key", unixTime); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testExpireAtWithExpiryOption() { - int unixTime = 1609459200; - - when(commandObjects.expireAt("key", unixTime, ExpiryOption.NX)).thenReturn(longCommandObject); - - Response response = pipeliningBase.expireAt("key", unixTime, ExpiryOption.NX); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testPexpireAt() { - long millisecondsTimestamp = 1609459200000L; - - when(commandObjects.pexpireAt("key", millisecondsTimestamp)).thenReturn(longCommandObject); - - Response response = pipeliningBase.pexpireAt("key", millisecondsTimestamp); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testPexpireAtWithExpiryOption() { - long millisecondsTimestamp = 1609459200000L; - - when(commandObjects.pexpireAt("key", millisecondsTimestamp, ExpiryOption.NX)).thenReturn(longCommandObject); - - Response response = pipeliningBase.pexpireAt("key", millisecondsTimestamp, ExpiryOption.NX); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testTtl() { - when(commandObjects.ttl("key")).thenReturn(longCommandObject); - - Response response = pipeliningBase.ttl("key"); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testPttl() { - when(commandObjects.pttl("key")).thenReturn(longCommandObject); - - Response response = pipeliningBase.pttl("key"); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testTouchSingleKey() { - when(commandObjects.touch("key")).thenReturn(longCommandObject); - - Response response = pipeliningBase.touch("key"); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testTouchMultipleKeys() { - String[] keys = { "key1", "key2", "key3" }; - - when(commandObjects.touch(keys)).thenReturn(longCommandObject); - - Response response = pipeliningBase.touch(keys); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testSortSingleKey() { - when(commandObjects.sort("key")).thenReturn(listStringCommandObject); - - Response> response = pipeliningBase.sort("key"); - - assertThat(commands, contains(listStringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testSortSingleKeyStore() { - when(commandObjects.sort("key", "dstKey")).thenReturn(longCommandObject); - - Response response = pipeliningBase.sort("key", "dstKey"); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testSortWithParams() { - SortingParams sortingParams = new SortingParams(); - - when(commandObjects.sort("key", sortingParams)).thenReturn(listStringCommandObject); - - Response> response = pipeliningBase.sort("key", sortingParams); - - assertThat(commands, contains(listStringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testSortWithParamsStore() { - SortingParams sortingParams = new SortingParams(); - - when(commandObjects.sort("key", sortingParams, "dstKey")).thenReturn(longCommandObject); - - Response response = pipeliningBase.sort("key", sortingParams, "dstKey"); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testSortReadonly() { - SortingParams sortingParams = new SortingParams(); - - when(commandObjects.sortReadonly("key", sortingParams)).thenReturn(listStringCommandObject); - - Response> response = pipeliningBase.sortReadonly("key", sortingParams); - - assertThat(commands, contains(listStringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testDelSingleKey() { - when(commandObjects.del("key")).thenReturn(longCommandObject); - - Response response = pipeliningBase.del("key"); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testDelMultipleKeys() { - String[] keys = { "key1", "key2", "key3" }; - - when(commandObjects.del(keys)).thenReturn(longCommandObject); - - Response response = pipeliningBase.del(keys); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testUnlinkSingleKey() { - when(commandObjects.unlink("key")).thenReturn(longCommandObject); - - Response response = pipeliningBase.unlink("key"); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testUnlinkMultipleKeys() { - String[] keys = { "key1", "key2", "key3" }; - - when(commandObjects.unlink(keys)).thenReturn(longCommandObject); - - Response response = pipeliningBase.unlink(keys); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testCopy() { - when(commandObjects.copy("srcKey", "dstKey", true)).thenReturn(booleanCommandObject); - - Response response = pipeliningBase.copy("srcKey", "dstKey", true); - - assertThat(commands, contains(booleanCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testRename() { - when(commandObjects.rename("oldkey", "newkey")).thenReturn(stringCommandObject); - - Response response = pipeliningBase.rename("oldkey", "newkey"); - - assertThat(commands, contains(stringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testRenamenx() { - when(commandObjects.renamenx("oldkey", "newkey")).thenReturn(longCommandObject); - - Response response = pipeliningBase.renamenx("oldkey", "newkey"); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testMemoryUsageSingleKey() { - when(commandObjects.memoryUsage("key")).thenReturn(longCommandObject); - - Response response = pipeliningBase.memoryUsage("key"); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testMemoryUsageWithSamples() { - when(commandObjects.memoryUsage("key", 10)).thenReturn(longCommandObject); - - Response response = pipeliningBase.memoryUsage("key", 10); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testObjectRefcount() { - when(commandObjects.objectRefcount("key")).thenReturn(longCommandObject); - - Response response = pipeliningBase.objectRefcount("key"); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testObjectEncoding() { - when(commandObjects.objectEncoding("key")).thenReturn(stringCommandObject); - - Response response = pipeliningBase.objectEncoding("key"); - - assertThat(commands, contains(stringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testObjectIdletime() { - when(commandObjects.objectIdletime("key")).thenReturn(longCommandObject); - - Response response = pipeliningBase.objectIdletime("key"); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testObjectFreq() { - when(commandObjects.objectFreq("key")).thenReturn(longCommandObject); - - Response response = pipeliningBase.objectFreq("key"); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testMigrateSingleKey() { - when(commandObjects.migrate("host", 6379, "key", 5000)).thenReturn(stringCommandObject); - - Response response = pipeliningBase.migrate("host", 6379, "key", 5000); - - assertThat(commands, contains(stringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testMigrateMultipleKeys() { - MigrateParams params = new MigrateParams(); - String[] keys = { "key1", "key2" }; - - when(commandObjects.migrate("host", 6379, 5000, params, keys)).thenReturn(stringCommandObject); - - Response response = pipeliningBase.migrate("host", 6379, 5000, params, keys); - - assertThat(commands, contains(stringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testKeys() { - when(commandObjects.keys("pattern")).thenReturn(setStringCommandObject); - - Response> response = pipeliningBase.keys("pattern"); - - assertThat(commands, contains(setStringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testScan() { - when(commandObjects.scan("0")).thenReturn(scanResultStringCommandObject); - - Response> response = pipeliningBase.scan("0"); - - assertThat(commands, contains(scanResultStringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testScanWithParams() { - ScanParams scanParams = new ScanParams(); - - when(commandObjects.scan("0", scanParams)).thenReturn(scanResultStringCommandObject); - - Response> response = pipeliningBase.scan("0", scanParams); - - assertThat(commands, contains(scanResultStringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testScanWithType() { - ScanParams scanParams = new ScanParams(); - - when(commandObjects.scan("0", scanParams, "type")).thenReturn(scanResultStringCommandObject); - - Response> response = pipeliningBase.scan("0", scanParams, "type"); - - assertThat(commands, contains(scanResultStringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testRandomKey() { - when(commandObjects.randomKey()).thenReturn(stringCommandObject); - - Response response = pipeliningBase.randomKey(); - - assertThat(commands, contains(stringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testGet() { - when(commandObjects.get("key")).thenReturn(stringCommandObject); - - Response response = pipeliningBase.get("key"); - - assertThat(commands, contains(stringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testSetGet() { - when(commandObjects.setGet("key", "value")).thenReturn(stringCommandObject); - - Response response = pipeliningBase.setGet("key", "value"); - - assertThat(commands, contains(stringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testSetGetWithParams() { - SetParams setParams = new SetParams(); - - when(commandObjects.setGet("key", "value", setParams)).thenReturn(stringCommandObject); - - Response response = pipeliningBase.setGet("key", "value", setParams); - - assertThat(commands, contains(stringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testGetDel() { - when(commandObjects.getDel("key")).thenReturn(stringCommandObject); - - Response response = pipeliningBase.getDel("key"); - - assertThat(commands, contains(stringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testGetEx() { - GetExParams params = new GetExParams(); - - when(commandObjects.getEx("key", params)).thenReturn(stringCommandObject); - - Response response = pipeliningBase.getEx("key", params); - - assertThat(commands, contains(stringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testSetbit() { - when(commandObjects.setbit("key", 100, true)).thenReturn(booleanCommandObject); - - Response response = pipeliningBase.setbit("key", 100, true); - - assertThat(commands, contains(booleanCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testGetbit() { - when(commandObjects.getbit("key", 100)).thenReturn(booleanCommandObject); - - Response response = pipeliningBase.getbit("key", 100); - - assertThat(commands, contains(booleanCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testSetrange() { - when(commandObjects.setrange("key", 100, "value")).thenReturn(longCommandObject); - - Response response = pipeliningBase.setrange("key", 100, "value"); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testGetrange() { - when(commandObjects.getrange("key", 0, 100)).thenReturn(stringCommandObject); - - Response response = pipeliningBase.getrange("key", 0, 100); - - assertThat(commands, contains(stringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testGetSet() { - when(commandObjects.getSet("key", "value")).thenReturn(stringCommandObject); - - Response response = pipeliningBase.getSet("key", "value"); - - assertThat(commands, contains(stringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testSetnx() { - when(commandObjects.setnx("key", "value")).thenReturn(longCommandObject); - - Response response = pipeliningBase.setnx("key", "value"); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testSetex() { - when(commandObjects.setex("key", 60, "value")).thenReturn(stringCommandObject); - - Response response = pipeliningBase.setex("key", 60, "value"); - - assertThat(commands, contains(stringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testPsetex() { - when(commandObjects.psetex("key", 100000, "value")).thenReturn(stringCommandObject); - - Response response = pipeliningBase.psetex("key", 100000, "value"); - - assertThat(commands, contains(stringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testMget() { - String[] keys = { "key1", "key2", "key3" }; - - when(commandObjects.mget(keys)).thenReturn(listStringCommandObject); - - Response> response = pipeliningBase.mget(keys); - - assertThat(commands, contains(listStringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testMset() { - String[] keysvalues = { "key1", "value1", "key2", "value2" }; - - when(commandObjects.mset(keysvalues)).thenReturn(stringCommandObject); - - Response response = pipeliningBase.mset(keysvalues); - - assertThat(commands, contains(stringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testMsetnx() { - String[] keysvalues = { "key1", "value1", "key2", "value2" }; - - when(commandObjects.msetnx(keysvalues)).thenReturn(longCommandObject); - - Response response = pipeliningBase.msetnx(keysvalues); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testIncr() { - when(commandObjects.incr("key")).thenReturn(longCommandObject); - - Response response = pipeliningBase.incr("key"); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testIncrBy() { - when(commandObjects.incrBy("key", 10L)).thenReturn(longCommandObject); - - Response response = pipeliningBase.incrBy("key", 10L); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testIncrByFloat() { - when(commandObjects.incrByFloat("key", 1.5)).thenReturn(doubleCommandObject); - - Response response = pipeliningBase.incrByFloat("key", 1.5); - - assertThat(commands, contains(doubleCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testDecr() { - when(commandObjects.decr("key")).thenReturn(longCommandObject); - - Response response = pipeliningBase.decr("key"); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testDecrBy() { - when(commandObjects.decrBy("key", 10L)).thenReturn(longCommandObject); - - Response response = pipeliningBase.decrBy("key", 10L); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testAppend() { - when(commandObjects.append("key", "value")).thenReturn(longCommandObject); - - Response response = pipeliningBase.append("key", "value"); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testSubstr() { - when(commandObjects.substr("key", 0, 10)).thenReturn(stringCommandObject); - - Response response = pipeliningBase.substr("key", 0, 10); - - assertThat(commands, contains(stringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testStrlen() { - when(commandObjects.strlen("key")).thenReturn(longCommandObject); - - Response response = pipeliningBase.strlen("key"); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testBitcount() { - when(commandObjects.bitcount("key")).thenReturn(longCommandObject); - - Response response = pipeliningBase.bitcount("key"); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testBitcountRange() { - when(commandObjects.bitcount("key", 0, 10)).thenReturn(longCommandObject); - - Response response = pipeliningBase.bitcount("key", 0, 10); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testBitcountRangeOption() { - BitCountOption option = BitCountOption.BYTE; - - when(commandObjects.bitcount("key", 0, 10, option)).thenReturn(longCommandObject); - - Response response = pipeliningBase.bitcount("key", 0, 10, option); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testBitpos() { - when(commandObjects.bitpos("key", true)).thenReturn(longCommandObject); - - Response response = pipeliningBase.bitpos("key", true); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testBitposParams() { - BitPosParams params = new BitPosParams(0, -1); - - when(commandObjects.bitpos("key", true, params)).thenReturn(longCommandObject); - - Response response = pipeliningBase.bitpos("key", true, params); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testBitfield() { - String[] arguments = { "INCRBY", "mykey", "2", "1" }; - - when(commandObjects.bitfield("key", arguments)).thenReturn(listLongCommandObject); - - Response> response = pipeliningBase.bitfield("key", arguments); - - assertThat(commands, contains(listLongCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testBitfieldReadonly() { - String[] arguments = { "GET", "u4", "0" }; - - when(commandObjects.bitfieldReadonly("key", arguments)).thenReturn(listLongCommandObject); - - Response> response = pipeliningBase.bitfieldReadonly("key", arguments); - - assertThat(commands, contains(listLongCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testBitop() { - BitOP op = BitOP.AND; - - when(commandObjects.bitop(op, "destKey", "srckey1", "srckey2")).thenReturn(longCommandObject); - - Response response = pipeliningBase.bitop(op, "destKey", "srckey1", "srckey2"); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testLcs() { - LCSParams params = new LCSParams(); - - when(commandObjects.lcs("keyA", "keyB", params)).thenReturn(lcsMatchResultCommandObject); - - Response response = pipeliningBase.lcs("keyA", "keyB", params); - - assertThat(commands, contains(lcsMatchResultCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testSet() { - when(commandObjects.set("key", "value")).thenReturn(stringCommandObject); - - Response response = pipeliningBase.set("key", "value"); - - assertThat(commands, contains(stringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testSetWithParams() { - SetParams params = new SetParams(); - - when(commandObjects.set("key", "value", params)).thenReturn(stringCommandObject); - - Response response = pipeliningBase.set("key", "value", params); - - assertThat(commands, contains(stringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testRpush() { - when(commandObjects.rpush("key", "value1", "value2")).thenReturn(longCommandObject); - - Response response = pipeliningBase.rpush("key", "value1", "value2"); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testLpush() { - when(commandObjects.lpush("key", "value1", "value2")).thenReturn(longCommandObject); - - Response response = pipeliningBase.lpush("key", "value1", "value2"); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testLlen() { - when(commandObjects.llen("key")).thenReturn(longCommandObject); - - Response response = pipeliningBase.llen("key"); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testLrange() { - when(commandObjects.lrange("key", 0, -1)).thenReturn(listStringCommandObject); - - Response> response = pipeliningBase.lrange("key", 0, -1); - - assertThat(commands, contains(listStringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testLtrim() { - when(commandObjects.ltrim("key", 1, -1)).thenReturn(stringCommandObject); - - Response response = pipeliningBase.ltrim("key", 1, -1); - - assertThat(commands, contains(stringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testLindex() { - when(commandObjects.lindex("key", 1)).thenReturn(stringCommandObject); - - Response response = pipeliningBase.lindex("key", 1); - - assertThat(commands, contains(stringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testLset() { - when(commandObjects.lset("key", 1, "value")).thenReturn(stringCommandObject); - - Response response = pipeliningBase.lset("key", 1, "value"); - - assertThat(commands, contains(stringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testLrem() { - when(commandObjects.lrem("key", 2, "value")).thenReturn(longCommandObject); - - Response response = pipeliningBase.lrem("key", 2, "value"); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testLpop() { - when(commandObjects.lpop("key")).thenReturn(stringCommandObject); - - Response response = pipeliningBase.lpop("key"); - - assertThat(commands, contains(stringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testLpopCount() { - when(commandObjects.lpop("key", 2)).thenReturn(listStringCommandObject); - - Response> response = pipeliningBase.lpop("key", 2); - - assertThat(commands, contains(listStringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testLpos() { - when(commandObjects.lpos("key", "element")).thenReturn(longCommandObject); - - Response response = pipeliningBase.lpos("key", "element"); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testLposWithParams() { - LPosParams params = new LPosParams(); - - when(commandObjects.lpos("key", "element", params)).thenReturn(longCommandObject); - - Response response = pipeliningBase.lpos("key", "element", params); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testLposWithParamsCount() { - LPosParams params = new LPosParams(); - - when(commandObjects.lpos("key", "element", params, 3)).thenReturn(listLongCommandObject); - - Response> response = pipeliningBase.lpos("key", "element", params, 3); - - assertThat(commands, contains(listLongCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testRpop() { - when(commandObjects.rpop("key")).thenReturn(stringCommandObject); - - Response response = pipeliningBase.rpop("key"); - - assertThat(commands, contains(stringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testRpopCount() { - when(commandObjects.rpop("key", 2)).thenReturn(listStringCommandObject); - - Response> response = pipeliningBase.rpop("key", 2); - - assertThat(commands, contains(listStringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testLinsert() { - ListPosition where = ListPosition.BEFORE; - - when(commandObjects.linsert("key", where, "pivot", "value")).thenReturn(longCommandObject); - - Response response = pipeliningBase.linsert("key", where, "pivot", "value"); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testLpushx() { - when(commandObjects.lpushx("key", "value1", "value2")).thenReturn(longCommandObject); - - Response response = pipeliningBase.lpushx("key", "value1", "value2"); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testRpushx() { - when(commandObjects.rpushx("key", "value1", "value2")).thenReturn(longCommandObject); - - Response response = pipeliningBase.rpushx("key", "value1", "value2"); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testBlpop() { - when(commandObjects.blpop(30, "key")).thenReturn(listStringCommandObject); - - Response> response = pipeliningBase.blpop(30, "key"); - - assertThat(commands, contains(listStringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testBlpopDoubleTimeoutKey() { - when(commandObjects.blpop(30.0, "key")).thenReturn(keyValueStringStringCommandObject); - - Response> response = pipeliningBase.blpop(30.0, "key"); - - assertThat(commands, contains(keyValueStringStringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testBrpop() { - when(commandObjects.brpop(30, "key")).thenReturn(listStringCommandObject); - - Response> response = pipeliningBase.brpop(30, "key"); - - assertThat(commands, contains(listStringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testBrpopDoubleTimeoutKey() { - when(commandObjects.brpop(30.0, "key")).thenReturn(keyValueStringStringCommandObject); - - Response> response = pipeliningBase.brpop(30.0, "key"); - - assertThat(commands, contains(keyValueStringStringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testBlpopMultipleKeys() { - when(commandObjects.blpop(30, "key1", "key2")).thenReturn(listStringCommandObject); - - Response> response = pipeliningBase.blpop(30, "key1", "key2"); - - assertThat(commands, contains(listStringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testBlpopDoubleTimeoutKeys() { - when(commandObjects.blpop(30.0, "key1", "key2")).thenReturn(keyValueStringStringCommandObject); - - Response> response = pipeliningBase.blpop(30.0, "key1", "key2"); - - assertThat(commands, contains(keyValueStringStringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testBrpopMultipleKeys() { - when(commandObjects.brpop(30, "key1", "key2")).thenReturn(listStringCommandObject); - - Response> response = pipeliningBase.brpop(30, "key1", "key2"); - - assertThat(commands, contains(listStringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testBrpopDoubleTimeoutKeys() { - when(commandObjects.brpop(30.0, "key1", "key2")).thenReturn(keyValueStringStringCommandObject); - - Response> response = pipeliningBase.brpop(30.0, "key1", "key2"); - - assertThat(commands, contains(keyValueStringStringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testRpoplpush() { - when(commandObjects.rpoplpush("srcKey", "dstKey")).thenReturn(stringCommandObject); - - Response response = pipeliningBase.rpoplpush("srcKey", "dstKey"); - - assertThat(commands, contains(stringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testBrpoplpush() { - when(commandObjects.brpoplpush("source", "destination", 30)).thenReturn(stringCommandObject); - - Response response = pipeliningBase.brpoplpush("source", "destination", 30); - - assertThat(commands, contains(stringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testLmove() { - ListDirection from = ListDirection.LEFT; - ListDirection to = ListDirection.RIGHT; - - when(commandObjects.lmove("srcKey", "dstKey", from, to)).thenReturn(stringCommandObject); - - Response response = pipeliningBase.lmove("srcKey", "dstKey", from, to); - - assertThat(commands, contains(stringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testBlmove() { - ListDirection from = ListDirection.LEFT; - ListDirection to = ListDirection.RIGHT; - double timeout = 1.0; - - when(commandObjects.blmove("srcKey", "dstKey", from, to, timeout)).thenReturn(stringCommandObject); - - Response response = pipeliningBase.blmove("srcKey", "dstKey", from, to, timeout); - - assertThat(commands, contains(stringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testLmpop() { - ListDirection direction = ListDirection.LEFT; - - when(commandObjects.lmpop(direction, "key1", "key2")).thenReturn(keyValueStringListStringCommandObject); - - Response>> response = pipeliningBase.lmpop(direction, "key1", "key2"); - - assertThat(commands, contains(keyValueStringListStringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testLmpopCount() { - ListDirection direction = ListDirection.LEFT; - int count = 2; - - when(commandObjects.lmpop(direction, count, "key1", "key2")).thenReturn(keyValueStringListStringCommandObject); - - Response>> response = pipeliningBase.lmpop(direction, count, "key1", "key2"); - - assertThat(commands, contains(keyValueStringListStringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testBlmpop() { - double timeout = 1.0; - ListDirection direction = ListDirection.LEFT; - - when(commandObjects.blmpop(timeout, direction, "key1", "key2")).thenReturn(keyValueStringListStringCommandObject); - - Response>> response = pipeliningBase.blmpop(timeout, direction, "key1", "key2"); - - assertThat(commands, contains(keyValueStringListStringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testBlmpopCount() { - double timeout = 1.0; - ListDirection direction = ListDirection.LEFT; - int count = 2; - - when(commandObjects.blmpop(timeout, direction, count, "key1", "key2")).thenReturn(keyValueStringListStringCommandObject); - - Response>> response = pipeliningBase.blmpop(timeout, direction, count, "key1", "key2"); - - assertThat(commands, contains(keyValueStringListStringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testHset() { - when(commandObjects.hset("key", "field", "value")).thenReturn(longCommandObject); - - Response response = pipeliningBase.hset("key", "field", "value"); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testHsetMap() { - Map hash = new HashMap<>(); - hash.put("field1", "value1"); - hash.put("field2", "value2"); - - when(commandObjects.hset("key", hash)).thenReturn(longCommandObject); - - Response response = pipeliningBase.hset("key", hash); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testHget() { - when(commandObjects.hget("key", "field")).thenReturn(stringCommandObject); - - Response response = pipeliningBase.hget("key", "field"); - - assertThat(commands, contains(stringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testHsetnx() { - when(commandObjects.hsetnx("key", "field", "value")).thenReturn(longCommandObject); - - Response response = pipeliningBase.hsetnx("key", "field", "value"); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testHmset() { - Map hash = new HashMap<>(); - hash.put("field1", "value1"); - hash.put("field2", "value2"); - - when(commandObjects.hmset("key", hash)).thenReturn(stringCommandObject); - - Response response = pipeliningBase.hmset("key", hash); - - assertThat(commands, contains(stringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testHmget() { - when(commandObjects.hmget("key", "field1", "field2")).thenReturn(listStringCommandObject); - - Response> response = pipeliningBase.hmget("key", "field1", "field2"); - - assertThat(commands, contains(listStringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testHincrBy() { - when(commandObjects.hincrBy("key", "field", 1L)).thenReturn(longCommandObject); - - Response response = pipeliningBase.hincrBy("key", "field", 1L); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testHincrByFloat() { - when(commandObjects.hincrByFloat("key", "field", 1.0)).thenReturn(doubleCommandObject); - - Response response = pipeliningBase.hincrByFloat("key", "field", 1.0); - - assertThat(commands, contains(doubleCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testHexists() { - when(commandObjects.hexists("key", "field")).thenReturn(booleanCommandObject); - - Response response = pipeliningBase.hexists("key", "field"); - - assertThat(commands, contains(booleanCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testHdel() { - when(commandObjects.hdel("key", "field1", "field2")).thenReturn(longCommandObject); - - Response response = pipeliningBase.hdel("key", "field1", "field2"); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testHlen() { - when(commandObjects.hlen("key")).thenReturn(longCommandObject); - - Response response = pipeliningBase.hlen("key"); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testHkeys() { - when(commandObjects.hkeys("key")).thenReturn(setStringCommandObject); - - Response> response = pipeliningBase.hkeys("key"); - - assertThat(commands, contains(setStringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testHvals() { - when(commandObjects.hvals("key")).thenReturn(listStringCommandObject); - - Response> response = pipeliningBase.hvals("key"); - - assertThat(commands, contains(listStringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testHgetAll() { - when(commandObjects.hgetAll("key")).thenReturn(mapStringStringCommandObject); - - Response> response = pipeliningBase.hgetAll("key"); - - assertThat(commands, contains(mapStringStringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testHrandfield() { - when(commandObjects.hrandfield("key")).thenReturn(stringCommandObject); - - Response response = pipeliningBase.hrandfield("key"); - - assertThat(commands, contains(stringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testHrandfieldCount() { - long count = 2; - - when(commandObjects.hrandfield("key", count)).thenReturn(listStringCommandObject); - - Response> response = pipeliningBase.hrandfield("key", count); - - assertThat(commands, contains(listStringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testHrandfieldWithValues() { - long count = 2; - - when(commandObjects.hrandfieldWithValues("key", count)).thenReturn(listEntryStringStringCommandObject); - - Response>> response = pipeliningBase.hrandfieldWithValues("key", count); - - assertThat(commands, contains(listEntryStringStringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testHscan() { - String cursor = "0"; - ScanParams params = new ScanParams(); - - when(commandObjects.hscan("key", cursor, params)).thenReturn(scanResultEntryStringStringCommandObject); - - Response>> response = pipeliningBase.hscan("key", cursor, params); - - assertThat(commands, contains(scanResultEntryStringStringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testHscanNoValues() { - String cursor = "0"; - ScanParams params = new ScanParams(); - - when(commandObjects.hscanNoValues("key", cursor, params)).thenReturn(scanResultStringCommandObject); - - Response> response = pipeliningBase.hscanNoValues("key", cursor, params); - - assertThat(commands, contains(scanResultStringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testHstrlen() { - when(commandObjects.hstrlen("key", "field")).thenReturn(longCommandObject); - - Response response = pipeliningBase.hstrlen("key", "field"); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testSadd() { - when(commandObjects.sadd("key", "member1", "member2")).thenReturn(longCommandObject); - - Response response = pipeliningBase.sadd("key", "member1", "member2"); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testSmembers() { - when(commandObjects.smembers("key")).thenReturn(setStringCommandObject); - - Response> response = pipeliningBase.smembers("key"); - - assertThat(commands, contains(setStringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testSrem() { - when(commandObjects.srem("key", "member1", "member2")).thenReturn(longCommandObject); - - Response response = pipeliningBase.srem("key", "member1", "member2"); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testSpop() { - when(commandObjects.spop("key")).thenReturn(stringCommandObject); - - Response response = pipeliningBase.spop("key"); - - assertThat(commands, contains(stringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testSpopCount() { - long count = 2; - - when(commandObjects.spop("key", count)).thenReturn(setStringCommandObject); - - Response> response = pipeliningBase.spop("key", count); - - assertThat(commands, contains(setStringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testScard() { - when(commandObjects.scard("key")).thenReturn(longCommandObject); - - Response response = pipeliningBase.scard("key"); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testSismember() { - when(commandObjects.sismember("key", "member")).thenReturn(booleanCommandObject); - - Response response = pipeliningBase.sismember("key", "member"); - - assertThat(commands, contains(booleanCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testSmismember() { - when(commandObjects.smismember("key", "member1", "member2")).thenReturn(listBooleanCommandObject); - - Response> response = pipeliningBase.smismember("key", "member1", "member2"); - - assertThat(commands, contains(listBooleanCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testSrandmember() { - when(commandObjects.srandmember("key")).thenReturn(stringCommandObject); - - Response response = pipeliningBase.srandmember("key"); - - assertThat(commands, contains(stringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testSrandmemberCount() { - int count = 2; - - when(commandObjects.srandmember("key", count)).thenReturn(listStringCommandObject); - - Response> response = pipeliningBase.srandmember("key", count); - - assertThat(commands, contains(listStringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testSscan() { - String cursor = "0"; - ScanParams params = new ScanParams(); - - when(commandObjects.sscan("key", cursor, params)).thenReturn(scanResultStringCommandObject); - - Response> response = pipeliningBase.sscan("key", cursor, params); - - assertThat(commands, contains(scanResultStringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testSdiff() { - when(commandObjects.sdiff("key1", "key2")).thenReturn(setStringCommandObject); - - Response> response = pipeliningBase.sdiff("key1", "key2"); - - assertThat(commands, contains(setStringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testSdiffstore() { - when(commandObjects.sdiffstore("dstKey", "key1", "key2")).thenReturn(longCommandObject); - - Response response = pipeliningBase.sdiffstore("dstKey", "key1", "key2"); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testSinter() { - when(commandObjects.sinter("key1", "key2")).thenReturn(setStringCommandObject); - - Response> response = pipeliningBase.sinter("key1", "key2"); - - assertThat(commands, contains(setStringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testSinterstore() { - when(commandObjects.sinterstore("dstKey", "key1", "key2")).thenReturn(longCommandObject); - - Response response = pipeliningBase.sinterstore("dstKey", "key1", "key2"); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testSintercard() { - when(commandObjects.sintercard("key1", "key2")).thenReturn(longCommandObject); - - Response response = pipeliningBase.sintercard("key1", "key2"); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testSintercardWithLimit() { - int limit = 1; - - when(commandObjects.sintercard(limit, "key1", "key2")).thenReturn(longCommandObject); - - Response response = pipeliningBase.sintercard(limit, "key1", "key2"); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testSunion() { - when(commandObjects.sunion("key1", "key2")).thenReturn(setStringCommandObject); - - Response> response = pipeliningBase.sunion("key1", "key2"); - - assertThat(commands, contains(setStringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testSunionstore() { - when(commandObjects.sunionstore("dstKey", "key1", "key2")).thenReturn(longCommandObject); - - Response response = pipeliningBase.sunionstore("dstKey", "key1", "key2"); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testSmove() { - when(commandObjects.smove("srcKey", "dstKey", "member")).thenReturn(longCommandObject); - - Response response = pipeliningBase.smove("srcKey", "dstKey", "member"); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testZaddSingle() { - when(commandObjects.zadd("key", 1.0, "member")).thenReturn(longCommandObject); - - Response response = pipeliningBase.zadd("key", 1.0, "member"); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testZaddSingleWithParams() { - ZAddParams params = new ZAddParams(); - - when(commandObjects.zadd("key", 1.0, "member", params)).thenReturn(longCommandObject); - - Response response = pipeliningBase.zadd("key", 1.0, "member", params); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testZaddMultiple() { - Map scoreMembers = new HashMap<>(); - scoreMembers.put("member1", 1.0); - scoreMembers.put("member2", 2.0); - - when(commandObjects.zadd("key", scoreMembers)).thenReturn(longCommandObject); - - Response response = pipeliningBase.zadd("key", scoreMembers); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testZaddMultipleWithParams() { - Map scoreMembers = new HashMap<>(); - scoreMembers.put("member1", 1.0); - scoreMembers.put("member2", 2.0); - - ZAddParams params = new ZAddParams(); - - when(commandObjects.zadd("key", scoreMembers, params)).thenReturn(longCommandObject); - - Response response = pipeliningBase.zadd("key", scoreMembers, params); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testZaddIncr() { - ZAddParams params = new ZAddParams(); - - when(commandObjects.zaddIncr("key", 1.0, "member", params)).thenReturn(doubleCommandObject); - - Response response = pipeliningBase.zaddIncr("key", 1.0, "member", params); - - assertThat(commands, contains(doubleCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testZrem() { - when(commandObjects.zrem("key", "member1", "member2")).thenReturn(longCommandObject); - - Response response = pipeliningBase.zrem("key", "member1", "member2"); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testZincrby() { - when(commandObjects.zincrby("key", 1.0, "member")).thenReturn(doubleCommandObject); - - Response response = pipeliningBase.zincrby("key", 1.0, "member"); - - assertThat(commands, contains(doubleCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testZincrbyWithParams() { - ZIncrByParams params = new ZIncrByParams(); - - when(commandObjects.zincrby("key", 1.0, "member", params)).thenReturn(doubleCommandObject); - - Response response = pipeliningBase.zincrby("key", 1.0, "member", params); - - assertThat(commands, contains(doubleCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testZrank() { - when(commandObjects.zrank("key", "member")).thenReturn(longCommandObject); - - Response response = pipeliningBase.zrank("key", "member"); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testZrevrank() { - when(commandObjects.zrevrank("key", "member")).thenReturn(longCommandObject); - - Response response = pipeliningBase.zrevrank("key", "member"); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testZrankWithScore() { - when(commandObjects.zrankWithScore("key", "member")).thenReturn(keyValueLongDoubleCommandObject); - - Response> response = pipeliningBase.zrankWithScore("key", "member"); - - assertThat(commands, contains(keyValueLongDoubleCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testZrevrankWithScore() { - when(commandObjects.zrevrankWithScore("key", "member")).thenReturn(keyValueLongDoubleCommandObject); - - Response> response = pipeliningBase.zrevrankWithScore("key", "member"); - - assertThat(commands, contains(keyValueLongDoubleCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testZrange() { - when(commandObjects.zrange("key", 0, -1)).thenReturn(listStringCommandObject); - - Response> response = pipeliningBase.zrange("key", 0, -1); - - assertThat(commands, contains(listStringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testZrevrange() { - when(commandObjects.zrevrange("key", 0, -1)).thenReturn(listStringCommandObject); - - Response> response = pipeliningBase.zrevrange("key", 0, -1); - - assertThat(commands, contains(listStringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testZrangeWithScores() { - when(commandObjects.zrangeWithScores("key", 0, -1)).thenReturn(listTupleCommandObject); - - Response> response = pipeliningBase.zrangeWithScores("key", 0, -1); - - assertThat(commands, contains(listTupleCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testZrevrangeWithScores() { - when(commandObjects.zrevrangeWithScores("key", 0, -1)).thenReturn(listTupleCommandObject); - - Response> response = pipeliningBase.zrevrangeWithScores("key", 0, -1); - - assertThat(commands, contains(listTupleCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testZrandmember() { - when(commandObjects.zrandmember("key")).thenReturn(stringCommandObject); - - Response response = pipeliningBase.zrandmember("key"); - - assertThat(commands, contains(stringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testZrandmemberCount() { - long count = 2; - - when(commandObjects.zrandmember("key", count)).thenReturn(listStringCommandObject); - - Response> response = pipeliningBase.zrandmember("key", count); - - assertThat(commands, contains(listStringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testZrandmemberWithScores() { - long count = 2; - - when(commandObjects.zrandmemberWithScores("key", count)).thenReturn(listTupleCommandObject); - - Response> response = pipeliningBase.zrandmemberWithScores("key", count); - - assertThat(commands, contains(listTupleCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testZcard() { - when(commandObjects.zcard("key")).thenReturn(longCommandObject); - - Response response = pipeliningBase.zcard("key"); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testZscore() { - when(commandObjects.zscore("key", "member")).thenReturn(doubleCommandObject); - - Response response = pipeliningBase.zscore("key", "member"); - - assertThat(commands, contains(doubleCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testZmscore() { - when(commandObjects.zmscore("key", "member1", "member2")).thenReturn(listDoubleCommandObject); - - Response> response = pipeliningBase.zmscore("key", "member1", "member2"); - - assertThat(commands, contains(listDoubleCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testZpopmax() { - when(commandObjects.zpopmax("key")).thenReturn(tupleCommandObject); - - Response response = pipeliningBase.zpopmax("key"); - - assertThat(commands, contains(tupleCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testZpopmaxCount() { - int count = 2; - - when(commandObjects.zpopmax("key", count)).thenReturn(listTupleCommandObject); - - Response> response = pipeliningBase.zpopmax("key", count); - - assertThat(commands, contains(listTupleCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testZpopmin() { - when(commandObjects.zpopmin("key")).thenReturn(tupleCommandObject); - - Response response = pipeliningBase.zpopmin("key"); - - assertThat(commands, contains(tupleCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testZpopminCount() { - int count = 2; - - when(commandObjects.zpopmin("key", count)).thenReturn(listTupleCommandObject); - - Response> response = pipeliningBase.zpopmin("key", count); - - assertThat(commands, contains(listTupleCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testZcountDouble() { - when(commandObjects.zcount("key", 1.0, 2.0)).thenReturn(longCommandObject); - - Response response = pipeliningBase.zcount("key", 1.0, 2.0); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testZcountString() { - when(commandObjects.zcount("key", "1", "2")).thenReturn(longCommandObject); - - Response response = pipeliningBase.zcount("key", "1", "2"); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testZrangeByScoreDouble() { - when(commandObjects.zrangeByScore("key", 1.0, 2.0)).thenReturn(listStringCommandObject); - - Response> response = pipeliningBase.zrangeByScore("key", 1.0, 2.0); - - assertThat(commands, contains(listStringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testZrangeByScoreString() { - when(commandObjects.zrangeByScore("key", "1", "2")).thenReturn(listStringCommandObject); - - Response> response = pipeliningBase.zrangeByScore("key", "1", "2"); - - assertThat(commands, contains(listStringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testZrevrangeByScoreDouble() { - when(commandObjects.zrevrangeByScore("key", 2.0, 1.0)).thenReturn(listStringCommandObject); - - Response> response = pipeliningBase.zrevrangeByScore("key", 2.0, 1.0); - - assertThat(commands, contains(listStringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testZrangeByScoreDoubleWithLimit() { - when(commandObjects.zrangeByScore("key", 1.0, 2.0, 0, 1)).thenReturn(listStringCommandObject); - - Response> response = pipeliningBase.zrangeByScore("key", 1.0, 2.0, 0, 1); - - assertThat(commands, contains(listStringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testZrevrangeByScoreString() { - when(commandObjects.zrevrangeByScore("key", "2", "1")).thenReturn(listStringCommandObject); - - Response> response = pipeliningBase.zrevrangeByScore("key", "2", "1"); - - assertThat(commands, contains(listStringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testZrangeByScoreStringWithLimit() { - when(commandObjects.zrangeByScore("key", "1", "2", 0, 1)).thenReturn(listStringCommandObject); - - Response> response = pipeliningBase.zrangeByScore("key", "1", "2", 0, 1); - - assertThat(commands, contains(listStringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testZrevrangeByScoreDoubleWithLimit() { - when(commandObjects.zrevrangeByScore("key", 2.0, 1.0, 0, 1)).thenReturn(listStringCommandObject); - - Response> response = pipeliningBase.zrevrangeByScore("key", 2.0, 1.0, 0, 1); - - assertThat(commands, contains(listStringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testZrangeByScoreWithScores() { - when(commandObjects.zrangeByScoreWithScores("key", 1.0, 2.0)).thenReturn(listTupleCommandObject); - - Response> response = pipeliningBase.zrangeByScoreWithScores("key", 1.0, 2.0); - - assertThat(commands, contains(listTupleCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testZrevrangeByScoreWithScoresDouble() { - when(commandObjects.zrevrangeByScoreWithScores("key", 2.0, 1.0)).thenReturn(listTupleCommandObject); - - Response> response = pipeliningBase.zrevrangeByScoreWithScores("key", 2.0, 1.0); - - assertThat(commands, contains(listTupleCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testZrangeByScoreWithScoresDoubleWithLimit() { - when(commandObjects.zrangeByScoreWithScores("key", 1.0, 2.0, 0, 1)).thenReturn(listTupleCommandObject); - - Response> response = pipeliningBase.zrangeByScoreWithScores("key", 1.0, 2.0, 0, 1); - - assertThat(commands, contains(listTupleCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testZrevrangeByScoreStringWithLimit() { - when(commandObjects.zrevrangeByScore("key", "2", "1", 0, 1)).thenReturn(listStringCommandObject); - - Response> response = pipeliningBase.zrevrangeByScore("key", "2", "1", 0, 1); - - assertThat(commands, contains(listStringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testZrangeByScoreWithScoresString() { - when(commandObjects.zrangeByScoreWithScores("key", "1", "2")).thenReturn(listTupleCommandObject); - - Response> response = pipeliningBase.zrangeByScoreWithScores("key", "1", "2"); - - assertThat(commands, contains(listTupleCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testZrevrangeByScoreWithScoresString() { - when(commandObjects.zrevrangeByScoreWithScores("key", "2", "1")).thenReturn(listTupleCommandObject); - - Response> response = pipeliningBase.zrevrangeByScoreWithScores("key", "2", "1"); - - assertThat(commands, contains(listTupleCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testZrangeByScoreWithScoresStringWithLimit() { - when(commandObjects.zrangeByScoreWithScores("key", "1", "2", 0, 1)).thenReturn(listTupleCommandObject); - - Response> response = pipeliningBase.zrangeByScoreWithScores("key", "1", "2", 0, 1); - - assertThat(commands, contains(listTupleCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testZrevrangeByScoreWithScoresDoubleWithLimit() { - when(commandObjects.zrevrangeByScoreWithScores("key", 2.0, 1.0, 0, 1)).thenReturn(listTupleCommandObject); - - Response> response = pipeliningBase.zrevrangeByScoreWithScores("key", 2.0, 1.0, 0, 1); - - assertThat(commands, contains(listTupleCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testZrevrangeByScoreWithScoresStringWithLimit() { - when(commandObjects.zrevrangeByScoreWithScores("key", "2", "1", 0, 1)).thenReturn(listTupleCommandObject); - - Response> response = pipeliningBase.zrevrangeByScoreWithScores("key", "2", "1", 0, 1); - - assertThat(commands, contains(listTupleCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testZrangeZRangeParams() { - ZRangeParams zRangeParams = new ZRangeParams(1, 2); - - when(commandObjects.zrange("key", zRangeParams)).thenReturn(listStringCommandObject); - - Response> response = pipeliningBase.zrange("key", zRangeParams); - - assertThat(commands, contains(listStringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testZrangeWithScoresZRangeParams() { - ZRangeParams zRangeParams = new ZRangeParams(1, 2); - - when(commandObjects.zrangeWithScores("key", zRangeParams)).thenReturn(listTupleCommandObject); - - Response> response = pipeliningBase.zrangeWithScores("key", zRangeParams); - - assertThat(commands, contains(listTupleCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testZrangestore() { - ZRangeParams zRangeParams = new ZRangeParams(1, 2); - - when(commandObjects.zrangestore("dest", "src", zRangeParams)).thenReturn(longCommandObject); - - Response response = pipeliningBase.zrangestore("dest", "src", zRangeParams); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testZremrangeByRank() { - when(commandObjects.zremrangeByRank("key", 0, 1)).thenReturn(longCommandObject); - - Response response = pipeliningBase.zremrangeByRank("key", 0, 1); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testZremrangeByScoreDouble() { - when(commandObjects.zremrangeByScore("key", 1.0, 2.0)).thenReturn(longCommandObject); - - Response response = pipeliningBase.zremrangeByScore("key", 1.0, 2.0); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testZremrangeByScoreString() { - when(commandObjects.zremrangeByScore("key", "1", "2")).thenReturn(longCommandObject); - - Response response = pipeliningBase.zremrangeByScore("key", "1", "2"); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testZlexcount() { - when(commandObjects.zlexcount("key", "[a", "[z")).thenReturn(longCommandObject); - - Response response = pipeliningBase.zlexcount("key", "[a", "[z"); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testZrangeByLex() { - when(commandObjects.zrangeByLex("key", "[a", "[z")).thenReturn(listStringCommandObject); - - Response> response = pipeliningBase.zrangeByLex("key", "[a", "[z"); - - assertThat(commands, contains(listStringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testZrangeByLexWithLimit() { - when(commandObjects.zrangeByLex("key", "[a", "[z", 0, 10)).thenReturn(listStringCommandObject); - - Response> response = pipeliningBase.zrangeByLex("key", "[a", "[z", 0, 10); - - assertThat(commands, contains(listStringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testZrevrangeByLex() { - when(commandObjects.zrevrangeByLex("key", "[z", "[a")).thenReturn(listStringCommandObject); - - Response> response = pipeliningBase.zrevrangeByLex("key", "[z", "[a"); - - assertThat(commands, contains(listStringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testZrevrangeByLexWithLimit() { - when(commandObjects.zrevrangeByLex("key", "[z", "[a", 0, 10)).thenReturn(listStringCommandObject); - - Response> response = pipeliningBase.zrevrangeByLex("key", "[z", "[a", 0, 10); - - assertThat(commands, contains(listStringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testZremrangeByLex() { - when(commandObjects.zremrangeByLex("key", "[a", "[z")).thenReturn(longCommandObject); - - Response response = pipeliningBase.zremrangeByLex("key", "[a", "[z"); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testZscan() { - ScanParams params = new ScanParams(); - - when(commandObjects.zscan("key", "0", params)).thenReturn(scanResultTupleCommandObject); - - Response> response = pipeliningBase.zscan("key", "0", params); - - assertThat(commands, contains(scanResultTupleCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testBzpopmax() { - when(commandObjects.bzpopmax(1.0, "key1", "key2")).thenReturn(keyValueStringTupleCommandObject); - - Response> response = pipeliningBase.bzpopmax(1.0, "key1", "key2"); - - assertThat(commands, contains(keyValueStringTupleCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testBzpopmin() { - when(commandObjects.bzpopmin(1.0, "key1", "key2")).thenReturn(keyValueStringTupleCommandObject); - - Response> response = pipeliningBase.bzpopmin(1.0, "key1", "key2"); - - assertThat(commands, contains(keyValueStringTupleCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testZmpop() { - SortedSetOption option = SortedSetOption.MAX; - - when(commandObjects.zmpop(option, "key1", "key2")).thenReturn(keyValueStringListTupleCommandObject); - - Response>> response = pipeliningBase.zmpop(option, "key1", "key2"); - - assertThat(commands, contains(keyValueStringListTupleCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testZmpopWithCount() { - SortedSetOption option = SortedSetOption.MAX; - int count = 2; - - when(commandObjects.zmpop(option, count, "key1", "key2")).thenReturn(keyValueStringListTupleCommandObject); - - Response>> response = pipeliningBase.zmpop(option, count, "key1", "key2"); - - assertThat(commands, contains(keyValueStringListTupleCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testBzmpop() { - SortedSetOption option = SortedSetOption.MAX; - - when(commandObjects.bzmpop(1.0, option, "key1", "key2")).thenReturn(keyValueStringListTupleCommandObject); - - Response>> response = pipeliningBase.bzmpop(1.0, option, "key1", "key2"); - - assertThat(commands, contains(keyValueStringListTupleCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testBzmpopWithCount() { - SortedSetOption option = SortedSetOption.MAX; - int count = 2; - - when(commandObjects.bzmpop(1.0, option, count, "key1", "key2")).thenReturn(keyValueStringListTupleCommandObject); - - Response>> response = pipeliningBase.bzmpop(1.0, option, count, "key1", "key2"); - - assertThat(commands, contains(keyValueStringListTupleCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testZdiff() { - when(commandObjects.zdiff("key1", "key2")).thenReturn(listStringCommandObject); - - Response> response = pipeliningBase.zdiff("key1", "key2"); - - assertThat(commands, contains(listStringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testZdiffWithScores() { - when(commandObjects.zdiffWithScores("key1", "key2")).thenReturn(listTupleCommandObject); - - Response> response = pipeliningBase.zdiffWithScores("key1", "key2"); - - assertThat(commands, contains(listTupleCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testZdiffStore() { - when(commandObjects.zdiffStore("dstKey", "key1", "key2")).thenReturn(longCommandObject); - - Response response = pipeliningBase.zdiffStore("dstKey", "key1", "key2"); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testZdiffstore() { - when(commandObjects.zdiffstore("dstKey", "key1", "key2")).thenReturn(longCommandObject); - - Response response = pipeliningBase.zdiffstore("dstKey", "key1", "key2"); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testZinterstore() { - when(commandObjects.zinterstore("dstKey", "set1", "set2")).thenReturn(longCommandObject); - - Response response = pipeliningBase.zinterstore("dstKey", "set1", "set2"); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testZinterstoreWithParams() { - ZParams params = new ZParams(); - - when(commandObjects.zinterstore("dstKey", params, "set1", "set2")).thenReturn(longCommandObject); - - Response response = pipeliningBase.zinterstore("dstKey", params, "set1", "set2"); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testZinter() { - ZParams params = new ZParams(); - - when(commandObjects.zinter(params, "key1", "key2")).thenReturn(listStringCommandObject); - - Response> response = pipeliningBase.zinter(params, "key1", "key2"); - - assertThat(commands, contains(listStringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testZinterWithScores() { - ZParams params = new ZParams(); - - when(commandObjects.zinterWithScores(params, "key1", "key2")).thenReturn(listTupleCommandObject); - - Response> response = pipeliningBase.zinterWithScores(params, "key1", "key2"); - - assertThat(commands, contains(listTupleCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testZintercard() { - when(commandObjects.zintercard("key1", "key2")).thenReturn(longCommandObject); - - Response response = pipeliningBase.zintercard("key1", "key2"); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testZintercardWithLimit() { - long limit = 2; - - when(commandObjects.zintercard(limit, "key1", "key2")).thenReturn(longCommandObject); - - Response response = pipeliningBase.zintercard(limit, "key1", "key2"); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testZunion() { - ZParams params = new ZParams(); - - when(commandObjects.zunion(params, "key1", "key2")).thenReturn(listStringCommandObject); - - Response> response = pipeliningBase.zunion(params, "key1", "key2"); - - assertThat(commands, contains(listStringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testZunionWithScores() { - ZParams params = new ZParams(); - - when(commandObjects.zunionWithScores(params, "key1", "key2")).thenReturn(listTupleCommandObject); - - Response> response = pipeliningBase.zunionWithScores(params, "key1", "key2"); - - assertThat(commands, contains(listTupleCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testZunionstore() { - when(commandObjects.zunionstore("dstKey", "set1", "set2")).thenReturn(longCommandObject); - - Response response = pipeliningBase.zunionstore("dstKey", "set1", "set2"); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testZunionstoreWithParams() { - ZParams params = new ZParams(); - - when(commandObjects.zunionstore("dstKey", params, "set1", "set2")).thenReturn(longCommandObject); - - Response response = pipeliningBase.zunionstore("dstKey", params, "set1", "set2"); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testGeoaddSingle() { - when(commandObjects.geoadd("key", 13.361389, 38.115556, "member")).thenReturn(longCommandObject); - - Response response = pipeliningBase.geoadd("key", 13.361389, 38.115556, "member"); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testGeoaddMap() { - Map memberCoordinateMap = new HashMap<>(); - memberCoordinateMap.put("member", new GeoCoordinate(13.361389, 38.115556)); - - when(commandObjects.geoadd("key", memberCoordinateMap)).thenReturn(longCommandObject); - - Response response = pipeliningBase.geoadd("key", memberCoordinateMap); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testGeoaddMapWithParams() { - GeoAddParams params = new GeoAddParams(); - - Map memberCoordinateMap = new HashMap<>(); - memberCoordinateMap.put("member", new GeoCoordinate(13.361389, 38.115556)); - - when(commandObjects.geoadd("key", params, memberCoordinateMap)).thenReturn(longCommandObject); - - Response response = pipeliningBase.geoadd("key", params, memberCoordinateMap); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testGeodist() { - when(commandObjects.geodist("key", "member1", "member2")).thenReturn(doubleCommandObject); - - Response response = pipeliningBase.geodist("key", "member1", "member2"); - - assertThat(commands, contains(doubleCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testGeodistWithUnit() { - GeoUnit unit = GeoUnit.KM; - - when(commandObjects.geodist("key", "member1", "member2", unit)).thenReturn(doubleCommandObject); - - Response response = pipeliningBase.geodist("key", "member1", "member2", unit); - - assertThat(commands, contains(doubleCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testGeohash() { - when(commandObjects.geohash("key", "member1", "member2")).thenReturn(listStringCommandObject); - - Response> response = pipeliningBase.geohash("key", "member1", "member2"); - - assertThat(commands, contains(listStringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testGeopos() { - when(commandObjects.geopos("key", "member1", "member2")).thenReturn(listGeoCoordinateCommandObject); - - Response> response = pipeliningBase.geopos("key", "member1", "member2"); - - assertThat(commands, contains(listGeoCoordinateCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testGeoradius() { - when(commandObjects.georadius("key", 15.0, 37.0, 100.0, GeoUnit.KM)) - .thenReturn(listGeoRadiusResponseCommandObject); - - Response> response = - pipeliningBase.georadius("key", 15.0, 37.0, 100.0, GeoUnit.KM); - - assertThat(commands, contains(listGeoRadiusResponseCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testGeoradiusReadonly() { - when(commandObjects.georadiusReadonly("key", 15.0, 37.0, 100.0, GeoUnit.KM)) - .thenReturn(listGeoRadiusResponseCommandObject); - - Response> response = - pipeliningBase.georadiusReadonly("key", 15.0, 37.0, 100.0, GeoUnit.KM); - - assertThat(commands, contains(listGeoRadiusResponseCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testGeoradiusWithParam() { - GeoRadiusParam param = GeoRadiusParam.geoRadiusParam(); - - when(commandObjects.georadius("key", 15.0, 37.0, 100.0, GeoUnit.KM, param)) - .thenReturn(listGeoRadiusResponseCommandObject); - - Response> response = - pipeliningBase.georadius("key", 15.0, 37.0, 100.0, GeoUnit.KM, param); - - assertThat(commands, contains(listGeoRadiusResponseCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testGeoradiusReadonlyWithParam() { - GeoRadiusParam param = GeoRadiusParam.geoRadiusParam(); - - when(commandObjects.georadiusReadonly("key", 15.0, 37.0, 100.0, GeoUnit.KM, param)) - .thenReturn(listGeoRadiusResponseCommandObject); - - Response> response = - pipeliningBase.georadiusReadonly("key", 15.0, 37.0, 100.0, GeoUnit.KM, param); - - assertThat(commands, contains(listGeoRadiusResponseCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testGeoradiusByMember() { - when(commandObjects.georadiusByMember("key", "member", 100.0, GeoUnit.KM)) - .thenReturn(listGeoRadiusResponseCommandObject); - - Response> response = - pipeliningBase.georadiusByMember("key", "member", 100.0, GeoUnit.KM); - - assertThat(commands, contains(listGeoRadiusResponseCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testGeoradiusByMemberReadonly() { - when(commandObjects.georadiusByMemberReadonly("key", "member", 100.0, GeoUnit.KM)) - .thenReturn(listGeoRadiusResponseCommandObject); - - Response> response = - pipeliningBase.georadiusByMemberReadonly("key", "member", 100.0, GeoUnit.KM); - - assertThat(commands, contains(listGeoRadiusResponseCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testGeoradiusByMemberWithParam() { - GeoRadiusParam param = GeoRadiusParam.geoRadiusParam(); - - when(commandObjects.georadiusByMember("key", "member", 100.0, GeoUnit.KM, param)) - .thenReturn(listGeoRadiusResponseCommandObject); - - Response> response = pipeliningBase - .georadiusByMember("key", "member", 100.0, GeoUnit.KM, param); - - assertThat(commands, contains(listGeoRadiusResponseCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testGeoradiusByMemberReadonlyWithParam() { - GeoRadiusParam param = GeoRadiusParam.geoRadiusParam(); - - when(commandObjects.georadiusByMemberReadonly("key", "member", 100.0, GeoUnit.KM, param)) - .thenReturn(listGeoRadiusResponseCommandObject); - - Response> response = pipeliningBase - .georadiusByMemberReadonly("key", "member", 100.0, GeoUnit.KM, param); - - assertThat(commands, contains(listGeoRadiusResponseCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testGeoradiusStore() { - GeoRadiusParam param = GeoRadiusParam.geoRadiusParam(); - GeoRadiusStoreParam storeParam = GeoRadiusStoreParam.geoRadiusStoreParam().store("storeKey"); - - when(commandObjects.georadiusStore("key", 15.0, 37.0, 100.0, GeoUnit.KM, param, storeParam)) - .thenReturn(longCommandObject); - - Response response = pipeliningBase - .georadiusStore("key", 15.0, 37.0, 100.0, GeoUnit.KM, param, storeParam); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testGeoradiusByMemberStore() { - GeoRadiusParam param = GeoRadiusParam.geoRadiusParam(); - GeoRadiusStoreParam storeParam = GeoRadiusStoreParam.geoRadiusStoreParam().store("storeKey"); - - when(commandObjects.georadiusByMemberStore("key", "member", 100.0, GeoUnit.KM, param, storeParam)) - .thenReturn(longCommandObject); - - Response response = pipeliningBase - .georadiusByMemberStore("key", "member", 100.0, GeoUnit.KM, param, storeParam); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testGeosearchByMemberRadius() { - when(commandObjects.geosearch("key", "member", 100.0, GeoUnit.KM)) - .thenReturn(listGeoRadiusResponseCommandObject); - - Response> response = pipeliningBase - .geosearch("key", "member", 100.0, GeoUnit.KM); - - assertThat(commands, contains(listGeoRadiusResponseCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testGeosearchByCoordRadius() { - GeoCoordinate coord = new GeoCoordinate(15.0, 37.0); - - when(commandObjects.geosearch("key", coord, 100.0, GeoUnit.KM)) - .thenReturn(listGeoRadiusResponseCommandObject); - - Response> response = pipeliningBase.geosearch("key", coord, 100.0, GeoUnit.KM); - - assertThat(commands, contains(listGeoRadiusResponseCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testGeosearchByMemberBox() { - when(commandObjects.geosearch("key", "member", 50.0, 50.0, GeoUnit.KM)) - .thenReturn(listGeoRadiusResponseCommandObject); - - Response> response = pipeliningBase - .geosearch("key", "member", 50.0, 50.0, GeoUnit.KM); - - assertThat(commands, contains(listGeoRadiusResponseCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testGeosearchByCoordBox() { - GeoCoordinate coord = new GeoCoordinate(15.0, 37.0); - - when(commandObjects.geosearch("key", coord, 50.0, 50.0, GeoUnit.KM)) - .thenReturn(listGeoRadiusResponseCommandObject); - - Response> response = pipeliningBase - .geosearch("key", coord, 50.0, 50.0, GeoUnit.KM); - - assertThat(commands, contains(listGeoRadiusResponseCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testGeosearchWithParams() { - GeoSearchParam params = new GeoSearchParam(); - - when(commandObjects.geosearch("key", params)).thenReturn(listGeoRadiusResponseCommandObject); - - Response> response = pipeliningBase.geosearch("key", params); - - assertThat(commands, contains(listGeoRadiusResponseCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testGeosearchStoreByMemberRadius() { - when(commandObjects.geosearchStore("dest", "src", "member", 100.0, GeoUnit.KM)) - .thenReturn(longCommandObject); - - Response response = pipeliningBase - .geosearchStore("dest", "src", "member", 100.0, GeoUnit.KM); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testGeosearchStoreByCoordRadius() { - GeoCoordinate coord = new GeoCoordinate(15.0, 37.0); - - when(commandObjects.geosearchStore("dest", "src", coord, 100.0, GeoUnit.KM)) - .thenReturn(longCommandObject); - - Response response = pipeliningBase.geosearchStore("dest", "src", coord, 100.0, GeoUnit.KM); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testGeosearchStoreByMemberBox() { - when(commandObjects.geosearchStore("dest", "src", "member", 50.0, 50.0, GeoUnit.KM)) - .thenReturn(longCommandObject); - - Response response = pipeliningBase - .geosearchStore("dest", "src", "member", 50.0, 50.0, GeoUnit.KM); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testGeosearchStoreByCoordBox() { - GeoCoordinate coord = new GeoCoordinate(15.0, 37.0); - - when(commandObjects.geosearchStore("dest", "src", coord, 50.0, 50.0, GeoUnit.KM)) - .thenReturn(longCommandObject); - - Response response = pipeliningBase - .geosearchStore("dest", "src", coord, 50.0, 50.0, GeoUnit.KM); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testGeosearchStoreWithParams() { - GeoSearchParam params = new GeoSearchParam(); - - when(commandObjects.geosearchStore("dest", "src", params)).thenReturn(longCommandObject); - - Response response = pipeliningBase.geosearchStore("dest", "src", params); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testGeosearchStoreStoreDist() { - GeoSearchParam params = new GeoSearchParam(); - - when(commandObjects.geosearchStoreStoreDist("dest", "src", params)).thenReturn(longCommandObject); - - Response response = pipeliningBase.geosearchStoreStoreDist("dest", "src", params); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testPfadd() { - when(commandObjects.pfadd("key", "element1", "element2")).thenReturn(longCommandObject); - - Response response = pipeliningBase.pfadd("key", "element1", "element2"); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testPfmerge() { - when(commandObjects.pfmerge("destkey", "sourcekey1", "sourcekey2")).thenReturn(stringCommandObject); - - Response response = pipeliningBase.pfmerge("destkey", "sourcekey1", "sourcekey2"); - - assertThat(commands, contains(stringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testPfcountSingleKey() { - when(commandObjects.pfcount("key")).thenReturn(longCommandObject); - - Response response = pipeliningBase.pfcount("key"); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testPfcountMultipleKeys() { - when(commandObjects.pfcount("key1", "key2")).thenReturn(longCommandObject); - - Response response = pipeliningBase.pfcount("key1", "key2"); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testXadd() { - StreamEntryID id = new StreamEntryID(); - - Map hash = new HashMap<>(); - hash.put("field1", "value1"); - - when(commandObjects.xadd("key", id, hash)).thenReturn(streamEntryIdCommandObject); - - Response response = pipeliningBase.xadd("key", id, hash); - - assertThat(commands, contains(streamEntryIdCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testXaddWithParams() { - XAddParams params = new XAddParams(); - - Map hash = new HashMap<>(); - hash.put("field1", "value1"); - - when(commandObjects.xadd("key", params, hash)).thenReturn(streamEntryIdCommandObject); - - Response response = pipeliningBase.xadd("key", params, hash); - - assertThat(commands, contains(streamEntryIdCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testXlen() { - when(commandObjects.xlen("key")).thenReturn(longCommandObject); - - Response response = pipeliningBase.xlen("key"); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testXrange() { - StreamEntryID start = new StreamEntryID("0-0"); - StreamEntryID end = new StreamEntryID("9999999999999-0"); - - when(commandObjects.xrange("key", start, end)).thenReturn(listStreamEntryCommandObject); - - Response> response = pipeliningBase.xrange("key", start, end); - - assertThat(commands, contains(listStreamEntryCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testXrangeWithCount() { - StreamEntryID start = new StreamEntryID("0-0"); - StreamEntryID end = new StreamEntryID("9999999999999-0"); - int count = 10; - - when(commandObjects.xrange("key", start, end, count)).thenReturn(listStreamEntryCommandObject); - - Response> response = pipeliningBase.xrange("key", start, end, count); - - assertThat(commands, contains(listStreamEntryCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testXrevrange() { - StreamEntryID end = new StreamEntryID("9999999999999-0"); - StreamEntryID start = new StreamEntryID("0-0"); - - when(commandObjects.xrevrange("key", end, start)).thenReturn(listStreamEntryCommandObject); - - Response> response = pipeliningBase.xrevrange("key", end, start); - - assertThat(commands, contains(listStreamEntryCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testXrevrangeWithCount() { - StreamEntryID end = new StreamEntryID("9999999999999-0"); - StreamEntryID start = new StreamEntryID("0-0"); - int count = 10; - - when(commandObjects.xrevrange("key", end, start, count)).thenReturn(listStreamEntryCommandObject); - - Response> response = pipeliningBase.xrevrange("key", end, start, count); - - assertThat(commands, contains(listStreamEntryCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testXrangeWithStringIDs() { - String start = "-"; - String end = "+"; - - when(commandObjects.xrange("key", start, end)).thenReturn(listStreamEntryCommandObject); - - Response> response = pipeliningBase.xrange("key", start, end); - - assertThat(commands, contains(listStreamEntryCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testXrangeWithStringIDsAndCount() { - String start = "-"; - String end = "+"; - int count = 10; - - when(commandObjects.xrange("key", start, end, count)).thenReturn(listStreamEntryCommandObject); - - Response> response = pipeliningBase.xrange("key", start, end, count); - - assertThat(commands, contains(listStreamEntryCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testXrevrangeWithStringIDs() { - String end = "+"; - String start = "-"; - - when(commandObjects.xrevrange("key", end, start)).thenReturn(listStreamEntryCommandObject); - - Response> response = pipeliningBase.xrevrange("key", end, start); - - assertThat(commands, contains(listStreamEntryCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testXrevrangeWithStringIDsAndCount() { - String end = "+"; - String start = "-"; - int count = 10; - - when(commandObjects.xrevrange("key", end, start, count)).thenReturn(listStreamEntryCommandObject); - - Response> response = pipeliningBase.xrevrange("key", end, start, count); - - assertThat(commands, contains(listStreamEntryCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testXack() { - StreamEntryID[] ids = { new StreamEntryID("1526999352406-0"), new StreamEntryID("1526999352406-1") }; - - when(commandObjects.xack("key", "group", ids)).thenReturn(longCommandObject); - - Response response = pipeliningBase.xack("key", "group", ids); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testXgroupCreate() { - StreamEntryID id = new StreamEntryID("0-0"); - - when(commandObjects.xgroupCreate("key", "groupName", id, true)).thenReturn(stringCommandObject); - - Response response = pipeliningBase.xgroupCreate("key", "groupName", id, true); - - assertThat(commands, contains(stringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testXgroupSetID() { - StreamEntryID id = new StreamEntryID("0-0"); - - when(commandObjects.xgroupSetID("key", "groupName", id)).thenReturn(stringCommandObject); - - Response response = pipeliningBase.xgroupSetID("key", "groupName", id); - - assertThat(commands, contains(stringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testXgroupDestroy() { - when(commandObjects.xgroupDestroy("key", "groupName")).thenReturn(longCommandObject); - - Response response = pipeliningBase.xgroupDestroy("key", "groupName"); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testXgroupCreateConsumer() { - when(commandObjects.xgroupCreateConsumer("key", "groupName", "consumerName")) - .thenReturn(booleanCommandObject); - - Response response = pipeliningBase.xgroupCreateConsumer("key", "groupName", "consumerName"); - - assertThat(commands, contains(booleanCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testXgroupDelConsumer() { - when(commandObjects.xgroupDelConsumer("key", "groupName", "consumerName")) - .thenReturn(longCommandObject); - - Response response = pipeliningBase.xgroupDelConsumer("key", "groupName", "consumerName"); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testXpendingSummary() { - when(commandObjects.xpending("key", "groupName")).thenReturn(streamPendingSummaryCommandObject); - - Response response = pipeliningBase.xpending("key", "groupName"); - - assertThat(commands, contains(streamPendingSummaryCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testXpendingRange() { - XPendingParams params = new XPendingParams(); - - when(commandObjects.xpending("key", "groupName", params)).thenReturn(listStreamPendingEntryCommandObject); - - Response> response = pipeliningBase.xpending("key", "groupName", params); - - assertThat(commands, contains(listStreamPendingEntryCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testXdel() { - StreamEntryID[] ids = { new StreamEntryID("1526999352406-0"), new StreamEntryID("1526999352406-1") }; - - when(commandObjects.xdel("key", ids)).thenReturn(longCommandObject); - - Response response = pipeliningBase.xdel("key", ids); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testXtrim() { - when(commandObjects.xtrim("key", 1000L, true)).thenReturn(longCommandObject); - - Response response = pipeliningBase.xtrim("key", 1000L, true); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testXtrimWithParams() { - XTrimParams params = new XTrimParams().maxLen(1000L); - when(commandObjects.xtrim("key", params)).thenReturn(longCommandObject); - - Response response = pipeliningBase.xtrim("key", params); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testXclaim() { - StreamEntryID[] ids = { new StreamEntryID("1526999352406-0"), new StreamEntryID("1526999352406-1") }; - XClaimParams params = new XClaimParams().idle(10000L); - - when(commandObjects.xclaim("key", "group", "consumerName", 10000L, params, ids)) - .thenReturn(listStreamEntryCommandObject); - - Response> response = pipeliningBase - .xclaim("key", "group", "consumerName", 10000L, params, ids); - - assertThat(commands, contains(listStreamEntryCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testXclaimJustId() { - StreamEntryID[] ids = { new StreamEntryID("1526999352406-0"), new StreamEntryID("1526999352406-1") }; - XClaimParams params = new XClaimParams().idle(10000L); - - when(commandObjects.xclaimJustId("key", "group", "consumerName", 10000L, params, ids)) - .thenReturn(listStreamEntryIdCommandObject); - - Response> response = pipeliningBase - .xclaimJustId("key", "group", "consumerName", 10000L, params, ids); - - assertThat(commands, contains(listStreamEntryIdCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testXautoclaim() { - StreamEntryID start = new StreamEntryID("0-0"); - XAutoClaimParams params = new XAutoClaimParams(); - - when(commandObjects.xautoclaim("key", "group", "consumerName", 10000L, start, params)) - .thenReturn(entryStreamEntryIdListStreamEntryCommandObject); - - Response>> response = pipeliningBase - .xautoclaim("key", "group", "consumerName", 10000L, start, params); - - assertThat(commands, contains(entryStreamEntryIdListStreamEntryCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testXautoclaimJustId() { - StreamEntryID start = new StreamEntryID("0-0"); - XAutoClaimParams params = new XAutoClaimParams(); - - when(commandObjects.xautoclaimJustId("key", "group", "consumerName", 10000L, start, params)) - .thenReturn(entryStreamEntryIdListStreamEntryIdCommandObject); - - Response>> response = pipeliningBase - .xautoclaimJustId("key", "group", "consumerName", 10000L, start, params); - - assertThat(commands, contains(entryStreamEntryIdListStreamEntryIdCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testXinfoStream() { - when(commandObjects.xinfoStream("key")).thenReturn(streamInfoCommandObject); - - Response response = pipeliningBase.xinfoStream("key"); - - assertThat(commands, contains(streamInfoCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testXinfoStreamFull() { - when(commandObjects.xinfoStreamFull("key")).thenReturn(streamFullInfoCommandObject); - - Response response = pipeliningBase.xinfoStreamFull("key"); - - assertThat(commands, contains(streamFullInfoCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testXinfoStreamFullWithCount() { - int count = 10; - when(commandObjects.xinfoStreamFull("key", count)).thenReturn(streamFullInfoCommandObject); - - Response response = pipeliningBase.xinfoStreamFull("key", count); - - assertThat(commands, contains(streamFullInfoCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testXinfoGroups() { - when(commandObjects.xinfoGroups("key")).thenReturn(listStreamGroupInfoCommandObject); - - Response> response = pipeliningBase.xinfoGroups("key"); - - assertThat(commands, contains(listStreamGroupInfoCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testXinfoConsumers() { - when(commandObjects.xinfoConsumers("key", "group")).thenReturn(listStreamConsumersInfoCommandObject); - - Response> response = pipeliningBase.xinfoConsumers("key", "group"); - - assertThat(commands, contains(listStreamConsumersInfoCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testXinfoConsumers2() { - when(commandObjects.xinfoConsumers2("key", "group")).thenReturn(listStreamConsumerInfoCommandObject); - - Response> response = pipeliningBase.xinfoConsumers2("key", "group"); - - assertThat(commands, contains(listStreamConsumerInfoCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testXread() { - XReadParams xReadParams = new XReadParams(); - - Map streams = new HashMap<>(); - streams.put("key1", new StreamEntryID("0-0")); - streams.put("key2", new StreamEntryID("0-0")); - - when(commandObjects.xread(xReadParams, streams)).thenReturn(listEntryStringListStreamEntryCommandObject); - - Response>>> response = pipeliningBase.xread(xReadParams, streams); - - assertThat(commands, contains(listEntryStringListStreamEntryCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testXreadGroup() { - XReadGroupParams xReadGroupParams = new XReadGroupParams(); - - Map streams = new HashMap<>(); - streams.put("stream1", new StreamEntryID("0-0")); - - when(commandObjects.xreadGroup("groupName", "consumer", xReadGroupParams, streams)) - .thenReturn(listEntryStringListStreamEntryCommandObject); - - Response>>> response = pipeliningBase - .xreadGroup("groupName", "consumer", xReadGroupParams, streams); - - assertThat(commands, contains(listEntryStringListStreamEntryCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testEval() { - String script = "return 'Hello, world!'"; - when(commandObjects.eval(script)).thenReturn(objectCommandObject); - - Response response = pipeliningBase.eval(script); - - assertThat(commands, contains(objectCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testEvalWithKeysAndParams() { - String script = "return KEYS[1] .. ARGV[1]"; - int keyCount = 1; - - when(commandObjects.eval(script, keyCount, "key", "arg")).thenReturn(objectCommandObject); - - Response response = pipeliningBase.eval(script, keyCount, "key", "arg"); - - assertThat(commands, contains(objectCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testEvalWithLists() { - String script = "return KEYS[1] .. ARGV[1]"; - List keys = Collections.singletonList("key"); - List args = Collections.singletonList("arg"); - - when(commandObjects.eval(script, keys, args)).thenReturn(objectCommandObject); - - Response response = pipeliningBase.eval(script, keys, args); - - assertThat(commands, contains(objectCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testEvalReadonlyWithLists() { - String script = "return KEYS[1] .. ARGV[1]"; - List keys = Collections.singletonList("key"); - List args = Collections.singletonList("arg"); - - when(commandObjects.evalReadonly(script, keys, args)).thenReturn(objectCommandObject); - - Response response = pipeliningBase.evalReadonly(script, keys, args); - - assertThat(commands, contains(objectCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testEvalsha() { - String sha1 = "somehash"; - - when(commandObjects.evalsha(sha1)).thenReturn(objectCommandObject); - - Response response = pipeliningBase.evalsha(sha1); - - assertThat(commands, contains(objectCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testEvalshaWithKeysAndParams() { - String sha1 = "somehash"; - int keyCount = 1; - - when(commandObjects.evalsha(sha1, keyCount, "key", "arg")).thenReturn(objectCommandObject); - - Response response = pipeliningBase.evalsha(sha1, keyCount, "key", "arg"); - - assertThat(commands, contains(objectCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testEvalshaWithLists() { - String sha1 = "somehash"; - List keys = Collections.singletonList("key"); - List args = Collections.singletonList("arg"); - - when(commandObjects.evalsha(sha1, keys, args)).thenReturn(objectCommandObject); - - Response response = pipeliningBase.evalsha(sha1, keys, args); - - assertThat(commands, contains(objectCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testEvalshaReadonlyWithLists() { - String sha1 = "somehash"; - List keys = Collections.singletonList("key"); - List args = Collections.singletonList("arg"); - - when(commandObjects.evalshaReadonly(sha1, keys, args)).thenReturn(objectCommandObject); - - Response response = pipeliningBase.evalshaReadonly(sha1, keys, args); - - assertThat(commands, contains(objectCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testWaitReplicas() { - int replicas = 2; - long timeout = 1000L; - - when(commandObjects.waitReplicas("key", replicas, timeout)).thenReturn(longCommandObject); - - Response response = pipeliningBase.waitReplicas("key", replicas, timeout); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testWaitAOF() { - long numLocal = 1L; - long numReplicas = 1L; - long timeout = 1000L; - - when(commandObjects.waitAOF("key", numLocal, numReplicas, timeout)).thenReturn(keyValueLongLongCommandObject); - - Response> response = pipeliningBase.waitAOF("key", numLocal, numReplicas, timeout); - - assertThat(commands, contains(keyValueLongLongCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testEvalWithSampleKey() { - String script = "return 'Hello, world!'"; - - when(commandObjects.eval(script, "key")).thenReturn(objectCommandObject); - - Response response = pipeliningBase.eval(script, "key"); - - assertThat(commands, contains(objectCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testEvalshaWithSampleKey() { - String sha1 = "somehash"; - - when(commandObjects.evalsha(sha1, "key")).thenReturn(objectCommandObject); - - Response response = pipeliningBase.evalsha(sha1, "key"); - - assertThat(commands, contains(objectCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testScriptExists() { - String[] sha1 = { "somehash1", "somehash2" }; - - when(commandObjects.scriptExists("key", sha1)).thenReturn(listBooleanCommandObject); - - Response> response = pipeliningBase.scriptExists("key", sha1); - - assertThat(commands, contains(listBooleanCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testScriptLoad() { - String script = "return 'Hello, world!'"; - - when(commandObjects.scriptLoad(script, "key")).thenReturn(stringCommandObject); - - Response response = pipeliningBase.scriptLoad(script, "key"); - - assertThat(commands, contains(stringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testScriptFlush() { - when(commandObjects.scriptFlush("key")).thenReturn(stringCommandObject); - - Response response = pipeliningBase.scriptFlush("key"); - - assertThat(commands, contains(stringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testScriptFlushWithFlushMode() { - FlushMode flushMode = FlushMode.SYNC; - - when(commandObjects.scriptFlush("key", flushMode)).thenReturn(stringCommandObject); - - Response response = pipeliningBase.scriptFlush("key", flushMode); - - assertThat(commands, contains(stringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testScriptKill() { - when(commandObjects.scriptKill("key")).thenReturn(stringCommandObject); - - Response response = pipeliningBase.scriptKill("key"); - - assertThat(commands, contains(stringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testFcallBytes() { - byte[] name = "functionName".getBytes(); - List keys = Collections.singletonList("key".getBytes()); - List args = Collections.singletonList("arg".getBytes()); - - when(commandObjects.fcall(name, keys, args)).thenReturn(objectCommandObject); - - Response response = pipeliningBase.fcall(name, keys, args); - - assertThat(commands, contains(objectCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testFcallStrings() { - String name = "functionName"; - List keys = Collections.singletonList("key"); - List args = Collections.singletonList("arg"); - - when(commandObjects.fcall(name, keys, args)).thenReturn(objectCommandObject); - - Response response = pipeliningBase.fcall(name, keys, args); - - assertThat(commands, contains(objectCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testFcallReadonlyBytes() { - byte[] name = "functionName".getBytes(); - List keys = Collections.singletonList("key".getBytes()); - List args = Collections.singletonList("arg".getBytes()); - - when(commandObjects.fcallReadonly(name, keys, args)).thenReturn(objectCommandObject); - - Response response = pipeliningBase.fcallReadonly(name, keys, args); - - assertThat(commands, contains(objectCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testFcallReadonlyStrings() { - String name = "functionName"; - List keys = Collections.singletonList("key"); - List args = Collections.singletonList("arg"); - - when(commandObjects.fcallReadonly(name, keys, args)).thenReturn(objectCommandObject); - - Response response = pipeliningBase.fcallReadonly(name, keys, args); - - assertThat(commands, contains(objectCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testFunctionDeleteBytes() { - byte[] libraryName = "libraryName".getBytes(); - - when(commandObjects.functionDelete(libraryName)).thenReturn(stringCommandObject); - - Response response = pipeliningBase.functionDelete(libraryName); - - assertThat(commands, contains(stringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testFunctionDeleteStrings() { - String libraryName = "libraryName"; - - when(commandObjects.functionDelete(libraryName)).thenReturn(stringCommandObject); - - Response response = pipeliningBase.functionDelete(libraryName); - - assertThat(commands, contains(stringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testFunctionDump() { - when(commandObjects.functionDump()).thenReturn(bytesCommandObject); - - Response response = pipeliningBase.functionDump(); - - assertThat(commands, contains(bytesCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testFunctionListWithPattern() { - String libraryNamePattern = "lib*"; - - when(commandObjects.functionList(libraryNamePattern)).thenReturn(listLibraryInfoCommandObject); - - Response> response = pipeliningBase.functionList(libraryNamePattern); - - assertThat(commands, contains(listLibraryInfoCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testFunctionList() { - when(commandObjects.functionList()).thenReturn(listLibraryInfoCommandObject); - - Response> response = pipeliningBase.functionList(); - - assertThat(commands, contains(listLibraryInfoCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testFunctionListWithCodeWithPattern() { - String libraryNamePattern = "lib*"; - - when(commandObjects.functionListWithCode(libraryNamePattern)).thenReturn(listLibraryInfoCommandObject); - - Response> response = pipeliningBase.functionListWithCode(libraryNamePattern); - - assertThat(commands, contains(listLibraryInfoCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testFunctionListWithCode() { - when(commandObjects.functionListWithCode()).thenReturn(listLibraryInfoCommandObject); - - Response> response = pipeliningBase.functionListWithCode(); - - assertThat(commands, contains(listLibraryInfoCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testFunctionListByteArray() { - when(commandObjects.functionListBinary()).thenReturn(listObjectCommandObject); - - Response> response = pipeliningBase.functionListBinary(); - - assertThat(commands, contains(listObjectCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testFunctionListBytes() { - byte[] libraryNamePattern = "lib*".getBytes(); - - when(commandObjects.functionList(libraryNamePattern)).thenReturn(listObjectCommandObject); - - Response> response = pipeliningBase.functionList(libraryNamePattern); - - assertThat(commands, contains(listObjectCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testFunctionListWithCodeByteArray() { - when(commandObjects.functionListWithCodeBinary()).thenReturn(listObjectCommandObject); - - Response> response = pipeliningBase.functionListWithCodeBinary(); - - assertThat(commands, contains(listObjectCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testFunctionListWithCodeBytes() { - byte[] libraryNamePattern = "lib*".getBytes(); - - when(commandObjects.functionListWithCode(libraryNamePattern)).thenReturn(listObjectCommandObject); - - Response> response = pipeliningBase.functionListWithCode(libraryNamePattern); - - assertThat(commands, contains(listObjectCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testFunctionLoadBytes() { - byte[] functionCode = "return 'Hello, world!'".getBytes(); - - when(commandObjects.functionLoad(functionCode)).thenReturn(stringCommandObject); - - Response response = pipeliningBase.functionLoad(functionCode); - - assertThat(commands, contains(stringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testFunctionLoadStrings() { - String functionCode = "return 'Hello, world!'"; - - when(commandObjects.functionLoad(functionCode)).thenReturn(stringCommandObject); - - Response response = pipeliningBase.functionLoad(functionCode); - - assertThat(commands, contains(stringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testFunctionLoadReplaceBytes() { - byte[] functionCode = "return 'Hello, world!'".getBytes(); - - when(commandObjects.functionLoadReplace(functionCode)).thenReturn(stringCommandObject); - - Response response = pipeliningBase.functionLoadReplace(functionCode); - - assertThat(commands, contains(stringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testFunctionLoadReplaceStrings() { - String functionCode = "return 'Hello, world!'"; - - when(commandObjects.functionLoadReplace(functionCode)).thenReturn(stringCommandObject); - - Response response = pipeliningBase.functionLoadReplace(functionCode); - - assertThat(commands, contains(stringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testFunctionRestoreBytes() { - byte[] serializedValue = "serialized".getBytes(); - - when(commandObjects.functionRestore(serializedValue)).thenReturn(stringCommandObject); - - Response response = pipeliningBase.functionRestore(serializedValue); - - assertThat(commands, contains(stringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testFunctionRestoreBytesWithPolicy() { - byte[] serializedValue = "serialized".getBytes(); - FunctionRestorePolicy policy = FunctionRestorePolicy.FLUSH; - - when(commandObjects.functionRestore(serializedValue, policy)).thenReturn(stringCommandObject); - - Response response = pipeliningBase.functionRestore(serializedValue, policy); - - assertThat(commands, contains(stringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testFunctionFlush() { - when(commandObjects.functionFlush()).thenReturn(stringCommandObject); - - Response response = pipeliningBase.functionFlush(); - - assertThat(commands, contains(stringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testFunctionFlushWithMode() { - FlushMode mode = FlushMode.SYNC; - - when(commandObjects.functionFlush(mode)).thenReturn(stringCommandObject); - - Response response = pipeliningBase.functionFlush(mode); - - assertThat(commands, contains(stringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testFunctionKill() { - when(commandObjects.functionKill()).thenReturn(stringCommandObject); - - Response response = pipeliningBase.functionKill(); - - assertThat(commands, contains(stringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testFunctionStats() { - when(commandObjects.functionStats()).thenReturn(functionStatsCommandObject); - - Response response = pipeliningBase.functionStats(); - - assertThat(commands, contains(functionStatsCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testFunctionStatsByteArray() { - when(commandObjects.functionStatsBinary()).thenReturn(objectCommandObject); - - Response response = pipeliningBase.functionStatsBinary(); - - assertThat(commands, contains(objectCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testGeoaddSingleMember() { - byte[] key = "location".getBytes(); - double longitude = 13.361389; - double latitude = 38.115556; - byte[] member = "Sicily".getBytes(); - - when(commandObjects.geoadd(key, longitude, latitude, member)).thenReturn(longCommandObject); - - Response response = pipeliningBase.geoadd(key, longitude, latitude, member); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testGeoaddMemberCoordinateMap() { - byte[] key = "location".getBytes(); - - Map memberCoordinateMap = new HashMap<>(); - memberCoordinateMap.put("Palermo".getBytes(), new GeoCoordinate(13.361389, 38.115556)); - - when(commandObjects.geoadd(key, memberCoordinateMap)).thenReturn(longCommandObject); - - Response response = pipeliningBase.geoadd(key, memberCoordinateMap); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testGeoaddWithParams() { - byte[] key = "location".getBytes(); - GeoAddParams params = GeoAddParams.geoAddParams(); - - Map memberCoordinateMap = new HashMap<>(); - memberCoordinateMap.put("Palermo".getBytes(), new GeoCoordinate(13.361389, 38.115556)); - - when(commandObjects.geoadd(key, params, memberCoordinateMap)).thenReturn(longCommandObject); - - Response response = pipeliningBase.geoadd(key, params, memberCoordinateMap); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testGeodistByteArray() { - byte[] key = "location".getBytes(); - byte[] member1 = "Palermo".getBytes(); - byte[] member2 = "Catania".getBytes(); - - when(commandObjects.geodist(key, member1, member2)).thenReturn(doubleCommandObject); - - Response response = pipeliningBase.geodist(key, member1, member2); - - assertThat(commands, contains(doubleCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testGeodistWithUnitByteArray() { - byte[] key = "location".getBytes(); - byte[] member1 = "Palermo".getBytes(); - byte[] member2 = "Catania".getBytes(); - GeoUnit unit = GeoUnit.KM; - - when(commandObjects.geodist(key, member1, member2, unit)).thenReturn(doubleCommandObject); - - Response response = pipeliningBase.geodist(key, member1, member2, unit); - - assertThat(commands, contains(doubleCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testGeohashByteArray() { - byte[] key = "location".getBytes(); - byte[] member = "Palermo".getBytes(); - - when(commandObjects.geohash(key, member)).thenReturn(listBytesCommandObject); - - Response> response = pipeliningBase.geohash(key, member); - - assertThat(commands, contains(listBytesCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testGeoposByteArray() { - byte[] key = "location".getBytes(); - byte[] member = "Palermo".getBytes(); - - when(commandObjects.geopos(key, member)).thenReturn(listGeoCoordinateCommandObject); - - Response> response = pipeliningBase.geopos(key, member); - - assertThat(commands, contains(listGeoCoordinateCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testGeoradiusByteArray() { - byte[] key = "location".getBytes(); - double longitude = 13.361389; - double latitude = 38.115556; - double radius = 100; - GeoUnit unit = GeoUnit.KM; - - when(commandObjects.georadius(key, longitude, latitude, radius, unit)).thenReturn(listGeoRadiusResponseCommandObject); - - Response> response = pipeliningBase.georadius(key, longitude, latitude, radius, unit); - - assertThat(commands, contains(listGeoRadiusResponseCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testGeoradiusReadonlyByteArray() { - byte[] key = "location".getBytes(); - double longitude = 13.361389; - double latitude = 38.115556; - double radius = 100; - GeoUnit unit = GeoUnit.KM; - - when(commandObjects.georadiusReadonly(key, longitude, latitude, radius, unit)).thenReturn(listGeoRadiusResponseCommandObject); - - Response> response = pipeliningBase.georadiusReadonly(key, longitude, latitude, radius, unit); - - assertThat(commands, contains(listGeoRadiusResponseCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testGeoradiusWithParamByteArray() { - byte[] key = "location".getBytes(); - double longitude = 13.361389; - double latitude = 38.115556; - double radius = 100; - GeoUnit unit = GeoUnit.KM; - GeoRadiusParam param = GeoRadiusParam.geoRadiusParam(); - - when(commandObjects.georadius(key, longitude, latitude, radius, unit, param)).thenReturn(listGeoRadiusResponseCommandObject); - - Response> response = pipeliningBase.georadius(key, longitude, latitude, radius, unit, param); - - assertThat(commands, contains(listGeoRadiusResponseCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testGeoradiusReadonlyWithParamByteArray() { - byte[] key = "location".getBytes(); - double longitude = 13.361389; - double latitude = 38.115556; - double radius = 100; - GeoUnit unit = GeoUnit.KM; - GeoRadiusParam param = GeoRadiusParam.geoRadiusParam(); - - when(commandObjects.georadiusReadonly(key, longitude, latitude, radius, unit, param)).thenReturn(listGeoRadiusResponseCommandObject); - - Response> response = pipeliningBase.georadiusReadonly(key, longitude, latitude, radius, unit, param); - - assertThat(commands, contains(listGeoRadiusResponseCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testGeoradiusByMemberByteArray() { - byte[] key = "location".getBytes(); - byte[] member = "Palermo".getBytes(); - double radius = 100; - GeoUnit unit = GeoUnit.KM; - - when(commandObjects.georadiusByMember(key, member, radius, unit)).thenReturn(listGeoRadiusResponseCommandObject); - - Response> response = pipeliningBase.georadiusByMember(key, member, radius, unit); - - assertThat(commands, contains(listGeoRadiusResponseCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testGeoradiusByMemberReadonlyByteArray() { - byte[] key = "location".getBytes(); - byte[] member = "Palermo".getBytes(); - double radius = 100; - GeoUnit unit = GeoUnit.KM; - - when(commandObjects.georadiusByMemberReadonly(key, member, radius, unit)).thenReturn(listGeoRadiusResponseCommandObject); - - Response> response = pipeliningBase.georadiusByMemberReadonly(key, member, radius, unit); - - assertThat(commands, contains(listGeoRadiusResponseCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testGeoradiusByMemberWithParamByteArray() { - byte[] key = "location".getBytes(); - byte[] member = "Palermo".getBytes(); - double radius = 100; - GeoUnit unit = GeoUnit.KM; - GeoRadiusParam param = GeoRadiusParam.geoRadiusParam(); - - when(commandObjects.georadiusByMember(key, member, radius, unit, param)).thenReturn(listGeoRadiusResponseCommandObject); - - Response> response = pipeliningBase.georadiusByMember(key, member, radius, unit, param); - - assertThat(commands, contains(listGeoRadiusResponseCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testGeoradiusByMemberReadonlyWithParamByteArray() { - byte[] key = "location".getBytes(); - byte[] member = "Palermo".getBytes(); - double radius = 100; - GeoUnit unit = GeoUnit.KM; - GeoRadiusParam param = GeoRadiusParam.geoRadiusParam(); - - when(commandObjects.georadiusByMemberReadonly(key, member, radius, unit, param)).thenReturn(listGeoRadiusResponseCommandObject); - - Response> response = pipeliningBase.georadiusByMemberReadonly(key, member, radius, unit, param); - - assertThat(commands, contains(listGeoRadiusResponseCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testGeoradiusStoreByteArray() { - byte[] key = "location".getBytes(); - double longitude = 13.361389; - double latitude = 38.115556; - double radius = 100; - GeoUnit unit = GeoUnit.KM; - GeoRadiusParam param = GeoRadiusParam.geoRadiusParam(); - GeoRadiusStoreParam storeParam = GeoRadiusStoreParam.geoRadiusStoreParam().store("storeKey"); - - when(commandObjects.georadiusStore(key, longitude, latitude, radius, unit, param, storeParam)).thenReturn(longCommandObject); - - Response response = pipeliningBase.georadiusStore(key, longitude, latitude, radius, unit, param, storeParam); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testGeoradiusByMemberStoreByteArray() { - byte[] key = "location".getBytes(); - byte[] member = "Palermo".getBytes(); - double radius = 100; - GeoUnit unit = GeoUnit.KM; - GeoRadiusParam param = GeoRadiusParam.geoRadiusParam(); - GeoRadiusStoreParam storeParam = GeoRadiusStoreParam.geoRadiusStoreParam().store("storeKey"); - - when(commandObjects.georadiusByMemberStore(key, member, radius, unit, param, storeParam)).thenReturn(longCommandObject); - - Response response = pipeliningBase.georadiusByMemberStore(key, member, radius, unit, param, storeParam); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testGeosearchByMemberRadiusByteArray() { - byte[] key = "location".getBytes(); - byte[] member = "Palermo".getBytes(); - double radius = 100; - GeoUnit unit = GeoUnit.KM; - - when(commandObjects.geosearch(key, member, radius, unit)).thenReturn(listGeoRadiusResponseCommandObject); - - Response> response = pipeliningBase.geosearch(key, member, radius, unit); - - assertThat(commands, contains(listGeoRadiusResponseCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testGeosearchByCoordinateRadiusByteArray() { - byte[] key = "location".getBytes(); - GeoCoordinate coord = new GeoCoordinate(13.361389, 38.115556); - double radius = 100; - GeoUnit unit = GeoUnit.KM; - - when(commandObjects.geosearch(key, coord, radius, unit)).thenReturn(listGeoRadiusResponseCommandObject); - - Response> response = pipeliningBase.geosearch(key, coord, radius, unit); - - assertThat(commands, contains(listGeoRadiusResponseCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testGeosearchByMemberBoxByteArray() { - byte[] key = "location".getBytes(); - byte[] member = "Palermo".getBytes(); - double width = 200; - double height = 100; - GeoUnit unit = GeoUnit.KM; - - when(commandObjects.geosearch(key, member, width, height, unit)).thenReturn(listGeoRadiusResponseCommandObject); - - Response> response = pipeliningBase.geosearch(key, member, width, height, unit); - - assertThat(commands, contains(listGeoRadiusResponseCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testGeosearchByCoordinateBoxByteArray() { - byte[] key = "location".getBytes(); - GeoCoordinate coord = new GeoCoordinate(13.361389, 38.115556); - double width = 200; - double height = 100; - GeoUnit unit = GeoUnit.KM; - - when(commandObjects.geosearch(key, coord, width, height, unit)).thenReturn(listGeoRadiusResponseCommandObject); - - Response> response = pipeliningBase.geosearch(key, coord, width, height, unit); - - assertThat(commands, contains(listGeoRadiusResponseCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testGeosearchWithParamsByteArray() { - byte[] key = "location".getBytes(); - GeoSearchParam params = GeoSearchParam.geoSearchParam().byRadius(100, GeoUnit.KM); - - when(commandObjects.geosearch(key, params)).thenReturn(listGeoRadiusResponseCommandObject); - - Response> response = pipeliningBase.geosearch(key, params); - - assertThat(commands, contains(listGeoRadiusResponseCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testGeosearchStore() { - byte[] dest = "destination".getBytes(); - byte[] src = "location".getBytes(); - byte[] member = "Palermo".getBytes(); - double radius = 100; - GeoUnit unit = GeoUnit.KM; - - when(commandObjects.geosearchStore(dest, src, member, radius, unit)).thenReturn(longCommandObject); - - Response response = pipeliningBase.geosearchStore(dest, src, member, radius, unit); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testGeosearchStoreByCoordinateRadius() { - byte[] dest = "destination".getBytes(); - byte[] src = "location".getBytes(); - GeoCoordinate coord = new GeoCoordinate(13.361389, 38.115556); - double radius = 100; - GeoUnit unit = GeoUnit.KM; - - when(commandObjects.geosearchStore(dest, src, coord, radius, unit)).thenReturn(longCommandObject); - - Response response = pipeliningBase.geosearchStore(dest, src, coord, radius, unit); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testGeosearchStoreByMemberBoxByteArray() { - byte[] dest = "destination".getBytes(); - byte[] src = "location".getBytes(); - byte[] member = "Palermo".getBytes(); - double width = 200; - double height = 100; - GeoUnit unit = GeoUnit.KM; - - when(commandObjects.geosearchStore(dest, src, member, width, height, unit)).thenReturn(longCommandObject); - - Response response = pipeliningBase.geosearchStore(dest, src, member, width, height, unit); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testGeosearchStoreByCoordinateBox() { - byte[] dest = "destination".getBytes(); - byte[] src = "location".getBytes(); - GeoCoordinate coord = new GeoCoordinate(13.361389, 38.115556); - double width = 200; - double height = 100; - GeoUnit unit = GeoUnit.KM; - - when(commandObjects.geosearchStore(dest, src, coord, width, height, unit)).thenReturn(longCommandObject); - - Response response = pipeliningBase.geosearchStore(dest, src, coord, width, height, unit); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testGeosearchStoreWithParamsByteArray() { - byte[] dest = "destination".getBytes(); - byte[] src = "location".getBytes(); - GeoSearchParam params = GeoSearchParam.geoSearchParam().byRadius(100, GeoUnit.KM); - - when(commandObjects.geosearchStore(dest, src, params)).thenReturn(longCommandObject); - - Response response = pipeliningBase.geosearchStore(dest, src, params); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testGeosearchStoreStoreDistByteArray() { - byte[] dest = "destination".getBytes(); - byte[] src = "location".getBytes(); - GeoSearchParam params = GeoSearchParam.geoSearchParam().byRadius(100, GeoUnit.KM); - - when(commandObjects.geosearchStoreStoreDist(dest, src, params)).thenReturn(longCommandObject); - - Response response = pipeliningBase.geosearchStoreStoreDist(dest, src, params); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testHsetKeyValue() { - byte[] key = "hash".getBytes(); - byte[] field = "field1".getBytes(); - byte[] value = "value1".getBytes(); - - when(commandObjects.hset(key, field, value)).thenReturn(longCommandObject); - - Response response = pipeliningBase.hset(key, field, value); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testHsetMapByteArray() { - byte[] key = "hash".getBytes(); - - Map hash = new HashMap<>(); - hash.put("field1".getBytes(), "value1".getBytes()); - - when(commandObjects.hset(key, hash)).thenReturn(longCommandObject); - - Response response = pipeliningBase.hset(key, hash); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testHgetByteArray() { - byte[] key = "hash".getBytes(); - byte[] field = "field1".getBytes(); - - when(commandObjects.hget(key, field)).thenReturn(bytesCommandObject); - - Response response = pipeliningBase.hget(key, field); - - assertThat(commands, contains(bytesCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testHsetnxByteArray() { - byte[] key = "hash".getBytes(); - byte[] field = "field1".getBytes(); - byte[] value = "value1".getBytes(); - - when(commandObjects.hsetnx(key, field, value)).thenReturn(longCommandObject); - - Response response = pipeliningBase.hsetnx(key, field, value); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testHmsetByteArray() { - byte[] key = "hash".getBytes(); - - Map hash = new HashMap<>(); - hash.put("field1".getBytes(), "value1".getBytes()); - - when(commandObjects.hmset(key, hash)).thenReturn(stringCommandObject); - - Response response = pipeliningBase.hmset(key, hash); - - assertThat(commands, contains(stringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testHmgetByteArray() { - byte[] key = "hash".getBytes(); - byte[] field1 = "field1".getBytes(); - byte[] field2 = "field2".getBytes(); - - when(commandObjects.hmget(key, field1, field2)).thenReturn(listBytesCommandObject); - - Response> response = pipeliningBase.hmget(key, field1, field2); - - assertThat(commands, contains(listBytesCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testHincrByByteArray() { - byte[] key = "hash".getBytes(); - byte[] field = "field1".getBytes(); - long increment = 2L; - - when(commandObjects.hincrBy(key, field, increment)).thenReturn(longCommandObject); - - Response response = pipeliningBase.hincrBy(key, field, increment); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testHincrByFloatByteArray() { - byte[] key = "hash".getBytes(); - byte[] field = "field1".getBytes(); - double increment = 2.5; - - when(commandObjects.hincrByFloat(key, field, increment)).thenReturn(doubleCommandObject); - - Response response = pipeliningBase.hincrByFloat(key, field, increment); - - assertThat(commands, contains(doubleCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testHexistsByteArray() { - byte[] key = "hash".getBytes(); - byte[] field = "field1".getBytes(); - - when(commandObjects.hexists(key, field)).thenReturn(booleanCommandObject); - - Response response = pipeliningBase.hexists(key, field); - - assertThat(commands, contains(booleanCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testHdelByteArray() { - byte[] key = "hash".getBytes(); - byte[] field1 = "field1".getBytes(); - byte[] field2 = "field2".getBytes(); - - when(commandObjects.hdel(key, field1, field2)).thenReturn(longCommandObject); - - Response response = pipeliningBase.hdel(key, field1, field2); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testHlenByteArray() { - byte[] key = "hash".getBytes(); - - when(commandObjects.hlen(key)).thenReturn(longCommandObject); - - Response response = pipeliningBase.hlen(key); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testHkeysByteArray() { - byte[] key = "hash".getBytes(); - - when(commandObjects.hkeys(key)).thenReturn(setBytesCommandObject); - - Response> response = pipeliningBase.hkeys(key); - - assertThat(commands, contains(setBytesCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testHvalsByteArray() { - byte[] key = "hash".getBytes(); - - when(commandObjects.hvals(key)).thenReturn(listBytesCommandObject); - - Response> response = pipeliningBase.hvals(key); - - assertThat(commands, contains(listBytesCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testHgetAllByteArray() { - byte[] key = "hash".getBytes(); - - when(commandObjects.hgetAll(key)).thenReturn(mapBytesBytesCommandObject); - - Response> response = pipeliningBase.hgetAll(key); - - assertThat(commands, contains(mapBytesBytesCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testHrandfieldByteArray() { - byte[] key = "hash".getBytes(); - - when(commandObjects.hrandfield(key)).thenReturn(bytesCommandObject); - - Response response = pipeliningBase.hrandfield(key); - - assertThat(commands, contains(bytesCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testHrandfieldWithCountByteArray() { - byte[] key = "hash".getBytes(); - long count = 2; - - when(commandObjects.hrandfield(key, count)).thenReturn(listBytesCommandObject); - - Response> response = pipeliningBase.hrandfield(key, count); - - assertThat(commands, contains(listBytesCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testHrandfieldWithValuesByteArray() { - byte[] key = "hash".getBytes(); - long count = 2; - - when(commandObjects.hrandfieldWithValues(key, count)).thenReturn(listEntryBytesBytesCommandObject); - - Response>> response = pipeliningBase.hrandfieldWithValues(key, count); - - assertThat(commands, contains(listEntryBytesBytesCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testHscanByteArray() { - byte[] key = "hash".getBytes(); - byte[] cursor = "0".getBytes(); - ScanParams params = new ScanParams().match("*").count(10); - - when(commandObjects.hscan(key, cursor, params)).thenReturn(scanResultEntryBytesBytesCommandObject); - - Response>> response = pipeliningBase.hscan(key, cursor, params); - - assertThat(commands, contains(scanResultEntryBytesBytesCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testHscanNoValuesByteArray() { - byte[] key = "hash".getBytes(); - byte[] cursor = "0".getBytes(); - ScanParams params = new ScanParams().match("*").count(10); - - when(commandObjects.hscanNoValues(key, cursor, params)).thenReturn(scanResultBytesCommandObject); - - Response> response = pipeliningBase.hscanNoValues(key, cursor, params); - - assertThat(commands, contains(scanResultBytesCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testHstrlenByteArray() { - byte[] key = "hash".getBytes(); - byte[] field = "field1".getBytes(); - - when(commandObjects.hstrlen(key, field)).thenReturn(longCommandObject); - - Response response = pipeliningBase.hstrlen(key, field); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testPfaddByteArray() { - byte[] key = "hll".getBytes(); - byte[] element1 = "element1".getBytes(); - byte[] element2 = "element2".getBytes(); - - when(commandObjects.pfadd(key, element1, element2)).thenReturn(longCommandObject); - - Response response = pipeliningBase.pfadd(key, element1, element2); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testPfmergeByteArray() { - byte[] destkey = "hll_dest".getBytes(); - byte[] sourcekey1 = "hll1".getBytes(); - byte[] sourcekey2 = "hll2".getBytes(); - - when(commandObjects.pfmerge(destkey, sourcekey1, sourcekey2)).thenReturn(stringCommandObject); - - Response response = pipeliningBase.pfmerge(destkey, sourcekey1, sourcekey2); - - assertThat(commands, contains(stringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testPfcountSingleKeyByteArray() { - byte[] key = "hll".getBytes(); - - when(commandObjects.pfcount(key)).thenReturn(longCommandObject); - - Response response = pipeliningBase.pfcount(key); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testPfcountMultipleKeysByteArray() { - byte[] key1 = "hll1".getBytes(); - byte[] key2 = "hll2".getBytes(); - - when(commandObjects.pfcount(key1, key2)).thenReturn(longCommandObject); - - Response response = pipeliningBase.pfcount(key1, key2); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testExistsByteArray() { - byte[] key = "key".getBytes(); - - when(commandObjects.exists(key)).thenReturn(booleanCommandObject); - - Response response = pipeliningBase.exists(key); - - assertThat(commands, contains(booleanCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testExistsMultipleKeysByteArray() { - byte[] key1 = "key1".getBytes(); - byte[] key2 = "key2".getBytes(); - - when(commandObjects.exists(key1, key2)).thenReturn(longCommandObject); - - Response response = pipeliningBase.exists(key1, key2); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testPersistByteArray() { - byte[] key = "key".getBytes(); - - when(commandObjects.persist(key)).thenReturn(longCommandObject); - - Response response = pipeliningBase.persist(key); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testTypeByteArray() { - byte[] key = "key".getBytes(); - - when(commandObjects.type(key)).thenReturn(stringCommandObject); - - Response response = pipeliningBase.type(key); - - assertThat(commands, contains(stringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testDumpByteArray() { - byte[] key = "key".getBytes(); - - when(commandObjects.dump(key)).thenReturn(bytesCommandObject); - - Response response = pipeliningBase.dump(key); - - assertThat(commands, contains(bytesCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testRestoreByteArray() { - byte[] key = "key".getBytes(); - long ttl = 0L; - byte[] serializedValue = "serialized".getBytes(); - - when(commandObjects.restore(key, ttl, serializedValue)).thenReturn(stringCommandObject); - - Response response = pipeliningBase.restore(key, ttl, serializedValue); - - assertThat(commands, contains(stringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testRestoreWithParamsByteArray() { - byte[] key = "key".getBytes(); - long ttl = 0L; - byte[] serializedValue = "serialized".getBytes(); - RestoreParams params = RestoreParams.restoreParams().replace(); - - when(commandObjects.restore(key, ttl, serializedValue, params)).thenReturn(stringCommandObject); - - Response response = pipeliningBase.restore(key, ttl, serializedValue, params); - - assertThat(commands, contains(stringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testExpireByteArray() { - byte[] key = "key".getBytes(); - long seconds = 60L; - - when(commandObjects.expire(key, seconds)).thenReturn(longCommandObject); - - Response response = pipeliningBase.expire(key, seconds); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testExpireWithOptionByteArray() { - byte[] key = "key".getBytes(); - long seconds = 60L; - ExpiryOption expiryOption = ExpiryOption.NX; - - when(commandObjects.expire(key, seconds, expiryOption)).thenReturn(longCommandObject); - - Response response = pipeliningBase.expire(key, seconds, expiryOption); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testPexpireByteArray() { - byte[] key = "key".getBytes(); - long milliseconds = 60000L; - - when(commandObjects.pexpire(key, milliseconds)).thenReturn(longCommandObject); - - Response response = pipeliningBase.pexpire(key, milliseconds); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testPexpireWithOptionByteArray() { - byte[] key = "key".getBytes(); - long milliseconds = 60000L; - ExpiryOption expiryOption = ExpiryOption.NX; - - when(commandObjects.pexpire(key, milliseconds, expiryOption)).thenReturn(longCommandObject); - - Response response = pipeliningBase.pexpire(key, milliseconds, expiryOption); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testExpireTimeByteArray() { - byte[] key = "key".getBytes(); - - when(commandObjects.expireTime(key)).thenReturn(longCommandObject); - - Response response = pipeliningBase.expireTime(key); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testPexpireTimeByteArray() { - byte[] key = "key".getBytes(); - - when(commandObjects.pexpireTime(key)).thenReturn(longCommandObject); - - Response response = pipeliningBase.pexpireTime(key); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testExpireAtByteArray() { - byte[] key = "key".getBytes(); - long unixTime = 1625097600L; - - when(commandObjects.expireAt(key, unixTime)).thenReturn(longCommandObject); - - Response response = pipeliningBase.expireAt(key, unixTime); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testExpireAtWithOptionByteArray() { - byte[] key = "key".getBytes(); - long unixTime = 1625097600L; - ExpiryOption expiryOption = ExpiryOption.NX; - - when(commandObjects.expireAt(key, unixTime, expiryOption)).thenReturn(longCommandObject); - - Response response = pipeliningBase.expireAt(key, unixTime, expiryOption); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testPexpireAtByteArray() { - byte[] key = "key".getBytes(); - long millisecondsTimestamp = 1625097600000L; - - when(commandObjects.pexpireAt(key, millisecondsTimestamp)).thenReturn(longCommandObject); - - Response response = pipeliningBase.pexpireAt(key, millisecondsTimestamp); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testPexpireAtWithOptionByteArray() { - byte[] key = "key".getBytes(); - long millisecondsTimestamp = 1625097600000L; - ExpiryOption expiryOption = ExpiryOption.NX; - - when(commandObjects.pexpireAt(key, millisecondsTimestamp, expiryOption)).thenReturn(longCommandObject); - - Response response = pipeliningBase.pexpireAt(key, millisecondsTimestamp, expiryOption); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testTtlByteArray() { - byte[] key = "key".getBytes(); - - when(commandObjects.ttl(key)).thenReturn(longCommandObject); - - Response response = pipeliningBase.ttl(key); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testPttlByteArray() { - byte[] key = "key".getBytes(); - - when(commandObjects.pttl(key)).thenReturn(longCommandObject); - - Response response = pipeliningBase.pttl(key); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testTouchSingleKeyByteArray() { - byte[] key = "key".getBytes(); - - when(commandObjects.touch(key)).thenReturn(longCommandObject); - - Response response = pipeliningBase.touch(key); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testTouchMultipleKeysByteArray() { - byte[] key1 = "key1".getBytes(); - byte[] key2 = "key2".getBytes(); - - when(commandObjects.touch(key1, key2)).thenReturn(longCommandObject); - - Response response = pipeliningBase.touch(key1, key2); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testSortDefaultByteArray() { - byte[] key = "key".getBytes(); - - when(commandObjects.sort(key)).thenReturn(listBytesCommandObject); - - Response> response = pipeliningBase.sort(key); - - assertThat(commands, contains(listBytesCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testSortWithParamsByteArray() { - byte[] key = "key".getBytes(); - SortingParams sortingParams = new SortingParams().alpha().limit(0, 10); - - when(commandObjects.sort(key, sortingParams)).thenReturn(listBytesCommandObject); - - Response> response = pipeliningBase.sort(key, sortingParams); - - assertThat(commands, contains(listBytesCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testSortReadonlyByteArray() { - byte[] key = "key".getBytes(); - SortingParams sortingParams = new SortingParams().alpha().limit(0, 10); - - when(commandObjects.sortReadonly(key, sortingParams)).thenReturn(listBytesCommandObject); - - Response> response = pipeliningBase.sortReadonly(key, sortingParams); - - assertThat(commands, contains(listBytesCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testDelSingleKeyByteArray() { - byte[] key = "key".getBytes(); - - when(commandObjects.del(key)).thenReturn(longCommandObject); - - Response response = pipeliningBase.del(key); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testDelMultipleKeysByteArray() { - byte[] key1 = "key1".getBytes(); - byte[] key2 = "key2".getBytes(); - - when(commandObjects.del(key1, key2)).thenReturn(longCommandObject); - - Response response = pipeliningBase.del(key1, key2); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testUnlinkSingleKeyByteArray() { - byte[] key = "key".getBytes(); - - when(commandObjects.unlink(key)).thenReturn(longCommandObject); - - Response response = pipeliningBase.unlink(key); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testUnlinkMultipleKeysByteArray() { - byte[] key1 = "key1".getBytes(); - byte[] key2 = "key2".getBytes(); - - when(commandObjects.unlink(key1, key2)).thenReturn(longCommandObject); - - Response response = pipeliningBase.unlink(key1, key2); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testCopyByteArray() { - byte[] srcKey = "sourceKey".getBytes(); - byte[] dstKey = "destinationKey".getBytes(); - boolean replace = true; - - when(commandObjects.copy(srcKey, dstKey, replace)).thenReturn(booleanCommandObject); - - Response response = pipeliningBase.copy(srcKey, dstKey, replace); - - assertThat(commands, contains(booleanCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testRenameByteArray() { - byte[] oldkey = "oldKey".getBytes(); - byte[] newkey = "newKey".getBytes(); - - when(commandObjects.rename(oldkey, newkey)).thenReturn(stringCommandObject); - - Response response = pipeliningBase.rename(oldkey, newkey); - - assertThat(commands, contains(stringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testRenamenxByteArray() { - byte[] oldkey = "oldKey".getBytes(); - byte[] newkey = "newKey".getBytes(); - - when(commandObjects.renamenx(oldkey, newkey)).thenReturn(longCommandObject); - - Response response = pipeliningBase.renamenx(oldkey, newkey); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testSortToDstKeyWithParamsByteArray() { - byte[] key = "key".getBytes(); - byte[] dstkey = "dstkey".getBytes(); - SortingParams sortingParams = new SortingParams().alpha().limit(0, 10); - - when(commandObjects.sort(key, sortingParams, dstkey)).thenReturn(longCommandObject); - - Response response = pipeliningBase.sort(key, sortingParams, dstkey); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testSortToDstKeyByteArray() { - byte[] key = "key".getBytes(); - byte[] dstkey = "dstkey".getBytes(); - - when(commandObjects.sort(key, dstkey)).thenReturn(longCommandObject); - - Response response = pipeliningBase.sort(key, dstkey); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testMemoryUsageByteArray() { - byte[] key = "key".getBytes(); - - when(commandObjects.memoryUsage(key)).thenReturn(longCommandObject); - - Response response = pipeliningBase.memoryUsage(key); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testMemoryUsageWithSamplesByteArray() { - byte[] key = "key".getBytes(); - int samples = 5; - - when(commandObjects.memoryUsage(key, samples)).thenReturn(longCommandObject); - - Response response = pipeliningBase.memoryUsage(key, samples); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testObjectRefcountByteArray() { - byte[] key = "key".getBytes(); - - when(commandObjects.objectRefcount(key)).thenReturn(longCommandObject); - - Response response = pipeliningBase.objectRefcount(key); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testObjectEncodingByteArray() { - byte[] key = "key".getBytes(); - - when(commandObjects.objectEncoding(key)).thenReturn(bytesCommandObject); - - Response response = pipeliningBase.objectEncoding(key); - - assertThat(commands, contains(bytesCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testObjectIdletimeByteArray() { - byte[] key = "key".getBytes(); - - when(commandObjects.objectIdletime(key)).thenReturn(longCommandObject); - - Response response = pipeliningBase.objectIdletime(key); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testObjectFreqByteArray() { - byte[] key = "key".getBytes(); - - when(commandObjects.objectFreq(key)).thenReturn(longCommandObject); - - Response response = pipeliningBase.objectFreq(key); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testMigrateSingleKeyByteArray() { - String host = "localhost"; - int port = 6379; - byte[] key = "key".getBytes(); - int timeout = 1000; - - when(commandObjects.migrate(host, port, key, timeout)).thenReturn(stringCommandObject); - - Response response = pipeliningBase.migrate(host, port, key, timeout); - - assertThat(commands, contains(stringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testMigrateMultipleKeysByteArray() { - String host = "localhost"; - int port = 6379; - int timeout = 1000; - MigrateParams params = MigrateParams.migrateParams().copy().replace(); - byte[] key1 = "key1".getBytes(); - byte[] key2 = "key2".getBytes(); - - when(commandObjects.migrate(host, port, timeout, params, key1, key2)).thenReturn(stringCommandObject); - - Response response = pipeliningBase.migrate(host, port, timeout, params, key1, key2); - - assertThat(commands, contains(stringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testKeysByteArray() { - byte[] pattern = "*".getBytes(); - - when(commandObjects.keys(pattern)).thenReturn(setBytesCommandObject); - - Response> response = pipeliningBase.keys(pattern); - - assertThat(commands, contains(setBytesCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testScanByteArray() { - byte[] cursor = "0".getBytes(); - - when(commandObjects.scan(cursor)).thenReturn(scanResultBytesCommandObject); - - Response> response = pipeliningBase.scan(cursor); - - assertThat(commands, contains(scanResultBytesCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testScanWithParamsByteArray() { - byte[] cursor = "0".getBytes(); - ScanParams params = new ScanParams().match("*").count(10); - - when(commandObjects.scan(cursor, params)).thenReturn(scanResultBytesCommandObject); - - Response> response = pipeliningBase.scan(cursor, params); - - assertThat(commands, contains(scanResultBytesCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testScanWithTypeByteArray() { - byte[] cursor = "0".getBytes(); - ScanParams params = new ScanParams().match("*").count(10); - byte[] type = "string".getBytes(); - - when(commandObjects.scan(cursor, params, type)).thenReturn(scanResultBytesCommandObject); - - Response> response = pipeliningBase.scan(cursor, params, type); - - assertThat(commands, contains(scanResultBytesCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testRandomBinaryKeyByteArray() { - when(commandObjects.randomBinaryKey()).thenReturn(bytesCommandObject); - - Response response = pipeliningBase.randomBinaryKey(); - - assertThat(commands, contains(bytesCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testRpushByteArray() { - byte[] key = "key".getBytes(); - byte[] arg1 = "value1".getBytes(); - byte[] arg2 = "value2".getBytes(); - - when(commandObjects.rpush(key, arg1, arg2)).thenReturn(longCommandObject); - - Response response = pipeliningBase.rpush(key, arg1, arg2); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testLpushByteArray() { - byte[] key = "key".getBytes(); - byte[] arg1 = "value1".getBytes(); - byte[] arg2 = "value2".getBytes(); - - when(commandObjects.lpush(key, arg1, arg2)).thenReturn(longCommandObject); - - Response response = pipeliningBase.lpush(key, arg1, arg2); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testLlenByteArray() { - byte[] key = "key".getBytes(); - - when(commandObjects.llen(key)).thenReturn(longCommandObject); - - Response response = pipeliningBase.llen(key); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testLrangeByteArray() { - byte[] key = "key".getBytes(); - long start = 0; - long stop = -1; - - when(commandObjects.lrange(key, start, stop)).thenReturn(listBytesCommandObject); - - Response> response = pipeliningBase.lrange(key, start, stop); - - assertThat(commands, contains(listBytesCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testLtrimByteArray() { - byte[] key = "key".getBytes(); - long start = 1; - long stop = -1; - - when(commandObjects.ltrim(key, start, stop)).thenReturn(stringCommandObject); - - Response response = pipeliningBase.ltrim(key, start, stop); - - assertThat(commands, contains(stringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testLindexByteArray() { - byte[] key = "key".getBytes(); - long index = 0; - - when(commandObjects.lindex(key, index)).thenReturn(bytesCommandObject); - - Response response = pipeliningBase.lindex(key, index); - - assertThat(commands, contains(bytesCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testLsetByteArray() { - byte[] key = "key".getBytes(); - long index = 0; - byte[] value = "value".getBytes(); - - when(commandObjects.lset(key, index, value)).thenReturn(stringCommandObject); - - Response response = pipeliningBase.lset(key, index, value); - - assertThat(commands, contains(stringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testLremByteArray() { - byte[] key = "key".getBytes(); - long count = 1; - byte[] value = "value".getBytes(); - - when(commandObjects.lrem(key, count, value)).thenReturn(longCommandObject); - - Response response = pipeliningBase.lrem(key, count, value); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testLpopByteArray() { - byte[] key = "key".getBytes(); - - when(commandObjects.lpop(key)).thenReturn(bytesCommandObject); - - Response response = pipeliningBase.lpop(key); - - assertThat(commands, contains(bytesCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testLpopWithCountByteArray() { - byte[] key = "key".getBytes(); - int count = 2; - - when(commandObjects.lpop(key, count)).thenReturn(listBytesCommandObject); - - Response> response = pipeliningBase.lpop(key, count); - - assertThat(commands, contains(listBytesCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testLposSingleByteArray() { - byte[] key = "key".getBytes(); - byte[] element = "element".getBytes(); - - when(commandObjects.lpos(key, element)).thenReturn(longCommandObject); - - Response response = pipeliningBase.lpos(key, element); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testLposWithParamsByteArray() { - byte[] key = "key".getBytes(); - byte[] element = "element".getBytes(); - LPosParams params = new LPosParams().rank(1); - - when(commandObjects.lpos(key, element, params)).thenReturn(longCommandObject); - - Response response = pipeliningBase.lpos(key, element, params); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testLposWithParamsAndCountByteArray() { - byte[] key = "key".getBytes(); - byte[] element = "element".getBytes(); - LPosParams params = new LPosParams().rank(1); - long count = 2; - - when(commandObjects.lpos(key, element, params, count)).thenReturn(listLongCommandObject); - - Response> response = pipeliningBase.lpos(key, element, params, count); - - assertThat(commands, contains(listLongCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testRpopByteArray() { - byte[] key = "key".getBytes(); - - when(commandObjects.rpop(key)).thenReturn(bytesCommandObject); - - Response response = pipeliningBase.rpop(key); - - assertThat(commands, contains(bytesCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testRpopWithCountByteArray() { - byte[] key = "key".getBytes(); - int count = 2; - - when(commandObjects.rpop(key, count)).thenReturn(listBytesCommandObject); - - Response> response = pipeliningBase.rpop(key, count); - - assertThat(commands, contains(listBytesCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testLinsertByteArray() { - byte[] key = "key".getBytes(); - ListPosition where = ListPosition.BEFORE; - byte[] pivot = "pivot".getBytes(); - byte[] value = "value".getBytes(); - - when(commandObjects.linsert(key, where, pivot, value)).thenReturn(longCommandObject); - - Response response = pipeliningBase.linsert(key, where, pivot, value); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testLpushxByteArray() { - byte[] key = "key".getBytes(); - byte[] arg = "value".getBytes(); - - when(commandObjects.lpushx(key, arg)).thenReturn(longCommandObject); - - Response response = pipeliningBase.lpushx(key, arg); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testRpushxByteArray() { - byte[] key = "key".getBytes(); - byte[] arg = "value".getBytes(); - - when(commandObjects.rpushx(key, arg)).thenReturn(longCommandObject); - - Response response = pipeliningBase.rpushx(key, arg); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testBlpopWithTimeoutByteArray() { - int timeout = 10; - byte[] key1 = "key1".getBytes(); - byte[] key2 = "key2".getBytes(); - - when(commandObjects.blpop(timeout, key1, key2)).thenReturn(listBytesCommandObject); - - Response> response = pipeliningBase.blpop(timeout, key1, key2); - - assertThat(commands, contains(listBytesCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testBlpopWithDoubleTimeoutByteArray() { - double timeout = 10.5; - byte[] key1 = "key1".getBytes(); - byte[] key2 = "key2".getBytes(); - - when(commandObjects.blpop(timeout, key1, key2)).thenReturn(keyValueBytesBytesCommandObject); - - Response> response = pipeliningBase.blpop(timeout, key1, key2); - - assertThat(commands, contains(keyValueBytesBytesCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testBrpopWithTimeoutByteArray() { - int timeout = 10; - byte[] key1 = "key1".getBytes(); - byte[] key2 = "key2".getBytes(); - - when(commandObjects.brpop(timeout, key1, key2)).thenReturn(listBytesCommandObject); - - Response> response = pipeliningBase.brpop(timeout, key1, key2); - - assertThat(commands, contains(listBytesCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testBrpopWithDoubleTimeoutByteArray() { - double timeout = 10.5; - byte[] key1 = "key1".getBytes(); - byte[] key2 = "key2".getBytes(); - - when(commandObjects.brpop(timeout, key1, key2)).thenReturn(keyValueBytesBytesCommandObject); - - Response> response = pipeliningBase.brpop(timeout, key1, key2); - - assertThat(commands, contains(keyValueBytesBytesCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testRpoplpushByteArray() { - byte[] srckey = "srckey".getBytes(); - byte[] dstkey = "dstkey".getBytes(); - - when(commandObjects.rpoplpush(srckey, dstkey)).thenReturn(bytesCommandObject); - - Response response = pipeliningBase.rpoplpush(srckey, dstkey); - - assertThat(commands, contains(bytesCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testBrpoplpushByteArray() { - byte[] source = "source".getBytes(); - byte[] destination = "destination".getBytes(); - int timeout = 10; - - when(commandObjects.brpoplpush(source, destination, timeout)).thenReturn(bytesCommandObject); - - Response response = pipeliningBase.brpoplpush(source, destination, timeout); - - assertThat(commands, contains(bytesCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testLmoveByteArray() { - byte[] srcKey = "srcKey".getBytes(); - byte[] dstKey = "dstKey".getBytes(); - ListDirection from = ListDirection.LEFT; - ListDirection to = ListDirection.RIGHT; - - when(commandObjects.lmove(srcKey, dstKey, from, to)).thenReturn(bytesCommandObject); - - Response response = pipeliningBase.lmove(srcKey, dstKey, from, to); - - assertThat(commands, contains(bytesCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testBlmoveByteArray() { - byte[] srcKey = "srcKey".getBytes(); - byte[] dstKey = "dstKey".getBytes(); - ListDirection from = ListDirection.LEFT; - ListDirection to = ListDirection.RIGHT; - double timeout = 10.5; - - when(commandObjects.blmove(srcKey, dstKey, from, to, timeout)).thenReturn(bytesCommandObject); - - Response response = pipeliningBase.blmove(srcKey, dstKey, from, to, timeout); - - assertThat(commands, contains(bytesCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testLmpopByteArray() { - ListDirection direction = ListDirection.LEFT; - byte[] key1 = "key1".getBytes(); - byte[] key2 = "key2".getBytes(); - - when(commandObjects.lmpop(direction, key1, key2)).thenReturn(keyValueBytesListBytesCommandObject); - - Response>> response = pipeliningBase.lmpop(direction, key1, key2); - - assertThat(commands, contains(keyValueBytesListBytesCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testLmpopWithCountByteArray() { - ListDirection direction = ListDirection.LEFT; - int count = 2; - byte[] key1 = "key1".getBytes(); - byte[] key2 = "key2".getBytes(); - - when(commandObjects.lmpop(direction, count, key1, key2)).thenReturn(keyValueBytesListBytesCommandObject); - - Response>> response = pipeliningBase.lmpop(direction, count, key1, key2); - - assertThat(commands, contains(keyValueBytesListBytesCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testBlmpopByteArray() { - double timeout = 10.5; - ListDirection direction = ListDirection.LEFT; - byte[] key1 = "key1".getBytes(); - byte[] key2 = "key2".getBytes(); - - when(commandObjects.blmpop(timeout, direction, key1, key2)).thenReturn(keyValueBytesListBytesCommandObject); - - Response>> response = pipeliningBase.blmpop(timeout, direction, key1, key2); - - assertThat(commands, contains(keyValueBytesListBytesCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testBlmpopWithCountByteArray() { - double timeout = 10.5; - ListDirection direction = ListDirection.LEFT; - int count = 2; - byte[] key1 = "key1".getBytes(); - byte[] key2 = "key2".getBytes(); - - when(commandObjects.blmpop(timeout, direction, count, key1, key2)).thenReturn(keyValueBytesListBytesCommandObject); - - Response>> response = pipeliningBase.blmpop(timeout, direction, count, key1, key2); - - assertThat(commands, contains(keyValueBytesListBytesCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testWaitReplicasByteArray() { - byte[] sampleKey = "sampleKey".getBytes(); - int replicas = 1; - long timeout = 1000; - - when(commandObjects.waitReplicas(sampleKey, replicas, timeout)).thenReturn(longCommandObject); - - Response response = pipeliningBase.waitReplicas(sampleKey, replicas, timeout); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testWaitAOFByteArray() { - byte[] sampleKey = "sampleKey".getBytes(); - long numLocal = 1; - long numReplicas = 1; - long timeout = 1000; - - when(commandObjects.waitAOF(sampleKey, numLocal, numReplicas, timeout)).thenReturn(keyValueLongLongCommandObject); - - Response> response = pipeliningBase.waitAOF(sampleKey, numLocal, numReplicas, timeout); - - assertThat(commands, contains(keyValueLongLongCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testEvalByteArray() { - byte[] script = "return 'Hello, world!'".getBytes(); - byte[] sampleKey = "sampleKey".getBytes(); - - when(commandObjects.eval(script, sampleKey)).thenReturn(objectCommandObject); - - Response response = pipeliningBase.eval(script, sampleKey); - - assertThat(commands, contains(objectCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testEvalshaByteArray() { - byte[] sha1 = "abcdef1234567890".getBytes(); - byte[] sampleKey = "sampleKey".getBytes(); - - when(commandObjects.evalsha(sha1, sampleKey)).thenReturn(objectCommandObject); - - Response response = pipeliningBase.evalsha(sha1, sampleKey); - - assertThat(commands, contains(objectCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testScriptExistsByteArray() { - byte[] sampleKey = "sampleKey".getBytes(); - byte[] sha1 = "abcdef1234567890".getBytes(); - - when(commandObjects.scriptExists(sampleKey, sha1)).thenReturn(listBooleanCommandObject); - - Response> response = pipeliningBase.scriptExists(sampleKey, sha1); - - assertThat(commands, contains(listBooleanCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testScriptLoadByteArray() { - byte[] script = "return 'Hello, world!'".getBytes(); - byte[] sampleKey = "sampleKey".getBytes(); - - when(commandObjects.scriptLoad(script, sampleKey)).thenReturn(bytesCommandObject); - - Response response = pipeliningBase.scriptLoad(script, sampleKey); - - assertThat(commands, contains(bytesCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testScriptFlushByteArray() { - byte[] sampleKey = "sampleKey".getBytes(); - - when(commandObjects.scriptFlush(sampleKey)).thenReturn(stringCommandObject); - - Response response = pipeliningBase.scriptFlush(sampleKey); - - assertThat(commands, contains(stringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testScriptFlushWithFlushModeByteArray() { - byte[] sampleKey = "sampleKey".getBytes(); - FlushMode flushMode = FlushMode.SYNC; - - when(commandObjects.scriptFlush(sampleKey, flushMode)).thenReturn(stringCommandObject); - - Response response = pipeliningBase.scriptFlush(sampleKey, flushMode); - - assertThat(commands, contains(stringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testScriptKillByteArray() { - byte[] sampleKey = "sampleKey".getBytes(); - - when(commandObjects.scriptKill(sampleKey)).thenReturn(stringCommandObject); - - Response response = pipeliningBase.scriptKill(sampleKey); - - assertThat(commands, contains(stringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testEvalNoKeysByteArray() { - byte[] script = "return 'Hello, world!'".getBytes(); - - when(commandObjects.eval(script)).thenReturn(objectCommandObject); - - Response response = pipeliningBase.eval(script); - - assertThat(commands, contains(objectCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testEvalWithKeyCountAndParamsByteArray() { - byte[] script = "return KEYS[1]".getBytes(); - int keyCount = 1; - byte[] param1 = "key1".getBytes(); - - when(commandObjects.eval(script, keyCount, param1)).thenReturn(objectCommandObject); - - Response response = pipeliningBase.eval(script, keyCount, param1); - - assertThat(commands, contains(objectCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testEvalWithKeysAndArgsByteArray() { - byte[] script = "return {KEYS[1], ARGV[1]}".getBytes(); - List keys = Collections.singletonList("key1".getBytes()); - List args = Collections.singletonList("arg1".getBytes()); - - when(commandObjects.eval(script, keys, args)).thenReturn(objectCommandObject); - - Response response = pipeliningBase.eval(script, keys, args); - - assertThat(commands, contains(objectCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testEvalReadonlyWithKeysAndArgsByteArray() { - byte[] script = "return {KEYS[1], ARGV[1]}".getBytes(); - List keys = Collections.singletonList("key1".getBytes()); - List args = Collections.singletonList("arg1".getBytes()); - - when(commandObjects.evalReadonly(script, keys, args)).thenReturn(objectCommandObject); - - Response response = pipeliningBase.evalReadonly(script, keys, args); - - assertThat(commands, contains(objectCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testEvalshaNoKeysByteArray() { - byte[] sha1 = "abcdef1234567890".getBytes(); - - when(commandObjects.evalsha(sha1)).thenReturn(objectCommandObject); - - Response response = pipeliningBase.evalsha(sha1); - - assertThat(commands, contains(objectCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testEvalshaWithKeyCountAndParamsByteArray() { - byte[] sha1 = "abcdef1234567890".getBytes(); - int keyCount = 1; - byte[] param1 = "key1".getBytes(); - - when(commandObjects.evalsha(sha1, keyCount, param1)).thenReturn(objectCommandObject); - - Response response = pipeliningBase.evalsha(sha1, keyCount, param1); - - assertThat(commands, contains(objectCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testEvalshaWithKeysAndArgsByteArray() { - byte[] sha1 = "abcdef1234567890".getBytes(); - List keys = Collections.singletonList("key1".getBytes()); - List args = Collections.singletonList("arg1".getBytes()); - - when(commandObjects.evalsha(sha1, keys, args)).thenReturn(objectCommandObject); - - Response response = pipeliningBase.evalsha(sha1, keys, args); - - assertThat(commands, contains(objectCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testEvalshaReadonlyWithKeysAndArgsByteArray() { - byte[] sha1 = "abcdef1234567890".getBytes(); - List keys = Collections.singletonList("key1".getBytes()); - List args = Collections.singletonList("arg1".getBytes()); - - when(commandObjects.evalshaReadonly(sha1, keys, args)).thenReturn(objectCommandObject); - - Response response = pipeliningBase.evalshaReadonly(sha1, keys, args); - - assertThat(commands, contains(objectCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testSaddByteArray() { - byte[] key = "key".getBytes(); - byte[] member1 = "member1".getBytes(); - byte[] member2 = "member2".getBytes(); - - when(commandObjects.sadd(key, member1, member2)).thenReturn(longCommandObject); - - Response response = pipeliningBase.sadd(key, member1, member2); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testSmembersByteArray() { - byte[] key = "key".getBytes(); - - when(commandObjects.smembers(key)).thenReturn(setBytesCommandObject); - - Response> response = pipeliningBase.smembers(key); - - assertThat(commands, contains(setBytesCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testSremByteArray() { - byte[] key = "key".getBytes(); - byte[] member1 = "member1".getBytes(); - byte[] member2 = "member2".getBytes(); - - when(commandObjects.srem(key, member1, member2)).thenReturn(longCommandObject); - - Response response = pipeliningBase.srem(key, member1, member2); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testSpopSingleByteArray() { - byte[] key = "key".getBytes(); - - when(commandObjects.spop(key)).thenReturn(bytesCommandObject); - - Response response = pipeliningBase.spop(key); - - assertThat(commands, contains(bytesCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testSpopMultipleByteArray() { - byte[] key = "key".getBytes(); - long count = 2; - - when(commandObjects.spop(key, count)).thenReturn(setBytesCommandObject); - - Response> response = pipeliningBase.spop(key, count); - - assertThat(commands, contains(setBytesCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testScardByteArray() { - byte[] key = "key".getBytes(); - - when(commandObjects.scard(key)).thenReturn(longCommandObject); - - Response response = pipeliningBase.scard(key); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testSismemberByteArray() { - byte[] key = "key".getBytes(); - byte[] member = "member".getBytes(); - - when(commandObjects.sismember(key, member)).thenReturn(booleanCommandObject); - - Response response = pipeliningBase.sismember(key, member); - - assertThat(commands, contains(booleanCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testSmismemberByteArray() { - byte[] key = "key".getBytes(); - byte[] member1 = "member1".getBytes(); - byte[] member2 = "member2".getBytes(); - - when(commandObjects.smismember(key, member1, member2)).thenReturn(listBooleanCommandObject); - - Response> response = pipeliningBase.smismember(key, member1, member2); - - assertThat(commands, contains(listBooleanCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testSrandmemberSingleByteArray() { - byte[] key = "key".getBytes(); - - when(commandObjects.srandmember(key)).thenReturn(bytesCommandObject); - - Response response = pipeliningBase.srandmember(key); - - assertThat(commands, contains(bytesCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testSrandmemberMultipleByteArray() { - byte[] key = "key".getBytes(); - int count = 2; - - when(commandObjects.srandmember(key, count)).thenReturn(listBytesCommandObject); - - Response> response = pipeliningBase.srandmember(key, count); - - assertThat(commands, contains(listBytesCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testSscanByteArray() { - byte[] key = "key".getBytes(); - byte[] cursor = "0".getBytes(); - ScanParams params = new ScanParams().match("pattern*").count(10); - - when(commandObjects.sscan(key, cursor, params)).thenReturn(scanResultBytesCommandObject); - - Response> response = pipeliningBase.sscan(key, cursor, params); - - assertThat(commands, contains(scanResultBytesCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testSdiffByteArray() { - byte[][] keys = { "key1".getBytes(), "key2".getBytes(), "key3".getBytes() }; - - when(commandObjects.sdiff(keys)).thenReturn(setBytesCommandObject); - - Response> response = pipeliningBase.sdiff(keys); - - assertThat(commands, contains(setBytesCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testSdiffstoreByteArray() { - byte[] dstkey = "destination".getBytes(); - byte[][] keys = { "key1".getBytes(), "key2".getBytes() }; - - when(commandObjects.sdiffstore(dstkey, keys)).thenReturn(longCommandObject); - - Response response = pipeliningBase.sdiffstore(dstkey, keys); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testSinterByteArray() { - byte[][] keys = { "key1".getBytes(), "key2".getBytes() }; - - when(commandObjects.sinter(keys)).thenReturn(setBytesCommandObject); - - Response> response = pipeliningBase.sinter(keys); - - assertThat(commands, contains(setBytesCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testSinterstoreByteArray() { - byte[] dstkey = "destination".getBytes(); - byte[][] keys = { "key1".getBytes(), "key2".getBytes() }; - - when(commandObjects.sinterstore(dstkey, keys)).thenReturn(longCommandObject); - - Response response = pipeliningBase.sinterstore(dstkey, keys); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testSintercardByteArray() { - byte[][] keys = { "key1".getBytes(), "key2".getBytes() }; - - when(commandObjects.sintercard(keys)).thenReturn(longCommandObject); - - Response response = pipeliningBase.sintercard(keys); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testSintercardWithLimitByteArray() { - int limit = 2; - byte[][] keys = { "key1".getBytes(), "key2".getBytes() }; - - when(commandObjects.sintercard(limit, keys)).thenReturn(longCommandObject); - - Response response = pipeliningBase.sintercard(limit, keys); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testSunionByteArray() { - byte[][] keys = { "key1".getBytes(), "key2".getBytes() }; - - when(commandObjects.sunion(keys)).thenReturn(setBytesCommandObject); - - Response> response = pipeliningBase.sunion(keys); - - assertThat(commands, contains(setBytesCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testSunionstoreByteArray() { - byte[] dstkey = "destination".getBytes(); - byte[][] keys = { "key1".getBytes(), "key2".getBytes() }; - - when(commandObjects.sunionstore(dstkey, keys)).thenReturn(longCommandObject); - - Response response = pipeliningBase.sunionstore(dstkey, keys); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testSmoveByteArray() { - byte[] srckey = "source".getBytes(); - byte[] dstkey = "destination".getBytes(); - byte[] member = "member".getBytes(); - - when(commandObjects.smove(srckey, dstkey, member)).thenReturn(longCommandObject); - - Response response = pipeliningBase.smove(srckey, dstkey, member); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testZaddByteArray() { - byte[] key = "zset".getBytes(); - double score = 1.0; - byte[] member = "member".getBytes(); - - when(commandObjects.zadd(key, score, member)).thenReturn(longCommandObject); - - Response response = pipeliningBase.zadd(key, score, member); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testZaddWithParamsByteArray() { - byte[] key = "zset".getBytes(); - double score = 1.0; - byte[] member = "member".getBytes(); - ZAddParams params = ZAddParams.zAddParams().nx(); - - when(commandObjects.zadd(key, score, member, params)).thenReturn(longCommandObject); - - Response response = pipeliningBase.zadd(key, score, member, params); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testZaddWithScoreMembersByteArray() { - byte[] key = "zset".getBytes(); - - Map scoreMembers = new HashMap<>(); - scoreMembers.put("member1".getBytes(), 1.0); - scoreMembers.put("member2".getBytes(), 2.0); - - when(commandObjects.zadd(key, scoreMembers)).thenReturn(longCommandObject); - - Response response = pipeliningBase.zadd(key, scoreMembers); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testZaddWithScoreMembersAndParamsByteArray() { - byte[] key = "zset".getBytes(); - - Map scoreMembers = new HashMap<>(); - scoreMembers.put("member1".getBytes(), 1.0); - scoreMembers.put("member2".getBytes(), 2.0); - - ZAddParams params = ZAddParams.zAddParams().nx(); - - when(commandObjects.zadd(key, scoreMembers, params)).thenReturn(longCommandObject); - - Response response = pipeliningBase.zadd(key, scoreMembers, params); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testZaddIncrByteArray() { - byte[] key = "zset".getBytes(); - double score = 1.0; - byte[] member = "member".getBytes(); - ZAddParams params = ZAddParams.zAddParams().xx(); - - when(commandObjects.zaddIncr(key, score, member, params)).thenReturn(doubleCommandObject); - - Response response = pipeliningBase.zaddIncr(key, score, member, params); - - assertThat(commands, contains(doubleCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testZremByteArray() { - byte[] key = "zset".getBytes(); - byte[][] members = { "member1".getBytes(), "member2".getBytes() }; - - when(commandObjects.zrem(key, members)).thenReturn(longCommandObject); - - Response response = pipeliningBase.zrem(key, members); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testZincrbyByteArray() { - byte[] key = "zset".getBytes(); - double increment = 2.0; - byte[] member = "member".getBytes(); - - when(commandObjects.zincrby(key, increment, member)).thenReturn(doubleCommandObject); - - Response response = pipeliningBase.zincrby(key, increment, member); - - assertThat(commands, contains(doubleCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testZincrbyWithParamsByteArray() { - byte[] key = "zset".getBytes(); - double increment = 2.0; - byte[] member = "member".getBytes(); - ZIncrByParams params = ZIncrByParams.zIncrByParams().xx(); - - when(commandObjects.zincrby(key, increment, member, params)).thenReturn(doubleCommandObject); - - Response response = pipeliningBase.zincrby(key, increment, member, params); - - assertThat(commands, contains(doubleCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testZrankByteArray() { - byte[] key = "zset".getBytes(); - byte[] member = "member".getBytes(); - - when(commandObjects.zrank(key, member)).thenReturn(longCommandObject); - - Response response = pipeliningBase.zrank(key, member); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testZrevrankByteArray() { - byte[] key = "zset".getBytes(); - byte[] member = "member".getBytes(); - - when(commandObjects.zrevrank(key, member)).thenReturn(longCommandObject); - - Response response = pipeliningBase.zrevrank(key, member); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testZrankWithScoreByteArray() { - byte[] key = "zset".getBytes(); - byte[] member = "member".getBytes(); - - when(commandObjects.zrankWithScore(key, member)).thenReturn(keyValueLongDoubleCommandObject); - - Response> response = pipeliningBase.zrankWithScore(key, member); - - assertThat(commands, contains(keyValueLongDoubleCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testZrevrankWithScoreByteArray() { - byte[] key = "zset".getBytes(); - byte[] member = "member".getBytes(); - - when(commandObjects.zrevrankWithScore(key, member)).thenReturn(keyValueLongDoubleCommandObject); - - Response> response = pipeliningBase.zrevrankWithScore(key, member); - - assertThat(commands, contains(keyValueLongDoubleCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testZrangeByteArray() { - byte[] key = "zset".getBytes(); - long start = 0; - long stop = 1; - - when(commandObjects.zrange(key, start, stop)).thenReturn(listBytesCommandObject); - - Response> response = pipeliningBase.zrange(key, start, stop); - - assertThat(commands, contains(listBytesCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testZrevrangeByteArray() { - byte[] key = "zset".getBytes(); - long start = 0; - long stop = 1; - - when(commandObjects.zrevrange(key, start, stop)).thenReturn(listBytesCommandObject); - - Response> response = pipeliningBase.zrevrange(key, start, stop); - - assertThat(commands, contains(listBytesCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testZrangeWithScoresByteArray() { - byte[] key = "zset".getBytes(); - long start = 0; - long stop = 1; - - when(commandObjects.zrangeWithScores(key, start, stop)).thenReturn(listTupleCommandObject); - - Response> response = pipeliningBase.zrangeWithScores(key, start, stop); - - assertThat(commands, contains(listTupleCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testZrevrangeWithScoresByteArray() { - byte[] key = "zset".getBytes(); - long start = 0; - long stop = 1; - - when(commandObjects.zrevrangeWithScores(key, start, stop)).thenReturn(listTupleCommandObject); - - Response> response = pipeliningBase.zrevrangeWithScores(key, start, stop); - - assertThat(commands, contains(listTupleCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testZrandmemberByteArray() { - byte[] key = "zset".getBytes(); - - when(commandObjects.zrandmember(key)).thenReturn(bytesCommandObject); - - Response response = pipeliningBase.zrandmember(key); - - assertThat(commands, contains(bytesCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testZrandmemberWithCountByteArray() { - byte[] key = "zset".getBytes(); - long count = 2; - - when(commandObjects.zrandmember(key, count)).thenReturn(listBytesCommandObject); - - Response> response = pipeliningBase.zrandmember(key, count); - - assertThat(commands, contains(listBytesCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testZrandmemberWithScoresByteArray() { - byte[] key = "zset".getBytes(); - long count = 2; - - when(commandObjects.zrandmemberWithScores(key, count)).thenReturn(listTupleCommandObject); - - Response> response = pipeliningBase.zrandmemberWithScores(key, count); - - assertThat(commands, contains(listTupleCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testZcardByteArray() { - byte[] key = "zset".getBytes(); - - when(commandObjects.zcard(key)).thenReturn(longCommandObject); - - Response response = pipeliningBase.zcard(key); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testZscoreByteArray() { - byte[] key = "zset".getBytes(); - byte[] member = "member".getBytes(); - - when(commandObjects.zscore(key, member)).thenReturn(doubleCommandObject); - - Response response = pipeliningBase.zscore(key, member); - - assertThat(commands, contains(doubleCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testZmscoreByteArray() { - byte[] key = "zset".getBytes(); - byte[][] members = { "member1".getBytes(), "member2".getBytes() }; - - when(commandObjects.zmscore(key, members)).thenReturn(listDoubleCommandObject); - - Response> response = pipeliningBase.zmscore(key, members); - - assertThat(commands, contains(listDoubleCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testZpopmaxByteArray() { - byte[] key = "zset".getBytes(); - - when(commandObjects.zpopmax(key)).thenReturn(tupleCommandObject); - - Response response = pipeliningBase.zpopmax(key); - - assertThat(commands, contains(tupleCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testZpopmaxWithCountByteArray() { - byte[] key = "zset".getBytes(); - int count = 2; - - when(commandObjects.zpopmax(key, count)).thenReturn(listTupleCommandObject); - - Response> response = pipeliningBase.zpopmax(key, count); - - assertThat(commands, contains(listTupleCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testZpopminByteArray() { - byte[] key = "zset".getBytes(); - - when(commandObjects.zpopmin(key)).thenReturn(tupleCommandObject); - - Response response = pipeliningBase.zpopmin(key); - - assertThat(commands, contains(tupleCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testZpopminWithCountByteArray() { - byte[] key = "zset".getBytes(); - int count = 2; - - when(commandObjects.zpopmin(key, count)).thenReturn(listTupleCommandObject); - - Response> response = pipeliningBase.zpopmin(key, count); - - assertThat(commands, contains(listTupleCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testZcountWithScoreRangeByteArray() { - byte[] key = "zset".getBytes(); - double min = 1.0; - double max = 2.0; - - when(commandObjects.zcount(key, min, max)).thenReturn(longCommandObject); - - Response response = pipeliningBase.zcount(key, min, max); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testZcountWithLexRangeByteArray() { - byte[] key = "zset".getBytes(); - byte[] min = "min".getBytes(); - byte[] max = "max".getBytes(); - - when(commandObjects.zcount(key, min, max)).thenReturn(longCommandObject); - - Response response = pipeliningBase.zcount(key, min, max); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testZrangeByScoreByteArray() { - byte[] key = "zset".getBytes(); - double min = 1.0; - double max = 2.0; - - when(commandObjects.zrangeByScore(key, min, max)).thenReturn(listBytesCommandObject); - - Response> response = pipeliningBase.zrangeByScore(key, min, max); - - assertThat(commands, contains(listBytesCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testZrangeByScoreWithMinMaxBytesByteArray() { - byte[] key = "zset".getBytes(); - byte[] min = "1".getBytes(); - byte[] max = "2".getBytes(); - - when(commandObjects.zrangeByScore(key, min, max)).thenReturn(listBytesCommandObject); - - Response> response = pipeliningBase.zrangeByScore(key, min, max); - - assertThat(commands, contains(listBytesCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testZrevrangeByScoreByteArray() { - byte[] key = "zset".getBytes(); - double max = 2.0; - double min = 1.0; - - when(commandObjects.zrevrangeByScore(key, max, min)).thenReturn(listBytesCommandObject); - - Response> response = pipeliningBase.zrevrangeByScore(key, max, min); - - assertThat(commands, contains(listBytesCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testZrangeByScoreWithOffsetCountByteArray() { - byte[] key = "zset".getBytes(); - double min = 1.0; - double max = 2.0; - int offset = 0; - int count = 2; - - when(commandObjects.zrangeByScore(key, min, max, offset, count)).thenReturn(listBytesCommandObject); - - Response> response = pipeliningBase.zrangeByScore(key, min, max, offset, count); - - assertThat(commands, contains(listBytesCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testZrevrangeByScoreWithMinMaxBytesByteArray() { - byte[] key = "zset".getBytes(); - byte[] max = "2".getBytes(); - byte[] min = "1".getBytes(); - - when(commandObjects.zrevrangeByScore(key, max, min)).thenReturn(listBytesCommandObject); - - Response> response = pipeliningBase.zrevrangeByScore(key, max, min); - - assertThat(commands, contains(listBytesCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testZrangeByScoreWithMinMaxBytesOffsetCountByteArray() { - byte[] key = "zset".getBytes(); - byte[] min = "1".getBytes(); - byte[] max = "2".getBytes(); - int offset = 0; - int count = 2; - - when(commandObjects.zrangeByScore(key, min, max, offset, count)).thenReturn(listBytesCommandObject); - - Response> response = pipeliningBase.zrangeByScore(key, min, max, offset, count); - - assertThat(commands, contains(listBytesCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testZrevrangeByScoreWithOffsetCountByteArray() { - byte[] key = "zset".getBytes(); - double max = 2.0; - double min = 1.0; - int offset = 0; - int count = 2; - - when(commandObjects.zrevrangeByScore(key, max, min, offset, count)).thenReturn(listBytesCommandObject); - - Response> response = pipeliningBase.zrevrangeByScore(key, max, min, offset, count); - - assertThat(commands, contains(listBytesCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testZrangeByScoreWithScoresByteArray() { - byte[] key = "zset".getBytes(); - double min = 1.0; - double max = 2.0; - - when(commandObjects.zrangeByScoreWithScores(key, min, max)).thenReturn(listTupleCommandObject); - - Response> response = pipeliningBase.zrangeByScoreWithScores(key, min, max); - - assertThat(commands, contains(listTupleCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testZrevrangeByScoreWithScoresByteArray() { - byte[] key = "zset".getBytes(); - double max = 2.0; - double min = 1.0; - - when(commandObjects.zrevrangeByScoreWithScores(key, max, min)).thenReturn(listTupleCommandObject); - - Response> response = pipeliningBase.zrevrangeByScoreWithScores(key, max, min); - - assertThat(commands, contains(listTupleCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testZrangeByScoreWithScoresOffsetCountByteArray() { - byte[] key = "zset".getBytes(); - double min = 1.0; - double max = 2.0; - int offset = 0; - int count = 2; - - when(commandObjects.zrangeByScoreWithScores(key, min, max, offset, count)).thenReturn(listTupleCommandObject); - - Response> response = pipeliningBase.zrangeByScoreWithScores(key, min, max, offset, count); - - assertThat(commands, contains(listTupleCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testZrevrangeByScoreBytesOffsetCountByteArray() { - byte[] key = "zset".getBytes(); - byte[] max = "2".getBytes(); - byte[] min = "1".getBytes(); - int offset = 0; - int count = 2; - - when(commandObjects.zrevrangeByScore(key, max, min, offset, count)).thenReturn(listBytesCommandObject); - - Response> response = pipeliningBase.zrevrangeByScore(key, max, min, offset, count); - - assertThat(commands, contains(listBytesCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testZrangeByScoreWithScoresBytesByteArray() { - byte[] key = "zset".getBytes(); - byte[] min = "1".getBytes(); - byte[] max = "2".getBytes(); - - when(commandObjects.zrangeByScoreWithScores(key, min, max)).thenReturn(listTupleCommandObject); - - Response> response = pipeliningBase.zrangeByScoreWithScores(key, min, max); - - assertThat(commands, contains(listTupleCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testZrevrangeByScoreWithScoresBytesByteArray() { - byte[] key = "zset".getBytes(); - byte[] max = "2".getBytes(); - byte[] min = "1".getBytes(); - - when(commandObjects.zrevrangeByScoreWithScores(key, max, min)).thenReturn(listTupleCommandObject); - - Response> response = pipeliningBase.zrevrangeByScoreWithScores(key, max, min); - - assertThat(commands, contains(listTupleCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testZrangeByScoreWithScoresBytesOffsetCountByteArray() { - byte[] key = "zset".getBytes(); - byte[] min = "1".getBytes(); - byte[] max = "2".getBytes(); - int offset = 0; - int count = 2; - - when(commandObjects.zrangeByScoreWithScores(key, min, max, offset, count)).thenReturn(listTupleCommandObject); - - Response> response = pipeliningBase.zrangeByScoreWithScores(key, min, max, offset, count); - - assertThat(commands, contains(listTupleCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testZrevrangeByScoreWithScoresOffsetCountByteArray() { - byte[] key = "zset".getBytes(); - double max = 2.0; - double min = 1.0; - int offset = 0; - int count = 2; - - when(commandObjects.zrevrangeByScoreWithScores(key, max, min, offset, count)).thenReturn(listTupleCommandObject); - - Response> response = pipeliningBase.zrevrangeByScoreWithScores(key, max, min, offset, count); - - assertThat(commands, contains(listTupleCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testZrevrangeByScoreWithScoresBytesOffsetCountByteArray() { - byte[] key = "zset".getBytes(); - byte[] max = "2".getBytes(); - byte[] min = "1".getBytes(); - int offset = 0; - int count = 2; - - when(commandObjects.zrevrangeByScoreWithScores(key, max, min, offset, count)).thenReturn(listTupleCommandObject); - - Response> response = pipeliningBase.zrevrangeByScoreWithScores(key, max, min, offset, count); - - assertThat(commands, contains(listTupleCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testZremrangeByRankByteArray() { - byte[] key = "zset".getBytes(); - long start = 0; - long stop = 1; - - when(commandObjects.zremrangeByRank(key, start, stop)).thenReturn(longCommandObject); - - Response response = pipeliningBase.zremrangeByRank(key, start, stop); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testZremrangeByScoreByteArray() { - byte[] key = "zset".getBytes(); - double min = 1.0; - double max = 2.0; - - when(commandObjects.zremrangeByScore(key, min, max)).thenReturn(longCommandObject); - - Response response = pipeliningBase.zremrangeByScore(key, min, max); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testZremrangeByScoreBytesByteArray() { - byte[] key = "zset".getBytes(); - byte[] min = "1".getBytes(); - byte[] max = "2".getBytes(); - - when(commandObjects.zremrangeByScore(key, min, max)).thenReturn(longCommandObject); - - Response response = pipeliningBase.zremrangeByScore(key, min, max); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testZlexcountByteArray() { - byte[] key = "zset".getBytes(); - byte[] min = "[a".getBytes(); - byte[] max = "[z".getBytes(); - - when(commandObjects.zlexcount(key, min, max)).thenReturn(longCommandObject); - - Response response = pipeliningBase.zlexcount(key, min, max); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testZrangeByLexByteArray() { - byte[] key = "zset".getBytes(); - byte[] min = "[a".getBytes(); - byte[] max = "[z".getBytes(); - - when(commandObjects.zrangeByLex(key, min, max)).thenReturn(listBytesCommandObject); - - Response> response = pipeliningBase.zrangeByLex(key, min, max); - - assertThat(commands, contains(listBytesCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testZrangeByLexWithLimitByteArray() { - byte[] key = "zset".getBytes(); - byte[] min = "[a".getBytes(); - byte[] max = "[z".getBytes(); - int offset = 0; - int count = 10; - - when(commandObjects.zrangeByLex(key, min, max, offset, count)).thenReturn(listBytesCommandObject); - - Response> response = pipeliningBase.zrangeByLex(key, min, max, offset, count); - - assertThat(commands, contains(listBytesCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testZrevrangeByLexByteArray() { - byte[] key = "zset".getBytes(); - byte[] max = "[z".getBytes(); - byte[] min = "[a".getBytes(); - - when(commandObjects.zrevrangeByLex(key, max, min)).thenReturn(listBytesCommandObject); - - Response> response = pipeliningBase.zrevrangeByLex(key, max, min); - - assertThat(commands, contains(listBytesCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testZrevrangeByLexWithLimitByteArray() { - byte[] key = "zset".getBytes(); - byte[] max = "[z".getBytes(); - byte[] min = "[a".getBytes(); - int offset = 0; - int count = 10; - - when(commandObjects.zrevrangeByLex(key, max, min, offset, count)).thenReturn(listBytesCommandObject); - - Response> response = pipeliningBase.zrevrangeByLex(key, max, min, offset, count); - - assertThat(commands, contains(listBytesCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testZrangeWithZRangeParamsByteArray() { - byte[] key = "zset".getBytes(); - ZRangeParams zRangeParams = ZRangeParams.zrangeParams(0, 1); - - when(commandObjects.zrange(key, zRangeParams)).thenReturn(listBytesCommandObject); - - Response> response = pipeliningBase.zrange(key, zRangeParams); - - assertThat(commands, contains(listBytesCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testZrangeWithScoresWithZRangeParamsByteArray() { - byte[] key = "zset".getBytes(); - ZRangeParams zRangeParams = ZRangeParams.zrangeParams(0, 1); - - when(commandObjects.zrangeWithScores(key, zRangeParams)).thenReturn(listTupleCommandObject); - - Response> response = pipeliningBase.zrangeWithScores(key, zRangeParams); - - assertThat(commands, contains(listTupleCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testZrangestoreByteArray() { - byte[] dest = "destZset".getBytes(); - byte[] src = "srcZset".getBytes(); - ZRangeParams zRangeParams = ZRangeParams.zrangeParams(0, 1); - - when(commandObjects.zrangestore(dest, src, zRangeParams)).thenReturn(longCommandObject); - - Response response = pipeliningBase.zrangestore(dest, src, zRangeParams); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testZremrangeByLexByteArray() { - byte[] key = "zset".getBytes(); - byte[] min = "[a".getBytes(); - byte[] max = "[z".getBytes(); - - when(commandObjects.zremrangeByLex(key, min, max)).thenReturn(longCommandObject); - - Response response = pipeliningBase.zremrangeByLex(key, min, max); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testZscanByteArray() { - byte[] key = "zset".getBytes(); - byte[] cursor = "0".getBytes(); - ScanParams params = new ScanParams(); - - when(commandObjects.zscan(key, cursor, params)).thenReturn(scanResultTupleCommandObject); - - Response> response = pipeliningBase.zscan(key, cursor, params); - - assertThat(commands, contains(scanResultTupleCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testBzpopmaxByteArray() { - double timeout = 1.0; - byte[][] keys = { "zset1".getBytes(), "zset2".getBytes() }; - - when(commandObjects.bzpopmax(timeout, keys)).thenReturn(keyValueBytesTupleCommandObject); - - Response> response = pipeliningBase.bzpopmax(timeout, keys); - - assertThat(commands, contains(keyValueBytesTupleCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testBzpopminByteArray() { - double timeout = 1.0; - byte[][] keys = { "zset1".getBytes(), "zset2".getBytes() }; - - when(commandObjects.bzpopmin(timeout, keys)).thenReturn(keyValueBytesTupleCommandObject); - - Response> response = pipeliningBase.bzpopmin(timeout, keys); - - assertThat(commands, contains(keyValueBytesTupleCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testZmpopByteArray() { - SortedSetOption option = SortedSetOption.MAX; - byte[][] keys = { "zset1".getBytes(), "zset2".getBytes() }; - - when(commandObjects.zmpop(option, keys)).thenReturn(keyValueBytesListTupleCommandObject); - - Response>> response = pipeliningBase.zmpop(option, keys); - - assertThat(commands, contains(keyValueBytesListTupleCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testZmpopWithCountByteArray() { - SortedSetOption option = SortedSetOption.MAX; - int count = 2; - byte[][] keys = { "zset1".getBytes(), "zset2".getBytes() }; - - when(commandObjects.zmpop(option, count, keys)).thenReturn(keyValueBytesListTupleCommandObject); - - Response>> response = pipeliningBase.zmpop(option, count, keys); - - assertThat(commands, contains(keyValueBytesListTupleCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testBzmpopByteArray() { - double timeout = 1.0; - SortedSetOption option = SortedSetOption.MAX; - byte[][] keys = { "zset1".getBytes(), "zset2".getBytes() }; - - when(commandObjects.bzmpop(timeout, option, keys)).thenReturn(keyValueBytesListTupleCommandObject); - - Response>> response = pipeliningBase.bzmpop(timeout, option, keys); - - assertThat(commands, contains(keyValueBytesListTupleCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testBzmpopWithCountByteArray() { - double timeout = 1.0; - SortedSetOption option = SortedSetOption.MAX; - int count = 2; - byte[][] keys = { "zset1".getBytes(), "zset2".getBytes() }; - - when(commandObjects.bzmpop(timeout, option, count, keys)).thenReturn(keyValueBytesListTupleCommandObject); - - Response>> response = pipeliningBase.bzmpop(timeout, option, count, keys); - - assertThat(commands, contains(keyValueBytesListTupleCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testZdiffByteArray() { - byte[][] keys = { "zset1".getBytes(), "zset2".getBytes() }; - - when(commandObjects.zdiff(keys)).thenReturn(listBytesCommandObject); - - Response> response = pipeliningBase.zdiff(keys); - - assertThat(commands, contains(listBytesCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testZdiffWithScoresByteArray() { - byte[][] keys = { "zset1".getBytes(), "zset2".getBytes() }; - - when(commandObjects.zdiffWithScores(keys)).thenReturn(listTupleCommandObject); - - Response> response = pipeliningBase.zdiffWithScores(keys); - - assertThat(commands, contains(listTupleCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testZdiffStoreByteArray() { - byte[] dstkey = "destZset".getBytes(); - byte[][] keys = { "zset1".getBytes(), "zset2".getBytes() }; - - when(commandObjects.zdiffStore(dstkey, keys)).thenReturn(longCommandObject); - - Response response = pipeliningBase.zdiffStore(dstkey, keys); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testZdifftoreByteArray() { - byte[] dstkey = "destZset".getBytes(); - byte[][] keys = { "zset1".getBytes(), "zset2".getBytes() }; - - when(commandObjects.zdiffstore(dstkey, keys)).thenReturn(longCommandObject); - - Response response = pipeliningBase.zdiffstore(dstkey, keys); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testZinterByteArray() { - ZParams params = new ZParams(); - byte[][] keys = { "zset1".getBytes(), "zset2".getBytes() }; - - when(commandObjects.zinter(params, keys)).thenReturn(listBytesCommandObject); - - Response> response = pipeliningBase.zinter(params, keys); - - assertThat(commands, contains(listBytesCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testZinterWithScoresByteArray() { - ZParams params = new ZParams(); - byte[][] keys = { "zset1".getBytes(), "zset2".getBytes() }; - - when(commandObjects.zinterWithScores(params, keys)).thenReturn(listTupleCommandObject); - - Response> response = pipeliningBase.zinterWithScores(params, keys); - - assertThat(commands, contains(listTupleCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testZinterstoreByteArray() { - byte[] dstkey = "destZset".getBytes(); - byte[][] sets = { "zset1".getBytes(), "zset2".getBytes() }; - - when(commandObjects.zinterstore(dstkey, sets)).thenReturn(longCommandObject); - - Response response = pipeliningBase.zinterstore(dstkey, sets); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testZinterstoreWithParamsByteArray() { - byte[] dstkey = "destZset".getBytes(); - ZParams params = new ZParams(); - byte[][] sets = { "zset1".getBytes(), "zset2".getBytes() }; - - when(commandObjects.zinterstore(dstkey, params, sets)).thenReturn(longCommandObject); - - Response response = pipeliningBase.zinterstore(dstkey, params, sets); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testZintercardByteArray() { - byte[][] keys = { "zset1".getBytes(), "zset2".getBytes() }; - - when(commandObjects.zintercard(keys)).thenReturn(longCommandObject); - - Response response = pipeliningBase.zintercard(keys); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testZintercardWithLimitByteArray() { - long limit = 2; - byte[][] keys = { "zset1".getBytes(), "zset2".getBytes() }; - - when(commandObjects.zintercard(limit, keys)).thenReturn(longCommandObject); - - Response response = pipeliningBase.zintercard(limit, keys); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testZunionByteArray() { - ZParams params = new ZParams(); - byte[][] keys = { "zset1".getBytes(), "zset2".getBytes() }; - - when(commandObjects.zunion(params, keys)).thenReturn(listBytesCommandObject); - - Response> response = pipeliningBase.zunion(params, keys); - - assertThat(commands, contains(listBytesCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testZunionWithScoresByteArray() { - ZParams params = new ZParams(); - byte[][] keys = { "zset1".getBytes(), "zset2".getBytes() }; - - when(commandObjects.zunionWithScores(params, keys)).thenReturn(listTupleCommandObject); - - Response> response = pipeliningBase.zunionWithScores(params, keys); - - assertThat(commands, contains(listTupleCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testZunionstoreByteArray() { - byte[] dstkey = "destZset".getBytes(); - byte[][] sets = { "zset1".getBytes(), "zset2".getBytes() }; - - when(commandObjects.zunionstore(dstkey, sets)).thenReturn(longCommandObject); - - Response response = pipeliningBase.zunionstore(dstkey, sets); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testZunionstoreWithParamsByteArray() { - byte[] dstkey = "destZset".getBytes(); - ZParams params = new ZParams(); - byte[][] sets = { "zset1".getBytes(), "zset2".getBytes() }; - - when(commandObjects.zunionstore(dstkey, params, sets)).thenReturn(longCommandObject); - - Response response = pipeliningBase.zunionstore(dstkey, params, sets); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testXaddByteArray() { - byte[] key = "stream".getBytes(); - XAddParams params = new XAddParams(); - - Map hash = new HashMap<>(); - hash.put("field1".getBytes(), "value1".getBytes()); - - when(commandObjects.xadd(key, params, hash)).thenReturn(bytesCommandObject); - - Response response = pipeliningBase.xadd(key, params, hash); - - assertThat(commands, contains(bytesCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testXlenByteArray() { - byte[] key = "stream".getBytes(); - - when(commandObjects.xlen(key)).thenReturn(longCommandObject); - - Response response = pipeliningBase.xlen(key); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testXrangeByteArray() { - byte[] key = "stream".getBytes(); - byte[] start = "startId".getBytes(); - byte[] end = "endId".getBytes(); - - when(commandObjects.xrange(key, start, end)).thenReturn(listObjectCommandObject); - - Response> response = pipeliningBase.xrange(key, start, end); - - assertThat(commands, contains(listObjectCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testXrangeWithCountByteArray() { - byte[] key = "stream".getBytes(); - byte[] start = "startId".getBytes(); - byte[] end = "endId".getBytes(); - int count = 10; - - when(commandObjects.xrange(key, start, end, count)).thenReturn(listObjectCommandObject); - - Response> response = pipeliningBase.xrange(key, start, end, count); - - assertThat(commands, contains(listObjectCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testXrevrangeByteArray() { - byte[] key = "stream".getBytes(); - byte[] end = "endId".getBytes(); - byte[] start = "startId".getBytes(); - - when(commandObjects.xrevrange(key, end, start)).thenReturn(listObjectCommandObject); - - Response> response = pipeliningBase.xrevrange(key, end, start); - - assertThat(commands, contains(listObjectCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testXrevrangeWithCountByteArray() { - byte[] key = "stream".getBytes(); - byte[] end = "endId".getBytes(); - byte[] start = "startId".getBytes(); - int count = 10; - - when(commandObjects.xrevrange(key, end, start, count)).thenReturn(listObjectCommandObject); - - Response> response = pipeliningBase.xrevrange(key, end, start, count); - - assertThat(commands, contains(listObjectCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testXackByteArray() { - byte[] key = "stream".getBytes(); - byte[] group = "group".getBytes(); - byte[] id1 = "id1".getBytes(); - byte[] id2 = "id2".getBytes(); - - when(commandObjects.xack(key, group, id1, id2)).thenReturn(longCommandObject); - - Response response = pipeliningBase.xack(key, group, id1, id2); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testXgroupCreateByteArray() { - byte[] key = "stream".getBytes(); - byte[] groupName = "group".getBytes(); - byte[] id = "id".getBytes(); - boolean makeStream = true; - - when(commandObjects.xgroupCreate(key, groupName, id, makeStream)).thenReturn(stringCommandObject); - - Response response = pipeliningBase.xgroupCreate(key, groupName, id, makeStream); - - assertThat(commands, contains(stringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testXgroupSetIDByteArray() { - byte[] key = "stream".getBytes(); - byte[] groupName = "group".getBytes(); - byte[] id = "id".getBytes(); - - when(commandObjects.xgroupSetID(key, groupName, id)).thenReturn(stringCommandObject); - - Response response = pipeliningBase.xgroupSetID(key, groupName, id); - - assertThat(commands, contains(stringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testXgroupDestroyByteArray() { - byte[] key = "stream".getBytes(); - byte[] groupName = "group".getBytes(); - - when(commandObjects.xgroupDestroy(key, groupName)).thenReturn(longCommandObject); - - Response response = pipeliningBase.xgroupDestroy(key, groupName); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testXgroupCreateConsumerByteArray() { - byte[] key = "stream".getBytes(); - byte[] groupName = "group".getBytes(); - byte[] consumerName = "consumer".getBytes(); - - when(commandObjects.xgroupCreateConsumer(key, groupName, consumerName)).thenReturn(booleanCommandObject); - - Response response = pipeliningBase.xgroupCreateConsumer(key, groupName, consumerName); - - assertThat(commands, contains(booleanCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testXgroupDelConsumerByteArray() { - byte[] key = "stream".getBytes(); - byte[] groupName = "group".getBytes(); - byte[] consumerName = "consumer".getBytes(); - - when(commandObjects.xgroupDelConsumer(key, groupName, consumerName)).thenReturn(longCommandObject); - - Response response = pipeliningBase.xgroupDelConsumer(key, groupName, consumerName); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testXdelByteArray() { - byte[] key = "stream".getBytes(); - byte[] id1 = "id1".getBytes(); - byte[] id2 = "id2".getBytes(); - - when(commandObjects.xdel(key, id1, id2)).thenReturn(longCommandObject); - - Response response = pipeliningBase.xdel(key, id1, id2); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testXtrimByteArray() { - byte[] key = "stream".getBytes(); - long maxLen = 1000L; - boolean approximateLength = true; - - when(commandObjects.xtrim(key, maxLen, approximateLength)).thenReturn(longCommandObject); - - Response response = pipeliningBase.xtrim(key, maxLen, approximateLength); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testXtrimWithParamsByteArray() { - byte[] key = "stream".getBytes(); - XTrimParams params = new XTrimParams().maxLen(1000L); - - when(commandObjects.xtrim(key, params)).thenReturn(longCommandObject); - - Response response = pipeliningBase.xtrim(key, params); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testXpendingByteArray() { - byte[] key = "stream".getBytes(); - byte[] groupName = "group".getBytes(); - - when(commandObjects.xpending(key, groupName)).thenReturn(objectCommandObject); - - Response response = pipeliningBase.xpending(key, groupName); - - assertThat(commands, contains(objectCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testXpendingWithParamsByteArray() { - byte[] key = "stream".getBytes(); - byte[] groupName = "group".getBytes(); - XPendingParams params = new XPendingParams().count(10); - - when(commandObjects.xpending(key, groupName, params)).thenReturn(listObjectCommandObject); - - Response> response = pipeliningBase.xpending(key, groupName, params); - - assertThat(commands, contains(listObjectCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testXclaimByteArray() { - byte[] key = "stream".getBytes(); - byte[] group = "group".getBytes(); - byte[] consumerName = "consumer".getBytes(); - long minIdleTime = 10000L; - XClaimParams params = new XClaimParams(); - byte[] id1 = "id1".getBytes(); - byte[] id2 = "id2".getBytes(); - - when(commandObjects.xclaim(key, group, consumerName, minIdleTime, params, id1, id2)).thenReturn(listBytesCommandObject); - - Response> response = pipeliningBase.xclaim(key, group, consumerName, minIdleTime, params, id1, id2); - - assertThat(commands, contains(listBytesCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testXclaimJustIdByteArray() { - byte[] key = "stream".getBytes(); - byte[] group = "group".getBytes(); - byte[] consumerName = "consumer".getBytes(); - long minIdleTime = 10000L; - XClaimParams params = new XClaimParams(); - byte[] id1 = "id1".getBytes(); - byte[] id2 = "id2".getBytes(); - - when(commandObjects.xclaimJustId(key, group, consumerName, minIdleTime, params, id1, id2)).thenReturn(listBytesCommandObject); - - Response> response = pipeliningBase.xclaimJustId(key, group, consumerName, minIdleTime, params, id1, id2); - - assertThat(commands, contains(listBytesCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testXautoclaimByteArray() { - byte[] key = "stream".getBytes(); - byte[] groupName = "group".getBytes(); - byte[] consumerName = "consumer".getBytes(); - long minIdleTime = 10000L; - byte[] start = "startId".getBytes(); - XAutoClaimParams params = new XAutoClaimParams(); - - when(commandObjects.xautoclaim(key, groupName, consumerName, minIdleTime, start, params)).thenReturn(listObjectCommandObject); - - Response> response = pipeliningBase.xautoclaim(key, groupName, consumerName, minIdleTime, start, params); - - assertThat(commands, contains(listObjectCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testXautoclaimJustIdByteArray() { - byte[] key = "stream".getBytes(); - byte[] groupName = "group".getBytes(); - byte[] consumerName = "consumer".getBytes(); - long minIdleTime = 10000L; - byte[] start = "startId".getBytes(); - XAutoClaimParams params = new XAutoClaimParams(); - - when(commandObjects.xautoclaimJustId(key, groupName, consumerName, minIdleTime, start, params)).thenReturn(listObjectCommandObject); - - Response> response = pipeliningBase.xautoclaimJustId(key, groupName, consumerName, minIdleTime, start, params); - - assertThat(commands, contains(listObjectCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testXinfoStreamByteArray() { - byte[] key = "stream".getBytes(); - - when(commandObjects.xinfoStream(key)).thenReturn(objectCommandObject); - - Response response = pipeliningBase.xinfoStream(key); - - assertThat(commands, contains(objectCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testXinfoStreamFullByteArray() { - byte[] key = "stream".getBytes(); - - when(commandObjects.xinfoStreamFull(key)).thenReturn(objectCommandObject); - - Response response = pipeliningBase.xinfoStreamFull(key); - - assertThat(commands, contains(objectCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testXinfoStreamFullWithCountByteArray() { - byte[] key = "stream".getBytes(); - int count = 10; - - when(commandObjects.xinfoStreamFull(key, count)).thenReturn(objectCommandObject); - - Response response = pipeliningBase.xinfoStreamFull(key, count); - - assertThat(commands, contains(objectCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testXinfoGroupsByteArray() { - byte[] key = "stream".getBytes(); - - when(commandObjects.xinfoGroups(key)).thenReturn(listObjectCommandObject); - - Response> response = pipeliningBase.xinfoGroups(key); - - assertThat(commands, contains(listObjectCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testXinfoConsumersByteArray() { - byte[] key = "stream".getBytes(); - byte[] group = "group".getBytes(); - - when(commandObjects.xinfoConsumers(key, group)).thenReturn(listObjectCommandObject); - - Response> response = pipeliningBase.xinfoConsumers(key, group); - - assertThat(commands, contains(listObjectCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testXreadByteArray() { - XReadParams xReadParams = new XReadParams(); - Map.Entry stream1 = new AbstractMap.SimpleImmutableEntry<>("stream1".getBytes(), "id1".getBytes()); - - when(commandObjects.xread(xReadParams, stream1)).thenReturn(listObjectCommandObject); - - Response> response = pipeliningBase.xread(xReadParams, stream1); - - assertThat(commands, contains(listObjectCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testXreadGroupByteArray() { - byte[] groupName = "group".getBytes(); - byte[] consumer = "consumer".getBytes(); - XReadGroupParams xReadGroupParams = new XReadGroupParams(); - Map.Entry stream1 = new AbstractMap.SimpleImmutableEntry<>("stream1".getBytes(), "id1".getBytes()); - - when(commandObjects.xreadGroup(groupName, consumer, xReadGroupParams, stream1)).thenReturn(listObjectCommandObject); - - Response> response = pipeliningBase.xreadGroup(groupName, consumer, xReadGroupParams, stream1); - - assertThat(commands, contains(listObjectCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testSetByteArray() { - byte[] key = "key".getBytes(); - byte[] value = "value".getBytes(); - - when(commandObjects.set(key, value)).thenReturn(stringCommandObject); - - Response response = pipeliningBase.set(key, value); - - assertThat(commands, contains(stringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testSetWithParamsByteArray() { - byte[] key = "key".getBytes(); - byte[] value = "value".getBytes(); - SetParams params = new SetParams().nx().ex(10); - - when(commandObjects.set(key, value, params)).thenReturn(stringCommandObject); - - Response response = pipeliningBase.set(key, value, params); - - assertThat(commands, contains(stringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testGetByteArray() { - byte[] key = "key".getBytes(); - - when(commandObjects.get(key)).thenReturn(bytesCommandObject); - - Response response = pipeliningBase.get(key); - - assertThat(commands, contains(bytesCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testSetGetByteArray() { - byte[] key = "key".getBytes(); - byte[] value = "value".getBytes(); - - when(commandObjects.setGet(key, value)).thenReturn(bytesCommandObject); - - Response response = pipeliningBase.setGet(key, value); - - assertThat(commands, contains(bytesCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testSetGetWithParamsByteArray() { - byte[] key = "key".getBytes(); - byte[] value = "value".getBytes(); - SetParams params = new SetParams().nx().ex(10); - - when(commandObjects.setGet(key, value, params)).thenReturn(bytesCommandObject); - - Response response = pipeliningBase.setGet(key, value, params); - - assertThat(commands, contains(bytesCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testGetDelByteArray() { - byte[] key = "key".getBytes(); - - when(commandObjects.getDel(key)).thenReturn(bytesCommandObject); - - Response response = pipeliningBase.getDel(key); - - assertThat(commands, contains(bytesCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testGetExByteArray() { - byte[] key = "key".getBytes(); - GetExParams params = new GetExParams().ex(10); - - when(commandObjects.getEx(key, params)).thenReturn(bytesCommandObject); - - Response response = pipeliningBase.getEx(key, params); - - assertThat(commands, contains(bytesCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testSetbitByteArray() { - byte[] key = "key".getBytes(); - long offset = 10L; - boolean value = true; - - when(commandObjects.setbit(key, offset, value)).thenReturn(booleanCommandObject); - - Response response = pipeliningBase.setbit(key, offset, value); - - assertThat(commands, contains(booleanCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testGetbitByteArray() { - byte[] key = "key".getBytes(); - long offset = 10L; - - when(commandObjects.getbit(key, offset)).thenReturn(booleanCommandObject); - - Response response = pipeliningBase.getbit(key, offset); - - assertThat(commands, contains(booleanCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testSetrangeByteArray() { - byte[] key = "key".getBytes(); - long offset = 10L; - byte[] value = "value".getBytes(); - - when(commandObjects.setrange(key, offset, value)).thenReturn(longCommandObject); - - Response response = pipeliningBase.setrange(key, offset, value); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testGetrangeByteArray() { - byte[] key = "key".getBytes(); - long startOffset = 0L; - long endOffset = 10L; - - when(commandObjects.getrange(key, startOffset, endOffset)).thenReturn(bytesCommandObject); - - Response response = pipeliningBase.getrange(key, startOffset, endOffset); - - assertThat(commands, contains(bytesCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testGetSetByteArray() { - byte[] key = "key".getBytes(); - byte[] value = "value".getBytes(); - - when(commandObjects.getSet(key, value)).thenReturn(bytesCommandObject); - - Response response = pipeliningBase.getSet(key, value); - - assertThat(commands, contains(bytesCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testSetnxByteArray() { - byte[] key = "key".getBytes(); - byte[] value = "value".getBytes(); - - when(commandObjects.setnx(key, value)).thenReturn(longCommandObject); - - Response response = pipeliningBase.setnx(key, value); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testSetexByteArray() { - byte[] key = "key".getBytes(); - long seconds = 60L; - byte[] value = "value".getBytes(); - - when(commandObjects.setex(key, seconds, value)).thenReturn(stringCommandObject); - - Response response = pipeliningBase.setex(key, seconds, value); - - assertThat(commands, contains(stringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testPsetexByteArray() { - byte[] key = "key".getBytes(); - long milliseconds = 5000L; - byte[] value = "value".getBytes(); - - when(commandObjects.psetex(key, milliseconds, value)).thenReturn(stringCommandObject); - - Response response = pipeliningBase.psetex(key, milliseconds, value); - - assertThat(commands, contains(stringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testMgetByteArray() { - byte[] key1 = "key1".getBytes(); - byte[] key2 = "key2".getBytes(); - - when(commandObjects.mget(key1, key2)).thenReturn(listBytesCommandObject); - - Response> response = pipeliningBase.mget(key1, key2); - - assertThat(commands, contains(listBytesCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testMsetByteArray() { - byte[] key1 = "key1".getBytes(); - byte[] value1 = "value1".getBytes(); - byte[] key2 = "key2".getBytes(); - byte[] value2 = "value2".getBytes(); - - when(commandObjects.mset(key1, value1, key2, value2)).thenReturn(stringCommandObject); - - Response response = pipeliningBase.mset(key1, value1, key2, value2); - - assertThat(commands, contains(stringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testMsetnxByteArray() { - byte[] key1 = "key1".getBytes(); - byte[] value1 = "value1".getBytes(); - byte[] key2 = "key2".getBytes(); - byte[] value2 = "value2".getBytes(); - - when(commandObjects.msetnx(key1, value1, key2, value2)).thenReturn(longCommandObject); - - Response response = pipeliningBase.msetnx(key1, value1, key2, value2); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testIncrByteArray() { - byte[] key = "key".getBytes(); - - when(commandObjects.incr(key)).thenReturn(longCommandObject); - - Response response = pipeliningBase.incr(key); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testIncrByByteArray() { - byte[] key = "key".getBytes(); - long increment = 2L; - - when(commandObjects.incrBy(key, increment)).thenReturn(longCommandObject); - - Response response = pipeliningBase.incrBy(key, increment); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testIncrByFloatByteArray() { - byte[] key = "key".getBytes(); - double increment = 2.5; - - when(commandObjects.incrByFloat(key, increment)).thenReturn(doubleCommandObject); - - Response response = pipeliningBase.incrByFloat(key, increment); - - assertThat(commands, contains(doubleCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testDecrByteArray() { - byte[] key = "key".getBytes(); - - when(commandObjects.decr(key)).thenReturn(longCommandObject); - - Response response = pipeliningBase.decr(key); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testDecrByByteArray() { - byte[] key = "key".getBytes(); - long decrement = 2L; - - when(commandObjects.decrBy(key, decrement)).thenReturn(longCommandObject); - - Response response = pipeliningBase.decrBy(key, decrement); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testAppendByteArray() { - byte[] key = "key".getBytes(); - byte[] value = "value".getBytes(); - - when(commandObjects.append(key, value)).thenReturn(longCommandObject); - - Response response = pipeliningBase.append(key, value); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testSubstrByteArray() { - byte[] key = "key".getBytes(); - int start = 0; - int end = 5; - - when(commandObjects.substr(key, start, end)).thenReturn(bytesCommandObject); - - Response response = pipeliningBase.substr(key, start, end); - - assertThat(commands, contains(bytesCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testStrlenByteArray() { - byte[] key = "key".getBytes(); - - when(commandObjects.strlen(key)).thenReturn(longCommandObject); - - Response response = pipeliningBase.strlen(key); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testBitcountByteArray() { - byte[] key = "key".getBytes(); - - when(commandObjects.bitcount(key)).thenReturn(longCommandObject); - - Response response = pipeliningBase.bitcount(key); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testBitcountWithRangeByteArray() { - byte[] key = "key".getBytes(); - long start = 0L; - long end = 10L; - - when(commandObjects.bitcount(key, start, end)).thenReturn(longCommandObject); - - Response response = pipeliningBase.bitcount(key, start, end); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testBitcountWithRangeAndOptionByteArray() { - byte[] key = "key".getBytes(); - long start = 0L; - long end = 10L; - BitCountOption option = BitCountOption.BYTE; - - when(commandObjects.bitcount(key, start, end, option)).thenReturn(longCommandObject); - - Response response = pipeliningBase.bitcount(key, start, end, option); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testBitposByteArray() { - byte[] key = "key".getBytes(); - boolean value = true; - - when(commandObjects.bitpos(key, value)).thenReturn(longCommandObject); - - Response response = pipeliningBase.bitpos(key, value); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testBitposWithParamsByteArray() { - byte[] key = "key".getBytes(); - boolean value = true; - BitPosParams params = new BitPosParams(0); - - when(commandObjects.bitpos(key, value, params)).thenReturn(longCommandObject); - - Response response = pipeliningBase.bitpos(key, value, params); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testBitfieldByteArray() { - byte[] key = "key".getBytes(); - byte[] arguments = "INCRBY i5 100 1".getBytes(); - - when(commandObjects.bitfield(key, arguments)).thenReturn(listLongCommandObject); - - Response> response = pipeliningBase.bitfield(key, arguments); - - assertThat(commands, contains(listLongCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testBitfieldReadonlyByteArray() { - byte[] key = "key".getBytes(); - byte[] arguments = "GET i5 100".getBytes(); - - when(commandObjects.bitfieldReadonly(key, arguments)).thenReturn(listLongCommandObject); - - Response> response = pipeliningBase.bitfieldReadonly(key, arguments); - - assertThat(commands, contains(listLongCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testBitopByteArray() { - BitOP op = BitOP.AND; - byte[] destKey = "destKey".getBytes(); - byte[] srcKey1 = "srcKey1".getBytes(); - byte[] srcKey2 = "srcKey2".getBytes(); - - when(commandObjects.bitop(op, destKey, srcKey1, srcKey2)).thenReturn(longCommandObject); - - Response response = pipeliningBase.bitop(op, destKey, srcKey1, srcKey2); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testFtCreateByteArray() { - IndexOptions indexOptions = IndexOptions.defaultOptions(); - Schema schema = new Schema().addField(new Schema.Field("myField", Schema.FieldType.TEXT)); - - when(commandObjects.ftCreate("myIndex", indexOptions, schema)).thenReturn(stringCommandObject); - - Response response = pipeliningBase.ftCreate("myIndex", indexOptions, schema); - - assertThat(commands, contains(stringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testFtCreateWithParamsByteArray() { - FTCreateParams createParams = FTCreateParams.createParams(); - Iterable schemaFields = Collections.singletonList(new TextField("myField")); - - when(commandObjects.ftCreate("myIndex", createParams, schemaFields)).thenReturn(stringCommandObject); - - Response response = pipeliningBase.ftCreate("myIndex", createParams, schemaFields); - - assertThat(commands, contains(stringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testFtAlterByteArray() { - Schema schema = new Schema().addField(new Schema.Field("newField", Schema.FieldType.TEXT)); - - when(commandObjects.ftAlter("myIndex", schema)).thenReturn(stringCommandObject); - - Response response = pipeliningBase.ftAlter("myIndex", schema); - - assertThat(commands, contains(stringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testFtAlterWithFieldsByteArray() { - Iterable schemaFields = Collections.singletonList(new TextField("newField")); - - when(commandObjects.ftAlter("myIndex", schemaFields)).thenReturn(stringCommandObject); - - Response response = pipeliningBase.ftAlter("myIndex", schemaFields); - - assertThat(commands, contains(stringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testFtAliasAddByteArray() { - when(commandObjects.ftAliasAdd("myAlias", "myIndex")).thenReturn(stringCommandObject); - - Response response = pipeliningBase.ftAliasAdd("myAlias", "myIndex"); - - assertThat(commands, contains(stringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testFtAliasUpdateByteArray() { - when(commandObjects.ftAliasUpdate("myAlias", "myIndex")).thenReturn(stringCommandObject); - - Response response = pipeliningBase.ftAliasUpdate("myAlias", "myIndex"); - - assertThat(commands, contains(stringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testFtAliasDelByteArray() { - when(commandObjects.ftAliasDel("myAlias")).thenReturn(stringCommandObject); - - Response response = pipeliningBase.ftAliasDel("myAlias"); - - assertThat(commands, contains(stringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testFtDropIndexByteArray() { - when(commandObjects.ftDropIndex("myIndex")).thenReturn(stringCommandObject); - - Response response = pipeliningBase.ftDropIndex("myIndex"); - - assertThat(commands, contains(stringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testFtDropIndexDDByteArray() { - when(commandObjects.ftDropIndexDD("myIndex")).thenReturn(stringCommandObject); - - Response response = pipeliningBase.ftDropIndexDD("myIndex"); - - assertThat(commands, contains(stringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testFtSearchByteArray() { - String query = "hello world"; - - when(commandObjects.ftSearch("myIndex", query)).thenReturn(searchResultCommandObject); - - Response response = pipeliningBase.ftSearch("myIndex", query); - - assertThat(commands, contains(searchResultCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testFtSearchWithParamsByteArray() { - String query = "hello world"; - FTSearchParams searchParams = FTSearchParams.searchParams().limit(0, 10); - - when(commandObjects.ftSearch("myIndex", query, searchParams)).thenReturn(searchResultCommandObject); - - Response response = pipeliningBase.ftSearch("myIndex", query, searchParams); - - assertThat(commands, contains(searchResultCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testFtSearchWithQueryByteArray() { - Query query = new Query("hello world").limit(0, 10); - - when(commandObjects.ftSearch("myIndex", query)).thenReturn(searchResultCommandObject); - - Response response = pipeliningBase.ftSearch("myIndex", query); - - assertThat(commands, contains(searchResultCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testFtSearchWithQueryBytesByteArray() { - byte[] indexName = "myIndex".getBytes(); - Query query = new Query("hello world").limit(0, 10); - - when(commandObjects.ftSearch(indexName, query)).thenReturn(searchResultCommandObject); - - Response response = pipeliningBase.ftSearch(indexName, query); - - assertThat(commands, contains(searchResultCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testFtExplainByteArray() { - Query query = new Query("hello world"); - - when(commandObjects.ftExplain("myIndex", query)).thenReturn(stringCommandObject); - - Response response = pipeliningBase.ftExplain("myIndex", query); - - assertThat(commands, contains(stringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testFtExplainCLIByteArray() { - Query query = new Query("hello world"); - - when(commandObjects.ftExplainCLI("myIndex", query)).thenReturn(listStringCommandObject); - - Response> response = pipeliningBase.ftExplainCLI("myIndex", query); - - assertThat(commands, contains(listStringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testFtAggregateByteArray() { - AggregationBuilder aggr = new AggregationBuilder().groupBy("@field"); - - when(commandObjects.ftAggregate("myIndex", aggr)).thenReturn(aggregationResultCommandObject); - - Response response = pipeliningBase.ftAggregate("myIndex", aggr); - - assertThat(commands, contains(aggregationResultCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testFtSynUpdateByteArray() { - String synonymGroupId = "group1"; - String[] terms = { "term1", "term2" }; - - when(commandObjects.ftSynUpdate("myIndex", synonymGroupId, terms)).thenReturn(stringCommandObject); - - Response response = pipeliningBase.ftSynUpdate("myIndex", synonymGroupId, terms); - - assertThat(commands, contains(stringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testFtSynDump() { - when(commandObjects.ftSynDump("myIndex")).thenReturn(mapStringListStringCommandObject); - - Response>> response = pipeliningBase.ftSynDump("myIndex"); - - assertThat(commands, contains(mapStringListStringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testFtDictAdd() { - String[] terms = { "term1", "term2" }; - - when(commandObjects.ftDictAdd("myDict", terms)).thenReturn(longCommandObject); - - Response response = pipeliningBase.ftDictAdd("myDict", terms); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testFtDictDel() { - String[] terms = { "term1", "term2" }; - - when(commandObjects.ftDictDel("myDict", terms)).thenReturn(longCommandObject); - - Response response = pipeliningBase.ftDictDel("myDict", terms); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testFtDictDump() { - when(commandObjects.ftDictDump("myDict")).thenReturn(setStringCommandObject); - - Response> response = pipeliningBase.ftDictDump("myDict"); - - assertThat(commands, contains(setStringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testFtDictAddBySampleKey() { - String[] terms = { "term1", "term2" }; - - when(commandObjects.ftDictAddBySampleKey("myIndex", "myDict", terms)).thenReturn(longCommandObject); - - Response response = pipeliningBase.ftDictAddBySampleKey("myIndex", "myDict", terms); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testFtDictDelBySampleKey() { - String[] terms = { "term1", "term2" }; - - when(commandObjects.ftDictDelBySampleKey("myIndex", "myDict", terms)).thenReturn(longCommandObject); - - Response response = pipeliningBase.ftDictDelBySampleKey("myIndex", "myDict", terms); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testFtDictDumpBySampleKey() { - when(commandObjects.ftDictDumpBySampleKey("myIndex", "myDict")).thenReturn(setStringCommandObject); - - Response> response = pipeliningBase.ftDictDumpBySampleKey("myIndex", "myDict"); - - assertThat(commands, contains(setStringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testFtSpellCheck() { - String query = "hello world"; - - when(commandObjects.ftSpellCheck("myIndex", query)).thenReturn(mapStringMapStringDoubleCommandObject); - - Response>> response = pipeliningBase.ftSpellCheck("myIndex", query); - - assertThat(commands, contains(mapStringMapStringDoubleCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testFtSpellCheckWithParams() { - String query = "hello world"; - FTSpellCheckParams spellCheckParams = new FTSpellCheckParams().distance(1); - - when(commandObjects.ftSpellCheck("myIndex", query, spellCheckParams)).thenReturn(mapStringMapStringDoubleCommandObject); - - Response>> response = pipeliningBase.ftSpellCheck("myIndex", query, spellCheckParams); - - assertThat(commands, contains(mapStringMapStringDoubleCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testFtInfo() { - when(commandObjects.ftInfo("myIndex")).thenReturn(mapStringObjectCommandObject); - - Response> response = pipeliningBase.ftInfo("myIndex"); - - assertThat(commands, contains(mapStringObjectCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testFtTagVals() { - when(commandObjects.ftTagVals("myIndex", "myField")).thenReturn(setStringCommandObject); - - Response> response = pipeliningBase.ftTagVals("myIndex", "myField"); - - assertThat(commands, contains(setStringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testFtConfigGet() { - when(commandObjects.ftConfigGet("TIMEOUT")).thenReturn(mapStringObjectCommandObject); - - Response> response = pipeliningBase.ftConfigGet("TIMEOUT"); - - assertThat(commands, contains(mapStringObjectCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testFtConfigGetWithIndexName() { - when(commandObjects.ftConfigGet("myIndex", "TIMEOUT")).thenReturn(mapStringObjectCommandObject); - - Response> response = pipeliningBase.ftConfigGet("myIndex", "TIMEOUT"); - - assertThat(commands, contains(mapStringObjectCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testFtConfigSet() { - when(commandObjects.ftConfigSet("TIMEOUT", "100")).thenReturn(stringCommandObject); - - Response response = pipeliningBase.ftConfigSet("TIMEOUT", "100"); - - assertThat(commands, contains(stringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testFtConfigSetWithIndexName() { - when(commandObjects.ftConfigSet("myIndex", "TIMEOUT", "100")).thenReturn(stringCommandObject); - - Response response = pipeliningBase.ftConfigSet("myIndex", "TIMEOUT", "100"); - - assertThat(commands, contains(stringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testFtSugAdd() { - when(commandObjects.ftSugAdd("mySug", "hello", 1.0)).thenReturn(longCommandObject); - - Response response = pipeliningBase.ftSugAdd("mySug", "hello", 1.0); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testFtSugAddIncr() { - when(commandObjects.ftSugAddIncr("mySug", "hello", 1.0)).thenReturn(longCommandObject); - - Response response = pipeliningBase.ftSugAddIncr("mySug", "hello", 1.0); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testFtSugGet() { - when(commandObjects.ftSugGet("mySug", "he")).thenReturn(listStringCommandObject); - - Response> response = pipeliningBase.ftSugGet("mySug", "he"); - - assertThat(commands, contains(listStringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testFtSugGetWithFuzzyAndMax() { - when(commandObjects.ftSugGet("mySug", "he", true, 10)).thenReturn(listStringCommandObject); - - Response> response = pipeliningBase.ftSugGet("mySug", "he", true, 10); - - assertThat(commands, contains(listStringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testFtSugGetWithScores() { - when(commandObjects.ftSugGetWithScores("mySug", "he")).thenReturn(listTupleCommandObject); - - Response> response = pipeliningBase.ftSugGetWithScores("mySug", "he"); - - assertThat(commands, contains(listTupleCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testFtSugGetWithScoresFuzzyMax() { - when(commandObjects.ftSugGetWithScores("mySug", "he", true, 10)).thenReturn(listTupleCommandObject); - - Response> response = pipeliningBase.ftSugGetWithScores("mySug", "he", true, 10); - - assertThat(commands, contains(listTupleCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testFtSugDel() { - when(commandObjects.ftSugDel("mySug", "hello")).thenReturn(booleanCommandObject); - - Response response = pipeliningBase.ftSugDel("mySug", "hello"); - - assertThat(commands, contains(booleanCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testFtSugLen() { - when(commandObjects.ftSugLen("mySug")).thenReturn(longCommandObject); - - Response response = pipeliningBase.ftSugLen("mySug"); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testLcsByteArray() { - byte[] keyA = "keyA".getBytes(); - byte[] keyB = "keyB".getBytes(); - LCSParams params = new LCSParams().withMatchLen(); - - when(commandObjects.lcs(keyA, keyB, params)).thenReturn(lcsMatchResultCommandObject); - - Response response = pipeliningBase.lcs(keyA, keyB, params); - - assertThat(commands, contains(lcsMatchResultCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testJsonSet() { - Path2 path = Path2.of("$.field"); - Object object = new JsonObject(); - - when(commandObjects.jsonSet("myJson", path, object)).thenReturn(stringCommandObject); - - Response response = pipeliningBase.jsonSet("myJson", path, object); - - assertThat(commands, contains(stringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testJsonSetWithEscape() { - Path2 path = Path2.of("$.field"); - Object object = new JsonObject(); - - when(commandObjects.jsonSetWithEscape("myJson", path, object)).thenReturn(stringCommandObject); - - Response response = pipeliningBase.jsonSetWithEscape("myJson", path, object); - - assertThat(commands, contains(stringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testJsonSetOldPath() { - Path path = Path.of("$.field"); - Object object = new JsonObject(); - - when(commandObjects.jsonSet("myJson", path, object)).thenReturn(stringCommandObject); - - Response response = pipeliningBase.jsonSet("myJson", path, object); - - assertThat(commands, contains(stringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testJsonSetWithParams() { - Path2 path = Path2.of("$.field"); - Object object = new JsonObject(); - JsonSetParams params = new JsonSetParams().nx(); - - when(commandObjects.jsonSet("myJson", path, object, params)).thenReturn(stringCommandObject); - - Response response = pipeliningBase.jsonSet("myJson", path, object, params); - - assertThat(commands, contains(stringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testJsonSetWithEscapeAndParams() { - Path2 path = Path2.of("$.field"); - Object object = new JsonObject(); - JsonSetParams params = new JsonSetParams().nx(); - - when(commandObjects.jsonSetWithEscape("myJson", path, object, params)).thenReturn(stringCommandObject); - - Response response = pipeliningBase.jsonSetWithEscape("myJson", path, object, params); - - assertThat(commands, contains(stringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testJsonSetWithPathAndParams() { - Path path = new Path("$.field"); - Object object = new JsonObject(); - JsonSetParams params = new JsonSetParams().nx(); - - when(commandObjects.jsonSet("myJson", path, object, params)).thenReturn(stringCommandObject); - - Response response = pipeliningBase.jsonSet("myJson", path, object, params); - - assertThat(commands, contains(stringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testJsonMergeWithPath2() { - Path2 path = Path2.of("$.field"); - Object object = new JsonObject(); - - when(commandObjects.jsonMerge("myJson", path, object)).thenReturn(stringCommandObject); - - Response response = pipeliningBase.jsonMerge("myJson", path, object); - - assertThat(commands, contains(stringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testJsonMergeWithPath() { - Path path = new Path("$.field"); - Object object = new JsonObject(); - - when(commandObjects.jsonMerge("myJson", path, object)).thenReturn(stringCommandObject); - - Response response = pipeliningBase.jsonMerge("myJson", path, object); - - assertThat(commands, contains(stringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testJsonGet() { - when(commandObjects.jsonGet("myJson")).thenReturn(objectCommandObject); - - Response response = pipeliningBase.jsonGet("myJson"); - - assertThat(commands, contains(objectCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testJsonGetWithClass() { - when(commandObjects.jsonGet("myJson", MyBean.class)).thenReturn(myBeanCommandObject); - - Response response = pipeliningBase.jsonGet("myJson", MyBean.class); - - assertThat(commands, contains(myBeanCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testJsonGetWithPaths2() { - Path2[] paths = { Path2.of("$.field1"), Path2.of("$.field2") }; - - when(commandObjects.jsonGet("myJson", paths)).thenReturn(objectCommandObject); - - Response response = pipeliningBase.jsonGet("myJson", paths); - - assertThat(commands, contains(objectCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testJsonGetWithPaths() { - Path[] paths = { new Path("$.field1"), new Path("$.field2") }; - - when(commandObjects.jsonGet("myJson", paths)).thenReturn(objectCommandObject); - - Response response = pipeliningBase.jsonGet("myJson", paths); - - assertThat(commands, contains(objectCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testJsonGetWithClassAndPaths() { - Path[] paths = { new Path("$.field1"), new Path("$.field2") }; - - when(commandObjects.jsonGet("myJson", MyBean.class, paths)).thenReturn(myBeanCommandObject); - - Response response = pipeliningBase.jsonGet("myJson", MyBean.class, paths); - - assertThat(commands, contains(myBeanCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testJsonMGetWithPath2() { - Path2 path = Path2.of("$.field"); - - when(commandObjects.jsonMGet(path, "key1", "key2")).thenReturn(listJsonArrayCommandObject); - - Response> response = pipeliningBase.jsonMGet(path, "key1", "key2"); - - assertThat(commands, contains(listJsonArrayCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testJsonMGetWithPathAndClass() { - Path path = new Path("$.field"); - - when(commandObjects.jsonMGet(path, MyBean.class, "key1", "key2")).thenReturn(listMyBeanCommandObject); - - Response> response = pipeliningBase.jsonMGet(path, MyBean.class, "key1", "key2"); - - assertThat(commands, contains(listMyBeanCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testJsonDelWithKey() { - when(commandObjects.jsonDel("myJson")).thenReturn(longCommandObject); - - Response response = pipeliningBase.jsonDel("myJson"); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testJsonDelWithKeyAndPath2() { - Path2 path = Path2.of("$.field"); - - when(commandObjects.jsonDel("myJson", path)).thenReturn(longCommandObject); - - Response response = pipeliningBase.jsonDel("myJson", path); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testJsonDelWithKeyAndPath() { - Path path = new Path("$.field"); - - when(commandObjects.jsonDel("myJson", path)).thenReturn(longCommandObject); - - Response response = pipeliningBase.jsonDel("myJson", path); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testJsonClearWithKey() { - when(commandObjects.jsonClear("myJson")).thenReturn(longCommandObject); - - Response response = pipeliningBase.jsonClear("myJson"); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testJsonClearWithKeyAndPath2() { - Path2 path = Path2.of("$.field"); - - when(commandObjects.jsonClear("myJson", path)).thenReturn(longCommandObject); - - Response response = pipeliningBase.jsonClear("myJson", path); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testJsonClearWithKeyAndPath() { - Path path = new Path("$.field"); - - when(commandObjects.jsonClear("myJson", path)).thenReturn(longCommandObject); - - Response response = pipeliningBase.jsonClear("myJson", path); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testJsonToggleWithPath2() { - Path2 path = Path2.of("$.field"); - - when(commandObjects.jsonToggle("myJson", path)).thenReturn(listBooleanCommandObject); - - Response> response = pipeliningBase.jsonToggle("myJson", path); - - assertThat(commands, contains(listBooleanCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testJsonToggleWithPath() { - Path path = new Path("$.field"); - - when(commandObjects.jsonToggle("myJson", path)).thenReturn(stringCommandObject); - - Response response = pipeliningBase.jsonToggle("myJson", path); - - assertThat(commands, contains(stringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testJsonTypeWithKey() { - when(commandObjects.jsonType("myJson")).thenReturn(classCommandObject); - - Response> response = pipeliningBase.jsonType("myJson"); - - assertThat(commands, contains(classCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testJsonTypeWithKeyAndPath2() { - Path2 path = Path2.of("$.field"); - - when(commandObjects.jsonType("myJson", path)).thenReturn(listClassCommandObject); - - Response>> response = pipeliningBase.jsonType("myJson", path); - - assertThat(commands, contains(listClassCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testJsonTypeWithKeyAndPath() { - Path path = new Path("$.field"); - - when(commandObjects.jsonType("myJson", path)).thenReturn(classCommandObject); - - Response> response = pipeliningBase.jsonType("myJson", path); - - assertThat(commands, contains(classCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testJsonStrAppendWithKey() { - when(commandObjects.jsonStrAppend("myJson", "append")).thenReturn(longCommandObject); - - Response response = pipeliningBase.jsonStrAppend("myJson", "append"); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testJsonStrAppendWithKeyAndPath2() { - Path2 path = Path2.of("$.field"); - - when(commandObjects.jsonStrAppend("myJson", path, "append")).thenReturn(listLongCommandObject); - - Response> response = pipeliningBase.jsonStrAppend("myJson", path, "append"); - - assertThat(commands, contains(listLongCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testJsonStrAppendWithKeyAndPath() { - Path path = new Path("$.field"); - - when(commandObjects.jsonStrAppend("myJson", path, "append")).thenReturn(longCommandObject); - - Response response = pipeliningBase.jsonStrAppend("myJson", path, "append"); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testJsonStrLenWithKey() { - when(commandObjects.jsonStrLen("myJson")).thenReturn(longCommandObject); - - Response response = pipeliningBase.jsonStrLen("myJson"); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testJsonStrLenWithKeyAndPath2() { - Path2 path = Path2.of("$.field"); - - when(commandObjects.jsonStrLen("myJson", path)).thenReturn(listLongCommandObject); - - Response> response = pipeliningBase.jsonStrLen("myJson", path); - - assertThat(commands, contains(listLongCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testJsonStrLenWithKeyAndPath() { - Path path = new Path("$.field"); - - when(commandObjects.jsonStrLen("myJson", path)).thenReturn(longCommandObject); - - Response response = pipeliningBase.jsonStrLen("myJson", path); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testJsonNumIncrByWithPath2() { - Path2 path = Path2.of("$.number"); - - when(commandObjects.jsonNumIncrBy("myJson", path, 42.0)).thenReturn(objectCommandObject); - - Response response = pipeliningBase.jsonNumIncrBy("myJson", path, 42.0); - - assertThat(commands, contains(objectCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testJsonNumIncrByWithPath() { - Path path = new Path("$.number"); - - when(commandObjects.jsonNumIncrBy("myJson", path, 42.0)).thenReturn(doubleCommandObject); - - Response response = pipeliningBase.jsonNumIncrBy("myJson", path, 42.0); - - assertThat(commands, contains(doubleCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testJsonArrAppendWithPath2() { - Path2 path = Path2.of("$.array"); - Object[] objects = { "one", "two", "three" }; - - when(commandObjects.jsonArrAppend("myJson", path, objects)).thenReturn(listLongCommandObject); - - Response> response = pipeliningBase.jsonArrAppend("myJson", path, objects); - - assertThat(commands, contains(listLongCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testJsonArrAppendWithPath2WithEscape() { - Path2 path = Path2.of("$.array"); - Object[] objects = { "one", "two", "three" }; - - when(commandObjects.jsonArrAppendWithEscape("myJson", path, objects)).thenReturn(listLongCommandObject); - - Response> response = pipeliningBase.jsonArrAppendWithEscape("myJson", path, objects); - - assertThat(commands, contains(listLongCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testJsonArrAppendWithPath() { - Path path = new Path("$.array"); - Object[] objects = { "one", "two", "three" }; - - when(commandObjects.jsonArrAppend("myJson", path, objects)).thenReturn(longCommandObject); - - Response response = pipeliningBase.jsonArrAppend("myJson", path, objects); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testJsonArrIndexWithPath2() { - Path2 path = Path2.of("$.array"); - Object scalar = "two"; - - when(commandObjects.jsonArrIndex("myJson", path, scalar)).thenReturn(listLongCommandObject); - - Response> response = pipeliningBase.jsonArrIndex("myJson", path, scalar); - - assertThat(commands, contains(listLongCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testJsonArrIndexWithPath2WithEscape() { - Path2 path = Path2.of("$.array"); - Object scalar = "two"; - - when(commandObjects.jsonArrIndexWithEscape("myJson", path, scalar)).thenReturn(listLongCommandObject); - - Response> response = pipeliningBase.jsonArrIndexWithEscape("myJson", path, scalar); - - assertThat(commands, contains(listLongCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testJsonArrIndexWithPath() { - Path path = new Path("$.array"); - Object scalar = "two"; - - when(commandObjects.jsonArrIndex("myJson", path, scalar)).thenReturn(longCommandObject); - - Response response = pipeliningBase.jsonArrIndex("myJson", path, scalar); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testJsonArrInsertWithPath2() { - Path2 path = Path2.of("$.array"); - Object[] objects = { "one", "two", "three" }; - - when(commandObjects.jsonArrInsert("myJson", path, 1, objects)).thenReturn(listLongCommandObject); - - Response> response = pipeliningBase.jsonArrInsert("myJson", path, 1, objects); - - assertThat(commands, contains(listLongCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testJsonArrInsertWithPath2WithEscape() { - Path2 path = Path2.of("$.array"); - Object[] objects = { "one", "two", "three" }; - - when(commandObjects.jsonArrInsertWithEscape("myJson", path, 1, objects)).thenReturn(listLongCommandObject); - - Response> response = pipeliningBase.jsonArrInsertWithEscape("myJson", path, 1, objects); - - assertThat(commands, contains(listLongCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testJsonArrInsertWithPath() { - Path path = new Path("$.array"); - Object[] pojos = { "one", "two", "three" }; - - when(commandObjects.jsonArrInsert("myJson", path, 1, pojos)).thenReturn(longCommandObject); - - Response response = pipeliningBase.jsonArrInsert("myJson", path, 1, pojos); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testJsonArrPopWithKey() { - when(commandObjects.jsonArrPop("myJson")).thenReturn(objectCommandObject); - - Response response = pipeliningBase.jsonArrPop("myJson"); - - assertThat(commands, contains(objectCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testJsonArrLenWithKeyAndPath() { - Path path = new Path("$.array"); - - when(commandObjects.jsonArrLen("myJson", path)).thenReturn(longCommandObject); - - Response response = pipeliningBase.jsonArrLen("myJson", path); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testJsonArrTrimWithPath2() { - Path2 path = Path2.of("$.array"); - - when(commandObjects.jsonArrTrim("myJson", path, 1, 2)).thenReturn(listLongCommandObject); - - Response> response = pipeliningBase.jsonArrTrim("myJson", path, 1, 2); - - assertThat(commands, contains(listLongCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testJsonArrTrimWithPath() { - Path path = new Path("$.array"); - - when(commandObjects.jsonArrTrim("myJson", path, 1, 2)).thenReturn(longCommandObject); - - Response response = pipeliningBase.jsonArrTrim("myJson", path, 1, 2); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testJsonArrPopWithKeyClassAndPath() { - Path path = new Path("$.array"); - - when(commandObjects.jsonArrPop("myJson", MyBean.class, path)).thenReturn(myBeanCommandObject); - - Response response = pipeliningBase.jsonArrPop("myJson", MyBean.class, path); - - assertThat(commands, contains(myBeanCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testJsonArrPopWithKeyPath2AndIndex() { - Path2 path = Path2.of("$.array"); - - when(commandObjects.jsonArrPop("myJson", path, 1)).thenReturn(listObjectCommandObject); - - Response> response = pipeliningBase.jsonArrPop("myJson", path, 1); - - assertThat(commands, contains(listObjectCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testJsonArrPopWithKeyPathAndIndex() { - Path path = new Path("$.array"); - - when(commandObjects.jsonArrPop("myJson", path, 1)).thenReturn(objectCommandObject); - - Response response = pipeliningBase.jsonArrPop("myJson", path, 1); - - assertThat(commands, contains(objectCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testJsonArrPopWithKeyClassPathAndIndex() { - Path path = new Path("$.array"); - - when(commandObjects.jsonArrPop("myJson", MyBean.class, path, 1)).thenReturn(myBeanCommandObject); - - Response response = pipeliningBase.jsonArrPop("myJson", MyBean.class, path, 1); - - assertThat(commands, contains(myBeanCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testJsonArrLenWithKey() { - when(commandObjects.jsonArrLen("myJson")).thenReturn(longCommandObject); - - Response response = pipeliningBase.jsonArrLen("myJson"); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testJsonArrLenWithKeyAndPath2() { - Path2 path = Path2.of("$.array"); - - when(commandObjects.jsonArrLen("myJson", path)).thenReturn(listLongCommandObject); - - Response> response = pipeliningBase.jsonArrLen("myJson", path); - - assertThat(commands, contains(listLongCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testJsonArrPopWithKeyAndClass() { - when(commandObjects.jsonArrPop("myJson", MyBean.class)).thenReturn(myBeanCommandObject); - - Response response = pipeliningBase.jsonArrPop("myJson", MyBean.class); - - assertThat(commands, contains(myBeanCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testJsonArrPopWithKeyAndPath2() { - Path2 path = Path2.of("$.array"); - - when(commandObjects.jsonArrPop("myJson", path)).thenReturn(listObjectCommandObject); - - Response> response = pipeliningBase.jsonArrPop("myJson", path); - - assertThat(commands, contains(listObjectCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testJsonArrPopWithKeyAndPath() { - Path path = new Path("$.array"); - - when(commandObjects.jsonArrPop("myJson", path)).thenReturn(objectCommandObject); - - Response response = pipeliningBase.jsonArrPop("myJson", path); - - assertThat(commands, contains(objectCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testTsCreate() { - when(commandObjects.tsCreate("myTimeSeries")).thenReturn(stringCommandObject); - - Response response = pipeliningBase.tsCreate("myTimeSeries"); - - assertThat(commands, contains(stringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testTsCreateWithParams() { - TSCreateParams createParams = TSCreateParams.createParams(); - - when(commandObjects.tsCreate("myTimeSeries", createParams)).thenReturn(stringCommandObject); - - Response response = pipeliningBase.tsCreate("myTimeSeries", createParams); - - assertThat(commands, contains(stringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testTsDel() { - when(commandObjects.tsDel("myTimeSeries", 1000L, 2000L)).thenReturn(longCommandObject); - - Response response = pipeliningBase.tsDel("myTimeSeries", 1000L, 2000L); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testTsAlter() { - TSAlterParams alterParams = TSAlterParams.alterParams(); - - when(commandObjects.tsAlter("myTimeSeries", alterParams)).thenReturn(stringCommandObject); - - Response response = pipeliningBase.tsAlter("myTimeSeries", alterParams); - - assertThat(commands, contains(stringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testTsAdd() { - when(commandObjects.tsAdd("myTimeSeries", 42.0)).thenReturn(longCommandObject); - - Response response = pipeliningBase.tsAdd("myTimeSeries", 42.0); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testTsAddWithTimestamp() { - when(commandObjects.tsAdd("myTimeSeries", 1000L, 42.0)).thenReturn(longCommandObject); - - Response response = pipeliningBase.tsAdd("myTimeSeries", 1000L, 42.0); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testTsAddWithTimestampAndParams() { - TSCreateParams createParams = TSCreateParams.createParams(); - - when(commandObjects.tsAdd("myTimeSeries", 1000L, 42.0, createParams)).thenReturn(longCommandObject); - - Response response = pipeliningBase.tsAdd("myTimeSeries", 1000L, 42.0, createParams); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testTsMAdd() { - Map.Entry entry1 = new AbstractMap.SimpleEntry<>("ts1", new TSElement(1000L, 1.0)); - Map.Entry entry2 = new AbstractMap.SimpleEntry<>("ts2", new TSElement(2000L, 2.0)); - - when(commandObjects.tsMAdd(entry1, entry2)).thenReturn(listLongCommandObject); - - Response> response = pipeliningBase.tsMAdd(entry1, entry2); - - assertThat(commands, contains(listLongCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testTsIncrBy() { - when(commandObjects.tsIncrBy("myTimeSeries", 1.0)).thenReturn(longCommandObject); - - Response response = pipeliningBase.tsIncrBy("myTimeSeries", 1.0); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testTsIncrByWithTimestamp() { - when(commandObjects.tsIncrBy("myTimeSeries", 1.0, 1000L)).thenReturn(longCommandObject); - - Response response = pipeliningBase.tsIncrBy("myTimeSeries", 1.0, 1000L); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testTsDecrBy() { - when(commandObjects.tsDecrBy("myTimeSeries", 1.0)).thenReturn(longCommandObject); - - Response response = pipeliningBase.tsDecrBy("myTimeSeries", 1.0); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testTsDecrByWithTimestamp() { - when(commandObjects.tsDecrBy("myTimeSeries", 1.0, 1000L)).thenReturn(longCommandObject); - - Response response = pipeliningBase.tsDecrBy("myTimeSeries", 1.0, 1000L); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testTsRange() { - when(commandObjects.tsRange("myTimeSeries", 1000L, 2000L)).thenReturn(listTsElementCommandObject); - - Response> response = pipeliningBase.tsRange("myTimeSeries", 1000L, 2000L); - - assertThat(commands, contains(listTsElementCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testTsRangeWithParams() { - TSRangeParams rangeParams = TSRangeParams.rangeParams(); - - when(commandObjects.tsRange("myTimeSeries", rangeParams)).thenReturn(listTsElementCommandObject); - - Response> response = pipeliningBase.tsRange("myTimeSeries", rangeParams); - - assertThat(commands, contains(listTsElementCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testTsRevRange() { - when(commandObjects.tsRevRange("myTimeSeries", 1000L, 2000L)).thenReturn(listTsElementCommandObject); - - Response> response = pipeliningBase.tsRevRange("myTimeSeries", 1000L, 2000L); - - assertThat(commands, contains(listTsElementCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testTsRevRangeWithParams() { - TSRangeParams rangeParams = TSRangeParams.rangeParams(); - - when(commandObjects.tsRevRange("myTimeSeries", rangeParams)).thenReturn(listTsElementCommandObject); - - Response> response = pipeliningBase.tsRevRange("myTimeSeries", rangeParams); - - assertThat(commands, contains(listTsElementCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testTsMRange() { - String[] filters = { "sensor_id=123" }; - - when(commandObjects.tsMRange(1000L, 2000L, filters)).thenReturn(mapStringTsmRangeElementsCommandObject); - - Response> response = pipeliningBase.tsMRange(1000L, 2000L, filters); - - assertThat(commands, contains(mapStringTsmRangeElementsCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testTsMRangeWithParams() { - TSMRangeParams multiRangeParams = TSMRangeParams.multiRangeParams(); - - when(commandObjects.tsMRange(multiRangeParams)).thenReturn(mapStringTsmRangeElementsCommandObject); - - Response> response = pipeliningBase.tsMRange(multiRangeParams); - - assertThat(commands, contains(mapStringTsmRangeElementsCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testTsMRevRange() { - String[] filters = { "sensor_id=123" }; - - when(commandObjects.tsMRevRange(1000L, 2000L, filters)).thenReturn(mapStringTsmRangeElementsCommandObject); - - Response> response = pipeliningBase.tsMRevRange(1000L, 2000L, filters); - - assertThat(commands, contains(mapStringTsmRangeElementsCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testTsMRevRangeWithParams() { - TSMRangeParams multiRangeParams = TSMRangeParams.multiRangeParams(); - - when(commandObjects.tsMRevRange(multiRangeParams)).thenReturn(mapStringTsmRangeElementsCommandObject); - - Response> response = pipeliningBase.tsMRevRange(multiRangeParams); - - assertThat(commands, contains(mapStringTsmRangeElementsCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testTsGet() { - when(commandObjects.tsGet("myTimeSeries")).thenReturn(tsElementCommandObject); - - Response response = pipeliningBase.tsGet("myTimeSeries"); - - assertThat(commands, contains(tsElementCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testTsGetWithParams() { - TSGetParams getParams = TSGetParams.getParams(); - - when(commandObjects.tsGet("myTimeSeries", getParams)).thenReturn(tsElementCommandObject); - - Response response = pipeliningBase.tsGet("myTimeSeries", getParams); - - assertThat(commands, contains(tsElementCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testTsMGet() { - TSMGetParams multiGetParams = TSMGetParams.multiGetParams(); - String[] filters = { "sensor_id=123" }; - - when(commandObjects.tsMGet(multiGetParams, filters)).thenReturn(mapStringTsmGetElementCommandObject); - - Response> response = pipeliningBase.tsMGet(multiGetParams, filters); - - assertThat(commands, contains(mapStringTsmGetElementCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testTsCreateRule() { - AggregationType aggregationType = AggregationType.AVG; - long timeBucket = 60; - - when(commandObjects.tsCreateRule("sourceTimeSeries", "destTimeSeries", aggregationType, timeBucket)).thenReturn(stringCommandObject); - - Response response = pipeliningBase.tsCreateRule("sourceTimeSeries", "destTimeSeries", aggregationType, timeBucket); - - assertThat(commands, contains(stringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testTsCreateRuleWithAlignTimestamp() { - AggregationType aggregationType = AggregationType.AVG; - long bucketDuration = 60; - long alignTimestamp = 0; - - when(commandObjects.tsCreateRule("sourceTimeSeries", "destTimeSeries", aggregationType, bucketDuration, alignTimestamp)).thenReturn(stringCommandObject); - - Response response = pipeliningBase.tsCreateRule("sourceTimeSeries", "destTimeSeries", aggregationType, bucketDuration, alignTimestamp); - - assertThat(commands, contains(stringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testTsDeleteRule() { - when(commandObjects.tsDeleteRule("sourceTimeSeries", "destTimeSeries")).thenReturn(stringCommandObject); - - Response response = pipeliningBase.tsDeleteRule("sourceTimeSeries", "destTimeSeries"); - - assertThat(commands, contains(stringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testTsQueryIndex() { - String[] filters = { "sensor_id=123" }; - - when(commandObjects.tsQueryIndex(filters)).thenReturn(listStringCommandObject); - - Response> response = pipeliningBase.tsQueryIndex(filters); - - assertThat(commands, contains(listStringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testBfReserve() { - double errorRate = 0.01; - long capacity = 10000L; - - when(commandObjects.bfReserve("myBloomFilter", errorRate, capacity)).thenReturn(stringCommandObject); - - Response response = pipeliningBase.bfReserve("myBloomFilter", errorRate, capacity); - - assertThat(commands, contains(stringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testBfReserveWithParams() { - double errorRate = 0.01; - long capacity = 10000L; - - BFReserveParams reserveParams = new BFReserveParams().expansion(2); - when(commandObjects.bfReserve("myBloomFilter", errorRate, capacity, reserveParams)).thenReturn(stringCommandObject); - - Response response = pipeliningBase.bfReserve("myBloomFilter", errorRate, capacity, reserveParams); - - assertThat(commands, contains(stringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testBfAdd() { - when(commandObjects.bfAdd("myBloomFilter", "item1")).thenReturn(booleanCommandObject); - - Response response = pipeliningBase.bfAdd("myBloomFilter", "item1"); - - assertThat(commands, contains(booleanCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testBfMAdd() { - when(commandObjects.bfMAdd("myBloomFilter", "item1", "item2")).thenReturn(listBooleanCommandObject); - - Response> response = pipeliningBase.bfMAdd("myBloomFilter", "item1", "item2"); - - assertThat(commands, contains(listBooleanCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testBfInsert() { - when(commandObjects.bfInsert("myBloomFilter", "item1", "item2")).thenReturn(listBooleanCommandObject); - - Response> response = pipeliningBase.bfInsert("myBloomFilter", "item1", "item2"); - - assertThat(commands, contains(listBooleanCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testBfInsertWithParams() { - BFInsertParams insertParams = new BFInsertParams().capacity(10000L).error(0.01); - - when(commandObjects.bfInsert("myBloomFilter", insertParams, "item1", "item2")).thenReturn(listBooleanCommandObject); - - Response> response = pipeliningBase.bfInsert("myBloomFilter", insertParams, "item1", "item2"); - - assertThat(commands, contains(listBooleanCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testBfExists() { - when(commandObjects.bfExists("myBloomFilter", "item1")).thenReturn(booleanCommandObject); - - Response response = pipeliningBase.bfExists("myBloomFilter", "item1"); - - assertThat(commands, contains(booleanCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testBfMExists() { - when(commandObjects.bfMExists("myBloomFilter", "item1", "item2")).thenReturn(listBooleanCommandObject); - - Response> response = pipeliningBase.bfMExists("myBloomFilter", "item1", "item2"); - - assertThat(commands, contains(listBooleanCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testBfScanDump() { - when(commandObjects.bfScanDump("myBloomFilter", 0L)).thenReturn(entryLongBytesCommandObject); - - Response> response = pipeliningBase.bfScanDump("myBloomFilter", 0L); - - assertThat(commands, contains(entryLongBytesCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testBfLoadChunk() { - byte[] data = { 1, 2, 3, 4 }; - - when(commandObjects.bfLoadChunk("myBloomFilter", 0L, data)).thenReturn(stringCommandObject); - - Response response = pipeliningBase.bfLoadChunk("myBloomFilter", 0L, data); - - assertThat(commands, contains(stringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testBfCard() { - when(commandObjects.bfCard("myBloomFilter")).thenReturn(longCommandObject); - - Response response = pipeliningBase.bfCard("myBloomFilter"); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testBfInfo() { - when(commandObjects.bfInfo("myBloomFilter")).thenReturn(mapStringObjectCommandObject); - - Response> response = pipeliningBase.bfInfo("myBloomFilter"); - - assertThat(commands, contains(mapStringObjectCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testCfReserve() { - when(commandObjects.cfReserve("myCuckooFilter", 10000L)).thenReturn(stringCommandObject); - - Response response = pipeliningBase.cfReserve("myCuckooFilter", 10000L); - - assertThat(commands, contains(stringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testCfReserveWithParams() { - CFReserveParams reserveParams = new CFReserveParams().bucketSize(2).maxIterations(500).expansion(2); - - when(commandObjects.cfReserve("myCuckooFilter", 10000L, reserveParams)).thenReturn(stringCommandObject); - - Response response = pipeliningBase.cfReserve("myCuckooFilter", 10000L, reserveParams); - - assertThat(commands, contains(stringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testCfAdd() { - when(commandObjects.cfAdd("myCuckooFilter", "item1")).thenReturn(booleanCommandObject); - - Response response = pipeliningBase.cfAdd("myCuckooFilter", "item1"); - - assertThat(commands, contains(booleanCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testCfAddNx() { - when(commandObjects.cfAddNx("myCuckooFilter", "item1")).thenReturn(booleanCommandObject); - - Response response = pipeliningBase.cfAddNx("myCuckooFilter", "item1"); - - assertThat(commands, contains(booleanCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testCfInsert() { - when(commandObjects.cfInsert("myCuckooFilter", "item1", "item2")).thenReturn(listBooleanCommandObject); - - Response> response = pipeliningBase.cfInsert("myCuckooFilter", "item1", "item2"); - - assertThat(commands, contains(listBooleanCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testCfInsertWithParams() { - CFInsertParams insertParams = new CFInsertParams().capacity(10000L).noCreate(); - - when(commandObjects.cfInsert("myCuckooFilter", insertParams, "item1", "item2")).thenReturn(listBooleanCommandObject); - - Response> response = pipeliningBase.cfInsert("myCuckooFilter", insertParams, "item1", "item2"); - - assertThat(commands, contains(listBooleanCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testCfInsertNx() { - when(commandObjects.cfInsertNx("myCuckooFilter", "item1", "item2")).thenReturn(listBooleanCommandObject); - - Response> response = pipeliningBase.cfInsertNx("myCuckooFilter", "item1", "item2"); - - assertThat(commands, contains(listBooleanCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testCfInsertNxWithParams() { - CFInsertParams insertParams = new CFInsertParams().capacity(10000L).noCreate(); - - when(commandObjects.cfInsertNx("myCuckooFilter", insertParams, "item1", "item2")).thenReturn(listBooleanCommandObject); - - Response> response = pipeliningBase.cfInsertNx("myCuckooFilter", insertParams, "item1", "item2"); - - assertThat(commands, contains(listBooleanCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testCfExists() { - when(commandObjects.cfExists("myCuckooFilter", "item1")).thenReturn(booleanCommandObject); - - Response response = pipeliningBase.cfExists("myCuckooFilter", "item1"); - - assertThat(commands, contains(booleanCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testCfDel() { - when(commandObjects.cfDel("myCuckooFilter", "item1")).thenReturn(booleanCommandObject); - - Response response = pipeliningBase.cfDel("myCuckooFilter", "item1"); - - assertThat(commands, contains(booleanCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testCfCount() { - when(commandObjects.cfCount("myCuckooFilter", "item1")).thenReturn(longCommandObject); - - Response response = pipeliningBase.cfCount("myCuckooFilter", "item1"); - - assertThat(commands, contains(longCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testCfScanDump() { - when(commandObjects.cfScanDump("myCuckooFilter", 0L)).thenReturn(entryLongBytesCommandObject); - - Response> response = pipeliningBase.cfScanDump("myCuckooFilter", 0L); - - assertThat(commands, contains(entryLongBytesCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testCfLoadChunk() { - byte[] data = { 1, 2, 3, 4 }; - - when(commandObjects.cfLoadChunk("myCuckooFilter", 0L, data)).thenReturn(stringCommandObject); - - Response response = pipeliningBase.cfLoadChunk("myCuckooFilter", 0L, data); - - assertThat(commands, contains(stringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testCfInfo() { - when(commandObjects.cfInfo("myCuckooFilter")).thenReturn(mapStringObjectCommandObject); - - Response> response = pipeliningBase.cfInfo("myCuckooFilter"); - - assertThat(commands, contains(mapStringObjectCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testCmsInitByDim() { - when(commandObjects.cmsInitByDim("myCountMinSketch", 1000L, 5L)).thenReturn(stringCommandObject); - - Response response = pipeliningBase.cmsInitByDim("myCountMinSketch", 1000L, 5L); - - assertThat(commands, contains(stringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testCmsInitByProb() { - double error = 0.01; - double probability = 0.99; - - when(commandObjects.cmsInitByProb("myCountMinSketch", error, probability)).thenReturn(stringCommandObject); - - Response response = pipeliningBase.cmsInitByProb("myCountMinSketch", error, probability); - - assertThat(commands, contains(stringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testCmsIncrBy() { - Map itemIncrements = new HashMap<>(); - itemIncrements.put("item1", 1L); - itemIncrements.put("item2", 2L); - - when(commandObjects.cmsIncrBy("myCountMinSketch", itemIncrements)).thenReturn(listLongCommandObject); - - Response> response = pipeliningBase.cmsIncrBy("myCountMinSketch", itemIncrements); - - assertThat(commands, contains(listLongCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testCmsQuery() { - when(commandObjects.cmsQuery("myCountMinSketch", "item1", "item2")).thenReturn(listLongCommandObject); - - Response> response = pipeliningBase.cmsQuery("myCountMinSketch", "item1", "item2"); - - assertThat(commands, contains(listLongCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testCmsMerge() { - when(commandObjects.cmsMerge("mergedCountMinSketch", "cms1", "cms2")).thenReturn(stringCommandObject); - - Response response = pipeliningBase.cmsMerge("mergedCountMinSketch", "cms1", "cms2"); - - assertThat(commands, contains(stringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testCmsMergeWithWeights() { - Map keysAndWeights = new HashMap<>(); - keysAndWeights.put("cms1", 1L); - keysAndWeights.put("cms2", 2L); - - when(commandObjects.cmsMerge("mergedCountMinSketch", keysAndWeights)).thenReturn(stringCommandObject); - - Response response = pipeliningBase.cmsMerge("mergedCountMinSketch", keysAndWeights); - - assertThat(commands, contains(stringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testCmsInfo() { - when(commandObjects.cmsInfo("myCountMinSketch")).thenReturn(mapStringObjectCommandObject); - - Response> response = pipeliningBase.cmsInfo("myCountMinSketch"); - - assertThat(commands, contains(mapStringObjectCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testTopkReserve() { - when(commandObjects.topkReserve("myTopK", 3L)).thenReturn(stringCommandObject); - - Response response = pipeliningBase.topkReserve("myTopK", 3L); - - assertThat(commands, contains(stringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testTopkReserveWithParams() { - long width = 50L; - long depth = 5L; - double decay = 0.9; - - when(commandObjects.topkReserve("myTopK", 3L, width, depth, decay)).thenReturn(stringCommandObject); - - Response response = pipeliningBase.topkReserve("myTopK", 3L, width, depth, decay); - - assertThat(commands, contains(stringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testTopkAdd() { - when(commandObjects.topkAdd("myTopK", "item1", "item2")).thenReturn(listStringCommandObject); - - Response> response = pipeliningBase.topkAdd("myTopK", "item1", "item2"); - - assertThat(commands, contains(listStringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testTopkIncrBy() { - Map itemIncrements = new HashMap<>(); - itemIncrements.put("item1", 1L); - itemIncrements.put("item2", 2L); - - when(commandObjects.topkIncrBy("myTopK", itemIncrements)).thenReturn(listStringCommandObject); - - Response> response = pipeliningBase.topkIncrBy("myTopK", itemIncrements); - - assertThat(commands, contains(listStringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testTopkQuery() { - when(commandObjects.topkQuery("myTopK", "item1", "item2")).thenReturn(listBooleanCommandObject); - - Response> response = pipeliningBase.topkQuery("myTopK", "item1", "item2"); - - assertThat(commands, contains(listBooleanCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testTopkList() { - when(commandObjects.topkList("myTopK")).thenReturn(listStringCommandObject); - - Response> response = pipeliningBase.topkList("myTopK"); - - assertThat(commands, contains(listStringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testTopkListWithCount() { - when(commandObjects.topkListWithCount("myTopK")).thenReturn(mapStringLongCommandObject); - - Response> response = pipeliningBase.topkListWithCount("myTopK"); - - assertThat(commands, contains(mapStringLongCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testTopkInfo() { - when(commandObjects.topkInfo("myTopK")).thenReturn(mapStringObjectCommandObject); - - Response> response = pipeliningBase.topkInfo("myTopK"); - - assertThat(commands, contains(mapStringObjectCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testTdigestCreate() { - when(commandObjects.tdigestCreate("myTDigest")).thenReturn(stringCommandObject); - - Response response = pipeliningBase.tdigestCreate("myTDigest"); - - assertThat(commands, contains(stringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testTdigestCreateWithCompression() { - when(commandObjects.tdigestCreate("myTDigest", 100)).thenReturn(stringCommandObject); - - Response response = pipeliningBase.tdigestCreate("myTDigest", 100); - - assertThat(commands, contains(stringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testTdigestReset() { - when(commandObjects.tdigestReset("myTDigest")).thenReturn(stringCommandObject); - - Response response = pipeliningBase.tdigestReset("myTDigest"); - - assertThat(commands, contains(stringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testTdigestMerge() { - when(commandObjects.tdigestMerge("destinationTDigest", "sourceTDigest1", "sourceTDigest2")) - .thenReturn(stringCommandObject); - - Response response = - pipeliningBase.tdigestMerge("destinationTDigest", "sourceTDigest1", "sourceTDigest2"); - - assertThat(commands, contains(stringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testTdigestMergeWithParams() { - TDigestMergeParams mergeParams = new TDigestMergeParams().compression(100); - - when(commandObjects.tdigestMerge(mergeParams, "destinationTDigest", "sourceTDigest1", "sourceTDigest2")) - .thenReturn(stringCommandObject); - - Response response = - pipeliningBase.tdigestMerge(mergeParams, "destinationTDigest", "sourceTDigest1", "sourceTDigest2"); - - assertThat(commands, contains(stringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testTdigestInfo() { - when(commandObjects.tdigestInfo("myTDigest")).thenReturn(mapStringObjectCommandObject); - - Response> response = pipeliningBase.tdigestInfo("myTDigest"); - - assertThat(commands, contains(mapStringObjectCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testTdigestAdd() { - when(commandObjects.tdigestAdd("myTDigest", 1.0, 2.0, 3.0)).thenReturn(stringCommandObject); - - Response response = pipeliningBase.tdigestAdd("myTDigest", 1.0, 2.0, 3.0); - - assertThat(commands, contains(stringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testTdigestCDF() { - when(commandObjects.tdigestCDF("myTDigest", 1.0, 2.0)).thenReturn(listDoubleCommandObject); - - Response> response = pipeliningBase.tdigestCDF("myTDigest", 1.0, 2.0); - - assertThat(commands, contains(listDoubleCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testTdigestQuantile() { - when(commandObjects.tdigestQuantile("myTDigest", 0.5, 0.9)).thenReturn(listDoubleCommandObject); - - Response> response = pipeliningBase.tdigestQuantile("myTDigest", 0.5, 0.9); - - assertThat(commands, contains(listDoubleCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testTdigestMin() { - when(commandObjects.tdigestMin("myTDigest")).thenReturn(doubleCommandObject); - - Response response = pipeliningBase.tdigestMin("myTDigest"); - - assertThat(commands, contains(doubleCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testTdigestMax() { - when(commandObjects.tdigestMax("myTDigest")).thenReturn(doubleCommandObject); - - Response response = pipeliningBase.tdigestMax("myTDigest"); - - assertThat(commands, contains(doubleCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testTdigestTrimmedMean() { - when(commandObjects.tdigestTrimmedMean("myTDigest", 0.1, 0.9)).thenReturn(doubleCommandObject); - - Response response = pipeliningBase.tdigestTrimmedMean("myTDigest", 0.1, 0.9); - - assertThat(commands, contains(doubleCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testTdigestRank() { - when(commandObjects.tdigestRank("myTDigest", 1.0, 2.0)).thenReturn(listLongCommandObject); - - Response> response = pipeliningBase.tdigestRank("myTDigest", 1.0, 2.0); - - assertThat(commands, contains(listLongCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testTdigestRevRank() { - when(commandObjects.tdigestRevRank("myTDigest", 1.0, 2.0)).thenReturn(listLongCommandObject); - - Response> response = pipeliningBase.tdigestRevRank("myTDigest", 1.0, 2.0); - - assertThat(commands, contains(listLongCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testTdigestByRank() { - when(commandObjects.tdigestByRank("myTDigest", 1, 2)).thenReturn(listDoubleCommandObject); - - Response> response = pipeliningBase.tdigestByRank("myTDigest", 1, 2); - - assertThat(commands, contains(listDoubleCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testTdigestByRevRank() { - when(commandObjects.tdigestByRevRank("myTDigest", 1, 2)).thenReturn(listDoubleCommandObject); - - Response> response = pipeliningBase.tdigestByRevRank("myTDigest", 1, 2); - - assertThat(commands, contains(listDoubleCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testGraphQuery() { - String query = "MATCH (n) RETURN n"; - - when(graphCommandObjects.graphQuery("myGraph", query)).thenReturn(resultSetCommandObject); - - Response response = pipeliningBase.graphQuery("myGraph", query); - - assertThat(commands, contains(resultSetCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testGraphReadonlyQuery() { - String query = "MATCH (n) RETURN n"; - - when(graphCommandObjects.graphReadonlyQuery("myGraph", query)).thenReturn(resultSetCommandObject); - - Response response = pipeliningBase.graphReadonlyQuery("myGraph", query); - - assertThat(commands, contains(resultSetCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testGraphQueryWithTimeout() { - String query = "MATCH (n) RETURN n"; - - when(graphCommandObjects.graphQuery("myGraph", query, 1000L)).thenReturn(resultSetCommandObject); - - Response response = pipeliningBase.graphQuery("myGraph", query, 1000L); - - assertThat(commands, contains(resultSetCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testGraphReadonlyQueryWithTimeout() { - String query = "MATCH (n) RETURN n"; - - when(graphCommandObjects.graphReadonlyQuery("myGraph", query, 1000L)).thenReturn(resultSetCommandObject); - - Response response = pipeliningBase.graphReadonlyQuery("myGraph", query, 1000L); - - assertThat(commands, contains(resultSetCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testGraphQueryWithParams() { - String query = "MATCH (n) WHERE n.name = $name RETURN n"; - Map params = Collections.singletonMap("name", "Alice"); - - when(graphCommandObjects.graphQuery("myGraph", query, params)).thenReturn(resultSetCommandObject); - - Response response = pipeliningBase.graphQuery("myGraph", query, params); - - assertThat(commands, contains(resultSetCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testGraphReadonlyQueryWithParams() { - String query = "MATCH (n) WHERE n.name = $name RETURN n"; - Map params = Collections.singletonMap("name", "Alice"); - - when(graphCommandObjects.graphReadonlyQuery("myGraph", query, params)).thenReturn(resultSetCommandObject); - - Response response = pipeliningBase.graphReadonlyQuery("myGraph", query, params); - - assertThat(commands, contains(resultSetCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testGraphQueryWithParamsAndTimeout() { - String query = "MATCH (n) WHERE n.name = $name RETURN n"; - Map params = Collections.singletonMap("name", "Alice"); - - when(graphCommandObjects.graphQuery("myGraph", query, params, 1000L)).thenReturn(resultSetCommandObject); - - Response response = pipeliningBase.graphQuery("myGraph", query, params, 1000L); - - assertThat(commands, contains(resultSetCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testGraphReadonlyQueryWithParamsAndTimeout() { - String query = "MATCH (n) WHERE n.name = $name RETURN n"; - Map params = Collections.singletonMap("name", "Alice"); - - when(graphCommandObjects.graphReadonlyQuery("myGraph", query, params, 1000L)).thenReturn(resultSetCommandObject); - - Response response = pipeliningBase.graphReadonlyQuery("myGraph", query, params, 1000L); - - assertThat(commands, contains(resultSetCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testGraphDelete() { - when(graphCommandObjects.graphDelete("myGraph")).thenReturn(stringCommandObject); - - Response response = pipeliningBase.graphDelete("myGraph"); - - assertThat(commands, contains(stringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testGraphProfile() { - String query = "PROFILE MATCH (n) RETURN n"; - - when(commandObjects.graphProfile("myGraph", query)).thenReturn(listStringCommandObject); - - Response> response = pipeliningBase.graphProfile("myGraph", query); - - assertThat(commands, contains(listStringCommandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testSendCommandWithStringArgs() { - ProtocolCommand cmd = Protocol.Command.GET; - String arg1 = "key1"; - String arg2 = "key2"; - - Response response = pipeliningBase.sendCommand(cmd, arg1, arg2); - - assertThat(commands, hasSize(1)); - - List arguments = new ArrayList<>(); - commands.get(0).getArguments().forEach(arguments::add); - - assertThat(arguments.stream().map(Rawable::getRaw).collect(Collectors.toList()), contains( - Protocol.Command.GET.getRaw(), - arg1.getBytes(), - arg2.getBytes() - )); - - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testSendCommandWithByteArgs() { - ProtocolCommand cmd = Protocol.Command.SET; - byte[] arg1 = "key1".getBytes(); - byte[] arg2 = "value1".getBytes(); - - Response response = pipeliningBase.sendCommand(cmd, arg1, arg2); - - assertThat(commands, hasSize(1)); - - List arguments = new ArrayList<>(); - commands.get(0).getArguments().forEach(arguments::add); - - assertThat(arguments.stream().map(Rawable::getRaw).collect(Collectors.toList()), contains( - Protocol.Command.SET.getRaw(), - arg1, - arg2 - )); - - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testExecuteCommand() { - CommandArguments commandArguments = new CommandArguments(Protocol.Command.GET).key("key1"); - CommandObject commandObject = new CommandObject<>(commandArguments, BuilderFactory.STRING); - - Response response = pipeliningBase.executeCommand(commandObject); - - assertThat(commands, contains(commandObject)); - assertThat(response, is(predefinedResponse)); - } - - @Test - public void testSetJsonObjectMapper() { - JsonObjectMapper jsonObjectMapper = mock(JsonObjectMapper.class); - doNothing().when(commandObjects).setJsonObjectMapper(jsonObjectMapper); - - pipeliningBase.setJsonObjectMapper(jsonObjectMapper); - - verify(commandObjects).setJsonObjectMapper(jsonObjectMapper); - } - - @Test - public void testMultipleCommands() { - when(commandObjects.exists("key1")).thenReturn(booleanCommandObject); - when(commandObjects.exists("key2")).thenReturn(booleanCommandObject); - - Response result1 = pipeliningBase.exists("key1"); - Response result2 = pipeliningBase.exists("key2"); - - assertThat(commands, contains( - booleanCommandObject, - booleanCommandObject - )); - - assertThat(result1, is(predefinedResponse)); - assertThat(result2, is(predefinedResponse)); - } - -} diff --git a/src/test/java/redis/clients/jedis/UnifiedJedisCustomCommandsTest.java b/src/test/java/redis/clients/jedis/UnifiedJedisCustomCommandsTest.java new file mode 100644 index 00000000000..bb125cc28dc --- /dev/null +++ b/src/test/java/redis/clients/jedis/UnifiedJedisCustomCommandsTest.java @@ -0,0 +1,263 @@ +package redis.clients.jedis; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.sameInstance; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import org.junit.Test; +import org.mockito.ArgumentCaptor; +import redis.clients.jedis.commands.ProtocolCommand; +import redis.clients.jedis.mocked.unified.UnifiedJedisMockedTestBase; + +/** + * These tests are part of the mocked tests for {@link UnifiedJedis}, but, due to {@code protected} + * visibility of some methods, they must reside in the same package as the tested class. + */ +public class UnifiedJedisCustomCommandsTest extends UnifiedJedisMockedTestBase { + + @Test + public void testSendCommandWithProtocolCommand() { + ProtocolCommand cmd = mock(ProtocolCommand.class); + CommandArguments commandArguments = mock(CommandArguments.class); + + when(commandObjects.commandArguments(cmd)).thenReturn(commandArguments); + when(commandExecutor.executeCommand(any())).thenReturn("OK"); + + Object result = jedis.sendCommand(cmd); + + ArgumentCaptor> argumentCaptor = ArgumentCaptor.forClass(CommandObject.class); + verify(commandExecutor).executeCommand(argumentCaptor.capture()); + + CommandObject commandObject = argumentCaptor.getValue(); + assertThat(commandObject.getArguments(), sameInstance(commandArguments)); + + assertThat(result, equalTo("OK")); + + verify(commandObjects).commandArguments(cmd); + } + + @Test + public void testSendCommandWithProtocolCommandAndByteArrayArgs() { + ProtocolCommand cmd = mock(ProtocolCommand.class); + byte[][] args = { "arg1".getBytes(), "arg2".getBytes() }; + CommandArguments commandArguments = mock(CommandArguments.class); + CommandArguments commandArgumentsWithArgs = mock(CommandArguments.class); + when(commandArguments.addObjects(args)).thenReturn(commandArgumentsWithArgs); + + when(commandObjects.commandArguments(cmd)).thenReturn(commandArguments); + when(commandExecutor.executeCommand(any())).thenReturn("OK"); + + Object result = jedis.sendCommand(cmd, args); + + ArgumentCaptor> argumentCaptor = ArgumentCaptor.forClass(CommandObject.class); + verify(commandExecutor).executeCommand(argumentCaptor.capture()); + + CommandObject commandObject = argumentCaptor.getValue(); + assertThat(commandObject.getArguments(), sameInstance(commandArgumentsWithArgs)); + + assertThat(result, equalTo("OK")); + + verify(commandObjects).commandArguments(cmd); + } + + @Test + public void testSendBlockingCommandWithProtocolCommandAndByteArrayArgs() { + ProtocolCommand cmd = mock(ProtocolCommand.class); + byte[][] args = { "arg1".getBytes(), "arg2".getBytes() }; + CommandArguments commandArguments = mock(CommandArguments.class); + + CommandArguments commandArgumentsBlocking = mock(CommandArguments.class); + CommandArguments commandArgumentsWithArgs = mock(CommandArguments.class); + when(commandArgumentsWithArgs.blocking()).thenReturn(commandArgumentsBlocking); + + when(commandArguments.addObjects(args)).thenReturn(commandArgumentsWithArgs); + + when(commandObjects.commandArguments(cmd)).thenReturn(commandArguments); + when(commandExecutor.executeCommand(any())).thenReturn("OK"); + + Object result = jedis.sendBlockingCommand(cmd, args); + + ArgumentCaptor> argumentCaptor = ArgumentCaptor.forClass(CommandObject.class); + verify(commandExecutor).executeCommand(argumentCaptor.capture()); + + CommandObject commandObject = argumentCaptor.getValue(); + assertThat(commandObject.getArguments(), sameInstance(commandArgumentsBlocking)); + + assertThat(result, equalTo("OK")); + + verify(commandObjects).commandArguments(cmd); + } + + @Test + public void testSendCommandWithProtocolCommandAndStringArgs() { + ProtocolCommand cmd = mock(ProtocolCommand.class); + String[] args = { "arg1", "arg2" }; + CommandArguments commandArguments = mock(CommandArguments.class); + CommandArguments commandArgumentsWithArgs = mock(CommandArguments.class); + when(commandArguments.addObjects(args)).thenReturn(commandArgumentsWithArgs); + + when(commandObjects.commandArguments(cmd)).thenReturn(commandArguments); + when(commandExecutor.executeCommand(any())).thenReturn("OK"); + + Object result = jedis.sendCommand(cmd, args); + + ArgumentCaptor> argumentCaptor = ArgumentCaptor.forClass(CommandObject.class); + verify(commandExecutor).executeCommand(argumentCaptor.capture()); + + CommandObject commandObject = argumentCaptor.getValue(); + assertThat(commandObject.getArguments(), sameInstance(commandArgumentsWithArgs)); + + assertThat(result, equalTo("OK")); + + verify(commandObjects).commandArguments(cmd); + } + + @Test + public void testSendBlockingCommandWithProtocolCommandAndStringArgs() { + ProtocolCommand cmd = mock(ProtocolCommand.class); + String[] args = { "arg1", "arg2" }; + CommandArguments commandArguments = mock(CommandArguments.class); + + CommandArguments commandArgumentsBlocking = mock(CommandArguments.class); + CommandArguments commandArgumentsWithArgs = mock(CommandArguments.class); + when(commandArgumentsWithArgs.blocking()).thenReturn(commandArgumentsBlocking); + + when(commandArguments.addObjects(args)).thenReturn(commandArgumentsWithArgs); + + when(commandObjects.commandArguments(cmd)).thenReturn(commandArguments); + when(commandExecutor.executeCommand(any())).thenReturn("OK"); + + Object result = jedis.sendBlockingCommand(cmd, args); + + ArgumentCaptor> argumentCaptor = ArgumentCaptor.forClass(CommandObject.class); + verify(commandExecutor).executeCommand(argumentCaptor.capture()); + + CommandObject commandObject = argumentCaptor.getValue(); + assertThat(commandObject.getArguments(), sameInstance(commandArgumentsBlocking)); + + assertThat(result, equalTo("OK")); + + verify(commandObjects).commandArguments(cmd); + } + + @Test + public void testSendCommandWithSampleKeyProtocolCommandAndByteArrayArgs() { + byte[] sampleKey = "key".getBytes(); + ProtocolCommand cmd = mock(ProtocolCommand.class); + byte[][] args = { "arg1".getBytes(), "arg2".getBytes() }; + CommandArguments commandArguments = mock(CommandArguments.class); + CommandArguments commandArgumentsWithArgs = mock(CommandArguments.class); + CommandArguments commandArgumentsWithKey = mock(CommandArguments.class); + + when(commandArguments.addObjects((Object[]) args)).thenReturn(commandArgumentsWithArgs); + when(commandArgumentsWithArgs.processKey(sampleKey)).thenReturn(commandArgumentsWithKey); + + when(commandObjects.commandArguments(cmd)).thenReturn(commandArguments); + when(commandExecutor.executeCommand(any())).thenReturn("OK"); + + Object result = jedis.sendCommand(sampleKey, cmd, args); + + ArgumentCaptor> argumentCaptor = ArgumentCaptor.forClass(CommandObject.class); + verify(commandExecutor).executeCommand(argumentCaptor.capture()); + + CommandObject commandObject = argumentCaptor.getValue(); + assertThat(commandObject.getArguments(), sameInstance(commandArgumentsWithKey)); + + assertThat(result, equalTo("OK")); + + verify(commandObjects).commandArguments(cmd); + } + + @Test + public void testSendBlockingCommandWithSampleKeyProtocolCommandAndByteArrayArgs() { + byte[] sampleKey = "key".getBytes(); + ProtocolCommand cmd = mock(ProtocolCommand.class); + byte[][] args = { "arg1".getBytes(), "arg2".getBytes() }; + CommandArguments commandArguments = mock(CommandArguments.class); + CommandArguments commandArgumentsWithArgs = mock(CommandArguments.class); + CommandArguments commandArgumentsBlocking = mock(CommandArguments.class); + CommandArguments commandArgumentsWithKey = mock(CommandArguments.class); + + when(commandArguments.addObjects((Object[]) args)).thenReturn(commandArgumentsWithArgs); + when(commandArgumentsWithArgs.blocking()).thenReturn(commandArgumentsBlocking); + when(commandArgumentsBlocking.processKey(sampleKey)).thenReturn(commandArgumentsWithKey); + + when(commandObjects.commandArguments(cmd)).thenReturn(commandArguments); + when(commandExecutor.executeCommand(any())).thenReturn("OK"); + + Object result = jedis.sendBlockingCommand(sampleKey, cmd, args); + + ArgumentCaptor> argumentCaptor = ArgumentCaptor.forClass(CommandObject.class); + verify(commandExecutor).executeCommand(argumentCaptor.capture()); + + CommandObject commandObject = argumentCaptor.getValue(); + assertThat(commandObject.getArguments(), sameInstance(commandArgumentsWithKey)); + + assertThat(result, equalTo("OK")); + + verify(commandObjects).commandArguments(cmd); + } + + @Test + public void testSendCommandWithStringSampleKeyProtocolCommandAndStringArgs() { + String sampleKey = "key"; + ProtocolCommand cmd = mock(ProtocolCommand.class); + String[] args = { "arg1", "arg2" }; + CommandArguments commandArguments = mock(CommandArguments.class); + CommandArguments commandArgumentsWithArgs = mock(CommandArguments.class); + CommandArguments commandArgumentsWithKey = mock(CommandArguments.class); + + when(commandArguments.addObjects((Object[]) args)).thenReturn(commandArgumentsWithArgs); + when(commandArgumentsWithArgs.processKey(sampleKey)).thenReturn(commandArgumentsWithKey); + + when(commandObjects.commandArguments(cmd)).thenReturn(commandArguments); + when(commandExecutor.executeCommand(any())).thenReturn("OK"); + + Object result = jedis.sendCommand(sampleKey, cmd, args); + + ArgumentCaptor> argumentCaptor = ArgumentCaptor.forClass(CommandObject.class); + verify(commandExecutor).executeCommand(argumentCaptor.capture()); + + CommandObject commandObject = argumentCaptor.getValue(); + assertThat(commandObject.getArguments(), sameInstance(commandArgumentsWithKey)); + + assertThat(result, equalTo("OK")); + + verify(commandObjects).commandArguments(cmd); + } + + @Test + public void testSendBlockingCommandWithStringSampleKeyProtocolCommandAndStringArgs() { + String sampleKey = "key"; + ProtocolCommand cmd = mock(ProtocolCommand.class); + String[] args = { "arg1", "arg2" }; + CommandArguments commandArguments = mock(CommandArguments.class); + CommandArguments commandArgumentsWithArgs = mock(CommandArguments.class); + CommandArguments commandArgumentsBlocking = mock(CommandArguments.class); + CommandArguments commandArgumentsWithKey = mock(CommandArguments.class); + + when(commandArguments.addObjects((Object[]) args)).thenReturn(commandArgumentsWithArgs); + when(commandArgumentsWithArgs.blocking()).thenReturn(commandArgumentsBlocking); + when(commandArgumentsBlocking.processKey(sampleKey)).thenReturn(commandArgumentsWithKey); + + when(commandObjects.commandArguments(cmd)).thenReturn(commandArguments); + when(commandExecutor.executeCommand(any())).thenReturn("OK"); + + Object result = jedis.sendBlockingCommand(sampleKey, cmd, args); + + ArgumentCaptor> argumentCaptor = ArgumentCaptor.forClass(CommandObject.class); + verify(commandExecutor).executeCommand(argumentCaptor.capture()); + + CommandObject commandObject = argumentCaptor.getValue(); + assertThat(commandObject.getArguments(), sameInstance(commandArgumentsWithKey)); + + assertThat(result, equalTo("OK")); + + verify(commandObjects).commandArguments(cmd); + } + +} diff --git a/src/test/java/redis/clients/jedis/mocked/MockedCommandObjectsTestBase.java b/src/test/java/redis/clients/jedis/mocked/MockedCommandObjectsTestBase.java new file mode 100644 index 00000000000..8127c417bc2 --- /dev/null +++ b/src/test/java/redis/clients/jedis/mocked/MockedCommandObjectsTestBase.java @@ -0,0 +1,140 @@ +package redis.clients.jedis.mocked; + +import java.util.List; +import java.util.Map; +import java.util.Set; + +import org.json.JSONArray; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.junit.MockitoJUnitRunner; +import redis.clients.jedis.CommandObject; +import redis.clients.jedis.GeoCoordinate; +import redis.clients.jedis.StreamEntryID; +import redis.clients.jedis.gears.resps.GearsLibraryInfo; +import redis.clients.jedis.graph.ResultSet; +import redis.clients.jedis.resps.FunctionStats; +import redis.clients.jedis.resps.GeoRadiusResponse; +import redis.clients.jedis.resps.LCSMatchResult; +import redis.clients.jedis.resps.LibraryInfo; +import redis.clients.jedis.resps.ScanResult; +import redis.clients.jedis.resps.StreamConsumerInfo; +import redis.clients.jedis.resps.StreamConsumersInfo; +import redis.clients.jedis.resps.StreamEntry; +import redis.clients.jedis.resps.StreamFullInfo; +import redis.clients.jedis.resps.StreamGroupInfo; +import redis.clients.jedis.resps.StreamInfo; +import redis.clients.jedis.resps.StreamPendingEntry; +import redis.clients.jedis.resps.StreamPendingSummary; +import redis.clients.jedis.resps.Tuple; +import redis.clients.jedis.search.SearchResult; +import redis.clients.jedis.search.aggr.AggregationResult; +import redis.clients.jedis.timeseries.TSElement; +import redis.clients.jedis.timeseries.TSInfo; +import redis.clients.jedis.timeseries.TSMGetElement; +import redis.clients.jedis.timeseries.TSMRangeElements; +import redis.clients.jedis.util.KeyValue; + +/** + * Provides an exhaustive list of mocked {@link redis.clients.jedis.CommandObject}s for use in unit tests. + */ +@RunWith(MockitoJUnitRunner.class) +public abstract class MockedCommandObjectsTestBase { + + /** + * Used for JSON related tests. The fields are not used actually, given that tests are mocked. + */ + @SuppressWarnings("unused") + public final static class MyBean { + String field1; + String field2; + } + + + // Below follows a list of mocked CommandObjects, one per type. This is the cleanest way to create + // mocks, given that CommandObject is a generic class. Using {@code Mockito.mock(...)} yields too + // many warnings related to generics. + // To make the code more readable, try to keep the list sorted alphabetically, and without automatic + // reformatting. + + // @formatter:off + @Mock protected CommandObject aggregationResultCommandObject; + @Mock protected CommandObject booleanCommandObject; + @Mock protected CommandObject> classCommandObject; + @Mock protected CommandObject doubleCommandObject; + @Mock protected CommandObject functionStatsCommandObject; + @Mock protected CommandObject> keyValueLongDoubleCommandObject; + @Mock protected CommandObject> keyValueLongLongCommandObject; + @Mock protected CommandObject>> keyValueStringListStringCommandObject; + @Mock protected CommandObject>> keyValueStringListTupleCommandObject; + @Mock protected CommandObject> keyValueStringStringCommandObject; + @Mock protected CommandObject> keyValueStringTupleCommandObject; + @Mock protected CommandObject>> keyValueBytesListTupleCommandObject; + @Mock protected CommandObject>> keyValueBytesListBytesCommandObject; + @Mock protected CommandObject> keyValueBytesTupleCommandObject; + @Mock protected CommandObject> keyValueBytesBytesCommandObject; + @Mock protected CommandObject lcsMatchResultCommandObject; + @Mock protected CommandObject> listBooleanCommandObject; + @Mock protected CommandObject>> listClassCommandObject; + @Mock protected CommandObject> listDoubleCommandObject; + @Mock protected CommandObject> listGearsLibraryInfoCommandObject; + @Mock protected CommandObject> listGeoCoordinateCommandObject; + @Mock protected CommandObject> listGeoRadiusResponseCommandObject; + @Mock protected CommandObject> listJsonArrayCommandObject; + @Mock protected CommandObject> listLibraryInfoCommandObject; + @Mock protected CommandObject>> listListObjectCommandObject; + @Mock protected CommandObject>> listListStringCommandObject; + @Mock protected CommandObject> listLongCommandObject; + @Mock protected CommandObject>>> listEntryStringListStreamEntryCommandObject; + @Mock protected CommandObject>> listEntryStringStringCommandObject; + @Mock protected CommandObject>> listEntryBytesBytesCommandObject; + @Mock protected CommandObject> listMyBeanCommandObject; + @Mock protected CommandObject> listObjectCommandObject; + @Mock protected CommandObject> listStreamConsumerInfoCommandObject; + @Mock protected CommandObject> listStreamConsumersInfoCommandObject; + @Mock protected CommandObject> listStreamEntryCommandObject; + @Mock protected CommandObject> listStreamEntryIdCommandObject; + @Mock protected CommandObject> listStreamGroupInfoCommandObject; + @Mock protected CommandObject> listStreamPendingEntryCommandObject; + @Mock protected CommandObject> listStringCommandObject; + @Mock protected CommandObject> listTsElementCommandObject; + @Mock protected CommandObject> listTupleCommandObject; + @Mock protected CommandObject> listBytesCommandObject; + @Mock protected CommandObject longCommandObject; + @Mock protected CommandObject>> entryAggregationResultMapStringObjectCommandObject; + @Mock protected CommandObject> entryLongBytesCommandObject; + @Mock protected CommandObject>> entrySearchResultMapStringObjectCommandObject; + @Mock protected CommandObject>> entryStreamEntryIdListStreamEntryCommandObject; + @Mock protected CommandObject>> entryStreamEntryIdListStreamEntryIdCommandObject; + @Mock protected CommandObject>> mapStringListStringCommandObject; + @Mock protected CommandObject>> mapStringListStreamEntryCommandObject; + @Mock protected CommandObject> mapStringLongCommandObject; + @Mock protected CommandObject>> mapStringMapStringDoubleCommandObject; + @Mock protected CommandObject> mapStringObjectCommandObject; + @Mock protected CommandObject> mapStringStringCommandObject; + @Mock protected CommandObject> mapStringTsmGetElementCommandObject; + @Mock protected CommandObject> mapStringTsmRangeElementsCommandObject; + @Mock protected CommandObject> mapBytesBytesCommandObject; + @Mock protected CommandObject myBeanCommandObject; + @Mock protected CommandObject objectCommandObject; + @Mock protected CommandObject resultSetCommandObject; + @Mock protected CommandObject>> scanResultEntryStringStringCommandObject; + @Mock protected CommandObject>> scanResultEntryBytesBytesCommandObject; + @Mock protected CommandObject> scanResultStringCommandObject; + @Mock protected CommandObject> scanResultTupleCommandObject; + @Mock protected CommandObject> scanResultBytesCommandObject; + @Mock protected CommandObject searchResultCommandObject; + @Mock protected CommandObject> setStringCommandObject; + @Mock protected CommandObject> setBytesCommandObject; + @Mock protected CommandObject streamEntryIdCommandObject; + @Mock protected CommandObject streamFullInfoCommandObject; + @Mock protected CommandObject streamInfoCommandObject; + @Mock protected CommandObject streamPendingSummaryCommandObject; + @Mock protected CommandObject stringCommandObject; + @Mock protected CommandObject tsElementCommandObject; + @Mock protected CommandObject tsInfoCommandObject; + @Mock protected CommandObject tupleCommandObject; + @Mock protected CommandObject bytesCommandObject; + // @formatter:on + +} diff --git a/src/test/java/redis/clients/jedis/mocked/pipeline/PipeliningBaseBitmapCommandsTest.java b/src/test/java/redis/clients/jedis/mocked/pipeline/PipeliningBaseBitmapCommandsTest.java new file mode 100644 index 00000000000..a96690f19ba --- /dev/null +++ b/src/test/java/redis/clients/jedis/mocked/pipeline/PipeliningBaseBitmapCommandsTest.java @@ -0,0 +1,264 @@ +package redis.clients.jedis.mocked.pipeline; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.contains; +import static org.hamcrest.Matchers.is; +import static org.mockito.Mockito.when; + +import java.util.List; + +import org.junit.Test; +import redis.clients.jedis.Response; +import redis.clients.jedis.args.BitCountOption; +import redis.clients.jedis.args.BitOP; +import redis.clients.jedis.params.BitPosParams; + +public class PipeliningBaseBitmapCommandsTest extends PipeliningBaseMockedTestBase { + + @Test + public void testBitcount() { + when(commandObjects.bitcount("key")).thenReturn(longCommandObject); + + Response response = pipeliningBase.bitcount("key"); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testBitcountBinary() { + byte[] key = "key".getBytes(); + + when(commandObjects.bitcount(key)).thenReturn(longCommandObject); + + Response response = pipeliningBase.bitcount(key); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testBitcountRange() { + when(commandObjects.bitcount("key", 0, 10)).thenReturn(longCommandObject); + + Response response = pipeliningBase.bitcount("key", 0, 10); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testBitcountRangeBinary() { + byte[] key = "key".getBytes(); + long start = 0L; + long end = 10L; + + when(commandObjects.bitcount(key, start, end)).thenReturn(longCommandObject); + + Response response = pipeliningBase.bitcount(key, start, end); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testBitcountRangeOption() { + BitCountOption option = BitCountOption.BYTE; + + when(commandObjects.bitcount("key", 0, 10, option)).thenReturn(longCommandObject); + + Response response = pipeliningBase.bitcount("key", 0, 10, option); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testBitcountRangeOptionBinary() { + byte[] key = "key".getBytes(); + long start = 0L; + long end = 10L; + BitCountOption option = BitCountOption.BYTE; + + when(commandObjects.bitcount(key, start, end, option)).thenReturn(longCommandObject); + + Response response = pipeliningBase.bitcount(key, start, end, option); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testBitfield() { + String[] arguments = { "INCRBY", "mykey", "2", "1" }; + + when(commandObjects.bitfield("key", arguments)).thenReturn(listLongCommandObject); + + Response> response = pipeliningBase.bitfield("key", arguments); + + assertThat(commands, contains(listLongCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testBitfieldBinary() { + byte[] key = "key".getBytes(); + byte[][] arguments = { "INCRBY".getBytes(), "mykey".getBytes(), "2".getBytes(), "1".getBytes() }; + + when(commandObjects.bitfield(key, arguments)).thenReturn(listLongCommandObject); + + Response> response = pipeliningBase.bitfield(key, arguments); + + assertThat(commands, contains(listLongCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testBitfieldReadonly() { + String[] arguments = { "GET", "u4", "0" }; + + when(commandObjects.bitfieldReadonly("key", arguments)).thenReturn(listLongCommandObject); + + Response> response = pipeliningBase.bitfieldReadonly("key", arguments); + + assertThat(commands, contains(listLongCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testBitfieldReadonlyBinary() { + byte[] key = "key".getBytes(); + byte[][] arguments = { "GET".getBytes(), "u4".getBytes(), "0".getBytes() }; + + when(commandObjects.bitfieldReadonly(key, arguments)).thenReturn(listLongCommandObject); + + Response> response = pipeliningBase.bitfieldReadonly(key, arguments); + + assertThat(commands, contains(listLongCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testBitop() { + BitOP op = BitOP.AND; + + when(commandObjects.bitop(op, "destKey", "srckey1", "srckey2")).thenReturn(longCommandObject); + + Response response = pipeliningBase.bitop(op, "destKey", "srckey1", "srckey2"); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testBitopBinary() { + BitOP op = BitOP.AND; + byte[] destKey = "destKey".getBytes(); + byte[] srcKey1 = "srcKey1".getBytes(); + byte[] srcKey2 = "srcKey2".getBytes(); + + when(commandObjects.bitop(op, destKey, srcKey1, srcKey2)).thenReturn(longCommandObject); + + Response response = pipeliningBase.bitop(op, destKey, srcKey1, srcKey2); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testBitpos() { + when(commandObjects.bitpos("key", true)).thenReturn(longCommandObject); + + Response response = pipeliningBase.bitpos("key", true); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testBitposBinary() { + byte[] key = "key".getBytes(); + boolean value = true; + + when(commandObjects.bitpos(key, value)).thenReturn(longCommandObject); + + Response response = pipeliningBase.bitpos(key, value); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testBitposParams() { + BitPosParams params = new BitPosParams(0, -1); + + when(commandObjects.bitpos("key", true, params)).thenReturn(longCommandObject); + + Response response = pipeliningBase.bitpos("key", true, params); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testBitposParamsBinary() { + byte[] key = "key".getBytes(); + boolean value = true; + BitPosParams params = new BitPosParams(0); + + when(commandObjects.bitpos(key, value, params)).thenReturn(longCommandObject); + + Response response = pipeliningBase.bitpos(key, value, params); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testGetbit() { + when(commandObjects.getbit("key", 100)).thenReturn(booleanCommandObject); + + Response response = pipeliningBase.getbit("key", 100); + + assertThat(commands, contains(booleanCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testGetbitBinary() { + byte[] key = "key".getBytes(); + long offset = 10L; + + when(commandObjects.getbit(key, offset)).thenReturn(booleanCommandObject); + + Response response = pipeliningBase.getbit(key, offset); + + assertThat(commands, contains(booleanCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testSetbit() { + when(commandObjects.setbit("key", 100, true)).thenReturn(booleanCommandObject); + + Response response = pipeliningBase.setbit("key", 100, true); + + assertThat(commands, contains(booleanCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testSetbitBinary() { + byte[] key = "key".getBytes(); + long offset = 10L; + boolean value = true; + + when(commandObjects.setbit(key, offset, value)).thenReturn(booleanCommandObject); + + Response response = pipeliningBase.setbit(key, offset, value); + + assertThat(commands, contains(booleanCommandObject)); + assertThat(response, is(predefinedResponse)); + } + +} diff --git a/src/test/java/redis/clients/jedis/mocked/pipeline/PipeliningBaseBloomFilterCommandsTest.java b/src/test/java/redis/clients/jedis/mocked/pipeline/PipeliningBaseBloomFilterCommandsTest.java new file mode 100644 index 00000000000..6525e521e12 --- /dev/null +++ b/src/test/java/redis/clients/jedis/mocked/pipeline/PipeliningBaseBloomFilterCommandsTest.java @@ -0,0 +1,149 @@ +package redis.clients.jedis.mocked.pipeline; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.contains; +import static org.hamcrest.Matchers.is; +import static org.mockito.Mockito.when; + +import java.util.List; +import java.util.Map; + +import org.junit.Test; +import redis.clients.jedis.Response; +import redis.clients.jedis.bloom.BFInsertParams; +import redis.clients.jedis.bloom.BFReserveParams; + +public class PipeliningBaseBloomFilterCommandsTest extends PipeliningBaseMockedTestBase { + + @Test + public void testBfAdd() { + when(commandObjects.bfAdd("myBloomFilter", "item1")).thenReturn(booleanCommandObject); + + Response response = pipeliningBase.bfAdd("myBloomFilter", "item1"); + + assertThat(commands, contains(booleanCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testBfCard() { + when(commandObjects.bfCard("myBloomFilter")).thenReturn(longCommandObject); + + Response response = pipeliningBase.bfCard("myBloomFilter"); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testBfExists() { + when(commandObjects.bfExists("myBloomFilter", "item1")).thenReturn(booleanCommandObject); + + Response response = pipeliningBase.bfExists("myBloomFilter", "item1"); + + assertThat(commands, contains(booleanCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testBfInfo() { + when(commandObjects.bfInfo("myBloomFilter")).thenReturn(mapStringObjectCommandObject); + + Response> response = pipeliningBase.bfInfo("myBloomFilter"); + + assertThat(commands, contains(mapStringObjectCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testBfInsert() { + when(commandObjects.bfInsert("myBloomFilter", "item1", "item2")).thenReturn(listBooleanCommandObject); + + Response> response = pipeliningBase.bfInsert("myBloomFilter", "item1", "item2"); + + assertThat(commands, contains(listBooleanCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testBfInsertWithParams() { + BFInsertParams insertParams = new BFInsertParams().capacity(10000L).error(0.01); + + when(commandObjects.bfInsert("myBloomFilter", insertParams, "item1", "item2")).thenReturn(listBooleanCommandObject); + + Response> response = pipeliningBase.bfInsert("myBloomFilter", insertParams, "item1", "item2"); + + assertThat(commands, contains(listBooleanCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testBfLoadChunk() { + byte[] data = { 1, 2, 3, 4 }; + + when(commandObjects.bfLoadChunk("myBloomFilter", 0L, data)).thenReturn(stringCommandObject); + + Response response = pipeliningBase.bfLoadChunk("myBloomFilter", 0L, data); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testBfMAdd() { + when(commandObjects.bfMAdd("myBloomFilter", "item1", "item2")).thenReturn(listBooleanCommandObject); + + Response> response = pipeliningBase.bfMAdd("myBloomFilter", "item1", "item2"); + + assertThat(commands, contains(listBooleanCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testBfMExists() { + when(commandObjects.bfMExists("myBloomFilter", "item1", "item2")).thenReturn(listBooleanCommandObject); + + Response> response = pipeliningBase.bfMExists("myBloomFilter", "item1", "item2"); + + assertThat(commands, contains(listBooleanCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testBfReserve() { + double errorRate = 0.01; + long capacity = 10000L; + + when(commandObjects.bfReserve("myBloomFilter", errorRate, capacity)).thenReturn(stringCommandObject); + + Response response = pipeliningBase.bfReserve("myBloomFilter", errorRate, capacity); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testBfReserveWithParams() { + double errorRate = 0.01; + long capacity = 10000L; + + BFReserveParams reserveParams = new BFReserveParams().expansion(2); + when(commandObjects.bfReserve("myBloomFilter", errorRate, capacity, reserveParams)).thenReturn(stringCommandObject); + + Response response = pipeliningBase.bfReserve("myBloomFilter", errorRate, capacity, reserveParams); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testBfScanDump() { + when(commandObjects.bfScanDump("myBloomFilter", 0L)).thenReturn(entryLongBytesCommandObject); + + Response> response = pipeliningBase.bfScanDump("myBloomFilter", 0L); + + assertThat(commands, contains(entryLongBytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + +} diff --git a/src/test/java/redis/clients/jedis/mocked/pipeline/PipeliningBaseCountMinSketchCommandsTest.java b/src/test/java/redis/clients/jedis/mocked/pipeline/PipeliningBaseCountMinSketchCommandsTest.java new file mode 100644 index 00000000000..e594ce1aade --- /dev/null +++ b/src/test/java/redis/clients/jedis/mocked/pipeline/PipeliningBaseCountMinSketchCommandsTest.java @@ -0,0 +1,98 @@ +package redis.clients.jedis.mocked.pipeline; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.contains; +import static org.hamcrest.Matchers.is; +import static org.mockito.Mockito.when; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.junit.Test; +import redis.clients.jedis.Response; + +public class PipeliningBaseCountMinSketchCommandsTest extends PipeliningBaseMockedTestBase { + + @Test + public void testCmsIncrBy() { + Map itemIncrements = new HashMap<>(); + itemIncrements.put("item1", 1L); + itemIncrements.put("item2", 2L); + + when(commandObjects.cmsIncrBy("myCountMinSketch", itemIncrements)).thenReturn(listLongCommandObject); + + Response> response = pipeliningBase.cmsIncrBy("myCountMinSketch", itemIncrements); + + assertThat(commands, contains(listLongCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testCmsInfo() { + when(commandObjects.cmsInfo("myCountMinSketch")).thenReturn(mapStringObjectCommandObject); + + Response> response = pipeliningBase.cmsInfo("myCountMinSketch"); + + assertThat(commands, contains(mapStringObjectCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testCmsInitByDim() { + when(commandObjects.cmsInitByDim("myCountMinSketch", 1000L, 5L)).thenReturn(stringCommandObject); + + Response response = pipeliningBase.cmsInitByDim("myCountMinSketch", 1000L, 5L); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testCmsInitByProb() { + double error = 0.01; + double probability = 0.99; + + when(commandObjects.cmsInitByProb("myCountMinSketch", error, probability)).thenReturn(stringCommandObject); + + Response response = pipeliningBase.cmsInitByProb("myCountMinSketch", error, probability); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testCmsMerge() { + when(commandObjects.cmsMerge("mergedCountMinSketch", "cms1", "cms2")).thenReturn(stringCommandObject); + + Response response = pipeliningBase.cmsMerge("mergedCountMinSketch", "cms1", "cms2"); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testCmsMergeWithWeights() { + Map keysAndWeights = new HashMap<>(); + keysAndWeights.put("cms1", 1L); + keysAndWeights.put("cms2", 2L); + + when(commandObjects.cmsMerge("mergedCountMinSketch", keysAndWeights)).thenReturn(stringCommandObject); + + Response response = pipeliningBase.cmsMerge("mergedCountMinSketch", keysAndWeights); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testCmsQuery() { + when(commandObjects.cmsQuery("myCountMinSketch", "item1", "item2")).thenReturn(listLongCommandObject); + + Response> response = pipeliningBase.cmsQuery("myCountMinSketch", "item1", "item2"); + + assertThat(commands, contains(listLongCommandObject)); + assertThat(response, is(predefinedResponse)); + } + +} diff --git a/src/test/java/redis/clients/jedis/mocked/pipeline/PipeliningBaseCuckooFilterCommandsTest.java b/src/test/java/redis/clients/jedis/mocked/pipeline/PipeliningBaseCuckooFilterCommandsTest.java new file mode 100644 index 00000000000..85a26029c7c --- /dev/null +++ b/src/test/java/redis/clients/jedis/mocked/pipeline/PipeliningBaseCuckooFilterCommandsTest.java @@ -0,0 +1,176 @@ +package redis.clients.jedis.mocked.pipeline; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.contains; +import static org.hamcrest.Matchers.is; +import static org.mockito.Mockito.when; + +import java.util.List; +import java.util.Map; + +import org.junit.Test; +import redis.clients.jedis.Response; +import redis.clients.jedis.bloom.CFInsertParams; +import redis.clients.jedis.bloom.CFReserveParams; + +public class PipeliningBaseCuckooFilterCommandsTest extends PipeliningBaseMockedTestBase { + + @Test + public void testCfAdd() { + when(commandObjects.cfAdd("myCuckooFilter", "item1")).thenReturn(booleanCommandObject); + + Response response = pipeliningBase.cfAdd("myCuckooFilter", "item1"); + + assertThat(commands, contains(booleanCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testCfAddNx() { + when(commandObjects.cfAddNx("myCuckooFilter", "item1")).thenReturn(booleanCommandObject); + + Response response = pipeliningBase.cfAddNx("myCuckooFilter", "item1"); + + assertThat(commands, contains(booleanCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testCfCount() { + when(commandObjects.cfCount("myCuckooFilter", "item1")).thenReturn(longCommandObject); + + Response response = pipeliningBase.cfCount("myCuckooFilter", "item1"); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testCfDel() { + when(commandObjects.cfDel("myCuckooFilter", "item1")).thenReturn(booleanCommandObject); + + Response response = pipeliningBase.cfDel("myCuckooFilter", "item1"); + + assertThat(commands, contains(booleanCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testCfExists() { + when(commandObjects.cfExists("myCuckooFilter", "item1")).thenReturn(booleanCommandObject); + + Response response = pipeliningBase.cfExists("myCuckooFilter", "item1"); + + assertThat(commands, contains(booleanCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testCfInfo() { + when(commandObjects.cfInfo("myCuckooFilter")).thenReturn(mapStringObjectCommandObject); + + Response> response = pipeliningBase.cfInfo("myCuckooFilter"); + + assertThat(commands, contains(mapStringObjectCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testCfInsert() { + when(commandObjects.cfInsert("myCuckooFilter", "item1", "item2")).thenReturn(listBooleanCommandObject); + + Response> response = pipeliningBase.cfInsert("myCuckooFilter", "item1", "item2"); + + assertThat(commands, contains(listBooleanCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testCfInsertWithParams() { + CFInsertParams insertParams = new CFInsertParams().capacity(10000L).noCreate(); + + when(commandObjects.cfInsert("myCuckooFilter", insertParams, "item1", "item2")).thenReturn(listBooleanCommandObject); + + Response> response = pipeliningBase.cfInsert("myCuckooFilter", insertParams, "item1", "item2"); + + assertThat(commands, contains(listBooleanCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testCfInsertNx() { + when(commandObjects.cfInsertNx("myCuckooFilter", "item1", "item2")).thenReturn(listBooleanCommandObject); + + Response> response = pipeliningBase.cfInsertNx("myCuckooFilter", "item1", "item2"); + + assertThat(commands, contains(listBooleanCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testCfInsertNxWithParams() { + CFInsertParams insertParams = new CFInsertParams().capacity(10000L).noCreate(); + + when(commandObjects.cfInsertNx("myCuckooFilter", insertParams, "item1", "item2")).thenReturn(listBooleanCommandObject); + + Response> response = pipeliningBase.cfInsertNx("myCuckooFilter", insertParams, "item1", "item2"); + + assertThat(commands, contains(listBooleanCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testCfLoadChunk() { + byte[] data = { 1, 2, 3, 4 }; + + when(commandObjects.cfLoadChunk("myCuckooFilter", 0L, data)).thenReturn(stringCommandObject); + + Response response = pipeliningBase.cfLoadChunk("myCuckooFilter", 0L, data); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testCfMExists() { + when(commandObjects.cfMExists("myCuckooFilter", "item1", "item2", "item3")).thenReturn(listBooleanCommandObject); + + Response> response = pipeliningBase.cfMExists("myCuckooFilter", "item1", "item2", "item3"); + + assertThat(commands, contains(listBooleanCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testCfReserve() { + when(commandObjects.cfReserve("myCuckooFilter", 10000L)).thenReturn(stringCommandObject); + + Response response = pipeliningBase.cfReserve("myCuckooFilter", 10000L); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testCfReserveWithParams() { + CFReserveParams reserveParams = new CFReserveParams().bucketSize(2).maxIterations(500).expansion(2); + + when(commandObjects.cfReserve("myCuckooFilter", 10000L, reserveParams)).thenReturn(stringCommandObject); + + Response response = pipeliningBase.cfReserve("myCuckooFilter", 10000L, reserveParams); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testCfScanDump() { + when(commandObjects.cfScanDump("myCuckooFilter", 0L)).thenReturn(entryLongBytesCommandObject); + + Response> response = pipeliningBase.cfScanDump("myCuckooFilter", 0L); + + assertThat(commands, contains(entryLongBytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + +} diff --git a/src/test/java/redis/clients/jedis/mocked/pipeline/PipeliningBaseGenericCommandsTest.java b/src/test/java/redis/clients/jedis/mocked/pipeline/PipeliningBaseGenericCommandsTest.java new file mode 100644 index 00000000000..1e79ec87a9e --- /dev/null +++ b/src/test/java/redis/clients/jedis/mocked/pipeline/PipeliningBaseGenericCommandsTest.java @@ -0,0 +1,1120 @@ +package redis.clients.jedis.mocked.pipeline; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.contains; +import static org.hamcrest.Matchers.is; +import static org.mockito.Mockito.when; + +import java.util.List; +import java.util.Set; + +import org.junit.Test; +import redis.clients.jedis.Response; +import redis.clients.jedis.args.ExpiryOption; +import redis.clients.jedis.params.MigrateParams; +import redis.clients.jedis.params.RestoreParams; +import redis.clients.jedis.params.ScanParams; +import redis.clients.jedis.params.SortingParams; +import redis.clients.jedis.resps.ScanResult; +import redis.clients.jedis.util.KeyValue; + +public class PipeliningBaseGenericCommandsTest extends PipeliningBaseMockedTestBase { + + @Test + public void testCopy() { + when(commandObjects.copy("srcKey", "dstKey", true)).thenReturn(booleanCommandObject); + + Response response = pipeliningBase.copy("srcKey", "dstKey", true); + + assertThat(commands, contains(booleanCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testCopyBinary() { + byte[] srcKey = "sourceKey".getBytes(); + byte[] dstKey = "destinationKey".getBytes(); + boolean replace = true; + + when(commandObjects.copy(srcKey, dstKey, replace)).thenReturn(booleanCommandObject); + + Response response = pipeliningBase.copy(srcKey, dstKey, replace); + + assertThat(commands, contains(booleanCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testDel() { + when(commandObjects.del("key")).thenReturn(longCommandObject); + + Response response = pipeliningBase.del("key"); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testDelBinary() { + byte[] key = "key".getBytes(); + + when(commandObjects.del(key)).thenReturn(longCommandObject); + + Response response = pipeliningBase.del(key); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testDelMultipleKeys() { + String[] keys = { "key1", "key2", "key3" }; + + when(commandObjects.del(keys)).thenReturn(longCommandObject); + + Response response = pipeliningBase.del(keys); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testDelMultipleKeysBinary() { + byte[] key1 = "key1".getBytes(); + byte[] key2 = "key2".getBytes(); + + when(commandObjects.del(key1, key2)).thenReturn(longCommandObject); + + Response response = pipeliningBase.del(key1, key2); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testDump() { + when(commandObjects.dump("key")).thenReturn(bytesCommandObject); + + Response response = pipeliningBase.dump("key"); + + assertThat(commands, contains(bytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testDumpBinary() { + byte[] key = "key".getBytes(); + + when(commandObjects.dump(key)).thenReturn(bytesCommandObject); + + Response response = pipeliningBase.dump(key); + + assertThat(commands, contains(bytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testExists() { + when(commandObjects.exists("key")).thenReturn(booleanCommandObject); + + Response result = pipeliningBase.exists("key"); + + assertThat(commands, contains(booleanCommandObject)); + assertThat(result, is(predefinedResponse)); + } + + @Test + public void testExistsBinary() { + byte[] key = "key".getBytes(); + + when(commandObjects.exists(key)).thenReturn(booleanCommandObject); + + Response response = pipeliningBase.exists(key); + + assertThat(commands, contains(booleanCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testExistsMultipleKeys() { + when(commandObjects.exists("key1", "key2", "key3")).thenReturn(longCommandObject); + + Response response = pipeliningBase.exists("key1", "key2", "key3"); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testExistsMultipleKeysBinary() { + byte[] key1 = "key1".getBytes(); + byte[] key2 = "key2".getBytes(); + + when(commandObjects.exists(key1, key2)).thenReturn(longCommandObject); + + Response response = pipeliningBase.exists(key1, key2); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testExpire() { + when(commandObjects.expire("key", 60)).thenReturn(longCommandObject); + + Response response = pipeliningBase.expire("key", 60); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testExpireBinary() { + byte[] key = "key".getBytes(); + long seconds = 60L; + + when(commandObjects.expire(key, seconds)).thenReturn(longCommandObject); + + Response response = pipeliningBase.expire(key, seconds); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testExpireWithExpiryOption() { + when(commandObjects.expire("key", 60, ExpiryOption.NX)).thenReturn(longCommandObject); + + Response response = pipeliningBase.expire("key", 60, ExpiryOption.NX); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testExpireWithExpiryOptionBinary() { + byte[] key = "key".getBytes(); + long seconds = 60L; + ExpiryOption expiryOption = ExpiryOption.NX; + + when(commandObjects.expire(key, seconds, expiryOption)).thenReturn(longCommandObject); + + Response response = pipeliningBase.expire(key, seconds, expiryOption); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testExpireAt() { + int unixTime = 1609459200; + + when(commandObjects.expireAt("key", unixTime)).thenReturn(longCommandObject); + + Response response = pipeliningBase.expireAt("key", unixTime); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testExpireAtBinary() { + byte[] key = "key".getBytes(); + long unixTime = 1625097600L; + + when(commandObjects.expireAt(key, unixTime)).thenReturn(longCommandObject); + + Response response = pipeliningBase.expireAt(key, unixTime); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testExpireAtWithExpiryOption() { + int unixTime = 1609459200; + + when(commandObjects.expireAt("key", unixTime, ExpiryOption.NX)).thenReturn(longCommandObject); + + Response response = pipeliningBase.expireAt("key", unixTime, ExpiryOption.NX); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testExpireAtWithExpiryOptionBinary() { + byte[] key = "key".getBytes(); + long unixTime = 1625097600L; + ExpiryOption expiryOption = ExpiryOption.NX; + + when(commandObjects.expireAt(key, unixTime, expiryOption)).thenReturn(longCommandObject); + + Response response = pipeliningBase.expireAt(key, unixTime, expiryOption); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testExpireTime() { + when(commandObjects.expireTime("key")).thenReturn(longCommandObject); + + Response response = pipeliningBase.expireTime("key"); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testExpireTimeBinary() { + byte[] key = "key".getBytes(); + + when(commandObjects.expireTime(key)).thenReturn(longCommandObject); + + Response response = pipeliningBase.expireTime(key); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testKeys() { + when(commandObjects.keys("pattern")).thenReturn(setStringCommandObject); + + Response> response = pipeliningBase.keys("pattern"); + + assertThat(commands, contains(setStringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testKeysBinary() { + byte[] pattern = "*".getBytes(); + + when(commandObjects.keys(pattern)).thenReturn(setBytesCommandObject); + + Response> response = pipeliningBase.keys(pattern); + + assertThat(commands, contains(setBytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testMigrate() { + when(commandObjects.migrate("host", 6379, "key", 5000)).thenReturn(stringCommandObject); + + Response response = pipeliningBase.migrate("host", 6379, "key", 5000); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testMigrateBinary() { + String host = "localhost"; + int port = 6379; + byte[] key = "key".getBytes(); + int timeout = 1000; + + when(commandObjects.migrate(host, port, key, timeout)).thenReturn(stringCommandObject); + + Response response = pipeliningBase.migrate(host, port, key, timeout); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testMigrateMultipleKeys() { + MigrateParams params = new MigrateParams(); + String[] keys = { "key1", "key2" }; + + when(commandObjects.migrate("host", 6379, 5000, params, keys)).thenReturn(stringCommandObject); + + Response response = pipeliningBase.migrate("host", 6379, 5000, params, keys); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testMigrateMultipleKeysBinary() { + String host = "localhost"; + int port = 6379; + int timeout = 1000; + MigrateParams params = MigrateParams.migrateParams().copy().replace(); + byte[] key1 = "key1".getBytes(); + byte[] key2 = "key2".getBytes(); + + when(commandObjects.migrate(host, port, timeout, params, key1, key2)).thenReturn(stringCommandObject); + + Response response = pipeliningBase.migrate(host, port, timeout, params, key1, key2); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testObjectEncoding() { + when(commandObjects.objectEncoding("key")).thenReturn(stringCommandObject); + + Response response = pipeliningBase.objectEncoding("key"); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testObjectEncodingBinary() { + byte[] key = "key".getBytes(); + + when(commandObjects.objectEncoding(key)).thenReturn(bytesCommandObject); + + Response response = pipeliningBase.objectEncoding(key); + + assertThat(commands, contains(bytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testObjectFreq() { + when(commandObjects.objectFreq("key")).thenReturn(longCommandObject); + + Response response = pipeliningBase.objectFreq("key"); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testObjectFreqBinary() { + byte[] key = "key".getBytes(); + + when(commandObjects.objectFreq(key)).thenReturn(longCommandObject); + + Response response = pipeliningBase.objectFreq(key); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testObjectIdletime() { + when(commandObjects.objectIdletime("key")).thenReturn(longCommandObject); + + Response response = pipeliningBase.objectIdletime("key"); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testObjectIdletimeBinary() { + byte[] key = "key".getBytes(); + + when(commandObjects.objectIdletime(key)).thenReturn(longCommandObject); + + Response response = pipeliningBase.objectIdletime(key); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testObjectRefcount() { + when(commandObjects.objectRefcount("key")).thenReturn(longCommandObject); + + Response response = pipeliningBase.objectRefcount("key"); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testObjectRefcountBinary() { + byte[] key = "key".getBytes(); + + when(commandObjects.objectRefcount(key)).thenReturn(longCommandObject); + + Response response = pipeliningBase.objectRefcount(key); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testPersist() { + when(commandObjects.persist("key")).thenReturn(longCommandObject); + + Response response = pipeliningBase.persist("key"); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testPersistBinary() { + byte[] key = "key".getBytes(); + + when(commandObjects.persist(key)).thenReturn(longCommandObject); + + Response response = pipeliningBase.persist(key); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testPexpire() { + when(commandObjects.pexpire("key", 100000)).thenReturn(longCommandObject); + + Response response = pipeliningBase.pexpire("key", 100000); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testPexpireBinary() { + byte[] key = "key".getBytes(); + long milliseconds = 60000L; + + when(commandObjects.pexpire(key, milliseconds)).thenReturn(longCommandObject); + + Response response = pipeliningBase.pexpire(key, milliseconds); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testPexpireWithExpiryOption() { + when(commandObjects.pexpire("key", 100000, ExpiryOption.NX)).thenReturn(longCommandObject); + + Response response = pipeliningBase.pexpire("key", 100000, ExpiryOption.NX); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testPexpireWithExpiryOptionBinary() { + byte[] key = "key".getBytes(); + long milliseconds = 60000L; + ExpiryOption expiryOption = ExpiryOption.NX; + + when(commandObjects.pexpire(key, milliseconds, expiryOption)).thenReturn(longCommandObject); + + Response response = pipeliningBase.pexpire(key, milliseconds, expiryOption); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testPexpireAt() { + long millisecondsTimestamp = 1609459200000L; + + when(commandObjects.pexpireAt("key", millisecondsTimestamp)).thenReturn(longCommandObject); + + Response response = pipeliningBase.pexpireAt("key", millisecondsTimestamp); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testPexpireAtBinary() { + byte[] key = "key".getBytes(); + long millisecondsTimestamp = 1625097600000L; + + when(commandObjects.pexpireAt(key, millisecondsTimestamp)).thenReturn(longCommandObject); + + Response response = pipeliningBase.pexpireAt(key, millisecondsTimestamp); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testPexpireAtWithExpiryOption() { + long millisecondsTimestamp = 1609459200000L; + + when(commandObjects.pexpireAt("key", millisecondsTimestamp, ExpiryOption.NX)).thenReturn(longCommandObject); + + Response response = pipeliningBase.pexpireAt("key", millisecondsTimestamp, ExpiryOption.NX); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testPexpireAtWithExpiryOptionBinary() { + byte[] key = "key".getBytes(); + long millisecondsTimestamp = 1625097600000L; + ExpiryOption expiryOption = ExpiryOption.NX; + + when(commandObjects.pexpireAt(key, millisecondsTimestamp, expiryOption)).thenReturn(longCommandObject); + + Response response = pipeliningBase.pexpireAt(key, millisecondsTimestamp, expiryOption); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testPexpireTime() { + when(commandObjects.pexpireTime("key")).thenReturn(longCommandObject); + + Response response = pipeliningBase.pexpireTime("key"); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testPexpireTimeBinary() { + byte[] key = "key".getBytes(); + + when(commandObjects.pexpireTime(key)).thenReturn(longCommandObject); + + Response response = pipeliningBase.pexpireTime(key); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testPttl() { + when(commandObjects.pttl("key")).thenReturn(longCommandObject); + + Response response = pipeliningBase.pttl("key"); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testPttlBinary() { + byte[] key = "key".getBytes(); + + when(commandObjects.pttl(key)).thenReturn(longCommandObject); + + Response response = pipeliningBase.pttl(key); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testRandomKey() { + when(commandObjects.randomKey()).thenReturn(stringCommandObject); + + Response response = pipeliningBase.randomKey(); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testRandomBinaryKey() { + when(commandObjects.randomBinaryKey()).thenReturn(bytesCommandObject); + + Response response = pipeliningBase.randomBinaryKey(); + + assertThat(commands, contains(bytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testRename() { + when(commandObjects.rename("oldkey", "newkey")).thenReturn(stringCommandObject); + + Response response = pipeliningBase.rename("oldkey", "newkey"); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testRenameBinary() { + byte[] oldkey = "oldKey".getBytes(); + byte[] newkey = "newKey".getBytes(); + + when(commandObjects.rename(oldkey, newkey)).thenReturn(stringCommandObject); + + Response response = pipeliningBase.rename(oldkey, newkey); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testRenamenx() { + when(commandObjects.renamenx("oldkey", "newkey")).thenReturn(longCommandObject); + + Response response = pipeliningBase.renamenx("oldkey", "newkey"); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testRenamenxBinary() { + byte[] oldkey = "oldKey".getBytes(); + byte[] newkey = "newKey".getBytes(); + + when(commandObjects.renamenx(oldkey, newkey)).thenReturn(longCommandObject); + + Response response = pipeliningBase.renamenx(oldkey, newkey); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testRestore() { + byte[] serializedValue = new byte[]{ 1, 2, 3 }; + long ttl = 1000L; + + when(commandObjects.restore("key", ttl, serializedValue)).thenReturn(stringCommandObject); + + Response response = pipeliningBase.restore("key", ttl, serializedValue); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testRestoreBinary() { + byte[] key = "key".getBytes(); + long ttl = 0L; + byte[] serializedValue = "serialized".getBytes(); + + when(commandObjects.restore(key, ttl, serializedValue)).thenReturn(stringCommandObject); + + Response response = pipeliningBase.restore(key, ttl, serializedValue); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testRestoreWithParams() { + byte[] serializedValue = new byte[]{ 1, 2, 3 }; + long ttl = 1000L; + RestoreParams params = new RestoreParams(); + + when(commandObjects.restore("key", ttl, serializedValue, params)).thenReturn(stringCommandObject); + + Response response = pipeliningBase.restore("key", ttl, serializedValue, params); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testRestoreWithParamsBinary() { + byte[] key = "key".getBytes(); + long ttl = 0L; + byte[] serializedValue = "serialized".getBytes(); + RestoreParams params = RestoreParams.restoreParams().replace(); + + when(commandObjects.restore(key, ttl, serializedValue, params)).thenReturn(stringCommandObject); + + Response response = pipeliningBase.restore(key, ttl, serializedValue, params); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testScan() { + when(commandObjects.scan("0")).thenReturn(scanResultStringCommandObject); + + Response> response = pipeliningBase.scan("0"); + + assertThat(commands, contains(scanResultStringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testScanBinary() { + byte[] cursor = "0".getBytes(); + + when(commandObjects.scan(cursor)).thenReturn(scanResultBytesCommandObject); + + Response> response = pipeliningBase.scan(cursor); + + assertThat(commands, contains(scanResultBytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testScanWithParams() { + ScanParams scanParams = new ScanParams(); + + when(commandObjects.scan("0", scanParams)).thenReturn(scanResultStringCommandObject); + + Response> response = pipeliningBase.scan("0", scanParams); + + assertThat(commands, contains(scanResultStringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testScanWithParamsBinary() { + byte[] cursor = "0".getBytes(); + ScanParams params = new ScanParams().match("*").count(10); + + when(commandObjects.scan(cursor, params)).thenReturn(scanResultBytesCommandObject); + + Response> response = pipeliningBase.scan(cursor, params); + + assertThat(commands, contains(scanResultBytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testScanWithType() { + ScanParams scanParams = new ScanParams(); + + when(commandObjects.scan("0", scanParams, "type")).thenReturn(scanResultStringCommandObject); + + Response> response = pipeliningBase.scan("0", scanParams, "type"); + + assertThat(commands, contains(scanResultStringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testScanWithTypeBinary() { + byte[] cursor = "0".getBytes(); + ScanParams params = new ScanParams().match("*").count(10); + byte[] type = "string".getBytes(); + + when(commandObjects.scan(cursor, params, type)).thenReturn(scanResultBytesCommandObject); + + Response> response = pipeliningBase.scan(cursor, params, type); + + assertThat(commands, contains(scanResultBytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testSort() { + when(commandObjects.sort("key")).thenReturn(listStringCommandObject); + + Response> response = pipeliningBase.sort("key"); + + assertThat(commands, contains(listStringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testSortBinary() { + byte[] key = "key".getBytes(); + + when(commandObjects.sort(key)).thenReturn(listBytesCommandObject); + + Response> response = pipeliningBase.sort(key); + + assertThat(commands, contains(listBytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testSortWithParams() { + SortingParams sortingParams = new SortingParams(); + + when(commandObjects.sort("key", sortingParams)).thenReturn(listStringCommandObject); + + Response> response = pipeliningBase.sort("key", sortingParams); + + assertThat(commands, contains(listStringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testSortWithParamsBinary() { + byte[] key = "key".getBytes(); + SortingParams sortingParams = new SortingParams().alpha().limit(0, 10); + + when(commandObjects.sort(key, sortingParams)).thenReturn(listBytesCommandObject); + + Response> response = pipeliningBase.sort(key, sortingParams); + + assertThat(commands, contains(listBytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testSortStore() { + when(commandObjects.sort("key", "dstKey")).thenReturn(longCommandObject); + + Response response = pipeliningBase.sort("key", "dstKey"); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testSortStoreBinary() { + byte[] key = "key".getBytes(); + byte[] dstkey = "dstkey".getBytes(); + + when(commandObjects.sort(key, dstkey)).thenReturn(longCommandObject); + + Response response = pipeliningBase.sort(key, dstkey); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testSortStoreWithParams() { + SortingParams sortingParams = new SortingParams(); + + when(commandObjects.sort("key", sortingParams, "dstKey")).thenReturn(longCommandObject); + + Response response = pipeliningBase.sort("key", sortingParams, "dstKey"); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testSortStoreWithParamsBinary() { + byte[] key = "key".getBytes(); + byte[] dstkey = "dstkey".getBytes(); + SortingParams sortingParams = new SortingParams().alpha().limit(0, 10); + + when(commandObjects.sort(key, sortingParams, dstkey)).thenReturn(longCommandObject); + + Response response = pipeliningBase.sort(key, sortingParams, dstkey); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testSortReadonly() { + SortingParams sortingParams = new SortingParams(); + + when(commandObjects.sortReadonly("key", sortingParams)).thenReturn(listStringCommandObject); + + Response> response = pipeliningBase.sortReadonly("key", sortingParams); + + assertThat(commands, contains(listStringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testSortReadonlyBinary() { + byte[] key = "key".getBytes(); + SortingParams sortingParams = new SortingParams().alpha().limit(0, 10); + + when(commandObjects.sortReadonly(key, sortingParams)).thenReturn(listBytesCommandObject); + + Response> response = pipeliningBase.sortReadonly(key, sortingParams); + + assertThat(commands, contains(listBytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testTouch() { + when(commandObjects.touch("key")).thenReturn(longCommandObject); + + Response response = pipeliningBase.touch("key"); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testTouchBinary() { + byte[] key = "key".getBytes(); + + when(commandObjects.touch(key)).thenReturn(longCommandObject); + + Response response = pipeliningBase.touch(key); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testTouchMultipleKeys() { + String[] keys = { "key1", "key2", "key3" }; + + when(commandObjects.touch(keys)).thenReturn(longCommandObject); + + Response response = pipeliningBase.touch(keys); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testTouchMultipleKeysBinary() { + byte[] key1 = "key1".getBytes(); + byte[] key2 = "key2".getBytes(); + + when(commandObjects.touch(key1, key2)).thenReturn(longCommandObject); + + Response response = pipeliningBase.touch(key1, key2); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testTtl() { + when(commandObjects.ttl("key")).thenReturn(longCommandObject); + + Response response = pipeliningBase.ttl("key"); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testTtlBinary() { + byte[] key = "key".getBytes(); + + when(commandObjects.ttl(key)).thenReturn(longCommandObject); + + Response response = pipeliningBase.ttl(key); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testType() { + when(commandObjects.type("key")).thenReturn(stringCommandObject); + + Response response = pipeliningBase.type("key"); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testTypeBinary() { + byte[] key = "key".getBytes(); + + when(commandObjects.type(key)).thenReturn(stringCommandObject); + + Response response = pipeliningBase.type(key); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testUnlink() { + when(commandObjects.unlink("key")).thenReturn(longCommandObject); + + Response response = pipeliningBase.unlink("key"); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testUnlinkBinary() { + byte[] key = "key".getBytes(); + + when(commandObjects.unlink(key)).thenReturn(longCommandObject); + + Response response = pipeliningBase.unlink(key); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testUnlinkMultipleKeys() { + String[] keys = { "key1", "key2", "key3" }; + + when(commandObjects.unlink(keys)).thenReturn(longCommandObject); + + Response response = pipeliningBase.unlink(keys); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testUnlinkMultipleKeysBinary() { + byte[] key1 = "key1".getBytes(); + byte[] key2 = "key2".getBytes(); + + when(commandObjects.unlink(key1, key2)).thenReturn(longCommandObject); + + Response response = pipeliningBase.unlink(key1, key2); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testWaitReplicas() { + int replicas = 2; + long timeout = 1000L; + + when(commandObjects.waitReplicas("key", replicas, timeout)).thenReturn(longCommandObject); + + Response response = pipeliningBase.waitReplicas("key", replicas, timeout); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testWaitReplicasBinary() { + byte[] sampleKey = "sampleKey".getBytes(); + int replicas = 1; + long timeout = 1000; + + when(commandObjects.waitReplicas(sampleKey, replicas, timeout)).thenReturn(longCommandObject); + + Response response = pipeliningBase.waitReplicas(sampleKey, replicas, timeout); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testWaitAOF() { + long numLocal = 1L; + long numReplicas = 1L; + long timeout = 1000L; + + when(commandObjects.waitAOF("key", numLocal, numReplicas, timeout)).thenReturn(keyValueLongLongCommandObject); + + Response> response = pipeliningBase.waitAOF("key", numLocal, numReplicas, timeout); + + assertThat(commands, contains(keyValueLongLongCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testWaitAOFBinary() { + byte[] sampleKey = "sampleKey".getBytes(); + long numLocal = 1; + long numReplicas = 1; + long timeout = 1000; + + when(commandObjects.waitAOF(sampleKey, numLocal, numReplicas, timeout)).thenReturn(keyValueLongLongCommandObject); + + Response> response = pipeliningBase.waitAOF(sampleKey, numLocal, numReplicas, timeout); + + assertThat(commands, contains(keyValueLongLongCommandObject)); + assertThat(response, is(predefinedResponse)); + } + +} diff --git a/src/test/java/redis/clients/jedis/mocked/pipeline/PipeliningBaseGeospatialCommandsTest.java b/src/test/java/redis/clients/jedis/mocked/pipeline/PipeliningBaseGeospatialCommandsTest.java new file mode 100644 index 00000000000..114bc07dc0b --- /dev/null +++ b/src/test/java/redis/clients/jedis/mocked/pipeline/PipeliningBaseGeospatialCommandsTest.java @@ -0,0 +1,809 @@ +package redis.clients.jedis.mocked.pipeline; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.contains; +import static org.hamcrest.Matchers.is; +import static org.mockito.Mockito.when; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.junit.Test; +import redis.clients.jedis.GeoCoordinate; +import redis.clients.jedis.Response; +import redis.clients.jedis.args.GeoUnit; +import redis.clients.jedis.params.GeoAddParams; +import redis.clients.jedis.params.GeoRadiusParam; +import redis.clients.jedis.params.GeoRadiusStoreParam; +import redis.clients.jedis.params.GeoSearchParam; +import redis.clients.jedis.resps.GeoRadiusResponse; + +public class PipeliningBaseGeospatialCommandsTest extends PipeliningBaseMockedTestBase { + + @Test + public void testGeoadd() { + when(commandObjects.geoadd("key", 13.361389, 38.115556, "member")).thenReturn(longCommandObject); + + Response response = pipeliningBase.geoadd("key", 13.361389, 38.115556, "member"); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testGeoaddBinary() { + byte[] key = "location".getBytes(); + double longitude = 13.361389; + double latitude = 38.115556; + byte[] member = "Sicily".getBytes(); + + when(commandObjects.geoadd(key, longitude, latitude, member)).thenReturn(longCommandObject); + + Response response = pipeliningBase.geoadd(key, longitude, latitude, member); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testGeoaddMap() { + Map memberCoordinateMap = new HashMap<>(); + memberCoordinateMap.put("member", new GeoCoordinate(13.361389, 38.115556)); + + when(commandObjects.geoadd("key", memberCoordinateMap)).thenReturn(longCommandObject); + + Response response = pipeliningBase.geoadd("key", memberCoordinateMap); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testGeoaddMapBinary() { + byte[] key = "location".getBytes(); + + Map memberCoordinateMap = new HashMap<>(); + memberCoordinateMap.put("Palermo".getBytes(), new GeoCoordinate(13.361389, 38.115556)); + + when(commandObjects.geoadd(key, memberCoordinateMap)).thenReturn(longCommandObject); + + Response response = pipeliningBase.geoadd(key, memberCoordinateMap); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testGeoaddMapWithParams() { + GeoAddParams params = new GeoAddParams(); + + Map memberCoordinateMap = new HashMap<>(); + memberCoordinateMap.put("member", new GeoCoordinate(13.361389, 38.115556)); + + when(commandObjects.geoadd("key", params, memberCoordinateMap)).thenReturn(longCommandObject); + + Response response = pipeliningBase.geoadd("key", params, memberCoordinateMap); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testGeoaddMapWithParamsBinary() { + byte[] key = "location".getBytes(); + GeoAddParams params = GeoAddParams.geoAddParams(); + + Map memberCoordinateMap = new HashMap<>(); + memberCoordinateMap.put("Palermo".getBytes(), new GeoCoordinate(13.361389, 38.115556)); + + when(commandObjects.geoadd(key, params, memberCoordinateMap)).thenReturn(longCommandObject); + + Response response = pipeliningBase.geoadd(key, params, memberCoordinateMap); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testGeodist() { + when(commandObjects.geodist("key", "member1", "member2")).thenReturn(doubleCommandObject); + + Response response = pipeliningBase.geodist("key", "member1", "member2"); + + assertThat(commands, contains(doubleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testGeodistBinary() { + byte[] key = "location".getBytes(); + byte[] member1 = "Palermo".getBytes(); + byte[] member2 = "Catania".getBytes(); + + when(commandObjects.geodist(key, member1, member2)).thenReturn(doubleCommandObject); + + Response response = pipeliningBase.geodist(key, member1, member2); + + assertThat(commands, contains(doubleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testGeodistWithUnit() { + GeoUnit unit = GeoUnit.KM; + + when(commandObjects.geodist("key", "member1", "member2", unit)).thenReturn(doubleCommandObject); + + Response response = pipeliningBase.geodist("key", "member1", "member2", unit); + + assertThat(commands, contains(doubleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testGeodistWithUnitBinary() { + byte[] key = "location".getBytes(); + byte[] member1 = "Palermo".getBytes(); + byte[] member2 = "Catania".getBytes(); + GeoUnit unit = GeoUnit.KM; + + when(commandObjects.geodist(key, member1, member2, unit)).thenReturn(doubleCommandObject); + + Response response = pipeliningBase.geodist(key, member1, member2, unit); + + assertThat(commands, contains(doubleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testGeohash() { + when(commandObjects.geohash("key", "member1", "member2")).thenReturn(listStringCommandObject); + + Response> response = pipeliningBase.geohash("key", "member1", "member2"); + + assertThat(commands, contains(listStringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testGeohashBinary() { + byte[] key = "location".getBytes(); + byte[] member = "Palermo".getBytes(); + + when(commandObjects.geohash(key, member)).thenReturn(listBytesCommandObject); + + Response> response = pipeliningBase.geohash(key, member); + + assertThat(commands, contains(listBytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testGeopos() { + when(commandObjects.geopos("key", "member1", "member2")).thenReturn(listGeoCoordinateCommandObject); + + Response> response = pipeliningBase.geopos("key", "member1", "member2"); + + assertThat(commands, contains(listGeoCoordinateCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testGeoposBinary() { + byte[] key = "location".getBytes(); + byte[] member = "Palermo".getBytes(); + + when(commandObjects.geopos(key, member)).thenReturn(listGeoCoordinateCommandObject); + + Response> response = pipeliningBase.geopos(key, member); + + assertThat(commands, contains(listGeoCoordinateCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testGeoradius() { + when(commandObjects.georadius("key", 15.0, 37.0, 100.0, GeoUnit.KM)) + .thenReturn(listGeoRadiusResponseCommandObject); + + Response> response = + pipeliningBase.georadius("key", 15.0, 37.0, 100.0, GeoUnit.KM); + + assertThat(commands, contains(listGeoRadiusResponseCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testGeoradiusBinary() { + byte[] key = "location".getBytes(); + double longitude = 13.361389; + double latitude = 38.115556; + double radius = 100; + GeoUnit unit = GeoUnit.KM; + + when(commandObjects.georadius(key, longitude, latitude, radius, unit)).thenReturn(listGeoRadiusResponseCommandObject); + + Response> response = pipeliningBase.georadius(key, longitude, latitude, radius, unit); + + assertThat(commands, contains(listGeoRadiusResponseCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testGeoradiusReadonly() { + when(commandObjects.georadiusReadonly("key", 15.0, 37.0, 100.0, GeoUnit.KM)) + .thenReturn(listGeoRadiusResponseCommandObject); + + Response> response = + pipeliningBase.georadiusReadonly("key", 15.0, 37.0, 100.0, GeoUnit.KM); + + assertThat(commands, contains(listGeoRadiusResponseCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testGeoradiusReadonlyBinary() { + byte[] key = "location".getBytes(); + double longitude = 13.361389; + double latitude = 38.115556; + double radius = 100; + GeoUnit unit = GeoUnit.KM; + + when(commandObjects.georadiusReadonly(key, longitude, latitude, radius, unit)).thenReturn(listGeoRadiusResponseCommandObject); + + Response> response = pipeliningBase.georadiusReadonly(key, longitude, latitude, radius, unit); + + assertThat(commands, contains(listGeoRadiusResponseCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testGeoradiusWithParam() { + GeoRadiusParam param = GeoRadiusParam.geoRadiusParam(); + + when(commandObjects.georadius("key", 15.0, 37.0, 100.0, GeoUnit.KM, param)) + .thenReturn(listGeoRadiusResponseCommandObject); + + Response> response = + pipeliningBase.georadius("key", 15.0, 37.0, 100.0, GeoUnit.KM, param); + + assertThat(commands, contains(listGeoRadiusResponseCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testGeoradiusWithParamBinary() { + byte[] key = "location".getBytes(); + double longitude = 13.361389; + double latitude = 38.115556; + double radius = 100; + GeoUnit unit = GeoUnit.KM; + GeoRadiusParam param = GeoRadiusParam.geoRadiusParam(); + + when(commandObjects.georadius(key, longitude, latitude, radius, unit, param)).thenReturn(listGeoRadiusResponseCommandObject); + + Response> response = pipeliningBase.georadius(key, longitude, latitude, radius, unit, param); + + assertThat(commands, contains(listGeoRadiusResponseCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testGeoradiusReadonlyWithParam() { + GeoRadiusParam param = GeoRadiusParam.geoRadiusParam(); + + when(commandObjects.georadiusReadonly("key", 15.0, 37.0, 100.0, GeoUnit.KM, param)) + .thenReturn(listGeoRadiusResponseCommandObject); + + Response> response = + pipeliningBase.georadiusReadonly("key", 15.0, 37.0, 100.0, GeoUnit.KM, param); + + assertThat(commands, contains(listGeoRadiusResponseCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testGeoradiusReadonlyWithParamBinary() { + byte[] key = "location".getBytes(); + double longitude = 13.361389; + double latitude = 38.115556; + double radius = 100; + GeoUnit unit = GeoUnit.KM; + GeoRadiusParam param = GeoRadiusParam.geoRadiusParam(); + + when(commandObjects.georadiusReadonly(key, longitude, latitude, radius, unit, param)).thenReturn(listGeoRadiusResponseCommandObject); + + Response> response = pipeliningBase.georadiusReadonly(key, longitude, latitude, radius, unit, param); + + assertThat(commands, contains(listGeoRadiusResponseCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testGeoradiusByMember() { + when(commandObjects.georadiusByMember("key", "member", 100.0, GeoUnit.KM)) + .thenReturn(listGeoRadiusResponseCommandObject); + + Response> response = + pipeliningBase.georadiusByMember("key", "member", 100.0, GeoUnit.KM); + + assertThat(commands, contains(listGeoRadiusResponseCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testGeoradiusByMemberBinary() { + byte[] key = "location".getBytes(); + byte[] member = "Palermo".getBytes(); + double radius = 100; + GeoUnit unit = GeoUnit.KM; + + when(commandObjects.georadiusByMember(key, member, radius, unit)).thenReturn(listGeoRadiusResponseCommandObject); + + Response> response = pipeliningBase.georadiusByMember(key, member, radius, unit); + + assertThat(commands, contains(listGeoRadiusResponseCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testGeoradiusByMemberReadonly() { + when(commandObjects.georadiusByMemberReadonly("key", "member", 100.0, GeoUnit.KM)) + .thenReturn(listGeoRadiusResponseCommandObject); + + Response> response = + pipeliningBase.georadiusByMemberReadonly("key", "member", 100.0, GeoUnit.KM); + + assertThat(commands, contains(listGeoRadiusResponseCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testGeoradiusByMemberReadonlyBinary() { + byte[] key = "location".getBytes(); + byte[] member = "Palermo".getBytes(); + double radius = 100; + GeoUnit unit = GeoUnit.KM; + + when(commandObjects.georadiusByMemberReadonly(key, member, radius, unit)).thenReturn(listGeoRadiusResponseCommandObject); + + Response> response = pipeliningBase.georadiusByMemberReadonly(key, member, radius, unit); + + assertThat(commands, contains(listGeoRadiusResponseCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testGeoradiusByMemberWithParam() { + GeoRadiusParam param = GeoRadiusParam.geoRadiusParam(); + + when(commandObjects.georadiusByMember("key", "member", 100.0, GeoUnit.KM, param)) + .thenReturn(listGeoRadiusResponseCommandObject); + + Response> response = pipeliningBase + .georadiusByMember("key", "member", 100.0, GeoUnit.KM, param); + + assertThat(commands, contains(listGeoRadiusResponseCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testGeoradiusByMemberWithParamBinary() { + byte[] key = "location".getBytes(); + byte[] member = "Palermo".getBytes(); + double radius = 100; + GeoUnit unit = GeoUnit.KM; + GeoRadiusParam param = GeoRadiusParam.geoRadiusParam(); + + when(commandObjects.georadiusByMember(key, member, radius, unit, param)).thenReturn(listGeoRadiusResponseCommandObject); + + Response> response = pipeliningBase.georadiusByMember(key, member, radius, unit, param); + + assertThat(commands, contains(listGeoRadiusResponseCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testGeoradiusByMemberReadonlyWithParam() { + GeoRadiusParam param = GeoRadiusParam.geoRadiusParam(); + + when(commandObjects.georadiusByMemberReadonly("key", "member", 100.0, GeoUnit.KM, param)) + .thenReturn(listGeoRadiusResponseCommandObject); + + Response> response = pipeliningBase + .georadiusByMemberReadonly("key", "member", 100.0, GeoUnit.KM, param); + + assertThat(commands, contains(listGeoRadiusResponseCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testGeoradiusByMemberReadonlyWithParamBinary() { + byte[] key = "location".getBytes(); + byte[] member = "Palermo".getBytes(); + double radius = 100; + GeoUnit unit = GeoUnit.KM; + GeoRadiusParam param = GeoRadiusParam.geoRadiusParam(); + + when(commandObjects.georadiusByMemberReadonly(key, member, radius, unit, param)).thenReturn(listGeoRadiusResponseCommandObject); + + Response> response = pipeliningBase.georadiusByMemberReadonly(key, member, radius, unit, param); + + assertThat(commands, contains(listGeoRadiusResponseCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testGeoradiusStore() { + GeoRadiusParam param = GeoRadiusParam.geoRadiusParam(); + GeoRadiusStoreParam storeParam = GeoRadiusStoreParam.geoRadiusStoreParam().store("storeKey"); + + when(commandObjects.georadiusStore("key", 15.0, 37.0, 100.0, GeoUnit.KM, param, storeParam)) + .thenReturn(longCommandObject); + + Response response = pipeliningBase + .georadiusStore("key", 15.0, 37.0, 100.0, GeoUnit.KM, param, storeParam); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testGeoradiusStoreBinary() { + byte[] key = "location".getBytes(); + double longitude = 13.361389; + double latitude = 38.115556; + double radius = 100; + GeoUnit unit = GeoUnit.KM; + GeoRadiusParam param = GeoRadiusParam.geoRadiusParam(); + GeoRadiusStoreParam storeParam = GeoRadiusStoreParam.geoRadiusStoreParam().store("storeKey"); + + when(commandObjects.georadiusStore(key, longitude, latitude, radius, unit, param, storeParam)).thenReturn(longCommandObject); + + Response response = pipeliningBase.georadiusStore(key, longitude, latitude, radius, unit, param, storeParam); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testGeoradiusByMemberStore() { + GeoRadiusParam param = GeoRadiusParam.geoRadiusParam(); + GeoRadiusStoreParam storeParam = GeoRadiusStoreParam.geoRadiusStoreParam().store("storeKey"); + + when(commandObjects.georadiusByMemberStore("key", "member", 100.0, GeoUnit.KM, param, storeParam)) + .thenReturn(longCommandObject); + + Response response = pipeliningBase + .georadiusByMemberStore("key", "member", 100.0, GeoUnit.KM, param, storeParam); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testGeoradiusByMemberStoreBinary() { + byte[] key = "location".getBytes(); + byte[] member = "Palermo".getBytes(); + double radius = 100; + GeoUnit unit = GeoUnit.KM; + GeoRadiusParam param = GeoRadiusParam.geoRadiusParam(); + GeoRadiusStoreParam storeParam = GeoRadiusStoreParam.geoRadiusStoreParam().store("storeKey"); + + when(commandObjects.georadiusByMemberStore(key, member, radius, unit, param, storeParam)).thenReturn(longCommandObject); + + Response response = pipeliningBase.georadiusByMemberStore(key, member, radius, unit, param, storeParam); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testGeosearchByMemberRadius() { + when(commandObjects.geosearch("key", "member", 100.0, GeoUnit.KM)) + .thenReturn(listGeoRadiusResponseCommandObject); + + Response> response = pipeliningBase + .geosearch("key", "member", 100.0, GeoUnit.KM); + + assertThat(commands, contains(listGeoRadiusResponseCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testGeosearchByMemberRadiusBinary() { + byte[] key = "location".getBytes(); + byte[] member = "Palermo".getBytes(); + double radius = 100; + GeoUnit unit = GeoUnit.KM; + + when(commandObjects.geosearch(key, member, radius, unit)).thenReturn(listGeoRadiusResponseCommandObject); + + Response> response = pipeliningBase.geosearch(key, member, radius, unit); + + assertThat(commands, contains(listGeoRadiusResponseCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testGeosearchByCoordRadius() { + GeoCoordinate coord = new GeoCoordinate(15.0, 37.0); + + when(commandObjects.geosearch("key", coord, 100.0, GeoUnit.KM)) + .thenReturn(listGeoRadiusResponseCommandObject); + + Response> response = pipeliningBase.geosearch("key", coord, 100.0, GeoUnit.KM); + + assertThat(commands, contains(listGeoRadiusResponseCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testGeosearchByCoordRadiusBinary() { + byte[] key = "location".getBytes(); + GeoCoordinate coord = new GeoCoordinate(13.361389, 38.115556); + double radius = 100; + GeoUnit unit = GeoUnit.KM; + + when(commandObjects.geosearch(key, coord, radius, unit)).thenReturn(listGeoRadiusResponseCommandObject); + + Response> response = pipeliningBase.geosearch(key, coord, radius, unit); + + assertThat(commands, contains(listGeoRadiusResponseCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testGeosearchByMemberBox() { + when(commandObjects.geosearch("key", "member", 50.0, 50.0, GeoUnit.KM)) + .thenReturn(listGeoRadiusResponseCommandObject); + + Response> response = pipeliningBase + .geosearch("key", "member", 50.0, 50.0, GeoUnit.KM); + + assertThat(commands, contains(listGeoRadiusResponseCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testGeosearchByMemberBoxBinary() { + byte[] key = "location".getBytes(); + byte[] member = "Palermo".getBytes(); + double width = 200; + double height = 100; + GeoUnit unit = GeoUnit.KM; + + when(commandObjects.geosearch(key, member, width, height, unit)).thenReturn(listGeoRadiusResponseCommandObject); + + Response> response = pipeliningBase.geosearch(key, member, width, height, unit); + + assertThat(commands, contains(listGeoRadiusResponseCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testGeosearchByCoordBox() { + GeoCoordinate coord = new GeoCoordinate(15.0, 37.0); + + when(commandObjects.geosearch("key", coord, 50.0, 50.0, GeoUnit.KM)) + .thenReturn(listGeoRadiusResponseCommandObject); + + Response> response = pipeliningBase + .geosearch("key", coord, 50.0, 50.0, GeoUnit.KM); + + assertThat(commands, contains(listGeoRadiusResponseCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testGeosearchByCoordBoxBinary() { + byte[] key = "location".getBytes(); + GeoCoordinate coord = new GeoCoordinate(13.361389, 38.115556); + double width = 200; + double height = 100; + GeoUnit unit = GeoUnit.KM; + + when(commandObjects.geosearch(key, coord, width, height, unit)).thenReturn(listGeoRadiusResponseCommandObject); + + Response> response = pipeliningBase.geosearch(key, coord, width, height, unit); + + assertThat(commands, contains(listGeoRadiusResponseCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testGeosearchWithParams() { + GeoSearchParam params = new GeoSearchParam(); + + when(commandObjects.geosearch("key", params)).thenReturn(listGeoRadiusResponseCommandObject); + + Response> response = pipeliningBase.geosearch("key", params); + + assertThat(commands, contains(listGeoRadiusResponseCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testGeosearchWithParamsBinary() { + byte[] key = "location".getBytes(); + GeoSearchParam params = GeoSearchParam.geoSearchParam().byRadius(100, GeoUnit.KM); + + when(commandObjects.geosearch(key, params)).thenReturn(listGeoRadiusResponseCommandObject); + + Response> response = pipeliningBase.geosearch(key, params); + + assertThat(commands, contains(listGeoRadiusResponseCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testGeosearchStoreByMemberRadius() { + when(commandObjects.geosearchStore("dest", "src", "member", 100.0, GeoUnit.KM)) + .thenReturn(longCommandObject); + + Response response = pipeliningBase + .geosearchStore("dest", "src", "member", 100.0, GeoUnit.KM); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testGeosearchStoreByMemberRadiusBinary() { + byte[] dest = "destination".getBytes(); + byte[] src = "location".getBytes(); + byte[] member = "Palermo".getBytes(); + double radius = 100; + GeoUnit unit = GeoUnit.KM; + + when(commandObjects.geosearchStore(dest, src, member, radius, unit)).thenReturn(longCommandObject); + + Response response = pipeliningBase.geosearchStore(dest, src, member, radius, unit); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testGeosearchStoreByCoordRadius() { + GeoCoordinate coord = new GeoCoordinate(15.0, 37.0); + + when(commandObjects.geosearchStore("dest", "src", coord, 100.0, GeoUnit.KM)) + .thenReturn(longCommandObject); + + Response response = pipeliningBase.geosearchStore("dest", "src", coord, 100.0, GeoUnit.KM); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testGeosearchStoreByCoordRadiusBinary() { + byte[] dest = "destination".getBytes(); + byte[] src = "location".getBytes(); + GeoCoordinate coord = new GeoCoordinate(13.361389, 38.115556); + double radius = 100; + GeoUnit unit = GeoUnit.KM; + + when(commandObjects.geosearchStore(dest, src, coord, radius, unit)).thenReturn(longCommandObject); + + Response response = pipeliningBase.geosearchStore(dest, src, coord, radius, unit); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testGeosearchStoreByMemberBox() { + when(commandObjects.geosearchStore("dest", "src", "member", 50.0, 50.0, GeoUnit.KM)) + .thenReturn(longCommandObject); + + Response response = pipeliningBase + .geosearchStore("dest", "src", "member", 50.0, 50.0, GeoUnit.KM); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testGeosearchStoreByMemberBoxBinary() { + byte[] dest = "destination".getBytes(); + byte[] src = "location".getBytes(); + byte[] member = "Palermo".getBytes(); + double width = 200; + double height = 100; + GeoUnit unit = GeoUnit.KM; + + when(commandObjects.geosearchStore(dest, src, member, width, height, unit)).thenReturn(longCommandObject); + + Response response = pipeliningBase.geosearchStore(dest, src, member, width, height, unit); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testGeosearchStoreByCoordBox() { + GeoCoordinate coord = new GeoCoordinate(15.0, 37.0); + + when(commandObjects.geosearchStore("dest", "src", coord, 50.0, 50.0, GeoUnit.KM)) + .thenReturn(longCommandObject); + + Response response = pipeliningBase + .geosearchStore("dest", "src", coord, 50.0, 50.0, GeoUnit.KM); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testGeosearchStoreByCoordBoxBinary() { + byte[] dest = "destination".getBytes(); + byte[] src = "location".getBytes(); + GeoCoordinate coord = new GeoCoordinate(13.361389, 38.115556); + double width = 200; + double height = 100; + GeoUnit unit = GeoUnit.KM; + + when(commandObjects.geosearchStore(dest, src, coord, width, height, unit)).thenReturn(longCommandObject); + + Response response = pipeliningBase.geosearchStore(dest, src, coord, width, height, unit); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testGeosearchStoreWithParams() { + GeoSearchParam params = new GeoSearchParam(); + + when(commandObjects.geosearchStore("dest", "src", params)).thenReturn(longCommandObject); + + Response response = pipeliningBase.geosearchStore("dest", "src", params); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testGeosearchStoreWithParamsBinary() { + byte[] dest = "destination".getBytes(); + byte[] src = "location".getBytes(); + GeoSearchParam params = GeoSearchParam.geoSearchParam().byRadius(100, GeoUnit.KM); + + when(commandObjects.geosearchStore(dest, src, params)).thenReturn(longCommandObject); + + Response response = pipeliningBase.geosearchStore(dest, src, params); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testGeosearchStoreStoreDist() { + GeoSearchParam params = new GeoSearchParam(); + + when(commandObjects.geosearchStoreStoreDist("dest", "src", params)).thenReturn(longCommandObject); + + Response response = pipeliningBase.geosearchStoreStoreDist("dest", "src", params); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testGeosearchStoreStoreDistBinary() { + byte[] dest = "destination".getBytes(); + byte[] src = "location".getBytes(); + GeoSearchParam params = GeoSearchParam.geoSearchParam().byRadius(100, GeoUnit.KM); + + when(commandObjects.geosearchStoreStoreDist(dest, src, params)).thenReturn(longCommandObject); + + Response response = pipeliningBase.geosearchStoreStoreDist(dest, src, params); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + +} diff --git a/src/test/java/redis/clients/jedis/mocked/pipeline/PipeliningBaseGraphCommandsTest.java b/src/test/java/redis/clients/jedis/mocked/pipeline/PipeliningBaseGraphCommandsTest.java new file mode 100644 index 00000000000..7a16176e544 --- /dev/null +++ b/src/test/java/redis/clients/jedis/mocked/pipeline/PipeliningBaseGraphCommandsTest.java @@ -0,0 +1,140 @@ +package redis.clients.jedis.mocked.pipeline; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.contains; +import static org.hamcrest.Matchers.is; +import static org.mockito.Mockito.when; + +import java.util.Collections; +import java.util.List; +import java.util.Map; + +import org.junit.Test; +import redis.clients.jedis.Response; +import redis.clients.jedis.graph.ResultSet; + +public class PipeliningBaseGraphCommandsTest extends PipeliningBaseMockedTestBase { + + @Test + public void testGraphQuery() { + String query = "MATCH (n) RETURN n"; + + when(graphCommandObjects.graphQuery("myGraph", query)).thenReturn(resultSetCommandObject); + + Response response = pipeliningBase.graphQuery("myGraph", query); + + assertThat(commands, contains(resultSetCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testGraphReadonlyQuery() { + String query = "MATCH (n) RETURN n"; + + when(graphCommandObjects.graphReadonlyQuery("myGraph", query)).thenReturn(resultSetCommandObject); + + Response response = pipeliningBase.graphReadonlyQuery("myGraph", query); + + assertThat(commands, contains(resultSetCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testGraphQueryWithTimeout() { + String query = "MATCH (n) RETURN n"; + + when(graphCommandObjects.graphQuery("myGraph", query, 1000L)).thenReturn(resultSetCommandObject); + + Response response = pipeliningBase.graphQuery("myGraph", query, 1000L); + + assertThat(commands, contains(resultSetCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testGraphReadonlyQueryWithTimeout() { + String query = "MATCH (n) RETURN n"; + + when(graphCommandObjects.graphReadonlyQuery("myGraph", query, 1000L)).thenReturn(resultSetCommandObject); + + Response response = pipeliningBase.graphReadonlyQuery("myGraph", query, 1000L); + + assertThat(commands, contains(resultSetCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testGraphQueryWithParams() { + String query = "MATCH (n) WHERE n.name = $name RETURN n"; + Map params = Collections.singletonMap("name", "Alice"); + + when(graphCommandObjects.graphQuery("myGraph", query, params)).thenReturn(resultSetCommandObject); + + Response response = pipeliningBase.graphQuery("myGraph", query, params); + + assertThat(commands, contains(resultSetCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testGraphReadonlyQueryWithParams() { + String query = "MATCH (n) WHERE n.name = $name RETURN n"; + Map params = Collections.singletonMap("name", "Alice"); + + when(graphCommandObjects.graphReadonlyQuery("myGraph", query, params)).thenReturn(resultSetCommandObject); + + Response response = pipeliningBase.graphReadonlyQuery("myGraph", query, params); + + assertThat(commands, contains(resultSetCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testGraphQueryWithParamsAndTimeout() { + String query = "MATCH (n) WHERE n.name = $name RETURN n"; + Map params = Collections.singletonMap("name", "Alice"); + + when(graphCommandObjects.graphQuery("myGraph", query, params, 1000L)).thenReturn(resultSetCommandObject); + + Response response = pipeliningBase.graphQuery("myGraph", query, params, 1000L); + + assertThat(commands, contains(resultSetCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testGraphReadonlyQueryWithParamsAndTimeout() { + String query = "MATCH (n) WHERE n.name = $name RETURN n"; + Map params = Collections.singletonMap("name", "Alice"); + + when(graphCommandObjects.graphReadonlyQuery("myGraph", query, params, 1000L)).thenReturn(resultSetCommandObject); + + Response response = pipeliningBase.graphReadonlyQuery("myGraph", query, params, 1000L); + + assertThat(commands, contains(resultSetCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testGraphDelete() { + when(graphCommandObjects.graphDelete("myGraph")).thenReturn(stringCommandObject); + + Response response = pipeliningBase.graphDelete("myGraph"); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testGraphProfile() { + String query = "PROFILE MATCH (n) RETURN n"; + + when(commandObjects.graphProfile("myGraph", query)).thenReturn(listStringCommandObject); + + Response> response = pipeliningBase.graphProfile("myGraph", query); + + assertThat(commands, contains(listStringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + +} diff --git a/src/test/java/redis/clients/jedis/mocked/pipeline/PipeliningBaseHashCommandsTest.java b/src/test/java/redis/clients/jedis/mocked/pipeline/PipeliningBaseHashCommandsTest.java new file mode 100644 index 00000000000..b23cee6da26 --- /dev/null +++ b/src/test/java/redis/clients/jedis/mocked/pipeline/PipeliningBaseHashCommandsTest.java @@ -0,0 +1,505 @@ +package redis.clients.jedis.mocked.pipeline; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.contains; +import static org.hamcrest.Matchers.is; +import static org.mockito.Mockito.when; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import org.junit.Test; +import redis.clients.jedis.Response; +import redis.clients.jedis.params.ScanParams; +import redis.clients.jedis.resps.ScanResult; + +public class PipeliningBaseHashCommandsTest extends PipeliningBaseMockedTestBase { + + @Test + public void testHdel() { + when(commandObjects.hdel("key", "field1", "field2")).thenReturn(longCommandObject); + + Response response = pipeliningBase.hdel("key", "field1", "field2"); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testHdelBinary() { + byte[] key = "hash".getBytes(); + byte[] field1 = "field1".getBytes(); + byte[] field2 = "field2".getBytes(); + + when(commandObjects.hdel(key, field1, field2)).thenReturn(longCommandObject); + + Response response = pipeliningBase.hdel(key, field1, field2); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testHexists() { + when(commandObjects.hexists("key", "field")).thenReturn(booleanCommandObject); + + Response response = pipeliningBase.hexists("key", "field"); + + assertThat(commands, contains(booleanCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testHexistsBinary() { + byte[] key = "hash".getBytes(); + byte[] field = "field1".getBytes(); + + when(commandObjects.hexists(key, field)).thenReturn(booleanCommandObject); + + Response response = pipeliningBase.hexists(key, field); + + assertThat(commands, contains(booleanCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testHget() { + when(commandObjects.hget("key", "field")).thenReturn(stringCommandObject); + + Response response = pipeliningBase.hget("key", "field"); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testHgetBinary() { + byte[] key = "hash".getBytes(); + byte[] field = "field1".getBytes(); + + when(commandObjects.hget(key, field)).thenReturn(bytesCommandObject); + + Response response = pipeliningBase.hget(key, field); + + assertThat(commands, contains(bytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testHgetAll() { + when(commandObjects.hgetAll("key")).thenReturn(mapStringStringCommandObject); + + Response> response = pipeliningBase.hgetAll("key"); + + assertThat(commands, contains(mapStringStringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testHgetAllBinary() { + byte[] key = "hash".getBytes(); + + when(commandObjects.hgetAll(key)).thenReturn(mapBytesBytesCommandObject); + + Response> response = pipeliningBase.hgetAll(key); + + assertThat(commands, contains(mapBytesBytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testHincrBy() { + when(commandObjects.hincrBy("key", "field", 1L)).thenReturn(longCommandObject); + + Response response = pipeliningBase.hincrBy("key", "field", 1L); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testHincrByBinary() { + byte[] key = "hash".getBytes(); + byte[] field = "field1".getBytes(); + long increment = 2L; + + when(commandObjects.hincrBy(key, field, increment)).thenReturn(longCommandObject); + + Response response = pipeliningBase.hincrBy(key, field, increment); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testHincrByFloat() { + when(commandObjects.hincrByFloat("key", "field", 1.0)).thenReturn(doubleCommandObject); + + Response response = pipeliningBase.hincrByFloat("key", "field", 1.0); + + assertThat(commands, contains(doubleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testHincrByFloatBinary() { + byte[] key = "hash".getBytes(); + byte[] field = "field1".getBytes(); + double increment = 2.5; + + when(commandObjects.hincrByFloat(key, field, increment)).thenReturn(doubleCommandObject); + + Response response = pipeliningBase.hincrByFloat(key, field, increment); + + assertThat(commands, contains(doubleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testHkeys() { + when(commandObjects.hkeys("key")).thenReturn(setStringCommandObject); + + Response> response = pipeliningBase.hkeys("key"); + + assertThat(commands, contains(setStringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testHkeysBinary() { + byte[] key = "hash".getBytes(); + + when(commandObjects.hkeys(key)).thenReturn(setBytesCommandObject); + + Response> response = pipeliningBase.hkeys(key); + + assertThat(commands, contains(setBytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testHlen() { + when(commandObjects.hlen("key")).thenReturn(longCommandObject); + + Response response = pipeliningBase.hlen("key"); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testHlenBinary() { + byte[] key = "hash".getBytes(); + + when(commandObjects.hlen(key)).thenReturn(longCommandObject); + + Response response = pipeliningBase.hlen(key); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testHmget() { + when(commandObjects.hmget("key", "field1", "field2")).thenReturn(listStringCommandObject); + + Response> response = pipeliningBase.hmget("key", "field1", "field2"); + + assertThat(commands, contains(listStringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testHmgetBinary() { + byte[] key = "hash".getBytes(); + byte[] field1 = "field1".getBytes(); + byte[] field2 = "field2".getBytes(); + + when(commandObjects.hmget(key, field1, field2)).thenReturn(listBytesCommandObject); + + Response> response = pipeliningBase.hmget(key, field1, field2); + + assertThat(commands, contains(listBytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testHmset() { + Map hash = new HashMap<>(); + hash.put("field1", "value1"); + hash.put("field2", "value2"); + + when(commandObjects.hmset("key", hash)).thenReturn(stringCommandObject); + + Response response = pipeliningBase.hmset("key", hash); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testHmsetBinary() { + byte[] key = "hash".getBytes(); + + Map hash = new HashMap<>(); + hash.put("field1".getBytes(), "value1".getBytes()); + + when(commandObjects.hmset(key, hash)).thenReturn(stringCommandObject); + + Response response = pipeliningBase.hmset(key, hash); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testHrandfield() { + when(commandObjects.hrandfield("key")).thenReturn(stringCommandObject); + + Response response = pipeliningBase.hrandfield("key"); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testHrandfieldBinary() { + byte[] key = "hash".getBytes(); + + when(commandObjects.hrandfield(key)).thenReturn(bytesCommandObject); + + Response response = pipeliningBase.hrandfield(key); + + assertThat(commands, contains(bytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testHrandfieldCount() { + long count = 2; + + when(commandObjects.hrandfield("key", count)).thenReturn(listStringCommandObject); + + Response> response = pipeliningBase.hrandfield("key", count); + + assertThat(commands, contains(listStringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testHrandfieldCountBinary() { + byte[] key = "hash".getBytes(); + long count = 2; + + when(commandObjects.hrandfield(key, count)).thenReturn(listBytesCommandObject); + + Response> response = pipeliningBase.hrandfield(key, count); + + assertThat(commands, contains(listBytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testHrandfieldWithValues() { + long count = 2; + + when(commandObjects.hrandfieldWithValues("key", count)).thenReturn(listEntryStringStringCommandObject); + + Response>> response = pipeliningBase.hrandfieldWithValues("key", count); + + assertThat(commands, contains(listEntryStringStringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testHrandfieldWithValuesBinary() { + byte[] key = "hash".getBytes(); + long count = 2; + + when(commandObjects.hrandfieldWithValues(key, count)).thenReturn(listEntryBytesBytesCommandObject); + + Response>> response = pipeliningBase.hrandfieldWithValues(key, count); + + assertThat(commands, contains(listEntryBytesBytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testHscan() { + String cursor = "0"; + ScanParams params = new ScanParams(); + + when(commandObjects.hscan("key", cursor, params)).thenReturn(scanResultEntryStringStringCommandObject); + + Response>> response = pipeliningBase.hscan("key", cursor, params); + + assertThat(commands, contains(scanResultEntryStringStringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testHscanBinary() { + byte[] key = "hash".getBytes(); + byte[] cursor = "0".getBytes(); + ScanParams params = new ScanParams().match("*").count(10); + + when(commandObjects.hscan(key, cursor, params)).thenReturn(scanResultEntryBytesBytesCommandObject); + + Response>> response = pipeliningBase.hscan(key, cursor, params); + + assertThat(commands, contains(scanResultEntryBytesBytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testHscanNoValues() { + String cursor = "0"; + ScanParams params = new ScanParams(); + + when(commandObjects.hscanNoValues("key", cursor, params)).thenReturn(scanResultStringCommandObject); + + Response> response = pipeliningBase.hscanNoValues("key", cursor, params); + + assertThat(commands, contains(scanResultStringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testHscanNoValuesBinary() { + byte[] key = "hash".getBytes(); + byte[] cursor = "0".getBytes(); + ScanParams params = new ScanParams().match("*").count(10); + + when(commandObjects.hscanNoValues(key, cursor, params)).thenReturn(scanResultBytesCommandObject); + + Response> response = pipeliningBase.hscanNoValues(key, cursor, params); + + assertThat(commands, contains(scanResultBytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testHset() { + when(commandObjects.hset("key", "field", "value")).thenReturn(longCommandObject); + + Response response = pipeliningBase.hset("key", "field", "value"); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testHsetBinary() { + byte[] key = "hash".getBytes(); + byte[] field = "field1".getBytes(); + byte[] value = "value1".getBytes(); + + when(commandObjects.hset(key, field, value)).thenReturn(longCommandObject); + + Response response = pipeliningBase.hset(key, field, value); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testHsetMap() { + Map hash = new HashMap<>(); + hash.put("field1", "value1"); + hash.put("field2", "value2"); + + when(commandObjects.hset("key", hash)).thenReturn(longCommandObject); + + Response response = pipeliningBase.hset("key", hash); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testHsetMapBinary() { + byte[] key = "hash".getBytes(); + + Map hash = new HashMap<>(); + hash.put("field1".getBytes(), "value1".getBytes()); + + when(commandObjects.hset(key, hash)).thenReturn(longCommandObject); + + Response response = pipeliningBase.hset(key, hash); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testHsetnx() { + when(commandObjects.hsetnx("key", "field", "value")).thenReturn(longCommandObject); + + Response response = pipeliningBase.hsetnx("key", "field", "value"); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testHsetnxBinary() { + byte[] key = "hash".getBytes(); + byte[] field = "field1".getBytes(); + byte[] value = "value1".getBytes(); + + when(commandObjects.hsetnx(key, field, value)).thenReturn(longCommandObject); + + Response response = pipeliningBase.hsetnx(key, field, value); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testHstrlen() { + when(commandObjects.hstrlen("key", "field")).thenReturn(longCommandObject); + + Response response = pipeliningBase.hstrlen("key", "field"); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testHstrlenBinary() { + byte[] key = "hash".getBytes(); + byte[] field = "field1".getBytes(); + + when(commandObjects.hstrlen(key, field)).thenReturn(longCommandObject); + + Response response = pipeliningBase.hstrlen(key, field); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testHvals() { + when(commandObjects.hvals("key")).thenReturn(listStringCommandObject); + + Response> response = pipeliningBase.hvals("key"); + + assertThat(commands, contains(listStringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testHvalsBinary() { + byte[] key = "hash".getBytes(); + + when(commandObjects.hvals(key)).thenReturn(listBytesCommandObject); + + Response> response = pipeliningBase.hvals(key); + + assertThat(commands, contains(listBytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + +} diff --git a/src/test/java/redis/clients/jedis/mocked/pipeline/PipeliningBaseHyperloglogCommandsTest.java b/src/test/java/redis/clients/jedis/mocked/pipeline/PipeliningBaseHyperloglogCommandsTest.java new file mode 100644 index 00000000000..d5b59b99a44 --- /dev/null +++ b/src/test/java/redis/clients/jedis/mocked/pipeline/PipeliningBaseHyperloglogCommandsTest.java @@ -0,0 +1,106 @@ +package redis.clients.jedis.mocked.pipeline; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.contains; +import static org.hamcrest.Matchers.is; +import static org.mockito.Mockito.when; + +import org.junit.Test; +import redis.clients.jedis.Response; + +public class PipeliningBaseHyperloglogCommandsTest extends PipeliningBaseMockedTestBase { + + @Test + public void testPfadd() { + when(commandObjects.pfadd("key", "element1", "element2")).thenReturn(longCommandObject); + + Response response = pipeliningBase.pfadd("key", "element1", "element2"); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testPfaddBinary() { + byte[] key = "hll".getBytes(); + byte[] element1 = "element1".getBytes(); + byte[] element2 = "element2".getBytes(); + + when(commandObjects.pfadd(key, element1, element2)).thenReturn(longCommandObject); + + Response response = pipeliningBase.pfadd(key, element1, element2); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testPfcount() { + when(commandObjects.pfcount("key")).thenReturn(longCommandObject); + + Response response = pipeliningBase.pfcount("key"); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testPfcountBinary() { + byte[] key = "hll".getBytes(); + + when(commandObjects.pfcount(key)).thenReturn(longCommandObject); + + Response response = pipeliningBase.pfcount(key); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testPfcountMultipleKeys() { + when(commandObjects.pfcount("key1", "key2")).thenReturn(longCommandObject); + + Response response = pipeliningBase.pfcount("key1", "key2"); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testPfcountMultipleKeysBinary() { + byte[] key1 = "hll1".getBytes(); + byte[] key2 = "hll2".getBytes(); + + when(commandObjects.pfcount(key1, key2)).thenReturn(longCommandObject); + + Response response = pipeliningBase.pfcount(key1, key2); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testPfmerge() { + when(commandObjects.pfmerge("destkey", "sourcekey1", "sourcekey2")).thenReturn(stringCommandObject); + + Response response = pipeliningBase.pfmerge("destkey", "sourcekey1", "sourcekey2"); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testPfmergeBinary() { + byte[] destkey = "hll_dest".getBytes(); + byte[] sourcekey1 = "hll1".getBytes(); + byte[] sourcekey2 = "hll2".getBytes(); + + when(commandObjects.pfmerge(destkey, sourcekey1, sourcekey2)).thenReturn(stringCommandObject); + + Response response = pipeliningBase.pfmerge(destkey, sourcekey1, sourcekey2); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + +} diff --git a/src/test/java/redis/clients/jedis/mocked/pipeline/PipeliningBaseJsonCommandsTest.java b/src/test/java/redis/clients/jedis/mocked/pipeline/PipeliningBaseJsonCommandsTest.java new file mode 100644 index 00000000000..aabb6ca5a18 --- /dev/null +++ b/src/test/java/redis/clients/jedis/mocked/pipeline/PipeliningBaseJsonCommandsTest.java @@ -0,0 +1,706 @@ +package redis.clients.jedis.mocked.pipeline; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.contains; +import static org.hamcrest.Matchers.is; +import static org.mockito.Mockito.doNothing; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import java.util.List; + +import com.google.gson.JsonObject; +import org.json.JSONArray; +import org.junit.Test; +import redis.clients.jedis.Response; +import redis.clients.jedis.json.JsonObjectMapper; +import redis.clients.jedis.json.JsonSetParams; +import redis.clients.jedis.json.Path; +import redis.clients.jedis.json.Path2; + +public class PipeliningBaseJsonCommandsTest extends PipeliningBaseMockedTestBase { + + @Test + public void testJsonArrAppendWithPath() { + Path path = new Path("$.array"); + Object[] objects = { "one", "two", "three" }; + + when(commandObjects.jsonArrAppend("myJson", path, objects)).thenReturn(longCommandObject); + + Response response = pipeliningBase.jsonArrAppend("myJson", path, objects); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testJsonArrAppendWithPath2() { + Path2 path = Path2.of("$.array"); + Object[] objects = { "one", "two", "three" }; + + when(commandObjects.jsonArrAppend("myJson", path, objects)).thenReturn(listLongCommandObject); + + Response> response = pipeliningBase.jsonArrAppend("myJson", path, objects); + + assertThat(commands, contains(listLongCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testJsonArrAppendWithPath2WithEscape() { + Path2 path = Path2.of("$.array"); + Object[] objects = { "one", "two", "three" }; + + when(commandObjects.jsonArrAppendWithEscape("myJson", path, objects)).thenReturn(listLongCommandObject); + + Response> response = pipeliningBase.jsonArrAppendWithEscape("myJson", path, objects); + + assertThat(commands, contains(listLongCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testJsonArrIndexWithPath() { + Path path = new Path("$.array"); + Object scalar = "two"; + + when(commandObjects.jsonArrIndex("myJson", path, scalar)).thenReturn(longCommandObject); + + Response response = pipeliningBase.jsonArrIndex("myJson", path, scalar); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testJsonArrIndexWithPath2() { + Path2 path = Path2.of("$.array"); + Object scalar = "two"; + + when(commandObjects.jsonArrIndex("myJson", path, scalar)).thenReturn(listLongCommandObject); + + Response> response = pipeliningBase.jsonArrIndex("myJson", path, scalar); + + assertThat(commands, contains(listLongCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testJsonArrIndexWithPath2WithEscape() { + Path2 path = Path2.of("$.array"); + Object scalar = "two"; + + when(commandObjects.jsonArrIndexWithEscape("myJson", path, scalar)).thenReturn(listLongCommandObject); + + Response> response = pipeliningBase.jsonArrIndexWithEscape("myJson", path, scalar); + + assertThat(commands, contains(listLongCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testJsonArrInsertWithPath() { + Path path = new Path("$.array"); + Object[] pojos = { "one", "two", "three" }; + + when(commandObjects.jsonArrInsert("myJson", path, 1, pojos)).thenReturn(longCommandObject); + + Response response = pipeliningBase.jsonArrInsert("myJson", path, 1, pojos); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testJsonArrInsertWithPath2() { + Path2 path = Path2.of("$.array"); + Object[] objects = { "one", "two", "three" }; + + when(commandObjects.jsonArrInsert("myJson", path, 1, objects)).thenReturn(listLongCommandObject); + + Response> response = pipeliningBase.jsonArrInsert("myJson", path, 1, objects); + + assertThat(commands, contains(listLongCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testJsonArrInsertWithPath2WithEscape() { + Path2 path = Path2.of("$.array"); + Object[] objects = { "one", "two", "three" }; + + when(commandObjects.jsonArrInsertWithEscape("myJson", path, 1, objects)).thenReturn(listLongCommandObject); + + Response> response = pipeliningBase.jsonArrInsertWithEscape("myJson", path, 1, objects); + + assertThat(commands, contains(listLongCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testJsonArrLen() { + when(commandObjects.jsonArrLen("myJson")).thenReturn(longCommandObject); + + Response response = pipeliningBase.jsonArrLen("myJson"); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testJsonArrLenWithPath() { + Path path = new Path("$.array"); + + when(commandObjects.jsonArrLen("myJson", path)).thenReturn(longCommandObject); + + Response response = pipeliningBase.jsonArrLen("myJson", path); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testJsonArrLenWithPath2() { + Path2 path = Path2.of("$.array"); + + when(commandObjects.jsonArrLen("myJson", path)).thenReturn(listLongCommandObject); + + Response> response = pipeliningBase.jsonArrLen("myJson", path); + + assertThat(commands, contains(listLongCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testJsonArrPop() { + when(commandObjects.jsonArrPop("myJson")).thenReturn(objectCommandObject); + + Response response = pipeliningBase.jsonArrPop("myJson"); + + assertThat(commands, contains(objectCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testJsonArrPopWithPath() { + Path path = new Path("$.array"); + + when(commandObjects.jsonArrPop("myJson", path)).thenReturn(objectCommandObject); + + Response response = pipeliningBase.jsonArrPop("myJson", path); + + assertThat(commands, contains(objectCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testJsonArrPopWithPathAndIndex() { + Path path = new Path("$.array"); + + when(commandObjects.jsonArrPop("myJson", path, 1)).thenReturn(objectCommandObject); + + Response response = pipeliningBase.jsonArrPop("myJson", path, 1); + + assertThat(commands, contains(objectCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testJsonArrPopWithClassAndPath() { + Path path = new Path("$.array"); + + when(commandObjects.jsonArrPop("myJson", MyBean.class, path)).thenReturn(myBeanCommandObject); + + Response response = pipeliningBase.jsonArrPop("myJson", MyBean.class, path); + + assertThat(commands, contains(myBeanCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testJsonArrPopWithClassPathAndIndex() { + Path path = new Path("$.array"); + + when(commandObjects.jsonArrPop("myJson", MyBean.class, path, 1)).thenReturn(myBeanCommandObject); + + Response response = pipeliningBase.jsonArrPop("myJson", MyBean.class, path, 1); + + assertThat(commands, contains(myBeanCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testJsonArrPopWithPath2() { + Path2 path = Path2.of("$.array"); + + when(commandObjects.jsonArrPop("myJson", path)).thenReturn(listObjectCommandObject); + + Response> response = pipeliningBase.jsonArrPop("myJson", path); + + assertThat(commands, contains(listObjectCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testJsonArrPopWithPath2AndIndex() { + Path2 path = Path2.of("$.array"); + + when(commandObjects.jsonArrPop("myJson", path, 1)).thenReturn(listObjectCommandObject); + + Response> response = pipeliningBase.jsonArrPop("myJson", path, 1); + + assertThat(commands, contains(listObjectCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testJsonArrPopWithClass() { + when(commandObjects.jsonArrPop("myJson", MyBean.class)).thenReturn(myBeanCommandObject); + + Response response = pipeliningBase.jsonArrPop("myJson", MyBean.class); + + assertThat(commands, contains(myBeanCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testJsonArrTrimWithPath() { + Path path = new Path("$.array"); + + when(commandObjects.jsonArrTrim("myJson", path, 1, 2)).thenReturn(longCommandObject); + + Response response = pipeliningBase.jsonArrTrim("myJson", path, 1, 2); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testJsonArrTrimWithPath2() { + Path2 path = Path2.of("$.array"); + + when(commandObjects.jsonArrTrim("myJson", path, 1, 2)).thenReturn(listLongCommandObject); + + Response> response = pipeliningBase.jsonArrTrim("myJson", path, 1, 2); + + assertThat(commands, contains(listLongCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testJsonClear() { + when(commandObjects.jsonClear("myJson")).thenReturn(longCommandObject); + + Response response = pipeliningBase.jsonClear("myJson"); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testJsonClearWithPath() { + Path path = new Path("$.field"); + + when(commandObjects.jsonClear("myJson", path)).thenReturn(longCommandObject); + + Response response = pipeliningBase.jsonClear("myJson", path); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testJsonClearWithPath2() { + Path2 path = Path2.of("$.field"); + + when(commandObjects.jsonClear("myJson", path)).thenReturn(longCommandObject); + + Response response = pipeliningBase.jsonClear("myJson", path); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testJsonDel() { + when(commandObjects.jsonDel("myJson")).thenReturn(longCommandObject); + + Response response = pipeliningBase.jsonDel("myJson"); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testJsonDelWithPath() { + Path path = new Path("$.field"); + + when(commandObjects.jsonDel("myJson", path)).thenReturn(longCommandObject); + + Response response = pipeliningBase.jsonDel("myJson", path); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testJsonDelWithPath2() { + Path2 path = Path2.of("$.field"); + + when(commandObjects.jsonDel("myJson", path)).thenReturn(longCommandObject); + + Response response = pipeliningBase.jsonDel("myJson", path); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testJsonGet() { + when(commandObjects.jsonGet("myJson")).thenReturn(objectCommandObject); + + Response response = pipeliningBase.jsonGet("myJson"); + + assertThat(commands, contains(objectCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testJsonGetWithClass() { + when(commandObjects.jsonGet("myJson", MyBean.class)).thenReturn(myBeanCommandObject); + + Response response = pipeliningBase.jsonGet("myJson", MyBean.class); + + assertThat(commands, contains(myBeanCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testJsonGetWithPath() { + Path[] paths = { new Path("$.field1"), new Path("$.field2") }; + + when(commandObjects.jsonGet("myJson", paths)).thenReturn(objectCommandObject); + + Response response = pipeliningBase.jsonGet("myJson", paths); + + assertThat(commands, contains(objectCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testJsonGetWithPath2() { + Path2[] paths = { Path2.of("$.field1"), Path2.of("$.field2") }; + + when(commandObjects.jsonGet("myJson", paths)).thenReturn(objectCommandObject); + + Response response = pipeliningBase.jsonGet("myJson", paths); + + assertThat(commands, contains(objectCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testJsonGetWithClassAndPath() { + Path[] paths = { new Path("$.field1"), new Path("$.field2") }; + + when(commandObjects.jsonGet("myJson", MyBean.class, paths)).thenReturn(myBeanCommandObject); + + Response response = pipeliningBase.jsonGet("myJson", MyBean.class, paths); + + assertThat(commands, contains(myBeanCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testJsonMergeWithPath() { + Path path = new Path("$.field"); + Object object = new JsonObject(); + + when(commandObjects.jsonMerge("myJson", path, object)).thenReturn(stringCommandObject); + + Response response = pipeliningBase.jsonMerge("myJson", path, object); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testJsonMergeWithPath2() { + Path2 path = Path2.of("$.field"); + Object object = new JsonObject(); + + when(commandObjects.jsonMerge("myJson", path, object)).thenReturn(stringCommandObject); + + Response response = pipeliningBase.jsonMerge("myJson", path, object); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testJsonMGetWithPathAndClass() { + Path path = new Path("$.field"); + + when(commandObjects.jsonMGet(path, MyBean.class, "key1", "key2")).thenReturn(listMyBeanCommandObject); + + Response> response = pipeliningBase.jsonMGet(path, MyBean.class, "key1", "key2"); + + assertThat(commands, contains(listMyBeanCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testJsonMGetWithPath2() { + Path2 path = Path2.of("$.field"); + + when(commandObjects.jsonMGet(path, "key1", "key2")).thenReturn(listJsonArrayCommandObject); + + Response> response = pipeliningBase.jsonMGet(path, "key1", "key2"); + + assertThat(commands, contains(listJsonArrayCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testJsonNumIncrByWithPath() { + Path path = new Path("$.number"); + + when(commandObjects.jsonNumIncrBy("myJson", path, 42.0)).thenReturn(doubleCommandObject); + + Response response = pipeliningBase.jsonNumIncrBy("myJson", path, 42.0); + + assertThat(commands, contains(doubleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testJsonNumIncrByWithPath2() { + Path2 path = Path2.of("$.number"); + + when(commandObjects.jsonNumIncrBy("myJson", path, 42.0)).thenReturn(objectCommandObject); + + Response response = pipeliningBase.jsonNumIncrBy("myJson", path, 42.0); + + assertThat(commands, contains(objectCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testJsonSetWithPath() { + Path path = Path.of("$.field"); + Object object = new JsonObject(); + + when(commandObjects.jsonSet("myJson", path, object)).thenReturn(stringCommandObject); + + Response response = pipeliningBase.jsonSet("myJson", path, object); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testJsonSetWithPathAndParams() { + Path path = new Path("$.field"); + Object object = new JsonObject(); + JsonSetParams params = new JsonSetParams().nx(); + + when(commandObjects.jsonSet("myJson", path, object, params)).thenReturn(stringCommandObject); + + Response response = pipeliningBase.jsonSet("myJson", path, object, params); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testJsonSetWithPath2() { + Path2 path = Path2.of("$.field"); + Object object = new JsonObject(); + + when(commandObjects.jsonSet("myJson", path, object)).thenReturn(stringCommandObject); + + Response response = pipeliningBase.jsonSet("myJson", path, object); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testJsonSetWithPath2WithEscape() { + Path2 path = Path2.of("$.field"); + Object object = new JsonObject(); + + when(commandObjects.jsonSetWithEscape("myJson", path, object)).thenReturn(stringCommandObject); + + Response response = pipeliningBase.jsonSetWithEscape("myJson", path, object); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testJsonSetWithPath2AndParams() { + Path2 path = Path2.of("$.field"); + Object object = new JsonObject(); + JsonSetParams params = new JsonSetParams().nx(); + + when(commandObjects.jsonSet("myJson", path, object, params)).thenReturn(stringCommandObject); + + Response response = pipeliningBase.jsonSet("myJson", path, object, params); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testJsonSetWithPath2EscapeAndParams() { + Path2 path = Path2.of("$.field"); + Object object = new JsonObject(); + JsonSetParams params = new JsonSetParams().nx(); + + when(commandObjects.jsonSetWithEscape("myJson", path, object, params)).thenReturn(stringCommandObject); + + Response response = pipeliningBase.jsonSetWithEscape("myJson", path, object, params); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testJsonStrAppend() { + when(commandObjects.jsonStrAppend("myJson", "append")).thenReturn(longCommandObject); + + Response response = pipeliningBase.jsonStrAppend("myJson", "append"); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testJsonStrAppendWithPath() { + Path path = new Path("$.field"); + + when(commandObjects.jsonStrAppend("myJson", path, "append")).thenReturn(longCommandObject); + + Response response = pipeliningBase.jsonStrAppend("myJson", path, "append"); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testJsonStrAppendWithPath2() { + Path2 path = Path2.of("$.field"); + + when(commandObjects.jsonStrAppend("myJson", path, "append")).thenReturn(listLongCommandObject); + + Response> response = pipeliningBase.jsonStrAppend("myJson", path, "append"); + + assertThat(commands, contains(listLongCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testJsonStrLen() { + when(commandObjects.jsonStrLen("myJson")).thenReturn(longCommandObject); + + Response response = pipeliningBase.jsonStrLen("myJson"); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testJsonStrLenWithPath() { + Path path = new Path("$.field"); + + when(commandObjects.jsonStrLen("myJson", path)).thenReturn(longCommandObject); + + Response response = pipeliningBase.jsonStrLen("myJson", path); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testJsonStrLenWithPath2() { + Path2 path = Path2.of("$.field"); + + when(commandObjects.jsonStrLen("myJson", path)).thenReturn(listLongCommandObject); + + Response> response = pipeliningBase.jsonStrLen("myJson", path); + + assertThat(commands, contains(listLongCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testJsonToggleWithPath() { + Path path = new Path("$.field"); + + when(commandObjects.jsonToggle("myJson", path)).thenReturn(stringCommandObject); + + Response response = pipeliningBase.jsonToggle("myJson", path); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testJsonToggleWithPath2() { + Path2 path = Path2.of("$.field"); + + when(commandObjects.jsonToggle("myJson", path)).thenReturn(listBooleanCommandObject); + + Response> response = pipeliningBase.jsonToggle("myJson", path); + + assertThat(commands, contains(listBooleanCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testJsonType() { + when(commandObjects.jsonType("myJson")).thenReturn(classCommandObject); + + Response> response = pipeliningBase.jsonType("myJson"); + + assertThat(commands, contains(classCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testJsonTypeWithPath() { + Path path = new Path("$.field"); + + when(commandObjects.jsonType("myJson", path)).thenReturn(classCommandObject); + + Response> response = pipeliningBase.jsonType("myJson", path); + + assertThat(commands, contains(classCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testJsonTypeWithPath2() { + Path2 path = Path2.of("$.field"); + + when(commandObjects.jsonType("myJson", path)).thenReturn(listClassCommandObject); + + Response>> response = pipeliningBase.jsonType("myJson", path); + + assertThat(commands, contains(listClassCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testSetJsonObjectMapper() { + JsonObjectMapper jsonObjectMapper = mock(JsonObjectMapper.class); + doNothing().when(commandObjects).setJsonObjectMapper(jsonObjectMapper); + + pipeliningBase.setJsonObjectMapper(jsonObjectMapper); + + verify(commandObjects).setJsonObjectMapper(jsonObjectMapper); + } + +} diff --git a/src/test/java/redis/clients/jedis/mocked/pipeline/PipeliningBaseListCommandsTest.java b/src/test/java/redis/clients/jedis/mocked/pipeline/PipeliningBaseListCommandsTest.java new file mode 100644 index 00000000000..a43d80a1383 --- /dev/null +++ b/src/test/java/redis/clients/jedis/mocked/pipeline/PipeliningBaseListCommandsTest.java @@ -0,0 +1,800 @@ +package redis.clients.jedis.mocked.pipeline; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.contains; +import static org.hamcrest.Matchers.is; +import static org.mockito.Mockito.when; + +import java.util.List; + +import org.junit.Test; +import redis.clients.jedis.Response; +import redis.clients.jedis.args.ListDirection; +import redis.clients.jedis.args.ListPosition; +import redis.clients.jedis.params.LPosParams; +import redis.clients.jedis.util.KeyValue; + +public class PipeliningBaseListCommandsTest extends PipeliningBaseMockedTestBase { + + @Test + public void testBlmove() { + ListDirection from = ListDirection.LEFT; + ListDirection to = ListDirection.RIGHT; + double timeout = 1.0; + + when(commandObjects.blmove("srcKey", "dstKey", from, to, timeout)).thenReturn(stringCommandObject); + + Response response = pipeliningBase.blmove("srcKey", "dstKey", from, to, timeout); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testBlmoveBinary() { + byte[] srcKey = "srcKey".getBytes(); + byte[] dstKey = "dstKey".getBytes(); + ListDirection from = ListDirection.LEFT; + ListDirection to = ListDirection.RIGHT; + double timeout = 10.5; + + when(commandObjects.blmove(srcKey, dstKey, from, to, timeout)).thenReturn(bytesCommandObject); + + Response response = pipeliningBase.blmove(srcKey, dstKey, from, to, timeout); + + assertThat(commands, contains(bytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testBlmpop() { + double timeout = 1.0; + ListDirection direction = ListDirection.LEFT; + + when(commandObjects.blmpop(timeout, direction, "key1", "key2")).thenReturn(keyValueStringListStringCommandObject); + + Response>> response = pipeliningBase.blmpop(timeout, direction, "key1", "key2"); + + assertThat(commands, contains(keyValueStringListStringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testBlmpopBinary() { + double timeout = 10.5; + ListDirection direction = ListDirection.LEFT; + byte[] key1 = "key1".getBytes(); + byte[] key2 = "key2".getBytes(); + + when(commandObjects.blmpop(timeout, direction, key1, key2)).thenReturn(keyValueBytesListBytesCommandObject); + + Response>> response = pipeliningBase.blmpop(timeout, direction, key1, key2); + + assertThat(commands, contains(keyValueBytesListBytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testBlmpopCount() { + double timeout = 1.0; + ListDirection direction = ListDirection.LEFT; + int count = 2; + + when(commandObjects.blmpop(timeout, direction, count, "key1", "key2")).thenReturn(keyValueStringListStringCommandObject); + + Response>> response = pipeliningBase.blmpop(timeout, direction, count, "key1", "key2"); + + assertThat(commands, contains(keyValueStringListStringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testBlmpopCountBinary() { + double timeout = 10.5; + ListDirection direction = ListDirection.LEFT; + int count = 2; + byte[] key1 = "key1".getBytes(); + byte[] key2 = "key2".getBytes(); + + when(commandObjects.blmpop(timeout, direction, count, key1, key2)).thenReturn(keyValueBytesListBytesCommandObject); + + Response>> response = pipeliningBase.blmpop(timeout, direction, count, key1, key2); + + assertThat(commands, contains(keyValueBytesListBytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testBlpop() { + when(commandObjects.blpop(30, "key")).thenReturn(listStringCommandObject); + + Response> response = pipeliningBase.blpop(30, "key"); + + assertThat(commands, contains(listStringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testBlpopBinary() { + int timeout = 10; + byte[] key1 = "key1".getBytes(); + byte[] key2 = "key2".getBytes(); + + when(commandObjects.blpop(timeout, key1, key2)).thenReturn(listBytesCommandObject); + + Response> response = pipeliningBase.blpop(timeout, key1, key2); + + assertThat(commands, contains(listBytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testBlpopDoubleTimeout() { + when(commandObjects.blpop(30.0, "key")).thenReturn(keyValueStringStringCommandObject); + + Response> response = pipeliningBase.blpop(30.0, "key"); + + assertThat(commands, contains(keyValueStringStringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testBlpopDoubleTimeoutBinary() { + double timeout = 10.5; + byte[] key1 = "key1".getBytes(); + byte[] key2 = "key2".getBytes(); + + when(commandObjects.blpop(timeout, key1, key2)).thenReturn(keyValueBytesBytesCommandObject); + + Response> response = pipeliningBase.blpop(timeout, key1, key2); + + assertThat(commands, contains(keyValueBytesBytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testBlpopMultipleKeys() { + when(commandObjects.blpop(30, "key1", "key2")).thenReturn(listStringCommandObject); + + Response> response = pipeliningBase.blpop(30, "key1", "key2"); + + assertThat(commands, contains(listStringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testBlpopMultipleKeysDoubleTimeout() { + when(commandObjects.blpop(30.0, "key1", "key2")).thenReturn(keyValueStringStringCommandObject); + + Response> response = pipeliningBase.blpop(30.0, "key1", "key2"); + + assertThat(commands, contains(keyValueStringStringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testBrpop() { + when(commandObjects.brpop(30, "key")).thenReturn(listStringCommandObject); + + Response> response = pipeliningBase.brpop(30, "key"); + + assertThat(commands, contains(listStringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testBrpopBinary() { + int timeout = 10; + byte[] key1 = "key1".getBytes(); + byte[] key2 = "key2".getBytes(); + + when(commandObjects.brpop(timeout, key1, key2)).thenReturn(listBytesCommandObject); + + Response> response = pipeliningBase.brpop(timeout, key1, key2); + + assertThat(commands, contains(listBytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testBrpopDoubleTimeout() { + when(commandObjects.brpop(30.0, "key")).thenReturn(keyValueStringStringCommandObject); + + Response> response = pipeliningBase.brpop(30.0, "key"); + + assertThat(commands, contains(keyValueStringStringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testBrpopDoubleTimeoutBinary() { + double timeout = 10.5; + byte[] key1 = "key1".getBytes(); + byte[] key2 = "key2".getBytes(); + + when(commandObjects.brpop(timeout, key1, key2)).thenReturn(keyValueBytesBytesCommandObject); + + Response> response = pipeliningBase.brpop(timeout, key1, key2); + + assertThat(commands, contains(keyValueBytesBytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testBrpopMultipleKeys() { + when(commandObjects.brpop(30, "key1", "key2")).thenReturn(listStringCommandObject); + + Response> response = pipeliningBase.brpop(30, "key1", "key2"); + + assertThat(commands, contains(listStringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testBrpopMultipleKeysDoubleTimeout() { + when(commandObjects.brpop(30.0, "key1", "key2")).thenReturn(keyValueStringStringCommandObject); + + Response> response = pipeliningBase.brpop(30.0, "key1", "key2"); + + assertThat(commands, contains(keyValueStringStringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testBrpoplpush() { + when(commandObjects.brpoplpush("source", "destination", 30)).thenReturn(stringCommandObject); + + Response response = pipeliningBase.brpoplpush("source", "destination", 30); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testBrpoplpushBinary() { + byte[] source = "source".getBytes(); + byte[] destination = "destination".getBytes(); + int timeout = 10; + + when(commandObjects.brpoplpush(source, destination, timeout)).thenReturn(bytesCommandObject); + + Response response = pipeliningBase.brpoplpush(source, destination, timeout); + + assertThat(commands, contains(bytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testLindex() { + when(commandObjects.lindex("key", 1)).thenReturn(stringCommandObject); + + Response response = pipeliningBase.lindex("key", 1); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testLindexBinary() { + byte[] key = "key".getBytes(); + long index = 0; + + when(commandObjects.lindex(key, index)).thenReturn(bytesCommandObject); + + Response response = pipeliningBase.lindex(key, index); + + assertThat(commands, contains(bytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testLinsert() { + ListPosition where = ListPosition.BEFORE; + + when(commandObjects.linsert("key", where, "pivot", "value")).thenReturn(longCommandObject); + + Response response = pipeliningBase.linsert("key", where, "pivot", "value"); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testLinsertBinary() { + byte[] key = "key".getBytes(); + ListPosition where = ListPosition.BEFORE; + byte[] pivot = "pivot".getBytes(); + byte[] value = "value".getBytes(); + + when(commandObjects.linsert(key, where, pivot, value)).thenReturn(longCommandObject); + + Response response = pipeliningBase.linsert(key, where, pivot, value); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testLlen() { + when(commandObjects.llen("key")).thenReturn(longCommandObject); + + Response response = pipeliningBase.llen("key"); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testLlenBinary() { + byte[] key = "key".getBytes(); + + when(commandObjects.llen(key)).thenReturn(longCommandObject); + + Response response = pipeliningBase.llen(key); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testLmove() { + ListDirection from = ListDirection.LEFT; + ListDirection to = ListDirection.RIGHT; + + when(commandObjects.lmove("srcKey", "dstKey", from, to)).thenReturn(stringCommandObject); + + Response response = pipeliningBase.lmove("srcKey", "dstKey", from, to); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testLmoveBinary() { + byte[] srcKey = "srcKey".getBytes(); + byte[] dstKey = "dstKey".getBytes(); + ListDirection from = ListDirection.LEFT; + ListDirection to = ListDirection.RIGHT; + + when(commandObjects.lmove(srcKey, dstKey, from, to)).thenReturn(bytesCommandObject); + + Response response = pipeliningBase.lmove(srcKey, dstKey, from, to); + + assertThat(commands, contains(bytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testLmpop() { + ListDirection direction = ListDirection.LEFT; + + when(commandObjects.lmpop(direction, "key1", "key2")).thenReturn(keyValueStringListStringCommandObject); + + Response>> response = pipeliningBase.lmpop(direction, "key1", "key2"); + + assertThat(commands, contains(keyValueStringListStringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testLmpopBinary() { + ListDirection direction = ListDirection.LEFT; + byte[] key1 = "key1".getBytes(); + byte[] key2 = "key2".getBytes(); + + when(commandObjects.lmpop(direction, key1, key2)).thenReturn(keyValueBytesListBytesCommandObject); + + Response>> response = pipeliningBase.lmpop(direction, key1, key2); + + assertThat(commands, contains(keyValueBytesListBytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testLmpopCount() { + ListDirection direction = ListDirection.LEFT; + int count = 2; + + when(commandObjects.lmpop(direction, count, "key1", "key2")).thenReturn(keyValueStringListStringCommandObject); + + Response>> response = pipeliningBase.lmpop(direction, count, "key1", "key2"); + + assertThat(commands, contains(keyValueStringListStringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testLmpopCountBinary() { + ListDirection direction = ListDirection.LEFT; + int count = 2; + byte[] key1 = "key1".getBytes(); + byte[] key2 = "key2".getBytes(); + + when(commandObjects.lmpop(direction, count, key1, key2)).thenReturn(keyValueBytesListBytesCommandObject); + + Response>> response = pipeliningBase.lmpop(direction, count, key1, key2); + + assertThat(commands, contains(keyValueBytesListBytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testLpop() { + when(commandObjects.lpop("key")).thenReturn(stringCommandObject); + + Response response = pipeliningBase.lpop("key"); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testLpopBinary() { + byte[] key = "key".getBytes(); + + when(commandObjects.lpop(key)).thenReturn(bytesCommandObject); + + Response response = pipeliningBase.lpop(key); + + assertThat(commands, contains(bytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testLpopCount() { + when(commandObjects.lpop("key", 2)).thenReturn(listStringCommandObject); + + Response> response = pipeliningBase.lpop("key", 2); + + assertThat(commands, contains(listStringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testLpopCountBinary() { + byte[] key = "key".getBytes(); + int count = 2; + + when(commandObjects.lpop(key, count)).thenReturn(listBytesCommandObject); + + Response> response = pipeliningBase.lpop(key, count); + + assertThat(commands, contains(listBytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testLpos() { + when(commandObjects.lpos("key", "element")).thenReturn(longCommandObject); + + Response response = pipeliningBase.lpos("key", "element"); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testLposBinary() { + byte[] key = "key".getBytes(); + byte[] element = "element".getBytes(); + + when(commandObjects.lpos(key, element)).thenReturn(longCommandObject); + + Response response = pipeliningBase.lpos(key, element); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testLposWithParams() { + LPosParams params = new LPosParams(); + + when(commandObjects.lpos("key", "element", params)).thenReturn(longCommandObject); + + Response response = pipeliningBase.lpos("key", "element", params); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testLposWithParamsBinary() { + byte[] key = "key".getBytes(); + byte[] element = "element".getBytes(); + LPosParams params = new LPosParams().rank(1); + + when(commandObjects.lpos(key, element, params)).thenReturn(longCommandObject); + + Response response = pipeliningBase.lpos(key, element, params); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testLposWithParamsCount() { + LPosParams params = new LPosParams(); + + when(commandObjects.lpos("key", "element", params, 3)).thenReturn(listLongCommandObject); + + Response> response = pipeliningBase.lpos("key", "element", params, 3); + + assertThat(commands, contains(listLongCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testLposWithParamsCountBinary() { + byte[] key = "key".getBytes(); + byte[] element = "element".getBytes(); + LPosParams params = new LPosParams().rank(1); + long count = 2; + + when(commandObjects.lpos(key, element, params, count)).thenReturn(listLongCommandObject); + + Response> response = pipeliningBase.lpos(key, element, params, count); + + assertThat(commands, contains(listLongCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testLpush() { + when(commandObjects.lpush("key", "value1", "value2")).thenReturn(longCommandObject); + + Response response = pipeliningBase.lpush("key", "value1", "value2"); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testLpushBinary() { + byte[] key = "key".getBytes(); + byte[] arg1 = "value1".getBytes(); + byte[] arg2 = "value2".getBytes(); + + when(commandObjects.lpush(key, arg1, arg2)).thenReturn(longCommandObject); + + Response response = pipeliningBase.lpush(key, arg1, arg2); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testLpushx() { + when(commandObjects.lpushx("key", "value1", "value2")).thenReturn(longCommandObject); + + Response response = pipeliningBase.lpushx("key", "value1", "value2"); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testLpushxBinary() { + byte[] key = "key".getBytes(); + byte[] arg = "value".getBytes(); + + when(commandObjects.lpushx(key, arg)).thenReturn(longCommandObject); + + Response response = pipeliningBase.lpushx(key, arg); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testLrange() { + when(commandObjects.lrange("key", 0, -1)).thenReturn(listStringCommandObject); + + Response> response = pipeliningBase.lrange("key", 0, -1); + + assertThat(commands, contains(listStringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testLrangeBinary() { + byte[] key = "key".getBytes(); + long start = 0; + long stop = -1; + + when(commandObjects.lrange(key, start, stop)).thenReturn(listBytesCommandObject); + + Response> response = pipeliningBase.lrange(key, start, stop); + + assertThat(commands, contains(listBytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testLrem() { + when(commandObjects.lrem("key", 2, "value")).thenReturn(longCommandObject); + + Response response = pipeliningBase.lrem("key", 2, "value"); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testLremBinary() { + byte[] key = "key".getBytes(); + long count = 1; + byte[] value = "value".getBytes(); + + when(commandObjects.lrem(key, count, value)).thenReturn(longCommandObject); + + Response response = pipeliningBase.lrem(key, count, value); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testLset() { + when(commandObjects.lset("key", 1, "value")).thenReturn(stringCommandObject); + + Response response = pipeliningBase.lset("key", 1, "value"); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testLsetBinary() { + byte[] key = "key".getBytes(); + long index = 0; + byte[] value = "value".getBytes(); + + when(commandObjects.lset(key, index, value)).thenReturn(stringCommandObject); + + Response response = pipeliningBase.lset(key, index, value); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testLtrim() { + when(commandObjects.ltrim("key", 1, -1)).thenReturn(stringCommandObject); + + Response response = pipeliningBase.ltrim("key", 1, -1); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testLtrimBinary() { + byte[] key = "key".getBytes(); + long start = 1; + long stop = -1; + + when(commandObjects.ltrim(key, start, stop)).thenReturn(stringCommandObject); + + Response response = pipeliningBase.ltrim(key, start, stop); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testRpop() { + when(commandObjects.rpop("key")).thenReturn(stringCommandObject); + + Response response = pipeliningBase.rpop("key"); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testRpopBinary() { + byte[] key = "key".getBytes(); + + when(commandObjects.rpop(key)).thenReturn(bytesCommandObject); + + Response response = pipeliningBase.rpop(key); + + assertThat(commands, contains(bytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testRpopCount() { + when(commandObjects.rpop("key", 2)).thenReturn(listStringCommandObject); + + Response> response = pipeliningBase.rpop("key", 2); + + assertThat(commands, contains(listStringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testRpopCountBinary() { + byte[] key = "key".getBytes(); + int count = 2; + + when(commandObjects.rpop(key, count)).thenReturn(listBytesCommandObject); + + Response> response = pipeliningBase.rpop(key, count); + + assertThat(commands, contains(listBytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testRpoplpush() { + when(commandObjects.rpoplpush("srcKey", "dstKey")).thenReturn(stringCommandObject); + + Response response = pipeliningBase.rpoplpush("srcKey", "dstKey"); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testRpoplpushBinary() { + byte[] srckey = "srckey".getBytes(); + byte[] dstkey = "dstkey".getBytes(); + + when(commandObjects.rpoplpush(srckey, dstkey)).thenReturn(bytesCommandObject); + + Response response = pipeliningBase.rpoplpush(srckey, dstkey); + + assertThat(commands, contains(bytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testRpush() { + when(commandObjects.rpush("key", "value1", "value2")).thenReturn(longCommandObject); + + Response response = pipeliningBase.rpush("key", "value1", "value2"); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testRpushBinary() { + byte[] key = "key".getBytes(); + byte[] arg1 = "value1".getBytes(); + byte[] arg2 = "value2".getBytes(); + + when(commandObjects.rpush(key, arg1, arg2)).thenReturn(longCommandObject); + + Response response = pipeliningBase.rpush(key, arg1, arg2); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testRpushx() { + when(commandObjects.rpushx("key", "value1", "value2")).thenReturn(longCommandObject); + + Response response = pipeliningBase.rpushx("key", "value1", "value2"); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testRpushxBinary() { + byte[] key = "key".getBytes(); + byte[] arg = "value".getBytes(); + + when(commandObjects.rpushx(key, arg)).thenReturn(longCommandObject); + + Response response = pipeliningBase.rpushx(key, arg); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + +} diff --git a/src/test/java/redis/clients/jedis/mocked/pipeline/PipeliningBaseMiscellaneousTest.java b/src/test/java/redis/clients/jedis/mocked/pipeline/PipeliningBaseMiscellaneousTest.java new file mode 100644 index 00000000000..d712a5cdd47 --- /dev/null +++ b/src/test/java/redis/clients/jedis/mocked/pipeline/PipeliningBaseMiscellaneousTest.java @@ -0,0 +1,99 @@ +package redis.clients.jedis.mocked.pipeline; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.contains; +import static org.hamcrest.Matchers.hasSize; +import static org.hamcrest.Matchers.is; +import static org.mockito.Mockito.when; + +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; + +import org.junit.Test; +import redis.clients.jedis.BuilderFactory; +import redis.clients.jedis.CommandArguments; +import redis.clients.jedis.CommandObject; +import redis.clients.jedis.Protocol; +import redis.clients.jedis.Response; +import redis.clients.jedis.args.Rawable; +import redis.clients.jedis.commands.ProtocolCommand; + +/** + * {@link redis.clients.jedis.PipeliningBase} tests that don't really fall into any category of commands. + */ +public class PipeliningBaseMiscellaneousTest extends PipeliningBaseMockedTestBase { + + @Test + public void testSendCommandWithStringArgs() { + ProtocolCommand cmd = Protocol.Command.GET; + String arg1 = "key1"; + String arg2 = "key2"; + + Response response = pipeliningBase.sendCommand(cmd, arg1, arg2); + + assertThat(commands, hasSize(1)); + + List arguments = new ArrayList<>(); + commands.get(0).getArguments().forEach(arguments::add); + + assertThat(arguments.stream().map(Rawable::getRaw).collect(Collectors.toList()), contains( + Protocol.Command.GET.getRaw(), + arg1.getBytes(), + arg2.getBytes() + )); + + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testSendCommandWithByteArgs() { + ProtocolCommand cmd = Protocol.Command.SET; + byte[] arg1 = "key1".getBytes(); + byte[] arg2 = "value1".getBytes(); + + Response response = pipeliningBase.sendCommand(cmd, arg1, arg2); + + assertThat(commands, hasSize(1)); + + List arguments = new ArrayList<>(); + commands.get(0).getArguments().forEach(arguments::add); + + assertThat(arguments.stream().map(Rawable::getRaw).collect(Collectors.toList()), contains( + Protocol.Command.SET.getRaw(), + arg1, + arg2 + )); + + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testExecuteCommand() { + CommandArguments commandArguments = new CommandArguments(Protocol.Command.GET).key("key1"); + CommandObject commandObject = new CommandObject<>(commandArguments, BuilderFactory.STRING); + + Response response = pipeliningBase.executeCommand(commandObject); + + assertThat(commands, contains(commandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testMultipleCommands() { + when(commandObjects.exists("key1")).thenReturn(booleanCommandObject); + when(commandObjects.exists("key2")).thenReturn(booleanCommandObject); + + Response result1 = pipeliningBase.exists("key1"); + Response result2 = pipeliningBase.exists("key2"); + + assertThat(commands, contains( + booleanCommandObject, + booleanCommandObject + )); + + assertThat(result1, is(predefinedResponse)); + assertThat(result2, is(predefinedResponse)); + } + +} diff --git a/src/test/java/redis/clients/jedis/mocked/pipeline/PipeliningBaseMockedTestBase.java b/src/test/java/redis/clients/jedis/mocked/pipeline/PipeliningBaseMockedTestBase.java new file mode 100644 index 00000000000..e2ceac54df4 --- /dev/null +++ b/src/test/java/redis/clients/jedis/mocked/pipeline/PipeliningBaseMockedTestBase.java @@ -0,0 +1,87 @@ +package redis.clients.jedis.mocked.pipeline; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.Before; +import org.mockito.Mock; +import redis.clients.jedis.CommandObject; +import redis.clients.jedis.CommandObjects; +import redis.clients.jedis.PipeliningBase; +import redis.clients.jedis.Response; +import redis.clients.jedis.graph.GraphCommandObjects; +import redis.clients.jedis.mocked.MockedCommandObjectsTestBase; + +/** + * Base class for unit tests for {@link PipeliningBase}, using Mockito. Given that {@link PipeliningBase} + * is, essentially, only requesting commands from a {@link CommandObjects} instance and sending them + * to its subclasses, and given that it has many methods, using mocks is the most convenient and + * reliable way to completely test it. + */ +public abstract class PipeliningBaseMockedTestBase extends MockedCommandObjectsTestBase { + + /** + * A concrete implementation of {@link PipeliningBase} that collects all commands + * in a list (so that asserts can be run on the content of the list), and always returns a + * predefined response (so that the response can be asserted). + */ + private static class TestPipeliningBase extends PipeliningBase { + + private final Response predefinedResponse; + private final List> commands; + + public TestPipeliningBase(CommandObjects commandObjects, + GraphCommandObjects graphCommandObjects, + Response predefinedResponse, + List> commands) { + super(commandObjects); + setGraphCommands(graphCommandObjects); + this.predefinedResponse = predefinedResponse; + this.commands = commands; + } + + @Override + @SuppressWarnings("unchecked") + protected Response appendCommand(CommandObject commandObject) { + // Collect the command in the list. + commands.add(commandObject); + // Return a well known response, that can be asserted in the test cases. + return (Response) predefinedResponse; + } + } + + /** + * {@link PipeliningBase} under-test. Given that it is an abstract class, an in-place implementation + * is used, that collects commands in a list. + */ + protected PipeliningBase pipeliningBase; + + /** + * Accumulates commands sent by the {@link PipeliningBase} under-test to its subclass. + */ + protected final List> commands = new ArrayList<>(); + + /** + * {@link CommandObjects} instance used by the {@link PipeliningBase} under-test. Depending on + * the test case, it is trained to return one of the mock {@link CommandObject} instances below. + */ + @Mock + protected CommandObjects commandObjects; + + /** + * The {@link GraphCommandObjects} instance used by the {@link PipeliningBase} under-test. + */ + @Mock + protected GraphCommandObjects graphCommandObjects; + + /** + * Mock {@link Response} that is returned by {@link PipeliningBase} from each method. + */ + @Mock + protected Response predefinedResponse; + + @Before + public void setUp() { + pipeliningBase = new TestPipeliningBase(commandObjects, graphCommandObjects, predefinedResponse, commands); + } +} diff --git a/src/test/java/redis/clients/jedis/mocked/pipeline/PipeliningBaseScriptingAndFunctionsCommandsTest.java b/src/test/java/redis/clients/jedis/mocked/pipeline/PipeliningBaseScriptingAndFunctionsCommandsTest.java new file mode 100644 index 00000000000..a5aa8dc7eaa --- /dev/null +++ b/src/test/java/redis/clients/jedis/mocked/pipeline/PipeliningBaseScriptingAndFunctionsCommandsTest.java @@ -0,0 +1,705 @@ +package redis.clients.jedis.mocked.pipeline; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.contains; +import static org.hamcrest.Matchers.is; +import static org.mockito.Mockito.when; + +import java.util.Collections; +import java.util.List; + +import org.junit.Test; +import redis.clients.jedis.Response; +import redis.clients.jedis.args.FlushMode; +import redis.clients.jedis.args.FunctionRestorePolicy; +import redis.clients.jedis.resps.FunctionStats; +import redis.clients.jedis.resps.LibraryInfo; + +public class PipeliningBaseScriptingAndFunctionsCommandsTest extends PipeliningBaseMockedTestBase { + + @Test + public void testEval() { + String script = "return 'Hello, world!'"; + when(commandObjects.eval(script)).thenReturn(objectCommandObject); + + Response response = pipeliningBase.eval(script); + + assertThat(commands, contains(objectCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testEvalBinary() { + byte[] script = "return 'Hello, world!'".getBytes(); + + when(commandObjects.eval(script)).thenReturn(objectCommandObject); + + Response response = pipeliningBase.eval(script); + + assertThat(commands, contains(objectCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testEvalWithParams() { + String script = "return KEYS[1] .. ARGV[1]"; + int keyCount = 1; + + when(commandObjects.eval(script, keyCount, "key", "arg")).thenReturn(objectCommandObject); + + Response response = pipeliningBase.eval(script, keyCount, "key", "arg"); + + assertThat(commands, contains(objectCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testEvalWithParamsBinary() { + byte[] script = "return KEYS[1]".getBytes(); + int keyCount = 1; + byte[] param1 = "key1".getBytes(); + + when(commandObjects.eval(script, keyCount, param1)).thenReturn(objectCommandObject); + + Response response = pipeliningBase.eval(script, keyCount, param1); + + assertThat(commands, contains(objectCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testEvalWithLists() { + String script = "return KEYS[1] .. ARGV[1]"; + List keys = Collections.singletonList("key"); + List args = Collections.singletonList("arg"); + + when(commandObjects.eval(script, keys, args)).thenReturn(objectCommandObject); + + Response response = pipeliningBase.eval(script, keys, args); + + assertThat(commands, contains(objectCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testEvalWithListsBinary() { + byte[] script = "return {KEYS[1], ARGV[1]}".getBytes(); + List keys = Collections.singletonList("key1".getBytes()); + List args = Collections.singletonList("arg1".getBytes()); + + when(commandObjects.eval(script, keys, args)).thenReturn(objectCommandObject); + + Response response = pipeliningBase.eval(script, keys, args); + + assertThat(commands, contains(objectCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testEvalWithSampleKey() { + String script = "return 'Hello, world!'"; + + when(commandObjects.eval(script, "key")).thenReturn(objectCommandObject); + + Response response = pipeliningBase.eval(script, "key"); + + assertThat(commands, contains(objectCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testEvalWithSampleKeyBinary() { + byte[] script = "return 'Hello, world!'".getBytes(); + byte[] sampleKey = "sampleKey".getBytes(); + + when(commandObjects.eval(script, sampleKey)).thenReturn(objectCommandObject); + + Response response = pipeliningBase.eval(script, sampleKey); + + assertThat(commands, contains(objectCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testEvalReadonly() { + String script = "return KEYS[1] .. ARGV[1]"; + List keys = Collections.singletonList("key"); + List args = Collections.singletonList("arg"); + + when(commandObjects.evalReadonly(script, keys, args)).thenReturn(objectCommandObject); + + Response response = pipeliningBase.evalReadonly(script, keys, args); + + assertThat(commands, contains(objectCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testEvalReadonlyBinary() { + byte[] script = "return {KEYS[1], ARGV[1]}".getBytes(); + List keys = Collections.singletonList("key1".getBytes()); + List args = Collections.singletonList("arg1".getBytes()); + + when(commandObjects.evalReadonly(script, keys, args)).thenReturn(objectCommandObject); + + Response response = pipeliningBase.evalReadonly(script, keys, args); + + assertThat(commands, contains(objectCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testEvalsha() { + String sha1 = "somehash"; + + when(commandObjects.evalsha(sha1)).thenReturn(objectCommandObject); + + Response response = pipeliningBase.evalsha(sha1); + + assertThat(commands, contains(objectCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testEvalshaBinary() { + byte[] sha1 = "abcdef1234567890".getBytes(); + + when(commandObjects.evalsha(sha1)).thenReturn(objectCommandObject); + + Response response = pipeliningBase.evalsha(sha1); + + assertThat(commands, contains(objectCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testEvalshaWithParams() { + String sha1 = "somehash"; + int keyCount = 1; + + when(commandObjects.evalsha(sha1, keyCount, "key", "arg")).thenReturn(objectCommandObject); + + Response response = pipeliningBase.evalsha(sha1, keyCount, "key", "arg"); + + assertThat(commands, contains(objectCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testEvalshaWithParamsBinary() { + byte[] sha1 = "abcdef1234567890".getBytes(); + int keyCount = 1; + byte[] param1 = "key1".getBytes(); + + when(commandObjects.evalsha(sha1, keyCount, param1)).thenReturn(objectCommandObject); + + Response response = pipeliningBase.evalsha(sha1, keyCount, param1); + + assertThat(commands, contains(objectCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testEvalshaWithLists() { + String sha1 = "somehash"; + List keys = Collections.singletonList("key"); + List args = Collections.singletonList("arg"); + + when(commandObjects.evalsha(sha1, keys, args)).thenReturn(objectCommandObject); + + Response response = pipeliningBase.evalsha(sha1, keys, args); + + assertThat(commands, contains(objectCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testEvalshaWithListsBinary() { + byte[] sha1 = "abcdef1234567890".getBytes(); + List keys = Collections.singletonList("key1".getBytes()); + List args = Collections.singletonList("arg1".getBytes()); + + when(commandObjects.evalsha(sha1, keys, args)).thenReturn(objectCommandObject); + + Response response = pipeliningBase.evalsha(sha1, keys, args); + + assertThat(commands, contains(objectCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testEvalshaWithSampleKey() { + String sha1 = "somehash"; + + when(commandObjects.evalsha(sha1, "key")).thenReturn(objectCommandObject); + + Response response = pipeliningBase.evalsha(sha1, "key"); + + assertThat(commands, contains(objectCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testEvalshaWithSampleKeyBinary() { + byte[] sha1 = "abcdef1234567890".getBytes(); + byte[] sampleKey = "sampleKey".getBytes(); + + when(commandObjects.evalsha(sha1, sampleKey)).thenReturn(objectCommandObject); + + Response response = pipeliningBase.evalsha(sha1, sampleKey); + + assertThat(commands, contains(objectCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testEvalshaReadonly() { + String sha1 = "somehash"; + List keys = Collections.singletonList("key"); + List args = Collections.singletonList("arg"); + + when(commandObjects.evalshaReadonly(sha1, keys, args)).thenReturn(objectCommandObject); + + Response response = pipeliningBase.evalshaReadonly(sha1, keys, args); + + assertThat(commands, contains(objectCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testEvalshaReadonlyBinary() { + byte[] sha1 = "abcdef1234567890".getBytes(); + List keys = Collections.singletonList("key1".getBytes()); + List args = Collections.singletonList("arg1".getBytes()); + + when(commandObjects.evalshaReadonly(sha1, keys, args)).thenReturn(objectCommandObject); + + Response response = pipeliningBase.evalshaReadonly(sha1, keys, args); + + assertThat(commands, contains(objectCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testFcall() { + String name = "functionName"; + List keys = Collections.singletonList("key"); + List args = Collections.singletonList("arg"); + + when(commandObjects.fcall(name, keys, args)).thenReturn(objectCommandObject); + + Response response = pipeliningBase.fcall(name, keys, args); + + assertThat(commands, contains(objectCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testFcallBinary() { + byte[] name = "functionName".getBytes(); + List keys = Collections.singletonList("key".getBytes()); + List args = Collections.singletonList("arg".getBytes()); + + when(commandObjects.fcall(name, keys, args)).thenReturn(objectCommandObject); + + Response response = pipeliningBase.fcall(name, keys, args); + + assertThat(commands, contains(objectCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testFcallReadonly() { + String name = "functionName"; + List keys = Collections.singletonList("key"); + List args = Collections.singletonList("arg"); + + when(commandObjects.fcallReadonly(name, keys, args)).thenReturn(objectCommandObject); + + Response response = pipeliningBase.fcallReadonly(name, keys, args); + + assertThat(commands, contains(objectCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testFcallReadonlyBinary() { + byte[] name = "functionName".getBytes(); + List keys = Collections.singletonList("key".getBytes()); + List args = Collections.singletonList("arg".getBytes()); + + when(commandObjects.fcallReadonly(name, keys, args)).thenReturn(objectCommandObject); + + Response response = pipeliningBase.fcallReadonly(name, keys, args); + + assertThat(commands, contains(objectCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testFunctionDelete() { + String libraryName = "libraryName"; + + when(commandObjects.functionDelete(libraryName)).thenReturn(stringCommandObject); + + Response response = pipeliningBase.functionDelete(libraryName); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testFunctionDeleteBinary() { + byte[] libraryName = "libraryName".getBytes(); + + when(commandObjects.functionDelete(libraryName)).thenReturn(stringCommandObject); + + Response response = pipeliningBase.functionDelete(libraryName); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testFunctionDump() { + when(commandObjects.functionDump()).thenReturn(bytesCommandObject); + + Response response = pipeliningBase.functionDump(); + + assertThat(commands, contains(bytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testFunctionFlush() { + when(commandObjects.functionFlush()).thenReturn(stringCommandObject); + + Response response = pipeliningBase.functionFlush(); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testFunctionFlushWithMode() { + FlushMode mode = FlushMode.SYNC; + + when(commandObjects.functionFlush(mode)).thenReturn(stringCommandObject); + + Response response = pipeliningBase.functionFlush(mode); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testFunctionKill() { + when(commandObjects.functionKill()).thenReturn(stringCommandObject); + + Response response = pipeliningBase.functionKill(); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testFunctionList() { + when(commandObjects.functionList()).thenReturn(listLibraryInfoCommandObject); + + Response> response = pipeliningBase.functionList(); + + assertThat(commands, contains(listLibraryInfoCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testFunctionListBinary() { + when(commandObjects.functionListBinary()).thenReturn(listObjectCommandObject); + + Response> response = pipeliningBase.functionListBinary(); + + assertThat(commands, contains(listObjectCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testFunctionListWithPattern() { + String libraryNamePattern = "lib*"; + + when(commandObjects.functionList(libraryNamePattern)).thenReturn(listLibraryInfoCommandObject); + + Response> response = pipeliningBase.functionList(libraryNamePattern); + + assertThat(commands, contains(listLibraryInfoCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testFunctionListWithPatternBinary() { + byte[] libraryNamePattern = "lib*".getBytes(); + + when(commandObjects.functionList(libraryNamePattern)).thenReturn(listObjectCommandObject); + + Response> response = pipeliningBase.functionList(libraryNamePattern); + + assertThat(commands, contains(listObjectCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testFunctionListWithCode() { + when(commandObjects.functionListWithCode()).thenReturn(listLibraryInfoCommandObject); + + Response> response = pipeliningBase.functionListWithCode(); + + assertThat(commands, contains(listLibraryInfoCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testFunctionListWithCodeBinary() { + when(commandObjects.functionListWithCodeBinary()).thenReturn(listObjectCommandObject); + + Response> response = pipeliningBase.functionListWithCodeBinary(); + + assertThat(commands, contains(listObjectCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testFunctionListWithCodeAndPattern() { + String libraryNamePattern = "lib*"; + + when(commandObjects.functionListWithCode(libraryNamePattern)).thenReturn(listLibraryInfoCommandObject); + + Response> response = pipeliningBase.functionListWithCode(libraryNamePattern); + + assertThat(commands, contains(listLibraryInfoCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testFunctionListWithCodeAndPatternBinary() { + byte[] libraryNamePattern = "lib*".getBytes(); + + when(commandObjects.functionListWithCode(libraryNamePattern)).thenReturn(listObjectCommandObject); + + Response> response = pipeliningBase.functionListWithCode(libraryNamePattern); + + assertThat(commands, contains(listObjectCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testFunctionLoad() { + String functionCode = "return 'Hello, world!'"; + + when(commandObjects.functionLoad(functionCode)).thenReturn(stringCommandObject); + + Response response = pipeliningBase.functionLoad(functionCode); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testFunctionLoadBinary() { + byte[] functionCode = "return 'Hello, world!'".getBytes(); + + when(commandObjects.functionLoad(functionCode)).thenReturn(stringCommandObject); + + Response response = pipeliningBase.functionLoad(functionCode); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testFunctionLoadReplace() { + String functionCode = "return 'Hello, world!'"; + + when(commandObjects.functionLoadReplace(functionCode)).thenReturn(stringCommandObject); + + Response response = pipeliningBase.functionLoadReplace(functionCode); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testFunctionLoadReplaceBinary() { + byte[] functionCode = "return 'Hello, world!'".getBytes(); + + when(commandObjects.functionLoadReplace(functionCode)).thenReturn(stringCommandObject); + + Response response = pipeliningBase.functionLoadReplace(functionCode); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testFunctionRestore() { + byte[] serializedValue = "serialized".getBytes(); + + when(commandObjects.functionRestore(serializedValue)).thenReturn(stringCommandObject); + + Response response = pipeliningBase.functionRestore(serializedValue); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testFunctionRestoreWithPolicy() { + byte[] serializedValue = "serialized".getBytes(); + FunctionRestorePolicy policy = FunctionRestorePolicy.FLUSH; + + when(commandObjects.functionRestore(serializedValue, policy)).thenReturn(stringCommandObject); + + Response response = pipeliningBase.functionRestore(serializedValue, policy); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testFunctionStats() { + when(commandObjects.functionStats()).thenReturn(functionStatsCommandObject); + + Response response = pipeliningBase.functionStats(); + + assertThat(commands, contains(functionStatsCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testFunctionStatsBinary() { + when(commandObjects.functionStatsBinary()).thenReturn(objectCommandObject); + + Response response = pipeliningBase.functionStatsBinary(); + + assertThat(commands, contains(objectCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testScriptExistsWithKeyAndSha1s() { + String[] sha1 = { "somehash1", "somehash2" }; + + when(commandObjects.scriptExists("key", sha1)).thenReturn(listBooleanCommandObject); + + Response> response = pipeliningBase.scriptExists("key", sha1); + + assertThat(commands, contains(listBooleanCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testScriptExistsWithKeyAndSha1sBinary() { + byte[] sampleKey = "sampleKey".getBytes(); + byte[] sha1 = "abcdef1234567890".getBytes(); + + when(commandObjects.scriptExists(sampleKey, sha1)).thenReturn(listBooleanCommandObject); + + Response> response = pipeliningBase.scriptExists(sampleKey, sha1); + + assertThat(commands, contains(listBooleanCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testScriptFlush() { + when(commandObjects.scriptFlush("key")).thenReturn(stringCommandObject); + + Response response = pipeliningBase.scriptFlush("key"); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testScriptFlushBinary() { + byte[] sampleKey = "sampleKey".getBytes(); + + when(commandObjects.scriptFlush(sampleKey)).thenReturn(stringCommandObject); + + Response response = pipeliningBase.scriptFlush(sampleKey); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testScriptFlushWithMode() { + FlushMode flushMode = FlushMode.SYNC; + + when(commandObjects.scriptFlush("key", flushMode)).thenReturn(stringCommandObject); + + Response response = pipeliningBase.scriptFlush("key", flushMode); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testScriptFlushWithModeBinary() { + byte[] sampleKey = "sampleKey".getBytes(); + FlushMode flushMode = FlushMode.SYNC; + + when(commandObjects.scriptFlush(sampleKey, flushMode)).thenReturn(stringCommandObject); + + Response response = pipeliningBase.scriptFlush(sampleKey, flushMode); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testScriptKill() { + when(commandObjects.scriptKill("key")).thenReturn(stringCommandObject); + + Response response = pipeliningBase.scriptKill("key"); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testScriptKillBinary() { + byte[] sampleKey = "sampleKey".getBytes(); + + when(commandObjects.scriptKill(sampleKey)).thenReturn(stringCommandObject); + + Response response = pipeliningBase.scriptKill(sampleKey); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testScriptLoad() { + String script = "return 'Hello, world!'"; + + when(commandObjects.scriptLoad(script, "key")).thenReturn(stringCommandObject); + + Response response = pipeliningBase.scriptLoad(script, "key"); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testScriptLoadBinary() { + byte[] script = "return 'Hello, world!'".getBytes(); + byte[] sampleKey = "sampleKey".getBytes(); + + when(commandObjects.scriptLoad(script, sampleKey)).thenReturn(bytesCommandObject); + + Response response = pipeliningBase.scriptLoad(script, sampleKey); + + assertThat(commands, contains(bytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + +} diff --git a/src/test/java/redis/clients/jedis/mocked/pipeline/PipeliningBaseSearchAndQueryCommandsTest.java b/src/test/java/redis/clients/jedis/mocked/pipeline/PipeliningBaseSearchAndQueryCommandsTest.java new file mode 100644 index 00000000000..4ac820d693d --- /dev/null +++ b/src/test/java/redis/clients/jedis/mocked/pipeline/PipeliningBaseSearchAndQueryCommandsTest.java @@ -0,0 +1,472 @@ +package redis.clients.jedis.mocked.pipeline; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.contains; +import static org.hamcrest.Matchers.is; +import static org.mockito.Mockito.when; + +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import org.junit.Test; +import redis.clients.jedis.Response; +import redis.clients.jedis.resps.Tuple; +import redis.clients.jedis.search.FTCreateParams; +import redis.clients.jedis.search.FTSearchParams; +import redis.clients.jedis.search.FTSpellCheckParams; +import redis.clients.jedis.search.IndexOptions; +import redis.clients.jedis.search.Query; +import redis.clients.jedis.search.Schema; +import redis.clients.jedis.search.SearchResult; +import redis.clients.jedis.search.aggr.AggregationBuilder; +import redis.clients.jedis.search.aggr.AggregationResult; +import redis.clients.jedis.search.schemafields.SchemaField; +import redis.clients.jedis.search.schemafields.TextField; + +public class PipeliningBaseSearchAndQueryCommandsTest extends PipeliningBaseMockedTestBase { + + @Test + public void testFtAggregate() { + AggregationBuilder aggr = new AggregationBuilder().groupBy("@field"); + + when(commandObjects.ftAggregate("myIndex", aggr)).thenReturn(aggregationResultCommandObject); + + Response response = pipeliningBase.ftAggregate("myIndex", aggr); + + assertThat(commands, contains(aggregationResultCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testFtAliasAdd() { + when(commandObjects.ftAliasAdd("myAlias", "myIndex")).thenReturn(stringCommandObject); + + Response response = pipeliningBase.ftAliasAdd("myAlias", "myIndex"); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testFtAliasDel() { + when(commandObjects.ftAliasDel("myAlias")).thenReturn(stringCommandObject); + + Response response = pipeliningBase.ftAliasDel("myAlias"); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testFtAliasUpdate() { + when(commandObjects.ftAliasUpdate("myAlias", "myIndex")).thenReturn(stringCommandObject); + + Response response = pipeliningBase.ftAliasUpdate("myAlias", "myIndex"); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testFtAlterWithSchema() { + Schema schema = new Schema().addField(new Schema.Field("newField", Schema.FieldType.TEXT)); + + when(commandObjects.ftAlter("myIndex", schema)).thenReturn(stringCommandObject); + + Response response = pipeliningBase.ftAlter("myIndex", schema); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testFtAlterWithSchemaFields() { + Iterable schemaFields = Collections.singletonList(new TextField("newField")); + + when(commandObjects.ftAlter("myIndex", schemaFields)).thenReturn(stringCommandObject); + + Response response = pipeliningBase.ftAlter("myIndex", schemaFields); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testFtConfigGet() { + when(commandObjects.ftConfigGet("TIMEOUT")).thenReturn(mapStringObjectCommandObject); + + Response> response = pipeliningBase.ftConfigGet("TIMEOUT"); + + assertThat(commands, contains(mapStringObjectCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testFtConfigGetWithIndexName() { + when(commandObjects.ftConfigGet("myIndex", "TIMEOUT")).thenReturn(mapStringObjectCommandObject); + + Response> response = pipeliningBase.ftConfigGet("myIndex", "TIMEOUT"); + + assertThat(commands, contains(mapStringObjectCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testFtConfigSet() { + when(commandObjects.ftConfigSet("TIMEOUT", "100")).thenReturn(stringCommandObject); + + Response response = pipeliningBase.ftConfigSet("TIMEOUT", "100"); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testFtConfigSetWithIndexName() { + when(commandObjects.ftConfigSet("myIndex", "TIMEOUT", "100")).thenReturn(stringCommandObject); + + Response response = pipeliningBase.ftConfigSet("myIndex", "TIMEOUT", "100"); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testFtCreateWithOptionsAndSchema() { + IndexOptions indexOptions = IndexOptions.defaultOptions(); + Schema schema = new Schema().addField(new Schema.Field("myField", Schema.FieldType.TEXT)); + + when(commandObjects.ftCreate("myIndex", indexOptions, schema)).thenReturn(stringCommandObject); + + Response response = pipeliningBase.ftCreate("myIndex", indexOptions, schema); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testFtCreateWithCreateParamsAndSchemaFields() { + FTCreateParams createParams = FTCreateParams.createParams(); + Iterable schemaFields = Collections.singletonList(new TextField("myField")); + + when(commandObjects.ftCreate("myIndex", createParams, schemaFields)).thenReturn(stringCommandObject); + + Response response = pipeliningBase.ftCreate("myIndex", createParams, schemaFields); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testFtDictAdd() { + String[] terms = { "term1", "term2" }; + + when(commandObjects.ftDictAdd("myDict", terms)).thenReturn(longCommandObject); + + Response response = pipeliningBase.ftDictAdd("myDict", terms); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testFtDictAddBySampleKey() { + String[] terms = { "term1", "term2" }; + + when(commandObjects.ftDictAddBySampleKey("myIndex", "myDict", terms)).thenReturn(longCommandObject); + + Response response = pipeliningBase.ftDictAddBySampleKey("myIndex", "myDict", terms); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testFtDictDel() { + String[] terms = { "term1", "term2" }; + + when(commandObjects.ftDictDel("myDict", terms)).thenReturn(longCommandObject); + + Response response = pipeliningBase.ftDictDel("myDict", terms); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testFtDictDelBySampleKey() { + String[] terms = { "term1", "term2" }; + + when(commandObjects.ftDictDelBySampleKey("myIndex", "myDict", terms)).thenReturn(longCommandObject); + + Response response = pipeliningBase.ftDictDelBySampleKey("myIndex", "myDict", terms); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testFtDictDump() { + when(commandObjects.ftDictDump("myDict")).thenReturn(setStringCommandObject); + + Response> response = pipeliningBase.ftDictDump("myDict"); + + assertThat(commands, contains(setStringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testFtDictDumpBySampleKey() { + when(commandObjects.ftDictDumpBySampleKey("myIndex", "myDict")).thenReturn(setStringCommandObject); + + Response> response = pipeliningBase.ftDictDumpBySampleKey("myIndex", "myDict"); + + assertThat(commands, contains(setStringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testFtDropIndex() { + when(commandObjects.ftDropIndex("myIndex")).thenReturn(stringCommandObject); + + Response response = pipeliningBase.ftDropIndex("myIndex"); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testFtDropIndexDD() { + when(commandObjects.ftDropIndexDD("myIndex")).thenReturn(stringCommandObject); + + Response response = pipeliningBase.ftDropIndexDD("myIndex"); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testFtExplain() { + Query query = new Query("hello world"); + + when(commandObjects.ftExplain("myIndex", query)).thenReturn(stringCommandObject); + + Response response = pipeliningBase.ftExplain("myIndex", query); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testFtExplainCLI() { + Query query = new Query("hello world"); + + when(commandObjects.ftExplainCLI("myIndex", query)).thenReturn(listStringCommandObject); + + Response> response = pipeliningBase.ftExplainCLI("myIndex", query); + + assertThat(commands, contains(listStringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testFtInfo() { + when(commandObjects.ftInfo("myIndex")).thenReturn(mapStringObjectCommandObject); + + Response> response = pipeliningBase.ftInfo("myIndex"); + + assertThat(commands, contains(mapStringObjectCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testFtSearch() { + String query = "hello world"; + + when(commandObjects.ftSearch("myIndex", query)).thenReturn(searchResultCommandObject); + + Response response = pipeliningBase.ftSearch("myIndex", query); + + assertThat(commands, contains(searchResultCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testFtSearchWithParams() { + String query = "hello world"; + FTSearchParams searchParams = FTSearchParams.searchParams().limit(0, 10); + + when(commandObjects.ftSearch("myIndex", query, searchParams)).thenReturn(searchResultCommandObject); + + Response response = pipeliningBase.ftSearch("myIndex", query, searchParams); + + assertThat(commands, contains(searchResultCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testFtSearchWithQueryObject() { + Query query = new Query("hello world").limit(0, 10); + + when(commandObjects.ftSearch("myIndex", query)).thenReturn(searchResultCommandObject); + + Response response = pipeliningBase.ftSearch("myIndex", query); + + assertThat(commands, contains(searchResultCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testFtSearchWithQueryObjectBinary() { + byte[] indexName = "myIndex".getBytes(); + Query query = new Query("hello world").limit(0, 10); + + when(commandObjects.ftSearch(indexName, query)).thenReturn(searchResultCommandObject); + + Response response = pipeliningBase.ftSearch(indexName, query); + + assertThat(commands, contains(searchResultCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testFtSpellCheck() { + String query = "hello world"; + + when(commandObjects.ftSpellCheck("myIndex", query)).thenReturn(mapStringMapStringDoubleCommandObject); + + Response>> response = pipeliningBase.ftSpellCheck("myIndex", query); + + assertThat(commands, contains(mapStringMapStringDoubleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testFtSpellCheckWithParams() { + String query = "hello world"; + FTSpellCheckParams spellCheckParams = new FTSpellCheckParams().distance(1); + + when(commandObjects.ftSpellCheck("myIndex", query, spellCheckParams)).thenReturn(mapStringMapStringDoubleCommandObject); + + Response>> response = pipeliningBase.ftSpellCheck("myIndex", query, spellCheckParams); + + assertThat(commands, contains(mapStringMapStringDoubleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testFtSynDump() { + when(commandObjects.ftSynDump("myIndex")).thenReturn(mapStringListStringCommandObject); + + Response>> response = pipeliningBase.ftSynDump("myIndex"); + + assertThat(commands, contains(mapStringListStringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testFtSynUpdate() { + String synonymGroupId = "group1"; + String[] terms = { "term1", "term2" }; + + when(commandObjects.ftSynUpdate("myIndex", synonymGroupId, terms)).thenReturn(stringCommandObject); + + Response response = pipeliningBase.ftSynUpdate("myIndex", synonymGroupId, terms); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testFtTagVals() { + when(commandObjects.ftTagVals("myIndex", "myField")).thenReturn(setStringCommandObject); + + Response> response = pipeliningBase.ftTagVals("myIndex", "myField"); + + assertThat(commands, contains(setStringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testFtSugAdd() { + when(commandObjects.ftSugAdd("mySug", "hello", 1.0)).thenReturn(longCommandObject); + + Response response = pipeliningBase.ftSugAdd("mySug", "hello", 1.0); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testFtSugAddIncr() { + when(commandObjects.ftSugAddIncr("mySug", "hello", 1.0)).thenReturn(longCommandObject); + + Response response = pipeliningBase.ftSugAddIncr("mySug", "hello", 1.0); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testFtSugDel() { + when(commandObjects.ftSugDel("mySug", "hello")).thenReturn(booleanCommandObject); + + Response response = pipeliningBase.ftSugDel("mySug", "hello"); + + assertThat(commands, contains(booleanCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testFtSugGet() { + when(commandObjects.ftSugGet("mySug", "he")).thenReturn(listStringCommandObject); + + Response> response = pipeliningBase.ftSugGet("mySug", "he"); + + assertThat(commands, contains(listStringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testFtSugGetWithFuzzyAndMax() { + when(commandObjects.ftSugGet("mySug", "he", true, 10)).thenReturn(listStringCommandObject); + + Response> response = pipeliningBase.ftSugGet("mySug", "he", true, 10); + + assertThat(commands, contains(listStringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testFtSugGetWithScores() { + when(commandObjects.ftSugGetWithScores("mySug", "he")).thenReturn(listTupleCommandObject); + + Response> response = pipeliningBase.ftSugGetWithScores("mySug", "he"); + + assertThat(commands, contains(listTupleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testFtSugGetWithScoresFuzzyMax() { + when(commandObjects.ftSugGetWithScores("mySug", "he", true, 10)).thenReturn(listTupleCommandObject); + + Response> response = pipeliningBase.ftSugGetWithScores("mySug", "he", true, 10); + + assertThat(commands, contains(listTupleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testFtSugLen() { + when(commandObjects.ftSugLen("mySug")).thenReturn(longCommandObject); + + Response response = pipeliningBase.ftSugLen("mySug"); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + +} diff --git a/src/test/java/redis/clients/jedis/mocked/pipeline/PipeliningBaseServerManagementCommandsTest.java b/src/test/java/redis/clients/jedis/mocked/pipeline/PipeliningBaseServerManagementCommandsTest.java new file mode 100644 index 00000000000..2a7365daceb --- /dev/null +++ b/src/test/java/redis/clients/jedis/mocked/pipeline/PipeliningBaseServerManagementCommandsTest.java @@ -0,0 +1,58 @@ +package redis.clients.jedis.mocked.pipeline; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.contains; +import static org.hamcrest.Matchers.is; +import static org.mockito.Mockito.when; + +import org.junit.Test; +import redis.clients.jedis.Response; + +public class PipeliningBaseServerManagementCommandsTest extends PipeliningBaseMockedTestBase { + + @Test + public void testMemoryUsage() { + when(commandObjects.memoryUsage("key")).thenReturn(longCommandObject); + + Response response = pipeliningBase.memoryUsage("key"); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testMemoryUsageBinary() { + byte[] key = "key".getBytes(); + + when(commandObjects.memoryUsage(key)).thenReturn(longCommandObject); + + Response response = pipeliningBase.memoryUsage(key); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testMemoryUsageWithSamples() { + when(commandObjects.memoryUsage("key", 10)).thenReturn(longCommandObject); + + Response response = pipeliningBase.memoryUsage("key", 10); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testMemoryUsageWithSamplesBinary() { + byte[] key = "key".getBytes(); + int samples = 5; + + when(commandObjects.memoryUsage(key, samples)).thenReturn(longCommandObject); + + Response response = pipeliningBase.memoryUsage(key, samples); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + +} diff --git a/src/test/java/redis/clients/jedis/mocked/pipeline/PipeliningBaseSetCommandsTest.java b/src/test/java/redis/clients/jedis/mocked/pipeline/PipeliningBaseSetCommandsTest.java new file mode 100644 index 00000000000..694461a5a8e --- /dev/null +++ b/src/test/java/redis/clients/jedis/mocked/pipeline/PipeliningBaseSetCommandsTest.java @@ -0,0 +1,484 @@ +package redis.clients.jedis.mocked.pipeline; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.contains; +import static org.hamcrest.Matchers.is; +import static org.mockito.Mockito.when; + +import java.util.List; +import java.util.Set; + +import org.junit.Test; +import redis.clients.jedis.Response; +import redis.clients.jedis.params.ScanParams; +import redis.clients.jedis.resps.ScanResult; + +public class PipeliningBaseSetCommandsTest extends PipeliningBaseMockedTestBase { + + @Test + public void testSadd() { + when(commandObjects.sadd("key", "member1", "member2")).thenReturn(longCommandObject); + + Response response = pipeliningBase.sadd("key", "member1", "member2"); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testSaddBinary() { + byte[] key = "key".getBytes(); + byte[] member1 = "member1".getBytes(); + byte[] member2 = "member2".getBytes(); + + when(commandObjects.sadd(key, member1, member2)).thenReturn(longCommandObject); + + Response response = pipeliningBase.sadd(key, member1, member2); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testScard() { + when(commandObjects.scard("key")).thenReturn(longCommandObject); + + Response response = pipeliningBase.scard("key"); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testScardBinary() { + byte[] key = "key".getBytes(); + + when(commandObjects.scard(key)).thenReturn(longCommandObject); + + Response response = pipeliningBase.scard(key); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testSdiff() { + when(commandObjects.sdiff("key1", "key2")).thenReturn(setStringCommandObject); + + Response> response = pipeliningBase.sdiff("key1", "key2"); + + assertThat(commands, contains(setStringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testSdiffBinary() { + byte[][] keys = { "key1".getBytes(), "key2".getBytes(), "key3".getBytes() }; + + when(commandObjects.sdiff(keys)).thenReturn(setBytesCommandObject); + + Response> response = pipeliningBase.sdiff(keys); + + assertThat(commands, contains(setBytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testSdiffstore() { + when(commandObjects.sdiffstore("dstKey", "key1", "key2")).thenReturn(longCommandObject); + + Response response = pipeliningBase.sdiffstore("dstKey", "key1", "key2"); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testSdiffstoreBinary() { + byte[] dstkey = "destination".getBytes(); + byte[][] keys = { "key1".getBytes(), "key2".getBytes() }; + + when(commandObjects.sdiffstore(dstkey, keys)).thenReturn(longCommandObject); + + Response response = pipeliningBase.sdiffstore(dstkey, keys); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testSinter() { + when(commandObjects.sinter("key1", "key2")).thenReturn(setStringCommandObject); + + Response> response = pipeliningBase.sinter("key1", "key2"); + + assertThat(commands, contains(setStringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testSinterBinary() { + byte[][] keys = { "key1".getBytes(), "key2".getBytes() }; + + when(commandObjects.sinter(keys)).thenReturn(setBytesCommandObject); + + Response> response = pipeliningBase.sinter(keys); + + assertThat(commands, contains(setBytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testSintercard() { + when(commandObjects.sintercard("key1", "key2")).thenReturn(longCommandObject); + + Response response = pipeliningBase.sintercard("key1", "key2"); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testSintercardBinary() { + byte[][] keys = { "key1".getBytes(), "key2".getBytes() }; + + when(commandObjects.sintercard(keys)).thenReturn(longCommandObject); + + Response response = pipeliningBase.sintercard(keys); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testSintercardWithLimit() { + int limit = 1; + + when(commandObjects.sintercard(limit, "key1", "key2")).thenReturn(longCommandObject); + + Response response = pipeliningBase.sintercard(limit, "key1", "key2"); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testSintercardWithLimitBinary() { + int limit = 2; + byte[][] keys = { "key1".getBytes(), "key2".getBytes() }; + + when(commandObjects.sintercard(limit, keys)).thenReturn(longCommandObject); + + Response response = pipeliningBase.sintercard(limit, keys); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testSinterstore() { + when(commandObjects.sinterstore("dstKey", "key1", "key2")).thenReturn(longCommandObject); + + Response response = pipeliningBase.sinterstore("dstKey", "key1", "key2"); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testSinterstoreBinary() { + byte[] dstkey = "destination".getBytes(); + byte[][] keys = { "key1".getBytes(), "key2".getBytes() }; + + when(commandObjects.sinterstore(dstkey, keys)).thenReturn(longCommandObject); + + Response response = pipeliningBase.sinterstore(dstkey, keys); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testSismember() { + when(commandObjects.sismember("key", "member")).thenReturn(booleanCommandObject); + + Response response = pipeliningBase.sismember("key", "member"); + + assertThat(commands, contains(booleanCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testSismemberBinary() { + byte[] key = "key".getBytes(); + byte[] member = "member".getBytes(); + + when(commandObjects.sismember(key, member)).thenReturn(booleanCommandObject); + + Response response = pipeliningBase.sismember(key, member); + + assertThat(commands, contains(booleanCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testSmembers() { + when(commandObjects.smembers("key")).thenReturn(setStringCommandObject); + + Response> response = pipeliningBase.smembers("key"); + + assertThat(commands, contains(setStringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testSmembersBinary() { + byte[] key = "key".getBytes(); + + when(commandObjects.smembers(key)).thenReturn(setBytesCommandObject); + + Response> response = pipeliningBase.smembers(key); + + assertThat(commands, contains(setBytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testSmismember() { + when(commandObjects.smismember("key", "member1", "member2")).thenReturn(listBooleanCommandObject); + + Response> response = pipeliningBase.smismember("key", "member1", "member2"); + + assertThat(commands, contains(listBooleanCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testSmismemberBinary() { + byte[] key = "key".getBytes(); + byte[] member1 = "member1".getBytes(); + byte[] member2 = "member2".getBytes(); + + when(commandObjects.smismember(key, member1, member2)).thenReturn(listBooleanCommandObject); + + Response> response = pipeliningBase.smismember(key, member1, member2); + + assertThat(commands, contains(listBooleanCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testSmove() { + when(commandObjects.smove("srcKey", "dstKey", "member")).thenReturn(longCommandObject); + + Response response = pipeliningBase.smove("srcKey", "dstKey", "member"); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testSmoveBinary() { + byte[] srckey = "source".getBytes(); + byte[] dstkey = "destination".getBytes(); + byte[] member = "member".getBytes(); + + when(commandObjects.smove(srckey, dstkey, member)).thenReturn(longCommandObject); + + Response response = pipeliningBase.smove(srckey, dstkey, member); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testSpop() { + when(commandObjects.spop("key")).thenReturn(stringCommandObject); + + Response response = pipeliningBase.spop("key"); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testSpopBinary() { + byte[] key = "key".getBytes(); + + when(commandObjects.spop(key)).thenReturn(bytesCommandObject); + + Response response = pipeliningBase.spop(key); + + assertThat(commands, contains(bytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testSpopCount() { + long count = 2; + + when(commandObjects.spop("key", count)).thenReturn(setStringCommandObject); + + Response> response = pipeliningBase.spop("key", count); + + assertThat(commands, contains(setStringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testSpopCountBinary() { + byte[] key = "key".getBytes(); + long count = 2; + + when(commandObjects.spop(key, count)).thenReturn(setBytesCommandObject); + + Response> response = pipeliningBase.spop(key, count); + + assertThat(commands, contains(setBytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testSrandmember() { + when(commandObjects.srandmember("key")).thenReturn(stringCommandObject); + + Response response = pipeliningBase.srandmember("key"); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testSrandmemberBinary() { + byte[] key = "key".getBytes(); + + when(commandObjects.srandmember(key)).thenReturn(bytesCommandObject); + + Response response = pipeliningBase.srandmember(key); + + assertThat(commands, contains(bytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testSrandmemberCount() { + int count = 2; + + when(commandObjects.srandmember("key", count)).thenReturn(listStringCommandObject); + + Response> response = pipeliningBase.srandmember("key", count); + + assertThat(commands, contains(listStringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testSrandmemberCountBinary() { + byte[] key = "key".getBytes(); + int count = 2; + + when(commandObjects.srandmember(key, count)).thenReturn(listBytesCommandObject); + + Response> response = pipeliningBase.srandmember(key, count); + + assertThat(commands, contains(listBytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testSrem() { + when(commandObjects.srem("key", "member1", "member2")).thenReturn(longCommandObject); + + Response response = pipeliningBase.srem("key", "member1", "member2"); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testSremBinary() { + byte[] key = "key".getBytes(); + byte[] member1 = "member1".getBytes(); + byte[] member2 = "member2".getBytes(); + + when(commandObjects.srem(key, member1, member2)).thenReturn(longCommandObject); + + Response response = pipeliningBase.srem(key, member1, member2); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testSscan() { + String cursor = "0"; + ScanParams params = new ScanParams(); + + when(commandObjects.sscan("key", cursor, params)).thenReturn(scanResultStringCommandObject); + + Response> response = pipeliningBase.sscan("key", cursor, params); + + assertThat(commands, contains(scanResultStringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testSscanBinary() { + byte[] key = "key".getBytes(); + byte[] cursor = "0".getBytes(); + ScanParams params = new ScanParams().match("pattern*").count(10); + + when(commandObjects.sscan(key, cursor, params)).thenReturn(scanResultBytesCommandObject); + + Response> response = pipeliningBase.sscan(key, cursor, params); + + assertThat(commands, contains(scanResultBytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testSunion() { + when(commandObjects.sunion("key1", "key2")).thenReturn(setStringCommandObject); + + Response> response = pipeliningBase.sunion("key1", "key2"); + + assertThat(commands, contains(setStringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testSunionBinary() { + byte[][] keys = { "key1".getBytes(), "key2".getBytes() }; + + when(commandObjects.sunion(keys)).thenReturn(setBytesCommandObject); + + Response> response = pipeliningBase.sunion(keys); + + assertThat(commands, contains(setBytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testSunionstore() { + when(commandObjects.sunionstore("dstKey", "key1", "key2")).thenReturn(longCommandObject); + + Response response = pipeliningBase.sunionstore("dstKey", "key1", "key2"); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testSunionstoreBinary() { + byte[] dstkey = "destination".getBytes(); + byte[][] keys = { "key1".getBytes(), "key2".getBytes() }; + + when(commandObjects.sunionstore(dstkey, keys)).thenReturn(longCommandObject); + + Response response = pipeliningBase.sunionstore(dstkey, keys); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + +} diff --git a/src/test/java/redis/clients/jedis/mocked/pipeline/PipeliningBaseSortedSetCommandsTest.java b/src/test/java/redis/clients/jedis/mocked/pipeline/PipeliningBaseSortedSetCommandsTest.java new file mode 100644 index 00000000000..3e3958abb17 --- /dev/null +++ b/src/test/java/redis/clients/jedis/mocked/pipeline/PipeliningBaseSortedSetCommandsTest.java @@ -0,0 +1,1921 @@ +package redis.clients.jedis.mocked.pipeline; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.contains; +import static org.hamcrest.Matchers.is; +import static org.mockito.Mockito.when; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.junit.Test; +import redis.clients.jedis.Response; +import redis.clients.jedis.args.SortedSetOption; +import redis.clients.jedis.params.ScanParams; +import redis.clients.jedis.params.ZAddParams; +import redis.clients.jedis.params.ZIncrByParams; +import redis.clients.jedis.params.ZParams; +import redis.clients.jedis.params.ZRangeParams; +import redis.clients.jedis.resps.ScanResult; +import redis.clients.jedis.resps.Tuple; +import redis.clients.jedis.util.KeyValue; + +public class PipeliningBaseSortedSetCommandsTest extends PipeliningBaseMockedTestBase { + + @Test + public void testBzmpop() { + SortedSetOption option = SortedSetOption.MAX; + + when(commandObjects.bzmpop(1.0, option, "key1", "key2")).thenReturn(keyValueStringListTupleCommandObject); + + Response>> response = pipeliningBase.bzmpop(1.0, option, "key1", "key2"); + + assertThat(commands, contains(keyValueStringListTupleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testBzmpopBinary() { + double timeout = 1.0; + SortedSetOption option = SortedSetOption.MAX; + byte[][] keys = { "zset1".getBytes(), "zset2".getBytes() }; + + when(commandObjects.bzmpop(timeout, option, keys)).thenReturn(keyValueBytesListTupleCommandObject); + + Response>> response = pipeliningBase.bzmpop(timeout, option, keys); + + assertThat(commands, contains(keyValueBytesListTupleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testBzmpopWithCount() { + SortedSetOption option = SortedSetOption.MAX; + int count = 2; + + when(commandObjects.bzmpop(1.0, option, count, "key1", "key2")).thenReturn(keyValueStringListTupleCommandObject); + + Response>> response = pipeliningBase.bzmpop(1.0, option, count, "key1", "key2"); + + assertThat(commands, contains(keyValueStringListTupleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testBzmpopWithCountBinary() { + double timeout = 1.0; + SortedSetOption option = SortedSetOption.MAX; + int count = 2; + byte[][] keys = { "zset1".getBytes(), "zset2".getBytes() }; + + when(commandObjects.bzmpop(timeout, option, count, keys)).thenReturn(keyValueBytesListTupleCommandObject); + + Response>> response = pipeliningBase.bzmpop(timeout, option, count, keys); + + assertThat(commands, contains(keyValueBytesListTupleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testBzpopmax() { + when(commandObjects.bzpopmax(1.0, "key1", "key2")).thenReturn(keyValueStringTupleCommandObject); + + Response> response = pipeliningBase.bzpopmax(1.0, "key1", "key2"); + + assertThat(commands, contains(keyValueStringTupleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testBzpopmaxBinary() { + double timeout = 1.0; + byte[][] keys = { "zset1".getBytes(), "zset2".getBytes() }; + + when(commandObjects.bzpopmax(timeout, keys)).thenReturn(keyValueBytesTupleCommandObject); + + Response> response = pipeliningBase.bzpopmax(timeout, keys); + + assertThat(commands, contains(keyValueBytesTupleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testBzpopmin() { + when(commandObjects.bzpopmin(1.0, "key1", "key2")).thenReturn(keyValueStringTupleCommandObject); + + Response> response = pipeliningBase.bzpopmin(1.0, "key1", "key2"); + + assertThat(commands, contains(keyValueStringTupleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testBzpopminBinary() { + double timeout = 1.0; + byte[][] keys = { "zset1".getBytes(), "zset2".getBytes() }; + + when(commandObjects.bzpopmin(timeout, keys)).thenReturn(keyValueBytesTupleCommandObject); + + Response> response = pipeliningBase.bzpopmin(timeout, keys); + + assertThat(commands, contains(keyValueBytesTupleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZadd() { + when(commandObjects.zadd("key", 1.0, "member")).thenReturn(longCommandObject); + + Response response = pipeliningBase.zadd("key", 1.0, "member"); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZaddBinary() { + byte[] key = "zset".getBytes(); + double score = 1.0; + byte[] member = "member".getBytes(); + + when(commandObjects.zadd(key, score, member)).thenReturn(longCommandObject); + + Response response = pipeliningBase.zadd(key, score, member); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZaddWithParams() { + ZAddParams params = new ZAddParams(); + + when(commandObjects.zadd("key", 1.0, "member", params)).thenReturn(longCommandObject); + + Response response = pipeliningBase.zadd("key", 1.0, "member", params); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZaddWithParamsBinary() { + byte[] key = "zset".getBytes(); + double score = 1.0; + byte[] member = "member".getBytes(); + ZAddParams params = ZAddParams.zAddParams().nx(); + + when(commandObjects.zadd(key, score, member, params)).thenReturn(longCommandObject); + + Response response = pipeliningBase.zadd(key, score, member, params); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZaddMultiple() { + Map scoreMembers = new HashMap<>(); + scoreMembers.put("member1", 1.0); + scoreMembers.put("member2", 2.0); + + when(commandObjects.zadd("key", scoreMembers)).thenReturn(longCommandObject); + + Response response = pipeliningBase.zadd("key", scoreMembers); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZaddMultipleBinary() { + byte[] key = "zset".getBytes(); + + Map scoreMembers = new HashMap<>(); + scoreMembers.put("member1".getBytes(), 1.0); + scoreMembers.put("member2".getBytes(), 2.0); + + when(commandObjects.zadd(key, scoreMembers)).thenReturn(longCommandObject); + + Response response = pipeliningBase.zadd(key, scoreMembers); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZaddMultipleWithParams() { + Map scoreMembers = new HashMap<>(); + scoreMembers.put("member1", 1.0); + scoreMembers.put("member2", 2.0); + + ZAddParams params = new ZAddParams(); + + when(commandObjects.zadd("key", scoreMembers, params)).thenReturn(longCommandObject); + + Response response = pipeliningBase.zadd("key", scoreMembers, params); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZaddMultipleWithParamsBinary() { + byte[] key = "zset".getBytes(); + + Map scoreMembers = new HashMap<>(); + scoreMembers.put("member1".getBytes(), 1.0); + scoreMembers.put("member2".getBytes(), 2.0); + + ZAddParams params = ZAddParams.zAddParams().nx(); + + when(commandObjects.zadd(key, scoreMembers, params)).thenReturn(longCommandObject); + + Response response = pipeliningBase.zadd(key, scoreMembers, params); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZaddIncr() { + ZAddParams params = new ZAddParams(); + + when(commandObjects.zaddIncr("key", 1.0, "member", params)).thenReturn(doubleCommandObject); + + Response response = pipeliningBase.zaddIncr("key", 1.0, "member", params); + + assertThat(commands, contains(doubleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZaddIncrBinary() { + byte[] key = "zset".getBytes(); + double score = 1.0; + byte[] member = "member".getBytes(); + ZAddParams params = ZAddParams.zAddParams().xx(); + + when(commandObjects.zaddIncr(key, score, member, params)).thenReturn(doubleCommandObject); + + Response response = pipeliningBase.zaddIncr(key, score, member, params); + + assertThat(commands, contains(doubleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZcard() { + when(commandObjects.zcard("key")).thenReturn(longCommandObject); + + Response response = pipeliningBase.zcard("key"); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZcardBinary() { + byte[] key = "zset".getBytes(); + + when(commandObjects.zcard(key)).thenReturn(longCommandObject); + + Response response = pipeliningBase.zcard(key); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZcount() { + when(commandObjects.zcount("key", "1", "2")).thenReturn(longCommandObject); + + Response response = pipeliningBase.zcount("key", "1", "2"); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZcountBinary() { + byte[] key = "zset".getBytes(); + byte[] min = "min".getBytes(); + byte[] max = "max".getBytes(); + + when(commandObjects.zcount(key, min, max)).thenReturn(longCommandObject); + + Response response = pipeliningBase.zcount(key, min, max); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZcountDouble() { + when(commandObjects.zcount("key", 1.0, 2.0)).thenReturn(longCommandObject); + + Response response = pipeliningBase.zcount("key", 1.0, 2.0); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZcountDoubleBinary() { + byte[] key = "zset".getBytes(); + double min = 1.0; + double max = 2.0; + + when(commandObjects.zcount(key, min, max)).thenReturn(longCommandObject); + + Response response = pipeliningBase.zcount(key, min, max); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZdiff() { + when(commandObjects.zdiff("key1", "key2")).thenReturn(listStringCommandObject); + + Response> response = pipeliningBase.zdiff("key1", "key2"); + + assertThat(commands, contains(listStringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZdiffBinary() { + byte[][] keys = { "zset1".getBytes(), "zset2".getBytes() }; + + when(commandObjects.zdiff(keys)).thenReturn(listBytesCommandObject); + + Response> response = pipeliningBase.zdiff(keys); + + assertThat(commands, contains(listBytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZdiffWithScores() { + when(commandObjects.zdiffWithScores("key1", "key2")).thenReturn(listTupleCommandObject); + + Response> response = pipeliningBase.zdiffWithScores("key1", "key2"); + + assertThat(commands, contains(listTupleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZdiffWithScoresBinary() { + byte[][] keys = { "zset1".getBytes(), "zset2".getBytes() }; + + when(commandObjects.zdiffWithScores(keys)).thenReturn(listTupleCommandObject); + + Response> response = pipeliningBase.zdiffWithScores(keys); + + assertThat(commands, contains(listTupleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZdiffStore() { + when(commandObjects.zdiffStore("dstKey", "key1", "key2")).thenReturn(longCommandObject); + + Response response = pipeliningBase.zdiffStore("dstKey", "key1", "key2"); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZdiffStoreBinary() { + byte[] dstkey = "destZset".getBytes(); + byte[][] keys = { "zset1".getBytes(), "zset2".getBytes() }; + + when(commandObjects.zdiffStore(dstkey, keys)).thenReturn(longCommandObject); + + Response response = pipeliningBase.zdiffStore(dstkey, keys); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZdiffstore() { + when(commandObjects.zdiffstore("dstKey", "key1", "key2")).thenReturn(longCommandObject); + + Response response = pipeliningBase.zdiffstore("dstKey", "key1", "key2"); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZdiffstoreBinary() { + byte[] dstkey = "destZset".getBytes(); + byte[][] keys = { "zset1".getBytes(), "zset2".getBytes() }; + + when(commandObjects.zdiffstore(dstkey, keys)).thenReturn(longCommandObject); + + Response response = pipeliningBase.zdiffstore(dstkey, keys); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZincrby() { + when(commandObjects.zincrby("key", 1.0, "member")).thenReturn(doubleCommandObject); + + Response response = pipeliningBase.zincrby("key", 1.0, "member"); + + assertThat(commands, contains(doubleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZincrbyBinary() { + byte[] key = "zset".getBytes(); + double increment = 2.0; + byte[] member = "member".getBytes(); + + when(commandObjects.zincrby(key, increment, member)).thenReturn(doubleCommandObject); + + Response response = pipeliningBase.zincrby(key, increment, member); + + assertThat(commands, contains(doubleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZincrbyWithParams() { + ZIncrByParams params = new ZIncrByParams(); + + when(commandObjects.zincrby("key", 1.0, "member", params)).thenReturn(doubleCommandObject); + + Response response = pipeliningBase.zincrby("key", 1.0, "member", params); + + assertThat(commands, contains(doubleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZincrbyWithParamsBinary() { + byte[] key = "zset".getBytes(); + double increment = 2.0; + byte[] member = "member".getBytes(); + ZIncrByParams params = ZIncrByParams.zIncrByParams().xx(); + + when(commandObjects.zincrby(key, increment, member, params)).thenReturn(doubleCommandObject); + + Response response = pipeliningBase.zincrby(key, increment, member, params); + + assertThat(commands, contains(doubleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZinter() { + ZParams params = new ZParams(); + + when(commandObjects.zinter(params, "key1", "key2")).thenReturn(listStringCommandObject); + + Response> response = pipeliningBase.zinter(params, "key1", "key2"); + + assertThat(commands, contains(listStringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZinterBinary() { + ZParams params = new ZParams(); + byte[][] keys = { "zset1".getBytes(), "zset2".getBytes() }; + + when(commandObjects.zinter(params, keys)).thenReturn(listBytesCommandObject); + + Response> response = pipeliningBase.zinter(params, keys); + + assertThat(commands, contains(listBytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZinterWithScores() { + ZParams params = new ZParams(); + + when(commandObjects.zinterWithScores(params, "key1", "key2")).thenReturn(listTupleCommandObject); + + Response> response = pipeliningBase.zinterWithScores(params, "key1", "key2"); + + assertThat(commands, contains(listTupleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZinterWithScoresBinary() { + ZParams params = new ZParams(); + byte[][] keys = { "zset1".getBytes(), "zset2".getBytes() }; + + when(commandObjects.zinterWithScores(params, keys)).thenReturn(listTupleCommandObject); + + Response> response = pipeliningBase.zinterWithScores(params, keys); + + assertThat(commands, contains(listTupleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZintercard() { + when(commandObjects.zintercard("key1", "key2")).thenReturn(longCommandObject); + + Response response = pipeliningBase.zintercard("key1", "key2"); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZintercardBinary() { + byte[][] keys = { "zset1".getBytes(), "zset2".getBytes() }; + + when(commandObjects.zintercard(keys)).thenReturn(longCommandObject); + + Response response = pipeliningBase.zintercard(keys); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZintercardWithLimit() { + long limit = 2; + + when(commandObjects.zintercard(limit, "key1", "key2")).thenReturn(longCommandObject); + + Response response = pipeliningBase.zintercard(limit, "key1", "key2"); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZintercardWithLimitBinary() { + long limit = 2; + byte[][] keys = { "zset1".getBytes(), "zset2".getBytes() }; + + when(commandObjects.zintercard(limit, keys)).thenReturn(longCommandObject); + + Response response = pipeliningBase.zintercard(limit, keys); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZinterstore() { + when(commandObjects.zinterstore("dstKey", "set1", "set2")).thenReturn(longCommandObject); + + Response response = pipeliningBase.zinterstore("dstKey", "set1", "set2"); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZinterstoreBinary() { + byte[] dstkey = "destZset".getBytes(); + byte[][] sets = { "zset1".getBytes(), "zset2".getBytes() }; + + when(commandObjects.zinterstore(dstkey, sets)).thenReturn(longCommandObject); + + Response response = pipeliningBase.zinterstore(dstkey, sets); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZinterstoreWithParams() { + ZParams params = new ZParams(); + + when(commandObjects.zinterstore("dstKey", params, "set1", "set2")).thenReturn(longCommandObject); + + Response response = pipeliningBase.zinterstore("dstKey", params, "set1", "set2"); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZinterstoreWithParamsBinary() { + byte[] dstkey = "destZset".getBytes(); + ZParams params = new ZParams(); + byte[][] sets = { "zset1".getBytes(), "zset2".getBytes() }; + + when(commandObjects.zinterstore(dstkey, params, sets)).thenReturn(longCommandObject); + + Response response = pipeliningBase.zinterstore(dstkey, params, sets); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZlexcount() { + when(commandObjects.zlexcount("key", "[a", "[z")).thenReturn(longCommandObject); + + Response response = pipeliningBase.zlexcount("key", "[a", "[z"); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZlexcountBinary() { + byte[] key = "zset".getBytes(); + byte[] min = "[a".getBytes(); + byte[] max = "[z".getBytes(); + + when(commandObjects.zlexcount(key, min, max)).thenReturn(longCommandObject); + + Response response = pipeliningBase.zlexcount(key, min, max); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZmpop() { + SortedSetOption option = SortedSetOption.MAX; + + when(commandObjects.zmpop(option, "key1", "key2")).thenReturn(keyValueStringListTupleCommandObject); + + Response>> response = pipeliningBase.zmpop(option, "key1", "key2"); + + assertThat(commands, contains(keyValueStringListTupleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZmpopBinary() { + SortedSetOption option = SortedSetOption.MAX; + byte[][] keys = { "zset1".getBytes(), "zset2".getBytes() }; + + when(commandObjects.zmpop(option, keys)).thenReturn(keyValueBytesListTupleCommandObject); + + Response>> response = pipeliningBase.zmpop(option, keys); + + assertThat(commands, contains(keyValueBytesListTupleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZmpopWithCount() { + SortedSetOption option = SortedSetOption.MAX; + int count = 2; + + when(commandObjects.zmpop(option, count, "key1", "key2")).thenReturn(keyValueStringListTupleCommandObject); + + Response>> response = pipeliningBase.zmpop(option, count, "key1", "key2"); + + assertThat(commands, contains(keyValueStringListTupleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZmpopWithCountBinary() { + SortedSetOption option = SortedSetOption.MAX; + int count = 2; + byte[][] keys = { "zset1".getBytes(), "zset2".getBytes() }; + + when(commandObjects.zmpop(option, count, keys)).thenReturn(keyValueBytesListTupleCommandObject); + + Response>> response = pipeliningBase.zmpop(option, count, keys); + + assertThat(commands, contains(keyValueBytesListTupleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZmscore() { + when(commandObjects.zmscore("key", "member1", "member2")).thenReturn(listDoubleCommandObject); + + Response> response = pipeliningBase.zmscore("key", "member1", "member2"); + + assertThat(commands, contains(listDoubleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZmscoreBinary() { + byte[] key = "zset".getBytes(); + byte[][] members = { "member1".getBytes(), "member2".getBytes() }; + + when(commandObjects.zmscore(key, members)).thenReturn(listDoubleCommandObject); + + Response> response = pipeliningBase.zmscore(key, members); + + assertThat(commands, contains(listDoubleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZpopmax() { + when(commandObjects.zpopmax("key")).thenReturn(tupleCommandObject); + + Response response = pipeliningBase.zpopmax("key"); + + assertThat(commands, contains(tupleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZpopmaxBinary() { + byte[] key = "zset".getBytes(); + + when(commandObjects.zpopmax(key)).thenReturn(tupleCommandObject); + + Response response = pipeliningBase.zpopmax(key); + + assertThat(commands, contains(tupleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZpopmaxCount() { + int count = 2; + + when(commandObjects.zpopmax("key", count)).thenReturn(listTupleCommandObject); + + Response> response = pipeliningBase.zpopmax("key", count); + + assertThat(commands, contains(listTupleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZpopmaxCountBinary() { + byte[] key = "zset".getBytes(); + int count = 2; + + when(commandObjects.zpopmax(key, count)).thenReturn(listTupleCommandObject); + + Response> response = pipeliningBase.zpopmax(key, count); + + assertThat(commands, contains(listTupleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZpopmin() { + when(commandObjects.zpopmin("key")).thenReturn(tupleCommandObject); + + Response response = pipeliningBase.zpopmin("key"); + + assertThat(commands, contains(tupleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZpopminBinary() { + byte[] key = "zset".getBytes(); + + when(commandObjects.zpopmin(key)).thenReturn(tupleCommandObject); + + Response response = pipeliningBase.zpopmin(key); + + assertThat(commands, contains(tupleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZpopminCount() { + int count = 2; + + when(commandObjects.zpopmin("key", count)).thenReturn(listTupleCommandObject); + + Response> response = pipeliningBase.zpopmin("key", count); + + assertThat(commands, contains(listTupleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZpopminCountBinary() { + byte[] key = "zset".getBytes(); + int count = 2; + + when(commandObjects.zpopmin(key, count)).thenReturn(listTupleCommandObject); + + Response> response = pipeliningBase.zpopmin(key, count); + + assertThat(commands, contains(listTupleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZrandmember() { + when(commandObjects.zrandmember("key")).thenReturn(stringCommandObject); + + Response response = pipeliningBase.zrandmember("key"); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZrandmemberBinary() { + byte[] key = "zset".getBytes(); + + when(commandObjects.zrandmember(key)).thenReturn(bytesCommandObject); + + Response response = pipeliningBase.zrandmember(key); + + assertThat(commands, contains(bytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZrandmemberCount() { + long count = 2; + + when(commandObjects.zrandmember("key", count)).thenReturn(listStringCommandObject); + + Response> response = pipeliningBase.zrandmember("key", count); + + assertThat(commands, contains(listStringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZrandmemberCountBinary() { + byte[] key = "zset".getBytes(); + long count = 2; + + when(commandObjects.zrandmember(key, count)).thenReturn(listBytesCommandObject); + + Response> response = pipeliningBase.zrandmember(key, count); + + assertThat(commands, contains(listBytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZrandmemberWithScores() { + long count = 2; + + when(commandObjects.zrandmemberWithScores("key", count)).thenReturn(listTupleCommandObject); + + Response> response = pipeliningBase.zrandmemberWithScores("key", count); + + assertThat(commands, contains(listTupleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZrandmemberWithScoresBinary() { + byte[] key = "zset".getBytes(); + long count = 2; + + when(commandObjects.zrandmemberWithScores(key, count)).thenReturn(listTupleCommandObject); + + Response> response = pipeliningBase.zrandmemberWithScores(key, count); + + assertThat(commands, contains(listTupleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZrange() { + when(commandObjects.zrange("key", 0, -1)).thenReturn(listStringCommandObject); + + Response> response = pipeliningBase.zrange("key", 0, -1); + + assertThat(commands, contains(listStringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZrangeBinary() { + byte[] key = "zset".getBytes(); + long start = 0; + long stop = 1; + + when(commandObjects.zrange(key, start, stop)).thenReturn(listBytesCommandObject); + + Response> response = pipeliningBase.zrange(key, start, stop); + + assertThat(commands, contains(listBytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZrangeWithScores() { + when(commandObjects.zrangeWithScores("key", 0, -1)).thenReturn(listTupleCommandObject); + + Response> response = pipeliningBase.zrangeWithScores("key", 0, -1); + + assertThat(commands, contains(listTupleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZrangeWithScoresBinary() { + byte[] key = "zset".getBytes(); + long start = 0; + long stop = 1; + + when(commandObjects.zrangeWithScores(key, start, stop)).thenReturn(listTupleCommandObject); + + Response> response = pipeliningBase.zrangeWithScores(key, start, stop); + + assertThat(commands, contains(listTupleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZrangeWithZRangeParams() { + ZRangeParams zRangeParams = new ZRangeParams(1, 2); + + when(commandObjects.zrange("key", zRangeParams)).thenReturn(listStringCommandObject); + + Response> response = pipeliningBase.zrange("key", zRangeParams); + + assertThat(commands, contains(listStringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZrangeWithZRangeParamsBinary() { + byte[] key = "zset".getBytes(); + ZRangeParams zRangeParams = ZRangeParams.zrangeParams(0, 1); + + when(commandObjects.zrange(key, zRangeParams)).thenReturn(listBytesCommandObject); + + Response> response = pipeliningBase.zrange(key, zRangeParams); + + assertThat(commands, contains(listBytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZrangeWithScoresWithZRangeParams() { + ZRangeParams zRangeParams = new ZRangeParams(1, 2); + + when(commandObjects.zrangeWithScores("key", zRangeParams)).thenReturn(listTupleCommandObject); + + Response> response = pipeliningBase.zrangeWithScores("key", zRangeParams); + + assertThat(commands, contains(listTupleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZrangeWithScoresWithZRangeParamsBinary() { + byte[] key = "zset".getBytes(); + ZRangeParams zRangeParams = ZRangeParams.zrangeParams(0, 1); + + when(commandObjects.zrangeWithScores(key, zRangeParams)).thenReturn(listTupleCommandObject); + + Response> response = pipeliningBase.zrangeWithScores(key, zRangeParams); + + assertThat(commands, contains(listTupleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZrangeByLex() { + when(commandObjects.zrangeByLex("key", "[a", "[z")).thenReturn(listStringCommandObject); + + Response> response = pipeliningBase.zrangeByLex("key", "[a", "[z"); + + assertThat(commands, contains(listStringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZrangeByLexBinary() { + byte[] key = "zset".getBytes(); + byte[] min = "[a".getBytes(); + byte[] max = "[z".getBytes(); + + when(commandObjects.zrangeByLex(key, min, max)).thenReturn(listBytesCommandObject); + + Response> response = pipeliningBase.zrangeByLex(key, min, max); + + assertThat(commands, contains(listBytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZrangeByLexWithOffsetCount() { + when(commandObjects.zrangeByLex("key", "[a", "[z", 0, 10)).thenReturn(listStringCommandObject); + + Response> response = pipeliningBase.zrangeByLex("key", "[a", "[z", 0, 10); + + assertThat(commands, contains(listStringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZrangeByLexWithOffsetCountBinary() { + byte[] key = "zset".getBytes(); + byte[] min = "[a".getBytes(); + byte[] max = "[z".getBytes(); + int offset = 0; + int count = 10; + + when(commandObjects.zrangeByLex(key, min, max, offset, count)).thenReturn(listBytesCommandObject); + + Response> response = pipeliningBase.zrangeByLex(key, min, max, offset, count); + + assertThat(commands, contains(listBytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZrangeByScore() { + when(commandObjects.zrangeByScore("key", "1", "2")).thenReturn(listStringCommandObject); + + Response> response = pipeliningBase.zrangeByScore("key", "1", "2"); + + assertThat(commands, contains(listStringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZrangeByScoreBinary() { + byte[] key = "zset".getBytes(); + byte[] min = "1".getBytes(); + byte[] max = "2".getBytes(); + + when(commandObjects.zrangeByScore(key, min, max)).thenReturn(listBytesCommandObject); + + Response> response = pipeliningBase.zrangeByScore(key, min, max); + + assertThat(commands, contains(listBytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZrangeByScoreDouble() { + when(commandObjects.zrangeByScore("key", 1.0, 2.0)).thenReturn(listStringCommandObject); + + Response> response = pipeliningBase.zrangeByScore("key", 1.0, 2.0); + + assertThat(commands, contains(listStringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZrangeByScoreDoubleBinary() { + byte[] key = "zset".getBytes(); + double min = 1.0; + double max = 2.0; + + when(commandObjects.zrangeByScore(key, min, max)).thenReturn(listBytesCommandObject); + + Response> response = pipeliningBase.zrangeByScore(key, min, max); + + assertThat(commands, contains(listBytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZrangeByScoreWithOffsetCount() { + when(commandObjects.zrangeByScore("key", "1", "2", 0, 1)).thenReturn(listStringCommandObject); + + Response> response = pipeliningBase.zrangeByScore("key", "1", "2", 0, 1); + + assertThat(commands, contains(listStringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZrangeByScoreWithOffsetCountBinary() { + byte[] key = "zset".getBytes(); + byte[] min = "1".getBytes(); + byte[] max = "2".getBytes(); + int offset = 0; + int count = 2; + + when(commandObjects.zrangeByScore(key, min, max, offset, count)).thenReturn(listBytesCommandObject); + + Response> response = pipeliningBase.zrangeByScore(key, min, max, offset, count); + + assertThat(commands, contains(listBytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZrangeByScoreDoubleWithOffsetCount() { + when(commandObjects.zrangeByScore("key", 1.0, 2.0, 0, 1)).thenReturn(listStringCommandObject); + + Response> response = pipeliningBase.zrangeByScore("key", 1.0, 2.0, 0, 1); + + assertThat(commands, contains(listStringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZrangeByScoreDoubleWithOffsetCountBinary() { + byte[] key = "zset".getBytes(); + double min = 1.0; + double max = 2.0; + int offset = 0; + int count = 2; + + when(commandObjects.zrangeByScore(key, min, max, offset, count)).thenReturn(listBytesCommandObject); + + Response> response = pipeliningBase.zrangeByScore(key, min, max, offset, count); + + assertThat(commands, contains(listBytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZrangeByScoreWithScores() { + when(commandObjects.zrangeByScoreWithScores("key", "1", "2")).thenReturn(listTupleCommandObject); + + Response> response = pipeliningBase.zrangeByScoreWithScores("key", "1", "2"); + + assertThat(commands, contains(listTupleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZrangeByScoreWithScoresBinary() { + byte[] key = "zset".getBytes(); + byte[] min = "1".getBytes(); + byte[] max = "2".getBytes(); + + when(commandObjects.zrangeByScoreWithScores(key, min, max)).thenReturn(listTupleCommandObject); + + Response> response = pipeliningBase.zrangeByScoreWithScores(key, min, max); + + assertThat(commands, contains(listTupleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZrangeByScoreWithScoresDouble() { + when(commandObjects.zrangeByScoreWithScores("key", 1.0, 2.0)).thenReturn(listTupleCommandObject); + + Response> response = pipeliningBase.zrangeByScoreWithScores("key", 1.0, 2.0); + + assertThat(commands, contains(listTupleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZrangeByScoreWithScoresDoubleBinary() { + byte[] key = "zset".getBytes(); + double min = 1.0; + double max = 2.0; + + when(commandObjects.zrangeByScoreWithScores(key, min, max)).thenReturn(listTupleCommandObject); + + Response> response = pipeliningBase.zrangeByScoreWithScores(key, min, max); + + assertThat(commands, contains(listTupleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZrangeByScoreWithScoresWithOffsetCount() { + when(commandObjects.zrangeByScoreWithScores("key", "1", "2", 0, 1)).thenReturn(listTupleCommandObject); + + Response> response = pipeliningBase.zrangeByScoreWithScores("key", "1", "2", 0, 1); + + assertThat(commands, contains(listTupleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZrangeByScoreWithScoresWithOffsetCountBinary() { + byte[] key = "zset".getBytes(); + byte[] min = "1".getBytes(); + byte[] max = "2".getBytes(); + int offset = 0; + int count = 2; + + when(commandObjects.zrangeByScoreWithScores(key, min, max, offset, count)).thenReturn(listTupleCommandObject); + + Response> response = pipeliningBase.zrangeByScoreWithScores(key, min, max, offset, count); + + assertThat(commands, contains(listTupleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZrangeByScoreWithScoresDoubleWithOffsetCount() { + when(commandObjects.zrangeByScoreWithScores("key", 1.0, 2.0, 0, 1)).thenReturn(listTupleCommandObject); + + Response> response = pipeliningBase.zrangeByScoreWithScores("key", 1.0, 2.0, 0, 1); + + assertThat(commands, contains(listTupleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZrangeByScoreWithScoresDoubleWithOffsetCountBinary() { + byte[] key = "zset".getBytes(); + double min = 1.0; + double max = 2.0; + int offset = 0; + int count = 2; + + when(commandObjects.zrangeByScoreWithScores(key, min, max, offset, count)).thenReturn(listTupleCommandObject); + + Response> response = pipeliningBase.zrangeByScoreWithScores(key, min, max, offset, count); + + assertThat(commands, contains(listTupleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZrangestore() { + ZRangeParams zRangeParams = new ZRangeParams(1, 2); + + when(commandObjects.zrangestore("dest", "src", zRangeParams)).thenReturn(longCommandObject); + + Response response = pipeliningBase.zrangestore("dest", "src", zRangeParams); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZrangestoreBinary() { + byte[] dest = "destZset".getBytes(); + byte[] src = "srcZset".getBytes(); + ZRangeParams zRangeParams = ZRangeParams.zrangeParams(0, 1); + + when(commandObjects.zrangestore(dest, src, zRangeParams)).thenReturn(longCommandObject); + + Response response = pipeliningBase.zrangestore(dest, src, zRangeParams); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZrank() { + when(commandObjects.zrank("key", "member")).thenReturn(longCommandObject); + + Response response = pipeliningBase.zrank("key", "member"); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZrankBinary() { + byte[] key = "zset".getBytes(); + byte[] member = "member".getBytes(); + + when(commandObjects.zrank(key, member)).thenReturn(longCommandObject); + + Response response = pipeliningBase.zrank(key, member); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZrankWithScore() { + when(commandObjects.zrankWithScore("key", "member")).thenReturn(keyValueLongDoubleCommandObject); + + Response> response = pipeliningBase.zrankWithScore("key", "member"); + + assertThat(commands, contains(keyValueLongDoubleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZrankWithScoreBinary() { + byte[] key = "zset".getBytes(); + byte[] member = "member".getBytes(); + + when(commandObjects.zrankWithScore(key, member)).thenReturn(keyValueLongDoubleCommandObject); + + Response> response = pipeliningBase.zrankWithScore(key, member); + + assertThat(commands, contains(keyValueLongDoubleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZrem() { + when(commandObjects.zrem("key", "member1", "member2")).thenReturn(longCommandObject); + + Response response = pipeliningBase.zrem("key", "member1", "member2"); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZremBinary() { + byte[] key = "zset".getBytes(); + byte[][] members = { "member1".getBytes(), "member2".getBytes() }; + + when(commandObjects.zrem(key, members)).thenReturn(longCommandObject); + + Response response = pipeliningBase.zrem(key, members); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZremrangeByLex() { + when(commandObjects.zremrangeByLex("key", "[a", "[z")).thenReturn(longCommandObject); + + Response response = pipeliningBase.zremrangeByLex("key", "[a", "[z"); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZremrangeByLexBinary() { + byte[] key = "zset".getBytes(); + byte[] min = "[a".getBytes(); + byte[] max = "[z".getBytes(); + + when(commandObjects.zremrangeByLex(key, min, max)).thenReturn(longCommandObject); + + Response response = pipeliningBase.zremrangeByLex(key, min, max); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZremrangeByRank() { + when(commandObjects.zremrangeByRank("key", 0, 1)).thenReturn(longCommandObject); + + Response response = pipeliningBase.zremrangeByRank("key", 0, 1); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZremrangeByRankBinary() { + byte[] key = "zset".getBytes(); + long start = 0; + long stop = 1; + + when(commandObjects.zremrangeByRank(key, start, stop)).thenReturn(longCommandObject); + + Response response = pipeliningBase.zremrangeByRank(key, start, stop); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZremrangeByScore() { + when(commandObjects.zremrangeByScore("key", "1", "2")).thenReturn(longCommandObject); + + Response response = pipeliningBase.zremrangeByScore("key", "1", "2"); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZremrangeByScoreBinary() { + byte[] key = "zset".getBytes(); + byte[] min = "1".getBytes(); + byte[] max = "2".getBytes(); + + when(commandObjects.zremrangeByScore(key, min, max)).thenReturn(longCommandObject); + + Response response = pipeliningBase.zremrangeByScore(key, min, max); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZremrangeByScoreDouble() { + when(commandObjects.zremrangeByScore("key", 1.0, 2.0)).thenReturn(longCommandObject); + + Response response = pipeliningBase.zremrangeByScore("key", 1.0, 2.0); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZremrangeByScoreDoubleBinary() { + byte[] key = "zset".getBytes(); + double min = 1.0; + double max = 2.0; + + when(commandObjects.zremrangeByScore(key, min, max)).thenReturn(longCommandObject); + + Response response = pipeliningBase.zremrangeByScore(key, min, max); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZrevrange() { + when(commandObjects.zrevrange("key", 0, -1)).thenReturn(listStringCommandObject); + + Response> response = pipeliningBase.zrevrange("key", 0, -1); + + assertThat(commands, contains(listStringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZrevrangeBinary() { + byte[] key = "zset".getBytes(); + long start = 0; + long stop = 1; + + when(commandObjects.zrevrange(key, start, stop)).thenReturn(listBytesCommandObject); + + Response> response = pipeliningBase.zrevrange(key, start, stop); + + assertThat(commands, contains(listBytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZrevrangeWithScores() { + when(commandObjects.zrevrangeWithScores("key", 0, -1)).thenReturn(listTupleCommandObject); + + Response> response = pipeliningBase.zrevrangeWithScores("key", 0, -1); + + assertThat(commands, contains(listTupleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZrevrangeWithScoresBinary() { + byte[] key = "zset".getBytes(); + long start = 0; + long stop = 1; + + when(commandObjects.zrevrangeWithScores(key, start, stop)).thenReturn(listTupleCommandObject); + + Response> response = pipeliningBase.zrevrangeWithScores(key, start, stop); + + assertThat(commands, contains(listTupleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZrevrangeByLex() { + when(commandObjects.zrevrangeByLex("key", "[z", "[a")).thenReturn(listStringCommandObject); + + Response> response = pipeliningBase.zrevrangeByLex("key", "[z", "[a"); + + assertThat(commands, contains(listStringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZrevrangeByLexBinary() { + byte[] key = "zset".getBytes(); + byte[] max = "[z".getBytes(); + byte[] min = "[a".getBytes(); + + when(commandObjects.zrevrangeByLex(key, max, min)).thenReturn(listBytesCommandObject); + + Response> response = pipeliningBase.zrevrangeByLex(key, max, min); + + assertThat(commands, contains(listBytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZrevrangeByLexWithLimit() { + when(commandObjects.zrevrangeByLex("key", "[z", "[a", 0, 10)).thenReturn(listStringCommandObject); + + Response> response = pipeliningBase.zrevrangeByLex("key", "[z", "[a", 0, 10); + + assertThat(commands, contains(listStringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZrevrangeByLexWithLimitBinary() { + byte[] key = "zset".getBytes(); + byte[] max = "[z".getBytes(); + byte[] min = "[a".getBytes(); + int offset = 0; + int count = 10; + + when(commandObjects.zrevrangeByLex(key, max, min, offset, count)).thenReturn(listBytesCommandObject); + + Response> response = pipeliningBase.zrevrangeByLex(key, max, min, offset, count); + + assertThat(commands, contains(listBytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZrevrangeByScore() { + when(commandObjects.zrevrangeByScore("key", "2", "1")).thenReturn(listStringCommandObject); + + Response> response = pipeliningBase.zrevrangeByScore("key", "2", "1"); + + assertThat(commands, contains(listStringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZrevrangeByScoreBinary() { + byte[] key = "zset".getBytes(); + byte[] max = "2".getBytes(); + byte[] min = "1".getBytes(); + + when(commandObjects.zrevrangeByScore(key, max, min)).thenReturn(listBytesCommandObject); + + Response> response = pipeliningBase.zrevrangeByScore(key, max, min); + + assertThat(commands, contains(listBytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZrevrangeByScoreDouble() { + when(commandObjects.zrevrangeByScore("key", 2.0, 1.0)).thenReturn(listStringCommandObject); + + Response> response = pipeliningBase.zrevrangeByScore("key", 2.0, 1.0); + + assertThat(commands, contains(listStringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZrevrangeByScoreDoubleBinary() { + byte[] key = "zset".getBytes(); + double max = 2.0; + double min = 1.0; + + when(commandObjects.zrevrangeByScore(key, max, min)).thenReturn(listBytesCommandObject); + + Response> response = pipeliningBase.zrevrangeByScore(key, max, min); + + assertThat(commands, contains(listBytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZrevrangeByScoreWithLimit() { + when(commandObjects.zrevrangeByScore("key", "2", "1", 0, 1)).thenReturn(listStringCommandObject); + + Response> response = pipeliningBase.zrevrangeByScore("key", "2", "1", 0, 1); + + assertThat(commands, contains(listStringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZrevrangeByScoreWithLimitBinary() { + byte[] key = "zset".getBytes(); + byte[] max = "2".getBytes(); + byte[] min = "1".getBytes(); + int offset = 0; + int count = 2; + + when(commandObjects.zrevrangeByScore(key, max, min, offset, count)).thenReturn(listBytesCommandObject); + + Response> response = pipeliningBase.zrevrangeByScore(key, max, min, offset, count); + + assertThat(commands, contains(listBytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZrevrangeByScoreDoubleWithLimit() { + when(commandObjects.zrevrangeByScore("key", 2.0, 1.0, 0, 1)).thenReturn(listStringCommandObject); + + Response> response = pipeliningBase.zrevrangeByScore("key", 2.0, 1.0, 0, 1); + + assertThat(commands, contains(listStringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZrevrangeByScoreDoubleWithLimitBinary() { + byte[] key = "zset".getBytes(); + double max = 2.0; + double min = 1.0; + int offset = 0; + int count = 2; + + when(commandObjects.zrevrangeByScore(key, max, min, offset, count)).thenReturn(listBytesCommandObject); + + Response> response = pipeliningBase.zrevrangeByScore(key, max, min, offset, count); + + assertThat(commands, contains(listBytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZrevrangeByScoreWithScores() { + when(commandObjects.zrevrangeByScoreWithScores("key", "2", "1")).thenReturn(listTupleCommandObject); + + Response> response = pipeliningBase.zrevrangeByScoreWithScores("key", "2", "1"); + + assertThat(commands, contains(listTupleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZrevrangeByScoreWithScoresBinary() { + byte[] key = "zset".getBytes(); + byte[] max = "2".getBytes(); + byte[] min = "1".getBytes(); + + when(commandObjects.zrevrangeByScoreWithScores(key, max, min)).thenReturn(listTupleCommandObject); + + Response> response = pipeliningBase.zrevrangeByScoreWithScores(key, max, min); + + assertThat(commands, contains(listTupleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZrevrangeByScoreWithScoresDouble() { + when(commandObjects.zrevrangeByScoreWithScores("key", 2.0, 1.0)).thenReturn(listTupleCommandObject); + + Response> response = pipeliningBase.zrevrangeByScoreWithScores("key", 2.0, 1.0); + + assertThat(commands, contains(listTupleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZrevrangeByScoreWithScoresDoubleBinary() { + byte[] key = "zset".getBytes(); + double max = 2.0; + double min = 1.0; + + when(commandObjects.zrevrangeByScoreWithScores(key, max, min)).thenReturn(listTupleCommandObject); + + Response> response = pipeliningBase.zrevrangeByScoreWithScores(key, max, min); + + assertThat(commands, contains(listTupleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZrevrangeByScoreWithScoresWithLimit() { + when(commandObjects.zrevrangeByScoreWithScores("key", "2", "1", 0, 1)).thenReturn(listTupleCommandObject); + + Response> response = pipeliningBase.zrevrangeByScoreWithScores("key", "2", "1", 0, 1); + + assertThat(commands, contains(listTupleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZrevrangeByScoreWithScoresWithLimitBinary() { + byte[] key = "zset".getBytes(); + byte[] max = "2".getBytes(); + byte[] min = "1".getBytes(); + int offset = 0; + int count = 2; + + when(commandObjects.zrevrangeByScoreWithScores(key, max, min, offset, count)).thenReturn(listTupleCommandObject); + + Response> response = pipeliningBase.zrevrangeByScoreWithScores(key, max, min, offset, count); + + assertThat(commands, contains(listTupleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZrevrangeByScoreWithScoresDoubleWithLimit() { + when(commandObjects.zrevrangeByScoreWithScores("key", 2.0, 1.0, 0, 1)).thenReturn(listTupleCommandObject); + + Response> response = pipeliningBase.zrevrangeByScoreWithScores("key", 2.0, 1.0, 0, 1); + + assertThat(commands, contains(listTupleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZrevrangeByScoreWithScoresDoubleWithLimitBinary() { + byte[] key = "zset".getBytes(); + double max = 2.0; + double min = 1.0; + int offset = 0; + int count = 2; + + when(commandObjects.zrevrangeByScoreWithScores(key, max, min, offset, count)).thenReturn(listTupleCommandObject); + + Response> response = pipeliningBase.zrevrangeByScoreWithScores(key, max, min, offset, count); + + assertThat(commands, contains(listTupleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZrevrank() { + when(commandObjects.zrevrank("key", "member")).thenReturn(longCommandObject); + + Response response = pipeliningBase.zrevrank("key", "member"); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZrevrankBinary() { + byte[] key = "zset".getBytes(); + byte[] member = "member".getBytes(); + + when(commandObjects.zrevrank(key, member)).thenReturn(longCommandObject); + + Response response = pipeliningBase.zrevrank(key, member); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZrevrankWithScore() { + when(commandObjects.zrevrankWithScore("key", "member")).thenReturn(keyValueLongDoubleCommandObject); + + Response> response = pipeliningBase.zrevrankWithScore("key", "member"); + + assertThat(commands, contains(keyValueLongDoubleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZrevrankWithScoreBinary() { + byte[] key = "zset".getBytes(); + byte[] member = "member".getBytes(); + + when(commandObjects.zrevrankWithScore(key, member)).thenReturn(keyValueLongDoubleCommandObject); + + Response> response = pipeliningBase.zrevrankWithScore(key, member); + + assertThat(commands, contains(keyValueLongDoubleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZscan() { + ScanParams params = new ScanParams(); + + when(commandObjects.zscan("key", "0", params)).thenReturn(scanResultTupleCommandObject); + + Response> response = pipeliningBase.zscan("key", "0", params); + + assertThat(commands, contains(scanResultTupleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZscanBinary() { + byte[] key = "zset".getBytes(); + byte[] cursor = "0".getBytes(); + ScanParams params = new ScanParams(); + + when(commandObjects.zscan(key, cursor, params)).thenReturn(scanResultTupleCommandObject); + + Response> response = pipeliningBase.zscan(key, cursor, params); + + assertThat(commands, contains(scanResultTupleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZscore() { + when(commandObjects.zscore("key", "member")).thenReturn(doubleCommandObject); + + Response response = pipeliningBase.zscore("key", "member"); + + assertThat(commands, contains(doubleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZscoreBinary() { + byte[] key = "zset".getBytes(); + byte[] member = "member".getBytes(); + + when(commandObjects.zscore(key, member)).thenReturn(doubleCommandObject); + + Response response = pipeliningBase.zscore(key, member); + + assertThat(commands, contains(doubleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZunion() { + ZParams params = new ZParams(); + + when(commandObjects.zunion(params, "key1", "key2")).thenReturn(listStringCommandObject); + + Response> response = pipeliningBase.zunion(params, "key1", "key2"); + + assertThat(commands, contains(listStringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZunionBinary() { + ZParams params = new ZParams(); + byte[][] keys = { "zset1".getBytes(), "zset2".getBytes() }; + + when(commandObjects.zunion(params, keys)).thenReturn(listBytesCommandObject); + + Response> response = pipeliningBase.zunion(params, keys); + + assertThat(commands, contains(listBytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZunionWithScores() { + ZParams params = new ZParams(); + + when(commandObjects.zunionWithScores(params, "key1", "key2")).thenReturn(listTupleCommandObject); + + Response> response = pipeliningBase.zunionWithScores(params, "key1", "key2"); + + assertThat(commands, contains(listTupleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZunionWithScoresBinary() { + ZParams params = new ZParams(); + byte[][] keys = { "zset1".getBytes(), "zset2".getBytes() }; + + when(commandObjects.zunionWithScores(params, keys)).thenReturn(listTupleCommandObject); + + Response> response = pipeliningBase.zunionWithScores(params, keys); + + assertThat(commands, contains(listTupleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZunionstore() { + when(commandObjects.zunionstore("dstKey", "set1", "set2")).thenReturn(longCommandObject); + + Response response = pipeliningBase.zunionstore("dstKey", "set1", "set2"); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZunionstoreBinary() { + byte[] dstkey = "destZset".getBytes(); + byte[][] sets = { "zset1".getBytes(), "zset2".getBytes() }; + + when(commandObjects.zunionstore(dstkey, sets)).thenReturn(longCommandObject); + + Response response = pipeliningBase.zunionstore(dstkey, sets); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZunionstoreWithParams() { + ZParams params = new ZParams(); + + when(commandObjects.zunionstore("dstKey", params, "set1", "set2")).thenReturn(longCommandObject); + + Response response = pipeliningBase.zunionstore("dstKey", params, "set1", "set2"); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testZunionstoreWithParamsBinary() { + byte[] dstkey = "destZset".getBytes(); + ZParams params = new ZParams(); + byte[][] sets = { "zset1".getBytes(), "zset2".getBytes() }; + + when(commandObjects.zunionstore(dstkey, params, sets)).thenReturn(longCommandObject); + + Response response = pipeliningBase.zunionstore(dstkey, params, sets); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + +} diff --git a/src/test/java/redis/clients/jedis/mocked/pipeline/PipeliningBaseStreamCommandsTest.java b/src/test/java/redis/clients/jedis/mocked/pipeline/PipeliningBaseStreamCommandsTest.java new file mode 100644 index 00000000000..ff010f6e534 --- /dev/null +++ b/src/test/java/redis/clients/jedis/mocked/pipeline/PipeliningBaseStreamCommandsTest.java @@ -0,0 +1,858 @@ +package redis.clients.jedis.mocked.pipeline; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.contains; +import static org.hamcrest.Matchers.is; +import static org.mockito.Mockito.when; + +import java.util.AbstractMap; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.junit.Test; +import redis.clients.jedis.Response; +import redis.clients.jedis.StreamEntryID; +import redis.clients.jedis.params.XAddParams; +import redis.clients.jedis.params.XAutoClaimParams; +import redis.clients.jedis.params.XClaimParams; +import redis.clients.jedis.params.XPendingParams; +import redis.clients.jedis.params.XReadGroupParams; +import redis.clients.jedis.params.XReadParams; +import redis.clients.jedis.params.XTrimParams; +import redis.clients.jedis.resps.StreamConsumerInfo; +import redis.clients.jedis.resps.StreamConsumersInfo; +import redis.clients.jedis.resps.StreamEntry; +import redis.clients.jedis.resps.StreamFullInfo; +import redis.clients.jedis.resps.StreamGroupInfo; +import redis.clients.jedis.resps.StreamInfo; +import redis.clients.jedis.resps.StreamPendingEntry; +import redis.clients.jedis.resps.StreamPendingSummary; + +public class PipeliningBaseStreamCommandsTest extends PipeliningBaseMockedTestBase { + + @Test + public void testXack() { + StreamEntryID[] ids = { new StreamEntryID("1526999352406-0"), new StreamEntryID("1526999352406-1") }; + + when(commandObjects.xack("key", "group", ids)).thenReturn(longCommandObject); + + Response response = pipeliningBase.xack("key", "group", ids); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testXackBinary() { + byte[] key = "stream".getBytes(); + byte[] group = "group".getBytes(); + byte[] id1 = "id1".getBytes(); + byte[] id2 = "id2".getBytes(); + + when(commandObjects.xack(key, group, id1, id2)).thenReturn(longCommandObject); + + Response response = pipeliningBase.xack(key, group, id1, id2); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testXadd() { + StreamEntryID id = new StreamEntryID(); + + Map hash = new HashMap<>(); + hash.put("field1", "value1"); + + when(commandObjects.xadd("key", id, hash)).thenReturn(streamEntryIdCommandObject); + + Response response = pipeliningBase.xadd("key", id, hash); + + assertThat(commands, contains(streamEntryIdCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testXaddBinary() { + byte[] key = "stream".getBytes(); + XAddParams params = new XAddParams(); + + Map hash = new HashMap<>(); + hash.put("field1".getBytes(), "value1".getBytes()); + + when(commandObjects.xadd(key, params, hash)).thenReturn(bytesCommandObject); + + Response response = pipeliningBase.xadd(key, params, hash); + + assertThat(commands, contains(bytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testXaddWithParams() { + XAddParams params = new XAddParams(); + + Map hash = new HashMap<>(); + hash.put("field1", "value1"); + + when(commandObjects.xadd("key", params, hash)).thenReturn(streamEntryIdCommandObject); + + Response response = pipeliningBase.xadd("key", params, hash); + + assertThat(commands, contains(streamEntryIdCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testXautoclaim() { + StreamEntryID start = new StreamEntryID("0-0"); + XAutoClaimParams params = new XAutoClaimParams(); + + when(commandObjects.xautoclaim("key", "group", "consumerName", 10000L, start, params)) + .thenReturn(entryStreamEntryIdListStreamEntryCommandObject); + + Response>> response = pipeliningBase + .xautoclaim("key", "group", "consumerName", 10000L, start, params); + + assertThat(commands, contains(entryStreamEntryIdListStreamEntryCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testXautoclaimBinary() { + byte[] key = "stream".getBytes(); + byte[] groupName = "group".getBytes(); + byte[] consumerName = "consumer".getBytes(); + long minIdleTime = 10000L; + byte[] start = "startId".getBytes(); + XAutoClaimParams params = new XAutoClaimParams(); + + when(commandObjects.xautoclaim(key, groupName, consumerName, minIdleTime, start, params)).thenReturn(listObjectCommandObject); + + Response> response = pipeliningBase.xautoclaim(key, groupName, consumerName, minIdleTime, start, params); + + assertThat(commands, contains(listObjectCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testXautoclaimJustId() { + StreamEntryID start = new StreamEntryID("0-0"); + XAutoClaimParams params = new XAutoClaimParams(); + + when(commandObjects.xautoclaimJustId("key", "group", "consumerName", 10000L, start, params)) + .thenReturn(entryStreamEntryIdListStreamEntryIdCommandObject); + + Response>> response = pipeliningBase + .xautoclaimJustId("key", "group", "consumerName", 10000L, start, params); + + assertThat(commands, contains(entryStreamEntryIdListStreamEntryIdCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testXautoclaimJustIdBinary() { + byte[] key = "stream".getBytes(); + byte[] groupName = "group".getBytes(); + byte[] consumerName = "consumer".getBytes(); + long minIdleTime = 10000L; + byte[] start = "startId".getBytes(); + XAutoClaimParams params = new XAutoClaimParams(); + + when(commandObjects.xautoclaimJustId(key, groupName, consumerName, minIdleTime, start, params)).thenReturn(listObjectCommandObject); + + Response> response = pipeliningBase.xautoclaimJustId(key, groupName, consumerName, minIdleTime, start, params); + + assertThat(commands, contains(listObjectCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testXclaim() { + StreamEntryID[] ids = { new StreamEntryID("1526999352406-0"), new StreamEntryID("1526999352406-1") }; + XClaimParams params = new XClaimParams().idle(10000L); + + when(commandObjects.xclaim("key", "group", "consumerName", 10000L, params, ids)) + .thenReturn(listStreamEntryCommandObject); + + Response> response = pipeliningBase + .xclaim("key", "group", "consumerName", 10000L, params, ids); + + assertThat(commands, contains(listStreamEntryCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testXclaimBinary() { + byte[] key = "stream".getBytes(); + byte[] group = "group".getBytes(); + byte[] consumerName = "consumer".getBytes(); + long minIdleTime = 10000L; + XClaimParams params = new XClaimParams(); + byte[] id1 = "id1".getBytes(); + byte[] id2 = "id2".getBytes(); + + when(commandObjects.xclaim(key, group, consumerName, minIdleTime, params, id1, id2)).thenReturn(listBytesCommandObject); + + Response> response = pipeliningBase.xclaim(key, group, consumerName, minIdleTime, params, id1, id2); + + assertThat(commands, contains(listBytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testXclaimJustId() { + StreamEntryID[] ids = { new StreamEntryID("1526999352406-0"), new StreamEntryID("1526999352406-1") }; + XClaimParams params = new XClaimParams().idle(10000L); + + when(commandObjects.xclaimJustId("key", "group", "consumerName", 10000L, params, ids)) + .thenReturn(listStreamEntryIdCommandObject); + + Response> response = pipeliningBase + .xclaimJustId("key", "group", "consumerName", 10000L, params, ids); + + assertThat(commands, contains(listStreamEntryIdCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testXclaimJustIdBinary() { + byte[] key = "stream".getBytes(); + byte[] group = "group".getBytes(); + byte[] consumerName = "consumer".getBytes(); + long minIdleTime = 10000L; + XClaimParams params = new XClaimParams(); + byte[] id1 = "id1".getBytes(); + byte[] id2 = "id2".getBytes(); + + when(commandObjects.xclaimJustId(key, group, consumerName, minIdleTime, params, id1, id2)).thenReturn(listBytesCommandObject); + + Response> response = pipeliningBase.xclaimJustId(key, group, consumerName, minIdleTime, params, id1, id2); + + assertThat(commands, contains(listBytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testXdel() { + StreamEntryID[] ids = { new StreamEntryID("1526999352406-0"), new StreamEntryID("1526999352406-1") }; + + when(commandObjects.xdel("key", ids)).thenReturn(longCommandObject); + + Response response = pipeliningBase.xdel("key", ids); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testXdelBinary() { + byte[] key = "stream".getBytes(); + byte[] id1 = "id1".getBytes(); + byte[] id2 = "id2".getBytes(); + + when(commandObjects.xdel(key, id1, id2)).thenReturn(longCommandObject); + + Response response = pipeliningBase.xdel(key, id1, id2); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testXgroupCreate() { + StreamEntryID id = new StreamEntryID("0-0"); + + when(commandObjects.xgroupCreate("key", "groupName", id, true)).thenReturn(stringCommandObject); + + Response response = pipeliningBase.xgroupCreate("key", "groupName", id, true); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testXgroupCreateBinary() { + byte[] key = "stream".getBytes(); + byte[] groupName = "group".getBytes(); + byte[] id = "id".getBytes(); + boolean makeStream = true; + + when(commandObjects.xgroupCreate(key, groupName, id, makeStream)).thenReturn(stringCommandObject); + + Response response = pipeliningBase.xgroupCreate(key, groupName, id, makeStream); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testXgroupCreateConsumer() { + when(commandObjects.xgroupCreateConsumer("key", "groupName", "consumerName")) + .thenReturn(booleanCommandObject); + + Response response = pipeliningBase.xgroupCreateConsumer("key", "groupName", "consumerName"); + + assertThat(commands, contains(booleanCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testXgroupCreateConsumerBinary() { + byte[] key = "stream".getBytes(); + byte[] groupName = "group".getBytes(); + byte[] consumerName = "consumer".getBytes(); + + when(commandObjects.xgroupCreateConsumer(key, groupName, consumerName)).thenReturn(booleanCommandObject); + + Response response = pipeliningBase.xgroupCreateConsumer(key, groupName, consumerName); + + assertThat(commands, contains(booleanCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testXgroupDelConsumer() { + when(commandObjects.xgroupDelConsumer("key", "groupName", "consumerName")) + .thenReturn(longCommandObject); + + Response response = pipeliningBase.xgroupDelConsumer("key", "groupName", "consumerName"); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testXgroupDelConsumerBinary() { + byte[] key = "stream".getBytes(); + byte[] groupName = "group".getBytes(); + byte[] consumerName = "consumer".getBytes(); + + when(commandObjects.xgroupDelConsumer(key, groupName, consumerName)).thenReturn(longCommandObject); + + Response response = pipeliningBase.xgroupDelConsumer(key, groupName, consumerName); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testXgroupDestroy() { + when(commandObjects.xgroupDestroy("key", "groupName")).thenReturn(longCommandObject); + + Response response = pipeliningBase.xgroupDestroy("key", "groupName"); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testXgroupDestroyBinary() { + byte[] key = "stream".getBytes(); + byte[] groupName = "group".getBytes(); + + when(commandObjects.xgroupDestroy(key, groupName)).thenReturn(longCommandObject); + + Response response = pipeliningBase.xgroupDestroy(key, groupName); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testXgroupSetID() { + StreamEntryID id = new StreamEntryID("0-0"); + + when(commandObjects.xgroupSetID("key", "groupName", id)).thenReturn(stringCommandObject); + + Response response = pipeliningBase.xgroupSetID("key", "groupName", id); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testXgroupSetIDBinary() { + byte[] key = "stream".getBytes(); + byte[] groupName = "group".getBytes(); + byte[] id = "id".getBytes(); + + when(commandObjects.xgroupSetID(key, groupName, id)).thenReturn(stringCommandObject); + + Response response = pipeliningBase.xgroupSetID(key, groupName, id); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testXinfoConsumers() { + when(commandObjects.xinfoConsumers("key", "group")).thenReturn(listStreamConsumersInfoCommandObject); + + Response> response = pipeliningBase.xinfoConsumers("key", "group"); + + assertThat(commands, contains(listStreamConsumersInfoCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testXinfoConsumersBinary() { + byte[] key = "stream".getBytes(); + byte[] group = "group".getBytes(); + + when(commandObjects.xinfoConsumers(key, group)).thenReturn(listObjectCommandObject); + + Response> response = pipeliningBase.xinfoConsumers(key, group); + + assertThat(commands, contains(listObjectCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testXinfoConsumers2() { + when(commandObjects.xinfoConsumers2("key", "group")).thenReturn(listStreamConsumerInfoCommandObject); + + Response> response = pipeliningBase.xinfoConsumers2("key", "group"); + + assertThat(commands, contains(listStreamConsumerInfoCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testXinfoGroups() { + when(commandObjects.xinfoGroups("key")).thenReturn(listStreamGroupInfoCommandObject); + + Response> response = pipeliningBase.xinfoGroups("key"); + + assertThat(commands, contains(listStreamGroupInfoCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testXinfoGroupsBinary() { + byte[] key = "stream".getBytes(); + + when(commandObjects.xinfoGroups(key)).thenReturn(listObjectCommandObject); + + Response> response = pipeliningBase.xinfoGroups(key); + + assertThat(commands, contains(listObjectCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testXinfoStream() { + when(commandObjects.xinfoStream("key")).thenReturn(streamInfoCommandObject); + + Response response = pipeliningBase.xinfoStream("key"); + + assertThat(commands, contains(streamInfoCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testXinfoStreamBinary() { + byte[] key = "stream".getBytes(); + + when(commandObjects.xinfoStream(key)).thenReturn(objectCommandObject); + + Response response = pipeliningBase.xinfoStream(key); + + assertThat(commands, contains(objectCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testXinfoStreamFull() { + when(commandObjects.xinfoStreamFull("key")).thenReturn(streamFullInfoCommandObject); + + Response response = pipeliningBase.xinfoStreamFull("key"); + + assertThat(commands, contains(streamFullInfoCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testXinfoStreamFullBinary() { + byte[] key = "stream".getBytes(); + + when(commandObjects.xinfoStreamFull(key)).thenReturn(objectCommandObject); + + Response response = pipeliningBase.xinfoStreamFull(key); + + assertThat(commands, contains(objectCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testXinfoStreamFullWithCount() { + int count = 10; + when(commandObjects.xinfoStreamFull("key", count)).thenReturn(streamFullInfoCommandObject); + + Response response = pipeliningBase.xinfoStreamFull("key", count); + + assertThat(commands, contains(streamFullInfoCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testXinfoStreamFullWithCountBinary() { + byte[] key = "stream".getBytes(); + int count = 10; + + when(commandObjects.xinfoStreamFull(key, count)).thenReturn(objectCommandObject); + + Response response = pipeliningBase.xinfoStreamFull(key, count); + + assertThat(commands, contains(objectCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testXlen() { + when(commandObjects.xlen("key")).thenReturn(longCommandObject); + + Response response = pipeliningBase.xlen("key"); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testXlenBinary() { + byte[] key = "stream".getBytes(); + + when(commandObjects.xlen(key)).thenReturn(longCommandObject); + + Response response = pipeliningBase.xlen(key); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testXpending() { + when(commandObjects.xpending("key", "groupName")).thenReturn(streamPendingSummaryCommandObject); + + Response response = pipeliningBase.xpending("key", "groupName"); + + assertThat(commands, contains(streamPendingSummaryCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testXpendingBinary() { + byte[] key = "stream".getBytes(); + byte[] groupName = "group".getBytes(); + + when(commandObjects.xpending(key, groupName)).thenReturn(objectCommandObject); + + Response response = pipeliningBase.xpending(key, groupName); + + assertThat(commands, contains(objectCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testXpendingWithParams() { + XPendingParams params = new XPendingParams(); + + when(commandObjects.xpending("key", "groupName", params)).thenReturn(listStreamPendingEntryCommandObject); + + Response> response = pipeliningBase.xpending("key", "groupName", params); + + assertThat(commands, contains(listStreamPendingEntryCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testXpendingWithParamsBinary() { + byte[] key = "stream".getBytes(); + byte[] groupName = "group".getBytes(); + XPendingParams params = new XPendingParams().count(10); + + when(commandObjects.xpending(key, groupName, params)).thenReturn(listObjectCommandObject); + + Response> response = pipeliningBase.xpending(key, groupName, params); + + assertThat(commands, contains(listObjectCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testXrange() { + String start = "-"; + String end = "+"; + + when(commandObjects.xrange("key", start, end)).thenReturn(listStreamEntryCommandObject); + + Response> response = pipeliningBase.xrange("key", start, end); + + assertThat(commands, contains(listStreamEntryCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testXrangeBinary() { + byte[] key = "stream".getBytes(); + byte[] start = "startId".getBytes(); + byte[] end = "endId".getBytes(); + + when(commandObjects.xrange(key, start, end)).thenReturn(listObjectCommandObject); + + Response> response = pipeliningBase.xrange(key, start, end); + + assertThat(commands, contains(listObjectCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testXrangeWithCount() { + String start = "-"; + String end = "+"; + int count = 10; + + when(commandObjects.xrange("key", start, end, count)).thenReturn(listStreamEntryCommandObject); + + Response> response = pipeliningBase.xrange("key", start, end, count); + + assertThat(commands, contains(listStreamEntryCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testXrangeWithCountBinary() { + byte[] key = "stream".getBytes(); + byte[] start = "startId".getBytes(); + byte[] end = "endId".getBytes(); + int count = 10; + + when(commandObjects.xrange(key, start, end, count)).thenReturn(listObjectCommandObject); + + Response> response = pipeliningBase.xrange(key, start, end, count); + + assertThat(commands, contains(listObjectCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testXrangeIds() { + StreamEntryID start = new StreamEntryID("0-0"); + StreamEntryID end = new StreamEntryID("9999999999999-0"); + + when(commandObjects.xrange("key", start, end)).thenReturn(listStreamEntryCommandObject); + + Response> response = pipeliningBase.xrange("key", start, end); + + assertThat(commands, contains(listStreamEntryCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testXrangeIdsWithCount() { + StreamEntryID start = new StreamEntryID("0-0"); + StreamEntryID end = new StreamEntryID("9999999999999-0"); + int count = 10; + + when(commandObjects.xrange("key", start, end, count)).thenReturn(listStreamEntryCommandObject); + + Response> response = pipeliningBase.xrange("key", start, end, count); + + assertThat(commands, contains(listStreamEntryCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testXread() { + XReadParams xReadParams = new XReadParams(); + + Map streams = new HashMap<>(); + streams.put("key1", new StreamEntryID("0-0")); + streams.put("key2", new StreamEntryID("0-0")); + + when(commandObjects.xread(xReadParams, streams)).thenReturn(listEntryStringListStreamEntryCommandObject); + + Response>>> response = pipeliningBase.xread(xReadParams, streams); + + assertThat(commands, contains(listEntryStringListStreamEntryCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testXreadBinary() { + XReadParams xReadParams = new XReadParams(); + Map.Entry stream1 = new AbstractMap.SimpleImmutableEntry<>("stream1".getBytes(), "id1".getBytes()); + + when(commandObjects.xread(xReadParams, stream1)).thenReturn(listObjectCommandObject); + + Response> response = pipeliningBase.xread(xReadParams, stream1); + + assertThat(commands, contains(listObjectCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testXreadGroup() { + XReadGroupParams xReadGroupParams = new XReadGroupParams(); + + Map streams = new HashMap<>(); + streams.put("stream1", new StreamEntryID("0-0")); + + when(commandObjects.xreadGroup("groupName", "consumer", xReadGroupParams, streams)) + .thenReturn(listEntryStringListStreamEntryCommandObject); + + Response>>> response = pipeliningBase + .xreadGroup("groupName", "consumer", xReadGroupParams, streams); + + assertThat(commands, contains(listEntryStringListStreamEntryCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testXreadGroupBinary() { + byte[] groupName = "group".getBytes(); + byte[] consumer = "consumer".getBytes(); + XReadGroupParams xReadGroupParams = new XReadGroupParams(); + Map.Entry stream1 = new AbstractMap.SimpleImmutableEntry<>("stream1".getBytes(), "id1".getBytes()); + + when(commandObjects.xreadGroup(groupName, consumer, xReadGroupParams, stream1)).thenReturn(listObjectCommandObject); + + Response> response = pipeliningBase.xreadGroup(groupName, consumer, xReadGroupParams, stream1); + + assertThat(commands, contains(listObjectCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testXrevrange() { + String end = "+"; + String start = "-"; + + when(commandObjects.xrevrange("key", end, start)).thenReturn(listStreamEntryCommandObject); + + Response> response = pipeliningBase.xrevrange("key", end, start); + + assertThat(commands, contains(listStreamEntryCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testXrevrangeBinary() { + byte[] key = "stream".getBytes(); + byte[] end = "endId".getBytes(); + byte[] start = "startId".getBytes(); + + when(commandObjects.xrevrange(key, end, start)).thenReturn(listObjectCommandObject); + + Response> response = pipeliningBase.xrevrange(key, end, start); + + assertThat(commands, contains(listObjectCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testXrevrangeWithCount() { + String end = "+"; + String start = "-"; + int count = 10; + + when(commandObjects.xrevrange("key", end, start, count)).thenReturn(listStreamEntryCommandObject); + + Response> response = pipeliningBase.xrevrange("key", end, start, count); + + assertThat(commands, contains(listStreamEntryCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testXrevrangeWithCountBinary() { + byte[] key = "stream".getBytes(); + byte[] end = "endId".getBytes(); + byte[] start = "startId".getBytes(); + int count = 10; + + when(commandObjects.xrevrange(key, end, start, count)).thenReturn(listObjectCommandObject); + + Response> response = pipeliningBase.xrevrange(key, end, start, count); + + assertThat(commands, contains(listObjectCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testXrevrangeIds() { + StreamEntryID end = new StreamEntryID("9999999999999-0"); + StreamEntryID start = new StreamEntryID("0-0"); + + when(commandObjects.xrevrange("key", end, start)).thenReturn(listStreamEntryCommandObject); + + Response> response = pipeliningBase.xrevrange("key", end, start); + + assertThat(commands, contains(listStreamEntryCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testXrevrangeIdsWithCount() { + StreamEntryID end = new StreamEntryID("9999999999999-0"); + StreamEntryID start = new StreamEntryID("0-0"); + int count = 10; + + when(commandObjects.xrevrange("key", end, start, count)).thenReturn(listStreamEntryCommandObject); + + Response> response = pipeliningBase.xrevrange("key", end, start, count); + + assertThat(commands, contains(listStreamEntryCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testXtrim() { + when(commandObjects.xtrim("key", 1000L, true)).thenReturn(longCommandObject); + + Response response = pipeliningBase.xtrim("key", 1000L, true); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testXtrimBinary() { + byte[] key = "stream".getBytes(); + long maxLen = 1000L; + boolean approximateLength = true; + + when(commandObjects.xtrim(key, maxLen, approximateLength)).thenReturn(longCommandObject); + + Response response = pipeliningBase.xtrim(key, maxLen, approximateLength); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testXtrimWithParams() { + XTrimParams params = new XTrimParams().maxLen(1000L); + when(commandObjects.xtrim("key", params)).thenReturn(longCommandObject); + + Response response = pipeliningBase.xtrim("key", params); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testXtrimWithParamsBinary() { + byte[] key = "stream".getBytes(); + XTrimParams params = new XTrimParams().maxLen(1000L); + + when(commandObjects.xtrim(key, params)).thenReturn(longCommandObject); + + Response response = pipeliningBase.xtrim(key, params); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + +} diff --git a/src/test/java/redis/clients/jedis/mocked/pipeline/PipeliningBaseStringCommandsTest.java b/src/test/java/redis/clients/jedis/mocked/pipeline/PipeliningBaseStringCommandsTest.java new file mode 100644 index 00000000000..6fdd1f10ddd --- /dev/null +++ b/src/test/java/redis/clients/jedis/mocked/pipeline/PipeliningBaseStringCommandsTest.java @@ -0,0 +1,615 @@ +package redis.clients.jedis.mocked.pipeline; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.contains; +import static org.hamcrest.Matchers.is; +import static org.mockito.Mockito.when; + +import java.util.List; + +import org.junit.Test; +import redis.clients.jedis.Response; +import redis.clients.jedis.params.GetExParams; +import redis.clients.jedis.params.LCSParams; +import redis.clients.jedis.params.SetParams; +import redis.clients.jedis.resps.LCSMatchResult; + +public class PipeliningBaseStringCommandsTest extends PipeliningBaseMockedTestBase { + + @Test + public void testAppend() { + when(commandObjects.append("key", "value")).thenReturn(longCommandObject); + + Response response = pipeliningBase.append("key", "value"); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testAppendBinary() { + byte[] key = "key".getBytes(); + byte[] value = "value".getBytes(); + + when(commandObjects.append(key, value)).thenReturn(longCommandObject); + + Response response = pipeliningBase.append(key, value); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testDecr() { + when(commandObjects.decr("key")).thenReturn(longCommandObject); + + Response response = pipeliningBase.decr("key"); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testDecrBinary() { + byte[] key = "key".getBytes(); + + when(commandObjects.decr(key)).thenReturn(longCommandObject); + + Response response = pipeliningBase.decr(key); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testDecrBy() { + when(commandObjects.decrBy("key", 10L)).thenReturn(longCommandObject); + + Response response = pipeliningBase.decrBy("key", 10L); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testDecrByBinary() { + byte[] key = "key".getBytes(); + long decrement = 2L; + + when(commandObjects.decrBy(key, decrement)).thenReturn(longCommandObject); + + Response response = pipeliningBase.decrBy(key, decrement); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testGet() { + when(commandObjects.get("key")).thenReturn(stringCommandObject); + + Response response = pipeliningBase.get("key"); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testGetBinary() { + byte[] key = "key".getBytes(); + + when(commandObjects.get(key)).thenReturn(bytesCommandObject); + + Response response = pipeliningBase.get(key); + + assertThat(commands, contains(bytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testGetDel() { + when(commandObjects.getDel("key")).thenReturn(stringCommandObject); + + Response response = pipeliningBase.getDel("key"); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testGetDelBinary() { + byte[] key = "key".getBytes(); + + when(commandObjects.getDel(key)).thenReturn(bytesCommandObject); + + Response response = pipeliningBase.getDel(key); + + assertThat(commands, contains(bytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testGetEx() { + GetExParams params = new GetExParams(); + + when(commandObjects.getEx("key", params)).thenReturn(stringCommandObject); + + Response response = pipeliningBase.getEx("key", params); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testGetExBinary() { + byte[] key = "key".getBytes(); + GetExParams params = new GetExParams().ex(10); + + when(commandObjects.getEx(key, params)).thenReturn(bytesCommandObject); + + Response response = pipeliningBase.getEx(key, params); + + assertThat(commands, contains(bytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testGetrange() { + when(commandObjects.getrange("key", 0, 100)).thenReturn(stringCommandObject); + + Response response = pipeliningBase.getrange("key", 0, 100); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testGetrangeBinary() { + byte[] key = "key".getBytes(); + long startOffset = 0L; + long endOffset = 10L; + + when(commandObjects.getrange(key, startOffset, endOffset)).thenReturn(bytesCommandObject); + + Response response = pipeliningBase.getrange(key, startOffset, endOffset); + + assertThat(commands, contains(bytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testGetSet() { + when(commandObjects.getSet("key", "value")).thenReturn(stringCommandObject); + + Response response = pipeliningBase.getSet("key", "value"); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testGetSetBinary() { + byte[] key = "key".getBytes(); + byte[] value = "value".getBytes(); + + when(commandObjects.getSet(key, value)).thenReturn(bytesCommandObject); + + Response response = pipeliningBase.getSet(key, value); + + assertThat(commands, contains(bytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testIncr() { + when(commandObjects.incr("key")).thenReturn(longCommandObject); + + Response response = pipeliningBase.incr("key"); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testIncrBinary() { + byte[] key = "key".getBytes(); + + when(commandObjects.incr(key)).thenReturn(longCommandObject); + + Response response = pipeliningBase.incr(key); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testIncrBy() { + when(commandObjects.incrBy("key", 10L)).thenReturn(longCommandObject); + + Response response = pipeliningBase.incrBy("key", 10L); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testIncrByBinary() { + byte[] key = "key".getBytes(); + long increment = 2L; + + when(commandObjects.incrBy(key, increment)).thenReturn(longCommandObject); + + Response response = pipeliningBase.incrBy(key, increment); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testIncrByFloat() { + when(commandObjects.incrByFloat("key", 1.5)).thenReturn(doubleCommandObject); + + Response response = pipeliningBase.incrByFloat("key", 1.5); + + assertThat(commands, contains(doubleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testIncrByFloatBinary() { + byte[] key = "key".getBytes(); + double increment = 2.5; + + when(commandObjects.incrByFloat(key, increment)).thenReturn(doubleCommandObject); + + Response response = pipeliningBase.incrByFloat(key, increment); + + assertThat(commands, contains(doubleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testLcs() { + LCSParams params = new LCSParams(); + + when(commandObjects.lcs("keyA", "keyB", params)).thenReturn(lcsMatchResultCommandObject); + + Response response = pipeliningBase.lcs("keyA", "keyB", params); + + assertThat(commands, contains(lcsMatchResultCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testLcsBinary() { + byte[] keyA = "keyA".getBytes(); + byte[] keyB = "keyB".getBytes(); + LCSParams params = new LCSParams().withMatchLen(); + + when(commandObjects.lcs(keyA, keyB, params)).thenReturn(lcsMatchResultCommandObject); + + Response response = pipeliningBase.lcs(keyA, keyB, params); + + assertThat(commands, contains(lcsMatchResultCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testMget() { + String[] keys = { "key1", "key2", "key3" }; + + when(commandObjects.mget(keys)).thenReturn(listStringCommandObject); + + Response> response = pipeliningBase.mget(keys); + + assertThat(commands, contains(listStringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testMgetBinary() { + byte[] key1 = "key1".getBytes(); + byte[] key2 = "key2".getBytes(); + + when(commandObjects.mget(key1, key2)).thenReturn(listBytesCommandObject); + + Response> response = pipeliningBase.mget(key1, key2); + + assertThat(commands, contains(listBytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testMset() { + String[] keysvalues = { "key1", "value1", "key2", "value2" }; + + when(commandObjects.mset(keysvalues)).thenReturn(stringCommandObject); + + Response response = pipeliningBase.mset(keysvalues); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testMsetBinary() { + byte[] key1 = "key1".getBytes(); + byte[] value1 = "value1".getBytes(); + byte[] key2 = "key2".getBytes(); + byte[] value2 = "value2".getBytes(); + + when(commandObjects.mset(key1, value1, key2, value2)).thenReturn(stringCommandObject); + + Response response = pipeliningBase.mset(key1, value1, key2, value2); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testMsetnx() { + String[] keysvalues = { "key1", "value1", "key2", "value2" }; + + when(commandObjects.msetnx(keysvalues)).thenReturn(longCommandObject); + + Response response = pipeliningBase.msetnx(keysvalues); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testMsetnxBinary() { + byte[] key1 = "key1".getBytes(); + byte[] value1 = "value1".getBytes(); + byte[] key2 = "key2".getBytes(); + byte[] value2 = "value2".getBytes(); + + when(commandObjects.msetnx(key1, value1, key2, value2)).thenReturn(longCommandObject); + + Response response = pipeliningBase.msetnx(key1, value1, key2, value2); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testPsetex() { + when(commandObjects.psetex("key", 100000, "value")).thenReturn(stringCommandObject); + + Response response = pipeliningBase.psetex("key", 100000, "value"); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testPsetexBinary() { + byte[] key = "key".getBytes(); + long milliseconds = 5000L; + byte[] value = "value".getBytes(); + + when(commandObjects.psetex(key, milliseconds, value)).thenReturn(stringCommandObject); + + Response response = pipeliningBase.psetex(key, milliseconds, value); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testSet() { + when(commandObjects.set("key", "value")).thenReturn(stringCommandObject); + + Response response = pipeliningBase.set("key", "value"); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testSetBinary() { + byte[] key = "key".getBytes(); + byte[] value = "value".getBytes(); + + when(commandObjects.set(key, value)).thenReturn(stringCommandObject); + + Response response = pipeliningBase.set(key, value); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testSetWithParams() { + SetParams params = new SetParams(); + + when(commandObjects.set("key", "value", params)).thenReturn(stringCommandObject); + + Response response = pipeliningBase.set("key", "value", params); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testSetWithParamsBinary() { + byte[] key = "key".getBytes(); + byte[] value = "value".getBytes(); + SetParams params = new SetParams().nx().ex(10); + + when(commandObjects.set(key, value, params)).thenReturn(stringCommandObject); + + Response response = pipeliningBase.set(key, value, params); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testSetGet() { + when(commandObjects.setGet("key", "value")).thenReturn(stringCommandObject); + + Response response = pipeliningBase.setGet("key", "value"); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testSetGetBinary() { + byte[] key = "key".getBytes(); + byte[] value = "value".getBytes(); + + when(commandObjects.setGet(key, value)).thenReturn(bytesCommandObject); + + Response response = pipeliningBase.setGet(key, value); + + assertThat(commands, contains(bytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testSetGetWithParams() { + SetParams setParams = new SetParams(); + + when(commandObjects.setGet("key", "value", setParams)).thenReturn(stringCommandObject); + + Response response = pipeliningBase.setGet("key", "value", setParams); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testSetGetWithParamsBinary() { + byte[] key = "key".getBytes(); + byte[] value = "value".getBytes(); + SetParams params = new SetParams().nx().ex(10); + + when(commandObjects.setGet(key, value, params)).thenReturn(bytesCommandObject); + + Response response = pipeliningBase.setGet(key, value, params); + + assertThat(commands, contains(bytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testSetex() { + when(commandObjects.setex("key", 60, "value")).thenReturn(stringCommandObject); + + Response response = pipeliningBase.setex("key", 60, "value"); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testSetexBinary() { + byte[] key = "key".getBytes(); + long seconds = 60L; + byte[] value = "value".getBytes(); + + when(commandObjects.setex(key, seconds, value)).thenReturn(stringCommandObject); + + Response response = pipeliningBase.setex(key, seconds, value); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testSetnx() { + when(commandObjects.setnx("key", "value")).thenReturn(longCommandObject); + + Response response = pipeliningBase.setnx("key", "value"); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testSetnxBinary() { + byte[] key = "key".getBytes(); + byte[] value = "value".getBytes(); + + when(commandObjects.setnx(key, value)).thenReturn(longCommandObject); + + Response response = pipeliningBase.setnx(key, value); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testSetrange() { + when(commandObjects.setrange("key", 100, "value")).thenReturn(longCommandObject); + + Response response = pipeliningBase.setrange("key", 100, "value"); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testSetrangeBinary() { + byte[] key = "key".getBytes(); + long offset = 10L; + byte[] value = "value".getBytes(); + + when(commandObjects.setrange(key, offset, value)).thenReturn(longCommandObject); + + Response response = pipeliningBase.setrange(key, offset, value); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testStrlen() { + when(commandObjects.strlen("key")).thenReturn(longCommandObject); + + Response response = pipeliningBase.strlen("key"); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testStrlenBinary() { + byte[] key = "key".getBytes(); + + when(commandObjects.strlen(key)).thenReturn(longCommandObject); + + Response response = pipeliningBase.strlen(key); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testSubstr() { + when(commandObjects.substr("key", 0, 10)).thenReturn(stringCommandObject); + + Response response = pipeliningBase.substr("key", 0, 10); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testSubstrBinary() { + byte[] key = "key".getBytes(); + int start = 0; + int end = 5; + + when(commandObjects.substr(key, start, end)).thenReturn(bytesCommandObject); + + Response response = pipeliningBase.substr(key, start, end); + + assertThat(commands, contains(bytesCommandObject)); + assertThat(response, is(predefinedResponse)); + } + +} diff --git a/src/test/java/redis/clients/jedis/mocked/pipeline/PipeliningBaseTDigestCommandsTest.java b/src/test/java/redis/clients/jedis/mocked/pipeline/PipeliningBaseTDigestCommandsTest.java new file mode 100644 index 00000000000..1e2b29f9a10 --- /dev/null +++ b/src/test/java/redis/clients/jedis/mocked/pipeline/PipeliningBaseTDigestCommandsTest.java @@ -0,0 +1,183 @@ +package redis.clients.jedis.mocked.pipeline; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.contains; +import static org.hamcrest.Matchers.is; +import static org.mockito.Mockito.when; + +import java.util.List; +import java.util.Map; + +import org.junit.Test; +import redis.clients.jedis.Response; +import redis.clients.jedis.bloom.TDigestMergeParams; + +public class PipeliningBaseTDigestCommandsTest extends PipeliningBaseMockedTestBase { + + @Test + public void testTdigestAdd() { + when(commandObjects.tdigestAdd("myTDigest", 1.0, 2.0, 3.0)).thenReturn(stringCommandObject); + + Response response = pipeliningBase.tdigestAdd("myTDigest", 1.0, 2.0, 3.0); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testTdigestByRank() { + when(commandObjects.tdigestByRank("myTDigest", 1, 2)).thenReturn(listDoubleCommandObject); + + Response> response = pipeliningBase.tdigestByRank("myTDigest", 1, 2); + + assertThat(commands, contains(listDoubleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testTdigestByRevRank() { + when(commandObjects.tdigestByRevRank("myTDigest", 1, 2)).thenReturn(listDoubleCommandObject); + + Response> response = pipeliningBase.tdigestByRevRank("myTDigest", 1, 2); + + assertThat(commands, contains(listDoubleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testTdigestCDF() { + when(commandObjects.tdigestCDF("myTDigest", 1.0, 2.0)).thenReturn(listDoubleCommandObject); + + Response> response = pipeliningBase.tdigestCDF("myTDigest", 1.0, 2.0); + + assertThat(commands, contains(listDoubleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testTdigestCreate() { + when(commandObjects.tdigestCreate("myTDigest")).thenReturn(stringCommandObject); + + Response response = pipeliningBase.tdigestCreate("myTDigest"); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testTdigestCreateWithCompression() { + when(commandObjects.tdigestCreate("myTDigest", 100)).thenReturn(stringCommandObject); + + Response response = pipeliningBase.tdigestCreate("myTDigest", 100); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testTdigestInfo() { + when(commandObjects.tdigestInfo("myTDigest")).thenReturn(mapStringObjectCommandObject); + + Response> response = pipeliningBase.tdigestInfo("myTDigest"); + + assertThat(commands, contains(mapStringObjectCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testTdigestMax() { + when(commandObjects.tdigestMax("myTDigest")).thenReturn(doubleCommandObject); + + Response response = pipeliningBase.tdigestMax("myTDigest"); + + assertThat(commands, contains(doubleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testTdigestMerge() { + when(commandObjects.tdigestMerge("destinationTDigest", "sourceTDigest1", "sourceTDigest2")) + .thenReturn(stringCommandObject); + + Response response = + pipeliningBase.tdigestMerge("destinationTDigest", "sourceTDigest1", "sourceTDigest2"); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testTdigestMergeWithParams() { + TDigestMergeParams mergeParams = new TDigestMergeParams().compression(100); + + when(commandObjects.tdigestMerge(mergeParams, "destinationTDigest", "sourceTDigest1", "sourceTDigest2")) + .thenReturn(stringCommandObject); + + Response response = + pipeliningBase.tdigestMerge(mergeParams, "destinationTDigest", "sourceTDigest1", "sourceTDigest2"); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testTdigestMin() { + when(commandObjects.tdigestMin("myTDigest")).thenReturn(doubleCommandObject); + + Response response = pipeliningBase.tdigestMin("myTDigest"); + + assertThat(commands, contains(doubleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testTdigestQuantile() { + when(commandObjects.tdigestQuantile("myTDigest", 0.5, 0.9)).thenReturn(listDoubleCommandObject); + + Response> response = pipeliningBase.tdigestQuantile("myTDigest", 0.5, 0.9); + + assertThat(commands, contains(listDoubleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testTdigestRank() { + when(commandObjects.tdigestRank("myTDigest", 1.0, 2.0)).thenReturn(listLongCommandObject); + + Response> response = pipeliningBase.tdigestRank("myTDigest", 1.0, 2.0); + + assertThat(commands, contains(listLongCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testTdigestReset() { + when(commandObjects.tdigestReset("myTDigest")).thenReturn(stringCommandObject); + + Response response = pipeliningBase.tdigestReset("myTDigest"); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testTdigestRevRank() { + when(commandObjects.tdigestRevRank("myTDigest", 1.0, 2.0)).thenReturn(listLongCommandObject); + + Response> response = pipeliningBase.tdigestRevRank("myTDigest", 1.0, 2.0); + + assertThat(commands, contains(listLongCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testTdigestTrimmedMean() { + when(commandObjects.tdigestTrimmedMean("myTDigest", 0.1, 0.9)).thenReturn(doubleCommandObject); + + Response response = pipeliningBase.tdigestTrimmedMean("myTDigest", 0.1, 0.9); + + assertThat(commands, contains(doubleCommandObject)); + assertThat(response, is(predefinedResponse)); + } + +} diff --git a/src/test/java/redis/clients/jedis/mocked/pipeline/PipeliningBaseTimeSeriesCommandsTest.java b/src/test/java/redis/clients/jedis/mocked/pipeline/PipeliningBaseTimeSeriesCommandsTest.java new file mode 100644 index 00000000000..44e653c0116 --- /dev/null +++ b/src/test/java/redis/clients/jedis/mocked/pipeline/PipeliningBaseTimeSeriesCommandsTest.java @@ -0,0 +1,353 @@ +package redis.clients.jedis.mocked.pipeline; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.contains; +import static org.hamcrest.Matchers.is; +import static org.mockito.Mockito.when; + +import java.util.AbstractMap; +import java.util.List; +import java.util.Map; + +import org.junit.Test; +import redis.clients.jedis.Response; +import redis.clients.jedis.timeseries.AggregationType; +import redis.clients.jedis.timeseries.TSAlterParams; +import redis.clients.jedis.timeseries.TSCreateParams; +import redis.clients.jedis.timeseries.TSElement; +import redis.clients.jedis.timeseries.TSGetParams; +import redis.clients.jedis.timeseries.TSInfo; +import redis.clients.jedis.timeseries.TSMGetElement; +import redis.clients.jedis.timeseries.TSMGetParams; +import redis.clients.jedis.timeseries.TSMRangeElements; +import redis.clients.jedis.timeseries.TSMRangeParams; +import redis.clients.jedis.timeseries.TSRangeParams; + +public class PipeliningBaseTimeSeriesCommandsTest extends PipeliningBaseMockedTestBase { + + @Test + public void testTsAdd() { + when(commandObjects.tsAdd("myTimeSeries", 42.0)).thenReturn(longCommandObject); + + Response response = pipeliningBase.tsAdd("myTimeSeries", 42.0); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testTsAddWithTimestamp() { + when(commandObjects.tsAdd("myTimeSeries", 1000L, 42.0)).thenReturn(longCommandObject); + + Response response = pipeliningBase.tsAdd("myTimeSeries", 1000L, 42.0); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testTsAddWithTimestampAndParams() { + TSCreateParams createParams = TSCreateParams.createParams(); + + when(commandObjects.tsAdd("myTimeSeries", 1000L, 42.0, createParams)).thenReturn(longCommandObject); + + Response response = pipeliningBase.tsAdd("myTimeSeries", 1000L, 42.0, createParams); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testTsAlter() { + TSAlterParams alterParams = TSAlterParams.alterParams(); + + when(commandObjects.tsAlter("myTimeSeries", alterParams)).thenReturn(stringCommandObject); + + Response response = pipeliningBase.tsAlter("myTimeSeries", alterParams); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testTsCreate() { + when(commandObjects.tsCreate("myTimeSeries")).thenReturn(stringCommandObject); + + Response response = pipeliningBase.tsCreate("myTimeSeries"); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testTsCreateWithParams() { + TSCreateParams createParams = TSCreateParams.createParams(); + + when(commandObjects.tsCreate("myTimeSeries", createParams)).thenReturn(stringCommandObject); + + Response response = pipeliningBase.tsCreate("myTimeSeries", createParams); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testTsCreateRule() { + AggregationType aggregationType = AggregationType.AVG; + long timeBucket = 60; + + when(commandObjects.tsCreateRule("sourceTimeSeries", "destTimeSeries", aggregationType, timeBucket)).thenReturn(stringCommandObject); + + Response response = pipeliningBase.tsCreateRule("sourceTimeSeries", "destTimeSeries", aggregationType, timeBucket); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testTsCreateRuleWithAlignTimestamp() { + AggregationType aggregationType = AggregationType.AVG; + long bucketDuration = 60; + long alignTimestamp = 0; + + when(commandObjects.tsCreateRule("sourceTimeSeries", "destTimeSeries", aggregationType, bucketDuration, alignTimestamp)).thenReturn(stringCommandObject); + + Response response = pipeliningBase.tsCreateRule("sourceTimeSeries", "destTimeSeries", aggregationType, bucketDuration, alignTimestamp); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testTsDecrBy() { + when(commandObjects.tsDecrBy("myTimeSeries", 1.0)).thenReturn(longCommandObject); + + Response response = pipeliningBase.tsDecrBy("myTimeSeries", 1.0); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testTsDecrByWithTimestamp() { + when(commandObjects.tsDecrBy("myTimeSeries", 1.0, 1000L)).thenReturn(longCommandObject); + + Response response = pipeliningBase.tsDecrBy("myTimeSeries", 1.0, 1000L); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testTsDel() { + when(commandObjects.tsDel("myTimeSeries", 1000L, 2000L)).thenReturn(longCommandObject); + + Response response = pipeliningBase.tsDel("myTimeSeries", 1000L, 2000L); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testTsDeleteRule() { + when(commandObjects.tsDeleteRule("sourceTimeSeries", "destTimeSeries")).thenReturn(stringCommandObject); + + Response response = pipeliningBase.tsDeleteRule("sourceTimeSeries", "destTimeSeries"); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testTsGet() { + when(commandObjects.tsGet("myTimeSeries")).thenReturn(tsElementCommandObject); + + Response response = pipeliningBase.tsGet("myTimeSeries"); + + assertThat(commands, contains(tsElementCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testTsGetWithParams() { + TSGetParams getParams = TSGetParams.getParams(); + + when(commandObjects.tsGet("myTimeSeries", getParams)).thenReturn(tsElementCommandObject); + + Response response = pipeliningBase.tsGet("myTimeSeries", getParams); + + assertThat(commands, contains(tsElementCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testTsIncrBy() { + when(commandObjects.tsIncrBy("myTimeSeries", 1.0)).thenReturn(longCommandObject); + + Response response = pipeliningBase.tsIncrBy("myTimeSeries", 1.0); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testTsIncrByWithTimestamp() { + when(commandObjects.tsIncrBy("myTimeSeries", 1.0, 1000L)).thenReturn(longCommandObject); + + Response response = pipeliningBase.tsIncrBy("myTimeSeries", 1.0, 1000L); + + assertThat(commands, contains(longCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testTsInfo() { + when(commandObjects.tsInfo("myTimeSeries")).thenReturn(tsInfoCommandObject); + + Response response = pipeliningBase.tsInfo("myTimeSeries"); + + assertThat(commands, contains(tsInfoCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testTsInfoDebug() { + when(commandObjects.tsInfoDebug("myTimeSeries")).thenReturn(tsInfoCommandObject); + + Response response = pipeliningBase.tsInfoDebug("myTimeSeries"); + + assertThat(commands, contains(tsInfoCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testTsMAdd() { + Map.Entry entry1 = new AbstractMap.SimpleEntry<>("ts1", new TSElement(1000L, 1.0)); + Map.Entry entry2 = new AbstractMap.SimpleEntry<>("ts2", new TSElement(2000L, 2.0)); + + when(commandObjects.tsMAdd(entry1, entry2)).thenReturn(listLongCommandObject); + + Response> response = pipeliningBase.tsMAdd(entry1, entry2); + + assertThat(commands, contains(listLongCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testTsMGet() { + TSMGetParams multiGetParams = TSMGetParams.multiGetParams(); + String[] filters = { "sensor_id=123" }; + + when(commandObjects.tsMGet(multiGetParams, filters)).thenReturn(mapStringTsmGetElementCommandObject); + + Response> response = pipeliningBase.tsMGet(multiGetParams, filters); + + assertThat(commands, contains(mapStringTsmGetElementCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testTsMRange() { + String[] filters = { "sensor_id=123" }; + + when(commandObjects.tsMRange(1000L, 2000L, filters)).thenReturn(mapStringTsmRangeElementsCommandObject); + + Response> response = pipeliningBase.tsMRange(1000L, 2000L, filters); + + assertThat(commands, contains(mapStringTsmRangeElementsCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testTsMRangeWithParams() { + TSMRangeParams multiRangeParams = TSMRangeParams.multiRangeParams(); + + when(commandObjects.tsMRange(multiRangeParams)).thenReturn(mapStringTsmRangeElementsCommandObject); + + Response> response = pipeliningBase.tsMRange(multiRangeParams); + + assertThat(commands, contains(mapStringTsmRangeElementsCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testTsMRevRange() { + String[] filters = { "sensor_id=123" }; + + when(commandObjects.tsMRevRange(1000L, 2000L, filters)).thenReturn(mapStringTsmRangeElementsCommandObject); + + Response> response = pipeliningBase.tsMRevRange(1000L, 2000L, filters); + + assertThat(commands, contains(mapStringTsmRangeElementsCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testTsMRevRangeWithParams() { + TSMRangeParams multiRangeParams = TSMRangeParams.multiRangeParams(); + + when(commandObjects.tsMRevRange(multiRangeParams)).thenReturn(mapStringTsmRangeElementsCommandObject); + + Response> response = pipeliningBase.tsMRevRange(multiRangeParams); + + assertThat(commands, contains(mapStringTsmRangeElementsCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testTsQueryIndex() { + String[] filters = { "sensor_id=123" }; + + when(commandObjects.tsQueryIndex(filters)).thenReturn(listStringCommandObject); + + Response> response = pipeliningBase.tsQueryIndex(filters); + + assertThat(commands, contains(listStringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testTsRange() { + when(commandObjects.tsRange("myTimeSeries", 1000L, 2000L)).thenReturn(listTsElementCommandObject); + + Response> response = pipeliningBase.tsRange("myTimeSeries", 1000L, 2000L); + + assertThat(commands, contains(listTsElementCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testTsRangeWithParams() { + TSRangeParams rangeParams = TSRangeParams.rangeParams(); + + when(commandObjects.tsRange("myTimeSeries", rangeParams)).thenReturn(listTsElementCommandObject); + + Response> response = pipeliningBase.tsRange("myTimeSeries", rangeParams); + + assertThat(commands, contains(listTsElementCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testTsRevRange() { + when(commandObjects.tsRevRange("myTimeSeries", 1000L, 2000L)).thenReturn(listTsElementCommandObject); + + Response> response = pipeliningBase.tsRevRange("myTimeSeries", 1000L, 2000L); + + assertThat(commands, contains(listTsElementCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testTsRevRangeWithParams() { + TSRangeParams rangeParams = TSRangeParams.rangeParams(); + + when(commandObjects.tsRevRange("myTimeSeries", rangeParams)).thenReturn(listTsElementCommandObject); + + Response> response = pipeliningBase.tsRevRange("myTimeSeries", rangeParams); + + assertThat(commands, contains(listTsElementCommandObject)); + assertThat(response, is(predefinedResponse)); + } + +} diff --git a/src/test/java/redis/clients/jedis/mocked/pipeline/PipeliningBaseTopKCommandsTest.java b/src/test/java/redis/clients/jedis/mocked/pipeline/PipeliningBaseTopKCommandsTest.java new file mode 100644 index 00000000000..b652c0df25d --- /dev/null +++ b/src/test/java/redis/clients/jedis/mocked/pipeline/PipeliningBaseTopKCommandsTest.java @@ -0,0 +1,105 @@ +package redis.clients.jedis.mocked.pipeline; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.contains; +import static org.hamcrest.Matchers.is; +import static org.mockito.Mockito.when; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.junit.Test; +import redis.clients.jedis.Response; + +public class PipeliningBaseTopKCommandsTest extends PipeliningBaseMockedTestBase { + + @Test + public void testTopkAdd() { + when(commandObjects.topkAdd("myTopK", "item1", "item2")).thenReturn(listStringCommandObject); + + Response> response = pipeliningBase.topkAdd("myTopK", "item1", "item2"); + + assertThat(commands, contains(listStringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testTopkIncrBy() { + Map itemIncrements = new HashMap<>(); + itemIncrements.put("item1", 1L); + itemIncrements.put("item2", 2L); + + when(commandObjects.topkIncrBy("myTopK", itemIncrements)).thenReturn(listStringCommandObject); + + Response> response = pipeliningBase.topkIncrBy("myTopK", itemIncrements); + + assertThat(commands, contains(listStringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testTopkInfo() { + when(commandObjects.topkInfo("myTopK")).thenReturn(mapStringObjectCommandObject); + + Response> response = pipeliningBase.topkInfo("myTopK"); + + assertThat(commands, contains(mapStringObjectCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testTopkList() { + when(commandObjects.topkList("myTopK")).thenReturn(listStringCommandObject); + + Response> response = pipeliningBase.topkList("myTopK"); + + assertThat(commands, contains(listStringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testTopkListWithCount() { + when(commandObjects.topkListWithCount("myTopK")).thenReturn(mapStringLongCommandObject); + + Response> response = pipeliningBase.topkListWithCount("myTopK"); + + assertThat(commands, contains(mapStringLongCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testTopkQuery() { + when(commandObjects.topkQuery("myTopK", "item1", "item2")).thenReturn(listBooleanCommandObject); + + Response> response = pipeliningBase.topkQuery("myTopK", "item1", "item2"); + + assertThat(commands, contains(listBooleanCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testTopkReserve() { + when(commandObjects.topkReserve("myTopK", 3L)).thenReturn(stringCommandObject); + + Response response = pipeliningBase.topkReserve("myTopK", 3L); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + + @Test + public void testTopkReserveWithParams() { + long width = 50L; + long depth = 5L; + double decay = 0.9; + + when(commandObjects.topkReserve("myTopK", 3L, width, depth, decay)).thenReturn(stringCommandObject); + + Response response = pipeliningBase.topkReserve("myTopK", 3L, width, depth, decay); + + assertThat(commands, contains(stringCommandObject)); + assertThat(response, is(predefinedResponse)); + } + +} diff --git a/src/test/java/redis/clients/jedis/mocked/unified/UnifiedJedisBitmapCommandsTest.java b/src/test/java/redis/clients/jedis/mocked/unified/UnifiedJedisBitmapCommandsTest.java new file mode 100644 index 00000000000..86492b49dac --- /dev/null +++ b/src/test/java/redis/clients/jedis/mocked/unified/UnifiedJedisBitmapCommandsTest.java @@ -0,0 +1,368 @@ +package redis.clients.jedis.mocked.unified; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.sameInstance; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +import org.junit.Test; +import redis.clients.jedis.args.BitCountOption; +import redis.clients.jedis.args.BitOP; +import redis.clients.jedis.params.BitPosParams; + +public class UnifiedJedisBitmapCommandsTest extends UnifiedJedisMockedTestBase { + + @Test + public void testBitcount() { + String key = "key"; + long expectedCount = 4L; + + when(commandObjects.bitcount(key)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedCount); + + long result = jedis.bitcount(key); + + assertThat(result, sameInstance(expectedCount)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).bitcount(key); + } + + @Test + public void testBitcountBinary() { + byte[] key = "key".getBytes(); + long expectedCount = 4L; + + when(commandObjects.bitcount(key)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedCount); + + long result = jedis.bitcount(key); + + assertThat(result, sameInstance(expectedCount)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).bitcount(key); + } + + @Test + public void testBitcountRange() { + String key = "key"; + long start = 1L; + long end = 2L; + long expectedCount = 2L; + + when(commandObjects.bitcount(key, start, end)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedCount); + + long result = jedis.bitcount(key, start, end); + + assertThat(result, sameInstance(expectedCount)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).bitcount(key, start, end); + } + + @Test + public void testBitcountRangeBinary() { + byte[] key = "key".getBytes(); + long start = 1L; + long end = 2L; + long expectedCount = 2L; + + when(commandObjects.bitcount(key, start, end)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedCount); + + long result = jedis.bitcount(key, start, end); + + assertThat(result, sameInstance(expectedCount)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).bitcount(key, start, end); + } + + @Test + public void testBitcountRangeOption() { + String key = "key"; + long start = 1L; + long end = 2L; + BitCountOption option = BitCountOption.BYTE; + long expectedCount = 2L; + + when(commandObjects.bitcount(key, start, end, option)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedCount); + + long result = jedis.bitcount(key, start, end, option); + + assertThat(result, sameInstance(expectedCount)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).bitcount(key, start, end, option); + } + + @Test + public void testBitcountRangeOptionBinary() { + byte[] key = "key".getBytes(); + long start = 1L; + long end = 2L; + BitCountOption option = BitCountOption.BYTE; + long expectedCount = 2L; + + when(commandObjects.bitcount(key, start, end, option)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedCount); + + long result = jedis.bitcount(key, start, end, option); + + assertThat(result, sameInstance(expectedCount)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).bitcount(key, start, end, option); + } + + @Test + public void testBitfield() { + String key = "key"; + String[] arguments = { "INCRBY", "mykey", "1", "1000" }; + List expectedResults = Arrays.asList(1000L, 2000L); + + when(commandObjects.bitfield(key, arguments)).thenReturn(listLongCommandObject); + when(commandExecutor.executeCommand(listLongCommandObject)).thenReturn(expectedResults); + + List results = jedis.bitfield(key, arguments); + + assertThat(results, sameInstance(expectedResults)); + + verify(commandExecutor).executeCommand(listLongCommandObject); + verify(commandObjects).bitfield(key, arguments); + } + + @Test + public void testBitfieldBinary() { + byte[] key = "key".getBytes(); + byte[][] arguments = { "INCRBY".getBytes(), "mykey".getBytes(), "1".getBytes(), "1000".getBytes() }; + List expectedResults = Arrays.asList(1000L, 2000L); + + when(commandObjects.bitfield(key, arguments)).thenReturn(listLongCommandObject); + when(commandExecutor.executeCommand(listLongCommandObject)).thenReturn(expectedResults); + + List results = jedis.bitfield(key, arguments); + + assertThat(results, sameInstance(expectedResults)); + + verify(commandExecutor).executeCommand(listLongCommandObject); + verify(commandObjects).bitfield(key, arguments); + } + + @Test + public void testBitfieldReadonly() { + String key = "key"; + String[] arguments = { "GET", "u4", "0" }; + List expectedResults = Collections.singletonList(15L); + + when(commandObjects.bitfieldReadonly(key, arguments)).thenReturn(listLongCommandObject); + when(commandExecutor.executeCommand(listLongCommandObject)).thenReturn(expectedResults); + + List results = jedis.bitfieldReadonly(key, arguments); + + assertThat(results, sameInstance(expectedResults)); + + verify(commandExecutor).executeCommand(listLongCommandObject); + verify(commandObjects).bitfieldReadonly(key, arguments); + } + + @Test + public void testBitfieldReadonlyBinary() { + byte[] key = "key".getBytes(); + byte[][] arguments = { "GET".getBytes(), "u4".getBytes(), "0".getBytes() }; + List expectedResults = Collections.singletonList(15L); + + when(commandObjects.bitfieldReadonly(key, arguments)).thenReturn(listLongCommandObject); + when(commandExecutor.executeCommand(listLongCommandObject)).thenReturn(expectedResults); + + List results = jedis.bitfieldReadonly(key, arguments); + + assertThat(results, sameInstance(expectedResults)); + + verify(commandExecutor).executeCommand(listLongCommandObject); + verify(commandObjects).bitfieldReadonly(key, arguments); + } + + @Test + public void testBitop() { + BitOP op = BitOP.OR; + String destKey = "destKey"; + String[] srcKeys = { "srcKey1", "srcKey2" }; + long expectedResponse = 3L; + + when(commandObjects.bitop(op, destKey, srcKeys)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedResponse); + + long result = jedis.bitop(op, destKey, srcKeys); + + assertThat(result, sameInstance(expectedResponse)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).bitop(op, destKey, srcKeys); + } + + @Test + public void testBitopBinary() { + BitOP op = BitOP.XOR; + byte[] destKey = "destKey".getBytes(); + byte[][] srcKeys = { "srcKey1".getBytes(), "srcKey2".getBytes() }; + long expectedResponse = 4L; + + when(commandObjects.bitop(op, destKey, srcKeys)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedResponse); + + long result = jedis.bitop(op, destKey, srcKeys); + + assertThat(result, sameInstance(expectedResponse)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).bitop(op, destKey, srcKeys); + } + + @Test + public void testBitpos() { + String key = "key"; + boolean value = true; // Looking for the first bit set to 1 + long expectedPosition = 2L; // Assuming the first bit set to 1 is at position 2 + + when(commandObjects.bitpos(key, value)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedPosition); + + long result = jedis.bitpos(key, value); + + assertThat(result, sameInstance(expectedPosition)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).bitpos(key, value); + } + + @Test + public void testBitposBinary() { + byte[] key = "key".getBytes(); + boolean value = true; // Looking for the first bit set to 1 + long expectedPosition = 2L; // Assuming the first bit set to 1 is at position 2 + + when(commandObjects.bitpos(key, value)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedPosition); + + long result = jedis.bitpos(key, value); + + assertThat(result, sameInstance(expectedPosition)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).bitpos(key, value); + } + + @Test + public void testBitposParams() { + String key = "key"; + boolean value = false; // Looking for the first bit set to 0 + BitPosParams params = new BitPosParams(1); // Starting the search from byte offset 1 + long expectedPosition = 8L; // Assuming the first bit set to 0 from offset 1 is at position 8 + + when(commandObjects.bitpos(key, value, params)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedPosition); + + long result = jedis.bitpos(key, value, params); + + assertThat(result, sameInstance(expectedPosition)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).bitpos(key, value, params); + } + + @Test + public void testBitposParamsBinary() { + byte[] key = "key".getBytes(); + boolean value = false; // Looking for the first bit set to 0 + BitPosParams params = new BitPosParams(1); // Starting the search from byte offset 1 + long expectedPosition = 8L; // Assuming the first bit set to 0 from offset 1 is at position 8 + + when(commandObjects.bitpos(key, value, params)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedPosition); + + long result = jedis.bitpos(key, value, params); + + assertThat(result, sameInstance(expectedPosition)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).bitpos(key, value, params); + } + + @Test + public void testGetbit() { + String key = "key"; + long offset = 10L; + boolean expectedResponse = true; + + when(commandObjects.getbit(key, offset)).thenReturn(booleanCommandObject); + when(commandExecutor.executeCommand(booleanCommandObject)).thenReturn(expectedResponse); + + boolean result = jedis.getbit(key, offset); + + assertThat(result, sameInstance(expectedResponse)); + + verify(commandExecutor).executeCommand(booleanCommandObject); + verify(commandObjects).getbit(key, offset); + } + + @Test + public void testGetbitBinary() { + byte[] key = "key".getBytes(); + long offset = 10L; + boolean expectedResponse = true; + + when(commandObjects.getbit(key, offset)).thenReturn(booleanCommandObject); + when(commandExecutor.executeCommand(booleanCommandObject)).thenReturn(expectedResponse); + + boolean result = jedis.getbit(key, offset); + + assertThat(result, sameInstance(expectedResponse)); + verify(commandExecutor).executeCommand(booleanCommandObject); + verify(commandObjects).getbit(key, offset); + } + + @Test + public void testSetbit() { + String key = "key"; + long offset = 10L; + boolean value = true; + boolean expectedResponse = true; + + when(commandObjects.setbit(key, offset, value)).thenReturn(booleanCommandObject); + when(commandExecutor.executeCommand(booleanCommandObject)).thenReturn(expectedResponse); + + boolean result = jedis.setbit(key, offset, value); + + assertThat(result, sameInstance(expectedResponse)); + + verify(commandExecutor).executeCommand(booleanCommandObject); + verify(commandObjects).setbit(key, offset, value); + } + + @Test + public void testSetbitBinary() { + byte[] key = "key".getBytes(); + long offset = 10L; + boolean value = true; + boolean expectedResponse = true; + + when(commandObjects.setbit(key, offset, value)).thenReturn(booleanCommandObject); + when(commandExecutor.executeCommand(booleanCommandObject)).thenReturn(expectedResponse); + + boolean result = jedis.setbit(key, offset, value); + + assertThat(result, sameInstance(expectedResponse)); + + verify(commandExecutor).executeCommand(booleanCommandObject); + verify(commandObjects).setbit(key, offset, value); + } + +} diff --git a/src/test/java/redis/clients/jedis/mocked/unified/UnifiedJedisBloomFilterCommandsTest.java b/src/test/java/redis/clients/jedis/mocked/unified/UnifiedJedisBloomFilterCommandsTest.java new file mode 100644 index 00000000000..cafb2d2c83e --- /dev/null +++ b/src/test/java/redis/clients/jedis/mocked/unified/UnifiedJedisBloomFilterCommandsTest.java @@ -0,0 +1,230 @@ +package redis.clients.jedis.mocked.unified; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.sameInstance; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import java.util.AbstractMap; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.junit.Test; +import redis.clients.jedis.bloom.BFInsertParams; +import redis.clients.jedis.bloom.BFReserveParams; + +public class UnifiedJedisBloomFilterCommandsTest extends UnifiedJedisMockedTestBase { + + @Test + public void testBfAdd() { + String key = "testBloom"; + String item = "item1"; + boolean expectedResponse = true; + + when(commandObjects.bfAdd(key, item)).thenReturn(booleanCommandObject); + when(commandExecutor.executeCommand(booleanCommandObject)).thenReturn(expectedResponse); + + boolean result = jedis.bfAdd(key, item); + + assertThat(result, sameInstance(expectedResponse)); + + verify(commandExecutor).executeCommand(booleanCommandObject); + verify(commandObjects).bfAdd(key, item); + } + + @Test + public void testBfCard() { + String key = "testBloom"; + long expectedResponse = 42L; + + when(commandObjects.bfCard(key)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedResponse); + + long result = jedis.bfCard(key); + + assertThat(result, sameInstance(expectedResponse)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).bfCard(key); + } + + @Test + public void testBfExists() { + String key = "testBloom"; + String item = "item1"; + boolean expectedResponse = true; + + when(commandObjects.bfExists(key, item)).thenReturn(booleanCommandObject); + when(commandExecutor.executeCommand(booleanCommandObject)).thenReturn(expectedResponse); + + boolean result = jedis.bfExists(key, item); + + assertThat(result, sameInstance(expectedResponse)); + + verify(commandExecutor).executeCommand(booleanCommandObject); + verify(commandObjects).bfExists(key, item); + } + + @Test + public void testBfInfo() { + String key = "testBloom"; + Map expectedResponse = new HashMap<>(); + expectedResponse.put("size", 42L); + expectedResponse.put("numberOfFilters", 3L); + expectedResponse.put("insertedItems", 1000L); + + when(commandObjects.bfInfo(key)).thenReturn(mapStringObjectCommandObject); + when(commandExecutor.executeCommand(mapStringObjectCommandObject)).thenReturn(expectedResponse); + + Map result = jedis.bfInfo(key); + + assertThat(result, sameInstance(expectedResponse)); + + verify(commandExecutor).executeCommand(mapStringObjectCommandObject); + verify(commandObjects).bfInfo(key); + } + + @Test + public void testBfInsert() { + String key = "testBloom"; + String[] items = { "item1", "item2" }; + List expectedResponse = Arrays.asList(true, false); + + when(commandObjects.bfInsert(key, items)).thenReturn(listBooleanCommandObject); + when(commandExecutor.executeCommand(listBooleanCommandObject)).thenReturn(expectedResponse); + + List result = jedis.bfInsert(key, items); + + assertThat(result, sameInstance(expectedResponse)); + + verify(commandExecutor).executeCommand(listBooleanCommandObject); + verify(commandObjects).bfInsert(key, items); + } + + @Test + public void testBfInsertWithParams() { + String key = "testBloom"; + BFInsertParams insertParams = new BFInsertParams().noCreate(); + String[] items = { "item1", "item2" }; + List expectedResponse = Arrays.asList(true, false); + + when(commandObjects.bfInsert(key, insertParams, items)).thenReturn(listBooleanCommandObject); + when(commandExecutor.executeCommand(listBooleanCommandObject)).thenReturn(expectedResponse); + + List result = jedis.bfInsert(key, insertParams, items); + + assertThat(result, sameInstance(expectedResponse)); + + verify(commandExecutor).executeCommand(listBooleanCommandObject); + verify(commandObjects).bfInsert(key, insertParams, items); + } + + @Test + public void testBfLoadChunk() { + String key = "testBloom"; + long iterator = 1L; + byte[] data = new byte[]{ 1, 2, 3 }; + String expectedResponse = "OK"; + + when(commandObjects.bfLoadChunk(key, iterator, data)).thenReturn(stringCommandObject); + when(commandExecutor.executeCommand(stringCommandObject)).thenReturn(expectedResponse); + + String result = jedis.bfLoadChunk(key, iterator, data); + + assertThat(result, sameInstance(expectedResponse)); + + verify(commandExecutor).executeCommand(stringCommandObject); + verify(commandObjects).bfLoadChunk(key, iterator, data); + } + + @Test + public void testBfMAdd() { + String key = "testBloom"; + String[] items = { "item1", "item2", "item3" }; + List expectedResponse = Arrays.asList(true, false, true); + + when(commandObjects.bfMAdd(key, items)).thenReturn(listBooleanCommandObject); + when(commandExecutor.executeCommand(listBooleanCommandObject)).thenReturn(expectedResponse); + + List result = jedis.bfMAdd(key, items); + + assertThat(result, sameInstance(expectedResponse)); + + verify(commandExecutor).executeCommand(listBooleanCommandObject); + verify(commandObjects).bfMAdd(key, items); + } + + @Test + public void testBfMExists() { + String key = "testBloom"; + String[] items = { "item1", "item2" }; + List expectedResponse = Arrays.asList(true, false); + + when(commandObjects.bfMExists(key, items)).thenReturn(listBooleanCommandObject); + when(commandExecutor.executeCommand(listBooleanCommandObject)).thenReturn(expectedResponse); + + List result = jedis.bfMExists(key, items); + + assertThat(result, sameInstance(expectedResponse)); + + verify(commandExecutor).executeCommand(listBooleanCommandObject); + verify(commandObjects).bfMExists(key, items); + } + + @Test + public void testBfReserve() { + String key = "testBloom"; + double errorRate = 0.01; + long capacity = 10000L; + String expectedResponse = "OK"; + + when(commandObjects.bfReserve(key, errorRate, capacity)).thenReturn(stringCommandObject); + when(commandExecutor.executeCommand(stringCommandObject)).thenReturn(expectedResponse); + + String result = jedis.bfReserve(key, errorRate, capacity); + + assertThat(result, sameInstance(expectedResponse)); + + verify(commandExecutor).executeCommand(stringCommandObject); + verify(commandObjects).bfReserve(key, errorRate, capacity); + } + + @Test + public void testBfReserveWithParams() { + String key = "testBloom"; + double errorRate = 0.01; + long capacity = 10000L; + BFReserveParams reserveParams = new BFReserveParams().expansion(2); + String expectedResponse = "OK"; + + when(commandObjects.bfReserve(key, errorRate, capacity, reserveParams)).thenReturn(stringCommandObject); + when(commandExecutor.executeCommand(stringCommandObject)).thenReturn(expectedResponse); + + String result = jedis.bfReserve(key, errorRate, capacity, reserveParams); + + assertThat(result, sameInstance(expectedResponse)); + + verify(commandExecutor).executeCommand(stringCommandObject); + verify(commandObjects).bfReserve(key, errorRate, capacity, reserveParams); + } + + @Test + public void testBfScanDump() { + String key = "testBloom"; + long iterator = 0L; + Map.Entry expectedResponse = new AbstractMap.SimpleEntry<>(1L, new byte[]{ 1, 2, 3 }); + + when(commandObjects.bfScanDump(key, iterator)).thenReturn(entryLongBytesCommandObject); + when(commandExecutor.executeCommand(entryLongBytesCommandObject)).thenReturn(expectedResponse); + + Map.Entry result = jedis.bfScanDump(key, iterator); + + assertThat(result, sameInstance(expectedResponse)); + + verify(commandExecutor).executeCommand(entryLongBytesCommandObject); + verify(commandObjects).bfScanDump(key, iterator); + } + +} diff --git a/src/test/java/redis/clients/jedis/mocked/unified/UnifiedJedisConnectionManagementCommandsTest.java b/src/test/java/redis/clients/jedis/mocked/unified/UnifiedJedisConnectionManagementCommandsTest.java new file mode 100644 index 00000000000..dc795765ee2 --- /dev/null +++ b/src/test/java/redis/clients/jedis/mocked/unified/UnifiedJedisConnectionManagementCommandsTest.java @@ -0,0 +1,25 @@ +package redis.clients.jedis.mocked.unified; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.equalTo; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import org.junit.Test; + +public class UnifiedJedisConnectionManagementCommandsTest extends UnifiedJedisMockedTestBase { + + @Test + public void testPing() { + when(commandObjects.ping()).thenReturn(stringCommandObject); + when(commandExecutor.broadcastCommand(stringCommandObject)).thenReturn("foo"); + + String result = jedis.ping(); + + assertThat(result, equalTo("foo")); + + verify(commandExecutor).broadcastCommand(stringCommandObject); + verify(commandObjects).ping(); + } + +} diff --git a/src/test/java/redis/clients/jedis/mocked/unified/UnifiedJedisCountMinSketchCommandsTest.java b/src/test/java/redis/clients/jedis/mocked/unified/UnifiedJedisCountMinSketchCommandsTest.java new file mode 100644 index 00000000000..8397d35f593 --- /dev/null +++ b/src/test/java/redis/clients/jedis/mocked/unified/UnifiedJedisCountMinSketchCommandsTest.java @@ -0,0 +1,144 @@ +package redis.clients.jedis.mocked.unified; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.sameInstance; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.junit.Test; + +public class UnifiedJedisCountMinSketchCommandsTest extends UnifiedJedisMockedTestBase { + + @Test + public void testCmsIncrBy() { + String key = "testCMS"; + Map itemIncrements = new HashMap<>(); + itemIncrements.put("item1", 1L); + itemIncrements.put("item2", 2L); + List expectedResponse = Arrays.asList(1L, 2L); + + when(commandObjects.cmsIncrBy(key, itemIncrements)).thenReturn(listLongCommandObject); + when(commandExecutor.executeCommand(listLongCommandObject)).thenReturn(expectedResponse); + + List result = jedis.cmsIncrBy(key, itemIncrements); + + assertThat(result, sameInstance(expectedResponse)); + + verify(commandExecutor).executeCommand(listLongCommandObject); + verify(commandObjects).cmsIncrBy(key, itemIncrements); + } + + @Test + public void testCmsInfo() { + String key = "testCMS"; + Map expectedResponse = new HashMap<>(); + expectedResponse.put("width", 1000L); + expectedResponse.put("depth", 5L); + expectedResponse.put("count", 42L); + + when(commandObjects.cmsInfo(key)).thenReturn(mapStringObjectCommandObject); + when(commandExecutor.executeCommand(mapStringObjectCommandObject)).thenReturn(expectedResponse); + + Map result = jedis.cmsInfo(key); + + assertThat(result, sameInstance(expectedResponse)); + + verify(commandExecutor).executeCommand(mapStringObjectCommandObject); + verify(commandObjects).cmsInfo(key); + } + + @Test + public void testCmsInitByDim() { + String key = "testCMS"; + long width = 1000L; + long depth = 5L; + String expectedResponse = "OK"; + + when(commandObjects.cmsInitByDim(key, width, depth)).thenReturn(stringCommandObject); + when(commandExecutor.executeCommand(stringCommandObject)).thenReturn(expectedResponse); + + String result = jedis.cmsInitByDim(key, width, depth); + + assertThat(result, sameInstance(expectedResponse)); + + verify(commandExecutor).executeCommand(stringCommandObject); + verify(commandObjects).cmsInitByDim(key, width, depth); + } + + @Test + public void testCmsInitByProb() { + String key = "testCMS"; + double error = 0.01; + double probability = 0.99; + String expectedResponse = "OK"; + + when(commandObjects.cmsInitByProb(key, error, probability)).thenReturn(stringCommandObject); + when(commandExecutor.executeCommand(stringCommandObject)).thenReturn(expectedResponse); + + String result = jedis.cmsInitByProb(key, error, probability); + + assertThat(result, sameInstance(expectedResponse)); + + verify(commandExecutor).executeCommand(stringCommandObject); + verify(commandObjects).cmsInitByProb(key, error, probability); + } + + @Test + public void testCmsMerge() { + String destKey = "destCMS"; + String[] keys = { "cms1", "cms2" }; + String expectedResponse = "OK"; + + when(commandObjects.cmsMerge(destKey, keys)).thenReturn(stringCommandObject); + when(commandExecutor.executeCommand(stringCommandObject)).thenReturn(expectedResponse); + + String result = jedis.cmsMerge(destKey, keys); + + assertThat(result, sameInstance(expectedResponse)); + + verify(commandExecutor).executeCommand(stringCommandObject); + verify(commandObjects).cmsMerge(destKey, keys); + } + + @Test + public void testCmsMergeWithWeights() { + String destKey = "destCMS"; + Map keysAndWeights = new HashMap<>(); + keysAndWeights.put("cms1", 1L); + keysAndWeights.put("cms2", 2L); + String expectedResponse = "OK"; + + when(commandObjects.cmsMerge(destKey, keysAndWeights)).thenReturn(stringCommandObject); + when(commandExecutor.executeCommand(stringCommandObject)).thenReturn(expectedResponse); + + String result = jedis.cmsMerge(destKey, keysAndWeights); + + assertThat(result, sameInstance(expectedResponse)); + + verify(commandExecutor).executeCommand(stringCommandObject); + verify(commandObjects).cmsMerge(destKey, keysAndWeights); + } + + @Test + public void testCmsQuery() { + String key = "testCMS"; + String[] items = { "item1", "item2" }; + List expectedResponse = Arrays.asList(42L, 27L); + + when(commandObjects.cmsQuery(key, items)).thenReturn(listLongCommandObject); + when(commandExecutor.executeCommand(listLongCommandObject)).thenReturn(expectedResponse); + + List result = jedis.cmsQuery(key, items); + + assertThat(result, sameInstance(expectedResponse)); + + verify(commandExecutor).executeCommand(listLongCommandObject); + verify(commandObjects).cmsQuery(key, items); + } + +} diff --git a/src/test/java/redis/clients/jedis/mocked/unified/UnifiedJedisCuckooFilterCommandsTest.java b/src/test/java/redis/clients/jedis/mocked/unified/UnifiedJedisCuckooFilterCommandsTest.java new file mode 100644 index 00000000000..d0e463aaf20 --- /dev/null +++ b/src/test/java/redis/clients/jedis/mocked/unified/UnifiedJedisCuckooFilterCommandsTest.java @@ -0,0 +1,281 @@ +package redis.clients.jedis.mocked.unified; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.sameInstance; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import java.util.AbstractMap; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.junit.Test; +import redis.clients.jedis.bloom.CFInsertParams; +import redis.clients.jedis.bloom.CFReserveParams; + +public class UnifiedJedisCuckooFilterCommandsTest extends UnifiedJedisMockedTestBase { + + @Test + public void testCfAdd() { + String key = "testCuckooFilter"; + String item = "item1"; + boolean expectedResponse = true; + + when(commandObjects.cfAdd(key, item)).thenReturn(booleanCommandObject); + when(commandExecutor.executeCommand(booleanCommandObject)).thenReturn(expectedResponse); + + boolean result = jedis.cfAdd(key, item); + + assertThat(result, sameInstance(expectedResponse)); + + verify(commandExecutor).executeCommand(booleanCommandObject); + verify(commandObjects).cfAdd(key, item); + } + + @Test + public void testCfAddNx() { + String key = "testCuckooFilter"; + String item = "item1"; + boolean expectedResponse = true; + + when(commandObjects.cfAddNx(key, item)).thenReturn(booleanCommandObject); + when(commandExecutor.executeCommand(booleanCommandObject)).thenReturn(expectedResponse); + + boolean result = jedis.cfAddNx(key, item); + + assertThat(result, sameInstance(expectedResponse)); + + verify(commandExecutor).executeCommand(booleanCommandObject); + verify(commandObjects).cfAddNx(key, item); + } + + @Test + public void testCfCount() { + String key = "testCuckooFilter"; + String item = "item1"; + long expectedResponse = 42L; + + when(commandObjects.cfCount(key, item)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedResponse); + + long result = jedis.cfCount(key, item); + + assertThat(result, sameInstance(expectedResponse)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).cfCount(key, item); + } + + @Test + public void testCfDel() { + String key = "testCuckooFilter"; + String item = "item1"; + boolean expectedResponse = true; + + when(commandObjects.cfDel(key, item)).thenReturn(booleanCommandObject); + when(commandExecutor.executeCommand(booleanCommandObject)).thenReturn(expectedResponse); + + boolean result = jedis.cfDel(key, item); + + assertThat(result, sameInstance(expectedResponse)); + + verify(commandExecutor).executeCommand(booleanCommandObject); + verify(commandObjects).cfDel(key, item); + } + + @Test + public void testCfExists() { + String key = "testCuckooFilter"; + String item = "item1"; + boolean expectedResponse = true; + + when(commandObjects.cfExists(key, item)).thenReturn(booleanCommandObject); + when(commandExecutor.executeCommand(booleanCommandObject)).thenReturn(expectedResponse); + + boolean result = jedis.cfExists(key, item); + + assertThat(result, sameInstance(expectedResponse)); + + verify(commandExecutor).executeCommand(booleanCommandObject); + verify(commandObjects).cfExists(key, item); + } + + @Test + public void testCfInfo() { + String key = "testCuckooFilter"; + Map expectedResponse = new HashMap<>(); + expectedResponse.put("size", 42L); + expectedResponse.put("bucketSize", 2L); + expectedResponse.put("maxIterations", 500L); + + when(commandObjects.cfInfo(key)).thenReturn(mapStringObjectCommandObject); + when(commandExecutor.executeCommand(mapStringObjectCommandObject)).thenReturn(expectedResponse); + + Map result = jedis.cfInfo(key); + + assertThat(result, sameInstance(expectedResponse)); + + verify(commandExecutor).executeCommand(mapStringObjectCommandObject); + verify(commandObjects).cfInfo(key); + } + + @Test + public void testCfInsert() { + String key = "testCuckooFilter"; + String[] items = { "item1", "item2" }; + List expectedResponse = Arrays.asList(true, false); + + when(commandObjects.cfInsert(key, items)).thenReturn(listBooleanCommandObject); + when(commandExecutor.executeCommand(listBooleanCommandObject)).thenReturn(expectedResponse); + + List result = jedis.cfInsert(key, items); + + assertThat(result, sameInstance(expectedResponse)); + + verify(commandExecutor).executeCommand(listBooleanCommandObject); + verify(commandObjects).cfInsert(key, items); + } + + @Test + public void testCfInsertWithParams() { + String key = "testCuckooFilter"; + CFInsertParams insertParams = new CFInsertParams().noCreate(); + String[] items = { "item1", "item2" }; + List expectedResponse = Arrays.asList(true, false); + + when(commandObjects.cfInsert(key, insertParams, items)).thenReturn(listBooleanCommandObject); + when(commandExecutor.executeCommand(listBooleanCommandObject)).thenReturn(expectedResponse); + + List result = jedis.cfInsert(key, insertParams, items); + + assertThat(result, sameInstance(expectedResponse)); + + verify(commandExecutor).executeCommand(listBooleanCommandObject); + verify(commandObjects).cfInsert(key, insertParams, items); + } + + @Test + public void testCfInsertNx() { + String key = "testCuckooFilter"; + String[] items = { "item1", "item2" }; + List expectedResponse = Arrays.asList(true, false); + + when(commandObjects.cfInsertNx(key, items)).thenReturn(listBooleanCommandObject); + when(commandExecutor.executeCommand(listBooleanCommandObject)).thenReturn(expectedResponse); + + List result = jedis.cfInsertNx(key, items); + + assertThat(result, sameInstance(expectedResponse)); + + verify(commandExecutor).executeCommand(listBooleanCommandObject); + verify(commandObjects).cfInsertNx(key, items); + } + + @Test + public void testCfInsertNxWithParams() { + String key = "testCuckooFilter"; + CFInsertParams insertParams = new CFInsertParams().noCreate(); + String[] items = { "item1", "item2" }; + List expectedResponse = Arrays.asList(true, false); + + when(commandObjects.cfInsertNx(key, insertParams, items)).thenReturn(listBooleanCommandObject); + when(commandExecutor.executeCommand(listBooleanCommandObject)).thenReturn(expectedResponse); + + List result = jedis.cfInsertNx(key, insertParams, items); + + assertThat(result, sameInstance(expectedResponse)); + + verify(commandExecutor).executeCommand(listBooleanCommandObject); + verify(commandObjects).cfInsertNx(key, insertParams, items); + } + + @Test + public void testCfLoadChunk() { + String key = "testCuckooFilter"; + long iterator = 1L; + byte[] data = new byte[]{ 1, 2, 3 }; + String expectedResponse = "OK"; + + when(commandObjects.cfLoadChunk(key, iterator, data)).thenReturn(stringCommandObject); + when(commandExecutor.executeCommand(stringCommandObject)).thenReturn(expectedResponse); + + String result = jedis.cfLoadChunk(key, iterator, data); + + assertThat(result, sameInstance(expectedResponse)); + + verify(commandExecutor).executeCommand(stringCommandObject); + verify(commandObjects).cfLoadChunk(key, iterator, data); + } + + @Test + public void testCfMExists() { + String key = "testCuckooFilter"; + String[] items = { "item1", "item2", "item3" }; + List expectedResponse = Arrays.asList(true, false, true); + + when(commandObjects.cfMExists(key, items)).thenReturn(listBooleanCommandObject); + when(commandExecutor.executeCommand(listBooleanCommandObject)).thenReturn(expectedResponse); + + List result = jedis.cfMExists(key, items); + + assertThat(result, sameInstance(expectedResponse)); + + verify(commandExecutor).executeCommand(listBooleanCommandObject); + verify(commandObjects).cfMExists(key, items); + } + + @Test + public void testCfReserve() { + String key = "testCuckooFilter"; + long capacity = 10000L; + String expectedResponse = "OK"; + + when(commandObjects.cfReserve(key, capacity)).thenReturn(stringCommandObject); + when(commandExecutor.executeCommand(stringCommandObject)).thenReturn(expectedResponse); + + String result = jedis.cfReserve(key, capacity); + + assertThat(result, sameInstance(expectedResponse)); + + verify(commandExecutor).executeCommand(stringCommandObject); + verify(commandObjects).cfReserve(key, capacity); + } + + @Test + public void testCfReserveWithParams() { + String key = "testCuckooFilter"; + long capacity = 10000L; + CFReserveParams reserveParams = new CFReserveParams().expansion(2); + String expectedResponse = "OK"; + + when(commandObjects.cfReserve(key, capacity, reserveParams)).thenReturn(stringCommandObject); + when(commandExecutor.executeCommand(stringCommandObject)).thenReturn(expectedResponse); + + String result = jedis.cfReserve(key, capacity, reserveParams); + + assertThat(result, sameInstance(expectedResponse)); + + verify(commandExecutor).executeCommand(stringCommandObject); + verify(commandObjects).cfReserve(key, capacity, reserveParams); + } + + @Test + public void testCfScanDump() { + String key = "testCuckooFilter"; + long iterator = 0L; + Map.Entry expectedResponse = new AbstractMap.SimpleEntry<>(1L, new byte[]{ 1, 2, 3 }); + + when(commandObjects.cfScanDump(key, iterator)).thenReturn(entryLongBytesCommandObject); + when(commandExecutor.executeCommand(entryLongBytesCommandObject)).thenReturn(expectedResponse); + + Map.Entry result = jedis.cfScanDump(key, iterator); + + assertThat(result, sameInstance(expectedResponse)); + + verify(commandExecutor).executeCommand(entryLongBytesCommandObject); + verify(commandObjects).cfScanDump(key, iterator); + } + +} diff --git a/src/test/java/redis/clients/jedis/mocked/unified/UnifiedJedisGenericCommandsTest.java b/src/test/java/redis/clients/jedis/mocked/unified/UnifiedJedisGenericCommandsTest.java new file mode 100644 index 00000000000..c3c0d384421 --- /dev/null +++ b/src/test/java/redis/clients/jedis/mocked/unified/UnifiedJedisGenericCommandsTest.java @@ -0,0 +1,1582 @@ +package redis.clients.jedis.mocked.unified; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.contains; +import static org.hamcrest.Matchers.equalTo; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import java.util.Arrays; +import java.util.Collections; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import org.junit.Test; +import org.mockito.invocation.InvocationOnMock; +import org.mockito.stubbing.Answer; +import redis.clients.jedis.CommandArguments; +import redis.clients.jedis.Connection; +import redis.clients.jedis.ScanIteration; +import redis.clients.jedis.args.ExpiryOption; +import redis.clients.jedis.params.MigrateParams; +import redis.clients.jedis.params.RestoreParams; +import redis.clients.jedis.params.ScanParams; +import redis.clients.jedis.params.SortingParams; +import redis.clients.jedis.resps.ScanResult; +import redis.clients.jedis.util.KeyValue; + +public class UnifiedJedisGenericCommandsTest extends UnifiedJedisMockedTestBase { + + @Test + public void testCopy() { + String srcKey = "sourceKey"; + String dstKey = "destinationKey"; + boolean replace = true; + + when(commandObjects.copy(srcKey, dstKey, replace)).thenReturn(booleanCommandObject); + when(commandExecutor.executeCommand(booleanCommandObject)).thenReturn(true); + + boolean result = jedis.copy(srcKey, dstKey, replace); + + assertTrue(result); + + verify(commandExecutor).executeCommand(booleanCommandObject); + verify(commandObjects).copy(srcKey, dstKey, replace); + } + + @Test + public void testCopyBinary() { + byte[] srcKey = new byte[]{ 1, 2, 3 }; + byte[] dstKey = new byte[]{ 4, 5, 6 }; + boolean replace = false; + + when(commandObjects.copy(srcKey, dstKey, replace)).thenReturn(booleanCommandObject); + when(commandExecutor.executeCommand(booleanCommandObject)).thenReturn(true); + + boolean result = jedis.copy(srcKey, dstKey, replace); + + assertTrue(result); + + verify(commandExecutor).executeCommand(booleanCommandObject); + verify(commandObjects).copy(srcKey, dstKey, replace); + } + + @Test + public void testDel() { + String key = "key1"; + + when(commandObjects.del(key)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(1L); + + long result = jedis.del(key); + + assertThat(result, equalTo(1L)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).del(key); + } + + @Test + public void testDelBinary() { + byte[] key = new byte[]{ 1, 2, 3 }; + + when(commandObjects.del(key)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(1L); + + long result = jedis.del(key); + + assertThat(result, equalTo(1L)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).del(key); + } + + @Test + public void testDelMultipleKeys() { + String[] keys = { "key1", "key2", "key3" }; + + when(commandObjects.del(keys)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(3L); + + long result = jedis.del(keys); + + assertThat(result, equalTo(3L)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).del(keys); + } + + @Test + public void testDelMultipleKeysBinary() { + byte[][] keys = { new byte[]{ 1, 2, 3 }, new byte[]{ 4, 5, 6 } }; + + when(commandObjects.del(keys)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(2L); + + long result = jedis.del(keys); + + assertThat(result, equalTo(2L)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).del(keys); + } + + @Test + public void testDump() { + String key = "key1"; + + when(commandObjects.dump(key)).thenReturn(bytesCommandObject); + when(commandExecutor.executeCommand(bytesCommandObject)).thenReturn(new byte[]{ 1, 2, 3 }); + + byte[] result = jedis.dump(key); + + assertThat(result, equalTo(new byte[]{ 1, 2, 3 })); + + verify(commandExecutor).executeCommand(bytesCommandObject); + verify(commandObjects).dump(key); + } + + @Test + public void testDumpBinary() { + byte[] key = new byte[]{ 1, 2, 3 }; + + when(commandObjects.dump(key)).thenReturn(bytesCommandObject); + when(commandExecutor.executeCommand(bytesCommandObject)).thenReturn(new byte[]{ 4, 5, 6 }); + + byte[] result = jedis.dump(key); + + assertThat(result, equalTo(new byte[]{ 4, 5, 6 })); + + verify(commandExecutor).executeCommand(bytesCommandObject); + verify(commandObjects).dump(key); + } + + @Test + public void testExists() { + String key = "mykey"; + + when(commandObjects.exists(key)).thenReturn(booleanCommandObject); + when(commandExecutor.executeCommand(booleanCommandObject)).thenReturn(true); + + boolean result = jedis.exists(key); + + assertTrue(result); + + verify(commandExecutor).executeCommand(booleanCommandObject); + verify(commandObjects).exists(key); + } + + @Test + public void testExistsBinary() { + byte[] key = new byte[]{ 1, 2, 3 }; + + when(commandObjects.exists(key)).thenReturn(booleanCommandObject); + when(commandExecutor.executeCommand(booleanCommandObject)).thenReturn(true); + + boolean result = jedis.exists(key); + + assertTrue(result); + + verify(commandExecutor).executeCommand(booleanCommandObject); + verify(commandObjects).exists(key); + } + + @Test + public void testExistsMultipleKeys() { + String[] keys = { "key1", "key2", "key3" }; + + when(commandObjects.exists(keys)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(3L); + + long result = jedis.exists(keys); + + assertThat(result, equalTo(3L)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).exists(keys); + } + + @Test + public void testExistsMultipleKeysBinary() { + byte[][] keys = { new byte[]{ 1, 2, 3 }, new byte[]{ 4, 5, 6 } }; + + when(commandObjects.exists(keys)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(2L); + + long result = jedis.exists(keys); + + assertThat(result, equalTo(2L)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).exists(keys); + } + + @Test + public void testExpire() { + String key = "key1"; + long seconds = 60L; + + when(commandObjects.expire(key, seconds)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(1L); + + long result = jedis.expire(key, seconds); + + assertThat(result, equalTo(1L)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).expire(key, seconds); + } + + @Test + public void testExpireBinary() { + byte[] key = new byte[]{ 1, 2, 3 }; + long seconds = 60L; + + when(commandObjects.expire(key, seconds)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(1L); + + long result = jedis.expire(key, seconds); + + assertThat(result, equalTo(1L)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).expire(key, seconds); + } + + @Test + public void testExpireWithExpiryOption() { + String key = "key1"; + long seconds = 60L; + ExpiryOption expiryOption = ExpiryOption.NX; + + when(commandObjects.expire(key, seconds, expiryOption)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(1L); + + long result = jedis.expire(key, seconds, expiryOption); + + assertThat(result, equalTo(1L)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).expire(key, seconds, expiryOption); + } + + @Test + public void testExpireWithExpiryOptionBinary() { + byte[] key = new byte[]{ 1, 2, 3 }; + long seconds = 60L; + ExpiryOption expiryOption = ExpiryOption.NX; + + when(commandObjects.expire(key, seconds, expiryOption)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(1L); + + long result = jedis.expire(key, seconds, expiryOption); + + assertThat(result, equalTo(1L)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).expire(key, seconds, expiryOption); + } + + @Test + public void testExpireAt() { + String key = "key1"; + long unixTime = 1633072800L; + + when(commandObjects.expireAt(key, unixTime)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(1L); + + long result = jedis.expireAt(key, unixTime); + + assertThat(result, equalTo(1L)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).expireAt(key, unixTime); + } + + @Test + public void testExpireAtBinary() { + byte[] key = new byte[]{ 1, 2, 3 }; + long unixTime = 1633072800L; + + when(commandObjects.expireAt(key, unixTime)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(1L); + + long result = jedis.expireAt(key, unixTime); + + assertThat(result, equalTo(1L)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).expireAt(key, unixTime); + } + + @Test + public void testExpireAtWithExpiryOption() { + String key = "key1"; + long unixTime = 1633072800L; + ExpiryOption expiryOption = ExpiryOption.NX; + + when(commandObjects.expireAt(key, unixTime, expiryOption)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(1L); + + long result = jedis.expireAt(key, unixTime, expiryOption); + + assertThat(result, equalTo(1L)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).expireAt(key, unixTime, expiryOption); + } + + @Test + public void testExpireAtWithExpiryOptionBinary() { + byte[] key = new byte[]{ 1, 2, 3 }; + long unixTime = 1633072800L; + ExpiryOption expiryOption = ExpiryOption.NX; + + when(commandObjects.expireAt(key, unixTime, expiryOption)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(1L); + + long result = jedis.expireAt(key, unixTime, expiryOption); + + assertThat(result, equalTo(1L)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).expireAt(key, unixTime, expiryOption); + } + + @Test + public void testExpireTime() { + String key = "key1"; + + when(commandObjects.expireTime(key)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(1234567890L); + + long result = jedis.expireTime(key); + + assertThat(result, equalTo(1234567890L)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).expireTime(key); + } + + @Test + public void testExpireTimeBinary() { + byte[] key = new byte[]{ 1, 2, 3 }; + + when(commandObjects.expireTime(key)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(1234567890L); + + long result = jedis.expireTime(key); + + assertThat(result, equalTo(1234567890L)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).expireTime(key); + } + + @Test + public void testKeys() { + String pattern = "*"; + Set expectedKeys = new HashSet<>(Arrays.asList("key1", "key2", "key3")); + + when(commandObjects.keys(pattern)).thenReturn(setStringCommandObject); + when(commandExecutor.executeCommand(setStringCommandObject)).thenReturn(expectedKeys); + + Set result = jedis.keys(pattern); + + assertThat(result, equalTo(expectedKeys)); + + verify(commandExecutor).executeCommand(setStringCommandObject); + verify(commandObjects).keys(pattern); + } + + @Test + public void testKeysBinary() { + byte[] pattern = "key*".getBytes(); + Set expectedKeys = new HashSet<>(Arrays.asList("key1".getBytes(), "key2".getBytes())); + + when(commandObjects.keys(pattern)).thenReturn(setBytesCommandObject); + when(commandExecutor.executeCommand(setBytesCommandObject)).thenReturn(expectedKeys); + + Set result = jedis.keys(pattern); + + assertThat(result, equalTo(expectedKeys)); + + verify(commandExecutor).executeCommand(setBytesCommandObject); + verify(commandObjects).keys(pattern); + } + + @Test + public void testMigrate() { + String host = "destinationHost"; + int port = 6379; + String key = "myKey"; + int timeout = 5000; + String expectedResponse = "OK"; + + when(commandObjects.migrate(host, port, key, timeout)).thenReturn(stringCommandObject); + when(commandExecutor.executeCommand(stringCommandObject)).thenReturn(expectedResponse); + + String result = jedis.migrate(host, port, key, timeout); + + assertThat(result, equalTo(expectedResponse)); + + verify(commandExecutor).executeCommand(stringCommandObject); + verify(commandObjects).migrate(host, port, key, timeout); + } + + @Test + public void testMigrateBinary() { + String host = "destinationHost"; + int port = 6379; + byte[] key = "myKey".getBytes(); + int timeout = 5000; + String expectedResponse = "OK"; + + when(commandObjects.migrate(host, port, key, timeout)).thenReturn(stringCommandObject); + when(commandExecutor.executeCommand(stringCommandObject)).thenReturn(expectedResponse); + + String result = jedis.migrate(host, port, key, timeout); + + assertThat(result, equalTo(expectedResponse)); + + verify(commandExecutor).executeCommand(stringCommandObject); + verify(commandObjects).migrate(host, port, key, timeout); + } + + @Test + public void testMigrateMultipleKeys() { + String host = "destinationHost"; + int port = 6379; + int timeout = 5000; + MigrateParams params = new MigrateParams(); + String[] keys = { "key1", "key2" }; + String expectedResponse = "OK"; + + when(commandObjects.migrate(host, port, timeout, params, keys)).thenReturn(stringCommandObject); + when(commandExecutor.executeCommand(stringCommandObject)).thenReturn(expectedResponse); + + String result = jedis.migrate(host, port, timeout, params, keys); + + assertThat(result, equalTo(expectedResponse)); + + verify(commandExecutor).executeCommand(stringCommandObject); + verify(commandObjects).migrate(host, port, timeout, params, keys); + } + + @Test + public void testMigrateMultipleKeysBinary() { + String host = "destinationHost"; + int port = 6379; + int timeout = 5000; + MigrateParams params = new MigrateParams(); + byte[][] keys = { "key1".getBytes(), "key2".getBytes() }; + String expectedResponse = "OK"; + + when(commandObjects.migrate(host, port, timeout, params, keys)).thenReturn(stringCommandObject); + when(commandExecutor.executeCommand(stringCommandObject)).thenReturn(expectedResponse); + + String result = jedis.migrate(host, port, timeout, params, keys); + + assertThat(result, equalTo(expectedResponse)); + + verify(commandExecutor).executeCommand(stringCommandObject); + verify(commandObjects).migrate(host, port, timeout, params, keys); + } + + @Test + public void testObjectEncoding() { + String key = "myKey"; + String expectedEncoding = "ziplist"; + + when(commandObjects.objectEncoding(key)).thenReturn(stringCommandObject); + when(commandExecutor.executeCommand(stringCommandObject)).thenReturn(expectedEncoding); + + String result = jedis.objectEncoding(key); + + assertThat(result, equalTo(expectedEncoding)); + + verify(commandExecutor).executeCommand(stringCommandObject); + verify(commandObjects).objectEncoding(key); + } + + @Test + public void testObjectEncodingBinary() { + byte[] key = "myKey".getBytes(); + byte[] expectedEncoding = "ziplist".getBytes(); + + when(commandObjects.objectEncoding(key)).thenReturn(bytesCommandObject); + when(commandExecutor.executeCommand(bytesCommandObject)).thenReturn(expectedEncoding); + + byte[] result = jedis.objectEncoding(key); + + assertThat(result, equalTo(expectedEncoding)); + + verify(commandExecutor).executeCommand(bytesCommandObject); + verify(commandObjects).objectEncoding(key); + } + + @Test + public void testObjectFreq() { + String key = "myKey"; + Long expectedFreq = 10L; + + when(commandObjects.objectFreq(key)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedFreq); + + Long result = jedis.objectFreq(key); + + assertThat(result, equalTo(expectedFreq)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).objectFreq(key); + } + + @Test + public void testObjectFreqBinary() { + byte[] key = "myKey".getBytes(); + Long expectedFreq = 10L; + + when(commandObjects.objectFreq(key)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedFreq); + + Long result = jedis.objectFreq(key); + + assertThat(result, equalTo(expectedFreq)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).objectFreq(key); + } + + @Test + public void testObjectIdletime() { + String key = "myKey"; + Long expectedIdletime = 3600L; + + when(commandObjects.objectIdletime(key)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedIdletime); + + Long result = jedis.objectIdletime(key); + + assertThat(result, equalTo(expectedIdletime)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).objectIdletime(key); + } + + @Test + public void testObjectIdletimeBinary() { + byte[] key = "myKey".getBytes(); + Long expectedIdletime = 3600L; + + when(commandObjects.objectIdletime(key)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedIdletime); + + Long result = jedis.objectIdletime(key); + + assertThat(result, equalTo(expectedIdletime)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).objectIdletime(key); + } + + @Test + public void testObjectRefcount() { + String key = "myKey"; + Long expectedRefcount = 42L; + + when(commandObjects.objectRefcount(key)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedRefcount); + + Long result = jedis.objectRefcount(key); + + assertThat(result, equalTo(expectedRefcount)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).objectRefcount(key); + } + + @Test + public void testObjectRefcountBinary() { + byte[] key = "myKey".getBytes(); + Long expectedRefcount = 42L; + + when(commandObjects.objectRefcount(key)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedRefcount); + + Long result = jedis.objectRefcount(key); + + assertThat(result, equalTo(expectedRefcount)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).objectRefcount(key); + } + + @Test + public void testPersist() { + String key = "key1"; + + when(commandObjects.persist(key)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(1L); + + long result = jedis.persist(key); + + assertThat(result, equalTo(1L)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).persist(key); + } + + @Test + public void testPersistBinary() { + byte[] key = new byte[]{ 1, 2, 3 }; + + when(commandObjects.persist(key)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(1L); + + long result = jedis.persist(key); + + assertThat(result, equalTo(1L)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).persist(key); + } + + @Test + public void testPexpire() { + String key = "key1"; + long milliseconds = 1000L; + + when(commandObjects.pexpire(key, milliseconds)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(1L); + + long result = jedis.pexpire(key, milliseconds); + + assertThat(result, equalTo(1L)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).pexpire(key, milliseconds); + } + + @Test + public void testPexpireBinary() { + byte[] key = new byte[]{ 1, 2, 3 }; + long milliseconds = 1000L; + + when(commandObjects.pexpire(key, milliseconds)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(1L); + + long result = jedis.pexpire(key, milliseconds); + + assertThat(result, equalTo(1L)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).pexpire(key, milliseconds); + } + + @Test + public void testPexpireWithExpiryOption() { + String key = "key1"; + long milliseconds = 1000L; + ExpiryOption expiryOption = ExpiryOption.NX; + + when(commandObjects.pexpire(key, milliseconds, expiryOption)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(1L); + + long result = jedis.pexpire(key, milliseconds, expiryOption); + + assertThat(result, equalTo(1L)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).pexpire(key, milliseconds, expiryOption); + } + + @Test + public void testPexpireWithExpiryOptionBinary() { + byte[] key = new byte[]{ 1, 2, 3 }; + long milliseconds = 1000L; + ExpiryOption expiryOption = ExpiryOption.NX; + + when(commandObjects.pexpire(key, milliseconds, expiryOption)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(1L); + + long result = jedis.pexpire(key, milliseconds, expiryOption); + + assertThat(result, equalTo(1L)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).pexpire(key, milliseconds, expiryOption); + } + + @Test + public void testPexpireAt() { + String key = "key1"; + long millisecondsTimestamp = 1633072800123L; + + when(commandObjects.pexpireAt(key, millisecondsTimestamp)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(1L); + + long result = jedis.pexpireAt(key, millisecondsTimestamp); + + assertThat(result, equalTo(1L)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).pexpireAt(key, millisecondsTimestamp); + } + + @Test + public void testPexpireAtBinary() { + byte[] key = new byte[]{ 1, 2, 3 }; + long millisecondsTimestamp = 1633072800123L; + + when(commandObjects.pexpireAt(key, millisecondsTimestamp)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(1L); + + long result = jedis.pexpireAt(key, millisecondsTimestamp); + + assertThat(result, equalTo(1L)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).pexpireAt(key, millisecondsTimestamp); + } + + @Test + public void testPexpireAtWithExpiryOption() { + String key = "key1"; + long millisecondsTimestamp = 1633072800123L; + ExpiryOption expiryOption = ExpiryOption.NX; + + when(commandObjects.pexpireAt(key, millisecondsTimestamp, expiryOption)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(1L); + + long result = jedis.pexpireAt(key, millisecondsTimestamp, expiryOption); + + assertThat(result, equalTo(1L)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).pexpireAt(key, millisecondsTimestamp, expiryOption); + } + + @Test + public void testPexpireAtWithExpiryOptionBinary() { + byte[] key = new byte[]{ 1, 2, 3 }; + long millisecondsTimestamp = 1633072800123L; + ExpiryOption expiryOption = ExpiryOption.NX; + + when(commandObjects.pexpireAt(key, millisecondsTimestamp, expiryOption)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(1L); + + long result = jedis.pexpireAt(key, millisecondsTimestamp, expiryOption); + + assertThat(result, equalTo(1L)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).pexpireAt(key, millisecondsTimestamp, expiryOption); + } + + @Test + public void testPexpireTime() { + String key = "key1"; + + when(commandObjects.pexpireTime(key)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(1234567890123L); + + long result = jedis.pexpireTime(key); + + assertThat(result, equalTo(1234567890123L)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).pexpireTime(key); + } + + @Test + public void testPexpireTimeBinary() { + byte[] key = new byte[]{ 1, 2, 3 }; + + when(commandObjects.pexpireTime(key)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(1234567890123L); + + long result = jedis.pexpireTime(key); + + assertThat(result, equalTo(1234567890123L)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).pexpireTime(key); + } + + @Test + public void testPttl() { + String key = "key1"; + + when(commandObjects.pttl(key)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(120000L); + + long result = jedis.pttl(key); + + assertThat(result, equalTo(120000L)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).pttl(key); + } + + @Test + public void testPttlBinary() { + byte[] key = new byte[]{ 1, 2, 3 }; + + when(commandObjects.pttl(key)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(120000L); + + long result = jedis.pttl(key); + + assertThat(result, equalTo(120000L)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).pttl(key); + } + + @Test + public void testRandomKey() { + String expectedKey = "randomKey"; + + when(commandObjects.randomKey()).thenReturn(stringCommandObject); + when(commandExecutor.executeCommand(stringCommandObject)).thenReturn(expectedKey); + + String result = jedis.randomKey(); + + assertThat(result, equalTo(expectedKey)); + + verify(commandExecutor).executeCommand(stringCommandObject); + verify(commandObjects).randomKey(); + } + + @Test + public void testRandomBinaryKey() { + byte[] expectedKey = "randomKey".getBytes(); + + when(commandObjects.randomBinaryKey()).thenReturn(bytesCommandObject); + when(commandExecutor.executeCommand(bytesCommandObject)).thenReturn(expectedKey); + + byte[] result = jedis.randomBinaryKey(); + + assertThat(result, equalTo(expectedKey)); + + verify(commandExecutor).executeCommand(bytesCommandObject); + verify(commandObjects).randomBinaryKey(); + } + + @Test + public void testRename() { + String oldkey = "oldKey"; + String newkey = "newKey"; + String expectedStatus = "OK"; + + when(commandObjects.rename(oldkey, newkey)).thenReturn(stringCommandObject); + when(commandExecutor.executeCommand(stringCommandObject)).thenReturn(expectedStatus); + + String result = jedis.rename(oldkey, newkey); + + assertEquals(expectedStatus, result); + + verify(commandExecutor).executeCommand(stringCommandObject); + verify(commandObjects).rename(oldkey, newkey); + } + + @Test + public void testRenameBinary() { + byte[] oldkey = new byte[]{ 1, 2, 3 }; + byte[] newkey = new byte[]{ 4, 5, 6 }; + String expectedStatus = "OK"; + + when(commandObjects.rename(oldkey, newkey)).thenReturn(stringCommandObject); + when(commandExecutor.executeCommand(stringCommandObject)).thenReturn(expectedStatus); + + String result = jedis.rename(oldkey, newkey); + + assertEquals(expectedStatus, result); + + verify(commandExecutor).executeCommand(stringCommandObject); + verify(commandObjects).rename(oldkey, newkey); + } + + @Test + public void testRenamenx() { + String oldkey = "oldKey"; + String newkey = "newKey"; + long expected = 1L; + + when(commandObjects.renamenx(oldkey, newkey)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expected); + + long result = jedis.renamenx(oldkey, newkey); + + assertEquals(expected, result); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).renamenx(oldkey, newkey); + } + + @Test + public void testRenamenxBinary() { + byte[] oldkey = new byte[]{ 1, 2, 3 }; + byte[] newkey = new byte[]{ 4, 5, 6 }; + long expected = 1L; + + when(commandObjects.renamenx(oldkey, newkey)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expected); + + long result = jedis.renamenx(oldkey, newkey); + + assertThat(result, equalTo(expected)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).renamenx(oldkey, newkey); + } + + @Test + public void testRestore() { + String key = "key1"; + long ttl = 0L; + byte[] serializedValue = new byte[]{ 1, 2, 3 }; + + when(commandObjects.restore(key, ttl, serializedValue)).thenReturn(stringCommandObject); + when(commandExecutor.executeCommand(stringCommandObject)).thenReturn("OK"); + + String result = jedis.restore(key, ttl, serializedValue); + + assertThat(result, equalTo("OK")); + + verify(commandExecutor).executeCommand(stringCommandObject); + verify(commandObjects).restore(key, ttl, serializedValue); + } + + @Test + public void testRestoreBinary() { + byte[] key = new byte[]{ 1, 2, 3 }; + long ttl = 1000L; + byte[] serializedValue = new byte[]{ 4, 5, 6 }; + + when(commandObjects.restore(key, ttl, serializedValue)).thenReturn(stringCommandObject); + when(commandExecutor.executeCommand(stringCommandObject)).thenReturn("OK"); + + String result = jedis.restore(key, ttl, serializedValue); + + assertThat(result, equalTo("OK")); + + verify(commandExecutor).executeCommand(stringCommandObject); + verify(commandObjects).restore(key, ttl, serializedValue); + } + + @Test + public void testRestoreWithParams() { + String key = "key1"; + long ttl = 0L; + byte[] serializedValue = new byte[]{ 1, 2, 3 }; + RestoreParams params = new RestoreParams(); + + when(commandObjects.restore(key, ttl, serializedValue, params)).thenReturn(stringCommandObject); + when(commandExecutor.executeCommand(stringCommandObject)).thenReturn("OK"); + + String result = jedis.restore(key, ttl, serializedValue, params); + + assertThat(result, equalTo("OK")); + + verify(commandExecutor).executeCommand(stringCommandObject); + verify(commandObjects).restore(key, ttl, serializedValue, params); + + } + + @Test + public void testRestoreWithParamsBinary() { + byte[] key = new byte[]{ 1, 2, 3 }; + long ttl = 1000L; + byte[] serializedValue = new byte[]{ 4, 5, 6 }; + RestoreParams params = new RestoreParams(); + + when(commandObjects.restore(key, ttl, serializedValue, params)).thenReturn(stringCommandObject); + when(commandExecutor.executeCommand(stringCommandObject)).thenReturn("OK"); + + String result = jedis.restore(key, ttl, serializedValue, params); + + assertThat(result, equalTo("OK")); + + verify(commandExecutor).executeCommand(stringCommandObject); + verify(commandObjects).restore(key, ttl, serializedValue, params); + } + + @Test + public void testScan() { + String cursor = "0"; + ScanResult expectedScanResult = new ScanResult<>(cursor, Arrays.asList("key1", "key2")); + + when(commandObjects.scan(cursor)).thenReturn(scanResultStringCommandObject); + when(commandExecutor.executeCommand(scanResultStringCommandObject)).thenReturn(expectedScanResult); + + ScanResult result = jedis.scan(cursor); + + assertThat(result, equalTo(expectedScanResult)); + + verify(commandExecutor).executeCommand(scanResultStringCommandObject); + verify(commandObjects).scan(cursor); + } + + @Test + public void testScanBinary() { + byte[] cursor = "0".getBytes(); + ScanResult expectedScanResult = new ScanResult<>(cursor, Arrays.asList("key1".getBytes(), "key2".getBytes())); + + when(commandObjects.scan(cursor)).thenReturn(scanResultBytesCommandObject); + when(commandExecutor.executeCommand(scanResultBytesCommandObject)).thenReturn(expectedScanResult); + + ScanResult result = jedis.scan(cursor); + + assertThat(result, equalTo(expectedScanResult)); + + verify(commandExecutor).executeCommand(scanResultBytesCommandObject); + verify(commandObjects).scan(cursor); + } + + @Test + public void testScanWithParams() { + String cursor = "0"; + ScanParams params = new ScanParams().match("*").count(10); + ScanResult expectedScanResult = new ScanResult<>(cursor, Arrays.asList("key1", "key2")); + + when(commandObjects.scan(cursor, params)).thenReturn(scanResultStringCommandObject); + when(commandExecutor.executeCommand(scanResultStringCommandObject)).thenReturn(expectedScanResult); + + ScanResult result = jedis.scan(cursor, params); + + assertThat(result, equalTo(expectedScanResult)); + + verify(commandExecutor).executeCommand(scanResultStringCommandObject); + verify(commandObjects).scan(cursor, params); + } + + @Test + public void testScanWithParamsBinary() { + byte[] cursor = "0".getBytes(); + ScanParams params = new ScanParams().match("*".getBytes()).count(10); + ScanResult expectedScanResult = new ScanResult<>(cursor, Arrays.asList("key1".getBytes(), "key2".getBytes())); + + when(commandObjects.scan(cursor, params)).thenReturn(scanResultBytesCommandObject); + when(commandExecutor.executeCommand(scanResultBytesCommandObject)).thenReturn(expectedScanResult); + + ScanResult result = jedis.scan(cursor, params); + + assertThat(result, equalTo(expectedScanResult)); + + verify(commandExecutor).executeCommand(scanResultBytesCommandObject); + verify(commandObjects).scan(cursor, params); + } + + @Test + public void testScanWithType() { + String cursor = "0"; + ScanParams params = new ScanParams().match("*").count(10); + String type = "hash"; + ScanResult expectedScanResult = new ScanResult<>(cursor, Arrays.asList("key1", "key2")); + + when(commandObjects.scan(cursor, params, type)).thenReturn(scanResultStringCommandObject); + when(commandExecutor.executeCommand(scanResultStringCommandObject)).thenReturn(expectedScanResult); + + ScanResult result = jedis.scan(cursor, params, type); + + assertThat(result, equalTo(expectedScanResult)); + + verify(commandExecutor).executeCommand(scanResultStringCommandObject); + verify(commandObjects).scan(cursor, params, type); + } + + @Test + public void testScanWithTypeBinary() { + byte[] cursor = "0".getBytes(); + ScanParams params = new ScanParams().match("*".getBytes()).count(10); + byte[] type = "string".getBytes(); + ScanResult expectedScanResult = new ScanResult<>(cursor, Arrays.asList("key1".getBytes(), "key2".getBytes())); + + when(commandObjects.scan(cursor, params, type)).thenReturn(scanResultBytesCommandObject); + when(commandExecutor.executeCommand(scanResultBytesCommandObject)).thenReturn(expectedScanResult); + + ScanResult result = jedis.scan(cursor, params, type); + + assertThat(result, equalTo(expectedScanResult)); + + verify(commandExecutor).executeCommand(scanResultBytesCommandObject); + verify(commandObjects).scan(cursor, params, type); + } + + @Test + public void testScanIteration() { + String cursor = "0"; + String key1 = "key1"; + String key2 = "key2"; + + Connection connection = mock(Connection.class); + when(connection.executeCommand(any(CommandArguments.class))) + .thenReturn(Arrays.asList(cursor.getBytes(), Arrays.asList(key1.getBytes(), key2.getBytes()))); + + when(connectionProvider.getConnectionMap()).thenAnswer(new Answer>() { + @Override + public Map answer(InvocationOnMock invocationOnMock) { + return Collections.singletonMap("c", connection); + } + }); + + ScanIteration result = jedis.scanIteration(10, "prefix:*"); + + ScanResult batch = result.nextBatch(); + assertThat(batch.getCursor(), equalTo(cursor)); + assertThat(batch.getResult(), contains(key1, key2)); + + verify(connectionProvider).getConnectionMap(); + } + + @Test + public void testScanIterationWithType() { + String cursor = "0"; + String key1 = "key1"; + String key2 = "key2"; + + Connection connection = mock(Connection.class); + when(connection.executeCommand(any(CommandArguments.class))) + .thenReturn(Arrays.asList(cursor.getBytes(), Arrays.asList(key1.getBytes(), key2.getBytes()))); + + when(connectionProvider.getConnectionMap()).thenAnswer(new Answer>() { + @Override + public Map answer(InvocationOnMock invocationOnMock) { + return Collections.singletonMap("c", connection); + } + }); + + ScanIteration result = jedis.scanIteration(10, "prefix:*", "zset"); + + ScanResult batch = result.nextBatch(); + assertThat(batch.getCursor(), equalTo(cursor)); + assertThat(batch.getResult(), contains(key1, key2)); + + verify(connectionProvider).getConnectionMap(); + } + + @Test + public void testSort() { + String key = "key1"; + List expected = Arrays.asList("one", "two", "three"); + + when(commandObjects.sort(key)).thenReturn(listStringCommandObject); + when(commandExecutor.executeCommand(listStringCommandObject)).thenReturn(expected); + + List result = jedis.sort(key); + + assertThat(result, equalTo(expected)); + + verify(commandExecutor).executeCommand(listStringCommandObject); + verify(commandObjects).sort(key); + } + + @Test + public void testSortBinary() { + byte[] key = new byte[]{ 1, 2, 3 }; + List expected = Arrays.asList(new byte[]{ 4 }, new byte[]{ 5 }, new byte[]{ 6 }); + + when(commandObjects.sort(key)).thenReturn(listBytesCommandObject); + when(commandExecutor.executeCommand(listBytesCommandObject)).thenReturn(expected); + + List result = jedis.sort(key); + + assertThat(result, equalTo(expected)); + + verify(commandExecutor).executeCommand(listBytesCommandObject); + verify(commandObjects).sort(key); + } + + @Test + public void testSortWithParams() { + String key = "key1"; + SortingParams sortingParams = new SortingParams().asc(); + List expected = Arrays.asList("one", "three", "two"); + + when(commandObjects.sort(key, sortingParams)).thenReturn(listStringCommandObject); + when(commandExecutor.executeCommand(listStringCommandObject)).thenReturn(expected); + + List result = jedis.sort(key, sortingParams); + + assertThat(result, equalTo(expected)); + + verify(commandExecutor).executeCommand(listStringCommandObject); + verify(commandObjects).sort(key, sortingParams); + } + + @Test + public void testSortWithParamsBinary() { + byte[] key = new byte[]{ 1, 2, 3 }; + SortingParams sortingParams = new SortingParams().asc(); + List expected = Arrays.asList(new byte[]{ 4 }, new byte[]{ 6 }, new byte[]{ 5 }); + + when(commandObjects.sort(key, sortingParams)).thenReturn(listBytesCommandObject); + when(commandExecutor.executeCommand(listBytesCommandObject)).thenReturn(expected); + + List result = jedis.sort(key, sortingParams); + + assertThat(result, equalTo(expected)); + + verify(commandExecutor).executeCommand(listBytesCommandObject); + verify(commandObjects).sort(key, sortingParams); + } + + @Test + public void testSortStore() { + String key = "key1"; + String dstkey = "resultKey"; + + when(commandObjects.sort(key, dstkey)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(3L); + + long result = jedis.sort(key, dstkey); + + assertThat(result, equalTo(3L)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).sort(key, dstkey); + } + + @Test + public void testSortStoreBinary() { + byte[] key = new byte[]{ 1, 2, 3 }; + byte[] dstkey = new byte[]{ 7, 8, 9 }; + + when(commandObjects.sort(key, dstkey)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(3L); + + long result = jedis.sort(key, dstkey); + + assertThat(result, equalTo(3L)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).sort(key, dstkey); + } + + @Test + public void testSortStoreWithParams() { + String key = "key1"; + SortingParams sortingParams = new SortingParams().asc(); + String dstkey = "resultKey"; + + when(commandObjects.sort(key, sortingParams, dstkey)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(3L); + + long result = jedis.sort(key, sortingParams, dstkey); + + assertThat(result, equalTo(3L)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).sort(key, sortingParams, dstkey); + } + + @Test + public void testSortStoreWithParamsBinary() { + byte[] key = new byte[]{ 1, 2, 3 }; + SortingParams sortingParams = new SortingParams().asc(); + byte[] dstkey = new byte[]{ 7, 8, 9 }; + + when(commandObjects.sort(key, sortingParams, dstkey)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(3L); + + long result = jedis.sort(key, sortingParams, dstkey); + + assertThat(result, equalTo(3L)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).sort(key, sortingParams, dstkey); + } + + @Test + public void testSortReadonly() { + String key = "key1"; + SortingParams sortingParams = new SortingParams().asc(); + List expected = Arrays.asList("one", "three", "two"); + + when(commandObjects.sortReadonly(key, sortingParams)).thenReturn(listStringCommandObject); + when(commandExecutor.executeCommand(listStringCommandObject)).thenReturn(expected); + + List result = jedis.sortReadonly(key, sortingParams); + + assertThat(result, equalTo(expected)); + + verify(commandExecutor).executeCommand(listStringCommandObject); + verify(commandObjects).sortReadonly(key, sortingParams); + } + + @Test + public void testSortReadonlyBinary() { + byte[] key = new byte[]{ 1, 2, 3 }; + SortingParams sortingParams = new SortingParams().asc(); + List expected = Arrays.asList(new byte[]{ 4 }, new byte[]{ 6 }, new byte[]{ 5 }); + + when(commandObjects.sortReadonly(key, sortingParams)).thenReturn(listBytesCommandObject); + when(commandExecutor.executeCommand(listBytesCommandObject)).thenReturn(expected); + + List result = jedis.sortReadonly(key, sortingParams); + + assertThat(result, equalTo(expected)); + + verify(commandExecutor).executeCommand(listBytesCommandObject); + verify(commandObjects).sortReadonly(key, sortingParams); + } + + @Test + public void testTouch() { + String key = "key1"; + + when(commandObjects.touch(key)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(1L); + + long result = jedis.touch(key); + + assertThat(result, equalTo(1L)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).touch(key); + } + + @Test + public void testTouchBinary() { + byte[] key = new byte[]{ 1, 2, 3 }; + + when(commandObjects.touch(key)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(1L); + + long result = jedis.touch(key); + + assertThat(result, equalTo(1L)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).touch(key); + } + + @Test + public void testTouchMultipleKeys() { + String[] keys = { "key1", "key2", "key3" }; + + when(commandObjects.touch(keys)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(3L); + + long result = jedis.touch(keys); + + assertThat(result, equalTo(3L)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).touch(keys); + } + + @Test + public void testTouchMultipleKeysBinary() { + byte[][] keys = { new byte[]{ 1, 2, 3 }, new byte[]{ 4, 5, 6 } }; + + when(commandObjects.touch(keys)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(2L); + + long result = jedis.touch(keys); + + assertThat(result, equalTo(2L)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).touch(keys); + } + + @Test + public void testTtl() { + String key = "key1"; + + when(commandObjects.ttl(key)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(120L); + + long result = jedis.ttl(key); + + assertThat(result, equalTo(120L)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).ttl(key); + } + + @Test + public void testTtlBinary() { + byte[] key = new byte[]{ 1, 2, 3 }; + + when(commandObjects.ttl(key)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(120L); + + long result = jedis.ttl(key); + + assertThat(result, equalTo(120L)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).ttl(key); + } + + @Test + public void testType() { + String key = "key1"; + + when(commandObjects.type(key)).thenReturn(stringCommandObject); + when(commandExecutor.executeCommand(stringCommandObject)).thenReturn("string"); + + String result = jedis.type(key); + + assertThat(result, equalTo("string")); + + verify(commandExecutor).executeCommand(stringCommandObject); + verify(commandObjects).type(key); + } + + @Test + public void testTypeBinary() { + byte[] key = new byte[]{ 1, 2, 3 }; + + when(commandObjects.type(key)).thenReturn(stringCommandObject); + when(commandExecutor.executeCommand(stringCommandObject)).thenReturn("string"); + + String result = jedis.type(key); + + assertThat(result, equalTo("string")); + + verify(commandExecutor).executeCommand(stringCommandObject); + verify(commandObjects).type(key); + } + + @Test + public void testUnlink() { + String key = "key1"; + + when(commandObjects.unlink(key)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(1L); + + long result = jedis.unlink(key); + + assertThat(result, equalTo(1L)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).unlink(key); + } + + @Test + public void testUnlinkBinary() { + byte[] key = new byte[]{ 1, 2, 3 }; + + when(commandObjects.unlink(key)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(1L); + + long result = jedis.unlink(key); + + assertThat(result, equalTo(1L)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).unlink(key); + } + + @Test + public void testUnlinkMultipleKeys() { + String[] keys = { "key1", "key2", "key3" }; + + when(commandObjects.unlink(keys)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(3L); + + long result = jedis.unlink(keys); + + assertThat(result, equalTo(3L)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).unlink(keys); + } + + @Test + public void testUnlinkMultipleKeysBinary() { + byte[][] keys = { new byte[]{ 1, 2, 3 }, new byte[]{ 4, 5, 6 } }; + + when(commandObjects.unlink(keys)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(2L); + + long result = jedis.unlink(keys); + + assertThat(result, equalTo(2L)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).unlink(keys); + } + + @Test + public void testWaitReplicas() { + String sampleKey = "myKey"; + int replicas = 2; + long timeout = 10000L; + long expectedReplicaCount = 2L; + + when(commandObjects.waitReplicas(sampleKey, replicas, timeout)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedReplicaCount); + + long result = jedis.waitReplicas(sampleKey, replicas, timeout); + + assertThat(result, equalTo(expectedReplicaCount)); + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).waitReplicas(sampleKey, replicas, timeout); + } + + @Test + public void testWaitReplicasBinary() { + byte[] sampleKey = "myKey".getBytes(); + int replicas = 2; + long timeout = 10000L; + long expectedReplicaCount = 2L; + + when(commandObjects.waitReplicas(sampleKey, replicas, timeout)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedReplicaCount); + + long result = jedis.waitReplicas(sampleKey, replicas, timeout); + + assertThat(result, equalTo(expectedReplicaCount)); + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).waitReplicas(sampleKey, replicas, timeout); + } + + @Test + public void testWaitAOF() { + String sampleKey = "myKey"; + long numLocal = 1L; + long numReplicas = 2L; + long timeout = 10000L; + KeyValue expectedResponse = new KeyValue<>(numLocal, numReplicas); + + when(commandObjects.waitAOF(sampleKey, numLocal, numReplicas, timeout)).thenReturn(keyValueLongLongCommandObject); + when(commandExecutor.executeCommand(keyValueLongLongCommandObject)).thenReturn(expectedResponse); + + KeyValue result = jedis.waitAOF(sampleKey, numLocal, numReplicas, timeout); + + assertThat(result, equalTo(expectedResponse)); + verify(commandExecutor).executeCommand(keyValueLongLongCommandObject); + verify(commandObjects).waitAOF(sampleKey, numLocal, numReplicas, timeout); + } + + @Test + public void testWaitAOFBinary() { + byte[] sampleKey = "myKey".getBytes(); + long numLocal = 1L; + long numReplicas = 2L; + long timeout = 10000L; + KeyValue expectedResponse = new KeyValue<>(numLocal, numReplicas); + + when(commandObjects.waitAOF(sampleKey, numLocal, numReplicas, timeout)).thenReturn(keyValueLongLongCommandObject); + when(commandExecutor.executeCommand(keyValueLongLongCommandObject)).thenReturn(expectedResponse); + + KeyValue result = jedis.waitAOF(sampleKey, numLocal, numReplicas, timeout); + + assertThat(result, equalTo(expectedResponse)); + + verify(commandExecutor).executeCommand(keyValueLongLongCommandObject); + verify(commandObjects).waitAOF(sampleKey, numLocal, numReplicas, timeout); + } + +} diff --git a/src/test/java/redis/clients/jedis/mocked/unified/UnifiedJedisGeospatialCommandsTest.java b/src/test/java/redis/clients/jedis/mocked/unified/UnifiedJedisGeospatialCommandsTest.java new file mode 100644 index 00000000000..a6f8b8ac83e --- /dev/null +++ b/src/test/java/redis/clients/jedis/mocked/unified/UnifiedJedisGeospatialCommandsTest.java @@ -0,0 +1,1145 @@ +package redis.clients.jedis.mocked.unified; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.equalTo; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.junit.Test; +import redis.clients.jedis.GeoCoordinate; +import redis.clients.jedis.args.GeoUnit; +import redis.clients.jedis.params.GeoAddParams; +import redis.clients.jedis.params.GeoRadiusParam; +import redis.clients.jedis.params.GeoRadiusStoreParam; +import redis.clients.jedis.params.GeoSearchParam; +import redis.clients.jedis.resps.GeoRadiusResponse; + +public class UnifiedJedisGeospatialCommandsTest extends UnifiedJedisMockedTestBase { + + @Test + public void testGeoadd() { + String key = "cities"; + double longitude = 13.361389; + double latitude = 38.115556; + String member = "Palermo"; + long expectedAdded = 1L; + + when(commandObjects.geoadd(key, longitude, latitude, member)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedAdded); + + long result = jedis.geoadd(key, longitude, latitude, member); + + assertThat(result, equalTo(expectedAdded)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).geoadd(key, longitude, latitude, member); + } + + @Test + public void testGeoaddBinary() { + byte[] key = "cities".getBytes(); + double longitude = 13.361389; + double latitude = 38.115556; + byte[] member = "Palermo".getBytes(); + long expectedAdded = 1L; + + when(commandObjects.geoadd(key, longitude, latitude, member)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedAdded); + + long result = jedis.geoadd(key, longitude, latitude, member); + + assertThat(result, equalTo(expectedAdded)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).geoadd(key, longitude, latitude, member); + } + + @Test + public void testGeoaddMap() { + String key = "cities"; + Map memberCoordinateMap = new HashMap<>(); + memberCoordinateMap.put("Palermo", new GeoCoordinate(13.361389, 38.115556)); + memberCoordinateMap.put("Catania", new GeoCoordinate(15.087269, 37.502669)); + long expectedAdded = 2L; + + when(commandObjects.geoadd(key, memberCoordinateMap)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedAdded); + + long result = jedis.geoadd(key, memberCoordinateMap); + + assertThat(result, equalTo(expectedAdded)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).geoadd(key, memberCoordinateMap); + } + + @Test + public void testGeoaddMapBinary() { + byte[] key = "cities".getBytes(); + Map memberCoordinateMap = new HashMap<>(); + memberCoordinateMap.put("Palermo".getBytes(), new GeoCoordinate(13.361389, 38.115556)); + memberCoordinateMap.put("Catania".getBytes(), new GeoCoordinate(15.087269, 37.502669)); + long expectedAdded = 2L; + + when(commandObjects.geoadd(key, memberCoordinateMap)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedAdded); + + long result = jedis.geoadd(key, memberCoordinateMap); + + assertThat(result, equalTo(expectedAdded)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).geoadd(key, memberCoordinateMap); + } + + @Test + public void testGeoaddMapWithParams() { + String key = "cities"; + GeoAddParams params = GeoAddParams.geoAddParams().nx(); + Map memberCoordinateMap = new HashMap<>(); + memberCoordinateMap.put("Palermo", new GeoCoordinate(13.361389, 38.115556)); + long expectedAdded = 1L; + + when(commandObjects.geoadd(key, params, memberCoordinateMap)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedAdded); + + long result = jedis.geoadd(key, params, memberCoordinateMap); + + assertThat(result, equalTo(expectedAdded)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).geoadd(key, params, memberCoordinateMap); + } + + @Test + public void testGeoaddMapWithParamsBinary() { + byte[] key = "cities".getBytes(); + GeoAddParams params = GeoAddParams.geoAddParams().nx(); + Map memberCoordinateMap = new HashMap<>(); + memberCoordinateMap.put("Palermo".getBytes(), new GeoCoordinate(13.361389, 38.115556)); + long expectedAdded = 1L; + + when(commandObjects.geoadd(key, params, memberCoordinateMap)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedAdded); + + long result = jedis.geoadd(key, params, memberCoordinateMap); + + assertThat(result, equalTo(expectedAdded)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).geoadd(key, params, memberCoordinateMap); + } + + @Test + public void testGeodist() { + String key = "cities"; + String member1 = "Palermo"; + String member2 = "Catania"; + Double expectedDistance = 166274.15156960033; + + when(commandObjects.geodist(key, member1, member2)).thenReturn(doubleCommandObject); + when(commandExecutor.executeCommand(doubleCommandObject)).thenReturn(expectedDistance); + + Double result = jedis.geodist(key, member1, member2); + + assertThat(result, equalTo(expectedDistance)); + + verify(commandExecutor).executeCommand(doubleCommandObject); + verify(commandObjects).geodist(key, member1, member2); + } + + @Test + public void testGeodistBinary() { + byte[] key = "cities".getBytes(); + byte[] member1 = "Palermo".getBytes(); + byte[] member2 = "Catania".getBytes(); + Double expectedDistance = 166274.15156960033; + + when(commandObjects.geodist(key, member1, member2)).thenReturn(doubleCommandObject); + when(commandExecutor.executeCommand(doubleCommandObject)).thenReturn(expectedDistance); + + Double result = jedis.geodist(key, member1, member2); + + assertThat(result, equalTo(expectedDistance)); + + verify(commandExecutor).executeCommand(doubleCommandObject); + verify(commandObjects).geodist(key, member1, member2); + } + + @Test + public void testGeodistWithUnit() { + String key = "cities"; + String member1 = "Palermo"; + String member2 = "Catania"; + GeoUnit unit = GeoUnit.KM; + Double expectedDistance = 166.274; + + when(commandObjects.geodist(key, member1, member2, unit)).thenReturn(doubleCommandObject); + when(commandExecutor.executeCommand(doubleCommandObject)).thenReturn(expectedDistance); + + Double result = jedis.geodist(key, member1, member2, unit); + + assertThat(result, equalTo(expectedDistance)); + + verify(commandExecutor).executeCommand(doubleCommandObject); + verify(commandObjects).geodist(key, member1, member2, unit); + } + + @Test + public void testGeodistWithUnitBinary() { + byte[] key = "cities".getBytes(); + byte[] member1 = "Palermo".getBytes(); + byte[] member2 = "Catania".getBytes(); + GeoUnit unit = GeoUnit.KM; + Double expectedDistance = 166.274; + + when(commandObjects.geodist(key, member1, member2, unit)).thenReturn(doubleCommandObject); + when(commandExecutor.executeCommand(doubleCommandObject)).thenReturn(expectedDistance); + + Double result = jedis.geodist(key, member1, member2, unit); + + assertThat(result, equalTo(expectedDistance)); + + verify(commandExecutor).executeCommand(doubleCommandObject); + verify(commandObjects).geodist(key, member1, member2, unit); + } + + @Test + public void testGeohash() { + String key = "cities"; + String[] members = { "Palermo", "Catania" }; + List expectedHashes = Arrays.asList("sqc8b49rny0", "sqdtr74hyu0"); + + when(commandObjects.geohash(key, members)).thenReturn(listStringCommandObject); + when(commandExecutor.executeCommand(listStringCommandObject)).thenReturn(expectedHashes); + + List result = jedis.geohash(key, members); + + assertThat(result, equalTo(expectedHashes)); + + verify(commandExecutor).executeCommand(listStringCommandObject); + verify(commandObjects).geohash(key, members); + } + + @Test + public void testGeohashBinary() { + byte[] key = "cities".getBytes(); + byte[][] members = { "Palermo".getBytes(), "Catania".getBytes() }; + List expectedHashes = Arrays.asList("sqc8b49rny0".getBytes(), "sqdtr74hyu0".getBytes()); + + when(commandObjects.geohash(key, members)).thenReturn(listBytesCommandObject); + when(commandExecutor.executeCommand(listBytesCommandObject)).thenReturn(expectedHashes); + + List result = jedis.geohash(key, members); + + assertThat(result, equalTo(expectedHashes)); + + verify(commandExecutor).executeCommand(listBytesCommandObject); + verify(commandObjects).geohash(key, members); + } + + @Test + public void testGeopos() { + String key = "cities"; + String[] members = { "Palermo", "Catania" }; + List expectedPositions = Arrays.asList( + new GeoCoordinate(13.361389, 38.115556), + new GeoCoordinate(15.087269, 37.502669) + ); + + when(commandObjects.geopos(key, members)).thenReturn(listGeoCoordinateCommandObject); + when(commandExecutor.executeCommand(listGeoCoordinateCommandObject)).thenReturn(expectedPositions); + + List result = jedis.geopos(key, members); + + assertThat(result, equalTo(expectedPositions)); + + verify(commandExecutor).executeCommand(listGeoCoordinateCommandObject); + verify(commandObjects).geopos(key, members); + } + + @Test + public void testGeoposBinary() { + byte[] key = "cities".getBytes(); + byte[][] members = { "Palermo".getBytes(), "Catania".getBytes() }; + List expectedPositions = Arrays.asList( + new GeoCoordinate(13.361389, 38.115556), + new GeoCoordinate(15.087269, 37.502669) + ); + + when(commandObjects.geopos(key, members)).thenReturn(listGeoCoordinateCommandObject); + when(commandExecutor.executeCommand(listGeoCoordinateCommandObject)).thenReturn(expectedPositions); + + List result = jedis.geopos(key, members); + + assertThat(result, equalTo(expectedPositions)); + + verify(commandExecutor).executeCommand(listGeoCoordinateCommandObject); + verify(commandObjects).geopos(key, members); + } + + @Test + public void testGeoradius() { + String key = "cities"; + double longitude = 15.087269; + double latitude = 37.502669; + double radius = 100; + GeoUnit unit = GeoUnit.KM; + List expectedResponses = new ArrayList<>(); + expectedResponses.add(new GeoRadiusResponse("Palermo".getBytes())); + + when(commandObjects.georadius(key, longitude, latitude, radius, unit)).thenReturn(listGeoRadiusResponseCommandObject); + when(commandExecutor.executeCommand(listGeoRadiusResponseCommandObject)).thenReturn(expectedResponses); + + List result = jedis.georadius(key, longitude, latitude, radius, unit); + + assertThat(result, equalTo(expectedResponses)); + + verify(commandExecutor).executeCommand(listGeoRadiusResponseCommandObject); + verify(commandObjects).georadius(key, longitude, latitude, radius, unit); + } + + @Test + public void testGeoradiusBinary() { + byte[] key = "cities".getBytes(); + double longitude = 15.087269; + double latitude = 37.502669; + double radius = 100; + GeoUnit unit = GeoUnit.KM; + List expectedResponses = new ArrayList<>(); + expectedResponses.add(new GeoRadiusResponse("Palermo".getBytes())); + + when(commandObjects.georadius(key, longitude, latitude, radius, unit)).thenReturn(listGeoRadiusResponseCommandObject); + when(commandExecutor.executeCommand(listGeoRadiusResponseCommandObject)).thenReturn(expectedResponses); + + List result = jedis.georadius(key, longitude, latitude, radius, unit); + + assertThat(result, equalTo(expectedResponses)); + + verify(commandExecutor).executeCommand(listGeoRadiusResponseCommandObject); + verify(commandObjects).georadius(key, longitude, latitude, radius, unit); + } + + @Test + public void testGeoradiusReadonly() { + String key = "cities"; + double longitude = 15.087269; + double latitude = 37.502669; + double radius = 100; + GeoUnit unit = GeoUnit.KM; + List expectedResponses = new ArrayList<>(); + expectedResponses.add(new GeoRadiusResponse("Palermo".getBytes())); + + when(commandObjects.georadiusReadonly(key, longitude, latitude, radius, unit)).thenReturn(listGeoRadiusResponseCommandObject); + when(commandExecutor.executeCommand(listGeoRadiusResponseCommandObject)).thenReturn(expectedResponses); + + List result = jedis.georadiusReadonly(key, longitude, latitude, radius, unit); + + assertThat(result, equalTo(expectedResponses)); + + verify(commandExecutor).executeCommand(listGeoRadiusResponseCommandObject); + verify(commandObjects).georadiusReadonly(key, longitude, latitude, radius, unit); + } + + @Test + public void testGeoradiusReadonlyBinary() { + byte[] key = "cities".getBytes(); + double longitude = 15.087269; + double latitude = 37.502669; + double radius = 100; + GeoUnit unit = GeoUnit.KM; + List expectedResponses = new ArrayList<>(); + expectedResponses.add(new GeoRadiusResponse("Palermo".getBytes())); + + when(commandObjects.georadiusReadonly(key, longitude, latitude, radius, unit)).thenReturn(listGeoRadiusResponseCommandObject); + when(commandExecutor.executeCommand(listGeoRadiusResponseCommandObject)).thenReturn(expectedResponses); + + List result = jedis.georadiusReadonly(key, longitude, latitude, radius, unit); + + assertThat(result, equalTo(expectedResponses)); + + verify(commandExecutor).executeCommand(listGeoRadiusResponseCommandObject); + verify(commandObjects).georadiusReadonly(key, longitude, latitude, radius, unit); + } + + @Test + public void testGeoradiusWithParam() { + String key = "cities"; + double longitude = 15.087269; + double latitude = 37.502669; + double radius = 100; + GeoUnit unit = GeoUnit.KM; + GeoRadiusParam param = GeoRadiusParam.geoRadiusParam().withDist(); + List expectedResponses = new ArrayList<>(); + expectedResponses.add(new GeoRadiusResponse("Palermo".getBytes())); + + when(commandObjects.georadius(key, longitude, latitude, radius, unit, param)).thenReturn(listGeoRadiusResponseCommandObject); + when(commandExecutor.executeCommand(listGeoRadiusResponseCommandObject)).thenReturn(expectedResponses); + + List result = jedis.georadius(key, longitude, latitude, radius, unit, param); + + assertThat(result, equalTo(expectedResponses)); + + verify(commandExecutor).executeCommand(listGeoRadiusResponseCommandObject); + verify(commandObjects).georadius(key, longitude, latitude, radius, unit, param); + } + + @Test + public void testGeoradiusWithParamBinary() { + byte[] key = "cities".getBytes(); + double longitude = 15.087269; + double latitude = 37.502669; + double radius = 100; + GeoUnit unit = GeoUnit.KM; + GeoRadiusParam param = GeoRadiusParam.geoRadiusParam().withDist(); + List expectedResponses = new ArrayList<>(); + expectedResponses.add(new GeoRadiusResponse("Palermo".getBytes())); + + when(commandObjects.georadius(key, longitude, latitude, radius, unit, param)).thenReturn(listGeoRadiusResponseCommandObject); + when(commandExecutor.executeCommand(listGeoRadiusResponseCommandObject)).thenReturn(expectedResponses); + + List result = jedis.georadius(key, longitude, latitude, radius, unit, param); + + assertThat(result, equalTo(expectedResponses)); + + verify(commandExecutor).executeCommand(listGeoRadiusResponseCommandObject); + verify(commandObjects).georadius(key, longitude, latitude, radius, unit, param); + } + + @Test + public void testGeoradiusReadonlyWithParam() { + String key = "cities"; + double longitude = 15.087269; + double latitude = 37.502669; + double radius = 100; + GeoUnit unit = GeoUnit.KM; + GeoRadiusParam param = GeoRadiusParam.geoRadiusParam().withDist(); + List expectedResponses = new ArrayList<>(); + expectedResponses.add(new GeoRadiusResponse("Palermo".getBytes())); + + when(commandObjects.georadiusReadonly(key, longitude, latitude, radius, unit, param)).thenReturn(listGeoRadiusResponseCommandObject); + when(commandExecutor.executeCommand(listGeoRadiusResponseCommandObject)).thenReturn(expectedResponses); + + List result = jedis.georadiusReadonly(key, longitude, latitude, radius, unit, param); + + assertThat(result, equalTo(expectedResponses)); + + verify(commandExecutor).executeCommand(listGeoRadiusResponseCommandObject); + verify(commandObjects).georadiusReadonly(key, longitude, latitude, radius, unit, param); + } + + @Test + public void testGeoradiusReadonlyWithParamBinary() { + byte[] key = "cities".getBytes(); + double longitude = 15.087269; + double latitude = 37.502669; + double radius = 100; + GeoUnit unit = GeoUnit.KM; + GeoRadiusParam param = GeoRadiusParam.geoRadiusParam().withDist(); + List expectedResponses = new ArrayList<>(); + expectedResponses.add(new GeoRadiusResponse("Palermo".getBytes())); + + when(commandObjects.georadiusReadonly(key, longitude, latitude, radius, unit, param)).thenReturn(listGeoRadiusResponseCommandObject); + when(commandExecutor.executeCommand(listGeoRadiusResponseCommandObject)).thenReturn(expectedResponses); + + List result = jedis.georadiusReadonly(key, longitude, latitude, radius, unit, param); + + assertThat(result, equalTo(expectedResponses)); + + verify(commandExecutor).executeCommand(listGeoRadiusResponseCommandObject); + verify(commandObjects).georadiusReadonly(key, longitude, latitude, radius, unit, param); + } + + @Test + public void testGeoradiusByMember() { + String key = "cities"; + String member = "Catania"; + double radius = 100; + GeoUnit unit = GeoUnit.KM; + List expectedResponses = new ArrayList<>(); + expectedResponses.add(new GeoRadiusResponse("Palermo".getBytes())); + + when(commandObjects.georadiusByMember(key, member, radius, unit)).thenReturn(listGeoRadiusResponseCommandObject); + when(commandExecutor.executeCommand(listGeoRadiusResponseCommandObject)).thenReturn(expectedResponses); + + List result = jedis.georadiusByMember(key, member, radius, unit); + + assertThat(result, equalTo(expectedResponses)); + + verify(commandExecutor).executeCommand(listGeoRadiusResponseCommandObject); + verify(commandObjects).georadiusByMember(key, member, radius, unit); + } + + @Test + public void testGeoradiusByMemberBinary() { + byte[] key = "cities".getBytes(); + byte[] member = "Catania".getBytes(); + double radius = 100; + GeoUnit unit = GeoUnit.KM; + List expectedResponses = new ArrayList<>(); + expectedResponses.add(new GeoRadiusResponse("Palermo".getBytes())); + + when(commandObjects.georadiusByMember(key, member, radius, unit)).thenReturn(listGeoRadiusResponseCommandObject); + when(commandExecutor.executeCommand(listGeoRadiusResponseCommandObject)).thenReturn(expectedResponses); + + List result = jedis.georadiusByMember(key, member, radius, unit); + + assertThat(result, equalTo(expectedResponses)); + + verify(commandExecutor).executeCommand(listGeoRadiusResponseCommandObject); + verify(commandObjects).georadiusByMember(key, member, radius, unit); + } + + @Test + public void testGeoradiusByMemberReadonly() { + String key = "cities"; + String member = "Catania"; + double radius = 100; + GeoUnit unit = GeoUnit.KM; + List expectedResponses = new ArrayList<>(); + expectedResponses.add(new GeoRadiusResponse("Palermo".getBytes())); + + when(commandObjects.georadiusByMemberReadonly(key, member, radius, unit)).thenReturn(listGeoRadiusResponseCommandObject); + when(commandExecutor.executeCommand(listGeoRadiusResponseCommandObject)).thenReturn(expectedResponses); + + List result = jedis.georadiusByMemberReadonly(key, member, radius, unit); + + assertThat(result, equalTo(expectedResponses)); + + verify(commandExecutor).executeCommand(listGeoRadiusResponseCommandObject); + verify(commandObjects).georadiusByMemberReadonly(key, member, radius, unit); + } + + @Test + public void testGeoradiusByMemberReadonlyBinary() { + byte[] key = "cities".getBytes(); + byte[] member = "Catania".getBytes(); + double radius = 100; + GeoUnit unit = GeoUnit.KM; + List expectedResponses = new ArrayList<>(); + expectedResponses.add(new GeoRadiusResponse("Palermo".getBytes())); + + when(commandObjects.georadiusByMemberReadonly(key, member, radius, unit)).thenReturn(listGeoRadiusResponseCommandObject); + when(commandExecutor.executeCommand(listGeoRadiusResponseCommandObject)).thenReturn(expectedResponses); + + List result = jedis.georadiusByMemberReadonly(key, member, radius, unit); + + assertThat(result, equalTo(expectedResponses)); + + verify(commandExecutor).executeCommand(listGeoRadiusResponseCommandObject); + verify(commandObjects).georadiusByMemberReadonly(key, member, radius, unit); + } + + @Test + public void testGeoradiusByMemberWithParam() { + String key = "cities"; + String member = "Catania"; + double radius = 100; + GeoUnit unit = GeoUnit.KM; + GeoRadiusParam param = GeoRadiusParam.geoRadiusParam().withDist(); + List expectedResponses = new ArrayList<>(); + expectedResponses.add(new GeoRadiusResponse("Palermo".getBytes())); + + when(commandObjects.georadiusByMember(key, member, radius, unit, param)).thenReturn(listGeoRadiusResponseCommandObject); + when(commandExecutor.executeCommand(listGeoRadiusResponseCommandObject)).thenReturn(expectedResponses); + + List result = jedis.georadiusByMember(key, member, radius, unit, param); + + assertThat(result, equalTo(expectedResponses)); + + verify(commandExecutor).executeCommand(listGeoRadiusResponseCommandObject); + verify(commandObjects).georadiusByMember(key, member, radius, unit, param); + } + + @Test + public void testGeoradiusByMemberWithParamBinary() { + byte[] key = "cities".getBytes(); + byte[] member = "Catania".getBytes(); + double radius = 100; + GeoUnit unit = GeoUnit.KM; + GeoRadiusParam param = GeoRadiusParam.geoRadiusParam().withDist(); + List expectedResponses = new ArrayList<>(); + expectedResponses.add(new GeoRadiusResponse("Palermo".getBytes())); + + when(commandObjects.georadiusByMember(key, member, radius, unit, param)).thenReturn(listGeoRadiusResponseCommandObject); + when(commandExecutor.executeCommand(listGeoRadiusResponseCommandObject)).thenReturn(expectedResponses); + + List result = jedis.georadiusByMember(key, member, radius, unit, param); + + assertThat(result, equalTo(expectedResponses)); + + verify(commandExecutor).executeCommand(listGeoRadiusResponseCommandObject); + verify(commandObjects).georadiusByMember(key, member, radius, unit, param); + } + + @Test + public void testGeoradiusByMemberReadonlyWithParam() { + String key = "cities"; + String member = "Catania"; + double radius = 100; + GeoUnit unit = GeoUnit.KM; + GeoRadiusParam param = GeoRadiusParam.geoRadiusParam().withDist(); + List expectedResponses = new ArrayList<>(); + expectedResponses.add(new GeoRadiusResponse("Palermo".getBytes())); + + when(commandObjects.georadiusByMemberReadonly(key, member, radius, unit, param)).thenReturn(listGeoRadiusResponseCommandObject); + when(commandExecutor.executeCommand(listGeoRadiusResponseCommandObject)).thenReturn(expectedResponses); + + List result = jedis.georadiusByMemberReadonly(key, member, radius, unit, param); + + assertThat(result, equalTo(expectedResponses)); + + verify(commandExecutor).executeCommand(listGeoRadiusResponseCommandObject); + verify(commandObjects).georadiusByMemberReadonly(key, member, radius, unit, param); + } + + @Test + public void testGeoradiusByMemberReadonlyWithParamBinary() { + byte[] key = "cities".getBytes(); + byte[] member = "Catania".getBytes(); + double radius = 100; + GeoUnit unit = GeoUnit.KM; + GeoRadiusParam param = GeoRadiusParam.geoRadiusParam().withDist(); + List expectedResponses = new ArrayList<>(); + expectedResponses.add(new GeoRadiusResponse("Palermo".getBytes())); + + when(commandObjects.georadiusByMemberReadonly(key, member, radius, unit, param)).thenReturn(listGeoRadiusResponseCommandObject); + when(commandExecutor.executeCommand(listGeoRadiusResponseCommandObject)).thenReturn(expectedResponses); + + List result = jedis.georadiusByMemberReadonly(key, member, radius, unit, param); + + assertThat(result, equalTo(expectedResponses)); + + verify(commandExecutor).executeCommand(listGeoRadiusResponseCommandObject); + verify(commandObjects).georadiusByMemberReadonly(key, member, radius, unit, param); + } + + @Test + public void testGeoradiusStore() { + String key = "cities"; + double longitude = 15.087269; + double latitude = 37.502669; + double radius = 100; + GeoUnit unit = GeoUnit.KM; + GeoRadiusParam param = GeoRadiusParam.geoRadiusParam().withDist(); + GeoRadiusStoreParam storeParam = GeoRadiusStoreParam.geoRadiusStoreParam(); + long expectedStored = 2L; + + when(commandObjects.georadiusStore(key, longitude, latitude, radius, unit, param, storeParam)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedStored); + + long result = jedis.georadiusStore(key, longitude, latitude, radius, unit, param, storeParam); + + assertThat(result, equalTo(expectedStored)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).georadiusStore(key, longitude, latitude, radius, unit, param, storeParam); + } + + @Test + public void testGeoradiusStoreBinary() { + byte[] key = "cities".getBytes(); + double longitude = 15.087269; + double latitude = 37.502669; + double radius = 100; + GeoUnit unit = GeoUnit.KM; + GeoRadiusParam param = GeoRadiusParam.geoRadiusParam().withDist(); + GeoRadiusStoreParam storeParam = GeoRadiusStoreParam.geoRadiusStoreParam(); + long expectedStored = 2L; + + when(commandObjects.georadiusStore(key, longitude, latitude, radius, unit, param, storeParam)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedStored); + + long result = jedis.georadiusStore(key, longitude, latitude, radius, unit, param, storeParam); + + assertThat(result, equalTo(expectedStored)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).georadiusStore(key, longitude, latitude, radius, unit, param, storeParam); + } + + @Test + public void testGeoradiusByMemberStore() { + String key = "cities"; + String member = "Catania"; + double radius = 100; + GeoUnit unit = GeoUnit.KM; + GeoRadiusParam param = GeoRadiusParam.geoRadiusParam().withDist(); + GeoRadiusStoreParam storeParam = GeoRadiusStoreParam.geoRadiusStoreParam(); + long expectedStored = 2L; + + when(commandObjects.georadiusByMemberStore(key, member, radius, unit, param, storeParam)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedStored); + + long result = jedis.georadiusByMemberStore(key, member, radius, unit, param, storeParam); + + assertThat(result, equalTo(expectedStored)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).georadiusByMemberStore(key, member, radius, unit, param, storeParam); + } + + @Test + public void testGeoradiusByMemberStoreBinary() { + byte[] key = "cities".getBytes(); + byte[] member = "Catania".getBytes(); + double radius = 100; + GeoUnit unit = GeoUnit.KM; + GeoRadiusParam param = GeoRadiusParam.geoRadiusParam().withDist(); + GeoRadiusStoreParam storeParam = GeoRadiusStoreParam.geoRadiusStoreParam(); + long expectedStored = 2L; + + when(commandObjects.georadiusByMemberStore(key, member, radius, unit, param, storeParam)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedStored); + + long result = jedis.georadiusByMemberStore(key, member, radius, unit, param, storeParam); + + assertThat(result, equalTo(expectedStored)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).georadiusByMemberStore(key, member, radius, unit, param, storeParam); + } + + @Test + public void testGeosearchByMemberRadius() { + String key = "cities"; + String member = "Catania"; + double radius = 100; + GeoUnit unit = GeoUnit.KM; + List expectedResponses = new ArrayList<>(); + expectedResponses.add(new GeoRadiusResponse("Palermo".getBytes())); + + when(commandObjects.geosearch(key, member, radius, unit)).thenReturn(listGeoRadiusResponseCommandObject); + when(commandExecutor.executeCommand(listGeoRadiusResponseCommandObject)).thenReturn(expectedResponses); + + List result = jedis.geosearch(key, member, radius, unit); + + assertThat(result, equalTo(expectedResponses)); + + verify(commandExecutor).executeCommand(listGeoRadiusResponseCommandObject); + verify(commandObjects).geosearch(key, member, radius, unit); + } + + @Test + public void testGeosearchByMemberRadiusBinary() { + byte[] key = "cities".getBytes(); + byte[] member = "Catania".getBytes(); + double radius = 100; + GeoUnit unit = GeoUnit.KM; + List expectedResponses = new ArrayList<>(); + expectedResponses.add(new GeoRadiusResponse("Palermo".getBytes())); + + when(commandObjects.geosearch(key, member, radius, unit)).thenReturn(listGeoRadiusResponseCommandObject); + when(commandExecutor.executeCommand(listGeoRadiusResponseCommandObject)).thenReturn(expectedResponses); + + List result = jedis.geosearch(key, member, radius, unit); + + assertThat(result, equalTo(expectedResponses)); + + verify(commandExecutor).executeCommand(listGeoRadiusResponseCommandObject); + verify(commandObjects).geosearch(key, member, radius, unit); + } + + @Test + public void testGeosearchKeyCoordRadius() { + String key = "cities"; + GeoCoordinate coord = new GeoCoordinate(15.087269, 37.502669); + double radius = 100; + GeoUnit unit = GeoUnit.KM; + List expectedResponses = new ArrayList<>(); + expectedResponses.add(new GeoRadiusResponse("Palermo".getBytes())); + + when(commandObjects.geosearch(key, coord, radius, unit)).thenReturn(listGeoRadiusResponseCommandObject); + when(commandExecutor.executeCommand(listGeoRadiusResponseCommandObject)).thenReturn(expectedResponses); + + List result = jedis.geosearch(key, coord, radius, unit); + + assertThat(result, equalTo(expectedResponses)); + + verify(commandExecutor).executeCommand(listGeoRadiusResponseCommandObject); + verify(commandObjects).geosearch(key, coord, radius, unit); + } + + @Test + public void testGeosearchKeyCoordRadiusBinary() { + byte[] key = "cities".getBytes(); + GeoCoordinate coord = new GeoCoordinate(15.087269, 37.502669); + double radius = 100; + GeoUnit unit = GeoUnit.KM; + List expectedResponses = new ArrayList<>(); + expectedResponses.add(new GeoRadiusResponse("Palermo".getBytes())); + + when(commandObjects.geosearch(key, coord, radius, unit)).thenReturn(listGeoRadiusResponseCommandObject); + when(commandExecutor.executeCommand(listGeoRadiusResponseCommandObject)).thenReturn(expectedResponses); + + List result = jedis.geosearch(key, coord, radius, unit); + + assertThat(result, equalTo(expectedResponses)); + + verify(commandExecutor).executeCommand(listGeoRadiusResponseCommandObject); + verify(commandObjects).geosearch(key, coord, radius, unit); + } + + @Test + public void testGeosearchByMemberBox() { + String key = "cities"; + String member = "Catania"; + double width = 100; + double height = 200; + GeoUnit unit = GeoUnit.KM; + List expectedResponses = new ArrayList<>(); + expectedResponses.add(new GeoRadiusResponse("Palermo".getBytes())); + + when(commandObjects.geosearch(key, member, width, height, unit)).thenReturn(listGeoRadiusResponseCommandObject); + when(commandExecutor.executeCommand(listGeoRadiusResponseCommandObject)).thenReturn(expectedResponses); + + List result = jedis.geosearch(key, member, width, height, unit); + + assertThat(result, equalTo(expectedResponses)); + + verify(commandExecutor).executeCommand(listGeoRadiusResponseCommandObject); + verify(commandObjects).geosearch(key, member, width, height, unit); + } + + @Test + public void testGeosearchByMemberBoxBinary() { + byte[] key = "cities".getBytes(); + byte[] member = "Catania".getBytes(); + double width = 150; + double height = 75; + GeoUnit unit = GeoUnit.KM; + List expectedResponses = new ArrayList<>(); + expectedResponses.add(new GeoRadiusResponse("Palermo".getBytes())); + + when(commandObjects.geosearch(key, member, width, height, unit)).thenReturn(listGeoRadiusResponseCommandObject); + when(commandExecutor.executeCommand(listGeoRadiusResponseCommandObject)).thenReturn(expectedResponses); + + List result = jedis.geosearch(key, member, width, height, unit); + + assertThat(result, equalTo(expectedResponses)); + + verify(commandExecutor).executeCommand(listGeoRadiusResponseCommandObject); + verify(commandObjects).geosearch(key, member, width, height, unit); + } + + @Test + public void testGeosearchByCoordBox() { + String key = "cities"; + GeoCoordinate coord = new GeoCoordinate(15.087269, 37.502669); + double width = 100; + double height = 200; + GeoUnit unit = GeoUnit.KM; + List expectedResponses = new ArrayList<>(); + expectedResponses.add(new GeoRadiusResponse("Palermo".getBytes())); + + when(commandObjects.geosearch(key, coord, width, height, unit)).thenReturn(listGeoRadiusResponseCommandObject); + when(commandExecutor.executeCommand(listGeoRadiusResponseCommandObject)).thenReturn(expectedResponses); + + List result = jedis.geosearch(key, coord, width, height, unit); + + assertThat(result, equalTo(expectedResponses)); + + verify(commandExecutor).executeCommand(listGeoRadiusResponseCommandObject); + verify(commandObjects).geosearch(key, coord, width, height, unit); + } + + @Test + public void testGeosearchByCoordBoxBinary() { + byte[] key = "cities".getBytes(); + GeoCoordinate coord = new GeoCoordinate(15.087269, 37.502669); + double width = 150; + double height = 75; + GeoUnit unit = GeoUnit.KM; + List expectedResponses = new ArrayList<>(); + expectedResponses.add(new GeoRadiusResponse("Palermo".getBytes())); + + when(commandObjects.geosearch(key, coord, width, height, unit)).thenReturn(listGeoRadiusResponseCommandObject); + when(commandExecutor.executeCommand(listGeoRadiusResponseCommandObject)).thenReturn(expectedResponses); + + List result = jedis.geosearch(key, coord, width, height, unit); + + assertThat(result, equalTo(expectedResponses)); + + verify(commandExecutor).executeCommand(listGeoRadiusResponseCommandObject); + verify(commandObjects).geosearch(key, coord, width, height, unit); + } + + @Test + public void testGeosearchWithParams() { + String key = "cities"; + GeoSearchParam params = GeoSearchParam.geoSearchParam().byRadius(100, GeoUnit.KM).withCoord().withDist(); + List expectedResponses = new ArrayList<>(); + expectedResponses.add(new GeoRadiusResponse("Palermo".getBytes())); + + when(commandObjects.geosearch(key, params)).thenReturn(listGeoRadiusResponseCommandObject); + when(commandExecutor.executeCommand(listGeoRadiusResponseCommandObject)).thenReturn(expectedResponses); + + List result = jedis.geosearch(key, params); + + assertThat(result, equalTo(expectedResponses)); + + verify(commandExecutor).executeCommand(listGeoRadiusResponseCommandObject); + verify(commandObjects).geosearch(key, params); + } + + @Test + public void testGeosearchWithParamsBinary() { + byte[] key = "cities".getBytes(); + GeoSearchParam params = GeoSearchParam.geoSearchParam().byRadius(100, GeoUnit.KM).withCoord().withDist(); + List expectedResponses = new ArrayList<>(); + expectedResponses.add(new GeoRadiusResponse("Palermo".getBytes())); + + when(commandObjects.geosearch(key, params)).thenReturn(listGeoRadiusResponseCommandObject); + when(commandExecutor.executeCommand(listGeoRadiusResponseCommandObject)).thenReturn(expectedResponses); + + List result = jedis.geosearch(key, params); + + assertThat(result, equalTo(expectedResponses)); + + verify(commandExecutor).executeCommand(listGeoRadiusResponseCommandObject); + verify(commandObjects).geosearch(key, params); + } + + @Test + public void testGeosearchStoreByMemberRadius() { + String dest = "cities_store"; + String src = "cities"; + String member = "Catania"; + double radius = 100; + GeoUnit unit = GeoUnit.KM; + long expectedStored = 2L; + + when(commandObjects.geosearchStore(dest, src, member, radius, unit)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedStored); + + long result = jedis.geosearchStore(dest, src, member, radius, unit); + + assertThat(result, equalTo(expectedStored)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).geosearchStore(dest, src, member, radius, unit); + } + + @Test + public void testGeosearchStoreByMemberRadiusBinary() { + byte[] dest = "cities_store".getBytes(); + byte[] src = "cities".getBytes(); + byte[] member = "Catania".getBytes(); + double radius = 100; + GeoUnit unit = GeoUnit.KM; + long expectedStored = 3L; + + when(commandObjects.geosearchStore(dest, src, member, radius, unit)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedStored); + + long result = jedis.geosearchStore(dest, src, member, radius, unit); + + assertThat(result, equalTo(expectedStored)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).geosearchStore(dest, src, member, radius, unit); + } + + @Test + public void testGeosearchStoreByCoordRadius() { + String dest = "cities_store"; + String src = "cities"; + GeoCoordinate coord = new GeoCoordinate(15.087269, 37.502669); + double radius = 100; + GeoUnit unit = GeoUnit.KM; + long expectedStored = 2L; + + when(commandObjects.geosearchStore(dest, src, coord, radius, unit)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedStored); + + long result = jedis.geosearchStore(dest, src, coord, radius, unit); + + assertThat(result, equalTo(expectedStored)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).geosearchStore(dest, src, coord, radius, unit); + } + + @Test + public void testGeosearchStoreByCoordRadiusBinary() { + byte[] dest = "cities_store".getBytes(); + byte[] src = "cities".getBytes(); + GeoCoordinate coord = new GeoCoordinate(15.087269, 37.502669); + double radius = 100; + GeoUnit unit = GeoUnit.KM; + long expectedStored = 3L; + + when(commandObjects.geosearchStore(dest, src, coord, radius, unit)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedStored); + + long result = jedis.geosearchStore(dest, src, coord, radius, unit); + + assertThat(result, equalTo(expectedStored)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).geosearchStore(dest, src, coord, radius, unit); + } + + @Test + public void testGeosearchStoreByMemberBox() { + String dest = "cities_store"; + String src = "cities"; + String member = "Catania"; + double width = 150; + double height = 75; + GeoUnit unit = GeoUnit.KM; + long expectedStored = 3L; + + when(commandObjects.geosearchStore(dest, src, member, width, height, unit)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedStored); + + long result = jedis.geosearchStore(dest, src, member, width, height, unit); + + assertThat(result, equalTo(expectedStored)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).geosearchStore(dest, src, member, width, height, unit); + } + + @Test + public void testGeosearchStoreByMemberBoxBinary() { + byte[] dest = "cities_store".getBytes(); + byte[] src = "cities".getBytes(); + byte[] member = "Catania".getBytes(); + double width = 150; + double height = 75; + GeoUnit unit = GeoUnit.KM; + long expectedStored = 3L; + + when(commandObjects.geosearchStore(dest, src, member, width, height, unit)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedStored); + + long result = jedis.geosearchStore(dest, src, member, width, height, unit); + + assertThat(result, equalTo(expectedStored)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).geosearchStore(dest, src, member, width, height, unit); + } + + @Test + public void testGeosearchStoreByCoordBox() { + String dest = "cities_store"; + String src = "cities"; + GeoCoordinate coord = new GeoCoordinate(15.087269, 37.502669); + double width = 150; + double height = 75; + GeoUnit unit = GeoUnit.KM; + long expectedStored = 3L; + + when(commandObjects.geosearchStore(dest, src, coord, width, height, unit)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedStored); + + long result = jedis.geosearchStore(dest, src, coord, width, height, unit); + + assertThat(result, equalTo(expectedStored)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).geosearchStore(dest, src, coord, width, height, unit); + } + + @Test + public void testGeosearchStoreByCoordBoxBinary() { + byte[] dest = "cities_store".getBytes(); + byte[] src = "cities".getBytes(); + GeoCoordinate coord = new GeoCoordinate(15.087269, 37.502669); + double width = 150; + double height = 75; + GeoUnit unit = GeoUnit.KM; + long expectedStored = 3L; + + when(commandObjects.geosearchStore(dest, src, coord, width, height, unit)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedStored); + + long result = jedis.geosearchStore(dest, src, coord, width, height, unit); + + assertThat(result, equalTo(expectedStored)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).geosearchStore(dest, src, coord, width, height, unit); + } + + @Test + public void testGeosearchStoreWithParams() { + String dest = "cities_store"; + String src = "cities"; + GeoSearchParam params = GeoSearchParam.geoSearchParam().byRadius(100, GeoUnit.KM).withCoord().withDist(); + long expectedStored = 3L; + + when(commandObjects.geosearchStore(dest, src, params)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedStored); + + long result = jedis.geosearchStore(dest, src, params); + + assertThat(result, equalTo(expectedStored)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).geosearchStore(dest, src, params); + } + + @Test + public void testGeosearchStoreWithParamsBinary() { + byte[] dest = "cities_store".getBytes(); + byte[] src = "cities".getBytes(); + GeoSearchParam params = GeoSearchParam.geoSearchParam().byRadius(100, GeoUnit.KM).withCoord().withDist(); + long expectedStored = 3L; + + when(commandObjects.geosearchStore(dest, src, params)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedStored); + + long result = jedis.geosearchStore(dest, src, params); + + assertThat(result, equalTo(expectedStored)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).geosearchStore(dest, src, params); + } + + @Test + public void testGeosearchStoreStoreDist() { + String dest = "cities_store"; + String src = "cities"; + GeoSearchParam params = GeoSearchParam.geoSearchParam().byRadius(100, GeoUnit.KM).withCoord().withDist(); + long expectedStoredDist = 3L; + + when(commandObjects.geosearchStoreStoreDist(dest, src, params)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedStoredDist); + + long result = jedis.geosearchStoreStoreDist(dest, src, params); + + assertThat(result, equalTo(expectedStoredDist)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).geosearchStoreStoreDist(dest, src, params); + } + + @Test + public void testGeosearchStoreStoreDistBinary() { + byte[] dest = "cities_store".getBytes(); + byte[] src = "cities".getBytes(); + GeoSearchParam params = GeoSearchParam.geoSearchParam().byRadius(100, GeoUnit.KM).withCoord().withDist(); + long expectedStoredDist = 3L; + + when(commandObjects.geosearchStoreStoreDist(dest, src, params)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedStoredDist); + + long result = jedis.geosearchStoreStoreDist(dest, src, params); + + assertThat(result, equalTo(expectedStoredDist)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).geosearchStoreStoreDist(dest, src, params); + } + +} diff --git a/src/test/java/redis/clients/jedis/mocked/unified/UnifiedJedisHashCommandsTest.java b/src/test/java/redis/clients/jedis/mocked/unified/UnifiedJedisHashCommandsTest.java new file mode 100644 index 00000000000..c867e4d3e51 --- /dev/null +++ b/src/test/java/redis/clients/jedis/mocked/unified/UnifiedJedisHashCommandsTest.java @@ -0,0 +1,767 @@ +package redis.clients.jedis.mocked.unified; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.equalTo; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import java.util.AbstractMap; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import org.junit.Test; +import redis.clients.jedis.params.ScanParams; +import redis.clients.jedis.resps.ScanResult; + +public class UnifiedJedisHashCommandsTest extends UnifiedJedisMockedTestBase { + + @Test + public void testHdel() { + String key = "hashKey"; + String[] fields = { "field1", "field2" }; + long expected = 2L; + + when(commandObjects.hdel(key, fields)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expected); + + long result = jedis.hdel(key, fields); + + assertThat(result, equalTo(expected)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).hdel(key, fields); + } + + @Test + public void testHdelBinary() { + byte[] key = "hashKey".getBytes(); + byte[][] fields = { "field1".getBytes(), "field2".getBytes() }; + long expected = 2L; // Assuming both fields were deleted + + when(commandObjects.hdel(key, fields)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expected); + + long result = jedis.hdel(key, fields); + + assertThat(result, equalTo(expected)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).hdel(key, fields); + } + + @Test + public void testHexists() { + String key = "hashKey"; + String field = "field1"; + boolean expected = true; + + when(commandObjects.hexists(key, field)).thenReturn(booleanCommandObject); + when(commandExecutor.executeCommand(booleanCommandObject)).thenReturn(expected); + + boolean result = jedis.hexists(key, field); + + assertThat(result, equalTo(expected)); + + verify(commandExecutor).executeCommand(booleanCommandObject); + verify(commandObjects).hexists(key, field); + } + + @Test + public void testHexistsBinary() { + byte[] key = "hashKey".getBytes(); + byte[] field = "field1".getBytes(); + boolean expected = true; + + when(commandObjects.hexists(key, field)).thenReturn(booleanCommandObject); + when(commandExecutor.executeCommand(booleanCommandObject)).thenReturn(expected); + + boolean result = jedis.hexists(key, field); + + assertThat(result, equalTo(expected)); + + verify(commandExecutor).executeCommand(booleanCommandObject); + verify(commandObjects).hexists(key, field); + } + + @Test + public void testHget() { + String key = "hashKey"; + String field = "field1"; + String expectedValue = "value1"; + + when(commandObjects.hget(key, field)).thenReturn(stringCommandObject); + when(commandExecutor.executeCommand(stringCommandObject)).thenReturn(expectedValue); + + String result = jedis.hget(key, field); + + assertThat(result, equalTo(expectedValue)); + + verify(commandExecutor).executeCommand(stringCommandObject); + verify(commandObjects).hget(key, field); + } + + @Test + public void testHgetBinary() { + byte[] key = "hashKey".getBytes(); + byte[] field = "field1".getBytes(); + byte[] expectedValue = "value1".getBytes(); + + when(commandObjects.hget(key, field)).thenReturn(bytesCommandObject); + when(commandExecutor.executeCommand(bytesCommandObject)).thenReturn(expectedValue); + + byte[] result = jedis.hget(key, field); + + assertThat(result, equalTo(expectedValue)); + + verify(commandExecutor).executeCommand(bytesCommandObject); + verify(commandObjects).hget(key, field); + } + + @Test + public void testHgetAll() { + String key = "hashKey"; + Map expectedMap = new HashMap<>(); + expectedMap.put("field1", "value1"); + expectedMap.put("field2", "value2"); + + when(commandObjects.hgetAll(key)).thenReturn(mapStringStringCommandObject); + when(commandExecutor.executeCommand(mapStringStringCommandObject)).thenReturn(expectedMap); + + Map result = jedis.hgetAll(key); + + assertThat(result, equalTo(expectedMap)); + + verify(commandExecutor).executeCommand(mapStringStringCommandObject); + verify(commandObjects).hgetAll(key); + } + + @Test + public void testHgetAllBinary() { + byte[] key = "hashKey".getBytes(); + Map expectedMap = new HashMap<>(); + expectedMap.put("field1".getBytes(), "value1".getBytes()); + expectedMap.put("field2".getBytes(), "value2".getBytes()); + + when(commandObjects.hgetAll(key)).thenReturn(mapBytesBytesCommandObject); + when(commandExecutor.executeCommand(mapBytesBytesCommandObject)).thenReturn(expectedMap); + + Map result = jedis.hgetAll(key); + + assertThat(result, equalTo(expectedMap)); + + verify(commandExecutor).executeCommand(mapBytesBytesCommandObject); + verify(commandObjects).hgetAll(key); + } + + @Test + public void testHincrBy() { + String key = "hashKey"; + String field = "field1"; + long increment = 2L; + long expectedValue = 5L; // Assuming the original value was 3 + + when(commandObjects.hincrBy(key, field, increment)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedValue); + + long result = jedis.hincrBy(key, field, increment); + + assertThat(result, equalTo(expectedValue)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).hincrBy(key, field, increment); + } + + @Test + public void testHincrByBinary() { + byte[] key = "hashKey".getBytes(); + byte[] field = "field1".getBytes(); + long increment = 2L; + long expectedValue = 5L; // Assuming the original value was 3 + + when(commandObjects.hincrBy(key, field, increment)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedValue); + + long result = jedis.hincrBy(key, field, increment); + + assertThat(result, equalTo(expectedValue)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).hincrBy(key, field, increment); + } + + @Test + public void testHincrByFloat() { + String key = "hashKey"; + String field = "field1"; + double increment = 1.5; + double expectedValue = 4.5; // Assuming the original value was 3.0 + + when(commandObjects.hincrByFloat(key, field, increment)).thenReturn(doubleCommandObject); + when(commandExecutor.executeCommand(doubleCommandObject)).thenReturn(expectedValue); + + double result = jedis.hincrByFloat(key, field, increment); + + assertThat(result, equalTo(expectedValue)); + + verify(commandExecutor).executeCommand(doubleCommandObject); + verify(commandObjects).hincrByFloat(key, field, increment); + } + + @Test + public void testHincrByFloatBinary() { + byte[] key = "hashKey".getBytes(); + byte[] field = "field1".getBytes(); + double increment = 1.5; + double expectedValue = 4.5; // Assuming the original value was 3.0 + + when(commandObjects.hincrByFloat(key, field, increment)).thenReturn(doubleCommandObject); + when(commandExecutor.executeCommand(doubleCommandObject)).thenReturn(expectedValue); + + double result = jedis.hincrByFloat(key, field, increment); + + assertThat(result, equalTo(expectedValue)); + + verify(commandExecutor).executeCommand(doubleCommandObject); + verify(commandObjects).hincrByFloat(key, field, increment); + } + + @Test + public void testHkeys() { + String key = "hashKey"; + Set expectedKeys = new HashSet<>(Arrays.asList("field1", "field2", "field3")); + + when(commandObjects.hkeys(key)).thenReturn(setStringCommandObject); + when(commandExecutor.executeCommand(setStringCommandObject)).thenReturn(expectedKeys); + + Set result = jedis.hkeys(key); + + assertThat(result, equalTo(expectedKeys)); + + verify(commandExecutor).executeCommand(setStringCommandObject); + verify(commandObjects).hkeys(key); + } + + @Test + public void testHkeysBinary() { + byte[] key = "hashKey".getBytes(); + Set expectedKeys = new HashSet<>(Arrays.asList("field1".getBytes(), "field2".getBytes(), "field3".getBytes())); + + when(commandObjects.hkeys(key)).thenReturn(setBytesCommandObject); + when(commandExecutor.executeCommand(setBytesCommandObject)).thenReturn(expectedKeys); + + Set result = jedis.hkeys(key); + + assertThat(result, equalTo(expectedKeys)); + + verify(commandExecutor).executeCommand(setBytesCommandObject); + verify(commandObjects).hkeys(key); + } + + @Test + public void testHlen() { + String key = "hashKey"; + long expected = 3L; // Assuming there are 3 fields in the hash + + when(commandObjects.hlen(key)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expected); + + long result = jedis.hlen(key); + + assertThat(result, equalTo(expected)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).hlen(key); + } + + @Test + public void testHlenBinary() { + byte[] key = "hashKey".getBytes(); + long expected = 3L; // Assuming there are 3 fields in the hash + + when(commandObjects.hlen(key)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expected); + + long result = jedis.hlen(key); + + assertThat(result, equalTo(expected)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).hlen(key); + } + + @Test + public void testHmget() { + String key = "hashKey"; + String[] fields = { "field1", "field2" }; + List expectedValues = Arrays.asList("value1", "value2"); + + when(commandObjects.hmget(key, fields)).thenReturn(listStringCommandObject); + when(commandExecutor.executeCommand(listStringCommandObject)).thenReturn(expectedValues); + + List result = jedis.hmget(key, fields); + + assertThat(result, equalTo(expectedValues)); + + verify(commandExecutor).executeCommand(listStringCommandObject); + verify(commandObjects).hmget(key, fields); + } + + @Test + public void testHmgetBinary() { + byte[] key = "hashKey".getBytes(); + byte[][] fields = { "field1".getBytes(), "field2".getBytes() }; + List expectedValues = Arrays.asList("value1".getBytes(), "value2".getBytes()); + + when(commandObjects.hmget(key, fields)).thenReturn(listBytesCommandObject); + when(commandExecutor.executeCommand(listBytesCommandObject)).thenReturn(expectedValues); + + List result = jedis.hmget(key, fields); + + assertThat(result, equalTo(expectedValues)); + + verify(commandExecutor).executeCommand(listBytesCommandObject); + verify(commandObjects).hmget(key, fields); + } + + @Test + public void testHmset() { + String key = "hashKey"; + Map hash = new HashMap<>(); + hash.put("field1", "value1"); + hash.put("field2", "value2"); + String expectedStatus = "OK"; + + when(commandObjects.hmset(key, hash)).thenReturn(stringCommandObject); + when(commandExecutor.executeCommand(stringCommandObject)).thenReturn(expectedStatus); + + String result = jedis.hmset(key, hash); + + assertThat(result, equalTo(expectedStatus)); + + verify(commandExecutor).executeCommand(stringCommandObject); + verify(commandObjects).hmset(key, hash); + } + + @Test + public void testHmsetBinary() { + byte[] key = "hashKey".getBytes(); + Map hash = new HashMap<>(); + hash.put("field1".getBytes(), "value1".getBytes()); + hash.put("field2".getBytes(), "value2".getBytes()); + String expectedStatus = "OK"; + + when(commandObjects.hmset(key, hash)).thenReturn(stringCommandObject); + when(commandExecutor.executeCommand(stringCommandObject)).thenReturn(expectedStatus); + + String result = jedis.hmset(key, hash); + + assertThat(result, equalTo(expectedStatus)); + + verify(commandExecutor).executeCommand(stringCommandObject); + verify(commandObjects).hmset(key, hash); + } + + @Test + public void testHrandfield() { + String key = "hashKey"; + String expectedField = "field1"; + + when(commandObjects.hrandfield(key)).thenReturn(stringCommandObject); + when(commandExecutor.executeCommand(stringCommandObject)).thenReturn(expectedField); + + String result = jedis.hrandfield(key); + + assertThat(result, equalTo(expectedField)); + + verify(commandExecutor).executeCommand(stringCommandObject); + verify(commandObjects).hrandfield(key); + } + + @Test + public void testHrandfieldBinary() { + byte[] key = "hashKey".getBytes(); + byte[] expectedField = "field1".getBytes(); + + when(commandObjects.hrandfield(key)).thenReturn(bytesCommandObject); + when(commandExecutor.executeCommand(bytesCommandObject)).thenReturn(expectedField); + + byte[] result = jedis.hrandfield(key); + + assertThat(result, equalTo(expectedField)); + + verify(commandExecutor).executeCommand(bytesCommandObject); + verify(commandObjects).hrandfield(key); + } + + @Test + public void testHrandfieldCount() { + String key = "hashKey"; + long count = 2; + List expectedFields = Arrays.asList("field1", "field2"); + + when(commandObjects.hrandfield(key, count)).thenReturn(listStringCommandObject); + when(commandExecutor.executeCommand(listStringCommandObject)).thenReturn(expectedFields); + + List result = jedis.hrandfield(key, count); + + assertThat(result, equalTo(expectedFields)); + + verify(commandExecutor).executeCommand(listStringCommandObject); + verify(commandObjects).hrandfield(key, count); + } + + @Test + public void testHrandfieldCountBinary() { + byte[] key = "hashKey".getBytes(); + long count = 2; + List expectedFields = Arrays.asList("field1".getBytes(), "field2".getBytes()); + + when(commandObjects.hrandfield(key, count)).thenReturn(listBytesCommandObject); + when(commandExecutor.executeCommand(listBytesCommandObject)).thenReturn(expectedFields); + + List result = jedis.hrandfield(key, count); + + assertThat(result, equalTo(expectedFields)); + + verify(commandExecutor).executeCommand(listBytesCommandObject); + verify(commandObjects).hrandfield(key, count); + } + + @Test + public void testHrandfieldWithValues() { + String key = "hashKey"; + long count = 2; + List> expectedEntries = new ArrayList<>(); + expectedEntries.add(new AbstractMap.SimpleEntry<>("field1", "value1")); + expectedEntries.add(new AbstractMap.SimpleEntry<>("field2", "value2")); + + when(commandObjects.hrandfieldWithValues(key, count)).thenReturn(listEntryStringStringCommandObject); + when(commandExecutor.executeCommand(listEntryStringStringCommandObject)).thenReturn(expectedEntries); + + List> result = jedis.hrandfieldWithValues(key, count); + + assertThat(result, equalTo(expectedEntries)); + + verify(commandExecutor).executeCommand(listEntryStringStringCommandObject); + verify(commandObjects).hrandfieldWithValues(key, count); + } + + @Test + public void testHrandfieldWithValuesBinary() { + byte[] key = "hashKey".getBytes(); + long count = 2; + List> expectedEntries = new ArrayList<>(); + + expectedEntries.add(new AbstractMap.SimpleEntry<>("field1".getBytes(), "value1".getBytes())); + expectedEntries.add(new AbstractMap.SimpleEntry<>("field2".getBytes(), "value2".getBytes())); + + when(commandObjects.hrandfieldWithValues(key, count)).thenReturn(listEntryBytesBytesCommandObject); + when(commandExecutor.executeCommand(listEntryBytesBytesCommandObject)).thenReturn(expectedEntries); + + List> result = jedis.hrandfieldWithValues(key, count); + + assertThat(result, equalTo(expectedEntries)); + + verify(commandExecutor).executeCommand(listEntryBytesBytesCommandObject); + verify(commandObjects).hrandfieldWithValues(key, count); + } + + @Test + public void testHscan() { + String key = "hashKey"; + String cursor = "0"; + ScanParams params = new ScanParams().match("*").count(10); + List> scanResultData = new ArrayList<>(); + scanResultData.add(new AbstractMap.SimpleEntry<>("field1", "value1")); + scanResultData.add(new AbstractMap.SimpleEntry<>("field2", "value2")); + ScanResult> expectedScanResult = new ScanResult<>(cursor, scanResultData); + + when(commandObjects.hscan(key, cursor, params)).thenReturn(scanResultEntryStringStringCommandObject); + when(commandExecutor.executeCommand(scanResultEntryStringStringCommandObject)).thenReturn(expectedScanResult); + + ScanResult> result = jedis.hscan(key, cursor, params); + + assertThat(result, equalTo(expectedScanResult)); + + verify(commandExecutor).executeCommand(scanResultEntryStringStringCommandObject); + verify(commandObjects).hscan(key, cursor, params); + } + + @Test + public void testHscanBinary() { + byte[] key = "hashKey".getBytes(); + byte[] cursor = ScanParams.SCAN_POINTER_START_BINARY; + ScanParams params = new ScanParams().match("*".getBytes()).count(10); + List> scanResultData = new ArrayList<>(); + scanResultData.add(new AbstractMap.SimpleEntry<>("field1".getBytes(), "value1".getBytes())); + scanResultData.add(new AbstractMap.SimpleEntry<>("field2".getBytes(), "value2".getBytes())); + ScanResult> expectedScanResult = new ScanResult<>(cursor, scanResultData); + + when(commandObjects.hscan(key, cursor, params)).thenReturn(scanResultEntryBytesBytesCommandObject); + when(commandExecutor.executeCommand(scanResultEntryBytesBytesCommandObject)).thenReturn(expectedScanResult); + + ScanResult> result = jedis.hscan(key, cursor, params); + + assertThat(result, equalTo(expectedScanResult)); + + verify(commandExecutor).executeCommand(scanResultEntryBytesBytesCommandObject); + verify(commandObjects).hscan(key, cursor, params); + } + + @Test + public void testHscanNoValues() { + String key = "hashKey"; + String cursor = "0"; + ScanParams params = new ScanParams().match("*").count(10); + List scanResultData = Arrays.asList("field1", "field2"); + ScanResult expectedScanResult = new ScanResult<>(cursor, scanResultData); + + when(commandObjects.hscanNoValues(key, cursor, params)).thenReturn(scanResultStringCommandObject); + when(commandExecutor.executeCommand(scanResultStringCommandObject)).thenReturn(expectedScanResult); + + ScanResult result = jedis.hscanNoValues(key, cursor, params); + + assertThat(result, equalTo(expectedScanResult)); + + verify(commandExecutor).executeCommand(scanResultStringCommandObject); + verify(commandObjects).hscanNoValues(key, cursor, params); + } + + @Test + public void testHscanNoValuesBinary() { + byte[] key = "hashKey".getBytes(); + byte[] cursor = ScanParams.SCAN_POINTER_START_BINARY; + ScanParams params = new ScanParams().match("*".getBytes()).count(10); + List scanResultData = Arrays.asList("field1".getBytes(), "field2".getBytes()); + ScanResult expectedScanResult = new ScanResult<>(cursor, scanResultData); + + when(commandObjects.hscanNoValues(key, cursor, params)).thenReturn(scanResultBytesCommandObject); + when(commandExecutor.executeCommand(scanResultBytesCommandObject)).thenReturn(expectedScanResult); + + ScanResult result = jedis.hscanNoValues(key, cursor, params); + + assertThat(result, equalTo(expectedScanResult)); + + verify(commandExecutor).executeCommand(scanResultBytesCommandObject); + verify(commandObjects).hscanNoValues(key, cursor, params); + } + + @Test + public void testHset() { + String key = "hashKey"; + String field = "field1"; + String value = "value1"; + long expected = 1L; // Assuming the field was newly set + + when(commandObjects.hset(key, field, value)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expected); + + long result = jedis.hset(key, field, value); + + assertThat(result, equalTo(expected)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).hset(key, field, value); + } + + @Test + public void testHsetBinary() { + byte[] key = "hashKey".getBytes(); + byte[] field = "field1".getBytes(); + byte[] value = "value1".getBytes(); + long expected = 1L; // Assuming the field was newly set + + when(commandObjects.hset(key, field, value)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expected); + + long result = jedis.hset(key, field, value); + + assertThat(result, equalTo(expected)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).hset(key, field, value); + } + + @Test + public void testHsetMap() { + String key = "hashKey"; + Map hash = new HashMap<>(); + hash.put("field1", "value1"); + hash.put("field2", "value2"); + long expected = 2L; // Assuming both fields were newly set + + when(commandObjects.hset(key, hash)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expected); + + long result = jedis.hset(key, hash); + + assertThat(result, equalTo(expected)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).hset(key, hash); + } + + @Test + public void testHsetMapBinary() { + byte[] key = "hashKey".getBytes(); + Map hash = new HashMap<>(); + hash.put("field1".getBytes(), "value1".getBytes()); + hash.put("field2".getBytes(), "value2".getBytes()); + long expected = 2L; // Assuming both fields were newly set + + when(commandObjects.hset(key, hash)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expected); + + long result = jedis.hset(key, hash); + + assertThat(result, equalTo(expected)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).hset(key, hash); + } + + @Test + public void testHsetObject() { + String key = "myHash"; + String field = "myField"; + Object value = "myValue"; + long expectedResponse = 1L; + + when(commandObjects.hsetObject(key, field, value)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedResponse); + + long result = jedis.hsetObject(key, field, value); + + assertThat(result, equalTo(expectedResponse)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).hsetObject(key, field, value); + } + + @Test + public void testHsetObjectMap() { + String key = "myHash"; + Map hash = new HashMap<>(); + hash.put("field1", "value1"); + hash.put("field2", "value2"); + long expectedResponse = 2L; + + when(commandObjects.hsetObject(key, hash)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedResponse); + + long result = jedis.hsetObject(key, hash); + + assertThat(result, equalTo(expectedResponse)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).hsetObject(key, hash); + } + + @Test + public void testHsetnx() { + String key = "hashKey"; + String field = "field1"; + String value = "value1"; + long expected = 1L; // Assuming the field was newly set + + when(commandObjects.hsetnx(key, field, value)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expected); + + long result = jedis.hsetnx(key, field, value); + + assertThat(result, equalTo(expected)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).hsetnx(key, field, value); + } + + @Test + public void testHsetnxBinary() { + byte[] key = "hashKey".getBytes(); + byte[] field = "field1".getBytes(); + byte[] value = "value1".getBytes(); + long expected = 1L; // Assuming the field was newly set + + when(commandObjects.hsetnx(key, field, value)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expected); + + long result = jedis.hsetnx(key, field, value); + + assertThat(result, equalTo(expected)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).hsetnx(key, field, value); + } + + @Test + public void testHstrlen() { + String key = "hashKey"; + String field = "field1"; + long expectedLength = 6L; // Assuming the value of the field is "value1" + + when(commandObjects.hstrlen(key, field)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedLength); + + long result = jedis.hstrlen(key, field); + + assertThat(result, equalTo(expectedLength)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).hstrlen(key, field); + } + + @Test + public void testHstrlenBinary() { + byte[] key = "hashKey".getBytes(); + byte[] field = "field1".getBytes(); + long expectedLength = 6L; // Assuming the value of the field is "value1".getBytes() + + when(commandObjects.hstrlen(key, field)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedLength); + + long result = jedis.hstrlen(key, field); + + assertThat(result, equalTo(expectedLength)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).hstrlen(key, field); + } + + @Test + public void testHvals() { + String key = "hashKey"; + List expectedValues = Arrays.asList("value1", "value2", "value3"); + + when(commandObjects.hvals(key)).thenReturn(listStringCommandObject); + when(commandExecutor.executeCommand(listStringCommandObject)).thenReturn(expectedValues); + + List result = jedis.hvals(key); + + assertThat(result, equalTo(expectedValues)); + + verify(commandExecutor).executeCommand(listStringCommandObject); + verify(commandObjects).hvals(key); + } + + @Test + public void testHvalsBinary() { + byte[] key = "hashKey".getBytes(); + List expectedValues = Arrays.asList("value1".getBytes(), "value2".getBytes(), "value3".getBytes()); + + when(commandObjects.hvals(key)).thenReturn(listBytesCommandObject); + when(commandExecutor.executeCommand(listBytesCommandObject)).thenReturn(expectedValues); + + List result = jedis.hvals(key); + + assertThat(result, equalTo(expectedValues)); + + verify(commandExecutor).executeCommand(listBytesCommandObject); + verify(commandObjects).hvals(key); + } + +} diff --git a/src/test/java/redis/clients/jedis/mocked/unified/UnifiedJedisHyperloglogCommandsTest.java b/src/test/java/redis/clients/jedis/mocked/unified/UnifiedJedisHyperloglogCommandsTest.java new file mode 100644 index 00000000000..f7e1cc4b3ce --- /dev/null +++ b/src/test/java/redis/clients/jedis/mocked/unified/UnifiedJedisHyperloglogCommandsTest.java @@ -0,0 +1,143 @@ +package redis.clients.jedis.mocked.unified; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.equalTo; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import org.junit.Test; + +public class UnifiedJedisHyperloglogCommandsTest extends UnifiedJedisMockedTestBase { + + @Test + public void testPfadd() { + String key = "hll"; + String[] elements = { "element1", "element2" }; + long expectedAdded = 1L; + + when(commandObjects.pfadd(key, elements)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedAdded); + + long result = jedis.pfadd(key, elements); + + assertThat(result, equalTo(expectedAdded)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).pfadd(key, elements); + } + + @Test + public void testPfaddBinary() { + byte[] key = "hll".getBytes(); + byte[][] elements = { "element1".getBytes(), "element2".getBytes() }; + long expectedAdded = 1L; + + when(commandObjects.pfadd(key, elements)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedAdded); + + long result = jedis.pfadd(key, elements); + + assertThat(result, equalTo(expectedAdded)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).pfadd(key, elements); + } + + @Test + public void testPfcount() { + String key = "hll"; + long expectedCount = 42L; + + when(commandObjects.pfcount(key)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedCount); + + long result = jedis.pfcount(key); + + assertThat(result, equalTo(expectedCount)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).pfcount(key); + } + + @Test + public void testPfcountBinary() { + byte[] key = "hll".getBytes(); + long expectedCount = 42L; + + when(commandObjects.pfcount(key)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedCount); + + long result = jedis.pfcount(key); + + assertThat(result, equalTo(expectedCount)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).pfcount(key); + } + + @Test + public void testPfcountMultipleKeys() { + String[] keys = { "hll1", "hll2" }; + long expectedCount = 84L; + + when(commandObjects.pfcount(keys)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedCount); + + long result = jedis.pfcount(keys); + + assertThat(result, equalTo(expectedCount)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).pfcount(keys); + } + + @Test + public void testPfcountMultipleKeysBinary() { + byte[][] keys = { "hll1".getBytes(), "hll2".getBytes() }; + long expectedCount = 84L; + + when(commandObjects.pfcount(keys)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedCount); + + long result = jedis.pfcount(keys); + + assertThat(result, equalTo(expectedCount)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).pfcount(keys); + } + + @Test + public void testPfmergeString() { + String destkey = "hll1"; + String[] sourcekeys = { "hll2", "hll3" }; + String expectedStatus = "OK"; + when(commandObjects.pfmerge(destkey, sourcekeys)).thenReturn(stringCommandObject); + when(commandExecutor.executeCommand(stringCommandObject)).thenReturn(expectedStatus); + + String result = jedis.pfmerge(destkey, sourcekeys); + + assertThat(result, equalTo(expectedStatus)); + + verify(commandExecutor).executeCommand(stringCommandObject); + verify(commandObjects).pfmerge(destkey, sourcekeys); + } + + @Test + public void testPfmergeBinary() { + byte[] destkey = "hll1".getBytes(); + byte[][] sourcekeys = { "hll2".getBytes(), "hll3".getBytes() }; + String expectedStatus = "OK"; + + when(commandObjects.pfmerge(destkey, sourcekeys)).thenReturn(stringCommandObject); + when(commandExecutor.executeCommand(stringCommandObject)).thenReturn(expectedStatus); + + String result = jedis.pfmerge(destkey, sourcekeys); + + assertThat(result, equalTo(expectedStatus)); + + verify(commandExecutor).executeCommand(stringCommandObject); + verify(commandObjects).pfmerge(destkey, sourcekeys); + } + +} diff --git a/src/test/java/redis/clients/jedis/mocked/unified/UnifiedJedisJsonCommandsTest.java b/src/test/java/redis/clients/jedis/mocked/unified/UnifiedJedisJsonCommandsTest.java new file mode 100644 index 00000000000..2ce1009decd --- /dev/null +++ b/src/test/java/redis/clients/jedis/mocked/unified/UnifiedJedisJsonCommandsTest.java @@ -0,0 +1,1211 @@ +package redis.clients.jedis.mocked.unified; + +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +import com.google.gson.JsonObject; +import org.json.JSONArray; +import org.junit.Test; +import org.mockito.invocation.InvocationOnMock; +import org.mockito.stubbing.Answer; +import redis.clients.jedis.json.JsonObjectMapper; +import redis.clients.jedis.json.JsonSetParams; +import redis.clients.jedis.json.Path; +import redis.clients.jedis.json.Path2; + +public class UnifiedJedisJsonCommandsTest extends UnifiedJedisMockedTestBase { + + @Test + public void testJsonArrAppendWithPath() { + String key = "testKey"; + Path path = Path.of(".path.to.array"); + Object[] pojos = new Object[]{ "value1", "value2" }; + Long expectedResponse = 4L; + + when(commandObjects.jsonArrAppend(key, path, pojos)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedResponse); + + Long result = jedis.jsonArrAppend(key, path, pojos); + + assertEquals(expectedResponse, result); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).jsonArrAppend(key, path, pojos); + } + + @Test + public void testJsonArrAppendWithPath2() { + String key = "testKey"; + Path2 path = Path2.of(".path.to.array"); + Object[] objects = new Object[]{ "value1", "value2" }; + List expectedResponse = Arrays.asList(3L, 4L); + + when(commandObjects.jsonArrAppend(key, path, objects)).thenReturn(listLongCommandObject); + when(commandExecutor.executeCommand(listLongCommandObject)).thenReturn(expectedResponse); + + List result = jedis.jsonArrAppend(key, path, objects); + + assertEquals(expectedResponse, result); + + verify(commandExecutor).executeCommand(listLongCommandObject); + verify(commandObjects).jsonArrAppend(key, path, objects); + } + + @Test + public void testJsonArrAppendWithPath2WithEscape() { + String key = "testKey"; + Path2 path = Path2.of(".path.to.array"); + Object[] objects = new Object[]{ "value1", "value2" }; + List expectedResponse = Arrays.asList(3L, 4L); + + when(commandObjects.jsonArrAppendWithEscape(key, path, objects)).thenReturn(listLongCommandObject); + when(commandExecutor.executeCommand(listLongCommandObject)).thenReturn(expectedResponse); + + List result = jedis.jsonArrAppendWithEscape(key, path, objects); + + assertEquals(expectedResponse, result); + + verify(commandExecutor).executeCommand(listLongCommandObject); + verify(commandObjects).jsonArrAppendWithEscape(key, path, objects); + } + + @Test + public void testJsonArrIndexWithPath() { + String key = "testKey"; + Path path = Path.of(".path.to.array"); + Object scalar = "value"; + long expectedResponse = 2L; + + when(commandObjects.jsonArrIndex(key, path, scalar)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedResponse); + + long result = jedis.jsonArrIndex(key, path, scalar); + + assertEquals(expectedResponse, result); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).jsonArrIndex(key, path, scalar); + } + + @Test + public void testJsonArrIndexWithPath2() { + String key = "testKey"; + Path2 path = Path2.of(".path.to.array"); + Object scalar = "value"; + List expectedResponse = Collections.singletonList(2L); + + when(commandObjects.jsonArrIndex(key, path, scalar)).thenReturn(listLongCommandObject); + when(commandExecutor.executeCommand(listLongCommandObject)).thenReturn(expectedResponse); + + List result = jedis.jsonArrIndex(key, path, scalar); + + assertEquals(expectedResponse, result); + + verify(commandExecutor).executeCommand(listLongCommandObject); + verify(commandObjects).jsonArrIndex(key, path, scalar); + } + + @Test + public void testJsonArrIndexWithPath2WithEscape() { + String key = "testKey"; + Path2 path = Path2.of(".path.to.array"); + Object scalar = "value"; + List expectedResponse = Collections.singletonList(2L); + + when(commandObjects.jsonArrIndexWithEscape(key, path, scalar)).thenReturn(listLongCommandObject); + when(commandExecutor.executeCommand(listLongCommandObject)).thenReturn(expectedResponse); + + List result = jedis.jsonArrIndexWithEscape(key, path, scalar); + + assertEquals(expectedResponse, result); + + verify(commandExecutor).executeCommand(listLongCommandObject); + verify(commandObjects).jsonArrIndexWithEscape(key, path, scalar); + } + + @Test + public void testJsonArrInsertWithPath() { + String key = "testKey"; + Path path = Path.of(".path.to.array"); + int index = 1; + Object[] pojos = new Object[]{ "value1", "value2" }; + long expectedResponse = 5L; + + when(commandObjects.jsonArrInsert(key, path, index, pojos)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedResponse); + + long result = jedis.jsonArrInsert(key, path, index, pojos); + + assertEquals(expectedResponse, result); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).jsonArrInsert(key, path, index, pojos); + } + + @Test + public void testJsonArrInsertWithPath2() { + String key = "testKey"; + Path2 path = Path2.of(".path.to.array"); + int index = 1; + Object[] objects = new Object[]{ "value1", "value2" }; + List expectedResponse = Collections.singletonList(5L); + + when(commandObjects.jsonArrInsert(key, path, index, objects)).thenReturn(listLongCommandObject); + when(commandExecutor.executeCommand(listLongCommandObject)).thenReturn(expectedResponse); + + List result = jedis.jsonArrInsert(key, path, index, objects); + + assertEquals(expectedResponse, result); + + verify(commandExecutor).executeCommand(listLongCommandObject); + verify(commandObjects).jsonArrInsert(key, path, index, objects); + } + + @Test + public void testJsonArrInsertWithPath2WithEscape() { + String key = "testKey"; + Path2 path = Path2.of(".path.to.array"); + int index = 1; + Object[] objects = new Object[]{ "value1", "value2" }; + List expectedResponse = Collections.singletonList(5L); + + when(commandObjects.jsonArrInsertWithEscape(key, path, index, objects)).thenReturn(listLongCommandObject); + when(commandExecutor.executeCommand(listLongCommandObject)).thenReturn(expectedResponse); + + List result = jedis.jsonArrInsertWithEscape(key, path, index, objects); + + assertEquals(expectedResponse, result); + + verify(commandExecutor).executeCommand(listLongCommandObject); + verify(commandObjects).jsonArrInsertWithEscape(key, path, index, objects); + } + + @Test + public void testJsonArrLen() { + String key = "testKey"; + Long expectedResponse = 10L; + + when(commandObjects.jsonArrLen(key)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedResponse); + + Long result = jedis.jsonArrLen(key); + + assertEquals(expectedResponse, result); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).jsonArrLen(key); + } + + @Test + public void testJsonArrLenWithPath() { + String key = "testKey"; + Path path = Path.of(".path.to.array"); + Long expectedResponse = 10L; + + when(commandObjects.jsonArrLen(key, path)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedResponse); + + Long result = jedis.jsonArrLen(key, path); + + assertEquals(expectedResponse, result); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).jsonArrLen(key, path); + } + + @Test + public void testJsonArrLenWithPath2() { + String key = "testKey"; + Path2 path = Path2.of(".path.to.array"); + List expectedResponse = Collections.singletonList(10L); + + when(commandObjects.jsonArrLen(key, path)).thenReturn(listLongCommandObject); + when(commandExecutor.executeCommand(listLongCommandObject)).thenReturn(expectedResponse); + + List result = jedis.jsonArrLen(key, path); + + assertEquals(expectedResponse, result); + + verify(commandExecutor).executeCommand(listLongCommandObject); + verify(commandObjects).jsonArrLen(key, path); + } + + @Test + public void testJsonArrPop() { + String key = "testKey"; + Object expectedResponse = "poppedValue"; + + when(commandObjects.jsonArrPop(key)).thenReturn(objectCommandObject); + when(commandExecutor.executeCommand(objectCommandObject)).thenReturn(expectedResponse); + + Object result = jedis.jsonArrPop(key); + + assertEquals(expectedResponse, result); + + verify(commandExecutor).executeCommand(objectCommandObject); + verify(commandObjects).jsonArrPop(key); + } + + @Test + public void testJsonArrPopWithPath() { + String key = "testKey"; + Path path = Path.of(".path.to.array"); + Object expectedResponse = "poppedValue"; + + when(commandObjects.jsonArrPop(key, path)).thenReturn(objectCommandObject); + when(commandExecutor.executeCommand(objectCommandObject)).thenReturn(expectedResponse); + + Object result = jedis.jsonArrPop(key, path); + + assertEquals(expectedResponse, result); + + verify(commandExecutor).executeCommand(objectCommandObject); + verify(commandObjects).jsonArrPop(key, path); + } + + @Test + public void testJsonArrPopWithPathAndIndex() { + String key = "testKey"; + Path path = Path.of(".path.to.array"); + int index = 1; + Object expectedResponse = "poppedValueAtIndex"; + + when(commandObjects.jsonArrPop(key, path, index)).thenReturn(objectCommandObject); + when(commandExecutor.executeCommand(objectCommandObject)).thenReturn(expectedResponse); + + Object result = jedis.jsonArrPop(key, path, index); + + assertEquals(expectedResponse, result); + + verify(commandExecutor).executeCommand(objectCommandObject); + verify(commandObjects).jsonArrPop(key, path, index); + } + + @Test + public void testJsonArrPopWithClassAndPath() { + String key = "testKey"; + Class clazz = String.class; + Path path = Path.of(".path.to.array"); + String expectedResponse = "poppedValue"; + + when(commandObjects.jsonArrPop(key, clazz, path)).thenReturn(stringCommandObject); + when(commandExecutor.executeCommand(stringCommandObject)).thenReturn(expectedResponse); + + String result = jedis.jsonArrPop(key, clazz, path); + + assertEquals(expectedResponse, result); + + verify(commandExecutor).executeCommand(stringCommandObject); + verify(commandObjects).jsonArrPop(key, clazz, path); + } + + @Test + public void testJsonArrPopWithClassPathAndIndex() { + String key = "testKey"; + Class clazz = String.class; + Path path = Path.of(".path.to.array"); + int index = 1; + String expectedResponse = "poppedValueAtIndex"; + + when(commandObjects.jsonArrPop(key, clazz, path, index)).thenReturn(stringCommandObject); + when(commandExecutor.executeCommand(stringCommandObject)).thenReturn(expectedResponse); + + String result = jedis.jsonArrPop(key, clazz, path, index); + + assertEquals(expectedResponse, result); + + verify(commandExecutor).executeCommand(stringCommandObject); + verify(commandObjects).jsonArrPop(key, clazz, path, index); + } + + @Test + public void testJsonArrPopWithPath2() { + String key = "testKey"; + Path2 path = Path2.of(".path.to.array"); + List expectedResponse = Collections.singletonList("poppedValue"); + + when(commandObjects.jsonArrPop(key, path)).thenReturn(listObjectCommandObject); + when(commandExecutor.executeCommand(listObjectCommandObject)).thenReturn(expectedResponse); + + List result = jedis.jsonArrPop(key, path); + + assertEquals(expectedResponse, result); + + verify(commandExecutor).executeCommand(listObjectCommandObject); + verify(commandObjects).jsonArrPop(key, path); + } + + @Test + public void testJsonArrPopWithPath2AndIndex() { + String key = "testKey"; + Path2 path = Path2.of(".path.to.array"); + int index = 1; + List expectedResponse = Collections.singletonList("poppedValueAtIndex"); + + when(commandObjects.jsonArrPop(key, path, index)).thenReturn(listObjectCommandObject); + when(commandExecutor.executeCommand(listObjectCommandObject)).thenReturn(expectedResponse); + + List result = jedis.jsonArrPop(key, path, index); + + assertEquals(expectedResponse, result); + + verify(commandExecutor).executeCommand(listObjectCommandObject); + verify(commandObjects).jsonArrPop(key, path, index); + } + + @Test + public void testJsonArrPopWithClass() { + String key = "testKey"; + Class clazz = String.class; + String expectedResponse = "poppedValue"; + + when(commandObjects.jsonArrPop(key, clazz)).thenReturn(stringCommandObject); + when(commandExecutor.executeCommand(stringCommandObject)).thenReturn(expectedResponse); + + String result = jedis.jsonArrPop(key, clazz); + + assertEquals(expectedResponse, result); + + verify(commandExecutor).executeCommand(stringCommandObject); + verify(commandObjects).jsonArrPop(key, clazz); + } + + @Test + public void testJsonArrTrimWithPath() { + String key = "testKey"; + Path path = Path.of(".path.to.array"); + int start = 1; + int stop = 3; + Long expectedResponse = 3L; + + when(commandObjects.jsonArrTrim(key, path, start, stop)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedResponse); + + Long result = jedis.jsonArrTrim(key, path, start, stop); + + assertEquals(expectedResponse, result); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).jsonArrTrim(key, path, start, stop); + } + + @Test + public void testJsonArrTrimWithPath2() { + String key = "testKey"; + Path2 path = Path2.of(".path.to.array"); + int start = 1; + int stop = 3; + List expectedResponse = Collections.singletonList(3L); + + when(commandObjects.jsonArrTrim(key, path, start, stop)).thenReturn(listLongCommandObject); + when(commandExecutor.executeCommand(listLongCommandObject)).thenReturn(expectedResponse); + + List result = jedis.jsonArrTrim(key, path, start, stop); + + assertEquals(expectedResponse, result); + + verify(commandExecutor).executeCommand(listLongCommandObject); + verify(commandObjects).jsonArrTrim(key, path, start, stop); + } + + @Test + public void testJsonClear() { + String key = "testKey"; + long expectedResponse = 1L; + + when(commandObjects.jsonClear(key)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedResponse); + + long result = jedis.jsonClear(key); + + assertEquals(expectedResponse, result); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).jsonClear(key); + } + + @Test + public void testJsonClearWithPath() { + String key = "testKey"; + Path path = Path.of(".path.to.element"); + long expectedResponse = 1L; + + when(commandObjects.jsonClear(key, path)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedResponse); + + long result = jedis.jsonClear(key, path); + + assertEquals(expectedResponse, result); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).jsonClear(key, path); + } + + @Test + public void testJsonClearWithPath2() { + String key = "testKey"; + Path2 path = Path2.of(".path.to.element"); + long expectedResponse = 1L; + + when(commandObjects.jsonClear(key, path)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedResponse); + + long result = jedis.jsonClear(key, path); + + assertEquals(expectedResponse, result); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).jsonClear(key, path); + } + + @Test + public void testJsonDebugMemory() { + String key = "testKey"; + long expectedResponse = 1024L; + + when(commandObjects.jsonDebugMemory(key)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedResponse); + + long result = jedis.jsonDebugMemory(key); + + assertEquals(expectedResponse, result); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).jsonDebugMemory(key); + } + + @Test + public void testJsonDebugMemoryWithPath() { + String key = "testKey"; + Path path = Path.of(".path.to.element"); + long expectedResponse = 512L; + + when(commandObjects.jsonDebugMemory(key, path)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedResponse); + + long result = jedis.jsonDebugMemory(key, path); + + assertEquals(expectedResponse, result); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).jsonDebugMemory(key, path); + } + + @Test + public void testJsonDebugMemoryWithPath2() { + String key = "testKey"; + Path2 path = Path2.of(".path.to.element"); + List expectedResponse = Collections.singletonList(512L); + + when(commandObjects.jsonDebugMemory(key, path)).thenReturn(listLongCommandObject); + when(commandExecutor.executeCommand(listLongCommandObject)).thenReturn(expectedResponse); + + List result = jedis.jsonDebugMemory(key, path); + + assertEquals(expectedResponse, result); + + verify(commandExecutor).executeCommand(listLongCommandObject); + verify(commandObjects).jsonDebugMemory(key, path); + } + + @Test + public void testJsonDel() { + String key = "testKey"; + long expectedResponse = 1L; + + when(commandObjects.jsonDel(key)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedResponse); + + long result = jedis.jsonDel(key); + + assertEquals(expectedResponse, result); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).jsonDel(key); + } + + @Test + public void testJsonDelWithPath() { + String key = "testKey"; + Path path = Path.of(".path.to.element"); + long expectedResponse = 1L; + + when(commandObjects.jsonDel(key, path)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedResponse); + + long result = jedis.jsonDel(key, path); + + assertEquals(expectedResponse, result); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).jsonDel(key, path); + } + + @Test + public void testJsonDelWithPath2() { + String key = "testKey"; + Path2 path = Path2.of(".path.to.element"); + long expectedResponse = 1L; + + when(commandObjects.jsonDel(key, path)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedResponse); + + long result = jedis.jsonDel(key, path); + + assertEquals(expectedResponse, result); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).jsonDel(key, path); + } + + @Test + public void testJsonGet() { + String key = "testKey"; + Object expectedResponse = new JsonObject(); + + when(commandObjects.jsonGet(key)).thenReturn(objectCommandObject); + when(commandExecutor.executeCommand(objectCommandObject)).thenReturn(expectedResponse); + + Object result = jedis.jsonGet(key); + + assertEquals(expectedResponse, result); + + verify(commandExecutor).executeCommand(objectCommandObject); + verify(commandObjects).jsonGet(key); + } + + @Test + public void testJsonGetWithClass() { + String key = "testKey"; + Class clazz = MyBean.class; + MyBean expectedResponse = new MyBean(); + + when(commandObjects.jsonGet(key, clazz)).thenReturn(myBeanCommandObject); + when(commandExecutor.executeCommand(myBeanCommandObject)).thenReturn(expectedResponse); + + MyBean result = jedis.jsonGet(key, clazz); + + assertEquals(expectedResponse, result); + + verify(commandExecutor).executeCommand(myBeanCommandObject); + verify(commandObjects).jsonGet(key, clazz); + } + + @Test + public void testJsonGetWithPath() { + String key = "testKey"; + Path[] paths = new Path[]{ Path.of(".path.to.element1"), Path.of(".path.to.element2") }; + Object expectedResponse = new JsonObject(); + + when(commandObjects.jsonGet(key, paths)).thenReturn(objectCommandObject); + when(commandExecutor.executeCommand(objectCommandObject)).thenReturn(expectedResponse); + + Object result = jedis.jsonGet(key, paths); + + assertEquals(expectedResponse, result); + + verify(commandExecutor).executeCommand(objectCommandObject); + verify(commandObjects).jsonGet(key, paths); + } + + @Test + public void testJsonGetWithPath2() { + String key = "testKey"; + Path2[] paths = new Path2[]{ Path2.of(".path.to.element1"), Path2.of(".path.to.element2") }; + Object expectedResponse = new JsonObject(); + + when(commandObjects.jsonGet(key, paths)).thenReturn(objectCommandObject); + when(commandExecutor.executeCommand(objectCommandObject)).thenReturn(expectedResponse); + + Object result = jedis.jsonGet(key, paths); + + assertEquals(expectedResponse, result); + + verify(commandExecutor).executeCommand(objectCommandObject); + verify(commandObjects).jsonGet(key, paths); + } + + @Test + public void testJsonGetAsPlainString() { + String key = "testKey"; + Path path = Path.of(".path.to.element"); + String expectedResponse = "{\"field\":\"value\"}"; + + when(commandObjects.jsonGetAsPlainString(key, path)).thenReturn(stringCommandObject); + when(commandExecutor.executeCommand(stringCommandObject)).thenReturn(expectedResponse); + + String result = jedis.jsonGetAsPlainString(key, path); + + assertEquals(expectedResponse, result); + + verify(commandExecutor).executeCommand(stringCommandObject); + verify(commandObjects).jsonGetAsPlainString(key, path); + } + + @Test + public void testJsonGetWithClassAndPath() { + String key = "testKey"; + Class clazz = MyBean.class; + Path[] paths = new Path[]{ Path.of(".path.to.element1"), Path.of(".path.to.element2") }; + MyBean expectedResponse = new MyBean(); + + when(commandObjects.jsonGet(key, clazz, paths)).thenReturn(myBeanCommandObject); + when(commandExecutor.executeCommand(myBeanCommandObject)).thenReturn(expectedResponse); + + MyBean result = jedis.jsonGet(key, clazz, paths); + + assertEquals(expectedResponse, result); + + verify(commandExecutor).executeCommand(myBeanCommandObject); + verify(commandObjects).jsonGet(key, clazz, paths); + } + + @Test + public void testJsonMergeWithPath() { + String key = "testKey"; + Path path = Path.of(".path.to.element"); + Object pojo = new MyBean(); + String expectedResponse = "OK"; + + when(commandObjects.jsonMerge(key, path, pojo)).thenReturn(stringCommandObject); + when(commandExecutor.executeCommand(stringCommandObject)).thenReturn(expectedResponse); + + String result = jedis.jsonMerge(key, path, pojo); + + assertEquals(expectedResponse, result); + + verify(commandExecutor).executeCommand(stringCommandObject); + verify(commandObjects).jsonMerge(key, path, pojo); + } + + @Test + public void testJsonMergeWithPath2() { + String key = "testKey"; + Path2 path = Path2.of(".path.to.element"); + Object object = new JsonObject(); + String expectedResponse = "OK"; + + when(commandObjects.jsonMerge(key, path, object)).thenReturn(stringCommandObject); + when(commandExecutor.executeCommand(stringCommandObject)).thenReturn(expectedResponse); + + String result = jedis.jsonMerge(key, path, object); + + assertEquals(expectedResponse, result); + + verify(commandExecutor).executeCommand(stringCommandObject); + verify(commandObjects).jsonMerge(key, path, object); + } + + @Test + public void testJsonMGetWithPathAndClass() { + Path path = Path.of(".path.to.element"); + Class clazz = MyBean.class; + String[] keys = { "testKey1", "testKey2" }; + List expectedResponse = Arrays.asList(new MyBean(), new MyBean()); + + when(commandObjects.jsonMGet(path, clazz, keys)).thenReturn(listMyBeanCommandObject); + when(commandExecutor.executeCommand(listMyBeanCommandObject)).thenReturn(expectedResponse); + + List result = jedis.jsonMGet(path, clazz, keys); + + assertEquals(expectedResponse, result); + + verify(commandExecutor).executeCommand(listMyBeanCommandObject); + verify(commandObjects).jsonMGet(path, clazz, keys); + } + + @Test + public void testJsonMGetWithPath2() { + Path2 path = Path2.of(".path.to.element"); + String[] keys = { "testKey1", "testKey2" }; + List expectedResponse = Arrays.asList(new JSONArray(), new JSONArray()); + + when(commandObjects.jsonMGet(path, keys)).thenReturn(listJsonArrayCommandObject); + when(commandExecutor.executeCommand(listJsonArrayCommandObject)).thenReturn(expectedResponse); + + List result = jedis.jsonMGet(path, keys); + + assertEquals(expectedResponse, result); + + verify(commandExecutor).executeCommand(listJsonArrayCommandObject); + verify(commandObjects).jsonMGet(path, keys); + } + + @Test + public void testJsonNumIncrByWithPath() { + String key = "testKey"; + Path path = Path.of(".path.to.element"); + double value = 10.5; + double expectedResponse = 20.5; + + when(commandObjects.jsonNumIncrBy(key, path, value)).thenReturn(doubleCommandObject); + when(commandExecutor.executeCommand(doubleCommandObject)).thenReturn(expectedResponse); + + double result = jedis.jsonNumIncrBy(key, path, value); + + assertEquals(expectedResponse, result, 0.0); + + verify(commandExecutor).executeCommand(doubleCommandObject); + verify(commandObjects).jsonNumIncrBy(key, path, value); + } + + @Test + public void testJsonNumIncrByWithPath2() { + String key = "testKey"; + Path2 path = Path2.of(".path.to.element"); + double value = 10.5; + Object expectedResponse = 20.5; + + when(commandObjects.jsonNumIncrBy(key, path, value)).thenReturn(objectCommandObject); + when(commandExecutor.executeCommand(objectCommandObject)).thenReturn(expectedResponse); + + Object result = jedis.jsonNumIncrBy(key, path, value); + + assertEquals(expectedResponse, result); + + verify(commandExecutor).executeCommand(objectCommandObject); + verify(commandObjects).jsonNumIncrBy(key, path, value); + } + + @Test + public void testJsonSetWithPath() { + String key = "testKey"; + Path path = Path.of(".path.to.element"); + Object pojo = new MyBean(); + String expectedResponse = "OK"; + + when(commandObjects.jsonSet(key, path, pojo)).thenReturn(stringCommandObject); + when(commandExecutor.executeCommand(stringCommandObject)).thenReturn(expectedResponse); + + String result = jedis.jsonSet(key, path, pojo); + + assertEquals(expectedResponse, result); + + verify(commandExecutor).executeCommand(stringCommandObject); + verify(commandObjects).jsonSet(key, path, pojo); + } + + @Test + public void testJsonSetWithPathAndParams() { + String key = "testKey"; + Path path = Path.of(".path.to.element"); + Object pojo = new MyBean(); + JsonSetParams params = new JsonSetParams().nx(); + String expectedResponse = "OK"; + + when(commandObjects.jsonSet(key, path, pojo, params)).thenReturn(stringCommandObject); + when(commandExecutor.executeCommand(stringCommandObject)).thenReturn(expectedResponse); + + String result = jedis.jsonSet(key, path, pojo, params); + + assertEquals(expectedResponse, result); + + verify(commandExecutor).executeCommand(stringCommandObject); + verify(commandObjects).jsonSet(key, path, pojo, params); + } + + @Test + public void testJsonSetWithPath2() { + String key = "testKey"; + Path2 path = Path2.of(".path.to.element"); + Object object = new JsonObject(); + String expectedResponse = "OK"; + + when(commandObjects.jsonSet(key, path, object)).thenReturn(stringCommandObject); + when(commandExecutor.executeCommand(stringCommandObject)).thenReturn(expectedResponse); + + String result = jedis.jsonSet(key, path, object); + + assertEquals(expectedResponse, result); + + verify(commandExecutor).executeCommand(stringCommandObject); + verify(commandObjects).jsonSet(key, path, object); + } + + @Test + public void testJsonSetWithPath2WithEscape() { + String key = "testKey"; + Path2 path = Path2.of(".path.to.element"); + Object object = new JsonObject(); + String expectedResponse = "OK"; + + when(commandObjects.jsonSetWithEscape(key, path, object)).thenReturn(stringCommandObject); + when(commandExecutor.executeCommand(stringCommandObject)).thenReturn(expectedResponse); + + String result = jedis.jsonSetWithEscape(key, path, object); + + assertEquals(expectedResponse, result); + + verify(commandExecutor).executeCommand(stringCommandObject); + verify(commandObjects).jsonSetWithEscape(key, path, object); + } + + @Test + public void testJsonSetWithPath2AndParams() { + String key = "testKey"; + Path2 path = Path2.of(".path.to.element"); + Object object = new JsonObject(); + JsonSetParams params = new JsonSetParams().nx(); + String expectedResponse = "OK"; + + when(commandObjects.jsonSet(key, path, object, params)).thenReturn(stringCommandObject); + when(commandExecutor.executeCommand(stringCommandObject)).thenReturn(expectedResponse); + + String result = jedis.jsonSet(key, path, object, params); + + assertEquals(expectedResponse, result); + + verify(commandExecutor).executeCommand(stringCommandObject); + verify(commandObjects).jsonSet(key, path, object, params); + } + + @Test + public void testJsonSetWithPath2EscapeAndParams() { + String key = "testKey"; + Path2 path = Path2.of(".path.to.element"); + Object object = new JsonObject(); + JsonSetParams params = new JsonSetParams().nx(); + String expectedResponse = "OK"; + + when(commandObjects.jsonSetWithEscape(key, path, object, params)).thenReturn(stringCommandObject); + when(commandExecutor.executeCommand(stringCommandObject)).thenReturn(expectedResponse); + + String result = jedis.jsonSetWithEscape(key, path, object, params); + + assertEquals(expectedResponse, result); + + verify(commandExecutor).executeCommand(stringCommandObject); + verify(commandObjects).jsonSetWithEscape(key, path, object, params); + } + + @Test + public void testJsonSetWithPlainString() { + String key = "testKey"; + Path path = Path.of(".path.to.element"); + String jsonString = "{\"field\":\"value\"}"; + String expectedResponse = "OK"; + + when(commandObjects.jsonSetWithPlainString(key, path, jsonString)).thenReturn(stringCommandObject); + when(commandExecutor.executeCommand(stringCommandObject)).thenReturn(expectedResponse); + + String result = jedis.jsonSetWithPlainString(key, path, jsonString); + + assertEquals(expectedResponse, result); + + verify(commandExecutor).executeCommand(stringCommandObject); + verify(commandObjects).jsonSetWithPlainString(key, path, jsonString); + } + + @Test + public void testJsonStrAppend() { + String key = "testKey"; + Object string = "additional string"; + long expectedResponse = 20L; + + when(commandObjects.jsonStrAppend(key, string)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedResponse); + + long result = jedis.jsonStrAppend(key, string); + + assertEquals(expectedResponse, result); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).jsonStrAppend(key, string); + } + + @Test + public void testJsonStrAppendWithPath() { + String key = "testKey"; + Path path = Path.of(".path.to.element"); + Object string = "additional string"; + long expectedResponse = 20L; + + when(commandObjects.jsonStrAppend(key, path, string)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedResponse); + + long result = jedis.jsonStrAppend(key, path, string); + + assertEquals(expectedResponse, result); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).jsonStrAppend(key, path, string); + } + + @Test + public void testJsonStrAppendWithPath2() { + String key = "testKey"; + Path2 path = Path2.of(".path.to.element"); + Object string = "additional string"; + List expectedResponse = Collections.singletonList(20L); + + when(commandObjects.jsonStrAppend(key, path, string)).thenReturn(listLongCommandObject); + when(commandExecutor.executeCommand(listLongCommandObject)).thenReturn(expectedResponse); + + List result = jedis.jsonStrAppend(key, path, string); + + assertEquals(expectedResponse, result); + + verify(commandExecutor).executeCommand(listLongCommandObject); + verify(commandObjects).jsonStrAppend(key, path, string); + } + + @Test + public void testJsonStrLen() { + String key = "testKey"; + Long expectedResponse = 15L; + + when(commandObjects.jsonStrLen(key)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedResponse); + + Long result = jedis.jsonStrLen(key); + + assertEquals(expectedResponse, result); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).jsonStrLen(key); + } + + @Test + public void testJsonStrLenWithPath() { + String key = "testKey"; + Path path = Path.of(".path.to.element"); + Long expectedResponse = 15L; + + when(commandObjects.jsonStrLen(key, path)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedResponse); + + Long result = jedis.jsonStrLen(key, path); + + assertEquals(expectedResponse, result); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).jsonStrLen(key, path); + } + + @Test + public void testJsonStrLenWithPath2() { + String key = "testKey"; + Path2 path = Path2.of(".path.to.element"); + List expectedResponse = Collections.singletonList(15L); + + when(commandObjects.jsonStrLen(key, path)).thenReturn(listLongCommandObject); + when(commandExecutor.executeCommand(listLongCommandObject)).thenReturn(expectedResponse); + + List result = jedis.jsonStrLen(key, path); + + assertEquals(expectedResponse, result); + + verify(commandExecutor).executeCommand(listLongCommandObject); + verify(commandObjects).jsonStrLen(key, path); + } + + @Test + public void testJsonToggleWithPath() { + String key = "testKey"; + Path path = Path.of(".path.to.element"); + String expectedResponse = "OK"; + + when(commandObjects.jsonToggle(key, path)).thenReturn(stringCommandObject); + when(commandExecutor.executeCommand(stringCommandObject)).thenReturn(expectedResponse); + + String result = jedis.jsonToggle(key, path); + + assertEquals(expectedResponse, result); + + verify(commandExecutor).executeCommand(stringCommandObject); + verify(commandObjects).jsonToggle(key, path); + } + + @Test + public void testJsonToggleWithPath2() { + String key = "testKey"; + Path2 path = Path2.of(".path.to.element"); + List expectedResponse = Arrays.asList(true, false); + + when(commandObjects.jsonToggle(key, path)).thenReturn(listBooleanCommandObject); + when(commandExecutor.executeCommand(listBooleanCommandObject)).thenReturn(expectedResponse); + + List result = jedis.jsonToggle(key, path); + + assertEquals(expectedResponse, result); + + verify(commandExecutor).executeCommand(listBooleanCommandObject); + verify(commandObjects).jsonToggle(key, path); + } + + @Test + public void testJsonType() { + String key = "testKey"; + Class expectedResponse = String.class; + + when(commandObjects.jsonType(key)).thenReturn(classCommandObject); + when(commandExecutor.executeCommand(classCommandObject)).thenAnswer(new Answer>() { + @Override + public Class answer(InvocationOnMock invocationOnMock) { + return expectedResponse; + } + }); + + Class result = jedis.jsonType(key); + + assertEquals(expectedResponse, result); + + verify(commandExecutor).executeCommand(classCommandObject); + verify(commandObjects).jsonType(key); + } + + @Test + public void testJsonTypeWithPath() { + String key = "testKey"; + Path path = Path.of(".path.to.element"); + Class expectedResponse = String.class; + + when(commandObjects.jsonType(key, path)).thenReturn(classCommandObject); + when(commandExecutor.executeCommand(classCommandObject)).thenAnswer(new Answer>() { + @Override + public Class answer(InvocationOnMock invocationOnMock) { + return expectedResponse; + } + }); + + Class result = jedis.jsonType(key, path); + + assertEquals(expectedResponse, result); + + verify(commandExecutor).executeCommand(classCommandObject); + verify(commandObjects).jsonType(key, path); + } + + @Test + public void testJsonTypeWithPath2() { + String key = "testKey"; + Path2 path = Path2.of(".path.to.element"); + List> expectedResponse = Collections.singletonList(String.class); + + when(commandObjects.jsonType(key, path)).thenReturn(listClassCommandObject); + when(commandExecutor.executeCommand(listClassCommandObject)).thenReturn(expectedResponse); + + List> result = jedis.jsonType(key, path); + + assertEquals(expectedResponse, result); + + verify(commandExecutor).executeCommand(listClassCommandObject); + verify(commandObjects).jsonType(key, path); + } + + @Test + public void testJsonObjKeys() { + String key = "testKey"; + List expectedResponse = Arrays.asList("key1", "key2", "key3"); + + when(commandObjects.jsonObjKeys(key)).thenReturn(listStringCommandObject); + when(commandExecutor.executeCommand(listStringCommandObject)).thenReturn(expectedResponse); + + List result = jedis.jsonObjKeys(key); + + assertEquals(expectedResponse, result); + + verify(commandExecutor).executeCommand(listStringCommandObject); + verify(commandObjects).jsonObjKeys(key); + } + + @Test + public void testJsonObjKeysWithPath() { + String key = "testKey"; + Path path = Path.of(".path.to.object"); + List expectedResponse = Arrays.asList("key1", "key2"); + + when(commandObjects.jsonObjKeys(key, path)).thenReturn(listStringCommandObject); + when(commandExecutor.executeCommand(listStringCommandObject)).thenReturn(expectedResponse); + + List result = jedis.jsonObjKeys(key, path); + + assertEquals(expectedResponse, result); + + verify(commandExecutor).executeCommand(listStringCommandObject); + verify(commandObjects).jsonObjKeys(key, path); + } + + @Test + public void testJsonObjKeysWithPath2() { + String key = "testKey"; + Path2 path = Path2.of(".path.to.object"); + List> expectedResponse = Collections.singletonList(Arrays.asList("key1", "key2")); + + when(commandObjects.jsonObjKeys(key, path)).thenReturn(listListStringCommandObject); + when(commandExecutor.executeCommand(listListStringCommandObject)).thenReturn(expectedResponse); + + List> result = jedis.jsonObjKeys(key, path); + + assertEquals(expectedResponse, result); + + verify(commandExecutor).executeCommand(listListStringCommandObject); + verify(commandObjects).jsonObjKeys(key, path); + } + + @Test + public void testJsonObjLen() { + String key = "testKey"; + Long expectedResponse = 5L; + + when(commandObjects.jsonObjLen(key)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedResponse); + + Long result = jedis.jsonObjLen(key); + + assertEquals(expectedResponse, result); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).jsonObjLen(key); + } + + @Test + public void testJsonObjLenWithPath() { + String key = "testKey"; + Path path = Path.of(".path.to.object"); + Long expectedResponse = 3L; + + when(commandObjects.jsonObjLen(key, path)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedResponse); + + Long result = jedis.jsonObjLen(key, path); + + assertEquals(expectedResponse, result); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).jsonObjLen(key, path); + } + + @Test + public void testJsonObjLenWithPath2() { + String key = "testKey"; + Path2 path = Path2.of(".path.to.object"); + List expectedResponse = Collections.singletonList(3L); + + when(commandObjects.jsonObjLen(key, path)).thenReturn(listLongCommandObject); + when(commandExecutor.executeCommand(listLongCommandObject)).thenReturn(expectedResponse); + + List result = jedis.jsonObjLen(key, path); + + assertEquals(expectedResponse, result); + + verify(commandExecutor).executeCommand(listLongCommandObject); + verify(commandObjects).jsonObjLen(key, path); + } + + @Test + public void testSetJsonObjectMapper() { + JsonObjectMapper jsonObjectMapper = mock(JsonObjectMapper.class); + + jedis.setJsonObjectMapper(jsonObjectMapper); + + verify(commandObjects).setJsonObjectMapper(jsonObjectMapper); + } + +} diff --git a/src/test/java/redis/clients/jedis/mocked/unified/UnifiedJedisListCommandsTest.java b/src/test/java/redis/clients/jedis/mocked/unified/UnifiedJedisListCommandsTest.java new file mode 100644 index 00000000000..1eec5a58960 --- /dev/null +++ b/src/test/java/redis/clients/jedis/mocked/unified/UnifiedJedisListCommandsTest.java @@ -0,0 +1,1135 @@ +package redis.clients.jedis.mocked.unified; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.equalTo; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import java.util.Arrays; +import java.util.List; + +import org.junit.Test; +import redis.clients.jedis.args.ListDirection; +import redis.clients.jedis.args.ListPosition; +import redis.clients.jedis.params.LPosParams; +import redis.clients.jedis.util.KeyValue; + +public class UnifiedJedisListCommandsTest extends UnifiedJedisMockedTestBase { + + @Test + public void testBlmove() { + String srcKey = "sourceList"; + String dstKey = "destinationList"; + ListDirection from = ListDirection.LEFT; + ListDirection to = ListDirection.RIGHT; + double timeout = 10.5; // Timeout in seconds + String expectedMovedValue = "value"; + + when(commandObjects.blmove(srcKey, dstKey, from, to, timeout)).thenReturn(stringCommandObject); + when(commandExecutor.executeCommand(stringCommandObject)).thenReturn(expectedMovedValue); + + String result = jedis.blmove(srcKey, dstKey, from, to, timeout); + + assertThat(result, equalTo(expectedMovedValue)); + + verify(commandExecutor).executeCommand(stringCommandObject); + verify(commandObjects).blmove(srcKey, dstKey, from, to, timeout); + } + + @Test + public void testBlmoveBinary() { + byte[] srcKey = "sourceList".getBytes(); + byte[] dstKey = "destinationList".getBytes(); + ListDirection from = ListDirection.LEFT; + ListDirection to = ListDirection.RIGHT; + double timeout = 10.5; // Timeout in seconds + byte[] expectedMovedValue = "value".getBytes(); + + when(commandObjects.blmove(srcKey, dstKey, from, to, timeout)).thenReturn(bytesCommandObject); + when(commandExecutor.executeCommand(bytesCommandObject)).thenReturn(expectedMovedValue); + + byte[] result = jedis.blmove(srcKey, dstKey, from, to, timeout); + + assertThat(result, equalTo(expectedMovedValue)); + + verify(commandExecutor).executeCommand(bytesCommandObject); + verify(commandObjects).blmove(srcKey, dstKey, from, to, timeout); + } + + @Test + public void testBlmpop() { + double timeout = 10.5; // Timeout in seconds + ListDirection direction = ListDirection.LEFT; + String[] keys = { "listKey1", "listKey2" }; + KeyValue> expectedKeyValue = new KeyValue<>("listKey1", Arrays.asList("value1", "value2")); + + when(commandObjects.blmpop(timeout, direction, keys)).thenReturn(keyValueStringListStringCommandObject); + when(commandExecutor.executeCommand(keyValueStringListStringCommandObject)).thenReturn(expectedKeyValue); + + KeyValue> result = jedis.blmpop(timeout, direction, keys); + + assertThat(result, equalTo(expectedKeyValue)); + + verify(commandExecutor).executeCommand(keyValueStringListStringCommandObject); + verify(commandObjects).blmpop(timeout, direction, keys); + } + + @Test + public void testBlmpopBinary() { + double timeout = 10.5; // Timeout in seconds + ListDirection direction = ListDirection.LEFT; + byte[][] keys = { "listKey1".getBytes(), "listKey2".getBytes() }; + KeyValue> expectedKeyValue = new KeyValue<>("listKey1".getBytes(), Arrays.asList("value1".getBytes(), "value2".getBytes())); + + when(commandObjects.blmpop(timeout, direction, keys)).thenReturn(keyValueBytesListBytesCommandObject); + when(commandExecutor.executeCommand(keyValueBytesListBytesCommandObject)).thenReturn(expectedKeyValue); + + KeyValue> result = jedis.blmpop(timeout, direction, keys); + + assertThat(result, equalTo(expectedKeyValue)); + + verify(commandExecutor).executeCommand(keyValueBytesListBytesCommandObject); + verify(commandObjects).blmpop(timeout, direction, keys); + } + + @Test + public void testBlmpopCount() { + double timeout = 10.5; // Timeout in seconds + ListDirection direction = ListDirection.RIGHT; + int count = 2; + String[] keys = { "listKey1", "listKey2" }; + KeyValue> expectedKeyValue = new KeyValue<>("listKey2", Arrays.asList("value3", "value4")); + + when(commandObjects.blmpop(timeout, direction, count, keys)).thenReturn(keyValueStringListStringCommandObject); + when(commandExecutor.executeCommand(keyValueStringListStringCommandObject)).thenReturn(expectedKeyValue); + + KeyValue> result = jedis.blmpop(timeout, direction, count, keys); + + assertThat(result, equalTo(expectedKeyValue)); + + verify(commandExecutor).executeCommand(keyValueStringListStringCommandObject); + verify(commandObjects).blmpop(timeout, direction, count, keys); + } + + @Test + public void testBlmpopCountBinary() { + double timeout = 10.5; // Timeout in seconds + ListDirection direction = ListDirection.RIGHT; + int count = 2; + byte[][] keys = { "listKey1".getBytes(), "listKey2".getBytes() }; + KeyValue> expectedKeyValue = new KeyValue<>("listKey2".getBytes(), Arrays.asList("value3".getBytes(), "value4".getBytes())); + + when(commandObjects.blmpop(timeout, direction, count, keys)).thenReturn(keyValueBytesListBytesCommandObject); + when(commandExecutor.executeCommand(keyValueBytesListBytesCommandObject)).thenReturn(expectedKeyValue); + + KeyValue> result = jedis.blmpop(timeout, direction, count, keys); + + assertThat(result, equalTo(expectedKeyValue)); + + verify(commandExecutor).executeCommand(keyValueBytesListBytesCommandObject); + verify(commandObjects).blmpop(timeout, direction, count, keys); + } + + @Test + public void testBlpop() { + int timeout = 10; // Timeout in seconds + String key = "listKey"; + List expectedValues = Arrays.asList(key, "value1"); + + when(commandObjects.blpop(timeout, key)).thenReturn(listStringCommandObject); + when(commandExecutor.executeCommand(listStringCommandObject)).thenReturn(expectedValues); + + List result = jedis.blpop(timeout, key); + + assertThat(result, equalTo(expectedValues)); + + verify(commandExecutor).executeCommand(listStringCommandObject); + verify(commandObjects).blpop(timeout, key); + } + + @Test + public void testBlpopBinary() { + int timeout = 10; // Timeout in seconds + byte[][] keys = { "listKey1".getBytes(), "listKey2".getBytes() }; + List expectedValues = Arrays.asList("listKey1".getBytes(), "value1".getBytes()); + + when(commandObjects.blpop(timeout, keys)).thenReturn(listBytesCommandObject); + when(commandExecutor.executeCommand(listBytesCommandObject)).thenReturn(expectedValues); + + List result = jedis.blpop(timeout, keys); + + assertThat(result, equalTo(expectedValues)); + + verify(commandExecutor).executeCommand(listBytesCommandObject); + verify(commandObjects).blpop(timeout, keys); + } + + @Test + public void testBlpopDoubleTimeout() { + double timeout = 10.5; // Timeout in seconds + String key = "listKey"; + KeyValue expectedKeyValue = new KeyValue<>(key, "value1"); + + when(commandObjects.blpop(timeout, key)).thenReturn(keyValueStringStringCommandObject); + when(commandExecutor.executeCommand(keyValueStringStringCommandObject)).thenReturn(expectedKeyValue); + + KeyValue result = jedis.blpop(timeout, key); + + assertThat(result, equalTo(expectedKeyValue)); + + verify(commandExecutor).executeCommand(keyValueStringStringCommandObject); + verify(commandObjects).blpop(timeout, key); + } + + @Test + public void testBlpopDoubleTimeoutBinary() { + double timeout = 10.5; // Timeout in seconds + byte[][] keys = { "listKey1".getBytes(), "listKey2".getBytes() }; + KeyValue expectedKeyValue = new KeyValue<>("listKey1".getBytes(), "value1".getBytes()); + + when(commandObjects.blpop(timeout, keys)).thenReturn(keyValueBytesBytesCommandObject); + when(commandExecutor.executeCommand(keyValueBytesBytesCommandObject)).thenReturn(expectedKeyValue); + + KeyValue result = jedis.blpop(timeout, keys); + + assertThat(result, equalTo(expectedKeyValue)); + + verify(commandExecutor).executeCommand(keyValueBytesBytesCommandObject); + verify(commandObjects).blpop(timeout, keys); + } + + @Test + public void testBlpopMultipleKeys() { + int timeout = 10; // Timeout in seconds + String[] keys = { "listKey1", "listKey2" }; + List expectedValues = Arrays.asList("listKey1", "value1"); + + when(commandObjects.blpop(timeout, keys)).thenReturn(listStringCommandObject); + when(commandExecutor.executeCommand(listStringCommandObject)).thenReturn(expectedValues); + + List result = jedis.blpop(timeout, keys); + + assertThat(result, equalTo(expectedValues)); + + verify(commandExecutor).executeCommand(listStringCommandObject); + verify(commandObjects).blpop(timeout, keys); + } + + @Test + public void testBlpopMultipleKeysDoubleTimeout() { + double timeout = 10.5; // Timeout in seconds + String[] keys = { "listKey1", "listKey2" }; + KeyValue expectedKeyValue = new KeyValue<>("listKey1", "value1"); + + when(commandObjects.blpop(timeout, keys)).thenReturn(keyValueStringStringCommandObject); + when(commandExecutor.executeCommand(keyValueStringStringCommandObject)).thenReturn(expectedKeyValue); + + KeyValue result = jedis.blpop(timeout, keys); + + assertThat(result, equalTo(expectedKeyValue)); + + verify(commandExecutor).executeCommand(keyValueStringStringCommandObject); + verify(commandObjects).blpop(timeout, keys); + } + + @Test + public void testBrpop() { + int timeout = 10; // Timeout in seconds + String key = "listKey"; + List expectedValues = Arrays.asList(key, "value1"); + + when(commandObjects.brpop(timeout, key)).thenReturn(listStringCommandObject); + when(commandExecutor.executeCommand(listStringCommandObject)).thenReturn(expectedValues); + + List result = jedis.brpop(timeout, key); + + assertThat(result, equalTo(expectedValues)); + + verify(commandExecutor).executeCommand(listStringCommandObject); + verify(commandObjects).brpop(timeout, key); + } + + @Test + public void testBrpopBinary() { + int timeout = 10; // Timeout in seconds + byte[][] keys = { "listKey1".getBytes(), "listKey2".getBytes() }; + List expectedValues = Arrays.asList("listKey1".getBytes(), "value1".getBytes()); + + when(commandObjects.brpop(timeout, keys)).thenReturn(listBytesCommandObject); + when(commandExecutor.executeCommand(listBytesCommandObject)).thenReturn(expectedValues); + + List result = jedis.brpop(timeout, keys); + + assertThat(result, equalTo(expectedValues)); + + verify(commandExecutor).executeCommand(listBytesCommandObject); + verify(commandObjects).brpop(timeout, keys); + } + + @Test + public void testBrpopDoubleTimeout() { + double timeout = 10.5; // Timeout in seconds + String key = "listKey"; + KeyValue expectedKeyValue = new KeyValue<>(key, "value1"); + + when(commandObjects.brpop(timeout, key)).thenReturn(keyValueStringStringCommandObject); + when(commandExecutor.executeCommand(keyValueStringStringCommandObject)).thenReturn(expectedKeyValue); + + KeyValue result = jedis.brpop(timeout, key); + + assertThat(result, equalTo(expectedKeyValue)); + + verify(commandExecutor).executeCommand(keyValueStringStringCommandObject); + verify(commandObjects).brpop(timeout, key); + } + + @Test + public void testBrpopDoubleTimeoutBinary() { + double timeout = 10.5; // Timeout in seconds + byte[][] keys = { "listKey1".getBytes(), "listKey2".getBytes() }; + KeyValue expectedKeyValue = new KeyValue<>("listKey1".getBytes(), "value1".getBytes()); + + when(commandObjects.brpop(timeout, keys)).thenReturn(keyValueBytesBytesCommandObject); + when(commandExecutor.executeCommand(keyValueBytesBytesCommandObject)).thenReturn(expectedKeyValue); + + KeyValue result = jedis.brpop(timeout, keys); + + assertThat(result, equalTo(expectedKeyValue)); + + verify(commandExecutor).executeCommand(keyValueBytesBytesCommandObject); + verify(commandObjects).brpop(timeout, keys); + } + + @Test + public void testBrpopMultipleKeys() { + int timeout = 10; // Timeout in seconds + String[] keys = { "listKey1", "listKey2" }; + List expectedValues = Arrays.asList("listKey1", "value1"); + + when(commandObjects.brpop(timeout, keys)).thenReturn(listStringCommandObject); + when(commandExecutor.executeCommand(listStringCommandObject)).thenReturn(expectedValues); + + List result = jedis.brpop(timeout, keys); + + assertThat(result, equalTo(expectedValues)); + + verify(commandExecutor).executeCommand(listStringCommandObject); + verify(commandObjects).brpop(timeout, keys); + } + + @Test + public void testBrpopMultipleKeysDoubleTimeout() { + double timeout = 10.5; // Timeout in seconds + String[] keys = { "listKey1", "listKey2" }; + KeyValue expectedKeyValue = new KeyValue<>("listKey1", "value1"); + + when(commandObjects.brpop(timeout, keys)).thenReturn(keyValueStringStringCommandObject); + when(commandExecutor.executeCommand(keyValueStringStringCommandObject)).thenReturn(expectedKeyValue); + + KeyValue result = jedis.brpop(timeout, keys); + + assertThat(result, equalTo(expectedKeyValue)); + + verify(commandExecutor).executeCommand(keyValueStringStringCommandObject); + verify(commandObjects).brpop(timeout, keys); + } + + @Test + public void testBrpoplpush() { + String source = "sourceList"; + String destination = "destinationList"; + int timeout = 10; // Timeout in seconds + String expectedPoppedAndPushedValue = "value"; + + when(commandObjects.brpoplpush(source, destination, timeout)).thenReturn(stringCommandObject); + when(commandExecutor.executeCommand(stringCommandObject)).thenReturn(expectedPoppedAndPushedValue); + + String result = jedis.brpoplpush(source, destination, timeout); + + assertThat(result, equalTo(expectedPoppedAndPushedValue)); + + verify(commandExecutor).executeCommand(stringCommandObject); + verify(commandObjects).brpoplpush(source, destination, timeout); + } + + @Test + public void testBrpoplpushBinary() { + byte[] source = "sourceList".getBytes(); + byte[] destination = "destinationList".getBytes(); + int timeout = 10; // Timeout in seconds + byte[] expectedPoppedAndPushedValue = "value".getBytes(); + + when(commandObjects.brpoplpush(source, destination, timeout)).thenReturn(bytesCommandObject); + when(commandExecutor.executeCommand(bytesCommandObject)).thenReturn(expectedPoppedAndPushedValue); + + byte[] result = jedis.brpoplpush(source, destination, timeout); + + assertThat(result, equalTo(expectedPoppedAndPushedValue)); + + verify(commandExecutor).executeCommand(bytesCommandObject); + verify(commandObjects).brpoplpush(source, destination, timeout); + } + + @Test + public void testLindex() { + String key = "listKey"; + long index = 1; // Get the element at index 1 + String expectedValue = "value2"; + + when(commandObjects.lindex(key, index)).thenReturn(stringCommandObject); + when(commandExecutor.executeCommand(stringCommandObject)).thenReturn(expectedValue); + + String result = jedis.lindex(key, index); + + assertThat(result, equalTo(expectedValue)); + + verify(commandExecutor).executeCommand(stringCommandObject); + verify(commandObjects).lindex(key, index); + } + + @Test + public void testLindexBinary() { + byte[] key = "listKey".getBytes(); + long index = 1; // Get the element at index 1 + byte[] expectedValue = "value2".getBytes(); + + when(commandObjects.lindex(key, index)).thenReturn(bytesCommandObject); + when(commandExecutor.executeCommand(bytesCommandObject)).thenReturn(expectedValue); + + byte[] result = jedis.lindex(key, index); + + assertThat(result, equalTo(expectedValue)); + + verify(commandExecutor).executeCommand(bytesCommandObject); + verify(commandObjects).lindex(key, index); + } + + @Test + public void testLinsert() { + String key = "listKey"; + ListPosition where = ListPosition.BEFORE; + String pivot = "pivotValue"; + String value = "newValue"; + long expectedInsertions = 1L; // Assuming one element was inserted + + when(commandObjects.linsert(key, where, pivot, value)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedInsertions); + + long result = jedis.linsert(key, where, pivot, value); + + assertThat(result, equalTo(expectedInsertions)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).linsert(key, where, pivot, value); + } + + @Test + public void testLinsertBinary() { + byte[] key = "listKey".getBytes(); + ListPosition where = ListPosition.AFTER; + byte[] pivot = "pivotValue".getBytes(); + byte[] value = "newValue".getBytes(); + long expectedInsertions = 1L; // Assuming one element was inserted + + when(commandObjects.linsert(key, where, pivot, value)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedInsertions); + + long result = jedis.linsert(key, where, pivot, value); + + assertThat(result, equalTo(expectedInsertions)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).linsert(key, where, pivot, value); + } + + @Test + public void testLlen() { + String key = "listKey"; + long expectedLength = 5L; // Assuming the length of the list is 5 + + when(commandObjects.llen(key)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedLength); + + long result = jedis.llen(key); + + assertThat(result, equalTo(expectedLength)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).llen(key); + } + + @Test + public void testLlenBinary() { + byte[] key = "listKey".getBytes(); + long expectedLength = 5L; // Assuming the length of the list is 5 + + when(commandObjects.llen(key)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedLength); + + long result = jedis.llen(key); + + assertThat(result, equalTo(expectedLength)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).llen(key); + } + + @Test + public void testLmove() { + String srcKey = "sourceList"; + String dstKey = "destinationList"; + ListDirection from = ListDirection.LEFT; + ListDirection to = ListDirection.RIGHT; + String expectedMovedValue = "value"; + when(commandObjects.lmove(srcKey, dstKey, from, to)).thenReturn(stringCommandObject); + when(commandExecutor.executeCommand(stringCommandObject)).thenReturn(expectedMovedValue); + + String result = jedis.lmove(srcKey, dstKey, from, to); + + assertThat(result, equalTo(expectedMovedValue)); + verify(commandExecutor).executeCommand(stringCommandObject); + verify(commandObjects).lmove(srcKey, dstKey, from, to); + } + + @Test + public void testLmoveBinary() { + byte[] srcKey = "sourceList".getBytes(); + byte[] dstKey = "destinationList".getBytes(); + ListDirection from = ListDirection.LEFT; + ListDirection to = ListDirection.RIGHT; + byte[] expectedMovedValue = "value".getBytes(); + + when(commandObjects.lmove(srcKey, dstKey, from, to)).thenReturn(bytesCommandObject); + when(commandExecutor.executeCommand(bytesCommandObject)).thenReturn(expectedMovedValue); + + byte[] result = jedis.lmove(srcKey, dstKey, from, to); + + assertThat(result, equalTo(expectedMovedValue)); + + verify(commandExecutor).executeCommand(bytesCommandObject); + verify(commandObjects).lmove(srcKey, dstKey, from, to); + } + + @Test + public void testLmpop() { + ListDirection direction = ListDirection.LEFT; + String[] keys = { "listKey1", "listKey2" }; + KeyValue> expectedKeyValue = new KeyValue<>("listKey1", Arrays.asList("value1", "value2")); + + when(commandObjects.lmpop(direction, keys)).thenReturn(keyValueStringListStringCommandObject); + when(commandExecutor.executeCommand(keyValueStringListStringCommandObject)).thenReturn(expectedKeyValue); + + KeyValue> result = jedis.lmpop(direction, keys); + + assertThat(result, equalTo(expectedKeyValue)); + + verify(commandExecutor).executeCommand(keyValueStringListStringCommandObject); + verify(commandObjects).lmpop(direction, keys); + } + + @Test + public void testLmpopBinary() { + ListDirection direction = ListDirection.LEFT; + byte[][] keys = { "listKey1".getBytes(), "listKey2".getBytes() }; + KeyValue> expectedKeyValue = new KeyValue<>("listKey1".getBytes(), Arrays.asList("value1".getBytes(), "value2".getBytes())); + + when(commandObjects.lmpop(direction, keys)).thenReturn(keyValueBytesListBytesCommandObject); + when(commandExecutor.executeCommand(keyValueBytesListBytesCommandObject)).thenReturn(expectedKeyValue); + + KeyValue> result = jedis.lmpop(direction, keys); + + assertThat(result, equalTo(expectedKeyValue)); + + verify(commandExecutor).executeCommand(keyValueBytesListBytesCommandObject); + verify(commandObjects).lmpop(direction, keys); + } + + @Test + public void testLmpopCount() { + ListDirection direction = ListDirection.RIGHT; + int count = 2; + String[] keys = { "listKey1", "listKey2" }; + KeyValue> expectedKeyValue = new KeyValue<>("listKey2", Arrays.asList("value3", "value4")); + + when(commandObjects.lmpop(direction, count, keys)).thenReturn(keyValueStringListStringCommandObject); + when(commandExecutor.executeCommand(keyValueStringListStringCommandObject)).thenReturn(expectedKeyValue); + + KeyValue> result = jedis.lmpop(direction, count, keys); + + assertThat(result, equalTo(expectedKeyValue)); + + verify(commandExecutor).executeCommand(keyValueStringListStringCommandObject); + verify(commandObjects).lmpop(direction, count, keys); + } + + @Test + public void testLmpopCountBinary() { + ListDirection direction = ListDirection.RIGHT; + int count = 2; + byte[][] keys = { "listKey1".getBytes(), "listKey2".getBytes() }; + KeyValue> expectedKeyValue = new KeyValue<>("listKey2".getBytes(), Arrays.asList("value3".getBytes(), "value4".getBytes())); + + when(commandObjects.lmpop(direction, count, keys)).thenReturn(keyValueBytesListBytesCommandObject); + when(commandExecutor.executeCommand(keyValueBytesListBytesCommandObject)).thenReturn(expectedKeyValue); + + KeyValue> result = jedis.lmpop(direction, count, keys); + + assertThat(result, equalTo(expectedKeyValue)); + + verify(commandExecutor).executeCommand(keyValueBytesListBytesCommandObject); + verify(commandObjects).lmpop(direction, count, keys); + } + + @Test + public void testLpop() { + String key = "listKey"; + String expectedPoppedValue = "poppedValue"; + + when(commandObjects.lpop(key)).thenReturn(stringCommandObject); + when(commandExecutor.executeCommand(stringCommandObject)).thenReturn(expectedPoppedValue); + + String result = jedis.lpop(key); + + assertThat(result, equalTo(expectedPoppedValue)); + + verify(commandExecutor).executeCommand(stringCommandObject); + verify(commandObjects).lpop(key); + } + + @Test + public void testLpopBinary() { + byte[] key = "listKey".getBytes(); + byte[] expectedPoppedValue = "poppedValue".getBytes(); + + when(commandObjects.lpop(key)).thenReturn(bytesCommandObject); + when(commandExecutor.executeCommand(bytesCommandObject)).thenReturn(expectedPoppedValue); + + byte[] result = jedis.lpop(key); + + assertThat(result, equalTo(expectedPoppedValue)); + + verify(commandExecutor).executeCommand(bytesCommandObject); + verify(commandObjects).lpop(key); + } + + @Test + public void testLpopCount() { + String key = "listKey"; + int count = 2; // Pop two elements + List expectedPoppedValues = Arrays.asList("value1", "value2"); + + when(commandObjects.lpop(key, count)).thenReturn(listStringCommandObject); + when(commandExecutor.executeCommand(listStringCommandObject)).thenReturn(expectedPoppedValues); + + List result = jedis.lpop(key, count); + + assertThat(result, equalTo(expectedPoppedValues)); + + verify(commandExecutor).executeCommand(listStringCommandObject); + verify(commandObjects).lpop(key, count); + } + + @Test + public void testLpopCountBinary() { + byte[] key = "listKey".getBytes(); + int count = 2; // Pop two elements + List expectedPoppedValues = Arrays.asList("value1".getBytes(), "value2".getBytes()); + + when(commandObjects.lpop(key, count)).thenReturn(listBytesCommandObject); + when(commandExecutor.executeCommand(listBytesCommandObject)).thenReturn(expectedPoppedValues); + + List result = jedis.lpop(key, count); + + assertThat(result, equalTo(expectedPoppedValues)); + + verify(commandExecutor).executeCommand(listBytesCommandObject); + verify(commandObjects).lpop(key, count); + } + + @Test + public void testLpos() { + String key = "listKey"; + String element = "valueToFind"; + Long expectedPosition = 1L; // Assuming the element is at index 1 + + when(commandObjects.lpos(key, element)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedPosition); + + Long result = jedis.lpos(key, element); + + assertThat(result, equalTo(expectedPosition)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).lpos(key, element); + } + + @Test + public void testLposBinary() { + byte[] key = "listKey".getBytes(); + byte[] element = "valueToFind".getBytes(); + Long expectedPosition = 1L; // Assuming the element is at index 1 + + when(commandObjects.lpos(key, element)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedPosition); + + Long result = jedis.lpos(key, element); + + assertThat(result, equalTo(expectedPosition)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).lpos(key, element); + } + + @Test + public void testLposWithParams() { + String key = "listKey"; + String element = "valueToFind"; + LPosParams params = new LPosParams().rank(2); // Find the second occurrence + Long expectedPosition = 3L; // Assuming the second occurrence is at index 3 + + when(commandObjects.lpos(key, element, params)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedPosition); + + Long result = jedis.lpos(key, element, params); + + assertThat(result, equalTo(expectedPosition)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).lpos(key, element, params); + } + + @Test + public void testLposWithParamsBinary() { + byte[] key = "listKey".getBytes(); + byte[] element = "valueToFind".getBytes(); + LPosParams params = new LPosParams().rank(2); // Find the second occurrence + Long expectedPosition = 3L; // Assuming the second occurrence is at index 3 + + when(commandObjects.lpos(key, element, params)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedPosition); + + Long result = jedis.lpos(key, element, params); + + assertThat(result, equalTo(expectedPosition)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).lpos(key, element, params); + } + + @Test + public void testLposWithParamsCount() { + String key = "listKey"; + String element = "valueToFind"; + LPosParams params = new LPosParams().rank(1); // Find the first occurrence + long count = 2; // Find up to two positions + List expectedPositions = Arrays.asList(1L, 4L); // Assuming occurrences at indexes 1 and 4 + + when(commandObjects.lpos(key, element, params, count)).thenReturn(listLongCommandObject); + when(commandExecutor.executeCommand(listLongCommandObject)).thenReturn(expectedPositions); + + List result = jedis.lpos(key, element, params, count); + + assertThat(result, equalTo(expectedPositions)); + + verify(commandExecutor).executeCommand(listLongCommandObject); + verify(commandObjects).lpos(key, element, params, count); + } + + @Test + public void testLposWithParamsCountBinary() { + byte[] key = "listKey".getBytes(); + byte[] element = "valueToFind".getBytes(); + LPosParams params = new LPosParams().rank(1); // Find the first occurrence + long count = 2; // Find up to two positions + List expectedPositions = Arrays.asList(1L, 4L); // Assuming occurrences at indexes 1 and 4 + + when(commandObjects.lpos(key, element, params, count)).thenReturn(listLongCommandObject); + when(commandExecutor.executeCommand(listLongCommandObject)).thenReturn(expectedPositions); + + List result = jedis.lpos(key, element, params, count); + + assertThat(result, equalTo(expectedPositions)); + + verify(commandExecutor).executeCommand(listLongCommandObject); + verify(commandObjects).lpos(key, element, params, count); + } + + @Test + public void testLpush() { + String key = "listKey"; + String[] strings = { "value1", "value2", "value3" }; + long expectedLength = 3L; // Assuming the new length of the list is 3 after LPUSH + + when(commandObjects.lpush(key, strings)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedLength); + + long result = jedis.lpush(key, strings); + + assertThat(result, equalTo(expectedLength)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).lpush(key, strings); + } + + @Test + public void testLpushBinary() { + byte[] key = "listKey".getBytes(); + byte[][] args = { "value1".getBytes(), "value2".getBytes(), "value3".getBytes() }; + long expectedLength = 3L; // Assuming the new length of the list is 3 after LPUSH + + when(commandObjects.lpush(key, args)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedLength); + + long result = jedis.lpush(key, args); + + assertThat(result, equalTo(expectedLength)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).lpush(key, args); + } + + @Test + public void testLpushx() { + String key = "listKey"; + String[] strings = { "value1", "value2" }; + long expectedLength = 5L; // Assuming the new length of the list is 5 after LPUSHX + + when(commandObjects.lpushx(key, strings)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedLength); + + long result = jedis.lpushx(key, strings); + + assertThat(result, equalTo(expectedLength)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).lpushx(key, strings); + } + + @Test + public void testLpushxBinary() { + byte[] key = "listKey".getBytes(); + byte[][] args = { "value1".getBytes(), "value2".getBytes() }; + long expectedLength = 5L; // Assuming the new length of the list is 5 after LPUSHX + + when(commandObjects.lpushx(key, args)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedLength); + + long result = jedis.lpushx(key, args); + + assertThat(result, equalTo(expectedLength)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).lpushx(key, args); + } + + @Test + public void testLrange() { + String key = "listKey"; + long start = 0; + long stop = -1; // Get all elements in the list + List expectedValues = Arrays.asList("value1", "value2", "value3"); + + when(commandObjects.lrange(key, start, stop)).thenReturn(listStringCommandObject); + when(commandExecutor.executeCommand(listStringCommandObject)).thenReturn(expectedValues); + + List result = jedis.lrange(key, start, stop); + + assertThat(result, equalTo(expectedValues)); + + verify(commandExecutor).executeCommand(listStringCommandObject); + verify(commandObjects).lrange(key, start, stop); + } + + @Test + public void testLrangeBinary() { + byte[] key = "listKey".getBytes(); + long start = 0; + long stop = -1; // Get all elements in the list + List expectedValues = Arrays.asList("value1".getBytes(), "value2".getBytes(), "value3".getBytes()); + + when(commandObjects.lrange(key, start, stop)).thenReturn(listBytesCommandObject); + when(commandExecutor.executeCommand(listBytesCommandObject)).thenReturn(expectedValues); + + List result = jedis.lrange(key, start, stop); + + assertThat(result, equalTo(expectedValues)); + + verify(commandExecutor).executeCommand(listBytesCommandObject); + verify(commandObjects).lrange(key, start, stop); + } + + @Test + public void testLrem() { + String key = "listKey"; + long count = 1; // Remove the first occurrence + String value = "valueToRemove"; + long expectedRemovals = 1L; // Assuming one element was removed + + when(commandObjects.lrem(key, count, value)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedRemovals); + + long result = jedis.lrem(key, count, value); + + assertThat(result, equalTo(expectedRemovals)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).lrem(key, count, value); + } + + @Test + public void testLremBinary() { + byte[] key = "listKey".getBytes(); + long count = 1; // Remove the first occurrence + byte[] value = "valueToRemove".getBytes(); + long expectedRemovals = 1L; // Assuming one element was removed + + when(commandObjects.lrem(key, count, value)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedRemovals); + + long result = jedis.lrem(key, count, value); + + assertThat(result, equalTo(expectedRemovals)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).lrem(key, count, value); + } + + @Test + public void testLtrim() { + String key = "listKey"; + long start = 1; + long stop = -1; // Trim the list to keep elements from index 1 to the end + String expectedResponse = "OK"; + + when(commandObjects.ltrim(key, start, stop)).thenReturn(stringCommandObject); + when(commandExecutor.executeCommand(stringCommandObject)).thenReturn(expectedResponse); + + String result = jedis.ltrim(key, start, stop); + + assertThat(result, equalTo(expectedResponse)); + + verify(commandExecutor).executeCommand(stringCommandObject); + verify(commandObjects).ltrim(key, start, stop); + } + + @Test + public void testLtrimBinary() { + byte[] key = "listKey".getBytes(); + long start = 1; + long stop = -1; // Trim the list to keep elements from index 1 to the end + String expectedResponse = "OK"; + + when(commandObjects.ltrim(key, start, stop)).thenReturn(stringCommandObject); + when(commandExecutor.executeCommand(stringCommandObject)).thenReturn(expectedResponse); + + String result = jedis.ltrim(key, start, stop); + + assertThat(result, equalTo(expectedResponse)); + + verify(commandExecutor).executeCommand(stringCommandObject); + verify(commandObjects).ltrim(key, start, stop); + } + + @Test + public void testLset() { + String key = "listKey"; + long index = 1; // Set the element at index 1 + String value = "newValue"; + String expectedResponse = "OK"; + + when(commandObjects.lset(key, index, value)).thenReturn(stringCommandObject); + when(commandExecutor.executeCommand(stringCommandObject)).thenReturn(expectedResponse); + + String result = jedis.lset(key, index, value); + + assertThat(result, equalTo(expectedResponse)); + + verify(commandExecutor).executeCommand(stringCommandObject); + verify(commandObjects).lset(key, index, value); + } + + @Test + public void testLsetBinary() { + byte[] key = "listKey".getBytes(); + long index = 1; // Set the element at index 1 + byte[] value = "newValue".getBytes(); + String expectedResponse = "OK"; + + when(commandObjects.lset(key, index, value)).thenReturn(stringCommandObject); + when(commandExecutor.executeCommand(stringCommandObject)).thenReturn(expectedResponse); + + String result = jedis.lset(key, index, value); + + assertThat(result, equalTo(expectedResponse)); + + verify(commandExecutor).executeCommand(stringCommandObject); + verify(commandObjects).lset(key, index, value); + } + + @Test + public void testRpop() { + String key = "listKey"; + String expectedPoppedValue = "poppedValue"; + + when(commandObjects.rpop(key)).thenReturn(stringCommandObject); + when(commandExecutor.executeCommand(stringCommandObject)).thenReturn(expectedPoppedValue); + + String result = jedis.rpop(key); + + assertThat(result, equalTo(expectedPoppedValue)); + + verify(commandExecutor).executeCommand(stringCommandObject); + verify(commandObjects).rpop(key); + } + + @Test + public void testRpopBinary() { + byte[] key = "listKey".getBytes(); + byte[] expectedPoppedValue = "poppedValue".getBytes(); + + when(commandObjects.rpop(key)).thenReturn(bytesCommandObject); + when(commandExecutor.executeCommand(bytesCommandObject)).thenReturn(expectedPoppedValue); + + byte[] result = jedis.rpop(key); + + assertThat(result, equalTo(expectedPoppedValue)); + + verify(commandExecutor).executeCommand(bytesCommandObject); + verify(commandObjects).rpop(key); + } + + @Test + public void testRpopCount() { + String key = "listKey"; + int count = 2; // Pop two elements + List expectedPoppedValues = Arrays.asList("value1", "value2"); + + when(commandObjects.rpop(key, count)).thenReturn(listStringCommandObject); + when(commandExecutor.executeCommand(listStringCommandObject)).thenReturn(expectedPoppedValues); + + List result = jedis.rpop(key, count); + + assertThat(result, equalTo(expectedPoppedValues)); + + verify(commandExecutor).executeCommand(listStringCommandObject); + verify(commandObjects).rpop(key, count); + } + + @Test + public void testRpopCountBinary() { + byte[] key = "listKey".getBytes(); + int count = 2; // Pop two elements + List expectedPoppedValues = Arrays.asList("value1".getBytes(), "value2".getBytes()); + + when(commandObjects.rpop(key, count)).thenReturn(listBytesCommandObject); + when(commandExecutor.executeCommand(listBytesCommandObject)).thenReturn(expectedPoppedValues); + + List result = jedis.rpop(key, count); + + assertThat(result, equalTo(expectedPoppedValues)); + + verify(commandExecutor).executeCommand(listBytesCommandObject); + verify(commandObjects).rpop(key, count); + } + + @Test + public void testRpoplpush() { + String srckey = "sourceList"; + String dstkey = "destinationList"; + String expectedPoppedAndPushedValue = "value"; + + when(commandObjects.rpoplpush(srckey, dstkey)).thenReturn(stringCommandObject); + when(commandExecutor.executeCommand(stringCommandObject)).thenReturn(expectedPoppedAndPushedValue); + + String result = jedis.rpoplpush(srckey, dstkey); + + assertThat(result, equalTo(expectedPoppedAndPushedValue)); + + verify(commandExecutor).executeCommand(stringCommandObject); + verify(commandObjects).rpoplpush(srckey, dstkey); + } + + @Test + public void testRpoplpushBinary() { + byte[] srckey = "sourceList".getBytes(); + byte[] dstkey = "destinationList".getBytes(); + byte[] expectedPoppedAndPushedValue = "value".getBytes(); + + when(commandObjects.rpoplpush(srckey, dstkey)).thenReturn(bytesCommandObject); + when(commandExecutor.executeCommand(bytesCommandObject)).thenReturn(expectedPoppedAndPushedValue); + + byte[] result = jedis.rpoplpush(srckey, dstkey); + + assertThat(result, equalTo(expectedPoppedAndPushedValue)); + + verify(commandExecutor).executeCommand(bytesCommandObject); + verify(commandObjects).rpoplpush(srckey, dstkey); + } + + @Test + public void testRpush() { + String key = "listKey"; + String[] strings = { "value1", "value2", "value3" }; + long expectedLength = 3L; // Assuming the new length of the list is 3 after RPUSH + + when(commandObjects.rpush(key, strings)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedLength); + + long result = jedis.rpush(key, strings); + + assertThat(result, equalTo(expectedLength)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).rpush(key, strings); + } + + @Test + public void testRpushBinary() { + byte[] key = "listKey".getBytes(); + byte[][] args = { "value1".getBytes(), "value2".getBytes(), "value3".getBytes() }; + long expectedLength = 3L; // Assuming the new length of the list is 3 after RPUSH + when(commandObjects.rpush(key, args)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedLength); + + long result = jedis.rpush(key, args); + + assertThat(result, equalTo(expectedLength)); + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).rpush(key, args); + } + + @Test + public void testRpushx() { + String key = "listKey"; + String[] strings = { "value1", "value2" }; + long expectedLength = 7L; // Assuming the new length of the list is 7 after RPUSHX + + when(commandObjects.rpushx(key, strings)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedLength); + + long result = jedis.rpushx(key, strings); + + assertThat(result, equalTo(expectedLength)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).rpushx(key, strings); + } + + @Test + public void testRpushxBinary() { + byte[] key = "listKey".getBytes(); + byte[][] args = { "value1".getBytes(), "value2".getBytes() }; + long expectedLength = 7L; // Assuming the new length of the list is 7 after RPUSHX + + when(commandObjects.rpushx(key, args)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedLength); + + long result = jedis.rpushx(key, args); + + assertThat(result, equalTo(expectedLength)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).rpushx(key, args); + } + +} diff --git a/src/test/java/redis/clients/jedis/mocked/unified/UnifiedJedisMockedTestBase.java b/src/test/java/redis/clients/jedis/mocked/unified/UnifiedJedisMockedTestBase.java new file mode 100644 index 00000000000..55fb55b5cdb --- /dev/null +++ b/src/test/java/redis/clients/jedis/mocked/unified/UnifiedJedisMockedTestBase.java @@ -0,0 +1,66 @@ +package redis.clients.jedis.mocked.unified; + +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyNoMoreInteractions; + +import org.junit.After; +import org.junit.Before; +import org.mockito.Mock; +import redis.clients.jedis.CommandObject; +import redis.clients.jedis.CommandObjects; +import redis.clients.jedis.UnifiedJedis; +import redis.clients.jedis.executors.CommandExecutor; +import redis.clients.jedis.mocked.MockedCommandObjectsTestBase; +import redis.clients.jedis.providers.ConnectionProvider; + +/** + * Base class for {@link UnifiedJedis} mocked unit tests. Exposes a {@link UnifiedJedis} instance that + * uses mocked executors, providers and command objects, which can be asserted upon. + */ +public abstract class UnifiedJedisMockedTestBase extends MockedCommandObjectsTestBase { + + /** + * The {@link UnifiedJedis} instance under-test. + */ + protected UnifiedJedis jedis; + + /** + * Mocked {@link CommandExecutor} instance. Instead of going to the wire and exchanging data + * with a real Redis server, this instance is trained to returned pre-packaged response data, + * depending on what is being tested. + */ + @Mock + protected CommandExecutor commandExecutor; + + /** + * Mocked {@link ConnectionProvider}. This is not really used in tests, except in some very + * specific test cases. + */ + @Mock + protected ConnectionProvider connectionProvider; + + /** + * {@link CommandObjects} instance used by the {@link UnifiedJedis} under-test. Depending on + * the test case, it is trained to return one of the mock {@link CommandObject} instances inherited + * from the superclass. + */ + @Mock + protected CommandObjects commandObjects; + + @Before + public void setUp() { + jedis = new UnifiedJedis(commandExecutor, connectionProvider, commandObjects); + } + + @After + public void tearDown() { + // We want to be accurate about our mocks, hence we verify no more interactions here. + // This might mean that some methods need to verify their interactions in a more verbose way, + // but overall the benefit should be greater than the cost. + verify(connectionProvider).getConnection(); + verifyNoMoreInteractions(connectionProvider); + verifyNoMoreInteractions(commandExecutor); + verifyNoMoreInteractions(commandObjects); + } + +} diff --git a/src/test/java/redis/clients/jedis/mocked/unified/UnifiedJedisPubSubCommandsTest.java b/src/test/java/redis/clients/jedis/mocked/unified/UnifiedJedisPubSubCommandsTest.java new file mode 100644 index 00000000000..ee5db612556 --- /dev/null +++ b/src/test/java/redis/clients/jedis/mocked/unified/UnifiedJedisPubSubCommandsTest.java @@ -0,0 +1,46 @@ +package redis.clients.jedis.mocked.unified; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.equalTo; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import org.junit.Test; + +public class UnifiedJedisPubSubCommandsTest extends UnifiedJedisMockedTestBase { + + @Test + public void testPublishWithStringChannelAndMessage() { + String channel = "myChannel"; + String message = "Hello, World!"; + long expectedPublishCount = 10L; + + when(commandObjects.publish(channel, message)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedPublishCount); + + long result = jedis.publish(channel, message); + + assertThat(result, equalTo(expectedPublishCount)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).publish(channel, message); + } + + @Test + public void testPublishWithByteArrayChannelAndMessage() { + byte[] channel = "myChannel".getBytes(); + byte[] message = "Hello, World!".getBytes(); + long expectedPublishCount = 10L; + + when(commandObjects.publish(channel, message)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedPublishCount); + + long result = jedis.publish(channel, message); + + assertThat(result, equalTo(expectedPublishCount)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).publish(channel, message); + } + +} diff --git a/src/test/java/redis/clients/jedis/mocked/unified/UnifiedJedisScriptingAndFunctionsCommandsTest.java b/src/test/java/redis/clients/jedis/mocked/unified/UnifiedJedisScriptingAndFunctionsCommandsTest.java new file mode 100644 index 00000000000..8ab868ad417 --- /dev/null +++ b/src/test/java/redis/clients/jedis/mocked/unified/UnifiedJedisScriptingAndFunctionsCommandsTest.java @@ -0,0 +1,1049 @@ +package redis.clients.jedis.mocked.unified; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.sameInstance; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +import org.junit.Test; +import redis.clients.jedis.args.FlushMode; +import redis.clients.jedis.args.FunctionRestorePolicy; +import redis.clients.jedis.resps.FunctionStats; +import redis.clients.jedis.resps.LibraryInfo; + +public class UnifiedJedisScriptingAndFunctionsCommandsTest extends UnifiedJedisMockedTestBase { + + @Test + public void testEval() { + String script = "return 1"; + Object expectedEvalResult = 1; + + when(commandObjects.eval(script)).thenReturn(objectCommandObject); + when(commandExecutor.executeCommand(objectCommandObject)).thenReturn(expectedEvalResult); + + Object result = jedis.eval(script); + + assertThat(result, equalTo(expectedEvalResult)); + + verify(commandExecutor).executeCommand(objectCommandObject); + verify(commandObjects).eval(script); + } + + @Test + public void testEvalBinary() { + byte[] script = "return 1".getBytes(); + Object expectedEvalResult = 1; + + when(commandObjects.eval(script)).thenReturn(objectCommandObject); + when(commandExecutor.executeCommand(objectCommandObject)).thenReturn(expectedEvalResult); + + Object result = jedis.eval(script); + + assertThat(result, equalTo(expectedEvalResult)); + + verify(commandExecutor).executeCommand(objectCommandObject); + verify(commandObjects).eval(script); + } + + @Test + public void testEvalWithParams() { + String script = "return KEYS[1]"; + int keyCount = 1; + String[] params = { "key1" }; + Object expectedEvalResult = "key1"; + + when(commandObjects.eval(script, keyCount, params)).thenReturn(objectCommandObject); + when(commandExecutor.executeCommand(objectCommandObject)).thenReturn(expectedEvalResult); + + Object result = jedis.eval(script, keyCount, params); + + assertThat(result, equalTo(expectedEvalResult)); + + verify(commandExecutor).executeCommand(objectCommandObject); + verify(commandObjects).eval(script, keyCount, params); + } + + @Test + public void testEvalWithParamsBinary() { + byte[] script = "return KEYS[1]".getBytes(); + int keyCount = 1; + byte[][] params = { "key1".getBytes() }; + Object expectedEvalResult = "key1".getBytes(); + + when(commandObjects.eval(script, keyCount, params)).thenReturn(objectCommandObject); + when(commandExecutor.executeCommand(objectCommandObject)).thenReturn(expectedEvalResult); + + Object result = jedis.eval(script, keyCount, params); + + assertThat(result, equalTo(expectedEvalResult)); + + verify(commandExecutor).executeCommand(objectCommandObject); + verify(commandObjects).eval(script, keyCount, params); + } + + @Test + public void testEvalWithLists() { + String script = "return KEYS[1]"; + List keys = Collections.singletonList("key1"); + List args = Collections.emptyList(); + Object expectedEvalResult = "key1"; + + when(commandObjects.eval(script, keys, args)).thenReturn(objectCommandObject); + when(commandExecutor.executeCommand(objectCommandObject)).thenReturn(expectedEvalResult); + + Object result = jedis.eval(script, keys, args); + + assertThat(result, equalTo(expectedEvalResult)); + + verify(commandExecutor).executeCommand(objectCommandObject); + verify(commandObjects).eval(script, keys, args); + } + + @Test + public void testEvalWithListsBinary() { + byte[] script = "return KEYS[1]".getBytes(); + List keys = Collections.singletonList("key1".getBytes()); + List args = Collections.emptyList(); + Object expectedEvalResult = "key1".getBytes(); + + when(commandObjects.eval(script, keys, args)).thenReturn(objectCommandObject); + when(commandExecutor.executeCommand(objectCommandObject)).thenReturn(expectedEvalResult); + + Object result = jedis.eval(script, keys, args); + + assertThat(result, equalTo(expectedEvalResult)); + + verify(commandExecutor).executeCommand(objectCommandObject); + verify(commandObjects).eval(script, keys, args); + } + + @Test + public void testEvalWithSampleKey() { + String script = "return redis.call('get', KEYS[1])"; + String sampleKey = "myKey"; + Object expectedResponse = "value"; + + when(commandObjects.eval(script, sampleKey)).thenReturn(objectCommandObject); + when(commandExecutor.executeCommand(objectCommandObject)).thenReturn(expectedResponse); + + Object result = jedis.eval(script, sampleKey); + + assertThat(result, equalTo(expectedResponse)); + + verify(commandExecutor).executeCommand(objectCommandObject); + verify(commandObjects).eval(script, sampleKey); + } + + @Test + public void testEvalWithSampleKeyBinary() { + byte[] script = "return redis.call('get', KEYS[1])".getBytes(); + byte[] sampleKey = "myKey".getBytes(); + Object expectedResponse = "value".getBytes(); + + when(commandObjects.eval(script, sampleKey)).thenReturn(objectCommandObject); + when(commandExecutor.executeCommand(objectCommandObject)).thenReturn(expectedResponse); + + Object result = jedis.eval(script, sampleKey); + + assertThat(result, equalTo(expectedResponse)); + + verify(commandExecutor).executeCommand(objectCommandObject); + verify(commandObjects).eval(script, sampleKey); + } + + @Test + public void testEvalReadonly() { + String script = "return KEYS[1]"; + List keys = Collections.singletonList("key1"); + List args = Collections.emptyList(); + Object expectedEvalResult = "key1"; + + when(commandObjects.evalReadonly(script, keys, args)).thenReturn(objectCommandObject); + when(commandExecutor.executeCommand(objectCommandObject)).thenReturn(expectedEvalResult); + + Object result = jedis.evalReadonly(script, keys, args); + + assertThat(result, equalTo(expectedEvalResult)); + + verify(commandExecutor).executeCommand(objectCommandObject); + verify(commandObjects).evalReadonly(script, keys, args); + } + + @Test + public void testEvalReadonlyBinary() { + byte[] script = "return KEYS[1]".getBytes(); + List keys = Collections.singletonList("key1".getBytes()); + List args = Collections.emptyList(); + Object expectedEvalResult = "key1".getBytes(); + + when(commandObjects.evalReadonly(script, keys, args)).thenReturn(objectCommandObject); + when(commandExecutor.executeCommand(objectCommandObject)).thenReturn(expectedEvalResult); + + Object result = jedis.evalReadonly(script, keys, args); + + assertThat(result, equalTo(expectedEvalResult)); + + verify(commandExecutor).executeCommand(objectCommandObject); + verify(commandObjects).evalReadonly(script, keys, args); + } + + @Test + public void testEvalsha() { + String sha1 = "someSha1Hash"; + Object expectedEvalshaResult = 1; + + when(commandObjects.evalsha(sha1)).thenReturn(objectCommandObject); + when(commandExecutor.executeCommand(objectCommandObject)).thenReturn(expectedEvalshaResult); + + Object result = jedis.evalsha(sha1); + + assertThat(result, equalTo(expectedEvalshaResult)); + + verify(commandExecutor).executeCommand(objectCommandObject); + verify(commandObjects).evalsha(sha1); + } + + @Test + public void testEvalshaBinary() { + byte[] sha1 = "someSha1Hash".getBytes(); + Object expectedEvalshaResult = 1; + + when(commandObjects.evalsha(sha1)).thenReturn(objectCommandObject); + when(commandExecutor.executeCommand(objectCommandObject)).thenReturn(expectedEvalshaResult); + + Object result = jedis.evalsha(sha1); + + assertThat(result, equalTo(expectedEvalshaResult)); + + verify(commandExecutor).executeCommand(objectCommandObject); + verify(commandObjects).evalsha(sha1); + } + + @Test + public void testEvalshaWithParams() { + String sha1 = "someSha1Hash"; + int keyCount = 1; + String[] params = { "key1" }; + Object expectedEvalshaResult = "key1"; + + when(commandObjects.evalsha(sha1, keyCount, params)).thenReturn(objectCommandObject); + when(commandExecutor.executeCommand(objectCommandObject)).thenReturn(expectedEvalshaResult); + + Object result = jedis.evalsha(sha1, keyCount, params); + + assertThat(result, equalTo(expectedEvalshaResult)); + + verify(commandExecutor).executeCommand(objectCommandObject); + verify(commandObjects).evalsha(sha1, keyCount, params); + } + + @Test + public void testEvalshaWithParamsBinary() { + byte[] sha1 = "someSha1Hash".getBytes(); + int keyCount = 1; + byte[][] params = { "key1".getBytes() }; + Object expectedEvalshaResult = "key1".getBytes(); + + when(commandObjects.evalsha(sha1, keyCount, params)).thenReturn(objectCommandObject); + when(commandExecutor.executeCommand(objectCommandObject)).thenReturn(expectedEvalshaResult); + + Object result = jedis.evalsha(sha1, keyCount, params); + + assertThat(result, equalTo(expectedEvalshaResult)); + + verify(commandExecutor).executeCommand(objectCommandObject); + verify(commandObjects).evalsha(sha1, keyCount, params); + } + + @Test + public void testEvalshaWithLists() { + String sha1 = "someSha1Hash"; + List keys = Collections.singletonList("key1"); + List args = Collections.emptyList(); + Object expectedEvalshaResult = "key1"; + + when(commandObjects.evalsha(sha1, keys, args)).thenReturn(objectCommandObject); + when(commandExecutor.executeCommand(objectCommandObject)).thenReturn(expectedEvalshaResult); + + Object result = jedis.evalsha(sha1, keys, args); + + assertThat(result, equalTo(expectedEvalshaResult)); + + verify(commandExecutor).executeCommand(objectCommandObject); + verify(commandObjects).evalsha(sha1, keys, args); + } + + @Test + public void testEvalshaWithListsBinary() { + byte[] sha1 = "someSha1Hash".getBytes(); + List keys = Collections.singletonList("key1".getBytes()); + List args = Collections.emptyList(); + Object expectedEvalshaResult = "key1".getBytes(); + + when(commandObjects.evalsha(sha1, keys, args)).thenReturn(objectCommandObject); + when(commandExecutor.executeCommand(objectCommandObject)).thenReturn(expectedEvalshaResult); + + Object result = jedis.evalsha(sha1, keys, args); + + assertThat(result, equalTo(expectedEvalshaResult)); + + verify(commandExecutor).executeCommand(objectCommandObject); + verify(commandObjects).evalsha(sha1, keys, args); + } + + @Test + public void testEvalshaWithSampleKey() { + String sha1 = "someSha1Hash"; + String sampleKey = "myKey"; + Object expectedResponse = "value"; + + when(commandObjects.evalsha(sha1, sampleKey)).thenReturn(objectCommandObject); + when(commandExecutor.executeCommand(objectCommandObject)).thenReturn(expectedResponse); + + Object result = jedis.evalsha(sha1, sampleKey); + + assertThat(result, equalTo(expectedResponse)); + + verify(commandExecutor).executeCommand(objectCommandObject); + verify(commandObjects).evalsha(sha1, sampleKey); + } + + @Test + public void testEvalshaWithSampleKeyBinary() { + byte[] sha1 = "someSha1Hash".getBytes(); + byte[] sampleKey = "myKey".getBytes(); + Object expectedResponse = "value".getBytes(); + + when(commandObjects.evalsha(sha1, sampleKey)).thenReturn(objectCommandObject); + when(commandExecutor.executeCommand(objectCommandObject)).thenReturn(expectedResponse); + + Object result = jedis.evalsha(sha1, sampleKey); + + assertThat(result, equalTo(expectedResponse)); + + verify(commandExecutor).executeCommand(objectCommandObject); + verify(commandObjects).evalsha(sha1, sampleKey); + } + + @Test + public void testEvalshaReadonly() { + String sha1 = "someSha1Hash"; + List keys = Collections.singletonList("key1"); + List args = Collections.emptyList(); + Object expectedEvalshaResult = "key1"; + + when(commandObjects.evalshaReadonly(sha1, keys, args)).thenReturn(objectCommandObject); + when(commandExecutor.executeCommand(objectCommandObject)).thenReturn(expectedEvalshaResult); + + Object result = jedis.evalshaReadonly(sha1, keys, args); + + assertThat(result, equalTo(expectedEvalshaResult)); + + verify(commandExecutor).executeCommand(objectCommandObject); + verify(commandObjects).evalshaReadonly(sha1, keys, args); + } + + @Test + public void testEvalshaReadonlyBinary() { + byte[] sha1 = "someSha1Hash".getBytes(); + List keys = Collections.singletonList("key1".getBytes()); + List args = Collections.emptyList(); + Object expectedEvalshaResult = "key1".getBytes(); + + when(commandObjects.evalshaReadonly(sha1, keys, args)).thenReturn(objectCommandObject); + when(commandExecutor.executeCommand(objectCommandObject)).thenReturn(expectedEvalshaResult); + + Object result = jedis.evalshaReadonly(sha1, keys, args); + + assertThat(result, equalTo(expectedEvalshaResult)); + + verify(commandExecutor).executeCommand(objectCommandObject); + verify(commandObjects).evalshaReadonly(sha1, keys, args); + } + + @Test + public void testFcall() { + String name = "myFunction"; + List keys = Collections.singletonList("key1"); + List args = Collections.singletonList("arg1"); + Object expectedFcallResult = "someResult"; + + when(commandObjects.fcall(name, keys, args)).thenReturn(objectCommandObject); + when(commandExecutor.executeCommand(objectCommandObject)).thenReturn(expectedFcallResult); + + Object result = jedis.fcall(name, keys, args); + + assertThat(result, equalTo(expectedFcallResult)); + + verify(commandExecutor).executeCommand(objectCommandObject); + verify(commandObjects).fcall(name, keys, args); + } + + @Test + public void testFcallBinary() { + byte[] name = "myFunction".getBytes(); + List keys = Collections.singletonList("key1".getBytes()); + List args = Collections.singletonList("arg1".getBytes()); + Object expectedFcallResult = "someResult".getBytes(); + + when(commandObjects.fcall(name, keys, args)).thenReturn(objectCommandObject); + when(commandExecutor.executeCommand(objectCommandObject)).thenReturn(expectedFcallResult); + + Object result = jedis.fcall(name, keys, args); + + assertThat(result, equalTo(expectedFcallResult)); + + verify(commandExecutor).executeCommand(objectCommandObject); + verify(commandObjects).fcall(name, keys, args); + } + + @Test + public void testFcallReadonly() { + String name = "myFunction"; + List keys = Collections.singletonList("key1"); + List args = Collections.singletonList("arg1"); + Object expectedFcallResult = "someResult"; + + when(commandObjects.fcallReadonly(name, keys, args)).thenReturn(objectCommandObject); + when(commandExecutor.executeCommand(objectCommandObject)).thenReturn(expectedFcallResult); + + Object result = jedis.fcallReadonly(name, keys, args); + + assertThat(result, equalTo(expectedFcallResult)); + + verify(commandExecutor).executeCommand(objectCommandObject); + verify(commandObjects).fcallReadonly(name, keys, args); + } + + @Test + public void testFcallReadonlyBinary() { + byte[] name = "myFunction".getBytes(); + List keys = Collections.singletonList("key1".getBytes()); + List args = Collections.singletonList("arg1".getBytes()); + Object expectedFcallResult = "someResult".getBytes(); + + when(commandObjects.fcallReadonly(name, keys, args)).thenReturn(objectCommandObject); + when(commandExecutor.executeCommand(objectCommandObject)).thenReturn(expectedFcallResult); + + Object result = jedis.fcallReadonly(name, keys, args); + + assertThat(result, equalTo(expectedFcallResult)); + + verify(commandExecutor).executeCommand(objectCommandObject); + verify(commandObjects).fcallReadonly(name, keys, args); + } + + @Test + public void testFunctionDelete() { + String libraryName = "mylib"; + String expectedResponse = "OK"; + + when(commandObjects.functionDelete(libraryName)).thenReturn(stringCommandObject); + when(commandExecutor.broadcastCommand(stringCommandObject)).thenReturn(expectedResponse); + + String result = jedis.functionDelete(libraryName); + + assertThat(result, equalTo(expectedResponse)); + + verify(commandExecutor).broadcastCommand(stringCommandObject); + verify(commandObjects).functionDelete(libraryName); + } + + @Test + public void testFunctionDeleteBinary() { + byte[] libraryName = "mylib".getBytes(); + String expectedResponse = "OK"; + + when(commandObjects.functionDelete(libraryName)).thenReturn(stringCommandObject); + when(commandExecutor.broadcastCommand(stringCommandObject)).thenReturn(expectedResponse); + + String result = jedis.functionDelete(libraryName); + + assertThat(result, equalTo(expectedResponse)); + + verify(commandExecutor).broadcastCommand(stringCommandObject); + verify(commandObjects).functionDelete(libraryName); + } + + @Test + public void testFunctionDump() { + byte[] expectedDump = "someSerializedData".getBytes(); + + when(commandObjects.functionDump()).thenReturn(bytesCommandObject); + when(commandExecutor.executeCommand(bytesCommandObject)).thenReturn(expectedDump); + + byte[] result = jedis.functionDump(); + + assertThat(result, equalTo(expectedDump)); + + verify(commandExecutor).executeCommand(bytesCommandObject); + verify(commandObjects).functionDump(); + } + + @Test + public void testFunctionFlush() { + String expectedResponse = "OK"; + + when(commandObjects.functionFlush()).thenReturn(stringCommandObject); + when(commandExecutor.broadcastCommand(stringCommandObject)).thenReturn(expectedResponse); + + String result = jedis.functionFlush(); + + assertThat(result, equalTo(expectedResponse)); + + verify(commandExecutor).broadcastCommand(stringCommandObject); + verify(commandObjects).functionFlush(); + } + + @Test + public void testFunctionFlushWithMode() { + FlushMode mode = FlushMode.ASYNC; + String expectedResponse = "OK"; + + when(commandObjects.functionFlush(mode)).thenReturn(stringCommandObject); + when(commandExecutor.broadcastCommand(stringCommandObject)).thenReturn(expectedResponse); + + String result = jedis.functionFlush(mode); + + assertThat(result, equalTo(expectedResponse)); + + verify(commandExecutor).broadcastCommand(stringCommandObject); + verify(commandObjects).functionFlush(mode); + } + + @Test + public void testFunctionKill() { + String expectedResponse = "OK"; + + when(commandObjects.functionKill()).thenReturn(stringCommandObject); + when(commandExecutor.broadcastCommand(stringCommandObject)).thenReturn(expectedResponse); + + String result = jedis.functionKill(); + + assertThat(result, equalTo(expectedResponse)); + + verify(commandExecutor).broadcastCommand(stringCommandObject); + verify(commandObjects).functionKill(); + } + + @Test + public void testFunctionList() { + List expectedLibraryInfoList = new ArrayList<>(); + + when(commandObjects.functionList()).thenReturn(listLibraryInfoCommandObject); + when(commandExecutor.executeCommand(listLibraryInfoCommandObject)).thenReturn(expectedLibraryInfoList); + + List result = jedis.functionList(); + + assertThat(result, equalTo(expectedLibraryInfoList)); + + verify(commandExecutor).executeCommand(listLibraryInfoCommandObject); + verify(commandObjects).functionList(); + } + + @Test + public void testFunctionListBinary() { + List expectedFunctionListBinary = new ArrayList<>(); + + when(commandObjects.functionListBinary()).thenReturn(listObjectCommandObject); + when(commandExecutor.executeCommand(listObjectCommandObject)).thenReturn(expectedFunctionListBinary); + + List result = jedis.functionListBinary(); + + assertThat(result, equalTo(expectedFunctionListBinary)); + + verify(commandExecutor).executeCommand(listObjectCommandObject); + verify(commandObjects).functionListBinary(); + } + + @Test + public void testFunctionListWithPattern() { + String libraryNamePattern = "mylib*"; + List expectedLibraryInfoList = new ArrayList<>(); + + when(commandObjects.functionList(libraryNamePattern)).thenReturn(listLibraryInfoCommandObject); + when(commandExecutor.executeCommand(listLibraryInfoCommandObject)).thenReturn(expectedLibraryInfoList); + + List result = jedis.functionList(libraryNamePattern); + + assertThat(result, equalTo(expectedLibraryInfoList)); + + verify(commandExecutor).executeCommand(listLibraryInfoCommandObject); + verify(commandObjects).functionList(libraryNamePattern); + } + + @Test + public void testFunctionListWithPatternBinary() { + byte[] libraryNamePattern = "mylib*".getBytes(); + List expectedFunctionList = new ArrayList<>(); + + when(commandObjects.functionList(libraryNamePattern)).thenReturn(listObjectCommandObject); + when(commandExecutor.executeCommand(listObjectCommandObject)).thenReturn(expectedFunctionList); + + List result = jedis.functionList(libraryNamePattern); + + assertThat(result, equalTo(expectedFunctionList)); + + verify(commandExecutor).executeCommand(listObjectCommandObject); + verify(commandObjects).functionList(libraryNamePattern); + } + + @Test + public void testFunctionListWithCode() { + List expectedLibraryInfoList = new ArrayList<>(); + + when(commandObjects.functionListWithCode()).thenReturn(listLibraryInfoCommandObject); + when(commandExecutor.executeCommand(listLibraryInfoCommandObject)).thenReturn(expectedLibraryInfoList); + + List result = jedis.functionListWithCode(); + + assertThat(result, equalTo(expectedLibraryInfoList)); + + verify(commandExecutor).executeCommand(listLibraryInfoCommandObject); + verify(commandObjects).functionListWithCode(); + } + + @Test + public void testFunctionListWithCodeBinary() { + List expectedFunctionListWithCodeBinary = new ArrayList<>(); + + when(commandObjects.functionListWithCodeBinary()).thenReturn(listObjectCommandObject); + when(commandExecutor.executeCommand(listObjectCommandObject)).thenReturn(expectedFunctionListWithCodeBinary); + + List result = jedis.functionListWithCodeBinary(); + + assertThat(result, equalTo(expectedFunctionListWithCodeBinary)); + + verify(commandExecutor).executeCommand(listObjectCommandObject); + verify(commandObjects).functionListWithCodeBinary(); + } + + @Test + public void testFunctionListWithCodeAndPattern() { + String libraryNamePattern = "mylib*"; + List expectedLibraryInfoList = new ArrayList<>(); + + when(commandObjects.functionListWithCode(libraryNamePattern)).thenReturn(listLibraryInfoCommandObject); + when(commandExecutor.executeCommand(listLibraryInfoCommandObject)).thenReturn(expectedLibraryInfoList); + + List result = jedis.functionListWithCode(libraryNamePattern); + + assertThat(result, equalTo(expectedLibraryInfoList)); + + verify(commandExecutor).executeCommand(listLibraryInfoCommandObject); + verify(commandObjects).functionListWithCode(libraryNamePattern); + } + + @Test + public void testFunctionListWithCodeAndPatternBinary() { + byte[] libraryNamePattern = "mylib*".getBytes(); + List expectedFunctionListWithCode = new ArrayList<>(); + + when(commandObjects.functionListWithCode(libraryNamePattern)).thenReturn(listObjectCommandObject); + when(commandExecutor.executeCommand(listObjectCommandObject)).thenReturn(expectedFunctionListWithCode); + + List result = jedis.functionListWithCode(libraryNamePattern); + + assertThat(result, equalTo(expectedFunctionListWithCode)); + + verify(commandExecutor).executeCommand(listObjectCommandObject); + verify(commandObjects).functionListWithCode(libraryNamePattern); + } + + @Test + public void testFunctionLoad() { + String functionCode = "function myfunc() return 'hello' end"; + String expectedResponse = "OK"; + + when(commandObjects.functionLoad(functionCode)).thenReturn(stringCommandObject); + when(commandExecutor.broadcastCommand(stringCommandObject)).thenReturn(expectedResponse); + + String result = jedis.functionLoad(functionCode); + + assertThat(result, equalTo(expectedResponse)); + + verify(commandExecutor).broadcastCommand(stringCommandObject); + verify(commandObjects).functionLoad(functionCode); + } + + @Test + public void testFunctionLoadWithBinary() { + byte[] functionCode = "function myfunc() return 'hello' end".getBytes(); + String expectedResponse = "OK"; + + when(commandObjects.functionLoad(functionCode)).thenReturn(stringCommandObject); + when(commandExecutor.broadcastCommand(stringCommandObject)).thenReturn(expectedResponse); + + String result = jedis.functionLoad(functionCode); + + assertThat(result, equalTo(expectedResponse)); + + verify(commandExecutor).broadcastCommand(stringCommandObject); + verify(commandObjects).functionLoad(functionCode); + } + + @Test + public void testFunctionLoadReplace() { + String functionCode = "function myfunc() return 'hello' end"; + String expectedResponse = "OK"; + + when(commandObjects.functionLoadReplace(functionCode)).thenReturn(stringCommandObject); + when(commandExecutor.broadcastCommand(stringCommandObject)).thenReturn(expectedResponse); + + String result = jedis.functionLoadReplace(functionCode); + + assertThat(result, equalTo(expectedResponse)); + + verify(commandExecutor).broadcastCommand(stringCommandObject); + verify(commandObjects).functionLoadReplace(functionCode); + } + + @Test + public void testFunctionLoadReplaceBinary() { + byte[] functionCode = "function myfunc() return 'hello' end".getBytes(); + String expectedResponse = "OK"; + + when(commandObjects.functionLoadReplace(functionCode)).thenReturn(stringCommandObject); + when(commandExecutor.broadcastCommand(stringCommandObject)).thenReturn(expectedResponse); + + String result = jedis.functionLoadReplace(functionCode); + + assertThat(result, equalTo(expectedResponse)); + + verify(commandExecutor).broadcastCommand(stringCommandObject); + verify(commandObjects).functionLoadReplace(functionCode); + } + + @Test + public void testFunctionRestore() { + byte[] serializedValue = "serializedData".getBytes(); + String expectedResponse = "OK"; + + when(commandObjects.functionRestore(serializedValue)).thenReturn(stringCommandObject); + when(commandExecutor.broadcastCommand(stringCommandObject)).thenReturn(expectedResponse); + + String result = jedis.functionRestore(serializedValue); + + assertThat(result, equalTo(expectedResponse)); + + verify(commandExecutor).broadcastCommand(stringCommandObject); + verify(commandObjects).functionRestore(serializedValue); + } + + @Test + public void testFunctionRestoreWithPolicy() { + byte[] serializedValue = "serializedData".getBytes(); + FunctionRestorePolicy policy = FunctionRestorePolicy.FLUSH; + String expectedResponse = "OK"; + + when(commandObjects.functionRestore(serializedValue, policy)).thenReturn(stringCommandObject); + when(commandExecutor.broadcastCommand(stringCommandObject)).thenReturn(expectedResponse); + + String result = jedis.functionRestore(serializedValue, policy); + + assertThat(result, equalTo(expectedResponse)); + + verify(commandExecutor).broadcastCommand(stringCommandObject); + verify(commandObjects).functionRestore(serializedValue, policy); + } + + @Test + public void testFunctionStats() { + FunctionStats expectedFunctionStats = mock(FunctionStats.class); + + when(commandObjects.functionStats()).thenReturn(functionStatsCommandObject); + when(commandExecutor.executeCommand(functionStatsCommandObject)).thenReturn(expectedFunctionStats); + + FunctionStats result = jedis.functionStats(); + + assertThat(result, sameInstance(expectedFunctionStats)); + + verify(commandExecutor).executeCommand(functionStatsCommandObject); + verify(commandObjects).functionStats(); + } + + @Test + public void testFunctionStatsBinary() { + Object expectedFunctionStatsBinary = new Object(); + + when(commandObjects.functionStatsBinary()).thenReturn(objectCommandObject); + when(commandExecutor.executeCommand(objectCommandObject)).thenReturn(expectedFunctionStatsBinary); + + Object result = jedis.functionStatsBinary(); + + assertThat(result, equalTo(expectedFunctionStatsBinary)); + + verify(commandExecutor).executeCommand(objectCommandObject); + verify(commandObjects).functionStatsBinary(); + } + + @Test + public void testScriptExistsWithSha1s() { + List sha1s = Arrays.asList("sha1One", "sha1Two"); + List expectedResponse = Arrays.asList(true, false); + + when(commandObjects.scriptExists(sha1s)).thenReturn(listBooleanCommandObject); + when(commandExecutor.broadcastCommand(listBooleanCommandObject)).thenReturn(expectedResponse); + + List result = jedis.scriptExists(sha1s); + + assertThat(result, equalTo(expectedResponse)); + + verify(commandExecutor).broadcastCommand(listBooleanCommandObject); + verify(commandObjects).scriptExists(sha1s); + } + + @Test + public void testScriptExistsWithSha1AndSampleKey() { + String sha1 = "someSha1Hash"; + String sampleKey = "myKey"; + Boolean expectedResponse = true; + + when(commandObjects.scriptExists(sampleKey, sha1)).thenReturn(listBooleanCommandObject); + when(commandExecutor.executeCommand(listBooleanCommandObject)).thenReturn(Collections.singletonList(expectedResponse)); + + Boolean result = jedis.scriptExists(sha1, sampleKey); + + assertThat(result, equalTo(expectedResponse)); + + verify(commandExecutor).executeCommand(listBooleanCommandObject); + verify(commandObjects).scriptExists(sampleKey, sha1); + } + + @Test + public void testScriptExistsWithSha1AndSampleKeyBinary() { + byte[] sha1 = "someSha1Hash".getBytes(); + byte[] sampleKey = "myKey".getBytes(); + Boolean expectedResponse = true; + + when(commandObjects.scriptExists(sampleKey, new byte[][]{ sha1 })).thenReturn(listBooleanCommandObject); + when(commandExecutor.executeCommand(listBooleanCommandObject)).thenReturn(Collections.singletonList(expectedResponse)); + + Boolean result = jedis.scriptExists(sha1, sampleKey); + + assertThat(result, equalTo(expectedResponse)); + + verify(commandExecutor).executeCommand(listBooleanCommandObject); + verify(commandObjects).scriptExists(sampleKey, new byte[][]{ sha1 }); + } + + @Test + public void testScriptExistsWithKeyAndSha1s() { + String sampleKey = "myKey"; + String[] sha1s = { "sha1One", "sha1Two" }; + List expectedResponse = Arrays.asList(true, false); + + when(commandObjects.scriptExists(sampleKey, sha1s)).thenReturn(listBooleanCommandObject); + when(commandExecutor.executeCommand(listBooleanCommandObject)).thenReturn(expectedResponse); + + List result = jedis.scriptExists(sampleKey, sha1s); + + assertThat(result, equalTo(expectedResponse)); + + verify(commandExecutor).executeCommand(listBooleanCommandObject); + verify(commandObjects).scriptExists(sampleKey, sha1s); + } + + @Test + public void testScriptExistsWithKeyAndSha1sBinary() { + byte[] sampleKey = "myKey".getBytes(); + byte[][] sha1s = { "sha1One".getBytes(), "sha1Two".getBytes() }; + List expectedResponse = Arrays.asList(true, false); + + when(commandObjects.scriptExists(sampleKey, sha1s)).thenReturn(listBooleanCommandObject); + when(commandExecutor.executeCommand(listBooleanCommandObject)).thenReturn(expectedResponse); + + List result = jedis.scriptExists(sampleKey, sha1s); + + assertThat(result, equalTo(expectedResponse)); + + verify(commandExecutor).executeCommand(listBooleanCommandObject); + verify(commandObjects).scriptExists(sampleKey, sha1s); + } + + @Test + public void testScriptFlushWithoutKey() { + String expectedResponse = "OK"; + + when(commandObjects.scriptFlush()).thenReturn(stringCommandObject); + when(commandExecutor.broadcastCommand(stringCommandObject)).thenReturn(expectedResponse); + + String result = jedis.scriptFlush(); + + assertThat(result, equalTo(expectedResponse)); + + verify(commandExecutor).broadcastCommand(stringCommandObject); + verify(commandObjects).scriptFlush(); + } + + @Test + public void testScriptFlush() { + String sampleKey = "myKey"; + String expectedResponse = "OK"; + + when(commandObjects.scriptFlush(sampleKey)).thenReturn(stringCommandObject); + when(commandExecutor.executeCommand(stringCommandObject)).thenReturn(expectedResponse); + + String result = jedis.scriptFlush(sampleKey); + + assertThat(result, equalTo(expectedResponse)); + + verify(commandExecutor).executeCommand(stringCommandObject); + verify(commandObjects).scriptFlush(sampleKey); + } + + @Test + public void testScriptFlushBinary() { + byte[] sampleKey = "myKey".getBytes(); + String expectedResponse = "OK"; + + when(commandObjects.scriptFlush(sampleKey)).thenReturn(stringCommandObject); + when(commandExecutor.executeCommand(stringCommandObject)).thenReturn(expectedResponse); + + String result = jedis.scriptFlush(sampleKey); + + assertThat(result, equalTo(expectedResponse)); + + verify(commandExecutor).executeCommand(stringCommandObject); + verify(commandObjects).scriptFlush(sampleKey); + } + + @Test + public void testScriptFlushWithMode() { + String sampleKey = "myKey"; + FlushMode flushMode = FlushMode.SYNC; + String expectedResponse = "OK"; + + when(commandObjects.scriptFlush(sampleKey, flushMode)).thenReturn(stringCommandObject); + when(commandExecutor.executeCommand(stringCommandObject)).thenReturn(expectedResponse); + + String result = jedis.scriptFlush(sampleKey, flushMode); + + assertThat(result, equalTo(expectedResponse)); + + verify(commandExecutor).executeCommand(stringCommandObject); + verify(commandObjects).scriptFlush(sampleKey, flushMode); + } + + @Test + public void testScriptFlushWithModeBinary() { + byte[] sampleKey = "myKey".getBytes(); + FlushMode flushMode = FlushMode.SYNC; + String expectedResponse = "OK"; + + when(commandObjects.scriptFlush(sampleKey, flushMode)).thenReturn(stringCommandObject); + when(commandExecutor.executeCommand(stringCommandObject)).thenReturn(expectedResponse); + + String result = jedis.scriptFlush(sampleKey, flushMode); + + assertThat(result, equalTo(expectedResponse)); + + verify(commandExecutor).executeCommand(stringCommandObject); + verify(commandObjects).scriptFlush(sampleKey, flushMode); + } + + @Test + public void testScriptKillWithoutKey() { + String expectedResponse = "OK"; + + when(commandObjects.scriptKill()).thenReturn(stringCommandObject); + when(commandExecutor.broadcastCommand(stringCommandObject)).thenReturn(expectedResponse); + + String result = jedis.scriptKill(); + + assertThat(result, equalTo(expectedResponse)); + + verify(commandExecutor).broadcastCommand(stringCommandObject); + verify(commandObjects).scriptKill(); + } + + @Test + public void testScriptKill() { + String sampleKey = "myKey"; + String expectedResponse = "OK"; + + when(commandObjects.scriptKill(sampleKey)).thenReturn(stringCommandObject); + when(commandExecutor.executeCommand(stringCommandObject)).thenReturn(expectedResponse); + + String result = jedis.scriptKill(sampleKey); + + assertThat(result, equalTo(expectedResponse)); + + verify(commandExecutor).executeCommand(stringCommandObject); + verify(commandObjects).scriptKill(sampleKey); + } + + @Test + public void testScriptKillBinary() { + byte[] sampleKey = "myKey".getBytes(); + String expectedResponse = "OK"; + + when(commandObjects.scriptKill(sampleKey)).thenReturn(stringCommandObject); + when(commandExecutor.executeCommand(stringCommandObject)).thenReturn(expectedResponse); + + String result = jedis.scriptKill(sampleKey); + + assertThat(result, equalTo(expectedResponse)); + + verify(commandExecutor).executeCommand(stringCommandObject); + verify(commandObjects).scriptKill(sampleKey); + } + + @Test + public void testScriptLoadWithoutKey() { + String script = "return redis.call('get', 'constantKey')"; + String expectedSha1 = "someSha1Hash"; + + when(commandObjects.scriptLoad(script)).thenReturn(stringCommandObject); + when(commandExecutor.broadcastCommand(stringCommandObject)).thenReturn(expectedSha1); + + String result = jedis.scriptLoad(script); + + assertThat(result, equalTo(expectedSha1)); + + verify(commandExecutor).broadcastCommand(stringCommandObject); + verify(commandObjects).scriptLoad(script); + } + + @Test + public void testScriptLoad() { + String script = "return redis.call('get', KEYS[1])"; + String sampleKey = "myKey"; + String expectedSha1 = "someSha1Hash"; + + when(commandObjects.scriptLoad(script, sampleKey)).thenReturn(stringCommandObject); + when(commandExecutor.executeCommand(stringCommandObject)).thenReturn(expectedSha1); + + String result = jedis.scriptLoad(script, sampleKey); + + assertThat(result, equalTo(expectedSha1)); + + verify(commandExecutor).executeCommand(stringCommandObject); + verify(commandObjects).scriptLoad(script, sampleKey); + } + + @Test + public void testScriptLoadBinary() { + byte[] script = "return redis.call('get', KEYS[1])".getBytes(); + byte[] sampleKey = "myKey".getBytes(); + byte[] expectedSha1 = "someSha1Hash".getBytes(); + + when(commandObjects.scriptLoad(script, sampleKey)).thenReturn(bytesCommandObject); + when(commandExecutor.executeCommand(bytesCommandObject)).thenReturn(expectedSha1); + + byte[] result = jedis.scriptLoad(script, sampleKey); + + assertThat(result, equalTo(expectedSha1)); + + verify(commandExecutor).executeCommand(bytesCommandObject); + verify(commandObjects).scriptLoad(script, sampleKey); + } + +} diff --git a/src/test/java/redis/clients/jedis/mocked/unified/UnifiedJedisSearchAndQueryCommandsTest.java b/src/test/java/redis/clients/jedis/mocked/unified/UnifiedJedisSearchAndQueryCommandsTest.java new file mode 100644 index 00000000000..1f6d9d6363b --- /dev/null +++ b/src/test/java/redis/clients/jedis/mocked/unified/UnifiedJedisSearchAndQueryCommandsTest.java @@ -0,0 +1,838 @@ +package redis.clients.jedis.mocked.unified; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.sameInstance; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import java.util.AbstractMap; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import org.junit.Test; +import redis.clients.jedis.resps.Tuple; +import redis.clients.jedis.search.FTCreateParams; +import redis.clients.jedis.search.FTProfileParams; +import redis.clients.jedis.search.FTSearchParams; +import redis.clients.jedis.search.FTSpellCheckParams; +import redis.clients.jedis.search.IndexOptions; +import redis.clients.jedis.search.Query; +import redis.clients.jedis.search.Schema; +import redis.clients.jedis.search.SearchResult; +import redis.clients.jedis.search.aggr.AggregationBuilder; +import redis.clients.jedis.search.aggr.AggregationResult; +import redis.clients.jedis.search.schemafields.SchemaField; +import redis.clients.jedis.search.schemafields.TextField; + +public class UnifiedJedisSearchAndQueryCommandsTest extends UnifiedJedisMockedTestBase { + + @Test + public void testFtAggregate() { + String indexName = "myIndex"; + AggregationBuilder aggr = new AggregationBuilder().groupBy("@field"); + AggregationResult expectedResponse = mock(AggregationResult.class); + + when(commandObjects.ftAggregate(indexName, aggr)).thenReturn(aggregationResultCommandObject); + when(commandExecutor.executeCommand(aggregationResultCommandObject)).thenReturn(expectedResponse); + + AggregationResult result = jedis.ftAggregate(indexName, aggr); + + assertThat(result, sameInstance(expectedResponse)); + + verify(commandExecutor).executeCommand(aggregationResultCommandObject); + verify(commandObjects).ftAggregate(indexName, aggr); + } + + @Test + public void testFtAliasAdd() { + String aliasName = "myAlias"; + String indexName = "myIndex"; + String expectedResponse = "OK"; + + when(commandObjects.ftAliasAdd(aliasName, indexName)).thenReturn(stringCommandObject); + when(commandExecutor.broadcastCommand(stringCommandObject)).thenReturn(expectedResponse); + + String result = jedis.ftAliasAdd(aliasName, indexName); + + assertThat(result, equalTo(expectedResponse)); + + verify(commandExecutor).broadcastCommand(stringCommandObject); + verify(commandObjects).ftAliasAdd(aliasName, indexName); + } + + @Test + public void testFtAliasDel() { + String aliasName = "myAlias"; + String expectedResponse = "OK"; + + when(commandObjects.ftAliasDel(aliasName)).thenReturn(stringCommandObject); + when(commandExecutor.broadcastCommand(stringCommandObject)).thenReturn(expectedResponse); + + String result = jedis.ftAliasDel(aliasName); + + assertThat(result, equalTo(expectedResponse)); + + verify(commandExecutor).broadcastCommand(stringCommandObject); + verify(commandObjects).ftAliasDel(aliasName); + } + + @Test + public void testFtAliasUpdate() { + String aliasName = "myAlias"; + String indexName = "myIndex"; + String expectedResponse = "OK"; + + when(commandObjects.ftAliasUpdate(aliasName, indexName)).thenReturn(stringCommandObject); + when(commandExecutor.broadcastCommand(stringCommandObject)).thenReturn(expectedResponse); + + String result = jedis.ftAliasUpdate(aliasName, indexName); + + assertThat(result, equalTo(expectedResponse)); + + verify(commandExecutor).broadcastCommand(stringCommandObject); + verify(commandObjects).ftAliasUpdate(aliasName, indexName); + } + + @Test + public void testFtAlterWithSchema() { + String indexName = "myIndex"; + Schema schema = new Schema().addField(new Schema.Field("myField", Schema.FieldType.TEXT)); + String expectedResponse = "OK"; + + when(commandObjects.ftAlter(indexName, schema)).thenReturn(stringCommandObject); + when(commandExecutor.broadcastCommand(stringCommandObject)).thenReturn(expectedResponse); + + String result = jedis.ftAlter(indexName, schema); + + assertThat(result, equalTo(expectedResponse)); + + verify(commandExecutor).broadcastCommand(stringCommandObject); + verify(commandObjects).ftAlter(indexName, schema); + } + + @Test + public void testFtAlterWithSchemaFields() { + String indexName = "myIndex"; + Iterable schemaFields = Collections.singletonList(new TextField("newField")); + String expectedResponse = "OK"; + + when(commandObjects.ftAlter(indexName, schemaFields)).thenReturn(stringCommandObject); + when(commandExecutor.broadcastCommand(stringCommandObject)).thenReturn(expectedResponse); + + String result = jedis.ftAlter(indexName, schemaFields); + + assertThat(result, equalTo(expectedResponse)); + + verify(commandExecutor).broadcastCommand(stringCommandObject); + verify(commandObjects).ftAlter(indexName, schemaFields); + } + + @Test + public void testFtConfigGet() { + String option = "TIMEOUT"; + Map expectedResponse = Collections.singletonMap(option, "1000"); + + when(commandObjects.ftConfigGet(option)).thenReturn(mapStringObjectCommandObject); + when(commandExecutor.executeCommand(mapStringObjectCommandObject)).thenReturn(expectedResponse); + + Map result = jedis.ftConfigGet(option); + + assertThat(result, equalTo(expectedResponse)); + + verify(commandExecutor).executeCommand(mapStringObjectCommandObject); + verify(commandObjects).ftConfigGet(option); + } + + @Test + public void testFtConfigGetWithIndexName() { + String indexName = "myIndex"; + String option = "TIMEOUT"; + Map expectedResponse = Collections.singletonMap(option, "1000"); + + when(commandObjects.ftConfigGet(indexName, option)).thenReturn(mapStringObjectCommandObject); + when(commandExecutor.executeCommand(mapStringObjectCommandObject)).thenReturn(expectedResponse); + + Map result = jedis.ftConfigGet(indexName, option); + + assertThat(result, equalTo(expectedResponse)); + + verify(commandExecutor).executeCommand(mapStringObjectCommandObject); + verify(commandObjects).ftConfigGet(indexName, option); + } + + @Test + public void testFtConfigSet() { + String option = "TIMEOUT"; + String value = "1000"; + String expectedResponse = "OK"; + + when(commandObjects.ftConfigSet(option, value)).thenReturn(stringCommandObject); + when(commandExecutor.executeCommand(stringCommandObject)).thenReturn(expectedResponse); + + String result = jedis.ftConfigSet(option, value); + + assertThat(result, equalTo(expectedResponse)); + + verify(commandExecutor).executeCommand(stringCommandObject); + verify(commandObjects).ftConfigSet(option, value); + } + + @Test + public void testFtConfigSetWithIndexName() { + String indexName = "myIndex"; + String option = "TIMEOUT"; + String value = "1000"; + String expectedResponse = "OK"; + + when(commandObjects.ftConfigSet(indexName, option, value)).thenReturn(stringCommandObject); + when(commandExecutor.executeCommand(stringCommandObject)).thenReturn(expectedResponse); + + String result = jedis.ftConfigSet(indexName, option, value); + + assertThat(result, equalTo(expectedResponse)); + + verify(commandExecutor).executeCommand(stringCommandObject); + verify(commandObjects).ftConfigSet(indexName, option, value); + } + + @Test + public void testFtCreateWithOptionsAndSchema() { + String indexName = "myIndex"; + IndexOptions indexOptions = IndexOptions.defaultOptions(); + Schema schema = new Schema().addField(new Schema.Field("myField", Schema.FieldType.TEXT)); + String expectedResponse = "OK"; + + when(commandObjects.ftCreate(indexName, indexOptions, schema)).thenReturn(stringCommandObject); + when(commandExecutor.broadcastCommand(stringCommandObject)).thenReturn(expectedResponse); + + String result = jedis.ftCreate(indexName, indexOptions, schema); + + assertThat(result, equalTo(expectedResponse)); + + verify(commandExecutor).broadcastCommand(stringCommandObject); + verify(commandObjects).ftCreate(indexName, indexOptions, schema); + } + + @Test + public void testFtCreateWithCreateParamsAndSchemaFields() { + String indexName = "myIndex"; + FTCreateParams createParams = FTCreateParams.createParams(); + Iterable schemaFields = Collections.singletonList(new TextField("myField")); + String expectedResponse = "OK"; + + when(commandObjects.ftCreate(indexName, createParams, schemaFields)).thenReturn(stringCommandObject); + when(commandExecutor.broadcastCommand(stringCommandObject)).thenReturn(expectedResponse); + + String result = jedis.ftCreate(indexName, createParams, schemaFields); + + assertThat(result, equalTo(expectedResponse)); + + verify(commandExecutor).broadcastCommand(stringCommandObject); + verify(commandObjects).ftCreate(indexName, createParams, schemaFields); + } + + @Test + public void testFtCursorDel() { + String indexName = "myIndex"; + long cursorId = 123L; + String expectedResponse = "OK"; + + when(commandObjects.ftCursorDel(indexName, cursorId)).thenReturn(stringCommandObject); + when(commandExecutor.executeCommand(stringCommandObject)).thenReturn(expectedResponse); + + String result = jedis.ftCursorDel(indexName, cursorId); + + assertThat(result, equalTo(expectedResponse)); + + verify(commandExecutor).executeCommand(stringCommandObject); + verify(commandObjects).ftCursorDel(indexName, cursorId); + } + + @Test + public void testFtCursorRead() { + String indexName = "myIndex"; + long cursorId = 123L; + int count = 10; + AggregationResult expectedResponse = mock(AggregationResult.class); + + when(commandObjects.ftCursorRead(indexName, cursorId, count)).thenReturn(aggregationResultCommandObject); + when(commandExecutor.executeCommand(aggregationResultCommandObject)).thenReturn(expectedResponse); + + AggregationResult result = jedis.ftCursorRead(indexName, cursorId, count); + + assertThat(result, sameInstance(expectedResponse)); + + verify(commandExecutor).executeCommand(aggregationResultCommandObject); + verify(commandObjects).ftCursorRead(indexName, cursorId, count); + } + + @Test + public void testFtDictAdd() { + String dictionary = "myDict"; + String[] terms = { "term1", "term2" }; + long expectedResponse = 2L; + + when(commandObjects.ftDictAdd(dictionary, terms)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedResponse); + + long result = jedis.ftDictAdd(dictionary, terms); + + assertThat(result, equalTo(expectedResponse)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).ftDictAdd(dictionary, terms); + } + + @Test + public void testFtDictAddBySampleKey() { + String indexName = "myIndex"; + String dictionary = "myDict"; + String[] terms = { "term1", "term2" }; + long expectedResponse = 2L; + + when(commandObjects.ftDictAddBySampleKey(indexName, dictionary, terms)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedResponse); + + long result = jedis.ftDictAddBySampleKey(indexName, dictionary, terms); + + assertThat(result, equalTo(expectedResponse)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).ftDictAddBySampleKey(indexName, dictionary, terms); + } + + @Test + public void testFtDictDel() { + String dictionary = "myDict"; + String[] terms = { "term1", "term2" }; + long expectedResponse = 1L; + + when(commandObjects.ftDictDel(dictionary, terms)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedResponse); + + long result = jedis.ftDictDel(dictionary, terms); + + assertThat(result, equalTo(expectedResponse)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).ftDictDel(dictionary, terms); + } + + @Test + public void testFtDictDelBySampleKey() { + String indexName = "myIndex"; + String dictionary = "myDict"; + String[] terms = { "term1", "term2" }; + long expectedResponse = 1L; + + when(commandObjects.ftDictDelBySampleKey(indexName, dictionary, terms)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedResponse); + + long result = jedis.ftDictDelBySampleKey(indexName, dictionary, terms); + + assertThat(result, equalTo(expectedResponse)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).ftDictDelBySampleKey(indexName, dictionary, terms); + } + + @Test + public void testFtDictDump() { + String dictionary = "myDict"; + Set expectedResponse = new HashSet<>(Arrays.asList("term1", "term2")); + + when(commandObjects.ftDictDump(dictionary)).thenReturn(setStringCommandObject); + when(commandExecutor.executeCommand(setStringCommandObject)).thenReturn(expectedResponse); + + Set result = jedis.ftDictDump(dictionary); + + assertThat(result, equalTo(expectedResponse)); + + verify(commandExecutor).executeCommand(setStringCommandObject); + verify(commandObjects).ftDictDump(dictionary); + } + + @Test + public void testFtDictDumpBySampleKey() { + String indexName = "myIndex"; + String dictionary = "myDict"; + Set expectedResponse = new HashSet<>(Arrays.asList("term1", "term2")); + + when(commandObjects.ftDictDumpBySampleKey(indexName, dictionary)).thenReturn(setStringCommandObject); + when(commandExecutor.executeCommand(setStringCommandObject)).thenReturn(expectedResponse); + + Set result = jedis.ftDictDumpBySampleKey(indexName, dictionary); + + assertThat(result, equalTo(expectedResponse)); + + verify(commandExecutor).executeCommand(setStringCommandObject); + verify(commandObjects).ftDictDumpBySampleKey(indexName, dictionary); + } + + @Test + public void testFtDropIndex() { + String indexName = "myIndex"; + String expectedResponse = "OK"; + + when(commandObjects.ftDropIndex(indexName)).thenReturn(stringCommandObject); + when(commandExecutor.broadcastCommand(stringCommandObject)).thenReturn(expectedResponse); + + String result = jedis.ftDropIndex(indexName); + + assertThat(result, equalTo(expectedResponse)); + + verify(commandExecutor).broadcastCommand(stringCommandObject); + verify(commandObjects).ftDropIndex(indexName); + } + + @Test + public void testFtDropIndexDD() { + String indexName = "myIndex"; + String expectedResponse = "OK"; + + when(commandObjects.ftDropIndexDD(indexName)).thenReturn(stringCommandObject); + when(commandExecutor.broadcastCommand(stringCommandObject)).thenReturn(expectedResponse); + + String result = jedis.ftDropIndexDD(indexName); + + assertThat(result, equalTo(expectedResponse)); + + verify(commandExecutor).broadcastCommand(stringCommandObject); + verify(commandObjects).ftDropIndexDD(indexName); + } + + @Test + public void testFtExplain() { + String indexName = "myIndex"; + Query query = new Query("hello world").limit(0, 10); + String expectedResponse = "QUERY PLAN"; + + when(commandObjects.ftExplain(indexName, query)).thenReturn(stringCommandObject); + when(commandExecutor.executeCommand(stringCommandObject)).thenReturn(expectedResponse); + + String result = jedis.ftExplain(indexName, query); + + assertThat(result, equalTo(expectedResponse)); + + verify(commandExecutor).executeCommand(stringCommandObject); + verify(commandObjects).ftExplain(indexName, query); + } + + @Test + public void testFtExplainCLI() { + String indexName = "myIndex"; + Query query = new Query("hello world").limit(0, 10); + List expectedResponse = Arrays.asList("QUERY PLAN", "DETAILS"); + + when(commandObjects.ftExplainCLI(indexName, query)).thenReturn(listStringCommandObject); + when(commandExecutor.executeCommand(listStringCommandObject)).thenReturn(expectedResponse); + + List result = jedis.ftExplainCLI(indexName, query); + + assertThat(result, equalTo(expectedResponse)); + + verify(commandExecutor).executeCommand(listStringCommandObject); + verify(commandObjects).ftExplainCLI(indexName, query); + } + + @Test + public void testFtInfo() { + String indexName = "myIndex"; + Map expectedResponse = Collections.singletonMap("index_definition", Collections.singletonMap("key_type", "HASH")); + + when(commandObjects.ftInfo(indexName)).thenReturn(mapStringObjectCommandObject); + when(commandExecutor.executeCommand(mapStringObjectCommandObject)).thenReturn(expectedResponse); + + Map result = jedis.ftInfo(indexName); + + assertThat(result, equalTo(expectedResponse)); + + verify(commandExecutor).executeCommand(mapStringObjectCommandObject); + verify(commandObjects).ftInfo(indexName); + } + + @Test + public void testFtList() { + Set expectedResponse = new HashSet<>(Arrays.asList("index1", "index2")); + + when(commandObjects.ftList()).thenReturn(setStringCommandObject); + when(commandExecutor.executeCommand(setStringCommandObject)).thenReturn(expectedResponse); + + Set result = jedis.ftList(); + + assertThat(result, equalTo(expectedResponse)); + + verify(commandExecutor).executeCommand(setStringCommandObject); + verify(commandObjects).ftList(); + } + + @Test + public void testFtSearch() { + String indexName = "myIndex"; + String query = "hello world"; + SearchResult expectedResponse = mock(SearchResult.class); + + when(commandObjects.ftSearch(indexName, query)).thenReturn(searchResultCommandObject); + when(commandExecutor.executeCommand(searchResultCommandObject)).thenReturn(expectedResponse); + + SearchResult result = jedis.ftSearch(indexName, query); + + assertThat(result, sameInstance(expectedResponse)); + + verify(commandExecutor).executeCommand(searchResultCommandObject); + verify(commandObjects).ftSearch(indexName, query); + } + + @Test + public void testFtSearchWithParams() { + String indexName = "myIndex"; + String query = "hello world"; + FTSearchParams params = new FTSearchParams().noContent().limit(0, 10); + SearchResult expectedResponse = mock(SearchResult.class); + + when(commandObjects.ftSearch(indexName, query, params)).thenReturn(searchResultCommandObject); + when(commandExecutor.executeCommand(searchResultCommandObject)).thenReturn(expectedResponse); + + SearchResult result = jedis.ftSearch(indexName, query, params); + + assertThat(result, sameInstance(expectedResponse)); + + verify(commandExecutor).executeCommand(searchResultCommandObject); + verify(commandObjects).ftSearch(indexName, query, params); + } + + @Test + public void testFtSearchWithQueryObject() { + String indexName = "myIndex"; + Query query = new Query("hello world"); + SearchResult expectedResponse = mock(SearchResult.class); + + when(commandObjects.ftSearch(indexName, query)).thenReturn(searchResultCommandObject); + when(commandExecutor.executeCommand(searchResultCommandObject)).thenReturn(expectedResponse); + + SearchResult result = jedis.ftSearch(indexName, query); + + assertThat(result, sameInstance(expectedResponse)); + + verify(commandExecutor).executeCommand(searchResultCommandObject); + verify(commandObjects).ftSearch(indexName, query); + } + + @Test + public void testFtSearchWithQueryObjectBinary() { + byte[] indexName = "myIndex".getBytes(); + Query query = new Query("hello world").limit(0, 10); + SearchResult expectedResponse = mock(SearchResult.class); + + when(commandObjects.ftSearch(indexName, query)).thenReturn(searchResultCommandObject); + when(commandExecutor.executeCommand(searchResultCommandObject)).thenReturn(expectedResponse); + + SearchResult result = jedis.ftSearch(indexName, query); + + assertThat(result, sameInstance(expectedResponse)); + + verify(commandExecutor).executeCommand(searchResultCommandObject); + verify(commandObjects).ftSearch(indexName, query); + } + + @Test + public void testFtSpellCheck() { + String index = "myIndex"; + String query = "hello world"; + Map> expectedResponse = Collections.singletonMap("term1", Collections.singletonMap("suggestion1", 1.0)); + + when(commandObjects.ftSpellCheck(index, query)).thenReturn(mapStringMapStringDoubleCommandObject); + when(commandExecutor.executeCommand(mapStringMapStringDoubleCommandObject)).thenReturn(expectedResponse); + + Map> result = jedis.ftSpellCheck(index, query); + + assertThat(result, equalTo(expectedResponse)); + + verify(commandExecutor).executeCommand(mapStringMapStringDoubleCommandObject); + verify(commandObjects).ftSpellCheck(index, query); + } + + @Test + public void testFtSpellCheckWithParams() { + String index = "myIndex"; + String query = "hello world"; + FTSpellCheckParams spellCheckParams = new FTSpellCheckParams().distance(1); + Map> expectedResponse = Collections.singletonMap("term1", Collections.singletonMap("suggestion1", 1.0)); + + when(commandObjects.ftSpellCheck(index, query, spellCheckParams)).thenReturn(mapStringMapStringDoubleCommandObject); + when(commandExecutor.executeCommand(mapStringMapStringDoubleCommandObject)).thenReturn(expectedResponse); + + Map> result = jedis.ftSpellCheck(index, query, spellCheckParams); + + assertThat(result, equalTo(expectedResponse)); + + verify(commandExecutor).executeCommand(mapStringMapStringDoubleCommandObject); + verify(commandObjects).ftSpellCheck(index, query, spellCheckParams); + } + + @Test + public void testFtSynDump() { + String indexName = "myIndex"; + Map> expectedResponse = Collections.singletonMap("group1", Arrays.asList("term1", "term2")); + + when(commandObjects.ftSynDump(indexName)).thenReturn(mapStringListStringCommandObject); + when(commandExecutor.executeCommand(mapStringListStringCommandObject)).thenReturn(expectedResponse); + + Map> result = jedis.ftSynDump(indexName); + + assertThat(result, equalTo(expectedResponse)); + + verify(commandExecutor).executeCommand(mapStringListStringCommandObject); + verify(commandObjects).ftSynDump(indexName); + } + + @Test + public void testFtSynUpdate() { + String indexName = "myIndex"; + String synonymGroupId = "group1"; + String[] terms = { "term1", "term2" }; + String expectedResponse = "OK"; + + when(commandObjects.ftSynUpdate(indexName, synonymGroupId, terms)).thenReturn(stringCommandObject); + when(commandExecutor.executeCommand(stringCommandObject)).thenReturn(expectedResponse); + + String result = jedis.ftSynUpdate(indexName, synonymGroupId, terms); + + assertThat(result, equalTo(expectedResponse)); + + verify(commandExecutor).executeCommand(stringCommandObject); + verify(commandObjects).ftSynUpdate(indexName, synonymGroupId, terms); + } + + @Test + public void testFtTagVals() { + String indexName = "myIndex"; + String fieldName = "myField"; + Set expectedResponse = new HashSet<>(Arrays.asList("tag1", "tag2")); + + when(commandObjects.ftTagVals(indexName, fieldName)).thenReturn(setStringCommandObject); + when(commandExecutor.executeCommand(setStringCommandObject)).thenReturn(expectedResponse); + + Set result = jedis.ftTagVals(indexName, fieldName); + + assertThat(result, equalTo(expectedResponse)); + + verify(commandExecutor).executeCommand(setStringCommandObject); + verify(commandObjects).ftTagVals(indexName, fieldName); + } + + @Test + public void testFtSugAdd() { + String key = "sugKey"; + String string = "suggestion"; + double score = 1.0; + long expectedResponse = 1L; + + when(commandObjects.ftSugAdd(key, string, score)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedResponse); + + long result = jedis.ftSugAdd(key, string, score); + + assertThat(result, equalTo(expectedResponse)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).ftSugAdd(key, string, score); + } + + @Test + public void testFtSugAddIncr() { + String key = "sugKey"; + String string = "suggestion"; + double score = 1.0; + long expectedResponse = 2L; + + when(commandObjects.ftSugAddIncr(key, string, score)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedResponse); + + long result = jedis.ftSugAddIncr(key, string, score); + + assertThat(result, equalTo(expectedResponse)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).ftSugAddIncr(key, string, score); + } + + @Test + public void testFtSugDel() { + String key = "sugKey"; + String string = "suggestion"; + boolean expectedResponse = true; + + when(commandObjects.ftSugDel(key, string)).thenReturn(booleanCommandObject); + when(commandExecutor.executeCommand(booleanCommandObject)).thenReturn(expectedResponse); + + boolean result = jedis.ftSugDel(key, string); + + assertThat(result, equalTo(expectedResponse)); + + verify(commandExecutor).executeCommand(booleanCommandObject); + verify(commandObjects).ftSugDel(key, string); + } + + @Test + public void testFtSugGet() { + String key = "sugKey"; + String prefix = "sug"; + List expectedResponse = Arrays.asList("suggestion1", "suggestion2"); + + when(commandObjects.ftSugGet(key, prefix)).thenReturn(listStringCommandObject); + when(commandExecutor.executeCommand(listStringCommandObject)).thenReturn(expectedResponse); + + List result = jedis.ftSugGet(key, prefix); + + assertThat(result, equalTo(expectedResponse)); + + verify(commandExecutor).executeCommand(listStringCommandObject); + verify(commandObjects).ftSugGet(key, prefix); + } + + @Test + public void testFtSugGetWithFuzzyAndMax() { + String key = "sugKey"; + String prefix = "sug"; + boolean fuzzy = true; + int max = 10; + List expectedResponse = Arrays.asList("suggestion1", "suggestion2"); + + when(commandObjects.ftSugGet(key, prefix, fuzzy, max)).thenReturn(listStringCommandObject); + when(commandExecutor.executeCommand(listStringCommandObject)).thenReturn(expectedResponse); + + List result = jedis.ftSugGet(key, prefix, fuzzy, max); + + assertThat(result, equalTo(expectedResponse)); + + verify(commandExecutor).executeCommand(listStringCommandObject); + verify(commandObjects).ftSugGet(key, prefix, fuzzy, max); + } + + @Test + public void testFtSugGetWithScores() { + String key = "sugKey"; + String prefix = "sug"; + List expectedResponse = Arrays.asList(new Tuple("suggestion1", 1.0), new Tuple("suggestion2", 0.8)); + + when(commandObjects.ftSugGetWithScores(key, prefix)).thenReturn(listTupleCommandObject); + when(commandExecutor.executeCommand(listTupleCommandObject)).thenReturn(expectedResponse); + + List result = jedis.ftSugGetWithScores(key, prefix); + + assertThat(result, equalTo(expectedResponse)); + + verify(commandExecutor).executeCommand(listTupleCommandObject); + verify(commandObjects).ftSugGetWithScores(key, prefix); + } + + @Test + public void testFtSugGetWithScoresAndFuzzyMax() { + String key = "sugKey"; + String prefix = "sug"; + boolean fuzzy = true; + int max = 10; + List expectedResponse = Arrays.asList(new Tuple("suggestion1", 1.0), new Tuple("suggestion2", 0.8)); + + when(commandObjects.ftSugGetWithScores(key, prefix, fuzzy, max)).thenReturn(listTupleCommandObject); + when(commandExecutor.executeCommand(listTupleCommandObject)).thenReturn(expectedResponse); + + List result = jedis.ftSugGetWithScores(key, prefix, fuzzy, max); + + assertThat(result, equalTo(expectedResponse)); + + verify(commandExecutor).executeCommand(listTupleCommandObject); + verify(commandObjects).ftSugGetWithScores(key, prefix, fuzzy, max); + } + + @Test + public void testFtSugLen() { + String key = "sugKey"; + long expectedResponse = 42L; + + when(commandObjects.ftSugLen(key)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedResponse); + + long result = jedis.ftSugLen(key); + + assertThat(result, equalTo(expectedResponse)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).ftSugLen(key); + } + + @Test + public void testFtProfileAggregate() { + String indexName = "myIndex"; + FTProfileParams profileParams = new FTProfileParams(); + AggregationBuilder aggr = new AggregationBuilder().groupBy("@field"); + Map.Entry> expectedResponse = new AbstractMap.SimpleEntry<>( + mock(AggregationResult.class), Collections.singletonMap("Profile", "Data")); + + when(commandObjects.ftProfileAggregate(indexName, profileParams, aggr)).thenReturn(entryAggregationResultMapStringObjectCommandObject); + when(commandExecutor.executeCommand(entryAggregationResultMapStringObjectCommandObject)).thenReturn(expectedResponse); + + Map.Entry> result = jedis.ftProfileAggregate(indexName, profileParams, aggr); + + assertThat(result, equalTo(expectedResponse)); + + verify(commandExecutor).executeCommand(entryAggregationResultMapStringObjectCommandObject); + verify(commandObjects).ftProfileAggregate(indexName, profileParams, aggr); + } + + @Test + public void testFtProfileSearchWithQueryObject() { + String indexName = "myIndex"; + FTProfileParams profileParams = new FTProfileParams(); + Query query = new Query("hello world").limit(0, 10); + Map.Entry> expectedResponse = new AbstractMap.SimpleEntry<>( + mock(SearchResult.class), Collections.singletonMap("Profile", "Data")); + + when(commandObjects.ftProfileSearch(indexName, profileParams, query)).thenReturn(entrySearchResultMapStringObjectCommandObject); + when(commandExecutor.executeCommand(entrySearchResultMapStringObjectCommandObject)).thenReturn(expectedResponse); + + Map.Entry> result = jedis.ftProfileSearch(indexName, profileParams, query); + + assertThat(result, equalTo(expectedResponse)); + + verify(commandExecutor).executeCommand(entrySearchResultMapStringObjectCommandObject); + verify(commandObjects).ftProfileSearch(indexName, profileParams, query); + } + + @Test + public void testFtProfileSearchWithQueryAndSearchParams() { + String indexName = "myIndex"; + FTProfileParams profileParams = new FTProfileParams(); + String query = "hello world"; + FTSearchParams searchParams = new FTSearchParams().noContent().limit(0, 10); + Map.Entry> expectedResponse = new AbstractMap.SimpleEntry<>( + mock(SearchResult.class), Collections.singletonMap("Profile", "Data")); + + when(commandObjects.ftProfileSearch(indexName, profileParams, query, searchParams)).thenReturn(entrySearchResultMapStringObjectCommandObject); + when(commandExecutor.executeCommand(entrySearchResultMapStringObjectCommandObject)).thenReturn(expectedResponse); + + Map.Entry> result = jedis.ftProfileSearch(indexName, profileParams, query, searchParams); + + assertThat(result, equalTo(expectedResponse)); + + verify(commandExecutor).executeCommand(entrySearchResultMapStringObjectCommandObject); + verify(commandObjects).ftProfileSearch(indexName, profileParams, query, searchParams); + } + + @Test + public void testSetDefaultSearchDialect() { + int dialect = 1; + + jedis.setDefaultSearchDialect(dialect); + + verify(commandObjects).setDefaultSearchDialect(dialect); + } + +} diff --git a/src/test/java/redis/clients/jedis/mocked/unified/UnifiedJedisServerManagementCommandsTest.java b/src/test/java/redis/clients/jedis/mocked/unified/UnifiedJedisServerManagementCommandsTest.java new file mode 100644 index 00000000000..3dc85aa2016 --- /dev/null +++ b/src/test/java/redis/clients/jedis/mocked/unified/UnifiedJedisServerManagementCommandsTest.java @@ -0,0 +1,149 @@ +package redis.clients.jedis.mocked.unified; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.equalTo; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import org.junit.Test; + +public class UnifiedJedisServerManagementCommandsTest extends UnifiedJedisMockedTestBase { + + @Test + public void testConfigSet() { + String parameter = "param"; + String value = "value"; + + when(commandObjects.configSet(parameter, value)).thenReturn(stringCommandObject); + when(commandExecutor.broadcastCommand(stringCommandObject)).thenReturn("OK"); + + String result = jedis.configSet(parameter, value); + + assertThat(result, equalTo("OK")); + + verify(commandExecutor).broadcastCommand(stringCommandObject); + verify(commandObjects).configSet(parameter, value); + } + + @Test + public void testDbSize() { + long expectedSize = 42L; + + when(commandObjects.dbSize()).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedSize); + + long result = jedis.dbSize(); + + assertThat(result, equalTo(expectedSize)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).dbSize(); + } + + @Test + public void testFlushAll() { + when(commandObjects.flushAll()).thenReturn(stringCommandObject); + when(commandExecutor.broadcastCommand(stringCommandObject)).thenReturn("OK"); + + String result = jedis.flushAll(); + + assertThat(result, equalTo("OK")); + + verify(commandExecutor).broadcastCommand(stringCommandObject); + verify(commandObjects).flushAll(); + } + + @Test + public void testFlushDB() { + when(commandObjects.flushDB()).thenReturn(stringCommandObject); + when(commandExecutor.broadcastCommand(stringCommandObject)).thenReturn("OK"); + + String result = jedis.flushDB(); + + assertThat(result, equalTo("OK")); + + verify(commandExecutor).broadcastCommand(stringCommandObject); + verify(commandObjects).flushDB(); + } + + @Test + public void testMemoryUsage() { + String key = "key1"; + Long expectedMemoryUsage = 1024L; + + when(commandObjects.memoryUsage(key)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedMemoryUsage); + + Long result = jedis.memoryUsage(key); + + assertThat(result, equalTo(expectedMemoryUsage)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).memoryUsage(key); + } + + @Test + public void testMemoryUsageWithSamples() { + String key = "key1"; + int samples = 5; + Long expectedMemoryUsage = 2048L; + + when(commandObjects.memoryUsage(key, samples)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedMemoryUsage); + + Long result = jedis.memoryUsage(key, samples); + + assertThat(result, equalTo(expectedMemoryUsage)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).memoryUsage(key, samples); + } + + @Test + public void testMemoryUsageBinary() { + byte[] key = new byte[]{ 1, 2, 3 }; + Long expectedMemoryUsage = 512L; + + when(commandObjects.memoryUsage(key)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedMemoryUsage); + + Long result = jedis.memoryUsage(key); + + assertThat(result, equalTo(expectedMemoryUsage)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).memoryUsage(key); + } + + @Test + public void testMemoryUsageWithSamplesBinary() { + byte[] key = new byte[]{ 1, 2, 3 }; + int samples = 5; + Long expectedMemoryUsage = 1024L; + + when(commandObjects.memoryUsage(key, samples)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedMemoryUsage); + + Long result = jedis.memoryUsage(key, samples); + + assertThat(result, equalTo(expectedMemoryUsage)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).memoryUsage(key, samples); + } + + @Test + public void testSlowlogReset() { + String expectedResponse = "OK"; + + when(commandObjects.slowlogReset()).thenReturn(stringCommandObject); + when(commandExecutor.broadcastCommand(stringCommandObject)).thenReturn(expectedResponse); + + String result = jedis.slowlogReset(); + + assertThat(result, equalTo(expectedResponse)); + verify(commandExecutor).broadcastCommand(stringCommandObject); + verify(commandObjects).slowlogReset(); + } + +} diff --git a/src/test/java/redis/clients/jedis/mocked/unified/UnifiedJedisSetCommandsTest.java b/src/test/java/redis/clients/jedis/mocked/unified/UnifiedJedisSetCommandsTest.java new file mode 100644 index 00000000000..3fe180baebe --- /dev/null +++ b/src/test/java/redis/clients/jedis/mocked/unified/UnifiedJedisSetCommandsTest.java @@ -0,0 +1,688 @@ +package redis.clients.jedis.mocked.unified; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.equalTo; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import java.util.Arrays; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import org.junit.Test; +import redis.clients.jedis.params.ScanParams; +import redis.clients.jedis.resps.ScanResult; + +public class UnifiedJedisSetCommandsTest extends UnifiedJedisMockedTestBase { + + @Test + public void testSadd() { + String key = "setKey"; + String[] members = { "member1", "member2" }; + long expectedAdded = 2L; // Assuming both members were added + + when(commandObjects.sadd(key, members)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedAdded); + + long result = jedis.sadd(key, members); + + assertThat(result, equalTo(expectedAdded)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).sadd(key, members); + } + + @Test + public void testSaddBinary() { + byte[] key = "setKey".getBytes(); + byte[][] members = { "member1".getBytes(), "member2".getBytes() }; + long expectedAdded = 2L; // Assuming both members were added + + when(commandObjects.sadd(key, members)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedAdded); + + long result = jedis.sadd(key, members); + + assertThat(result, equalTo(expectedAdded)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).sadd(key, members); + } + + @Test + public void testScard() { + String key = "setKey"; + long expectedCardinality = 3L; // Assuming the set has 3 members + + when(commandObjects.scard(key)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedCardinality); + + long result = jedis.scard(key); + + assertThat(result, equalTo(expectedCardinality)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).scard(key); + } + + @Test + public void testScardBinary() { + byte[] key = "setKey".getBytes(); + long expectedCardinality = 3L; // Assuming the set has 3 members + + when(commandObjects.scard(key)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedCardinality); + + long result = jedis.scard(key); + + assertThat(result, equalTo(expectedCardinality)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).scard(key); + } + + @Test + public void testSdiff() { + String[] keys = { "setKey1", "setKey2" }; + Set expectedDifference = new HashSet<>(Arrays.asList("member1", "member3")); // Assuming these members are in setKey1 but not in setKey2 + + when(commandObjects.sdiff(keys)).thenReturn(setStringCommandObject); + when(commandExecutor.executeCommand(setStringCommandObject)).thenReturn(expectedDifference); + + Set result = jedis.sdiff(keys); + + assertThat(result, equalTo(expectedDifference)); + + verify(commandExecutor).executeCommand(setStringCommandObject); + verify(commandObjects).sdiff(keys); + } + + @Test + public void testSdiffBinary() { + byte[][] keys = { "setKey1".getBytes(), "setKey2".getBytes() }; + Set expectedDifference = new HashSet<>(Arrays.asList("member1".getBytes(), "member3".getBytes())); // Assuming these members are in setKey1 but not in setKey2 + + when(commandObjects.sdiff(keys)).thenReturn(setBytesCommandObject); + when(commandExecutor.executeCommand(setBytesCommandObject)).thenReturn(expectedDifference); + + Set result = jedis.sdiff(keys); + + assertThat(result, equalTo(expectedDifference)); + + verify(commandExecutor).executeCommand(setBytesCommandObject); + verify(commandObjects).sdiff(keys); + } + + @Test + public void testSdiffstore() { + String dstkey = "destinationKey"; + String[] keys = { "setKey1", "setKey2" }; + long expectedStored = 2L; // Assuming two members were stored in the destination set + + when(commandObjects.sdiffstore(dstkey, keys)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedStored); + + long result = jedis.sdiffstore(dstkey, keys); + + assertThat(result, equalTo(expectedStored)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).sdiffstore(dstkey, keys); + } + + @Test + public void testSdiffstoreBinary() { + byte[] dstkey = "destinationKey".getBytes(); + byte[][] keys = { "setKey1".getBytes(), "setKey2".getBytes() }; + long expectedStored = 2L; // Assuming two members were stored in the destination set + + when(commandObjects.sdiffstore(dstkey, keys)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedStored); + + long result = jedis.sdiffstore(dstkey, keys); + + assertThat(result, equalTo(expectedStored)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).sdiffstore(dstkey, keys); + } + + @Test + public void testSinter() { + String[] keys = { "setKey1", "setKey2" }; + Set expectedIntersection = new HashSet<>(Arrays.asList("member2", "member4")); // Assuming these members are common to setKey1 and setKey2 + + when(commandObjects.sinter(keys)).thenReturn(setStringCommandObject); + when(commandExecutor.executeCommand(setStringCommandObject)).thenReturn(expectedIntersection); + + Set result = jedis.sinter(keys); + + assertThat(result, equalTo(expectedIntersection)); + + verify(commandExecutor).executeCommand(setStringCommandObject); + verify(commandObjects).sinter(keys); + } + + @Test + public void testSinterBinary() { + byte[][] keys = { "setKey1".getBytes(), "setKey2".getBytes() }; + Set expectedIntersection = new HashSet<>(Arrays.asList("member2".getBytes(), "member4".getBytes())); // Assuming these members are common to setKey1 and setKey2 + + when(commandObjects.sinter(keys)).thenReturn(setBytesCommandObject); + when(commandExecutor.executeCommand(setBytesCommandObject)).thenReturn(expectedIntersection); + + Set result = jedis.sinter(keys); + + assertThat(result, equalTo(expectedIntersection)); + + verify(commandExecutor).executeCommand(setBytesCommandObject); + verify(commandObjects).sinter(keys); + } + + @Test + public void testSintercard() { + String[] keys = { "setKey1", "setKey2" }; + long expectedCardinality = 2L; // Assuming there are two common members + + when(commandObjects.sintercard(keys)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedCardinality); + + long result = jedis.sintercard(keys); + + assertThat(result, equalTo(expectedCardinality)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).sintercard(keys); + } + + @Test + public void testSintercardBinary() { + byte[][] keys = { "setKey1".getBytes(), "setKey2".getBytes() }; + long expectedCardinality = 2L; // Assuming there are two common members + + when(commandObjects.sintercard(keys)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedCardinality); + + long result = jedis.sintercard(keys); + + assertThat(result, equalTo(expectedCardinality)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).sintercard(keys); + } + + @Test + public void testSintercardWithLimit() { + int limit = 1; + String[] keys = { "setKey1", "setKey2" }; + long expectedCardinality = 1L; // Assuming the limit is set to 1 and there is at least one common member + + when(commandObjects.sintercard(limit, keys)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedCardinality); + + long result = jedis.sintercard(limit, keys); + + assertThat(result, equalTo(expectedCardinality)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).sintercard(limit, keys); + } + + @Test + public void testSintercardWithLimitBinary() { + int limit = 1; + byte[][] keys = { "setKey1".getBytes(), "setKey2".getBytes() }; + long expectedCardinality = 1L; // Assuming the limit is set to 1 and there is at least one common member + + when(commandObjects.sintercard(limit, keys)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedCardinality); + + long result = jedis.sintercard(limit, keys); + + assertThat(result, equalTo(expectedCardinality)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).sintercard(limit, keys); + } + + @Test + public void testSinterstore() { + String dstkey = "destinationKey"; + String[] keys = { "setKey1", "setKey2" }; + long expectedStored = 2L; // Assuming two members were stored in the destination set + + when(commandObjects.sinterstore(dstkey, keys)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedStored); + + long result = jedis.sinterstore(dstkey, keys); + + assertThat(result, equalTo(expectedStored)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).sinterstore(dstkey, keys); + } + + @Test + public void testSinterstoreBinary() { + byte[] dstkey = "destinationKey".getBytes(); + byte[][] keys = { "setKey1".getBytes(), "setKey2".getBytes() }; + long expectedStored = 2L; // Assuming two members were stored in the destination set + + when(commandObjects.sinterstore(dstkey, keys)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedStored); + + long result = jedis.sinterstore(dstkey, keys); + + assertThat(result, equalTo(expectedStored)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).sinterstore(dstkey, keys); + } + + @Test + public void testSismember() { + String key = "setKey"; + String member = "member1"; + boolean expectedIsMember = true; // Assuming the member is part of the set + + when(commandObjects.sismember(key, member)).thenReturn(booleanCommandObject); + when(commandExecutor.executeCommand(booleanCommandObject)).thenReturn(expectedIsMember); + + boolean result = jedis.sismember(key, member); + + assertThat(result, equalTo(expectedIsMember)); + + verify(commandExecutor).executeCommand(booleanCommandObject); + verify(commandObjects).sismember(key, member); + } + + @Test + public void testSismemberBinary() { + byte[] key = "setKey".getBytes(); + byte[] member = "member1".getBytes(); + boolean expectedIsMember = true; // Assuming the member is part of the set + + when(commandObjects.sismember(key, member)).thenReturn(booleanCommandObject); + when(commandExecutor.executeCommand(booleanCommandObject)).thenReturn(expectedIsMember); + + boolean result = jedis.sismember(key, member); + + assertThat(result, equalTo(expectedIsMember)); + + verify(commandExecutor).executeCommand(booleanCommandObject); + verify(commandObjects).sismember(key, member); + } + + @Test + public void testSmembers() { + String key = "setKey"; + Set expectedMembers = new HashSet<>(Arrays.asList("member1", "member2")); + + when(commandObjects.smembers(key)).thenReturn(setStringCommandObject); + when(commandExecutor.executeCommand(setStringCommandObject)).thenReturn(expectedMembers); + + Set result = jedis.smembers(key); + + assertThat(result, equalTo(expectedMembers)); + + verify(commandExecutor).executeCommand(setStringCommandObject); + verify(commandObjects).smembers(key); + } + + @Test + public void testSmembersBinary() { + byte[] key = "setKey".getBytes(); + Set expectedMembers = new HashSet<>(Arrays.asList("member1".getBytes(), "member2".getBytes())); + + when(commandObjects.smembers(key)).thenReturn(setBytesCommandObject); + when(commandExecutor.executeCommand(setBytesCommandObject)).thenReturn(expectedMembers); + + Set result = jedis.smembers(key); + + assertThat(result, equalTo(expectedMembers)); + + verify(commandExecutor).executeCommand(setBytesCommandObject); + verify(commandObjects).smembers(key); + } + + @Test + public void testSmismember() { + String key = "setKey"; + String[] members = { "member1", "member2", "member3" }; + List expectedMembership = Arrays.asList(true, false, true); // Assuming the first and last members are part of the set + + when(commandObjects.smismember(key, members)).thenReturn(listBooleanCommandObject); + when(commandExecutor.executeCommand(listBooleanCommandObject)).thenReturn(expectedMembership); + + List result = jedis.smismember(key, members); + + assertThat(result, equalTo(expectedMembership)); + + verify(commandExecutor).executeCommand(listBooleanCommandObject); + verify(commandObjects).smismember(key, members); + } + + @Test + public void testSmismemberBinary() { + byte[] key = "setKey".getBytes(); + byte[][] members = { "member1".getBytes(), "member2".getBytes(), "member3".getBytes() }; + List expectedMembership = Arrays.asList(true, false, true); // Assuming the first and last members are part of the set + + when(commandObjects.smismember(key, members)).thenReturn(listBooleanCommandObject); + when(commandExecutor.executeCommand(listBooleanCommandObject)).thenReturn(expectedMembership); + + List result = jedis.smismember(key, members); + + assertThat(result, equalTo(expectedMembership)); + + verify(commandExecutor).executeCommand(listBooleanCommandObject); + verify(commandObjects).smismember(key, members); + } + + @Test + public void testSmove() { + String srckey = "sourceKey"; + String dstkey = "destinationKey"; + String member = "member1"; + long expectedMoved = 1L; // Assuming the member was successfully moved + + when(commandObjects.smove(srckey, dstkey, member)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedMoved); + + long result = jedis.smove(srckey, dstkey, member); + + assertThat(result, equalTo(expectedMoved)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).smove(srckey, dstkey, member); + } + + @Test + public void testSmoveBinary() { + byte[] srckey = "sourceKey".getBytes(); + byte[] dstkey = "destinationKey".getBytes(); + byte[] member = "member1".getBytes(); + long expectedMoved = 1L; // Assuming the member was successfully moved + + when(commandObjects.smove(srckey, dstkey, member)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedMoved); + + long result = jedis.smove(srckey, dstkey, member); + + assertThat(result, equalTo(expectedMoved)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).smove(srckey, dstkey, member); + } + + @Test + public void testSpop() { + String key = "setKey"; + String expectedPopped = "member1"; // Assuming "member1" was popped + + when(commandObjects.spop(key)).thenReturn(stringCommandObject); + when(commandExecutor.executeCommand(stringCommandObject)).thenReturn(expectedPopped); + + String result = jedis.spop(key); + + assertThat(result, equalTo(expectedPopped)); + + verify(commandExecutor).executeCommand(stringCommandObject); + verify(commandObjects).spop(key); + } + + @Test + public void testSpopBinary() { + byte[] key = "setKey".getBytes(); + byte[] expectedPopped = "member1".getBytes(); // Assuming "member1" was popped + + when(commandObjects.spop(key)).thenReturn(bytesCommandObject); + when(commandExecutor.executeCommand(bytesCommandObject)).thenReturn(expectedPopped); + + byte[] result = jedis.spop(key); + + assertThat(result, equalTo(expectedPopped)); + + verify(commandExecutor).executeCommand(bytesCommandObject); + verify(commandObjects).spop(key); + } + + @Test + public void testSpopCount() { + String key = "setKey"; + long count = 2; + Set expectedPopped = new HashSet<>(Arrays.asList("member1", "member2")); // Assuming these members were popped + + when(commandObjects.spop(key, count)).thenReturn(setStringCommandObject); + when(commandExecutor.executeCommand(setStringCommandObject)).thenReturn(expectedPopped); + + Set result = jedis.spop(key, count); + + assertThat(result, equalTo(expectedPopped)); + + verify(commandExecutor).executeCommand(setStringCommandObject); + verify(commandObjects).spop(key, count); + } + + @Test + public void testSpopCountBinary() { + byte[] key = "setKey".getBytes(); + long count = 2; + Set expectedPopped = new HashSet<>(Arrays.asList("member1".getBytes(), "member2".getBytes())); // Assuming these members were popped + + when(commandObjects.spop(key, count)).thenReturn(setBytesCommandObject); + when(commandExecutor.executeCommand(setBytesCommandObject)).thenReturn(expectedPopped); + + Set result = jedis.spop(key, count); + + assertThat(result, equalTo(expectedPopped)); + + verify(commandExecutor).executeCommand(setBytesCommandObject); + verify(commandObjects).spop(key, count); + } + + @Test + public void testSrandmember() { + String key = "setKey"; + String expectedRandomMember = "member1"; // Assuming "member1" is randomly selected + when(commandObjects.srandmember(key)).thenReturn(stringCommandObject); + when(commandExecutor.executeCommand(stringCommandObject)).thenReturn(expectedRandomMember); + + String result = jedis.srandmember(key); + + assertThat(result, equalTo(expectedRandomMember)); + + verify(commandExecutor).executeCommand(stringCommandObject); + verify(commandObjects).srandmember(key); + } + + @Test + public void testSrandmemberBinary() { + byte[] key = "setKey".getBytes(); + byte[] expectedRandomMember = "member1".getBytes(); // Assuming "member1" is randomly selected + + when(commandObjects.srandmember(key)).thenReturn(bytesCommandObject); + when(commandExecutor.executeCommand(bytesCommandObject)).thenReturn(expectedRandomMember); + + byte[] result = jedis.srandmember(key); + + assertThat(result, equalTo(expectedRandomMember)); + + verify(commandExecutor).executeCommand(bytesCommandObject); + verify(commandObjects).srandmember(key); + } + + @Test + public void testSrandmemberCount() { + String key = "setKey"; + int count = 2; + List expectedRandomMembers = Arrays.asList("member1", "member2"); // Assuming these members are randomly selected + + when(commandObjects.srandmember(key, count)).thenReturn(listStringCommandObject); + when(commandExecutor.executeCommand(listStringCommandObject)).thenReturn(expectedRandomMembers); + + List result = jedis.srandmember(key, count); + + assertThat(result, equalTo(expectedRandomMembers)); + + verify(commandExecutor).executeCommand(listStringCommandObject); + verify(commandObjects).srandmember(key, count); + } + + @Test + public void testSrandmemberCountBinary() { + byte[] key = "setKey".getBytes(); + int count = 2; + List expectedRandomMembers = Arrays.asList("member1".getBytes(), "member2".getBytes()); // Assuming these members are randomly selected + + when(commandObjects.srandmember(key, count)).thenReturn(listBytesCommandObject); + when(commandExecutor.executeCommand(listBytesCommandObject)).thenReturn(expectedRandomMembers); + + List result = jedis.srandmember(key, count); + + assertThat(result, equalTo(expectedRandomMembers)); + + verify(commandExecutor).executeCommand(listBytesCommandObject); + verify(commandObjects).srandmember(key, count); + } + + @Test + public void testSrem() { + String key = "setKey"; + String[] members = { "member1", "member2" }; + long expectedRemoved = 2L; // Assuming both members were removed + + when(commandObjects.srem(key, members)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedRemoved); + + long result = jedis.srem(key, members); + + assertThat(result, equalTo(expectedRemoved)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).srem(key, members); + } + + @Test + public void testSremBinary() { + byte[] key = "setKey".getBytes(); + byte[][] members = { "member1".getBytes(), "member2".getBytes() }; + long expectedRemoved = 2L; // Assuming both members were removed + + when(commandObjects.srem(key, members)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedRemoved); + + long result = jedis.srem(key, members); + + assertThat(result, equalTo(expectedRemoved)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).srem(key, members); + } + + @Test + public void testSscan() { + String key = "setKey"; + String cursor = "0"; + ScanParams params = new ScanParams().match("*").count(10); + List scanResultData = Arrays.asList("member1", "member2", "member3"); + ScanResult expectedScanResult = new ScanResult<>(cursor, scanResultData); + + when(commandObjects.sscan(key, cursor, params)).thenReturn(scanResultStringCommandObject); + when(commandExecutor.executeCommand(scanResultStringCommandObject)).thenReturn(expectedScanResult); + + ScanResult result = jedis.sscan(key, cursor, params); + + assertThat(result, equalTo(expectedScanResult)); + + verify(commandExecutor).executeCommand(scanResultStringCommandObject); + verify(commandObjects).sscan(key, cursor, params); + } + + @Test + public void testSscanBinary() { + byte[] key = "setKey".getBytes(); + byte[] cursor = ScanParams.SCAN_POINTER_START_BINARY; + ScanParams params = new ScanParams().match("*".getBytes()).count(10); + List scanResultData = Arrays.asList("member1".getBytes(), "member2".getBytes(), "member3".getBytes()); + ScanResult expectedScanResult = new ScanResult<>(cursor, scanResultData); + + when(commandObjects.sscan(key, cursor, params)).thenReturn(scanResultBytesCommandObject); + when(commandExecutor.executeCommand(scanResultBytesCommandObject)).thenReturn(expectedScanResult); + + ScanResult result = jedis.sscan(key, cursor, params); + + assertThat(result, equalTo(expectedScanResult)); + + verify(commandExecutor).executeCommand(scanResultBytesCommandObject); + verify(commandObjects).sscan(key, cursor, params); + } + + @Test + public void testSunion() { + String[] keys = { "setKey1", "setKey2" }; + Set expectedUnion = new HashSet<>(Arrays.asList("member1", "member2", "member3", "member4")); // Assuming these members are in either setKey1 or setKey2 + + when(commandObjects.sunion(keys)).thenReturn(setStringCommandObject); + when(commandExecutor.executeCommand(setStringCommandObject)).thenReturn(expectedUnion); + + Set result = jedis.sunion(keys); + + assertThat(result, equalTo(expectedUnion)); + + verify(commandExecutor).executeCommand(setStringCommandObject); + verify(commandObjects).sunion(keys); + } + + @Test + public void testSunionBinary() { + byte[][] keys = { "setKey1".getBytes(), "setKey2".getBytes() }; + Set expectedUnion = new HashSet<>(Arrays.asList("member1".getBytes(), "member2".getBytes(), "member3".getBytes(), "member4".getBytes())); // Assuming these members are in either setKey1 or setKey2 + + when(commandObjects.sunion(keys)).thenReturn(setBytesCommandObject); + when(commandExecutor.executeCommand(setBytesCommandObject)).thenReturn(expectedUnion); + + Set result = jedis.sunion(keys); + + assertThat(result, equalTo(expectedUnion)); + + verify(commandExecutor).executeCommand(setBytesCommandObject); + verify(commandObjects).sunion(keys); + } + + @Test + public void testSunionstore() { + String dstkey = "destinationKey"; + String[] keys = { "setKey1", "setKey2" }; + long expectedStored = 4L; // Assuming four unique members were stored in the destination set + + when(commandObjects.sunionstore(dstkey, keys)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedStored); + + long result = jedis.sunionstore(dstkey, keys); + + assertThat(result, equalTo(expectedStored)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).sunionstore(dstkey, keys); + } + + @Test + public void testSunionstoreBinary() { + byte[] dstkey = "destinationKey".getBytes(); + byte[][] keys = { "setKey1".getBytes(), "setKey2".getBytes() }; + long expectedStored = 4L; // Assuming four unique members were stored in the destination set + + when(commandObjects.sunionstore(dstkey, keys)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedStored); + + long result = jedis.sunionstore(dstkey, keys); + + assertThat(result, equalTo(expectedStored)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).sunionstore(dstkey, keys); + } + +} diff --git a/src/test/java/redis/clients/jedis/mocked/unified/UnifiedJedisSortedSetCommandsTest.java b/src/test/java/redis/clients/jedis/mocked/unified/UnifiedJedisSortedSetCommandsTest.java new file mode 100644 index 00000000000..2dea520ea85 --- /dev/null +++ b/src/test/java/redis/clients/jedis/mocked/unified/UnifiedJedisSortedSetCommandsTest.java @@ -0,0 +1,2886 @@ +package redis.clients.jedis.mocked.unified; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.equalTo; +import static org.junit.Assert.assertArrayEquals; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.junit.Test; +import redis.clients.jedis.args.SortedSetOption; +import redis.clients.jedis.params.ScanParams; +import redis.clients.jedis.params.ZAddParams; +import redis.clients.jedis.params.ZIncrByParams; +import redis.clients.jedis.params.ZParams; +import redis.clients.jedis.params.ZRangeParams; +import redis.clients.jedis.resps.ScanResult; +import redis.clients.jedis.resps.Tuple; +import redis.clients.jedis.util.KeyValue; + +public class UnifiedJedisSortedSetCommandsTest extends UnifiedJedisMockedTestBase { + + @Test + public void testBzmpop() { + double timeout = 2.0; + SortedSetOption option = SortedSetOption.MAX; + String[] keys = { "zset1", "zset2" }; + KeyValue> expectedPopResult = new KeyValue<>("zset1", Collections.singletonList(new Tuple("member1", 1.0))); + + when(commandObjects.bzmpop(timeout, option, keys)).thenReturn(keyValueStringListTupleCommandObject); + when(commandExecutor.executeCommand(keyValueStringListTupleCommandObject)).thenReturn(expectedPopResult); + + KeyValue> result = jedis.bzmpop(timeout, option, keys); + + assertThat(result, equalTo(expectedPopResult)); + + verify(commandExecutor).executeCommand(keyValueStringListTupleCommandObject); + verify(commandObjects).bzmpop(timeout, option, keys); + } + + @Test + public void testBzmpopBinary() { + double timeout = 2.0; + SortedSetOption option = SortedSetOption.MAX; + byte[][] keys = { "zset1".getBytes(), "zset2".getBytes() }; + KeyValue> expectedPopResult = new KeyValue<>("zset1".getBytes(), Collections.singletonList(new Tuple("member1", 1.0))); + + when(commandObjects.bzmpop(timeout, option, keys)).thenReturn(keyValueBytesListTupleCommandObject); + when(commandExecutor.executeCommand(keyValueBytesListTupleCommandObject)).thenReturn(expectedPopResult); + + KeyValue> result = jedis.bzmpop(timeout, option, keys); + + assertThat(result, equalTo(expectedPopResult)); + + verify(commandExecutor).executeCommand(keyValueBytesListTupleCommandObject); + verify(commandObjects).bzmpop(timeout, option, keys); + } + + @Test + public void testBzmpopWithCount() { + double timeout = 2.0; + SortedSetOption option = SortedSetOption.MAX; + int count = 2; + String[] keys = { "zset1", "zset2" }; + KeyValue> expectedPopResult = new KeyValue<>("zset1", Arrays.asList(new Tuple("member1", 1.0), new Tuple("member2", 2.0))); + + when(commandObjects.bzmpop(timeout, option, count, keys)).thenReturn(keyValueStringListTupleCommandObject); + when(commandExecutor.executeCommand(keyValueStringListTupleCommandObject)).thenReturn(expectedPopResult); + + KeyValue> result = jedis.bzmpop(timeout, option, count, keys); + + assertThat(result, equalTo(expectedPopResult)); + + verify(commandExecutor).executeCommand(keyValueStringListTupleCommandObject); + verify(commandObjects).bzmpop(timeout, option, count, keys); + } + + @Test + public void testBzmpopWithCountBinary() { + double timeout = 2.0; + SortedSetOption option = SortedSetOption.MAX; + int count = 2; + byte[][] keys = { "zset1".getBytes(), "zset2".getBytes() }; + KeyValue> expectedPopResult = new KeyValue<>("zset1".getBytes(), Arrays.asList(new Tuple("member1", 1.0), new Tuple("member2", 2.0))); + + when(commandObjects.bzmpop(timeout, option, count, keys)).thenReturn(keyValueBytesListTupleCommandObject); + when(commandExecutor.executeCommand(keyValueBytesListTupleCommandObject)).thenReturn(expectedPopResult); + + KeyValue> result = jedis.bzmpop(timeout, option, count, keys); + + assertThat(result, equalTo(expectedPopResult)); + + verify(commandExecutor).executeCommand(keyValueBytesListTupleCommandObject); + verify(commandObjects).bzmpop(timeout, option, count, keys); + } + + @Test + public void testBzpopmax() { + double timeout = 2.0; + String[] keys = { "zset1", "zset2" }; + Tuple expectedTuple = new Tuple("member1", 1.0); + KeyValue expectedKeyValue = new KeyValue<>("zset1", expectedTuple); + + when(commandObjects.bzpopmax(timeout, keys)).thenReturn(keyValueStringTupleCommandObject); + when(commandExecutor.executeCommand(keyValueStringTupleCommandObject)).thenReturn(expectedKeyValue); + + KeyValue result = jedis.bzpopmax(timeout, keys); + + assertThat(result, equalTo(expectedKeyValue)); + + verify(commandExecutor).executeCommand(keyValueStringTupleCommandObject); + verify(commandObjects).bzpopmax(timeout, keys); + } + + @Test + public void testBzpopmaxBinary() { + double timeout = 2.0; + byte[][] keys = { "zset1".getBytes(), "zset2".getBytes() }; + Tuple expectedTuple = new Tuple("member1".getBytes(), 1.0); + KeyValue expectedKeyValue = new KeyValue<>("zset1".getBytes(), expectedTuple); + + when(commandObjects.bzpopmax(timeout, keys)).thenReturn(keyValueBytesTupleCommandObject); + when(commandExecutor.executeCommand(keyValueBytesTupleCommandObject)).thenReturn(expectedKeyValue); + + KeyValue result = jedis.bzpopmax(timeout, keys); + + assertThat(result, equalTo(expectedKeyValue)); + + verify(commandExecutor).executeCommand(keyValueBytesTupleCommandObject); + verify(commandObjects).bzpopmax(timeout, keys); + } + + @Test + public void testBzpopmin() { + double timeout = 2.0; + String[] keys = { "zset1", "zset2" }; + Tuple expectedTuple = new Tuple("member1", 1.0); + KeyValue expectedKeyValue = new KeyValue<>("zset1", expectedTuple); + + when(commandObjects.bzpopmin(timeout, keys)).thenReturn(keyValueStringTupleCommandObject); + when(commandExecutor.executeCommand(keyValueStringTupleCommandObject)).thenReturn(expectedKeyValue); + + KeyValue result = jedis.bzpopmin(timeout, keys); + + assertThat(result, equalTo(expectedKeyValue)); + + verify(commandExecutor).executeCommand(keyValueStringTupleCommandObject); + verify(commandObjects).bzpopmin(timeout, keys); + } + + @Test + public void testBzpopminBinary() { + double timeout = 2.0; + byte[][] keys = { "zset1".getBytes(), "zset2".getBytes() }; + Tuple expectedTuple = new Tuple("member1".getBytes(), 1.0); + KeyValue expectedKeyValue = new KeyValue<>("zset1".getBytes(), expectedTuple); + + when(commandObjects.bzpopmin(timeout, keys)).thenReturn(keyValueBytesTupleCommandObject); + when(commandExecutor.executeCommand(keyValueBytesTupleCommandObject)).thenReturn(expectedKeyValue); + + KeyValue result = jedis.bzpopmin(timeout, keys); + + assertThat(result, equalTo(expectedKeyValue)); + + verify(commandExecutor).executeCommand(keyValueBytesTupleCommandObject); + verify(commandObjects).bzpopmin(timeout, keys); + } + + @Test + public void testZadd() { + String key = "zsetKey"; + double score = 1.0; + String member = "member1"; + long expectedAdded = 1L; // Assuming the member was successfully added + + when(commandObjects.zadd(key, score, member)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedAdded); + + long result = jedis.zadd(key, score, member); + + assertThat(result, equalTo(expectedAdded)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).zadd(key, score, member); + } + + @Test + public void testZaddBinary() { + byte[] key = "zsetKey".getBytes(); + double score = 1.0; + byte[] member = "member1".getBytes(); + long expectedAdded = 1L; // Assuming the member was successfully added + + when(commandObjects.zadd(key, score, member)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedAdded); + + long result = jedis.zadd(key, score, member); + + assertThat(result, equalTo(expectedAdded)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).zadd(key, score, member); + } + + @Test + public void testZaddWithParams() { + String key = "zsetKey"; + double score = 1.0; + String member = "member1"; + ZAddParams params = ZAddParams.zAddParams().nx(); + long expectedAdded = 1L; // Assuming the member was successfully added with NX flag + + when(commandObjects.zadd(key, score, member, params)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedAdded); + + long result = jedis.zadd(key, score, member, params); + + assertThat(result, equalTo(expectedAdded)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).zadd(key, score, member, params); + } + + @Test + public void testZaddWithParamsBinary() { + byte[] key = "zsetKey".getBytes(); + double score = 1.0; + byte[] member = "member1".getBytes(); + ZAddParams params = ZAddParams.zAddParams().nx(); + long expectedAdded = 1L; // Assuming the member was successfully added with NX flag + + when(commandObjects.zadd(key, score, member, params)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedAdded); + + long result = jedis.zadd(key, score, member, params); + + assertThat(result, equalTo(expectedAdded)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).zadd(key, score, member, params); + } + + @Test + public void testZaddMultiple() { + String key = "zsetKey"; + Map scoreMembers = new HashMap<>(); + scoreMembers.put("member1", 1.0); + scoreMembers.put("member2", 2.0); + long expectedAdded = 2L; // Assuming both members were successfully added + + when(commandObjects.zadd(key, scoreMembers)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedAdded); + + long result = jedis.zadd(key, scoreMembers); + + assertThat(result, equalTo(expectedAdded)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).zadd(key, scoreMembers); + } + + @Test + public void testZaddMultipleBinary() { + byte[] key = "zsetKey".getBytes(); + Map scoreMembers = new HashMap<>(); + scoreMembers.put("member1".getBytes(), 1.0); + scoreMembers.put("member2".getBytes(), 2.0); + long expectedAdded = 2L; // Assuming both members were successfully added + + when(commandObjects.zadd(key, scoreMembers)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedAdded); + + long result = jedis.zadd(key, scoreMembers); + + assertThat(result, equalTo(expectedAdded)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).zadd(key, scoreMembers); + } + + @Test + public void testZaddMultipleWithParams() { + String key = "zsetKey"; + Map scoreMembers = new HashMap<>(); + scoreMembers.put("member1", 1.0); + scoreMembers.put("member2", 2.0); + ZAddParams params = ZAddParams.zAddParams().xx(); + long expectedAdded = 2L; // Assuming both members were successfully added with XX flag + + when(commandObjects.zadd(key, scoreMembers, params)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedAdded); + + long result = jedis.zadd(key, scoreMembers, params); + + assertThat(result, equalTo(expectedAdded)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).zadd(key, scoreMembers, params); + } + + @Test + public void testZaddMultipleWithParamsBinary() { + byte[] key = "zsetKey".getBytes(); + Map scoreMembers = new HashMap<>(); + scoreMembers.put("member1".getBytes(), 1.0); + scoreMembers.put("member2".getBytes(), 2.0); + ZAddParams params = ZAddParams.zAddParams().xx(); + long expectedAdded = 2L; // Assuming both members were successfully added with XX flag + + when(commandObjects.zadd(key, scoreMembers, params)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedAdded); + + long result = jedis.zadd(key, scoreMembers, params); + + assertThat(result, equalTo(expectedAdded)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).zadd(key, scoreMembers, params); + } + + @Test + public void testZaddIncr() { + String key = "zsetKey"; + double score = 1.0; + String member = "member1"; + ZAddParams params = ZAddParams.zAddParams().ch(); + Double expectedNewScore = 2.0; // Assuming the member's score was incremented to 2.0 + + when(commandObjects.zaddIncr(key, score, member, params)).thenReturn(doubleCommandObject); + when(commandExecutor.executeCommand(doubleCommandObject)).thenReturn(expectedNewScore); + + Double result = jedis.zaddIncr(key, score, member, params); + + assertThat(result, equalTo(expectedNewScore)); + + verify(commandExecutor).executeCommand(doubleCommandObject); + verify(commandObjects).zaddIncr(key, score, member, params); + } + + @Test + public void testZaddIncrBinary() { + byte[] key = "zsetKey".getBytes(); + double score = 1.0; + byte[] member = "member1".getBytes(); + ZAddParams params = ZAddParams.zAddParams().ch(); + Double expectedNewScore = 2.0; // Assuming the member's score was incremented to 2.0 + + when(commandObjects.zaddIncr(key, score, member, params)).thenReturn(doubleCommandObject); + when(commandExecutor.executeCommand(doubleCommandObject)).thenReturn(expectedNewScore); + + Double result = jedis.zaddIncr(key, score, member, params); + + assertThat(result, equalTo(expectedNewScore)); + + verify(commandExecutor).executeCommand(doubleCommandObject); + verify(commandObjects).zaddIncr(key, score, member, params); + } + + @Test + public void testZcard() { + String key = "zsetKey"; + long expectedCardinality = 5L; // Assuming the sorted set has 5 members + + when(commandObjects.zcard(key)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedCardinality); + + long result = jedis.zcard(key); + + assertThat(result, equalTo(expectedCardinality)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).zcard(key); + } + + @Test + public void testZcardBinary() { + byte[] key = "zsetKey".getBytes(); + long expectedCardinality = 5L; // Assuming the sorted set has 5 members + + when(commandObjects.zcard(key)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedCardinality); + + long result = jedis.zcard(key); + + assertThat(result, equalTo(expectedCardinality)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).zcard(key); + } + + @Test + public void testZcount() { + String key = "zsetKey"; + String min = "1"; + String max = "2"; + long expectedCount = 3L; // Assuming there are 3 members within the score range + + when(commandObjects.zcount(key, min, max)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedCount); + + long result = jedis.zcount(key, min, max); + + assertThat(result, equalTo(expectedCount)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).zcount(key, min, max); + } + + @Test + public void testZcountBinary() { + byte[] key = "zsetKey".getBytes(); + byte[] min = "1".getBytes(); + byte[] max = "2".getBytes(); + long expectedCount = 3L; // Assuming there are 3 members within the score range + + when(commandObjects.zcount(key, min, max)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedCount); + + long result = jedis.zcount(key, min, max); + + assertThat(result, equalTo(expectedCount)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).zcount(key, min, max); + } + + @Test + public void testZcountDouble() { + String key = "zsetKey"; + double min = 1.0; + double max = 2.0; + long expectedCount = 3L; // Assuming there are 3 members within the score range + + when(commandObjects.zcount(key, min, max)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedCount); + + long result = jedis.zcount(key, min, max); + + assertThat(result, equalTo(expectedCount)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).zcount(key, min, max); + } + + @Test + public void testZcountDoubleBinary() { + byte[] key = "zsetKey".getBytes(); + double min = 1.0; + double max = 2.0; + long expectedCount = 3L; // Assuming there are 3 members within the score range + + when(commandObjects.zcount(key, min, max)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedCount); + + long result = jedis.zcount(key, min, max); + + assertThat(result, equalTo(expectedCount)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).zcount(key, min, max); + } + + @Test + public void testZdiff() { + String[] keys = { "zset1", "zset2", "zset3" }; + List expectedDifference = Arrays.asList("member1", "member3"); + + when(commandObjects.zdiff(keys)).thenReturn(listStringCommandObject); + when(commandExecutor.executeCommand(listStringCommandObject)).thenReturn(expectedDifference); + + List result = jedis.zdiff(keys); + + assertThat(result, equalTo(expectedDifference)); + + verify(commandExecutor).executeCommand(listStringCommandObject); + verify(commandObjects).zdiff(keys); + } + + @Test + public void testZdiffBinary() { + byte[][] keys = { "zset1".getBytes(), "zset2".getBytes(), "zset3".getBytes() }; + List expectedDifference = Arrays.asList("member1".getBytes(), "member3".getBytes()); + + when(commandObjects.zdiff(keys)).thenReturn(listBytesCommandObject); + when(commandExecutor.executeCommand(listBytesCommandObject)).thenReturn(expectedDifference); + + List result = jedis.zdiff(keys); + + assertThat(result, equalTo(expectedDifference)); + + verify(commandExecutor).executeCommand(listBytesCommandObject); + verify(commandObjects).zdiff(keys); + } + + @Test + public void testZdiffWithScores() { + String[] keys = { "zset1", "zset2", "zset3" }; + List expectedDifferenceWithScores = Arrays.asList( + new Tuple("member1", 1.0), + new Tuple("member3", 3.0) + ); + + when(commandObjects.zdiffWithScores(keys)).thenReturn(listTupleCommandObject); + when(commandExecutor.executeCommand(listTupleCommandObject)).thenReturn(expectedDifferenceWithScores); + + List result = jedis.zdiffWithScores(keys); + + assertThat(result, equalTo(expectedDifferenceWithScores)); + + verify(commandExecutor).executeCommand(listTupleCommandObject); + verify(commandObjects).zdiffWithScores(keys); + } + + @Test + public void testZdiffWithScoresBinary() { + byte[][] keys = { "zset1".getBytes(), "zset2".getBytes(), "zset3".getBytes() }; + List expectedDifferenceWithScores = Arrays.asList( + new Tuple("member1".getBytes(), 1.0), + new Tuple("member3".getBytes(), 3.0) + ); + + when(commandObjects.zdiffWithScores(keys)).thenReturn(listTupleCommandObject); + when(commandExecutor.executeCommand(listTupleCommandObject)).thenReturn(expectedDifferenceWithScores); + + List result = jedis.zdiffWithScores(keys); + + assertThat(result, equalTo(expectedDifferenceWithScores)); + + verify(commandExecutor).executeCommand(listTupleCommandObject); + verify(commandObjects).zdiffWithScores(keys); + } + + @Test + public void testZdiffStore() { + String dstkey = "zsetDiff"; + String[] keys = { "zset1", "zset2", "zset3" }; + long expectedStoredCount = 2L; // Assuming 2 elements were stored + + when(commandObjects.zdiffStore(dstkey, keys)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedStoredCount); + + long result = jedis.zdiffStore(dstkey, keys); + + assertThat(result, equalTo(expectedStoredCount)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).zdiffStore(dstkey, keys); + } + + @Test + public void testZdiffStoreBinary() { + byte[] dstkey = "zsetDiff".getBytes(); + byte[][] keys = { "zset1".getBytes(), "zset2".getBytes(), "zset3".getBytes() }; + long expectedStoredCount = 2L; // Assuming 2 elements were stored + + when(commandObjects.zdiffStore(dstkey, keys)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedStoredCount); + + long result = jedis.zdiffStore(dstkey, keys); + + assertThat(result, equalTo(expectedStoredCount)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).zdiffStore(dstkey, keys); + } + + @Test + public void testZdiffstore() { + String dstkey = "zsetDiff"; + String[] keys = { "zset1", "zset2", "zset3" }; + long expectedStoredCount = 2L; // Assuming 2 elements were stored + + when(commandObjects.zdiffstore(dstkey, keys)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedStoredCount); + + long result = jedis.zdiffstore(dstkey, keys); + + assertThat(result, equalTo(expectedStoredCount)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).zdiffstore(dstkey, keys); + } + + @Test + public void testZdiffstoreBinary() { + byte[] dstkey = "zsetDiff".getBytes(); + byte[][] keys = { "zset1".getBytes(), "zset2".getBytes(), "zset3".getBytes() }; + long expectedStoredCount = 2L; // Assuming 2 elements were stored + + when(commandObjects.zdiffstore(dstkey, keys)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedStoredCount); + + long result = jedis.zdiffstore(dstkey, keys); + + assertThat(result, equalTo(expectedStoredCount)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).zdiffstore(dstkey, keys); + } + + @Test + public void testZincrby() { + String key = "zsetKey"; + double increment = 2.0; + String member = "member1"; + double expectedScore = 3.0; // Assuming the member's score was incremented to 3.0 + + when(commandObjects.zincrby(key, increment, member)).thenReturn(doubleCommandObject); + when(commandExecutor.executeCommand(doubleCommandObject)).thenReturn(expectedScore); + + double result = jedis.zincrby(key, increment, member); + + assertThat(result, equalTo(expectedScore)); + + verify(commandExecutor).executeCommand(doubleCommandObject); + verify(commandObjects).zincrby(key, increment, member); + } + + @Test + public void testZincrbyBinary() { + byte[] key = "zsetKey".getBytes(); + double increment = 2.0; + byte[] member = "member1".getBytes(); + double expectedScore = 3.0; // Assuming the member's score was incremented to 3.0 + + when(commandObjects.zincrby(key, increment, member)).thenReturn(doubleCommandObject); + when(commandExecutor.executeCommand(doubleCommandObject)).thenReturn(expectedScore); + + double result = jedis.zincrby(key, increment, member); + + assertThat(result, equalTo(expectedScore)); + + verify(commandExecutor).executeCommand(doubleCommandObject); + verify(commandObjects).zincrby(key, increment, member); + } + + @Test + public void testZincrbyWithParams() { + String key = "zsetKey"; + double increment = 1.5; + String member = "member1"; + ZIncrByParams params = ZIncrByParams.zIncrByParams().xx(); + Double expectedNewScore = 4.5; // Assuming the member's score was incremented to 4.5 with XX flag + + when(commandObjects.zincrby(key, increment, member, params)).thenReturn(doubleCommandObject); + when(commandExecutor.executeCommand(doubleCommandObject)).thenReturn(expectedNewScore); + + Double result = jedis.zincrby(key, increment, member, params); + + assertThat(result, equalTo(expectedNewScore)); + + verify(commandExecutor).executeCommand(doubleCommandObject); + verify(commandObjects).zincrby(key, increment, member, params); + } + + @Test + public void testZincrbyWithParamsBinary() { + byte[] key = "zsetKey".getBytes(); + double increment = 1.5; + byte[] member = "member1".getBytes(); + ZIncrByParams params = ZIncrByParams.zIncrByParams().xx(); + Double expectedNewScore = 4.5; // Assuming the member's score was incremented to 4.5 with XX flag + + when(commandObjects.zincrby(key, increment, member, params)).thenReturn(doubleCommandObject); + when(commandExecutor.executeCommand(doubleCommandObject)).thenReturn(expectedNewScore); + + Double result = jedis.zincrby(key, increment, member, params); + + assertThat(result, equalTo(expectedNewScore)); + + verify(commandExecutor).executeCommand(doubleCommandObject); + verify(commandObjects).zincrby(key, increment, member, params); + } + + @Test + public void testZinter() { + ZParams params = new ZParams().weights(2, 3).aggregate(ZParams.Aggregate.SUM); + String[] keys = { "zset1", "zset2" }; + List expectedIntersection = Arrays.asList("member1", "member2"); + + when(commandObjects.zinter(params, keys)).thenReturn(listStringCommandObject); + when(commandExecutor.executeCommand(listStringCommandObject)).thenReturn(expectedIntersection); + + List result = jedis.zinter(params, keys); + + assertThat(result, equalTo(expectedIntersection)); + + verify(commandExecutor).executeCommand(listStringCommandObject); + verify(commandObjects).zinter(params, keys); + } + + @Test + public void testZinterBinary() { + ZParams params = new ZParams().weights(1, 2).aggregate(ZParams.Aggregate.MAX); + byte[][] keys = { "zset1".getBytes(), "zset2".getBytes() }; + List expectedIntersection = Arrays.asList("member1".getBytes(), "member2".getBytes()); + + when(commandObjects.zinter(params, keys)).thenReturn(listBytesCommandObject); + when(commandExecutor.executeCommand(listBytesCommandObject)).thenReturn(expectedIntersection); + + List result = jedis.zinter(params, keys); + + assertThat(result, equalTo(expectedIntersection)); + + verify(commandExecutor).executeCommand(listBytesCommandObject); + verify(commandObjects).zinter(params, keys); + } + + @Test + public void testZinterWithScores() { + ZParams params = new ZParams().weights(2, 3).aggregate(ZParams.Aggregate.SUM); + String[] keys = { "zset1", "zset2" }; + List expectedIntersectionWithScores = Arrays.asList( + new Tuple("member1", 5.0), + new Tuple("member2", 9.0) + ); + + when(commandObjects.zinterWithScores(params, keys)).thenReturn(listTupleCommandObject); + when(commandExecutor.executeCommand(listTupleCommandObject)).thenReturn(expectedIntersectionWithScores); + + List result = jedis.zinterWithScores(params, keys); + + assertThat(result, equalTo(expectedIntersectionWithScores)); + + verify(commandExecutor).executeCommand(listTupleCommandObject); + verify(commandObjects).zinterWithScores(params, keys); + } + + @Test + public void testZinterWithScoresBinary() { + ZParams params = new ZParams().weights(1, 2).aggregate(ZParams.Aggregate.MAX); + byte[][] keys = { "zset1".getBytes(), "zset2".getBytes() }; + List expectedIntersectionWithScores = Arrays.asList(new Tuple("member1", 1.0), new Tuple("member2", 2.0)); + + when(commandObjects.zinterWithScores(params, keys)).thenReturn(listTupleCommandObject); + when(commandExecutor.executeCommand(listTupleCommandObject)).thenReturn(expectedIntersectionWithScores); + + List result = jedis.zinterWithScores(params, keys); + + assertThat(result, equalTo(expectedIntersectionWithScores)); + + verify(commandExecutor).executeCommand(listTupleCommandObject); + verify(commandObjects).zinterWithScores(params, keys); + } + + @Test + public void testZintercard() { + String[] keys = { "zset1", "zset2" }; + long expectedCardinality = 2L; + + when(commandObjects.zintercard(keys)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedCardinality); + + long result = jedis.zintercard(keys); + + assertThat(result, equalTo(expectedCardinality)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).zintercard(keys); + } + + @Test + public void testZintercardBinary() { + byte[][] keys = { "zset1".getBytes(), "zset2".getBytes() }; + long expectedCardinality = 2L; // Assuming the cardinality of the intersection is 2 + + when(commandObjects.zintercard(keys)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedCardinality); + + long result = jedis.zintercard(keys); + + assertThat(result, equalTo(expectedCardinality)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).zintercard(keys); + } + + @Test + public void testZintercardWithLimit() { + String[] keys = { "zset1", "zset2" }; + long limit = 1000L; + long expectedCardinality = 2L; + + when(commandObjects.zintercard(limit, keys)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedCardinality); + + long result = jedis.zintercard(limit, keys); + + assertThat(result, equalTo(expectedCardinality)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).zintercard(limit, keys); + } + + @Test + public void testZintercardWithLimitBinary() { + byte[][] keys = { "zset1".getBytes(), "zset2".getBytes() }; + long limit = 1000L; + long expectedIntersectionCardinality = 5L; + + when(commandObjects.zintercard(limit, keys)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedIntersectionCardinality); + + long result = jedis.zintercard(limit, keys); + + assertThat(result, equalTo(expectedIntersectionCardinality)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).zintercard(limit, keys); + } + + @Test + public void testZinterstore() { + String dstkey = "zsetInter"; + String[] sets = { "zset1", "zset2" }; + long expectedStoredCount = 3L; // Assuming 3 elements were stored + + when(commandObjects.zinterstore(dstkey, sets)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedStoredCount); + + long result = jedis.zinterstore(dstkey, sets); + + assertThat(result, equalTo(expectedStoredCount)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).zinterstore(dstkey, sets); + } + + @Test + public void testZinterstoreBinary() { + byte[] dstkey = "zsetInter".getBytes(); + byte[][] sets = { "zset1".getBytes(), "zset2".getBytes() }; + long expectedStoredCount = 3L; // Assuming 3 elements were stored + + when(commandObjects.zinterstore(dstkey, sets)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedStoredCount); + + long result = jedis.zinterstore(dstkey, sets); + + assertThat(result, equalTo(expectedStoredCount)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).zinterstore(dstkey, sets); + } + + @Test + public void testZinterstoreWithParams() { + String dstkey = "zsetInter"; + ZParams params = new ZParams().weights(2, 3).aggregate(ZParams.Aggregate.SUM); + String[] sets = { "zset1", "zset2" }; + long expectedStoredCount = 3L; // Assuming 3 elements were stored with the specified weights and aggregation + + when(commandObjects.zinterstore(dstkey, params, sets)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedStoredCount); + + long result = jedis.zinterstore(dstkey, params, sets); + + assertThat(result, equalTo(expectedStoredCount)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).zinterstore(dstkey, params, sets); + } + + @Test + public void testZinterstoreWithParamsBinary() { + byte[] dstkey = "zsetInter".getBytes(); + ZParams params = new ZParams().weights(2, 3).aggregate(ZParams.Aggregate.SUM); + byte[][] sets = { "zset1".getBytes(), "zset2".getBytes() }; + long expectedStoredCount = 3L; // Assuming 3 elements were stored with the specified weights and aggregation + + when(commandObjects.zinterstore(dstkey, params, sets)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedStoredCount); + + long result = jedis.zinterstore(dstkey, params, sets); + + assertThat(result, equalTo(expectedStoredCount)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).zinterstore(dstkey, params, sets); + } + + @Test + public void testZlexcount() { + String key = "zsetKey"; + String min = "[a"; + String max = "(b"; + long expectedCount = 5L; // Assuming there are 5 elements in the lex range + + when(commandObjects.zlexcount(key, min, max)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedCount); + + long result = jedis.zlexcount(key, min, max); + + assertThat(result, equalTo(expectedCount)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).zlexcount(key, min, max); + } + + @Test + public void testZlexcountBinary() { + byte[] key = "zsetKey".getBytes(); + byte[] min = "[a".getBytes(); + byte[] max = "[b".getBytes(); + long expectedCount = 5L; // Assuming there are 5 elements in the lex range + + when(commandObjects.zlexcount(key, min, max)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedCount); + + long result = jedis.zlexcount(key, min, max); + + assertThat(result, equalTo(expectedCount)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).zlexcount(key, min, max); + } + + @Test + public void testZmpop() { + SortedSetOption option = SortedSetOption.MAX; + String[] keys = { "zset1", "zset2" }; + KeyValue> expectedPopResult = new KeyValue<>("zset1", Collections.singletonList(new Tuple("member1", 1.0))); + + when(commandObjects.zmpop(option, keys)).thenReturn(keyValueStringListTupleCommandObject); + when(commandExecutor.executeCommand(keyValueStringListTupleCommandObject)).thenReturn(expectedPopResult); + + KeyValue> result = jedis.zmpop(option, keys); + + assertThat(result, equalTo(expectedPopResult)); + + verify(commandExecutor).executeCommand(keyValueStringListTupleCommandObject); + verify(commandObjects).zmpop(option, keys); + } + + @Test + public void testZmpopBinary() { + SortedSetOption option = SortedSetOption.MAX; + byte[][] keys = { "zset1".getBytes(), "zset2".getBytes() }; + KeyValue> expectedPopResult = new KeyValue<>("zset1".getBytes(), Collections.singletonList(new Tuple("member1", 1.0))); + + when(commandObjects.zmpop(option, keys)).thenReturn(keyValueBytesListTupleCommandObject); + when(commandExecutor.executeCommand(keyValueBytesListTupleCommandObject)).thenReturn(expectedPopResult); + + KeyValue> result = jedis.zmpop(option, keys); + + assertThat(result, equalTo(expectedPopResult)); + + verify(commandExecutor).executeCommand(keyValueBytesListTupleCommandObject); + verify(commandObjects).zmpop(option, keys); + } + + @Test + public void testZmpopWithCount() { + SortedSetOption option = SortedSetOption.MAX; + int count = 2; + String[] keys = { "zset1", "zset2" }; + KeyValue> expectedPopResult = new KeyValue<>("zset1", Arrays.asList(new Tuple("member1", 1.0), new Tuple("member2", 2.0))); + + when(commandObjects.zmpop(option, count, keys)).thenReturn(keyValueStringListTupleCommandObject); + when(commandExecutor.executeCommand(keyValueStringListTupleCommandObject)).thenReturn(expectedPopResult); + + KeyValue> result = jedis.zmpop(option, count, keys); + + assertThat(result, equalTo(expectedPopResult)); + + verify(commandExecutor).executeCommand(keyValueStringListTupleCommandObject); + verify(commandObjects).zmpop(option, count, keys); + } + + @Test + public void testZmpopWithCountBinary() { + SortedSetOption option = SortedSetOption.MAX; + int count = 2; + byte[][] keys = { "zset1".getBytes(), "zset2".getBytes() }; + KeyValue> expectedPopResult = new KeyValue<>("zset1".getBytes(), Arrays.asList(new Tuple("member1", 1.0), new Tuple("member2", 2.0))); + + when(commandObjects.zmpop(option, count, keys)).thenReturn(keyValueBytesListTupleCommandObject); + when(commandExecutor.executeCommand(keyValueBytesListTupleCommandObject)).thenReturn(expectedPopResult); + + KeyValue> result = jedis.zmpop(option, count, keys); + + assertThat(result, equalTo(expectedPopResult)); + + verify(commandExecutor).executeCommand(keyValueBytesListTupleCommandObject); + verify(commandObjects).zmpop(option, count, keys); + } + + @Test + public void testZmscore() { + String key = "zsetKey"; + String[] members = { "member1", "member2" }; + List expectedScores = Arrays.asList(1.0, 2.0); // Assuming the members have scores of 1.0 and 2.0 respectively + + when(commandObjects.zmscore(key, members)).thenReturn(listDoubleCommandObject); + when(commandExecutor.executeCommand(listDoubleCommandObject)).thenReturn(expectedScores); + + List result = jedis.zmscore(key, members); + + assertThat(result, equalTo(expectedScores)); + + verify(commandExecutor).executeCommand(listDoubleCommandObject); + verify(commandObjects).zmscore(key, members); + } + + @Test + public void testZmscoreBinary() { + byte[] key = "zsetKey".getBytes(); + byte[][] members = { "member1".getBytes(), "member2".getBytes() }; + List expectedScores = Arrays.asList(1.0, 2.0); // Assuming the members have scores of 1.0 and 2.0 respectively + + when(commandObjects.zmscore(key, members)).thenReturn(listDoubleCommandObject); + when(commandExecutor.executeCommand(listDoubleCommandObject)).thenReturn(expectedScores); + + List result = jedis.zmscore(key, members); + + assertThat(result, equalTo(expectedScores)); + + verify(commandExecutor).executeCommand(listDoubleCommandObject); + verify(commandObjects).zmscore(key, members); + } + + @Test + public void testZpopmax() { + String key = "zsetKey"; + Tuple expectedTuple = new Tuple("member1", 2.0); // Assuming this member has the highest score + + when(commandObjects.zpopmax(key)).thenReturn(tupleCommandObject); + when(commandExecutor.executeCommand(tupleCommandObject)).thenReturn(expectedTuple); + + Tuple result = jedis.zpopmax(key); + + assertThat(result, equalTo(expectedTuple)); + + verify(commandExecutor).executeCommand(tupleCommandObject); + verify(commandObjects).zpopmax(key); + } + + @Test + public void testZpopmaxBinary() { + byte[] key = "zsetKey".getBytes(); + Tuple expectedTuple = new Tuple("member1".getBytes(), 2.0); // Assuming this member has the highest score + + when(commandObjects.zpopmax(key)).thenReturn(tupleCommandObject); + when(commandExecutor.executeCommand(tupleCommandObject)).thenReturn(expectedTuple); + + Tuple result = jedis.zpopmax(key); + + assertThat(result, equalTo(expectedTuple)); + + verify(commandExecutor).executeCommand(tupleCommandObject); + verify(commandObjects).zpopmax(key); + } + + @Test + public void testZpopmaxWithCount() { + String key = "zsetKey"; + int count = 2; + List expectedTuples = Arrays.asList( + new Tuple("member1", 2.0), + new Tuple("member2", 1.5) + ); // Assuming these members have the highest scores + + when(commandObjects.zpopmax(key, count)).thenReturn(listTupleCommandObject); + when(commandExecutor.executeCommand(listTupleCommandObject)).thenReturn(expectedTuples); + + List result = jedis.zpopmax(key, count); + + assertThat(result, equalTo(expectedTuples)); + + verify(commandExecutor).executeCommand(listTupleCommandObject); + verify(commandObjects).zpopmax(key, count); + } + + @Test + public void testZpopmaxWithCountBinary() { + byte[] key = "zsetKey".getBytes(); + int count = 2; + List expectedTuples = Arrays.asList( + new Tuple("member1".getBytes(), 2.0), + new Tuple("member2".getBytes(), 1.5) + ); // Assuming these members have the highest scores + + when(commandObjects.zpopmax(key, count)).thenReturn(listTupleCommandObject); + when(commandExecutor.executeCommand(listTupleCommandObject)).thenReturn(expectedTuples); + + List result = jedis.zpopmax(key, count); + + assertThat(result, equalTo(expectedTuples)); + + verify(commandExecutor).executeCommand(listTupleCommandObject); + verify(commandObjects).zpopmax(key, count); + } + + @Test + public void testZpopmin() { + String key = "zsetKey"; + Tuple expectedTuple = new Tuple("member1", 1.0); // Assuming this member has the lowest score + + when(commandObjects.zpopmin(key)).thenReturn(tupleCommandObject); + when(commandExecutor.executeCommand(tupleCommandObject)).thenReturn(expectedTuple); + + Tuple result = jedis.zpopmin(key); + + assertThat(result, equalTo(expectedTuple)); + + verify(commandExecutor).executeCommand(tupleCommandObject); + verify(commandObjects).zpopmin(key); + } + + @Test + public void testZpopminBinary() { + byte[] key = "zsetKey".getBytes(); + Tuple expectedTuple = new Tuple("member1".getBytes(), 1.0); // Assuming this member has the lowest score + + when(commandObjects.zpopmin(key)).thenReturn(tupleCommandObject); + when(commandExecutor.executeCommand(tupleCommandObject)).thenReturn(expectedTuple); + + Tuple result = jedis.zpopmin(key); + + assertThat(result, equalTo(expectedTuple)); + + verify(commandExecutor).executeCommand(tupleCommandObject); + verify(commandObjects).zpopmin(key); + } + + @Test + public void testZpopminWithCount() { + String key = "zsetKey"; + int count = 2; + List expectedTuples = Arrays.asList( + new Tuple("member1", 1.0), + new Tuple("member2", 1.5) + ); // Assuming these members have the lowest scores + + when(commandObjects.zpopmin(key, count)).thenReturn(listTupleCommandObject); + when(commandExecutor.executeCommand(listTupleCommandObject)).thenReturn(expectedTuples); + + List result = jedis.zpopmin(key, count); + + assertThat(result, equalTo(expectedTuples)); + + verify(commandExecutor).executeCommand(listTupleCommandObject); + verify(commandObjects).zpopmin(key, count); + } + + @Test + public void testZpopminWithCountBinary() { + byte[] key = "zsetKey".getBytes(); + int count = 2; + List expectedTuples = Arrays.asList( + new Tuple("member1".getBytes(), 1.0), + new Tuple("member2".getBytes(), 1.5) + ); // Assuming these members have the lowest scores + + when(commandObjects.zpopmin(key, count)).thenReturn(listTupleCommandObject); + when(commandExecutor.executeCommand(listTupleCommandObject)).thenReturn(expectedTuples); + + List result = jedis.zpopmin(key, count); + + assertThat(result, equalTo(expectedTuples)); + + verify(commandExecutor).executeCommand(listTupleCommandObject); + verify(commandObjects).zpopmin(key, count); + } + + @Test + public void testZrandmember() { + String key = "zsetKey"; + String expectedMember = "member1"; // Assuming this member is randomly selected + + when(commandObjects.zrandmember(key)).thenReturn(stringCommandObject); + when(commandExecutor.executeCommand(stringCommandObject)).thenReturn(expectedMember); + + String result = jedis.zrandmember(key); + + assertThat(result, equalTo(expectedMember)); + + verify(commandExecutor).executeCommand(stringCommandObject); + verify(commandObjects).zrandmember(key); + } + + @Test + public void testZrandmemberBinary() { + byte[] key = "zsetKey".getBytes(); + byte[] expectedMember = "member1".getBytes(); // Assuming this member is randomly selected + + when(commandObjects.zrandmember(key)).thenReturn(bytesCommandObject); + when(commandExecutor.executeCommand(bytesCommandObject)).thenReturn(expectedMember); + + byte[] result = jedis.zrandmember(key); + + assertArrayEquals(expectedMember, result); + + verify(commandExecutor).executeCommand(bytesCommandObject); + verify(commandObjects).zrandmember(key); + } + + @Test + public void testZrandmemberWithCount() { + String key = "zsetKey"; + long count = 2; + List expectedMembers = Arrays.asList("member1", "member2"); // Assuming these members are randomly selected + + when(commandObjects.zrandmember(key, count)).thenReturn(listStringCommandObject); + when(commandExecutor.executeCommand(listStringCommandObject)).thenReturn(expectedMembers); + + List result = jedis.zrandmember(key, count); + + assertThat(result, equalTo(expectedMembers)); + + verify(commandExecutor).executeCommand(listStringCommandObject); + verify(commandObjects).zrandmember(key, count); + } + + @Test + public void testZrandmemberBytesWithCount() { + byte[] key = "zsetKey".getBytes(); + long count = 2; + List expectedMembers = Arrays.asList("member1".getBytes(), "member2".getBytes()); // Assuming these members are randomly selected + + when(commandObjects.zrandmember(key, count)).thenReturn(listBytesCommandObject); + when(commandExecutor.executeCommand(listBytesCommandObject)).thenReturn(expectedMembers); + + List result = jedis.zrandmember(key, count); + + for (int i = 0; i < expectedMembers.size(); i++) { + assertArrayEquals(expectedMembers.get(i), result.get(i)); + } + + verify(commandExecutor).executeCommand(listBytesCommandObject); + verify(commandObjects).zrandmember(key, count); + } + + @Test + public void testZrandmemberWithScores() { + String key = "zsetKey"; + long count = 2; + List expectedMembersWithScores = Arrays.asList( + new Tuple("member1", 1.0), + new Tuple("member2", 2.0) + ); // Assuming these members with scores are randomly selected + + when(commandObjects.zrandmemberWithScores(key, count)).thenReturn(listTupleCommandObject); + when(commandExecutor.executeCommand(listTupleCommandObject)).thenReturn(expectedMembersWithScores); + + List result = jedis.zrandmemberWithScores(key, count); + + assertThat(result, equalTo(expectedMembersWithScores)); + + verify(commandExecutor).executeCommand(listTupleCommandObject); + verify(commandObjects).zrandmemberWithScores(key, count); + } + + @Test + public void testZrandmemberWithScoresBinary() { + byte[] key = "zsetKey".getBytes(); + long count = 2; + List expectedMembersWithScores = Arrays.asList( + new Tuple("member1".getBytes(), 1.0), + new Tuple("member2".getBytes(), 2.0) + ); // Assuming these members with scores are randomly selected + + when(commandObjects.zrandmemberWithScores(key, count)).thenReturn(listTupleCommandObject); + when(commandExecutor.executeCommand(listTupleCommandObject)).thenReturn(expectedMembersWithScores); + + List result = jedis.zrandmemberWithScores(key, count); + + assertThat(result, equalTo(expectedMembersWithScores)); + + verify(commandExecutor).executeCommand(listTupleCommandObject); + verify(commandObjects).zrandmemberWithScores(key, count); + } + + @Test + public void testZrange() { + String key = "zsetKey"; + long start = 0; + long stop = -1; // This typically means all elements in the sorted set + List expectedMembers = Arrays.asList("member1", "member2", "member3"); + + when(commandObjects.zrange(key, start, stop)).thenReturn(listStringCommandObject); + when(commandExecutor.executeCommand(listStringCommandObject)).thenReturn(expectedMembers); + + List result = jedis.zrange(key, start, stop); + + assertThat(result, equalTo(expectedMembers)); + + verify(commandExecutor).executeCommand(listStringCommandObject); + verify(commandObjects).zrange(key, start, stop); + } + + @Test + public void testZrangeBinary() { + byte[] key = "zsetKey".getBytes(); + long start = 0; + long stop = -1; // This typically means all elements in the sorted set + List expectedMembers = Arrays.asList("member1".getBytes(), "member2".getBytes(), "member3".getBytes()); + + when(commandObjects.zrange(key, start, stop)).thenReturn(listBytesCommandObject); + when(commandExecutor.executeCommand(listBytesCommandObject)).thenReturn(expectedMembers); + + List result = jedis.zrange(key, start, stop); + + assertThat(result, equalTo(expectedMembers)); + + verify(commandExecutor).executeCommand(listBytesCommandObject); + verify(commandObjects).zrange(key, start, stop); + } + + @Test + public void testZrangeWithScores() { + String key = "zsetKey"; + long start = 0; + long stop = -1; // This typically means all elements in the sorted set with their scores + List expectedMembersWithScores = Arrays.asList( + new Tuple("member1", 1.0), + new Tuple("member2", 2.0), + new Tuple("member3", 3.0) + ); + + when(commandObjects.zrangeWithScores(key, start, stop)).thenReturn(listTupleCommandObject); + when(commandExecutor.executeCommand(listTupleCommandObject)).thenReturn(expectedMembersWithScores); + + List result = jedis.zrangeWithScores(key, start, stop); + + assertThat(result, equalTo(expectedMembersWithScores)); + + verify(commandExecutor).executeCommand(listTupleCommandObject); + verify(commandObjects).zrangeWithScores(key, start, stop); + } + + @Test + public void testZrangeWithScoresBinary() { + byte[] key = "zsetKey".getBytes(); + long start = 0; + long stop = -1; // This typically means all elements in the sorted set with their scores + List expectedMembersWithScores = Arrays.asList( + new Tuple("member1".getBytes(), 1.0), + new Tuple("member2".getBytes(), 2.0), + new Tuple("member3".getBytes(), 3.0) + ); + + when(commandObjects.zrangeWithScores(key, start, stop)).thenReturn(listTupleCommandObject); + when(commandExecutor.executeCommand(listTupleCommandObject)).thenReturn(expectedMembersWithScores); + + List result = jedis.zrangeWithScores(key, start, stop); + + assertThat(result, equalTo(expectedMembersWithScores)); + + verify(commandExecutor).executeCommand(listTupleCommandObject); + verify(commandObjects).zrangeWithScores(key, start, stop); + } + + @Test + public void testZrangeWithZRangeParams() { + String key = "zsetKey"; + ZRangeParams zRangeParams = ZRangeParams.zrangeParams(1, 3); + List expectedMembers = Arrays.asList("member1", "member2"); + + when(commandObjects.zrange(key, zRangeParams)).thenReturn(listStringCommandObject); + when(commandExecutor.executeCommand(listStringCommandObject)).thenReturn(expectedMembers); + + List result = jedis.zrange(key, zRangeParams); + + assertThat(result, equalTo(expectedMembers)); + + verify(commandExecutor).executeCommand(listStringCommandObject); + verify(commandObjects).zrange(key, zRangeParams); + } + + @Test + public void testZrangeWithZRangeParamsBinary() { + byte[] key = "zsetKey".getBytes(); + ZRangeParams zRangeParams = ZRangeParams.zrangeParams(1, 3); + List expectedMembers = Arrays.asList("member1".getBytes(), "member2".getBytes()); + + when(commandObjects.zrange(key, zRangeParams)).thenReturn(listBytesCommandObject); + when(commandExecutor.executeCommand(listBytesCommandObject)).thenReturn(expectedMembers); + + List result = jedis.zrange(key, zRangeParams); + + assertThat(result, equalTo(expectedMembers)); + + verify(commandExecutor).executeCommand(listBytesCommandObject); + verify(commandObjects).zrange(key, zRangeParams); + } + + @Test + public void testZrangeWithScoresWithZRangeParams() { + String key = "zsetKey"; + ZRangeParams zRangeParams = ZRangeParams.zrangeParams(1, 3); + List expectedMembersWithScores = Arrays.asList( + new Tuple("member1", 1.0), + new Tuple("member2", 2.0) + ); + + when(commandObjects.zrangeWithScores(key, zRangeParams)).thenReturn(listTupleCommandObject); + when(commandExecutor.executeCommand(listTupleCommandObject)).thenReturn(expectedMembersWithScores); + + List result = jedis.zrangeWithScores(key, zRangeParams); + + assertThat(result, equalTo(expectedMembersWithScores)); + + verify(commandExecutor).executeCommand(listTupleCommandObject); + verify(commandObjects).zrangeWithScores(key, zRangeParams); + } + + @Test + public void testZrangeWithScoresWithZRangeParamsBinary() { + byte[] key = "zsetKey".getBytes(); + ZRangeParams zRangeParams = ZRangeParams.zrangeParams(1, 3); + List expectedMembersWithScores = Arrays.asList( + new Tuple("member1".getBytes(), 1.0), + new Tuple("member2".getBytes(), 2.0) + ); + + when(commandObjects.zrangeWithScores(key, zRangeParams)).thenReturn(listTupleCommandObject); + when(commandExecutor.executeCommand(listTupleCommandObject)).thenReturn(expectedMembersWithScores); + + List result = jedis.zrangeWithScores(key, zRangeParams); + + assertThat(result, equalTo(expectedMembersWithScores)); + + verify(commandExecutor).executeCommand(listTupleCommandObject); + verify(commandObjects).zrangeWithScores(key, zRangeParams); + } + + @Test + public void testZrangeByLex() { + String key = "zsetKey"; + String min = "[a"; + String max = "(b"; + List expectedMembers = Arrays.asList("alpha", "beta"); + + when(commandObjects.zrangeByLex(key, min, max)).thenReturn(listStringCommandObject); + when(commandExecutor.executeCommand(listStringCommandObject)).thenReturn(expectedMembers); + + List result = jedis.zrangeByLex(key, min, max); + + assertThat(result, equalTo(expectedMembers)); + + verify(commandExecutor).executeCommand(listStringCommandObject); + verify(commandObjects).zrangeByLex(key, min, max); + } + + @Test + public void testZrangeByLexBinary() { + byte[] key = "zsetKey".getBytes(); + byte[] min = "[a".getBytes(); + byte[] max = "[b".getBytes(); + List expectedMembers = Arrays.asList("alpha".getBytes(), "beta".getBytes()); + + when(commandObjects.zrangeByLex(key, min, max)).thenReturn(listBytesCommandObject); + when(commandExecutor.executeCommand(listBytesCommandObject)).thenReturn(expectedMembers); + + List result = jedis.zrangeByLex(key, min, max); + + assertThat(result, equalTo(expectedMembers)); + + verify(commandExecutor).executeCommand(listBytesCommandObject); + verify(commandObjects).zrangeByLex(key, min, max); + } + + @Test + public void testZrangeByLexWithOffsetCount() { + String key = "zsetKey"; + String min = "[a"; + String max = "(b"; + int offset = 1; + int count = 2; + List expectedMembers = Arrays.asList("beta", "gamma"); + + when(commandObjects.zrangeByLex(key, min, max, offset, count)).thenReturn(listStringCommandObject); + when(commandExecutor.executeCommand(listStringCommandObject)).thenReturn(expectedMembers); + + List result = jedis.zrangeByLex(key, min, max, offset, count); + + assertThat(result, equalTo(expectedMembers)); + + verify(commandExecutor).executeCommand(listStringCommandObject); + verify(commandObjects).zrangeByLex(key, min, max, offset, count); + } + + @Test + public void testZrangeByLexWithOffsetCountBinary() { + byte[] key = "zsetKey".getBytes(); + byte[] min = "[a".getBytes(); + byte[] max = "[b".getBytes(); + int offset = 1; + int count = 2; + List expectedMembers = Arrays.asList("beta".getBytes(), "gamma".getBytes()); + + when(commandObjects.zrangeByLex(key, min, max, offset, count)).thenReturn(listBytesCommandObject); + when(commandExecutor.executeCommand(listBytesCommandObject)).thenReturn(expectedMembers); + + List result = jedis.zrangeByLex(key, min, max, offset, count); + + assertThat(result, equalTo(expectedMembers)); + + verify(commandExecutor).executeCommand(listBytesCommandObject); + verify(commandObjects).zrangeByLex(key, min, max, offset, count); + } + + @Test + public void testZrangeByScore() { + String key = "zsetKey"; + String min = "1"; + String max = "3"; + List expectedMembers = Arrays.asList("member1", "member2"); + + when(commandObjects.zrangeByScore(key, min, max)).thenReturn(listStringCommandObject); + when(commandExecutor.executeCommand(listStringCommandObject)).thenReturn(expectedMembers); + + List result = jedis.zrangeByScore(key, min, max); + + assertThat(result, equalTo(expectedMembers)); + + verify(commandExecutor).executeCommand(listStringCommandObject); + verify(commandObjects).zrangeByScore(key, min, max); + } + + @Test + public void testZrangeByScoreBinary() { + byte[] key = "zsetKey".getBytes(); + byte[] min = "1".getBytes(); + byte[] max = "3".getBytes(); + List expectedMembers = Arrays.asList("member1".getBytes(), "member2".getBytes()); + + when(commandObjects.zrangeByScore(key, min, max)).thenReturn(listBytesCommandObject); + when(commandExecutor.executeCommand(listBytesCommandObject)).thenReturn(expectedMembers); + + List result = jedis.zrangeByScore(key, min, max); + + assertThat(result, equalTo(expectedMembers)); + + verify(commandExecutor).executeCommand(listBytesCommandObject); + verify(commandObjects).zrangeByScore(key, min, max); + } + + @Test + public void testZrangeByScoreDouble() { + String key = "zsetKey"; + double min = 1.0; + double max = 3.0; + List expectedMembers = Arrays.asList("member1", "member2"); + + when(commandObjects.zrangeByScore(key, min, max)).thenReturn(listStringCommandObject); + when(commandExecutor.executeCommand(listStringCommandObject)).thenReturn(expectedMembers); + + List result = jedis.zrangeByScore(key, min, max); + + assertThat(result, equalTo(expectedMembers)); + + verify(commandExecutor).executeCommand(listStringCommandObject); + verify(commandObjects).zrangeByScore(key, min, max); + } + + @Test + public void testZrangeByScoreDoubleBinary() { + byte[] key = "zsetKey".getBytes(); + double min = 1.0; + double max = 3.0; + List expectedMembers = Arrays.asList("member1".getBytes(), "member2".getBytes()); + + when(commandObjects.zrangeByScore(key, min, max)).thenReturn(listBytesCommandObject); + when(commandExecutor.executeCommand(listBytesCommandObject)).thenReturn(expectedMembers); + + List result = jedis.zrangeByScore(key, min, max); + + assertThat(result, equalTo(expectedMembers)); + + verify(commandExecutor).executeCommand(listBytesCommandObject); + verify(commandObjects).zrangeByScore(key, min, max); + } + + @Test + public void testZrangeByScoreWithOffsetCount() { + String key = "zsetKey"; + String min = "1"; + String max = "3"; + int offset = 1; + int count = 2; + List expectedMembers = Arrays.asList("member2", "member3"); + + when(commandObjects.zrangeByScore(key, min, max, offset, count)).thenReturn(listStringCommandObject); + when(commandExecutor.executeCommand(listStringCommandObject)).thenReturn(expectedMembers); + + List result = jedis.zrangeByScore(key, min, max, offset, count); + + assertThat(result, equalTo(expectedMembers)); + + verify(commandExecutor).executeCommand(listStringCommandObject); + verify(commandObjects).zrangeByScore(key, min, max, offset, count); + } + + @Test + public void testZrangeByScoreWithOffsetCountBinary() { + byte[] key = "zsetKey".getBytes(); + byte[] min = "1".getBytes(); + byte[] max = "3".getBytes(); + int offset = 1; + int count = 2; + List expectedMembers = Arrays.asList("member2".getBytes(), "member3".getBytes()); + + when(commandObjects.zrangeByScore(key, min, max, offset, count)).thenReturn(listBytesCommandObject); + when(commandExecutor.executeCommand(listBytesCommandObject)).thenReturn(expectedMembers); + + List result = jedis.zrangeByScore(key, min, max, offset, count); + + assertThat(result, equalTo(expectedMembers)); + + verify(commandExecutor).executeCommand(listBytesCommandObject); + verify(commandObjects).zrangeByScore(key, min, max, offset, count); + } + + @Test + public void testZrangeByScoreDoubleWithOffsetCount() { + String key = "zsetKey"; + double min = 1.0; + double max = 3.0; + int offset = 1; + int count = 2; + List expectedMembers = Arrays.asList("member2", "member3"); + + when(commandObjects.zrangeByScore(key, min, max, offset, count)).thenReturn(listStringCommandObject); + when(commandExecutor.executeCommand(listStringCommandObject)).thenReturn(expectedMembers); + + List result = jedis.zrangeByScore(key, min, max, offset, count); + + assertThat(result, equalTo(expectedMembers)); + + verify(commandExecutor).executeCommand(listStringCommandObject); + verify(commandObjects).zrangeByScore(key, min, max, offset, count); + } + + @Test + public void testZrangeByScoreDoubleWithOffsetCountBinary() { + byte[] key = "zsetKey".getBytes(); + double min = 1.0; + double max = 3.0; + int offset = 1; + int count = 2; + List expectedMembers = Arrays.asList("member2".getBytes(), "member3".getBytes()); + + when(commandObjects.zrangeByScore(key, min, max, offset, count)).thenReturn(listBytesCommandObject); + when(commandExecutor.executeCommand(listBytesCommandObject)).thenReturn(expectedMembers); + + List result = jedis.zrangeByScore(key, min, max, offset, count); + + assertThat(result, equalTo(expectedMembers)); + + verify(commandExecutor).executeCommand(listBytesCommandObject); + verify(commandObjects).zrangeByScore(key, min, max, offset, count); + } + + @Test + public void testZrangeByScoreWithScores() { + String key = "zsetKey"; + String min = "1"; + String max = "3"; + List expectedMembersWithScores = Arrays.asList( + new Tuple("member1", 1.0), + new Tuple("member2", 2.0) + ); + + when(commandObjects.zrangeByScoreWithScores(key, min, max)).thenReturn(listTupleCommandObject); + when(commandExecutor.executeCommand(listTupleCommandObject)).thenReturn(expectedMembersWithScores); + + List result = jedis.zrangeByScoreWithScores(key, min, max); + + assertThat(result, equalTo(expectedMembersWithScores)); + + verify(commandExecutor).executeCommand(listTupleCommandObject); + verify(commandObjects).zrangeByScoreWithScores(key, min, max); + } + + @Test + public void testZrangeByScoreWithScoresBinary() { + byte[] key = "zsetKey".getBytes(); + byte[] min = "1".getBytes(); + byte[] max = "3".getBytes(); + List expectedMembersWithScores = Arrays.asList( + new Tuple("member1".getBytes(), 1.0), + new Tuple("member2".getBytes(), 2.0) + ); + + when(commandObjects.zrangeByScoreWithScores(key, min, max)).thenReturn(listTupleCommandObject); + when(commandExecutor.executeCommand(listTupleCommandObject)).thenReturn(expectedMembersWithScores); + + List result = jedis.zrangeByScoreWithScores(key, min, max); + + assertThat(result, equalTo(expectedMembersWithScores)); + + verify(commandExecutor).executeCommand(listTupleCommandObject); + verify(commandObjects).zrangeByScoreWithScores(key, min, max); + } + + @Test + public void testZrangeByScoreWithScoresDouble() { + String key = "zsetKey"; + double min = 1.0; + double max = 3.0; + List expectedMembersWithScores = Arrays.asList( + new Tuple("member1", 1.0), + new Tuple("member2", 2.0) + ); + + when(commandObjects.zrangeByScoreWithScores(key, min, max)).thenReturn(listTupleCommandObject); + when(commandExecutor.executeCommand(listTupleCommandObject)).thenReturn(expectedMembersWithScores); + + List result = jedis.zrangeByScoreWithScores(key, min, max); + + assertThat(result, equalTo(expectedMembersWithScores)); + + verify(commandExecutor).executeCommand(listTupleCommandObject); + verify(commandObjects).zrangeByScoreWithScores(key, min, max); + } + + @Test + public void testZrangeByScoreWithScoresDoubleBinary() { + byte[] key = "zsetKey".getBytes(); + double min = 1.0; + double max = 3.0; + List expectedMembersWithScores = Arrays.asList( + new Tuple("member1".getBytes(), 1.0), + new Tuple("member2".getBytes(), 2.0) + ); + + when(commandObjects.zrangeByScoreWithScores(key, min, max)).thenReturn(listTupleCommandObject); + when(commandExecutor.executeCommand(listTupleCommandObject)).thenReturn(expectedMembersWithScores); + + List result = jedis.zrangeByScoreWithScores(key, min, max); + + assertThat(result, equalTo(expectedMembersWithScores)); + + verify(commandExecutor).executeCommand(listTupleCommandObject); + verify(commandObjects).zrangeByScoreWithScores(key, min, max); + } + + @Test + public void testZrangeByScoreWithScoresWithOffsetCount() { + String key = "zsetKey"; + String min = "1"; + String max = "3"; + int offset = 1; + int count = 2; + List expectedMembersWithScores = Arrays.asList( + new Tuple("member2", 2.0), + new Tuple("member3", 3.0) + ); + + when(commandObjects.zrangeByScoreWithScores(key, min, max, offset, count)).thenReturn(listTupleCommandObject); + when(commandExecutor.executeCommand(listTupleCommandObject)).thenReturn(expectedMembersWithScores); + + List result = jedis.zrangeByScoreWithScores(key, min, max, offset, count); + + assertThat(result, equalTo(expectedMembersWithScores)); + + verify(commandExecutor).executeCommand(listTupleCommandObject); + verify(commandObjects).zrangeByScoreWithScores(key, min, max, offset, count); + } + + @Test + public void testZrangeByScoreWithScoresWithOffsetCountBinary() { + byte[] key = "zsetKey".getBytes(); + byte[] min = "1".getBytes(); + byte[] max = "3".getBytes(); + int offset = 1; + int count = 2; + List expectedMembersWithScores = Arrays.asList( + new Tuple("member2".getBytes(), 2.0), + new Tuple("member3".getBytes(), 3.0) + ); + + when(commandObjects.zrangeByScoreWithScores(key, min, max, offset, count)).thenReturn(listTupleCommandObject); + when(commandExecutor.executeCommand(listTupleCommandObject)).thenReturn(expectedMembersWithScores); + + List result = jedis.zrangeByScoreWithScores(key, min, max, offset, count); + + assertThat(result, equalTo(expectedMembersWithScores)); + + verify(commandExecutor).executeCommand(listTupleCommandObject); + verify(commandObjects).zrangeByScoreWithScores(key, min, max, offset, count); + } + + @Test + public void testZrangeByScoreWithScoresDoubleWithOffsetCount() { + String key = "zsetKey"; + double min = 1.0; + double max = 3.0; + int offset = 1; + int count = 2; + List expectedMembersWithScores = Arrays.asList( + new Tuple("member2", 2.0), + new Tuple("member3", 3.0) + ); + + when(commandObjects.zrangeByScoreWithScores(key, min, max, offset, count)).thenReturn(listTupleCommandObject); + when(commandExecutor.executeCommand(listTupleCommandObject)).thenReturn(expectedMembersWithScores); + + List result = jedis.zrangeByScoreWithScores(key, min, max, offset, count); + + assertThat(result, equalTo(expectedMembersWithScores)); + + verify(commandExecutor).executeCommand(listTupleCommandObject); + verify(commandObjects).zrangeByScoreWithScores(key, min, max, offset, count); + } + + @Test + public void testZrangeByScoreWithScoresDoubleWithOffsetCountBinary() { + byte[] key = "zsetKey".getBytes(); + double min = 1.0; + double max = 3.0; + int offset = 1; + int count = 2; + List expectedMembersWithScores = Arrays.asList( + new Tuple("member2".getBytes(), 2.0), + new Tuple("member3".getBytes(), 3.0) + ); + + when(commandObjects.zrangeByScoreWithScores(key, min, max, offset, count)).thenReturn(listTupleCommandObject); + when(commandExecutor.executeCommand(listTupleCommandObject)).thenReturn(expectedMembersWithScores); + + List result = jedis.zrangeByScoreWithScores(key, min, max, offset, count); + + assertThat(result, equalTo(expectedMembersWithScores)); + + verify(commandExecutor).executeCommand(listTupleCommandObject); + verify(commandObjects).zrangeByScoreWithScores(key, min, max, offset, count); + } + + @Test + public void testZrangestore() { + String dest = "destinationKey"; + String src = "sourceKey"; + ZRangeParams zRangeParams = ZRangeParams.zrangeParams(1, 3); + long expectedStoredCount = 2L; // Assuming 2 members were within the range and stored + + when(commandObjects.zrangestore(dest, src, zRangeParams)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedStoredCount); + + long result = jedis.zrangestore(dest, src, zRangeParams); + + assertThat(result, equalTo(expectedStoredCount)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).zrangestore(dest, src, zRangeParams); + } + + @Test + public void testZrangestoreBinary() { + byte[] dest = "destinationKey".getBytes(); + byte[] src = "sourceKey".getBytes(); + ZRangeParams zRangeParams = ZRangeParams.zrangeParams(1, 3); + long expectedStoredCount = 2L; // Assuming 2 members were within the range and stored + + when(commandObjects.zrangestore(dest, src, zRangeParams)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedStoredCount); + + long result = jedis.zrangestore(dest, src, zRangeParams); + + assertThat(result, equalTo(expectedStoredCount)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).zrangestore(dest, src, zRangeParams); + } + + @Test + public void testZrank() { + String key = "zsetKey"; + String member = "member1"; + Long expectedRank = 0L; // Assuming the member is the first in the sorted set + + when(commandObjects.zrank(key, member)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedRank); + + Long result = jedis.zrank(key, member); + + assertThat(result, equalTo(expectedRank)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).zrank(key, member); + } + + @Test + public void testZrankBinary() { + byte[] key = "zsetKey".getBytes(); + byte[] member = "member1".getBytes(); + Long expectedRank = 0L; // Assuming the member is the first in the sorted set + + when(commandObjects.zrank(key, member)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedRank); + + Long result = jedis.zrank(key, member); + + assertThat(result, equalTo(expectedRank)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).zrank(key, member); + } + + @Test + public void testZrankWithScore() { + String key = "zsetKey"; + String member = "member1"; + KeyValue expectedRankWithScore = new KeyValue<>(0L, 1.0); // Assuming the member is the first with a score of 1.0 + + when(commandObjects.zrankWithScore(key, member)).thenReturn(keyValueLongDoubleCommandObject); + when(commandExecutor.executeCommand(keyValueLongDoubleCommandObject)).thenReturn(expectedRankWithScore); + + KeyValue result = jedis.zrankWithScore(key, member); + + assertThat(result, equalTo(expectedRankWithScore)); + + verify(commandExecutor).executeCommand(keyValueLongDoubleCommandObject); + verify(commandObjects).zrankWithScore(key, member); + } + + @Test + public void testZrankWithScoreBinary() { + byte[] key = "zsetKey".getBytes(); + byte[] member = "member1".getBytes(); + KeyValue expectedRankWithScore = new KeyValue<>(0L, 1.0); // Assuming the member is the first with a score of 1.0 + + when(commandObjects.zrankWithScore(key, member)).thenReturn(keyValueLongDoubleCommandObject); + when(commandExecutor.executeCommand(keyValueLongDoubleCommandObject)).thenReturn(expectedRankWithScore); + + KeyValue result = jedis.zrankWithScore(key, member); + + assertThat(result, equalTo(expectedRankWithScore)); + + verify(commandExecutor).executeCommand(keyValueLongDoubleCommandObject); + verify(commandObjects).zrankWithScore(key, member); + } + + @Test + public void testZrem() { + String key = "zsetKey"; + String[] members = { "member1", "member2" }; + long expectedRemoved = 2L; // Assuming both members were successfully removed + + when(commandObjects.zrem(key, members)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedRemoved); + + long result = jedis.zrem(key, members); + + assertThat(result, equalTo(expectedRemoved)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).zrem(key, members); + } + + @Test + public void testZremBinary() { + byte[] key = "zsetKey".getBytes(); + byte[][] members = { "member1".getBytes(), "member2".getBytes() }; + long expectedRemoved = 2L; // Assuming both members were successfully removed + + when(commandObjects.zrem(key, members)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedRemoved); + + long result = jedis.zrem(key, members); + + assertThat(result, equalTo(expectedRemoved)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).zrem(key, members); + } + + @Test + public void testZremrangeByLex() { + String key = "zsetKey"; + String min = "[a"; + String max = "[b"; + long expectedRemovals = 2L; // Assuming 2 elements were removed + + when(commandObjects.zremrangeByLex(key, min, max)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedRemovals); + + long result = jedis.zremrangeByLex(key, min, max); + + assertThat(result, equalTo(expectedRemovals)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).zremrangeByLex(key, min, max); + } + + @Test + public void testZremrangeByLexBinary() { + byte[] key = "zsetKey".getBytes(); + byte[] min = "[a".getBytes(); + byte[] max = "[b".getBytes(); + long expectedRemovals = 2L; // Assuming 2 elements were removed + + when(commandObjects.zremrangeByLex(key, min, max)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedRemovals); + + long result = jedis.zremrangeByLex(key, min, max); + + assertThat(result, equalTo(expectedRemovals)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).zremrangeByLex(key, min, max); + } + + @Test + public void testZremrangeByRank() { + String key = "zsetKey"; + long start = 0; + long stop = 2; + long expectedRemovals = 3L; // Assuming 3 elements were removed + + when(commandObjects.zremrangeByRank(key, start, stop)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedRemovals); + + long result = jedis.zremrangeByRank(key, start, stop); + + assertThat(result, equalTo(expectedRemovals)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).zremrangeByRank(key, start, stop); + } + + @Test + public void testZremrangeByRankBinary() { + byte[] key = "zsetKey".getBytes(); + long start = 0; + long stop = 2; + long expectedRemovals = 3L; // Assuming 3 elements were removed + + when(commandObjects.zremrangeByRank(key, start, stop)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedRemovals); + + long result = jedis.zremrangeByRank(key, start, stop); + + assertThat(result, equalTo(expectedRemovals)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).zremrangeByRank(key, start, stop); + } + + @Test + public void testZremrangeByScore() { + String key = "zsetKey"; + String min = "1"; + String max = "3"; + long expectedRemovals = 2L; // Assuming 2 elements were removed + + when(commandObjects.zremrangeByScore(key, min, max)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedRemovals); + + long result = jedis.zremrangeByScore(key, min, max); + + assertThat(result, equalTo(expectedRemovals)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).zremrangeByScore(key, min, max); + } + + @Test + public void testZremrangeByScoreBinary() { + byte[] key = "zsetKey".getBytes(); + byte[] min = "1".getBytes(); + byte[] max = "3".getBytes(); + long expectedRemovals = 2L; // Assuming 2 elements were removed + + when(commandObjects.zremrangeByScore(key, min, max)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedRemovals); + + long result = jedis.zremrangeByScore(key, min, max); + + assertThat(result, equalTo(expectedRemovals)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).zremrangeByScore(key, min, max); + } + + @Test + public void testZremrangeByScoreDouble() { + String key = "zsetKey"; + double min = 1.0; + double max = 3.0; + long expectedRemovals = 2L; // Assuming 2 elements were removed + + when(commandObjects.zremrangeByScore(key, min, max)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedRemovals); + + long result = jedis.zremrangeByScore(key, min, max); + + assertThat(result, equalTo(expectedRemovals)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).zremrangeByScore(key, min, max); + } + + @Test + public void testZremrangeByScoreDoubleBinary() { + byte[] key = "zsetKey".getBytes(); + double min = 1.0; + double max = 3.0; + long expectedRemovals = 2L; // Assuming 2 elements were removed + + when(commandObjects.zremrangeByScore(key, min, max)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedRemovals); + + long result = jedis.zremrangeByScore(key, min, max); + + assertThat(result, equalTo(expectedRemovals)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).zremrangeByScore(key, min, max); + } + + @Test + public void testZrevrange() { + String key = "zsetKey"; + long start = 0; + long stop = -1; // This typically means all elements in the sorted set, in reverse order + List expectedMembers = Arrays.asList("member3", "member2", "member1"); + + when(commandObjects.zrevrange(key, start, stop)).thenReturn(listStringCommandObject); + when(commandExecutor.executeCommand(listStringCommandObject)).thenReturn(expectedMembers); + + List result = jedis.zrevrange(key, start, stop); + + assertThat(result, equalTo(expectedMembers)); + + verify(commandExecutor).executeCommand(listStringCommandObject); + verify(commandObjects).zrevrange(key, start, stop); + } + + @Test + public void testZrevrangeBinary() { + byte[] key = "zsetKey".getBytes(); + long start = 0; + long stop = -1; // This typically means all elements in the sorted set, in reverse order + List expectedMembers = Arrays.asList("member3".getBytes(), "member2".getBytes(), "member1".getBytes()); + + when(commandObjects.zrevrange(key, start, stop)).thenReturn(listBytesCommandObject); + when(commandExecutor.executeCommand(listBytesCommandObject)).thenReturn(expectedMembers); + + List result = jedis.zrevrange(key, start, stop); + + assertThat(result, equalTo(expectedMembers)); + + verify(commandExecutor).executeCommand(listBytesCommandObject); + verify(commandObjects).zrevrange(key, start, stop); + } + + @Test + public void testZrevrangeWithScores() { + String key = "zsetKey"; + long start = 0; + long stop = -1; // This typically means all elements in the sorted set with their scores, in reverse order + List expectedMembersWithScores = Arrays.asList( + new Tuple("member3", 3.0), + new Tuple("member2", 2.0), + new Tuple("member1", 1.0) + ); + + when(commandObjects.zrevrangeWithScores(key, start, stop)).thenReturn(listTupleCommandObject); + when(commandExecutor.executeCommand(listTupleCommandObject)).thenReturn(expectedMembersWithScores); + + List result = jedis.zrevrangeWithScores(key, start, stop); + + assertThat(result, equalTo(expectedMembersWithScores)); + + verify(commandExecutor).executeCommand(listTupleCommandObject); + verify(commandObjects).zrevrangeWithScores(key, start, stop); + } + + @Test + public void testZrevrangeWithScoresBinary() { + byte[] key = "zsetKey".getBytes(); + long start = 0; + long stop = -1; // This typically means all elements in the sorted set with their scores, in reverse order + List expectedMembersWithScores = Arrays.asList( + new Tuple("member3".getBytes(), 3.0), + new Tuple("member2".getBytes(), 2.0), + new Tuple("member1".getBytes(), 1.0) + ); + when(commandObjects.zrevrangeWithScores(key, start, stop)).thenReturn(listTupleCommandObject); + when(commandExecutor.executeCommand(listTupleCommandObject)).thenReturn(expectedMembersWithScores); + + List result = jedis.zrevrangeWithScores(key, start, stop); + + assertThat(result, equalTo(expectedMembersWithScores)); + + verify(commandExecutor).executeCommand(listTupleCommandObject); + verify(commandObjects).zrevrangeWithScores(key, start, stop); + } + + @Test + public void testZrevrangeByLex() { + String key = "zsetKey"; + String max = "[z"; + String min = "[a"; + List expectedMembers = Arrays.asList("omega", "mu", "alpha"); + + when(commandObjects.zrevrangeByLex(key, max, min)).thenReturn(listStringCommandObject); + when(commandExecutor.executeCommand(listStringCommandObject)).thenReturn(expectedMembers); + + List result = jedis.zrevrangeByLex(key, max, min); + + assertThat(result, equalTo(expectedMembers)); + + verify(commandExecutor).executeCommand(listStringCommandObject); + verify(commandObjects).zrevrangeByLex(key, max, min); + } + + @Test + public void testZrevrangeByLexBinary() { + byte[] key = "zsetKey".getBytes(); + byte[] max = "[z".getBytes(); + byte[] min = "[a".getBytes(); + List expectedMembers = Arrays.asList("omega".getBytes(), "mu".getBytes(), "alpha".getBytes()); + + when(commandObjects.zrevrangeByLex(key, max, min)).thenReturn(listBytesCommandObject); + when(commandExecutor.executeCommand(listBytesCommandObject)).thenReturn(expectedMembers); + + List result = jedis.zrevrangeByLex(key, max, min); + + assertThat(result, equalTo(expectedMembers)); + + verify(commandExecutor).executeCommand(listBytesCommandObject); + verify(commandObjects).zrevrangeByLex(key, max, min); + } + + @Test + public void testZrevrangeByLexWithOffsetCount() { + String key = "zsetKey"; + String max = "[z"; + String min = "[a"; + int offset = 1; + int count = 2; + List expectedMembers = Arrays.asList("mu", "alpha"); + + when(commandObjects.zrevrangeByLex(key, max, min, offset, count)).thenReturn(listStringCommandObject); + when(commandExecutor.executeCommand(listStringCommandObject)).thenReturn(expectedMembers); + + List result = jedis.zrevrangeByLex(key, max, min, offset, count); + + assertThat(result, equalTo(expectedMembers)); + + verify(commandExecutor).executeCommand(listStringCommandObject); + verify(commandObjects).zrevrangeByLex(key, max, min, offset, count); + } + + @Test + public void testZrevrangeByLexWithOffsetCountBinary() { + byte[] key = "zsetKey".getBytes(); + byte[] max = "[z".getBytes(); + byte[] min = "[a".getBytes(); + int offset = 1; + int count = 2; + List expectedMembers = Arrays.asList("mu".getBytes(), "alpha".getBytes()); + + when(commandObjects.zrevrangeByLex(key, max, min, offset, count)).thenReturn(listBytesCommandObject); + when(commandExecutor.executeCommand(listBytesCommandObject)).thenReturn(expectedMembers); + + List result = jedis.zrevrangeByLex(key, max, min, offset, count); + + assertThat(result, equalTo(expectedMembers)); + + verify(commandExecutor).executeCommand(listBytesCommandObject); + verify(commandObjects).zrevrangeByLex(key, max, min, offset, count); + } + + @Test + public void testZrevrangeByScore() { + String key = "zsetKey"; + String max = "3"; + String min = "1"; + List expectedMembers = Arrays.asList("member2", "member1"); + + when(commandObjects.zrevrangeByScore(key, max, min)).thenReturn(listStringCommandObject); + when(commandExecutor.executeCommand(listStringCommandObject)).thenReturn(expectedMembers); + + List result = jedis.zrevrangeByScore(key, max, min); + + assertThat(result, equalTo(expectedMembers)); + + verify(commandExecutor).executeCommand(listStringCommandObject); + verify(commandObjects).zrevrangeByScore(key, max, min); + } + + @Test + public void testZrevrangeByScoreBinary() { + byte[] key = "zsetKey".getBytes(); + byte[] max = "3".getBytes(); + byte[] min = "1".getBytes(); + List expectedMembers = Arrays.asList("member2".getBytes(), "member1".getBytes()); + + when(commandObjects.zrevrangeByScore(key, max, min)).thenReturn(listBytesCommandObject); + when(commandExecutor.executeCommand(listBytesCommandObject)).thenReturn(expectedMembers); + + List result = jedis.zrevrangeByScore(key, max, min); + + assertThat(result, equalTo(expectedMembers)); + + verify(commandExecutor).executeCommand(listBytesCommandObject); + verify(commandObjects).zrevrangeByScore(key, max, min); + } + + @Test + public void testZrevrangeByScoreDouble() { + String key = "zsetKey"; + double max = 3.0; + double min = 1.0; + List expectedMembers = Arrays.asList("member2", "member1"); + + when(commandObjects.zrevrangeByScore(key, max, min)).thenReturn(listStringCommandObject); + when(commandExecutor.executeCommand(listStringCommandObject)).thenReturn(expectedMembers); + + List result = jedis.zrevrangeByScore(key, max, min); + + assertThat(result, equalTo(expectedMembers)); + + verify(commandExecutor).executeCommand(listStringCommandObject); + verify(commandObjects).zrevrangeByScore(key, max, min); + } + + @Test + public void testZrevrangeByScoreDoubleBinary() { + byte[] key = "zsetKey".getBytes(); + double max = 3.0; + double min = 1.0; + List expectedMembers = Arrays.asList("member2".getBytes(), "member1".getBytes()); + + when(commandObjects.zrevrangeByScore(key, max, min)).thenReturn(listBytesCommandObject); + when(commandExecutor.executeCommand(listBytesCommandObject)).thenReturn(expectedMembers); + + List result = jedis.zrevrangeByScore(key, max, min); + + assertThat(result, equalTo(expectedMembers)); + + verify(commandExecutor).executeCommand(listBytesCommandObject); + verify(commandObjects).zrevrangeByScore(key, max, min); + } + + @Test + public void testZrevrangeByScoreDoubleWithLimit() { + String key = "zsetKey"; + double max = 3.0; + double min = 1.0; + int offset = 1; + int count = 2; + List expectedMembers = Arrays.asList("member2", "member1"); + + when(commandObjects.zrevrangeByScore(key, max, min, offset, count)).thenReturn(listStringCommandObject); + when(commandExecutor.executeCommand(listStringCommandObject)).thenReturn(expectedMembers); + + List result = jedis.zrevrangeByScore(key, max, min, offset, count); + + assertThat(result, equalTo(expectedMembers)); + + verify(commandExecutor).executeCommand(listStringCommandObject); + verify(commandObjects).zrevrangeByScore(key, max, min, offset, count); + } + + @Test + public void testZrevrangeByScoreDoubleWithLimitBinary() { + byte[] key = "zsetKey".getBytes(); + double max = 3.0; + double min = 1.0; + int offset = 1; + int count = 2; + List expectedMembers = Arrays.asList("member2".getBytes(), "member1".getBytes()); + + when(commandObjects.zrevrangeByScore(key, max, min, offset, count)).thenReturn(listBytesCommandObject); + when(commandExecutor.executeCommand(listBytesCommandObject)).thenReturn(expectedMembers); + + List result = jedis.zrevrangeByScore(key, max, min, offset, count); + + assertThat(result, equalTo(expectedMembers)); + + verify(commandExecutor).executeCommand(listBytesCommandObject); + verify(commandObjects).zrevrangeByScore(key, max, min, offset, count); + } + + @Test + public void testZrevrangeByScoreWithScoresDouble() { + String key = "zsetKey"; + double max = 3.0; + double min = 1.0; + List expectedMembersWithScores = Arrays.asList( + new Tuple("member2", 2.0), + new Tuple("member1", 1.0) + ); + + when(commandObjects.zrevrangeByScoreWithScores(key, max, min)).thenReturn(listTupleCommandObject); + when(commandExecutor.executeCommand(listTupleCommandObject)).thenReturn(expectedMembersWithScores); + + List result = jedis.zrevrangeByScoreWithScores(key, max, min); + + assertThat(result, equalTo(expectedMembersWithScores)); + + verify(commandExecutor).executeCommand(listTupleCommandObject); + verify(commandObjects).zrevrangeByScoreWithScores(key, max, min); + } + + @Test + public void testZrevrangeByScoreWithScoresDoubleBinary() { + byte[] key = "zsetKey".getBytes(); + double max = 3.0; + double min = 1.0; + List expectedMembersWithScores = Arrays.asList( + new Tuple("member2".getBytes(), 2.0), + new Tuple("member1".getBytes(), 1.0) + ); + + when(commandObjects.zrevrangeByScoreWithScores(key, max, min)).thenReturn(listTupleCommandObject); + when(commandExecutor.executeCommand(listTupleCommandObject)).thenReturn(expectedMembersWithScores); + + List result = jedis.zrevrangeByScoreWithScores(key, max, min); + + assertThat(result, equalTo(expectedMembersWithScores)); + + verify(commandExecutor).executeCommand(listTupleCommandObject); + verify(commandObjects).zrevrangeByScoreWithScores(key, max, min); + } + + @Test + public void testZrevrangeByScoreWithLimit() { + String key = "zsetKey"; + String max = "3"; + String min = "1"; + int offset = 1; + int count = 2; + List expectedMembers = Arrays.asList("member2", "member1"); + + when(commandObjects.zrevrangeByScore(key, max, min, offset, count)).thenReturn(listStringCommandObject); + when(commandExecutor.executeCommand(listStringCommandObject)).thenReturn(expectedMembers); + + List result = jedis.zrevrangeByScore(key, max, min, offset, count); + + assertThat(result, equalTo(expectedMembers)); + + verify(commandExecutor).executeCommand(listStringCommandObject); + verify(commandObjects).zrevrangeByScore(key, max, min, offset, count); + } + + @Test + public void testZrevrangeByScoreWithLimitBinary() { + byte[] key = "zsetKey".getBytes(); + byte[] max = "3".getBytes(); + byte[] min = "1".getBytes(); + int offset = 1; + int count = 2; + List expectedMembers = Arrays.asList("member2".getBytes(), "member1".getBytes()); + + when(commandObjects.zrevrangeByScore(key, max, min, offset, count)).thenReturn(listBytesCommandObject); + when(commandExecutor.executeCommand(listBytesCommandObject)).thenReturn(expectedMembers); + + List result = jedis.zrevrangeByScore(key, max, min, offset, count); + + assertThat(result, equalTo(expectedMembers)); + + verify(commandExecutor).executeCommand(listBytesCommandObject); + verify(commandObjects).zrevrangeByScore(key, max, min, offset, count); + } + + @Test + public void testZrevrangeByScoreWithScores() { + String key = "zsetKey"; + String max = "3"; + String min = "1"; + List expectedMembersWithScores = Arrays.asList( + new Tuple("member2", 2.0), + new Tuple("member1", 1.0) + ); + + when(commandObjects.zrevrangeByScoreWithScores(key, max, min)).thenReturn(listTupleCommandObject); + when(commandExecutor.executeCommand(listTupleCommandObject)).thenReturn(expectedMembersWithScores); + + List result = jedis.zrevrangeByScoreWithScores(key, max, min); + + assertThat(result, equalTo(expectedMembersWithScores)); + + verify(commandExecutor).executeCommand(listTupleCommandObject); + verify(commandObjects).zrevrangeByScoreWithScores(key, max, min); + } + + @Test + public void testZrevrangeByScoreWithScoresBinary() { + byte[] key = "zsetKey".getBytes(); + byte[] max = "3".getBytes(); + byte[] min = "1".getBytes(); + List expectedMembersWithScores = Arrays.asList( + new Tuple("member2".getBytes(), 2.0), + new Tuple("member1".getBytes(), 1.0) + ); + + when(commandObjects.zrevrangeByScoreWithScores(key, max, min)).thenReturn(listTupleCommandObject); + when(commandExecutor.executeCommand(listTupleCommandObject)).thenReturn(expectedMembersWithScores); + + List result = jedis.zrevrangeByScoreWithScores(key, max, min); + + assertThat(result, equalTo(expectedMembersWithScores)); + + verify(commandExecutor).executeCommand(listTupleCommandObject); + verify(commandObjects).zrevrangeByScoreWithScores(key, max, min); + } + + @Test + public void testZrevrangeByScoreWithScoresWithLimit() { + String key = "zsetKey"; + String max = "3"; + String min = "1"; + int offset = 1; + int count = 2; + List expectedMembersWithScores = Arrays.asList( + new Tuple("member2", 2.0), + new Tuple("member1", 1.0) + ); + + when(commandObjects.zrevrangeByScoreWithScores(key, max, min, offset, count)).thenReturn(listTupleCommandObject); + when(commandExecutor.executeCommand(listTupleCommandObject)).thenReturn(expectedMembersWithScores); + + List result = jedis.zrevrangeByScoreWithScores(key, max, min, offset, count); + + assertThat(result, equalTo(expectedMembersWithScores)); + + verify(commandExecutor).executeCommand(listTupleCommandObject); + verify(commandObjects).zrevrangeByScoreWithScores(key, max, min, offset, count); + } + + @Test + public void testZrevrangeByScoreWithScoresWithLimitBinary() { + byte[] key = "zsetKey".getBytes(); + byte[] max = "3".getBytes(); + byte[] min = "1".getBytes(); + int offset = 1; + int count = 2; + List expectedMembersWithScores = Arrays.asList( + new Tuple("member2".getBytes(), 2.0), + new Tuple("member1".getBytes(), 1.0) + ); + + when(commandObjects.zrevrangeByScoreWithScores(key, max, min, offset, count)).thenReturn(listTupleCommandObject); + when(commandExecutor.executeCommand(listTupleCommandObject)).thenReturn(expectedMembersWithScores); + + List result = jedis.zrevrangeByScoreWithScores(key, max, min, offset, count); + + assertThat(result, equalTo(expectedMembersWithScores)); + + verify(commandExecutor).executeCommand(listTupleCommandObject); + verify(commandObjects).zrevrangeByScoreWithScores(key, max, min, offset, count); + } + + @Test + public void testZrevrangeByScoreWithScoresDoubleWithLimit() { + String key = "zsetKey"; + double max = 3.0; + double min = 1.0; + int offset = 1; + int count = 2; + List expectedMembersWithScores = Arrays.asList( + new Tuple("member2", 2.0), + new Tuple("member1", 1.0) + ); + + when(commandObjects.zrevrangeByScoreWithScores(key, max, min, offset, count)).thenReturn(listTupleCommandObject); + when(commandExecutor.executeCommand(listTupleCommandObject)).thenReturn(expectedMembersWithScores); + + List result = jedis.zrevrangeByScoreWithScores(key, max, min, offset, count); + + assertThat(result, equalTo(expectedMembersWithScores)); + + verify(commandExecutor).executeCommand(listTupleCommandObject); + verify(commandObjects).zrevrangeByScoreWithScores(key, max, min, offset, count); + } + + @Test + public void testZrevrangeByScoreWithScoresDoubleWithLimitBinary() { + byte[] key = "zsetKey".getBytes(); + double max = 3.0; + double min = 1.0; + int offset = 1; + int count = 2; + List expectedMembersWithScores = Arrays.asList( + new Tuple("member2".getBytes(), 2.0), + new Tuple("member1".getBytes(), 1.0) + ); + + when(commandObjects.zrevrangeByScoreWithScores(key, max, min, offset, count)).thenReturn(listTupleCommandObject); + when(commandExecutor.executeCommand(listTupleCommandObject)).thenReturn(expectedMembersWithScores); + + List result = jedis.zrevrangeByScoreWithScores(key, max, min, offset, count); + + assertThat(result, equalTo(expectedMembersWithScores)); + + verify(commandExecutor).executeCommand(listTupleCommandObject); + verify(commandObjects).zrevrangeByScoreWithScores(key, max, min, offset, count); + } + + @Test + public void testZrevrank() { + String key = "zsetKey"; + String member = "member1"; + Long expectedRevRank = 10L; // Assuming the member is the eleventh from the end in the sorted set + + when(commandObjects.zrevrank(key, member)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedRevRank); + + Long result = jedis.zrevrank(key, member); + + assertThat(result, equalTo(expectedRevRank)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).zrevrank(key, member); + } + + @Test + public void testZrevrankBinary() { + byte[] key = "zsetKey".getBytes(); + byte[] member = "member1".getBytes(); + Long expectedRevRank = 10L; // Assuming the member is the eleventh from the end in the sorted set + + when(commandObjects.zrevrank(key, member)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedRevRank); + + Long result = jedis.zrevrank(key, member); + + assertThat(result, equalTo(expectedRevRank)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).zrevrank(key, member); + } + + @Test + public void testZrevrankWithScore() { + String key = "zsetKey"; + String member = "member1"; + KeyValue expectedRevRankWithScore = new KeyValue<>(10L, 1.0); // Assuming the member is the eleventh from the end with a score of 1.0 + + when(commandObjects.zrevrankWithScore(key, member)).thenReturn(keyValueLongDoubleCommandObject); + when(commandExecutor.executeCommand(keyValueLongDoubleCommandObject)).thenReturn(expectedRevRankWithScore); + + KeyValue result = jedis.zrevrankWithScore(key, member); + + assertThat(result, equalTo(expectedRevRankWithScore)); + + verify(commandExecutor).executeCommand(keyValueLongDoubleCommandObject); + verify(commandObjects).zrevrankWithScore(key, member); + } + + @Test + public void testZrevrankWithScoreBinary() { + byte[] key = "zsetKey".getBytes(); + byte[] member = "member1".getBytes(); + KeyValue expectedRevRankWithScore = new KeyValue<>(10L, 1.0); // Assuming the member is the eleventh from the end with a score of 1.0 + + when(commandObjects.zrevrankWithScore(key, member)).thenReturn(keyValueLongDoubleCommandObject); + when(commandExecutor.executeCommand(keyValueLongDoubleCommandObject)).thenReturn(expectedRevRankWithScore); + + KeyValue result = jedis.zrevrankWithScore(key, member); + + assertThat(result, equalTo(expectedRevRankWithScore)); + + verify(commandExecutor).executeCommand(keyValueLongDoubleCommandObject); + verify(commandObjects).zrevrankWithScore(key, member); + } + + @Test + public void testZscan() { + String key = "zsetKey"; + String cursor = "0"; + ScanParams params = new ScanParams().match("*").count(10); + List expectedTuples = Arrays.asList( + new Tuple("member1", 1.0), + new Tuple("member2", 2.0) + ); + ScanResult expectedScanResult = new ScanResult<>(cursor, expectedTuples); + + when(commandObjects.zscan(key, cursor, params)).thenReturn(scanResultTupleCommandObject); + when(commandExecutor.executeCommand(scanResultTupleCommandObject)).thenReturn(expectedScanResult); + + ScanResult result = jedis.zscan(key, cursor, params); + + assertThat(result, equalTo(expectedScanResult)); + + verify(commandExecutor).executeCommand(scanResultTupleCommandObject); + verify(commandObjects).zscan(key, cursor, params); + } + + @Test + public void testZscanBinary() { + byte[] key = "zsetKey".getBytes(); + byte[] cursor = "0".getBytes(); + ScanParams params = new ScanParams().match("*").count(10); + List expectedTuples = Arrays.asList( + new Tuple("member1".getBytes(), 1.0), + new Tuple("member2".getBytes(), 2.0) + ); + ScanResult expectedScanResult = new ScanResult<>(cursor, expectedTuples); + + when(commandObjects.zscan(key, cursor, params)).thenReturn(scanResultTupleCommandObject); + when(commandExecutor.executeCommand(scanResultTupleCommandObject)).thenReturn(expectedScanResult); + + ScanResult result = jedis.zscan(key, cursor, params); + + assertThat(result, equalTo(expectedScanResult)); + + verify(commandExecutor).executeCommand(scanResultTupleCommandObject); + verify(commandObjects).zscan(key, cursor, params); + } + + @Test + public void testZscore() { + String key = "zsetKey"; + String member = "member1"; + Double expectedScore = 1.0; // Assuming the member has a score of 1.0 + + when(commandObjects.zscore(key, member)).thenReturn(doubleCommandObject); + when(commandExecutor.executeCommand(doubleCommandObject)).thenReturn(expectedScore); + + Double result = jedis.zscore(key, member); + + assertThat(result, equalTo(expectedScore)); + + verify(commandExecutor).executeCommand(doubleCommandObject); + verify(commandObjects).zscore(key, member); + } + + @Test + public void testZscoreBinary() { + byte[] key = "zsetKey".getBytes(); + byte[] member = "member1".getBytes(); + Double expectedScore = 1.0; // Assuming the member has a score of 1.0 + + when(commandObjects.zscore(key, member)).thenReturn(doubleCommandObject); + when(commandExecutor.executeCommand(doubleCommandObject)).thenReturn(expectedScore); + + Double result = jedis.zscore(key, member); + + assertThat(result, equalTo(expectedScore)); + + verify(commandExecutor).executeCommand(doubleCommandObject); + verify(commandObjects).zscore(key, member); + } + + @Test + public void testZunion() { + ZParams params = new ZParams().weights(1, 2).aggregate(ZParams.Aggregate.MIN); + String[] keys = { "zset1", "zset2" }; + List expectedUnion = Arrays.asList("member1", "member2"); + + when(commandObjects.zunion(params, keys)).thenReturn(listStringCommandObject); + when(commandExecutor.executeCommand(listStringCommandObject)).thenReturn(expectedUnion); + + List result = jedis.zunion(params, keys); + + assertThat(result, equalTo(expectedUnion)); + + verify(commandExecutor).executeCommand(listStringCommandObject); + verify(commandObjects).zunion(params, keys); + } + + @Test + public void testZunionBinary() { + ZParams params = new ZParams().weights(1, 2).aggregate(ZParams.Aggregate.MAX); + byte[][] keys = { "zset1".getBytes(), "zset2".getBytes() }; + List expectedUnion = Arrays.asList("member1".getBytes(), "member2".getBytes()); + + when(commandObjects.zunion(params, keys)).thenReturn(listBytesCommandObject); + when(commandExecutor.executeCommand(listBytesCommandObject)).thenReturn(expectedUnion); + + List result = jedis.zunion(params, keys); + + assertThat(result, equalTo(expectedUnion)); + + verify(commandExecutor).executeCommand(listBytesCommandObject); + verify(commandObjects).zunion(params, keys); + } + + @Test + public void testZunionWithScores() { + ZParams params = new ZParams().weights(1, 2).aggregate(ZParams.Aggregate.MAX); + String[] keys = { "zset1", "zset2" }; + List expectedUnionWithScores = Arrays.asList(new Tuple("member1", 1.0), new Tuple("member2", 2.0)); + + when(commandObjects.zunionWithScores(params, keys)).thenReturn(listTupleCommandObject); + when(commandExecutor.executeCommand(listTupleCommandObject)).thenReturn(expectedUnionWithScores); + + List result = jedis.zunionWithScores(params, keys); + + assertThat(result, equalTo(expectedUnionWithScores)); + + verify(commandExecutor).executeCommand(listTupleCommandObject); + verify(commandObjects).zunionWithScores(params, keys); + } + + @Test + public void testZunionWithScoresBinary() { + ZParams params = new ZParams().weights(1, 2).aggregate(ZParams.Aggregate.MAX); + byte[][] keys = { "zset1".getBytes(), "zset2".getBytes() }; + List expectedUnionWithScores = Arrays.asList(new Tuple("member1", 1.0), new Tuple("member2", 2.0)); + + when(commandObjects.zunionWithScores(params, keys)).thenReturn(listTupleCommandObject); + when(commandExecutor.executeCommand(listTupleCommandObject)).thenReturn(expectedUnionWithScores); + + List result = jedis.zunionWithScores(params, keys); + + assertThat(result, equalTo(expectedUnionWithScores)); + + verify(commandExecutor).executeCommand(listTupleCommandObject); + verify(commandObjects).zunionWithScores(params, keys); + } + + @Test + public void testZunionstore() { + String dstkey = "zsetUnion"; + String[] sets = { "zset1", "zset2" }; + long expectedStoredCount = 3L; + + when(commandObjects.zunionstore(dstkey, sets)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedStoredCount); + + long result = jedis.zunionstore(dstkey, sets); + + assertThat(result, equalTo(expectedStoredCount)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).zunionstore(dstkey, sets); + } + + @Test + public void testZunionstoreBinary() { + byte[] dstkey = "zsetUnion".getBytes(); + byte[][] sets = { "zset1".getBytes(), "zset2".getBytes() }; + long expectedStoredCount = 3L; + + when(commandObjects.zunionstore(dstkey, sets)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedStoredCount); + + long result = jedis.zunionstore(dstkey, sets); + + assertThat(result, equalTo(expectedStoredCount)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).zunionstore(dstkey, sets); + } + + @Test + public void testZunionstoreWithParams() { + String dstkey = "zsetUnion"; + ZParams params = new ZParams().weights(1, 2).aggregate(ZParams.Aggregate.MAX); + String[] sets = { "zset1", "zset2" }; + long expectedStoredCount = 3L; + + when(commandObjects.zunionstore(dstkey, params, sets)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedStoredCount); + + long result = jedis.zunionstore(dstkey, params, sets); + + assertThat(result, equalTo(expectedStoredCount)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).zunionstore(dstkey, params, sets); + } + + @Test + public void testZunionstoreWithParamsBinary() { + byte[] dstkey = "zsetUnion".getBytes(); + ZParams params = new ZParams().weights(1, 2).aggregate(ZParams.Aggregate.MAX); + byte[][] sets = { "zset1".getBytes(), "zset2".getBytes() }; + long expectedStoredCount = 3L; + + when(commandObjects.zunionstore(dstkey, params, sets)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedStoredCount); + + long result = jedis.zunionstore(dstkey, params, sets); + + assertThat(result, equalTo(expectedStoredCount)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).zunionstore(dstkey, params, sets); + } + +} diff --git a/src/test/java/redis/clients/jedis/mocked/unified/UnifiedJedisStreamCommandsTest.java b/src/test/java/redis/clients/jedis/mocked/unified/UnifiedJedisStreamCommandsTest.java new file mode 100644 index 00000000000..404476788fe --- /dev/null +++ b/src/test/java/redis/clients/jedis/mocked/unified/UnifiedJedisStreamCommandsTest.java @@ -0,0 +1,1233 @@ +package redis.clients.jedis.mocked.unified; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.sameInstance; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import java.util.AbstractMap; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.junit.Test; +import redis.clients.jedis.StreamEntryID; +import redis.clients.jedis.params.XAddParams; +import redis.clients.jedis.params.XAutoClaimParams; +import redis.clients.jedis.params.XClaimParams; +import redis.clients.jedis.params.XPendingParams; +import redis.clients.jedis.params.XReadGroupParams; +import redis.clients.jedis.params.XReadParams; +import redis.clients.jedis.params.XTrimParams; +import redis.clients.jedis.resps.StreamConsumerInfo; +import redis.clients.jedis.resps.StreamConsumersInfo; +import redis.clients.jedis.resps.StreamEntry; +import redis.clients.jedis.resps.StreamFullInfo; +import redis.clients.jedis.resps.StreamGroupInfo; +import redis.clients.jedis.resps.StreamInfo; +import redis.clients.jedis.resps.StreamPendingEntry; +import redis.clients.jedis.resps.StreamPendingSummary; + +public class UnifiedJedisStreamCommandsTest extends UnifiedJedisMockedTestBase { + + @Test + public void testXack() { + String key = "mystream"; + String group = "mygroup"; + StreamEntryID[] ids = { new StreamEntryID("0-0"), new StreamEntryID("0-1") }; + long expectedAcked = 2L; + + when(commandObjects.xack(key, group, ids)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedAcked); + + long result = jedis.xack(key, group, ids); + + assertThat(result, equalTo(expectedAcked)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).xack(key, group, ids); + } + + @Test + public void testXackBinary() { + byte[] key = "mystream".getBytes(); + byte[] group = "mygroup".getBytes(); + byte[][] ids = { "0-0".getBytes(), "0-1".getBytes() }; + long expectedAcked = 2L; + + when(commandObjects.xack(key, group, ids)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedAcked); + + long result = jedis.xack(key, group, ids); + + assertThat(result, equalTo(expectedAcked)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).xack(key, group, ids); + } + + @Test + public void testXadd() { + String key = "mystream"; + StreamEntryID id = new StreamEntryID("0-0"); + Map hash = new HashMap<>(); + hash.put("field1", "value1"); + hash.put("field2", "value2"); + StreamEntryID expectedEntryID = new StreamEntryID("0-1"); + + when(commandObjects.xadd(key, id, hash)).thenReturn(streamEntryIdCommandObject); + when(commandExecutor.executeCommand(streamEntryIdCommandObject)).thenReturn(expectedEntryID); + + StreamEntryID result = jedis.xadd(key, id, hash); + + assertThat(result, equalTo(expectedEntryID)); + + verify(commandExecutor).executeCommand(streamEntryIdCommandObject); + verify(commandObjects).xadd(key, id, hash); + } + + @Test + public void testXaddBinary() { + byte[] key = "mystream".getBytes(); + XAddParams params = new XAddParams().id("0-1"); + Map hash = new HashMap<>(); + hash.put("field1".getBytes(), "value1".getBytes()); + byte[] expectedEntryId = "0-1".getBytes(); + + when(commandObjects.xadd(key, params, hash)).thenReturn(bytesCommandObject); + when(commandExecutor.executeCommand(bytesCommandObject)).thenReturn(expectedEntryId); + + byte[] result = jedis.xadd(key, params, hash); + + assertThat(result, equalTo(expectedEntryId)); + + verify(commandExecutor).executeCommand(bytesCommandObject); + verify(commandObjects).xadd(key, params, hash); + } + + @Test + public void testXaddWithParams() { + String key = "mystream"; + XAddParams params = new XAddParams(); + Map hash = new HashMap<>(); + hash.put("field1", "value1"); + hash.put("field2", "value2"); + StreamEntryID expectedEntryID = new StreamEntryID("0-1"); + + when(commandObjects.xadd(key, params, hash)).thenReturn(streamEntryIdCommandObject); + when(commandExecutor.executeCommand(streamEntryIdCommandObject)).thenReturn(expectedEntryID); + + StreamEntryID result = jedis.xadd(key, params, hash); + + assertThat(result, equalTo(expectedEntryID)); + + verify(commandExecutor).executeCommand(streamEntryIdCommandObject); + verify(commandObjects).xadd(key, params, hash); + } + + @Test + public void testXautoclaim() { + String key = "mystream"; + String group = "mygroup"; + String consumerName = "myconsumer"; + long minIdleTime = 10000L; + StreamEntryID start = new StreamEntryID("0-0"); + XAutoClaimParams params = new XAutoClaimParams(); + StreamEntryID nextStart = new StreamEntryID("0-1"); + List claimedEntries = new ArrayList<>(); + AbstractMap.SimpleImmutableEntry> expectedResponse = new AbstractMap.SimpleImmutableEntry<>(nextStart, claimedEntries); + + when(commandObjects.xautoclaim(key, group, consumerName, minIdleTime, start, params)).thenReturn(entryStreamEntryIdListStreamEntryCommandObject); + when(commandExecutor.executeCommand(entryStreamEntryIdListStreamEntryCommandObject)).thenReturn(expectedResponse); + + Map.Entry> result = jedis.xautoclaim(key, group, consumerName, minIdleTime, start, params); + + assertThat(result, equalTo(expectedResponse)); + + verify(commandExecutor).executeCommand(entryStreamEntryIdListStreamEntryCommandObject); + verify(commandObjects).xautoclaim(key, group, consumerName, minIdleTime, start, params); + } + + @Test + public void testXautoclaimBinary() { + byte[] key = "mystream".getBytes(); + byte[] groupName = "mygroup".getBytes(); + byte[] consumerName = "myconsumer".getBytes(); + long minIdleTime = 10000L; + byte[] start = "0-0".getBytes(); + XAutoClaimParams params = new XAutoClaimParams(); + List expectedAutoClaimResult = new ArrayList<>(); + + when(commandObjects.xautoclaim(key, groupName, consumerName, minIdleTime, start, params)).thenReturn(listObjectCommandObject); + when(commandExecutor.executeCommand(listObjectCommandObject)).thenReturn(expectedAutoClaimResult); + + List result = jedis.xautoclaim(key, groupName, consumerName, minIdleTime, start, params); + + assertThat(result, equalTo(expectedAutoClaimResult)); + + verify(commandExecutor).executeCommand(listObjectCommandObject); + verify(commandObjects).xautoclaim(key, groupName, consumerName, minIdleTime, start, params); + } + + @Test + public void testXautoclaimJustId() { + String key = "mystream"; + String group = "mygroup"; + String consumerName = "myconsumer"; + long minIdleTime = 10000L; + StreamEntryID start = new StreamEntryID("0-0"); + XAutoClaimParams params = new XAutoClaimParams(); + StreamEntryID nextStart = new StreamEntryID("0-1"); + List claimedEntryIds = Arrays.asList(new StreamEntryID("0-0"), new StreamEntryID("0-1")); + AbstractMap.SimpleImmutableEntry> expectedResponse = new AbstractMap.SimpleImmutableEntry<>(nextStart, claimedEntryIds); + + when(commandObjects.xautoclaimJustId(key, group, consumerName, minIdleTime, start, params)).thenReturn(entryStreamEntryIdListStreamEntryIdCommandObject); + when(commandExecutor.executeCommand(entryStreamEntryIdListStreamEntryIdCommandObject)).thenReturn(expectedResponse); + + Map.Entry> result = jedis.xautoclaimJustId(key, group, consumerName, minIdleTime, start, params); + + assertThat(result, equalTo(expectedResponse)); + + verify(commandExecutor).executeCommand(entryStreamEntryIdListStreamEntryIdCommandObject); + verify(commandObjects).xautoclaimJustId(key, group, consumerName, minIdleTime, start, params); + } + + @Test + public void testXautoclaimJustIdBinary() { + byte[] key = "mystream".getBytes(); + byte[] groupName = "mygroup".getBytes(); + byte[] consumerName = "myconsumer".getBytes(); + long minIdleTime = 10000L; + byte[] start = "0-0".getBytes(); + XAutoClaimParams params = new XAutoClaimParams(); + List expectedAutoClaimResult = new ArrayList<>(); + + when(commandObjects.xautoclaimJustId(key, groupName, consumerName, minIdleTime, start, params)).thenReturn(listObjectCommandObject); + when(commandExecutor.executeCommand(listObjectCommandObject)).thenReturn(expectedAutoClaimResult); + + List result = jedis.xautoclaimJustId(key, groupName, consumerName, minIdleTime, start, params); + + assertThat(result, equalTo(expectedAutoClaimResult)); + + verify(commandExecutor).executeCommand(listObjectCommandObject); + verify(commandObjects).xautoclaimJustId(key, groupName, consumerName, minIdleTime, start, params); + } + + @Test + public void testXclaim() { + String key = "mystream"; + String group = "mygroup"; + String consumerName = "myconsumer"; + long minIdleTime = 10000L; + XClaimParams params = new XClaimParams(); + StreamEntryID[] ids = { new StreamEntryID("0-0"), new StreamEntryID("0-1") }; + List expectedEntries = new ArrayList<>(); + + when(commandObjects.xclaim(key, group, consumerName, minIdleTime, params, ids)).thenReturn(listStreamEntryCommandObject); + when(commandExecutor.executeCommand(listStreamEntryCommandObject)).thenReturn(expectedEntries); + + List result = jedis.xclaim(key, group, consumerName, minIdleTime, params, ids); + + assertThat(result, equalTo(expectedEntries)); + + verify(commandExecutor).executeCommand(listStreamEntryCommandObject); + verify(commandObjects).xclaim(key, group, consumerName, minIdleTime, params, ids); + } + + @Test + public void testXclaimBinary() { + byte[] key = "mystream".getBytes(); + byte[] group = "mygroup".getBytes(); + byte[] consumerName = "myconsumer".getBytes(); + long minIdleTime = 10000L; + XClaimParams params = new XClaimParams(); + byte[][] ids = { "0-0".getBytes(), "0-1".getBytes() }; + List expectedClaimedIds = Arrays.asList("0-0".getBytes(), "0-1".getBytes()); + + when(commandObjects.xclaim(key, group, consumerName, minIdleTime, params, ids)).thenReturn(listBytesCommandObject); + when(commandExecutor.executeCommand(listBytesCommandObject)).thenReturn(expectedClaimedIds); + + List result = jedis.xclaim(key, group, consumerName, minIdleTime, params, ids); + + assertThat(result, equalTo(expectedClaimedIds)); + + verify(commandExecutor).executeCommand(listBytesCommandObject); + verify(commandObjects).xclaim(key, group, consumerName, minIdleTime, params, ids); + } + + @Test + public void testXclaimJustId() { + String key = "mystream"; + String group = "mygroup"; + String consumerName = "myconsumer"; + long minIdleTime = 10000L; + XClaimParams params = new XClaimParams(); + StreamEntryID[] ids = { new StreamEntryID("0-0"), new StreamEntryID("0-1") }; + List expectedEntryIds = Arrays.asList(ids); + + when(commandObjects.xclaimJustId(key, group, consumerName, minIdleTime, params, ids)).thenReturn(listStreamEntryIdCommandObject); + when(commandExecutor.executeCommand(listStreamEntryIdCommandObject)).thenReturn(expectedEntryIds); + + List result = jedis.xclaimJustId(key, group, consumerName, minIdleTime, params, ids); + + assertThat(result, equalTo(expectedEntryIds)); + + verify(commandExecutor).executeCommand(listStreamEntryIdCommandObject); + verify(commandObjects).xclaimJustId(key, group, consumerName, minIdleTime, params, ids); + } + + @Test + public void testXclaimJustIdBinary() { + byte[] key = "mystream".getBytes(); + byte[] group = "mygroup".getBytes(); + byte[] consumerName = "myconsumer".getBytes(); + long minIdleTime = 10000L; + XClaimParams params = new XClaimParams(); + byte[][] ids = { "0-0".getBytes(), "0-1".getBytes() }; + List expectedClaimedIds = Arrays.asList("0-0".getBytes(), "0-1".getBytes()); + + when(commandObjects.xclaimJustId(key, group, consumerName, minIdleTime, params, ids)).thenReturn(listBytesCommandObject); + when(commandExecutor.executeCommand(listBytesCommandObject)).thenReturn(expectedClaimedIds); + + List result = jedis.xclaimJustId(key, group, consumerName, minIdleTime, params, ids); + + assertThat(result, equalTo(expectedClaimedIds)); + + verify(commandExecutor).executeCommand(listBytesCommandObject); + verify(commandObjects).xclaimJustId(key, group, consumerName, minIdleTime, params, ids); + } + + @Test + public void testXdel() { + String key = "mystream"; + StreamEntryID[] ids = { new StreamEntryID("0-0"), new StreamEntryID("0-1") }; + long expectedDeletedCount = 2L; // Assuming the entries were successfully deleted + + when(commandObjects.xdel(key, ids)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedDeletedCount); + + long result = jedis.xdel(key, ids); + + assertThat(result, equalTo(expectedDeletedCount)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).xdel(key, ids); + } + + @Test + public void testXdelBinary() { + byte[] key = "mystream".getBytes(); + byte[][] ids = { "0-0".getBytes(), "0-1".getBytes() }; + long expectedDeleted = 2L; + + when(commandObjects.xdel(key, ids)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedDeleted); + + long result = jedis.xdel(key, ids); + + assertThat(result, equalTo(expectedDeleted)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).xdel(key, ids); + } + + @Test + public void testXgroupCreate() { + String key = "mystream"; + String groupName = "mygroup"; + StreamEntryID id = new StreamEntryID("0-0"); + boolean makeStream = true; + String expectedResponse = "OK"; + + when(commandObjects.xgroupCreate(key, groupName, id, makeStream)).thenReturn(stringCommandObject); + when(commandExecutor.executeCommand(stringCommandObject)).thenReturn(expectedResponse); + + String result = jedis.xgroupCreate(key, groupName, id, makeStream); + + assertThat(result, equalTo(expectedResponse)); + + verify(commandExecutor).executeCommand(stringCommandObject); + verify(commandObjects).xgroupCreate(key, groupName, id, makeStream); + } + + @Test + public void testXgroupCreateBinary() { + byte[] key = "mystream".getBytes(); + byte[] groupName = "mygroup".getBytes(); + byte[] id = "0-0".getBytes(); + boolean makeStream = true; + String expectedResponse = "OK"; + + when(commandObjects.xgroupCreate(key, groupName, id, makeStream)).thenReturn(stringCommandObject); + when(commandExecutor.executeCommand(stringCommandObject)).thenReturn(expectedResponse); + + String result = jedis.xgroupCreate(key, groupName, id, makeStream); + + assertThat(result, equalTo(expectedResponse)); + + verify(commandExecutor).executeCommand(stringCommandObject); + verify(commandObjects).xgroupCreate(key, groupName, id, makeStream); + } + + @Test + public void testXgroupCreateConsumer() { + String key = "mystream"; + String groupName = "mygroup"; + String consumerName = "myconsumer"; + boolean expectedResponse = true; // Assuming the consumer was successfully created + + when(commandObjects.xgroupCreateConsumer(key, groupName, consumerName)).thenReturn(booleanCommandObject); + when(commandExecutor.executeCommand(booleanCommandObject)).thenReturn(expectedResponse); + + boolean result = jedis.xgroupCreateConsumer(key, groupName, consumerName); + + assertThat(result, equalTo(expectedResponse)); + + verify(commandExecutor).executeCommand(booleanCommandObject); + verify(commandObjects).xgroupCreateConsumer(key, groupName, consumerName); + } + + @Test + public void testXgroupCreateConsumerBinary() { + byte[] key = "mystream".getBytes(); + byte[] groupName = "mygroup".getBytes(); + byte[] consumerName = "myconsumer".getBytes(); + boolean expectedResponse = true; + + when(commandObjects.xgroupCreateConsumer(key, groupName, consumerName)).thenReturn(booleanCommandObject); + when(commandExecutor.executeCommand(booleanCommandObject)).thenReturn(expectedResponse); + + boolean result = jedis.xgroupCreateConsumer(key, groupName, consumerName); + + assertThat(result, equalTo(expectedResponse)); + + verify(commandExecutor).executeCommand(booleanCommandObject); + verify(commandObjects).xgroupCreateConsumer(key, groupName, consumerName); + } + + @Test + public void testXgroupDelConsumer() { + String key = "mystream"; + String groupName = "mygroup"; + String consumerName = "myconsumer"; + long expectedDeletedCount = 1L; // Assuming the consumer was successfully deleted + + when(commandObjects.xgroupDelConsumer(key, groupName, consumerName)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedDeletedCount); + + long result = jedis.xgroupDelConsumer(key, groupName, consumerName); + + assertThat(result, equalTo(expectedDeletedCount)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).xgroupDelConsumer(key, groupName, consumerName); + } + + @Test + public void testXgroupDelConsumerBinary() { + byte[] key = "mystream".getBytes(); + byte[] groupName = "mygroup".getBytes(); + byte[] consumerName = "myconsumer".getBytes(); + long expectedDeleted = 1L; + + when(commandObjects.xgroupDelConsumer(key, groupName, consumerName)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedDeleted); + + long result = jedis.xgroupDelConsumer(key, groupName, consumerName); + + assertThat(result, equalTo(expectedDeleted)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).xgroupDelConsumer(key, groupName, consumerName); + } + + @Test + public void testXgroupDestroy() { + String key = "mystream"; + String groupName = "mygroup"; + long expectedResponse = 1L; // Assuming the group was successfully destroyed + + when(commandObjects.xgroupDestroy(key, groupName)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedResponse); + + long result = jedis.xgroupDestroy(key, groupName); + + assertThat(result, equalTo(expectedResponse)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).xgroupDestroy(key, groupName); + } + + @Test + public void testXgroupDestroyBinary() { + byte[] key = "mystream".getBytes(); + byte[] groupName = "mygroup".getBytes(); + long expectedDestroyed = 1L; + + when(commandObjects.xgroupDestroy(key, groupName)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedDestroyed); + + long result = jedis.xgroupDestroy(key, groupName); + + assertThat(result, equalTo(expectedDestroyed)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).xgroupDestroy(key, groupName); + } + + @Test + public void testXgroupSetID() { + String key = "mystream"; + String groupName = "mygroup"; + StreamEntryID id = new StreamEntryID("0-0"); + String expectedResponse = "OK"; + + when(commandObjects.xgroupSetID(key, groupName, id)).thenReturn(stringCommandObject); + when(commandExecutor.executeCommand(stringCommandObject)).thenReturn(expectedResponse); + + String result = jedis.xgroupSetID(key, groupName, id); + + assertThat(result, equalTo(expectedResponse)); + + verify(commandExecutor).executeCommand(stringCommandObject); + verify(commandObjects).xgroupSetID(key, groupName, id); + } + + @Test + public void testXgroupSetIDBinary() { + byte[] key = "mystream".getBytes(); + byte[] groupName = "mygroup".getBytes(); + byte[] id = "0-1".getBytes(); + String expectedResponse = "OK"; + + when(commandObjects.xgroupSetID(key, groupName, id)).thenReturn(stringCommandObject); + when(commandExecutor.executeCommand(stringCommandObject)).thenReturn(expectedResponse); + + String result = jedis.xgroupSetID(key, groupName, id); + + assertThat(result, equalTo(expectedResponse)); + + verify(commandExecutor).executeCommand(stringCommandObject); + verify(commandObjects).xgroupSetID(key, groupName, id); + } + + @Test + public void testXinfoConsumers() { + String key = "mystream"; + String group = "mygroup"; + List expectedConsumers = Collections.singletonList(mock(StreamConsumersInfo.class)); + + when(commandObjects.xinfoConsumers(key, group)).thenReturn(listStreamConsumersInfoCommandObject); + when(commandExecutor.executeCommand(listStreamConsumersInfoCommandObject)).thenReturn(expectedConsumers); + + List result = jedis.xinfoConsumers(key, group); + + assertThat(result, equalTo(expectedConsumers)); + + verify(commandExecutor).executeCommand(listStreamConsumersInfoCommandObject); + verify(commandObjects).xinfoConsumers(key, group); + } + + @Test + public void testXinfoConsumersBinary() { + byte[] key = "mystream".getBytes(); + byte[] group = "mygroup".getBytes(); + List expectedConsumersInfo = new ArrayList<>(); + + when(commandObjects.xinfoConsumers(key, group)).thenReturn(listObjectCommandObject); + when(commandExecutor.executeCommand(listObjectCommandObject)).thenReturn(expectedConsumersInfo); + + List result = jedis.xinfoConsumers(key, group); + + assertThat(result, equalTo(expectedConsumersInfo)); + + verify(commandExecutor).executeCommand(listObjectCommandObject); + verify(commandObjects).xinfoConsumers(key, group); + } + + @Test + public void testXinfoConsumers2() { + String key = "mystream"; + String group = "mygroup"; + List expectedConsumerInfos = Collections.singletonList(mock(StreamConsumerInfo.class)); + + when(commandObjects.xinfoConsumers2(key, group)).thenReturn(listStreamConsumerInfoCommandObject); + when(commandExecutor.executeCommand(listStreamConsumerInfoCommandObject)).thenReturn(expectedConsumerInfos); + + List result = jedis.xinfoConsumers2(key, group); + + assertThat(result, equalTo(expectedConsumerInfos)); + + verify(commandExecutor).executeCommand(listStreamConsumerInfoCommandObject); + verify(commandObjects).xinfoConsumers2(key, group); + } + + @Test + public void testXinfoGroups() { + String key = "mystream"; + List expectedGroups = Collections.singletonList(mock(StreamGroupInfo.class)); + + when(commandObjects.xinfoGroups(key)).thenReturn(listStreamGroupInfoCommandObject); + when(commandExecutor.executeCommand(listStreamGroupInfoCommandObject)).thenReturn(expectedGroups); + + List result = jedis.xinfoGroups(key); + + assertThat(result, equalTo(expectedGroups)); + + verify(commandExecutor).executeCommand(listStreamGroupInfoCommandObject); + verify(commandObjects).xinfoGroups(key); + } + + @Test + public void testXinfoGroupsBinary() { + byte[] key = "mystream".getBytes(); + List expectedGroupsInfo = new ArrayList<>(); + + when(commandObjects.xinfoGroups(key)).thenReturn(listObjectCommandObject); + when(commandExecutor.executeCommand(listObjectCommandObject)).thenReturn(expectedGroupsInfo); + + List result = jedis.xinfoGroups(key); + + assertThat(result, equalTo(expectedGroupsInfo)); + + verify(commandExecutor).executeCommand(listObjectCommandObject); + verify(commandObjects).xinfoGroups(key); + } + + @Test + public void testXinfoStream() { + String key = "mystream"; + StreamInfo expectedStreamInfo = mock(StreamInfo.class); + + when(commandObjects.xinfoStream(key)).thenReturn(streamInfoCommandObject); + when(commandExecutor.executeCommand(streamInfoCommandObject)).thenReturn(expectedStreamInfo); + + StreamInfo result = jedis.xinfoStream(key); + + assertThat(result, sameInstance(expectedStreamInfo)); + + verify(commandExecutor).executeCommand(streamInfoCommandObject); + verify(commandObjects).xinfoStream(key); + } + + @Test + public void testXinfoStreamBinary() { + byte[] key = "mystream".getBytes(); + Object expectedStreamInfo = new Object(); + + when(commandObjects.xinfoStream(key)).thenReturn(objectCommandObject); + when(commandExecutor.executeCommand(objectCommandObject)).thenReturn(expectedStreamInfo); + + Object result = jedis.xinfoStream(key); + + assertThat(result, sameInstance(expectedStreamInfo)); + + verify(commandExecutor).executeCommand(objectCommandObject); + verify(commandObjects).xinfoStream(key); + } + + @Test + public void testXinfoStreamFull() { + String key = "mystream"; + StreamFullInfo expectedStreamFullInfo = mock(StreamFullInfo.class); + + when(commandObjects.xinfoStreamFull(key)).thenReturn(streamFullInfoCommandObject); + when(commandExecutor.executeCommand(streamFullInfoCommandObject)).thenReturn(expectedStreamFullInfo); + + StreamFullInfo result = jedis.xinfoStreamFull(key); + + assertThat(result, sameInstance(expectedStreamFullInfo)); + + verify(commandExecutor).executeCommand(streamFullInfoCommandObject); + verify(commandObjects).xinfoStreamFull(key); + } + + @Test + public void testXinfoStreamFullBinary() { + byte[] key = "mystream".getBytes(); + Object expectedStreamInfoFull = new Object(); + + when(commandObjects.xinfoStreamFull(key)).thenReturn(objectCommandObject); + when(commandExecutor.executeCommand(objectCommandObject)).thenReturn(expectedStreamInfoFull); + + Object result = jedis.xinfoStreamFull(key); + + assertThat(result, sameInstance(expectedStreamInfoFull)); + + verify(commandExecutor).executeCommand(objectCommandObject); + verify(commandObjects).xinfoStreamFull(key); + } + + @Test + public void testXinfoStreamFullWithCount() { + String key = "mystream"; + int count = 10; + StreamFullInfo expectedStreamFullInfo = mock(StreamFullInfo.class); + + when(commandObjects.xinfoStreamFull(key, count)).thenReturn(streamFullInfoCommandObject); + when(commandExecutor.executeCommand(streamFullInfoCommandObject)).thenReturn(expectedStreamFullInfo); + + StreamFullInfo result = jedis.xinfoStreamFull(key, count); + + assertThat(result, sameInstance(expectedStreamFullInfo)); + + verify(commandExecutor).executeCommand(streamFullInfoCommandObject); + verify(commandObjects).xinfoStreamFull(key, count); + } + + @Test + public void testXinfoStreamFullWithCountBinary() { + byte[] key = "mystream".getBytes(); + int count = 10; + Object expectedStreamInfoFull = new Object(); + + when(commandObjects.xinfoStreamFull(key, count)).thenReturn(objectCommandObject); + when(commandExecutor.executeCommand(objectCommandObject)).thenReturn(expectedStreamInfoFull); + + Object result = jedis.xinfoStreamFull(key, count); + + assertThat(result, sameInstance(expectedStreamInfoFull)); + + verify(commandExecutor).executeCommand(objectCommandObject); + verify(commandObjects).xinfoStreamFull(key, count); + } + + @Test + public void testXlen() { + String key = "mystream"; + long expectedLength = 10L; + + when(commandObjects.xlen(key)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedLength); + + long result = jedis.xlen(key); + + assertThat(result, equalTo(expectedLength)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).xlen(key); + } + + @Test + public void testXlenBinary() { + byte[] key = "mystream".getBytes(); + long expectedLength = 100L; + + when(commandObjects.xlen(key)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedLength); + + long result = jedis.xlen(key); + + assertThat(result, equalTo(expectedLength)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).xlen(key); + } + + @Test + public void testXpending() { + String key = "mystream"; + String groupName = "mygroup"; + StreamPendingSummary expectedSummary = new StreamPendingSummary(10L, + new StreamEntryID("0-0"), new StreamEntryID("0-1"), Collections.emptyMap()); + + when(commandObjects.xpending(key, groupName)).thenReturn(streamPendingSummaryCommandObject); + when(commandExecutor.executeCommand(streamPendingSummaryCommandObject)).thenReturn(expectedSummary); + + StreamPendingSummary result = jedis.xpending(key, groupName); + + assertThat(result, equalTo(expectedSummary)); + + verify(commandExecutor).executeCommand(streamPendingSummaryCommandObject); + verify(commandObjects).xpending(key, groupName); + } + + @Test + public void testXpendingBinary() { + byte[] key = "mystream".getBytes(); + byte[] groupName = "mygroup".getBytes(); + Object expectedPendingInfo = new Object(); + + when(commandObjects.xpending(key, groupName)).thenReturn(objectCommandObject); + when(commandExecutor.executeCommand(objectCommandObject)).thenReturn(expectedPendingInfo); + + Object result = jedis.xpending(key, groupName); + + assertThat(result, sameInstance(expectedPendingInfo)); + + verify(commandExecutor).executeCommand(objectCommandObject); + verify(commandObjects).xpending(key, groupName); + } + + @Test + public void testXpendingWithParams() { + String key = "mystream"; + String groupName = "mygroup"; + XPendingParams params = new XPendingParams(); + List expectedPendingEntries = new ArrayList<>(); + + when(commandObjects.xpending(key, groupName, params)).thenReturn(listStreamPendingEntryCommandObject); + when(commandExecutor.executeCommand(listStreamPendingEntryCommandObject)).thenReturn(expectedPendingEntries); + + List result = jedis.xpending(key, groupName, params); + + assertThat(result, equalTo(expectedPendingEntries)); + + verify(commandExecutor).executeCommand(listStreamPendingEntryCommandObject); + verify(commandObjects).xpending(key, groupName, params); + } + + @Test + public void testXpendingWithParamsBinary() { + byte[] key = "mystream".getBytes(); + byte[] groupName = "mygroup".getBytes(); + XPendingParams params = new XPendingParams().count(10); + List expectedPendingList = new ArrayList<>(); + + when(commandObjects.xpending(key, groupName, params)).thenReturn(listObjectCommandObject); + when(commandExecutor.executeCommand(listObjectCommandObject)).thenReturn(expectedPendingList); + + List result = jedis.xpending(key, groupName, params); + + assertThat(result, equalTo(expectedPendingList)); + + verify(commandExecutor).executeCommand(listObjectCommandObject); + verify(commandObjects).xpending(key, groupName, params); + } + + @Test + public void testXrange() { + String key = "mystream"; + String start = "-"; + String end = "+"; + Map hash = new HashMap<>(); + hash.put("field1", "value1"); + hash.put("field2", "value2"); + List expectedEntries = Collections.singletonList(new StreamEntry(new StreamEntryID("0-1"), hash)); + + when(commandObjects.xrange(key, start, end)).thenReturn(listStreamEntryCommandObject); + when(commandExecutor.executeCommand(listStreamEntryCommandObject)).thenReturn(expectedEntries); + + List result = jedis.xrange(key, start, end); + + assertThat(result, equalTo(expectedEntries)); + + verify(commandExecutor).executeCommand(listStreamEntryCommandObject); + verify(commandObjects).xrange(key, start, end); + } + + @Test + public void testXrangeBinary() { + byte[] key = "mystream".getBytes(); + byte[] start = "0-0".getBytes(); + byte[] end = "+".getBytes(); + List expectedRange = Arrays.asList( + new StreamEntry(new StreamEntryID("0-0"), Collections.singletonMap("field1", "value1")), + new StreamEntry(new StreamEntryID("0-1"), Collections.singletonMap("field2", "value2"))); + + when(commandObjects.xrange(key, start, end)).thenReturn(listObjectCommandObject); + when(commandExecutor.executeCommand(listObjectCommandObject)).thenReturn(expectedRange); + + List result = jedis.xrange(key, start, end); + + assertThat(result, equalTo(expectedRange)); + + verify(commandExecutor).executeCommand(listObjectCommandObject); + verify(commandObjects).xrange(key, start, end); + } + + @Test + public void testXrangeWithCount() { + String key = "mystream"; + String start = "-"; + String end = "+"; + int count = 10; + Map hash = new HashMap<>(); + hash.put("field1", "value1"); + hash.put("field2", "value2"); + List expectedEntries = Collections.singletonList(new StreamEntry(new StreamEntryID("0-1"), hash)); + + when(commandObjects.xrange(key, start, end, count)).thenReturn(listStreamEntryCommandObject); + when(commandExecutor.executeCommand(listStreamEntryCommandObject)).thenReturn(expectedEntries); + + List result = jedis.xrange(key, start, end, count); + + assertThat(result, equalTo(expectedEntries)); + + verify(commandExecutor).executeCommand(listStreamEntryCommandObject); + verify(commandObjects).xrange(key, start, end, count); + } + + @Test + public void testXrangeWithCountBinary() { + byte[] key = "mystream".getBytes(); + byte[] start = "0-0".getBytes(); + byte[] end = "+".getBytes(); + int count = 2; + List expectedRange = Arrays.asList( + new StreamEntry(new StreamEntryID("0-0"), Collections.singletonMap("field1", "value1")), + new StreamEntry(new StreamEntryID("0-1"), Collections.singletonMap("field2", "value2"))); + + when(commandObjects.xrange(key, start, end, count)).thenReturn(listObjectCommandObject); + when(commandExecutor.executeCommand(listObjectCommandObject)).thenReturn(expectedRange); + + List result = jedis.xrange(key, start, end, count); + + assertThat(result, equalTo(expectedRange)); + + verify(commandExecutor).executeCommand(listObjectCommandObject); + verify(commandObjects).xrange(key, start, end, count); + } + + @Test + public void testXrangeIds() { + String key = "mystream"; + StreamEntryID start = new StreamEntryID("0-0"); + StreamEntryID end = new StreamEntryID("0-1"); + List expectedEntries = new ArrayList<>(); + Map hash = new HashMap<>(); + hash.put("field1", "value1"); + hash.put("field2", "value2"); + expectedEntries.add(new StreamEntry(new StreamEntryID("0-1"), hash)); + + when(commandObjects.xrange(key, start, end)).thenReturn(listStreamEntryCommandObject); + when(commandExecutor.executeCommand(listStreamEntryCommandObject)).thenReturn(expectedEntries); + + List result = jedis.xrange(key, start, end); + + assertThat(result, equalTo(expectedEntries)); + + verify(commandExecutor).executeCommand(listStreamEntryCommandObject); + verify(commandObjects).xrange(key, start, end); + } + + @Test + public void testXrangeIdsWithCount() { + String key = "mystream"; + StreamEntryID start = new StreamEntryID("0-0"); + StreamEntryID end = new StreamEntryID("0-1"); + int count = 10; + Map hash = new HashMap<>(); + hash.put("field1", "value1"); + hash.put("field2", "value2"); + List expectedEntries = Collections.singletonList(new StreamEntry(new StreamEntryID("0-1"), hash)); + + when(commandObjects.xrange(key, start, end, count)).thenReturn(listStreamEntryCommandObject); + when(commandExecutor.executeCommand(listStreamEntryCommandObject)).thenReturn(expectedEntries); + + List result = jedis.xrange(key, start, end, count); + + assertThat(result, equalTo(expectedEntries)); + + verify(commandExecutor).executeCommand(listStreamEntryCommandObject); + verify(commandObjects).xrange(key, start, end, count); + } + + @Test + public void testXread() { + XReadParams xReadParams = new XReadParams().count(2).block(0); + Map streams = Collections.singletonMap("mystream", new StreamEntryID("0-0")); + List>> expectedEntries = new ArrayList<>(); + + when(commandObjects.xread(xReadParams, streams)).thenReturn(listEntryStringListStreamEntryCommandObject); + when(commandExecutor.executeCommand(listEntryStringListStreamEntryCommandObject)).thenReturn(expectedEntries); + + List>> result = jedis.xread(xReadParams, streams); + + assertThat(result, equalTo(expectedEntries)); + verify(commandExecutor).executeCommand(listEntryStringListStreamEntryCommandObject); + verify(commandObjects).xread(xReadParams, streams); + } + + @Test + public void testXreadBinary() { + XReadParams xReadParams = new XReadParams().count(2).block(0); + Map.Entry stream1 = new AbstractMap.SimpleEntry<>("mystream".getBytes(), "0-0".getBytes()); + List expectedReadResult = new ArrayList<>(); + + when(commandObjects.xread(xReadParams, stream1)).thenReturn(listObjectCommandObject); + when(commandExecutor.executeCommand(listObjectCommandObject)).thenReturn(expectedReadResult); + + List result = jedis.xread(xReadParams, stream1); + + assertThat(result, equalTo(expectedReadResult)); + + verify(commandExecutor).executeCommand(listObjectCommandObject); + verify(commandObjects).xread(xReadParams, stream1); + } + + @Test + public void testXreadAsMap() { + XReadParams xReadParams = new XReadParams().count(2).block(0); + Map stream = Collections.singletonMap("mystream", new StreamEntryID("0-0")); + Map> expectedResult = new HashMap<>(); + + when(commandObjects.xreadAsMap(xReadParams, stream)).thenReturn(mapStringListStreamEntryCommandObject); + when(commandExecutor.executeCommand(mapStringListStreamEntryCommandObject)).thenReturn(expectedResult); + + Map> result = jedis.xreadAsMap(xReadParams, stream); + + assertThat(result, sameInstance(expectedResult)); + verify(commandExecutor).executeCommand(mapStringListStreamEntryCommandObject); + verify(commandObjects).xreadAsMap(xReadParams, stream); + } + + @Test + public void testXreadGroup() { + String groupName = "mygroup"; + String consumer = "myconsumer"; + XReadGroupParams xReadGroupParams = new XReadGroupParams().count(2).block(0); + Map streams = Collections.singletonMap("mystream", new StreamEntryID("0-0")); + List>> expectedEntries = new ArrayList<>(); + + when(commandObjects.xreadGroup(groupName, consumer, xReadGroupParams, streams)).thenReturn(listEntryStringListStreamEntryCommandObject); + when(commandExecutor.executeCommand(listEntryStringListStreamEntryCommandObject)).thenReturn(expectedEntries); + + List>> result = jedis.xreadGroup(groupName, consumer, xReadGroupParams, streams); + + assertThat(result, equalTo(expectedEntries)); + + verify(commandExecutor).executeCommand(listEntryStringListStreamEntryCommandObject); + verify(commandObjects).xreadGroup(groupName, consumer, xReadGroupParams, streams); + } + + @Test + public void testXreadGroupBinary() { + byte[] groupName = "mygroup".getBytes(); + byte[] consumer = "myconsumer".getBytes(); + XReadGroupParams xReadGroupParams = new XReadGroupParams().count(2).block(0); + Map.Entry stream1 = new AbstractMap.SimpleEntry<>("mystream".getBytes(), "0-0".getBytes()); + List expectedReadGroupResult = new ArrayList<>(); + + when(commandObjects.xreadGroup(groupName, consumer, xReadGroupParams, stream1)).thenReturn(listObjectCommandObject); + when(commandExecutor.executeCommand(listObjectCommandObject)).thenReturn(expectedReadGroupResult); + + List result = jedis.xreadGroup(groupName, consumer, xReadGroupParams, stream1); + + assertThat(result, equalTo(expectedReadGroupResult)); + + verify(commandExecutor).executeCommand(listObjectCommandObject); + verify(commandObjects).xreadGroup(groupName, consumer, xReadGroupParams, stream1); + } + + @Test + public void testXreadGroupAsMap() { + String groupName = "mygroup"; + String consumer = "myconsumer"; + XReadGroupParams xReadGroupParams = new XReadGroupParams().count(2).block(0); + Map stream1 = Collections.singletonMap("mystream", new StreamEntryID()); + Map> expectedReadGroupAsMapResult = new HashMap<>(); + + when(commandObjects.xreadGroupAsMap(groupName, consumer, xReadGroupParams, stream1)).thenReturn(mapStringListStreamEntryCommandObject); + when(commandExecutor.executeCommand(mapStringListStreamEntryCommandObject)).thenReturn(expectedReadGroupAsMapResult); + + Map> result = jedis.xreadGroupAsMap(groupName, consumer, xReadGroupParams, stream1); + + assertThat(result, sameInstance(expectedReadGroupAsMapResult)); + + verify(commandExecutor).executeCommand(mapStringListStreamEntryCommandObject); + verify(commandObjects).xreadGroupAsMap(groupName, consumer, xReadGroupParams, stream1); + } + + @Test + public void testXrevrange() { + String key = "mystream"; + String end = "+"; + String start = "-"; + Map hash = new HashMap<>(); + hash.put("field1", "value1"); + hash.put("field2", "value2"); + List expectedEntries = Collections.singletonList(new StreamEntry(new StreamEntryID("0-0"), hash)); + + when(commandObjects.xrevrange(key, end, start)).thenReturn(listStreamEntryCommandObject); + when(commandExecutor.executeCommand(listStreamEntryCommandObject)).thenReturn(expectedEntries); + + List result = jedis.xrevrange(key, end, start); + + assertThat(result, equalTo(expectedEntries)); + + verify(commandExecutor).executeCommand(listStreamEntryCommandObject); + verify(commandObjects).xrevrange(key, end, start); + } + + @Test + public void testXrevrangeBinary() { + byte[] key = "mystream".getBytes(); + byte[] end = "+".getBytes(); + byte[] start = "0-0".getBytes(); + List expectedReverseRange = Arrays.asList( + new StreamEntry(new StreamEntryID("0-1"), Collections.singletonMap("field2", "value2")), + new StreamEntry(new StreamEntryID("0-0"), Collections.singletonMap("field1", "value1"))); + + when(commandObjects.xrevrange(key, end, start)).thenReturn(listObjectCommandObject); + when(commandExecutor.executeCommand(listObjectCommandObject)).thenReturn(expectedReverseRange); + + List result = jedis.xrevrange(key, end, start); + + assertThat(result, equalTo(expectedReverseRange)); + + verify(commandExecutor).executeCommand(listObjectCommandObject); + verify(commandObjects).xrevrange(key, end, start); + } + + @Test + public void testXrevrangeWithCount() { + String key = "mystream"; + String end = "+"; + String start = "-"; + int count = 10; + Map hash = new HashMap<>(); + hash.put("field1", "value1"); + hash.put("field2", "value2"); + List expectedEntries = Collections.singletonList(new StreamEntry(new StreamEntryID("0-0"), hash)); + + when(commandObjects.xrevrange(key, end, start, count)).thenReturn(listStreamEntryCommandObject); + when(commandExecutor.executeCommand(listStreamEntryCommandObject)).thenReturn(expectedEntries); + + List result = jedis.xrevrange(key, end, start, count); + + assertThat(result, equalTo(expectedEntries)); + + verify(commandExecutor).executeCommand(listStreamEntryCommandObject); + verify(commandObjects).xrevrange(key, end, start, count); + } + + @Test + public void testXrevrangeWithCountBinary() { + byte[] key = "mystream".getBytes(); + byte[] end = "+".getBytes(); + byte[] start = "0-0".getBytes(); + int count = 1; + List expectedReverseRange = Collections.singletonList( + new StreamEntry(new StreamEntryID("0-1"), Collections.singletonMap("field2", "value2"))); + + when(commandObjects.xrevrange(key, end, start, count)).thenReturn(listObjectCommandObject); + when(commandExecutor.executeCommand(listObjectCommandObject)).thenReturn(expectedReverseRange); + + List result = jedis.xrevrange(key, end, start, count); + + assertThat(result, equalTo(expectedReverseRange)); + + verify(commandExecutor).executeCommand(listObjectCommandObject); + verify(commandObjects).xrevrange(key, end, start, count); + } + + @Test + public void testXrevrangeIds() { + String key = "mystream"; + StreamEntryID end = new StreamEntryID("0-1"); + StreamEntryID start = new StreamEntryID("0-0"); + Map hash = new HashMap<>(); + hash.put("field1", "value1"); + hash.put("field2", "value2"); + List expectedEntries = Collections.singletonList(new StreamEntry(new StreamEntryID("0-0"), hash)); + + when(commandObjects.xrevrange(key, end, start)).thenReturn(listStreamEntryCommandObject); + when(commandExecutor.executeCommand(listStreamEntryCommandObject)).thenReturn(expectedEntries); + + List result = jedis.xrevrange(key, end, start); + + assertThat(result, equalTo(expectedEntries)); + + verify(commandExecutor).executeCommand(listStreamEntryCommandObject); + verify(commandObjects).xrevrange(key, end, start); + } + + @Test + public void testXrevrangeIdsWithCount() { + String key = "mystream"; + StreamEntryID end = new StreamEntryID("0-1"); + StreamEntryID start = new StreamEntryID("0-0"); + int count = 10; + Map hash = new HashMap<>(); + hash.put("field1", "value1"); + hash.put("field2", "value2"); + List expectedEntries = Collections.singletonList(new StreamEntry(new StreamEntryID("0-0"), hash)); + + when(commandObjects.xrevrange(key, end, start, count)).thenReturn(listStreamEntryCommandObject); + when(commandExecutor.executeCommand(listStreamEntryCommandObject)).thenReturn(expectedEntries); + + List result = jedis.xrevrange(key, end, start, count); + + assertThat(result, equalTo(expectedEntries)); + + verify(commandExecutor).executeCommand(listStreamEntryCommandObject); + verify(commandObjects).xrevrange(key, end, start, count); + } + + @Test + public void testXtrim() { + String key = "mystream"; + long maxLen = 1000L; + boolean approximate = false; + long expectedTrimmedCount = 10L; // Assuming 10 entries were trimmed + + when(commandObjects.xtrim(key, maxLen, approximate)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedTrimmedCount); + + long result = jedis.xtrim(key, maxLen, approximate); + + assertThat(result, equalTo(expectedTrimmedCount)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).xtrim(key, maxLen, approximate); + } + + @Test + public void testXtrimBinary() { + byte[] key = "mystream".getBytes(); + long maxLen = 1000L; + boolean approximateLength = true; + long expectedTrimmed = 10L; + + when(commandObjects.xtrim(key, maxLen, approximateLength)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedTrimmed); + + long result = jedis.xtrim(key, maxLen, approximateLength); + + assertThat(result, equalTo(expectedTrimmed)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).xtrim(key, maxLen, approximateLength); + } + + @Test + public void testXtrimWithParams() { + String key = "mystream"; + XTrimParams params = new XTrimParams().maxLen(1000L); + long expectedTrimmedCount = 10L; // Assuming 10 entries were trimmed + + when(commandObjects.xtrim(key, params)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedTrimmedCount); + + long result = jedis.xtrim(key, params); + + assertThat(result, equalTo(expectedTrimmedCount)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).xtrim(key, params); + } + + @Test + public void testXtrimWithParamsBinary() { + byte[] key = "mystream".getBytes(); + XTrimParams params = new XTrimParams().maxLen(1000L); + long expectedTrimmed = 10L; + + when(commandObjects.xtrim(key, params)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedTrimmed); + + long result = jedis.xtrim(key, params); + + assertThat(result, equalTo(expectedTrimmed)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).xtrim(key, params); + } + +} diff --git a/src/test/java/redis/clients/jedis/mocked/unified/UnifiedJedisStringCommandsTest.java b/src/test/java/redis/clients/jedis/mocked/unified/UnifiedJedisStringCommandsTest.java new file mode 100644 index 00000000000..7d1e4f1bfd1 --- /dev/null +++ b/src/test/java/redis/clients/jedis/mocked/unified/UnifiedJedisStringCommandsTest.java @@ -0,0 +1,869 @@ +package redis.clients.jedis.mocked.unified; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.equalTo; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import java.util.Arrays; +import java.util.List; + +import org.junit.Test; +import redis.clients.jedis.params.GetExParams; +import redis.clients.jedis.params.LCSParams; +import redis.clients.jedis.params.SetParams; +import redis.clients.jedis.resps.LCSMatchResult; + +public class UnifiedJedisStringCommandsTest extends UnifiedJedisMockedTestBase { + + @Test + public void testAppend() { + String key = "key"; + String value = "value"; + long expectedLength = 10L; // Assuming the new length of the string is 10 after append + + when(commandObjects.append(key, value)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedLength); + + long result = jedis.append(key, value); + + assertThat(result, equalTo(expectedLength)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).append(key, value); + } + + @Test + public void testAppendBinary() { + byte[] key = "key".getBytes(); + byte[] value = "value".getBytes(); + long expectedLength = 10L; // Assuming the new length of the string is 10 after append + + when(commandObjects.append(key, value)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedLength); + + long result = jedis.append(key, value); + + assertThat(result, equalTo(expectedLength)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).append(key, value); + } + + @Test + public void testDecr() { + String key = "key"; + long expectedValue = -1L; // Assuming the key was decremented successfully + + when(commandObjects.decr(key)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedValue); + + long result = jedis.decr(key); + + assertThat(result, equalTo(expectedValue)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).decr(key); + } + + @Test + public void testDecrBinary() { + byte[] key = "key".getBytes(); + long expectedValue = -1L; // Assuming the key was decremented successfully + + when(commandObjects.decr(key)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedValue); + + long result = jedis.decr(key); + + assertThat(result, equalTo(expectedValue)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).decr(key); + } + + @Test + public void testDecrBy() { + String key = "key"; + long decrement = 2L; + long expectedValue = -2L; // Assuming the key was decremented by 2 successfully + + when(commandObjects.decrBy(key, decrement)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedValue); + + long result = jedis.decrBy(key, decrement); + + assertThat(result, equalTo(expectedValue)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).decrBy(key, decrement); + } + + @Test + public void testDecrByBinary() { + byte[] key = "key".getBytes(); + long decrement = 2L; + long expectedValue = -2L; // Assuming the key was decremented by 2 successfully + + when(commandObjects.decrBy(key, decrement)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedValue); + + long result = jedis.decrBy(key, decrement); + + assertThat(result, equalTo(expectedValue)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).decrBy(key, decrement); + } + + @Test + public void testGet() { + String key = "key"; + String expectedValue = "value"; + + when(commandObjects.get(key)).thenReturn(stringCommandObject); + when(commandExecutor.executeCommand(stringCommandObject)).thenReturn(expectedValue); + + String result = jedis.get(key); + + assertThat(result, equalTo(expectedValue)); + + verify(commandExecutor).executeCommand(stringCommandObject); + verify(commandObjects).get(key); + } + + @Test + public void testGetBinary() { + byte[] key = "key".getBytes(); + byte[] expectedValue = "value".getBytes(); + + when(commandObjects.get(key)).thenReturn(bytesCommandObject); + when(commandExecutor.executeCommand(bytesCommandObject)).thenReturn(expectedValue); + + byte[] result = jedis.get(key); + + assertThat(result, equalTo(expectedValue)); + + verify(commandExecutor).executeCommand(bytesCommandObject); + verify(commandObjects).get(key); + } + + @Test + public void testGetDel() { + String key = "key"; + String expectedValue = "value"; + + when(commandObjects.getDel(key)).thenReturn(stringCommandObject); + when(commandExecutor.executeCommand(stringCommandObject)).thenReturn(expectedValue); + + String result = jedis.getDel(key); + + assertThat(result, equalTo(expectedValue)); + + verify(commandExecutor).executeCommand(stringCommandObject); + verify(commandObjects).getDel(key); + } + + @Test + public void testGetDelBinary() { + byte[] key = "key".getBytes(); + byte[] expectedValue = "value".getBytes(); + + when(commandObjects.getDel(key)).thenReturn(bytesCommandObject); + when(commandExecutor.executeCommand(bytesCommandObject)).thenReturn(expectedValue); + + byte[] result = jedis.getDel(key); + + assertThat(result, equalTo(expectedValue)); + + verify(commandExecutor).executeCommand(bytesCommandObject); + verify(commandObjects).getDel(key); + } + + @Test + public void testGetEx() { + String key = "key"; + GetExParams params = new GetExParams().ex(10); + String expectedValue = "value"; + + when(commandObjects.getEx(key, params)).thenReturn(stringCommandObject); + when(commandExecutor.executeCommand(stringCommandObject)).thenReturn(expectedValue); + + String result = jedis.getEx(key, params); + + assertThat(result, equalTo(expectedValue)); + + verify(commandExecutor).executeCommand(stringCommandObject); + verify(commandObjects).getEx(key, params); + } + + @Test + public void testGetExBinary() { + byte[] key = "key".getBytes(); + GetExParams params = new GetExParams().ex(10); + byte[] expectedValue = "value".getBytes(); + + when(commandObjects.getEx(key, params)).thenReturn(bytesCommandObject); + when(commandExecutor.executeCommand(bytesCommandObject)).thenReturn(expectedValue); + + byte[] result = jedis.getEx(key, params); + + assertThat(result, equalTo(expectedValue)); + + verify(commandExecutor).executeCommand(bytesCommandObject); + verify(commandObjects).getEx(key, params); + } + + @Test + public void testGetrange() { + String key = "key"; + long startOffset = 0L; + long endOffset = 10L; + String expectedResponse = "value"; + + when(commandObjects.getrange(key, startOffset, endOffset)).thenReturn(stringCommandObject); + when(commandExecutor.executeCommand(stringCommandObject)).thenReturn(expectedResponse); + + String result = jedis.getrange(key, startOffset, endOffset); + + assertThat(result, equalTo(expectedResponse)); + + verify(commandExecutor).executeCommand(stringCommandObject); + verify(commandObjects).getrange(key, startOffset, endOffset); + } + + @Test + public void testGetrangeBinary() { + byte[] key = "key".getBytes(); + long startOffset = 0L; + long endOffset = 10L; + byte[] expectedResponse = "value".getBytes(); + + when(commandObjects.getrange(key, startOffset, endOffset)).thenReturn(bytesCommandObject); + when(commandExecutor.executeCommand(bytesCommandObject)).thenReturn(expectedResponse); + + byte[] result = jedis.getrange(key, startOffset, endOffset); + + assertThat(result, equalTo(expectedResponse)); + + verify(commandExecutor).executeCommand(bytesCommandObject); + verify(commandObjects).getrange(key, startOffset, endOffset); + } + + @Test + public void testGetSet() { + String key = "key"; + String value = "newValue"; + String expectedPreviousValue = "oldValue"; + + when(commandObjects.getSet(key, value)).thenReturn(stringCommandObject); + when(commandExecutor.executeCommand(stringCommandObject)).thenReturn(expectedPreviousValue); + + String result = jedis.getSet(key, value); + + assertThat(result, equalTo(expectedPreviousValue)); + + verify(commandExecutor).executeCommand(stringCommandObject); + verify(commandObjects).getSet(key, value); + } + + @Test + public void testGetSetBinary() { + byte[] key = "key".getBytes(); + byte[] value = "newValue".getBytes(); + byte[] expectedPreviousValue = "oldValue".getBytes(); + + when(commandObjects.getSet(key, value)).thenReturn(bytesCommandObject); + when(commandExecutor.executeCommand(bytesCommandObject)).thenReturn(expectedPreviousValue); + + byte[] result = jedis.getSet(key, value); + + assertThat(result, equalTo(expectedPreviousValue)); + + verify(commandExecutor).executeCommand(bytesCommandObject); + verify(commandObjects).getSet(key, value); + } + + @Test + public void testIncr() { + String key = "key"; + long expectedValue = 1L; + + when(commandObjects.incr(key)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedValue); + + long result = jedis.incr(key); + + assertThat(result, equalTo(expectedValue)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).incr(key); + } + + @Test + public void testIncrBinary() { + byte[] key = "key".getBytes(); + long expectedValue = 1L; // Assuming the key was incremented successfully + + when(commandObjects.incr(key)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedValue); + + long result = jedis.incr(key); + + assertThat(result, equalTo(expectedValue)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).incr(key); + } + + @Test + public void testIncrBy() { + String key = "key"; + long increment = 2L; + long expectedValue = 3L; // Assuming the key was incremented by 2 successfully + + when(commandObjects.incrBy(key, increment)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedValue); + + long result = jedis.incrBy(key, increment); + + assertThat(result, equalTo(expectedValue)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).incrBy(key, increment); + } + + @Test + public void testIncrByBinary() { + byte[] key = "key".getBytes(); + long increment = 2L; + long expectedValue = 3L; // Assuming the key was incremented by 2 successfully + + when(commandObjects.incrBy(key, increment)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedValue); + + long result = jedis.incrBy(key, increment); + + assertThat(result, equalTo(expectedValue)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).incrBy(key, increment); + } + + @Test + public void testIncrByFloat() { + String key = "key"; + double increment = 2.5; + double expectedValue = 3.5; // Assuming the key was incremented by 2.5 successfully + + when(commandObjects.incrByFloat(key, increment)).thenReturn(doubleCommandObject); + when(commandExecutor.executeCommand(doubleCommandObject)).thenReturn(expectedValue); + + double result = jedis.incrByFloat(key, increment); + + assertThat(result, equalTo(expectedValue)); + + verify(commandExecutor).executeCommand(doubleCommandObject); + verify(commandObjects).incrByFloat(key, increment); + } + + @Test + public void testIncrByFloatBinary() { + byte[] key = "key".getBytes(); + double increment = 2.5; + double expectedValue = 3.5; // Assuming the key was incremented by 2.5 successfully + + when(commandObjects.incrByFloat(key, increment)).thenReturn(doubleCommandObject); + when(commandExecutor.executeCommand(doubleCommandObject)).thenReturn(expectedValue); + + double result = jedis.incrByFloat(key, increment); + + assertThat(result, equalTo(expectedValue)); + + verify(commandExecutor).executeCommand(doubleCommandObject); + verify(commandObjects).incrByFloat(key, increment); + } + + @Test + public void testLcs() { + String keyA = "keyA"; + String keyB = "keyB"; + LCSParams params = new LCSParams().withMatchLen(); + LCSMatchResult expectedResult = new LCSMatchResult(5); // Assuming the LCS length is 5 + + when(commandObjects.lcs(keyA, keyB, params)).thenReturn(lcsMatchResultCommandObject); + when(commandExecutor.executeCommand(lcsMatchResultCommandObject)).thenReturn(expectedResult); + + LCSMatchResult result = jedis.lcs(keyA, keyB, params); + + assertThat(result, equalTo(expectedResult)); + + verify(commandExecutor).executeCommand(lcsMatchResultCommandObject); + verify(commandObjects).lcs(keyA, keyB, params); + } + + @Test + public void testLcsBinary() { + byte[] keyA = "keyA".getBytes(); + byte[] keyB = "keyB".getBytes(); + LCSParams params = new LCSParams().withMatchLen(); + LCSMatchResult expectedResult = new LCSMatchResult(5); // Assuming the LCS length is 5 + + when(commandObjects.lcs(keyA, keyB, params)).thenReturn(lcsMatchResultCommandObject); + when(commandExecutor.executeCommand(lcsMatchResultCommandObject)).thenReturn(expectedResult); + + LCSMatchResult result = jedis.lcs(keyA, keyB, params); + + assertThat(result, equalTo(expectedResult)); + + verify(commandExecutor).executeCommand(lcsMatchResultCommandObject); + verify(commandObjects).lcs(keyA, keyB, params); + } + + @Test + public void testMget() { + String[] keys = { "key1", "key2", "key3" }; + List expectedValues = Arrays.asList("value1", "value2", "value3"); + + when(commandObjects.mget(keys)).thenReturn(listStringCommandObject); + when(commandExecutor.executeCommand(listStringCommandObject)).thenReturn(expectedValues); + + List result = jedis.mget(keys); + + assertThat(result, equalTo(expectedValues)); + + verify(commandExecutor).executeCommand(listStringCommandObject); + verify(commandObjects).mget(keys); + } + + @Test + public void testMgetBinary() { + byte[][] keys = { "key1".getBytes(), "key2".getBytes(), "key3".getBytes() }; + List expectedValues = Arrays.asList("value1".getBytes(), "value2".getBytes(), "value3".getBytes()); + + when(commandObjects.mget(keys)).thenReturn(listBytesCommandObject); + when(commandExecutor.executeCommand(listBytesCommandObject)).thenReturn(expectedValues); + + List result = jedis.mget(keys); + + assertThat(result, equalTo(expectedValues)); + + verify(commandExecutor).executeCommand(listBytesCommandObject); + verify(commandObjects).mget(keys); + } + + @Test + public void testMset() { + String[] keysvalues = { "key1", "value1", "key2", "value2" }; + String expectedResponse = "OK"; + + when(commandObjects.mset(keysvalues)).thenReturn(stringCommandObject); + when(commandExecutor.executeCommand(stringCommandObject)).thenReturn(expectedResponse); + + String result = jedis.mset(keysvalues); + + assertThat(result, equalTo(expectedResponse)); + + verify(commandExecutor).executeCommand(stringCommandObject); + verify(commandObjects).mset(keysvalues); + } + + @Test + public void testMsetBinary() { + byte[][] keysvalues = { "key1".getBytes(), "value1".getBytes(), "key2".getBytes(), "value2".getBytes() }; + String expectedResponse = "OK"; + + when(commandObjects.mset(keysvalues)).thenReturn(stringCommandObject); + when(commandExecutor.executeCommand(stringCommandObject)).thenReturn(expectedResponse); + + String result = jedis.mset(keysvalues); + + assertThat(result, equalTo(expectedResponse)); + + verify(commandExecutor).executeCommand(stringCommandObject); + verify(commandObjects).mset(keysvalues); + } + + @Test + public void testMsetnx() { + String[] keysvalues = { "key1", "value1", "key2", "value2" }; + long expectedResponse = 1L; // Assuming the keys were set successfully + + when(commandObjects.msetnx(keysvalues)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedResponse); + + long result = jedis.msetnx(keysvalues); + + assertThat(result, equalTo(expectedResponse)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).msetnx(keysvalues); + } + + @Test + public void testMsetnxBinary() { + byte[][] keysvalues = { "key1".getBytes(), "value1".getBytes(), "key2".getBytes(), "value2".getBytes() }; + long expectedResponse = 1L; // Assuming the keys were set successfully + + when(commandObjects.msetnx(keysvalues)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedResponse); + + long result = jedis.msetnx(keysvalues); + + assertThat(result, equalTo(expectedResponse)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).msetnx(keysvalues); + } + + @Test + public void testPsetex() { + String key = "key"; + long milliseconds = 1000L; + String value = "value"; + String expectedResponse = "OK"; + + when(commandObjects.psetex(key, milliseconds, value)).thenReturn(stringCommandObject); + when(commandExecutor.executeCommand(stringCommandObject)).thenReturn(expectedResponse); + + String result = jedis.psetex(key, milliseconds, value); + + assertThat(result, equalTo(expectedResponse)); + + verify(commandExecutor).executeCommand(stringCommandObject); + verify(commandObjects).psetex(key, milliseconds, value); + } + + @Test + public void testPsetexBinary() { + byte[] key = "key".getBytes(); + long milliseconds = 1000L; + byte[] value = "value".getBytes(); + String expectedResponse = "OK"; + + when(commandObjects.psetex(key, milliseconds, value)).thenReturn(stringCommandObject); + when(commandExecutor.executeCommand(stringCommandObject)).thenReturn(expectedResponse); + + String result = jedis.psetex(key, milliseconds, value); + + assertThat(result, equalTo(expectedResponse)); + + verify(commandExecutor).executeCommand(stringCommandObject); + verify(commandObjects).psetex(key, milliseconds, value); + } + + @Test + public void testSet() { + String key = "key"; + String value = "value"; + String expectedResponse = "OK"; + + when(commandObjects.set(key, value)).thenReturn(stringCommandObject); + when(commandExecutor.executeCommand(stringCommandObject)).thenReturn(expectedResponse); + + String result = jedis.set(key, value); + + assertThat(result, equalTo(expectedResponse)); + + verify(commandExecutor).executeCommand(stringCommandObject); + verify(commandObjects).set(key, value); + } + + @Test + public void testSetBinary() { + byte[] key = "key".getBytes(); + byte[] value = "value".getBytes(); + String expectedResponse = "OK"; + + when(commandObjects.set(key, value)).thenReturn(stringCommandObject); + when(commandExecutor.executeCommand(stringCommandObject)).thenReturn(expectedResponse); + + String result = jedis.set(key, value); + + assertThat(result, equalTo(expectedResponse)); + + verify(commandExecutor).executeCommand(stringCommandObject); + verify(commandObjects).set(key, value); + } + + @Test + public void testSetWithParams() { + String key = "key"; + String value = "value"; + SetParams params = new SetParams().nx().ex(10); + String expectedResponse = "OK"; + + when(commandObjects.set(key, value, params)).thenReturn(stringCommandObject); + when(commandExecutor.executeCommand(stringCommandObject)).thenReturn(expectedResponse); + + String result = jedis.set(key, value, params); + + assertThat(result, equalTo(expectedResponse)); + + verify(commandExecutor).executeCommand(stringCommandObject); + verify(commandObjects).set(key, value, params); + } + + @Test + public void testSetWithParamsBinary() { + byte[] key = "key".getBytes(); + byte[] value = "value".getBytes(); + SetParams params = new SetParams().nx().ex(10); + String expectedResponse = "OK"; + + when(commandObjects.set(key, value, params)).thenReturn(stringCommandObject); + when(commandExecutor.executeCommand(stringCommandObject)).thenReturn(expectedResponse); + + String result = jedis.set(key, value, params); + + assertThat(result, equalTo(expectedResponse)); + + verify(commandExecutor).executeCommand(stringCommandObject); + verify(commandObjects).set(key, value, params); + } + + @Test + public void testSetGet() { + String key = "key"; + String value = "value"; + String expectedPreviousValue = "previousValue"; + + when(commandObjects.setGet(key, value)).thenReturn(stringCommandObject); + when(commandExecutor.executeCommand(stringCommandObject)).thenReturn(expectedPreviousValue); + + String result = jedis.setGet(key, value); + + assertThat(result, equalTo(expectedPreviousValue)); + + verify(commandExecutor).executeCommand(stringCommandObject); + verify(commandObjects).setGet(key, value); + } + + @Test + public void testSetGetBinary() { + byte[] key = "key".getBytes(); + byte[] value = "value".getBytes(); + byte[] expectedPreviousValue = "previousValue".getBytes(); + + when(commandObjects.setGet(key, value)).thenReturn(bytesCommandObject); + when(commandExecutor.executeCommand(bytesCommandObject)).thenReturn(expectedPreviousValue); + + byte[] result = jedis.setGet(key, value); + + assertThat(result, equalTo(expectedPreviousValue)); + + verify(commandExecutor).executeCommand(bytesCommandObject); + verify(commandObjects).setGet(key, value); + } + + @Test + public void testSetGetWithParams() { + String key = "key"; + String value = "value"; + SetParams params = new SetParams().nx().ex(10); + String expectedPreviousValue = "previousValue"; + + when(commandObjects.setGet(key, value, params)).thenReturn(stringCommandObject); + when(commandExecutor.executeCommand(stringCommandObject)).thenReturn(expectedPreviousValue); + + String result = jedis.setGet(key, value, params); + + assertThat(result, equalTo(expectedPreviousValue)); + + verify(commandExecutor).executeCommand(stringCommandObject); + verify(commandObjects).setGet(key, value, params); + } + + @Test + public void testSetGetWithParamsBinary() { + byte[] key = "key".getBytes(); + byte[] value = "value".getBytes(); + SetParams params = new SetParams().nx().ex(10); + byte[] expectedPreviousValue = "previousValue".getBytes(); + + when(commandObjects.setGet(key, value, params)).thenReturn(bytesCommandObject); + when(commandExecutor.executeCommand(bytesCommandObject)).thenReturn(expectedPreviousValue); + + byte[] result = jedis.setGet(key, value, params); + + assertThat(result, equalTo(expectedPreviousValue)); + + verify(commandExecutor).executeCommand(bytesCommandObject); + verify(commandObjects).setGet(key, value, params); + } + + @Test + public void testSetex() { + String key = "key"; + long seconds = 60L; + String value = "value"; + String expectedResponse = "OK"; + + when(commandObjects.setex(key, seconds, value)).thenReturn(stringCommandObject); + when(commandExecutor.executeCommand(stringCommandObject)).thenReturn(expectedResponse); + + String result = jedis.setex(key, seconds, value); + + assertThat(result, equalTo(expectedResponse)); + + verify(commandExecutor).executeCommand(stringCommandObject); + verify(commandObjects).setex(key, seconds, value); + } + + @Test + public void testSetexBinary() { + byte[] key = "key".getBytes(); + long seconds = 60L; + byte[] value = "value".getBytes(); + String expectedResponse = "OK"; + + when(commandObjects.setex(key, seconds, value)).thenReturn(stringCommandObject); + when(commandExecutor.executeCommand(stringCommandObject)).thenReturn(expectedResponse); + + String result = jedis.setex(key, seconds, value); + + assertThat(result, equalTo(expectedResponse)); + + verify(commandExecutor).executeCommand(stringCommandObject); + verify(commandObjects).setex(key, seconds, value); + } + + @Test + public void testSetnx() { + String key = "key"; + String value = "value"; + long expectedResponse = 1L; // Assuming the key was set successfully + + when(commandObjects.setnx(key, value)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedResponse); + + long result = jedis.setnx(key, value); + + assertThat(result, equalTo(expectedResponse)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).setnx(key, value); + } + + @Test + public void testSetnxBinary() { + byte[] key = "key".getBytes(); + byte[] value = "value".getBytes(); + long expectedResponse = 1L; // Assuming the key was set successfully + + when(commandObjects.setnx(key, value)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedResponse); + + long result = jedis.setnx(key, value); + + assertThat(result, equalTo(expectedResponse)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).setnx(key, value); + } + + @Test + public void testSetrange() { + String key = "key"; + long offset = 10L; + String value = "value"; + long expectedResponse = value.length(); + + when(commandObjects.setrange(key, offset, value)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedResponse); + + long result = jedis.setrange(key, offset, value); + + assertThat(result, equalTo(expectedResponse)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).setrange(key, offset, value); + } + + @Test + public void testSetrangeBinary() { + byte[] key = "key".getBytes(); + long offset = 10L; + byte[] value = "value".getBytes(); + long expectedResponse = value.length; + + when(commandObjects.setrange(key, offset, value)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedResponse); + + long result = jedis.setrange(key, offset, value); + + assertThat(result, equalTo(expectedResponse)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).setrange(key, offset, value); + } + + @Test + public void testStrlen() { + String key = "key"; + long expectedLength = 5L; // Assuming the length of the string value is 5 + + when(commandObjects.strlen(key)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedLength); + + long result = jedis.strlen(key); + + assertThat(result, equalTo(expectedLength)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).strlen(key); + } + + @Test + public void testStrlenBinary() { + byte[] key = "key".getBytes(); + long expectedLength = 5L; // Assuming the length of the string value is 5 + + when(commandObjects.strlen(key)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedLength); + + long result = jedis.strlen(key); + + assertThat(result, equalTo(expectedLength)); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).strlen(key); + } + + @Test + public void testSubstr() { + String key = "key"; + int start = 0; + int end = 3; + String expectedSubstring = "valu"; + + when(commandObjects.substr(key, start, end)).thenReturn(stringCommandObject); + when(commandExecutor.executeCommand(stringCommandObject)).thenReturn(expectedSubstring); + + String result = jedis.substr(key, start, end); + + assertThat(result, equalTo(expectedSubstring)); + + verify(commandExecutor).executeCommand(stringCommandObject); + verify(commandObjects).substr(key, start, end); + } + + @Test + public void testSubstrBinary() { + byte[] key = "key".getBytes(); + int start = 0; + int end = 3; + byte[] expectedSubstring = "valu".getBytes(); + + when(commandObjects.substr(key, start, end)).thenReturn(bytesCommandObject); + when(commandExecutor.executeCommand(bytesCommandObject)).thenReturn(expectedSubstring); + + byte[] result = jedis.substr(key, start, end); + + assertThat(result, equalTo(expectedSubstring)); + + verify(commandExecutor).executeCommand(bytesCommandObject); + verify(commandObjects).substr(key, start, end); + } + +} diff --git a/src/test/java/redis/clients/jedis/mocked/unified/UnifiedJedisTDigestCommandsTest.java b/src/test/java/redis/clients/jedis/mocked/unified/UnifiedJedisTDigestCommandsTest.java new file mode 100644 index 00000000000..4ccec8c1c70 --- /dev/null +++ b/src/test/java/redis/clients/jedis/mocked/unified/UnifiedJedisTDigestCommandsTest.java @@ -0,0 +1,277 @@ +package redis.clients.jedis.mocked.unified; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.sameInstance; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.junit.Test; +import redis.clients.jedis.bloom.TDigestMergeParams; + +public class UnifiedJedisTDigestCommandsTest extends UnifiedJedisMockedTestBase { + + @Test + public void testTdigestAdd() { + String key = "testTDigest"; + double[] values = { 1.0, 2.0, 3.0 }; + String expectedResponse = "OK"; + + when(commandObjects.tdigestAdd(key, values)).thenReturn(stringCommandObject); + when(commandExecutor.executeCommand(stringCommandObject)).thenReturn(expectedResponse); + + String result = jedis.tdigestAdd(key, values); + + assertThat(result, sameInstance(expectedResponse)); + verify(commandExecutor).executeCommand(stringCommandObject); + verify(commandObjects).tdigestAdd(key, values); + } + + @Test + public void testTdigestByRank() { + String key = "testTDigest"; + long[] ranks = { 1, 2 }; + List expectedResponse = Arrays.asList(0.1, 0.2); + + when(commandObjects.tdigestByRank(key, ranks)).thenReturn(listDoubleCommandObject); + when(commandExecutor.executeCommand(listDoubleCommandObject)).thenReturn(expectedResponse); + + List result = jedis.tdigestByRank(key, ranks); + + assertThat(result, sameInstance(expectedResponse)); + verify(commandExecutor).executeCommand(listDoubleCommandObject); + verify(commandObjects).tdigestByRank(key, ranks); + } + + @Test + public void testTdigestByRevRank() { + String key = "testTDigest"; + long[] ranks = { 1, 2 }; + List expectedResponse = Arrays.asList(9.9, 9.8); + + when(commandObjects.tdigestByRevRank(key, ranks)).thenReturn(listDoubleCommandObject); + when(commandExecutor.executeCommand(listDoubleCommandObject)).thenReturn(expectedResponse); + + List result = jedis.tdigestByRevRank(key, ranks); + + assertThat(result, sameInstance(expectedResponse)); + verify(commandExecutor).executeCommand(listDoubleCommandObject); + verify(commandObjects).tdigestByRevRank(key, ranks); + } + + @Test + public void testTdigestCDF() { + String key = "testTDigest"; + double[] values = { 0.5, 0.9 }; + List expectedResponse = Arrays.asList(0.1, 0.95); + + when(commandObjects.tdigestCDF(key, values)).thenReturn(listDoubleCommandObject); + when(commandExecutor.executeCommand(listDoubleCommandObject)).thenReturn(expectedResponse); + + List result = jedis.tdigestCDF(key, values); + + assertThat(result, sameInstance(expectedResponse)); + verify(commandExecutor).executeCommand(listDoubleCommandObject); + verify(commandObjects).tdigestCDF(key, values); + } + + @Test + public void testTdigestCreate() { + String key = "testTDigest"; + String expectedResponse = "OK"; + + when(commandObjects.tdigestCreate(key)).thenReturn(stringCommandObject); + when(commandExecutor.executeCommand(stringCommandObject)).thenReturn(expectedResponse); + + String result = jedis.tdigestCreate(key); + + assertThat(result, sameInstance(expectedResponse)); + verify(commandExecutor).executeCommand(stringCommandObject); + verify(commandObjects).tdigestCreate(key); + } + + @Test + public void testTdigestCreateWithCompression() { + String key = "testTDigest"; + int compression = 100; + String expectedResponse = "OK"; + + when(commandObjects.tdigestCreate(key, compression)).thenReturn(stringCommandObject); + when(commandExecutor.executeCommand(stringCommandObject)).thenReturn(expectedResponse); + + String result = jedis.tdigestCreate(key, compression); + + assertThat(result, sameInstance(expectedResponse)); + verify(commandExecutor).executeCommand(stringCommandObject); + verify(commandObjects).tdigestCreate(key, compression); + } + + @Test + public void testTdigestInfo() { + String key = "testTDigest"; + Map expectedResponse = new HashMap<>(); + expectedResponse.put("compression", 100); + expectedResponse.put("capacity", 1000); + expectedResponse.put("merged_nodes", 500); + expectedResponse.put("unmerged_nodes", 50); + expectedResponse.put("total_compressions", 10); + + when(commandObjects.tdigestInfo(key)).thenReturn(mapStringObjectCommandObject); + when(commandExecutor.executeCommand(mapStringObjectCommandObject)).thenReturn(expectedResponse); + + Map result = jedis.tdigestInfo(key); + + assertThat(result, sameInstance(expectedResponse)); + verify(commandExecutor).executeCommand(mapStringObjectCommandObject); + verify(commandObjects).tdigestInfo(key); + } + + @Test + public void testTdigestMax() { + String key = "testTDigest"; + double expectedResponse = 10.0; + + when(commandObjects.tdigestMax(key)).thenReturn(doubleCommandObject); + when(commandExecutor.executeCommand(doubleCommandObject)).thenReturn(expectedResponse); + + double result = jedis.tdigestMax(key); + + assertThat(result, equalTo(expectedResponse)); + verify(commandExecutor).executeCommand(doubleCommandObject); + verify(commandObjects).tdigestMax(key); + } + + @Test + public void testTdigestMerge() { + String destinationKey = "destTDigest"; + String[] sourceKeys = { "sourceTDigest1", "sourceTDigest2" }; + String expectedResponse = "OK"; + + when(commandObjects.tdigestMerge(destinationKey, sourceKeys)).thenReturn(stringCommandObject); + when(commandExecutor.executeCommand(stringCommandObject)).thenReturn(expectedResponse); + + String result = jedis.tdigestMerge(destinationKey, sourceKeys); + + assertThat(result, sameInstance(expectedResponse)); + verify(commandExecutor).executeCommand(stringCommandObject); + verify(commandObjects).tdigestMerge(destinationKey, sourceKeys); + } + + @Test + public void testTdigestMergeWithParams() { + TDigestMergeParams mergeParams = new TDigestMergeParams().compression(200); + String destinationKey = "destTDigest"; + String[] sourceKeys = { "sourceTDigest1", "sourceTDigest2" }; + String expectedResponse = "OK"; + + when(commandObjects.tdigestMerge(mergeParams, destinationKey, sourceKeys)).thenReturn(stringCommandObject); + when(commandExecutor.executeCommand(stringCommandObject)).thenReturn(expectedResponse); + + String result = jedis.tdigestMerge(mergeParams, destinationKey, sourceKeys); + + assertThat(result, sameInstance(expectedResponse)); + verify(commandExecutor).executeCommand(stringCommandObject); + verify(commandObjects).tdigestMerge(mergeParams, destinationKey, sourceKeys); + } + + @Test + public void testTdigestMin() { + String key = "testTDigest"; + double expectedResponse = 0.1; + + when(commandObjects.tdigestMin(key)).thenReturn(doubleCommandObject); + when(commandExecutor.executeCommand(doubleCommandObject)).thenReturn(expectedResponse); + + double result = jedis.tdigestMin(key); + + assertThat(result, equalTo(expectedResponse)); + verify(commandExecutor).executeCommand(doubleCommandObject); + verify(commandObjects).tdigestMin(key); + } + + @Test + public void testTdigestQuantile() { + String key = "testTDigest"; + double[] quantiles = { 0.1, 0.5, 0.9 }; + List expectedResponse = Arrays.asList(1.0, 2.0, 3.0); + + when(commandObjects.tdigestQuantile(key, quantiles)).thenReturn(listDoubleCommandObject); + when(commandExecutor.executeCommand(listDoubleCommandObject)).thenReturn(expectedResponse); + + List result = jedis.tdigestQuantile(key, quantiles); + + assertThat(result, sameInstance(expectedResponse)); + verify(commandExecutor).executeCommand(listDoubleCommandObject); + verify(commandObjects).tdigestQuantile(key, quantiles); + } + + @Test + public void testTdigestRank() { + String key = "testTDigest"; + double[] values = { 1.0, 2.0 }; + List expectedResponse = Arrays.asList(10L, 20L); + + when(commandObjects.tdigestRank(key, values)).thenReturn(listLongCommandObject); + when(commandExecutor.executeCommand(listLongCommandObject)).thenReturn(expectedResponse); + + List result = jedis.tdigestRank(key, values); + + assertThat(result, sameInstance(expectedResponse)); + verify(commandExecutor).executeCommand(listLongCommandObject); + verify(commandObjects).tdigestRank(key, values); + } + + @Test + public void testTdigestReset() { + String key = "testTDigest"; + String expectedResponse = "OK"; + + when(commandObjects.tdigestReset(key)).thenReturn(stringCommandObject); + when(commandExecutor.executeCommand(stringCommandObject)).thenReturn(expectedResponse); + + String result = jedis.tdigestReset(key); + + assertThat(result, sameInstance(expectedResponse)); + verify(commandExecutor).executeCommand(stringCommandObject); + verify(commandObjects).tdigestReset(key); + } + + @Test + public void testTdigestRevRank() { + String key = "testTDigest"; + double[] values = { 1.0, 2.0 }; + List expectedResponse = Arrays.asList(90L, 80L); + + when(commandObjects.tdigestRevRank(key, values)).thenReturn(listLongCommandObject); + when(commandExecutor.executeCommand(listLongCommandObject)).thenReturn(expectedResponse); + + List result = jedis.tdigestRevRank(key, values); + + assertThat(result, sameInstance(expectedResponse)); + verify(commandExecutor).executeCommand(listLongCommandObject); + verify(commandObjects).tdigestRevRank(key, values); + } + + @Test + public void testTdigestTrimmedMean() { + String key = "testTDigest"; + double lowCutQuantile = 0.1; + double highCutQuantile = 0.9; + double expectedResponse = 5.0; + + when(commandObjects.tdigestTrimmedMean(key, lowCutQuantile, highCutQuantile)).thenReturn(doubleCommandObject); + when(commandExecutor.executeCommand(doubleCommandObject)).thenReturn(expectedResponse); + + double result = jedis.tdigestTrimmedMean(key, lowCutQuantile, highCutQuantile); + + assertThat(result, equalTo(expectedResponse)); + verify(commandExecutor).executeCommand(doubleCommandObject); + verify(commandObjects).tdigestTrimmedMean(key, lowCutQuantile, highCutQuantile); + } + +} diff --git a/src/test/java/redis/clients/jedis/mocked/unified/UnifiedJedisTimeSeriesCommandsTest.java b/src/test/java/redis/clients/jedis/mocked/unified/UnifiedJedisTimeSeriesCommandsTest.java new file mode 100644 index 00000000000..d9e06ce77cb --- /dev/null +++ b/src/test/java/redis/clients/jedis/mocked/unified/UnifiedJedisTimeSeriesCommandsTest.java @@ -0,0 +1,538 @@ +package redis.clients.jedis.mocked.unified; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.sameInstance; +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import java.util.AbstractMap; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.junit.Test; +import redis.clients.jedis.timeseries.AggregationType; +import redis.clients.jedis.timeseries.TSAlterParams; +import redis.clients.jedis.timeseries.TSCreateParams; +import redis.clients.jedis.timeseries.TSElement; +import redis.clients.jedis.timeseries.TSGetParams; +import redis.clients.jedis.timeseries.TSInfo; +import redis.clients.jedis.timeseries.TSMGetElement; +import redis.clients.jedis.timeseries.TSMGetParams; +import redis.clients.jedis.timeseries.TSMRangeElements; +import redis.clients.jedis.timeseries.TSMRangeParams; +import redis.clients.jedis.timeseries.TSRangeParams; + +public class UnifiedJedisTimeSeriesCommandsTest extends UnifiedJedisMockedTestBase { + + @Test + public void testTsAdd() { + String key = "testKey"; + double value = 123.45; + long expectedResponse = 1582605077000L; // Timestamp of the added value + + when(commandObjects.tsAdd(key, value)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedResponse); + + long result = jedis.tsAdd(key, value); + + assertEquals(expectedResponse, result); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).tsAdd(key, value); + } + + @Test + public void testTsAddWithTimestamp() { + String key = "testKey"; + long timestamp = 1582605077000L; + double value = 123.45; + long expectedResponse = timestamp; // Timestamp of the added value + + when(commandObjects.tsAdd(key, timestamp, value)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedResponse); + + long result = jedis.tsAdd(key, timestamp, value); + + assertEquals(expectedResponse, result); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).tsAdd(key, timestamp, value); + } + + @Test + public void testTsAddWithTimestampAndParams() { + String key = "testKey"; + long timestamp = 1582605077000L; + double value = 123.45; + TSCreateParams createParams = new TSCreateParams().retention(86400000L); // 1 day retention + long expectedResponse = timestamp; // Timestamp of the added value + + when(commandObjects.tsAdd(key, timestamp, value, createParams)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedResponse); + + long result = jedis.tsAdd(key, timestamp, value, createParams); + + assertEquals(expectedResponse, result); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).tsAdd(key, timestamp, value, createParams); + } + + @Test + public void testTsAlter() { + String key = "testKey"; + TSAlterParams alterParams = new TSAlterParams().retention(86400000L); // 1 day retention + String expectedResponse = "OK"; + + when(commandObjects.tsAlter(key, alterParams)).thenReturn(stringCommandObject); + when(commandExecutor.executeCommand(stringCommandObject)).thenReturn(expectedResponse); + + String result = jedis.tsAlter(key, alterParams); + + assertEquals(expectedResponse, result); + + verify(commandExecutor).executeCommand(stringCommandObject); + verify(commandObjects).tsAlter(key, alterParams); + } + + @Test + public void testTsCreate() { + String key = "testKey"; + String expectedResponse = "OK"; + + when(commandObjects.tsCreate(key)).thenReturn(stringCommandObject); + when(commandExecutor.executeCommand(stringCommandObject)).thenReturn(expectedResponse); + + String result = jedis.tsCreate(key); + + assertEquals(expectedResponse, result); + + verify(commandExecutor).executeCommand(stringCommandObject); + verify(commandObjects).tsCreate(key); + } + + @Test + public void testTsCreateWithParams() { + String key = "testKey"; + TSCreateParams createParams = new TSCreateParams().retention(86400000L); // 1 day retention + String expectedResponse = "OK"; + + when(commandObjects.tsCreate(key, createParams)).thenReturn(stringCommandObject); + when(commandExecutor.executeCommand(stringCommandObject)).thenReturn(expectedResponse); + + String result = jedis.tsCreate(key, createParams); + + assertEquals(expectedResponse, result); + + verify(commandExecutor).executeCommand(stringCommandObject); + verify(commandObjects).tsCreate(key, createParams); + } + + @Test + public void testTsCreateRule() { + String sourceKey = "sourceKey"; + String destKey = "destKey"; + AggregationType aggregationType = AggregationType.AVG; + long timeBucket = 60000L; // 1 minute + String expectedResponse = "OK"; + + when(commandObjects.tsCreateRule(sourceKey, destKey, aggregationType, timeBucket)).thenReturn(stringCommandObject); + when(commandExecutor.executeCommand(stringCommandObject)).thenReturn(expectedResponse); + + String result = jedis.tsCreateRule(sourceKey, destKey, aggregationType, timeBucket); + + assertEquals(expectedResponse, result); + + verify(commandExecutor).executeCommand(stringCommandObject); + verify(commandObjects).tsCreateRule(sourceKey, destKey, aggregationType, timeBucket); + } + + @Test + public void testTsCreateRuleWithAlignTimestamp() { + String sourceKey = "sourceKey"; + String destKey = "destKey"; + AggregationType aggregationType = AggregationType.AVG; + long bucketDuration = 60000L; // 1 minute + long alignTimestamp = 1582600000000L; + String expectedResponse = "OK"; + + when(commandObjects.tsCreateRule(sourceKey, destKey, aggregationType, bucketDuration, alignTimestamp)).thenReturn(stringCommandObject); + when(commandExecutor.executeCommand(stringCommandObject)).thenReturn(expectedResponse); + + String result = jedis.tsCreateRule(sourceKey, destKey, aggregationType, bucketDuration, alignTimestamp); + + assertThat(result, sameInstance(expectedResponse)); + + verify(commandExecutor).executeCommand(stringCommandObject); + verify(commandObjects).tsCreateRule(sourceKey, destKey, aggregationType, bucketDuration, alignTimestamp); + } + + @Test + public void testTsDecrBy() { + String key = "testKey"; + double value = 1.5; + long expectedResponse = -1L; // Assuming the decrement results in a total of -1 + + when(commandObjects.tsDecrBy(key, value)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedResponse); + + long result = jedis.tsDecrBy(key, value); + + assertEquals(expectedResponse, result); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).tsDecrBy(key, value); + } + + @Test + public void testTsDecrByWithTimestamp() { + String key = "testKey"; + double value = 1.5; + long timestamp = 1582605077000L; + long expectedResponse = -1L; // Assuming the decrement results in a total of -1 + + when(commandObjects.tsDecrBy(key, value, timestamp)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedResponse); + + long result = jedis.tsDecrBy(key, value, timestamp); + + assertEquals(expectedResponse, result); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).tsDecrBy(key, value, timestamp); + } + + @Test + public void testTsDel() { + String key = "testKey"; + long fromTimestamp = 1582605077000L; + long toTimestamp = 1582605079000L; + long expectedResponse = 2L; // Number of deleted entries + + when(commandObjects.tsDel(key, fromTimestamp, toTimestamp)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedResponse); + + long result = jedis.tsDel(key, fromTimestamp, toTimestamp); + + assertEquals(expectedResponse, result); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).tsDel(key, fromTimestamp, toTimestamp); + } + + @Test + public void testTsDeleteRule() { + String sourceKey = "sourceKey"; + String destKey = "destKey"; + String expectedResponse = "OK"; + + when(commandObjects.tsDeleteRule(sourceKey, destKey)).thenReturn(stringCommandObject); + when(commandExecutor.executeCommand(stringCommandObject)).thenReturn(expectedResponse); + + String result = jedis.tsDeleteRule(sourceKey, destKey); + + assertThat(result, sameInstance(expectedResponse)); + + verify(commandExecutor).executeCommand(stringCommandObject); + verify(commandObjects).tsDeleteRule(sourceKey, destKey); + } + + @Test + public void testTsGet() { + String key = "testKey"; + TSElement expectedResponse = new TSElement(1582605077000L, 123.45); + + when(commandObjects.tsGet(key)).thenReturn(tsElementCommandObject); + when(commandExecutor.executeCommand(tsElementCommandObject)).thenReturn(expectedResponse); + + TSElement result = jedis.tsGet(key); + + assertEquals(expectedResponse, result); + + verify(commandExecutor).executeCommand(tsElementCommandObject); + verify(commandObjects).tsGet(key); + } + + @Test + public void testTsGetWithParams() { + String key = "testKey"; + TSGetParams getParams = new TSGetParams().latest(); + TSElement expectedResponse = new TSElement(1582605077000L, 123.45); + + when(commandObjects.tsGet(key, getParams)).thenReturn(tsElementCommandObject); + when(commandExecutor.executeCommand(tsElementCommandObject)).thenReturn(expectedResponse); + + TSElement result = jedis.tsGet(key, getParams); + + assertEquals(expectedResponse, result); + + verify(commandExecutor).executeCommand(tsElementCommandObject); + verify(commandObjects).tsGet(key, getParams); + } + + @Test + public void testTsIncrBy() { + String key = "testKey"; + double value = 2.5; + long expectedResponse = 5L; // Assuming the increment results in a total of 5 + + when(commandObjects.tsIncrBy(key, value)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedResponse); + + long result = jedis.tsIncrBy(key, value); + + assertEquals(expectedResponse, result); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).tsIncrBy(key, value); + } + + @Test + public void testTsIncrByWithTimestamp() { + String key = "testKey"; + double value = 2.5; + long timestamp = 1582605077000L; + long expectedResponse = 5L; // Assuming the increment results in a total of 5 + + when(commandObjects.tsIncrBy(key, value, timestamp)).thenReturn(longCommandObject); + when(commandExecutor.executeCommand(longCommandObject)).thenReturn(expectedResponse); + + long result = jedis.tsIncrBy(key, value, timestamp); + + assertEquals(expectedResponse, result); + + verify(commandExecutor).executeCommand(longCommandObject); + verify(commandObjects).tsIncrBy(key, value, timestamp); + } + + @Test + public void testTsInfo() { + String key = "testKey"; + TSInfo expectedResponse = mock(TSInfo.class); + + when(commandObjects.tsInfo(key)).thenReturn(tsInfoCommandObject); + when(commandExecutor.executeCommand(tsInfoCommandObject)).thenReturn(expectedResponse); + + TSInfo result = jedis.tsInfo(key); + + assertThat(result, sameInstance(expectedResponse)); + + verify(commandExecutor).executeCommand(tsInfoCommandObject); + verify(commandObjects).tsInfo(key); + } + + @Test + public void testTsInfoDebug() { + String key = "testKey"; + TSInfo expectedResponse = mock(TSInfo.class); + + when(commandObjects.tsInfoDebug(key)).thenReturn(tsInfoCommandObject); + when(commandExecutor.executeCommand(tsInfoCommandObject)).thenReturn(expectedResponse); + + TSInfo result = jedis.tsInfoDebug(key); + + assertThat(result, sameInstance(expectedResponse)); + + verify(commandExecutor).executeCommand(tsInfoCommandObject); + verify(commandObjects).tsInfoDebug(key); + } + + @Test + public void testTsMAdd() { + Map.Entry entry1 = new AbstractMap.SimpleEntry<>("key1", new TSElement(1582605077000L, 123.45)); + Map.Entry entry2 = new AbstractMap.SimpleEntry<>("key2", new TSElement(1582605078000L, 234.56)); + List expectedResponse = Arrays.asList(1582605077000L, 1582605078000L); // Timestamps of the added values + + when(commandObjects.tsMAdd(entry1, entry2)).thenReturn(listLongCommandObject); + when(commandExecutor.executeCommand(listLongCommandObject)).thenReturn(expectedResponse); + + List result = jedis.tsMAdd(entry1, entry2); + + assertEquals(expectedResponse, result); + + verify(commandExecutor).executeCommand(listLongCommandObject); + verify(commandObjects).tsMAdd(entry1, entry2); + } + + @Test + public void testTsMGet() { + TSMGetParams multiGetParams = new TSMGetParams().withLabels(); + String[] filters = { "sensor=temperature" }; + Map expectedResponse = new HashMap<>(); + + when(commandObjects.tsMGet(multiGetParams, filters)).thenReturn(mapStringTsmGetElementCommandObject); + when(commandExecutor.executeCommand(mapStringTsmGetElementCommandObject)).thenReturn(expectedResponse); + + Map result = jedis.tsMGet(multiGetParams, filters); + + assertEquals(expectedResponse, result); + + verify(commandExecutor).executeCommand(mapStringTsmGetElementCommandObject); + verify(commandObjects).tsMGet(multiGetParams, filters); + } + + @Test + public void testTsMRange() { + long fromTimestamp = 1582600000000L; + long toTimestamp = 1582605077000L; + String[] filters = { "sensor=temperature" }; + Map expectedResponse = new HashMap<>(); + + when(commandObjects.tsMRange(fromTimestamp, toTimestamp, filters)).thenReturn(mapStringTsmRangeElementsCommandObject); + when(commandExecutor.executeCommand(mapStringTsmRangeElementsCommandObject)).thenReturn(expectedResponse); + + Map result = jedis.tsMRange(fromTimestamp, toTimestamp, filters); + + assertEquals(expectedResponse, result); + + verify(commandExecutor).executeCommand(mapStringTsmRangeElementsCommandObject); + verify(commandObjects).tsMRange(fromTimestamp, toTimestamp, filters); + } + + @Test + public void testTsMRangeWithParams() { + TSMRangeParams multiRangeParams = TSMRangeParams.multiRangeParams(1582600000000L, 1582605077000L).filter("sensor=temperature"); + Map expectedResponse = new HashMap<>(); + + when(commandObjects.tsMRange(multiRangeParams)).thenReturn(mapStringTsmRangeElementsCommandObject); + when(commandExecutor.executeCommand(mapStringTsmRangeElementsCommandObject)).thenReturn(expectedResponse); + + Map result = jedis.tsMRange(multiRangeParams); + + assertEquals(expectedResponse, result); + + verify(commandExecutor).executeCommand(mapStringTsmRangeElementsCommandObject); + verify(commandObjects).tsMRange(multiRangeParams); + } + + @Test + public void testTsMRevRange() { + long fromTimestamp = 1582600000000L; + long toTimestamp = 1582605077000L; + String[] filters = { "sensor=temperature" }; + Map expectedResponse = new HashMap<>(); + + when(commandObjects.tsMRevRange(fromTimestamp, toTimestamp, filters)).thenReturn(mapStringTsmRangeElementsCommandObject); + when(commandExecutor.executeCommand(mapStringTsmRangeElementsCommandObject)).thenReturn(expectedResponse); + + Map result = jedis.tsMRevRange(fromTimestamp, toTimestamp, filters); + + assertEquals(expectedResponse, result); + + verify(commandExecutor).executeCommand(mapStringTsmRangeElementsCommandObject); + verify(commandObjects).tsMRevRange(fromTimestamp, toTimestamp, filters); + } + + @Test + public void testTsMRevRangeWithParams() { + TSMRangeParams multiRangeParams = + TSMRangeParams.multiRangeParams(1582600000000L, 1582605077000L).filter("sensor=temperature"); + Map expectedResponse = new HashMap<>(); + + when(commandObjects.tsMRevRange(multiRangeParams)).thenReturn(mapStringTsmRangeElementsCommandObject); + when(commandExecutor.executeCommand(mapStringTsmRangeElementsCommandObject)).thenReturn(expectedResponse); + + Map result = jedis.tsMRevRange(multiRangeParams); + + assertEquals(expectedResponse, result); + + verify(commandExecutor).executeCommand(mapStringTsmRangeElementsCommandObject); + verify(commandObjects).tsMRevRange(multiRangeParams); + } + + @Test + public void testTsQueryIndex() { + String[] filters = { "sensor=temperature", "location=warehouse" }; + List expectedResponse = Arrays.asList("series1", "series2"); + + when(commandObjects.tsQueryIndex(filters)).thenReturn(listStringCommandObject); + when(commandExecutor.executeCommand(listStringCommandObject)).thenReturn(expectedResponse); + + List result = jedis.tsQueryIndex(filters); + + assertThat(result, sameInstance(expectedResponse)); + + verify(commandExecutor).executeCommand(listStringCommandObject); + verify(commandObjects).tsQueryIndex(filters); + } + + @Test + public void testTsRange() { + String key = "testKey"; + long fromTimestamp = 1582600000000L; + long toTimestamp = 1582605077000L; + List expectedResponse = Collections.singletonList(new TSElement(fromTimestamp, 123.45)); + + when(commandObjects.tsRange(key, fromTimestamp, toTimestamp)).thenReturn(listTsElementCommandObject); + when(commandExecutor.executeCommand(listTsElementCommandObject)).thenReturn(expectedResponse); + + List result = jedis.tsRange(key, fromTimestamp, toTimestamp); + + assertEquals(expectedResponse, result); + + verify(commandExecutor).executeCommand(listTsElementCommandObject); + verify(commandObjects).tsRange(key, fromTimestamp, toTimestamp); + } + + @Test + public void testTsRangeWithParams() { + String key = "testKey"; + TSRangeParams rangeParams = TSRangeParams.rangeParams(1582600000000L, 1582605077000L); + List expectedResponse = Arrays.asList( + new TSElement(1582600000000L, 123.45), + new TSElement(1582605077000L, 234.56)); + + when(commandObjects.tsRange(key, rangeParams)).thenReturn(listTsElementCommandObject); + when(commandExecutor.executeCommand(listTsElementCommandObject)).thenReturn(expectedResponse); + + List result = jedis.tsRange(key, rangeParams); + + assertEquals(expectedResponse, result); + + verify(commandExecutor).executeCommand(listTsElementCommandObject); + verify(commandObjects).tsRange(key, rangeParams); + } + + @Test + public void testTsRevRange() { + String key = "testKey"; + long fromTimestamp = 1582600000000L; + long toTimestamp = 1582605077000L; + List expectedResponse = Collections.singletonList(new TSElement(toTimestamp, 234.56)); + + when(commandObjects.tsRevRange(key, fromTimestamp, toTimestamp)).thenReturn(listTsElementCommandObject); + when(commandExecutor.executeCommand(listTsElementCommandObject)).thenReturn(expectedResponse); + + List result = jedis.tsRevRange(key, fromTimestamp, toTimestamp); + + assertEquals(expectedResponse, result); + + verify(commandExecutor).executeCommand(listTsElementCommandObject); + verify(commandObjects).tsRevRange(key, fromTimestamp, toTimestamp); + } + + @Test + public void testTsRevRangeWithParams() { + String key = "testKey"; + TSRangeParams rangeParams = TSRangeParams.rangeParams(1582600000000L, 1582605077000L); + List expectedResponse = Arrays.asList( + new TSElement(1582605077000L, 234.56), + new TSElement(1582600000000L, 123.45)); + + when(commandObjects.tsRevRange(key, rangeParams)).thenReturn(listTsElementCommandObject); + when(commandExecutor.executeCommand(listTsElementCommandObject)).thenReturn(expectedResponse); + + List result = jedis.tsRevRange(key, rangeParams); + + assertEquals(expectedResponse, result); + + verify(commandExecutor).executeCommand(listTsElementCommandObject); + verify(commandObjects).tsRevRange(key, rangeParams); + } + +} diff --git a/src/test/java/redis/clients/jedis/mocked/unified/UnifiedJedisTopKCommandsTest.java b/src/test/java/redis/clients/jedis/mocked/unified/UnifiedJedisTopKCommandsTest.java new file mode 100644 index 00000000000..e629f80bd98 --- /dev/null +++ b/src/test/java/redis/clients/jedis/mocked/unified/UnifiedJedisTopKCommandsTest.java @@ -0,0 +1,161 @@ +package redis.clients.jedis.mocked.unified; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.sameInstance; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.junit.Test; + +public class UnifiedJedisTopKCommandsTest extends UnifiedJedisMockedTestBase { + + @Test + public void testTopkAdd() { + String key = "testTopK"; + String[] items = { "item1", "item2" }; + List expectedResponse = Arrays.asList("item3", "item4"); + + when(commandObjects.topkAdd(key, items)).thenReturn(listStringCommandObject); + when(commandExecutor.executeCommand(listStringCommandObject)).thenReturn(expectedResponse); + + List result = jedis.topkAdd(key, items); + + assertThat(result, sameInstance(expectedResponse)); + + verify(commandExecutor).executeCommand(listStringCommandObject); + verify(commandObjects).topkAdd(key, items); + } + + @Test + public void testTopkIncrBy() { + String key = "testTopK"; + Map itemIncrements = new HashMap<>(); + itemIncrements.put("item1", 1L); + itemIncrements.put("item2", 2L); + List expectedResponse = Arrays.asList("item3", "item4"); + + when(commandObjects.topkIncrBy(key, itemIncrements)).thenReturn(listStringCommandObject); + when(commandExecutor.executeCommand(listStringCommandObject)).thenReturn(expectedResponse); + + List result = jedis.topkIncrBy(key, itemIncrements); + + assertThat(result, sameInstance(expectedResponse)); + + verify(commandExecutor).executeCommand(listStringCommandObject); + verify(commandObjects).topkIncrBy(key, itemIncrements); + } + + @Test + public void testTopkInfo() { + String key = "testTopK"; + Map expectedResponse = new HashMap<>(); + expectedResponse.put("k", 10L); + expectedResponse.put("width", 50L); + expectedResponse.put("depth", 5L); + expectedResponse.put("decay", 0.9); + + when(commandObjects.topkInfo(key)).thenReturn(mapStringObjectCommandObject); + when(commandExecutor.executeCommand(mapStringObjectCommandObject)).thenReturn(expectedResponse); + + Map result = jedis.topkInfo(key); + + assertThat(result, sameInstance(expectedResponse)); + + verify(commandExecutor).executeCommand(mapStringObjectCommandObject); + verify(commandObjects).topkInfo(key); + } + + @Test + public void testTopkList() { + String key = "testTopK"; + List expectedResponse = Arrays.asList("item1", "item2", "item3"); + + when(commandObjects.topkList(key)).thenReturn(listStringCommandObject); + when(commandExecutor.executeCommand(listStringCommandObject)).thenReturn(expectedResponse); + + List result = jedis.topkList(key); + + assertThat(result, sameInstance(expectedResponse)); + + verify(commandExecutor).executeCommand(listStringCommandObject); + verify(commandObjects).topkList(key); + } + + @Test + public void testTopkListWithCount() { + String key = "testTopK"; + Map expectedResponse = new HashMap<>(); + expectedResponse.put("item1", 1L); + expectedResponse.put("item2", 2L); + + when(commandObjects.topkListWithCount(key)).thenReturn(mapStringLongCommandObject); + when(commandExecutor.executeCommand(mapStringLongCommandObject)).thenReturn(expectedResponse); + + Map result = jedis.topkListWithCount(key); + + assertThat(result, sameInstance(expectedResponse)); + + verify(commandExecutor).executeCommand(mapStringLongCommandObject); + verify(commandObjects).topkListWithCount(key); + } + + @Test + public void testTopkQuery() { + String key = "testTopK"; + String[] items = { "item1", "item2" }; + List expectedResponse = Arrays.asList(true, false); + + when(commandObjects.topkQuery(key, items)).thenReturn(listBooleanCommandObject); + when(commandExecutor.executeCommand(listBooleanCommandObject)).thenReturn(expectedResponse); + + List result = jedis.topkQuery(key, items); + + assertThat(result, sameInstance(expectedResponse)); + + verify(commandExecutor).executeCommand(listBooleanCommandObject); + verify(commandObjects).topkQuery(key, items); + } + + @Test + public void testTopkReserve() { + String key = "testTopK"; + long topk = 10L; + String expectedResponse = "OK"; + + when(commandObjects.topkReserve(key, topk)).thenReturn(stringCommandObject); + when(commandExecutor.executeCommand(stringCommandObject)).thenReturn(expectedResponse); + + String result = jedis.topkReserve(key, topk); + + assertThat(result, sameInstance(expectedResponse)); + + verify(commandExecutor).executeCommand(stringCommandObject); + verify(commandObjects).topkReserve(key, topk); + } + + @Test + public void testTopkReserveWidth() { + String key = "testTopK"; + long topk = 10L; + long width = 50L; + long depth = 5L; + double decay = 0.9; + String expectedResponse = "OK"; + + when(commandObjects.topkReserve(key, topk, width, depth, decay)).thenReturn(stringCommandObject); + when(commandExecutor.executeCommand(stringCommandObject)).thenReturn(expectedResponse); + + String result = jedis.topkReserve(key, topk, width, depth, decay); + + assertThat(result, sameInstance(expectedResponse)); + + verify(commandExecutor).executeCommand(stringCommandObject); + verify(commandObjects).topkReserve(key, topk, width, depth, decay); + } + +} diff --git a/src/test/java/redis/clients/jedis/mocked/unified/UnifiedJedisTriggersAndFunctionsCommandsTest.java b/src/test/java/redis/clients/jedis/mocked/unified/UnifiedJedisTriggersAndFunctionsCommandsTest.java new file mode 100644 index 00000000000..5dec794c65a --- /dev/null +++ b/src/test/java/redis/clients/jedis/mocked/unified/UnifiedJedisTriggersAndFunctionsCommandsTest.java @@ -0,0 +1,108 @@ +package redis.clients.jedis.mocked.unified; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.sameInstance; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import org.junit.Test; +import redis.clients.jedis.gears.TFunctionListParams; +import redis.clients.jedis.gears.TFunctionLoadParams; +import redis.clients.jedis.gears.resps.GearsLibraryInfo; + +public class UnifiedJedisTriggersAndFunctionsCommandsTest extends UnifiedJedisMockedTestBase { + + @Test + public void testTFunctionCall() { + String library = "mylib"; + String function = "myfunc"; + List keys = Arrays.asList("key1", "key2"); + List args = Arrays.asList("arg1", "arg2"); + Object expectedResponse = "result"; + + when(commandObjects.tFunctionCall(library, function, keys, args)).thenReturn(objectCommandObject); + when(commandExecutor.executeCommand(objectCommandObject)).thenReturn(expectedResponse); + + Object result = jedis.tFunctionCall(library, function, keys, args); + + assertThat(result, sameInstance(expectedResponse)); + + verify(commandExecutor).executeCommand(objectCommandObject); + verify(commandObjects).tFunctionCall(library, function, keys, args); + } + + @Test + public void testTFunctionCallAsync() { + String library = "mylib"; + String function = "myfunc"; + List keys = Arrays.asList("key1", "key2"); + List args = Arrays.asList("arg1", "arg2"); + Object expectedResponse = "result"; + + when(commandObjects.tFunctionCallAsync(library, function, keys, args)).thenReturn(objectCommandObject); + when(commandExecutor.executeCommand(objectCommandObject)).thenReturn(expectedResponse); + + Object result = jedis.tFunctionCallAsync(library, function, keys, args); + + assertThat(result, sameInstance(expectedResponse)); + + verify(commandExecutor).executeCommand(objectCommandObject); + verify(commandObjects).tFunctionCallAsync(library, function, keys, args); + } + + @Test + public void testTFunctionDelete() { + String libraryName = "mylib"; + String expectedResponse = "OK"; + + when(commandObjects.tFunctionDelete(libraryName)).thenReturn(stringCommandObject); + when(commandExecutor.executeCommand(stringCommandObject)).thenReturn(expectedResponse); + + String result = jedis.tFunctionDelete(libraryName); + + assertThat(result, sameInstance(expectedResponse)); + + verify(commandExecutor).executeCommand(stringCommandObject); + verify(commandObjects).tFunctionDelete(libraryName); + } + + @Test + public void testTFunctionList() { + TFunctionListParams params = new TFunctionListParams(); + List expectedResponse = new ArrayList<>(); + expectedResponse.add(mock(GearsLibraryInfo.class)); + + when(commandObjects.tFunctionList(params)).thenReturn(listGearsLibraryInfoCommandObject); + when(commandExecutor.executeCommand(listGearsLibraryInfoCommandObject)).thenReturn(expectedResponse); + + List result = jedis.tFunctionList(params); + + assertThat(result, sameInstance(expectedResponse)); + + verify(commandExecutor).executeCommand(listGearsLibraryInfoCommandObject); + verify(commandObjects).tFunctionList(params); + } + + @Test + public void testTFunctionLoad() { + String libraryCode = "function code"; + TFunctionLoadParams params = new TFunctionLoadParams(); + String expectedResponse = "OK"; + + when(commandObjects.tFunctionLoad(libraryCode, params)).thenReturn(stringCommandObject); + when(commandExecutor.executeCommand(stringCommandObject)).thenReturn(expectedResponse); + + String result = jedis.tFunctionLoad(libraryCode, params); + + assertThat(result, sameInstance(expectedResponse)); + + verify(commandExecutor).executeCommand(stringCommandObject); + verify(commandObjects).tFunctionLoad(libraryCode, params); + } + +} From 7a5bce18ae4e38f67781716b2ff39c5ea3a0fd9d Mon Sep 17 00:00:00 2001 From: Gabriel Erzse Date: Wed, 3 Apr 2024 16:48:31 +0300 Subject: [PATCH 32/33] Extensive unit tests for the CommandObjects class (#3796) Write isolated unit test for the different methods of the CommandObjects class. These can be tested by themselves, without considerations like cluster, sentinel or other orthogonal aspects. Structure the tests into logical groups, similar to how the Redis commands are documented on the redis.io website. For each group of commands there is a corresponding test class. The main goal is to have the test code as readable as possible. The methods are kept to a minimum length in general. Sometimes, due to required data preparation, this is not possible. Another goal is to have this as a sort of documentation. Ideally someone who reads these tests should be able to grasp what the Redis commands are doing. This being said, the tests still focus on testing the client. For example negative cases are rarely included, and mostly when they impact the client, for example the parsing of the response. It is not the goal of these tests to test the Redis server itself. Co-authored-by: Gabriel Erzse --- pom.xml | 6 + .../CommandObjectsBitmapCommandsTest.java | 195 +++ ...CommandObjectsBloomFilterCommandsTest.java | 138 ++ ...mandObjectsCountMinSketchCommandsTest.java | 203 +++ ...ommandObjectsCuckooFilterCommandsTest.java | 192 +++ .../CommandObjectsGenericCommandsTest.java | 81 + .../CommandObjectsGeospatialCommandsTest.java | 701 ++++++++ .../CommandObjectsHashCommandsTest.java | 405 +++++ ...CommandObjectsHyperloglogCommandsTest.java | 94 + .../CommandObjectsJsonCommandsTest.java | 1434 ++++++++++++++++ .../CommandObjectsListCommandsTest.java | 663 ++++++++ .../CommandObjectsModulesTestBase.java | 19 + .../CommandObjectsScriptingCommandsTest.java | 815 +++++++++ ...mandObjectsSearchAndQueryCommandsTest.java | 255 +++ ...ndObjectsServerManagementCommandsTest.java | 92 + .../CommandObjectsSetCommandsTest.java | 373 ++++ .../CommandObjectsSortedSetCommandsTest.java | 1508 +++++++++++++++++ .../CommandObjectsStandaloneTestBase.java | 15 + .../CommandObjectsStreamCommandsTest.java | 1023 +++++++++++ .../CommandObjectsStringCommandsTest.java | 593 +++++++ .../CommandObjectsTDigestCommandsTest.java | 255 +++ .../CommandObjectsTestBase.java | 108 ++ .../CommandObjectsTimeSeriesCommandsTest.java | 622 +++++++ .../CommandObjectsTopkCommandsTest.java | 118 ++ ...jectsTriggersAndFunctionsCommandsTest.java | 66 + .../jedis/commands/commandobjects/Person.java | 49 + 26 files changed, 10023 insertions(+) create mode 100644 src/test/java/redis/clients/jedis/commands/commandobjects/CommandObjectsBitmapCommandsTest.java create mode 100644 src/test/java/redis/clients/jedis/commands/commandobjects/CommandObjectsBloomFilterCommandsTest.java create mode 100644 src/test/java/redis/clients/jedis/commands/commandobjects/CommandObjectsCountMinSketchCommandsTest.java create mode 100644 src/test/java/redis/clients/jedis/commands/commandobjects/CommandObjectsCuckooFilterCommandsTest.java create mode 100644 src/test/java/redis/clients/jedis/commands/commandobjects/CommandObjectsGenericCommandsTest.java create mode 100644 src/test/java/redis/clients/jedis/commands/commandobjects/CommandObjectsGeospatialCommandsTest.java create mode 100644 src/test/java/redis/clients/jedis/commands/commandobjects/CommandObjectsHashCommandsTest.java create mode 100644 src/test/java/redis/clients/jedis/commands/commandobjects/CommandObjectsHyperloglogCommandsTest.java create mode 100644 src/test/java/redis/clients/jedis/commands/commandobjects/CommandObjectsJsonCommandsTest.java create mode 100644 src/test/java/redis/clients/jedis/commands/commandobjects/CommandObjectsListCommandsTest.java create mode 100644 src/test/java/redis/clients/jedis/commands/commandobjects/CommandObjectsModulesTestBase.java create mode 100644 src/test/java/redis/clients/jedis/commands/commandobjects/CommandObjectsScriptingCommandsTest.java create mode 100644 src/test/java/redis/clients/jedis/commands/commandobjects/CommandObjectsSearchAndQueryCommandsTest.java create mode 100644 src/test/java/redis/clients/jedis/commands/commandobjects/CommandObjectsServerManagementCommandsTest.java create mode 100644 src/test/java/redis/clients/jedis/commands/commandobjects/CommandObjectsSetCommandsTest.java create mode 100644 src/test/java/redis/clients/jedis/commands/commandobjects/CommandObjectsSortedSetCommandsTest.java create mode 100644 src/test/java/redis/clients/jedis/commands/commandobjects/CommandObjectsStandaloneTestBase.java create mode 100644 src/test/java/redis/clients/jedis/commands/commandobjects/CommandObjectsStreamCommandsTest.java create mode 100644 src/test/java/redis/clients/jedis/commands/commandobjects/CommandObjectsStringCommandsTest.java create mode 100644 src/test/java/redis/clients/jedis/commands/commandobjects/CommandObjectsTDigestCommandsTest.java create mode 100644 src/test/java/redis/clients/jedis/commands/commandobjects/CommandObjectsTestBase.java create mode 100644 src/test/java/redis/clients/jedis/commands/commandobjects/CommandObjectsTimeSeriesCommandsTest.java create mode 100644 src/test/java/redis/clients/jedis/commands/commandobjects/CommandObjectsTopkCommandsTest.java create mode 100644 src/test/java/redis/clients/jedis/commands/commandobjects/CommandObjectsTriggersAndFunctionsCommandsTest.java create mode 100644 src/test/java/redis/clients/jedis/commands/commandobjects/Person.java diff --git a/pom.xml b/pom.xml index aee4077c836..402cd358424 100644 --- a/pom.xml +++ b/pom.xml @@ -127,6 +127,12 @@ ${jackson.version} test + + net.javacrumbs.json-unit + json-unit + 2.38.0 + test + diff --git a/src/test/java/redis/clients/jedis/commands/commandobjects/CommandObjectsBitmapCommandsTest.java b/src/test/java/redis/clients/jedis/commands/commandobjects/CommandObjectsBitmapCommandsTest.java new file mode 100644 index 00000000000..5427447100c --- /dev/null +++ b/src/test/java/redis/clients/jedis/commands/commandobjects/CommandObjectsBitmapCommandsTest.java @@ -0,0 +1,195 @@ +package redis.clients.jedis.commands.commandobjects; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.contains; +import static org.hamcrest.Matchers.equalTo; + +import java.util.List; + +import org.junit.Test; +import redis.clients.jedis.RedisProtocol; +import redis.clients.jedis.args.BitCountOption; +import redis.clients.jedis.args.BitOP; +import redis.clients.jedis.params.BitPosParams; + +/** + * Tests related to Bitmap commands. + */ +public class CommandObjectsBitmapCommandsTest extends CommandObjectsStandaloneTestBase { + + public CommandObjectsBitmapCommandsTest(RedisProtocol protocol) { + super(protocol); + } + + @Test + public void testSetbitAndGetbit() { + String key = "bitKey"; + long offset = 10; + + Boolean initialValue = exec(commandObjects.getbit(key, offset)); + assertThat(initialValue, equalTo(false)); + + Boolean setbit = exec(commandObjects.setbit(key, offset, true)); + assertThat(setbit, equalTo(false)); // original value returned + + Boolean finalValue = exec(commandObjects.getbit(key, offset)); + assertThat(finalValue, equalTo(true)); + } + + @Test + public void testSetbitAndGetbitBinary() { + byte[] key = "bitKeyBytes".getBytes(); + long offset = 10; + + Boolean initialValue = exec(commandObjects.getbit(key, offset)); + assertThat(initialValue, equalTo(false)); + + Boolean setbit = exec(commandObjects.setbit(key, offset, true)); + assertThat(setbit, equalTo(false)); // original value returned + + Boolean finalValue = exec(commandObjects.getbit(key, offset)); + assertThat(finalValue, equalTo(true)); + } + + @Test + public void testBitcount() { + String key = "bitcountKey"; + byte[] keyBytes = key.getBytes(); + + // Set some bits + exec(commandObjects.setbit(key, 1, true)); + exec(commandObjects.setbit(key, 2, true)); + exec(commandObjects.setbit(key, 7, true)); // This makes 1 byte with 3 bits set + exec(commandObjects.setbit(key, 8, true)); // Next byte, first bit set + + Long bitcountFullString = exec(commandObjects.bitcount(key)); + assertThat(bitcountFullString, equalTo(4L)); + + Long bitcountFirstByte = exec(commandObjects.bitcount(key, 0, 0)); + assertThat(bitcountFirstByte, equalTo(3L)); + + Long bitcountFullStringBinary = exec(commandObjects.bitcount(keyBytes)); + assertThat(bitcountFullStringBinary, equalTo(4L)); + + Long bitcountFirstByteBinary = exec(commandObjects.bitcount(keyBytes, 0, 0)); + assertThat(bitcountFirstByteBinary, equalTo(3L)); + + Long bitcountFirstSixBits = exec(commandObjects.bitcount(key, 0, 5, BitCountOption.BIT)); + assertThat(bitcountFirstSixBits, equalTo(2L)); + + Long bitcountFirstSixBitsBinary = exec(commandObjects.bitcount(keyBytes, 0, 5, BitCountOption.BIT)); + assertThat(bitcountFirstSixBitsBinary, equalTo(2L)); + } + + @Test + public void testBitpos() { + String key = "bitposKey"; + byte[] keyBytes = key.getBytes(); + + // Set some bits + exec(commandObjects.setbit(key, 10, true)); + exec(commandObjects.setbit(key, 22, true)); + exec(commandObjects.setbit(key, 30, true)); + + Long firstSetBit = exec(commandObjects.bitpos(key, true)); + assertThat(firstSetBit, equalTo(10L)); + + Long firstUnsetBit = exec(commandObjects.bitpos(key, false)); + assertThat(firstUnsetBit, equalTo(0L)); + + BitPosParams params = new BitPosParams(15, 25).modifier(BitCountOption.BIT); + + Long firstSetBitInRange = exec(commandObjects.bitpos(key, true, params)); + assertThat(firstSetBitInRange, equalTo(22L)); + + Long firstUnsetBitInRange = exec(commandObjects.bitpos(key, false, params)); + assertThat(firstUnsetBitInRange, equalTo(15L)); + + Long firstSetBitBinary = exec(commandObjects.bitpos(keyBytes, true)); + assertThat(firstSetBitBinary, equalTo(10L)); + + Long firstUnsetBitBinary = exec(commandObjects.bitpos(keyBytes, false)); + assertThat(firstUnsetBitBinary, equalTo(0L)); + + Long firstSetBitInRangeBinary = exec(commandObjects.bitpos(keyBytes, true, params)); + assertThat(firstSetBitInRangeBinary, equalTo(22L)); + + Long firstUnsetBitInRangeBinary = exec(commandObjects.bitpos(keyBytes, false, params)); + assertThat(firstUnsetBitInRangeBinary, equalTo(15L)); + } + + @Test + public void testBitfield() { + String key = "bitfieldKey"; + + List bitfieldResult = exec(commandObjects.bitfield( + key, "INCRBY", "i5", "100", "7", "GET", "i5", "100")); + + // Contains the result of the INCRBY operation, and the result of the GET operation. + assertThat(bitfieldResult, contains(7L, 7L)); + + List bitfieldRoResult = exec(commandObjects.bitfieldReadonly( + key, "GET", "i4", "100")); + assertThat(bitfieldRoResult, contains(3L)); + } + + @Test + public void testBitfieldBinary() { + byte[] key = "bitfieldKeyBytes".getBytes(); + + List bitfieldResult = exec(commandObjects.bitfield(key, + "INCRBY".getBytes(), "i5".getBytes(), "100".getBytes(), "7".getBytes(), + "GET".getBytes(), "i5".getBytes(), "100".getBytes())); + + // Contains the result of the INCRBY operation, and the result of the GET operation. + assertThat(bitfieldResult, contains(7L, 7L)); + + List bitfieldRoResult = exec(commandObjects.bitfieldReadonly(key, + "GET".getBytes(), "i4".getBytes(), "100".getBytes())); + assertThat(bitfieldRoResult, contains(3L)); + } + + @Test + public void testBitop() { + String srcKey1 = "srcKey1"; + String srcKey2 = "srcKey2"; + String destKey = "destKey"; + + // Set some bits + exec(commandObjects.setbit(srcKey1, 1, true)); + exec(commandObjects.setbit(srcKey1, 2, true)); + exec(commandObjects.setbit(srcKey1, 3, true)); + + exec(commandObjects.setbit(srcKey2, 1, true)); + exec(commandObjects.setbit(srcKey2, 3, true)); + + Long bitopResult = exec(commandObjects.bitop(BitOP.AND, destKey, srcKey1, srcKey2)); + assertThat(bitopResult, equalTo(1L)); // 1 byte stored + + assertThat(exec(commandObjects.getbit(destKey, 1)), equalTo(true)); + assertThat(exec(commandObjects.getbit(destKey, 2)), equalTo(false)); + assertThat(exec(commandObjects.getbit(destKey, 3)), equalTo(true)); + } + + @Test + public void testBitopBinary() { + byte[] srcKey1 = "srcKey1".getBytes(); + byte[] srcKey2 = "srcKey2".getBytes(); + byte[] destKey = "destKey".getBytes(); + + // Set some bits + exec(commandObjects.setbit(srcKey1, 1, true)); + exec(commandObjects.setbit(srcKey1, 2, true)); + exec(commandObjects.setbit(srcKey1, 3, true)); + + exec(commandObjects.setbit(srcKey2, 1, true)); + exec(commandObjects.setbit(srcKey2, 3, true)); + + Long bitopResult = exec(commandObjects.bitop(BitOP.XOR, destKey, srcKey1, srcKey2)); + assertThat(bitopResult, equalTo(1L)); // 1 byte stored + + assertThat(exec(commandObjects.getbit(new String(destKey), 1)), equalTo(false)); + assertThat(exec(commandObjects.getbit(new String(destKey), 2)), equalTo(true)); + assertThat(exec(commandObjects.getbit(new String(destKey), 3)), equalTo(false)); + } +} diff --git a/src/test/java/redis/clients/jedis/commands/commandobjects/CommandObjectsBloomFilterCommandsTest.java b/src/test/java/redis/clients/jedis/commands/commandobjects/CommandObjectsBloomFilterCommandsTest.java new file mode 100644 index 00000000000..a69bd8b68ea --- /dev/null +++ b/src/test/java/redis/clients/jedis/commands/commandobjects/CommandObjectsBloomFilterCommandsTest.java @@ -0,0 +1,138 @@ +package redis.clients.jedis.commands.commandobjects; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.contains; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.hasEntry; +import static org.hamcrest.Matchers.notNullValue; + +import java.util.List; +import java.util.Map; + +import org.junit.Test; +import redis.clients.jedis.RedisProtocol; +import redis.clients.jedis.bloom.BFInsertParams; +import redis.clients.jedis.bloom.BFReserveParams; + +/** + * Tests related to Bloom Filter commands. + */ +public class CommandObjectsBloomFilterCommandsTest extends CommandObjectsModulesTestBase { + + public CommandObjectsBloomFilterCommandsTest(RedisProtocol protocol) { + super(protocol); + } + + @Test + public void testBfAddAndExists() { + String key = "testBf"; + + String reserve = exec(commandObjects.bfReserve(key, 0.01, 1000)); + assertThat(reserve, equalTo("OK")); + + boolean add = exec(commandObjects.bfAdd(key, "item1")); + assertThat(add, equalTo(true)); + + boolean exists = exec(commandObjects.bfExists(key, "item1")); + assertThat(exists, equalTo(true)); + + boolean notExists = exec(commandObjects.bfExists(key, "item2")); + assertThat(notExists, equalTo(false)); + } + + @Test + public void testBfInsert() { + String key = "testBf"; + + String reserve = exec(commandObjects.bfReserve(key, 0.01, 1000)); + assertThat(reserve, equalTo("OK")); + + List insert = exec(commandObjects.bfInsert(key, "item1", "item2")); + assertThat(insert, contains(true, true)); + + BFInsertParams insertParams = new BFInsertParams().noCreate().capacity(1000); + + List insertWithParams = exec(commandObjects.bfInsert(key, insertParams, "item1", "item2")); + assertThat(insertWithParams, contains(false, false)); + + assertThat(exec(commandObjects.bfExists(key, "item1")), equalTo(true)); + assertThat(exec(commandObjects.bfExists(key, "item2")), equalTo(true)); + assertThat(exec(commandObjects.bfExists(key, "item3")), equalTo(false)); + } + + @Test + public void testBfMAddMExistsAndCard() { + String key = "testBf"; + + String reserve = exec(commandObjects.bfReserve(key, 0.01, 1000)); + assertThat(reserve, equalTo("OK")); + + List mAdd = exec(commandObjects.bfMAdd(key, "item1", "item2", "item3")); + assertThat(mAdd, contains(true, true, true)); + + List mExists = exec(commandObjects.bfMExists(key, "item1", "item2", "item3", "item4")); + assertThat(mExists, contains(true, true, true, false)); + + Long card = exec(commandObjects.bfCard(key)); + assertThat(card, equalTo(3L)); + } + + @Test + public void testBfScanDumpAndLoadChunk() { + String key = "test"; + + String reserve = exec(commandObjects.bfReserve(key, 0.01, 5000)); + assertThat(reserve, equalTo("OK")); + + for (int i = 0; i < 1000; i++) { + Boolean add = exec(commandObjects.bfAdd(key, "item" + i)); + assertThat(add, equalTo(true)); + } + + String newKey = "testBfLoadChunk"; + + long iterator = 0; + do { + Map.Entry scanDumpResult = exec(commandObjects.bfScanDump(key, iterator)); + + iterator = scanDumpResult.getKey(); + + if (iterator > 0) { + byte[] data = scanDumpResult.getValue(); + + assertThat(data, notNullValue()); + + String loadChunk = exec(commandObjects.bfLoadChunk(newKey, iterator, data)); + assertThat(loadChunk, equalTo("OK")); + } + } while (iterator != 0); + + // verify destination + for (int i = 0; i < 1000; i++) { + Boolean exists = exec(commandObjects.bfExists(newKey, "item" + i)); + assertThat(exists, equalTo(true)); + } + + Boolean missingItem = exec(commandObjects.bfExists(newKey, "item1001")); + assertThat(missingItem, equalTo(false)); + } + + @Test + public void testBfInfo() { + String key = "testBf"; + + double errorRate = 0.01; + long capacity = 1000; + BFReserveParams reserveParams = new BFReserveParams().expansion(2); + + String reserve = exec(commandObjects.bfReserve(key, errorRate, capacity, reserveParams)); + assertThat(reserve, equalTo("OK")); + + Boolean add = exec(commandObjects.bfAdd(key, "item1")); + assertThat(add, equalTo(true)); + + Map info = exec(commandObjects.bfInfo(key)); + assertThat(info, hasEntry("Capacity", 1000L)); + assertThat(info, hasEntry("Number of items inserted", 1L)); + } +} diff --git a/src/test/java/redis/clients/jedis/commands/commandobjects/CommandObjectsCountMinSketchCommandsTest.java b/src/test/java/redis/clients/jedis/commands/commandobjects/CommandObjectsCountMinSketchCommandsTest.java new file mode 100644 index 00000000000..c1be92acb4b --- /dev/null +++ b/src/test/java/redis/clients/jedis/commands/commandobjects/CommandObjectsCountMinSketchCommandsTest.java @@ -0,0 +1,203 @@ +package redis.clients.jedis.commands.commandobjects; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.containsInAnyOrder; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.greaterThanOrEqualTo; +import static org.hamcrest.Matchers.hasEntry; +import static org.hamcrest.Matchers.hasSize; +import static org.hamcrest.Matchers.lessThanOrEqualTo; +import static org.hamcrest.Matchers.notNullValue; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.junit.Test; +import redis.clients.jedis.RedisProtocol; + +/** + * Tests related to Count-min sketch commands. + */ +public class CommandObjectsCountMinSketchCommandsTest extends CommandObjectsModulesTestBase { + + public CommandObjectsCountMinSketchCommandsTest(RedisProtocol protocol) { + super(protocol); + } + + @Test + public void testIncrByAndQuery() { + String key = "testCMS"; + + String init = exec(commandObjects.cmsInitByDim(key, 10000, 5)); + assertThat(init, equalTo("OK")); + + Map itemIncrements = new HashMap<>(); + itemIncrements.put("apple", 30L); + itemIncrements.put("banana", 20L); + itemIncrements.put("carrot", 10L); + + List incrBy = exec(commandObjects.cmsIncrBy(key, itemIncrements)); + // due to Map's unpredictable order, we can't assert ordering of the result + assertThat(incrBy, containsInAnyOrder(10L, 20L, 30L)); + + List query = exec(commandObjects.cmsQuery(key, "apple", "banana", "carrot", "date")); + + assertThat(query, notNullValue()); + assertThat(query.size(), equalTo(4)); + + assertThat(query.get(0), greaterThanOrEqualTo(30L)); // apple + assertThat(query.get(1), greaterThanOrEqualTo(20L)); // banana + assertThat(query.get(2), greaterThanOrEqualTo(10L)); // carrot + assertThat(query.get(3), lessThanOrEqualTo(1L)); // date, in practice, could be >0 due to estimation error + } + + @Test + public void testCMSInitByProb() { + String key = "testCMS"; + + String init = exec(commandObjects.cmsInitByProb(key, 0.01, 0.99)); + assertThat(init, equalTo("OK")); + + Map itemIncrements = new HashMap<>(); + itemIncrements.put("apple", 5L); + itemIncrements.put("banana", 3L); + itemIncrements.put("carrot", 8L); + + List incrBy = exec(commandObjects.cmsIncrBy(key, itemIncrements)); + assertThat(incrBy, containsInAnyOrder(3L, 5L, 8L)); + + List query = exec(commandObjects.cmsQuery(key, "apple", "banana", "carrot", "dragonfruit")); + + assertThat(query, notNullValue()); + assertThat(query.size(), equalTo(4)); + + assertThat(query.get(0), greaterThanOrEqualTo(5L)); // apple + assertThat(query.get(1), greaterThanOrEqualTo(3L)); // banana + assertThat(query.get(2), greaterThanOrEqualTo(8L)); // carrot + // "dragonfruit" was not incremented, its count should be minimal, but due to the probabilistic nature of CMS, it might not be exactly 0. + assertThat(query.get(3), lessThanOrEqualTo(1L)); + } + + @Test + public void testCMSMerge() { + String cmsKey1 = "testCMS1"; + String cmsKey2 = "testCMS2"; + String cmsDestKey = "testCMSMerged"; + + long width = 10000; + long depth = 5; + + String init1 = exec(commandObjects.cmsInitByDim(cmsKey1, width, depth)); + assertThat(init1, equalTo("OK")); + + String init2 = exec(commandObjects.cmsInitByDim(cmsKey2, width, depth)); + assertThat(init2, equalTo("OK")); + + Map itemIncrements1 = new HashMap<>(); + itemIncrements1.put("apple", 2L); + itemIncrements1.put("banana", 3L); + + List incrBy1 = exec(commandObjects.cmsIncrBy(cmsKey1, itemIncrements1)); + assertThat(incrBy1, containsInAnyOrder(2L, 3L)); + + Map itemIncrements2 = new HashMap<>(); + itemIncrements2.put("carrot", 5L); + itemIncrements2.put("date", 4L); + + List incrBy2 = exec(commandObjects.cmsIncrBy(cmsKey2, itemIncrements2)); + assertThat(incrBy2, containsInAnyOrder(4L, 5L)); + + String init3 = exec(commandObjects.cmsInitByDim(cmsDestKey, width, depth)); + assertThat(init3, equalTo("OK")); + + String merge = exec(commandObjects.cmsMerge(cmsDestKey, cmsKey1, cmsKey2)); + assertThat(merge, equalTo("OK")); + + List query = exec(commandObjects.cmsQuery(cmsDestKey, "apple", "banana", "carrot", "date")); + + assertThat(query, notNullValue()); + assertThat(query.size(), equalTo(4)); + + assertThat(query.get(0), greaterThanOrEqualTo(2L)); // apple + assertThat(query.get(1), greaterThanOrEqualTo(3L)); // banana + assertThat(query.get(2), greaterThanOrEqualTo(5L)); // carrot + assertThat(query.get(3), greaterThanOrEqualTo(4L)); // date + } + + @Test + public void testCMSMergeWithWeights() { + String cmsKey1 = "testCMS1"; + String cmsKey2 = "testCMS2"; + String cmsDestKey = "testCMSMerged"; + + long width = 10000; + long depth = 5; + + String init1 = exec(commandObjects.cmsInitByDim(cmsKey1, width, depth)); + assertThat(init1, equalTo("OK")); + + String init2 = exec(commandObjects.cmsInitByDim(cmsKey2, width, depth)); + assertThat(init2, equalTo("OK")); + + Map itemIncrements1 = new HashMap<>(); + itemIncrements1.put("apple", 2L); + itemIncrements1.put("banana", 3L); + + List incrBy1 = exec(commandObjects.cmsIncrBy(cmsKey1, itemIncrements1)); + assertThat(incrBy1, containsInAnyOrder(2L, 3L)); + + Map itemIncrements2 = new HashMap<>(); + itemIncrements2.put("carrot", 5L); + itemIncrements2.put("date", 4L); + + List incrBy2 = exec(commandObjects.cmsIncrBy(cmsKey2, itemIncrements2)); + assertThat(incrBy2, containsInAnyOrder(4L, 5L)); + + String init3 = exec(commandObjects.cmsInitByDim(cmsDestKey, width, depth)); + assertThat(init3, equalTo("OK")); + + // Weights for the CMS keys to be merged + Map keysAndWeights = new HashMap<>(); + keysAndWeights.put(cmsKey1, 1L); + keysAndWeights.put(cmsKey2, 2L); + + String merge = exec(commandObjects.cmsMerge(cmsDestKey, keysAndWeights)); + assertThat(merge, equalTo("OK")); + + List query = exec(commandObjects.cmsQuery(cmsDestKey, "apple", "banana", "carrot", "date")); + + assertThat(query, notNullValue()); + assertThat(query.size(), equalTo(4)); + + assertThat(query.get(0), greaterThanOrEqualTo(2L)); // apple, weight of 1 + assertThat(query.get(1), greaterThanOrEqualTo(3L)); // banana, weight of 1 + assertThat(query.get(2), greaterThanOrEqualTo(10L)); // carrot, weight of 2, so 5 * 2 + assertThat(query.get(3), greaterThanOrEqualTo(8L)); // date, weight of 2, so 4 * 2 + } + + @Test + public void testCMSInfo() { + String key = "testCMS"; + + long width = 10000; + long depth = 5; + + String init = exec(commandObjects.cmsInitByDim(key, width, depth)); + assertThat(init, equalTo("OK")); + + Map itemIncrements = new HashMap<>(); + itemIncrements.put("apple", 3L); + itemIncrements.put("banana", 2L); + itemIncrements.put("carrot", 1L); + + List incrBy = exec(commandObjects.cmsIncrBy(key, itemIncrements)); + assertThat(incrBy, hasSize(3)); + + Map info = exec(commandObjects.cmsInfo(key)); + + assertThat(info, hasEntry("width", 10000L)); + assertThat(info, hasEntry("depth", 5L)); + assertThat(info, hasEntry("count", 6L)); // 3 + 2 + 1 + } +} diff --git a/src/test/java/redis/clients/jedis/commands/commandobjects/CommandObjectsCuckooFilterCommandsTest.java b/src/test/java/redis/clients/jedis/commands/commandobjects/CommandObjectsCuckooFilterCommandsTest.java new file mode 100644 index 00000000000..68bc9b7060f --- /dev/null +++ b/src/test/java/redis/clients/jedis/commands/commandobjects/CommandObjectsCuckooFilterCommandsTest.java @@ -0,0 +1,192 @@ +package redis.clients.jedis.commands.commandobjects; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.contains; +import static org.hamcrest.Matchers.empty; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.everyItem; +import static org.hamcrest.Matchers.greaterThanOrEqualTo; +import static org.hamcrest.Matchers.hasEntry; +import static org.hamcrest.Matchers.not; +import static org.hamcrest.Matchers.notNullValue; + +import java.util.List; +import java.util.Map; + +import org.junit.Test; +import redis.clients.jedis.RedisProtocol; +import redis.clients.jedis.bloom.CFInsertParams; +import redis.clients.jedis.bloom.CFReserveParams; + +/** + * Tests related to Cuckoo filter commands. + */ +public class CommandObjectsCuckooFilterCommandsTest extends CommandObjectsModulesTestBase { + + public CommandObjectsCuckooFilterCommandsTest(RedisProtocol protocol) { + super(protocol); + } + + @Test + public void testCuckooFilterAdd() { + String key = "testCuckooFilter"; + + String reserve = exec(commandObjects.cfReserve(key, 1000)); + assertThat(reserve, equalTo("OK")); + + Boolean add = exec(commandObjects.cfAdd(key, "apple")); + assertThat(add, equalTo(true)); + + Boolean addNx = exec(commandObjects.cfAddNx(key, "apple")); + assertThat(addNx, equalTo(false)); // "apple" already exists, NX makes this fail + + Boolean addNx2 = exec(commandObjects.cfAddNx(key, "banana")); + assertThat(addNx2, equalTo(true)); + + Long count = exec(commandObjects.cfCount(key, "apple")); + assertThat(count, greaterThanOrEqualTo(1L)); + } + + @Test + public void testCuckooFilterReserveInsertAndCount() { + String key = "testCuckooFilterAdvanced"; + + CFReserveParams reserveParams = new CFReserveParams() + .bucketSize(4).maxIterations(500).expansion(1); + + String reserve = exec(commandObjects.cfReserve(key, 5000, reserveParams)); + assertThat(reserve, equalTo("OK")); + + List insert = exec(commandObjects.cfInsert( + key, "apple", "banana", "carrot", "date")); + assertThat(insert, everyItem(equalTo(true))); + + CFInsertParams insertParams = new CFInsertParams().noCreate(); + + List insertWithParams = exec(commandObjects.cfInsert( + key, insertParams, "eggplant", "fig", "grape", "apple")); + assertThat(insertWithParams, everyItem(equalTo(true))); + + Long countApple = exec(commandObjects.cfCount(key, "apple")); + assertThat(countApple, greaterThanOrEqualTo(2L)); + + Long countBanana = exec(commandObjects.cfCount(key, "banana")); + assertThat(countBanana, greaterThanOrEqualTo(1L)); + + Long countNonExisting = exec(commandObjects.cfCount(key, "watermelon")); + assertThat(countNonExisting, equalTo(0L)); + } + + @Test + public void testCuckooFilterInsertNx() { + String key = "testCf"; + + String[] items = { "item1", "item2", "item3" }; + + CFInsertParams insertParams = new CFInsertParams().capacity(1000L).noCreate(); + + List insertNx1 = exec(commandObjects.cfInsertNx(key, items)); + assertThat(insertNx1, not(empty())); + assertThat(insertNx1, everyItem(equalTo(true))); + + long countAfterFirstInsert = exec(commandObjects.cfCount(key, "item1")); + assertThat(countAfterFirstInsert, greaterThanOrEqualTo(1L)); + + List insertNx2 = exec(commandObjects.cfInsertNx(key, insertParams, items)); + assertThat(insertNx2, not(empty())); + assertThat(insertNx2, everyItem(equalTo(false))); + + long countAfterSecondInsert = exec(commandObjects.cfCount(key, "item1")); + assertThat(countAfterSecondInsert, greaterThanOrEqualTo(1L)); // count should remain the same + } + + @Test + public void testCuckooFilterExistsAndDel() { + String key = "testCf"; + String item = "item1"; + + boolean existsBeforeInsert = exec(commandObjects.cfExists(key, item)); + assertThat(existsBeforeInsert, equalTo(false)); + + Boolean add = exec(commandObjects.cfAdd(key, item)); + assertThat(add, equalTo(true)); + + boolean existsAfterInsert = exec(commandObjects.cfExists(key, item)); + assertThat(existsAfterInsert, equalTo(true)); + + boolean delete = exec(commandObjects.cfDel(key, item)); + assertThat(delete, equalTo(true)); + + boolean existsAfterDelete = exec(commandObjects.cfExists(key, item)); + assertThat(existsAfterDelete, equalTo(false)); + } + + @Test + public void testCuckooFilterMExists() { + String key = "testCf"; + + exec(commandObjects.cfInsert(key, "item1", "item2", "item3")); + + List mExists = exec(commandObjects.cfMExists( + key, "item1", "item2", "item3", "item4", "item5")); + + assertThat(mExists, contains(true, true, true, false, false)); + } + + @Test + public void testCuckooFilterScanDumpAndLoadChunk() { + long capacity = 5000; + + CFReserveParams reserveParams = new CFReserveParams() + .bucketSize(4).maxIterations(500).expansion(1); + + String key = "testCf"; + + String reserve = exec(commandObjects.cfReserve(key, capacity, reserveParams)); + assertThat(reserve, equalTo("OK")); + + // add some items to the source + for (int i = 0; i < 1000; i++) { + exec(commandObjects.cfAdd(key, "item" + i)); + } + + String newKey = "testCfLoadChunk"; + + // scandump and load + long iterator = 0; + do { + Map.Entry scanDumpResult = exec(commandObjects.cfScanDump(key, iterator)); + + iterator = scanDumpResult.getKey(); + if (iterator > 0) { + byte[] data = scanDumpResult.getValue(); + assertThat(data, notNullValue()); + + String loadChunk = exec(commandObjects.cfLoadChunk(newKey, iterator, data)); + assertThat(loadChunk, equalTo("OK")); + } + } while (iterator != 0); + + // verify destination + for (int i = 0; i < 1000; i++) { + boolean exists = exec(commandObjects.cfExists(newKey, "item" + i)); + assertThat(exists, equalTo(true)); + } + + boolean missingItem = exec(commandObjects.cfExists(newKey, "item1001")); + assertThat(missingItem, equalTo(false)); + } + + @Test + public void testCuckooFilterInfo() { + String key = "testCfInfo"; + + exec(commandObjects.cfReserve(key, 1000)); + + exec(commandObjects.cfAdd(key, "item1")); + + Map info = exec(commandObjects.cfInfo(key)); + + assertThat(info, hasEntry("Number of items inserted", 1L)); + } +} diff --git a/src/test/java/redis/clients/jedis/commands/commandobjects/CommandObjectsGenericCommandsTest.java b/src/test/java/redis/clients/jedis/commands/commandobjects/CommandObjectsGenericCommandsTest.java new file mode 100644 index 00000000000..0182de207f6 --- /dev/null +++ b/src/test/java/redis/clients/jedis/commands/commandobjects/CommandObjectsGenericCommandsTest.java @@ -0,0 +1,81 @@ +package redis.clients.jedis.commands.commandobjects; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.equalTo; + +import org.junit.Test; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.RedisProtocol; + +/** + * Tests related to Generic commands. + */ +public class CommandObjectsGenericCommandsTest extends CommandObjectsStandaloneTestBase { + + public CommandObjectsGenericCommandsTest(RedisProtocol protocol) { + super(protocol); + } + + @Test + public void testCopy() { + String srcKey = "sourceKey"; + String dstKey = "destinationKey"; + int dstDB = 1; + + exec(commandObjects.set(srcKey, "initialValue")); + + Boolean existsAfterSet = exec(commandObjects.exists(srcKey)); + assertThat(existsAfterSet, equalTo(true)); + + Boolean copy = exec(commandObjects.copy(srcKey, dstKey, dstDB, true)); + assertThat(copy, equalTo(true)); + + assertKeyExists(dstDB, dstKey, "initialValue"); + + // Update source + exec(commandObjects.set(srcKey, "newValue")); + + // Copy again without replace, it fails since dstKey already exists + Boolean secondCopy = exec(commandObjects.copy(srcKey, dstKey, dstDB, false)); + assertThat(secondCopy, equalTo(false)); + + assertKeyExists(dstDB, dstKey, "initialValue"); + } + + @Test + public void testCopyBinary() { + String srcKey = "sourceKey"; + String dstKey = "destinationKey"; + int dstDB = 1; + + exec(commandObjects.set(srcKey, "initialValue")); + + Boolean existsAfterSet = exec(commandObjects.exists(srcKey)); + assertThat(existsAfterSet, equalTo(true)); + + Boolean copy = exec(commandObjects.copy( + srcKey.getBytes(), dstKey.getBytes(), dstDB, true)); + assertThat(copy, equalTo(true)); + + assertKeyExists(dstDB, dstKey, "initialValue"); + + // Update source + exec(commandObjects.set(srcKey, "newValue")); + + // Copy again without replace, it will fail + Boolean secondCopy = exec(commandObjects.copy(srcKey.getBytes(), dstKey.getBytes(), dstDB, false)); + assertThat(secondCopy, equalTo(false)); + + assertKeyExists(dstDB, dstKey, "initialValue"); + } + + private void assertKeyExists(int dstDb, String key, Object expectedValue) { + // Cheat and use Jedis, it gives us access to any db. + try (Jedis jedis = new Jedis(nodeInfo)) { + jedis.auth("foobared"); + jedis.select(dstDb); + assertThat(jedis.get(key), equalTo(expectedValue)); + } + } + +} diff --git a/src/test/java/redis/clients/jedis/commands/commandobjects/CommandObjectsGeospatialCommandsTest.java b/src/test/java/redis/clients/jedis/commands/commandobjects/CommandObjectsGeospatialCommandsTest.java new file mode 100644 index 00000000000..bcdcd540921 --- /dev/null +++ b/src/test/java/redis/clients/jedis/commands/commandobjects/CommandObjectsGeospatialCommandsTest.java @@ -0,0 +1,701 @@ +package redis.clients.jedis.commands.commandobjects; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.closeTo; +import static org.hamcrest.Matchers.contains; +import static org.hamcrest.Matchers.containsInAnyOrder; +import static org.hamcrest.Matchers.empty; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.notNullValue; +import static org.hamcrest.Matchers.nullValue; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +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.GeoAddParams; +import redis.clients.jedis.params.GeoRadiusParam; +import redis.clients.jedis.params.GeoRadiusStoreParam; +import redis.clients.jedis.params.GeoSearchParam; +import redis.clients.jedis.resps.GeoRadiusResponse; + +/** + * Tests related to Geospatial commands. + */ +public class CommandObjectsGeospatialCommandsTest extends CommandObjectsStandaloneTestBase { + + // Some coordinates for testing + public static final String CATANIA = "Catania"; + public static final double CATANIA_LATITUDE = 37.502669; + public static final double CATANIA_LONGITUDE = 15.087269; + + public static final String PALERMO = "Palermo"; + public static final double PALERMO_LONGITUDE = 13.361389; + public static final double PALERMO_LATITUDE = 38.115556; + + public static final String SYRACUSE = "Syracuse"; + public static final double SYRACUSE_LONGITUDE = 15.293331; + public static final double SYRACUSE_LATITUDE = 37.075474; + + public static final String AGRIGENTO = "Agrigento"; + public static final double AGRIGENTO_LONGITUDE = 13.583333; + public static final double AGRIGENTO_LATITUDE = 37.316667; + + public CommandObjectsGeospatialCommandsTest(RedisProtocol protocol) { + super(protocol); + } + + @Test + public void testGeoAddAndRadius() { + String key = "locations"; + + Map cataniaCoordinates = new HashMap<>(); + cataniaCoordinates.put(CATANIA, new GeoCoordinate(CATANIA_LONGITUDE, CATANIA_LATITUDE)); + + Map syracuseCoordinates = new HashMap<>(); + syracuseCoordinates.put(SYRACUSE, new GeoCoordinate(SYRACUSE_LONGITUDE, SYRACUSE_LATITUDE)); + + Long addPalermo = exec(commandObjects.geoadd(key, PALERMO_LONGITUDE, PALERMO_LATITUDE, PALERMO)); + assertThat(addPalermo, equalTo(1L)); + + List radiusFromPalermo = exec(commandObjects.georadius( + key, PALERMO_LONGITUDE, PALERMO_LATITUDE, 100, GeoUnit.KM)); + assertThat(radiusFromPalermo.stream().map(GeoRadiusResponse::getMemberByString).collect(Collectors.toList()), + contains(equalTo(PALERMO))); + + Long addCatania = exec(commandObjects.geoadd(key, cataniaCoordinates)); + assertThat(addCatania, equalTo(1L)); + + List radiusFromCatania = exec(commandObjects.georadius( + key, CATANIA_LONGITUDE, CATANIA_LATITUDE, 100, GeoUnit.KM)); + assertThat(radiusFromCatania.stream().map(GeoRadiusResponse::getMemberByString).collect(Collectors.toList()), + contains(equalTo(CATANIA))); + + Long addSyracuse = exec(commandObjects.geoadd(key, GeoAddParams.geoAddParams().nx(), syracuseCoordinates)); + assertThat(addSyracuse, equalTo(1L)); + + List radiusEverything = exec(commandObjects.georadius( + key, 15, 37, 200, GeoUnit.KM)); + assertThat(radiusEverything.stream().map(GeoRadiusResponse::getMemberByString).collect(Collectors.toList()), + containsInAnyOrder(equalTo(CATANIA), equalTo(SYRACUSE), equalTo(PALERMO))); + } + + @Test + public void testGeoAddAndRadiusBinary() { + byte[] key = "locations".getBytes(); + + Map cataniaCoordinates = new HashMap<>(); + cataniaCoordinates.put(CATANIA.getBytes(), new GeoCoordinate(CATANIA_LONGITUDE, CATANIA_LATITUDE)); + + Map syracuseCoordinates = new HashMap<>(); + syracuseCoordinates.put(SYRACUSE.getBytes(), new GeoCoordinate(SYRACUSE_LONGITUDE, SYRACUSE_LATITUDE)); + + Long addPalermo = exec(commandObjects.geoadd(key, PALERMO_LONGITUDE, PALERMO_LATITUDE, PALERMO.getBytes())); + assertThat(addPalermo, equalTo(1L)); + + List radiusFromPalermo = exec(commandObjects.georadius( + key, PALERMO_LONGITUDE, PALERMO_LATITUDE, 100, GeoUnit.KM)); + assertThat(radiusFromPalermo.stream().map(GeoRadiusResponse::getMember).collect(Collectors.toList()), + contains(equalTo(PALERMO.getBytes()))); + + Long addCatania = exec(commandObjects.geoadd(key, cataniaCoordinates)); + assertThat(addCatania, equalTo(1L)); + + List radiusFromCatania = exec(commandObjects.georadius( + key, CATANIA_LONGITUDE, CATANIA_LATITUDE, 100, GeoUnit.KM)); + assertThat(radiusFromCatania.stream().map(GeoRadiusResponse::getMember).collect(Collectors.toList()), + contains(equalTo(CATANIA.getBytes()))); + + Long addSyracuse = exec(commandObjects.geoadd(key, GeoAddParams.geoAddParams().nx(), syracuseCoordinates)); + assertThat(addSyracuse, equalTo(1L)); + + List radiusEverything = exec(commandObjects.georadius( + key, 15, 37, 200, GeoUnit.KM)); + assertThat(radiusEverything.stream().map(GeoRadiusResponse::getMember).collect(Collectors.toList()), + containsInAnyOrder(equalTo(CATANIA.getBytes()), equalTo(PALERMO.getBytes()), equalTo(SYRACUSE.getBytes()))); + } + + @Test + public void testGeoDist() { + String key = "locations"; + byte[] binaryKey = key.getBytes(); + + // Add locations to calculate distance + exec(commandObjects.geoadd(key, CATANIA_LONGITUDE, CATANIA_LATITUDE, CATANIA)); + exec(commandObjects.geoadd(key, PALERMO_LONGITUDE, PALERMO_LATITUDE, PALERMO)); + + Double distance = exec(commandObjects.geodist(key, CATANIA, PALERMO)); + // This is in meters, we don't try to accurately assert it. We refer to it later. + assertThat(distance, notNullValue()); + + Double distanceWithUnit = exec(commandObjects.geodist(key, CATANIA, PALERMO, GeoUnit.KM)); + assertThat(distanceWithUnit, closeTo(distance / 1000, 0.001)); + + Double binaryDistance = exec(commandObjects.geodist(binaryKey, CATANIA.getBytes(), PALERMO.getBytes())); + assertThat(binaryDistance, closeTo(distance, 0.001)); + + Double binaryDistanceWithUnit = exec(commandObjects.geodist(binaryKey, CATANIA.getBytes(), PALERMO.getBytes(), GeoUnit.KM)); + assertThat(binaryDistanceWithUnit, closeTo(distance / 1000, 0.001)); + } + + @Test + public void testGeoHash() { + String key = "locations"; + byte[] binaryKey = key.getBytes(); + + exec(commandObjects.geoadd(key, CATANIA_LONGITUDE, CATANIA_LATITUDE, CATANIA)); + exec(commandObjects.geoadd(key, PALERMO_LONGITUDE, PALERMO_LATITUDE, PALERMO)); + + List hashes = exec(commandObjects.geohash(key, CATANIA, PALERMO)); + assertThat(hashes, contains(notNullValue(), notNullValue())); + + List binaryHashes = exec(commandObjects.geohash(binaryKey, CATANIA.getBytes(), PALERMO.getBytes())); + assertThat(binaryHashes, contains(hashes.get(0).getBytes(), hashes.get(1).getBytes())); + } + + @Test + public void testGeoPos() { + String key = "locations"; + byte[] binaryKey = key.getBytes(); + + exec(commandObjects.geoadd(key, CATANIA_LONGITUDE, CATANIA_LATITUDE, CATANIA)); + exec(commandObjects.geoadd(key, PALERMO_LONGITUDE, PALERMO_LATITUDE, PALERMO)); + + List positions = exec(commandObjects.geopos(key, CATANIA, PALERMO)); + assertThat(positions.size(), equalTo(2)); + + assertThat(positions.get(0), notNullValue()); + assertThat(positions.get(0).getLongitude(), closeTo(CATANIA_LONGITUDE, 0.001)); + assertThat(positions.get(0).getLatitude(), closeTo(CATANIA_LATITUDE, 0.001)); + + assertThat(positions.get(1), notNullValue()); + assertThat(positions.get(1).getLongitude(), closeTo(PALERMO_LONGITUDE, 0.001)); + assertThat(positions.get(1).getLatitude(), closeTo(PALERMO_LATITUDE, 0.001)); + + List binaryPositions = exec(commandObjects.geopos(binaryKey, CATANIA.getBytes(), PALERMO.getBytes())); + assertThat(binaryPositions.size(), equalTo(2)); + + assertThat(binaryPositions.get(0), notNullValue()); + assertThat(binaryPositions.get(0).getLongitude(), closeTo(CATANIA_LONGITUDE, 0.001)); + assertThat(binaryPositions.get(0).getLatitude(), closeTo(CATANIA_LATITUDE, 0.001)); + + assertThat(binaryPositions.get(1), notNullValue()); + assertThat(binaryPositions.get(1).getLongitude(), closeTo(PALERMO_LONGITUDE, 0.001)); + assertThat(binaryPositions.get(1).getLatitude(), closeTo(PALERMO_LATITUDE, 0.001)); + } + + @Test + public void testGeoRadius() { + String key = "locations"; + byte[] binaryKey = key.getBytes(); + + GeoRadiusParam param = GeoRadiusParam.geoRadiusParam().withCoord().withDist(); + + exec(commandObjects.geoadd(key, CATANIA_LONGITUDE, CATANIA_LATITUDE, CATANIA)); + exec(commandObjects.geoadd(key, PALERMO_LONGITUDE, PALERMO_LATITUDE, PALERMO)); + + List responses = exec(commandObjects.georadius(key, CATANIA_LONGITUDE, CATANIA_LATITUDE, 200, GeoUnit.KM)); + + // we got distances, but no coordinates + assertThat(responses.stream().map(GeoRadiusResponse::getMemberByString).collect(Collectors.toList()), + containsInAnyOrder(CATANIA, PALERMO)); + assertThat(responses.stream().map(GeoRadiusResponse::getDistance).collect(Collectors.toList()), + containsInAnyOrder(notNullValue(), notNullValue())); + assertThat(responses.stream().map(GeoRadiusResponse::getCoordinate).collect(Collectors.toList()), + containsInAnyOrder(nullValue(), nullValue())); + + List responsesWithParam = exec(commandObjects.georadius(key, CATANIA_LONGITUDE, CATANIA_LATITUDE, 200, GeoUnit.KM, param)); + + // we got distances, and coordinates + assertThat(responsesWithParam.stream().map(GeoRadiusResponse::getMemberByString).collect(Collectors.toList()), + containsInAnyOrder(CATANIA, PALERMO)); + assertThat(responsesWithParam.stream().map(GeoRadiusResponse::getDistance).collect(Collectors.toList()), + containsInAnyOrder(notNullValue(), notNullValue())); + assertThat(responsesWithParam.stream().map(GeoRadiusResponse::getCoordinate).collect(Collectors.toList()), + containsInAnyOrder(notNullValue(), notNullValue())); + assertThat(responsesWithParam.stream().map(GeoRadiusResponse::getCoordinate).map(GeoCoordinate::getLatitude).collect(Collectors.toList()), + containsInAnyOrder(closeTo(PALERMO_LATITUDE, 0.001), closeTo(CATANIA_LATITUDE, 0.001))); + assertThat(responsesWithParam.stream().map(GeoRadiusResponse::getCoordinate).map(GeoCoordinate::getLongitude).collect(Collectors.toList()), + containsInAnyOrder(closeTo(PALERMO_LONGITUDE, 0.001), closeTo(CATANIA_LONGITUDE, 0.001))); + + List binaryResponses = exec(commandObjects.georadius(binaryKey, CATANIA_LONGITUDE, CATANIA_LATITUDE, 200, GeoUnit.KM)); + + // distances, but no coordinates + assertThat(binaryResponses.stream().map(GeoRadiusResponse::getMemberByString).collect(Collectors.toList()), + containsInAnyOrder(CATANIA, PALERMO)); + assertThat(binaryResponses.stream().map(GeoRadiusResponse::getDistance).collect(Collectors.toList()), + containsInAnyOrder(notNullValue(), notNullValue())); + assertThat(binaryResponses.stream().map(GeoRadiusResponse::getCoordinate).collect(Collectors.toList()), + containsInAnyOrder(nullValue(), nullValue())); + + List binaryResponsesWithParam = exec(commandObjects.georadius(binaryKey, CATANIA_LONGITUDE, CATANIA_LATITUDE, 200, GeoUnit.KM, param)); + + // distances, and coordinates + assertThat(binaryResponsesWithParam.stream().map(GeoRadiusResponse::getMember).collect(Collectors.toList()), + containsInAnyOrder(CATANIA.getBytes(), PALERMO.getBytes())); + assertThat(binaryResponsesWithParam.stream().map(GeoRadiusResponse::getDistance).collect(Collectors.toList()), + containsInAnyOrder(notNullValue(), notNullValue())); + assertThat(binaryResponsesWithParam.stream().map(GeoRadiusResponse::getCoordinate).collect(Collectors.toList()), + containsInAnyOrder(notNullValue(), notNullValue())); + assertThat(binaryResponsesWithParam.stream().map(GeoRadiusResponse::getCoordinate).map(GeoCoordinate::getLatitude).collect(Collectors.toList()), + containsInAnyOrder(closeTo(PALERMO_LATITUDE, 0.001), closeTo(CATANIA_LATITUDE, 0.001))); + assertThat(binaryResponsesWithParam.stream().map(GeoRadiusResponse::getCoordinate).map(GeoCoordinate::getLongitude).collect(Collectors.toList()), + containsInAnyOrder(closeTo(PALERMO_LONGITUDE, 0.001), closeTo(CATANIA_LONGITUDE, 0.001))); + } + + @Test + public void testGeoRadiusReadonly() { + String key = "locations"; + byte[] binaryKey = key.getBytes(); + + GeoRadiusParam param = GeoRadiusParam.geoRadiusParam().withCoord().withDist(); + + exec(commandObjects.geoadd(key, CATANIA_LONGITUDE, CATANIA_LATITUDE, CATANIA)); + exec(commandObjects.geoadd(key, PALERMO_LONGITUDE, PALERMO_LATITUDE, PALERMO)); + + List responses = exec(commandObjects.georadiusReadonly(key, CATANIA_LONGITUDE, CATANIA_LATITUDE, 200, GeoUnit.KM)); + + // we got distances, but no coordinates + assertThat(responses.stream().map(GeoRadiusResponse::getMemberByString).collect(Collectors.toList()), + containsInAnyOrder(CATANIA, PALERMO)); + assertThat(responses.stream().map(GeoRadiusResponse::getDistance).collect(Collectors.toList()), + containsInAnyOrder(notNullValue(), notNullValue())); + assertThat(responses.stream().map(GeoRadiusResponse::getCoordinate).collect(Collectors.toList()), + containsInAnyOrder(nullValue(), nullValue())); + + List responsesWithParam = exec(commandObjects.georadiusReadonly(key, CATANIA_LONGITUDE, CATANIA_LATITUDE, 200, GeoUnit.KM, param)); + + // we got distances, and coordinates + assertThat(responsesWithParam.stream().map(GeoRadiusResponse::getMemberByString).collect(Collectors.toList()), + containsInAnyOrder(CATANIA, PALERMO)); + assertThat(responsesWithParam.stream().map(GeoRadiusResponse::getDistance).collect(Collectors.toList()), + containsInAnyOrder(notNullValue(), notNullValue())); + assertThat(responsesWithParam.stream().map(GeoRadiusResponse::getCoordinate).collect(Collectors.toList()), + containsInAnyOrder(notNullValue(), notNullValue())); + assertThat(responsesWithParam.stream().map(GeoRadiusResponse::getCoordinate).map(GeoCoordinate::getLatitude).collect(Collectors.toList()), + containsInAnyOrder(closeTo(PALERMO_LATITUDE, 0.001), closeTo(CATANIA_LATITUDE, 0.001))); + assertThat(responsesWithParam.stream().map(GeoRadiusResponse::getCoordinate).map(GeoCoordinate::getLongitude).collect(Collectors.toList()), + containsInAnyOrder(closeTo(PALERMO_LONGITUDE, 0.001), closeTo(CATANIA_LONGITUDE, 0.001))); + + List binaryResponses = exec(commandObjects.georadiusReadonly(binaryKey, CATANIA_LONGITUDE, CATANIA_LATITUDE, 200, GeoUnit.KM)); + + // distances, but no coordinates + assertThat(binaryResponses.stream().map(GeoRadiusResponse::getMemberByString).collect(Collectors.toList()), + containsInAnyOrder(CATANIA, PALERMO)); + assertThat(binaryResponses.stream().map(GeoRadiusResponse::getDistance).collect(Collectors.toList()), + containsInAnyOrder(notNullValue(), notNullValue())); + assertThat(binaryResponses.stream().map(GeoRadiusResponse::getCoordinate).collect(Collectors.toList()), + containsInAnyOrder(nullValue(), nullValue())); + + List binaryResponsesWithParam = exec(commandObjects.georadiusReadonly(binaryKey, CATANIA_LONGITUDE, CATANIA_LATITUDE, 200, GeoUnit.KM, param)); + + // distances, and coordinates + assertThat(binaryResponsesWithParam.stream().map(GeoRadiusResponse::getMember).collect(Collectors.toList()), + containsInAnyOrder(CATANIA.getBytes(), PALERMO.getBytes())); + assertThat(binaryResponsesWithParam.stream().map(GeoRadiusResponse::getDistance).collect(Collectors.toList()), + containsInAnyOrder(notNullValue(), notNullValue())); + assertThat(binaryResponsesWithParam.stream().map(GeoRadiusResponse::getCoordinate).collect(Collectors.toList()), + containsInAnyOrder(notNullValue(), notNullValue())); + assertThat(binaryResponsesWithParam.stream().map(GeoRadiusResponse::getCoordinate).map(GeoCoordinate::getLatitude).collect(Collectors.toList()), + containsInAnyOrder(closeTo(PALERMO_LATITUDE, 0.001), closeTo(CATANIA_LATITUDE, 0.001))); + assertThat(binaryResponsesWithParam.stream().map(GeoRadiusResponse::getCoordinate).map(GeoCoordinate::getLongitude).collect(Collectors.toList()), + containsInAnyOrder(closeTo(PALERMO_LONGITUDE, 0.001), closeTo(CATANIA_LONGITUDE, 0.001))); + } + + @Test + public void testGeoRadiusByMember() { + String key = "locations"; + byte[] binaryKey = key.getBytes(); + + GeoRadiusParam param = GeoRadiusParam.geoRadiusParam().withCoord().withDist(); + + exec(commandObjects.geoadd(key, CATANIA_LONGITUDE, CATANIA_LATITUDE, CATANIA)); + exec(commandObjects.geoadd(key, PALERMO_LONGITUDE, PALERMO_LATITUDE, PALERMO)); + exec(commandObjects.geoadd(key, AGRIGENTO_LONGITUDE, AGRIGENTO_LATITUDE, AGRIGENTO)); + + List responses = exec(commandObjects.georadiusByMember(key, AGRIGENTO, 100, GeoUnit.KM)); + + assertThat(responses.stream().map(GeoRadiusResponse::getMemberByString).collect(Collectors.toList()), + containsInAnyOrder(AGRIGENTO, PALERMO)); + assertThat(responses.stream().map(GeoRadiusResponse::getDistance).collect(Collectors.toList()), + containsInAnyOrder(notNullValue(), notNullValue())); + assertThat(responses.stream().map(GeoRadiusResponse::getCoordinate).collect(Collectors.toList()), + containsInAnyOrder(nullValue(), nullValue())); + + List responsesWithParam = exec(commandObjects.georadiusByMember(key, AGRIGENTO, 100, GeoUnit.KM, param)); + + assertThat(responsesWithParam.stream().map(GeoRadiusResponse::getMemberByString).collect(Collectors.toList()), + containsInAnyOrder(AGRIGENTO, PALERMO)); + assertThat(responsesWithParam.stream().map(GeoRadiusResponse::getDistance).collect(Collectors.toList()), + containsInAnyOrder(notNullValue(), notNullValue())); + assertThat(responsesWithParam.stream().map(GeoRadiusResponse::getCoordinate).collect(Collectors.toList()), + containsInAnyOrder(notNullValue(), notNullValue())); + assertThat(responsesWithParam.stream().map(GeoRadiusResponse::getCoordinate).map(GeoCoordinate::getLatitude).collect(Collectors.toList()), + containsInAnyOrder(closeTo(PALERMO_LATITUDE, 0.001), closeTo(AGRIGENTO_LATITUDE, 0.001))); + assertThat(responsesWithParam.stream().map(GeoRadiusResponse::getCoordinate).map(GeoCoordinate::getLongitude).collect(Collectors.toList()), + containsInAnyOrder(closeTo(PALERMO_LONGITUDE, 0.001), closeTo(AGRIGENTO_LONGITUDE, 0.001))); + + List binaryResponses = exec(commandObjects.georadiusByMember(binaryKey, AGRIGENTO.getBytes(), 100, GeoUnit.KM)); + + assertThat(binaryResponses.stream().map(GeoRadiusResponse::getMemberByString).collect(Collectors.toList()), + containsInAnyOrder(AGRIGENTO, PALERMO)); + assertThat(binaryResponses.stream().map(GeoRadiusResponse::getDistance).collect(Collectors.toList()), + containsInAnyOrder(notNullValue(), notNullValue())); + assertThat(binaryResponses.stream().map(GeoRadiusResponse::getCoordinate).collect(Collectors.toList()), + containsInAnyOrder(nullValue(), nullValue())); + + List binaryResponsesWithParam = exec(commandObjects.georadiusByMember(binaryKey, AGRIGENTO.getBytes(), 100, GeoUnit.KM, param)); + + assertThat(binaryResponsesWithParam.stream().map(GeoRadiusResponse::getMember).collect(Collectors.toList()), + containsInAnyOrder(AGRIGENTO.getBytes(), PALERMO.getBytes())); + assertThat(binaryResponsesWithParam.stream().map(GeoRadiusResponse::getDistance).collect(Collectors.toList()), + containsInAnyOrder(notNullValue(), notNullValue())); + assertThat(binaryResponsesWithParam.stream().map(GeoRadiusResponse::getCoordinate).collect(Collectors.toList()), + containsInAnyOrder(notNullValue(), notNullValue())); + assertThat(binaryResponsesWithParam.stream().map(GeoRadiusResponse::getCoordinate).map(GeoCoordinate::getLatitude).collect(Collectors.toList()), + containsInAnyOrder(closeTo(PALERMO_LATITUDE, 0.001), closeTo(AGRIGENTO_LATITUDE, 0.001))); + assertThat(binaryResponsesWithParam.stream().map(GeoRadiusResponse::getCoordinate).map(GeoCoordinate::getLongitude).collect(Collectors.toList()), + containsInAnyOrder(closeTo(PALERMO_LONGITUDE, 0.001), closeTo(AGRIGENTO_LONGITUDE, 0.001))); + } + + @Test + public void testGeoRadiusByMemberReadonly() { + String key = "locations"; + byte[] binaryKey = key.getBytes(); + + GeoRadiusParam param = GeoRadiusParam.geoRadiusParam().withCoord().withDist(); + + exec(commandObjects.geoadd(key, CATANIA_LONGITUDE, CATANIA_LATITUDE, CATANIA)); + exec(commandObjects.geoadd(key, PALERMO_LONGITUDE, PALERMO_LATITUDE, PALERMO)); + exec(commandObjects.geoadd(key, AGRIGENTO_LONGITUDE, AGRIGENTO_LATITUDE, AGRIGENTO)); + + List responses = exec(commandObjects.georadiusByMemberReadonly(key, AGRIGENTO, 100, GeoUnit.KM)); + + assertThat(responses.stream().map(GeoRadiusResponse::getMemberByString).collect(Collectors.toList()), + containsInAnyOrder(AGRIGENTO, PALERMO)); + assertThat(responses.stream().map(GeoRadiusResponse::getDistance).collect(Collectors.toList()), + containsInAnyOrder(notNullValue(), notNullValue())); + assertThat(responses.stream().map(GeoRadiusResponse::getCoordinate).collect(Collectors.toList()), + containsInAnyOrder(nullValue(), nullValue())); + + List responsesWithParam = exec(commandObjects.georadiusByMemberReadonly(key, AGRIGENTO, 100, GeoUnit.KM, param)); + + assertThat(responsesWithParam.stream().map(GeoRadiusResponse::getMemberByString).collect(Collectors.toList()), + containsInAnyOrder(AGRIGENTO, PALERMO)); + assertThat(responsesWithParam.stream().map(GeoRadiusResponse::getDistance).collect(Collectors.toList()), + containsInAnyOrder(notNullValue(), notNullValue())); + assertThat(responsesWithParam.stream().map(GeoRadiusResponse::getCoordinate).collect(Collectors.toList()), + containsInAnyOrder(notNullValue(), notNullValue())); + assertThat(responsesWithParam.stream().map(GeoRadiusResponse::getCoordinate).map(GeoCoordinate::getLatitude).collect(Collectors.toList()), + containsInAnyOrder(closeTo(PALERMO_LATITUDE, 0.001), closeTo(AGRIGENTO_LATITUDE, 0.001))); + assertThat(responsesWithParam.stream().map(GeoRadiusResponse::getCoordinate).map(GeoCoordinate::getLongitude).collect(Collectors.toList()), + containsInAnyOrder(closeTo(PALERMO_LONGITUDE, 0.001), closeTo(AGRIGENTO_LONGITUDE, 0.001))); + + List binaryResponses = exec(commandObjects.georadiusByMemberReadonly(binaryKey, AGRIGENTO.getBytes(), 100, GeoUnit.KM)); + + assertThat(binaryResponses.stream().map(GeoRadiusResponse::getMemberByString).collect(Collectors.toList()), + containsInAnyOrder(AGRIGENTO, PALERMO)); + assertThat(binaryResponses.stream().map(GeoRadiusResponse::getDistance).collect(Collectors.toList()), + containsInAnyOrder(notNullValue(), notNullValue())); + assertThat(binaryResponses.stream().map(GeoRadiusResponse::getCoordinate).collect(Collectors.toList()), + containsInAnyOrder(nullValue(), nullValue())); + + List binaryResponsesWithParam = exec(commandObjects.georadiusByMemberReadonly(binaryKey, AGRIGENTO.getBytes(), 100, GeoUnit.KM, param)); + + assertThat(binaryResponsesWithParam.stream().map(GeoRadiusResponse::getMember).collect(Collectors.toList()), + containsInAnyOrder(AGRIGENTO.getBytes(), PALERMO.getBytes())); + assertThat(binaryResponsesWithParam.stream().map(GeoRadiusResponse::getDistance).collect(Collectors.toList()), + containsInAnyOrder(notNullValue(), notNullValue())); + assertThat(binaryResponsesWithParam.stream().map(GeoRadiusResponse::getCoordinate).collect(Collectors.toList()), + containsInAnyOrder(notNullValue(), notNullValue())); + assertThat(binaryResponsesWithParam.stream().map(GeoRadiusResponse::getCoordinate).map(GeoCoordinate::getLatitude).collect(Collectors.toList()), + containsInAnyOrder(closeTo(PALERMO_LATITUDE, 0.001), closeTo(AGRIGENTO_LATITUDE, 0.001))); + assertThat(binaryResponsesWithParam.stream().map(GeoRadiusResponse::getCoordinate).map(GeoCoordinate::getLongitude).collect(Collectors.toList()), + containsInAnyOrder(closeTo(PALERMO_LONGITUDE, 0.001), closeTo(AGRIGENTO_LONGITUDE, 0.001))); + } + + @Test + public void testGeoradiusStore() { + String key = "locations"; + byte[] binaryKey = key.getBytes(); + + String destinationKey = "result"; + String binaryDestinationKey = "resultBinary"; + + GeoRadiusParam param = GeoRadiusParam.geoRadiusParam().sortAscending(); + + exec(commandObjects.geoadd(key, PALERMO_LONGITUDE, PALERMO_LATITUDE, PALERMO)); + exec(commandObjects.geoadd(key, CATANIA_LONGITUDE, CATANIA_LATITUDE, CATANIA)); + + GeoRadiusStoreParam storeParam = GeoRadiusStoreParam.geoRadiusStoreParam().store(destinationKey); + + Long store = exec(commandObjects.georadiusStore(key, PALERMO_LONGITUDE, PALERMO_LATITUDE, 200, GeoUnit.KM, param, storeParam)); + assertThat(store, equalTo(2L)); + + List destination = exec(commandObjects.zrange(destinationKey, 0, -1)); + assertThat(destination, containsInAnyOrder(PALERMO, CATANIA)); + + GeoRadiusStoreParam storeParamForBinary = GeoRadiusStoreParam.geoRadiusStoreParam().store(binaryDestinationKey); + + Long storeBinary = exec(commandObjects.georadiusStore(binaryKey, PALERMO_LONGITUDE, PALERMO_LATITUDE, 200, GeoUnit.KM, param, storeParamForBinary)); + assertThat(storeBinary, equalTo(2L)); + + destination = exec(commandObjects.zrange(binaryDestinationKey, 0, -1)); + assertThat(destination, containsInAnyOrder(PALERMO, CATANIA)); + } + + @Test + public void testGeoradiusByMemberStore() { + String key = "locations"; + byte[] binaryKey = key.getBytes(); + + String destinationKey = "result"; + String binaryDestinationKey = "resultBinary"; + + GeoRadiusParam param = GeoRadiusParam.geoRadiusParam().sortAscending(); + + exec(commandObjects.geoadd(key, PALERMO_LONGITUDE, PALERMO_LATITUDE, PALERMO)); + exec(commandObjects.geoadd(key, CATANIA_LONGITUDE, CATANIA_LATITUDE, CATANIA)); + + GeoRadiusStoreParam storeParam = GeoRadiusStoreParam.geoRadiusStoreParam().store(destinationKey); + + Long store = exec(commandObjects.georadiusByMemberStore(key, PALERMO, 200, GeoUnit.KM, param, storeParam)); + assertThat(store, equalTo(2L)); + + List storedResults = exec(commandObjects.zrange(destinationKey, 0, -1)); + assertThat(storedResults, containsInAnyOrder(PALERMO, CATANIA)); + + GeoRadiusStoreParam storeParamForBinary = GeoRadiusStoreParam.geoRadiusStoreParam().store(binaryDestinationKey); + + Long storeBinary = exec(commandObjects.georadiusByMemberStore(binaryKey, PALERMO.getBytes(), 200, GeoUnit.KM, param, storeParamForBinary)); + assertThat(storeBinary, equalTo(2L)); + + storedResults = exec(commandObjects.zrange(binaryDestinationKey, 0, -1)); + assertThat(storedResults, containsInAnyOrder(PALERMO, CATANIA)); + } + + @Test + public void testGeosearch() { + String key = "locations"; + + GeoCoordinate palermoCoord = new GeoCoordinate(PALERMO_LONGITUDE, PALERMO_LATITUDE); + + exec(commandObjects.geoadd(key, PALERMO_LONGITUDE, PALERMO_LATITUDE, PALERMO)); + exec(commandObjects.geoadd(key, CATANIA_LONGITUDE, CATANIA_LATITUDE, CATANIA)); + + List resultsByMember = exec(commandObjects.geosearch(key, PALERMO, 200, GeoUnit.KM)); + + assertThat(resultsByMember.stream().map(GeoRadiusResponse::getMemberByString).collect(Collectors.toList()), + containsInAnyOrder(PALERMO, CATANIA)); + + List resultsByCoord = exec(commandObjects.geosearch(key, palermoCoord, 200, GeoUnit.KM)); + + assertThat(resultsByCoord.stream().map(GeoRadiusResponse::getMemberByString).collect(Collectors.toList()), + containsInAnyOrder(PALERMO, CATANIA)); + + List resultsByMemberBox = exec(commandObjects.geosearch(key, PALERMO, 200, 200, GeoUnit.KM)); + + assertThat(resultsByMemberBox.stream().map(GeoRadiusResponse::getMemberByString).collect(Collectors.toList()), + containsInAnyOrder(PALERMO)); + + List resultsByCoordBox = exec(commandObjects.geosearch(key, palermoCoord, 200, 200, GeoUnit.KM)); + + assertThat(resultsByCoordBox.stream().map(GeoRadiusResponse::getMemberByString).collect(Collectors.toList()), + containsInAnyOrder(PALERMO)); + + GeoSearchParam params = GeoSearchParam.geoSearchParam() + .byRadius(200, GeoUnit.KM).withCoord().withDist().fromMember(PALERMO); + + List resultsWithParams = exec(commandObjects.geosearch(key, params)); + + assertThat(resultsWithParams.stream().map(GeoRadiusResponse::getMemberByString).collect(Collectors.toList()), + containsInAnyOrder(PALERMO, CATANIA)); + + List resultsInvalidKey = exec(commandObjects.geosearch("invalidKey", PALERMO, 100, GeoUnit.KM)); + + assertThat(resultsInvalidKey, empty()); + } + + @Test + public void testGeosearchBinary() { + byte[] key = "locations".getBytes(); + + GeoCoordinate palermoCoord = new GeoCoordinate(PALERMO_LONGITUDE, PALERMO_LATITUDE); + + exec(commandObjects.geoadd(key, PALERMO_LONGITUDE, PALERMO_LATITUDE, PALERMO.getBytes())); + exec(commandObjects.geoadd(key, CATANIA_LONGITUDE, CATANIA_LATITUDE, CATANIA.getBytes())); + + List resultsByMember = exec(commandObjects.geosearch(key, PALERMO.getBytes(), 200, GeoUnit.KM)); + + assertThat(resultsByMember.stream().map(GeoRadiusResponse::getMemberByString).collect(Collectors.toList()), + containsInAnyOrder(PALERMO, CATANIA)); + + List resultsByCoord = exec(commandObjects.geosearch(key, palermoCoord, 200, GeoUnit.KM)); + + assertThat(resultsByCoord.stream().map(GeoRadiusResponse::getMemberByString).collect(Collectors.toList()), + containsInAnyOrder(PALERMO, CATANIA)); + + List resultsByMemberBox = exec(commandObjects.geosearch(key, PALERMO.getBytes(), 200, 200, GeoUnit.KM)); + + assertThat(resultsByMemberBox.stream().map(GeoRadiusResponse::getMemberByString).collect(Collectors.toList()), + containsInAnyOrder(PALERMO)); + + List resultsByCoordBox = exec(commandObjects.geosearch(key, palermoCoord, 200, 200, GeoUnit.KM)); + + assertThat(resultsByCoordBox.stream().map(GeoRadiusResponse::getMemberByString).collect(Collectors.toList()), + containsInAnyOrder(PALERMO)); + + GeoSearchParam params = GeoSearchParam.geoSearchParam() + .byRadius(200, GeoUnit.KM).withCoord().withDist().fromMember(PALERMO); + + List resultsWithParams = exec(commandObjects.geosearch(key, params)); + + assertThat(resultsWithParams.stream().map(GeoRadiusResponse::getMemberByString).collect(Collectors.toList()), + containsInAnyOrder(PALERMO, CATANIA)); + + List resultsInvalidKey = exec(commandObjects.geosearch("invalidKey".getBytes(), PALERMO.getBytes(), 100, GeoUnit.KM)); + + assertThat(resultsInvalidKey, empty()); + } + + @Test + public void testGeosearchStore() { + String srcKey = "locations"; + String destKey = "locationsStore"; + + GeoCoordinate palermoCoord = new GeoCoordinate(PALERMO_LONGITUDE, PALERMO_LATITUDE); + + exec(commandObjects.geoadd(srcKey, PALERMO_LONGITUDE, PALERMO_LATITUDE, PALERMO)); + exec(commandObjects.geoadd(srcKey, CATANIA_LONGITUDE, CATANIA_LATITUDE, CATANIA)); + + Long storeByMember = exec(commandObjects.geosearchStore(destKey, srcKey, PALERMO, 200, GeoUnit.KM)); + assertThat(storeByMember, equalTo(2L)); + + List storedResultsByMember = exec(commandObjects.zrange(destKey, 0, -1)); + assertThat(storedResultsByMember, containsInAnyOrder(PALERMO, CATANIA)); + + // Reset + exec(commandObjects.del(destKey)); + + Long storeByCoord = exec(commandObjects.geosearchStore(destKey, srcKey, palermoCoord, 200, GeoUnit.KM)); + assertThat(storeByCoord, equalTo(2L)); + + List storedResultsByCoord = exec(commandObjects.zrange(destKey, 0, -1)); + assertThat(storedResultsByCoord, containsInAnyOrder(PALERMO, CATANIA)); + + exec(commandObjects.del(destKey)); + + Long storeByMemberBox = exec(commandObjects.geosearchStore(destKey, srcKey, PALERMO, 200, 200, GeoUnit.KM)); + assertThat(storeByMemberBox, equalTo(1L)); + + List storedResultsByMemberBox = exec(commandObjects.zrange(destKey, 0, -1)); + assertThat(storedResultsByMemberBox, containsInAnyOrder(PALERMO)); + + exec(commandObjects.del(destKey)); + + Long storeByCoordBox = exec(commandObjects.geosearchStore(destKey, srcKey, palermoCoord, 200, 200, GeoUnit.KM)); + assertThat(storeByCoordBox, equalTo(1L)); + + List storedResultsByCoordBox = exec(commandObjects.zrange(destKey, 0, -1)); + assertThat(storedResultsByCoordBox, containsInAnyOrder(PALERMO)); + + exec(commandObjects.del(destKey)); + + GeoSearchParam params = GeoSearchParam.geoSearchParam() + .byRadius(200, GeoUnit.KM).fromMember(PALERMO); + + Long storeWithParams = exec(commandObjects.geosearchStore(destKey, srcKey, params)); + assertThat(storeWithParams, equalTo(2L)); + + List storedResultsWithParams = exec(commandObjects.zrange(destKey, 0, -1)); + assertThat(storedResultsWithParams, containsInAnyOrder(PALERMO, CATANIA)); + } + + @Test + public void testGeosearchStoreBinary() { + byte[] srcKey = "locations".getBytes(); + byte[] destKey = "locationsStore".getBytes(); + + GeoCoordinate palermoCoord = new GeoCoordinate(PALERMO_LONGITUDE, PALERMO_LATITUDE); + + exec(commandObjects.geoadd(srcKey, PALERMO_LONGITUDE, PALERMO_LATITUDE, PALERMO.getBytes())); + exec(commandObjects.geoadd(srcKey, CATANIA_LONGITUDE, CATANIA_LATITUDE, CATANIA.getBytes())); + + Long storeByMember = exec(commandObjects.geosearchStore(destKey, srcKey, PALERMO.getBytes(), 200, GeoUnit.KM)); + assertThat(storeByMember, equalTo(2L)); + + List storedResultsByMember = exec(commandObjects.zrange(destKey, 0, -1)); + assertThat(storedResultsByMember, containsInAnyOrder(PALERMO.getBytes(), CATANIA.getBytes())); + + // Reset + exec(commandObjects.del(destKey)); + + Long storeByCoord = exec(commandObjects.geosearchStore(destKey, srcKey, palermoCoord, 200, GeoUnit.KM)); + assertThat(storeByCoord, equalTo(2L)); + + List storedResultsByCoord = exec(commandObjects.zrange(destKey, 0, -1)); + assertThat(storedResultsByCoord, containsInAnyOrder(PALERMO.getBytes(), CATANIA.getBytes())); + + exec(commandObjects.del(destKey)); + + Long storeByMemberBox = exec(commandObjects.geosearchStore(destKey, srcKey, PALERMO.getBytes(), 200, 200, GeoUnit.KM)); + assertThat(storeByMemberBox, equalTo(1L)); + + List storedResultsByMemberBox = exec(commandObjects.zrange(destKey, 0, -1)); + assertThat(storedResultsByMemberBox, containsInAnyOrder(PALERMO.getBytes())); + + exec(commandObjects.del(destKey)); + + Long storeByCoordBox = exec(commandObjects.geosearchStore(destKey, srcKey, palermoCoord, 200, 200, GeoUnit.KM)); + assertThat(storeByCoordBox, equalTo(1L)); + + List storedResultsByCoordBox = exec(commandObjects.zrange(destKey, 0, -1)); + assertThat(storedResultsByCoordBox, containsInAnyOrder(PALERMO.getBytes())); + + exec(commandObjects.del(destKey)); + + GeoSearchParam params = GeoSearchParam.geoSearchParam() + .byRadius(200, GeoUnit.KM).fromMember(PALERMO); + + Long storeWithParams = exec(commandObjects.geosearchStore(destKey, srcKey, params)); + assertThat(storeWithParams, equalTo(2L)); + + List storedResultsWithParams = exec(commandObjects.zrange(destKey, 0, -1)); + assertThat(storedResultsWithParams, containsInAnyOrder(PALERMO.getBytes(), CATANIA.getBytes())); + } + + @Test + public void testGeosearchStoreStoreDist() { + String srcKey = "locations"; + byte[] srcKeyBytes = srcKey.getBytes(); + + String destKey = "resultKey"; + byte[] destKeyBytes = destKey.getBytes(); + + exec(commandObjects.geoadd(srcKey, PALERMO_LONGITUDE, PALERMO_LATITUDE, PALERMO)); + exec(commandObjects.geoadd(srcKey, CATANIA_LONGITUDE, CATANIA_LATITUDE, CATANIA)); + exec(commandObjects.geoadd(srcKey, SYRACUSE_LONGITUDE, SYRACUSE_LATITUDE, SYRACUSE)); + + GeoSearchParam params = new GeoSearchParam() + .byRadius(100, GeoUnit.KM).fromLonLat(15, 37); + + Long store = exec(commandObjects.geosearchStoreStoreDist(destKey, srcKey, params)); + assertThat(store, equalTo(2L)); + + List dstContent = exec(commandObjects.zrange(destKey, 0, -1)); + assertThat(dstContent, containsInAnyOrder(CATANIA, SYRACUSE)); + + exec(commandObjects.del(destKey)); + + Long storeWithBytes = exec(commandObjects.geosearchStoreStoreDist(destKeyBytes, srcKeyBytes, params)); + assertThat(storeWithBytes, equalTo(2L)); + + List dstContentWithBytes = exec(commandObjects.zrange(destKeyBytes, 0, -1)); + assertThat(dstContentWithBytes, containsInAnyOrder(CATANIA.getBytes(), SYRACUSE.getBytes())); + } +} diff --git a/src/test/java/redis/clients/jedis/commands/commandobjects/CommandObjectsHashCommandsTest.java b/src/test/java/redis/clients/jedis/commands/commandobjects/CommandObjectsHashCommandsTest.java new file mode 100644 index 00000000000..b025b854408 --- /dev/null +++ b/src/test/java/redis/clients/jedis/commands/commandobjects/CommandObjectsHashCommandsTest.java @@ -0,0 +1,405 @@ +package redis.clients.jedis.commands.commandobjects; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.allOf; +import static org.hamcrest.Matchers.anyOf; +import static org.hamcrest.Matchers.contains; +import static org.hamcrest.Matchers.containsInAnyOrder; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.everyItem; +import static org.hamcrest.Matchers.hasEntry; +import static org.hamcrest.Matchers.hasSize; +import static org.hamcrest.Matchers.lessThanOrEqualTo; +import static org.hamcrest.Matchers.nullValue; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import org.junit.Test; +import redis.clients.jedis.RedisProtocol; +import redis.clients.jedis.params.ScanParams; +import redis.clients.jedis.resps.ScanResult; + +/** + * Tests related to Hash commands. + */ +public class CommandObjectsHashCommandsTest extends CommandObjectsStandaloneTestBase { + + public CommandObjectsHashCommandsTest(RedisProtocol protocol) { + super(protocol); + } + + @Test + public void testHashSetGet() { + String key = "hashKey"; + String field = "name"; + String value = "John"; + + String getInitial = exec(commandObjects.hget(key, field)); + assertThat(getInitial, nullValue()); + + Long set = exec(commandObjects.hset(key, field, value)); + assertThat(set, equalTo(1L)); + + String get = exec(commandObjects.hget(key, field)); + assertThat(get, equalTo(value)); + } + + @Test + public void testHashSetGetBinary() { + byte[] key = "hashKeyBytes".getBytes(); + byte[] field = "field".getBytes(); + byte[] value = "value".getBytes(); + + byte[] getInitial = exec(commandObjects.hget(key, field)); + assertThat(getInitial, nullValue()); + + Long set = exec(commandObjects.hset(key, field, value)); + assertThat(set, equalTo(1L)); + + byte[] get = exec(commandObjects.hget(key, field)); + assertThat(get, equalTo(value)); + } + + @Test + public void testHashBulkSet() { + String key = "hashKey"; + + Map hash = new HashMap<>(); + hash.put("field1", "value1"); + hash.put("field2", "value2"); + + Long set = exec(commandObjects.hset(key, hash)); + assertThat(set, equalTo((long) hash.size())); + + List mget = exec(commandObjects.hmget(key, "field1", "field2")); + assertThat(mget, contains("value1", "value2")); + } + + @Test + public void testHashBulkSetBinary() { + byte[] key = "hashKey".getBytes(); + + Map hash = new HashMap<>(); + hash.put("field1".getBytes(), "value1".getBytes()); + hash.put("field2".getBytes(), "value2".getBytes()); + + Long set = exec(commandObjects.hset(key, hash)); + assertThat(set, equalTo((long) hash.size())); + + List mget = exec(commandObjects.hmget(key, "field1".getBytes(), "field2".getBytes())); + assertThat(mget, contains("value1".getBytes(), "value2".getBytes())); + } + + @Test + public void testHashMsetMget() { + String key = "bulkHashKey"; + + Map hash = new HashMap<>(); + hash.put("field1", "value1"); + hash.put("field2", "value2"); + + String mset = exec(commandObjects.hmset(key, hash)); + assertThat(mset, equalTo("OK")); + + List mget = exec(commandObjects.hmget(key, "field1", "field2")); + assertThat(mget, contains("value1", "value2")); + } + + @Test + public void testHashMsetMgetBinary() { + byte[] key = "hashKey".getBytes(); + + Map hash = new HashMap<>(); + hash.put("field1".getBytes(), "value1".getBytes()); + hash.put("field2".getBytes(), "value2".getBytes()); + + String mset = exec(commandObjects.hmset(key, hash)); + assertThat(mset, equalTo("OK")); + + List mget = exec(commandObjects.hmget(key, "field1".getBytes(), "field2".getBytes())); + assertThat(mget, contains("value1".getBytes(), "value2".getBytes())); + } + + @Test + public void testHsetnx() { + String key = "hashKey"; + String field = "field"; + String value = "value"; + + String initialGet = exec(commandObjects.hget(key, field)); + assertThat(initialGet, nullValue()); + + Long initialSet = exec(commandObjects.hsetnx(key, field, value)); + assertThat(initialSet, equalTo(1L)); + + String get = exec(commandObjects.hget(key, field)); + assertThat(get, equalTo(value)); + + Long secondSet = exec(commandObjects.hsetnx(key, field, "newValue")); + assertThat(secondSet, equalTo(0L)); + + String secondGet = exec(commandObjects.hget(key, field)); + assertThat(secondGet, equalTo(value)); + } + + @Test + public void testHsetnxBinary() { + byte[] key = "hashKey".getBytes(); + byte[] field = "field".getBytes(); + byte[] value = "value".getBytes(); + + byte[] initialGet = exec(commandObjects.hget(key, field)); + assertThat(initialGet, nullValue()); + + Long set = exec(commandObjects.hsetnx(key, field, value)); + assertThat(set, equalTo(1L)); + + byte[] get = exec(commandObjects.hget(key, field)); + assertThat(get, equalTo(value)); + + Long secondSet = exec(commandObjects.hsetnx(key, field, "newValue".getBytes())); + assertThat(secondSet, equalTo(0L)); + + byte[] secondGet = exec(commandObjects.hget(key, field)); + assertThat(secondGet, equalTo(value)); + } + + @Test + public void testHincrBy() { + String key = "incrementHashKey"; + String field = "incrementField"; + + Long initialSet = exec(commandObjects.hset(key, field, "0")); + assertThat(initialSet, equalTo(1L)); + + String initialGet = exec(commandObjects.hget(key, field)); + assertThat(initialGet, equalTo("0")); + + Long incrByLong = exec(commandObjects.hincrBy(key, field, 10L)); + assertThat(incrByLong, equalTo(10L)); + + String getAfterIncrByLong = exec(commandObjects.hget(key, field)); + assertThat(getAfterIncrByLong, equalTo("10")); + + Double incrByFloat = exec(commandObjects.hincrByFloat(key, field, 2.5)); + assertThat(incrByFloat, equalTo(12.5)); + + String getAfterIncrByFloat = exec(commandObjects.hget(key, field)); + assertThat(getAfterIncrByFloat, equalTo("12.5")); + } + + @Test + public void testHincrByBinary() { + byte[] key = "key".getBytes(); + byte[] field = "field".getBytes(); + + Long initialSet = exec(commandObjects.hset(key, field, "0".getBytes())); + assertThat(initialSet, equalTo(1L)); + + byte[] initialGet = exec(commandObjects.hget(key, field)); + assertThat(initialGet, equalTo("0".getBytes())); + + Long incrByLong = exec(commandObjects.hincrBy(key, field, 10L)); + assertThat(incrByLong, equalTo(10L)); + + byte[] getAfterIncrByLong = exec(commandObjects.hget(key, field)); + assertThat(getAfterIncrByLong, equalTo("10".getBytes())); + + Double incrByDouble = exec(commandObjects.hincrByFloat(key, field, 2.5)); + assertThat(incrByDouble, equalTo(12.5)); + + byte[] getAfterIncrByDouble = exec(commandObjects.hget(key, field)); + assertThat(getAfterIncrByDouble, equalTo("12.5".getBytes())); + } + + @Test + public void testHashExistsDel() { + String key = "key"; + String field1 = "field1"; + String field2 = "field2"; + String value = "value"; + + exec(commandObjects.hset(key, field1, value)); + exec(commandObjects.hset(key, field2, value)); + + Boolean exists = exec(commandObjects.hexists(key, field1)); + assertThat(exists, equalTo(true)); + + Long len = exec(commandObjects.hlen(key)); + assertThat(len, equalTo(2L)); + + Long del = exec(commandObjects.hdel(key, field1)); + assertThat(del, equalTo(1L)); + + Boolean existsAfterDel = exec(commandObjects.hexists(key, field1)); + assertThat(existsAfterDel, equalTo(false)); + + Long lenAfterDel = exec(commandObjects.hlen(key)); + assertThat(lenAfterDel, equalTo(1L)); + } + + @Test + public void testHashExistsDelBinary() { + byte[] key = "key".getBytes(); + byte[] field1 = "field1".getBytes(); + byte[] field2 = "field2".getBytes(); + byte[] value = "value".getBytes(); + + exec(commandObjects.hset(key, field1, value)); + exec(commandObjects.hset(key, field2, value)); + + Boolean exists = exec(commandObjects.hexists(key, field1)); + assertThat(exists, equalTo(true)); + + Long len = exec(commandObjects.hlen(key)); + assertThat(len, equalTo(2L)); + + Long del = exec(commandObjects.hdel(key, field1)); + assertThat(del, equalTo(1L)); + + Boolean existsAfterDel = exec(commandObjects.hexists(key, field1)); + assertThat(existsAfterDel, equalTo(false)); + + Long lenAfterDel = exec(commandObjects.hlen(key)); + assertThat(lenAfterDel, equalTo(1L)); + } + + @Test + public void testHashKeysValsGetAll() { + String key = "hashKey"; + byte[] keyBinary = key.getBytes(); + + String field1 = "field1"; + String field2 = "field2"; + String value1 = "value1"; + String value2 = "value2"; + + exec(commandObjects.hset(key, field1, value1)); + exec(commandObjects.hset(key, field2, value2)); + + Set keys = exec(commandObjects.hkeys(key)); + assertThat(keys, containsInAnyOrder(field1, field2)); + + List values = exec(commandObjects.hvals(key)); + assertThat(values, containsInAnyOrder(value1, value2)); + + Map hash = exec(commandObjects.hgetAll(key)); + assertThat(hash, allOf( + hasEntry(field1, value1), + hasEntry(field2, value2))); + + // binary + Set keysBinary = exec(commandObjects.hkeys(keyBinary)); + assertThat(keysBinary, containsInAnyOrder(field1.getBytes(), field2.getBytes())); + + List valuesBinary = exec(commandObjects.hvals(keyBinary)); + assertThat(valuesBinary, containsInAnyOrder(value1.getBytes(), value2.getBytes())); + + Map hashBinary = exec(commandObjects.hgetAll(keyBinary)); + assertThat(hashBinary, allOf( + hasEntry(field1.getBytes(), value1.getBytes()), + hasEntry(field2.getBytes(), value2.getBytes()))); + } + + @Test + public void testHashRandfield() { + String key = "testHash"; + byte[] bkey = key.getBytes(); + + exec(commandObjects.hset(key, "field1", "value1")); + exec(commandObjects.hset(key, "field2", "value2")); + + String singleField = exec(commandObjects.hrandfield(key)); + assertThat(singleField, anyOf(equalTo("field1"), equalTo("field2"))); + + List fields = exec(commandObjects.hrandfield(key, 2)); + assertThat(fields, containsInAnyOrder("field1", "field2")); + + List> fieldsWithValues = exec(commandObjects.hrandfieldWithValues(key, 2)); + + assertThat(fieldsWithValues, hasSize(2)); + fieldsWithValues.forEach(entry -> + assertThat(entry.getValue(), anyOf(equalTo("value1"), equalTo("value2")))); + + // binary + byte[] singleFieldBinary = exec(commandObjects.hrandfield(bkey)); + assertThat(singleFieldBinary, anyOf(equalTo("field1".getBytes()), equalTo("field2".getBytes()))); + + List fieldsBinary = exec(commandObjects.hrandfield(bkey, 2)); + assertThat(fieldsBinary, containsInAnyOrder("field1".getBytes(), "field2".getBytes())); + + List> fieldsWithValuesBinary = exec(commandObjects.hrandfieldWithValues(bkey, 2)); + + assertThat(fieldsWithValuesBinary, hasSize(2)); + fieldsWithValuesBinary.forEach(entry -> + assertThat(entry.getValue(), anyOf(equalTo("value1".getBytes()), equalTo("value2".getBytes())))); + } + + @Test + public void testHscan() { + String key = "testHashScan"; + byte[] bkey = key.getBytes(); + + exec(commandObjects.hset(key, "field1", "value1")); + exec(commandObjects.hset(key, "field2", "value2")); + + ScanParams params = new ScanParams().count(2); + + ScanResult> scanResult = exec(commandObjects.hscan(key, ScanParams.SCAN_POINTER_START, params)); + + assertThat(scanResult.getResult(), hasSize(lessThanOrEqualTo(2))); + + scanResult.getResult().forEach(entry -> + assertThat(entry.getKey(), anyOf(equalTo("field1"), equalTo("field2")))); + scanResult.getResult().forEach(entry -> + assertThat(entry.getValue(), anyOf(equalTo("value1"), equalTo("value2")))); + + ScanResult scanResultNoValues = exec(commandObjects.hscanNoValues(key, ScanParams.SCAN_POINTER_START, params)); + + assertThat(scanResultNoValues.getResult(), hasSize(lessThanOrEqualTo(2))); + + assertThat(scanResultNoValues.getResult(), + everyItem(anyOf(equalTo("field1"), equalTo("field2")))); + + // binary + ScanResult> bscanResult = exec(commandObjects.hscan(bkey, ScanParams.SCAN_POINTER_START_BINARY, params)); + + assertThat(bscanResult.getResult(), hasSize(lessThanOrEqualTo(2))); + + bscanResult.getResult().forEach(entry -> + assertThat(entry.getKey(), anyOf(equalTo("field1".getBytes()), equalTo("field2".getBytes())))); + bscanResult.getResult().forEach(entry -> + assertThat(entry.getValue(), anyOf(equalTo("value1".getBytes()), equalTo("value2".getBytes())))); + + ScanResult bscanResultNoValues = exec(commandObjects.hscanNoValues(bkey, ScanParams.SCAN_POINTER_START_BINARY, params)); + + assertThat(bscanResultNoValues.getResult(), hasSize(lessThanOrEqualTo(2))); + + assertThat(bscanResultNoValues.getResult(), + everyItem(anyOf(equalTo("field1".getBytes()), equalTo("field2".getBytes())))); + } + + @Test + public void testHashStrlen() { + String key = "testHashStrlen"; + byte[] bkey = key.getBytes(); + + exec(commandObjects.hset(key, "field1", "value1")); + + Long strlen = exec(commandObjects.hstrlen(key, "field1")); + assertThat(strlen, equalTo(6L)); + + Long strlenNonExistingField = exec(commandObjects.hstrlen(key, "nonExistingField")); + assertThat(strlenNonExistingField, equalTo(0L)); + + // binary + Long strlenBinary = exec(commandObjects.hstrlen(bkey, "field1".getBytes())); + assertThat(strlenBinary, equalTo(6L)); + + Long strlenNonExistingFieldBinary = exec(commandObjects.hstrlen(bkey, "nonExistingField".getBytes())); + assertThat(strlenNonExistingFieldBinary, equalTo(0L)); + } +} diff --git a/src/test/java/redis/clients/jedis/commands/commandobjects/CommandObjectsHyperloglogCommandsTest.java b/src/test/java/redis/clients/jedis/commands/commandobjects/CommandObjectsHyperloglogCommandsTest.java new file mode 100644 index 00000000000..cdfe5aa7bd7 --- /dev/null +++ b/src/test/java/redis/clients/jedis/commands/commandobjects/CommandObjectsHyperloglogCommandsTest.java @@ -0,0 +1,94 @@ +package redis.clients.jedis.commands.commandobjects; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.greaterThan; +import static org.hamcrest.Matchers.greaterThanOrEqualTo; + +import org.junit.Test; +import redis.clients.jedis.RedisProtocol; + +/** + * Tests related to HyperLogLog commands. + */ +public class CommandObjectsHyperloglogCommandsTest extends CommandObjectsStandaloneTestBase { + + public CommandObjectsHyperloglogCommandsTest(RedisProtocol protocol) { + super(protocol); + } + + @Test + public void testPfaddAndCount() { + String key = "hyperloglogKey"; + + Long add = exec(commandObjects.pfadd(key, "element1", "element2", "element3")); + assertThat(add, equalTo(1L)); + + Long count = exec(commandObjects.pfcount(key)); + assertThat(count, greaterThanOrEqualTo(3L)); // approximate, expect at least 3 + + Long addNewElement = exec(commandObjects.pfadd(key, "element4")); + assertThat(addNewElement, equalTo(1L)); + + Long countWithNewElement = exec(commandObjects.pfcount(key)); + assertThat(countWithNewElement, greaterThan(count)); + } + + @Test + public void testPfaddAndCountBinary() { + byte[] key = "hyperloglogKey".getBytes(); + + Long add = exec(commandObjects.pfadd(key, "element1".getBytes(), "element2".getBytes(), "element3".getBytes())); + assertThat(add, equalTo(1L)); + + Long count = exec(commandObjects.pfcount(key)); + assertThat(count, greaterThanOrEqualTo(3L)); + } + + @Test + public void testPfmerge() { + String key1 = "hyperloglog1"; + String key2 = "hyperloglog2"; + + exec(commandObjects.pfadd(key1, "elementA", "elementB")); + exec(commandObjects.pfadd(key2, "elementC", "elementD")); + + String destKey = "mergedHyperloglog"; + byte[] destKeyBytes = "mergedHyperloglogBytes".getBytes(); + + String mergeResultWithString = exec(commandObjects.pfmerge(destKey, key1, key2)); + assertThat(mergeResultWithString, equalTo("OK")); + + Long countAfterMergeWithString = exec(commandObjects.pfcount(destKey)); + assertThat(countAfterMergeWithString, greaterThanOrEqualTo(4L)); + + // binary + String mergeResultWithBytes = exec(commandObjects.pfmerge(destKeyBytes, key1.getBytes(), key2.getBytes())); + assertThat(mergeResultWithBytes, equalTo("OK")); + + Long countAfterMergeWithBytes = exec(commandObjects.pfcount(destKeyBytes)); + assertThat(countAfterMergeWithBytes, greaterThanOrEqualTo(4L)); + } + + @Test + public void testPfcount() { + String key1 = "hyperloglogCount1"; + String key2 = "hyperloglogCount2"; + + exec(commandObjects.pfadd(key1, "element1", "element2", "element3")); + exec(commandObjects.pfadd(key2, "element4", "element5", "element6")); + + Long countForKey1 = exec(commandObjects.pfcount(key1)); + assertThat(countForKey1, greaterThanOrEqualTo(3L)); + + Long countForBothKeys = exec(commandObjects.pfcount(key1, key2)); + assertThat(countForBothKeys, greaterThanOrEqualTo(6L)); + + // binary + Long countForKey1Binary = exec(commandObjects.pfcount(key1.getBytes())); + assertThat(countForKey1Binary, greaterThanOrEqualTo(3L)); + + Long countForBothKeysBinary = exec(commandObjects.pfcount(key1.getBytes(), key2.getBytes())); + assertThat(countForBothKeysBinary, greaterThanOrEqualTo(6L)); + } +} diff --git a/src/test/java/redis/clients/jedis/commands/commandobjects/CommandObjectsJsonCommandsTest.java b/src/test/java/redis/clients/jedis/commands/commandobjects/CommandObjectsJsonCommandsTest.java new file mode 100644 index 00000000000..a416be21039 --- /dev/null +++ b/src/test/java/redis/clients/jedis/commands/commandobjects/CommandObjectsJsonCommandsTest.java @@ -0,0 +1,1434 @@ +package redis.clients.jedis.commands.commandobjects; + +import static net.javacrumbs.jsonunit.JsonMatchers.jsonEquals; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.contains; +import static org.hamcrest.Matchers.containsInAnyOrder; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.greaterThan; +import static org.hamcrest.Matchers.hasEntry; +import static org.hamcrest.Matchers.instanceOf; +import static org.hamcrest.Matchers.not; +import static org.hamcrest.Matchers.notNullValue; +import static org.hamcrest.Matchers.nullValue; +import static org.junit.Assume.assumeThat; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.json.JSONArray; +import org.json.JSONObject; +import org.junit.Test; +import redis.clients.jedis.RedisProtocol; +import redis.clients.jedis.json.JsonSetParams; +import redis.clients.jedis.json.Path; +import redis.clients.jedis.json.Path2; + +/** + * Tests related to JSON commands. + */ +public class CommandObjectsJsonCommandsTest extends CommandObjectsModulesTestBase { + + public CommandObjectsJsonCommandsTest(RedisProtocol protocol) { + super(protocol); + } + + @Test + public void testJsonSetAndJsonGet() { + String key = "jsonKey"; + + JSONObject person = new JSONObject(); + person.put("name", "John Doe"); + person.put("age", 30); + + String setRoot = exec(commandObjects.jsonSet(key, Path2.ROOT_PATH, person)); + assertThat(setRoot, equalTo("OK")); + + Object getRoot = exec(commandObjects.jsonGet(key, Path2.ROOT_PATH)); + assertThat(getRoot, jsonEquals(new JSONArray().put(person))); + + JSONObject details = new JSONObject(); + details.put("city", "New York"); + + String setDeep = exec(commandObjects.jsonSet(key, new Path2("$.details"), details)); + assertThat(setDeep, equalTo("OK")); + + Object getDeep = exec(commandObjects.jsonGet(key, new Path2("$.details"))); + assertThat(getDeep, jsonEquals(new JSONArray().put(details))); + + Object getFull = exec(commandObjects.jsonGet(key, Path2.ROOT_PATH)); + + person.put("details", details); + assertThat(getFull, jsonEquals(new JSONArray().put(person))); + } + + @Test + public void testJsonSetWithEscape() { + String key = "jsonKey"; + + Map book = new HashMap<>(); + book.put("title", "Learning JSON"); + + String setRoot = exec(commandObjects.jsonSetWithEscape(key, Path2.ROOT_PATH, book)); + assertThat(setRoot, equalTo("OK")); + + Object getRoot = exec(commandObjects.jsonGet(key, Path2.ROOT_PATH)); + + JSONArray expected = new JSONArray().put(new JSONObject(book)); + assertThat(getRoot, jsonEquals(expected)); + } + + @Test + @Deprecated + public void testJsonSetJsonGetOldPath() { + String key = "jsonKey"; + + Map book = new HashMap<>(); + book.put("author", "Jane Doe"); + book.put("title", "Advanced JSON Techniques"); + + String setRoot = exec(commandObjects.jsonSet(key, Path.ROOT_PATH, book)); + assertThat(setRoot, equalTo("OK")); + + Object getRoot = exec(commandObjects.jsonGet(key, Path.ROOT_PATH)); + assertThat(getRoot, instanceOf(Map.class)); + + @SuppressWarnings("unchecked") + Map getRootMap = (Map) getRoot; + assertThat(getRootMap, hasEntry("author", "Jane Doe")); + assertThat(getRootMap, hasEntry("title", "Advanced JSON Techniques")); + } + + @Test + @Deprecated + public void testJsonSetWithPlainString() { + String key = "jsonKey"; + String jsonString = "{\"name\":\"John\"}"; + + String setRoot = exec(commandObjects.jsonSetWithPlainString(key, Path.ROOT_PATH, jsonString)); + assertThat(setRoot, equalTo("OK")); + + Object getRoot = exec(commandObjects.jsonGet(key, Path.ROOT_PATH)); + assertThat(getRoot, instanceOf(Map.class)); + + @SuppressWarnings("unchecked") + Map getRootMap = (Map) getRoot; + assertThat(getRootMap, hasEntry("name", "John")); + } + + @Test + public void testJsonSetWithParams() { + String key = "jsonKey"; + + JSONObject book = new JSONObject(); + book.put("author", "Jane Doe"); + book.put("title", "Advanced JSON Techniques"); + + JsonSetParams params = new JsonSetParams().nx(); + + String setRoot = exec(commandObjects.jsonSet(key, Path2.ROOT_PATH, book, params)); + assertThat(setRoot, equalTo("OK")); + + Object getRoot = exec(commandObjects.jsonGet(key, Path2.ROOT_PATH)); + + JSONArray expected = new JSONArray().put(book); + assertThat(getRoot, jsonEquals(expected)); + } + + @Test + public void testJsonSetWithEscapeAndParams() { + String key = "jsonKey"; + + Map book = new HashMap<>(); + book.put("author", "John Smith"); + book.put("title", "JSON Escaping 101"); + + JsonSetParams params = new JsonSetParams().nx(); + + String setRoot = exec(commandObjects.jsonSetWithEscape(key, Path2.ROOT_PATH, book, params)); + assertThat(setRoot, equalTo("OK")); + + Object getRoot = exec(commandObjects.jsonGet(key, Path2.ROOT_PATH)); + + JSONArray expected = new JSONArray().put(new JSONObject(book)); + assertThat(getRoot, jsonEquals(expected)); + } + + @Test + @Deprecated + public void testJsonSetOldPathWithParams() { + String key = "jsonKey"; + + Map user = new HashMap<>(); + user.put("username", "johndoe"); + user.put("accountType", "premium"); + + JsonSetParams params = new JsonSetParams().nx(); + + String setRoot = exec(commandObjects.jsonSet(key, Path.ROOT_PATH, user, params)); + assertThat(setRoot, equalTo("OK")); + + Object getRoot = exec(commandObjects.jsonGet(key, Path.ROOT_PATH)); + assertThat(getRoot, instanceOf(Map.class)); + + @SuppressWarnings("unchecked") + Map readResultMap = (Map) getRoot; + assertThat(readResultMap, hasEntry("username", "johndoe")); + assertThat(readResultMap, hasEntry("accountType", "premium")); + } + + @Test + public void testJsonMerge() { + String key = "jsonKey"; + + JSONObject initialUser = new JSONObject(); + initialUser.put("name", "John Doe"); + initialUser.put("age", 30); + + exec(commandObjects.jsonSet(key, Path2.ROOT_PATH, initialUser)); + + JSONObject mergeUser = new JSONObject(); + mergeUser.put("occupation", "Software Developer"); + mergeUser.put("age", 31); // Assuming we're updating the age as well + + String mergeRoot = exec(commandObjects.jsonMerge(key, Path2.ROOT_PATH, mergeUser)); + assertThat(mergeRoot, equalTo("OK")); + + Object getRoot = exec(commandObjects.jsonGet(key, Path2.ROOT_PATH)); + assertThat(getRoot, notNullValue()); + + JSONObject expectedUser = new JSONObject(); + expectedUser.put("name", "John Doe"); + expectedUser.put("age", 31); + expectedUser.put("occupation", "Software Developer"); + + JSONArray expected = new JSONArray().put(expectedUser); + assertThat(getRoot, jsonEquals(expected)); + } + + @Test + @Deprecated + public void testJsonMergeOldPath() { + String key = "jsonKey"; + + Map initialUser = new HashMap<>(); + initialUser.put("name", "Jane Doe"); + + exec(commandObjects.jsonSet(key, Path.ROOT_PATH, initialUser)); + + Map mergeUser = new HashMap<>(); + mergeUser.put("occupation", "Data Scientist"); + mergeUser.put("name", "Jane Smith"); // update the name as well + + String mergeRoot = exec(commandObjects.jsonMerge(key, Path.ROOT_PATH, mergeUser)); + assertThat(mergeRoot, equalTo("OK")); + + Object getRoot = exec(commandObjects.jsonGet(key, Path.ROOT_PATH)); + assertThat(getRoot, instanceOf(Map.class)); + + @SuppressWarnings("unchecked") + Map resultMap = (Map) getRoot; + assertThat(resultMap, hasEntry("name", "Jane Smith")); + assertThat(resultMap, hasEntry("occupation", "Data Scientist")); + } + + @Test + @Deprecated + public void testJsonGenericObjectResp2() { + assumeThat(protocol, not(equalTo(RedisProtocol.RESP3))); + + String key = "user:1000"; + + Person person = new Person(); + person.setName("John Doe"); + person.setAge(30); + + String setRoot = exec(commandObjects.jsonSet(key, Path.ROOT_PATH, person)); + assertThat(setRoot, equalTo("OK")); + + Object getRoot = exec(commandObjects.jsonGet(key)); + assertThat(getRoot, instanceOf(Map.class)); + + @SuppressWarnings("unchecked") + Map resultMap = (Map) getRoot; + assertThat(resultMap, hasEntry("name", "John Doe")); + assertThat(resultMap, hasEntry("age", 30.0)); + } + + @Test + @Deprecated + public void testJsonGenericObjectResp3() { + assumeThat(protocol, equalTo(RedisProtocol.RESP3)); + + String key = "user:1000"; + + Person person = new Person("John Doe", 30); + + String setResult = exec(commandObjects.jsonSet(key, Path.ROOT_PATH, person)); + assertThat(setResult, equalTo("OK")); + + Object getRoot = exec(commandObjects.jsonGet(key)); + assertThat(getRoot, instanceOf(JSONArray.class)); + + JSONObject expectedPerson = new JSONObject(); + expectedPerson.put("name", "John Doe"); + expectedPerson.put("age", 30); + + JSONArray expected = new JSONArray().put(expectedPerson); + assertThat(getRoot, jsonEquals(expected)); + } + + @Test + @Deprecated + public void testJsonGetWithClass() { + assumeThat(protocol, not(equalTo(RedisProtocol.RESP3))); + + String key = "user:2000"; + + String jsonObject = "{\"name\":\"Jane Doe\",\"age\":25}"; + + exec(commandObjects.jsonSetWithPlainString(key, Path.ROOT_PATH, jsonObject)); + + Person getRoot = exec(commandObjects.jsonGet(key, Person.class)); + + assertThat(getRoot.getName(), equalTo("Jane Doe")); + assertThat(getRoot.getAge(), equalTo(25)); + } + + @Test + public void testJsonMGet() { + String keyBob = "user:bob"; + String keyCharlie = "user:charlie"; + + JSONObject bob = new JSONObject(); + bob.put("name", "Bob"); + bob.put("age", 30); + + JSONObject charlie = new JSONObject(); + charlie.put("name", "Charlie"); + charlie.put("age", 25); + + String setBobRoot = exec(commandObjects.jsonSet(keyBob, Path2.ROOT_PATH, bob)); + assertThat(setBobRoot, equalTo("OK")); + + String setCharlieRoot = exec(commandObjects.jsonSet(keyCharlie, Path2.ROOT_PATH, charlie)); + assertThat(setCharlieRoot, equalTo("OK")); + + List getNames = exec(commandObjects.jsonMGet(Path2.of("name"), keyBob, keyCharlie)); + assertThat(getNames, contains( + jsonEquals(new JSONArray().put("Bob")), + jsonEquals(new JSONArray().put("Charlie")) + )); + + List getRoots = exec(commandObjects.jsonMGet(Path2.ROOT_PATH, keyBob, keyCharlie)); + assertThat(getRoots, contains( + jsonEquals(new JSONArray().put(bob)), + jsonEquals(new JSONArray().put(charlie)) + )); + } + + @Test + @Deprecated + public void testJsonMGetOldPath() { + String keyBob = "user:bob"; + String keyCharlie = "user:charlie"; + + JSONObject bob = new JSONObject(); + bob.put("name", "Bob"); + bob.put("age", 30); + + JSONObject charlie = new JSONObject(); + charlie.put("name", "Charlie"); + charlie.put("age", 25); + + String setBobRoot = exec(commandObjects.jsonSet(keyBob, Path2.ROOT_PATH, bob)); + assertThat(setBobRoot, equalTo("OK")); + + String setCharlieRoot = exec(commandObjects.jsonSet(keyCharlie, Path2.ROOT_PATH, charlie)); + assertThat(setCharlieRoot, equalTo("OK")); + + List getNamesTyped = exec(commandObjects.jsonMGet(Path.of("name"), String.class, keyBob, keyCharlie)); + assertThat(getNamesTyped, contains("Bob", "Charlie")); + + List getPersonsTyped = exec(commandObjects.jsonMGet(Path.ROOT_PATH, Person.class, keyBob, keyCharlie)); + assertThat(getPersonsTyped, contains( + new Person("Bob", 30), + new Person("Charlie", 25) + )); + } + + @Test + @Deprecated + public void testJsonGetAsPlainString() { + String key = "user:3000"; + + Person person = new Person("John Smith", 30); + + exec(commandObjects.jsonSet(key, Path.ROOT_PATH, person)); + + String getName = exec(commandObjects.jsonGetAsPlainString(key, Path.of(".name"))); + assertThat(getName, equalTo("\"John Smith\"")); + + String getRoot = exec(commandObjects.jsonGetAsPlainString(key, Path.ROOT_PATH)); + assertThat(getRoot, jsonEquals(person)); + } + + @Test + @Deprecated + public void testJsonGetWithPathAndClass() { + String key = "user:4000"; + + String jsonObject = "{\"person\":{\"name\":\"Alice Johnson\",\"age\":28}}"; + + String setRoot = exec(commandObjects.jsonSetWithPlainString(key, Path.ROOT_PATH, jsonObject)); + assertThat(setRoot, equalTo("OK")); + + Person getPerson = exec(commandObjects.jsonGet(key, Person.class, Path.of(".person"))); + assertThat(getPerson.getName(), equalTo("Alice Johnson")); + assertThat(getPerson.getAge(), equalTo(28)); + } + + @Test + public void testJsonDel() { + String key = "user:11000"; + + JSONObject person = new JSONObject(); + person.put("name", "Gina"); + person.put("age", 29); + + exec(commandObjects.jsonSet(key, Path2.ROOT_PATH, person)); + + Object preCheck = exec(commandObjects.jsonGet(key, Path2.ROOT_PATH)); + assertThat(preCheck, jsonEquals(new JSONArray().put(person))); + + Long del = exec(commandObjects.jsonDel(key)); + assertThat(del, equalTo(1L)); + + Object postCheck = exec(commandObjects.jsonGet(key, Path2.ROOT_PATH)); + assertThat(postCheck, nullValue()); + } + + @Test + public void testJsonDelPath() { + String key = "user:11000"; + + JSONObject person = new JSONObject(); + person.put("name", "Gina"); + person.put("age", 29); + + exec(commandObjects.jsonSet(key, Path2.ROOT_PATH, person)); + + Object preCheck = exec(commandObjects.jsonGet(key, Path2.ROOT_PATH)); + assertThat(preCheck, jsonEquals(new JSONArray().put(person))); + + Long delAge = exec(commandObjects.jsonDel(key, Path2.of(".age"))); + assertThat(delAge, equalTo(1L)); + + Object postCheck = exec(commandObjects.jsonGet(key, Path2.ROOT_PATH)); + + JSONObject expected = new JSONObject(); + expected.put("name", "Gina"); + assertThat(postCheck, jsonEquals(new JSONArray().put(expected))); + } + + @Test + @Deprecated + public void testJsonDelOldPath() { + String key = "user:11000"; + + JSONObject person = new JSONObject(); + person.put("name", "Gina"); + person.put("age", 29); + + exec(commandObjects.jsonSet(key, Path2.ROOT_PATH, person)); + + Object preCheck = exec(commandObjects.jsonGet(key, Path2.ROOT_PATH)); + assertThat(preCheck, jsonEquals(new JSONArray().put(person))); + + Long delAge = exec(commandObjects.jsonDel(key, Path.of(".age"))); + assertThat(delAge, equalTo(1L)); + + Object postCheck = exec(commandObjects.jsonGet(key, Path2.ROOT_PATH)); + + JSONObject expected = new JSONObject(); + expected.put("name", "Gina"); + assertThat(postCheck, jsonEquals(new JSONArray().put(expected))); + } + + @Test + public void testJsonClear() { + String key = "user:11000"; + + JSONObject person = new JSONObject(); + person.put("name", "Gina"); + person.put("age", 29); + + exec(commandObjects.jsonSet(key, Path2.ROOT_PATH, person)); + + Object preCheck = exec(commandObjects.jsonGet(key, Path2.ROOT_PATH)); + assertThat(preCheck, jsonEquals(new JSONArray().put(person))); + + Long clear = exec(commandObjects.jsonClear(key)); + assertThat(clear, equalTo(1L)); + + Object postCheck = exec(commandObjects.jsonGet(key, Path2.ROOT_PATH)); + + JSONArray expected = new JSONArray().put(new JSONObject()); + assertThat(postCheck, jsonEquals(expected)); + } + + @Test + public void testJsonClearPath() { + String key = "user:11000"; + + JSONObject person = new JSONObject(); + person.put("name", "Gina"); + person.put("age", 29); + person.put("occupations", new JSONArray().put("Data Scientist").put("Developer")); + + exec(commandObjects.jsonSet(key, Path2.ROOT_PATH, person)); + + Object preCheck = exec(commandObjects.jsonGet(key, Path2.ROOT_PATH)); + assertThat(preCheck, jsonEquals(new JSONArray().put(person))); + + Long clearOccupations = exec(commandObjects.jsonClear(key, Path2.of(".occupations"))); + assertThat(clearOccupations, equalTo(1L)); + + Object postCheck = exec(commandObjects.jsonGet(key, Path2.ROOT_PATH)); + + JSONObject expected = new JSONObject(); + expected.put("name", "Gina"); + expected.put("age", 29); + expected.put("occupations", new JSONArray()); + assertThat(postCheck, jsonEquals(new JSONArray().put(expected))); + } + + @Test + @Deprecated + public void testJsonClearOldPath() { + String key = "user:11000"; + + JSONObject person = new JSONObject(); + person.put("name", "Gina"); + person.put("age", 29); + person.put("occupations", new JSONArray().put("Data Scientist").put("Developer")); + + exec(commandObjects.jsonSet(key, Path2.ROOT_PATH, person)); + + Object preCheck = exec(commandObjects.jsonGet(key, Path2.ROOT_PATH)); + assertThat(preCheck, jsonEquals(new JSONArray().put(person))); + + Long clearOccupations = exec(commandObjects.jsonClear(key, Path.of(".occupations"))); + assertThat(clearOccupations, equalTo(1L)); + + Object postCheck = exec(commandObjects.jsonGet(key, Path2.ROOT_PATH)); + + JSONObject expected = new JSONObject(); + expected.put("name", "Gina"); + expected.put("age", 29); + expected.put("occupations", new JSONArray()); + assertThat(postCheck, jsonEquals(new JSONArray().put(expected))); + } + + @Test + public void testJsonToggle() { + String key = "user:13000"; + + JSONObject item = new JSONObject(); + item.put("active", true); + + exec(commandObjects.jsonSet(key, Path2.ROOT_PATH, item)); + + Object preCheck = exec(commandObjects.jsonGet(key, Path2.ROOT_PATH)); + assertThat(preCheck, jsonEquals(new JSONArray().put(item))); + + List toggle = exec(commandObjects.jsonToggle(key, Path2.of(".active"))); + assertThat(toggle, contains(false)); + + Object postCheck = exec(commandObjects.jsonGet(key, Path2.ROOT_PATH)); + + JSONObject expected = new JSONObject(); + expected.put("active", false); + assertThat(postCheck, jsonEquals(new JSONArray().put(expected))); + } + + @Test + public void testJsonType() { + String key = "jsonKey"; + + JSONObject item = new JSONObject(); + item.put("active", true); + + exec(commandObjects.jsonSet(key, Path2.ROOT_PATH, item)); + + List> type = exec(commandObjects.jsonType(key, Path2.of(".active"))); + assertThat(type, contains(boolean.class)); + } + + @Test + @Deprecated + public void testJsonTypeOldPath() { + assumeThat(protocol, not(equalTo(RedisProtocol.RESP3))); + + String key = "jsonKey"; + + JSONObject item = new JSONObject(); + item.put("active", true); + + exec(commandObjects.jsonSet(key, Path2.ROOT_PATH, item)); + + Class type = exec(commandObjects.jsonType(key, Path.of(".active"))); + assertThat(type, equalTo(boolean.class)); + } + + @Test + public void testJsonStrAppend() { + String key = "user:1000"; + + JSONObject person = new JSONObject(); + person.put("name", "Gina"); + person.put("age", 29); + + exec(commandObjects.jsonSet(key, Path2.ROOT_PATH, person)); + + Object preCheck = exec(commandObjects.jsonGet(key, Path2.ROOT_PATH)); + assertThat(preCheck, jsonEquals(new JSONArray().put(person))); + + List strAppend = exec(commandObjects.jsonStrAppend(key, Path2.of(".name"), " Smith")); + assertThat(strAppend, contains(10L)); + + Object postCheck = exec(commandObjects.jsonGet(key, Path2.ROOT_PATH)); + + JSONObject expected = new JSONObject(); + expected.put("name", "Gina Smith"); + expected.put("age", 29); + assertThat(postCheck, jsonEquals(new JSONArray().put(expected))); + } + + @Test + @Deprecated + public void testJsonStrAppendOldPath() { + String key = "user:1000"; + + JSONObject person = new JSONObject(); + person.put("name", "Gina"); + person.put("age", 29); + + exec(commandObjects.jsonSet(key, Path2.ROOT_PATH, person)); + + Object preCheck = exec(commandObjects.jsonGet(key, Path2.ROOT_PATH)); + assertThat(preCheck, jsonEquals(new JSONArray().put(person))); + + Long strAppend = exec(commandObjects.jsonStrAppend(key, Path.of(".name"), " Smith")); + assertThat(strAppend, equalTo(10L)); + + Object postCheck = exec(commandObjects.jsonGet(key, Path2.ROOT_PATH)); + + JSONObject expected = new JSONObject(); + expected.put("name", "Gina Smith"); + expected.put("age", 29); + assertThat(postCheck, jsonEquals(new JSONArray().put(expected))); + } + + @Test + @Deprecated + public void testJsonStrAppendRootPath() { + assumeThat(protocol, not(equalTo(RedisProtocol.RESP3))); + + String key = "user:1000"; + + String setRoot = exec(commandObjects.jsonSetWithPlainString(key, Path.ROOT_PATH, "\"John\"")); + assertThat(setRoot, equalTo("OK")); + + Object getBefore = exec(commandObjects.jsonGet(key, Path2.ROOT_PATH)); + assertThat(getBefore, jsonEquals(new JSONArray().put("John"))); + + Long strAppend = exec(commandObjects.jsonStrAppend(key, " Doe")); + assertThat(strAppend, equalTo(8L)); + + Object getAfter = exec(commandObjects.jsonGet(key, Path2.ROOT_PATH)); + assertThat(getAfter, jsonEquals(new JSONArray().put("John Doe"))); + } + + @Test + @Deprecated + public void testJsonStrLenRootPath() { + assumeThat(protocol, not(equalTo(RedisProtocol.RESP3))); + + String key = "user:1001"; + + String setRoot = exec(commandObjects.jsonSetWithPlainString(key, Path.ROOT_PATH, "\"Hello World\"")); + assertThat(setRoot, equalTo("OK")); + + Long strLen = exec(commandObjects.jsonStrLen(key)); + assertThat(strLen, equalTo(11L)); // "Hello World" length + } + + @Test + public void testJsonStrLen() { + String key = "user:1002"; + + JSONObject item = new JSONObject(); + item.put("message", "Hello, Redis!"); + + String setResponse = exec(commandObjects.jsonSet(key, Path2.ROOT_PATH, item)); + assertThat(setResponse, equalTo("OK")); + + List strLenResponse = exec(commandObjects.jsonStrLen(key, Path2.of(".message"))); + assertThat(strLenResponse, contains(13L)); // "Hello, Redis!" length + } + + @Test + @Deprecated + public void testJsonStrLenOldPath() { + String key = "user:1003"; + + JSONObject item = new JSONObject(); + item.put("message", "Hello, Redis!"); + + String setResponse = exec(commandObjects.jsonSet(key, Path2.ROOT_PATH, item)); + assertThat(setResponse, equalTo("OK")); + + Long strLenResponse = exec(commandObjects.jsonStrLen(key, Path.of(".message"))); + assertThat(strLenResponse, equalTo(13L)); // "Hello, Redis!" length + } + + @Test + public void testJsonNumIncrBy() { + String key = "user:12000"; + + JSONObject item = new JSONObject(); + item.put("balance", 100); + + exec(commandObjects.jsonSet(key, Path2.ROOT_PATH, item)); + + Object preCheck = exec(commandObjects.jsonGet(key, Path2.ROOT_PATH)); + assertThat(preCheck, jsonEquals(new JSONArray().put(item))); + + Object numIncrBy = exec(commandObjects.jsonNumIncrBy(key, Path2.of("$.balance"), 50.0)); + assertThat(numIncrBy, jsonEquals(new JSONArray().put(150.0))); + + Object postCheck = exec(commandObjects.jsonGet(key, Path2.ROOT_PATH)); + + JSONObject expected = new JSONObject(); + expected.put("balance", 150.0); + assertThat(postCheck, jsonEquals(new JSONArray().put(expected))); + } + + @Test + public void testJsonArrAppendWithEscape() { + String key = "json"; + + JSONArray data = new JSONArray() + .put("Elixir") + .put("Swift"); + + exec(commandObjects.jsonSet(key, Path2.ROOT_PATH, data)); + + Object preCheck = exec(commandObjects.jsonGet(key, Path2.ROOT_PATH)); + assertThat(preCheck, jsonEquals(new JSONArray().put(data))); + + List arrAppend = exec(commandObjects.jsonArrAppendWithEscape( + key, Path2.ROOT_PATH, "Kotlin", "TypeScript")); + assertThat(arrAppend, contains(4L)); + + Object postCheck = exec(commandObjects.jsonGet(key, Path2.ROOT_PATH)); + + JSONArray expected = new JSONArray() + .put("Elixir") + .put("Swift") + .put("Kotlin") + .put("TypeScript"); + assertThat(postCheck, jsonEquals(new JSONArray().put(expected))); + } + + @Test + public void testJsonArrAppend() { + String key = "json"; + + JSONArray data = new JSONArray() + .put("Java") + .put("Python"); + + exec(commandObjects.jsonSet(key, Path2.ROOT_PATH, data)); + + JSONObject person = new JSONObject(); + person.put("name", "John"); + + List arrAppend = exec(commandObjects.jsonArrAppend(key, Path2.ROOT_PATH, + "\"C++\"", "\"JavaScript\"", person)); + assertThat(arrAppend, contains(5L)); + + Object postCheck = exec(commandObjects.jsonGet(key, Path2.ROOT_PATH)); + + JSONArray expected = new JSONArray() + .put("Java") + .put("Python") + .put("C++") + .put("JavaScript") + .put(person); + assertThat(postCheck, jsonEquals(new JSONArray().put(expected))); + } + + @Test + @Deprecated + public void testJsonArrAppendOldPath() { + String key = "json"; + + JSONArray data = new JSONArray() + .put(new JSONArray() + .put("Java") + .put("Python")) + .put(1); + + exec(commandObjects.jsonSet(key, Path2.ROOT_PATH, data)); + + Person person = new Person("John", 45); + + Long arrAppend = exec( + commandObjects.jsonArrAppend(key, Path.of(".[0]"), "Swift", "Go", person)); + assertThat(arrAppend, equalTo(5L)); + + Object postCheck = exec(commandObjects.jsonGet(key, Path2.ROOT_PATH)); + + JSONArray expected = new JSONArray() + .put(new JSONArray() + .put("Java") + .put("Python") + .put("Swift") + .put("Go") + .put(new JSONObject() + .put("name", "John") + .put("age", 45))) + .put(1); + assertThat(postCheck, jsonEquals(new JSONArray().put(expected))); + } + + @Test + public void testJsonArrIndex() { + String key = "json"; + + JSONArray data = new JSONArray() + .put("Java") + .put("Python") + .put("Java"); // duplicate + + exec(commandObjects.jsonSet(key, Path2.ROOT_PATH, data)); + + List arrIndex = exec(commandObjects.jsonArrIndex(key, Path2.ROOT_PATH, "\"Java\"")); + assertThat(arrIndex, contains(0L)); + + List arrIndexNotFound = exec(commandObjects.jsonArrIndex(key, Path2.ROOT_PATH, "\"C++\"")); + assertThat(arrIndexNotFound, contains(-1L)); + } + + @Test + public void testJsonArrIndexWithEscape() { + String key = "json"; + + JSONArray data = new JSONArray() + .put("Java") + .put("Python") + .put("Java"); // duplicate + + exec(commandObjects.jsonSet(key, Path2.ROOT_PATH, data)); + + List arrIndex = exec(commandObjects.jsonArrIndexWithEscape(key, Path2.ROOT_PATH, "Java")); + assertThat(arrIndex, contains(0L)); + + List arrIndexNotFound = exec(commandObjects.jsonArrIndexWithEscape(key, Path2.ROOT_PATH, "Go")); + assertThat(arrIndexNotFound, contains(-1L)); + } + + @Test + @Deprecated + public void testJsonArrIndexDeprecated() { + String key = "json"; + + JSONArray data = new JSONArray() + .put(new JSONArray() + .put("Java") + .put("Python") + .put("Java")); // duplicate + + exec(commandObjects.jsonSet(key, Path2.ROOT_PATH, data)); + + Long arrIndex = exec(commandObjects.jsonArrIndex(key, Path.of(".[0]"), "Java")); + assertThat(arrIndex, equalTo(0L)); + + Long arrIndexNotFound = exec(commandObjects.jsonArrIndex(key, Path.of(".[0]"), "Swift")); + assertThat(arrIndexNotFound, equalTo(-1L)); + } + + @Test + public void testJsonArrInsert() { + String key = "json"; + + JSONArray data = new JSONArray() + .put("Java") + .put("Python"); + + exec(commandObjects.jsonSet(key, Path2.ROOT_PATH, data)); + + Object preCheck = exec(commandObjects.jsonGet(key, Path2.ROOT_PATH)); + assertThat(preCheck, jsonEquals(new JSONArray().put(data))); + + List arrInsert = exec( + commandObjects.jsonArrInsert(key, Path2.ROOT_PATH, 1, "\"C++\"")); + assertThat(arrInsert, contains(3L)); + + Object postCheck = exec(commandObjects.jsonGet(key, Path2.ROOT_PATH)); + + JSONArray expected = new JSONArray() + .put("Java") + .put("C++") + .put("Python"); + assertThat(postCheck, jsonEquals(new JSONArray().put(expected))); + } + + @Test + public void testJsonArrInsertWithEscape() { + String key = "json"; + + JSONArray data = new JSONArray() + .put("Java") + .put("Python"); + + exec(commandObjects.jsonSet(key, Path2.ROOT_PATH, data)); + + Object preCheck = exec(commandObjects.jsonGet(key, Path2.ROOT_PATH)); + assertThat(preCheck, jsonEquals(new JSONArray().put(data))); + + List arrInsert = exec(commandObjects.jsonArrInsertWithEscape(key, Path2.ROOT_PATH, 1, "Go")); + assertThat(arrInsert, contains(3L)); + + Object postCheck = exec(commandObjects.jsonGet(key, Path2.ROOT_PATH)); + + JSONArray expected = new JSONArray() + .put("Java") + .put("Go") + .put("Python"); + assertThat(postCheck, jsonEquals(new JSONArray().put(expected))); + } + + @Test + @Deprecated + public void testJsonArrInsertOldPath() { + String key = "json"; + + JSONArray data = new JSONArray() + .put(1) + .put(new JSONArray() + .put("Scala") + .put("Kotlin")); + + exec(commandObjects.jsonSet(key, Path2.ROOT_PATH, data)); + + Object preCheck = exec(commandObjects.jsonGet(key, Path2.ROOT_PATH)); + assertThat(preCheck, jsonEquals(new JSONArray().put(data))); + + Long arrInsert = exec(commandObjects.jsonArrInsert(key, Path.of(".[1]"), 1, "Swift")); + assertThat(arrInsert, equalTo(3L)); + + Object postCheck = exec(commandObjects.jsonGet(key, Path2.ROOT_PATH)); + + JSONArray expected = new JSONArray() + .put(1) + .put(new JSONArray() + .put("Scala") + .put("Swift") + .put("Kotlin")); + assertThat(postCheck, jsonEquals(new JSONArray().put(expected))); + } + + @Test + @Deprecated + public void testJsonArrPopRoot() { + String key = "json"; + + JSONArray data = new JSONArray() + .put("apple") + .put("banana") + .put("cherry"); + + exec(commandObjects.jsonSet(key, Path2.ROOT_PATH, data)); + + Object preCheck = exec(commandObjects.jsonGet(key, Path2.ROOT_PATH)); + assertThat(preCheck, jsonEquals(new JSONArray().put(data))); + + Object arrPop = exec(commandObjects.jsonArrPop(key)); + assertThat(arrPop, equalTo("cherry")); + + Object postCheck = exec(commandObjects.jsonGet(key, Path2.ROOT_PATH)); + + JSONArray expected = new JSONArray() + .put("apple") + .put("banana"); + assertThat(postCheck, jsonEquals(new JSONArray().put(expected))); + } + + @Test + public void testJsonArrPopWithPath2() { + String key = "json"; + + JSONObject data = new JSONObject() + .put("fruits", new JSONArray() + .put("apple") + .put("banana") + .put("cherry")); + + exec(commandObjects.jsonSet(key, Path2.ROOT_PATH, data)); + + Object preCheck = exec(commandObjects.jsonGet(key, Path2.ROOT_PATH)); + assertThat(preCheck, jsonEquals(new JSONArray().put(data))); + + List arrPop = exec(commandObjects.jsonArrPop(key, Path2.of(".fruits"))); + assertThat(arrPop, contains("cherry")); + + Object postCheck = exec(commandObjects.jsonGet(key, Path2.ROOT_PATH)); + + JSONObject expected = new JSONObject() + .put("fruits", new JSONArray() + .put("apple") + .put("banana")); + assertThat(postCheck, jsonEquals(new JSONArray().put(expected))); + } + + @Test + @Deprecated + public void testJsonArrPopOldPath() { + String key = "json"; + + JSONObject data = new JSONObject() + .put("fruits", new JSONArray() + .put("apple") + .put("banana") + .put("cherry")); + + exec(commandObjects.jsonSet(key, Path2.ROOT_PATH, data)); + + Object preCheck = exec(commandObjects.jsonGet(key, Path2.ROOT_PATH)); + assertThat(preCheck, jsonEquals(new JSONArray().put(data))); + + Object arrPop = exec(commandObjects.jsonArrPop(key, Path.of(".fruits"))); + assertThat(arrPop, equalTo("cherry")); + + Object postCheck = exec(commandObjects.jsonGet(key, Path2.ROOT_PATH)); + + JSONObject expected = new JSONObject() + .put("fruits", new JSONArray() + .put("apple") + .put("banana")); + assertThat(postCheck, jsonEquals(new JSONArray().put(expected))); + } + + @Test + @Deprecated + public void testJsonArrPopRootWithType() { + String key = "json"; + + JSONArray data = new JSONArray() + .put(1) + .put(2) + .put(3); + + exec(commandObjects.jsonSet(key, Path2.ROOT_PATH, data)); + + Object preCheck = exec(commandObjects.jsonGet(key, Path2.ROOT_PATH)); + assertThat(preCheck, jsonEquals(new JSONArray().put(data))); + + Integer arrPop = exec(commandObjects.jsonArrPop(key, Integer.class)); + assertThat(arrPop, equalTo(3)); + + Object postCheck = exec(commandObjects.jsonGet(key, Path2.ROOT_PATH)); + + JSONArray expected = new JSONArray() + .put(1) + .put(2); + assertThat(postCheck, jsonEquals(new JSONArray().put(expected))); + } + + @Test + @Deprecated + public void testJsonArrPopWithOldPathAndType() { + String key = "json"; + + JSONObject data = new JSONObject() + .put("numbers", new JSONArray() + .put(10) + .put(20) + .put(30)); + + exec(commandObjects.jsonSet(key, Path2.ROOT_PATH, data)); + + Object preCheck = exec(commandObjects.jsonGet(key, Path2.ROOT_PATH)); + assertThat(preCheck, jsonEquals(new JSONArray().put(data))); + + Integer arrPop = exec(commandObjects.jsonArrPop(key, Integer.class, Path.of(".numbers"))); + assertThat(arrPop, equalTo(30)); + + Object postCheck = exec(commandObjects.jsonGet(key, Path2.ROOT_PATH)); + + JSONObject expected = new JSONObject() + .put("numbers", new JSONArray() + .put(10) + .put(20)); + assertThat(postCheck, jsonEquals(new JSONArray().put(expected))); + } + + @Test + @Deprecated + public void testJsonArrPopWithOldPathTypeAndIndex() { + String key = "json"; + + JSONObject data = new JSONObject() + .put("numbers", new JSONArray() + .put(10) + .put(20) + .put(30)); + + exec(commandObjects.jsonSet(key, Path2.ROOT_PATH, data)); + + Object preCheck = exec(commandObjects.jsonGet(key, Path2.ROOT_PATH)); + assertThat(preCheck, jsonEquals(new JSONArray().put(data))); + + Integer arrPop = exec(commandObjects.jsonArrPop(key, Integer.class, Path.of(".numbers"), 1)); + assertThat(arrPop, equalTo(20)); + + Object postCheck = exec(commandObjects.jsonGet(key, Path2.ROOT_PATH)); + + JSONObject expected = new JSONObject() + .put("numbers", new JSONArray() + .put(10) + .put(30)); + assertThat(postCheck, jsonEquals(new JSONArray().put(expected))); + } + + @Test + public void testJsonArrPopWithPathAndIndex() { + String key = "json"; + + JSONObject data = new JSONObject() + .put("numbers", new JSONArray() + .put(10) + .put(20) + .put(30)); + + exec(commandObjects.jsonSet(key, Path2.ROOT_PATH, data)); + + Object preCheck = exec(commandObjects.jsonGet(key, Path2.ROOT_PATH)); + assertThat(preCheck, jsonEquals(new JSONArray().put(data))); + + List arrPop = exec(commandObjects.jsonArrPop(key, Path2.of(".numbers"), 1)); + assertThat(arrPop, contains(20.0)); + + Object postCheck = exec(commandObjects.jsonGet(key, Path2.ROOT_PATH)); + + JSONObject expected = new JSONObject() + .put("numbers", new JSONArray() + .put(10) + .put(30)); + assertThat(postCheck, jsonEquals(new JSONArray().put(expected))); + } + + @Test + @Deprecated + public void testJsonArrPopOldPathAndIndex() { + String key = "json"; + + JSONObject data = new JSONObject() + .put("numbers", new JSONArray() + .put(10) + .put(20) + .put(30)); + + exec(commandObjects.jsonSet(key, Path2.ROOT_PATH, data)); + + Object preCheck = exec(commandObjects.jsonGet(key, Path2.ROOT_PATH)); + assertThat(preCheck, jsonEquals(new JSONArray().put(data))); + + Object arrPop = exec(commandObjects.jsonArrPop(key, Path.of(".numbers"), 1)); + assertThat(arrPop, equalTo(20.0)); + + Object postCheck = exec(commandObjects.jsonGet(key, Path2.ROOT_PATH)); + + JSONObject expected = new JSONObject() + .put("numbers", new JSONArray() + .put(10) + .put(30)); + assertThat(postCheck, jsonEquals(new JSONArray().put(expected))); + } + + @Test + public void testJsonArrTrimWithPath() { + String key = "json"; + + JSONObject data = new JSONObject() + .put("fruits", new JSONArray() + .put("apple") + .put("banana") + .put("cherry") + .put("date") + .put("fig")); + + exec(commandObjects.jsonSet(key, Path2.ROOT_PATH, data)); + + Object preCheck = exec(commandObjects.jsonGet(key, Path2.ROOT_PATH)); + assertThat(preCheck, jsonEquals(new JSONArray().put(data))); + + List arrTrim = exec(commandObjects.jsonArrTrim(key, Path2.of(".fruits"), 1, 3)); + assertThat(arrTrim, contains(3L)); + + Object postCheck = exec(commandObjects.jsonGet(key, Path2.ROOT_PATH)); + + JSONObject expected = new JSONObject() + .put("fruits", new JSONArray() + .put("banana") + .put("cherry") + .put("date")); + assertThat(postCheck, jsonEquals(new JSONArray().put(expected))); + } + + @Test + @Deprecated + public void testJsonArrTrimOldPath() { + String key = "json"; + + JSONObject data = new JSONObject() + .put("fruits", new JSONArray() + .put("apple") + .put("banana") + .put("cherry") + .put("date") + .put("fig")); + + exec(commandObjects.jsonSet(key, Path2.ROOT_PATH, data)); + + Object preCheck = exec(commandObjects.jsonGet(key, Path2.ROOT_PATH)); + assertThat(preCheck, jsonEquals(new JSONArray().put(data))); + + Long arrTrim = exec(commandObjects.jsonArrTrim(key, Path.of(".fruits"), 1, 3)); + assertThat(arrTrim, equalTo(3L)); + + Object postCheck = exec(commandObjects.jsonGet(key, Path2.ROOT_PATH)); + + JSONObject expected = new JSONObject() + .put("fruits", new JSONArray() + .put("banana") + .put("cherry") + .put("date")); + assertThat(postCheck, jsonEquals(new JSONArray().put(expected))); + } + + @Test + @Deprecated + public void testJsonArrLenRoot() { + assumeThat(protocol, not(equalTo(RedisProtocol.RESP3))); + + String key = "json"; + + JSONArray data = new JSONArray() + .put("apple") + .put("banana") + .put("cherry") + .put("date") + .put("fig"); + + exec(commandObjects.jsonSet(key, Path2.ROOT_PATH, data)); + + Long arrLen = exec(commandObjects.jsonArrLen(key)); + assertThat(arrLen, equalTo(5L)); + } + + @Test + public void testJsonArrLenWithPath() { + String key = "json"; + + JSONObject data = new JSONObject() + .put("fruits", new JSONArray() + .put("apple") + .put("banana") + .put("cherry") + .put("date") + .put("fig")); + + exec(commandObjects.jsonSet(key, Path2.ROOT_PATH, data)); + + List arrLen = exec(commandObjects.jsonArrLen(key, Path2.of(".fruits"))); + assertThat(arrLen, contains(5L)); + } + + @Test + @Deprecated + public void testJsonArrLenOldPath() { + String key = "json"; + + JSONObject data = new JSONObject() + .put("fruits", new JSONArray() + .put("apple") + .put("banana") + .put("cherry") + .put("date") + .put("fig")); + + exec(commandObjects.jsonSet(key, Path2.ROOT_PATH, data)); + + Long arrLen = exec(commandObjects.jsonArrLen(key, Path.of(".fruits"))); + assertThat(arrLen, equalTo(5L)); + } + + @Test + @Deprecated + public void testJsonObjLenRoot() { + assumeThat(protocol, not(equalTo(RedisProtocol.RESP3))); + + String key = "json"; + + JSONObject data = new JSONObject(); + data.put("name", "John"); + data.put("age", 30); + + String setResponse = exec(commandObjects.jsonSet(key, Path2.ROOT_PATH, data)); + assertThat(setResponse, equalTo("OK")); + + Long objLen = exec(commandObjects.jsonObjLen(key)); + assertThat(objLen, equalTo(2L)); // 2 keys: "name" and "age" + } + + @Test + @Deprecated + public void testJsonObjLenOldPath() { + String key = "json"; + + JSONObject data = new JSONObject().put("user", + new JSONObject() + .put("name", "John") + .put("age", 30)); + + String setResponse = exec(commandObjects.jsonSet(key, Path2.ROOT_PATH, data)); + assertThat(setResponse, equalTo("OK")); + + Long objLen = exec(commandObjects.jsonObjLen(key, Path.of(".user"))); + assertThat(objLen, equalTo(2L)); + } + + @Test + public void testJsonObjLenWithPath2() { + String key = "json"; + + JSONObject data = new JSONObject().put("user", + new JSONObject() + .put("name", "John") + .put("age", 30)); + + String setResponse = exec(commandObjects.jsonSet(key, Path2.ROOT_PATH, data)); + assertThat(setResponse, equalTo("OK")); + + List objLen = exec(commandObjects.jsonObjLen(key, Path2.of(".user"))); + assertThat(objLen, contains(2L)); + } + + @Test + @Deprecated + public void testJsonObjKeysRoot() { + assumeThat(protocol, not(equalTo(RedisProtocol.RESP3))); + + String key = "json"; + + JSONObject data = new JSONObject(); + data.put("name", "John"); + data.put("age", 30); + + String setResponse = exec(commandObjects.jsonSet(key, Path2.ROOT_PATH, data)); + assertThat(setResponse, equalTo("OK")); + + List keys = exec(commandObjects.jsonObjKeys(key)); + assertThat(keys, containsInAnyOrder("name", "age")); + } + + @Test + @Deprecated + public void testJsonObjKeysOldPath() { + String key = "json"; + + JSONObject data = new JSONObject().put("user", + new JSONObject() + .put("name", "John") + .put("age", 30)); + + String setResponse = exec(commandObjects.jsonSet(key, Path2.ROOT_PATH, data)); + assertThat(setResponse, equalTo("OK")); + + List keys = exec(commandObjects.jsonObjKeys(key, Path.of(".user"))); + assertThat(keys, containsInAnyOrder("name", "age")); + } + + @Test + public void testJsonObjKeysWithPath() { + String key = "json"; + + JSONObject data = new JSONObject().put("user", + new JSONObject() + .put("name", "John") + .put("age", 30)); + + String setResponse = exec(commandObjects.jsonSet(key, Path2.ROOT_PATH, data)); + assertThat(setResponse, equalTo("OK")); + + List> keys = exec(commandObjects.jsonObjKeys(key, Path2.of(".user"))); + assertThat(keys, contains(containsInAnyOrder("name", "age"))); + } + + @Test + @Deprecated + public void testJsonDebugMemoryRoot() { + assumeThat(protocol, not(equalTo(RedisProtocol.RESP3))); + String key = "json"; + + JSONObject data = new JSONObject() + .put("name", "John") + .put("age", 30); + + String setResponse = exec(commandObjects.jsonSet(key, Path2.ROOT_PATH, data)); + assertThat(setResponse, equalTo("OK")); + + Long memoryUsage = exec(commandObjects.jsonDebugMemory(key)); + assertThat(memoryUsage, notNullValue()); + assertThat(memoryUsage, greaterThan(0L)); + } + + @Test + @Deprecated + public void testJsonDebugMemoryOldPath() { + String key = "json"; + + JSONObject data = new JSONObject().put("user", + new JSONObject() + .put("name", "John") + .put("age", 30)); + + String setResponse = exec(commandObjects.jsonSet(key, Path2.ROOT_PATH, data)); + assertThat(setResponse, equalTo("OK")); + + Long memoryUsage = exec(commandObjects.jsonDebugMemory(key, Path.of(".user"))); + assertThat(memoryUsage, notNullValue()); + assertThat(memoryUsage, greaterThan(0L)); + } + + @Test + public void testJsonDebugMemoryWithPath2() { + String key = "json"; + + JSONObject data = new JSONObject().put("user", + new JSONObject() + .put("name", "John") + .put("age", 30)); + + String setResponse = exec(commandObjects.jsonSet(key, Path2.ROOT_PATH, data)); + assertThat(setResponse, equalTo("OK")); + + List memoryUsages = exec(commandObjects.jsonDebugMemory(key, Path2.of(".user"))); + assertThat(memoryUsages, contains(greaterThan(0L))); + } +} diff --git a/src/test/java/redis/clients/jedis/commands/commandobjects/CommandObjectsListCommandsTest.java b/src/test/java/redis/clients/jedis/commands/commandobjects/CommandObjectsListCommandsTest.java new file mode 100644 index 00000000000..c7f84157d1a --- /dev/null +++ b/src/test/java/redis/clients/jedis/commands/commandobjects/CommandObjectsListCommandsTest.java @@ -0,0 +1,663 @@ +package redis.clients.jedis.commands.commandobjects; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.anyOf; +import static org.hamcrest.Matchers.contains; +import static org.hamcrest.Matchers.empty; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.nullValue; + +import java.util.List; + +import org.junit.Test; +import redis.clients.jedis.RedisProtocol; +import redis.clients.jedis.args.ListDirection; +import redis.clients.jedis.args.ListPosition; +import redis.clients.jedis.params.LPosParams; +import redis.clients.jedis.util.KeyValue; + +/** + * Tests related to List commands. + */ +public class CommandObjectsListCommandsTest extends CommandObjectsStandaloneTestBase { + + public CommandObjectsListCommandsTest(RedisProtocol protocol) { + super(protocol); + } + + @Test + public void testPushCommands() { + String key = "list"; + + Long rpush = exec(commandObjects.rpush(key, "hello", "world")); + assertThat(rpush, equalTo(2L)); + + Long lpush = exec(commandObjects.lpush(key, "hello", "world")); + assertThat(lpush, equalTo(4L)); + + List lrange = exec(commandObjects.lrange(key, 0, -1)); + assertThat(lrange, contains("world", "hello", "hello", "world")); + } + + @Test + public void testPushCommandsBinary() { + String keyStr = "list"; + byte[] key = keyStr.getBytes(); + + Long rpush = exec(commandObjects.rpush(key, "hello".getBytes(), "world".getBytes())); + assertThat(rpush, equalTo(2L)); + + Long lpush = exec(commandObjects.lpush(key, "hello".getBytes(), "world".getBytes())); + assertThat(lpush, equalTo(4L)); + + List lrange = exec(commandObjects.lrange(keyStr, 0, -1)); + assertThat(lrange, contains("world", "hello", "hello", "world")); + } + + @Test + public void testLlen() { + String key = "list"; + + Long initialLength = exec(commandObjects.llen(key)); + assertThat(initialLength, equalTo(0L)); + + exec(commandObjects.rpush(key, "value", "value")); + + Long llen = exec(commandObjects.llen(key)); + assertThat(llen, equalTo(2L)); + + Long llenBinary = exec(commandObjects.llen(key.getBytes())); + assertThat(llenBinary, equalTo(2L)); + } + + @Test + public void testLrange() { + String key = "list"; + String value1 = "first"; + String value2 = "second"; + String value3 = "third"; + + exec(commandObjects.rpush(key, value1, value2, value3)); + + List lrange = exec(commandObjects.lrange(key, 0, -1)); + assertThat(lrange, contains(value1, value2, value3)); + + List lrangeBinary = exec(commandObjects.lrange(key.getBytes(), 0, -1)); + assertThat(lrangeBinary, contains(value1.getBytes(), value2.getBytes(), value3.getBytes())); + + List partialRange = exec(commandObjects.lrange(key, 1, 2)); + assertThat(partialRange, contains(value2, value3)); + + List emptyRange = exec(commandObjects.lrange(key, 4, 5)); + assertThat(emptyRange, empty()); + } + + @Test + public void testLtrim() { + String key = "list"; + + exec(commandObjects.rpush(key, "one", "two", "three", "four")); + + String trim = exec(commandObjects.ltrim(key, 1, 2)); + assertThat(trim, equalTo("OK")); + + List lrange = exec(commandObjects.lrange(key, 0, -1)); + assertThat(lrange, contains("two", "three")); + } + + @Test + public void testLtrimBinary() { + byte[] key = "list".getBytes(); + + exec(commandObjects.rpush(key, "one".getBytes(), "two".getBytes(), "three".getBytes(), "four".getBytes())); + + String trim = exec(commandObjects.ltrim(key, 1, 2)); + assertThat(trim, equalTo("OK")); + + List lrange = exec(commandObjects.lrange(key, 0, -1)); + assertThat(lrange, contains("two".getBytes(), "three".getBytes())); + } + + @Test + public void testLindexCommands() { + String key = "list"; + + exec(commandObjects.rpush(key, "alpha", "beta", "gamma")); + + String lindex = exec(commandObjects.lindex(key, 1)); + assertThat(lindex, equalTo("beta")); + + byte[] lindexBinary = exec(commandObjects.lindex(key.getBytes(), 2)); + assertThat(lindexBinary, equalTo("gamma".getBytes())); + + String lindexOufOfRange = exec(commandObjects.lindex(key, 5)); + assertThat(lindexOufOfRange, nullValue()); + + byte[] lindexLastPositionBinary = exec(commandObjects.lindex(key.getBytes(), -1)); + assertThat(lindexLastPositionBinary, equalTo("gamma".getBytes())); + } + + @Test + public void testLset() { + String key = "list"; + String initialValue = "initial"; + String updatedValue = "updated"; + + exec(commandObjects.rpush(key, initialValue)); + + String lindexBefore = exec(commandObjects.lindex(key, 0)); + assertThat(lindexBefore, equalTo(initialValue)); + + String lset = exec(commandObjects.lset(key, 0, updatedValue)); + assertThat(lset, equalTo("OK")); + + String lindexAfter = exec(commandObjects.lindex(key, 0)); + assertThat(lindexAfter, equalTo(updatedValue)); + } + + @Test + public void testLsetBinary() { + byte[] keyBytes = "list".getBytes(); + String initialValue = "initial"; + String updatedValue = "updated"; + + exec(commandObjects.rpush(keyBytes, initialValue.getBytes())); + + byte[] lindexBefore = exec(commandObjects.lindex(keyBytes, 0)); + assertThat(lindexBefore, equalTo(initialValue.getBytes())); + + String lset = exec(commandObjects.lset(keyBytes, 0, updatedValue.getBytes())); + assertThat(lset, equalTo("OK")); + + byte[] lindexAfter = exec(commandObjects.lindex(keyBytes, 0)); + assertThat(lindexAfter, equalTo(updatedValue.getBytes())); + } + + @Test + public void testLrem() { + String key = "remList"; + + exec(commandObjects.rpush(key, "duplicate", "duplicate", "unique")); + + List lrangeInitial = exec(commandObjects.lrange(key, 0, -1)); + assertThat(lrangeInitial, contains("duplicate", "duplicate", "unique")); + + Long lrem = exec(commandObjects.lrem(key, 1, "duplicate")); + assertThat(lrem, equalTo(1L)); + + List lrangeAfterLremSingle = exec(commandObjects.lrange(key, 0, -1)); + assertThat(lrangeAfterLremSingle, contains("duplicate", "unique")); + + Long lremNonExistent = exec(commandObjects.lrem(key, 0, "nonexistent")); + assertThat(lremNonExistent, equalTo(0L)); + + List lrangeAfterLremNonExistent = exec(commandObjects.lrange(key, 0, -1)); + assertThat(lrangeAfterLremNonExistent, contains("duplicate", "unique")); + } + + @Test + public void testLremBinary() { + byte[] keyBytes = "remList".getBytes(); + + exec(commandObjects.rpush(keyBytes, "duplicate".getBytes(), "duplicate".getBytes(), "unique".getBytes())); + + List lrangeBefore = exec(commandObjects.lrange(keyBytes, 0, -1)); + assertThat(lrangeBefore, contains("duplicate".getBytes(), "duplicate".getBytes(), "unique".getBytes())); + + Long lremMultiple = exec(commandObjects.lrem(keyBytes, 0, "duplicate".getBytes())); + assertThat(lremMultiple, equalTo(2L)); + + List lrangeAfter = exec(commandObjects.lrange(keyBytes, 0, -1)); + assertThat(lrangeAfter, contains("unique".getBytes())); + } + + @Test + public void testPopCommands() { + String key = "popList"; + + exec(commandObjects.rpush(key, + "first", "second", "third", "first", "second", "third")); + + String lpop = exec(commandObjects.lpop(key)); + assertThat(lpop, equalTo("first")); + + String rpop = exec(commandObjects.rpop(key)); + assertThat(rpop, equalTo("third")); + + List lpopMultiple = exec(commandObjects.lpop(key, 2)); + assertThat(lpopMultiple, contains("second", "third")); + + List rpopMultiple = exec(commandObjects.rpop(key, 2)); + assertThat(rpopMultiple, contains("second", "first")); + } + + @Test + public void testPopCommandsBinary() { + byte[] key = "popList".getBytes(); + + exec(commandObjects.rpush(key, + "first".getBytes(), "second".getBytes(), "third".getBytes(), + "first".getBytes(), "second".getBytes(), "third".getBytes())); + + byte[] lpop = exec(commandObjects.lpop(key)); + assertThat(lpop, equalTo("first".getBytes())); + + byte[] rpop = exec(commandObjects.rpop(key)); + assertThat(rpop, equalTo("third".getBytes())); + + List lpopMultiple = exec(commandObjects.lpop(key, 2)); + assertThat(lpopMultiple, contains("second".getBytes(), "third".getBytes())); + + List rpopMultiple = exec(commandObjects.rpop(key, 2)); + assertThat(rpopMultiple, contains("second".getBytes(), "first".getBytes())); + } + + @Test + public void testLpos() { + String key = "list"; + String value = "target"; + String nonExistentValue = "ghost"; + + exec(commandObjects.rpush(key, "start", value, "middle", value, "end")); + + Long lposFirst = exec(commandObjects.lpos(key, value)); + assertThat(lposFirst, equalTo(1L)); + + Long lposFirstBinary = exec(commandObjects.lpos(key.getBytes(), value.getBytes())); + assertThat(lposFirstBinary, equalTo(1L)); + + LPosParams params = LPosParams.lPosParams().rank(-1); + Long lposLast = exec(commandObjects.lpos(key, value, params)); + assertThat(lposLast, equalTo(3L)); + + Long lposLastBinary = exec(commandObjects.lpos(key.getBytes(), value.getBytes(), params)); + assertThat(lposLastBinary, equalTo(3L)); + + List lposMultiple = exec(commandObjects.lpos(key, value, params, 2)); + assertThat(lposMultiple, contains(3L, 1L)); + + List lposMultipleBinary = exec(commandObjects.lpos(key.getBytes(), value.getBytes(), params, 2)); + assertThat(lposMultipleBinary, contains(3L, 1L)); + + Long lposNonExistent = exec(commandObjects.lpos(key, nonExistentValue)); + assertThat(lposNonExistent, nullValue()); + + Long lposNonExistentBinary = exec(commandObjects.lpos(key.getBytes(), nonExistentValue.getBytes())); + assertThat(lposNonExistentBinary, nullValue()); + } + + @Test + public void testLinsert() { + String key = "insertList"; + String pivot = "pivot"; + String valueBefore = "beforePivot"; + String valueAfter = "afterPivot"; + + exec(commandObjects.rpush(key, pivot)); + + Long linsertBefore = exec(commandObjects.linsert(key, ListPosition.BEFORE, pivot, valueBefore)); + assertThat(linsertBefore, equalTo(2L)); + + Long linsertAfter = exec(commandObjects.linsert(key, ListPosition.AFTER, pivot, valueAfter)); + assertThat(linsertAfter, equalTo(3L)); + + List lrange = exec(commandObjects.lrange(key, 0, -1)); + assertThat(lrange, contains(valueBefore, pivot, valueAfter)); + } + + @Test + public void testLinsertBinary() { + byte[] key = "insertList".getBytes(); + byte[] pivot = "pivot".getBytes(); + byte[] valueBefore = "valueBefore".getBytes(); + byte[] valueAfter = "valueAfter".getBytes(); + + exec(commandObjects.rpush(key, pivot)); + + Long linsertBefore = exec(commandObjects.linsert(key, ListPosition.BEFORE, pivot, valueBefore)); + assertThat(linsertBefore, equalTo(2L)); + + Long linsertAfter = exec(commandObjects.linsert(key, ListPosition.AFTER, pivot, valueAfter)); + assertThat(linsertAfter, equalTo(3L)); + + List lrange = exec(commandObjects.lrange(key, 0, -1)); + assertThat(lrange, contains(valueBefore, pivot, valueAfter)); + } + + @Test + public void testPushxCommands() { + String key = "pushxList"; + String value1 = "first"; + String value2 = "second"; + + Long lpushxInitial = exec(commandObjects.lpushx(key, value1)); + assertThat(lpushxInitial, equalTo(0L)); + + Long rpushxInitial = exec(commandObjects.rpushx(key, value1)); + assertThat(rpushxInitial, equalTo(0L)); + + Boolean exists = exec(commandObjects.exists(key)); + assertThat(exists, equalTo(false)); + + exec(commandObjects.lpush(key, "init")); + + Long lpushx = exec(commandObjects.lpushx(key, value1, value2)); + assertThat(lpushx, equalTo(3L)); // new size returned + + Long rpushx = exec(commandObjects.rpushx(key, value1, value2)); + assertThat(rpushx, equalTo(5L)); + + List lrange = exec(commandObjects.lrange(key, 0, -1)); + assertThat(lrange, contains(value2, value1, "init", value1, value2)); + } + + @Test + public void testPushxCommandsBinary() { + byte[] key = "pushxList".getBytes(); + byte[] value1 = "first".getBytes(); + byte[] value2 = "second".getBytes(); + + Long lpushxInitial = exec(commandObjects.lpushx(key, value1)); + assertThat(lpushxInitial, equalTo(0L)); + + Long rpushxInitial = exec(commandObjects.rpushx(key, value1)); + assertThat(rpushxInitial, equalTo(0L)); + + Boolean exists = exec(commandObjects.exists(key)); + assertThat(exists, equalTo(false)); + + exec(commandObjects.lpush(key, "init".getBytes())); + + Long lpushx = exec(commandObjects.lpushx(key, value1, value2)); + assertThat(lpushx, equalTo(3L)); + + Long rpushx = exec(commandObjects.rpushx(key, value1, value2)); + assertThat(rpushx, equalTo(5L)); + + List lrange = exec(commandObjects.lrange(key, 0, -1)); + assertThat(lrange, contains(value2, value1, "init".getBytes(), value1, value2)); + } + + @Test + public void testBlpop() { + String key1 = "list1"; + String key2 = "list2"; + String value1 = "value1"; + String value2 = "value2"; + + exec(commandObjects.lpush(key1, value1)); + + List blpop = exec(commandObjects.blpop(1, key1)); + assertThat(blpop, contains(key1, value1)); + + exec(commandObjects.lpush(key1, value1)); + exec(commandObjects.lpush(key2, value2)); + + List blpopMultiple = exec(commandObjects.blpop(1, key1, key2)); + assertThat(blpopMultiple, anyOf(contains(key1, value1), contains(key2, value2))); + + exec(commandObjects.lpush(key1, value1)); + + KeyValue blpopDoubleTimeout = exec(commandObjects.blpop(1.0, key1)); + assertThat(blpopDoubleTimeout.getKey(), equalTo(key1)); + assertThat(blpopDoubleTimeout.getValue(), equalTo(value1)); + + exec(commandObjects.lpush(key1, value1)); + exec(commandObjects.lpush(key2, value2)); + + KeyValue blpopDoubleTimeoutMultiple = exec(commandObjects.blpop(1.0, key1, key2)); + assertThat(blpopDoubleTimeoutMultiple.getKey(), anyOf(equalTo(key1), equalTo(key2))); + assertThat(blpopDoubleTimeoutMultiple.getValue(), anyOf(equalTo(value1), equalTo(value2))); + } + + @Test + public void testBlpopBinary() { + byte[] key1 = "list1".getBytes(); + byte[] key2 = "list2".getBytes(); + byte[] value1 = "value1".getBytes(); + byte[] value2 = "value2".getBytes(); + + exec(commandObjects.lpush(key1, value1)); + + List blpop = exec(commandObjects.blpop(1, key1)); + assertThat(blpop.get(0), equalTo(key1)); + assertThat(blpop.get(1), equalTo(value1)); + + exec(commandObjects.lpush(key1, value1)); + exec(commandObjects.lpush(key2, value2)); + + List blpopMultiple = exec(commandObjects.blpop(1, key1, key2)); + assertThat(blpopMultiple, anyOf(contains(key1, value1), contains(key2, value2))); + + exec(commandObjects.lpush(key1, value1)); + + KeyValue blpopDoubleTimeout = exec(commandObjects.blpop(1.0, key1)); + assertThat(blpopDoubleTimeout.getKey(), equalTo(key1)); + assertThat(blpopDoubleTimeout.getValue(), equalTo(value1)); + + exec(commandObjects.lpush(key1, value1)); + exec(commandObjects.lpush(key2, value2)); + + KeyValue blpopDoubleTimeoutMultiple = exec(commandObjects.blpop(1.0, key1, key2)); + assertThat(blpopDoubleTimeoutMultiple.getKey(), anyOf(equalTo(key1), equalTo(key2))); + assertThat(blpopDoubleTimeoutMultiple.getValue(), anyOf(equalTo(value1), equalTo(value2))); + } + + @Test + public void testBrpop() { + String key1 = "list1"; + String key2 = "list2"; + String value1 = "value1"; + String value2 = "value2"; + + exec(commandObjects.lpush(key1, value1)); + + List brpop = exec(commandObjects.brpop(1, key1)); + assertThat(brpop, contains(key1, value1)); + + exec(commandObjects.lpush(key1, value1)); + exec(commandObjects.lpush(key2, value2)); + + List brpopMultiple = exec(commandObjects.brpop(1, key1, key2)); + assertThat(brpopMultiple, anyOf(contains(key1, value1), contains(key2, value2))); + + exec(commandObjects.lpush(key1, value1)); + + KeyValue brpopDoubleTimeout = exec(commandObjects.brpop(1.0, key1)); + assertThat(brpopDoubleTimeout.getKey(), equalTo(key1)); + assertThat(brpopDoubleTimeout.getValue(), equalTo(value1)); + + exec(commandObjects.lpush(key1, value1)); + exec(commandObjects.lpush(key2, value2)); + + KeyValue brpopDoubleTimeoutMultiple = exec(commandObjects.brpop(1.0, key1, key2)); + assertThat(brpopDoubleTimeoutMultiple.getKey(), anyOf(equalTo(key1), equalTo(key2))); + assertThat(brpopDoubleTimeoutMultiple.getValue(), anyOf(equalTo(value1), equalTo(value2))); + } + + @Test + public void testBrpopBinary() { + byte[] key1 = "list1".getBytes(); + byte[] key2 = "list2".getBytes(); + byte[] value1 = "value1".getBytes(); + byte[] value2 = "value2".getBytes(); + + exec(commandObjects.lpush(key1, value1)); + + List brpop = exec(commandObjects.brpop(1, key1)); + assertThat(brpop.get(0), equalTo(key1)); + assertThat(brpop.get(1), equalTo(value1)); + + exec(commandObjects.lpush(key1, value1)); + exec(commandObjects.lpush(key2, value2)); + + List brpopMultiple = exec(commandObjects.brpop(1, key1, key2)); + assertThat(brpopMultiple, anyOf(contains(key1, value1), contains(key2, value2))); + + exec(commandObjects.lpush(key1, value1)); + + KeyValue brpopDoubleTimeout = exec(commandObjects.brpop(1.0, key1)); + assertThat(brpopDoubleTimeout.getKey(), equalTo(key1)); + assertThat(brpopDoubleTimeout.getValue(), equalTo(value1)); + + exec(commandObjects.lpush(key1, value1)); + exec(commandObjects.lpush(key2, value2)); + + KeyValue brpopDoubleTimeoutMultiple = exec(commandObjects.brpop(1.0, key1, key2)); + assertThat(brpopDoubleTimeoutMultiple.getKey(), anyOf(equalTo(key1), equalTo(key2))); + assertThat(brpopDoubleTimeoutMultiple.getValue(), anyOf(equalTo(value1), equalTo(value2))); + } + + @Test + public void testRpoplpushAndBrpoplpush() { + String srcKey = "sourceList"; + String dstKey = "destinationList"; + String value1 = "value1"; + String value2 = "value2"; + + String noResult = exec(commandObjects.rpoplpush(srcKey, dstKey)); + assertThat(noResult, nullValue()); + + exec(commandObjects.lpush(srcKey, value1)); + + String result = exec(commandObjects.rpoplpush(srcKey, dstKey)); + assertThat(result, equalTo(value1)); + + List dstList = exec(commandObjects.lrange(dstKey, 0, -1)); + assertThat(dstList, contains(value1)); + + exec(commandObjects.lpush(srcKey, value2)); + + String bResult = exec(commandObjects.brpoplpush(srcKey, dstKey, 1)); + assertThat(bResult, equalTo(value2)); + + dstList = exec(commandObjects.lrange(dstKey, 0, -1)); + assertThat(dstList, contains(value2, value1)); + } + + @Test + public void testRpoplpushAndBrpoplpushBinary() { + byte[] srcKey = "sourceList".getBytes(); + byte[] dstKey = "destinationList".getBytes(); + byte[] value1 = "value1".getBytes(); + byte[] value2 = "value2".getBytes(); + + exec(commandObjects.lpush(srcKey, value1)); + + byte[] result = exec(commandObjects.rpoplpush(srcKey, dstKey)); + assertThat(result, equalTo(value1)); + + List dstList = exec(commandObjects.lrange(dstKey, 0, -1)); + assertThat(dstList, contains(equalTo(value1))); + + exec(commandObjects.lpush(srcKey, value2)); + + byte[] bResult = exec(commandObjects.brpoplpush(srcKey, dstKey, 1)); + assertThat(bResult, equalTo(value2)); + + dstList = exec(commandObjects.lrange(dstKey, 0, -1)); + assertThat(dstList, contains(equalTo(value2), equalTo(value1))); + } + + @Test + public void testLmoveAndBlmove() { + String srcKey = "sourceList"; + String dstKey = "destinationList"; + String value1 = "value1"; + String value2 = "value2"; + + exec(commandObjects.lpush(srcKey, value1)); + + String result = exec(commandObjects.lmove(srcKey, dstKey, ListDirection.LEFT, ListDirection.RIGHT)); + assertThat(result, equalTo(value1)); + + List dstList = exec(commandObjects.lrange(dstKey, 0, -1)); + assertThat(dstList, contains(value1)); + + exec(commandObjects.lpush(srcKey, value2)); + + String bResult = exec(commandObjects.blmove(srcKey, dstKey, ListDirection.LEFT, ListDirection.LEFT, 1.0)); + assertThat(bResult, equalTo(value2)); + + dstList = exec(commandObjects.lrange(dstKey, 0, -1)); + assertThat(dstList, contains(value2, value1)); + } + + @Test + public void testLmoveAndBlmoveBinary() { + byte[] srcKey = "sourceList".getBytes(); + byte[] dstKey = "destinationList".getBytes(); + byte[] value1 = "value1".getBytes(); + byte[] value2 = "value2".getBytes(); + + exec(commandObjects.lpush(srcKey, value1)); + + byte[] result = exec(commandObjects.lmove(srcKey, dstKey, ListDirection.LEFT, ListDirection.RIGHT)); + assertThat(result, equalTo(value1)); + + List dstList = exec(commandObjects.lrange(dstKey, 0, -1)); + assertThat(dstList.get(0), equalTo(value1)); + + exec(commandObjects.lpush(srcKey, value2)); + + byte[] bResult = exec(commandObjects.blmove(srcKey, dstKey, ListDirection.LEFT, ListDirection.LEFT, 1.0)); + assertThat(bResult, equalTo(value2)); + + dstList = exec(commandObjects.lrange(dstKey, 0, -1)); + assertThat(dstList, contains(equalTo(value2), equalTo(value1))); + } + + @Test + public void testLmpopAndBlmpop() { + String key1 = "list1"; + String key2 = "list2"; + String value1 = "value1"; + String value2 = "value2"; + + exec(commandObjects.lpush(key1, value1, value1, value1, value1, value1, value1)); + exec(commandObjects.lpush(key2, value2, value2, value2, value2, value2, value2)); + + KeyValue> lmpop = exec(commandObjects.lmpop(ListDirection.LEFT, key1, key2)); + assertThat(lmpop.getKey(), anyOf(equalTo(key1), equalTo(key2))); + assertThat(lmpop.getValue(), anyOf(contains(value1), contains(value2))); + + KeyValue> lmpopMultiple = exec(commandObjects.lmpop(ListDirection.LEFT, 2, key1, key2)); + assertThat(lmpopMultiple.getKey(), anyOf(equalTo(key1), equalTo(key2))); + assertThat(lmpopMultiple.getValue(), anyOf(contains(value1, value1), contains(value2, value2))); + + KeyValue> blmpop = exec(commandObjects.blmpop(1.0, ListDirection.LEFT, key1, key2)); + assertThat(blmpop.getKey(), anyOf(equalTo(key1), equalTo(key2))); + assertThat(blmpop.getValue(), anyOf(contains(value1), contains(value2))); + + KeyValue> blmpopMultiple = exec(commandObjects.blmpop(1.0, ListDirection.LEFT, 2, key1, key2)); + assertThat(blmpopMultiple.getKey(), anyOf(equalTo(key1), equalTo(key2))); + assertThat(blmpopMultiple.getValue(), anyOf(contains(value1, value1), contains(value2, value2))); + } + + @Test + public void testLmpopAndBlmpopBinary() { + byte[] key1 = "list1".getBytes(); + byte[] key2 = "list2".getBytes(); + byte[] value1 = "value1".getBytes(); + byte[] value2 = "value2".getBytes(); + + exec(commandObjects.lpush(key1, value1, value1, value1, value1, value1, value1)); + exec(commandObjects.lpush(key2, value2, value2, value2, value2, value2, value2)); + + KeyValue> lmpop = exec(commandObjects.lmpop(ListDirection.LEFT, key1, key2)); + assertThat(lmpop.getKey(), anyOf(equalTo(key1), equalTo(key2))); + assertThat(lmpop.getValue(), anyOf(contains(equalTo(value1)), contains(equalTo(value2)))); + + KeyValue> lmpopMultiple = exec(commandObjects.lmpop(ListDirection.LEFT, 2, key1, key2)); + assertThat(lmpopMultiple.getKey(), anyOf(equalTo(key1), equalTo(key2))); + assertThat(lmpopMultiple.getValue(), anyOf(contains(equalTo(value1), equalTo(value1)), contains(equalTo(value2), equalTo(value2)))); + + KeyValue> blmpop = exec(commandObjects.blmpop(1.0, ListDirection.LEFT, key1, key2)); + assertThat(blmpop.getKey(), anyOf(equalTo(key1), equalTo(key2))); + assertThat(blmpop.getValue(), anyOf(contains(equalTo(value1)), contains(equalTo(value2)))); + + KeyValue> blmpopMultiple = exec(commandObjects.blmpop(1.0, ListDirection.LEFT, 2, key1, key2)); + assertThat(blmpopMultiple.getKey(), anyOf(equalTo(key1), equalTo(key2))); + assertThat(blmpopMultiple.getValue(), anyOf(contains(equalTo(value1), equalTo(value1)), contains(equalTo(value2), equalTo(value2)))); + } +} diff --git a/src/test/java/redis/clients/jedis/commands/commandobjects/CommandObjectsModulesTestBase.java b/src/test/java/redis/clients/jedis/commands/commandobjects/CommandObjectsModulesTestBase.java new file mode 100644 index 00000000000..3bac716fa4a --- /dev/null +++ b/src/test/java/redis/clients/jedis/commands/commandobjects/CommandObjectsModulesTestBase.java @@ -0,0 +1,19 @@ +package redis.clients.jedis.commands.commandobjects; + +import redis.clients.jedis.HostAndPort; +import redis.clients.jedis.Protocol; +import redis.clients.jedis.RedisProtocol; + +/** + * Base class for tests that need a Redis Stack server. + */ +public abstract class CommandObjectsModulesTestBase extends CommandObjectsTestBase { + + private static final String address = + System.getProperty("modulesDocker", Protocol.DEFAULT_HOST + ':' + 6479); + + public CommandObjectsModulesTestBase(RedisProtocol protocol) { + super(protocol, HostAndPort.from(address), null); + } + +} diff --git a/src/test/java/redis/clients/jedis/commands/commandobjects/CommandObjectsScriptingCommandsTest.java b/src/test/java/redis/clients/jedis/commands/commandobjects/CommandObjectsScriptingCommandsTest.java new file mode 100644 index 00000000000..7b6c1feae90 --- /dev/null +++ b/src/test/java/redis/clients/jedis/commands/commandobjects/CommandObjectsScriptingCommandsTest.java @@ -0,0 +1,815 @@ +package redis.clients.jedis.commands.commandobjects; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.contains; +import static org.hamcrest.Matchers.containsString; +import static org.hamcrest.Matchers.empty; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.hasEntry; +import static org.hamcrest.Matchers.hasKey; +import static org.hamcrest.Matchers.hasSize; +import static org.hamcrest.Matchers.notNullValue; +import static org.hamcrest.Matchers.nullValue; +import static org.junit.Assert.assertThrows; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Map; + +import org.junit.Test; +import redis.clients.jedis.RedisProtocol; +import redis.clients.jedis.args.FlushMode; +import redis.clients.jedis.args.FunctionRestorePolicy; +import redis.clients.jedis.exceptions.JedisException; +import redis.clients.jedis.resps.FunctionStats; +import redis.clients.jedis.resps.LibraryInfo; + +/** + * Tests related to Scripting commands. + */ +public class CommandObjectsScriptingCommandsTest extends CommandObjectsStandaloneTestBase { + + public CommandObjectsScriptingCommandsTest(RedisProtocol protocol) { + super(protocol); + } + + @Test + public void testEvalWithOnlyScript() { + String set = exec(commandObjects.set("foo", "bar")); + assertThat(set, equalTo("OK")); + + String script = "return redis.call('get', 'foo')"; + + Object eval = exec(commandObjects.eval(script)); + assertThat(eval, equalTo("bar")); + + Object evalBinary = exec(commandObjects.eval(script.getBytes())); + assertThat(evalBinary, equalTo("bar".getBytes())); + + // eval with incorrect script + assertThrows(JedisException.class, + () -> exec(commandObjects.eval("return x"))); + } + + @Test + public void testEvalWithScriptAndSampleKey() { + String set = exec(commandObjects.set("foo", "bar")); + assertThat(set, equalTo("OK")); + + String script = "return redis.call('get', 'foo');"; + + Object eval = exec(commandObjects.eval(script, "sampleKey")); + assertThat(eval, equalTo("bar")); + + Object evalBinary = exec(commandObjects.eval(script.getBytes(), "sampleKey".getBytes())); + assertThat(evalBinary, equalTo("bar".getBytes())); + } + + @Test + public void testEvalWithScriptKeyCountAndParams() { + exec(commandObjects.set("key1", "value1")); + exec(commandObjects.set("key2", "value2")); + + // Script to get values of two keys and compare them + String script = "if redis.call('get', KEYS[1]) == ARGV[1] and redis.call('get', KEYS[2]) == ARGV[2] then return 'true' else return 'false' end"; + + Object evalTrue = exec(commandObjects.eval( + script, 2, "key1", "key2", "value1", "value2")); + + assertThat(evalTrue, equalTo("true")); + + Object evalTrueBinary = exec(commandObjects.eval( + script.getBytes(), 2, "key1".getBytes(), "key2".getBytes(), "value1".getBytes(), "value2".getBytes())); + + assertThat(evalTrueBinary, equalTo("true".getBytes())); + + Object evalFalse = exec(commandObjects.eval( + script, 2, "key1", "key2", "value1", "value3")); + + assertThat(evalFalse, equalTo("false")); + + Object evalFalseBinary = exec(commandObjects.eval( + script.getBytes(), 2, "key1".getBytes(), "key2".getBytes(), "value1".getBytes(), "value3".getBytes())); + + assertThat(evalFalseBinary, equalTo("false".getBytes())); + + // Incorrect number of keys specified + assertThrows(JedisException.class, + () -> exec(commandObjects.eval(script, 1, "key1", "value1", "value2"))); + } + + @Test + public void testEvalWithScriptKeysAndArgsList() { + exec(commandObjects.hset("fruits", "apples", "5")); + exec(commandObjects.hset("fruits", "bananas", "3")); + exec(commandObjects.hset("fruits", "oranges", "4")); + + // Script to sum the values for the fruits provided as args. The hash name is provided as key. + // The sum is written to a string value whose name is also provided as keys. + String script = "local sum = 0\n" + + "for i, fruitKey in ipairs(ARGV) do\n" + + " local value = redis.call('HGET', KEYS[1], fruitKey)\n" + + " if value then\n" + + " sum = sum + tonumber(value)\n" + + " end\n" + + "end\n" + + "redis.call('SET', KEYS[2], sum)\n" + + "return sum"; + + String initialTotal = exec(commandObjects.get("total")); + assertThat(initialTotal, nullValue()); + + Object eval = exec(commandObjects.eval(script, + Arrays.asList("fruits", "total"), Arrays.asList("apples", "bananas", "oranges"))); + + assertThat(eval, equalTo(12L)); + + String totalAfterEval = exec(commandObjects.get("total")); + assertThat(totalAfterEval, equalTo("12")); + + // reset + assertThat(exec(commandObjects.del("total")), equalTo(1L)); + + // binary + String initialTotalBinary = exec(commandObjects.get("total")); + assertThat(initialTotalBinary, nullValue()); + + Object evalBinary = exec(commandObjects.eval(script.getBytes(), + Arrays.asList("fruits".getBytes(), "total".getBytes()), Arrays.asList("apples".getBytes(), "bananas".getBytes(), "oranges".getBytes()))); + + assertThat(evalBinary, equalTo(12L)); + + String totalAfterEvalBinary = exec(commandObjects.get("total")); + assertThat(totalAfterEvalBinary, equalTo("12")); + } + + @Test + public void testEvalReadonlyWithScriptKeysAndArgsList() { + exec(commandObjects.set("readonlyKey1", "readonlyValue1")); + exec(commandObjects.set("readonlyKey2", "readonlyValue2")); + + // Script to retrieve values for provided keys, concatenates + String script = "return redis.call('get', KEYS[1]) .. redis.call('get', KEYS[2])"; + + Object eval = exec(commandObjects.evalReadonly( + script, Arrays.asList("readonlyKey1", "readonlyKey2"), Collections.emptyList())); + + assertThat(eval, equalTo("readonlyValue1readonlyValue2")); + + Object evalBinary = exec(commandObjects.evalReadonly( + script.getBytes(), Arrays.asList("readonlyKey1".getBytes(), "readonlyKey2".getBytes()), Collections.emptyList())); + + assertThat(evalBinary, equalTo("readonlyValue1readonlyValue2".getBytes())); + } + + @Test + public void testEvalshaWithSha1() { + String script = "return 42"; + String sha1 = exec(commandObjects.scriptLoad(script)); + assertThat(sha1, notNullValue()); + + Object eval = exec(commandObjects.evalsha(sha1)); + assertThat(eval, equalTo(42L)); + + Object evalBinary = exec(commandObjects.evalsha(sha1.getBytes())); + assertThat(evalBinary, equalTo(42L)); + + // incorrect SHA1 hash + assertThrows(JedisException.class, + () -> exec(commandObjects.evalsha("incorrectSha1"))); + } + + @Test + public void testEvalshaWithSha1AndSampleKey() { + String script = "return redis.call('get', 'foo')"; + String sha1 = exec(commandObjects.scriptLoad(script)); + assertThat(sha1, notNullValue()); + + exec(commandObjects.set("foo", "bar")); + + Object eval = exec(commandObjects.evalsha(sha1, "sampleKey")); + + assertThat(eval, equalTo("bar")); + + Object evalBinary = exec(commandObjects.evalsha(sha1.getBytes(), "sampleKey".getBytes())); + + assertThat(evalBinary, equalTo("bar".getBytes())); + } + + @Test + public void testEvalWithScriptKeyCountAndParamsSha() { + exec(commandObjects.set("key1", "value1")); + exec(commandObjects.set("key2", "value2")); + + // Script to get values of two keys and compare them with expected values + String script = "if redis.call('get', KEYS[1]) == ARGV[1] and redis.call('get', KEYS[2]) == ARGV[2] then return 'true' else return 'false' end"; + String sha1 = exec(commandObjects.scriptLoad(script)); + assertThat(sha1, notNullValue()); + + Object evalTrue = exec(commandObjects.evalsha( + sha1, 2, "key1", "key2", "value1", "value2")); + + assertThat(evalTrue, equalTo("true")); + + Object evalTrueBinary = exec(commandObjects.evalsha( + sha1.getBytes(), 2, "key1".getBytes(), "key2".getBytes(), "value1".getBytes(), "value2".getBytes())); + + assertThat(evalTrueBinary, equalTo("true".getBytes())); + + Object evalFalse = exec(commandObjects.evalsha( + sha1, 2, "key1", "key2", "value1", "value3")); + + assertThat(evalFalse, equalTo("false")); + + Object evalFalseBinary = exec(commandObjects.evalsha( + sha1.getBytes(), 2, "key1".getBytes(), "key2".getBytes(), "value1".getBytes(), "value3".getBytes())); + + assertThat(evalFalseBinary, equalTo("false".getBytes())); + + // Incorrect number of keys + assertThrows(JedisException.class, + () -> exec(commandObjects.evalsha(sha1, 1, "key1", "value1", "value2"))); + } + + @Test + public void testEvalWithScriptKeysAndArgsListSha() { + exec(commandObjects.hset("fruits", "apples", "5")); + exec(commandObjects.hset("fruits", "bananas", "3")); + exec(commandObjects.hset("fruits", "oranges", "4")); + + // Sums the values for given fruits, stores the result, and returns it + String script = "local sum = 0\n" + + "for i, fruitKey in ipairs(ARGV) do\n" + + " local value = redis.call('HGET', KEYS[1], fruitKey)\n" + + " if value then\n" + + " sum = sum + tonumber(value)\n" + + " end\n" + + "end\n" + + "redis.call('SET', KEYS[2], sum)\n" + + "return sum"; + String sha1 = exec(commandObjects.scriptLoad(script)); + assertThat(sha1, notNullValue()); + + String initialTotal = exec(commandObjects.get("total")); + assertThat(initialTotal, nullValue()); + + Object eval = exec(commandObjects.evalsha( + sha1, Arrays.asList("fruits", "total"), Arrays.asList("apples", "bananas", "oranges"))); + + assertThat(eval, equalTo(12L)); + + String totalAfterEval = exec(commandObjects.get("total")); + assertThat(totalAfterEval, equalTo("12")); + + // reset + assertThat(exec(commandObjects.del("total")), equalTo(1L)); + + // binary + String initialTotalBinary = exec(commandObjects.get("total")); + assertThat(initialTotalBinary, nullValue()); + + Object evalBinary = exec(commandObjects.evalsha( + sha1.getBytes(), + Arrays.asList("fruits".getBytes(), "total".getBytes()), + Arrays.asList("apples".getBytes(), "bananas".getBytes(), "oranges".getBytes()))); + + assertThat(evalBinary, equalTo(12L)); + + String totalAfterEvalBinary = exec(commandObjects.get("total")); + assertThat(totalAfterEvalBinary, equalTo("12")); + } + + @Test + public void testEvalReadonlyWithScriptKeysAndArgsListSha() { + exec(commandObjects.set("readonlyKey1", "readonlyValue1")); + exec(commandObjects.set("readonlyKey2", "readonlyValue2")); + + // Script to retrieve values for provided keys, concatenated + String script = "return redis.call('get', KEYS[1]) .. redis.call('get', KEYS[2])"; + String sha1 = exec(commandObjects.scriptLoad(script)); + assertThat(sha1, notNullValue()); + + Object eval = exec(commandObjects.evalshaReadonly( + sha1, + Arrays.asList("readonlyKey1", "readonlyKey2"), + Collections.emptyList())); + + assertThat(eval, equalTo("readonlyValue1readonlyValue2")); + + Object evalBinary = exec(commandObjects.evalshaReadonly( + sha1.getBytes(), + Arrays.asList("readonlyKey1".getBytes(), "readonlyKey2".getBytes()), + Collections.emptyList())); + + assertThat(evalBinary, equalTo("readonlyValue1readonlyValue2".getBytes())); + } + + @Test + public void testScriptExists() { + String script = "return 'test script'"; + String sha1 = exec(commandObjects.scriptLoad(script)); + assertThat(sha1, notNullValue()); + + List exists = exec(commandObjects.scriptExists(Collections.singletonList(sha1))); + + assertThat(exists, contains(true)); + + // Load another script to test with multiple SHA1 hashes + String anotherScript = "return 'another test script'"; + String anotherSha1 = exec(commandObjects.scriptLoad(anotherScript)); + assertThat(anotherSha1, notNullValue()); + + String nonExistingSha1 = "nonexistentsha1"; + + List existsMultiple = exec(commandObjects.scriptExists( + "sampleKey", sha1, anotherSha1, nonExistingSha1)); + + assertThat(existsMultiple, contains(true, true, false)); + + List existsMultipleBinary = exec(commandObjects.scriptExists( + "sampleKey".getBytes(), sha1.getBytes(), anotherSha1.getBytes(), nonExistingSha1.getBytes())); + + assertThat(existsMultipleBinary, contains(true, true, false)); + } + + @Test + public void testScriptLoadAndRun() { + String script = "return 'Hello, Redis!'"; + String sha1 = exec(commandObjects.scriptLoad(script)); + assertThat(sha1, notNullValue()); + + Object scriptResponse1 = exec(commandObjects.evalsha(sha1)); + assertThat(scriptResponse1, equalTo("Hello, Redis!")); + } + + @Test + public void testScriptLoadAndRunSampleKey() { + String anotherScript = "return redis.call('get', 'testKey')"; + + String sampleKey = "testKey"; + exec(commandObjects.set(sampleKey, "sampleValue")); // Set a value for the sampleKey + + String anotherSha1 = exec(commandObjects.scriptLoad(anotherScript, sampleKey)); + assertThat(anotherSha1, notNullValue()); + + Object scriptResponse2 = exec(commandObjects.evalsha(anotherSha1, sampleKey)); + assertThat(scriptResponse2, equalTo("sampleValue")); + } + + @Test + public void testScriptLoadAndRunSampleKeyBinary() { + String anotherScript = "return redis.call('get', 'testKey')"; + + String sampleKey = "testKey"; + exec(commandObjects.set(sampleKey, "sampleValue")); // Set a value for the sampleKey + + byte[] anotherSha1 = exec(commandObjects.scriptLoad(anotherScript.getBytes(), sampleKey.getBytes())); + assertThat(anotherSha1, notNullValue()); + + Object scriptResponse2 = exec(commandObjects.evalsha(anotherSha1, sampleKey.getBytes())); + assertThat(scriptResponse2, equalTo("sampleValue".getBytes())); + } + + @Test + public void testScriptFlush() { + String script = "return 'test script flush'"; + String sha1 = exec(commandObjects.scriptLoad(script)); + assertThat(sha1, notNullValue()); + + List existsBefore = exec(commandObjects.scriptExists(Collections.singletonList(sha1))); + assertThat(existsBefore, contains(true)); + + String flush = exec(commandObjects.scriptFlush()); + assertThat(flush, equalTo("OK")); + + List existsAfter = exec(commandObjects.scriptExists(Collections.singletonList(sha1))); + assertThat(existsAfter, contains(false)); + } + + @Test + public void testScriptFlushSampleKeyAndMode() { + String script = "return 'test script flush'"; + String sha1 = exec(commandObjects.scriptLoad(script)); + assertThat(sha1, notNullValue()); + + List existsBefore = exec(commandObjects.scriptExists(Collections.singletonList(sha1))); + assertThat(existsBefore, contains(true)); + + String flush = exec(commandObjects.scriptFlush("anyKey", FlushMode.SYNC)); + assertThat(flush, equalTo("OK")); + + List existsAfter = exec(commandObjects.scriptExists(Collections.singletonList(sha1))); + assertThat(existsAfter, contains(false)); + } + + @Test + public void testScriptFlushSampleKey() { + String script = "return 'test script flush'"; + String sha1 = exec(commandObjects.scriptLoad(script)); + assertThat(sha1, notNullValue()); + + List existsBefore = exec(commandObjects.scriptExists(Collections.singletonList(sha1))); + assertThat(existsBefore, contains(true)); + + String flush = exec(commandObjects.scriptFlush("anyKey")); + assertThat(flush, equalTo("OK")); + + List existsAfter = exec(commandObjects.scriptExists(Collections.singletonList(sha1))); + assertThat(existsAfter, contains(false)); + } + + @Test + public void testScriptFlushBinary() { + String script = "return 'test script flush'"; + String sha1 = exec(commandObjects.scriptLoad(script)); + assertThat(sha1, notNullValue()); + + List existsBefore = exec(commandObjects.scriptExists(Collections.singletonList(sha1))); + assertThat(existsBefore, contains(true)); + + String flush = exec(commandObjects.scriptFlush("anyKey".getBytes())); + assertThat(flush, equalTo("OK")); + + List existsAfter = exec(commandObjects.scriptExists(Collections.singletonList(sha1))); + assertThat(existsAfter, contains(false)); + } + + @Test + public void testScriptFlushSampleKeyAndModeBinary() { + String script = "return 'test script flush'"; + String sha1 = exec(commandObjects.scriptLoad(script)); + assertThat(sha1, notNullValue()); + + List existsBefore = exec(commandObjects.scriptExists(Collections.singletonList(sha1))); + assertThat(existsBefore, contains(true)); + + String flush = exec(commandObjects.scriptFlush("anyKey".getBytes(), FlushMode.SYNC)); + assertThat(flush, equalTo("OK")); + + List existsAfter = exec(commandObjects.scriptExists(Collections.singletonList(sha1))); + assertThat(existsAfter, contains(false)); + } + + @Test + public void testScriptKill() { + JedisException e = assertThrows(JedisException.class, + () -> exec(commandObjects.scriptKill())); + assertThat(e.getMessage(), containsString("No scripts in execution right now.")); + + e = assertThrows(JedisException.class, + () -> exec(commandObjects.scriptKill("anyKey"))); + assertThat(e.getMessage(), containsString("No scripts in execution right now.")); + + e = assertThrows(JedisException.class, + () -> exec(commandObjects.scriptKill("anyKey".getBytes()))); + assertThat(e.getMessage(), containsString("No scripts in execution right now.")); + } + + @Test + public void testSumValuesFunction() { + String luaScript = "#!lua name=mylib\n" + + "redis.register_function('sumValues', function(keys, args)\n" + + "local sum = 0\n" + + "for _, key in ipairs(keys) do\n" + + "local val = redis.call('GET', key)\n" + + "if val then sum = sum + tonumber(val) end\n" + + "end\n" + + "redis.call('SET', 'total', sum)\n" + + "return sum\n" + + "end)"; + String functionLoad = exec(commandObjects.functionLoad(luaScript)); + assertThat(functionLoad, equalTo("mylib")); + + exec(commandObjects.set("key1", "10")); + exec(commandObjects.set("key2", "20")); + exec(commandObjects.set("key3", "30")); + + String initialTotal = exec(commandObjects.get("total")); + assertThat(initialTotal, nullValue()); + + Object fcall = exec(commandObjects.fcall( + "sumValues", + Arrays.asList("key1", "key2", "key3"), + new ArrayList<>())); + + assertThat(fcall, equalTo(60L)); + + String totalAfterFcall = exec(commandObjects.get("total")); + assertThat(totalAfterFcall, equalTo("60")); + + // reset + exec(commandObjects.del("total")); + + String totalAfterRest = exec(commandObjects.get("total")); + assertThat(totalAfterRest, nullValue()); + + Object fcallBinary = exec(commandObjects.fcall( + "sumValues".getBytes(), + Arrays.asList("key1".getBytes(), "key2".getBytes(), "key3".getBytes()), + new ArrayList<>())); + + assertThat(fcallBinary, equalTo(60L)); + + String totalAfterFcallBinary = exec(commandObjects.get("total")); + assertThat(totalAfterFcallBinary, equalTo("60")); + } + + @Test + public void testSumValuesFunctionReadonly() { + String luaScript = "#!lua name=mylib\n" + + "redis.register_function{function_name='sumValues', callback=function(keys, args)\n" + + "local sum = 0\n" + + "for _, key in ipairs(keys) do\n" + + "local val = redis.call('GET', key)\n" + + "if val then sum = sum + tonumber(val) end\n" + + "end\n" + + "return sum\n" + + "end, flags={'no-writes'}}"; + String functionLoad = exec(commandObjects.functionLoad(luaScript)); + assertThat(functionLoad, equalTo("mylib")); + + exec(commandObjects.set("key1", "10")); + exec(commandObjects.set("key2", "20")); + exec(commandObjects.set("key3", "30")); + + Object fcall = exec(commandObjects.fcallReadonly( + "sumValues", + Arrays.asList("key1", "key2", "key3"), + new ArrayList<>())); + + assertThat(fcall, equalTo(60L)); + + Object fcallBinary = exec(commandObjects.fcallReadonly( + "sumValues".getBytes(), + Arrays.asList("key1".getBytes(), "key2".getBytes(), "key3".getBytes()), + new ArrayList<>())); + + assertThat(fcallBinary, equalTo(60L)); + } + + @Test + public void testFunctionDeletion() { + String luaScript = "#!lua name=mylib\n" + + "redis.register_function('sumValues', function(keys, args) return 42 end)"; + exec(commandObjects.functionLoad(luaScript)); + + String libraryName = "mylib"; + + List listResponse = exec(commandObjects.functionList()); + + assertThat(listResponse, hasSize(1)); + assertThat(listResponse.get(0).getLibraryName(), equalTo(libraryName)); + assertThat(listResponse.get(0).getFunctions(), hasSize(1)); + assertThat(listResponse.get(0).getFunctions().get(0), hasEntry("name", "sumValues")); + + String delete = exec(commandObjects.functionDelete(libraryName)); + assertThat(delete, equalTo("OK")); + + listResponse = exec(commandObjects.functionList()); + assertThat(listResponse, empty()); + } + + @Test + public void testFunctionDeletionBinary() { + String luaScript = "#!lua name=mylib\n" + + "redis.register_function('sumValues', function(keys, args) return 42 end)"; + exec(commandObjects.functionLoad(luaScript)); + + String libraryName = "mylib"; + + List listResponse = exec(commandObjects.functionList()); + + assertThat(listResponse, hasSize(1)); + assertThat(listResponse.get(0).getLibraryName(), equalTo(libraryName)); + assertThat(listResponse.get(0).getFunctions(), hasSize(1)); + assertThat(listResponse.get(0).getFunctions().get(0), hasEntry("name", "sumValues")); + + String deleteBinary = exec(commandObjects.functionDelete(libraryName.getBytes())); + assertThat(deleteBinary, equalTo("OK")); + + listResponse = exec(commandObjects.functionList()); + assertThat(listResponse, empty()); + } + + @Test + public void testFunctionListing() { + String luaScript = "#!lua name=mylib\n" + + "redis.register_function('sumValues', function(keys, args) return 42 end)"; + exec(commandObjects.functionLoad(luaScript)); + + String libraryName = "mylib"; + + List list = exec(commandObjects.functionList()); + + assertThat(list, hasSize(1)); + assertThat(list.get(0).getLibraryName(), equalTo(libraryName)); + assertThat(list.get(0).getFunctions(), hasSize(1)); + assertThat(list.get(0).getFunctions().get(0), hasEntry("name", "sumValues")); + assertThat(list.get(0).getLibraryCode(), nullValue()); + + List listBinary = exec(commandObjects.functionListBinary()); + + assertThat(listBinary, hasSize(1)); + + List listLibrary = exec(commandObjects.functionList(libraryName)); + + assertThat(listLibrary, hasSize(1)); + assertThat(listLibrary.get(0).getLibraryName(), equalTo(libraryName)); + assertThat(listLibrary.get(0).getFunctions(), hasSize(1)); + assertThat(listLibrary.get(0).getFunctions().get(0), hasEntry("name", "sumValues")); + assertThat(listLibrary.get(0).getLibraryCode(), nullValue()); + + List listLibraryBinary = exec(commandObjects.functionList(libraryName.getBytes())); + + assertThat(listLibraryBinary, hasSize(1)); + + List listWithCode = exec(commandObjects.functionListWithCode()); + + assertThat(listWithCode, hasSize(1)); + assertThat(listWithCode.get(0).getLibraryName(), equalTo(libraryName)); + assertThat(listWithCode.get(0).getFunctions(), hasSize(1)); + assertThat(listWithCode.get(0).getFunctions().get(0), hasEntry("name", "sumValues")); + assertThat(listWithCode.get(0).getLibraryCode(), notNullValue()); + + List listWithCodeBinary = exec(commandObjects.functionListWithCodeBinary()); + + assertThat(listWithCodeBinary, hasSize(1)); + + List listWithCodeLibrary = exec(commandObjects.functionListWithCode(libraryName)); + + assertThat(listWithCodeLibrary, hasSize(1)); + assertThat(listWithCodeLibrary.get(0).getLibraryName(), equalTo(libraryName)); + assertThat(listWithCodeLibrary.get(0).getFunctions(), hasSize(1)); + assertThat(listWithCodeLibrary.get(0).getFunctions().get(0), hasEntry("name", "sumValues")); + assertThat(listWithCodeLibrary.get(0).getLibraryCode(), notNullValue()); + + List listWithCodeLibraryBinary = exec(commandObjects.functionListWithCode(libraryName.getBytes())); + + assertThat(listWithCodeLibraryBinary, hasSize(1)); + } + + @Test + public void testFunctionReload() { + String luaScript = "#!lua name=mylib\n" + + "redis.register_function('dummy', function(keys, args) return 42 end)"; + String loadResult = exec(commandObjects.functionLoad(luaScript)); + assertThat(loadResult, equalTo("mylib")); + + Object result = exec(commandObjects.fcall( + "dummy".getBytes(), new ArrayList<>(), new ArrayList<>())); + assertThat(result, equalTo(42L)); + + String luaScriptChanged = "#!lua name=mylib\n" + + "redis.register_function('dummy', function(keys, args) return 52 end)"; + String replaceResult = exec(commandObjects.functionLoadReplace(luaScriptChanged)); + assertThat(replaceResult, equalTo("mylib")); + + Object resultAfter = exec(commandObjects.fcall( + "dummy".getBytes(), new ArrayList<>(), new ArrayList<>())); + assertThat(resultAfter, equalTo(52L)); + } + + @Test + public void testFunctionReloadBinary() { + String luaScript = "#!lua name=mylib\n" + + "redis.register_function('dummy', function(keys, args) return 42 end)"; + String loadResult = exec(commandObjects.functionLoad(luaScript.getBytes())); + assertThat(loadResult, equalTo("mylib")); + + Object result = exec(commandObjects.fcall(( + "dummy").getBytes(), new ArrayList<>(), new ArrayList<>())); + assertThat(result, equalTo(42L)); + + String luaScriptChanged = "#!lua name=mylib\n" + + "redis.register_function('dummy', function(keys, args) return 52 end)"; + String replaceResult = exec(commandObjects.functionLoadReplace(luaScriptChanged.getBytes())); + assertThat(replaceResult, equalTo("mylib")); + + Object resultAfter = exec(commandObjects.fcall( + "dummy".getBytes(), new ArrayList<>(), new ArrayList<>())); + assertThat(resultAfter, equalTo(52L)); + } + + @Test + public void testFunctionStats() { + String luaScript = "#!lua name=mylib\n" + + "redis.register_function('dummy', function(keys, args) return 42 end)"; + String loadResult = exec(commandObjects.functionLoad(luaScript)); + assertThat(loadResult, equalTo("mylib")); + + for (int i = 0; i < 5; i++) { + Object result = exec(commandObjects.fcall( + "dummy".getBytes(), new ArrayList<>(), new ArrayList<>())); + assertThat(result, equalTo(42L)); + } + + FunctionStats stats = exec(commandObjects.functionStats()); + + assertThat(stats, notNullValue()); + assertThat(stats.getEngines(), hasKey("LUA")); + Map luaStats = stats.getEngines().get("LUA"); + assertThat(luaStats, hasEntry("libraries_count", 1L)); + assertThat(luaStats, hasEntry("functions_count", 1L)); + + Object statsBinary = exec(commandObjects.functionStatsBinary()); + + assertThat(statsBinary, notNullValue()); + } + + @Test + public void testFunctionDumpFlushRestore() { + String luaScript = "#!lua name=mylib\n" + + "redis.register_function('sumValues', function(keys, args) return 42 end)"; + exec(commandObjects.functionLoad(luaScript)); + + String libraryName = "mylib"; + + List list = exec(commandObjects.functionList()); + assertThat(list, hasSize(1)); + assertThat(list.get(0).getLibraryName(), equalTo(libraryName)); + assertThat(list.get(0).getFunctions(), hasSize(1)); + assertThat(list.get(0).getFunctions().get(0), hasEntry("name", "sumValues")); + + byte[] dump = exec(commandObjects.functionDump()); + assertThat(dump, notNullValue()); + + String flush = exec(commandObjects.functionFlush()); + assertThat(flush, equalTo("OK")); + + list = exec(commandObjects.functionList()); + assertThat(list, empty()); + + String restore = exec(commandObjects.functionRestore(dump)); + assertThat(restore, equalTo("OK")); + + list = exec(commandObjects.functionList()); + assertThat(list, hasSize(1)); + assertThat(list.get(0).getLibraryName(), equalTo(libraryName)); + assertThat(list.get(0).getFunctions(), hasSize(1)); + assertThat(list.get(0).getFunctions().get(0), hasEntry("name", "sumValues")); + } + + @Test + public void testFunctionDumpFlushRestoreWithPolicy() { + String luaScript = "#!lua name=mylib\n" + + "redis.register_function('sumValues', function(keys, args) return 42 end)"; + exec(commandObjects.functionLoad(luaScript)); + + String libraryName = "mylib"; + + List list = exec(commandObjects.functionList()); + assertThat(list, hasSize(1)); + assertThat(list.get(0).getLibraryName(), equalTo(libraryName)); + assertThat(list.get(0).getFunctions(), hasSize(1)); + assertThat(list.get(0).getFunctions().get(0), hasEntry("name", "sumValues")); + + byte[] dump = exec(commandObjects.functionDump()); + assertThat(dump, notNullValue()); + + String flush = exec(commandObjects.functionFlush()); + assertThat(flush, equalTo("OK")); + + list = exec(commandObjects.functionList()); + assertThat(list, empty()); + + String restore = exec(commandObjects.functionRestore(dump, FunctionRestorePolicy.REPLACE)); + assertThat(restore, equalTo("OK")); + + list = exec(commandObjects.functionList()); + assertThat(list, hasSize(1)); + assertThat(list.get(0).getLibraryName(), equalTo(libraryName)); + assertThat(list.get(0).getFunctions(), hasSize(1)); + assertThat(list.get(0).getFunctions().get(0), hasEntry("name", "sumValues")); + } + + @Test + public void testFunctionFlushWithMode() { + String luaScript = "#!lua name=mylib\n" + + "redis.register_function('sumValues', function(keys, args) return 42 end)"; + exec(commandObjects.functionLoad(luaScript)); + + String libraryName = "mylib"; + + List list = exec(commandObjects.functionList()); + + assertThat(list, hasSize(1)); + assertThat(list.get(0).getLibraryName(), equalTo(libraryName)); + assertThat(list.get(0).getFunctions(), hasSize(1)); + assertThat(list.get(0).getFunctions().get(0), hasEntry("name", "sumValues")); + + String flush = exec(commandObjects.functionFlush(FlushMode.SYNC)); + assertThat(flush, equalTo("OK")); + + list = exec(commandObjects.functionList()); + assertThat(list, empty()); + } + + @Test + public void testFunctionKill() { + JedisException e = assertThrows(JedisException.class, + () -> exec(commandObjects.functionKill())); + assertThat(e.getMessage(), containsString("No scripts in execution right now")); + } +} diff --git a/src/test/java/redis/clients/jedis/commands/commandobjects/CommandObjectsSearchAndQueryCommandsTest.java b/src/test/java/redis/clients/jedis/commands/commandobjects/CommandObjectsSearchAndQueryCommandsTest.java new file mode 100644 index 00000000000..d1b1eaacaa4 --- /dev/null +++ b/src/test/java/redis/clients/jedis/commands/commandobjects/CommandObjectsSearchAndQueryCommandsTest.java @@ -0,0 +1,255 @@ +package redis.clients.jedis.commands.commandobjects; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.contains; +import static org.hamcrest.Matchers.empty; +import static org.hamcrest.Matchers.emptyOrNullString; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.hasEntry; +import static org.hamcrest.Matchers.hasSize; +import static org.hamcrest.Matchers.not; +import static org.hamcrest.Matchers.notNullValue; +import static org.hamcrest.Matchers.nullValue; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +import org.json.JSONObject; +import org.junit.Test; +import redis.clients.jedis.RedisProtocol; +import redis.clients.jedis.args.SortingOrder; +import redis.clients.jedis.json.Path2; +import redis.clients.jedis.search.Document; +import redis.clients.jedis.search.FTSearchParams; +import redis.clients.jedis.search.IndexDefinition; +import redis.clients.jedis.search.IndexOptions; +import redis.clients.jedis.search.Query; +import redis.clients.jedis.search.Schema; +import redis.clients.jedis.search.SearchResult; +import redis.clients.jedis.search.aggr.AggregationBuilder; +import redis.clients.jedis.search.aggr.AggregationResult; +import redis.clients.jedis.search.aggr.Reducers; + +/** + * Tests related to Search and query commands. + */ +public class CommandObjectsSearchAndQueryCommandsTest extends CommandObjectsModulesTestBase { + + public CommandObjectsSearchAndQueryCommandsTest(RedisProtocol protocol) { + super(protocol); + } + + @Test + public void testFtSearchHash() { + String indexName = "booksIndex"; + + IndexDefinition indexDefinition = + new IndexDefinition(IndexDefinition.Type.HASH).setPrefixes("books:"); + + IndexOptions indexOptions = IndexOptions.defaultOptions().setDefinition(indexDefinition); + + Schema schema = new Schema() + .addField(new Schema.Field("title", Schema.FieldType.TEXT)) + .addField(new Schema.Field("price", Schema.FieldType.NUMERIC)); + + String create = exec(commandObjects.ftCreate(indexName, indexOptions, schema)); + assertThat(create, equalTo("OK")); + + // Set individual fields. + String book1000 = "books:1000"; + + Long hset = exec(commandObjects.hsetObject(book1000, "title", "Redis in Action")); + assertThat(hset, equalTo(1L)); + + hset = exec(commandObjects.hsetObject(book1000, "price", 17.99)); + assertThat(hset, equalTo(1L)); + + hset = exec(commandObjects.hsetObject(book1000, "author", "John Doe")); + assertThat(hset, equalTo(1L)); + + // Set multiple fields. + Map hash = new HashMap<>(); + hash.put("title", "Redis Essentials"); + hash.put("price", 19.99); + hash.put("author", "Jane Doe"); + String book1200 = "books:1200"; + + Long hsetMultiple = exec(commandObjects.hsetObject(book1200, hash)); + assertThat(hsetMultiple, equalTo(3L)); + + // Text search. + SearchResult search = exec(commandObjects.ftSearch(indexName, "Action")); + + assertThat(search.getTotalResults(), equalTo(1L)); + assertThat(search.getDocuments(), hasSize(1)); + + Document document = search.getDocuments().get(0); + assertThat(document.getId(), equalTo(book1000)); + assertThat(document.get("title"), equalTo("Redis in Action")); + assertThat(document.get("price"), equalTo("17.99")); + assertThat(document.get("author"), equalTo("John Doe")); + + // Price range search. + SearchResult searchByPrice = exec(commandObjects.ftSearch(indexName, "@price:[19 +inf]")); + + assertThat(searchByPrice.getTotalResults(), equalTo(1L)); + assertThat(searchByPrice.getDocuments(), hasSize(1)); + + Document documentByPrice = searchByPrice.getDocuments().get(0); + assertThat(documentByPrice.getId(), equalTo(book1200)); + assertThat(documentByPrice.get("title"), equalTo("Redis Essentials")); + assertThat(documentByPrice.get("price"), equalTo("19.99")); + assertThat(documentByPrice.get("author"), equalTo("Jane Doe")); + + // Price range search with sorting. + FTSearchParams ftSearchParams = new FTSearchParams().sortBy("price", SortingOrder.DESC); + SearchResult searchByPriceWithParams = exec(commandObjects.ftSearch(indexName, "@price:[10 20]", ftSearchParams)); + + assertThat(searchByPriceWithParams.getTotalResults(), equalTo(2L)); + assertThat(searchByPriceWithParams.getDocuments(), hasSize(2)); + assertThat(searchByPriceWithParams.getDocuments().stream().map(Document::getId).collect(Collectors.toList()), + contains(book1200, book1000)); + + Query query = new Query() + .addFilter(new Query.NumericFilter("price", 19.0, 20.0)) + .returnFields("price", "title"); + SearchResult searchByPriceWithQuery = exec(commandObjects.ftSearch(indexName, query)); + + assertThat(searchByPriceWithQuery.getTotalResults(), equalTo(1L)); + assertThat(searchByPriceWithQuery.getDocuments(), hasSize(1)); + + Document documentByPriceWithQuery = searchByPriceWithQuery.getDocuments().get(0); + assertThat(documentByPriceWithQuery.getId(), equalTo(book1200)); + assertThat(documentByPriceWithQuery.get("title"), equalTo("Redis Essentials")); + assertThat(documentByPriceWithQuery.get("price"), equalTo("19.99")); + assertThat(documentByPriceWithQuery.get("author"), nullValue()); + } + + @Test + public void testFtSearchJson() { + String indexName = "testIndex"; + + IndexDefinition indexDefinition = new IndexDefinition(IndexDefinition.Type.JSON) + .setPrefixes("books:"); + + IndexOptions indexOptions = IndexOptions.defaultOptions().setDefinition(indexDefinition); + + Schema schema = new Schema() + .addField(new Schema.Field("$.title", Schema.FieldType.TEXT)) + .addField(new Schema.Field("$.price", Schema.FieldType.NUMERIC)); + + String create = exec(commandObjects.ftCreate(indexName, indexOptions, schema)); + assertThat(create, equalTo("OK")); + + Map hash = new HashMap<>(); + hash.put("title", "Redis in Action"); + hash.put("price", 17.99); + hash.put("author", "John Doe"); + + String jsonSet = exec(commandObjects.jsonSet("books:1000", Path2.ROOT_PATH, new JSONObject(hash))); + assertThat(jsonSet, equalTo("OK")); + + Map hash2 = new HashMap<>(); + hash2.put("title", "Redis Essentials"); + hash2.put("price", 19.99); + hash2.put("author", "Jane Doe"); + + String jsonSet2 = exec(commandObjects.jsonSet("books:1200", Path2.ROOT_PATH, new JSONObject(hash2))); + assertThat(jsonSet2, equalTo("OK")); + + SearchResult searchResult = exec(commandObjects.ftSearch(indexName, "Action")); + + assertThat(searchResult.getTotalResults(), equalTo(1L)); + assertThat(searchResult.getDocuments(), hasSize(1)); + + Document document = searchResult.getDocuments().get(0); + assertThat(document.getId(), equalTo("books:1000")); + assertThat(document.get("$"), equalTo("{\"title\":\"Redis in Action\",\"price\":17.99,\"author\":\"John Doe\"}")); + } + + @Test + public void testFtExplain() { + String indexName = "booksIndex"; + + IndexDefinition indexDefinition = new IndexDefinition(IndexDefinition.Type.HASH).setPrefixes("books:"); + + IndexOptions indexOptions = IndexOptions.defaultOptions().setDefinition(indexDefinition); + + Schema schema = new Schema() + .addField(new Schema.Field("title", Schema.FieldType.TEXT)) + .addField(new Schema.Field("price", Schema.FieldType.NUMERIC)); + + String createResult = exec(commandObjects.ftCreate(indexName, indexOptions, schema)); + assertThat(createResult, equalTo("OK")); + + // Add a book to the index + String bookId = "books:123"; + + Map bookFields = new HashMap<>(); + bookFields.put("title", "Redis for Dummies"); + bookFields.put("price", 29.99); + + Long hsetResult = exec(commandObjects.hsetObject(bookId, bookFields)); + assertThat(hsetResult, equalTo(2L)); + + Query query = new Query("Redis").returnFields("title", "price"); + + String explanation = exec(commandObjects.ftExplain(indexName, query)); + assertThat(explanation, not(emptyOrNullString())); + + List explanationCli = exec(commandObjects.ftExplainCLI(indexName, query)); + assertThat(explanationCli, not(empty())); + } + + @Test + public void testFtAggregate() { + String indexName = "booksIndex"; + + IndexDefinition indexDefinition = new IndexDefinition(IndexDefinition.Type.HASH).setPrefixes("books:"); + + IndexOptions indexOptions = IndexOptions.defaultOptions().setDefinition(indexDefinition); + + Schema schema = new Schema() + .addField(new Schema.Field("title", Schema.FieldType.TEXT)) + .addField(new Schema.Field("price", Schema.FieldType.NUMERIC)) + .addField(new Schema.Field("genre", Schema.FieldType.TAG)); + + String createResult = exec(commandObjects.ftCreate(indexName, indexOptions, schema)); + assertThat(createResult, equalTo("OK")); + + // Add books to the index + Map book1Fields = new HashMap<>(); + book1Fields.put("title", "Redis for Dummies"); + book1Fields.put("price", 20.99); + book1Fields.put("genre", "Technology"); + + String book1Id = "books:101"; + + exec(commandObjects.hsetObject(book1Id, book1Fields)); + + Map book2Fields = new HashMap<>(); + book2Fields.put("title", "Advanced Redis"); + book2Fields.put("price", 25.99); + book2Fields.put("genre", "Technology"); + + String book2Id = "books:102"; + + exec(commandObjects.hsetObject(book2Id, book2Fields)); + + // Aggregation: average price of books in the 'Technology' genre + AggregationBuilder aggr = new AggregationBuilder() + .groupBy("@genre", Reducers.avg("@price").as("avgPrice")) + .filter("@genre=='Technology'"); + + AggregationResult aggregationResult = exec(commandObjects.ftAggregate(indexName, aggr)); + + assertThat(aggregationResult, notNullValue()); + assertThat(aggregationResult.getResults(), hasSize(1)); + + Map result = aggregationResult.getResults().get(0); + assertThat(result, hasEntry("genre", "Technology")); + assertThat(result, hasEntry("avgPrice", "23.49")); + } +} diff --git a/src/test/java/redis/clients/jedis/commands/commandobjects/CommandObjectsServerManagementCommandsTest.java b/src/test/java/redis/clients/jedis/commands/commandobjects/CommandObjectsServerManagementCommandsTest.java new file mode 100644 index 00000000000..543f2dc6d9b --- /dev/null +++ b/src/test/java/redis/clients/jedis/commands/commandobjects/CommandObjectsServerManagementCommandsTest.java @@ -0,0 +1,92 @@ +package redis.clients.jedis.commands.commandobjects; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.containsString; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.greaterThan; +import static org.hamcrest.Matchers.greaterThanOrEqualTo; + +import org.junit.Test; +import redis.clients.jedis.CommandObject; +import redis.clients.jedis.RedisProtocol; + +/** + * Tests related to Server management commands. + */ +public class CommandObjectsServerManagementCommandsTest extends CommandObjectsStandaloneTestBase { + + public CommandObjectsServerManagementCommandsTest(RedisProtocol protocol) { + super(protocol); + } + + @Test + public void testSlowLogReset() { + String reset = exec(commandObjects.slowlogReset()); + assertThat(reset, equalTo("OK")); + } + + @Test + public void testMemoryUsage() { + String key = "key"; + int samples = 5; + + exec(commandObjects.set(key, "value")); + + CommandObject memoryUsage = commandObjects.memoryUsage(key); + assertThat(exec(memoryUsage), greaterThan(0L)); + + CommandObject memoryUsageWithSamples = commandObjects.memoryUsage(key, samples); + assertThat(exec(memoryUsageWithSamples), greaterThan(0L)); + + CommandObject memoryUsageBinary = commandObjects.memoryUsage(key.getBytes()); + assertThat(exec(memoryUsageBinary), greaterThan(0L)); + + CommandObject memoryUsageBinaryWithSamples = commandObjects.memoryUsage(key.getBytes(), samples); + assertThat(exec(memoryUsageBinaryWithSamples), greaterThan(0L)); + } + + @Test + public void testObjectRefcount() { + String key = "refcountKey"; + + exec(commandObjects.set(key, "value")); + + Long refcount = exec(commandObjects.objectRefcount(key)); + + assertThat(refcount, greaterThanOrEqualTo(1L)); + + Long refcountBinary = exec(commandObjects.objectRefcount(key.getBytes())); + + assertThat(refcountBinary, greaterThanOrEqualTo(1L)); + } + + @Test + public void testObjectEncoding() { + exec(commandObjects.lpush("lst", "Hello, Redis!")); + + String encoding = exec(commandObjects.objectEncoding("lst")); + + assertThat(encoding, containsString("list")); + + byte[] encodingBinary = exec(commandObjects.objectEncoding("lst".getBytes())); + + assertThat(new String(encodingBinary), containsString("list")); + } + + @Test + public void testObjectIdletime() throws InterruptedException { + String key = "idleTestString"; + String value = "Idle value test"; + + exec(commandObjects.set(key, value)); + + // A small delay to simulate idle time + Thread.sleep(1000); + + Long idleTime = exec(commandObjects.objectIdletime(key)); + assertThat(idleTime, greaterThan(0L)); + + Long idleTimeBinary = exec(commandObjects.objectIdletime(key.getBytes())); + assertThat(idleTimeBinary, greaterThan(0L)); + } +} diff --git a/src/test/java/redis/clients/jedis/commands/commandobjects/CommandObjectsSetCommandsTest.java b/src/test/java/redis/clients/jedis/commands/commandobjects/CommandObjectsSetCommandsTest.java new file mode 100644 index 00000000000..6a6874ef4db --- /dev/null +++ b/src/test/java/redis/clients/jedis/commands/commandobjects/CommandObjectsSetCommandsTest.java @@ -0,0 +1,373 @@ +package redis.clients.jedis.commands.commandobjects; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.anyOf; +import static org.hamcrest.Matchers.contains; +import static org.hamcrest.Matchers.containsInAnyOrder; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.everyItem; +import static org.hamcrest.Matchers.hasSize; +import static org.hamcrest.Matchers.lessThanOrEqualTo; +import static org.hamcrest.Matchers.not; + +import java.util.List; +import java.util.Set; + +import org.junit.Test; +import redis.clients.jedis.RedisProtocol; +import redis.clients.jedis.params.ScanParams; +import redis.clients.jedis.resps.ScanResult; + +/** + * Tests related to Set commands. + */ +public class CommandObjectsSetCommandsTest extends CommandObjectsStandaloneTestBase { + + public CommandObjectsSetCommandsTest(RedisProtocol protocol) { + super(protocol); + } + + @Test + public void testSetCommands() { + String key = "testSet"; + String member1 = "member1"; + String member2 = "member2"; + String member3 = "member3"; + + Long sadd = exec(commandObjects.sadd(key, member1, member2, member3)); + assertThat(sadd, equalTo(3L)); + + Set members = exec(commandObjects.smembers(key)); + assertThat(members, containsInAnyOrder(member1, member2, member3)); + + Long srem = exec(commandObjects.srem(key, member1)); + assertThat(srem, equalTo(1L)); + + Set membersAfterSrem = exec(commandObjects.smembers(key)); + assertThat(membersAfterSrem, containsInAnyOrder(member2, member3)); + } + + @Test + public void testSetCommandsBinary() { + byte[] key = "testSetB".getBytes(); + byte[] member1 = "member1".getBytes(); + byte[] member2 = "member2".getBytes(); + byte[] member3 = "member3".getBytes(); + + Long sadd = exec(commandObjects.sadd(key, member1, member2, member3)); + assertThat(sadd, equalTo(3L)); + + Set members = exec(commandObjects.smembers(key)); + assertThat(members, containsInAnyOrder(member1, member2, member3)); + + Long srem = exec(commandObjects.srem(key, member1)); + assertThat(srem, equalTo(1L)); + + Set membersAfterSrem = exec(commandObjects.smembers(key)); + assertThat(membersAfterSrem, containsInAnyOrder(member2, member3)); + } + + @Test + public void testSpop() { + String key = "testSetPop"; + String member1 = "member1"; + String member2 = "member2"; + String member3 = "member3"; + + Long sadd = exec(commandObjects.sadd(key, member1, member2, member3)); + assertThat(sadd, equalTo(3L)); + + String spop = exec(commandObjects.spop(key)); + assertThat(spop, anyOf(equalTo(member1), equalTo(member2), equalTo(member3))); + + Set spopMultiple = exec(commandObjects.spop(key, 2)); + assertThat(spopMultiple, hasSize(2)); + assertThat(spopMultiple, everyItem(anyOf(equalTo(member1), equalTo(member2), equalTo(member3)))); + assertThat(spopMultiple, not(contains(spop))); + } + + @Test + public void testSpopBinary() { + byte[] bkey = "testSetPopB".getBytes(); + byte[] member1 = "member1".getBytes(); + byte[] member2 = "member2".getBytes(); + byte[] member3 = "member3".getBytes(); + + Long sadd = exec(commandObjects.sadd(bkey, member1, member2, member3)); + assertThat(sadd, equalTo(3L)); + + byte[] spop = exec(commandObjects.spop(bkey)); + assertThat(spop, anyOf(equalTo(member1), equalTo(member2), equalTo(member3))); + + Set spopMultiple = exec(commandObjects.spop(bkey, 2)); + assertThat(spopMultiple, hasSize(2)); + assertThat(spopMultiple, everyItem(anyOf(equalTo(member1), equalTo(member2), equalTo(member3)))); + assertThat(spopMultiple, not(contains(spop))); + } + + @Test + public void testSetMembershipCommands() { + String key = "testSetMembership"; + String member1 = "member1"; + String member2 = "member2"; + + exec(commandObjects.sadd(key, member1, member2)); + + Long scard = exec(commandObjects.scard(key)); + assertThat(scard, equalTo(2L)); + + Long scardBinary = exec(commandObjects.scard(key.getBytes())); + assertThat(scardBinary, equalTo(2L)); + + Boolean isMember = exec(commandObjects.sismember(key, member1)); + assertThat(isMember, equalTo(true)); + + Boolean isMemberBinary = exec(commandObjects.sismember(key.getBytes(), member1.getBytes())); + assertThat(isMemberBinary, equalTo(true)); + + List mIsMember = exec(commandObjects.smismember(key, member1, "nonMember")); + assertThat(mIsMember, contains(true, false)); + + List mIsMemberBinary = exec(commandObjects.smismember(key.getBytes(), member1.getBytes(), "nonMember".getBytes())); + assertThat(mIsMemberBinary, contains(true, false)); + } + + @Test + public void testSrandmemberCommands() { + String key = "testSetRandomMember"; + String member1 = "member1"; + String member2 = "member2"; + String member3 = "member3"; + + exec(commandObjects.sadd(key, member1, member2, member3)); + + String randomMember = exec(commandObjects.srandmember(key)); + assertThat(randomMember, anyOf(equalTo(member1), equalTo(member2), equalTo(member3))); + + byte[] randomMemberBinary = exec(commandObjects.srandmember(key.getBytes())); + assertThat(new String(randomMemberBinary), anyOf(equalTo(member1), equalTo(member2), equalTo(member3))); + + List randomMembers = exec(commandObjects.srandmember(key, 2)); + assertThat(randomMembers, hasSize(2)); + assertThat(randomMembers, everyItem(anyOf(equalTo(member1), equalTo(member2), equalTo(member3)))); + assertThat(randomMembers, not(contains(randomMember))); + + List randomMembersBinary = exec(commandObjects.srandmember(key.getBytes(), 2)); + assertThat(randomMembersBinary, hasSize(2)); + assertThat(randomMembersBinary, everyItem(anyOf(equalTo(member1.getBytes()), equalTo(member2.getBytes()), equalTo(member3.getBytes())))); + assertThat(randomMembersBinary, not(contains(randomMemberBinary))); + } + + @Test + public void testSscanCommands() { + String key = "testSetScan"; + String member1 = "member1"; + String member2 = "member2"; + String member3 = "member3"; + + exec(commandObjects.sadd(key, member1, member2, member3)); + + ScanParams params = new ScanParams().count(2); + + ScanResult scan = exec(commandObjects.sscan(key, ScanParams.SCAN_POINTER_START, params)); + + assertThat(scan.getResult(), hasSize(lessThanOrEqualTo(3))); + assertThat(scan.getResult(), everyItem(anyOf(equalTo(member1), equalTo(member2), equalTo(member3)))); + + ScanResult scanBinary = exec(commandObjects.sscan(key.getBytes(), ScanParams.SCAN_POINTER_START_BINARY, params)); + + assertThat(scanBinary.getResult(), hasSize(lessThanOrEqualTo(3))); + assertThat(scanBinary.getResult(), everyItem(anyOf(equalTo(member1.getBytes()), equalTo(member2.getBytes()), equalTo(member3.getBytes())))); + } + + @Test + public void testSdiff() { + String key1 = "testSet1"; + String key2 = "testSet2"; + + exec(commandObjects.sadd(key1, "member1", "member2", "member3")); + exec(commandObjects.sadd(key2, "member2", "member3", "member4")); + + Set diff = exec(commandObjects.sdiff(key1, key2)); + assertThat(diff, contains("member1")); + + Set diffBinary = exec(commandObjects.sdiff(key1.getBytes(), key2.getBytes())); + assertThat(diffBinary, contains("member1".getBytes())); + } + + @Test + public void testSdiffstore() { + String key1 = "testSet1"; + String key2 = "testSet2"; + String dstKey = "testSetDiff"; + + exec(commandObjects.sadd(key1, "member1", "member2", "member3")); + exec(commandObjects.sadd(key2, "member2", "member3", "member4")); + + Long diffStore = exec(commandObjects.sdiffstore(dstKey, key1, key2)); + assertThat(diffStore, equalTo(1L)); + + Set dstSet = exec(commandObjects.smembers(dstKey)); + assertThat(dstSet, contains("member1")); + } + + @Test + public void testSdiffstoreBinary() { + byte[] key1 = "testSet1".getBytes(); + byte[] key2 = "testSet2".getBytes(); + byte[] dstKey = "testSetDiff".getBytes(); + + exec(commandObjects.sadd(key1, "member1".getBytes(), "member2".getBytes(), "member3".getBytes())); + exec(commandObjects.sadd(key2, "member2".getBytes(), "member3".getBytes(), "member4".getBytes())); + + Long diffStore = exec(commandObjects.sdiffstore(dstKey, key1, key2)); + assertThat(diffStore, equalTo(1L)); + + Set dstSet = exec(commandObjects.smembers(dstKey)); + assertThat(dstSet, contains("member1".getBytes())); + } + + @Test + public void testSinterAndSinterCard() { + String key1 = "testSetInter1"; + String key2 = "testSetInter2"; + + exec(commandObjects.sadd(key1, "member1", "member2", "member3")); + exec(commandObjects.sadd(key2, "member2", "member3", "member4")); + + Set inter = exec(commandObjects.sinter(key1, key2)); + assertThat(inter, containsInAnyOrder("member2", "member3")); + + Set interBinary = exec(commandObjects.sinter(key1.getBytes(), key2.getBytes())); + assertThat(interBinary, containsInAnyOrder("member2".getBytes(), "member3".getBytes())); + + Long interCard = exec(commandObjects.sintercard(key1, key2)); + assertThat(interCard, equalTo(2L)); + + Long interCardBinary = exec(commandObjects.sintercard(key1.getBytes(), key2.getBytes())); + assertThat(interCardBinary, equalTo(2L)); + + Long interCardLimited = exec(commandObjects.sintercard(1, key1, key2)); + assertThat(interCardLimited, equalTo(1L)); + + Long interCardLimitedBinary = exec(commandObjects.sintercard(1, key1.getBytes(), key2.getBytes())); + assertThat(interCardLimitedBinary, equalTo(1L)); + } + + @Test + public void testSinterstore() { + String key1 = "testSetInter1"; + String key2 = "testSetInter2"; + String dstKey = "testSetInterResult"; + + exec(commandObjects.sadd(key1, "member1", "member2", "member3")); + exec(commandObjects.sadd(key2, "member2", "member3", "member4")); + + Long interStore = exec(commandObjects.sinterstore(dstKey, key1, key2)); + assertThat(interStore, equalTo(2L)); + + Set dstSet = exec(commandObjects.smembers(dstKey)); + assertThat(dstSet, containsInAnyOrder("member2", "member3")); + } + + @Test + public void testSinterstoreBinary() { + byte[] key1 = "testSetInter1B".getBytes(); + byte[] key2 = "testSetInter2B".getBytes(); + byte[] dstKey = "testSetInterResultB".getBytes(); + + exec(commandObjects.sadd(key1, "member1".getBytes(), "member2".getBytes(), "member3".getBytes())); + exec(commandObjects.sadd(key2, "member2".getBytes(), "member3".getBytes(), "member4".getBytes())); + + Long interStore = exec(commandObjects.sinterstore(dstKey, key1, key2)); + assertThat(interStore, equalTo(2L)); + + Set dstSet = exec(commandObjects.smembers(dstKey)); + assertThat(dstSet, containsInAnyOrder("member2".getBytes(), "member3".getBytes())); + } + + @Test + public void testSunion() { + String key1 = "testSetUnion1"; + String key2 = "testSetUnion2"; + + exec(commandObjects.sadd(key1, "member1", "member2", "member3")); + exec(commandObjects.sadd(key2, "member3", "member4", "member5")); + + Set unionResult = exec(commandObjects.sunion(key1, key2)); + + assertThat(unionResult, containsInAnyOrder( + "member1", "member2", "member3", "member4", "member5")); + + Set bunionResult = exec(commandObjects.sunion(key1.getBytes(), key2.getBytes())); + + assertThat(bunionResult, containsInAnyOrder( + "member1".getBytes(), "member2".getBytes(), "member3".getBytes(), "member4".getBytes(), "member5".getBytes())); + } + + @Test + public void testSunionstore() { + String key1 = "testSetUnion1"; + String key2 = "testSetUnion2"; + String dstKey = "testSetUnionResult"; + + exec(commandObjects.sadd(key1, "member1", "member2", "member3")); + exec(commandObjects.sadd(key2, "member3", "member4", "member5")); + + Long unionStore = exec(commandObjects.sunionstore(dstKey, key1, key2)); + + assertThat(unionStore, equalTo(5L)); + + Set dstSet = exec(commandObjects.smembers(dstKey)); + + assertThat(dstSet, containsInAnyOrder( + "member1", "member2", "member3", "member4", "member5")); + } + + @Test + public void testSunionstoreBinary() { + byte[] key1 = "testSetUnion1".getBytes(); + byte[] key2 = "testSetUnion2".getBytes(); + byte[] dstKey = "testSetUnionResult".getBytes(); + + exec(commandObjects.sadd(key1, "member1".getBytes(), "member2".getBytes(), "member3".getBytes())); + exec(commandObjects.sadd(key2, "member3".getBytes(), "member4".getBytes(), "member5".getBytes())); + + Long unionStore = exec(commandObjects.sunionstore(dstKey, key1, key2)); + assertThat(unionStore, equalTo(5L)); + + Set dstSet = exec(commandObjects.smembers(dstKey)); + assertThat(dstSet, containsInAnyOrder( + "member1".getBytes(), "member2".getBytes(), "member3".getBytes(), "member4".getBytes(), "member5".getBytes())); + } + + @Test + public void testSmove() { + String srcKey = "testSetSrc"; + String dstKey = "testSetDst"; + String member = "memberToMove"; + + exec(commandObjects.sadd(srcKey, member)); + + Long smove = exec(commandObjects.smove(srcKey, dstKey, member)); + assertThat(smove, equalTo(1L)); + + Set dstSet = exec(commandObjects.smembers(dstKey)); + assertThat(dstSet, contains(member)); + } + + @Test + public void testSmoveBinary() { + byte[] srcKey = "testSetSrc".getBytes(); + byte[] dstKey = "testSetDst".getBytes(); + byte[] member = "memberToMove".getBytes(); + + exec(commandObjects.sadd(srcKey, member)); + + Long smove = exec(commandObjects.smove(srcKey, dstKey, member)); + assertThat(smove, equalTo(1L)); + + Set dstSet = exec(commandObjects.smembers(dstKey)); + assertThat(dstSet, contains(member)); + } +} diff --git a/src/test/java/redis/clients/jedis/commands/commandobjects/CommandObjectsSortedSetCommandsTest.java b/src/test/java/redis/clients/jedis/commands/commandobjects/CommandObjectsSortedSetCommandsTest.java new file mode 100644 index 00000000000..cf2be1b0a7f --- /dev/null +++ b/src/test/java/redis/clients/jedis/commands/commandobjects/CommandObjectsSortedSetCommandsTest.java @@ -0,0 +1,1508 @@ +package redis.clients.jedis.commands.commandobjects; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.anyOf; +import static org.hamcrest.Matchers.closeTo; +import static org.hamcrest.Matchers.contains; +import static org.hamcrest.Matchers.containsInAnyOrder; +import static org.hamcrest.Matchers.either; +import static org.hamcrest.Matchers.empty; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.hasItem; +import static org.hamcrest.Matchers.hasItems; +import static org.hamcrest.Matchers.hasSize; +import static org.hamcrest.Matchers.notNullValue; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.junit.Test; +import redis.clients.jedis.RedisProtocol; +import redis.clients.jedis.args.SortedSetOption; +import redis.clients.jedis.params.ScanParams; +import redis.clients.jedis.params.ZAddParams; +import redis.clients.jedis.params.ZIncrByParams; +import redis.clients.jedis.params.ZParams; +import redis.clients.jedis.params.ZRangeParams; +import redis.clients.jedis.resps.ScanResult; +import redis.clients.jedis.resps.Tuple; +import redis.clients.jedis.util.KeyValue; + +/** + * Tests related to Sorted set commands. + */ +public class CommandObjectsSortedSetCommandsTest extends CommandObjectsStandaloneTestBase { + + public CommandObjectsSortedSetCommandsTest(RedisProtocol protocol) { + super(protocol); + } + + @Test + public void testZaddAndZcard() { + String key = "zset"; + String member = "member1"; + double score = 1.0; + + Map scoreMembers = new HashMap<>(); + scoreMembers.put("member2", 2.0); + scoreMembers.put("member3", 3.0); + + ZAddParams params = ZAddParams.zAddParams().nx(); + + Long zadd = exec(commandObjects.zadd(key, score, member)); + assertThat(zadd, equalTo(1L)); + + Long zaddParams = exec(commandObjects.zadd(key, score, member, params)); + assertThat(zaddParams, equalTo(0L)); + + Long zaddMultiple = exec(commandObjects.zadd(key, scoreMembers)); + assertThat(zaddMultiple, equalTo(2L)); + + Long zaddMultipleParams = exec(commandObjects.zadd(key, scoreMembers, params)); + assertThat(zaddMultipleParams, equalTo(0L)); + + Long zcard = exec(commandObjects.zcard(key)); + assertThat(zcard, equalTo(3L)); + } + + @Test + public void testZaddAndZcardBinary() { + byte[] key = "zset".getBytes(); + byte[] member = "member1".getBytes(); + double score = 1.0; + + Map binaryScoreMembers = new HashMap<>(); + binaryScoreMembers.put("member2".getBytes(), 2.0); + binaryScoreMembers.put("member3".getBytes(), 3.0); + + ZAddParams params = ZAddParams.zAddParams().nx(); + + Long zadd = exec(commandObjects.zadd(key, score, member)); + assertThat(zadd, equalTo(1L)); + + Long zaddParams = exec(commandObjects.zadd(key, score, member, params)); + assertThat(zaddParams, equalTo(0L)); + + Long zaddMultiple = exec(commandObjects.zadd(key, binaryScoreMembers)); + assertThat(zaddMultiple, equalTo(2L)); + + Long zaddMultipleParams = exec(commandObjects.zadd(key, binaryScoreMembers, params)); + assertThat(zaddMultipleParams, equalTo(0L)); + + Long zcard = exec(commandObjects.zcard(key)); + assertThat(zcard, equalTo(3L)); + } + + @Test + public void testZIncrAndZincrBy() { + String key = "zset"; + String member = "member"; + double initialScore = 1.0; + double increment = 2.0; + + ZAddParams zAddParams = ZAddParams.zAddParams().xx(); + + ZIncrByParams zIncrByParams = ZIncrByParams.zIncrByParams().xx(); + + Long zadd = exec(commandObjects.zadd(key, initialScore, member)); + assertThat(zadd, equalTo(1L)); + + Double zaddIncr = exec(commandObjects.zaddIncr(key, increment, member, zAddParams)); + assertThat(zaddIncr, closeTo(initialScore + increment, 0.001)); + + Double zscoreAfterZaddincr = exec(commandObjects.zscore(key, member)); + assertThat(zscoreAfterZaddincr, closeTo(initialScore + increment, 0.001)); + + Double zincrBy = exec(commandObjects.zincrby(key, increment, member)); + assertThat(zincrBy, closeTo(initialScore + increment * 2, 0.001)); + + Double zscoreAfterZincrBy = exec(commandObjects.zscore(key, member)); + assertThat(zscoreAfterZincrBy, closeTo(initialScore + increment * 2, 0.001)); + + Double zincrByParams = exec(commandObjects.zincrby(key, increment, member, zIncrByParams)); + assertThat(zincrByParams, closeTo(initialScore + increment * 3, 0.001)); + + Double zscoreAfterZincrByParams = exec(commandObjects.zscore(key, member)); + assertThat(zscoreAfterZincrByParams, closeTo(initialScore + increment * 3, 0.001)); + } + + @Test + public void testZIncrAndZincrByBinary() { + byte[] key = "zset".getBytes(); + byte[] member = "member".getBytes(); + double initialScore = 1.0; + double increment = 2.0; + + ZAddParams zAddParams = ZAddParams.zAddParams().xx(); + + ZIncrByParams zIncrByParams = ZIncrByParams.zIncrByParams().xx(); + + Long zadd = exec(commandObjects.zadd(key, initialScore, member)); + assertThat(zadd, equalTo(1L)); + + Double zaddIncr = exec(commandObjects.zaddIncr(key, increment, member, zAddParams)); + assertThat(zaddIncr, closeTo(initialScore + increment, 0.001)); + + Double zscoreAfterZaddIncr = exec(commandObjects.zscore(key, member)); + assertThat(zscoreAfterZaddIncr, closeTo(initialScore + increment, 0.001)); + + Double zincrBy = exec(commandObjects.zincrby(key, increment, member)); + assertThat(zincrBy, closeTo(initialScore + increment * 2, 0.001)); + + Double zscoreAfterZincrBy = exec(commandObjects.zscore(key, member)); + assertThat(zscoreAfterZincrBy, closeTo(initialScore + increment * 2, 0.001)); + + Double zincrByParams = exec(commandObjects.zincrby(key, increment, member, zIncrByParams)); + assertThat(zincrByParams, closeTo(initialScore + increment * 3, 0.001)); + + Double zscoreAfterZincrByParams = exec(commandObjects.zscore(key, member)); + assertThat(zscoreAfterZincrByParams, closeTo(initialScore + increment * 3, 0.001)); + } + + @Test + public void testZrem() { + String key = "zset"; + String member1 = "one"; + String member2 = "two"; + double score1 = 1.0; + double score2 = 2.0; + + exec(commandObjects.zadd(key, score1, member1)); + exec(commandObjects.zadd(key, score2, member2)); + + List zrangeBefore = exec(commandObjects.zrange(key, 0, -1)); + assertThat(zrangeBefore, containsInAnyOrder(member1, member2)); + + Long removedCount = exec(commandObjects.zrem(key, member1)); + assertThat(removedCount, equalTo(1L)); + + List zrangeAfter = exec(commandObjects.zrange(key, 0, -1)); + assertThat(zrangeAfter, containsInAnyOrder(member2)); + } + + @Test + public void testZremBinary() { + byte[] key = "zset".getBytes(); + byte[] member1 = "one".getBytes(); + byte[] member2 = "two".getBytes(); + double score1 = 1.0; + double score2 = 2.0; + + exec(commandObjects.zadd(key, score1, member1)); + exec(commandObjects.zadd(key, score2, member2)); + + List zrangeBefore = exec(commandObjects.zrange(key, 0, -1)); + assertThat(zrangeBefore, containsInAnyOrder(member1, member2)); + + Long removedCount = exec(commandObjects.zrem(key, member1)); + assertThat(removedCount, equalTo(1L)); + + List zrangeAfter = exec(commandObjects.zrange(key, 0, -1)); + assertThat(zrangeAfter, containsInAnyOrder(member2)); + } + + @Test + public void testZrandmember() { + String key = "zset"; + String member1 = "one"; + String member2 = "two"; + double score1 = 1.0; + double score2 = 2.0; + + exec(commandObjects.zadd(key, score1, member1)); + exec(commandObjects.zadd(key, score2, member2)); + + String randomMember = exec(commandObjects.zrandmember(key)); + + assertThat(randomMember, anyOf(equalTo(member1), equalTo(member2))); + + byte[] randomMemberBinary = exec(commandObjects.zrandmember(key.getBytes())); + + assertThat(randomMemberBinary, anyOf(equalTo(member1.getBytes()), equalTo(member2.getBytes()))); + + List randomMembers = exec(commandObjects.zrandmember(key, 2)); + + assertThat(randomMembers, containsInAnyOrder(member1, member2)); + + List randomMembersBinary = exec(commandObjects.zrandmember(key.getBytes(), 2)); + + assertThat(randomMembersBinary.get(0), anyOf(equalTo(member1.getBytes()), equalTo(member2.getBytes()))); + assertThat(randomMembersBinary.get(1), anyOf(equalTo(member1.getBytes()), equalTo(member2.getBytes()))); + } + + @Test + public void testZrandmemberWithScores() { + String key = "zset"; + String member1 = "one"; + String member2 = "two"; + double score1 = 1.0; + double score2 = 2.0; + + exec(commandObjects.zadd(key, score1, member1)); + exec(commandObjects.zadd(key, score2, member2)); + + List randomMembersWithScores = exec(commandObjects.zrandmemberWithScores(key, 2)); + + assertThat(randomMembersWithScores, hasSize(2)); + assertThat(randomMembersWithScores, containsInAnyOrder(new Tuple(member1, score1), new Tuple(member2, score2))); + + List randomMembersWithScoresBinary = exec(commandObjects.zrandmemberWithScores(key.getBytes(), 2)); + + assertThat(randomMembersWithScoresBinary, hasSize(2)); + + assertThat(randomMembersWithScoresBinary.get(0).getBinaryElement(), anyOf(equalTo(member1.getBytes()), equalTo(member2.getBytes()))); + assertThat(randomMembersWithScoresBinary.get(0).getScore(), anyOf(equalTo(score1), equalTo(score2))); + + assertThat(randomMembersWithScoresBinary.get(1).getBinaryElement(), anyOf(equalTo(member1.getBytes()), equalTo(member2.getBytes()))); + assertThat(randomMembersWithScoresBinary.get(1).getScore(), anyOf(equalTo(score1), equalTo(score2))); + } + + @Test + public void testZscore() { + String key = "zset"; + String member1 = "one"; + double score1 = 1.0; + + exec(commandObjects.zadd(key, score1, member1)); + + Double score = exec(commandObjects.zscore(key, member1)); + assertThat(score, equalTo(score1)); + + Double scoreBinary = exec(commandObjects.zscore(key.getBytes(), member1.getBytes())); + assertThat(scoreBinary, equalTo(score1)); + } + + @Test + public void testZmscore() { + String key = "zset"; + String member1 = "one"; + String member2 = "two"; + double score1 = 1.0; + double score2 = 2.0; + + exec(commandObjects.zadd(key, score1, member1)); + exec(commandObjects.zadd(key, score2, member2)); + + List scores = exec(commandObjects.zmscore(key, member1, member2)); + assertThat(scores, contains(score1, score2)); + + List scoresBinary = exec(commandObjects.zmscore(key.getBytes(), member1.getBytes(), member2.getBytes())); + assertThat(scoresBinary, contains(score1, score2)); + } + + @Test + public void testZrankAndZrevrank() { + String key = "zset"; + String member1 = "one"; + String member2 = "two"; + double score1 = 1.0; + double score2 = 2.0; + + exec(commandObjects.zadd(key, score1, member1)); + exec(commandObjects.zadd(key, score2, member2)); + + Long rankMember1 = exec(commandObjects.zrank(key, member1)); + assertThat(rankMember1, equalTo(0L)); + + Long rankMember2 = exec(commandObjects.zrank(key, member2)); + assertThat(rankMember2, equalTo(1L)); + + Long rankMember1Binary = exec(commandObjects.zrank(key.getBytes(), member1.getBytes())); + assertThat(rankMember1Binary, equalTo(0L)); + + Long rankMember2Binary = exec(commandObjects.zrank(key.getBytes(), member2.getBytes())); + assertThat(rankMember2Binary, equalTo(1L)); + + Long revRankMember1 = exec(commandObjects.zrevrank(key, member1)); + assertThat(revRankMember1, equalTo(1L)); + + Long revRankMember2 = exec(commandObjects.zrevrank(key, member2)); + assertThat(revRankMember2, equalTo(0L)); + + Long revRankMember1Binary = exec(commandObjects.zrevrank(key.getBytes(), member1.getBytes())); + assertThat(revRankMember1Binary, equalTo(1L)); + + Long revRankMember2Binary = exec(commandObjects.zrevrank(key.getBytes(), member2.getBytes())); + assertThat(revRankMember2Binary, equalTo(0L)); + } + + @Test + public void testZrankWithScoreAndZrevrankWithScore() { + String key = "zset"; + String member1 = "one"; + String member2 = "two"; + double score1 = 1.0; + double score2 = 2.0; + + exec(commandObjects.zadd(key, score1, member1)); + exec(commandObjects.zadd(key, score2, member2)); + + KeyValue rankWithScoreMember1 = exec(commandObjects.zrankWithScore(key, member1)); + assertThat(rankWithScoreMember1.getKey(), equalTo(0L)); + assertThat(rankWithScoreMember1.getValue(), equalTo(score1)); + + KeyValue rankWithScoreMember2 = exec(commandObjects.zrankWithScore(key, member2)); + assertThat(rankWithScoreMember2.getKey(), equalTo(1L)); + assertThat(rankWithScoreMember2.getValue(), equalTo(score2)); + + KeyValue rankWithScoreMember1Binary = exec(commandObjects.zrankWithScore(key.getBytes(), member1.getBytes())); + assertThat(rankWithScoreMember1Binary.getKey(), equalTo(0L)); + assertThat(rankWithScoreMember1Binary.getValue(), equalTo(score1)); + + KeyValue rankWithScoreMember2Binary = exec(commandObjects.zrankWithScore(key.getBytes(), member2.getBytes())); + assertThat(rankWithScoreMember2Binary.getKey(), equalTo(1L)); + assertThat(rankWithScoreMember2Binary.getValue(), equalTo(score2)); + + KeyValue revRankWithScoreMember1 = exec(commandObjects.zrevrankWithScore(key, member1)); + assertThat(revRankWithScoreMember1.getKey(), equalTo(1L)); + assertThat(revRankWithScoreMember1.getValue(), equalTo(score1)); + + KeyValue revRankWithScoreMember2 = exec(commandObjects.zrevrankWithScore(key, member2)); + assertThat(revRankWithScoreMember2.getKey(), equalTo(0L)); + assertThat(revRankWithScoreMember2.getValue(), equalTo(score2)); + + KeyValue revRankWithScoreMember1Binary = exec(commandObjects.zrevrankWithScore(key.getBytes(), member1.getBytes())); + assertThat(revRankWithScoreMember1Binary.getKey(), equalTo(1L)); + assertThat(revRankWithScoreMember1Binary.getValue(), equalTo(score1)); + + KeyValue revRankWithScoreMember2Binary = exec(commandObjects.zrevrankWithScore(key.getBytes(), member2.getBytes())); + assertThat(revRankWithScoreMember2Binary.getKey(), equalTo(0L)); + assertThat(revRankWithScoreMember2Binary.getValue(), equalTo(score2)); + } + + @Test + public void testZpopmax() { + String key = "zset"; + String member1 = "one"; + String member2 = "two"; + double score1 = 1.0; + double score2 = 2.0; + + exec(commandObjects.zadd(key, score1, member1)); + exec(commandObjects.zadd(key, score2, member2)); + + Tuple poppedMax = exec(commandObjects.zpopmax(key)); + assertThat(poppedMax.getElement(), equalTo(member2)); + assertThat(poppedMax.getScore(), equalTo(score2)); + + List poppedMaxMultiple = exec(commandObjects.zpopmax(key, 2)); + assertThat(poppedMaxMultiple, hasSize(1)); // Since we already popped the max, only one remains + assertThat(poppedMaxMultiple.get(0).getElement(), equalTo(member1)); + assertThat(poppedMaxMultiple.get(0).getScore(), equalTo(score1)); + } + + @Test + public void testZpopmaxBinary() { + byte[] key = "zset".getBytes(); + String member1 = "one"; + String member2 = "two"; + double score1 = 1.0; + double score2 = 2.0; + + exec(commandObjects.zadd(key, score1, member1.getBytes())); + exec(commandObjects.zadd(key, score2, member2.getBytes())); + + Tuple poppedMaxBinary = exec(commandObjects.zpopmax(key)); + assertThat(poppedMaxBinary.getBinaryElement(), equalTo(member2.getBytes())); + assertThat(poppedMaxBinary.getScore(), equalTo(score2)); + + List poppedMaxMultipleBinary = exec(commandObjects.zpopmax(key, 2)); + assertThat(poppedMaxMultipleBinary, hasSize(1)); // Since we already popped the max, only one remains + assertThat(poppedMaxMultipleBinary.get(0).getBinaryElement(), equalTo(member1.getBytes())); + assertThat(poppedMaxMultipleBinary.get(0).getScore(), equalTo(score1)); + } + + @Test + public void testZpopmin() { + String key = "zset"; + String member1 = "one"; + String member2 = "two"; + double score1 = 1.0; + double score2 = 2.0; + + exec(commandObjects.zadd(key, score1, member1)); + exec(commandObjects.zadd(key, score2, member2)); + + Tuple poppedMin = exec(commandObjects.zpopmin(key)); + assertThat(poppedMin.getElement(), equalTo(member1)); + assertThat(poppedMin.getScore(), equalTo(score1)); + + List poppedMinMultiple = exec(commandObjects.zpopmin(key, 2)); + assertThat(poppedMinMultiple, hasSize(1)); // Since we already popped the min, only one remains + assertThat(poppedMinMultiple.get(0).getElement(), equalTo(member2)); + assertThat(poppedMinMultiple.get(0).getScore(), equalTo(score2)); + } + + @Test + public void testZpopminBinary() { + byte[] key = "zset".getBytes(); + String member1 = "one"; + String member2 = "two"; + double score1 = 1.0; + double score2 = 2.0; + + exec(commandObjects.zadd(key, score1, member1.getBytes())); + exec(commandObjects.zadd(key, score2, member2.getBytes())); + + Tuple poppedMinBinary = exec(commandObjects.zpopmin(key)); + assertThat(poppedMinBinary.getBinaryElement(), equalTo(member1.getBytes())); + assertThat(poppedMinBinary.getScore(), equalTo(score1)); + + List poppedMinMultipleBinary = exec(commandObjects.zpopmin(key, 2)); + assertThat(poppedMinMultipleBinary, hasSize(1)); // Since we already popped the min, only one remains + assertThat(poppedMinMultipleBinary.get(0).getBinaryElement(), equalTo(member2.getBytes())); + assertThat(poppedMinMultipleBinary.get(0).getScore(), equalTo(score2)); + } + + @Test + public void testBzpopmaxAndBzpopmin() { + String key1 = "zset1"; + String key2 = "zset2"; + String member1 = "one"; + String member2 = "two"; + double score1 = 1.0; + double score2 = 2.0; + double timeout = 2.0; // 2 seconds timeout for blocking operations + + exec(commandObjects.zadd(key1, score1, member1)); + exec(commandObjects.zadd(key2, score2, member2)); + + KeyValue poppedMax = exec(commandObjects.bzpopmax(timeout, key1, key2)); + assertThat(poppedMax.getKey(), anyOf(equalTo(key1), equalTo(key2))); + assertThat(poppedMax.getValue().getScore(), anyOf(equalTo(score1), equalTo(score2))); + + KeyValue poppedMin = exec(commandObjects.bzpopmin(timeout, key1, key2)); + assertThat(poppedMin.getKey(), anyOf(equalTo(key1), equalTo(key2))); + assertThat(poppedMin.getValue().getScore(), anyOf(equalTo(score1), equalTo(score2))); + } + + @Test + public void testBzpopmaxAndBzpopminBinary() { + byte[] key1 = "zset1".getBytes(); + byte[] key2 = "zset2".getBytes(); + String member1 = "one"; + String member2 = "two"; + double score1 = 1.0; + double score2 = 2.0; + double timeout = 2.0; // 2 seconds timeout for blocking operations + + exec(commandObjects.zadd(key1, score1, member1.getBytes())); + exec(commandObjects.zadd(key2, score2, member2.getBytes())); + + KeyValue poppedMaxBinary = exec(commandObjects.bzpopmax(timeout, key1, key2)); + assertThat(poppedMaxBinary.getKey(), anyOf(equalTo(key1), equalTo(key2))); + assertThat(poppedMaxBinary.getValue().getScore(), anyOf(equalTo(score1), equalTo(score2))); + + KeyValue poppedMinBinary = exec(commandObjects.bzpopmin(timeout, key1, key2)); + assertThat(poppedMinBinary.getKey(), anyOf(equalTo(key1), equalTo(key2))); + assertThat(poppedMinBinary.getValue().getScore(), anyOf(equalTo(score1), equalTo(score2))); + } + + @Test + public void testZcount() { + String key = "zset"; + String member1 = "one"; + String member2 = "two"; + String member3 = "three"; + double score1 = 1.0; + double score2 = 2.0; + double score3 = 3.0; + + exec(commandObjects.zadd(key, score1, member1)); + exec(commandObjects.zadd(key, score2, member2)); + exec(commandObjects.zadd(key, score3, member3)); + + Long countInNumericRange = exec(commandObjects.zcount(key, 1.5, 2.5)); + assertThat(countInNumericRange, equalTo(1L)); + + Long countInStringRange = exec(commandObjects.zcount(key, "(1", "3")); + assertThat(countInStringRange, equalTo(2L)); + + Long countInNumericRangeBinary = exec(commandObjects.zcount(key.getBytes(), 1.5, 2.5)); + assertThat(countInNumericRangeBinary, equalTo(1L)); + + Long countInBinaryRange = exec(commandObjects.zcount(key.getBytes(), "(1".getBytes(), "3".getBytes())); + assertThat(countInBinaryRange, equalTo(2L)); + } + + @Test + public void testZrange() { + String key = "zset"; + String member1 = "one"; + String member2 = "two"; + double score1 = 1.0; + double score2 = 2.0; + + exec(commandObjects.zadd(key, score1, member1)); + exec(commandObjects.zadd(key, score2, member2)); + + List range = exec(commandObjects.zrange(key, 0, -1)); + assertThat(range, contains(member1, member2)); + + List rangeBinary = exec(commandObjects.zrange(key.getBytes(), 0, -1)); + assertThat(rangeBinary, contains(member1.getBytes(), member2.getBytes())); + + ZRangeParams zRangeParams = ZRangeParams.zrangeParams(0, -1); + + List rangeWithParams = exec(commandObjects.zrange(key, zRangeParams)); + assertThat(rangeWithParams, hasItems(member1, member2)); + + List rangeWithParamsBinary = exec(commandObjects.zrange(key.getBytes(), zRangeParams)); + assertThat(rangeWithParamsBinary.get(0), equalTo(member1.getBytes())); + assertThat(rangeWithParamsBinary.get(1), equalTo(member2.getBytes())); + } + + @Test + public void testZrangeWithScores() { + String key = "zset"; + String member1 = "one"; + String member2 = "two"; + double score1 = 1.0; + double score2 = 2.0; + + exec(commandObjects.zadd(key, score1, member1)); + exec(commandObjects.zadd(key, score2, member2)); + + List rangeWithScores = exec(commandObjects.zrangeWithScores(key, 0, -1)); + + assertThat(rangeWithScores, hasSize(2)); + assertThat(rangeWithScores.get(0).getElement(), equalTo(member1)); + assertThat(rangeWithScores.get(0).getScore(), equalTo(score1)); + assertThat(rangeWithScores.get(1).getElement(), equalTo(member2)); + assertThat(rangeWithScores.get(1).getScore(), equalTo(score2)); + + List rangeWithScoresBinary = exec(commandObjects.zrangeWithScores(key.getBytes(), 0, -1)); + + assertThat(rangeWithScoresBinary, hasSize(2)); + assertThat(rangeWithScoresBinary.get(0).getBinaryElement(), equalTo(member1.getBytes())); + assertThat(rangeWithScoresBinary.get(0).getScore(), equalTo(score1)); + assertThat(rangeWithScoresBinary.get(1).getBinaryElement(), equalTo(member2.getBytes())); + assertThat(rangeWithScoresBinary.get(1).getScore(), equalTo(score2)); + + ZRangeParams zRangeParams = ZRangeParams.zrangeParams(0, -1); + + List rangeWithScoresParams = exec(commandObjects.zrangeWithScores(key, zRangeParams)); + + assertThat(rangeWithScoresParams, hasSize(2)); + assertThat(rangeWithScoresParams.get(0).getElement(), equalTo(member1)); + assertThat(rangeWithScoresParams.get(0).getScore(), equalTo(score1)); + assertThat(rangeWithScoresParams.get(1).getElement(), equalTo(member2)); + assertThat(rangeWithScoresParams.get(1).getScore(), equalTo(score2)); + + List rangeWithScoresParamsBinary = exec(commandObjects.zrangeWithScores(key.getBytes(), zRangeParams)); + + assertThat(rangeWithScoresParamsBinary, hasSize(2)); + assertThat(rangeWithScoresParamsBinary.get(0).getBinaryElement(), equalTo(member1.getBytes())); + assertThat(rangeWithScoresParamsBinary.get(0).getScore(), equalTo(score1)); + assertThat(rangeWithScoresParamsBinary.get(1).getBinaryElement(), equalTo(member2.getBytes())); + assertThat(rangeWithScoresParamsBinary.get(1).getScore(), equalTo(score2)); + } + + @Test + public void testZrangestore() { + String srcKey = "zsetSrc"; + String destKey = "zsetDest"; + String member1 = "one"; + String member2 = "two"; + double score1 = 1.0; + double score2 = 2.0; + + exec(commandObjects.zadd(srcKey, score1, member1)); + exec(commandObjects.zadd(srcKey, score2, member2)); + + ZRangeParams zRangeParams = ZRangeParams.zrangeByScoreParams(score1, score2); + + Long zrangeStore = exec(commandObjects.zrangestore(destKey, srcKey, zRangeParams)); + + assertThat(zrangeStore, equalTo(2L)); + + List zrangeWithScores = exec(commandObjects.zrangeWithScores(destKey, 0, -1)); + + assertThat(zrangeWithScores, hasSize(2)); + assertThat(zrangeWithScores.get(0).getElement(), equalTo(member1)); + assertThat(zrangeWithScores.get(1).getElement(), equalTo(member2)); + } + + @Test + public void testZrangestoreBinary() { + byte[] srcKey = "zsetSrcB".getBytes(); + byte[] destKey = "zsetDestB".getBytes(); + String member1 = "one"; + String member2 = "two"; + double score1 = 1.0; + double score2 = 2.0; + + exec(commandObjects.zadd(srcKey, score1, member1.getBytes())); + exec(commandObjects.zadd(srcKey, score2, member2.getBytes())); + + ZRangeParams zRangeParams = ZRangeParams.zrangeByScoreParams(score1, score2); + + Long zrangeStore = exec(commandObjects.zrangestore(destKey, srcKey, zRangeParams)); + + assertThat(zrangeStore, equalTo(2L)); + + List zrangeWithScores = exec(commandObjects.zrangeWithScores(destKey, 0, -1)); + + assertThat(zrangeWithScores, hasSize(2)); + assertThat(zrangeWithScores.get(0).getBinaryElement(), equalTo(member1.getBytes())); + assertThat(zrangeWithScores.get(1).getBinaryElement(), equalTo(member2.getBytes())); + } + + @Test + public void testZrevrange() { + String key = "zset"; + String member1 = "one"; + String member2 = "two"; + double score1 = 1.0; + double score2 = 2.0; + + exec(commandObjects.zadd(key, score1, member1)); + exec(commandObjects.zadd(key, score2, member2)); + + List revRange = exec(commandObjects.zrevrange(key, 0, -1)); + assertThat(revRange, contains(member2, member1)); + + List revRangeBinary = exec(commandObjects.zrevrange(key.getBytes(), 0, -1)); + assertThat(revRangeBinary, contains(member2.getBytes(), member1.getBytes())); + } + + @Test + public void testZrevrangeWithScores() { + String key = "zset"; + String member1 = "one"; + String member2 = "two"; + double score1 = 1.0; + double score2 = 2.0; + + exec(commandObjects.zadd(key, score1, member1)); + exec(commandObjects.zadd(key, score2, member2)); + + List revRangeWithScores = exec(commandObjects.zrevrangeWithScores(key, 0, -1)); + + assertThat(revRangeWithScores, hasSize(2)); + assertThat(revRangeWithScores.get(0).getElement(), equalTo(member2)); + assertThat(revRangeWithScores.get(0).getScore(), equalTo(score2)); + assertThat(revRangeWithScores.get(1).getElement(), equalTo(member1)); + assertThat(revRangeWithScores.get(1).getScore(), equalTo(score1)); + + List revRangeWithScoresBinary = exec(commandObjects.zrevrangeWithScores(key.getBytes(), 0, -1)); + + assertThat(revRangeWithScoresBinary, hasSize(2)); + assertThat(revRangeWithScoresBinary.get(0).getBinaryElement(), equalTo(member2.getBytes())); + assertThat(revRangeWithScoresBinary.get(0).getScore(), equalTo(score2)); + assertThat(revRangeWithScoresBinary.get(1).getBinaryElement(), equalTo(member1.getBytes())); + assertThat(revRangeWithScoresBinary.get(1).getScore(), equalTo(score1)); + } + + @Test + public void testZrangeByScore() { + String key = "zset"; + double min = 1.0; + double max = 10.0; + String smin = "1"; + String smax = "10"; + byte[] bmin = "1.0".getBytes(); + byte[] bmax = "10.0".getBytes(); + int offset = 0; + int count = 1; + + exec(commandObjects.zadd(key, 1, "one")); + exec(commandObjects.zadd(key, 2, "two")); + exec(commandObjects.zadd(key, 3, "three")); + exec(commandObjects.zadd(key, 13, "four")); + + List numericRange = exec(commandObjects.zrangeByScore(key, min, max)); + assertThat(numericRange, contains("one", "two", "three")); + + List stringRange = exec(commandObjects.zrangeByScore(key, smin, smax)); + assertThat(stringRange, contains("one", "two", "three")); + + List numericRangeOffsetCount = exec(commandObjects.zrangeByScore(key, min, max, offset, count)); + assertThat(numericRangeOffsetCount, contains("one")); + + List stringRangeOffsetCount = exec(commandObjects.zrangeByScore(key, smin, smax, offset, count)); + assertThat(stringRangeOffsetCount, contains("one")); + + List numericRangeBinary = exec(commandObjects.zrangeByScore(key.getBytes(), min, max)); + assertThat(numericRangeBinary.get(0), equalTo("one".getBytes())); + assertThat(numericRangeBinary.get(1), equalTo("two".getBytes())); + assertThat(numericRangeBinary.get(2), equalTo("three".getBytes())); + + List stringRangeBinary = exec(commandObjects.zrangeByScore(key.getBytes(), bmin, bmax)); + assertThat(stringRangeBinary, contains("one".getBytes(), "two".getBytes(), "three".getBytes())); + + List numericRangeOffsetCountBinary = exec(commandObjects.zrangeByScore(key.getBytes(), min, max, offset, count)); + assertThat(numericRangeOffsetCountBinary.get(0), equalTo("one".getBytes())); + + List stringRangeOffsetCountBinary = exec(commandObjects.zrangeByScore(key.getBytes(), bmin, bmax, offset, count)); + assertThat(stringRangeOffsetCountBinary, contains("one".getBytes())); + } + + @Test + public void testZrevrangeByScore() { + String key = "zset"; + double max = 10.0; + double min = 1.0; + String smax = "10"; + String smin = "1"; + byte[] bmax = "10.0".getBytes(); + byte[] bmin = "1.0".getBytes(); + int offset = 0; + int count = 1; + + exec(commandObjects.zadd(key, 13, "four")); + exec(commandObjects.zadd(key, 3, "three")); + exec(commandObjects.zadd(key, 2, "two")); + exec(commandObjects.zadd(key, 1, "one")); + + List numericRevrange = exec(commandObjects.zrevrangeByScore(key, max, min)); + assertThat(numericRevrange, contains("three", "two", "one")); + + List stringRevrange = exec(commandObjects.zrevrangeByScore(key, smax, smin)); + assertThat(stringRevrange, contains("three", "two", "one")); + + List numericRevrangeOffsetCount = exec(commandObjects.zrevrangeByScore(key, max, min, offset, count)); + assertThat(numericRevrangeOffsetCount, contains("three")); + + List stringRevrangeOffsetCount = exec(commandObjects.zrevrangeByScore(key, smax, smin, offset, count)); + assertThat(stringRevrangeOffsetCount, contains("three")); + + List numericRevrangeBinary = exec(commandObjects.zrevrangeByScore(key.getBytes(), max, min)); + assertThat(numericRevrangeBinary, contains("three".getBytes(), "two".getBytes(), "one".getBytes())); + + List stringRevrangeBinary = exec(commandObjects.zrevrangeByScore(key.getBytes(), bmax, bmin)); + assertThat(stringRevrangeBinary, contains("three".getBytes(), "two".getBytes(), "one".getBytes())); + + List numericRevrangeOffsetCountBinary = exec(commandObjects.zrevrangeByScore(key.getBytes(), max, min, offset, count)); + assertThat(numericRevrangeOffsetCountBinary.get(0), equalTo("three".getBytes())); + + List stringRevrangeOffsetCountBinary = exec(commandObjects.zrevrangeByScore(key.getBytes(), bmax, bmin, offset, count)); + assertThat(stringRevrangeOffsetCountBinary, contains("three".getBytes())); + } + + @Test + public void testZrangeByScoreWithScores() { + String key = "zset"; + double min = 1.0; + double max = 10.0; + String smin = "1"; + String smax = "10"; + byte[] bmin = "1.0".getBytes(); + byte[] bmax = "10.0".getBytes(); + int offset = 0; + int count = 2; + + exec(commandObjects.zadd(key, 1, "one")); + exec(commandObjects.zadd(key, 2, "two")); + exec(commandObjects.zadd(key, 3, "three")); + + List numericRange = exec(commandObjects.zrangeByScoreWithScores(key, min, max)); + assertThat(numericRange, contains( + new Tuple("one", 1d), + new Tuple("two", 2d), + new Tuple("three", 3d))); + + List stringRange = exec(commandObjects.zrangeByScoreWithScores(key, smin, smax)); + assertThat(stringRange, contains( + new Tuple("one", 1d), + new Tuple("two", 2d), + new Tuple("three", 3d))); + + List numericRangeOffsetCount = exec(commandObjects.zrangeByScoreWithScores(key, min, max, offset, count)); + assertThat(numericRangeOffsetCount, contains( + new Tuple("one", 1d), + new Tuple("two", 2d))); + + List stringRangeOffsetCount = exec(commandObjects.zrangeByScoreWithScores(key, smin, smax, offset, count)); + assertThat(stringRangeOffsetCount, contains( + new Tuple("one", 1d), + new Tuple("two", 2d))); + + List numericRangeBinary = exec(commandObjects.zrangeByScoreWithScores(key.getBytes(), min, max)); + assertThat(numericRangeBinary, contains( + new Tuple("one".getBytes(), 1d), + new Tuple("two".getBytes(), 2d), + new Tuple("three".getBytes(), 3d))); + + List stringRangeBinary = exec(commandObjects.zrangeByScoreWithScores(key.getBytes(), bmin, bmax)); + assertThat(stringRangeBinary, contains( + new Tuple("one".getBytes(), 1d), + new Tuple("two".getBytes(), 2d), + new Tuple("three".getBytes(), 3d))); + + List numericRangeOffsetCountBinary = exec(commandObjects.zrangeByScoreWithScores(key.getBytes(), min, max, offset, count)); + assertThat(numericRangeOffsetCountBinary, contains( + new Tuple("one".getBytes(), 1d), + new Tuple("two".getBytes(), 2d))); + + List stringRangeOffsetCountBinary = exec(commandObjects.zrangeByScoreWithScores(key.getBytes(), bmin, bmax, offset, count)); + assertThat(stringRangeOffsetCountBinary, contains( + new Tuple("one".getBytes(), 1d), + new Tuple("two".getBytes(), 2d))); + } + + @Test + public void testZrevrangeByScoreWithScores() { + String key = "zset"; + double max = 10.0; + double min = 1.0; + String smax = "10"; + String smin = "1"; + byte[] bmax = "10".getBytes(); + byte[] bmin = "1".getBytes(); + int offset = 0; + int count = 2; + + exec(commandObjects.zadd(key, 3, "three")); + exec(commandObjects.zadd(key, 2, "two")); + exec(commandObjects.zadd(key, 1, "one")); + + List numericRevrange = exec(commandObjects.zrevrangeByScoreWithScores(key, max, min)); + assertThat(numericRevrange, contains( + new Tuple("three", 3d), + new Tuple("two", 2d), + new Tuple("one", 1d))); + + List stringRevrange = exec(commandObjects.zrevrangeByScoreWithScores(key, smax, smin)); + assertThat(stringRevrange, contains( + new Tuple("three", 3d), + new Tuple("two", 2d), + new Tuple("one", 1d))); + + List numericRevrangeOffsetCount = exec(commandObjects.zrevrangeByScoreWithScores(key, max, min, offset, count)); + assertThat(numericRevrangeOffsetCount, contains( + new Tuple("three", 3d), + new Tuple("two", 2d))); + + List stringRevrangeOffsetCount = exec(commandObjects.zrevrangeByScoreWithScores(key, smax, smin, offset, count)); + assertThat(stringRevrangeOffsetCount, contains( + new Tuple("three", 3d), + new Tuple("two", 2d))); + + List numericRevrangeBinary = exec(commandObjects.zrevrangeByScoreWithScores(key.getBytes(), max, min)); + assertThat(numericRevrangeBinary, contains( + new Tuple("three".getBytes(), 3d), + new Tuple("two".getBytes(), 2d), + new Tuple("one".getBytes(), 1d))); + + List stringRevrangeBinary = exec(commandObjects.zrevrangeByScoreWithScores(key.getBytes(), bmax, bmin)); + assertThat(stringRevrangeBinary, contains( + new Tuple("three".getBytes(), 3d), + new Tuple("two".getBytes(), 2d), + new Tuple("one".getBytes(), 1d))); + + List numericRevrangeOffsetCountBinary = exec(commandObjects.zrevrangeByScoreWithScores(key.getBytes(), max, min, offset, count)); + assertThat(numericRevrangeOffsetCountBinary, contains( + new Tuple("three".getBytes(), 3d), + new Tuple("two".getBytes(), 2d))); + + List stringRevrangeOffsetCountBinary = exec(commandObjects.zrevrangeByScoreWithScores(key.getBytes(), bmax, bmin, offset, count)); + assertThat(stringRevrangeOffsetCountBinary, contains( + new Tuple("three".getBytes(), 3d), + new Tuple("two".getBytes(), 2d))); + } + + @Test + public void testZremrangeByRank() { + String key = "zset"; + long start = 0; + long stop = 1; + + exec(commandObjects.zadd(key, 1, "one")); + exec(commandObjects.zadd(key, 2, "two")); + exec(commandObjects.zadd(key, 3, "three")); + + Long removedCount = exec(commandObjects.zremrangeByRank(key, start, stop)); + assertThat(removedCount, equalTo(2L)); + + List remainingElements = exec(commandObjects.zrange(key, 0, -1)); + assertThat(remainingElements, contains("three")); + } + + @Test + public void testZremrangeByRankBinary() { + byte[] key = "zset".getBytes(); + long start = 0; + long stop = 1; + + exec(commandObjects.zadd(key, 1, "one".getBytes())); + exec(commandObjects.zadd(key, 2, "two".getBytes())); + exec(commandObjects.zadd(key, 3, "three".getBytes())); + + Long removedCount = exec(commandObjects.zremrangeByRank(key, start, stop)); + assertThat(removedCount, equalTo(2L)); + + List remainingElements = exec(commandObjects.zrange(key, 0, -1)); + assertThat(remainingElements, contains("three".getBytes())); + } + + @Test + public void testZremrangeByScore() { + String key = "zset"; + double min = 1.0; + double max = 2.0; + String smin = "1"; + String smax = "2"; + + exec(commandObjects.zadd(key, 1, "one")); + exec(commandObjects.zadd(key, 2, "two")); + exec(commandObjects.zadd(key, 3, "three")); + + Long removedCountNumeric = exec(commandObjects.zremrangeByScore(key, min, max)); + assertThat(removedCountNumeric, equalTo(2L)); + + List remainingElements = exec(commandObjects.zrange(key, 0, -1)); + assertThat(remainingElements, contains("three")); + + exec(commandObjects.zadd(key, 1, "one")); + exec(commandObjects.zadd(key, 2, "two")); + + Long removedCountString = exec(commandObjects.zremrangeByScore(key, smin, smax)); + assertThat(removedCountString, equalTo(2L)); + + remainingElements = exec(commandObjects.zrange(key, 0, -1)); + assertThat(remainingElements, contains("three")); + } + + @Test + public void testZremrangeByScoreBinary() { + byte[] bkey = "zset".getBytes(); + double min = 1.0; + double max = 2.0; + byte[] bmin = "1".getBytes(); + byte[] bmax = "2".getBytes(); + + exec(commandObjects.zadd(bkey, 1, "one".getBytes())); + exec(commandObjects.zadd(bkey, 2, "two".getBytes())); + exec(commandObjects.zadd(bkey, 3, "three".getBytes())); + + Long removedCountNumericBinary = exec(commandObjects.zremrangeByScore(bkey, min, max)); + assertThat(removedCountNumericBinary, equalTo(2L)); + + List remainingElements = exec(commandObjects.zrange(bkey, 0, -1)); + assertThat(remainingElements, contains("three".getBytes())); + + exec(commandObjects.zadd(bkey, 1, "one".getBytes())); + exec(commandObjects.zadd(bkey, 2, "two".getBytes())); + + Long removedCountStringBinary = exec(commandObjects.zremrangeByScore(bkey, bmin, bmax)); + assertThat(removedCountStringBinary, equalTo(2L)); + + remainingElements = exec(commandObjects.zrange(bkey, 0, -1)); + assertThat(remainingElements, contains("three".getBytes())); + } + + @Test + public void testZlexcount() { + String key = "zset"; + String min = "[a", max = "(g"; + + exec(commandObjects.zadd(key, 0, "abc")); + exec(commandObjects.zadd(key, 0, "def")); + exec(commandObjects.zadd(key, 0, "ghi")); + + Long count = exec(commandObjects.zlexcount(key, min, max)); + assertThat(count, equalTo(2L)); + + Long countBinary = exec(commandObjects.zlexcount(key.getBytes(), min.getBytes(), max.getBytes())); + assertThat(countBinary, equalTo(2L)); + } + + @Test + public void testZrangeByLex() { + String key = "zset"; + String min = "[abc"; + String max = "(cde"; + int offset = 0; + int count = 2; + + exec(commandObjects.zadd(key, 0, "aaa")); + exec(commandObjects.zadd(key, 0, "abc")); + exec(commandObjects.zadd(key, 0, "bcd")); + exec(commandObjects.zadd(key, 0, "cde")); + + List range = exec(commandObjects.zrangeByLex(key, min, max)); + assertThat(range, contains("abc", "bcd")); + + List limitedRange = exec(commandObjects.zrangeByLex(key, min, max, offset, count)); + assertThat(limitedRange, contains("abc", "bcd")); + + List rangeBinary = exec(commandObjects.zrangeByLex(key.getBytes(), min.getBytes(), max.getBytes())); + assertThat(rangeBinary, contains("abc".getBytes(), "bcd".getBytes())); + + List limitedRangeBinary = exec(commandObjects.zrangeByLex(key.getBytes(), min.getBytes(), max.getBytes(), offset, count)); + assertThat(limitedRangeBinary, contains("abc".getBytes(), "bcd".getBytes())); + } + + @Test + public void testZrevrangeByLex() { + String key = "zset"; + String max = "[cde"; + String min = "(aaa"; + int offset = 0; + int count = 2; + + exec(commandObjects.zadd(key, 0, "aaa")); + exec(commandObjects.zadd(key, 0, "abc")); + exec(commandObjects.zadd(key, 0, "bcd")); + exec(commandObjects.zadd(key, 0, "cde")); + + List revRange = exec(commandObjects.zrevrangeByLex(key, max, min)); + assertThat(revRange, contains("cde", "bcd", "abc")); + + List limitedRevRange = exec(commandObjects.zrevrangeByLex(key, max, min, offset, count)); + assertThat(limitedRevRange, contains("cde", "bcd")); + + List revRangeBinary = exec(commandObjects.zrevrangeByLex(key.getBytes(), max.getBytes(), min.getBytes())); + assertThat(revRangeBinary.get(0), equalTo("cde".getBytes())); + assertThat(revRangeBinary.get(1), equalTo("bcd".getBytes())); + assertThat(revRangeBinary.get(2), equalTo("abc".getBytes())); + + List limitedRevRangeBinary = exec(commandObjects.zrevrangeByLex(key.getBytes(), max.getBytes(), min.getBytes(), offset, count)); + assertThat(limitedRevRangeBinary.get(0), equalTo("cde".getBytes())); + assertThat(limitedRevRangeBinary.get(1), equalTo("bcd".getBytes())); + } + + @Test + public void testZremrangeByLex() { + String key = "zset"; + String min = "[aaa"; + String max = "(ccc"; + + exec(commandObjects.zadd(key, 0, "aaa")); + exec(commandObjects.zadd(key, 0, "bbb")); + exec(commandObjects.zadd(key, 0, "ccc")); + + Long removedCount = exec(commandObjects.zremrangeByLex(key, min, max)); + assertThat(removedCount, equalTo(2L)); + + List remainingElements = exec(commandObjects.zrange(key, 0, -1)); + assertThat(remainingElements, contains("ccc")); + } + + @Test + public void testZremrangeByLexBinary() { + byte[] key = "zset".getBytes(); + byte[] min = "[aaa".getBytes(); + byte[] bmax = "(ccc".getBytes(); + + exec(commandObjects.zadd(key, 0, "aaa".getBytes())); + exec(commandObjects.zadd(key, 0, "bbb".getBytes())); + exec(commandObjects.zadd(key, 0, "ccc".getBytes())); + + Long removedCount = exec(commandObjects.zremrangeByLex(key, min, bmax)); + assertThat(removedCount, equalTo(2L)); + + List remainingElements = exec(commandObjects.zrange(key, 0, -1)); + assertThat(remainingElements, contains("ccc".getBytes())); + } + + @Test + public void testZscan() { + String key = "zset"; + String cursor = "0"; + ScanParams params = new ScanParams().count(2); + String member1 = "one"; + double score1 = 1.0; + String member2 = "two"; + double score2 = 2.0; + + exec(commandObjects.zadd(key, score1, member1)); + exec(commandObjects.zadd(key, score2, member2)); + + ScanResult result = exec(commandObjects.zscan(key, cursor, params)); + assertThat(result.getResult(), containsInAnyOrder( + new Tuple(member1, score1), + new Tuple(member2, score2))); + + ScanResult resultBinar = exec(commandObjects.zscan(key.getBytes(), cursor.getBytes(), params)); + assertThat(resultBinar.getResult(), containsInAnyOrder( + new Tuple(member1, score1), + new Tuple(member2, score2))); + } + + @Test + public void testZdiffAndZdiffWithScores() { + String key1 = "zset1"; + String key2 = "zset2"; + String member1 = "one"; + double score1 = 1.0; + String member2 = "two"; + double score2 = 2.0; + + exec(commandObjects.zadd(key1, score1, member1)); + exec(commandObjects.zadd(key1, score2, member2)); + exec(commandObjects.zadd(key2, score1, member1)); + + List diff = exec(commandObjects.zdiff(key1, key2)); + assertThat(diff, containsInAnyOrder(member2)); + + List diffWithScores = exec(commandObjects.zdiffWithScores(key1, key2)); + assertThat(diffWithScores, containsInAnyOrder(new Tuple(member2, score2))); + + List diffBinary = exec(commandObjects.zdiff(key1.getBytes(), key2.getBytes())); + assertThat(diffBinary, containsInAnyOrder(member2.getBytes())); + + List diffWithScoresBinary = exec(commandObjects.zdiffWithScores(key1.getBytes(), key2.getBytes())); + assertThat(diffWithScoresBinary, containsInAnyOrder(new Tuple(member2.getBytes(), score2))); + } + + @Test + public void testZdiffStore() { + String dstKey = "result"; + + exec(commandObjects.zadd("set1", 1, "member1")); + exec(commandObjects.zadd("set1", 2, "member2")); + exec(commandObjects.zadd("set2", 3, "member2")); + + Long result = exec(commandObjects.zdiffStore(dstKey, "set1", "set2")); + assertThat(result, equalTo(1L)); + + List resultSet = exec(commandObjects.zrange(dstKey, 0, -1)); + assertThat(resultSet, containsInAnyOrder("member1")); + + exec(commandObjects.del(dstKey)); + + result = exec(commandObjects.zdiffstore(dstKey, "set1", "set2")); + assertThat(result, equalTo(1L)); + + resultSet = exec(commandObjects.zrange(dstKey, 0, -1)); + assertThat(resultSet, hasSize(1)); + assertThat(resultSet, containsInAnyOrder("member1")); + } + + @Test + public void testZdiffStoreBinary() { + byte[] dstKey = "result".getBytes(); + + exec(commandObjects.zadd("set1".getBytes(), 1, "member1".getBytes())); + exec(commandObjects.zadd("set1".getBytes(), 2, "member2".getBytes())); + exec(commandObjects.zadd("set2".getBytes(), 3, "member2".getBytes())); + + Long result = exec(commandObjects.zdiffStore(dstKey, "set1".getBytes(), "set2".getBytes())); + assertThat(result, equalTo(1L)); + + List resultSet = exec(commandObjects.zrange(dstKey, 0, -1)); + assertThat(resultSet, hasSize(1)); + assertThat(resultSet, containsInAnyOrder("member1".getBytes())); + + exec(commandObjects.del(dstKey)); + + result = exec(commandObjects.zdiffstore(dstKey, "set1".getBytes(), "set2".getBytes())); + assertThat(result, equalTo(1L)); + + resultSet = exec(commandObjects.zrange(dstKey, 0, -1)); + assertThat(resultSet, hasSize(1)); + assertThat(resultSet, containsInAnyOrder("member1".getBytes())); + } + + @Test + public void testZinterAndZintercard() { + ZParams params = new ZParams().aggregate(ZParams.Aggregate.SUM).weights(1, 2); + + exec(commandObjects.zadd("set1", 1, "member1")); + exec(commandObjects.zadd("set2", 2, "member1")); + exec(commandObjects.zadd("set2", 2, "member2")); + + List inter = exec(commandObjects.zinter(params, "set1", "set2")); + assertThat(inter, containsInAnyOrder("member1")); + + List interWithScores = exec(commandObjects.zinterWithScores(params, "set1", "set2")); + assertThat(interWithScores, containsInAnyOrder( + new Tuple("member1", 5.0))); + + Long card = exec(commandObjects.zintercard("set1", "set2")); + assertThat(card, equalTo(1L)); + + Long cardLimited = exec(commandObjects.zintercard(1L, "set1", "set2")); + assertThat(cardLimited, equalTo(1L)); + + List interBinary = exec(commandObjects.zinter(params, "set1".getBytes(), "set2".getBytes())); + assertThat(interBinary, containsInAnyOrder("member1".getBytes())); + + List interWithScoresBinary = exec(commandObjects.zinterWithScores(params, "set1".getBytes(), "set2".getBytes())); + assertThat(interWithScoresBinary, hasItem( + new Tuple("member1".getBytes(), 5.0))); + + Long cardBinary = exec(commandObjects.zintercard("set1".getBytes(), "set2".getBytes())); + assertThat(cardBinary, equalTo(1L)); + + Long cardLimitedBinary = exec(commandObjects.zintercard(1L, "set1".getBytes(), "set2".getBytes())); + assertThat(cardLimitedBinary, equalTo(1L)); + } + + @Test + public void testZinterstore() { + String dstKey = "destinationIntersect"; + String set1 = "sortedSet1"; + String set2 = "sortedSet2"; + String set3 = "sortedSet3"; + double score1 = 1.0; + double score2 = 2.0; + double score3 = 3.0; + String member1 = "member1"; + String member2 = "member2"; + String member3 = "member3"; + + exec(commandObjects.zadd(set1, score1, member1)); + exec(commandObjects.zadd(set1, score2, member2)); + + exec(commandObjects.zadd(set2, score2, member2)); + exec(commandObjects.zadd(set2, score3, member3)); + + exec(commandObjects.zadd(set3, score1, member1)); + exec(commandObjects.zadd(set3, score3, member3)); + + ZParams params = new ZParams().aggregate(ZParams.Aggregate.SUM); + + Long interStore = exec(commandObjects.zinterstore(dstKey, set1, set2, set3)); + assertThat(interStore, equalTo(0L)); + + Long interStoreWithParams = exec(commandObjects.zinterstore(dstKey, params, set1, set2)); + assertThat(interStoreWithParams, equalTo(1L)); + + List dstSetContent = exec(commandObjects.zrangeWithScores(dstKey, 0, -1)); + assertThat(dstSetContent, hasSize(1)); + assertThat(dstSetContent.get(0).getElement(), equalTo(member2)); + assertThat(dstSetContent.get(0).getScore(), equalTo(score2 * 2)); // Score aggregated as SUM + } + + @Test + public void testZinterstoreBinary() { + byte[] dstKey = "destinationIntersect".getBytes(); + byte[] set1 = "sortedSet1".getBytes(); + byte[] set2 = "sortedSet2".getBytes(); + byte[] set3 = "sortedSet3".getBytes(); + double score1 = 1.0; + double score2 = 2.0; + double score3 = 3.0; + byte[] member1 = "member1".getBytes(); + byte[] member2 = "member2".getBytes(); + byte[] member3 = "member3".getBytes(); + + exec(commandObjects.zadd(set1, score1, member1)); + exec(commandObjects.zadd(set1, score2, member2)); + + exec(commandObjects.zadd(set2, score2, member2)); + exec(commandObjects.zadd(set2, score3, member3)); + + exec(commandObjects.zadd(set3, score1, member1)); + exec(commandObjects.zadd(set3, score3, member3)); + + ZParams params = new ZParams().aggregate(ZParams.Aggregate.SUM); + + Long interStore = exec(commandObjects.zinterstore(dstKey, set1, set2, set3)); + assertThat(interStore, equalTo(0L)); + + List dstSetContent = exec(commandObjects.zrangeWithScores(dstKey, 0, -1)); + assertThat(dstSetContent, empty()); + + Long interStoreParams = exec(commandObjects.zinterstore(dstKey, params, set1, set2)); + assertThat(interStoreParams, equalTo(1L)); + + List dstSetParamsContent = exec(commandObjects.zrangeWithScores(dstKey, 0, -1)); + assertThat(dstSetParamsContent, hasSize(1)); + assertThat(dstSetParamsContent.get(0).getBinaryElement(), equalTo(member2)); + assertThat(dstSetParamsContent.get(0).getScore(), equalTo(score2 * 2)); // Score aggregated as SUM + } + + @Test + public void testZunionAndZunionWithScores() { + String key1 = "sortedSet1"; + String key2 = "sortedSet2"; + String member1 = "member1"; + String member2 = "member2"; + double score1 = 1.0; + double score2 = 2.0; + + exec(commandObjects.zadd(key1, score1, member1)); + + exec(commandObjects.zadd(key2, score2, member1)); + exec(commandObjects.zadd(key2, score2, member2)); + + ZParams params = new ZParams().aggregate(ZParams.Aggregate.SUM); + + List zunion = exec(commandObjects.zunion(params, key1, key2)); + assertThat(zunion, containsInAnyOrder(member1, member2)); + + List zunionWithScores = exec(commandObjects.zunionWithScores(params, key1, key2)); + assertThat(zunionWithScores, containsInAnyOrder( + new Tuple(member1, score1 + score2), + new Tuple(member2, score2))); + + List zunionBinary = exec(commandObjects.zunion(params, key1.getBytes(), key2.getBytes())); + assertThat(zunionBinary, containsInAnyOrder(member1.getBytes(), member2.getBytes())); + + List zunionWithScoresBinary = exec(commandObjects.zunionWithScores(params, key1.getBytes(), key2.getBytes())); + assertThat(zunionWithScoresBinary, containsInAnyOrder( + new Tuple(member1, score1 + score2), + new Tuple(member2, score2))); + } + + @Test + public void testZunionstore() { + String dstKey = "destinationSet"; + String set1 = "sortedSet1"; + String set2 = "sortedSet2"; + double score1 = 1.0; + double score2 = 2.0; + double score3 = 3.0; + String member1 = "member1"; + String member2 = "member2"; + String member3 = "member3"; + + exec(commandObjects.zadd(set1, score1, member1)); + exec(commandObjects.zadd(set1, score2, member2)); + exec(commandObjects.zadd(set1, score3, member3)); + + exec(commandObjects.zadd(set2, score3, member3)); + + ZParams params = new ZParams().aggregate(ZParams.Aggregate.MAX); + + Long zunionStore = exec(commandObjects.zunionstore(dstKey, set1, set2)); + assertThat(zunionStore, equalTo(3L)); + + List dstSetContent = exec(commandObjects.zrangeWithScores(dstKey, 0, -1)); + assertThat(dstSetContent, containsInAnyOrder( + new Tuple(member1, score1), + new Tuple(member2, score2), + new Tuple(member3, score3 * 2))); + + Long zunionStoreParams = exec(commandObjects.zunionstore(dstKey, params, set1, set2)); + assertThat(zunionStoreParams, equalTo(3L)); + + List dstSetContentParams = exec(commandObjects.zrangeWithScores(dstKey, 0, -1)); + assertThat(dstSetContentParams, containsInAnyOrder( + new Tuple(member1, score1), + new Tuple(member2, score2), + new Tuple(member3, score3))); + } + + @Test + public void testZunionstoreBinary() { + byte[] dstKey = "destinationSet".getBytes(); + byte[] set1 = "sortedSet1".getBytes(); + byte[] set2 = "sortedSet2".getBytes(); + double score1 = 1.0; + double score2 = 2.0; + double score3 = 3.0; + byte[] member1 = "member1".getBytes(); + byte[] member2 = "member2".getBytes(); + byte[] member3 = "member3".getBytes(); + + exec(commandObjects.zadd(set1, score1, member1)); + exec(commandObjects.zadd(set1, score2, member2)); + exec(commandObjects.zadd(set1, score3, member3)); + + exec(commandObjects.zadd(set2, score3, member3)); + + ZParams params = new ZParams().aggregate(ZParams.Aggregate.MAX); + + Long zunionStore = exec(commandObjects.zunionstore(dstKey, set1, set2)); + assertThat(zunionStore, equalTo(3L)); + + List dstSetContent = exec(commandObjects.zrangeWithScores(dstKey, 0, -1)); + assertThat(dstSetContent, containsInAnyOrder( + new Tuple(member1, score1), + new Tuple(member2, score2), + new Tuple(member3, score3 * 2))); + + Long zunionStoreParams = exec(commandObjects.zunionstore(dstKey, params, set1, set2)); + assertThat(zunionStoreParams, equalTo(3L)); + + List dstSetContentParams = exec(commandObjects.zrangeWithScores(dstKey, 0, -1)); + assertThat(dstSetContentParams, containsInAnyOrder( + new Tuple(member1, score1), + new Tuple(member2, score2), + new Tuple(member3, score3))); + } + + @Test + public void testZmpopAndZmpopWithCount() { + String key1 = "sortedSet1"; + String key2 = "sortedSet2"; + double score1 = 1.0; + double score2 = 2.0; + String member1 = "member1"; + String member2 = "member2"; + + exec(commandObjects.zadd(key1, score1, member1)); + exec(commandObjects.zadd(key2, score2, member2)); + + KeyValue> zmpop = exec(commandObjects.zmpop(SortedSetOption.MAX, key1, key2)); + + assertThat(zmpop, notNullValue()); + assertThat(zmpop.getKey(), either(equalTo(key1)).or(equalTo(key2))); + assertThat(zmpop.getValue(), hasSize(1)); + + KeyValue> zmpopCount = exec(commandObjects.zmpop(SortedSetOption.MIN, 2, key1, key2)); + + assertThat(zmpopCount, notNullValue()); + assertThat(zmpopCount.getKey(), either(equalTo(key1)).or(equalTo(key2))); + assertThat(zmpopCount.getValue(), hasSize(1)); + } + + @Test + public void testZmpopAndZmpopWithCountBinary() { + byte[] key1 = "sortedSet1".getBytes(); + byte[] key2 = "sortedSet2".getBytes(); + double score1 = 1.0; + double score2 = 2.0; + byte[] member1 = "member1".getBytes(); + byte[] member2 = "member2".getBytes(); + + exec(commandObjects.zadd(key1, score1, member1)); + exec(commandObjects.zadd(key2, score2, member2)); + + KeyValue> zmpopBinary = exec(commandObjects.zmpop(SortedSetOption.MAX, key1, key2)); + + assertThat(zmpopBinary, notNullValue()); + assertThat(zmpopBinary.getKey(), either(equalTo(key1)).or(equalTo(key2))); + assertThat(zmpopBinary.getValue(), hasSize(1)); + + KeyValue> zmpopCountBinary = exec(commandObjects.zmpop(SortedSetOption.MIN, 2, key1, key2)); + + assertThat(zmpopCountBinary, notNullValue()); + assertThat(zmpopCountBinary.getKey(), either(equalTo(key1)).or(equalTo(key2))); + assertThat(zmpopCountBinary.getValue(), hasSize(1)); + } + + @Test + public void testBzmpop() { + String key1 = "sortedSet1"; + String key2 = "sortedSet2"; + double score1 = 1.0; + double score2 = 2.0; + double timeout = 0.1; + String member1 = "member1"; + String member2 = "member2"; + + exec(commandObjects.zadd(key1, score1, member1)); + exec(commandObjects.zadd(key2, score2, member2)); + + KeyValue> bzmpop = exec(commandObjects.bzmpop(timeout, SortedSetOption.MAX, 1, key1, key2)); + assertThat(bzmpop, notNullValue()); + assertThat(bzmpop.getKey(), either(equalTo(key1)).or(equalTo(key2))); + assertThat(bzmpop.getValue(), hasSize(1)); + } + + @Test + public void testBzmpopBinary() { + byte[] key1 = "sortedSet1".getBytes(); + byte[] key2 = "sortedSet2".getBytes(); + double score1 = 1.0; + double score2 = 2.0; + double timeout = 0.1; + byte[] member1 = "member1".getBytes(); + byte[] member2 = "member2".getBytes(); + + exec(commandObjects.zadd(key1, score1, member1)); + exec(commandObjects.zadd(key2, score2, member2)); + + KeyValue> bzmpopBinary = exec(commandObjects.bzmpop(timeout, SortedSetOption.MAX, 1, key1, key2)); + assertThat(bzmpopBinary, notNullValue()); + assertThat(bzmpopBinary.getKey(), either(equalTo(key1)).or(equalTo(key2))); + assertThat(bzmpopBinary.getValue(), hasSize(1)); + } +} diff --git a/src/test/java/redis/clients/jedis/commands/commandobjects/CommandObjectsStandaloneTestBase.java b/src/test/java/redis/clients/jedis/commands/commandobjects/CommandObjectsStandaloneTestBase.java new file mode 100644 index 00000000000..fa4a43ea800 --- /dev/null +++ b/src/test/java/redis/clients/jedis/commands/commandobjects/CommandObjectsStandaloneTestBase.java @@ -0,0 +1,15 @@ +package redis.clients.jedis.commands.commandobjects; + +import redis.clients.jedis.HostAndPorts; +import redis.clients.jedis.RedisProtocol; + +/** + * Base class for tests that use the standalone client. + */ +public abstract class CommandObjectsStandaloneTestBase extends CommandObjectsTestBase { + + public CommandObjectsStandaloneTestBase(RedisProtocol protocol) { + super(protocol, HostAndPorts.getRedisServers().get(0), "foobared"); + } + +} diff --git a/src/test/java/redis/clients/jedis/commands/commandobjects/CommandObjectsStreamCommandsTest.java b/src/test/java/redis/clients/jedis/commands/commandobjects/CommandObjectsStreamCommandsTest.java new file mode 100644 index 00000000000..29785440939 --- /dev/null +++ b/src/test/java/redis/clients/jedis/commands/commandobjects/CommandObjectsStreamCommandsTest.java @@ -0,0 +1,1023 @@ +package redis.clients.jedis.commands.commandobjects; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.empty; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.hasSize; +import static org.hamcrest.Matchers.instanceOf; +import static org.hamcrest.Matchers.not; +import static org.hamcrest.Matchers.notNullValue; + +import java.util.AbstractMap; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Optional; + +import org.junit.Test; +import redis.clients.jedis.RedisProtocol; +import redis.clients.jedis.StreamEntryID; +import redis.clients.jedis.params.XAddParams; +import redis.clients.jedis.params.XAutoClaimParams; +import redis.clients.jedis.params.XClaimParams; +import redis.clients.jedis.params.XPendingParams; +import redis.clients.jedis.params.XReadGroupParams; +import redis.clients.jedis.params.XReadParams; +import redis.clients.jedis.resps.StreamConsumerInfo; +import redis.clients.jedis.resps.StreamConsumersInfo; +import redis.clients.jedis.resps.StreamEntry; +import redis.clients.jedis.resps.StreamFullInfo; +import redis.clients.jedis.resps.StreamGroupInfo; +import redis.clients.jedis.resps.StreamInfo; +import redis.clients.jedis.resps.StreamPendingEntry; +import redis.clients.jedis.resps.StreamPendingSummary; + +/** + * Tests related to Stream commands. + */ +public class CommandObjectsStreamCommandsTest extends CommandObjectsStandaloneTestBase { + + public CommandObjectsStreamCommandsTest(RedisProtocol protocol) { + super(protocol); + } + + @Test + public void testXaddAndXlen() { + String streamKey = "testStream"; + StreamEntryID entryID = StreamEntryID.NEW_ENTRY; + + Map entryData = new HashMap<>(); + entryData.put("field1", "value1"); + entryData.put("field2", "value2"); + + StreamEntryID addedEntryId = exec(commandObjects.xadd(streamKey, entryID, entryData)); + assertThat(addedEntryId, notNullValue()); + + XAddParams params = new XAddParams().maxLen(1000); + StreamEntryID addedEntryIdWithParams = exec(commandObjects.xadd(streamKey, params, entryData)); + assertThat(addedEntryIdWithParams, notNullValue()); + + Long streamLength = exec(commandObjects.xlen(streamKey)); + assertThat(streamLength, equalTo(2L)); + } + + @Test + public void testXaddAndXlenBinary() { + byte[] streamKey = "streamKey".getBytes(); + + Map entryData = new HashMap<>(); + entryData.put("field1".getBytes(), "value1".getBytes()); + entryData.put("field2".getBytes(), "value2".getBytes()); + + XAddParams params = new XAddParams().maxLen(1000); + byte[] addedEntryId = exec(commandObjects.xadd(streamKey, params, entryData)); + assertThat(addedEntryId, notNullValue()); + + Long streamLengthBytes = exec(commandObjects.xlen(streamKey)); + assertThat(streamLengthBytes, equalTo(1L)); + } + + @Test + public void testXrangeWithIdParameters() { + String key = "testStream"; + + Map entryData1 = new HashMap<>(); + entryData1.put("field1", "value1"); + + Map entryData2 = new HashMap<>(); + entryData2.put("field2", "value2"); + + StreamEntryID startID = exec(commandObjects.xadd(key, StreamEntryID.NEW_ENTRY, entryData1)); + StreamEntryID endID = exec(commandObjects.xadd(key, StreamEntryID.NEW_ENTRY, entryData2)); + + List xrangeAll = exec(commandObjects.xrange(key, null, (StreamEntryID) null)); + assertThat(xrangeAll.size(), equalTo(2)); + assertThat(xrangeAll.get(0).getFields(), equalTo(entryData1)); + assertThat(xrangeAll.get(1).getFields(), equalTo(entryData2)); + + List xrangeAllCount = exec(commandObjects.xrange(key, null, (StreamEntryID) null, 1)); + assertThat(xrangeAllCount.size(), equalTo(1)); + assertThat(xrangeAllCount.get(0).getFields(), equalTo(entryData1)); + + List xrangeStartEnd = exec(commandObjects.xrange(key, startID, endID)); + assertThat(xrangeStartEnd.size(), equalTo(2)); + assertThat(xrangeStartEnd.get(0).getFields(), equalTo(entryData1)); + assertThat(xrangeStartEnd.get(1).getFields(), equalTo(entryData2)); + + List xrangeStartEndCount = exec(commandObjects.xrange(key, startID, endID, 1)); + assertThat(xrangeStartEndCount.size(), equalTo(1)); + assertThat(xrangeStartEndCount.get(0).getFields(), equalTo(entryData1)); + + List xrangeUnknown = exec(commandObjects.xrange("nonExistingStream", null, (StreamEntryID) null)); + assertThat(xrangeUnknown, empty()); + } + + @Test + public void testXrangeWithStringParameters() { + String key = "testStreamWithString"; + + Map entryData1 = new HashMap<>(); + entryData1.put("field1", "value1"); + + Map entryData2 = new HashMap<>(); + entryData2.put("field2", "value2"); + + StreamEntryID startID = exec(commandObjects.xadd(key, StreamEntryID.NEW_ENTRY, entryData1)); + StreamEntryID endID = exec(commandObjects.xadd(key, StreamEntryID.NEW_ENTRY, entryData2)); + + String start = startID.toString(); + String end = endID.toString(); + + List xrangeStartEnd = exec(commandObjects.xrange(key, start, end)); + assertThat(xrangeStartEnd.size(), equalTo(2)); + assertThat(xrangeStartEnd.get(0).getFields(), equalTo(entryData1)); + assertThat(xrangeStartEnd.get(1).getFields(), equalTo(entryData2)); + + List xrangeStartEndCount = exec(commandObjects.xrange(key, start, end, 1)); + assertThat(xrangeStartEndCount.size(), equalTo(1)); + assertThat(xrangeStartEndCount.get(0).getFields(), equalTo(entryData1)); + + List xrangeUnknown = exec(commandObjects.xrange("nonExistingStream", start, end)); + assertThat(xrangeUnknown, empty()); + } + + @Test + public void testXrangeWithBinaryParameters() { + String keyStr = "testStreamWithBytes"; + byte[] key = keyStr.getBytes(); + + Map entryData1 = new HashMap<>(); + entryData1.put("field1", "value1"); + + Map entryData2 = new HashMap<>(); + entryData2.put("field2", "value2"); + + StreamEntryID startID = exec(commandObjects.xadd(keyStr, StreamEntryID.NEW_ENTRY, entryData1)); + StreamEntryID endID = exec(commandObjects.xadd(keyStr, StreamEntryID.NEW_ENTRY, entryData2)); + + byte[] start = startID.toString().getBytes(); + byte[] end = endID.toString().getBytes(); + + List xrangeAll = exec(commandObjects.xrange(key, null, null)); + assertThat(xrangeAll, hasSize(2)); + assertThat(xrangeAll.get(0), instanceOf(List.class)); + assertThat(((List) xrangeAll.get(0)).get(0), equalTo(start)); + assertThat(((List) xrangeAll.get(1)).get(0), equalTo(end)); + + List xrangeStartEnd = exec(commandObjects.xrange(key, start, end)); + assertThat(xrangeStartEnd, hasSize(2)); + assertThat(xrangeStartEnd.get(0), instanceOf(List.class)); + assertThat(((List) xrangeStartEnd.get(0)).get(0), equalTo(start)); + assertThat(((List) xrangeStartEnd.get(1)).get(0), equalTo(end)); + + List xrangeAllCount = exec(commandObjects.xrange(key, null, null, 1)); + assertThat(xrangeAllCount, hasSize(1)); + assertThat(xrangeAllCount.get(0), instanceOf(List.class)); + assertThat(((List) xrangeAllCount.get(0)).get(0), equalTo(start)); + + List xrangeStartEndCount = exec(commandObjects.xrange(key, start, end, 1)); + assertThat(xrangeStartEndCount, hasSize(1)); + assertThat(xrangeStartEndCount.get(0), instanceOf(List.class)); + assertThat(((List) xrangeStartEndCount.get(0)).get(0), equalTo(start)); + + List xrangeUnknown = exec(commandObjects.xrange("nonExistingStream".getBytes(), start, end)); + assertThat(xrangeUnknown, empty()); + } + + @Test + public void testXrevrangeWithIdParameters() { + String key = "testStreamForXrevrange"; + + Map entryData1 = new HashMap<>(); + entryData1.put("field1", "value1"); + + Map entryData2 = new HashMap<>(); + entryData2.put("field2", "value2"); + + StreamEntryID startID = exec(commandObjects.xadd(key, StreamEntryID.NEW_ENTRY, entryData1)); + StreamEntryID endID = exec(commandObjects.xadd(key, StreamEntryID.NEW_ENTRY, entryData2)); + + List xrevrangeAll = exec(commandObjects.xrevrange(key, null, (StreamEntryID) null)); + assertThat(xrevrangeAll.size(), equalTo(2)); + assertThat(xrevrangeAll.get(0).getFields(), equalTo(entryData2)); // The latest entry comes first + assertThat(xrevrangeAll.get(1).getFields(), equalTo(entryData1)); + + List xrevrangeAllCount = exec(commandObjects.xrevrange(key, null, (StreamEntryID) null, 1)); + assertThat(xrevrangeAllCount.size(), equalTo(1)); + assertThat(xrevrangeAllCount.get(0).getFields(), equalTo(entryData2)); // Only the latest entry is returned + + List xrevrangeEndStart = exec(commandObjects.xrevrange(key, endID, startID)); + assertThat(xrevrangeEndStart.size(), equalTo(2)); + assertThat(xrevrangeEndStart.get(0).getFields(), equalTo(entryData2)); + assertThat(xrevrangeEndStart.get(1).getFields(), equalTo(entryData1)); + + List xrevrangeStartEndCount = exec(commandObjects.xrevrange(key, endID, startID, 1)); + assertThat(xrevrangeStartEndCount.size(), equalTo(1)); + assertThat(xrevrangeStartEndCount.get(0).getFields(), equalTo(entryData2)); + + List xrevrangeUnknown = exec(commandObjects.xrevrange("nonExistingStream", null, (StreamEntryID) null)); + assertThat(xrevrangeUnknown, empty()); + } + + @Test + public void testXrevrangeWithStringParameters() { + String key = "testStreamForXrevrangeString"; + + Map entryData1 = new HashMap<>(); + entryData1.put("field1", "value1"); + + Map entryData2 = new HashMap<>(); + entryData2.put("field2", "value2"); + + StreamEntryID startID = exec(commandObjects.xadd(key, StreamEntryID.NEW_ENTRY, entryData1)); + StreamEntryID endID = exec(commandObjects.xadd(key, StreamEntryID.NEW_ENTRY, entryData2)); + + String start = startID.toString(); + String end = endID.toString(); + + List xrevrangeAll = exec(commandObjects.xrevrange(key, null, (StreamEntryID) null)); + assertThat(xrevrangeAll.size(), equalTo(2)); + assertThat(xrevrangeAll.get(0).getFields(), equalTo(entryData2)); // The latest entry comes first + assertThat(xrevrangeAll.get(1).getFields(), equalTo(entryData1)); + + List xrevrangeEndStart = exec(commandObjects.xrevrange(key, end, start)); + assertThat(xrevrangeEndStart.size(), equalTo(2)); + assertThat(xrevrangeEndStart.get(0).getFields(), equalTo(entryData2)); + assertThat(xrevrangeEndStart.get(1).getFields(), equalTo(entryData1)); + + List xrevrangeAllCount = exec(commandObjects.xrevrange(key, null, (StreamEntryID) null, 1)); + assertThat(xrevrangeAllCount.size(), equalTo(1)); + assertThat(xrevrangeAllCount.get(0).getFields(), equalTo(entryData2)); + + List xrevrangeEndStartCount = exec(commandObjects.xrevrange(key, end, start, 1)); + assertThat(xrevrangeEndStartCount.size(), equalTo(1)); + assertThat(xrevrangeEndStartCount.get(0).getFields(), equalTo(entryData2)); + + List xrevrangeUnknown = exec(commandObjects.xrevrange("nonExistingStream", end, start)); + assertThat(xrevrangeUnknown, empty()); + } + + @Test + public void testXrevrangeWithBinaryParameters() { + String keyStr = "testStreamForXrevrangeBytes"; + byte[] key = keyStr.getBytes(); + + Map entryData1 = new HashMap<>(); + entryData1.put("field1", "value1"); + + Map entryData2 = new HashMap<>(); + entryData2.put("field2", "value2"); + + StreamEntryID startID = exec(commandObjects.xadd(keyStr, StreamEntryID.NEW_ENTRY, entryData1)); + StreamEntryID endID = exec(commandObjects.xadd(keyStr, StreamEntryID.NEW_ENTRY, entryData2)); + + byte[] start = startID.toString().getBytes(); + byte[] end = endID.toString().getBytes(); + + List xrevrangeAll = exec(commandObjects.xrevrange(key, null, null)); + assertThat(xrevrangeAll, hasSize(2)); + assertThat(xrevrangeAll.get(0), instanceOf(List.class)); + assertThat(((List) xrevrangeAll.get(0)).get(0), equalTo(end)); + assertThat(((List) xrevrangeAll.get(1)).get(0), equalTo(start)); + + List xrevrangeEndStart = exec(commandObjects.xrevrange(key, end, start)); + assertThat(xrevrangeEndStart, hasSize(2)); + assertThat(xrevrangeEndStart.get(0), instanceOf(List.class)); + assertThat(((List) xrevrangeEndStart.get(0)).get(0), equalTo(end)); + assertThat(((List) xrevrangeEndStart.get(1)).get(0), equalTo(start)); + + List xrevrangeAllCount = exec(commandObjects.xrevrange(key, null, null, 1)); + assertThat(xrevrangeAllCount, hasSize(1)); + assertThat(xrevrangeAllCount.get(0), instanceOf(List.class)); + assertThat(((List) xrevrangeAllCount.get(0)).get(0), equalTo(end)); + + List xrevrangeEndStartCount = exec(commandObjects.xrevrange(key, end, start, 1)); + assertThat(xrevrangeEndStartCount, hasSize(1)); + assertThat(xrevrangeEndStartCount.get(0), instanceOf(List.class)); + assertThat(((List) xrevrangeEndStartCount.get(0)).get(0), equalTo(end)); + + List xrevrangeUnknown = exec(commandObjects.xrevrange("nonExistingStream".getBytes(), end, start)); + assertThat(xrevrangeUnknown, empty()); + } + + @Test + public void testXackXpending() { + String key = "testStreamForXackEffect"; + String group = "testGroup"; + String consumer = "testConsumer"; + + Map entryData = new HashMap<>(); + entryData.put("field1", "value1"); + + exec(commandObjects.xgroupCreate(key, group, new StreamEntryID(), true)); + + StreamEntryID entryID = exec(commandObjects.xadd(key, StreamEntryID.NEW_ENTRY, entryData)); + + Map streams = Collections.singletonMap(key, StreamEntryID.XREADGROUP_UNDELIVERED_ENTRY); + + XReadGroupParams params = new XReadGroupParams(); + + List>> messages = exec(commandObjects.xreadGroup(group, consumer, params, streams)); + + assertThat(messages, hasSize(1)); + assertThat(messages.get(0).getKey(), equalTo(key)); + assertThat(messages.get(0).getValue(), hasSize(1)); + assertThat(messages.get(0).getValue().get(0).getID(), equalTo(entryID)); + + StreamPendingSummary pendingSummary = exec(commandObjects.xpending(key, group)); + assertThat(pendingSummary.getTotal(), equalTo(1L)); + + XPendingParams xPendingParams = new XPendingParams() + .start(StreamEntryID.MINIMUM_ID).end(StreamEntryID.MAXIMUM_ID).count(1000); + List pendingSummaryWithParams = exec(commandObjects.xpending(key, group, xPendingParams)); + + assertThat(pendingSummaryWithParams, hasSize(1)); + assertThat(pendingSummaryWithParams.get(0).getConsumerName(), equalTo(consumer)); + assertThat(pendingSummaryWithParams.get(0).getID(), equalTo(entryID)); + + Long ack = exec(commandObjects.xack(key, group, entryID)); + assertThat(ack, equalTo(1L)); + + pendingSummary = exec(commandObjects.xpending(key, group)); + assertThat(pendingSummary.getTotal(), equalTo(0L)); + + pendingSummaryWithParams = exec(commandObjects.xpending(key, group, xPendingParams)); + assertThat(pendingSummaryWithParams, empty()); + } + + @Test + public void testXackXPendingBinary() { + String keyStr = "testStreamForXackEffect"; + byte[] key = keyStr.getBytes(); + byte[] group = "testGroup".getBytes(); + byte[] consumer = "testConsumer".getBytes(); + + Map entryData = new HashMap<>(); + entryData.put("field1", "value1"); + + exec(commandObjects.xgroupCreate(key, group, new StreamEntryID().toString().getBytes(), true)); + + StreamEntryID entryID = exec(commandObjects.xadd(keyStr, StreamEntryID.NEW_ENTRY, entryData)); + + Map.Entry stream = new AbstractMap.SimpleEntry<>(key, StreamEntryID.XREADGROUP_UNDELIVERED_ENTRY.toString().getBytes()); + + XReadGroupParams params = new XReadGroupParams(); + + List messages = exec(commandObjects.xreadGroup(group, consumer, params, stream)); + assertThat(messages, hasSize(1)); + + Object pendingSummary = exec(commandObjects.xpending(key, group)); + + assertThat(pendingSummary, instanceOf(List.class)); + assertThat(((List) pendingSummary).get(0), equalTo(1L)); + + XPendingParams xPendingParams = new XPendingParams() + .start(StreamEntryID.MINIMUM_ID).end(StreamEntryID.MAXIMUM_ID).count(1000); + + List pendingList = exec(commandObjects.xpending(key, group, xPendingParams)); + assertThat(pendingList, hasSize(1)); + + Long ack = exec(commandObjects.xack(key, group, entryID.toString().getBytes())); + assertThat(ack, equalTo(1L)); + + pendingSummary = exec(commandObjects.xpending(key, group)); + assertThat(pendingSummary, instanceOf(List.class)); + assertThat(((List) pendingSummary).get(0), equalTo(0L)); + + pendingList = exec(commandObjects.xpending(key, group, xPendingParams)); + assertThat(pendingList, empty()); + } + + @Test + public void testXGroupSetID() { + String key = "testStream"; + String groupName = "testGroup"; + + StreamEntryID initialId = new StreamEntryID(); + StreamEntryID newId = new StreamEntryID("0-1"); + StreamEntryID newId2 = new StreamEntryID("0-2"); + + exec(commandObjects.xadd(key, StreamEntryID.NEW_ENTRY, Collections.singletonMap("field", "value"))); + + exec(commandObjects.xgroupCreate(key, groupName, initialId, false)); + + List groupIdBefore = exec(commandObjects.xinfoGroups(key)); + + assertThat(groupIdBefore, hasSize(1)); + assertThat(groupIdBefore.get(0).getName(), equalTo(groupName)); + assertThat(groupIdBefore.get(0).getLastDeliveredId(), equalTo(initialId)); + + String xgroupSetId = exec(commandObjects.xgroupSetID(key, groupName, newId)); + assertThat(xgroupSetId, equalTo("OK")); + + List groupIdAfter = exec(commandObjects.xinfoGroups(key)); + + assertThat(groupIdAfter, hasSize(1)); + assertThat(groupIdAfter.get(0).getName(), equalTo(groupName)); + assertThat(groupIdAfter.get(0).getLastDeliveredId(), equalTo(newId)); + + String xgroupSetIdBinary = exec(commandObjects.xgroupSetID(key.getBytes(), groupName.getBytes(), newId2.toString().getBytes())); + assertThat(xgroupSetIdBinary, equalTo("OK")); + + List groupIdAfterBinary = exec(commandObjects.xinfoGroups(key)); + + assertThat(groupIdAfterBinary, hasSize(1)); + assertThat(groupIdAfterBinary.get(0).getName(), equalTo(groupName)); + assertThat(groupIdAfterBinary.get(0).getLastDeliveredId(), equalTo(newId2)); + + List binaryGroupIdAfterBinary = exec(commandObjects.xinfoGroups(key.getBytes())); + assertThat(binaryGroupIdAfterBinary, notNullValue()); + } + + @Test + public void testXGroupDestroy() { + String key = "testStream"; + String groupName = "testGroup"; + + StreamEntryID initialId = new StreamEntryID(); + + exec(commandObjects.xadd(key, StreamEntryID.NEW_ENTRY, Collections.singletonMap("field", "value"))); + + exec(commandObjects.xgroupCreate(key, groupName, initialId, false)); + + List groupIdBefore = exec(commandObjects.xinfoGroups(key)); + + assertThat(groupIdBefore, hasSize(1)); + assertThat(groupIdBefore.get(0).getName(), equalTo(groupName)); + assertThat(groupIdBefore.get(0).getLastDeliveredId(), equalTo(initialId)); + + Long xgroupDestroy = exec(commandObjects.xgroupDestroy(key, groupName)); + assertThat(xgroupDestroy, equalTo(1L)); + + List groupInfoAfter = exec(commandObjects.xinfoGroups(key)); + assertThat(groupInfoAfter, empty()); + + // Re-create the group + exec(commandObjects.xgroupCreate(key, groupName, initialId, false)); + + List groupIdBeforeBinary = exec(commandObjects.xinfoGroups(key)); + + assertThat(groupIdBeforeBinary, hasSize(1)); + assertThat(groupIdBeforeBinary.get(0).getName(), equalTo(groupName)); + assertThat(groupIdBeforeBinary.get(0).getLastDeliveredId(), equalTo(initialId)); + + Long xgroupDestroyBinary = exec(commandObjects.xgroupDestroy(key.getBytes(), groupName.getBytes())); + assertThat(xgroupDestroyBinary, equalTo(1L)); + + List groupInfoAfterBinary = exec(commandObjects.xinfoGroups(key)); + assertThat(groupInfoAfterBinary, empty()); + } + + @Test + public void testXGroupConsumer() { + String key = "testStream"; + String groupName = "testGroup"; + String consumerName = "testConsumer"; + + StreamEntryID initialId = new StreamEntryID(); + + exec(commandObjects.xadd(key, StreamEntryID.NEW_ENTRY, Collections.singletonMap("field", "value"))); + + exec(commandObjects.xgroupCreate(key, groupName, initialId, false)); + + List groupIdBefore = exec(commandObjects.xinfoGroups(key)); + + assertThat(groupIdBefore, hasSize(1)); + assertThat(groupIdBefore.get(0).getName(), equalTo(groupName)); + assertThat(groupIdBefore.get(0).getConsumers(), equalTo(0L)); + + Boolean createConsumer = exec(commandObjects.xgroupCreateConsumer(key, groupName, consumerName)); + assertThat(createConsumer, equalTo(true)); + + List groupIdAfterCreateConsumer = exec(commandObjects.xinfoGroups(key)); + + assertThat(groupIdAfterCreateConsumer, hasSize(1)); + assertThat(groupIdAfterCreateConsumer.get(0).getName(), equalTo(groupName)); + assertThat(groupIdAfterCreateConsumer.get(0).getConsumers(), equalTo(1L)); + + Long deleteConsumer = exec(commandObjects.xgroupDelConsumer(key, groupName, consumerName)); + assertThat(deleteConsumer, equalTo(0L)); + + List groupIdAfterDeleteConsumer = exec(commandObjects.xinfoGroups(key)); + + assertThat(groupIdAfterDeleteConsumer, hasSize(1)); + assertThat(groupIdAfterDeleteConsumer.get(0).getName(), equalTo(groupName)); + assertThat(groupIdAfterDeleteConsumer.get(0).getConsumers(), equalTo(0L)); + + Boolean createConsumerBinary = exec(commandObjects.xgroupCreateConsumer( + key.getBytes(), groupName.getBytes(), consumerName.getBytes())); + assertThat(createConsumerBinary, equalTo(true)); + + List groupIdAfterCreateConsumerBinary = exec(commandObjects.xinfoGroups(key)); + + assertThat(groupIdAfterCreateConsumerBinary, hasSize(1)); + assertThat(groupIdAfterCreateConsumerBinary.get(0).getName(), equalTo(groupName)); + assertThat(groupIdAfterCreateConsumerBinary.get(0).getConsumers(), equalTo(1L)); + + Long deleteConsumerBinary = exec(commandObjects.xgroupDelConsumer( + key.getBytes(), groupName.getBytes(), consumerName.getBytes())); + assertThat(deleteConsumerBinary, equalTo(0L)); + + List groupIdAfterDeleteConsumerBinary = exec(commandObjects.xinfoGroups(key)); + + assertThat(groupIdAfterDeleteConsumerBinary, hasSize(1)); + assertThat(groupIdAfterDeleteConsumerBinary.get(0).getName(), equalTo(groupName)); + assertThat(groupIdAfterDeleteConsumerBinary.get(0).getConsumers(), equalTo(0L)); + } + + @Test + public void testXDelWithStreamSize() { + String key = "testStream"; + + StreamEntryID id1 = exec(commandObjects.xadd(key, StreamEntryID.NEW_ENTRY, Collections.singletonMap("field1", "value1"))); + StreamEntryID id2 = exec(commandObjects.xadd(key, StreamEntryID.NEW_ENTRY, Collections.singletonMap("field2", "value2"))); + + Long sizeBefore = exec(commandObjects.xlen(key)); + assertThat(sizeBefore, equalTo(2L)); + + Long xdel = exec(commandObjects.xdel(key, id1, id2)); + assertThat(xdel, equalTo(2L)); + + Long sizeAfterStringDeletion = exec(commandObjects.xlen(key)); + assertThat(sizeAfterStringDeletion, equalTo(0L)); + + StreamEntryID id3 = exec(commandObjects.xadd(key, StreamEntryID.NEW_ENTRY, Collections.singletonMap("field3", "value3"))); + StreamEntryID id4 = exec(commandObjects.xadd(key, StreamEntryID.NEW_ENTRY, Collections.singletonMap("field4", "value4"))); + + Long sizeBeforeBinaryDeletion = exec(commandObjects.xlen(key)); + assertThat(sizeBeforeBinaryDeletion, equalTo(2L)); + + Long xdelBinary = exec(commandObjects.xdel( + key.getBytes(), id3.toString().getBytes(), id4.toString().getBytes())); + assertThat(xdelBinary, equalTo(2L)); + + Long sizeAfterBinaryDeletion = exec(commandObjects.xlen(key)); + assertThat(sizeAfterBinaryDeletion, equalTo(0L)); + } + + @Test + public void testXTrimCommands() { + String key = "testStream"; + + // Populate the stream with more entries than we intend to keep + for (int i = 0; i < 10; i++) { + exec(commandObjects.xadd(key, StreamEntryID.NEW_ENTRY, Collections.singletonMap("field" + i, "value" + i))); + } + + Long sizeBeforeTrim = exec(commandObjects.xlen(key)); + assertThat(sizeBeforeTrim, equalTo(10L)); + + Long xtrim = exec(commandObjects.xtrim(key, 5, false)); + assertThat(xtrim, equalTo(5L)); + + Long sizeAfterTrim = exec(commandObjects.xlen(key)); + assertThat(sizeAfterTrim, equalTo(5L)); + + // Repopulate the stream for byte[] parameter tests. + // Adding back 5 entries to ensure we have 10 again. + byte[] bKey = key.getBytes(); + for (int i = 5; i < 10; i++) { + exec(commandObjects.xadd(key, StreamEntryID.NEW_ENTRY, Collections.singletonMap("field" + i, "value" + i))); + } + + Long sizeBeforeBinaryTrim = exec(commandObjects.xlen(key)); + assertThat(sizeBeforeBinaryTrim, equalTo(10L)); + + Long xtrimBinary = exec(commandObjects.xtrim(bKey, 5, false)); + assertThat(xtrimBinary, equalTo(5L)); + + Long sizeAfterBinaryTrim = exec(commandObjects.xlen(key)); + assertThat(sizeAfterBinaryTrim, equalTo(5L)); + } + + @Test + public void testXClaim() throws InterruptedException { + String key = "testStream"; + String group = "testGroup"; + String consumer1 = "consumer1"; + String consumer2 = "consumer2"; + + StreamEntryID initialId = new StreamEntryID(); + + exec(commandObjects.xgroupCreate(key, group, initialId, true)); + + StreamEntryID messageId = exec(commandObjects.xadd(key, StreamEntryID.NEW_ENTRY, Collections.singletonMap("field", "value2"))); + + // Consumer1 reads the message to make it pending + Map stream = Collections.singletonMap(key, StreamEntryID.XREADGROUP_UNDELIVERED_ENTRY); + List>> readEntries = exec( + commandObjects.xreadGroup(group, consumer1, new XReadGroupParams().count(1), stream)); + + assertThat(readEntries, hasSize(1)); + assertThat(readEntries.get(0).getKey(), equalTo(key)); + assertThat(readEntries.get(0).getValue(), hasSize(1)); + assertThat(readEntries.get(0).getValue().get(0).getID(), equalTo(messageId)); + + Thread.sleep(200); // Wait a bit + + // Claim the message for consumer2 + List claimedMessages = exec( + commandObjects.xclaim(key, group, consumer2, 1, new XClaimParams(), messageId)); + + assertThat(claimedMessages, hasSize(1)); + assertThat(claimedMessages.get(0).getID(), equalTo(messageId)); + } + + @Test + public void testXClaimBinary() throws InterruptedException { + String key = "testStream"; + String group = "testGroup"; + String consumer1 = "consumer1"; + String consumer2 = "consumer2"; + + StreamEntryID initialId = new StreamEntryID(); + + exec(commandObjects.xgroupCreate(key, group, initialId, true)); + + StreamEntryID messageId = exec(commandObjects.xadd(key, StreamEntryID.NEW_ENTRY, Collections.singletonMap("field", "value2"))); + + // Consumer1 reads the message to make it pending + Map stream = Collections.singletonMap(key, StreamEntryID.XREADGROUP_UNDELIVERED_ENTRY); + List>> readEntries = exec( + commandObjects.xreadGroup(group, consumer1, new XReadGroupParams().count(1), stream)); + + assertThat(readEntries, hasSize(1)); + assertThat(readEntries.get(0).getKey(), equalTo(key)); + assertThat(readEntries.get(0).getValue(), hasSize(1)); + assertThat(readEntries.get(0).getValue().get(0).getID(), equalTo(messageId)); + + Thread.sleep(200); // Wait a bit + + byte[] bMessageId = messageId.toString().getBytes(); + + // Claim the message for consumer2 + List claimedMessagesBytes = exec( + commandObjects.xclaim(key.getBytes(), group.getBytes(), consumer2.getBytes(), 1, new XClaimParams(), bMessageId)); + assertThat(claimedMessagesBytes, hasSize(1)); + // Good luck with asserting the content of this! + } + + @Test + public void testXClaimJustId() throws InterruptedException { + String key = "testStream"; + String group = "testGroup"; + String consumer1 = "consumer1"; + String consumer2 = "consumer2"; + + StreamEntryID initialId = new StreamEntryID(); + + exec(commandObjects.xgroupCreate(key, group, initialId, true)); + + StreamEntryID messageId = exec(commandObjects.xadd(key, StreamEntryID.NEW_ENTRY, Collections.singletonMap("field", "value2"))); + + // Consumer1 reads the message to make it pending + Map stream = Collections.singletonMap(key, StreamEntryID.XREADGROUP_UNDELIVERED_ENTRY); + List>> readEntries = exec( + commandObjects.xreadGroup(group, consumer1, new XReadGroupParams().count(1), stream)); + + assertThat(readEntries, hasSize(1)); + assertThat(readEntries.get(0).getKey(), equalTo(key)); + assertThat(readEntries.get(0).getValue(), hasSize(1)); + assertThat(readEntries.get(0).getValue().get(0).getID(), equalTo(messageId)); + + Thread.sleep(200); // Wait a bit + + // Claim the message for consumer2 with String parameters + List claimedMessagesString = exec( + commandObjects.xclaimJustId(key, group, consumer2, 1, new XClaimParams(), messageId)); + assertThat(claimedMessagesString, hasSize(1)); + assertThat(claimedMessagesString.get(0), equalTo(messageId)); + } + + @Test + public void testXClaimJustIdBinary() throws InterruptedException { + String key = "testStream"; + String group = "testGroup"; + String consumer1 = "consumer1"; + String consumer2 = "consumer2"; + + StreamEntryID initialId = new StreamEntryID(); + + exec(commandObjects.xgroupCreate(key, group, initialId, true)); + + StreamEntryID messageId = exec(commandObjects.xadd(key, StreamEntryID.NEW_ENTRY, Collections.singletonMap("field", "value2"))); + + // Consumer1 reads the message to make it pending + Map stream = Collections.singletonMap(key, StreamEntryID.XREADGROUP_UNDELIVERED_ENTRY); + List>> readEntries = exec( + commandObjects.xreadGroup(group, consumer1, new XReadGroupParams().count(1), stream)); + + assertThat(readEntries, hasSize(1)); + assertThat(readEntries.get(0).getKey(), equalTo(key)); + assertThat(readEntries.get(0).getValue(), hasSize(1)); + assertThat(readEntries.get(0).getValue().get(0).getID(), equalTo(messageId)); + + Thread.sleep(200); // Wait a bit + + byte[] bMessageId = messageId.toString().getBytes(); + + // Claim the message for consumer2 with byte[] parameters + List claimedMessagesBytes = exec( + commandObjects.xclaimJustId(key.getBytes(), group.getBytes(), consumer2.getBytes(), 1, new XClaimParams(), bMessageId)); + assertThat(claimedMessagesBytes, hasSize(1)); + // Good luck with asserting the content of this! + } + + @Test + public void testXAutoClaim() throws InterruptedException { + String streamKey = "testStream"; + String group = "testGroup"; + String consumer1 = "consumer1"; + String consumer2 = "consumer2"; + + exec(commandObjects.xgroupCreate(streamKey, group, new StreamEntryID(), true)); + + Map messageBody = Collections.singletonMap("field", "value"); + StreamEntryID initialEntryId = exec(commandObjects.xadd(streamKey, StreamEntryID.NEW_ENTRY, messageBody)); + + Map stream = Collections.singletonMap(streamKey, StreamEntryID.XREADGROUP_UNDELIVERED_ENTRY); + exec(commandObjects.xreadGroup(group, consumer1, new XReadGroupParams().count(1), stream)); + + Thread.sleep(200); // Wait a bit + + StreamEntryID startId = new StreamEntryID(initialEntryId.getTime() - 1, initialEntryId.getSequence()); + XAutoClaimParams params = new XAutoClaimParams().count(1); + + // Auto claim message for consumer2 + Map.Entry> autoClaimResult = exec( + commandObjects.xautoclaim(streamKey, group, consumer2, 1, startId, params)); + + assertThat(autoClaimResult.getValue(), hasSize(1)); + assertThat(autoClaimResult.getValue().get(0).getFields(), equalTo(messageBody)); + } + + @Test + public void testXAutoClaimBinary() throws InterruptedException { + byte[] streamKey = "testStream".getBytes(); + byte[] group = "testGroup".getBytes(); + byte[] consumer1 = "consumer1".getBytes(); + byte[] consumer2 = "consumer2".getBytes(); + + exec(commandObjects.xgroupCreate(streamKey, group, new StreamEntryID().toString().getBytes(), true)); + + Map messageBody = Collections.singletonMap("field".getBytes(), "value".getBytes()); + byte[] initialEntryId = exec(commandObjects.xadd(streamKey, new XAddParams(), messageBody)); + + Map.Entry entry = new AbstractMap.SimpleEntry<>(streamKey, StreamEntryID.XREADGROUP_UNDELIVERED_ENTRY.toString().getBytes()); + exec(commandObjects.xreadGroup(group, consumer1, new XReadGroupParams().count(1), entry)); + + Thread.sleep(200); // Wait a bit + + StreamEntryID initialStreamEntryID = new StreamEntryID(new String(initialEntryId)); + byte[] startId = new StreamEntryID(initialStreamEntryID.getTime() - 1, 0).toString().getBytes(); + XAutoClaimParams params = new XAutoClaimParams().count(1); + + // Auto claim message for consumer2 in binary + List autoClaimResultBinary = exec(commandObjects.xautoclaim(streamKey, group, consumer2, 1, startId, params)); + assertThat(autoClaimResultBinary, not(empty())); + } + + @Test + public void testXAutoClaimJustId() throws InterruptedException { + String streamKey = "testStream"; + String group = "testGroup"; + String consumer1 = "consumer1"; + String consumer2 = "consumer2"; + + exec(commandObjects.xgroupCreate(streamKey, group, new StreamEntryID(), true)); + + Map messageBody = Collections.singletonMap("fieldSingle", "valueSingle"); + StreamEntryID initialEntryId = exec(commandObjects.xadd(streamKey, StreamEntryID.NEW_ENTRY, messageBody)); + + Map stream = Collections.singletonMap(streamKey, StreamEntryID.XREADGROUP_UNDELIVERED_ENTRY); + exec(commandObjects.xreadGroup(group, consumer1, new XReadGroupParams().count(1), stream)); + + Thread.sleep(200); // Wait a bit + + StreamEntryID startId = new StreamEntryID(initialEntryId.getTime() - 1, initialEntryId.getSequence()); + XAutoClaimParams params = new XAutoClaimParams().count(1); + + Map.Entry> autoClaimResult = exec( + commandObjects.xautoclaimJustId(streamKey, group, consumer2, 1, startId, params)); + + assertThat(autoClaimResult.getValue(), hasSize(1)); + assertThat(autoClaimResult.getValue().get(0), equalTo(initialEntryId)); + } + + @Test + public void testXAutoClaimJustIdBinary() throws InterruptedException { + byte[] streamKey = "testStream".getBytes(); + byte[] group = "testGroup".getBytes(); + byte[] consumer1 = "consumer1".getBytes(); + byte[] consumer2 = "consumer2".getBytes(); + + exec(commandObjects.xgroupCreate(streamKey, group, new StreamEntryID().toString().getBytes(), true)); + + Map messageBody = Collections.singletonMap("fieldBinary".getBytes(), "valueBinary".getBytes()); + byte[] initialEntryId = exec(commandObjects.xadd(streamKey, new XAddParams(), messageBody)); + + Map.Entry stream = new AbstractMap.SimpleEntry<>(streamKey, StreamEntryID.XREADGROUP_UNDELIVERED_ENTRY.toString().getBytes()); + exec(commandObjects.xreadGroup(group, consumer1, new XReadGroupParams().count(1), stream)); + + Thread.sleep(200); // Wait a bit + + StreamEntryID initialStreamEntryID = new StreamEntryID(new String(initialEntryId)); + byte[] startId = new StreamEntryID(initialStreamEntryID.getTime() - 1, 0).toString().getBytes(); + XAutoClaimParams params = new XAutoClaimParams().count(1); + + List autoClaimResultBinary = exec( + commandObjects.xautoclaimJustId(streamKey, group, consumer2, 1, startId, params)); + assertThat(autoClaimResultBinary, not(empty())); + } + + @Test + public void testXInfoStream() { + String streamKey = "testStreamInfo"; + + Map messageBody = Collections.singletonMap("fieldInfo", "valueInfo"); + + exec(commandObjects.xadd(streamKey, StreamEntryID.NEW_ENTRY, messageBody)); + + StreamInfo streamInfo = exec(commandObjects.xinfoStream(streamKey)); + + assertThat(streamInfo, notNullValue()); + assertThat(streamInfo.getLength(), equalTo(1L)); + assertThat(streamInfo.getFirstEntry().getFields(), equalTo(messageBody)); + + Object streamInfoBinary = exec(commandObjects.xinfoStream(streamKey.getBytes())); + assertThat(streamInfoBinary, notNullValue()); + } + + @Test + public void testXInfoStreamFull() { + String streamKey = "testStreamFullInfo"; + + Map messageBody = Collections.singletonMap("fieldFull", "valueFull"); + + exec(commandObjects.xadd(streamKey, StreamEntryID.NEW_ENTRY, messageBody)); + + StreamFullInfo streamFullInfo = exec(commandObjects.xinfoStreamFull(streamKey)); + + assertThat(streamFullInfo, notNullValue()); + assertThat(streamFullInfo.getEntries(), not(empty())); + assertThat(streamFullInfo.getEntries().get(0).getFields(), equalTo(messageBody)); + + StreamFullInfo streamFullInfoWithCount = exec(commandObjects.xinfoStreamFull(streamKey, 1)); + assertThat(streamFullInfoWithCount, notNullValue()); + assertThat(streamFullInfoWithCount.getEntries(), hasSize(1)); + + Object streamInfoBinaryFull = exec(commandObjects.xinfoStreamFull(streamKey.getBytes())); + assertThat(streamInfoBinaryFull, notNullValue()); + + Object streamInfoBinaryFullWithCount = exec(commandObjects.xinfoStreamFull(streamKey.getBytes(), 1)); + assertThat(streamInfoBinaryFullWithCount, notNullValue()); + } + + @Test + @Deprecated + public void testXInfoConsumersWithActiveConsumers() { + String streamKey = "testStreamWithConsumers"; + String group = "testConsumerGroup"; + String consumer1 = "consumer1"; + String consumer2 = "consumer2"; + + Map messageBody1 = Collections.singletonMap("field1", "value1"); + Map messageBody2 = Collections.singletonMap("field2", "value2"); + + exec(commandObjects.xadd(streamKey, StreamEntryID.NEW_ENTRY, messageBody1)); + exec(commandObjects.xadd(streamKey, StreamEntryID.NEW_ENTRY, messageBody2)); + + exec(commandObjects.xgroupCreate(streamKey, group, new StreamEntryID(), true)); + + XReadGroupParams xReadGroupParams = new XReadGroupParams().count(1); + Map stream = Collections.singletonMap(streamKey, StreamEntryID.XREADGROUP_UNDELIVERED_ENTRY); + exec(commandObjects.xreadGroup(group, consumer1, xReadGroupParams, stream)); + exec(commandObjects.xreadGroup(group, consumer2, xReadGroupParams, stream)); + + List consumersInfoList = exec(commandObjects.xinfoConsumers(streamKey, group)); + assertThat(consumersInfoList, notNullValue()); + assertThat(consumersInfoList, hasSize(2)); + + Optional consumersInfo1 = consumersInfoList.stream().filter(c -> c.getName().equals(consumer1)).findFirst(); + Optional consumersInfo2 = consumersInfoList.stream().filter(c -> c.getName().equals(consumer2)).findFirst(); + + assertThat(consumersInfo1.isPresent(), equalTo(true)); + assertThat(consumersInfo1.get().getPending(), equalTo(1L)); + + assertThat(consumersInfo2.isPresent(), equalTo(true)); + assertThat(consumersInfo2.get().getPending(), equalTo(1L)); + + List consumerInfoList = exec(commandObjects.xinfoConsumers2(streamKey, group)); + assertThat(consumerInfoList, notNullValue()); + assertThat(consumerInfoList, hasSize(2)); + + Optional consumerInfo1 = consumerInfoList.stream().filter(c -> c.getName().equals(consumer1)).findFirst(); + Optional consumerInfo2 = consumerInfoList.stream().filter(c -> c.getName().equals(consumer2)).findFirst(); + + assertThat(consumerInfo1.isPresent(), equalTo(true)); + assertThat(consumerInfo1.get().getPending(), equalTo(1L)); + + assertThat(consumerInfo2.isPresent(), equalTo(true)); + assertThat(consumerInfo2.get().getPending(), equalTo(1L)); + + List consumersInfoBinary = exec(commandObjects.xinfoConsumers(streamKey.getBytes(), group.getBytes())); + assertThat(consumersInfoBinary, notNullValue()); + } + + @Test + public void testXRead() { + String streamKey1 = "testStream1"; + String streamKey2 = "testStream2"; + + Map messageBody1 = Collections.singletonMap("field1", "value1"); + Map messageBody2 = Collections.singletonMap("field2", "value2"); + + StreamEntryID messageId1 = exec(commandObjects.xadd(streamKey1, StreamEntryID.NEW_ENTRY, messageBody1)); + StreamEntryID messageId2 = exec(commandObjects.xadd(streamKey2, StreamEntryID.NEW_ENTRY, messageBody2)); + + XReadParams params = XReadParams.xReadParams().count(1).block(1000); + Map streams = new HashMap<>(); + streams.put(streamKey1, new StreamEntryID()); + streams.put(streamKey2, new StreamEntryID()); + + List>> xread = exec(commandObjects.xread(params, streams)); + + assertThat(xread, not(empty())); + assertThat(xread.size(), equalTo(2)); + assertThat(xread.get(0).getKey(), equalTo(streamKey1)); + assertThat(xread.get(1).getKey(), equalTo(streamKey2)); + assertThat(xread.get(0).getValue().get(0).getID(), equalTo(messageId1)); + assertThat(xread.get(1).getValue().get(0).getID(), equalTo(messageId2)); + assertThat(xread.get(0).getValue().get(0).getFields(), equalTo(messageBody1)); + assertThat(xread.get(1).getValue().get(0).getFields(), equalTo(messageBody2)); + + byte[] streamKey1Binary = streamKey1.getBytes(); + byte[] streamKey2Binary = streamKey2.getBytes(); + Map.Entry stream1 = new AbstractMap.SimpleEntry<>(streamKey1Binary, new StreamEntryID().toString().getBytes()); + Map.Entry stream2 = new AbstractMap.SimpleEntry<>(streamKey2Binary, new StreamEntryID().toString().getBytes()); + + List xreadBinary = exec(commandObjects.xread(params, stream1, stream2)); + assertThat(xreadBinary, not(empty())); + } + + @Test + public void testXReadAsMap() { + String streamKey1 = "testStreamMap1"; + String streamKey2 = "testStreamMap2"; + + Map messageBody1 = Collections.singletonMap("fieldMap1", "valueMap1"); + Map messageBody2 = Collections.singletonMap("fieldMap2", "valueMap2"); + + exec(commandObjects.xadd(streamKey1, StreamEntryID.NEW_ENTRY, messageBody1)); + exec(commandObjects.xadd(streamKey2, StreamEntryID.NEW_ENTRY, messageBody2)); + + XReadParams params = new XReadParams().count(1).block(1000); + + Map streams = new HashMap<>(); + streams.put(streamKey1, new StreamEntryID()); + streams.put(streamKey2, new StreamEntryID()); + + Map> xreadAsMap = exec(commandObjects.xreadAsMap(params, streams)); + assertThat(xreadAsMap, notNullValue()); + assertThat(xreadAsMap.keySet(), hasSize(2)); // Expecting keys for both streams + assertThat(xreadAsMap.get(streamKey1).get(0).getFields(), equalTo(messageBody1)); + assertThat(xreadAsMap.get(streamKey2).get(0).getFields(), equalTo(messageBody2)); + } + + @Test + public void testXReadGroupAsMap() { + String streamKey = "testStreamGroupMap"; + String group = "testGroupMap"; + String consumer1 = "testConsumerMap1"; + String consumer2 = "testConsumerMap2"; + + Map messageBody = Collections.singletonMap("fieldGroupMap", "valueGroupMap"); + + exec(commandObjects.xgroupCreate(streamKey, group, new StreamEntryID(), true)); + + StreamEntryID initialMessageId = exec(commandObjects.xadd(streamKey, StreamEntryID.NEW_ENTRY, messageBody)); + StreamEntryID secondMessageId = exec(commandObjects.xadd(streamKey, StreamEntryID.NEW_ENTRY, messageBody)); + + XReadGroupParams params = new XReadGroupParams().count(1); + + Map streams = new HashMap<>(); + streams.put(streamKey, StreamEntryID.XREADGROUP_UNDELIVERED_ENTRY); + + Map> xreadGroupConsumer1 = exec(commandObjects.xreadGroupAsMap(group, consumer1, params, streams)); + + assertThat(xreadGroupConsumer1, notNullValue()); + assertThat(xreadGroupConsumer1.keySet(), hasSize(1)); + assertThat(xreadGroupConsumer1.get(streamKey), not(empty())); + assertThat(xreadGroupConsumer1.get(streamKey).get(0).getID(), equalTo(initialMessageId)); + assertThat(xreadGroupConsumer1.get(streamKey).get(0).getFields(), equalTo(messageBody)); + + Map> xreadGroupConsumer2 = exec(commandObjects.xreadGroupAsMap(group, consumer2, params, streams)); + + assertThat(xreadGroupConsumer2, notNullValue()); + assertThat(xreadGroupConsumer2.keySet(), hasSize(1)); // Expecting keys for the stream + assertThat(xreadGroupConsumer2.get(streamKey), not(empty())); // Expecting at least one message + assertThat(xreadGroupConsumer2.get(streamKey).get(0).getID(), equalTo(secondMessageId)); + assertThat(xreadGroupConsumer2.get(streamKey).get(0).getFields(), equalTo(messageBody)); + } +} diff --git a/src/test/java/redis/clients/jedis/commands/commandobjects/CommandObjectsStringCommandsTest.java b/src/test/java/redis/clients/jedis/commands/commandobjects/CommandObjectsStringCommandsTest.java new file mode 100644 index 00000000000..9a35cd88e4e --- /dev/null +++ b/src/test/java/redis/clients/jedis/commands/commandobjects/CommandObjectsStringCommandsTest.java @@ -0,0 +1,593 @@ +package redis.clients.jedis.commands.commandobjects; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.closeTo; +import static org.hamcrest.Matchers.contains; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.greaterThan; +import static org.hamcrest.Matchers.hasSize; +import static org.hamcrest.Matchers.nullValue; + +import java.util.List; + +import org.junit.Test; +import redis.clients.jedis.RedisProtocol; +import redis.clients.jedis.params.GetExParams; +import redis.clients.jedis.params.LCSParams; +import redis.clients.jedis.params.SetParams; +import redis.clients.jedis.resps.LCSMatchResult; + +/** + * Tests related to String commands. + */ +public class CommandObjectsStringCommandsTest extends CommandObjectsStandaloneTestBase { + + public CommandObjectsStringCommandsTest(RedisProtocol protocol) { + super(protocol); + } + + @Test + public void testAppend() { + String key = "testKey"; + String value = "testValue"; + + String initialGet = exec(commandObjects.get(key)); + assertThat(initialGet, nullValue()); + + Long append = exec(commandObjects.append(key, value)); + assertThat(append, equalTo((long) value.length())); + + String getAfterAppend = exec(commandObjects.get(key)); + assertThat(getAfterAppend, equalTo(value)); + + Long secondAppend = exec(commandObjects.append(key, value)); + assertThat(secondAppend, equalTo((long) value.length() * 2)); + + String getAfterSecondAppend = exec(commandObjects.get(key)); + assertThat(getAfterSecondAppend, equalTo(value + value)); + } + + @Test + public void testAppendBinary() { + byte[] key = "testKeyBytes".getBytes(); + byte[] value = "testValueBytes".getBytes(); + + byte[] initialGet = exec(commandObjects.get(key)); + assertThat(initialGet, nullValue()); + + Long append = exec(commandObjects.append(key, value)); + assertThat(append, equalTo((long) value.length)); + + byte[] getAfterAppend = exec(commandObjects.get(key)); + assertThat(getAfterAppend, equalTo(value)); + + Long secondAppend = exec(commandObjects.append(key, value)); + assertThat(secondAppend, equalTo((long) value.length * 2)); + + byte[] getAfterSecondAppend = exec(commandObjects.get(key)); + + byte[] expected = new byte[value.length + value.length]; + System.arraycopy(value, 0, expected, 0, value.length); + System.arraycopy(value, 0, expected, value.length, value.length); + + assertThat(getAfterSecondAppend, equalTo(expected)); + } + + @Test + public void testDecrementOperations() { + String key = "testDecr"; + + exec(commandObjects.set(key, String.valueOf(10L))); + + String initialGet = exec(commandObjects.get(key)); + assertThat(initialGet, equalTo("10")); + + Long decr = exec(commandObjects.decr(key)); + assertThat(decr, equalTo(9L)); + + String getAfterDecr = exec(commandObjects.get(key)); + assertThat(getAfterDecr, equalTo("9")); + + Long decrBy = exec(commandObjects.decrBy(key, 2L)); + assertThat(decrBy, equalTo(7L)); + + String getAfterDecrBy = exec(commandObjects.get(key)); + assertThat(getAfterDecrBy, equalTo("7")); + } + + @Test + public void testDecrementOperationsBinary() { + byte[] key = "testDecrBytes".getBytes(); + + exec(commandObjects.set(key, String.valueOf(10L).getBytes())); + + byte[] initialGet = exec(commandObjects.get(key)); + assertThat(initialGet, equalTo("10".getBytes())); + + Long decr = exec(commandObjects.decr(key)); + assertThat(decr, equalTo(9L)); + + byte[] getAfterDecr = exec(commandObjects.get(key)); + assertThat(getAfterDecr, equalTo("9".getBytes())); + + Long decrBy = exec(commandObjects.decrBy(key, 2L)); + assertThat(decrBy, equalTo(7L)); + + byte[] getAfterDecrBy = exec(commandObjects.get(key)); + assertThat(getAfterDecrBy, equalTo("7".getBytes())); + } + + @Test + public void testGetOperations() { + String key = "testGet"; + String value = "value"; + + exec(commandObjects.set(key, value)); + + String initialGet = exec(commandObjects.get(key)); + assertThat(initialGet, equalTo(value)); + + String getDel = exec(commandObjects.getDel(key)); + assertThat(getDel, equalTo(value)); + + String getAfterGetDel = exec(commandObjects.get(key)); + assertThat(getAfterGetDel, nullValue()); + + // set again + exec(commandObjects.set(key, value)); + + Long initialTtl = exec(commandObjects.ttl(key)); + assertThat(initialTtl, equalTo(-1L)); + + GetExParams getExParams = GetExParams.getExParams().ex(10); + String getEx = exec(commandObjects.getEx(key, getExParams)); + assertThat(getEx, equalTo(value)); + + Long ttlAfterGetEx = exec(commandObjects.ttl(key)); + assertThat(ttlAfterGetEx, greaterThan(0L)); + } + + @Test + public void testGetOperationsBinary() { + byte[] key = "testGetBytes".getBytes(); + byte[] value = "value".getBytes(); + + exec(commandObjects.set(key, value)); + + byte[] initialGet = exec(commandObjects.get(key)); + assertThat(initialGet, equalTo(value)); + + byte[] getDel = exec(commandObjects.getDel(key)); + assertThat(getDel, equalTo(value)); + + byte[] getAfterGetDel = exec(commandObjects.get(key)); + assertThat(getAfterGetDel, nullValue()); + + // set again + exec(commandObjects.set(key, value)); + + Long initialTtl = exec(commandObjects.ttl(key)); + assertThat(initialTtl, equalTo(-1L)); + + GetExParams getExParams = GetExParams.getExParams().ex(10); + byte[] getEx = exec(commandObjects.getEx(key, getExParams)); + assertThat(getEx, equalTo(value)); + + Long ttlAfterGetEx = exec(commandObjects.ttl(key)); + assertThat(ttlAfterGetEx, greaterThan(0L)); + } + + @Test + @Deprecated + public void testGetSet() { + String key = "testGetSet"; + String initialValue = "initialValue"; + String newValue = "newValue"; + + exec(commandObjects.set(key, initialValue)); + + String initialGet = exec(commandObjects.get(key)); + assertThat(initialGet, equalTo(initialValue)); + + String getSet = exec(commandObjects.getSet(key, newValue)); + assertThat(getSet, equalTo(initialValue)); + + String getAfterGetSet = exec(commandObjects.get(key)); + assertThat(getAfterGetSet, equalTo(newValue)); + } + + @Test + @Deprecated + public void testGetSetBinary() { + byte[] key = "testGetSetBytes".getBytes(); + byte[] initialValue = "initialValue".getBytes(); + byte[] newValue = "newValue".getBytes(); + + exec(commandObjects.set(key, initialValue)); + + byte[] initialGet = exec(commandObjects.get(key)); + assertThat(initialGet, equalTo(initialValue)); + + byte[] getSet = exec(commandObjects.getSet(key, newValue)); + assertThat(getSet, equalTo(initialValue)); + + byte[] getAfterGetSet = exec(commandObjects.get(key)); + assertThat(getAfterGetSet, equalTo(newValue)); + } + + @Test + public void testSetRangeAndGetRange() { + String key = "testRange"; + String initial = "Hello World"; + String replacement = "Everyone"; + long replacementOffset = 6L; + + exec(commandObjects.set(key, initial)); + + Long setRange = exec(commandObjects.setrange(key, replacementOffset, replacement)); + assertThat(setRange, equalTo(14L)); // Length after replacement + + String getRange = exec(commandObjects.getrange(key, 0, -1)); + assertThat(getRange, equalTo("Hello Everyone")); + } + + @Test + public void testSetRangeAndGetRangeBinary() { + byte[] key = "testRangeBytes".getBytes(); + byte[] initialValue = "Hello World".getBytes(); + byte[] replacement = "Everyone".getBytes(); + long replacementOffset = 6L; + + exec(commandObjects.set(key, initialValue)); + + Long setRange = exec(commandObjects.setrange(key, replacementOffset, replacement)); + assertThat(setRange, equalTo(14L)); // Length after replacement + + byte[] getRange = exec(commandObjects.getrange(key, 0, -1)); + assertThat(getRange, equalTo("Hello Everyone".getBytes())); + } + + @Test + public void testIncrementOperations() { + String key = "testIncr"; + + exec(commandObjects.set(key, "0")); + + Long incr = exec(commandObjects.incr(key)); + assertThat(incr, equalTo(1L)); + + String getAfterIncr = exec(commandObjects.get(key)); + assertThat(getAfterIncr, equalTo("1")); + + Long incrBy = exec(commandObjects.incrBy(key, 5L)); + assertThat(incrBy, equalTo(6L)); + + String getAfterIncrBy = exec(commandObjects.get(key)); + assertThat(getAfterIncrBy, equalTo("6")); + + Double incrByFloat = exec(commandObjects.incrByFloat(key, 2.5)); + assertThat(incrByFloat, closeTo(8.5, 0.001)); + + String getAfterIncrByFloat = exec(commandObjects.get(key)); + assertThat(getAfterIncrByFloat, equalTo("8.5")); + } + + @Test + public void testIncrementOperationsBinary() { + byte[] key = "testIncrBytes".getBytes(); + + exec(commandObjects.set(key, "0".getBytes())); + + Long incr = exec(commandObjects.incr(key)); + assertThat(incr, equalTo(1L)); + + byte[] getAfterIncr = exec(commandObjects.get(key)); + assertThat(getAfterIncr, equalTo("1".getBytes())); + + Long incrBy = exec(commandObjects.incrBy(key, 5L)); + assertThat(incrBy, equalTo(6L)); + + byte[] getAfterIncrBy = exec(commandObjects.get(key)); + assertThat(getAfterIncrBy, equalTo("6".getBytes())); + + Double incrByFloat = exec(commandObjects.incrByFloat(key, 2.5)); + assertThat(incrByFloat, closeTo(8.5, 0.001)); + + byte[] getAfterIncrByFloat = exec(commandObjects.get(key)); + assertThat(getAfterIncrByFloat, equalTo("8.5".getBytes())); + } + + @Test + public void testLcs() { + String keyA = "keyA"; + String keyB = "keyB"; + + // "abcdfg" is the common substring + String valueA = "abcdfgh"; + String valueB = "abcdefg"; + + exec(commandObjects.set(keyA, valueA)); + exec(commandObjects.set(keyB, valueB)); + + LCSMatchResult lcsLen = exec(commandObjects.lcs(keyA, keyB, new LCSParams().len())); + assertThat(lcsLen.getLen(), equalTo(6L)); + assertThat(lcsLen.getMatchString(), nullValue()); + + LCSMatchResult lcs = exec(commandObjects.lcs(keyA, keyB, new LCSParams())); + assertThat(lcs.getLen(), equalTo(0L)); + assertThat(lcs.getMatchString(), equalTo("abcdfg")); + + LCSMatchResult lcsMatches = exec(commandObjects.lcs(keyA, keyB, new LCSParams().idx().withMatchLen())); + assertThat(lcsMatches.getLen(), equalTo(6L)); + assertThat(lcsMatches.getMatchString(), nullValue()); + assertThat(lcsMatches.getMatches(), hasSize(2)); + + LCSMatchResult.MatchedPosition match1 = lcsMatches.getMatches().get(0); + assertThat(match1.getMatchLen(), equalTo(2L)); + assertThat(match1.getA().getStart(), equalTo(4L)); + assertThat(match1.getA().getEnd(), equalTo(5L)); + assertThat(match1.getB().getStart(), equalTo(5L)); + assertThat(match1.getB().getEnd(), equalTo(6L)); + + LCSMatchResult.MatchedPosition match2 = lcsMatches.getMatches().get(1); + assertThat(match2.getMatchLen(), equalTo(4L)); + assertThat(match2.getA().getStart(), equalTo(0L)); + assertThat(match2.getA().getEnd(), equalTo(3L)); + assertThat(match2.getB().getStart(), equalTo(0L)); + assertThat(match2.getB().getEnd(), equalTo(3L)); + } + + @Test + public void testLcsBinary() { + byte[] keyA = "keyA".getBytes(); + byte[] keyB = "keyB".getBytes(); + + // "abcdfg" is the common substring + String valueA = "abcdfgh"; + String valueB = "abcdefg"; + + exec(commandObjects.set(keyA, valueA.getBytes())); + exec(commandObjects.set(keyB, valueB.getBytes())); + + LCSMatchResult lcsLen = exec(commandObjects.lcs(keyA, keyB, new LCSParams().len())); + assertThat(lcsLen.getLen(), equalTo(6L)); + assertThat(lcsLen.getMatchString(), nullValue()); + + LCSMatchResult lcs = exec(commandObjects.lcs(keyA, keyB, new LCSParams())); + assertThat(lcs.getLen(), equalTo(0L)); + assertThat(lcs.getMatchString(), equalTo("abcdfg")); + + LCSMatchResult lcsMatches = exec(commandObjects.lcs(keyA, keyB, new LCSParams().idx().withMatchLen())); + assertThat(lcsMatches.getLen(), equalTo(6L)); + assertThat(lcsMatches.getMatchString(), nullValue()); + assertThat(lcsMatches.getMatches(), hasSize(2)); + + LCSMatchResult.MatchedPosition match1 = lcsMatches.getMatches().get(0); + assertThat(match1.getMatchLen(), equalTo(2L)); + assertThat(match1.getA().getStart(), equalTo(4L)); + assertThat(match1.getA().getEnd(), equalTo(5L)); + assertThat(match1.getB().getStart(), equalTo(5L)); + assertThat(match1.getB().getEnd(), equalTo(6L)); + + LCSMatchResult.MatchedPosition match2 = lcsMatches.getMatches().get(1); + assertThat(match2.getMatchLen(), equalTo(4L)); + assertThat(match2.getA().getStart(), equalTo(0L)); + assertThat(match2.getA().getEnd(), equalTo(3L)); + assertThat(match2.getB().getStart(), equalTo(0L)); + assertThat(match2.getB().getEnd(), equalTo(3L)); + } + + @Test + public void testMgetMsetAndMsetnx() { + String key1 = "key1"; + String key2 = "key2"; + + String mset = exec(commandObjects.mset(key1, "value1", key2, "value2")); + assertThat(mset, equalTo("OK")); + + List mget = exec(commandObjects.mget(key1, key2)); + assertThat(mget, contains("value1", "value2")); + + Long msetNx = exec(commandObjects.msetnx(key1, "new1", key2, "new2")); + assertThat(msetNx, equalTo(0L)); + + List mgetAfterMsetNx = exec(commandObjects.mget(key1, key2)); + assertThat(mgetAfterMsetNx, contains("value1", "value2")); + + Long del = exec(commandObjects.del(key1, key2)); + assertThat(del, equalTo(2L)); + + List mgetAfterDel = exec(commandObjects.mget(key1, key2)); + assertThat(mgetAfterDel, contains(nullValue(), nullValue())); + + Long msetNxAfterDel = exec(commandObjects.msetnx(key1, "new1", key2, "new2")); + assertThat(msetNxAfterDel, equalTo(1L)); + + List mgetAfterMsetNxAfterDel = exec(commandObjects.mget(key1, key2)); + assertThat(mgetAfterMsetNxAfterDel, contains("new1", "new2")); + } + + @Test + public void testMgetMsetAndMsetnxBinary() { + byte[] key1 = "key1Bytes".getBytes(); + byte[] key2 = "key2Bytes".getBytes(); + + String mset = exec(commandObjects.mset(key1, "value1".getBytes(), key2, "value2".getBytes())); + assertThat(mset, equalTo("OK")); + + List mget = exec(commandObjects.mget(key1, key2)); + assertThat(mget, contains("value1".getBytes(), "value2".getBytes())); + + Long msetNx = exec(commandObjects.msetnx(key1, "new1".getBytes(), key2, "new2".getBytes())); + assertThat(msetNx, equalTo(0L)); + + List mgetAfterMsetNx = exec(commandObjects.mget(key1, key2)); + assertThat(mgetAfterMsetNx, contains("value1".getBytes(), "value2".getBytes())); + + Long del = exec(commandObjects.del(key1, key2)); + assertThat(del, equalTo(2L)); + + List mgetAfterDel = exec(commandObjects.mget(key1, key2)); + assertThat(mgetAfterDel, contains(nullValue(), nullValue())); + + Long msetNxAfterDel = exec(commandObjects.msetnx(key1, "new1".getBytes(), key2, "new2".getBytes())); + assertThat(msetNxAfterDel, equalTo(1L)); + + List mgetAfterMsetNxAfterDel = exec(commandObjects.mget(key1, key2)); + assertThat(mgetAfterMsetNxAfterDel, contains("new1".getBytes(), "new2".getBytes())); + } + + @Test + public void testPsetexPttl() { + String key = "tempKey"; + long milliseconds = 1000L; + + String psetEx = exec(commandObjects.psetex(key, milliseconds, "tempValue")); + assertThat(psetEx, equalTo("OK")); + + Long pttl = exec(commandObjects.pttl(key)); + assertThat(pttl, greaterThan(0L)); + } + + @Test + public void testPsetexPttlBinary() { + byte[] key = "tempKey".getBytes(); + long milliseconds = 1000L; + + String psetEx = exec(commandObjects.psetex(key, milliseconds, "tempValue".getBytes())); + assertThat(psetEx, equalTo("OK")); + + Long pttl = exec(commandObjects.pttl(key)); + assertThat(pttl, greaterThan(0L)); + } + + @Test + public void testSetAndSetGet() { + String key = "myKey"; + + String set = exec(commandObjects.set(key, "firstValue")); + assertThat(set, equalTo("OK")); + + String initialGet = exec(commandObjects.get(key)); + assertThat(initialGet, equalTo("firstValue")); + + SetParams setParams = new SetParams().ex(10); + String setWithParams = exec(commandObjects.set(key, "secondValue", setParams)); + assertThat(setWithParams, equalTo("OK")); + + String getAfterSetWithParams = exec(commandObjects.get(key)); + assertThat(getAfterSetWithParams, equalTo("secondValue")); + + String setGet = exec(commandObjects.setGet(key, "thirdValue")); + assertThat(setGet, equalTo("secondValue")); + + String getAfterSetGet = exec(commandObjects.get(key)); + assertThat(getAfterSetGet, equalTo("thirdValue")); + + String setGetWithParams = exec(commandObjects.setGet(key, "finalValue", setParams)); + assertThat(setGetWithParams, equalTo("thirdValue")); + + String finalGet = exec(commandObjects.get(key)); + assertThat(finalGet, equalTo("finalValue")); + } + + @Test + public void testSetAndSetGetBinary() { + byte[] key = "myKeyBytes".getBytes(); + + String set = exec(commandObjects.set(key, "firstValue".getBytes())); + assertThat(set, equalTo("OK")); + + byte[] getAfterSet = exec(commandObjects.get(key)); + assertThat(getAfterSet, equalTo("firstValue".getBytes())); + + SetParams setParams = new SetParams().ex(10); + String setWithParams = exec(commandObjects.set(key, "secondValue".getBytes(), setParams)); + assertThat(setWithParams, equalTo("OK")); + + byte[] getAfterSetWithParams = exec(commandObjects.get(key)); + assertThat(getAfterSetWithParams, equalTo("secondValue".getBytes())); + + byte[] setGet = exec(commandObjects.setGet(key, "thirdValue".getBytes())); + assertThat(setGet, equalTo("secondValue".getBytes())); + + byte[] getAfterSetGet = exec(commandObjects.get(key)); + assertThat(getAfterSetGet, equalTo("thirdValue".getBytes())); + + byte[] setGetWithParams = exec(commandObjects.setGet(key, "finalValue".getBytes(), setParams)); + assertThat(setGetWithParams, equalTo("thirdValue".getBytes())); + + byte[] getAfterSetGetWithParams = exec(commandObjects.get(key)); + assertThat(getAfterSetGetWithParams, equalTo("finalValue".getBytes())); + } + + @Test + public void testSetnxAndSetexWithGets() { + String key = "uniqueKey"; + + Long setNx = exec(commandObjects.setnx(key, "helloWorld")); + assertThat(setNx, equalTo(1L)); + + String getAfterSetNx = exec(commandObjects.get(key)); + assertThat(getAfterSetNx, equalTo("helloWorld")); + + String setEx = exec(commandObjects.setex(key, 10L, "newValue")); + assertThat(setEx, equalTo("OK")); + + String getAfterSetEx = exec(commandObjects.get(key)); + assertThat(getAfterSetEx, equalTo("newValue")); + + Long setNxAgain = exec(commandObjects.setnx(key, "anotherNewValue")); + assertThat(setNxAgain, equalTo(0L)); + + String getAfterSetNxAgain = exec(commandObjects.get(key)); + assertThat(getAfterSetNxAgain, equalTo("newValue")); + } + + @Test + public void testSetnxAndSetexWithGetsBinary() { + byte[] key = "uniqueKeyBytes".getBytes(); + + Long setNx = exec(commandObjects.setnx(key, "helloWorld".getBytes())); + assertThat(setNx, equalTo(1L)); + + byte[] getAfterSetNx = exec(commandObjects.get(key)); + assertThat(getAfterSetNx, equalTo("helloWorld".getBytes())); + + String setEx = exec(commandObjects.setex(key, 10L, "newValue".getBytes())); + assertThat(setEx, equalTo("OK")); + + byte[] getAfterSetEx = exec(commandObjects.get(key)); + assertThat(getAfterSetEx, equalTo("newValue".getBytes())); + + Long setNxAgain = exec(commandObjects.setnx(key, "anotherNewValueBytes".getBytes())); + assertThat(setNxAgain, equalTo(0L)); + + byte[] getAfterSetNxAgain = exec(commandObjects.get(key)); + assertThat(getAfterSetNxAgain, equalTo("newValue".getBytes())); + } + + @Test + public void testSubstrAndStrlen() { + String key = "testKey"; + String value = "HelloWorld"; + + int start = 1; + int end = 5; // end is inclusive + String fragment = "elloW"; + + exec(commandObjects.set(key, value)); + + String substr = exec(commandObjects.substr(key, start, end)); + assertThat(substr, equalTo(fragment)); + + byte[] substrBinary = exec(commandObjects.substr(key.getBytes(), start, end)); + assertThat(substrBinary, equalTo(fragment.getBytes())); + + Long strlen = exec(commandObjects.strlen(key)); + assertThat(strlen, equalTo((long) value.length())); + + Long strlenBinary = exec(commandObjects.strlen(key.getBytes())); + assertThat(strlenBinary, equalTo((long) value.length())); + } +} diff --git a/src/test/java/redis/clients/jedis/commands/commandobjects/CommandObjectsTDigestCommandsTest.java b/src/test/java/redis/clients/jedis/commands/commandobjects/CommandObjectsTDigestCommandsTest.java new file mode 100644 index 00000000000..f16bc91abb7 --- /dev/null +++ b/src/test/java/redis/clients/jedis/commands/commandobjects/CommandObjectsTDigestCommandsTest.java @@ -0,0 +1,255 @@ +package redis.clients.jedis.commands.commandobjects; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.closeTo; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.greaterThanOrEqualTo; +import static org.hamcrest.Matchers.hasEntry; +import static org.hamcrest.Matchers.hasKey; +import static org.hamcrest.Matchers.lessThanOrEqualTo; +import static org.hamcrest.Matchers.notANumber; +import static org.hamcrest.Matchers.notNullValue; + +import java.util.List; +import java.util.Map; + +import org.junit.Test; +import redis.clients.jedis.RedisProtocol; +import redis.clients.jedis.bloom.TDigestMergeParams; + +/** + * Tests related to T-Digest commands. + */ +public class CommandObjectsTDigestCommandsTest extends CommandObjectsModulesTestBase { + + public CommandObjectsTDigestCommandsTest(RedisProtocol protocol) { + super(protocol); + } + + @Test + public void testTDigestAddMinMax() { + String key = "testTDigest"; + + String create = exec(commandObjects.tdigestCreate(key)); + assertThat(create, equalTo("OK")); + + String add = exec(commandObjects.tdigestAdd(key, 1.0, 2.0, 3.0, 4.0, 5.0)); + assertThat(add, equalTo("OK")); + + Double minValue = exec(commandObjects.tdigestMin(key)); + assertThat(minValue, equalTo(1.0)); + + Double maxValue = exec(commandObjects.tdigestMax(key)); + assertThat(maxValue, equalTo(5.0)); + } + + @Test + public void testTDigestMerge() { + String destinationKey = "testTDigestMergeDest"; + String sourceKey1 = "testTDigestSource1"; + String sourceKey2 = "testTDigestSource2"; + + String create1 = exec(commandObjects.tdigestCreate(sourceKey1)); + assertThat(create1, equalTo("OK")); + + String create2 = exec(commandObjects.tdigestCreate(sourceKey2)); + assertThat(create2, equalTo("OK")); + + String add1 = exec(commandObjects.tdigestAdd(sourceKey1, 1.0, 2.0)); + assertThat(add1, equalTo("OK")); + + String add2 = exec(commandObjects.tdigestAdd(sourceKey2, 3.0, 4.0)); + assertThat(add2, equalTo("OK")); + + String merge = exec(commandObjects.tdigestMerge(destinationKey, sourceKey1, sourceKey2)); + assertThat(merge, equalTo("OK")); + + Double minAfterMerge = exec(commandObjects.tdigestMin(destinationKey)); + assertThat(minAfterMerge, equalTo(1.0)); + + Double maxAfterMerge = exec(commandObjects.tdigestMax(destinationKey)); + assertThat(maxAfterMerge, equalTo(4.0)); + } + + @Test + public void testTDigestMergeWithParams() { + String destinationKey = "testTDigestMergeDestParams"; + String sourceKey1 = "testTDigestSource1Params"; + String sourceKey2 = "testTDigestSource2Params"; + + TDigestMergeParams mergeParams = new TDigestMergeParams().compression(100); + + String create1 = exec(commandObjects.tdigestCreate(sourceKey1, 100)); + assertThat(create1, equalTo("OK")); + + String create2 = exec(commandObjects.tdigestCreate(sourceKey2, 100)); + assertThat(create2, equalTo("OK")); + + String add1 = exec(commandObjects.tdigestAdd(sourceKey1, 10.0, 20.0)); + assertThat(add1, equalTo("OK")); + + String add2 = exec(commandObjects.tdigestAdd(sourceKey2, 30.0, 40.0)); + assertThat(add2, equalTo("OK")); + + String merge = exec(commandObjects.tdigestMerge(mergeParams, destinationKey, sourceKey1, sourceKey2)); + assertThat(merge, equalTo("OK")); + + Double minAfterMerge = exec(commandObjects.tdigestMin(destinationKey)); + assertThat(minAfterMerge, equalTo(10.0)); + + Double maxAfterMerge = exec(commandObjects.tdigestMax(destinationKey)); + assertThat(maxAfterMerge, equalTo(40.0)); + } + + @Test + public void testTDigestReset() { + String key = "testTDigest"; + + String create = exec(commandObjects.tdigestCreate(key)); + assertThat(create, equalTo("OK")); + + String add = exec(commandObjects.tdigestAdd(key, 5.0, 10.0, 15.0)); + assertThat(add, equalTo("OK")); + + Double minBeforeReset = exec(commandObjects.tdigestMin(key)); + assertThat(minBeforeReset, equalTo(5.0)); + + Double maxBeforeReset = exec(commandObjects.tdigestMax(key)); + assertThat(maxBeforeReset, equalTo(15.0)); + + String reset = exec(commandObjects.tdigestReset(key)); + assertThat(reset, equalTo("OK")); + + Double minAfterReset = exec(commandObjects.tdigestMin(key)); + assertThat(minAfterReset, notANumber()); + + Double maxAfterReset = exec(commandObjects.tdigestMax(key)); + assertThat(maxAfterReset, notANumber()); + } + + @Test + public void testTDigestCdf() { + String key = "testTDigest"; + + String create = exec(commandObjects.tdigestCreate(key)); + assertThat(create, equalTo("OK")); + + String add = exec(commandObjects.tdigestAdd(key, 1.0, 2.0, 3.0, 4.0, 5.0)); + assertThat(add, equalTo("OK")); + + List cdf = exec(commandObjects.tdigestCDF(key, 1.0, 3.0, 5.0)); + + assertThat(cdf, notNullValue()); + assertThat(cdf.size(), equalTo(3)); + assertThat(cdf.get(0), lessThanOrEqualTo(0.2)); + assertThat(cdf.get(1), lessThanOrEqualTo(0.6)); + assertThat(cdf.get(2), lessThanOrEqualTo(1.0)); + } + + @Test + public void testTDigestQuantile() { + String key = "testTDigest"; + + String create = exec(commandObjects.tdigestCreate(key)); + assertThat(create, equalTo("OK")); + + String add = exec(commandObjects.tdigestAdd(key, 1.0, 2.0, 3.0, 4.0, 5.0)); + assertThat(add, equalTo("OK")); + + List quantile = exec(commandObjects.tdigestQuantile(key, 0.25, 0.5, 0.75)); + + assertThat(quantile, notNullValue()); + assertThat(quantile.size(), equalTo(3)); + assertThat(quantile.get(0), lessThanOrEqualTo(2.0)); + assertThat(quantile.get(1), lessThanOrEqualTo(3.0)); + assertThat(quantile.get(2), lessThanOrEqualTo(4.0)); + } + + @Test + public void testTDigestTrimmedMean() { + String key = "testTDigest"; + + String create = exec(commandObjects.tdigestCreate(key)); + assertThat(create, equalTo("OK")); + + String add = exec(commandObjects.tdigestAdd(key, 1.0, 2.0, 3.0, 4.0, 5.0)); + assertThat(add, equalTo("OK")); + + Double trimmedMean = exec(commandObjects.tdigestTrimmedMean(key, 0.1, 0.9)); + + assertThat(trimmedMean, notNullValue()); + assertThat(trimmedMean, lessThanOrEqualTo(4.0)); + assertThat(trimmedMean, greaterThanOrEqualTo(2.0)); + } + + @Test + public void testTDigestRankAndRevRank() { + String key = "testTDigest"; + + String create = exec(commandObjects.tdigestCreate(key)); + assertThat(create, equalTo("OK")); + + String add = exec(commandObjects.tdigestAdd(key, 1.0, 2.0, 3.0, 4.0, 5.0)); + assertThat(add, equalTo("OK")); + + List rank = exec(commandObjects.tdigestRank(key, 1.0, 3.0, 5.0)); + + assertThat(rank, notNullValue()); + assertThat(rank.size(), equalTo(3)); + assertThat(rank.get(0), lessThanOrEqualTo(1L)); + assertThat(rank.get(1), lessThanOrEqualTo(3L)); + assertThat(rank.get(2), lessThanOrEqualTo(5L)); + + List revRank = exec(commandObjects.tdigestRevRank(key, 1.0, 3.0, 5.0)); + + assertThat(revRank, notNullValue()); + assertThat(revRank.size(), equalTo(3)); + assertThat(revRank.get(0), greaterThanOrEqualTo(4L)); + assertThat(revRank.get(1), greaterThanOrEqualTo(2L)); + assertThat(revRank.get(2), greaterThanOrEqualTo(0L)); + } + + @Test + public void testTDigestByRankAndByRevRank() { + String key = "testTDigest"; + + String create = exec(commandObjects.tdigestCreate(key)); + assertThat(create, equalTo("OK")); + + String add = exec(commandObjects.tdigestAdd(key, 0.5, 1.5, 2.5, 3.5, 4.5)); + assertThat(add, equalTo("OK")); + + List byRank = exec(commandObjects.tdigestByRank(key, 0, 2, 4)); + + assertThat(byRank, notNullValue()); + assertThat(byRank.size(), equalTo(3)); + assertThat(byRank.get(0), closeTo(0.5, 0.1)); + assertThat(byRank.get(1), closeTo(2.5, 0.1)); + assertThat(byRank.get(2), closeTo(4.5, 0.1)); + + List byRevRank = exec(commandObjects.tdigestByRevRank(key, 0, 2, 4)); + + assertThat(byRevRank, notNullValue()); + assertThat(byRevRank.size(), equalTo(3)); + assertThat(byRevRank.get(0), closeTo(4.5, 0.1)); + assertThat(byRevRank.get(1), closeTo(2.5, 0.1)); + assertThat(byRevRank.get(2), closeTo(0.5, 0.1)); + } + + @Test + public void testTDigestInfo() { + String key = "testTDigest"; + + String create = exec(commandObjects.tdigestCreate(key)); + assertThat(create, equalTo("OK")); + + String add = exec(commandObjects.tdigestAdd(key, 1.0, 2.0, 3.0)); + assertThat(add, equalTo("OK")); + + Map info = exec(commandObjects.tdigestInfo(key)); + + assertThat(info, notNullValue()); + assertThat(info, hasKey("Compression")); + assertThat(info, hasEntry("Observations", 3L)); + } +} diff --git a/src/test/java/redis/clients/jedis/commands/commandobjects/CommandObjectsTestBase.java b/src/test/java/redis/clients/jedis/commands/commandobjects/CommandObjectsTestBase.java new file mode 100644 index 00000000000..5fde2888393 --- /dev/null +++ b/src/test/java/redis/clients/jedis/commands/commandobjects/CommandObjectsTestBase.java @@ -0,0 +1,108 @@ +package redis.clients.jedis.commands.commandobjects; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.equalTo; + +import java.util.Collection; + +import org.junit.Before; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import redis.clients.jedis.CommandObject; +import redis.clients.jedis.CommandObjects; +import redis.clients.jedis.DefaultJedisClientConfig; +import redis.clients.jedis.HostAndPort; +import redis.clients.jedis.RedisProtocol; +import redis.clients.jedis.args.FlushMode; +import redis.clients.jedis.commands.CommandsTestsParameters; +import redis.clients.jedis.executors.CommandExecutor; +import redis.clients.jedis.executors.DefaultCommandExecutor; +import redis.clients.jedis.providers.ConnectionProvider; +import redis.clients.jedis.providers.PooledConnectionProvider; + +/** + * Base class for CommandObjects tests. The tests are parameterized to run with + * several versions of RESP. The idea is to test commands at this low level, using + * a simple executor. Higher level concepts like {@link redis.clients.jedis.UnifiedJedis}, + * or {@link redis.clients.jedis.PipeliningBase} can be tested separately with mocks. + *

+ * This class provides the basic setup, except the {@link HostAndPort} for connecting + * to a running Redis server. That one is provided by abstract subclasses, depending + * on if a Redis Stack server is needed, or a standalone suffices. + */ +@RunWith(Parameterized.class) +public abstract class CommandObjectsTestBase { + + /** + * 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(); + } + + /** + * RESP protocol used in the tests. Injected from subclasses. + */ + protected final RedisProtocol protocol; + + /** + * Host and port of the Redis server to connect to. Injected from subclasses. + */ + protected final HostAndPort nodeInfo; + + /** + * Password to use when connecting to the Redis server, if needed. Injected from subclasses. + */ + private final String authPassword; + + /** + * The {@link CommandObjects} to use for the tests. This is the subject-under-test. + */ + protected final CommandObjects commandObjects; + + /** + * A {@link CommandExecutor} that can execute commands against the running Redis server. + * Not exposed to subclasses, which should use a convenience method instead. + */ + private CommandExecutor commandExecutor; + + public CommandObjectsTestBase(RedisProtocol protocol, HostAndPort nodeInfo, String authPassword) { + this.protocol = protocol; + this.nodeInfo = nodeInfo; + this.authPassword = authPassword; + commandObjects = new CommandObjects(); + commandObjects.setProtocol(protocol); + } + + @Before + public void setUp() { + // Configure a default command executor. + DefaultJedisClientConfig clientConfig = DefaultJedisClientConfig.builder() + .protocol(protocol).password(authPassword).build(); + + ConnectionProvider connectionProvider = new PooledConnectionProvider(nodeInfo, clientConfig); + + commandExecutor = new DefaultCommandExecutor(connectionProvider); + + // Cleanup before each test. + assertThat( + commandExecutor.executeCommand(commandObjects.flushAll()), + equalTo("OK")); + + assertThat( + commandExecutor.executeCommand(commandObjects.functionFlush(FlushMode.SYNC)), + equalTo("OK")); + } + + /** + * Convenience method for subclasses, for running any {@link CommandObject}. + */ + protected T exec(CommandObject commandObject) { + return commandExecutor.executeCommand(commandObject); + } + +} diff --git a/src/test/java/redis/clients/jedis/commands/commandobjects/CommandObjectsTimeSeriesCommandsTest.java b/src/test/java/redis/clients/jedis/commands/commandobjects/CommandObjectsTimeSeriesCommandsTest.java new file mode 100644 index 00000000000..374ca315c24 --- /dev/null +++ b/src/test/java/redis/clients/jedis/commands/commandobjects/CommandObjectsTimeSeriesCommandsTest.java @@ -0,0 +1,622 @@ +package redis.clients.jedis.commands.commandobjects; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.closeTo; +import static org.hamcrest.Matchers.contains; +import static org.hamcrest.Matchers.containsInAnyOrder; +import static org.hamcrest.Matchers.empty; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.hasEntry; +import static org.hamcrest.Matchers.hasItems; +import static org.hamcrest.Matchers.hasSize; +import static org.hamcrest.Matchers.notNullValue; +import static org.hamcrest.Matchers.nullValue; + +import java.util.AbstractMap; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +import org.junit.Test; +import redis.clients.jedis.RedisProtocol; +import redis.clients.jedis.timeseries.AggregationType; +import redis.clients.jedis.timeseries.TSAlterParams; +import redis.clients.jedis.timeseries.TSCreateParams; +import redis.clients.jedis.timeseries.TSElement; +import redis.clients.jedis.timeseries.TSGetParams; +import redis.clients.jedis.timeseries.TSInfo; +import redis.clients.jedis.timeseries.TSMGetElement; +import redis.clients.jedis.timeseries.TSMGetParams; +import redis.clients.jedis.timeseries.TSMRangeElements; +import redis.clients.jedis.timeseries.TSMRangeParams; +import redis.clients.jedis.timeseries.TSRangeParams; + +/** + * Tests related to Time series commands. + */ +public class CommandObjectsTimeSeriesCommandsTest extends CommandObjectsModulesTestBase { + + public CommandObjectsTimeSeriesCommandsTest(RedisProtocol protocol) { + super(protocol); + } + + @Test + public void testTsAddAndRange() throws InterruptedException { + String key = "testTs"; + + String create = exec(commandObjects.tsCreate(key)); + assertThat(create, equalTo("OK")); + + long currentTime = System.currentTimeMillis(); + double[] values = { 42.0, 43.0, 44.0 }; + for (double value : values) { + Long add = exec(commandObjects.tsAdd(key, value)); + assertThat(add, notNullValue()); + + // short delay to avoid the same timestamp + Thread.sleep(10); + } + + List range = exec(commandObjects.tsRange(key, currentTime - 1000, currentTime + 1000)); + + assertThat(range, hasSize(values.length)); + for (int i = 0; i < values.length; i++) { + assertThat(range.get(i).getValue(), equalTo(values[i])); + } + } + + @Test + public void testTsAddWithTimestampDelAndRangeWithPreDeleteAssert() { + String key = "testTs"; + + String create = exec(commandObjects.tsCreate(key)); + assertThat(create, equalTo("OK")); + + long timestamp1 = 1000; + double value1 = 42.0; + + long timestamp2 = 2000; + double value2 = 43.0; + + Long add1 = exec(commandObjects.tsAdd(key, timestamp1, value1)); + assertThat(add1, notNullValue()); + + Long add2 = exec(commandObjects.tsAdd(key, timestamp2, value2)); + assertThat(add2, notNullValue()); + + List preDelRange = exec(commandObjects.tsRange(key, timestamp1 - 500, timestamp2 + 500)); + + assertThat(preDelRange, hasSize(2)); + assertThat(preDelRange.get(0).getValue(), equalTo(value1)); + assertThat(preDelRange.get(1).getValue(), equalTo(value2)); + + Long del = exec(commandObjects.tsDel(key, timestamp1 - 500, timestamp1 + 500)); + assertThat(del, equalTo(1L)); + + List postDelRange = exec(commandObjects.tsRange(key, timestamp1 - 500, timestamp2 + 500)); + + assertThat(postDelRange, hasSize(1)); + assertThat(postDelRange.get(0).getValue(), equalTo(value2)); + } + + @Test + public void testTsAddWithParams() { + String key = "testTs"; + + long timestamp = System.currentTimeMillis(); + double value = 42.0; + + TSCreateParams createParams = new TSCreateParams() + .uncompressed().retention(86400000); + + Long add = exec(commandObjects.tsAdd(key, timestamp, value, createParams)); + assertThat(add, notNullValue()); + + List range = exec(commandObjects.tsRange(key, timestamp - 1000, timestamp + 1000)); + + assertThat(range, hasSize(1)); + assertThat(range.get(0).getTimestamp(), equalTo(timestamp)); + assertThat(range.get(0).getValue(), equalTo(value)); + } + + @Test + public void testTsMAdd() { + String key1 = "testTsMAdd1"; + String key2 = "testTsMAdd2"; + + String create1 = exec(commandObjects.tsCreate(key1)); + assertThat(create1, equalTo("OK")); + + String create2 = exec(commandObjects.tsCreate(key2)); + assertThat(create2, equalTo("OK")); + + long timestamp1 = 2000; + long timestamp2 = 3000; + + Map.Entry entry1 = + new AbstractMap.SimpleEntry<>(key1, new TSElement(timestamp1, 42.0)); + + Map.Entry entry2 = + new AbstractMap.SimpleEntry<>(key2, new TSElement(timestamp2, 43.0)); + + List mAdd = exec(commandObjects.tsMAdd(entry1, entry2)); + assertThat(mAdd, contains(timestamp1, timestamp2)); + + List range1 = exec(commandObjects.tsRange(key1, timestamp1 - 1000, timestamp1 + 1000)); + + assertThat(range1, hasSize(1)); + assertThat(range1.get(0).getTimestamp(), equalTo(timestamp1)); + assertThat(range1.get(0).getValue(), equalTo(42.0)); + + List range2 = exec(commandObjects.tsRange(key2, timestamp2 - 1000, timestamp2 + 1000)); + + assertThat(range2, hasSize(1)); + assertThat(range2.get(0).getTimestamp(), equalTo(timestamp2)); + assertThat(range2.get(0).getValue(), equalTo(43.0)); + } + + @Test + public void testTsIncrByAndDecrBy() throws InterruptedException { + String key = "testTs"; + + String create = exec(commandObjects.tsCreate(key)); + assertThat(create, equalTo("OK")); + + double initialValue = 10.0; + double incrementValue = 5.0; + double decrementValue = 3.0; + + Long initialAdd = exec(commandObjects.tsAdd(key, System.currentTimeMillis(), initialValue)); + assertThat(initialAdd, notNullValue()); + + Thread.sleep(50); + + Long incr = exec(commandObjects.tsIncrBy(key, incrementValue)); + assertThat(incr, notNullValue()); + + Thread.sleep(50); + + Long decr = exec(commandObjects.tsDecrBy(key, decrementValue)); + assertThat(decr, notNullValue()); + + TSElement latestElement = exec(commandObjects.tsGet(key)); + double expectedValue = initialValue + incrementValue - decrementValue; + assertThat(latestElement.getValue(), equalTo(expectedValue)); + + List range = exec(commandObjects.tsRange( + key, latestElement.getTimestamp() - 1000, latestElement.getTimestamp() + 1000)); + + assertThat(range.stream().map(TSElement::getValue).collect(Collectors.toList()), contains( + closeTo(initialValue, 0.001), + closeTo(initialValue + incrementValue, 0.001), + closeTo(expectedValue, 0.001))); + } + + @Test + public void testTsIncrByAndDecrByWithTimestamp() { + String key = "testTs"; + + String create = exec(commandObjects.tsCreate(key)); + assertThat(create, equalTo("OK")); + + double initialValue = 10.0; + double incrementValue = 5.0; + double decrementValue = 3.0; + + long initialTimestamp = System.currentTimeMillis(); + + Long initialAdd = exec(commandObjects.tsAdd(key, initialTimestamp, initialValue)); + assertThat(initialAdd, equalTo(initialTimestamp)); + + long incrementTimestamp = initialTimestamp + 1000; + + Long incr = exec(commandObjects.tsIncrBy(key, incrementValue, incrementTimestamp)); + assertThat(incr, equalTo(incrementTimestamp)); + + long decrementTimestamp = incrementTimestamp + 1000; + + Long decr = exec(commandObjects.tsDecrBy(key, decrementValue, decrementTimestamp)); + assertThat(decr, equalTo(decrementTimestamp)); + + List range = exec(commandObjects.tsRange( + key, initialTimestamp - 1000, decrementTimestamp + 1000)); + + assertThat(range.stream().map(TSElement::getValue).collect(Collectors.toList()), contains( + closeTo(initialValue, 0.001), + closeTo(initialValue + incrementValue, 0.001), + closeTo(initialValue + incrementValue - decrementValue, 0.001))); + } + + @Test + public void testTsRange() { + String key = "tsKey"; + + String create = exec(commandObjects.tsCreate(key)); + assertThat(create, equalTo("OK")); + + long fromTimestamp = 1000L; + long toTimestamp = 2000L; + + List initialRange = exec(commandObjects.tsRange(key, fromTimestamp - 100, toTimestamp + 100)); + assertThat(initialRange, hasSize(0)); + + exec(commandObjects.tsAdd(key, fromTimestamp, 1.0)); + exec(commandObjects.tsAdd(key, toTimestamp, 2.0)); + + List elementsByTimestamp = exec(commandObjects.tsRange(key, fromTimestamp - 100, toTimestamp + 100)); + + assertThat(elementsByTimestamp.stream().map(TSElement::getValue).collect(Collectors.toList()), contains( + closeTo(1.0, 0.001), + closeTo(2.0, 0.001))); + + TSRangeParams rangeParams = new TSRangeParams(fromTimestamp - 100, toTimestamp + 100); + + List elementsByParams = exec(commandObjects.tsRange(key, rangeParams)); + + assertThat(elementsByParams.stream().map(TSElement::getValue).collect(Collectors.toList()), contains( + closeTo(1.0, 0.001), + closeTo(2.0, 0.001))); + } + + @Test + public void testTsRevRange() { + String key = "tsRevKey"; + + String create = exec(commandObjects.tsCreate(key)); + assertThat(create, equalTo("OK")); + + long fromTimestamp = 1000L; + long toTimestamp = 2000L; + + List initialRevRange = exec(commandObjects.tsRevRange(key, fromTimestamp - 100, toTimestamp + 100)); + assertThat(initialRevRange, hasSize(0)); + + exec(commandObjects.tsAdd(key, fromTimestamp, 1.0)); + exec(commandObjects.tsAdd(key, toTimestamp, 2.0)); + + List elementsByTimestamp = exec(commandObjects.tsRevRange(key, fromTimestamp - 100, toTimestamp + 100)); + + assertThat(elementsByTimestamp.stream().map(TSElement::getValue).collect(Collectors.toList()), contains( + closeTo(2.0, 0.001), + closeTo(1.0, 0.001))); + + TSRangeParams rangeParams = new TSRangeParams(fromTimestamp - 100, toTimestamp + 100); + + List elementsByParams = exec(commandObjects.tsRevRange(key, rangeParams)); + + assertThat(elementsByParams.stream().map(TSElement::getValue).collect(Collectors.toList()), contains( + closeTo(2.0, 0.001), + closeTo(1.0, 0.001))); + } + + @Test + public void testTsMRangeCommands() { + String key1 = "tsMRangeKey1"; + String key2 = "tsMRangeKey2"; + + long fromTimestamp = 1000L; + long toTimestamp = 3000L; + + String filter = "sensor_id=1234"; + + Map initialMRange = exec(commandObjects.tsMRange( + fromTimestamp - 100, toTimestamp + 100, filter)); + assertThat(initialMRange.entrySet(), hasSize(0)); + + TSCreateParams createParams = new TSCreateParams() + .uncompressed().label("sensor_id", "1234"); + + exec(commandObjects.tsAdd(key1, fromTimestamp, 1.0, createParams)); + exec(commandObjects.tsAdd(key1, fromTimestamp + 500, 1.5, createParams)); + exec(commandObjects.tsAdd(key2, toTimestamp - 500, 2.5, createParams)); + exec(commandObjects.tsAdd(key2, toTimestamp, 2.0, createParams)); + + Map range = exec(commandObjects.tsMRange( + fromTimestamp - 100, toTimestamp + 100, filter)); + + assertThat(range.keySet(), hasItems(key1, key2)); + assertThat(range.get(key1).getElements().stream().map(TSElement::getValue).collect(Collectors.toList()), + containsInAnyOrder(closeTo(1.0, 0.001), closeTo(1.5, 0.001))); + assertThat(range.get(key2).getElements().stream().map(TSElement::getValue).collect(Collectors.toList()), + containsInAnyOrder(closeTo(2.5, 0.001), closeTo(2.0, 0.001))); + + Map revRangeResult = exec(commandObjects.tsMRevRange( + fromTimestamp - 100, toTimestamp + 100, filter)); + + assertThat(revRangeResult.keySet(), hasItems(key1, key2)); + assertThat(revRangeResult.get(key1).getElements().stream().map(TSElement::getValue).collect(Collectors.toList()), + containsInAnyOrder(closeTo(1.5, 0.001), closeTo(1.0, 0.001))); + assertThat(revRangeResult.get(key2).getElements().stream().map(TSElement::getValue).collect(Collectors.toList()), + containsInAnyOrder(closeTo(2.0, 0.001), closeTo(2.5, 0.001))); + + TSMRangeParams multiRangeParamsA = + new TSMRangeParams(fromTimestamp - 100, toTimestamp + 100).filter(filter); + + Map rangeResultWithParams = exec(commandObjects.tsMRange(multiRangeParamsA)); + + assertThat(rangeResultWithParams.keySet(), hasItems(key1, key2)); + assertThat(rangeResultWithParams, equalTo(range)); + + TSMRangeParams multiRangeParams = new TSMRangeParams(fromTimestamp - 100, toTimestamp + 100).filter(filter); + + Map revRangeResultWithParams = exec(commandObjects.tsMRevRange(multiRangeParams)); + + assertThat(revRangeResultWithParams.keySet(), hasItems(key1, key2)); + assertThat(revRangeResultWithParams, equalTo(revRangeResult)); + } + + @Test + public void testTsGet() { + String key = "tsGetKey"; + + String create = exec(commandObjects.tsCreate(key)); + assertThat(create, equalTo("OK")); + + long timestamp = 1000L; + + double firstValue = 2.5; + double secondValue = 3.5; + + TSElement initialGet = exec(commandObjects.tsGet(key)); + assertThat(initialGet, nullValue()); + + exec(commandObjects.tsAdd(key, timestamp, firstValue)); + exec(commandObjects.tsAdd(key, timestamp + 100, secondValue)); + + TSElement getLastValue = exec(commandObjects.tsGet(key)); + assertThat(getLastValue, notNullValue()); + assertThat(getLastValue.getValue(), closeTo(secondValue, 0.001)); + + TSElement getWithParams = exec(commandObjects.tsGet(key, new TSGetParams().latest())); + assertThat(getWithParams, notNullValue()); + assertThat(getWithParams.getValue(), closeTo(secondValue, 0.001)); + } + + @Test + public void testTsMGet() { + String key1 = "tsMGetKey1"; + String key2 = "tsMGetKey2"; + + long timestamp1 = 1000L; + long timestamp2 = 2000L; + + double value1 = 1.0; + double value2 = 2.0; + + String filter = "sensor_id=1234"; + + TSCreateParams createParams = new TSCreateParams() + .uncompressed().label("sensor_id", "1234"); + + exec(commandObjects.tsAdd(key1, timestamp1, value1, createParams)); + exec(commandObjects.tsAdd(key2, timestamp2, value2, createParams)); + + TSMGetParams multiGetParams = new TSMGetParams().withLabels(); + + Map elements = exec(commandObjects.tsMGet(multiGetParams, filter)); + + assertThat(elements.keySet(), hasItems(key1, key2)); + + TSMGetElement element1 = elements.get(key1); + assertThat(element1, notNullValue()); + assertThat(element1.getElement().getTimestamp(), equalTo(timestamp1)); + assertThat(element1.getElement().getValue(), closeTo(value1, 0.001)); + + TSMGetElement element2 = elements.get(key2); + assertThat(element2, notNullValue()); + assertThat(element2.getElement().getTimestamp(), equalTo(timestamp2)); + assertThat(element2.getElement().getValue(), closeTo(value2, 0.001)); + + assertThat(element1.getLabels(), hasEntry("sensor_id", "1234")); + assertThat(element2.getLabels(), hasEntry("sensor_id", "1234")); + } + + @Test + public void testTsCreateRule() { + String sourceKey = "tsSourceKey"; + String destKey = "tsDestKey"; + + AggregationType aggregationType = AggregationType.AVG; + + long timeBucket = 60000; // 1 minute + + exec(commandObjects.tsCreate(sourceKey)); + exec(commandObjects.tsCreate(destKey)); + + String createRule = exec(commandObjects.tsCreateRule(sourceKey, destKey, aggregationType, timeBucket)); + assertThat(createRule, equalTo("OK")); + + long timestamp1 = 1000L; // 1 second + double value1 = 10.0; + exec(commandObjects.tsAdd(sourceKey, timestamp1, value1)); + + long timestamp2 = 30000L; // 30 seconds + double value2 = 20.0; + exec(commandObjects.tsAdd(sourceKey, timestamp2, value2)); + + long timestamp3 = 100000L; // 100 seconds, should be in the second aggregation bucket + double value3 = 30.0; + exec(commandObjects.tsAdd(sourceKey, timestamp3, value3)); + + long timestamp4 = 200000L; // 200 seconds, should be in the fourth aggregation bucket + double value4 = 1.0; + exec(commandObjects.tsAdd(sourceKey, timestamp4, value4)); + + // Verify that aggregated data appears in the destination key + // We only check the first three buckets, i.e. 180 seconds + // The average of value1 and value2 should be in the first bucket, value3 in the second + List destElements = exec(commandObjects.tsRange(destKey, 0, 180000)); + + assertThat(destElements.size(), equalTo(2)); + + double expectedAvgFirstBucket = (value1 + value2) / 2.0; + assertThat(destElements.get(0).getValue(), closeTo(expectedAvgFirstBucket, 0.001)); + + assertThat(destElements.get(1).getValue(), closeTo(value3, 0.001)); + } + + @Test + public void testTsCreateRuleWithAlign() { + String sourceKey = "tsSourceKey"; + String destKey = "tsDestKey"; + + AggregationType aggregationType = AggregationType.AVG; + + long timeBucket = 60000; // 1 minute + + exec(commandObjects.tsCreate(sourceKey)); + exec(commandObjects.tsCreate(destKey)); + + String createRule = exec(commandObjects.tsCreateRule(sourceKey, destKey, aggregationType, timeBucket, 2000)); + assertThat(createRule, equalTo("OK")); + + long timestamp1 = 1000L; // 1 second + double value1 = 10.0; + exec(commandObjects.tsAdd(sourceKey, timestamp1, value1)); + + long timestamp2 = 30000L; // 30 seconds + double value2 = 20.0; + exec(commandObjects.tsAdd(sourceKey, timestamp2, value2)); + + long timestamp3 = 100000L; // 100 seconds, should be in the second aggregation bucket + double value3 = 30.0; + exec(commandObjects.tsAdd(sourceKey, timestamp3, value3)); + + long timestamp4 = 200000L; // 200 seconds, should be in the fourth aggregation bucket + double value4 = 1.0; + exec(commandObjects.tsAdd(sourceKey, timestamp4, value4)); + + // Verify that aggregated data appears in the destination key + // We only check the first three buckets, i.e. 180 seconds + // The average of value1 and value2 should be in the first bucket, value3 in the second + List destElements = exec(commandObjects.tsRange(destKey, 2000, 182000)); + + assertThat(destElements.size(), equalTo(2)); + assertThat(destElements.get(0).getValue(), closeTo(value2, 0.001)); + assertThat(destElements.get(1).getValue(), closeTo(value3, 0.001)); + } + + + @Test + public void testTsDeleteRule() { + String sourceKey = "tsSourceKeyForDeletionWithData"; + String destKey = "tsDestKeyForDeletionWithData"; + + AggregationType aggregationType = AggregationType.SUM; + + long bucketDuration = 60000; // 1 minute + + exec(commandObjects.tsCreate(sourceKey)); + exec(commandObjects.tsCreate(destKey)); + + exec(commandObjects.tsCreateRule(sourceKey, destKey, aggregationType, bucketDuration)); + + long initialTimestamp = 1000; + exec(commandObjects.tsAdd(sourceKey, initialTimestamp, 10.0)); + + // This will force aggregation of the first bucket + exec(commandObjects.tsAdd(sourceKey, initialTimestamp + bucketDuration, 20.0)); + + List initialAggregatedData = exec(commandObjects.tsRange(destKey, 0, bucketDuration)); + + assertThat(initialAggregatedData.stream().map(TSElement::getValue).collect(Collectors.toList()), + contains(closeTo(10.0, 0.001))); + + List initialAggregatedDataSecondBucket = exec(commandObjects.tsRange(destKey, bucketDuration, 2 * bucketDuration)); + + assertThat(initialAggregatedDataSecondBucket.stream().map(TSElement::getValue).collect(Collectors.toList()), + empty()); + + // Delete the rule + String deleteRule = exec(commandObjects.tsDeleteRule(sourceKey, destKey)); + assertThat(deleteRule, equalTo("OK")); + + // Add more data to the source key after the rule has been deleted + long postDeletionTimestamp = initialTimestamp + bucketDuration + 10; + + exec(commandObjects.tsAdd(sourceKey, postDeletionTimestamp, 20)); + + // This should force the aggregation of the second bucket, if there was a rule + exec(commandObjects.tsAdd(sourceKey, postDeletionTimestamp + bucketDuration, 20)); + + // Make sure that the data in the destination key has not changed + List postDeletionAggregatedData = exec(commandObjects.tsRange(destKey, 0, bucketDuration)); + + assertThat(postDeletionAggregatedData.stream().map(TSElement::getValue).collect(Collectors.toList()), + contains(closeTo(10.0, 0.001))); + + List postDeletionAggregatedDataSecondBucket = exec(commandObjects.tsRange(destKey, bucketDuration, 2 * bucketDuration)); + + assertThat(postDeletionAggregatedDataSecondBucket.stream().map(TSElement::getValue).collect(Collectors.toList()), + empty()); + } + + @Test + public void testTsQueryIndexWithKeyCreation() { + String key1 = "temperature:sensor:1"; + String key2 = "temperature:sensor:2"; + String key3 = "humidity:sensor:1"; + + TSCreateParams paramsTempSensor1 = new TSCreateParams() + .label("type", "temperature").label("sensor_id", "1"); + + exec(commandObjects.tsCreate(key1, paramsTempSensor1)); + + TSCreateParams paramsTempSensor2 = new TSCreateParams() + .label("type", "temperature").label("sensor_id", "2"); + + exec(commandObjects.tsCreate(key2, paramsTempSensor2)); + + TSCreateParams paramsHumiditySensor1 = new TSCreateParams() + .label("type", "humidity").label("sensor_id", "1"); + + exec(commandObjects.tsCreate(key3, paramsHumiditySensor1)); + + String[] filters = new String[]{ "type=temperature" }; + List matchingKeys = exec(commandObjects.tsQueryIndex(filters)); + + assertThat(matchingKeys, containsInAnyOrder(key1, key2)); + } + + @Test + public void testTsAlterAndInfo() { + String key = "tsKey"; + + TSCreateParams createParams = new TSCreateParams() + .label("sensor", "temperature"); + + TSAlterParams alterParams = new TSAlterParams() + .label("sensor", "humidity"); + + String create = exec(commandObjects.tsCreate(key, createParams)); + assertThat(create, equalTo("OK")); + + TSInfo info = exec(commandObjects.tsInfo(key)); + + assertThat(info, notNullValue()); + assertThat(info.getLabels().get("sensor"), equalTo("temperature")); + assertThat(info.getChunks(), nullValue()); + + TSInfo debugInfo = exec(commandObjects.tsInfoDebug(key)); + + assertThat(debugInfo, notNullValue()); + assertThat(debugInfo.getLabels().get("sensor"), equalTo("temperature")); + assertThat(debugInfo.getChunks(), notNullValue()); + + String alter = exec(commandObjects.tsAlter(key, alterParams)); + + assertThat(alter, equalTo("OK")); + + TSInfo infoAfter = exec(commandObjects.tsInfo(key)); + + assertThat(infoAfter, notNullValue()); + assertThat(infoAfter.getLabels().get("sensor"), equalTo("humidity")); + assertThat(infoAfter.getChunks(), nullValue()); + + TSInfo debugInfoAfter = exec(commandObjects.tsInfoDebug(key)); + + assertThat(debugInfoAfter, notNullValue()); + assertThat(debugInfoAfter.getLabels().get("sensor"), equalTo("humidity")); + assertThat(debugInfoAfter.getChunks(), notNullValue()); + } +} diff --git a/src/test/java/redis/clients/jedis/commands/commandobjects/CommandObjectsTopkCommandsTest.java b/src/test/java/redis/clients/jedis/commands/commandobjects/CommandObjectsTopkCommandsTest.java new file mode 100644 index 00000000000..4091fd52800 --- /dev/null +++ b/src/test/java/redis/clients/jedis/commands/commandobjects/CommandObjectsTopkCommandsTest.java @@ -0,0 +1,118 @@ +package redis.clients.jedis.commands.commandobjects; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.aMapWithSize; +import static org.hamcrest.Matchers.contains; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.hasEntry; +import static org.hamcrest.Matchers.hasKey; +import static org.hamcrest.Matchers.hasSize; +import static org.hamcrest.Matchers.notNullValue; +import static org.hamcrest.Matchers.nullValue; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.junit.Test; +import redis.clients.jedis.RedisProtocol; + +/** + * Tests related to Top-k commands. + */ +public class CommandObjectsTopkCommandsTest extends CommandObjectsModulesTestBase { + + public CommandObjectsTopkCommandsTest(RedisProtocol protocol) { + super(protocol); + } + + @Test + public void testTopKAddAndQuery() { + String key = "testTopK"; + + long topKSize = 3; + + String reserve = exec(commandObjects.topkReserve(key, topKSize)); + assertThat(reserve, equalTo("OK")); + + List add = exec(commandObjects.topkAdd(key, + "apple", "banana", "carrot", "apple", "banana", + "date", "eggplant", "fig", "grape", "apple")); + // As the values are added, some items get kicked out from top 3. They are returned in the response. + assertThat(add, contains( + nullValue(), nullValue(), nullValue(), nullValue(), nullValue(), + equalTo("carrot"), equalTo("date"), equalTo("eggplant"), equalTo("fig"), nullValue() + )); + + List query = exec(commandObjects.topkQuery(key, "apple", "banana", "carrot", "grape")); + assertThat(query, contains(true, true, false, true)); + } + + @Test + public void testTopKIncrBy() { + String key = "testTopK"; + + long topKSize = 3; + + Map itemIncrements = new HashMap<>(); + itemIncrements.put("apple", 2L); + itemIncrements.put("banana", 3L); + itemIncrements.put("carrot", 1L); + itemIncrements.put("date", 5L); + + String reserve = exec(commandObjects.topkReserve(key, topKSize, 2000, 7, 0.9)); + assertThat(reserve, equalTo("OK")); + + List incrBy = exec(commandObjects.topkIncrBy(key, itemIncrements)); + // Due to Map's unpredictable order, we can't assert ordering of the result + assertThat(incrBy, hasSize(4)); + + List query = exec(commandObjects.topkQuery(key, "apple", "banana", "date", "carrot")); + assertThat(query, contains(true, true, true, false)); + } + + @Test + public void testTopKListAndListWithCount() { + String key = "testTopK"; + + long topKSize = 3; + + String reserve = exec(commandObjects.topkReserve(key, topKSize)); + assertThat(reserve, equalTo("OK")); + + List add = exec(commandObjects.topkAdd(key, + "apple", "banana", "carrot", "apple", "banana", + "date", "eggplant", "fig", "grape", "apple")); + assertThat(add, notNullValue()); + + List list = exec(commandObjects.topkList(key)); + assertThat(list, contains("apple", "banana", "grape")); + + Map listWithCount = exec(commandObjects.topkListWithCount(key)); + assertThat(listWithCount, aMapWithSize(3)); + assertThat(listWithCount, hasEntry("apple", 3L)); + assertThat(listWithCount, hasEntry("banana", 2L)); + assertThat(listWithCount, hasEntry("grape", 1L)); + } + + @Test + public void testTopKInfo() { + String key = "testTopK"; + + long topKSize = 3; + long width = 1000; + long depth = 7; + double decay = 0.9; + + String reserve = exec(commandObjects.topkReserve(key, topKSize, width, depth, decay)); + assertThat(reserve, equalTo("OK")); + + Map info = exec(commandObjects.topkInfo(key)); + + assertThat(info, notNullValue()); + assertThat(info, hasEntry("k", 3L)); + assertThat(info, hasEntry("width", width)); + assertThat(info, hasEntry("depth", depth)); + assertThat(info, hasKey("decay")); + } +} diff --git a/src/test/java/redis/clients/jedis/commands/commandobjects/CommandObjectsTriggersAndFunctionsCommandsTest.java b/src/test/java/redis/clients/jedis/commands/commandobjects/CommandObjectsTriggersAndFunctionsCommandsTest.java new file mode 100644 index 00000000000..31528e80928 --- /dev/null +++ b/src/test/java/redis/clients/jedis/commands/commandobjects/CommandObjectsTriggersAndFunctionsCommandsTest.java @@ -0,0 +1,66 @@ +package redis.clients.jedis.commands.commandobjects; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.empty; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.hasSize; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.Test; +import redis.clients.jedis.RedisProtocol; +import redis.clients.jedis.gears.TFunctionListParams; +import redis.clients.jedis.gears.TFunctionLoadParams; +import redis.clients.jedis.gears.resps.GearsLibraryInfo; + +/** + * Tests related to Triggers and functions commands. + */ +public class CommandObjectsTriggersAndFunctionsCommandsTest extends CommandObjectsModulesTestBase { + + public CommandObjectsTriggersAndFunctionsCommandsTest(RedisProtocol protocol) { + super(protocol); + } + + @Test + public void testTFunctionLoadAndCall() { + String libraryCode = "#!js api_version=1.0 name=lib\n" + + "redis.registerFunction('hello', ()=>{return 42;})"; + + TFunctionLoadParams params = new TFunctionLoadParams().replace(); + + String load = exec(commandObjects.tFunctionLoad(libraryCode, params)); + assertThat(load, equalTo("OK")); + + Object call = exec(commandObjects.tFunctionCall("lib", "hello", new ArrayList<>(), new ArrayList<>())); + assertThat(call.toString(), equalTo("42")); + + Object callAsync = exec(commandObjects.tFunctionCallAsync("lib", "hello", new ArrayList<>(), new ArrayList<>())); + assertThat(callAsync.toString(), equalTo("42")); + } + + @Test + public void testTFunctionDeleteAndList() { + String libraryCode = "#!js api_version=1.0 name=lib\n" + + "redis.registerFunction('hello', ()=>{return 42;})"; + + String load = exec(commandObjects.tFunctionLoad(libraryCode, new TFunctionLoadParams().replace())); + assertThat(load, equalTo("OK")); + + TFunctionListParams params = new TFunctionListParams().library("lib"); + + List list = exec(commandObjects.tFunctionList(params)); + + assertThat(list, hasSize(1)); + assertThat(list.get(0).getName(), equalTo("lib")); + assertThat(list.get(0).getFunctions(), hasSize(1)); + assertThat(list.get(0).getFunctions().get(0).getName(), equalTo("hello")); + + String delete = exec(commandObjects.tFunctionDelete("lib")); + assertThat(delete, equalTo("OK")); + + list = exec(commandObjects.tFunctionList(params)); + assertThat(list, empty()); + } +} diff --git a/src/test/java/redis/clients/jedis/commands/commandobjects/Person.java b/src/test/java/redis/clients/jedis/commands/commandobjects/Person.java new file mode 100644 index 00000000000..f5ff0334018 --- /dev/null +++ b/src/test/java/redis/clients/jedis/commands/commandobjects/Person.java @@ -0,0 +1,49 @@ +package redis.clients.jedis.commands.commandobjects; + +import java.util.Objects; + +/** + * Bean class used for testing Redis JSON commands. + */ +public class Person { + + private String name; + private int age; + + public Person() { + } + + public Person(String name, int age) { + this.name = name; + this.age = age; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public int getAge() { + return age; + } + + public void setAge(int age) { + this.age = age; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + Person person = (Person) o; + return age == person.age && Objects.equals(name, person.name); + } + + @Override + public int hashCode() { + return Objects.hash(name, age); + } +} From 2d42338fcb0f5c7a264b6ee468aecfb137a63613 Mon Sep 17 00:00:00 2001 From: M Sazzadul Hoque <7600764+sazzad16@users.noreply.github.com> Date: Wed, 3 Apr 2024 21:14:11 +0600 Subject: [PATCH 33/33] Deprecate unused JSON.ARRAPPEND in CommandObjects (#3798) Update CommandObjects.java --- src/main/java/redis/clients/jedis/CommandObjects.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/redis/clients/jedis/CommandObjects.java b/src/main/java/redis/clients/jedis/CommandObjects.java index 139fa78ae8f..896ef38293b 100644 --- a/src/main/java/redis/clients/jedis/CommandObjects.java +++ b/src/main/java/redis/clients/jedis/CommandObjects.java @@ -3623,6 +3623,7 @@ public final CommandObject jsonNumIncrBy(String key, Path path, double v return new CommandObject<>(commandArguments(JsonCommand.NUMINCRBY).key(key).add(path).add(value), BuilderFactory.DOUBLE); } + @Deprecated public final CommandObject jsonArrAppend(String key, String path, JSONObject... objects) { CommandArguments args = commandArguments(JsonCommand.ARRAPPEND).key(key).add(path); for (Object object : objects) {