Clean up Connection integration tests
- Test multi for all applicable connection types - Clean up unused code - Remove redundant long-running pubsub test
This commit is contained in:
@@ -19,7 +19,6 @@ package org.springframework.data.redis.connection;
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNotSame;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
@@ -31,7 +30,6 @@ import java.util.UUID;
|
||||
import java.util.concurrent.BlockingDeque;
|
||||
import java.util.concurrent.LinkedBlockingDeque;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.AfterClass;
|
||||
@@ -213,61 +211,6 @@ public abstract class AbstractConnectionIntegrationTests {
|
||||
connection.closePipeline();
|
||||
}
|
||||
|
||||
// pub sub test
|
||||
@Test
|
||||
public void testPubSub() throws Exception {
|
||||
|
||||
final BlockingDeque<Message> queue = new LinkedBlockingDeque<Message>();
|
||||
|
||||
final MessageListener ml = new MessageListener() {
|
||||
|
||||
public void onMessage(Message message, byte[] pattern) {
|
||||
queue.add(message);
|
||||
System.out.println("received message");
|
||||
}
|
||||
};
|
||||
|
||||
final byte[] channel = "foo.tv".getBytes();
|
||||
final RedisConnection subConn = getConnectionFactory().getConnection();
|
||||
|
||||
assertNotSame(connection, subConn);
|
||||
|
||||
|
||||
final AtomicBoolean flag = new AtomicBoolean(true);
|
||||
|
||||
Runnable listener = new Runnable() {
|
||||
|
||||
public void run() {
|
||||
subConn.subscribe(ml, channel);
|
||||
System.out.println("Subscribed");
|
||||
while (flag.get()) {
|
||||
try {
|
||||
Thread.currentThread().sleep(2000);
|
||||
} catch (Exception ex) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Thread th = new Thread(listener, "listener");
|
||||
th.start();
|
||||
|
||||
try {
|
||||
Thread.sleep(1500);
|
||||
connection.publish(channel, "one".getBytes());
|
||||
connection.publish(channel, "two".getBytes());
|
||||
connection.publish(channel, "I see you".getBytes());
|
||||
System.out.println("Done publishing...");
|
||||
Thread.sleep(5000);
|
||||
System.out.println("Done waiting ...");
|
||||
} finally {
|
||||
flag.set(false);
|
||||
}
|
||||
System.out.println(queue);
|
||||
assertEquals(3, queue.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPubSubWithNamedChannels() throws Exception {
|
||||
final String expectedChannel = "channel1";
|
||||
@@ -420,6 +363,20 @@ public abstract class AbstractConnectionIntegrationTests {
|
||||
assertTrue(hashMap.containsKey(key2));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMulti() throws Exception {
|
||||
byte[] key = "key".getBytes();
|
||||
byte[] value = "value".getBytes();
|
||||
|
||||
connection.multi();
|
||||
connection.set(key, value);
|
||||
assertNull(connection.get(key));
|
||||
List<Object> results = connection.exec();
|
||||
assertEquals(2, results.size());
|
||||
assertEquals("OK", new String((byte[])results.get(0)));
|
||||
assertEquals(new String(value), new String((byte[])results.get(1)));
|
||||
}
|
||||
|
||||
private boolean isAsync() {
|
||||
return (getConnectionFactory() instanceof LettuceConnectionFactory) ||
|
||||
(getConnectionFactory() instanceof SrpConnectionFactory);
|
||||
|
||||
@@ -16,14 +16,9 @@
|
||||
|
||||
package org.springframework.data.redis.connection.jedis;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.data.redis.SettingsUtils;
|
||||
import org.springframework.data.redis.connection.AbstractConnectionIntegrationTests;
|
||||
import org.springframework.data.redis.connection.RedisConnectionFactory;
|
||||
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
|
||||
|
||||
import redis.clients.jedis.BinaryJedis;
|
||||
import redis.clients.jedis.Transaction;
|
||||
|
||||
public class JedisConnectionIntegrationTests extends AbstractConnectionIntegrationTests {
|
||||
|
||||
@@ -43,48 +38,4 @@ public class JedisConnectionIntegrationTests extends AbstractConnectionIntegrati
|
||||
protected RedisConnectionFactory getConnectionFactory() {
|
||||
return factory;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMulti() throws Exception {
|
||||
byte[] key = "key".getBytes();
|
||||
byte[] value = "value".getBytes();
|
||||
|
||||
BinaryJedis jedis = (BinaryJedis) connection.getNativeConnection();
|
||||
Transaction multi = jedis.multi();
|
||||
//connection.set(key, value);
|
||||
multi.set(value, key);
|
||||
System.out.println(multi.exec());
|
||||
|
||||
connection.multi();
|
||||
connection.set(value, key);
|
||||
System.out.println(connection.exec());
|
||||
}
|
||||
|
||||
// @Test
|
||||
// public void setAdd() {
|
||||
// connection.sadd("s1", "1");
|
||||
// connection.sadd("s1", "2");
|
||||
// connection.sadd("s1", "3");
|
||||
// connection.sadd("s2", "2");
|
||||
// connection.sadd("s2", "3");
|
||||
// Set<String> intersection = connection.sinter("s1", "s2");
|
||||
// System.out.println(intersection);
|
||||
//
|
||||
//
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void setIntersectionTests() {
|
||||
// RedisTemplate template = new RedisTemplate(clientFactory);
|
||||
// RedisSet s1 = new RedisSet(template, "s1");
|
||||
// s1.add("1");
|
||||
// s1.add("2");
|
||||
// s1.add("3");
|
||||
// RedisSet s2 = new RedisSet(template, "s2");
|
||||
// s2.add("2");
|
||||
// s2.add("3");
|
||||
// Set s3 = s1.intersection("s3", s1, s2);
|
||||
// for (Object object : s3) {
|
||||
// System.out.println(object);
|
||||
// }
|
||||
}
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
package org.springframework.data.redis.connection.jredis;
|
||||
|
||||
import org.jredis.JRedis;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.springframework.data.redis.SettingsUtils;
|
||||
@@ -41,16 +40,6 @@ public class JRedisConnectionIntegrationTests extends AbstractConnectionIntegrat
|
||||
return factory;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRaw() throws Exception {
|
||||
JRedis jr = (JRedis) factory.getConnection().getNativeConnection();
|
||||
|
||||
System.out.println(jr.dbsize());
|
||||
System.out.println(jr.exists("foobar"));
|
||||
jr.set("foobar", "barfoo");
|
||||
System.out.println(jr.get("foobar"));
|
||||
}
|
||||
|
||||
@Ignore("JRedis does not support pipelining")
|
||||
public void testNullCollections() {
|
||||
}
|
||||
@@ -91,6 +80,10 @@ public class JRedisConnectionIntegrationTests extends AbstractConnectionIntegrat
|
||||
public void testBitSet() throws Exception {
|
||||
}
|
||||
|
||||
@Ignore
|
||||
public void testMulti() throws Exception {
|
||||
}
|
||||
|
||||
@Ignore
|
||||
public void exceptionExecuteNativeWithPipeline() throws Exception {
|
||||
}
|
||||
|
||||
@@ -16,13 +16,16 @@
|
||||
|
||||
package org.springframework.data.redis.connection.lettuce;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.data.redis.SettingsUtils;
|
||||
import org.springframework.data.redis.connection.AbstractConnectionIntegrationTests;
|
||||
import org.springframework.data.redis.connection.RedisConnectionFactory;
|
||||
|
||||
import com.lambdaworks.redis.RedisAsyncConnection;
|
||||
|
||||
public class LettuceConnectionIntegrationTests extends AbstractConnectionIntegrationTests {
|
||||
|
||||
LettuceConnectionFactory factory;
|
||||
@@ -46,24 +49,12 @@ public class LettuceConnectionIntegrationTests extends AbstractConnectionIntegra
|
||||
byte[] key = "key".getBytes();
|
||||
byte[] value = "value".getBytes();
|
||||
|
||||
RedisAsyncConnection<byte[], byte[]> rc = (RedisAsyncConnection<byte[], byte[]>) connection.getNativeConnection();
|
||||
rc.multi();
|
||||
//connection.set(key, value);
|
||||
rc.set(value, key);
|
||||
System.out.println(rc.exec());
|
||||
|
||||
connection.multi();
|
||||
connection.set(value, key);
|
||||
System.out.println(connection.exec());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRaw() throws Exception {
|
||||
RedisAsyncConnection<byte[], byte[]> rc = (RedisAsyncConnection<byte[], byte[]>) factory.getConnection().getNativeConnection();
|
||||
|
||||
System.out.println(rc.dbsize());
|
||||
System.out.println(rc.exists("foobar".getBytes()));
|
||||
rc.set("foobar".getBytes(), "barfoo".getBytes());
|
||||
System.out.println(rc.get("foobar".getBytes()));
|
||||
connection.set(key, value);
|
||||
assertNull(connection.get(key));
|
||||
List<Object> results = connection.exec();
|
||||
assertEquals(2, results.size());
|
||||
assertEquals("OK", results.get(0));
|
||||
assertEquals(new String(value), new String((byte[])results.get(1)));
|
||||
}
|
||||
}
|
||||
@@ -16,11 +16,11 @@
|
||||
package org.springframework.data.redis.connection.rjc;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.idevlab.rjc.Session;
|
||||
import org.junit.Test;
|
||||
import org.springframework.data.redis.SettingsUtils;
|
||||
import org.springframework.data.redis.connection.AbstractConnectionIntegrationTests;
|
||||
@@ -48,13 +48,17 @@ public class RjcConnectionIntegrationTests extends AbstractConnectionIntegration
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRaw() throws Exception {
|
||||
Session jr = (Session) factory.getConnection().getNativeConnection();
|
||||
public void testMulti() throws Exception {
|
||||
byte[] key = "key".getBytes();
|
||||
byte[] value = "value".getBytes();
|
||||
|
||||
System.out.println(jr.dbSize());
|
||||
System.out.println(jr.exists("foobar"));
|
||||
jr.set("foobar", "barfoo");
|
||||
System.out.println(jr.get("foobar"));
|
||||
connection.multi();
|
||||
connection.set(key, value);
|
||||
assertNull(connection.get(key));
|
||||
List<Object> results = connection.exec();
|
||||
assertEquals(2, results.size());
|
||||
assertEquals("OK", (String) results.get(0));
|
||||
assertEquals(new String(value), new String(RjcUtils.encode((String)results.get(1))));
|
||||
}
|
||||
|
||||
// override test to address the encoding issue (the bytes[] in raw format differ)
|
||||
|
||||
@@ -16,13 +16,11 @@
|
||||
|
||||
package org.springframework.data.redis.connection.srp;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.Ignore;
|
||||
import org.springframework.data.redis.SettingsUtils;
|
||||
import org.springframework.data.redis.connection.AbstractConnectionIntegrationTests;
|
||||
import org.springframework.data.redis.connection.RedisConnectionFactory;
|
||||
|
||||
import redis.client.RedisClient;
|
||||
|
||||
/**
|
||||
* @author Costin Leau
|
||||
*/
|
||||
@@ -42,16 +40,12 @@ public class SrpConnectionIntegrationTests extends AbstractConnectionIntegration
|
||||
return factory;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRaw() throws Exception {
|
||||
RedisClient rc = (RedisClient) factory.getConnection().getNativeConnection();
|
||||
|
||||
System.out.println(rc.dbsize());
|
||||
System.out.println(rc.exists("foobar"));
|
||||
rc.set("foobar", "barfoo");
|
||||
System.out.println(rc.get("foobar"));
|
||||
}
|
||||
|
||||
@Ignore
|
||||
public void testNullCollections() throws Exception {
|
||||
}
|
||||
|
||||
//DATAREDIS-123, exec does not return command results
|
||||
@Ignore
|
||||
public void testMulti() throws Exception {
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user