Repository: camel Updated Branches: refs/heads/master 51fca498b -> 504799388
CAMEL-8478: IdempotentRepository - Add clear operation, fix clear operation in RedisIdempotentRepository Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/50479938 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/50479938 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/50479938 Branch: refs/heads/master Commit: 5047993887fa06b33ddac75ee3085bde867650c6 Parents: 51fca49 Author: Andrea Cosentino <anco...@gmail.com> Authored: Sat Jul 4 00:18:58 2015 +0200 Committer: Andrea Cosentino <anco...@gmail.com> Committed: Sat Jul 4 00:18:58 2015 +0200 ---------------------------------------------------------------------- .../processor/idempotent/RedisIdempotentRepository.java | 6 +++++- .../idempotent/RedisIdempotentRepositoryTest.java | 10 +++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/50479938/components/camel-spring-redis/src/main/java/org/apache/camel/component/redis/processor/idempotent/RedisIdempotentRepository.java ---------------------------------------------------------------------- diff --git a/components/camel-spring-redis/src/main/java/org/apache/camel/component/redis/processor/idempotent/RedisIdempotentRepository.java b/components/camel-spring-redis/src/main/java/org/apache/camel/component/redis/processor/idempotent/RedisIdempotentRepository.java index a1ef7ed..7f6a24e 100755 --- a/components/camel-spring-redis/src/main/java/org/apache/camel/component/redis/processor/idempotent/RedisIdempotentRepository.java +++ b/components/camel-spring-redis/src/main/java/org/apache/camel/component/redis/processor/idempotent/RedisIdempotentRepository.java @@ -30,16 +30,20 @@ public class RedisIdempotentRepository extends ServiceSupport implements Idempot private final SetOperations<String, String> setOperations; private final String processorName; private RedisConfiguration redisConfiguration; + private RedisTemplate<String, String> redisTemplate; public RedisIdempotentRepository(RedisTemplate<String, String> redisTemplate, String processorName) { this.setOperations = redisTemplate.opsForSet(); this.processorName = processorName; + this.redisTemplate = redisTemplate; } public RedisIdempotentRepository(String processorName) { redisConfiguration = new RedisConfiguration(); RedisTemplate<String, String> redisTemplate = redisConfiguration.getRedisTemplate(); + this.redisTemplate = redisTemplate; this.setOperations = redisTemplate.opsForSet(); + redisTemplate.getConnectionFactory().getConnection().flushDb(); this.processorName = processorName; } @@ -73,7 +77,7 @@ public class RedisIdempotentRepository extends ServiceSupport implements Idempot @ManagedOperation(description = "Clear the store") public void clear() { - setOperations.remove(processorName); + redisTemplate.getConnectionFactory().getConnection().flushDb(); } @ManagedAttribute(description = "The processor name") http://git-wip-us.apache.org/repos/asf/camel/blob/50479938/components/camel-spring-redis/src/test/java/org/apache/camel/component/redis/processor/idempotent/RedisIdempotentRepositoryTest.java ---------------------------------------------------------------------- diff --git a/components/camel-spring-redis/src/test/java/org/apache/camel/component/redis/processor/idempotent/RedisIdempotentRepositoryTest.java b/components/camel-spring-redis/src/test/java/org/apache/camel/component/redis/processor/idempotent/RedisIdempotentRepositoryTest.java index fd977ac..9c80e9a 100755 --- a/components/camel-spring-redis/src/test/java/org/apache/camel/component/redis/processor/idempotent/RedisIdempotentRepositoryTest.java +++ b/components/camel-spring-redis/src/test/java/org/apache/camel/component/redis/processor/idempotent/RedisIdempotentRepositoryTest.java @@ -18,6 +18,8 @@ package org.apache.camel.component.redis.processor.idempotent; import org.junit.Before; import org.junit.Test; +import org.springframework.data.redis.connection.RedisConnection; +import org.springframework.data.redis.connection.RedisConnectionFactory; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.core.SetOperations; @@ -30,6 +32,8 @@ public class RedisIdempotentRepositoryTest { private static final String REPOSITORY = "testRepository"; private static final String KEY = "KEY"; private RedisTemplate redisTemplate; + private RedisConnectionFactory redisConnectionFactory; + private RedisConnection redisConnection; private SetOperations setOperations; private RedisIdempotentRepository idempotentRepository; @@ -37,7 +41,11 @@ public class RedisIdempotentRepositoryTest { public void setUp() throws Exception { redisTemplate = mock(RedisTemplate.class); setOperations = mock(SetOperations.class); + redisConnection = mock(RedisConnection.class); + redisConnectionFactory = mock(RedisConnectionFactory.class); when(redisTemplate.opsForSet()).thenReturn(setOperations); + when(redisTemplate.getConnectionFactory()).thenReturn(redisConnectionFactory); + when(redisTemplate.getConnectionFactory().getConnection()).thenReturn(redisConnection); idempotentRepository = RedisIdempotentRepository.redisIdempotentRepository(redisTemplate, REPOSITORY); } @@ -62,7 +70,7 @@ public class RedisIdempotentRepositoryTest { @Test public void shouldClearRepository() { idempotentRepository.clear(); - verify(setOperations).remove(REPOSITORY); + verify(redisConnection).flushDb(); } @Test