camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From acosent...@apache.org
Subject camel git commit: CAMEL-11337: Camel-Infinispan: Add support for GetOrDefault operation on Producer
Date Fri, 26 May 2017 09:42:31 GMT
Repository: camel
Updated Branches:
  refs/heads/master 83ee9a5e5 -> 9d2f1df1e


CAMEL-11337: Camel-Infinispan: Add support for GetOrDefault operation on Producer


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/9d2f1df1
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/9d2f1df1
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/9d2f1df1

Branch: refs/heads/master
Commit: 9d2f1df1e926e82c5cd21a7a0bffe8c18e7e758c
Parents: 83ee9a5
Author: Andrea Cosentino <ancosen@gmail.com>
Authored: Fri May 26 11:38:24 2017 +0200
Committer: Andrea Cosentino <ancosen@gmail.com>
Committed: Fri May 26 11:42:00 2017 +0200

----------------------------------------------------------------------
 .../infinispan/InfinispanConstants.java         |  1 +
 .../infinispan/InfinispanOperation.java         |  1 +
 .../infinispan/InfinispanProducer.java          | 12 ++++++-
 .../infinispan/InfinispanProducerTest.java      | 38 ++++++++++++++++++++
 4 files changed, 51 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/9d2f1df1/components/camel-infinispan/src/main/java/org/apache/camel/component/infinispan/InfinispanConstants.java
----------------------------------------------------------------------
diff --git a/components/camel-infinispan/src/main/java/org/apache/camel/component/infinispan/InfinispanConstants.java
b/components/camel-infinispan/src/main/java/org/apache/camel/component/infinispan/InfinispanConstants.java
index 0ad16e1..eef8f6a 100644
--- a/components/camel-infinispan/src/main/java/org/apache/camel/component/infinispan/InfinispanConstants.java
+++ b/components/camel-infinispan/src/main/java/org/apache/camel/component/infinispan/InfinispanConstants.java
@@ -23,6 +23,7 @@ public interface InfinispanConstants {
     String CACHE_NAME = "CamelInfinispanCacheName";
     String KEY = "CamelInfinispanKey";
     String VALUE = "CamelInfinispanValue";
+    String DEFAULT_VALUE = "CamelInfinispanDefaultValue";
     String OLD_VALUE = "CamelInfinispanOldValue";
     String MAP = "CamelInfinispanMap";
     String OPERATION = "CamelInfinispanOperation";

http://git-wip-us.apache.org/repos/asf/camel/blob/9d2f1df1/components/camel-infinispan/src/main/java/org/apache/camel/component/infinispan/InfinispanOperation.java
----------------------------------------------------------------------
diff --git a/components/camel-infinispan/src/main/java/org/apache/camel/component/infinispan/InfinispanOperation.java
b/components/camel-infinispan/src/main/java/org/apache/camel/component/infinispan/InfinispanOperation.java
index 8d20969..7753fff 100644
--- a/components/camel-infinispan/src/main/java/org/apache/camel/component/infinispan/InfinispanOperation.java
+++ b/components/camel-infinispan/src/main/java/org/apache/camel/component/infinispan/InfinispanOperation.java
@@ -24,6 +24,7 @@ public enum InfinispanOperation {
     PUTIFABSENT,
     PUTIFABSENTASYNC,
     GET,
+    GETORDEFAULT,
     CONTAINSKEY,
     CONTAINSVALUE,
     REMOVE,

http://git-wip-us.apache.org/repos/asf/camel/blob/9d2f1df1/components/camel-infinispan/src/main/java/org/apache/camel/component/infinispan/InfinispanProducer.java
----------------------------------------------------------------------
diff --git a/components/camel-infinispan/src/main/java/org/apache/camel/component/infinispan/InfinispanProducer.java
b/components/camel-infinispan/src/main/java/org/apache/camel/component/infinispan/InfinispanProducer.java
index c1ccda2..7c09c8f 100644
--- a/components/camel-infinispan/src/main/java/org/apache/camel/component/infinispan/InfinispanProducer.java
+++ b/components/camel-infinispan/src/main/java/org/apache/camel/component/infinispan/InfinispanProducer.java
@@ -224,6 +224,17 @@ public class InfinispanProducer extends HeaderSelectorProducer {
 
         setResult(message, result);
     }
+    
+    @InvokeOnHeader("GETORDEFAULT")
+    void onGetOrDefault(Message message) {
+        final BasicCache<Object, Object> cache = manager.getCache(message, this.cacheName);
+        final Object key = message.getHeader(InfinispanConstants.KEY);
+        final Object defaultValue = message.getHeader(InfinispanConstants.DEFAULT_VALUE);
+        final Object result = cache.getOrDefault(key, defaultValue);
+
+        setResult(message, result);
+    }
+
 
     @InvokeOnHeader("CONTAINSKEY")
     @InvokeOnHeader(InfinispanConstants.CONTAINS_KEY)
@@ -371,7 +382,6 @@ public class InfinispanProducer extends HeaderSelectorProducer {
     void onSize(Message message) {
         final BasicCache<Object, Object> cache = manager.getCache(message, this.cacheName);
         final Object result = cache.size();
-
         setResult(message, result);
     }
 

http://git-wip-us.apache.org/repos/asf/camel/blob/9d2f1df1/components/camel-infinispan/src/test/java/org/apache/camel/component/infinispan/InfinispanProducerTest.java
----------------------------------------------------------------------
diff --git a/components/camel-infinispan/src/test/java/org/apache/camel/component/infinispan/InfinispanProducerTest.java
b/components/camel-infinispan/src/test/java/org/apache/camel/component/infinispan/InfinispanProducerTest.java
index d26744a..f84bcc9 100644
--- a/components/camel-infinispan/src/test/java/org/apache/camel/component/infinispan/InfinispanProducerTest.java
+++ b/components/camel-infinispan/src/test/java/org/apache/camel/component/infinispan/InfinispanProducerTest.java
@@ -494,6 +494,42 @@ public class InfinispanProducerTest extends InfinispanTestSupport {
 
         waitForNullValue(KEY_ONE);
     }
+    
+    @Test
+    public void getOrDefault() throws Exception {
+        template.send("direct:start", new Processor() {
+            @Override
+            public void process(Exchange exchange) throws Exception {
+                exchange.getIn().setHeader(InfinispanConstants.KEY, KEY_ONE);
+                exchange.getIn().setHeader(InfinispanConstants.VALUE, VALUE_ONE);
+                exchange.getIn().setHeader(InfinispanConstants.OPERATION, InfinispanOperation.PUT);
+            }
+        });
+
+        Object value = currentCache().get(KEY_ONE);
+        assertEquals(VALUE_ONE, value.toString());
+
+        Exchange exchange;
+        exchange = template.send("direct:getOrDefault", new Processor() {
+            @Override
+            public void process(Exchange exchange) throws Exception {
+                exchange.getIn().setHeader(InfinispanConstants.KEY, KEY_ONE);
+                exchange.getIn().setHeader(InfinispanConstants.DEFAULT_VALUE, "defaultTest");
+            }
+        });
+        String resultGet = exchange.getIn().getBody(String.class);
+        assertEquals(VALUE_ONE, resultGet);
+        
+        exchange = template.send("direct:getOrDefault", new Processor() {
+            @Override
+            public void process(Exchange exchange) throws Exception {
+                exchange.getIn().setHeader(InfinispanConstants.KEY, KEY_TWO);
+                exchange.getIn().setHeader(InfinispanConstants.DEFAULT_VALUE, "defaultTest");
+            }
+        });
+        resultGet = exchange.getIn().getBody(String.class);
+        assertEquals("defaultTest", resultGet);
+    }
 
     @Test
     public void putOperationReturnsThePreviousValue() throws Exception {
@@ -1015,6 +1051,8 @@ public class InfinispanProducerTest extends InfinispanTestSupport {
                     .to("infinispan?cacheContainer=#cacheContainer&operation=PUTIFABSENT");
                 from("direct:get")
                     .to("infinispan?cacheContainer=#cacheContainer&operation=GET");
+                from("direct:getOrDefault")
+                    .to("infinispan?cacheContainer=#cacheContainer&operation=GETORDEFAULT");
                 from("direct:remove")
                     .to("infinispan?cacheContainer=#cacheContainer&operation=REMOVE");
                 from("direct:clear")


Mime
View raw message