DATAREDIS-842 - Polishing.
Reformat code. Add author tags. Add integration test. Original pull request: #345.
This commit is contained in:
@@ -59,6 +59,7 @@ import org.springframework.test.util.ReflectionTestUtils;
|
||||
* @author Christoph Strobl
|
||||
* @author Mark Paluch
|
||||
* @author Balázs Németh
|
||||
* @author Ruben Cervilla
|
||||
*/
|
||||
public class LettuceConnectionFactoryUnitTests {
|
||||
|
||||
@@ -70,7 +71,7 @@ public class LettuceConnectionFactoryUnitTests {
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
public void tearDown() {
|
||||
ConnectionFactoryTracker.cleanUp();
|
||||
}
|
||||
|
||||
@@ -613,7 +614,8 @@ public class LettuceConnectionFactoryUnitTests {
|
||||
@Test // DATAREDIS-842
|
||||
public void databaseShouldBeSetCorrectlyOnSentinelClient() {
|
||||
|
||||
RedisSentinelConfiguration redisSentinelConfiguration = new RedisSentinelConfiguration("mymaster", Collections.singleton("host:1234"));
|
||||
RedisSentinelConfiguration redisSentinelConfiguration = new RedisSentinelConfiguration("mymaster",
|
||||
Collections.singleton("host:1234"));
|
||||
redisSentinelConfiguration.setDatabase(1);
|
||||
LettuceConnectionFactory connectionFactory = new LettuceConnectionFactory(redisSentinelConfiguration);
|
||||
connectionFactory.setClientResources(getSharedClientResources());
|
||||
|
||||
@@ -35,7 +35,6 @@ 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.SettingsUtils;
|
||||
import org.springframework.data.redis.connection.AbstractConnectionIntegrationTests;
|
||||
import org.springframework.data.redis.connection.DefaultStringRedisConnection;
|
||||
import org.springframework.data.redis.connection.RedisConnection;
|
||||
@@ -62,9 +61,15 @@ public class LettuceSentinelIntegrationTests extends AbstractConnectionIntegrati
|
||||
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() //
|
||||
private static final RedisSentinelConfiguration SENTINEL_CONFIG;
|
||||
static {
|
||||
|
||||
SENTINEL_CONFIG = new RedisSentinelConfiguration() //
|
||||
.master(MASTER_NAME).sentinel(SENTINEL_0).sentinel(SENTINEL_1);
|
||||
|
||||
SENTINEL_CONFIG.setDatabase(5);
|
||||
}
|
||||
|
||||
public static @ClassRule RedisSentinelRule sentinelRule = RedisSentinelRule.forConfig(SENTINEL_CONFIG).oneActive();
|
||||
public @Rule MinimumRedisVersionRule minimumVersionRule = new MinimumRedisVersionRule();
|
||||
|
||||
@@ -124,6 +129,30 @@ public class LettuceSentinelIntegrationTests extends AbstractConnectionIntegrati
|
||||
assertThat(servers.get(0).getName(), is(MASTER_NAME));
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-842
|
||||
public void shouldUseSpecifiedDatabase() {
|
||||
|
||||
RedisConnection connection = connectionFactory.getConnection();
|
||||
|
||||
connection.flushDb();
|
||||
connection.set("foo".getBytes(), "bar".getBytes());
|
||||
connection.close();
|
||||
|
||||
LettuceConnectionFactory connectionFactory = new LettuceConnectionFactory();
|
||||
connectionFactory.setClientResources(LettuceTestClientResources.getSharedClientResources());
|
||||
connectionFactory.setShutdownTimeout(0);
|
||||
connectionFactory.setShareNativeConnection(false);
|
||||
connectionFactory.afterPropertiesSet();
|
||||
|
||||
RedisConnection directConnection = connectionFactory.getConnection();
|
||||
assertThat(directConnection.exists("foo".getBytes()), is(false));
|
||||
directConnection.select(5);
|
||||
|
||||
assertThat(directConnection.exists("foo".getBytes()), is(true));
|
||||
directConnection.close();
|
||||
connectionFactory.destroy();
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-348
|
||||
public void shouldReadSlavesOfMastersCorrectly() {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user