diff --git a/src/main/java/org/springframework/data/redis/connection/DefaultStringRedisConnection.java b/src/main/java/org/springframework/data/redis/connection/DefaultStringRedisConnection.java index d6ab7eae4..6ca890265 100644 --- a/src/main/java/org/springframework/data/redis/connection/DefaultStringRedisConnection.java +++ b/src/main/java/org/springframework/data/redis/connection/DefaultStringRedisConnection.java @@ -300,15 +300,15 @@ public class DefaultStringRedisConnection implements StringRedisConnection, Deco */ @Override public Long exists(String... keys) { - return convertAndReturn(delegate.exists(Arrays.asList(serializeMulti(keys))), identityConverter); + return convertAndReturn(delegate.exists(serializeMulti(keys)), identityConverter); } /* * (non-Javadoc) - * @see org.springframework.data.redis.connection.RedisKeyCommands#exists(java.util.Collection) + * @see org.springframework.data.redis.connection.RedisKeyCommands#exists(byte[][]) */ @Override - public Long exists(Collection keys) { + public Long exists(byte[]... keys) { return convertAndReturn(delegate.exists(keys), identityConverter); } diff --git a/src/main/java/org/springframework/data/redis/connection/DefaultedRedisConnection.java b/src/main/java/org/springframework/data/redis/connection/DefaultedRedisConnection.java index 049f06d2f..3fa2358ee 100644 --- a/src/main/java/org/springframework/data/redis/connection/DefaultedRedisConnection.java +++ b/src/main/java/org/springframework/data/redis/connection/DefaultedRedisConnection.java @@ -15,7 +15,6 @@ */ package org.springframework.data.redis.connection; -import java.util.Collection; import java.util.List; import java.util.Map; import java.util.Map.Entry; @@ -58,7 +57,7 @@ public interface DefaultedRedisConnection extends RedisConnection { /** @deprecated in favor of {@link RedisConnection#keyCommands()}. */ @Override @Deprecated - default Long exists(Collection keys) { + default Long exists(byte[]... keys) { return keyCommands().exists(keys); } diff --git a/src/main/java/org/springframework/data/redis/connection/RedisKeyCommands.java b/src/main/java/org/springframework/data/redis/connection/RedisKeyCommands.java index c691280b7..aad3ceb4d 100644 --- a/src/main/java/org/springframework/data/redis/connection/RedisKeyCommands.java +++ b/src/main/java/org/springframework/data/redis/connection/RedisKeyCommands.java @@ -15,8 +15,6 @@ */ package org.springframework.data.redis.connection; -import java.util.Collection; -import java.util.Collections; import java.util.List; import java.util.Set; import java.util.concurrent.TimeUnit; @@ -46,20 +44,21 @@ public interface RedisKeyCommands { default Boolean exists(byte[] key) { Assert.notNull(key, "Key must not be null!"); - Long count = exists(Collections.singleton(key)); + Long count = exists(new byte[][] { key }); return count != null ? count > 0 : null; } /** - * Count how many of the given {@code keys} exists. Providing the very same {@code key} more than once also counts + * Count how many of the given {@code keys} exist. Providing the very same {@code key} more than once also counts * multiple times. * * @param keys must not be {@literal null}. - * @return the number of keys existing among the ones specified as arguments. + * @return the number of keys existing among the ones specified as arguments. {@literal null} when used in pipeline / + * transaction. * @since 2.1 */ @Nullable - Long exists(Collection keys); + Long exists(byte[]... keys); /** * Delete given {@code keys}. diff --git a/src/main/java/org/springframework/data/redis/connection/StringRedisConnection.java b/src/main/java/org/springframework/data/redis/connection/StringRedisConnection.java index 26a5b1d0c..d0002ea22 100644 --- a/src/main/java/org/springframework/data/redis/connection/StringRedisConnection.java +++ b/src/main/java/org/springframework/data/redis/connection/StringRedisConnection.java @@ -92,12 +92,12 @@ public interface StringRedisConnection extends RedisConnection { Boolean exists(String key); /** - * Count how many of the if given {@code keys} exists. + * Count how many of the given {@code keys} exist. * * @param keys must not be {@literal null}. * @return * @see Redis Documentation: EXISTS - * @see RedisKeyCommands#exists(java.util.Collection) + * @see RedisKeyCommands#exists(byte[][]) * @since 2.1 */ @Nullable diff --git a/src/main/java/org/springframework/data/redis/connection/jedis/JedisClusterKeyCommands.java b/src/main/java/org/springframework/data/redis/connection/jedis/JedisClusterKeyCommands.java index f1cf5e00d..47c36790a 100644 --- a/src/main/java/org/springframework/data/redis/connection/jedis/JedisClusterKeyCommands.java +++ b/src/main/java/org/springframework/data/redis/connection/jedis/JedisClusterKeyCommands.java @@ -15,6 +15,8 @@ */ package org.springframework.data.redis.connection.jedis; +import redis.clients.jedis.BinaryJedis; + import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; @@ -62,7 +64,8 @@ class JedisClusterKeyCommands implements RedisKeyCommands { @Override public Long del(byte[]... keys) { - Assert.noNullElements(keys, "Keys must not be null or contain null key!"); + Assert.notNull(keys, "Keys must not be null!"); + Assert.noNullElements(keys, "Keys must not contain null elements!"); if (ClusterSlotHashUtil.isSameSlotForAllKeys(keys)) { try { @@ -473,26 +476,26 @@ class JedisClusterKeyCommands implements RedisKeyCommands { /* * (non-Javadoc) - * @see org.springframework.data.redis.connection.RedisKeyCommands#exists(java.util.Collection) + * @see org.springframework.data.redis.connection.RedisKeyCommands#exists(byte[][]) */ @Nullable @Override - public Long exists(Collection keys) { + public Long exists(byte[]... keys) { Assert.notNull(keys, "Keys must not be null!"); + Assert.noNullElements(keys, "Keys must not contain null elements!"); - try { - - return keys.stream() // - .parallel() - .map(key -> connection.getClusterCommandExecutor() - .executeCommandOnSingleNode((JedisClusterCommandCallback) client -> client.exists(key), - connection.getTopologyProvider().getTopology().getKeyServingMasterNode(key)) - .getValue()) - .mapToLong(val -> ObjectUtils.nullSafeEquals(val, Boolean.TRUE) ? 1L : 0L).sum(); - } catch (Exception ex) { - throw convertJedisAccessException(ex); + if (ClusterSlotHashUtil.isSameSlotForAllKeys(keys)) { + try { + return connection.getCluster().exists(keys); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } } + + return connection.getClusterCommandExecutor() + .executeMultiKeyCommand((JedisMultiKeyClusterCommandCallback) BinaryJedis::exists, Arrays.asList(keys)) + .resultsAsList().stream().mapToLong(val -> ObjectUtils.nullSafeEquals(val, Boolean.TRUE) ? 1 : 0).sum(); } private DataAccessException convertJedisAccessException(Exception ex) { diff --git a/src/main/java/org/springframework/data/redis/connection/jedis/JedisKeyCommands.java b/src/main/java/org/springframework/data/redis/connection/jedis/JedisKeyCommands.java index 4f76ed01b..f87c396ab 100644 --- a/src/main/java/org/springframework/data/redis/connection/jedis/JedisKeyCommands.java +++ b/src/main/java/org/springframework/data/redis/connection/jedis/JedisKeyCommands.java @@ -20,7 +20,6 @@ import lombok.RequiredArgsConstructor; import redis.clients.jedis.ScanParams; import redis.clients.jedis.SortingParams; -import java.util.Collection; import java.util.List; import java.util.Set; import java.util.concurrent.TimeUnit; @@ -73,26 +72,27 @@ class JedisKeyCommands implements RedisKeyCommands { /* * (non-Javadoc) - * @see org.springframework.data.redis.connection.RedisKeyCommands#exists(java.util.Collection) + * @see org.springframework.data.redis.connection.RedisKeyCommands#exists(byte[][]) */ @Nullable @Override - public Long exists(Collection keys) { + public Long exists(byte[]... keys) { Assert.notNull(keys, "Keys must not be null!"); + Assert.noNullElements(keys, "Keys must not contain null elements!"); try { if (isPipelined()) { pipeline( - connection.newJedisResult(connection.getRequiredPipeline().exists(keys.toArray(new byte[keys.size()][])))); + connection.newJedisResult(connection.getRequiredPipeline().exists(keys))); return null; } if (isQueueing()) { transaction(connection - .newJedisResult(connection.getRequiredTransaction().exists(keys.toArray(new byte[keys.size()][])))); + .newJedisResult(connection.getRequiredTransaction().exists(keys))); return null; } - return connection.getJedis().exists(keys.toArray(new byte[keys.size()][])); + return connection.getJedis().exists(keys); } catch (Exception ex) { throw connection.convertJedisAccessException(ex); } diff --git a/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceKeyCommands.java b/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceKeyCommands.java index 90fe6182c..5ccefb7ae 100644 --- a/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceKeyCommands.java +++ b/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceKeyCommands.java @@ -23,7 +23,6 @@ import io.lettuce.core.cluster.api.sync.RedisClusterCommands; import lombok.NonNull; import lombok.RequiredArgsConstructor; -import java.util.Collection; import java.util.List; import java.util.Set; import java.util.concurrent.TimeUnit; @@ -80,24 +79,25 @@ class LettuceKeyCommands implements RedisKeyCommands { /* * (non-Javadoc) - * @see org.springframework.data.redis.connection.RedisKeyCommands#exists(java.util.Collection) + * @see org.springframework.data.redis.connection.RedisKeyCommands#exists(byte[][]) */ @Nullable @Override - public Long exists(Collection keys) { + public Long exists(byte[]... keys) { Assert.notNull(keys, "Keys must not be null!"); + Assert.noNullElements(keys, "Keys must not contain null elements!"); try { if (isPipelined()) { - pipeline(connection.newLettuceResult(getAsyncConnection().exists(keys.toArray(new byte[keys.size()][])))); + pipeline(connection.newLettuceResult(getAsyncConnection().exists(keys))); return null; } if (isQueueing()) { - transaction(connection.newLettuceTxResult(getAsyncConnection().exists(keys.toArray(new byte[keys.size()][])))); + transaction(connection.newLettuceTxResult(getAsyncConnection().exists(keys))); return null; } - return getConnection().exists(keys.toArray(new byte[keys.size()][])); + return getConnection().exists(keys); } catch (Exception ex) { throw convertLettuceAccessException(ex); } diff --git a/src/main/java/org/springframework/data/redis/core/RedisOperations.java b/src/main/java/org/springframework/data/redis/core/RedisOperations.java index 3ce8ca55f..2f0f11a97 100644 --- a/src/main/java/org/springframework/data/redis/core/RedisOperations.java +++ b/src/main/java/org/springframework/data/redis/core/RedisOperations.java @@ -163,7 +163,7 @@ public interface RedisOperations { Boolean hasKey(K key); /** - * Count the number of {@code keys} that exists. + * Count the number of {@code keys} that exist. * * @param keys must not be {@literal null}. * @return The number of keys existing among the ones specified as arguments. Keys mentioned multiple times and diff --git a/src/main/java/org/springframework/data/redis/core/RedisTemplate.java b/src/main/java/org/springframework/data/redis/core/RedisTemplate.java index 644278aec..4d867774f 100644 --- a/src/main/java/org/springframework/data/redis/core/RedisTemplate.java +++ b/src/main/java/org/springframework/data/redis/core/RedisTemplate.java @@ -18,7 +18,6 @@ package org.springframework.data.redis.core; import java.io.Closeable; import java.lang.reflect.Proxy; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.Date; @@ -750,7 +749,7 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation Assert.notNull(keys, "Keys must not be null!"); byte[][] rawKeys = rawKeys(keys); - return execute(connection -> connection.exists(Arrays.asList(rawKeys)), true); + return execute(connection -> connection.exists(rawKeys), true); } /* @@ -1327,7 +1326,7 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation * Set the {@link ClassLoader} to be used for the default {@link JdkSerializationRedisSerializer} in case no other * {@link RedisSerializer} is explicitly set as the default one. * - * @param resourceLoader can be {@literal null}. + * @param classLoader can be {@literal null}. * @see org.springframework.beans.factory.BeanClassLoaderAware#setBeanClassLoader * @since 1.8 */ diff --git a/src/test/java/org/springframework/data/redis/connection/ClusterConnectionTests.java b/src/test/java/org/springframework/data/redis/connection/ClusterConnectionTests.java index fc073be43..4f9a6a91d 100644 --- a/src/test/java/org/springframework/data/redis/connection/ClusterConnectionTests.java +++ b/src/test/java/org/springframework/data/redis/connection/ClusterConnectionTests.java @@ -27,179 +27,14 @@ public interface ClusterConnectionTests { Point POINT_CATANIA = new Point(15.087269, 37.502669); Point POINT_PALERMO = new Point(13.361389, 38.115556); - // DATAREDIS-315 - void shouldAllowSettingAndGettingValues(); - - // DATAREDIS-315 - void delShouldRemoveSingleKeyCorrectly(); - - // DATAREDIS-315 - void delShouldRemoveMultipleKeysCorrectly(); - - // DATAREDIS-315 - void delShouldRemoveMultipleKeysOnSameSlotCorrectly(); - - // DATAREDIS-315 - void typeShouldReadKeyTypeCorrectly(); - - // DATAREDIS-315 - void keysShouldReturnAllKeys(); - - // DATAREDIS-315 - void keysShouldReturnAllKeysForSpecificNode(); - - // DATAREDIS-315 - void randomKeyShouldReturnCorrectlyWhenKeysAvailable(); - - // DATAREDIS-315 - void randomKeyShouldReturnNullWhenNoKeysAvailable(); - - // DATAREDIS-315 - void rename(); - - // DATAREDIS-315 - void renameSameKeysOnSameSlot(); - - // DATAREDIS-315 - void renameNXWhenTargetKeyDoesNotExist(); - - // DATAREDIS-315 - void renameNXWhenTargetKeyDoesExist(); - - // DATAREDIS-315 - void renameNXWhenOnSameSlot(); - - // DATAREDIS-315 - void expireShouldBeSetCorreclty(); - - // DATAREDIS-315 - void pExpireShouldBeSetCorreclty(); - - // DATAREDIS-315 - void expireAtShouldBeSetCorrectly(); - - // DATAREDIS-315 - void pExpireAtShouldBeSetCorrectly(); - - // DATAREDIS-315 - void persistShouldRemoveTTL(); - - // DATAREDIS-315 - void moveShouldNotBeSupported(); - - // DATAREDIS-315 - void dbSizeShouldReturnCummulatedDbSize(); - - // DATAREDIS-315 - void dbSizeForSpecificNodeShouldGetNodeDbSize(); - - // DATAREDIS-315 - void ttlShouldReturnMinusTwoWhenKeyDoesNotExist(); - - // DATAREDIS-526 - void ttlWithTimeUnitShouldReturnMinusTwoWhenKeyDoesNotExist(); - - // DATAREDIS-315 - void ttlShouldReturnMinusOneWhenKeyDoesNotHaveExpirationSet(); - - // DATAREDIS-315 - void ttlShouldReturnValueCorrectly(); - - // DATAREDIS-315 - void pTtlShouldReturnMinusTwoWhenKeyDoesNotExist(); - - // DATAREDIS-526 - void pTtlWithTimeUnitShouldReturnMinusTwoWhenKeyDoesNotExist(); - - // DATAREDIS-315 - void pTtlShouldReturnMinusOneWhenKeyDoesNotHaveExpirationSet(); - - // DATAREDIS-315 - void pTtlShouldReturValueCorrectly(); - - // DATAREDIS-315 - void sortShouldReturnValuesCorrectly(); - - // DATAREDIS-315 - void sortAndStoreShouldAddSortedValuesValuesCorrectly(); - - // DATAREDIS-315 - void sortAndStoreShouldReturnZeroWhenListDoesNotExist(); - - // DATAREDIS-315 - void dumpAndRestoreShouldWorkCorrectly(); - - // DATAREDIS-315 - void getShouldReturnValueCorrectly(); - - // DATAREDIS-315 - void getSetShouldWorkCorrectly(); - - // DATAREDIS-315 - void mGetShouldReturnCorrectlyWhenKeysMapToSameSlot(); - - // DATAREDIS-315 - void mGetShouldReturnCorrectlyWhenKeysDoNotMapToSameSlot(); - - // DATAREDIS-315 - void setShouldSetValueCorrectly(); - - // DATAREDIS-315 - void setNxShouldSetValueCorrectly(); - - // DATAREDIS-315 - void setNxShouldNotSetValueWhenAlreadyExistsInDBCorrectly(); - - // DATAREDIS-315 - void setExShouldSetValueCorrectly(); - - // DATAREDIS-315 - void pSetExShouldSetValueCorrectly(); - - // DATAREDIS-315 - void mSetShouldWorkWhenKeysMapToSameSlot(); - - // DATAREDIS-315 - void mSetShouldWorkWhenKeysDoNotMapToSameSlot(); - - // DATAREDIS-315 - void mSetNXShouldReturnTrueIfAllKeysSet(); - - // DATAREDIS-315 - void mSetNXShouldReturnFalseIfNotAllKeysSet(); - - // DATAREDIS-315 - void mSetNXShouldWorkForOnSameSlotKeys(); - - // DATAREDIS-315 - void incrShouldIncreaseValueCorrectly(); - - // DATAREDIS-315 - void incrByShouldIncreaseValueCorrectly(); - - // DATAREDIS-315 - void incrByFloatShouldIncreaseValueCorrectly(); - - // DATAREDIS-315 - void decrShouldDecreaseValueCorrectly(); - - // DATAREDIS-315 - void decrByShouldDecreaseValueCorrectly(); - // DATAREDIS-315 void appendShouldAddValueCorrectly(); // DATAREDIS-315 - void getRangeShouldReturnValueCorrectly(); + void bRPopLPushShouldWork(); // DATAREDIS-315 - void setRangeShouldWorkCorrectly(); - - // DATAREDIS-315 - void getBitShouldWorkCorrectly(); - - // DATAREDIS-315 - void setBitShouldWorkCorrectly(); + void bRPopLPushShouldWorkOnSameSlotKeys(); // DATAREDIS-315 void bitCountShouldWorkCorrectly(); @@ -210,48 +45,6 @@ public interface ClusterConnectionTests { // DATAREDIS-315 void bitOpShouldThrowExceptionWhenKeysDoNotMapToSameSlot(); - // DATAREDIS-315 - void strLenShouldWorkCorrectly(); - - // DATAREDIS-315 - void rPushShoultAddValuesCorrectly(); - - // DATAREDIS-315 - void lPushShoultAddValuesCorrectly(); - - // DATAREDIS-315 - void rPushNXShoultNotAddValuesWhenKeyDoesNotExist(); - - // DATAREDIS-315 - void lPushNXShoultNotAddValuesWhenKeyDoesNotExist(); - - // DATAREDIS-315 - void lLenShouldCountValuesCorrectly(); - - // DATAREDIS-315 - void lRangeShouldGetValuesCorrectly(); - - // DATAREDIS-315 - void lTrimShouldTrimListCorrectly(); - - // DATAREDIS-315 - void lIndexShouldGetElementAtIndexCorrectly(); - - // DATAREDIS-315 - void lInsertShouldAddElementAtPositionCorrectly(); - - // DATAREDIS-315 - void lSetShouldSetElementAtPositionCorrectly(); - - // DATAREDIS-315 - void lRemShouldRemoveElementAtPositionCorrectly(); - - // DATAREDIS-315 - void lPopShouldReturnElementCorrectly(); - - // DATAREDIS-315 - void rPopShouldReturnElementCorrectly(); - // DATAREDIS-315 void blPopShouldPopElementCorectly(); @@ -264,337 +57,78 @@ public interface ClusterConnectionTests { // DATAREDIS-315 void brPopShouldPopElementCorectlyWhenKeyOnSameSlot(); - // DATAREDIS-315 - void rPopLPushShouldWorkWhenDoNotMapToSameSlot(); - - // DATAREDIS-315 - public void rPopLPushShouldWorkWhenKeysOnSameSlot(); - - // DATAREDIS-315 - void bRPopLPushShouldWork(); - - // DATAREDIS-315 - void bRPopLPushShouldWorkOnSameSlotKeys(); - - // DATAREDIS-315 - void sAddShouldAddValueToSetCorrectly(); - - // DATAREDIS-315 - void sRemShouldRemoveValueFromSetCorrectly(); - - // DATAREDIS-315 - void sPopShouldPopValueFromSetCorrectly(); - - // DATAREDIS-315 - void sMoveShouldWorkWhenKeysMapToSameSlot(); - - // DATAREDIS-315 - void sMoveShouldWorkWhenKeysDoNotMapToSameSlot(); - - // DATAREDIS-315 - void sCardShouldCountValuesInSetCorrectly(); - - // DATAREDIS-315 - void sIsMemberShouldReturnTrueIfValueIsMemberOfSet(); - - // DATAREDIS-315 - void sIsMemberShouldReturnFalseIfValueIsMemberOfSet(); - - // DATAREDIS-315 - void sInterShouldWorkForKeysMappingToSameSlot(); - - // DATAREDIS-315 - void sInterShouldWorkForKeysNotMappingToSameSlot(); - - // DATAREDIS-315 - void sInterStoreShouldWorkForKeysMappingToSameSlot(); - - // DATAREDIS-315 - void sInterStoreShouldWorkForKeysNotMappingToSameSlot(); - - // DATAREDIS-315 - void sUnionShouldWorkForKeysMappingToSameSlot(); - - // DATAREDIS-315 - void sUnionShouldWorkForKeysNotMappingToSameSlot(); - - // DATAREDIS-315 - void sUnionStoreShouldWorkForKeysMappingToSameSlot(); - - // DATAREDIS-315 - void sUnionStoreShouldWorkForKeysNotMappingToSameSlot(); - - // DATAREDIS-315 - void sDiffShouldWorkWhenKeysMapToSameSlot(); - - // DATAREDIS-315 - void sDiffShouldWorkWhenKeysNotMapToSameSlot(); - - // DATAREDIS-315 - void sDiffStoreShouldWorkWhenKeysMapToSameSlot(); - - // DATAREDIS-315 - void sDiffStoreShouldWorkWhenKeysNotMapToSameSlot(); - - // DATAREDIS-315 - void sMembersShouldReturnValuesContainedInSetCorrectly(); - - // DATAREDIS-315 - void sRandMamberShouldReturnValueCorrectly(); - - // DATAREDIS-315 - void sRandMamberWithCountShouldReturnValueCorrectly(); - - // DATAREDIS-315 - void sscanShouldRetrieveAllValuesInSetCorrectly(); - - // DATAREDIS-315 - void zAddShouldAddValueWithScoreCorrectly(); - - // DATAREDIS-315 - void zRemShouldRemoveValueWithScoreCorrectly(); - - // DATAREDIS-315 - void zIncrByShouldIncScoreForValueCorrectly(); - - // DATAREDIS-315 - void zRankShouldReturnPositionForValueCorrectly(); - - // DATAREDIS-315 - void zRankShouldReturnReversePositionForValueCorrectly(); - - // DATAREDIS-315 - void zRangeShouldReturnValuesCorrectly(); - - // DATAREDIS-315 - void zRangeWithScoresShouldReturnValuesAndScoreCorrectly(); - - // DATAREDIS-315 - void zRangeByScoreShouldReturnValuesCorrectly(); - - // DATAREDIS-315 - void zRangeByScoreWithScoresShouldReturnValuesAndScoreCorrectly(); - - // DATAREDIS-315 - void zRangeByScoreShouldReturnValuesCorrectlyWhenGivenOffsetAndScore(); - - // DATAREDIS-315 - void zRangeByScoreWithScoresShouldReturnValuesCorrectlyWhenGivenOffsetAndScore(); - - // DATAREDIS-315 - void zRevRangeShouldReturnValuesCorrectly(); - - // DATAREDIS-315 - void zRevRangeWithScoresShouldReturnValuesAndScoreCorrectly(); - - // DATAREDIS-315 - void zRevRangeByScoreShouldReturnValuesCorrectly(); - - // DATAREDIS-315 - void zRevRangeByScoreWithScoresShouldReturnValuesAndScoreCorrectly(); - - // DATAREDIS-315 - void zRevRangeByScoreShouldReturnValuesCorrectlyWhenGivenOffsetAndScore(); - - // DATAREDIS-315 - void zRevRangeByScoreWithScoresShouldReturnValuesCorrectlyWhenGivenOffsetAndScore(); - - // DATAREDIS-315 - void zCountShouldCountValuesInRange(); - - // DATAREDIS-315 - void zCardShouldReturnTotalNumberOfValues(); - - // DATAREDIS-315 - void zScoreShouldRetrieveScoreForValue(); - - // DATAREDIS-315 - void zRemRangeShouldRemoveValues(); - - // DATAREDIS-315 - void zRemRangeByScoreShouldRemoveValues(); - - // DATAREDIS-315 - void zUnionStoreShouldWorkForSameSlotKeys(); - - // DATAREDIS-315 - void zUnionStoreShouldThrowExceptionWhenKeysDoNotMapToSameSlots(); - - // DATAREDIS-315 - void zInterStoreShouldWorkForSameSlotKeys(); - - // DATAREDIS-315 - void zInterStoreShouldThrowExceptionWhenKeysDoNotMapToSameSlots(); - - // DATAREDIS-479 - void zScanShouldReadEntireValueRange(); - - // DATAREDIS-315 - void hSetShouldSetValueCorrectly(); - - // DATAREDIS-315 - void hSetNXShouldSetValueCorrectly(); - - // DATAREDIS-315 - void hSetNXShouldNotSetValueWhenAlreadyExists(); - - // DATAREDIS-315 - void hGetShouldRetrieveValueCorrectly(); - - // DATAREDIS-315 - void hMGetShouldRetrieveValueCorrectly(); - - // DATAREDIS-315 - void hMSetShouldAddValuesCorrectly(); - - // DATAREDIS-315 - void hIncrByShouldIncreaseFieldCorretly(); - - // DATAREDIS-315 - void hIncrByFloatShouldIncreaseFieldCorretly(); - - // DATAREDIS-315 - void hExistsShouldReturnPresenceOfFieldCorrectly(); - - // DATAREDIS-315 - void hDelShouldRemoveFieldsCorrectly(); - - // DATAREDIS-315 - void hLenShouldRetrieveSizeCorrectly(); - - // DATAREDIS-315 - void hKeysShouldRetrieveKeysCorrectly(); - - // DATAREDIS-315 - void hValsShouldRetrieveValuesCorrectly(); - - // DATAREDIS-315 - void hGetAllShouldRetrieveEntriesCorrectly(); - - // DATAREDIS-479 - public void hScanShouldReadEntireValueRange(); - - // DATAREDIS-315 - void multiShouldThrowException(); - - // DATAREDIS-315 - void execShouldThrowException(); - - // DATAREDIS-315 - void discardShouldThrowException(); - - // DATAREDIS-315 - void watchShouldThrowException(); - - // DATAREDIS-315 - void unwatchShouldThrowException(); - - // DATAREDIS-315 - void selectShouldAllowSelectionOfDBIndexZero(); - - // DATAREDIS-315 - void selectShouldThrowExceptionWhenSelectingNonZeroDbIndex(); - - // DATAREDIS-315 - void echoShouldReturnInputCorrectly(); - - // DATAREDIS-315 - void pingShouldRetrunPongForExistingNode(); - - // DATAREDIS-315 - void pingShouldRetrunPong(); - - // DATAREDIS-315 - void pingShouldThrowExceptionWhenNodeNotKnownToCluster(); - - // DATAREDIS-315 - void flushDbShouldFlushAllClusterNodes(); - - // DATAREDIS-315 - void flushDbOnSingleNodeShouldFlushOnlyGivenNodesDb(); - - // DATAREDIS-315 - void zRangeByLexShouldReturnResultCorrectly(); - - // DATAREDIS-315 - void infoShouldCollectionInfoFromAllClusterNodes(); - // DATAREDIS-315 void clientListShouldGetInfosForAllClients(); // DATAREDIS-315 - void getClusterNodeForKeyShouldReturnNodeCorrectly(); - - // DATAREDIS-315 - void countKeysShouldReturnNumberOfKeysInSlot(); - - // DATAREDIS-315 - - void pfAddShouldAddValuesCorrectly(); - - // DATAREDIS-315 - void pfCountShouldAllowCountingOnSingleKey(); - - // DATAREDIS-315 - void pfCountShouldAllowCountingOnSameSlotKeys(); - - // DATAREDIS-315 - void pfCountShouldThrowErrorCountingOnDifferentSlotKeys(); - - // DATAREDIS-315 - void pfMergeShouldWorkWhenAllKeysMapToSameSlot(); - - // DATAREDIS-315 - public void pfMergeShouldThrowErrorOnDifferentSlotKeys(); - - // DATAREDIS-315 - void infoShouldCollectInfoForSpecificNode(); - - // DATAREDIS-315 - void infoShouldCollectInfoForSpecificNodeAndSection(); - - // DATAREDIS-315 - void getConfigShouldLoadCumulatedConfiguration(); - - // DATAREDIS-315 - void getConfigShouldLoadConfigurationOfSpecificNode(); + void clusterGetMasterSlaveMapShouldListMastersAndSlavesCorrectly(); // DATAREDIS-315 void clusterGetSlavesShouldReturnSlaveCorrectly(); // DATAREDIS-315 - void clusterGetMasterSlaveMapShouldListMastersAndSlavesCorrectly(); + void countKeysShouldReturnNumberOfKeysInSlot(); - // DATAREDIS-316 - void setWithExpirationInSecondsShouldWorkCorrectly(); + // DATAREDIS-315 + void dbSizeForSpecificNodeShouldGetNodeDbSize(); - // DATAREDIS-316 - void setWithExpirationInMillisecondsShouldWorkCorrectly(); + // DATAREDIS-315 + void dbSizeShouldReturnCummulatedDbSize(); - // DATAREDIS-316 - void setWithOptionIfPresentShouldWorkCorrectly(); + // DATAREDIS-315 + void decrByShouldDecreaseValueCorrectly(); - // DATAREDIS-316 - void setWithOptionIfAbsentShouldWorkCorrectly(); + // DATAREDIS-315 + void decrShouldDecreaseValueCorrectly(); - // DATAREDIS-316 - void setWithExpirationAndIfAbsentShouldWorkCorrectly(); + // DATAREDIS-315 + void delShouldRemoveMultipleKeysCorrectly(); - // DATAREDIS-316 - void setWithExpirationAndIfAbsentShouldNotBeAppliedWhenKeyExists(); + // DATAREDIS-315 + void delShouldRemoveMultipleKeysOnSameSlotCorrectly(); - // DATAREDIS-316 - void setWithExpirationAndIfPresentShouldWorkCorrectly(); + // DATAREDIS-315 + void delShouldRemoveSingleKeyCorrectly(); - // DATAREDIS-316 - void setWithExpirationAndIfPresentShouldNotBeAppliedWhenKeyDoesNotExists(); + // DATAREDIS-315 + void discardShouldThrowException(); - // DATAREDIS-438 - void geoAddSingleGeoLocation(); + // DATAREDIS-315 + void dumpAndRestoreShouldWorkCorrectly(); + + // DATAREDIS-315 + void echoShouldReturnInputCorrectly(); + + // DATAREDIS-315 + void execShouldThrowException(); + + // DATAREDIS-529 + void existsShouldCountSameKeyMultipleTimes(); + + // DATAREDIS-529 + void existsWithMultipleKeysShouldConsiderAbsentKeys(); + + // DATAREDIS-529 + void existsWithMultipleKeysShouldReturnResultCorrectly(); + + // DATAREDIS-315 + void expireAtShouldBeSetCorrectly(); + + // DATAREDIS-315 + void expireShouldBeSetCorreclty(); + + // DATAREDIS-315 + void flushDbOnSingleNodeShouldFlushOnlyGivenNodesDb(); + + // DATAREDIS-315 + void flushDbShouldFlushAllClusterNodes(); // DATAREDIS-438 void geoAddMultipleGeoLocations(); + // DATAREDIS-438 + void geoAddSingleGeoLocation(); + // DATAREDIS-438 void geoDist(); @@ -614,26 +148,89 @@ public interface ClusterConnectionTests { void geoPositionNonExisting(); // DATAREDIS-438 - void geoRadiusShouldReturnMembersCorrectly(); - - // DATAREDIS-438 - void geoRadiusShouldReturnDistanceCorrectly(); - - // DATAREDIS-438 - void geoRadiusShouldApplyLimit(); - - // DATAREDIS-438 - void geoRadiusByMemberShouldReturnMembersCorrectly(); + void geoRadiusByMemberShouldApplyLimit(); // DATAREDIS-438 void geoRadiusByMemberShouldReturnDistanceCorrectly(); // DATAREDIS-438 - void geoRadiusByMemberShouldApplyLimit(); + void geoRadiusByMemberShouldReturnMembersCorrectly(); + + // DATAREDIS-438 + void geoRadiusShouldApplyLimit(); + + // DATAREDIS-438 + void geoRadiusShouldReturnDistanceCorrectly(); + + // DATAREDIS-438 + void geoRadiusShouldReturnMembersCorrectly(); // DATAREDIS-438 void geoRemoveDeletesMembers(); + // DATAREDIS-315 + void getBitShouldWorkCorrectly(); + + // DATAREDIS-315 + void getClusterNodeForKeyShouldReturnNodeCorrectly(); + + // DATAREDIS-315 + void getConfigShouldLoadConfigurationOfSpecificNode(); + + // DATAREDIS-315 + void getConfigShouldLoadCumulatedConfiguration(); + + // DATAREDIS-315 + void getRangeShouldReturnValueCorrectly(); + + // DATAREDIS-315 + void getSetShouldWorkCorrectly(); + + // DATAREDIS-315 + void getShouldReturnValueCorrectly(); + + // DATAREDIS-315 + void hDelShouldRemoveFieldsCorrectly(); + + // DATAREDIS-315 + void hExistsShouldReturnPresenceOfFieldCorrectly(); + + // DATAREDIS-315 + void hGetAllShouldRetrieveEntriesCorrectly(); + + // DATAREDIS-315 + void hGetShouldRetrieveValueCorrectly(); + + // DATAREDIS-315 + void hIncrByFloatShouldIncreaseFieldCorretly(); + + // DATAREDIS-315 + void hIncrByShouldIncreaseFieldCorretly(); + + // DATAREDIS-315 + void hKeysShouldRetrieveKeysCorrectly(); + + // DATAREDIS-315 + void hLenShouldRetrieveSizeCorrectly(); + + // DATAREDIS-315 + void hMGetShouldRetrieveValueCorrectly(); + + // DATAREDIS-315 + void hMSetShouldAddValuesCorrectly(); + + // DATAREDIS-479 + public void hScanShouldReadEntireValueRange(); + + // DATAREDIS-315 + void hSetNXShouldNotSetValueWhenAlreadyExists(); + + // DATAREDIS-315 + void hSetNXShouldSetValueCorrectly(); + + // DATAREDIS-315 + void hSetShouldSetValueCorrectly(); + // DATAREDIS-698 void hStrLenReturnsFieldLength(); @@ -643,13 +240,416 @@ public interface ClusterConnectionTests { // DATAREDIS-698 void hStrLenReturnsZeroWhenKeyDoesNotExist(); - // DATAREDIS-529 - void testExistsWithMultipleKeys(); + // DATAREDIS-315 + void hValsShouldRetrieveValuesCorrectly(); - // DATAREDIS-529 - void testExistsWithMultipleKeysNoneExists(); + // DATAREDIS-315 + void incrByFloatShouldIncreaseValueCorrectly(); - // DATAREDIS-529 - void testExistsSameKeyMultipleTimes(); + // DATAREDIS-315 + void incrByShouldIncreaseValueCorrectly(); + + // DATAREDIS-315 + void incrShouldIncreaseValueCorrectly(); + + // DATAREDIS-315 + void infoShouldCollectInfoForSpecificNode(); + + // DATAREDIS-315 + void infoShouldCollectInfoForSpecificNodeAndSection(); + + // DATAREDIS-315 + void infoShouldCollectionInfoFromAllClusterNodes(); + + // DATAREDIS-315 + void keysShouldReturnAllKeys(); + + // DATAREDIS-315 + void keysShouldReturnAllKeysForSpecificNode(); + + // DATAREDIS-315 + void lIndexShouldGetElementAtIndexCorrectly(); + + // DATAREDIS-315 + void lInsertShouldAddElementAtPositionCorrectly(); + + // DATAREDIS-315 + void lLenShouldCountValuesCorrectly(); + + // DATAREDIS-315 + void lPopShouldReturnElementCorrectly(); + + // DATAREDIS-315 + void lPushNXShoultNotAddValuesWhenKeyDoesNotExist(); + + // DATAREDIS-315 + void lPushShoultAddValuesCorrectly(); + + // DATAREDIS-315 + void lRangeShouldGetValuesCorrectly(); + + // DATAREDIS-315 + void lRemShouldRemoveElementAtPositionCorrectly(); + + // DATAREDIS-315 + void lSetShouldSetElementAtPositionCorrectly(); + + // DATAREDIS-315 + void lTrimShouldTrimListCorrectly(); + + // DATAREDIS-315 + void mGetShouldReturnCorrectlyWhenKeysDoNotMapToSameSlot(); + + // DATAREDIS-315 + void mGetShouldReturnCorrectlyWhenKeysMapToSameSlot(); + + // DATAREDIS-315 + void mSetNXShouldReturnFalseIfNotAllKeysSet(); + + // DATAREDIS-315 + void mSetNXShouldReturnTrueIfAllKeysSet(); + + // DATAREDIS-315 + void mSetNXShouldWorkForOnSameSlotKeys(); + + // DATAREDIS-315 + void mSetShouldWorkWhenKeysDoNotMapToSameSlot(); + + // DATAREDIS-315 + void mSetShouldWorkWhenKeysMapToSameSlot(); + + // DATAREDIS-315 + void moveShouldNotBeSupported(); + + // DATAREDIS-315 + void multiShouldThrowException(); + + // DATAREDIS-315 + void pExpireAtShouldBeSetCorrectly(); + + // DATAREDIS-315 + void pExpireShouldBeSetCorreclty(); + + // DATAREDIS-315 + void pSetExShouldSetValueCorrectly(); + + // DATAREDIS-315 + void pTtlShouldReturValueCorrectly(); + + // DATAREDIS-315 + void pTtlShouldReturnMinusOneWhenKeyDoesNotHaveExpirationSet(); + + // DATAREDIS-315 + void pTtlShouldReturnMinusTwoWhenKeyDoesNotExist(); + + // DATAREDIS-526 + void pTtlWithTimeUnitShouldReturnMinusTwoWhenKeyDoesNotExist(); + + // DATAREDIS-315 + void persistShouldRemoveTTL(); + + void pfAddShouldAddValuesCorrectly(); + + // DATAREDIS-315 + void pfCountShouldAllowCountingOnSameSlotKeys(); + + // DATAREDIS-315 + void pfCountShouldAllowCountingOnSingleKey(); + + // DATAREDIS-315 + void pfCountShouldThrowErrorCountingOnDifferentSlotKeys(); + + // DATAREDIS-315 + public void pfMergeShouldThrowErrorOnDifferentSlotKeys(); + + // DATAREDIS-315 + void pfMergeShouldWorkWhenAllKeysMapToSameSlot(); + + // DATAREDIS-315 + void pingShouldRetrunPong(); + + // DATAREDIS-315 + void pingShouldRetrunPongForExistingNode(); + + // DATAREDIS-315 + void pingShouldThrowExceptionWhenNodeNotKnownToCluster(); + + // DATAREDIS-315 + void rPopLPushShouldWorkWhenDoNotMapToSameSlot(); + + // DATAREDIS-315 + public void rPopLPushShouldWorkWhenKeysOnSameSlot(); + + // DATAREDIS-315 + void rPopShouldReturnElementCorrectly(); + + // DATAREDIS-315 + void rPushNXShoultNotAddValuesWhenKeyDoesNotExist(); + + // DATAREDIS-315 + void rPushShoultAddValuesCorrectly(); + + // DATAREDIS-315 + void randomKeyShouldReturnCorrectlyWhenKeysAvailable(); + + // DATAREDIS-315 + void randomKeyShouldReturnNullWhenNoKeysAvailable(); + + // DATAREDIS-315 + void rename(); + + // DATAREDIS-315 + void renameNXWhenOnSameSlot(); + + // DATAREDIS-315 + void renameNXWhenTargetKeyDoesExist(); + + // DATAREDIS-315 + void renameNXWhenTargetKeyDoesNotExist(); + + // DATAREDIS-315 + void renameSameKeysOnSameSlot(); + + // DATAREDIS-315 + void sAddShouldAddValueToSetCorrectly(); + + // DATAREDIS-315 + void sCardShouldCountValuesInSetCorrectly(); + + // DATAREDIS-315 + void sDiffShouldWorkWhenKeysMapToSameSlot(); + + // DATAREDIS-315 + void sDiffShouldWorkWhenKeysNotMapToSameSlot(); + + // DATAREDIS-315 + void sDiffStoreShouldWorkWhenKeysMapToSameSlot(); + + // DATAREDIS-315 + void sDiffStoreShouldWorkWhenKeysNotMapToSameSlot(); + + // DATAREDIS-315 + void sInterShouldWorkForKeysMappingToSameSlot(); + + // DATAREDIS-315 + void sInterShouldWorkForKeysNotMappingToSameSlot(); + + // DATAREDIS-315 + void sInterStoreShouldWorkForKeysMappingToSameSlot(); + + // DATAREDIS-315 + void sInterStoreShouldWorkForKeysNotMappingToSameSlot(); + + // DATAREDIS-315 + void sIsMemberShouldReturnFalseIfValueIsMemberOfSet(); + + // DATAREDIS-315 + void sIsMemberShouldReturnTrueIfValueIsMemberOfSet(); + + // DATAREDIS-315 + void sMembersShouldReturnValuesContainedInSetCorrectly(); + + // DATAREDIS-315 + void sMoveShouldWorkWhenKeysDoNotMapToSameSlot(); + + // DATAREDIS-315 + void sMoveShouldWorkWhenKeysMapToSameSlot(); + + // DATAREDIS-315 + void sPopShouldPopValueFromSetCorrectly(); + + // DATAREDIS-315 + void sRandMamberShouldReturnValueCorrectly(); + + // DATAREDIS-315 + void sRandMamberWithCountShouldReturnValueCorrectly(); + + // DATAREDIS-315 + void sRemShouldRemoveValueFromSetCorrectly(); + + // DATAREDIS-315 + void sUnionShouldWorkForKeysMappingToSameSlot(); + + // DATAREDIS-315 + void sUnionShouldWorkForKeysNotMappingToSameSlot(); + + // DATAREDIS-315 + void sUnionStoreShouldWorkForKeysMappingToSameSlot(); + + // DATAREDIS-315 + void sUnionStoreShouldWorkForKeysNotMappingToSameSlot(); + + // DATAREDIS-315 + void selectShouldAllowSelectionOfDBIndexZero(); + + // DATAREDIS-315 + void selectShouldThrowExceptionWhenSelectingNonZeroDbIndex(); + + // DATAREDIS-315 + void setBitShouldWorkCorrectly(); + + // DATAREDIS-315 + void setExShouldSetValueCorrectly(); + + // DATAREDIS-315 + void setNxShouldNotSetValueWhenAlreadyExistsInDBCorrectly(); + + // DATAREDIS-315 + void setNxShouldSetValueCorrectly(); + + // DATAREDIS-315 + void setRangeShouldWorkCorrectly(); + + // DATAREDIS-315 + void setShouldSetValueCorrectly(); + + // DATAREDIS-316 + void setWithExpirationAndIfAbsentShouldNotBeAppliedWhenKeyExists(); + + // DATAREDIS-316 + void setWithExpirationAndIfAbsentShouldWorkCorrectly(); + + // DATAREDIS-316 + void setWithExpirationAndIfPresentShouldNotBeAppliedWhenKeyDoesNotExists(); + + // DATAREDIS-316 + void setWithExpirationAndIfPresentShouldWorkCorrectly(); + + // DATAREDIS-316 + void setWithExpirationInMillisecondsShouldWorkCorrectly(); + + // DATAREDIS-316 + void setWithExpirationInSecondsShouldWorkCorrectly(); + + // DATAREDIS-316 + void setWithOptionIfAbsentShouldWorkCorrectly(); + + // DATAREDIS-316 + void setWithOptionIfPresentShouldWorkCorrectly(); + + // DATAREDIS-315 + + // DATAREDIS-315 + void shouldAllowSettingAndGettingValues(); + + // DATAREDIS-315 + void sortAndStoreShouldAddSortedValuesValuesCorrectly(); + + // DATAREDIS-315 + void sortAndStoreShouldReturnZeroWhenListDoesNotExist(); + + // DATAREDIS-315 + void sortShouldReturnValuesCorrectly(); + + // DATAREDIS-315 + void sscanShouldRetrieveAllValuesInSetCorrectly(); + + // DATAREDIS-315 + void strLenShouldWorkCorrectly(); + + // DATAREDIS-315 + void ttlShouldReturnMinusOneWhenKeyDoesNotHaveExpirationSet(); + + // DATAREDIS-315 + void ttlShouldReturnMinusTwoWhenKeyDoesNotExist(); + + // DATAREDIS-315 + void ttlShouldReturnValueCorrectly(); + + // DATAREDIS-526 + void ttlWithTimeUnitShouldReturnMinusTwoWhenKeyDoesNotExist(); + + // DATAREDIS-315 + void typeShouldReadKeyTypeCorrectly(); + + // DATAREDIS-315 + void unwatchShouldThrowException(); + + // DATAREDIS-315 + void watchShouldThrowException(); + + // DATAREDIS-315 + void zAddShouldAddValueWithScoreCorrectly(); + + // DATAREDIS-315 + void zCardShouldReturnTotalNumberOfValues(); + + // DATAREDIS-315 + void zCountShouldCountValuesInRange(); + + // DATAREDIS-315 + void zIncrByShouldIncScoreForValueCorrectly(); + + // DATAREDIS-315 + void zInterStoreShouldThrowExceptionWhenKeysDoNotMapToSameSlots(); + + // DATAREDIS-315 + void zInterStoreShouldWorkForSameSlotKeys(); + + // DATAREDIS-315 + void zRangeByLexShouldReturnResultCorrectly(); + + // DATAREDIS-315 + void zRangeByScoreShouldReturnValuesCorrectly(); + + // DATAREDIS-315 + void zRangeByScoreShouldReturnValuesCorrectlyWhenGivenOffsetAndScore(); + + // DATAREDIS-315 + void zRangeByScoreWithScoresShouldReturnValuesAndScoreCorrectly(); + + // DATAREDIS-315 + void zRangeByScoreWithScoresShouldReturnValuesCorrectlyWhenGivenOffsetAndScore(); + + // DATAREDIS-315 + void zRangeShouldReturnValuesCorrectly(); + + // DATAREDIS-315 + void zRangeWithScoresShouldReturnValuesAndScoreCorrectly(); + + // DATAREDIS-315 + void zRankShouldReturnPositionForValueCorrectly(); + + // DATAREDIS-315 + void zRankShouldReturnReversePositionForValueCorrectly(); + + // DATAREDIS-315 + void zRemRangeByScoreShouldRemoveValues(); + + // DATAREDIS-315 + void zRemRangeShouldRemoveValues(); + + // DATAREDIS-315 + void zRemShouldRemoveValueWithScoreCorrectly(); + + // DATAREDIS-315 + void zRevRangeByScoreShouldReturnValuesCorrectly(); + + // DATAREDIS-315 + void zRevRangeByScoreShouldReturnValuesCorrectlyWhenGivenOffsetAndScore(); + + // DATAREDIS-315 + void zRevRangeByScoreWithScoresShouldReturnValuesAndScoreCorrectly(); + + // DATAREDIS-315 + void zRevRangeByScoreWithScoresShouldReturnValuesCorrectlyWhenGivenOffsetAndScore(); + + // DATAREDIS-315 + void zRevRangeShouldReturnValuesCorrectly(); + + // DATAREDIS-315 + void zRevRangeWithScoresShouldReturnValuesAndScoreCorrectly(); + + // DATAREDIS-479 + void zScanShouldReadEntireValueRange(); + + // DATAREDIS-315 + void zScoreShouldRetrieveScoreForValue(); + + // DATAREDIS-315 + void zUnionStoreShouldThrowExceptionWhenKeysDoNotMapToSameSlots(); + + // DATAREDIS-315 + void zUnionStoreShouldWorkForSameSlotKeys(); } diff --git a/src/test/java/org/springframework/data/redis/connection/jedis/JedisClusterConnectionTests.java b/src/test/java/org/springframework/data/redis/connection/jedis/JedisClusterConnectionTests.java index 4952cbffb..39ab89e72 100644 --- a/src/test/java/org/springframework/data/redis/connection/jedis/JedisClusterConnectionTests.java +++ b/src/test/java/org/springframework/data/redis/connection/jedis/JedisClusterConnectionTests.java @@ -28,16 +28,7 @@ import redis.clients.jedis.JedisPool; import java.io.IOException; import java.nio.charset.Charset; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; -import java.util.Properties; -import java.util.Set; +import java.util.*; import java.util.concurrent.TimeUnit; import org.junit.After; @@ -132,501 +123,6 @@ public class JedisClusterConnectionTests implements ClusterConnectionTests { nativeConnection.close(); } - @Test // DATAREDIS-315 - public void shouldAllowSettingAndGettingValues() { - - clusterConnection.set(KEY_1_BYTES, VALUE_1_BYTES); - assertThat(clusterConnection.get(KEY_1_BYTES), is(VALUE_1_BYTES)); - } - - @Test // DATAREDIS-315 - public void delShouldRemoveSingleKeyCorrectly() { - - nativeConnection.set(KEY_1, VALUE_1); - - clusterConnection.del(KEY_1_BYTES); - - assertThat(nativeConnection.get(KEY_1), nullValue()); - } - - @Test // DATAREDIS-315 - public void delShouldRemoveMultipleKeysCorrectly() { - - nativeConnection.set(KEY_1, VALUE_1); - nativeConnection.set(KEY_2, VALUE_2); - - clusterConnection.del(KEY_1_BYTES, KEY_2_BYTES); - - assertThat(nativeConnection.get(KEY_1), nullValue()); - assertThat(nativeConnection.get(KEY_2), nullValue()); - } - - @Test // DATAREDIS-315 - public void delShouldRemoveMultipleKeysOnSameSlotCorrectly() { - - nativeConnection.set(SAME_SLOT_KEY_1, VALUE_1); - nativeConnection.set(SAME_SLOT_KEY_2, VALUE_2); - - clusterConnection.del(SAME_SLOT_KEY_1_BYTES, SAME_SLOT_KEY_2_BYTES); - - assertThat(nativeConnection.get(SAME_SLOT_KEY_1), nullValue()); - assertThat(nativeConnection.get(SAME_SLOT_KEY_2), nullValue()); - } - - @Test // DATAREDIS-315 - public void typeShouldReadKeyTypeCorrectly() { - - nativeConnection.sadd(KEY_1_BYTES, VALUE_1_BYTES); - nativeConnection.set(KEY_2_BYTES, VALUE_2_BYTES); - nativeConnection.hmset(KEY_3_BYTES, Collections.singletonMap(KEY_1_BYTES, VALUE_1_BYTES)); - - assertThat(clusterConnection.type(KEY_1_BYTES), is(DataType.SET)); - assertThat(clusterConnection.type(KEY_2_BYTES), is(DataType.STRING)); - assertThat(clusterConnection.type(KEY_3_BYTES), is(DataType.HASH)); - } - - @Test // DATAREDIS-315 - public void keysShouldReturnAllKeys() { - - nativeConnection.set(KEY_1, VALUE_1); - nativeConnection.set(KEY_2, VALUE_2); - - assertThat(clusterConnection.keys(JedisConverters.toBytes("*")), hasItems(KEY_1_BYTES, KEY_2_BYTES)); - } - - @Test // DATAREDIS-315 - public void keysShouldReturnAllKeysForSpecificNode() { - - nativeConnection.set(KEY_1, VALUE_1); - nativeConnection.set(KEY_2, VALUE_2); - - Set keysOnNode = clusterConnection.keys(new RedisClusterNode("127.0.0.1", 7379, SlotRange.empty()), - JedisConverters.toBytes("*")); - - assertThat(keysOnNode, hasItems(KEY_2_BYTES)); - assertThat(keysOnNode, not(hasItems(KEY_1_BYTES))); - } - - @Test // DATAREDIS-315 - public void randomKeyShouldReturnCorrectlyWhenKeysAvailable() { - - nativeConnection.set(KEY_1, VALUE_1); - nativeConnection.set(KEY_2, VALUE_2); - - assertThat(clusterConnection.randomKey(), notNullValue()); - } - - @Test // DATAREDIS-315 - public void randomKeyShouldReturnNullWhenNoKeysAvailable() { - assertThat(clusterConnection.randomKey(), nullValue()); - } - - @Test // DATAREDIS-315 - public void rename() { - - nativeConnection.set(KEY_1_BYTES, VALUE_1_BYTES); - - clusterConnection.rename(KEY_1_BYTES, KEY_2_BYTES); - - assertThat(nativeConnection.exists(KEY_1_BYTES), is(false)); - assertThat(nativeConnection.get(KEY_2_BYTES), is(VALUE_1_BYTES)); - } - - @Test // DATAREDIS-315 - public void renameSameKeysOnSameSlot() { - - nativeConnection.set(SAME_SLOT_KEY_1_BYTES, VALUE_1_BYTES); - - clusterConnection.rename(SAME_SLOT_KEY_1_BYTES, SAME_SLOT_KEY_2_BYTES); - - assertThat(nativeConnection.exists(SAME_SLOT_KEY_1_BYTES), is(false)); - assertThat(nativeConnection.get(SAME_SLOT_KEY_2_BYTES), is(VALUE_1_BYTES)); - } - - @Test // DATAREDIS-315 - public void renameNXWhenTargetKeyDoesNotExist() { - - nativeConnection.set(KEY_1_BYTES, VALUE_1_BYTES); - - assertThat(clusterConnection.renameNX(KEY_1_BYTES, KEY_2_BYTES), is(Boolean.TRUE)); - - assertThat(nativeConnection.exists(KEY_1_BYTES), is(false)); - assertThat(nativeConnection.get(KEY_2_BYTES), is(VALUE_1_BYTES)); - } - - @Test // DATAREDIS-315 - public void renameNXWhenTargetKeyDoesExist() { - - nativeConnection.set(KEY_1_BYTES, VALUE_1_BYTES); - nativeConnection.set(KEY_2_BYTES, VALUE_2_BYTES); - - assertThat(clusterConnection.renameNX(KEY_1_BYTES, KEY_2_BYTES), is(Boolean.FALSE)); - - assertThat(nativeConnection.get(KEY_1_BYTES), is(VALUE_1_BYTES)); - assertThat(nativeConnection.get(KEY_2_BYTES), is(VALUE_2_BYTES)); - } - - @Test // DATAREDIS-315 - public void renameNXWhenOnSameSlot() { - - nativeConnection.set(SAME_SLOT_KEY_1_BYTES, VALUE_1_BYTES); - - assertThat(clusterConnection.renameNX(SAME_SLOT_KEY_1_BYTES, SAME_SLOT_KEY_2_BYTES), is(Boolean.TRUE)); - - assertThat(nativeConnection.exists(SAME_SLOT_KEY_1_BYTES), is(false)); - assertThat(nativeConnection.get(SAME_SLOT_KEY_2_BYTES), is(VALUE_1_BYTES)); - } - - @Test // DATAREDIS-315 - public void expireShouldBeSetCorreclty() { - - nativeConnection.set(KEY_1, VALUE_1); - - clusterConnection.expire(KEY_1_BYTES, 5); - - assertThat(nativeConnection.ttl(JedisConverters.toString(KEY_1_BYTES)) > 1, is(true)); - } - - @Test // DATAREDIS-315 - public void pExpireShouldBeSetCorreclty() { - - nativeConnection.set(KEY_1, VALUE_1); - - clusterConnection.pExpire(KEY_1_BYTES, 5000); - - assertThat(nativeConnection.ttl(JedisConverters.toString(KEY_1_BYTES)) > 1, is(true)); - } - - @Test // DATAREDIS-315 - public void expireAtShouldBeSetCorrectly() { - - nativeConnection.set(KEY_1, VALUE_1); - - clusterConnection.expireAt(KEY_1_BYTES, System.currentTimeMillis() / 1000 + 5000); - - assertThat(nativeConnection.ttl(JedisConverters.toString(KEY_1_BYTES)) > 1, is(true)); - } - - @Test // DATAREDIS-315 - public void pExpireAtShouldBeSetCorrectly() { - - nativeConnection.set(KEY_1, VALUE_1); - - clusterConnection.pExpireAt(KEY_1_BYTES, System.currentTimeMillis() + 5000); - - assertThat(nativeConnection.ttl(JedisConverters.toString(KEY_1_BYTES)) > 1, is(true)); - } - - @Test // DATAREDIS-315 - public void persistShouldRemoveTTL() { - - nativeConnection.setex(KEY_1_BYTES, 10, VALUE_1_BYTES); - - assertThat(clusterConnection.persist(KEY_1_BYTES), is(Boolean.TRUE)); - assertThat(nativeConnection.ttl(KEY_1_BYTES), is(-1L)); - } - - @Test(expected = UnsupportedOperationException.class) // DATAREDIS-315 - public void moveShouldNotBeSupported() { - clusterConnection.move(KEY_1_BYTES, 3); - } - - @Test // DATAREDIS-315 - public void dbSizeShouldReturnCummulatedDbSize() { - - nativeConnection.set(KEY_1, VALUE_1); - nativeConnection.set(KEY_2, VALUE_2); - - assertThat(clusterConnection.dbSize(), is(2L)); - } - - @Test // DATAREDIS-315 - public void dbSizeForSpecificNodeShouldGetNodeDbSize() { - - nativeConnection.set(KEY_1, VALUE_1); - nativeConnection.set(KEY_2, VALUE_2); - - assertThat(clusterConnection.dbSize(new RedisClusterNode("127.0.0.1", 7379, SlotRange.empty())), is(1L)); - assertThat(clusterConnection.dbSize(new RedisClusterNode("127.0.0.1", 7380, SlotRange.empty())), is(1L)); - assertThat(clusterConnection.dbSize(new RedisClusterNode("127.0.0.1", 7381, SlotRange.empty())), is(0L)); - } - - @Test // DATAREDIS-315 - public void ttlShouldReturnMinusTwoWhenKeyDoesNotExist() { - assertThat(clusterConnection.ttl(KEY_1_BYTES), is(-2L)); - } - - @Test // DATAREDIS-526 - public void ttlWithTimeUnitShouldReturnMinusTwoWhenKeyDoesNotExist() { - assertThat(clusterConnection.ttl(KEY_1_BYTES, TimeUnit.HOURS), is(-2L)); - } - - @Test // DATAREDIS-315 - public void ttlShouldReturnMinusOneWhenKeyDoesNotHaveExpirationSet() { - - nativeConnection.set(KEY_1, VALUE_1); - - assertThat(clusterConnection.ttl(KEY_1_BYTES), is(-1L)); - } - - @Test // DATAREDIS-315 - public void ttlShouldReturnValueCorrectly() { - - nativeConnection.set(KEY_1, VALUE_1); - nativeConnection.expire(KEY_1, 5); - - assertThat(clusterConnection.ttl(KEY_1_BYTES) > 1, is(true)); - } - - @Test // DATAREDIS-315 - public void pTtlShouldReturnMinusTwoWhenKeyDoesNotExist() { - assertThat(clusterConnection.pTtl(KEY_1_BYTES), is(-2L)); - } - - @Test // DATAREDIS-526 - public void pTtlWithTimeUnitShouldReturnMinusTwoWhenKeyDoesNotExist() { - assertThat(clusterConnection.pTtl(KEY_1_BYTES, TimeUnit.HOURS), is(-2L)); - } - - @Test // DATAREDIS-315 - public void pTtlShouldReturnMinusOneWhenKeyDoesNotHaveExpirationSet() { - - nativeConnection.set(KEY_1, VALUE_1); - - assertThat(clusterConnection.pTtl(KEY_1_BYTES), is(-1L)); - } - - @Test // DATAREDIS-315 - public void pTtlShouldReturValueCorrectly() { - - nativeConnection.set(KEY_1, VALUE_1); - nativeConnection.expire(KEY_1, 5); - - assertThat(clusterConnection.pTtl(KEY_1_BYTES) > 1, is(true)); - } - - @Test // DATAREDIS-315 - public void sortShouldReturnValuesCorrectly() { - - nativeConnection.lpush(KEY_1, VALUE_2, VALUE_1); - - assertThat(clusterConnection.sort(KEY_1_BYTES, new DefaultSortParameters().alpha()), - hasItems(VALUE_1_BYTES, VALUE_2_BYTES)); - } - - @Test // DATAREDIS-315 - public void sortAndStoreShouldAddSortedValuesValuesCorrectly() { - - nativeConnection.lpush(KEY_1, VALUE_2, VALUE_1); - - assertThat(clusterConnection.sort(KEY_1_BYTES, new DefaultSortParameters().alpha(), KEY_2_BYTES), is(1L)); - assertThat(nativeConnection.exists(KEY_2_BYTES), is(true)); - } - - @Test // DATAREDIS-315 - public void sortAndStoreShouldReturnZeroWhenListDoesNotExist() { - assertThat(clusterConnection.sort(KEY_1_BYTES, new DefaultSortParameters().alpha(), KEY_2_BYTES), is(0L)); - } - - @Test // DATAREDIS-315 - public void dumpAndRestoreShouldWorkCorrectly() { - - nativeConnection.set(KEY_1, VALUE_1); - - byte[] dumpedValue = clusterConnection.dump(KEY_1_BYTES); - clusterConnection.restore(KEY_2_BYTES, 0, dumpedValue); - - assertThat(nativeConnection.get(KEY_2), is(VALUE_1)); - } - - @Test // DATAREDIS-315 - public void getShouldReturnValueCorrectly() { - - nativeConnection.set(KEY_1, VALUE_1); - - assertThat(clusterConnection.get(KEY_1_BYTES), is(VALUE_1_BYTES)); - } - - @Test // DATAREDIS-315 - public void getSetShouldWorkCorrectly() { - - nativeConnection.set(KEY_1, VALUE_1); - - byte[] valueBeforeSet = clusterConnection.getSet(KEY_1_BYTES, VALUE_2_BYTES); - - assertThat(valueBeforeSet, is(VALUE_1_BYTES)); - assertThat(nativeConnection.get(KEY_1), is(VALUE_2)); - } - - @Test // DATAREDIS-315 - public void mGetShouldReturnCorrectlyWhenKeysMapToSameSlot() { - - nativeConnection.set(SAME_SLOT_KEY_1_BYTES, VALUE_1_BYTES); - nativeConnection.set(SAME_SLOT_KEY_2_BYTES, VALUE_2_BYTES); - - assertThat(clusterConnection.mGet(SAME_SLOT_KEY_1_BYTES, SAME_SLOT_KEY_2_BYTES), - contains(VALUE_1_BYTES, VALUE_2_BYTES)); - } - - @Test // DATAREDIS-315 - public void mGetShouldReturnCorrectlyWhenKeysDoNotMapToSameSlot() { - - nativeConnection.set(KEY_1_BYTES, VALUE_1_BYTES); - nativeConnection.set(KEY_2_BYTES, VALUE_2_BYTES); - - assertThat(clusterConnection.mGet(KEY_1_BYTES, KEY_2_BYTES), contains(VALUE_1_BYTES, VALUE_2_BYTES)); - } - - @Test // DATAREDIS-315 - public void setShouldSetValueCorrectly() { - - clusterConnection.set(KEY_1_BYTES, VALUE_1_BYTES); - - assertThat(nativeConnection.get(KEY_1), is(VALUE_1)); - } - - @Test // DATAREDIS-315 - public void setNxShouldSetValueCorrectly() { - - clusterConnection.setNX(KEY_1_BYTES, VALUE_1_BYTES); - - assertThat(nativeConnection.get(KEY_1), is(VALUE_1)); - } - - @Test // DATAREDIS-315 - public void setNxShouldNotSetValueWhenAlreadyExistsInDBCorrectly() { - - nativeConnection.set(KEY_1, VALUE_1); - - clusterConnection.setNX(KEY_1_BYTES, VALUE_2_BYTES); - - assertThat(nativeConnection.get(KEY_1), is(VALUE_1)); - } - - @Test // DATAREDIS-315 - public void setExShouldSetValueCorrectly() { - - clusterConnection.setEx(KEY_1_BYTES, 5, VALUE_1_BYTES); - - assertThat(nativeConnection.get(KEY_1), is(VALUE_1)); - assertThat(nativeConnection.ttl(KEY_1) > 1, is(true)); - } - - @Test // DATAREDIS-315 - public void pSetExShouldSetValueCorrectly() { - - clusterConnection.pSetEx(KEY_1_BYTES, 5000, VALUE_1_BYTES); - - assertThat(nativeConnection.get(KEY_1), is(VALUE_1)); - assertThat(nativeConnection.ttl(KEY_1) > 1, is(true)); - } - - @Test // DATAREDIS-315 - public void mSetShouldWorkWhenKeysMapToSameSlot() { - - Map map = new LinkedHashMap<>(); - map.put(SAME_SLOT_KEY_1_BYTES, VALUE_1_BYTES); - map.put(SAME_SLOT_KEY_2_BYTES, VALUE_2_BYTES); - - clusterConnection.mSet(map); - - assertThat(nativeConnection.get(SAME_SLOT_KEY_1), is(VALUE_1)); - assertThat(nativeConnection.get(SAME_SLOT_KEY_2), is(VALUE_2)); - } - - @Test // DATAREDIS-315 - public void mSetShouldWorkWhenKeysDoNotMapToSameSlot() { - - Map map = new LinkedHashMap<>(); - map.put(KEY_1_BYTES, VALUE_1_BYTES); - map.put(KEY_2_BYTES, VALUE_2_BYTES); - - clusterConnection.mSet(map); - - assertThat(nativeConnection.get(KEY_1), is(VALUE_1)); - assertThat(nativeConnection.get(KEY_2), is(VALUE_2)); - } - - @Test // DATAREDIS-315 - public void mSetNXShouldReturnTrueIfAllKeysSet() { - - Map map = new LinkedHashMap<>(); - map.put(KEY_1_BYTES, VALUE_1_BYTES); - map.put(KEY_2_BYTES, VALUE_2_BYTES); - - assertThat(clusterConnection.mSetNX(map), is(true)); - - assertThat(nativeConnection.get(KEY_1), is(VALUE_1)); - assertThat(nativeConnection.get(KEY_2), is(VALUE_2)); - } - - @Test // DATAREDIS-315 - public void mSetNXShouldReturnFalseIfNotAllKeysSet() { - - nativeConnection.set(KEY_2_BYTES, VALUE_3_BYTES); - Map map = new LinkedHashMap<>(); - map.put(KEY_1_BYTES, VALUE_1_BYTES); - map.put(KEY_2_BYTES, VALUE_2_BYTES); - - assertThat(clusterConnection.mSetNX(map), is(false)); - - assertThat(nativeConnection.get(KEY_1), is(VALUE_1)); - assertThat(nativeConnection.get(KEY_2), is(VALUE_3)); - } - - @Test // DATAREDIS-315 - public void mSetNXShouldWorkForOnSameSlotKeys() { - - Map map = new LinkedHashMap<>(); - map.put(SAME_SLOT_KEY_1_BYTES, VALUE_1_BYTES); - map.put(SAME_SLOT_KEY_2_BYTES, VALUE_2_BYTES); - - assertThat(clusterConnection.mSetNX(map), is(true)); - - assertThat(nativeConnection.get(SAME_SLOT_KEY_1), is(VALUE_1)); - assertThat(nativeConnection.get(SAME_SLOT_KEY_2), is(VALUE_2)); - } - - @Test // DATAREDIS-315 - public void incrShouldIncreaseValueCorrectly() { - - nativeConnection.set(KEY_1, "1"); - - assertThat(clusterConnection.incr(KEY_1_BYTES), is(2L)); - } - - @Test // DATAREDIS-315 - public void incrByShouldIncreaseValueCorrectly() { - - nativeConnection.set(KEY_1, "1"); - - assertThat(clusterConnection.incrBy(KEY_1_BYTES, 5), is(6L)); - } - - @Test // DATAREDIS-315 - public void incrByFloatShouldIncreaseValueCorrectly() { - - nativeConnection.set(KEY_1, "1"); - - assertThat(clusterConnection.incrBy(KEY_1_BYTES, 5.5D), is(6.5D)); - } - - @Test // DATAREDIS-315 - public void decrShouldDecreaseValueCorrectly() { - - nativeConnection.set(KEY_1, "5"); - - assertThat(clusterConnection.decr(KEY_1_BYTES), is(4L)); - } - - @Test // DATAREDIS-315 - public void decrByShouldDecreaseValueCorrectly() { - - nativeConnection.set(KEY_1, "5"); - - assertThat(clusterConnection.decrBy(KEY_1_BYTES, 4), is(1L)); - } - @Test // DATAREDIS-315 public void appendShouldAddValueCorrectly() { @@ -637,41 +133,21 @@ public class JedisClusterConnectionTests implements ClusterConnectionTests { } @Test // DATAREDIS-315 - public void getRangeShouldReturnValueCorrectly() { + public void bRPopLPushShouldWork() { - nativeConnection.set(KEY_1, VALUE_1); + nativeConnection.lpush(KEY_1_BYTES, VALUE_1_BYTES, VALUE_2_BYTES); - assertThat(clusterConnection.getRange(KEY_1_BYTES, 0, 2), is(JedisConverters.toBytes("val"))); + assertThat(clusterConnection.bRPopLPush(0, KEY_1_BYTES, KEY_2_BYTES), is(VALUE_1_BYTES)); + assertThat(nativeConnection.exists(KEY_2_BYTES), is(true)); } @Test // DATAREDIS-315 - public void setRangeShouldWorkCorrectly() { + public void bRPopLPushShouldWorkOnSameSlotKeys() { - nativeConnection.set(KEY_1, VALUE_1); + nativeConnection.lpush(SAME_SLOT_KEY_1_BYTES, VALUE_1_BYTES, VALUE_2_BYTES); - clusterConnection.setRange(KEY_1_BYTES, JedisConverters.toBytes("UE"), 3); - - assertThat(nativeConnection.get(KEY_1), is("valUE1")); - } - - @Test // DATAREDIS-315 - public void getBitShouldWorkCorrectly() { - - nativeConnection.setbit(KEY_1, 0, true); - nativeConnection.setbit(KEY_1, 1, false); - - assertThat(clusterConnection.getBit(KEY_1_BYTES, 0), is(true)); - assertThat(clusterConnection.getBit(KEY_1_BYTES, 1), is(false)); - } - - @Test // DATAREDIS-315 - public void setBitShouldWorkCorrectly() { - - clusterConnection.setBit(KEY_1_BYTES, 0, true); - clusterConnection.setBit(KEY_1_BYTES, 1, false); - - assertThat(nativeConnection.getbit(KEY_1, 0), is(true)); - assertThat(nativeConnection.getbit(KEY_1, 1), is(false)); + assertThat(clusterConnection.bRPopLPush(0, SAME_SLOT_KEY_1_BYTES, SAME_SLOT_KEY_2_BYTES), is(VALUE_1_BYTES)); + assertThat(nativeConnection.exists(SAME_SLOT_KEY_2_BYTES), is(true)); } @Test // DATAREDIS-315 @@ -695,6 +171,11 @@ public class JedisClusterConnectionTests implements ClusterConnectionTests { assertThat(clusterConnection.bitCount(KEY_1_BYTES, 0, 3), is(3L)); } + @Test(expected = DataAccessException.class) // DATAREDIS-315 + public void bitOpShouldThrowExceptionWhenKeysDoNotMapToSameSlot() { + clusterConnection.bitOp(BitOperation.AND, KEY_1_BYTES, KEY_2_BYTES, KEY_3_BYTES); + } + @Test // DATAREDIS-315 public void bitOpShouldWorkCorrectly() { @@ -706,131 +187,6 @@ public class JedisClusterConnectionTests implements ClusterConnectionTests { assertThat(nativeConnection.get(SAME_SLOT_KEY_3), is("bab")); } - @Test(expected = DataAccessException.class) // DATAREDIS-315 - public void bitOpShouldThrowExceptionWhenKeysDoNotMapToSameSlot() { - clusterConnection.bitOp(BitOperation.AND, KEY_1_BYTES, KEY_2_BYTES, KEY_3_BYTES); - } - - @Test // DATAREDIS-315 - public void strLenShouldWorkCorrectly() { - - nativeConnection.set(KEY_1, VALUE_1); - - assertThat(clusterConnection.strLen(KEY_1_BYTES), is(6L)); - } - - @Test // DATAREDIS-315 - public void rPushShoultAddValuesCorrectly() { - - clusterConnection.rPush(KEY_1_BYTES, VALUE_1_BYTES, VALUE_2_BYTES); - - assertThat(nativeConnection.lrange(KEY_1, 0, -1), hasItems(VALUE_1, VALUE_2)); - } - - @Test // DATAREDIS-315 - public void lPushShoultAddValuesCorrectly() { - - clusterConnection.lPush(KEY_1_BYTES, VALUE_1_BYTES, VALUE_2_BYTES); - - assertThat(nativeConnection.lrange(KEY_1, 0, -1), hasItems(VALUE_1, VALUE_2)); - } - - @Test // DATAREDIS-315 - public void rPushNXShoultNotAddValuesWhenKeyDoesNotExist() { - - clusterConnection.rPushX(KEY_1_BYTES, VALUE_1_BYTES); - - assertThat(nativeConnection.exists(KEY_1), is(false)); - } - - @Test // DATAREDIS-315 - public void lPushNXShoultNotAddValuesWhenKeyDoesNotExist() { - - clusterConnection.lPushX(KEY_1_BYTES, VALUE_1_BYTES); - - assertThat(nativeConnection.exists(KEY_1), is(false)); - } - - @Test // DATAREDIS-315 - public void lLenShouldCountValuesCorrectly() { - - nativeConnection.lpush(KEY_1, VALUE_1, VALUE_2); - - assertThat(clusterConnection.lLen(KEY_1_BYTES), is(2L)); - } - - @Test // DATAREDIS-315 - public void lRangeShouldGetValuesCorrectly() { - - nativeConnection.lpush(KEY_1, VALUE_1, VALUE_2); - - assertThat(clusterConnection.lRange(KEY_1_BYTES, 0L, -1L), hasItems(VALUE_1_BYTES, VALUE_2_BYTES)); - } - - @Test // DATAREDIS-315 - public void lTrimShouldTrimListCorrectly() { - - nativeConnection.lpush(KEY_1, VALUE_1, VALUE_2, "foo", "bar"); - - clusterConnection.lTrim(KEY_1_BYTES, 2, 3); - - assertThat(nativeConnection.lrange(KEY_1, 0, -1), hasItems(VALUE_1, VALUE_2)); - } - - @Test // DATAREDIS-315 - public void lIndexShouldGetElementAtIndexCorrectly() { - - nativeConnection.rpush(KEY_1, VALUE_1, VALUE_2, "foo", "bar"); - - assertThat(clusterConnection.lIndex(KEY_1_BYTES, 1), is(VALUE_2_BYTES)); - } - - @Test // DATAREDIS-315 - public void lInsertShouldAddElementAtPositionCorrectly() { - - nativeConnection.rpush(KEY_1, VALUE_1, VALUE_2, "foo", "bar"); - - clusterConnection.lInsert(KEY_1_BYTES, Position.AFTER, VALUE_2_BYTES, JedisConverters.toBytes("booh!")); - - assertThat(nativeConnection.lrange(KEY_1, 0, -1).get(2), is("booh!")); - } - - @Test // DATAREDIS-315 - public void lSetShouldSetElementAtPositionCorrectly() { - - nativeConnection.rpush(KEY_1, VALUE_1, VALUE_2, "foo", "bar"); - - clusterConnection.lSet(KEY_1_BYTES, 1L, VALUE_1_BYTES); - - assertThat(nativeConnection.lrange(KEY_1, 0, -1).get(1), is(VALUE_1)); - } - - @Test // DATAREDIS-315 - public void lRemShouldRemoveElementAtPositionCorrectly() { - - nativeConnection.rpush(KEY_1, VALUE_1, VALUE_2, "foo", "bar"); - - clusterConnection.lRem(KEY_1_BYTES, 1L, VALUE_1_BYTES); - - assertThat(nativeConnection.llen(KEY_1), is(3L)); - } - - @Test // DATAREDIS-315 - public void lPopShouldReturnElementCorrectly() { - - nativeConnection.rpush(KEY_1, VALUE_1, VALUE_2); - - assertThat(clusterConnection.lPop(KEY_1_BYTES), is(VALUE_1_BYTES)); - } - - @Test // DATAREDIS-315 - public void rPopShouldReturnElementCorrectly() { - - nativeConnection.rpush(KEY_1, VALUE_1, VALUE_2); - - assertThat(clusterConnection.rPop(KEY_1_BYTES), is(VALUE_2_BYTES)); - } - @Test // DATAREDIS-315 public void blPopShouldPopElementCorectly() { @@ -867,992 +223,11 @@ public class JedisClusterConnectionTests implements ClusterConnectionTests { assertThat(clusterConnection.bRPop(100, SAME_SLOT_KEY_1_BYTES, SAME_SLOT_KEY_2_BYTES).size(), is(2)); } - @Test // DATAREDIS-315 - public void rPopLPushShouldWorkWhenDoNotMapToSameSlot() { - - nativeConnection.lpush(KEY_1_BYTES, VALUE_1_BYTES, VALUE_2_BYTES); - - assertThat(clusterConnection.rPopLPush(KEY_1_BYTES, KEY_2_BYTES), is(VALUE_1_BYTES)); - assertThat(nativeConnection.exists(KEY_2_BYTES), is(true)); - } - - @Test // DATAREDIS-315 - public void rPopLPushShouldWorkWhenKeysOnSameSlot() { - - nativeConnection.lpush(SAME_SLOT_KEY_1_BYTES, VALUE_1_BYTES, VALUE_2_BYTES); - - assertThat(clusterConnection.rPopLPush(SAME_SLOT_KEY_1_BYTES, SAME_SLOT_KEY_2_BYTES), is(VALUE_1_BYTES)); - assertThat(nativeConnection.exists(SAME_SLOT_KEY_2_BYTES), is(true)); - } - - @Test // DATAREDIS-315 - public void bRPopLPushShouldWork() { - - nativeConnection.lpush(KEY_1_BYTES, VALUE_1_BYTES, VALUE_2_BYTES); - - assertThat(clusterConnection.bRPopLPush(0, KEY_1_BYTES, KEY_2_BYTES), is(VALUE_1_BYTES)); - assertThat(nativeConnection.exists(KEY_2_BYTES), is(true)); - } - - @Test // DATAREDIS-315 - public void bRPopLPushShouldWorkOnSameSlotKeys() { - - nativeConnection.lpush(SAME_SLOT_KEY_1_BYTES, VALUE_1_BYTES, VALUE_2_BYTES); - - assertThat(clusterConnection.bRPopLPush(0, SAME_SLOT_KEY_1_BYTES, SAME_SLOT_KEY_2_BYTES), is(VALUE_1_BYTES)); - assertThat(nativeConnection.exists(SAME_SLOT_KEY_2_BYTES), is(true)); - } - - @Test // DATAREDIS-315 - public void sAddShouldAddValueToSetCorrectly() { - - clusterConnection.sAdd(KEY_1_BYTES, VALUE_1_BYTES, VALUE_2_BYTES); - - assertThat(nativeConnection.smembers(KEY_1), hasItems(VALUE_1, VALUE_2)); - } - - @Test // DATAREDIS-315 - public void sRemShouldRemoveValueFromSetCorrectly() { - - nativeConnection.sadd(KEY_1, VALUE_1, VALUE_2); - - clusterConnection.sRem(KEY_1_BYTES, VALUE_2_BYTES); - - assertThat(nativeConnection.smembers(KEY_1), hasItems(VALUE_1)); - } - - @Test // DATAREDIS-315 - public void sPopShouldPopValueFromSetCorrectly() { - - nativeConnection.sadd(KEY_1, VALUE_1, VALUE_2); - - assertThat(clusterConnection.sPop(KEY_1_BYTES), notNullValue()); - } - - @Test // DATAREDIS-668 - public void sPopWithCountShouldPopValueFromSetCorrectly() { - - nativeConnection.sadd(KEY_1, VALUE_1, VALUE_2, VALUE_3); - - assertThat(clusterConnection.setCommands().sPop(KEY_1_BYTES, 2), hasSize(2)); - assertThat(nativeConnection.scard(KEY_1), is(1L)); - } - - @Test // DATAREDIS-315 - public void sMoveShouldWorkWhenKeysMapToSameSlot() { - - nativeConnection.sadd(SAME_SLOT_KEY_1_BYTES, VALUE_1_BYTES, VALUE_2_BYTES); - nativeConnection.sadd(SAME_SLOT_KEY_2_BYTES, VALUE_3_BYTES); - - clusterConnection.sMove(SAME_SLOT_KEY_1_BYTES, SAME_SLOT_KEY_2_BYTES, VALUE_2_BYTES); - - assertThat(nativeConnection.sismember(SAME_SLOT_KEY_1_BYTES, VALUE_2_BYTES), is(false)); - assertThat(nativeConnection.sismember(SAME_SLOT_KEY_2_BYTES, VALUE_2_BYTES), is(true)); - } - - @Test // DATAREDIS-315 - public void sMoveShouldWorkWhenKeysDoNotMapToSameSlot() { - - nativeConnection.sadd(KEY_1_BYTES, VALUE_1_BYTES, VALUE_2_BYTES); - nativeConnection.sadd(KEY_2_BYTES, VALUE_3_BYTES); - - clusterConnection.sMove(KEY_1_BYTES, KEY_2_BYTES, VALUE_2_BYTES); - - assertThat(nativeConnection.sismember(KEY_1_BYTES, VALUE_2_BYTES), is(false)); - assertThat(nativeConnection.sismember(KEY_2_BYTES, VALUE_2_BYTES), is(true)); - } - - @Test // DATAREDIS-315 - public void sCardShouldCountValuesInSetCorrectly() { - - nativeConnection.sadd(KEY_1, VALUE_1, VALUE_2); - - assertThat(clusterConnection.sCard(KEY_1_BYTES), is(2L)); - } - - @Test // DATAREDIS-315 - public void sIsMemberShouldReturnTrueIfValueIsMemberOfSet() { - - nativeConnection.sadd(KEY_1, VALUE_1, VALUE_2); - - assertThat(clusterConnection.sIsMember(KEY_1_BYTES, VALUE_1_BYTES), is(true)); - } - - @Test // DATAREDIS-315 - public void sIsMemberShouldReturnFalseIfValueIsMemberOfSet() { - - nativeConnection.sadd(KEY_1, VALUE_1, VALUE_2); - - assertThat(clusterConnection.sIsMember(KEY_1_BYTES, JedisConverters.toBytes("foo")), is(false)); - } - - @Test // DATAREDIS-315 - public void sInterShouldWorkForKeysMappingToSameSlot() { - - nativeConnection.sadd(SAME_SLOT_KEY_1_BYTES, VALUE_1_BYTES, VALUE_2_BYTES); - nativeConnection.sadd(SAME_SLOT_KEY_2_BYTES, VALUE_2_BYTES, VALUE_3_BYTES); - - assertThat(clusterConnection.sInter(SAME_SLOT_KEY_1_BYTES, SAME_SLOT_KEY_2_BYTES), hasItem(VALUE_2_BYTES)); - } - - @Test // DATAREDIS-315 - public void sInterShouldWorkForKeysNotMappingToSameSlot() { - - nativeConnection.sadd(KEY_1_BYTES, VALUE_1_BYTES, VALUE_2_BYTES); - nativeConnection.sadd(KEY_2_BYTES, VALUE_2_BYTES, VALUE_3_BYTES); - - assertThat(clusterConnection.sInter(KEY_1_BYTES, KEY_2_BYTES), hasItem(VALUE_2_BYTES)); - } - - @Test // DATAREDIS-315 - public void sInterStoreShouldWorkForKeysMappingToSameSlot() { - - nativeConnection.sadd(SAME_SLOT_KEY_1_BYTES, VALUE_1_BYTES, VALUE_2_BYTES); - nativeConnection.sadd(SAME_SLOT_KEY_2_BYTES, VALUE_2_BYTES, VALUE_3_BYTES); - - clusterConnection.sInterStore(SAME_SLOT_KEY_3_BYTES, SAME_SLOT_KEY_1_BYTES, SAME_SLOT_KEY_2_BYTES); - - assertThat(nativeConnection.smembers(SAME_SLOT_KEY_3_BYTES), hasItem(VALUE_2_BYTES)); - } - - @Test // DATAREDIS-315 - public void sInterStoreShouldWorkForKeysNotMappingToSameSlot() { - - nativeConnection.sadd(KEY_1_BYTES, VALUE_1_BYTES, VALUE_2_BYTES); - nativeConnection.sadd(KEY_2_BYTES, VALUE_2_BYTES, VALUE_3_BYTES); - - clusterConnection.sInterStore(KEY_3_BYTES, KEY_1_BYTES, KEY_2_BYTES); - - assertThat(nativeConnection.smembers(KEY_3_BYTES), hasItem(VALUE_2_BYTES)); - } - - @Test // DATAREDIS-315 - public void sUnionShouldWorkForKeysMappingToSameSlot() { - - nativeConnection.sadd(SAME_SLOT_KEY_1_BYTES, VALUE_1_BYTES, VALUE_2_BYTES); - nativeConnection.sadd(SAME_SLOT_KEY_2_BYTES, VALUE_2_BYTES, VALUE_3_BYTES); - - assertThat(clusterConnection.sUnion(SAME_SLOT_KEY_1_BYTES, SAME_SLOT_KEY_2_BYTES), - hasItems(VALUE_1_BYTES, VALUE_2_BYTES, VALUE_3_BYTES)); - } - - @Test // DATAREDIS-315 - public void sUnionShouldWorkForKeysNotMappingToSameSlot() { - - nativeConnection.sadd(KEY_1_BYTES, VALUE_1_BYTES, VALUE_2_BYTES); - nativeConnection.sadd(KEY_2_BYTES, VALUE_2_BYTES, VALUE_3_BYTES); - - assertThat(clusterConnection.sUnion(KEY_1_BYTES, KEY_2_BYTES), - hasItems(VALUE_1_BYTES, VALUE_2_BYTES, VALUE_3_BYTES)); - } - - @Test // DATAREDIS-315 - public void sUnionStoreShouldWorkForKeysMappingToSameSlot() { - - nativeConnection.sadd(SAME_SLOT_KEY_1_BYTES, VALUE_1_BYTES, VALUE_2_BYTES); - nativeConnection.sadd(SAME_SLOT_KEY_2_BYTES, VALUE_2_BYTES, VALUE_3_BYTES); - - clusterConnection.sUnionStore(SAME_SLOT_KEY_3_BYTES, SAME_SLOT_KEY_1_BYTES, SAME_SLOT_KEY_2_BYTES); - - assertThat(nativeConnection.smembers(SAME_SLOT_KEY_3_BYTES), hasItems(VALUE_1_BYTES, VALUE_2_BYTES, VALUE_3_BYTES)); - } - - @Test // DATAREDIS-315 - public void sUnionStoreShouldWorkForKeysNotMappingToSameSlot() { - - nativeConnection.sadd(KEY_1_BYTES, VALUE_1_BYTES, VALUE_2_BYTES); - nativeConnection.sadd(KEY_2_BYTES, VALUE_2_BYTES, VALUE_3_BYTES); - - clusterConnection.sUnionStore(KEY_3_BYTES, KEY_1_BYTES, KEY_2_BYTES); - - assertThat(nativeConnection.smembers(KEY_3_BYTES), hasItems(VALUE_1_BYTES, VALUE_2_BYTES, VALUE_3_BYTES)); - } - - @Test // DATAREDIS-315 - public void sDiffShouldWorkWhenKeysMapToSameSlot() { - - nativeConnection.sadd(SAME_SLOT_KEY_1_BYTES, VALUE_1_BYTES, VALUE_2_BYTES); - nativeConnection.sadd(SAME_SLOT_KEY_2_BYTES, VALUE_2_BYTES, VALUE_3_BYTES); - - assertThat(clusterConnection.sDiff(SAME_SLOT_KEY_1_BYTES, SAME_SLOT_KEY_2_BYTES), hasItems(VALUE_1_BYTES)); - } - - @Test // DATAREDIS-315, DATAREDIS-647 - public void sDiffShouldWorkWhenKeysNotMapToSameSlot() { - - nativeConnection.sadd(KEY_1_BYTES, VALUE_1_BYTES, VALUE_2_BYTES); - nativeConnection.sadd(KEY_2_BYTES, VALUE_2_BYTES, VALUE_3_BYTES); - nativeConnection.sadd(KEY_3_BYTES, VALUE_1_BYTES, VALUE_3_BYTES); - - assertThat(clusterConnection.sDiff(KEY_1_BYTES, KEY_2_BYTES), hasItems(VALUE_1_BYTES)); - assertThat(clusterConnection.sDiff(KEY_1_BYTES, KEY_2_BYTES, KEY_3_BYTES), is(empty())); - } - - @Test // DATAREDIS-315 - public void sDiffStoreShouldWorkWhenKeysMapToSameSlot() { - - nativeConnection.sadd(SAME_SLOT_KEY_1_BYTES, VALUE_1_BYTES, VALUE_2_BYTES); - nativeConnection.sadd(SAME_SLOT_KEY_2_BYTES, VALUE_2_BYTES, VALUE_3_BYTES); - - clusterConnection.sDiffStore(SAME_SLOT_KEY_3_BYTES, SAME_SLOT_KEY_1_BYTES, SAME_SLOT_KEY_2_BYTES); - - assertThat(nativeConnection.smembers(SAME_SLOT_KEY_3_BYTES), hasItems(VALUE_1_BYTES)); - } - - @Test // DATAREDIS-315 - public void sDiffStoreShouldWorkWhenKeysNotMapToSameSlot() { - - nativeConnection.sadd(KEY_1_BYTES, VALUE_1_BYTES, VALUE_2_BYTES); - nativeConnection.sadd(KEY_2_BYTES, VALUE_2_BYTES, VALUE_3_BYTES); - - clusterConnection.sDiffStore(KEY_3_BYTES, KEY_1_BYTES, KEY_2_BYTES); - - assertThat(nativeConnection.smembers(KEY_3_BYTES), hasItems(VALUE_1_BYTES)); - } - - @Test // DATAREDIS-315 - public void sMembersShouldReturnValuesContainedInSetCorrectly() { - - nativeConnection.sadd(KEY_1, VALUE_1, VALUE_2); - - assertThat(clusterConnection.sMembers(KEY_1_BYTES), hasItems(VALUE_1_BYTES, VALUE_2_BYTES)); - } - - @Test // DATAREDIS-315 - public void sRandMamberShouldReturnValueCorrectly() { - - nativeConnection.sadd(KEY_1, VALUE_1, VALUE_2); - - assertThat(clusterConnection.sRandMember(KEY_1_BYTES), notNullValue()); - } - - @Test // DATAREDIS-315 - public void sRandMamberWithCountShouldReturnValueCorrectly() { - - nativeConnection.sadd(KEY_1, VALUE_1, VALUE_2); - - assertThat(clusterConnection.sRandMember(KEY_1_BYTES, 3), notNullValue()); - } - - @Test // DATAREDIS-315 - public void sscanShouldRetrieveAllValuesInSetCorrectly() { - - for (int i = 0; i < 30; i++) { - nativeConnection.sadd(KEY_1_BYTES, JedisConverters.toBytes(Integer.valueOf(i))); - } - - int count = 0; - Cursor cursor = clusterConnection.sScan(KEY_1_BYTES, ScanOptions.NONE); - while (cursor.hasNext()) { - count++; - cursor.next(); - } - - assertThat(count, is(30)); - } - - @Test // DATAREDIS-315 - public void zAddShouldAddValueWithScoreCorrectly() { - - clusterConnection.zAdd(KEY_1_BYTES, 10D, VALUE_1_BYTES); - clusterConnection.zAdd(KEY_1_BYTES, 20D, VALUE_2_BYTES); - - assertThat(nativeConnection.zcard(KEY_1_BYTES), is(2L)); - } - - @Test // DATAREDIS-674 - public void zAddShouldAddMultipleValuesWithScoreCorrectly() { - - Set tuples = new HashSet<>(); - tuples.add(new DefaultTuple(VALUE_1_BYTES, 10D)); - tuples.add(new DefaultTuple(VALUE_2_BYTES, 20D)); - - clusterConnection.zAdd(KEY_1_BYTES, tuples); - - assertThat(nativeConnection.zcard(KEY_1_BYTES), is(2L)); - } - - @Test // DATAREDIS-315 - public void zRemShouldRemoveValueWithScoreCorrectly() { - - nativeConnection.zadd(KEY_1_BYTES, 10D, VALUE_1_BYTES); - nativeConnection.zadd(KEY_1_BYTES, 20D, VALUE_2_BYTES); - - clusterConnection.zRem(KEY_1_BYTES, VALUE_1_BYTES); - - assertThat(nativeConnection.zcard(KEY_1_BYTES), is(1L)); - } - - @Test // DATAREDIS-315 - public void zIncrByShouldIncScoreForValueCorrectly() { - - nativeConnection.zadd(KEY_1_BYTES, 10D, VALUE_1_BYTES); - nativeConnection.zadd(KEY_1_BYTES, 20D, VALUE_2_BYTES); - - clusterConnection.zIncrBy(KEY_1_BYTES, 100D, VALUE_1_BYTES); - - assertThat(nativeConnection.zrank(KEY_1_BYTES, VALUE_1_BYTES), is(1L)); - } - - @Test // DATAREDIS-315 - public void zRankShouldReturnPositionForValueCorrectly() { - - nativeConnection.zadd(KEY_1_BYTES, 10D, VALUE_1_BYTES); - nativeConnection.zadd(KEY_1_BYTES, 20D, VALUE_2_BYTES); - - assertThat(clusterConnection.zRank(KEY_1_BYTES, VALUE_2_BYTES), is(1L)); - } - - @Test // DATAREDIS-315 - public void zRankShouldReturnReversePositionForValueCorrectly() { - - nativeConnection.zadd(KEY_1_BYTES, 10D, VALUE_1_BYTES); - nativeConnection.zadd(KEY_1_BYTES, 20D, VALUE_2_BYTES); - - assertThat(clusterConnection.zRevRank(KEY_1_BYTES, VALUE_2_BYTES), is(0L)); - } - - @Test // DATAREDIS-315 - public void zRangeShouldReturnValuesCorrectly() { - - nativeConnection.zadd(KEY_1_BYTES, 10D, VALUE_1_BYTES); - nativeConnection.zadd(KEY_1_BYTES, 20D, VALUE_2_BYTES); - nativeConnection.zadd(KEY_1_BYTES, 5D, VALUE_3_BYTES); - - assertThat(clusterConnection.zRange(KEY_1_BYTES, 1, 2), hasItems(VALUE_1_BYTES, VALUE_2_BYTES)); - } - - @Test // DATAREDIS-315 - public void zRangeWithScoresShouldReturnValuesAndScoreCorrectly() { - - nativeConnection.zadd(KEY_1_BYTES, 10D, VALUE_1_BYTES); - nativeConnection.zadd(KEY_1_BYTES, 20D, VALUE_2_BYTES); - nativeConnection.zadd(KEY_1_BYTES, 5D, VALUE_3_BYTES); - - assertThat(clusterConnection.zRangeWithScores(KEY_1_BYTES, 1, 2), - hasItems((Tuple) new DefaultTuple(VALUE_1_BYTES, 10D), (Tuple) new DefaultTuple(VALUE_2_BYTES, 20D))); - } - - @Test // DATAREDIS-315 - public void zRangeByScoreShouldReturnValuesCorrectly() { - - nativeConnection.zadd(KEY_1_BYTES, 10D, VALUE_1_BYTES); - nativeConnection.zadd(KEY_1_BYTES, 20D, VALUE_2_BYTES); - nativeConnection.zadd(KEY_1_BYTES, 5D, VALUE_3_BYTES); - - assertThat(clusterConnection.zRangeByScore(KEY_1_BYTES, 10, 20), hasItems(VALUE_1_BYTES, VALUE_2_BYTES)); - } - - @Test // DATAREDIS-315 - public void zRangeByScoreWithScoresShouldReturnValuesAndScoreCorrectly() { - - nativeConnection.zadd(KEY_1_BYTES, 10D, VALUE_1_BYTES); - nativeConnection.zadd(KEY_1_BYTES, 20D, VALUE_2_BYTES); - nativeConnection.zadd(KEY_1_BYTES, 5D, VALUE_3_BYTES); - - assertThat(clusterConnection.zRangeByScoreWithScores(KEY_1_BYTES, 10, 20), - hasItems((Tuple) new DefaultTuple(VALUE_1_BYTES, 10D), (Tuple) new DefaultTuple(VALUE_2_BYTES, 20D))); - } - - @Test // DATAREDIS-315 - public void zRangeByScoreShouldReturnValuesCorrectlyWhenGivenOffsetAndScore() { - - nativeConnection.zadd(KEY_1_BYTES, 10D, VALUE_1_BYTES); - nativeConnection.zadd(KEY_1_BYTES, 20D, VALUE_2_BYTES); - nativeConnection.zadd(KEY_1_BYTES, 5D, VALUE_3_BYTES); - - assertThat(clusterConnection.zRangeByScore(KEY_1_BYTES, 10D, 20D, 0L, 1L), hasItems(VALUE_1_BYTES)); - } - - @Test // DATAREDIS-315 - public void zRangeByScoreWithScoresShouldReturnValuesCorrectlyWhenGivenOffsetAndScore() { - - nativeConnection.zadd(KEY_1_BYTES, 10D, VALUE_1_BYTES); - nativeConnection.zadd(KEY_1_BYTES, 20D, VALUE_2_BYTES); - nativeConnection.zadd(KEY_1_BYTES, 5D, VALUE_3_BYTES); - - assertThat(clusterConnection.zRangeByScoreWithScores(KEY_1_BYTES, 10D, 20D, 0L, 1L), - hasItems((Tuple) new DefaultTuple(VALUE_1_BYTES, 10D))); - } - - @Test // DATAREDIS-315 - public void zRevRangeShouldReturnValuesCorrectly() { - - nativeConnection.zadd(KEY_1_BYTES, 10D, VALUE_1_BYTES); - nativeConnection.zadd(KEY_1_BYTES, 20D, VALUE_2_BYTES); - nativeConnection.zadd(KEY_1_BYTES, 5D, VALUE_3_BYTES); - - assertThat(clusterConnection.zRevRange(KEY_1_BYTES, 1, 2), hasItems(VALUE_3_BYTES, VALUE_1_BYTES)); - } - - @Test // DATAREDIS-315 - public void zRevRangeWithScoresShouldReturnValuesAndScoreCorrectly() { - - nativeConnection.zadd(KEY_1_BYTES, 10D, VALUE_1_BYTES); - nativeConnection.zadd(KEY_1_BYTES, 20D, VALUE_2_BYTES); - nativeConnection.zadd(KEY_1_BYTES, 5D, VALUE_3_BYTES); - - assertThat(clusterConnection.zRevRangeWithScores(KEY_1_BYTES, 1, 2), - hasItems((Tuple) new DefaultTuple(VALUE_3_BYTES, 5D), (Tuple) new DefaultTuple(VALUE_1_BYTES, 10D))); - } - - @Test // DATAREDIS-315 - public void zRevRangeByScoreShouldReturnValuesCorrectly() { - - nativeConnection.zadd(KEY_1_BYTES, 10D, VALUE_1_BYTES); - nativeConnection.zadd(KEY_1_BYTES, 20D, VALUE_2_BYTES); - nativeConnection.zadd(KEY_1_BYTES, 5D, VALUE_3_BYTES); - - assertThat(clusterConnection.zRevRangeByScore(KEY_1_BYTES, 10D, 20D), hasItems(VALUE_2_BYTES, VALUE_1_BYTES)); - } - - @Test // DATAREDIS-315 - public void zRevRangeByScoreWithScoresShouldReturnValuesAndScoreCorrectly() { - - nativeConnection.zadd(KEY_1_BYTES, 10D, VALUE_1_BYTES); - nativeConnection.zadd(KEY_1_BYTES, 20D, VALUE_2_BYTES); - nativeConnection.zadd(KEY_1_BYTES, 5D, VALUE_3_BYTES); - - assertThat(clusterConnection.zRevRangeByScoreWithScores(KEY_1_BYTES, 10D, 20D), - hasItems((Tuple) new DefaultTuple(VALUE_2_BYTES, 20D), (Tuple) new DefaultTuple(VALUE_1_BYTES, 10D))); - } - - @Test // DATAREDIS-315 - public void zRevRangeByScoreShouldReturnValuesCorrectlyWhenGivenOffsetAndScore() { - - nativeConnection.zadd(KEY_1_BYTES, 10D, VALUE_1_BYTES); - nativeConnection.zadd(KEY_1_BYTES, 20D, VALUE_2_BYTES); - nativeConnection.zadd(KEY_1_BYTES, 5D, VALUE_3_BYTES); - - assertThat(clusterConnection.zRevRangeByScore(KEY_1_BYTES, 10D, 20D, 0L, 1L), hasItems(VALUE_2_BYTES)); - } - - @Test // DATAREDIS-315 - public void zRevRangeByScoreWithScoresShouldReturnValuesCorrectlyWhenGivenOffsetAndScore() { - - nativeConnection.zadd(KEY_1_BYTES, 10D, VALUE_1_BYTES); - nativeConnection.zadd(KEY_1_BYTES, 20D, VALUE_2_BYTES); - nativeConnection.zadd(KEY_1_BYTES, 5D, VALUE_3_BYTES); - - assertThat(clusterConnection.zRevRangeByScoreWithScores(KEY_1_BYTES, 10D, 20D, 0L, 1L), - hasItems((Tuple) new DefaultTuple(VALUE_2_BYTES, 20D))); - } - - @Test // DATAREDIS-315 - public void zCountShouldCountValuesInRange() { - - nativeConnection.zadd(KEY_1_BYTES, 10D, VALUE_1_BYTES); - nativeConnection.zadd(KEY_1_BYTES, 20D, VALUE_2_BYTES); - nativeConnection.zadd(KEY_1_BYTES, 5D, VALUE_3_BYTES); - - assertThat(clusterConnection.zCount(KEY_1_BYTES, 10, 20), is(2L)); - } - - @Test // DATAREDIS-315 - public void zCardShouldReturnTotalNumberOfValues() { - - nativeConnection.zadd(KEY_1_BYTES, 10D, VALUE_1_BYTES); - nativeConnection.zadd(KEY_1_BYTES, 20D, VALUE_2_BYTES); - nativeConnection.zadd(KEY_1_BYTES, 5D, VALUE_3_BYTES); - - assertThat(clusterConnection.zCard(KEY_1_BYTES), is(3L)); - } - - @Test // DATAREDIS-315 - public void zScoreShouldRetrieveScoreForValue() { - - nativeConnection.zadd(KEY_1_BYTES, 10D, VALUE_1_BYTES); - nativeConnection.zadd(KEY_1_BYTES, 20D, VALUE_2_BYTES); - - assertThat(clusterConnection.zScore(KEY_1_BYTES, VALUE_2_BYTES), is(20D)); - } - - @Test // DATAREDIS-315 - public void zRemRangeShouldRemoveValues() { - - nativeConnection.zadd(KEY_1_BYTES, 10D, VALUE_1_BYTES); - nativeConnection.zadd(KEY_1_BYTES, 20D, VALUE_2_BYTES); - nativeConnection.zadd(KEY_1_BYTES, 30D, VALUE_3_BYTES); - - clusterConnection.zRemRange(KEY_1_BYTES, 1, 2); - - assertThat(nativeConnection.zcard(KEY_1_BYTES), is(1L)); - assertThat(nativeConnection.zrange(KEY_1_BYTES, 0, -1), hasItem(VALUE_1_BYTES)); - } - - @Test // DATAREDIS-315 - public void zRemRangeByScoreShouldRemoveValues() { - - nativeConnection.zadd(KEY_1_BYTES, 10D, VALUE_1_BYTES); - nativeConnection.zadd(KEY_1_BYTES, 20D, VALUE_2_BYTES); - nativeConnection.zadd(KEY_1_BYTES, 30D, VALUE_3_BYTES); - - clusterConnection.zRemRangeByScore(KEY_1_BYTES, 15D, 25D); - - assertThat(nativeConnection.zcard(KEY_1_BYTES), is(2L)); - assertThat(nativeConnection.zrange(KEY_1_BYTES, 0, -1), hasItems(VALUE_1_BYTES, VALUE_3_BYTES)); - } - - @Test // DATAREDIS-315 - public void zUnionStoreShouldWorkForSameSlotKeys() { - - nativeConnection.zadd(SAME_SLOT_KEY_1_BYTES, 10D, VALUE_1_BYTES); - nativeConnection.zadd(SAME_SLOT_KEY_1_BYTES, 30D, VALUE_3_BYTES); - nativeConnection.zadd(SAME_SLOT_KEY_2_BYTES, 20D, VALUE_2_BYTES); - - clusterConnection.zUnionStore(SAME_SLOT_KEY_3_BYTES, SAME_SLOT_KEY_1_BYTES, SAME_SLOT_KEY_2_BYTES); - - assertThat(nativeConnection.zrange(SAME_SLOT_KEY_3_BYTES, 0, -1), - hasItems(VALUE_1_BYTES, VALUE_2_BYTES, VALUE_3_BYTES)); - } - - @Test(expected = DataAccessException.class) // DATAREDIS-315 - public void zUnionStoreShouldThrowExceptionWhenKeysDoNotMapToSameSlots() { - clusterConnection.zUnionStore(KEY_3_BYTES, KEY_1_BYTES, KEY_2_BYTES); - } - - @Test // DATAREDIS-315 - public void zInterStoreShouldWorkForSameSlotKeys() { - - nativeConnection.zadd(SAME_SLOT_KEY_1_BYTES, 10D, VALUE_1_BYTES); - nativeConnection.zadd(SAME_SLOT_KEY_1_BYTES, 20D, VALUE_2_BYTES); - - nativeConnection.zadd(SAME_SLOT_KEY_2_BYTES, 20D, VALUE_2_BYTES); - nativeConnection.zadd(SAME_SLOT_KEY_2_BYTES, 30D, VALUE_3_BYTES); - - clusterConnection.zInterStore(SAME_SLOT_KEY_3_BYTES, SAME_SLOT_KEY_1_BYTES, SAME_SLOT_KEY_2_BYTES); - - assertThat(nativeConnection.zrange(SAME_SLOT_KEY_3_BYTES, 0, -1), hasItems(VALUE_2_BYTES)); - } - - @Test(expected = DataAccessException.class) // DATAREDIS-315 - public void zInterStoreShouldThrowExceptionWhenKeysDoNotMapToSameSlots() { - clusterConnection.zInterStore(KEY_3_BYTES, KEY_1_BYTES, KEY_2_BYTES); - } - - @Test // DATAREDIS-479 - public void zScanShouldReadEntireValueRange() { - - int nrOfValues = 321; - for (int i = 0; i < nrOfValues; i++) { - nativeConnection.zadd(KEY_1_BYTES, i, JedisConverters.toBytes("value-" + i)); - } - - Cursor tuples = clusterConnection.zScan(KEY_1_BYTES, ScanOptions.NONE); - - int count = 0; - while (tuples.hasNext()) { - - tuples.next(); - count++; - } - - assertThat(count, equalTo(nrOfValues)); - } - - @Test // DATAREDIS-315 - public void hSetShouldSetValueCorrectly() { - - clusterConnection.hSet(KEY_1_BYTES, KEY_2_BYTES, VALUE_1_BYTES); - - assertThat(nativeConnection.hget(KEY_1_BYTES, KEY_2_BYTES), is(VALUE_1_BYTES)); - } - - @Test // DATAREDIS-315 - public void hSetNXShouldSetValueCorrectly() { - - clusterConnection.hSetNX(KEY_1_BYTES, KEY_2_BYTES, VALUE_1_BYTES); - - assertThat(nativeConnection.hget(KEY_1_BYTES, KEY_2_BYTES), is(VALUE_1_BYTES)); - } - - @Test // DATAREDIS-315 - public void hSetNXShouldNotSetValueWhenAlreadyExists() { - - nativeConnection.hset(KEY_1_BYTES, KEY_2_BYTES, VALUE_1_BYTES); - - clusterConnection.hSetNX(KEY_1_BYTES, KEY_2_BYTES, VALUE_2_BYTES); - - assertThat(nativeConnection.hget(KEY_1_BYTES, KEY_2_BYTES), is(VALUE_1_BYTES)); - } - - @Test // DATAREDIS-315 - public void hGetShouldRetrieveValueCorrectly() { - - nativeConnection.hset(KEY_1_BYTES, KEY_2_BYTES, VALUE_1_BYTES); - - assertThat(clusterConnection.hGet(KEY_1_BYTES, KEY_2_BYTES), is(VALUE_1_BYTES)); - } - - @Test // DATAREDIS-315 - public void hMGetShouldRetrieveValueCorrectly() { - - nativeConnection.hset(KEY_1_BYTES, KEY_2_BYTES, VALUE_1_BYTES); - nativeConnection.hset(KEY_1_BYTES, KEY_3_BYTES, VALUE_2_BYTES); - - assertThat(clusterConnection.hMGet(KEY_1_BYTES, KEY_2_BYTES, KEY_3_BYTES), hasItems(VALUE_1_BYTES, VALUE_2_BYTES)); - } - - @Test // DATAREDIS-315 - public void hMSetShouldAddValuesCorrectly() { - - Map hashes = new HashMap<>(); - hashes.put(KEY_2_BYTES, VALUE_1_BYTES); - hashes.put(KEY_3_BYTES, VALUE_2_BYTES); - - clusterConnection.hMSet(KEY_1_BYTES, hashes); - - assertThat(nativeConnection.hmget(KEY_1_BYTES, KEY_2_BYTES, KEY_3_BYTES), hasItems(VALUE_1_BYTES, VALUE_2_BYTES)); - } - - @Test // DATAREDIS-315 - public void hIncrByShouldIncreaseFieldCorretly() { - - nativeConnection.hset(KEY_1_BYTES, KEY_2_BYTES, JedisConverters.toBytes(1L)); - nativeConnection.hset(KEY_1_BYTES, KEY_3_BYTES, JedisConverters.toBytes(2L)); - - clusterConnection.hIncrBy(KEY_1_BYTES, KEY_3_BYTES, 3); - - assertThat(nativeConnection.hget(KEY_1_BYTES, KEY_3_BYTES), is(JedisConverters.toBytes(5L))); - } - - @Test // DATAREDIS-315 - public void hIncrByFloatShouldIncreaseFieldCorretly() { - - nativeConnection.hset(KEY_1_BYTES, KEY_2_BYTES, JedisConverters.toBytes(1L)); - nativeConnection.hset(KEY_1_BYTES, KEY_3_BYTES, JedisConverters.toBytes(2L)); - - clusterConnection.hIncrBy(KEY_1_BYTES, KEY_3_BYTES, 3.5D); - - assertThat(nativeConnection.hget(KEY_1_BYTES, KEY_3_BYTES), is(JedisConverters.toBytes(5.5D))); - } - - @Test // DATAREDIS-315 - public void hExistsShouldReturnPresenceOfFieldCorrectly() { - - nativeConnection.hset(KEY_1_BYTES, KEY_2_BYTES, VALUE_1_BYTES); - - assertThat(clusterConnection.hExists(KEY_1_BYTES, KEY_2_BYTES), is(true)); - assertThat(clusterConnection.hExists(KEY_1_BYTES, KEY_3_BYTES), is(false)); - assertThat(clusterConnection.hExists(JedisConverters.toBytes("foo"), KEY_2_BYTES), is(false)); - } - - @Test // DATAREDIS-315 - public void hDelShouldRemoveFieldsCorrectly() { - - nativeConnection.hset(KEY_1_BYTES, KEY_2_BYTES, VALUE_1_BYTES); - nativeConnection.hset(KEY_1_BYTES, KEY_3_BYTES, VALUE_2_BYTES); - - clusterConnection.hDel(KEY_1_BYTES, KEY_2_BYTES); - - assertThat(nativeConnection.hexists(KEY_1_BYTES, KEY_2_BYTES), is(false)); - assertThat(nativeConnection.hexists(KEY_1_BYTES, KEY_3_BYTES), is(true)); - } - - @Test // DATAREDIS-315 - public void hLenShouldRetrieveSizeCorrectly() { - - nativeConnection.hset(KEY_1_BYTES, KEY_2_BYTES, VALUE_1_BYTES); - nativeConnection.hset(KEY_1_BYTES, KEY_3_BYTES, VALUE_2_BYTES); - - assertThat(clusterConnection.hLen(KEY_1_BYTES), is(2L)); - } - - @Test // DATAREDIS-315 - public void hKeysShouldRetrieveKeysCorrectly() { - - nativeConnection.hset(KEY_1_BYTES, KEY_2_BYTES, VALUE_1_BYTES); - nativeConnection.hset(KEY_1_BYTES, KEY_3_BYTES, VALUE_2_BYTES); - - assertThat(clusterConnection.hKeys(KEY_1_BYTES), hasItems(KEY_2_BYTES, KEY_3_BYTES)); - } - - @Test // DATAREDIS-315 - public void hValsShouldRetrieveValuesCorrectly() { - - nativeConnection.hset(KEY_1_BYTES, KEY_2_BYTES, VALUE_1_BYTES); - nativeConnection.hset(KEY_1_BYTES, KEY_3_BYTES, VALUE_2_BYTES); - - assertThat(clusterConnection.hVals(KEY_1_BYTES), hasItems(VALUE_1_BYTES, VALUE_2_BYTES)); - } - - @Test // DATAREDIS-315 - public void hGetAllShouldRetrieveEntriesCorrectly() { - - Map hashes = new HashMap<>(); - hashes.put(KEY_2_BYTES, VALUE_1_BYTES); - hashes.put(KEY_3_BYTES, VALUE_2_BYTES); - - nativeConnection.hmset(KEY_1_BYTES, hashes); - - Map hGetAll = clusterConnection.hGetAll(KEY_1_BYTES); - - assertThat(hGetAll.containsKey(KEY_2_BYTES), is(true)); - assertThat(hGetAll.containsKey(KEY_3_BYTES), is(true)); - } - - @Test // DATAREDIS-479 - public void hScanShouldReadEntireValueRange() { - - int nrOfValues = 321; - for (int i = 0; i < nrOfValues; i++) { - nativeConnection.hset(KEY_1_BYTES, JedisConverters.toBytes("key" + i), JedisConverters.toBytes("value-" + i)); - } - - Cursor> cursor = clusterConnection.hScan(KEY_1_BYTES, - scanOptions().match("key*").build()); - - int i = 0; - while (cursor.hasNext()) { - - cursor.next(); - i++; - } - - assertThat(i, is(nrOfValues)); - } - - @Test(expected = DataAccessException.class) // DATAREDIS-315 - public void multiShouldThrowException() { - clusterConnection.multi(); - } - - @Test(expected = DataAccessException.class) // DATAREDIS-315 - public void execShouldThrowException() { - clusterConnection.exec(); - } - - @Test(expected = DataAccessException.class) // DATAREDIS-315 - public void discardShouldThrowException() { - clusterConnection.discard(); - } - - @Test(expected = DataAccessException.class) // DATAREDIS-315 - public void watchShouldThrowException() { - clusterConnection.watch(); - } - - @Test(expected = DataAccessException.class) // DATAREDIS-315 - public void unwatchShouldThrowException() { - clusterConnection.unwatch(); - } - - @Test // DATAREDIS-315 - public void selectShouldAllowSelectionOfDBIndexZero() { - clusterConnection.select(0); - } - - @Test(expected = DataAccessException.class) // DATAREDIS-315 - public void selectShouldThrowExceptionWhenSelectingNonZeroDbIndex() { - clusterConnection.select(1); - } - - @Test // DATAREDIS-315 - public void echoShouldReturnInputCorrectly() { - assertThat(clusterConnection.echo(VALUE_1_BYTES), is(VALUE_1_BYTES)); - } - - @Test // DATAREDIS-315 - public void pingShouldRetrunPongForExistingNode() { - assertThat(clusterConnection.ping(new RedisClusterNode("127.0.0.1", 7379, SlotRange.empty())), is("PONG")); - } - - @Test // DATAREDIS-315 - public void pingShouldRetrunPong() { - assertThat(clusterConnection.ping(), is("PONG")); - } - - @Test(expected = IllegalArgumentException.class) // DATAREDIS-315 - public void pingShouldThrowExceptionWhenNodeNotKnownToCluster() { - clusterConnection.ping(new RedisClusterNode("127.0.0.1", 1234, null)); - } - - @Test // DATAREDIS-315 - public void flushDbShouldFlushAllClusterNodes() { - - nativeConnection.set(KEY_1, VALUE_1); - nativeConnection.set(KEY_2, VALUE_2); - - clusterConnection.flushDb(); - - assertThat(nativeConnection.get(KEY_1), nullValue()); - assertThat(nativeConnection.get(KEY_2), nullValue()); - } - - @Test // DATAREDIS-315 - public void flushDbOnSingleNodeShouldFlushOnlyGivenNodesDb() { - - nativeConnection.set(KEY_1, VALUE_1); - nativeConnection.set(KEY_2, VALUE_2); - - clusterConnection.flushDb(new RedisClusterNode("127.0.0.1", 7379, SlotRange.empty())); - - assertThat(nativeConnection.get(KEY_1), notNullValue()); - assertThat(nativeConnection.get(KEY_2), nullValue()); - } - - @Test // DATAREDIS-315 - public void zRangeByLexShouldReturnResultCorrectly() { - - nativeConnection.zadd(KEY_1, 0, "a"); - nativeConnection.zadd(KEY_1, 0, "b"); - nativeConnection.zadd(KEY_1, 0, "c"); - nativeConnection.zadd(KEY_1, 0, "d"); - nativeConnection.zadd(KEY_1, 0, "e"); - nativeConnection.zadd(KEY_1, 0, "f"); - nativeConnection.zadd(KEY_1, 0, "g"); - - Set values = clusterConnection.zRangeByLex(KEY_1_BYTES, Range.range().lte("c")); - - assertThat(values, - hasItems(JedisConverters.toBytes("a"), JedisConverters.toBytes("b"), JedisConverters.toBytes("c"))); - assertThat(values, not(hasItems(JedisConverters.toBytes("d"), JedisConverters.toBytes("e"), - JedisConverters.toBytes("f"), JedisConverters.toBytes("g")))); - - values = clusterConnection.zRangeByLex(KEY_1_BYTES, Range.range().lt("c")); - assertThat(values, hasItems(JedisConverters.toBytes("a"), JedisConverters.toBytes("b"))); - assertThat(values, not(hasItem(JedisConverters.toBytes("c")))); - - values = clusterConnection.zRangeByLex(KEY_1_BYTES, Range.range().gte("aaa").lt("g")); - assertThat(values, hasItems(JedisConverters.toBytes("b"), JedisConverters.toBytes("c"), - JedisConverters.toBytes("d"), JedisConverters.toBytes("e"), JedisConverters.toBytes("f"))); - assertThat(values, not(hasItems(JedisConverters.toBytes("a"), JedisConverters.toBytes("g")))); - - values = clusterConnection.zRangeByLex(KEY_1_BYTES, Range.range().gte("e")); - assertThat(values, - hasItems(JedisConverters.toBytes("e"), JedisConverters.toBytes("f"), JedisConverters.toBytes("g"))); - assertThat(values, not(hasItems(JedisConverters.toBytes("a"), JedisConverters.toBytes("b"), - JedisConverters.toBytes("c"), JedisConverters.toBytes("d")))); - } - - @Test // DATAREDIS-315, DATAREDIS-685 - public void infoShouldCollectionInfoFromAllClusterNodes() { - - Properties singleNodeInfo = clusterConnection.serverCommands().info(new RedisClusterNode("127.0.0.1", 7380)); - assertThat(Double.valueOf(clusterConnection.serverCommands().info().size()), - closeTo(singleNodeInfo.size() * 3, 12d)); - } - @Test // DATAREDIS-315 public void clientListShouldGetInfosForAllClients() { assertThat(clusterConnection.getClientList().isEmpty(), is(false)); } - @Test // DATAREDIS-315 - public void getClusterNodeForKeyShouldReturnNodeCorrectly() { - assertThat((RedisNode) clusterConnection.clusterGetNodeForKey(KEY_1_BYTES), is(new RedisNode("127.0.0.1", 7380))); - } - - @Test // DATAREDIS-315 - public void countKeysShouldReturnNumberOfKeysInSlot() { - - nativeConnection.set(SAME_SLOT_KEY_1, VALUE_1); - nativeConnection.set(SAME_SLOT_KEY_2, VALUE_2); - - assertThat(clusterConnection.clusterCountKeysInSlot(ClusterSlotHashUtil.calculateSlot(SAME_SLOT_KEY_1)), is(2L)); - } - - @Test // DATAREDIS-315 - public void pfAddShouldAddValuesCorrectly() { - - clusterConnection.pfAdd(KEY_1_BYTES, VALUE_1_BYTES, VALUE_2_BYTES, VALUE_3_BYTES); - - assertThat(nativeConnection.pfcount(KEY_1_BYTES), is(3L)); - } - - @Test // DATAREDIS-315 - public void pfCountShouldAllowCountingOnSingleKey() { - - nativeConnection.pfadd(KEY_1, VALUE_1, VALUE_2, VALUE_3); - - assertThat(clusterConnection.pfCount(KEY_1_BYTES), is(3L)); - } - - @Test // DATAREDIS-315 - public void pfCountShouldAllowCountingOnSameSlotKeys() { - - nativeConnection.pfadd(SAME_SLOT_KEY_1, VALUE_1, VALUE_2); - nativeConnection.pfadd(SAME_SLOT_KEY_2, VALUE_2, VALUE_3); - - assertThat(clusterConnection.pfCount(SAME_SLOT_KEY_1_BYTES, SAME_SLOT_KEY_2_BYTES), is(3L)); - } - - @Test(expected = DataAccessException.class) // DATAREDIS-315 - public void pfCountShouldThrowErrorCountingOnDifferentSlotKeys() { - - nativeConnection.pfadd(KEY_1, VALUE_1, VALUE_2); - nativeConnection.pfadd(KEY_2, VALUE_2, VALUE_3); - - clusterConnection.pfCount(KEY_1_BYTES, KEY_2_BYTES); - } - - @Test // DATAREDIS-315 - public void pfMergeShouldWorkWhenAllKeysMapToSameSlot() { - - nativeConnection.pfadd(SAME_SLOT_KEY_1, VALUE_1, VALUE_2); - nativeConnection.pfadd(SAME_SLOT_KEY_2, VALUE_2, VALUE_3); - - clusterConnection.pfMerge(SAME_SLOT_KEY_3_BYTES, SAME_SLOT_KEY_1_BYTES, SAME_SLOT_KEY_2_BYTES); - - assertThat(nativeConnection.pfcount(SAME_SLOT_KEY_3), is(3L)); - } - - @Test(expected = DataAccessException.class) // DATAREDIS-315 - public void pfMergeShouldThrowErrorOnDifferentSlotKeys() { - clusterConnection.pfMerge(KEY_3_BYTES, KEY_1_BYTES, KEY_2_BYTES); - } - - @Test // DATAREDIS-315 - public void infoShouldCollectInfoForSpecificNode() { - - Properties properties = clusterConnection.info(new RedisClusterNode(CLUSTER_HOST, MASTER_NODE_2_PORT)); - - assertThat(properties.getProperty("tcp_port"), is(Integer.toString(MASTER_NODE_2_PORT))); - } - - @Test // DATAREDIS-315 - public void infoShouldCollectInfoForSpecificNodeAndSection() { - - Properties properties = clusterConnection.info(new RedisClusterNode(CLUSTER_HOST, MASTER_NODE_2_PORT), "server"); - - assertThat(properties.getProperty("tcp_port"), is(Integer.toString(MASTER_NODE_2_PORT))); - assertThat(properties.getProperty("used_memory"), nullValue()); - } - - @Test // DATAREDIS-315, DATAREDIS-661 - public void getConfigShouldLoadCumulatedConfiguration() { - - Properties result = clusterConnection.getConfig("*max-*-entries*"); - - // config get *max-*-entries on redis 3.0.7 returns 8 entries per node while on 3.2.0-rc3 returns 6. - // @link https://github.com/spring-projects/spring-data-redis/pull/187 - assertThat(result.size() % 3, is(0)); - - for (Object o : result.keySet()) { - - assertThat(o.toString(), startsWith(CLUSTER_HOST)); - assertThat(result.getProperty(o.toString()), not(startsWith(CLUSTER_HOST))); - } - } - - @Test // DATAREDIS-315, DATAREDIS-661 - public void getConfigShouldLoadConfigurationOfSpecificNode() { - - Properties result = clusterConnection.getConfig(new RedisClusterNode(CLUSTER_HOST, SLAVEOF_NODE_1_PORT), "*"); - - assertThat(result.getProperty("slaveof"), endsWith("7379")); - } - - @Test // DATAREDIS-315 - public void clusterGetSlavesShouldReturnSlaveCorrectly() { - - Set slaves = clusterConnection - .clusterGetSlaves(new RedisClusterNode(CLUSTER_HOST, MASTER_NODE_1_PORT)); - - assertThat(slaves.size(), is(1)); - assertThat(slaves, hasItem(new RedisClusterNode(CLUSTER_HOST, SLAVEOF_NODE_1_PORT))); - } - @Test // DATAREDIS-315 public void clusterGetMasterSlaveMapShouldListMastersAndSlavesCorrectly() { @@ -1866,85 +241,210 @@ public class JedisClusterConnectionTests implements ClusterConnectionTests { assertThat(masterSlaveMap.get(new RedisClusterNode(CLUSTER_HOST, MASTER_NODE_3_PORT)).isEmpty(), is(true)); } - @Test // DATAREDIS-316 - public void setWithExpirationInSecondsShouldWorkCorrectly() { + @Test // DATAREDIS-315 + public void clusterGetSlavesShouldReturnSlaveCorrectly() { - clusterConnection.set(KEY_1_BYTES, VALUE_1_BYTES, Expiration.seconds(1), SetOption.upsert()); + Set slaves = clusterConnection + .clusterGetSlaves(new RedisClusterNode(CLUSTER_HOST, MASTER_NODE_1_PORT)); - assertThat(nativeConnection.exists(KEY_1_BYTES), is(true)); - assertThat(nativeConnection.ttl(KEY_1_BYTES), is(1L)); + assertThat(slaves.size(), is(1)); + assertThat(slaves, hasItem(new RedisClusterNode(CLUSTER_HOST, SLAVEOF_NODE_1_PORT))); } - @Test // DATAREDIS-316 - public void setWithExpirationInMillisecondsShouldWorkCorrectly() { + @Test // DATAREDIS-315 + public void countKeysShouldReturnNumberOfKeysInSlot() { - clusterConnection.set(KEY_1_BYTES, VALUE_1_BYTES, Expiration.milliseconds(500), SetOption.upsert()); + nativeConnection.set(SAME_SLOT_KEY_1, VALUE_1); + nativeConnection.set(SAME_SLOT_KEY_2, VALUE_2); - assertThat(nativeConnection.exists(KEY_1_BYTES), is(true)); - assertThat(nativeConnection.pttl(KEY_1).doubleValue(), is(closeTo(500d, 499d))); + assertThat(clusterConnection.clusterCountKeysInSlot(ClusterSlotHashUtil.calculateSlot(SAME_SLOT_KEY_1)), is(2L)); } - @Test(expected = UnsupportedOperationException.class) // DATAREDIS-316 - public void setWithOptionIfPresentShouldWorkCorrectly() { + @Test // DATAREDIS-315 + public void dbSizeForSpecificNodeShouldGetNodeDbSize() { - nativeConnection.set(KEY_1_BYTES, VALUE_1_BYTES); - clusterConnection.set(KEY_1_BYTES, VALUE_2_BYTES, Expiration.persistent(), SetOption.ifPresent()); + nativeConnection.set(KEY_1, VALUE_1); + nativeConnection.set(KEY_2, VALUE_2); + + assertThat(clusterConnection.dbSize(new RedisClusterNode("127.0.0.1", 7379, SlotRange.empty())), is(1L)); + assertThat(clusterConnection.dbSize(new RedisClusterNode("127.0.0.1", 7380, SlotRange.empty())), is(1L)); + assertThat(clusterConnection.dbSize(new RedisClusterNode("127.0.0.1", 7381, SlotRange.empty())), is(0L)); } - @Test // DATAREDIS-316 - public void setWithOptionIfAbsentShouldWorkCorrectly() { + @Test // DATAREDIS-315 + public void dbSizeShouldReturnCummulatedDbSize() { - clusterConnection.set(KEY_1_BYTES, VALUE_1_BYTES, Expiration.persistent(), SetOption.ifAbsent()); + nativeConnection.set(KEY_1, VALUE_1); + nativeConnection.set(KEY_2, VALUE_2); - assertThat(nativeConnection.exists(KEY_1_BYTES), is(true)); - assertThat(nativeConnection.ttl(KEY_1_BYTES), is(-1L)); + assertThat(clusterConnection.dbSize(), is(2L)); } - @Test // DATAREDIS-316 - public void setWithExpirationAndIfAbsentShouldWorkCorrectly() { + @Test // DATAREDIS-315 + public void decrByShouldDecreaseValueCorrectly() { - clusterConnection.set(KEY_1_BYTES, VALUE_1_BYTES, Expiration.seconds(1), SetOption.ifAbsent()); + nativeConnection.set(KEY_1, "5"); - assertThat(nativeConnection.exists(KEY_1_BYTES), is(true)); - assertThat(nativeConnection.ttl(KEY_1_BYTES), is(1L)); + assertThat(clusterConnection.decrBy(KEY_1_BYTES, 4), is(1L)); } - @Test // DATAREDIS-316 - public void setWithExpirationAndIfAbsentShouldNotBeAppliedWhenKeyExists() { + @Test // DATAREDIS-315 + public void decrShouldDecreaseValueCorrectly() { - nativeConnection.set(KEY_1_BYTES, VALUE_1_BYTES); + nativeConnection.set(KEY_1, "5"); - clusterConnection.set(KEY_1_BYTES, VALUE_2_BYTES, Expiration.seconds(1), SetOption.ifAbsent()); - - assertThat(nativeConnection.exists(KEY_1_BYTES), is(true)); - assertThat(nativeConnection.ttl(KEY_1_BYTES), is(-1L)); - assertThat(nativeConnection.get(KEY_1_BYTES), is(equalTo(VALUE_1_BYTES))); + assertThat(clusterConnection.decr(KEY_1_BYTES), is(4L)); } - @Test // DATAREDIS-316 - public void setWithExpirationAndIfPresentShouldWorkCorrectly() { + @Test // DATAREDIS-315 + public void delShouldRemoveMultipleKeysCorrectly() { - nativeConnection.set(KEY_1_BYTES, VALUE_1_BYTES); + nativeConnection.set(KEY_1, VALUE_1); + nativeConnection.set(KEY_2, VALUE_2); - clusterConnection.set(KEY_1_BYTES, VALUE_2_BYTES, Expiration.seconds(1), SetOption.ifPresent()); + clusterConnection.del(KEY_1_BYTES, KEY_2_BYTES); - assertThat(nativeConnection.exists(KEY_1_BYTES), is(true)); - assertThat(nativeConnection.ttl(KEY_1_BYTES), is(1L)); - assertThat(nativeConnection.get(KEY_1_BYTES), is(equalTo(VALUE_2_BYTES))); + assertThat(nativeConnection.get(KEY_1), nullValue()); + assertThat(nativeConnection.get(KEY_2), nullValue()); } - @Test // DATAREDIS-316 - public void setWithExpirationAndIfPresentShouldNotBeAppliedWhenKeyDoesNotExists() { + @Test // DATAREDIS-315 + public void delShouldRemoveMultipleKeysOnSameSlotCorrectly() { - clusterConnection.set(KEY_1_BYTES, VALUE_1_BYTES, Expiration.seconds(1), SetOption.ifPresent()); + nativeConnection.set(SAME_SLOT_KEY_1, VALUE_1); + nativeConnection.set(SAME_SLOT_KEY_2, VALUE_2); - assertThat(nativeConnection.exists(KEY_1_BYTES), is(false)); + clusterConnection.del(SAME_SLOT_KEY_1_BYTES, SAME_SLOT_KEY_2_BYTES); + + assertThat(nativeConnection.get(SAME_SLOT_KEY_1), nullValue()); + assertThat(nativeConnection.get(SAME_SLOT_KEY_2), nullValue()); } - @Test // DATAREDIS-438 - @IfProfileValue(name = "redisVersion", value = "3.2+") - public void geoAddSingleGeoLocation() { - assertThat(clusterConnection.geoAdd(KEY_1_BYTES, PALERMO), is(1L)); + @Test // DATAREDIS-315 + public void delShouldRemoveSingleKeyCorrectly() { + + nativeConnection.set(KEY_1, VALUE_1); + + clusterConnection.del(KEY_1_BYTES); + + assertThat(nativeConnection.get(KEY_1), nullValue()); + } + + @Test(expected = DataAccessException.class) // DATAREDIS-315 + public void discardShouldThrowException() { + clusterConnection.discard(); + } + + @Test // DATAREDIS-315 + public void dumpAndRestoreShouldWorkCorrectly() { + + nativeConnection.set(KEY_1, VALUE_1); + + byte[] dumpedValue = clusterConnection.dump(KEY_1_BYTES); + clusterConnection.restore(KEY_2_BYTES, 0, dumpedValue); + + assertThat(nativeConnection.get(KEY_2), is(VALUE_1)); + } + + @Test // DATAREDIS-315 + public void echoShouldReturnInputCorrectly() { + assertThat(clusterConnection.echo(VALUE_1_BYTES), is(VALUE_1_BYTES)); + } + + @Test(expected = DataAccessException.class) // DATAREDIS-315 + public void execShouldThrowException() { + clusterConnection.exec(); + } + + @Test // DATAREDIS-689 + public void executeWithArgs() { + + assertThat(clusterConnection.execute("SET", KEY_1_BYTES, VALUE_1_BYTES), is("OK".getBytes())); + + assertThat(nativeConnection.get(KEY_1), is(VALUE_1)); + } + + @Test // DATAREDIS-689 + public void executeWithKeyAndArgs() { + + assertThat(clusterConnection.execute("SET", KEY_1_BYTES, Collections.singletonList(VALUE_1_BYTES)), + is("OK".getBytes())); + + assertThat(nativeConnection.get(KEY_1), is(VALUE_1)); + } + + @Test(expected = IllegalArgumentException.class) // DATAREDIS-689 + public void executeWithNoKeyAndArgsThrowsException() { + clusterConnection.execute("KEYS", null, Collections.singletonList("*".getBytes())); + } + + @Test // DATAREDIS-529 + public void existsShouldCountSameKeyMultipleTimes() { + + nativeConnection.set(KEY_1, "true"); + + assertThat(clusterConnection.keyCommands().exists(KEY_1_BYTES, KEY_1_BYTES), is(2L)); + } + + @Test // DATAREDIS-529 + public void existsWithMultipleKeysShouldConsiderAbsentKeys() { + + assertThat(clusterConnection.keyCommands().exists("no-exist-1".getBytes(), "no-exist-2".getBytes()), is(0L)); + } + + @Test // DATAREDIS-529 + public void existsWithMultipleKeysShouldReturnResultCorrectly() { + + nativeConnection.set(KEY_1, "true"); + nativeConnection.set(KEY_2, "true"); + nativeConnection.set(KEY_3, "true"); + + assertThat(clusterConnection.keyCommands().exists(KEY_1_BYTES, KEY_2_BYTES, KEY_3_BYTES, "nonexistent".getBytes()), + is(3L)); + } + + @Test // DATAREDIS-315 + public void expireAtShouldBeSetCorrectly() { + + nativeConnection.set(KEY_1, VALUE_1); + + clusterConnection.expireAt(KEY_1_BYTES, System.currentTimeMillis() / 1000 + 5000); + + assertThat(nativeConnection.ttl(JedisConverters.toString(KEY_1_BYTES)) > 1, is(true)); + } + + @Test // DATAREDIS-315 + public void expireShouldBeSetCorreclty() { + + nativeConnection.set(KEY_1, VALUE_1); + + clusterConnection.expire(KEY_1_BYTES, 5); + + assertThat(nativeConnection.ttl(JedisConverters.toString(KEY_1_BYTES)) > 1, is(true)); + } + + @Test // DATAREDIS-315 + public void flushDbOnSingleNodeShouldFlushOnlyGivenNodesDb() { + + nativeConnection.set(KEY_1, VALUE_1); + nativeConnection.set(KEY_2, VALUE_2); + + clusterConnection.flushDb(new RedisClusterNode("127.0.0.1", 7379, SlotRange.empty())); + + assertThat(nativeConnection.get(KEY_1), notNullValue()); + assertThat(nativeConnection.get(KEY_2), nullValue()); + } + + @Test // DATAREDIS-315 + public void flushDbShouldFlushAllClusterNodes() { + + nativeConnection.set(KEY_1, VALUE_1); + nativeConnection.set(KEY_2, VALUE_2); + + clusterConnection.flushDb(); + + assertThat(nativeConnection.get(KEY_1), nullValue()); + assertThat(nativeConnection.get(KEY_2), nullValue()); } @Test // DATAREDIS-438 @@ -1953,6 +453,12 @@ public class JedisClusterConnectionTests implements ClusterConnectionTests { assertThat(clusterConnection.geoAdd(KEY_1_BYTES, Arrays.asList(PALERMO, ARIGENTO, CATANIA, PALERMO)), is(3L)); } + @Test // DATAREDIS-438 + @IfProfileValue(name = "redisVersion", value = "3.2+") + public void geoAddSingleGeoLocation() { + assertThat(clusterConnection.geoAdd(KEY_1_BYTES, PALERMO), is(1L)); + } + @Test // DATAREDIS-438 @IfProfileValue(name = "redisVersion", value = "3.2+") public void geoDist() { @@ -2040,14 +546,60 @@ public class JedisClusterConnectionTests implements ClusterConnectionTests { @Test // DATAREDIS-438 @IfProfileValue(name = "redisVersion", value = "3.2+") - public void geoRadiusShouldReturnMembersCorrectly() { + public void geoRadiusByMemberShouldApplyLimit() { + + nativeConnection.geoadd(KEY_1_BYTES, PALERMO.getPoint().getX(), PALERMO.getPoint().getY(), PALERMO.getName()); + nativeConnection.geoadd(KEY_1_BYTES, ARIGENTO.getPoint().getX(), ARIGENTO.getPoint().getY(), ARIGENTO.getName()); + nativeConnection.geoadd(KEY_1_BYTES, CATANIA.getPoint().getX(), CATANIA.getPoint().getY(), CATANIA.getName()); + + GeoResults> result = clusterConnection.geoRadiusByMember(KEY_1_BYTES, PALERMO.getName(), + new Distance(200, KILOMETERS), newGeoRadiusArgs().limit(2)); + + assertThat(result.getContent(), hasSize(2)); + } + + @Test // DATAREDIS-438 + @IfProfileValue(name = "redisVersion", value = "3.2+") + public void geoRadiusByMemberShouldReturnDistanceCorrectly() { + + nativeConnection.geoadd(KEY_1_BYTES, PALERMO.getPoint().getX(), PALERMO.getPoint().getY(), PALERMO.getName()); + nativeConnection.geoadd(KEY_1_BYTES, ARIGENTO.getPoint().getX(), ARIGENTO.getPoint().getY(), ARIGENTO.getName()); + nativeConnection.geoadd(KEY_1_BYTES, CATANIA.getPoint().getX(), CATANIA.getPoint().getY(), CATANIA.getName()); + + GeoResults> result = clusterConnection.geoRadiusByMember(KEY_1_BYTES, PALERMO.getName(), + new Distance(100, KILOMETERS), newGeoRadiusArgs().includeDistance()); + + assertThat(result.getContent(), hasSize(2)); + assertThat(result.getContent().get(0).getDistance().getValue(), is(closeTo(90.978D, 0.005))); + assertThat(result.getContent().get(0).getDistance().getUnit(), is("km")); + } + + @Test // DATAREDIS-438 + @IfProfileValue(name = "redisVersion", value = "3.2+") + public void geoRadiusByMemberShouldReturnMembersCorrectly() { + + nativeConnection.geoadd(KEY_1_BYTES, PALERMO.getPoint().getX(), PALERMO.getPoint().getY(), PALERMO.getName()); + nativeConnection.geoadd(KEY_1_BYTES, ARIGENTO.getPoint().getX(), ARIGENTO.getPoint().getY(), ARIGENTO.getName()); + nativeConnection.geoadd(KEY_1_BYTES, CATANIA.getPoint().getX(), CATANIA.getPoint().getY(), CATANIA.getName()); + + GeoResults> result = clusterConnection.geoRadiusByMember(KEY_1_BYTES, PALERMO.getName(), + new Distance(100, KILOMETERS), newGeoRadiusArgs().sortAscending()); + + assertThat(result.getContent().get(0).getContent().getName(), is(PALERMO.getName())); + assertThat(result.getContent().get(1).getContent().getName(), is(ARIGENTO.getName())); + } + + @Test // DATAREDIS-438 + @IfProfileValue(name = "redisVersion", value = "3.2+") + public void geoRadiusShouldApplyLimit() { nativeConnection.geoadd(KEY_1_BYTES, PALERMO.getPoint().getX(), PALERMO.getPoint().getY(), PALERMO.getName()); nativeConnection.geoadd(KEY_1_BYTES, ARIGENTO.getPoint().getX(), ARIGENTO.getPoint().getY(), ARIGENTO.getName()); nativeConnection.geoadd(KEY_1_BYTES, CATANIA.getPoint().getX(), CATANIA.getPoint().getY(), CATANIA.getName()); GeoResults> result = clusterConnection.geoRadius(KEY_1_BYTES, - new Circle(new Point(15D, 37D), new Distance(150D, KILOMETERS))); + new Circle(new Point(15D, 37D), new Distance(200D, KILOMETERS)), newGeoRadiusArgs().limit(2)); + assertThat(result.getContent(), hasSize(2)); } @@ -2069,60 +621,14 @@ public class JedisClusterConnectionTests implements ClusterConnectionTests { @Test // DATAREDIS-438 @IfProfileValue(name = "redisVersion", value = "3.2+") - public void geoRadiusShouldApplyLimit() { + public void geoRadiusShouldReturnMembersCorrectly() { nativeConnection.geoadd(KEY_1_BYTES, PALERMO.getPoint().getX(), PALERMO.getPoint().getY(), PALERMO.getName()); nativeConnection.geoadd(KEY_1_BYTES, ARIGENTO.getPoint().getX(), ARIGENTO.getPoint().getY(), ARIGENTO.getName()); nativeConnection.geoadd(KEY_1_BYTES, CATANIA.getPoint().getX(), CATANIA.getPoint().getY(), CATANIA.getName()); GeoResults> result = clusterConnection.geoRadius(KEY_1_BYTES, - new Circle(new Point(15D, 37D), new Distance(200D, KILOMETERS)), newGeoRadiusArgs().limit(2)); - - assertThat(result.getContent(), hasSize(2)); - } - - @Test // DATAREDIS-438 - @IfProfileValue(name = "redisVersion", value = "3.2+") - public void geoRadiusByMemberShouldReturnMembersCorrectly() { - - nativeConnection.geoadd(KEY_1_BYTES, PALERMO.getPoint().getX(), PALERMO.getPoint().getY(), PALERMO.getName()); - nativeConnection.geoadd(KEY_1_BYTES, ARIGENTO.getPoint().getX(), ARIGENTO.getPoint().getY(), ARIGENTO.getName()); - nativeConnection.geoadd(KEY_1_BYTES, CATANIA.getPoint().getX(), CATANIA.getPoint().getY(), CATANIA.getName()); - - GeoResults> result = clusterConnection.geoRadiusByMember(KEY_1_BYTES, PALERMO.getName(), - new Distance(100, KILOMETERS), newGeoRadiusArgs().sortAscending()); - - assertThat(result.getContent().get(0).getContent().getName(), is(PALERMO.getName())); - assertThat(result.getContent().get(1).getContent().getName(), is(ARIGENTO.getName())); - } - - @Test // DATAREDIS-438 - @IfProfileValue(name = "redisVersion", value = "3.2+") - public void geoRadiusByMemberShouldReturnDistanceCorrectly() { - - nativeConnection.geoadd(KEY_1_BYTES, PALERMO.getPoint().getX(), PALERMO.getPoint().getY(), PALERMO.getName()); - nativeConnection.geoadd(KEY_1_BYTES, ARIGENTO.getPoint().getX(), ARIGENTO.getPoint().getY(), ARIGENTO.getName()); - nativeConnection.geoadd(KEY_1_BYTES, CATANIA.getPoint().getX(), CATANIA.getPoint().getY(), CATANIA.getName()); - - GeoResults> result = clusterConnection.geoRadiusByMember(KEY_1_BYTES, PALERMO.getName(), - new Distance(100, KILOMETERS), newGeoRadiusArgs().includeDistance()); - - assertThat(result.getContent(), hasSize(2)); - assertThat(result.getContent().get(0).getDistance().getValue(), is(closeTo(90.978D, 0.005))); - assertThat(result.getContent().get(0).getDistance().getUnit(), is("km")); - } - - @Test // DATAREDIS-438 - @IfProfileValue(name = "redisVersion", value = "3.2+") - public void geoRadiusByMemberShouldApplyLimit() { - - nativeConnection.geoadd(KEY_1_BYTES, PALERMO.getPoint().getX(), PALERMO.getPoint().getY(), PALERMO.getName()); - nativeConnection.geoadd(KEY_1_BYTES, ARIGENTO.getPoint().getX(), ARIGENTO.getPoint().getY(), ARIGENTO.getName()); - nativeConnection.geoadd(KEY_1_BYTES, CATANIA.getPoint().getX(), CATANIA.getPoint().getY(), CATANIA.getName()); - - GeoResults> result = clusterConnection.geoRadiusByMember(KEY_1_BYTES, PALERMO.getName(), - new Distance(200, KILOMETERS), newGeoRadiusArgs().limit(2)); - + new Circle(new Point(15D, 37D), new Distance(150D, KILOMETERS))); assertThat(result.getContent(), hasSize(2)); } @@ -2137,52 +643,223 @@ public class JedisClusterConnectionTests implements ClusterConnectionTests { assertThat(clusterConnection.geoRemove(KEY_1_BYTES, ARIGENTO.getName()), is(1L)); } - @Test // DATAREDIS-529 - public void testExistsWithMultipleKeys() { + @Test // DATAREDIS-315 + public void getBitShouldWorkCorrectly() { - nativeConnection.set(KEY_1, "true"); - nativeConnection.set(KEY_2, "true"); - nativeConnection.set(KEY_3, "true"); + nativeConnection.setbit(KEY_1, 0, true); + nativeConnection.setbit(KEY_1, 1, false); - assertThat(clusterConnection.keyCommands() - .exists(Arrays.asList(KEY_1_BYTES, KEY_2_BYTES, KEY_3_BYTES, "nonexistent".getBytes())), is(3L)); + assertThat(clusterConnection.getBit(KEY_1_BYTES, 0), is(true)); + assertThat(clusterConnection.getBit(KEY_1_BYTES, 1), is(false)); } - @Test // DATAREDIS-529 - public void testExistsWithMultipleKeysNoneExists() { - - assertThat(clusterConnection.keyCommands().exists(Arrays.asList("no-exist-1".getBytes(), "no-exist-2".getBytes())), - is(0L)); + @Test // DATAREDIS-315 + public void getClusterNodeForKeyShouldReturnNodeCorrectly() { + assertThat((RedisNode) clusterConnection.clusterGetNodeForKey(KEY_1_BYTES), is(new RedisNode("127.0.0.1", 7380))); } - @Test // DATAREDIS-529 - public void testExistsSameKeyMultipleTimes() { + @Test // DATAREDIS-315, DATAREDIS-661 + public void getConfigShouldLoadConfigurationOfSpecificNode() { - nativeConnection.set(KEY_1, "true"); + Properties result = clusterConnection.getConfig(new RedisClusterNode(CLUSTER_HOST, SLAVEOF_NODE_1_PORT), "*"); - assertThat(clusterConnection.keyCommands().exists(Arrays.asList(KEY_1_BYTES, KEY_1_BYTES)), is(2L)); + assertThat(result.getProperty("slaveof"), endsWith("7379")); } - @Test(expected = IllegalArgumentException.class) // DATAREDIS-689 - public void executeWithNoKeyAndArgsThrowsException() { - clusterConnection.execute("KEYS", null, Collections.singletonList("*".getBytes())); + @Test // DATAREDIS-315, DATAREDIS-661 + public void getConfigShouldLoadCumulatedConfiguration() { + + Properties result = clusterConnection.getConfig("*max-*-entries*"); + + // config get *max-*-entries on redis 3.0.7 returns 8 entries per node while on 3.2.0-rc3 returns 6. + // @link https://github.com/spring-projects/spring-data-redis/pull/187 + assertThat(result.size() % 3, is(0)); + + for (Object o : result.keySet()) { + + assertThat(o.toString(), startsWith(CLUSTER_HOST)); + assertThat(result.getProperty(o.toString()), not(startsWith(CLUSTER_HOST))); + } } - @Test // DATAREDIS-689 - public void executeWithArgs() { + @Test // DATAREDIS-315 + public void getRangeShouldReturnValueCorrectly() { - assertThat(clusterConnection.execute("SET", KEY_1_BYTES, VALUE_1_BYTES), is("OK".getBytes())); + nativeConnection.set(KEY_1, VALUE_1); - assertThat(nativeConnection.get(KEY_1), is(VALUE_1)); + assertThat(clusterConnection.getRange(KEY_1_BYTES, 0, 2), is(JedisConverters.toBytes("val"))); } - @Test // DATAREDIS-689 - public void executeWithKeyAndArgs() { + @Test // DATAREDIS-315 + public void getSetShouldWorkCorrectly() { - assertThat(clusterConnection.execute("SET", KEY_1_BYTES, Collections.singletonList(VALUE_1_BYTES)), - is("OK".getBytes())); + nativeConnection.set(KEY_1, VALUE_1); - assertThat(nativeConnection.get(KEY_1), is(VALUE_1)); + byte[] valueBeforeSet = clusterConnection.getSet(KEY_1_BYTES, VALUE_2_BYTES); + + assertThat(valueBeforeSet, is(VALUE_1_BYTES)); + assertThat(nativeConnection.get(KEY_1), is(VALUE_2)); + } + + @Test // DATAREDIS-315 + public void getShouldReturnValueCorrectly() { + + nativeConnection.set(KEY_1, VALUE_1); + + assertThat(clusterConnection.get(KEY_1_BYTES), is(VALUE_1_BYTES)); + } + + @Test // DATAREDIS-315 + public void hDelShouldRemoveFieldsCorrectly() { + + nativeConnection.hset(KEY_1_BYTES, KEY_2_BYTES, VALUE_1_BYTES); + nativeConnection.hset(KEY_1_BYTES, KEY_3_BYTES, VALUE_2_BYTES); + + clusterConnection.hDel(KEY_1_BYTES, KEY_2_BYTES); + + assertThat(nativeConnection.hexists(KEY_1_BYTES, KEY_2_BYTES), is(false)); + assertThat(nativeConnection.hexists(KEY_1_BYTES, KEY_3_BYTES), is(true)); + } + + @Test // DATAREDIS-315 + public void hExistsShouldReturnPresenceOfFieldCorrectly() { + + nativeConnection.hset(KEY_1_BYTES, KEY_2_BYTES, VALUE_1_BYTES); + + assertThat(clusterConnection.hExists(KEY_1_BYTES, KEY_2_BYTES), is(true)); + assertThat(clusterConnection.hExists(KEY_1_BYTES, KEY_3_BYTES), is(false)); + assertThat(clusterConnection.hExists(JedisConverters.toBytes("foo"), KEY_2_BYTES), is(false)); + } + + @Test // DATAREDIS-315 + public void hGetAllShouldRetrieveEntriesCorrectly() { + + Map hashes = new HashMap<>(); + hashes.put(KEY_2_BYTES, VALUE_1_BYTES); + hashes.put(KEY_3_BYTES, VALUE_2_BYTES); + + nativeConnection.hmset(KEY_1_BYTES, hashes); + + Map hGetAll = clusterConnection.hGetAll(KEY_1_BYTES); + + assertThat(hGetAll.containsKey(KEY_2_BYTES), is(true)); + assertThat(hGetAll.containsKey(KEY_3_BYTES), is(true)); + } + + @Test // DATAREDIS-315 + public void hGetShouldRetrieveValueCorrectly() { + + nativeConnection.hset(KEY_1_BYTES, KEY_2_BYTES, VALUE_1_BYTES); + + assertThat(clusterConnection.hGet(KEY_1_BYTES, KEY_2_BYTES), is(VALUE_1_BYTES)); + } + + @Test // DATAREDIS-315 + public void hIncrByFloatShouldIncreaseFieldCorretly() { + + nativeConnection.hset(KEY_1_BYTES, KEY_2_BYTES, JedisConverters.toBytes(1L)); + nativeConnection.hset(KEY_1_BYTES, KEY_3_BYTES, JedisConverters.toBytes(2L)); + + clusterConnection.hIncrBy(KEY_1_BYTES, KEY_3_BYTES, 3.5D); + + assertThat(nativeConnection.hget(KEY_1_BYTES, KEY_3_BYTES), is(JedisConverters.toBytes(5.5D))); + } + + @Test // DATAREDIS-315 + public void hIncrByShouldIncreaseFieldCorretly() { + + nativeConnection.hset(KEY_1_BYTES, KEY_2_BYTES, JedisConverters.toBytes(1L)); + nativeConnection.hset(KEY_1_BYTES, KEY_3_BYTES, JedisConverters.toBytes(2L)); + + clusterConnection.hIncrBy(KEY_1_BYTES, KEY_3_BYTES, 3); + + assertThat(nativeConnection.hget(KEY_1_BYTES, KEY_3_BYTES), is(JedisConverters.toBytes(5L))); + } + + @Test // DATAREDIS-315 + public void hKeysShouldRetrieveKeysCorrectly() { + + nativeConnection.hset(KEY_1_BYTES, KEY_2_BYTES, VALUE_1_BYTES); + nativeConnection.hset(KEY_1_BYTES, KEY_3_BYTES, VALUE_2_BYTES); + + assertThat(clusterConnection.hKeys(KEY_1_BYTES), hasItems(KEY_2_BYTES, KEY_3_BYTES)); + } + + @Test // DATAREDIS-315 + public void hLenShouldRetrieveSizeCorrectly() { + + nativeConnection.hset(KEY_1_BYTES, KEY_2_BYTES, VALUE_1_BYTES); + nativeConnection.hset(KEY_1_BYTES, KEY_3_BYTES, VALUE_2_BYTES); + + assertThat(clusterConnection.hLen(KEY_1_BYTES), is(2L)); + } + + @Test // DATAREDIS-315 + public void hMGetShouldRetrieveValueCorrectly() { + + nativeConnection.hset(KEY_1_BYTES, KEY_2_BYTES, VALUE_1_BYTES); + nativeConnection.hset(KEY_1_BYTES, KEY_3_BYTES, VALUE_2_BYTES); + + assertThat(clusterConnection.hMGet(KEY_1_BYTES, KEY_2_BYTES, KEY_3_BYTES), hasItems(VALUE_1_BYTES, VALUE_2_BYTES)); + } + + @Test // DATAREDIS-315 + public void hMSetShouldAddValuesCorrectly() { + + Map hashes = new HashMap<>(); + hashes.put(KEY_2_BYTES, VALUE_1_BYTES); + hashes.put(KEY_3_BYTES, VALUE_2_BYTES); + + clusterConnection.hMSet(KEY_1_BYTES, hashes); + + assertThat(nativeConnection.hmget(KEY_1_BYTES, KEY_2_BYTES, KEY_3_BYTES), hasItems(VALUE_1_BYTES, VALUE_2_BYTES)); + } + + @Test // DATAREDIS-479 + public void hScanShouldReadEntireValueRange() { + + int nrOfValues = 321; + for (int i = 0; i < nrOfValues; i++) { + nativeConnection.hset(KEY_1_BYTES, JedisConverters.toBytes("key" + i), JedisConverters.toBytes("value-" + i)); + } + + Cursor> cursor = clusterConnection.hScan(KEY_1_BYTES, + scanOptions().match("key*").build()); + + int i = 0; + while (cursor.hasNext()) { + + cursor.next(); + i++; + } + + assertThat(i, is(nrOfValues)); + } + + @Test // DATAREDIS-315 + public void hSetNXShouldNotSetValueWhenAlreadyExists() { + + nativeConnection.hset(KEY_1_BYTES, KEY_2_BYTES, VALUE_1_BYTES); + + clusterConnection.hSetNX(KEY_1_BYTES, KEY_2_BYTES, VALUE_2_BYTES); + + assertThat(nativeConnection.hget(KEY_1_BYTES, KEY_2_BYTES), is(VALUE_1_BYTES)); + } + + @Test // DATAREDIS-315 + public void hSetNXShouldSetValueCorrectly() { + + clusterConnection.hSetNX(KEY_1_BYTES, KEY_2_BYTES, VALUE_1_BYTES); + + assertThat(nativeConnection.hget(KEY_1_BYTES, KEY_2_BYTES), is(VALUE_1_BYTES)); + } + + @Test // DATAREDIS-315 + public void hSetShouldSetValueCorrectly() { + + clusterConnection.hSet(KEY_1_BYTES, KEY_2_BYTES, VALUE_1_BYTES); + + assertThat(nativeConnection.hget(KEY_1_BYTES, KEY_2_BYTES), is(VALUE_1_BYTES)); } @Test // DATAREDIS-698 @@ -2205,4 +882,1317 @@ public class JedisClusterConnectionTests implements ClusterConnectionTests { public void hStrLenReturnsZeroWhenKeyDoesNotExist() { assertThat(clusterConnection.hashCommands().hStrLen(KEY_1_BYTES, KEY_1_BYTES), is(0L)); } + + @Test // DATAREDIS-315 + public void hValsShouldRetrieveValuesCorrectly() { + + nativeConnection.hset(KEY_1_BYTES, KEY_2_BYTES, VALUE_1_BYTES); + nativeConnection.hset(KEY_1_BYTES, KEY_3_BYTES, VALUE_2_BYTES); + + assertThat(clusterConnection.hVals(KEY_1_BYTES), hasItems(VALUE_1_BYTES, VALUE_2_BYTES)); + } + + @Test // DATAREDIS-315 + public void incrByFloatShouldIncreaseValueCorrectly() { + + nativeConnection.set(KEY_1, "1"); + + assertThat(clusterConnection.incrBy(KEY_1_BYTES, 5.5D), is(6.5D)); + } + + @Test // DATAREDIS-315 + public void incrByShouldIncreaseValueCorrectly() { + + nativeConnection.set(KEY_1, "1"); + + assertThat(clusterConnection.incrBy(KEY_1_BYTES, 5), is(6L)); + } + + @Test // DATAREDIS-315 + public void incrShouldIncreaseValueCorrectly() { + + nativeConnection.set(KEY_1, "1"); + + assertThat(clusterConnection.incr(KEY_1_BYTES), is(2L)); + } + + @Test // DATAREDIS-315 + public void infoShouldCollectInfoForSpecificNode() { + + Properties properties = clusterConnection.info(new RedisClusterNode(CLUSTER_HOST, MASTER_NODE_2_PORT)); + + assertThat(properties.getProperty("tcp_port"), is(Integer.toString(MASTER_NODE_2_PORT))); + } + + @Test // DATAREDIS-315 + public void infoShouldCollectInfoForSpecificNodeAndSection() { + + Properties properties = clusterConnection.info(new RedisClusterNode(CLUSTER_HOST, MASTER_NODE_2_PORT), "server"); + + assertThat(properties.getProperty("tcp_port"), is(Integer.toString(MASTER_NODE_2_PORT))); + assertThat(properties.getProperty("used_memory"), nullValue()); + } + + @Test // DATAREDIS-315, DATAREDIS-685 + public void infoShouldCollectionInfoFromAllClusterNodes() { + + Properties singleNodeInfo = clusterConnection.serverCommands().info(new RedisClusterNode("127.0.0.1", 7380)); + assertThat(Double.valueOf(clusterConnection.serverCommands().info().size()), + closeTo(singleNodeInfo.size() * 3, 12d)); + } + + @Test // DATAREDIS-315 + public void keysShouldReturnAllKeys() { + + nativeConnection.set(KEY_1, VALUE_1); + nativeConnection.set(KEY_2, VALUE_2); + + assertThat(clusterConnection.keys(JedisConverters.toBytes("*")), hasItems(KEY_1_BYTES, KEY_2_BYTES)); + } + + @Test // DATAREDIS-315 + public void keysShouldReturnAllKeysForSpecificNode() { + + nativeConnection.set(KEY_1, VALUE_1); + nativeConnection.set(KEY_2, VALUE_2); + + Set keysOnNode = clusterConnection.keys(new RedisClusterNode("127.0.0.1", 7379, SlotRange.empty()), + JedisConverters.toBytes("*")); + + assertThat(keysOnNode, hasItems(KEY_2_BYTES)); + assertThat(keysOnNode, not(hasItems(KEY_1_BYTES))); + } + + @Test // DATAREDIS-315 + public void lIndexShouldGetElementAtIndexCorrectly() { + + nativeConnection.rpush(KEY_1, VALUE_1, VALUE_2, "foo", "bar"); + + assertThat(clusterConnection.lIndex(KEY_1_BYTES, 1), is(VALUE_2_BYTES)); + } + + @Test // DATAREDIS-315 + public void lInsertShouldAddElementAtPositionCorrectly() { + + nativeConnection.rpush(KEY_1, VALUE_1, VALUE_2, "foo", "bar"); + + clusterConnection.lInsert(KEY_1_BYTES, Position.AFTER, VALUE_2_BYTES, JedisConverters.toBytes("booh!")); + + assertThat(nativeConnection.lrange(KEY_1, 0, -1).get(2), is("booh!")); + } + + @Test // DATAREDIS-315 + public void lLenShouldCountValuesCorrectly() { + + nativeConnection.lpush(KEY_1, VALUE_1, VALUE_2); + + assertThat(clusterConnection.lLen(KEY_1_BYTES), is(2L)); + } + + @Test // DATAREDIS-315 + public void lPopShouldReturnElementCorrectly() { + + nativeConnection.rpush(KEY_1, VALUE_1, VALUE_2); + + assertThat(clusterConnection.lPop(KEY_1_BYTES), is(VALUE_1_BYTES)); + } + + @Test // DATAREDIS-315 + public void lPushNXShoultNotAddValuesWhenKeyDoesNotExist() { + + clusterConnection.lPushX(KEY_1_BYTES, VALUE_1_BYTES); + + assertThat(nativeConnection.exists(KEY_1), is(false)); + } + + @Test // DATAREDIS-315 + public void lPushShoultAddValuesCorrectly() { + + clusterConnection.lPush(KEY_1_BYTES, VALUE_1_BYTES, VALUE_2_BYTES); + + assertThat(nativeConnection.lrange(KEY_1, 0, -1), hasItems(VALUE_1, VALUE_2)); + } + + @Test // DATAREDIS-315 + public void lRangeShouldGetValuesCorrectly() { + + nativeConnection.lpush(KEY_1, VALUE_1, VALUE_2); + + assertThat(clusterConnection.lRange(KEY_1_BYTES, 0L, -1L), hasItems(VALUE_1_BYTES, VALUE_2_BYTES)); + } + + @Test // DATAREDIS-315 + public void lRemShouldRemoveElementAtPositionCorrectly() { + + nativeConnection.rpush(KEY_1, VALUE_1, VALUE_2, "foo", "bar"); + + clusterConnection.lRem(KEY_1_BYTES, 1L, VALUE_1_BYTES); + + assertThat(nativeConnection.llen(KEY_1), is(3L)); + } + + @Test // DATAREDIS-315 + public void lSetShouldSetElementAtPositionCorrectly() { + + nativeConnection.rpush(KEY_1, VALUE_1, VALUE_2, "foo", "bar"); + + clusterConnection.lSet(KEY_1_BYTES, 1L, VALUE_1_BYTES); + + assertThat(nativeConnection.lrange(KEY_1, 0, -1).get(1), is(VALUE_1)); + } + + @Test // DATAREDIS-315 + public void lTrimShouldTrimListCorrectly() { + + nativeConnection.lpush(KEY_1, VALUE_1, VALUE_2, "foo", "bar"); + + clusterConnection.lTrim(KEY_1_BYTES, 2, 3); + + assertThat(nativeConnection.lrange(KEY_1, 0, -1), hasItems(VALUE_1, VALUE_2)); + } + + @Test // DATAREDIS-315 + public void mGetShouldReturnCorrectlyWhenKeysDoNotMapToSameSlot() { + + nativeConnection.set(KEY_1_BYTES, VALUE_1_BYTES); + nativeConnection.set(KEY_2_BYTES, VALUE_2_BYTES); + + assertThat(clusterConnection.mGet(KEY_1_BYTES, KEY_2_BYTES), contains(VALUE_1_BYTES, VALUE_2_BYTES)); + } + + @Test // DATAREDIS-315 + public void mGetShouldReturnCorrectlyWhenKeysMapToSameSlot() { + + nativeConnection.set(SAME_SLOT_KEY_1_BYTES, VALUE_1_BYTES); + nativeConnection.set(SAME_SLOT_KEY_2_BYTES, VALUE_2_BYTES); + + assertThat(clusterConnection.mGet(SAME_SLOT_KEY_1_BYTES, SAME_SLOT_KEY_2_BYTES), + contains(VALUE_1_BYTES, VALUE_2_BYTES)); + } + + @Test // DATAREDIS-315 + public void mSetNXShouldReturnFalseIfNotAllKeysSet() { + + nativeConnection.set(KEY_2_BYTES, VALUE_3_BYTES); + Map map = new LinkedHashMap<>(); + map.put(KEY_1_BYTES, VALUE_1_BYTES); + map.put(KEY_2_BYTES, VALUE_2_BYTES); + + assertThat(clusterConnection.mSetNX(map), is(false)); + + assertThat(nativeConnection.get(KEY_1), is(VALUE_1)); + assertThat(nativeConnection.get(KEY_2), is(VALUE_3)); + } + + @Test // DATAREDIS-315 + public void mSetNXShouldReturnTrueIfAllKeysSet() { + + Map map = new LinkedHashMap<>(); + map.put(KEY_1_BYTES, VALUE_1_BYTES); + map.put(KEY_2_BYTES, VALUE_2_BYTES); + + assertThat(clusterConnection.mSetNX(map), is(true)); + + assertThat(nativeConnection.get(KEY_1), is(VALUE_1)); + assertThat(nativeConnection.get(KEY_2), is(VALUE_2)); + } + + @Test // DATAREDIS-315 + public void mSetNXShouldWorkForOnSameSlotKeys() { + + Map map = new LinkedHashMap<>(); + map.put(SAME_SLOT_KEY_1_BYTES, VALUE_1_BYTES); + map.put(SAME_SLOT_KEY_2_BYTES, VALUE_2_BYTES); + + assertThat(clusterConnection.mSetNX(map), is(true)); + + assertThat(nativeConnection.get(SAME_SLOT_KEY_1), is(VALUE_1)); + assertThat(nativeConnection.get(SAME_SLOT_KEY_2), is(VALUE_2)); + } + + @Test // DATAREDIS-315 + public void mSetShouldWorkWhenKeysDoNotMapToSameSlot() { + + Map map = new LinkedHashMap<>(); + map.put(KEY_1_BYTES, VALUE_1_BYTES); + map.put(KEY_2_BYTES, VALUE_2_BYTES); + + clusterConnection.mSet(map); + + assertThat(nativeConnection.get(KEY_1), is(VALUE_1)); + assertThat(nativeConnection.get(KEY_2), is(VALUE_2)); + } + + @Test // DATAREDIS-315 + public void mSetShouldWorkWhenKeysMapToSameSlot() { + + Map map = new LinkedHashMap<>(); + map.put(SAME_SLOT_KEY_1_BYTES, VALUE_1_BYTES); + map.put(SAME_SLOT_KEY_2_BYTES, VALUE_2_BYTES); + + clusterConnection.mSet(map); + + assertThat(nativeConnection.get(SAME_SLOT_KEY_1), is(VALUE_1)); + assertThat(nativeConnection.get(SAME_SLOT_KEY_2), is(VALUE_2)); + } + + @Test(expected = UnsupportedOperationException.class) // DATAREDIS-315 + public void moveShouldNotBeSupported() { + clusterConnection.move(KEY_1_BYTES, 3); + } + + @Test(expected = DataAccessException.class) // DATAREDIS-315 + public void multiShouldThrowException() { + clusterConnection.multi(); + } + + @Test // DATAREDIS-315 + public void pExpireAtShouldBeSetCorrectly() { + + nativeConnection.set(KEY_1, VALUE_1); + + clusterConnection.pExpireAt(KEY_1_BYTES, System.currentTimeMillis() + 5000); + + assertThat(nativeConnection.ttl(JedisConverters.toString(KEY_1_BYTES)) > 1, is(true)); + } + + @Test // DATAREDIS-315 + public void pExpireShouldBeSetCorreclty() { + + nativeConnection.set(KEY_1, VALUE_1); + + clusterConnection.pExpire(KEY_1_BYTES, 5000); + + assertThat(nativeConnection.ttl(JedisConverters.toString(KEY_1_BYTES)) > 1, is(true)); + } + + @Test // DATAREDIS-315 + public void pSetExShouldSetValueCorrectly() { + + clusterConnection.pSetEx(KEY_1_BYTES, 5000, VALUE_1_BYTES); + + assertThat(nativeConnection.get(KEY_1), is(VALUE_1)); + assertThat(nativeConnection.ttl(KEY_1) > 1, is(true)); + } + + @Test // DATAREDIS-315 + public void pTtlShouldReturValueCorrectly() { + + nativeConnection.set(KEY_1, VALUE_1); + nativeConnection.expire(KEY_1, 5); + + assertThat(clusterConnection.pTtl(KEY_1_BYTES) > 1, is(true)); + } + + @Test // DATAREDIS-315 + public void pTtlShouldReturnMinusOneWhenKeyDoesNotHaveExpirationSet() { + + nativeConnection.set(KEY_1, VALUE_1); + + assertThat(clusterConnection.pTtl(KEY_1_BYTES), is(-1L)); + } + + @Test // DATAREDIS-315 + public void pTtlShouldReturnMinusTwoWhenKeyDoesNotExist() { + assertThat(clusterConnection.pTtl(KEY_1_BYTES), is(-2L)); + } + + @Test // DATAREDIS-526 + public void pTtlWithTimeUnitShouldReturnMinusTwoWhenKeyDoesNotExist() { + assertThat(clusterConnection.pTtl(KEY_1_BYTES, TimeUnit.HOURS), is(-2L)); + } + + @Test // DATAREDIS-315 + public void persistShouldRemoveTTL() { + + nativeConnection.setex(KEY_1_BYTES, 10, VALUE_1_BYTES); + + assertThat(clusterConnection.persist(KEY_1_BYTES), is(Boolean.TRUE)); + assertThat(nativeConnection.ttl(KEY_1_BYTES), is(-1L)); + } + + @Test // DATAREDIS-315 + public void pfAddShouldAddValuesCorrectly() { + + clusterConnection.pfAdd(KEY_1_BYTES, VALUE_1_BYTES, VALUE_2_BYTES, VALUE_3_BYTES); + + assertThat(nativeConnection.pfcount(KEY_1_BYTES), is(3L)); + } + + @Test // DATAREDIS-315 + public void pfCountShouldAllowCountingOnSameSlotKeys() { + + nativeConnection.pfadd(SAME_SLOT_KEY_1, VALUE_1, VALUE_2); + nativeConnection.pfadd(SAME_SLOT_KEY_2, VALUE_2, VALUE_3); + + assertThat(clusterConnection.pfCount(SAME_SLOT_KEY_1_BYTES, SAME_SLOT_KEY_2_BYTES), is(3L)); + } + + @Test // DATAREDIS-315 + public void pfCountShouldAllowCountingOnSingleKey() { + + nativeConnection.pfadd(KEY_1, VALUE_1, VALUE_2, VALUE_3); + + assertThat(clusterConnection.pfCount(KEY_1_BYTES), is(3L)); + } + + @Test(expected = DataAccessException.class) // DATAREDIS-315 + public void pfCountShouldThrowErrorCountingOnDifferentSlotKeys() { + + nativeConnection.pfadd(KEY_1, VALUE_1, VALUE_2); + nativeConnection.pfadd(KEY_2, VALUE_2, VALUE_3); + + clusterConnection.pfCount(KEY_1_BYTES, KEY_2_BYTES); + } + + @Test(expected = DataAccessException.class) // DATAREDIS-315 + public void pfMergeShouldThrowErrorOnDifferentSlotKeys() { + clusterConnection.pfMerge(KEY_3_BYTES, KEY_1_BYTES, KEY_2_BYTES); + } + + @Test // DATAREDIS-315 + public void pfMergeShouldWorkWhenAllKeysMapToSameSlot() { + + nativeConnection.pfadd(SAME_SLOT_KEY_1, VALUE_1, VALUE_2); + nativeConnection.pfadd(SAME_SLOT_KEY_2, VALUE_2, VALUE_3); + + clusterConnection.pfMerge(SAME_SLOT_KEY_3_BYTES, SAME_SLOT_KEY_1_BYTES, SAME_SLOT_KEY_2_BYTES); + + assertThat(nativeConnection.pfcount(SAME_SLOT_KEY_3), is(3L)); + } + + @Test // DATAREDIS-315 + public void pingShouldRetrunPong() { + assertThat(clusterConnection.ping(), is("PONG")); + } + + @Test // DATAREDIS-315 + public void pingShouldRetrunPongForExistingNode() { + assertThat(clusterConnection.ping(new RedisClusterNode("127.0.0.1", 7379, SlotRange.empty())), is("PONG")); + } + + @Test(expected = IllegalArgumentException.class) // DATAREDIS-315 + public void pingShouldThrowExceptionWhenNodeNotKnownToCluster() { + clusterConnection.ping(new RedisClusterNode("127.0.0.1", 1234, null)); + } + + @Test // DATAREDIS-315 + public void rPopLPushShouldWorkWhenDoNotMapToSameSlot() { + + nativeConnection.lpush(KEY_1_BYTES, VALUE_1_BYTES, VALUE_2_BYTES); + + assertThat(clusterConnection.rPopLPush(KEY_1_BYTES, KEY_2_BYTES), is(VALUE_1_BYTES)); + assertThat(nativeConnection.exists(KEY_2_BYTES), is(true)); + } + + @Test // DATAREDIS-315 + public void rPopLPushShouldWorkWhenKeysOnSameSlot() { + + nativeConnection.lpush(SAME_SLOT_KEY_1_BYTES, VALUE_1_BYTES, VALUE_2_BYTES); + + assertThat(clusterConnection.rPopLPush(SAME_SLOT_KEY_1_BYTES, SAME_SLOT_KEY_2_BYTES), is(VALUE_1_BYTES)); + assertThat(nativeConnection.exists(SAME_SLOT_KEY_2_BYTES), is(true)); + } + + @Test // DATAREDIS-315 + public void rPopShouldReturnElementCorrectly() { + + nativeConnection.rpush(KEY_1, VALUE_1, VALUE_2); + + assertThat(clusterConnection.rPop(KEY_1_BYTES), is(VALUE_2_BYTES)); + } + + @Test // DATAREDIS-315 + public void rPushNXShoultNotAddValuesWhenKeyDoesNotExist() { + + clusterConnection.rPushX(KEY_1_BYTES, VALUE_1_BYTES); + + assertThat(nativeConnection.exists(KEY_1), is(false)); + } + + @Test // DATAREDIS-315 + public void rPushShoultAddValuesCorrectly() { + + clusterConnection.rPush(KEY_1_BYTES, VALUE_1_BYTES, VALUE_2_BYTES); + + assertThat(nativeConnection.lrange(KEY_1, 0, -1), hasItems(VALUE_1, VALUE_2)); + } + + @Test // DATAREDIS-315 + public void randomKeyShouldReturnCorrectlyWhenKeysAvailable() { + + nativeConnection.set(KEY_1, VALUE_1); + nativeConnection.set(KEY_2, VALUE_2); + + assertThat(clusterConnection.randomKey(), notNullValue()); + } + + @Test // DATAREDIS-315 + public void randomKeyShouldReturnNullWhenNoKeysAvailable() { + assertThat(clusterConnection.randomKey(), nullValue()); + } + + @Test // DATAREDIS-315 + public void rename() { + + nativeConnection.set(KEY_1_BYTES, VALUE_1_BYTES); + + clusterConnection.rename(KEY_1_BYTES, KEY_2_BYTES); + + assertThat(nativeConnection.exists(KEY_1_BYTES), is(false)); + assertThat(nativeConnection.get(KEY_2_BYTES), is(VALUE_1_BYTES)); + } + + @Test // DATAREDIS-315 + public void renameNXWhenOnSameSlot() { + + nativeConnection.set(SAME_SLOT_KEY_1_BYTES, VALUE_1_BYTES); + + assertThat(clusterConnection.renameNX(SAME_SLOT_KEY_1_BYTES, SAME_SLOT_KEY_2_BYTES), is(Boolean.TRUE)); + + assertThat(nativeConnection.exists(SAME_SLOT_KEY_1_BYTES), is(false)); + assertThat(nativeConnection.get(SAME_SLOT_KEY_2_BYTES), is(VALUE_1_BYTES)); + } + + @Test // DATAREDIS-315 + public void renameNXWhenTargetKeyDoesExist() { + + nativeConnection.set(KEY_1_BYTES, VALUE_1_BYTES); + nativeConnection.set(KEY_2_BYTES, VALUE_2_BYTES); + + assertThat(clusterConnection.renameNX(KEY_1_BYTES, KEY_2_BYTES), is(Boolean.FALSE)); + + assertThat(nativeConnection.get(KEY_1_BYTES), is(VALUE_1_BYTES)); + assertThat(nativeConnection.get(KEY_2_BYTES), is(VALUE_2_BYTES)); + } + + @Test // DATAREDIS-315 + public void renameNXWhenTargetKeyDoesNotExist() { + + nativeConnection.set(KEY_1_BYTES, VALUE_1_BYTES); + + assertThat(clusterConnection.renameNX(KEY_1_BYTES, KEY_2_BYTES), is(Boolean.TRUE)); + + assertThat(nativeConnection.exists(KEY_1_BYTES), is(false)); + assertThat(nativeConnection.get(KEY_2_BYTES), is(VALUE_1_BYTES)); + } + + @Test // DATAREDIS-315 + public void renameSameKeysOnSameSlot() { + + nativeConnection.set(SAME_SLOT_KEY_1_BYTES, VALUE_1_BYTES); + + clusterConnection.rename(SAME_SLOT_KEY_1_BYTES, SAME_SLOT_KEY_2_BYTES); + + assertThat(nativeConnection.exists(SAME_SLOT_KEY_1_BYTES), is(false)); + assertThat(nativeConnection.get(SAME_SLOT_KEY_2_BYTES), is(VALUE_1_BYTES)); + } + + @Test // DATAREDIS-315 + public void sAddShouldAddValueToSetCorrectly() { + + clusterConnection.sAdd(KEY_1_BYTES, VALUE_1_BYTES, VALUE_2_BYTES); + + assertThat(nativeConnection.smembers(KEY_1), hasItems(VALUE_1, VALUE_2)); + } + + @Test // DATAREDIS-315 + public void sCardShouldCountValuesInSetCorrectly() { + + nativeConnection.sadd(KEY_1, VALUE_1, VALUE_2); + + assertThat(clusterConnection.sCard(KEY_1_BYTES), is(2L)); + } + + @Test // DATAREDIS-315 + public void sDiffShouldWorkWhenKeysMapToSameSlot() { + + nativeConnection.sadd(SAME_SLOT_KEY_1_BYTES, VALUE_1_BYTES, VALUE_2_BYTES); + nativeConnection.sadd(SAME_SLOT_KEY_2_BYTES, VALUE_2_BYTES, VALUE_3_BYTES); + + assertThat(clusterConnection.sDiff(SAME_SLOT_KEY_1_BYTES, SAME_SLOT_KEY_2_BYTES), hasItems(VALUE_1_BYTES)); + } + + @Test // DATAREDIS-315, DATAREDIS-647 + public void sDiffShouldWorkWhenKeysNotMapToSameSlot() { + + nativeConnection.sadd(KEY_1_BYTES, VALUE_1_BYTES, VALUE_2_BYTES); + nativeConnection.sadd(KEY_2_BYTES, VALUE_2_BYTES, VALUE_3_BYTES); + nativeConnection.sadd(KEY_3_BYTES, VALUE_1_BYTES, VALUE_3_BYTES); + + assertThat(clusterConnection.sDiff(KEY_1_BYTES, KEY_2_BYTES), hasItems(VALUE_1_BYTES)); + assertThat(clusterConnection.sDiff(KEY_1_BYTES, KEY_2_BYTES, KEY_3_BYTES), is(empty())); + } + + @Test // DATAREDIS-315 + public void sDiffStoreShouldWorkWhenKeysMapToSameSlot() { + + nativeConnection.sadd(SAME_SLOT_KEY_1_BYTES, VALUE_1_BYTES, VALUE_2_BYTES); + nativeConnection.sadd(SAME_SLOT_KEY_2_BYTES, VALUE_2_BYTES, VALUE_3_BYTES); + + clusterConnection.sDiffStore(SAME_SLOT_KEY_3_BYTES, SAME_SLOT_KEY_1_BYTES, SAME_SLOT_KEY_2_BYTES); + + assertThat(nativeConnection.smembers(SAME_SLOT_KEY_3_BYTES), hasItems(VALUE_1_BYTES)); + } + + @Test // DATAREDIS-315 + public void sDiffStoreShouldWorkWhenKeysNotMapToSameSlot() { + + nativeConnection.sadd(KEY_1_BYTES, VALUE_1_BYTES, VALUE_2_BYTES); + nativeConnection.sadd(KEY_2_BYTES, VALUE_2_BYTES, VALUE_3_BYTES); + + clusterConnection.sDiffStore(KEY_3_BYTES, KEY_1_BYTES, KEY_2_BYTES); + + assertThat(nativeConnection.smembers(KEY_3_BYTES), hasItems(VALUE_1_BYTES)); + } + + @Test // DATAREDIS-315 + public void sInterShouldWorkForKeysMappingToSameSlot() { + + nativeConnection.sadd(SAME_SLOT_KEY_1_BYTES, VALUE_1_BYTES, VALUE_2_BYTES); + nativeConnection.sadd(SAME_SLOT_KEY_2_BYTES, VALUE_2_BYTES, VALUE_3_BYTES); + + assertThat(clusterConnection.sInter(SAME_SLOT_KEY_1_BYTES, SAME_SLOT_KEY_2_BYTES), hasItem(VALUE_2_BYTES)); + } + + @Test // DATAREDIS-315 + public void sInterShouldWorkForKeysNotMappingToSameSlot() { + + nativeConnection.sadd(KEY_1_BYTES, VALUE_1_BYTES, VALUE_2_BYTES); + nativeConnection.sadd(KEY_2_BYTES, VALUE_2_BYTES, VALUE_3_BYTES); + + assertThat(clusterConnection.sInter(KEY_1_BYTES, KEY_2_BYTES), hasItem(VALUE_2_BYTES)); + } + + @Test // DATAREDIS-315 + public void sInterStoreShouldWorkForKeysMappingToSameSlot() { + + nativeConnection.sadd(SAME_SLOT_KEY_1_BYTES, VALUE_1_BYTES, VALUE_2_BYTES); + nativeConnection.sadd(SAME_SLOT_KEY_2_BYTES, VALUE_2_BYTES, VALUE_3_BYTES); + + clusterConnection.sInterStore(SAME_SLOT_KEY_3_BYTES, SAME_SLOT_KEY_1_BYTES, SAME_SLOT_KEY_2_BYTES); + + assertThat(nativeConnection.smembers(SAME_SLOT_KEY_3_BYTES), hasItem(VALUE_2_BYTES)); + } + + @Test // DATAREDIS-315 + public void sInterStoreShouldWorkForKeysNotMappingToSameSlot() { + + nativeConnection.sadd(KEY_1_BYTES, VALUE_1_BYTES, VALUE_2_BYTES); + nativeConnection.sadd(KEY_2_BYTES, VALUE_2_BYTES, VALUE_3_BYTES); + + clusterConnection.sInterStore(KEY_3_BYTES, KEY_1_BYTES, KEY_2_BYTES); + + assertThat(nativeConnection.smembers(KEY_3_BYTES), hasItem(VALUE_2_BYTES)); + } + + @Test // DATAREDIS-315 + public void sIsMemberShouldReturnFalseIfValueIsMemberOfSet() { + + nativeConnection.sadd(KEY_1, VALUE_1, VALUE_2); + + assertThat(clusterConnection.sIsMember(KEY_1_BYTES, JedisConverters.toBytes("foo")), is(false)); + } + + @Test // DATAREDIS-315 + public void sIsMemberShouldReturnTrueIfValueIsMemberOfSet() { + + nativeConnection.sadd(KEY_1, VALUE_1, VALUE_2); + + assertThat(clusterConnection.sIsMember(KEY_1_BYTES, VALUE_1_BYTES), is(true)); + } + + @Test // DATAREDIS-315 + public void sMembersShouldReturnValuesContainedInSetCorrectly() { + + nativeConnection.sadd(KEY_1, VALUE_1, VALUE_2); + + assertThat(clusterConnection.sMembers(KEY_1_BYTES), hasItems(VALUE_1_BYTES, VALUE_2_BYTES)); + } + + @Test // DATAREDIS-315 + public void sMoveShouldWorkWhenKeysDoNotMapToSameSlot() { + + nativeConnection.sadd(KEY_1_BYTES, VALUE_1_BYTES, VALUE_2_BYTES); + nativeConnection.sadd(KEY_2_BYTES, VALUE_3_BYTES); + + clusterConnection.sMove(KEY_1_BYTES, KEY_2_BYTES, VALUE_2_BYTES); + + assertThat(nativeConnection.sismember(KEY_1_BYTES, VALUE_2_BYTES), is(false)); + assertThat(nativeConnection.sismember(KEY_2_BYTES, VALUE_2_BYTES), is(true)); + } + + @Test // DATAREDIS-315 + public void sMoveShouldWorkWhenKeysMapToSameSlot() { + + nativeConnection.sadd(SAME_SLOT_KEY_1_BYTES, VALUE_1_BYTES, VALUE_2_BYTES); + nativeConnection.sadd(SAME_SLOT_KEY_2_BYTES, VALUE_3_BYTES); + + clusterConnection.sMove(SAME_SLOT_KEY_1_BYTES, SAME_SLOT_KEY_2_BYTES, VALUE_2_BYTES); + + assertThat(nativeConnection.sismember(SAME_SLOT_KEY_1_BYTES, VALUE_2_BYTES), is(false)); + assertThat(nativeConnection.sismember(SAME_SLOT_KEY_2_BYTES, VALUE_2_BYTES), is(true)); + } + + @Test // DATAREDIS-315 + public void sPopShouldPopValueFromSetCorrectly() { + + nativeConnection.sadd(KEY_1, VALUE_1, VALUE_2); + + assertThat(clusterConnection.sPop(KEY_1_BYTES), notNullValue()); + } + + @Test // DATAREDIS-668 + public void sPopWithCountShouldPopValueFromSetCorrectly() { + + nativeConnection.sadd(KEY_1, VALUE_1, VALUE_2, VALUE_3); + + assertThat(clusterConnection.setCommands().sPop(KEY_1_BYTES, 2), hasSize(2)); + assertThat(nativeConnection.scard(KEY_1), is(1L)); + } + + @Test // DATAREDIS-315 + public void sRandMamberShouldReturnValueCorrectly() { + + nativeConnection.sadd(KEY_1, VALUE_1, VALUE_2); + + assertThat(clusterConnection.sRandMember(KEY_1_BYTES), notNullValue()); + } + + @Test // DATAREDIS-315 + public void sRandMamberWithCountShouldReturnValueCorrectly() { + + nativeConnection.sadd(KEY_1, VALUE_1, VALUE_2); + + assertThat(clusterConnection.sRandMember(KEY_1_BYTES, 3), notNullValue()); + } + + @Test // DATAREDIS-315 + public void sRemShouldRemoveValueFromSetCorrectly() { + + nativeConnection.sadd(KEY_1, VALUE_1, VALUE_2); + + clusterConnection.sRem(KEY_1_BYTES, VALUE_2_BYTES); + + assertThat(nativeConnection.smembers(KEY_1), hasItems(VALUE_1)); + } + + @Test // DATAREDIS-315 + public void sUnionShouldWorkForKeysMappingToSameSlot() { + + nativeConnection.sadd(SAME_SLOT_KEY_1_BYTES, VALUE_1_BYTES, VALUE_2_BYTES); + nativeConnection.sadd(SAME_SLOT_KEY_2_BYTES, VALUE_2_BYTES, VALUE_3_BYTES); + + assertThat(clusterConnection.sUnion(SAME_SLOT_KEY_1_BYTES, SAME_SLOT_KEY_2_BYTES), + hasItems(VALUE_1_BYTES, VALUE_2_BYTES, VALUE_3_BYTES)); + } + + @Test // DATAREDIS-315 + public void sUnionShouldWorkForKeysNotMappingToSameSlot() { + + nativeConnection.sadd(KEY_1_BYTES, VALUE_1_BYTES, VALUE_2_BYTES); + nativeConnection.sadd(KEY_2_BYTES, VALUE_2_BYTES, VALUE_3_BYTES); + + assertThat(clusterConnection.sUnion(KEY_1_BYTES, KEY_2_BYTES), + hasItems(VALUE_1_BYTES, VALUE_2_BYTES, VALUE_3_BYTES)); + } + + @Test // DATAREDIS-315 + public void sUnionStoreShouldWorkForKeysMappingToSameSlot() { + + nativeConnection.sadd(SAME_SLOT_KEY_1_BYTES, VALUE_1_BYTES, VALUE_2_BYTES); + nativeConnection.sadd(SAME_SLOT_KEY_2_BYTES, VALUE_2_BYTES, VALUE_3_BYTES); + + clusterConnection.sUnionStore(SAME_SLOT_KEY_3_BYTES, SAME_SLOT_KEY_1_BYTES, SAME_SLOT_KEY_2_BYTES); + + assertThat(nativeConnection.smembers(SAME_SLOT_KEY_3_BYTES), hasItems(VALUE_1_BYTES, VALUE_2_BYTES, VALUE_3_BYTES)); + } + + @Test // DATAREDIS-315 + public void sUnionStoreShouldWorkForKeysNotMappingToSameSlot() { + + nativeConnection.sadd(KEY_1_BYTES, VALUE_1_BYTES, VALUE_2_BYTES); + nativeConnection.sadd(KEY_2_BYTES, VALUE_2_BYTES, VALUE_3_BYTES); + + clusterConnection.sUnionStore(KEY_3_BYTES, KEY_1_BYTES, KEY_2_BYTES); + + assertThat(nativeConnection.smembers(KEY_3_BYTES), hasItems(VALUE_1_BYTES, VALUE_2_BYTES, VALUE_3_BYTES)); + } + + @Test // DATAREDIS-315 + public void selectShouldAllowSelectionOfDBIndexZero() { + clusterConnection.select(0); + } + + @Test(expected = DataAccessException.class) // DATAREDIS-315 + public void selectShouldThrowExceptionWhenSelectingNonZeroDbIndex() { + clusterConnection.select(1); + } + + @Test // DATAREDIS-315 + public void setBitShouldWorkCorrectly() { + + clusterConnection.setBit(KEY_1_BYTES, 0, true); + clusterConnection.setBit(KEY_1_BYTES, 1, false); + + assertThat(nativeConnection.getbit(KEY_1, 0), is(true)); + assertThat(nativeConnection.getbit(KEY_1, 1), is(false)); + } + + @Test // DATAREDIS-315 + public void setExShouldSetValueCorrectly() { + + clusterConnection.setEx(KEY_1_BYTES, 5, VALUE_1_BYTES); + + assertThat(nativeConnection.get(KEY_1), is(VALUE_1)); + assertThat(nativeConnection.ttl(KEY_1) > 1, is(true)); + } + + @Test // DATAREDIS-315 + public void setNxShouldNotSetValueWhenAlreadyExistsInDBCorrectly() { + + nativeConnection.set(KEY_1, VALUE_1); + + clusterConnection.setNX(KEY_1_BYTES, VALUE_2_BYTES); + + assertThat(nativeConnection.get(KEY_1), is(VALUE_1)); + } + + @Test // DATAREDIS-315 + public void setNxShouldSetValueCorrectly() { + + clusterConnection.setNX(KEY_1_BYTES, VALUE_1_BYTES); + + assertThat(nativeConnection.get(KEY_1), is(VALUE_1)); + } + + @Test // DATAREDIS-315 + public void setRangeShouldWorkCorrectly() { + + nativeConnection.set(KEY_1, VALUE_1); + + clusterConnection.setRange(KEY_1_BYTES, JedisConverters.toBytes("UE"), 3); + + assertThat(nativeConnection.get(KEY_1), is("valUE1")); + } + + @Test // DATAREDIS-315 + public void setShouldSetValueCorrectly() { + + clusterConnection.set(KEY_1_BYTES, VALUE_1_BYTES); + + assertThat(nativeConnection.get(KEY_1), is(VALUE_1)); + } + + @Test // DATAREDIS-316 + public void setWithExpirationAndIfAbsentShouldNotBeAppliedWhenKeyExists() { + + nativeConnection.set(KEY_1_BYTES, VALUE_1_BYTES); + + clusterConnection.set(KEY_1_BYTES, VALUE_2_BYTES, Expiration.seconds(1), SetOption.ifAbsent()); + + assertThat(nativeConnection.exists(KEY_1_BYTES), is(true)); + assertThat(nativeConnection.ttl(KEY_1_BYTES), is(-1L)); + assertThat(nativeConnection.get(KEY_1_BYTES), is(equalTo(VALUE_1_BYTES))); + } + + @Test // DATAREDIS-316 + public void setWithExpirationAndIfAbsentShouldWorkCorrectly() { + + clusterConnection.set(KEY_1_BYTES, VALUE_1_BYTES, Expiration.seconds(1), SetOption.ifAbsent()); + + assertThat(nativeConnection.exists(KEY_1_BYTES), is(true)); + assertThat(nativeConnection.ttl(KEY_1_BYTES), is(1L)); + } + + @Test // DATAREDIS-316 + public void setWithExpirationAndIfPresentShouldNotBeAppliedWhenKeyDoesNotExists() { + + clusterConnection.set(KEY_1_BYTES, VALUE_1_BYTES, Expiration.seconds(1), SetOption.ifPresent()); + + assertThat(nativeConnection.exists(KEY_1_BYTES), is(false)); + } + + @Test // DATAREDIS-316 + public void setWithExpirationAndIfPresentShouldWorkCorrectly() { + + nativeConnection.set(KEY_1_BYTES, VALUE_1_BYTES); + + clusterConnection.set(KEY_1_BYTES, VALUE_2_BYTES, Expiration.seconds(1), SetOption.ifPresent()); + + assertThat(nativeConnection.exists(KEY_1_BYTES), is(true)); + assertThat(nativeConnection.ttl(KEY_1_BYTES), is(1L)); + assertThat(nativeConnection.get(KEY_1_BYTES), is(equalTo(VALUE_2_BYTES))); + } + + @Test // DATAREDIS-316 + public void setWithExpirationInMillisecondsShouldWorkCorrectly() { + + clusterConnection.set(KEY_1_BYTES, VALUE_1_BYTES, Expiration.milliseconds(500), SetOption.upsert()); + + assertThat(nativeConnection.exists(KEY_1_BYTES), is(true)); + assertThat(nativeConnection.pttl(KEY_1).doubleValue(), is(closeTo(500d, 499d))); + } + + @Test // DATAREDIS-316 + public void setWithExpirationInSecondsShouldWorkCorrectly() { + + clusterConnection.set(KEY_1_BYTES, VALUE_1_BYTES, Expiration.seconds(1), SetOption.upsert()); + + assertThat(nativeConnection.exists(KEY_1_BYTES), is(true)); + assertThat(nativeConnection.ttl(KEY_1_BYTES), is(1L)); + } + + @Test // DATAREDIS-316 + public void setWithOptionIfAbsentShouldWorkCorrectly() { + + clusterConnection.set(KEY_1_BYTES, VALUE_1_BYTES, Expiration.persistent(), SetOption.ifAbsent()); + + assertThat(nativeConnection.exists(KEY_1_BYTES), is(true)); + assertThat(nativeConnection.ttl(KEY_1_BYTES), is(-1L)); + } + + @Test(expected = UnsupportedOperationException.class) // DATAREDIS-316 + public void setWithOptionIfPresentShouldWorkCorrectly() { + + nativeConnection.set(KEY_1_BYTES, VALUE_1_BYTES); + clusterConnection.set(KEY_1_BYTES, VALUE_2_BYTES, Expiration.persistent(), SetOption.ifPresent()); + } + + @Test // DATAREDIS-315 + public void shouldAllowSettingAndGettingValues() { + + clusterConnection.set(KEY_1_BYTES, VALUE_1_BYTES); + assertThat(clusterConnection.get(KEY_1_BYTES), is(VALUE_1_BYTES)); + } + + @Test // DATAREDIS-315 + public void sortAndStoreShouldAddSortedValuesValuesCorrectly() { + + nativeConnection.lpush(KEY_1, VALUE_2, VALUE_1); + + assertThat(clusterConnection.sort(KEY_1_BYTES, new DefaultSortParameters().alpha(), KEY_2_BYTES), is(1L)); + assertThat(nativeConnection.exists(KEY_2_BYTES), is(true)); + } + + @Test // DATAREDIS-315 + public void sortAndStoreShouldReturnZeroWhenListDoesNotExist() { + assertThat(clusterConnection.sort(KEY_1_BYTES, new DefaultSortParameters().alpha(), KEY_2_BYTES), is(0L)); + } + + @Test // DATAREDIS-315 + public void sortShouldReturnValuesCorrectly() { + + nativeConnection.lpush(KEY_1, VALUE_2, VALUE_1); + + assertThat(clusterConnection.sort(KEY_1_BYTES, new DefaultSortParameters().alpha()), + hasItems(VALUE_1_BYTES, VALUE_2_BYTES)); + } + + @Test // DATAREDIS-315 + public void sscanShouldRetrieveAllValuesInSetCorrectly() { + + for (int i = 0; i < 30; i++) { + nativeConnection.sadd(KEY_1_BYTES, JedisConverters.toBytes(Integer.valueOf(i))); + } + + int count = 0; + Cursor cursor = clusterConnection.sScan(KEY_1_BYTES, ScanOptions.NONE); + while (cursor.hasNext()) { + count++; + cursor.next(); + } + + assertThat(count, is(30)); + } + + @Test // DATAREDIS-315 + public void strLenShouldWorkCorrectly() { + + nativeConnection.set(KEY_1, VALUE_1); + + assertThat(clusterConnection.strLen(KEY_1_BYTES), is(6L)); + } + + @Test // DATAREDIS-315 + public void ttlShouldReturnMinusOneWhenKeyDoesNotHaveExpirationSet() { + + nativeConnection.set(KEY_1, VALUE_1); + + assertThat(clusterConnection.ttl(KEY_1_BYTES), is(-1L)); + } + + @Test // DATAREDIS-315 + public void ttlShouldReturnMinusTwoWhenKeyDoesNotExist() { + assertThat(clusterConnection.ttl(KEY_1_BYTES), is(-2L)); + } + + @Test // DATAREDIS-315 + public void ttlShouldReturnValueCorrectly() { + + nativeConnection.set(KEY_1, VALUE_1); + nativeConnection.expire(KEY_1, 5); + + assertThat(clusterConnection.ttl(KEY_1_BYTES) > 1, is(true)); + } + + @Test // DATAREDIS-526 + public void ttlWithTimeUnitShouldReturnMinusTwoWhenKeyDoesNotExist() { + assertThat(clusterConnection.ttl(KEY_1_BYTES, TimeUnit.HOURS), is(-2L)); + } + + @Test // DATAREDIS-315 + public void typeShouldReadKeyTypeCorrectly() { + + nativeConnection.sadd(KEY_1_BYTES, VALUE_1_BYTES); + nativeConnection.set(KEY_2_BYTES, VALUE_2_BYTES); + nativeConnection.hmset(KEY_3_BYTES, Collections.singletonMap(KEY_1_BYTES, VALUE_1_BYTES)); + + assertThat(clusterConnection.type(KEY_1_BYTES), is(DataType.SET)); + assertThat(clusterConnection.type(KEY_2_BYTES), is(DataType.STRING)); + assertThat(clusterConnection.type(KEY_3_BYTES), is(DataType.HASH)); + } + + @Test(expected = DataAccessException.class) // DATAREDIS-315 + public void unwatchShouldThrowException() { + clusterConnection.unwatch(); + } + + @Test(expected = DataAccessException.class) // DATAREDIS-315 + public void watchShouldThrowException() { + clusterConnection.watch(); + } + + @Test // DATAREDIS-674 + public void zAddShouldAddMultipleValuesWithScoreCorrectly() { + + Set tuples = new HashSet<>(); + tuples.add(new DefaultTuple(VALUE_1_BYTES, 10D)); + tuples.add(new DefaultTuple(VALUE_2_BYTES, 20D)); + + clusterConnection.zAdd(KEY_1_BYTES, tuples); + + assertThat(nativeConnection.zcard(KEY_1_BYTES), is(2L)); + } + + @Test // DATAREDIS-315 + public void zAddShouldAddValueWithScoreCorrectly() { + + clusterConnection.zAdd(KEY_1_BYTES, 10D, VALUE_1_BYTES); + clusterConnection.zAdd(KEY_1_BYTES, 20D, VALUE_2_BYTES); + + assertThat(nativeConnection.zcard(KEY_1_BYTES), is(2L)); + } + + @Test // DATAREDIS-315 + public void zCardShouldReturnTotalNumberOfValues() { + + nativeConnection.zadd(KEY_1_BYTES, 10D, VALUE_1_BYTES); + nativeConnection.zadd(KEY_1_BYTES, 20D, VALUE_2_BYTES); + nativeConnection.zadd(KEY_1_BYTES, 5D, VALUE_3_BYTES); + + assertThat(clusterConnection.zCard(KEY_1_BYTES), is(3L)); + } + + @Test // DATAREDIS-315 + public void zCountShouldCountValuesInRange() { + + nativeConnection.zadd(KEY_1_BYTES, 10D, VALUE_1_BYTES); + nativeConnection.zadd(KEY_1_BYTES, 20D, VALUE_2_BYTES); + nativeConnection.zadd(KEY_1_BYTES, 5D, VALUE_3_BYTES); + + assertThat(clusterConnection.zCount(KEY_1_BYTES, 10, 20), is(2L)); + } + + @Test // DATAREDIS-315 + public void zIncrByShouldIncScoreForValueCorrectly() { + + nativeConnection.zadd(KEY_1_BYTES, 10D, VALUE_1_BYTES); + nativeConnection.zadd(KEY_1_BYTES, 20D, VALUE_2_BYTES); + + clusterConnection.zIncrBy(KEY_1_BYTES, 100D, VALUE_1_BYTES); + + assertThat(nativeConnection.zrank(KEY_1_BYTES, VALUE_1_BYTES), is(1L)); + } + + @Test(expected = DataAccessException.class) // DATAREDIS-315 + public void zInterStoreShouldThrowExceptionWhenKeysDoNotMapToSameSlots() { + clusterConnection.zInterStore(KEY_3_BYTES, KEY_1_BYTES, KEY_2_BYTES); + } + + @Test // DATAREDIS-315 + public void zInterStoreShouldWorkForSameSlotKeys() { + + nativeConnection.zadd(SAME_SLOT_KEY_1_BYTES, 10D, VALUE_1_BYTES); + nativeConnection.zadd(SAME_SLOT_KEY_1_BYTES, 20D, VALUE_2_BYTES); + + nativeConnection.zadd(SAME_SLOT_KEY_2_BYTES, 20D, VALUE_2_BYTES); + nativeConnection.zadd(SAME_SLOT_KEY_2_BYTES, 30D, VALUE_3_BYTES); + + clusterConnection.zInterStore(SAME_SLOT_KEY_3_BYTES, SAME_SLOT_KEY_1_BYTES, SAME_SLOT_KEY_2_BYTES); + + assertThat(nativeConnection.zrange(SAME_SLOT_KEY_3_BYTES, 0, -1), hasItems(VALUE_2_BYTES)); + } + + @Test // DATAREDIS-315 + public void zRangeByLexShouldReturnResultCorrectly() { + + nativeConnection.zadd(KEY_1, 0, "a"); + nativeConnection.zadd(KEY_1, 0, "b"); + nativeConnection.zadd(KEY_1, 0, "c"); + nativeConnection.zadd(KEY_1, 0, "d"); + nativeConnection.zadd(KEY_1, 0, "e"); + nativeConnection.zadd(KEY_1, 0, "f"); + nativeConnection.zadd(KEY_1, 0, "g"); + + Set values = clusterConnection.zRangeByLex(KEY_1_BYTES, Range.range().lte("c")); + + assertThat(values, + hasItems(JedisConverters.toBytes("a"), JedisConverters.toBytes("b"), JedisConverters.toBytes("c"))); + assertThat(values, not(hasItems(JedisConverters.toBytes("d"), JedisConverters.toBytes("e"), + JedisConverters.toBytes("f"), JedisConverters.toBytes("g")))); + + values = clusterConnection.zRangeByLex(KEY_1_BYTES, Range.range().lt("c")); + assertThat(values, hasItems(JedisConverters.toBytes("a"), JedisConverters.toBytes("b"))); + assertThat(values, not(hasItem(JedisConverters.toBytes("c")))); + + values = clusterConnection.zRangeByLex(KEY_1_BYTES, Range.range().gte("aaa").lt("g")); + assertThat(values, hasItems(JedisConverters.toBytes("b"), JedisConverters.toBytes("c"), + JedisConverters.toBytes("d"), JedisConverters.toBytes("e"), JedisConverters.toBytes("f"))); + assertThat(values, not(hasItems(JedisConverters.toBytes("a"), JedisConverters.toBytes("g")))); + + values = clusterConnection.zRangeByLex(KEY_1_BYTES, Range.range().gte("e")); + assertThat(values, + hasItems(JedisConverters.toBytes("e"), JedisConverters.toBytes("f"), JedisConverters.toBytes("g"))); + assertThat(values, not(hasItems(JedisConverters.toBytes("a"), JedisConverters.toBytes("b"), + JedisConverters.toBytes("c"), JedisConverters.toBytes("d")))); + } + + @Test // DATAREDIS-315 + public void zRangeByScoreShouldReturnValuesCorrectly() { + + nativeConnection.zadd(KEY_1_BYTES, 10D, VALUE_1_BYTES); + nativeConnection.zadd(KEY_1_BYTES, 20D, VALUE_2_BYTES); + nativeConnection.zadd(KEY_1_BYTES, 5D, VALUE_3_BYTES); + + assertThat(clusterConnection.zRangeByScore(KEY_1_BYTES, 10, 20), hasItems(VALUE_1_BYTES, VALUE_2_BYTES)); + } + + @Test // DATAREDIS-315 + public void zRangeByScoreShouldReturnValuesCorrectlyWhenGivenOffsetAndScore() { + + nativeConnection.zadd(KEY_1_BYTES, 10D, VALUE_1_BYTES); + nativeConnection.zadd(KEY_1_BYTES, 20D, VALUE_2_BYTES); + nativeConnection.zadd(KEY_1_BYTES, 5D, VALUE_3_BYTES); + + assertThat(clusterConnection.zRangeByScore(KEY_1_BYTES, 10D, 20D, 0L, 1L), hasItems(VALUE_1_BYTES)); + } + + @Test // DATAREDIS-315 + public void zRangeByScoreWithScoresShouldReturnValuesAndScoreCorrectly() { + + nativeConnection.zadd(KEY_1_BYTES, 10D, VALUE_1_BYTES); + nativeConnection.zadd(KEY_1_BYTES, 20D, VALUE_2_BYTES); + nativeConnection.zadd(KEY_1_BYTES, 5D, VALUE_3_BYTES); + + assertThat(clusterConnection.zRangeByScoreWithScores(KEY_1_BYTES, 10, 20), + hasItems((Tuple) new DefaultTuple(VALUE_1_BYTES, 10D), (Tuple) new DefaultTuple(VALUE_2_BYTES, 20D))); + } + + @Test // DATAREDIS-315 + public void zRangeByScoreWithScoresShouldReturnValuesCorrectlyWhenGivenOffsetAndScore() { + + nativeConnection.zadd(KEY_1_BYTES, 10D, VALUE_1_BYTES); + nativeConnection.zadd(KEY_1_BYTES, 20D, VALUE_2_BYTES); + nativeConnection.zadd(KEY_1_BYTES, 5D, VALUE_3_BYTES); + + assertThat(clusterConnection.zRangeByScoreWithScores(KEY_1_BYTES, 10D, 20D, 0L, 1L), + hasItems((Tuple) new DefaultTuple(VALUE_1_BYTES, 10D))); + } + + @Test // DATAREDIS-315 + public void zRangeShouldReturnValuesCorrectly() { + + nativeConnection.zadd(KEY_1_BYTES, 10D, VALUE_1_BYTES); + nativeConnection.zadd(KEY_1_BYTES, 20D, VALUE_2_BYTES); + nativeConnection.zadd(KEY_1_BYTES, 5D, VALUE_3_BYTES); + + assertThat(clusterConnection.zRange(KEY_1_BYTES, 1, 2), hasItems(VALUE_1_BYTES, VALUE_2_BYTES)); + } + + @Test // DATAREDIS-315 + public void zRangeWithScoresShouldReturnValuesAndScoreCorrectly() { + + nativeConnection.zadd(KEY_1_BYTES, 10D, VALUE_1_BYTES); + nativeConnection.zadd(KEY_1_BYTES, 20D, VALUE_2_BYTES); + nativeConnection.zadd(KEY_1_BYTES, 5D, VALUE_3_BYTES); + + assertThat(clusterConnection.zRangeWithScores(KEY_1_BYTES, 1, 2), + hasItems((Tuple) new DefaultTuple(VALUE_1_BYTES, 10D), (Tuple) new DefaultTuple(VALUE_2_BYTES, 20D))); + } + + @Test // DATAREDIS-315 + public void zRankShouldReturnPositionForValueCorrectly() { + + nativeConnection.zadd(KEY_1_BYTES, 10D, VALUE_1_BYTES); + nativeConnection.zadd(KEY_1_BYTES, 20D, VALUE_2_BYTES); + + assertThat(clusterConnection.zRank(KEY_1_BYTES, VALUE_2_BYTES), is(1L)); + } + + @Test // DATAREDIS-315 + public void zRankShouldReturnReversePositionForValueCorrectly() { + + nativeConnection.zadd(KEY_1_BYTES, 10D, VALUE_1_BYTES); + nativeConnection.zadd(KEY_1_BYTES, 20D, VALUE_2_BYTES); + + assertThat(clusterConnection.zRevRank(KEY_1_BYTES, VALUE_2_BYTES), is(0L)); + } + + @Test // DATAREDIS-315 + public void zRemRangeByScoreShouldRemoveValues() { + + nativeConnection.zadd(KEY_1_BYTES, 10D, VALUE_1_BYTES); + nativeConnection.zadd(KEY_1_BYTES, 20D, VALUE_2_BYTES); + nativeConnection.zadd(KEY_1_BYTES, 30D, VALUE_3_BYTES); + + clusterConnection.zRemRangeByScore(KEY_1_BYTES, 15D, 25D); + + assertThat(nativeConnection.zcard(KEY_1_BYTES), is(2L)); + assertThat(nativeConnection.zrange(KEY_1_BYTES, 0, -1), hasItems(VALUE_1_BYTES, VALUE_3_BYTES)); + } + + @Test // DATAREDIS-315 + public void zRemRangeShouldRemoveValues() { + + nativeConnection.zadd(KEY_1_BYTES, 10D, VALUE_1_BYTES); + nativeConnection.zadd(KEY_1_BYTES, 20D, VALUE_2_BYTES); + nativeConnection.zadd(KEY_1_BYTES, 30D, VALUE_3_BYTES); + + clusterConnection.zRemRange(KEY_1_BYTES, 1, 2); + + assertThat(nativeConnection.zcard(KEY_1_BYTES), is(1L)); + assertThat(nativeConnection.zrange(KEY_1_BYTES, 0, -1), hasItem(VALUE_1_BYTES)); + } + + @Test // DATAREDIS-315 + public void zRemShouldRemoveValueWithScoreCorrectly() { + + nativeConnection.zadd(KEY_1_BYTES, 10D, VALUE_1_BYTES); + nativeConnection.zadd(KEY_1_BYTES, 20D, VALUE_2_BYTES); + + clusterConnection.zRem(KEY_1_BYTES, VALUE_1_BYTES); + + assertThat(nativeConnection.zcard(KEY_1_BYTES), is(1L)); + } + + @Test // DATAREDIS-315 + public void zRevRangeByScoreShouldReturnValuesCorrectly() { + + nativeConnection.zadd(KEY_1_BYTES, 10D, VALUE_1_BYTES); + nativeConnection.zadd(KEY_1_BYTES, 20D, VALUE_2_BYTES); + nativeConnection.zadd(KEY_1_BYTES, 5D, VALUE_3_BYTES); + + assertThat(clusterConnection.zRevRangeByScore(KEY_1_BYTES, 10D, 20D), hasItems(VALUE_2_BYTES, VALUE_1_BYTES)); + } + + @Test // DATAREDIS-315 + public void zRevRangeByScoreShouldReturnValuesCorrectlyWhenGivenOffsetAndScore() { + + nativeConnection.zadd(KEY_1_BYTES, 10D, VALUE_1_BYTES); + nativeConnection.zadd(KEY_1_BYTES, 20D, VALUE_2_BYTES); + nativeConnection.zadd(KEY_1_BYTES, 5D, VALUE_3_BYTES); + + assertThat(clusterConnection.zRevRangeByScore(KEY_1_BYTES, 10D, 20D, 0L, 1L), hasItems(VALUE_2_BYTES)); + } + + @Test // DATAREDIS-315 + public void zRevRangeByScoreWithScoresShouldReturnValuesAndScoreCorrectly() { + + nativeConnection.zadd(KEY_1_BYTES, 10D, VALUE_1_BYTES); + nativeConnection.zadd(KEY_1_BYTES, 20D, VALUE_2_BYTES); + nativeConnection.zadd(KEY_1_BYTES, 5D, VALUE_3_BYTES); + + assertThat(clusterConnection.zRevRangeByScoreWithScores(KEY_1_BYTES, 10D, 20D), + hasItems((Tuple) new DefaultTuple(VALUE_2_BYTES, 20D), (Tuple) new DefaultTuple(VALUE_1_BYTES, 10D))); + } + + @Test // DATAREDIS-315 + public void zRevRangeByScoreWithScoresShouldReturnValuesCorrectlyWhenGivenOffsetAndScore() { + + nativeConnection.zadd(KEY_1_BYTES, 10D, VALUE_1_BYTES); + nativeConnection.zadd(KEY_1_BYTES, 20D, VALUE_2_BYTES); + nativeConnection.zadd(KEY_1_BYTES, 5D, VALUE_3_BYTES); + + assertThat(clusterConnection.zRevRangeByScoreWithScores(KEY_1_BYTES, 10D, 20D, 0L, 1L), + hasItems((Tuple) new DefaultTuple(VALUE_2_BYTES, 20D))); + } + + @Test // DATAREDIS-315 + public void zRevRangeShouldReturnValuesCorrectly() { + + nativeConnection.zadd(KEY_1_BYTES, 10D, VALUE_1_BYTES); + nativeConnection.zadd(KEY_1_BYTES, 20D, VALUE_2_BYTES); + nativeConnection.zadd(KEY_1_BYTES, 5D, VALUE_3_BYTES); + + assertThat(clusterConnection.zRevRange(KEY_1_BYTES, 1, 2), hasItems(VALUE_3_BYTES, VALUE_1_BYTES)); + } + + @Test // DATAREDIS-315 + public void zRevRangeWithScoresShouldReturnValuesAndScoreCorrectly() { + + nativeConnection.zadd(KEY_1_BYTES, 10D, VALUE_1_BYTES); + nativeConnection.zadd(KEY_1_BYTES, 20D, VALUE_2_BYTES); + nativeConnection.zadd(KEY_1_BYTES, 5D, VALUE_3_BYTES); + + assertThat(clusterConnection.zRevRangeWithScores(KEY_1_BYTES, 1, 2), + hasItems((Tuple) new DefaultTuple(VALUE_3_BYTES, 5D), (Tuple) new DefaultTuple(VALUE_1_BYTES, 10D))); + } + + @Test // DATAREDIS-479 + public void zScanShouldReadEntireValueRange() { + + int nrOfValues = 321; + for (int i = 0; i < nrOfValues; i++) { + nativeConnection.zadd(KEY_1_BYTES, i, JedisConverters.toBytes("value-" + i)); + } + + Cursor tuples = clusterConnection.zScan(KEY_1_BYTES, ScanOptions.NONE); + + int count = 0; + while (tuples.hasNext()) { + + tuples.next(); + count++; + } + + assertThat(count, equalTo(nrOfValues)); + } + + @Test // DATAREDIS-315 + public void zScoreShouldRetrieveScoreForValue() { + + nativeConnection.zadd(KEY_1_BYTES, 10D, VALUE_1_BYTES); + nativeConnection.zadd(KEY_1_BYTES, 20D, VALUE_2_BYTES); + + assertThat(clusterConnection.zScore(KEY_1_BYTES, VALUE_2_BYTES), is(20D)); + } + + @Test(expected = DataAccessException.class) // DATAREDIS-315 + public void zUnionStoreShouldThrowExceptionWhenKeysDoNotMapToSameSlots() { + clusterConnection.zUnionStore(KEY_3_BYTES, KEY_1_BYTES, KEY_2_BYTES); + } + + @Test // DATAREDIS-315 + public void zUnionStoreShouldWorkForSameSlotKeys() { + + nativeConnection.zadd(SAME_SLOT_KEY_1_BYTES, 10D, VALUE_1_BYTES); + nativeConnection.zadd(SAME_SLOT_KEY_1_BYTES, 30D, VALUE_3_BYTES); + nativeConnection.zadd(SAME_SLOT_KEY_2_BYTES, 20D, VALUE_2_BYTES); + + clusterConnection.zUnionStore(SAME_SLOT_KEY_3_BYTES, SAME_SLOT_KEY_1_BYTES, SAME_SLOT_KEY_2_BYTES); + + assertThat(nativeConnection.zrange(SAME_SLOT_KEY_3_BYTES, 0, -1), + hasItems(VALUE_1_BYTES, VALUE_2_BYTES, VALUE_3_BYTES)); + } } diff --git a/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceClusterConnectionTests.java b/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceClusterConnectionTests.java index 9e67cdde9..f99f5209d 100644 --- a/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceClusterConnectionTests.java +++ b/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceClusterConnectionTests.java @@ -28,16 +28,7 @@ import io.lettuce.core.cluster.RedisClusterClient; import io.lettuce.core.cluster.api.sync.RedisAdvancedClusterCommands; import java.nio.charset.Charset; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; -import java.util.Properties; -import java.util.Set; +import java.util.*; import java.util.concurrent.TimeUnit; import org.junit.After; @@ -130,510 +121,6 @@ public class LettuceClusterConnectionTests implements ClusterConnectionTests { client.shutdown(0, 0, TimeUnit.MILLISECONDS); } - @Test // DATAREDIS-315 - public void shouldAllowSettingAndGettingValues() { - - clusterConnection.set(KEY_1_BYTES, VALUE_1_BYTES); - assertThat(clusterConnection.get(KEY_1_BYTES), is(VALUE_1_BYTES)); - } - - @Test // DATAREDIS-315 - public void delShouldRemoveSingleKeyCorrectly() { - - nativeConnection.set(KEY_1, VALUE_1); - - clusterConnection.del(KEY_1_BYTES); - - assertThat(nativeConnection.get(KEY_1), nullValue()); - } - - @Test // DATAREDIS-315 - public void delShouldRemoveMultipleKeysCorrectly() { - - nativeConnection.set(KEY_1, VALUE_1); - nativeConnection.set(KEY_2, VALUE_2); - - clusterConnection.del(KEY_1_BYTES); - clusterConnection.del(KEY_2_BYTES); - - assertThat(nativeConnection.get(KEY_1), nullValue()); - assertThat(nativeConnection.get(KEY_2), nullValue()); - } - - @Test // DATAREDIS-315 - public void delShouldRemoveMultipleKeysOnSameSlotCorrectly() { - - nativeConnection.set(SAME_SLOT_KEY_1, VALUE_1); - nativeConnection.set(SAME_SLOT_KEY_2, VALUE_2); - - clusterConnection.del(SAME_SLOT_KEY_1_BYTES, SAME_SLOT_KEY_2_BYTES); - - assertThat(nativeConnection.get(SAME_SLOT_KEY_1), nullValue()); - assertThat(nativeConnection.get(SAME_SLOT_KEY_2), nullValue()); - } - - @Test // DATAREDIS-315 - public void typeShouldReadKeyTypeCorrectly() { - - nativeConnection.sadd(KEY_1, VALUE_1); - nativeConnection.set(KEY_2, VALUE_2); - nativeConnection.hmset(KEY_3, Collections.singletonMap(KEY_1, VALUE_1)); - - assertThat(clusterConnection.type(KEY_1_BYTES), is(DataType.SET)); - assertThat(clusterConnection.type(KEY_2_BYTES), is(DataType.STRING)); - assertThat(clusterConnection.type(KEY_3_BYTES), is(DataType.HASH)); - } - - @Test // DATAREDIS-315 - public void keysShouldReturnAllKeys() { - - nativeConnection.set(KEY_1, VALUE_1); - nativeConnection.set(KEY_2, VALUE_2); - - assertThat(clusterConnection.keys(LettuceConverters.toBytes("*")), hasItems(KEY_1_BYTES, KEY_2_BYTES)); - } - - @Test // DATAREDIS-315 - public void keysShouldReturnAllKeysForSpecificNode() { - - nativeConnection.set(KEY_1, VALUE_1); - nativeConnection.set(KEY_2, VALUE_2); - - Set keysOnNode = clusterConnection.keys(new RedisClusterNode("127.0.0.1", 7379, SlotRange.empty()), - JedisConverters.toBytes("*")); - - assertThat(keysOnNode, hasItems(KEY_2_BYTES)); - assertThat(keysOnNode, not(hasItems(KEY_1_BYTES))); - } - - @Test // DATAREDIS-315 - public void randomKeyShouldReturnCorrectlyWhenKeysAvailable() { - - nativeConnection.set(KEY_1, VALUE_1); - nativeConnection.set(KEY_2, VALUE_2); - - assertThat(clusterConnection.randomKey(), notNullValue()); - } - - @Test // DATAREDIS-315 - public void randomKeyShouldReturnNullWhenNoKeysAvailable() { - assertThat(clusterConnection.randomKey(), nullValue()); - } - - @Test // DATAREDIS-315 - public void rename() { - - nativeConnection.set(KEY_1, VALUE_1); - - clusterConnection.rename(KEY_1_BYTES, KEY_2_BYTES); - - assertThat(nativeConnection.exists(KEY_1), is(0L)); - assertThat(nativeConnection.get(KEY_2), is(VALUE_1)); - } - - @Test // DATAREDIS-315 - public void renameSameKeysOnSameSlot() { - - nativeConnection.set(SAME_SLOT_KEY_1, VALUE_1); - - clusterConnection.rename(SAME_SLOT_KEY_1_BYTES, SAME_SLOT_KEY_2_BYTES); - - assertThat(nativeConnection.exists(SAME_SLOT_KEY_1), is(0L)); - assertThat(nativeConnection.get(SAME_SLOT_KEY_2), is(VALUE_1)); - } - - @Test // DATAREDIS-315 - public void renameNXWhenTargetKeyDoesNotExist() { - - nativeConnection.set(KEY_1, VALUE_1); - - assertThat(clusterConnection.renameNX(KEY_1_BYTES, KEY_2_BYTES), is(Boolean.TRUE)); - - assertThat(nativeConnection.exists(KEY_1), is(0L)); - assertThat(nativeConnection.get(KEY_2), is(VALUE_1)); - } - - @Test // DATAREDIS-315 - public void renameNXWhenTargetKeyDoesExist() { - - nativeConnection.set(KEY_1, VALUE_1); - nativeConnection.set(KEY_2, VALUE_2); - - assertThat(clusterConnection.renameNX(KEY_1_BYTES, KEY_2_BYTES), is(Boolean.FALSE)); - - assertThat(nativeConnection.get(KEY_1), is(VALUE_1)); - assertThat(nativeConnection.get(KEY_2), is(VALUE_2)); - } - - @Test // DATAREDIS-315 - public void renameNXWhenOnSameSlot() { - - nativeConnection.set(SAME_SLOT_KEY_1, VALUE_1); - - assertThat(clusterConnection.renameNX(SAME_SLOT_KEY_1_BYTES, SAME_SLOT_KEY_2_BYTES), is(Boolean.TRUE)); - - assertThat(nativeConnection.exists(SAME_SLOT_KEY_1), is(0L)); - assertThat(nativeConnection.get(SAME_SLOT_KEY_2), is(VALUE_1)); - } - - @Test // DATAREDIS-315 - public void expireShouldBeSetCorreclty() { - - nativeConnection.set(KEY_1, VALUE_1); - - clusterConnection.expire(KEY_1_BYTES, 5); - - assertThat(nativeConnection.ttl(LettuceConverters.toString(KEY_1_BYTES)) > 1, is(true)); - } - - @Test // DATAREDIS-315 - public void pExpireShouldBeSetCorreclty() { - - nativeConnection.set(KEY_1, VALUE_1); - - clusterConnection.pExpire(KEY_1_BYTES, 5000); - - assertThat(nativeConnection.ttl(LettuceConverters.toString(KEY_1_BYTES)) > 1, is(true)); - } - - @Test // DATAREDIS-315 - public void expireAtShouldBeSetCorrectly() { - - nativeConnection.set(KEY_1, VALUE_1); - - clusterConnection.expireAt(KEY_1_BYTES, System.currentTimeMillis() / 1000 + 5000); - - assertThat(nativeConnection.ttl(LettuceConverters.toString(KEY_1_BYTES)) > 1, is(true)); - } - - @Test // DATAREDIS-315 - public void pExpireAtShouldBeSetCorrectly() { - - nativeConnection.set(KEY_1, VALUE_1); - - clusterConnection.pExpireAt(KEY_1_BYTES, System.currentTimeMillis() + 5000); - - assertThat(nativeConnection.ttl(LettuceConverters.toString(KEY_1_BYTES)) > 1, is(true)); - } - - @Test // DATAREDIS-315 - public void persistShouldRemoveTTL() { - - nativeConnection.setex(KEY_1, 10, VALUE_1); - - assertThat(clusterConnection.persist(KEY_1_BYTES), is(Boolean.TRUE)); - assertThat(nativeConnection.ttl(KEY_1), is(-1L)); - } - - @Test(expected = UnsupportedOperationException.class) // DATAREDIS-315 - public void moveShouldNotBeSupported() { - clusterConnection.move(KEY_1_BYTES, 3); - } - - @Test // DATAREDIS-315 - public void dbSizeShouldReturnCummulatedDbSize() { - - nativeConnection.set(KEY_1, VALUE_1); - nativeConnection.set(KEY_2, VALUE_2); - - assertThat(clusterConnection.dbSize(), is(2L)); - } - - @Test // DATAREDIS-315 - public void dbSizeForSpecificNodeShouldGetNodeDbSize() { - - nativeConnection.set(KEY_1, VALUE_1); - nativeConnection.set(KEY_2, VALUE_2); - - assertThat(clusterConnection.dbSize(new RedisClusterNode("127.0.0.1", 7379, SlotRange.empty())), is(1L)); - assertThat(clusterConnection.dbSize(new RedisClusterNode("127.0.0.1", 7380, SlotRange.empty())), is(1L)); - assertThat(clusterConnection.dbSize(new RedisClusterNode("127.0.0.1", 7381, SlotRange.empty())), is(0L)); - } - - @Test // DATAREDIS-315 - public void ttlShouldReturnMinusTwoWhenKeyDoesNotExist() { - assertThat(clusterConnection.ttl(KEY_1_BYTES), is(-2L)); - } - - @Test // DATAREDIS-526 - public void ttlWithTimeUnitShouldReturnMinusTwoWhenKeyDoesNotExist() { - assertThat(clusterConnection.ttl(KEY_1_BYTES, TimeUnit.HOURS), is(-2L)); - } - - @Test // DATAREDIS-315 - public void ttlShouldReturnMinusOneWhenKeyDoesNotHaveExpirationSet() { - - nativeConnection.set(KEY_1, VALUE_1); - - assertThat(clusterConnection.ttl(KEY_1_BYTES), is(-1L)); - } - - @Test // DATAREDIS-526 - public void ttlWithTimeUnitShouldReturnMinusOneWhenKeyDoesNotHaveExpirationSet() { - - nativeConnection.set(KEY_1, VALUE_1); - - assertThat(clusterConnection.ttl(KEY_1_BYTES, TimeUnit.SECONDS), is(-1L)); - } - - @Test // DATAREDIS-315 - public void ttlShouldReturnValueCorrectly() { - - nativeConnection.set(KEY_1, VALUE_1); - nativeConnection.expire(KEY_1, 5); - - assertThat(clusterConnection.ttl(KEY_1_BYTES) > 1, is(true)); - } - - @Test // DATAREDIS-315 - public void pTtlShouldReturnMinusTwoWhenKeyDoesNotExist() { - assertThat(clusterConnection.pTtl(KEY_1_BYTES), is(-2L)); - } - - @Test // DATAREDIS-526 - public void pTtlWithTimeUnitShouldReturnMinusTwoWhenKeyDoesNotExist() { - assertThat(clusterConnection.pTtl(KEY_1_BYTES, TimeUnit.SECONDS), is(-2L)); - } - - @Test // DATAREDIS-315 - public void pTtlShouldReturnMinusOneWhenKeyDoesNotHaveExpirationSet() { - - nativeConnection.set(KEY_1, VALUE_1); - - assertThat(clusterConnection.pTtl(KEY_1_BYTES), is(-1L)); - } - - @Test // DATAREDIS-315 - public void pTtlShouldReturValueCorrectly() { - - nativeConnection.set(KEY_1, VALUE_1); - nativeConnection.expire(KEY_1, 5); - - assertThat(clusterConnection.pTtl(KEY_1_BYTES) > 1, is(true)); - } - - @Test // DATAREDIS-315 - public void sortShouldReturnValuesCorrectly() { - - nativeConnection.lpush(KEY_1, VALUE_2, VALUE_1); - - assertThat(clusterConnection.sort(KEY_1_BYTES, new DefaultSortParameters().alpha()), - hasItems(VALUE_1_BYTES, VALUE_2_BYTES)); - } - - @Test // DATAREDIS-315 - public void sortAndStoreShouldAddSortedValuesValuesCorrectly() { - - nativeConnection.lpush(KEY_1, VALUE_2, VALUE_1); - - assertThat(clusterConnection.sort(KEY_1_BYTES, new DefaultSortParameters().alpha(), KEY_2_BYTES), is(1L)); - assertThat(nativeConnection.exists(KEY_2), is(1L)); - } - - @Test // DATAREDIS-315 - public void sortAndStoreShouldReturnZeroWhenListDoesNotExist() { - assertThat(clusterConnection.sort(KEY_1_BYTES, new DefaultSortParameters().alpha(), KEY_2_BYTES), is(0L)); - } - - @Test // DATAREDIS-315 - public void dumpAndRestoreShouldWorkCorrectly() { - - nativeConnection.set(KEY_1, VALUE_1); - - byte[] dumpedValue = clusterConnection.dump(KEY_1_BYTES); - clusterConnection.restore(KEY_2_BYTES, 0, dumpedValue); - - assertThat(nativeConnection.get(KEY_2), is(VALUE_1)); - } - - @Test // DATAREDIS-315 - public void getShouldReturnValueCorrectly() { - - nativeConnection.set(KEY_1, VALUE_1); - - assertThat(clusterConnection.get(KEY_1_BYTES), is(VALUE_1_BYTES)); - } - - @Test // DATAREDIS-315 - public void getSetShouldWorkCorrectly() { - - nativeConnection.set(KEY_1, VALUE_1); - - byte[] valueBeforeSet = clusterConnection.getSet(KEY_1_BYTES, VALUE_2_BYTES); - - assertThat(valueBeforeSet, is(VALUE_1_BYTES)); - assertThat(nativeConnection.get(KEY_1), is(VALUE_2)); - } - - @Test // DATAREDIS-315 - public void mGetShouldReturnCorrectlyWhenKeysMapToSameSlot() { - - nativeConnection.set(SAME_SLOT_KEY_1, VALUE_1); - nativeConnection.set(SAME_SLOT_KEY_2, VALUE_2); - - assertThat(clusterConnection.mGet(SAME_SLOT_KEY_1_BYTES, SAME_SLOT_KEY_2_BYTES), - contains(VALUE_1_BYTES, VALUE_2_BYTES)); - } - - @Test // DATAREDIS-315 - public void mGetShouldReturnCorrectlyWhenKeysDoNotMapToSameSlot() { - - nativeConnection.set(KEY_1, VALUE_1); - nativeConnection.set(KEY_2, VALUE_2); - - assertThat(clusterConnection.mGet(KEY_1_BYTES, KEY_2_BYTES), contains(VALUE_1_BYTES, VALUE_2_BYTES)); - } - - @Test // DATAREDIS-315 - public void setShouldSetValueCorrectly() { - - clusterConnection.set(KEY_1_BYTES, VALUE_1_BYTES); - - assertThat(nativeConnection.get(KEY_1), is(VALUE_1)); - } - - @Test // DATAREDIS-315 - public void setNxShouldSetValueCorrectly() { - - clusterConnection.setNX(KEY_1_BYTES, VALUE_1_BYTES); - - assertThat(nativeConnection.get(KEY_1), is(VALUE_1)); - } - - @Test // DATAREDIS-315 - public void setNxShouldNotSetValueWhenAlreadyExistsInDBCorrectly() { - - nativeConnection.set(KEY_1, VALUE_1); - - clusterConnection.setNX(KEY_1_BYTES, VALUE_2_BYTES); - - assertThat(nativeConnection.get(KEY_1), is(VALUE_1)); - } - - @Test // DATAREDIS-315 - public void setExShouldSetValueCorrectly() { - - clusterConnection.setEx(KEY_1_BYTES, 5, VALUE_1_BYTES); - - assertThat(nativeConnection.get(KEY_1), is(VALUE_1)); - assertThat(nativeConnection.ttl(KEY_1) > 1, is(true)); - } - - @Test // DATAREDIS-315 - public void pSetExShouldSetValueCorrectly() { - - clusterConnection.pSetEx(KEY_1_BYTES, 5000, VALUE_1_BYTES); - - assertThat(nativeConnection.get(KEY_1), is(VALUE_1)); - assertThat(nativeConnection.ttl(KEY_1) > 1, is(true)); - } - - @Test // DATAREDIS-315 - public void mSetShouldWorkWhenKeysMapToSameSlot() { - - Map map = new LinkedHashMap<>(); - map.put(SAME_SLOT_KEY_1_BYTES, VALUE_1_BYTES); - map.put(SAME_SLOT_KEY_2_BYTES, VALUE_2_BYTES); - - clusterConnection.mSet(map); - - assertThat(nativeConnection.get(SAME_SLOT_KEY_1), is(VALUE_1)); - assertThat(nativeConnection.get(SAME_SLOT_KEY_2), is(VALUE_2)); - } - - @Test // DATAREDIS-315 - public void mSetShouldWorkWhenKeysDoNotMapToSameSlot() { - - Map map = new LinkedHashMap<>(); - map.put(KEY_1_BYTES, VALUE_1_BYTES); - map.put(KEY_2_BYTES, VALUE_2_BYTES); - - clusterConnection.mSet(map); - - assertThat(nativeConnection.get(KEY_1), is(VALUE_1)); - assertThat(nativeConnection.get(KEY_2), is(VALUE_2)); - } - - @Test // DATAREDIS-315 - public void mSetNXShouldReturnTrueIfAllKeysSet() { - - Map map = new LinkedHashMap<>(); - map.put(KEY_1_BYTES, VALUE_1_BYTES); - map.put(KEY_2_BYTES, VALUE_2_BYTES); - - assertThat(clusterConnection.mSetNX(map), is(true)); - - assertThat(nativeConnection.get(KEY_1), is(VALUE_1)); - assertThat(nativeConnection.get(KEY_2), is(VALUE_2)); - } - - @Test // DATAREDIS-315 - public void mSetNXShouldReturnFalseIfNotAllKeysSet() { - - nativeConnection.set(KEY_2, VALUE_3); - Map map = new LinkedHashMap<>(); - map.put(KEY_1_BYTES, VALUE_1_BYTES); - map.put(KEY_2_BYTES, VALUE_2_BYTES); - - assertThat(clusterConnection.mSetNX(map), is(false)); - - assertThat(nativeConnection.get(KEY_1), is(VALUE_1)); - assertThat(nativeConnection.get(KEY_2), is(VALUE_3)); - } - - @Test // DATAREDIS-315 - public void mSetNXShouldWorkForOnSameSlotKeys() { - - Map map = new LinkedHashMap<>(); - map.put(SAME_SLOT_KEY_1_BYTES, VALUE_1_BYTES); - map.put(SAME_SLOT_KEY_2_BYTES, VALUE_2_BYTES); - - assertThat(clusterConnection.mSetNX(map), is(true)); - - assertThat(nativeConnection.get(SAME_SLOT_KEY_1), is(VALUE_1)); - assertThat(nativeConnection.get(SAME_SLOT_KEY_2), is(VALUE_2)); - } - - @Test // DATAREDIS-315 - public void incrShouldIncreaseValueCorrectly() { - - nativeConnection.set(KEY_1, "1"); - - assertThat(clusterConnection.incr(KEY_1_BYTES), is(2L)); - } - - @Test // DATAREDIS-315 - public void incrByFloatShouldIncreaseValueCorrectly() { - - nativeConnection.set(KEY_1, "1"); - - assertThat(clusterConnection.incrBy(KEY_1_BYTES, 5.5D), is(6.5D)); - } - - @Test // DATAREDIS-315 - public void incrByShouldIncreaseValueCorrectly() { - - nativeConnection.set(KEY_1, "1"); - - assertThat(clusterConnection.incrBy(KEY_1_BYTES, 5), is(6L)); - } - - @Test // DATAREDIS-315 - public void decrShouldDecreaseValueCorrectly() { - - nativeConnection.set(KEY_1, "5"); - - assertThat(clusterConnection.decr(KEY_1_BYTES), is(4L)); - } - - @Test // DATAREDIS-315 - public void decrByShouldDecreaseValueCorrectly() { - - nativeConnection.set(KEY_1, "5"); - - assertThat(clusterConnection.decrBy(KEY_1_BYTES, 4), is(1L)); - } - @Test // DATAREDIS-315 public void appendShouldAddValueCorrectly() { @@ -644,41 +131,21 @@ public class LettuceClusterConnectionTests implements ClusterConnectionTests { } @Test // DATAREDIS-315 - public void getRangeShouldReturnValueCorrectly() { + public void bRPopLPushShouldWork() { - nativeConnection.set(KEY_1, VALUE_1); + nativeConnection.lpush(KEY_1, VALUE_1, VALUE_2); - assertThat(clusterConnection.getRange(KEY_1_BYTES, 0, 2), is(LettuceConverters.toBytes("val"))); + assertThat(clusterConnection.bRPopLPush(0, KEY_1_BYTES, KEY_2_BYTES), is(VALUE_1_BYTES)); + assertThat(nativeConnection.exists(KEY_2), is(1L)); } @Test // DATAREDIS-315 - public void setRangeShouldWorkCorrectly() { + public void bRPopLPushShouldWorkOnSameSlotKeys() { - nativeConnection.set(KEY_1, VALUE_1); + nativeConnection.lpush(SAME_SLOT_KEY_1, VALUE_1, VALUE_2); - clusterConnection.setRange(KEY_1_BYTES, LettuceConverters.toBytes("UE"), 3); - - assertThat(nativeConnection.get(KEY_1), is("valUE1")); - } - - @Test // DATAREDIS-315 - public void getBitShouldWorkCorrectly() { - - nativeConnection.setbit(KEY_1, 0, 1); - nativeConnection.setbit(KEY_1, 1, 0); - - assertThat(clusterConnection.getBit(KEY_1_BYTES, 0), is(true)); - assertThat(clusterConnection.getBit(KEY_1_BYTES, 1), is(false)); - } - - @Test // DATAREDIS-315 - public void setBitShouldWorkCorrectly() { - - clusterConnection.setBit(KEY_1_BYTES, 0, true); - clusterConnection.setBit(KEY_1_BYTES, 1, false); - - assertThat(nativeConnection.getbit(KEY_1, 0), is(1L)); - assertThat(nativeConnection.getbit(KEY_1, 1), is(0L)); + assertThat(clusterConnection.bRPopLPush(0, SAME_SLOT_KEY_1_BYTES, SAME_SLOT_KEY_2_BYTES), is(VALUE_1_BYTES)); + assertThat(nativeConnection.exists(SAME_SLOT_KEY_2), is(1L)); } @Test // DATAREDIS-315 @@ -702,6 +169,11 @@ public class LettuceClusterConnectionTests implements ClusterConnectionTests { assertThat(clusterConnection.bitCount(KEY_1_BYTES, 0, 3), is(3L)); } + @Test(expected = DataAccessException.class) // DATAREDIS-315 + public void bitOpShouldThrowExceptionWhenKeysDoNotMapToSameSlot() { + clusterConnection.bitOp(BitOperation.AND, KEY_1_BYTES, KEY_2_BYTES, KEY_3_BYTES); + } + @Test // DATAREDIS-315 public void bitOpShouldWorkCorrectly() { @@ -713,131 +185,6 @@ public class LettuceClusterConnectionTests implements ClusterConnectionTests { assertThat(nativeConnection.get(SAME_SLOT_KEY_3), is("bab")); } - @Test(expected = DataAccessException.class) // DATAREDIS-315 - public void bitOpShouldThrowExceptionWhenKeysDoNotMapToSameSlot() { - clusterConnection.bitOp(BitOperation.AND, KEY_1_BYTES, KEY_2_BYTES, KEY_3_BYTES); - } - - @Test // DATAREDIS-315 - public void strLenShouldWorkCorrectly() { - - nativeConnection.set(KEY_1, VALUE_1); - - assertThat(clusterConnection.strLen(KEY_1_BYTES), is(6L)); - } - - @Test // DATAREDIS-315 - public void rPushShoultAddValuesCorrectly() { - - clusterConnection.rPush(KEY_1_BYTES, VALUE_1_BYTES, VALUE_2_BYTES); - - assertThat(nativeConnection.lrange(KEY_1, 0, -1), hasItems(VALUE_1, VALUE_2)); - } - - @Test // DATAREDIS-315 - public void lPushShoultAddValuesCorrectly() { - - clusterConnection.lPush(KEY_1_BYTES, VALUE_1_BYTES, VALUE_2_BYTES); - - assertThat(nativeConnection.lrange(KEY_1, 0, -1), hasItems(VALUE_1, VALUE_2)); - } - - @Test // DATAREDIS-315 - public void rPushNXShoultNotAddValuesWhenKeyDoesNotExist() { - - clusterConnection.rPushX(KEY_1_BYTES, VALUE_1_BYTES); - - assertThat(nativeConnection.exists(KEY_1), is(0L)); - } - - @Test // DATAREDIS-315 - public void lPushNXShoultNotAddValuesWhenKeyDoesNotExist() { - - clusterConnection.lPushX(KEY_1_BYTES, VALUE_1_BYTES); - - assertThat(nativeConnection.exists(KEY_1), is(0L)); - } - - @Test // DATAREDIS-315 - public void lLenShouldCountValuesCorrectly() { - - nativeConnection.lpush(KEY_1, VALUE_1, VALUE_2); - - assertThat(clusterConnection.lLen(KEY_1_BYTES), is(2L)); - } - - @Test // DATAREDIS-315 - public void lRangeShouldGetValuesCorrectly() { - - nativeConnection.lpush(KEY_1, VALUE_1, VALUE_2); - - assertThat(clusterConnection.lRange(KEY_1_BYTES, 0L, -1L), hasItems(VALUE_1_BYTES, VALUE_2_BYTES)); - } - - @Test // DATAREDIS-315 - public void lTrimShouldTrimListCorrectly() { - - nativeConnection.lpush(KEY_1, VALUE_1, VALUE_2, "foo", "bar"); - - clusterConnection.lTrim(KEY_1_BYTES, 2, 3); - - assertThat(nativeConnection.lrange(KEY_1, 0, -1), hasItems(VALUE_1, VALUE_2)); - } - - @Test // DATAREDIS-315 - public void lIndexShouldGetElementAtIndexCorrectly() { - - nativeConnection.rpush(KEY_1, VALUE_1, VALUE_2, "foo", "bar"); - - assertThat(clusterConnection.lIndex(KEY_1_BYTES, 1), is(VALUE_2_BYTES)); - } - - @Test // DATAREDIS-315 - public void lInsertShouldAddElementAtPositionCorrectly() { - - nativeConnection.rpush(KEY_1, VALUE_1, VALUE_2, "foo", "bar"); - - clusterConnection.lInsert(KEY_1_BYTES, Position.AFTER, VALUE_2_BYTES, LettuceConverters.toBytes("booh!")); - - assertThat(nativeConnection.lrange(KEY_1, 0, -1).get(2), is("booh!")); - } - - @Test // DATAREDIS-315 - public void lSetShouldSetElementAtPositionCorrectly() { - - nativeConnection.rpush(KEY_1, VALUE_1, VALUE_2, "foo", "bar"); - - clusterConnection.lSet(KEY_1_BYTES, 1L, VALUE_1_BYTES); - - assertThat(nativeConnection.lrange(KEY_1, 0, -1).get(1), is(VALUE_1)); - } - - @Test // DATAREDIS-315 - public void lRemShouldRemoveElementAtPositionCorrectly() { - - nativeConnection.rpush(KEY_1, VALUE_1, VALUE_2, "foo", "bar"); - - clusterConnection.lRem(KEY_1_BYTES, 1L, VALUE_1_BYTES); - - assertThat(nativeConnection.llen(KEY_1), is(3L)); - } - - @Test // DATAREDIS-315 - public void lPopShouldReturnElementCorrectly() { - - nativeConnection.rpush(KEY_1, VALUE_1, VALUE_2); - - assertThat(clusterConnection.lPop(KEY_1_BYTES), is(VALUE_1_BYTES)); - } - - @Test // DATAREDIS-315 - public void rPopShouldReturnElementCorrectly() { - - nativeConnection.rpush(KEY_1, VALUE_1, VALUE_2); - - assertThat(clusterConnection.rPop(KEY_1_BYTES), is(VALUE_2_BYTES)); - } - @Test // DATAREDIS-315 public void blPopShouldPopElementCorectly() { @@ -874,990 +221,11 @@ public class LettuceClusterConnectionTests implements ClusterConnectionTests { assertThat(clusterConnection.bRPop(100, SAME_SLOT_KEY_1_BYTES, SAME_SLOT_KEY_2_BYTES).size(), is(2)); } - @Test // DATAREDIS-315 - public void rPopLPushShouldWorkWhenDoNotMapToSameSlot() { - - nativeConnection.lpush(KEY_1, VALUE_1, VALUE_2); - nativeConnection.lpush(KEY_2, VALUE_3); - - assertThat(clusterConnection.bLPop(100, KEY_1_BYTES, KEY_2_BYTES).size(), is(2)); - } - - @Test // DATAREDIS-315 - public void bRPopLPushShouldWork() { - - nativeConnection.lpush(KEY_1, VALUE_1, VALUE_2); - - assertThat(clusterConnection.bRPopLPush(0, KEY_1_BYTES, KEY_2_BYTES), is(VALUE_1_BYTES)); - assertThat(nativeConnection.exists(KEY_2), is(1L)); - } - - @Test // DATAREDIS-315 - public void bRPopLPushShouldWorkOnSameSlotKeys() { - - nativeConnection.lpush(SAME_SLOT_KEY_1, VALUE_1, VALUE_2); - - assertThat(clusterConnection.bRPopLPush(0, SAME_SLOT_KEY_1_BYTES, SAME_SLOT_KEY_2_BYTES), is(VALUE_1_BYTES)); - assertThat(nativeConnection.exists(SAME_SLOT_KEY_2), is(1L)); - } - - @Test // DATAREDIS-315 - public void rPopLPushShouldWorkWhenKeysOnSameSlot() { - - nativeConnection.lpush(SAME_SLOT_KEY_1, VALUE_1, VALUE_2); - - assertThat(clusterConnection.rPopLPush(SAME_SLOT_KEY_1_BYTES, SAME_SLOT_KEY_2_BYTES), is(VALUE_1_BYTES)); - assertThat(nativeConnection.exists(SAME_SLOT_KEY_2), is(1L)); - } - - @Test // DATAREDIS-315 - public void sAddShouldAddValueToSetCorrectly() { - - clusterConnection.sAdd(KEY_1_BYTES, VALUE_1_BYTES, VALUE_2_BYTES); - - assertThat(nativeConnection.smembers(KEY_1), hasItems(VALUE_1, VALUE_2)); - } - - @Test // DATAREDIS-315 - public void sRemShouldRemoveValueFromSetCorrectly() { - - nativeConnection.sadd(KEY_1, VALUE_1, VALUE_2); - - clusterConnection.sRem(KEY_1_BYTES, VALUE_2_BYTES); - - assertThat(nativeConnection.smembers(KEY_1), hasItems(VALUE_1)); - } - - @Test // DATAREDIS-315 - public void sPopShouldPopValueFromSetCorrectly() { - - nativeConnection.sadd(KEY_1, VALUE_1, VALUE_2); - - assertThat(clusterConnection.sPop(KEY_1_BYTES), notNullValue()); - } - - @Test // DATAREDIS-668 - public void sPopWithCountShouldPopValueFromSetCorrectly() { - - nativeConnection.sadd(KEY_1, VALUE_1, VALUE_2, VALUE_3); - - assertThat(clusterConnection.setCommands().sPop(KEY_1_BYTES, 2), hasSize(2)); - assertThat(nativeConnection.scard(KEY_1), is(1L)); - } - - @Test // DATAREDIS-315 - public void sMoveShouldWorkWhenKeysMapToSameSlot() { - - nativeConnection.sadd(SAME_SLOT_KEY_1, VALUE_1, VALUE_2); - nativeConnection.sadd(SAME_SLOT_KEY_2, VALUE_3); - - clusterConnection.sMove(SAME_SLOT_KEY_1_BYTES, SAME_SLOT_KEY_2_BYTES, VALUE_2_BYTES); - - assertThat(nativeConnection.sismember(SAME_SLOT_KEY_1, VALUE_2), is(false)); - assertThat(nativeConnection.sismember(SAME_SLOT_KEY_2, VALUE_2), is(true)); - } - - @Test // DATAREDIS-315 - public void sMoveShouldWorkWhenKeysDoNotMapToSameSlot() { - - nativeConnection.sadd(KEY_1, VALUE_1, VALUE_2); - nativeConnection.sadd(KEY_2, VALUE_3); - - clusterConnection.sMove(KEY_1_BYTES, KEY_2_BYTES, VALUE_2_BYTES); - - assertThat(nativeConnection.sismember(KEY_1, VALUE_2), is(false)); - assertThat(nativeConnection.sismember(KEY_2, VALUE_2), is(true)); - } - - @Test // DATAREDIS-315 - public void sCardShouldCountValuesInSetCorrectly() { - - nativeConnection.sadd(KEY_1, VALUE_1, VALUE_2); - - assertThat(clusterConnection.sCard(KEY_1_BYTES), is(2L)); - } - - @Test // DATAREDIS-315 - public void sIsMemberShouldReturnTrueIfValueIsMemberOfSet() { - - nativeConnection.sadd(KEY_1, VALUE_1, VALUE_2); - - assertThat(clusterConnection.sIsMember(KEY_1_BYTES, VALUE_1_BYTES), is(true)); - } - - @Test // DATAREDIS-315 - public void sIsMemberShouldReturnFalseIfValueIsMemberOfSet() { - - nativeConnection.sadd(KEY_1, VALUE_1, VALUE_2); - - assertThat(clusterConnection.sIsMember(KEY_1_BYTES, LettuceConverters.toBytes("foo")), is(false)); - } - - @Test // DATAREDIS-315 - public void sInterShouldWorkForKeysMappingToSameSlot() { - - nativeConnection.sadd(SAME_SLOT_KEY_1, VALUE_1, VALUE_2); - nativeConnection.sadd(SAME_SLOT_KEY_2, VALUE_2, VALUE_3); - - assertThat(clusterConnection.sInter(SAME_SLOT_KEY_1_BYTES, SAME_SLOT_KEY_2_BYTES), hasItem(VALUE_2_BYTES)); - } - - @Test // DATAREDIS-315 - public void sInterShouldWorkForKeysNotMappingToSameSlot() { - - nativeConnection.sadd(KEY_1, VALUE_1, VALUE_2); - nativeConnection.sadd(KEY_2, VALUE_2, VALUE_3); - - assertThat(clusterConnection.sInter(KEY_1_BYTES, KEY_2_BYTES), hasItem(VALUE_2_BYTES)); - } - - @Test // DATAREDIS-315 - public void sInterStoreShouldWorkForKeysMappingToSameSlot() { - - nativeConnection.sadd(SAME_SLOT_KEY_1, VALUE_1, VALUE_2); - nativeConnection.sadd(SAME_SLOT_KEY_2, VALUE_2, VALUE_3); - - clusterConnection.sInterStore(SAME_SLOT_KEY_3_BYTES, SAME_SLOT_KEY_1_BYTES, SAME_SLOT_KEY_2_BYTES); - - assertThat(nativeConnection.smembers(SAME_SLOT_KEY_3), hasItem(VALUE_2)); - } - - @Test // DATAREDIS-315 - public void sInterStoreShouldWorkForKeysNotMappingToSameSlot() { - - nativeConnection.sadd(KEY_1, VALUE_1, VALUE_2); - nativeConnection.sadd(KEY_2, VALUE_2, VALUE_3); - - clusterConnection.sInterStore(KEY_3_BYTES, KEY_1_BYTES, KEY_2_BYTES); - - assertThat(nativeConnection.smembers(KEY_3), hasItem(VALUE_2)); - } - - @Test // DATAREDIS-315 - public void sUnionShouldWorkForKeysMappingToSameSlot() { - - nativeConnection.sadd(SAME_SLOT_KEY_1, VALUE_1, VALUE_2); - nativeConnection.sadd(SAME_SLOT_KEY_2, VALUE_2, VALUE_3); - - assertThat(clusterConnection.sUnion(SAME_SLOT_KEY_1_BYTES, SAME_SLOT_KEY_2_BYTES), - hasItems(VALUE_1_BYTES, VALUE_2_BYTES, VALUE_3_BYTES)); - } - - @Test // DATAREDIS-315 - public void sUnionShouldWorkForKeysNotMappingToSameSlot() { - - nativeConnection.sadd(KEY_1, VALUE_1, VALUE_2); - nativeConnection.sadd(KEY_2, VALUE_2, VALUE_3); - - assertThat(clusterConnection.sUnion(KEY_1_BYTES, KEY_2_BYTES), - hasItems(VALUE_1_BYTES, VALUE_2_BYTES, VALUE_3_BYTES)); - } - - @Test // DATAREDIS-315 - public void sUnionStoreShouldWorkForKeysMappingToSameSlot() { - - nativeConnection.sadd(SAME_SLOT_KEY_1, VALUE_1, VALUE_2); - nativeConnection.sadd(SAME_SLOT_KEY_2, VALUE_2, VALUE_3); - - clusterConnection.sUnionStore(SAME_SLOT_KEY_3_BYTES, SAME_SLOT_KEY_1_BYTES, SAME_SLOT_KEY_2_BYTES); - - assertThat(nativeConnection.smembers(SAME_SLOT_KEY_3), hasItems(VALUE_1, VALUE_2, VALUE_3)); - } - - @Test // DATAREDIS-315 - public void sUnionStoreShouldWorkForKeysNotMappingToSameSlot() { - - nativeConnection.sadd(KEY_1, VALUE_1, VALUE_2); - nativeConnection.sadd(KEY_2, VALUE_2, VALUE_3); - - clusterConnection.sUnionStore(KEY_3_BYTES, KEY_1_BYTES, KEY_2_BYTES); - - assertThat(nativeConnection.smembers(KEY_3), hasItems(VALUE_1, VALUE_2, VALUE_3)); - } - - @Test // DATAREDIS-315 - public void sDiffShouldWorkWhenKeysMapToSameSlot() { - - nativeConnection.sadd(SAME_SLOT_KEY_1, VALUE_1, VALUE_2); - nativeConnection.sadd(SAME_SLOT_KEY_2, VALUE_2, VALUE_3); - - assertThat(clusterConnection.sDiff(SAME_SLOT_KEY_1_BYTES, SAME_SLOT_KEY_2_BYTES), hasItems(VALUE_1_BYTES)); - } - - @Test // DATAREDIS-315, DATAREDIS-647 - public void sDiffShouldWorkWhenKeysNotMapToSameSlot() { - - nativeConnection.sadd(KEY_1, VALUE_1, VALUE_2); - nativeConnection.sadd(KEY_2, VALUE_2, VALUE_3); - nativeConnection.sadd(KEY_3, VALUE_1, VALUE_3); - - assertThat(clusterConnection.sDiff(KEY_1_BYTES, KEY_2_BYTES), hasItems(VALUE_1_BYTES)); - assertThat(clusterConnection.sDiff(KEY_1_BYTES, KEY_2_BYTES, KEY_3_BYTES), is(empty())); - } - - @Test // DATAREDIS-315 - public void sDiffStoreShouldWorkWhenKeysMapToSameSlot() { - - nativeConnection.sadd(SAME_SLOT_KEY_1, VALUE_1, VALUE_2); - nativeConnection.sadd(SAME_SLOT_KEY_2, VALUE_2, VALUE_3); - - clusterConnection.sDiffStore(SAME_SLOT_KEY_3_BYTES, SAME_SLOT_KEY_1_BYTES, SAME_SLOT_KEY_2_BYTES); - - assertThat(nativeConnection.smembers(SAME_SLOT_KEY_3), hasItems(VALUE_1)); - } - - @Test // DATAREDIS-315 - public void sDiffStoreShouldWorkWhenKeysNotMapToSameSlot() { - - nativeConnection.sadd(KEY_1, VALUE_1, VALUE_2); - nativeConnection.sadd(KEY_2, VALUE_2, VALUE_3); - - clusterConnection.sDiffStore(KEY_3_BYTES, KEY_1_BYTES, KEY_2_BYTES); - - assertThat(nativeConnection.smembers(KEY_3), hasItems(VALUE_1)); - } - - @Test // DATAREDIS-315 - public void sMembersShouldReturnValuesContainedInSetCorrectly() { - - nativeConnection.sadd(KEY_1, VALUE_1, VALUE_2); - - assertThat(clusterConnection.sMembers(KEY_1_BYTES), hasItems(VALUE_1_BYTES, VALUE_2_BYTES)); - } - - @Test // DATAREDIS-315 - public void sRandMamberShouldReturnValueCorrectly() { - - nativeConnection.sadd(KEY_1, VALUE_1, VALUE_2); - - assertThat(clusterConnection.sRandMember(KEY_1_BYTES), notNullValue()); - } - - @Test // DATAREDIS-315 - public void sRandMamberWithCountShouldReturnValueCorrectly() { - - nativeConnection.sadd(KEY_1, VALUE_1, VALUE_2); - - assertThat(clusterConnection.sRandMember(KEY_1_BYTES, 3), notNullValue()); - } - - @Test // DATAREDIS-315 - public void sscanShouldRetrieveAllValuesInSetCorrectly() { - - for (int i = 0; i < 30; i++) { - nativeConnection.sadd(KEY_1, Integer.valueOf(i).toString()); - } - - int count = 0; - Cursor cursor = clusterConnection.sScan(KEY_1_BYTES, ScanOptions.NONE); - while (cursor.hasNext()) { - count++; - cursor.next(); - } - - assertThat(count, is(30)); - } - - @Test // DATAREDIS-315 - public void zAddShouldAddValueWithScoreCorrectly() { - - clusterConnection.zAdd(KEY_1_BYTES, 10D, VALUE_1_BYTES); - clusterConnection.zAdd(KEY_1_BYTES, 20D, VALUE_2_BYTES); - - assertThat(nativeConnection.zcard(KEY_1), is(2L)); - } - - @Test // DATAREDIS-674 - public void zAddShouldAddMultipleValuesWithScoreCorrectly() { - - Set tuples = new HashSet<>(); - tuples.add(new DefaultTuple(VALUE_1_BYTES, 10D)); - tuples.add(new DefaultTuple(VALUE_2_BYTES, 20D)); - - clusterConnection.zAdd(KEY_1_BYTES, tuples); - - assertThat(nativeConnection.zcard(KEY_1), is(2L)); - } - - @Test // DATAREDIS-315 - public void zRemShouldRemoveValueWithScoreCorrectly() { - - nativeConnection.zadd(KEY_1, 10D, VALUE_1); - nativeConnection.zadd(KEY_1, 20D, VALUE_2); - - clusterConnection.zRem(KEY_1_BYTES, VALUE_1_BYTES); - - assertThat(nativeConnection.zcard(KEY_1), is(1L)); - } - - @Test // DATAREDIS-315 - public void zIncrByShouldIncScoreForValueCorrectly() { - - nativeConnection.zadd(KEY_1, 10D, VALUE_1); - nativeConnection.zadd(KEY_1, 20D, VALUE_2); - - clusterConnection.zIncrBy(KEY_1_BYTES, 100D, VALUE_1_BYTES); - - assertThat(nativeConnection.zrank(KEY_1, VALUE_1), is(1L)); - } - - @Test // DATAREDIS-315 - public void zRankShouldReturnPositionForValueCorrectly() { - - nativeConnection.zadd(KEY_1, 10D, VALUE_1); - nativeConnection.zadd(KEY_1, 20D, VALUE_2); - - assertThat(clusterConnection.zRank(KEY_1_BYTES, VALUE_2_BYTES), is(1L)); - } - - @Test // DATAREDIS-315 - public void zRankShouldReturnReversePositionForValueCorrectly() { - - nativeConnection.zadd(KEY_1, 10D, VALUE_1); - nativeConnection.zadd(KEY_1, 20D, VALUE_2); - - assertThat(clusterConnection.zRevRank(KEY_1_BYTES, VALUE_2_BYTES), is(0L)); - } - - @Test // DATAREDIS-315 - public void zRangeShouldReturnValuesCorrectly() { - - nativeConnection.zadd(KEY_1, 10D, VALUE_1); - nativeConnection.zadd(KEY_1, 20D, VALUE_2); - nativeConnection.zadd(KEY_1, 5D, VALUE_3); - - assertThat(clusterConnection.zRange(KEY_1_BYTES, 1, 2), hasItems(VALUE_1_BYTES, VALUE_2_BYTES)); - } - - @Test // DATAREDIS-315 - public void zRangeWithScoresShouldReturnValuesAndScoreCorrectly() { - - nativeConnection.zadd(KEY_1, 10D, VALUE_1); - nativeConnection.zadd(KEY_1, 20D, VALUE_2); - nativeConnection.zadd(KEY_1, 5D, VALUE_3); - - assertThat(clusterConnection.zRangeWithScores(KEY_1_BYTES, 1, 2), - hasItems((Tuple) new DefaultTuple(VALUE_1_BYTES, 10D), (Tuple) new DefaultTuple(VALUE_2_BYTES, 20D))); - } - - @Test // DATAREDIS-315 - public void zRangeByScoreShouldReturnValuesCorrectly() { - - nativeConnection.zadd(KEY_1, 10D, VALUE_1); - nativeConnection.zadd(KEY_1, 20D, VALUE_2); - nativeConnection.zadd(KEY_1, 5D, VALUE_3); - - assertThat(clusterConnection.zRangeByScore(KEY_1_BYTES, 10, 20), hasItems(VALUE_1_BYTES, VALUE_2_BYTES)); - } - - @Test // DATAREDIS-315 - public void zRangeByScoreWithScoresShouldReturnValuesAndScoreCorrectly() { - - nativeConnection.zadd(KEY_1, 10D, VALUE_1); - nativeConnection.zadd(KEY_1, 20D, VALUE_2); - nativeConnection.zadd(KEY_1, 5D, VALUE_3); - - assertThat(clusterConnection.zRangeByScoreWithScores(KEY_1_BYTES, 10, 20), - hasItems((Tuple) new DefaultTuple(VALUE_1_BYTES, 10D), (Tuple) new DefaultTuple(VALUE_2_BYTES, 20D))); - } - - @Test // DATAREDIS-315 - public void zRangeByScoreShouldReturnValuesCorrectlyWhenGivenOffsetAndScore() { - - nativeConnection.zadd(KEY_1, 10D, VALUE_1); - nativeConnection.zadd(KEY_1, 20D, VALUE_2); - nativeConnection.zadd(KEY_1, 5D, VALUE_3); - - assertThat(clusterConnection.zRangeByScore(KEY_1_BYTES, 10D, 20D, 0L, 1L), hasItems(VALUE_1_BYTES)); - } - - @Test // DATAREDIS-315 - public void zRangeByScoreWithScoresShouldReturnValuesCorrectlyWhenGivenOffsetAndScore() { - - nativeConnection.zadd(KEY_1, 10D, VALUE_1); - nativeConnection.zadd(KEY_1, 20D, VALUE_2); - nativeConnection.zadd(KEY_1, 5D, VALUE_3); - - assertThat(clusterConnection.zRangeByScoreWithScores(KEY_1_BYTES, 10D, 20D, 0L, 1L), - hasItems((Tuple) new DefaultTuple(VALUE_1_BYTES, 10D))); - } - - @Test // DATAREDIS-315 - public void zRevRangeShouldReturnValuesCorrectly() { - - nativeConnection.zadd(KEY_1, 10D, VALUE_1); - nativeConnection.zadd(KEY_1, 20D, VALUE_2); - nativeConnection.zadd(KEY_1, 5D, VALUE_3); - - assertThat(clusterConnection.zRevRange(KEY_1_BYTES, 1, 2), hasItems(VALUE_3_BYTES, VALUE_1_BYTES)); - } - - @Test // DATAREDIS-315 - public void zRevRangeWithScoresShouldReturnValuesAndScoreCorrectly() { - - nativeConnection.zadd(KEY_1, 10D, VALUE_1); - nativeConnection.zadd(KEY_1, 20D, VALUE_2); - nativeConnection.zadd(KEY_1, 5D, VALUE_3); - - assertThat(clusterConnection.zRevRangeWithScores(KEY_1_BYTES, 1, 2), - hasItems((Tuple) new DefaultTuple(VALUE_3_BYTES, 5D), (Tuple) new DefaultTuple(VALUE_1_BYTES, 10D))); - } - - @Test // DATAREDIS-315 - public void zRevRangeByScoreShouldReturnValuesCorrectly() { - - nativeConnection.zadd(KEY_1, 10D, VALUE_1); - nativeConnection.zadd(KEY_1, 20D, VALUE_2); - nativeConnection.zadd(KEY_1, 5D, VALUE_3); - - assertThat(clusterConnection.zRevRangeByScore(KEY_1_BYTES, 10D, 20D), hasItems(VALUE_2_BYTES, VALUE_1_BYTES)); - } - - @Test // DATAREDIS-315 - public void zRevRangeByScoreWithScoresShouldReturnValuesAndScoreCorrectly() { - - nativeConnection.zadd(KEY_1, 10D, VALUE_1); - nativeConnection.zadd(KEY_1, 20D, VALUE_2); - nativeConnection.zadd(KEY_1, 5D, VALUE_3); - - assertThat(clusterConnection.zRevRangeByScoreWithScores(KEY_1_BYTES, 10D, 20D), - hasItems((Tuple) new DefaultTuple(VALUE_2_BYTES, 20D), (Tuple) new DefaultTuple(VALUE_1_BYTES, 10D))); - } - - @Test // DATAREDIS-315 - public void zRevRangeByScoreShouldReturnValuesCorrectlyWhenGivenOffsetAndScore() { - - nativeConnection.zadd(KEY_1, 10D, VALUE_1); - nativeConnection.zadd(KEY_1, 20D, VALUE_2); - nativeConnection.zadd(KEY_1, 5D, VALUE_3); - - assertThat(clusterConnection.zRevRangeByScore(KEY_1_BYTES, 10D, 20D, 0L, 1L), hasItems(VALUE_2_BYTES)); - } - - @Test // DATAREDIS-315 - public void zRevRangeByScoreWithScoresShouldReturnValuesCorrectlyWhenGivenOffsetAndScore() { - - nativeConnection.zadd(KEY_1, 10D, VALUE_1); - nativeConnection.zadd(KEY_1, 20D, VALUE_2); - nativeConnection.zadd(KEY_1, 5D, VALUE_3); - - assertThat(clusterConnection.zRevRangeByScoreWithScores(KEY_1_BYTES, 10D, 20D, 0L, 1L), - hasItems((Tuple) new DefaultTuple(VALUE_2_BYTES, 20D))); - } - - @Test // DATAREDIS-315 - public void zCountShouldCountValuesInRange() { - - nativeConnection.zadd(KEY_1, 10D, VALUE_1); - nativeConnection.zadd(KEY_1, 20D, VALUE_2); - nativeConnection.zadd(KEY_1, 5D, VALUE_3); - - assertThat(clusterConnection.zCount(KEY_1_BYTES, 10, 20), is(2L)); - } - - @Test // DATAREDIS-315 - public void zCardShouldReturnTotalNumberOfValues() { - - nativeConnection.zadd(KEY_1, 10D, VALUE_1); - nativeConnection.zadd(KEY_1, 20D, VALUE_2); - nativeConnection.zadd(KEY_1, 5D, VALUE_3); - - assertThat(clusterConnection.zCard(KEY_1_BYTES), is(3L)); - } - - @Test // DATAREDIS-315 - public void zScoreShouldRetrieveScoreForValue() { - - nativeConnection.zadd(KEY_1, 10D, VALUE_1); - nativeConnection.zadd(KEY_1, 20D, VALUE_2); - - assertThat(clusterConnection.zScore(KEY_1_BYTES, VALUE_2_BYTES), is(20D)); - } - - @Test // DATAREDIS-315 - public void zRemRangeShouldRemoveValues() { - - nativeConnection.zadd(KEY_1, 10D, VALUE_1); - nativeConnection.zadd(KEY_1, 20D, VALUE_2); - nativeConnection.zadd(KEY_1, 30D, VALUE_3); - - clusterConnection.zRemRange(KEY_1_BYTES, 1, 2); - - assertThat(nativeConnection.zcard(KEY_1), is(1L)); - assertThat(nativeConnection.zrange(KEY_1, 0, -1), hasItem(VALUE_1)); - } - - @Test // DATAREDIS-315 - public void zRemRangeByScoreShouldRemoveValues() { - - nativeConnection.zadd(KEY_1, 10D, VALUE_1); - nativeConnection.zadd(KEY_1, 20D, VALUE_2); - nativeConnection.zadd(KEY_1, 30D, VALUE_3); - - clusterConnection.zRemRangeByScore(KEY_1_BYTES, 15D, 25D); - - assertThat(nativeConnection.zcard(KEY_1), is(2L)); - assertThat(nativeConnection.zrange(KEY_1, 0, -1), hasItems(VALUE_1, VALUE_3)); - } - - @Test // DATAREDIS-315 - public void zUnionStoreShouldWorkForSameSlotKeys() { - - nativeConnection.zadd(SAME_SLOT_KEY_1, 10D, VALUE_1); - nativeConnection.zadd(SAME_SLOT_KEY_1, 30D, VALUE_3); - nativeConnection.zadd(SAME_SLOT_KEY_2, 20D, VALUE_2); - - clusterConnection.zUnionStore(SAME_SLOT_KEY_3_BYTES, SAME_SLOT_KEY_1_BYTES, SAME_SLOT_KEY_2_BYTES); - - assertThat(nativeConnection.zrange(SAME_SLOT_KEY_3, 0, -1), hasItems(VALUE_1, VALUE_2, VALUE_3)); - } - - @Test(expected = DataAccessException.class) // DATAREDIS-315 - public void zUnionStoreShouldThrowExceptionWhenKeysDoNotMapToSameSlots() { - clusterConnection.zUnionStore(KEY_3_BYTES, KEY_1_BYTES, KEY_2_BYTES); - } - - @Test // DATAREDIS-315 - public void zInterStoreShouldWorkForSameSlotKeys() { - - nativeConnection.zadd(SAME_SLOT_KEY_1, 10D, VALUE_1); - nativeConnection.zadd(SAME_SLOT_KEY_1, 20D, VALUE_2); - - nativeConnection.zadd(SAME_SLOT_KEY_2, 20D, VALUE_2); - nativeConnection.zadd(SAME_SLOT_KEY_2, 30D, VALUE_3); - - clusterConnection.zInterStore(SAME_SLOT_KEY_3_BYTES, SAME_SLOT_KEY_1_BYTES, SAME_SLOT_KEY_2_BYTES); - - assertThat(nativeConnection.zrange(SAME_SLOT_KEY_3, 0, -1), hasItems(VALUE_2)); - } - - @Test(expected = DataAccessException.class) // DATAREDIS-315 - public void zInterStoreShouldThrowExceptionWhenKeysDoNotMapToSameSlots() { - clusterConnection.zInterStore(KEY_3_BYTES, KEY_1_BYTES, KEY_2_BYTES); - } - - @Test - public void zScanShouldReadEntireValueRange() { - - int nrOfValues = 321; - for (int i = 0; i < nrOfValues; i++) { - nativeConnection.zadd(KEY_1, i, "value-" + i); - } - - Cursor tuples = clusterConnection.zScan(KEY_1_BYTES, ScanOptions.NONE); - - int count = 0; - while (tuples.hasNext()) { - - tuples.next(); - count++; - } - - assertThat(count, equalTo(nrOfValues)); - } - - @Test // DATAREDIS-315 - public void hSetShouldSetValueCorrectly() { - - clusterConnection.hSet(KEY_1_BYTES, KEY_2_BYTES, VALUE_1_BYTES); - - assertThat(nativeConnection.hget(KEY_1, KEY_2), is(VALUE_1)); - } - - @Test // DATAREDIS-315 - public void hSetNXShouldSetValueCorrectly() { - - clusterConnection.hSetNX(KEY_1_BYTES, KEY_2_BYTES, VALUE_1_BYTES); - - assertThat(nativeConnection.hget(KEY_1, KEY_2), is(VALUE_1)); - } - - @Test // DATAREDIS-315 - public void hSetNXShouldNotSetValueWhenAlreadyExists() { - - nativeConnection.hset(KEY_1, KEY_2, VALUE_1); - - clusterConnection.hSetNX(KEY_1_BYTES, KEY_2_BYTES, VALUE_2_BYTES); - - assertThat(nativeConnection.hget(KEY_1, KEY_2), is(VALUE_1)); - } - - @Test // DATAREDIS-315 - public void hGetShouldRetrieveValueCorrectly() { - - nativeConnection.hset(KEY_1, KEY_2, VALUE_1); - - assertThat(clusterConnection.hGet(KEY_1_BYTES, KEY_2_BYTES), is(VALUE_1_BYTES)); - } - - @Test // DATAREDIS-315 - public void hMGetShouldRetrieveValueCorrectly() { - - nativeConnection.hset(KEY_1, KEY_2, VALUE_1); - nativeConnection.hset(KEY_1, KEY_3, VALUE_2); - - assertThat(clusterConnection.hMGet(KEY_1_BYTES, KEY_2_BYTES, KEY_3_BYTES), hasItems(VALUE_1_BYTES, VALUE_2_BYTES)); - } - - @Test // DATAREDIS-315 - public void hMSetShouldAddValuesCorrectly() { - - Map hashes = new HashMap<>(); - hashes.put(KEY_2_BYTES, VALUE_1_BYTES); - hashes.put(KEY_3_BYTES, VALUE_2_BYTES); - - clusterConnection.hMSet(KEY_1_BYTES, hashes); - - assertThat(clusterConnection.hMGet(KEY_1_BYTES, KEY_2_BYTES, KEY_3_BYTES), hasItems(VALUE_1_BYTES, VALUE_2_BYTES)); - } - - @Test // DATAREDIS-315 - public void hIncrByShouldIncreaseFieldCorretly() { - - nativeConnection.hset(KEY_1, KEY_2, "1"); - nativeConnection.hset(KEY_1, KEY_3, "2"); - - clusterConnection.hIncrBy(KEY_1_BYTES, KEY_3_BYTES, 3); - - assertThat(nativeConnection.hget(KEY_1, KEY_3), is("5")); - } - - @Test // DATAREDIS-315 - public void hIncrByFloatShouldIncreaseFieldCorretly() { - - nativeConnection.hset(KEY_1, KEY_2, "1"); - nativeConnection.hset(KEY_1, KEY_3, "2"); - - clusterConnection.hIncrBy(KEY_1_BYTES, KEY_3_BYTES, 3.5D); - - assertThat(nativeConnection.hget(KEY_1, KEY_3), is("5.5")); - } - - @Test // DATAREDIS-315 - public void hExistsShouldReturnPresenceOfFieldCorrectly() { - - nativeConnection.hset(KEY_1, KEY_2, VALUE_1); - - assertThat(clusterConnection.hExists(KEY_1_BYTES, KEY_2_BYTES), is(true)); - assertThat(clusterConnection.hExists(KEY_1_BYTES, KEY_3_BYTES), is(false)); - assertThat(clusterConnection.hExists(LettuceConverters.toBytes("foo"), KEY_2_BYTES), is(false)); - } - - @Test // DATAREDIS-315 - public void hDelShouldRemoveFieldsCorrectly() { - - nativeConnection.hset(KEY_1, KEY_2, VALUE_1); - nativeConnection.hset(KEY_1, KEY_3, VALUE_2); - - clusterConnection.hDel(KEY_1_BYTES, KEY_2_BYTES); - - assertThat(nativeConnection.hexists(KEY_1, KEY_2), is(false)); - assertThat(nativeConnection.hexists(KEY_1, KEY_3), is(true)); - } - - @Test // DATAREDIS-315 - public void hLenShouldRetrieveSizeCorrectly() { - - nativeConnection.hset(KEY_1, KEY_2, VALUE_1); - nativeConnection.hset(KEY_1, KEY_3, VALUE_2); - - assertThat(clusterConnection.hLen(KEY_1_BYTES), is(2L)); - } - - @Test // DATAREDIS-315 - public void hKeysShouldRetrieveKeysCorrectly() { - - nativeConnection.hset(KEY_1, KEY_2, VALUE_1); - nativeConnection.hset(KEY_1, KEY_3, VALUE_2); - - assertThat(clusterConnection.hKeys(KEY_1_BYTES), hasItems(KEY_2_BYTES, KEY_3_BYTES)); - } - - @Test // DATAREDIS-315 - public void hValsShouldRetrieveValuesCorrectly() { - - nativeConnection.hset(KEY_1, KEY_2, VALUE_1); - nativeConnection.hset(KEY_1, KEY_3, VALUE_2); - - assertThat(clusterConnection.hVals(KEY_1_BYTES), hasItems(VALUE_1_BYTES, VALUE_2_BYTES)); - } - - @Test // DATAREDIS-315 - public void hGetAllShouldRetrieveEntriesCorrectly() { - - Map hashes = new HashMap<>(); - hashes.put(KEY_2, VALUE_1); - hashes.put(KEY_3, VALUE_2); - - nativeConnection.hmset(KEY_1, hashes); - - Map hGetAll = clusterConnection.hGetAll(KEY_1_BYTES); - - assertThat(hGetAll.keySet(), hasItems(KEY_2_BYTES, KEY_3_BYTES)); - } - - @Test - public void hScanShouldReadEntireValueRange() { - - int nrOfValues = 321; - for (int i = 0; i < nrOfValues; i++) { - nativeConnection.hset(KEY_1, "key" + i, "value-" + i); - } - - Cursor> cursor = clusterConnection.hScan(KEY_1_BYTES, - scanOptions().match("key*").build()); - - int i = 0; - while (cursor.hasNext()) { - - cursor.next(); - i++; - } - - assertThat(i, is(nrOfValues)); - } - - @Test(expected = DataAccessException.class) // DATAREDIS-315 - public void multiShouldThrowException() { - clusterConnection.multi(); - } - - @Test(expected = DataAccessException.class) // DATAREDIS-315 - public void execShouldThrowException() { - clusterConnection.exec(); - } - - @Test(expected = DataAccessException.class) // DATAREDIS-315 - public void discardShouldThrowException() { - clusterConnection.discard(); - } - - @Test(expected = DataAccessException.class) // DATAREDIS-315 - public void watchShouldThrowException() { - clusterConnection.watch(); - } - - @Test(expected = DataAccessException.class) // DATAREDIS-315 - public void unwatchShouldThrowException() { - clusterConnection.unwatch(); - } - - @Test // DATAREDIS-315 - public void selectShouldAllowSelectionOfDBIndexZero() { - clusterConnection.select(0); - } - - @Test(expected = DataAccessException.class) // DATAREDIS-315 - public void selectShouldThrowExceptionWhenSelectingNonZeroDbIndex() { - clusterConnection.select(1); - } - - @Test // DATAREDIS-315 - public void echoShouldReturnInputCorrectly() { - assertThat(clusterConnection.echo(VALUE_1_BYTES), is(VALUE_1_BYTES)); - } - - @Test // DATAREDIS-315 - public void pingShouldRetrunPongForExistingNode() { - assertThat(clusterConnection.ping(new RedisClusterNode("127.0.0.1", 7379, SlotRange.empty())), is("PONG")); - } - - @Test // DATAREDIS-315 - public void pingShouldRetrunPong() { - assertThat(clusterConnection.ping(), is("PONG")); - } - - @Test(expected = IllegalArgumentException.class) // DATAREDIS-315 - public void pingShouldThrowExceptionWhenNodeNotKnownToCluster() { - clusterConnection.ping(new RedisClusterNode("127.0.0.1", 1234, SlotRange.empty())); - } - - @Test // DATAREDIS-315 - public void flushDbShouldFlushAllClusterNodes() { - - nativeConnection.set(KEY_1, VALUE_1); - nativeConnection.set(KEY_2, VALUE_2); - - clusterConnection.flushDb(); - - assertThat(nativeConnection.get(KEY_1), nullValue()); - assertThat(nativeConnection.get(KEY_2), nullValue()); - } - - @Test // DATAREDIS-315 - public void flushDbOnSingleNodeShouldFlushOnlyGivenNodesDb() { - - nativeConnection.set(KEY_1, VALUE_1); - nativeConnection.set(KEY_2, VALUE_2); - - clusterConnection.flushDb(new RedisClusterNode("127.0.0.1", 7379, SlotRange.empty())); - - assertThat(nativeConnection.get(KEY_1), notNullValue()); - assertThat(nativeConnection.get(KEY_2), nullValue()); - } - - @Test // DATAREDIS-315 - public void zRangeByLexShouldReturnResultCorrectly() { - - nativeConnection.zadd(KEY_1, 0, "a"); - nativeConnection.zadd(KEY_1, 0, "b"); - nativeConnection.zadd(KEY_1, 0, "c"); - nativeConnection.zadd(KEY_1, 0, "d"); - nativeConnection.zadd(KEY_1, 0, "e"); - nativeConnection.zadd(KEY_1, 0, "f"); - nativeConnection.zadd(KEY_1, 0, "g"); - - Set values = clusterConnection.zRangeByLex(KEY_1_BYTES, Range.range().lte("c")); - - assertThat(values, - hasItems(LettuceConverters.toBytes("a"), LettuceConverters.toBytes("b"), LettuceConverters.toBytes("c"))); - assertThat(values, not(hasItems(LettuceConverters.toBytes("d"), LettuceConverters.toBytes("e"), - LettuceConverters.toBytes("f"), LettuceConverters.toBytes("g")))); - - values = clusterConnection.zRangeByLex(KEY_1_BYTES, Range.range().lt("c")); - assertThat(values, hasItems(LettuceConverters.toBytes("a"), LettuceConverters.toBytes("b"))); - assertThat(values, not(hasItem(LettuceConverters.toBytes("c")))); - - values = clusterConnection.zRangeByLex(KEY_1_BYTES, Range.range().gte("aaa").lt("g")); - assertThat(values, hasItems(LettuceConverters.toBytes("b"), LettuceConverters.toBytes("c"), - LettuceConverters.toBytes("d"), LettuceConverters.toBytes("e"), LettuceConverters.toBytes("f"))); - assertThat(values, not(hasItems(LettuceConverters.toBytes("a"), LettuceConverters.toBytes("g")))); - - values = clusterConnection.zRangeByLex(KEY_1_BYTES, Range.range().gte("e")); - assertThat(values, - hasItems(LettuceConverters.toBytes("e"), LettuceConverters.toBytes("f"), LettuceConverters.toBytes("g"))); - assertThat(values, not(hasItems(LettuceConverters.toBytes("a"), LettuceConverters.toBytes("b"), - LettuceConverters.toBytes("c"), LettuceConverters.toBytes("d")))); - } - - @Test // DATAREDIS-315, DATAREDIS-685 - public void infoShouldCollectionInfoFromAllClusterNodes() { - - Properties singleNodeInfo = clusterConnection.serverCommands().info(new RedisClusterNode("127.0.0.1", 7380)); - assertThat(Double.valueOf(clusterConnection.serverCommands().info().size()), - closeTo(singleNodeInfo.size() * 3, 12d)); - } - @Test // DATAREDIS-315 public void clientListShouldGetInfosForAllClients() { assertThat(clusterConnection.getClientList().isEmpty(), is(false)); } - @Test // DATAREDIS-315 - public void getClusterNodeForKeyShouldReturnNodeCorrectly() { - assertThat((RedisNode) clusterConnection.clusterGetNodeForKey(KEY_1_BYTES), is(new RedisNode("127.0.0.1", 7380))); - } - - @Test // DATAREDIS-315 - public void countKeysShouldReturnNumberOfKeysInSlot() { - - nativeConnection.set(SAME_SLOT_KEY_1, VALUE_1); - nativeConnection.set(SAME_SLOT_KEY_2, VALUE_2); - - assertThat(clusterConnection.clusterCountKeysInSlot(ClusterSlotHashUtil.calculateSlot(SAME_SLOT_KEY_1)), is(2L)); - } - - @Test // DATAREDIS-315 - public void pfAddShouldAddValuesCorrectly() { - - clusterConnection.pfAdd(KEY_1_BYTES, VALUE_1_BYTES, VALUE_2_BYTES, VALUE_3_BYTES); - - assertThat(((RedisHLLCommands) nativeConnection).pfcount(KEY_1), is(3L)); - } - - @Test // DATAREDIS-315 - public void pfCountShouldAllowCountingOnSingleKey() { - - ((RedisHLLCommands) nativeConnection).pfadd(KEY_1, VALUE_1, VALUE_2, VALUE_3); - - assertThat(clusterConnection.pfCount(KEY_1_BYTES), is(3L)); - } - - @Test // DATAREDIS-315 - public void pfCountShouldAllowCountingOnSameSlotKeys() { - - ((RedisHLLCommands) nativeConnection).pfadd(SAME_SLOT_KEY_1, VALUE_1, VALUE_2); - ((RedisHLLCommands) nativeConnection).pfadd(SAME_SLOT_KEY_2, VALUE_2, VALUE_3); - - assertThat(clusterConnection.pfCount(SAME_SLOT_KEY_1_BYTES, SAME_SLOT_KEY_2_BYTES), is(3L)); - } - - @Test(expected = DataAccessException.class) // DATAREDIS-315 - public void pfCountShouldThrowErrorCountingOnDifferentSlotKeys() { - - ((RedisHLLCommands) nativeConnection).pfadd(KEY_1, VALUE_1, VALUE_2); - ((RedisHLLCommands) nativeConnection).pfadd(KEY_2, VALUE_2, VALUE_3); - - clusterConnection.pfCount(KEY_1_BYTES, KEY_2_BYTES); - } - - @Test // DATAREDIS-315 - public void pfMergeShouldWorkWhenAllKeysMapToSameSlot() { - - ((RedisHLLCommands) nativeConnection).pfadd(SAME_SLOT_KEY_1, VALUE_1, VALUE_2); - ((RedisHLLCommands) nativeConnection).pfadd(SAME_SLOT_KEY_2, VALUE_2, VALUE_3); - - ((RedisHLLCommands) nativeConnection).pfmerge(SAME_SLOT_KEY_3, SAME_SLOT_KEY_1, SAME_SLOT_KEY_2); - - assertThat(((RedisHLLCommands) nativeConnection).pfcount(SAME_SLOT_KEY_3), is(3L)); - } - - @Test(expected = DataAccessException.class) // DATAREDIS-315 - public void pfMergeShouldThrowErrorOnDifferentSlotKeys() { - clusterConnection.pfMerge(KEY_3_BYTES, KEY_1_BYTES, KEY_2_BYTES); - } - - @Test // DATAREDIS-315 - public void infoShouldCollectInfoForSpecificNode() { - - Properties properties = clusterConnection.info(new RedisClusterNode(CLUSTER_HOST, MASTER_NODE_2_PORT)); - - assertThat(properties.getProperty("tcp_port"), is(Integer.toString(MASTER_NODE_2_PORT))); - } - - @Test // DATAREDIS-315 - public void infoShouldCollectInfoForSpecificNodeAndSection() { - - Properties properties = clusterConnection.info(new RedisClusterNode(CLUSTER_HOST, MASTER_NODE_2_PORT), "server"); - - assertThat(properties.getProperty("tcp_port"), is(Integer.toString(MASTER_NODE_2_PORT))); - assertThat(properties.getProperty("used_memory"), nullValue()); - } - - @Test // DATAREDIS-315, DATAREDIS-661 - public void getConfigShouldLoadCumulatedConfiguration() { - - Properties result = clusterConnection.getConfig("*max-*-entries*"); - - // config get *max-*-entries on redis 3.0.7 returns 8 entries per node while on 3.2.0-rc3 returns 6. - // @link https://github.com/spring-projects/spring-data-redis/pull/187 - assertThat(result.size() % 3, is(0)); - - for (Object key : result.keySet()) { - - assertThat(key.toString(), startsWith(CLUSTER_HOST)); - assertThat(result.getProperty(key.toString()), not(startsWith(CLUSTER_HOST))); - } - } - - @Test // DATAREDIS-315, DATAREDIS-661 - public void getConfigShouldLoadConfigurationOfSpecificNode() { - - Properties result = clusterConnection.getConfig(new RedisClusterNode(CLUSTER_HOST, SLAVEOF_NODE_1_PORT), "*"); - - assertThat(result.getProperty("slaveof"), endsWith("7379")); - } - - @Test // DATAREDIS-315 - public void clusterGetSlavesShouldReturnSlaveCorrectly() { - - Set slaves = clusterConnection - .clusterGetSlaves(new RedisClusterNode(CLUSTER_HOST, MASTER_NODE_1_PORT)); - - assertThat(slaves.size(), is(1)); - assertThat(slaves, hasItem(new RedisClusterNode(CLUSTER_HOST, SLAVEOF_NODE_1_PORT))); - } - @Test // DATAREDIS-315 public void clusterGetMasterSlaveMapShouldListMastersAndSlavesCorrectly() { @@ -1871,87 +239,189 @@ public class LettuceClusterConnectionTests implements ClusterConnectionTests { assertThat(masterSlaveMap.get(new RedisClusterNode(CLUSTER_HOST, MASTER_NODE_3_PORT)).isEmpty(), is(true)); } - @Test // DATAREDIS-316 - public void setWithExpirationInSecondsShouldWorkCorrectly() { + @Test // DATAREDIS-315 + public void clusterGetSlavesShouldReturnSlaveCorrectly() { - clusterConnection.set(KEY_1_BYTES, VALUE_1_BYTES, Expiration.seconds(1), SetOption.upsert()); + Set slaves = clusterConnection + .clusterGetSlaves(new RedisClusterNode(CLUSTER_HOST, MASTER_NODE_1_PORT)); - assertThat(nativeConnection.exists(KEY_1), is(1L)); - assertThat(nativeConnection.ttl(KEY_1), is(1L)); + assertThat(slaves.size(), is(1)); + assertThat(slaves, hasItem(new RedisClusterNode(CLUSTER_HOST, SLAVEOF_NODE_1_PORT))); } - @Test // DATAREDIS-316 - public void setWithExpirationInMillisecondsShouldWorkCorrectly() { + @Test // DATAREDIS-315 + public void countKeysShouldReturnNumberOfKeysInSlot() { - clusterConnection.set(KEY_1_BYTES, VALUE_1_BYTES, Expiration.milliseconds(500), SetOption.upsert()); + nativeConnection.set(SAME_SLOT_KEY_1, VALUE_1); + nativeConnection.set(SAME_SLOT_KEY_2, VALUE_2); - assertThat(nativeConnection.exists(KEY_1), is(1L)); - assertThat(nativeConnection.pttl(KEY_1).doubleValue(), is(closeTo(500d, 499d))); + assertThat(clusterConnection.clusterCountKeysInSlot(ClusterSlotHashUtil.calculateSlot(SAME_SLOT_KEY_1)), is(2L)); } - @Test // DATAREDIS-316 - public void setWithOptionIfPresentShouldWorkCorrectly() { + @Test // DATAREDIS-315 + public void dbSizeForSpecificNodeShouldGetNodeDbSize() { nativeConnection.set(KEY_1, VALUE_1); - clusterConnection.set(KEY_1_BYTES, VALUE_2_BYTES, Expiration.persistent(), SetOption.ifPresent()); + nativeConnection.set(KEY_2, VALUE_2); + + assertThat(clusterConnection.dbSize(new RedisClusterNode("127.0.0.1", 7379, SlotRange.empty())), is(1L)); + assertThat(clusterConnection.dbSize(new RedisClusterNode("127.0.0.1", 7380, SlotRange.empty())), is(1L)); + assertThat(clusterConnection.dbSize(new RedisClusterNode("127.0.0.1", 7381, SlotRange.empty())), is(0L)); } - @Test // DATAREDIS-316 - public void setWithOptionIfAbsentShouldWorkCorrectly() { + @Test // DATAREDIS-315 + public void dbSizeShouldReturnCummulatedDbSize() { - clusterConnection.set(KEY_1_BYTES, VALUE_1_BYTES, Expiration.persistent(), SetOption.ifAbsent()); + nativeConnection.set(KEY_1, VALUE_1); + nativeConnection.set(KEY_2, VALUE_2); - assertThat(nativeConnection.exists(KEY_1), is(1L)); - assertThat(nativeConnection.ttl(KEY_1), is(-1L)); + assertThat(clusterConnection.dbSize(), is(2L)); } - @Test // DATAREDIS-316 - public void setWithExpirationAndIfAbsentShouldWorkCorrectly() { + @Test // DATAREDIS-315 + public void decrByShouldDecreaseValueCorrectly() { - clusterConnection.set(KEY_1_BYTES, VALUE_1_BYTES, Expiration.seconds(1), SetOption.ifAbsent()); + nativeConnection.set(KEY_1, "5"); - assertThat(nativeConnection.exists(KEY_1), is(1L)); - assertThat(nativeConnection.ttl(KEY_1), is(1L)); + assertThat(clusterConnection.decrBy(KEY_1_BYTES, 4), is(1L)); } - @Test // DATAREDIS-316 - public void setWithExpirationAndIfAbsentShouldNotBeAppliedWhenKeyExists() { + @Test // DATAREDIS-315 + public void decrShouldDecreaseValueCorrectly() { + + nativeConnection.set(KEY_1, "5"); + + assertThat(clusterConnection.decr(KEY_1_BYTES), is(4L)); + } + + @Test // DATAREDIS-315 + public void delShouldRemoveMultipleKeysCorrectly() { + + nativeConnection.set(KEY_1, VALUE_1); + nativeConnection.set(KEY_2, VALUE_2); + + clusterConnection.del(KEY_1_BYTES); + clusterConnection.del(KEY_2_BYTES); + + assertThat(nativeConnection.get(KEY_1), nullValue()); + assertThat(nativeConnection.get(KEY_2), nullValue()); + } + + @Test // DATAREDIS-315 + public void delShouldRemoveMultipleKeysOnSameSlotCorrectly() { + + nativeConnection.set(SAME_SLOT_KEY_1, VALUE_1); + nativeConnection.set(SAME_SLOT_KEY_2, VALUE_2); + + clusterConnection.del(SAME_SLOT_KEY_1_BYTES, SAME_SLOT_KEY_2_BYTES); + + assertThat(nativeConnection.get(SAME_SLOT_KEY_1), nullValue()); + assertThat(nativeConnection.get(SAME_SLOT_KEY_2), nullValue()); + } + + @Test // DATAREDIS-315 + public void delShouldRemoveSingleKeyCorrectly() { nativeConnection.set(KEY_1, VALUE_1); - clusterConnection.set(KEY_1_BYTES, VALUE_2_BYTES, Expiration.seconds(1), SetOption.ifAbsent()); - - assertThat(nativeConnection.exists(KEY_1), is(1L)); - assertThat(nativeConnection.ttl(KEY_1), is(-1L)); - assertThat(nativeConnection.get(KEY_1), is(equalTo(VALUE_1))); + clusterConnection.del(KEY_1_BYTES); + assertThat(nativeConnection.get(KEY_1), nullValue()); } - @Test // DATAREDIS-316 - public void setWithExpirationAndIfPresentShouldWorkCorrectly() { + @Test(expected = DataAccessException.class) // DATAREDIS-315 + public void discardShouldThrowException() { + clusterConnection.discard(); + } + + @Test // DATAREDIS-315 + public void dumpAndRestoreShouldWorkCorrectly() { nativeConnection.set(KEY_1, VALUE_1); - clusterConnection.set(KEY_1_BYTES, VALUE_2_BYTES, Expiration.seconds(1), SetOption.ifPresent()); - - assertThat(nativeConnection.exists(KEY_1), is(1L)); - assertThat(nativeConnection.ttl(KEY_1), is(1L)); - assertThat(nativeConnection.get(KEY_1), is(equalTo(VALUE_2))); + byte[] dumpedValue = clusterConnection.dump(KEY_1_BYTES); + clusterConnection.restore(KEY_2_BYTES, 0, dumpedValue); + assertThat(nativeConnection.get(KEY_2), is(VALUE_1)); } - @Test // DATAREDIS-316 - public void setWithExpirationAndIfPresentShouldNotBeAppliedWhenKeyDoesNotExists() { - - clusterConnection.set(KEY_1_BYTES, VALUE_1_BYTES, Expiration.seconds(1), SetOption.ifPresent()); - - assertThat(nativeConnection.exists(KEY_1), is(0L)); + @Test // DATAREDIS-315 + public void echoShouldReturnInputCorrectly() { + assertThat(clusterConnection.echo(VALUE_1_BYTES), is(VALUE_1_BYTES)); } - @Test // DATAREDIS-438 - @IfProfileValue(name = "redisVersion", value = "3.2+") - public void geoAddSingleGeoLocation() { - assertThat(clusterConnection.geoAdd(KEY_1_BYTES, PALERMO_BYTES), is(1L)); + @Test(expected = DataAccessException.class) // DATAREDIS-315 + public void execShouldThrowException() { + clusterConnection.exec(); + } + + @Test // DATAREDIS-529 + public void existsShouldCountSameKeyMultipleTimes() { + + nativeConnection.set(KEY_1, "true"); + + assertThat(clusterConnection.keyCommands().exists(KEY_1_BYTES, KEY_1_BYTES), is(2L)); + } + + @Test // DATAREDIS-529 + public void existsWithMultipleKeysShouldConsiderAbsentKeys() { + + assertThat(clusterConnection.keyCommands().exists("no-exist-1".getBytes(), "no-exist-2".getBytes()), is(0L)); + } + + @Test // DATAREDIS-529 + public void existsWithMultipleKeysShouldReturnResultCorrectly() { + + nativeConnection.set(KEY_1, "true"); + nativeConnection.set(KEY_2, "true"); + nativeConnection.set(KEY_3, "true"); + + assertThat(clusterConnection.keyCommands().exists(KEY_1_BYTES, KEY_2_BYTES, KEY_3_BYTES, "nonexistent".getBytes()), + is(3L)); + } + + @Test // DATAREDIS-315 + public void expireAtShouldBeSetCorrectly() { + + nativeConnection.set(KEY_1, VALUE_1); + + clusterConnection.expireAt(KEY_1_BYTES, System.currentTimeMillis() / 1000 + 5000); + + assertThat(nativeConnection.ttl(LettuceConverters.toString(KEY_1_BYTES)) > 1, is(true)); + } + + @Test // DATAREDIS-315 + public void expireShouldBeSetCorreclty() { + + nativeConnection.set(KEY_1, VALUE_1); + + clusterConnection.expire(KEY_1_BYTES, 5); + + assertThat(nativeConnection.ttl(LettuceConverters.toString(KEY_1_BYTES)) > 1, is(true)); + } + + @Test // DATAREDIS-315 + public void flushDbOnSingleNodeShouldFlushOnlyGivenNodesDb() { + + nativeConnection.set(KEY_1, VALUE_1); + nativeConnection.set(KEY_2, VALUE_2); + + clusterConnection.flushDb(new RedisClusterNode("127.0.0.1", 7379, SlotRange.empty())); + + assertThat(nativeConnection.get(KEY_1), notNullValue()); + assertThat(nativeConnection.get(KEY_2), nullValue()); + } + + @Test // DATAREDIS-315 + public void flushDbShouldFlushAllClusterNodes() { + + nativeConnection.set(KEY_1, VALUE_1); + nativeConnection.set(KEY_2, VALUE_2); + + clusterConnection.flushDb(); + + assertThat(nativeConnection.get(KEY_1), nullValue()); + assertThat(nativeConnection.get(KEY_2), nullValue()); } @Test // DATAREDIS-438 @@ -1961,6 +431,12 @@ public class LettuceClusterConnectionTests implements ClusterConnectionTests { Arrays.asList(PALERMO_BYTES, ARIGENTO_BYTES, CATANIA_BYTES, PALERMO_BYTES)), is(3L)); } + @Test // DATAREDIS-438 + @IfProfileValue(name = "redisVersion", value = "3.2+") + public void geoAddSingleGeoLocation() { + assertThat(clusterConnection.geoAdd(KEY_1_BYTES, PALERMO_BYTES), is(1L)); + } + @Test // DATAREDIS-438 @IfProfileValue(name = "redisVersion", value = "3.2+") public void geoDist() { @@ -2049,14 +525,60 @@ public class LettuceClusterConnectionTests implements ClusterConnectionTests { @Test // DATAREDIS-438 @IfProfileValue(name = "redisVersion", value = "3.2+") - public void geoRadiusShouldReturnMembersCorrectly() { + public void geoRadiusByMemberShouldApplyLimit() { + + nativeConnection.geoadd(KEY_1, PALERMO.getPoint().getX(), PALERMO.getPoint().getY(), PALERMO.getName()); + nativeConnection.geoadd(KEY_1, ARIGENTO.getPoint().getX(), ARIGENTO.getPoint().getY(), ARIGENTO.getName()); + nativeConnection.geoadd(KEY_1, CATANIA.getPoint().getX(), CATANIA.getPoint().getY(), CATANIA.getName()); + + GeoResults> result = clusterConnection.geoRadiusByMember(KEY_1_BYTES, PALERMO_BYTES.getName(), + new Distance(200, KILOMETERS), newGeoRadiusArgs().limit(2)); + + assertThat(result.getContent(), hasSize(2)); + } + + @Test // DATAREDIS-438 + @IfProfileValue(name = "redisVersion", value = "3.2+") + public void geoRadiusByMemberShouldReturnDistanceCorrectly() { + + nativeConnection.geoadd(KEY_1, PALERMO.getPoint().getX(), PALERMO.getPoint().getY(), PALERMO.getName()); + nativeConnection.geoadd(KEY_1, ARIGENTO.getPoint().getX(), ARIGENTO.getPoint().getY(), ARIGENTO.getName()); + nativeConnection.geoadd(KEY_1, CATANIA.getPoint().getX(), CATANIA.getPoint().getY(), CATANIA.getName()); + + GeoResults> result = clusterConnection.geoRadiusByMember(KEY_1_BYTES, PALERMO_BYTES.getName(), + new Distance(100, KILOMETERS), newGeoRadiusArgs().includeDistance()); + + assertThat(result.getContent(), hasSize(2)); + assertThat(result.getContent().get(0).getDistance().getValue(), is(closeTo(90.978D, 0.005))); + assertThat(result.getContent().get(0).getDistance().getUnit(), is("km")); + } + + @Test // DATAREDIS-438 + @IfProfileValue(name = "redisVersion", value = "3.2+") + public void geoRadiusByMemberShouldReturnMembersCorrectly() { + + nativeConnection.geoadd(KEY_1, PALERMO.getPoint().getX(), PALERMO.getPoint().getY(), PALERMO.getName()); + nativeConnection.geoadd(KEY_1, ARIGENTO.getPoint().getX(), ARIGENTO.getPoint().getY(), ARIGENTO.getName()); + nativeConnection.geoadd(KEY_1, CATANIA.getPoint().getX(), CATANIA.getPoint().getY(), CATANIA.getName()); + + GeoResults> result = clusterConnection.geoRadiusByMember(KEY_1_BYTES, PALERMO_BYTES.getName(), + new Distance(100, KILOMETERS), newGeoRadiusArgs().sortAscending()); + + assertThat(result.getContent().get(0).getContent().getName(), is(PALERMO_BYTES.getName())); + assertThat(result.getContent().get(1).getContent().getName(), is(ARIGENTO_BYTES.getName())); + } + + @Test // DATAREDIS-438 + @IfProfileValue(name = "redisVersion", value = "3.2+") + public void geoRadiusShouldApplyLimit() { nativeConnection.geoadd(KEY_1, PALERMO.getPoint().getX(), PALERMO.getPoint().getY(), PALERMO.getName()); nativeConnection.geoadd(KEY_1, ARIGENTO.getPoint().getX(), ARIGENTO.getPoint().getY(), ARIGENTO.getName()); nativeConnection.geoadd(KEY_1, CATANIA.getPoint().getX(), CATANIA.getPoint().getY(), CATANIA.getName()); GeoResults> result = clusterConnection.geoRadius(KEY_1_BYTES, - new Circle(new Point(15D, 37D), new Distance(150D, KILOMETERS))); + new Circle(new Point(15D, 37D), new Distance(200D, KILOMETERS)), newGeoRadiusArgs().limit(2)); + assertThat(result.getContent(), hasSize(2)); } @@ -2078,60 +600,14 @@ public class LettuceClusterConnectionTests implements ClusterConnectionTests { @Test // DATAREDIS-438 @IfProfileValue(name = "redisVersion", value = "3.2+") - public void geoRadiusShouldApplyLimit() { + public void geoRadiusShouldReturnMembersCorrectly() { nativeConnection.geoadd(KEY_1, PALERMO.getPoint().getX(), PALERMO.getPoint().getY(), PALERMO.getName()); nativeConnection.geoadd(KEY_1, ARIGENTO.getPoint().getX(), ARIGENTO.getPoint().getY(), ARIGENTO.getName()); nativeConnection.geoadd(KEY_1, CATANIA.getPoint().getX(), CATANIA.getPoint().getY(), CATANIA.getName()); GeoResults> result = clusterConnection.geoRadius(KEY_1_BYTES, - new Circle(new Point(15D, 37D), new Distance(200D, KILOMETERS)), newGeoRadiusArgs().limit(2)); - - assertThat(result.getContent(), hasSize(2)); - } - - @Test // DATAREDIS-438 - @IfProfileValue(name = "redisVersion", value = "3.2+") - public void geoRadiusByMemberShouldReturnMembersCorrectly() { - - nativeConnection.geoadd(KEY_1, PALERMO.getPoint().getX(), PALERMO.getPoint().getY(), PALERMO.getName()); - nativeConnection.geoadd(KEY_1, ARIGENTO.getPoint().getX(), ARIGENTO.getPoint().getY(), ARIGENTO.getName()); - nativeConnection.geoadd(KEY_1, CATANIA.getPoint().getX(), CATANIA.getPoint().getY(), CATANIA.getName()); - - GeoResults> result = clusterConnection.geoRadiusByMember(KEY_1_BYTES, PALERMO_BYTES.getName(), - new Distance(100, KILOMETERS), newGeoRadiusArgs().sortAscending()); - - assertThat(result.getContent().get(0).getContent().getName(), is(PALERMO_BYTES.getName())); - assertThat(result.getContent().get(1).getContent().getName(), is(ARIGENTO_BYTES.getName())); - } - - @Test // DATAREDIS-438 - @IfProfileValue(name = "redisVersion", value = "3.2+") - public void geoRadiusByMemberShouldReturnDistanceCorrectly() { - - nativeConnection.geoadd(KEY_1, PALERMO.getPoint().getX(), PALERMO.getPoint().getY(), PALERMO.getName()); - nativeConnection.geoadd(KEY_1, ARIGENTO.getPoint().getX(), ARIGENTO.getPoint().getY(), ARIGENTO.getName()); - nativeConnection.geoadd(KEY_1, CATANIA.getPoint().getX(), CATANIA.getPoint().getY(), CATANIA.getName()); - - GeoResults> result = clusterConnection.geoRadiusByMember(KEY_1_BYTES, PALERMO_BYTES.getName(), - new Distance(100, KILOMETERS), newGeoRadiusArgs().includeDistance()); - - assertThat(result.getContent(), hasSize(2)); - assertThat(result.getContent().get(0).getDistance().getValue(), is(closeTo(90.978D, 0.005))); - assertThat(result.getContent().get(0).getDistance().getUnit(), is("km")); - } - - @Test // DATAREDIS-438 - @IfProfileValue(name = "redisVersion", value = "3.2+") - public void geoRadiusByMemberShouldApplyLimit() { - - nativeConnection.geoadd(KEY_1, PALERMO.getPoint().getX(), PALERMO.getPoint().getY(), PALERMO.getName()); - nativeConnection.geoadd(KEY_1, ARIGENTO.getPoint().getX(), ARIGENTO.getPoint().getY(), ARIGENTO.getName()); - nativeConnection.geoadd(KEY_1, CATANIA.getPoint().getX(), CATANIA.getPoint().getY(), CATANIA.getName()); - - GeoResults> result = clusterConnection.geoRadiusByMember(KEY_1_BYTES, PALERMO_BYTES.getName(), - new Distance(200, KILOMETERS), newGeoRadiusArgs().limit(2)); - + new Circle(new Point(15D, 37D), new Distance(150D, KILOMETERS))); assertThat(result.getContent(), hasSize(2)); } @@ -2146,30 +622,222 @@ public class LettuceClusterConnectionTests implements ClusterConnectionTests { assertThat(clusterConnection.geoRemove(KEY_1_BYTES, ARIGENTO_BYTES.getName()), is(1L)); } - @Test // DATAREDIS-529 - public void testExistsWithMultipleKeys() { + @Test // DATAREDIS-315 + public void getBitShouldWorkCorrectly() { - nativeConnection.set(KEY_1, "true"); - nativeConnection.set(KEY_2, "true"); - nativeConnection.set(KEY_3, "true"); + nativeConnection.setbit(KEY_1, 0, 1); + nativeConnection.setbit(KEY_1, 1, 0); - assertThat(clusterConnection.keyCommands() - .exists(Arrays.asList(KEY_1_BYTES, KEY_2_BYTES, KEY_3_BYTES, "nonexistent".getBytes())), is(3L)); + assertThat(clusterConnection.getBit(KEY_1_BYTES, 0), is(true)); + assertThat(clusterConnection.getBit(KEY_1_BYTES, 1), is(false)); } - @Test // DATAREDIS-529 - public void testExistsWithMultipleKeysNoneExists() { - - assertThat(clusterConnection.keyCommands().exists(Arrays.asList("no-exist-1".getBytes(), "no-exist-2".getBytes())), - is(0L)); + @Test // DATAREDIS-315 + public void getClusterNodeForKeyShouldReturnNodeCorrectly() { + assertThat((RedisNode) clusterConnection.clusterGetNodeForKey(KEY_1_BYTES), is(new RedisNode("127.0.0.1", 7380))); } - @Test // DATAREDIS-529 - public void testExistsSameKeyMultipleTimes() { + @Test // DATAREDIS-315, DATAREDIS-661 + public void getConfigShouldLoadConfigurationOfSpecificNode() { - nativeConnection.set(KEY_1, "true"); + Properties result = clusterConnection.getConfig(new RedisClusterNode(CLUSTER_HOST, SLAVEOF_NODE_1_PORT), "*"); - assertThat(clusterConnection.keyCommands().exists(Arrays.asList(KEY_1_BYTES, KEY_1_BYTES)), is(2L)); + assertThat(result.getProperty("slaveof"), endsWith("7379")); + } + + @Test // DATAREDIS-315, DATAREDIS-661 + public void getConfigShouldLoadCumulatedConfiguration() { + + Properties result = clusterConnection.getConfig("*max-*-entries*"); + + // config get *max-*-entries on redis 3.0.7 returns 8 entries per node while on 3.2.0-rc3 returns 6. + // @link https://github.com/spring-projects/spring-data-redis/pull/187 + assertThat(result.size() % 3, is(0)); + + for (Object key : result.keySet()) { + + assertThat(key.toString(), startsWith(CLUSTER_HOST)); + assertThat(result.getProperty(key.toString()), not(startsWith(CLUSTER_HOST))); + } + } + + @Test // DATAREDIS-315 + public void getRangeShouldReturnValueCorrectly() { + + nativeConnection.set(KEY_1, VALUE_1); + + assertThat(clusterConnection.getRange(KEY_1_BYTES, 0, 2), is(LettuceConverters.toBytes("val"))); + } + + @Test // DATAREDIS-315 + public void getSetShouldWorkCorrectly() { + + nativeConnection.set(KEY_1, VALUE_1); + + byte[] valueBeforeSet = clusterConnection.getSet(KEY_1_BYTES, VALUE_2_BYTES); + + assertThat(valueBeforeSet, is(VALUE_1_BYTES)); + assertThat(nativeConnection.get(KEY_1), is(VALUE_2)); + } + + @Test // DATAREDIS-315 + public void getShouldReturnValueCorrectly() { + + nativeConnection.set(KEY_1, VALUE_1); + + assertThat(clusterConnection.get(KEY_1_BYTES), is(VALUE_1_BYTES)); + } + + @Test // DATAREDIS-315 + public void hDelShouldRemoveFieldsCorrectly() { + + nativeConnection.hset(KEY_1, KEY_2, VALUE_1); + nativeConnection.hset(KEY_1, KEY_3, VALUE_2); + + clusterConnection.hDel(KEY_1_BYTES, KEY_2_BYTES); + + assertThat(nativeConnection.hexists(KEY_1, KEY_2), is(false)); + assertThat(nativeConnection.hexists(KEY_1, KEY_3), is(true)); + } + + @Test // DATAREDIS-315 + public void hExistsShouldReturnPresenceOfFieldCorrectly() { + + nativeConnection.hset(KEY_1, KEY_2, VALUE_1); + + assertThat(clusterConnection.hExists(KEY_1_BYTES, KEY_2_BYTES), is(true)); + assertThat(clusterConnection.hExists(KEY_1_BYTES, KEY_3_BYTES), is(false)); + assertThat(clusterConnection.hExists(LettuceConverters.toBytes("foo"), KEY_2_BYTES), is(false)); + } + + @Test // DATAREDIS-315 + public void hGetAllShouldRetrieveEntriesCorrectly() { + + Map hashes = new HashMap<>(); + hashes.put(KEY_2, VALUE_1); + hashes.put(KEY_3, VALUE_2); + + nativeConnection.hmset(KEY_1, hashes); + + Map hGetAll = clusterConnection.hGetAll(KEY_1_BYTES); + + assertThat(hGetAll.keySet(), hasItems(KEY_2_BYTES, KEY_3_BYTES)); + } + + @Test // DATAREDIS-315 + public void hGetShouldRetrieveValueCorrectly() { + + nativeConnection.hset(KEY_1, KEY_2, VALUE_1); + + assertThat(clusterConnection.hGet(KEY_1_BYTES, KEY_2_BYTES), is(VALUE_1_BYTES)); + } + + @Test // DATAREDIS-315 + public void hIncrByFloatShouldIncreaseFieldCorretly() { + + nativeConnection.hset(KEY_1, KEY_2, "1"); + nativeConnection.hset(KEY_1, KEY_3, "2"); + + clusterConnection.hIncrBy(KEY_1_BYTES, KEY_3_BYTES, 3.5D); + + assertThat(nativeConnection.hget(KEY_1, KEY_3), is("5.5")); + } + + @Test // DATAREDIS-315 + public void hIncrByShouldIncreaseFieldCorretly() { + + nativeConnection.hset(KEY_1, KEY_2, "1"); + nativeConnection.hset(KEY_1, KEY_3, "2"); + + clusterConnection.hIncrBy(KEY_1_BYTES, KEY_3_BYTES, 3); + + assertThat(nativeConnection.hget(KEY_1, KEY_3), is("5")); + } + + @Test // DATAREDIS-315 + public void hKeysShouldRetrieveKeysCorrectly() { + + nativeConnection.hset(KEY_1, KEY_2, VALUE_1); + nativeConnection.hset(KEY_1, KEY_3, VALUE_2); + + assertThat(clusterConnection.hKeys(KEY_1_BYTES), hasItems(KEY_2_BYTES, KEY_3_BYTES)); + } + + @Test // DATAREDIS-315 + public void hLenShouldRetrieveSizeCorrectly() { + + nativeConnection.hset(KEY_1, KEY_2, VALUE_1); + nativeConnection.hset(KEY_1, KEY_3, VALUE_2); + + assertThat(clusterConnection.hLen(KEY_1_BYTES), is(2L)); + } + + @Test // DATAREDIS-315 + public void hMGetShouldRetrieveValueCorrectly() { + + nativeConnection.hset(KEY_1, KEY_2, VALUE_1); + nativeConnection.hset(KEY_1, KEY_3, VALUE_2); + + assertThat(clusterConnection.hMGet(KEY_1_BYTES, KEY_2_BYTES, KEY_3_BYTES), hasItems(VALUE_1_BYTES, VALUE_2_BYTES)); + } + + @Test // DATAREDIS-315 + public void hMSetShouldAddValuesCorrectly() { + + Map hashes = new HashMap<>(); + hashes.put(KEY_2_BYTES, VALUE_1_BYTES); + hashes.put(KEY_3_BYTES, VALUE_2_BYTES); + + clusterConnection.hMSet(KEY_1_BYTES, hashes); + + assertThat(clusterConnection.hMGet(KEY_1_BYTES, KEY_2_BYTES, KEY_3_BYTES), hasItems(VALUE_1_BYTES, VALUE_2_BYTES)); + } + + @Test + public void hScanShouldReadEntireValueRange() { + + int nrOfValues = 321; + for (int i = 0; i < nrOfValues; i++) { + nativeConnection.hset(KEY_1, "key" + i, "value-" + i); + } + + Cursor> cursor = clusterConnection.hScan(KEY_1_BYTES, + scanOptions().match("key*").build()); + + int i = 0; + while (cursor.hasNext()) { + + cursor.next(); + i++; + } + + assertThat(i, is(nrOfValues)); + } + + @Test // DATAREDIS-315 + public void hSetNXShouldNotSetValueWhenAlreadyExists() { + + nativeConnection.hset(KEY_1, KEY_2, VALUE_1); + + clusterConnection.hSetNX(KEY_1_BYTES, KEY_2_BYTES, VALUE_2_BYTES); + + assertThat(nativeConnection.hget(KEY_1, KEY_2), is(VALUE_1)); + } + + @Test // DATAREDIS-315 + public void hSetNXShouldSetValueCorrectly() { + + clusterConnection.hSetNX(KEY_1_BYTES, KEY_2_BYTES, VALUE_1_BYTES); + + assertThat(nativeConnection.hget(KEY_1, KEY_2), is(VALUE_1)); + } + + @Test // DATAREDIS-315 + public void hSetShouldSetValueCorrectly() { + + clusterConnection.hSet(KEY_1_BYTES, KEY_2_BYTES, VALUE_1_BYTES); + + assertThat(nativeConnection.hget(KEY_1, KEY_2), is(VALUE_1)); } @Test // DATAREDIS-698 @@ -2192,4 +860,1326 @@ public class LettuceClusterConnectionTests implements ClusterConnectionTests { public void hStrLenReturnsZeroWhenKeyDoesNotExist() { assertThat(clusterConnection.hashCommands().hStrLen(KEY_1_BYTES, KEY_1_BYTES), is(0L)); } + + @Test // DATAREDIS-315 + public void hValsShouldRetrieveValuesCorrectly() { + + nativeConnection.hset(KEY_1, KEY_2, VALUE_1); + nativeConnection.hset(KEY_1, KEY_3, VALUE_2); + + assertThat(clusterConnection.hVals(KEY_1_BYTES), hasItems(VALUE_1_BYTES, VALUE_2_BYTES)); + } + + @Test // DATAREDIS-315 + public void incrByFloatShouldIncreaseValueCorrectly() { + + nativeConnection.set(KEY_1, "1"); + + assertThat(clusterConnection.incrBy(KEY_1_BYTES, 5.5D), is(6.5D)); + } + + @Test // DATAREDIS-315 + public void incrByShouldIncreaseValueCorrectly() { + + nativeConnection.set(KEY_1, "1"); + + assertThat(clusterConnection.incrBy(KEY_1_BYTES, 5), is(6L)); + } + + @Test // DATAREDIS-315 + public void incrShouldIncreaseValueCorrectly() { + + nativeConnection.set(KEY_1, "1"); + + assertThat(clusterConnection.incr(KEY_1_BYTES), is(2L)); + } + + @Test // DATAREDIS-315 + public void infoShouldCollectInfoForSpecificNode() { + + Properties properties = clusterConnection.info(new RedisClusterNode(CLUSTER_HOST, MASTER_NODE_2_PORT)); + + assertThat(properties.getProperty("tcp_port"), is(Integer.toString(MASTER_NODE_2_PORT))); + } + + @Test // DATAREDIS-315 + public void infoShouldCollectInfoForSpecificNodeAndSection() { + + Properties properties = clusterConnection.info(new RedisClusterNode(CLUSTER_HOST, MASTER_NODE_2_PORT), "server"); + + assertThat(properties.getProperty("tcp_port"), is(Integer.toString(MASTER_NODE_2_PORT))); + assertThat(properties.getProperty("used_memory"), nullValue()); + } + + @Test // DATAREDIS-315, DATAREDIS-685 + public void infoShouldCollectionInfoFromAllClusterNodes() { + + Properties singleNodeInfo = clusterConnection.serverCommands().info(new RedisClusterNode("127.0.0.1", 7380)); + assertThat(Double.valueOf(clusterConnection.serverCommands().info().size()), + closeTo(singleNodeInfo.size() * 3, 12d)); + } + + @Test // DATAREDIS-315 + public void keysShouldReturnAllKeys() { + + nativeConnection.set(KEY_1, VALUE_1); + nativeConnection.set(KEY_2, VALUE_2); + + assertThat(clusterConnection.keys(LettuceConverters.toBytes("*")), hasItems(KEY_1_BYTES, KEY_2_BYTES)); + } + + @Test // DATAREDIS-315 + public void keysShouldReturnAllKeysForSpecificNode() { + + nativeConnection.set(KEY_1, VALUE_1); + nativeConnection.set(KEY_2, VALUE_2); + + Set keysOnNode = clusterConnection.keys(new RedisClusterNode("127.0.0.1", 7379, SlotRange.empty()), + JedisConverters.toBytes("*")); + + assertThat(keysOnNode, hasItems(KEY_2_BYTES)); + assertThat(keysOnNode, not(hasItems(KEY_1_BYTES))); + } + + @Test // DATAREDIS-315 + public void lIndexShouldGetElementAtIndexCorrectly() { + + nativeConnection.rpush(KEY_1, VALUE_1, VALUE_2, "foo", "bar"); + + assertThat(clusterConnection.lIndex(KEY_1_BYTES, 1), is(VALUE_2_BYTES)); + } + + @Test // DATAREDIS-315 + public void lInsertShouldAddElementAtPositionCorrectly() { + + nativeConnection.rpush(KEY_1, VALUE_1, VALUE_2, "foo", "bar"); + + clusterConnection.lInsert(KEY_1_BYTES, Position.AFTER, VALUE_2_BYTES, LettuceConverters.toBytes("booh!")); + + assertThat(nativeConnection.lrange(KEY_1, 0, -1).get(2), is("booh!")); + } + + @Test // DATAREDIS-315 + public void lLenShouldCountValuesCorrectly() { + + nativeConnection.lpush(KEY_1, VALUE_1, VALUE_2); + + assertThat(clusterConnection.lLen(KEY_1_BYTES), is(2L)); + } + + @Test // DATAREDIS-315 + public void lPopShouldReturnElementCorrectly() { + + nativeConnection.rpush(KEY_1, VALUE_1, VALUE_2); + + assertThat(clusterConnection.lPop(KEY_1_BYTES), is(VALUE_1_BYTES)); + } + + @Test // DATAREDIS-315 + public void lPushNXShoultNotAddValuesWhenKeyDoesNotExist() { + + clusterConnection.lPushX(KEY_1_BYTES, VALUE_1_BYTES); + + assertThat(nativeConnection.exists(KEY_1), is(0L)); + } + + @Test // DATAREDIS-315 + public void lPushShoultAddValuesCorrectly() { + + clusterConnection.lPush(KEY_1_BYTES, VALUE_1_BYTES, VALUE_2_BYTES); + + assertThat(nativeConnection.lrange(KEY_1, 0, -1), hasItems(VALUE_1, VALUE_2)); + } + + @Test // DATAREDIS-315 + public void lRangeShouldGetValuesCorrectly() { + + nativeConnection.lpush(KEY_1, VALUE_1, VALUE_2); + + assertThat(clusterConnection.lRange(KEY_1_BYTES, 0L, -1L), hasItems(VALUE_1_BYTES, VALUE_2_BYTES)); + } + + @Test // DATAREDIS-315 + public void lRemShouldRemoveElementAtPositionCorrectly() { + + nativeConnection.rpush(KEY_1, VALUE_1, VALUE_2, "foo", "bar"); + + clusterConnection.lRem(KEY_1_BYTES, 1L, VALUE_1_BYTES); + + assertThat(nativeConnection.llen(KEY_1), is(3L)); + } + + @Test // DATAREDIS-315 + public void lSetShouldSetElementAtPositionCorrectly() { + + nativeConnection.rpush(KEY_1, VALUE_1, VALUE_2, "foo", "bar"); + + clusterConnection.lSet(KEY_1_BYTES, 1L, VALUE_1_BYTES); + + assertThat(nativeConnection.lrange(KEY_1, 0, -1).get(1), is(VALUE_1)); + } + + @Test // DATAREDIS-315 + public void lTrimShouldTrimListCorrectly() { + + nativeConnection.lpush(KEY_1, VALUE_1, VALUE_2, "foo", "bar"); + + clusterConnection.lTrim(KEY_1_BYTES, 2, 3); + + assertThat(nativeConnection.lrange(KEY_1, 0, -1), hasItems(VALUE_1, VALUE_2)); + } + + @Test // DATAREDIS-315 + public void mGetShouldReturnCorrectlyWhenKeysDoNotMapToSameSlot() { + + nativeConnection.set(KEY_1, VALUE_1); + nativeConnection.set(KEY_2, VALUE_2); + + assertThat(clusterConnection.mGet(KEY_1_BYTES, KEY_2_BYTES), contains(VALUE_1_BYTES, VALUE_2_BYTES)); + } + + @Test // DATAREDIS-315 + public void mGetShouldReturnCorrectlyWhenKeysMapToSameSlot() { + + nativeConnection.set(SAME_SLOT_KEY_1, VALUE_1); + nativeConnection.set(SAME_SLOT_KEY_2, VALUE_2); + + assertThat(clusterConnection.mGet(SAME_SLOT_KEY_1_BYTES, SAME_SLOT_KEY_2_BYTES), + contains(VALUE_1_BYTES, VALUE_2_BYTES)); + } + + @Test // DATAREDIS-315 + public void mSetNXShouldReturnFalseIfNotAllKeysSet() { + + nativeConnection.set(KEY_2, VALUE_3); + Map map = new LinkedHashMap<>(); + map.put(KEY_1_BYTES, VALUE_1_BYTES); + map.put(KEY_2_BYTES, VALUE_2_BYTES); + + assertThat(clusterConnection.mSetNX(map), is(false)); + + assertThat(nativeConnection.get(KEY_1), is(VALUE_1)); + assertThat(nativeConnection.get(KEY_2), is(VALUE_3)); + } + + @Test // DATAREDIS-315 + public void mSetNXShouldReturnTrueIfAllKeysSet() { + + Map map = new LinkedHashMap<>(); + map.put(KEY_1_BYTES, VALUE_1_BYTES); + map.put(KEY_2_BYTES, VALUE_2_BYTES); + + assertThat(clusterConnection.mSetNX(map), is(true)); + + assertThat(nativeConnection.get(KEY_1), is(VALUE_1)); + assertThat(nativeConnection.get(KEY_2), is(VALUE_2)); + } + + @Test // DATAREDIS-315 + public void mSetNXShouldWorkForOnSameSlotKeys() { + + Map map = new LinkedHashMap<>(); + map.put(SAME_SLOT_KEY_1_BYTES, VALUE_1_BYTES); + map.put(SAME_SLOT_KEY_2_BYTES, VALUE_2_BYTES); + + assertThat(clusterConnection.mSetNX(map), is(true)); + + assertThat(nativeConnection.get(SAME_SLOT_KEY_1), is(VALUE_1)); + assertThat(nativeConnection.get(SAME_SLOT_KEY_2), is(VALUE_2)); + } + + @Test // DATAREDIS-315 + public void mSetShouldWorkWhenKeysDoNotMapToSameSlot() { + + Map map = new LinkedHashMap<>(); + map.put(KEY_1_BYTES, VALUE_1_BYTES); + map.put(KEY_2_BYTES, VALUE_2_BYTES); + + clusterConnection.mSet(map); + + assertThat(nativeConnection.get(KEY_1), is(VALUE_1)); + assertThat(nativeConnection.get(KEY_2), is(VALUE_2)); + } + + @Test // DATAREDIS-315 + public void mSetShouldWorkWhenKeysMapToSameSlot() { + + Map map = new LinkedHashMap<>(); + map.put(SAME_SLOT_KEY_1_BYTES, VALUE_1_BYTES); + map.put(SAME_SLOT_KEY_2_BYTES, VALUE_2_BYTES); + + clusterConnection.mSet(map); + + assertThat(nativeConnection.get(SAME_SLOT_KEY_1), is(VALUE_1)); + assertThat(nativeConnection.get(SAME_SLOT_KEY_2), is(VALUE_2)); + } + + @Test(expected = UnsupportedOperationException.class) // DATAREDIS-315 + public void moveShouldNotBeSupported() { + clusterConnection.move(KEY_1_BYTES, 3); + } + + @Test(expected = DataAccessException.class) // DATAREDIS-315 + public void multiShouldThrowException() { + clusterConnection.multi(); + } + + @Test // DATAREDIS-315 + public void pExpireAtShouldBeSetCorrectly() { + + nativeConnection.set(KEY_1, VALUE_1); + + clusterConnection.pExpireAt(KEY_1_BYTES, System.currentTimeMillis() + 5000); + + assertThat(nativeConnection.ttl(LettuceConverters.toString(KEY_1_BYTES)) > 1, is(true)); + } + + @Test // DATAREDIS-315 + public void pExpireShouldBeSetCorreclty() { + + nativeConnection.set(KEY_1, VALUE_1); + + clusterConnection.pExpire(KEY_1_BYTES, 5000); + + assertThat(nativeConnection.ttl(LettuceConverters.toString(KEY_1_BYTES)) > 1, is(true)); + } + + @Test // DATAREDIS-315 + public void pSetExShouldSetValueCorrectly() { + + clusterConnection.pSetEx(KEY_1_BYTES, 5000, VALUE_1_BYTES); + + assertThat(nativeConnection.get(KEY_1), is(VALUE_1)); + assertThat(nativeConnection.ttl(KEY_1) > 1, is(true)); + } + + @Test // DATAREDIS-315 + public void pTtlShouldReturValueCorrectly() { + + nativeConnection.set(KEY_1, VALUE_1); + nativeConnection.expire(KEY_1, 5); + + assertThat(clusterConnection.pTtl(KEY_1_BYTES) > 1, is(true)); + } + + @Test // DATAREDIS-315 + public void pTtlShouldReturnMinusOneWhenKeyDoesNotHaveExpirationSet() { + + nativeConnection.set(KEY_1, VALUE_1); + + assertThat(clusterConnection.pTtl(KEY_1_BYTES), is(-1L)); + } + + @Test // DATAREDIS-315 + public void pTtlShouldReturnMinusTwoWhenKeyDoesNotExist() { + assertThat(clusterConnection.pTtl(KEY_1_BYTES), is(-2L)); + } + + @Test // DATAREDIS-526 + public void pTtlWithTimeUnitShouldReturnMinusTwoWhenKeyDoesNotExist() { + assertThat(clusterConnection.pTtl(KEY_1_BYTES, TimeUnit.SECONDS), is(-2L)); + } + + @Test // DATAREDIS-315 + public void persistShouldRemoveTTL() { + + nativeConnection.setex(KEY_1, 10, VALUE_1); + + assertThat(clusterConnection.persist(KEY_1_BYTES), is(Boolean.TRUE)); + assertThat(nativeConnection.ttl(KEY_1), is(-1L)); + } + + @Test // DATAREDIS-315 + public void pfAddShouldAddValuesCorrectly() { + + clusterConnection.pfAdd(KEY_1_BYTES, VALUE_1_BYTES, VALUE_2_BYTES, VALUE_3_BYTES); + + assertThat(((RedisHLLCommands) nativeConnection).pfcount(KEY_1), is(3L)); + } + + @Test // DATAREDIS-315 + public void pfCountShouldAllowCountingOnSameSlotKeys() { + + ((RedisHLLCommands) nativeConnection).pfadd(SAME_SLOT_KEY_1, VALUE_1, VALUE_2); + ((RedisHLLCommands) nativeConnection).pfadd(SAME_SLOT_KEY_2, VALUE_2, VALUE_3); + + assertThat(clusterConnection.pfCount(SAME_SLOT_KEY_1_BYTES, SAME_SLOT_KEY_2_BYTES), is(3L)); + } + + @Test // DATAREDIS-315 + public void pfCountShouldAllowCountingOnSingleKey() { + + ((RedisHLLCommands) nativeConnection).pfadd(KEY_1, VALUE_1, VALUE_2, VALUE_3); + + assertThat(clusterConnection.pfCount(KEY_1_BYTES), is(3L)); + } + + @Test(expected = DataAccessException.class) // DATAREDIS-315 + public void pfCountShouldThrowErrorCountingOnDifferentSlotKeys() { + + ((RedisHLLCommands) nativeConnection).pfadd(KEY_1, VALUE_1, VALUE_2); + ((RedisHLLCommands) nativeConnection).pfadd(KEY_2, VALUE_2, VALUE_3); + + clusterConnection.pfCount(KEY_1_BYTES, KEY_2_BYTES); + } + + @Test(expected = DataAccessException.class) // DATAREDIS-315 + public void pfMergeShouldThrowErrorOnDifferentSlotKeys() { + clusterConnection.pfMerge(KEY_3_BYTES, KEY_1_BYTES, KEY_2_BYTES); + } + + @Test // DATAREDIS-315 + public void pfMergeShouldWorkWhenAllKeysMapToSameSlot() { + + ((RedisHLLCommands) nativeConnection).pfadd(SAME_SLOT_KEY_1, VALUE_1, VALUE_2); + ((RedisHLLCommands) nativeConnection).pfadd(SAME_SLOT_KEY_2, VALUE_2, VALUE_3); + + ((RedisHLLCommands) nativeConnection).pfmerge(SAME_SLOT_KEY_3, SAME_SLOT_KEY_1, SAME_SLOT_KEY_2); + + assertThat(((RedisHLLCommands) nativeConnection).pfcount(SAME_SLOT_KEY_3), is(3L)); + } + + @Test // DATAREDIS-315 + public void pingShouldRetrunPong() { + assertThat(clusterConnection.ping(), is("PONG")); + } + + @Test // DATAREDIS-315 + public void pingShouldRetrunPongForExistingNode() { + assertThat(clusterConnection.ping(new RedisClusterNode("127.0.0.1", 7379, SlotRange.empty())), is("PONG")); + } + + @Test(expected = IllegalArgumentException.class) // DATAREDIS-315 + public void pingShouldThrowExceptionWhenNodeNotKnownToCluster() { + clusterConnection.ping(new RedisClusterNode("127.0.0.1", 1234, SlotRange.empty())); + } + + @Test // DATAREDIS-315 + public void rPopLPushShouldWorkWhenDoNotMapToSameSlot() { + + nativeConnection.lpush(KEY_1, VALUE_1, VALUE_2); + nativeConnection.lpush(KEY_2, VALUE_3); + + assertThat(clusterConnection.bLPop(100, KEY_1_BYTES, KEY_2_BYTES).size(), is(2)); + } + + @Test // DATAREDIS-315 + public void rPopLPushShouldWorkWhenKeysOnSameSlot() { + + nativeConnection.lpush(SAME_SLOT_KEY_1, VALUE_1, VALUE_2); + + assertThat(clusterConnection.rPopLPush(SAME_SLOT_KEY_1_BYTES, SAME_SLOT_KEY_2_BYTES), is(VALUE_1_BYTES)); + assertThat(nativeConnection.exists(SAME_SLOT_KEY_2), is(1L)); + } + + @Test // DATAREDIS-315 + public void rPopShouldReturnElementCorrectly() { + + nativeConnection.rpush(KEY_1, VALUE_1, VALUE_2); + + assertThat(clusterConnection.rPop(KEY_1_BYTES), is(VALUE_2_BYTES)); + } + + @Test // DATAREDIS-315 + public void rPushNXShoultNotAddValuesWhenKeyDoesNotExist() { + + clusterConnection.rPushX(KEY_1_BYTES, VALUE_1_BYTES); + + assertThat(nativeConnection.exists(KEY_1), is(0L)); + } + + @Test // DATAREDIS-315 + public void rPushShoultAddValuesCorrectly() { + + clusterConnection.rPush(KEY_1_BYTES, VALUE_1_BYTES, VALUE_2_BYTES); + + assertThat(nativeConnection.lrange(KEY_1, 0, -1), hasItems(VALUE_1, VALUE_2)); + } + + @Test // DATAREDIS-315 + public void randomKeyShouldReturnCorrectlyWhenKeysAvailable() { + + nativeConnection.set(KEY_1, VALUE_1); + nativeConnection.set(KEY_2, VALUE_2); + + assertThat(clusterConnection.randomKey(), notNullValue()); + } + + @Test // DATAREDIS-315 + public void randomKeyShouldReturnNullWhenNoKeysAvailable() { + assertThat(clusterConnection.randomKey(), nullValue()); + } + + @Test // DATAREDIS-315 + public void rename() { + + nativeConnection.set(KEY_1, VALUE_1); + + clusterConnection.rename(KEY_1_BYTES, KEY_2_BYTES); + + assertThat(nativeConnection.exists(KEY_1), is(0L)); + assertThat(nativeConnection.get(KEY_2), is(VALUE_1)); + } + + @Test // DATAREDIS-315 + public void renameNXWhenOnSameSlot() { + + nativeConnection.set(SAME_SLOT_KEY_1, VALUE_1); + + assertThat(clusterConnection.renameNX(SAME_SLOT_KEY_1_BYTES, SAME_SLOT_KEY_2_BYTES), is(Boolean.TRUE)); + + assertThat(nativeConnection.exists(SAME_SLOT_KEY_1), is(0L)); + assertThat(nativeConnection.get(SAME_SLOT_KEY_2), is(VALUE_1)); + } + + @Test // DATAREDIS-315 + public void renameNXWhenTargetKeyDoesExist() { + + nativeConnection.set(KEY_1, VALUE_1); + nativeConnection.set(KEY_2, VALUE_2); + + assertThat(clusterConnection.renameNX(KEY_1_BYTES, KEY_2_BYTES), is(Boolean.FALSE)); + + assertThat(nativeConnection.get(KEY_1), is(VALUE_1)); + assertThat(nativeConnection.get(KEY_2), is(VALUE_2)); + } + + @Test // DATAREDIS-315 + public void renameNXWhenTargetKeyDoesNotExist() { + + nativeConnection.set(KEY_1, VALUE_1); + + assertThat(clusterConnection.renameNX(KEY_1_BYTES, KEY_2_BYTES), is(Boolean.TRUE)); + + assertThat(nativeConnection.exists(KEY_1), is(0L)); + assertThat(nativeConnection.get(KEY_2), is(VALUE_1)); + } + + @Test // DATAREDIS-315 + public void renameSameKeysOnSameSlot() { + + nativeConnection.set(SAME_SLOT_KEY_1, VALUE_1); + + clusterConnection.rename(SAME_SLOT_KEY_1_BYTES, SAME_SLOT_KEY_2_BYTES); + + assertThat(nativeConnection.exists(SAME_SLOT_KEY_1), is(0L)); + assertThat(nativeConnection.get(SAME_SLOT_KEY_2), is(VALUE_1)); + } + + @Test // DATAREDIS-315 + public void sAddShouldAddValueToSetCorrectly() { + + clusterConnection.sAdd(KEY_1_BYTES, VALUE_1_BYTES, VALUE_2_BYTES); + + assertThat(nativeConnection.smembers(KEY_1), hasItems(VALUE_1, VALUE_2)); + } + + @Test // DATAREDIS-315 + public void sCardShouldCountValuesInSetCorrectly() { + + nativeConnection.sadd(KEY_1, VALUE_1, VALUE_2); + + assertThat(clusterConnection.sCard(KEY_1_BYTES), is(2L)); + } + + @Test // DATAREDIS-315 + public void sDiffShouldWorkWhenKeysMapToSameSlot() { + + nativeConnection.sadd(SAME_SLOT_KEY_1, VALUE_1, VALUE_2); + nativeConnection.sadd(SAME_SLOT_KEY_2, VALUE_2, VALUE_3); + + assertThat(clusterConnection.sDiff(SAME_SLOT_KEY_1_BYTES, SAME_SLOT_KEY_2_BYTES), hasItems(VALUE_1_BYTES)); + } + + @Test // DATAREDIS-315, DATAREDIS-647 + public void sDiffShouldWorkWhenKeysNotMapToSameSlot() { + + nativeConnection.sadd(KEY_1, VALUE_1, VALUE_2); + nativeConnection.sadd(KEY_2, VALUE_2, VALUE_3); + nativeConnection.sadd(KEY_3, VALUE_1, VALUE_3); + + assertThat(clusterConnection.sDiff(KEY_1_BYTES, KEY_2_BYTES), hasItems(VALUE_1_BYTES)); + assertThat(clusterConnection.sDiff(KEY_1_BYTES, KEY_2_BYTES, KEY_3_BYTES), is(empty())); + } + + @Test // DATAREDIS-315 + public void sDiffStoreShouldWorkWhenKeysMapToSameSlot() { + + nativeConnection.sadd(SAME_SLOT_KEY_1, VALUE_1, VALUE_2); + nativeConnection.sadd(SAME_SLOT_KEY_2, VALUE_2, VALUE_3); + + clusterConnection.sDiffStore(SAME_SLOT_KEY_3_BYTES, SAME_SLOT_KEY_1_BYTES, SAME_SLOT_KEY_2_BYTES); + + assertThat(nativeConnection.smembers(SAME_SLOT_KEY_3), hasItems(VALUE_1)); + } + + @Test // DATAREDIS-315 + public void sDiffStoreShouldWorkWhenKeysNotMapToSameSlot() { + + nativeConnection.sadd(KEY_1, VALUE_1, VALUE_2); + nativeConnection.sadd(KEY_2, VALUE_2, VALUE_3); + + clusterConnection.sDiffStore(KEY_3_BYTES, KEY_1_BYTES, KEY_2_BYTES); + + assertThat(nativeConnection.smembers(KEY_3), hasItems(VALUE_1)); + } + + @Test // DATAREDIS-315 + public void sInterShouldWorkForKeysMappingToSameSlot() { + + nativeConnection.sadd(SAME_SLOT_KEY_1, VALUE_1, VALUE_2); + nativeConnection.sadd(SAME_SLOT_KEY_2, VALUE_2, VALUE_3); + + assertThat(clusterConnection.sInter(SAME_SLOT_KEY_1_BYTES, SAME_SLOT_KEY_2_BYTES), hasItem(VALUE_2_BYTES)); + } + + @Test // DATAREDIS-315 + public void sInterShouldWorkForKeysNotMappingToSameSlot() { + + nativeConnection.sadd(KEY_1, VALUE_1, VALUE_2); + nativeConnection.sadd(KEY_2, VALUE_2, VALUE_3); + + assertThat(clusterConnection.sInter(KEY_1_BYTES, KEY_2_BYTES), hasItem(VALUE_2_BYTES)); + } + + @Test // DATAREDIS-315 + public void sInterStoreShouldWorkForKeysMappingToSameSlot() { + + nativeConnection.sadd(SAME_SLOT_KEY_1, VALUE_1, VALUE_2); + nativeConnection.sadd(SAME_SLOT_KEY_2, VALUE_2, VALUE_3); + + clusterConnection.sInterStore(SAME_SLOT_KEY_3_BYTES, SAME_SLOT_KEY_1_BYTES, SAME_SLOT_KEY_2_BYTES); + + assertThat(nativeConnection.smembers(SAME_SLOT_KEY_3), hasItem(VALUE_2)); + } + + @Test // DATAREDIS-315 + public void sInterStoreShouldWorkForKeysNotMappingToSameSlot() { + + nativeConnection.sadd(KEY_1, VALUE_1, VALUE_2); + nativeConnection.sadd(KEY_2, VALUE_2, VALUE_3); + + clusterConnection.sInterStore(KEY_3_BYTES, KEY_1_BYTES, KEY_2_BYTES); + + assertThat(nativeConnection.smembers(KEY_3), hasItem(VALUE_2)); + } + + @Test // DATAREDIS-315 + public void sIsMemberShouldReturnFalseIfValueIsMemberOfSet() { + + nativeConnection.sadd(KEY_1, VALUE_1, VALUE_2); + + assertThat(clusterConnection.sIsMember(KEY_1_BYTES, LettuceConverters.toBytes("foo")), is(false)); + } + + @Test // DATAREDIS-315 + public void sIsMemberShouldReturnTrueIfValueIsMemberOfSet() { + + nativeConnection.sadd(KEY_1, VALUE_1, VALUE_2); + + assertThat(clusterConnection.sIsMember(KEY_1_BYTES, VALUE_1_BYTES), is(true)); + } + + @Test // DATAREDIS-315 + public void sMembersShouldReturnValuesContainedInSetCorrectly() { + + nativeConnection.sadd(KEY_1, VALUE_1, VALUE_2); + + assertThat(clusterConnection.sMembers(KEY_1_BYTES), hasItems(VALUE_1_BYTES, VALUE_2_BYTES)); + } + + @Test // DATAREDIS-315 + public void sMoveShouldWorkWhenKeysDoNotMapToSameSlot() { + + nativeConnection.sadd(KEY_1, VALUE_1, VALUE_2); + nativeConnection.sadd(KEY_2, VALUE_3); + + clusterConnection.sMove(KEY_1_BYTES, KEY_2_BYTES, VALUE_2_BYTES); + + assertThat(nativeConnection.sismember(KEY_1, VALUE_2), is(false)); + assertThat(nativeConnection.sismember(KEY_2, VALUE_2), is(true)); + } + + @Test // DATAREDIS-315 + public void sMoveShouldWorkWhenKeysMapToSameSlot() { + + nativeConnection.sadd(SAME_SLOT_KEY_1, VALUE_1, VALUE_2); + nativeConnection.sadd(SAME_SLOT_KEY_2, VALUE_3); + + clusterConnection.sMove(SAME_SLOT_KEY_1_BYTES, SAME_SLOT_KEY_2_BYTES, VALUE_2_BYTES); + + assertThat(nativeConnection.sismember(SAME_SLOT_KEY_1, VALUE_2), is(false)); + assertThat(nativeConnection.sismember(SAME_SLOT_KEY_2, VALUE_2), is(true)); + } + + @Test // DATAREDIS-315 + public void sPopShouldPopValueFromSetCorrectly() { + + nativeConnection.sadd(KEY_1, VALUE_1, VALUE_2); + + assertThat(clusterConnection.sPop(KEY_1_BYTES), notNullValue()); + } + + @Test // DATAREDIS-668 + public void sPopWithCountShouldPopValueFromSetCorrectly() { + + nativeConnection.sadd(KEY_1, VALUE_1, VALUE_2, VALUE_3); + + assertThat(clusterConnection.setCommands().sPop(KEY_1_BYTES, 2), hasSize(2)); + assertThat(nativeConnection.scard(KEY_1), is(1L)); + } + + @Test // DATAREDIS-315 + public void sRandMamberShouldReturnValueCorrectly() { + + nativeConnection.sadd(KEY_1, VALUE_1, VALUE_2); + + assertThat(clusterConnection.sRandMember(KEY_1_BYTES), notNullValue()); + } + + @Test // DATAREDIS-315 + public void sRandMamberWithCountShouldReturnValueCorrectly() { + + nativeConnection.sadd(KEY_1, VALUE_1, VALUE_2); + + assertThat(clusterConnection.sRandMember(KEY_1_BYTES, 3), notNullValue()); + } + + @Test // DATAREDIS-315 + public void sRemShouldRemoveValueFromSetCorrectly() { + + nativeConnection.sadd(KEY_1, VALUE_1, VALUE_2); + + clusterConnection.sRem(KEY_1_BYTES, VALUE_2_BYTES); + + assertThat(nativeConnection.smembers(KEY_1), hasItems(VALUE_1)); + } + + @Test // DATAREDIS-315 + public void sUnionShouldWorkForKeysMappingToSameSlot() { + + nativeConnection.sadd(SAME_SLOT_KEY_1, VALUE_1, VALUE_2); + nativeConnection.sadd(SAME_SLOT_KEY_2, VALUE_2, VALUE_3); + + assertThat(clusterConnection.sUnion(SAME_SLOT_KEY_1_BYTES, SAME_SLOT_KEY_2_BYTES), + hasItems(VALUE_1_BYTES, VALUE_2_BYTES, VALUE_3_BYTES)); + } + + @Test // DATAREDIS-315 + public void sUnionShouldWorkForKeysNotMappingToSameSlot() { + + nativeConnection.sadd(KEY_1, VALUE_1, VALUE_2); + nativeConnection.sadd(KEY_2, VALUE_2, VALUE_3); + + assertThat(clusterConnection.sUnion(KEY_1_BYTES, KEY_2_BYTES), + hasItems(VALUE_1_BYTES, VALUE_2_BYTES, VALUE_3_BYTES)); + } + + @Test // DATAREDIS-315 + public void sUnionStoreShouldWorkForKeysMappingToSameSlot() { + + nativeConnection.sadd(SAME_SLOT_KEY_1, VALUE_1, VALUE_2); + nativeConnection.sadd(SAME_SLOT_KEY_2, VALUE_2, VALUE_3); + + clusterConnection.sUnionStore(SAME_SLOT_KEY_3_BYTES, SAME_SLOT_KEY_1_BYTES, SAME_SLOT_KEY_2_BYTES); + + assertThat(nativeConnection.smembers(SAME_SLOT_KEY_3), hasItems(VALUE_1, VALUE_2, VALUE_3)); + } + + @Test // DATAREDIS-315 + public void sUnionStoreShouldWorkForKeysNotMappingToSameSlot() { + + nativeConnection.sadd(KEY_1, VALUE_1, VALUE_2); + nativeConnection.sadd(KEY_2, VALUE_2, VALUE_3); + + clusterConnection.sUnionStore(KEY_3_BYTES, KEY_1_BYTES, KEY_2_BYTES); + + assertThat(nativeConnection.smembers(KEY_3), hasItems(VALUE_1, VALUE_2, VALUE_3)); + } + + @Test // DATAREDIS-315 + public void selectShouldAllowSelectionOfDBIndexZero() { + clusterConnection.select(0); + } + + @Test(expected = DataAccessException.class) // DATAREDIS-315 + public void selectShouldThrowExceptionWhenSelectingNonZeroDbIndex() { + clusterConnection.select(1); + } + + @Test // DATAREDIS-315 + public void setBitShouldWorkCorrectly() { + + clusterConnection.setBit(KEY_1_BYTES, 0, true); + clusterConnection.setBit(KEY_1_BYTES, 1, false); + + assertThat(nativeConnection.getbit(KEY_1, 0), is(1L)); + assertThat(nativeConnection.getbit(KEY_1, 1), is(0L)); + } + + @Test // DATAREDIS-315 + public void setExShouldSetValueCorrectly() { + + clusterConnection.setEx(KEY_1_BYTES, 5, VALUE_1_BYTES); + + assertThat(nativeConnection.get(KEY_1), is(VALUE_1)); + assertThat(nativeConnection.ttl(KEY_1) > 1, is(true)); + } + + @Test // DATAREDIS-315 + public void setNxShouldNotSetValueWhenAlreadyExistsInDBCorrectly() { + + nativeConnection.set(KEY_1, VALUE_1); + + clusterConnection.setNX(KEY_1_BYTES, VALUE_2_BYTES); + + assertThat(nativeConnection.get(KEY_1), is(VALUE_1)); + } + + @Test // DATAREDIS-315 + public void setNxShouldSetValueCorrectly() { + + clusterConnection.setNX(KEY_1_BYTES, VALUE_1_BYTES); + + assertThat(nativeConnection.get(KEY_1), is(VALUE_1)); + } + + @Test // DATAREDIS-315 + public void setRangeShouldWorkCorrectly() { + + nativeConnection.set(KEY_1, VALUE_1); + + clusterConnection.setRange(KEY_1_BYTES, LettuceConverters.toBytes("UE"), 3); + + assertThat(nativeConnection.get(KEY_1), is("valUE1")); + } + + @Test // DATAREDIS-315 + public void setShouldSetValueCorrectly() { + + clusterConnection.set(KEY_1_BYTES, VALUE_1_BYTES); + + assertThat(nativeConnection.get(KEY_1), is(VALUE_1)); + } + + @Test // DATAREDIS-316 + public void setWithExpirationAndIfAbsentShouldNotBeAppliedWhenKeyExists() { + + nativeConnection.set(KEY_1, VALUE_1); + + clusterConnection.set(KEY_1_BYTES, VALUE_2_BYTES, Expiration.seconds(1), SetOption.ifAbsent()); + + assertThat(nativeConnection.exists(KEY_1), is(1L)); + assertThat(nativeConnection.ttl(KEY_1), is(-1L)); + assertThat(nativeConnection.get(KEY_1), is(equalTo(VALUE_1))); + + } + + @Test // DATAREDIS-316 + public void setWithExpirationAndIfAbsentShouldWorkCorrectly() { + + clusterConnection.set(KEY_1_BYTES, VALUE_1_BYTES, Expiration.seconds(1), SetOption.ifAbsent()); + + assertThat(nativeConnection.exists(KEY_1), is(1L)); + assertThat(nativeConnection.ttl(KEY_1), is(1L)); + } + + @Test // DATAREDIS-316 + public void setWithExpirationAndIfPresentShouldNotBeAppliedWhenKeyDoesNotExists() { + + clusterConnection.set(KEY_1_BYTES, VALUE_1_BYTES, Expiration.seconds(1), SetOption.ifPresent()); + + assertThat(nativeConnection.exists(KEY_1), is(0L)); + } + + @Test // DATAREDIS-316 + public void setWithExpirationAndIfPresentShouldWorkCorrectly() { + + nativeConnection.set(KEY_1, VALUE_1); + + clusterConnection.set(KEY_1_BYTES, VALUE_2_BYTES, Expiration.seconds(1), SetOption.ifPresent()); + + assertThat(nativeConnection.exists(KEY_1), is(1L)); + assertThat(nativeConnection.ttl(KEY_1), is(1L)); + assertThat(nativeConnection.get(KEY_1), is(equalTo(VALUE_2))); + + } + + @Test // DATAREDIS-316 + public void setWithExpirationInMillisecondsShouldWorkCorrectly() { + + clusterConnection.set(KEY_1_BYTES, VALUE_1_BYTES, Expiration.milliseconds(500), SetOption.upsert()); + + assertThat(nativeConnection.exists(KEY_1), is(1L)); + assertThat(nativeConnection.pttl(KEY_1).doubleValue(), is(closeTo(500d, 499d))); + } + + @Test // DATAREDIS-316 + public void setWithExpirationInSecondsShouldWorkCorrectly() { + + clusterConnection.set(KEY_1_BYTES, VALUE_1_BYTES, Expiration.seconds(1), SetOption.upsert()); + + assertThat(nativeConnection.exists(KEY_1), is(1L)); + assertThat(nativeConnection.ttl(KEY_1), is(1L)); + } + + @Test // DATAREDIS-316 + public void setWithOptionIfAbsentShouldWorkCorrectly() { + + clusterConnection.set(KEY_1_BYTES, VALUE_1_BYTES, Expiration.persistent(), SetOption.ifAbsent()); + + assertThat(nativeConnection.exists(KEY_1), is(1L)); + assertThat(nativeConnection.ttl(KEY_1), is(-1L)); + } + + @Test // DATAREDIS-316 + public void setWithOptionIfPresentShouldWorkCorrectly() { + + nativeConnection.set(KEY_1, VALUE_1); + clusterConnection.set(KEY_1_BYTES, VALUE_2_BYTES, Expiration.persistent(), SetOption.ifPresent()); + } + + @Test // DATAREDIS-315 + public void shouldAllowSettingAndGettingValues() { + + clusterConnection.set(KEY_1_BYTES, VALUE_1_BYTES); + assertThat(clusterConnection.get(KEY_1_BYTES), is(VALUE_1_BYTES)); + } + + @Test // DATAREDIS-315 + public void sortAndStoreShouldAddSortedValuesValuesCorrectly() { + + nativeConnection.lpush(KEY_1, VALUE_2, VALUE_1); + + assertThat(clusterConnection.sort(KEY_1_BYTES, new DefaultSortParameters().alpha(), KEY_2_BYTES), is(1L)); + assertThat(nativeConnection.exists(KEY_2), is(1L)); + } + + @Test // DATAREDIS-315 + public void sortAndStoreShouldReturnZeroWhenListDoesNotExist() { + assertThat(clusterConnection.sort(KEY_1_BYTES, new DefaultSortParameters().alpha(), KEY_2_BYTES), is(0L)); + } + + @Test // DATAREDIS-315 + public void sortShouldReturnValuesCorrectly() { + + nativeConnection.lpush(KEY_1, VALUE_2, VALUE_1); + + assertThat(clusterConnection.sort(KEY_1_BYTES, new DefaultSortParameters().alpha()), + hasItems(VALUE_1_BYTES, VALUE_2_BYTES)); + } + + @Test // DATAREDIS-315 + public void sscanShouldRetrieveAllValuesInSetCorrectly() { + + for (int i = 0; i < 30; i++) { + nativeConnection.sadd(KEY_1, Integer.valueOf(i).toString()); + } + + int count = 0; + Cursor cursor = clusterConnection.sScan(KEY_1_BYTES, ScanOptions.NONE); + while (cursor.hasNext()) { + count++; + cursor.next(); + } + + assertThat(count, is(30)); + } + + @Test // DATAREDIS-315 + public void strLenShouldWorkCorrectly() { + + nativeConnection.set(KEY_1, VALUE_1); + + assertThat(clusterConnection.strLen(KEY_1_BYTES), is(6L)); + } + + @Test // DATAREDIS-315 + public void ttlShouldReturnMinusOneWhenKeyDoesNotHaveExpirationSet() { + + nativeConnection.set(KEY_1, VALUE_1); + + assertThat(clusterConnection.ttl(KEY_1_BYTES), is(-1L)); + } + + @Test // DATAREDIS-315 + public void ttlShouldReturnMinusTwoWhenKeyDoesNotExist() { + assertThat(clusterConnection.ttl(KEY_1_BYTES), is(-2L)); + } + + @Test // DATAREDIS-315 + public void ttlShouldReturnValueCorrectly() { + + nativeConnection.set(KEY_1, VALUE_1); + nativeConnection.expire(KEY_1, 5); + + assertThat(clusterConnection.ttl(KEY_1_BYTES) > 1, is(true)); + } + + @Test // DATAREDIS-526 + public void ttlWithTimeUnitShouldReturnMinusOneWhenKeyDoesNotHaveExpirationSet() { + + nativeConnection.set(KEY_1, VALUE_1); + + assertThat(clusterConnection.ttl(KEY_1_BYTES, TimeUnit.SECONDS), is(-1L)); + } + + @Test // DATAREDIS-526 + public void ttlWithTimeUnitShouldReturnMinusTwoWhenKeyDoesNotExist() { + assertThat(clusterConnection.ttl(KEY_1_BYTES, TimeUnit.HOURS), is(-2L)); + } + + @Test // DATAREDIS-315 + public void typeShouldReadKeyTypeCorrectly() { + + nativeConnection.sadd(KEY_1, VALUE_1); + nativeConnection.set(KEY_2, VALUE_2); + nativeConnection.hmset(KEY_3, Collections.singletonMap(KEY_1, VALUE_1)); + + assertThat(clusterConnection.type(KEY_1_BYTES), is(DataType.SET)); + assertThat(clusterConnection.type(KEY_2_BYTES), is(DataType.STRING)); + assertThat(clusterConnection.type(KEY_3_BYTES), is(DataType.HASH)); + } + + @Test(expected = DataAccessException.class) // DATAREDIS-315 + public void unwatchShouldThrowException() { + clusterConnection.unwatch(); + } + + @Test(expected = DataAccessException.class) // DATAREDIS-315 + public void watchShouldThrowException() { + clusterConnection.watch(); + } + + @Test // DATAREDIS-674 + public void zAddShouldAddMultipleValuesWithScoreCorrectly() { + + Set tuples = new HashSet<>(); + tuples.add(new DefaultTuple(VALUE_1_BYTES, 10D)); + tuples.add(new DefaultTuple(VALUE_2_BYTES, 20D)); + + clusterConnection.zAdd(KEY_1_BYTES, tuples); + + assertThat(nativeConnection.zcard(KEY_1), is(2L)); + } + + @Test // DATAREDIS-315 + public void zAddShouldAddValueWithScoreCorrectly() { + + clusterConnection.zAdd(KEY_1_BYTES, 10D, VALUE_1_BYTES); + clusterConnection.zAdd(KEY_1_BYTES, 20D, VALUE_2_BYTES); + + assertThat(nativeConnection.zcard(KEY_1), is(2L)); + } + + @Test // DATAREDIS-315 + public void zCardShouldReturnTotalNumberOfValues() { + + nativeConnection.zadd(KEY_1, 10D, VALUE_1); + nativeConnection.zadd(KEY_1, 20D, VALUE_2); + nativeConnection.zadd(KEY_1, 5D, VALUE_3); + + assertThat(clusterConnection.zCard(KEY_1_BYTES), is(3L)); + } + + @Test // DATAREDIS-315 + public void zCountShouldCountValuesInRange() { + + nativeConnection.zadd(KEY_1, 10D, VALUE_1); + nativeConnection.zadd(KEY_1, 20D, VALUE_2); + nativeConnection.zadd(KEY_1, 5D, VALUE_3); + + assertThat(clusterConnection.zCount(KEY_1_BYTES, 10, 20), is(2L)); + } + + @Test // DATAREDIS-315 + public void zIncrByShouldIncScoreForValueCorrectly() { + + nativeConnection.zadd(KEY_1, 10D, VALUE_1); + nativeConnection.zadd(KEY_1, 20D, VALUE_2); + + clusterConnection.zIncrBy(KEY_1_BYTES, 100D, VALUE_1_BYTES); + + assertThat(nativeConnection.zrank(KEY_1, VALUE_1), is(1L)); + } + + @Test(expected = DataAccessException.class) // DATAREDIS-315 + public void zInterStoreShouldThrowExceptionWhenKeysDoNotMapToSameSlots() { + clusterConnection.zInterStore(KEY_3_BYTES, KEY_1_BYTES, KEY_2_BYTES); + } + + @Test // DATAREDIS-315 + public void zInterStoreShouldWorkForSameSlotKeys() { + + nativeConnection.zadd(SAME_SLOT_KEY_1, 10D, VALUE_1); + nativeConnection.zadd(SAME_SLOT_KEY_1, 20D, VALUE_2); + + nativeConnection.zadd(SAME_SLOT_KEY_2, 20D, VALUE_2); + nativeConnection.zadd(SAME_SLOT_KEY_2, 30D, VALUE_3); + + clusterConnection.zInterStore(SAME_SLOT_KEY_3_BYTES, SAME_SLOT_KEY_1_BYTES, SAME_SLOT_KEY_2_BYTES); + + assertThat(nativeConnection.zrange(SAME_SLOT_KEY_3, 0, -1), hasItems(VALUE_2)); + } + + @Test // DATAREDIS-315 + public void zRangeByLexShouldReturnResultCorrectly() { + + nativeConnection.zadd(KEY_1, 0, "a"); + nativeConnection.zadd(KEY_1, 0, "b"); + nativeConnection.zadd(KEY_1, 0, "c"); + nativeConnection.zadd(KEY_1, 0, "d"); + nativeConnection.zadd(KEY_1, 0, "e"); + nativeConnection.zadd(KEY_1, 0, "f"); + nativeConnection.zadd(KEY_1, 0, "g"); + + Set values = clusterConnection.zRangeByLex(KEY_1_BYTES, Range.range().lte("c")); + + assertThat(values, + hasItems(LettuceConverters.toBytes("a"), LettuceConverters.toBytes("b"), LettuceConverters.toBytes("c"))); + assertThat(values, not(hasItems(LettuceConverters.toBytes("d"), LettuceConverters.toBytes("e"), + LettuceConverters.toBytes("f"), LettuceConverters.toBytes("g")))); + + values = clusterConnection.zRangeByLex(KEY_1_BYTES, Range.range().lt("c")); + assertThat(values, hasItems(LettuceConverters.toBytes("a"), LettuceConverters.toBytes("b"))); + assertThat(values, not(hasItem(LettuceConverters.toBytes("c")))); + + values = clusterConnection.zRangeByLex(KEY_1_BYTES, Range.range().gte("aaa").lt("g")); + assertThat(values, hasItems(LettuceConverters.toBytes("b"), LettuceConverters.toBytes("c"), + LettuceConverters.toBytes("d"), LettuceConverters.toBytes("e"), LettuceConverters.toBytes("f"))); + assertThat(values, not(hasItems(LettuceConverters.toBytes("a"), LettuceConverters.toBytes("g")))); + + values = clusterConnection.zRangeByLex(KEY_1_BYTES, Range.range().gte("e")); + assertThat(values, + hasItems(LettuceConverters.toBytes("e"), LettuceConverters.toBytes("f"), LettuceConverters.toBytes("g"))); + assertThat(values, not(hasItems(LettuceConverters.toBytes("a"), LettuceConverters.toBytes("b"), + LettuceConverters.toBytes("c"), LettuceConverters.toBytes("d")))); + } + + @Test // DATAREDIS-315 + public void zRangeByScoreShouldReturnValuesCorrectly() { + + nativeConnection.zadd(KEY_1, 10D, VALUE_1); + nativeConnection.zadd(KEY_1, 20D, VALUE_2); + nativeConnection.zadd(KEY_1, 5D, VALUE_3); + + assertThat(clusterConnection.zRangeByScore(KEY_1_BYTES, 10, 20), hasItems(VALUE_1_BYTES, VALUE_2_BYTES)); + } + + @Test // DATAREDIS-315 + public void zRangeByScoreShouldReturnValuesCorrectlyWhenGivenOffsetAndScore() { + + nativeConnection.zadd(KEY_1, 10D, VALUE_1); + nativeConnection.zadd(KEY_1, 20D, VALUE_2); + nativeConnection.zadd(KEY_1, 5D, VALUE_3); + + assertThat(clusterConnection.zRangeByScore(KEY_1_BYTES, 10D, 20D, 0L, 1L), hasItems(VALUE_1_BYTES)); + } + + @Test // DATAREDIS-315 + public void zRangeByScoreWithScoresShouldReturnValuesAndScoreCorrectly() { + + nativeConnection.zadd(KEY_1, 10D, VALUE_1); + nativeConnection.zadd(KEY_1, 20D, VALUE_2); + nativeConnection.zadd(KEY_1, 5D, VALUE_3); + + assertThat(clusterConnection.zRangeByScoreWithScores(KEY_1_BYTES, 10, 20), + hasItems((Tuple) new DefaultTuple(VALUE_1_BYTES, 10D), (Tuple) new DefaultTuple(VALUE_2_BYTES, 20D))); + } + + @Test // DATAREDIS-315 + public void zRangeByScoreWithScoresShouldReturnValuesCorrectlyWhenGivenOffsetAndScore() { + + nativeConnection.zadd(KEY_1, 10D, VALUE_1); + nativeConnection.zadd(KEY_1, 20D, VALUE_2); + nativeConnection.zadd(KEY_1, 5D, VALUE_3); + + assertThat(clusterConnection.zRangeByScoreWithScores(KEY_1_BYTES, 10D, 20D, 0L, 1L), + hasItems((Tuple) new DefaultTuple(VALUE_1_BYTES, 10D))); + } + + @Test // DATAREDIS-315 + public void zRangeShouldReturnValuesCorrectly() { + + nativeConnection.zadd(KEY_1, 10D, VALUE_1); + nativeConnection.zadd(KEY_1, 20D, VALUE_2); + nativeConnection.zadd(KEY_1, 5D, VALUE_3); + + assertThat(clusterConnection.zRange(KEY_1_BYTES, 1, 2), hasItems(VALUE_1_BYTES, VALUE_2_BYTES)); + } + + @Test // DATAREDIS-315 + public void zRangeWithScoresShouldReturnValuesAndScoreCorrectly() { + + nativeConnection.zadd(KEY_1, 10D, VALUE_1); + nativeConnection.zadd(KEY_1, 20D, VALUE_2); + nativeConnection.zadd(KEY_1, 5D, VALUE_3); + + assertThat(clusterConnection.zRangeWithScores(KEY_1_BYTES, 1, 2), + hasItems((Tuple) new DefaultTuple(VALUE_1_BYTES, 10D), (Tuple) new DefaultTuple(VALUE_2_BYTES, 20D))); + } + + @Test // DATAREDIS-315 + public void zRankShouldReturnPositionForValueCorrectly() { + + nativeConnection.zadd(KEY_1, 10D, VALUE_1); + nativeConnection.zadd(KEY_1, 20D, VALUE_2); + + assertThat(clusterConnection.zRank(KEY_1_BYTES, VALUE_2_BYTES), is(1L)); + } + + @Test // DATAREDIS-315 + public void zRankShouldReturnReversePositionForValueCorrectly() { + + nativeConnection.zadd(KEY_1, 10D, VALUE_1); + nativeConnection.zadd(KEY_1, 20D, VALUE_2); + + assertThat(clusterConnection.zRevRank(KEY_1_BYTES, VALUE_2_BYTES), is(0L)); + } + + @Test // DATAREDIS-315 + public void zRemRangeByScoreShouldRemoveValues() { + + nativeConnection.zadd(KEY_1, 10D, VALUE_1); + nativeConnection.zadd(KEY_1, 20D, VALUE_2); + nativeConnection.zadd(KEY_1, 30D, VALUE_3); + + clusterConnection.zRemRangeByScore(KEY_1_BYTES, 15D, 25D); + + assertThat(nativeConnection.zcard(KEY_1), is(2L)); + assertThat(nativeConnection.zrange(KEY_1, 0, -1), hasItems(VALUE_1, VALUE_3)); + } + + @Test // DATAREDIS-315 + public void zRemRangeShouldRemoveValues() { + + nativeConnection.zadd(KEY_1, 10D, VALUE_1); + nativeConnection.zadd(KEY_1, 20D, VALUE_2); + nativeConnection.zadd(KEY_1, 30D, VALUE_3); + + clusterConnection.zRemRange(KEY_1_BYTES, 1, 2); + + assertThat(nativeConnection.zcard(KEY_1), is(1L)); + assertThat(nativeConnection.zrange(KEY_1, 0, -1), hasItem(VALUE_1)); + } + + @Test // DATAREDIS-315 + public void zRemShouldRemoveValueWithScoreCorrectly() { + + nativeConnection.zadd(KEY_1, 10D, VALUE_1); + nativeConnection.zadd(KEY_1, 20D, VALUE_2); + + clusterConnection.zRem(KEY_1_BYTES, VALUE_1_BYTES); + + assertThat(nativeConnection.zcard(KEY_1), is(1L)); + } + + @Test // DATAREDIS-315 + public void zRevRangeByScoreShouldReturnValuesCorrectly() { + + nativeConnection.zadd(KEY_1, 10D, VALUE_1); + nativeConnection.zadd(KEY_1, 20D, VALUE_2); + nativeConnection.zadd(KEY_1, 5D, VALUE_3); + + assertThat(clusterConnection.zRevRangeByScore(KEY_1_BYTES, 10D, 20D), hasItems(VALUE_2_BYTES, VALUE_1_BYTES)); + } + + @Test // DATAREDIS-315 + public void zRevRangeByScoreShouldReturnValuesCorrectlyWhenGivenOffsetAndScore() { + + nativeConnection.zadd(KEY_1, 10D, VALUE_1); + nativeConnection.zadd(KEY_1, 20D, VALUE_2); + nativeConnection.zadd(KEY_1, 5D, VALUE_3); + + assertThat(clusterConnection.zRevRangeByScore(KEY_1_BYTES, 10D, 20D, 0L, 1L), hasItems(VALUE_2_BYTES)); + } + + @Test // DATAREDIS-315 + public void zRevRangeByScoreWithScoresShouldReturnValuesAndScoreCorrectly() { + + nativeConnection.zadd(KEY_1, 10D, VALUE_1); + nativeConnection.zadd(KEY_1, 20D, VALUE_2); + nativeConnection.zadd(KEY_1, 5D, VALUE_3); + + assertThat(clusterConnection.zRevRangeByScoreWithScores(KEY_1_BYTES, 10D, 20D), + hasItems((Tuple) new DefaultTuple(VALUE_2_BYTES, 20D), (Tuple) new DefaultTuple(VALUE_1_BYTES, 10D))); + } + + @Test // DATAREDIS-315 + public void zRevRangeByScoreWithScoresShouldReturnValuesCorrectlyWhenGivenOffsetAndScore() { + + nativeConnection.zadd(KEY_1, 10D, VALUE_1); + nativeConnection.zadd(KEY_1, 20D, VALUE_2); + nativeConnection.zadd(KEY_1, 5D, VALUE_3); + + assertThat(clusterConnection.zRevRangeByScoreWithScores(KEY_1_BYTES, 10D, 20D, 0L, 1L), + hasItems((Tuple) new DefaultTuple(VALUE_2_BYTES, 20D))); + } + + @Test // DATAREDIS-315 + public void zRevRangeShouldReturnValuesCorrectly() { + + nativeConnection.zadd(KEY_1, 10D, VALUE_1); + nativeConnection.zadd(KEY_1, 20D, VALUE_2); + nativeConnection.zadd(KEY_1, 5D, VALUE_3); + + assertThat(clusterConnection.zRevRange(KEY_1_BYTES, 1, 2), hasItems(VALUE_3_BYTES, VALUE_1_BYTES)); + } + + @Test // DATAREDIS-315 + public void zRevRangeWithScoresShouldReturnValuesAndScoreCorrectly() { + + nativeConnection.zadd(KEY_1, 10D, VALUE_1); + nativeConnection.zadd(KEY_1, 20D, VALUE_2); + nativeConnection.zadd(KEY_1, 5D, VALUE_3); + + assertThat(clusterConnection.zRevRangeWithScores(KEY_1_BYTES, 1, 2), + hasItems((Tuple) new DefaultTuple(VALUE_3_BYTES, 5D), (Tuple) new DefaultTuple(VALUE_1_BYTES, 10D))); + } + + @Test + public void zScanShouldReadEntireValueRange() { + + int nrOfValues = 321; + for (int i = 0; i < nrOfValues; i++) { + nativeConnection.zadd(KEY_1, i, "value-" + i); + } + + Cursor tuples = clusterConnection.zScan(KEY_1_BYTES, ScanOptions.NONE); + + int count = 0; + while (tuples.hasNext()) { + + tuples.next(); + count++; + } + + assertThat(count, equalTo(nrOfValues)); + } + + @Test // DATAREDIS-315 + public void zScoreShouldRetrieveScoreForValue() { + + nativeConnection.zadd(KEY_1, 10D, VALUE_1); + nativeConnection.zadd(KEY_1, 20D, VALUE_2); + + assertThat(clusterConnection.zScore(KEY_1_BYTES, VALUE_2_BYTES), is(20D)); + } + + @Test(expected = DataAccessException.class) // DATAREDIS-315 + public void zUnionStoreShouldThrowExceptionWhenKeysDoNotMapToSameSlots() { + clusterConnection.zUnionStore(KEY_3_BYTES, KEY_1_BYTES, KEY_2_BYTES); + } + + @Test // DATAREDIS-315 + public void zUnionStoreShouldWorkForSameSlotKeys() { + + nativeConnection.zadd(SAME_SLOT_KEY_1, 10D, VALUE_1); + nativeConnection.zadd(SAME_SLOT_KEY_1, 30D, VALUE_3); + nativeConnection.zadd(SAME_SLOT_KEY_2, 20D, VALUE_2); + + clusterConnection.zUnionStore(SAME_SLOT_KEY_3_BYTES, SAME_SLOT_KEY_1_BYTES, SAME_SLOT_KEY_2_BYTES); + + assertThat(nativeConnection.zrange(SAME_SLOT_KEY_3, 0, -1), hasItems(VALUE_1, VALUE_2, VALUE_3)); + } }