diff --git a/src/main/java/redis/clients/jedis/UnifiedJedis.java b/src/main/java/redis/clients/jedis/UnifiedJedis.java index 42aa67ae74..5c7b6e161f 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 2d096ba570..0000000000 --- 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 0000000000..bb125cc28d --- /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 0000000000..8127c417bc --- /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 0000000000..a96690f19b --- /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 0000000000..6525e521e1 --- /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 0000000000..e594ce1aad --- /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 0000000000..85a26029c7 --- /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 0000000000..1e79ec87a9 --- /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 0000000000..114bc07dc0 --- /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 0000000000..7a16176e54 --- /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 0000000000..b23cee6da2 --- /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 0000000000..d5b59b99a4 --- /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 0000000000..aabb6ca5a1 --- /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 0000000000..a43d80a138 --- /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 0000000000..d712a5cdd4 --- /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 0000000000..e2ceac54df --- /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 0000000000..a5aa8dc7ea --- /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 0000000000..4ac820d693 --- /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 0000000000..2a7365dace --- /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 0000000000..694461a5a8 --- /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 0000000000..3e3958abb1 --- /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 0000000000..ff010f6e53 --- /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 0000000000..6fdd1f10dd --- /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 0000000000..1e2b29f9a1 --- /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 0000000000..44e653c011 --- /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 0000000000..b652c0df25 --- /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 0000000000..86492b49da --- /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 0000000000..cafb2d2c83 --- /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 0000000000..dc795765ee --- /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 0000000000..8397d35f59 --- /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 0000000000..d0e463aaf2 --- /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 0000000000..c3c0d38442 --- /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 0000000000..a6f8b8ac83 --- /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 0000000000..c867e4d3e5 --- /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 0000000000..f7e1cc4b3c --- /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 0000000000..2ce1009dec --- /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 0000000000..1eec5a5896 --- /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 0000000000..55fb55b5cd --- /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 0000000000..ee5db61255 --- /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 0000000000..8ab868ad41 --- /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 0000000000..1f6d9d6363 --- /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 0000000000..3dc85aa201 --- /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 0000000000..3fe180baeb --- /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 0000000000..2dea520ea8 --- /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 0000000000..404476788f --- /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 0000000000..7d1e4f1bfd --- /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 0000000000..4ccec8c1c7 --- /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 0000000000..d9e06ce77c --- /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 0000000000..e629f80bd9 --- /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 0000000000..5dec794c65 --- /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); + } + +}