This is an automated email from the ASF dual-hosted git repository.

acosentino pushed a commit to branch camel-2.x
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/camel-2.x by this push:
     new 58937b4  CAMEL-13397 - RedisStringIdempotentRepository resetting 
expiry on existing keys
58937b4 is described below

commit 58937b4568cfdb996e771c0b201c15aebacec413
Author: Andrea Cosentino <[email protected]>
AuthorDate: Wed Apr 10 14:39:05 2019 +0200

    CAMEL-13397 - RedisStringIdempotentRepository resetting expiry on existing 
keys
---
 .../idempotent/RedisStringIdempotentRepository.java       |  6 +++---
 .../idempotent/RedisStringIdempotentRepositoryTest.java   | 15 +++++++++++----
 2 files changed, 14 insertions(+), 7 deletions(-)

diff --git 
a/components/camel-spring-redis/src/main/java/org/apache/camel/component/redis/processor/idempotent/RedisStringIdempotentRepository.java
 
b/components/camel-spring-redis/src/main/java/org/apache/camel/component/redis/processor/idempotent/RedisStringIdempotentRepository.java
index 43b6623..bdd336f 100644
--- 
a/components/camel-spring-redis/src/main/java/org/apache/camel/component/redis/processor/idempotent/RedisStringIdempotentRepository.java
+++ 
b/components/camel-spring-redis/src/main/java/org/apache/camel/component/redis/processor/idempotent/RedisStringIdempotentRepository.java
@@ -16,6 +16,7 @@
  */
 package org.apache.camel.component.redis.processor.idempotent;
 
+import java.time.Duration;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.concurrent.TimeUnit;
@@ -52,11 +53,10 @@ public class RedisStringIdempotentRepository extends 
RedisIdempotentRepository {
     @ManagedOperation(description = "Adds the key to the store")
     @Override
     public boolean add(String key) {
-        boolean added = valueOperations.setIfAbsent(createRedisKey(key), key);
         if (expiry > 0) {
-            valueOperations.getOperations().expire(createRedisKey(key), 
expiry, TimeUnit.SECONDS);
+            return valueOperations.setIfAbsent(createRedisKey(key), key, 
Duration.ofSeconds(expiry));
         }
-        return added;
+        return valueOperations.setIfAbsent(createRedisKey(key), key);
     }
 
     @ManagedOperation(description = "Remove the key from the store")
diff --git 
a/components/camel-spring-redis/src/test/java/org/apache/camel/component/redis/processor/idempotent/RedisStringIdempotentRepositoryTest.java
 
b/components/camel-spring-redis/src/test/java/org/apache/camel/component/redis/processor/idempotent/RedisStringIdempotentRepositoryTest.java
index 286b9e3..ae69d3f 100644
--- 
a/components/camel-spring-redis/src/test/java/org/apache/camel/component/redis/processor/idempotent/RedisStringIdempotentRepositoryTest.java
+++ 
b/components/camel-spring-redis/src/test/java/org/apache/camel/component/redis/processor/idempotent/RedisStringIdempotentRepositoryTest.java
@@ -16,6 +16,7 @@
  */
 package org.apache.camel.component.redis.processor.idempotent;
 
+import java.time.Duration;
 import java.util.concurrent.TimeUnit;
 
 import org.junit.Before;
@@ -37,6 +38,7 @@ import static org.mockito.Mockito.when;
 public class RedisStringIdempotentRepositoryTest {
 
     private static final String REPOSITORY = "testRepository";
+    private static final String REPOSITORY_NOEXPIRY = "testRepositoryNoExpiry";
     private static final String KEY = "KEY";
 
     @Mock
@@ -51,27 +53,30 @@ public class RedisStringIdempotentRepositoryTest {
     private ValueOperations<String, String> valueOperations;
 
     private RedisStringIdempotentRepository idempotentRepository;
+    private RedisStringIdempotentRepository idempotentRepositoryNoExpiry;
 
     @Before
     public void setUp() throws Exception {
         when(redisTemplate.opsForValue()).thenReturn(valueOperations);
-        when(valueOperations.getOperations()).thenReturn(redisOperations);
         idempotentRepository = new 
RedisStringIdempotentRepository(redisTemplate, REPOSITORY);
         idempotentRepository.setExpiry(1000L);
+        idempotentRepositoryNoExpiry = new 
RedisStringIdempotentRepository(redisTemplate, REPOSITORY_NOEXPIRY);
     }
 
     @Test
     public void shouldAddKey() {
         idempotentRepository.add(KEY);
-        
verify(valueOperations).setIfAbsent(idempotentRepository.createRedisKey(KEY), 
KEY);
-        verify(redisOperations)
-                .expire(idempotentRepository.createRedisKey(KEY), 1000L, 
TimeUnit.SECONDS);
+        
verify(valueOperations).setIfAbsent(idempotentRepository.createRedisKey(KEY), 
KEY, Duration.ofSeconds(1000L));
+        idempotentRepositoryNoExpiry.add(KEY);
+        
verify(valueOperations).setIfAbsent(idempotentRepositoryNoExpiry.createRedisKey(KEY),
 KEY);
     }
 
     @Test
     public void shoulCheckForMembers() {
         idempotentRepository.contains(KEY);
         verify(valueOperations).get(idempotentRepository.createRedisKey(KEY));
+        idempotentRepositoryNoExpiry.contains(KEY);
+        
verify(valueOperations).get(idempotentRepositoryNoExpiry.createRedisKey(KEY));  
     
     }
 
 
@@ -79,6 +84,8 @@ public class RedisStringIdempotentRepositoryTest {
     public void shouldReturnProcessorName() {
         String processorName = idempotentRepository.getProcessorName();
         assertEquals(REPOSITORY, processorName);
+        String processorNameNoExpiry = 
idempotentRepositoryNoExpiry.getProcessorName();
+        assertEquals(REPOSITORY_NOEXPIRY, processorNameNoExpiry);
     }
 
 }

Reply via email to