DATAREDIS-567 - Remove Support for SRP and JRedis.

This commit is contained in:
Christoph Strobl
2016-06-23 08:48:56 +02:00
committed by Mark Paluch
parent 186b6dd457
commit f6411b3811
53 changed files with 89 additions and 9335 deletions

View File

@@ -1,844 +0,0 @@
/*
* Copyright 2011-2015 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.jredis;
import static org.junit.Assert.*;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
import org.hamcrest.core.IsCollectionContaining;
import org.hamcrest.core.IsInstanceOf;
import org.jredis.JRedis;
import org.jredis.protocol.BulkResponse;
import org.jredis.ri.alphazero.protocol.SyncProtocol.SyncMultiBulkResponse;
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.RedisConnectionFailureException;
import org.springframework.data.redis.SettingsUtils;
import org.springframework.data.redis.connection.AbstractConnectionIntegrationTests;
import org.springframework.data.redis.connection.DefaultSortParameters;
import org.springframework.data.redis.connection.DefaultStringRedisConnection;
import org.springframework.data.redis.connection.RedisConnection;
import org.springframework.data.redis.connection.SortParameters.Order;
import org.springframework.data.redis.connection.StringRedisConnection;
import org.springframework.data.redis.test.util.RelaxedJUnit4ClassRunner;
import org.springframework.test.annotation.IfProfileValue;
import org.springframework.test.context.ContextConfiguration;
/**
* Integration test of {@link JredisConnection}
*
* @author Costin Leau
* @author Jennifer Hickey
* @author Christoph Strobl
*/
@RunWith(RelaxedJUnit4ClassRunner.class)
@ContextConfiguration
public class JRedisConnectionIntegrationTests extends AbstractConnectionIntegrationTests {
@After
public void tearDown() {
try {
connection.flushAll();
connection.close();
} 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("Pub/Sub not supported")
public void testPubSubWithPatterns() {}
@Ignore("Pub/Sub not supported")
public void testPubSubWithNamedChannels() {}
@Ignore("https://github.com/alphazero/jredis/issues/64 Protocol error: expected '$' got '*' on mset")
public void testMSet() {}
@Ignore("https://github.com/alphazero/jredis/issues/64 Protocol error: expected '$' got '*' on mset")
public void testMSetNx() {}
@Ignore("https://github.com/alphazero/jredis/issues/64 Protocol error: expected '$' got '*' on mset")
public void testMSetNxFailure() {}
@Ignore("JRedis casts to int")
public void testIncrDecrByLong() {}
@Ignore("Ping returns status response instead of value response")
public void testExecuteNoArgs() {}
@Test
public void testConnectionClosesWhenNotPooled() {
connection.close();
try {
connection.ping();
fail("Expected RedisConnectionFailureException trying to use a closed connection");
} catch (RedisConnectionFailureException e) {}
}
@Test
public void testConnectionStaysOpenWhenPooled() {
JredisConnectionFactory factory2 = new JredisConnectionFactory(new JredisPool(SettingsUtils.getHost(),
SettingsUtils.getPort()));
RedisConnection conn2 = factory2.getConnection();
conn2.close();
conn2.ping();
}
@Test
public void testConnectionNotReturnedOnException() {
GenericObjectPoolConfig config = new GenericObjectPoolConfig();
config.setMaxTotal(1);
config.setMaxWaitMillis(1);
JredisConnectionFactory factory2 = new JredisConnectionFactory(new JredisPool(SettingsUtils.getHost(),
SettingsUtils.getPort(), config));
RedisConnection conn2 = factory2.getConnection();
((JRedis) conn2.getNativeConnection()).quit();
try {
conn2.ping();
fail("Expected RedisConnectionFailureException trying to use a closed connection");
} catch (RedisConnectionFailureException e) {}
conn2.close();
// Verify we get a new connection from the pool and not the broken one
RedisConnection conn3 = factory2.getConnection();
conn3.ping();
}
@Test(expected = UnsupportedOperationException.class)
public void testMultiExec() throws Exception {
super.testMultiExec();
}
@Test(expected = UnsupportedOperationException.class)
public void testMultiAlreadyInTx() throws Exception {
super.testMultiAlreadyInTx();
}
@Test(expected = UnsupportedOperationException.class)
public void testMultiDiscard() throws Exception {
super.testMultiDiscard();
}
@Test(expected = UnsupportedOperationException.class)
public void testWatch() throws Exception {
super.testWatch();
}
@Test(expected = UnsupportedOperationException.class)
public void testUnwatch() throws Exception {
super.testUnwatch();
}
@Test(expected = UnsupportedOperationException.class)
public void testErrorInTx() {
super.testErrorInTx();
}
@Test(expected = UnsupportedOperationException.class)
public void testExecWithoutMulti() {
super.testExecWithoutMulti();
}
@Test(expected = UnsupportedOperationException.class)
public void testBLPop() {
super.testBLPop();
}
@Test(expected = UnsupportedOperationException.class)
public void testBRPop() {
super.testBRPop();
}
@Test(expected = UnsupportedOperationException.class)
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();
}
@Test(expected = UnsupportedOperationException.class)
public void testZRevRangeByScore() {
super.testZRevRangeByScore();
}
@Test(expected = UnsupportedOperationException.class)
public void testZRevRangeByScoreOffsetCount() {
super.testZRevRangeByScoreOffsetCount();
}
@Test(expected = UnsupportedOperationException.class)
public void testZRevRangeByScoreWithScores() {
super.testZRevRangeByScoreWithScores();
}
@Test(expected = UnsupportedOperationException.class)
public void testZRevRangeByScoreWithScoresOffsetCount() {
super.testZRevRangeByScoreWithScoresOffsetCount();
}
@Test(expected = UnsupportedOperationException.class)
public void testSelect() {
super.testSelect();
}
@Test(expected = UnsupportedOperationException.class)
public void testPExpire() {
super.testPExpire();
}
@Test(expected = UnsupportedOperationException.class)
public void testPExpireKeyNotExists() {
super.testPExpireKeyNotExists();
}
@Test(expected = UnsupportedOperationException.class)
public void testPExpireAt() {
super.testPExpireAt();
}
@Test(expected = UnsupportedOperationException.class)
public void testPExpireAtKeyNotExists() {
super.testPExpireAtKeyNotExists();
}
@Test(expected = UnsupportedOperationException.class)
public void testPTtl() {
super.testPTtl();
}
@Test(expected = UnsupportedOperationException.class)
public void testPTtlNoExpire() {
super.testPTtlNoExpire();
}
/**
* @see DATAREDIS-526
*/
@Test(expected = UnsupportedOperationException.class)
public void testPTtlWithTimeUnit() {
super.testPTtlWithTimeUnit();
}
@Test(expected = UnsupportedOperationException.class)
public void testDumpAndRestore() {
super.testDumpAndRestore();
}
@Test(expected = UnsupportedOperationException.class)
public void testDumpNonExistentKey() {
super.testDumpNonExistentKey();
}
@Test(expected = UnsupportedOperationException.class)
public void testRestoreBadData() {
super.testRestoreBadData();
}
@Test(expected = UnsupportedOperationException.class)
public void testRestoreExistingKey() {
super.testRestoreExistingKey();
}
@Test(expected = UnsupportedOperationException.class)
public void testRestoreTtl() {
super.testRestoreTtl();
}
@Test(expected = UnsupportedOperationException.class)
public void testBitCount() {
super.testBitCount();
}
@Test(expected = UnsupportedOperationException.class)
public void testBitCountInterval() {
super.testBitCountInterval();
}
@Test(expected = UnsupportedOperationException.class)
public void testBitCountNonExistentKey() {
super.testBitCountNonExistentKey();
}
@Test(expected = UnsupportedOperationException.class)
public void testBitOpAnd() {
super.testBitOpAnd();
}
@Test(expected = UnsupportedOperationException.class)
public void testBitOpOr() {
super.testBitOpOr();
}
@Test(expected = UnsupportedOperationException.class)
public void testBitOpXOr() {
super.testBitOpXOr();
}
@Test(expected = UnsupportedOperationException.class)
public void testBitOpNot() {
super.testBitOpNot();
}
@Test(expected = UnsupportedOperationException.class)
public void testHIncrByDouble() {
super.testHIncrByDouble();
}
@Test(expected = UnsupportedOperationException.class)
public void testHashIncrDecrByLong() {
super.testHashIncrDecrByLong();
}
@Test(expected = UnsupportedOperationException.class)
public void testIncrByDouble() {
super.testIncrByDouble();
}
@Test(expected = UnsupportedOperationException.class)
@IfProfileValue(name = "redisVersion", value = "2.6+")
public void testScriptLoadEvalSha() {
super.testScriptLoadEvalSha();
}
@Test(expected = UnsupportedOperationException.class)
@IfProfileValue(name = "redisVersion", value = "2.6+")
public void testEvalShaArrayStrings() {
super.testEvalShaArrayStrings();
}
@Test(expected = UnsupportedOperationException.class)
@IfProfileValue(name = "redisVersion", value = "2.6+")
public void testEvalShaArrayBytes() {
super.testEvalShaArrayBytes();
}
@Test(expected = UnsupportedOperationException.class)
@IfProfileValue(name = "redisVersion", value = "2.6+")
public void testEvalShaNotFound() {
super.testEvalShaNotFound();
}
@Test(expected = UnsupportedOperationException.class)
@IfProfileValue(name = "redisVersion", value = "2.6+")
public void testEvalShaArrayError() {
super.testEvalShaArrayError();
}
@Test(expected = UnsupportedOperationException.class)
@IfProfileValue(name = "redisVersion", value = "2.6+")
public void testEvalArrayScriptError() {
super.testEvalArrayScriptError();
}
@Test(expected = UnsupportedOperationException.class)
@IfProfileValue(name = "redisVersion", value = "2.6+")
public void testEvalReturnString() {
super.testEvalReturnString();
}
@Test(expected = UnsupportedOperationException.class)
@IfProfileValue(name = "redisVersion", value = "2.6+")
public void testEvalReturnNumber() {
super.testEvalReturnNumber();
}
@Test(expected = UnsupportedOperationException.class)
@IfProfileValue(name = "redisVersion", value = "2.6+")
public void testEvalReturnSingleOK() {
super.testEvalReturnSingleOK();
}
@Test(expected = UnsupportedOperationException.class)
@IfProfileValue(name = "redisVersion", value = "2.6+")
public void testEvalReturnSingleError() {
super.testEvalReturnSingleError();
}
@Test(expected = UnsupportedOperationException.class)
@IfProfileValue(name = "redisVersion", value = "2.6+")
public void testEvalReturnFalse() {
super.testEvalReturnFalse();
}
@Test(expected = UnsupportedOperationException.class)
@IfProfileValue(name = "redisVersion", value = "2.6+")
public void testEvalReturnTrue() {
super.testEvalReturnTrue();
}
@Test(expected = UnsupportedOperationException.class)
@IfProfileValue(name = "redisVersion", value = "2.6+")
public void testEvalReturnArrayStrings() {
super.testEvalReturnArrayStrings();
}
@Test(expected = UnsupportedOperationException.class)
@IfProfileValue(name = "redisVersion", value = "2.6+")
public void testEvalReturnArrayNumbers() {
super.testEvalReturnArrayNumbers();
}
@Test(expected = UnsupportedOperationException.class)
@IfProfileValue(name = "redisVersion", value = "2.6+")
public void testEvalReturnArrayOKs() {
super.testEvalReturnArrayOKs();
}
@Test(expected = UnsupportedOperationException.class)
@IfProfileValue(name = "redisVersion", value = "2.6+")
public void testEvalReturnArrayFalses() {
super.testEvalReturnArrayFalses();
}
@Test(expected = UnsupportedOperationException.class)
@IfProfileValue(name = "redisVersion", value = "2.6+")
public void testEvalReturnArrayTrues() {
super.testEvalReturnArrayTrues();
}
@Test(expected = UnsupportedOperationException.class)
@IfProfileValue(name = "redisVersion", value = "2.6+")
public void testScriptExists() {
super.testScriptExists();
}
@Test(expected = UnsupportedOperationException.class)
public void testScriptKill() throws Exception {
connection.scriptKill();
}
@Test(expected = UnsupportedOperationException.class)
@IfProfileValue(name = "redisVersion", value = "2.6+")
public void testScriptFlush() {
connection.scriptFlush();
}
@Test(expected = UnsupportedOperationException.class)
@IfProfileValue(name = "redisVersion", value = "2.6+")
public void testSRandMemberCount() {
super.testSRandMemberCount();
}
@Test(expected = UnsupportedOperationException.class)
@IfProfileValue(name = "redisVersion", value = "2.6+")
public void testSRandMemberCountKeyNotExists() {
super.testSRandMemberCountKeyNotExists();
}
@Test(expected = UnsupportedOperationException.class)
@IfProfileValue(name = "redisVersion", value = "2.6+")
public void testSRandMemberCountNegative() {
super.testSRandMemberCountNegative();
}
@Test(expected = UnsupportedOperationException.class)
@IfProfileValue(name = "redisVersion", value = "2.6+")
public void testInfoBySection() throws Exception {
super.testInfoBySection();
}
@Test(expected = UnsupportedOperationException.class)
public void testHDelMultiple() {
super.testHDelMultiple();
}
@Test(expected = UnsupportedOperationException.class)
public void testLPushMultiple() {
super.testLPushMultiple();
}
@Test(expected = UnsupportedOperationException.class)
public void testRPushMultiple() {
super.testRPushMultiple();
}
@Test(expected = UnsupportedOperationException.class)
public void testSAddMultiple() {
super.testSAddMultiple();
}
@Test(expected = UnsupportedOperationException.class)
public void testSRemMultiple() {
super.testSRemMultiple();
}
@Test(expected = UnsupportedOperationException.class)
public void testZAddMultiple() {
super.testZAddMultiple();
}
@Test(expected = UnsupportedOperationException.class)
public void testZRemMultiple() {
super.testZRemMultiple();
}
// Jredis returns null for rPush and lPush
@Test
public void testLLen() {
connection.rPush("PopList", "hello");
connection.rPush("PopList", "big");
connection.rPush("PopList", "world");
connection.rPush("PopList", "hello");
actual.add(connection.lLen("PopList"));
verifyResults(Arrays.asList(new Object[] { 4l }));
}
@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 testSortNullParams() {
connection.rPush("sortlist", "5");
connection.rPush("sortlist", "2");
connection.rPush("sortlist", "3");
actual.add(connection.sort("sortlist", null));
verifyResults(Arrays.asList(new Object[] { Arrays.asList(new String[] { "2", "3", "5" }) }));
}
@Test
public void testSortStoreNullParams() {
connection.rPush("sortlist", "9");
connection.rPush("sortlist", "3");
connection.rPush("sortlist", "5");
actual.add(connection.sort("sortlist", null, "newlist"));
actual.add(connection.lRange("newlist", 0, 9));
verifyResults(Arrays.asList(new Object[] { 3l, Arrays.asList(new String[] { "3", "5", "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));
}
@Test
public void testExecute() {
connection.set("foo", "bar");
BulkResponse response = (BulkResponse) connection.execute("GET", "foo".getBytes());
assertEquals("bar", stringSerializer.deserialize(response.getBulkData()));
}
@Test
public void testSDiffStore() {
actual.add(connection.sAdd("myset", "foo"));
actual.add(connection.sAdd("myset", "bar"));
actual.add(connection.sAdd("otherset", "bar"));
actual.add(connection.sDiffStore("thirdset", "myset", "otherset"));
actual.add(connection.sMembers("thirdset"));
// JRedis returns void for sDiffStore, so we always return -1
verifyResults(Arrays
.asList(new Object[] { 1l, 1l, 1l, -1l, new HashSet<String>(Collections.singletonList("foo")) }));
}
@Test
public void testSInterStore() {
actual.add(connection.sAdd("myset", "foo"));
actual.add(connection.sAdd("myset", "bar"));
actual.add(connection.sAdd("otherset", "bar"));
actual.add(connection.sInterStore("thirdset", "myset", "otherset"));
actual.add(connection.sMembers("thirdset"));
// JRedis returns void for sInterStore, so we always return -1
verifyResults(Arrays
.asList(new Object[] { 1l, 1l, 1l, -1l, new HashSet<String>(Collections.singletonList("bar")) }));
}
@Test
public void testSUnionStore() {
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.sUnionStore("thirdset", "myset", "otherset"));
actual.add(connection.sMembers("thirdset"));
// JRedis returns void for sUnionStore, so we always return -1
verifyResults(Arrays.asList(new Object[] { 1l, 1l, 1l, 1l, -1l,
new HashSet<String>(Arrays.asList(new String[] { "foo", "bar", "baz" })) }));
}
@Test
public void testMove() {
connection.set("foo", "bar");
actual.add(connection.move("foo", 1));
verifyResults(Arrays.asList(new Object[] { true }));
// JRedis does not support select() on existing conn, create new one
JredisConnectionFactory factory2 = new JredisConnectionFactory();
factory2.setDatabase(1);
factory2.afterPropertiesSet();
StringRedisConnection conn2 = new DefaultStringRedisConnection(factory2.getConnection());
try {
assertEquals("bar", conn2.get("foo"));
} finally {
if (conn2.exists("foo")) {
conn2.del("foo");
}
conn2.close();
}
}
/**
* @see DATAREDIS-206
*/
@Test(expected = UnsupportedOperationException.class)
public void testGetTimeShouldRequestServerTime() {
super.testGetTimeShouldRequestServerTime();
}
/**
* @see DATAREDIS-285
*/
@Test
public void testExecuteShouldConvertArrayReplyCorrectly() {
connection.set("spring", "awesome");
connection.set("data", "cool");
connection.set("redis", "supercalifragilisticexpialidocious");
Object result = connection.execute("MGET", "spring".getBytes(), "data".getBytes(), "redis".getBytes());
assertThat(result, IsInstanceOf.instanceOf(SyncMultiBulkResponse.class));
List<byte[]> data = ((SyncMultiBulkResponse) result).getMultiBulkData();
assertThat(
data,
IsCollectionContaining.hasItems("awesome".getBytes(), "cool".getBytes(),
"supercalifragilisticexpialidocious".getBytes()));
}
/**
* @see DATAREDIS-271
*/
@Test(expected = UnsupportedOperationException.class)
public void testPsetEx() throws Exception {
super.testPsetEx();
}
/**
* @see DATAREDIS-269
*/
@Override
@Test(expected = UnsupportedOperationException.class)
public void clientSetNameWorksCorrectly() {
super.clientSetNameWorksCorrectly();
}
/**
* @see DATAREDIS-268
*/
@Override
@Test(expected = UnsupportedOperationException.class)
public void testListClientsContainsAtLeastOneElement() {
super.testListClientsContainsAtLeastOneElement();
}
}

View File

@@ -1,68 +0,0 @@
/*
* Copyright 2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.redis.connection.jredis;
import org.jredis.JRedis;
import org.junit.Before;
import org.junit.Test;
import org.springframework.data.redis.connection.AbstractConnectionUnitTestBase;
import org.springframework.data.redis.connection.RedisServerCommands.ShutdownOption;
/**
* @author Christoph Strobl
*/
public class JRedisConnectionUnitTests extends AbstractConnectionUnitTestBase<JRedis> {
private JredisConnection connection;
@Before
public void setUp() {
connection = new JredisConnection(getNativeRedisConnectionMock());
}
/**
* @see DATAREDIS-184
*/
@Test(expected = UnsupportedOperationException.class)
public void shutdownSaveShouldThrowUnsupportedOperationException() {
connection.shutdown(ShutdownOption.SAVE);
}
/**
* @see DATAREDIS-184
*/
@Test(expected = UnsupportedOperationException.class)
public void shutdownNosaveShouldThrowUnsupportedOperationException() {
connection.shutdown(ShutdownOption.NOSAVE);
}
/**
* @see DATAREDIS-184
*/
@Test(expected = UnsupportedOperationException.class)
public void shutdownWithNullShouldThrowUnsupportedOperationException() {
connection.shutdown(null);
}
/**
* @see DATAREDIS-270
*/
@Test(expected = UnsupportedOperationException.class)
public void getClientNameShouldSendRequestCorrectly() {
connection.getClientName();
}
}

View File

@@ -1,141 +0,0 @@
/*
* Copyright 2013-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.redis.connection.jredis;
import static org.junit.Assert.*;
import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
import org.jredis.JRedis;
import org.jredis.RedisException;
import org.jredis.connector.ConnectionSpec;
import org.jredis.connector.NotConnectedException;
import org.jredis.ri.alphazero.connection.DefaultConnectionSpec;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.springframework.data.redis.SettingsUtils;
import org.springframework.data.redis.connection.PoolException;
/**
* Integration test of {@link JredisPool}.
*
* @author Jennifer Hickey
* @author Thomas Darimont
* @author Christoph Strobl
*/
public class JredisPoolTests {
private ConnectionSpec connectionSpec;
private JredisPool pool;
@Before
public void setUp() {
this.connectionSpec = DefaultConnectionSpec.newSpec(SettingsUtils.getHost(), SettingsUtils.getPort(), 0, null);
}
@After
public void tearDown() {
if (this.pool != null) {
this.pool.destroy();
}
}
@Test
public void testGetResource() throws RedisException {
this.pool = new JredisPool(connectionSpec);
JRedis client = pool.getResource();
assertNotNull(client);
client.ping();
}
@Test
public void testGetResourcePoolExhausted() {
GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig();
poolConfig.setMaxTotal(1);
poolConfig.setMaxWaitMillis(1);
this.pool = new JredisPool(connectionSpec, poolConfig);
JRedis client = pool.getResource();
assertNotNull(client);
try {
pool.getResource();
fail("PoolException should be thrown when pool exhausted");
} catch (PoolException e) {
}
}
@Test
public void testGetResourceValidate() {
GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig();
poolConfig.setTestOnBorrow(true);
this.pool = new JredisPool(connectionSpec, poolConfig);
JRedis client = pool.getResource();
assertNotNull(client);
}
@Test(expected = PoolException.class)
public void testGetResourceCreationUnsuccessful() {
// Config poolConfig = new Config();
// poolConfig.testOnBorrow = true;
this.pool = new JredisPool(DefaultConnectionSpec.newSpec(SettingsUtils.getHost(), 3333, 0, null));
pool.getResource();
}
@Test
public void testReturnResource() throws RedisException {
GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig();
poolConfig.setMaxTotal(1);
poolConfig.setMaxWaitMillis(1);
this.pool = new JredisPool(connectionSpec);
JRedis client = pool.getResource();
assertNotNull(client);
pool.returnResource(client);
assertNotNull(pool.getResource());
}
@Test
public void testReturnBrokenResource() throws RedisException {
GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig();
poolConfig.setMaxTotal(1);
poolConfig.setMaxWaitMillis(1);
this.pool = new JredisPool(connectionSpec, poolConfig);
JRedis client = pool.getResource();
assertNotNull(client);
pool.returnBrokenResource(client);
JRedis client2 = pool.getResource();
assertNotSame(client, client2);
try {
client.ping();
fail("Broken resouce connection should be closed");
} catch (NotConnectedException e) {}
}
@Test
public void testCreateWithHostAndPort() {
this.pool = new JredisPool(SettingsUtils.getHost(), SettingsUtils.getPort());
assertNotNull(pool.getResource());
}
@Test
public void testCreateWithHostPortAndDbIndex() {
this.pool = new JredisPool(SettingsUtils.getHost(), SettingsUtils.getPort(), 1, null, 0);
assertNotNull(pool.getResource());
}
}

View File

@@ -1,62 +0,0 @@
/*
* Copyright 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 org.junit.Ignore;
import org.junit.Test;
import org.springframework.data.redis.RedisConnectionFailureException;
import org.springframework.data.redis.SettingsUtils;
import org.springframework.data.redis.connection.RedisConnection;
import static org.junit.Assert.fail;
/**
* Integration test of {@link SrpConnectionFactory}
*
* @author Jennifer Hickey
*/
public class SrpConnectionFactoryTests {
@Test
public void testConnect() {
SrpConnectionFactory factory = new SrpConnectionFactory(SettingsUtils.getHost(), SettingsUtils.getPort());
factory.afterPropertiesSet();
RedisConnection connection = factory.getConnection();
connection.ping();
}
@Test
public void testConnectInvalidHost() {
SrpConnectionFactory factory = new SrpConnectionFactory();
factory.setHostName("fakeHost");
factory.afterPropertiesSet();
try {
factory.getConnection();
fail("Expected a connection failure exception");
} catch (RedisConnectionFailureException e) {}
}
@Ignore("Redis must have requirepass set to run this test")
@Test
public void testConnectWithPassword() {
SrpConnectionFactory factory = new SrpConnectionFactory(SettingsUtils.getHost(), SettingsUtils.getPort());
factory.setPassword("foob");
factory.afterPropertiesSet();
RedisConnection connection = factory.getConnection();
connection.ping();
RedisConnection connection2 = factory.getConnection();
connection2.ping();
}
}

View File

@@ -1,137 +0,0 @@
/*
* Copyright 2011-2015 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.*;
import java.util.Arrays;
import java.util.List;
import java.util.Set;
import org.hamcrest.core.Is;
import org.hamcrest.core.IsInstanceOf;
import org.junit.After;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.data.redis.connection.AbstractConnectionIntegrationTests;
import org.springframework.data.redis.connection.ReturnType;
import org.springframework.data.redis.test.util.RelaxedJUnit4ClassRunner;
import org.springframework.test.annotation.IfProfileValue;
import org.springframework.test.context.ContextConfiguration;
import redis.reply.Reply;
/**
* Integration test of {@link SrpConnection}
*
* @author Costin Leau
* @author Jennifer Hickey
* @author Thomas Darimont
* @author David Liu
*/
@RunWith(RelaxedJUnit4ClassRunner.class)
@ContextConfiguration
public class SrpConnectionIntegrationTests extends AbstractConnectionIntegrationTests {
@After
public void tearDown() {
try {
connection.flushAll();
} 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;
}
@Test(expected = UnsupportedOperationException.class)
public void testZInterStoreAggWeights() {
super.testZInterStoreAggWeights();
}
@Test(expected = UnsupportedOperationException.class)
public void testZUnionStoreAggWeights() {
super.testZUnionStoreAggWeights();
}
@Test
public void testExecuteNoArgs() {
// SRP returns this as String while other drivers return as byte[]
actual.add(connection.execute("PING"));
verifyResults(Arrays.asList(new Object[] { "PONG" }));
}
@Test
@IfProfileValue(name = "redisVersion", value = "2.6+")
public void testEvalReturnArrayOKs() {
// SRP returns the Strings from individual StatusReplys in a MultiBulkReply, while other clients return as byte[]
actual.add(connection.eval("return { redis.call('set','abc','ghk'), redis.call('set','abc','lfdf')}",
ReturnType.MULTI, 0));
verifyResults(Arrays.asList(new Object[] { Arrays.asList(new Object[] { "OK", "OK" }) }));
}
/**
* @see DATAREDIS-285
*/
@Test
public void testExecuteShouldConvertArrayReplyCorrectly() {
connection.set("spring", "awesome");
connection.set("data", "cool");
connection.set("redis", "supercalifragilisticexpialidocious");
Object result = connection.execute("MGET", "spring".getBytes(), "data".getBytes(), "redis".getBytes());
Assert.assertThat(result, IsInstanceOf.instanceOf(Reply[].class));
Reply<?>[] replies = (Reply[]) result;
Assert.assertThat(replies[0].data(), Is.<Object> is("awesome".getBytes()));
Assert.assertThat(replies[1].data(), Is.<Object> is("cool".getBytes()));
Assert.assertThat(replies[2].data(), Is.<Object> is("supercalifragilisticexpialidocious".getBytes()));
}
@SuppressWarnings("unchecked")
@Test
@IfProfileValue(name = "redisVersion", value = "2.6+")
public void testEvalShaArrayBytes() {
getResults();
byte[] sha1 = connection.scriptLoad("return {KEYS[1],ARGV[1]}").getBytes();
initConnection();
actual.add(connection.evalSha(sha1, ReturnType.MULTI, 1, "key1".getBytes(), "arg1".getBytes()));
List<Object> results = getResults();
List<byte[]> scriptResults = (List<byte[]>) results.get(0);
assertEquals(Arrays.asList(new Object[] { "key1", "arg1" }),
Arrays.asList(new Object[] { new String(scriptResults.get(0)), new String(scriptResults.get(1)) }));
}
/**
* @see DATAREDIS-106
*/
@Test
public void zRangeByScoreTest() {
connection.zAdd("myzset", 1, "one");
connection.zAdd("myzset", 2, "two");
connection.zAdd("myzset", 3, "three");
Set<byte[]> zRangeByScore = connection.zRangeByScore("myzset", "(1", "2");
Assert.assertEquals("two", new String(zRangeByScore.iterator().next()));
}
}

View File

@@ -1,89 +0,0 @@
/*
* 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.*;
import java.util.Arrays;
import java.util.List;
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.ReturnType;
import org.springframework.data.redis.test.util.RelaxedJUnit4ClassRunner;
import org.springframework.test.annotation.IfProfileValue;
import org.springframework.test.context.ContextConfiguration;
/**
* Integration test of {@link SrpConnection} pipeline functionality
*
* @author Jennifer Hickey
*/
@RunWith(RelaxedJUnit4ClassRunner.class)
@ContextConfiguration("SrpConnectionIntegrationTests-context.xml")
public class SrpConnectionPipelineIntegrationTests extends AbstractConnectionPipelineIntegrationTests {
@Test
@IfProfileValue(name = "redisVersion", value = "2.6+")
public void testEvalReturnArrayOKs() {
// SRP returns the Strings from individual StatusReplys in a
// MultiBulkReply, while other clients return as byte[]
actual.add(connection.eval("return { redis.call('set','abc','ghk'), redis.call('set','abc','lfdf')}",
ReturnType.MULTI, 0));
verifyResults(Arrays.asList(new Object[] { Arrays.asList(new Object[] { "OK", "OK" }) }));
}
@Test(expected = RedisSystemException.class)
public void testExecWithoutMulti() {
connection.exec();
// SRP throws an Exception right away on exec instead of once pipeline is closed
getResults();
}
@Test
public void testExecuteNoArgs() {
// SRP returns this as String while other drivers return as byte[]
actual.add(connection.execute("PING"));
verifyResults(Arrays.asList(new Object[] { "PONG" }));
}
@Test(expected = UnsupportedOperationException.class)
public void testZInterStoreAggWeights() {
super.testZInterStoreAggWeights();
}
@Test(expected = UnsupportedOperationException.class)
public void testZUnionStoreAggWeights() {
super.testZUnionStoreAggWeights();
}
@SuppressWarnings("unchecked")
@Test
@IfProfileValue(name = "redisVersion", value = "2.6+")
public void testEvalShaArrayBytes() {
getResults();
byte[] sha1 = connection.scriptLoad("return {KEYS[1],ARGV[1]}").getBytes();
initConnection();
actual.add(byteConnection.evalSha(sha1, ReturnType.MULTI, 1, "key1".getBytes(), "arg1".getBytes()));
List<Object> results = getResults();
List<byte[]> scriptResults = (List<byte[]>) results.get(0);
assertEquals(Arrays.asList(new Object[] { "key1", "arg1" }),
Arrays.asList(new Object[] { new String(scriptResults.get(0)), new String(scriptResults.get(1)) }));
}
}

View File

@@ -1,112 +0,0 @@
/*
* 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.assertNull;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import org.junit.Test;
import org.springframework.data.redis.connection.RedisPipelineException;
import org.springframework.test.annotation.IfProfileValue;
/**
* Integration test of {@link SrpConnection} transactions within a pipeline
*
* @author Jennifer Hickey
*/
public class SrpConnectionPipelineTxIntegrationTests extends SrpConnectionTransactionIntegrationTests {
@Test
public void testUsePipelineAfterTxExec() {
connection.set("foo", "bar");
assertNull(connection.exec());
assertNull(connection.get("foo"));
List<Object> results = connection.closePipeline();
assertEquals(Arrays.asList(new Object[] { Collections.emptyList(), "bar" }), results);
assertEquals("bar", connection.get("foo"));
}
@Test
public void testExec2TransactionsInPipeline() {
connection.set("foo", "bar");
assertNull(connection.get("foo"));
assertNull(connection.exec());
connection.multi();
connection.set("foo", "baz");
assertNull(connection.get("foo"));
assertNull(connection.exec());
List<Object> results = connection.closePipeline();
assertEquals(2, results.size());
assertEquals(Arrays.asList(new Object[] { "bar" }), results.get(0));
assertEquals(Arrays.asList(new Object[] { "baz" }), results.get(1));
}
@Test(expected = RedisPipelineException.class)
@IfProfileValue(name = "redisVersion", value = "2.6+")
public void testEvalShaNotFound() {
super.testEvalShaNotFound();
}
@Test(expected = RedisPipelineException.class)
@IfProfileValue(name = "redisVersion", value = "2.6+")
public void testEvalReturnSingleError() {
super.testEvalReturnSingleError();
}
@Test(expected = RedisPipelineException.class)
@IfProfileValue(name = "redisVersion", value = "2.6+")
public void testRestoreExistingKey() {
super.testRestoreExistingKey();
}
@Test(expected = RedisPipelineException.class)
@IfProfileValue(name = "redisVersion", value = "2.6+")
public void testRestoreBadData() {
super.testRestoreBadData();
}
@Test(expected = RedisPipelineException.class)
@IfProfileValue(name = "redisVersion", value = "2.6+")
public void testEvalArrayScriptError() {
super.testEvalArrayScriptError();
}
@Test(expected = RedisPipelineException.class)
@IfProfileValue(name = "redisVersion", value = "2.6+")
public void testEvalShaArrayError() {
super.testEvalShaArrayError();
}
protected void initConnection() {
connection.openPipeline();
connection.multi();
}
@SuppressWarnings("unchecked")
protected List<Object> getResults() {
assertNull(connection.exec());
List<Object> pipelined = connection.closePipeline();
// We expect only the results of exec to be in the closed pipeline
assertEquals(1, pipelined.size());
List<Object> txResults = (List<Object>) pipelined.get(0);
// Return exec results and this test should behave exactly like its superclass
return txResults;
}
}

View File

@@ -1,70 +0,0 @@
/*
* 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 java.util.Arrays;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.data.redis.connection.AbstractConnectionTransactionIntegrationTests;
import org.springframework.data.redis.connection.ReturnType;
import org.springframework.data.redis.test.util.RelaxedJUnit4ClassRunner;
import org.springframework.test.annotation.IfProfileValue;
import org.springframework.test.context.ContextConfiguration;
/**
* Integration test of {@link SrpConnection} functionality within a transaction
*
* @author Jennifer Hickey
*/
@RunWith(RelaxedJUnit4ClassRunner.class)
@ContextConfiguration("SrpConnectionIntegrationTests-context.xml")
public class SrpConnectionTransactionIntegrationTests extends AbstractConnectionTransactionIntegrationTests {
@Test
@IfProfileValue(name = "redisVersion", value = "2.6+")
public void testEvalReturnArrayOKs() {
// SRP returns the Strings from individual StatusReplys in a MultiBulkReply, while other clients return as byte[]
actual.add(connection.eval("return { redis.call('set','abc','ghk'), redis.call('set','abc','lfdf')}",
ReturnType.MULTI, 0));
verifyResults(Arrays.asList(new Object[] { Arrays.asList(new Object[] { "OK", "OK" }) }));
}
@Test
public void testExecuteNoArgs() {
// SRP returns this as String while other drivers return as byte[]
actual.add(connection.execute("PING"));
verifyResults(Arrays.asList(new Object[] { "PONG" }));
}
@Test(expected = UnsupportedOperationException.class)
public void testZInterStoreAggWeights() {
super.testZInterStoreAggWeights();
}
@Test(expected = UnsupportedOperationException.class)
public void testZUnionStoreAggWeights() {
super.testZUnionStoreAggWeights();
}
/**
* @see DATAREDIS-268
*/
@Test(expected = UnsupportedOperationException.class)
public void testListClientsContainsAtLeastOneElement() {
super.testListClientsContainsAtLeastOneElement();
}
}

View File

@@ -1,189 +0,0 @@
/*
* Copyright 2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.redis.connection.srp;
import static org.mockito.Matchers.*;
import static org.mockito.Mockito.*;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.springframework.data.redis.connection.AbstractConnectionUnitTestBase;
import org.springframework.data.redis.connection.RedisServerCommands.ShutdownOption;
import org.springframework.data.redis.connection.srp.SrpConnectionUnitTestSuite.SrpConnectionPiplineUnitTests;
import org.springframework.data.redis.connection.srp.SrpConnectionUnitTestSuite.SrpConnectionUnitTests;
import redis.client.RedisClient;
import redis.client.RedisClient.Pipeline;
import com.google.common.base.Charsets;
/**
* @author Christoph Strobl
*/
@RunWith(Suite.class)
@Suite.SuiteClasses({ SrpConnectionUnitTests.class, SrpConnectionPiplineUnitTests.class })
public class SrpConnectionUnitTestSuite {
public static class SrpConnectionUnitTests extends AbstractConnectionUnitTestBase<RedisClient> {
protected SrpConnection connection;
@Before
public void setUp() {
connection = new SrpConnection(getNativeRedisConnectionMock());
}
/**
* @see DATAREDIS-184
*/
@Test
public void shutdownWithNullOpionsIsCalledCorrectly() {
connection.shutdown(null);
verifyNativeConnectionInvocation().shutdown("SAVE".getBytes(Charsets.UTF_8), null);
}
/**
* @see DATAREDIS-184
*/
@Test
public void shutdownWithSaveIsCalledCorrectly() {
connection.shutdown(ShutdownOption.SAVE);
verifyNativeConnectionInvocation().shutdown("SAVE".getBytes(Charsets.UTF_8), null);
}
/**
* @see DATAREDIS-184
*/
@Test
public void shutdownWithNosaveIsCalledCorrectly() {
connection.shutdown(ShutdownOption.NOSAVE);
verifyNativeConnectionInvocation().shutdown("NOSAVE".getBytes(Charsets.UTF_8), null);
}
/**
* <<<<<<< HEAD
*
* @see DATAREDIS-267
*/
@Test
public void killClientShouldDelegateCallCorrectly() {
String ipPort = "127.0.0.1:1001";
connection.killClient("127.0.0.1", 1001);
verifyNativeConnectionInvocation().client_kill(eq(ipPort));
}
/**
* @see DATAREDIS-270
*/
@Test
public void getClientNameShouldSendRequestCorrectly() {
connection.getClientName();
verifyNativeConnectionInvocation().client_getname();
}
/**
* @see DATAREDIS-277
*/
@Test(expected = IllegalArgumentException.class)
public void slaveOfShouldThrowExectpionWhenCalledForNullHost() {
connection.slaveOf(null, 0);
}
/**
* @see DATAREDIS-277
*/
@Test
public void slaveOfShouldBeSentCorrectly() {
connection.slaveOf("127.0.0.1", 1001);
verifyNativeConnectionInvocation().slaveof(eq("127.0.0.1"), eq(1001));
}
/**
* @see DATAREDIS-277
*/
@Test
public void slaveOfNoOneShouldBeSentCorrectly() {
connection.slaveOfNoOne();
verifyNativeConnectionInvocation().slaveof(eq("NO"), eq("ONE"));
}
}
public static class SrpConnectionPiplineUnitTests extends AbstractConnectionUnitTestBase<Pipeline> {
protected SrpConnection connection;
@Before
public void setUp() {
RedisClient clientMock = mock(RedisClient.class);
connection = new SrpConnection(clientMock);
when(clientMock.pipeline()).thenReturn(getNativeRedisConnectionMock());
connection.openPipeline();
}
/**
* @see DATAREDIS-184
*/
@Test
public void shutdownWithNullOpionsIsCalledCorrectly() {
connection.shutdown(null);
verifyNativeConnectionInvocation().shutdown("SAVE".getBytes(Charsets.UTF_8), null);
}
/**
* @see DATAREDIS-184
*/
@Test
public void shutdownWithSaveIsCalledCorrectly() {
connection.shutdown(ShutdownOption.SAVE);
verifyNativeConnectionInvocation().shutdown("SAVE".getBytes(Charsets.UTF_8), null);
}
/**
* @see DATAREDIS-184
*/
@Test
public void shutdownWithNosaveIsCalledCorrectly() {
connection.shutdown(ShutdownOption.NOSAVE);
verifyNativeConnectionInvocation().shutdown("NOSAVE".getBytes(Charsets.UTF_8), null);
}
/**
* @see DATAREDIS-270
*/
@Test
public void getClientNameShouldSendRequestCorrectly() {
connection.getClientName();
verifyNativeConnectionInvocation().client_getname();
}
}
}

View File

@@ -1,96 +0,0 @@
/*
* Copyright 2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.redis.connection.srp;
import static org.hamcrest.core.IsEqual.*;
import static org.junit.Assert.*;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Collections;
import org.junit.Test;
import org.springframework.data.redis.core.types.RedisClientInfo;
import redis.reply.BulkReply;
import redis.reply.Reply;
/**
* @author Christoph Strobl
*/
public class SrpConvertersUnitTests {
private static final String CLIENT_ALL_SINGLE_LINE_RESPONSE = "addr=127.0.0.1:60311 fd=6 name= age=4059 idle=0 flags=N db=0 sub=0 psub=0 multi=-1 qbuf=0 qbuf-free=32768 obl=0 oll=0 omem=0 events=r cmd=client";
/**
* @see DATAREDIS-268
*/
@Test
public void convertingNullReplyToListOfRedisClientInfoShouldReturnEmptyList() {
assertThat(SrpConverters.toListOfRedisClientInformation(new BulkReply(null)),
equalTo(Collections.<RedisClientInfo> emptyList()));
}
/**
* @see DATAREDIS-268
*/
@Test
public void convertingEmptyReplyToListOfRedisClientInfoShouldReturnEmptyList() {
assertThat(SrpConverters.toListOfRedisClientInformation(new BulkReply(new byte[0])),
equalTo(Collections.<RedisClientInfo> emptyList()));
}
/**
* @see DATAREDIS-268
*/
@Test
public void convertingNullToListOfRedisClientInfoShouldReturnEmptyList() {
assertThat(SrpConverters.toListOfRedisClientInformation(null), equalTo(Collections.<RedisClientInfo> emptyList()));
}
/**
* @see DATAREDIS-268
*/
@Test
public void convertingMultipleLiesToListOfRedisClientInfoReturnsListCorrectly() {
StringBuilder sb = new StringBuilder();
sb.append(CLIENT_ALL_SINGLE_LINE_RESPONSE);
sb.append("\r\n");
sb.append(CLIENT_ALL_SINGLE_LINE_RESPONSE);
assertThat(SrpConverters.toListOfRedisClientInformation(new BulkReply(sb.toString().getBytes())).size(), equalTo(2));
}
/**
* @see DATAREDIS-268
*/
@Test(expected = IllegalArgumentException.class)
public void expectExcptionWhenProvidingInvalidDataInReply() {
SrpConverters.toListOfRedisClientInformation(new Reply<String>() {
@Override
public String data() {
return "foo";
}
@Override
public void write(OutputStream os) throws IOException {
// just do nothing;
}
});
}
}

View File

@@ -1,113 +0,0 @@
/*
* Copyright 2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.redis.connection.srp;
import java.nio.charset.Charset;
import org.hamcrest.core.IsEqual;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.springframework.core.convert.converter.Converter;
import redis.reply.BulkReply;
import redis.reply.Reply;
/**
* @author Christoph Strobl
* @author Thomas Darimont
*/
public class SrpReplyToTimeAsLongConverterUnitTests {
@SuppressWarnings("rawtypes") private Converter<Reply[], Long> converter;
@Before
public void setUp() {
this.converter = SrpConverters.repliesToTimeAsLong();
}
/**
* @see DATAREDIS-206
*/
@Test
public void testConverterShouldCreateMillisecondsCorrectlyWhenGivenValidReplyArray() {
Reply<?> seconds = new BulkReply("1392183718".getBytes(Charset.forName("UTF-8")));
Reply<?> microseconds = new BulkReply("555122".getBytes(Charset.forName("UTF-8")));
Assert.assertThat(converter.convert(new Reply[] { seconds, microseconds }), IsEqual.equalTo(1392183718555L));
}
/**
* @see DATAREDIS-206
*/
@Test(expected = IllegalArgumentException.class)
public void testConverterShouldThrowExceptionWhenGivenReplyArrayIsNull() {
converter.convert(null);
}
/**
* @see DATAREDIS-206
*/
@Test(expected = IllegalArgumentException.class)
public void testConverterShouldThrowExceptionWhenGivenReplyArrayIsEmpty() {
converter.convert(new Reply[] {});
}
/**
* @see DATAREDIS-206
*/
@Test(expected = IllegalArgumentException.class)
public void testConverterShouldThrowExceptionWhenGivenReplyArrayHasOnlyOneItem() {
converter.convert(new Reply[] { new BulkReply(null) });
}
/**
* @see DATAREDIS-206
*/
@Test(expected = IllegalArgumentException.class)
public void testConverterShouldThrowExceptionWhenGivenReplyArrayMoreThanTwoItems() {
converter.convert(new Reply[] { new BulkReply(null), new BulkReply(null), new BulkReply(null) });
}
/**
* @see DATAREDIS-206
*/
@Test(expected = NumberFormatException.class)
public void testConverterShouldThrowExecptionForNonParsableReply() {
Reply<?> invalidDataBlock = new BulkReply("123-not-a-number".getBytes(Charset.forName("UTF-8")));
Reply<?> microseconds = new BulkReply("555122".getBytes(Charset.forName("UTF-8")));
converter.convert(new Reply[] { invalidDataBlock, microseconds });
}
/**
* @see DATAREDIS-206
*/
@Test(expected = IllegalArgumentException.class)
public void testConverterShouldThrowExecptionForEmptyDataBlocks() {
Reply<?> invalidDataBlock = new BulkReply(null);
Reply<?> microseconds = new BulkReply("555122".getBytes(Charset.forName("UTF-8")));
converter.convert(new Reply[] { invalidDataBlock, microseconds });
}
}

View File

@@ -1,314 +0,0 @@
/*
* 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.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.any;
import java.util.Collection;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mockito;
import org.springframework.data.redis.connection.MessageListener;
import org.springframework.data.redis.connection.RedisInvalidSubscriptionException;
import redis.client.RedisClient;
import redis.client.ReplyListener;
/**
* Unit test of {@link SrpSubscription}
*
* @author Jennifer Hickey
*/
public class SrpSubscriptionTests {
private SrpSubscription subscription;
private RedisClient redisClient;
private MessageListener listener;
@Before
public void setUp() {
redisClient = Mockito.mock(RedisClient.class);
listener = Mockito.mock(MessageListener.class);
subscription = new SrpSubscription(listener, redisClient);
}
@Test
public void testUnsubscribeAllAndClose() {
subscription.subscribe(new byte[][] { "a".getBytes() });
subscription.unsubscribe();
verify(redisClient, times(1)).unsubscribe((Object[]) null);
verify(redisClient, never()).punsubscribe((Object[]) null);
assertFalse(subscription.isAlive());
verify(redisClient).removeListener(any(ReplyListener.class));
assertTrue(subscription.getChannels().isEmpty());
assertTrue(subscription.getPatterns().isEmpty());
}
@Test
public void testUnsubscribeAllChannelsWithPatterns() {
subscription.subscribe(new byte[][] { "a".getBytes() });
subscription.pSubscribe(new byte[][] { "s*".getBytes() });
subscription.unsubscribe();
verify(redisClient, times(1)).unsubscribe((Object[]) null);
verify(redisClient, never()).punsubscribe((Object[]) null);
assertTrue(subscription.isAlive());
assertTrue(subscription.getChannels().isEmpty());
Collection<byte[]> patterns = subscription.getPatterns();
assertEquals(1, patterns.size());
assertArrayEquals("s*".getBytes(), patterns.iterator().next());
}
@Test
public void testUnsubscribeChannelAndClose() {
byte[][] channel = new byte[][] { "a".getBytes() };
subscription.subscribe(channel);
subscription.unsubscribe(channel);
verify(redisClient, times(1)).unsubscribe((Object[]) channel);
verify(redisClient, never()).punsubscribe((Object[]) null);
verify(redisClient).removeListener(any(ReplyListener.class));
assertFalse(subscription.isAlive());
assertTrue(subscription.getChannels().isEmpty());
assertTrue(subscription.getPatterns().isEmpty());
}
@Test
public void testUnsubscribeChannelSomeLeft() {
byte[][] channels = new byte[][] { "a".getBytes(), "b".getBytes() };
subscription.subscribe(channels);
subscription.unsubscribe(new byte[][] { "a".getBytes() });
verify(redisClient, times(1)).unsubscribe((Object[]) new byte[][] { "a".getBytes() });
verify(redisClient, never()).punsubscribe((Object[]) null);
assertTrue(subscription.isAlive());
Collection<byte[]> subChannels = subscription.getChannels();
assertEquals(1, subChannels.size());
assertArrayEquals("b".getBytes(), subChannels.iterator().next());
assertTrue(subscription.getPatterns().isEmpty());
}
@Test
public void testUnsubscribeChannelWithPatterns() {
byte[][] channel = new byte[][] { "a".getBytes() };
subscription.subscribe(channel);
subscription.pSubscribe(new byte[][] { "s*".getBytes() });
subscription.unsubscribe(channel);
verify(redisClient, times(1)).unsubscribe((Object[]) channel);
verify(redisClient, never()).punsubscribe((Object[]) null);
assertTrue(subscription.isAlive());
assertTrue(subscription.getChannels().isEmpty());
Collection<byte[]> patterns = subscription.getPatterns();
assertEquals(1, patterns.size());
assertArrayEquals("s*".getBytes(), patterns.iterator().next());
}
@Test
public void testUnsubscribeChannelWithPatternsSomeLeft() {
byte[][] channel = new byte[][] { "a".getBytes() };
subscription.subscribe(new byte[][] { "a".getBytes(), "b".getBytes() });
subscription.pSubscribe(new byte[][] { "s*".getBytes() });
subscription.unsubscribe(channel);
verify(redisClient, times(1)).unsubscribe((Object[]) channel);
verify(redisClient, never()).punsubscribe((Object[]) null);
assertTrue(subscription.isAlive());
Collection<byte[]> channels = subscription.getChannels();
assertEquals(1, channels.size());
assertArrayEquals("b".getBytes(), channels.iterator().next());
Collection<byte[]> patterns = subscription.getPatterns();
assertEquals(1, patterns.size());
assertArrayEquals("s*".getBytes(), patterns.iterator().next());
}
@Test
public void testUnsubscribeAllNoChannels() {
subscription.pSubscribe(new byte[][] { "s*".getBytes() });
subscription.unsubscribe();
verify(redisClient, never()).unsubscribe((Object[]) null);
verify(redisClient, never()).punsubscribe((Object[]) null);
assertTrue(subscription.isAlive());
assertTrue(subscription.getChannels().isEmpty());
Collection<byte[]> patterns = subscription.getPatterns();
assertEquals(1, patterns.size());
assertArrayEquals("s*".getBytes(), patterns.iterator().next());
}
@Test
public void testUnsubscribeNotAlive() {
subscription.subscribe(new byte[][] { "a".getBytes() });
subscription.unsubscribe();
assertFalse(subscription.isAlive());
subscription.unsubscribe();
verify(redisClient, times(1)).removeListener(any(ReplyListener.class));
verify(redisClient, times(1)).unsubscribe((Object[]) null);
verify(redisClient, never()).punsubscribe((Object[]) null);
}
@Test(expected = RedisInvalidSubscriptionException.class)
public void testSubscribeNotAlive() {
subscription.subscribe(new byte[][] { "a".getBytes() });
subscription.unsubscribe();
assertFalse(subscription.isAlive());
subscription.subscribe(new byte[][] { "s".getBytes() });
}
@Test
public void testPUnsubscribeAllAndClose() {
subscription.pSubscribe(new byte[][] { "a*".getBytes() });
subscription.pUnsubscribe();
verify(redisClient, never()).unsubscribe((Object[]) null);
verify(redisClient, times(1)).punsubscribe((Object[]) null);
assertFalse(subscription.isAlive());
verify(redisClient).removeListener(any(ReplyListener.class));
assertTrue(subscription.getChannels().isEmpty());
assertTrue(subscription.getPatterns().isEmpty());
}
@Test
public void testPUnsubscribeAllPatternsWithChannels() {
subscription.subscribe(new byte[][] { "a".getBytes() });
subscription.pSubscribe(new byte[][] { "s*".getBytes() });
subscription.pUnsubscribe();
verify(redisClient, never()).unsubscribe((Object[]) null);
verify(redisClient, times(1)).punsubscribe((Object[]) null);
assertTrue(subscription.isAlive());
assertTrue(subscription.getPatterns().isEmpty());
Collection<byte[]> channels = subscription.getChannels();
assertEquals(1, channels.size());
assertArrayEquals("a".getBytes(), channels.iterator().next());
}
@Test
public void testPUnsubscribeAndClose() {
byte[][] pattern = new byte[][] { "a*".getBytes() };
subscription.pSubscribe(pattern);
subscription.pUnsubscribe(pattern);
verify(redisClient, never()).unsubscribe((Object[]) null);
verify(redisClient, times(1)).punsubscribe((Object[]) pattern);
assertFalse(subscription.isAlive());
verify(redisClient).removeListener(any(ReplyListener.class));
assertTrue(subscription.getChannels().isEmpty());
assertTrue(subscription.getPatterns().isEmpty());
}
@Test
public void testPUnsubscribePatternSomeLeft() {
byte[][] patterns = new byte[][] { "a*".getBytes(), "b*".getBytes() };
subscription.pSubscribe(patterns);
subscription.pUnsubscribe(new byte[][] { "a*".getBytes() });
verify(redisClient, times(1)).punsubscribe((Object[]) new byte[][] { "a*".getBytes() });
verify(redisClient, never()).unsubscribe((Object[]) null);
assertTrue(subscription.isAlive());
Collection<byte[]> subPatterns = subscription.getPatterns();
assertEquals(1, subPatterns.size());
assertArrayEquals("b*".getBytes(), subPatterns.iterator().next());
assertTrue(subscription.getChannels().isEmpty());
}
@Test
public void testPUnsubscribePatternWithChannels() {
byte[][] pattern = new byte[][] { "s*".getBytes() };
subscription.subscribe(new byte[][] { "a".getBytes() });
subscription.pSubscribe(pattern);
subscription.pUnsubscribe(pattern);
verify(redisClient, times(1)).punsubscribe((Object[]) pattern);
verify(redisClient, never()).unsubscribe((Object[]) null);
assertTrue(subscription.isAlive());
assertTrue(subscription.getPatterns().isEmpty());
Collection<byte[]> channels = subscription.getChannels();
assertEquals(1, channels.size());
assertArrayEquals("a".getBytes(), channels.iterator().next());
}
@Test
public void testUnsubscribePatternWithChannelsSomeLeft() {
byte[][] pattern = new byte[][] { "a*".getBytes() };
subscription.pSubscribe(new byte[][] { "a*".getBytes(), "b*".getBytes() });
subscription.subscribe(new byte[][] { "a".getBytes() });
subscription.pUnsubscribe(pattern);
verify(redisClient, never()).unsubscribe((Object[]) null);
verify(redisClient, times(1)).punsubscribe((Object[]) pattern);
assertTrue(subscription.isAlive());
Collection<byte[]> channels = subscription.getChannels();
assertEquals(1, channels.size());
assertArrayEquals("a".getBytes(), channels.iterator().next());
Collection<byte[]> patterns = subscription.getPatterns();
assertEquals(1, patterns.size());
assertArrayEquals("b*".getBytes(), patterns.iterator().next());
}
@Test
public void testPUnsubscribeAllNoPatterns() {
subscription.subscribe(new byte[][] { "s".getBytes() });
subscription.pUnsubscribe();
verify(redisClient, never()).unsubscribe((Object[]) null);
verify(redisClient, never()).punsubscribe((Object[]) null);
assertTrue(subscription.isAlive());
assertTrue(subscription.getPatterns().isEmpty());
Collection<byte[]> channels = subscription.getChannels();
assertEquals(1, channels.size());
assertArrayEquals("s".getBytes(), channels.iterator().next());
}
@Test
public void testPUnsubscribeNotAlive() {
subscription.subscribe(new byte[][] { "a".getBytes() });
subscription.unsubscribe();
assertFalse(subscription.isAlive());
subscription.pUnsubscribe();
verify(redisClient, times(1)).unsubscribe((Object[]) null);
verify(redisClient, never()).punsubscribe((Object[]) null);
verify(redisClient, times(1)).removeListener(any(ReplyListener.class));
}
@Test(expected = RedisInvalidSubscriptionException.class)
public void testPSubscribeNotAlive() {
subscription.subscribe(new byte[][] { "a".getBytes() });
subscription.unsubscribe();
assertFalse(subscription.isAlive());
subscription.pSubscribe(new byte[][] { "s*".getBytes() });
}
@Test
public void testDoCloseNotSubscribed() {
subscription.doClose();
verify(redisClient, never()).unsubscribe((Object[]) null);
verify(redisClient, never()).punsubscribe((Object[]) null);
}
@Test
public void testDoCloseSubscribedChannels() {
subscription.subscribe(new byte[][] { "a".getBytes() });
subscription.doClose();
verify(redisClient, times(1)).unsubscribe((Object[]) null);
verify(redisClient, never()).punsubscribe((Object[]) null);
}
@Test
public void testDoCloseSubscribedPatterns() {
subscription.pSubscribe(new byte[][] { "a*".getBytes() });
subscription.doClose();
verify(redisClient, never()).unsubscribe((Object[]) null);
verify(redisClient, times(1)).punsubscribe((Object[]) null);
}
}

View File

@@ -1,146 +0,0 @@
/*
* Copyright 2011-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.redis.connection.srp;
import org.junit.Test;
import org.springframework.data.redis.connection.DefaultSortParameters;
import org.springframework.data.redis.connection.SortParameters;
import java.util.ArrayList;
import java.util.List;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
/**
* Unit test of {@link SrpUtils}
*
* @author Jennifer Hickey
* @author Thomas Darimont Suppressed deprecation warnings since SrpUtils is deprecated.
*/
@SuppressWarnings("deprecation")
public class SrpUtilsTests {
@Test
public void testSortParamsWithAllParams() {
SortParameters sortParams = new DefaultSortParameters().alpha().asc().by("weight_*".getBytes())
.get("object_*".getBytes()).limit(0, 5);
Object[] sort = SrpUtils.sortParams(sortParams, "foo".getBytes());
assertArrayEquals(
new String[] { "BY", "weight_*", "LIMIT 0 5", "GET", "object_*", "ASC", "ALPHA", "STORE", "foo" },
convertByteArrays(sort));
}
@Test
public void testSortParamsOnlyBy() {
SortParameters sortParams = new DefaultSortParameters().numeric().by("weight_*".getBytes());
Object[] sort = SrpUtils.sortParams(sortParams);
assertArrayEquals(new String[] { "BY", "weight_*" }, convertByteArrays(sort));
}
@Test
public void testSortParamsOnlyLimit() {
SortParameters sortParams = new DefaultSortParameters().numeric().limit(0, 5);
Object[] sort = SrpUtils.sortParams(sortParams);
assertArrayEquals(new String[] { "LIMIT 0 5" }, convertByteArrays(sort));
}
@Test
public void testSortParamsOnlyGetPatterns() {
SortParameters sortParams = new DefaultSortParameters().numeric().get("foo".getBytes()).get("bar".getBytes());
Object[] sort = SrpUtils.sortParams(sortParams);
assertArrayEquals(new String[] { "GET", "foo", "GET", "bar" }, convertByteArrays(sort));
}
@Test
public void testSortParamsOnlyOrder() {
SortParameters sortParams = new DefaultSortParameters().numeric().desc();
Object[] sort = SrpUtils.sortParams(sortParams);
assertArrayEquals(new String[] { "DESC" }, convertByteArrays(sort));
}
@Test
public void testSortParamsOnlyAlpha() {
SortParameters sortParams = new DefaultSortParameters().alpha();
Object[] sort = SrpUtils.sortParams(sortParams);
assertArrayEquals(new String[] { "ALPHA" }, convertByteArrays(sort));
}
@Test
public void testSortParamsOnlyStore() {
SortParameters sortParams = new DefaultSortParameters().numeric();
Object[] sort = SrpUtils.sortParams(sortParams, "storelist".getBytes());
assertArrayEquals(new String[] { "STORE", "storelist" }, convertByteArrays(sort));
}
@Test
public void testSortWithAllParams() {
SortParameters sortParams = new DefaultSortParameters().alpha().asc().by("weight_*".getBytes())
.get("object_*".getBytes()).limit(0, 5);
byte[] sort = SrpUtils.sort(sortParams, "foo".getBytes());
assertEquals("BY weight_* LIMIT 0 5 GET object_* ASC ALPHA STORE foo", new String(sort));
}
@Test
public void testSortOnlyBy() {
SortParameters sortParams = new DefaultSortParameters().numeric().by("weight_*".getBytes());
byte[] sort = SrpUtils.sort(sortParams);
assertEquals("BY weight_*", new String(sort));
}
@Test
public void testSortOnlyLimit() {
SortParameters sortParams = new DefaultSortParameters().numeric().limit(0, 5);
byte[] sort = SrpUtils.sort(sortParams);
assertEquals("LIMIT 0 5", new String(sort));
}
@Test
public void testSortOnlyGetPatterns() {
SortParameters sortParams = new DefaultSortParameters().numeric().get("foo".getBytes()).get("bar".getBytes());
byte[] sort = SrpUtils.sort(sortParams);
assertEquals("GET foo GET bar", new String(sort));
}
@Test
public void testSortOnlyOrder() {
SortParameters sortParams = new DefaultSortParameters().numeric().desc();
byte[] sort = SrpUtils.sort(sortParams);
assertEquals("DESC", new String(sort));
}
@Test
public void testSortOnlyAlpha() {
SortParameters sortParams = new DefaultSortParameters().alpha();
byte[] sort = SrpUtils.sort(sortParams);
assertEquals("ALPHA", new String(sort));
}
@Test
public void testSortOnlyStore() {
SortParameters sortParams = new DefaultSortParameters().numeric();
byte[] sort = SrpUtils.sort(sortParams, "storelist".getBytes());
assertEquals("STORE storelist", new String(sort));
}
private String[] convertByteArrays(Object[] bytes) {
List<String> convertedParams = new ArrayList<String>();
for (Object b : bytes) {
convertedParams.add(new String((byte[]) b));
}
return convertedParams.toArray(new String[0]);
}
}

View File

@@ -1,45 +0,0 @@
/*
* Copyright 2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.redis.connection.srp;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.AbstractTransactionalTestBase;
import org.springframework.data.redis.connection.srp.TransactionalSrpItegrationTests.SrpContextConfiguration;
import org.springframework.test.context.ContextConfiguration;
/**
* @author Christoph Strobl
*/
@ContextConfiguration(classes = { SrpContextConfiguration.class })
public class TransactionalSrpItegrationTests extends AbstractTransactionalTestBase {
@Configuration
public static class SrpContextConfiguration extends RedisContextConfiguration {
@Override
@Bean
public SrpConnectionFactory redisConnectionFactory() {
SrpConnectionFactory factory = new SrpConnectionFactory();
factory.setHostName("localhost");
factory.setPort(6379);
return factory;
}
}
}

View File

@@ -33,7 +33,6 @@ import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
import org.springframework.data.redis.connection.lettuce.LettuceTestClientResources;
import org.springframework.data.redis.connection.srp.SrpConnectionFactory;
/**
* @author Artem Bilian
@@ -67,11 +66,7 @@ public class MultithreadedRedisTemplateTests {
lettuce.setPort(6379);
lettuce.afterPropertiesSet();
SrpConnectionFactory srp = new SrpConnectionFactory();
srp.setPort(6379);
srp.afterPropertiesSet();
return Arrays.asList(new Object[][] { { jedis }, { lettuce }, { srp } });
return Arrays.asList(new Object[][] { { jedis }, { lettuce } });
}
/**

View File

@@ -54,9 +54,7 @@ import org.springframework.data.redis.connection.DataType;
import org.springframework.data.redis.connection.RedisConnection;
import org.springframework.data.redis.connection.StringRedisConnection;
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
import org.springframework.data.redis.connection.jredis.JredisConnectionFactory;
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
import org.springframework.data.redis.connection.srp.SrpConnectionFactory;
import org.springframework.data.redis.core.ZSetOperations.TypedTuple;
import org.springframework.data.redis.core.query.SortQueryBuilder;
import org.springframework.data.redis.core.script.DefaultRedisScript;
@@ -202,8 +200,8 @@ public class RedisTemplateTests<K, V> {
});
List<V> list = Collections.singletonList(listValue);
Set<V> set = new HashSet<V>(Collections.singletonList(setValue));
Set<TypedTuple<V>> tupleSet = new LinkedHashSet<TypedTuple<V>>(Collections.singletonList(new DefaultTypedTuple<V>(
zsetValue, 1d)));
Set<TypedTuple<V>> tupleSet = new LinkedHashSet<TypedTuple<V>>(
Collections.singletonList(new DefaultTypedTuple<V>(zsetValue, 1d)));
assertThat(results, isEqual(Arrays.asList(new Object[] { value1, 1l, list, 1l, set, true, tupleSet })));
}
@@ -261,9 +259,13 @@ public class RedisTemplateTests<K, V> {
@Test
public void testExecConversionDisabled() {
SrpConnectionFactory factory2 = new SrpConnectionFactory(SettingsUtils.getHost(), SettingsUtils.getPort());
LettuceConnectionFactory factory2 = new LettuceConnectionFactory(SettingsUtils.getHost(), SettingsUtils.getPort());
factory2.setConvertPipelineAndTxResults(false);
factory2.afterPropertiesSet();
ConnectionFactoryTracker.add(factory2);
StringRedisTemplate template = new StringRedisTemplate(factory2);
template.afterPropertiesSet();
List<Object> results = template.execute(new SessionCallback<List<Object>>() {
@@ -490,30 +492,6 @@ public class RedisTemplateTests<K, V> {
}, 1500l);
}
@Test
public void testExpireMillisNotSupported() throws Exception {
assumeTrue(RedisTestProfileValueSource.matches("runLongTests", "true"));
assumeTrue(redisTemplate.getConnectionFactory() instanceof JredisConnectionFactory);
final K key1 = keyFactory.instance();
V value1 = valueFactory.instance();
assumeTrue(key1 instanceof String && value1 instanceof String);
final StringRedisTemplate template2 = new StringRedisTemplate(redisTemplate.getConnectionFactory());
template2.boundValueOps((String) key1).set((String) value1);
template2.expire((String) key1, 10, TimeUnit.MILLISECONDS);
Thread.sleep(15);
// 10 millis should get rounded up to 1 sec if pExpire not supported
assertTrue(template2.hasKey((String) key1));
waitFor(new TestCondition() {
public boolean passes() {
return (!template2.hasKey((String) key1));
}
}, 1000l);
}
@Test
public void testGetExpireNoTimeUnit() {
final K key1 = keyFactory.instance();

View File

@@ -1,69 +0,0 @@
/*
* Copyright 2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.redis.core.script.srp;
import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
import org.springframework.data.redis.SettingsUtils;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.connection.srp.SrpConnectionFactory;
import org.springframework.data.redis.core.script.AbstractDefaultScriptExecutorTests;
import org.springframework.data.redis.core.script.DefaultScriptExecutor;
/**
* Integration test of {@link DefaultScriptExecutor} with SRP.
*
* @author Thomas Darimont
*/
public class SrpDefaultScriptExecutorTests extends AbstractDefaultScriptExecutorTests {
private static SrpConnectionFactory connectionFactory;
@Before
public void setup() {
connectionFactory = new SrpConnectionFactory(SettingsUtils.getHost(), SettingsUtils.getPort());
connectionFactory.afterPropertiesSet();
}
@After
public void teardown() {
super.tearDown();
if (connectionFactory != null) {
connectionFactory.destroy();
}
}
@Override
protected RedisConnectionFactory getConnectionFactory() {
return connectionFactory;
}
@Ignore("transactional execution is currently not supported with SRP")
@Override
public void testExecuteTx() {
// super.testExecuteTx();
}
@Ignore("pipelined execution is currently not supported with SRP")
@Override
public void testExecutePipelined() {
// super.testExecutePipelined();
}
}

View File

@@ -16,7 +16,6 @@
package org.springframework.data.redis.listener;
import static org.hamcrest.core.Is.*;
import static org.junit.Assert.*;
import static org.junit.Assume.*;
import static org.springframework.data.redis.SpinBarrier.*;
@@ -46,13 +45,10 @@ import org.springframework.data.redis.ConnectionFactoryTracker;
import org.springframework.data.redis.RedisTestProfileValueSource;
import org.springframework.data.redis.SettingsUtils;
import org.springframework.data.redis.TestCondition;
import org.springframework.data.redis.connection.ConnectionUtils;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
import org.springframework.data.redis.connection.jredis.JredisConnectionFactory;
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
import org.springframework.data.redis.connection.lettuce.LettuceTestClientResources;
import org.springframework.data.redis.connection.srp.SrpConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.listener.adapter.MessageListenerAdapter;
@@ -75,7 +71,7 @@ public class PubSubResubscribeTests {
private RedisMessageListenerContainer container;
private RedisConnectionFactory factory;
@SuppressWarnings("rawtypes")//
@SuppressWarnings("rawtypes") //
private RedisTemplate template;
public PubSubResubscribeTests(RedisConnectionFactory connectionFactory) {
@@ -99,7 +95,7 @@ public class PubSubResubscribeTests {
int port = SettingsUtils.getPort();
String host = SettingsUtils.getHost();
// Jedis
JedisConnectionFactory jedisConnFactory = new JedisConnectionFactory();
jedisConnFactory.setUsePool(false);
@@ -117,29 +113,12 @@ public class PubSubResubscribeTests {
lettuceConnFactory.setValidateConnection(true);
lettuceConnFactory.afterPropertiesSet();
// SRP
SrpConnectionFactory srpConnFactory = new SrpConnectionFactory();
srpConnFactory.setPort(port);
srpConnFactory.setHostName(host);
srpConnFactory.afterPropertiesSet();
// JRedis
JredisConnectionFactory jRedisConnectionFactory = new JredisConnectionFactory();
jRedisConnectionFactory.setPort(port);
jRedisConnectionFactory.setHostName(host);
jRedisConnectionFactory.setDatabase(2);
jRedisConnectionFactory.afterPropertiesSet();
return Arrays.asList(new Object[][] { { jedisConnFactory }, { lettuceConnFactory }, { srpConnFactory },
{ jRedisConnectionFactory } });
return Arrays.asList(new Object[][] { { jedisConnFactory }, { lettuceConnFactory } });
}
@Before
public void setUp() throws Exception {
// JredisConnection#publish is currently not supported -> tests would fail
assumeThat(ConnectionUtils.isJredis(factory), is(false));
template = new StringRedisTemplate(factory);
adapter.setSerializer(template.getValueSerializer());

View File

@@ -27,7 +27,6 @@ import org.springframework.data.redis.StringObjectFactory;
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
import org.springframework.data.redis.connection.lettuce.LettuceTestClientResources;
import org.springframework.data.redis.connection.srp.SrpConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
@@ -77,26 +76,8 @@ public class PubSubTestParams {
rawTemplateLtc.setConnectionFactory(lettuceConnFactory);
rawTemplateLtc.afterPropertiesSet();
// SRP
SrpConnectionFactory srpConnFactory = new SrpConnectionFactory();
srpConnFactory.setPort(SettingsUtils.getPort());
srpConnFactory.setHostName(SettingsUtils.getHost());
srpConnFactory.afterPropertiesSet();
RedisTemplate<String, String> stringTemplateSrp = new StringRedisTemplate(srpConnFactory);
RedisTemplate<String, Person> personTemplateSrp = new RedisTemplate<String, Person>();
personTemplateSrp.setConnectionFactory(srpConnFactory);
personTemplateSrp.afterPropertiesSet();
RedisTemplate<byte[], byte[]> rawTemplateSrp = new RedisTemplate<byte[], byte[]>();
rawTemplateSrp.setEnableDefaultSerializer(false);
rawTemplateSrp.setConnectionFactory(srpConnFactory);
rawTemplateSrp.afterPropertiesSet();
// JRedis does not support pub/sub
return Arrays.asList(new Object[][] { { stringFactory, stringTemplate }, { personFactory, personTemplate },
{ rawFactory, rawTemplate }, { stringFactory, stringTemplateLtc }, { personFactory, personTemplateLtc },
{ rawFactory, rawTemplateLtc }, { stringFactory, stringTemplateSrp }, { personFactory, personTemplateSrp },
{ rawFactory, rawTemplateSrp } });
{ rawFactory, rawTemplateLtc } });
}
}

View File

@@ -36,10 +36,8 @@ import org.springframework.data.redis.connection.MessageListener;
import org.springframework.data.redis.connection.RedisConnection;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
import org.springframework.data.redis.connection.jredis.JredisConnectionFactory;
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
import org.springframework.data.redis.connection.lettuce.LettuceTestClientResources;
import org.springframework.data.redis.connection.srp.SrpConnectionFactory;
import org.springframework.data.redis.listener.adapter.MessageListenerAdapter;
/**
@@ -107,21 +105,7 @@ public class SubscriptionConnectionTests {
lettuceConnFactory.setValidateConnection(true);
lettuceConnFactory.afterPropertiesSet();
// SRP
SrpConnectionFactory srpConnFactory = new SrpConnectionFactory();
srpConnFactory.setPort(port);
srpConnFactory.setHostName(host);
srpConnFactory.afterPropertiesSet();
// JRedis
JredisConnectionFactory jRedisConnectionFactory = new JredisConnectionFactory();
jRedisConnectionFactory.setPort(port);
jRedisConnectionFactory.setHostName(host);
jRedisConnectionFactory.setDatabase(2);
jRedisConnectionFactory.afterPropertiesSet();
return Arrays.asList(new Object[][] { { jedisConnFactory }, { lettuceConnFactory }, { srpConnFactory },
{ jRedisConnectionFactory } });
return Arrays.asList(new Object[][] { { jedisConnFactory }, { lettuceConnFactory } });
}
@Test

View File

@@ -16,7 +16,6 @@
package org.springframework.data.redis.support;
import static org.junit.Assert.*;
import static org.junit.Assume.*;
import java.util.Collection;
import java.util.Map;
@@ -32,7 +31,6 @@ import org.junit.runners.Parameterized.Parameters;
import org.springframework.dao.DataAccessException;
import org.springframework.data.redis.ConnectionFactoryTracker;
import org.springframework.data.redis.ObjectFactory;
import org.springframework.data.redis.connection.ConnectionUtils;
import org.springframework.data.redis.connection.RedisConnection;
import org.springframework.data.redis.core.BoundKeyOperations;
import org.springframework.data.redis.core.RedisCallback;
@@ -49,12 +47,12 @@ import org.springframework.data.redis.support.atomic.RedisAtomicLong;
@RunWith(Parameterized.class)
public class BoundKeyOperationsTest {
@SuppressWarnings("rawtypes")//
@SuppressWarnings("rawtypes") //
private BoundKeyOperations keyOps;
private ObjectFactory<Object> objFactory;
@SuppressWarnings("rawtypes")//
@SuppressWarnings("rawtypes") //
private RedisTemplate template;
@SuppressWarnings("rawtypes")
@@ -127,7 +125,6 @@ public class BoundKeyOperationsTest {
*/
@Test
public void testPersist() throws Exception {
assumeTrue(!ConnectionUtils.isJredis(template.getConnectionFactory()));
keyOps.persist();

View File

@@ -21,10 +21,8 @@ import java.util.Collection;
import org.springframework.data.redis.SettingsUtils;
import org.springframework.data.redis.StringObjectFactory;
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
import org.springframework.data.redis.connection.jredis.JredisConnectionFactory;
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
import org.springframework.data.redis.connection.lettuce.LettuceTestClientResources;
import org.springframework.data.redis.connection.srp.SrpConnectionFactory;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.support.atomic.RedisAtomicInteger;
import org.springframework.data.redis.support.atomic.RedisAtomicLong;
@@ -52,16 +50,6 @@ public class BoundKeyParams {
DefaultRedisSet setJS = new DefaultRedisSet("bound:key:set", templateJS);
RedisList list = new DefaultRedisList("bound:key:list", templateJS);
// JRedis
JredisConnectionFactory jredisConnFactory = new JredisConnectionFactory();
jredisConnFactory.setPort(SettingsUtils.getPort());
jredisConnFactory.setHostName(SettingsUtils.getHost());
jredisConnFactory.afterPropertiesSet();
StringRedisTemplate templateJR = new StringRedisTemplate(jredisConnFactory);
DefaultRedisMap mapJR = new DefaultRedisMap("bound:key:mapJR", templateJR);
// Skip list and set. Rename in Collections uses Redis tx, not supported by JRedis
// Lettuce
LettuceConnectionFactory lettuceConnFactory = new LettuceConnectionFactory();
lettuceConnFactory.setClientResources(LettuceTestClientResources.getSharedClientResources());
@@ -74,30 +62,14 @@ public class BoundKeyParams {
DefaultRedisSet setLT = new DefaultRedisSet("bound:key:setLT", templateLT);
RedisList listLT = new DefaultRedisList("bound:key:listLT", templateLT);
// SRP
SrpConnectionFactory srpConnFactory = new SrpConnectionFactory();
srpConnFactory.setPort(SettingsUtils.getPort());
srpConnFactory.setHostName(SettingsUtils.getHost());
srpConnFactory.afterPropertiesSet();
StringRedisTemplate templateSRP = new StringRedisTemplate(srpConnFactory);
DefaultRedisMap mapSRP = new DefaultRedisMap("bound:key:mapSRP", templateSRP);
DefaultRedisSet setSRP = new DefaultRedisSet("bound:key:setSRP", templateSRP);
RedisList listSRP = new DefaultRedisList("bound:key:listSRP", templateSRP);
StringObjectFactory sof = new StringObjectFactory();
return Arrays.asList(new Object[][] {
{ new RedisAtomicInteger("bound:key:int", jedisConnFactory), sof, templateJS },
{ new RedisAtomicLong("bound:key:long", jedisConnFactory), sof, templateJS }, { list, sof, templateJS },
{ setJS, sof, templateJS }, { mapJS, sof, templateJS },
{ new RedisAtomicInteger("bound:key:intJR", jredisConnFactory), sof, templateJR },
{ new RedisAtomicLong("bound:key:longJR", jredisConnFactory), sof, templateJR }, { mapJR, sof, templateJR },
{ new RedisAtomicInteger("bound:key:intLT", lettuceConnFactory), sof, templateLT },
{ new RedisAtomicLong("bound:key:longLT", lettuceConnFactory), sof, templateLT }, { listLT, sof, templateLT },
{ setLT, sof, templateLT }, { mapLT, sof, templateLT },
{ new RedisAtomicInteger("bound:key:intSrp", srpConnFactory), sof, templateSRP },
{ new RedisAtomicLong("bound:key:longSrp", srpConnFactory), sof, templateSRP }, { listSRP, sof, templateSRP },
{ setSRP, sof, templateSRP }, { mapSRP, sof, templateSRP } });
return Arrays
.asList(new Object[][] { { new RedisAtomicInteger("bound:key:int", jedisConnFactory), sof, templateJS },
{ new RedisAtomicLong("bound:key:long", jedisConnFactory), sof, templateJS }, { list, sof, templateJS },
{ setJS, sof, templateJS }, { mapJS, sof, templateJS },
{ new RedisAtomicInteger("bound:key:intLT", lettuceConnFactory), sof, templateLT },
{ new RedisAtomicLong("bound:key:longLT", lettuceConnFactory), sof, templateLT },
{ listLT, sof, templateLT }, { setLT, sof, templateLT }, { mapLT, sof, templateLT } });
}
}

View File

@@ -20,11 +20,8 @@ import java.util.Collection;
import org.springframework.data.redis.SettingsUtils;
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
import org.springframework.data.redis.connection.jredis.JredisPool;
import org.springframework.data.redis.connection.jredis.JredisConnectionFactory;
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
import org.springframework.data.redis.connection.lettuce.LettuceTestClientResources;
import org.springframework.data.redis.connection.srp.SrpConnectionFactory;
/**
* @author Costin Leau
@@ -41,11 +38,6 @@ public abstract class AtomicCountersParam {
jedisConnFactory.setUsePool(true);
jedisConnFactory.afterPropertiesSet();
// JRedis
JredisConnectionFactory jredisConnFactory = new JredisConnectionFactory(new JredisPool(SettingsUtils.getHost(),
SettingsUtils.getPort()));
jredisConnFactory.afterPropertiesSet();
// Lettuce
LettuceConnectionFactory lettuceConnFactory = new LettuceConnectionFactory();
lettuceConnFactory.setClientResources(LettuceTestClientResources.getSharedClientResources());
@@ -53,13 +45,6 @@ public abstract class AtomicCountersParam {
lettuceConnFactory.setHostName(SettingsUtils.getHost());
lettuceConnFactory.afterPropertiesSet();
// SRP
SrpConnectionFactory srpConnFactory = new SrpConnectionFactory();
srpConnFactory.setPort(SettingsUtils.getPort());
srpConnFactory.setHostName(SettingsUtils.getHost());
srpConnFactory.afterPropertiesSet();
return Arrays.asList(new Object[][] { { jedisConnFactory }, { jredisConnFactory }, { lettuceConnFactory },
{ srpConnFactory } });
return Arrays.asList(new Object[][] { { jedisConnFactory }, { lettuceConnFactory } });
}
}

View File

@@ -94,8 +94,7 @@ public class RedisAtomicDoubleTests extends AbstractRedisAtomicsTests {
@Test
public void testCheckAndSet() {
// Txs not supported in Jredis
assumeTrue(!ConnectionUtils.isJredis(factory));
doubleCounter.set(0);
assertFalse(doubleCounter.compareAndSet(1.2, 10.6));
assertTrue(doubleCounter.compareAndSet(0, 10.6));
@@ -104,14 +103,14 @@ public class RedisAtomicDoubleTests extends AbstractRedisAtomicsTests {
@Test
public void testIncrementAndGet() throws Exception {
assumeTrue(!ConnectionUtils.isJredis(factory) && !(ConnectionUtils.isJedis(factory)));
assumeTrue(!(ConnectionUtils.isJedis(factory)));
doubleCounter.set(0);
assertEquals(1.0, doubleCounter.incrementAndGet(), 0);
}
@Test
public void testAddAndGet() throws Exception {
assumeTrue(!ConnectionUtils.isJredis(factory) && !(ConnectionUtils.isJedis(factory)));
assumeTrue(!(ConnectionUtils.isJedis(factory)));
doubleCounter.set(0);
double delta = 1.3;
assertEquals(delta, doubleCounter.addAndGet(delta), .0001);
@@ -119,7 +118,7 @@ public class RedisAtomicDoubleTests extends AbstractRedisAtomicsTests {
@Test
public void testDecrementAndGet() throws Exception {
assumeTrue(!ConnectionUtils.isJredis(factory) && !(ConnectionUtils.isJedis(factory)));
assumeTrue(!(ConnectionUtils.isJedis(factory)));
doubleCounter.set(1);
assertEquals(0, doubleCounter.decrementAndGet(), 0);
}
@@ -133,7 +132,7 @@ public class RedisAtomicDoubleTests extends AbstractRedisAtomicsTests {
@Test
public void testGetAndIncrement() {
assumeTrue(!ConnectionUtils.isJredis(factory) && !(ConnectionUtils.isJedis(factory)));
assumeTrue(!(ConnectionUtils.isJedis(factory)));
doubleCounter.set(2.3);
assertEquals(2.3, doubleCounter.getAndIncrement(), 0);
assertEquals(3.3, doubleCounter.get(), .0001);
@@ -141,7 +140,7 @@ public class RedisAtomicDoubleTests extends AbstractRedisAtomicsTests {
@Test
public void testGetAndDecrement() {
assumeTrue(!ConnectionUtils.isJredis(factory) && !(ConnectionUtils.isJedis(factory)));
assumeTrue(!(ConnectionUtils.isJedis(factory)));
doubleCounter.set(0.5);
assertEquals(0.5, doubleCounter.getAndDecrement(), 0);
assertEquals(-0.5, doubleCounter.get(), .0001);
@@ -149,7 +148,7 @@ public class RedisAtomicDoubleTests extends AbstractRedisAtomicsTests {
@Test
public void testGetAndAdd() {
assumeTrue(!ConnectionUtils.isJredis(factory) && !(ConnectionUtils.isJedis(factory)));
assumeTrue(!(ConnectionUtils.isJedis(factory)));
doubleCounter.set(0.5);
assertEquals(0.5, doubleCounter.getAndAdd(0.7), 0);
assertEquals(1.2, doubleCounter.get(), .0001);
@@ -163,8 +162,7 @@ public class RedisAtomicDoubleTests extends AbstractRedisAtomicsTests {
@Test
public void testExpireAt() {
// JRedis converts Unix time to millis before sending command, so it expires right away
assumeTrue(!ConnectionUtils.isJredis(factory));
doubleCounter.set(7.8);
assertTrue(doubleCounter.expireAt(new Date(System.currentTimeMillis() + 10000)));
assertTrue(doubleCounter.getExpire() > 0);

View File

@@ -17,7 +17,6 @@ package org.springframework.data.redis.support.atomic;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;
import static org.junit.Assume.*;
import java.util.Collection;
import java.util.concurrent.CountDownLatch;
@@ -32,7 +31,6 @@ import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import org.springframework.dao.DataRetrievalFailureException;
import org.springframework.data.redis.ConnectionFactoryTracker;
import org.springframework.data.redis.connection.ConnectionUtils;
import org.springframework.data.redis.connection.RedisConnection;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
@@ -88,8 +86,7 @@ public class RedisAtomicIntegerTests extends AbstractRedisAtomicsTests {
@Test
public void testCheckAndSet() {
// Txs not supported in Jredis
assumeTrue(!ConnectionUtils.isJredis(factory));
intCounter.set(0);
assertFalse(intCounter.compareAndSet(1, 10));
assertTrue(intCounter.compareAndSet(0, 10));
@@ -162,8 +159,7 @@ public class RedisAtomicIntegerTests extends AbstractRedisAtomicsTests {
@Test
@Ignore("DATAREDIS-108 Test is intermittently failing")
public void testCompareSet() throws Exception {
// Txs not supported in Jredis
assumeTrue(!ConnectionUtils.isJredis(factory));
final AtomicBoolean alreadySet = new AtomicBoolean(false);
final int NUM = 50;
final String KEY = getClass().getSimpleName() + ":atomic:counter";

View File

@@ -17,7 +17,6 @@ package org.springframework.data.redis.support.atomic;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;
import static org.junit.Assume.*;
import java.util.Collection;
@@ -29,7 +28,6 @@ import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import org.springframework.dao.DataRetrievalFailureException;
import org.springframework.data.redis.ConnectionFactoryTracker;
import org.springframework.data.redis.connection.ConnectionUtils;
import org.springframework.data.redis.connection.RedisConnection;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
@@ -84,8 +82,7 @@ public class RedisAtomicLongTests extends AbstractRedisAtomicsTests {
@Test
public void testCheckAndSet() throws Exception {
// Txs not supported in Jredis
assumeTrue(!ConnectionUtils.isJredis(factory));
longCounter.set(0);
assertFalse(longCounter.compareAndSet(1, 10));
assertTrue(longCounter.compareAndSet(0, 10));
@@ -111,7 +108,7 @@ public class RedisAtomicLongTests extends AbstractRedisAtomicsTests {
assertEquals(0, longCounter.decrementAndGet());
}
/**
/**
* @see DATAREDIS-469
*/
@Test

View File

@@ -15,15 +15,9 @@
*/
package org.springframework.data.redis.support.collections;
import static org.hamcrest.CoreMatchers.hasItem;
import static org.hamcrest.CoreMatchers.hasItems;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.junit.Assume.assumeTrue;
import static org.springframework.data.redis.matcher.RedisTestMatchers.isEqual;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;
import static org.springframework.data.redis.matcher.RedisTestMatchers.*;
import java.util.ArrayList;
import java.util.Arrays;
@@ -35,7 +29,6 @@ import java.util.concurrent.TimeUnit;
import org.junit.Before;
import org.junit.Test;
import org.springframework.data.redis.ObjectFactory;
import org.springframework.data.redis.connection.ConnectionUtils;
import org.springframework.data.redis.core.RedisTemplate;
/**
@@ -234,7 +227,7 @@ public abstract class AbstractRedisListTests<T> extends AbstractRedisCollectionT
@Test
public void testPollTimeout() throws InterruptedException {
assumeTrue(!ConnectionUtils.isJredis(template.getConnectionFactory()));
T t1 = getT();
list.add(t1);
assertThat(list.poll(1, TimeUnit.MILLISECONDS), isEqual(t1));
@@ -466,7 +459,7 @@ public abstract class AbstractRedisListTests<T> extends AbstractRedisCollectionT
@Test
public void testPollLastTimeout() throws InterruptedException {
assumeTrue(!ConnectionUtils.isJredis(template.getConnectionFactory()));
T t1 = getT();
T t2 = getT();

View File

@@ -44,7 +44,6 @@ import org.springframework.data.redis.DoubleAsStringObjectFactory;
import org.springframework.data.redis.LongAsStringObjectFactory;
import org.springframework.data.redis.ObjectFactory;
import org.springframework.data.redis.RedisSystemException;
import org.springframework.data.redis.connection.ConnectionUtils;
import org.springframework.data.redis.connection.RedisConnection;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.Cursor;
@@ -212,8 +211,7 @@ public abstract class AbstractRedisMapTests<K, V> {
@Test
public void testIncrementNotNumber() {
assumeTrue(!ConnectionUtils.isJredis(template.getConnectionFactory())
&& !(valueFactory instanceof LongAsStringObjectFactory));
assumeTrue(!(valueFactory instanceof LongAsStringObjectFactory));
K k1 = getKey();
V v1 = getValue();
@@ -291,7 +289,7 @@ public abstract class AbstractRedisMapTests<K, V> {
@Test
public void testPutAll() {
assumeTrue(!ConnectionUtils.isJredis(template.getConnectionFactory()));
Map<K, V> m = new LinkedHashMap<K, V>();
K k1 = getKey();
K k2 = getKey();
@@ -372,7 +370,7 @@ public abstract class AbstractRedisMapTests<K, V> {
@SuppressWarnings("unchecked")
@Test
public void testEntrySet() {
assumeTrue(!ConnectionUtils.isJredis(template.getConnectionFactory()));
Set<Entry<K, V>> entries = map.entrySet();
assertTrue(entries.isEmpty());
@@ -404,7 +402,7 @@ public abstract class AbstractRedisMapTests<K, V> {
@Test
public void testPutIfAbsent() {
assumeTrue(!ConnectionUtils.isJredis(template.getConnectionFactory()));
K k1 = getKey();
K k2 = getKey();
@@ -424,7 +422,7 @@ public abstract class AbstractRedisMapTests<K, V> {
@Test
public void testConcurrentRemove() {
assumeTrue(!ConnectionUtils.isJredis(template.getConnectionFactory()));
K k1 = getKey();
V v1 = getValue();
V v2 = getValue();
@@ -444,7 +442,7 @@ public abstract class AbstractRedisMapTests<K, V> {
@Test
public void testConcurrentReplaceTwoArgs() {
assumeTrue(!ConnectionUtils.isJredis(template.getConnectionFactory()));
K k1 = getKey();
V v1 = getValue();
V v2 = getValue();
@@ -471,7 +469,7 @@ public abstract class AbstractRedisMapTests<K, V> {
@Test
public void testConcurrentReplaceOneArg() {
assumeTrue(!ConnectionUtils.isJredis(template.getConnectionFactory()));
K k1 = getKey();
V v1 = getValue();
V v2 = getValue();

View File

@@ -34,7 +34,6 @@ import org.springframework.data.redis.DoubleObjectFactory;
import org.springframework.data.redis.LongAsStringObjectFactory;
import org.springframework.data.redis.LongObjectFactory;
import org.springframework.data.redis.ObjectFactory;
import org.springframework.data.redis.connection.ConnectionUtils;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.connection.RedisZSetCommands;
import org.springframework.data.redis.core.BoundZSetOperations;
@@ -219,7 +218,7 @@ public abstract class AbstractRedisZSetTest<T> extends AbstractRedisCollectionTe
@SuppressWarnings("unchecked")
@Test
public void testIntersectAndStore() {
assumeTrue(!ConnectionUtils.isJredis(template.getConnectionFactory()));
RedisZSet<T> interSet1 = createZSetFor("test:zset:inter1");
RedisZSet<T> interSet2 = createZSetFor("test:zset:inter");
@@ -265,7 +264,7 @@ public abstract class AbstractRedisZSetTest<T> extends AbstractRedisCollectionTe
@Test
public void testRangeWithScores() {
assumeTrue(!ConnectionUtils.isJredis(template.getConnectionFactory()));
T t1 = getT();
T t2 = getT();
T t3 = getT();
@@ -306,7 +305,7 @@ public abstract class AbstractRedisZSetTest<T> extends AbstractRedisCollectionTe
@Test
public void testReverseRangeWithScores() {
assumeTrue(!ConnectionUtils.isJredis(template.getConnectionFactory()));
T t1 = getT();
T t2 = getT();
T t3 = getT();
@@ -334,10 +333,8 @@ public abstract class AbstractRedisZSetTest<T> extends AbstractRedisCollectionTe
@Test
public void testRangeByLexUnbounded() {
assumeThat(
factory,
anyOf(instanceOf(DoubleObjectFactory.class), instanceOf(DoubleAsStringObjectFactory.class),
instanceOf(LongAsStringObjectFactory.class), instanceOf(LongObjectFactory.class)));
assumeThat(factory, anyOf(instanceOf(DoubleObjectFactory.class), instanceOf(DoubleAsStringObjectFactory.class),
instanceOf(LongAsStringObjectFactory.class), instanceOf(LongObjectFactory.class)));
T t1 = getT();
T t2 = getT();
@@ -359,10 +356,8 @@ public abstract class AbstractRedisZSetTest<T> extends AbstractRedisCollectionTe
@Test
public void testRangeByLexBounded() {
assumeThat(
factory,
anyOf(instanceOf(DoubleObjectFactory.class), instanceOf(DoubleAsStringObjectFactory.class),
instanceOf(LongAsStringObjectFactory.class), instanceOf(LongObjectFactory.class)));
assumeThat(factory, anyOf(instanceOf(DoubleObjectFactory.class), instanceOf(DoubleAsStringObjectFactory.class),
instanceOf(LongAsStringObjectFactory.class), instanceOf(LongObjectFactory.class)));
T t1 = getT();
T t2 = getT();
@@ -384,10 +379,8 @@ public abstract class AbstractRedisZSetTest<T> extends AbstractRedisCollectionTe
@Test
public void testRangeByLexUnboundedWithLimit() {
assumeThat(
factory,
anyOf(instanceOf(DoubleObjectFactory.class), instanceOf(DoubleAsStringObjectFactory.class),
instanceOf(LongAsStringObjectFactory.class), instanceOf(LongObjectFactory.class)));
assumeThat(factory, anyOf(instanceOf(DoubleObjectFactory.class), instanceOf(DoubleAsStringObjectFactory.class),
instanceOf(LongAsStringObjectFactory.class), instanceOf(LongObjectFactory.class)));
T t1 = getT();
T t2 = getT();
@@ -396,8 +389,8 @@ public abstract class AbstractRedisZSetTest<T> extends AbstractRedisCollectionTe
zSet.add(t1, 1);
zSet.add(t2, 2);
zSet.add(t3, 3);
Set<T> tuples = zSet.rangeByLex(RedisZSetCommands.Range.unbounded(), RedisZSetCommands.Limit.limit().count(1)
.offset(1));
Set<T> tuples = zSet.rangeByLex(RedisZSetCommands.Range.unbounded(),
RedisZSetCommands.Limit.limit().count(1).offset(1));
assertEquals(1, tuples.size());
T tuple = tuples.iterator().next();
@@ -410,10 +403,8 @@ public abstract class AbstractRedisZSetTest<T> extends AbstractRedisCollectionTe
@Test
public void testRangeByLexBoundedWithLimit() {
assumeThat(
factory,
anyOf(instanceOf(DoubleObjectFactory.class), instanceOf(DoubleAsStringObjectFactory.class),
instanceOf(LongAsStringObjectFactory.class), instanceOf(LongObjectFactory.class)));
assumeThat(factory, anyOf(instanceOf(DoubleObjectFactory.class), instanceOf(DoubleAsStringObjectFactory.class),
instanceOf(LongAsStringObjectFactory.class), instanceOf(LongObjectFactory.class)));
T t1 = getT();
T t2 = getT();
@@ -422,8 +413,8 @@ public abstract class AbstractRedisZSetTest<T> extends AbstractRedisCollectionTe
zSet.add(t1, 1);
zSet.add(t2, 2);
zSet.add(t3, 3);
Set<T> tuples = zSet.rangeByLex(RedisZSetCommands.Range.range().gte(t1), RedisZSetCommands.Limit.limit().count(1)
.offset(1));
Set<T> tuples = zSet.rangeByLex(RedisZSetCommands.Range.range().gte(t1),
RedisZSetCommands.Limit.limit().count(1).offset(1));
assertEquals(1, tuples.size());
T tuple = tuples.iterator().next();
@@ -432,7 +423,7 @@ public abstract class AbstractRedisZSetTest<T> extends AbstractRedisCollectionTe
@Test
public void testReverseRangeByScore() {
assumeTrue(!ConnectionUtils.isJredis(template.getConnectionFactory()));
T t1 = getT();
T t2 = getT();
T t3 = getT();
@@ -450,7 +441,7 @@ public abstract class AbstractRedisZSetTest<T> extends AbstractRedisCollectionTe
@Test
public void testReverseRangeByScoreWithScores() {
assumeTrue(!ConnectionUtils.isJredis(template.getConnectionFactory()));
T t1 = getT();
T t2 = getT();
T t3 = getT();
@@ -494,7 +485,7 @@ public abstract class AbstractRedisZSetTest<T> extends AbstractRedisCollectionTe
@Test
public void testRangeByScoreWithScores() {
assumeTrue(!ConnectionUtils.isJredis(template.getConnectionFactory()));
T t1 = getT();
T t2 = getT();
T t3 = getT();
@@ -560,7 +551,7 @@ public abstract class AbstractRedisZSetTest<T> extends AbstractRedisCollectionTe
@SuppressWarnings("unchecked")
@Test
public void testUnionAndStore() {
assumeTrue(!ConnectionUtils.isJredis(template.getConnectionFactory()));
RedisZSet<T> unionSet1 = createZSetFor("test:zset:union1");
RedisZSet<T> unionSet2 = createZSetFor("test:zset:union2");

View File

@@ -26,11 +26,8 @@ import org.springframework.data.redis.RawObjectFactory;
import org.springframework.data.redis.SettingsUtils;
import org.springframework.data.redis.StringObjectFactory;
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
import org.springframework.data.redis.connection.jredis.JredisConnectionFactory;
import org.springframework.data.redis.connection.jredis.JredisPool;
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
import org.springframework.data.redis.connection.lettuce.LettuceTestClientResources;
import org.springframework.data.redis.connection.srp.SrpConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
@@ -106,79 +103,6 @@ public abstract class CollectionTestParams {
rawTemplate.setKeySerializer(stringSerializer);
rawTemplate.afterPropertiesSet();
// jredis
JredisConnectionFactory jredisConnFactory = new JredisConnectionFactory(new JredisPool(SettingsUtils.getHost(),
SettingsUtils.getPort()));
jredisConnFactory.afterPropertiesSet();
RedisTemplate<String, String> stringTemplateJR = new StringRedisTemplate(jredisConnFactory);
RedisTemplate<String, Person> personTemplateJR = new RedisTemplate<String, Person>();
personTemplateJR.setConnectionFactory(jredisConnFactory);
personTemplateJR.afterPropertiesSet();
RedisTemplate<String, Person> xstreamStringTemplateJR = new RedisTemplate<String, Person>();
xstreamStringTemplateJR.setConnectionFactory(jredisConnFactory);
xstreamStringTemplateJR.setDefaultSerializer(serializer);
xstreamStringTemplateJR.afterPropertiesSet();
RedisTemplate<String, Person> xstreamPersonTemplateJR = new RedisTemplate<String, Person>();
xstreamPersonTemplateJR.setValueSerializer(serializer);
xstreamPersonTemplateJR.setConnectionFactory(jredisConnFactory);
xstreamPersonTemplateJR.afterPropertiesSet();
RedisTemplate<String, Person> jsonPersonTemplateJR = new RedisTemplate<String, Person>();
jsonPersonTemplateJR.setValueSerializer(jsonSerializer);
jsonPersonTemplateJR.setConnectionFactory(jredisConnFactory);
jsonPersonTemplateJR.afterPropertiesSet();
RedisTemplate<String, Person> jackson2JsonPersonTemplateJR = new RedisTemplate<String, Person>();
jackson2JsonPersonTemplateJR.setValueSerializer(jackson2JsonSerializer);
jackson2JsonPersonTemplateJR.setConnectionFactory(jredisConnFactory);
jackson2JsonPersonTemplateJR.afterPropertiesSet();
RedisTemplate<byte[], byte[]> rawTemplateJR = new RedisTemplate<byte[], byte[]>();
rawTemplateJR.setConnectionFactory(jredisConnFactory);
rawTemplateJR.setEnableDefaultSerializer(false);
rawTemplateJR.setKeySerializer(stringSerializer);
rawTemplateJR.afterPropertiesSet();
// SRP
SrpConnectionFactory srConnFactory = new SrpConnectionFactory();
srConnFactory.setPort(SettingsUtils.getPort());
srConnFactory.setHostName(SettingsUtils.getHost());
srConnFactory.afterPropertiesSet();
RedisTemplate<String, String> stringTemplateSRP = new StringRedisTemplate(srConnFactory);
RedisTemplate<String, Person> personTemplateSRP = new RedisTemplate<String, Person>();
personTemplateSRP.setConnectionFactory(srConnFactory);
personTemplateSRP.afterPropertiesSet();
RedisTemplate<String, Person> xstreamStringTemplateSRP = new RedisTemplate<String, Person>();
xstreamStringTemplateSRP.setConnectionFactory(srConnFactory);
xstreamStringTemplateSRP.setDefaultSerializer(serializer);
xstreamStringTemplateSRP.afterPropertiesSet();
RedisTemplate<String, Person> xstreamPersonTemplateSRP = new RedisTemplate<String, Person>();
xstreamPersonTemplateSRP.setValueSerializer(serializer);
xstreamPersonTemplateSRP.setConnectionFactory(srConnFactory);
xstreamPersonTemplateSRP.afterPropertiesSet();
RedisTemplate<String, Person> jsonPersonTemplateSRP = new RedisTemplate<String, Person>();
jsonPersonTemplateSRP.setValueSerializer(jsonSerializer);
jsonPersonTemplateSRP.setConnectionFactory(srConnFactory);
jsonPersonTemplateSRP.afterPropertiesSet();
RedisTemplate<String, Person> jackson2JsonPersonTemplateSRP = new RedisTemplate<String, Person>();
jackson2JsonPersonTemplateSRP.setValueSerializer(jackson2JsonSerializer);
jackson2JsonPersonTemplateSRP.setConnectionFactory(srConnFactory);
jackson2JsonPersonTemplateSRP.afterPropertiesSet();
RedisTemplate<byte[], byte[]> rawTemplateSRP = new RedisTemplate<byte[], byte[]>();
rawTemplateSRP.setConnectionFactory(srConnFactory);
rawTemplateSRP.setEnableDefaultSerializer(false);
rawTemplateSRP.setKeySerializer(stringSerializer);
rawTemplateSRP.afterPropertiesSet();
// Lettuce
LettuceConnectionFactory lettuceConnFactory = new LettuceConnectionFactory();
lettuceConnFactory.setClientResources(LettuceTestClientResources.getSharedClientResources());
@@ -217,36 +141,17 @@ public abstract class CollectionTestParams {
rawTemplateLtc.setKeySerializer(stringSerializer);
rawTemplateLtc.afterPropertiesSet();
return Arrays.asList(new Object[][] {
{ stringFactory, stringTemplate },
{ doubleAsStringObjectFactory, stringTemplate },
{ personFactory, personTemplate },
{ stringFactory, xstreamStringTemplate },
{ personFactory, xstreamPersonTemplate },
{ personFactory, jsonPersonTemplate },
{ personFactory, jackson2JsonPersonTemplate },
{ rawFactory, rawTemplate },
// Jredis
{ stringFactory, stringTemplateJR },
{ personFactory, personTemplateJR },
{ stringFactory, xstreamStringTemplateJR },
{ personFactory, xstreamPersonTemplateJR },
{ personFactory, jsonPersonTemplateJR },
{ personFactory, jackson2JsonPersonTemplateJR },
{ rawFactory, rawTemplateJR },
// srp
{ stringFactory, stringTemplateSRP },
{ personFactory, personTemplateSRP },
{ stringFactory, xstreamStringTemplateSRP },
{ personFactory, xstreamPersonTemplateSRP },
{ personFactory, jsonPersonTemplateSRP },
{ personFactory, jackson2JsonPersonTemplateSRP },
{ rawFactory, rawTemplateSRP },
// lettuce
{ stringFactory, stringTemplateLtc }, { personFactory, personTemplateLtc },
{ doubleAsStringObjectFactory, stringTemplateLtc }, { personFactory, personTemplateLtc },
{ stringFactory, xstreamStringTemplateLtc }, { personFactory, xstreamPersonTemplateLtc },
{ personFactory, jsonPersonTemplateLtc }, { personFactory, jackson2JsonPersonTemplateLtc },
{ rawFactory, rawTemplateLtc } });
return Arrays
.asList(new Object[][] { { stringFactory, stringTemplate }, { doubleAsStringObjectFactory, stringTemplate },
{ personFactory, personTemplate }, { stringFactory, xstreamStringTemplate },
{ personFactory, xstreamPersonTemplate }, { personFactory, jsonPersonTemplate },
{ personFactory, jackson2JsonPersonTemplate }, { rawFactory, rawTemplate },
// lettuce
{ stringFactory, stringTemplateLtc }, { personFactory, personTemplateLtc },
{ doubleAsStringObjectFactory, stringTemplateLtc }, { personFactory, personTemplateLtc },
{ stringFactory, xstreamStringTemplateLtc }, { personFactory, xstreamPersonTemplateLtc },
{ personFactory, jsonPersonTemplateLtc }, { personFactory, jackson2JsonPersonTemplateLtc },
{ rawFactory, rawTemplateLtc } });
}
}

View File

@@ -29,11 +29,8 @@ import org.springframework.data.redis.SettingsUtils;
import org.springframework.data.redis.StringObjectFactory;
import org.springframework.data.redis.connection.PoolConfig;
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
import org.springframework.data.redis.connection.jredis.JredisConnectionFactory;
import org.springframework.data.redis.connection.jredis.JredisPool;
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
import org.springframework.data.redis.connection.lettuce.LettuceTestClientResources;
import org.springframework.data.redis.connection.srp.SrpConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
@@ -131,40 +128,6 @@ public class RedisMapTests extends AbstractRedisMapTests<Object, Object> {
rawTemplate.setKeySerializer(stringSerializer);
rawTemplate.afterPropertiesSet();
// JRedis
JredisConnectionFactory jredisConnFactory = new JredisConnectionFactory(new JredisPool(SettingsUtils.getHost(),
SettingsUtils.getPort(), defaultPoolConfig));
jredisConnFactory.afterPropertiesSet();
RedisTemplate genericTemplateJR = new RedisTemplate();
genericTemplateJR.setConnectionFactory(jredisConnFactory);
genericTemplateJR.afterPropertiesSet();
RedisTemplate<String, Person> xGenericTemplateJR = new RedisTemplate<String, Person>();
xGenericTemplateJR.setConnectionFactory(jredisConnFactory);
xGenericTemplateJR.setDefaultSerializer(serializer);
xGenericTemplateJR.afterPropertiesSet();
RedisTemplate<String, Person> jsonPersonTemplateJR = new RedisTemplate<String, Person>();
jsonPersonTemplateJR.setConnectionFactory(jredisConnFactory);
jsonPersonTemplateJR.setDefaultSerializer(jsonSerializer);
jsonPersonTemplateJR.setHashKeySerializer(jsonSerializer);
jsonPersonTemplateJR.setHashValueSerializer(jsonStringSerializer);
jsonPersonTemplateJR.afterPropertiesSet();
RedisTemplate<String, Person> jackson2JsonPersonTemplateJR = new RedisTemplate<String, Person>();
jackson2JsonPersonTemplateJR.setConnectionFactory(jredisConnFactory);
jackson2JsonPersonTemplateJR.setDefaultSerializer(jackson2JsonSerializer);
jackson2JsonPersonTemplateJR.setHashKeySerializer(jackson2JsonSerializer);
jackson2JsonPersonTemplateJR.setHashValueSerializer(jackson2JsonStringSerializer);
jackson2JsonPersonTemplateJR.afterPropertiesSet();
RedisTemplate<String, byte[]> rawTemplateJR = new RedisTemplate<String, byte[]>();
rawTemplateJR.setEnableDefaultSerializer(false);
rawTemplateJR.setConnectionFactory(jredisConnFactory);
rawTemplateJR.setKeySerializer(stringSerializer);
rawTemplateJR.afterPropertiesSet();
// Lettuce
LettuceConnectionFactory lettuceConnFactory = new LettuceConnectionFactory();
lettuceConnFactory.setClientResources(LettuceTestClientResources.getSharedClientResources());
@@ -205,54 +168,11 @@ public class RedisMapTests extends AbstractRedisMapTests<Object, Object> {
rawTemplateLtc.setKeySerializer(stringSerializer);
rawTemplateLtc.afterPropertiesSet();
// SRP
SrpConnectionFactory srpConnFactory = new SrpConnectionFactory();
srpConnFactory.setPort(SettingsUtils.getPort());
srpConnFactory.setHostName(SettingsUtils.getHost());
srpConnFactory.afterPropertiesSet();
RedisTemplate genericTemplateSrp = new RedisTemplate();
genericTemplateSrp.setConnectionFactory(srpConnFactory);
genericTemplateSrp.afterPropertiesSet();
RedisTemplate<String, Person> xGenericTemplateSrp = new RedisTemplate<String, Person>();
xGenericTemplateSrp.setConnectionFactory(srpConnFactory);
xGenericTemplateSrp.setDefaultSerializer(serializer);
xGenericTemplateSrp.afterPropertiesSet();
RedisTemplate<String, Person> jsonPersonTemplateSrp = new RedisTemplate<String, Person>();
jsonPersonTemplateSrp.setConnectionFactory(srpConnFactory);
jsonPersonTemplateSrp.setDefaultSerializer(jsonSerializer);
jsonPersonTemplateSrp.setHashKeySerializer(jsonSerializer);
jsonPersonTemplateSrp.setHashValueSerializer(jsonStringSerializer);
jsonPersonTemplateSrp.afterPropertiesSet();
RedisTemplate<String, Person> jackson2JsonPersonTemplateSrp = new RedisTemplate<String, Person>();
jackson2JsonPersonTemplateSrp.setConnectionFactory(srpConnFactory);
jackson2JsonPersonTemplateSrp.setDefaultSerializer(jackson2JsonSerializer);
jackson2JsonPersonTemplateSrp.setHashKeySerializer(jackson2JsonSerializer);
jackson2JsonPersonTemplateSrp.setHashValueSerializer(jackson2JsonStringSerializer);
jackson2JsonPersonTemplateSrp.afterPropertiesSet();
RedisTemplate<String, String> stringTemplateSrp = new StringRedisTemplate();
stringTemplateSrp.setConnectionFactory(srpConnFactory);
stringTemplateSrp.afterPropertiesSet();
RedisTemplate<String, byte[]> rawTemplateSrp = new RedisTemplate<String, byte[]>();
rawTemplateSrp.setEnableDefaultSerializer(false);
rawTemplateSrp.setConnectionFactory(srpConnFactory);
rawTemplateSrp.setKeySerializer(stringSerializer);
rawTemplateSrp.afterPropertiesSet();
return Arrays.asList(new Object[][] { { stringFactory, stringFactory, genericTemplate },
{ personFactory, personFactory, genericTemplate }, { stringFactory, personFactory, genericTemplate },
{ personFactory, stringFactory, genericTemplate }, { personFactory, stringFactory, xstreamGenericTemplate },
{ personFactory, stringFactory, jsonPersonTemplate },
{ personFactory, stringFactory, jackson2JsonPersonTemplate }, { rawFactory, rawFactory, rawTemplate },
{ stringFactory, stringFactory, genericTemplateJR }, { personFactory, personFactory, genericTemplateJR },
{ stringFactory, personFactory, genericTemplateJR }, { personFactory, stringFactory, genericTemplateJR },
{ personFactory, stringFactory, xGenericTemplateJR }, { personFactory, stringFactory, jsonPersonTemplateJR },
{ personFactory, stringFactory, jackson2JsonPersonTemplateJR }, { rawFactory, rawFactory, rawTemplateJR },
{ stringFactory, stringFactory, genericTemplateLettuce },
{ personFactory, personFactory, genericTemplateLettuce },
{ stringFactory, personFactory, genericTemplateLettuce },
@@ -261,11 +181,6 @@ public class RedisMapTests extends AbstractRedisMapTests<Object, Object> {
{ personFactory, stringFactory, jsonPersonTemplateLettuce },
{ personFactory, stringFactory, jackson2JsonPersonTemplateLettuce },
{ stringFactory, doubleFactory, stringTemplateLtc }, { stringFactory, longFactory, stringTemplateLtc },
{ rawFactory, rawFactory, rawTemplateLtc }, { stringFactory, stringFactory, genericTemplateSrp },
{ personFactory, personFactory, genericTemplateSrp }, { stringFactory, personFactory, genericTemplateSrp },
{ personFactory, stringFactory, genericTemplateSrp }, { personFactory, stringFactory, xGenericTemplateSrp },
{ stringFactory, doubleFactory, stringTemplateSrp }, { stringFactory, longFactory, stringTemplateSrp },
{ personFactory, stringFactory, jsonPersonTemplateSrp },
{ personFactory, stringFactory, jackson2JsonPersonTemplateSrp }, { rawFactory, rawFactory, rawTemplateSrp } });
{ rawFactory, rawFactory, rawTemplateLtc } });
}
}

View File

@@ -39,11 +39,8 @@ import org.springframework.data.redis.Person;
import org.springframework.data.redis.SettingsUtils;
import org.springframework.data.redis.StringObjectFactory;
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
import org.springframework.data.redis.connection.jredis.JredisConnectionFactory;
import org.springframework.data.redis.connection.jredis.JredisPool;
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
import org.springframework.data.redis.connection.lettuce.LettuceTestClientResources;
import org.springframework.data.redis.connection.srp.SrpConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
@@ -91,8 +88,8 @@ public class RedisPropertiesTests extends RedisMapTests {
@Test
public void testPropertiesLoad() throws Exception {
InputStream stream = getClass().getResourceAsStream(
"/org/springframework/data/redis/support/collections/props.properties");
InputStream stream = getClass()
.getResourceAsStream("/org/springframework/data/redis/support/collections/props.properties");
assertNotNull(stream);
@@ -113,8 +110,8 @@ public class RedisPropertiesTests extends RedisMapTests {
@Test
@Ignore
public void testPropertiesLoadXml() throws Exception {
InputStream stream = getClass().getResourceAsStream(
"/org/springframework/data/keyvalue/redis/support/collections/props.properties");
InputStream stream = getClass()
.getResourceAsStream("/org/springframework/data/keyvalue/redis/support/collections/props.properties");
assertNotNull(stream);
@@ -284,31 +281,6 @@ public class RedisPropertiesTests extends RedisMapTests {
jackson2JsonPersonTemplate.setHashValueSerializer(jackson2JsonStringSerializer);
jackson2JsonPersonTemplate.afterPropertiesSet();
// JRedis
JredisConnectionFactory jredisConnFactory = new JredisConnectionFactory(new JredisPool(SettingsUtils.getHost(),
SettingsUtils.getPort()));
jredisConnFactory.afterPropertiesSet();
RedisTemplate<String, String> genericTemplateJR = new StringRedisTemplate(jredisConnFactory);
RedisTemplate<String, Person> xGenericTemplateJR = new RedisTemplate<String, Person>();
xGenericTemplateJR.setConnectionFactory(jredisConnFactory);
xGenericTemplateJR.setDefaultSerializer(serializer);
xGenericTemplateJR.afterPropertiesSet();
RedisTemplate<String, Person> jsonPersonTemplateJR = new RedisTemplate<String, Person>();
jsonPersonTemplateJR.setConnectionFactory(jredisConnFactory);
jsonPersonTemplateJR.setDefaultSerializer(jsonSerializer);
jsonPersonTemplateJR.setHashKeySerializer(jsonSerializer);
jsonPersonTemplateJR.setHashValueSerializer(jsonStringSerializer);
jsonPersonTemplateJR.afterPropertiesSet();
RedisTemplate<String, Person> jackson2JsonPersonTemplateJR = new RedisTemplate<String, Person>();
jackson2JsonPersonTemplateJR.setConnectionFactory(jredisConnFactory);
jackson2JsonPersonTemplateJR.setDefaultSerializer(jackson2JsonSerializer);
jackson2JsonPersonTemplateJR.setHashKeySerializer(jackson2JsonSerializer);
jackson2JsonPersonTemplateJR.setHashValueSerializer(jackson2JsonStringSerializer);
jackson2JsonPersonTemplateJR.afterPropertiesSet();
// Lettuce
LettuceConnectionFactory lettuceConnFactory = new LettuceConnectionFactory();
lettuceConnFactory.setClientResources(LettuceTestClientResources.getSharedClientResources());
@@ -336,51 +308,17 @@ public class RedisPropertiesTests extends RedisMapTests {
jackson2JsonPersonTemplateLtc.setHashValueSerializer(jackson2JsonStringSerializer);
jackson2JsonPersonTemplateLtc.afterPropertiesSet();
// SRP
SrpConnectionFactory srpConnFactory = new SrpConnectionFactory();
srpConnFactory.setPort(SettingsUtils.getPort());
srpConnFactory.setHostName(SettingsUtils.getHost());
srpConnFactory.afterPropertiesSet();
RedisTemplate<String, String> genericTemplateSrp = new StringRedisTemplate(srpConnFactory);
RedisTemplate<String, Person> xGenericTemplateSrp = new RedisTemplate<String, Person>();
xGenericTemplateSrp.setConnectionFactory(srpConnFactory);
xGenericTemplateSrp.setDefaultSerializer(serializer);
xGenericTemplateSrp.afterPropertiesSet();
RedisTemplate<String, Person> jsonPersonTemplateSrp = new RedisTemplate<String, Person>();
jsonPersonTemplateSrp.setConnectionFactory(srpConnFactory);
jsonPersonTemplateSrp.setDefaultSerializer(jsonSerializer);
jsonPersonTemplateSrp.setHashKeySerializer(jsonSerializer);
jsonPersonTemplateSrp.setHashValueSerializer(jsonStringSerializer);
jsonPersonTemplateSrp.afterPropertiesSet();
RedisTemplate<String, Person> jackson2JsonPersonTemplateSrp = new RedisTemplate<String, Person>();
jackson2JsonPersonTemplateSrp.setConnectionFactory(srpConnFactory);
jackson2JsonPersonTemplateSrp.setDefaultSerializer(jackson2JsonSerializer);
jackson2JsonPersonTemplateSrp.setHashKeySerializer(jackson2JsonSerializer);
jackson2JsonPersonTemplateSrp.setHashValueSerializer(jackson2JsonStringSerializer);
jackson2JsonPersonTemplateSrp.afterPropertiesSet();
return Arrays.asList(new Object[][] { { stringFactory, stringFactory, genericTemplate },
{ stringFactory, stringFactory, genericTemplate }, { stringFactory, stringFactory, genericTemplate },
{ stringFactory, stringFactory, genericTemplate }, { stringFactory, stringFactory, xstreamGenericTemplate },
{ stringFactory, stringFactory, genericTemplateJR }, { stringFactory, stringFactory, genericTemplateJR },
{ stringFactory, stringFactory, genericTemplateJR }, { stringFactory, stringFactory, genericTemplateJR },
{ stringFactory, stringFactory, xGenericTemplateJR }, { stringFactory, stringFactory, jsonPersonTemplate },
{ stringFactory, stringFactory, jsonPersonTemplate },
{ stringFactory, stringFactory, jackson2JsonPersonTemplate },
{ stringFactory, stringFactory, jsonPersonTemplateJR },
{ stringFactory, stringFactory, jackson2JsonPersonTemplateJR },
{ stringFactory, stringFactory, genericTemplateLtc }, { stringFactory, stringFactory, genericTemplateLtc },
{ stringFactory, stringFactory, genericTemplateLtc }, { stringFactory, stringFactory, genericTemplateLtc },
{ stringFactory, doubleFactory, genericTemplateLtc }, { stringFactory, longFactory, genericTemplateLtc },
{ stringFactory, stringFactory, xGenericTemplateLtc }, { stringFactory, stringFactory, jsonPersonTemplateLtc },
{ stringFactory, stringFactory, jackson2JsonPersonTemplateLtc },
{ stringFactory, stringFactory, genericTemplateSrp }, { stringFactory, stringFactory, genericTemplateSrp },
{ stringFactory, stringFactory, genericTemplateSrp }, { stringFactory, stringFactory, genericTemplateSrp },
{ stringFactory, doubleFactory, genericTemplateSrp }, { stringFactory, longFactory, genericTemplateSrp },
{ stringFactory, stringFactory, xGenericTemplateSrp }, { stringFactory, stringFactory, jsonPersonTemplateSrp },
{ stringFactory, stringFactory, jackson2JsonPersonTemplateSrp } });
{ stringFactory, stringFactory, jackson2JsonPersonTemplateLtc } });
}
}

View File

@@ -37,20 +37,7 @@ public enum RedisDriver {
public boolean matches(RedisConnectionFactory connectionFactory) {
return ConnectionUtils.isLettuce(connectionFactory);
}
},
SRP {
@Override
public boolean matches(RedisConnectionFactory connectionFactory) {
return ConnectionUtils.isSrp(connectionFactory);
}
},
JREDIS {
@Override
public boolean matches(RedisConnectionFactory connectionFactory) {
return ConnectionUtils.isJredis(connectionFactory);
}
};
/**