DATAREDIS-348 - Switch to mp911de/lettuce 3.0.

Updated lettuce redis client to latest snapshot, adopt changed API and use API for commands which were emulated using LUA script

Implemente Sentinel support using lettuce library, adopt finer grained exceptions and aligned exception behavior to match other libraries. Added shutdown-timeout property in order to control shutdown duration of the netty framework which reduces test run duration. Documentation updated as well. Contains also a fix to use psetex instead of setex (typo).

Switch to Jedis for Redis Version discovery in tests. Polished documentation. Use LettuceConverter and native time() method.

Original pull request: #144.
Related pull request: #104.
This commit is contained in:
Mark Paluch
2014-09-12 22:28:24 +02:00
committed by Oliver Gierke
parent 4cd6b82e7b
commit 7426b27688
23 changed files with 1237 additions and 200 deletions

View File

@@ -2074,8 +2074,8 @@ public abstract class AbstractConnectionIntegrationTests {
@IfProfileValue(name = "redisVersion", value = "2.8.9+")
public void pfAddShouldAddToNonExistingKeyCorrectly() {
if (!ConnectionUtils.isJedis(connectionFactory)) {
throw new AssumptionViolatedException("PFADD is only available for jedis");
if (!ConnectionUtils.isJedis(connectionFactory) && !ConnectionUtils.isLettuce(connectionFactory)) {
throw new AssumptionViolatedException("PFADD is only available for jedis and lettuce");
}
actual.add(connection.pfAdd("hll", "a", "b", "c"));
@@ -2091,8 +2091,8 @@ public abstract class AbstractConnectionIntegrationTests {
@IfProfileValue(name = "redisVersion", value = "2.8.9+")
public void pfAddShouldReturnZeroWhenValueAlreadyExists() {
if (!ConnectionUtils.isJedis(connectionFactory)) {
throw new AssumptionViolatedException("PFADD is only available for jedis");
if (!ConnectionUtils.isJedis(connectionFactory) && !ConnectionUtils.isLettuce(connectionFactory)) {
throw new AssumptionViolatedException("PFADD is only available for jedis and lettuce");
}
actual.add(connection.pfAdd("hll", "a", "b", "c"));
@@ -2112,8 +2112,8 @@ public abstract class AbstractConnectionIntegrationTests {
@IfProfileValue(name = "redisVersion", value = "2.8.9+")
public void pfCountShouldReturnCorrectly() {
if (!ConnectionUtils.isJedis(connectionFactory)) {
throw new AssumptionViolatedException("PFADD is only available for jedis");
if (!ConnectionUtils.isJedis(connectionFactory) && !ConnectionUtils.isLettuce(connectionFactory)) {
throw new AssumptionViolatedException("PFADD is only available for jedis and lettuce");
}
actual.add(connection.pfAdd("hll", "a", "b", "c"));
@@ -2131,8 +2131,8 @@ public abstract class AbstractConnectionIntegrationTests {
@IfProfileValue(name = "redisVersion", value = "2.8.9+")
public void pfCountWithMultipleKeysShouldReturnCorrectly() {
if (!ConnectionUtils.isJedis(connectionFactory)) {
throw new AssumptionViolatedException("PFADD is only available for jedis");
if (!ConnectionUtils.isJedis(connectionFactory) && !ConnectionUtils.isLettuce(connectionFactory)) {
throw new AssumptionViolatedException("PFADD is only available for jedis and lettuce");
}
actual.add(connection.pfAdd("hll", "a", "b", "c"));
@@ -2152,8 +2152,8 @@ public abstract class AbstractConnectionIntegrationTests {
@IfProfileValue(name = "redisVersion", value = "2.8.9+")
public void pfCountWithNullKeysShouldThrowIllegalArgumentException() {
if (!ConnectionUtils.isJedis(connectionFactory)) {
throw new AssumptionViolatedException("PFADD is only available for jedis");
if (!ConnectionUtils.isJedis(connectionFactory) && !ConnectionUtils.isLettuce(connectionFactory)) {
throw new AssumptionViolatedException("PFADD is only available for jedis and lettuce");
}
actual.add(connection.pfCount((String[]) null));

View File

@@ -46,6 +46,7 @@ public class LettuceConnectionFactoryTests {
public void setUp() {
factory = new LettuceConnectionFactory(SettingsUtils.getHost(), SettingsUtils.getPort());
factory.afterPropertiesSet();
factory.setShutdownTimeout(0);
connection = new DefaultStringRedisConnection(factory.getConnection());
}
@@ -109,6 +110,7 @@ public class LettuceConnectionFactoryTests {
@Test
public void testSelectDb() {
LettuceConnectionFactory factory2 = new LettuceConnectionFactory(SettingsUtils.getHost(), SettingsUtils.getPort());
factory2.setShutdownTimeout(0);
factory2.setDatabase(1);
factory2.afterPropertiesSet();
StringRedisConnection connection2 = new DefaultStringRedisConnection(factory2.getConnection());
@@ -177,7 +179,9 @@ public class LettuceConnectionFactoryTests {
newConnection.close();
}
@Test
public void testGetConnectionException() {
factory.resetConnection();
factory.setHostName("fakeHost");
factory.afterPropertiesSet();
try {
@@ -207,6 +211,7 @@ public class LettuceConnectionFactoryTests {
DefaultLettucePool pool = new DefaultLettucePool(SettingsUtils.getHost(), SettingsUtils.getPort());
pool.afterPropertiesSet();
LettuceConnectionFactory factory2 = new LettuceConnectionFactory(pool);
factory2.setShutdownTimeout(0);
factory2.afterPropertiesSet();
RedisConnection conn2 = factory2.getConnection();
conn2.close();

View File

@@ -16,6 +16,7 @@
package org.springframework.data.redis.connection.lettuce;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;
import static org.junit.Assume.*;
import static org.springframework.data.redis.SpinBarrier.*;
@@ -38,9 +39,12 @@ import org.springframework.data.redis.TestCondition;
import org.springframework.data.redis.connection.AbstractConnectionIntegrationTests;
import org.springframework.data.redis.connection.DefaultStringRedisConnection;
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.util.RedisSentinelRule;
import org.springframework.data.redis.test.util.RelaxedJUnit4ClassRunner;
import org.springframework.data.redis.test.util.RequiresRedisSentinel;
import org.springframework.test.annotation.IfProfileValue;
import org.springframework.test.context.ContextConfiguration;
@@ -133,6 +137,7 @@ public class LettuceConnectionIntegrationTests extends AbstractConnectionIntegra
DefaultLettucePool pool = new DefaultLettucePool(SettingsUtils.getHost(), SettingsUtils.getPort());
pool.afterPropertiesSet();
LettuceConnectionFactory factory2 = new LettuceConnectionFactory(pool);
factory2.setShutdownTimeout(0);
factory2.afterPropertiesSet();
RedisConnection connection = factory2.getConnection();
// Use the connection to make sure the channel is initialized, else nothing happens on close
@@ -170,6 +175,7 @@ public class LettuceConnectionIntegrationTests extends AbstractConnectionIntegra
@Test
public void testCloseNonPooledConnectionNotShared() {
LettuceConnectionFactory factory2 = new LettuceConnectionFactory(SettingsUtils.getHost(), SettingsUtils.getPort());
factory2.setShutdownTimeout(0);
factory2.setShareNativeConnection(false);
factory2.afterPropertiesSet();
RedisConnection connection = factory2.getConnection();
@@ -190,6 +196,7 @@ public class LettuceConnectionIntegrationTests extends AbstractConnectionIntegra
DefaultLettucePool pool = new DefaultLettucePool(SettingsUtils.getHost(), SettingsUtils.getPort());
pool.afterPropertiesSet();
LettuceConnectionFactory factory2 = new LettuceConnectionFactory(pool);
factory2.setShutdownTimeout(0);
factory2.setShareNativeConnection(false);
factory2.afterPropertiesSet();
RedisConnection connection = factory2.getConnection();
@@ -210,6 +217,7 @@ public class LettuceConnectionIntegrationTests extends AbstractConnectionIntegra
DefaultLettucePool pool = new DefaultLettucePool(SettingsUtils.getHost(), SettingsUtils.getPort());
pool.afterPropertiesSet();
LettuceConnectionFactory factory2 = new LettuceConnectionFactory(pool);
factory2.setShutdownTimeout(0);
factory2.setShareNativeConnection(false);
factory2.afterPropertiesSet();
RedisConnection connection = factory2.getConnection();
@@ -224,12 +232,6 @@ public class LettuceConnectionIntegrationTests extends AbstractConnectionIntegra
super.testSelect();
}
@Test(expected = UnsupportedOperationException.class)
@IfProfileValue(name = "redisVersion", value = "2.6+")
public void testSRandMemberCountNegative() {
super.testSRandMemberCountNegative();
}
@Test
@IfProfileValue(name = "runLongTests", value = "true")
public void testScriptKill() throws Exception {
@@ -241,6 +243,7 @@ public class LettuceConnectionIntegrationTests extends AbstractConnectionIntegra
// Use a different factory to get a non-shared native conn for blocking script
final LettuceConnectionFactory factory2 = new LettuceConnectionFactory(SettingsUtils.getHost(),
SettingsUtils.getPort());
factory2.setShutdownTimeout(0);
factory2.afterPropertiesSet();
DefaultStringRedisConnection conn2 = new DefaultStringRedisConnection(factory2.getConnection());
try {
@@ -269,6 +272,7 @@ public class LettuceConnectionIntegrationTests extends AbstractConnectionIntegra
verifyResults(Arrays.asList(new Object[] { true }));
// Lettuce does not support select when using shared conn, use a new conn factory
LettuceConnectionFactory factory2 = new LettuceConnectionFactory();
factory2.setShutdownTimeout(0);
factory2.setDatabase(1);
factory2.afterPropertiesSet();
StringRedisConnection conn2 = new DefaultStringRedisConnection(factory2.getConnection());
@@ -313,7 +317,7 @@ public class LettuceConnectionIntegrationTests extends AbstractConnectionIntegra
assertEquals(Arrays.asList(new Object[] { "key1", "arg1" }),
Arrays.asList(new Object[] { new String(scriptResults.get(0)), new String(scriptResults.get(1)) }));
}
/**
* @see DATAREDIS-106
*/
@@ -323,10 +327,21 @@ public class LettuceConnectionIntegrationTests extends AbstractConnectionIntegra
connection.zAdd("myzset", 1, "one");
connection.zAdd("myzset", 2, "two");
connection.zAdd("myzset", 3, "three");
Set<byte[]> zRangeByScore = connection.zRangeByScore("myzset", "(1", "2");
assertEquals("two", new String(zRangeByScore.iterator().next()));
}
/**
* @see DATAREDIS-348
*/
@Test
@RequiresRedisSentinel(RedisSentinelRule.SentinelsAvailable.ONE_ACTIVE)
public void shouldReturnSentinelCommandsWhenWhenActiveSentinelFound() {
((LettuceConnection) byteConnection).setSentinelConfiguration(new RedisSentinelConfiguration().master("mymaster")
.sentinel("127.0.0.1", 26379).sentinel("127.0.0.1", 26380));
assertThat(connection.getSentinelConnection(), notNullValue());
}
}

View File

@@ -52,12 +52,6 @@ public class LettuceConnectionPipelineIntegrationTests extends AbstractConnectio
super.testSelect();
}
@Test(expected = UnsupportedOperationException.class)
@IfProfileValue(name = "redisVersion", value = "2.6+")
public void testSRandMemberCountNegative() {
super.testSRandMemberCountNegative();
}
@Test
@IfProfileValue(name = "runLongTests", value = "true")
public void testScriptKill() throws Exception {

View File

@@ -25,7 +25,6 @@ import org.springframework.data.redis.connection.AbstractConnectionTransactionIn
import org.springframework.data.redis.connection.DefaultStringRedisConnection;
import org.springframework.data.redis.connection.StringRedisConnection;
import org.springframework.data.redis.test.util.RelaxedJUnit4ClassRunner;
import org.springframework.test.annotation.IfProfileValue;
import org.springframework.test.context.ContextConfiguration;
/**
@@ -39,12 +38,6 @@ import org.springframework.test.context.ContextConfiguration;
@ContextConfiguration("LettuceConnectionIntegrationTests-context.xml")
public class LettuceConnectionTransactionIntegrationTests extends AbstractConnectionTransactionIntegrationTests {
@Test(expected = UnsupportedOperationException.class)
@IfProfileValue(name = "redisVersion", value = "2.6+")
public void testSRandMemberCountNegative() {
super.testSRandMemberCountNegative();
}
@Test
public void testMove() {
connection.set("foo", "bar");

View File

@@ -15,19 +15,23 @@
*/
package org.springframework.data.redis.connection.lettuce;
import static org.mockito.Matchers.*;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.*;
import java.lang.reflect.InvocationTargetException;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
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.lettuce.LettuceConnectionUnitTestSuite.LettuceConnectionUnitTests;
import org.springframework.data.redis.connection.lettuce.LettuceConnectionUnitTestSuite.LettucePipelineConnectionUnitTests;
import com.lambdaworks.redis.RedisAsyncConnection;
import com.lambdaworks.redis.RedisAsyncConnectionImpl;
import com.lambdaworks.redis.RedisClient;
import com.lambdaworks.redis.codec.RedisCodec;
@@ -39,13 +43,13 @@ import com.lambdaworks.redis.codec.RedisCodec;
public class LettuceConnectionUnitTestSuite {
@SuppressWarnings("rawtypes")
public static class LettuceConnectionUnitTests extends AbstractConnectionUnitTestBase<RedisAsyncConnection> {
public static class LettuceConnectionUnitTests extends AbstractConnectionUnitTestBase<RedisAsyncConnectionImpl> {
protected LettuceConnection connection;
@SuppressWarnings({ "unchecked" })
@Before
public void setUp() {
public void setUp() throws InvocationTargetException, IllegalAccessException {
RedisClient clientMock = mock(RedisClient.class);
when(clientMock.connectAsync((RedisCodec) any())).thenReturn(getNativeRedisConnectionMock());
@@ -132,13 +136,21 @@ public class LettuceConnectionUnitTestSuite {
connection.slaveOfNoOne();
verifyNativeConnectionInvocation().slaveofNoOne();
}
/**
* @see DATAREDIS-348
*/
@Test(expected = InvalidDataAccessResourceUsageException.class)
public void shouldThrowExceptionWhenAccessingRedisSentinelsCommandsWhenNoSentinelsConfigured() {
connection.getSentinelConnection();
}
}
public static class LettucePipelineConnectionUnitTests extends LettuceConnectionUnitTests {
@Override
@Before
public void setUp() {
public void setUp() throws InvocationTargetException, IllegalAccessException {
super.setUp();
this.connection.openPipeline();
}

View File

@@ -0,0 +1,217 @@
/*
* Copyright 2014 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
*
* http://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;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.*;
import java.util.List;
import java.util.Map;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.springframework.data.redis.connection.RedisNode;
import org.springframework.data.redis.connection.RedisNode.RedisNodeBuilder;
import org.springframework.data.redis.connection.RedisServer;
import org.springframework.data.redis.connection.jedis.JedisSentinelConnection;
import redis.clients.jedis.Jedis;
import com.lambdaworks.redis.RedisClient;
import com.lambdaworks.redis.RedisFuture;
import com.lambdaworks.redis.RedisSentinelAsyncConnection;
/**
* @author Christoph Strobl
* @author Mark Paluch
*/
@RunWith(MockitoJUnitRunner.class)
public class LettuceSentinelConnectionUnitTests {
public static final String MASTER_ID = "mymaster";
private @Mock RedisClient redisClientMock;
private @Mock RedisSentinelAsyncConnection<String, String> connectionMock;
private @Mock RedisFuture<List<Map<String, String>>> redisFutureMock;
private LettuceSentinelConnection connection;
@Before
public void setUp() {
when(redisClientMock.connectSentinelAsync()).thenReturn(connectionMock);
this.connection = new LettuceSentinelConnection(redisClientMock);
}
/**
* @see DATAREDIS-348
*/
@Test
public void shouldConnectAfterCreation() {
verify(redisClientMock, times(1)).connectSentinelAsync();
}
/**
* @see DATAREDIS-348
*/
@SuppressWarnings("resource")
@Test
public void shouldNotConnectIfAlreadyConnected() {
Jedis yetAnotherJedisMock = mock(Jedis.class);
when(yetAnotherJedisMock.isConnected()).thenReturn(true);
new JedisSentinelConnection(yetAnotherJedisMock);
verify(yetAnotherJedisMock, never()).connect();
}
/**
* @see DATAREDIS-348
*/
@Test
public void failoverShouldBeSentCorrectly() {
connection.failover(new RedisNodeBuilder().withName(MASTER_ID).build());
verify(connectionMock, times(1)).failover(eq(MASTER_ID));
}
/**
* @see DATAREDIS-348
*/
@Test(expected = IllegalArgumentException.class)
public void failoverShouldThrowExceptionIfMasterNodeIsNull() {
connection.failover(null);
}
/**
* @see DATAREDIS-348
*/
@Test(expected = IllegalArgumentException.class)
public void failoverShouldThrowExceptionIfMasterNodeNameIsEmpty() {
connection.failover(new RedisNodeBuilder().build());
}
/**
* @see DATAREDIS-348
*/
@Test
public void mastersShouldReadMastersCorrectly() {
when(connectionMock.masters()).thenReturn(redisFutureMock);
connection.masters();
verify(connectionMock, times(1)).masters();
}
/**
* @see DATAREDIS-348
*/
@Test
public void shouldReadSlavesCorrectly() {
when(connectionMock.slaves(MASTER_ID)).thenReturn(redisFutureMock);
connection.slaves(MASTER_ID);
verify(connectionMock, times(1)).slaves(eq(MASTER_ID));
}
/**
* @see DATAREDIS-348
*/
@Test
public void shouldReadSlavesCorrectlyWhenGivenNamedNode() {
when(connectionMock.slaves(MASTER_ID)).thenReturn(redisFutureMock);
connection.slaves(new RedisNodeBuilder().withName(MASTER_ID).build());
verify(connectionMock, times(1)).slaves(eq(MASTER_ID));
}
/**
* @see DATAREDIS-348
*/
@Test(expected = IllegalArgumentException.class)
public void readSlavesShouldThrowExceptionWhenGivenEmptyMasterName() {
connection.slaves("");
}
/**
* @see DATAREDIS-348
*/
@Test(expected = IllegalArgumentException.class)
public void readSlavesShouldThrowExceptionWhenGivenNull() {
connection.slaves((RedisNode) null);
}
/**
* @see DATAREDIS-348
*/
@Test(expected = IllegalArgumentException.class)
public void readSlavesShouldThrowExceptionWhenNodeWithoutName() {
connection.slaves(new RedisNodeBuilder().build());
}
/**
* @see DATAREDIS-348
*/
@Test
public void shouldRemoveMasterCorrectlyWhenGivenNamedNode() {
connection.remove(new RedisNodeBuilder().withName(MASTER_ID).build());
verify(connectionMock, times(1)).remove(eq(MASTER_ID));
}
/**
* @see DATAREDIS-348
*/
@Test(expected = IllegalArgumentException.class)
public void removeShouldThrowExceptionWhenGivenEmptyMasterName() {
connection.remove("");
}
/**
* @see DATAREDIS-348
*/
@Test(expected = IllegalArgumentException.class)
public void removeShouldThrowExceptionWhenGivenNull() {
connection.remove((RedisNode) null);
}
/**
* @see DATAREDIS-348
*/
@Test(expected = IllegalArgumentException.class)
public void removeShouldThrowExceptionWhenNodeWithoutName() {
connection.remove(new RedisNodeBuilder().build());
}
/**
* @see DATAREDIS-348
*/
@Test
public void monitorShouldBeSentCorrectly() {
RedisServer server = new RedisServer("127.0.0.1", 6382);
server.setName("anothermaster");
server.setQuorum(3L);
connection.monitor(server);
verify(connectionMock, times(1)).monitor(eq("anothermaster"), eq("127.0.0.1"), eq(6382), eq(3));
}
}

View File

@@ -0,0 +1,105 @@
/*
* Copyright 2014 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
*
* http://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;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;
import java.util.Collection;
import java.util.List;
import org.junit.*;
import org.springframework.dao.InvalidDataAccessApiUsageException;
import org.springframework.data.redis.connection.*;
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
import org.springframework.data.redis.test.util.RedisSentinelRule;
import org.springframework.test.annotation.IfProfileValue;
/**
* @author Christoph Strobl
* @author Thomas Darimont
* @author Mark Paluch
*/
public class LettuceSentinelIntegrationTests extends AbstractConnectionIntegrationTests {
private static final String MASTER_NAME = "mymaster";
private static final RedisServer SENTINEL_0 = new RedisServer("127.0.0.1", 26379);
private static final RedisServer SENTINEL_1 = new RedisServer("127.0.0.1", 26380);
private static final RedisServer SLAVE_0 = new RedisServer("127.0.0.1", 6380);
private static final RedisServer SLAVE_1 = new RedisServer("127.0.0.1", 6381);
private static final RedisSentinelConfiguration SENTINEL_CONFIG = new RedisSentinelConfiguration() //
.master(MASTER_NAME)
.sentinel(SENTINEL_0)
.sentinel(SENTINEL_1);
public @Rule RedisSentinelRule sentinelRule = RedisSentinelRule.forConfig(SENTINEL_CONFIG).oneActive();
private static LettuceConnectionFactory lettuceConnectionFactory;
@BeforeClass
public static void beforeClass(){
LettuceConnectionFactory lettuceConnectionFactory = new LettuceConnectionFactory(SENTINEL_CONFIG);
lettuceConnectionFactory.setShareNativeConnection(false);
lettuceConnectionFactory.afterPropertiesSet();
LettuceSentinelIntegrationTests.lettuceConnectionFactory = lettuceConnectionFactory;
}
@AfterClass
public static void afterClass(){
LettuceSentinelIntegrationTests.lettuceConnectionFactory.destroy();
}
@Before
public void setUp() {
connectionFactory = lettuceConnectionFactory;
super.setUp();
}
@After
public void tearDown() {
super.tearDown();
}
/**
* @see DATAREDIS-348
*/
@Test
public void shouldReadMastersCorrectly() {
List<RedisServer> servers = (List<RedisServer>) connectionFactory.getSentinelConnection().masters();
assertThat(servers.size(), is(1));
assertThat(servers.get(0).getName(),is(MASTER_NAME));
}
/**
* @see DATAREDIS-348
*/
@Test
public void shouldReadSlavesOfMastersCorrectly() {
RedisSentinelConnection sentinelConnection = connectionFactory.getSentinelConnection();
List<RedisServer> servers = (List<RedisServer>) sentinelConnection.masters();
assertThat(servers.size(), is(1));
Collection<RedisServer> slaves = sentinelConnection.slaves(servers.get(0));
assertThat(slaves.size(), is(2));
assertThat(slaves, hasItems(SLAVE_0, SLAVE_1));
}
}

View File

@@ -23,6 +23,7 @@ import org.springframework.data.redis.RedisVersionUtils;
import org.springframework.data.redis.SettingsUtils;
import org.springframework.data.redis.Version;
import org.springframework.data.redis.connection.RedisConnection;
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
import org.springframework.test.annotation.IfProfileValue;
import org.springframework.util.StringUtils;
@@ -45,7 +46,7 @@ public class MinimumRedisVersionRule implements TestRule {
private Version readServerVersion() {
LettuceConnectionFactory connectionFactory = new LettuceConnectionFactory();
JedisConnectionFactory connectionFactory = new JedisConnectionFactory();
connectionFactory.setHostName(SettingsUtils.getHost());
connectionFactory.setPort(SettingsUtils.getPort());
connectionFactory.setTimeout(100);