Add tests of RedisTemplate with binary key/values
DATAREDIS-227
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Copyright 2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.data.redis;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Implementation of {@link ObjectFactory} that returns random byte[]s
|
||||
*
|
||||
* @author Jennifer Hickey
|
||||
*
|
||||
*/
|
||||
public class RawObjectFactory implements ObjectFactory<byte[]> {
|
||||
|
||||
public byte[] instance() {
|
||||
return UUID.randomUUID().toString().getBytes();
|
||||
}
|
||||
}
|
||||
@@ -20,6 +20,8 @@ import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.springframework.data.redis.matcher.RedisTestMatchers.isEqual;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -49,7 +51,9 @@ public abstract class AbstractNativeCacheTest<T> {
|
||||
|
||||
protected abstract Cache createCache(T nativeCache);
|
||||
|
||||
protected abstract Object getObject();
|
||||
protected abstract Object getKey();
|
||||
|
||||
protected abstract Object getValue();
|
||||
|
||||
@Test
|
||||
public void testCacheName() throws Exception {
|
||||
@@ -63,15 +67,15 @@ public abstract class AbstractNativeCacheTest<T> {
|
||||
|
||||
@Test
|
||||
public void testCachePut() throws Exception {
|
||||
Object key = getObject();
|
||||
Object value = getObject();
|
||||
Object key = getKey();
|
||||
Object value = getValue();
|
||||
|
||||
assertNotNull(value);
|
||||
assertNull(cache.get(key));
|
||||
cache.put(key, value);
|
||||
ValueWrapper valueWrapper = cache.get(key);
|
||||
if (valueWrapper != null) {
|
||||
assertEquals(value, valueWrapper.get());
|
||||
assertThat(valueWrapper.get(), isEqual(value));
|
||||
}
|
||||
// keeps failing on the CI server so do
|
||||
else {
|
||||
@@ -83,12 +87,12 @@ public abstract class AbstractNativeCacheTest<T> {
|
||||
|
||||
@Test
|
||||
public void testCacheClear() throws Exception {
|
||||
Object key1 = getObject();
|
||||
Object value1 = getObject();
|
||||
Object key1 = getKey();
|
||||
Object value1 = getValue();
|
||||
|
||||
|
||||
Object key2 = getObject();
|
||||
Object value2 = getObject();
|
||||
Object key2 = getKey();
|
||||
Object value2 = getValue();
|
||||
|
||||
assertNull(cache.get(key1));
|
||||
cache.put(key1, value1);
|
||||
|
||||
@@ -16,12 +16,12 @@
|
||||
|
||||
package org.springframework.data.redis.cache;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assume.assumeTrue;
|
||||
import static org.springframework.data.redis.matcher.RedisTestMatchers.isEqual;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
@@ -39,9 +39,8 @@ import org.springframework.cache.Cache.ValueWrapper;
|
||||
import org.springframework.cache.CacheManager;
|
||||
import org.springframework.data.redis.ConnectionFactoryTracker;
|
||||
import org.springframework.data.redis.ObjectFactory;
|
||||
import org.springframework.data.redis.connection.ConnectionUtils;
|
||||
import org.springframework.data.redis.core.AbstractOperationsTestParams;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.data.redis.support.collections.CollectionTestParams;
|
||||
|
||||
/**
|
||||
* @author Costin Leau
|
||||
@@ -51,19 +50,21 @@ import org.springframework.data.redis.support.collections.CollectionTestParams;
|
||||
@RunWith(Parameterized.class)
|
||||
public class RedisCacheTest extends AbstractNativeCacheTest<RedisTemplate> {
|
||||
|
||||
private ObjectFactory<Object> objFactory;
|
||||
private ObjectFactory<Object> keyFactory;
|
||||
private ObjectFactory<Object> valueFactory;
|
||||
private RedisTemplate template;
|
||||
|
||||
|
||||
public RedisCacheTest(ObjectFactory<Object> objFactory, RedisTemplate template) {
|
||||
this.objFactory = objFactory;
|
||||
public RedisCacheTest(RedisTemplate template, ObjectFactory<Object> keyFactory, ObjectFactory<Object> valueFactory) {
|
||||
this.keyFactory = keyFactory;
|
||||
this.valueFactory = valueFactory;
|
||||
this.template = template;
|
||||
ConnectionFactoryTracker.add(template.getConnectionFactory());
|
||||
}
|
||||
|
||||
@Parameters
|
||||
public static Collection<Object[]> testParams() {
|
||||
return CollectionTestParams.testParams();
|
||||
return AbstractOperationsTestParams.testParams();
|
||||
}
|
||||
|
||||
|
||||
@@ -80,7 +81,6 @@ public class RedisCacheTest extends AbstractNativeCacheTest<RedisTemplate> {
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
assumeTrue(!ConnectionUtils.isJredis(template.getConnectionFactory()));
|
||||
ConnectionFactoryTracker.add(template.getConnectionFactory());
|
||||
super.setUp();
|
||||
}
|
||||
@@ -90,18 +90,27 @@ public class RedisCacheTest extends AbstractNativeCacheTest<RedisTemplate> {
|
||||
ConnectionFactoryTracker.cleanUp();
|
||||
}
|
||||
|
||||
protected Object getValue() {
|
||||
return valueFactory.instance();
|
||||
}
|
||||
|
||||
protected Object getObject() {
|
||||
return objFactory.instance();
|
||||
protected Object getKey() {
|
||||
return keyFactory.instance();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConcurrentRead() throws Exception {
|
||||
final Object key1 = getObject();
|
||||
final Object value1 = getObject();
|
||||
final Object key1 = getKey();
|
||||
final Object value1 = getValue();
|
||||
|
||||
final Object key2 = getObject();
|
||||
final Object value2 = getObject();
|
||||
final Object k1 = getKey();
|
||||
final Object v1 = getValue();
|
||||
|
||||
final Object key2 = getKey();
|
||||
final Object value2 = getValue();
|
||||
|
||||
final Object k2 = getKey();
|
||||
final Object v2 = getValue();
|
||||
|
||||
final AtomicBoolean failed = new AtomicBoolean(true);
|
||||
cache.put(key1, value1);
|
||||
@@ -110,9 +119,9 @@ public class RedisCacheTest extends AbstractNativeCacheTest<RedisTemplate> {
|
||||
Thread th = new Thread(new Runnable() {
|
||||
public void run() {
|
||||
cache.clear();
|
||||
cache.put(value1, key1);
|
||||
cache.put(value2, key2);
|
||||
failed.set(key1.equals(cache.get(value1)));
|
||||
cache.put(k1, v1);
|
||||
cache.put(k2, v2);
|
||||
failed.set(v1.equals(cache.get(k1)));
|
||||
|
||||
}
|
||||
}, "concurrent-cache-access");
|
||||
@@ -121,17 +130,19 @@ public class RedisCacheTest extends AbstractNativeCacheTest<RedisTemplate> {
|
||||
|
||||
assertFalse(failed.get());
|
||||
|
||||
final Object key3 = getObject();
|
||||
final Object value3 = getObject();
|
||||
final Object key3 = getKey();
|
||||
final Object key4 = getKey();
|
||||
final Object value3 = getValue();
|
||||
final Object value4 = getValue();
|
||||
|
||||
cache.put(key3, value3);
|
||||
cache.put(value3, key3);
|
||||
cache.put(key4, value4);
|
||||
|
||||
assertNull(cache.get(key1));
|
||||
assertNull(cache.get(key2));
|
||||
ValueWrapper valueWrapper = cache.get(value1);
|
||||
ValueWrapper valueWrapper = cache.get(k1);
|
||||
assertNotNull(valueWrapper);
|
||||
assertEquals(key1, valueWrapper.get());
|
||||
assertThat(valueWrapper.get(), isEqual(v1));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -145,6 +156,8 @@ public class RedisCacheTest extends AbstractNativeCacheTest<RedisTemplate> {
|
||||
|
||||
@Test
|
||||
public void testGetWhileClear() throws InterruptedException {
|
||||
final Object key1 = getKey();
|
||||
final Object value1 = getValue();
|
||||
int numTries = 10;
|
||||
final AtomicBoolean monitorStateException = new AtomicBoolean(false);
|
||||
final CountDownLatch latch = new CountDownLatch(numTries);
|
||||
@@ -156,7 +169,7 @@ public class RedisCacheTest extends AbstractNativeCacheTest<RedisTemplate> {
|
||||
Runnable putCache = new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
cache.put("foo", "bar");
|
||||
cache.put(key1, value1);
|
||||
}catch(IllegalMonitorStateException e) {
|
||||
monitorStateException.set(true);
|
||||
} finally {
|
||||
|
||||
@@ -21,11 +21,17 @@ import java.util.Collection;
|
||||
import org.springframework.data.redis.DoubleObjectFactory;
|
||||
import org.springframework.data.redis.LongObjectFactory;
|
||||
import org.springframework.data.redis.ObjectFactory;
|
||||
import org.springframework.data.redis.Person;
|
||||
import org.springframework.data.redis.PersonObjectFactory;
|
||||
import org.springframework.data.redis.RawObjectFactory;
|
||||
import org.springframework.data.redis.SettingsUtils;
|
||||
import org.springframework.data.redis.StringObjectFactory;
|
||||
import org.springframework.data.redis.connection.srp.SrpConnectionFactory;
|
||||
import org.springframework.data.redis.serializer.GenericToStringSerializer;
|
||||
import org.springframework.data.redis.serializer.JacksonJsonRedisSerializer;
|
||||
import org.springframework.data.redis.serializer.OxmSerializer;
|
||||
import org.springframework.data.redis.serializer.StringRedisSerializer;
|
||||
import org.springframework.oxm.xstream.XStreamMarshaller;
|
||||
|
||||
/**
|
||||
* Parameters for testing implementations of {@link AbstractOperations}
|
||||
@@ -39,25 +45,69 @@ abstract public class AbstractOperationsTestParams {
|
||||
ObjectFactory<String> stringFactory = new StringObjectFactory();
|
||||
ObjectFactory<Long> longFactory = new LongObjectFactory();
|
||||
ObjectFactory<Double> doubleFactory = new DoubleObjectFactory();
|
||||
ObjectFactory<byte[]> rawFactory = new RawObjectFactory();
|
||||
ObjectFactory<Person> personFactory = new PersonObjectFactory();
|
||||
|
||||
// XStream serializer
|
||||
XStreamMarshaller xstream = new XStreamMarshaller();
|
||||
try {
|
||||
xstream.afterPropertiesSet();
|
||||
} catch (Exception ex) {
|
||||
throw new RuntimeException("Cannot init XStream", ex);
|
||||
}
|
||||
|
||||
OxmSerializer serializer = new OxmSerializer(xstream, xstream);
|
||||
JacksonJsonRedisSerializer<Person> jsonSerializer = new JacksonJsonRedisSerializer<Person>(Person.class);
|
||||
|
||||
SrpConnectionFactory srConnFactory = new SrpConnectionFactory();
|
||||
srConnFactory.setPort(SettingsUtils.getPort());
|
||||
srConnFactory.setHostName(SettingsUtils.getHost());
|
||||
srConnFactory.afterPropertiesSet();
|
||||
|
||||
RedisTemplate<String,String> stringTemplate = new StringRedisTemplate();
|
||||
stringTemplate.setConnectionFactory(srConnFactory);
|
||||
stringTemplate.afterPropertiesSet();
|
||||
|
||||
RedisTemplate<String,Long> longTemplate = new RedisTemplate<String,Long>();
|
||||
longTemplate.setKeySerializer(new StringRedisSerializer());
|
||||
longTemplate.setValueSerializer(new GenericToStringSerializer<Long>(Long.class));
|
||||
longTemplate.setConnectionFactory(srConnFactory);
|
||||
longTemplate.afterPropertiesSet();
|
||||
|
||||
RedisTemplate<String,Double> doubleTemplate = new RedisTemplate<String,Double>();
|
||||
doubleTemplate.setKeySerializer(new StringRedisSerializer());
|
||||
doubleTemplate.setValueSerializer(new GenericToStringSerializer<Double>(Double.class));
|
||||
doubleTemplate.setConnectionFactory(srConnFactory);
|
||||
doubleTemplate.afterPropertiesSet();
|
||||
|
||||
RedisTemplate<byte[],byte[]> rawTemplate = new RedisTemplate<byte[],byte[]>();
|
||||
rawTemplate.setEnableDefaultSerializer(false);
|
||||
rawTemplate.setConnectionFactory(srConnFactory);
|
||||
rawTemplate.afterPropertiesSet();
|
||||
|
||||
RedisTemplate<String, Person> personTemplate = new RedisTemplate<String, Person>();
|
||||
personTemplate.setConnectionFactory(srConnFactory);
|
||||
personTemplate.afterPropertiesSet();
|
||||
|
||||
RedisTemplate<String, String> xstreamStringTemplate = new RedisTemplate<String, String>();
|
||||
xstreamStringTemplate.setConnectionFactory(srConnFactory);
|
||||
xstreamStringTemplate.setDefaultSerializer(serializer);
|
||||
xstreamStringTemplate.afterPropertiesSet();
|
||||
|
||||
RedisTemplate<String, Person> xstreamPersonTemplate = new RedisTemplate<String, Person>();
|
||||
xstreamPersonTemplate.setConnectionFactory(srConnFactory);
|
||||
xstreamPersonTemplate.setValueSerializer(serializer);
|
||||
xstreamPersonTemplate.afterPropertiesSet();
|
||||
|
||||
RedisTemplate<String, Person> jsonPersonTemplate = new RedisTemplate<String, Person>();
|
||||
jsonPersonTemplate.setConnectionFactory(srConnFactory);
|
||||
jsonPersonTemplate.setValueSerializer(jsonSerializer);
|
||||
jsonPersonTemplate.afterPropertiesSet();
|
||||
|
||||
return Arrays.asList(new Object[][] { { stringTemplate, stringFactory, stringFactory },
|
||||
{ longTemplate, stringFactory, longFactory }, { doubleTemplate, stringFactory, doubleFactory }
|
||||
});
|
||||
{ longTemplate, stringFactory, longFactory }, { doubleTemplate, stringFactory, doubleFactory },
|
||||
{ rawTemplate, rawFactory, rawFactory}, { personTemplate, stringFactory, personFactory },
|
||||
{ xstreamStringTemplate, stringFactory, stringFactory }, { xstreamPersonTemplate, stringFactory, personFactory },
|
||||
{ jsonPersonTemplate, stringFactory, personFactory }});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,9 +15,12 @@
|
||||
*/
|
||||
package org.springframework.data.redis.core;
|
||||
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.springframework.data.redis.matcher.RedisTestMatchers.isEqual;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.After;
|
||||
@@ -27,11 +30,11 @@ import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
import org.junit.runners.Parameterized.Parameters;
|
||||
import org.springframework.data.redis.ObjectFactory;
|
||||
import org.springframework.data.redis.RawObjectFactory;
|
||||
import org.springframework.data.redis.SettingsUtils;
|
||||
import org.springframework.data.redis.StringObjectFactory;
|
||||
import org.springframework.data.redis.connection.RedisConnection;
|
||||
import org.springframework.data.redis.connection.srp.SrpConnectionFactory;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* Integration test of {@link DefaultHashOperations}
|
||||
@@ -65,14 +68,24 @@ public class DefaultHashOperationsTests<K,HK,HV> {
|
||||
@Parameters
|
||||
public static Collection<Object[]> testParams() {
|
||||
ObjectFactory<String> stringFactory = new StringObjectFactory();
|
||||
ObjectFactory<byte[]> rawFactory = new RawObjectFactory();
|
||||
|
||||
SrpConnectionFactory srConnFactory = new SrpConnectionFactory();
|
||||
srConnFactory.setPort(SettingsUtils.getPort());
|
||||
srConnFactory.setHostName(SettingsUtils.getHost());
|
||||
srConnFactory.afterPropertiesSet();
|
||||
|
||||
RedisTemplate<String,String> stringTemplate = new StringRedisTemplate();
|
||||
stringTemplate.setConnectionFactory(srConnFactory);
|
||||
stringTemplate.afterPropertiesSet();
|
||||
return Arrays.asList(new Object[][] { { stringTemplate, stringFactory, stringFactory, stringFactory }});
|
||||
|
||||
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 }});
|
||||
}
|
||||
|
||||
@Before
|
||||
@@ -99,9 +112,9 @@ 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 HashMap<HK,HV>();
|
||||
Map<HK,HV> expected = new LinkedHashMap<HK,HV>();
|
||||
expected.put(key1, val1);
|
||||
expected.put(key2, val2);
|
||||
assertEquals(expected, hashOps.entries(key));
|
||||
assertThat(hashOps.entries(key), isEqual(expected));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,8 @@ package org.springframework.data.redis.core;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assume.assumeTrue;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.springframework.data.redis.matcher.RedisTestMatchers.isEqual;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
@@ -90,7 +92,7 @@ public class DefaultListOperationsTests<K,V> {
|
||||
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));
|
||||
assertEquals(Arrays.asList(new Object[] {v2, v3, v1}),listOps.range(key, 0, -1));
|
||||
assertThat(listOps.range(key, 0, -1), isEqual(Arrays.asList(new Object[] {v2, v3, v1})));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -101,7 +103,7 @@ public class DefaultListOperationsTests<K,V> {
|
||||
assertEquals(Long.valueOf(0), listOps.leftPushIfPresent(key, v1));
|
||||
assertEquals(Long.valueOf(1),listOps.leftPush(key, v1));
|
||||
assertEquals(Long.valueOf(2),listOps.leftPushIfPresent(key, v2));
|
||||
assertEquals(Arrays.asList(new Object[] {v2, v1}),listOps.range(key, 0, -1));
|
||||
assertThat(listOps.range(key, 0, -1), isEqual(Arrays.asList(new Object[] {v2, v1})));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -113,7 +115,7 @@ public class DefaultListOperationsTests<K,V> {
|
||||
V v1 = valueFactory.instance();
|
||||
assertNull(listOps.rightPopAndLeftPush(key, key2, 1, TimeUnit.MILLISECONDS));
|
||||
listOps.leftPush(key, v1);
|
||||
assertEquals(v1, listOps.rightPopAndLeftPush(key, key2, 1, TimeUnit.MILLISECONDS));
|
||||
assertThat(listOps.rightPopAndLeftPush(key, key2, 1, TimeUnit.MILLISECONDS), isEqual(v1));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -123,7 +125,7 @@ public class DefaultListOperationsTests<K,V> {
|
||||
V v1 = valueFactory.instance();
|
||||
assertNull(listOps.rightPopAndLeftPush(key, key2));
|
||||
listOps.leftPush(key, v1);
|
||||
assertEquals(v1, listOps.rightPopAndLeftPush(key, key2));
|
||||
assertThat(listOps.rightPopAndLeftPush(key, key2), isEqual(v1));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -135,7 +137,8 @@ public class DefaultListOperationsTests<K,V> {
|
||||
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));
|
||||
assertEquals(Arrays.asList(new Object[] {v1, v3, v2}),listOps.range(key, 0, -1));
|
||||
assertThat(listOps.range(key, 0, -1),
|
||||
isEqual(Arrays.asList(new Object[] {v1, v3, v2})));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -146,6 +149,7 @@ public class DefaultListOperationsTests<K,V> {
|
||||
assertEquals(Long.valueOf(0), listOps.rightPushIfPresent(key, v1));
|
||||
assertEquals(Long.valueOf(1),listOps.rightPush(key, v1));
|
||||
assertEquals(Long.valueOf(2),listOps.rightPushIfPresent(key, v2));
|
||||
assertEquals(Arrays.asList(new Object[] {v1, v2}),listOps.range(key, 0, -1));
|
||||
assertThat(listOps.range(key, 0, -1),
|
||||
isEqual(Arrays.asList(new Object[] {v1, v2})));
|
||||
}
|
||||
}
|
||||
@@ -19,6 +19,8 @@ import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.junit.Assume.assumeTrue;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.springframework.data.redis.matcher.RedisTestMatchers.isEqual;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
@@ -135,10 +137,10 @@ public class DefaultSetOperationsTests<K,V> {
|
||||
setOps.add(key1, v1);
|
||||
setOps.add(key1, v2);
|
||||
setOps.move(key1, v1, key2);
|
||||
assertEquals(new HashSet<V>(Collections.singletonList(v2)),
|
||||
setOps.members(key1));
|
||||
assertEquals(new HashSet<V>(Collections.singletonList(v1)),
|
||||
setOps.members(key2));
|
||||
assertThat(setOps.members(key1),
|
||||
isEqual(new HashSet<V>(Collections.singletonList(v2))));
|
||||
assertThat(setOps.members(key2),
|
||||
isEqual(new HashSet<V>(Collections.singletonList(v1))));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -146,7 +148,7 @@ public class DefaultSetOperationsTests<K,V> {
|
||||
K key = keyFactory.instance();
|
||||
V v1 = valueFactory.instance();
|
||||
setOps.add(key, v1);
|
||||
assertEquals(v1, setOps.pop(key));
|
||||
assertThat(setOps.pop(key), isEqual(v1));
|
||||
assertTrue(setOps.members(key).isEmpty());
|
||||
}
|
||||
|
||||
@@ -154,12 +156,7 @@ public class DefaultSetOperationsTests<K,V> {
|
||||
public void testRandomMember() {
|
||||
K key = keyFactory.instance();
|
||||
V v1 = valueFactory.instance();
|
||||
V v2 = valueFactory.instance();
|
||||
setOps.add(key, v1);
|
||||
setOps.add(key, v2);
|
||||
HashSet<V> expected = new HashSet<V>();
|
||||
expected.add(v1);
|
||||
expected.add(v2);
|
||||
assertTrue(expected.contains(setOps.randomMember(key)));
|
||||
assertThat(setOps.randomMember(key), isEqual(v1));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,16 +17,18 @@ package org.springframework.data.redis.core;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assume.assumeTrue;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.springframework.data.redis.SpinBarrier.waitFor;
|
||||
import static org.springframework.data.redis.matcher.RedisTestMatchers.isEqual;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@@ -36,17 +38,10 @@ import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
import org.junit.runners.Parameterized.Parameters;
|
||||
import org.springframework.data.redis.DoubleObjectFactory;
|
||||
import org.springframework.data.redis.LongObjectFactory;
|
||||
import org.springframework.data.redis.ObjectFactory;
|
||||
import org.springframework.data.redis.RedisTestProfileValueSource;
|
||||
import org.springframework.data.redis.SettingsUtils;
|
||||
import org.springframework.data.redis.StringObjectFactory;
|
||||
import org.springframework.data.redis.TestCondition;
|
||||
import org.springframework.data.redis.connection.RedisConnection;
|
||||
import org.springframework.data.redis.connection.srp.SrpConnectionFactory;
|
||||
import org.springframework.data.redis.serializer.GenericToStringSerializer;
|
||||
import org.springframework.data.redis.serializer.StringRedisSerializer;
|
||||
|
||||
/**
|
||||
* Integration test of {@link DefaultValueOperations}
|
||||
@@ -128,8 +123,8 @@ public class DefaultValueOperationsTests<K,V> {
|
||||
keysAndValues.put(key1, value1);
|
||||
keysAndValues.put(key2, value2);
|
||||
assertTrue(valueOps.multiSetIfAbsent(keysAndValues));
|
||||
assertEquals(new HashSet<V>(keysAndValues.values()),
|
||||
new HashSet<V>(valueOps.multiGet(keysAndValues.keySet())));
|
||||
assertThat(valueOps.multiGet(keysAndValues.keySet()),
|
||||
isEqual(new ArrayList<V>(keysAndValues.values())));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -156,7 +151,8 @@ public class DefaultValueOperationsTests<K,V> {
|
||||
keysAndValues.put(key1, value1);
|
||||
keysAndValues.put(key2, value2);
|
||||
valueOps.multiSet(keysAndValues);
|
||||
assertEquals(new ArrayList<V>(keysAndValues.values()), valueOps.multiGet(keysAndValues.keySet()));
|
||||
assertThat(valueOps.multiGet(keysAndValues.keySet()),
|
||||
isEqual(new ArrayList<V>(keysAndValues.values())));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -164,7 +160,7 @@ public class DefaultValueOperationsTests<K,V> {
|
||||
K key1 = keyFactory.instance();
|
||||
V value1 = valueFactory.instance();
|
||||
valueOps.set(key1,value1);
|
||||
assertEquals(value1, valueOps.get(key1));
|
||||
assertThat(valueOps.get(key1), isEqual(value1));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -173,7 +169,7 @@ public class DefaultValueOperationsTests<K,V> {
|
||||
V value1 = valueFactory.instance();
|
||||
V value2 = valueFactory.instance();
|
||||
valueOps.set(key1, value1);
|
||||
assertEquals(value1, valueOps.getAndSet(key1, value2));
|
||||
assertThat(valueOps.getAndSet(key1, value2), isEqual(value1));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -194,7 +190,7 @@ public class DefaultValueOperationsTests<K,V> {
|
||||
public void testAppend() {
|
||||
K key1 = keyFactory.instance();
|
||||
V value1 = valueFactory.instance();
|
||||
assumeTrue(value1 instanceof String);
|
||||
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));
|
||||
@@ -254,4 +250,12 @@ public class DefaultValueOperationsTests<K,V> {
|
||||
byte[][] rawKeys = ((DefaultValueOperations)valueOps).rawKeys(Arrays.asList(new Object[] {key1, key2}));
|
||||
assertEquals(2, rawKeys.length);
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
@Test
|
||||
public void testDeserializeKey() {
|
||||
K key1 = keyFactory.instance();
|
||||
assumeTrue(key1 instanceof byte[]);
|
||||
assertNotNull(((DefaultValueOperations)valueOps).deserializeKey((byte[])key1));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
package org.springframework.data.redis.core;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.springframework.data.redis.matcher.RedisTestMatchers.isEqual;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
@@ -95,8 +97,7 @@ public class DefaultZSetOperationsTests<K,V> {
|
||||
Set<TypedTuple<V>> values = zSetOps.rangeWithScores(key1, 0, -1);
|
||||
assertEquals(1,values.size());
|
||||
TypedTuple<V> tuple = values.iterator().next();
|
||||
assertEquals(value1, tuple.getValue());
|
||||
assertEquals(Double.valueOf(5.7), tuple.getScore());
|
||||
assertEquals(new DefaultTypedTuple<V>(value1, 5.7), tuple);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -108,7 +109,8 @@ public class DefaultZSetOperationsTests<K,V> {
|
||||
zSetOps.add(key, value1, 1.9);
|
||||
zSetOps.add(key, value2, 3.7);
|
||||
zSetOps.add(key, value3, 5.8);
|
||||
assertEquals(Collections.singleton(value1), zSetOps.rangeByScore(key, 1.5, 4.7, 0, 1));
|
||||
assertThat(zSetOps.rangeByScore(key, 1.5, 4.7, 0, 1),
|
||||
isEqual(Collections.singleton(value1)));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -123,8 +125,7 @@ public class DefaultZSetOperationsTests<K,V> {
|
||||
Set<TypedTuple<V>> tuples = zSetOps.rangeByScoreWithScores(key, 1.5, 4.7, 0, 1);
|
||||
assertEquals(1, tuples.size());
|
||||
TypedTuple<V> tuple = tuples.iterator().next();
|
||||
assertEquals(value1,tuple.getValue());
|
||||
assertEquals(Double.valueOf(1.9), tuple.getScore());
|
||||
assertThat(tuple, isEqual(new DefaultTypedTuple<V>(value1, 1.9)));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -136,7 +137,8 @@ public class DefaultZSetOperationsTests<K,V> {
|
||||
zSetOps.add(key, value1, 1.9);
|
||||
zSetOps.add(key, value2, 3.7);
|
||||
zSetOps.add(key, value3, 5.8);
|
||||
assertEquals(Collections.singleton(value2), zSetOps.reverseRangeByScore(key, 1.5, 4.7, 0, 1));
|
||||
assertThat(zSetOps.reverseRangeByScore(key, 1.5, 4.7, 0, 1),
|
||||
isEqual(Collections.singleton(value2)));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -151,7 +153,6 @@ public class DefaultZSetOperationsTests<K,V> {
|
||||
Set<TypedTuple<V>> tuples = zSetOps.reverseRangeByScoreWithScores(key, 1.5, 4.7, 0, 1);
|
||||
assertEquals(1, tuples.size());
|
||||
TypedTuple<V> tuple = tuples.iterator().next();
|
||||
assertEquals(value2,tuple.getValue());
|
||||
assertEquals(Double.valueOf(3.7), tuple.getScore());
|
||||
assertThat(tuple, isEqual(new DefaultTypedTuple<V>(value2, 3.7)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,12 +16,14 @@
|
||||
package org.springframework.data.redis.core;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assume.assumeTrue;
|
||||
import static org.springframework.data.redis.SpinBarrier.waitFor;
|
||||
import static org.springframework.data.redis.matcher.RedisTestMatchers.isEqual;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
@@ -169,11 +171,6 @@ public class RedisTemplateTests<K,V> {
|
||||
final V setValue = valueFactory.instance();
|
||||
final K zsetKey = keyFactory.instance();
|
||||
final V zsetValue = valueFactory.instance();
|
||||
final K mapKey = keyFactory.instance();
|
||||
final Object hashKey = deserialize(serialize("test", redisTemplate.getHashKeySerializer()),
|
||||
redisTemplate.getHashKeySerializer());
|
||||
final Object hashValue = deserialize(serialize("passed", redisTemplate.getHashValueSerializer()),
|
||||
redisTemplate.getHashValueSerializer());
|
||||
List<Object> results = redisTemplate.execute(new SessionCallback<List<Object>>() {
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
public List<Object> execute(RedisOperations operations) throws DataAccessException {
|
||||
@@ -186,8 +183,6 @@ public class RedisTemplateTests<K,V> {
|
||||
operations.opsForSet().members(setKey);
|
||||
operations.opsForZSet().add(zsetKey, zsetValue, 1d);
|
||||
operations.opsForZSet().rangeWithScores(zsetKey, 0l, -1l);
|
||||
operations.opsForHash().put(mapKey, hashKey, hashValue);
|
||||
operations.opsForHash().entries(mapKey);
|
||||
return operations.exec();
|
||||
}
|
||||
});
|
||||
@@ -195,10 +190,7 @@ public class RedisTemplateTests<K,V> {
|
||||
Set<V> set = new HashSet<V>(Collections.singletonList(setValue));
|
||||
Set<TypedTuple<V>> tupleSet = new LinkedHashSet<TypedTuple<V>>(
|
||||
Collections.singletonList(new DefaultTypedTuple<V>(zsetValue, 1d)));
|
||||
Map<Object,Object> map = new LinkedHashMap<Object,Object>();
|
||||
map.put(hashKey, hashValue);
|
||||
assertEquals(Arrays.asList(new Object[] {value1, 1l, list, true, set, true, tupleSet, true, map}),
|
||||
results);
|
||||
assertThat(results, isEqual(Arrays.asList(new Object[] {value1, 1l, list, true, set, true, tupleSet})));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -216,7 +208,7 @@ public class RedisTemplateTests<K,V> {
|
||||
return null;
|
||||
}
|
||||
});
|
||||
assertEquals(value1, redisTemplate.boundValueOps(key1).get());
|
||||
assertThat(redisTemplate.boundValueOps(key1).get(), isEqual(value1));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -248,8 +240,8 @@ public class RedisTemplateTests<K,V> {
|
||||
Set<Long> zSet = new LinkedHashSet<Long>(Collections.singletonList(9l));
|
||||
Map<Long, Long> map = new LinkedHashMap<Long,Long>();
|
||||
map.put(10l, 11l);
|
||||
assertEquals(Arrays.asList(new Object[] {5l, 1l, list, true, longSet, true, tupleSet, zSet, true, map}),
|
||||
results);
|
||||
assertThat(results,
|
||||
isEqual(Arrays.asList(new Object[] {5l, 1l, list, true, longSet, true, tupleSet, zSet, true, map})));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -292,7 +284,8 @@ public class RedisTemplateTests<K,V> {
|
||||
return null;
|
||||
}
|
||||
});
|
||||
assertEquals(Arrays.asList(new Object[] {value1, 1l, 2l, Arrays.asList(new Object[] {listValue, listValue2})}), results);
|
||||
assertThat(results,
|
||||
isEqual(Arrays.asList(new Object[] {value1, 1l, 2l, Arrays.asList(new Object[] {listValue, listValue2})})));
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
@@ -340,7 +333,7 @@ public class RedisTemplateTests<K,V> {
|
||||
}
|
||||
});
|
||||
// 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, value1, 0l}), value1}), pipelinedResults);
|
||||
assertThat(pipelinedResults, isEqual(Arrays.asList(new Object[] {Arrays.asList(new Object[] {1l, value1, 0l}), value1})));
|
||||
}
|
||||
|
||||
@SuppressWarnings({"rawtypes", "unchecked"})
|
||||
@@ -482,7 +475,7 @@ public class RedisTemplateTests<K,V> {
|
||||
K key1 = keyFactory.instance();
|
||||
V value1 = valueFactory.instance();
|
||||
redisTemplate.opsForValue().set(key1, value1);
|
||||
assertEquals(key1, redisTemplate.randomKey());
|
||||
assertThat(redisTemplate.randomKey(), isEqual(key1));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -492,7 +485,7 @@ public class RedisTemplateTests<K,V> {
|
||||
V value1 = valueFactory.instance();
|
||||
redisTemplate.opsForValue().set(key1, value1);
|
||||
redisTemplate.rename(key1, key2);
|
||||
assertEquals(value1, redisTemplate.opsForValue().get(key2));
|
||||
assertThat(redisTemplate.opsForValue().get(key2), isEqual(value1));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -540,7 +533,7 @@ public class RedisTemplateTests<K,V> {
|
||||
}
|
||||
});
|
||||
assertNull(results);
|
||||
assertEquals(value2, redisTemplate.opsForValue().get(key1));
|
||||
assertThat(redisTemplate.opsForValue().get(key1), isEqual(value2));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -571,7 +564,7 @@ public class RedisTemplateTests<K,V> {
|
||||
}
|
||||
});
|
||||
assertTrue(results.isEmpty());
|
||||
assertEquals(value3, redisTemplate.opsForValue().get(key1));
|
||||
assertThat(redisTemplate.opsForValue().get(key1), isEqual(value3));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -605,7 +598,7 @@ public class RedisTemplateTests<K,V> {
|
||||
}
|
||||
});
|
||||
assertNull(results);
|
||||
assertEquals(value2, redisTemplate.opsForValue().get(key1));
|
||||
assertThat(redisTemplate.opsForValue().get(key1), isEqual(value2));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -617,11 +610,9 @@ public class RedisTemplateTests<K,V> {
|
||||
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
private byte[] serialize(Object value, RedisSerializer serializer) {
|
||||
if(serializer == null && value instanceof byte[]) {
|
||||
return (byte[])value;
|
||||
}
|
||||
return serializer.serialize(value);
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
private Object deserialize(byte[] value, RedisSerializer serializer) {
|
||||
return serializer.deserialize(value);
|
||||
}
|
||||
}
|
||||
|
||||
131
src/test/java/org/springframework/data/redis/matcher/Equals.java
Normal file
131
src/test/java/org/springframework/data/redis/matcher/Equals.java
Normal file
@@ -0,0 +1,131 @@
|
||||
/*
|
||||
* Copyright 2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.data.redis.matcher;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.hamcrest.BaseMatcher;
|
||||
import org.hamcrest.Description;
|
||||
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())
|
||||
*
|
||||
* @author Jennifer Hickey
|
||||
*
|
||||
*/
|
||||
public class Equals extends BaseMatcher<Object> {
|
||||
|
||||
private Object expected;
|
||||
|
||||
public Equals(Object expected) {
|
||||
this.expected = expected;
|
||||
}
|
||||
|
||||
public void describeTo(Description description) {
|
||||
description.appendValue(expected);
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
public boolean matches(Object actual) {
|
||||
if (expected instanceof List) {
|
||||
return listEquals((List) expected, (List) actual);
|
||||
} else if (expected instanceof Set) {
|
||||
return setEquals((Set) expected, (Set) actual);
|
||||
} else if (expected instanceof LinkedHashMap) {
|
||||
return mapEquals((Map) expected, (Map) actual);
|
||||
} else {
|
||||
return equals(expected, actual);
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
private boolean listEquals(List expected, List actual) {
|
||||
if (expected.size() != actual.size()) {
|
||||
return false;
|
||||
}
|
||||
Iterator<Object> actualItr = actual.iterator();
|
||||
Iterator<Object> expectedItr = expected.iterator();
|
||||
while (expectedItr.hasNext()) {
|
||||
Object expectedObj = expectedItr.next();
|
||||
if (expectedObj instanceof List) {
|
||||
if (!(listEquals((List) expectedObj, (List) actualItr.next()))) {
|
||||
return false;
|
||||
}
|
||||
} else if (expectedObj instanceof Set) {
|
||||
if (!(setEquals((Set) expectedObj, (Set) actualItr.next()))) {
|
||||
return false;
|
||||
}
|
||||
} else if (expectedObj instanceof Map) {
|
||||
if (!(mapEquals((Map) expectedObj, (Map) actualItr.next()))) {
|
||||
return false;
|
||||
}
|
||||
} else if (!equals(expectedObj, actualItr.next())) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
private boolean setEquals(Set expected, Set actual) {
|
||||
if (expected.size() != actual.size()) {
|
||||
return false;
|
||||
}
|
||||
return hasItems(actual.toArray()).matches(expected);
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
private boolean mapEquals(Map expected, Map actual) {
|
||||
if (expected.size() != actual.size()) {
|
||||
return false;
|
||||
}
|
||||
Iterator actualItr = actual.entrySet().iterator();
|
||||
Iterator expectedItr = expected.entrySet().iterator();
|
||||
while (expectedItr.hasNext()) {
|
||||
Map.Entry expectedEntry = (Map.Entry) expectedItr.next();
|
||||
Map.Entry actualEntry = (Map.Entry) actualItr.next();
|
||||
if (!(equals(expectedEntry.getKey(), actualEntry.getKey()))
|
||||
|| !(equals(expectedEntry.getValue(), actualEntry.getValue()))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean equals(Object expected, Object actual) {
|
||||
if (expected == null) {
|
||||
return actual == null;
|
||||
}
|
||||
if (expected instanceof byte[]) {
|
||||
return Arrays.equals((byte[]) expected, (byte[]) actual);
|
||||
}
|
||||
return expected.equals(actual);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright 2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.data.redis.matcher;
|
||||
|
||||
import org.hamcrest.Matcher;
|
||||
|
||||
/**
|
||||
* Customs {@link Matcher}s for Redis tests
|
||||
*
|
||||
* @author Jennifer Hickey
|
||||
*
|
||||
*/
|
||||
abstract public class RedisTestMatchers {
|
||||
|
||||
/**
|
||||
*
|
||||
* @param expected
|
||||
* The expected results
|
||||
* @return The {@link Equals} matcher
|
||||
*/
|
||||
public static Matcher<Object> isEqual(Object expected) {
|
||||
return new Equals(expected);
|
||||
}
|
||||
}
|
||||
@@ -27,6 +27,7 @@ import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.matchers.JUnitMatchers.hasItem;
|
||||
import static org.junit.matchers.JUnitMatchers.hasItems;
|
||||
import static org.springframework.data.redis.matcher.RedisTestMatchers.isEqual;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
@@ -58,6 +59,7 @@ public abstract class AbstractRedisCollectionTests<T> {
|
||||
|
||||
protected AbstractRedisCollection<T> collection;
|
||||
protected ObjectFactory<T> factory;
|
||||
@SuppressWarnings("rawtypes")
|
||||
protected RedisTemplate template;
|
||||
|
||||
@Before
|
||||
@@ -70,6 +72,7 @@ public abstract class AbstractRedisCollectionTests<T> {
|
||||
abstract RedisStore copyStore(RedisStore store);
|
||||
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
public AbstractRedisCollectionTests(ObjectFactory<T> factory, RedisTemplate template) {
|
||||
this.factory = factory;
|
||||
this.template = template;
|
||||
@@ -94,6 +97,7 @@ public abstract class AbstractRedisCollectionTests<T> {
|
||||
return factory.instance();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
// remove the collection entirely since clear() doesn't always work
|
||||
@@ -160,7 +164,7 @@ public abstract class AbstractRedisCollectionTests<T> {
|
||||
List<T> list = Arrays.asList(t1, t2, t3);
|
||||
|
||||
assertThat(collection.addAll(list), is(true));
|
||||
assertThat(collection.containsAll(list), is(true));
|
||||
assertThat(collection, hasItems((T[])list.toArray()));
|
||||
assertThat(collection, hasItems(t1, t2, t3));
|
||||
}
|
||||
|
||||
@@ -185,6 +189,7 @@ public abstract class AbstractRedisCollectionTests<T> {
|
||||
assertTrue(collection.isEmpty());
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void testIterator() {
|
||||
T t1 = getT();
|
||||
@@ -197,10 +202,10 @@ public abstract class AbstractRedisCollectionTests<T> {
|
||||
assertThat(collection.addAll(list), is(true));
|
||||
Iterator<T> iterator = collection.iterator();
|
||||
|
||||
assertEquals(t1, iterator.next());
|
||||
assertEquals(t2, iterator.next());
|
||||
assertEquals(t3, iterator.next());
|
||||
assertEquals(t4, iterator.next());
|
||||
assertThat(iterator.next(), isEqual(t1));
|
||||
assertThat(iterator.next(), isEqual(t2));
|
||||
assertThat(iterator.next(), isEqual(t3));
|
||||
assertThat(iterator.next(), isEqual(t4));
|
||||
assertFalse(iterator.hasNext());
|
||||
}
|
||||
|
||||
@@ -222,6 +227,7 @@ public abstract class AbstractRedisCollectionTests<T> {
|
||||
assertEquals(0, collection.size());
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void removeAll() {
|
||||
T t1 = getT();
|
||||
@@ -231,7 +237,7 @@ public abstract class AbstractRedisCollectionTests<T> {
|
||||
List<T> list = Arrays.asList(t1, t2, t3);
|
||||
|
||||
assertThat(collection.addAll(list), is(true));
|
||||
assertThat(collection.containsAll(list), is(true));
|
||||
assertThat(collection, hasItems((T[])list.toArray()));
|
||||
assertThat(collection, hasItems(t1, t2, t3));
|
||||
|
||||
List<T> newList = Arrays.asList(getT(), getT());
|
||||
@@ -246,6 +252,7 @@ public abstract class AbstractRedisCollectionTests<T> {
|
||||
}
|
||||
|
||||
//@Test(expected = UnsupportedOperationException.class)
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testRetainAll() {
|
||||
T t1 = getT();
|
||||
T t2 = getT();
|
||||
|
||||
@@ -15,9 +15,15 @@
|
||||
*/
|
||||
package org.springframework.data.redis.support.collections;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.matchers.JUnitMatchers.*;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.junit.Assume.assumeTrue;
|
||||
import static org.junit.matchers.JUnitMatchers.hasItem;
|
||||
import static org.junit.matchers.JUnitMatchers.hasItems;
|
||||
import static org.springframework.data.redis.matcher.RedisTestMatchers.isEqual;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
@@ -29,11 +35,8 @@ import java.util.concurrent.TimeUnit;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.data.redis.ObjectFactory;
|
||||
import org.springframework.data.redis.RedisTestProfileValueSource;
|
||||
import org.springframework.data.redis.connection.ConnectionUtils;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.data.redis.support.collections.DefaultRedisList;
|
||||
import org.springframework.data.redis.support.collections.RedisList;
|
||||
|
||||
/**
|
||||
* Integration test for RedisList
|
||||
@@ -72,9 +75,9 @@ public abstract class AbstractRedisListTests<T> extends AbstractRedisCollectionT
|
||||
list.add(t1);
|
||||
list.add(t2);
|
||||
|
||||
assertEquals(t1, list.get(0));
|
||||
assertThat(list.get(0), isEqual(t1));
|
||||
list.add(0, t3);
|
||||
assertEquals(t3, list.get(0));
|
||||
assertThat(list.get(0), isEqual(t3));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -86,9 +89,9 @@ public abstract class AbstractRedisListTests<T> extends AbstractRedisCollectionT
|
||||
list.add(t1);
|
||||
list.add(t2);
|
||||
|
||||
assertEquals(t2, list.get(1));
|
||||
assertThat(list.get(1), isEqual(t2));
|
||||
list.add(2, t3);
|
||||
assertEquals(t3, list.get(2));
|
||||
assertThat(list.get(2), isEqual(t3));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@@ -100,7 +103,7 @@ public abstract class AbstractRedisListTests<T> extends AbstractRedisCollectionT
|
||||
list.add(t1);
|
||||
list.add(t2);
|
||||
|
||||
assertEquals(t1, list.get(0));
|
||||
assertThat(list.get(0), isEqual(t1));
|
||||
list.add(1, t3);
|
||||
}
|
||||
|
||||
@@ -117,11 +120,11 @@ public abstract class AbstractRedisListTests<T> extends AbstractRedisCollectionT
|
||||
|
||||
List<T> asList = Arrays.asList(t3, t4);
|
||||
|
||||
assertEquals(t1, list.get(0));
|
||||
assertThat(list.get(0), isEqual(t1));
|
||||
list.addAll(0, asList);
|
||||
// verify insertion order
|
||||
assertEquals(t3, list.get(0));
|
||||
assertEquals(t4, list.get(1));
|
||||
assertThat(list.get(0), isEqual(t3));
|
||||
assertThat(list.get(1), isEqual(t4));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@@ -137,12 +140,12 @@ public abstract class AbstractRedisListTests<T> extends AbstractRedisCollectionT
|
||||
|
||||
List<T> asList = Arrays.asList(t3, t4);
|
||||
|
||||
assertEquals(t1, list.get(0));
|
||||
assertThat(list.get(0), isEqual(t1));
|
||||
assertTrue(list.addAll(2, asList));
|
||||
|
||||
// verify insertion order
|
||||
assertEquals(t3, list.get(2));
|
||||
assertEquals(t4, list.get(3));
|
||||
assertThat(list.get(2), isEqual(t3));
|
||||
assertThat(list.get(3), isEqual(t4));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@@ -158,7 +161,7 @@ public abstract class AbstractRedisListTests<T> extends AbstractRedisCollectionT
|
||||
|
||||
List<T> asList = Arrays.asList(t3, t4);
|
||||
|
||||
assertEquals(t1, list.get(0));
|
||||
assertThat(list.get(0), isEqual(t1));
|
||||
assertTrue(list.addAll(1, asList));
|
||||
}
|
||||
|
||||
@@ -181,7 +184,7 @@ public abstract class AbstractRedisListTests<T> extends AbstractRedisCollectionT
|
||||
T t1 = getT();
|
||||
|
||||
assertTrue(list.offer(t1));
|
||||
assertTrue(list.contains(t1));
|
||||
assertThat(list.get(0), isEqual(t1));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -189,7 +192,7 @@ public abstract class AbstractRedisListTests<T> extends AbstractRedisCollectionT
|
||||
assertNull(list.peek());
|
||||
T t1 = getT();
|
||||
list.add(t1);
|
||||
assertEquals(t1, list.peek());
|
||||
assertThat(list.peek(), isEqual(t1));
|
||||
list.clear();
|
||||
assertNull(list.peek());
|
||||
}
|
||||
@@ -205,7 +208,7 @@ public abstract class AbstractRedisListTests<T> extends AbstractRedisCollectionT
|
||||
|
||||
T t1 = getT();
|
||||
list.add(t1);
|
||||
assertEquals(t1, list.element());
|
||||
assertThat(list.element(), isEqual(t1));
|
||||
list.clear();
|
||||
try {
|
||||
list.element();
|
||||
@@ -225,7 +228,7 @@ public abstract class AbstractRedisListTests<T> extends AbstractRedisCollectionT
|
||||
assertNull(list.poll());
|
||||
T t1 = getT();
|
||||
list.add(t1);
|
||||
assertEquals(t1, list.poll());
|
||||
assertThat(list.poll(), isEqual(t1));
|
||||
assertNull(list.poll());
|
||||
}
|
||||
|
||||
@@ -234,7 +237,7 @@ public abstract class AbstractRedisListTests<T> extends AbstractRedisCollectionT
|
||||
assumeTrue(!ConnectionUtils.isJredis(template.getConnectionFactory()));
|
||||
T t1 = getT();
|
||||
list.add(t1);
|
||||
assertEquals(t1, list.poll(1, TimeUnit.MILLISECONDS));
|
||||
assertThat(list.poll(1, TimeUnit.MILLISECONDS), isEqual(t1));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -248,7 +251,7 @@ public abstract class AbstractRedisListTests<T> extends AbstractRedisCollectionT
|
||||
|
||||
T t1 = getT();
|
||||
list.add(t1);
|
||||
assertEquals(t1, list.remove());
|
||||
assertThat(list.remove(), isEqual(t1));
|
||||
try {
|
||||
list.remove();
|
||||
fail();
|
||||
@@ -266,8 +269,8 @@ public abstract class AbstractRedisListTests<T> extends AbstractRedisCollectionT
|
||||
list.add(t1);
|
||||
list.add(t2);
|
||||
assertEquals(2, list.range(0, -1).size());
|
||||
assertEquals(t1, list.range(0, 0).get(0));
|
||||
assertEquals(t2, list.range(1, 1).get(0));
|
||||
assertThat(list.range(0, 0).get(0), isEqual(t1));
|
||||
assertThat(list.range(1, 1).get(0), isEqual(t2));
|
||||
}
|
||||
|
||||
@Test(expected = UnsupportedOperationException.class)
|
||||
@@ -289,8 +292,8 @@ public abstract class AbstractRedisListTests<T> extends AbstractRedisCollectionT
|
||||
T t2 = getT();
|
||||
list.add(t1);
|
||||
list.set(0, t1);
|
||||
assertEquals(t1, list.set(0, t2));
|
||||
assertEquals(t2, list.get(0));
|
||||
assertThat(list.set(0, t2), isEqual(t1));
|
||||
assertThat(list.get(0), isEqual(t2));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -304,7 +307,7 @@ public abstract class AbstractRedisListTests<T> extends AbstractRedisCollectionT
|
||||
assertEquals(2, list.size());
|
||||
assertEquals(1, list.trim(0, 0).size());
|
||||
assertEquals(1, list.size());
|
||||
assertEquals(t1, list.get(0));
|
||||
assertThat(list.get(0), isEqual(t1));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@@ -319,7 +322,7 @@ public abstract class AbstractRedisListTests<T> extends AbstractRedisCollectionT
|
||||
T last = getT();
|
||||
cappedList.add(last);
|
||||
assertEquals(1, cappedList.size());
|
||||
assertEquals(first, cappedList.get(0));
|
||||
assertThat(cappedList.get(0), isEqual(first));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -333,9 +336,9 @@ public abstract class AbstractRedisListTests<T> extends AbstractRedisCollectionT
|
||||
list.addFirst(t3);
|
||||
|
||||
Iterator<T> iterator = list.iterator();
|
||||
assertEquals(t3, iterator.next());
|
||||
assertEquals(t2, iterator.next());
|
||||
assertEquals(t1, iterator.next());
|
||||
assertThat(iterator.next(), isEqual(t3));
|
||||
assertThat(iterator.next(), isEqual(t2));
|
||||
assertThat(iterator.next(), isEqual(t1));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -354,9 +357,9 @@ public abstract class AbstractRedisListTests<T> extends AbstractRedisCollectionT
|
||||
list.add(t3);
|
||||
|
||||
Iterator<T> iterator = list.descendingIterator();
|
||||
assertEquals(t3, iterator.next());
|
||||
assertEquals(t2, iterator.next());
|
||||
assertEquals(t1, iterator.next());
|
||||
assertThat(iterator.next(), isEqual(t3));
|
||||
assertThat(iterator.next(), isEqual(t2));
|
||||
assertThat(iterator.next(), isEqual(t1));
|
||||
|
||||
}
|
||||
|
||||
@@ -407,7 +410,7 @@ public abstract class AbstractRedisListTests<T> extends AbstractRedisCollectionT
|
||||
list.add(t1);
|
||||
list.add(t2);
|
||||
|
||||
assertEquals(t1, list.getFirst());
|
||||
assertThat(list.getFirst(), isEqual(t1));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -438,7 +441,7 @@ public abstract class AbstractRedisListTests<T> extends AbstractRedisCollectionT
|
||||
list.add(t1);
|
||||
list.add(t2);
|
||||
|
||||
assertEquals(t2, list.peekLast());
|
||||
assertThat(list.peekLast(), isEqual(t2));
|
||||
assertEquals(2, list.size());
|
||||
}
|
||||
|
||||
@@ -456,7 +459,7 @@ public abstract class AbstractRedisListTests<T> extends AbstractRedisCollectionT
|
||||
list.add(t2);
|
||||
|
||||
T last = list.pollLast();
|
||||
assertEquals(t2, last);
|
||||
assertThat(last, isEqual(t2));
|
||||
assertEquals(1, list.size());
|
||||
assertThat(list, hasItem(t1));
|
||||
}
|
||||
@@ -471,7 +474,7 @@ public abstract class AbstractRedisListTests<T> extends AbstractRedisCollectionT
|
||||
list.add(t2);
|
||||
|
||||
T last = list.pollLast(1, TimeUnit.MILLISECONDS);
|
||||
assertEquals(t2, last);
|
||||
assertThat(last, isEqual(t2));
|
||||
assertEquals(1, list.size());
|
||||
assertThat(list, hasItem(t1));
|
||||
}
|
||||
@@ -524,9 +527,9 @@ public abstract class AbstractRedisListTests<T> extends AbstractRedisCollectionT
|
||||
list.removeLastOccurrence(t2);
|
||||
assertEquals(3, list.size());
|
||||
Iterator<T> iterator = list.iterator();
|
||||
assertEquals(t1, iterator.next());
|
||||
assertEquals(t2, iterator.next());
|
||||
assertEquals(t1, iterator.next());
|
||||
assertThat(iterator.next(), isEqual(t1));
|
||||
assertThat(iterator.next(), isEqual(t2));
|
||||
assertThat(iterator.next(), isEqual(t1));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -26,6 +26,7 @@ import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assume.assumeTrue;
|
||||
import static org.junit.matchers.JUnitMatchers.hasItem;
|
||||
import static org.junit.matchers.JUnitMatchers.hasItems;
|
||||
import static org.springframework.data.redis.matcher.RedisTestMatchers.isEqual;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.ArrayList;
|
||||
@@ -36,7 +37,6 @@ import java.util.LinkedHashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.AfterClass;
|
||||
@@ -181,10 +181,9 @@ public abstract class AbstractRedisMapTests<K, V> {
|
||||
K k1 = getKey();
|
||||
V v1 = getValue();
|
||||
|
||||
assertNull(map.get(UUID.randomUUID().toString()));
|
||||
assertNull(map.get(k1));
|
||||
map.put(k1, v1);
|
||||
assertEquals(v1, map.get(k1));
|
||||
assertThat(map.get(k1), isEqual(v1));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -279,8 +278,8 @@ public abstract class AbstractRedisMapTests<K, V> {
|
||||
map.put(k1, v1);
|
||||
map.put(k2, v2);
|
||||
|
||||
assertEquals(v1, map.get(k1));
|
||||
assertEquals(v2, map.get(k2));
|
||||
assertThat(map.get(k1), isEqual(v1));
|
||||
assertThat(map.get(k2), isEqual(v2));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -301,8 +300,8 @@ public abstract class AbstractRedisMapTests<K, V> {
|
||||
|
||||
map.putAll(m);
|
||||
|
||||
assertEquals(v1, map.get(k1));
|
||||
assertEquals(v2, map.get(k2));
|
||||
assertThat(map.get(k1), isEqual(v1));
|
||||
assertThat(map.get(k2), isEqual(v2));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -319,11 +318,11 @@ public abstract class AbstractRedisMapTests<K, V> {
|
||||
map.put(k1, v1);
|
||||
map.put(k2, v2);
|
||||
|
||||
assertEquals(v1, map.remove(k1));
|
||||
assertThat(map.remove(k1), isEqual(v1));
|
||||
assertNull(map.remove(k1));
|
||||
assertNull(map.get(k1));
|
||||
|
||||
assertEquals(v2, map.remove(k2));
|
||||
assertThat(map.remove(k2), isEqual(v2));
|
||||
assertNull(map.remove(k2));
|
||||
assertNull(map.get(k2));
|
||||
}
|
||||
@@ -407,13 +406,13 @@ public abstract class AbstractRedisMapTests<K, V> {
|
||||
|
||||
assertNull(map.get(k1));
|
||||
assertNull(map.putIfAbsent(k1, v1));
|
||||
assertEquals(v1, map.putIfAbsent(k1, v2));
|
||||
assertEquals(v1, map.get(k1));
|
||||
assertThat(map.putIfAbsent(k1, v2), isEqual(v1));
|
||||
assertThat(map.get(k1), isEqual(v1));
|
||||
|
||||
assertNull(map.putIfAbsent(k2, v2));
|
||||
assertEquals(v2, map.putIfAbsent(k2, v1));
|
||||
assertThat(map.putIfAbsent(k2, v1), isEqual(v2));
|
||||
|
||||
assertEquals(v2, map.get(k2));
|
||||
assertThat(map.get(k2), isEqual(v2));
|
||||
}
|
||||
|
||||
@Test(expected = UnsupportedOperationException.class)
|
||||
|
||||
@@ -18,6 +18,7 @@ package org.springframework.data.redis.support.collections;
|
||||
import static org.hamcrest.CoreMatchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.matchers.JUnitMatchers.*;
|
||||
import static org.springframework.data.redis.matcher.RedisTestMatchers.isEqual;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
@@ -49,6 +50,7 @@ public abstract class AbstractRedisSetTests<T> extends AbstractRedisCollectionTe
|
||||
* @param factory
|
||||
* @param template
|
||||
*/
|
||||
@SuppressWarnings("rawtypes")
|
||||
public AbstractRedisSetTests(ObjectFactory<T> factory, RedisTemplate template) {
|
||||
super(factory, template);
|
||||
}
|
||||
@@ -61,10 +63,12 @@ public abstract class AbstractRedisSetTests<T> extends AbstractRedisCollectionTe
|
||||
set = (RedisSet<T>) collection;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private RedisSet<T> createSetFor(String key) {
|
||||
return new DefaultRedisSet<T>((BoundSetOperations<String, T>) set.getOperations().boundSetOps(key));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void testDiff() {
|
||||
RedisSet<T> diffSet1 = createSetFor("test:set:diff1");
|
||||
@@ -86,6 +90,7 @@ public abstract class AbstractRedisSetTests<T> extends AbstractRedisCollectionTe
|
||||
assertThat(diff, hasItem(t1));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void testDiffAndStore() {
|
||||
RedisSet<T> diffSet1 = createSetFor("test:set:diff1");
|
||||
@@ -112,6 +117,7 @@ public abstract class AbstractRedisSetTests<T> extends AbstractRedisCollectionTe
|
||||
assertEquals(resultName, diff.getKey());
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void testIntersect() {
|
||||
RedisSet<T> intSet1 = createSetFor("test:set:int1");
|
||||
@@ -137,6 +143,7 @@ public abstract class AbstractRedisSetTests<T> extends AbstractRedisCollectionTe
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testIntersectAndStore() {
|
||||
RedisSet<T> intSet1 = createSetFor("test:set:int1");
|
||||
RedisSet<T> intSet2 = createSetFor("test:set:int2");
|
||||
@@ -162,6 +169,7 @@ public abstract class AbstractRedisSetTests<T> extends AbstractRedisCollectionTe
|
||||
assertEquals(resultName, inter.getKey());
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void testUnion() {
|
||||
RedisSet<T> unionSet1 = createSetFor("test:set:union1");
|
||||
@@ -184,6 +192,7 @@ public abstract class AbstractRedisSetTests<T> extends AbstractRedisCollectionTe
|
||||
assertThat(union, hasItems(t1, t2, t3, t4));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void testUnionAndStore() {
|
||||
RedisSet<T> unionSet1 = createSetFor("test:set:union1");
|
||||
@@ -208,6 +217,7 @@ public abstract class AbstractRedisSetTests<T> extends AbstractRedisCollectionTe
|
||||
assertEquals(resultName, union.getKey());
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void testIterator() {
|
||||
T t1 = getT();
|
||||
@@ -220,10 +230,18 @@ 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()) {
|
||||
result.remove(iterator.next());
|
||||
T expected = iterator.next();
|
||||
Iterator<T> resultItr = result.iterator();
|
||||
while(resultItr.hasNext()) {
|
||||
T obj = resultItr.next();
|
||||
if(isEqual(expected).matches(obj)) {
|
||||
resultItr.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
assertEquals(0, result.size());
|
||||
@@ -242,7 +260,13 @@ public abstract class AbstractRedisSetTests<T> extends AbstractRedisCollectionTe
|
||||
List<T> result = new ArrayList<T>(list);
|
||||
|
||||
for (int i = 0; i < array.length; i++) {
|
||||
result.remove(array[i]);
|
||||
Iterator<T> resultItr = result.iterator();
|
||||
while(resultItr.hasNext()) {
|
||||
T obj = resultItr.next();
|
||||
if(isEqual(array[i]).matches(obj)) {
|
||||
resultItr.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
assertEquals(0, result.size());
|
||||
@@ -260,7 +284,13 @@ public abstract class AbstractRedisSetTests<T> extends AbstractRedisCollectionTe
|
||||
List<T> result = new ArrayList<T>(list);
|
||||
|
||||
for (int i = 0; i < array.length; i++) {
|
||||
result.remove(array[i]);
|
||||
Iterator<T> resultItr = result.iterator();
|
||||
while(resultItr.hasNext()) {
|
||||
T obj = resultItr.next();
|
||||
if(isEqual(array[i]).matches(obj)) {
|
||||
resultItr.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
assertEquals(0, result.size());
|
||||
|
||||
@@ -23,6 +23,7 @@ import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assume.assumeTrue;
|
||||
import static org.junit.matchers.JUnitMatchers.hasItem;
|
||||
import static org.junit.matchers.JUnitMatchers.hasItems;
|
||||
import static org.springframework.data.redis.matcher.RedisTestMatchers.isEqual;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Iterator;
|
||||
@@ -76,9 +77,9 @@ public abstract class AbstractRedisZSetTest<T> extends AbstractRedisCollectionTe
|
||||
zSet.add(t3, 5);
|
||||
|
||||
Iterator<T> iterator = zSet.iterator();
|
||||
assertEquals(t1, iterator.next());
|
||||
assertEquals(t2, iterator.next());
|
||||
assertEquals(t3, iterator.next());
|
||||
assertThat(iterator.next(), isEqual(t1));
|
||||
assertThat(iterator.next(), isEqual(t2));
|
||||
assertThat(iterator.next(), isEqual(t3));
|
||||
assertFalse(iterator.hasNext());
|
||||
}
|
||||
|
||||
@@ -111,7 +112,7 @@ public abstract class AbstractRedisZSetTest<T> extends AbstractRedisCollectionTe
|
||||
zSet.add(t3, 5);
|
||||
|
||||
assertEquals(3, zSet.size());
|
||||
assertEquals(t1, zSet.first());
|
||||
assertThat(zSet.first(), isEqual(t1));
|
||||
}
|
||||
|
||||
@Test(expected = NoSuchElementException.class)
|
||||
@@ -130,7 +131,7 @@ public abstract class AbstractRedisZSetTest<T> extends AbstractRedisCollectionTe
|
||||
zSet.add(t3, 5);
|
||||
|
||||
assertEquals(3, zSet.size());
|
||||
assertEquals(t3, zSet.last());
|
||||
assertThat(zSet.last(), isEqual(t3));
|
||||
}
|
||||
|
||||
@Test(expected = NoSuchElementException.class)
|
||||
@@ -240,8 +241,8 @@ public abstract class AbstractRedisZSetTest<T> extends AbstractRedisCollectionTe
|
||||
Set<T> range = zSet.range(1, 2);
|
||||
assertEquals(2, range.size());
|
||||
Iterator<T> iterator = range.iterator();
|
||||
assertEquals(t2, iterator.next());
|
||||
assertEquals(t3, iterator.next());
|
||||
assertThat(iterator.next(), isEqual(t2));
|
||||
assertThat(iterator.next(), isEqual(t3));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -260,12 +261,12 @@ public abstract class AbstractRedisZSetTest<T> extends AbstractRedisCollectionTe
|
||||
|
||||
Iterator<TypedTuple<T>> iterator = range.iterator();
|
||||
TypedTuple<T> tuple1 = iterator.next();
|
||||
assertEquals(t2, tuple1.getValue());
|
||||
assertEquals(Double.valueOf(2), tuple1.getScore());
|
||||
assertThat(tuple1.getValue(), isEqual(t2));
|
||||
assertThat(tuple1.getScore(), isEqual(Double.valueOf(2)));
|
||||
|
||||
TypedTuple<T> tuple2 = iterator.next();
|
||||
assertEquals(t3, tuple2.getValue());
|
||||
assertEquals(Double.valueOf(3), tuple2.getScore());
|
||||
assertThat(tuple2.getValue(), isEqual(t3));
|
||||
assertThat(tuple2.getScore(), isEqual(Double.valueOf(3)));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -281,8 +282,8 @@ public abstract class AbstractRedisZSetTest<T> extends AbstractRedisCollectionTe
|
||||
Set<T> range = zSet.reverseRange(1, 2);
|
||||
assertEquals(2, range.size());
|
||||
Iterator<T> iterator = range.iterator();
|
||||
assertEquals(t2, iterator.next());
|
||||
assertEquals(t1, iterator.next());
|
||||
assertThat(iterator.next(), isEqual(t2));
|
||||
assertThat(iterator.next(), isEqual(t1));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -301,12 +302,12 @@ public abstract class AbstractRedisZSetTest<T> extends AbstractRedisCollectionTe
|
||||
|
||||
Iterator<TypedTuple<T>> iterator = range.iterator();
|
||||
TypedTuple<T> tuple1 = iterator.next();
|
||||
assertEquals(t2, tuple1.getValue());
|
||||
assertEquals(Double.valueOf(2), tuple1.getScore());
|
||||
assertThat(tuple1.getValue(), isEqual(t2));
|
||||
assertThat(tuple1.getScore(), isEqual(Double.valueOf(2)));
|
||||
|
||||
TypedTuple<T> tuple2 = iterator.next();
|
||||
assertEquals(t1, tuple2.getValue());
|
||||
assertEquals(Double.valueOf(1), tuple2.getScore());
|
||||
assertThat(tuple2.getValue(), isEqual(t1));
|
||||
assertThat(tuple2.getScore(), isEqual(Double.valueOf(1)));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -323,8 +324,8 @@ public abstract class AbstractRedisZSetTest<T> extends AbstractRedisCollectionTe
|
||||
Set<T> range = zSet.reverseRangeByScore(1.5, 3.5);
|
||||
assertEquals(2, range.size());
|
||||
Iterator<T> iterator = range.iterator();
|
||||
assertEquals(t3, iterator.next());
|
||||
assertEquals(t2, iterator.next());
|
||||
assertThat(iterator.next(), isEqual(t3));
|
||||
assertThat(iterator.next(), isEqual(t2));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -343,12 +344,12 @@ public abstract class AbstractRedisZSetTest<T> extends AbstractRedisCollectionTe
|
||||
|
||||
Iterator<TypedTuple<T>> iterator = range.iterator();
|
||||
TypedTuple<T> tuple1 = iterator.next();
|
||||
assertEquals(t3, tuple1.getValue());
|
||||
assertEquals(Double.valueOf(3), tuple1.getScore());
|
||||
assertThat(tuple1.getValue(), isEqual(t3));
|
||||
assertThat(tuple1.getScore(), isEqual(Double.valueOf(3)));
|
||||
|
||||
TypedTuple<T> tuple2 = iterator.next();
|
||||
assertEquals(t2, tuple2.getValue());
|
||||
assertEquals(Double.valueOf(2), tuple2.getScore());
|
||||
assertThat(tuple2.getValue(), isEqual(t2));
|
||||
assertThat(tuple2.getScore(), isEqual(Double.valueOf(2)));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@@ -367,8 +368,8 @@ public abstract class AbstractRedisZSetTest<T> extends AbstractRedisCollectionTe
|
||||
assertThat(range, hasItems(t2, t3));
|
||||
|
||||
Iterator<T> iterator = range.iterator();
|
||||
assertEquals(t2, iterator.next());
|
||||
assertEquals(t3, iterator.next());
|
||||
assertThat(iterator.next(), isEqual(t2));
|
||||
assertThat(iterator.next(), isEqual(t3));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -387,12 +388,12 @@ public abstract class AbstractRedisZSetTest<T> extends AbstractRedisCollectionTe
|
||||
|
||||
Iterator<TypedTuple<T>> iterator = range.iterator();
|
||||
TypedTuple<T> tuple1 = iterator.next();
|
||||
assertEquals(t2, tuple1.getValue());
|
||||
assertEquals(Double.valueOf(2), tuple1.getScore());
|
||||
assertThat(tuple1.getValue(), isEqual(t2));
|
||||
assertThat(tuple1.getScore(), isEqual(Double.valueOf(2)));
|
||||
|
||||
TypedTuple<T> tuple2 = iterator.next();
|
||||
assertEquals(t3, tuple2.getValue());
|
||||
assertEquals(Double.valueOf(3), tuple2.getScore());
|
||||
assertThat(tuple2.getValue(), isEqual(t3));
|
||||
assertThat(tuple2.getScore(), isEqual(Double.valueOf(3)));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -411,8 +412,8 @@ public abstract class AbstractRedisZSetTest<T> extends AbstractRedisCollectionTe
|
||||
|
||||
assertEquals(2, zSet.size());
|
||||
Iterator<T> iterator = zSet.iterator();
|
||||
assertEquals(t1, iterator.next());
|
||||
assertEquals(t4, iterator.next());
|
||||
assertThat(iterator.next(), isEqual(t1));
|
||||
assertThat(iterator.next(), isEqual(t4));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -431,9 +432,9 @@ public abstract class AbstractRedisZSetTest<T> extends AbstractRedisCollectionTe
|
||||
|
||||
assertEquals(3, zSet.size());
|
||||
Iterator<T> iterator = zSet.iterator();
|
||||
assertEquals(t1, iterator.next());
|
||||
assertEquals(t3, iterator.next());
|
||||
assertEquals(t4, iterator.next());
|
||||
assertThat(iterator.next(), isEqual(t1));
|
||||
assertThat(iterator.next(), isEqual(t3));
|
||||
assertThat(iterator.next(), isEqual(t4));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@@ -481,10 +482,10 @@ public abstract class AbstractRedisZSetTest<T> extends AbstractRedisCollectionTe
|
||||
|
||||
Iterator<T> iterator = collection.iterator();
|
||||
|
||||
assertEquals(t1, iterator.next());
|
||||
assertEquals(t2, iterator.next());
|
||||
assertEquals(t3, iterator.next());
|
||||
assertEquals(t4, iterator.next());
|
||||
assertThat(iterator.next(), isEqual(t1));
|
||||
assertThat(iterator.next(), isEqual(t2));
|
||||
assertThat(iterator.next(), isEqual(t3));
|
||||
assertThat(iterator.next(), isEqual(t4));
|
||||
assertFalse(iterator.hasNext());
|
||||
}
|
||||
|
||||
|
||||
@@ -21,17 +21,19 @@ import java.util.Collection;
|
||||
import org.springframework.data.redis.ObjectFactory;
|
||||
import org.springframework.data.redis.Person;
|
||||
import org.springframework.data.redis.PersonObjectFactory;
|
||||
import org.springframework.data.redis.RawObjectFactory;
|
||||
import org.springframework.data.redis.SettingsUtils;
|
||||
import org.springframework.data.redis.StringObjectFactory;
|
||||
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
|
||||
import org.springframework.data.redis.connection.jredis.JredisPool;
|
||||
import org.springframework.data.redis.connection.jredis.JredisConnectionFactory;
|
||||
import org.springframework.data.redis.connection.jredis.JredisPool;
|
||||
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
|
||||
import org.springframework.data.redis.connection.srp.SrpConnectionFactory;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
import org.springframework.data.redis.serializer.JacksonJsonRedisSerializer;
|
||||
import org.springframework.data.redis.serializer.OxmSerializer;
|
||||
import org.springframework.data.redis.serializer.StringRedisSerializer;
|
||||
import org.springframework.oxm.xstream.XStreamMarshaller;
|
||||
|
||||
/**
|
||||
@@ -49,10 +51,12 @@ public abstract class CollectionTestParams {
|
||||
}
|
||||
OxmSerializer serializer = new OxmSerializer(xstream, xstream);
|
||||
JacksonJsonRedisSerializer<Person> jsonSerializer = new JacksonJsonRedisSerializer<Person>(Person.class);
|
||||
StringRedisSerializer stringSerializer = new StringRedisSerializer();
|
||||
|
||||
// create Jedis Factory
|
||||
ObjectFactory<String> stringFactory = new StringObjectFactory();
|
||||
ObjectFactory<Person> personFactory = new PersonObjectFactory();
|
||||
ObjectFactory<byte[]> rawFactory = new RawObjectFactory();
|
||||
|
||||
JedisConnectionFactory jedisConnFactory = new JedisConnectionFactory();
|
||||
jedisConnFactory.setUsePool(true);
|
||||
@@ -83,6 +87,12 @@ public abstract class CollectionTestParams {
|
||||
jsonPersonTemplate.setValueSerializer(jsonSerializer);
|
||||
jsonPersonTemplate.afterPropertiesSet();
|
||||
|
||||
RedisTemplate<byte[],byte[]> rawTemplate = new RedisTemplate<byte[],byte[]>();
|
||||
rawTemplate.setConnectionFactory(jedisConnFactory);
|
||||
rawTemplate.setEnableDefaultSerializer(false);
|
||||
rawTemplate.setKeySerializer(stringSerializer);
|
||||
rawTemplate.afterPropertiesSet();
|
||||
|
||||
// jredis
|
||||
JredisConnectionFactory jredisConnFactory = new JredisConnectionFactory(new JredisPool(
|
||||
SettingsUtils.getHost(), SettingsUtils.getPort()));
|
||||
@@ -108,6 +118,12 @@ public abstract class CollectionTestParams {
|
||||
jsonPersonTemplateJR.setConnectionFactory(jredisConnFactory);
|
||||
jsonPersonTemplateJR.afterPropertiesSet();
|
||||
|
||||
RedisTemplate<byte[],byte[]> rawTemplateJR = new RedisTemplate<byte[],byte[]>();
|
||||
rawTemplateJR.setConnectionFactory(jredisConnFactory);
|
||||
rawTemplateJR.setEnableDefaultSerializer(false);
|
||||
rawTemplateJR.setKeySerializer(stringSerializer);
|
||||
rawTemplateJR.afterPropertiesSet();
|
||||
|
||||
// SRP
|
||||
SrpConnectionFactory srConnFactory = new SrpConnectionFactory();
|
||||
srConnFactory.setPort(SettingsUtils.getPort());
|
||||
@@ -134,6 +150,12 @@ public abstract class CollectionTestParams {
|
||||
jsonPersonTemplateSRP.setConnectionFactory(srConnFactory);
|
||||
jsonPersonTemplateSRP.afterPropertiesSet();
|
||||
|
||||
RedisTemplate<byte[],byte[]> rawTemplateSRP = new RedisTemplate<byte[],byte[]>();
|
||||
rawTemplateSRP.setConnectionFactory(srConnFactory);
|
||||
rawTemplateSRP.setEnableDefaultSerializer(false);
|
||||
rawTemplateSRP.setKeySerializer(stringSerializer);
|
||||
rawTemplateSRP.afterPropertiesSet();
|
||||
|
||||
// Lettuce
|
||||
LettuceConnectionFactory lettuceConnFactory = new LettuceConnectionFactory();
|
||||
lettuceConnFactory.setPort(SettingsUtils.getPort());
|
||||
@@ -160,24 +182,30 @@ public abstract class CollectionTestParams {
|
||||
jsonPersonTemplateLtc.setConnectionFactory(lettuceConnFactory);
|
||||
jsonPersonTemplateLtc.afterPropertiesSet();
|
||||
|
||||
RedisTemplate<byte[],byte[]> rawTemplateLtc = new RedisTemplate<byte[],byte[]>();
|
||||
rawTemplateLtc.setConnectionFactory(lettuceConnFactory);
|
||||
rawTemplateLtc.setEnableDefaultSerializer(false);
|
||||
rawTemplateLtc.setKeySerializer(stringSerializer);
|
||||
rawTemplateLtc.afterPropertiesSet();
|
||||
|
||||
return Arrays.asList(new Object[][] { { stringFactory, stringTemplate },
|
||||
{ stringFactory, stringTemplateJR },
|
||||
{ personFactory, personTemplateJR },
|
||||
{ personFactory, personTemplate },
|
||||
{ stringFactory, xstreamStringTemplate }, { personFactory, xstreamPersonTemplate },
|
||||
{ personFactory, jsonPersonTemplate }, {rawFactory, rawTemplate},
|
||||
// Jredis
|
||||
{ stringFactory, stringTemplateJR },
|
||||
{ personFactory, personTemplateJR },
|
||||
{ stringFactory, xstreamStringTemplateJR },
|
||||
{ personFactory, xstreamPersonTemplateJR },
|
||||
{ personFactory, jsonPersonTemplate },
|
||||
{ personFactory, jsonPersonTemplateJR },
|
||||
{ personFactory, jsonPersonTemplateJR }, {rawFactory, rawTemplateJR},
|
||||
// srp
|
||||
{ stringFactory, stringTemplateSRP },{ personFactory, personTemplateSRP },
|
||||
{ stringFactory, xstreamStringTemplateSRP }, { personFactory, xstreamPersonTemplateSRP },
|
||||
{ personFactory, jsonPersonTemplateSRP },
|
||||
{ personFactory, jsonPersonTemplateSRP }, {rawFactory, rawTemplateSRP},
|
||||
// lettuce
|
||||
{ stringFactory, stringTemplateLtc }, { personFactory, personTemplateLtc },
|
||||
{ stringFactory, xstreamStringTemplateLtc }, { personFactory, xstreamPersonTemplateLtc },
|
||||
{ personFactory, jsonPersonTemplateLtc }
|
||||
|
||||
{ personFactory, jsonPersonTemplateLtc }, {rawFactory, rawTemplateLtc}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,16 +47,19 @@ import org.springframework.oxm.xstream.XStreamMarshaller;
|
||||
*/
|
||||
public class RedisMapTests extends AbstractRedisMapTests<Object, Object> {
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
public RedisMapTests(ObjectFactory<Object> keyFactory, ObjectFactory<Object> valueFactory, RedisTemplate template) {
|
||||
super(keyFactory, valueFactory, template);
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
RedisMap<Object, Object> createMap() {
|
||||
String redisName = getClass().getSimpleName();
|
||||
return new DefaultRedisMap<Object, Object>(redisName, template);
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
@Parameters
|
||||
public static Collection<Object[]> testParams() {
|
||||
// XStream serializer
|
||||
@@ -69,6 +72,7 @@ public class RedisMapTests extends AbstractRedisMapTests<Object, Object> {
|
||||
OxmSerializer serializer = new OxmSerializer(xstream, xstream);
|
||||
JacksonJsonRedisSerializer<Person> jsonSerializer = new JacksonJsonRedisSerializer<Person>(Person.class);
|
||||
JacksonJsonRedisSerializer<String> jsonStringSerializer = new JacksonJsonRedisSerializer<String>(String.class);
|
||||
StringRedisSerializer stringSerializer = new StringRedisSerializer();
|
||||
|
||||
// create Jedis Factory
|
||||
ObjectFactory<String> stringFactory = new StringObjectFactory();
|
||||
@@ -99,9 +103,10 @@ public class RedisMapTests extends AbstractRedisMapTests<Object, Object> {
|
||||
jsonPersonTemplate.setHashValueSerializer(jsonStringSerializer);
|
||||
jsonPersonTemplate.afterPropertiesSet();
|
||||
|
||||
RedisTemplate<byte[], byte[]> rawTemplate = new RedisTemplate<byte[], byte[]>();
|
||||
RedisTemplate<String, byte[]> rawTemplate = new RedisTemplate<String, byte[]>();
|
||||
rawTemplate.setEnableDefaultSerializer(false);
|
||||
rawTemplate.setConnectionFactory(jedisConnFactory);
|
||||
rawTemplate.setKeySerializer(stringSerializer);
|
||||
rawTemplate.afterPropertiesSet();
|
||||
|
||||
// JRedis
|
||||
@@ -125,9 +130,10 @@ public class RedisMapTests extends AbstractRedisMapTests<Object, Object> {
|
||||
jsonPersonTemplateJR.setHashValueSerializer(jsonStringSerializer);
|
||||
jsonPersonTemplateJR.afterPropertiesSet();
|
||||
|
||||
RedisTemplate<byte[], byte[]> rawTemplateJR = new RedisTemplate<byte[], byte[]>();
|
||||
RedisTemplate<String, byte[]> rawTemplateJR = new RedisTemplate<String, byte[]>();
|
||||
rawTemplateJR.setEnableDefaultSerializer(false);
|
||||
rawTemplateJR.setConnectionFactory(jredisConnFactory);
|
||||
rawTemplateJR.setKeySerializer(stringSerializer);
|
||||
rawTemplateJR.afterPropertiesSet();
|
||||
|
||||
// Lettuce
|
||||
@@ -156,9 +162,10 @@ public class RedisMapTests extends AbstractRedisMapTests<Object, Object> {
|
||||
stringTemplateLtc.setConnectionFactory(lettuceConnFactory);
|
||||
stringTemplateLtc.afterPropertiesSet();
|
||||
|
||||
RedisTemplate<byte[], byte[]> rawTemplateLtc = new RedisTemplate<byte[], byte[]>();
|
||||
RedisTemplate<String, byte[]> rawTemplateLtc = new RedisTemplate<String, byte[]>();
|
||||
rawTemplateLtc.setEnableDefaultSerializer(false);
|
||||
rawTemplateLtc.setConnectionFactory(lettuceConnFactory);
|
||||
rawTemplateLtc.setKeySerializer(stringSerializer);
|
||||
rawTemplateLtc.afterPropertiesSet();
|
||||
|
||||
// SRP
|
||||
@@ -187,9 +194,10 @@ public class RedisMapTests extends AbstractRedisMapTests<Object, Object> {
|
||||
stringTemplateSrp.setConnectionFactory(srpConnFactory);
|
||||
stringTemplateSrp.afterPropertiesSet();
|
||||
|
||||
RedisTemplate<byte[], byte[]> rawTemplateSrp = new RedisTemplate<byte[], byte[]>();
|
||||
RedisTemplate<String, byte[]> rawTemplateSrp = new RedisTemplate<String, byte[]>();
|
||||
rawTemplateSrp.setEnableDefaultSerializer(false);
|
||||
rawTemplateSrp.setConnectionFactory(srpConnFactory);
|
||||
rawTemplateSrp.setKeySerializer(stringSerializer);
|
||||
rawTemplateSrp.afterPropertiesSet();
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user