Enable testing opsForX with multiple serializers
This commit is contained in:
@@ -13,7 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.data.redis.support.collections;
|
||||
package org.springframework.data.redis;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
@@ -23,7 +23,7 @@ import java.util.Random;
|
||||
* @author Jennifer Hickey
|
||||
*
|
||||
*/
|
||||
public class DoubleObjectFactory implements ObjectFactory<String> {
|
||||
public class DoubleAsStringObjectFactory implements ObjectFactory<String> {
|
||||
|
||||
private Random random = new Random(System.currentTimeMillis());
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* 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.Random;
|
||||
|
||||
/**
|
||||
* Returns random Doubles
|
||||
*
|
||||
* @author Jennifer Hickey
|
||||
*
|
||||
*/
|
||||
public class DoubleObjectFactory implements ObjectFactory<Double> {
|
||||
|
||||
private Random random = new Random(System.currentTimeMillis());
|
||||
|
||||
public Double instance() {
|
||||
return random.nextDouble();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -13,7 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.data.redis.support.collections;
|
||||
package org.springframework.data.redis;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
@@ -23,7 +23,7 @@ import java.util.Random;
|
||||
* @author Jennifer Hickey
|
||||
*
|
||||
*/
|
||||
public class LongObjectFactory implements ObjectFactory<String> {
|
||||
public class LongAsStringObjectFactory implements ObjectFactory<String> {
|
||||
|
||||
private Random random = new Random(System.currentTimeMillis());
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* 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.Random;
|
||||
|
||||
/**
|
||||
* Returns random Longs
|
||||
*
|
||||
* @author Jennifer Hickey
|
||||
*
|
||||
*/
|
||||
public class LongObjectFactory implements ObjectFactory<Long> {
|
||||
|
||||
private Random random = new Random(System.currentTimeMillis());
|
||||
|
||||
public Long instance() {
|
||||
return random.nextLong();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -13,7 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.data.redis.support.collections;
|
||||
package org.springframework.data.redis;
|
||||
|
||||
/**
|
||||
* Simple object factory.
|
||||
@@ -1,24 +1,22 @@
|
||||
/*
|
||||
* Copyright 2011-2013 the original author or authors.
|
||||
*
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.data.redis.support.collections;
|
||||
package org.springframework.data.redis;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import org.springframework.data.redis.Address;
|
||||
import org.springframework.data.redis.Person;
|
||||
|
||||
/**
|
||||
* @author Costin Leau
|
||||
@@ -27,7 +25,6 @@ public class PersonObjectFactory implements ObjectFactory<Person> {
|
||||
|
||||
private int counter = 0;
|
||||
|
||||
|
||||
public Person instance() {
|
||||
String uuid = UUID.randomUUID().toString();
|
||||
return new Person(uuid, uuid, ++counter, new Address(uuid, counter));
|
||||
@@ -36,6 +36,7 @@ public class RedisTestProfileValueSource implements ProfileValueSource {
|
||||
private static final String REDIS_26 = "2.6";
|
||||
private static final String REDIS_VERSION_KEY = "redisVersion";
|
||||
private static Version redisVersion;
|
||||
private static final RedisTestProfileValueSource INSTANCE = new RedisTestProfileValueSource();
|
||||
|
||||
public RedisTestProfileValueSource() {
|
||||
if (redisVersion == null) {
|
||||
@@ -60,4 +61,8 @@ public class RedisTestProfileValueSource implements ProfileValueSource {
|
||||
}
|
||||
return System.getProperty(key);
|
||||
}
|
||||
|
||||
public static boolean matches(String key, String value) {
|
||||
return INSTANCE.get(key) != null ? INSTANCE.get(key).equals(value) : value == null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,30 +1,30 @@
|
||||
/*
|
||||
* Copyright 2011-2013 the original author or authors.
|
||||
*
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.data.redis.support.collections;
|
||||
package org.springframework.data.redis;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
|
||||
/**
|
||||
* String object factory based on UUID.
|
||||
*
|
||||
*
|
||||
* @author Costin Leau
|
||||
*/
|
||||
public class StringObjectFactory implements ObjectFactory<String> {
|
||||
|
||||
|
||||
public String instance() {
|
||||
return UUID.randomUUID().toString();
|
||||
}
|
||||
@@ -37,9 +37,9 @@ import org.springframework.cache.Cache;
|
||||
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.core.RedisTemplate;
|
||||
import org.springframework.data.redis.support.collections.CollectionTestParams;
|
||||
import org.springframework.data.redis.support.collections.ObjectFactory;
|
||||
|
||||
/**
|
||||
* @author Costin Leau
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* 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.core;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
|
||||
import org.springframework.data.redis.ObjectFactory;
|
||||
import org.springframework.data.redis.SettingsUtils;
|
||||
import org.springframework.data.redis.StringObjectFactory;
|
||||
import org.springframework.data.redis.connection.srp.SrpConnectionFactory;
|
||||
|
||||
/**
|
||||
* Parameters for testing implementations of {@link AbstractOperations}
|
||||
*
|
||||
* @author Jennifer Hickey
|
||||
*
|
||||
*/
|
||||
abstract public class AbstractOperationsTestParams {
|
||||
|
||||
public static Collection<Object[]> testParams() {
|
||||
ObjectFactory<String> stringFactory = new StringObjectFactory();
|
||||
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 } });
|
||||
}
|
||||
}
|
||||
@@ -15,21 +15,25 @@
|
||||
*/
|
||||
package org.springframework.data.redis.core;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
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 java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.junit.runners.Parameterized;
|
||||
import org.junit.runners.Parameterized.Parameters;
|
||||
import org.springframework.data.redis.ObjectFactory;
|
||||
import org.springframework.data.redis.RedisTestProfileValueSource;
|
||||
import org.springframework.test.annotation.IfProfileValue;
|
||||
import org.springframework.test.annotation.ProfileValueSourceConfiguration;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.data.redis.connection.RedisConnection;
|
||||
|
||||
/**
|
||||
* Integration test of {@link DefaultSetOperations}
|
||||
@@ -37,15 +41,28 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
* @author Jennifer Hickey
|
||||
*
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration("StringRedisTemplateTests-context.xml")
|
||||
@ProfileValueSourceConfiguration(RedisTestProfileValueSource.class)
|
||||
public class DefaultSetOperationsTests {
|
||||
@RunWith(Parameterized.class)
|
||||
public class DefaultSetOperationsTests<K,V> {
|
||||
|
||||
@Autowired
|
||||
private RedisTemplate<String, String> redisTemplate;
|
||||
|
||||
private SetOperations<String, String> setOps;
|
||||
private RedisTemplate<K,V> redisTemplate;
|
||||
|
||||
private ObjectFactory<K> keyFactory;
|
||||
|
||||
private ObjectFactory<V> valueFactory;
|
||||
|
||||
private SetOperations<K,V> setOps;
|
||||
|
||||
public DefaultSetOperationsTests(RedisTemplate<K,V> redisTemplate, ObjectFactory<K> keyFactory,
|
||||
ObjectFactory<V> valueFactory) {
|
||||
this.redisTemplate = redisTemplate;
|
||||
this.keyFactory = keyFactory;
|
||||
this.valueFactory = valueFactory;
|
||||
}
|
||||
|
||||
@Parameters
|
||||
public static Collection<Object[]> testParams() {
|
||||
return AbstractOperationsTestParams.testParams();
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
@@ -54,37 +71,56 @@ public class DefaultSetOperationsTests {
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
redisTemplate.getConnectionFactory().getConnection().flushDb();
|
||||
redisTemplate.execute(new RedisCallback<Object>() {
|
||||
public Object doInRedis(RedisConnection connection) {
|
||||
connection.flushDb();
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
@IfProfileValue(name = "redisVersion", value = "2.6")
|
||||
public void testDistinctRandomMembers() {
|
||||
setOps.add("test", "foo");
|
||||
setOps.add("test", "bar");
|
||||
setOps.add("test", "baz");
|
||||
Set<String> members = setOps.distinctRandomMembers("test", 2);
|
||||
assumeTrue(RedisTestProfileValueSource.matches("redisVersion", "2.6"));
|
||||
K setKey = keyFactory.instance();
|
||||
V v1 = valueFactory.instance();
|
||||
V v2 = valueFactory.instance();
|
||||
V v3 = valueFactory.instance();
|
||||
setOps.add(setKey, v1);
|
||||
setOps.add(setKey, v2);
|
||||
setOps.add(setKey, v3);
|
||||
Set<V> members = setOps.distinctRandomMembers(setKey, 2);
|
||||
assertEquals(2, members.size());
|
||||
assertTrue(Arrays.asList(new String[] {"foo", "bar", "baz"}).containsAll(members));
|
||||
assertTrue(Arrays.asList(new Object[] {v1, v2, v3}).containsAll(members));
|
||||
}
|
||||
|
||||
@Test
|
||||
@IfProfileValue(name = "redisVersion", value = "2.6")
|
||||
public void testRandomMembersWithDuplicates() {
|
||||
setOps.add("test", "foo");
|
||||
List<String> members = setOps.randomMembers("test", 2);
|
||||
assertEquals(Arrays.asList(new String[] {"foo", "foo"}), members);
|
||||
assumeTrue(RedisTestProfileValueSource.matches("redisVersion", "2.6"));
|
||||
K setKey = keyFactory.instance();
|
||||
V v1 = valueFactory.instance();
|
||||
setOps.add(setKey, v1);
|
||||
List<V> members = setOps.randomMembers(setKey, 2);
|
||||
assertEquals(Arrays.asList(new Object[] {v1, v1}), members);
|
||||
}
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
@IfProfileValue(name = "redisVersion", value = "2.6")
|
||||
@Test
|
||||
public void testRandomMembersNegative() {
|
||||
setOps.randomMembers("test", -1);
|
||||
assumeTrue(RedisTestProfileValueSource.matches("redisVersion", "2.6"));
|
||||
try {
|
||||
setOps.randomMembers(keyFactory.instance(), -1);
|
||||
fail("IllegalArgumentException should be thrown");
|
||||
}catch(IllegalArgumentException e) {
|
||||
}
|
||||
}
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
@IfProfileValue(name = "redisVersion", value = "2.6")
|
||||
@Test
|
||||
public void testDistinctRandomMembersNegative() {
|
||||
setOps.distinctRandomMembers("test", -2);
|
||||
assumeTrue(RedisTestProfileValueSource.matches("redisVersion", "2.6"));
|
||||
try {
|
||||
setOps.distinctRandomMembers(keyFactory.instance(), -2);
|
||||
fail("IllegalArgumentException should be thrown");
|
||||
}catch(IllegalArgumentException e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,8 +16,13 @@
|
||||
package org.springframework.data.redis.core;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assume.assumeTrue;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
@@ -26,12 +31,18 @@ import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
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.test.annotation.IfProfileValue;
|
||||
import org.springframework.test.annotation.ProfileValueSourceConfiguration;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
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 org.springframework.data.redis.serializer.GenericToStringSerializer;
|
||||
import org.springframework.data.redis.serializer.StringRedisSerializer;
|
||||
|
||||
/**
|
||||
* Integration test of {@link DefaultValueOperations}
|
||||
@@ -39,15 +50,50 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
* @author Jennifer Hickey
|
||||
*
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration("StringRedisTemplateTests-context.xml")
|
||||
@ProfileValueSourceConfiguration(RedisTestProfileValueSource.class)
|
||||
public class DefaultValueOperationsTests {
|
||||
@RunWith(Parameterized.class)
|
||||
public class DefaultValueOperationsTests<K,V> {
|
||||
|
||||
@Autowired
|
||||
private RedisTemplate<String, String> redisTemplate;
|
||||
private RedisTemplate<K,V> redisTemplate;
|
||||
|
||||
private ValueOperations<String, String> valueOps;
|
||||
private ObjectFactory<K> keyFactory;
|
||||
|
||||
private ObjectFactory<V> valueFactory;
|
||||
|
||||
private ValueOperations<K, V> valueOps;
|
||||
|
||||
public DefaultValueOperationsTests(RedisTemplate<K,V> redisTemplate, ObjectFactory<K> keyFactory,
|
||||
ObjectFactory<V> valueFactory) {
|
||||
this.redisTemplate = redisTemplate;
|
||||
this.keyFactory = keyFactory;
|
||||
this.valueFactory = valueFactory;
|
||||
}
|
||||
|
||||
@Parameters
|
||||
public static Collection<Object[]> testParams() {
|
||||
ObjectFactory<String> stringFactory = new StringObjectFactory();
|
||||
ObjectFactory<Long> longFactory = new LongObjectFactory();
|
||||
ObjectFactory<Double> doubleFactory = new DoubleObjectFactory();
|
||||
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();
|
||||
return Arrays.asList(new Object[][] { { stringTemplate, stringFactory, stringFactory },
|
||||
{ longTemplate, stringFactory, longFactory }, { doubleTemplate, stringFactory, doubleFactory }
|
||||
});
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
@@ -56,46 +102,68 @@ public class DefaultValueOperationsTests {
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
redisTemplate.getConnectionFactory().getConnection().flushDb();
|
||||
redisTemplate.execute(new RedisCallback<Object>() {
|
||||
public Object doInRedis(RedisConnection connection) {
|
||||
connection.flushDb();
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIncrementLong() throws Exception {
|
||||
String key = "test.template.inc";
|
||||
valueOps.set(key, "10");
|
||||
assertEquals(Long.valueOf(0), valueOps.increment(key, -10));
|
||||
assertEquals(0, Integer.valueOf(valueOps.get(key)).intValue());
|
||||
K key = keyFactory.instance();
|
||||
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));
|
||||
valueOps.increment(key, -10);
|
||||
assertEquals(-10, Integer.valueOf(valueOps.get(key)).intValue());
|
||||
assertEquals(Long.valueOf((Long)v1 - 20), (Long)valueOps.get(key));
|
||||
}
|
||||
|
||||
@Test
|
||||
@IfProfileValue(name = "redisVersion", value = "2.6")
|
||||
public void testIncrementDouble() {
|
||||
String key = "test.template.inc";
|
||||
valueOps.set(key, "10.5");
|
||||
assertEquals(Double.valueOf(11.9), valueOps.increment(key, 1.4));
|
||||
assertEquals("11.9", valueOps.get(key));
|
||||
assumeTrue(RedisTestProfileValueSource.matches("redisVersion", "2.6"));
|
||||
K key = keyFactory.instance();
|
||||
V v1 = valueFactory.instance();
|
||||
assumeTrue(v1 instanceof Double);
|
||||
valueOps.set(key, v1);
|
||||
DecimalFormat twoDForm = new DecimalFormat("#.##");
|
||||
assertEquals(twoDForm.format(Double.valueOf((Double)v1 + 1.4)),
|
||||
twoDForm.format(valueOps.increment(key, 1.4)));
|
||||
assertEquals(twoDForm.format(Double.valueOf((Double)v1 + 1.4)),
|
||||
twoDForm.format((Double) valueOps.get(key)));
|
||||
valueOps.increment(key, -10d);
|
||||
assertEquals("1.9", valueOps.get(key));
|
||||
assertEquals(twoDForm.format(Double.valueOf((Double)v1 + 1.4 - 10d)),
|
||||
twoDForm.format((Double) valueOps.get(key)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultiSetIfAbsent() {
|
||||
Map<String,String> keysAndValues = new HashMap<String,String>();
|
||||
keysAndValues.put("foo", "bar");
|
||||
keysAndValues.put("baz", "test");
|
||||
Map<K,V> keysAndValues = new HashMap<K,V>();
|
||||
K key1 = keyFactory.instance();
|
||||
K key2 = keyFactory.instance();
|
||||
V value1 = valueFactory.instance();
|
||||
V value2 = valueFactory.instance();
|
||||
keysAndValues.put(key1, value1);
|
||||
keysAndValues.put(key2, value2);
|
||||
assertTrue(valueOps.multiSetIfAbsent(keysAndValues));
|
||||
assertEquals(new HashSet<String>(keysAndValues.values()),
|
||||
new HashSet<String>(valueOps.multiGet(keysAndValues.keySet())));
|
||||
assertEquals(new HashSet<V>(keysAndValues.values()),
|
||||
new HashSet<V>(valueOps.multiGet(keysAndValues.keySet())));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultiSetIfAbsentFailure() {
|
||||
valueOps.set("foo", "alreadyset");
|
||||
Map<String,String> keysAndValues = new HashMap<String,String>();
|
||||
keysAndValues.put("foo", "bar");
|
||||
keysAndValues.put("baz", "test");
|
||||
K key1 = keyFactory.instance();
|
||||
K key2 = keyFactory.instance();
|
||||
V value1 = valueFactory.instance();
|
||||
V value2 = valueFactory.instance();
|
||||
V value3 = valueFactory.instance();
|
||||
valueOps.set(key1, value1);
|
||||
Map<K,V> keysAndValues = new HashMap<K,V>();
|
||||
keysAndValues.put(key1, value2);
|
||||
keysAndValues.put(key2, value3);
|
||||
assertFalse(valueOps.multiSetIfAbsent(keysAndValues));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,16 +18,16 @@ package org.springframework.data.redis.listener;
|
||||
import java.util.Arrays;
|
||||
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.SettingsUtils;
|
||||
import org.springframework.data.redis.StringObjectFactory;
|
||||
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
|
||||
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
|
||||
import org.springframework.data.redis.connection.srp.SrpConnectionFactory;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
import org.springframework.data.redis.support.collections.ObjectFactory;
|
||||
import org.springframework.data.redis.support.collections.PersonObjectFactory;
|
||||
import org.springframework.data.redis.support.collections.StringObjectFactory;
|
||||
|
||||
/**
|
||||
* @author Costin Leau
|
||||
|
||||
@@ -37,9 +37,9 @@ import org.junit.runners.Parameterized.Parameters;
|
||||
import org.springframework.core.task.SimpleAsyncTaskExecutor;
|
||||
import org.springframework.core.task.SyncTaskExecutor;
|
||||
import org.springframework.data.redis.ConnectionFactoryTracker;
|
||||
import org.springframework.data.redis.ObjectFactory;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.data.redis.listener.adapter.MessageListenerAdapter;
|
||||
import org.springframework.data.redis.support.collections.ObjectFactory;
|
||||
|
||||
/**
|
||||
* Base test class for PubSub integration tests
|
||||
|
||||
@@ -30,10 +30,10 @@ import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
import org.junit.runners.Parameterized.Parameters;
|
||||
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.BoundKeyOperations;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.data.redis.support.collections.ObjectFactory;
|
||||
|
||||
/**
|
||||
* @author Costin Leau
|
||||
|
||||
@@ -19,6 +19,7 @@ import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
|
||||
import org.springframework.data.redis.SettingsUtils;
|
||||
import org.springframework.data.redis.StringObjectFactory;
|
||||
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
|
||||
import org.springframework.data.redis.connection.jredis.JredisConnectionFactory;
|
||||
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
|
||||
@@ -30,7 +31,6 @@ import org.springframework.data.redis.support.collections.DefaultRedisList;
|
||||
import org.springframework.data.redis.support.collections.DefaultRedisMap;
|
||||
import org.springframework.data.redis.support.collections.DefaultRedisSet;
|
||||
import org.springframework.data.redis.support.collections.RedisList;
|
||||
import org.springframework.data.redis.support.collections.StringObjectFactory;
|
||||
|
||||
/**
|
||||
* @author Costin Leau
|
||||
|
||||
@@ -42,6 +42,7 @@ import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
import org.junit.runners.Parameterized.Parameters;
|
||||
import org.springframework.data.redis.ConnectionFactoryTracker;
|
||||
import org.springframework.data.redis.ObjectFactory;
|
||||
import org.springframework.data.redis.connection.RedisConnection;
|
||||
import org.springframework.data.redis.core.RedisCallback;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
|
||||
@@ -26,6 +26,7 @@ import java.util.NoSuchElementException;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.data.redis.ObjectFactory;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.data.redis.support.collections.DefaultRedisList;
|
||||
import org.springframework.data.redis.support.collections.RedisList;
|
||||
|
||||
@@ -46,6 +46,9 @@ import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
import org.springframework.dao.InvalidDataAccessApiUsageException;
|
||||
import org.springframework.data.redis.ConnectionFactoryTracker;
|
||||
import org.springframework.data.redis.DoubleAsStringObjectFactory;
|
||||
import org.springframework.data.redis.LongAsStringObjectFactory;
|
||||
import org.springframework.data.redis.ObjectFactory;
|
||||
import org.springframework.data.redis.RedisSystemException;
|
||||
import org.springframework.data.redis.RedisVersionUtils;
|
||||
import org.springframework.data.redis.connection.ConnectionUtils;
|
||||
@@ -198,7 +201,7 @@ public abstract class AbstractRedisMapTests<K, V> {
|
||||
@Test
|
||||
public void testIncrementNotNumber() {
|
||||
assumeTrue(!ConnectionUtils.isJredis(template.getConnectionFactory()) &&
|
||||
!(valueFactory instanceof LongObjectFactory));
|
||||
!(valueFactory instanceof LongAsStringObjectFactory));
|
||||
K k1 = getKey();
|
||||
V v1 = getValue();
|
||||
|
||||
@@ -215,7 +218,7 @@ public abstract class AbstractRedisMapTests<K, V> {
|
||||
|
||||
@Test
|
||||
public void testIncrement() {
|
||||
assumeTrue(valueFactory instanceof LongObjectFactory);
|
||||
assumeTrue(valueFactory instanceof LongAsStringObjectFactory);
|
||||
K k1 = getKey();
|
||||
V v1 = getValue();
|
||||
map.put(k1, v1);
|
||||
@@ -225,7 +228,7 @@ public abstract class AbstractRedisMapTests<K, V> {
|
||||
@Test
|
||||
public void testIncrementDouble() {
|
||||
assumeTrue(RedisVersionUtils.atLeast("2.6", template.getConnectionFactory().getConnection()) &&
|
||||
valueFactory instanceof DoubleObjectFactory);
|
||||
valueFactory instanceof DoubleAsStringObjectFactory);
|
||||
K k1 = getKey();
|
||||
V v1 = getValue();
|
||||
map.put(k1, v1);
|
||||
|
||||
@@ -27,6 +27,7 @@ import java.util.Set;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.data.redis.ObjectFactory;
|
||||
import org.springframework.data.redis.core.BoundSetOperations;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.data.redis.support.collections.DefaultRedisSet;
|
||||
|
||||
@@ -31,6 +31,7 @@ import java.util.Set;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.data.redis.ObjectFactory;
|
||||
import org.springframework.data.redis.connection.ConnectionUtils;
|
||||
import org.springframework.data.redis.core.BoundZSetOperations;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
|
||||
@@ -18,8 +18,11 @@ package org.springframework.data.redis.support.collections;
|
||||
import java.util.Arrays;
|
||||
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.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;
|
||||
|
||||
@@ -22,7 +22,9 @@ import org.junit.After;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Test;
|
||||
import org.springframework.data.redis.ConnectionFactoryTracker;
|
||||
import org.springframework.data.redis.ObjectFactory;
|
||||
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.jedis.JedisConnectionFactory;
|
||||
import org.springframework.data.redis.core.RedisCallback;
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package org.springframework.data.redis.support.collections;
|
||||
|
||||
import org.springframework.data.redis.ObjectFactory;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.data.redis.support.collections.AbstractRedisCollection;
|
||||
import org.springframework.data.redis.support.collections.DefaultRedisList;
|
||||
|
||||
@@ -19,8 +19,13 @@ import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
|
||||
import org.junit.runners.Parameterized.Parameters;
|
||||
import org.springframework.data.redis.DoubleAsStringObjectFactory;
|
||||
import org.springframework.data.redis.LongAsStringObjectFactory;
|
||||
import org.springframework.data.redis.ObjectFactory;
|
||||
import org.springframework.data.redis.Person;
|
||||
import org.springframework.data.redis.PersonObjectFactory;
|
||||
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;
|
||||
@@ -67,8 +72,8 @@ public class RedisMapTests extends AbstractRedisMapTests<Object, Object> {
|
||||
// create Jedis Factory
|
||||
ObjectFactory<String> stringFactory = new StringObjectFactory();
|
||||
ObjectFactory<Person> personFactory = new PersonObjectFactory();
|
||||
ObjectFactory<String> doubleFactory = new DoubleObjectFactory();
|
||||
ObjectFactory<String> longFactory = new LongObjectFactory();
|
||||
ObjectFactory<String> doubleFactory = new DoubleAsStringObjectFactory();
|
||||
ObjectFactory<String> longFactory = new LongAsStringObjectFactory();
|
||||
|
||||
JedisConnectionFactory jedisConnFactory = new JedisConnectionFactory();
|
||||
jedisConnFactory.setUsePool(true);
|
||||
|
||||
@@ -35,8 +35,12 @@ import java.util.Set;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.runners.Parameterized.Parameters;
|
||||
import org.springframework.data.redis.DoubleAsStringObjectFactory;
|
||||
import org.springframework.data.redis.LongAsStringObjectFactory;
|
||||
import org.springframework.data.redis.ObjectFactory;
|
||||
import org.springframework.data.redis.Person;
|
||||
import org.springframework.data.redis.SettingsUtils;
|
||||
import org.springframework.data.redis.StringObjectFactory;
|
||||
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
|
||||
import org.springframework.data.redis.connection.jredis.JredisPool;
|
||||
import org.springframework.data.redis.connection.jredis.JredisConnectionFactory;
|
||||
@@ -236,8 +240,8 @@ public class RedisPropertiesTests extends RedisMapTests {
|
||||
|
||||
// create Jedis Factory
|
||||
ObjectFactory<String> stringFactory = new StringObjectFactory();
|
||||
ObjectFactory<String> longFactory = new LongObjectFactory();
|
||||
ObjectFactory<String> doubleFactory = new DoubleObjectFactory();
|
||||
ObjectFactory<String> longFactory = new LongAsStringObjectFactory();
|
||||
ObjectFactory<String> doubleFactory = new DoubleAsStringObjectFactory();
|
||||
|
||||
JedisConnectionFactory jedisConnFactory = new JedisConnectionFactory();
|
||||
jedisConnFactory.setUsePool(true);
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package org.springframework.data.redis.support.collections;
|
||||
|
||||
import org.springframework.data.redis.ObjectFactory;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.data.redis.support.collections.AbstractRedisCollection;
|
||||
import org.springframework.data.redis.support.collections.DefaultRedisSet;
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package org.springframework.data.redis.support.collections;
|
||||
|
||||
import org.springframework.data.redis.ObjectFactory;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.data.redis.support.collections.AbstractRedisCollection;
|
||||
import org.springframework.data.redis.support.collections.DefaultRedisZSet;
|
||||
|
||||
Reference in New Issue
Block a user