diff --git a/src/test/java/org/springframework/data/redis/support/collections/DoubleObjectFactory.java b/src/test/java/org/springframework/data/redis/DoubleAsStringObjectFactory.java similarity index 87% rename from src/test/java/org/springframework/data/redis/support/collections/DoubleObjectFactory.java rename to src/test/java/org/springframework/data/redis/DoubleAsStringObjectFactory.java index 72dcb7ade..010ee9872 100644 --- a/src/test/java/org/springframework/data/redis/support/collections/DoubleObjectFactory.java +++ b/src/test/java/org/springframework/data/redis/DoubleAsStringObjectFactory.java @@ -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 { +public class DoubleAsStringObjectFactory implements ObjectFactory { private Random random = new Random(System.currentTimeMillis()); diff --git a/src/test/java/org/springframework/data/redis/DoubleObjectFactory.java b/src/test/java/org/springframework/data/redis/DoubleObjectFactory.java new file mode 100644 index 000000000..a5e9622ad --- /dev/null +++ b/src/test/java/org/springframework/data/redis/DoubleObjectFactory.java @@ -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 { + + private Random random = new Random(System.currentTimeMillis()); + + public Double instance() { + return random.nextDouble(); + } + +} diff --git a/src/test/java/org/springframework/data/redis/support/collections/LongObjectFactory.java b/src/test/java/org/springframework/data/redis/LongAsStringObjectFactory.java similarity index 87% rename from src/test/java/org/springframework/data/redis/support/collections/LongObjectFactory.java rename to src/test/java/org/springframework/data/redis/LongAsStringObjectFactory.java index d1838551d..d643bb963 100644 --- a/src/test/java/org/springframework/data/redis/support/collections/LongObjectFactory.java +++ b/src/test/java/org/springframework/data/redis/LongAsStringObjectFactory.java @@ -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 { +public class LongAsStringObjectFactory implements ObjectFactory { private Random random = new Random(System.currentTimeMillis()); diff --git a/src/test/java/org/springframework/data/redis/LongObjectFactory.java b/src/test/java/org/springframework/data/redis/LongObjectFactory.java new file mode 100644 index 000000000..fa816ee7c --- /dev/null +++ b/src/test/java/org/springframework/data/redis/LongObjectFactory.java @@ -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 { + + private Random random = new Random(System.currentTimeMillis()); + + public Long instance() { + return random.nextLong(); + } + +} diff --git a/src/test/java/org/springframework/data/redis/support/collections/ObjectFactory.java b/src/test/java/org/springframework/data/redis/ObjectFactory.java similarity index 92% rename from src/test/java/org/springframework/data/redis/support/collections/ObjectFactory.java rename to src/test/java/org/springframework/data/redis/ObjectFactory.java index cb7a995ad..5d4803444 100644 --- a/src/test/java/org/springframework/data/redis/support/collections/ObjectFactory.java +++ b/src/test/java/org/springframework/data/redis/ObjectFactory.java @@ -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. diff --git a/src/test/java/org/springframework/data/redis/support/collections/PersonObjectFactory.java b/src/test/java/org/springframework/data/redis/PersonObjectFactory.java similarity index 84% rename from src/test/java/org/springframework/data/redis/support/collections/PersonObjectFactory.java rename to src/test/java/org/springframework/data/redis/PersonObjectFactory.java index 78b521dab..db3389b68 100644 --- a/src/test/java/org/springframework/data/redis/support/collections/PersonObjectFactory.java +++ b/src/test/java/org/springframework/data/redis/PersonObjectFactory.java @@ -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 { private int counter = 0; - public Person instance() { String uuid = UUID.randomUUID().toString(); return new Person(uuid, uuid, ++counter, new Address(uuid, counter)); diff --git a/src/test/java/org/springframework/data/redis/RedisTestProfileValueSource.java b/src/test/java/org/springframework/data/redis/RedisTestProfileValueSource.java index f8beaef52..ffcdc9b55 100644 --- a/src/test/java/org/springframework/data/redis/RedisTestProfileValueSource.java +++ b/src/test/java/org/springframework/data/redis/RedisTestProfileValueSource.java @@ -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; + } } diff --git a/src/test/java/org/springframework/data/redis/support/collections/StringObjectFactory.java b/src/test/java/org/springframework/data/redis/StringObjectFactory.java similarity index 91% rename from src/test/java/org/springframework/data/redis/support/collections/StringObjectFactory.java rename to src/test/java/org/springframework/data/redis/StringObjectFactory.java index 7cfc54dbb..9ad76d977 100644 --- a/src/test/java/org/springframework/data/redis/support/collections/StringObjectFactory.java +++ b/src/test/java/org/springframework/data/redis/StringObjectFactory.java @@ -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 { - public String instance() { return UUID.randomUUID().toString(); } diff --git a/src/test/java/org/springframework/data/redis/cache/RedisCacheTest.java b/src/test/java/org/springframework/data/redis/cache/RedisCacheTest.java index 8e76558ab..6746312ff 100644 --- a/src/test/java/org/springframework/data/redis/cache/RedisCacheTest.java +++ b/src/test/java/org/springframework/data/redis/cache/RedisCacheTest.java @@ -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 diff --git a/src/test/java/org/springframework/data/redis/core/AbstractOperationsTestParams.java b/src/test/java/org/springframework/data/redis/core/AbstractOperationsTestParams.java new file mode 100644 index 000000000..f41eb8fbf --- /dev/null +++ b/src/test/java/org/springframework/data/redis/core/AbstractOperationsTestParams.java @@ -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 testParams() { + ObjectFactory stringFactory = new StringObjectFactory(); + SrpConnectionFactory srConnFactory = new SrpConnectionFactory(); + srConnFactory.setPort(SettingsUtils.getPort()); + srConnFactory.setHostName(SettingsUtils.getHost()); + srConnFactory.afterPropertiesSet(); + RedisTemplate stringTemplate = new StringRedisTemplate(); + stringTemplate.setConnectionFactory(srConnFactory); + stringTemplate.afterPropertiesSet(); + return Arrays.asList(new Object[][] { { stringTemplate, stringFactory, stringFactory } }); + } +} diff --git a/src/test/java/org/springframework/data/redis/core/DefaultSetOperationsTests.java b/src/test/java/org/springframework/data/redis/core/DefaultSetOperationsTests.java index 22558f4dd..429aae971 100644 --- a/src/test/java/org/springframework/data/redis/core/DefaultSetOperationsTests.java +++ b/src/test/java/org/springframework/data/redis/core/DefaultSetOperationsTests.java @@ -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 { - @Autowired - private RedisTemplate redisTemplate; - - private SetOperations setOps; + private RedisTemplate redisTemplate; + + private ObjectFactory keyFactory; + + private ObjectFactory valueFactory; + + private SetOperations setOps; + + public DefaultSetOperationsTests(RedisTemplate redisTemplate, ObjectFactory keyFactory, + ObjectFactory valueFactory) { + this.redisTemplate = redisTemplate; + this.keyFactory = keyFactory; + this.valueFactory = valueFactory; + } + + @Parameters + public static Collection 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() { + 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 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 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 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 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) { + } } } diff --git a/src/test/java/org/springframework/data/redis/core/DefaultValueOperationsTests.java b/src/test/java/org/springframework/data/redis/core/DefaultValueOperationsTests.java index 6ab0cfac1..aa90bc1aa 100644 --- a/src/test/java/org/springframework/data/redis/core/DefaultValueOperationsTests.java +++ b/src/test/java/org/springframework/data/redis/core/DefaultValueOperationsTests.java @@ -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 { - @Autowired - private RedisTemplate redisTemplate; + private RedisTemplate redisTemplate; - private ValueOperations valueOps; + private ObjectFactory keyFactory; + + private ObjectFactory valueFactory; + + private ValueOperations valueOps; + + public DefaultValueOperationsTests(RedisTemplate redisTemplate, ObjectFactory keyFactory, + ObjectFactory valueFactory) { + this.redisTemplate = redisTemplate; + this.keyFactory = keyFactory; + this.valueFactory = valueFactory; + } + + @Parameters + public static Collection testParams() { + ObjectFactory stringFactory = new StringObjectFactory(); + ObjectFactory longFactory = new LongObjectFactory(); + ObjectFactory doubleFactory = new DoubleObjectFactory(); + SrpConnectionFactory srConnFactory = new SrpConnectionFactory(); + srConnFactory.setPort(SettingsUtils.getPort()); + srConnFactory.setHostName(SettingsUtils.getHost()); + srConnFactory.afterPropertiesSet(); + RedisTemplate stringTemplate = new StringRedisTemplate(); + stringTemplate.setConnectionFactory(srConnFactory); + stringTemplate.afterPropertiesSet(); + RedisTemplate longTemplate = new RedisTemplate(); + longTemplate.setKeySerializer(new StringRedisSerializer()); + longTemplate.setValueSerializer(new GenericToStringSerializer(Long.class)); + longTemplate.setConnectionFactory(srConnFactory); + longTemplate.afterPropertiesSet(); + RedisTemplate doubleTemplate = new RedisTemplate(); + doubleTemplate.setKeySerializer(new StringRedisSerializer()); + doubleTemplate.setValueSerializer(new GenericToStringSerializer(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() { + 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 keysAndValues = new HashMap(); - keysAndValues.put("foo", "bar"); - keysAndValues.put("baz", "test"); + Map keysAndValues = new HashMap(); + 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(keysAndValues.values()), - new HashSet(valueOps.multiGet(keysAndValues.keySet()))); + assertEquals(new HashSet(keysAndValues.values()), + new HashSet(valueOps.multiGet(keysAndValues.keySet()))); } @Test public void testMultiSetIfAbsentFailure() { - valueOps.set("foo", "alreadyset"); - Map keysAndValues = new HashMap(); - 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 keysAndValues = new HashMap(); + keysAndValues.put(key1, value2); + keysAndValues.put(key2, value3); assertFalse(valueOps.multiSetIfAbsent(keysAndValues)); } } diff --git a/src/test/java/org/springframework/data/redis/listener/PubSubTestParams.java b/src/test/java/org/springframework/data/redis/listener/PubSubTestParams.java index a95bc7fb6..1de87e1b9 100644 --- a/src/test/java/org/springframework/data/redis/listener/PubSubTestParams.java +++ b/src/test/java/org/springframework/data/redis/listener/PubSubTestParams.java @@ -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 diff --git a/src/test/java/org/springframework/data/redis/listener/PubSubTests.java b/src/test/java/org/springframework/data/redis/listener/PubSubTests.java index a5235b324..74e29bf69 100644 --- a/src/test/java/org/springframework/data/redis/listener/PubSubTests.java +++ b/src/test/java/org/springframework/data/redis/listener/PubSubTests.java @@ -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 diff --git a/src/test/java/org/springframework/data/redis/support/BoundKeyOperationsTest.java b/src/test/java/org/springframework/data/redis/support/BoundKeyOperationsTest.java index 2b72a4188..29075e3fe 100644 --- a/src/test/java/org/springframework/data/redis/support/BoundKeyOperationsTest.java +++ b/src/test/java/org/springframework/data/redis/support/BoundKeyOperationsTest.java @@ -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 diff --git a/src/test/java/org/springframework/data/redis/support/BoundKeyParams.java b/src/test/java/org/springframework/data/redis/support/BoundKeyParams.java index 2c6edf06f..7c13e4cab 100644 --- a/src/test/java/org/springframework/data/redis/support/BoundKeyParams.java +++ b/src/test/java/org/springframework/data/redis/support/BoundKeyParams.java @@ -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 diff --git a/src/test/java/org/springframework/data/redis/support/collections/AbstractRedisCollectionTests.java b/src/test/java/org/springframework/data/redis/support/collections/AbstractRedisCollectionTests.java index f623bb3a2..d91cc3461 100644 --- a/src/test/java/org/springframework/data/redis/support/collections/AbstractRedisCollectionTests.java +++ b/src/test/java/org/springframework/data/redis/support/collections/AbstractRedisCollectionTests.java @@ -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; diff --git a/src/test/java/org/springframework/data/redis/support/collections/AbstractRedisListTests.java b/src/test/java/org/springframework/data/redis/support/collections/AbstractRedisListTests.java index 6f035c61a..037b4ac3d 100644 --- a/src/test/java/org/springframework/data/redis/support/collections/AbstractRedisListTests.java +++ b/src/test/java/org/springframework/data/redis/support/collections/AbstractRedisListTests.java @@ -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; diff --git a/src/test/java/org/springframework/data/redis/support/collections/AbstractRedisMapTests.java b/src/test/java/org/springframework/data/redis/support/collections/AbstractRedisMapTests.java index 11873a77a..266c21eb6 100644 --- a/src/test/java/org/springframework/data/redis/support/collections/AbstractRedisMapTests.java +++ b/src/test/java/org/springframework/data/redis/support/collections/AbstractRedisMapTests.java @@ -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 { @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 { @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 { @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); diff --git a/src/test/java/org/springframework/data/redis/support/collections/AbstractRedisSetTests.java b/src/test/java/org/springframework/data/redis/support/collections/AbstractRedisSetTests.java index 57f40fa1b..d8338e824 100644 --- a/src/test/java/org/springframework/data/redis/support/collections/AbstractRedisSetTests.java +++ b/src/test/java/org/springframework/data/redis/support/collections/AbstractRedisSetTests.java @@ -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; diff --git a/src/test/java/org/springframework/data/redis/support/collections/AbstractRedisZSetTest.java b/src/test/java/org/springframework/data/redis/support/collections/AbstractRedisZSetTest.java index c6a704a9f..043a241cf 100644 --- a/src/test/java/org/springframework/data/redis/support/collections/AbstractRedisZSetTest.java +++ b/src/test/java/org/springframework/data/redis/support/collections/AbstractRedisZSetTest.java @@ -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; diff --git a/src/test/java/org/springframework/data/redis/support/collections/CollectionTestParams.java b/src/test/java/org/springframework/data/redis/support/collections/CollectionTestParams.java index 99e0dfa97..06d16867e 100644 --- a/src/test/java/org/springframework/data/redis/support/collections/CollectionTestParams.java +++ b/src/test/java/org/springframework/data/redis/support/collections/CollectionTestParams.java @@ -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; diff --git a/src/test/java/org/springframework/data/redis/support/collections/RedisCollectionFactoryBeanTests.java b/src/test/java/org/springframework/data/redis/support/collections/RedisCollectionFactoryBeanTests.java index 100f6bd5e..86f008987 100644 --- a/src/test/java/org/springframework/data/redis/support/collections/RedisCollectionFactoryBeanTests.java +++ b/src/test/java/org/springframework/data/redis/support/collections/RedisCollectionFactoryBeanTests.java @@ -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; diff --git a/src/test/java/org/springframework/data/redis/support/collections/RedisListTests.java b/src/test/java/org/springframework/data/redis/support/collections/RedisListTests.java index caaaf7d7d..02432099b 100644 --- a/src/test/java/org/springframework/data/redis/support/collections/RedisListTests.java +++ b/src/test/java/org/springframework/data/redis/support/collections/RedisListTests.java @@ -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; diff --git a/src/test/java/org/springframework/data/redis/support/collections/RedisMapTests.java b/src/test/java/org/springframework/data/redis/support/collections/RedisMapTests.java index 95173adcd..e4aefa61a 100644 --- a/src/test/java/org/springframework/data/redis/support/collections/RedisMapTests.java +++ b/src/test/java/org/springframework/data/redis/support/collections/RedisMapTests.java @@ -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 { // create Jedis Factory ObjectFactory stringFactory = new StringObjectFactory(); ObjectFactory personFactory = new PersonObjectFactory(); - ObjectFactory doubleFactory = new DoubleObjectFactory(); - ObjectFactory longFactory = new LongObjectFactory(); + ObjectFactory doubleFactory = new DoubleAsStringObjectFactory(); + ObjectFactory longFactory = new LongAsStringObjectFactory(); JedisConnectionFactory jedisConnFactory = new JedisConnectionFactory(); jedisConnFactory.setUsePool(true); diff --git a/src/test/java/org/springframework/data/redis/support/collections/RedisPropertiesTests.java b/src/test/java/org/springframework/data/redis/support/collections/RedisPropertiesTests.java index e52832a2c..091a1f713 100644 --- a/src/test/java/org/springframework/data/redis/support/collections/RedisPropertiesTests.java +++ b/src/test/java/org/springframework/data/redis/support/collections/RedisPropertiesTests.java @@ -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 stringFactory = new StringObjectFactory(); - ObjectFactory longFactory = new LongObjectFactory(); - ObjectFactory doubleFactory = new DoubleObjectFactory(); + ObjectFactory longFactory = new LongAsStringObjectFactory(); + ObjectFactory doubleFactory = new DoubleAsStringObjectFactory(); JedisConnectionFactory jedisConnFactory = new JedisConnectionFactory(); jedisConnFactory.setUsePool(true); diff --git a/src/test/java/org/springframework/data/redis/support/collections/RedisSetTests.java b/src/test/java/org/springframework/data/redis/support/collections/RedisSetTests.java index 2770c696c..0b2ced9c1 100644 --- a/src/test/java/org/springframework/data/redis/support/collections/RedisSetTests.java +++ b/src/test/java/org/springframework/data/redis/support/collections/RedisSetTests.java @@ -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; diff --git a/src/test/java/org/springframework/data/redis/support/collections/RedisZSetTests.java b/src/test/java/org/springframework/data/redis/support/collections/RedisZSetTests.java index 566394203..57071e286 100644 --- a/src/test/java/org/springframework/data/redis/support/collections/RedisZSetTests.java +++ b/src/test/java/org/springframework/data/redis/support/collections/RedisZSetTests.java @@ -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;