DATAREDIS-254 - Clean up codebase to match spring-data conventions

format code with spring data formatter
This commit is contained in:
Christoph Strobl
2014-01-27 13:04:40 +01:00
committed by Thomas Darimont
parent b99992a8f5
commit e0524379d6
249 changed files with 3302 additions and 5087 deletions

View File

@@ -30,12 +30,11 @@ public class Address implements Serializable {
private Integer number;
public Address() {
}
public Address() {}
/**
* Constructs a new <code>Address</code> instance.
*
*
* @param street
* @param number
*/
@@ -45,10 +44,9 @@ public class Address implements Serializable {
this.number = number;
}
/**
* Returns the street.
*
*
* @return Returns the street
*/
public String getStreet() {
@@ -64,7 +62,7 @@ public class Address implements Serializable {
/**
* Returns the number.
*
*
* @return Returns the number
*/
public Integer getNumber() {
@@ -78,7 +76,6 @@ public class Address implements Serializable {
this.number = number;
}
public int hashCode() {
final int prime = 31;
int result = 1;
@@ -87,7 +84,6 @@ public class Address implements Serializable {
return result;
}
public boolean equals(Object obj) {
if (this == obj)
return true;
@@ -99,15 +95,13 @@ public class Address implements Serializable {
if (number == null) {
if (other.number != null)
return false;
}
else if (!number.equals(other.number))
} else if (!number.equals(other.number))
return false;
if (street == null) {
if (other.street != null)
return false;
}
else if (!street.equals(other.street))
} else if (!street.equals(other.street))
return false;
return true;
}
}
}

View File

@@ -22,8 +22,8 @@ import org.springframework.beans.factory.DisposableBean;
import org.springframework.data.redis.connection.RedisConnectionFactory;
/**
* Basic utility to help with the destruction of {@link RedisConnectionFactory} inside JUnit 4 tests.
* Simply add the factory during setup and then call {@link #cleanUp()} through the <tt>@AfterClass</tt> method.
* Basic utility to help with the destruction of {@link RedisConnectionFactory} inside JUnit 4 tests. Simply add the
* factory during setup and then call {@link #cleanUp()} through the <tt>@AfterClass</tt> method.
*
* @author Costin Leau
*/
@@ -40,7 +40,7 @@ public abstract class ConnectionFactoryTracker {
for (RedisConnectionFactory connectionFactory : connFactories) {
try {
((DisposableBean) connectionFactory).destroy();
//System.out.println("Succesfully cleaned up factory " + connectionFactory);
// System.out.println("Succesfully cleaned up factory " + connectionFactory);
} catch (Exception ex) {
System.err.println("Cannot clean factory " + connectionFactory + ex);
}

View File

@@ -18,11 +18,9 @@ package org.springframework.data.redis;
import java.util.concurrent.atomic.AtomicLong;
/**
*
* Implementation of {@link ObjectFactory} that returns unique Doubles as Strings,
* incrementing by 1 each time
* Implementation of {@link ObjectFactory} that returns unique Doubles as Strings, incrementing by 1 each time
*
* @author Jennifer Hickey
*
*/
public class DoubleAsStringObjectFactory implements ObjectFactory<String> {

View File

@@ -19,9 +19,8 @@ import java.util.concurrent.atomic.AtomicLong;
/**
* Returns unique Doubles, incrementing by 1 each time
*
*
* @author Jennifer Hickey
*
*/
public class DoubleObjectFactory implements ObjectFactory<Double> {

View File

@@ -18,11 +18,10 @@ package org.springframework.data.redis;
import java.util.concurrent.atomic.AtomicLong;
/**
*
* Implementation of {@link ObjectFactory} that returns unique incremented Longs as Strings
* @author Jennifer Hickey
*
*/
* Implementation of {@link ObjectFactory} that returns unique incremented Longs as Strings
*
* @author Jennifer Hickey
*/
public class LongAsStringObjectFactory implements ObjectFactory<String> {
private AtomicLong counter = new AtomicLong();

View File

@@ -19,9 +19,8 @@ import java.util.concurrent.atomic.AtomicLong;
/**
* Returns unique Longs by incrementing a counter each time
*
*
* @author Jennifer Hickey
*
*/
public class LongObjectFactory implements ObjectFactory<Long> {

View File

@@ -16,7 +16,7 @@
package org.springframework.data.redis;
/**
* Simple object factory.
* Simple object factory.
*
* @author Costin Leau
*/

View File

@@ -33,8 +33,7 @@ public class Person implements Serializable {
private Integer age;
private Address address;
public Person() {
}
public Person() {}
public Person(String firstName, String lastName, int age) {
this(firstName, lastName, age, null);
@@ -80,7 +79,6 @@ public class Person implements Serializable {
this.address = address;
}
public int hashCode() {
final int prime = 31;
int result = 1;
@@ -91,7 +89,6 @@ public class Person implements Serializable {
return result;
}
public boolean equals(Object obj) {
if (this == obj)
return true;
@@ -103,27 +100,23 @@ public class Person implements Serializable {
if (address == null) {
if (other.address != null)
return false;
}
else if (!address.equals(other.address))
} else if (!address.equals(other.address))
return false;
if (age == null) {
if (other.age != null)
return false;
}
else if (!age.equals(other.age))
} else if (!age.equals(other.age))
return false;
if (firstName == null) {
if (other.firstName != null)
return false;
}
else if (!firstName.equals(other.firstName))
} else if (!firstName.equals(other.firstName))
return false;
if (lastName == null) {
if (other.lastName != null)
return false;
}
else if (!lastName.equals(other.lastName))
} else if (!lastName.equals(other.lastName))
return false;
return true;
}
}
}

View File

@@ -17,7 +17,6 @@ package org.springframework.data.redis;
import java.util.UUID;
/**
* @author Costin Leau
*/

View File

@@ -19,9 +19,8 @@ import java.util.UUID;
/**
* Implementation of {@link ObjectFactory} that returns random byte[]s
*
*
* @author Jennifer Hickey
*
*/
public class RawObjectFactory implements ObjectFactory<byte[]> {

View File

@@ -20,15 +20,12 @@ import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactor
import org.springframework.test.annotation.ProfileValueSource;
/**
* Implementation of {@link ProfileValueSource} that handles profile value name
* "redisVersion" by checking the current version of Redis. 2.4.x will be
* returned as "2.4" and 2.6.x will be returned as "2.6". Any other version
* found will cause an {@link UnsupportedOperationException}
*
* System property values will be returned for any key other than "redisVersion"
* Implementation of {@link ProfileValueSource} that handles profile value name "redisVersion" by checking the current
* version of Redis. 2.4.x will be returned as "2.4" and 2.6.x will be returned as "2.6". Any other version found will
* cause an {@link UnsupportedOperationException} System property values will be returned for any key other than
* "redisVersion"
*
* @author Jennifer Hickey
*
*/
public class RedisTestProfileValueSource implements ProfileValueSource {
@@ -40,8 +37,8 @@ public class RedisTestProfileValueSource implements ProfileValueSource {
public RedisTestProfileValueSource() {
if (redisVersion == null) {
LettuceConnectionFactory connectionFactory = new LettuceConnectionFactory(
SettingsUtils.getHost(), SettingsUtils.getPort());
LettuceConnectionFactory connectionFactory = new LettuceConnectionFactory(SettingsUtils.getHost(),
SettingsUtils.getPort());
connectionFactory.afterPropertiesSet();
RedisConnection connection = connectionFactory.getConnection();
redisVersion = RedisVersionUtils.getRedisVersion(connection);

View File

@@ -22,14 +22,12 @@ import org.springframework.data.redis.connection.RedisConnection;
/**
* Utilities for examining the Redis version
*
*
* @author Jennifer Hickey
*
*/
public abstract class RedisVersionUtils {
private static final Pattern VERSION_MATCHER = Pattern
.compile("([0-9]+)\\.([0-9]+)(\\.([0-9]+))?");
private static final Pattern VERSION_MATCHER = Pattern.compile("([0-9]+)\\.([0-9]+)(\\.([0-9]+))?");
public static Version getRedisVersion(RedisConnection connection) {
return parseVersion((String) connection.info().get("redis_version"));

View File

@@ -71,4 +71,4 @@ public class RedisViewPE {
public void setHashOps(HashOperations<Object, String, Object> hashOps) {
this.hashOps = hashOps;
}
}
}

View File

@@ -16,21 +16,16 @@
package org.springframework.data.redis;
/**
*
* @author Jennifer Hickey
*
*/
abstract public class SpinBarrier {
/**
* Periodically tests for a condition until it is met or a timeout occurs
*
* @param condition
* The condition to periodically test
* @param timeout
* The timeout
* @return true if condition passes, false if condition does not pass within
* timeout
* @param condition The condition to periodically test
* @param timeout The timeout
* @return true if condition passes, false if condition does not pass within timeout
*/
public static boolean waitFor(TestCondition condition, long timeout) {
boolean passes = false;
@@ -41,8 +36,7 @@ abstract public class SpinBarrier {
}
try {
Thread.sleep(100);
} catch (InterruptedException e) {
}
} catch (InterruptedException e) {}
}
return passes;
}

View File

@@ -17,10 +17,9 @@ package org.springframework.data.redis;
import java.util.UUID;
/**
* String object factory based on UUID.
*
*
* @author Costin Leau
*/
public class StringObjectFactory implements ObjectFactory<String> {

View File

@@ -16,17 +16,13 @@
package org.springframework.data.redis;
/**
* A condition to test periodically, used in conjunction with {@link SpinBarrier}
*
* A condition to test periodically, used in conjunction with
* {@link SpinBarrier}
*
* @author Jennifer Hickey
*
*/
public interface TestCondition {
/**
*
* @return true if condition passes
*/
boolean passes();

View File

@@ -17,9 +17,8 @@ package org.springframework.data.redis;
/**
* A {@link Comparable} software version
*
*
* @author Jennifer Hickey
*
*/
public class Version implements Comparable<Version> {
Integer major;

View File

@@ -46,7 +46,6 @@ public abstract class AbstractNativeCacheTest<T> {
cache.clear();
}
protected abstract T createNativeCache() throws Exception;
protected abstract Cache createCache(T nativeCache);
@@ -77,10 +76,10 @@ public abstract class AbstractNativeCacheTest<T> {
if (valueWrapper != null) {
assertThat(valueWrapper.get(), isEqual(value));
}
// keeps failing on the CI server so do
// keeps failing on the CI server so do
else {
// Thread.sleep(200);
// assertNotNull(cache.get(key));
// Thread.sleep(200);
// assertNotNull(cache.get(key));
// ignore for now
}
}
@@ -90,7 +89,6 @@ public abstract class AbstractNativeCacheTest<T> {
Object key1 = getKey();
Object value1 = getValue();
Object key2 = getKey();
Object value2 = getValue();
@@ -102,4 +100,4 @@ public abstract class AbstractNativeCacheTest<T> {
assertNull(cache.get(key2));
assertNull(cache.get(key1));
}
}
}

View File

@@ -58,7 +58,6 @@ public class RedisCacheTest extends AbstractNativeCacheTest<RedisTemplate> {
private ObjectFactory<Object> valueFactory;
private RedisTemplate template;
public RedisCacheTest(RedisTemplate template, ObjectFactory<Object> keyFactory, ObjectFactory<Object> valueFactory) {
this.keyFactory = keyFactory;
this.valueFactory = valueFactory;
@@ -71,14 +70,11 @@ public class RedisCacheTest extends AbstractNativeCacheTest<RedisTemplate> {
return AbstractOperationsTestParams.testParams();
}
@SuppressWarnings("unchecked")
protected Cache createCache(RedisTemplate nativeCache) {
return new RedisCache(CACHE_NAME, CACHE_NAME.concat(":").getBytes(), nativeCache,
TimeUnit.MINUTES.toSeconds(10));
return new RedisCache(CACHE_NAME, CACHE_NAME.concat(":").getBytes(), nativeCache, TimeUnit.MINUTES.toSeconds(10));
}
protected RedisTemplate createNativeCache() throws Exception {
return template;
}
@@ -174,7 +170,7 @@ public class RedisCacheTest extends AbstractNativeCacheTest<RedisTemplate> {
public void run() {
try {
cache.put(key1, value1);
}catch(IllegalMonitorStateException e) {
} catch (IllegalMonitorStateException e) {
monitorStateException.set(true);
} finally {
latch.countDown();
@@ -188,33 +184,33 @@ public class RedisCacheTest extends AbstractNativeCacheTest<RedisTemplate> {
latch.await();
assertFalse(monitorStateException.get());
}
/**
* @see DATAREDIS-243
*/
@Test
public void testCacheGetShouldReturnCachedInstance() {
assumeThat(cache, instanceOf(RedisCache.class));
Object key = getKey();
Object value = getValue();
cache.put(key, value);
assertThat(value, isEqual(((RedisCache)cache).get(key, Object.class)));
assertThat(value, isEqual(((RedisCache) cache).get(key, Object.class)));
}
/**
* @see DATAREDIS-243
*/
@Test
public void testCacheGetShouldRetunInstanceOfCorrectType() {
assumeThat(cache, instanceOf(RedisCache.class));
Object key = getKey();
Object value = getValue();
cache.put(key, value);
RedisCache redisCache = (RedisCache)cache;
RedisCache redisCache = (RedisCache) cache;
assertThat(redisCache.get(key, value.getClass()), instanceOf(value.getClass()));
}
@@ -224,29 +220,29 @@ public class RedisCacheTest extends AbstractNativeCacheTest<RedisTemplate> {
@Test(expected = ClassCastException.class)
public void testCacheGetShouldThrowExceptionOnInvalidType() {
assumeThat(cache, instanceOf(RedisCache.class));
Object key = getKey();
Object value = getValue();
cache.put(key, value);
RedisCache redisCache = (RedisCache)cache;
RedisCache redisCache = (RedisCache) cache;
@SuppressWarnings("unused")
Cache retrievedObject = redisCache.get(key, Cache.class);
}
/**
* @see DATAREDIS-243
*/
@Test
public void testCacheGetShouldReturnNullIfNoCachedValueFound() {
assumeThat(cache, instanceOf(RedisCache.class));
Object key = getKey();
Object value = getValue();
cache.put(key, value);
RedisCache redisCache = (RedisCache)cache;
RedisCache redisCache = (RedisCache) cache;
Object invalidKey = template.getKeySerializer() == null ? "spring-data-redis".getBytes() : "spring-data-redis";
assertThat(redisCache.get(invalidKey, value.getClass()), nullValue());
}

View File

@@ -38,14 +38,11 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@ProfileValueSourceConfiguration
public class NamespaceTest {
@Autowired
private RedisMessageListenerContainer container;
@Autowired private RedisMessageListenerContainer container;
@Autowired
private StringRedisTemplate template;
@Autowired private StringRedisTemplate template;
@Autowired
private StubErrorHandler handler;
@Autowired private StubErrorHandler handler;
@Test
@IfProfileValue(name = "runLongTests", value = "true")

View File

@@ -27,7 +27,6 @@ public class StubErrorHandler implements ErrorHandler {
public BlockingDeque<Throwable> throwables = new LinkedBlockingDeque<Throwable>();
public void handleError(Throwable t) {
throwables.add(t);
}

View File

@@ -65,10 +65,9 @@ import org.springframework.test.annotation.ProfileValueSourceConfiguration;
/**
* Base test class for AbstractConnection integration tests
*
*
* @author Costin Leau
* @author Jennifer Hickey
*
*/
@ProfileValueSourceConfiguration(RedisTestProfileValueSource.class)
public abstract class AbstractConnectionIntegrationTests {
@@ -81,8 +80,7 @@ public abstract class AbstractConnectionIntegrationTests {
protected List<Object> actual = new ArrayList<Object>();
@Autowired
protected RedisConnectionFactory connectionFactory;
@Autowired protected RedisConnectionFactory connectionFactory;
protected RedisConnection byteConnection;
@@ -90,7 +88,7 @@ public abstract class AbstractConnectionIntegrationTests {
public void setUp() {
byteConnection = connectionFactory.getConnection();
connection = new DefaultStringRedisConnection(byteConnection);
((DefaultStringRedisConnection)connection).setDeserializePipelineAndTxResults(true);
((DefaultStringRedisConnection) connection).setDeserializePipelineAndTxResults(true);
initConnection();
}
@@ -105,7 +103,7 @@ public abstract class AbstractConnectionIntegrationTests {
connection.close();
connection = null;
}
@Test
public void testSelect() {
// Make sure this doesn't throw Exception
@@ -182,13 +180,11 @@ public abstract class AbstractConnectionIntegrationTests {
actual.add(connection.evalSha(sha1, ReturnType.MULTI, 1, "key1", "arg1"));
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)) }));
assertEquals(Arrays.asList(new Object[] { "key1", "arg1" }),
Arrays.asList(new Object[] { new String(scriptResults.get(0)), new String(scriptResults.get(1)) }));
}
@Test(expected=RedisSystemException.class)
@Test(expected = RedisSystemException.class)
@IfProfileValue(name = "redisVersion", value = "2.6")
public void testEvalShaArrayError() {
connection.evalSha("notasha", ReturnType.MULTI, 1, "key1", "arg1");
@@ -251,8 +247,8 @@ public abstract class AbstractConnectionIntegrationTests {
public void testEvalReturnArrayStrings() {
actual.add(connection.eval("return {KEYS[1],ARGV[1]}", ReturnType.MULTI, 1, "foo", "bar"));
List<byte[]> result = (List<byte[]>) getResults().get(0);
assertEquals(Arrays.asList(new Object[] { "foo", "bar" }), Arrays.asList(new Object[] {
new String(result.get(0)), new String(result.get(1)) }));
assertEquals(Arrays.asList(new Object[] { "foo", "bar" }),
Arrays.asList(new Object[] { new String(result.get(0)), new String(result.get(1)) }));
}
@Test
@@ -262,7 +258,7 @@ public abstract class AbstractConnectionIntegrationTests {
verifyResults(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 1l, 2l }) }));
}
@Test(expected=RedisSystemException.class)
@Test(expected = RedisSystemException.class)
@IfProfileValue(name = "redisVersion", value = "2.6")
public void testEvalArrayScriptError() {
// Syntax error
@@ -274,12 +270,11 @@ public abstract class AbstractConnectionIntegrationTests {
@Test
@IfProfileValue(name = "redisVersion", value = "2.6")
public void testEvalReturnArrayOKs() {
actual.add(connection.eval(
"return { redis.call('set','abc','ghk'), redis.call('set','abc','lfdf')}",
actual.add(connection.eval("return { redis.call('set','abc','ghk'), redis.call('set','abc','lfdf')}",
ReturnType.MULTI, 0));
List<byte[]> result = (List<byte[]>) getResults().get(0);
assertEquals(Arrays.asList(new Object[] { "OK", "OK" }), Arrays.asList(new Object[] {
new String(result.get(0)), new String(result.get(1)) }));
assertEquals(Arrays.asList(new Object[] { "OK", "OK" }),
Arrays.asList(new Object[] { new String(result.get(0)), new String(result.get(1)) }));
}
@Test
@@ -315,11 +310,9 @@ public abstract class AbstractConnectionIntegrationTests {
final AtomicBoolean scriptDead = new AtomicBoolean(false);
Thread th = new Thread(new Runnable() {
public void run() {
DefaultStringRedisConnection conn2 = new DefaultStringRedisConnection(
connectionFactory.getConnection());
DefaultStringRedisConnection conn2 = new DefaultStringRedisConnection(connectionFactory.getConnection());
try {
conn2.eval("local time=1 while time < 10000000000 do time=time+1 end",
ReturnType.BOOLEAN, 0);
conn2.eval("local time=1 while time < 10000000000 do time=time+1 end", ReturnType.BOOLEAN, 0);
} catch (DataAccessException e) {
scriptDead.set(true);
}
@@ -480,7 +473,7 @@ public abstract class AbstractConnectionIntegrationTests {
verifyResults(Arrays.asList(new Object[] { 4l }));
}
@Test(expected =UnsupportedOperationException.class)
@Test(expected = UnsupportedOperationException.class)
@IfProfileValue(name = "redisVersion", value = "2.6")
public void testBitOpNotMultipleSources() {
connection.set("key1", "abcd");
@@ -691,7 +684,7 @@ public abstract class AbstractConnectionIntegrationTests {
public void testExecuteNoArgs() {
actual.add(connection.execute("PING"));
List<Object> results = getResults();
assertEquals("PONG", stringSerializer.deserialize((byte[])results.get(0)));
assertEquals("PONG", stringSerializer.deserialize((byte[]) results.get(0)));
}
@SuppressWarnings("unchecked")
@@ -703,7 +696,7 @@ public abstract class AbstractConnectionIntegrationTests {
actual.add(connection.exec());
List<Object> results = getResults();
List<Object> execResults = (List<Object>) results.get(0);
assertEquals(Arrays.asList(new Object[] {"value"}), execResults);
assertEquals(Arrays.asList(new Object[] { "value" }), execResults);
assertEquals("value", connection.get("key"));
}
@@ -714,16 +707,16 @@ public abstract class AbstractConnectionIntegrationTests {
testMultiExec();
}
@Test(expected=RedisSystemException.class)
@Test(expected = RedisSystemException.class)
public void testExecWithoutMulti() {
connection.exec();
getResults();
}
@Test(expected=RedisSystemException.class)
@Test(expected = RedisSystemException.class)
public void testErrorInTx() {
connection.multi();
connection.set("foo","bar");
connection.set("foo", "bar");
// Try to do a list op on a value
connection.lPop("foo");
connection.exec();
@@ -732,8 +725,7 @@ public abstract class AbstractConnectionIntegrationTests {
@Test
public void testMultiDiscard() throws Exception {
DefaultStringRedisConnection conn2 = new DefaultStringRedisConnection(
connectionFactory.getConnection());
DefaultStringRedisConnection conn2 = new DefaultStringRedisConnection(connectionFactory.getConnection());
conn2.set("testitnow", "willdo");
connection.multi();
connection.set("testitnow2", "notok");
@@ -750,10 +742,9 @@ public abstract class AbstractConnectionIntegrationTests {
public void testWatch() throws Exception {
connection.set("testitnow", "willdo");
connection.watch("testitnow".getBytes());
//Give some time for watch to be asynch executed in extending tests
// Give some time for watch to be asynch executed in extending tests
Thread.sleep(500);
DefaultStringRedisConnection conn2 = new DefaultStringRedisConnection(
connectionFactory.getConnection());
DefaultStringRedisConnection conn2 = new DefaultStringRedisConnection(connectionFactory.getConnection());
conn2.set("testitnow", "something");
conn2.close();
connection.multi();
@@ -770,17 +761,16 @@ public abstract class AbstractConnectionIntegrationTests {
connection.watch("testitnow".getBytes());
connection.unwatch();
connection.multi();
//Give some time for unwatch to be asynch executed
// Give some time for unwatch to be asynch executed
Thread.sleep(100);
DefaultStringRedisConnection conn2 = new DefaultStringRedisConnection(
connectionFactory.getConnection());
DefaultStringRedisConnection conn2 = new DefaultStringRedisConnection(connectionFactory.getConnection());
conn2.set("testitnow", "something");
connection.set("testitnow", "somethingelse");
connection.get("testitnow");
actual.add(connection.exec());
List<Object> results = getResults();
List<Object> execResults = (List<Object>) results.get(0);
assertEquals(Arrays.asList(new Object[] {"somethingelse"}), execResults);
assertEquals(Arrays.asList(new Object[] { "somethingelse" }), execResults);
}
@Test
@@ -789,9 +779,7 @@ public abstract class AbstractConnectionIntegrationTests {
actual.add(connection.rPush("sortlist", "bar"));
actual.add(connection.rPush("sortlist", "baz"));
actual.add(connection.sort("sortlist", new DefaultSortParameters(null, Order.ASC, true)));
verifyResults(
Arrays.asList(new Object[] { 1l, 2l, 3l,
Arrays.asList(new String[] { "bar", "baz", "foo" }) }));
verifyResults(Arrays.asList(new Object[] { 1l, 2l, 3l, Arrays.asList(new String[] { "bar", "baz", "foo" }) }));
}
@Test
@@ -799,12 +787,9 @@ public abstract class AbstractConnectionIntegrationTests {
actual.add(connection.rPush("sortlist", "foo"));
actual.add(connection.rPush("sortlist", "bar"));
actual.add(connection.rPush("sortlist", "baz"));
actual.add(connection.sort("sortlist", new DefaultSortParameters(null, Order.ASC, true),
"newlist"));
actual.add(connection.sort("sortlist", new DefaultSortParameters(null, Order.ASC, true), "newlist"));
actual.add(connection.lRange("newlist", 0, 9));
verifyResults(
Arrays.asList(new Object[] { 1l, 2l, 3l, 3l,
Arrays.asList(new String[] { "bar", "baz", "foo" }) }));
verifyResults(Arrays.asList(new Object[] { 1l, 2l, 3l, 3l, Arrays.asList(new String[] { "bar", "baz", "foo" }) }));
}
@Test
@@ -813,9 +798,7 @@ public abstract class AbstractConnectionIntegrationTests {
actual.add(connection.rPush("sortlist", "2"));
actual.add(connection.rPush("sortlist", "3"));
actual.add(connection.sort("sortlist", null));
verifyResults(
Arrays.asList(new Object[] { 1l, 2l, 3l,
Arrays.asList(new String[] { "2", "3", "5" }) }));
verifyResults(Arrays.asList(new Object[] { 1l, 2l, 3l, Arrays.asList(new String[] { "2", "3", "5" }) }));
}
@Test
@@ -825,9 +808,7 @@ public abstract class AbstractConnectionIntegrationTests {
actual.add(connection.rPush("sortlist", "5"));
actual.add(connection.sort("sortlist", null, "newlist"));
actual.add(connection.lRange("newlist", 0, 9));
verifyResults(
Arrays.asList(new Object[] { 1l, 2l, 3l, 3l,
Arrays.asList(new String[] { "3", "5", "9" }) }));
verifyResults(Arrays.asList(new Object[] { 1l, 2l, 3l, 3l, Arrays.asList(new String[] { "3", "5", "9" }) }));
}
@Test
@@ -981,7 +962,7 @@ public abstract class AbstractConnectionIntegrationTests {
@Test
public void testDel() {
connection.set("testing","123");
connection.set("testing", "123");
actual.add(connection.del("testing"));
actual.add(connection.exists("testing"));
verifyResults(Arrays.asList(new Object[] { 1l, false }));
@@ -1076,7 +1057,7 @@ public abstract class AbstractConnectionIntegrationTests {
actual.add(connection.incrBy(key, largeNumber));
actual.add(connection.decrBy(key, largeNumber));
actual.add(connection.decrBy(key, 2 * largeNumber));
verifyResults(Arrays.asList(new Object[] {largeNumber, 0l, -2 * largeNumber}));
verifyResults(Arrays.asList(new Object[] { largeNumber, 0l, -2 * largeNumber }));
}
@Test
@@ -1087,10 +1068,10 @@ public abstract class AbstractConnectionIntegrationTests {
long largeNumber = 0x123456789L; // > 32bits
actual.add(connection.hSet(key, hkey, "0"));
actual.add(connection.hIncrBy(key, hkey, largeNumber));
//assertEquals(largeNumber, Long.valueOf(connection.hGet(key, hkey)).longValue());
// assertEquals(largeNumber, Long.valueOf(connection.hGet(key, hkey)).longValue());
actual.add(connection.hIncrBy(key, hkey, -2 * largeNumber));
//assertEquals(-largeNumber, Long.valueOf(connection.hGet(key, hkey)).longValue());
verifyResults(Arrays.asList(new Object[] {true, largeNumber, -largeNumber}));
// assertEquals(-largeNumber, Long.valueOf(connection.hGet(key, hkey)).longValue());
verifyResults(Arrays.asList(new Object[] { true, largeNumber, -largeNumber }));
}
@Test
@@ -1114,26 +1095,20 @@ public abstract class AbstractConnectionIntegrationTests {
@Test
public void testBLPop() {
DefaultStringRedisConnection conn2 = new DefaultStringRedisConnection(
connectionFactory.getConnection());
DefaultStringRedisConnection conn2 = new DefaultStringRedisConnection(connectionFactory.getConnection());
conn2.lPush("poplist", "foo");
conn2.lPush("poplist", "bar");
actual.add(connection.bLPop(100, "poplist", "otherlist"));
verifyResults(
Arrays.asList(new Object[] {
Arrays.asList(new String[] { "poplist", "bar" }) }));
verifyResults(Arrays.asList(new Object[] { Arrays.asList(new String[] { "poplist", "bar" }) }));
}
@Test
public void testBRPop() {
DefaultStringRedisConnection conn2 = new DefaultStringRedisConnection(
connectionFactory.getConnection());
DefaultStringRedisConnection conn2 = new DefaultStringRedisConnection(connectionFactory.getConnection());
conn2.rPush("rpoplist", "bar");
conn2.rPush("rpoplist", "foo");
actual.add(connection.bRPop(1, "rpoplist"));
verifyResults(
Arrays.asList(new Object[] {
Arrays.asList(new String[] { "rpoplist", "foo" }) }));
verifyResults(Arrays.asList(new Object[] { Arrays.asList(new String[] { "rpoplist", "foo" }) }));
}
@Test
@@ -1144,10 +1119,8 @@ public abstract class AbstractConnectionIntegrationTests {
actual.add(connection.lRange("MyList", 0, -1));
actual.add(connection.lInsert("MyList", Position.BEFORE, "big", "very"));
actual.add(connection.lRange("MyList", 0, -1));
verifyResults(
Arrays.asList(new Object[] { 1l, 2l, 3l,
Arrays.asList(new String[] { "hello", "big", "world" }), 4l,
Arrays.asList(new String[] { "hello", "very", "big", "world" }) }));
verifyResults(Arrays.asList(new Object[] { 1l, 2l, 3l, Arrays.asList(new String[] { "hello", "big", "world" }), 4l,
Arrays.asList(new String[] { "hello", "very", "big", "world" }) }));
}
@Test
@@ -1166,9 +1139,7 @@ public abstract class AbstractConnectionIntegrationTests {
actual.add(connection.rPush("PopList", "hello"));
actual.add(connection.lRem("PopList", 2, "hello"));
actual.add(connection.lRange("PopList", 0, -1));
verifyResults(
Arrays.asList(new Object[] { 1l, 2l, 3l, 4l, 2l,
Arrays.asList(new String[] { "big", "world" }) }));
verifyResults(Arrays.asList(new Object[] { 1l, 2l, 3l, 4l, 2l, Arrays.asList(new String[] { "big", "world" }) }));
}
@Test
@@ -1178,8 +1149,7 @@ public abstract class AbstractConnectionIntegrationTests {
actual.add(connection.rPush("PopList", "world"));
actual.add(connection.rPush("PopList", "hello"));
actual.add(connection.lLen("PopList"));
verifyResults(
Arrays.asList(new Object[] { 1l, 2l, 3l, 4l, 4l }));
verifyResults(Arrays.asList(new Object[] { 1l, 2l, 3l, 4l, 4l }));
}
@Test
@@ -1189,9 +1159,7 @@ public abstract class AbstractConnectionIntegrationTests {
actual.add(connection.rPush("PopList", "world"));
connection.lSet("PopList", 1, "cruel");
actual.add(connection.lRange("PopList", 0, -1));
verifyResults(
Arrays.asList(new Object[] { 1l, 2l, 3l,
Arrays.asList(new String[] { "hello", "cruel", "world" }) }));
verifyResults(Arrays.asList(new Object[] { 1l, 2l, 3l, Arrays.asList(new String[] { "hello", "cruel", "world" }) }));
}
@Test
@@ -1201,9 +1169,7 @@ public abstract class AbstractConnectionIntegrationTests {
actual.add(connection.rPush("PopList", "world"));
connection.lTrim("PopList", 1, -1);
actual.add(connection.lRange("PopList", 0, -1));
verifyResults(
Arrays.asList(new Object[] { 1l, 2l, 3l,
Arrays.asList(new String[] { "big", "world" }) }));
verifyResults(Arrays.asList(new Object[] { 1l, 2l, 3l, Arrays.asList(new String[] { "big", "world" }) }));
}
@Test
@@ -1222,17 +1188,14 @@ public abstract class AbstractConnectionIntegrationTests {
actual.add(connection.rPopLPush("PopList", "pop2"));
actual.add(connection.lRange("PopList", 0, -1));
actual.add(connection.lRange("pop2", 0, -1));
verifyResults(
Arrays.asList(new Object[] { 1l, 2l, 1l, "world",
Arrays.asList(new String[] { "hello" }),
Arrays.asList(new String[] { "world", "hey" }) }));
verifyResults(Arrays.asList(new Object[] { 1l, 2l, 1l, "world", Arrays.asList(new String[] { "hello" }),
Arrays.asList(new String[] { "world", "hey" }) }));
}
@Test
public void testBRPopLPush() {
DefaultStringRedisConnection conn2 = new DefaultStringRedisConnection(
connectionFactory.getConnection());
DefaultStringRedisConnection conn2 = new DefaultStringRedisConnection(connectionFactory.getConnection());
conn2.rPush("PopList", "hello");
conn2.rPush("PopList", "world");
conn2.rPush("pop2", "hey");
@@ -1240,8 +1203,7 @@ public abstract class AbstractConnectionIntegrationTests {
List<Object> results = getResults();
assertEquals(Arrays.asList(new String[] { "world" }), results);
assertEquals(Arrays.asList(new String[] { "hello" }), connection.lRange("PopList", 0, -1));
assertEquals(Arrays.asList(new String[] { "world", "hey" }),
connection.lRange("pop2", 0, -1));
assertEquals(Arrays.asList(new String[] { "world", "hey" }), connection.lRange("pop2", 0, -1));
}
@Test
@@ -1279,16 +1241,14 @@ public abstract class AbstractConnectionIntegrationTests {
actual.add(connection.lPush("testlist", "bar"));
actual.add(connection.lPush("testlist", "baz"));
actual.add(connection.lRange("testlist", 0, -1));
verifyResults(Arrays.asList(new Object[] { 1l, 2l,
Arrays.asList(new String[] { "baz", "bar" }) }));
verifyResults(Arrays.asList(new Object[] { 1l, 2l, Arrays.asList(new String[] { "baz", "bar" }) }));
}
@Test
public void testLPushMultiple() {
actual.add(connection.lPush("testlist", "bar", "baz"));
actual.add(connection.lRange("testlist", 0, -1));
verifyResults(Arrays.asList(new Object[] { 2l,
Arrays.asList(new String[] { "baz", "bar" }) }));
verifyResults(Arrays.asList(new Object[] { 2l, Arrays.asList(new String[] { "baz", "bar" }) }));
}
// Set operations
@@ -1298,8 +1258,8 @@ public abstract class AbstractConnectionIntegrationTests {
actual.add(connection.sAdd("myset", "foo"));
actual.add(connection.sAdd("myset", "bar"));
actual.add(connection.sMembers("myset"));
verifyResults(Arrays.asList(new Object[] { 1l, 1l, new HashSet<String>(Arrays.asList(new String[] {
"foo", "bar" })) }));
verifyResults(Arrays.asList(new Object[] { 1l, 1l,
new HashSet<String>(Arrays.asList(new String[] { "foo", "bar" })) }));
}
@Test
@@ -1307,8 +1267,8 @@ public abstract class AbstractConnectionIntegrationTests {
actual.add(connection.sAdd("myset", "foo", "bar"));
actual.add(connection.sAdd("myset", "baz"));
actual.add(connection.sMembers("myset"));
verifyResults(Arrays.asList(new Object[] { 2l, 1l, new HashSet<String>(Arrays.asList(new String[] {
"foo", "bar", "baz" })) }));
verifyResults(Arrays.asList(new Object[] { 2l, 1l,
new HashSet<String>(Arrays.asList(new String[] { "foo", "bar", "baz" })) }));
}
@Test
@@ -1325,9 +1285,7 @@ public abstract class AbstractConnectionIntegrationTests {
actual.add(connection.sAdd("myset", "bar"));
actual.add(connection.sAdd("otherset", "bar"));
actual.add(connection.sDiff("myset", "otherset"));
verifyResults(
Arrays.asList(new Object[] { 1l, 1l, 1l,
new HashSet<String>(Collections.singletonList("foo")) }));
verifyResults(Arrays.asList(new Object[] { 1l, 1l, 1l, new HashSet<String>(Collections.singletonList("foo")) }));
}
@Test
@@ -1337,9 +1295,7 @@ public abstract class AbstractConnectionIntegrationTests {
actual.add(connection.sAdd("otherset", "bar"));
actual.add(connection.sDiffStore("thirdset", "myset", "otherset"));
actual.add(connection.sMembers("thirdset"));
verifyResults(
Arrays.asList(new Object[] { 1l, 1l, 1l, 1l,
new HashSet<String>(Collections.singletonList("foo")) }));
verifyResults(Arrays.asList(new Object[] { 1l, 1l, 1l, 1l, new HashSet<String>(Collections.singletonList("foo")) }));
}
@Test
@@ -1348,9 +1304,7 @@ public abstract class AbstractConnectionIntegrationTests {
actual.add(connection.sAdd("myset", "bar"));
actual.add(connection.sAdd("otherset", "bar"));
actual.add(connection.sInter("myset", "otherset"));
verifyResults(
Arrays.asList(new Object[] { 1l, 1l, 1l,
new HashSet<String>(Collections.singletonList("bar")) }));
verifyResults(Arrays.asList(new Object[] { 1l, 1l, 1l, new HashSet<String>(Collections.singletonList("bar")) }));
}
@Test
@@ -1360,9 +1314,7 @@ public abstract class AbstractConnectionIntegrationTests {
actual.add(connection.sAdd("otherset", "bar"));
actual.add(connection.sInterStore("thirdset", "myset", "otherset"));
actual.add(connection.sMembers("thirdset"));
verifyResults(
Arrays.asList(new Object[] { 1l, 1l, 1l, 1l,
new HashSet<String>(Collections.singletonList("bar")) }));
verifyResults(Arrays.asList(new Object[] { 1l, 1l, 1l, 1l, new HashSet<String>(Collections.singletonList("bar")) }));
}
@Test
@@ -1388,8 +1340,7 @@ public abstract class AbstractConnectionIntegrationTests {
actual.add(connection.sAdd("myset", "foo"));
actual.add(connection.sAdd("myset", "bar"));
actual.add(connection.sPop("myset"));
assertTrue(new HashSet<String>(Arrays.asList(new String[] { "foo", "bar" }))
.contains((String) getResults().get(2)));
assertTrue(new HashSet<String>(Arrays.asList(new String[] { "foo", "bar" })).contains((String) getResults().get(2)));
}
@Test
@@ -1397,8 +1348,7 @@ public abstract class AbstractConnectionIntegrationTests {
actual.add(connection.sAdd("myset", "foo"));
actual.add(connection.sAdd("myset", "bar"));
actual.add(connection.sRandMember("myset"));
assertTrue(new HashSet<String>(Arrays.asList(new String[] { "foo", "bar" }))
.contains((String) getResults().get(2)));
assertTrue(new HashSet<String>(Arrays.asList(new String[] { "foo", "bar" })).contains((String) getResults().get(2)));
}
@Test
@@ -1442,9 +1392,7 @@ public abstract class AbstractConnectionIntegrationTests {
actual.add(connection.sRem("myset", "foo"));
actual.add(connection.sRem("myset", "baz"));
actual.add(connection.sMembers("myset"));
verifyResults(
Arrays.asList(new Object[] { 1l, 1l, 1l, 0l,
new HashSet<String>(Collections.singletonList("bar")) }));
verifyResults(Arrays.asList(new Object[] { 1l, 1l, 1l, 0l, new HashSet<String>(Collections.singletonList("bar")) }));
}
@Test
@@ -1454,9 +1402,7 @@ public abstract class AbstractConnectionIntegrationTests {
actual.add(connection.sAdd("myset", "baz"));
actual.add(connection.sRem("myset", "foo", "nope", "baz"));
actual.add(connection.sMembers("myset"));
verifyResults(
Arrays.asList(new Object[] { 1l, 1l, 1l, 2l,
new HashSet<String>(Collections.singletonList("bar")) }));
verifyResults(Arrays.asList(new Object[] { 1l, 1l, 1l, 2l, new HashSet<String>(Collections.singletonList("bar")) }));
}
@Test
@@ -1500,7 +1446,7 @@ public abstract class AbstractConnectionIntegrationTests {
strTuples.add(new DefaultStringTuple("James".getBytes(), "James", 1.0));
Set<Tuple> tuples = new HashSet<Tuple>();
tuples.add(new DefaultTuple("Joe".getBytes(), 2.5));
actual.add(connection.zAdd("myset",strTuples));
actual.add(connection.zAdd("myset", strTuples));
actual.add(connection.zAdd("myset".getBytes(), tuples));
actual.add(connection.zRange("myset", 0, -1));
verifyResults(Arrays.asList(new Object[] { 2l, 1l,
@@ -1531,9 +1477,8 @@ public abstract class AbstractConnectionIntegrationTests {
actual.add(connection.zAdd("myset", 4, "Joe"));
actual.add(connection.zIncrBy("myset", 2, "Joe"));
actual.add(connection.zRangeByScore("myset", 6, 6));
verifyResults(
Arrays.asList(new Object[] { true, true, true, 6d,
new LinkedHashSet<String>(Collections.singletonList("Joe")) }));
verifyResults(Arrays.asList(new Object[] { true, true, true, 6d,
new LinkedHashSet<String>(Collections.singletonList("Joe")) }));
}
@Test
@@ -1556,21 +1501,19 @@ public abstract class AbstractConnectionIntegrationTests {
actual.add(connection.zAdd("myset", 4, "Joe"));
actual.add(connection.zAdd("otherset", 1, "Bob"));
actual.add(connection.zAdd("otherset", 4, "James"));
actual.add(connection.zInterStore("thirdset", Aggregate.MAX, new int[] { 2, 3 }, "myset",
"otherset"));
actual.add(connection.zInterStore("thirdset", Aggregate.MAX, new int[] { 2, 3 }, "myset", "otherset"));
actual.add(connection.zRangeWithScores("thirdset", 0, -1));
verifyResults(
Arrays.asList(new Object[] {
true,
true,
true,
true,
true,
2l,
new LinkedHashSet<StringTuple>(Arrays.asList(new StringTuple[] {
new DefaultStringTuple("Bob".getBytes(), "Bob", 4d),
new DefaultStringTuple("James".getBytes(), "James", 12d) })) }));
verifyResults(Arrays.asList(new Object[] {
true,
true,
true,
true,
true,
2l,
new LinkedHashSet<StringTuple>(Arrays.asList(new StringTuple[] {
new DefaultStringTuple("Bob".getBytes(), "Bob", 4d),
new DefaultStringTuple("James".getBytes(), "James", 12d) })) }));
}
@Test
@@ -1578,13 +1521,12 @@ public abstract class AbstractConnectionIntegrationTests {
actual.add(connection.zAdd("myset", 2, "Bob"));
actual.add(connection.zAdd("myset", 1, "James"));
actual.add(connection.zRangeWithScores("myset", 0, -1));
verifyResults(
Arrays.asList(new Object[] {
true,
true,
new LinkedHashSet<StringTuple>(Arrays.asList(new StringTuple[] {
new DefaultStringTuple("James".getBytes(), "James", 1d),
new DefaultStringTuple("Bob".getBytes(), "Bob", 2d) })) }));
verifyResults(Arrays.asList(new Object[] {
true,
true,
new LinkedHashSet<StringTuple>(Arrays.asList(new StringTuple[] {
new DefaultStringTuple("James".getBytes(), "James", 1d),
new DefaultStringTuple("Bob".getBytes(), "Bob", 2d) })) }));
}
@Test
@@ -1593,7 +1535,7 @@ public abstract class AbstractConnectionIntegrationTests {
actual.add(connection.zAdd("myset", 1, "James"));
actual.add(connection.zRangeByScore("myset", 1, 1));
verifyResults(Arrays.asList(new Object[] { true, true,
new LinkedHashSet<String>(Arrays.asList(new String[] { "James" })) }));
new LinkedHashSet<String>(Arrays.asList(new String[] { "James" })) }));
}
@Test
@@ -1601,9 +1543,8 @@ public abstract class AbstractConnectionIntegrationTests {
actual.add(connection.zAdd("myset", 2, "Bob"));
actual.add(connection.zAdd("myset", 1, "James"));
actual.add(connection.zRangeByScore("myset", 1d, 3d, 1, -1));
verifyResults(
Arrays.asList(new Object[] { true, true,
new LinkedHashSet<String>(Arrays.asList(new String[] { "Bob" })) }));
verifyResults(Arrays.asList(new Object[] { true, true,
new LinkedHashSet<String>(Arrays.asList(new String[] { "Bob" })) }));
}
@Test
@@ -1614,9 +1555,8 @@ public abstract class AbstractConnectionIntegrationTests {
verifyResults(Arrays.asList(new Object[] {
true,
true,
new LinkedHashSet<StringTuple>(Arrays
.asList(new StringTuple[] { new DefaultStringTuple("Bob".getBytes(), "Bob",
2d) })) }));
new LinkedHashSet<StringTuple>(Arrays.asList(new StringTuple[] { new DefaultStringTuple("Bob".getBytes(),
"Bob", 2d) })) }));
}
@Test
@@ -1627,9 +1567,8 @@ public abstract class AbstractConnectionIntegrationTests {
verifyResults(Arrays.asList(new Object[] {
true,
true,
new LinkedHashSet<StringTuple>(Arrays
.asList(new StringTuple[] { new DefaultStringTuple("James".getBytes(),
"James", 1d) })) }));
new LinkedHashSet<StringTuple>(Arrays.asList(new StringTuple[] { new DefaultStringTuple("James".getBytes(),
"James", 1d) })) }));
}
@Test
@@ -1646,13 +1585,12 @@ public abstract class AbstractConnectionIntegrationTests {
actual.add(connection.zAdd("myset", 2, "Bob"));
actual.add(connection.zAdd("myset", 1, "James"));
actual.add(connection.zRevRangeWithScores("myset", 0, -1));
verifyResults(
Arrays.asList(new Object[] {
true,
true,
new LinkedHashSet<StringTuple>(Arrays.asList(new StringTuple[] {
new DefaultStringTuple("Bob".getBytes(), "Bob", 2d),
new DefaultStringTuple("James".getBytes(), "James", 1d) })) }));
verifyResults(Arrays.asList(new Object[] {
true,
true,
new LinkedHashSet<StringTuple>(Arrays.asList(new StringTuple[] {
new DefaultStringTuple("Bob".getBytes(), "Bob", 2d),
new DefaultStringTuple("James".getBytes(), "James", 1d) })) }));
}
@Test
@@ -1660,8 +1598,8 @@ public abstract class AbstractConnectionIntegrationTests {
actual.add(connection.zAdd("myset".getBytes(), 2, "Bob".getBytes()));
actual.add(connection.zAdd("myset".getBytes(), 1, "James".getBytes()));
actual.add(connection.zRevRangeByScore("myset", 0d, 3d, 0, 5));
verifyResults(Arrays.asList(new Object[] {true, true,
new LinkedHashSet<String>(Arrays.asList(new String[] { "Bob", "James" }))}));
verifyResults(Arrays.asList(new Object[] { true, true,
new LinkedHashSet<String>(Arrays.asList(new String[] { "Bob", "James" })) }));
}
@Test
@@ -1669,8 +1607,8 @@ public abstract class AbstractConnectionIntegrationTests {
actual.add(connection.zAdd("myset".getBytes(), 2, "Bob".getBytes()));
actual.add(connection.zAdd("myset".getBytes(), 1, "James".getBytes()));
actual.add(connection.zRevRangeByScore("myset", 0d, 3d));
verifyResults(Arrays.asList(new Object[] {true, true,
new LinkedHashSet<String>(Arrays.asList(new String[] { "Bob", "James" }))}));
verifyResults(Arrays.asList(new Object[] { true, true,
new LinkedHashSet<String>(Arrays.asList(new String[] { "Bob", "James" })) }));
}
@Test
@@ -1678,9 +1616,11 @@ public abstract class AbstractConnectionIntegrationTests {
actual.add(connection.zAdd("myset".getBytes(), 2, "Bob".getBytes()));
actual.add(connection.zAdd("myset".getBytes(), 1, "James".getBytes()));
actual.add(connection.zRevRangeByScoreWithScores("myset", 0d, 3d, 0, 1));
verifyResults(Arrays.asList(new Object[] {true, true,
new LinkedHashSet<StringTuple>(Arrays.asList(new StringTuple[] { new DefaultStringTuple("Bob"
.getBytes(), "Bob", 2d) }))}));
verifyResults(Arrays.asList(new Object[] {
true,
true,
new LinkedHashSet<StringTuple>(Arrays.asList(new StringTuple[] { new DefaultStringTuple("Bob".getBytes(),
"Bob", 2d) })) }));
}
@Test
@@ -1689,10 +1629,13 @@ public abstract class AbstractConnectionIntegrationTests {
actual.add(connection.zAdd("myset", 1, "James"));
actual.add(connection.zAdd("myset", 3, "Joe"));
actual.add(connection.zRevRangeByScoreWithScores("myset", 0d, 2d));
verifyResults(Arrays.asList(new Object[] {true, true, true,
verifyResults(Arrays.asList(new Object[] {
true,
true,
true,
new LinkedHashSet<StringTuple>(Arrays.asList(new StringTuple[] {
new DefaultStringTuple("Bob".getBytes(), "Bob", 2d),
new DefaultStringTuple("James".getBytes(), "James", 1d) }))}));
new DefaultStringTuple("James".getBytes(), "James", 1d) })) }));
}
@Test
@@ -1710,9 +1653,8 @@ public abstract class AbstractConnectionIntegrationTests {
actual.add(connection.zAdd("myset", 1, "James"));
actual.add(connection.zRem("myset", "James"));
actual.add(connection.zRange("myset", 0l, -1l));
verifyResults(
Arrays.asList(new Object[] { true, true, 1l,
new LinkedHashSet<String>(Arrays.asList(new String[] { "Bob" })) }));
verifyResults(Arrays.asList(new Object[] { true, true, 1l,
new LinkedHashSet<String>(Arrays.asList(new String[] { "Bob" })) }));
}
@Test
@@ -1723,9 +1665,8 @@ public abstract class AbstractConnectionIntegrationTests {
actual.add(connection.zAdd("myset", 2.5, "Jen"));
actual.add(connection.zRem("myset", "James", "Jen"));
actual.add(connection.zRange("myset", 0l, -1l));
verifyResults(
Arrays.asList(new Object[] { true, true, true, true, 2l,
new LinkedHashSet<String>(Arrays.asList(new String[] { "Joe", "Bob" })) }));
verifyResults(Arrays.asList(new Object[] { true, true, true, true, 2l,
new LinkedHashSet<String>(Arrays.asList(new String[] { "Joe", "Bob" })) }));
}
@Test
@@ -1743,9 +1684,8 @@ public abstract class AbstractConnectionIntegrationTests {
actual.add(connection.zAdd("myset", 1, "James"));
actual.add(connection.zRemRangeByScore("myset", 0d, 1d));
actual.add(connection.zRange("myset", 0l, -1l));
verifyResults(
Arrays.asList(new Object[] { true, true, 1l,
new LinkedHashSet<String>(Arrays.asList(new String[] { "Bob" })) }));
verifyResults(Arrays.asList(new Object[] { true, true, 1l,
new LinkedHashSet<String>(Arrays.asList(new String[] { "Bob" })) }));
}
@Test
@@ -1775,16 +1715,8 @@ public abstract class AbstractConnectionIntegrationTests {
actual.add(connection.zAdd("otherset", 4, "James"));
actual.add(connection.zUnionStore("thirdset", "myset", "otherset"));
actual.add(connection.zRange("thirdset", 0, -1));
verifyResults(
Arrays.asList(new Object[] {
true,
true,
true,
true,
true,
3l,
new LinkedHashSet<String>(Arrays.asList(new String[] { "Bob", "James",
"Joe" })) }));
verifyResults(Arrays.asList(new Object[] { true, true, true, true, true, 3l,
new LinkedHashSet<String>(Arrays.asList(new String[] { "Bob", "James", "Joe" })) }));
}
@Test
@@ -1794,21 +1726,18 @@ public abstract class AbstractConnectionIntegrationTests {
actual.add(connection.zAdd("myset", 4, "Joe"));
actual.add(connection.zAdd("otherset", 1, "Bob"));
actual.add(connection.zAdd("otherset", 4, "James"));
actual.add(connection.zUnionStore("thirdset", Aggregate.MAX, new int[] { 2, 3 }, "myset",
"otherset"));
actual.add(connection.zUnionStore("thirdset", Aggregate.MAX, new int[] { 2, 3 }, "myset", "otherset"));
actual.add(connection.zRangeWithScores("thirdset", 0, -1));
verifyResults(
Arrays.asList(new Object[] {
true,
true,
true,
true,
true,
3l,
new LinkedHashSet<StringTuple>(Arrays.asList(new StringTuple[] {
new DefaultStringTuple("Bob".getBytes(), "Bob", 4d),
new DefaultStringTuple("Joe".getBytes(), "Joe", 8d),
new DefaultStringTuple("James".getBytes(), "James", 12d) })) }));
verifyResults(Arrays.asList(new Object[] {
true,
true,
true,
true,
true,
3l,
new LinkedHashSet<StringTuple>(Arrays.asList(new StringTuple[] {
new DefaultStringTuple("Bob".getBytes(), "Bob", 4d), new DefaultStringTuple("Joe".getBytes(), "Joe", 8d),
new DefaultStringTuple("James".getBytes(), "James", 12d) })) }));
}
// Hash Ops
@@ -1880,7 +1809,7 @@ public abstract class AbstractConnectionIntegrationTests {
actual.add(connection.hSet("test", "key2", "2"));
actual.add(connection.hKeys("test"));
verifyResults(Arrays.asList(new Object[] { true, true,
new LinkedHashSet<String>(Arrays.asList(new String[] { "key", "key2" })) }));
new LinkedHashSet<String>(Arrays.asList(new String[] { "key", "key2" })) }));
}
@Test
@@ -1906,21 +1835,19 @@ public abstract class AbstractConnectionIntegrationTests {
actual.add(connection.hSet("test", "key", "foo"));
actual.add(connection.hSet("test", "key2", "bar"));
actual.add(connection.hVals("test"));
verifyResults(
Arrays.asList(new Object[] { true, true,
Arrays.asList(new String[] { "foo", "bar" }) }));
verifyResults(Arrays.asList(new Object[] { true, true, Arrays.asList(new String[] { "foo", "bar" }) }));
}
@Test
public void testMove() {
connection.set("foo", "bar");
actual.add(connection.move("foo", 1));
verifyResults(Arrays.asList(new Object[] { true}));
verifyResults(Arrays.asList(new Object[] { true }));
connection.select(1);
try {
assertEquals("bar",connection.get("foo"));
assertEquals("bar", connection.get("foo"));
} finally {
if(connection.exists("foo")) {
if (connection.exists("foo")) {
connection.del("foo");
}
}
@@ -1956,4 +1883,4 @@ public abstract class AbstractConnectionIntegrationTests {
return (!connection.exists(key));
}
}
}
}

View File

@@ -27,50 +27,40 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
/**
* Base test class for integration tests that execute each operation of a
* Connection while a pipeline is open, verifying that the operations return
* null and the proper values are returned when closing the pipeline.
* Base test class for integration tests that execute each operation of a Connection while a pipeline is open, verifying
* that the operations return null and the proper values are returned when closing the pipeline.
* <p>
* Pipelined results are generally native to the provider and not transformed by
* our {@link RedisConnection}, so this test overrides
* {@link AbstractConnectionIntegrationTests} when result types are different
*
* Pipelined results are generally native to the provider and not transformed by our {@link RedisConnection}, so this
* test overrides {@link AbstractConnectionIntegrationTests} when result types are different
*
* @author Jennifer Hickey
*
*/
abstract public class AbstractConnectionPipelineIntegrationTests extends
AbstractConnectionIntegrationTests {
abstract public class AbstractConnectionPipelineIntegrationTests extends AbstractConnectionIntegrationTests {
@Ignore
public void testNullKey() throws Exception {
}
public void testNullKey() throws Exception {}
@Ignore
public void testNullValue() throws Exception {
}
public void testNullValue() throws Exception {}
@Ignore
public void testHashNullKey() throws Exception {
}
public void testHashNullKey() throws Exception {}
@Ignore
public void testHashNullValue() throws Exception {
}
public void testHashNullValue() throws Exception {}
@Ignore("Pub/Sub not supported while pipelining")
public void testPubSubWithNamedChannels() throws Exception {
}
public void testPubSubWithNamedChannels() throws Exception {}
@Ignore("Pub/Sub not supported while pipelining")
public void testPubSubWithPatterns() throws Exception {
}
public void testPubSubWithPatterns() throws Exception {}
@Test(expected=RedisPipelineException.class)
@Test(expected = RedisPipelineException.class)
public void testExecWithoutMulti() {
super.testExecWithoutMulti();
}
@Test(expected=RedisPipelineException.class)
@Test(expected = RedisPipelineException.class)
public void testErrorInTx() {
super.testErrorInTx();
}
@@ -104,20 +94,20 @@ abstract public class AbstractConnectionPipelineIntegrationTests extends
super.testRestoreExistingKey();
}
@Test(expected=RedisPipelineException.class)
@Test(expected = RedisPipelineException.class)
@IfProfileValue(name = "redisVersion", value = "2.6")
public void testEvalArrayScriptError() {
super.testEvalArrayScriptError();
}
@Test(expected=RedisPipelineException.class)
@Test(expected = RedisPipelineException.class)
@IfProfileValue(name = "redisVersion", value = "2.6")
public void testEvalShaArrayError() {
super.testEvalShaArrayError();
}
@Test
public void testOpenPipelineTwice() {
public void testOpenPipelineTwice() {
connection.openPipeline();
// ensure things still proceed normally with an extra openPipeline
testGetSet();
@@ -146,13 +136,13 @@ abstract public class AbstractConnectionPipelineIntegrationTests extends
protected List<Object> getResults() {
try {
//we give redis some time to keep up
Thread.sleep(10);
} catch (InterruptedException e) {
e.printStackTrace();
}
try {
// we give redis some time to keep up
Thread.sleep(10);
} catch (InterruptedException e) {
e.printStackTrace();
}
return connection.closePipeline();
return connection.closePipeline();
}
}

View File

@@ -9,34 +9,27 @@ import org.junit.Ignore;
import org.junit.Test;
import org.springframework.test.annotation.IfProfileValue;
abstract public class AbstractConnectionTransactionIntegrationTests extends
AbstractConnectionIntegrationTests {
abstract public class AbstractConnectionTransactionIntegrationTests extends AbstractConnectionIntegrationTests {
@Ignore
public void testMultiDiscard() {
}
public void testMultiDiscard() {}
@Ignore
public void testMultiExec() {
}
public void testMultiExec() {}
@Ignore
public void testUnwatch() {
}
public void testUnwatch() {}
@Ignore
public void testWatch() {
}
public void testWatch() {}
@Ignore
@Test
public void testExecWithoutMulti() {
}
public void testExecWithoutMulti() {}
@Ignore
@Test
public void testErrorInTx() {
}
public void testErrorInTx() {}
/*
* Using blocking ops inside a tx does not make a lot of sense as it would require blocking the
@@ -45,52 +38,40 @@ abstract public class AbstractConnectionTransactionIntegrationTests extends
*/
@Ignore
public void testBLPop() {
}
public void testBLPop() {}
@Ignore
public void testBRPop() {
}
public void testBRPop() {}
@Ignore
public void testBRPopLPush() {
}
public void testBRPopLPush() {}
@Ignore
public void testBLPopTimeout() {
}
public void testBLPopTimeout() {}
@Ignore
public void testBRPopTimeout() {
}
public void testBRPopTimeout() {}
@Ignore
public void testBRPopLPushTimeout() {
}
public void testBRPopLPushTimeout() {}
@Ignore("Pub/Sub not supported with transactions")
public void testPubSubWithNamedChannels() throws Exception {
}
public void testPubSubWithNamedChannels() throws Exception {}
@Ignore("Pub/Sub not supported with transactions")
public void testPubSubWithPatterns() throws Exception {
}
public void testPubSubWithPatterns() throws Exception {}
@Ignore
public void testNullKey() throws Exception {
}
public void testNullKey() throws Exception {}
@Ignore
public void testNullValue() throws Exception {
}
public void testNullValue() throws Exception {}
@Ignore
public void testHashNullKey() throws Exception {
}
public void testHashNullKey() throws Exception {}
@Ignore
public void testHashNullValue() throws Exception {
}
public void testHashNullValue() throws Exception {}
@Test(expected = UnsupportedOperationException.class)
public void testWatchWhileInTx() {

View File

@@ -28,9 +28,8 @@ import org.junit.Test;
/**
* Unit test of {@link DefaultStringRedisConnection} that executes commands in a pipeline
*
*
* @author Jennifer Hickey
*
*/
public class DefaultStringRedisConnectionPipelineTests extends DefaultStringRedisConnectionTests {
@@ -152,7 +151,7 @@ public class DefaultStringRedisConnectionPipelineTests extends DefaultStringRedi
connection.lLen(fooBytes);
connection.exec();
// closePipeline should only return the results of exec, not of llen
verifyResults(Arrays.asList(new Object[] {results}));
verifyResults(Arrays.asList(new Object[] { results }));
}
@Test
@@ -973,15 +972,13 @@ public class DefaultStringRedisConnectionPipelineTests extends DefaultStringRedi
@Test
public void testTypeBytes() {
doReturn(Arrays.asList(new Object[] { DataType.HASH })).when(nativeConnection)
.closePipeline();
doReturn(Arrays.asList(new Object[] { DataType.HASH })).when(nativeConnection).closePipeline();
super.testTypeBytes();
}
@Test
public void testType() {
doReturn(Arrays.asList(new Object[] { DataType.HASH })).when(nativeConnection)
.closePipeline();
doReturn(Arrays.asList(new Object[] { DataType.HASH })).when(nativeConnection).closePipeline();
super.testType();
}
@@ -1426,8 +1423,7 @@ public class DefaultStringRedisConnectionPipelineTests extends DefaultStringRedi
// Only call one method, but return 2 results from nativeConnection.closePipeline()
// Emulates scenario where user has called some methods directly on the native connection
// while pipeline is open
doReturn(Arrays.asList(new Object[] { barBytes, 3l })).when(nativeConnection)
.closePipeline();
doReturn(Arrays.asList(new Object[] { barBytes, 3l })).when(nativeConnection).closePipeline();
doReturn(barBytes).when(nativeConnection).get(fooBytes);
connection.get(foo);
verifyResults(Arrays.asList(new Object[] { barBytes, 3l }));

View File

@@ -43,16 +43,14 @@ import org.springframework.data.redis.serializer.StringRedisSerializer;
/**
* Unit test of {@link DefaultStringRedisConnection}
*
*
* @author Jennifer Hickey
*
*/
public class DefaultStringRedisConnectionTests {
protected List<Object> actual = new ArrayList<Object>();
@Mock
protected RedisConnection nativeConnection;
@Mock protected RedisConnection nativeConnection;
protected DefaultStringRedisConnection connection;
@@ -78,8 +76,7 @@ public class DefaultStringRedisConnectionTests {
protected Map<String, String> stringMap = new HashMap<String, String>();
protected Set<Tuple> tupleSet = new HashSet<Tuple>(Collections.singletonList(new DefaultTuple(
barBytes, 3d)));
protected Set<Tuple> tupleSet = new HashSet<Tuple>(Collections.singletonList(new DefaultTuple(barBytes, 3d)));
protected Set<StringTuple> stringTupleSet = new HashSet<StringTuple>(
Collections.singletonList(new DefaultStringTuple(new DefaultTuple(barBytes, 3d), bar)));
@@ -1254,16 +1251,14 @@ public class DefaultStringRedisConnectionTests {
@Test
public void testZInterStoreAggWeightsBytes() {
doReturn(5l).when(nativeConnection).zInterStore(fooBytes, Aggregate.MAX, new int[0],
fooBytes);
doReturn(5l).when(nativeConnection).zInterStore(fooBytes, Aggregate.MAX, new int[0], fooBytes);
actual.add(connection.zInterStore(fooBytes, Aggregate.MAX, new int[0], fooBytes));
verifyResults(Arrays.asList(new Object[] { 5l }));
}
@Test
public void testZInterStoreAggWeights() {
doReturn(5l).when(nativeConnection).zInterStore(fooBytes, Aggregate.MAX, new int[0],
fooBytes);
doReturn(5l).when(nativeConnection).zInterStore(fooBytes, Aggregate.MAX, new int[0], fooBytes);
actual.add(connection.zInterStore(foo, Aggregate.MAX, new int[0], foo));
verifyResults(Arrays.asList(new Object[] { 5l }));
}
@@ -1396,16 +1391,14 @@ public class DefaultStringRedisConnectionTests {
@Test
public void testZRevRangeByScoreWithScoresOffsetCountBytes() {
doReturn(tupleSet).when(nativeConnection).zRevRangeByScoreWithScores(fooBytes, 1d, 3d, 5l,
7l);
doReturn(tupleSet).when(nativeConnection).zRevRangeByScoreWithScores(fooBytes, 1d, 3d, 5l, 7l);
actual.add(connection.zRevRangeByScoreWithScores(fooBytes, 1d, 3d, 5l, 7l));
verifyResults(Arrays.asList(new Object[] { tupleSet }));
}
@Test
public void testZRevRangeByScoreWithScoresOffsetCount() {
doReturn(tupleSet).when(nativeConnection).zRevRangeByScoreWithScores(fooBytes, 1d, 3d, 5l,
7l);
doReturn(tupleSet).when(nativeConnection).zRevRangeByScoreWithScores(fooBytes, 1d, 3d, 5l, 7l);
actual.add(connection.zRevRangeByScoreWithScores(foo, 1d, 3d, 5l, 7l));
verifyResults(Arrays.asList(new Object[] { stringTupleSet }));
}
@@ -1538,16 +1531,14 @@ public class DefaultStringRedisConnectionTests {
@Test
public void testZUnionStoreAggWeightsBytes() {
doReturn(5l).when(nativeConnection).zUnionStore(fooBytes, Aggregate.MAX, new int[0],
fooBytes);
doReturn(5l).when(nativeConnection).zUnionStore(fooBytes, Aggregate.MAX, new int[0], fooBytes);
actual.add(connection.zUnionStore(fooBytes, Aggregate.MAX, new int[0], fooBytes));
verifyResults(Arrays.asList(new Object[] { 5l }));
}
@Test
public void testZUnionStoreAggWeights() {
doReturn(5l).when(nativeConnection).zUnionStore(fooBytes, Aggregate.MAX, new int[0],
fooBytes);
doReturn(5l).when(nativeConnection).zUnionStore(fooBytes, Aggregate.MAX, new int[0], fooBytes);
actual.add(connection.zUnionStore(foo, Aggregate.MAX, new int[0], foo));
verifyResults(Arrays.asList(new Object[] { 5l }));
}

View File

@@ -940,15 +940,13 @@ public class DefaultStringRedisConnectionTxTests extends DefaultStringRedisConne
@Test
public void testTypeBytes() {
doReturn(Arrays.asList(new Object[] { DataType.HASH })).when(nativeConnection)
.exec();
doReturn(Arrays.asList(new Object[] { DataType.HASH })).when(nativeConnection).exec();
super.testTypeBytes();
}
@Test
public void testType() {
doReturn(Arrays.asList(new Object[] { DataType.HASH })).when(nativeConnection)
.exec();
doReturn(Arrays.asList(new Object[] { DataType.HASH })).when(nativeConnection).exec();
super.testType();
}
@@ -1383,7 +1381,8 @@ public class DefaultStringRedisConnectionTxTests extends DefaultStringRedisConne
public void testDisablePipelineAndTxDeserialize() {
connection.setDeserializePipelineAndTxResults(false);
doReturn(Arrays.asList(new Object[] { barBytes })).when(nativeConnection).exec();
doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { barBytes })})).when(nativeConnection).closePipeline();
doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { barBytes }) })).when(nativeConnection)
.closePipeline();
doReturn(barBytes).when(nativeConnection).get(fooBytes);
connection.get(foo);
verifyResults(Arrays.asList(new Object[] { barBytes }));
@@ -1403,7 +1402,8 @@ public class DefaultStringRedisConnectionTxTests extends DefaultStringRedisConne
@Test
public void testDiscard() {
doReturn(Arrays.asList(new Object[] { fooBytes })).when(nativeConnection).exec();
doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { fooBytes })})).when(nativeConnection).closePipeline();
doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { fooBytes }) })).when(nativeConnection)
.closePipeline();
doReturn(barBytes).when(nativeConnection).get(fooBytes);
doReturn(fooBytes).when(nativeConnection).get(barBytes);
connection.get(foo);

View File

@@ -45,11 +45,10 @@ import static org.junit.Assert.assertNotNull;
/**
* Integration test of {@link JedisConnection}
*
*
* @author Costin Leau
* @author Jennifer Hickey
* @author Thomas Darimont
*
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration
@@ -66,11 +65,11 @@ public class JedisConnectionIntegrationTests extends AbstractConnectionIntegrati
// error on sending QUIT to Redis
}
try{
connection.close();
} catch (Exception e) {
//silently close connection
}
try {
connection.close();
} catch (Exception e) {
// silently close connection
}
connection = null;
}
@@ -85,7 +84,7 @@ public class JedisConnectionIntegrationTests extends AbstractConnectionIntegrati
factory2.destroy();
}
@Test(expected=InvalidDataAccessApiUsageException.class)
@Test(expected = InvalidDataAccessApiUsageException.class)
public void testCreateConnectionWithDbFailure() {
JedisConnectionFactory factory2 = new JedisConnectionFactory();
factory2.setDatabase(77);
@@ -109,7 +108,7 @@ public class JedisConnectionIntegrationTests extends AbstractConnectionIntegrati
factory2.destroy();
}
@Test(expected=UnsupportedOperationException.class)
@Test(expected = UnsupportedOperationException.class)
public void testZAddSameScores() {
Set<StringTuple> strTuples = new HashSet<StringTuple>();
strTuples.add(new DefaultStringTuple("Bob".getBytes(), "Bob", 2.0));
@@ -117,114 +116,114 @@ public class JedisConnectionIntegrationTests extends AbstractConnectionIntegrati
connection.zAdd("myset", strTuples);
}
@Test(expected=InvalidDataAccessApiUsageException.class)
@Test(expected = InvalidDataAccessApiUsageException.class)
@IfProfileValue(name = "redisVersion", value = "2.6")
public void testEvalReturnSingleError() {
connection.eval("return redis.call('expire','foo')", ReturnType.BOOLEAN, 0);
}
@Test(expected=InvalidDataAccessApiUsageException.class)
@Test(expected = InvalidDataAccessApiUsageException.class)
@IfProfileValue(name = "redisVersion", value = "2.6")
public void testEvalArrayScriptError() {
super.testEvalArrayScriptError();
}
@Test(expected=InvalidDataAccessApiUsageException.class)
@Test(expected = InvalidDataAccessApiUsageException.class)
@IfProfileValue(name = "redisVersion", value = "2.6")
public void testEvalShaNotFound() {
connection.evalSha("somefakesha", ReturnType.VALUE, 2, "key1", "key2");
}
@Test(expected=InvalidDataAccessApiUsageException.class)
@Test(expected = InvalidDataAccessApiUsageException.class)
@IfProfileValue(name = "redisVersion", value = "2.6")
public void testEvalShaArrayError() {
super.testEvalShaArrayError();
}
@Test(expected=InvalidDataAccessApiUsageException.class)
@Test(expected = InvalidDataAccessApiUsageException.class)
@IfProfileValue(name = "redisVersion", value = "2.6")
public void testRestoreBadData() {
super.testRestoreBadData();
}
@Test(expected=InvalidDataAccessApiUsageException.class)
@Test(expected = InvalidDataAccessApiUsageException.class)
@IfProfileValue(name = "redisVersion", value = "2.6")
public void testRestoreExistingKey() {
super.testRestoreExistingKey();
}
@Test(expected=InvalidDataAccessApiUsageException.class)
@Test(expected = InvalidDataAccessApiUsageException.class)
public void testExecWithoutMulti() {
super.testExecWithoutMulti();
}
@Test(expected=InvalidDataAccessApiUsageException.class)
@Test(expected = InvalidDataAccessApiUsageException.class)
public void testErrorInTx() {
super.testErrorInTx();
}
/**
* Override pub/sub test methods to use a separate connection factory for
* subscribing threads, due to this issue: https://github.com/xetorthio/jedis/issues/445
*/
/**
* Override pub/sub test methods to use a separate connection factory for subscribing threads, due to this issue:
* https://github.com/xetorthio/jedis/issues/445
*/
@Test
public void testPubSubWithNamedChannels() throws Exception {
final String expectedChannel = "channel1";
final String expectedChannel = "channel1";
final String expectedMessage = "msg";
final BlockingDeque<Message> messages = new LinkedBlockingDeque<Message>();
MessageListener listener = new MessageListener() {
public void onMessage(Message message, byte[] pattern) {
messages.add(message);
messages.add(message);
System.out.println("Received message '" + new String(message.getBody()) + "'");
}
};
Thread t = new Thread(){
{
setDaemon(true);
}
public void run(){
Thread t = new Thread() {
{
setDaemon(true);
}
RedisConnection con = connectionFactory.getConnection();
try {
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
public void run() {
con.publish(expectedChannel.getBytes(),expectedMessage.getBytes());
RedisConnection con = connectionFactory.getConnection();
try {
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
try {
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
con.publish(expectedChannel.getBytes(), expectedMessage.getBytes());
/*
In some clients, unsubscribe happens async of message
receipt, so not all
messages may be received if unsubscribing now.
Connection.close in teardown
will take care of unsubscribing.
*/
if (!(ConnectionUtils.isAsync(connectionFactory))) {
connection.getSubscription().unsubscribe();
}
con.close();
}
};
t.start();
try {
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
connection.subscribe(listener, expectedChannel.getBytes());
/*
In some clients, unsubscribe happens async of message
receipt, so not all
messages may be received if unsubscribing now.
Connection.close in teardown
will take care of unsubscribing.
*/
if (!(ConnectionUtils.isAsync(connectionFactory))) {
connection.getSubscription().unsubscribe();
}
con.close();
}
};
t.start();
Message message = messages.poll(5, TimeUnit.SECONDS);
connection.subscribe(listener, expectedChannel.getBytes());
Message message = messages.poll(5, TimeUnit.SECONDS);
assertNotNull(message);
assertEquals(expectedMessage, new String(message.getBody()));
assertEquals(expectedChannel, new String(message.getChannel()));
}
}
@Test
public void testPubSubWithPatterns() throws Exception {
@@ -241,28 +240,29 @@ public class JedisConnectionIntegrationTests extends AbstractConnectionIntegrati
}
};
Thread th = new Thread(){
{
setDaemon(true);
}
Thread th = new Thread() {
{
setDaemon(true);
}
public void run() {
// open a new connection
RedisConnection con = connectionFactory.getConnection();
try {
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
// open a new connection
RedisConnection con = connectionFactory.getConnection();
try {
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
con.publish("channel1".getBytes(), expectedMessage.getBytes());
con.publish("channel2".getBytes(), expectedMessage.getBytes());
try {
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
try {
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
con.close();
// In some clients, unsubscribe happens async of message
@@ -274,7 +274,7 @@ public class JedisConnectionIntegrationTests extends AbstractConnectionIntegrati
connection.getSubscription().pUnsubscribe(expectedPattern.getBytes());
}
}
};
};
th.start();
connection.pSubscribe(listener, expectedPattern);
@@ -300,11 +300,10 @@ public class JedisConnectionIntegrationTests extends AbstractConnectionIntegrati
RedisConnection conn = factory2.getConnection();
try {
conn.get(null);
}catch(Exception e) {
}
} catch (Exception e) {}
conn.close();
// Make sure we don't end up with broken connection
factory2.getConnection().dbSize();
factory2.destroy();
factory2.destroy();
}
}

View File

@@ -36,14 +36,12 @@ import redis.clients.jedis.JedisPoolConfig;
/**
* Integration test of {@link JedisConnection} pipeline functionality
*
*
* @author Jennifer Hickey
*
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("JedisConnectionIntegrationTests-context.xml")
public class JedisConnectionPipelineIntegrationTests extends
AbstractConnectionPipelineIntegrationTests {
public class JedisConnectionPipelineIntegrationTests extends AbstractConnectionPipelineIntegrationTests {
@After
public void tearDown() {
@@ -60,8 +58,7 @@ public class JedisConnectionPipelineIntegrationTests extends
}
@Ignore("Jedis issue: Pipeline tries to return String instead of List<String>")
public void testGetConfig() {
}
public void testGetConfig() {}
@Test
public void testWatch() {
@@ -69,8 +66,7 @@ public class JedisConnectionPipelineIntegrationTests extends
connection.watch("testitnow".getBytes());
// Jedis doesn't actually send commands until you close the pipeline
getResults();
DefaultStringRedisConnection conn2 = new DefaultStringRedisConnection(
connectionFactory.getConnection());
DefaultStringRedisConnection conn2 = new DefaultStringRedisConnection(connectionFactory.getConnection());
conn2.set("testitnow", "something");
conn2.close();
// Reopen the pipeline
@@ -95,19 +91,18 @@ public class JedisConnectionPipelineIntegrationTests extends
getResults();
initConnection();
connection.multi();
DefaultStringRedisConnection conn2 = new DefaultStringRedisConnection(
connectionFactory.getConnection());
DefaultStringRedisConnection conn2 = new DefaultStringRedisConnection(connectionFactory.getConnection());
conn2.set("testitnow", "something");
connection.set("testitnow", "somethingelse");
connection.get("testitnow");
actual.add(connection.exec());
List<Object> results = getResults();
List<Object> execResults = (List<Object>) results.get(0);
assertEquals(Arrays.asList(new Object[] {"somethingelse"}), execResults);
assertEquals(Arrays.asList(new Object[] { "somethingelse" }), execResults);
}
@Test
//DATAREDIS-213 - Verify connection returns to pool after select
// DATAREDIS-213 - Verify connection returns to pool after select
public void testClosePoolPipelinedDbSelect() {
JedisPoolConfig config = new JedisPoolConfig();
config.setMaxActive(1);
@@ -125,127 +120,127 @@ public class JedisConnectionPipelineIntegrationTests extends
}
// Unsupported Ops
@Test(expected=UnsupportedOperationException.class)
@Test(expected = UnsupportedOperationException.class)
@IfProfileValue(name = "redisVersion", value = "2.6")
public void testScriptLoadEvalSha() {
super.testScriptLoadEvalSha();
}
@Test(expected=UnsupportedOperationException.class)
@Test(expected = UnsupportedOperationException.class)
@IfProfileValue(name = "redisVersion", value = "2.6")
public void testEvalShaArrayStrings() {
super.testEvalShaArrayStrings();
}
@Test(expected=UnsupportedOperationException.class)
@Test(expected = UnsupportedOperationException.class)
@IfProfileValue(name = "redisVersion", value = "2.6")
public void testEvalShaNotFound() {
super.testEvalShaNotFound();
}
@Test(expected=UnsupportedOperationException.class)
@Test(expected = UnsupportedOperationException.class)
@IfProfileValue(name = "redisVersion", value = "2.6")
public void testEvalShaArrayError() {
super.testEvalShaArrayError();
}
@Test(expected=UnsupportedOperationException.class)
@Test(expected = UnsupportedOperationException.class)
@IfProfileValue(name = "redisVersion", value = "2.6")
public void testEvalArrayScriptError() {
super.testEvalArrayScriptError();
}
@Test(expected=UnsupportedOperationException.class)
@Test(expected = UnsupportedOperationException.class)
@IfProfileValue(name = "redisVersion", value = "2.6")
public void testEvalReturnString() {
super.testEvalReturnString();
}
@Test(expected=UnsupportedOperationException.class)
@Test(expected = UnsupportedOperationException.class)
@IfProfileValue(name = "redisVersion", value = "2.6")
public void testEvalReturnNumber() {
super.testEvalReturnNumber();
}
@Test(expected=UnsupportedOperationException.class)
@Test(expected = UnsupportedOperationException.class)
@IfProfileValue(name = "redisVersion", value = "2.6")
public void testEvalReturnSingleOK() {
super.testEvalReturnSingleOK();
}
@Test(expected=UnsupportedOperationException.class)
@Test(expected = UnsupportedOperationException.class)
@IfProfileValue(name = "redisVersion", value = "2.6")
public void testEvalReturnSingleError() {
super.testEvalReturnSingleError();
}
@Test(expected=UnsupportedOperationException.class)
@Test(expected = UnsupportedOperationException.class)
@IfProfileValue(name = "redisVersion", value = "2.6")
public void testEvalReturnFalse() {
super.testEvalReturnFalse();
}
@Test(expected=UnsupportedOperationException.class)
@Test(expected = UnsupportedOperationException.class)
@IfProfileValue(name = "redisVersion", value = "2.6")
public void testEvalReturnTrue() {
super.testEvalReturnTrue();
}
@Test(expected=UnsupportedOperationException.class)
@Test(expected = UnsupportedOperationException.class)
@IfProfileValue(name = "redisVersion", value = "2.6")
public void testEvalReturnArrayStrings() {
super.testEvalReturnArrayStrings();
}
@Test(expected=UnsupportedOperationException.class)
@Test(expected = UnsupportedOperationException.class)
@IfProfileValue(name = "redisVersion", value = "2.6")
public void testEvalReturnArrayNumbers() {
super.testEvalReturnArrayNumbers();
}
@Test(expected=UnsupportedOperationException.class)
@Test(expected = UnsupportedOperationException.class)
@IfProfileValue(name = "redisVersion", value = "2.6")
public void testEvalReturnArrayOKs() {
super.testEvalReturnArrayOKs();
}
@Test(expected=UnsupportedOperationException.class)
@Test(expected = UnsupportedOperationException.class)
@IfProfileValue(name = "redisVersion", value = "2.6")
public void testEvalReturnArrayFalses() {
super.testEvalReturnArrayFalses();
}
@Test(expected=UnsupportedOperationException.class)
@Test(expected = UnsupportedOperationException.class)
@IfProfileValue(name = "redisVersion", value = "2.6")
public void testEvalReturnArrayTrues() {
super.testEvalReturnArrayTrues();
}
@Test(expected=UnsupportedOperationException.class)
@Test(expected = UnsupportedOperationException.class)
@IfProfileValue(name = "redisVersion", value = "2.6")
public void testScriptExists() {
super.testScriptExists();
}
@IfProfileValue(name = "redisVersion", value = "2.6")
@Test(expected=UnsupportedOperationException.class)
public void testScriptKill() throws Exception{
@Test(expected = UnsupportedOperationException.class)
public void testScriptKill() throws Exception {
connection.scriptKill();
}
@Test(expected=UnsupportedOperationException.class)
@Test(expected = UnsupportedOperationException.class)
@IfProfileValue(name = "redisVersion", value = "2.6")
public void testScriptFlush() {
connection.scriptFlush();
}
@Test(expected=UnsupportedOperationException.class)
@Test(expected = UnsupportedOperationException.class)
@IfProfileValue(name = "redisVersion", value = "2.6")
public void testInfoBySection() throws Exception {
super.testInfoBySection();
}
@Test(expected=UnsupportedOperationException.class)
@Test(expected = UnsupportedOperationException.class)
public void testZAddMultiple() {
super.testZAddMultiple();
}

View File

@@ -14,23 +14,22 @@ public class JedisConnectionPipelineTxIntegrationTests extends JedisConnectionTr
@Ignore("Jedis issue: Pipeline tries to return String instead of List<String>")
@Test
public void testGetConfig() {
}
public void testGetConfig() {}
@Test(expected=RedisPipelineException.class)
@Test(expected = RedisPipelineException.class)
public void exceptionExecuteNative() throws Exception {
connection.execute("set", "foo");
connection.execute("ZadD", getClass() + "#foo\t0.90\titem");
getResults();
}
@Test(expected=RedisPipelineException.class)
@Test(expected = RedisPipelineException.class)
@IfProfileValue(name = "redisVersion", value = "2.6")
public void testRestoreBadData() {
super.testRestoreBadData();
}
@Test(expected=RedisPipelineException.class)
@Test(expected = RedisPipelineException.class)
@IfProfileValue(name = "redisVersion", value = "2.6")
public void testRestoreExistingKey() {
super.testRestoreExistingKey();
@@ -46,8 +45,8 @@ public class JedisConnectionPipelineTxIntegrationTests extends JedisConnectionTr
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);
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

@@ -28,17 +28,14 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
/**
* Integration test of {@link JedisConnection} transaction functionality.
* <p>
* Each method of {@link JedisConnection} behaves differently if executed with a
* transaction (i.e. between multi and exec or discard calls), so this test
* covers those branching points
*
* Each method of {@link JedisConnection} behaves differently if executed with a transaction (i.e. between multi and
* exec or discard calls), so this test covers those branching points
*
* @author Jennifer Hickey
*
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("JedisConnectionIntegrationTests-context.xml")
public class JedisConnectionTransactionIntegrationTests extends
AbstractConnectionTransactionIntegrationTests {
public class JedisConnectionTransactionIntegrationTests extends AbstractConnectionTransactionIntegrationTests {
@After
public void tearDown() {
@@ -55,8 +52,7 @@ public class JedisConnectionTransactionIntegrationTests extends
}
@Ignore("Jedis issue: Transaction tries to return String instead of List<String>")
public void testGetConfig() {
}
public void testGetConfig() {}
// Unsupported Ops
@Test(expected = UnsupportedOperationException.class)
@@ -77,13 +73,13 @@ public class JedisConnectionTransactionIntegrationTests extends
super.testEvalShaNotFound();
}
@Test(expected=UnsupportedOperationException.class)
@Test(expected = UnsupportedOperationException.class)
@IfProfileValue(name = "redisVersion", value = "2.6")
public void testEvalShaArrayError() {
super.testEvalShaArrayError();
}
@Test(expected=UnsupportedOperationException.class)
@Test(expected = UnsupportedOperationException.class)
@IfProfileValue(name = "redisVersion", value = "2.6")
public void testEvalArrayScriptError() {
super.testEvalArrayScriptError();
@@ -179,18 +175,18 @@ public class JedisConnectionTransactionIntegrationTests extends
super.testInfoBySection();
}
@Test(expected=UnsupportedOperationException.class)
@Test(expected = UnsupportedOperationException.class)
public void testZAddMultiple() {
super.testZAddMultiple();
}
@Test(expected=InvalidDataAccessApiUsageException.class)
@Test(expected = InvalidDataAccessApiUsageException.class)
@IfProfileValue(name = "redisVersion", value = "2.6")
public void testRestoreBadData() {
super.testRestoreBadData();
}
@Test(expected=InvalidDataAccessApiUsageException.class)
@Test(expected = InvalidDataAccessApiUsageException.class)
@IfProfileValue(name = "redisVersion", value = "2.6")
public void testRestoreExistingKey() {
super.testRestoreExistingKey();

View File

@@ -34,9 +34,8 @@ import redis.clients.jedis.BinaryJedisPubSub;
/**
* Unit test of {@link JedisSubscription}
*
*
* @author Jennifer Hickey
*
*/
public class JedisSubscriptionTests {

View File

@@ -45,10 +45,9 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
/**
* Integration test of {@link JredisConnection}
*
*
* @author Costin Leau
* @author Jennifer Hickey
*
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration
@@ -69,32 +68,25 @@ public class JRedisConnectionIntegrationTests extends AbstractConnectionIntegrat
}
@Ignore("Pub/Sub not supported")
public void testPubSubWithPatterns() {
}
public void testPubSubWithPatterns() {}
@Ignore("Pub/Sub not supported")
public void testPubSubWithNamedChannels() {
}
public void testPubSubWithNamedChannels() {}
@Ignore("https://github.com/alphazero/jredis/issues/64 Protocol error: expected '$' got '*' on mset")
public void testMSet() {
}
public void testMSet() {}
@Ignore("https://github.com/alphazero/jredis/issues/64 Protocol error: expected '$' got '*' on mset")
public void testMSetNx() {
}
public void testMSetNx() {}
@Ignore("https://github.com/alphazero/jredis/issues/64 Protocol error: expected '$' got '*' on mset")
public void testMSetNxFailure() {
}
public void testMSetNxFailure() {}
@Ignore("JRedis casts to int")
public void testIncrDecrByLong() {
}
public void testIncrDecrByLong() {}
@Ignore("Ping returns status response instead of value response")
public void testExecuteNoArgs() {
}
public void testExecuteNoArgs() {}
@Test
public void testConnectionClosesWhenNotPooled() {
@@ -102,14 +94,13 @@ public class JRedisConnectionIntegrationTests extends AbstractConnectionIntegrat
try {
connection.ping();
fail("Expected RedisConnectionFailureException trying to use a closed connection");
} catch (RedisConnectionFailureException e) {
}
} catch (RedisConnectionFailureException e) {}
}
@Test
public void testConnectionStaysOpenWhenPooled() {
JredisConnectionFactory factory2 = new JredisConnectionFactory(new JredisPool(
SettingsUtils.getHost(), SettingsUtils.getPort()));
JredisConnectionFactory factory2 = new JredisConnectionFactory(new JredisPool(SettingsUtils.getHost(),
SettingsUtils.getPort()));
RedisConnection conn2 = factory2.getConnection();
conn2.close();
conn2.ping();
@@ -120,15 +111,14 @@ public class JRedisConnectionIntegrationTests extends AbstractConnectionIntegrat
Config config = new Config();
config.maxActive = 1;
config.maxWait = 1;
JredisConnectionFactory factory2 = new JredisConnectionFactory(new JredisPool(
SettingsUtils.getHost(), SettingsUtils.getPort(), config));
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) {
}
} catch (RedisConnectionFailureException e) {}
conn2.close();
// Verify we get a new connection from the pool and not the broken one
RedisConnection conn3 = factory2.getConnection();
@@ -160,12 +150,12 @@ public class JRedisConnectionIntegrationTests extends AbstractConnectionIntegrat
super.testUnwatch();
}
@Test(expected=UnsupportedOperationException.class)
@Test(expected = UnsupportedOperationException.class)
public void testErrorInTx() {
super.testErrorInTx();
}
@Test(expected=UnsupportedOperationException.class)
@Test(expected = UnsupportedOperationException.class)
public void testExecWithoutMulti() {
super.testExecWithoutMulti();
}
@@ -319,285 +309,285 @@ public class JRedisConnectionIntegrationTests extends AbstractConnectionIntegrat
public void testZRevRangeByScoreWithScoresOffsetCount() {
super.testZRevRangeByScoreWithScoresOffsetCount();
}
@Test(expected = UnsupportedOperationException.class)
public void testSelect() {
super.testSelect();
}
@Test(expected=UnsupportedOperationException.class)
@Test(expected = UnsupportedOperationException.class)
public void testPExpire() {
super.testPExpire();
}
@Test(expected=UnsupportedOperationException.class)
@Test(expected = UnsupportedOperationException.class)
public void testPExpireKeyNotExists() {
super.testPExpireKeyNotExists();
}
@Test(expected=UnsupportedOperationException.class)
@Test(expected = UnsupportedOperationException.class)
public void testPExpireAt() {
super.testPExpireAt();
}
@Test(expected=UnsupportedOperationException.class)
@Test(expected = UnsupportedOperationException.class)
public void testPExpireAtKeyNotExists() {
super.testPExpireAtKeyNotExists();
}
@Test(expected=UnsupportedOperationException.class)
@Test(expected = UnsupportedOperationException.class)
public void testPTtl() {
super.testPTtl();
}
@Test(expected=UnsupportedOperationException.class)
@Test(expected = UnsupportedOperationException.class)
public void testPTtlNoExpire() {
super.testPTtlNoExpire();
}
@Test(expected=UnsupportedOperationException.class)
@Test(expected = UnsupportedOperationException.class)
public void testDumpAndRestore() {
super.testDumpAndRestore();
}
@Test(expected=UnsupportedOperationException.class)
@Test(expected = UnsupportedOperationException.class)
public void testDumpNonExistentKey() {
super.testDumpNonExistentKey();
}
@Test(expected=UnsupportedOperationException.class)
@Test(expected = UnsupportedOperationException.class)
public void testRestoreBadData() {
super.testRestoreBadData();
}
@Test(expected=UnsupportedOperationException.class)
@Test(expected = UnsupportedOperationException.class)
public void testRestoreExistingKey() {
super.testRestoreExistingKey();
}
@Test(expected=UnsupportedOperationException.class)
@Test(expected = UnsupportedOperationException.class)
public void testRestoreTtl() {
super.testRestoreTtl();
}
@Test(expected=UnsupportedOperationException.class)
@Test(expected = UnsupportedOperationException.class)
public void testBitCount() {
super.testBitCount();
}
@Test(expected=UnsupportedOperationException.class)
@Test(expected = UnsupportedOperationException.class)
public void testBitCountInterval() {
super.testBitCountInterval();
}
@Test(expected=UnsupportedOperationException.class)
@Test(expected = UnsupportedOperationException.class)
public void testBitCountNonExistentKey() {
super.testBitCountNonExistentKey();
}
@Test(expected=UnsupportedOperationException.class)
@Test(expected = UnsupportedOperationException.class)
public void testBitOpAnd() {
super.testBitOpAnd();
}
@Test(expected=UnsupportedOperationException.class)
@Test(expected = UnsupportedOperationException.class)
public void testBitOpOr() {
super.testBitOpOr();
}
@Test(expected=UnsupportedOperationException.class)
@Test(expected = UnsupportedOperationException.class)
public void testBitOpXOr() {
super.testBitOpXOr();
}
@Test(expected=UnsupportedOperationException.class)
@Test(expected = UnsupportedOperationException.class)
public void testBitOpNot() {
super.testBitOpNot();
}
@Test(expected=UnsupportedOperationException.class)
@Test(expected = UnsupportedOperationException.class)
public void testHIncrByDouble() {
super.testHIncrByDouble();
}
@Test(expected=UnsupportedOperationException.class)
@Test(expected = UnsupportedOperationException.class)
public void testHashIncrDecrByLong() {
super.testHashIncrDecrByLong();
}
@Test(expected=UnsupportedOperationException.class)
@Test(expected = UnsupportedOperationException.class)
public void testIncrByDouble() {
super.testIncrByDouble();
}
@Test(expected=UnsupportedOperationException.class)
@Test(expected = UnsupportedOperationException.class)
@IfProfileValue(name = "redisVersion", value = "2.6")
public void testScriptLoadEvalSha() {
super.testScriptLoadEvalSha();
}
@Test(expected=UnsupportedOperationException.class)
@Test(expected = UnsupportedOperationException.class)
@IfProfileValue(name = "redisVersion", value = "2.6")
public void testEvalShaArrayStrings() {
super.testEvalShaArrayStrings();
}
@Test(expected=UnsupportedOperationException.class)
@Test(expected = UnsupportedOperationException.class)
@IfProfileValue(name = "redisVersion", value = "2.6")
public void testEvalShaNotFound() {
super.testEvalShaNotFound();
}
@Test(expected=UnsupportedOperationException.class)
@Test(expected = UnsupportedOperationException.class)
@IfProfileValue(name = "redisVersion", value = "2.6")
public void testEvalShaArrayError() {
super.testEvalShaArrayError();
}
@Test(expected=UnsupportedOperationException.class)
@Test(expected = UnsupportedOperationException.class)
@IfProfileValue(name = "redisVersion", value = "2.6")
public void testEvalArrayScriptError() {
super.testEvalArrayScriptError();
}
@Test(expected=UnsupportedOperationException.class)
@Test(expected = UnsupportedOperationException.class)
@IfProfileValue(name = "redisVersion", value = "2.6")
public void testEvalReturnString() {
super.testEvalReturnString();
}
@Test(expected=UnsupportedOperationException.class)
@Test(expected = UnsupportedOperationException.class)
@IfProfileValue(name = "redisVersion", value = "2.6")
public void testEvalReturnNumber() {
super.testEvalReturnNumber();
}
@Test(expected=UnsupportedOperationException.class)
@Test(expected = UnsupportedOperationException.class)
@IfProfileValue(name = "redisVersion", value = "2.6")
public void testEvalReturnSingleOK() {
super.testEvalReturnSingleOK();
}
@Test(expected=UnsupportedOperationException.class)
@Test(expected = UnsupportedOperationException.class)
@IfProfileValue(name = "redisVersion", value = "2.6")
public void testEvalReturnSingleError() {
super.testEvalReturnSingleError();
}
@Test(expected=UnsupportedOperationException.class)
@Test(expected = UnsupportedOperationException.class)
@IfProfileValue(name = "redisVersion", value = "2.6")
public void testEvalReturnFalse() {
super.testEvalReturnFalse();
}
@Test(expected=UnsupportedOperationException.class)
@Test(expected = UnsupportedOperationException.class)
@IfProfileValue(name = "redisVersion", value = "2.6")
public void testEvalReturnTrue() {
super.testEvalReturnTrue();
}
@Test(expected=UnsupportedOperationException.class)
@Test(expected = UnsupportedOperationException.class)
@IfProfileValue(name = "redisVersion", value = "2.6")
public void testEvalReturnArrayStrings() {
super.testEvalReturnArrayStrings();
}
@Test(expected=UnsupportedOperationException.class)
@Test(expected = UnsupportedOperationException.class)
@IfProfileValue(name = "redisVersion", value = "2.6")
public void testEvalReturnArrayNumbers() {
super.testEvalReturnArrayNumbers();
}
@Test(expected=UnsupportedOperationException.class)
@Test(expected = UnsupportedOperationException.class)
@IfProfileValue(name = "redisVersion", value = "2.6")
public void testEvalReturnArrayOKs() {
super.testEvalReturnArrayOKs();
}
@Test(expected=UnsupportedOperationException.class)
@Test(expected = UnsupportedOperationException.class)
@IfProfileValue(name = "redisVersion", value = "2.6")
public void testEvalReturnArrayFalses() {
super.testEvalReturnArrayFalses();
}
@Test(expected=UnsupportedOperationException.class)
@Test(expected = UnsupportedOperationException.class)
@IfProfileValue(name = "redisVersion", value = "2.6")
public void testEvalReturnArrayTrues() {
super.testEvalReturnArrayTrues();
}
@Test(expected=UnsupportedOperationException.class)
@Test(expected = UnsupportedOperationException.class)
@IfProfileValue(name = "redisVersion", value = "2.6")
public void testScriptExists() {
super.testScriptExists();
}
@Test(expected=UnsupportedOperationException.class)
public void testScriptKill() throws Exception{
@Test(expected = UnsupportedOperationException.class)
public void testScriptKill() throws Exception {
connection.scriptKill();
}
@Test(expected=UnsupportedOperationException.class)
@Test(expected = UnsupportedOperationException.class)
@IfProfileValue(name = "redisVersion", value = "2.6")
public void testScriptFlush() {
connection.scriptFlush();
}
@Test(expected=UnsupportedOperationException.class)
@Test(expected = UnsupportedOperationException.class)
@IfProfileValue(name = "redisVersion", value = "2.6")
public void testSRandMemberCount() {
super.testSRandMemberCount();
}
@Test(expected=UnsupportedOperationException.class)
@Test(expected = UnsupportedOperationException.class)
@IfProfileValue(name = "redisVersion", value = "2.6")
public void testSRandMemberCountKeyNotExists() {
super.testSRandMemberCountKeyNotExists();
}
@Test(expected=UnsupportedOperationException.class)
@Test(expected = UnsupportedOperationException.class)
@IfProfileValue(name = "redisVersion", value = "2.6")
public void testSRandMemberCountNegative() {
super.testSRandMemberCountNegative();
}
@Test(expected=UnsupportedOperationException.class)
@Test(expected = UnsupportedOperationException.class)
@IfProfileValue(name = "redisVersion", value = "2.6")
public void testInfoBySection() throws Exception {
super.testInfoBySection();
}
@Test(expected=UnsupportedOperationException.class)
@Test(expected = UnsupportedOperationException.class)
public void testHDelMultiple() {
super.testHDelMultiple();
}
@Test(expected=UnsupportedOperationException.class)
@Test(expected = UnsupportedOperationException.class)
public void testLPushMultiple() {
super.testLPushMultiple();
}
@Test(expected=UnsupportedOperationException.class)
@Test(expected = UnsupportedOperationException.class)
public void testRPushMultiple() {
super.testRPushMultiple();
}
@Test(expected=UnsupportedOperationException.class)
@Test(expected = UnsupportedOperationException.class)
public void testSAddMultiple() {
super.testSAddMultiple();
}
@Test(expected=UnsupportedOperationException.class)
@Test(expected = UnsupportedOperationException.class)
public void testSRemMultiple() {
super.testSRemMultiple();
}
@Test(expected=UnsupportedOperationException.class)
@Test(expected = UnsupportedOperationException.class)
public void testZAddMultiple() {
super.testZAddMultiple();
}
@Test(expected=UnsupportedOperationException.class)
@Test(expected = UnsupportedOperationException.class)
public void testZRemMultiple() {
super.testZRemMultiple();
}
@@ -674,8 +664,7 @@ public class JRedisConnectionIntegrationTests extends AbstractConnectionIntegrat
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));
assertEquals(Arrays.asList(new String[] { "hello", "cruel", "world" }), connection.lRange("PopList", 0, -1));
}
@Test
@@ -732,8 +721,8 @@ public class JRedisConnectionIntegrationTests extends AbstractConnectionIntegrat
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")) }));
verifyResults(Arrays
.asList(new Object[] { 1l, 1l, 1l, -1l, new HashSet<String>(Collections.singletonList("foo")) }));
}
@Test
@@ -744,8 +733,8 @@ public class JRedisConnectionIntegrationTests extends AbstractConnectionIntegrat
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")) }));
verifyResults(Arrays
.asList(new Object[] { 1l, 1l, 1l, -1l, new HashSet<String>(Collections.singletonList("bar")) }));
}
@Test
@@ -758,27 +747,27 @@ public class JRedisConnectionIntegrationTests extends AbstractConnectionIntegrat
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" })) }));
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}));
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"));
assertEquals("bar", conn2.get("foo"));
} finally {
if(conn2.exists("foo")) {
if (conn2.exists("foo")) {
conn2.del("foo");
}
conn2.close();
}
}
}
}

View File

@@ -34,7 +34,6 @@ import static org.junit.Assert.*;
*
* @author Jennifer Hickey
* @author Thomas Darimont
*
*/
public class JredisPoolTests {
@@ -44,8 +43,7 @@ public class JredisPoolTests {
@Before
public void setUp() {
this.connectionSpec = DefaultConnectionSpec.newSpec(SettingsUtils.getHost(), SettingsUtils.getPort(),
0, null);
this.connectionSpec = DefaultConnectionSpec.newSpec(SettingsUtils.getHost(), SettingsUtils.getPort(), 0, null);
}
@After
@@ -92,8 +90,7 @@ public class JredisPoolTests {
public void testGetResourceCreationUnsuccessful() {
// Config poolConfig = new Config();
// poolConfig.testOnBorrow = true;
this.pool = new JredisPool(DefaultConnectionSpec.newSpec(SettingsUtils.getHost(), 3333, 0,
null));
this.pool = new JredisPool(DefaultConnectionSpec.newSpec(SettingsUtils.getHost(), 3333, 0, null));
pool.getResource();
}
@@ -123,8 +120,7 @@ public class JredisPoolTests {
try {
client.ping();
fail("Broken resouce connection should be closed");
} catch (NotConnectedException e) {
}
} catch (NotConnectedException e) {}
}
@Test

View File

@@ -26,12 +26,10 @@ import org.junit.Ignore;
import org.junit.Test;
/**
* Integration test of {@link AuthenticatingRedisClient}. Enable requirepass and
* comment out the @Ignore to run.
* Integration test of {@link AuthenticatingRedisClient}. Enable requirepass and comment out the @Ignore to run.
*
* @author Jennifer Hickey
* @author Thomas Darimont
*
*/
@Ignore("Redis must have requirepass set to run this test")
public class AuthenticatingRedisClientTests {
@@ -43,26 +41,26 @@ public class AuthenticatingRedisClientTests {
client = new AuthenticatingRedisClient("localhost", "foo");
}
@After
public void tearDown(){
if(client != null){
client.shutdown();
}
}
@After
public void tearDown() {
if (client != null) {
client.shutdown();
}
}
@Test
public void connect() {
RedisConnection<String, String> conn = client.connect();
conn.ping();
conn.close();
conn.close();
}
@Test(expected = RedisException.class)
public void connectWithInvalidPassword() {
if(client != null){
client.shutdown();
}
if (client != null) {
client.shutdown();
}
RedisClient badClient = new AuthenticatingRedisClient("localhost", "notthepassword");
badClient.connect();
@@ -72,35 +70,35 @@ public class AuthenticatingRedisClientTests {
public void codecConnect() {
RedisConnection<byte[], byte[]> conn = client.connect(LettuceConnection.CODEC);
conn.ping();
conn.close();
conn.close();
}
@Test
public void connectAsync() {
RedisAsyncConnection<String, String> conn = client.connectAsync();
conn.ping();
conn.close();
conn.close();
}
@Test
public void codecConnectAsync() {
RedisAsyncConnection<byte[], byte[]> conn = client.connectAsync(LettuceConnection.CODEC);
conn.ping();
conn.close();
conn.close();
}
@Test
public void connectPubSub() {
RedisPubSubConnection<String, String> conn = client.connectPubSub();
conn.ping();
conn.close();
conn.close();
}
@Test
public void codecConnectPubSub() {
RedisPubSubConnection<byte[], byte[]> conn = client.connectPubSub(LettuceConnection.CODEC);
conn.ping();
conn.close();
conn.close();
}
}

View File

@@ -29,23 +29,21 @@ import static org.junit.Assert.*;
/**
* Unit test of {@link DefaultLettucePool}
*
*
* @author Jennifer Hickey
* @author Thomas Darimont
*
*/
public class
DefaultLettucePoolTests {
public class DefaultLettucePoolTests {
private DefaultLettucePool pool;
@After
public void tearDown() {
if(this.pool != null) {
if (this.pool != null) {
if(this.pool.getClient() != null){
this.pool.getClient().shutdown();
}
if (this.pool.getClient() != null) {
this.pool.getClient().shutdown();
}
this.pool.destroy();
}
@@ -58,7 +56,7 @@ public class
RedisAsyncConnection<byte[], byte[]> client = pool.getResource();
assertNotNull(client);
client.ping();
client.close();
client.close();
}
@Test
@@ -73,10 +71,9 @@ public class
try {
pool.getResource();
fail("PoolException should be thrown when pool exhausted");
} catch (PoolException e) {
}finally{
client.close();
}
} catch (PoolException e) {} finally {
client.close();
}
}
@Test
@@ -87,7 +84,7 @@ public class
pool.afterPropertiesSet();
RedisAsyncConnection<byte[], byte[]> client = pool.getResource();
assertNotNull(client);
client.close();
client.close();
}
@Test(expected = PoolException.class)
@@ -108,7 +105,7 @@ public class
assertNotNull(client);
pool.returnResource(client);
assertNotNull(pool.getResource());
client.close();
client.close();
}
@Test
@@ -126,11 +123,10 @@ public class
try {
client.ping();
fail("Broken resouce connection should be closed");
} catch (RedisException e) {
} finally{
client.close();
client2.close();
}
} catch (RedisException e) {} finally {
client.close();
client2.close();
}
}
@Test
@@ -165,7 +161,7 @@ public class
pool.afterPropertiesSet();
RedisAsyncConnection<byte[], byte[]> conn = pool.getResource();
conn.ping();
conn.close();
conn.close();
}
@Ignore("Redis must have requirepass set to run this test")

View File

@@ -32,10 +32,9 @@ import static org.junit.Assert.*;
/**
* Integration test of {@link LettuceConnectionFactory}
*
*
* @author Jennifer Hickey
* @author Thomas Darimont
*
*/
public class LettuceConnectionFactoryTests {
@@ -54,9 +53,9 @@ public class LettuceConnectionFactoryTests {
public void tearDown() {
factory.destroy();
if(connection != null){
connection.close();
}
if (connection != null) {
connection.close();
}
}
@SuppressWarnings("rawtypes")
@@ -75,12 +74,11 @@ public class LettuceConnectionFactoryTests {
} catch (RedisSystemException e) {
// expected, shared conn is closed
}
DefaultStringRedisConnection conn2 = new DefaultStringRedisConnection(
factory.getConnection());
DefaultStringRedisConnection conn2 = new DefaultStringRedisConnection(factory.getConnection());
assertNotSame(nativeConn, conn2.getNativeConnection());
conn2.set("anotherkey", "anothervalue");
assertEquals("anothervalue", conn2.get("anotherkey"));
conn2.close();
conn2.close();
}
@SuppressWarnings("rawtypes")
@@ -90,16 +88,15 @@ public class LettuceConnectionFactoryTests {
((RedisAsyncConnection) connection.getNativeConnection()).close();
// Give some time for async channel close
Thread.sleep(500);
DefaultStringRedisConnection conn2 = new DefaultStringRedisConnection(
factory.getConnection());
DefaultStringRedisConnection conn2 = new DefaultStringRedisConnection(factory.getConnection());
try {
conn2.set("anotherkey", "anothervalue");
fail("Expected exception using natively closed conn");
} catch (RedisSystemException e) {
// expected, as we are re-using the natively closed conn
}finally{
conn2.close();
}
} finally {
conn2.close();
}
}
@Test
@@ -111,12 +108,10 @@ public class LettuceConnectionFactoryTests {
@Test
public void testSelectDb() {
LettuceConnectionFactory factory2 = new LettuceConnectionFactory(SettingsUtils.getHost(),
SettingsUtils.getPort());
LettuceConnectionFactory factory2 = new LettuceConnectionFactory(SettingsUtils.getHost(), SettingsUtils.getPort());
factory2.setDatabase(1);
factory2.afterPropertiesSet();
StringRedisConnection connection2 = new DefaultStringRedisConnection(
factory2.getConnection());
StringRedisConnection connection2 = new DefaultStringRedisConnection(factory2.getConnection());
connection2.flushDb();
// put an item in database 0
connection.set("sometestkey", "sometestvalue");
@@ -124,7 +119,7 @@ public class LettuceConnectionFactoryTests {
// there should still be nothing in database 1
assertEquals(Long.valueOf(0), connection2.dbSize());
} finally {
connection2.close();
connection2.close();
factory2.destroy();
}
}
@@ -156,7 +151,7 @@ public class LettuceConnectionFactoryTests {
.getNativeConnection();
factory.resetConnection();
assertNotSame(nativeConn, factory.getConnection().getNativeConnection());
nativeConn.close();
nativeConn.close();
}
@SuppressWarnings("unchecked")
@@ -165,9 +160,9 @@ public class LettuceConnectionFactoryTests {
RedisAsyncConnection<byte[], byte[]> nativeConn = (RedisAsyncConnection<byte[], byte[]>) connection
.getNativeConnection();
factory.initConnection();
RedisConnection newConnection = factory.getConnection();
assertNotSame(nativeConn, newConnection.getNativeConnection());
newConnection.close();
RedisConnection newConnection = factory.getConnection();
assertNotSame(nativeConn, newConnection.getNativeConnection());
newConnection.close();
}
@SuppressWarnings("unchecked")
@@ -177,9 +172,9 @@ public class LettuceConnectionFactoryTests {
.getNativeConnection();
factory.resetConnection();
factory.initConnection();
RedisConnection newConnection = factory.getConnection();
assertNotSame(nativeConn, newConnection.getNativeConnection());
newConnection.close();
RedisConnection newConnection = factory.getConnection();
assertNotSame(nativeConn, newConnection.getNativeConnection());
newConnection.close();
}
public void testGetConnectionException() {
@@ -188,8 +183,7 @@ public class LettuceConnectionFactoryTests {
try {
factory.getConnection();
fail("Expected connection failure exception");
} catch(RedisConnectionFailureException e) {
}
} catch (RedisConnectionFailureException e) {}
}
@Test
@@ -210,26 +204,26 @@ public class LettuceConnectionFactoryTests {
@Test
public void testCreateFactoryWithPool() {
DefaultLettucePool pool = new DefaultLettucePool(SettingsUtils.getHost(),
SettingsUtils.getPort());
DefaultLettucePool pool = new DefaultLettucePool(SettingsUtils.getHost(), SettingsUtils.getPort());
pool.afterPropertiesSet();
LettuceConnectionFactory factory2 = new LettuceConnectionFactory(pool);
factory2.afterPropertiesSet();
RedisConnection conn2 = factory2.getConnection();
conn2.close();
factory2.destroy();
pool.destroy();
RedisConnection conn2 = factory2.getConnection();
conn2.close();
factory2.destroy();
pool.destroy();
}
@Ignore("Uncomment this test to manually check connection reuse in a pool scenario")
@Test
public void testLotsOfConnections() throws InterruptedException {
// Running a netstat here should show only the 8 conns from the pool (plus 2 from setUp and 1 from factory2 afterPropertiesSet for shared conn)
// Running a netstat here should show only the 8 conns from the pool (plus 2 from setUp and 1 from factory2
// afterPropertiesSet for shared conn)
DefaultLettucePool pool = new DefaultLettucePool(SettingsUtils.getHost(), SettingsUtils.getPort());
pool.afterPropertiesSet();
final LettuceConnectionFactory factory2 = new LettuceConnectionFactory(pool);
factory2.afterPropertiesSet();
for(int i=1;i< 1000;i++) {
for (int i = 1; i < 1000; i++) {
Thread th = new Thread(new Runnable() {
public void run() {
factory2.getConnection().bRPop(50000, "foo".getBytes());
@@ -249,6 +243,6 @@ public class LettuceConnectionFactoryTests {
// Test shared and dedicated conns
conn.ping();
conn.bLPop(1, "key".getBytes());
conn.close();
conn.close();
}
}

View File

@@ -42,11 +42,10 @@ import static org.springframework.data.redis.SpinBarrier.waitFor;
/**
* Integration test of {@link LettuceConnection}
*
*
* @author Costin Leau
* @author Jennifer Hickey
* @author Thomas Darimont
*
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration
@@ -57,8 +56,7 @@ public class LettuceConnectionIntegrationTests extends AbstractConnectionIntegra
public void testMultiThreadsOneBlocking() throws Exception {
Thread th = new Thread(new Runnable() {
public void run() {
DefaultStringRedisConnection conn2 = new DefaultStringRedisConnection(
connectionFactory.getConnection());
DefaultStringRedisConnection conn2 = new DefaultStringRedisConnection(connectionFactory.getConnection());
conn2.openPipeline();
conn2.bLPop(3, "multilist");
conn2.closePipeline();
@@ -77,8 +75,7 @@ public class LettuceConnectionIntegrationTests extends AbstractConnectionIntegra
connection.set("txs1", "rightnow");
connection.multi();
connection.set("txs1", "delay");
DefaultStringRedisConnection conn2 = new DefaultStringRedisConnection(
connectionFactory.getConnection());
DefaultStringRedisConnection conn2 = new DefaultStringRedisConnection(connectionFactory.getConnection());
// We get immediate results executing command in separate conn (not part
// of tx)
@@ -91,8 +88,8 @@ public class LettuceConnectionIntegrationTests extends AbstractConnectionIntegra
// Now it should be set
assertEquals("delay", conn2.get("txs1"));
conn2.closePipeline();
conn2.close();
conn2.closePipeline();
conn2.close();
}
@Test
@@ -120,14 +117,12 @@ public class LettuceConnectionIntegrationTests extends AbstractConnectionIntegra
// can't do blocking ops after closing
connection.bLPop(1, "what".getBytes());
fail("Expected exception using a closed conn for dedicated ops");
}catch(RedisSystemException e) {
}
} catch (RedisSystemException e) {}
}
@Test
public void testClosePooledConnectionWithShared() {
DefaultLettucePool pool = new DefaultLettucePool(SettingsUtils.getHost(),
SettingsUtils.getPort());
DefaultLettucePool pool = new DefaultLettucePool(SettingsUtils.getHost(), SettingsUtils.getPort());
pool.afterPropertiesSet();
LettuceConnectionFactory factory2 = new LettuceConnectionFactory(pool);
factory2.afterPropertiesSet();
@@ -140,15 +135,14 @@ public class LettuceConnectionIntegrationTests extends AbstractConnectionIntegra
// The dedicated connection should not be closed b/c it's part of a pool
connection.multi();
connection.close();
connection.close();
factory2.destroy();
pool.destroy();
pool.destroy();
}
@Test
public void testClosePooledConnectionNotShared() {
DefaultLettucePool pool = new DefaultLettucePool(SettingsUtils.getHost(),
SettingsUtils.getPort());
DefaultLettucePool pool = new DefaultLettucePool(SettingsUtils.getHost(), SettingsUtils.getPort());
pool.afterPropertiesSet();
LettuceConnectionFactory factory2 = new LettuceConnectionFactory(pool);
factory2.setShareNativeConnection(false);
@@ -160,13 +154,13 @@ public class LettuceConnectionIntegrationTests extends AbstractConnectionIntegra
// The dedicated connection should not be closed
connection.ping();
connection.close();
connection.close();
factory2.destroy();
pool.destroy();
pool.destroy();
}
@Test
public void testCloseNonPooledConnectionNotShared() {
public void testCloseNonPooledConnectionNotShared() {
LettuceConnectionFactory factory2 = new LettuceConnectionFactory(SettingsUtils.getHost(), SettingsUtils.getPort());
factory2.setShareNativeConnection(false);
factory2.afterPropertiesSet();
@@ -178,16 +172,14 @@ public class LettuceConnectionIntegrationTests extends AbstractConnectionIntegra
try {
connection.set("foo".getBytes(), "bar".getBytes());
fail("Exception should be thrown trying to use a closed connection");
}catch(RedisSystemException e) {
}
} catch (RedisSystemException e) {}
factory2.destroy();
}
@SuppressWarnings("rawtypes")
@Test
public void testCloseReturnBrokenResourceToPool() {
DefaultLettucePool pool = new DefaultLettucePool(SettingsUtils.getHost(),
SettingsUtils.getPort());
DefaultLettucePool pool = new DefaultLettucePool(SettingsUtils.getHost(), SettingsUtils.getPort());
pool.afterPropertiesSet();
LettuceConnectionFactory factory2 = new LettuceConnectionFactory(pool);
factory2.setShareNativeConnection(false);
@@ -195,30 +187,28 @@ public class LettuceConnectionIntegrationTests extends AbstractConnectionIntegra
RedisConnection connection = factory2.getConnection();
// Use the connection to make sure the channel is initialized, else nothing happens on close
connection.ping();
((RedisAsyncConnection)connection.getNativeConnection()).close();
((RedisAsyncConnection) connection.getNativeConnection()).close();
try {
connection.ping();
fail("Exception should be thrown trying to use a closed connection");
}catch(RedisSystemException e) {
}
} catch (RedisSystemException e) {}
connection.close();
factory2.destroy();
pool.destroy();
pool.destroy();
}
@Test
public void testSelectNotShared() {
DefaultLettucePool pool = new DefaultLettucePool(SettingsUtils.getHost(),
SettingsUtils.getPort());
DefaultLettucePool pool = new DefaultLettucePool(SettingsUtils.getHost(), SettingsUtils.getPort());
pool.afterPropertiesSet();
LettuceConnectionFactory factory2 = new LettuceConnectionFactory(pool);
factory2.setShareNativeConnection(false);
factory2.afterPropertiesSet();
RedisConnection connection = factory2.getConnection();
connection.select(2);
connection.close();
connection.close();
factory2.destroy();
pool.destroy();
pool.destroy();
}
@Test(expected = UnsupportedOperationException.class)
@@ -226,7 +216,7 @@ public class LettuceConnectionIntegrationTests extends AbstractConnectionIntegra
super.testSelect();
}
@Test(expected=UnsupportedOperationException.class)
@Test(expected = UnsupportedOperationException.class)
@IfProfileValue(name = "redisVersion", value = "2.6")
public void testSRandMemberCountNegative() {
super.testSRandMemberCountNegative();
@@ -234,7 +224,7 @@ public class LettuceConnectionIntegrationTests extends AbstractConnectionIntegra
@Test
@IfProfileValue(name = "runLongTests", value = "true")
public void testScriptKill() throws Exception{
public void testScriptKill() throws Exception {
getResults();
assumeTrue(RedisVersionUtils.atLeast("2.6", byteConnection));
final AtomicBoolean scriptDead = new AtomicBoolean(false);
@@ -244,15 +234,14 @@ public class LettuceConnectionIntegrationTests extends AbstractConnectionIntegra
final LettuceConnectionFactory factory2 = new LettuceConnectionFactory(SettingsUtils.getHost(),
SettingsUtils.getPort());
factory2.afterPropertiesSet();
DefaultStringRedisConnection conn2 = new DefaultStringRedisConnection(
factory2.getConnection());
DefaultStringRedisConnection conn2 = new DefaultStringRedisConnection(factory2.getConnection());
try {
conn2.eval("local time=1 while time < 10000000000 do time=time+1 end", ReturnType.BOOLEAN, 0);
}catch(DataAccessException e) {
} catch (DataAccessException e) {
scriptDead.set(true);
}
conn2.close();
factory2.destroy();
factory2.destroy();
}
});
th.start();
@@ -269,20 +258,20 @@ public class LettuceConnectionIntegrationTests extends AbstractConnectionIntegra
public void testMove() {
connection.set("foo", "bar");
actual.add(connection.move("foo", 1));
verifyResults(Arrays.asList(new Object[] { true}));
verifyResults(Arrays.asList(new Object[] { true }));
// Lettuce does not support select when using shared conn, use a new conn factory
LettuceConnectionFactory factory2 = new LettuceConnectionFactory();
factory2.setDatabase(1);
factory2.afterPropertiesSet();
StringRedisConnection conn2 = new DefaultStringRedisConnection(factory2.getConnection());
try {
assertEquals("bar",conn2.get("foo"));
assertEquals("bar", conn2.get("foo"));
} finally {
if(conn2.exists("foo")) {
if (conn2.exists("foo")) {
conn2.del("foo");
}
conn2.close();
factory2.destroy();
factory2.destroy();
}
}
}
}

View File

@@ -39,22 +39,20 @@ import static org.springframework.data.redis.SpinBarrier.waitFor;
/**
* Integration test of {@link LettuceConnection} pipeline functionality
*
*
* @author Jennifer Hickey
* @author Thomas Darimont
*
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("LettuceConnectionIntegrationTests-context.xml")
public class LettuceConnectionPipelineIntegrationTests extends
AbstractConnectionPipelineIntegrationTests {
@Test(expected=UnsupportedOperationException.class)
public class LettuceConnectionPipelineIntegrationTests extends AbstractConnectionPipelineIntegrationTests {
@Test(expected = UnsupportedOperationException.class)
public void testSelect() {
super.testSelect();
}
@Test(expected=UnsupportedOperationException.class)
@Test(expected = UnsupportedOperationException.class)
@IfProfileValue(name = "redisVersion", value = "2.6")
public void testSRandMemberCountNegative() {
super.testSRandMemberCountNegative();
@@ -62,7 +60,7 @@ public class LettuceConnectionPipelineIntegrationTests extends
@Test
@IfProfileValue(name = "runLongTests", value = "true")
public void testScriptKill() throws Exception{
public void testScriptKill() throws Exception {
getResults();
assumeTrue(RedisVersionUtils.atLeast("2.6", byteConnection));
initConnection();
@@ -73,15 +71,14 @@ public class LettuceConnectionPipelineIntegrationTests extends
final LettuceConnectionFactory factory2 = new LettuceConnectionFactory(SettingsUtils.getHost(),
SettingsUtils.getPort());
factory2.afterPropertiesSet();
DefaultStringRedisConnection conn2 = new DefaultStringRedisConnection(
factory2.getConnection());
DefaultStringRedisConnection conn2 = new DefaultStringRedisConnection(factory2.getConnection());
try {
conn2.eval("local time=1 while time < 10000000000 do time=time+1 end", ReturnType.BOOLEAN, 0);
}catch(DataAccessException e) {
} catch (DataAccessException e) {
scriptDead.set(true);
}
conn2.close();
factory2.destroy();
factory2.destroy();
}
});
th.start();
@@ -99,20 +96,20 @@ public class LettuceConnectionPipelineIntegrationTests extends
public void testMove() {
connection.set("foo", "bar");
actual.add(connection.move("foo", 1));
verifyResults(Arrays.asList(new Object[] { true}));
verifyResults(Arrays.asList(new Object[] { true }));
// Lettuce does not support select when using shared conn, use a new conn factory
LettuceConnectionFactory factory2 = new LettuceConnectionFactory();
factory2.setDatabase(1);
factory2.afterPropertiesSet();
StringRedisConnection conn2 = new DefaultStringRedisConnection(factory2.getConnection());
try {
assertEquals("bar",conn2.get("foo"));
assertEquals("bar", conn2.get("foo"));
} finally {
if(conn2.exists("foo")) {
if (conn2.exists("foo")) {
conn2.del("foo");
}
conn2.close();
factory2.destroy();
factory2.destroy();
}
}
}

View File

@@ -11,12 +11,10 @@ import org.springframework.test.annotation.IfProfileValue;
/**
* Integration test of {@link LettuceConnection} transactions within a pipeline
*
*
* @author Jennifer Hickey
*
*/
public class LettuceConnectionPipelineTxIntegrationTests extends
LettuceConnectionTransactionIntegrationTests {
public class LettuceConnectionPipelineTxIntegrationTests extends LettuceConnectionTransactionIntegrationTests {
@Test(expected = RedisPipelineException.class)
@IfProfileValue(name = "redisVersion", value = "2.6")
@@ -42,13 +40,13 @@ public class LettuceConnectionPipelineTxIntegrationTests extends
super.testRestoreExistingKey();
}
@Test(expected=RedisPipelineException.class)
@Test(expected = RedisPipelineException.class)
@IfProfileValue(name = "redisVersion", value = "2.6")
public void testEvalArrayScriptError() {
super.testEvalArrayScriptError();
}
@Test(expected=RedisPipelineException.class)
@Test(expected = RedisPipelineException.class)
@IfProfileValue(name = "redisVersion", value = "2.6")
public void testEvalShaArrayError() {
super.testEvalShaArrayError();
@@ -64,8 +62,8 @@ public class LettuceConnectionPipelineTxIntegrationTests extends
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);
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

@@ -30,22 +30,18 @@ import java.util.Arrays;
import static org.junit.Assert.assertEquals;
/**
* Integration test of {@link LettuceConnection} functionality within a
* transaction
*
* Integration test of {@link LettuceConnection} functionality within a transaction
*
* @author Jennifer Hickey
* @author Thomas Darimont
*
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("LettuceConnectionIntegrationTests-context.xml")
public class LettuceConnectionTransactionIntegrationTests extends
AbstractConnectionTransactionIntegrationTests {
public class LettuceConnectionTransactionIntegrationTests extends AbstractConnectionTransactionIntegrationTests {
@Test
@Ignore("DATAREDIS-226 Exceptions on native execute are swallowed in tx")
public void exceptionExecuteNative() throws Exception {
}
public void exceptionExecuteNative() throws Exception {}
@Test(expected = UnsupportedOperationException.class)
@IfProfileValue(name = "redisVersion", value = "2.6")
@@ -57,24 +53,24 @@ public class LettuceConnectionTransactionIntegrationTests extends
public void testMove() {
connection.set("foo", "bar");
actual.add(connection.move("foo", 1));
verifyResults(Arrays.asList(new Object[] { true}));
verifyResults(Arrays.asList(new Object[] { true }));
// Lettuce does not support select when using shared conn, use a new conn factory
LettuceConnectionFactory factory2 = new LettuceConnectionFactory();
factory2.setDatabase(1);
factory2.afterPropertiesSet();
StringRedisConnection conn2 = new DefaultStringRedisConnection(factory2.getConnection());
try {
assertEquals("bar",conn2.get("foo"));
assertEquals("bar", conn2.get("foo"));
} finally {
if(conn2.exists("foo")) {
if (conn2.exists("foo")) {
conn2.del("foo");
}
conn2.close();
factory2.destroy();
factory2.destroy();
}
}
@Test(expected=UnsupportedOperationException.class)
@Test(expected = UnsupportedOperationException.class)
public void testSelect() {
super.testSelect();
}

View File

@@ -35,9 +35,8 @@ import com.lambdaworks.redis.pubsub.RedisPubSubConnection;
/**
* Unit test of {@link LettuceSubscription}
*
*
* @author Jennifer Hickey
*
*/
public class LettuceSubscriptionTests {

View File

@@ -24,16 +24,14 @@ 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());
SrpConnectionFactory factory = new SrpConnectionFactory(SettingsUtils.getHost(), SettingsUtils.getPort());
factory.afterPropertiesSet();
RedisConnection connection = factory.getConnection();
connection.ping();
@@ -47,15 +45,13 @@ public class SrpConnectionFactoryTests {
try {
factory.getConnection();
fail("Expected a connection failure exception");
} catch(RedisConnectionFailureException e) {
}
} 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());
SrpConnectionFactory factory = new SrpConnectionFactory(SettingsUtils.getHost(), SettingsUtils.getPort());
factory.setPassword("foob");
factory.afterPropertiesSet();
RedisConnection connection = factory.getConnection();

View File

@@ -29,10 +29,9 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
/**
* Integration test of {@link SrpConnection}
*
*
* @author Costin Leau
* @author Jennifer Hickey
*
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration
@@ -74,6 +73,6 @@ public class SrpConnectionIntegrationTests extends AbstractConnectionIntegration
// 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"} )}));
verifyResults(Arrays.asList(new Object[] { Arrays.asList(new Object[] { "OK", "OK" }) }));
}
}

View File

@@ -28,27 +28,24 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
/**
* Integration test of {@link SrpConnection} pipeline functionality
*
*
* @author Jennifer Hickey
*
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("SrpConnectionIntegrationTests-context.xml")
public class SrpConnectionPipelineIntegrationTests extends
AbstractConnectionPipelineIntegrationTests {
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')}",
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)
@Test(expected = RedisSystemException.class)
public void testExecWithoutMulti() {
connection.exec();
// SRP throws an Exception right away on exec instead of once pipeline is closed

View File

@@ -28,9 +28,8 @@ import org.springframework.test.annotation.IfProfileValue;
/**
* Integration test of {@link SrpConnection} transactions within a pipeline
*
*
* @author Jennifer Hickey
*
*/
public class SrpConnectionPipelineTxIntegrationTests extends SrpConnectionTransactionIntegrationTests {
@@ -40,7 +39,7 @@ public class SrpConnectionPipelineTxIntegrationTests extends SrpConnectionTransa
assertNull(connection.exec());
assertNull(connection.get("foo"));
List<Object> results = connection.closePipeline();
assertEquals(Arrays.asList(new Object[] {Collections.emptyList(), "bar"}), results);
assertEquals(Arrays.asList(new Object[] { Collections.emptyList(), "bar" }), results);
assertEquals("bar", connection.get("foo"));
}
@@ -55,17 +54,17 @@ public class SrpConnectionPipelineTxIntegrationTests extends SrpConnectionTransa
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));
assertEquals(Arrays.asList(new Object[] { "bar" }), results.get(0));
assertEquals(Arrays.asList(new Object[] { "baz" }), results.get(1));
}
@Test(expected=RedisPipelineException.class)
@Test(expected = RedisPipelineException.class)
@IfProfileValue(name = "redisVersion", value = "2.6")
public void testEvalShaNotFound() {
super.testEvalShaNotFound();
}
@Test(expected=RedisPipelineException.class)
@Test(expected = RedisPipelineException.class)
@IfProfileValue(name = "redisVersion", value = "2.6")
public void testEvalReturnSingleError() {
super.testEvalReturnSingleError();
@@ -83,13 +82,13 @@ public class SrpConnectionPipelineTxIntegrationTests extends SrpConnectionTransa
super.testRestoreBadData();
}
@Test(expected=RedisPipelineException.class)
@Test(expected = RedisPipelineException.class)
@IfProfileValue(name = "redisVersion", value = "2.6")
public void testEvalArrayScriptError() {
super.testEvalArrayScriptError();
}
@Test(expected=RedisPipelineException.class)
@Test(expected = RedisPipelineException.class)
@IfProfileValue(name = "redisVersion", value = "2.6")
public void testEvalShaArrayError() {
super.testEvalShaArrayError();
@@ -105,8 +104,8 @@ public class SrpConnectionPipelineTxIntegrationTests extends SrpConnectionTransa
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);
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

@@ -25,13 +25,10 @@ import org.springframework.test.annotation.IfProfileValue;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
/**
* Integration test of {@link SrpConnection} functionality within a transaction
*
*
* @author Jennifer Hickey
*
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("SrpConnectionIntegrationTests-context.xml")
@@ -43,7 +40,7 @@ public class SrpConnectionTransactionIntegrationTests extends AbstractConnection
// 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"} )}));
verifyResults(Arrays.asList(new Object[] { Arrays.asList(new Object[] { "OK", "OK" }) }));
}
@Test

View File

@@ -36,9 +36,8 @@ import redis.client.ReplyListener;
/**
* Unit test of {@link SrpSubscription}
*
*
* @author Jennifer Hickey
*
*/
public class SrpSubscriptionTests {

View File

@@ -27,56 +27,47 @@ import static org.junit.Assert.assertEquals;
/**
* Unit test of {@link SrpUtils}
*
*
* @author Jennifer Hickey
* @author Thomas Darimont
*
* Suppressed deprecation warnings since SrpUtils is deprecated.
* @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);
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" },
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());
SortParameters sortParams = new DefaultSortParameters().numeric().by("weight_*".getBytes());
Object[] sort = SrpUtils.sortParams(sortParams);
assertArrayEquals(new String[] { "BY", "weight_*" },
convertByteArrays(sort));
assertArrayEquals(new String[] { "BY", "weight_*" }, convertByteArrays(sort));
}
@Test
public void testSortParamsOnlyLimit() {
SortParameters sortParams = new DefaultSortParameters().numeric()
.limit(0, 5);
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());
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));
assertArrayEquals(new String[] { "GET", "foo", "GET", "bar" }, convertByteArrays(sort));
}
@Test
public void testSortParamsOnlyOrder() {
SortParameters sortParams = new DefaultSortParameters().numeric()
.desc();
SortParameters sortParams = new DefaultSortParameters().numeric().desc();
Object[] sort = SrpUtils.sortParams(sortParams);
assertArrayEquals(new String[] { "DESC" }, convertByteArrays(sort));
}
@@ -92,48 +83,41 @@ public class SrpUtilsTests {
public void testSortParamsOnlyStore() {
SortParameters sortParams = new DefaultSortParameters().numeric();
Object[] sort = SrpUtils.sortParams(sortParams, "storelist".getBytes());
assertArrayEquals(new String[] { "STORE", "storelist" },
convertByteArrays(sort));
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);
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));
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());
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);
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());
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();
SortParameters sortParams = new DefaultSortParameters().numeric().desc();
byte[] sort = SrpUtils.sort(sortParams);
assertEquals("DESC", new String(sort));
}

View File

@@ -46,7 +46,7 @@ abstract public class AbstractOperationsTestParams {
* @see DATAREDIS-241
*/
public static Collection<Object[]> testParams() {
ObjectFactory<String> stringFactory = new StringObjectFactory();
ObjectFactory<Long> longFactory = new LongObjectFactory();
ObjectFactory<Double> doubleFactory = new DoubleObjectFactory();

View File

@@ -39,16 +39,15 @@ import org.springframework.data.redis.connection.srp.SrpConnectionFactory;
/**
* Integration test of {@link DefaultHashOperations}
*
*
* @author Jennifer Hickey
*
* @param <K> Key type
* @param <HK> Hash key type
* @param <HV> Hash value type
*/
@RunWith(Parameterized.class)
public class DefaultHashOperationsTests<K,HK,HV> {
private RedisTemplate<K,?> redisTemplate;
public class DefaultHashOperationsTests<K, HK, HV> {
private RedisTemplate<K, ?> redisTemplate;
private ObjectFactory<K> keyFactory;
@@ -56,9 +55,9 @@ public class DefaultHashOperationsTests<K,HK,HV> {
private ObjectFactory<HV> hashValueFactory;
private HashOperations<K, HK,HV> hashOps;
private HashOperations<K, HK, HV> hashOps;
public DefaultHashOperationsTests(RedisTemplate<K,?> redisTemplate, ObjectFactory<K> keyFactory,
public DefaultHashOperationsTests(RedisTemplate<K, ?> redisTemplate, ObjectFactory<K> keyFactory,
ObjectFactory<HK> hashKeyFactory, ObjectFactory<HV> hashValueFactory) {
this.redisTemplate = redisTemplate;
this.keyFactory = keyFactory;
@@ -76,17 +75,17 @@ public class DefaultHashOperationsTests<K,HK,HV> {
srConnFactory.setHostName(SettingsUtils.getHost());
srConnFactory.afterPropertiesSet();
RedisTemplate<String,String> stringTemplate = new StringRedisTemplate();
RedisTemplate<String, String> stringTemplate = new StringRedisTemplate();
stringTemplate.setConnectionFactory(srConnFactory);
stringTemplate.afterPropertiesSet();
RedisTemplate<byte[],byte[]> rawTemplate = new RedisTemplate<byte[],byte[]>();
RedisTemplate<byte[], byte[]> rawTemplate = new RedisTemplate<byte[], byte[]>();
rawTemplate.setConnectionFactory(srConnFactory);
rawTemplate.setEnableDefaultSerializer(false);
rawTemplate.afterPropertiesSet();
return Arrays.asList(new Object[][] { { stringTemplate, stringFactory, stringFactory, stringFactory },
{ rawTemplate, rawFactory, rawFactory, rawFactory }});
{ rawTemplate, rawFactory, rawFactory, rawFactory } });
}
@Before
@@ -113,7 +112,7 @@ public class DefaultHashOperationsTests<K,HK,HV> {
HV val2 = hashValueFactory.instance();
hashOps.put(key, key1, val1);
hashOps.put(key, key2, val2);
Map<HK,HV> expected = new LinkedHashMap<HK,HV>();
Map<HK, HV> expected = new LinkedHashMap<HK, HV>();
expected.put(key1, val1);
expected.put(key2, val2);
assertThat(hashOps.entries(key), isEqual(expected));

View File

@@ -37,23 +37,23 @@ import org.springframework.data.redis.connection.RedisConnection;
/**
* Integration test of {@link DefaultListOperations}
*
* @author Jennifer Hickey
*
* @param <K> Key test
* @param <V> Value test
*/
@RunWith(Parameterized.class)
public class DefaultListOperationsTests<K,V> {
public class DefaultListOperationsTests<K, V> {
private RedisTemplate<K,V> redisTemplate;
private RedisTemplate<K, V> redisTemplate;
private ObjectFactory<K> keyFactory;
private ObjectFactory<V> valueFactory;
private ListOperations<K,V> listOps;
private ListOperations<K, V> listOps;
public DefaultListOperationsTests(RedisTemplate<K,V> redisTemplate, ObjectFactory<K> keyFactory,
public DefaultListOperationsTests(RedisTemplate<K, V> redisTemplate, ObjectFactory<K> keyFactory,
ObjectFactory<V> valueFactory) {
this.redisTemplate = redisTemplate;
this.keyFactory = keyFactory;
@@ -89,10 +89,10 @@ public class DefaultListOperationsTests<K,V> {
System.out.println("Value1" + v1);
System.out.println("Value2" + v2);
System.out.println("Value3" + v3);
assertEquals(Long.valueOf(1),listOps.leftPush(key, v1));
assertEquals(Long.valueOf(2),listOps.leftPush(key, v2));
assertEquals(Long.valueOf(1), listOps.leftPush(key, v1));
assertEquals(Long.valueOf(2), listOps.leftPush(key, v2));
assertEquals(Long.valueOf(3), listOps.leftPush(key, v1, v3));
assertThat(listOps.range(key, 0, -1), isEqual(Arrays.asList(new Object[] {v2, v3, v1})));
assertThat(listOps.range(key, 0, -1), isEqual(Arrays.asList(new Object[] { v2, v3, v1 })));
}
@Test
@@ -101,9 +101,9 @@ public class DefaultListOperationsTests<K,V> {
V v1 = valueFactory.instance();
V v2 = valueFactory.instance();
assertEquals(Long.valueOf(0), listOps.leftPushIfPresent(key, v1));
assertEquals(Long.valueOf(1),listOps.leftPush(key, v1));
assertEquals(Long.valueOf(2),listOps.leftPushIfPresent(key, v2));
assertThat(listOps.range(key, 0, -1), isEqual(Arrays.asList(new Object[] {v2, v1})));
assertEquals(Long.valueOf(1), listOps.leftPush(key, v1));
assertEquals(Long.valueOf(2), listOps.leftPushIfPresent(key, v2));
assertThat(listOps.range(key, 0, -1), isEqual(Arrays.asList(new Object[] { v2, v1 })));
}
@SuppressWarnings("unchecked")
@@ -113,9 +113,9 @@ public class DefaultListOperationsTests<K,V> {
V v1 = valueFactory.instance();
V v2 = valueFactory.instance();
V v3 = valueFactory.instance();
assertEquals(Long.valueOf(2),listOps.leftPushAll(key, v1, v2));
assertEquals(Long.valueOf(2), listOps.leftPushAll(key, v1, v2));
assertEquals(Long.valueOf(3), listOps.leftPush(key, v3));
assertThat(listOps.range(key, 0, -1), isEqual(Arrays.asList(new Object[] {v3, v2, v1})));
assertThat(listOps.range(key, 0, -1), isEqual(Arrays.asList(new Object[] { v3, v2, v1 })));
}
@Test
@@ -146,11 +146,10 @@ public class DefaultListOperationsTests<K,V> {
V v1 = valueFactory.instance();
V v2 = valueFactory.instance();
V v3 = valueFactory.instance();
assertEquals(Long.valueOf(1),listOps.rightPush(key, v1));
assertEquals(Long.valueOf(2),listOps.rightPush(key, v2));
assertEquals(Long.valueOf(1), listOps.rightPush(key, v1));
assertEquals(Long.valueOf(2), listOps.rightPush(key, v2));
assertEquals(Long.valueOf(3), listOps.rightPush(key, v1, v3));
assertThat(listOps.range(key, 0, -1),
isEqual(Arrays.asList(new Object[] {v1, v3, v2})));
assertThat(listOps.range(key, 0, -1), isEqual(Arrays.asList(new Object[] { v1, v3, v2 })));
}
@Test
@@ -159,10 +158,9 @@ public class DefaultListOperationsTests<K,V> {
V v1 = valueFactory.instance();
V v2 = valueFactory.instance();
assertEquals(Long.valueOf(0), listOps.rightPushIfPresent(key, v1));
assertEquals(Long.valueOf(1),listOps.rightPush(key, v1));
assertEquals(Long.valueOf(2),listOps.rightPushIfPresent(key, v2));
assertThat(listOps.range(key, 0, -1),
isEqual(Arrays.asList(new Object[] {v1, v2})));
assertEquals(Long.valueOf(1), listOps.rightPush(key, v1));
assertEquals(Long.valueOf(2), listOps.rightPushIfPresent(key, v2));
assertThat(listOps.range(key, 0, -1), isEqual(Arrays.asList(new Object[] { v1, v2 })));
}
@SuppressWarnings("unchecked")
@@ -172,9 +170,8 @@ public class DefaultListOperationsTests<K,V> {
V v1 = valueFactory.instance();
V v2 = valueFactory.instance();
V v3 = valueFactory.instance();
assertEquals(Long.valueOf(2),listOps.rightPushAll(key, v1, v2));
assertEquals(Long.valueOf(3),listOps.rightPush(key, v3));
assertThat(listOps.range(key, 0, -1),
isEqual(Arrays.asList(new Object[] {v1, v2, v3})));
assertEquals(Long.valueOf(2), listOps.rightPushAll(key, v1, v2));
assertEquals(Long.valueOf(3), listOps.rightPush(key, v3));
assertThat(listOps.range(key, 0, -1), isEqual(Arrays.asList(new Object[] { v1, v2, v3 })));
}
}
}

View File

@@ -45,20 +45,19 @@ import org.springframework.data.redis.connection.RedisConnection;
* Integration test of {@link DefaultSetOperations}
*
* @author Jennifer Hickey
*
*/
@RunWith(Parameterized.class)
public class DefaultSetOperationsTests<K,V> {
private RedisTemplate<K,V> redisTemplate;
public class DefaultSetOperationsTests<K, V> {
private RedisTemplate<K, V> redisTemplate;
private ObjectFactory<K> keyFactory;
private ObjectFactory<V> valueFactory;
private SetOperations<K,V> setOps;
private SetOperations<K, V> setOps;
public DefaultSetOperationsTests(RedisTemplate<K,V> redisTemplate, ObjectFactory<K> keyFactory,
public DefaultSetOperationsTests(RedisTemplate<K, V> redisTemplate, ObjectFactory<K> keyFactory,
ObjectFactory<V> valueFactory) {
this.redisTemplate = redisTemplate;
this.keyFactory = keyFactory;
@@ -69,7 +68,7 @@ public class DefaultSetOperationsTests<K,V> {
public static Collection<Object[]> testParams() {
return AbstractOperationsTestParams.testParams();
}
@Before
public void setUp() {
setOps = redisTemplate.opsForSet();
@@ -84,7 +83,7 @@ public class DefaultSetOperationsTests<K,V> {
}
});
}
@SuppressWarnings("unchecked")
@Test
public void testDistinctRandomMembers() {
@@ -102,7 +101,7 @@ public class DefaultSetOperationsTests<K,V> {
expected.add(v1);
expected.add(v2);
expected.add(v3);
assertThat(expected, hasItems((V[])members.toArray()));
assertThat(expected, hasItems((V[]) members.toArray()));
}
@SuppressWarnings("unchecked")
@@ -115,7 +114,7 @@ public class DefaultSetOperationsTests<K,V> {
setOps.add(setKey, v1);
setOps.add(setKey, v2);
List<V> members = setOps.randomMembers(setKey, 2);
assertEquals(2,members.size());
assertEquals(2, members.size());
assertThat(members, either(hasItem(v1)).or(hasItem(v2)));
}
@@ -125,8 +124,7 @@ public class DefaultSetOperationsTests<K,V> {
try {
setOps.randomMembers(keyFactory.instance(), -1);
fail("IllegalArgumentException should be thrown");
}catch(IllegalArgumentException e) {
}
} catch (IllegalArgumentException e) {}
}
@Test
@@ -135,8 +133,7 @@ public class DefaultSetOperationsTests<K,V> {
try {
setOps.distinctRandomMembers(keyFactory.instance(), -2);
fail("IllegalArgumentException should be thrown");
}catch(IllegalArgumentException e) {
}
} catch (IllegalArgumentException e) {}
}
@SuppressWarnings("unchecked")
@@ -149,10 +146,8 @@ public class DefaultSetOperationsTests<K,V> {
setOps.add(key1, v1);
setOps.add(key1, v2);
setOps.move(key1, v1, key2);
assertThat(setOps.members(key1),
isEqual(new HashSet<V>(Collections.singletonList(v2))));
assertThat(setOps.members(key2),
isEqual(new HashSet<V>(Collections.singletonList(v1))));
assertThat(setOps.members(key1), isEqual(new HashSet<V>(Collections.singletonList(v2))));
assertThat(setOps.members(key2), isEqual(new HashSet<V>(Collections.singletonList(v1))));
}
@SuppressWarnings("unchecked")
@@ -195,7 +190,7 @@ public class DefaultSetOperationsTests<K,V> {
V v2 = valueFactory.instance();
V v3 = valueFactory.instance();
V v4 = valueFactory.instance();
setOps.add(key,v1, v2, v3);
setOps.add(key, v1, v2, v3);
assertEquals(Long.valueOf(2), setOps.remove(key, v1, v2, v4));
assertThat(setOps.members(key), isEqual(Collections.singleton(v3)));
}

View File

@@ -44,12 +44,11 @@ import org.springframework.data.redis.connection.RedisConnection;
* Integration test of {@link DefaultValueOperations}
*
* @author Jennifer Hickey
*
*/
@RunWith(Parameterized.class)
public class DefaultValueOperationsTests<K,V> {
public class DefaultValueOperationsTests<K, V> {
private RedisTemplate<K,V> redisTemplate;
private RedisTemplate<K, V> redisTemplate;
private ObjectFactory<K> keyFactory;
@@ -57,7 +56,7 @@ public class DefaultValueOperationsTests<K,V> {
private ValueOperations<K, V> valueOps;
public DefaultValueOperationsTests(RedisTemplate<K,V> redisTemplate, ObjectFactory<K> keyFactory,
public DefaultValueOperationsTests(RedisTemplate<K, V> redisTemplate, ObjectFactory<K> keyFactory,
ObjectFactory<V> valueFactory) {
this.redisTemplate = redisTemplate;
this.keyFactory = keyFactory;
@@ -90,13 +89,12 @@ public class DefaultValueOperationsTests<K,V> {
V v1 = valueFactory.instance();
assumeTrue(v1 instanceof Long);
valueOps.set(key, v1);
assertEquals(Long.valueOf((Long)v1 - 10), valueOps.increment(key, -10));
assertEquals(Long.valueOf((Long)v1 - 10), (Long)valueOps.get(key));
assertEquals(Long.valueOf((Long) v1 - 10), valueOps.increment(key, -10));
assertEquals(Long.valueOf((Long) v1 - 10), (Long) valueOps.get(key));
valueOps.increment(key, -10);
assertEquals(Long.valueOf((Long)v1 - 20), (Long)valueOps.get(key));
assertEquals(Long.valueOf((Long) v1 - 20), (Long) valueOps.get(key));
}
/**
* @see DATAREDIS-247
*/
@@ -110,15 +108,15 @@ public class DefaultValueOperationsTests<K,V> {
valueOps.set(key, v1);
DecimalFormat twoDForm = (DecimalFormat) DecimalFormat.getInstance(Locale.US);
assertEquals(Double.valueOf(twoDForm.format((Double)v1 + 1.4)), valueOps.increment(key, 1.4));
assertEquals(Double.valueOf(twoDForm.format((Double)v1 + 1.4)), valueOps.get(key));
assertEquals(Double.valueOf(twoDForm.format((Double) v1 + 1.4)), valueOps.increment(key, 1.4));
assertEquals(Double.valueOf(twoDForm.format((Double) v1 + 1.4)), valueOps.get(key));
valueOps.increment(key, -10d);
assertEquals(Double.valueOf(twoDForm.format((Double)v1 + 1.4 - 10d)), valueOps.get(key));
assertEquals(Double.valueOf(twoDForm.format((Double) v1 + 1.4 - 10d)), valueOps.get(key));
}
@Test
public void testMultiSetIfAbsent() {
Map<K,V> keysAndValues = new HashMap<K,V>();
Map<K, V> keysAndValues = new HashMap<K, V>();
K key1 = keyFactory.instance();
K key2 = keyFactory.instance();
V value1 = valueFactory.instance();
@@ -126,8 +124,7 @@ public class DefaultValueOperationsTests<K,V> {
keysAndValues.put(key1, value1);
keysAndValues.put(key2, value2);
assertTrue(valueOps.multiSetIfAbsent(keysAndValues));
assertThat(valueOps.multiGet(keysAndValues.keySet()),
isEqual(new ArrayList<V>(keysAndValues.values())));
assertThat(valueOps.multiGet(keysAndValues.keySet()), isEqual(new ArrayList<V>(keysAndValues.values())));
}
@Test
@@ -138,7 +135,7 @@ public class DefaultValueOperationsTests<K,V> {
V value2 = valueFactory.instance();
V value3 = valueFactory.instance();
valueOps.set(key1, value1);
Map<K,V> keysAndValues = new HashMap<K,V>();
Map<K, V> keysAndValues = new HashMap<K, V>();
keysAndValues.put(key1, value2);
keysAndValues.put(key2, value3);
assertFalse(valueOps.multiSetIfAbsent(keysAndValues));
@@ -146,7 +143,7 @@ public class DefaultValueOperationsTests<K,V> {
@Test
public void testMultiSet() {
Map<K,V> keysAndValues = new HashMap<K,V>();
Map<K, V> keysAndValues = new HashMap<K, V>();
K key1 = keyFactory.instance();
K key2 = keyFactory.instance();
V value1 = valueFactory.instance();
@@ -154,15 +151,14 @@ public class DefaultValueOperationsTests<K,V> {
keysAndValues.put(key1, value1);
keysAndValues.put(key2, value2);
valueOps.multiSet(keysAndValues);
assertThat(valueOps.multiGet(keysAndValues.keySet()),
isEqual(new ArrayList<V>(keysAndValues.values())));
assertThat(valueOps.multiGet(keysAndValues.keySet()), isEqual(new ArrayList<V>(keysAndValues.values())));
}
@Test
public void testGetSet() {
K key1 = keyFactory.instance();
V value1 = valueFactory.instance();
valueOps.set(key1,value1);
valueOps.set(key1, value1);
assertThat(valueOps.get(key1), isEqual(value1));
}
@@ -195,8 +191,8 @@ public class DefaultValueOperationsTests<K,V> {
V value1 = valueFactory.instance();
assumeTrue(redisTemplate instanceof StringRedisTemplate);
valueOps.set(key1, value1);
assertEquals(Integer.valueOf(((String)value1).length() + 3), valueOps.append(key1, "aaa"));
assertEquals((String)value1 + "aaa",valueOps.get(key1));
assertEquals(Integer.valueOf(((String) value1).length() + 3), valueOps.append(key1, "aaa"));
assertEquals((String) value1 + "aaa", valueOps.get(key1));
}
@Test
@@ -205,7 +201,7 @@ public class DefaultValueOperationsTests<K,V> {
V value1 = valueFactory.instance();
assumeTrue(value1 instanceof String);
valueOps.set(key1, value1);
assertEquals(2,valueOps.get(key1, 0, 1).length());
assertEquals(2, valueOps.get(key1, 0, 1).length());
}
@Test
@@ -241,7 +237,7 @@ public class DefaultValueOperationsTests<K,V> {
public void testRawKeys() {
K key1 = keyFactory.instance();
K key2 = keyFactory.instance();
byte[][] rawKeys = ((DefaultValueOperations)valueOps).rawKeys(key1, key2);
byte[][] rawKeys = ((DefaultValueOperations) valueOps).rawKeys(key1, key2);
assertEquals(2, rawKeys.length);
}
@@ -250,7 +246,7 @@ public class DefaultValueOperationsTests<K,V> {
public void testRawKeysCollection() {
K key1 = keyFactory.instance();
K key2 = keyFactory.instance();
byte[][] rawKeys = ((DefaultValueOperations)valueOps).rawKeys(Arrays.asList(new Object[] {key1, key2}));
byte[][] rawKeys = ((DefaultValueOperations) valueOps).rawKeys(Arrays.asList(new Object[] { key1, key2 }));
assertEquals(2, rawKeys.length);
}
@@ -259,6 +255,6 @@ public class DefaultValueOperationsTests<K,V> {
public void testDeserializeKey() {
K key1 = keyFactory.instance();
assumeTrue(key1 instanceof byte[]);
assertNotNull(((DefaultValueOperations)valueOps).deserializeKey((byte[])key1));
assertNotNull(((DefaultValueOperations) valueOps).deserializeKey((byte[]) key1));
}
}

View File

@@ -37,15 +37,15 @@ import org.springframework.data.redis.core.ZSetOperations.TypedTuple;
/**
* Integration test of {@link DefaultZSetOperations}
*
* @author Jennifer Hickey
*
* @param <K> Key type
* @param <V> Value type
*/
@RunWith(Parameterized.class)
public class DefaultZSetOperationsTests<K,V> {
public class DefaultZSetOperationsTests<K, V> {
private RedisTemplate<K,V> redisTemplate;
private RedisTemplate<K, V> redisTemplate;
private ObjectFactory<K> keyFactory;
@@ -53,7 +53,7 @@ public class DefaultZSetOperationsTests<K,V> {
private ZSetOperations<K, V> zSetOps;
public DefaultZSetOperationsTests(RedisTemplate<K,V> redisTemplate, ObjectFactory<K> keyFactory,
public DefaultZSetOperationsTests(RedisTemplate<K, V> redisTemplate, ObjectFactory<K> keyFactory,
ObjectFactory<V> valueFactory) {
this.redisTemplate = redisTemplate;
this.keyFactory = keyFactory;
@@ -97,7 +97,7 @@ public class DefaultZSetOperationsTests<K,V> {
zSetOps.add(key1, value1, 2.5);
assertEquals(Double.valueOf(5.7), zSetOps.incrementScore(key1, value1, 3.2));
Set<TypedTuple<V>> values = zSetOps.rangeWithScores(key1, 0, -1);
assertEquals(1,values.size());
assertEquals(1, values.size());
TypedTuple<V> tuple = values.iterator().next();
assertEquals(new DefaultTypedTuple<V>(value1, 5.7), tuple);
}
@@ -112,8 +112,7 @@ public class DefaultZSetOperationsTests<K,V> {
zSetOps.add(key, value1, 1.9);
zSetOps.add(key, value2, 3.7);
zSetOps.add(key, value3, 5.8);
assertThat(zSetOps.rangeByScore(key, 1.5, 4.7, 0, 1),
isEqual(Collections.singleton(value1)));
assertThat(zSetOps.rangeByScore(key, 1.5, 4.7, 0, 1), isEqual(Collections.singleton(value1)));
}
@Test
@@ -140,8 +139,7 @@ public class DefaultZSetOperationsTests<K,V> {
zSetOps.add(key, value1, 1.9);
zSetOps.add(key, value2, 3.7);
zSetOps.add(key, value3, 5.8);
assertThat(zSetOps.reverseRangeByScore(key, 1.5, 4.7, 0, 1),
isEqual(Collections.singleton(value2)));
assertThat(zSetOps.reverseRangeByScore(key, 1.5, 4.7, 0, 1), isEqual(Collections.singleton(value2)));
}
@Test

View File

@@ -64,18 +64,15 @@ import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;
/**
*
* Integration test of {@link RedisTemplate}
*
*
* @author Jennifer Hickey
*
*/
@RunWith(Parameterized.class)
public class RedisTemplateTests<K,V> {
public class RedisTemplateTests<K, V> {
@Autowired private RedisTemplate<K, V> redisTemplate;
@Autowired
private RedisTemplate<K,V> redisTemplate;
private ObjectFactory<K> keyFactory;
private ObjectFactory<V> valueFactory;
@@ -140,7 +137,7 @@ public class RedisTemplateTests<K,V> {
V value1 = valueFactory.instance();
assumeTrue(key1 instanceof String || key1 instanceof byte[]);
redisTemplate.opsForValue().set(key1, value1);
K keyPattern = key1 instanceof String ? (K) "*" : (K)"*".getBytes();
K keyPattern = key1 instanceof String ? (K) "*" : (K) "*".getBytes();
assertNotNull(redisTemplate.keys(keyPattern));
}
@@ -162,7 +159,7 @@ public class RedisTemplateTests<K,V> {
return stringConn.get("test");
}
});
assertEquals(value,"it");
assertEquals(value, "it");
}
@Test
@@ -192,9 +189,9 @@ 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)));
assertThat(results, isEqual(Arrays.asList(new Object[] {value1, 1l, list, 1l, set, true, tupleSet})));
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 })));
}
@Test
@@ -242,10 +239,10 @@ public class RedisTemplateTests<K,V> {
Set<TypedTuple<Long>> tupleSet = new LinkedHashSet<TypedTuple<Long>>(
Collections.singletonList(new DefaultTypedTuple<Long>(9l, 1d)));
Set<Long> zSet = new LinkedHashSet<Long>(Collections.singletonList(9l));
Map<Long, Long> map = new LinkedHashMap<Long,Long>();
Map<Long, Long> map = new LinkedHashMap<Long, Long>();
map.put(10l, 11l);
assertThat(results,
isEqual(Arrays.asList(new Object[] {5l, 1l, list, 1l, longSet, true, tupleSet, zSet, true, map})));
isEqual(Arrays.asList(new Object[] { 5l, 1l, list, 1l, longSet, true, tupleSet, zSet, true, map })));
}
@Test
@@ -259,13 +256,13 @@ public class RedisTemplateTests<K,V> {
@SuppressWarnings({ "rawtypes", "unchecked" })
public List<Object> execute(RedisOperations operations) throws DataAccessException {
operations.multi();
operations.opsForValue().set("foo","bar");
operations.opsForValue().set("foo", "bar");
operations.opsForValue().get("foo");
return operations.exec();
}
});
// first value is "OK" from set call, results should still be in byte[]
assertEquals("bar", new String((byte[])results.get(1)));
assertEquals("bar", new String((byte[]) results.get(1)));
}
@SuppressWarnings("rawtypes")
@@ -289,7 +286,7 @@ public class RedisTemplateTests<K,V> {
}
});
assertThat(results,
isEqual(Arrays.asList(new Object[] {value1, 1l, 2l, Arrays.asList(new Object[] {listValue, listValue2})})));
isEqual(Arrays.asList(new Object[] { value1, 1l, 2l, Arrays.asList(new Object[] { listValue, listValue2 }) })));
}
@SuppressWarnings("rawtypes")
@@ -307,10 +304,10 @@ public class RedisTemplateTests<K,V> {
return null;
}
}, new GenericToStringSerializer<Long>(Long.class));
assertEquals(Arrays.asList(new Object[] {5l, 1l, 2l, Arrays.asList(new Long[] {10l, 11l})}), results);
assertEquals(Arrays.asList(new Object[] { 5l, 1l, 2l, Arrays.asList(new Long[] { 10l, 11l }) }), results);
}
@Test(expected=InvalidDataAccessApiUsageException.class)
@Test(expected = InvalidDataAccessApiUsageException.class)
public void testExecutePipelinedNonNullRedisCallback() {
redisTemplate.executePipelined(new RedisCallback<String>() {
public String doInRedis(RedisConnection connection) throws DataAccessException {
@@ -319,7 +316,7 @@ public class RedisTemplateTests<K,V> {
});
}
@SuppressWarnings({"rawtypes", "unchecked"})
@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void testExecutePipelinedTx() {
final K key1 = keyFactory.instance();
@@ -337,10 +334,11 @@ public class RedisTemplateTests<K,V> {
}
});
// Should contain the List of deserialized exec results and the result of the last call to get()
assertThat(pipelinedResults, isEqual(Arrays.asList(new Object[] {Arrays.asList(new Object[] {1l, value1, 0l}), value1})));
assertThat(pipelinedResults,
isEqual(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 1l, value1, 0l }), value1 })));
}
@SuppressWarnings({"rawtypes", "unchecked"})
@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void testExecutePipelinedTxCustomSerializer() {
assumeTrue(redisTemplate instanceof StringRedisTemplate);
@@ -355,12 +353,12 @@ public class RedisTemplateTests<K,V> {
operations.opsForValue().get("foo");
return null;
}
},new GenericToStringSerializer<Long>(Long.class));
}, new GenericToStringSerializer<Long>(Long.class));
// Should contain the List of deserialized exec results and the result of the last call to get()
assertEquals(Arrays.asList(new Object[] {Arrays.asList(new Object[] {1l, 5l, 0l}), 2l}), pipelinedResults);
assertEquals(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 1l, 5l, 0l }), 2l }), pipelinedResults);
}
@Test(expected=InvalidDataAccessApiUsageException.class)
@Test(expected = InvalidDataAccessApiUsageException.class)
public void testExecutePipelinedNonNullSessionCallback() {
redisTemplate.executePipelined(new SessionCallback<String>() {
@SuppressWarnings("rawtypes")
@@ -423,12 +421,13 @@ public class RedisTemplateTests<K,V> {
V value1 = valueFactory.instance();
assumeTrue(value1 instanceof Number);
redisTemplate.opsForList().rightPush(key1, value1);
List<String> results = redisTemplate.sort(SortQueryBuilder.sort(key1).get("#").build(), new BulkMapper<String, V>() {
public String mapBulk(List<V> tuple) {
return "FOO";
}
});
assertEquals(Collections.singletonList("FOO"),results);
List<String> results = redisTemplate.sort(SortQueryBuilder.sort(key1).get("#").build(),
new BulkMapper<String, V>() {
public String mapBulk(List<V> tuple) {
return "FOO";
}
});
assertEquals(Collections.singletonList("FOO"), results);
}
@Test
@@ -458,14 +457,14 @@ public class RedisTemplateTests<K,V> {
factory.setPort(SettingsUtils.getPort());
factory.afterPropertiesSet();
final StringRedisTemplate template2 = new StringRedisTemplate(factory);
template2.boundValueOps((String)key1).set((String)value1);
template2.expire((String)key1, 10, TimeUnit.MILLISECONDS);
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));
assertTrue(template2.hasKey((String) key1));
waitFor(new TestCondition() {
public boolean passes() {
return (!template2.hasKey((String)key1));
return (!template2.hasKey((String) key1));
}
}, 1000l);
}
@@ -501,9 +500,9 @@ public class RedisTemplateTests<K,V> {
factory.setPort(SettingsUtils.getPort());
factory.afterPropertiesSet();
final StringRedisTemplate template2 = new StringRedisTemplate(factory);
template2.boundValueOps((String)key1).set((String)value1);
template2.expire((String)key1, 5, TimeUnit.SECONDS);
long expire = template2.getExpire((String)key1, TimeUnit.MILLISECONDS);
template2.boundValueOps((String) key1).set((String) value1);
template2.expire((String) key1, 5, TimeUnit.SECONDS);
long expire = template2.getExpire((String) key1, TimeUnit.MILLISECONDS);
// we should still get expire in milliseconds if requested
assertTrue(expire > 1000 && expire <= 5000);
}
@@ -533,12 +532,12 @@ public class RedisTemplateTests<K,V> {
factory.setPort(SettingsUtils.getPort());
factory.afterPropertiesSet();
final StringRedisTemplate template2 = new StringRedisTemplate(factory);
template2.boundValueOps((String)key1).set((String)value1);
template2.expireAt((String)key1, new Date(System.currentTimeMillis() + 5l));
template2.boundValueOps((String) key1).set((String) value1);
template2.expireAt((String) key1, new Date(System.currentTimeMillis() + 5l));
// Just ensure this works as expected, pExpireAt just adds some precision over expireAt
waitFor(new TestCondition() {
public boolean passes() {
return (!template2.hasKey((String)key1));
return (!template2.hasKey((String) key1));
}
}, 5l);
}
@@ -589,7 +588,7 @@ public class RedisTemplateTests<K,V> {
K key1 = keyFactory.instance();
V value1 = valueFactory.instance();
redisTemplate.opsForValue().set(key1, value1);
assertEquals(DataType.STRING,redisTemplate.type(key1));
assertEquals(DataType.STRING, redisTemplate.type(key1));
}
@Test
@@ -611,8 +610,7 @@ public class RedisTemplateTests<K,V> {
th.start();
try {
th.join();
} catch (InterruptedException e) {
}
} catch (InterruptedException e) {}
operations.multi();
operations.opsForValue().set(key1, value3);
return operations.exec();
@@ -641,8 +639,7 @@ public class RedisTemplateTests<K,V> {
th.start();
try {
th.join();
} catch (InterruptedException e) {
}
} catch (InterruptedException e) {}
operations.unwatch();
operations.multi();
operations.opsForValue().set(key1, value3);
@@ -676,8 +673,7 @@ public class RedisTemplateTests<K,V> {
th.start();
try {
th.join();
} catch (InterruptedException e) {
}
} catch (InterruptedException e) {}
operations.multi();
operations.opsForValue().set(key1, value3);
return operations.exec();
@@ -698,17 +694,19 @@ public class RedisTemplateTests<K,V> {
public void testExecuteScriptCustomSerializers() {
assumeTrue(RedisTestProfileValueSource.matches("redisVersion", "2.6"));
K key1 = keyFactory.instance();
final DefaultRedisScript<String> script = new DefaultRedisScript<String>();
final DefaultRedisScript<String> script = new DefaultRedisScript<String>();
script.setScriptText("return 'Hey'");
script.setResultType(String.class);
assertEquals("Hey", redisTemplate.execute(script, redisTemplate.getValueSerializer(), new StringRedisSerializer(),
Collections.singletonList(key1)));
assertEquals(
"Hey",
redisTemplate.execute(script, redisTemplate.getValueSerializer(), new StringRedisSerializer(),
Collections.singletonList(key1)));
}
@SuppressWarnings({ "unchecked", "rawtypes" })
private byte[] serialize(Object value, RedisSerializer serializer) {
if(serializer == null && value instanceof byte[]) {
return (byte[])value;
if (serializer == null && value instanceof byte[]) {
return (byte[]) value;
}
return serializer.serialize(value);
}

View File

@@ -63,4 +63,4 @@ public class SessionTest {
}
}, true);
}
}
}

View File

@@ -15,7 +15,6 @@
*/
package org.springframework.data.redis.core;
import org.junit.After;
import org.junit.Before;
import org.springframework.data.redis.core.query.SortQueryBuilder;
@@ -23,12 +22,10 @@ import org.springframework.data.redis.core.query.SortQueryBuilder;
public class SortTest {
@Before
public void setUp() throws Exception {
}
public void setUp() throws Exception {}
@After
public void tearDown() throws Exception {
}
public void tearDown() throws Exception {}
public void testBasicDSL() throws Exception {
SortQueryBuilder.sort("list").build();

View File

@@ -25,7 +25,6 @@ import static org.junit.Assert.assertEquals;
* Unit test of {@link TimeoutUtils}
*
* @author Jennifer Hickey
*
*/
public class TimeoutUtilsTests {
@@ -43,21 +42,21 @@ public class TimeoutUtilsTests {
public void testConvertZeroSeconds() {
assertEquals(0, TimeoutUtils.toSeconds(0, TimeUnit.MINUTES));
}
@Test
public void testConvertNegativeSecondsGreaterThanNegativeOne() {
// Ensure we convert this to 0 as before, though ideally we wouldn't accept negative values
assertEquals(0,TimeoutUtils.toSeconds(-123, TimeUnit.MILLISECONDS));
assertEquals(0, TimeoutUtils.toSeconds(-123, TimeUnit.MILLISECONDS));
}
@Test
public void testConvertNegativeSecondsEqualNegativeOne() {
assertEquals(-1,TimeoutUtils.toSeconds(-1111, TimeUnit.MILLISECONDS));
assertEquals(-1, TimeoutUtils.toSeconds(-1111, TimeUnit.MILLISECONDS));
}
@Test
public void testConvertNegativeSecondsLessThanNegativeOne() {
assertEquals(-2,TimeoutUtils.toSeconds(-2344, TimeUnit.MILLISECONDS));
assertEquals(-2, TimeoutUtils.toSeconds(-2344, TimeUnit.MILLISECONDS));
}
@Test
@@ -78,16 +77,16 @@ public class TimeoutUtilsTests {
@Test
public void testConvertNegativeMillisGreaterThanNegativeOne() {
// Ensure we convert this to 0 as before, though ideally we wouldn't accept negative values
assertEquals(0,TimeoutUtils.toMillis(-123, TimeUnit.MICROSECONDS));
assertEquals(0, TimeoutUtils.toMillis(-123, TimeUnit.MICROSECONDS));
}
@Test
public void testConvertNegativeMillisEqualNegativeOne() {
assertEquals(-1,TimeoutUtils.toMillis(-1111, TimeUnit.MICROSECONDS));
assertEquals(-1, TimeoutUtils.toMillis(-1111, TimeUnit.MICROSECONDS));
}
@Test
public void testConvertNegativeMillisLessThanNegativeOne() {
assertEquals(-2,TimeoutUtils.toMillis(-2344, TimeUnit.MICROSECONDS));
assertEquals(-2, TimeoutUtils.toMillis(-2344, TimeUnit.MICROSECONDS));
}
}

View File

@@ -25,9 +25,8 @@ import org.springframework.scripting.support.StaticScriptSource;
/**
* Test of {@link DefaultRedisScript}
*
*
* @author Jennifer Hickey
*
*/
public class DefaultRedisScriptTests {

View File

@@ -52,7 +52,6 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
* Integration test of {@link DefaultScriptExecutor}
*
* @author Jennifer Hickey
*
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration
@@ -60,11 +59,9 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@IfProfileValue(name = "redisVersion", value = "2.6")
public class DefaultScriptExecutorTests {
@Autowired
private RedisConnectionFactory connFactory;
@Autowired private RedisConnectionFactory connFactory;
@SuppressWarnings("rawtypes")
private RedisTemplate template;
@SuppressWarnings("rawtypes") private RedisTemplate template;
@SuppressWarnings("unchecked")
@After
@@ -85,15 +82,13 @@ public class DefaultScriptExecutorTests {
template.setConnectionFactory(connFactory);
template.afterPropertiesSet();
DefaultRedisScript<Long> script = new DefaultRedisScript<Long>();
script.setLocation(new ClassPathResource(
"org/springframework/data/redis/core/script/increment.lua"));
script.setLocation(new ClassPathResource("org/springframework/data/redis/core/script/increment.lua"));
script.setResultType(Long.class);
ScriptExecutor<String> scriptExecutor = new DefaultScriptExecutor<String>(template);
Long result = scriptExecutor.execute(script, Collections.singletonList("mykey"));
assertNull(result);
template.boundValueOps("mykey").set("2");
assertEquals(Long.valueOf(3),
scriptExecutor.execute(script, Collections.singletonList("mykey")));
assertEquals(Long.valueOf(3), scriptExecutor.execute(script, Collections.singletonList("mykey")));
}
@SuppressWarnings("unchecked")
@@ -105,13 +100,11 @@ public class DefaultScriptExecutorTests {
template.setConnectionFactory(connFactory);
template.afterPropertiesSet();
DefaultRedisScript<Boolean> script = new DefaultRedisScript<Boolean>();
script.setLocation(new ClassPathResource(
"org/springframework/data/redis/core/script/cas.lua"));
script.setLocation(new ClassPathResource("org/springframework/data/redis/core/script/cas.lua"));
script.setResultType(Boolean.class);
ScriptExecutor<String> scriptExecutor = new DefaultScriptExecutor<String>(template);
template.boundValueOps("counter").set(0l);
Boolean valueSet = scriptExecutor.execute(script, Collections.singletonList("counter"), 0,
3);
Boolean valueSet = scriptExecutor.execute(script, Collections.singletonList("counter"), 0, 3);
assertTrue(valueSet);
assertFalse(scriptExecutor.execute(script, Collections.singletonList("counter"), 0, 3));
}
@@ -124,13 +117,11 @@ public class DefaultScriptExecutorTests {
template.afterPropertiesSet();
template.boundListOps("mylist").leftPushAll("a", "b", "c", "d");
DefaultRedisScript<List> script = new DefaultRedisScript<List>();
script.setLocation(new ClassPathResource(
"org/springframework/data/redis/core/script/bulkpop.lua"));
script.setLocation(new ClassPathResource("org/springframework/data/redis/core/script/bulkpop.lua"));
script.setResultType(List.class);
ScriptExecutor<String> scriptExecutor = new DefaultScriptExecutor<String>(template);
List<String> result = scriptExecutor
.execute(script, new GenericToStringSerializer<Long>(Long.class),
template.getValueSerializer(), Collections.singletonList("mylist"), 1l);
List<String> result = scriptExecutor.execute(script, new GenericToStringSerializer<Long>(Long.class),
template.getValueSerializer(), Collections.singletonList("mylist"), 1l);
assertEquals(Collections.singletonList("a"), result);
}
@@ -183,21 +174,19 @@ public class DefaultScriptExecutorTests {
@SuppressWarnings("unchecked")
@Test
public void testExecuteCustomResultSerializer() {
JacksonJsonRedisSerializer<Person> personSerializer = new JacksonJsonRedisSerializer<Person>(
Person.class);
JacksonJsonRedisSerializer<Person> personSerializer = new JacksonJsonRedisSerializer<Person>(Person.class);
this.template = new RedisTemplate<String, Person>();
template.setKeySerializer(new StringRedisSerializer());
template.setValueSerializer(personSerializer);
template.setConnectionFactory(connFactory);
template.afterPropertiesSet();
DefaultRedisScript<String> script = new DefaultRedisScript<String>();
script.setScriptSource(new StaticScriptSource(
"redis.call('SET',KEYS[1], ARGV[1])\nreturn 'FOO'"));
script.setScriptSource(new StaticScriptSource("redis.call('SET',KEYS[1], ARGV[1])\nreturn 'FOO'"));
script.setResultType(String.class);
ScriptExecutor<String> scriptExecutor = new DefaultScriptExecutor<String>(template);
Person joe = new Person("Joe", "Schmoe", 23);
String result = scriptExecutor.execute(script, personSerializer,
new StringRedisSerializer(), Collections.singletonList("bar"), joe);
String result = scriptExecutor.execute(script, personSerializer, new StringRedisSerializer(),
Collections.singletonList("bar"), joe);
assertEquals("FOO", result);
assertEquals(joe, template.boundValueOps("bar").get());
}

View File

@@ -61,8 +61,7 @@ public class PubSubResubscribeTests {
protected RedisMessageListenerContainer container;
protected RedisConnectionFactory factory;
@SuppressWarnings("rawtypes")
protected RedisTemplate template;
@SuppressWarnings("rawtypes") protected RedisTemplate template;
private final BlockingDeque<String> bag = new LinkedBlockingDeque<String>(99);
@@ -118,7 +117,6 @@ public class PubSubResubscribeTests {
Thread.sleep(1000);
}
@Test
public void testContainerPatternResubscribe() throws Exception {
String payload1 = "do";
@@ -160,10 +158,10 @@ public class PubSubResubscribeTests {
template.convertAndSend(ANOTHER_CHANNEL, payload2);
// original listener received only one message on another channel
assertEquals(payload2,bag.poll(1, TimeUnit.SECONDS));
assertEquals(payload2, bag.poll(1, TimeUnit.SECONDS));
assertNull(bag.poll(1, TimeUnit.SECONDS));
//another listener receives messages on both channels
// another listener receives messages on both channels
msgs.add(bag2.poll(1, TimeUnit.SECONDS));
msgs.add(bag2.poll(1, TimeUnit.SECONDS));
assertEquals(2, msgs.size());
@@ -187,11 +185,11 @@ public class PubSubResubscribeTests {
// Listener removed from channel
template.convertAndSend(CHANNEL, payload1);
template.convertAndSend(CHANNEL, payload2);
template.convertAndSend(CHANNEL, payload2);
// Listener receives messages on another channel
// Listener receives messages on another channel
template.convertAndSend(ANOTHER_CHANNEL, anotherPayload1);
template.convertAndSend(ANOTHER_CHANNEL, anotherPayload2);
template.convertAndSend(ANOTHER_CHANNEL, anotherPayload2);
Set<String> set = new LinkedHashSet<String>();
set.add(bag.poll(1, TimeUnit.SECONDS));
@@ -205,8 +203,9 @@ public class PubSubResubscribeTests {
}
/**
* Validates the behavior of {@link RedisMessageListenerContainer} when it needs to spin up
* a thread executing its PatternSubscriptionTask
* Validates the behavior of {@link RedisMessageListenerContainer} when it needs to spin up a thread executing its
* PatternSubscriptionTask
*
* @throws Exception
*/
@Ignore("DATAREDIS-166 Intermittent corrupted input/output streams subscribing to both patterns and channels in RMLC")
@@ -245,4 +244,4 @@ public class PubSubResubscribeTests {
bag.add(message);
}
}
}
}

View File

@@ -92,9 +92,8 @@ public class PubSubTestParams {
// 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, rawTemplate }, { stringFactory, stringTemplateLtc }, { personFactory, personTemplateLtc },
{ rawFactory, rawTemplateLtc }, { stringFactory, stringTemplateSrp }, { personFactory, personTemplateSrp },
{ rawFactory, rawTemplateSrp } });
}
}

View File

@@ -58,8 +58,7 @@ public class PubSubTests<T> {
protected RedisMessageListenerContainer container;
protected ObjectFactory<T> factory;
@SuppressWarnings("rawtypes")
protected RedisTemplate template;
@SuppressWarnings("rawtypes") protected RedisTemplate template;
private final BlockingDeque<Object> bag = new LinkedBlockingDeque<Object>(99);
@@ -120,6 +119,7 @@ public class PubSubTests<T> {
/**
* Return a new instance of T
*
* @return
*/
protected T getT() {
@@ -172,8 +172,7 @@ public class PubSubTests<T> {
// DATREDIS-207 This test previously took 5 seconds on start due to monitor wait
container.start();
}
/**
* @see DATAREDIS-251
*/
@@ -183,16 +182,16 @@ public class PubSubTests<T> {
container.removeMessageListener(adapter, new ChannelTopic(CHANNEL));
container.addMessageListener(adapter, Arrays.asList(new PatternTopic("*")));
container.start();
Thread.sleep(1000); //give the container a little time to recover
Thread.sleep(1000); // give the container a little time to recover
T payload = getT();
template.convertAndSend(CHANNEL, payload);
Set<T> set = new LinkedHashSet<T>();
set.add((T) bag.poll(3, TimeUnit.SECONDS));
assertThat(set, hasItems(payload));
}
}
}

View File

@@ -39,12 +39,10 @@ import java.util.Collection;
import java.util.List;
/**
* Integration tests confirming that {@link RedisMessageListenerContainer}
* closes connections after unsubscribing
*
* Integration tests confirming that {@link RedisMessageListenerContainer} closes connections after unsubscribing
*
* @author Jennifer Hickey
* @author Thomas Darimont
*
*/
@RunWith(Parameterized.class)
public class SubscriptionConnectionTests {
@@ -104,8 +102,7 @@ public class SubscriptionConnectionTests {
srpConnFactory.setHostName(SettingsUtils.getHost());
srpConnFactory.afterPropertiesSet();
return Arrays.asList(new Object[][] { { jedisConnFactory }, { lettuceConnFactory },
{ srpConnFactory } });
return Arrays.asList(new Object[][] { { jedisConnFactory }, { lettuceConnFactory }, { srpConnFactory } });
}
@Test
@@ -116,8 +113,7 @@ public class SubscriptionConnectionTests {
RedisMessageListenerContainer container = new RedisMessageListenerContainer();
container.setConnectionFactory(connectionFactory);
container.setBeanName("container" + i);
container.addMessageListener(new MessageListenerAdapter(handler),
Arrays.asList(new ChannelTopic(CHANNEL)));
container.addMessageListener(new MessageListenerAdapter(handler), Arrays.asList(new ChannelTopic(CHANNEL)));
container.setTaskExecutor(new SyncTaskExecutor());
container.setSubscriptionExecutor(new SimpleAsyncTaskExecutor());
container.afterPropertiesSet();

View File

@@ -32,15 +32,14 @@ public class ContainerXmlSetupTest {
@After
public void tearDown() {
if(ctx != null) {
if (ctx != null) {
ctx.destroy();
}
}
@Test
public void testContainerSetup() throws Exception {
ctx = new GenericXmlApplicationContext(
"/org/springframework/data/redis/listener/container.xml");
ctx = new GenericXmlApplicationContext("/org/springframework/data/redis/listener/container.xml");
RedisMessageListenerContainer container = ctx.getBean("redisContainer", RedisMessageListenerContainer.class);
assertTrue(container.isRunning());
}

View File

@@ -54,8 +54,7 @@ public class MessageListenerTest {
void customMethodWithChannel(String arg, String channel);
}
@Mock
private Delegate target;
@Mock private Delegate target;
@Before
public void setUp() {

View File

@@ -27,4 +27,4 @@ public class RedisMDP {
public void anotherHandle(String message) {
System.out.println("[*] Received message " + message);
}
}
}

View File

@@ -19,7 +19,6 @@ import org.springframework.data.redis.connection.Message;
import org.springframework.data.redis.connection.MessageListener;
/**
*
* @author Costin Leau
*/
public class ThrowableMessageListener implements MessageListener {

View File

@@ -46,4 +46,4 @@ public abstract class AbstractHashMapperTest {
public void testNestedBean() throws Exception {
test(new Person("George", "Enescu", 74, new Address("liveni", 19)));
}
}
}

View File

@@ -24,7 +24,6 @@ import org.springframework.data.redis.hash.HashMapper;
*/
public class BeanUtilsHashMapperTest extends AbstractHashMapperTest {
protected HashMapper mapperFor(Class t) {
return new BeanUtilsHashMapper(t);
}

View File

@@ -20,7 +20,6 @@ import org.springframework.data.redis.hash.JacksonHashMapper;
public class JacksonHashMapperTest extends AbstractHashMapperTest {
protected HashMapper mapperFor(Class t) {
return new JacksonHashMapper(t);
}

View File

@@ -30,16 +30,13 @@ import org.hamcrest.Matcher;
import static org.junit.matchers.JUnitMatchers.hasItems;
/**
* Custom JUnit {@link Matcher} that exists to properly compare byte arrays, either as individual
* results or members of a {@link Collection} or {@link LinkedHashMap}. Works the same as
* assertEquals for all other types of Objects.
*
* Make some assumptions about structure of data based on what we typically get back from Redis
* commands, i.e that Sets or Maps don't contain Collections, but a List might contain a bit of
* everything (when it comes back from exec() or closePipeline())
* Custom JUnit {@link Matcher} that exists to properly compare byte arrays, either as individual results or members of
* a {@link Collection} or {@link LinkedHashMap}. Works the same as assertEquals for all other types of Objects. Make
* some assumptions about structure of data based on what we typically get back from Redis commands, i.e that Sets or
* Maps don't contain Collections, but a List might contain a bit of everything (when it comes back from exec() or
* closePipeline())
*
* @author Jennifer Hickey
*
*/
public class Equals extends BaseMatcher<Object> {

View File

@@ -21,14 +21,11 @@ import org.hamcrest.Matcher;
* Customs {@link Matcher}s for Redis tests
*
* @author Jennifer Hickey
*
*/
abstract public class RedisTestMatchers {
/**
*
* @param expected
* The expected results
* @param expected The expected results
* @return The {@link Equals} matcher
*/
public static Matcher<Object> isEqual(Object expected) {

View File

@@ -31,24 +31,24 @@ import org.springframework.data.redis.PersonObjectFactory;
* @author Christoph Strobl
*/
public class Jackson2JsonRedisSerializerTests {
private Jackson2JsonRedisSerializer<Person> serializer;
@Before
public void setUp() {
this.serializer = new Jackson2JsonRedisSerializer<Person>(Person.class);
}
/**
* @see DATAREDIS-241
* @see DATAREDIS-241
*/
@Test
public void testJackson2JsonSerializer() throws Exception {
Person person = new PersonObjectFactory().instance();
assertEquals(person, serializer.deserialize(serializer.serialize(person)));
}
/**
* @see DATAREDIS-241
*/
@@ -56,7 +56,7 @@ public class Jackson2JsonRedisSerializerTests {
public void testJackson2JsonSerializerShouldReturnEmptyByteArrayWhenSerializingNull() {
assertThat(serializer.serialize(null), Is.is(new byte[0]));
}
/**
* @see DTATREDIS-241
*/
@@ -64,24 +64,24 @@ public class Jackson2JsonRedisSerializerTests {
public void testJackson2JsonSerializerShouldReturnNullWhenDerserializingEmtyByteArray() {
assertThat(serializer.deserialize(new byte[0]), IsNull.nullValue());
}
/**
* @see DTATREDIS-241
*/
@Test(expected=SerializationException.class)
@Test(expected = SerializationException.class)
public void testJackson2JsonSerilizerShouldThrowExceptionWhenDeserializingInvalidByteArray() {
Person person = new PersonObjectFactory().instance();
byte [] serializedValue = serializer.serialize(person);
Arrays.sort(serializedValue); //corrupt serialization result
byte[] serializedValue = serializer.serialize(person);
Arrays.sort(serializedValue); // corrupt serialization result
serializer.deserialize(serializedValue);
}
/**
* @see DTATREDIS-241
*/
@Test(expected=IllegalArgumentException.class)
@Test(expected = IllegalArgumentException.class)
public void testJackson2JsonSerilizerThrowsExceptionWhenSettingNullObjectMapper() {
serializer.setObjectMapper(null);
}

View File

@@ -33,6 +33,7 @@ import org.springframework.oxm.xstream.XStreamMarshaller;
public class SimpleRedisSerializerTests {
private static class A implements Serializable {
private Integer value = Integer.valueOf(30);
public int hashCode() {
@@ -60,6 +61,7 @@ public class SimpleRedisSerializerTests {
}
private static class B implements Serializable {
private String name = getClass().getName();
private A a = new A();
@@ -107,7 +109,6 @@ public class SimpleRedisSerializerTests {
@Test
public void testBasicSerializationRoundtrip() throws Exception {
Integer integer = new Integer(300);
verifySerializedObjects(new Integer(300), new Double(200), new B());
}

View File

@@ -82,21 +82,19 @@ public class BoundKeyParams {
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 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 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 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 }});
{ new RedisAtomicLong("bound:key:longSrp", srpConnFactory), sof, templateSRP }, { listSRP, sof, templateSRP },
{ setSRP, sof, templateSRP }, { mapSRP, sof, templateSRP } });
}
}

View File

@@ -40,8 +40,8 @@ public abstract class AtomicCountersParam {
jedisConnFactory.afterPropertiesSet();
// JRedis
JredisConnectionFactory jredisConnFactory = new JredisConnectionFactory(new JredisPool(
SettingsUtils.getHost(), SettingsUtils.getPort()));
JredisConnectionFactory jredisConnFactory = new JredisConnectionFactory(new JredisPool(SettingsUtils.getHost(),
SettingsUtils.getPort()));
jredisConnFactory.afterPropertiesSet();
// Lettuce
@@ -56,8 +56,7 @@ public abstract class AtomicCountersParam {
srpConnFactory.setHostName(SettingsUtils.getHost());
srpConnFactory.afterPropertiesSet();
return Arrays.asList(new Object[][] { { jedisConnFactory },
{ jredisConnFactory}, { lettuceConnFactory },
{ srpConnFactory} });
return Arrays.asList(new Object[][] { { jedisConnFactory }, { jredisConnFactory }, { lettuceConnFactory },
{ srpConnFactory } });
}
}

View File

@@ -40,7 +40,7 @@ import org.springframework.data.redis.connection.RedisConnectionFactory;
/**
* Integration test of {@link RedisAtomicDouble}
*
*
* @author Jennifer Hickey
*/
@RunWith(Parameterized.class)

View File

@@ -38,7 +38,7 @@ import org.springframework.data.redis.connection.RedisConnectionFactory;
/**
* Integration test of {@link RedisAtomicInteger}
*
*
* @author Costin Leau
* @author Jennifer Hickey
*/

View File

@@ -35,7 +35,7 @@ import org.springframework.data.redis.connection.RedisConnectionFactory;
/**
* Integration test of {@link RedisAtomicLong}
*
*
* @author Costin Leau
* @author Jennifer Hickey
*/

View File

@@ -15,7 +15,6 @@
*/
package org.springframework.data.redis.support.collections;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.not;
@@ -48,10 +47,9 @@ import org.springframework.data.redis.connection.RedisConnection;
import org.springframework.data.redis.core.RedisCallback;
import org.springframework.data.redis.core.RedisTemplate;
/**
* Base test for Redis collections.
*
*
* @author Costin Leau
*/
@RunWith(Parameterized.class)
@@ -59,8 +57,7 @@ public abstract class AbstractRedisCollectionTests<T> {
protected AbstractRedisCollection<T> collection;
protected ObjectFactory<T> factory;
@SuppressWarnings("rawtypes")
protected RedisTemplate template;
@SuppressWarnings("rawtypes") protected RedisTemplate template;
@Before
public void setUp() throws Exception {
@@ -71,7 +68,6 @@ public abstract class AbstractRedisCollectionTests<T> {
abstract RedisStore copyStore(RedisStore store);
@SuppressWarnings("rawtypes")
public AbstractRedisCollectionTests(ObjectFactory<T> factory, RedisTemplate template) {
this.factory = factory;
@@ -91,6 +87,7 @@ public abstract class AbstractRedisCollectionTests<T> {
/**
* Return a new instance of T
*
* @return
*/
protected T getT() {
@@ -104,7 +101,6 @@ public abstract class AbstractRedisCollectionTests<T> {
collection.getOperations().delete(Collections.singleton(collection.getKey()));
template.execute(new RedisCallback<Object>() {
public Object doInRedis(RedisConnection connection) {
connection.flushDb();
return null;
@@ -164,13 +160,13 @@ public abstract class AbstractRedisCollectionTests<T> {
List<T> list = Arrays.asList(t1, t2, t3);
assertThat(collection.addAll(list), is(true));
assertThat(collection, hasItems((T[])list.toArray()));
assertThat(collection, hasItems((T[]) list.toArray()));
assertThat(collection, hasItems(t1, t2, t3));
}
@Test
public void testEquals() {
//assertEquals(collection, copyStore(collection));
// assertEquals(collection, copyStore(collection));
}
@Test
@@ -237,7 +233,7 @@ public abstract class AbstractRedisCollectionTests<T> {
List<T> list = Arrays.asList(t1, t2, t3);
assertThat(collection.addAll(list), is(true));
assertThat(collection, hasItems((T[])list.toArray()));
assertThat(collection, hasItems((T[]) list.toArray()));
assertThat(collection, hasItems(t1, t2, t3));
List<T> newList = Arrays.asList(getT(), getT());
@@ -251,7 +247,7 @@ public abstract class AbstractRedisCollectionTests<T> {
assertThat(collection, not(hasItems(t2, t3)));
}
//@Test(expected = UnsupportedOperationException.class)
// @Test(expected = UnsupportedOperationException.class)
@SuppressWarnings("unchecked")
public void testRetainAll() {
T t1 = getT();
@@ -314,4 +310,4 @@ public abstract class AbstractRedisCollectionTests<T> {
public void testGetKey() throws Exception {
assertNotNull(collection.getKey());
}
}
}

View File

@@ -50,7 +50,7 @@ public abstract class AbstractRedisListTests<T> extends AbstractRedisCollectionT
/**
* Constructs a new <code>AbstractRedisListTests</code> instance.
*
*
* @param factory
* @param template
*/
@@ -546,4 +546,4 @@ public abstract class AbstractRedisListTests<T> extends AbstractRedisCollectionT
public void testTakeLast() {
testPollLast();
}
}
}

View File

@@ -69,8 +69,7 @@ public abstract class AbstractRedisMapTests<K, V> {
protected RedisMap<K, V> map;
protected ObjectFactory<K> keyFactory;
protected ObjectFactory<V> valueFactory;
@SuppressWarnings("rawtypes")
protected RedisTemplate template;
@SuppressWarnings("rawtypes") protected RedisTemplate template;
abstract RedisMap<K, V> createMap();
@@ -112,7 +111,6 @@ public abstract class AbstractRedisMapTests<K, V> {
map.getOperations().delete(Collections.singleton(map.getKey()));
template.execute(new RedisCallback<Object>() {
public Object doInRedis(RedisConnection connection) {
connection.flushDb();
return null;
@@ -204,8 +202,8 @@ public abstract class AbstractRedisMapTests<K, V> {
@Test
public void testIncrementNotNumber() {
assumeTrue(!ConnectionUtils.isJredis(template.getConnectionFactory()) &&
!(valueFactory instanceof LongAsStringObjectFactory));
assumeTrue(!ConnectionUtils.isJredis(template.getConnectionFactory())
&& !(valueFactory instanceof LongAsStringObjectFactory));
K k1 = getKey();
V v1 = getValue();
@@ -226,18 +224,18 @@ public abstract class AbstractRedisMapTests<K, V> {
K k1 = getKey();
V v1 = getValue();
map.put(k1, v1);
assertEquals(Long.valueOf(Long.valueOf((String)v1) + 10), map.increment(k1, 10));
assertEquals(Long.valueOf(Long.valueOf((String) v1) + 10), map.increment(k1, 10));
}
@Test
public void testIncrementDouble() {
assumeTrue(RedisVersionUtils.atLeast("2.6", template.getConnectionFactory().getConnection()) &&
valueFactory instanceof DoubleAsStringObjectFactory);
assumeTrue(RedisVersionUtils.atLeast("2.6", template.getConnectionFactory().getConnection())
&& valueFactory instanceof DoubleAsStringObjectFactory);
K k1 = getKey();
V v1 = getValue();
map.put(k1, v1);
DecimalFormat twoDForm = new DecimalFormat("#.##");
assertEquals(twoDForm.format(Double.valueOf((String)v1) + 3.4), twoDForm.format(map.increment(k1, 3.4)));
assertEquals(twoDForm.format(Double.valueOf((String) v1) + 3.4), twoDForm.format(map.increment(k1, 3.4)));
}
@Test
@@ -430,7 +428,7 @@ public abstract class AbstractRedisMapTests<K, V> {
assertNull(map.get(k1));
}
@Test(expected=NullPointerException.class)
@Test(expected = NullPointerException.class)
public void testRemoveNullValue() {
map.remove(getKey(), null);
}
@@ -452,12 +450,12 @@ public abstract class AbstractRedisMapTests<K, V> {
assertThat(map.get(k1), isEqual(v2));
}
@Test(expected=NullPointerException.class)
@Test(expected = NullPointerException.class)
public void testReplaceNullOldValue() {
map.replace(getKey(), null, getValue());
}
@Test(expected=NullPointerException.class)
@Test(expected = NullPointerException.class)
public void testReplaceNullNewValue() {
map.replace(getKey(), getValue(), null);
}
@@ -476,8 +474,8 @@ public abstract class AbstractRedisMapTests<K, V> {
assertThat(map.get(k1), isEqual(v2));
}
@Test(expected=NullPointerException.class)
@Test(expected = NullPointerException.class)
public void testReplaceNullValue() {
map.replace(getKey(), null);
}
}
}

View File

@@ -43,10 +43,9 @@ public abstract class AbstractRedisSetTests<T> extends AbstractRedisCollectionTe
protected RedisSet<T> set;
/**
* Constructs a new <code>AbstractRedisSetTests</code> instance.
*
*
* @param factory
* @param template
*/
@@ -55,7 +54,6 @@ public abstract class AbstractRedisSetTests<T> extends AbstractRedisCollectionTe
super(factory, template);
}
@SuppressWarnings("unchecked")
@Before
public void setUp() throws Exception {
@@ -142,7 +140,6 @@ public abstract class AbstractRedisSetTests<T> extends AbstractRedisCollectionTe
assertThat(inter, hasItem(t2));
}
@SuppressWarnings("unchecked")
public void testIntersectAndStore() {
RedisSet<T> intSet1 = createSetFor("test:set:int1");
@@ -230,15 +227,14 @@ public abstract class AbstractRedisSetTests<T> extends AbstractRedisCollectionTe
assertThat(collection.addAll(list), is(true));
Iterator<T> iterator = collection.iterator();
List<T> result = new ArrayList<T>(list);
while (iterator.hasNext()) {
T expected = iterator.next();
Iterator<T> resultItr = result.iterator();
while(resultItr.hasNext()) {
while (resultItr.hasNext()) {
T obj = resultItr.next();
if(isEqual(expected).matches(obj)) {
if (isEqual(expected).matches(obj)) {
resultItr.remove();
}
}
@@ -261,9 +257,9 @@ public abstract class AbstractRedisSetTests<T> extends AbstractRedisCollectionTe
for (int i = 0; i < array.length; i++) {
Iterator<T> resultItr = result.iterator();
while(resultItr.hasNext()) {
while (resultItr.hasNext()) {
T obj = resultItr.next();
if(isEqual(array[i]).matches(obj)) {
if (isEqual(array[i]).matches(obj)) {
resultItr.remove();
}
}
@@ -285,9 +281,9 @@ public abstract class AbstractRedisSetTests<T> extends AbstractRedisCollectionTe
for (int i = 0; i < array.length; i++) {
Iterator<T> resultItr = result.iterator();
while(resultItr.hasNext()) {
while (resultItr.hasNext()) {
T obj = resultItr.next();
if(isEqual(array[i]).matches(obj)) {
if (isEqual(array[i]).matches(obj)) {
resultItr.remove();
}
}
@@ -295,4 +291,4 @@ public abstract class AbstractRedisSetTests<T> extends AbstractRedisCollectionTe
assertEquals(0, result.size());
}
}
}

View File

@@ -50,7 +50,7 @@ public abstract class AbstractRedisZSetTest<T> extends AbstractRedisCollectionTe
/**
* Constructs a new <code>AbstractRedisZSetTest</code> instance.
*
*
* @param factory
* @param template
*/
@@ -100,7 +100,6 @@ public abstract class AbstractRedisZSetTest<T> extends AbstractRedisCollectionTe
assertEquals(d, zSet.score(t3));
}
@Test
public void testFirst() {
T t1 = getT();
@@ -153,7 +152,7 @@ public abstract class AbstractRedisZSetTest<T> extends AbstractRedisCollectionTe
assertEquals(Long.valueOf(1), zSet.rank(t2));
assertEquals(Long.valueOf(2), zSet.rank(t3));
assertNull(zSet.rank(getT()));
//assertNull();
// assertNull();
}
@Test
@@ -520,4 +519,4 @@ public abstract class AbstractRedisZSetTest<T> extends AbstractRedisCollectionTe
Object[] array = collection.toArray(new Object[zSet.size()]);
assertArrayEquals(new Object[] { t1, t2, t3, t4 }, array);
}
}
}

View File

@@ -69,7 +69,6 @@ public class RedisCollectionFactoryBeanTests {
// clean up the whole db
template.execute(new RedisCallback<Object>() {
public Object doInRedis(RedisConnection connection) {
connection.flushDb();
return null;
@@ -109,7 +108,6 @@ public class RedisCollectionFactoryBeanTests {
assertThat(store, instanceOf(DefaultRedisList.class));
}
@Test
public void testExistingCol() throws Exception {
String key = "set";
@@ -128,4 +126,4 @@ public class RedisCollectionFactoryBeanTests {
assertThat(col, is(RedisProperties.class));
}
}
}

View File

@@ -22,7 +22,7 @@ import org.springframework.data.redis.support.collections.DefaultRedisList;
import org.springframework.data.redis.support.collections.RedisStore;
/**
* Parameterized instance of Redis tests.
* Parameterized instance of Redis tests.
*
* @author Costin Leau
*/
@@ -30,7 +30,7 @@ public class RedisListTests extends AbstractRedisListTests<Object> {
/**
* Constructs a new <code>RedisListTests</code> instance.
*
*
* @param factory
* @param connFactory
*/
@@ -38,14 +38,12 @@ public class RedisListTests extends AbstractRedisListTests<Object> {
super(factory, template);
}
RedisStore copyStore(RedisStore store) {
return new DefaultRedisList(store.getKey().toString(), store.getOperations());
}
AbstractRedisCollection<Object> createCollection() {
String redisName = getClass().getName();
return new DefaultRedisList(redisName, template);
}
}
}

View File

@@ -67,7 +67,7 @@ public class RedisMapTests extends AbstractRedisMapTests<Object, Object> {
@SuppressWarnings("rawtypes")
@Parameters
public static Collection<Object[]> testParams() {
// XStream serializer
XStreamMarshaller xstream = new XStreamMarshaller();
try {

View File

@@ -225,7 +225,7 @@ public class RedisPropertiesTests extends RedisMapTests {
*/
@Parameters
public static Collection<Object[]> testParams() {
// XStream serializer
XStreamMarshaller xstream = new XStreamMarshaller();
try {

View File

@@ -30,7 +30,7 @@ public class RedisSetTests extends AbstractRedisSetTests<Object> {
/**
* Constructs a new <code>RedisSetTests</code> instance.
*
*
* @param factory
* @param template
*/
@@ -38,12 +38,10 @@ public class RedisSetTests extends AbstractRedisSetTests<Object> {
super(factory, template);
}
RedisStore copyStore(RedisStore store) {
return new DefaultRedisSet(store.getKey().toString(), store.getOperations());
}
AbstractRedisCollection<Object> createCollection() {
String redisName = getClass().getName();
return new DefaultRedisSet(redisName, template);

View File

@@ -30,7 +30,7 @@ public class RedisZSetTests extends AbstractRedisZSetTest<Object> {
/**
* Constructs a new <code>RedisZSetTests</code> instance.
*
*
* @param factory
* @param template
*/
@@ -38,12 +38,10 @@ public class RedisZSetTests extends AbstractRedisZSetTest<Object> {
super(factory, template);
}
RedisStore copyStore(RedisStore store) {
return new DefaultRedisZSet(store.getKey().toString(), store.getOperations());
}
AbstractRedisCollection<Object> createCollection() {
String redisName = getClass().getName();
return new DefaultRedisZSet(redisName, template);