DATAREDIS-528 - Upgrade to Lettuce 4.2.2.
We now support Lettuce 4.2.2.Final. Using Lettuce requires Java 8. Original pull request: #222.
This commit is contained in:
committed by
Mark Paluch
parent
863e5b8d68
commit
4be4ed0b28
@@ -48,6 +48,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import org.hamcrest.core.IsNot;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.internal.AssumptionViolatedException;
|
||||
@@ -575,6 +576,7 @@ public abstract class AbstractConnectionIntegrationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore("DATAREDIS-525")
|
||||
public void testNullKey() throws Exception {
|
||||
try {
|
||||
connection.decr((String) null);
|
||||
@@ -585,7 +587,9 @@ public abstract class AbstractConnectionIntegrationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore("DATAREDIS-525")
|
||||
public void testNullValue() throws Exception {
|
||||
|
||||
byte[] key = UUID.randomUUID().toString().getBytes();
|
||||
connection.append(key, EMPTY_ARRAY);
|
||||
try {
|
||||
@@ -597,7 +601,9 @@ public abstract class AbstractConnectionIntegrationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore("DATAREDIS-525")
|
||||
public void testHashNullKey() throws Exception {
|
||||
|
||||
byte[] key = UUID.randomUUID().toString().getBytes();
|
||||
try {
|
||||
connection.hExists(key, null);
|
||||
@@ -608,6 +614,7 @@ public abstract class AbstractConnectionIntegrationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore("DATAREDIS-525")
|
||||
public void testHashNullValue() throws Exception {
|
||||
byte[] key = UUID.randomUUID().toString().getBytes();
|
||||
byte[] field = "random".getBytes();
|
||||
|
||||
@@ -17,9 +17,10 @@ package org.springframework.data.redis.connection.lettuce;
|
||||
|
||||
import com.lambdaworks.redis.RedisAsyncConnection;
|
||||
import com.lambdaworks.redis.RedisClient;
|
||||
import com.lambdaworks.redis.RedisConnection;
|
||||
import com.lambdaworks.redis.RedisException;
|
||||
import com.lambdaworks.redis.pubsub.RedisPubSubConnection;
|
||||
import com.lambdaworks.redis.api.StatefulRedisConnection;
|
||||
import com.lambdaworks.redis.pubsub.StatefulRedisPubSubConnection;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
@@ -50,8 +51,8 @@ public class AuthenticatingRedisClientTests {
|
||||
|
||||
@Test
|
||||
public void connect() {
|
||||
RedisConnection<String, String> conn = client.connect();
|
||||
conn.ping();
|
||||
StatefulRedisConnection<String, String> conn = client.connect();
|
||||
conn.sync().ping();
|
||||
conn.close();
|
||||
}
|
||||
|
||||
@@ -68,8 +69,8 @@ public class AuthenticatingRedisClientTests {
|
||||
|
||||
@Test
|
||||
public void codecConnect() {
|
||||
RedisConnection<byte[], byte[]> conn = client.connect(LettuceConnection.CODEC);
|
||||
conn.ping();
|
||||
StatefulRedisConnection<byte[], byte[]> conn = client.connect(LettuceConnection.CODEC);
|
||||
conn.sync().ping();
|
||||
conn.close();
|
||||
}
|
||||
|
||||
@@ -89,15 +90,15 @@ public class AuthenticatingRedisClientTests {
|
||||
|
||||
@Test
|
||||
public void connectPubSub() {
|
||||
RedisPubSubConnection<String, String> conn = client.connectPubSub();
|
||||
conn.ping();
|
||||
StatefulRedisPubSubConnection<String, String> conn = client.connectPubSub();
|
||||
conn.sync().ping();
|
||||
conn.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void codecConnectPubSub() {
|
||||
RedisPubSubConnection<byte[], byte[]> conn = client.connectPubSub(LettuceConnection.CODEC);
|
||||
conn.ping();
|
||||
StatefulRedisPubSubConnection<byte[], byte[]> conn = client.connectPubSub(LettuceConnection.CODEC);
|
||||
conn.sync().ping();
|
||||
conn.close();
|
||||
}
|
||||
|
||||
|
||||
@@ -30,9 +30,9 @@ import org.springframework.data.redis.SettingsUtils;
|
||||
import org.springframework.data.redis.connection.PoolException;
|
||||
import org.springframework.data.redis.connection.RedisSentinelConfiguration;
|
||||
|
||||
import com.lambdaworks.redis.RedisAsyncConnection;
|
||||
import com.lambdaworks.redis.RedisException;
|
||||
import com.lambdaworks.redis.RedisURI;
|
||||
import com.lambdaworks.redis.api.StatefulRedisConnection;
|
||||
|
||||
/**
|
||||
* Unit test of {@link DefaultLettucePool}
|
||||
@@ -65,9 +65,9 @@ public class DefaultLettucePoolTests {
|
||||
pool = new DefaultLettucePool(SettingsUtils.getHost(), SettingsUtils.getPort());
|
||||
pool.setClientResources(LettuceTestClientResources.getSharedClientResources());
|
||||
pool.afterPropertiesSet();
|
||||
RedisAsyncConnection<byte[], byte[]> client = pool.getResource();
|
||||
StatefulRedisConnection<byte[], byte[]> client = (StatefulRedisConnection<byte[], byte[]>) pool.getResource();
|
||||
assertNotNull(client);
|
||||
client.ping();
|
||||
client.sync().ping();
|
||||
client.close();
|
||||
}
|
||||
|
||||
@@ -80,7 +80,7 @@ public class DefaultLettucePoolTests {
|
||||
pool = new DefaultLettucePool(SettingsUtils.getHost(), SettingsUtils.getPort(), poolConfig);
|
||||
pool.setClientResources(LettuceTestClientResources.getSharedClientResources());
|
||||
pool.afterPropertiesSet();
|
||||
RedisAsyncConnection<byte[], byte[]> client = pool.getResource();
|
||||
StatefulRedisConnection<byte[], byte[]> client = (StatefulRedisConnection<byte[], byte[]>) pool.getResource();
|
||||
assertNotNull(client);
|
||||
try {
|
||||
pool.getResource();
|
||||
@@ -98,7 +98,7 @@ public class DefaultLettucePoolTests {
|
||||
pool = new DefaultLettucePool(SettingsUtils.getHost(), SettingsUtils.getPort(), poolConfig);
|
||||
pool.setClientResources(LettuceTestClientResources.getSharedClientResources());
|
||||
pool.afterPropertiesSet();
|
||||
RedisAsyncConnection<byte[], byte[]> client = pool.getResource();
|
||||
StatefulRedisConnection<byte[], byte[]> client = (StatefulRedisConnection<byte[], byte[]>) pool.getResource();
|
||||
assertNotNull(client);
|
||||
client.close();
|
||||
}
|
||||
@@ -121,7 +121,7 @@ public class DefaultLettucePoolTests {
|
||||
pool = new DefaultLettucePool(SettingsUtils.getHost(), SettingsUtils.getPort(), poolConfig);
|
||||
pool.setClientResources(LettuceTestClientResources.getSharedClientResources());
|
||||
pool.afterPropertiesSet();
|
||||
RedisAsyncConnection<byte[], byte[]> client = pool.getResource();
|
||||
StatefulRedisConnection<byte[], byte[]> client = (StatefulRedisConnection<byte[], byte[]>) pool.getResource();
|
||||
assertNotNull(client);
|
||||
pool.returnResource(client);
|
||||
assertNotNull(pool.getResource());
|
||||
@@ -137,13 +137,13 @@ public class DefaultLettucePoolTests {
|
||||
pool = new DefaultLettucePool(SettingsUtils.getHost(), SettingsUtils.getPort(), poolConfig);
|
||||
pool.setClientResources(LettuceTestClientResources.getSharedClientResources());
|
||||
pool.afterPropertiesSet();
|
||||
RedisAsyncConnection<byte[], byte[]> client = pool.getResource();
|
||||
StatefulRedisConnection<byte[], byte[]> client = (StatefulRedisConnection<byte[], byte[]>) pool.getResource();
|
||||
assertNotNull(client);
|
||||
pool.returnBrokenResource(client);
|
||||
RedisAsyncConnection<byte[], byte[]> client2 = pool.getResource();
|
||||
StatefulRedisConnection<byte[], byte[]> client2 = (StatefulRedisConnection<byte[], byte[]>) pool.getResource();
|
||||
assertNotSame(client, client2);
|
||||
try {
|
||||
client.ping();
|
||||
client.sync().ping();
|
||||
fail("Broken resouce connection should be closed");
|
||||
} catch (RedisException e) {} finally {
|
||||
client.close();
|
||||
@@ -189,9 +189,9 @@ public class DefaultLettucePoolTests {
|
||||
pool.setClientResources(LettuceTestClientResources.getSharedClientResources());
|
||||
pool.setPassword("foo");
|
||||
pool.afterPropertiesSet();
|
||||
RedisAsyncConnection<byte[], byte[]> conn = pool.getResource();
|
||||
conn.ping();
|
||||
conn.close();
|
||||
StatefulRedisConnection<byte[], byte[]> client = (StatefulRedisConnection<byte[], byte[]>) pool.getResource();
|
||||
client.sync().ping();
|
||||
client.sync().getStatefulConnection().close();
|
||||
}
|
||||
|
||||
@Ignore("Redis must have requirepass set to run this test")
|
||||
|
||||
@@ -42,7 +42,6 @@ import java.util.concurrent.TimeUnit;
|
||||
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.springframework.dao.DataAccessException;
|
||||
@@ -72,8 +71,9 @@ import org.springframework.data.redis.test.util.RedisClusterRule;
|
||||
import org.springframework.test.annotation.IfProfileValue;
|
||||
|
||||
import com.lambdaworks.redis.RedisURI.Builder;
|
||||
import com.lambdaworks.redis.cluster.RedisAdvancedClusterConnection;
|
||||
import com.lambdaworks.redis.api.sync.RedisHLLCommands;
|
||||
import com.lambdaworks.redis.cluster.RedisClusterClient;
|
||||
import com.lambdaworks.redis.cluster.api.sync.RedisAdvancedClusterCommands;
|
||||
|
||||
/**
|
||||
* @author Christoph Strobl
|
||||
@@ -105,7 +105,7 @@ public class LettuceClusterConnectionTests implements ClusterConnectionTests {
|
||||
POINT_PALERMO);
|
||||
|
||||
RedisClusterClient client;
|
||||
RedisAdvancedClusterConnection<String, String> nativeConnection;
|
||||
RedisAdvancedClusterCommands<String, String> nativeConnection;
|
||||
LettuceClusterConnection clusterConnection;
|
||||
|
||||
public static @ClassRule RedisClusterRule clusterAvailable = new RedisClusterRule();
|
||||
@@ -120,7 +120,7 @@ public class LettuceClusterConnectionTests implements ClusterConnectionTests {
|
||||
|
||||
client = RedisClusterClient.create(LettuceTestClientResources.getSharedClientResources(),
|
||||
Builder.redis(CLUSTER_HOST, MASTER_NODE_1_PORT).withTimeout(100, TimeUnit.MILLISECONDS).build());
|
||||
nativeConnection = client.connectCluster();
|
||||
nativeConnection = client.connect().sync();
|
||||
clusterConnection = new LettuceClusterConnection(client);
|
||||
}
|
||||
|
||||
@@ -128,7 +128,7 @@ public class LettuceClusterConnectionTests implements ClusterConnectionTests {
|
||||
public void tearDown() throws InterruptedException {
|
||||
|
||||
clusterConnection.flushDb();
|
||||
nativeConnection.close();
|
||||
nativeConnection.getStatefulConnection().close();
|
||||
clusterConnection.close();
|
||||
client.shutdown(0, 0, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
@@ -2243,7 +2243,7 @@ public class LettuceClusterConnectionTests implements ClusterConnectionTests {
|
||||
|
||||
clusterConnection.pfAdd(KEY_1_BYTES, VALUE_1_BYTES, VALUE_2_BYTES, VALUE_3_BYTES);
|
||||
|
||||
assertThat(nativeConnection.pfcount(KEY_1), is(3L));
|
||||
assertThat(((RedisHLLCommands<String, String>) nativeConnection).pfcount(KEY_1), is(3L));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2252,7 +2252,7 @@ public class LettuceClusterConnectionTests implements ClusterConnectionTests {
|
||||
@Test
|
||||
public void pfCountShouldAllowCountingOnSingleKey() {
|
||||
|
||||
nativeConnection.pfadd(KEY_1, VALUE_1, VALUE_2, VALUE_3);
|
||||
((RedisHLLCommands<String, String>) nativeConnection).pfadd(KEY_1, VALUE_1, VALUE_2, VALUE_3);
|
||||
|
||||
assertThat(clusterConnection.pfCount(KEY_1_BYTES), is(3L));
|
||||
}
|
||||
@@ -2263,8 +2263,8 @@ public class LettuceClusterConnectionTests implements ClusterConnectionTests {
|
||||
@Test
|
||||
public void pfCountShouldAllowCountingOnSameSlotKeys() {
|
||||
|
||||
nativeConnection.pfadd(SAME_SLOT_KEY_1, VALUE_1, VALUE_2);
|
||||
nativeConnection.pfadd(SAME_SLOT_KEY_2, VALUE_2, VALUE_3);
|
||||
((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);
|
||||
|
||||
assertThat(clusterConnection.pfCount(SAME_SLOT_KEY_1_BYTES, SAME_SLOT_KEY_2_BYTES), is(3L));
|
||||
}
|
||||
@@ -2275,8 +2275,8 @@ public class LettuceClusterConnectionTests implements ClusterConnectionTests {
|
||||
@Test(expected = DataAccessException.class)
|
||||
public void pfCountShouldThrowErrorCountingOnDifferentSlotKeys() {
|
||||
|
||||
nativeConnection.pfadd(KEY_1, VALUE_1, VALUE_2);
|
||||
nativeConnection.pfadd(KEY_2, VALUE_2, VALUE_3);
|
||||
((RedisHLLCommands<String, String>) nativeConnection).pfadd(KEY_1, VALUE_1, VALUE_2);
|
||||
((RedisHLLCommands<String, String>) nativeConnection).pfadd(KEY_2, VALUE_2, VALUE_3);
|
||||
|
||||
clusterConnection.pfCount(KEY_1_BYTES, KEY_2_BYTES);
|
||||
}
|
||||
@@ -2287,12 +2287,12 @@ public class LettuceClusterConnectionTests implements ClusterConnectionTests {
|
||||
@Test
|
||||
public void pfMergeShouldWorkWhenAllKeysMapToSameSlot() {
|
||||
|
||||
nativeConnection.pfadd(SAME_SLOT_KEY_1, VALUE_1, VALUE_2);
|
||||
nativeConnection.pfadd(SAME_SLOT_KEY_2, VALUE_2, VALUE_3);
|
||||
((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.pfmerge(SAME_SLOT_KEY_3, SAME_SLOT_KEY_1, SAME_SLOT_KEY_2);
|
||||
((RedisHLLCommands<String, String>) nativeConnection).pfmerge(SAME_SLOT_KEY_3, SAME_SLOT_KEY_1, SAME_SLOT_KEY_2);
|
||||
|
||||
assertThat(nativeConnection.pfcount(SAME_SLOT_KEY_3), is(3L));
|
||||
assertThat(((RedisHLLCommands<String, String>) nativeConnection).pfcount(SAME_SLOT_KEY_3), is(3L));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2558,7 +2558,6 @@ public class LettuceClusterConnectionTests implements ClusterConnectionTests {
|
||||
*/
|
||||
@Test
|
||||
@IfProfileValue(name = "redisVersion", value = "3.2+")
|
||||
@Ignore("see mp911de/lettuce#241")
|
||||
public void geoHash() {
|
||||
|
||||
nativeConnection.geoadd(KEY_1, PALERMO.getPoint().getX(), PALERMO.getPoint().getY(), PALERMO.getName());
|
||||
@@ -2573,7 +2572,6 @@ public class LettuceClusterConnectionTests implements ClusterConnectionTests {
|
||||
*/
|
||||
@Test
|
||||
@IfProfileValue(name = "redisVersion", value = "3.2+")
|
||||
@Ignore("see mp911de/lettuce#241")
|
||||
public void geoHashNonExisting() {
|
||||
|
||||
nativeConnection.geoadd(KEY_1, PALERMO.getPoint().getX(), PALERMO.getPoint().getY(), PALERMO.getName());
|
||||
|
||||
@@ -30,7 +30,6 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
@@ -40,10 +39,10 @@ import org.springframework.data.redis.connection.ClusterNodeResourceProvider;
|
||||
import org.springframework.data.redis.connection.RedisClusterCommands.AddSlots;
|
||||
import org.springframework.data.redis.connection.RedisClusterNode;
|
||||
|
||||
import com.lambdaworks.redis.RedisAsyncConnection;
|
||||
import com.lambdaworks.redis.RedisConnection;
|
||||
import com.lambdaworks.redis.RedisURI;
|
||||
import com.lambdaworks.redis.cluster.RedisClusterClient;
|
||||
import com.lambdaworks.redis.cluster.api.async.RedisClusterAsyncCommands;
|
||||
import com.lambdaworks.redis.cluster.api.sync.RedisClusterCommands;
|
||||
import com.lambdaworks.redis.cluster.models.partitions.Partitions;
|
||||
import com.lambdaworks.redis.cluster.models.partitions.RedisClusterNode.NodeFlag;
|
||||
|
||||
@@ -65,10 +64,10 @@ public class LettuceClusterConnectionUnitTests {
|
||||
@Mock RedisClusterClient clusterMock;
|
||||
|
||||
@Mock ClusterNodeResourceProvider resourceProvider;
|
||||
@Mock RedisAsyncConnection<byte[], byte[]> dedicatedConnectionMock;
|
||||
@Mock RedisConnection<byte[], byte[]> clusterConnection1Mock;
|
||||
@Mock RedisConnection<byte[], byte[]> clusterConnection2Mock;
|
||||
@Mock RedisConnection<byte[], byte[]> clusterConnection3Mock;
|
||||
@Mock RedisClusterAsyncCommands<byte[], byte[]> dedicatedConnectionMock;
|
||||
@Mock RedisClusterCommands<byte[], byte[]> clusterConnection1Mock;
|
||||
@Mock RedisClusterCommands<byte[], byte[]> clusterConnection2Mock;
|
||||
@Mock RedisClusterCommands<byte[], byte[]> clusterConnection3Mock;
|
||||
|
||||
LettuceClusterConnection connection;
|
||||
|
||||
@@ -112,7 +111,7 @@ public class LettuceClusterConnectionUnitTests {
|
||||
connection = new LettuceClusterConnection(clusterMock, executor) {
|
||||
|
||||
@Override
|
||||
protected RedisAsyncConnection<byte[], byte[]> getAsyncDedicatedConnection() {
|
||||
protected RedisClusterAsyncCommands<byte[], byte[]> getAsyncDedicatedConnection() {
|
||||
return dedicatedConnectionMock;
|
||||
}
|
||||
|
||||
@@ -139,12 +138,12 @@ public class LettuceClusterConnectionUnitTests {
|
||||
|
||||
connection.clusterMeet(UNKNOWN_CLUSTER_NODE);
|
||||
|
||||
verify(clusterConnection1Mock, times(1))
|
||||
.clusterMeet(UNKNOWN_CLUSTER_NODE.getHost(), UNKNOWN_CLUSTER_NODE.getPort());
|
||||
verify(clusterConnection2Mock, times(1))
|
||||
.clusterMeet(UNKNOWN_CLUSTER_NODE.getHost(), UNKNOWN_CLUSTER_NODE.getPort());
|
||||
verify(clusterConnection3Mock, times(1))
|
||||
.clusterMeet(UNKNOWN_CLUSTER_NODE.getHost(), UNKNOWN_CLUSTER_NODE.getPort());
|
||||
verify(clusterConnection1Mock, times(1)).clusterMeet(UNKNOWN_CLUSTER_NODE.getHost(),
|
||||
UNKNOWN_CLUSTER_NODE.getPort());
|
||||
verify(clusterConnection2Mock, times(1)).clusterMeet(UNKNOWN_CLUSTER_NODE.getHost(),
|
||||
UNKNOWN_CLUSTER_NODE.getPort());
|
||||
verify(clusterConnection3Mock, times(1)).clusterMeet(UNKNOWN_CLUSTER_NODE.getHost(),
|
||||
UNKNOWN_CLUSTER_NODE.getPort());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -210,9 +209,9 @@ public class LettuceClusterConnectionUnitTests {
|
||||
@Test
|
||||
public void keysShouldBeRunOnAllClusterNodes() {
|
||||
|
||||
when(clusterConnection1Mock.keys(any(byte[].class))).thenReturn(Collections.<byte[]> emptyList());
|
||||
when(clusterConnection2Mock.keys(any(byte[].class))).thenReturn(Collections.<byte[]> emptyList());
|
||||
when(clusterConnection3Mock.keys(any(byte[].class))).thenReturn(Collections.<byte[]> emptyList());
|
||||
when(clusterConnection1Mock.keys(any(byte[].class))).thenReturn(Collections.<byte[]>emptyList());
|
||||
when(clusterConnection2Mock.keys(any(byte[].class))).thenReturn(Collections.<byte[]>emptyList());
|
||||
when(clusterConnection3Mock.keys(any(byte[].class))).thenReturn(Collections.<byte[]>emptyList());
|
||||
|
||||
byte[] pattern = LettuceConverters.toBytes("*");
|
||||
|
||||
@@ -229,7 +228,7 @@ public class LettuceClusterConnectionUnitTests {
|
||||
@Test
|
||||
public void keysShouldOnlyBeRunOnDedicatedNodeWhenPinned() {
|
||||
|
||||
when(clusterConnection2Mock.keys(any(byte[].class))).thenReturn(Collections.<byte[]> emptyList());
|
||||
when(clusterConnection2Mock.keys(any(byte[].class))).thenReturn(Collections.<byte[]>emptyList());
|
||||
|
||||
byte[] pattern = LettuceConverters.toBytes("*");
|
||||
|
||||
|
||||
@@ -33,8 +33,8 @@ import org.springframework.data.redis.connection.DefaultStringRedisConnection;
|
||||
import org.springframework.data.redis.connection.RedisConnection;
|
||||
import org.springframework.data.redis.connection.StringRedisConnection;
|
||||
|
||||
import com.lambdaworks.redis.RedisAsyncConnection;
|
||||
import com.lambdaworks.redis.RedisException;
|
||||
import com.lambdaworks.redis.api.async.RedisAsyncCommands;
|
||||
|
||||
/**
|
||||
* Integration test of {@link LettuceConnectionFactory}
|
||||
@@ -79,8 +79,8 @@ public class LettuceConnectionFactoryTests {
|
||||
public void testGetNewConnectionOnError() throws Exception {
|
||||
factory.setValidateConnection(true);
|
||||
connection.lPush("alist", "baz");
|
||||
RedisAsyncConnection nativeConn = (RedisAsyncConnection) connection.getNativeConnection();
|
||||
nativeConn.close();
|
||||
RedisAsyncCommands nativeConn = (RedisAsyncCommands) connection.getNativeConnection();
|
||||
nativeConn.getStatefulConnection().close();
|
||||
// Give some time for async channel close
|
||||
Thread.sleep(500);
|
||||
connection.bLPop(1, "alist".getBytes());
|
||||
@@ -101,7 +101,7 @@ public class LettuceConnectionFactoryTests {
|
||||
@Test
|
||||
public void testConnectionErrorNoValidate() throws Exception {
|
||||
connection.lPush("ablist", "baz");
|
||||
((RedisAsyncConnection) connection.getNativeConnection()).close();
|
||||
((RedisAsyncCommands) connection.getNativeConnection()).getStatefulConnection().close();
|
||||
// Give some time for async channel close
|
||||
Thread.sleep(500);
|
||||
DefaultStringRedisConnection conn2 = new DefaultStringRedisConnection(factory.getConnection());
|
||||
@@ -159,7 +159,7 @@ public class LettuceConnectionFactoryTests {
|
||||
// Give some time for native connection to asynchronously close
|
||||
Thread.sleep(100);
|
||||
try {
|
||||
((RedisAsyncConnection<byte[], byte[]>) conn2.getNativeConnection()).ping();
|
||||
((RedisAsyncCommands<byte[], byte[]>) conn2.getNativeConnection()).ping();
|
||||
fail("The native connection should be closed");
|
||||
} catch (RedisException e) {
|
||||
// expected
|
||||
@@ -169,17 +169,17 @@ public class LettuceConnectionFactoryTests {
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void testResetConnection() {
|
||||
RedisAsyncConnection<byte[], byte[]> nativeConn = (RedisAsyncConnection<byte[], byte[]>) connection
|
||||
RedisAsyncCommands<byte[], byte[]> nativeConn = (RedisAsyncCommands<byte[], byte[]>) connection
|
||||
.getNativeConnection();
|
||||
factory.resetConnection();
|
||||
assertNotSame(nativeConn, factory.getConnection().getNativeConnection());
|
||||
nativeConn.close();
|
||||
nativeConn.getStatefulConnection().close();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void testInitConnection() {
|
||||
RedisAsyncConnection<byte[], byte[]> nativeConn = (RedisAsyncConnection<byte[], byte[]>) connection
|
||||
RedisAsyncCommands<byte[], byte[]> nativeConn = (RedisAsyncCommands<byte[], byte[]>) connection
|
||||
.getNativeConnection();
|
||||
factory.initConnection();
|
||||
RedisConnection newConnection = factory.getConnection();
|
||||
@@ -190,7 +190,7 @@ public class LettuceConnectionFactoryTests {
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void testResetAndInitConnection() {
|
||||
RedisAsyncConnection<byte[], byte[]> nativeConn = (RedisAsyncConnection<byte[], byte[]>) connection
|
||||
RedisAsyncCommands<byte[], byte[]> nativeConn = (RedisAsyncCommands<byte[], byte[]>) connection
|
||||
.getNativeConnection();
|
||||
factory.resetConnection();
|
||||
factory.initConnection();
|
||||
|
||||
@@ -49,7 +49,7 @@ import org.springframework.data.redis.test.util.RequiresRedisSentinel;
|
||||
import org.springframework.test.annotation.IfProfileValue;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
|
||||
import com.lambdaworks.redis.RedisAsyncConnection;
|
||||
import com.lambdaworks.redis.api.async.RedisAsyncCommands;
|
||||
|
||||
/**
|
||||
* Integration test of {@link LettuceConnection}
|
||||
@@ -210,7 +210,7 @@ public class LettuceConnectionIntegrationTests extends AbstractConnectionIntegra
|
||||
RedisConnection connection = factory2.getConnection();
|
||||
// Use the connection to make sure the channel is initialized, else nothing happens on close
|
||||
connection.ping();
|
||||
((RedisAsyncConnection) connection.getNativeConnection()).close();
|
||||
((RedisAsyncCommands) connection.getNativeConnection()).getStatefulConnection().close();
|
||||
try {
|
||||
connection.ping();
|
||||
fail("Exception should be thrown trying to use a closed connection");
|
||||
@@ -351,8 +351,8 @@ public class LettuceConnectionIntegrationTests extends AbstractConnectionIntegra
|
||||
@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));
|
||||
((LettuceConnection) byteConnection).setSentinelConfiguration(
|
||||
new RedisSentinelConfiguration().master("mymaster").sentinel("127.0.0.1", 26379).sentinel("127.0.0.1", 26380));
|
||||
assertThat(connection.getSentinelConnection(), notNullValue());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,6 @@ import static org.junit.Assert.*;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.data.redis.connection.AbstractConnectionTransactionIntegrationTests;
|
||||
@@ -67,84 +66,4 @@ public class LettuceConnectionTransactionIntegrationTests extends AbstractConnec
|
||||
public void testSelect() {
|
||||
super.testSelect();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATAREDIS-438
|
||||
*/
|
||||
@Test
|
||||
@Override
|
||||
@Ignore("see mp911de/lettuce#241")
|
||||
public void geoPosition() {
|
||||
super.geoPosition();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATAREDIS-438
|
||||
*/
|
||||
@Test
|
||||
@Override
|
||||
@Ignore("see mp911de/lettuce#241")
|
||||
public void geoPositionNonExisting() {
|
||||
super.geoPositionNonExisting();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATAREDIS-438
|
||||
*/
|
||||
@Test
|
||||
@Override
|
||||
@Ignore("see mp911de/lettuce#241")
|
||||
public void geoRadiusByMemberShouldApplyLimit() {
|
||||
super.geoRadiusByMemberShouldApplyLimit();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATAREDIS-438
|
||||
*/
|
||||
@Test
|
||||
@Override
|
||||
@Ignore("see mp911de/lettuce#241")
|
||||
public void geoRadiusByMemberShouldReturnDistanceCorrectly() {
|
||||
super.geoRadiusByMemberShouldReturnDistanceCorrectly();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATAREDIS-438
|
||||
*/
|
||||
@Test
|
||||
@Override
|
||||
@Ignore("see mp911de/lettuce#241")
|
||||
public void geoRadiusByMemberShouldReturnMembersCorrectly() {
|
||||
super.geoRadiusByMemberShouldReturnMembersCorrectly();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATAREDIS-438
|
||||
*/
|
||||
@Test
|
||||
@Override
|
||||
@Ignore("see mp911de/lettuce#241")
|
||||
public void geoRadiusShouldApplyLimit() {
|
||||
super.geoRadiusShouldApplyLimit();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATAREDIS-438
|
||||
*/
|
||||
@Test
|
||||
@Override
|
||||
@Ignore("see mp911de/lettuce#")
|
||||
public void geoRadiusShouldReturnDistanceCorrectly() {
|
||||
super.geoRadiusShouldReturnDistanceCorrectly();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATAREDIS-438
|
||||
*/
|
||||
@Test
|
||||
@Override
|
||||
@Ignore("see mp911de/lettuce#241")
|
||||
public void geoRadiusShouldReturnMembersCorrectly() {
|
||||
super.geoRadiusShouldReturnMembersCorrectly();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,7 +15,8 @@
|
||||
*/
|
||||
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;
|
||||
@@ -30,8 +31,10 @@ import org.springframework.data.redis.connection.RedisServerCommands.ShutdownOpt
|
||||
import org.springframework.data.redis.connection.lettuce.LettuceConnectionUnitTestSuite.LettuceConnectionUnitTests;
|
||||
import org.springframework.data.redis.connection.lettuce.LettuceConnectionUnitTestSuite.LettucePipelineConnectionUnitTests;
|
||||
|
||||
import com.lambdaworks.redis.RedisAsyncConnectionImpl;
|
||||
import com.lambdaworks.redis.RedisClient;
|
||||
import com.lambdaworks.redis.api.StatefulRedisConnection;
|
||||
import com.lambdaworks.redis.api.async.RedisAsyncCommands;
|
||||
import com.lambdaworks.redis.api.sync.RedisCommands;
|
||||
import com.lambdaworks.redis.codec.RedisCodec;
|
||||
|
||||
/**
|
||||
@@ -43,17 +46,27 @@ import com.lambdaworks.redis.codec.RedisCodec;
|
||||
public class LettuceConnectionUnitTestSuite {
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
public static class LettuceConnectionUnitTests extends AbstractConnectionUnitTestBase<RedisAsyncConnectionImpl> {
|
||||
public static class LettuceConnectionUnitTests extends AbstractConnectionUnitTestBase<RedisAsyncCommands> {
|
||||
|
||||
protected LettuceConnection connection;
|
||||
private RedisClient clientMock;
|
||||
protected StatefulRedisConnection<byte[], byte[]> statefulConnectionMock;
|
||||
protected RedisAsyncCommands<byte[], byte[]> asyncCommandsMock;
|
||||
protected RedisCommands syncCommandsMock;
|
||||
|
||||
@SuppressWarnings({ "unchecked" })
|
||||
@Before
|
||||
public void setUp() throws InvocationTargetException, IllegalAccessException {
|
||||
|
||||
clientMock = mock(RedisClient.class);
|
||||
when(clientMock.connectAsync((RedisCodec) any())).thenReturn(getNativeRedisConnectionMock());
|
||||
statefulConnectionMock = mock(StatefulRedisConnection.class);
|
||||
when(clientMock.connect((RedisCodec) any())).thenReturn(statefulConnectionMock);
|
||||
|
||||
asyncCommandsMock = getNativeRedisConnectionMock();
|
||||
syncCommandsMock = mock(RedisCommands.class);
|
||||
|
||||
when(statefulConnectionMock.async()).thenReturn(getNativeRedisConnectionMock());
|
||||
when(statefulConnectionMock.sync()).thenReturn(syncCommandsMock);
|
||||
connection = new LettuceConnection(0, clientMock);
|
||||
}
|
||||
|
||||
@@ -61,10 +74,10 @@ public class LettuceConnectionUnitTestSuite {
|
||||
* @see DATAREDIS-184
|
||||
*/
|
||||
@Test
|
||||
public void shutdownWithNullOpionsIsCalledCorrectly() {
|
||||
public void shutdownWithNullOptionsIsCalledCorrectly() {
|
||||
|
||||
connection.shutdown(null);
|
||||
verifyNativeConnectionInvocation().shutdown(true);
|
||||
verify(syncCommandsMock, times(1)).shutdown(true);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -74,7 +87,7 @@ public class LettuceConnectionUnitTestSuite {
|
||||
public void shutdownWithNosaveOptionIsCalledCorrectly() {
|
||||
|
||||
connection.shutdown(ShutdownOption.NOSAVE);
|
||||
verifyNativeConnectionInvocation().shutdown(false);
|
||||
verify(syncCommandsMock, times(1)).shutdown(false);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -84,7 +97,7 @@ public class LettuceConnectionUnitTestSuite {
|
||||
public void shutdownWithSaveOptionIsCalledCorrectly() {
|
||||
|
||||
connection.shutdown(ShutdownOption.SAVE);
|
||||
verifyNativeConnectionInvocation().shutdown(true);
|
||||
verify(syncCommandsMock, times(1)).shutdown(true);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -95,7 +108,7 @@ public class LettuceConnectionUnitTestSuite {
|
||||
|
||||
String ipPort = "127.0.0.1:1001";
|
||||
connection.killClient("127.0.0.1", 1001);
|
||||
verifyNativeConnectionInvocation().clientKill(eq(ipPort));
|
||||
verify(syncCommandsMock, times(1)).clientKill(eq(ipPort));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -105,7 +118,7 @@ public class LettuceConnectionUnitTestSuite {
|
||||
public void getClientNameShouldSendRequestCorrectly() {
|
||||
|
||||
connection.getClientName();
|
||||
verifyNativeConnectionInvocation().clientGetname();
|
||||
verify(syncCommandsMock, times(1)).clientGetname();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -123,7 +136,7 @@ public class LettuceConnectionUnitTestSuite {
|
||||
public void slaveOfShouldBeSentCorrectly() {
|
||||
|
||||
connection.slaveOf("127.0.0.1", 1001);
|
||||
verifyNativeConnectionInvocation().slaveof(eq("127.0.0.1"), eq(1001));
|
||||
verify(syncCommandsMock, times(1)).slaveof(eq("127.0.0.1"), eq(1001));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -133,7 +146,7 @@ public class LettuceConnectionUnitTestSuite {
|
||||
public void slaveOfNoOneShouldBeSentCorrectly() {
|
||||
|
||||
connection.slaveOfNoOne();
|
||||
verifyNativeConnectionInvocation().slaveofNoOne();
|
||||
verify(syncCommandsMock, times(1)).slaveofNoOne();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -148,12 +161,12 @@ public class LettuceConnectionUnitTestSuite {
|
||||
* @see DATAREDIS-431
|
||||
*/
|
||||
@Test
|
||||
public void dbIndexShouldBeSetWhenOptainingConnection() {
|
||||
public void dbIndexShouldBeSetWhenObtainingConnection() {
|
||||
|
||||
connection = new LettuceConnection(null, 0, clientMock, null, 1);
|
||||
connection.getNativeConnection();
|
||||
|
||||
verify(getNativeRedisConnectionMock(), times(1)).select(1);
|
||||
verify(syncCommandsMock, times(1)).select(1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -165,6 +178,76 @@ public class LettuceConnectionUnitTestSuite {
|
||||
super.setUp();
|
||||
this.connection.openPipeline();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATAREDIS-528
|
||||
*/
|
||||
@Test
|
||||
public void shutdownWithSaveOptionIsCalledCorrectly() {
|
||||
|
||||
connection.shutdown(ShutdownOption.SAVE);
|
||||
verify(asyncCommandsMock, times(1)).shutdown(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATAREDIS-528
|
||||
*/
|
||||
@Test
|
||||
public void shutdownWithNosaveOptionIsCalledCorrectly() {
|
||||
|
||||
connection.shutdown(ShutdownOption.NOSAVE);
|
||||
verify(asyncCommandsMock, times(1)).shutdown(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATAREDIS-528
|
||||
*/
|
||||
@Test
|
||||
public void slaveOfShouldBeSentCorrectly() {
|
||||
|
||||
connection.slaveOf("127.0.0.1", 1001);
|
||||
verify(asyncCommandsMock, times(1)).slaveof(eq("127.0.0.1"), eq(1001));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATAREDIS-528
|
||||
*/
|
||||
@Test
|
||||
public void shutdownWithNullOptionsIsCalledCorrectly() {
|
||||
|
||||
connection.shutdown(null);
|
||||
verify(asyncCommandsMock, times(1)).shutdown(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATAREDIS-528
|
||||
*/
|
||||
@Test
|
||||
public void killClientShouldDelegateCallCorrectly() {
|
||||
|
||||
String ipPort = "127.0.0.1:1001";
|
||||
connection.killClient("127.0.0.1", 1001);
|
||||
verify(asyncCommandsMock, times(1)).clientKill(eq(ipPort));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATAREDIS-528
|
||||
*/
|
||||
@Test
|
||||
public void slaveOfNoOneShouldBeSentCorrectly() {
|
||||
|
||||
connection.slaveOfNoOne();
|
||||
verify(asyncCommandsMock, times(1)).slaveofNoOne();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATAREDIS-528
|
||||
*/
|
||||
@Test
|
||||
public void getClientNameShouldSendRequestCorrectly() {
|
||||
|
||||
connection.getClientName();
|
||||
verify(asyncCommandsMock, times(1)).clientGetname();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,9 +37,9 @@ import org.springframework.data.redis.core.types.Expiration;
|
||||
import org.springframework.data.redis.core.types.RedisClientInfo;
|
||||
|
||||
import com.lambdaworks.redis.RedisURI;
|
||||
import com.lambdaworks.redis.SetArgs;
|
||||
import com.lambdaworks.redis.cluster.models.partitions.Partitions;
|
||||
import com.lambdaworks.redis.cluster.models.partitions.RedisClusterNode.NodeFlag;
|
||||
import com.lambdaworks.redis.protocol.SetArgs;
|
||||
|
||||
/**
|
||||
* @author Christoph Strobl
|
||||
@@ -53,7 +53,7 @@ public class LettuceConvertersUnitTests {
|
||||
*/
|
||||
@Test
|
||||
public void convertingEmptyStringToListOfRedisClientInfoShouldReturnEmptyList() {
|
||||
assertThat(LettuceConverters.toListOfRedisClientInformation(""), equalTo(Collections.<RedisClientInfo> emptyList()));
|
||||
assertThat(LettuceConverters.toListOfRedisClientInformation(""), equalTo(Collections.<RedisClientInfo>emptyList()));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -62,7 +62,7 @@ public class LettuceConvertersUnitTests {
|
||||
@Test
|
||||
public void convertingNullToListOfRedisClientInfoShouldReturnEmptyList() {
|
||||
assertThat(LettuceConverters.toListOfRedisClientInformation(null),
|
||||
equalTo(Collections.<RedisClientInfo> emptyList()));
|
||||
equalTo(Collections.<RedisClientInfo>emptyList()));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -100,7 +100,7 @@ public class LettuceConvertersUnitTests {
|
||||
partition.setConnected(true);
|
||||
partition.setFlags(new HashSet<NodeFlag>(Arrays.asList(NodeFlag.MASTER, NodeFlag.MYSELF)));
|
||||
partition.setUri(RedisURI.create("redis://" + CLUSTER_HOST + ":" + MASTER_NODE_1_PORT));
|
||||
partition.setSlots(Arrays.<Integer> asList(1, 2, 3, 4, 5));
|
||||
partition.setSlots(Arrays.<Integer>asList(1, 2, 3, 4, 5));
|
||||
|
||||
partitions.addPartition(partition);
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@ package org.springframework.data.redis.connection.lettuce;
|
||||
import static org.mockito.Matchers.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -32,7 +33,8 @@ import org.springframework.data.redis.connection.RedisServer;
|
||||
|
||||
import com.lambdaworks.redis.RedisClient;
|
||||
import com.lambdaworks.redis.RedisFuture;
|
||||
import com.lambdaworks.redis.RedisSentinelAsyncConnection;
|
||||
import com.lambdaworks.redis.sentinel.api.StatefulRedisSentinelConnection;
|
||||
import com.lambdaworks.redis.sentinel.api.sync.RedisSentinelCommands;
|
||||
|
||||
/**
|
||||
* @author Christoph Strobl
|
||||
@@ -45,7 +47,8 @@ public class LettuceSentinelConnectionUnitTests {
|
||||
|
||||
private @Mock RedisClient redisClientMock;
|
||||
|
||||
private @Mock RedisSentinelAsyncConnection<String, String> connectionMock;
|
||||
private @Mock StatefulRedisSentinelConnection<String, String> connectionMock;
|
||||
private @Mock RedisSentinelCommands<String, String> sentinelCommandsMock;
|
||||
|
||||
private @Mock RedisFuture<List<Map<String, String>>> redisFutureMock;
|
||||
|
||||
@@ -54,7 +57,8 @@ public class LettuceSentinelConnectionUnitTests {
|
||||
@Before
|
||||
public void setUp() {
|
||||
|
||||
when(redisClientMock.connectSentinelAsync()).thenReturn(connectionMock);
|
||||
when(redisClientMock.connectSentinel()).thenReturn(connectionMock);
|
||||
when(connectionMock.sync()).thenReturn(sentinelCommandsMock);
|
||||
this.connection = new LettuceSentinelConnection(redisClientMock);
|
||||
}
|
||||
|
||||
@@ -63,7 +67,7 @@ public class LettuceSentinelConnectionUnitTests {
|
||||
*/
|
||||
@Test
|
||||
public void shouldConnectAfterCreation() {
|
||||
verify(redisClientMock, times(1)).connectSentinelAsync();
|
||||
verify(redisClientMock, times(1)).connectSentinel();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -73,7 +77,7 @@ public class LettuceSentinelConnectionUnitTests {
|
||||
public void failoverShouldBeSentCorrectly() {
|
||||
|
||||
connection.failover(new RedisNodeBuilder().withName(MASTER_ID).build());
|
||||
verify(connectionMock, times(1)).failover(eq(MASTER_ID));
|
||||
verify(sentinelCommandsMock, times(1)).failover(eq(MASTER_ID));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -98,9 +102,9 @@ public class LettuceSentinelConnectionUnitTests {
|
||||
@Test
|
||||
public void mastersShouldReadMastersCorrectly() {
|
||||
|
||||
when(connectionMock.masters()).thenReturn(redisFutureMock);
|
||||
when(sentinelCommandsMock.masters()).thenReturn(Collections.<Map<String, String>>emptyList());
|
||||
connection.masters();
|
||||
verify(connectionMock, times(1)).masters();
|
||||
verify(sentinelCommandsMock, times(1)).masters();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -109,9 +113,9 @@ public class LettuceSentinelConnectionUnitTests {
|
||||
@Test
|
||||
public void shouldReadSlavesCorrectly() {
|
||||
|
||||
when(connectionMock.slaves(MASTER_ID)).thenReturn(redisFutureMock);
|
||||
when(sentinelCommandsMock.slaves(MASTER_ID)).thenReturn(Collections.<Map<String, String>>emptyList());
|
||||
connection.slaves(MASTER_ID);
|
||||
verify(connectionMock, times(1)).slaves(eq(MASTER_ID));
|
||||
verify(sentinelCommandsMock, times(1)).slaves(eq(MASTER_ID));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -120,9 +124,9 @@ public class LettuceSentinelConnectionUnitTests {
|
||||
@Test
|
||||
public void shouldReadSlavesCorrectlyWhenGivenNamedNode() {
|
||||
|
||||
when(connectionMock.slaves(MASTER_ID)).thenReturn(redisFutureMock);
|
||||
when(sentinelCommandsMock.slaves(MASTER_ID)).thenReturn(Collections.<Map<String, String>>emptyList());
|
||||
connection.slaves(new RedisNodeBuilder().withName(MASTER_ID).build());
|
||||
verify(connectionMock, times(1)).slaves(eq(MASTER_ID));
|
||||
verify(sentinelCommandsMock, times(1)).slaves(eq(MASTER_ID));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -156,7 +160,7 @@ public class LettuceSentinelConnectionUnitTests {
|
||||
public void shouldRemoveMasterCorrectlyWhenGivenNamedNode() {
|
||||
|
||||
connection.remove(new RedisNodeBuilder().withName(MASTER_ID).build());
|
||||
verify(connectionMock, times(1)).remove(eq(MASTER_ID));
|
||||
verify(sentinelCommandsMock, times(1)).remove(eq(MASTER_ID));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -194,7 +198,6 @@ public class LettuceSentinelConnectionUnitTests {
|
||||
server.setQuorum(3L);
|
||||
|
||||
connection.monitor(server);
|
||||
verify(connectionMock, times(1)).monitor(eq("anothermaster"), eq("127.0.0.1"), eq(6382), eq(3));
|
||||
verify(sentinelCommandsMock, times(1)).monitor(eq("anothermaster"), eq("127.0.0.1"), eq(6382), eq(3));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -124,24 +124,4 @@ public class LettuceSentinelIntegrationTests extends AbstractConnectionIntegrati
|
||||
connection.close();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATAREDIS-438
|
||||
*/
|
||||
@Test
|
||||
@Override
|
||||
@Ignore("see mp911de/lettuce#241")
|
||||
public void geoHash() {
|
||||
super.geoHash();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATAREDIS-438
|
||||
*/
|
||||
@Test
|
||||
@Override
|
||||
@Ignore("see mp911de/lettuce#241")
|
||||
public void geoHashNonExisting() {
|
||||
super.geoHashNonExisting();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,14 +15,10 @@
|
||||
*/
|
||||
package org.springframework.data.redis.connection.lettuce;
|
||||
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.any;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.Matchers.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import org.junit.Before;
|
||||
@@ -31,7 +27,8 @@ import org.mockito.Mockito;
|
||||
import org.springframework.data.redis.connection.MessageListener;
|
||||
import org.springframework.data.redis.connection.RedisInvalidSubscriptionException;
|
||||
|
||||
import com.lambdaworks.redis.pubsub.RedisPubSubConnection;
|
||||
import com.lambdaworks.redis.pubsub.StatefulRedisPubSubConnection;
|
||||
import com.lambdaworks.redis.pubsub.api.sync.RedisPubSubCommands;
|
||||
|
||||
/**
|
||||
* Unit test of {@link LettuceSubscription}
|
||||
@@ -42,15 +39,21 @@ public class LettuceSubscriptionTests {
|
||||
|
||||
private LettuceSubscription subscription;
|
||||
|
||||
RedisPubSubConnection<byte[], byte[]> pubsub;
|
||||
StatefulRedisPubSubConnection<byte[], byte[]> pubsub;
|
||||
|
||||
private MessageListener listener;
|
||||
|
||||
private RedisPubSubCommands<byte[], byte[]> asyncCommands;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Before
|
||||
public void setUp() {
|
||||
pubsub = Mockito.mock(RedisPubSubConnection.class);
|
||||
|
||||
pubsub = Mockito.mock(StatefulRedisPubSubConnection.class);
|
||||
listener = Mockito.mock(MessageListener.class);
|
||||
asyncCommands = Mockito.mock(RedisPubSubCommands.class);
|
||||
|
||||
Mockito.when(pubsub.sync()).thenReturn(asyncCommands);
|
||||
subscription = new LettuceSubscription(listener, pubsub);
|
||||
}
|
||||
|
||||
@@ -58,9 +61,9 @@ public class LettuceSubscriptionTests {
|
||||
public void testUnsubscribeAllAndClose() {
|
||||
subscription.subscribe(new byte[][] { "a".getBytes() });
|
||||
subscription.unsubscribe();
|
||||
verify(pubsub, times(1)).unsubscribe(new byte[][] { "a".getBytes() });
|
||||
verify(pubsub, never()).unsubscribe(new byte[0]);
|
||||
verify(pubsub, never()).punsubscribe(new byte[0]);
|
||||
verify(asyncCommands, times(1)).unsubscribe(new byte[][] { "a".getBytes() });
|
||||
verify(asyncCommands, never()).unsubscribe(new byte[0]);
|
||||
verify(asyncCommands, never()).punsubscribe(new byte[0]);
|
||||
verify(pubsub).close();
|
||||
verify(pubsub).removeListener(any(LettuceMessageListener.class));
|
||||
assertFalse(subscription.isAlive());
|
||||
@@ -73,9 +76,9 @@ public class LettuceSubscriptionTests {
|
||||
subscription.subscribe(new byte[][] { "a".getBytes() });
|
||||
subscription.pSubscribe(new byte[][] { "s*".getBytes() });
|
||||
subscription.unsubscribe();
|
||||
verify(pubsub, times(1)).unsubscribe(new byte[][] { "a".getBytes() });
|
||||
verify(pubsub, never()).unsubscribe(new byte[0]);
|
||||
verify(pubsub, never()).punsubscribe(new byte[0]);
|
||||
verify(asyncCommands, times(1)).unsubscribe(new byte[][] { "a".getBytes() });
|
||||
verify(asyncCommands, never()).unsubscribe(new byte[0]);
|
||||
verify(asyncCommands, never()).punsubscribe(new byte[0]);
|
||||
assertTrue(subscription.isAlive());
|
||||
assertTrue(subscription.getChannels().isEmpty());
|
||||
Collection<byte[]> patterns = subscription.getPatterns();
|
||||
@@ -88,9 +91,9 @@ public class LettuceSubscriptionTests {
|
||||
byte[][] channel = new byte[][] { "a".getBytes() };
|
||||
subscription.subscribe(channel);
|
||||
subscription.unsubscribe(channel);
|
||||
verify(pubsub, times(1)).unsubscribe(channel);
|
||||
verify(pubsub, never()).unsubscribe(new byte[0]);
|
||||
verify(pubsub, never()).punsubscribe(new byte[0]);
|
||||
verify(asyncCommands, times(1)).unsubscribe(channel);
|
||||
verify(asyncCommands, never()).unsubscribe(new byte[0]);
|
||||
verify(asyncCommands, never()).punsubscribe(new byte[0]);
|
||||
verify(pubsub).close();
|
||||
verify(pubsub).removeListener(any(LettuceMessageListener.class));
|
||||
assertFalse(subscription.isAlive());
|
||||
@@ -103,9 +106,9 @@ public class LettuceSubscriptionTests {
|
||||
byte[][] channels = new byte[][] { "a".getBytes(), "b".getBytes() };
|
||||
subscription.subscribe(channels);
|
||||
subscription.unsubscribe(new byte[][] { "a".getBytes() });
|
||||
verify(pubsub, times(1)).unsubscribe(new byte[][] { "a".getBytes() });
|
||||
verify(pubsub, never()).unsubscribe(new byte[0]);
|
||||
verify(pubsub, never()).punsubscribe(new byte[0]);
|
||||
verify(asyncCommands, times(1)).unsubscribe(new byte[][] { "a".getBytes() });
|
||||
verify(asyncCommands, never()).unsubscribe(new byte[0]);
|
||||
verify(asyncCommands, never()).punsubscribe(new byte[0]);
|
||||
assertTrue(subscription.isAlive());
|
||||
Collection<byte[]> subChannels = subscription.getChannels();
|
||||
assertEquals(1, subChannels.size());
|
||||
@@ -119,9 +122,9 @@ public class LettuceSubscriptionTests {
|
||||
subscription.subscribe(channel);
|
||||
subscription.pSubscribe(new byte[][] { "s*".getBytes() });
|
||||
subscription.unsubscribe(channel);
|
||||
verify(pubsub, times(1)).unsubscribe(channel);
|
||||
verify(pubsub, never()).unsubscribe(new byte[0]);
|
||||
verify(pubsub, never()).punsubscribe(new byte[0]);
|
||||
verify(asyncCommands, times(1)).unsubscribe(channel);
|
||||
verify(asyncCommands, never()).unsubscribe(new byte[0]);
|
||||
verify(asyncCommands, never()).punsubscribe(new byte[0]);
|
||||
assertTrue(subscription.isAlive());
|
||||
assertTrue(subscription.getChannels().isEmpty());
|
||||
Collection<byte[]> patterns = subscription.getPatterns();
|
||||
@@ -135,9 +138,9 @@ public class LettuceSubscriptionTests {
|
||||
subscription.subscribe(new byte[][] { "a".getBytes(), "b".getBytes() });
|
||||
subscription.pSubscribe(new byte[][] { "s*".getBytes() });
|
||||
subscription.unsubscribe(channel);
|
||||
verify(pubsub, times(1)).unsubscribe(channel);
|
||||
verify(pubsub, never()).unsubscribe(new byte[0]);
|
||||
verify(pubsub, never()).punsubscribe(new byte[0]);
|
||||
verify(asyncCommands, times(1)).unsubscribe(channel);
|
||||
verify(asyncCommands, never()).unsubscribe(new byte[0]);
|
||||
verify(asyncCommands, never()).punsubscribe(new byte[0]);
|
||||
assertTrue(subscription.isAlive());
|
||||
Collection<byte[]> channels = subscription.getChannels();
|
||||
assertEquals(1, channels.size());
|
||||
@@ -151,8 +154,8 @@ public class LettuceSubscriptionTests {
|
||||
public void testUnsubscribeAllNoChannels() {
|
||||
subscription.pSubscribe(new byte[][] { "s*".getBytes() });
|
||||
subscription.unsubscribe();
|
||||
verify(pubsub, never()).unsubscribe(new byte[0]);
|
||||
verify(pubsub, never()).punsubscribe(new byte[0]);
|
||||
verify(asyncCommands, never()).unsubscribe(new byte[0]);
|
||||
verify(asyncCommands, never()).punsubscribe(new byte[0]);
|
||||
assertTrue(subscription.isAlive());
|
||||
assertTrue(subscription.getChannels().isEmpty());
|
||||
Collection<byte[]> patterns = subscription.getPatterns();
|
||||
@@ -168,9 +171,9 @@ public class LettuceSubscriptionTests {
|
||||
verify(pubsub, times(1)).removeListener(any(LettuceMessageListener.class));
|
||||
assertFalse(subscription.isAlive());
|
||||
subscription.unsubscribe();
|
||||
verify(pubsub, times(1)).unsubscribe(new byte[][] { "a".getBytes() });
|
||||
verify(pubsub, never()).unsubscribe(new byte[0]);
|
||||
verify(pubsub, never()).punsubscribe(new byte[0]);
|
||||
verify(asyncCommands, times(1)).unsubscribe(new byte[][] { "a".getBytes() });
|
||||
verify(asyncCommands, never()).unsubscribe(new byte[0]);
|
||||
verify(asyncCommands, never()).punsubscribe(new byte[0]);
|
||||
}
|
||||
|
||||
@Test(expected = RedisInvalidSubscriptionException.class)
|
||||
@@ -185,9 +188,9 @@ public class LettuceSubscriptionTests {
|
||||
public void testPUnsubscribeAllAndClose() {
|
||||
subscription.pSubscribe(new byte[][] { "a*".getBytes() });
|
||||
subscription.pUnsubscribe();
|
||||
verify(pubsub, never()).unsubscribe(new byte[0]);
|
||||
verify(pubsub, never()).punsubscribe(new byte[0]);
|
||||
verify(pubsub, times(1)).punsubscribe(new byte[][] { "a*".getBytes() });
|
||||
verify(asyncCommands, never()).unsubscribe(new byte[0]);
|
||||
verify(asyncCommands, never()).punsubscribe(new byte[0]);
|
||||
verify(asyncCommands, times(1)).punsubscribe(new byte[][] { "a*".getBytes() });
|
||||
assertFalse(subscription.isAlive());
|
||||
verify(pubsub).close();
|
||||
verify(pubsub).removeListener(any(LettuceMessageListener.class));
|
||||
@@ -200,9 +203,9 @@ public class LettuceSubscriptionTests {
|
||||
subscription.subscribe(new byte[][] { "a".getBytes() });
|
||||
subscription.pSubscribe(new byte[][] { "s*".getBytes() });
|
||||
subscription.pUnsubscribe();
|
||||
verify(pubsub, never()).unsubscribe(new byte[0]);
|
||||
verify(pubsub, never()).punsubscribe(new byte[0]);
|
||||
verify(pubsub, times(1)).punsubscribe(new byte[][] { "s*".getBytes() });
|
||||
verify(asyncCommands, never()).unsubscribe(new byte[0]);
|
||||
verify(asyncCommands, never()).punsubscribe(new byte[0]);
|
||||
verify(asyncCommands, times(1)).punsubscribe(new byte[][] { "s*".getBytes() });
|
||||
assertTrue(subscription.isAlive());
|
||||
assertTrue(subscription.getPatterns().isEmpty());
|
||||
Collection<byte[]> channels = subscription.getChannels();
|
||||
@@ -215,9 +218,9 @@ public class LettuceSubscriptionTests {
|
||||
byte[][] pattern = new byte[][] { "a*".getBytes() };
|
||||
subscription.pSubscribe(pattern);
|
||||
subscription.pUnsubscribe(pattern);
|
||||
verify(pubsub, never()).unsubscribe(new byte[0]);
|
||||
verify(pubsub, never()).punsubscribe(new byte[0]);
|
||||
verify(pubsub, times(1)).punsubscribe(pattern);
|
||||
verify(asyncCommands, never()).unsubscribe(new byte[0]);
|
||||
verify(asyncCommands, never()).punsubscribe(new byte[0]);
|
||||
verify(asyncCommands, times(1)).punsubscribe(pattern);
|
||||
verify(pubsub).close();
|
||||
verify(pubsub).removeListener(any(LettuceMessageListener.class));
|
||||
assertFalse(subscription.isAlive());
|
||||
@@ -230,9 +233,9 @@ public class LettuceSubscriptionTests {
|
||||
byte[][] patterns = new byte[][] { "a*".getBytes(), "b*".getBytes() };
|
||||
subscription.pSubscribe(patterns);
|
||||
subscription.pUnsubscribe(new byte[][] { "a*".getBytes() });
|
||||
verify(pubsub, times(1)).punsubscribe(new byte[][] { "a*".getBytes() });
|
||||
verify(pubsub, never()).unsubscribe(new byte[0]);
|
||||
verify(pubsub, never()).punsubscribe(new byte[0]);
|
||||
verify(asyncCommands, times(1)).punsubscribe(new byte[][] { "a*".getBytes() });
|
||||
verify(asyncCommands, never()).unsubscribe(new byte[0]);
|
||||
verify(asyncCommands, never()).punsubscribe(new byte[0]);
|
||||
assertTrue(subscription.isAlive());
|
||||
Collection<byte[]> subPatterns = subscription.getPatterns();
|
||||
assertEquals(1, subPatterns.size());
|
||||
@@ -246,9 +249,9 @@ public class LettuceSubscriptionTests {
|
||||
subscription.subscribe(new byte[][] { "a".getBytes() });
|
||||
subscription.pSubscribe(pattern);
|
||||
subscription.pUnsubscribe(pattern);
|
||||
verify(pubsub, times(1)).punsubscribe(pattern);
|
||||
verify(pubsub, never()).unsubscribe(new byte[0]);
|
||||
verify(pubsub, never()).punsubscribe(new byte[0]);
|
||||
verify(asyncCommands, times(1)).punsubscribe(pattern);
|
||||
verify(asyncCommands, never()).unsubscribe(new byte[0]);
|
||||
verify(asyncCommands, never()).punsubscribe(new byte[0]);
|
||||
assertTrue(subscription.isAlive());
|
||||
assertTrue(subscription.getPatterns().isEmpty());
|
||||
Collection<byte[]> channels = subscription.getChannels();
|
||||
@@ -262,9 +265,9 @@ public class LettuceSubscriptionTests {
|
||||
subscription.pSubscribe(new byte[][] { "a*".getBytes(), "b*".getBytes() });
|
||||
subscription.subscribe(new byte[][] { "a".getBytes() });
|
||||
subscription.pUnsubscribe(pattern);
|
||||
verify(pubsub, never()).unsubscribe(new byte[0]);
|
||||
verify(pubsub, never()).punsubscribe(new byte[0]);
|
||||
verify(pubsub, times(1)).punsubscribe(pattern);
|
||||
verify(asyncCommands, never()).unsubscribe(new byte[0]);
|
||||
verify(asyncCommands, never()).punsubscribe(new byte[0]);
|
||||
verify(asyncCommands, times(1)).punsubscribe(pattern);
|
||||
assertTrue(subscription.isAlive());
|
||||
Collection<byte[]> channels = subscription.getChannels();
|
||||
assertEquals(1, channels.size());
|
||||
@@ -278,8 +281,8 @@ public class LettuceSubscriptionTests {
|
||||
public void testPUnsubscribeAllNoPatterns() {
|
||||
subscription.subscribe(new byte[][] { "s".getBytes() });
|
||||
subscription.pUnsubscribe();
|
||||
verify(pubsub, never()).unsubscribe(new byte[0]);
|
||||
verify(pubsub, never()).punsubscribe(new byte[0]);
|
||||
verify(asyncCommands, never()).unsubscribe(new byte[0]);
|
||||
verify(asyncCommands, never()).punsubscribe(new byte[0]);
|
||||
assertTrue(subscription.isAlive());
|
||||
assertTrue(subscription.getPatterns().isEmpty());
|
||||
Collection<byte[]> channels = subscription.getChannels();
|
||||
@@ -295,9 +298,9 @@ public class LettuceSubscriptionTests {
|
||||
subscription.pUnsubscribe();
|
||||
verify(pubsub, times(1)).close();
|
||||
verify(pubsub, times(1)).removeListener(any(LettuceMessageListener.class));
|
||||
verify(pubsub, times(1)).unsubscribe(new byte[][] { "a".getBytes() });
|
||||
verify(pubsub, never()).unsubscribe(new byte[0]);
|
||||
verify(pubsub, never()).punsubscribe(new byte[0]);
|
||||
verify(asyncCommands, times(1)).unsubscribe(new byte[][] { "a".getBytes() });
|
||||
verify(asyncCommands, never()).unsubscribe(new byte[0]);
|
||||
verify(asyncCommands, never()).punsubscribe(new byte[0]);
|
||||
}
|
||||
|
||||
@Test(expected = RedisInvalidSubscriptionException.class)
|
||||
@@ -311,24 +314,23 @@ public class LettuceSubscriptionTests {
|
||||
@Test
|
||||
public void testDoCloseNotSubscribed() {
|
||||
subscription.doClose();
|
||||
verify(pubsub, never()).unsubscribe(new byte[0]);
|
||||
verify(pubsub, never()).punsubscribe(new byte[0]);
|
||||
verify(asyncCommands, never()).unsubscribe(new byte[0]);
|
||||
verify(asyncCommands, never()).punsubscribe(new byte[0]);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDoCloseSubscribedChannels() {
|
||||
subscription.subscribe(new byte[][] { "a".getBytes() });
|
||||
subscription.doClose();
|
||||
verify(pubsub, times(1)).unsubscribe(new byte[0]);
|
||||
verify(pubsub, never()).punsubscribe(new byte[0]);
|
||||
verify(asyncCommands, times(1)).unsubscribe(new byte[0]);
|
||||
verify(asyncCommands, never()).punsubscribe(new byte[0]);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDoCloseSubscribedPatterns() {
|
||||
subscription.pSubscribe(new byte[][] { "a*".getBytes() });
|
||||
subscription.doClose();
|
||||
verify(pubsub, never()).unsubscribe(new byte[0]);
|
||||
verify(pubsub, times(1)).punsubscribe(new byte[0]);
|
||||
verify(asyncCommands, never()).unsubscribe(new byte[0]);
|
||||
verify(asyncCommands, times(1)).punsubscribe(new byte[0]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -35,8 +35,8 @@ public class LettuceTestClientResources {
|
||||
|
||||
static {
|
||||
|
||||
SHARED_CLIENT_RESOURCES = new DefaultClientResources.Builder()
|
||||
.eventLoopGroupProvider(new TestEventLoopGroupProvider()).build();
|
||||
SHARED_CLIENT_RESOURCES = DefaultClientResources.builder().eventLoopGroupProvider(new TestEventLoopGroupProvider())
|
||||
.build();
|
||||
appendShutdownHook();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user