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-8877 Camel-Hazelcast: Add containsKey and containsValue operation to map Producer
Date Tue, 16 Jun 2015 15:32:33 GMT
Repository: camel
Updated Branches:
  refs/heads/master ca1d054b0 -> a7eb8b179


CAMEL-8877 Camel-Hazelcast: Add containsKey and containsValue operation to map Producer


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

Branch: refs/heads/master
Commit: a7eb8b17987b7fc4c9a8fe87fa8b5af31b14c547
Parents: ca1d054
Author: Andrea Cosentino <ancosen@gmail.com>
Authored: Tue Jun 16 11:43:46 2015 +0200
Committer: Andrea Cosentino <ancosen@gmail.com>
Committed: Tue Jun 16 11:44:24 2015 +0200

----------------------------------------------------------------------
 .../hazelcast/HazelcastComponentHelper.java     |  2 ++
 .../component/hazelcast/HazelcastConstants.java |  4 ++-
 .../hazelcast/map/HazelcastMapProducer.java     | 23 ++++++++++++
 .../HazelcastMapProducerForSpringTest.java      | 28 +++++++++++++++
 .../hazelcast/HazelcastMapProducerTest.java     | 38 +++++++++++++++++++-
 .../META-INF/spring/test-camel-context-map.xml  | 18 ++++++++++
 6 files changed, 111 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/a7eb8b17/components/camel-hazelcast/src/main/java/org/apache/camel/component/hazelcast/HazelcastComponentHelper.java
----------------------------------------------------------------------
diff --git a/components/camel-hazelcast/src/main/java/org/apache/camel/component/hazelcast/HazelcastComponentHelper.java
b/components/camel-hazelcast/src/main/java/org/apache/camel/component/hazelcast/HazelcastComponentHelper.java
index db96e91..66c7b6d 100644
--- a/components/camel-hazelcast/src/main/java/org/apache/camel/component/hazelcast/HazelcastComponentHelper.java
+++ b/components/camel-hazelcast/src/main/java/org/apache/camel/component/hazelcast/HazelcastComponentHelper.java
@@ -101,6 +101,8 @@ public final class HazelcastComponentHelper {
         addMapping("removeAll", HazelcastConstants.REMOVE_ALL_OPERATION);
         addMapping("retainAll", HazelcastConstants.RETAIN_ALL_OPERATION);
         addMapping("valueCount", HazelcastConstants.VALUE_COUNT_OPERATION);
+        addMapping("containsKey", HazelcastConstants.CONTAINS_KEY_OPERATION);
+        addMapping("containsValue", HazelcastConstants.CONTAINS_VALUE_OPERATION);
 
         // multimap
         addMapping("removevalue", HazelcastConstants.REMOVEVALUE_OPERATION);

http://git-wip-us.apache.org/repos/asf/camel/blob/a7eb8b17/components/camel-hazelcast/src/main/java/org/apache/camel/component/hazelcast/HazelcastConstants.java
----------------------------------------------------------------------
diff --git a/components/camel-hazelcast/src/main/java/org/apache/camel/component/hazelcast/HazelcastConstants.java
b/components/camel-hazelcast/src/main/java/org/apache/camel/component/hazelcast/HazelcastConstants.java
index 19e18b1..a146d46 100644
--- a/components/camel-hazelcast/src/main/java/org/apache/camel/component/hazelcast/HazelcastConstants.java
+++ b/components/camel-hazelcast/src/main/java/org/apache/camel/component/hazelcast/HazelcastConstants.java
@@ -69,9 +69,11 @@ public final class HazelcastConstants {
     public static final int EVICT_OPERATION = 12;
     public static final int EVICT_ALL_OPERATION = 13;
     public static final int VALUE_COUNT_OPERATION = 14;
+    public static final int CONTAINS_KEY_OPERATION = 15;
+    public static final int CONTAINS_VALUE_OPERATION = 16;
     
     // multimap
-    public static final int REMOVEVALUE_OPERATION = 15;
+    public static final int REMOVEVALUE_OPERATION = 17;
 
     // atomic numbers
     public static final int INCREMENT_OPERATION = 20;

http://git-wip-us.apache.org/repos/asf/camel/blob/a7eb8b17/components/camel-hazelcast/src/main/java/org/apache/camel/component/hazelcast/map/HazelcastMapProducer.java
----------------------------------------------------------------------
diff --git a/components/camel-hazelcast/src/main/java/org/apache/camel/component/hazelcast/map/HazelcastMapProducer.java
b/components/camel-hazelcast/src/main/java/org/apache/camel/component/hazelcast/map/HazelcastMapProducer.java
index 3d2abf2..563fe75 100644
--- a/components/camel-hazelcast/src/main/java/org/apache/camel/component/hazelcast/map/HazelcastMapProducer.java
+++ b/components/camel-hazelcast/src/main/java/org/apache/camel/component/hazelcast/map/HazelcastMapProducer.java
@@ -97,6 +97,14 @@ public class HazelcastMapProducer extends HazelcastDefaultProducer {
         case HazelcastConstants.GET_ALL_OPERATION:
             this.getAll(oid, exchange);
             break;
+            
+        case HazelcastConstants.CONTAINS_KEY_OPERATION:
+            this.containsKey(oid, exchange);
+            break;
+            
+        case HazelcastConstants.CONTAINS_VALUE_OPERATION:
+            this.containsValue(exchange);
+            break;
 
         case HazelcastConstants.DELETE_OPERATION:
             this.delete(oid);
@@ -241,4 +249,19 @@ public class HazelcastMapProducer extends HazelcastDefaultProducer {
     private void evictAll() {
         this.cache.evictAll();
     }
+    
+    /**
+     * Check for a specific key in the cache and return true if it exists or false otherwise
+     */
+    private void containsKey(Object oid, Exchange exchange) {
+        exchange.getOut().setBody(this.cache.containsKey(oid));
+    }
+    
+    /**
+     * Check for a specific value in the cache and return true if it exists or false otherwise
+     */
+    private void containsValue(Exchange exchange) {
+        Object body = exchange.getIn().getBody();
+        exchange.getOut().setBody(this.cache.containsValue(body));
+    }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/camel/blob/a7eb8b17/components/camel-hazelcast/src/test/java/org/apache/camel/component/hazelcast/HazelcastMapProducerForSpringTest.java
----------------------------------------------------------------------
diff --git a/components/camel-hazelcast/src/test/java/org/apache/camel/component/hazelcast/HazelcastMapProducerForSpringTest.java
b/components/camel-hazelcast/src/test/java/org/apache/camel/component/hazelcast/HazelcastMapProducerForSpringTest.java
index 75e2667..1c7374b 100644
--- a/components/camel-hazelcast/src/test/java/org/apache/camel/component/hazelcast/HazelcastMapProducerForSpringTest.java
+++ b/components/camel-hazelcast/src/test/java/org/apache/camel/component/hazelcast/HazelcastMapProducerForSpringTest.java
@@ -176,4 +176,32 @@ public class HazelcastMapProducerForSpringTest extends HazelcastCamelSpringTestS
         template.sendBodyAndHeaders("direct:evictAll", "", headers);
         verify(map).evictAll();
     }
+    
+    @Test
+    public void testContainsKey() {
+        when(map.containsKey("testOk")).thenReturn(true);
+        when(map.containsKey("testKo")).thenReturn(false);
+        template.sendBodyAndHeader("direct:containsKey", null, HazelcastConstants.OBJECT_ID,
"testOk");
+        Boolean body = consumer.receiveBody("seda:out", 5000, Boolean.class);
+        verify(map).containsKey("testOk");
+        assertEquals(true, body);
+        template.sendBodyAndHeader("direct:containsKey", null, HazelcastConstants.OBJECT_ID,
"testKo");
+        body = consumer.receiveBody("seda:out", 5000, Boolean.class);
+        verify(map).containsKey("testKo");
+        assertEquals(false, body);
+    }
+    
+    @Test
+    public void testContainsValue() {
+        when(map.containsValue("testOk")).thenReturn(true);
+        when(map.containsValue("testKo")).thenReturn(false);
+        template.sendBody("direct:containsValue", "testOk");
+        Boolean body = consumer.receiveBody("seda:out", 5000, Boolean.class);
+        verify(map).containsValue("testOk");
+        assertEquals(true, body);
+        template.sendBody("direct:containsValue", "testKo");
+        body = consumer.receiveBody("seda:out", 5000, Boolean.class);
+        verify(map).containsValue("testKo");
+        assertEquals(false, body);
+    }
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/a7eb8b17/components/camel-hazelcast/src/test/java/org/apache/camel/component/hazelcast/HazelcastMapProducerTest.java
----------------------------------------------------------------------
diff --git a/components/camel-hazelcast/src/test/java/org/apache/camel/component/hazelcast/HazelcastMapProducerTest.java
b/components/camel-hazelcast/src/test/java/org/apache/camel/component/hazelcast/HazelcastMapProducerTest.java
index 0652ce9..8ffb56d 100644
--- a/components/camel-hazelcast/src/test/java/org/apache/camel/component/hazelcast/HazelcastMapProducerTest.java
+++ b/components/camel-hazelcast/src/test/java/org/apache/camel/component/hazelcast/HazelcastMapProducerTest.java
@@ -217,6 +217,34 @@ public class HazelcastMapProducerTest extends HazelcastCamelTestSupport
implemen
         template.sendBody("direct:clear", "test");
         verify(map).clear();
     }
+    
+    @Test
+    public void testContainsKey() {
+        when(map.containsKey("testOk")).thenReturn(true);
+        when(map.containsKey("testKo")).thenReturn(false);
+        template.sendBodyAndHeader("direct:containsKey", null, HazelcastConstants.OBJECT_ID,
"testOk");
+        Boolean body = consumer.receiveBody("seda:out", 5000, Boolean.class);
+        verify(map).containsKey("testOk");
+        assertEquals(true, body);
+        template.sendBodyAndHeader("direct:containsKey", null, HazelcastConstants.OBJECT_ID,
"testKo");
+        body = consumer.receiveBody("seda:out", 5000, Boolean.class);
+        verify(map).containsKey("testKo");
+        assertEquals(false, body);
+    }
+    
+    @Test
+    public void testContainsValue() {
+        when(map.containsValue("testOk")).thenReturn(true);
+        when(map.containsValue("testKo")).thenReturn(false);
+        template.sendBody("direct:containsValue", "testOk");
+        Boolean body = consumer.receiveBody("seda:out", 5000, Boolean.class);
+        verify(map).containsValue("testOk");
+        assertEquals(true, body);
+        template.sendBody("direct:containsValue", "testKo");
+        body = consumer.receiveBody("seda:out", 5000, Boolean.class);
+        verify(map).containsValue("testKo");
+        assertEquals(false, body);
+    }
 
     @Override
     protected RouteBuilder createRouteBuilder() throws Exception {
@@ -250,7 +278,15 @@ public class HazelcastMapProducerTest extends HazelcastCamelTestSupport
implemen
                         .to("seda:out");
 
                 from("direct:evictAll").setHeader(HazelcastConstants.OPERATION, constant(HazelcastConstants.EVICT_ALL_OPERATION)).to(String.format("hazelcast:%sfoo",
HazelcastConstants.MAP_PREFIX))
-                        .to("seda:out");                
+                        .to("seda:out");
+                
+                from("direct:containsKey").setHeader(HazelcastConstants.OPERATION, constant(HazelcastConstants.CONTAINS_KEY_OPERATION))
+                        .to(String.format("hazelcast:%sfoo", HazelcastConstants.MAP_PREFIX))
+                        .to("seda:out");
+                
+                from("direct:containsValue").setHeader(HazelcastConstants.OPERATION, constant(HazelcastConstants.CONTAINS_VALUE_OPERATION))
+                        .to(String.format("hazelcast:%sfoo", HazelcastConstants.MAP_PREFIX))
+                        .to("seda:out");
                 
                 from("direct:putWithOperationNumber").toF("hazelcast:%sfoo?operation=%s",
HazelcastConstants.MAP_PREFIX, HazelcastConstants.PUT_OPERATION);
                 from("direct:putWithOperationName").toF("hazelcast:%sfoo?operation=put",
HazelcastConstants.MAP_PREFIX);

http://git-wip-us.apache.org/repos/asf/camel/blob/a7eb8b17/components/camel-hazelcast/src/test/resources/META-INF/spring/test-camel-context-map.xml
----------------------------------------------------------------------
diff --git a/components/camel-hazelcast/src/test/resources/META-INF/spring/test-camel-context-map.xml
b/components/camel-hazelcast/src/test/resources/META-INF/spring/test-camel-context-map.xml
index 359328a..a535238 100644
--- a/components/camel-hazelcast/src/test/resources/META-INF/spring/test-camel-context-map.xml
+++ b/components/camel-hazelcast/src/test/resources/META-INF/spring/test-camel-context-map.xml
@@ -106,6 +106,24 @@
 			</setHeader>
 			<to uri="hazelcast:map:foo" />
 			<to uri="seda:out" />
+		</route>
+		
+		<route>
+			<from uri="direct:containsKey" />
+			<setHeader headerName="CamelHazelcastOperationType">
+				<constant>containsKey</constant>
+			</setHeader>
+			<to uri="hazelcast:map:foo" />
+			<to uri="seda:out" />
+		</route>
+		
+		<route>
+			<from uri="direct:containsValue" />
+			<setHeader headerName="CamelHazelcastOperationType">
+				<constant>containsValue</constant>
+			</setHeader>
+			<to uri="hazelcast:map:foo" />
+			<to uri="seda:out" />
 		</route>		
 	</camelContext>
 


Mime
View raw message