From 64456ea13448b627a5dbcefab9288812ae0ee640 Mon Sep 17 00:00:00 2001 From: Mark Paluch Date: Fri, 17 Jun 2016 09:33:13 +0200 Subject: [PATCH] DATAREDIS-500 - Polishing. Apply formatting rules. Use differing serializers in test. Original pull request: #190. --- .../data/redis/core/RedisTemplate.java | 1 + .../data/redis/core/RedisTemplateTests.java | 25 +++++++++++++++---- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/springframework/data/redis/core/RedisTemplate.java b/src/main/java/org/springframework/data/redis/core/RedisTemplate.java index 9afc02d79..d410cd720 100644 --- a/src/main/java/org/springframework/data/redis/core/RedisTemplate.java +++ b/src/main/java/org/springframework/data/redis/core/RedisTemplate.java @@ -73,6 +73,7 @@ import org.springframework.util.CollectionUtils; * @author Costin Leau * @author Christoph Strobl * @author Ninad Divadkar + * @author Anqing Shao * @param the Redis key type against which the template works (usually a String) * @param the Redis value type against which the template works * @see StringRedisTemplate diff --git a/src/test/java/org/springframework/data/redis/core/RedisTemplateTests.java b/src/test/java/org/springframework/data/redis/core/RedisTemplateTests.java index dad261901..b35a202d5 100644 --- a/src/test/java/org/springframework/data/redis/core/RedisTemplateTests.java +++ b/src/test/java/org/springframework/data/redis/core/RedisTemplateTests.java @@ -45,13 +45,13 @@ import org.springframework.dao.DataAccessException; import org.springframework.dao.InvalidDataAccessApiUsageException; import org.springframework.data.redis.ConnectionFactoryTracker; import org.springframework.data.redis.ObjectFactory; +import org.springframework.data.redis.Person; import org.springframework.data.redis.RedisTestProfileValueSource; import org.springframework.data.redis.SettingsUtils; import org.springframework.data.redis.TestCondition; import org.springframework.data.redis.connection.DataType; import org.springframework.data.redis.connection.RedisConnection; import org.springframework.data.redis.connection.StringRedisConnection; -import org.springframework.data.redis.connection.jedis.JedisClusterConnection; import org.springframework.data.redis.connection.jedis.JedisConnectionFactory; import org.springframework.data.redis.connection.jredis.JredisConnectionFactory; import org.springframework.data.redis.connection.srp.SrpConnectionFactory; @@ -59,6 +59,7 @@ import org.springframework.data.redis.core.ZSetOperations.TypedTuple; import org.springframework.data.redis.core.query.SortQueryBuilder; import org.springframework.data.redis.core.script.DefaultRedisScript; import org.springframework.data.redis.serializer.GenericToStringSerializer; +import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer; import org.springframework.data.redis.serializer.RedisSerializer; import org.springframework.data.redis.serializer.StringRedisSerializer; @@ -67,6 +68,7 @@ import org.springframework.data.redis.serializer.StringRedisSerializer; * * @author Jennifer Hickey * @author Christoph Strobl + * @author Anqing Shao */ @RunWith(Parameterized.class) public class RedisTemplateTests { @@ -300,7 +302,9 @@ public class RedisTemplateTests { @SuppressWarnings("rawtypes") @Test public void testExecutePipelinedCustomSerializer() { + assumeTrue(redisTemplate instanceof StringRedisTemplate); + List results = redisTemplate.executePipelined(new RedisCallback() { public Object doInRedis(RedisConnection connection) throws DataAccessException { StringRedisConnection stringRedisConn = (StringRedisConnection) connection; @@ -312,23 +316,34 @@ public class RedisTemplateTests { return null; } }, new GenericToStringSerializer(Long.class)); + assertEquals(Arrays.asList(new Object[] { 5l, 1l, 2l, Arrays.asList(new Long[] { 10l, 11l }) }), results); } + /** + * @see DATAREDIS-500 + */ @Test public void testExecutePipelinedWidthDifferentHashKeySerializerAndHashValueSerializer() { + assumeTrue(redisTemplate instanceof StringRedisTemplate); + redisTemplate.setKeySerializer(new StringRedisSerializer()); - redisTemplate.setHashKeySerializer(new StringRedisSerializer()); - redisTemplate.setHashValueSerializer(new GenericToStringSerializer(Long.class)); - redisTemplate.opsForHash().put((K) "foo", "key", 1L); + redisTemplate.setHashKeySerializer(new GenericToStringSerializer(Long.class)); + redisTemplate.setHashValueSerializer(new Jackson2JsonRedisSerializer(Person.class)); + + Person person = new Person("Homer", "Simpson", 38); + + redisTemplate.opsForHash().put((K) "foo", 1L, person); + List results = redisTemplate.executePipelined(new RedisCallback() { public Object doInRedis(RedisConnection connection) throws DataAccessException { connection.hGetAll(((StringRedisSerializer) redisTemplate.getKeySerializer()).serialize("foo")); return null; } }); - assertEquals(((Map) results.get(0)).get("key"), 1L); + + assertEquals(((Map) results.get(0)).get(1L), person); } @Test(expected = InvalidDataAccessApiUsageException.class)