Add connection integration tests
- Add tests for all Connection methods - Add tests for all Connection methods through pipeline - Clean up DB between Connection test runs - Reduce sleeps in pub/sub tests to improve execution time
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,800 @@
|
||||
/*
|
||||
* Copyright 2011-2013 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;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.springframework.data.redis.connection.RedisZSetCommands.Aggregate;
|
||||
import org.springframework.data.redis.connection.RedisZSetCommands.Tuple;
|
||||
import org.springframework.data.redis.connection.StringRedisConnection.StringTuple;
|
||||
import org.springframework.data.redis.serializer.SerializationUtils;
|
||||
|
||||
/**
|
||||
* Base test class for integration tests that execute each operation of a
|
||||
* Connection while a pipeline is open, verifying that the operations return
|
||||
* null and the proper values are returned when closing the pipeline.
|
||||
* <p>
|
||||
* Pipelined results are generally native to the provider and not transformed by
|
||||
* our {@link RedisConnection}, so this test overrides
|
||||
* {@link AbstractConnectionIntegrationTests} when result types are different
|
||||
*
|
||||
* @author Jennifer Hickey
|
||||
*
|
||||
*/
|
||||
abstract public class AbstractConnectionPipelineIntegrationTests extends
|
||||
AbstractConnectionIntegrationTests {
|
||||
|
||||
/**
|
||||
* Individual results from closePipeline should be converted from List to
|
||||
* LinkedHashSet
|
||||
**/
|
||||
protected boolean convertResultToSet = false;
|
||||
|
||||
/**
|
||||
* Individual results from closePipeline should be converted to
|
||||
* {@link Tuple}s
|
||||
**/
|
||||
protected boolean convertResultToTuples = false;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
super.setUp();
|
||||
connection.openPipeline();
|
||||
}
|
||||
|
||||
@Ignore
|
||||
public void testByteValue() {
|
||||
}
|
||||
|
||||
@Ignore
|
||||
public void testNullKey() throws Exception {
|
||||
}
|
||||
|
||||
@Ignore
|
||||
public void testNullValue() throws Exception {
|
||||
}
|
||||
|
||||
@Ignore
|
||||
public void testHashNullKey() throws Exception {
|
||||
}
|
||||
|
||||
@Ignore
|
||||
public void testHashNullValue() throws Exception {
|
||||
}
|
||||
|
||||
@Ignore("Pub/Sub not supported while pipelining")
|
||||
public void testPubSubWithNamedChannels() throws Exception {
|
||||
}
|
||||
|
||||
@Ignore("Pub/Sub not supported while pipelining")
|
||||
public void testPubSubWithPatterns() throws Exception {
|
||||
}
|
||||
|
||||
@Test(expected = RedisPipelineException.class)
|
||||
public void exceptionExecuteNative() throws Exception {
|
||||
connection.execute("ZadD", getClass() + "#foo\t0.90\titem");
|
||||
connection.closePipeline();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExpire() throws Exception {
|
||||
connection.set("exp", "true");
|
||||
actual.add(connection.expire("exp", 1));
|
||||
Thread.sleep(2000);
|
||||
actual.add(connection.exists("exp"));
|
||||
verifyResults(Arrays.asList(new Object[] { 1l, 0l }), actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExpireAt() throws Exception {
|
||||
connection.set("exp2", "true");
|
||||
actual.add(connection.expireAt("exp2", System.currentTimeMillis() / 1000 + 1));
|
||||
Thread.sleep(2000);
|
||||
actual.add(connection.exists("exp2"));
|
||||
verifyResults(Arrays.asList(new Object[] { 1l, 0l }), actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPersist() throws Exception {
|
||||
connection.set("exp3", "true");
|
||||
actual.add(connection.expire("exp3", 1));
|
||||
actual.add(connection.persist("exp3"));
|
||||
Thread.sleep(1500);
|
||||
actual.add(connection.exists("exp3"));
|
||||
verifyResults(Arrays.asList(new Object[] { 1l, 1l, 1l }), actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetEx() throws Exception {
|
||||
connection.setEx("expy", 1l, "yep");
|
||||
actual.add(connection.get("expy"));
|
||||
Thread.sleep(2000);
|
||||
actual.add(connection.exists("expy"));
|
||||
verifyResults(Arrays.asList(new Object[] { "yep", 0l }), actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBitSet() throws Exception {
|
||||
String key = "bitset-test";
|
||||
connection.setBit(key, 0, false);
|
||||
connection.setBit(key, 1, true);
|
||||
actual.add(connection.getBit(key, 0));
|
||||
actual.add(connection.getBit(key, 1));
|
||||
verifyResults(Arrays.asList(new Object[] { 0l, 0l, 0l, 1l }), actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDbSize() {
|
||||
connection.set("dbparam", "foo");
|
||||
assertNull(connection.dbSize());
|
||||
List<Object> results = connection.closePipeline();
|
||||
assertEquals(2, results.size());
|
||||
assertTrue((Long) results.get(1) > 0);
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
@Test
|
||||
public void testGetConfig() {
|
||||
assertNull(connection.getConfig("*"));
|
||||
List<Object> results = convertResults(connection.closePipeline());
|
||||
assertEquals(1, results.size());
|
||||
assertTrue(!((List) results.get(0)).isEmpty());
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
@Test
|
||||
public void testKeys() throws Exception {
|
||||
connection.set("keytest", "true");
|
||||
connection.set("keytest2", "true");
|
||||
connection.keys("key*");
|
||||
List<Object> results = convertResults(connection.closePipeline());
|
||||
assertEquals(1, results.size());
|
||||
assertTrue(((List) results.get(0)).contains("keytest"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRandomKey() {
|
||||
connection.set("some", "thing");
|
||||
assertNull(connection.randomKey());
|
||||
List<Object> results = convertResults(connection.closePipeline());
|
||||
assertEquals(1, results.size());
|
||||
assertNotNull(results.get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testType() {
|
||||
connection.set("something", "yo");
|
||||
assertNull(connection.type("something"));
|
||||
List<Object> results = convertResults(connection.closePipeline());
|
||||
assertEquals(1, results.size());
|
||||
assertEquals("string", results.get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMSetNx() {
|
||||
Map<String, String> vals = new HashMap<String, String>();
|
||||
vals.put("height", "5");
|
||||
vals.put("width", "1");
|
||||
connection.mSetNXString(vals);
|
||||
assertNull(connection.mGet("height", "width"));
|
||||
verifyResults(Arrays.asList(new Object[] { 1l, Arrays.asList(new String[] { "5", "1" }) }),
|
||||
actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetNx() {
|
||||
actual.add(connection.setNX("notaround", "54"));
|
||||
actual.add(connection.get("notaround"));
|
||||
actual.add(connection.setNX("notaround", "55"));
|
||||
actual.add(connection.get("notaround"));
|
||||
verifyResults(Arrays.asList(new Object[] { 1l, "54", 0l, "54" }), actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRenameNx() {
|
||||
connection.set("nxtest", "testit");
|
||||
actual.add(connection.renameNX("nxtest", "newnxtest"));
|
||||
actual.add(connection.get("newnxtest"));
|
||||
actual.add(connection.exists("nxtest"));
|
||||
verifyResults(Arrays.asList(new Object[] { 1l, "testit", 0l }), actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetRangeSetRange() {
|
||||
connection.set("rangekey", "supercalifrag");
|
||||
actual.add(connection.getRange("rangekey", 0l, 2l));
|
||||
connection.setRange("rangekey", "ck", 2);
|
||||
actual.add(connection.get("rangekey"));
|
||||
verifyResults(Arrays.asList(new Object[] { "sup", 13l, "suckrcalifrag" }), actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultiDiscard() throws Exception {
|
||||
DefaultStringRedisConnection conn2 = new DefaultStringRedisConnection(
|
||||
connectionFactory.getConnection());
|
||||
conn2.set("testitnow", "willdo");
|
||||
connection.multi();
|
||||
connection.set("testitnow2", "notok");
|
||||
connection.discard();
|
||||
connection.get("testitnow");
|
||||
List<Object> convertedResults = convertResults(connection.closePipeline());
|
||||
assertEquals(Arrays.asList(new String[] { "willdo" }), convertedResults);
|
||||
connection.openPipeline();
|
||||
// Ensure we can run a new tx after discarding previous one
|
||||
testMultiExec();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultiExec() throws Exception {
|
||||
connection.multi();
|
||||
connection.set("key", "value");
|
||||
assertNull(connection.get("key"));
|
||||
assertNull(connection.exec());
|
||||
List<Object> convertedResults = convertResults(connection.closePipeline());
|
||||
assertEquals(Arrays.asList(new Object[] { Arrays.asList(new String[] { "OK", "value" }) }),
|
||||
convertedResults);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUnwatch() throws Exception {
|
||||
connection.set("testitnow", "willdo");
|
||||
connection.watch("testitnow".getBytes());
|
||||
connection.unwatch();
|
||||
connection.multi();
|
||||
DefaultStringRedisConnection conn2 = new DefaultStringRedisConnection(
|
||||
connectionFactory.getConnection());
|
||||
conn2.set("testitnow", "something");
|
||||
connection.set("testitnow", "somethingelse");
|
||||
connection.get("testitnow");
|
||||
connection.exec();
|
||||
List<Object> convertedResults = convertResults(connection.closePipeline());
|
||||
assertEquals(Arrays.asList(new Object[] { Arrays.asList(new String[] { "OK",
|
||||
"somethingelse" }) }), convertedResults);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSAdd() {
|
||||
convertResultToSet = true;
|
||||
actual.add(connection.sAdd("myset", "foo"));
|
||||
actual.add(connection.sAdd("myset", "bar"));
|
||||
actual.add(connection.sMembers("myset"));
|
||||
verifyResults(
|
||||
Arrays.asList(new Object[] { 1l, 1l,
|
||||
new HashSet<String>(Arrays.asList(new String[] { "foo", "bar" })) }),
|
||||
actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSCard() {
|
||||
actual.add(connection.sAdd("myset", "foo"));
|
||||
actual.add(connection.sAdd("myset", "bar"));
|
||||
actual.add(connection.sCard("myset"));
|
||||
verifyResults(Arrays.asList(new Object[] { 1l, 1l, 2l }), actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSDiff() {
|
||||
convertResultToSet = true;
|
||||
actual.add(connection.sAdd("myset", "foo"));
|
||||
actual.add(connection.sAdd("myset", "bar"));
|
||||
actual.add(connection.sAdd("otherset", "bar"));
|
||||
actual.add(connection.sDiff("myset", "otherset"));
|
||||
verifyResults(
|
||||
Arrays.asList(new Object[] { 1l, 1l, 1l,
|
||||
new HashSet<String>(Collections.singletonList("foo")) }), actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSDiffStore() {
|
||||
convertResultToSet = true;
|
||||
actual.add(connection.sAdd("myset", "foo"));
|
||||
actual.add(connection.sAdd("myset", "bar"));
|
||||
actual.add(connection.sAdd("otherset", "bar"));
|
||||
connection.sDiffStore("thirdset", "myset", "otherset");
|
||||
actual.add(connection.sMembers("thirdset"));
|
||||
verifyResults(
|
||||
Arrays.asList(new Object[] { 1l, 1l, 1l, 1l,
|
||||
new HashSet<String>(Collections.singletonList("foo")) }), actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSInter() {
|
||||
convertResultToSet = true;
|
||||
actual.add(connection.sAdd("myset", "foo"));
|
||||
actual.add(connection.sAdd("myset", "bar"));
|
||||
actual.add(connection.sAdd("otherset", "bar"));
|
||||
actual.add(connection.sInter("myset", "otherset"));
|
||||
verifyResults(
|
||||
Arrays.asList(new Object[] { 1l, 1l, 1l,
|
||||
new HashSet<String>(Collections.singletonList("bar")) }), actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSInterStore() {
|
||||
convertResultToSet = true;
|
||||
actual.add(connection.sAdd("myset", "foo"));
|
||||
actual.add(connection.sAdd("myset", "bar"));
|
||||
actual.add(connection.sAdd("otherset", "bar"));
|
||||
connection.sInterStore("thirdset", "myset", "otherset");
|
||||
actual.add(connection.sMembers("thirdset"));
|
||||
verifyResults(
|
||||
Arrays.asList(new Object[] { 1l, 1l, 1l, 1l,
|
||||
new HashSet<String>(Collections.singletonList("bar")) }), actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSIsMember() {
|
||||
convertResultToSet = true;
|
||||
actual.add(connection.sAdd("myset", "foo"));
|
||||
actual.add(connection.sAdd("myset", "bar"));
|
||||
actual.add(connection.sIsMember("myset", "foo"));
|
||||
actual.add(connection.sIsMember("myset", "baz"));
|
||||
verifyResults(Arrays.asList(new Object[] { 1l, 1l, true, false }), actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSMove() {
|
||||
convertResultToSet = true;
|
||||
actual.add(connection.sAdd("myset", "foo"));
|
||||
actual.add(connection.sAdd("myset", "bar"));
|
||||
actual.add(connection.sAdd("otherset", "bar"));
|
||||
actual.add(connection.sMove("myset", "otherset", "foo"));
|
||||
actual.add(connection.sMembers("otherset"));
|
||||
verifyResults(
|
||||
Arrays.asList(new Object[] { 1l, 1l, 1l, 1l,
|
||||
new HashSet<String>(Arrays.asList(new String[] { "foo", "bar" })) }),
|
||||
actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSPop() {
|
||||
convertResultToSet = true;
|
||||
connection.sAdd("myset", "foo");
|
||||
connection.sAdd("myset", "bar");
|
||||
assertNull(connection.sPop("myset"));
|
||||
List<Object> results = convertResults(connection.closePipeline());
|
||||
assertEquals(3, results.size());
|
||||
assertTrue(new HashSet<String>(Arrays.asList(new String[] { "foo", "bar" }))
|
||||
.contains(results.get(2)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSRandMember() {
|
||||
convertResultToSet = true;
|
||||
connection.sAdd("myset", "foo");
|
||||
connection.sAdd("myset", "bar");
|
||||
assertNull(connection.sRandMember("myset"));
|
||||
List<Object> results = convertResults(connection.closePipeline());
|
||||
assertEquals(3, results.size());
|
||||
assertTrue(new HashSet<String>(Arrays.asList(new String[] { "foo", "bar" }))
|
||||
.contains(results.get(2)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSRem() {
|
||||
convertResultToSet = true;
|
||||
actual.add(connection.sAdd("myset", "foo"));
|
||||
actual.add(connection.sAdd("myset", "bar"));
|
||||
actual.add(connection.sRem("myset", "foo"));
|
||||
actual.add(connection.sRem("myset", "baz"));
|
||||
actual.add(connection.sMembers("myset"));
|
||||
verifyResults(
|
||||
Arrays.asList(new Object[] { 1l, 1l, 1l, 0l,
|
||||
new HashSet<String>(Arrays.asList(new String[] { "bar" })) }), actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSUnion() {
|
||||
convertResultToSet = true;
|
||||
actual.add(connection.sAdd("myset", "foo"));
|
||||
actual.add(connection.sAdd("myset", "bar"));
|
||||
actual.add(connection.sAdd("otherset", "bar"));
|
||||
actual.add(connection.sAdd("otherset", "baz"));
|
||||
actual.add(connection.sUnion("myset", "otherset"));
|
||||
verifyResults(
|
||||
Arrays.asList(new Object[] { 1l, 1l, 1l, 1l,
|
||||
new HashSet<String>(Arrays.asList(new String[] { "foo", "bar", "baz" })) }),
|
||||
actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSUnionStore() {
|
||||
convertResultToSet = true;
|
||||
actual.add(connection.sAdd("myset", "foo"));
|
||||
actual.add(connection.sAdd("myset", "bar"));
|
||||
actual.add(connection.sAdd("otherset", "bar"));
|
||||
actual.add(connection.sAdd("otherset", "baz"));
|
||||
connection.sUnionStore("thirdset", "myset", "otherset");
|
||||
actual.add(connection.sMembers("thirdset"));
|
||||
verifyResults(
|
||||
Arrays.asList(new Object[] { 1l, 1l, 1l, 1l, 3l,
|
||||
new HashSet<String>(Arrays.asList(new String[] { "foo", "bar", "baz" })) }),
|
||||
actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testZAddAndZRange() {
|
||||
actual.add(connection.zAdd("myset", 2, "Bob"));
|
||||
actual.add(connection.zAdd("myset", 1, "James"));
|
||||
actual.add(connection.zRange("myset", 0, -1));
|
||||
verifyResults(Arrays.asList(new Object[] { 1l, 1l,
|
||||
Arrays.asList(new String[] { "James", "Bob" }) }), actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testZCard() {
|
||||
actual.add(connection.zAdd("myset", 2, "Bob"));
|
||||
actual.add(connection.zAdd("myset", 1, "James"));
|
||||
actual.add(connection.zCard("myset"));
|
||||
verifyResults(Arrays.asList(new Object[] { 1l, 1l, 2l }), actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testZCount() {
|
||||
actual.add(connection.zAdd("myset", 2, "Bob"));
|
||||
actual.add(connection.zAdd("myset", 1, "James"));
|
||||
actual.add(connection.zAdd("myset", 4, "Joe"));
|
||||
actual.add(connection.zCount("myset", 1, 2));
|
||||
verifyResults(Arrays.asList(new Object[] { 1l, 1l, 1l, 2l }), actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testZIncrBy() {
|
||||
actual.add(connection.zAdd("myset", 2, "Bob"));
|
||||
actual.add(connection.zAdd("myset", 1, "James"));
|
||||
actual.add(connection.zAdd("myset", 4, "Joe"));
|
||||
actual.add(connection.zIncrBy("myset", 2, "Joe"));
|
||||
actual.add(connection.zRangeByScore("myset", 6, 6));
|
||||
verifyResults(
|
||||
Arrays.asList(new Object[] { 1l, 1l, 1l, 6d, Collections.singletonList("Joe") }),
|
||||
actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testZInterStore() {
|
||||
actual.add(connection.zAdd("myset", 2, "Bob"));
|
||||
actual.add(connection.zAdd("myset", 1, "James"));
|
||||
actual.add(connection.zAdd("myset", 4, "Joe"));
|
||||
actual.add(connection.zAdd("otherset", 1, "Bob"));
|
||||
actual.add(connection.zAdd("otherset", 4, "James"));
|
||||
actual.add(connection.zInterStore("thirdset", "myset", "otherset"));
|
||||
actual.add(connection.zRange("thirdset", 0, -1));
|
||||
verifyResults(
|
||||
Arrays.asList(new Object[] { 1l, 1l, 1l, 1l, 1l, 2l,
|
||||
Arrays.asList(new String[] { "Bob", "James" }) }), actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testZInterStoreAggWeights() {
|
||||
convertResultToTuples = true;
|
||||
actual.add(connection.zAdd("myset", 2, "Bob"));
|
||||
actual.add(connection.zAdd("myset", 1, "James"));
|
||||
actual.add(connection.zAdd("myset", 4, "Joe"));
|
||||
actual.add(connection.zAdd("otherset", 1, "Bob"));
|
||||
actual.add(connection.zAdd("otherset", 4, "James"));
|
||||
actual.add(connection.zInterStore("thirdset", Aggregate.MAX, new int[] { 2, 3 }, "myset",
|
||||
"otherset"));
|
||||
actual.add(connection.zRangeWithScores("thirdset", 0, -1));
|
||||
verifyResults(
|
||||
Arrays.asList(new Object[] {
|
||||
1l,
|
||||
1l,
|
||||
1l,
|
||||
1l,
|
||||
1l,
|
||||
2l,
|
||||
Arrays.asList(new StringTuple[] {
|
||||
new DefaultStringTuple("Bob".getBytes(), "Bob", 4d),
|
||||
new DefaultStringTuple("James".getBytes(), "James", 12d) }) }),
|
||||
actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testZRangeWithScores() {
|
||||
convertResultToTuples = true;
|
||||
actual.add(connection.zAdd("myset", 2, "Bob"));
|
||||
actual.add(connection.zAdd("myset", 1, "James"));
|
||||
actual.add(connection.zRangeWithScores("myset", 0, -1));
|
||||
verifyResults(
|
||||
Arrays.asList(new Object[] {
|
||||
1l,
|
||||
1l,
|
||||
Arrays.asList(new StringTuple[] {
|
||||
new DefaultStringTuple("James".getBytes(), "James", 1d),
|
||||
new DefaultStringTuple("Bob".getBytes(), "Bob", 2d) }) }), actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testZRangeByScore() {
|
||||
actual.add(connection.zAdd("myset", 2, "Bob"));
|
||||
actual.add(connection.zAdd("myset", 1, "James"));
|
||||
actual.add(connection.zRangeByScore("myset", 1, 1));
|
||||
verifyResults(
|
||||
Arrays.asList(new Object[] { 1l, 1l, Arrays.asList(new String[] { "James" }) }),
|
||||
actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testZRangeByScoreOffsetCount() {
|
||||
actual.add(connection.zAdd("myset", 2, "Bob"));
|
||||
actual.add(connection.zAdd("myset", 1, "James"));
|
||||
actual.add(connection.zRangeByScore("myset", 1d, 3d, 1, -1));
|
||||
verifyResults(
|
||||
Arrays.asList(new Object[] { 1l, 1l, Arrays.asList(new String[] { "Bob" }) }),
|
||||
actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testZRangeByScoreWithScores() {
|
||||
convertResultToTuples = true;
|
||||
actual.add(connection.zAdd("myset", 2, "Bob"));
|
||||
actual.add(connection.zAdd("myset", 1, "James"));
|
||||
actual.add(connection.zRangeByScoreWithScores("myset", 2d, 5d));
|
||||
verifyResults(
|
||||
Arrays.asList(new Object[] {
|
||||
1l,
|
||||
1l,
|
||||
Arrays.asList(new StringTuple[] { new DefaultStringTuple("Bob".getBytes(),
|
||||
"Bob", 2d) }) }), actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testZRangeByScoreWithScoresOffsetCount() {
|
||||
convertResultToTuples = true;
|
||||
actual.add(connection.zAdd("myset", 2, "Bob"));
|
||||
actual.add(connection.zAdd("myset", 1, "James"));
|
||||
actual.add(connection.zRangeByScoreWithScores("myset", 1d, 5d, 0, 1));
|
||||
verifyResults(
|
||||
Arrays.asList(new Object[] {
|
||||
1l,
|
||||
1l,
|
||||
Arrays.asList(new StringTuple[] { new DefaultStringTuple(
|
||||
"James".getBytes(), "James", 1d) }) }), actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testZRevRange() {
|
||||
actual.add(connection.zAdd("myset", 2, "Bob"));
|
||||
actual.add(connection.zAdd("myset", 1, "James"));
|
||||
actual.add(connection.zRevRange("myset", 0, -1));
|
||||
verifyResults(Arrays.asList(new Object[] { 1l, 1l,
|
||||
Arrays.asList(new String[] { "Bob", "James" }) }), actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testZRevRangeWithScores() {
|
||||
convertResultToTuples = true;
|
||||
actual.add(connection.zAdd("myset", 2, "Bob"));
|
||||
actual.add(connection.zAdd("myset", 1, "James"));
|
||||
actual.add(connection.zRevRangeWithScores("myset", 0, -1));
|
||||
verifyResults(
|
||||
Arrays.asList(new Object[] {
|
||||
1l,
|
||||
1l,
|
||||
Arrays.asList(new StringTuple[] {
|
||||
new DefaultStringTuple("Bob".getBytes(), "Bob", 2d),
|
||||
new DefaultStringTuple("James".getBytes(), "James", 1d) }) }),
|
||||
actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testZRank() {
|
||||
actual.add(connection.zAdd("myset", 2, "Bob"));
|
||||
actual.add(connection.zAdd("myset", 1, "James"));
|
||||
actual.add(connection.zRank("myset", "James"));
|
||||
actual.add(connection.zRank("myset", "Bob"));
|
||||
verifyResults(Arrays.asList(new Object[] { 1l, 1l, 0l, 1l }), actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testZRem() {
|
||||
actual.add(connection.zAdd("myset", 2, "Bob"));
|
||||
actual.add(connection.zAdd("myset", 1, "James"));
|
||||
actual.add(connection.zRem("myset", "James"));
|
||||
actual.add(connection.zRange("myset", 0l, -1l));
|
||||
verifyResults(
|
||||
Arrays.asList(new Object[] { 1l, 1l, 1l, Arrays.asList(new String[] { "Bob" }) }),
|
||||
actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testZRemRangeByRank() {
|
||||
actual.add(connection.zAdd("myset", 2, "Bob"));
|
||||
actual.add(connection.zAdd("myset", 1, "James"));
|
||||
actual.add(connection.zRemRange("myset", 0l, 3l));
|
||||
actual.add(connection.zRange("myset", 0l, -1l));
|
||||
verifyResults(Arrays.asList(new Object[] { 1l, 1l, 2l, new ArrayList<String>() }), actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testZRemRangeByScore() {
|
||||
actual.add(connection.zAdd("myset", 2, "Bob"));
|
||||
actual.add(connection.zAdd("myset", 1, "James"));
|
||||
actual.add(connection.zRemRangeByScore("myset", 0d, 1d));
|
||||
actual.add(connection.zRange("myset", 0l, -1l));
|
||||
verifyResults(
|
||||
Arrays.asList(new Object[] { 1l, 1l, 1l, Arrays.asList(new String[] { "Bob" }) }),
|
||||
actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testZRevRank() {
|
||||
actual.add(connection.zAdd("myset", 2, "Bob"));
|
||||
actual.add(connection.zAdd("myset", 1, "James"));
|
||||
actual.add(connection.zAdd("myset", 3, "Joe"));
|
||||
actual.add(connection.zRevRank("myset", "Joe"));
|
||||
verifyResults(Arrays.asList(new Object[] { 1l, 1l, 1l, 0l }), actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testZScore() {
|
||||
actual.add(connection.zAdd("myset", 2, "Bob"));
|
||||
actual.add(connection.zAdd("myset", 1, "James"));
|
||||
actual.add(connection.zAdd("myset", 3, "Joe"));
|
||||
actual.add(connection.zScore("myset", "Joe"));
|
||||
verifyResults(Arrays.asList(new Object[] { 1l, 1l, 1l, 3d }), actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testZUnionStore() {
|
||||
actual.add(connection.zAdd("myset", 2, "Bob"));
|
||||
actual.add(connection.zAdd("myset", 1, "James"));
|
||||
actual.add(connection.zAdd("myset", 6, "Joe"));
|
||||
actual.add(connection.zAdd("otherset", 1, "Bob"));
|
||||
actual.add(connection.zAdd("otherset", 4, "James"));
|
||||
actual.add(connection.zUnionStore("thirdset", "myset", "otherset"));
|
||||
actual.add(connection.zRange("thirdset", 0, -1));
|
||||
|
||||
verifyResults(
|
||||
Arrays.asList(new Object[] { 1l, 1l, 1l, 1l, 1l, 3l,
|
||||
Arrays.asList(new String[] { "Bob", "James", "Joe" }) }), actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testZUnionStoreAggWeights() {
|
||||
actual.add(connection.zAdd("myset", 2, "Bob"));
|
||||
actual.add(connection.zAdd("myset", 1, "James"));
|
||||
actual.add(connection.zAdd("myset", 4, "Joe"));
|
||||
actual.add(connection.zAdd("otherset", 1, "Bob"));
|
||||
actual.add(connection.zAdd("otherset", 4, "James"));
|
||||
actual.add(connection.zUnionStore("thirdset", Aggregate.MAX, new int[] { 2, 3 }, "myset",
|
||||
"otherset"));
|
||||
actual.add(connection.zRangeWithScores("thirdset", 0, -1));
|
||||
|
||||
verifyResults(
|
||||
Arrays.asList(new Object[] {
|
||||
1l,
|
||||
1l,
|
||||
1l,
|
||||
1l,
|
||||
1l,
|
||||
3l,
|
||||
Arrays.asList(new StringTuple[] {
|
||||
new DefaultStringTuple("Bob".getBytes(), "Bob", 4d),
|
||||
new DefaultStringTuple("Joe".getBytes(), "Joe", 8d),
|
||||
new DefaultStringTuple("James".getBytes(), "James", 12d) }) }),
|
||||
actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHDel() throws Exception {
|
||||
actual.add(connection.hSet("test", "key", "val"));
|
||||
actual.add(connection.hDel("test", "key"));
|
||||
actual.add(connection.hDel("test", "foo"));
|
||||
actual.add(connection.hExists("test", "key"));
|
||||
verifyResults(Arrays.asList(new Object[] { 1l, 1l, 0l, 0l }), actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHKeys() {
|
||||
convertResultToSet = true;
|
||||
actual.add(connection.hSet("test", "key", "2"));
|
||||
actual.add(connection.hSet("test", "key2", "2"));
|
||||
actual.add(connection.hKeys("test"));
|
||||
verifyResults(
|
||||
Arrays.asList(new Object[] { 1l, 1l,
|
||||
new LinkedHashSet<String>(Arrays.asList(new String[] { "key", "key2" })) }),
|
||||
actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHSetNX() throws Exception {
|
||||
actual.add(connection.hSetNX("myhash", "key1", "foo"));
|
||||
actual.add(connection.hSetNX("myhash", "key1", "bar"));
|
||||
actual.add(connection.hGet("myhash", "key1"));
|
||||
verifyResults(Arrays.asList(new Object[] { 1l, 0l, "foo" }), actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHIncrBy() {
|
||||
actual.add(connection.hSet("test", "key", "2"));
|
||||
actual.add(connection.hIncrBy("test", "key", 3l));
|
||||
actual.add(connection.hGet("test", "key"));
|
||||
verifyResults(Arrays.asList(new Object[] { 1l, 5l, "5" }), actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHLen() {
|
||||
actual.add(connection.hSet("test", "key", "2"));
|
||||
actual.add(connection.hSet("test", "key2", "2"));
|
||||
actual.add(connection.hLen("test"));
|
||||
verifyResults(Arrays.asList(new Object[] { 1l, 1l, 2l }), actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHVals() {
|
||||
actual.add(connection.hSet("test", "key", "foo"));
|
||||
actual.add(connection.hSet("test", "key2", "bar"));
|
||||
actual.add(connection.hVals("test"));
|
||||
verifyResults(Arrays.asList(new Object[] { 1l, 1l,
|
||||
Arrays.asList(new String[] { "foo", "bar" }) }), actual);
|
||||
}
|
||||
|
||||
protected void verifyResults(List<Object> expected, List<Object> actual) {
|
||||
List<Object> expectedPipeline = new ArrayList<Object>();
|
||||
for (int i = 0; i < actual.size(); i++) {
|
||||
expectedPipeline.add(null);
|
||||
}
|
||||
assertEquals(expectedPipeline, actual);
|
||||
List<Object> pipelinedResults = connection.closePipeline();
|
||||
assertEquals(expected, convertResults(pipelinedResults));
|
||||
}
|
||||
|
||||
protected List<Object> convertResults(List<Object> pipelinedResults) {
|
||||
List<Object> serializedResults = new ArrayList<Object>();
|
||||
for (Object result : pipelinedResults) {
|
||||
Object convertedResult = convertResult(result);
|
||||
if (!"OK".equals(convertedResult) && !"QUEUED".equals(convertedResult)) {
|
||||
serializedResults.add(convertedResult);
|
||||
}
|
||||
}
|
||||
return serializedResults;
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
protected Object convertResult(Object result) {
|
||||
if (result instanceof List && !(((List) result).isEmpty())
|
||||
&& ((List) result).get(0) instanceof byte[]) {
|
||||
return (SerializationUtils.deserialize((List<byte[]>) result, stringSerializer));
|
||||
} else if (result instanceof byte[]) {
|
||||
return (stringSerializer.deserialize((byte[]) result));
|
||||
} else if (result instanceof Map
|
||||
&& ((Map) result).keySet().iterator().next() instanceof byte[]) {
|
||||
return (SerializationUtils.deserialize((Map) result, stringSerializer));
|
||||
} else if (result instanceof Set && !(((Set) result).isEmpty())
|
||||
&& ((Set) result).iterator().next() instanceof byte[]) {
|
||||
return (SerializationUtils.deserialize((Set) result, stringSerializer));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -21,50 +21,58 @@ import static org.junit.Assert.assertEquals;
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.data.redis.connection.AbstractConnectionIntegrationTests;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
/**
|
||||
* Integration test of {@link JedisConnection}
|
||||
*
|
||||
* @author Costin Leau
|
||||
* @author Jennifer Hickey
|
||||
*
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration
|
||||
public class JedisConnectionIntegrationTests extends AbstractConnectionIntegrationTests {
|
||||
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
try {
|
||||
connection.flushDb();
|
||||
connection.close();
|
||||
}catch(DataAccessException e) {
|
||||
// Jedis leaves some incomplete data in OutputStream on NPE caused by null key/value tests
|
||||
// Attempting to close the connection will result in error on sending QUIT to Redis
|
||||
System.out.println("Connection already closed");
|
||||
} catch (Exception e) {
|
||||
// Jedis leaves some incomplete data in OutputStream on NPE caused
|
||||
// by null key/value tests
|
||||
// Attempting to flush the DB or close the connection will result in
|
||||
// error on sending QUIT to Redis
|
||||
}
|
||||
connection = null;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIncrDecrBy() {
|
||||
public void testIncrDecrByLong() {
|
||||
String key = "test.count";
|
||||
long largeNumber = 0x123456789L; // > 32bits
|
||||
connection.set(key.getBytes(), "0".getBytes());
|
||||
connection.incrBy(key.getBytes(), largeNumber);
|
||||
assertEquals(largeNumber, Long.valueOf(new String(connection.get(key.getBytes()))).longValue());
|
||||
connection.decrBy(key.getBytes(), largeNumber);
|
||||
assertEquals(0, Long.valueOf(new String(connection.get(key.getBytes()))).longValue());
|
||||
connection.decrBy(key.getBytes(), 2*largeNumber);
|
||||
assertEquals(-2*largeNumber, Long.valueOf(new String(connection.get(key.getBytes()))).longValue());
|
||||
connection.set(key, "0");
|
||||
connection.incrBy(key, largeNumber);
|
||||
assertEquals(largeNumber, Long.valueOf(connection.get(key)).longValue());
|
||||
connection.decrBy(key, largeNumber);
|
||||
assertEquals(0, Long.valueOf(connection.get(key)).longValue());
|
||||
connection.decrBy(key, 2 * largeNumber);
|
||||
assertEquals(-2 * largeNumber, Long.valueOf(connection.get(key)).longValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHashIncrDecrBy() {
|
||||
byte[] key = "test.hcount".getBytes();
|
||||
byte[] hkey = "hashkey".getBytes();
|
||||
public void testHashIncrDecrByLong() {
|
||||
String key = "test.hcount";
|
||||
String hkey = "hashkey";
|
||||
|
||||
long largeNumber = 0x123456789L; // > 32bits
|
||||
connection.hSet(key, hkey, "0".getBytes());
|
||||
connection.hSet(key, hkey, "0");
|
||||
connection.hIncrBy(key, hkey, largeNumber);
|
||||
assertEquals(largeNumber, Long.valueOf(new String(connection.hGet(key, hkey))).longValue());
|
||||
connection.hIncrBy(key, hkey, -2*largeNumber);
|
||||
assertEquals(-largeNumber, Long.valueOf(new String(connection.hGet(key, hkey))).longValue());
|
||||
assertEquals(largeNumber, Long.valueOf(connection.hGet(key, hkey)).longValue());
|
||||
connection.hIncrBy(key, hkey, -2 * largeNumber);
|
||||
assertEquals(-largeNumber, Long.valueOf(connection.hGet(key, hkey)).longValue());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,277 @@
|
||||
/*
|
||||
* Copyright 2011-2013 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.jedis;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.data.redis.RedisSystemException;
|
||||
import org.springframework.data.redis.connection.AbstractConnectionPipelineIntegrationTests;
|
||||
import org.springframework.data.redis.connection.DefaultStringTuple;
|
||||
import org.springframework.data.redis.connection.StringRedisConnection.StringTuple;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import redis.clients.jedis.Tuple;
|
||||
|
||||
/**
|
||||
* Integration test of {@link JedisConnection} pipeline functionality
|
||||
*
|
||||
* @author Jennifer Hickey
|
||||
*
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration("JedisConnectionIntegrationTests-context.xml")
|
||||
public class JedisConnectionPipelineIntegrationTests extends
|
||||
AbstractConnectionPipelineIntegrationTests {
|
||||
|
||||
/**
|
||||
* Individual results from closePipeline should be converted from
|
||||
* LinkedHashSet to List
|
||||
**/
|
||||
private boolean convertResultToList;
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
try {
|
||||
connection.flushDb();
|
||||
connection.close();
|
||||
} catch (Exception e) {
|
||||
// Jedis leaves some incomplete data in OutputStream on NPE caused
|
||||
// by null key/value tests
|
||||
// Attempting to close the connection will result in error on
|
||||
// sending QUIT to Redis
|
||||
}
|
||||
connection = null;
|
||||
}
|
||||
|
||||
@Ignore("DATAREDIS-141 Jedis dbSize/flush ops execute synchronously while pipelining")
|
||||
public void testDbSize() {
|
||||
}
|
||||
|
||||
@Ignore("DATAREDIS-141 Jedis dbSize/flush ops execute synchronously while pipelining")
|
||||
public void testFlushDb() {
|
||||
}
|
||||
|
||||
@Ignore("DATAREDIS-138 NPE in DefaultStringRedisConnection deserializing a null Map")
|
||||
public void testHSetGet() throws Exception {
|
||||
// String hash = getClass() + ":hashtest";
|
||||
// String key1 = UUID.randomUUID().toString();
|
||||
// String key2 = UUID.randomUUID().toString();
|
||||
// String value1 = "foo";
|
||||
// String value2 = "bar";
|
||||
// actual.add(connection.hSet(hash, key1, value1));
|
||||
// actual.add(connection.hSet(hash, key2, value2));
|
||||
// actual.add(connection.hGet(hash, key1));
|
||||
// actual.add(connection.hGetAll(hash));
|
||||
// Map<String, String> expected = new HashMap<String, String>();
|
||||
// expected.put(key1, value1);
|
||||
// expected.put(key2, value2);
|
||||
// verifyResults(Arrays.asList(new Object[] { 1l, 1l, value1, expected
|
||||
// }), actual);
|
||||
}
|
||||
|
||||
@Ignore("DATAREDIS-143 Jedis ClassCastExceptions closing pipeline on certain ops")
|
||||
public void testGetConfig() {
|
||||
}
|
||||
|
||||
@Ignore("DATAREDIS-143 Jedis ClassCastExceptions closing pipeline on certain ops")
|
||||
public void testWatch() {
|
||||
}
|
||||
|
||||
@Ignore("DATAREDIS-143 Jedis ClassCastExceptions closing pipeline on certain ops")
|
||||
public void testUnwatch() {
|
||||
}
|
||||
|
||||
@Ignore("DATAREDIS-143 Jedis ClassCastExceptions closing pipeline on certain ops")
|
||||
public void testSortStore() {
|
||||
}
|
||||
|
||||
@Ignore("DATAREDIS-143 Jedis ClassCastExceptions closing pipeline on certain ops")
|
||||
public void testMultiExec() {
|
||||
}
|
||||
|
||||
@Ignore("DATAREDIS-143 Jedis NPE closing pipeline on certain ops")
|
||||
public void testMultiDiscard() {
|
||||
}
|
||||
|
||||
@Ignore("DATAREDIS-155 Exists returns true after key is supposed to expire")
|
||||
public void testExpire() throws Exception {
|
||||
}
|
||||
|
||||
@Ignore("DATAREDIS-155 Exists returns true after key is supposed to expire")
|
||||
public void testSetEx() {
|
||||
}
|
||||
|
||||
// Unsupported Ops
|
||||
@Test(expected = RedisSystemException.class)
|
||||
public void testBitSet() throws Exception {
|
||||
super.testBitSet();
|
||||
}
|
||||
|
||||
@Test(expected = RedisSystemException.class)
|
||||
public void testRandomKey() {
|
||||
super.testRandomKey();
|
||||
}
|
||||
|
||||
@Test(expected = RedisSystemException.class)
|
||||
public void testGetRangeSetRange() {
|
||||
super.testGetRangeSetRange();
|
||||
}
|
||||
|
||||
@Test(expected = RedisSystemException.class)
|
||||
public void testPingPong() throws Exception {
|
||||
super.testPingPong();
|
||||
}
|
||||
|
||||
@Test(expected = RedisSystemException.class)
|
||||
public void testInfo() throws Exception {
|
||||
super.testInfo();
|
||||
}
|
||||
|
||||
// Overrides, usually due to return values being Long vs Boolean or Set vs
|
||||
// List
|
||||
|
||||
@Test
|
||||
public void testRenameNx() {
|
||||
connection.set("nxtest", "testit");
|
||||
actual.add(connection.renameNX("nxtest", "newnxtest"));
|
||||
actual.add(connection.get("newnxtest"));
|
||||
actual.add(connection.exists("nxtest"));
|
||||
verifyResults(Arrays.asList(new Object[] { 1l, "testit", false }), actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testKeys() throws Exception {
|
||||
convertResultToList = true;
|
||||
super.testKeys();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testZAddAndZRange() {
|
||||
convertResultToList = true;
|
||||
super.testZAddAndZRange();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testZIncrBy() {
|
||||
convertResultToList = true;
|
||||
super.testZIncrBy();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testZInterStore() {
|
||||
convertResultToList = true;
|
||||
super.testZInterStore();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testZRangeByScore() {
|
||||
convertResultToList = true;
|
||||
super.testZRangeByScore();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testZRangeByScoreOffsetCount() {
|
||||
convertResultToList = true;
|
||||
super.testZRangeByScoreOffsetCount();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testZRevRange() {
|
||||
convertResultToList = true;
|
||||
super.testZRevRange();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testZRem() {
|
||||
convertResultToList = true;
|
||||
super.testZRem();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testZRemRangeByScore() {
|
||||
convertResultToList = true;
|
||||
super.testZRemRangeByScore();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testZUnionStore() {
|
||||
convertResultToList = true;
|
||||
super.testZUnionStore();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testZRemRangeByRank() {
|
||||
convertResultToList = true;
|
||||
super.testZRemRangeByRank();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHDel() throws Exception {
|
||||
actual.add(connection.hSet("test", "key", "val"));
|
||||
actual.add(connection.hDel("test", "key"));
|
||||
actual.add(connection.hDel("test", "foo"));
|
||||
actual.add(connection.hExists("test", "key"));
|
||||
verifyResults(Arrays.asList(new Object[] { 1l, 1l, 0l, false }), actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExpireAt() throws Exception {
|
||||
connection.set("exp2", "true");
|
||||
actual.add(connection.expireAt("exp2", System.currentTimeMillis() / 1000 + 1));
|
||||
Thread.sleep(2000);
|
||||
actual.add(connection.exists("exp2"));
|
||||
verifyResults(Arrays.asList(new Object[] { 1l, false }), actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPersist() throws Exception {
|
||||
connection.set("exp3", "true");
|
||||
actual.add(connection.expire("exp3", 1));
|
||||
actual.add(connection.persist("exp3"));
|
||||
Thread.sleep(1500);
|
||||
actual.add(connection.exists("exp3"));
|
||||
verifyResults(Arrays.asList(new Object[] { 1l, 1l, true }), actual);
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
protected Object convertResult(Object result) {
|
||||
Object convertedResult = super.convertResult(result);
|
||||
if (convertedResult instanceof Set) {
|
||||
if (convertResultToList) {
|
||||
// Other providers represent zSets as Lists, so transform here
|
||||
return new ArrayList((Set) result);
|
||||
} else if (!(((Set) result).isEmpty())
|
||||
&& ((Set) convertedResult).iterator().next() instanceof Tuple) {
|
||||
List<StringTuple> tuples = new ArrayList<StringTuple>();
|
||||
for (Tuple value : ((Set<Tuple>) convertedResult)) {
|
||||
DefaultStringTuple tuple = new DefaultStringTuple(
|
||||
(byte[]) value.getBinaryElement(), value.getElement(), value.getScore());
|
||||
tuples.add(tuple);
|
||||
}
|
||||
return tuples;
|
||||
}
|
||||
}
|
||||
return convertedResult;
|
||||
}
|
||||
}
|
||||
@@ -16,69 +16,77 @@
|
||||
|
||||
package org.springframework.data.redis.connection.jredis;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.data.redis.connection.AbstractConnectionIntegrationTests;
|
||||
import org.springframework.data.redis.connection.DefaultSortParameters;
|
||||
import org.springframework.data.redis.connection.SortParameters.Order;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
/**
|
||||
* Integration test of {@link JredisConnection}
|
||||
*
|
||||
* @author Costin Leau
|
||||
* @author Jennifer Hickey
|
||||
*
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration
|
||||
public class JRedisConnectionIntegrationTests extends AbstractConnectionIntegrationTests {
|
||||
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
try {
|
||||
connection.flushDb();
|
||||
connection.close();
|
||||
}catch(DataAccessException e) {
|
||||
// Jredis closes a connection on Exception (which some tests intentionally throw)
|
||||
} catch (DataAccessException e) {
|
||||
// Jredis closes a connection on Exception (which some tests
|
||||
// intentionally throw)
|
||||
// Attempting to close the connection again will result in error
|
||||
System.out.println("Connection already closed");
|
||||
}
|
||||
connection = null;
|
||||
}
|
||||
|
||||
@Ignore("JRedis does not support pipelining")
|
||||
public void testNullCollections() {
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Ignore("nulls are encoded to empty strings")
|
||||
public void testNullKey() throws Exception {
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Ignore("nulls are encoded to empty strings")
|
||||
public void testNullValue() throws Exception {
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Ignore("nulls are encoded to empty strings")
|
||||
public void testHashNullKey() throws Exception {
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Ignore("nulls are encoded to empty strings")
|
||||
public void testHashNullValue() throws Exception {
|
||||
}
|
||||
|
||||
@Ignore
|
||||
public void testNullSerialization() throws Exception {
|
||||
}
|
||||
|
||||
@Ignore
|
||||
public void testPubSub() throws Exception {
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Ignore("Pub/Sub not supported")
|
||||
public void testPubSubWithPatterns() {
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Ignore("Pub/Sub not supported")
|
||||
public void testPubSubWithNamedChannels() {
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Ignore("DATAREDIS-129 Key search does not work with regex")
|
||||
public void testKeys() throws Exception {
|
||||
}
|
||||
|
||||
@Test(expected = UnsupportedOperationException.class)
|
||||
public void testBitSet() throws Exception {
|
||||
super.testBitSet();
|
||||
}
|
||||
|
||||
@Test(expected = UnsupportedOperationException.class)
|
||||
@@ -91,28 +99,19 @@ public class JRedisConnectionIntegrationTests extends AbstractConnectionIntegrat
|
||||
super.testMultiDiscard();
|
||||
}
|
||||
|
||||
@Ignore
|
||||
public void exceptionExecuteNativeWithPipeline() throws Exception {
|
||||
@Test(expected = UnsupportedOperationException.class)
|
||||
public void testWatch() throws Exception {
|
||||
super.testWatch();
|
||||
}
|
||||
|
||||
@Test(expected = UnsupportedOperationException.class)
|
||||
public void testExceptionExecuteNativeWithPipeline() throws Exception {
|
||||
super.testExceptionExecuteNativeWithPipeline();
|
||||
public void testUnwatch() throws Exception {
|
||||
super.testUnwatch();
|
||||
}
|
||||
|
||||
@Test(expected = UnsupportedOperationException.class)
|
||||
public void testExecuteNativeWithPipeline() throws Exception {
|
||||
super.testExecuteNativeWithPipeline();
|
||||
}
|
||||
|
||||
@Test(expected = UnsupportedOperationException.class)
|
||||
public void testBlPopTimeout() {
|
||||
super.testBlPopTimeout();
|
||||
}
|
||||
|
||||
@Test(expected = UnsupportedOperationException.class)
|
||||
public void testBlPop() {
|
||||
super.testBlPop();
|
||||
public void testBLPop() {
|
||||
super.testBLPop();
|
||||
}
|
||||
|
||||
@Test(expected = UnsupportedOperationException.class)
|
||||
@@ -121,7 +120,214 @@ public class JRedisConnectionIntegrationTests extends AbstractConnectionIntegrat
|
||||
}
|
||||
|
||||
@Test(expected = UnsupportedOperationException.class)
|
||||
public void testBRPopTimeout() {
|
||||
public void testLInsert() {
|
||||
super.testLInsert();
|
||||
}
|
||||
|
||||
@Test(expected = UnsupportedOperationException.class)
|
||||
public void testBRPopLPush() {
|
||||
super.testBRPopLPush();
|
||||
}
|
||||
|
||||
@Test(expected = UnsupportedOperationException.class)
|
||||
public void testLPushX() {
|
||||
super.testLPushX();
|
||||
}
|
||||
|
||||
@Test(expected = UnsupportedOperationException.class)
|
||||
public void testRPushX() {
|
||||
super.testRPushX();
|
||||
}
|
||||
|
||||
@Test(expected = UnsupportedOperationException.class)
|
||||
public void testGetRangeSetRange() {
|
||||
super.testGetRangeSetRange();
|
||||
}
|
||||
|
||||
@Test(expected = UnsupportedOperationException.class)
|
||||
public void testStrLen() {
|
||||
super.testStrLen();
|
||||
}
|
||||
|
||||
@Test(expected = UnsupportedOperationException.class)
|
||||
public void testGetConfig() {
|
||||
super.testGetConfig();
|
||||
}
|
||||
|
||||
@Test(expected = UnsupportedOperationException.class)
|
||||
public void testZInterStore() {
|
||||
super.testZInterStore();
|
||||
}
|
||||
|
||||
@Test(expected = UnsupportedOperationException.class)
|
||||
public void testZInterStoreAggWeights() {
|
||||
super.testZInterStoreAggWeights();
|
||||
}
|
||||
|
||||
@Test(expected = UnsupportedOperationException.class)
|
||||
public void testZRangeWithScores() {
|
||||
super.testZRangeWithScores();
|
||||
}
|
||||
|
||||
@Test(expected = UnsupportedOperationException.class)
|
||||
public void testZRangeByScoreOffsetCount() {
|
||||
super.testZRangeByScoreOffsetCount();
|
||||
}
|
||||
|
||||
@Test(expected = UnsupportedOperationException.class)
|
||||
public void testZRangeByScoreWithScores() {
|
||||
super.testZRangeByScoreWithScores();
|
||||
}
|
||||
|
||||
@Test(expected = UnsupportedOperationException.class)
|
||||
public void testZRangeByScoreWithScoresOffsetCount() {
|
||||
super.testZRangeByScoreWithScoresOffsetCount();
|
||||
}
|
||||
|
||||
@Test(expected = UnsupportedOperationException.class)
|
||||
public void testZRevRangeWithScores() {
|
||||
super.testZRevRangeWithScores();
|
||||
}
|
||||
|
||||
@Test(expected = UnsupportedOperationException.class)
|
||||
public void testZUnionStore() {
|
||||
super.testZUnionStore();
|
||||
}
|
||||
|
||||
@Test(expected = UnsupportedOperationException.class)
|
||||
public void testZUnionStoreAggWeights() {
|
||||
super.testZUnionStoreAggWeights();
|
||||
}
|
||||
|
||||
@Test(expected = UnsupportedOperationException.class)
|
||||
public void testHSetNX() throws Exception {
|
||||
super.testHSetNX();
|
||||
}
|
||||
|
||||
@Test(expected = UnsupportedOperationException.class)
|
||||
public void testHIncrBy() {
|
||||
super.testHIncrBy();
|
||||
}
|
||||
|
||||
@Test(expected = UnsupportedOperationException.class)
|
||||
public void testHMGetSet() {
|
||||
super.testHMGetSet();
|
||||
}
|
||||
|
||||
@Test(expected = UnsupportedOperationException.class)
|
||||
public void testPersist() throws Exception {
|
||||
super.testPersist();
|
||||
}
|
||||
|
||||
@Test(expected = UnsupportedOperationException.class)
|
||||
public void testSetEx() throws Exception {
|
||||
super.testSetEx();
|
||||
}
|
||||
|
||||
@Test(expected = UnsupportedOperationException.class)
|
||||
public void testBRPopTimeout() throws Exception {
|
||||
super.testBRPopTimeout();
|
||||
}
|
||||
|
||||
@Test(expected = UnsupportedOperationException.class)
|
||||
public void testBLPopTimeout() throws Exception {
|
||||
super.testBLPopTimeout();
|
||||
}
|
||||
|
||||
@Test(expected = UnsupportedOperationException.class)
|
||||
public void testBRPopLPushTimeout() throws Exception {
|
||||
super.testBRPopLPushTimeout();
|
||||
}
|
||||
|
||||
// Jredis returns null for rPush
|
||||
@Test
|
||||
public void testSort() {
|
||||
connection.rPush("sortlist", "foo");
|
||||
connection.rPush("sortlist", "bar");
|
||||
connection.rPush("sortlist", "baz");
|
||||
assertEquals(Arrays.asList(new String[] { "bar", "baz", "foo" }),
|
||||
connection.sort("sortlist", new DefaultSortParameters(null, Order.ASC, true)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSortStore() {
|
||||
connection.rPush("sortlist", "foo");
|
||||
connection.rPush("sortlist", "bar");
|
||||
connection.rPush("sortlist", "baz");
|
||||
assertEquals(Long.valueOf(3), connection.sort("sortlist", new DefaultSortParameters(null,
|
||||
Order.ASC, true), "newlist"));
|
||||
assertEquals(Arrays.asList(new String[] { "bar", "baz", "foo" }),
|
||||
connection.lRange("newlist", 0, 9));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLPop() {
|
||||
connection.rPush("PopList", "hello");
|
||||
connection.rPush("PopList", "world");
|
||||
assertEquals("hello", connection.lPop("PopList"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLRem() {
|
||||
connection.rPush("PopList", "hello");
|
||||
connection.rPush("PopList", "big");
|
||||
connection.rPush("PopList", "world");
|
||||
connection.rPush("PopList", "hello");
|
||||
assertEquals(Long.valueOf(2), connection.lRem("PopList", 2, "hello"));
|
||||
assertEquals(Arrays.asList(new String[] { "big", "world" }),
|
||||
connection.lRange("PopList", 0, -1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLSet() {
|
||||
connection.rPush("PopList", "hello");
|
||||
connection.rPush("PopList", "big");
|
||||
connection.rPush("PopList", "world");
|
||||
connection.lSet("PopList", 1, "cruel");
|
||||
assertEquals(Arrays.asList(new String[] { "hello", "cruel", "world" }),
|
||||
connection.lRange("PopList", 0, -1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLTrim() {
|
||||
connection.rPush("PopList", "hello");
|
||||
connection.rPush("PopList", "big");
|
||||
connection.rPush("PopList", "world");
|
||||
connection.lTrim("PopList", 1, -1);
|
||||
assertEquals(Arrays.asList(new String[] { "big", "world" }),
|
||||
connection.lRange("PopList", 0, -1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRPop() {
|
||||
connection.rPush("PopList", "hello");
|
||||
connection.rPush("PopList", "world");
|
||||
assertEquals("world", connection.rPop("PopList"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRPopLPush() {
|
||||
connection.rPush("PopList", "hello");
|
||||
connection.rPush("PopList", "world");
|
||||
connection.rPush("pop2", "hey");
|
||||
assertEquals("world", connection.rPopLPush("PopList", "pop2"));
|
||||
assertEquals(Arrays.asList(new String[] { "hello" }), connection.lRange("PopList", 0, -1));
|
||||
assertEquals(Arrays.asList(new String[] { "world", "hey" }),
|
||||
connection.lRange("pop2", 0, -1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLIndex() {
|
||||
connection.lPush("testylist", "foo");
|
||||
assertEquals("foo", connection.lIndex("testylist", 0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLPush() throws Exception {
|
||||
connection.lPush("testlist", "bar");
|
||||
connection.lPush("testlist", "baz");
|
||||
assertEquals(Arrays.asList(new String[] { "baz", "bar" }),
|
||||
connection.lRange("testlist", 0, -1));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -16,33 +16,28 @@
|
||||
|
||||
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.junit.Ignore;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.data.redis.connection.AbstractConnectionIntegrationTests;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
/**
|
||||
* Integration test of {@link LettuceConnection}
|
||||
*
|
||||
* @author Costin Leau
|
||||
* @author Jennifer Hickey
|
||||
*
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration
|
||||
public class LettuceConnectionIntegrationTests extends AbstractConnectionIntegrationTests {
|
||||
|
||||
@Ignore("DATAREDIS-122 exec never returns null")
|
||||
public void testWatch() throws Exception {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultiExec() 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", results.get(0));
|
||||
assertEquals(new String(value), new String((byte[])results.get(1)));
|
||||
@Ignore("DATAREDIS-122 exec never returns null")
|
||||
public void testUnwatch() throws Exception {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,268 @@
|
||||
/*
|
||||
* Copyright 2011-2013 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.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.data.redis.connection.AbstractConnectionPipelineIntegrationTests;
|
||||
import org.springframework.data.redis.connection.DefaultStringTuple;
|
||||
import org.springframework.data.redis.connection.StringRedisConnection.StringTuple;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import com.lambdaworks.redis.KeyValue;
|
||||
import com.lambdaworks.redis.ScoredValue;
|
||||
|
||||
/**
|
||||
* Integration test of {@link LettuceConnection} pipeline functionality
|
||||
*
|
||||
* @author Jennifer Hickey
|
||||
*
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration("LettuceConnectionIntegrationTests-context.xml")
|
||||
public class LettuceConnectionPipelineIntegrationTests extends
|
||||
AbstractConnectionPipelineIntegrationTests {
|
||||
|
||||
@Ignore("DATAREDIS-144 Lettuce closePipeline hangs with discarded transaction")
|
||||
public void testMultiDiscard() {
|
||||
}
|
||||
|
||||
@Ignore("DATAREDIS-122 exec never returns null")
|
||||
public void testWatch() throws Exception {
|
||||
}
|
||||
|
||||
@Ignore("DATAREDIS-122 exec never returns null")
|
||||
public void testUnwatch() throws Exception {
|
||||
}
|
||||
|
||||
@Ignore("DATAREDIS-139 Lettuce exec while pipelining returns a non-null value")
|
||||
public void testMultiExec() throws Exception {
|
||||
}
|
||||
|
||||
@Ignore("DATAREDIS-140 Lettuce zCount/zInterStore methods execute synchronously when pipelining")
|
||||
public void testZInterStoreAggWeights() {
|
||||
}
|
||||
|
||||
@Ignore("DATAREDIS-140 Lettuce zCount/zInterStore methods execute synchronously when pipelining")
|
||||
public void testZInterStore() {
|
||||
}
|
||||
|
||||
@Ignore("DATAREDIS-140 Lettuce zCount/zInterStore methods execute synchronously when pipelining")
|
||||
public void testZCount() {
|
||||
}
|
||||
|
||||
@Ignore("DATAREDIS-138 NPE in DefaultStringRedisConnection deserializing a null Map")
|
||||
public void testHSetGet() throws Exception {
|
||||
// String hash = getClass() + ":hashtest";
|
||||
// String key1 = UUID.randomUUID().toString();
|
||||
// String key2 = UUID.randomUUID().toString();
|
||||
// String value1 = "foo";
|
||||
// String value2 = "bar";
|
||||
// actual.add(connection.hSet(hash, key1, value1));
|
||||
// actual.add(connection.hSet(hash, key2, value2));
|
||||
// actual.add(connection.hGet(hash, key1));
|
||||
// actual.add(connection.hGetAll(hash));
|
||||
// Map<String, String> expected = new HashMap<String, String>();
|
||||
// expected.put(key1, value1);
|
||||
// expected.put(key2, value2);
|
||||
// verifyResults(Arrays.asList(new Object[] { true, true, value1,
|
||||
// expected }), actual);
|
||||
}
|
||||
|
||||
// Overrides, usually due to return values being Long vs Boolean or Set vs
|
||||
// List
|
||||
|
||||
@Test
|
||||
public void testInfo() throws Exception {
|
||||
assertNull(connection.info());
|
||||
List<Object> results = connection.closePipeline();
|
||||
assertEquals(1, results.size());
|
||||
Properties info = LettuceUtils.info((String) results.get(0));
|
||||
assertTrue("at least 5 settings should be present", info.size() >= 5);
|
||||
String version = info.getProperty("redis_version");
|
||||
assertNotNull(version);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMSetNx() {
|
||||
Map<String, String> vals = new HashMap<String, String>();
|
||||
vals.put("height", "5");
|
||||
vals.put("width", "1");
|
||||
connection.mSetNXString(vals);
|
||||
assertNull(connection.mGet("height", "width"));
|
||||
verifyResults(
|
||||
Arrays.asList(new Object[] { true, Arrays.asList(new String[] { "5", "1" }) }),
|
||||
actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetNx() {
|
||||
actual.add(connection.setNX("notaround", "54"));
|
||||
actual.add(connection.get("notaround"));
|
||||
actual.add(connection.setNX("notaround", "55"));
|
||||
actual.add(connection.get("notaround"));
|
||||
verifyResults(Arrays.asList(new Object[] { true, "54", false, "54" }), actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRenameNx() {
|
||||
connection.set("nxtest", "testit");
|
||||
actual.add(connection.renameNX("nxtest", "newnxtest"));
|
||||
actual.add(connection.get("newnxtest"));
|
||||
actual.add(connection.exists("nxtest"));
|
||||
verifyResults(Arrays.asList(new Object[] { true, "testit", false }), actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSMove() {
|
||||
convertResultToSet = true;
|
||||
actual.add(connection.sAdd("myset", "foo"));
|
||||
actual.add(connection.sAdd("myset", "bar"));
|
||||
actual.add(connection.sAdd("otherset", "bar"));
|
||||
actual.add(connection.sMove("myset", "otherset", "foo"));
|
||||
actual.add(connection.sMembers("otherset"));
|
||||
verifyResults(
|
||||
Arrays.asList(new Object[] { 1l, 1l, 1l, true,
|
||||
new HashSet<String>(Arrays.asList(new String[] { "foo", "bar" })) }),
|
||||
actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHKeys() {
|
||||
actual.add(connection.hSet("test", "key", "2"));
|
||||
actual.add(connection.hSet("test", "key2", "2"));
|
||||
actual.add(connection.hKeys("test"));
|
||||
verifyResults(
|
||||
Arrays.asList(new Object[] { true, true,
|
||||
Arrays.asList(new String[] { "key", "key2" }) }), actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHSetNX() throws Exception {
|
||||
actual.add(connection.hSetNX("myhash", "key1", "foo"));
|
||||
actual.add(connection.hSetNX("myhash", "key1", "bar"));
|
||||
actual.add(connection.hGet("myhash", "key1"));
|
||||
verifyResults(Arrays.asList(new Object[] { true, false, "foo" }), actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHIncrBy() {
|
||||
actual.add(connection.hSet("test", "key", "2"));
|
||||
actual.add(connection.hIncrBy("test", "key", 3l));
|
||||
actual.add(connection.hGet("test", "key"));
|
||||
verifyResults(Arrays.asList(new Object[] { true, 5l, "5" }), actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHLen() {
|
||||
actual.add(connection.hSet("test", "key", "2"));
|
||||
actual.add(connection.hSet("test", "key2", "2"));
|
||||
actual.add(connection.hLen("test"));
|
||||
verifyResults(Arrays.asList(new Object[] { true, true, 2l }), actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHVals() {
|
||||
actual.add(connection.hSet("test", "key", "foo"));
|
||||
actual.add(connection.hSet("test", "key2", "bar"));
|
||||
actual.add(connection.hVals("test"));
|
||||
verifyResults(
|
||||
Arrays.asList(new Object[] { true, true,
|
||||
Arrays.asList(new String[] { "foo", "bar" }) }), actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHDel() throws Exception {
|
||||
actual.add(connection.hSet("test", "key", "val"));
|
||||
actual.add(connection.hDel("test", "key"));
|
||||
actual.add(connection.hDel("test", "foo"));
|
||||
actual.add(connection.hExists("test", "key"));
|
||||
verifyResults(Arrays.asList(new Object[] { true, 1l, 0l, false }), actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPersist() throws Exception {
|
||||
connection.set("exp3", "true");
|
||||
actual.add(connection.expire("exp3", 1));
|
||||
actual.add(connection.persist("exp3"));
|
||||
Thread.sleep(1500);
|
||||
actual.add(connection.exists("exp3"));
|
||||
verifyResults(Arrays.asList(new Object[] { true, true, true }), actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExpireAt() throws Exception {
|
||||
connection.set("exp2", "true");
|
||||
actual.add(connection.expireAt("exp2", System.currentTimeMillis() / 1000 + 1));
|
||||
Thread.sleep(2000);
|
||||
actual.add(connection.exists("exp2"));
|
||||
verifyResults(Arrays.asList(new Object[] { true, false }), actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExpire() throws Exception {
|
||||
connection.set("exp", "true");
|
||||
actual.add(connection.expire("exp", 1));
|
||||
Thread.sleep(2000);
|
||||
actual.add(connection.exists("exp"));
|
||||
verifyResults(Arrays.asList(new Object[] { true, false }), actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetEx() throws Exception {
|
||||
connection.setEx("expy", 1l, "yep");
|
||||
actual.add(connection.get("expy"));
|
||||
Thread.sleep(2000);
|
||||
actual.add(connection.exists("expy"));
|
||||
verifyResults(Arrays.asList(new Object[] { "yep", false }), actual);
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
protected Object convertResult(Object result) {
|
||||
Object convertedResult = super.convertResult(result);
|
||||
if (convertedResult instanceof KeyValue) {
|
||||
List<String> keyValue = new ArrayList<String>();
|
||||
keyValue.add((String) super.convertResult(((KeyValue) convertedResult).key));
|
||||
keyValue.add((String) super.convertResult(((KeyValue) convertedResult).value));
|
||||
return keyValue;
|
||||
} else if (convertedResult instanceof List && !(((List) result).isEmpty())
|
||||
&& ((List) convertedResult).get(0) instanceof ScoredValue) {
|
||||
List<StringTuple> tuples = new ArrayList<StringTuple>();
|
||||
for (ScoredValue value : ((List<ScoredValue>) convertedResult)) {
|
||||
DefaultStringTuple tuple = new DefaultStringTuple((byte[]) value.value, new String(
|
||||
(byte[]) value.value), value.score);
|
||||
tuples.add(tuple);
|
||||
}
|
||||
return tuples;
|
||||
}
|
||||
return convertedResult;
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,12 @@
|
||||
/*
|
||||
* Copyright 2011-2013 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.
|
||||
@@ -19,7 +19,6 @@ import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
@@ -29,7 +28,11 @@ import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
/**
|
||||
* Integration test of {@link RjcConnection}
|
||||
*
|
||||
* @author Costin Leau
|
||||
* @author Jennifer Hickey
|
||||
*
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration
|
||||
@@ -46,27 +49,66 @@ public class RjcConnectionIntegrationTests extends AbstractConnectionIntegration
|
||||
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))));
|
||||
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)
|
||||
@Test
|
||||
public void testExecuteNativeWithPipeline() throws Exception {
|
||||
String key1 = getClass() + "#ExecuteNativeWithPipeline#1";
|
||||
String value1 = UUID.randomUUID().toString();
|
||||
String key2 = getClass() + "#ExecuteNativeWithPipeline#2";
|
||||
String value2 = UUID.randomUUID().toString();
|
||||
@Ignore("nulls are encoded to empty strings")
|
||||
public void testNullKey() throws Exception {
|
||||
}
|
||||
|
||||
connection.openPipeline();
|
||||
connection.execute("SET", key1, value1);
|
||||
connection.execute("SET", key2, value2);
|
||||
connection.execute("GET", key1);
|
||||
connection.execute("GET", key2);
|
||||
List<Object> result = connection.closePipeline();
|
||||
assertEquals(4, result.size());
|
||||
@Ignore("nulls are encoded to empty strings")
|
||||
public void testNullValue() throws Exception {
|
||||
}
|
||||
|
||||
@Ignore("nulls are encoded to empty strings")
|
||||
public void testHashNullKey() throws Exception {
|
||||
}
|
||||
|
||||
@Ignore("nulls are encoded to empty strings")
|
||||
public void testHashNullValue() throws Exception {
|
||||
}
|
||||
|
||||
@Ignore("DATAREDIS-133 Key search does not work with regex")
|
||||
public void testKeys() throws Exception {
|
||||
}
|
||||
|
||||
@Ignore("DATAREDIS-121 incr/decr does not work with encoded values")
|
||||
public void testDecrByIncrBy() {
|
||||
}
|
||||
|
||||
@Ignore("DATAREDIS-121 incr/decr does not work with encoded values")
|
||||
public void testIncDecr() {
|
||||
}
|
||||
|
||||
@Ignore("DATAREDIS-121 incr/decr does not work with encoded values")
|
||||
public void testHIncrBy() {
|
||||
}
|
||||
|
||||
@Ignore("DATAREDIS-134 string ops do not work with encoded values")
|
||||
public void testSort() {
|
||||
}
|
||||
|
||||
@Ignore("DATAREDIS-134 string ops do not work with encoded values")
|
||||
public void testSortStore() {
|
||||
}
|
||||
|
||||
@Ignore("DATAREDIS-134 string ops do not work with encoded values")
|
||||
public void testGetRangeSetRange() {
|
||||
}
|
||||
|
||||
@Ignore("DATAREDIS-134 string ops do not work with encoded values")
|
||||
public void testStrLen() {
|
||||
}
|
||||
|
||||
@Ignore("DATAREDIS-120 Pattern matching currently broken")
|
||||
public void testPubSubWithPatterns() {
|
||||
}
|
||||
|
||||
@Ignore("DATAREDIS-137 zRevRangeWithScores returns incorrect results")
|
||||
public void testZRevRangeWithScores() {
|
||||
}
|
||||
|
||||
@Ignore("DATAREDIS-148 Syntax error on RJC zUnionStore")
|
||||
public void testZUnionStoreAggWeights() {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,280 @@
|
||||
/*
|
||||
* Copyright 2011-2013 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.rjc;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.data.redis.connection.AbstractConnectionPipelineIntegrationTests;
|
||||
import org.springframework.data.redis.connection.DefaultStringRedisConnection;
|
||||
import org.springframework.data.redis.connection.DefaultStringTuple;
|
||||
import org.springframework.data.redis.connection.StringRedisConnection.StringTuple;
|
||||
import org.springframework.data.redis.serializer.SerializationUtils;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
/**
|
||||
* Integration test of {@link RjcConnection} pipeline functionality
|
||||
*
|
||||
* @author Jennifer Hickey
|
||||
*
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration
|
||||
public class RjcConnectionPipelineIntegrationTests extends
|
||||
AbstractConnectionPipelineIntegrationTests {
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
super.setUp();
|
||||
}
|
||||
|
||||
@Ignore("DATAREDIS-134 string ops do not work with encoded values")
|
||||
public void testGetRangeSetRange() {
|
||||
}
|
||||
|
||||
@Ignore("DATAREDIS-133 Key search does not work with regex")
|
||||
public void testKeys() throws Exception {
|
||||
}
|
||||
|
||||
@Ignore("DATAREDIS-121 incr/decr does not work with encoded values")
|
||||
public void testDecrByIncrBy() {
|
||||
}
|
||||
|
||||
@Ignore("DATAREDIS-121 incr/decr does not work with encoded values")
|
||||
public void testIncDecr() {
|
||||
}
|
||||
|
||||
@Ignore("DATAREDIS-121 incr/decr does not work with encoded values")
|
||||
public void testHIncrBy() {
|
||||
}
|
||||
|
||||
@Ignore("DATAREDIS-134 string ops do not work with encoded values")
|
||||
public void testSort() {
|
||||
}
|
||||
|
||||
@Ignore("DATAREDIS-134 string ops do not work with encoded values")
|
||||
public void testSortStore() {
|
||||
}
|
||||
|
||||
@Ignore("DATAREDIS-134 string ops do not work with encoded values")
|
||||
public void testStrLen() {
|
||||
}
|
||||
|
||||
@Ignore("DATAREDIS-137 zRevRangeWithScores returns incorrect results")
|
||||
public void testZRevRangeWithScores() {
|
||||
}
|
||||
|
||||
@Ignore("DATAREDIS-138 NPE in DefaultStringRedisConnection deserializing a null Map")
|
||||
public void testHSetGet() throws Exception {
|
||||
// String hash = getClass() + ":hashtest";
|
||||
// String key1 = UUID.randomUUID().toString();
|
||||
// String key2 = UUID.randomUUID().toString();
|
||||
// String value1 = "foo";
|
||||
// String value2 = "bar";
|
||||
// actual.add(connection.hSet(hash, key1, value1));
|
||||
// actual.add(connection.hSet(hash, key2, value2));
|
||||
// actual.add(connection.hGet(hash, key1));
|
||||
// actual.add(connection.hGetAll(hash));
|
||||
// List<String> expected = Arrays.asList(new String[] { key1, value1,
|
||||
// key2, value2 });
|
||||
// verifyResults(Arrays.asList(new Object[] { 1l, 1l, value1, expected
|
||||
// }), actual);
|
||||
}
|
||||
|
||||
@Ignore("DATAREDIS-148 Syntax error on RJC zUnionStore")
|
||||
public void testZUnionStoreAggWeights() {
|
||||
}
|
||||
|
||||
@Ignore("DATAREDIS-149 Wrong number of args on RJC brPop when pipelining")
|
||||
public void testBRPop() {
|
||||
}
|
||||
|
||||
@Ignore("DATAREDIS-149 Wrong number of args on RJC brPop when pipelining")
|
||||
public void testBLPop() {
|
||||
}
|
||||
|
||||
@Ignore("DATAREDIS-149 Wrong number of args on RJC brPop when pipelining")
|
||||
public void testBRPopTimeout() {
|
||||
}
|
||||
|
||||
@Ignore("DATAREDIS-149 Wrong number of args on RJC brPop when pipelining")
|
||||
public void testBLPopTimeout() {
|
||||
}
|
||||
|
||||
@Ignore("DATAREDIS-150 the 6 from zIncrBy improperly decoded")
|
||||
public void testZIncrBy() {
|
||||
}
|
||||
|
||||
@Ignore("DATAREDIS-150 the 3 from zScore improperly decoded")
|
||||
public void testZScore() {
|
||||
}
|
||||
|
||||
@Ignore("DATAREDIS-150 the results of info improperly decoded")
|
||||
public void testInfo() throws Exception {
|
||||
}
|
||||
|
||||
@Ignore("DATAREDIS-150 the results of ping improperly decoded")
|
||||
public void testPingPong() throws Exception {
|
||||
}
|
||||
|
||||
@Ignore("DATAREDIS-150 the results of tye improperly decoded")
|
||||
public void testType() {
|
||||
}
|
||||
|
||||
// Overrides, usually due to return values being Long vs Boolean or Set vs
|
||||
// List
|
||||
|
||||
@Test
|
||||
public void testSIsMember() {
|
||||
convertResultToSet = true;
|
||||
actual.add(connection.sAdd("myset", "foo"));
|
||||
actual.add(connection.sAdd("myset", "bar"));
|
||||
actual.add(connection.sIsMember("myset", "foo"));
|
||||
actual.add(connection.sIsMember("myset", "baz"));
|
||||
verifyResults(Arrays.asList(new Object[] { 1l, 1l, 1l, 0l }), actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRename() {
|
||||
connection.set("renametest", "testit");
|
||||
connection.rename("renametest", "newrenametest");
|
||||
actual.add(connection.get("newrenametest"));
|
||||
actual.add(connection.exists("renametest"));
|
||||
verifyResults(Arrays.asList(new Object[] { "testit", 0l }), actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExists() {
|
||||
connection.set("existent", "true");
|
||||
actual.add(connection.exists("existent"));
|
||||
actual.add(connection.exists("nonexistent"));
|
||||
verifyResults(Arrays.asList(new Object[] { 1l, 0l }), actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultiExec() throws Exception {
|
||||
connection.multi();
|
||||
connection.set("key", "value");
|
||||
assertNull(connection.get("key"));
|
||||
assertNull(connection.exec());
|
||||
List<Object> convertedResults = convertResults(connection.closePipeline());
|
||||
// "OK" will be decoded to null
|
||||
assertEquals(Arrays.asList(new Object[] { Arrays.asList(new String[] { null, "value" }) }),
|
||||
convertedResults);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWatch() throws Exception {
|
||||
connection.set("testitnow", "willdo");
|
||||
connection.watch("testitnow".getBytes());
|
||||
DefaultStringRedisConnection conn2 = new DefaultStringRedisConnection(
|
||||
connectionFactory.getConnection());
|
||||
conn2.set("testitnow", "something");
|
||||
conn2.close();
|
||||
connection.multi();
|
||||
connection.set("testitnow", "somethingelse");
|
||||
actual.add(connection.exec());
|
||||
actual.add(connection.get("testitnow"));
|
||||
List<Object> convertedResults = convertResults(connection.closePipeline());
|
||||
// The null returned from exec will be filtered out
|
||||
assertEquals(Arrays.asList(new String[] { "something" }), convertedResults);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUnwatch() throws Exception {
|
||||
connection.set("testitnow", "willdo");
|
||||
connection.watch("testitnow".getBytes());
|
||||
connection.unwatch();
|
||||
connection.multi();
|
||||
DefaultStringRedisConnection conn2 = new DefaultStringRedisConnection(
|
||||
connectionFactory.getConnection());
|
||||
conn2.set("testitnow", "something");
|
||||
connection.set("testitnow", "somethingelse");
|
||||
connection.get("testitnow");
|
||||
connection.exec();
|
||||
List<Object> convertedResults = convertResults(connection.closePipeline());
|
||||
// "OK" will be decoded to null
|
||||
assertEquals(Arrays.asList(new Object[] { Arrays.asList(new String[] { null,
|
||||
"somethingelse" }) }), convertedResults);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBRPopLPushTimeout() throws Exception {
|
||||
connection.bRPopLPush(1, "alist", "foo");
|
||||
Thread.sleep(1500l);
|
||||
List<Object> results = connection.closePipeline();
|
||||
assertEquals(Arrays.asList(new Object[] { null }), results);
|
||||
}
|
||||
|
||||
protected List<Object> convertResults(List<Object> pipelinedResults) {
|
||||
List<Object> serializedResults = new ArrayList<Object>();
|
||||
for (Object result : pipelinedResults) {
|
||||
Object convertedResult = convertResult(result);
|
||||
// closePipeline attempts to decode "OK" and "QUEUED" which turn
|
||||
// them into null
|
||||
// Filter them out here
|
||||
if (convertedResult != null && !"OK".equals(convertedResult)
|
||||
&& !"QUEUED".equals(convertedResult)) {
|
||||
serializedResults.add(convertedResult);
|
||||
}
|
||||
}
|
||||
return serializedResults;
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
protected Object convertResult(Object result) {
|
||||
if (result instanceof List && !(((List) result).isEmpty())
|
||||
&& ((List) result).get(0) instanceof String) {
|
||||
if (convertResultToSet) {
|
||||
return SerializationUtils.deserialize(RjcUtils.convertToSet((List) result),
|
||||
stringSerializer);
|
||||
} else if (convertResultToTuples) {
|
||||
List resultList = (List) result;
|
||||
List<StringTuple> stringTuples = new ArrayList<StringTuple>();
|
||||
for (int i = 0; i < resultList.size(); i += 2) {
|
||||
String value = stringSerializer.deserialize(RjcUtils.encode((String) resultList
|
||||
.get(i)));
|
||||
stringTuples.add(new DefaultStringTuple(value.getBytes(), value, Double
|
||||
.valueOf((String) resultList.get(i + 1))));
|
||||
}
|
||||
return stringTuples;
|
||||
} else {
|
||||
return SerializationUtils.deserialize(RjcUtils.convertToList((List) result),
|
||||
stringSerializer);
|
||||
}
|
||||
} else if (result instanceof byte[]) {
|
||||
return stringSerializer.deserialize((byte[]) result);
|
||||
} else if (result instanceof Map
|
||||
&& ((Map) result).keySet().iterator().next() instanceof byte[]) {
|
||||
return (SerializationUtils.deserialize((Map) result, stringSerializer));
|
||||
} else if (result instanceof Set && !(((Set) result).isEmpty())
|
||||
&& ((Set) result).iterator().next() instanceof byte[]) {
|
||||
return (SerializationUtils.deserialize((Set) result, stringSerializer));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -16,21 +16,36 @@
|
||||
|
||||
package org.springframework.data.redis.connection.srp;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.data.redis.connection.AbstractConnectionIntegrationTests;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
/**
|
||||
* Integration test of {@link SrpConnection}
|
||||
*
|
||||
* @author Costin Leau
|
||||
* @author Jennifer Hickey
|
||||
*
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration
|
||||
public class SrpConnectionIntegrationTests extends AbstractConnectionIntegrationTests {
|
||||
|
||||
@Ignore
|
||||
public void testNullCollections() throws Exception {
|
||||
@After
|
||||
public void tearDown() {
|
||||
try {
|
||||
connection.flushDb();
|
||||
} catch (Exception e) {
|
||||
// SRP doesn't allow other commands to be executed once subscribed,
|
||||
// so
|
||||
// this fails after pub/sub tests
|
||||
}
|
||||
connection.close();
|
||||
connection = null;
|
||||
}
|
||||
|
||||
@Ignore("DATAREDIS-123, exec does not return command results")
|
||||
@@ -41,7 +56,45 @@ public class SrpConnectionIntegrationTests extends AbstractConnectionIntegration
|
||||
public void testMultiDiscard() {
|
||||
}
|
||||
|
||||
@Ignore("DATAREDIS-123, exec does not return command results")
|
||||
public void testWatch() {
|
||||
}
|
||||
|
||||
@Ignore("DATAREDIS-123, exec does not return command results")
|
||||
public void testUnwatch() {
|
||||
}
|
||||
|
||||
@Ignore("DATAREDIS-130, sort not working")
|
||||
public void testSort() {
|
||||
}
|
||||
|
||||
@Ignore("DATAREDIS-130, sort not working")
|
||||
public void testSortStore() {
|
||||
}
|
||||
|
||||
@Ignore("DATAREDIS-132 config get broken in SRP 0.2")
|
||||
public void testGetConfig() {
|
||||
}
|
||||
|
||||
@Ignore("DATAREDIS-152 Syntax error on zRangeByScore and and zRangeByScoreWithScores when using offset and count")
|
||||
public void testZRangeByScoreOffsetCount() {
|
||||
}
|
||||
|
||||
@Ignore("DATAREDIS-152 Syntax error on zRangeByScore and and zRangeByScoreWithScores when using offset and count")
|
||||
public void testZRangeByScoreWithScoresOffsetCount() {
|
||||
}
|
||||
|
||||
@Ignore("DATAREDIS-156 SRP bRPopLPush ClassCastException")
|
||||
public void testBRPopLPushTimeout() {
|
||||
}
|
||||
|
||||
@Test(expected = UnsupportedOperationException.class)
|
||||
public void testZInterStoreAggWeights() {
|
||||
super.testZInterStoreAggWeights();
|
||||
}
|
||||
|
||||
@Test(expected = UnsupportedOperationException.class)
|
||||
public void testZUnionStoreAggWeights() {
|
||||
super.testZUnionStoreAggWeights();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,208 @@
|
||||
/*
|
||||
* Copyright 2011-2013 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.srp;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
import java.util.Set;
|
||||
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.data.redis.connection.AbstractConnectionPipelineIntegrationTests;
|
||||
import org.springframework.data.redis.connection.DefaultStringTuple;
|
||||
import org.springframework.data.redis.connection.RedisZSetCommands.Tuple;
|
||||
import org.springframework.data.redis.connection.StringRedisConnection.StringTuple;
|
||||
import org.springframework.data.redis.serializer.SerializationUtils;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import redis.reply.BulkReply;
|
||||
import redis.reply.Reply;
|
||||
|
||||
/**
|
||||
* Integration test of {@link SrpConnection} pipeline functionality
|
||||
*
|
||||
* @author Jennifer Hickey
|
||||
*
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration("SrpConnectionIntegrationTests-context.xml")
|
||||
public class SrpConnectionPipelineIntegrationTests extends
|
||||
AbstractConnectionPipelineIntegrationTests {
|
||||
|
||||
@Ignore("DATAREDIS-123, exec does not return command results")
|
||||
public void testMultiExec() throws Exception {
|
||||
}
|
||||
|
||||
@Ignore("DATAREDIS-123, exec does not return command results")
|
||||
public void testMultiDiscard() {
|
||||
}
|
||||
|
||||
@Ignore("DATAREDIS-123, exec does not return command results")
|
||||
public void testWatch() {
|
||||
}
|
||||
|
||||
@Ignore("DATAREDIS-123, exec does not return command results")
|
||||
public void testUnwatch() {
|
||||
}
|
||||
|
||||
@Ignore("DATAREDIS-130, sort not working")
|
||||
public void testSort() {
|
||||
}
|
||||
|
||||
@Ignore("DATAREDIS-130, sort not working")
|
||||
public void testSortStore() {
|
||||
}
|
||||
|
||||
@Ignore("DATAREDIS-132 config get broken in SRP 0.2")
|
||||
public void testGetConfig() {
|
||||
}
|
||||
|
||||
@Ignore("DATAREDIS-142 SRP zCount/zInterStore methods execute synchronously when pipelining")
|
||||
public void testZCount() {
|
||||
}
|
||||
|
||||
@Ignore("DATAREDIS-142 SRP zCount/zInterStore methods execute synchronously when pipelining")
|
||||
public void testZInterStore() {
|
||||
}
|
||||
|
||||
@Ignore("DATAREDIS-152 Syntax error on zRangeByScore and and zRangeByScoreWithScores when using offset and count")
|
||||
public void testZRangeByScoreOffsetCount() {
|
||||
}
|
||||
|
||||
@Ignore("DATAREDIS-152 Syntax error on zRangeByScore and and zRangeByScoreWithScores when using offset and count")
|
||||
public void testZRangeByScoreWithScoresOffsetCount() {
|
||||
}
|
||||
|
||||
@Ignore("DATAREDIS-138 NPE in DefaultStringRedisConnection deserializing a null Map")
|
||||
public void testHSetGet() throws Exception {
|
||||
// String hash = getClass() + ":hashtest";
|
||||
// String key1 = UUID.randomUUID().toString();
|
||||
// String key2 = UUID.randomUUID().toString();
|
||||
// String value1 = "foo";
|
||||
// String value2 = "bar";
|
||||
// actual.add(connection.hSet(hash, key1, value1));
|
||||
// actual.add(connection.hSet(hash, key2, value2));
|
||||
// actual.add(connection.hGet(hash, key1));
|
||||
// actual.add(connection.hGetAll(hash));
|
||||
// List<String> expected = Arrays.asList(new String[] {key1, value1,
|
||||
// key2, value2});
|
||||
// verifyResults(Arrays.asList(new Object[] { 1l, 1l, value1, expected
|
||||
// }), actual);
|
||||
}
|
||||
|
||||
@Test(expected = UnsupportedOperationException.class)
|
||||
public void testZInterStoreAggWeights() {
|
||||
super.testZInterStoreAggWeights();
|
||||
}
|
||||
|
||||
@Test(expected = UnsupportedOperationException.class)
|
||||
public void testZUnionStoreAggWeights() {
|
||||
super.testZUnionStoreAggWeights();
|
||||
}
|
||||
|
||||
// Overrides, usually due to return values being Long vs Boolean or Set vs
|
||||
// List
|
||||
|
||||
@Test
|
||||
public void testInfo() throws Exception {
|
||||
assertNull(connection.info());
|
||||
List<Object> results = connection.closePipeline();
|
||||
assertEquals(1, results.size());
|
||||
Properties info = SrpUtils.info(new BulkReply((byte[]) results.get(0)));
|
||||
assertTrue("at least 5 settings should be present", info.size() >= 5);
|
||||
String version = info.getProperty("redis_version");
|
||||
assertNotNull(version);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExists() {
|
||||
connection.set("existent", "true");
|
||||
actual.add(connection.exists("existent"));
|
||||
actual.add(connection.exists("nonexistent"));
|
||||
verifyResults(Arrays.asList(new Object[] { 1l, 0l }), actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRename() {
|
||||
connection.set("renametest", "testit");
|
||||
connection.rename("renametest", "newrenametest");
|
||||
actual.add(connection.get("newrenametest"));
|
||||
actual.add(connection.exists("renametest"));
|
||||
verifyResults(Arrays.asList(new Object[] { "testit", 0l }), actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSIsMember() {
|
||||
convertResultToSet = true;
|
||||
actual.add(connection.sAdd("myset", "foo"));
|
||||
actual.add(connection.sAdd("myset", "bar"));
|
||||
actual.add(connection.sIsMember("myset", "foo"));
|
||||
actual.add(connection.sIsMember("myset", "baz"));
|
||||
verifyResults(Arrays.asList(new Object[] { 1l, 1l, 1l, 0l }), actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testZIncrBy() {
|
||||
actual.add(connection.zAdd("myset", 2, "Bob"));
|
||||
actual.add(connection.zAdd("myset", 1, "James"));
|
||||
actual.add(connection.zAdd("myset", 4, "Joe"));
|
||||
actual.add(connection.zIncrBy("myset", 2, "Joe"));
|
||||
actual.add(connection.zRangeByScore("myset", 6, 6));
|
||||
verifyResults(
|
||||
Arrays.asList(new Object[] { 1l, 1l, 1l, "6", Collections.singletonList("Joe") }),
|
||||
actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testZScore() {
|
||||
actual.add(connection.zAdd("myset", 2, "Bob"));
|
||||
actual.add(connection.zAdd("myset", 1, "James"));
|
||||
actual.add(connection.zAdd("myset", 3, "Joe"));
|
||||
actual.add(connection.zScore("myset", "Joe"));
|
||||
verifyResults(Arrays.asList(new Object[] { 1l, 1l, 1l, "3" }), actual);
|
||||
}
|
||||
|
||||
protected Object convertResult(Object result) {
|
||||
Object convertedResult = super.convertResult(result);
|
||||
if (convertedResult instanceof Reply[]) {
|
||||
if (convertResultToSet) {
|
||||
return SerializationUtils.deserialize(SrpUtils.toSet((Reply[]) convertedResult),
|
||||
stringSerializer);
|
||||
} else if (convertResultToTuples) {
|
||||
Set<Tuple> tuples = SrpUtils.convertTuple((Reply[]) convertedResult);
|
||||
List<StringTuple> stringTuples = new ArrayList<StringTuple>();
|
||||
for (Tuple tuple : tuples) {
|
||||
stringTuples.add(new DefaultStringTuple(tuple, new String(tuple.getValue())));
|
||||
}
|
||||
return stringTuples;
|
||||
} else {
|
||||
return SerializationUtils.deserialize(
|
||||
SrpUtils.toBytesList((Reply[]) convertedResult), stringSerializer);
|
||||
}
|
||||
}
|
||||
return convertedResult;
|
||||
}
|
||||
}
|
||||
@@ -71,6 +71,16 @@ public class BoundKeyOperationsTest {
|
||||
public void testRename() throws Exception {
|
||||
Object key = keyOps.getKey();
|
||||
assertNotNull(key);
|
||||
// RedisAtomicInteger/Long need to be reset, as they may be created
|
||||
// at start of test run and underlying key wiped out by other tests
|
||||
try {
|
||||
keyOps.getClass().getMethod("set", int.class).invoke(keyOps, 0);
|
||||
}catch(NoSuchMethodException e) {
|
||||
}
|
||||
try {
|
||||
keyOps.getClass().getMethod("set", long.class).invoke(keyOps, 0l);
|
||||
}catch(NoSuchMethodException e) {
|
||||
}
|
||||
Object newName = objFactory.instance();
|
||||
keyOps.rename(newName);
|
||||
assertEquals(newName, keyOps.getKey());
|
||||
|
||||
Reference in New Issue
Block a user