camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [2/2] camel git commit: Resolve CAMEL-8666 Infinispan add other operations to the available
Date Sun, 19 Apr 2015 06:18:20 GMT
Resolve CAMEL-8666 Infinispan add other operations to the available


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

Branch: refs/heads/master
Commit: 1be245a3f3ca1a0b67481b1753a585380b5a9b0f
Parents: 10fcf33
Author: ancosen <ancosen@gmail.com>
Authored: Sat Apr 18 14:03:57 2015 +0200
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Sun Apr 19 08:11:23 2015 +0200

----------------------------------------------------------------------
 .../infinispan/InfinispanConstants.java         |   5 +
 .../infinispan/InfinispanOperation.java         |  26 +++-
 .../infinispan/InfinispanProducerTest.java      | 122 ++++++++++++++++++-
 .../infinispan/InfinispanTestSupport.java       |   2 +
 .../src/test/resources/log4j.properties         |   2 +-
 5 files changed, 153 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/1be245a3/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 2a6b27e..427b618 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
@@ -24,8 +24,13 @@ public interface InfinispanConstants {
     String VALUE = "CamelInfinispanValue";
     String OPERATION = "CamelInfinispanOperation";
     String PUT = "CamelInfinispanOperationPut";
+    String PUT_ALL = "CamelInfinispanOperationPutAll";
+    String PUT_IF_ABSENT = "CamelInfinispanOperationPutIfAbsent";
     String GET = "CamelInfinispanOperationGet";
+    String CONTAINS_KEY = "CamelInfinispanOperationContainsKey";
+    String CONTAINS_VALUE = "CamelInfinispanOperationContainsValue";
     String REMOVE = "CamelInfinispanOperationRemove";
+    String REPLACE = "CamelInfinispanOperationReplace";
     String CLEAR = "CamelInfinispanOperationClear";
     String RESULT = "CamelInfinispanOperationResult";
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/1be245a3/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 9299fd6..023062d 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
@@ -56,20 +56,42 @@ public class InfinispanOperation {
                 Object result = cache.put(getKey(exchange), getValue(exchange));
                 setResult(result, exchange);
             }
+        }, PUTIFABSENT {
+            @Override
+            void execute(BasicCache<Object, Object> cache, Exchange exchange) {
+                Object result = cache.putIfAbsent(getKey(exchange), getValue(exchange));
+                setResult(result, exchange);
+            }
         }, GET {
             @Override
             void execute(BasicCache<Object, Object> cache, Exchange exchange) {
                 Object result = cache.get(getKey(exchange));
                 setResult(result, exchange);
             }
+        }, CONTAINSKEY {
+            @Override
+            void execute(BasicCache<Object, Object> cache, Exchange exchange) {
+                Object result = cache.containsKey(getKey(exchange));
+                setResult(result, exchange);
+            }
+        }, CONTAINSVALUE {
+            @Override
+            void execute(BasicCache<Object, Object> cache, Exchange exchange) {
+                Object result = cache.containsValue(getValue(exchange));
+                setResult(result, exchange);
+            }
         }, REMOVE {
             @Override
             void execute(BasicCache<Object, Object> cache, Exchange exchange) {
                 Object result = cache.remove(getKey(exchange));
                 setResult(result, exchange);
             }
-
-
+        }, REPLACE {
+            @Override
+            void execute(BasicCache<Object, Object> cache, Exchange exchange) {
+                Object result = cache.replace(getKey(exchange), getValue(exchange));
+                setResult(result, exchange);
+            }
         }, CLEAR {
             @Override
             void execute(BasicCache<Object, Object> cache, Exchange exchange) {

http://git-wip-us.apache.org/repos/asf/camel/blob/1be245a3/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 a5f6b25..4061864 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
@@ -57,6 +57,102 @@ public class InfinispanProducerTest extends InfinispanTestSupport {
         Object value = currentCache().get(KEY_ONE);
         assertThat(value.toString(), is(VALUE_ONE));
     }
+    
+    @Test
+    public void putIfAbsentAlreadyExists() throws Exception {
+        currentCache().put(KEY_ONE, VALUE_ONE);
+        
+        template.send("direct:putifabsent", new Processor() {
+            @Override
+            public void process(Exchange exchange) throws Exception {
+                exchange.getIn().setHeader(InfinispanConstants.KEY, KEY_ONE);
+                exchange.getIn().setHeader(InfinispanConstants.VALUE, VALUE_TWO);
+                exchange.getIn().setHeader(InfinispanConstants.OPERATION, InfinispanConstants.PUT_IF_ABSENT);
+            }
+        });
+
+        Object value = currentCache().get(KEY_ONE);
+        assertThat(value.toString(), is(VALUE_ONE));
+        assertEquals(currentCache().size(), 1);
+    }
+    
+    @Test
+    public void putIfAbsentNotExists() throws Exception {
+        currentCache().put(KEY_ONE, VALUE_ONE);
+        
+        template.send("direct:putifabsent", new Processor() {
+            @Override
+            public void process(Exchange exchange) throws Exception {
+                exchange.getIn().setHeader(InfinispanConstants.KEY, KEY_TWO);
+                exchange.getIn().setHeader(InfinispanConstants.VALUE, VALUE_TWO);
+                exchange.getIn().setHeader(InfinispanConstants.OPERATION, InfinispanConstants.PUT_IF_ABSENT);
+            }
+        });
+
+        Object value = currentCache().get(KEY_TWO);
+        assertThat(value.toString(), is(VALUE_TWO));
+        assertEquals(currentCache().size(), 2);
+    }
+    
+    @Test
+    public void notContainsKeyTest() throws Exception {
+        currentCache().put(KEY_ONE, VALUE_ONE);
+        
+        Exchange exchange = template.request("direct:containskey", new Processor() {
+            @Override
+            public void process(Exchange exchange) throws Exception {
+                exchange.getIn().setHeader(InfinispanConstants.KEY, KEY_TWO);
+                exchange.getIn().setHeader(InfinispanConstants.OPERATION, InfinispanConstants.CONTAINS_KEY);
+            }
+        });
+
+        assertThat(exchange.getIn().getHeader(InfinispanConstants.RESULT, Boolean.class),
is(false));
+    }
+    
+    @Test
+    public void containsKeyTest() throws Exception {
+        currentCache().put(KEY_ONE, VALUE_ONE);
+        
+        Exchange exchange = template.request("direct:containskey", new Processor() {
+            @Override
+            public void process(Exchange exchange) throws Exception {
+                exchange.getIn().setHeader(InfinispanConstants.KEY, KEY_ONE);
+                exchange.getIn().setHeader(InfinispanConstants.OPERATION, InfinispanConstants.CONTAINS_KEY);
+            }
+        });
+
+        assertThat(exchange.getIn().getHeader(InfinispanConstants.RESULT, Boolean.class),
is(true));
+    }
+    
+    @Test
+    public void notContainsValueTest() throws Exception {
+        currentCache().put(KEY_ONE, VALUE_ONE);
+        
+        Exchange exchange = template.request("direct:containsvalue", new Processor() {
+            @Override
+            public void process(Exchange exchange) throws Exception {
+                exchange.getIn().setHeader(InfinispanConstants.VALUE, VALUE_TWO);
+                exchange.getIn().setHeader(InfinispanConstants.OPERATION, InfinispanConstants.CONTAINS_VALUE);
+            }
+        });
+
+        assertThat(exchange.getIn().getHeader(InfinispanConstants.RESULT, Boolean.class),
is(false));
+    }
+    
+    @Test
+    public void containsValueTest() throws Exception {
+        currentCache().put(KEY_ONE, VALUE_ONE);
+        
+        Exchange exchange = template.request("direct:containsvalue", new Processor() {
+            @Override
+            public void process(Exchange exchange) throws Exception {
+                exchange.getIn().setHeader(InfinispanConstants.VALUE, VALUE_ONE);
+                exchange.getIn().setHeader(InfinispanConstants.OPERATION, InfinispanConstants.CONTAINS_VALUE);
+            }
+        });
+
+        assertThat(exchange.getIn().getHeader(InfinispanConstants.RESULT, Boolean.class),
is(true));
+    }
 
     @Test
     public void putOperationReturnsThePreviousValue() throws Exception {
@@ -88,6 +184,23 @@ public class InfinispanProducerTest extends InfinispanTestSupport {
 
         assertThat(exchange.getIn().getHeader(InfinispanConstants.RESULT, String.class),
is(VALUE_ONE));
     }
+    
+    @Test
+    public void replaceAValueByKey() throws Exception {
+        currentCache().put(KEY_ONE, VALUE_ONE);
+
+        Exchange exchange = template.request("direct:replace", new Processor() {
+            @Override
+            public void process(Exchange exchange) throws Exception {
+                exchange.getIn().setHeader(InfinispanConstants.KEY, KEY_ONE);
+                exchange.getIn().setHeader(InfinispanConstants.VALUE, VALUE_TWO);
+                exchange.getIn().setHeader(InfinispanConstants.OPERATION, InfinispanConstants.REPLACE);
+            }
+        });
+
+        assertThat(exchange.getIn().getHeader(InfinispanConstants.RESULT, String.class),
is(VALUE_ONE));
+        assertEquals(currentCache().get(KEY_ONE), VALUE_TWO);
+    }
 
     @Test
     public void deletesExistingValueByKey() throws Exception {
@@ -174,15 +287,22 @@ public class InfinispanProducerTest extends InfinispanTestSupport {
             public void configure() {
                 from("direct:start")
                         .to("infinispan://localhost?cacheContainer=#cacheContainer");
-
                 from("direct:put")
                         .to("infinispan://localhost?cacheContainer=#cacheContainer&command=PUT");
+                from("direct:putifabsent")
+                        .to("infinispan://localhost?cacheContainer=#cacheContainer&command=PUTIFABSENT");
                 from("direct:get")
                         .to("infinispan://localhost?cacheContainer=#cacheContainer&command=GET");
                 from("direct:remove")
                         .to("infinispan://localhost?cacheContainer=#cacheContainer&command=REMOVE");
                 from("direct:clear")
                         .to("infinispan://localhost?cacheContainer=#cacheContainer&command=CLEAR");
+                from("direct:replace")
+                        .to("infinispan://localhost?cacheContainer=#cacheContainer&command=REPLACE");
+                from("direct:containskey")
+                        .to("infinispan://localhost?cacheContainer=#cacheContainer&command=CONTAINSKEY");
+                from("direct:containsvalue")
+                        .to("infinispan://localhost?cacheContainer=#cacheContainer&command=CONTAINSVALUE");
             }
         };
     }

http://git-wip-us.apache.org/repos/asf/camel/blob/1be245a3/components/camel-infinispan/src/test/java/org/apache/camel/component/infinispan/InfinispanTestSupport.java
----------------------------------------------------------------------
diff --git a/components/camel-infinispan/src/test/java/org/apache/camel/component/infinispan/InfinispanTestSupport.java
b/components/camel-infinispan/src/test/java/org/apache/camel/component/infinispan/InfinispanTestSupport.java
index 0591f27..e6e2223 100644
--- a/components/camel-infinispan/src/test/java/org/apache/camel/component/infinispan/InfinispanTestSupport.java
+++ b/components/camel-infinispan/src/test/java/org/apache/camel/component/infinispan/InfinispanTestSupport.java
@@ -26,6 +26,8 @@ import org.junit.Before;
 public class InfinispanTestSupport extends CamelTestSupport {
     protected static final String KEY_ONE = "keyOne";
     protected static final String VALUE_ONE = "valueOne";
+    protected static final String KEY_TWO = "keyTwo";
+    protected static final String VALUE_TWO = "valueTwo";
 
     protected BasicCacheContainer basicCacheContainer;
 

http://git-wip-us.apache.org/repos/asf/camel/blob/1be245a3/components/camel-infinispan/src/test/resources/log4j.properties
----------------------------------------------------------------------
diff --git a/components/camel-infinispan/src/test/resources/log4j.properties b/components/camel-infinispan/src/test/resources/log4j.properties
index 077ffeb..622636c 100644
--- a/components/camel-infinispan/src/test/resources/log4j.properties
+++ b/components/camel-infinispan/src/test/resources/log4j.properties
@@ -30,5 +30,5 @@ log4j.appender.out.layout.ConversionPattern=[%30.30t] %-30.30c{1} %-5p %m%n
 log4j.appender.file=org.apache.log4j.FileAppender
 log4j.appender.file.layout=org.apache.log4j.PatternLayout
 log4j.appender.file.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - %m%n
-log4j.appender.file.file=target/camel-ical-test.log
+log4j.appender.file.file=target/camel-infinispan-test.log
 log4j.appender.file.append=true


Mime
View raw message