DATAREDIS-1233 - Add JUnit 5 extensions.
This commit is contained in:
committed by
Christoph Strobl
parent
7d2e899092
commit
2511aa18c0
@@ -35,10 +35,20 @@ public abstract class ConnectionFactoryTracker {
|
||||
private static Set<Object> connFactories = new LinkedHashSet<>();
|
||||
|
||||
public static void add(RedisConnectionFactory factory) {
|
||||
|
||||
if (factory instanceof Managed) {
|
||||
throw new UnsupportedOperationException("Cannot track managed resource");
|
||||
}
|
||||
|
||||
connFactories.add(factory);
|
||||
}
|
||||
|
||||
public static void add(Object factory) {
|
||||
|
||||
if (factory instanceof Managed) {
|
||||
throw new UnsupportedOperationException("Cannot track managed resource");
|
||||
}
|
||||
|
||||
connFactories.add(factory);
|
||||
}
|
||||
|
||||
@@ -57,4 +67,8 @@ public abstract class ConnectionFactoryTracker {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public interface Managed {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,9 +17,9 @@ package org.springframework.data.redis;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.context.support.GenericXmlApplicationContext;
|
||||
import org.springframework.data.redis.core.RedisOperations;
|
||||
@@ -27,23 +27,23 @@ import org.springframework.data.redis.core.RedisOperations;
|
||||
/**
|
||||
* @author Costin Leau
|
||||
*/
|
||||
public class PropertyEditorsTest {
|
||||
class PropertyEditorsTest {
|
||||
|
||||
private GenericXmlApplicationContext ctx;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
ctx = new GenericXmlApplicationContext("/org/springframework/data/redis/pe.xml");
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
@AfterEach
|
||||
void tearDown() {
|
||||
if (ctx != null)
|
||||
ctx.destroy();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInjection() throws Exception {
|
||||
void testInjection() throws Exception {
|
||||
RedisViewPE bean = ctx.getBean(RedisViewPE.class);
|
||||
RedisOperations<?, ?> ops = ctx.getBean(RedisOperations.class);
|
||||
|
||||
|
||||
@@ -15,8 +15,13 @@
|
||||
*/
|
||||
package org.springframework.data.redis;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.springframework.data.redis.connection.RedisClusterConfiguration;
|
||||
import org.springframework.data.redis.connection.RedisSentinelConfiguration;
|
||||
import org.springframework.data.redis.connection.RedisSocketConfiguration;
|
||||
import org.springframework.data.redis.connection.RedisStandaloneConfiguration;
|
||||
|
||||
@@ -35,6 +40,8 @@ public abstract class SettingsUtils {
|
||||
static {
|
||||
DEFAULTS.put("host", "127.0.0.1");
|
||||
DEFAULTS.put("port", "6379");
|
||||
DEFAULTS.put("clusterPort", "7379");
|
||||
DEFAULTS.put("sentinelPort", "26379");
|
||||
DEFAULTS.put("socket", "work/redis-6379.sock");
|
||||
|
||||
SETTINGS = new Properties(DEFAULTS);
|
||||
@@ -62,6 +69,28 @@ public abstract class SettingsUtils {
|
||||
return Integer.valueOf(SETTINGS.getProperty("port"));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the Redis Cluster port.
|
||||
*/
|
||||
public static int getSentinelPort() {
|
||||
return Integer.valueOf(SETTINGS.getProperty("sentinelPort"));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the Redis Sentinel Master Id.
|
||||
*/
|
||||
public static String getSentinelMaster() {
|
||||
return "mymaster";
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the Redis Cluster port.
|
||||
*/
|
||||
public static int getClusterPort() {
|
||||
return Integer.valueOf(SETTINGS.getProperty("clusterPort"));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return path to the unix domain socket.
|
||||
*/
|
||||
@@ -78,6 +107,27 @@ public abstract class SettingsUtils {
|
||||
return new RedisStandaloneConfiguration(getHost(), getPort());
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a new {@link RedisSentinelConfiguration} initialized with test endpoint settings.
|
||||
*
|
||||
* @return a new {@link RedisSentinelConfiguration} initialized with test endpoint settings.
|
||||
*/
|
||||
public static RedisSentinelConfiguration sentinelConfiguration() {
|
||||
return new RedisSentinelConfiguration(getSentinelMaster(),
|
||||
new HashSet<>(Arrays.asList(String.format("%s:%d", getHost(), getSentinelPort()),
|
||||
String.format("%s:%d", getHost(), getSentinelPort() + 1))));
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a new {@link RedisClusterConfiguration} initialized with test endpoint settings.
|
||||
*
|
||||
* @return a new {@link RedisClusterConfiguration} initialized with test endpoint settings.
|
||||
*/
|
||||
public static RedisClusterConfiguration clusterConfiguration() {
|
||||
return new RedisClusterConfiguration(
|
||||
Collections.singletonList(String.format("%s:%d", getHost(), getClusterPort())));
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a new {@link RedisSocketConfiguration} initialized with test endpoint settings.
|
||||
*
|
||||
@@ -86,4 +136,5 @@ public abstract class SettingsUtils {
|
||||
public static RedisSocketConfiguration socketConfiguration() {
|
||||
return new RedisSocketConfiguration(getSocket());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -15,8 +15,6 @@
|
||||
*/
|
||||
package org.springframework.data.redis.cache;
|
||||
|
||||
import static org.springframework.data.redis.connection.ClusterTestVariables.*;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.experimental.Delegate;
|
||||
|
||||
@@ -27,18 +25,20 @@ import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.junit.runners.model.Statement;
|
||||
|
||||
import org.springframework.data.redis.SettingsUtils;
|
||||
import org.springframework.data.redis.connection.RedisClusterConfiguration;
|
||||
import org.springframework.data.redis.connection.RedisClusterNode;
|
||||
import org.springframework.data.redis.connection.RedisConnectionFactory;
|
||||
import org.springframework.data.redis.connection.RedisStandaloneConfiguration;
|
||||
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
|
||||
import org.springframework.data.redis.connection.jedis.extension.JedisConnectionFactoryExtension;
|
||||
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
|
||||
import org.springframework.data.redis.connection.lettuce.LettuceTestClientResources;
|
||||
import org.springframework.data.redis.connection.lettuce.extension.LettuceConnectionFactoryExtension;
|
||||
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
|
||||
import org.springframework.data.redis.serializer.JdkSerializationRedisSerializer;
|
||||
import org.springframework.data.redis.serializer.OxmSerializer;
|
||||
import org.springframework.data.redis.serializer.RedisSerializer;
|
||||
import org.springframework.data.redis.test.extension.RedisCluster;
|
||||
import org.springframework.data.redis.test.extension.RedisStanalone;
|
||||
import org.springframework.data.redis.test.util.RedisClusterRule;
|
||||
import org.springframework.oxm.xstream.XStreamMarshaller;
|
||||
import org.springframework.util.StringUtils;
|
||||
@@ -57,32 +57,27 @@ class CacheTestParams {
|
||||
List<RedisConnectionFactory> factoryList = new ArrayList<>(3);
|
||||
|
||||
// Jedis Standalone
|
||||
JedisConnectionFactory jedisConnectionFactory = new JedisConnectionFactory(config);
|
||||
jedisConnectionFactory.afterPropertiesSet();
|
||||
JedisConnectionFactory jedisConnectionFactory = JedisConnectionFactoryExtension
|
||||
.getConnectionFactory(RedisStanalone.class);
|
||||
factoryList.add(new FixDamnedJunitParameterizedNameForConnectionFactory(jedisConnectionFactory, ""));
|
||||
|
||||
// Lettuce Standalone
|
||||
LettuceConnectionFactory lettuceConnectionFactory = new LettuceConnectionFactory(config);
|
||||
lettuceConnectionFactory.setClientResources(LettuceTestClientResources.getSharedClientResources());
|
||||
lettuceConnectionFactory.afterPropertiesSet();
|
||||
LettuceConnectionFactory lettuceConnectionFactory = LettuceConnectionFactoryExtension
|
||||
.getConnectionFactory(RedisStanalone.class);
|
||||
factoryList.add(new FixDamnedJunitParameterizedNameForConnectionFactory(lettuceConnectionFactory, ""));
|
||||
|
||||
if (clusterAvailable()) {
|
||||
|
||||
RedisClusterConfiguration clusterConfiguration = new RedisClusterConfiguration();
|
||||
clusterConfiguration.addClusterNode(new RedisClusterNode(CLUSTER_HOST, MASTER_NODE_1_PORT));
|
||||
|
||||
// Jedis Cluster
|
||||
JedisConnectionFactory jedisClusterConnectionFactory = new JedisConnectionFactory(clusterConfiguration);
|
||||
jedisClusterConnectionFactory.afterPropertiesSet();
|
||||
JedisConnectionFactory jedisClusterConnectionFactory = JedisConnectionFactoryExtension
|
||||
.getConnectionFactory(RedisCluster.class);
|
||||
factoryList
|
||||
.add(new FixDamnedJunitParameterizedNameForConnectionFactory(jedisClusterConnectionFactory, "cluster"));
|
||||
|
||||
// Lettuce Cluster
|
||||
LettuceConnectionFactory lettuceClusterConnectionFactory = new LettuceConnectionFactory(clusterConfiguration);
|
||||
lettuceClusterConnectionFactory.setClientResources(LettuceTestClientResources.getSharedClientResources());
|
||||
lettuceClusterConnectionFactory.afterPropertiesSet();
|
||||
|
||||
LettuceConnectionFactory lettuceClusterConnectionFactory = LettuceConnectionFactoryExtension
|
||||
.getConnectionFactory(RedisCluster.class);
|
||||
factoryList
|
||||
.add(new FixDamnedJunitParameterizedNameForConnectionFactory(lettuceClusterConnectionFactory, "cluster"));
|
||||
}
|
||||
|
||||
@@ -27,18 +27,19 @@ import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
import org.junit.runners.Parameterized.Parameters;
|
||||
import org.springframework.data.redis.ConnectionFactoryTracker;
|
||||
|
||||
import org.springframework.data.redis.connection.RedisConnection;
|
||||
import org.springframework.data.redis.connection.RedisConnectionFactory;
|
||||
import org.springframework.data.redis.connection.RedisStringCommands.SetOption;
|
||||
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
|
||||
import org.springframework.data.redis.connection.jedis.extension.JedisConnectionFactoryExtension;
|
||||
import org.springframework.data.redis.core.types.Expiration;
|
||||
import org.springframework.data.redis.test.extension.RedisStanalone;
|
||||
|
||||
/**
|
||||
* Integration tests for {@link DefaultRedisCacheWriter}.
|
||||
@@ -60,10 +61,7 @@ public class DefaultRedisCacheWriterTests {
|
||||
RedisConnectionFactory connectionFactory;
|
||||
|
||||
public DefaultRedisCacheWriterTests(RedisConnectionFactory connectionFactory) {
|
||||
|
||||
this.connectionFactory = connectionFactory;
|
||||
|
||||
ConnectionFactoryTracker.add(connectionFactory);
|
||||
}
|
||||
|
||||
@Parameters(name = "{index}: {0}")
|
||||
@@ -71,16 +69,10 @@ public class DefaultRedisCacheWriterTests {
|
||||
return CacheTestParams.justConnectionFactories();
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void cleanUpResources() {
|
||||
ConnectionFactoryTracker.cleanUp();
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
|
||||
JedisConnectionFactory cf = new JedisConnectionFactory();
|
||||
cf.afterPropertiesSet();
|
||||
JedisConnectionFactory cf = JedisConnectionFactoryExtension.getConnectionFactory(RedisStanalone.class);
|
||||
|
||||
connectionFactory = cf;
|
||||
|
||||
|
||||
@@ -72,7 +72,6 @@ public class LegacyRedisCacheTests {
|
||||
this.keyFactory = keyFactory;
|
||||
this.valueFactory = valueFactory;
|
||||
this.allowCacheNullValues = allowCacheNullValues;
|
||||
ConnectionFactoryTracker.add(connectionFactory);
|
||||
|
||||
cache = createCache();
|
||||
}
|
||||
@@ -98,11 +97,6 @@ public class LegacyRedisCacheTests {
|
||||
return target;
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void cleanUp() {
|
||||
ConnectionFactoryTracker.cleanUp();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private RedisCache createCache() {
|
||||
|
||||
|
||||
@@ -15,9 +15,10 @@
|
||||
*/
|
||||
package org.springframework.data.redis.cache;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.DirectFieldAccessor;
|
||||
import org.springframework.core.convert.converter.Converter;
|
||||
import org.springframework.instrument.classloading.ShadowingClassLoader;
|
||||
@@ -28,10 +29,10 @@ import org.springframework.lang.Nullable;
|
||||
*
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
public class RedisCacheConfigurationUnitTests {
|
||||
class RedisCacheConfigurationUnitTests {
|
||||
|
||||
@Test // DATAREDIS-763
|
||||
public void shouldSetClassLoader() {
|
||||
void shouldSetClassLoader() {
|
||||
|
||||
ShadowingClassLoader classLoader = new ShadowingClassLoader(getClass().getClassLoader());
|
||||
|
||||
@@ -47,7 +48,7 @@ public class RedisCacheConfigurationUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-1032
|
||||
public void shouldAllowConverterRegistration() {
|
||||
void shouldAllowConverterRegistration() {
|
||||
|
||||
RedisCacheConfiguration config = RedisCacheConfiguration.defaultCacheConfig();
|
||||
config.configureKeyConverters(registry -> registry.addConverter(new DomainTypeConverter()));
|
||||
|
||||
@@ -83,11 +83,6 @@ public class RedisCacheTests {
|
||||
return CacheTestParams.connectionFactoriesAndSerializers();
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void cleanUpResources() {
|
||||
ConnectionFactoryTracker.cleanUp();
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
|
||||
|
||||
@@ -17,24 +17,19 @@ package org.springframework.data.redis.config;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
import org.springframework.data.redis.listener.RedisMessageListenerContainer;
|
||||
import org.springframework.data.redis.test.util.RelaxedJUnit4ClassRunner;
|
||||
import org.springframework.test.annotation.ProfileValueSourceConfiguration;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
|
||||
|
||||
/**
|
||||
* @author Costin Leau
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
@RunWith(RelaxedJUnit4ClassRunner.class)
|
||||
@ContextConfiguration("namespace.xml")
|
||||
@ProfileValueSourceConfiguration
|
||||
public class NamespaceTest {
|
||||
@SpringJUnitConfig(locations = "namespace.xml")
|
||||
class NamespaceIntegrationTests {
|
||||
|
||||
@Autowired private RedisMessageListenerContainer container;
|
||||
|
||||
@@ -43,12 +38,12 @@ public class NamespaceTest {
|
||||
@Autowired private StubErrorHandler handler;
|
||||
|
||||
@Test
|
||||
public void testSanityTest() throws Exception {
|
||||
void testSanityTest() throws Exception {
|
||||
assertThat(container.isRunning()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWithMessages() throws Exception {
|
||||
void testWithMessages() throws Exception {
|
||||
template.convertAndSend("x1", "[X]test");
|
||||
template.convertAndSend("z1", "[Z]test");
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -15,9 +15,10 @@
|
||||
*/
|
||||
package org.springframework.data.redis.connection;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.data.redis.connection.BitFieldSubCommands.BitFieldType;
|
||||
|
||||
@@ -26,10 +27,10 @@ import org.springframework.data.redis.connection.BitFieldSubCommands.BitFieldTyp
|
||||
*
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
public class BitFieldSubCommandsUnitTests {
|
||||
class BitFieldSubCommandsUnitTests {
|
||||
|
||||
@Test // DATAREDIS-971
|
||||
public void shouldCreateSignedBitFieldType() {
|
||||
void shouldCreateSignedBitFieldType() {
|
||||
|
||||
BitFieldType type = BitFieldType.signed(10);
|
||||
|
||||
@@ -38,7 +39,7 @@ public class BitFieldSubCommandsUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-971
|
||||
public void shouldCreateUnsignedBitFieldType() {
|
||||
void shouldCreateUnsignedBitFieldType() {
|
||||
|
||||
BitFieldType type = BitFieldType.unsigned(10);
|
||||
|
||||
|
||||
@@ -22,16 +22,20 @@ import static org.springframework.data.redis.test.util.MockitoUtils.*;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import org.springframework.core.convert.converter.Converter;
|
||||
import org.springframework.core.task.AsyncTaskExecutor;
|
||||
import org.springframework.core.task.SyncTaskExecutor;
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.dao.InvalidDataAccessApiUsageException;
|
||||
@@ -50,33 +54,33 @@ import org.springframework.scheduling.concurrent.ConcurrentTaskExecutor;
|
||||
* @author Christoph Strobl
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class ClusterCommandExecutorUnitTests {
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class ClusterCommandExecutorUnitTests {
|
||||
|
||||
static final String CLUSTER_NODE_1_HOST = "127.0.0.1";
|
||||
static final String CLUSTER_NODE_2_HOST = "127.0.0.1";
|
||||
static final String CLUSTER_NODE_3_HOST = "127.0.0.1";
|
||||
private static final String CLUSTER_NODE_1_HOST = "127.0.0.1";
|
||||
private static final String CLUSTER_NODE_2_HOST = "127.0.0.1";
|
||||
private static final String CLUSTER_NODE_3_HOST = "127.0.0.1";
|
||||
|
||||
static final int CLUSTER_NODE_1_PORT = 7379;
|
||||
static final int CLUSTER_NODE_2_PORT = 7380;
|
||||
static final int CLUSTER_NODE_3_PORT = 7381;
|
||||
private static final int CLUSTER_NODE_1_PORT = 7379;
|
||||
private static final int CLUSTER_NODE_2_PORT = 7380;
|
||||
private static final int CLUSTER_NODE_3_PORT = 7381;
|
||||
|
||||
static final RedisClusterNode CLUSTER_NODE_1 = RedisClusterNode.newRedisClusterNode()
|
||||
private static final RedisClusterNode CLUSTER_NODE_1 = RedisClusterNode.newRedisClusterNode()
|
||||
.listeningAt(CLUSTER_NODE_1_HOST, CLUSTER_NODE_1_PORT).serving(new SlotRange(0, 5460))
|
||||
.withId("ef570f86c7b1a953846668debc177a3a16733420").promotedAs(NodeType.MASTER).linkState(LinkState.CONNECTED)
|
||||
.build();
|
||||
static final RedisClusterNode CLUSTER_NODE_2 = RedisClusterNode.newRedisClusterNode()
|
||||
private static final RedisClusterNode CLUSTER_NODE_2 = RedisClusterNode.newRedisClusterNode()
|
||||
.listeningAt(CLUSTER_NODE_2_HOST, CLUSTER_NODE_2_PORT).serving(new SlotRange(5461, 10922))
|
||||
.withId("0f2ee5df45d18c50aca07228cc18b1da96fd5e84").promotedAs(NodeType.MASTER).linkState(LinkState.CONNECTED)
|
||||
.build();
|
||||
static final RedisClusterNode CLUSTER_NODE_3 = RedisClusterNode.newRedisClusterNode()
|
||||
private static final RedisClusterNode CLUSTER_NODE_3 = RedisClusterNode.newRedisClusterNode()
|
||||
.listeningAt(CLUSTER_NODE_3_HOST, CLUSTER_NODE_3_PORT).serving(new SlotRange(10923, 16383))
|
||||
.withId("3b9b8192a874fa8f1f09dbc0ee20afab5738eee7").promotedAs(NodeType.MASTER).linkState(LinkState.CONNECTED)
|
||||
.build();
|
||||
static final RedisClusterNode CLUSTER_NODE_2_LOOKUP = RedisClusterNode.newRedisClusterNode()
|
||||
private static final RedisClusterNode CLUSTER_NODE_2_LOOKUP = RedisClusterNode.newRedisClusterNode()
|
||||
.withId("0f2ee5df45d18c50aca07228cc18b1da96fd5e84").build();
|
||||
|
||||
static final RedisClusterNode UNKNOWN_CLUSTER_NODE = new RedisClusterNode("8.8.8.8", 7379, SlotRange.empty());
|
||||
private static final RedisClusterNode UNKNOWN_CLUSTER_NODE = new RedisClusterNode("8.8.8.8", 7379, SlotRange.empty());
|
||||
|
||||
private ClusterCommandExecutor executor;
|
||||
|
||||
@@ -97,20 +101,20 @@ public class ClusterCommandExecutorUnitTests {
|
||||
@Mock Connection con2;
|
||||
@Mock Connection con3;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
|
||||
this.executor = new ClusterCommandExecutor(new MockClusterNodeProvider(), new MockClusterResourceProvider(),
|
||||
new PassThroughExceptionTranslationStrategy(exceptionConverter));
|
||||
new PassThroughExceptionTranslationStrategy(exceptionConverter), new ImmediateExecutor());
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
@AfterEach
|
||||
void tearDown() throws Exception {
|
||||
this.executor.destroy();
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-315
|
||||
public void executeCommandOnSingleNodeShouldBeExecutedCorrectly() {
|
||||
void executeCommandOnSingleNodeShouldBeExecutedCorrectly() {
|
||||
|
||||
executor.executeCommandOnSingleNode(COMMAND_CALLBACK, CLUSTER_NODE_2);
|
||||
|
||||
@@ -118,7 +122,7 @@ public class ClusterCommandExecutorUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-315
|
||||
public void executeCommandOnSingleNodeByHostAndPortShouldBeExecutedCorrectly() {
|
||||
void executeCommandOnSingleNodeByHostAndPortShouldBeExecutedCorrectly() {
|
||||
|
||||
executor.executeCommandOnSingleNode(COMMAND_CALLBACK,
|
||||
new RedisClusterNode(CLUSTER_NODE_2_HOST, CLUSTER_NODE_2_PORT));
|
||||
@@ -127,7 +131,7 @@ public class ClusterCommandExecutorUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-315
|
||||
public void executeCommandOnSingleNodeByNodeIdShouldBeExecutedCorrectly() {
|
||||
void executeCommandOnSingleNodeByNodeIdShouldBeExecutedCorrectly() {
|
||||
|
||||
executor.executeCommandOnSingleNode(COMMAND_CALLBACK, new RedisClusterNode(CLUSTER_NODE_2.id));
|
||||
|
||||
@@ -135,23 +139,23 @@ public class ClusterCommandExecutorUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-315
|
||||
public void executeCommandOnSingleNodeShouldThrowExceptionWhenNodeIsNull() {
|
||||
void executeCommandOnSingleNodeShouldThrowExceptionWhenNodeIsNull() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> executor.executeCommandOnSingleNode(COMMAND_CALLBACK, null));
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-315
|
||||
public void executeCommandOnSingleNodeShouldThrowExceptionWhenCommandCallbackIsNull() {
|
||||
void executeCommandOnSingleNodeShouldThrowExceptionWhenCommandCallbackIsNull() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> executor.executeCommandOnSingleNode(null, CLUSTER_NODE_1));
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-315
|
||||
public void executeCommandOnSingleNodeShouldThrowExceptionWhenNodeIsUnknown() {
|
||||
void executeCommandOnSingleNodeShouldThrowExceptionWhenNodeIsUnknown() {
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> executor.executeCommandOnSingleNode(COMMAND_CALLBACK, UNKNOWN_CLUSTER_NODE));
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-315
|
||||
public void executeCommandAsyncOnNodesShouldExecuteCommandOnGivenNodes() {
|
||||
void executeCommandAsyncOnNodesShouldExecuteCommandOnGivenNodes() {
|
||||
|
||||
ClusterCommandExecutor executor = new ClusterCommandExecutor(new MockClusterNodeProvider(),
|
||||
new MockClusterResourceProvider(), new PassThroughExceptionTranslationStrategy(exceptionConverter),
|
||||
@@ -165,7 +169,7 @@ public class ClusterCommandExecutorUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-315
|
||||
public void executeCommandAsyncOnNodesShouldExecuteCommandOnGivenNodesByHostAndPort() {
|
||||
void executeCommandAsyncOnNodesShouldExecuteCommandOnGivenNodesByHostAndPort() {
|
||||
|
||||
ClusterCommandExecutor executor = new ClusterCommandExecutor(new MockClusterNodeProvider(),
|
||||
new MockClusterResourceProvider(), new PassThroughExceptionTranslationStrategy(exceptionConverter),
|
||||
@@ -181,7 +185,7 @@ public class ClusterCommandExecutorUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-315
|
||||
public void executeCommandAsyncOnNodesShouldExecuteCommandOnGivenNodesByNodeId() {
|
||||
void executeCommandAsyncOnNodesShouldExecuteCommandOnGivenNodesByNodeId() {
|
||||
|
||||
ClusterCommandExecutor executor = new ClusterCommandExecutor(new MockClusterNodeProvider(),
|
||||
new MockClusterResourceProvider(), new PassThroughExceptionTranslationStrategy(exceptionConverter),
|
||||
@@ -195,19 +199,19 @@ public class ClusterCommandExecutorUnitTests {
|
||||
verify(con3, never()).theWheelWeavesAsTheWheelWills();
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class) // DATAREDIS-315
|
||||
public void executeCommandAsyncOnNodesShouldFailOnGivenUnknownNodes() {
|
||||
@Test // DATAREDIS-315
|
||||
void executeCommandAsyncOnNodesShouldFailOnGivenUnknownNodes() {
|
||||
|
||||
ClusterCommandExecutor executor = new ClusterCommandExecutor(new MockClusterNodeProvider(),
|
||||
new MockClusterResourceProvider(), new PassThroughExceptionTranslationStrategy(exceptionConverter),
|
||||
new ConcurrentTaskExecutor(new SyncTaskExecutor()));
|
||||
|
||||
executor.executeCommandAsyncOnNodes(COMMAND_CALLBACK,
|
||||
Arrays.asList(new RedisClusterNode("unknown"), CLUSTER_NODE_2_LOOKUP));
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> executor.executeCommandAsyncOnNodes(COMMAND_CALLBACK,
|
||||
Arrays.asList(new RedisClusterNode("unknown"), CLUSTER_NODE_2_LOOKUP)));
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-315
|
||||
public void executeCommandOnAllNodesShouldExecuteCommandOnEveryKnownClusterNode() {
|
||||
void executeCommandOnAllNodesShouldExecuteCommandOnEveryKnownClusterNode() {
|
||||
|
||||
ClusterCommandExecutor executor = new ClusterCommandExecutor(new MockClusterNodeProvider(),
|
||||
new MockClusterResourceProvider(), new PassThroughExceptionTranslationStrategy(exceptionConverter),
|
||||
@@ -221,7 +225,7 @@ public class ClusterCommandExecutorUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-315
|
||||
public void executeCommandAsyncOnNodesShouldCompleteAndCollectErrorsOfAllNodes() {
|
||||
void executeCommandAsyncOnNodesShouldCompleteAndCollectErrorsOfAllNodes() {
|
||||
|
||||
when(con1.theWheelWeavesAsTheWheelWills()).thenReturn("rand");
|
||||
when(con2.theWheelWeavesAsTheWheelWills()).thenThrow(new IllegalStateException("(error) mat lost the dagger..."));
|
||||
@@ -241,7 +245,7 @@ public class ClusterCommandExecutorUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-315
|
||||
public void executeCommandAsyncOnNodesShouldCollectResultsCorrectly() {
|
||||
void executeCommandAsyncOnNodesShouldCollectResultsCorrectly() {
|
||||
|
||||
when(con1.theWheelWeavesAsTheWheelWills()).thenReturn("rand");
|
||||
when(con2.theWheelWeavesAsTheWheelWills()).thenReturn("mat");
|
||||
@@ -253,7 +257,7 @@ public class ClusterCommandExecutorUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-315, DATAREDIS-467
|
||||
public void executeMultikeyCommandShouldRunCommandAcrossCluster() {
|
||||
void executeMultikeyCommandShouldRunCommandAcrossCluster() {
|
||||
|
||||
// key-1 and key-9 map both to node1
|
||||
ArgumentCaptor<byte[]> captor = ArgumentCaptor.forClass(byte[].class);
|
||||
@@ -273,7 +277,7 @@ public class ClusterCommandExecutorUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-315
|
||||
public void executeCommandOnSingleNodeAndFollowRedirect() {
|
||||
void executeCommandOnSingleNodeAndFollowRedirect() {
|
||||
|
||||
when(con1.theWheelWeavesAsTheWheelWills()).thenThrow(new MovedException(CLUSTER_NODE_3_HOST, CLUSTER_NODE_3_PORT));
|
||||
|
||||
@@ -285,7 +289,7 @@ public class ClusterCommandExecutorUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-315
|
||||
public void executeCommandOnSingleNodeAndFollowRedirectButStopsAfterMaxRedirects() {
|
||||
void executeCommandOnSingleNodeAndFollowRedirectButStopsAfterMaxRedirects() {
|
||||
|
||||
when(con1.theWheelWeavesAsTheWheelWills()).thenThrow(new MovedException(CLUSTER_NODE_3_HOST, CLUSTER_NODE_3_PORT));
|
||||
when(con3.theWheelWeavesAsTheWheelWills()).thenThrow(new MovedException(CLUSTER_NODE_2_HOST, CLUSTER_NODE_2_PORT));
|
||||
@@ -304,7 +308,7 @@ public class ClusterCommandExecutorUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-315
|
||||
public void executeCommandOnArbitraryNodeShouldPickARandomNode() {
|
||||
void executeCommandOnArbitraryNodeShouldPickARandomNode() {
|
||||
|
||||
executor.executeCommandOnArbitraryNode(COMMAND_CALLBACK);
|
||||
|
||||
@@ -366,11 +370,44 @@ public class ClusterCommandExecutorUnitTests {
|
||||
String host;
|
||||
int port;
|
||||
|
||||
public MovedException(String host, int port) {
|
||||
MovedException(String host, int port) {
|
||||
this.host = host;
|
||||
this.port = port;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static class ImmediateExecutor implements AsyncTaskExecutor {
|
||||
|
||||
@Override
|
||||
public void execute(Runnable runnable, long l) {
|
||||
runnable.run();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Future<?> submit(Runnable runnable) {
|
||||
return submit(() -> {
|
||||
runnable.run();
|
||||
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> Future<T> submit(Callable<T> callable) {
|
||||
try {
|
||||
return CompletableFuture.completedFuture(callable.call());
|
||||
} catch (Exception e) {
|
||||
|
||||
CompletableFuture<T> future = new CompletableFuture<>();
|
||||
future.completeExceptionally(e);
|
||||
return future;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(Runnable runnable) {
|
||||
runnable.run();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,97 +17,82 @@ package org.springframework.data.redis.connection;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import redis.clients.jedis.HostAndPort;
|
||||
import redis.clients.jedis.Jedis;
|
||||
import redis.clients.jedis.JedisCluster;
|
||||
import redis.clients.jedis.JedisPool;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
import java.util.Random;
|
||||
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
|
||||
import org.springframework.data.redis.test.util.RedisClusterRule;
|
||||
import org.springframework.data.redis.test.condition.EnabledOnRedisClusterAvailable;
|
||||
import org.springframework.data.redis.test.extension.JedisExtension;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* @author Christoph Strobl
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
@EnabledOnRedisClusterAvailable
|
||||
@ExtendWith(JedisExtension.class)
|
||||
public class ClusterSlotHashUtilsTests {
|
||||
|
||||
public static @ClassRule RedisClusterRule requiresCluster = new RedisClusterRule();
|
||||
|
||||
@Test
|
||||
public void localCalculationShoudMatchServers() throws IOException {
|
||||
|
||||
JedisCluster cluster = null;
|
||||
try {
|
||||
cluster = new JedisCluster(Collections.singleton(new HostAndPort("127.0.0.1", 7379)));
|
||||
|
||||
JedisPool pool = cluster.getClusterNodes().values().iterator().next();
|
||||
Jedis jedis = pool.getResource();
|
||||
for (int i = 0; i < 10000; i++) {
|
||||
|
||||
String key = randomString();
|
||||
int slot = ClusterSlotHashUtil.calculateSlot(key);
|
||||
Long serverSlot = jedis.clusterKeySlot(key);
|
||||
|
||||
assertThat(slot)
|
||||
.as(String.format("Expected slot for key '%s' to be %s but server calculated %s.", key, slot, serverSlot))
|
||||
.isEqualTo(serverSlot.intValue());
|
||||
|
||||
}
|
||||
jedis.close();
|
||||
} finally {
|
||||
if (cluster != null) {
|
||||
cluster.close();
|
||||
}
|
||||
}
|
||||
private final JedisCluster cluster;
|
||||
|
||||
public ClusterSlotHashUtilsTests(JedisCluster cluster) {
|
||||
this.cluster = cluster;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void localCalculationShoudMatchServersForPrefixedKeys() throws IOException {
|
||||
void localCalculationShouldMatchServers() {
|
||||
|
||||
JedisCluster cluster = null;
|
||||
try {
|
||||
cluster = new JedisCluster(Collections.singleton(new HostAndPort("127.0.0.1", 7379)));
|
||||
JedisPool pool = cluster.getClusterNodes().values().iterator().next();
|
||||
Jedis jedis = pool.getResource();
|
||||
for (int i = 0; i < 100; i++) {
|
||||
|
||||
JedisPool pool = cluster.getClusterNodes().values().iterator().next();
|
||||
Jedis jedis = pool.getResource();
|
||||
for (int i = 0; i < 10000; i++) {
|
||||
String key = randomString();
|
||||
int slot = ClusterSlotHashUtil.calculateSlot(key);
|
||||
Long serverSlot = jedis.clusterKeySlot(key);
|
||||
|
||||
String slotPrefix = "{" + randomString() + "}";
|
||||
assertThat(slot)
|
||||
.as(String.format("Expected slot for key '%s' to be %s but server calculated %s.", key, slot, serverSlot))
|
||||
.isEqualTo(serverSlot.intValue());
|
||||
|
||||
String key1 = slotPrefix + "." + randomString();
|
||||
String key2 = slotPrefix + "." + randomString();
|
||||
|
||||
int slot1 = ClusterSlotHashUtil.calculateSlot(key1);
|
||||
int slot2 = ClusterSlotHashUtil.calculateSlot(key2);
|
||||
|
||||
assertThat(slot2).as(String.format("Expected slot for prefixed keys '%s' and '%s' to be %s but was %s.", key1,
|
||||
key2, slot1, slot2)).isEqualTo(slot1);
|
||||
|
||||
Long serverSlot1 = jedis.clusterKeySlot(key1);
|
||||
Long serverSlot2 = jedis.clusterKeySlot(key2);
|
||||
|
||||
assertThat(slot1).as(
|
||||
String.format("Expected slot for key '%s' to be %s but server calculated %s.", key1, slot1, serverSlot1))
|
||||
.isEqualTo(serverSlot1.intValue());
|
||||
assertThat(slot1).as(
|
||||
String.format("Expected slot for key '%s' to be %s but server calculated %s.", key2, slot2, serverSlot2))
|
||||
.isEqualTo(serverSlot1.intValue());
|
||||
|
||||
}
|
||||
jedis.close();
|
||||
} finally {
|
||||
if (cluster != null) {
|
||||
cluster.close();
|
||||
}
|
||||
}
|
||||
jedis.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
void localCalculationShoudMatchServersForPrefixedKeys() {
|
||||
|
||||
JedisPool pool = cluster.getClusterNodes().values().iterator().next();
|
||||
Jedis jedis = pool.getResource();
|
||||
for (int i = 0; i < 100; i++) {
|
||||
|
||||
String slotPrefix = "{" + randomString() + "}";
|
||||
|
||||
String key1 = slotPrefix + "." + randomString();
|
||||
String key2 = slotPrefix + "." + randomString();
|
||||
|
||||
int slot1 = ClusterSlotHashUtil.calculateSlot(key1);
|
||||
int slot2 = ClusterSlotHashUtil.calculateSlot(key2);
|
||||
|
||||
assertThat(slot2).as(String.format("Expected slot for prefixed keys '%s' and '%s' to be %s but was %s.", key1,
|
||||
key2, slot1, slot2)).isEqualTo(slot1);
|
||||
|
||||
Long serverSlot1 = jedis.clusterKeySlot(key1);
|
||||
Long serverSlot2 = jedis.clusterKeySlot(key2);
|
||||
|
||||
assertThat(slot1)
|
||||
.as(String.format("Expected slot for key '%s' to be %s but server calculated %s.", key1, slot1, serverSlot1))
|
||||
.isEqualTo(serverSlot1.intValue());
|
||||
assertThat(slot1)
|
||||
.as(String.format("Expected slot for key '%s' to be %s but server calculated %s.", key2, slot2, serverSlot2))
|
||||
.isEqualTo(serverSlot1.intValue());
|
||||
|
||||
}
|
||||
jedis.close();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -25,8 +25,9 @@ import java.util.Properties;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.data.geo.Circle;
|
||||
import org.springframework.data.geo.Distance;
|
||||
@@ -47,14 +48,14 @@ import org.springframework.util.ObjectUtils;
|
||||
* @author Ninad Divadkar
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
public class RedisConnectionUnitTests {
|
||||
class RedisConnectionUnitTests {
|
||||
|
||||
private final RedisNode SENTINEL_1 = new RedisNodeBuilder().listeningAt("localhost", 23679).build();
|
||||
private AbstractDelegatingRedisConnectionStub connection;
|
||||
private RedisSentinelConnection sentinelConnectionMock;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
sentinelConnectionMock = mock(RedisSentinelConnection.class);
|
||||
|
||||
connection = new AbstractDelegatingRedisConnectionStub(mock(AbstractRedisConnection.class, CALLS_REAL_METHODS));
|
||||
@@ -63,7 +64,7 @@ public class RedisConnectionUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-330
|
||||
public void shouldCloseSentinelConnectionAlongWithRedisConnection() throws IOException {
|
||||
void shouldCloseSentinelConnectionAlongWithRedisConnection() throws IOException {
|
||||
|
||||
when(sentinelConnectionMock.isOpen()).thenReturn(true).thenReturn(false);
|
||||
|
||||
@@ -75,7 +76,7 @@ public class RedisConnectionUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-330
|
||||
public void shouldNotTryToCloseSentinelConnectionsWhenAlreadyClosed() throws IOException {
|
||||
void shouldNotTryToCloseSentinelConnectionsWhenAlreadyClosed() throws IOException {
|
||||
|
||||
when(sentinelConnectionMock.isOpen()).thenReturn(true);
|
||||
when(sentinelConnectionMock.isOpen()).thenReturn(false);
|
||||
@@ -93,7 +94,7 @@ public class RedisConnectionUnitTests {
|
||||
RedisNode activeNode;
|
||||
RedisSentinelConnection sentinelConnection;
|
||||
|
||||
public AbstractDelegatingRedisConnectionStub(RedisConnection delegate) {
|
||||
AbstractDelegatingRedisConnectionStub(RedisConnection delegate) {
|
||||
this.delegate = delegate;
|
||||
}
|
||||
|
||||
@@ -102,11 +103,11 @@ public class RedisConnectionUnitTests {
|
||||
return ObjectUtils.nullSafeEquals(activeNode, node);
|
||||
}
|
||||
|
||||
public void setActiveNode(RedisNode activeNode) {
|
||||
void setActiveNode(RedisNode activeNode) {
|
||||
this.activeNode = activeNode;
|
||||
}
|
||||
|
||||
public void setSentinelConnection(RedisSentinelConnection sentinelConnection) {
|
||||
void setSentinelConnection(RedisSentinelConnection sentinelConnection) {
|
||||
this.sentinelConnection = sentinelConnection;
|
||||
}
|
||||
|
||||
|
||||
@@ -17,17 +17,17 @@ package org.springframework.data.redis.connection;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link RedisStaticMasterReplicaConfiguration}.
|
||||
*
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
public class RedisElastiCacheConfigurationUnitTests {
|
||||
class RedisElastiCacheConfigurationUnitTests {
|
||||
|
||||
@Test // DATAREDIS-762
|
||||
public void shouldCreateSingleHostConfiguration() {
|
||||
void shouldCreateSingleHostConfiguration() {
|
||||
|
||||
RedisStaticMasterReplicaConfiguration singleHost = new RedisStaticMasterReplicaConfiguration("localhost");
|
||||
|
||||
@@ -40,7 +40,7 @@ public class RedisElastiCacheConfigurationUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-762
|
||||
public void shouldCreateMultiHostConfiguration() {
|
||||
void shouldCreateMultiHostConfiguration() {
|
||||
|
||||
RedisStaticMasterReplicaConfiguration multiHost = new RedisStaticMasterReplicaConfiguration("localhost");
|
||||
multiHost.node("other-host", 6479);
|
||||
@@ -59,7 +59,7 @@ public class RedisElastiCacheConfigurationUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-762
|
||||
public void shouldApplyPasswordToNodes() {
|
||||
void shouldApplyPasswordToNodes() {
|
||||
|
||||
RedisStaticMasterReplicaConfiguration multiHost = new RedisStaticMasterReplicaConfiguration("localhost").node("other-host", 6479);
|
||||
|
||||
@@ -71,7 +71,7 @@ public class RedisElastiCacheConfigurationUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-762
|
||||
public void shouldApplyDatabaseToNodes() {
|
||||
void shouldApplyDatabaseToNodes() {
|
||||
|
||||
RedisStaticMasterReplicaConfiguration multiHost = new RedisStaticMasterReplicaConfiguration("localhost").node("other-host", 6479);
|
||||
|
||||
|
||||
@@ -15,9 +15,10 @@
|
||||
*/
|
||||
package org.springframework.data.redis.connection;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link RedisPassword}.
|
||||
@@ -25,30 +26,30 @@ import org.junit.Test;
|
||||
* @author Mark Paluch
|
||||
* @author Christoph Strobl
|
||||
*/
|
||||
public class RedisPasswordUnitTests {
|
||||
class RedisPasswordUnitTests {
|
||||
|
||||
@Test // DATAREDIS-574
|
||||
public void shouldCreateFromEmptyString() {
|
||||
void shouldCreateFromEmptyString() {
|
||||
assertThat(RedisPassword.of("").toOptional()).isEmpty();
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-574
|
||||
public void shouldCreateFromExistingString() {
|
||||
void shouldCreateFromExistingString() {
|
||||
assertThat(RedisPassword.of("foo").map(String::new)).contains("foo");
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-574
|
||||
public void shouldCreateFromEmptyCharArray() {
|
||||
void shouldCreateFromEmptyCharArray() {
|
||||
assertThat(RedisPassword.of("".toCharArray()).toOptional()).isEmpty();
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-574
|
||||
public void shouldCreateFromExistingCharArray() {
|
||||
void shouldCreateFromExistingCharArray() {
|
||||
assertThat(RedisPassword.of("foo".toCharArray()).map(String::new)).contains("foo");
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-574
|
||||
public void toStringShouldHideValue() {
|
||||
void toStringShouldHideValue() {
|
||||
assertThat(RedisPassword.of("foo".toCharArray()).toString()).startsWith("RedisPassword[**").doesNotContain("foo");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,8 @@ import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.core.env.PropertySource;
|
||||
import org.springframework.mock.env.MockPropertySource;
|
||||
import org.springframework.util.StringUtils;
|
||||
@@ -29,70 +30,70 @@ import org.springframework.util.StringUtils;
|
||||
/**
|
||||
* @author Christoph Strobl
|
||||
*/
|
||||
public class RedisSentinelConfigurationUnitTests {
|
||||
class RedisSentinelConfigurationUnitTests {
|
||||
|
||||
static final String HOST_AND_PORT_1 = "127.0.0.1:123";
|
||||
static final String HOST_AND_PORT_2 = "localhost:456";
|
||||
static final String HOST_AND_PORT_3 = "localhost:789";
|
||||
static final String HOST_AND_NO_PORT = "localhost";
|
||||
private static final String HOST_AND_PORT_1 = "127.0.0.1:123";
|
||||
private static final String HOST_AND_PORT_2 = "localhost:456";
|
||||
private static final String HOST_AND_PORT_3 = "localhost:789";
|
||||
private static final String HOST_AND_NO_PORT = "localhost";
|
||||
|
||||
@Test // DATAREDIS-372
|
||||
public void shouldCreateRedisSentinelConfigurationCorrectlyGivenMasterAndSingleHostAndPortString() {
|
||||
void shouldCreateRedisSentinelConfigurationCorrectlyGivenMasterAndSingleHostAndPortString() {
|
||||
|
||||
RedisSentinelConfiguration config = new RedisSentinelConfiguration("mymaster",
|
||||
Collections.singleton(HOST_AND_PORT_1));
|
||||
|
||||
assertThat(config.getSentinels().size()).isEqualTo(1);
|
||||
assertThat(config.getSentinels()).hasSize(1);
|
||||
assertThat(config.getSentinels()).contains(new RedisNode("127.0.0.1", 123));
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-372
|
||||
public void shouldCreateRedisSentinelConfigurationCorrectlyGivenMasterAndMultipleHostAndPortStrings() {
|
||||
void shouldCreateRedisSentinelConfigurationCorrectlyGivenMasterAndMultipleHostAndPortStrings() {
|
||||
|
||||
RedisSentinelConfiguration config = new RedisSentinelConfiguration("mymaster",
|
||||
new HashSet<>(Arrays.asList(HOST_AND_PORT_1, HOST_AND_PORT_2, HOST_AND_PORT_3)));
|
||||
|
||||
assertThat(config.getSentinels().size()).isEqualTo(3);
|
||||
assertThat(config.getSentinels()).hasSize(3);
|
||||
assertThat(config.getSentinels()).contains(new RedisNode("127.0.0.1", 123), new RedisNode("localhost", 456),
|
||||
new RedisNode("localhost", 789));
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-372
|
||||
public void shouldThrowExecptionOnInvalidHostAndPortString() {
|
||||
void shouldThrowExecptionOnInvalidHostAndPortString() {
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> new RedisSentinelConfiguration("mymaster", Collections.singleton(HOST_AND_NO_PORT)));
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-372
|
||||
public void shouldThrowExceptionWhenListOfHostAndPortIsNull() {
|
||||
void shouldThrowExceptionWhenListOfHostAndPortIsNull() {
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> new RedisSentinelConfiguration("mymaster", Collections.<String> singleton(null)));
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-372
|
||||
public void shouldNotFailWhenListOfHostAndPortIsEmpty() {
|
||||
void shouldNotFailWhenListOfHostAndPortIsEmpty() {
|
||||
|
||||
RedisSentinelConfiguration config = new RedisSentinelConfiguration("mymaster", Collections.<String> emptySet());
|
||||
|
||||
assertThat(config.getSentinels().size()).isEqualTo(0);
|
||||
assertThat(config.getSentinels()).isEmpty();
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-372
|
||||
public void shouldThrowExceptionGivenNullPropertySource() {
|
||||
void shouldThrowExceptionGivenNullPropertySource() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> new RedisSentinelConfiguration((PropertySource<?>) null));
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-372
|
||||
public void shouldNotFailWhenGivenPropertySourceNotContainingRelevantProperties() {
|
||||
void shouldNotFailWhenGivenPropertySourceNotContainingRelevantProperties() {
|
||||
|
||||
RedisSentinelConfiguration config = new RedisSentinelConfiguration(new MockPropertySource());
|
||||
|
||||
assertThat(config.getMaster()).isNull();
|
||||
assertThat(config.getSentinels().size()).isEqualTo(0);
|
||||
assertThat(config.getSentinels()).isEmpty();
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-372
|
||||
public void shouldBeCreatedCorrecltyGivenValidPropertySourceWithMasterAndSingleHostPort() {
|
||||
void shouldBeCreatedCorrecltyGivenValidPropertySourceWithMasterAndSingleHostPort() {
|
||||
|
||||
MockPropertySource propertySource = new MockPropertySource();
|
||||
propertySource.setProperty("spring.redis.sentinel.master", "myMaster");
|
||||
@@ -101,12 +102,12 @@ public class RedisSentinelConfigurationUnitTests {
|
||||
RedisSentinelConfiguration config = new RedisSentinelConfiguration(propertySource);
|
||||
|
||||
assertThat(config.getMaster().getName()).isEqualTo("myMaster");
|
||||
assertThat(config.getSentinels().size()).isEqualTo(1);
|
||||
assertThat(config.getSentinels()).hasSize(1);
|
||||
assertThat(config.getSentinels()).contains(new RedisNode("127.0.0.1", 123));
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-372
|
||||
public void shouldBeCreatedCorrecltyGivenValidPropertySourceWithMasterAndMultipleHostPort() {
|
||||
void shouldBeCreatedCorrecltyGivenValidPropertySourceWithMasterAndMultipleHostPort() {
|
||||
|
||||
MockPropertySource propertySource = new MockPropertySource();
|
||||
propertySource.setProperty("spring.redis.sentinel.master", "myMaster");
|
||||
@@ -115,13 +116,13 @@ public class RedisSentinelConfigurationUnitTests {
|
||||
|
||||
RedisSentinelConfiguration config = new RedisSentinelConfiguration(propertySource);
|
||||
|
||||
assertThat(config.getSentinels().size()).isEqualTo(3);
|
||||
assertThat(config.getSentinels()).hasSize(3);
|
||||
assertThat(config.getSentinels()).contains(new RedisNode("127.0.0.1", 123), new RedisNode("localhost", 456),
|
||||
new RedisNode("localhost", 789));
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-1060
|
||||
public void dataNodePasswordDoesNotAffectSentinelPassword() {
|
||||
void dataNodePasswordDoesNotAffectSentinelPassword() {
|
||||
|
||||
RedisPassword password = RedisPassword.of("88888888-8x8-getting-creative-now");
|
||||
RedisSentinelConfiguration configuration = new RedisSentinelConfiguration("myMaster",
|
||||
@@ -132,7 +133,7 @@ public class RedisSentinelConfigurationUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-1060
|
||||
public void readSentinelPasswordFromConfigProperty() {
|
||||
void readSentinelPasswordFromConfigProperty() {
|
||||
|
||||
MockPropertySource propertySource = new MockPropertySource();
|
||||
propertySource.setProperty("spring.redis.sentinel.master", "myMaster");
|
||||
|
||||
@@ -19,17 +19,17 @@ import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link RedisServer}.
|
||||
*
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
public class RedisServerUnitTests {
|
||||
class RedisServerUnitTests {
|
||||
|
||||
@Test // DATAREDIS-618
|
||||
public void shouldReadNumberOfOtherSentinelsCorrectly() {
|
||||
void shouldReadNumberOfOtherSentinelsCorrectly() {
|
||||
|
||||
RedisServer redisServer = RedisServer.newServerFrom(createProperties());
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ import java.io.Serializable;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.data.redis.connection.stream.ByteRecord;
|
||||
import org.springframework.data.redis.connection.stream.MapRecord;
|
||||
@@ -39,21 +39,21 @@ import org.springframework.data.redis.serializer.RedisSerializer;
|
||||
* @author Christoph Strobl
|
||||
* @author Romain Beghi
|
||||
*/
|
||||
public class StreamRecordsUnitTests {
|
||||
class StreamRecordsUnitTests {
|
||||
|
||||
static final String STRING_STREAM_KEY = "stream-key";
|
||||
static final RecordId RECORD_ID = RecordId.of("1-0");
|
||||
static final String STRING_MAP_KEY = "string-key";
|
||||
static final String STRING_VAL = "string-val";
|
||||
static final DummyObject OBJECT_VAL = new DummyObject();
|
||||
private static final String STRING_STREAM_KEY = "stream-key";
|
||||
private static final RecordId RECORD_ID = RecordId.of("1-0");
|
||||
private static final String STRING_MAP_KEY = "string-key";
|
||||
private static final String STRING_VAL = "string-val";
|
||||
private static final DummyObject OBJECT_VAL = new DummyObject();
|
||||
|
||||
static final Jackson2JsonRedisSerializer<DummyObject> JSON_REDIS_SERIALIZER = new Jackson2JsonRedisSerializer<>(
|
||||
private static final Jackson2JsonRedisSerializer<DummyObject> JSON_REDIS_SERIALIZER = new Jackson2JsonRedisSerializer<>(
|
||||
DummyObject.class);
|
||||
|
||||
static final byte[] SERIALIZED_STRING_VAL = RedisSerializer.string().serialize(STRING_VAL);
|
||||
static final byte[] SERIALIZED_STRING_MAP_KEY = RedisSerializer.string().serialize(STRING_MAP_KEY);
|
||||
static final byte[] SERIALIZED_STRING_STREAM_KEY = RedisSerializer.string().serialize(STRING_STREAM_KEY);
|
||||
static final byte[] SERIALIZED_JSON_OBJECT_VAL = JSON_REDIS_SERIALIZER.serialize(OBJECT_VAL);
|
||||
private static final byte[] SERIALIZED_STRING_VAL = RedisSerializer.string().serialize(STRING_VAL);
|
||||
private static final byte[] SERIALIZED_STRING_MAP_KEY = RedisSerializer.string().serialize(STRING_MAP_KEY);
|
||||
private static final byte[] SERIALIZED_STRING_STREAM_KEY = RedisSerializer.string().serialize(STRING_STREAM_KEY);
|
||||
private static final byte[] SERIALIZED_JSON_OBJECT_VAL = JSON_REDIS_SERIALIZER.serialize(OBJECT_VAL);
|
||||
|
||||
private static class DummyObject implements Serializable {
|
||||
private final Integer dummyId = 1;
|
||||
@@ -64,7 +64,7 @@ public class StreamRecordsUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-864
|
||||
public void objectRecordToMapRecordViaHashMapper() {
|
||||
void objectRecordToMapRecordViaHashMapper() {
|
||||
|
||||
ObjectRecord<String, String> source = Record.of("some-string").withId(RECORD_ID).withStreamKey(STRING_STREAM_KEY);
|
||||
|
||||
@@ -77,7 +77,7 @@ public class StreamRecordsUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-864
|
||||
public void mapRecordToObjectRecordViaHashMapper() {
|
||||
void mapRecordToObjectRecordViaHashMapper() {
|
||||
|
||||
MapRecord<String, String, String> source = Record.of(Collections.singletonMap(STRING_MAP_KEY, "some-string"))
|
||||
.withId(RECORD_ID).withStreamKey(STRING_STREAM_KEY);
|
||||
@@ -90,7 +90,7 @@ public class StreamRecordsUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-864
|
||||
public void serializeMapRecordStringAsHashValue() {
|
||||
void serializeMapRecordStringAsHashValue() {
|
||||
|
||||
MapRecord<String, String, String> source = Record.of(Collections.singletonMap(STRING_MAP_KEY, STRING_VAL))
|
||||
.withId(RECORD_ID).withStreamKey(STRING_STREAM_KEY);
|
||||
@@ -104,7 +104,7 @@ public class StreamRecordsUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-993
|
||||
public void serializeMapRecordObjectAsHashValue() {
|
||||
void serializeMapRecordObjectAsHashValue() {
|
||||
|
||||
MapRecord<String, String, DummyObject> source = Record.of(Collections.singletonMap(STRING_MAP_KEY, OBJECT_VAL))
|
||||
.withId(RECORD_ID).withStreamKey(STRING_STREAM_KEY);
|
||||
@@ -118,7 +118,7 @@ public class StreamRecordsUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-864
|
||||
public void deserializeByteMapRecord() {
|
||||
void deserializeByteMapRecord() {
|
||||
|
||||
ByteRecord source = StreamRecords.newRecord().in(SERIALIZED_STRING_STREAM_KEY).withId(RECORD_ID)
|
||||
.ofBytes(Collections.singletonMap(SERIALIZED_STRING_MAP_KEY, SERIALIZED_STRING_VAL));
|
||||
@@ -144,7 +144,7 @@ public class StreamRecordsUnitTests {
|
||||
this(Collections.emptyMap(), from);
|
||||
}
|
||||
|
||||
public StubValueReturningHashMapper(Map<K, V> to, T from) {
|
||||
StubValueReturningHashMapper(Map<K, V> to, T from) {
|
||||
this.to = to;
|
||||
this.from = from;
|
||||
}
|
||||
|
||||
@@ -15,9 +15,10 @@
|
||||
*/
|
||||
package org.springframework.data.redis.connection;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.data.redis.connection.RedisZSetCommands.Weights;
|
||||
|
||||
/**
|
||||
@@ -25,24 +26,24 @@ import org.springframework.data.redis.connection.RedisZSetCommands.Weights;
|
||||
*
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
public class WeightsUnitTests {
|
||||
class WeightsUnitTests {
|
||||
|
||||
@Test // DATAREDIS-746
|
||||
public void shouldCreateWeights() {
|
||||
void shouldCreateWeights() {
|
||||
|
||||
assertThat(Weights.of(1, 2, 3).toArray()).contains(1, 2, 3);
|
||||
assertThat(Weights.of(1, 2d, 3).toArray()).contains(1d, 2d, 3d);
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-746
|
||||
public void shouldRejectCreationWithNull() {
|
||||
void shouldRejectCreationWithNull() {
|
||||
|
||||
assertThatThrownBy(() -> Weights.of((int[]) null)).isInstanceOf(IllegalArgumentException.class);
|
||||
assertThatThrownBy(() -> Weights.of((double[]) null)).isInstanceOf(IllegalArgumentException.class);
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-746
|
||||
public void shouldCreateEqualWeights() {
|
||||
void shouldCreateEqualWeights() {
|
||||
|
||||
Weights weights = Weights.fromSetCount(3);
|
||||
assertThat(weights.getWeight(0)).isOne();
|
||||
@@ -51,14 +52,14 @@ public class WeightsUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-746
|
||||
public void getShouldThrowIndexOutOfBoundsException() {
|
||||
void getShouldThrowIndexOutOfBoundsException() {
|
||||
|
||||
assertThatThrownBy(() -> Weights.fromSetCount(1).getWeight(1)).isInstanceOf(IndexOutOfBoundsException.class);
|
||||
assertThatThrownBy(() -> Weights.fromSetCount(1).getWeight(-1)).isInstanceOf(IndexOutOfBoundsException.class);
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-746
|
||||
public void shouldMultiplyDouble() {
|
||||
void shouldMultiplyDouble() {
|
||||
|
||||
Weights weights = Weights.of(1, 2, 3).multiply(2.5);
|
||||
assertThat(weights.getWeight(0)).isEqualTo(2.5);
|
||||
@@ -66,7 +67,7 @@ public class WeightsUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-746
|
||||
public void shouldMultiplyInt() {
|
||||
void shouldMultiplyInt() {
|
||||
|
||||
Weights weights = Weights.of(1, 2, 3).multiply(2);
|
||||
assertThat(weights.getWeight(0)).isEqualTo(2);
|
||||
|
||||
@@ -19,7 +19,7 @@ import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.data.redis.connection.RedisClusterNode;
|
||||
import org.springframework.data.redis.connection.RedisClusterNode.Flag;
|
||||
@@ -30,7 +30,7 @@ import org.springframework.data.redis.connection.RedisNode.NodeType;
|
||||
* @author Christoph Strobl
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
public class ConvertersUnitTests {
|
||||
class ConvertersUnitTests {
|
||||
|
||||
private static final String REDIS_3_0_CLUSTER_NODES_RESPONSE = "" //
|
||||
+ "ef570f86c7b1a953846668debc177a3a16733420 127.0.0.1:6379@16379 myself,master - 0 0 1 connected 0-5460 5602"
|
||||
@@ -57,7 +57,7 @@ public class ConvertersUnitTests {
|
||||
private static final String CLUSTER_NODE_IMPORTING_SLOT = "ef570f86c7b1a953846668debc177a3a16733420 127.0.0.1:6379 myself,master - 0 0 1 connected [5461-<-0f2ee5df45d18c50aca07228cc18b1da96fd5e84]";
|
||||
|
||||
@Test // DATAREDIS-315
|
||||
public void toSetOfRedis30ClusterNodesShouldConvertSingleStringNodesResponseCorrectly() {
|
||||
void toSetOfRedis30ClusterNodesShouldConvertSingleStringNodesResponseCorrectly() {
|
||||
|
||||
Iterator<RedisClusterNode> nodes = Converters.toSetOfRedisClusterNodes(REDIS_3_0_CLUSTER_NODES_RESPONSE).iterator();
|
||||
|
||||
@@ -107,7 +107,7 @@ public class ConvertersUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-315
|
||||
public void toSetOfRedis32ClusterNodesShouldConvertSingleStringNodesResponseCorrectly() {
|
||||
void toSetOfRedis32ClusterNodesShouldConvertSingleStringNodesResponseCorrectly() {
|
||||
|
||||
Iterator<RedisClusterNode> nodes = Converters.toSetOfRedisClusterNodes(REDIS_3_2_CLUSTER_NODES_RESPONSE).iterator();
|
||||
|
||||
@@ -157,7 +157,7 @@ public class ConvertersUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-315
|
||||
public void toSetOfRedisClusterNodesShouldConvertNodesWithSingleSlotCorrectly() {
|
||||
void toSetOfRedisClusterNodesShouldConvertNodesWithSingleSlotCorrectly() {
|
||||
|
||||
Iterator<RedisClusterNode> nodes = Converters.toSetOfRedisClusterNodes(CLUSTER_NODE_WITH_SINGLE_SLOT_RESPONSE)
|
||||
.iterator();
|
||||
@@ -171,7 +171,7 @@ public class ConvertersUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-315
|
||||
public void toSetOfRedisClusterNodesShouldParseLinkStateAndDisconnectedCorrectly() {
|
||||
void toSetOfRedisClusterNodesShouldParseLinkStateAndDisconnectedCorrectly() {
|
||||
|
||||
Iterator<RedisClusterNode> nodes = Converters.toSetOfRedisClusterNodes(
|
||||
CLUSTER_NODE_WITH_FAIL_FLAG_AND_DISCONNECTED_LINK_STATE).iterator();
|
||||
@@ -187,7 +187,7 @@ public class ConvertersUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-315
|
||||
public void toSetOfRedisClusterNodesShouldIgnoreImportingSlot() {
|
||||
void toSetOfRedisClusterNodesShouldIgnoreImportingSlot() {
|
||||
|
||||
Iterator<RedisClusterNode> nodes = Converters.toSetOfRedisClusterNodes(CLUSTER_NODE_IMPORTING_SLOT).iterator();
|
||||
|
||||
|
||||
@@ -20,31 +20,25 @@ import static org.assertj.core.api.Assertions.*;
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
|
||||
import org.junit.Assume;
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.RuleChain;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.data.redis.connection.RedisConnection;
|
||||
import org.springframework.data.redis.connection.RedisSentinelConfiguration;
|
||||
import org.springframework.data.redis.connection.RedisSentinelConnection;
|
||||
import org.springframework.data.redis.connection.RedisStandaloneConfiguration;
|
||||
import org.springframework.data.redis.test.util.MinimumRedisVersionRule;
|
||||
import org.springframework.data.redis.test.util.ServerAvailable;
|
||||
import org.springframework.test.annotation.IfProfileValue;
|
||||
import org.springframework.data.redis.test.condition.EnabledOnRedisSentinelAvailable;
|
||||
import org.springframework.data.redis.test.condition.EnabledOnRedisVersion;
|
||||
|
||||
/**
|
||||
* Integration tests for Redis 6 ACL.
|
||||
*
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
@IfProfileValue(name = "redisVersion", value = "6.0+")
|
||||
public class JedisAclIntegrationTests {
|
||||
|
||||
@ClassRule public static RuleChain requirements = RuleChain.outerRule(ServerAvailable.runningAtLocalhost(6382))
|
||||
.around(new MinimumRedisVersionRule());
|
||||
@EnabledOnRedisVersion("6.0")
|
||||
class JedisAclIntegrationTests {
|
||||
|
||||
@Test
|
||||
public void shouldConnectWithDefaultAuthentication() {
|
||||
void shouldConnectWithDefaultAuthentication() {
|
||||
|
||||
RedisStandaloneConfiguration standaloneConfiguration = new RedisStandaloneConfiguration("localhost", 6382);
|
||||
standaloneConfiguration.setPassword("foobared");
|
||||
@@ -61,7 +55,7 @@ public class JedisAclIntegrationTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-1046
|
||||
public void shouldConnectStandaloneWithAclAuthentication() {
|
||||
void shouldConnectStandaloneWithAclAuthentication() {
|
||||
|
||||
RedisStandaloneConfiguration standaloneConfiguration = new RedisStandaloneConfiguration("localhost", 6382);
|
||||
standaloneConfiguration.setUsername("spring");
|
||||
@@ -79,10 +73,8 @@ public class JedisAclIntegrationTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-1145
|
||||
public void shouldConnectSentinelWithAclAuthentication() throws IOException {
|
||||
|
||||
Assume.assumeTrue("Redis Sentinel at localhost:26382 did not answer.",
|
||||
ServerAvailable.runningAtLocalhost(26382).isAvailable());
|
||||
@EnabledOnRedisSentinelAvailable(26382)
|
||||
void shouldConnectSentinelWithAclAuthentication() throws IOException {
|
||||
|
||||
// Note: As per https://github.com/redis/redis/issues/7708, Sentinel does not support ACL authentication yet.
|
||||
|
||||
@@ -102,7 +94,7 @@ public class JedisAclIntegrationTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-1046
|
||||
public void shouldConnectStandaloneWithAclAuthenticationAndPooling() {
|
||||
void shouldConnectStandaloneWithAclAuthenticationAndPooling() {
|
||||
|
||||
RedisStandaloneConfiguration standaloneConfiguration = new RedisStandaloneConfiguration("localhost", 6382);
|
||||
standaloneConfiguration.setUsername("spring");
|
||||
|
||||
@@ -28,17 +28,17 @@ import javax.net.ssl.SSLParameters;
|
||||
import javax.net.ssl.SSLSession;
|
||||
import javax.net.ssl.SSLSocketFactory;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link JedisClientConfiguration}.
|
||||
*
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
public class JedisClientConfigurationUnitTests {
|
||||
class JedisClientConfigurationUnitTests {
|
||||
|
||||
@Test // DATAREDIS-574
|
||||
public void shouldCreateEmptyConfiguration() {
|
||||
void shouldCreateEmptyConfiguration() {
|
||||
|
||||
JedisClientConfiguration configuration = JedisClientConfiguration.defaultConfiguration();
|
||||
|
||||
@@ -52,7 +52,7 @@ public class JedisClientConfigurationUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-574
|
||||
public void shouldConfigureAllProperties() throws NoSuchAlgorithmException {
|
||||
void shouldConfigureAllProperties() throws NoSuchAlgorithmException {
|
||||
|
||||
SSLParameters sslParameters = new SSLParameters();
|
||||
SSLContext context = SSLContext.getDefault();
|
||||
|
||||
@@ -25,7 +25,9 @@ import static org.springframework.data.redis.connection.RedisGeoCommands.Distanc
|
||||
import static org.springframework.data.redis.connection.RedisGeoCommands.GeoRadiusCommandArgs.*;
|
||||
import static org.springframework.data.redis.core.ScanOptions.*;
|
||||
|
||||
import org.junit.jupiter.api.TestInstance;
|
||||
import redis.clients.jedis.HostAndPort;
|
||||
import redis.clients.jedis.Jedis;
|
||||
import redis.clients.jedis.JedisCluster;
|
||||
import redis.clients.jedis.JedisPool;
|
||||
|
||||
@@ -35,11 +37,9 @@ import java.time.Duration;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.dao.InvalidDataAccessApiUsageException;
|
||||
@@ -69,9 +69,9 @@ import org.springframework.data.redis.core.Cursor;
|
||||
import org.springframework.data.redis.core.ScanOptions;
|
||||
import org.springframework.data.redis.core.script.DigestUtils;
|
||||
import org.springframework.data.redis.core.types.Expiration;
|
||||
import org.springframework.data.redis.test.condition.EnabledOnRedisClusterAvailable;
|
||||
import org.springframework.data.redis.test.extension.JedisExtension;
|
||||
import org.springframework.data.redis.test.util.HexStringUtils;
|
||||
import org.springframework.data.redis.test.util.MinimumRedisVersionRule;
|
||||
import org.springframework.data.redis.test.util.RedisClusterRule;
|
||||
import org.springframework.test.annotation.IfProfileValue;
|
||||
|
||||
/**
|
||||
@@ -79,61 +79,51 @@ import org.springframework.test.annotation.IfProfileValue;
|
||||
* @author Mark Paluch
|
||||
* @author Pavel Khokhlov
|
||||
*/
|
||||
@EnabledOnRedisClusterAvailable
|
||||
@ExtendWith(JedisExtension.class)
|
||||
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
||||
public class JedisClusterConnectionTests implements ClusterConnectionTests {
|
||||
|
||||
static final List<HostAndPort> CLUSTER_NODES = Arrays.asList(new HostAndPort(CLUSTER_HOST, MASTER_NODE_1_PORT),
|
||||
new HostAndPort(CLUSTER_HOST, MASTER_NODE_2_PORT), new HostAndPort(CLUSTER_HOST, MASTER_NODE_3_PORT));
|
||||
|
||||
static final byte[] KEY_1_BYTES = JedisConverters.toBytes(KEY_1);
|
||||
static final byte[] KEY_2_BYTES = JedisConverters.toBytes(KEY_2);
|
||||
static final byte[] KEY_3_BYTES = JedisConverters.toBytes(KEY_3);
|
||||
private static final byte[] KEY_1_BYTES = JedisConverters.toBytes(KEY_1);
|
||||
private static final byte[] KEY_2_BYTES = JedisConverters.toBytes(KEY_2);
|
||||
private static final byte[] KEY_3_BYTES = JedisConverters.toBytes(KEY_3);
|
||||
|
||||
static final byte[] SAME_SLOT_KEY_1_BYTES = JedisConverters.toBytes(SAME_SLOT_KEY_1);
|
||||
static final byte[] SAME_SLOT_KEY_2_BYTES = JedisConverters.toBytes(SAME_SLOT_KEY_2);
|
||||
static final byte[] SAME_SLOT_KEY_3_BYTES = JedisConverters.toBytes(SAME_SLOT_KEY_3);
|
||||
private static final byte[] SAME_SLOT_KEY_1_BYTES = JedisConverters.toBytes(SAME_SLOT_KEY_1);
|
||||
private static final byte[] SAME_SLOT_KEY_2_BYTES = JedisConverters.toBytes(SAME_SLOT_KEY_2);
|
||||
private static final byte[] SAME_SLOT_KEY_3_BYTES = JedisConverters.toBytes(SAME_SLOT_KEY_3);
|
||||
|
||||
static final byte[] VALUE_1_BYTES = JedisConverters.toBytes(VALUE_1);
|
||||
static final byte[] VALUE_2_BYTES = JedisConverters.toBytes(VALUE_2);
|
||||
static final byte[] VALUE_3_BYTES = JedisConverters.toBytes(VALUE_3);
|
||||
private static final byte[] VALUE_1_BYTES = JedisConverters.toBytes(VALUE_1);
|
||||
private static final byte[] VALUE_2_BYTES = JedisConverters.toBytes(VALUE_2);
|
||||
private static final byte[] VALUE_3_BYTES = JedisConverters.toBytes(VALUE_3);
|
||||
|
||||
static final GeoLocation<byte[]> ARIGENTO = new GeoLocation<>("arigento".getBytes(Charset.forName("UTF-8")),
|
||||
private static final GeoLocation<byte[]> ARIGENTO = new GeoLocation<>("arigento".getBytes(Charset.forName("UTF-8")),
|
||||
POINT_ARIGENTO);
|
||||
static final GeoLocation<byte[]> CATANIA = new GeoLocation<>("catania".getBytes(Charset.forName("UTF-8")),
|
||||
private static final GeoLocation<byte[]> CATANIA = new GeoLocation<>("catania".getBytes(Charset.forName("UTF-8")),
|
||||
POINT_CATANIA);
|
||||
static final GeoLocation<byte[]> PALERMO = new GeoLocation<>("palermo".getBytes(Charset.forName("UTF-8")),
|
||||
private static final GeoLocation<byte[]> PALERMO = new GeoLocation<>("palermo".getBytes(Charset.forName("UTF-8")),
|
||||
POINT_PALERMO);
|
||||
|
||||
JedisCluster nativeConnection;
|
||||
JedisClusterConnection clusterConnection;
|
||||
private final JedisCluster nativeConnection;
|
||||
private final JedisClusterConnection clusterConnection;
|
||||
|
||||
/**
|
||||
* ONLY RUN WHEN CLUSTER AVAILABLE
|
||||
*/
|
||||
public static @ClassRule RedisClusterRule clusterRule = new RedisClusterRule();
|
||||
|
||||
/**
|
||||
* Check for specific Redis Versions
|
||||
*/
|
||||
public @Rule MinimumRedisVersionRule version = new MinimumRedisVersionRule();
|
||||
|
||||
@Before
|
||||
public void setUp() throws IOException {
|
||||
|
||||
nativeConnection = new JedisCluster(new HashSet<>(CLUSTER_NODES));
|
||||
public JedisClusterConnectionTests(JedisCluster nativeConnection) {
|
||||
this.nativeConnection = nativeConnection;
|
||||
clusterConnection = new JedisClusterConnection(this.nativeConnection);
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() throws IOException {
|
||||
@BeforeEach
|
||||
void tearDown() throws IOException {
|
||||
|
||||
for (JedisPool pool : nativeConnection.getClusterNodes().values()) {
|
||||
try {
|
||||
pool.getResource().flushDB();
|
||||
try (Jedis jedis = pool.getResource()) {
|
||||
jedis.flushAll();
|
||||
} catch (Exception e) {
|
||||
// ignore this one since we cannot remove data from slaves
|
||||
}
|
||||
}
|
||||
nativeConnection.close();
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-315
|
||||
@@ -191,7 +181,7 @@ public class JedisClusterConnectionTests implements ClusterConnectionTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-315
|
||||
public void bitOpShouldWorkCorrectly() {
|
||||
void bitOpShouldWorkCorrectly() {
|
||||
|
||||
nativeConnection.set(SAME_SLOT_KEY_1, "foo");
|
||||
nativeConnection.set(SAME_SLOT_KEY_2, "bar");
|
||||
@@ -347,7 +337,7 @@ public class JedisClusterConnectionTests implements ClusterConnectionTests {
|
||||
|
||||
@Test // DATAREDIS-315
|
||||
public void discardShouldThrowException() {
|
||||
assertThatExceptionOfType(DataAccessException.class).isThrownBy(() -> clusterConnection.discard());
|
||||
assertThatExceptionOfType(DataAccessException.class).isThrownBy(clusterConnection::discard);
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-315
|
||||
@@ -382,11 +372,11 @@ public class JedisClusterConnectionTests implements ClusterConnectionTests {
|
||||
|
||||
@Test // DATAREDIS-315
|
||||
public void execShouldThrowException() {
|
||||
assertThatExceptionOfType(DataAccessException.class).isThrownBy(() -> clusterConnection.exec());
|
||||
assertThatExceptionOfType(DataAccessException.class).isThrownBy(clusterConnection::exec);
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-689
|
||||
public void executeWithArgs() {
|
||||
void executeWithArgs() {
|
||||
|
||||
assertThat(clusterConnection.execute("SET", KEY_1_BYTES, VALUE_1_BYTES)).isEqualTo("OK".getBytes());
|
||||
|
||||
@@ -394,7 +384,7 @@ public class JedisClusterConnectionTests implements ClusterConnectionTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-689
|
||||
public void executeWithKeyAndArgs() {
|
||||
void executeWithKeyAndArgs() {
|
||||
|
||||
Object result = clusterConnection.execute("SET", KEY_1_BYTES, Collections.singletonList(VALUE_1_BYTES));
|
||||
assertThat(result).isEqualTo("OK".getBytes());
|
||||
@@ -403,7 +393,7 @@ public class JedisClusterConnectionTests implements ClusterConnectionTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-689
|
||||
public void executeWithNoKeyAndArgsThrowsException() {
|
||||
void executeWithNoKeyAndArgsThrowsException() {
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> clusterConnection.execute("KEYS", (byte[]) null, Collections.singletonList("*".getBytes())));
|
||||
}
|
||||
@@ -440,7 +430,7 @@ public class JedisClusterConnectionTests implements ClusterConnectionTests {
|
||||
|
||||
clusterConnection.expireAt(KEY_1_BYTES, System.currentTimeMillis() / 1000 + 5000);
|
||||
|
||||
assertThat(nativeConnection.ttl(JedisConverters.toString(KEY_1_BYTES)) > 1).isTrue();
|
||||
assertThat(nativeConnection.ttl(JedisConverters.toString(KEY_1_BYTES))).isGreaterThan(1);
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-315
|
||||
@@ -450,7 +440,7 @@ public class JedisClusterConnectionTests implements ClusterConnectionTests {
|
||||
|
||||
clusterConnection.expire(KEY_1_BYTES, 5);
|
||||
|
||||
assertThat(nativeConnection.ttl(JedisConverters.toString(KEY_1_BYTES)) > 1).isTrue();
|
||||
assertThat(nativeConnection.ttl(JedisConverters.toString(KEY_1_BYTES))).isGreaterThan(1);
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-315
|
||||
@@ -994,13 +984,14 @@ public class JedisClusterConnectionTests implements ClusterConnectionTests {
|
||||
assertThat(keysOnNode).contains(KEY_2_BYTES).doesNotContain(KEY_1_BYTES);
|
||||
}
|
||||
|
||||
@Test(expected = InvalidDataAccessApiUsageException.class) // DATAREDIS-635
|
||||
@Test // DATAREDIS-635
|
||||
public void scanShouldReturnAllKeys() {
|
||||
|
||||
nativeConnection.set(KEY_1, VALUE_1);
|
||||
nativeConnection.set(KEY_2, VALUE_2);
|
||||
|
||||
clusterConnection.scan(ScanOptions.NONE);
|
||||
assertThatExceptionOfType(InvalidDataAccessApiUsageException.class)
|
||||
.isThrownBy(() -> clusterConnection.scan(ScanOptions.NONE));
|
||||
}
|
||||
|
||||
@Override // DATAREDIS-635
|
||||
@@ -1219,7 +1210,7 @@ public class JedisClusterConnectionTests implements ClusterConnectionTests {
|
||||
|
||||
@Test // DATAREDIS-315
|
||||
public void multiShouldThrowException() {
|
||||
assertThatExceptionOfType(DataAccessException.class).isThrownBy(() -> clusterConnection.multi());
|
||||
assertThatExceptionOfType(DataAccessException.class).isThrownBy(clusterConnection::multi);
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-315
|
||||
@@ -1229,7 +1220,7 @@ public class JedisClusterConnectionTests implements ClusterConnectionTests {
|
||||
|
||||
clusterConnection.pExpireAt(KEY_1_BYTES, System.currentTimeMillis() + 5000);
|
||||
|
||||
assertThat(nativeConnection.ttl(JedisConverters.toString(KEY_1_BYTES)) > 1).isTrue();
|
||||
assertThat(nativeConnection.ttl(JedisConverters.toString(KEY_1_BYTES))).isGreaterThan(1);
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-315
|
||||
@@ -1239,7 +1230,7 @@ public class JedisClusterConnectionTests implements ClusterConnectionTests {
|
||||
|
||||
clusterConnection.pExpire(KEY_1_BYTES, 5000);
|
||||
|
||||
assertThat(nativeConnection.ttl(JedisConverters.toString(KEY_1_BYTES)) > 1).isTrue();
|
||||
assertThat(nativeConnection.ttl(JedisConverters.toString(KEY_1_BYTES))).isGreaterThan(1);
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-315
|
||||
@@ -1248,7 +1239,7 @@ public class JedisClusterConnectionTests implements ClusterConnectionTests {
|
||||
clusterConnection.pSetEx(KEY_1_BYTES, 5000, VALUE_1_BYTES);
|
||||
|
||||
assertThat(nativeConnection.get(KEY_1)).isEqualTo(VALUE_1);
|
||||
assertThat(nativeConnection.ttl(KEY_1) > 1).isTrue();
|
||||
assertThat(nativeConnection.ttl(KEY_1)).isGreaterThan(1);
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-315
|
||||
@@ -1257,7 +1248,7 @@ public class JedisClusterConnectionTests implements ClusterConnectionTests {
|
||||
nativeConnection.set(KEY_1, VALUE_1);
|
||||
nativeConnection.expire(KEY_1, 5);
|
||||
|
||||
assertThat(clusterConnection.pTtl(KEY_1_BYTES) > 1).isTrue();
|
||||
assertThat(clusterConnection.pTtl(KEY_1_BYTES)).isGreaterThan(1);
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-315
|
||||
@@ -1312,13 +1303,14 @@ public class JedisClusterConnectionTests implements ClusterConnectionTests {
|
||||
assertThat(clusterConnection.pfCount(KEY_1_BYTES)).isEqualTo(3L);
|
||||
}
|
||||
|
||||
@Test(expected = DataAccessException.class) // DATAREDIS-315
|
||||
@Test // 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);
|
||||
assertThatExceptionOfType(DataAccessException.class)
|
||||
.isThrownBy(() -> clusterConnection.pfCount(KEY_1_BYTES, KEY_2_BYTES));
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-315
|
||||
@@ -1633,7 +1625,7 @@ public class JedisClusterConnectionTests implements ClusterConnectionTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-668
|
||||
public void sPopWithCountShouldPopValueFromSetCorrectly() {
|
||||
void sPopWithCountShouldPopValueFromSetCorrectly() {
|
||||
|
||||
nativeConnection.sadd(KEY_1, VALUE_1, VALUE_2, VALUE_3);
|
||||
|
||||
@@ -1735,7 +1727,7 @@ public class JedisClusterConnectionTests implements ClusterConnectionTests {
|
||||
clusterConnection.setEx(KEY_1_BYTES, 5, VALUE_1_BYTES);
|
||||
|
||||
assertThat(nativeConnection.get(KEY_1)).isEqualTo(VALUE_1);
|
||||
assertThat(nativeConnection.ttl(KEY_1) > 1).isTrue();
|
||||
assertThat(nativeConnection.ttl(KEY_1)).isGreaterThan(1);
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-315
|
||||
@@ -1927,7 +1919,7 @@ public class JedisClusterConnectionTests implements ClusterConnectionTests {
|
||||
nativeConnection.set(KEY_1, VALUE_1);
|
||||
nativeConnection.expire(KEY_1, 5);
|
||||
|
||||
assertThat(clusterConnection.ttl(KEY_1_BYTES) > 1).isTrue();
|
||||
assertThat(clusterConnection.ttl(KEY_1_BYTES)).isGreaterThan(1);
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-526
|
||||
@@ -1949,16 +1941,16 @@ public class JedisClusterConnectionTests implements ClusterConnectionTests {
|
||||
|
||||
@Test // DATAREDIS-315
|
||||
public void unwatchShouldThrowException() {
|
||||
assertThatExceptionOfType(DataAccessException.class).isThrownBy(() -> clusterConnection.unwatch());
|
||||
assertThatExceptionOfType(DataAccessException.class).isThrownBy(clusterConnection::unwatch);
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-315
|
||||
public void watchShouldThrowException() {
|
||||
assertThatExceptionOfType(DataAccessException.class).isThrownBy(() -> clusterConnection.watch());
|
||||
assertThatExceptionOfType(DataAccessException.class).isThrownBy(clusterConnection::watch);
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-674
|
||||
public void zAddShouldAddMultipleValuesWithScoreCorrectly() {
|
||||
void zAddShouldAddMultipleValuesWithScoreCorrectly() {
|
||||
|
||||
Set<Tuple> tuples = new HashSet<>();
|
||||
tuples.add(new DefaultTuple(VALUE_1_BYTES, 10D));
|
||||
@@ -2293,7 +2285,7 @@ public class JedisClusterConnectionTests implements ClusterConnectionTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-694
|
||||
public void touchReturnsNrOfKeysTouched() {
|
||||
void touchReturnsNrOfKeysTouched() {
|
||||
|
||||
nativeConnection.set(KEY_1, VALUE_1);
|
||||
nativeConnection.set(KEY_2, VALUE_1);
|
||||
@@ -2302,12 +2294,12 @@ public class JedisClusterConnectionTests implements ClusterConnectionTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-694
|
||||
public void touchReturnsZeroIfNoKeysTouched() {
|
||||
void touchReturnsZeroIfNoKeysTouched() {
|
||||
assertThat(clusterConnection.keyCommands().touch(KEY_1_BYTES)).isEqualTo(0L);
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-693
|
||||
public void unlinkReturnsNrOfKeysTouched() {
|
||||
void unlinkReturnsNrOfKeysTouched() {
|
||||
|
||||
nativeConnection.set(KEY_1, VALUE_1);
|
||||
nativeConnection.set(KEY_2, VALUE_1);
|
||||
@@ -2316,13 +2308,13 @@ public class JedisClusterConnectionTests implements ClusterConnectionTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-693
|
||||
public void unlinkReturnsZeroIfNoKeysTouched() {
|
||||
void unlinkReturnsZeroIfNoKeysTouched() {
|
||||
assertThat(clusterConnection.keyCommands().unlink(KEY_1_BYTES)).isEqualTo(0L);
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-697
|
||||
@IfProfileValue(name = "redisVersion", value = "2.8.7+")
|
||||
public void bitPosShouldReturnPositionCorrectly() {
|
||||
void bitPosShouldReturnPositionCorrectly() {
|
||||
|
||||
nativeConnection.set(KEY_1_BYTES, HexStringUtils.hexToBytes("fff000"));
|
||||
|
||||
@@ -2331,7 +2323,7 @@ public class JedisClusterConnectionTests implements ClusterConnectionTests {
|
||||
|
||||
@Test // DATAREDIS-697
|
||||
@IfProfileValue(name = "redisVersion", value = "2.8.7+")
|
||||
public void bitPosShouldReturnPositionInRangeCorrectly() {
|
||||
void bitPosShouldReturnPositionInRangeCorrectly() {
|
||||
|
||||
nativeConnection.set(KEY_1_BYTES, HexStringUtils.hexToBytes("fff0f0"));
|
||||
|
||||
@@ -2340,7 +2332,7 @@ public class JedisClusterConnectionTests implements ClusterConnectionTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-716
|
||||
public void encodingReturnsCorrectly() {
|
||||
void encodingReturnsCorrectly() {
|
||||
|
||||
nativeConnection.set(KEY_1_BYTES, "1000".getBytes());
|
||||
|
||||
@@ -2348,12 +2340,12 @@ public class JedisClusterConnectionTests implements ClusterConnectionTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-716
|
||||
public void encodingReturnsVacantWhenKeyDoesNotExist() {
|
||||
void encodingReturnsVacantWhenKeyDoesNotExist() {
|
||||
assertThat(clusterConnection.keyCommands().encodingOf(KEY_2_BYTES)).isEqualTo(RedisValueEncoding.VACANT);
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-716
|
||||
public void idletimeReturnsCorrectly() {
|
||||
void idletimeReturnsCorrectly() {
|
||||
|
||||
nativeConnection.set(KEY_1_BYTES, VALUE_1_BYTES);
|
||||
nativeConnection.get(KEY_1_BYTES);
|
||||
@@ -2362,12 +2354,12 @@ public class JedisClusterConnectionTests implements ClusterConnectionTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-716
|
||||
public void idldetimeReturnsNullWhenKeyDoesNotExist() {
|
||||
void idldetimeReturnsNullWhenKeyDoesNotExist() {
|
||||
assertThat(clusterConnection.keyCommands().idletime(KEY_3_BYTES)).isNull();
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-716
|
||||
public void refcountReturnsCorrectly() {
|
||||
void refcountReturnsCorrectly() {
|
||||
|
||||
nativeConnection.lpush(KEY_1_BYTES, VALUE_1_BYTES);
|
||||
|
||||
@@ -2375,13 +2367,13 @@ public class JedisClusterConnectionTests implements ClusterConnectionTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-716
|
||||
public void refcountReturnsNullWhenKeyDoesNotExist() {
|
||||
void refcountReturnsNullWhenKeyDoesNotExist() {
|
||||
assertThat(clusterConnection.keyCommands().refcount(KEY_3_BYTES)).isNull();
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-562
|
||||
@IfProfileValue(name = "redisVersion", value = "3.2+")
|
||||
public void bitFieldSetShouldWorkCorrectly() {
|
||||
void bitFieldSetShouldWorkCorrectly() {
|
||||
|
||||
assertThat(clusterConnection.stringCommands().bitField(JedisConverters.toBytes(KEY_1),
|
||||
create().set(INT_8).valueAt(BitFieldSubCommands.Offset.offset(0L)).to(10L))).containsExactly(0L);
|
||||
@@ -2391,7 +2383,7 @@ public class JedisClusterConnectionTests implements ClusterConnectionTests {
|
||||
|
||||
@Test // DATAREDIS-562
|
||||
@IfProfileValue(name = "redisVersion", value = "3.2+")
|
||||
public void bitFieldGetShouldWorkCorrectly() {
|
||||
void bitFieldGetShouldWorkCorrectly() {
|
||||
|
||||
assertThat(clusterConnection.stringCommands().bitField(JedisConverters.toBytes(KEY_1),
|
||||
create().get(INT_8).valueAt(BitFieldSubCommands.Offset.offset(0L)))).containsExactly(0L);
|
||||
@@ -2399,7 +2391,7 @@ public class JedisClusterConnectionTests implements ClusterConnectionTests {
|
||||
|
||||
@Test // DATAREDIS-562
|
||||
@IfProfileValue(name = "redisVersion", value = "3.2+")
|
||||
public void bitFieldIncrByShouldWorkCorrectly() {
|
||||
void bitFieldIncrByShouldWorkCorrectly() {
|
||||
|
||||
assertThat(clusterConnection.stringCommands().bitField(JedisConverters.toBytes(KEY_1),
|
||||
create().incr(INT_8).valueAt(BitFieldSubCommands.Offset.offset(100L)).by(1L))).containsExactly(1L);
|
||||
@@ -2407,7 +2399,7 @@ public class JedisClusterConnectionTests implements ClusterConnectionTests {
|
||||
|
||||
@Test // DATAREDIS-562
|
||||
@IfProfileValue(name = "redisVersion", value = "3.2+")
|
||||
public void bitFieldIncrByWithOverflowShouldWorkCorrectly() {
|
||||
void bitFieldIncrByWithOverflowShouldWorkCorrectly() {
|
||||
|
||||
assertThat(clusterConnection.stringCommands().bitField(JedisConverters.toBytes(KEY_1),
|
||||
create().incr(unsigned(2)).valueAt(BitFieldSubCommands.Offset.offset(102L)).overflow(FAIL).by(1L)))
|
||||
@@ -2426,7 +2418,7 @@ public class JedisClusterConnectionTests implements ClusterConnectionTests {
|
||||
|
||||
@Test // DATAREDIS-562
|
||||
@IfProfileValue(name = "redisVersion", value = "3.2+")
|
||||
public void bitfieldShouldAllowMultipleSubcommands() {
|
||||
void bitfieldShouldAllowMultipleSubcommands() {
|
||||
|
||||
assertThat(clusterConnection.stringCommands().bitField(JedisConverters.toBytes(KEY_1),
|
||||
create().incr(signed(5)).valueAt(BitFieldSubCommands.Offset.offset(100L)).by(1L).get(unsigned(4)).valueAt(0L)))
|
||||
@@ -2435,7 +2427,7 @@ public class JedisClusterConnectionTests implements ClusterConnectionTests {
|
||||
|
||||
@Test // DATAREDIS-562
|
||||
@IfProfileValue(name = "redisVersion", value = "3.2+")
|
||||
public void bitfieldShouldWorkUsingNonZeroBasedOffset() {
|
||||
void bitfieldShouldWorkUsingNonZeroBasedOffset() {
|
||||
|
||||
assertThat(
|
||||
clusterConnection.stringCommands().bitField(JedisConverters.toBytes(KEY_1),
|
||||
@@ -2452,7 +2444,7 @@ public class JedisClusterConnectionTests implements ClusterConnectionTests {
|
||||
|
||||
@Test // DATAREDIS-1005
|
||||
@IfProfileValue(name = "redisVersion", value = "2.6+")
|
||||
public void evalShouldRunScript() {
|
||||
void evalShouldRunScript() {
|
||||
|
||||
byte[] keyAndArgs = JedisConverters.toBytes("FOO");
|
||||
String luaScript = "return redis.call(\"INCR\", KEYS[1])";
|
||||
@@ -2465,7 +2457,7 @@ public class JedisClusterConnectionTests implements ClusterConnectionTests {
|
||||
|
||||
@Test // DATAREDIS-1005
|
||||
@IfProfileValue(name = "redisVersion", value = "2.6+")
|
||||
public void scriptLoadShouldLoadScript() {
|
||||
void scriptLoadShouldLoadScript() {
|
||||
|
||||
String luaScript = "return redis.call(\"INCR\", KEYS[1])";
|
||||
String digest = DigestUtils.sha1DigestAsHex(luaScript);
|
||||
@@ -2478,7 +2470,7 @@ public class JedisClusterConnectionTests implements ClusterConnectionTests {
|
||||
|
||||
@Test // DATAREDIS-1005
|
||||
@IfProfileValue(name = "redisVersion", value = "2.6+")
|
||||
public void scriptFlushShouldRemoveScripts() {
|
||||
void scriptFlushShouldRemoveScripts() {
|
||||
|
||||
byte[] keyAndArgs = JedisConverters.toBytes("FOO");
|
||||
String luaScript = "return redis.call(\"GET\", KEYS[1])";
|
||||
@@ -2497,7 +2489,7 @@ public class JedisClusterConnectionTests implements ClusterConnectionTests {
|
||||
|
||||
@Test // DATAREDIS-1005
|
||||
@IfProfileValue(name = "redisVersion", value = "2.6+")
|
||||
public void evelShaShouldRunScript() {
|
||||
void evelShaShouldRunScript() {
|
||||
|
||||
byte[] keyAndArgs = JedisConverters.toBytes("FOO");
|
||||
String luaScript = "return redis.call(\"INCR\", KEYS[1])";
|
||||
|
||||
@@ -35,16 +35,17 @@ import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Spy;
|
||||
import org.mockito.invocation.InvocationOnMock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import org.mockito.junit.jupiter.MockitoSettings;
|
||||
import org.mockito.quality.Strictness;
|
||||
import org.mockito.stubbing.Answer;
|
||||
|
||||
import org.springframework.dao.DataAccessResourceFailureException;
|
||||
import org.springframework.data.redis.ClusterStateFailureException;
|
||||
import org.springframework.data.redis.RedisSystemException;
|
||||
@@ -58,8 +59,9 @@ import org.springframework.data.redis.connection.jedis.JedisClusterConnection.Je
|
||||
* @author Mark Paluch
|
||||
* @author Chen Guanqun
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.Silent.class)
|
||||
public class JedisClusterConnectionUnitTests {
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
@MockitoSettings(strictness = Strictness.LENIENT)
|
||||
class JedisClusterConnectionUnitTests {
|
||||
|
||||
private static final String CLUSTER_NODES_RESPONSE = "" //
|
||||
+ MASTER_NODE_1_ID + " " + CLUSTER_HOST + ":" + MASTER_NODE_1_PORT + " myself,master - 0 0 1 connected 0-5460"
|
||||
@@ -67,13 +69,13 @@ public class JedisClusterConnectionUnitTests {
|
||||
+ " master - 0 1427718161587 2 connected 5461-10922" + "\n" + MASTER_NODE_2_ID + " " + CLUSTER_HOST + ":"
|
||||
+ MASTER_NODE_3_PORT + " master - 0 1427718161587 3 connected 10923-16383";
|
||||
|
||||
static final String CLUSTER_INFO_RESPONSE = "cluster_state:ok" + "\n" + "cluster_slots_assigned:16384" + "\n"
|
||||
private static final String CLUSTER_INFO_RESPONSE = "cluster_state:ok" + "\n" + "cluster_slots_assigned:16384" + "\n"
|
||||
+ "cluster_slots_ok:16384" + "\n" + "cluster_slots_pfail:0" + "\n" + "cluster_slots_fail:0" + "\n"
|
||||
+ "cluster_known_nodes:4" + "\n" + "cluster_size:3" + "\n" + "cluster_current_epoch:30" + "\n"
|
||||
+ "cluster_my_epoch:2" + "\n" + "cluster_stats_messages_sent:2560260" + "\n"
|
||||
+ "cluster_stats_messages_received:2560086";
|
||||
|
||||
JedisClusterConnection connection;
|
||||
private JedisClusterConnection connection;
|
||||
|
||||
@Spy StubJedisCluster clusterMock;
|
||||
@Mock JedisClusterConnectionHandler connectionHandlerMock;
|
||||
@@ -86,12 +88,10 @@ public class JedisClusterConnectionUnitTests {
|
||||
@Mock Jedis con2Mock;
|
||||
@Mock Jedis con3Mock;
|
||||
|
||||
Map<String, JedisPool> nodes = new LinkedHashMap<>();
|
||||
private Map<String, JedisPool> nodes = new LinkedHashMap<>();
|
||||
|
||||
public @Rule ExpectedException expectedException = ExpectedException.none();
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
|
||||
nodes.put(CLUSTER_HOST + ":" + MASTER_NODE_1_PORT, node1PoolMock);
|
||||
nodes.put(CLUSTER_HOST + ":" + MASTER_NODE_2_PORT, node2PoolMock);
|
||||
@@ -111,15 +111,12 @@ public class JedisClusterConnectionUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-315
|
||||
public void throwsExceptionWhenClusterCommandExecutorIsNull() {
|
||||
|
||||
expectedException.expect(IllegalArgumentException.class);
|
||||
|
||||
new JedisClusterConnection(clusterMock, null);
|
||||
void throwsExceptionWhenClusterCommandExecutorIsNull() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> new JedisClusterConnection(clusterMock, null));
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-315
|
||||
public void clusterMeetShouldSendCommandsToExistingNodesCorrectly() {
|
||||
void clusterMeetShouldSendCommandsToExistingNodesCorrectly() {
|
||||
|
||||
connection.clusterMeet(UNKNOWN_CLUSTER_NODE);
|
||||
|
||||
@@ -129,15 +126,12 @@ public class JedisClusterConnectionUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-315
|
||||
public void clusterMeetShouldThrowExceptionWhenNodeIsNull() {
|
||||
|
||||
expectedException.expect(IllegalArgumentException.class);
|
||||
|
||||
connection.clusterMeet(null);
|
||||
void clusterMeetShouldThrowExceptionWhenNodeIsNull() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> connection.clusterMeet(null));
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-315, DATAREDIS-890
|
||||
public void clusterForgetShouldSendCommandsToRemainingNodesCorrectly() {
|
||||
void clusterForgetShouldSendCommandsToRemainingNodesCorrectly() {
|
||||
|
||||
connection.clusterForget(CLUSTER_NODE_2);
|
||||
|
||||
@@ -146,7 +140,7 @@ public class JedisClusterConnectionUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-315, DATAREDIS-890
|
||||
public void clusterReplicateShouldSendCommandsCorrectly() {
|
||||
void clusterReplicateShouldSendCommandsCorrectly() {
|
||||
|
||||
connection.clusterReplicate(CLUSTER_NODE_1, CLUSTER_NODE_2);
|
||||
|
||||
@@ -157,7 +151,7 @@ public class JedisClusterConnectionUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-315
|
||||
public void closeShouldNotCloseUnderlyingClusterPool() throws IOException {
|
||||
void closeShouldNotCloseUnderlyingClusterPool() throws IOException {
|
||||
|
||||
connection.close();
|
||||
|
||||
@@ -165,7 +159,7 @@ public class JedisClusterConnectionUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-315
|
||||
public void isClosedShouldReturnConnectionStateCorrectly() {
|
||||
void isClosedShouldReturnConnectionStateCorrectly() {
|
||||
|
||||
assertThat(connection.isClosed()).isFalse();
|
||||
|
||||
@@ -175,7 +169,7 @@ public class JedisClusterConnectionUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-315
|
||||
public void clusterInfoShouldBeReturnedCorrectly() {
|
||||
void clusterInfoShouldBeReturnedCorrectly() {
|
||||
|
||||
when(con1Mock.clusterInfo()).thenReturn(CLUSTER_INFO_RESPONSE);
|
||||
when(con2Mock.clusterInfo()).thenReturn(CLUSTER_INFO_RESPONSE);
|
||||
@@ -188,7 +182,7 @@ public class JedisClusterConnectionUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-315
|
||||
public void clusterSetSlotImportingShouldBeExecutedCorrectly() {
|
||||
void clusterSetSlotImportingShouldBeExecutedCorrectly() {
|
||||
|
||||
connection.clusterSetSlot(CLUSTER_NODE_1, 100, AddSlots.IMPORTING);
|
||||
|
||||
@@ -196,7 +190,7 @@ public class JedisClusterConnectionUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-315
|
||||
public void clusterSetSlotMigratingShouldBeExecutedCorrectly() {
|
||||
void clusterSetSlotMigratingShouldBeExecutedCorrectly() {
|
||||
|
||||
connection.clusterSetSlot(CLUSTER_NODE_1, 100, AddSlots.MIGRATING);
|
||||
|
||||
@@ -204,7 +198,7 @@ public class JedisClusterConnectionUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-315
|
||||
public void clusterSetSlotStableShouldBeExecutedCorrectly() {
|
||||
void clusterSetSlotStableShouldBeExecutedCorrectly() {
|
||||
|
||||
connection.clusterSetSlot(CLUSTER_NODE_1, 100, AddSlots.STABLE);
|
||||
|
||||
@@ -212,7 +206,7 @@ public class JedisClusterConnectionUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-315
|
||||
public void clusterSetSlotNodeShouldBeExecutedCorrectly() {
|
||||
void clusterSetSlotNodeShouldBeExecutedCorrectly() {
|
||||
|
||||
connection.clusterSetSlot(CLUSTER_NODE_1, 100, AddSlots.NODE);
|
||||
|
||||
@@ -220,7 +214,7 @@ public class JedisClusterConnectionUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-315
|
||||
public void clusterSetSlotShouldBeExecutedOnTargetNodeWhenNodeIdNotSet() {
|
||||
void clusterSetSlotShouldBeExecutedOnTargetNodeWhenNodeIdNotSet() {
|
||||
|
||||
connection.clusterSetSlot(new RedisClusterNode(CLUSTER_HOST, MASTER_NODE_2_PORT), 100, AddSlots.IMPORTING);
|
||||
|
||||
@@ -228,12 +222,12 @@ public class JedisClusterConnectionUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-315
|
||||
public void clusterSetSlotShouldThrowExceptionWhenModeIsNull() {
|
||||
void clusterSetSlotShouldThrowExceptionWhenModeIsNull() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> connection.clusterSetSlot(CLUSTER_NODE_1, 100, null));
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-315
|
||||
public void clusterDeleteSlotsShouldBeExecutedCorrectly() {
|
||||
void clusterDeleteSlotsShouldBeExecutedCorrectly() {
|
||||
|
||||
int[] slots = new int[] { 9000, 10000 };
|
||||
connection.clusterDeleteSlots(CLUSTER_NODE_2, slots);
|
||||
@@ -242,12 +236,12 @@ public class JedisClusterConnectionUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-315
|
||||
public void clusterDeleteSlotShouldThrowExceptionWhenNodeIsNull() {
|
||||
void clusterDeleteSlotShouldThrowExceptionWhenNodeIsNull() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> connection.clusterDeleteSlots(null, new int[] { 1 }));
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-315
|
||||
public void timeShouldBeExecutedOnArbitraryNode() {
|
||||
void timeShouldBeExecutedOnArbitraryNode() {
|
||||
|
||||
List<String> values = Arrays.asList("1449655759", "92217");
|
||||
when(con1Mock.time()).thenReturn(values);
|
||||
@@ -260,7 +254,7 @@ public class JedisClusterConnectionUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-679
|
||||
public void shouldFailWithUnknownNode() {
|
||||
void shouldFailWithUnknownNode() {
|
||||
|
||||
try {
|
||||
connection.serverCommands().dbSize(new RedisClusterNode(CLUSTER_HOST, SLAVEOF_NODE_1_PORT));
|
||||
@@ -271,18 +265,17 @@ public class JedisClusterConnectionUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-679
|
||||
public void shouldFailWithAbsentConnection() {
|
||||
void shouldFailWithAbsentConnection() {
|
||||
|
||||
nodes.remove(CLUSTER_HOST + ":" + MASTER_NODE_3_PORT);
|
||||
|
||||
expectedException.expect(DataAccessResourceFailureException.class);
|
||||
expectedException.expectMessage("Node " + CLUSTER_HOST + ":" + MASTER_NODE_3_PORT + " is unknown to cluster");
|
||||
|
||||
connection.serverCommands().dbSize(new RedisClusterNode(CLUSTER_HOST, MASTER_NODE_3_PORT));
|
||||
assertThatExceptionOfType(DataAccessResourceFailureException.class)
|
||||
.isThrownBy(() -> connection.serverCommands().dbSize(new RedisClusterNode(CLUSTER_HOST, MASTER_NODE_3_PORT)))
|
||||
.withMessageContaining("Node " + CLUSTER_HOST + ":" + MASTER_NODE_3_PORT + " is unknown to cluster");
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-679
|
||||
public void shouldReconfigureJedisWithDiscoveredNode() {
|
||||
void shouldReconfigureJedisWithDiscoveredNode() {
|
||||
|
||||
nodes.remove(CLUSTER_HOST + ":" + MASTER_NODE_3_PORT);
|
||||
|
||||
@@ -306,7 +299,7 @@ public class JedisClusterConnectionUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-315, DATAREDIS-890
|
||||
public void timeShouldBeExecutedOnSingleNode() {
|
||||
void timeShouldBeExecutedOnSingleNode() {
|
||||
|
||||
when(con2Mock.time()).thenReturn(Arrays.asList("1449655759", "92217"));
|
||||
|
||||
@@ -320,7 +313,7 @@ public class JedisClusterConnectionUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-315
|
||||
public void resetConfigStatsShouldBeExecutedOnAllNodes() {
|
||||
void resetConfigStatsShouldBeExecutedOnAllNodes() {
|
||||
|
||||
connection.resetConfigStats();
|
||||
|
||||
@@ -330,7 +323,7 @@ public class JedisClusterConnectionUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-315, DATAREDIS-890
|
||||
public void resetConfigStatsShouldBeExecutedOnSingleNodeCorrectly() {
|
||||
void resetConfigStatsShouldBeExecutedOnSingleNodeCorrectly() {
|
||||
|
||||
connection.resetConfigStats(CLUSTER_NODE_2);
|
||||
|
||||
@@ -341,22 +334,19 @@ public class JedisClusterConnectionUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-315
|
||||
public void clusterTopologyProviderShouldCollectErrorsWhenLoadingNodes() {
|
||||
|
||||
expectedException.expect(ClusterStateFailureException.class);
|
||||
expectedException.expectMessage("127.0.0.1:7379 failed: o.O");
|
||||
expectedException.expectMessage("127.0.0.1:7380 failed: o.1");
|
||||
expectedException.expectMessage("127.0.0.1:7381 failed: o.2");
|
||||
void clusterTopologyProviderShouldCollectErrorsWhenLoadingNodes() {
|
||||
|
||||
when(con1Mock.clusterNodes()).thenThrow(new JedisConnectionException("o.O"));
|
||||
when(con2Mock.clusterNodes()).thenThrow(new JedisConnectionException("o.1"));
|
||||
when(con3Mock.clusterNodes()).thenThrow(new JedisConnectionException("o.2"));
|
||||
|
||||
new JedisClusterTopologyProvider(clusterMock).getTopology();
|
||||
assertThatExceptionOfType(ClusterStateFailureException.class)
|
||||
.isThrownBy(() -> new JedisClusterTopologyProvider(clusterMock).getTopology())
|
||||
.withMessageContaining("127.0.0.1:7379 failed: o.O").withMessageContaining("127.0.0.1:7380 failed: o.1");
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-603
|
||||
public void translatesUnknownExceptions() {
|
||||
void translatesUnknownExceptions() {
|
||||
|
||||
IllegalArgumentException exception = new IllegalArgumentException("Aw, snap!");
|
||||
|
||||
@@ -368,7 +358,7 @@ public class JedisClusterConnectionUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-794
|
||||
public void clusterTopologyProviderShouldUseCachedTopology() {
|
||||
void clusterTopologyProviderShouldUseCachedTopology() {
|
||||
|
||||
when(clusterMock.getClusterNodes()).thenReturn(Collections.singletonMap("mock", node1PoolMock));
|
||||
when(con1Mock.clusterNodes()).thenReturn(CLUSTER_NODES_RESPONSE);
|
||||
@@ -381,7 +371,7 @@ public class JedisClusterConnectionUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-794
|
||||
public void clusterTopologyProviderShouldRequestTopology() {
|
||||
void clusterTopologyProviderShouldRequestTopology() {
|
||||
|
||||
when(clusterMock.getClusterNodes()).thenReturn(Collections.singletonMap("mock", node1PoolMock));
|
||||
when(con1Mock.clusterNodes()).thenReturn(CLUSTER_NODES_RESPONSE);
|
||||
|
||||
@@ -19,24 +19,25 @@ import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import redis.clients.jedis.JedisShardInfo;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.data.redis.SettingsUtils;
|
||||
import org.springframework.data.redis.connection.RedisConnection;
|
||||
import org.springframework.data.redis.connection.RedisStandaloneConfiguration;
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
/**
|
||||
* Integration tests for {@link JedisConnectionFactory}.
|
||||
*
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
public class JedisConnectionFactoryIntegrationTests {
|
||||
class JedisConnectionFactoryIntegrationTests {
|
||||
|
||||
private JedisConnectionFactory factory;
|
||||
private @Nullable JedisConnectionFactory factory;
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
@AfterEach
|
||||
void tearDown() {
|
||||
|
||||
if (factory != null) {
|
||||
factory.destroy();
|
||||
@@ -44,7 +45,7 @@ public class JedisConnectionFactoryIntegrationTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-574
|
||||
public void shardInfoShouldOverrideFactorySettings() {
|
||||
void shardInfoShouldOverrideFactorySettings() {
|
||||
|
||||
factory = new JedisConnectionFactory(new JedisShardInfo(SettingsUtils.getHost(), SettingsUtils.getPort()));
|
||||
factory.setUsePool(false);
|
||||
@@ -57,7 +58,7 @@ public class JedisConnectionFactoryIntegrationTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-574
|
||||
public void shouldInitializeWithStandaloneConfiguration() {
|
||||
void shouldInitializeWithStandaloneConfiguration() {
|
||||
|
||||
factory = new JedisConnectionFactory(
|
||||
new RedisStandaloneConfiguration(SettingsUtils.getHost(), SettingsUtils.getPort()),
|
||||
@@ -68,7 +69,7 @@ public class JedisConnectionFactoryIntegrationTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-575
|
||||
public void connectionAppliesClientName() {
|
||||
void connectionAppliesClientName() {
|
||||
|
||||
factory = new JedisConnectionFactory(
|
||||
new RedisStandaloneConfiguration(SettingsUtils.getHost(), SettingsUtils.getPort()),
|
||||
|
||||
@@ -17,12 +17,13 @@ package org.springframework.data.redis.connection.jedis;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.data.redis.connection.RedisConnection;
|
||||
import org.springframework.data.redis.connection.RedisSentinelConfiguration;
|
||||
import org.springframework.data.redis.test.util.RedisSentinelRule;
|
||||
import org.springframework.data.redis.test.condition.EnabledOnRedisSentinelAvailable;
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
/**
|
||||
* Sentinel integration tests for {@link JedisConnectionFactory}.
|
||||
@@ -32,16 +33,15 @@ import org.springframework.data.redis.test.util.RedisSentinelRule;
|
||||
* @author Mark Paluch
|
||||
* @author Ajith Kumar
|
||||
*/
|
||||
public class JedisConnectionFactorySentinelIntegrationTests {
|
||||
@EnabledOnRedisSentinelAvailable
|
||||
class JedisConnectionFactorySentinelIntegrationTests {
|
||||
|
||||
private static final RedisSentinelConfiguration SENTINEL_CONFIG = new RedisSentinelConfiguration().master("mymaster")
|
||||
.sentinel("127.0.0.1", 26379).sentinel("127.0.0.1", 26380);
|
||||
private JedisConnectionFactory factory;
|
||||
private @Nullable JedisConnectionFactory factory;
|
||||
|
||||
public @Rule RedisSentinelRule sentinelRule = RedisSentinelRule.forConfig(SENTINEL_CONFIG).oneActive();
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
@AfterEach
|
||||
void tearDown() {
|
||||
|
||||
if (factory != null) {
|
||||
factory.destroy();
|
||||
@@ -49,7 +49,7 @@ public class JedisConnectionFactorySentinelIntegrationTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-574, DATAREDIS-765
|
||||
public void shouldInitializeWithSentinelConfiguration() {
|
||||
void shouldInitializeWithSentinelConfiguration() {
|
||||
|
||||
JedisClientConfiguration clientConfiguration = JedisClientConfiguration.builder() //
|
||||
.clientName("clientName") //
|
||||
@@ -65,7 +65,7 @@ public class JedisConnectionFactorySentinelIntegrationTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-324
|
||||
public void shouldSendCommandCorrectlyViaConnectionFactoryUsingSentinel() {
|
||||
void shouldSendCommandCorrectlyViaConnectionFactoryUsingSentinel() {
|
||||
|
||||
factory = new JedisConnectionFactory(SENTINEL_CONFIG);
|
||||
factory.afterPropertiesSet();
|
||||
@@ -74,7 +74,7 @@ public class JedisConnectionFactorySentinelIntegrationTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-552
|
||||
public void getClientNameShouldEqualWithFactorySetting() {
|
||||
void getClientNameShouldEqualWithFactorySetting() {
|
||||
|
||||
factory = new JedisConnectionFactory(SENTINEL_CONFIG);
|
||||
factory.setClientName("clientName");
|
||||
@@ -84,7 +84,7 @@ public class JedisConnectionFactorySentinelIntegrationTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-1127
|
||||
public void shouldNotFailOnFirstSentinelDown() {
|
||||
void shouldNotFailOnFirstSentinelDown() {
|
||||
|
||||
RedisSentinelConfiguration oneDownSentinelConfig = new RedisSentinelConfiguration().master("mymaster")
|
||||
.sentinel("any.unavailable.host", 26379).sentinel("127.0.0.1", 26379);
|
||||
|
||||
@@ -18,6 +18,11 @@ package org.springframework.data.redis.connection.jedis;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import redis.clients.jedis.JedisCluster;
|
||||
import redis.clients.jedis.JedisClusterConnectionHandler;
|
||||
import redis.clients.jedis.JedisClusterInfoCache;
|
||||
import redis.clients.jedis.JedisPoolConfig;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.time.Duration;
|
||||
@@ -30,16 +35,15 @@ import javax.net.ssl.SSLParameters;
|
||||
import javax.net.ssl.SSLSocketFactory;
|
||||
|
||||
import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
|
||||
import org.junit.Test;
|
||||
import redis.clients.jedis.JedisCluster;
|
||||
import redis.clients.jedis.JedisClusterConnectionHandler;
|
||||
import redis.clients.jedis.JedisClusterInfoCache;
|
||||
import redis.clients.jedis.JedisPoolConfig;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.data.redis.connection.RedisClusterConfiguration;
|
||||
import org.springframework.data.redis.connection.RedisClusterConnection;
|
||||
import org.springframework.data.redis.connection.RedisPassword;
|
||||
import org.springframework.data.redis.connection.RedisSentinelConfiguration;
|
||||
import org.springframework.data.redis.connection.RedisStandaloneConfiguration;
|
||||
import org.springframework.data.redis.connection.jedis.extension.JedisConnectionFactoryExtension;
|
||||
import org.springframework.data.redis.test.extension.RedisStanalone;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
|
||||
/**
|
||||
@@ -48,7 +52,7 @@ import org.springframework.test.util.ReflectionTestUtils;
|
||||
* @author Christoph Strobl
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
public class JedisConnectionFactoryUnitTests {
|
||||
class JedisConnectionFactoryUnitTests {
|
||||
|
||||
private JedisConnectionFactory connectionFactory;
|
||||
|
||||
@@ -59,7 +63,7 @@ public class JedisConnectionFactoryUnitTests {
|
||||
.clusterNode("127.0.0.1", 6379).clusterNode("127.0.0.1", 6380);
|
||||
|
||||
@Test // DATAREDIS-324
|
||||
public void shouldInitSentinelPoolWhenSentinelConfigPresent() {
|
||||
void shouldInitSentinelPoolWhenSentinelConfigPresent() {
|
||||
|
||||
connectionFactory = initSpyedConnectionFactory(SINGLE_SENTINEL_CONFIG, new JedisPoolConfig());
|
||||
connectionFactory.afterPropertiesSet();
|
||||
@@ -69,7 +73,7 @@ public class JedisConnectionFactoryUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-324
|
||||
public void shouldInitJedisPoolWhenNoSentinelConfigPresent() {
|
||||
void shouldInitJedisPoolWhenNoSentinelConfigPresent() {
|
||||
|
||||
connectionFactory = initSpyedConnectionFactory((RedisSentinelConfiguration) null, new JedisPoolConfig());
|
||||
connectionFactory.afterPropertiesSet();
|
||||
@@ -78,16 +82,16 @@ public class JedisConnectionFactoryUnitTests {
|
||||
verify(connectionFactory, never()).createRedisSentinelPool(any(RedisSentinelConfiguration.class));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalStateException.class) // DATAREDIS-765
|
||||
public void shouldRejectPoolDisablingWhenSentinelConfigPresent() {
|
||||
@Test // DATAREDIS-765
|
||||
void shouldRejectPoolDisablingWhenSentinelConfigPresent() {
|
||||
|
||||
connectionFactory = new JedisConnectionFactory(new RedisSentinelConfiguration());
|
||||
|
||||
connectionFactory.setUsePool(false);
|
||||
assertThatIllegalStateException().isThrownBy(() -> connectionFactory.setUsePool(false));
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-315
|
||||
public void shouldInitConnectionCorrectlyWhenClusterConfigPresent() {
|
||||
void shouldInitConnectionCorrectlyWhenClusterConfigPresent() {
|
||||
|
||||
connectionFactory = initSpyedConnectionFactory(CLUSTER_CONFIG, new JedisPoolConfig());
|
||||
connectionFactory.afterPropertiesSet();
|
||||
@@ -98,19 +102,17 @@ public class JedisConnectionFactoryUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-315
|
||||
public void shouldCloseClusterCorrectlyOnFactoryDestruction() throws IOException {
|
||||
void shouldCloseClusterCorrectlyOnFactoryDestruction() throws IOException {
|
||||
|
||||
JedisCluster clusterMock = mock(JedisCluster.class);
|
||||
JedisConnectionFactory factory = new JedisConnectionFactory();
|
||||
ReflectionTestUtils.setField(factory, "cluster", clusterMock);
|
||||
|
||||
factory.destroy();
|
||||
|
||||
verify(clusterMock, times(1)).close();
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-574
|
||||
public void shouldReadStandalonePassword() {
|
||||
void shouldReadStandalonePassword() {
|
||||
|
||||
RedisStandaloneConfiguration envConfig = new RedisStandaloneConfiguration();
|
||||
envConfig.setPassword(RedisPassword.of("foo"));
|
||||
@@ -121,7 +123,7 @@ public class JedisConnectionFactoryUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-574
|
||||
public void shouldWriteStandalonePassword() {
|
||||
void shouldWriteStandalonePassword() {
|
||||
|
||||
RedisStandaloneConfiguration envConfig = new RedisStandaloneConfiguration();
|
||||
envConfig.setPassword(RedisPassword.of("foo"));
|
||||
@@ -134,7 +136,7 @@ public class JedisConnectionFactoryUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-574
|
||||
public void shouldReadSentinelPassword() {
|
||||
void shouldReadSentinelPassword() {
|
||||
|
||||
RedisSentinelConfiguration envConfig = new RedisSentinelConfiguration();
|
||||
envConfig.setPassword(RedisPassword.of("foo"));
|
||||
@@ -145,7 +147,7 @@ public class JedisConnectionFactoryUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-574
|
||||
public void shouldWriteSentinelPassword() {
|
||||
void shouldWriteSentinelPassword() {
|
||||
|
||||
RedisSentinelConfiguration envConfig = new RedisSentinelConfiguration();
|
||||
envConfig.setPassword(RedisPassword.of("foo"));
|
||||
@@ -158,7 +160,7 @@ public class JedisConnectionFactoryUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-574
|
||||
public void shouldReadClusterPassword() {
|
||||
void shouldReadClusterPassword() {
|
||||
|
||||
RedisClusterConfiguration envConfig = new RedisClusterConfiguration();
|
||||
envConfig.setPassword(RedisPassword.of("foo"));
|
||||
@@ -169,7 +171,7 @@ public class JedisConnectionFactoryUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-574
|
||||
public void shouldWriteClusterPassword() {
|
||||
void shouldWriteClusterPassword() {
|
||||
|
||||
RedisClusterConfiguration envConfig = new RedisClusterConfiguration();
|
||||
envConfig.setPassword(RedisPassword.of("foo"));
|
||||
@@ -182,7 +184,7 @@ public class JedisConnectionFactoryUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-574
|
||||
public void shouldReadStandaloneDatabaseIndex() {
|
||||
void shouldReadStandaloneDatabaseIndex() {
|
||||
|
||||
RedisStandaloneConfiguration envConfig = new RedisStandaloneConfiguration();
|
||||
envConfig.setDatabase(2);
|
||||
@@ -193,7 +195,7 @@ public class JedisConnectionFactoryUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-574
|
||||
public void shouldWriteStandaloneDatabaseIndex() {
|
||||
void shouldWriteStandaloneDatabaseIndex() {
|
||||
|
||||
RedisStandaloneConfiguration envConfig = new RedisStandaloneConfiguration();
|
||||
envConfig.setDatabase(2);
|
||||
@@ -206,7 +208,7 @@ public class JedisConnectionFactoryUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-574
|
||||
public void shouldReadSentinelDatabaseIndex() {
|
||||
void shouldReadSentinelDatabaseIndex() {
|
||||
|
||||
RedisSentinelConfiguration envConfig = new RedisSentinelConfiguration();
|
||||
envConfig.setDatabase(2);
|
||||
@@ -217,7 +219,7 @@ public class JedisConnectionFactoryUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-574
|
||||
public void shouldWriteSentinelDatabaseIndex() {
|
||||
void shouldWriteSentinelDatabaseIndex() {
|
||||
|
||||
RedisSentinelConfiguration envConfig = new RedisSentinelConfiguration();
|
||||
envConfig.setDatabase(2);
|
||||
@@ -230,13 +232,13 @@ public class JedisConnectionFactoryUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-574
|
||||
public void shouldApplyClientConfiguration() throws NoSuchAlgorithmException {
|
||||
void shouldApplyClientConfiguration() throws NoSuchAlgorithmException {
|
||||
|
||||
SSLParameters sslParameters = new SSLParameters();
|
||||
SSLContext context = SSLContext.getDefault();
|
||||
SSLSocketFactory socketFactory = context.getSocketFactory();
|
||||
JedisPoolConfig poolConfig = new JedisPoolConfig();
|
||||
|
||||
|
||||
JedisClientConfiguration configuration = JedisClientConfiguration.builder().useSsl() //
|
||||
.hostnameVerifier(HttpsURLConnection.getDefaultHostnameVerifier()) //
|
||||
.sslParameters(sslParameters) //
|
||||
@@ -258,7 +260,7 @@ public class JedisConnectionFactoryUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-574
|
||||
public void shouldReturnStandaloneConfiguration() {
|
||||
void shouldReturnStandaloneConfiguration() {
|
||||
|
||||
RedisStandaloneConfiguration configuration = new RedisStandaloneConfiguration();
|
||||
connectionFactory = new JedisConnectionFactory(configuration, JedisClientConfiguration.defaultConfiguration());
|
||||
@@ -269,7 +271,7 @@ public class JedisConnectionFactoryUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-574
|
||||
public void shouldReturnSentinelConfiguration() {
|
||||
void shouldReturnSentinelConfiguration() {
|
||||
|
||||
RedisSentinelConfiguration configuration = new RedisSentinelConfiguration();
|
||||
connectionFactory = new JedisConnectionFactory(configuration, JedisClientConfiguration.defaultConfiguration());
|
||||
@@ -280,7 +282,7 @@ public class JedisConnectionFactoryUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-574
|
||||
public void shouldReturnClusterConfiguration() {
|
||||
void shouldReturnClusterConfiguration() {
|
||||
|
||||
RedisClusterConfiguration configuration = new RedisClusterConfiguration();
|
||||
connectionFactory = new JedisConnectionFactory(configuration, JedisClientConfiguration.defaultConfiguration());
|
||||
@@ -291,7 +293,7 @@ public class JedisConnectionFactoryUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-974
|
||||
public void shouldApplySslConfigWhenCreatingClusterClient() throws NoSuchAlgorithmException {
|
||||
void shouldApplySslConfigWhenCreatingClusterClient() throws NoSuchAlgorithmException {
|
||||
|
||||
SSLParameters sslParameters = new SSLParameters();
|
||||
SSLContext context = SSLContext.getDefault();
|
||||
@@ -333,13 +335,13 @@ public class JedisConnectionFactoryUnitTests {
|
||||
assertThat(ReflectionTestUtils.getField(cache, "hostAndPortMap")).isNull();
|
||||
}
|
||||
|
||||
@Test(expected = IllegalStateException.class) // DATAREDIS-574
|
||||
public void shouldDenyChangesToImmutableClientConfiguration() throws NoSuchAlgorithmException {
|
||||
@Test // DATAREDIS-574
|
||||
void shouldDenyChangesToImmutableClientConfiguration() throws NoSuchAlgorithmException {
|
||||
|
||||
connectionFactory = new JedisConnectionFactory(new RedisStandaloneConfiguration(),
|
||||
JedisClientConfiguration.defaultConfiguration());
|
||||
|
||||
connectionFactory.setClientName("foo");
|
||||
assertThatIllegalStateException().isThrownBy(() -> connectionFactory.setClientName("foo"));
|
||||
}
|
||||
|
||||
private JedisConnectionFactory initSpyedConnectionFactory(RedisSentinelConfiguration sentinelConfig,
|
||||
|
||||
@@ -27,34 +27,30 @@ import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Suite;
|
||||
import org.junit.runners.Suite.SuiteClasses;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Nested;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
|
||||
import org.springframework.dao.InvalidDataAccessResourceUsageException;
|
||||
import org.springframework.data.redis.connection.AbstractConnectionUnitTestBase;
|
||||
import org.springframework.data.redis.connection.RedisServerCommands.ShutdownOption;
|
||||
import org.springframework.data.redis.connection.RedisZSetCommands.Tuple;
|
||||
import org.springframework.data.redis.connection.jedis.JedisConnectionUnitTestSuite.JedisConnectionPipelineUnitTests;
|
||||
import org.springframework.data.redis.connection.jedis.JedisConnectionUnitTestSuite.JedisConnectionUnitTests;
|
||||
import org.springframework.data.redis.core.Cursor;
|
||||
import org.springframework.data.redis.core.ScanOptions;
|
||||
|
||||
/**
|
||||
* @author Christoph Strobl
|
||||
*/
|
||||
@RunWith(Suite.class)
|
||||
@SuiteClasses({ JedisConnectionUnitTests.class, JedisConnectionPipelineUnitTests.class })
|
||||
public class JedisConnectionUnitTestSuite {
|
||||
class JedisConnectionUnitTests {
|
||||
|
||||
public static class JedisConnectionUnitTests extends AbstractConnectionUnitTestBase<Client> {
|
||||
@Nested
|
||||
public class BasicUnitTests extends AbstractConnectionUnitTestBase<Client> {
|
||||
|
||||
protected JedisConnection connection;
|
||||
private Jedis jedisSpy;
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
|
||||
jedisSpy = spy(new MockedClientJedis("http://localhost:1234", getNativeRedisConnectionMock()));
|
||||
@@ -62,7 +58,7 @@ public class JedisConnectionUnitTestSuite {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-184
|
||||
public void shutdownWithNullShouldDelegateCommandCorrectly() {
|
||||
void shutdownWithNullShouldDelegateCommandCorrectly() {
|
||||
|
||||
connection.shutdown(null);
|
||||
|
||||
@@ -106,7 +102,7 @@ public class JedisConnectionUnitTestSuite {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-277
|
||||
public void slaveOfShouldThrowExectpionWhenCalledForNullHost() {
|
||||
void slaveOfShouldThrowExectpionWhenCalledForNullHost() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> connection.slaveOf(null, 0));
|
||||
}
|
||||
|
||||
@@ -125,37 +121,37 @@ public class JedisConnectionUnitTestSuite {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-330
|
||||
public void shouldThrowExceptionWhenAccessingRedisSentinelsCommandsWhenNoSentinelsConfigured() {
|
||||
void shouldThrowExceptionWhenAccessingRedisSentinelsCommandsWhenNoSentinelsConfigured() {
|
||||
assertThatExceptionOfType(InvalidDataAccessResourceUsageException.class)
|
||||
.isThrownBy(() -> connection.getSentinelConnection());
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-472
|
||||
public void restoreShouldThrowExceptionWhenTtlInMillisExceedsIntegerRange() {
|
||||
void restoreShouldThrowExceptionWhenTtlInMillisExceedsIntegerRange() {
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> connection.restore("foo".getBytes(), (long) Integer.MAX_VALUE + 1L, "bar".getBytes()));
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-472
|
||||
public void setExShouldThrowExceptionWhenTimeExceedsIntegerRange() {
|
||||
void setExShouldThrowExceptionWhenTimeExceedsIntegerRange() {
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> connection.setEx("foo".getBytes(), (long) Integer.MAX_VALUE + 1L, "bar".getBytes()));
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-472
|
||||
public void sRandMemberShouldThrowExceptionWhenCountExceedsIntegerRange() {
|
||||
void sRandMemberShouldThrowExceptionWhenCountExceedsIntegerRange() {
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> connection.sRandMember("foo".getBytes(), (long) Integer.MAX_VALUE + 1L));
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-472
|
||||
public void zRangeByScoreShouldThrowExceptionWhenOffsetExceedsIntegerRange() {
|
||||
void zRangeByScoreShouldThrowExceptionWhenOffsetExceedsIntegerRange() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> connection.zRangeByScore("foo".getBytes(), "foo", "bar",
|
||||
(long) Integer.MAX_VALUE + 1L, Integer.MAX_VALUE));
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-472
|
||||
public void zRangeByScoreShouldThrowExceptionWhenCountExceedsIntegerRange() {
|
||||
void zRangeByScoreShouldThrowExceptionWhenCountExceedsIntegerRange() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> connection.zRangeByScore("foo".getBytes(), "foo", "bar",
|
||||
Integer.MAX_VALUE, (long) Integer.MAX_VALUE + 1L));
|
||||
}
|
||||
@@ -253,7 +249,7 @@ public class JedisConnectionUnitTestSuite {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-714
|
||||
public void doesNotSelectDbWhenCurrentDbMatchesDesiredOne() {
|
||||
void doesNotSelectDbWhenCurrentDbMatchesDesiredOne() {
|
||||
|
||||
Jedis jedisSpy = spy(new MockedClientJedis("http://localhost:1234", getNativeRedisConnectionMock()));
|
||||
new JedisConnection(jedisSpy);
|
||||
@@ -262,7 +258,7 @@ public class JedisConnectionUnitTestSuite {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-714
|
||||
public void doesNotSelectDbWhenCurrentDbDoesNotMatchDesiredOne() {
|
||||
void doesNotSelectDbWhenCurrentDbDoesNotMatchDesiredOne() {
|
||||
|
||||
Jedis jedisSpy = spy(new MockedClientJedis("http://localhost:1234", getNativeRedisConnectionMock()));
|
||||
when(jedisSpy.getDB()).thenReturn(3);
|
||||
@@ -273,9 +269,10 @@ public class JedisConnectionUnitTestSuite {
|
||||
}
|
||||
}
|
||||
|
||||
public static class JedisConnectionPipelineUnitTests extends JedisConnectionUnitTests {
|
||||
@Nested
|
||||
public class JedisConnectionPipelineUnitTests extends BasicUnitTests {
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
super.setUp();
|
||||
connection.openPipeline();
|
||||
@@ -380,7 +377,7 @@ public class JedisConnectionUnitTestSuite {
|
||||
*/
|
||||
private static class MockedClientJedis extends Jedis {
|
||||
|
||||
public MockedClientJedis(String host, Client client) {
|
||||
MockedClientJedis(String host, Client client) {
|
||||
super(host);
|
||||
this.client = client;
|
||||
}
|
||||
@@ -17,6 +17,7 @@ package org.springframework.data.redis.connection.jedis;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import redis.clients.jedis.params.SetParams;
|
||||
|
||||
import java.util.Arrays;
|
||||
@@ -26,8 +27,6 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.data.redis.connection.RedisServer;
|
||||
import org.springframework.data.redis.connection.RedisStringCommands.SetOption;
|
||||
import org.springframework.data.redis.connection.RedisZSetCommands.Range;
|
||||
@@ -37,23 +36,23 @@ import org.springframework.data.redis.core.types.RedisClientInfo;
|
||||
/**
|
||||
* @author Christoph Strobl
|
||||
*/
|
||||
public class JedisConvertersUnitTests {
|
||||
class JedisConvertersUnitTests {
|
||||
|
||||
private static final String CLIENT_ALL_SINGLE_LINE_RESPONSE = "addr=127.0.0.1:60311 fd=6 name= age=4059 idle=0 flags=N db=0 sub=0 psub=0 multi=-1 qbuf=0 qbuf-free=32768 obl=0 oll=0 omem=0 events=r cmd=client";
|
||||
|
||||
@Test // DATAREDIS-268
|
||||
public void convertingEmptyStringToListOfRedisClientInfoShouldReturnEmptyList() {
|
||||
void convertingEmptyStringToListOfRedisClientInfoShouldReturnEmptyList() {
|
||||
assertThat(JedisConverters.toListOfRedisClientInformation("")).isEqualTo(Collections.<RedisClientInfo> emptyList());
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-268
|
||||
public void convertingNullToListOfRedisClientInfoShouldReturnEmptyList() {
|
||||
void convertingNullToListOfRedisClientInfoShouldReturnEmptyList() {
|
||||
assertThat(JedisConverters.toListOfRedisClientInformation(null))
|
||||
.isEqualTo(Collections.<RedisClientInfo> emptyList());
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-268
|
||||
public void convertingMultipleLiesToListOfRedisClientInfoReturnsListCorrectly() {
|
||||
void convertingMultipleLiesToListOfRedisClientInfoReturnsListCorrectly() {
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(CLIENT_ALL_SINGLE_LINE_RESPONSE);
|
||||
@@ -64,7 +63,7 @@ public class JedisConvertersUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-330
|
||||
public void convertsSingleMapToRedisServerReturnsCollectionCorrectly() {
|
||||
void convertsSingleMapToRedisServerReturnsCollectionCorrectly() {
|
||||
|
||||
Map<String, String> values = getRedisServerInfoMap("mymaster", 23697);
|
||||
List<RedisServer> servers = JedisConverters.toListOfRedisServer(Collections.singletonList(values));
|
||||
@@ -74,7 +73,7 @@ public class JedisConvertersUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-330
|
||||
public void convertsMultipleMapsToRedisServerReturnsCollectionCorrectly() {
|
||||
void convertsMultipleMapsToRedisServerReturnsCollectionCorrectly() {
|
||||
|
||||
List<Map<String, String>> vals = Arrays.asList(getRedisServerInfoMap("mymaster", 23697),
|
||||
getRedisServerInfoMap("yourmaster", 23680));
|
||||
@@ -87,19 +86,19 @@ public class JedisConvertersUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-330
|
||||
public void convertsRedisServersCorrectlyWhenGivenAnEmptyList() {
|
||||
void convertsRedisServersCorrectlyWhenGivenAnEmptyList() {
|
||||
assertThat(JedisConverters.toListOfRedisServer(Collections.<Map<String, String>> emptyList())).isNotNull();
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-330
|
||||
public void convertsRedisServersCorrectlyWhenGivenNull() {
|
||||
void convertsRedisServersCorrectlyWhenGivenNull() {
|
||||
assertThat(JedisConverters.toListOfRedisServer(null)).isNotNull();
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
@Test
|
||||
public void boundaryToBytesForZRangeByLexShouldReturnDefaultValueWhenBoundaryIsNull() {
|
||||
void boundaryToBytesForZRangeByLexShouldReturnDefaultValueWhenBoundaryIsNull() {
|
||||
|
||||
byte[] defaultValue = "tyrion".getBytes();
|
||||
|
||||
@@ -107,7 +106,7 @@ public class JedisConvertersUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-378
|
||||
public void boundaryToBytesForZRangeByLexShouldReturnDefaultValueWhenBoundaryValueIsNull() {
|
||||
void boundaryToBytesForZRangeByLexShouldReturnDefaultValueWhenBoundaryValueIsNull() {
|
||||
|
||||
byte[] defaultValue = "tyrion".getBytes();
|
||||
|
||||
@@ -116,7 +115,7 @@ public class JedisConvertersUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-378
|
||||
public void boundaryToBytesForZRangeByLexShouldReturnValueCorrectlyWhenBoundaryIsIncluing() {
|
||||
void boundaryToBytesForZRangeByLexShouldReturnValueCorrectlyWhenBoundaryIsIncluing() {
|
||||
|
||||
assertThat(
|
||||
JedisConverters.boundaryToBytesForZRangeByLex(Range.range().gte(JedisConverters.toBytes("a")).getMin(), null))
|
||||
@@ -124,7 +123,7 @@ public class JedisConvertersUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-378
|
||||
public void boundaryToBytesForZRangeByLexShouldReturnValueCorrectlyWhenBoundaryIsExcluding() {
|
||||
void boundaryToBytesForZRangeByLexShouldReturnValueCorrectlyWhenBoundaryIsExcluding() {
|
||||
|
||||
assertThat(
|
||||
JedisConverters.boundaryToBytesForZRangeByLex(Range.range().gt(JedisConverters.toBytes("a")).getMin(), null))
|
||||
@@ -132,27 +131,27 @@ public class JedisConvertersUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-378
|
||||
public void boundaryToBytesForZRangeByLexShouldReturnValueCorrectlyWhenBoundaryIsAString() {
|
||||
void boundaryToBytesForZRangeByLexShouldReturnValueCorrectlyWhenBoundaryIsAString() {
|
||||
|
||||
assertThat(JedisConverters.boundaryToBytesForZRangeByLex(Range.range().gt("a").getMin(), null))
|
||||
.isEqualTo(JedisConverters.toBytes("(a"));
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-378
|
||||
public void boundaryToBytesForZRangeByLexShouldReturnValueCorrectlyWhenBoundaryIsANumber() {
|
||||
void boundaryToBytesForZRangeByLexShouldReturnValueCorrectlyWhenBoundaryIsANumber() {
|
||||
|
||||
assertThat(JedisConverters.boundaryToBytesForZRangeByLex(Range.range().gt(1L).getMin(), null))
|
||||
.isEqualTo(JedisConverters.toBytes("(1"));
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-378
|
||||
public void boundaryToBytesForZRangeByLexShouldThrowExceptionWhenBoundaryHoldsUnknownType() {
|
||||
void boundaryToBytesForZRangeByLexShouldThrowExceptionWhenBoundaryHoldsUnknownType() {
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> JedisConverters.boundaryToBytesForZRangeByLex(Range.range().gt(new Date()).getMin(), null));
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-352
|
||||
public void boundaryToBytesForZRangeByShouldReturnDefaultValueWhenBoundaryIsNull() {
|
||||
void boundaryToBytesForZRangeByShouldReturnDefaultValueWhenBoundaryIsNull() {
|
||||
|
||||
byte[] defaultValue = "tyrion".getBytes();
|
||||
|
||||
@@ -160,7 +159,7 @@ public class JedisConvertersUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-352
|
||||
public void boundaryToBytesForZRangeByShouldReturnDefaultValueWhenBoundaryValueIsNull() {
|
||||
void boundaryToBytesForZRangeByShouldReturnDefaultValueWhenBoundaryValueIsNull() {
|
||||
|
||||
byte[] defaultValue = "tyrion".getBytes();
|
||||
|
||||
@@ -169,61 +168,61 @@ public class JedisConvertersUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-352
|
||||
public void boundaryToBytesForZRangeByShouldReturnValueCorrectlyWhenBoundaryIsIncluing() {
|
||||
void boundaryToBytesForZRangeByShouldReturnValueCorrectlyWhenBoundaryIsIncluing() {
|
||||
|
||||
assertThat(JedisConverters.boundaryToBytesForZRange(Range.range().gte(JedisConverters.toBytes("a")).getMin(), null))
|
||||
.isEqualTo(JedisConverters.toBytes("a"));
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-352
|
||||
public void boundaryToBytesForZRangeByShouldReturnValueCorrectlyWhenBoundaryIsExcluding() {
|
||||
void boundaryToBytesForZRangeByShouldReturnValueCorrectlyWhenBoundaryIsExcluding() {
|
||||
|
||||
assertThat(JedisConverters.boundaryToBytesForZRange(Range.range().gt(JedisConverters.toBytes("a")).getMin(), null))
|
||||
.isEqualTo(JedisConverters.toBytes("(a"));
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-352
|
||||
public void boundaryToBytesForZRangeByShouldReturnValueCorrectlyWhenBoundaryIsAString() {
|
||||
void boundaryToBytesForZRangeByShouldReturnValueCorrectlyWhenBoundaryIsAString() {
|
||||
|
||||
assertThat(JedisConverters.boundaryToBytesForZRange(Range.range().gt("a").getMin(), null))
|
||||
.isEqualTo(JedisConverters.toBytes("(a"));
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-352
|
||||
public void boundaryToBytesForZRangeByShouldReturnValueCorrectlyWhenBoundaryIsANumber() {
|
||||
void boundaryToBytesForZRangeByShouldReturnValueCorrectlyWhenBoundaryIsANumber() {
|
||||
|
||||
assertThat(JedisConverters.boundaryToBytesForZRange(Range.range().gt(1L).getMin(), null))
|
||||
.isEqualTo(JedisConverters.toBytes("(1"));
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-352
|
||||
public void boundaryToBytesForZRangeByShouldThrowExceptionWhenBoundaryHoldsUnknownType() {
|
||||
void boundaryToBytesForZRangeByShouldThrowExceptionWhenBoundaryHoldsUnknownType() {
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> JedisConverters.boundaryToBytesForZRange(Range.range().gt(new Date()).getMin(), null));
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-316, DATAREDIS-749
|
||||
public void toSetCommandExPxOptionShouldReturnEXforSeconds() {
|
||||
void toSetCommandExPxOptionShouldReturnEXforSeconds() {
|
||||
assertThat(toString(JedisConverters.toSetCommandExPxArgument(Expiration.seconds(100)))).isEqualTo("ex 100");
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-316, DATAREDIS-749
|
||||
public void toSetCommandExPxOptionShouldReturnEXforMilliseconds() {
|
||||
void toSetCommandExPxOptionShouldReturnEXforMilliseconds() {
|
||||
assertThat(toString(JedisConverters.toSetCommandExPxArgument(Expiration.milliseconds(100)))).isEqualTo("px 100");
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-316, DATAREDIS-749
|
||||
public void toSetCommandNxXxOptionShouldReturnNXforAbsent() {
|
||||
void toSetCommandNxXxOptionShouldReturnNXforAbsent() {
|
||||
assertThat(toString(JedisConverters.toSetCommandNxXxArgument(SetOption.ifAbsent()))).isEqualTo("nx");
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-316, DATAREDIS-749
|
||||
public void toSetCommandNxXxOptionShouldReturnXXforAbsent() {
|
||||
void toSetCommandNxXxOptionShouldReturnXXforAbsent() {
|
||||
assertThat(toString(JedisConverters.toSetCommandNxXxArgument(SetOption.ifPresent()))).isEqualTo("xx");
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-316, DATAREDIS-749
|
||||
public void toSetCommandNxXxOptionShouldReturnEmptyArrayforUpsert() {
|
||||
void toSetCommandNxXxOptionShouldReturnEmptyArrayforUpsert() {
|
||||
assertThat(toString(JedisConverters.toSetCommandNxXxArgument(SetOption.upsert()))).isEqualTo("");
|
||||
}
|
||||
|
||||
|
||||
@@ -22,8 +22,7 @@ import redis.clients.jedis.exceptions.JedisAskDataException;
|
||||
import redis.clients.jedis.exceptions.JedisClusterMaxAttemptsException;
|
||||
import redis.clients.jedis.exceptions.JedisMovedDataException;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.data.redis.ClusterRedirectException;
|
||||
@@ -32,17 +31,12 @@ import org.springframework.data.redis.TooManyClusterRedirectionsException;
|
||||
/**
|
||||
* @author Christoph Strobl
|
||||
*/
|
||||
public class JedisExceptionConverterUnitTests {
|
||||
class JedisExceptionConverterUnitTests {
|
||||
|
||||
JedisExceptionConverter converter;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
converter = new JedisExceptionConverter();
|
||||
}
|
||||
private JedisExceptionConverter converter = new JedisExceptionConverter();
|
||||
|
||||
@Test // DATAREDIS-315
|
||||
public void shouldConvertMovedDataException() {
|
||||
void shouldConvertMovedDataException() {
|
||||
|
||||
DataAccessException converted = converter.convert(new JedisMovedDataException("MOVED 3999 127.0.0.1:6381",
|
||||
new HostAndPort("127.0.0.1", 6381), 3999));
|
||||
@@ -54,7 +48,7 @@ public class JedisExceptionConverterUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-315
|
||||
public void shouldConvertAskDataException() {
|
||||
void shouldConvertAskDataException() {
|
||||
|
||||
DataAccessException converted = converter.convert(new JedisAskDataException("ASK 3999 127.0.0.1:6381",
|
||||
new HostAndPort("127.0.0.1", 6381), 3999));
|
||||
@@ -66,7 +60,7 @@ public class JedisExceptionConverterUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-315
|
||||
public void shouldConvertMaxRedirectException() {
|
||||
void shouldConvertMaxRedirectException() {
|
||||
|
||||
DataAccessException converted = converter
|
||||
.convert(new JedisClusterMaxAttemptsException("Too many redirections?"));
|
||||
|
||||
@@ -20,11 +20,11 @@ import static org.mockito.Mockito.*;
|
||||
|
||||
import redis.clients.jedis.Jedis;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import org.springframework.data.redis.connection.RedisNode;
|
||||
import org.springframework.data.redis.connection.RedisNode.RedisNodeBuilder;
|
||||
@@ -33,26 +33,26 @@ import org.springframework.data.redis.connection.RedisServer;
|
||||
/**
|
||||
* @author Christoph Strobl
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class JedisSentinelConnectionUnitTests {
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class JedisSentinelConnectionUnitTests {
|
||||
|
||||
private @Mock Jedis jedisMock;
|
||||
|
||||
private JedisSentinelConnection connection;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
this.connection = new JedisSentinelConnection(jedisMock);
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-330
|
||||
public void shouldConnectAfterCreation() {
|
||||
void shouldConnectAfterCreation() {
|
||||
verify(jedisMock, times(1)).connect();
|
||||
}
|
||||
|
||||
@SuppressWarnings("resource")
|
||||
@Test // DATAREDIS-330
|
||||
public void shouldNotConnectIfAlreadyConnected() {
|
||||
void shouldNotConnectIfAlreadyConnected() {
|
||||
|
||||
Jedis yetAnotherJedisMock = mock(Jedis.class);
|
||||
when(yetAnotherJedisMock.isConnected()).thenReturn(true);
|
||||
@@ -63,82 +63,82 @@ public class JedisSentinelConnectionUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-330
|
||||
public void failoverShouldBeSentCorrectly() {
|
||||
void failoverShouldBeSentCorrectly() {
|
||||
|
||||
connection.failover(new RedisNodeBuilder().withName("mymaster").build());
|
||||
verify(jedisMock, times(1)).sentinelFailover(eq("mymaster"));
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-330
|
||||
public void failoverShouldThrowExceptionIfMasterNodeIsNull() {
|
||||
void failoverShouldThrowExceptionIfMasterNodeIsNull() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> connection.failover(null));
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-330
|
||||
public void failoverShouldThrowExceptionIfMasterNodeNameIsEmpty() {
|
||||
void failoverShouldThrowExceptionIfMasterNodeNameIsEmpty() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> connection.failover(new RedisNodeBuilder().build()));
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-330
|
||||
public void mastersShouldReadMastersCorrectly() {
|
||||
void mastersShouldReadMastersCorrectly() {
|
||||
|
||||
connection.masters();
|
||||
verify(jedisMock, times(1)).sentinelMasters();
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-330
|
||||
public void shouldReadSlavesCorrectly() {
|
||||
void shouldReadSlavesCorrectly() {
|
||||
|
||||
connection.slaves("mymaster");
|
||||
verify(jedisMock, times(1)).sentinelSlaves(eq("mymaster"));
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-330
|
||||
public void shouldReadSlavesCorrectlyWhenGivenNamedNode() {
|
||||
void shouldReadSlavesCorrectlyWhenGivenNamedNode() {
|
||||
|
||||
connection.slaves(new RedisNodeBuilder().withName("mymaster").build());
|
||||
verify(jedisMock, times(1)).sentinelSlaves(eq("mymaster"));
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-330
|
||||
public void readSlavesShouldThrowExceptionWhenGivenEmptyMasterName() {
|
||||
void readSlavesShouldThrowExceptionWhenGivenEmptyMasterName() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> connection.slaves(""));
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-330
|
||||
public void readSlavesShouldThrowExceptionWhenGivenNull() {
|
||||
void readSlavesShouldThrowExceptionWhenGivenNull() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> connection.slaves((RedisNode) null));
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-330
|
||||
public void readSlavesShouldThrowExceptionWhenNodeWithoutName() {
|
||||
void readSlavesShouldThrowExceptionWhenNodeWithoutName() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> connection.slaves(new RedisNodeBuilder().build()));
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-330
|
||||
public void shouldRemoveMasterCorrectlyWhenGivenNamedNode() {
|
||||
void shouldRemoveMasterCorrectlyWhenGivenNamedNode() {
|
||||
|
||||
connection.remove(new RedisNodeBuilder().withName("mymaster").build());
|
||||
verify(jedisMock, times(1)).sentinelRemove(eq("mymaster"));
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-330
|
||||
public void removeShouldThrowExceptionWhenGivenEmptyMasterName() {
|
||||
void removeShouldThrowExceptionWhenGivenEmptyMasterName() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> connection.remove(""));
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-330
|
||||
public void removeShouldThrowExceptionWhenGivenNull() {
|
||||
void removeShouldThrowExceptionWhenGivenNull() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> connection.remove((RedisNode) null));
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-330
|
||||
public void removeShouldThrowExceptionWhenNodeWithoutName() {
|
||||
void removeShouldThrowExceptionWhenNodeWithoutName() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> connection.remove(new RedisNodeBuilder().build()));
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-330
|
||||
public void monitorShouldBeSentCorrectly() {
|
||||
void monitorShouldBeSentCorrectly() {
|
||||
|
||||
RedisServer server = new RedisServer("127.0.0.1", 6382);
|
||||
server.setName("anothermaster");
|
||||
|
||||
@@ -17,6 +17,7 @@ package org.springframework.data.redis.connection.jedis;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import redis.clients.jedis.Jedis;
|
||||
|
||||
import java.util.Collection;
|
||||
@@ -24,11 +25,8 @@ import java.util.List;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.springframework.dao.InvalidDataAccessApiUsageException;
|
||||
import org.springframework.data.redis.connection.AbstractConnectionIntegrationTests;
|
||||
@@ -36,11 +34,9 @@ import org.springframework.data.redis.connection.RedisSentinelConfiguration;
|
||||
import org.springframework.data.redis.connection.RedisSentinelConnection;
|
||||
import org.springframework.data.redis.connection.RedisServer;
|
||||
import org.springframework.data.redis.connection.ReturnType;
|
||||
import org.springframework.data.redis.test.util.MinimumRedisVersionRule;
|
||||
import org.springframework.data.redis.test.util.RedisSentinelRule;
|
||||
import org.springframework.data.redis.test.util.RelaxedJUnit4ClassRunner;
|
||||
import org.springframework.test.annotation.IfProfileValue;
|
||||
import org.springframework.data.redis.test.condition.EnabledOnRedisSentinelAvailable;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
|
||||
/**
|
||||
@@ -48,8 +44,9 @@ import org.springframework.test.util.ReflectionTestUtils;
|
||||
* @author Thomas Darimont
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
@RunWith(RelaxedJUnit4ClassRunner.class)
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@ContextConfiguration("JedisConnectionIntegrationTests-context.xml")
|
||||
@EnabledOnRedisSentinelAvailable
|
||||
public class JedisSentinelIntegrationTests extends AbstractConnectionIntegrationTests {
|
||||
|
||||
private static final String MASTER_NAME = "mymaster";
|
||||
@@ -62,8 +59,6 @@ public class JedisSentinelIntegrationTests extends AbstractConnectionIntegration
|
||||
private static final RedisSentinelConfiguration SENTINEL_CONFIG = new RedisSentinelConfiguration() //
|
||||
.master(MASTER_NAME).sentinel(SENTINEL_0).sentinel(SENTINEL_1);
|
||||
|
||||
public static @ClassRule RedisSentinelRule sentinelRule = RedisSentinelRule.forConfig(SENTINEL_CONFIG).oneActive();
|
||||
public @Rule MinimumRedisVersionRule minimumVersionRule = new MinimumRedisVersionRule();
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
@@ -87,40 +82,34 @@ public class JedisSentinelIntegrationTests extends AbstractConnectionIntegration
|
||||
}
|
||||
|
||||
@Test
|
||||
@IfProfileValue(name = "redisVersion", value = "2.6+")
|
||||
public void testEvalReturnSingleError() {
|
||||
assertThatExceptionOfType(InvalidDataAccessApiUsageException.class)
|
||||
.isThrownBy(() -> connection.eval("return redis.call('expire','foo')", ReturnType.BOOLEAN, 0));
|
||||
}
|
||||
|
||||
@Test
|
||||
@IfProfileValue(name = "redisVersion", value = "2.6+")
|
||||
public void testEvalArrayScriptError() {
|
||||
assertThatExceptionOfType(InvalidDataAccessApiUsageException.class)
|
||||
.isThrownBy(() -> super.testEvalArrayScriptError());
|
||||
}
|
||||
|
||||
@Test
|
||||
@IfProfileValue(name = "redisVersion", value = "2.6+")
|
||||
public void testEvalShaNotFound() {
|
||||
assertThatExceptionOfType(InvalidDataAccessApiUsageException.class)
|
||||
.isThrownBy(() -> connection.evalSha("somefakesha", ReturnType.VALUE, 2, "key1", "key2"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@IfProfileValue(name = "redisVersion", value = "2.6+")
|
||||
public void testEvalShaArrayError() {
|
||||
assertThatExceptionOfType(InvalidDataAccessApiUsageException.class).isThrownBy(() -> super.testEvalShaArrayError());
|
||||
}
|
||||
|
||||
@Test
|
||||
@IfProfileValue(name = "redisVersion", value = "2.6+")
|
||||
public void testRestoreBadData() {
|
||||
assertThatExceptionOfType(InvalidDataAccessApiUsageException.class).isThrownBy(() -> super.testRestoreBadData());
|
||||
}
|
||||
|
||||
@Test
|
||||
@IfProfileValue(name = "redisVersion", value = "2.6+")
|
||||
public void testRestoreExistingKey() {
|
||||
assertThatExceptionOfType(InvalidDataAccessApiUsageException.class)
|
||||
.isThrownBy(() -> super.testRestoreExistingKey());
|
||||
|
||||
@@ -22,9 +22,11 @@ import redis.clients.jedis.BinaryJedisPubSub;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mockito.Mockito;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import org.springframework.data.redis.connection.MessageListener;
|
||||
import org.springframework.data.redis.connection.RedisInvalidSubscriptionException;
|
||||
@@ -34,60 +36,59 @@ import org.springframework.data.redis.connection.RedisInvalidSubscriptionExcepti
|
||||
*
|
||||
* @author Jennifer Hickey
|
||||
*/
|
||||
public class JedisSubscriptionTests {
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class JedisSubscriptionUnitTests {
|
||||
|
||||
private JedisSubscription subscription;
|
||||
@Mock BinaryJedisPubSub jedisPubSub;
|
||||
|
||||
private BinaryJedisPubSub jedisPubSub;
|
||||
@Mock MessageListener listener;
|
||||
|
||||
private MessageListener listener;
|
||||
JedisSubscription subscription;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
jedisPubSub = Mockito.mock(BinaryJedisPubSub.class);
|
||||
listener = Mockito.mock(MessageListener.class);
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
subscription = new JedisSubscription(listener, jedisPubSub, null, null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUnsubscribeAllAndClose() {
|
||||
void testUnsubscribeAllAndClose() {
|
||||
subscription.subscribe(new byte[][] { "a".getBytes() });
|
||||
subscription.unsubscribe();
|
||||
verify(jedisPubSub, times(1)).unsubscribe();
|
||||
verify(jedisPubSub, never()).punsubscribe();
|
||||
assertThat(subscription.isAlive()).isFalse();
|
||||
assertThat(subscription.getChannels().isEmpty()).isTrue();
|
||||
assertThat(subscription.getPatterns().isEmpty()).isTrue();
|
||||
assertThat(subscription.getChannels()).isEmpty();
|
||||
assertThat(subscription.getPatterns()).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUnsubscribeAllChannelsWithPatterns() {
|
||||
void testUnsubscribeAllChannelsWithPatterns() {
|
||||
subscription.subscribe(new byte[][] { "a".getBytes() });
|
||||
subscription.pSubscribe(new byte[][] { "s*".getBytes() });
|
||||
subscription.unsubscribe();
|
||||
verify(jedisPubSub, times(1)).unsubscribe();
|
||||
verify(jedisPubSub, never()).punsubscribe();
|
||||
assertThat(subscription.isAlive()).isTrue();
|
||||
assertThat(subscription.getChannels().isEmpty()).isTrue();
|
||||
assertThat(subscription.getChannels()).isEmpty();
|
||||
Collection<byte[]> patterns = subscription.getPatterns();
|
||||
assertThat(patterns.size()).isEqualTo(1);
|
||||
assertThat(patterns).hasSize(1);
|
||||
assertThat(patterns.iterator().next()).isEqualTo("s*".getBytes());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUnsubscribeChannelAndClose() {
|
||||
void testUnsubscribeChannelAndClose() {
|
||||
byte[][] channel = new byte[][] { "a".getBytes() };
|
||||
subscription.subscribe(channel);
|
||||
subscription.unsubscribe(channel);
|
||||
verify(jedisPubSub, times(1)).unsubscribe(channel);
|
||||
verify(jedisPubSub, never()).punsubscribe();
|
||||
assertThat(subscription.isAlive()).isFalse();
|
||||
assertThat(subscription.getChannels().isEmpty()).isTrue();
|
||||
assertThat(subscription.getPatterns().isEmpty()).isTrue();
|
||||
assertThat(subscription.getChannels()).isEmpty();
|
||||
assertThat(subscription.getPatterns()).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUnsubscribeChannelSomeLeft() {
|
||||
void testUnsubscribeChannelSomeLeft() {
|
||||
byte[][] channels = new byte[][] { "a".getBytes(), "b".getBytes() };
|
||||
subscription.subscribe(channels);
|
||||
subscription.unsubscribe(new byte[][] { "a".getBytes() });
|
||||
@@ -95,13 +96,13 @@ public class JedisSubscriptionTests {
|
||||
verify(jedisPubSub, never()).punsubscribe();
|
||||
assertThat(subscription.isAlive()).isTrue();
|
||||
Collection<byte[]> subChannels = subscription.getChannels();
|
||||
assertThat(subChannels.size()).isEqualTo(1);
|
||||
assertThat(subChannels).hasSize(1);
|
||||
assertThat(subChannels.iterator().next()).isEqualTo("b".getBytes());
|
||||
assertThat(subscription.getPatterns().isEmpty()).isTrue();
|
||||
assertThat(subscription.getPatterns()).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUnsubscribeChannelWithPatterns() {
|
||||
void testUnsubscribeChannelWithPatterns() {
|
||||
byte[][] channel = new byte[][] { "a".getBytes() };
|
||||
subscription.subscribe(channel);
|
||||
subscription.pSubscribe(new byte[][] { "s*".getBytes() });
|
||||
@@ -109,14 +110,14 @@ public class JedisSubscriptionTests {
|
||||
verify(jedisPubSub, times(1)).unsubscribe(channel);
|
||||
verify(jedisPubSub, never()).punsubscribe();
|
||||
assertThat(subscription.isAlive()).isTrue();
|
||||
assertThat(subscription.getChannels().isEmpty()).isTrue();
|
||||
assertThat(subscription.getChannels()).isEmpty();
|
||||
Collection<byte[]> patterns = subscription.getPatterns();
|
||||
assertThat(patterns.size()).isEqualTo(1);
|
||||
assertThat(patterns).hasSize(1);
|
||||
assertThat(patterns.iterator().next()).isEqualTo("s*".getBytes());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUnsubscribeChannelWithPatternsSomeLeft() {
|
||||
void testUnsubscribeChannelWithPatternsSomeLeft() {
|
||||
byte[][] channel = new byte[][] { "a".getBytes() };
|
||||
subscription.subscribe(new byte[][] { "a".getBytes(), "b".getBytes() });
|
||||
subscription.pSubscribe(new byte[][] { "s*".getBytes() });
|
||||
@@ -125,28 +126,28 @@ public class JedisSubscriptionTests {
|
||||
verify(jedisPubSub, never()).punsubscribe();
|
||||
assertThat(subscription.isAlive()).isTrue();
|
||||
Collection<byte[]> channels = subscription.getChannels();
|
||||
assertThat(channels.size()).isEqualTo(1);
|
||||
assertThat(channels).hasSize(1);
|
||||
assertThat(channels.iterator().next()).isEqualTo("b".getBytes());
|
||||
Collection<byte[]> patterns = subscription.getPatterns();
|
||||
assertThat(patterns.size()).isEqualTo(1);
|
||||
assertThat(patterns).hasSize(1);
|
||||
assertThat(patterns.iterator().next()).isEqualTo("s*".getBytes());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUnsubscribeAllNoChannels() {
|
||||
void testUnsubscribeAllNoChannels() {
|
||||
subscription.pSubscribe(new byte[][] { "s*".getBytes() });
|
||||
subscription.unsubscribe();
|
||||
verify(jedisPubSub, never()).unsubscribe();
|
||||
verify(jedisPubSub, never()).punsubscribe();
|
||||
assertThat(subscription.isAlive()).isTrue();
|
||||
assertThat(subscription.getChannels().isEmpty()).isTrue();
|
||||
assertThat(subscription.getChannels()).isEmpty();
|
||||
Collection<byte[]> patterns = subscription.getPatterns();
|
||||
assertThat(patterns.size()).isEqualTo(1);
|
||||
assertThat(patterns).hasSize(1);
|
||||
assertThat(patterns.iterator().next()).isEqualTo("s*".getBytes());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUnsubscribeNotAlive() {
|
||||
void testUnsubscribeNotAlive() {
|
||||
subscription.subscribe(new byte[][] { "a".getBytes() });
|
||||
subscription.unsubscribe();
|
||||
assertThat(subscription.isAlive()).isFalse();
|
||||
@@ -155,53 +156,55 @@ public class JedisSubscriptionTests {
|
||||
verify(jedisPubSub, never()).punsubscribe();
|
||||
}
|
||||
|
||||
@Test(expected = RedisInvalidSubscriptionException.class)
|
||||
public void testSubscribeNotAlive() {
|
||||
@Test
|
||||
void testSubscribeNotAlive() {
|
||||
subscription.subscribe(new byte[][] { "a".getBytes() });
|
||||
subscription.unsubscribe();
|
||||
assertThat(subscription.isAlive()).isFalse();
|
||||
subscription.subscribe(new byte[][] { "s".getBytes() });
|
||||
|
||||
assertThatExceptionOfType(RedisInvalidSubscriptionException.class)
|
||||
.isThrownBy(() -> subscription.subscribe(new byte[][] { "s".getBytes() }));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPUnsubscribeAllAndClose() {
|
||||
void testPUnsubscribeAllAndClose() {
|
||||
subscription.pSubscribe(new byte[][] { "a*".getBytes() });
|
||||
subscription.pUnsubscribe();
|
||||
verify(jedisPubSub, never()).unsubscribe();
|
||||
verify(jedisPubSub, times(1)).punsubscribe();
|
||||
assertThat(subscription.isAlive()).isFalse();
|
||||
assertThat(subscription.getChannels().isEmpty()).isTrue();
|
||||
assertThat(subscription.getPatterns().isEmpty()).isTrue();
|
||||
assertThat(subscription.getChannels()).isEmpty();
|
||||
assertThat(subscription.getPatterns()).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPUnsubscribeAllPatternsWithChannels() {
|
||||
void testPUnsubscribeAllPatternsWithChannels() {
|
||||
subscription.subscribe(new byte[][] { "a".getBytes() });
|
||||
subscription.pSubscribe(new byte[][] { "s*".getBytes() });
|
||||
subscription.pUnsubscribe();
|
||||
verify(jedisPubSub, never()).unsubscribe();
|
||||
verify(jedisPubSub, times(1)).punsubscribe();
|
||||
assertThat(subscription.isAlive()).isTrue();
|
||||
assertThat(subscription.getPatterns().isEmpty()).isTrue();
|
||||
assertThat(subscription.getPatterns()).isEmpty();
|
||||
Collection<byte[]> channels = subscription.getChannels();
|
||||
assertThat(channels.size()).isEqualTo(1);
|
||||
assertThat(channels).hasSize(1);
|
||||
assertThat(channels.iterator().next()).isEqualTo("a".getBytes());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPUnsubscribeAndClose() {
|
||||
void testPUnsubscribeAndClose() {
|
||||
byte[][] pattern = new byte[][] { "a*".getBytes() };
|
||||
subscription.pSubscribe(pattern);
|
||||
subscription.pUnsubscribe(pattern);
|
||||
verify(jedisPubSub, never()).unsubscribe();
|
||||
verify(jedisPubSub, times(1)).punsubscribe(pattern);
|
||||
assertThat(subscription.isAlive()).isFalse();
|
||||
assertThat(subscription.getChannels().isEmpty()).isTrue();
|
||||
assertThat(subscription.getPatterns().isEmpty()).isTrue();
|
||||
assertThat(subscription.getChannels()).isEmpty();
|
||||
assertThat(subscription.getPatterns()).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPUnsubscribePatternSomeLeft() {
|
||||
void testPUnsubscribePatternSomeLeft() {
|
||||
byte[][] patterns = new byte[][] { "a*".getBytes(), "b*".getBytes() };
|
||||
subscription.pSubscribe(patterns);
|
||||
subscription.pUnsubscribe(new byte[][] { "a*".getBytes() });
|
||||
@@ -209,13 +212,13 @@ public class JedisSubscriptionTests {
|
||||
verify(jedisPubSub, never()).unsubscribe();
|
||||
assertThat(subscription.isAlive()).isTrue();
|
||||
Collection<byte[]> subPatterns = subscription.getPatterns();
|
||||
assertThat(subPatterns.size()).isEqualTo(1);
|
||||
assertThat(subPatterns).hasSize(1);
|
||||
assertThat(subPatterns.iterator().next()).isEqualTo("b*".getBytes());
|
||||
assertThat(subscription.getChannels().isEmpty()).isTrue();
|
||||
assertThat(subscription.getChannels()).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPUnsubscribePatternWithChannels() {
|
||||
void testPUnsubscribePatternWithChannels() {
|
||||
byte[][] pattern = new byte[][] { "s*".getBytes() };
|
||||
subscription.subscribe(new byte[][] { "a".getBytes() });
|
||||
subscription.pSubscribe(pattern);
|
||||
@@ -223,14 +226,14 @@ public class JedisSubscriptionTests {
|
||||
verify(jedisPubSub, times(1)).punsubscribe(pattern);
|
||||
verify(jedisPubSub, never()).unsubscribe();
|
||||
assertThat(subscription.isAlive()).isTrue();
|
||||
assertThat(subscription.getPatterns().isEmpty()).isTrue();
|
||||
assertThat(subscription.getPatterns()).isEmpty();
|
||||
Collection<byte[]> channels = subscription.getChannels();
|
||||
assertThat(channels.size()).isEqualTo(1);
|
||||
assertThat(channels).hasSize(1);
|
||||
assertThat(channels.iterator().next()).isEqualTo("a".getBytes());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUnsubscribePatternWithChannelsSomeLeft() {
|
||||
void testUnsubscribePatternWithChannelsSomeLeft() {
|
||||
byte[][] pattern = new byte[][] { "a*".getBytes() };
|
||||
subscription.pSubscribe(new byte[][] { "a*".getBytes(), "b*".getBytes() });
|
||||
subscription.subscribe(new byte[][] { "a".getBytes() });
|
||||
@@ -239,28 +242,28 @@ public class JedisSubscriptionTests {
|
||||
verify(jedisPubSub, times(1)).punsubscribe(pattern);
|
||||
assertThat(subscription.isAlive()).isTrue();
|
||||
Collection<byte[]> channels = subscription.getChannels();
|
||||
assertThat(channels.size()).isEqualTo(1);
|
||||
assertThat(channels).hasSize(1);
|
||||
assertThat(channels.iterator().next()).isEqualTo("a".getBytes());
|
||||
Collection<byte[]> patterns = subscription.getPatterns();
|
||||
assertThat(patterns.size()).isEqualTo(1);
|
||||
assertThat(patterns).hasSize(1);
|
||||
assertThat(patterns.iterator().next()).isEqualTo("b*".getBytes());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPUnsubscribeAllNoPatterns() {
|
||||
void testPUnsubscribeAllNoPatterns() {
|
||||
subscription.subscribe(new byte[][] { "s".getBytes() });
|
||||
subscription.pUnsubscribe();
|
||||
verify(jedisPubSub, never()).unsubscribe();
|
||||
verify(jedisPubSub, never()).punsubscribe();
|
||||
assertThat(subscription.isAlive()).isTrue();
|
||||
assertThat(subscription.getPatterns().isEmpty()).isTrue();
|
||||
assertThat(subscription.getPatterns()).isEmpty();
|
||||
Collection<byte[]> channels = subscription.getChannels();
|
||||
assertThat(channels.size()).isEqualTo(1);
|
||||
assertThat(channels).hasSize(1);
|
||||
assertThat(channels.iterator().next()).isEqualTo("s".getBytes());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPUnsubscribeNotAlive() {
|
||||
void testPUnsubscribeNotAlive() {
|
||||
subscription.subscribe(new byte[][] { "a".getBytes() });
|
||||
subscription.unsubscribe();
|
||||
assertThat(subscription.isAlive()).isFalse();
|
||||
@@ -269,23 +272,25 @@ public class JedisSubscriptionTests {
|
||||
verify(jedisPubSub, never()).punsubscribe();
|
||||
}
|
||||
|
||||
@Test(expected = RedisInvalidSubscriptionException.class)
|
||||
public void testPSubscribeNotAlive() {
|
||||
@Test
|
||||
void testPSubscribeNotAlive() {
|
||||
subscription.subscribe(new byte[][] { "a".getBytes() });
|
||||
subscription.unsubscribe();
|
||||
assertThat(subscription.isAlive()).isFalse();
|
||||
subscription.pSubscribe(new byte[][] { "s*".getBytes() });
|
||||
|
||||
assertThatExceptionOfType(RedisInvalidSubscriptionException.class)
|
||||
.isThrownBy(() -> subscription.pSubscribe(new byte[][] { "s*".getBytes() }));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDoCloseNotSubscribed() {
|
||||
void testDoCloseNotSubscribed() {
|
||||
subscription.doClose();
|
||||
verify(jedisPubSub, never()).unsubscribe();
|
||||
verify(jedisPubSub, never()).punsubscribe();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDoCloseSubscribedChannels() {
|
||||
void testDoCloseSubscribedChannels() {
|
||||
subscription.subscribe(new byte[][] { "a".getBytes() });
|
||||
subscription.doClose();
|
||||
verify(jedisPubSub, times(1)).unsubscribe();
|
||||
@@ -293,7 +298,7 @@ public class JedisSubscriptionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDoCloseSubscribedPatterns() {
|
||||
void testDoCloseSubscribedPatterns() {
|
||||
subscription.pSubscribe(new byte[][] { "a*".getBytes() });
|
||||
subscription.doClose();
|
||||
verify(jedisPubSub, never()).unsubscribe();
|
||||
@@ -33,15 +33,16 @@ import org.junit.runners.Parameterized;
|
||||
import org.junit.runners.Parameterized.Parameters;
|
||||
|
||||
import org.springframework.data.redis.ConnectionFactoryTracker;
|
||||
import org.springframework.data.redis.SettingsUtils;
|
||||
import org.springframework.data.redis.connection.RedisConnectionFactory;
|
||||
import org.springframework.data.redis.connection.jedis.extension.JedisConnectionFactoryExtension;
|
||||
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
|
||||
import org.springframework.data.redis.connection.lettuce.LettuceTestClientResources;
|
||||
import org.springframework.data.redis.connection.lettuce.extension.LettuceConnectionFactoryExtension;
|
||||
import org.springframework.data.redis.core.BoundHashOperations;
|
||||
import org.springframework.data.redis.core.Cursor;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.data.redis.core.ScanOptions;
|
||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
import org.springframework.data.redis.test.extension.RedisStanalone;
|
||||
|
||||
/**
|
||||
* @author Mark Paluch
|
||||
@@ -57,33 +58,21 @@ public class ScanTests {
|
||||
new LinkedBlockingDeque<>());
|
||||
|
||||
public ScanTests(RedisConnectionFactory factory) {
|
||||
|
||||
this.factory = factory;
|
||||
ConnectionFactoryTracker.add(factory);
|
||||
}
|
||||
|
||||
@Parameters
|
||||
public static List<RedisConnectionFactory> params() {
|
||||
|
||||
JedisConnectionFactory jedisConnectionFactory = new JedisConnectionFactory();
|
||||
jedisConnectionFactory.setHostName(SettingsUtils.getHost());
|
||||
jedisConnectionFactory.setPort(SettingsUtils.getPort());
|
||||
jedisConnectionFactory.afterPropertiesSet();
|
||||
JedisConnectionFactory jedisConnectionFactory = JedisConnectionFactoryExtension
|
||||
.getConnectionFactory(RedisStanalone.class);
|
||||
|
||||
LettuceConnectionFactory lettuceConnectionFactory = new LettuceConnectionFactory();
|
||||
lettuceConnectionFactory.setClientResources(LettuceTestClientResources.getSharedClientResources());
|
||||
lettuceConnectionFactory.setHostName(SettingsUtils.getHost());
|
||||
lettuceConnectionFactory.setPort(SettingsUtils.getPort());
|
||||
lettuceConnectionFactory.afterPropertiesSet();
|
||||
LettuceConnectionFactory lettuceConnectionFactory = LettuceConnectionFactoryExtension
|
||||
.getConnectionFactory(RedisStanalone.class);
|
||||
|
||||
return Arrays.<RedisConnectionFactory> asList(jedisConnectionFactory, lettuceConnectionFactory);
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void cleanUp() {
|
||||
ConnectionFactoryTracker.cleanUp();
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
|
||||
|
||||
@@ -0,0 +1,216 @@
|
||||
/*
|
||||
* Copyright 2020 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.data.redis.connection.jedis.extension;
|
||||
|
||||
import redis.clients.jedis.JedisPoolConfig;
|
||||
import redis.clients.jedis.JedisShardInfo;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.jupiter.api.extension.ExtensionContext;
|
||||
import org.junit.jupiter.api.extension.ParameterContext;
|
||||
import org.junit.jupiter.api.extension.ParameterResolutionException;
|
||||
import org.junit.jupiter.api.extension.ParameterResolver;
|
||||
|
||||
import org.springframework.data.redis.ConnectionFactoryTracker;
|
||||
import org.springframework.data.redis.SettingsUtils;
|
||||
import org.springframework.data.redis.connection.RedisClusterConfiguration;
|
||||
import org.springframework.data.redis.connection.RedisConnectionFactory;
|
||||
import org.springframework.data.redis.connection.RedisSentinelConfiguration;
|
||||
import org.springframework.data.redis.connection.RedisStandaloneConfiguration;
|
||||
import org.springframework.data.redis.connection.jedis.JedisClientConfiguration;
|
||||
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
|
||||
import org.springframework.data.redis.test.extension.RedisCluster;
|
||||
import org.springframework.data.redis.test.extension.RedisSentinel;
|
||||
import org.springframework.data.redis.test.extension.RedisStanalone;
|
||||
import org.springframework.data.redis.test.extension.ShutdownQueue;
|
||||
import org.springframework.data.util.Lazy;
|
||||
|
||||
/**
|
||||
* JUnit {@link ParameterResolver} providing pre-cached {@link JedisConnectionFactory} instances. Connection factories
|
||||
* can be qualified with {@code @RedisStanalone} (default), {@code @RedisSentinel} or {@code @RedisCluster} to obtain a
|
||||
* specific factory instance. Instances are managed by this extension and will be shut down on JVM shutdown.
|
||||
*
|
||||
* @author Mark Paluch
|
||||
* @see RedisStanalone
|
||||
* @see RedisSentinel
|
||||
* @see RedisCluster
|
||||
*/
|
||||
public class JedisConnectionFactoryExtension implements ParameterResolver {
|
||||
|
||||
private static final ExtensionContext.Namespace NAMESPACE = ExtensionContext.Namespace
|
||||
.create(JedisConnectionFactoryExtension.class);
|
||||
|
||||
private static final Lazy<JedisConnectionFactory> STANDALONE = Lazy.of(() -> {
|
||||
|
||||
JedisClientConfiguration configuration = JedisClientConfiguration.builder().usePooling().build();
|
||||
|
||||
JedisConnectionFactory factory = new ManagedJedisConnectionFactory(SettingsUtils.standaloneConfiguration(),
|
||||
configuration);
|
||||
factory.afterPropertiesSet();
|
||||
ShutdownQueue.register(ShutdownQueue.toCloseable(factory));
|
||||
|
||||
return factory;
|
||||
});
|
||||
|
||||
private static final Lazy<JedisConnectionFactory> SENTINEL = Lazy.of(() -> {
|
||||
|
||||
JedisClientConfiguration configuration = JedisClientConfiguration.builder().usePooling().build();
|
||||
|
||||
JedisConnectionFactory factory = new ManagedJedisConnectionFactory(SettingsUtils.sentinelConfiguration(),
|
||||
configuration);
|
||||
factory.afterPropertiesSet();
|
||||
ShutdownQueue.register(ShutdownQueue.toCloseable(factory));
|
||||
|
||||
return factory;
|
||||
});
|
||||
|
||||
private static final Lazy<JedisConnectionFactory> CLUSTER = Lazy.of(() -> {
|
||||
|
||||
JedisClientConfiguration configuration = JedisClientConfiguration.builder().usePooling().build();
|
||||
|
||||
JedisConnectionFactory factory = new ManagedJedisConnectionFactory(SettingsUtils.clusterConfiguration(),
|
||||
configuration);
|
||||
factory.afterPropertiesSet();
|
||||
ShutdownQueue.register(ShutdownQueue.toCloseable(factory));
|
||||
|
||||
return factory;
|
||||
});
|
||||
|
||||
private static final Map<Class<?>, Lazy<JedisConnectionFactory>> factories;
|
||||
|
||||
static {
|
||||
|
||||
factories = new HashMap<>();
|
||||
factories.put(RedisStanalone.class, STANDALONE);
|
||||
factories.put(RedisSentinel.class, SENTINEL);
|
||||
factories.put(RedisCluster.class, CLUSTER);
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtain a {@link JedisConnectionFactory} described by {@code qualifier}. Instances are managed by this extension and
|
||||
* will be shut down on JVM shutdown.
|
||||
*
|
||||
* @param qualifier an be any of {@link RedisStanalone}, {@link RedisSentinel}, {@link RedisCluster}.
|
||||
* @return the managed {@link JedisConnectionFactory}.
|
||||
*/
|
||||
public static JedisConnectionFactory getConnectionFactory(Class<? extends Annotation> qualifier) {
|
||||
return factories.get(qualifier).get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsParameter(ParameterContext parameterContext, ExtensionContext extensionContext)
|
||||
throws ParameterResolutionException {
|
||||
return RedisConnectionFactory.class.isAssignableFrom(parameterContext.getParameter().getType());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object resolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext)
|
||||
throws ParameterResolutionException {
|
||||
|
||||
ExtensionContext.Store store = extensionContext.getStore(NAMESPACE);
|
||||
|
||||
Class<? extends Annotation> qualifier = getQualifier(parameterContext);
|
||||
|
||||
return store.getOrComputeIfAbsent(qualifier, JedisConnectionFactoryExtension::getConnectionFactory);
|
||||
}
|
||||
|
||||
private static Class<? extends Annotation> getQualifier(ParameterContext parameterContext) {
|
||||
|
||||
if (parameterContext.isAnnotated(RedisSentinel.class)) {
|
||||
return RedisSentinel.class;
|
||||
}
|
||||
|
||||
if (parameterContext.isAnnotated(RedisCluster.class)) {
|
||||
return RedisCluster.class;
|
||||
}
|
||||
|
||||
return RedisStanalone.class;
|
||||
}
|
||||
|
||||
static class ManagedJedisConnectionFactory extends JedisConnectionFactory
|
||||
implements ConnectionFactoryTracker.Managed {
|
||||
|
||||
public ManagedJedisConnectionFactory() {
|
||||
super();
|
||||
}
|
||||
|
||||
public ManagedJedisConnectionFactory(JedisShardInfo shardInfo) {
|
||||
super(shardInfo);
|
||||
}
|
||||
|
||||
public ManagedJedisConnectionFactory(JedisPoolConfig poolConfig) {
|
||||
super(poolConfig);
|
||||
}
|
||||
|
||||
public ManagedJedisConnectionFactory(RedisSentinelConfiguration sentinelConfig) {
|
||||
super(sentinelConfig);
|
||||
}
|
||||
|
||||
public ManagedJedisConnectionFactory(RedisSentinelConfiguration sentinelConfig, JedisPoolConfig poolConfig) {
|
||||
super(sentinelConfig, poolConfig);
|
||||
}
|
||||
|
||||
public ManagedJedisConnectionFactory(RedisClusterConfiguration clusterConfig) {
|
||||
super(clusterConfig);
|
||||
}
|
||||
|
||||
public ManagedJedisConnectionFactory(RedisClusterConfiguration clusterConfig, JedisPoolConfig poolConfig) {
|
||||
super(clusterConfig, poolConfig);
|
||||
}
|
||||
|
||||
public ManagedJedisConnectionFactory(RedisStandaloneConfiguration standaloneConfig) {
|
||||
super(standaloneConfig);
|
||||
}
|
||||
|
||||
public ManagedJedisConnectionFactory(RedisStandaloneConfiguration standaloneConfig,
|
||||
JedisClientConfiguration clientConfig) {
|
||||
super(standaloneConfig, clientConfig);
|
||||
}
|
||||
|
||||
public ManagedJedisConnectionFactory(RedisSentinelConfiguration sentinelConfig,
|
||||
JedisClientConfiguration clientConfig) {
|
||||
super(sentinelConfig, clientConfig);
|
||||
}
|
||||
|
||||
public ManagedJedisConnectionFactory(RedisClusterConfiguration clusterConfig,
|
||||
JedisClientConfiguration clientConfig) {
|
||||
super(clusterConfig, clientConfig);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
|
||||
StringBuilder builder = new StringBuilder("Jedis");
|
||||
|
||||
if (isRedisClusterAware()) {
|
||||
builder.append(" Cluster");
|
||||
}
|
||||
|
||||
if (isRedisSentinelAware()) {
|
||||
builder.append(" Sentinel");
|
||||
}
|
||||
|
||||
if (getUsePool()) {
|
||||
builder.append(" [pool]");
|
||||
}
|
||||
|
||||
return builder.toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -33,6 +33,7 @@ import org.junit.Test;
|
||||
import org.springframework.data.redis.SettingsUtils;
|
||||
import org.springframework.data.redis.connection.PoolException;
|
||||
import org.springframework.data.redis.connection.RedisSentinelConfiguration;
|
||||
import org.springframework.data.redis.test.extension.LettuceTestClientResources;
|
||||
|
||||
/**
|
||||
* Unit test of {@link DefaultLettucePool}
|
||||
|
||||
@@ -33,6 +33,7 @@ import org.springframework.data.redis.connection.RedisSentinelConfiguration;
|
||||
import org.springframework.data.redis.connection.RedisSentinelConnection;
|
||||
import org.springframework.data.redis.connection.RedisStandaloneConfiguration;
|
||||
import org.springframework.data.redis.connection.RedisStaticMasterReplicaConfiguration;
|
||||
import org.springframework.data.redis.test.extension.LettuceTestClientResources;
|
||||
import org.springframework.data.redis.test.util.MinimumRedisVersionRule;
|
||||
import org.springframework.data.redis.test.util.ServerAvailable;
|
||||
|
||||
|
||||
@@ -25,6 +25,8 @@ import java.time.Duration;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.data.redis.test.extension.LettuceTestClientResources;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link LettuceClientConfiguration}.
|
||||
*
|
||||
|
||||
@@ -25,8 +25,6 @@ import static org.springframework.data.redis.connection.RedisGeoCommands.Distanc
|
||||
import static org.springframework.data.redis.connection.RedisGeoCommands.GeoRadiusCommandArgs.*;
|
||||
import static org.springframework.data.redis.core.ScanOptions.*;
|
||||
|
||||
import io.lettuce.core.RedisURI.Builder;
|
||||
import io.lettuce.core.api.sync.RedisHLLCommands;
|
||||
import io.lettuce.core.cluster.RedisClusterClient;
|
||||
import io.lettuce.core.cluster.api.sync.RedisAdvancedClusterCommands;
|
||||
import io.lettuce.core.codec.ByteArrayCodec;
|
||||
@@ -37,11 +35,12 @@ import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.assertj.core.data.Offset;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestInstance;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.data.domain.Range.Bound;
|
||||
import org.springframework.data.geo.Circle;
|
||||
@@ -58,77 +57,91 @@ import org.springframework.data.redis.connection.RedisZSetCommands.Range;
|
||||
import org.springframework.data.redis.connection.RedisZSetCommands.Tuple;
|
||||
import org.springframework.data.redis.connection.ValueEncoding.RedisValueEncoding;
|
||||
import org.springframework.data.redis.connection.jedis.JedisConverters;
|
||||
import org.springframework.data.redis.connection.lettuce.extension.LettuceConnectionFactoryExtension;
|
||||
import org.springframework.data.redis.core.Cursor;
|
||||
import org.springframework.data.redis.core.ScanOptions;
|
||||
import org.springframework.data.redis.core.types.Expiration;
|
||||
import org.springframework.data.redis.test.condition.EnabledOnRedisClusterAvailable;
|
||||
import org.springframework.data.redis.test.extension.LettuceExtension;
|
||||
import org.springframework.data.redis.test.extension.RedisCluster;
|
||||
import org.springframework.data.redis.test.util.HexStringUtils;
|
||||
import org.springframework.data.redis.test.util.MinimumRedisVersionRule;
|
||||
import org.springframework.data.redis.test.util.RedisClusterRule;
|
||||
import org.springframework.test.annotation.IfProfileValue;
|
||||
|
||||
/**
|
||||
* @author Christoph Strobl
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
@EnabledOnRedisClusterAvailable
|
||||
@ExtendWith(LettuceExtension.class)
|
||||
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
||||
public class LettuceClusterConnectionTests implements ClusterConnectionTests {
|
||||
|
||||
static final byte[] KEY_1_BYTES = LettuceConverters.toBytes(KEY_1);
|
||||
static final byte[] KEY_2_BYTES = LettuceConverters.toBytes(KEY_2);
|
||||
static final byte[] KEY_3_BYTES = LettuceConverters.toBytes(KEY_3);
|
||||
private static final byte[] KEY_1_BYTES = LettuceConverters.toBytes(KEY_1);
|
||||
private static final byte[] KEY_2_BYTES = LettuceConverters.toBytes(KEY_2);
|
||||
private static final byte[] KEY_3_BYTES = LettuceConverters.toBytes(KEY_3);
|
||||
|
||||
static final byte[] SAME_SLOT_KEY_1_BYTES = LettuceConverters.toBytes(SAME_SLOT_KEY_1);
|
||||
static final byte[] SAME_SLOT_KEY_2_BYTES = LettuceConverters.toBytes(SAME_SLOT_KEY_2);
|
||||
static final byte[] SAME_SLOT_KEY_3_BYTES = LettuceConverters.toBytes(SAME_SLOT_KEY_3);
|
||||
private static final byte[] SAME_SLOT_KEY_1_BYTES = LettuceConverters.toBytes(SAME_SLOT_KEY_1);
|
||||
private static final byte[] SAME_SLOT_KEY_2_BYTES = LettuceConverters.toBytes(SAME_SLOT_KEY_2);
|
||||
private static final byte[] SAME_SLOT_KEY_3_BYTES = LettuceConverters.toBytes(SAME_SLOT_KEY_3);
|
||||
|
||||
static final byte[] VALUE_1_BYTES = LettuceConverters.toBytes(VALUE_1);
|
||||
static final byte[] VALUE_2_BYTES = LettuceConverters.toBytes(VALUE_2);
|
||||
static final byte[] VALUE_3_BYTES = LettuceConverters.toBytes(VALUE_3);
|
||||
private static final byte[] VALUE_1_BYTES = LettuceConverters.toBytes(VALUE_1);
|
||||
private static final byte[] VALUE_2_BYTES = LettuceConverters.toBytes(VALUE_2);
|
||||
private static final byte[] VALUE_3_BYTES = LettuceConverters.toBytes(VALUE_3);
|
||||
|
||||
static final GeoLocation<String> ARIGENTO = new GeoLocation<>("arigento", POINT_ARIGENTO);
|
||||
static final GeoLocation<String> CATANIA = new GeoLocation<>("catania", POINT_CATANIA);
|
||||
static final GeoLocation<String> PALERMO = new GeoLocation<>("palermo", POINT_PALERMO);
|
||||
private static final GeoLocation<String> ARIGENTO = new GeoLocation<>("arigento", POINT_ARIGENTO);
|
||||
private static final GeoLocation<String> CATANIA = new GeoLocation<>("catania", POINT_CATANIA);
|
||||
private static final GeoLocation<String> PALERMO = new GeoLocation<>("palermo", POINT_PALERMO);
|
||||
|
||||
static final GeoLocation<byte[]> ARIGENTO_BYTES = new GeoLocation<>("arigento".getBytes(Charset.forName("UTF-8")),
|
||||
private static final GeoLocation<byte[]> ARIGENTO_BYTES = new GeoLocation<>(
|
||||
"arigento".getBytes(Charset.forName("UTF-8")),
|
||||
POINT_ARIGENTO);
|
||||
static final GeoLocation<byte[]> CATANIA_BYTES = new GeoLocation<>("catania".getBytes(Charset.forName("UTF-8")),
|
||||
private static final GeoLocation<byte[]> CATANIA_BYTES = new GeoLocation<>(
|
||||
"catania".getBytes(Charset.forName("UTF-8")),
|
||||
POINT_CATANIA);
|
||||
static final GeoLocation<byte[]> PALERMO_BYTES = new GeoLocation<>("palermo".getBytes(Charset.forName("UTF-8")),
|
||||
private static final GeoLocation<byte[]> PALERMO_BYTES = new GeoLocation<>(
|
||||
"palermo".getBytes(Charset.forName("UTF-8")),
|
||||
POINT_PALERMO);
|
||||
|
||||
RedisClusterClient client;
|
||||
RedisAdvancedClusterCommands<String, String> nativeConnection;
|
||||
RedisAdvancedClusterCommands<byte[], byte[]> binaryConnection;
|
||||
LettuceClusterConnection clusterConnection;
|
||||
private final RedisClusterClient client;
|
||||
|
||||
public static @ClassRule RedisClusterRule clusterAvailable = new RedisClusterRule();
|
||||
private static RedisAdvancedClusterCommands<String, String> nativeConnection;
|
||||
private static RedisAdvancedClusterCommands<byte[], byte[]> binaryConnection;
|
||||
private static LettuceClusterConnection clusterConnection;
|
||||
|
||||
/**
|
||||
* Check for specific Redis Versions
|
||||
*/
|
||||
public @Rule MinimumRedisVersionRule version = new MinimumRedisVersionRule();
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
|
||||
client = RedisClusterClient.create(LettuceTestClientResources.getSharedClientResources(),
|
||||
Builder.redis(CLUSTER_HOST, MASTER_NODE_1_PORT).withTimeout(Duration.ofMillis(500)).build());
|
||||
public LettuceClusterConnectionTests(RedisClusterClient client) {
|
||||
this.client = client;
|
||||
nativeConnection = client.connect().sync();
|
||||
binaryConnection = client.connect(ByteArrayCodec.INSTANCE).sync();
|
||||
clusterConnection = new LettuceClusterConnection(client);
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() throws InterruptedException {
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
nativeConnection.getStatefulConnection().async().flushallAsync();
|
||||
}
|
||||
|
||||
clusterConnection.serverCommands().flushDb();
|
||||
nativeConnection.getStatefulConnection().close();
|
||||
binaryConnection.getStatefulConnection().close();
|
||||
clusterConnection.close();
|
||||
client.shutdown(0, 0, TimeUnit.MILLISECONDS);
|
||||
@AfterAll
|
||||
static void afterAll() {
|
||||
|
||||
if (nativeConnection != null) {
|
||||
nativeConnection.getStatefulConnection().closeAsync();
|
||||
nativeConnection = null;
|
||||
}
|
||||
|
||||
if (binaryConnection != null) {
|
||||
binaryConnection.getStatefulConnection().closeAsync();
|
||||
binaryConnection = null;
|
||||
}
|
||||
|
||||
if (clusterConnection != null) {
|
||||
clusterConnection.close();
|
||||
clusterConnection = null;
|
||||
}
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-775
|
||||
public void shouldCreateConnectionWithPooling() {
|
||||
void shouldCreateConnectionWithPooling() {
|
||||
|
||||
LettuceConnectionFactory factory = createConnectionFactory();
|
||||
factory.afterPropertiesSet();
|
||||
@@ -142,7 +155,7 @@ public class LettuceClusterConnectionTests implements ClusterConnectionTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-775
|
||||
public void shouldCreateClusterConnectionWithPooling() {
|
||||
void shouldCreateClusterConnectionWithPooling() {
|
||||
|
||||
LettuceConnectionFactory factory = createConnectionFactory();
|
||||
factory.afterPropertiesSet();
|
||||
@@ -156,16 +169,7 @@ public class LettuceClusterConnectionTests implements ClusterConnectionTests {
|
||||
}
|
||||
|
||||
private static LettuceConnectionFactory createConnectionFactory() {
|
||||
|
||||
LettucePoolingClientConfiguration clientConfiguration = LettucePoolingClientConfiguration.builder() //
|
||||
.clientResources(LettuceTestClientResources.getSharedClientResources()) //
|
||||
.shutdownTimeout(Duration.ZERO) //
|
||||
.build();
|
||||
|
||||
RedisClusterConfiguration clusterConfiguration = new RedisClusterConfiguration();
|
||||
clusterConfiguration.addClusterNode(ClusterTestVariables.CLUSTER_NODE_1);
|
||||
|
||||
return new LettuceConnectionFactory(clusterConfiguration, clientConfiguration);
|
||||
return LettuceConnectionFactoryExtension.getConnectionFactory(RedisCluster.class);
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-315
|
||||
@@ -223,7 +227,7 @@ public class LettuceClusterConnectionTests implements ClusterConnectionTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-315
|
||||
public void bitOpShouldWorkCorrectly() {
|
||||
void bitOpShouldWorkCorrectly() {
|
||||
|
||||
nativeConnection.set(SAME_SLOT_KEY_1, "foo");
|
||||
nativeConnection.set(SAME_SLOT_KEY_2, "bar");
|
||||
@@ -239,7 +243,7 @@ public class LettuceClusterConnectionTests implements ClusterConnectionTests {
|
||||
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()).isEqualTo(2);
|
||||
assertThat(clusterConnection.bLPop(100, KEY_1_BYTES, KEY_2_BYTES)).hasSize(2);
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-315
|
||||
@@ -248,7 +252,7 @@ public class LettuceClusterConnectionTests implements ClusterConnectionTests {
|
||||
nativeConnection.lpush(SAME_SLOT_KEY_1, VALUE_1, VALUE_2);
|
||||
nativeConnection.lpush(SAME_SLOT_KEY_2, VALUE_3);
|
||||
|
||||
assertThat(clusterConnection.bLPop(100, SAME_SLOT_KEY_1_BYTES, SAME_SLOT_KEY_2_BYTES).size()).isEqualTo(2);
|
||||
assertThat(clusterConnection.bLPop(100, SAME_SLOT_KEY_1_BYTES, SAME_SLOT_KEY_2_BYTES)).hasSize(2);
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-315
|
||||
@@ -257,7 +261,7 @@ public class LettuceClusterConnectionTests implements ClusterConnectionTests {
|
||||
nativeConnection.lpush(KEY_1, VALUE_1, VALUE_2);
|
||||
nativeConnection.lpush(KEY_2, VALUE_3);
|
||||
|
||||
assertThat(clusterConnection.bRPop(100, KEY_1_BYTES, KEY_2_BYTES).size()).isEqualTo(2);
|
||||
assertThat(clusterConnection.bRPop(100, KEY_1_BYTES, KEY_2_BYTES)).hasSize(2);
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-315
|
||||
@@ -266,7 +270,7 @@ public class LettuceClusterConnectionTests implements ClusterConnectionTests {
|
||||
nativeConnection.lpush(SAME_SLOT_KEY_1, VALUE_1, VALUE_2);
|
||||
nativeConnection.lpush(SAME_SLOT_KEY_2, VALUE_3);
|
||||
|
||||
assertThat(clusterConnection.bRPop(100, SAME_SLOT_KEY_1_BYTES, SAME_SLOT_KEY_2_BYTES).size()).isEqualTo(2);
|
||||
assertThat(clusterConnection.bRPop(100, SAME_SLOT_KEY_1_BYTES, SAME_SLOT_KEY_2_BYTES)).hasSize(2);
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-315
|
||||
@@ -280,7 +284,7 @@ public class LettuceClusterConnectionTests implements ClusterConnectionTests {
|
||||
Map<RedisClusterNode, Collection<RedisClusterNode>> masterSlaveMap = clusterConnection.clusterGetMasterSlaveMap();
|
||||
|
||||
assertThat(masterSlaveMap).isNotNull();
|
||||
assertThat(masterSlaveMap.size()).isEqualTo(3);
|
||||
assertThat(masterSlaveMap).hasSize(3);
|
||||
assertThat(masterSlaveMap.get(new RedisClusterNode(CLUSTER_HOST, MASTER_NODE_1_PORT)))
|
||||
.contains(new RedisClusterNode(CLUSTER_HOST, SLAVEOF_NODE_1_PORT));
|
||||
assertThat(masterSlaveMap.get(new RedisClusterNode(CLUSTER_HOST, MASTER_NODE_2_PORT)).isEmpty()).isTrue();
|
||||
@@ -293,7 +297,7 @@ public class LettuceClusterConnectionTests implements ClusterConnectionTests {
|
||||
Set<RedisClusterNode> slaves = clusterConnection
|
||||
.clusterGetSlaves(new RedisClusterNode(CLUSTER_HOST, MASTER_NODE_1_PORT));
|
||||
|
||||
assertThat(slaves.size()).isEqualTo(1);
|
||||
assertThat(slaves).hasSize(1);
|
||||
assertThat(slaves).contains(new RedisClusterNode(CLUSTER_HOST, SLAVEOF_NODE_1_PORT));
|
||||
}
|
||||
|
||||
@@ -450,7 +454,7 @@ public class LettuceClusterConnectionTests implements ClusterConnectionTests {
|
||||
|
||||
clusterConnection.expireAt(KEY_1_BYTES, System.currentTimeMillis() / 1000 + 5000);
|
||||
|
||||
assertThat(nativeConnection.ttl(LettuceConverters.toString(KEY_1_BYTES)) > 1).isTrue();
|
||||
assertThat(nativeConnection.ttl(LettuceConverters.toString(KEY_1_BYTES))).isGreaterThan(1);
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-315
|
||||
@@ -460,7 +464,7 @@ public class LettuceClusterConnectionTests implements ClusterConnectionTests {
|
||||
|
||||
clusterConnection.expire(KEY_1_BYTES, 5);
|
||||
|
||||
assertThat(nativeConnection.ttl(LettuceConverters.toString(KEY_1_BYTES)) > 1).isTrue();
|
||||
assertThat(nativeConnection.ttl(LettuceConverters.toString(KEY_1_BYTES))).isGreaterThan(1);
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-315
|
||||
@@ -548,7 +552,7 @@ public class LettuceClusterConnectionTests implements ClusterConnectionTests {
|
||||
|
||||
List<String> result = clusterConnection.geoHash(KEY_1_BYTES, PALERMO_BYTES.getName(), ARIGENTO_BYTES.getName(),
|
||||
CATANIA_BYTES.getName());
|
||||
assertThat(result).containsExactly("sqc8b49rny0", (String) null, "sqdtr74hyu0");
|
||||
assertThat(result).containsExactly("sqc8b49rny0", null, "sqdtr74hyu0");
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-438
|
||||
@@ -1245,7 +1249,7 @@ public class LettuceClusterConnectionTests implements ClusterConnectionTests {
|
||||
|
||||
clusterConnection.pExpireAt(KEY_1_BYTES, System.currentTimeMillis() + 5000);
|
||||
|
||||
assertThat(nativeConnection.ttl(LettuceConverters.toString(KEY_1_BYTES)) > 1).isTrue();
|
||||
assertThat(nativeConnection.ttl(LettuceConverters.toString(KEY_1_BYTES))).isGreaterThan(1);
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-315
|
||||
@@ -1255,7 +1259,7 @@ public class LettuceClusterConnectionTests implements ClusterConnectionTests {
|
||||
|
||||
clusterConnection.pExpire(KEY_1_BYTES, 5000);
|
||||
|
||||
assertThat(nativeConnection.ttl(LettuceConverters.toString(KEY_1_BYTES)) > 1).isTrue();
|
||||
assertThat(nativeConnection.ttl(LettuceConverters.toString(KEY_1_BYTES))).isGreaterThan(1);
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-315
|
||||
@@ -1264,7 +1268,7 @@ public class LettuceClusterConnectionTests implements ClusterConnectionTests {
|
||||
clusterConnection.pSetEx(KEY_1_BYTES, 5000, VALUE_1_BYTES);
|
||||
|
||||
assertThat(nativeConnection.get(KEY_1)).isEqualTo(VALUE_1);
|
||||
assertThat(nativeConnection.ttl(KEY_1) > 1).isTrue();
|
||||
assertThat(nativeConnection.ttl(KEY_1)).isGreaterThan(1);
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-315
|
||||
@@ -1273,7 +1277,7 @@ public class LettuceClusterConnectionTests implements ClusterConnectionTests {
|
||||
nativeConnection.set(KEY_1, VALUE_1);
|
||||
nativeConnection.expire(KEY_1, 5);
|
||||
|
||||
assertThat(clusterConnection.pTtl(KEY_1_BYTES) > 1).isTrue();
|
||||
assertThat(clusterConnection.pTtl(KEY_1_BYTES)).isGreaterThan(1);
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-315
|
||||
@@ -1308,14 +1312,14 @@ public class LettuceClusterConnectionTests implements ClusterConnectionTests {
|
||||
|
||||
clusterConnection.pfAdd(KEY_1_BYTES, VALUE_1_BYTES, VALUE_2_BYTES, VALUE_3_BYTES);
|
||||
|
||||
assertThat(((RedisHLLCommands<String, String>) nativeConnection).pfcount(KEY_1)).isEqualTo(3L);
|
||||
assertThat(nativeConnection.pfcount(KEY_1)).isEqualTo(3L);
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-315
|
||||
public void pfCountShouldAllowCountingOnSameSlotKeys() {
|
||||
|
||||
((RedisHLLCommands<String, String>) nativeConnection).pfadd(SAME_SLOT_KEY_1, VALUE_1, VALUE_2);
|
||||
((RedisHLLCommands<String, String>) nativeConnection).pfadd(SAME_SLOT_KEY_2, VALUE_2, VALUE_3);
|
||||
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)).isEqualTo(3L);
|
||||
}
|
||||
@@ -1323,18 +1327,19 @@ public class LettuceClusterConnectionTests implements ClusterConnectionTests {
|
||||
@Test // DATAREDIS-315
|
||||
public void pfCountShouldAllowCountingOnSingleKey() {
|
||||
|
||||
((RedisHLLCommands<String, String>) nativeConnection).pfadd(KEY_1, VALUE_1, VALUE_2, VALUE_3);
|
||||
nativeConnection.pfadd(KEY_1, VALUE_1, VALUE_2, VALUE_3);
|
||||
|
||||
assertThat(clusterConnection.pfCount(KEY_1_BYTES)).isEqualTo(3L);
|
||||
}
|
||||
|
||||
@Test(expected = DataAccessException.class) // DATAREDIS-315
|
||||
@Test // DATAREDIS-315
|
||||
public void pfCountShouldThrowErrorCountingOnDifferentSlotKeys() {
|
||||
|
||||
((RedisHLLCommands<String, String>) nativeConnection).pfadd(KEY_1, VALUE_1, VALUE_2);
|
||||
((RedisHLLCommands<String, String>) nativeConnection).pfadd(KEY_2, VALUE_2, VALUE_3);
|
||||
nativeConnection.pfadd(KEY_1, VALUE_1, VALUE_2);
|
||||
nativeConnection.pfadd(KEY_2, VALUE_2, VALUE_3);
|
||||
|
||||
clusterConnection.pfCount(KEY_1_BYTES, KEY_2_BYTES);
|
||||
assertThatExceptionOfType(DataAccessException.class)
|
||||
.isThrownBy(() -> clusterConnection.pfCount(KEY_1_BYTES, KEY_2_BYTES));
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-315
|
||||
@@ -1346,12 +1351,12 @@ public class LettuceClusterConnectionTests implements ClusterConnectionTests {
|
||||
@Test // DATAREDIS-315
|
||||
public void pfMergeShouldWorkWhenAllKeysMapToSameSlot() {
|
||||
|
||||
((RedisHLLCommands<String, String>) nativeConnection).pfadd(SAME_SLOT_KEY_1, VALUE_1, VALUE_2);
|
||||
((RedisHLLCommands<String, String>) nativeConnection).pfadd(SAME_SLOT_KEY_2, VALUE_2, VALUE_3);
|
||||
nativeConnection.pfadd(SAME_SLOT_KEY_1, VALUE_1, VALUE_2);
|
||||
nativeConnection.pfadd(SAME_SLOT_KEY_2, VALUE_2, VALUE_3);
|
||||
|
||||
((RedisHLLCommands<String, String>) nativeConnection).pfmerge(SAME_SLOT_KEY_3, SAME_SLOT_KEY_1, SAME_SLOT_KEY_2);
|
||||
nativeConnection.pfmerge(SAME_SLOT_KEY_3, SAME_SLOT_KEY_1, SAME_SLOT_KEY_2);
|
||||
|
||||
assertThat(((RedisHLLCommands<String, String>) nativeConnection).pfcount(SAME_SLOT_KEY_3)).isEqualTo(3L);
|
||||
assertThat(nativeConnection.pfcount(SAME_SLOT_KEY_3)).isEqualTo(3L);
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-315
|
||||
@@ -1376,7 +1381,7 @@ public class LettuceClusterConnectionTests implements ClusterConnectionTests {
|
||||
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()).isEqualTo(2);
|
||||
assertThat(clusterConnection.bLPop(100, KEY_1_BYTES, KEY_2_BYTES)).hasSize(2);
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-315
|
||||
@@ -1649,7 +1654,7 @@ public class LettuceClusterConnectionTests implements ClusterConnectionTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-668
|
||||
public void sPopWithCountShouldPopValueFromSetCorrectly() {
|
||||
void sPopWithCountShouldPopValueFromSetCorrectly() {
|
||||
|
||||
nativeConnection.sadd(KEY_1, VALUE_1, VALUE_2, VALUE_3);
|
||||
|
||||
@@ -1751,7 +1756,7 @@ public class LettuceClusterConnectionTests implements ClusterConnectionTests {
|
||||
clusterConnection.setEx(KEY_1_BYTES, 5, VALUE_1_BYTES);
|
||||
|
||||
assertThat(nativeConnection.get(KEY_1)).isEqualTo(VALUE_1);
|
||||
assertThat(nativeConnection.ttl(KEY_1) > 1).isTrue();
|
||||
assertThat(nativeConnection.ttl(KEY_1)).isGreaterThan(1);
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-315
|
||||
@@ -1941,11 +1946,11 @@ public class LettuceClusterConnectionTests implements ClusterConnectionTests {
|
||||
nativeConnection.set(KEY_1, VALUE_1);
|
||||
nativeConnection.expire(KEY_1, 5);
|
||||
|
||||
assertThat(clusterConnection.ttl(KEY_1_BYTES) > 1).isTrue();
|
||||
assertThat(clusterConnection.ttl(KEY_1_BYTES)).isGreaterThan(1);
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-526
|
||||
public void ttlWithTimeUnitShouldReturnMinusOneWhenKeyDoesNotHaveExpirationSet() {
|
||||
void ttlWithTimeUnitShouldReturnMinusOneWhenKeyDoesNotHaveExpirationSet() {
|
||||
|
||||
nativeConnection.set(KEY_1, VALUE_1);
|
||||
|
||||
@@ -1980,7 +1985,7 @@ public class LettuceClusterConnectionTests implements ClusterConnectionTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-674
|
||||
public void zAddShouldAddMultipleValuesWithScoreCorrectly() {
|
||||
void zAddShouldAddMultipleValuesWithScoreCorrectly() {
|
||||
|
||||
Set<Tuple> tuples = new HashSet<>();
|
||||
tuples.add(new DefaultTuple(VALUE_1_BYTES, 10D));
|
||||
@@ -2113,7 +2118,7 @@ public class LettuceClusterConnectionTests implements ClusterConnectionTests {
|
||||
nativeConnection.zadd(KEY_1, 5D, VALUE_3);
|
||||
|
||||
assertThat(clusterConnection.zRangeByScoreWithScores(KEY_1_BYTES, 10, 20))
|
||||
.contains((Tuple) new DefaultTuple(VALUE_1_BYTES, 10D), (Tuple) new DefaultTuple(VALUE_2_BYTES, 20D));
|
||||
.contains(new DefaultTuple(VALUE_1_BYTES, 10D), new DefaultTuple(VALUE_2_BYTES, 20D));
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-315
|
||||
@@ -2124,7 +2129,7 @@ public class LettuceClusterConnectionTests implements ClusterConnectionTests {
|
||||
nativeConnection.zadd(KEY_1, 5D, VALUE_3);
|
||||
|
||||
assertThat(clusterConnection.zRangeByScoreWithScores(KEY_1_BYTES, 10D, 20D, 0L, 1L))
|
||||
.contains((Tuple) new DefaultTuple(VALUE_1_BYTES, 10D));
|
||||
.contains(new DefaultTuple(VALUE_1_BYTES, 10D));
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-315
|
||||
@@ -2145,7 +2150,7 @@ public class LettuceClusterConnectionTests implements ClusterConnectionTests {
|
||||
nativeConnection.zadd(KEY_1, 5D, VALUE_3);
|
||||
|
||||
assertThat(clusterConnection.zRangeWithScores(KEY_1_BYTES, 1, 2))
|
||||
.contains((Tuple) new DefaultTuple(VALUE_1_BYTES, 10D), (Tuple) new DefaultTuple(VALUE_2_BYTES, 20D));
|
||||
.contains(new DefaultTuple(VALUE_1_BYTES, 10D), new DefaultTuple(VALUE_2_BYTES, 20D));
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-315
|
||||
@@ -2231,7 +2236,7 @@ public class LettuceClusterConnectionTests implements ClusterConnectionTests {
|
||||
nativeConnection.zadd(KEY_1, 5D, VALUE_3);
|
||||
|
||||
assertThat(clusterConnection.zRevRangeByScoreWithScores(KEY_1_BYTES, 10D, 20D))
|
||||
.contains((Tuple) new DefaultTuple(VALUE_2_BYTES, 20D), (Tuple) new DefaultTuple(VALUE_1_BYTES, 10D));
|
||||
.contains(new DefaultTuple(VALUE_2_BYTES, 20D), new DefaultTuple(VALUE_1_BYTES, 10D));
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-315
|
||||
@@ -2242,7 +2247,7 @@ public class LettuceClusterConnectionTests implements ClusterConnectionTests {
|
||||
nativeConnection.zadd(KEY_1, 5D, VALUE_3);
|
||||
|
||||
assertThat(clusterConnection.zRevRangeByScoreWithScores(KEY_1_BYTES, 10D, 20D, 0L, 1L))
|
||||
.contains((Tuple) new DefaultTuple(VALUE_2_BYTES, 20D));
|
||||
.contains(new DefaultTuple(VALUE_2_BYTES, 20D));
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-315
|
||||
@@ -2263,7 +2268,7 @@ public class LettuceClusterConnectionTests implements ClusterConnectionTests {
|
||||
nativeConnection.zadd(KEY_1, 5D, VALUE_3);
|
||||
|
||||
assertThat(clusterConnection.zRevRangeWithScores(KEY_1_BYTES, 1, 2))
|
||||
.contains((Tuple) new DefaultTuple(VALUE_3_BYTES, 5D), (Tuple) new DefaultTuple(VALUE_1_BYTES, 10D));
|
||||
.contains(new DefaultTuple(VALUE_3_BYTES, 5D), new DefaultTuple(VALUE_1_BYTES, 10D));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -2314,7 +2319,7 @@ public class LettuceClusterConnectionTests implements ClusterConnectionTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-694
|
||||
public void touchReturnsNrOfKeysTouched() {
|
||||
void touchReturnsNrOfKeysTouched() {
|
||||
|
||||
nativeConnection.set(KEY_1, VALUE_1);
|
||||
nativeConnection.set(KEY_2, VALUE_1);
|
||||
@@ -2323,12 +2328,12 @@ public class LettuceClusterConnectionTests implements ClusterConnectionTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-694
|
||||
public void touchReturnsZeroIfNoKeysTouched() {
|
||||
void touchReturnsZeroIfNoKeysTouched() {
|
||||
assertThat(clusterConnection.keyCommands().touch(KEY_1_BYTES)).isEqualTo(0L);
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-693
|
||||
public void unlinkReturnsNrOfKeysTouched() {
|
||||
void unlinkReturnsNrOfKeysTouched() {
|
||||
|
||||
nativeConnection.set(KEY_1, VALUE_1);
|
||||
nativeConnection.set(KEY_2, VALUE_1);
|
||||
@@ -2337,12 +2342,12 @@ public class LettuceClusterConnectionTests implements ClusterConnectionTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-693
|
||||
public void unlinkReturnsZeroIfNoKeysTouched() {
|
||||
void unlinkReturnsZeroIfNoKeysTouched() {
|
||||
assertThat(clusterConnection.keyCommands().unlink(KEY_1_BYTES)).isEqualTo(0L);
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-697
|
||||
public void bitPosShouldReturnPositionCorrectly() {
|
||||
void bitPosShouldReturnPositionCorrectly() {
|
||||
|
||||
binaryConnection.set(KEY_1_BYTES, HexStringUtils.hexToBytes("fff000"));
|
||||
|
||||
@@ -2350,7 +2355,7 @@ public class LettuceClusterConnectionTests implements ClusterConnectionTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-697
|
||||
public void bitPosShouldReturnPositionInRangeCorrectly() {
|
||||
void bitPosShouldReturnPositionInRangeCorrectly() {
|
||||
|
||||
binaryConnection.set(KEY_1_BYTES, HexStringUtils.hexToBytes("fff0f0"));
|
||||
|
||||
@@ -2359,7 +2364,7 @@ public class LettuceClusterConnectionTests implements ClusterConnectionTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-716
|
||||
public void encodingReturnsCorrectly() {
|
||||
void encodingReturnsCorrectly() {
|
||||
|
||||
nativeConnection.set(KEY_1, "1000");
|
||||
|
||||
@@ -2367,12 +2372,12 @@ public class LettuceClusterConnectionTests implements ClusterConnectionTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-716
|
||||
public void encodingReturnsVacantWhenKeyDoesNotExist() {
|
||||
void encodingReturnsVacantWhenKeyDoesNotExist() {
|
||||
assertThat(clusterConnection.keyCommands().encodingOf(KEY_2_BYTES)).isEqualTo(RedisValueEncoding.VACANT);
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-716
|
||||
public void idletimeReturnsCorrectly() {
|
||||
void idletimeReturnsCorrectly() {
|
||||
|
||||
nativeConnection.set(KEY_1, VALUE_1);
|
||||
nativeConnection.get(KEY_1);
|
||||
@@ -2381,12 +2386,12 @@ public class LettuceClusterConnectionTests implements ClusterConnectionTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-716
|
||||
public void idldetimeReturnsNullWhenKeyDoesNotExist() {
|
||||
void idldetimeReturnsNullWhenKeyDoesNotExist() {
|
||||
assertThat(clusterConnection.keyCommands().idletime(KEY_3_BYTES)).isNull();
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-716
|
||||
public void refcountReturnsCorrectly() {
|
||||
void refcountReturnsCorrectly() {
|
||||
|
||||
nativeConnection.lpush(KEY_1, VALUE_1);
|
||||
|
||||
@@ -2394,13 +2399,13 @@ public class LettuceClusterConnectionTests implements ClusterConnectionTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-716
|
||||
public void refcountReturnsNullWhenKeyDoesNotExist() {
|
||||
void refcountReturnsNullWhenKeyDoesNotExist() {
|
||||
assertThat(clusterConnection.keyCommands().refcount(KEY_3_BYTES)).isNull();
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-562
|
||||
@IfProfileValue(name = "redisVersion", value = "3.2+")
|
||||
public void bitFieldSetShouldWorkCorrectly() {
|
||||
void bitFieldSetShouldWorkCorrectly() {
|
||||
|
||||
assertThat(clusterConnection.stringCommands().bitField(JedisConverters.toBytes(KEY_1),
|
||||
create().set(INT_8).valueAt(BitFieldSubCommands.Offset.offset(0L)).to(10L))).containsExactly(0L);
|
||||
@@ -2410,7 +2415,7 @@ public class LettuceClusterConnectionTests implements ClusterConnectionTests {
|
||||
|
||||
@Test // DATAREDIS-562
|
||||
@IfProfileValue(name = "redisVersion", value = "3.2+")
|
||||
public void bitFieldGetShouldWorkCorrectly() {
|
||||
void bitFieldGetShouldWorkCorrectly() {
|
||||
|
||||
assertThat(clusterConnection.stringCommands().bitField(JedisConverters.toBytes(KEY_1),
|
||||
create().get(INT_8).valueAt(BitFieldSubCommands.Offset.offset(0L)))).containsExactly(0L);
|
||||
@@ -2418,7 +2423,7 @@ public class LettuceClusterConnectionTests implements ClusterConnectionTests {
|
||||
|
||||
@Test // DATAREDIS-562
|
||||
@IfProfileValue(name = "redisVersion", value = "3.2+")
|
||||
public void bitFieldIncrByShouldWorkCorrectly() {
|
||||
void bitFieldIncrByShouldWorkCorrectly() {
|
||||
|
||||
assertThat(clusterConnection.stringCommands().bitField(JedisConverters.toBytes(KEY_1),
|
||||
create().incr(INT_8).valueAt(BitFieldSubCommands.Offset.offset(100L)).by(1L))).containsExactly(1L);
|
||||
@@ -2426,7 +2431,7 @@ public class LettuceClusterConnectionTests implements ClusterConnectionTests {
|
||||
|
||||
@Test // DATAREDIS-562
|
||||
@IfProfileValue(name = "redisVersion", value = "3.2+")
|
||||
public void bitFieldIncrByWithOverflowShouldWorkCorrectly() {
|
||||
void bitFieldIncrByWithOverflowShouldWorkCorrectly() {
|
||||
|
||||
assertThat(clusterConnection.stringCommands().bitField(JedisConverters.toBytes(KEY_1),
|
||||
create().incr(unsigned(2)).valueAt(BitFieldSubCommands.Offset.offset(102L)).overflow(FAIL).by(1L)))
|
||||
@@ -2443,7 +2448,7 @@ public class LettuceClusterConnectionTests implements ClusterConnectionTests {
|
||||
|
||||
@Test // DATAREDIS-562
|
||||
@IfProfileValue(name = "redisVersion", value = "3.2+")
|
||||
public void bitfieldShouldAllowMultipleSubcommands() {
|
||||
void bitfieldShouldAllowMultipleSubcommands() {
|
||||
|
||||
assertThat(clusterConnection.stringCommands().bitField(JedisConverters.toBytes(KEY_1),
|
||||
create().incr(signed(5)).valueAt(BitFieldSubCommands.Offset.offset(100L)).by(1L).get(unsigned(4)).valueAt(0L)))
|
||||
@@ -2452,7 +2457,7 @@ public class LettuceClusterConnectionTests implements ClusterConnectionTests {
|
||||
|
||||
@Test // DATAREDIS-562
|
||||
@IfProfileValue(name = "redisVersion", value = "3.2+")
|
||||
public void bitfieldShouldWorkUsingNonZeroBasedOffset() {
|
||||
void bitfieldShouldWorkUsingNonZeroBasedOffset() {
|
||||
|
||||
assertThat(
|
||||
clusterConnection.stringCommands().bitField(JedisConverters.toBytes(KEY_1),
|
||||
@@ -2468,7 +2473,7 @@ public class LettuceClusterConnectionTests implements ClusterConnectionTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-1103
|
||||
public void setKeepTTL() {
|
||||
void setKeepTTL() {
|
||||
|
||||
long expireSeconds = 10;
|
||||
nativeConnection.setex(KEY_1, expireSeconds, VALUE_1);
|
||||
|
||||
@@ -43,6 +43,7 @@ import org.springframework.data.redis.connection.ClusterTopologyProvider;
|
||||
import org.springframework.data.redis.connection.MessageListener;
|
||||
import org.springframework.data.redis.connection.RedisClusterConnection;
|
||||
import org.springframework.data.redis.connection.RedisConfiguration;
|
||||
import org.springframework.data.redis.test.extension.LettuceTestClientResources;
|
||||
import org.springframework.data.redis.test.util.RedisClusterRule;
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
|
||||
@@ -48,6 +48,7 @@ import org.springframework.data.redis.connection.RedisConnection;
|
||||
import org.springframework.data.redis.connection.RedisStandaloneConfiguration;
|
||||
import org.springframework.data.redis.connection.RedisStaticMasterReplicaConfiguration;
|
||||
import org.springframework.data.redis.connection.StringRedisConnection;
|
||||
import org.springframework.data.redis.test.extension.LettuceTestClientResources;
|
||||
|
||||
/**
|
||||
* Integration test of {@link LettuceConnectionFactory}
|
||||
|
||||
@@ -19,7 +19,7 @@ import static org.assertj.core.api.Assertions.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.springframework.data.redis.connection.ClusterTestVariables.*;
|
||||
import static org.springframework.data.redis.connection.RedisConfiguration.*;
|
||||
import static org.springframework.data.redis.connection.lettuce.LettuceTestClientResources.*;
|
||||
import static org.springframework.data.redis.test.extension.LettuceTestClientResources.*;
|
||||
import static org.springframework.test.util.ReflectionTestUtils.*;
|
||||
|
||||
import io.lettuce.core.AbstractRedisClient;
|
||||
@@ -59,6 +59,7 @@ import org.springframework.data.redis.connection.RedisPassword;
|
||||
import org.springframework.data.redis.connection.RedisSentinelConfiguration;
|
||||
import org.springframework.data.redis.connection.RedisSocketConfiguration;
|
||||
import org.springframework.data.redis.connection.RedisStandaloneConfiguration;
|
||||
import org.springframework.data.redis.test.extension.LettuceTestClientResources;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
|
||||
/**
|
||||
|
||||
@@ -41,6 +41,7 @@ import org.springframework.data.redis.connection.RedisConnection;
|
||||
import org.springframework.data.redis.connection.RedisSentinelConfiguration;
|
||||
import org.springframework.data.redis.connection.ReturnType;
|
||||
import org.springframework.data.redis.connection.StringRedisConnection;
|
||||
import org.springframework.data.redis.test.extension.LettuceTestClientResources;
|
||||
import org.springframework.data.redis.test.util.RedisSentinelRule;
|
||||
import org.springframework.data.redis.test.util.RelaxedJUnit4ClassRunner;
|
||||
import org.springframework.data.redis.test.util.RequiresRedisSentinel;
|
||||
|
||||
@@ -17,7 +17,6 @@ package org.springframework.data.redis.connection.lettuce;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.junit.Assume.*;
|
||||
import static org.springframework.data.redis.SpinBarrier.*;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
@@ -33,6 +32,7 @@ import org.springframework.data.redis.connection.AbstractConnectionPipelineInteg
|
||||
import org.springframework.data.redis.connection.DefaultStringRedisConnection;
|
||||
import org.springframework.data.redis.connection.ReturnType;
|
||||
import org.springframework.data.redis.connection.StringRedisConnection;
|
||||
import org.springframework.data.redis.test.extension.LettuceTestClientResources;
|
||||
import org.springframework.data.redis.test.util.RelaxedJUnit4ClassRunner;
|
||||
import org.springframework.test.annotation.IfProfileValue;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
|
||||
@@ -33,37 +33,31 @@ import org.springframework.test.annotation.IfProfileValue;
|
||||
public class LettuceConnectionPipelineTxIntegrationTests extends LettuceConnectionTransactionIntegrationTests {
|
||||
|
||||
@Test
|
||||
@IfProfileValue(name = "redisVersion", value = "2.6+")
|
||||
public void testEvalShaNotFound() {
|
||||
assertThatExceptionOfType(RedisPipelineException.class).isThrownBy(() -> super.testEvalShaNotFound());
|
||||
}
|
||||
|
||||
@Test
|
||||
@IfProfileValue(name = "redisVersion", value = "2.6+")
|
||||
public void testEvalReturnSingleError() {
|
||||
assertThatExceptionOfType(RedisPipelineException.class).isThrownBy(() -> super.testEvalReturnSingleError());
|
||||
}
|
||||
|
||||
@Test
|
||||
@IfProfileValue(name = "redisVersion", value = "2.6+")
|
||||
public void testRestoreBadData() {
|
||||
assertThatExceptionOfType(RedisPipelineException.class).isThrownBy(() -> super.testRestoreBadData());
|
||||
}
|
||||
|
||||
@Test
|
||||
@IfProfileValue(name = "redisVersion", value = "2.6+")
|
||||
public void testRestoreExistingKey() {
|
||||
assertThatExceptionOfType(RedisPipelineException.class).isThrownBy(() -> super.testRestoreExistingKey());
|
||||
}
|
||||
|
||||
@Test
|
||||
@IfProfileValue(name = "redisVersion", value = "2.6+")
|
||||
public void testEvalArrayScriptError() {
|
||||
assertThatExceptionOfType(RedisPipelineException.class).isThrownBy(() -> super.testEvalArrayScriptError());
|
||||
}
|
||||
|
||||
@Test
|
||||
@IfProfileValue(name = "redisVersion", value = "2.6+")
|
||||
public void testEvalShaArrayError() {
|
||||
assertThatExceptionOfType(RedisPipelineException.class).isThrownBy(() -> super.testEvalShaArrayError());
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ import org.junit.runner.RunWith;
|
||||
import org.springframework.data.redis.connection.AbstractConnectionTransactionIntegrationTests;
|
||||
import org.springframework.data.redis.connection.DefaultStringRedisConnection;
|
||||
import org.springframework.data.redis.connection.StringRedisConnection;
|
||||
import org.springframework.data.redis.test.extension.LettuceTestClientResources;
|
||||
import org.springframework.data.redis.test.util.RelaxedJUnit4ClassRunner;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
|
||||
|
||||
@@ -30,18 +30,14 @@ import java.lang.reflect.InvocationTargetException;
|
||||
import java.time.Duration;
|
||||
import java.util.Collections;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Suite;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.springframework.dao.InvalidDataAccessResourceUsageException;
|
||||
import org.springframework.data.redis.connection.AbstractConnectionUnitTestBase;
|
||||
import org.springframework.data.redis.connection.RedisServerCommands.ShutdownOption;
|
||||
import org.springframework.data.redis.connection.RedisStreamCommands.XAddOptions;
|
||||
import org.springframework.data.redis.connection.RedisStreamCommands.XClaimOptions;
|
||||
import org.springframework.data.redis.connection.lettuce.LettuceConnectionUnitTestSuite.LettuceConnectionUnitTests;
|
||||
import org.springframework.data.redis.connection.lettuce.LettuceConnectionUnitTestSuite.LettucePipelineConnectionUnitTests;
|
||||
import org.springframework.data.redis.connection.stream.MapRecord;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
|
||||
@@ -49,21 +45,19 @@ import org.springframework.test.util.ReflectionTestUtils;
|
||||
* @author Christoph Strobl
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
@RunWith(Suite.class)
|
||||
@Suite.SuiteClasses({ LettuceConnectionUnitTests.class, LettucePipelineConnectionUnitTests.class })
|
||||
public class LettuceConnectionUnitTestSuite {
|
||||
public class LettuceConnectionUnitTests {
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
public static class LettuceConnectionUnitTests extends AbstractConnectionUnitTestBase<RedisAsyncCommands> {
|
||||
public static class BasicUnitTests extends AbstractConnectionUnitTestBase<RedisAsyncCommands> {
|
||||
|
||||
protected LettuceConnection connection;
|
||||
private RedisClient clientMock;
|
||||
protected StatefulRedisConnection<byte[], byte[]> statefulConnectionMock;
|
||||
protected RedisAsyncCommands<byte[], byte[]> asyncCommandsMock;
|
||||
protected RedisCommands syncCommandsMock;
|
||||
StatefulRedisConnection<byte[], byte[]> statefulConnectionMock;
|
||||
RedisAsyncCommands<byte[], byte[]> asyncCommandsMock;
|
||||
RedisCommands syncCommandsMock;
|
||||
|
||||
@SuppressWarnings({ "unchecked" })
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setUp() throws InvocationTargetException, IllegalAccessException {
|
||||
|
||||
clientMock = mock(RedisClient.class);
|
||||
@@ -115,7 +109,7 @@ public class LettuceConnectionUnitTestSuite {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-277
|
||||
public void slaveOfShouldThrowExectpionWhenCalledForNullHost() {
|
||||
void slaveOfShouldThrowExectpionWhenCalledForNullHost() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> connection.slaveOf(null, 0));
|
||||
}
|
||||
|
||||
@@ -134,22 +128,23 @@ public class LettuceConnectionUnitTestSuite {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-348
|
||||
public void shouldThrowExceptionWhenAccessingRedisSentinelsCommandsWhenNoSentinelsConfigured() {
|
||||
void shouldThrowExceptionWhenAccessingRedisSentinelsCommandsWhenNoSentinelsConfigured() {
|
||||
assertThatExceptionOfType(InvalidDataAccessResourceUsageException.class)
|
||||
.isThrownBy(() -> connection.getSentinelConnection());
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-431
|
||||
public void dbIndexShouldBeSetWhenObtainingConnection() {
|
||||
void dbIndexShouldBeSetWhenObtainingConnection() {
|
||||
|
||||
connection = new LettuceConnection(null, 0, clientMock, null, 1);
|
||||
connection = new LettuceConnection(null, 0, clientMock, null, 0);
|
||||
connection.select(1);
|
||||
connection.getNativeConnection();
|
||||
|
||||
verify(syncCommandsMock, times(1)).select(1);
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-603
|
||||
public void translatesUnknownExceptions() {
|
||||
void translatesUnknownExceptions() {
|
||||
|
||||
IllegalArgumentException exception = new IllegalArgumentException("Aw, snap!");
|
||||
|
||||
@@ -161,7 +156,7 @@ public class LettuceConnectionUnitTestSuite {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-603
|
||||
public void translatesPipelineUnknownExceptions() throws Exception {
|
||||
void translatesPipelineUnknownExceptions() throws Exception {
|
||||
|
||||
IllegalArgumentException exception = new IllegalArgumentException("Aw, snap!");
|
||||
|
||||
@@ -174,7 +169,7 @@ public class LettuceConnectionUnitTestSuite {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-1122
|
||||
public void xaddShouldHonorMaxlen() {
|
||||
void xaddShouldHonorMaxlen() {
|
||||
|
||||
MapRecord<byte[], byte[], byte[]> record = MapRecord.create("key".getBytes(), Collections.emptyMap());
|
||||
|
||||
@@ -190,7 +185,7 @@ public class LettuceConnectionUnitTestSuite {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-1226
|
||||
public void xClaimShouldNotAddJustIdFlagToArgs() {
|
||||
void xClaimShouldNotAddJustIdFlagToArgs() {
|
||||
|
||||
connection.streamCommands().xClaim("key".getBytes(), "group", "owner",
|
||||
XClaimOptions.minIdle(Duration.ofMillis(100)).ids("1-1"));
|
||||
@@ -207,7 +202,7 @@ public class LettuceConnectionUnitTestSuite {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-1226
|
||||
public void xClaimJustIdShouldAddJustIdFlagToArgs() {
|
||||
void xClaimJustIdShouldAddJustIdFlagToArgs() {
|
||||
|
||||
connection.streamCommands().xClaimJustId("key".getBytes(), "group", "owner",
|
||||
XClaimOptions.minIdle(Duration.ofMillis(100)).ids("1-1"));
|
||||
@@ -223,10 +218,10 @@ public class LettuceConnectionUnitTestSuite {
|
||||
}
|
||||
}
|
||||
|
||||
public static class LettucePipelineConnectionUnitTests extends LettuceConnectionUnitTests {
|
||||
public static class LettucePipelineConnectionUnitTests extends BasicUnitTests {
|
||||
|
||||
@Override
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setUp() throws InvocationTargetException, IllegalAccessException {
|
||||
super.setUp();
|
||||
this.connection.openPipeline();
|
||||
@@ -27,6 +27,8 @@ import java.time.Duration;
|
||||
import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.data.redis.test.extension.LettuceTestClientResources;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link LettucePoolingClientConfiguration}.
|
||||
*
|
||||
|
||||
@@ -15,13 +15,12 @@
|
||||
*/
|
||||
package org.springframework.data.redis.connection.lettuce;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.mockito.Mockito.anyInt;
|
||||
import static org.mockito.Mockito.anyString;
|
||||
import static org.springframework.data.redis.connection.ClusterTestVariables.*;
|
||||
|
||||
import io.lettuce.core.ConnectionFuture;
|
||||
import io.lettuce.core.api.StatefulRedisConnection;
|
||||
import io.lettuce.core.api.reactive.RedisReactiveCommands;
|
||||
import io.lettuce.core.cluster.RedisClusterClient;
|
||||
@@ -33,11 +32,14 @@ import reactor.test.StepVerifier;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import org.mockito.junit.jupiter.MockitoSettings;
|
||||
import org.mockito.quality.Strictness;
|
||||
|
||||
import org.springframework.data.redis.connection.RedisClusterNode;
|
||||
import org.springframework.data.redis.connection.lettuce.LettuceConnectionProvider.TargetAware;
|
||||
|
||||
@@ -46,7 +48,8 @@ import org.springframework.data.redis.connection.lettuce.LettuceConnectionProvid
|
||||
*
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
@MockitoSettings(strictness = Strictness.LENIENT)
|
||||
public class LettuceReactiveRedisClusterConnectionUnitTests {
|
||||
|
||||
static final RedisClusterNode NODE1 = new RedisClusterNode(CLUSTER_HOST, MASTER_NODE_1_PORT);
|
||||
@@ -59,7 +62,7 @@ public class LettuceReactiveRedisClusterConnectionUnitTests {
|
||||
@Mock RedisReactiveCommands<ByteBuffer, ByteBuffer> reactiveNodeCommands;
|
||||
@Mock(extraInterfaces = TargetAware.class) LettuceConnectionProvider connectionProvider;
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void before() {
|
||||
|
||||
when(connectionProvider.getConnectionAsync(any())).thenReturn(CompletableFuture.completedFuture(sharedConnection));
|
||||
|
||||
@@ -15,12 +15,9 @@
|
||||
*/
|
||||
package org.springframework.data.redis.connection.lettuce;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.junit.Assume.*;
|
||||
import static org.springframework.data.redis.SpinBarrier.*;
|
||||
|
||||
import io.lettuce.core.ScriptOutputType;
|
||||
import org.awaitility.Awaitility;
|
||||
import reactor.test.StepVerifier;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
@@ -29,6 +26,7 @@ import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import org.awaitility.Awaitility;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.data.redis.RedisSystemException;
|
||||
|
||||
@@ -42,6 +42,9 @@ import org.springframework.data.redis.connection.RedisSentinelConfiguration;
|
||||
import org.springframework.data.redis.connection.RedisSentinelConnection;
|
||||
import org.springframework.data.redis.connection.RedisServer;
|
||||
import org.springframework.data.redis.connection.StringRedisConnection;
|
||||
import org.springframework.data.redis.connection.lettuce.extension.LettuceConnectionFactoryExtension;
|
||||
import org.springframework.data.redis.test.extension.LettuceTestClientResources;
|
||||
import org.springframework.data.redis.test.extension.RedisSentinel;
|
||||
import org.springframework.data.redis.test.util.MinimumRedisVersionRule;
|
||||
import org.springframework.data.redis.test.util.RedisSentinelRule;
|
||||
|
||||
@@ -76,7 +79,6 @@ public class LettuceSentinelIntegrationTests extends AbstractConnectionIntegrati
|
||||
public LettuceSentinelIntegrationTests(LettuceConnectionFactory connectionFactory, String displayName) {
|
||||
|
||||
this.connectionFactory = connectionFactory;
|
||||
ConnectionFactoryTracker.add(connectionFactory);
|
||||
}
|
||||
|
||||
@Parameters(name = "{1}")
|
||||
@@ -84,17 +86,10 @@ public class LettuceSentinelIntegrationTests extends AbstractConnectionIntegrati
|
||||
|
||||
List<Object[]> parameters = new ArrayList<>();
|
||||
|
||||
LettuceConnectionFactory lettuceConnectionFactory = new LettuceConnectionFactory(SENTINEL_CONFIG);
|
||||
lettuceConnectionFactory.setClientResources(LettuceTestClientResources.getSharedClientResources());
|
||||
lettuceConnectionFactory.setShareNativeConnection(false);
|
||||
lettuceConnectionFactory.setShutdownTimeout(0);
|
||||
lettuceConnectionFactory.afterPropertiesSet();
|
||||
|
||||
LettuceConnectionFactory pooledConnectionFactory = new LettuceConnectionFactory(SENTINEL_CONFIG,
|
||||
LettucePoolingClientConfiguration.builder()
|
||||
.clientResources(LettuceTestClientResources.getSharedClientResources()).build());
|
||||
pooledConnectionFactory.setShareNativeConnection(false);
|
||||
pooledConnectionFactory.afterPropertiesSet();
|
||||
LettuceConnectionFactory lettuceConnectionFactory = LettuceConnectionFactoryExtension
|
||||
.getConnectionFactory(RedisSentinel.class, false);
|
||||
LettuceConnectionFactory pooledConnectionFactory = LettuceConnectionFactoryExtension
|
||||
.getConnectionFactory(RedisSentinel.class, true);
|
||||
|
||||
parameters.add(new Object[] { lettuceConnectionFactory, "Sentinel" });
|
||||
parameters.add(new Object[] { pooledConnectionFactory, "Sentinel/Pooled" });
|
||||
@@ -116,11 +111,6 @@ public class LettuceSentinelIntegrationTests extends AbstractConnectionIntegrati
|
||||
connection.close();
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void afterClass() {
|
||||
ConnectionFactoryTracker.cleanUp();
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-348
|
||||
public void shouldReadMastersCorrectly() {
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@ import io.lettuce.core.resource.ClientResources;
|
||||
import java.time.Duration;
|
||||
|
||||
import org.springframework.data.redis.connection.lettuce.LettuceClientConfiguration.LettuceClientConfigurationBuilder;
|
||||
import org.springframework.data.redis.test.extension.LettuceTestClientResources;
|
||||
|
||||
/**
|
||||
* Creates a specific client configuration for Lettuce tests.
|
||||
|
||||
@@ -14,49 +14,3 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.data.redis.connection.lettuce;
|
||||
|
||||
import io.lettuce.core.resource.DefaultEventLoopGroupProvider;
|
||||
import io.netty.util.concurrent.DefaultPromise;
|
||||
import io.netty.util.concurrent.EventExecutorGroup;
|
||||
import io.netty.util.concurrent.ImmediateEventExecutor;
|
||||
import io.netty.util.concurrent.Promise;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* A {@link io.lettuce.core.resource.EventLoopGroupProvider} suitable for testing. Preserves the event loop groups
|
||||
* between tests. Every time a new {@link TestEventLoopGroupProvider} instance is created, a
|
||||
* {@link Runtime#addShutdownHook(Thread) shutdown hook} is added to close the resources.
|
||||
*
|
||||
* @author Mark Paluch
|
||||
* @author Christoph Strobl
|
||||
*/
|
||||
class TestEventLoopGroupProvider extends DefaultEventLoopGroupProvider {
|
||||
|
||||
private static final int NUMBER_OF_THREADS = 10;
|
||||
|
||||
public TestEventLoopGroupProvider() {
|
||||
|
||||
super(NUMBER_OF_THREADS);
|
||||
|
||||
Runtime.getRuntime().addShutdownHook(new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
TestEventLoopGroupProvider.this.shutdown(0, 0, TimeUnit.MILLISECONDS).get(1, TimeUnit.SECONDS);
|
||||
} catch (Exception o_O) {
|
||||
// ignored
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public Promise<Boolean> release(EventExecutorGroup eventLoopGroup, long quietPeriod, long timeout, TimeUnit unit) {
|
||||
|
||||
DefaultPromise<Boolean> result = new DefaultPromise<>(ImmediateEventExecutor.INSTANCE);
|
||||
result.setSuccess(true);
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.data.redis.SettingsUtils;
|
||||
import org.springframework.data.redis.connection.AbstractTransactionalTestBase;
|
||||
import org.springframework.data.redis.connection.lettuce.TransactionalLettuceIntegrationTests.LettuceContextConfiguration;
|
||||
import org.springframework.data.redis.test.extension.LettuceTestClientResources;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,279 @@
|
||||
/*
|
||||
* Copyright 2020 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.data.redis.connection.lettuce.extension;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.jupiter.api.extension.ExtensionContext;
|
||||
import org.junit.jupiter.api.extension.ParameterContext;
|
||||
import org.junit.jupiter.api.extension.ParameterResolutionException;
|
||||
import org.junit.jupiter.api.extension.ParameterResolver;
|
||||
|
||||
import org.springframework.data.redis.ConnectionFactoryTracker;
|
||||
import org.springframework.data.redis.SettingsUtils;
|
||||
import org.springframework.data.redis.connection.ReactiveRedisConnectionFactory;
|
||||
import org.springframework.data.redis.connection.RedisClusterConfiguration;
|
||||
import org.springframework.data.redis.connection.RedisConfiguration;
|
||||
import org.springframework.data.redis.connection.RedisConnectionFactory;
|
||||
import org.springframework.data.redis.connection.RedisSentinelConfiguration;
|
||||
import org.springframework.data.redis.connection.RedisStandaloneConfiguration;
|
||||
import org.springframework.data.redis.connection.lettuce.LettuceClientConfiguration;
|
||||
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
|
||||
import org.springframework.data.redis.connection.lettuce.LettucePool;
|
||||
import org.springframework.data.redis.connection.lettuce.LettucePoolingClientConfiguration;
|
||||
import org.springframework.data.redis.test.extension.LettuceTestClientResources;
|
||||
import org.springframework.data.redis.test.extension.RedisCluster;
|
||||
import org.springframework.data.redis.test.extension.RedisSentinel;
|
||||
import org.springframework.data.redis.test.extension.RedisStanalone;
|
||||
import org.springframework.data.redis.test.extension.ShutdownQueue;
|
||||
import org.springframework.data.util.Lazy;
|
||||
|
||||
/**
|
||||
* JUnit {@link ParameterResolver} providing pre-cached {@link LettuceConnectionFactory} instances. Connection factories
|
||||
* can be qualified with {@code @RedisStanalone} (default), {@code @RedisSentinel} or {@code @RedisCluster} to obtain a
|
||||
* specific factory instance. Instances are managed by this extension and will be shut down on JVM shutdown.
|
||||
*
|
||||
* @author Mark Paluch
|
||||
* @see RedisStanalone
|
||||
* @see RedisSentinel
|
||||
* @see RedisCluster
|
||||
*/
|
||||
public class LettuceConnectionFactoryExtension implements ParameterResolver {
|
||||
|
||||
private static final ExtensionContext.Namespace NAMESPACE = ExtensionContext.Namespace
|
||||
.create(LettuceConnectionFactoryExtension.class);
|
||||
|
||||
private static final Lazy<LettuceConnectionFactory> STANDALONE = Lazy.of(() -> {
|
||||
|
||||
LettuceClientConfiguration configuration = LettucePoolingClientConfiguration.builder()
|
||||
.clientResources(LettuceTestClientResources.getSharedClientResources()).build();
|
||||
|
||||
LettuceConnectionFactory factory = new ManagedLettuceConnectionFactory(SettingsUtils.standaloneConfiguration(),
|
||||
configuration);
|
||||
factory.afterPropertiesSet();
|
||||
ShutdownQueue.register(ShutdownQueue.toCloseable(factory));
|
||||
|
||||
return factory;
|
||||
});
|
||||
|
||||
private static final Lazy<LettuceConnectionFactory> SENTINEL = Lazy.of(() -> {
|
||||
|
||||
LettuceClientConfiguration configuration = LettucePoolingClientConfiguration.builder()
|
||||
.clientResources(LettuceTestClientResources.getSharedClientResources()).build();
|
||||
|
||||
LettuceConnectionFactory factory = new ManagedLettuceConnectionFactory(SettingsUtils.sentinelConfiguration(),
|
||||
configuration);
|
||||
factory.afterPropertiesSet();
|
||||
ShutdownQueue.register(ShutdownQueue.toCloseable(factory));
|
||||
|
||||
return factory;
|
||||
});
|
||||
|
||||
private static final Lazy<LettuceConnectionFactory> CLUSTER = Lazy.of(() -> {
|
||||
|
||||
LettuceClientConfiguration configuration = LettucePoolingClientConfiguration.builder()
|
||||
.clientResources(LettuceTestClientResources.getSharedClientResources()).build();
|
||||
|
||||
LettuceConnectionFactory factory = new ManagedLettuceConnectionFactory(SettingsUtils.clusterConfiguration(),
|
||||
configuration);
|
||||
factory.afterPropertiesSet();
|
||||
ShutdownQueue.register(ShutdownQueue.toCloseable(factory));
|
||||
|
||||
return factory;
|
||||
});
|
||||
|
||||
private static final Lazy<LettuceConnectionFactory> STANDALONE_UNPOOLED = Lazy.of(() -> {
|
||||
|
||||
LettuceClientConfiguration configuration = LettuceClientConfiguration.builder()
|
||||
.clientResources(LettuceTestClientResources.getSharedClientResources()).build();
|
||||
|
||||
LettuceConnectionFactory factory = new ManagedLettuceConnectionFactory(SettingsUtils.standaloneConfiguration(),
|
||||
configuration);
|
||||
factory.afterPropertiesSet();
|
||||
ShutdownQueue.register(ShutdownQueue.toCloseable(factory));
|
||||
|
||||
return factory;
|
||||
});
|
||||
|
||||
private static final Lazy<LettuceConnectionFactory> SENTINEL_UNPOOLED = Lazy.of(() -> {
|
||||
|
||||
LettuceClientConfiguration configuration = LettuceClientConfiguration.builder()
|
||||
.clientResources(LettuceTestClientResources.getSharedClientResources()).build();
|
||||
|
||||
LettuceConnectionFactory factory = new ManagedLettuceConnectionFactory(SettingsUtils.sentinelConfiguration(),
|
||||
configuration);
|
||||
factory.afterPropertiesSet();
|
||||
ShutdownQueue.register(ShutdownQueue.toCloseable(factory));
|
||||
|
||||
return factory;
|
||||
});
|
||||
|
||||
private static final Lazy<LettuceConnectionFactory> CLUSTER_UNPOOLED = Lazy.of(() -> {
|
||||
|
||||
LettuceClientConfiguration configuration = LettuceClientConfiguration.builder()
|
||||
.clientResources(LettuceTestClientResources.getSharedClientResources()).build();
|
||||
|
||||
LettuceConnectionFactory factory = new ManagedLettuceConnectionFactory(SettingsUtils.clusterConfiguration(),
|
||||
configuration);
|
||||
factory.afterPropertiesSet();
|
||||
ShutdownQueue.register(ShutdownQueue.toCloseable(factory));
|
||||
|
||||
return factory;
|
||||
});
|
||||
|
||||
private static final Map<Class<?>, Lazy<LettuceConnectionFactory>> pooledFactories;
|
||||
private static final Map<Class<?>, Lazy<LettuceConnectionFactory>> unpooledFactories;
|
||||
|
||||
static {
|
||||
|
||||
pooledFactories = new HashMap<>();
|
||||
pooledFactories.put(RedisStanalone.class, STANDALONE);
|
||||
pooledFactories.put(RedisSentinel.class, SENTINEL);
|
||||
pooledFactories.put(RedisCluster.class, CLUSTER);
|
||||
|
||||
unpooledFactories = new HashMap<>();
|
||||
unpooledFactories.put(RedisStanalone.class, STANDALONE_UNPOOLED);
|
||||
unpooledFactories.put(RedisSentinel.class, SENTINEL_UNPOOLED);
|
||||
unpooledFactories.put(RedisCluster.class, CLUSTER_UNPOOLED);
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtain a {@link LettuceConnectionFactory} described by {@code qualifier}. Instances are managed by this extension
|
||||
* and will be shut down on JVM shutdown.
|
||||
*
|
||||
* @param qualifier an be any of {@link RedisStanalone}, {@link RedisSentinel}, {@link RedisCluster}.
|
||||
* @return the managed {@link LettuceConnectionFactory}.
|
||||
*/
|
||||
public static LettuceConnectionFactory getConnectionFactory(Class<? extends Annotation> qualifier) {
|
||||
return getConnectionFactory(qualifier, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtain a {@link LettuceConnectionFactory} described by {@code qualifier}. Instances are managed by this extension
|
||||
* and will be shut down on JVM shutdown.
|
||||
*
|
||||
* @param qualifier an be any of {@link RedisStanalone}, {@link RedisSentinel}, {@link RedisCluster}.
|
||||
* @return the managed {@link LettuceConnectionFactory}.
|
||||
*/
|
||||
public static LettuceConnectionFactory getConnectionFactory(Class<? extends Annotation> qualifier, boolean pooled) {
|
||||
return pooled ? pooledFactories.get(qualifier).get() : unpooledFactories.get(qualifier).get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsParameter(ParameterContext parameterContext, ExtensionContext extensionContext)
|
||||
throws ParameterResolutionException {
|
||||
return RedisConnectionFactory.class.isAssignableFrom(parameterContext.getParameter().getType())
|
||||
|| ReactiveRedisConnectionFactory.class.isAssignableFrom(parameterContext.getParameter().getType());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object resolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext)
|
||||
throws ParameterResolutionException {
|
||||
|
||||
ExtensionContext.Store store = extensionContext.getStore(NAMESPACE);
|
||||
|
||||
Class<? extends Annotation> qualifier = getQualifier(parameterContext);
|
||||
|
||||
return store.getOrComputeIfAbsent(qualifier, LettuceConnectionFactoryExtension::getConnectionFactory);
|
||||
}
|
||||
|
||||
private static Class<? extends Annotation> getQualifier(ParameterContext parameterContext) {
|
||||
|
||||
if (parameterContext.isAnnotated(RedisSentinel.class)) {
|
||||
return RedisSentinel.class;
|
||||
}
|
||||
|
||||
if (parameterContext.isAnnotated(RedisCluster.class)) {
|
||||
return RedisCluster.class;
|
||||
}
|
||||
|
||||
return RedisStanalone.class;
|
||||
}
|
||||
|
||||
static class ManagedLettuceConnectionFactory extends LettuceConnectionFactory
|
||||
implements ConnectionFactoryTracker.Managed {
|
||||
|
||||
public ManagedLettuceConnectionFactory() {
|
||||
super();
|
||||
}
|
||||
|
||||
public ManagedLettuceConnectionFactory(RedisStandaloneConfiguration configuration) {
|
||||
super(configuration);
|
||||
}
|
||||
|
||||
public ManagedLettuceConnectionFactory(String host, int port) {
|
||||
super(host, port);
|
||||
}
|
||||
|
||||
public ManagedLettuceConnectionFactory(RedisConfiguration redisConfiguration) {
|
||||
super(redisConfiguration);
|
||||
}
|
||||
|
||||
public ManagedLettuceConnectionFactory(RedisSentinelConfiguration sentinelConfiguration) {
|
||||
super(sentinelConfiguration);
|
||||
}
|
||||
|
||||
public ManagedLettuceConnectionFactory(RedisClusterConfiguration clusterConfiguration) {
|
||||
super(clusterConfiguration);
|
||||
}
|
||||
|
||||
public ManagedLettuceConnectionFactory(LettucePool pool) {
|
||||
super(pool);
|
||||
}
|
||||
|
||||
public ManagedLettuceConnectionFactory(RedisStandaloneConfiguration standaloneConfig,
|
||||
LettuceClientConfiguration clientConfig) {
|
||||
super(standaloneConfig, clientConfig);
|
||||
}
|
||||
|
||||
public ManagedLettuceConnectionFactory(RedisConfiguration redisConfiguration,
|
||||
LettuceClientConfiguration clientConfig) {
|
||||
super(redisConfiguration, clientConfig);
|
||||
}
|
||||
|
||||
public ManagedLettuceConnectionFactory(RedisSentinelConfiguration sentinelConfiguration,
|
||||
LettuceClientConfiguration clientConfig) {
|
||||
super(sentinelConfiguration, clientConfig);
|
||||
}
|
||||
|
||||
public ManagedLettuceConnectionFactory(RedisClusterConfiguration clusterConfiguration,
|
||||
LettuceClientConfiguration clientConfig) {
|
||||
super(clusterConfiguration, clientConfig);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
|
||||
StringBuilder builder = new StringBuilder("Lettuce");
|
||||
|
||||
if (isClusterAware()) {
|
||||
builder.append(" Cluster");
|
||||
}
|
||||
|
||||
if (isRedisSentinelAware()) {
|
||||
builder.append(" Sentinel");
|
||||
}
|
||||
|
||||
if (this.getClientConfiguration() instanceof LettucePoolingClientConfiguration) {
|
||||
builder.append(" [pool]");
|
||||
}
|
||||
|
||||
return builder.toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -19,18 +19,18 @@ import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import java.time.Duration;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link StreamReadOptions}.
|
||||
*
|
||||
*
|
||||
* @author Mark Paluch
|
||||
* @author Kaizhou Zhang
|
||||
*/
|
||||
public class StreamReadOptionsUnitTests {
|
||||
class StreamReadOptionsUnitTests {
|
||||
|
||||
@Test // DATAREDIS-1138
|
||||
public void shouldConsiderBlocking() {
|
||||
void shouldConsiderBlocking() {
|
||||
|
||||
assertThat(StreamReadOptions.empty().isBlocking()).isFalse();
|
||||
assertThat(StreamReadOptions.empty().block(Duration.ofSeconds(1)).isBlocking()).isTrue();
|
||||
@@ -38,9 +38,9 @@ public class StreamReadOptionsUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-1210
|
||||
public void testToString() {
|
||||
void testToString() {
|
||||
|
||||
assertThat(StreamReadOptions.empty().toString())
|
||||
.isEqualTo("StreamReadOptions{block=null, count=null, noack=false, blocking=false}");
|
||||
assertThat(StreamReadOptions.empty())
|
||||
.hasToString("StreamReadOptions{block=null, count=null, noack=false, blocking=false}");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,12 +28,14 @@ import org.springframework.data.redis.SettingsUtils;
|
||||
import org.springframework.data.redis.StringObjectFactory;
|
||||
import org.springframework.data.redis.connection.RedisStandaloneConfiguration;
|
||||
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
|
||||
import org.springframework.data.redis.connection.lettuce.LettuceTestClientResources;
|
||||
import org.springframework.data.redis.connection.lettuce.extension.LettuceConnectionFactoryExtension;
|
||||
import org.springframework.data.redis.test.extension.LettuceTestClientResources;
|
||||
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
|
||||
import org.springframework.data.redis.serializer.GenericToStringSerializer;
|
||||
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
|
||||
import org.springframework.data.redis.serializer.OxmSerializer;
|
||||
import org.springframework.data.redis.serializer.StringRedisSerializer;
|
||||
import org.springframework.data.redis.test.extension.RedisStanalone;
|
||||
import org.springframework.oxm.xstream.XStreamMarshaller;
|
||||
|
||||
/**
|
||||
@@ -49,9 +51,6 @@ abstract public class AbstractOperationsTestParams {
|
||||
// DATAREDIS-241
|
||||
public static Collection<Object[]> testParams() {
|
||||
|
||||
RedisStandaloneConfiguration standaloneConfiguration = new RedisStandaloneConfiguration(SettingsUtils.getHost(),
|
||||
SettingsUtils.getPort());
|
||||
|
||||
ObjectFactory<String> stringFactory = new StringObjectFactory();
|
||||
ObjectFactory<Long> longFactory = new LongObjectFactory();
|
||||
ObjectFactory<Double> doubleFactory = new DoubleObjectFactory();
|
||||
@@ -66,9 +65,8 @@ abstract public class AbstractOperationsTestParams {
|
||||
throw new RuntimeException("Cannot init XStream", ex);
|
||||
}
|
||||
|
||||
LettuceConnectionFactory lettuceConnectionFactory = new LettuceConnectionFactory(standaloneConfiguration);
|
||||
lettuceConnectionFactory.setClientResources(LettuceTestClientResources.getSharedClientResources());
|
||||
lettuceConnectionFactory.afterPropertiesSet();
|
||||
LettuceConnectionFactory lettuceConnectionFactory = LettuceConnectionFactoryExtension
|
||||
.getConnectionFactory(RedisStanalone.class);
|
||||
|
||||
RedisTemplate<String, String> stringTemplate = new StringRedisTemplate();
|
||||
stringTemplate.setConnectionFactory(lettuceConnectionFactory);
|
||||
|
||||
@@ -15,14 +15,19 @@
|
||||
*/
|
||||
package org.springframework.data.redis.core;
|
||||
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.assertj.core.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Mockito;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import org.mockito.junit.jupiter.MockitoSettings;
|
||||
import org.mockito.quality.Strictness;
|
||||
|
||||
import org.springframework.dao.InvalidDataAccessApiUsageException;
|
||||
import org.springframework.data.redis.connection.RedisConnection;
|
||||
import org.springframework.data.redis.connection.RedisConnectionFactory;
|
||||
@@ -32,8 +37,9 @@ import org.springframework.util.ClassUtils;
|
||||
/**
|
||||
* @author Christoph Strobl
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class ConnectionSplittingInterceptorUnitTests {
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
@MockitoSettings(strictness = Strictness.LENIENT)
|
||||
class ConnectionSplittingInterceptorUnitTests {
|
||||
|
||||
private static final Method WRITE_METHOD, READONLY_METHOD;
|
||||
|
||||
@@ -54,35 +60,37 @@ public class ConnectionSplittingInterceptorUnitTests {
|
||||
}
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
interceptor = new ConnectionSplittingInterceptor(connectionFactoryMock);
|
||||
Mockito.when(connectionFactoryMock.getConnection()).thenReturn(freshConnectionMock);
|
||||
when(connectionFactoryMock.getConnection()).thenReturn(freshConnectionMock);
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-73
|
||||
public void interceptorShouldRequestFreshConnectionForReadonlyCommand() throws Throwable {
|
||||
void interceptorShouldRequestFreshConnectionForReadonlyCommand() throws Throwable {
|
||||
|
||||
interceptor.intercept(boundConnectionMock, READONLY_METHOD, new Object[] { new byte[] {} }, null);
|
||||
Mockito.verify(connectionFactoryMock, Mockito.times(1)).getConnection();
|
||||
Mockito.verifyZeroInteractions(boundConnectionMock);
|
||||
verify(connectionFactoryMock, times(1)).getConnection();
|
||||
verifyZeroInteractions(boundConnectionMock);
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-73
|
||||
public void interceptorShouldUseBoundConnectionForWriteOperations() throws Throwable {
|
||||
void interceptorShouldUseBoundConnectionForWriteOperations() throws Throwable {
|
||||
|
||||
interceptor.intercept(boundConnectionMock, WRITE_METHOD, new Object[] { new byte[] {}, 0L }, null);
|
||||
Mockito.verify(boundConnectionMock, Mockito.times(1)).expire(Mockito.any(byte[].class), Mockito.anyLong());
|
||||
Mockito.verifyZeroInteractions(connectionFactoryMock);
|
||||
verify(boundConnectionMock, times(1)).expire(any(byte[].class), anyLong());
|
||||
verifyZeroInteractions(connectionFactoryMock);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test(expected = InvalidDataAccessApiUsageException.class) // DATAREDIS-73
|
||||
public void interceptorShouldNotWrapException() throws Throwable {
|
||||
@Test // DATAREDIS-73
|
||||
void interceptorShouldNotWrapException() {
|
||||
|
||||
Mockito.when(freshConnectionMock.keys(Mockito.any(byte[].class))).thenThrow(
|
||||
when(freshConnectionMock.keys(any(byte[].class))).thenThrow(
|
||||
InvalidDataAccessApiUsageException.class);
|
||||
interceptor.intercept(boundConnectionMock, READONLY_METHOD, new Object[] { new byte[] {} }, null);
|
||||
|
||||
Assertions.assertThatExceptionOfType(InvalidDataAccessApiUsageException.class).isThrownBy(
|
||||
() -> interceptor.intercept(boundConnectionMock, READONLY_METHOD, new Object[] { new byte[] {} }, null));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -20,29 +20,32 @@ import static org.mockito.Mockito.*;
|
||||
import java.time.Duration;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import org.mockito.junit.jupiter.MockitoSettings;
|
||||
import org.mockito.quality.Strictness;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link DefaultBoundValueOperations}
|
||||
*
|
||||
*
|
||||
* @author Christoph Strobl
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class DefaultBoundValueOperationsUnitTests {
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
@MockitoSettings(strictness = Strictness.LENIENT)
|
||||
class DefaultBoundValueOperationsUnitTests {
|
||||
|
||||
DefaultBoundValueOperations<String, Object> boundValueOps;
|
||||
private DefaultBoundValueOperations<String, Object> boundValueOps;
|
||||
|
||||
@Mock ValueOperations<String, Object> valueOps;
|
||||
|
||||
static final String KEY = "key-1";
|
||||
static final Object VALUE = "value";
|
||||
private static final String KEY = "key-1";
|
||||
private static final Object VALUE = "value";
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
|
||||
RedisOperations<String, Object> redisOps = mock(RedisOperations.class);
|
||||
when(redisOps.opsForValue()).thenReturn(valueOps);
|
||||
@@ -51,7 +54,7 @@ public class DefaultBoundValueOperationsUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-786
|
||||
public void setIfPresentShouldDelegateCorrectly() {
|
||||
void setIfPresentShouldDelegateCorrectly() {
|
||||
|
||||
boundValueOps.setIfPresent(VALUE);
|
||||
|
||||
@@ -59,7 +62,7 @@ public class DefaultBoundValueOperationsUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-786
|
||||
public void setIfPresentWithTimeoutShouldDelegateCorrectly() {
|
||||
void setIfPresentWithTimeoutShouldDelegateCorrectly() {
|
||||
|
||||
boundValueOps.setIfPresent(VALUE, 10, TimeUnit.SECONDS);
|
||||
|
||||
@@ -67,7 +70,7 @@ public class DefaultBoundValueOperationsUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-815
|
||||
public void setWithDurationOfSecondsShouldDelegateCorrectly() {
|
||||
void setWithDurationOfSecondsShouldDelegateCorrectly() {
|
||||
|
||||
boundValueOps.set(VALUE, Duration.ofSeconds(1));
|
||||
|
||||
@@ -75,7 +78,7 @@ public class DefaultBoundValueOperationsUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-815
|
||||
public void setWithDurationOfMillisShouldDelegateCorrectly() {
|
||||
void setWithDurationOfMillisShouldDelegateCorrectly() {
|
||||
|
||||
boundValueOps.set(VALUE, Duration.ofMillis(250));
|
||||
|
||||
@@ -83,7 +86,7 @@ public class DefaultBoundValueOperationsUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-815
|
||||
public void setIfAbsentWithDurationOfSecondsShouldDelegateCorrectly() {
|
||||
void setIfAbsentWithDurationOfSecondsShouldDelegateCorrectly() {
|
||||
|
||||
boundValueOps.setIfAbsent(VALUE, Duration.ofSeconds(1));
|
||||
|
||||
@@ -91,7 +94,7 @@ public class DefaultBoundValueOperationsUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-815
|
||||
public void setIfAbsentWithDurationOfMillisShouldDelegateCorrectly() {
|
||||
void setIfAbsentWithDurationOfMillisShouldDelegateCorrectly() {
|
||||
|
||||
boundValueOps.setIfAbsent(VALUE, Duration.ofMillis(250));
|
||||
|
||||
@@ -99,7 +102,7 @@ public class DefaultBoundValueOperationsUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-815
|
||||
public void setIfPresentWithDurationOfSecondsShouldDelegateCorrectly() {
|
||||
void setIfPresentWithDurationOfSecondsShouldDelegateCorrectly() {
|
||||
|
||||
boundValueOps.setIfPresent(VALUE, Duration.ofSeconds(1));
|
||||
|
||||
@@ -107,7 +110,7 @@ public class DefaultBoundValueOperationsUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-815
|
||||
public void setIfPresentWithDurationOfMillisShouldDelegateCorrectly() {
|
||||
void setIfPresentWithDurationOfMillisShouldDelegateCorrectly() {
|
||||
|
||||
boundValueOps.setIfPresent(VALUE, Duration.ofMillis(250));
|
||||
|
||||
|
||||
@@ -23,12 +23,14 @@ import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Mockito;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import org.mockito.junit.jupiter.MockitoSettings;
|
||||
import org.mockito.quality.Strictness;
|
||||
|
||||
import org.springframework.data.redis.connection.RedisClusterCommands.AddSlots;
|
||||
import org.springframework.data.redis.connection.RedisClusterConnection;
|
||||
@@ -43,24 +45,25 @@ import org.springframework.data.redis.serializer.StringRedisSerializer;
|
||||
* @author Christoph Strobl
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.Silent.class)
|
||||
public class DefaultClusterOperationsUnitTests {
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
@MockitoSettings(strictness = Strictness.LENIENT)
|
||||
class DefaultClusterOperationsUnitTests {
|
||||
|
||||
static final RedisClusterNode NODE_1 = RedisClusterNode.newRedisClusterNode().listeningAt("127.0.0.1", 6379)
|
||||
private static final RedisClusterNode NODE_1 = RedisClusterNode.newRedisClusterNode().listeningAt("127.0.0.1", 6379)
|
||||
.withId("d1861060fe6a534d42d8a19aeb36600e18785e04").build();
|
||||
|
||||
static final RedisClusterNode NODE_2 = RedisClusterNode.newRedisClusterNode().listeningAt("127.0.0.1", 6380)
|
||||
private static final RedisClusterNode NODE_2 = RedisClusterNode.newRedisClusterNode().listeningAt("127.0.0.1", 6380)
|
||||
.withId("0f2ee5df45d18c50aca07228cc18b1da96fd5e84").build();
|
||||
|
||||
@Mock RedisConnectionFactory connectionFactory;
|
||||
@Mock RedisClusterConnection connection;
|
||||
|
||||
RedisSerializer<String> serializer;
|
||||
private RedisSerializer<String> serializer;
|
||||
|
||||
DefaultClusterOperations<String, String> clusterOps;
|
||||
private DefaultClusterOperations<String, String> clusterOps;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
|
||||
when(connectionFactory.getConnection()).thenReturn(connection);
|
||||
when(connectionFactory.getClusterConnection()).thenReturn(connection);
|
||||
@@ -77,7 +80,7 @@ public class DefaultClusterOperationsUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-315
|
||||
public void keysShouldDelegateToConnectionCorrectly() {
|
||||
void keysShouldDelegateToConnectionCorrectly() {
|
||||
|
||||
Set<byte[]> keys = new HashSet<>(Arrays.asList(serializer.serialize("key-1"), serializer.serialize("key-2")));
|
||||
when(connection.keys(any(RedisClusterNode.class), any(byte[].class))).thenReturn(keys);
|
||||
@@ -86,12 +89,12 @@ public class DefaultClusterOperationsUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-315
|
||||
public void keysShouldThrowExceptionWhenNodeIsNull() {
|
||||
void keysShouldThrowExceptionWhenNodeIsNull() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> clusterOps.keys(null, "*"));
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-315
|
||||
public void keysShouldReturnEmptySetWhenNoKeysAvailable() {
|
||||
void keysShouldReturnEmptySetWhenNoKeysAvailable() {
|
||||
|
||||
when(connection.keys(any(RedisClusterNode.class), any(byte[].class))).thenReturn(null);
|
||||
|
||||
@@ -99,7 +102,7 @@ public class DefaultClusterOperationsUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-315
|
||||
public void randomKeyShouldDelegateToConnection() {
|
||||
void randomKeyShouldDelegateToConnection() {
|
||||
|
||||
when(connection.randomKey(any(RedisClusterNode.class))).thenReturn(serializer.serialize("key-1"));
|
||||
|
||||
@@ -107,12 +110,12 @@ public class DefaultClusterOperationsUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-315
|
||||
public void randomKeyShouldThrowExceptionWhenNodeIsNull() {
|
||||
void randomKeyShouldThrowExceptionWhenNodeIsNull() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> clusterOps.randomKey(null));
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-315
|
||||
public void randomKeyShouldReturnNullWhenNoKeyAvailable() {
|
||||
void randomKeyShouldReturnNullWhenNoKeyAvailable() {
|
||||
|
||||
when(connection.randomKey(any(RedisClusterNode.class))).thenReturn(null);
|
||||
|
||||
@@ -120,7 +123,7 @@ public class DefaultClusterOperationsUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-315
|
||||
public void pingShouldDelegateToConnection() {
|
||||
void pingShouldDelegateToConnection() {
|
||||
|
||||
when(connection.ping(any(RedisClusterNode.class))).thenReturn("PONG");
|
||||
|
||||
@@ -128,12 +131,12 @@ public class DefaultClusterOperationsUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-315
|
||||
public void pingShouldThrowExceptionWhenNodeIsNull() {
|
||||
void pingShouldThrowExceptionWhenNodeIsNull() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> clusterOps.ping(null));
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-315
|
||||
public void addSlotsShouldDelegateToConnection() {
|
||||
void addSlotsShouldDelegateToConnection() {
|
||||
|
||||
clusterOps.addSlots(NODE_1, 1, 2, 3);
|
||||
|
||||
@@ -141,12 +144,12 @@ public class DefaultClusterOperationsUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-315
|
||||
public void addSlotsShouldThrowExceptionWhenNodeIsNull() {
|
||||
void addSlotsShouldThrowExceptionWhenNodeIsNull() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> clusterOps.addSlots(null));
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-315
|
||||
public void addSlotsWithRangeShouldDelegateToConnection() {
|
||||
void addSlotsWithRangeShouldDelegateToConnection() {
|
||||
|
||||
clusterOps.addSlots(NODE_1, new SlotRange(1, 3));
|
||||
|
||||
@@ -154,12 +157,12 @@ public class DefaultClusterOperationsUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-315
|
||||
public void addSlotsWithRangeShouldThrowExceptionWhenRangeIsNull() {
|
||||
void addSlotsWithRangeShouldThrowExceptionWhenRangeIsNull() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> clusterOps.addSlots(NODE_1, (SlotRange) null));
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-315
|
||||
public void bgSaveShouldDelegateToConnection() {
|
||||
void bgSaveShouldDelegateToConnection() {
|
||||
|
||||
clusterOps.bgSave(NODE_1);
|
||||
|
||||
@@ -167,12 +170,12 @@ public class DefaultClusterOperationsUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-315
|
||||
public void bgSaveShouldThrowExceptionWhenNodeIsNull() {
|
||||
void bgSaveShouldThrowExceptionWhenNodeIsNull() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> clusterOps.bgSave(null));
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-315
|
||||
public void meetShouldDelegateToConnection() {
|
||||
void meetShouldDelegateToConnection() {
|
||||
|
||||
clusterOps.meet(NODE_1);
|
||||
|
||||
@@ -180,12 +183,12 @@ public class DefaultClusterOperationsUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-315
|
||||
public void meetShouldThrowExceptionWhenNodeIsNull() {
|
||||
void meetShouldThrowExceptionWhenNodeIsNull() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> clusterOps.meet(null));
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-315
|
||||
public void forgetShouldDelegateToConnection() {
|
||||
void forgetShouldDelegateToConnection() {
|
||||
|
||||
clusterOps.forget(NODE_1);
|
||||
|
||||
@@ -193,12 +196,12 @@ public class DefaultClusterOperationsUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-315
|
||||
public void forgetShouldThrowExceptionWhenNodeIsNull() {
|
||||
void forgetShouldThrowExceptionWhenNodeIsNull() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> clusterOps.forget(null));
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-315
|
||||
public void flushDbShouldDelegateToConnection() {
|
||||
void flushDbShouldDelegateToConnection() {
|
||||
|
||||
clusterOps.flushDb(NODE_1);
|
||||
|
||||
@@ -206,12 +209,12 @@ public class DefaultClusterOperationsUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-315
|
||||
public void flushDbShouldThrowExceptionWhenNodeIsNull() {
|
||||
void flushDbShouldThrowExceptionWhenNodeIsNull() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> clusterOps.flushDb(null));
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-315
|
||||
public void getSlavesShouldDelegateToConnection() {
|
||||
void getSlavesShouldDelegateToConnection() {
|
||||
|
||||
clusterOps.getSlaves(NODE_1);
|
||||
|
||||
@@ -219,12 +222,12 @@ public class DefaultClusterOperationsUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-315
|
||||
public void getSlavesShouldThrowExceptionWhenNodeIsNull() {
|
||||
void getSlavesShouldThrowExceptionWhenNodeIsNull() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> clusterOps.getSlaves(null));
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-315
|
||||
public void saveShouldDelegateToConnection() {
|
||||
void saveShouldDelegateToConnection() {
|
||||
|
||||
clusterOps.save(NODE_1);
|
||||
|
||||
@@ -232,12 +235,12 @@ public class DefaultClusterOperationsUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-315
|
||||
public void saveShouldThrowExceptionWhenNodeIsNull() {
|
||||
void saveShouldThrowExceptionWhenNodeIsNull() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> clusterOps.save(null));
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-315
|
||||
public void shutdownShouldDelegateToConnection() {
|
||||
void shutdownShouldDelegateToConnection() {
|
||||
|
||||
clusterOps.shutdown(NODE_1);
|
||||
|
||||
@@ -245,12 +248,12 @@ public class DefaultClusterOperationsUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-315
|
||||
public void shutdownShouldThrowExceptionWhenNodeIsNull() {
|
||||
void shutdownShouldThrowExceptionWhenNodeIsNull() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> clusterOps.shutdown(null));
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-315
|
||||
public void executeShouldDelegateToConnection() {
|
||||
void executeShouldDelegateToConnection() {
|
||||
|
||||
final byte[] key = serializer.serialize("foo");
|
||||
clusterOps.execute(connection -> serializer.deserialize(connection.get(key)));
|
||||
@@ -259,12 +262,12 @@ public class DefaultClusterOperationsUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-315
|
||||
public void executeShouldThrowExceptionWhenCallbackIsNull() {
|
||||
void executeShouldThrowExceptionWhenCallbackIsNull() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> clusterOps.execute(null));
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-315
|
||||
public void reshardShouldExecuteCommandsCorrectly() {
|
||||
void reshardShouldExecuteCommandsCorrectly() {
|
||||
|
||||
byte[] key = "foo".getBytes();
|
||||
when(connection.clusterGetKeysInSlot(eq(100), anyInt())).thenReturn(Collections.singletonList(key));
|
||||
|
||||
@@ -78,8 +78,6 @@ public class DefaultGeoOperationsTests<K, M> {
|
||||
this.redisTemplate = redisTemplate;
|
||||
this.keyFactory = keyFactory;
|
||||
this.valueFactory = valueFactory;
|
||||
|
||||
ConnectionFactoryTracker.add(redisTemplate.getConnectionFactory());
|
||||
}
|
||||
|
||||
@Parameters
|
||||
@@ -87,11 +85,6 @@ public class DefaultGeoOperationsTests<K, M> {
|
||||
return AbstractOperationsTestParams.testParams();
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void cleanUp() {
|
||||
ConnectionFactoryTracker.cleanUp();
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
geoOperations = redisTemplate.opsForGeo();
|
||||
|
||||
@@ -38,6 +38,8 @@ import org.springframework.data.redis.RawObjectFactory;
|
||||
import org.springframework.data.redis.SettingsUtils;
|
||||
import org.springframework.data.redis.StringObjectFactory;
|
||||
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
|
||||
import org.springframework.data.redis.connection.jedis.extension.JedisConnectionFactoryExtension;
|
||||
import org.springframework.data.redis.test.extension.RedisStanalone;
|
||||
import org.springframework.data.redis.test.util.MinimumRedisVersionRule;
|
||||
import org.springframework.test.annotation.IfProfileValue;
|
||||
|
||||
@@ -72,8 +74,6 @@ public class DefaultHashOperationsTests<K, HK, HV> {
|
||||
this.keyFactory = keyFactory;
|
||||
this.hashKeyFactory = hashKeyFactory;
|
||||
this.hashValueFactory = hashValueFactory;
|
||||
|
||||
ConnectionFactoryTracker.add(redisTemplate.getConnectionFactory());
|
||||
}
|
||||
|
||||
@Parameters
|
||||
@@ -81,10 +81,8 @@ public class DefaultHashOperationsTests<K, HK, HV> {
|
||||
ObjectFactory<String> stringFactory = new StringObjectFactory();
|
||||
ObjectFactory<byte[]> rawFactory = new RawObjectFactory();
|
||||
|
||||
JedisConnectionFactory jedisConnectionFactory = new JedisConnectionFactory();
|
||||
jedisConnectionFactory.setPort(SettingsUtils.getPort());
|
||||
jedisConnectionFactory.setHostName(SettingsUtils.getHost());
|
||||
jedisConnectionFactory.afterPropertiesSet();
|
||||
JedisConnectionFactory jedisConnectionFactory = JedisConnectionFactoryExtension
|
||||
.getConnectionFactory(RedisStanalone.class);
|
||||
|
||||
RedisTemplate<String, String> stringTemplate = new StringRedisTemplate();
|
||||
stringTemplate.setConnectionFactory(jedisConnectionFactory);
|
||||
@@ -99,11 +97,6 @@ public class DefaultHashOperationsTests<K, HK, HV> {
|
||||
{ rawTemplate, rawFactory, rawFactory, rawFactory } });
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void cleanUp() {
|
||||
ConnectionFactoryTracker.cleanUp();
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
hashOps = redisTemplate.opsForHash();
|
||||
|
||||
@@ -57,8 +57,6 @@ public class DefaultHyperLogLogOperationsTests<K, V> {
|
||||
this.redisTemplate = redisTemplate;
|
||||
this.keyFactory = keyFactory;
|
||||
this.valueFactory = valueFactory;
|
||||
|
||||
ConnectionFactoryTracker.add(redisTemplate.getConnectionFactory());
|
||||
}
|
||||
|
||||
@Parameters
|
||||
|
||||
@@ -68,8 +68,6 @@ public class DefaultListOperationsTests<K, V> {
|
||||
this.redisTemplate = redisTemplate;
|
||||
this.keyFactory = keyFactory;
|
||||
this.valueFactory = valueFactory;
|
||||
|
||||
ConnectionFactoryTracker.add(redisTemplate.getConnectionFactory());
|
||||
}
|
||||
|
||||
@Parameters
|
||||
|
||||
@@ -78,11 +78,6 @@ public class DefaultReactiveGeoOperationsIntegrationTests<K, V> {
|
||||
return ReactiveOperationsTestParams.testParams();
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void cleanUp() {
|
||||
ConnectionFactoryTracker.cleanUp();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param redisTemplate
|
||||
* @param keyFactory
|
||||
@@ -96,8 +91,6 @@ public class DefaultReactiveGeoOperationsIntegrationTests<K, V> {
|
||||
this.geoOperations = redisTemplate.opsForGeo();
|
||||
this.keyFactory = keyFactory;
|
||||
this.valueFactory = valueFactory;
|
||||
|
||||
ConnectionFactoryTracker.add(redisTemplate.getConnectionFactory());
|
||||
}
|
||||
|
||||
@Before
|
||||
|
||||
@@ -41,7 +41,7 @@ import org.springframework.data.redis.StringObjectFactory;
|
||||
import org.springframework.data.redis.connection.RedisConnection;
|
||||
import org.springframework.data.redis.connection.RedisConnectionFactory;
|
||||
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
|
||||
import org.springframework.data.redis.connection.lettuce.LettuceTestClientResources;
|
||||
import org.springframework.data.redis.test.extension.LettuceTestClientResources;
|
||||
import org.springframework.data.redis.serializer.RedisSerializationContext;
|
||||
import org.springframework.data.redis.serializer.StringRedisSerializer;
|
||||
|
||||
|
||||
@@ -55,11 +55,6 @@ public class DefaultReactiveHyperLogLogOperationsIntegrationTests<K, V> {
|
||||
return ReactiveOperationsTestParams.testParams();
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void cleanUp() {
|
||||
ConnectionFactoryTracker.cleanUp();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param redisTemplate
|
||||
* @param keyFactory
|
||||
@@ -73,8 +68,6 @@ public class DefaultReactiveHyperLogLogOperationsIntegrationTests<K, V> {
|
||||
this.hyperLogLogOperations = redisTemplate.opsForHyperLogLog();
|
||||
this.keyFactory = keyFactory;
|
||||
this.valueFactory = valueFactory;
|
||||
|
||||
ConnectionFactoryTracker.add(redisTemplate.getConnectionFactory());
|
||||
}
|
||||
|
||||
@Before
|
||||
|
||||
@@ -61,11 +61,6 @@ public class DefaultReactiveListOperationsIntegrationTests<K, V> {
|
||||
return ReactiveOperationsTestParams.testParams();
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void cleanUp() {
|
||||
ConnectionFactoryTracker.cleanUp();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param redisTemplate
|
||||
* @param keyFactory
|
||||
@@ -79,8 +74,6 @@ public class DefaultReactiveListOperationsIntegrationTests<K, V> {
|
||||
this.listOperations = redisTemplate.opsForList();
|
||||
this.keyFactory = keyFactory;
|
||||
this.valueFactory = valueFactory;
|
||||
|
||||
ConnectionFactoryTracker.add(redisTemplate.getConnectionFactory());
|
||||
}
|
||||
|
||||
@Before
|
||||
|
||||
@@ -57,11 +57,6 @@ public class DefaultReactiveSetOperationsIntegrationTests<K, V> {
|
||||
return ReactiveOperationsTestParams.testParams();
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void cleanUp() {
|
||||
ConnectionFactoryTracker.cleanUp();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param redisTemplate
|
||||
* @param keyFactory
|
||||
@@ -75,8 +70,6 @@ public class DefaultReactiveSetOperationsIntegrationTests<K, V> {
|
||||
this.setOperations = redisTemplate.opsForSet();
|
||||
this.keyFactory = keyFactory;
|
||||
this.valueFactory = valueFactory;
|
||||
|
||||
ConnectionFactoryTracker.add(redisTemplate.getConnectionFactory());
|
||||
}
|
||||
|
||||
@Before
|
||||
|
||||
@@ -69,11 +69,6 @@ public class DefaultReactiveValueOperationsIntegrationTests<K, V> {
|
||||
return ReactiveOperationsTestParams.testParams();
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void cleanUp() {
|
||||
ConnectionFactoryTracker.cleanUp();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param redisTemplate
|
||||
* @param keyFactory
|
||||
@@ -88,8 +83,6 @@ public class DefaultReactiveValueOperationsIntegrationTests<K, V> {
|
||||
this.keyFactory = keyFactory;
|
||||
this.valueFactory = valueFactory;
|
||||
this.serializer = serializer;
|
||||
|
||||
ConnectionFactoryTracker.add(redisTemplate.getConnectionFactory());
|
||||
}
|
||||
|
||||
@Before
|
||||
|
||||
@@ -73,11 +73,6 @@ public class DefaultReactiveZSetOperationsIntegrationTests<K, V> {
|
||||
return ReactiveOperationsTestParams.testParams();
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void cleanUp() {
|
||||
ConnectionFactoryTracker.cleanUp();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param redisTemplate
|
||||
* @param keyFactory
|
||||
@@ -92,8 +87,6 @@ public class DefaultReactiveZSetOperationsIntegrationTests<K, V> {
|
||||
this.keyFactory = keyFactory;
|
||||
this.valueFactory = valueFactory;
|
||||
this.serializer = serializer;
|
||||
|
||||
ConnectionFactoryTracker.add(redisTemplate.getConnectionFactory());
|
||||
}
|
||||
|
||||
@Before
|
||||
|
||||
@@ -67,8 +67,6 @@ public class DefaultSetOperationsTests<K, V> {
|
||||
this.redisTemplate = redisTemplate;
|
||||
this.keyFactory = keyFactory;
|
||||
this.valueFactory = valueFactory;
|
||||
|
||||
ConnectionFactoryTracker.add(redisTemplate.getConnectionFactory());
|
||||
}
|
||||
|
||||
@Parameters
|
||||
@@ -76,11 +74,6 @@ public class DefaultSetOperationsTests<K, V> {
|
||||
return AbstractOperationsTestParams.testParams();
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void cleanUp() {
|
||||
ConnectionFactoryTracker.cleanUp();
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
setOps = redisTemplate.opsForSet();
|
||||
|
||||
@@ -80,8 +80,6 @@ public class DefaultStreamOperationsTests<K, HK, HV> {
|
||||
this.keyFactory = keyFactory;
|
||||
this.hashKeyFactory = (ObjectFactory<HK>) keyFactory;
|
||||
this.hashValueFactory = (ObjectFactory<HV>) objectFactory;
|
||||
|
||||
ConnectionFactoryTracker.add(redisTemplate.getConnectionFactory());
|
||||
}
|
||||
|
||||
@Parameters
|
||||
@@ -89,11 +87,6 @@ public class DefaultStreamOperationsTests<K, HK, HV> {
|
||||
return AbstractOperationsTestParams.testParams();
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void cleanUp() {
|
||||
ConnectionFactoryTracker.cleanUp();
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
streamOps = redisTemplate.opsForStream();
|
||||
|
||||
@@ -15,16 +15,17 @@
|
||||
*/
|
||||
package org.springframework.data.redis.core;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.data.redis.core.ZSetOperations.TypedTuple;
|
||||
|
||||
/**
|
||||
* @author Christoph Strobl
|
||||
*/
|
||||
public class DefaultTypedTupleUnitTests {
|
||||
class DefaultTypedTupleUnitTests {
|
||||
|
||||
private static final TypedTuple<String> WITH_SCORE_1 = new DefaultTypedTuple<>("foo", 1D);
|
||||
private static final TypedTuple<String> ANOTHER_ONE_WITH_SCORE_1 = new DefaultTypedTuple<>("another", 1D);
|
||||
@@ -32,24 +33,24 @@ public class DefaultTypedTupleUnitTests {
|
||||
private static final TypedTuple<String> WITH_SCORE_NULL = new DefaultTypedTuple<>("foo", null);
|
||||
|
||||
@Test // DATAREDIS-294
|
||||
public void compareToShouldUseScore() {
|
||||
void compareToShouldUseScore() {
|
||||
|
||||
assertThat(WITH_SCORE_1.compareTo(WITH_SCORE_2)).isEqualTo(-1);
|
||||
assertThat(WITH_SCORE_2.compareTo(WITH_SCORE_1)).isEqualTo(1);
|
||||
assertThat(WITH_SCORE_1.compareTo(ANOTHER_ONE_WITH_SCORE_1)).isEqualTo(0);
|
||||
assertThat(WITH_SCORE_1).isLessThan(WITH_SCORE_2);
|
||||
assertThat(WITH_SCORE_2).isGreaterThan(WITH_SCORE_1);
|
||||
assertThat(WITH_SCORE_1).isEqualByComparingTo(ANOTHER_ONE_WITH_SCORE_1);
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-294
|
||||
public void compareToShouldConsiderGivenNullAsZeroScore() {
|
||||
void compareToShouldConsiderGivenNullAsZeroScore() {
|
||||
|
||||
assertThat(WITH_SCORE_1.compareTo(null)).isEqualTo(1);
|
||||
assertThat(WITH_SCORE_NULL.compareTo(null)).isEqualTo(0);
|
||||
assertThat(WITH_SCORE_1).isGreaterThan(null);
|
||||
assertThat(WITH_SCORE_NULL).isEqualByComparingTo(null);
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-294
|
||||
public void compareToShouldConsiderNullScoreAsZeroScore() {
|
||||
void compareToShouldConsiderNullScoreAsZeroScore() {
|
||||
|
||||
assertThat(WITH_SCORE_1.compareTo(WITH_SCORE_NULL)).isEqualTo(1);
|
||||
assertThat(WITH_SCORE_NULL.compareTo(WITH_SCORE_1)).isEqualTo(-1);
|
||||
assertThat(WITH_SCORE_1).isGreaterThan(WITH_SCORE_NULL);
|
||||
assertThat(WITH_SCORE_NULL).isLessThan(WITH_SCORE_1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,8 +68,6 @@ public class DefaultValueOperationsTests<K, V> {
|
||||
this.redisTemplate = redisTemplate;
|
||||
this.keyFactory = keyFactory;
|
||||
this.valueFactory = valueFactory;
|
||||
|
||||
ConnectionFactoryTracker.add(redisTemplate.getConnectionFactory());
|
||||
}
|
||||
|
||||
@Parameters
|
||||
@@ -77,11 +75,6 @@ public class DefaultValueOperationsTests<K, V> {
|
||||
return AbstractOperationsTestParams.testParams();
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void cleanUp() {
|
||||
ConnectionFactoryTracker.cleanUp();
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
valueOps = redisTemplate.opsForValue();
|
||||
|
||||
@@ -13,16 +13,17 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.data.redis.core;
|
||||
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import org.mockito.junit.jupiter.MockitoSettings;
|
||||
import org.mockito.quality.Strictness;
|
||||
|
||||
import org.springframework.data.redis.connection.BitFieldSubCommands;
|
||||
import org.springframework.data.redis.connection.BitFieldSubCommands.BitFieldType;
|
||||
@@ -34,17 +35,18 @@ import org.springframework.data.redis.serializer.StringRedisSerializer;
|
||||
/**
|
||||
* @author Christoph Strobl
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class DefaultValueOperationsUnitTests<K, V> {
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
@MockitoSettings(strictness = Strictness.LENIENT)
|
||||
class DefaultValueOperationsUnitTests<K, V> {
|
||||
|
||||
@Mock RedisConnectionFactory connectionFactoryMock;
|
||||
@Mock RedisConnection connectionMock;
|
||||
RedisSerializer<String> serializer;
|
||||
RedisTemplate<String, V> template;
|
||||
ValueOperations<String, V> valueOps;
|
||||
private RedisSerializer<String> serializer;
|
||||
private RedisTemplate<String, V> template;
|
||||
private ValueOperations<String, V> valueOps;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
|
||||
when(connectionFactoryMock.getConnection()).thenReturn(connectionMock);
|
||||
|
||||
@@ -59,7 +61,7 @@ public class DefaultValueOperationsUnitTests<K, V> {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-562
|
||||
public void bitfieldShouldBeDelegatedCorrectly() {
|
||||
void bitfieldShouldBeDelegatedCorrectly() {
|
||||
|
||||
BitFieldSubCommands command = BitFieldSubCommands.create().get(BitFieldType.INT_8).valueAt(0L);
|
||||
|
||||
|
||||
@@ -77,8 +77,6 @@ public class DefaultZSetOperationsTests<K, V> {
|
||||
this.redisTemplate = redisTemplate;
|
||||
this.keyFactory = keyFactory;
|
||||
this.valueFactory = valueFactory;
|
||||
|
||||
ConnectionFactoryTracker.add(redisTemplate.getConnectionFactory());
|
||||
}
|
||||
|
||||
@Parameters
|
||||
@@ -86,11 +84,6 @@ public class DefaultZSetOperationsTests<K, V> {
|
||||
return AbstractOperationsTestParams.testParams();
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void cleanUp() {
|
||||
ConnectionFactoryTracker.cleanUp();
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
zSetOps = redisTemplate.opsForZSet();
|
||||
|
||||
@@ -23,12 +23,14 @@ import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashSet;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import org.mockito.junit.jupiter.MockitoSettings;
|
||||
import org.mockito.quality.Strictness;
|
||||
|
||||
import org.springframework.core.convert.converter.Converter;
|
||||
import org.springframework.core.convert.support.GenericConversionService;
|
||||
@@ -47,21 +49,22 @@ import org.springframework.util.ObjectUtils;
|
||||
* @author Christoph Strobl
|
||||
* @author Rob Winch
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.Silent.class)
|
||||
public class IndexWriterUnitTests {
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
@MockitoSettings(strictness = Strictness.LENIENT)
|
||||
class IndexWriterUnitTests {
|
||||
|
||||
private static final Charset CHARSET = Charset.forName("UTF-8");
|
||||
private static final String KEYSPACE = "persons";
|
||||
private static final String KEY = "key-1";
|
||||
private static final byte[] KEY_BIN = KEY.getBytes(CHARSET);
|
||||
IndexWriter writer;
|
||||
MappingRedisConverter converter;
|
||||
private IndexWriter writer;
|
||||
private MappingRedisConverter converter;
|
||||
|
||||
@Mock RedisConnection connectionMock;
|
||||
@Mock ReferenceResolver referenceResolverMock;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
|
||||
converter = new MappingRedisConverter(new RedisMappingContext(), new PathIndexResolver(), referenceResolverMock);
|
||||
converter.afterPropertiesSet();
|
||||
@@ -70,7 +73,7 @@ public class IndexWriterUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-425
|
||||
public void addKeyToIndexShouldInvokeSaddCorrectly() {
|
||||
void addKeyToIndexShouldInvokeSaddCorrectly() {
|
||||
|
||||
writer.addKeyToIndex(KEY_BIN, new SimpleIndexedPropertyValue(KEYSPACE, "firstname", "Rand"));
|
||||
|
||||
@@ -80,12 +83,12 @@ public class IndexWriterUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-425
|
||||
public void addKeyToIndexShouldThrowErrorWhenIndexedDataIsNull() {
|
||||
void addKeyToIndexShouldThrowErrorWhenIndexedDataIsNull() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> writer.addKeyToIndex(KEY_BIN, null));
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-425
|
||||
public void removeKeyFromExistingIndexesShouldCheckForExistingIndexesForPath() {
|
||||
void removeKeyFromExistingIndexesShouldCheckForExistingIndexesForPath() {
|
||||
|
||||
writer.removeKeyFromExistingIndexes(KEY_BIN, new StubIndxedData());
|
||||
|
||||
@@ -94,7 +97,7 @@ public class IndexWriterUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-425
|
||||
public void removeKeyFromExistingIndexesShouldRemoveKeyFromAllExistingIndexesForPath() {
|
||||
void removeKeyFromExistingIndexesShouldRemoveKeyFromAllExistingIndexesForPath() {
|
||||
|
||||
byte[] indexKey1 = "persons:firstname:rand".getBytes(CHARSET);
|
||||
byte[] indexKey2 = "persons:firstname:mat".getBytes(CHARSET);
|
||||
@@ -109,12 +112,12 @@ public class IndexWriterUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-425
|
||||
public void removeKeyFromExistingIndexesShouldThrowExecptionForNullIndexedData() {
|
||||
void removeKeyFromExistingIndexesShouldThrowExecptionForNullIndexedData() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> writer.removeKeyFromExistingIndexes(KEY_BIN, null));
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-425
|
||||
public void removeAllIndexesShouldDeleteAllIndexKeys() {
|
||||
void removeAllIndexesShouldDeleteAllIndexKeys() {
|
||||
|
||||
byte[] indexKey1 = "persons:firstname:rand".getBytes(CHARSET);
|
||||
byte[] indexKey2 = "persons:firstname:mat".getBytes(CHARSET);
|
||||
@@ -131,13 +134,13 @@ public class IndexWriterUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-425
|
||||
public void addToIndexShouldThrowDataAccessExceptionWhenAddingDataThatConnotBeConverted() {
|
||||
void addToIndexShouldThrowDataAccessExceptionWhenAddingDataThatConnotBeConverted() {
|
||||
assertThatExceptionOfType(InvalidDataAccessApiUsageException.class).isThrownBy(
|
||||
() -> writer.addKeyToIndex(KEY_BIN, new SimpleIndexedPropertyValue(KEYSPACE, "firstname", new DummyObject())));
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-425
|
||||
public void addToIndexShouldUseRegisteredConverterWhenAddingData() {
|
||||
void addToIndexShouldUseRegisteredConverterWhenAddingData() {
|
||||
|
||||
DummyObject value = new DummyObject();
|
||||
final String identityHexString = ObjectUtils.getIdentityHexString(value);
|
||||
@@ -156,7 +159,7 @@ public class IndexWriterUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-512
|
||||
public void createIndexShouldNotTryToRemoveExistingValues() {
|
||||
void createIndexShouldNotTryToRemoveExistingValues() {
|
||||
|
||||
when(connectionMock.keys(any(byte[].class)))
|
||||
.thenReturn(new LinkedHashSet<>(Arrays.asList("persons:firstname:rand".getBytes(CHARSET))));
|
||||
@@ -171,7 +174,7 @@ public class IndexWriterUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-512
|
||||
public void updateIndexShouldRemoveExistingValues() {
|
||||
void updateIndexShouldRemoveExistingValues() {
|
||||
|
||||
when(connectionMock.keys(any(byte[].class)))
|
||||
.thenReturn(new LinkedHashSet<>(Arrays.asList("persons:firstname:rand".getBytes(CHARSET))));
|
||||
@@ -186,7 +189,7 @@ public class IndexWriterUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-533
|
||||
public void removeGeoIndexShouldCallGeoRemove() {
|
||||
void removeGeoIndexShouldCallGeoRemove() {
|
||||
|
||||
byte[] indexKey1 = "persons:location".getBytes(CHARSET);
|
||||
|
||||
@@ -210,7 +213,7 @@ public class IndexWriterUnitTests {
|
||||
}
|
||||
}
|
||||
|
||||
static class DummyObject {
|
||||
private static class DummyObject {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,8 +32,11 @@ import org.junit.runners.Parameterized.Parameters;
|
||||
import org.springframework.data.redis.ConnectionFactoryTracker;
|
||||
import org.springframework.data.redis.connection.RedisConnectionFactory;
|
||||
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
|
||||
import org.springframework.data.redis.connection.jedis.extension.JedisConnectionFactoryExtension;
|
||||
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
|
||||
import org.springframework.data.redis.connection.lettuce.LettuceTestClientResources;
|
||||
import org.springframework.data.redis.connection.lettuce.extension.LettuceConnectionFactoryExtension;
|
||||
import org.springframework.data.redis.test.extension.LettuceTestClientResources;
|
||||
import org.springframework.data.redis.test.extension.RedisStanalone;
|
||||
|
||||
/**
|
||||
* @author Artem Bilian
|
||||
@@ -47,25 +50,14 @@ public class MultithreadedRedisTemplateTests {
|
||||
|
||||
public MultithreadedRedisTemplateTests(RedisConnectionFactory factory) {
|
||||
this.factory = factory;
|
||||
ConnectionFactoryTracker.add(factory);
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void cleanUp() {
|
||||
ConnectionFactoryTracker.cleanUp();
|
||||
}
|
||||
|
||||
@Parameters
|
||||
public static Collection<Object[]> testParams() {
|
||||
|
||||
JedisConnectionFactory jedis = new JedisConnectionFactory();
|
||||
jedis.setPort(6379);
|
||||
jedis.afterPropertiesSet();
|
||||
JedisConnectionFactory jedis = JedisConnectionFactoryExtension.getConnectionFactory(RedisStanalone.class);
|
||||
|
||||
LettuceConnectionFactory lettuce = new LettuceConnectionFactory();
|
||||
lettuce.setClientResources(LettuceTestClientResources.getSharedClientResources());
|
||||
lettuce.setPort(6379);
|
||||
lettuce.afterPropertiesSet();
|
||||
LettuceConnectionFactory lettuce = LettuceConnectionFactoryExtension.getConnectionFactory(RedisStanalone.class);
|
||||
|
||||
return Arrays.asList(new Object[][] { { jedis }, { lettuce } });
|
||||
}
|
||||
|
||||
@@ -15,16 +15,14 @@
|
||||
*/
|
||||
package org.springframework.data.redis.core;
|
||||
|
||||
import static org.springframework.data.redis.connection.ClusterTestVariables.*;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.time.Duration;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.runners.model.Statement;
|
||||
|
||||
import org.springframework.data.redis.ByteBufferObjectFactory;
|
||||
import org.springframework.data.redis.DoubleObjectFactory;
|
||||
import org.springframework.data.redis.LongObjectFactory;
|
||||
@@ -32,15 +30,9 @@ import org.springframework.data.redis.ObjectFactory;
|
||||
import org.springframework.data.redis.Person;
|
||||
import org.springframework.data.redis.PersonObjectFactory;
|
||||
import org.springframework.data.redis.PrefixStringObjectFactory;
|
||||
import org.springframework.data.redis.SettingsUtils;
|
||||
import org.springframework.data.redis.StringObjectFactory;
|
||||
import org.springframework.data.redis.connection.RedisClusterConfiguration;
|
||||
import org.springframework.data.redis.connection.RedisClusterNode;
|
||||
import org.springframework.data.redis.connection.RedisStandaloneConfiguration;
|
||||
import org.springframework.data.redis.connection.lettuce.LettuceClientConfiguration;
|
||||
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
|
||||
import org.springframework.data.redis.connection.lettuce.LettucePoolingClientConfiguration;
|
||||
import org.springframework.data.redis.connection.lettuce.LettuceTestClientResources;
|
||||
import org.springframework.data.redis.connection.lettuce.extension.LettuceConnectionFactoryExtension;
|
||||
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
|
||||
import org.springframework.data.redis.serializer.GenericToStringSerializer;
|
||||
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
|
||||
@@ -48,6 +40,8 @@ import org.springframework.data.redis.serializer.JdkSerializationRedisSerializer
|
||||
import org.springframework.data.redis.serializer.OxmSerializer;
|
||||
import org.springframework.data.redis.serializer.RedisSerializationContext;
|
||||
import org.springframework.data.redis.serializer.StringRedisSerializer;
|
||||
import org.springframework.data.redis.test.extension.RedisCluster;
|
||||
import org.springframework.data.redis.test.extension.RedisStanalone;
|
||||
import org.springframework.data.redis.test.util.RedisClusterRule;
|
||||
import org.springframework.oxm.xstream.XStreamMarshaller;
|
||||
|
||||
@@ -61,19 +55,6 @@ abstract public class ReactiveOperationsTestParams {
|
||||
|
||||
public static Collection<Object[]> testParams() {
|
||||
|
||||
LettuceClientConfiguration clientConfiguration = LettuceClientConfiguration.builder() //
|
||||
.shutdownTimeout(Duration.ZERO) //
|
||||
.clientResources(LettuceTestClientResources.getSharedClientResources()) //
|
||||
.build();
|
||||
|
||||
LettucePoolingClientConfiguration poolingConfiguration = LettucePoolingClientConfiguration.builder() //
|
||||
.shutdownTimeout(Duration.ZERO) //
|
||||
.clientResources(LettuceTestClientResources.getSharedClientResources()) //
|
||||
.build();
|
||||
|
||||
RedisStandaloneConfiguration standaloneConfiguration = new RedisStandaloneConfiguration(SettingsUtils.getHost(),
|
||||
SettingsUtils.getPort());
|
||||
|
||||
ObjectFactory<String> stringFactory = new StringObjectFactory();
|
||||
ObjectFactory<String> clusterKeyStringFactory = new PrefixStringObjectFactory("{u1}.", stringFactory);
|
||||
ObjectFactory<Long> longFactory = new LongObjectFactory();
|
||||
@@ -89,21 +70,12 @@ abstract public class ReactiveOperationsTestParams {
|
||||
throw new RuntimeException("Cannot init XStream", ex);
|
||||
}
|
||||
|
||||
LettuceConnectionFactory lettuceConnectionFactory = new LettuceConnectionFactory(standaloneConfiguration,
|
||||
clientConfiguration);
|
||||
lettuceConnectionFactory.afterPropertiesSet();
|
||||
|
||||
LettuceConnectionFactory poolingConnectionFactory = new LettuceConnectionFactory(standaloneConfiguration,
|
||||
poolingConfiguration);
|
||||
poolingConnectionFactory.afterPropertiesSet();
|
||||
|
||||
LettuceConnectionFactory lettuceConnectionFactory = LettuceConnectionFactoryExtension
|
||||
.getConnectionFactory(RedisStanalone.class);
|
||||
|
||||
ReactiveRedisTemplate<Object, Object> objectTemplate = new ReactiveRedisTemplate<>(lettuceConnectionFactory,
|
||||
RedisSerializationContext.java(ReactiveOperationsTestParams.class.getClassLoader()));
|
||||
|
||||
ReactiveRedisTemplate<Object, Object> pooledObjectTemplate = new ReactiveRedisTemplate<>(poolingConnectionFactory,
|
||||
RedisSerializationContext.java());
|
||||
|
||||
StringRedisSerializer stringRedisSerializer = StringRedisSerializer.UTF_8;
|
||||
ReactiveRedisTemplate<String, String> stringTemplate = new ReactiveRedisTemplate<>(lettuceConnectionFactory,
|
||||
RedisSerializationContext.fromSerializer(stringRedisSerializer));
|
||||
@@ -143,7 +115,6 @@ abstract public class ReactiveOperationsTestParams {
|
||||
List<Object[]> list = Arrays.asList(new Object[][] { //
|
||||
{ stringTemplate, stringFactory, stringFactory, stringRedisSerializer, "String" }, //
|
||||
{ objectTemplate, personFactory, personFactory, jdkSerializationRedisSerializer, "Person/JDK" }, //
|
||||
{ pooledObjectTemplate, personFactory, personFactory, jdkSerializationRedisSerializer, "Pooled/Person/JDK" }, //
|
||||
{ longTemplate, stringFactory, longFactory, longToStringSerializer, "Long" }, //
|
||||
{ doubleTemplate, stringFactory, doubleFactory, doubleToStringSerializer, "Double" }, //
|
||||
{ rawTemplate, rawFactory, rawFactory, null, "raw" }, //
|
||||
@@ -156,14 +127,10 @@ abstract public class ReactiveOperationsTestParams {
|
||||
|
||||
if (clusterAvailable()) {
|
||||
|
||||
RedisClusterConfiguration clusterConfiguration = new RedisClusterConfiguration();
|
||||
clusterConfiguration.addClusterNode(new RedisClusterNode(CLUSTER_HOST, MASTER_NODE_1_PORT));
|
||||
|
||||
ReactiveRedisTemplate<String, String> clusterStringTemplate = null;
|
||||
|
||||
LettuceConnectionFactory lettuceClusterConnectionFactory = new LettuceConnectionFactory(clusterConfiguration,
|
||||
clientConfiguration);
|
||||
lettuceClusterConnectionFactory.afterPropertiesSet();
|
||||
LettuceConnectionFactory lettuceClusterConnectionFactory = LettuceConnectionFactoryExtension
|
||||
.getConnectionFactory(RedisCluster.class);
|
||||
|
||||
clusterStringTemplate = new ReactiveRedisTemplate<>(lettuceClusterConnectionFactory,
|
||||
RedisSerializationContext.string());
|
||||
|
||||
@@ -93,8 +93,6 @@ public class ReactiveRedisTemplateIntegrationTests<K, V> {
|
||||
this.redisTemplate = redisTemplate;
|
||||
this.keyFactory = keyFactory;
|
||||
this.valueFactory = valueFactory;
|
||||
|
||||
ConnectionFactoryTracker.add(redisTemplate.getConnectionFactory());
|
||||
}
|
||||
|
||||
@Before
|
||||
@@ -218,13 +216,13 @@ public class ReactiveRedisTemplateIntegrationTests<K, V> {
|
||||
redisTemplate.hasKey(key1).as(StepVerifier::create).expectNext(false).verifyComplete();
|
||||
redisTemplate.hasKey(key2).as(StepVerifier::create).expectNext(false).verifyComplete();
|
||||
}
|
||||
|
||||
|
||||
@Test // DATAREDIS-913
|
||||
public void unlinkManyPublisher() {
|
||||
|
||||
K key1 = keyFactory.instance();
|
||||
K key2 = keyFactory.instance();
|
||||
|
||||
|
||||
assumeTrue(key1 instanceof String && valueFactory instanceof StringObjectFactory);
|
||||
|
||||
redisTemplate.opsForValue().set(key1, valueFactory.instance()).as(StepVerifier::create).expectNext(true)
|
||||
@@ -237,13 +235,13 @@ public class ReactiveRedisTemplateIntegrationTests<K, V> {
|
||||
redisTemplate.hasKey(key1).as(StepVerifier::create).expectNext(false).verifyComplete();
|
||||
redisTemplate.hasKey(key2).as(StepVerifier::create).expectNext(false).verifyComplete();
|
||||
}
|
||||
|
||||
|
||||
@Test // DATAREDIS-913
|
||||
public void deleteManyPublisher() {
|
||||
|
||||
K key1 = keyFactory.instance();
|
||||
K key2 = keyFactory.instance();
|
||||
|
||||
|
||||
assumeTrue(key1 instanceof String && valueFactory instanceof StringObjectFactory);
|
||||
|
||||
redisTemplate.opsForValue().set(key1, valueFactory.instance()).as(StepVerifier::create).expectNext(true)
|
||||
|
||||
@@ -24,7 +24,8 @@ import reactor.test.StepVerifier;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.data.redis.connection.ReactivePubSubCommands;
|
||||
import org.springframework.data.redis.connection.ReactiveRedisConnection;
|
||||
import org.springframework.data.redis.connection.ReactiveRedisConnectionFactory;
|
||||
@@ -36,13 +37,13 @@ import org.springframework.data.redis.serializer.RedisSerializationContext;
|
||||
*
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
public class ReactiveRedisTemplateUnitTests {
|
||||
class ReactiveRedisTemplateUnitTests {
|
||||
|
||||
ReactiveRedisConnectionFactory connectionFactoryMock = mock(ReactiveRedisConnectionFactory.class);
|
||||
ReactiveRedisConnection connectionMock = mock(ReactiveRedisConnection.class);
|
||||
private ReactiveRedisConnectionFactory connectionFactoryMock = mock(ReactiveRedisConnectionFactory.class);
|
||||
private ReactiveRedisConnection connectionMock = mock(ReactiveRedisConnection.class);
|
||||
|
||||
@Test // DATAREDIS-999
|
||||
public void closeShouldUseAsyncRelease() {
|
||||
void closeShouldUseAsyncRelease() {
|
||||
|
||||
when(connectionFactoryMock.getReactiveConnection()).thenReturn(connectionMock);
|
||||
when(connectionMock.closeLater()).thenReturn(Mono.empty());
|
||||
@@ -59,7 +60,7 @@ public class ReactiveRedisTemplateUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-1053
|
||||
public void listenToShouldSubscribeToChannel() {
|
||||
void listenToShouldSubscribeToChannel() {
|
||||
|
||||
AtomicBoolean closed = new AtomicBoolean();
|
||||
when(connectionFactoryMock.getReactiveConnection()).thenReturn(connectionMock);
|
||||
|
||||
@@ -17,39 +17,31 @@ package org.springframework.data.redis.core;
|
||||
|
||||
import reactor.test.StepVerifier;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.springframework.data.redis.ConnectionFactoryTracker;
|
||||
import org.springframework.data.redis.SettingsUtils;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
|
||||
import org.springframework.data.redis.connection.ReactiveRedisConnectionFactory;
|
||||
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
|
||||
import org.springframework.data.redis.connection.lettuce.LettuceTestClientConfiguration;
|
||||
import org.springframework.data.redis.connection.lettuce.extension.LettuceConnectionFactoryExtension;
|
||||
|
||||
/**
|
||||
* Integration tests for {@link ReactiveStringRedisTemplate}.
|
||||
*
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
@ExtendWith(LettuceConnectionFactoryExtension.class)
|
||||
public class ReactiveStringRedisTemplateIntegrationTests {
|
||||
|
||||
private static ReactiveRedisConnectionFactory connectionFactory;
|
||||
private ReactiveRedisConnectionFactory connectionFactory;
|
||||
|
||||
private ReactiveStringRedisTemplate template;
|
||||
|
||||
@BeforeClass
|
||||
public static void beforeClass() {
|
||||
|
||||
LettuceConnectionFactory connectionFactory = new LettuceConnectionFactory(SettingsUtils.standaloneConfiguration(),
|
||||
LettuceTestClientConfiguration.create());
|
||||
connectionFactory.afterPropertiesSet();
|
||||
ConnectionFactoryTracker.add(connectionFactory);
|
||||
|
||||
ReactiveStringRedisTemplateIntegrationTests.connectionFactory = connectionFactory;
|
||||
public ReactiveStringRedisTemplateIntegrationTests(ReactiveRedisConnectionFactory connectionFactory) {
|
||||
this.connectionFactory = connectionFactory;
|
||||
}
|
||||
|
||||
@Before
|
||||
public void before() {
|
||||
@BeforeEach
|
||||
void before() {
|
||||
|
||||
template = new ReactiveStringRedisTemplate(connectionFactory);
|
||||
|
||||
@@ -58,7 +50,7 @@ public class ReactiveStringRedisTemplateIntegrationTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-643
|
||||
public void shouldSetAndGetKeys() {
|
||||
void shouldSetAndGetKeys() {
|
||||
|
||||
template.opsForValue().set("key", "value").as(StepVerifier::create).expectNext(true).verifyComplete();
|
||||
template.opsForValue().get("key").as(StepVerifier::create).expectNext("value").verifyComplete();
|
||||
|
||||
@@ -35,13 +35,16 @@ import org.springframework.data.redis.RawObjectFactory;
|
||||
import org.springframework.data.redis.StringObjectFactory;
|
||||
import org.springframework.data.redis.connection.RedisClusterConfiguration;
|
||||
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
|
||||
import org.springframework.data.redis.connection.jedis.extension.JedisConnectionFactoryExtension;
|
||||
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
|
||||
import org.springframework.data.redis.connection.lettuce.LettucePoolingClientConfiguration;
|
||||
import org.springframework.data.redis.connection.lettuce.LettuceTestClientResources;
|
||||
import org.springframework.data.redis.connection.lettuce.extension.LettuceConnectionFactoryExtension;
|
||||
import org.springframework.data.redis.serializer.GenericToStringSerializer;
|
||||
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
|
||||
import org.springframework.data.redis.serializer.OxmSerializer;
|
||||
import org.springframework.data.redis.serializer.StringRedisSerializer;
|
||||
import org.springframework.data.redis.test.extension.LettuceTestClientResources;
|
||||
import org.springframework.data.redis.test.extension.RedisCluster;
|
||||
import org.springframework.data.redis.test.util.RedisClusterRule;
|
||||
import org.springframework.oxm.xstream.XStreamMarshaller;
|
||||
|
||||
@@ -51,8 +54,6 @@ import org.springframework.oxm.xstream.XStreamMarshaller;
|
||||
*/
|
||||
public class RedisClusterTemplateTests<K, V> extends RedisTemplateTests<K, V> {
|
||||
|
||||
static final List<String> CLUSTER_NODES = Arrays.asList("127.0.0.1:7379", "127.0.0.1:7380", "127.0.0.1:7381");
|
||||
|
||||
public RedisClusterTemplateTests(RedisTemplate<K, V> redisTemplate, ObjectFactory<K> keyFactory,
|
||||
ObjectFactory<V> valueFactory) {
|
||||
super(redisTemplate, keyFactory, valueFactory);
|
||||
@@ -166,8 +167,8 @@ public class RedisClusterTemplateTests<K, V> extends RedisTemplateTests<K, V> {
|
||||
Jackson2JsonRedisSerializer<Person> jackson2JsonSerializer = new Jackson2JsonRedisSerializer<>(Person.class);
|
||||
|
||||
// JEDIS
|
||||
JedisConnectionFactory jedisConnectionFactory = new JedisConnectionFactory(
|
||||
new RedisClusterConfiguration(CLUSTER_NODES));
|
||||
JedisConnectionFactory jedisConnectionFactory = JedisConnectionFactoryExtension
|
||||
.getConnectionFactory(RedisCluster.class);
|
||||
|
||||
jedisConnectionFactory.afterPropertiesSet();
|
||||
|
||||
@@ -203,17 +204,8 @@ public class RedisClusterTemplateTests<K, V> extends RedisTemplateTests<K, V> {
|
||||
|
||||
// LETTUCE
|
||||
|
||||
LettuceConnectionFactory lettuceConnectionFactory = new LettuceConnectionFactory(
|
||||
new RedisClusterConfiguration(CLUSTER_NODES));
|
||||
lettuceConnectionFactory.setClientResources(LettuceTestClientResources.getSharedClientResources());
|
||||
|
||||
lettuceConnectionFactory.afterPropertiesSet();
|
||||
|
||||
LettuceConnectionFactory pooledLettuceConnectionFactory = new LettuceConnectionFactory(
|
||||
new RedisClusterConfiguration(CLUSTER_NODES), LettucePoolingClientConfiguration.builder()
|
||||
.clientResources(LettuceTestClientResources.getSharedClientResources()).build());
|
||||
|
||||
pooledLettuceConnectionFactory.afterPropertiesSet();
|
||||
LettuceConnectionFactory lettuceConnectionFactory = LettuceConnectionFactoryExtension
|
||||
.getConnectionFactory(RedisCluster.class);
|
||||
|
||||
RedisTemplate<String, String> lettuceStringTemplate = new RedisTemplate<>();
|
||||
lettuceStringTemplate.setDefaultSerializer(StringRedisSerializer.UTF_8);
|
||||
@@ -245,11 +237,6 @@ public class RedisClusterTemplateTests<K, V> extends RedisTemplateTests<K, V> {
|
||||
lettuceJackson2JsonPersonTemplate.setValueSerializer(jackson2JsonSerializer);
|
||||
lettuceJackson2JsonPersonTemplate.afterPropertiesSet();
|
||||
|
||||
RedisTemplate<String, String> pooledLettuceStringTemplate = new RedisTemplate<>();
|
||||
pooledLettuceStringTemplate.setDefaultSerializer(StringRedisSerializer.UTF_8);
|
||||
pooledLettuceStringTemplate.setConnectionFactory(pooledLettuceConnectionFactory);
|
||||
pooledLettuceStringTemplate.afterPropertiesSet();
|
||||
|
||||
return Arrays.asList(new Object[][] { //
|
||||
|
||||
// JEDIS
|
||||
@@ -267,7 +254,6 @@ public class RedisClusterTemplateTests<K, V> extends RedisTemplateTests<K, V> {
|
||||
{ lettucePersonTemplate, stringFactory, personFactory }, //
|
||||
{ lettuceXstreamStringTemplate, stringFactory, stringFactory }, //
|
||||
{ lettuceJackson2JsonPersonTemplate, stringFactory, personFactory }, //
|
||||
{ pooledLettuceStringTemplate, stringFactory, stringFactory } //
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -17,9 +17,7 @@ package org.springframework.data.redis.core;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link RedisCommand}.
|
||||
@@ -29,42 +27,40 @@ import org.junit.rules.ExpectedException;
|
||||
* @author Mark Paluch
|
||||
* @author Oscar Cai
|
||||
*/
|
||||
public class RedisCommandUnitTests {
|
||||
|
||||
public @Rule ExpectedException expectedException = ExpectedException.none();
|
||||
class RedisCommandUnitTests {
|
||||
|
||||
@Test // DATAREDIS-73
|
||||
public void shouldIdentifyAliasCorrectly() {
|
||||
void shouldIdentifyAliasCorrectly() {
|
||||
assertThat(RedisCommand.CONFIG_SET.isRepresentedBy("setconfig")).isTrue();
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-73
|
||||
public void shouldIdentifyAliasCorrectlyWhenNamePassedInMixedCase() {
|
||||
void shouldIdentifyAliasCorrectlyWhenNamePassedInMixedCase() {
|
||||
assertThat(RedisCommand.CONFIG_SET.isRepresentedBy("SetConfig")).isTrue();
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-73
|
||||
public void shouldNotThrowExceptionWhenUsingNullKeyForRepresentationCheck() {
|
||||
void shouldNotThrowExceptionWhenUsingNullKeyForRepresentationCheck() {
|
||||
assertThat(RedisCommand.CONFIG_SET.isRepresentedBy(null)).isFalse();
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-73
|
||||
public void shouldIdentifyAliasCorrectlyViaLookup() {
|
||||
void shouldIdentifyAliasCorrectlyViaLookup() {
|
||||
assertThat(RedisCommand.failsafeCommandLookup("setconfig")).isEqualTo(RedisCommand.CONFIG_SET);
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-73
|
||||
public void shouldIdentifyAliasCorrectlyWhenNamePassedInMixedCaseViaLookup() {
|
||||
void shouldIdentifyAliasCorrectlyWhenNamePassedInMixedCaseViaLookup() {
|
||||
assertThat(RedisCommand.failsafeCommandLookup("SetConfig")).isEqualTo(RedisCommand.CONFIG_SET);
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-73
|
||||
public void shouldReturnUnknownCommandForUnknownCommandString() {
|
||||
void shouldReturnUnknownCommandForUnknownCommandString() {
|
||||
assertThat(RedisCommand.failsafeCommandLookup("strangecommand")).isEqualTo(RedisCommand.UNKNOWN);
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-73, DATAREDIS-972, DATAREDIS-1013
|
||||
public void shouldNotThrowExceptionOnValidArgumentCount() {
|
||||
void shouldNotThrowExceptionOnValidArgumentCount() {
|
||||
|
||||
RedisCommand.AUTH.validateArgumentCount(1);
|
||||
RedisCommand.ZADD.validateArgumentCount(3);
|
||||
@@ -75,7 +71,7 @@ public class RedisCommandUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-822
|
||||
public void shouldConsiderMinMaxArguments() {
|
||||
void shouldConsiderMinMaxArguments() {
|
||||
|
||||
RedisCommand.BITPOS.validateArgumentCount(2);
|
||||
RedisCommand.BITPOS.validateArgumentCount(3);
|
||||
@@ -83,38 +79,26 @@ public class RedisCommandUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-822
|
||||
public void shouldReportArgumentMismatchIfMaxArgumentsExceeded() {
|
||||
|
||||
expectedException.expect(IllegalArgumentException.class);
|
||||
expectedException.expectMessage("SELECT command requires 1 argument");
|
||||
|
||||
RedisCommand.SELECT.validateArgumentCount(0);
|
||||
void shouldReportArgumentMismatchIfMaxArgumentsExceeded() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> RedisCommand.SELECT.validateArgumentCount(0))
|
||||
.withMessageContaining("SELECT command requires 1 argument");
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-73
|
||||
public void shouldThrowExceptionOnInvalidArgumentCountWhenExpectedExactMatch() {
|
||||
|
||||
expectedException.expect(IllegalArgumentException.class);
|
||||
expectedException.expectMessage("AUTH command requires 1 argument");
|
||||
|
||||
RedisCommand.AUTH.validateArgumentCount(2);
|
||||
void shouldThrowExceptionOnInvalidArgumentCountWhenExpectedExactMatch() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> RedisCommand.AUTH.validateArgumentCount(2))
|
||||
.withMessageContaining("AUTH command requires 1 argument");
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-73
|
||||
public void shouldThrowExceptionOnInvalidArgumentCountForDelWhenExpectedMinimalMatch() {
|
||||
|
||||
expectedException.expect(IllegalArgumentException.class);
|
||||
expectedException.expectMessage("DEL command requires at least 1 argument");
|
||||
|
||||
RedisCommand.DEL.validateArgumentCount(0);
|
||||
void shouldThrowExceptionOnInvalidArgumentCountForDelWhenExpectedMinimalMatch() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> RedisCommand.DEL.validateArgumentCount(0))
|
||||
.withMessageContaining("DEL command requires at least 1 argument");
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-972
|
||||
public void shouldThrowExceptionOnInvalidArgumentCountForZaddWhenExpectedMinimalMatch() {
|
||||
|
||||
expectedException.expect(IllegalArgumentException.class);
|
||||
expectedException.expectMessage("ZADD command requires at least 3 arguments");
|
||||
|
||||
RedisCommand.ZADD.validateArgumentCount(2);
|
||||
void shouldThrowExceptionOnInvalidArgumentCountForZaddWhenExpectedMinimalMatch() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> RedisCommand.ZADD.validateArgumentCount(2))
|
||||
.withMessageContaining("ZADD command requires at least 3 arguments");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ package org.springframework.data.redis.core;
|
||||
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.data.redis.connection.RedisConnection;
|
||||
import org.springframework.data.redis.connection.RedisConnectionFactory;
|
||||
@@ -27,10 +27,10 @@ import org.springframework.data.redis.connection.RedisConnectionFactory;
|
||||
*
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
public class RedisConnectionUtilsUnitTests {
|
||||
class RedisConnectionUtilsUnitTests {
|
||||
|
||||
@Test // DATAREDIS-1104
|
||||
public void shouldSilentlyCloseRedisConnection() {
|
||||
void shouldSilentlyCloseRedisConnection() {
|
||||
|
||||
RedisConnection connectionMock = mock(RedisConnection.class);
|
||||
RedisConnectionFactory factoryMock = mock(RedisConnectionFactory.class);
|
||||
|
||||
@@ -15,30 +15,31 @@
|
||||
*/
|
||||
package org.springframework.data.redis.core;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link RedisKeyExpiredEvent}.
|
||||
*
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
public class RedisKeyExpiredEventUnitTests {
|
||||
class RedisKeyExpiredEventUnitTests {
|
||||
|
||||
@Test // DATAREDIS-744
|
||||
public void shouldReturnKeyspace() {
|
||||
void shouldReturnKeyspace() {
|
||||
|
||||
assertThat(new RedisKeyExpiredEvent<Object>("foo".getBytes(), "").getKeyspace()).isNull();
|
||||
assertThat(new RedisKeyExpiredEvent<Object>("foo:bar".getBytes(), "").getKeyspace()).isEqualTo("foo");
|
||||
assertThat(new RedisKeyExpiredEvent<Object>("foo:bar:baz".getBytes(), "").getKeyspace()).isEqualTo("foo");
|
||||
assertThat(new RedisKeyExpiredEvent<>("foo".getBytes(), "").getKeyspace()).isNull();
|
||||
assertThat(new RedisKeyExpiredEvent<>("foo:bar".getBytes(), "").getKeyspace()).isEqualTo("foo");
|
||||
assertThat(new RedisKeyExpiredEvent<>("foo:bar:baz".getBytes(), "").getKeyspace()).isEqualTo("foo");
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-744
|
||||
public void shouldReturnId() {
|
||||
void shouldReturnId() {
|
||||
|
||||
assertThat(new RedisKeyExpiredEvent<Object>("foo".getBytes(), "").getId()).isEqualTo("foo".getBytes());
|
||||
assertThat(new RedisKeyExpiredEvent<Object>("foo:bar".getBytes(), "").getId()).isEqualTo("bar".getBytes());
|
||||
assertThat(new RedisKeyExpiredEvent<Object>("foo:bar:baz".getBytes(), "").getId()).isEqualTo("bar:baz".getBytes());
|
||||
assertThat(new RedisKeyExpiredEvent<>("foo".getBytes(), "").getId()).isEqualTo("foo".getBytes());
|
||||
assertThat(new RedisKeyExpiredEvent<>("foo:bar".getBytes(), "").getId()).isEqualTo("bar".getBytes());
|
||||
assertThat(new RedisKeyExpiredEvent<>("foo:bar:baz".getBytes(), "").getId()).isEqualTo("bar:baz".getBytes());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,22 +22,17 @@ import static org.junit.Assume.*;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
import org.junit.runners.Parameterized.Parameters;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.annotation.Reference;
|
||||
import org.springframework.data.geo.Point;
|
||||
@@ -46,8 +41,7 @@ import org.springframework.data.redis.ConnectionFactoryTracker;
|
||||
import org.springframework.data.redis.RedisTestProfileValueSource;
|
||||
import org.springframework.data.redis.connection.RedisConnection;
|
||||
import org.springframework.data.redis.connection.RedisConnectionFactory;
|
||||
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
|
||||
import org.springframework.data.redis.connection.lettuce.LettuceTestClientResources;
|
||||
import org.springframework.data.redis.connection.lettuce.extension.LettuceConnectionFactoryExtension;
|
||||
import org.springframework.data.redis.core.RedisKeyValueAdapter.EnableKeyspaceEvents;
|
||||
import org.springframework.data.redis.core.RedisKeyValueAdapter.ShadowCopy;
|
||||
import org.springframework.data.redis.core.convert.KeyspaceConfiguration;
|
||||
@@ -63,41 +57,19 @@ import org.springframework.data.redis.core.mapping.RedisMappingContext;
|
||||
* @author Christoph Strobl
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
@RunWith(Parameterized.class)
|
||||
@ExtendWith(LettuceConnectionFactoryExtension.class)
|
||||
public class RedisKeyValueAdapterTests {
|
||||
|
||||
private static Set<RedisConnectionFactory> initializedFactories = new HashSet<>();
|
||||
|
||||
RedisKeyValueAdapter adapter;
|
||||
StringRedisTemplate template;
|
||||
RedisConnectionFactory connectionFactory;
|
||||
private RedisKeyValueAdapter adapter;
|
||||
private StringRedisTemplate template;
|
||||
private RedisConnectionFactory connectionFactory;
|
||||
|
||||
public RedisKeyValueAdapterTests(RedisConnectionFactory connectionFactory) throws Exception {
|
||||
|
||||
if (connectionFactory instanceof InitializingBean && initializedFactories.add(connectionFactory)) {
|
||||
((InitializingBean) connectionFactory).afterPropertiesSet();
|
||||
}
|
||||
|
||||
this.connectionFactory = connectionFactory;
|
||||
ConnectionFactoryTracker.add(connectionFactory);
|
||||
}
|
||||
|
||||
@Parameters
|
||||
public static List<RedisConnectionFactory> params() {
|
||||
|
||||
LettuceConnectionFactory lettuceConnectionFactory = new LettuceConnectionFactory();
|
||||
lettuceConnectionFactory.setClientResources(LettuceTestClientResources.getSharedClientResources());
|
||||
return Collections.singletonList(lettuceConnectionFactory);
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void cleanUp() {
|
||||
initializedFactories.clear();
|
||||
ConnectionFactoryTracker.cleanUp();
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
|
||||
template = new StringRedisTemplate(connectionFactory);
|
||||
template.afterPropertiesSet();
|
||||
@@ -124,8 +96,8 @@ public class RedisKeyValueAdapterTests {
|
||||
}
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
@AfterEach
|
||||
void tearDown() {
|
||||
|
||||
try {
|
||||
adapter.destroy();
|
||||
@@ -135,7 +107,7 @@ public class RedisKeyValueAdapterTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-425
|
||||
public void putWritesDataCorrectly() {
|
||||
void putWritesDataCorrectly() {
|
||||
|
||||
Person rand = new Person();
|
||||
rand.age = 24;
|
||||
@@ -149,7 +121,7 @@ public class RedisKeyValueAdapterTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-744
|
||||
public void putWritesDataWithColonCorrectly() {
|
||||
void putWritesDataWithColonCorrectly() {
|
||||
|
||||
Person rand = new Person();
|
||||
rand.age = 24;
|
||||
@@ -163,7 +135,7 @@ public class RedisKeyValueAdapterTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-425
|
||||
public void putWritesSimpleIndexDataCorrectly() {
|
||||
void putWritesSimpleIndexDataCorrectly() {
|
||||
|
||||
Person rand = new Person();
|
||||
rand.firstname = "rand";
|
||||
@@ -175,7 +147,7 @@ public class RedisKeyValueAdapterTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-744
|
||||
public void putWritesSimpleIndexDataWithColonCorrectly() {
|
||||
void putWritesSimpleIndexDataWithColonCorrectly() {
|
||||
|
||||
Person rand = new Person();
|
||||
rand.firstname = "rand";
|
||||
@@ -187,7 +159,7 @@ public class RedisKeyValueAdapterTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-425
|
||||
public void putWritesNestedDataCorrectly() {
|
||||
void putWritesNestedDataCorrectly() {
|
||||
|
||||
Person rand = new Person();
|
||||
rand.address = new Address();
|
||||
@@ -200,7 +172,7 @@ public class RedisKeyValueAdapterTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-425
|
||||
public void putWritesSimpleNestedIndexValuesCorrectly() {
|
||||
void putWritesSimpleNestedIndexValuesCorrectly() {
|
||||
|
||||
Person rand = new Person();
|
||||
rand.address = new Address();
|
||||
@@ -213,7 +185,7 @@ public class RedisKeyValueAdapterTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-425
|
||||
public void getShouldReadSimpleObjectCorrectly() {
|
||||
void getShouldReadSimpleObjectCorrectly() {
|
||||
|
||||
Map<String, String> map = new LinkedHashMap<>();
|
||||
map.put("_class", Person.class.getName());
|
||||
@@ -227,7 +199,7 @@ public class RedisKeyValueAdapterTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-744
|
||||
public void getShouldReadSimpleObjectWithColonInIdCorrectly() {
|
||||
void getShouldReadSimpleObjectWithColonInIdCorrectly() {
|
||||
|
||||
Map<String, String> map = new LinkedHashMap<String, String>();
|
||||
map.put("_class", Person.class.getName());
|
||||
@@ -241,7 +213,7 @@ public class RedisKeyValueAdapterTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-425
|
||||
public void getShouldReadNestedObjectCorrectly() {
|
||||
void getShouldReadNestedObjectCorrectly() {
|
||||
|
||||
Map<String, String> map = new LinkedHashMap<>();
|
||||
map.put("_class", Person.class.getName());
|
||||
@@ -255,7 +227,7 @@ public class RedisKeyValueAdapterTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-425
|
||||
public void couldReadsKeyspaceSizeCorrectly() {
|
||||
void couldReadsKeyspaceSizeCorrectly() {
|
||||
|
||||
Map<String, String> map = new LinkedHashMap<>();
|
||||
map.put("_class", Person.class.getName());
|
||||
@@ -268,7 +240,7 @@ public class RedisKeyValueAdapterTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-425
|
||||
public void deleteRemovesEntriesCorrectly() {
|
||||
void deleteRemovesEntriesCorrectly() {
|
||||
|
||||
Map<String, String> map = new LinkedHashMap<>();
|
||||
map.put("_class", Person.class.getName());
|
||||
@@ -283,7 +255,7 @@ public class RedisKeyValueAdapterTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-425
|
||||
public void deleteCleansIndexedDataCorrectly() {
|
||||
void deleteCleansIndexedDataCorrectly() {
|
||||
|
||||
Map<String, String> map = new LinkedHashMap<>();
|
||||
map.put("_class", Person.class.getName());
|
||||
@@ -300,7 +272,7 @@ public class RedisKeyValueAdapterTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-1106
|
||||
public void deleteRemovesExpireHelperStructures() {
|
||||
void deleteRemovesExpireHelperStructures() {
|
||||
|
||||
WithExpiration source = new WithExpiration();
|
||||
source.id = "1";
|
||||
@@ -318,7 +290,7 @@ public class RedisKeyValueAdapterTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-425
|
||||
public void keyExpiredEventShouldRemoveHelperStructures() throws Exception {
|
||||
void keyExpiredEventShouldRemoveHelperStructures() throws Exception {
|
||||
|
||||
assumeTrue(RedisTestProfileValueSource.matches("runLongTests", "true"));
|
||||
|
||||
@@ -346,7 +318,7 @@ public class RedisKeyValueAdapterTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-744
|
||||
public void keyExpiredEventShouldRemoveHelperStructuresForObjectsWithColonInId() throws Exception {
|
||||
void keyExpiredEventShouldRemoveHelperStructuresForObjectsWithColonInId() throws Exception {
|
||||
|
||||
assumeTrue(RedisTestProfileValueSource.matches("runLongTests", "true"));
|
||||
|
||||
@@ -374,7 +346,7 @@ public class RedisKeyValueAdapterTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-589
|
||||
public void keyExpiredEventWithoutKeyspaceShouldBeIgnored() throws Exception {
|
||||
void keyExpiredEventWithoutKeyspaceShouldBeIgnored() throws Exception {
|
||||
|
||||
assumeTrue(RedisTestProfileValueSource.matches("runLongTests", "true"));
|
||||
|
||||
@@ -401,7 +373,7 @@ public class RedisKeyValueAdapterTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-512
|
||||
public void putWritesIndexDataCorrectly() {
|
||||
void putWritesIndexDataCorrectly() {
|
||||
|
||||
Person rand = new Person();
|
||||
rand.age = 24;
|
||||
@@ -437,7 +409,7 @@ public class RedisKeyValueAdapterTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-471
|
||||
public void updateShouldAlterIndexDataCorrectly() {
|
||||
void updateShouldAlterIndexDataCorrectly() {
|
||||
|
||||
Person rand = new Person();
|
||||
rand.firstname = "rand";
|
||||
@@ -456,7 +428,7 @@ public class RedisKeyValueAdapterTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-744
|
||||
public void updateShouldAlterIndexDataForObjectsWithColonInIdCorrectly() {
|
||||
void updateShouldAlterIndexDataForObjectsWithColonInIdCorrectly() {
|
||||
|
||||
Person rand = new Person();
|
||||
rand.firstname = "rand";
|
||||
@@ -475,7 +447,7 @@ public class RedisKeyValueAdapterTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-471
|
||||
public void updateShouldAlterIndexDataOnNestedObjectCorrectly() {
|
||||
void updateShouldAlterIndexDataOnNestedObjectCorrectly() {
|
||||
|
||||
Person rand = new Person();
|
||||
rand.address = new Address();
|
||||
@@ -498,7 +470,7 @@ public class RedisKeyValueAdapterTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-471
|
||||
public void updateShouldAlterIndexDataOnNestedObjectPathCorrectly() {
|
||||
void updateShouldAlterIndexDataOnNestedObjectPathCorrectly() {
|
||||
|
||||
Person rand = new Person();
|
||||
rand.address = new Address();
|
||||
@@ -518,7 +490,7 @@ public class RedisKeyValueAdapterTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-471
|
||||
public void updateShouldRemoveComplexObjectCorrectly() {
|
||||
void updateShouldRemoveComplexObjectCorrectly() {
|
||||
|
||||
Person rand = new Person();
|
||||
rand.address = new Address();
|
||||
@@ -538,7 +510,7 @@ public class RedisKeyValueAdapterTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-471
|
||||
public void updateShouldRemoveSimpleListValuesCorrectly() {
|
||||
void updateShouldRemoveSimpleListValuesCorrectly() {
|
||||
|
||||
Person rand = new Person();
|
||||
rand.nicknames = Arrays.asList("lews therin", "dragon reborn");
|
||||
@@ -555,7 +527,7 @@ public class RedisKeyValueAdapterTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-471
|
||||
public void updateShouldRemoveComplexListValuesCorrectly() {
|
||||
void updateShouldRemoveComplexListValuesCorrectly() {
|
||||
|
||||
Person mat = new Person();
|
||||
mat.firstname = "mat";
|
||||
@@ -582,7 +554,7 @@ public class RedisKeyValueAdapterTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-471
|
||||
public void updateShouldRemoveSimpleMapValuesCorrectly() {
|
||||
void updateShouldRemoveSimpleMapValuesCorrectly() {
|
||||
|
||||
Person rand = new Person();
|
||||
rand.physicalAttributes = Collections.singletonMap("eye-color", "grey");
|
||||
@@ -598,7 +570,7 @@ public class RedisKeyValueAdapterTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-471
|
||||
public void updateShouldRemoveComplexMapValuesCorrectly() {
|
||||
void updateShouldRemoveComplexMapValuesCorrectly() {
|
||||
|
||||
Person tam = new Person();
|
||||
tam.firstname = "tam";
|
||||
@@ -617,7 +589,7 @@ public class RedisKeyValueAdapterTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-533
|
||||
public void putShouldCreateGeoIndexCorrectly() {
|
||||
void putShouldCreateGeoIndexCorrectly() {
|
||||
|
||||
Person tam = new Person();
|
||||
tam.id = "1";
|
||||
@@ -631,7 +603,7 @@ public class RedisKeyValueAdapterTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-533
|
||||
public void deleteShouldRemoveGeoIndexCorrectly() {
|
||||
void deleteShouldRemoveGeoIndexCorrectly() {
|
||||
|
||||
Person tam = new Person();
|
||||
tam.id = "1";
|
||||
@@ -647,7 +619,7 @@ public class RedisKeyValueAdapterTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-533
|
||||
public void updateShouldAlterGeoIndexCorrectlyOnDelete() {
|
||||
void updateShouldAlterGeoIndexCorrectlyOnDelete() {
|
||||
|
||||
Person tam = new Person();
|
||||
tam.id = "1";
|
||||
@@ -666,7 +638,7 @@ public class RedisKeyValueAdapterTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-533, DATAREDIS-614
|
||||
public void updateShouldAlterGeoIndexCorrectlyOnUpdate() {
|
||||
void updateShouldAlterGeoIndexCorrectlyOnUpdate() {
|
||||
|
||||
Person tam = new Person();
|
||||
tam.id = "1";
|
||||
@@ -689,7 +661,7 @@ public class RedisKeyValueAdapterTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-1091
|
||||
public void phantomKeyNotInsertedOnPutWhenShadowCopyIsTurnedOff() {
|
||||
void phantomKeyNotInsertedOnPutWhenShadowCopyIsTurnedOff() {
|
||||
|
||||
RedisMappingContext mappingContext = new RedisMappingContext(
|
||||
new MappingConfiguration(new IndexConfiguration(), new KeyspaceConfiguration()));
|
||||
@@ -708,7 +680,7 @@ public class RedisKeyValueAdapterTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-1091
|
||||
public void phantomKeyInsertedOnPutWhenShadowCopyIsTurnedOn() {
|
||||
void phantomKeyInsertedOnPutWhenShadowCopyIsTurnedOn() {
|
||||
|
||||
RedisMappingContext mappingContext = new RedisMappingContext(
|
||||
new MappingConfiguration(new IndexConfiguration(), new KeyspaceConfiguration()));
|
||||
@@ -727,7 +699,7 @@ public class RedisKeyValueAdapterTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-1091
|
||||
public void phantomKeyInsertedOnPutWhenShadowCopyIsInDefaultAndKeyspaceNotificationEnabled() {
|
||||
void phantomKeyInsertedOnPutWhenShadowCopyIsInDefaultAndKeyspaceNotificationEnabled() {
|
||||
|
||||
ExpiringPerson rand = new ExpiringPerson();
|
||||
rand.age = 24;
|
||||
|
||||
@@ -26,13 +26,15 @@ import java.util.LinkedHashSet;
|
||||
import java.util.Properties;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Mockito;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import org.mockito.junit.jupiter.MockitoSettings;
|
||||
import org.mockito.quality.Strictness;
|
||||
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.redis.connection.RedisConnection;
|
||||
@@ -53,17 +55,18 @@ import org.springframework.data.redis.listener.KeyExpirationEventMessageListener
|
||||
* @author Christoph Strobl
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.Silent.class)
|
||||
public class RedisKeyValueAdapterUnitTests {
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
@MockitoSettings(strictness = Strictness.LENIENT)
|
||||
class RedisKeyValueAdapterUnitTests {
|
||||
|
||||
RedisKeyValueAdapter adapter;
|
||||
RedisTemplate<?, ?> template;
|
||||
RedisMappingContext context;
|
||||
private RedisKeyValueAdapter adapter;
|
||||
private RedisTemplate<?, ?> template;
|
||||
private RedisMappingContext context;
|
||||
@Mock JedisConnectionFactory jedisConnectionFactoryMock;
|
||||
@Mock RedisConnection redisConnectionMock;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
@BeforeEach
|
||||
void setUp() throws Exception {
|
||||
|
||||
template = new RedisTemplate<>();
|
||||
template.setConnectionFactory(jedisConnectionFactoryMock);
|
||||
@@ -83,13 +86,13 @@ public class RedisKeyValueAdapterUnitTests {
|
||||
adapter.afterPropertiesSet();
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
@AfterEach
|
||||
void tearDown() throws Exception {
|
||||
adapter.destroy();
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-507
|
||||
public void destroyShouldNotDestroyConnectionFactory() throws Exception {
|
||||
void destroyShouldNotDestroyConnectionFactory() throws Exception {
|
||||
|
||||
adapter.destroy();
|
||||
|
||||
@@ -97,7 +100,7 @@ public class RedisKeyValueAdapterUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-512, DATAREDIS-530
|
||||
public void putShouldRemoveExistingIndexValuesWhenUpdating() {
|
||||
void putShouldRemoveExistingIndexValuesWhenUpdating() {
|
||||
|
||||
RedisData rd = new RedisData(Bucket.newBucketFromStringMap(Collections.singletonMap("_id", "1")));
|
||||
rd.addIndexedData(new SimpleIndexedPropertyValue("persons", "firstname", "rand"));
|
||||
@@ -112,7 +115,7 @@ public class RedisKeyValueAdapterUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-512
|
||||
public void putShouldNotTryToRemoveExistingIndexValuesWhenInsertingNew() {
|
||||
void putShouldNotTryToRemoveExistingIndexValuesWhenInsertingNew() {
|
||||
|
||||
RedisData rd = new RedisData(Bucket.newBucketFromStringMap(Collections.singletonMap("_id", "1")));
|
||||
rd.addIndexedData(new SimpleIndexedPropertyValue("persons", "firstname", "rand"));
|
||||
@@ -127,7 +130,7 @@ public class RedisKeyValueAdapterUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-491
|
||||
public void shouldInitKeyExpirationListenerOnStartup() throws Exception {
|
||||
void shouldInitKeyExpirationListenerOnStartup() throws Exception {
|
||||
|
||||
adapter.destroy();
|
||||
|
||||
@@ -141,7 +144,7 @@ public class RedisKeyValueAdapterUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-491
|
||||
public void shouldInitKeyExpirationListenerOnFirstPutWithTtl() throws Exception {
|
||||
void shouldInitKeyExpirationListenerOnFirstPutWithTtl() throws Exception {
|
||||
|
||||
adapter.destroy();
|
||||
|
||||
@@ -165,7 +168,7 @@ public class RedisKeyValueAdapterUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-491
|
||||
public void shouldNeverInitKeyExpirationListener() throws Exception {
|
||||
void shouldNeverInitKeyExpirationListener() throws Exception {
|
||||
|
||||
adapter.destroy();
|
||||
|
||||
|
||||
@@ -43,10 +43,13 @@ import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.redis.ConnectionFactoryTracker;
|
||||
import org.springframework.data.redis.connection.RedisConnectionFactory;
|
||||
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
|
||||
import org.springframework.data.redis.connection.jedis.extension.JedisConnectionFactoryExtension;
|
||||
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
|
||||
import org.springframework.data.redis.connection.lettuce.LettuceTestClientResources;
|
||||
import org.springframework.data.redis.connection.lettuce.extension.LettuceConnectionFactoryExtension;
|
||||
import org.springframework.data.redis.test.extension.LettuceTestClientResources;
|
||||
import org.springframework.data.redis.core.index.Indexed;
|
||||
import org.springframework.data.redis.core.mapping.RedisMappingContext;
|
||||
import org.springframework.data.redis.test.extension.RedisStanalone;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
||||
/**
|
||||
@@ -65,30 +68,19 @@ public class RedisKeyValueTemplateTests {
|
||||
RedisKeyValueAdapter adapter;
|
||||
|
||||
public RedisKeyValueTemplateTests(RedisConnectionFactory connectionFactory) {
|
||||
|
||||
this.connectionFactory = connectionFactory;
|
||||
ConnectionFactoryTracker.add(connectionFactory);
|
||||
|
||||
}
|
||||
|
||||
@Parameters
|
||||
public static List<RedisConnectionFactory> params() {
|
||||
|
||||
JedisConnectionFactory jedis = new JedisConnectionFactory();
|
||||
jedis.afterPropertiesSet();
|
||||
JedisConnectionFactory jedis = JedisConnectionFactoryExtension.getConnectionFactory(RedisStanalone.class);
|
||||
|
||||
LettuceConnectionFactory lettuce = new LettuceConnectionFactory();
|
||||
lettuce.setClientResources(LettuceTestClientResources.getSharedClientResources());
|
||||
lettuce.afterPropertiesSet();
|
||||
LettuceConnectionFactory lettuce = LettuceConnectionFactoryExtension.getConnectionFactory(RedisStanalone.class);
|
||||
|
||||
return Arrays.<RedisConnectionFactory> asList(jedis, lettuce);
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void cleanUp() {
|
||||
ConnectionFactoryTracker.cleanUp();
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@ import org.springframework.data.redis.connection.DataType;
|
||||
import org.springframework.data.redis.connection.StringRedisConnection;
|
||||
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
|
||||
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
|
||||
import org.springframework.data.redis.connection.lettuce.LettuceTestClientResources;
|
||||
import org.springframework.data.redis.test.extension.LettuceTestClientResources;
|
||||
import org.springframework.data.redis.core.ZSetOperations.TypedTuple;
|
||||
import org.springframework.data.redis.core.query.SortQueryBuilder;
|
||||
import org.springframework.data.redis.core.script.DefaultRedisScript;
|
||||
@@ -79,8 +79,6 @@ public class RedisTemplateTests<K, V> {
|
||||
this.redisTemplate = redisTemplate;
|
||||
this.keyFactory = keyFactory;
|
||||
this.valueFactory = valueFactory;
|
||||
|
||||
ConnectionFactoryTracker.add(redisTemplate.getConnectionFactory());
|
||||
}
|
||||
|
||||
@After
|
||||
|
||||
@@ -21,10 +21,13 @@ import static org.mockito.Mockito.*;
|
||||
import java.io.Serializable;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.data.redis.connection.RedisConnection;
|
||||
@@ -40,15 +43,15 @@ import org.springframework.transaction.support.TransactionSynchronizationManager
|
||||
* @author Christoph Strobl
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class RedisTemplateUnitTests {
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class RedisTemplateUnitTests {
|
||||
|
||||
private RedisTemplate<Object, Object> template;
|
||||
private @Mock RedisConnectionFactory connectionFactoryMock;
|
||||
private @Mock RedisConnection redisConnectionMock;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
|
||||
TransactionSynchronizationManager.clear();
|
||||
|
||||
@@ -60,21 +63,21 @@ public class RedisTemplateUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-277
|
||||
public void slaveOfIsDelegatedToConnectionCorrectly() {
|
||||
void slaveOfIsDelegatedToConnectionCorrectly() {
|
||||
|
||||
template.slaveOf("127.0.0.1", 1001);
|
||||
verify(redisConnectionMock, times(1)).slaveOf(eq("127.0.0.1"), eq(1001));
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-277
|
||||
public void slaveOfNoOneIsDelegatedToConnectionCorrectly() {
|
||||
void slaveOfNoOneIsDelegatedToConnectionCorrectly() {
|
||||
|
||||
template.slaveOfNoOne();
|
||||
verify(redisConnectionMock, times(1)).slaveOfNoOne();
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-501
|
||||
public void templateShouldPassOnAndUseResoureLoaderClassLoaderToDefaultJdkSerializerWhenNotAlreadySet() {
|
||||
void templateShouldPassOnAndUseResoureLoaderClassLoaderToDefaultJdkSerializerWhenNotAlreadySet() {
|
||||
|
||||
ShadowingClassLoader scl = new ShadowingClassLoader(ClassLoader.getSystemClassLoader());
|
||||
|
||||
@@ -92,7 +95,7 @@ public class RedisTemplateUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-531
|
||||
public void executeWithStickyConnectionShouldNotCloseConnectionWhenDone() {
|
||||
void executeWithStickyConnectionShouldNotCloseConnectionWhenDone() {
|
||||
|
||||
CapturingCallback callback = new CapturingCallback();
|
||||
template.executeWithStickyConnection(callback);
|
||||
@@ -102,7 +105,7 @@ public class RedisTemplateUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-988
|
||||
public void executeSessionShouldReuseConnection() {
|
||||
void executeSessionShouldReuseConnection() {
|
||||
|
||||
template.execute(new SessionCallback<Object>() {
|
||||
@Nullable
|
||||
@@ -120,7 +123,7 @@ public class RedisTemplateUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-988
|
||||
public void executeSessionInTransactionShouldReuseConnection() {
|
||||
void executeSessionInTransactionShouldReuseConnection() {
|
||||
|
||||
TransactionSynchronizationManager.setCurrentTransactionReadOnly(true);
|
||||
|
||||
@@ -139,7 +142,7 @@ public class RedisTemplateUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-988
|
||||
public void transactionAwareTemplateShouldReleaseConnection() {
|
||||
void transactionAwareTemplateShouldReleaseConnection() {
|
||||
|
||||
template.setEnableTransactionSupport(true);
|
||||
TransactionSynchronizationManager.setCurrentTransactionReadOnly(true);
|
||||
@@ -159,7 +162,7 @@ public class RedisTemplateUnitTests {
|
||||
verify(redisConnectionMock, times(2)).close();
|
||||
}
|
||||
|
||||
static class SomeArbitrarySerializableObject implements Serializable {
|
||||
private static class SomeArbitrarySerializableObject implements Serializable {
|
||||
private static final long serialVersionUID = -5973659324040506423L;
|
||||
}
|
||||
|
||||
|
||||
@@ -27,33 +27,29 @@ import java.util.NoSuchElementException;
|
||||
import java.util.Queue;
|
||||
import java.util.Stack;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.dao.InvalidDataAccessApiUsageException;
|
||||
|
||||
/**
|
||||
* @author Christoph Strobl
|
||||
*/
|
||||
public class ScanCursorUnitTests {
|
||||
|
||||
public @Rule ExpectedException exception = ExpectedException.none();
|
||||
class ScanCursorUnitTests {
|
||||
|
||||
@Test // DATAREDIS-290
|
||||
public void cursorShouldNotLoopWhenNoValuesFound() {
|
||||
void cursorShouldNotLoopWhenNoValuesFound() {
|
||||
|
||||
CapturingCursorDummy cursor = initCursor(new LinkedList<>());
|
||||
assertThat(cursor.hasNext()).isFalse();
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-290
|
||||
public void cursorShouldReturnNullWhenNoNextElementAvailable() {
|
||||
void cursorShouldReturnNullWhenNoNextElementAvailable() {
|
||||
assertThatExceptionOfType(NoSuchElementException.class).isThrownBy(() -> initCursor(new LinkedList<>()).next());
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-290
|
||||
public void cursorShouldNotLoopWhenReachingStartingPointInFistLoop() {
|
||||
void cursorShouldNotLoopWhenReachingStartingPointInFistLoop() {
|
||||
|
||||
LinkedList<ScanIteration<String>> values = new LinkedList<>();
|
||||
values.add(createIteration(0, "spring", "data", "redis"));
|
||||
@@ -73,7 +69,7 @@ public class ScanCursorUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-290
|
||||
public void cursorShouldStopLoopWhenReachingStartingPoint() {
|
||||
void cursorShouldStopLoopWhenReachingStartingPoint() {
|
||||
|
||||
LinkedList<ScanIteration<String>> values = new LinkedList<>();
|
||||
values.add(createIteration(1, "spring"));
|
||||
@@ -95,40 +91,29 @@ public class ScanCursorUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-290
|
||||
public void shouldThrowExceptionWhenAccessingClosedCursor() {
|
||||
void shouldThrowExceptionWhenAccessingClosedCursor() {
|
||||
|
||||
CapturingCursorDummy cursor = new CapturingCursorDummy(null);
|
||||
|
||||
assertThat(cursor.isClosed()).isFalse();
|
||||
|
||||
exception.expect(InvalidDataAccessApiUsageException.class);
|
||||
exception.expectMessage("closed cursor");
|
||||
|
||||
cursor.next();
|
||||
assertThatExceptionOfType(InvalidDataAccessApiUsageException.class).isThrownBy(cursor::next)
|
||||
.withMessageContaining("closed cursor");
|
||||
}
|
||||
|
||||
@Test(expected = InvalidDataAccessApiUsageException.class) // DATAREDIS-290
|
||||
public void repoeningCursorShouldHappenAtLastPosition() throws IOException {
|
||||
@Test // DATAREDIS-290
|
||||
void repoeningCursorShouldHappenAtLastPosition() {
|
||||
|
||||
LinkedList<ScanIteration<String>> values = new LinkedList<>();
|
||||
values.add(createIteration(1, "spring"));
|
||||
values.add(createIteration(2, "data"));
|
||||
values.add(createIteration(0, "redis"));
|
||||
Cursor<String> cursor = initCursor(values).open();
|
||||
|
||||
assertThat(cursor.next()).isEqualTo("spring");
|
||||
assertThat(cursor.getCursorId()).isEqualTo(1L);
|
||||
|
||||
// close the cursor
|
||||
cursor.close();
|
||||
assertThat(cursor.isClosed()).isTrue();
|
||||
|
||||
// reopen cursor at last position
|
||||
cursor.open();
|
||||
assertThatExceptionOfType(InvalidDataAccessApiUsageException.class).isThrownBy(() -> initCursor(values).open());
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-290
|
||||
public void positionShouldBeIncrementedCorrectly() throws IOException {
|
||||
void positionShouldBeIncrementedCorrectly() {
|
||||
|
||||
LinkedList<ScanIteration<String>> values = new LinkedList<>();
|
||||
values.add(createIteration(1, "spring"));
|
||||
@@ -146,7 +131,7 @@ public class ScanCursorUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-417
|
||||
public void hasNextShouldCallScanUntilFinishedWhenScanResultIsAnEmptyCollection() {
|
||||
void hasNextShouldCallScanUntilFinishedWhenScanResultIsAnEmptyCollection() {
|
||||
|
||||
LinkedList<ScanIteration<String>> values = new LinkedList<>();
|
||||
values.add(createIteration(1, "spring"));
|
||||
@@ -167,7 +152,7 @@ public class ScanCursorUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-417
|
||||
public void hasNextShouldStopWhenScanResultIsAnEmptyCollectionAndStateIsFinished() {
|
||||
void hasNextShouldStopWhenScanResultIsAnEmptyCollectionAndStateIsFinished() {
|
||||
|
||||
LinkedList<ScanIteration<String>> values = new LinkedList<>();
|
||||
values.add(createIteration(1, "spring"));
|
||||
@@ -190,7 +175,7 @@ public class ScanCursorUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-417
|
||||
public void hasNextShouldStopCorrectlyWhenWholeScanIterationDoesNotReturnResultsAndStateIsFinished() {
|
||||
void hasNextShouldStopCorrectlyWhenWholeScanIterationDoesNotReturnResultsAndStateIsFinished() {
|
||||
|
||||
LinkedList<ScanIteration<String>> values = new LinkedList<>();
|
||||
values.add(createIteration(1));
|
||||
@@ -229,7 +214,7 @@ public class ScanCursorUnitTests {
|
||||
|
||||
private Stack<Long> cursors;
|
||||
|
||||
public CapturingCursorDummy(Queue<ScanIteration<String>> values) {
|
||||
CapturingCursorDummy(Queue<ScanIteration<String>> values) {
|
||||
this.values = values;
|
||||
}
|
||||
|
||||
|
||||
@@ -15,10 +15,11 @@
|
||||
*/
|
||||
package org.springframework.data.redis.core;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.data.redis.connection.RedisConnection;
|
||||
import org.springframework.data.redis.connection.RedisConnectionFactory;
|
||||
@@ -27,14 +28,14 @@ import org.springframework.data.redis.connection.StringRedisConnection;
|
||||
/**
|
||||
* @author Costin Leau
|
||||
*/
|
||||
public class SessionTest {
|
||||
class SessionUnitTests {
|
||||
|
||||
@Test
|
||||
public void testSession() throws Exception {
|
||||
final RedisConnection conn = mock(RedisConnection.class);
|
||||
final StringRedisConnection stringConn = mock(StringRedisConnection.class);
|
||||
void testSession() throws Exception {
|
||||
RedisConnection conn = mock(RedisConnection.class);
|
||||
StringRedisConnection stringConn = mock(StringRedisConnection.class);
|
||||
RedisConnectionFactory factory = mock(RedisConnectionFactory.class);
|
||||
final StringRedisTemplate template = spy(new StringRedisTemplate(factory));
|
||||
StringRedisTemplate template = spy(new StringRedisTemplate(factory));
|
||||
when(factory.getConnection()).thenReturn(conn);
|
||||
doReturn(stringConn).when(template).preProcessConnection(eq(conn), anyBoolean());
|
||||
|
||||
@@ -50,7 +51,7 @@ public class SessionTest {
|
||||
});
|
||||
}
|
||||
|
||||
private void checkConnection(RedisTemplate<?, ?> template, final RedisConnection expectedConnection) {
|
||||
private void checkConnection(RedisTemplate<?, ?> template, RedisConnection expectedConnection) {
|
||||
template.execute(connection -> {
|
||||
assertThat(connection).isSameAs(expectedConnection);
|
||||
return null;
|
||||
@@ -1,34 +0,0 @@
|
||||
/*
|
||||
* Copyright 2011-2020 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.data.redis.core;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.springframework.data.redis.core.query.SortQueryBuilder;
|
||||
|
||||
public class SortTest {
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {}
|
||||
|
||||
@After
|
||||
public void tearDown() throws Exception {}
|
||||
|
||||
public void testBasicDSL() throws Exception {
|
||||
SortQueryBuilder.sort("list").build();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -20,7 +20,7 @@ import static org.assertj.core.api.Assertions.*;
|
||||
import java.time.Duration;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Unit test of {@link TimeoutUtils}
|
||||
@@ -28,82 +28,82 @@ import org.junit.Test;
|
||||
* @author Jennifer Hickey
|
||||
* @author Christoph Strobl
|
||||
*/
|
||||
public class TimeoutUtilsTests {
|
||||
class TimeoutUtilsUnitTests {
|
||||
|
||||
@Test
|
||||
public void testConvertMoreThanOneSecond() {
|
||||
void testConvertMoreThanOneSecond() {
|
||||
assertThat(TimeoutUtils.toSeconds(2010, TimeUnit.MILLISECONDS)).isEqualTo(2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConvertLessThanOneSecond() {
|
||||
void testConvertLessThanOneSecond() {
|
||||
assertThat(TimeoutUtils.toSeconds(999, TimeUnit.NANOSECONDS)).isOne();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConvertZeroSeconds() {
|
||||
void testConvertZeroSeconds() {
|
||||
assertThat(TimeoutUtils.toSeconds(0, TimeUnit.MINUTES)).isZero();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConvertNegativeSecondsGreaterThanNegativeOne() {
|
||||
void testConvertNegativeSecondsGreaterThanNegativeOne() {
|
||||
// Ensure we convert this to 0 as before, though ideally we wouldn't accept negative values
|
||||
assertThat(TimeoutUtils.toSeconds(-123, TimeUnit.MILLISECONDS)).isZero();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConvertNegativeSecondsEqualNegativeOne() {
|
||||
void testConvertNegativeSecondsEqualNegativeOne() {
|
||||
assertThat(TimeoutUtils.toSeconds(-1111, TimeUnit.MILLISECONDS)).isEqualTo(-1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConvertNegativeSecondsLessThanNegativeOne() {
|
||||
void testConvertNegativeSecondsLessThanNegativeOne() {
|
||||
assertThat(TimeoutUtils.toSeconds(-2344, TimeUnit.MILLISECONDS)).isEqualTo(-2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConvertMoreThanOneMilli() {
|
||||
void testConvertMoreThanOneMilli() {
|
||||
assertThat(TimeoutUtils.toMillis(2010, TimeUnit.MICROSECONDS)).isEqualTo(2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConvertLessThanOneMilli() {
|
||||
void testConvertLessThanOneMilli() {
|
||||
assertThat(TimeoutUtils.toMillis(999, TimeUnit.NANOSECONDS)).isOne();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConvertZeroMillis() {
|
||||
void testConvertZeroMillis() {
|
||||
assertThat(TimeoutUtils.toMillis(0, TimeUnit.SECONDS)).isZero();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConvertNegativeMillisGreaterThanNegativeOne() {
|
||||
void testConvertNegativeMillisGreaterThanNegativeOne() {
|
||||
// Ensure we convert this to 0 as before, though ideally we wouldn't accept negative values
|
||||
assertThat(TimeoutUtils.toMillis(-123, TimeUnit.MICROSECONDS)).isZero();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConvertNegativeMillisEqualNegativeOne() {
|
||||
void testConvertNegativeMillisEqualNegativeOne() {
|
||||
assertThat(TimeoutUtils.toMillis(-1111, TimeUnit.MICROSECONDS)).isEqualTo(-1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConvertNegativeMillisLessThanNegativeOne() {
|
||||
void testConvertNegativeMillisLessThanNegativeOne() {
|
||||
assertThat(TimeoutUtils.toMillis(-2344, TimeUnit.MICROSECONDS)).isEqualTo(-2);
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-815
|
||||
public void hasMillisReturnsFalseForTimeoutOfExactSeconds() {
|
||||
void hasMillisReturnsFalseForTimeoutOfExactSeconds() {
|
||||
assertThat(TimeoutUtils.hasMillis(Duration.ofSeconds(1))).isFalse();
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-815
|
||||
public void hasMillisReturnsTrueForTimeoutWithMsec() {
|
||||
void hasMillisReturnsTrueForTimeoutWithMsec() {
|
||||
assertThat(TimeoutUtils.hasMillis(Duration.ofMillis(1500))).isTrue();
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-815
|
||||
public void hasMillisReturnsTrueForTimeoutLessThanOneSecond() {
|
||||
void hasMillisReturnsTrueForTimeoutLessThanOneSecond() {
|
||||
assertThat(TimeoutUtils.hasMillis(Duration.ofMillis(500))).isTrue();
|
||||
}
|
||||
}
|
||||
@@ -21,8 +21,8 @@ import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.dao.DataAccessException;
|
||||
@@ -36,9 +36,7 @@ import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
import org.springframework.data.redis.serializer.GenericToStringSerializer;
|
||||
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
|
||||
import org.springframework.data.redis.serializer.StringRedisSerializer;
|
||||
import org.springframework.data.redis.test.util.MinimumRedisVersionRule;
|
||||
import org.springframework.scripting.support.StaticScriptSource;
|
||||
import org.springframework.test.annotation.IfProfileValue;
|
||||
|
||||
/**
|
||||
* Integration test of {@link DefaultScriptExecutor}
|
||||
@@ -48,23 +46,19 @@ import org.springframework.test.annotation.IfProfileValue;
|
||||
* @author Christoph Strobl
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
@IfProfileValue(name = "redisVersion", value = "2.6+")
|
||||
public abstract class AbstractDefaultScriptExecutorTests {
|
||||
|
||||
public static @ClassRule MinimumRedisVersionRule minRedisVersion = new MinimumRedisVersionRule();
|
||||
|
||||
@SuppressWarnings("rawtypes") //
|
||||
private RedisTemplate template;
|
||||
|
||||
protected abstract RedisConnectionFactory getConnectionFactory();
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void tearDown() {
|
||||
|
||||
if (template == null) {
|
||||
return;
|
||||
}
|
||||
@BeforeEach
|
||||
void setup() {
|
||||
|
||||
StringRedisTemplate template = new StringRedisTemplate();
|
||||
template.setConnectionFactory(getConnectionFactory());
|
||||
template.afterPropertiesSet();
|
||||
template.execute((RedisCallback<Object>) connection -> {
|
||||
connection.flushDb();
|
||||
connection.scriptFlush();
|
||||
@@ -74,7 +68,7 @@ public abstract class AbstractDefaultScriptExecutorTests {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void testExecuteLongResult() {
|
||||
void testExecuteLongResult() {
|
||||
this.template = new StringRedisTemplate();
|
||||
template.setConnectionFactory(getConnectionFactory());
|
||||
template.afterPropertiesSet();
|
||||
@@ -90,7 +84,7 @@ public abstract class AbstractDefaultScriptExecutorTests {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void testExecuteBooleanResult() {
|
||||
void testExecuteBooleanResult() {
|
||||
this.template = new RedisTemplate<String, Long>();
|
||||
template.setKeySerializer(StringRedisSerializer.UTF_8);
|
||||
template.setValueSerializer(new GenericToStringSerializer<>(Long.class));
|
||||
@@ -108,7 +102,7 @@ public abstract class AbstractDefaultScriptExecutorTests {
|
||||
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
@Test
|
||||
public void testExecuteListResultCustomArgsSerializer() {
|
||||
void testExecuteListResultCustomArgsSerializer() {
|
||||
this.template = new StringRedisTemplate();
|
||||
template.setConnectionFactory(getConnectionFactory());
|
||||
template.afterPropertiesSet();
|
||||
@@ -124,7 +118,7 @@ public abstract class AbstractDefaultScriptExecutorTests {
|
||||
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
@Test
|
||||
public void testExecuteMixedListResult() {
|
||||
void testExecuteMixedListResult() {
|
||||
this.template = new StringRedisTemplate();
|
||||
template.setConnectionFactory(getConnectionFactory());
|
||||
template.afterPropertiesSet();
|
||||
@@ -140,7 +134,7 @@ public abstract class AbstractDefaultScriptExecutorTests {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void testExecuteValueResult() {
|
||||
void testExecuteValueResult() {
|
||||
this.template = new StringRedisTemplate();
|
||||
template.setConnectionFactory(getConnectionFactory());
|
||||
template.afterPropertiesSet();
|
||||
@@ -154,7 +148,7 @@ public abstract class AbstractDefaultScriptExecutorTests {
|
||||
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
@Test
|
||||
public void testExecuteStatusResult() {
|
||||
void testExecuteStatusResult() {
|
||||
this.template = new RedisTemplate<String, Long>();
|
||||
template.setKeySerializer(StringRedisSerializer.UTF_8);
|
||||
template.setValueSerializer(new GenericToStringSerializer<>(Long.class));
|
||||
@@ -170,7 +164,7 @@ public abstract class AbstractDefaultScriptExecutorTests {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void testExecuteCustomResultSerializer() {
|
||||
void testExecuteCustomResultSerializer() {
|
||||
Jackson2JsonRedisSerializer<Person> personSerializer = new Jackson2JsonRedisSerializer<>(Person.class);
|
||||
this.template = new RedisTemplate<String, Person>();
|
||||
template.setKeySerializer(StringRedisSerializer.UTF_8);
|
||||
@@ -232,7 +226,7 @@ public abstract class AbstractDefaultScriptExecutorTests {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void testExecuteCachedNullKeys() {
|
||||
void testExecuteCachedNullKeys() {
|
||||
this.template = new StringRedisTemplate();
|
||||
template.setConnectionFactory(getConnectionFactory());
|
||||
template.afterPropertiesSet();
|
||||
@@ -246,7 +240,7 @@ public abstract class AbstractDefaultScriptExecutorTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-356
|
||||
public void shouldTransparentlyReEvaluateScriptIfNotPresent() throws Exception {
|
||||
void shouldTransparentlyReEvaluateScriptIfNotPresent() throws Exception {
|
||||
|
||||
this.template = new StringRedisTemplate();
|
||||
template.setConnectionFactory(getConnectionFactory());
|
||||
|
||||
@@ -24,17 +24,16 @@ import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.data.redis.Person;
|
||||
import org.springframework.data.redis.SettingsUtils;
|
||||
import org.springframework.data.redis.connection.RedisConnection;
|
||||
import org.springframework.data.redis.connection.RedisConnectionFactory;
|
||||
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
|
||||
import org.springframework.data.redis.connection.lettuce.LettuceTestClientConfiguration;
|
||||
import org.springframework.data.redis.connection.lettuce.extension.LettuceConnectionFactoryExtension;
|
||||
import org.springframework.data.redis.core.RedisCallback;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
@@ -45,6 +44,7 @@ import org.springframework.data.redis.serializer.RedisElementWriter;
|
||||
import org.springframework.data.redis.serializer.RedisSerializationContext;
|
||||
import org.springframework.data.redis.serializer.RedisSerializationContext.RedisSerializationContextBuilder;
|
||||
import org.springframework.data.redis.serializer.StringRedisSerializer;
|
||||
import org.springframework.data.redis.test.extension.RedisStanalone;
|
||||
import org.springframework.scripting.support.StaticScriptSource;
|
||||
|
||||
/**
|
||||
@@ -57,27 +57,17 @@ public class DefaultReactiveScriptExecutorTests {
|
||||
private static StringRedisTemplate stringTemplate;
|
||||
private static ReactiveScriptExecutor<String> stringScriptExecutor;
|
||||
|
||||
@BeforeClass
|
||||
public static void setUp() {
|
||||
@BeforeAll
|
||||
static void setUp() {
|
||||
|
||||
connectionFactory = new LettuceConnectionFactory(SettingsUtils.standaloneConfiguration(),
|
||||
LettuceTestClientConfiguration.create());
|
||||
connectionFactory.afterPropertiesSet();
|
||||
connectionFactory = LettuceConnectionFactoryExtension.getConnectionFactory(RedisStanalone.class);
|
||||
|
||||
stringTemplate = new StringRedisTemplate(connectionFactory);
|
||||
stringScriptExecutor = new DefaultReactiveScriptExecutor<>(connectionFactory, RedisSerializationContext.string());
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void cleanUp() {
|
||||
|
||||
if (connectionFactory != null) {
|
||||
connectionFactory.destroy();
|
||||
}
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
@BeforeEach
|
||||
void before() {
|
||||
|
||||
RedisConnection connection = connectionFactory.getConnection();
|
||||
try {
|
||||
@@ -93,7 +83,7 @@ public class DefaultReactiveScriptExecutorTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-711
|
||||
public void shouldReturnLong() {
|
||||
void shouldReturnLong() {
|
||||
|
||||
DefaultRedisScript<Long> script = new DefaultRedisScript<>();
|
||||
script.setLocation(new ClassPathResource("org/springframework/data/redis/core/script/increment.lua"));
|
||||
@@ -108,7 +98,7 @@ public class DefaultReactiveScriptExecutorTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-711
|
||||
public void shouldReturnBoolean() {
|
||||
void shouldReturnBoolean() {
|
||||
|
||||
RedisSerializationContextBuilder<String, Long> builder = RedisSerializationContext
|
||||
.newSerializationContext(StringRedisSerializer.UTF_8);
|
||||
@@ -132,7 +122,7 @@ public class DefaultReactiveScriptExecutorTests {
|
||||
|
||||
@Test // DATAREDIS-711
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
public void shouldApplyCustomArgsSerializer() {
|
||||
void shouldApplyCustomArgsSerializer() {
|
||||
|
||||
DefaultRedisScript<List> script = new DefaultRedisScript<>();
|
||||
script.setLocation(new ClassPathResource("org/springframework/data/redis/core/script/bulkpop.lua"));
|
||||
@@ -148,7 +138,7 @@ public class DefaultReactiveScriptExecutorTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-711
|
||||
public void testExecuteMixedListResult() {
|
||||
void testExecuteMixedListResult() {
|
||||
|
||||
DefaultRedisScript<List> script = new DefaultRedisScript<>();
|
||||
script.setLocation(new ClassPathResource("org/springframework/data/redis/core/script/popandlength.lua"));
|
||||
@@ -164,7 +154,7 @@ public class DefaultReactiveScriptExecutorTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-711
|
||||
public void shouldReturnValueResult() {
|
||||
void shouldReturnValueResult() {
|
||||
|
||||
DefaultRedisScript<String> script = new DefaultRedisScript<>();
|
||||
script.setScriptText("return redis.call('GET',KEYS[1])");
|
||||
@@ -179,7 +169,7 @@ public class DefaultReactiveScriptExecutorTests {
|
||||
|
||||
@Test // DATAREDIS-711
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
public void shouldReturnStatusValue() {
|
||||
void shouldReturnStatusValue() {
|
||||
|
||||
DefaultRedisScript script = new DefaultRedisScript();
|
||||
script.setScriptText("return redis.call('SET',KEYS[1], ARGV[1])");
|
||||
@@ -198,7 +188,7 @@ public class DefaultReactiveScriptExecutorTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-711
|
||||
public void shouldApplyCustomResultSerializer() {
|
||||
void shouldApplyCustomResultSerializer() {
|
||||
|
||||
Jackson2JsonRedisSerializer<Person> personSerializer = new Jackson2JsonRedisSerializer<>(Person.class);
|
||||
|
||||
@@ -223,7 +213,7 @@ public class DefaultReactiveScriptExecutorTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-711
|
||||
public void executeAddsScriptToScriptCache() {
|
||||
void executeAddsScriptToScriptCache() {
|
||||
|
||||
DefaultRedisScript<String> script = new DefaultRedisScript<>();
|
||||
script.setScriptText("return 'HELLO'");
|
||||
|
||||
@@ -15,15 +15,15 @@
|
||||
*/
|
||||
package org.springframework.data.redis.core.script.jedis;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import redis.clients.jedis.Jedis;
|
||||
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
|
||||
import org.springframework.data.redis.connection.RedisConnectionFactory;
|
||||
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
|
||||
import org.springframework.data.redis.connection.jedis.extension.JedisConnectionFactoryExtension;
|
||||
import org.springframework.data.redis.core.script.AbstractDefaultScriptExecutorTests;
|
||||
import org.springframework.data.redis.core.script.DefaultScriptExecutor;
|
||||
|
||||
import redis.clients.jedis.Jedis;
|
||||
import org.springframework.data.redis.test.extension.RedisStanalone;
|
||||
|
||||
/**
|
||||
* Integration test of {@link DefaultScriptExecutor} with {@link Jedis}.
|
||||
@@ -32,38 +32,18 @@ import redis.clients.jedis.Jedis;
|
||||
*/
|
||||
public class JedisDefaultScriptExecutorTests extends AbstractDefaultScriptExecutorTests {
|
||||
|
||||
private static JedisConnectionFactory connectionFactory;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
|
||||
connectionFactory = new JedisConnectionFactory();
|
||||
connectionFactory.afterPropertiesSet();
|
||||
|
||||
}
|
||||
|
||||
@After
|
||||
public void teardown() {
|
||||
|
||||
super.tearDown();
|
||||
|
||||
if (connectionFactory != null) {
|
||||
connectionFactory.destroy();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected RedisConnectionFactory getConnectionFactory() {
|
||||
return connectionFactory;
|
||||
return JedisConnectionFactoryExtension.getConnectionFactory(RedisStanalone.class);
|
||||
}
|
||||
|
||||
@Ignore("transactional execution is currently not supported with Jedis")
|
||||
@Disabled("transactional execution is currently not supported with Jedis")
|
||||
@Override
|
||||
public void testExecuteTx() {
|
||||
// super.testExecuteTx();
|
||||
}
|
||||
|
||||
@Ignore("pipelined execution is currently not supported with Jedis")
|
||||
@Disabled("pipelined execution is currently not supported with Jedis")
|
||||
@Override
|
||||
public void testExecutePipelined() {
|
||||
// super.testExecutePipelined();
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user