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-8729 Add query all capabilities in hazelcast map producers
Date Fri, 01 May 2015 19:52:15 GMT
Repository: camel
Updated Branches:
  refs/heads/master c8c60933e -> 778e4b0e1


CAMEL-8729 Add query all capabilities in hazelcast map producers


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

Branch: refs/heads/master
Commit: 778e4b0e127d59739eabc16912e73f54bf60f211
Parents: c8c6093
Author: Andrea Cosentino <ancosen@gmail.com>
Authored: Fri May 1 21:50:40 2015 +0200
Committer: Andrea Cosentino <ancosen@gmail.com>
Committed: Fri May 1 21:50:40 2015 +0200

----------------------------------------------------------------------
 .../hazelcast/HazelcastComponentHelper.java     |  1 +
 .../component/hazelcast/HazelcastConstants.java |  1 +
 .../hazelcast/map/HazelcastMapProducer.java     | 21 +++++++-
 .../hazelcast/HazelcastMapProducerTest.java     | 51 ++++++++++++++++++--
 4 files changed, 70 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/778e4b0e/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 f6057c5..9c8acc4 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
@@ -92,6 +92,7 @@ public final class HazelcastComponentHelper {
         addMapping("get", HazelcastConstants.GET_OPERATION);
         addMapping("update", HazelcastConstants.UPDATE_OPERATION);
         addMapping("query", HazelcastConstants.QUERY_OPERATION);
+        addMapping("getAll", HazelcastConstants.GET_ALL_OPERATION);
 
         // multimap
         addMapping("removevalue", HazelcastConstants.REMOVEVALUE_OPERATION);

http://git-wip-us.apache.org/repos/asf/camel/blob/778e4b0e/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 a16013e..3caa167 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
@@ -55,6 +55,7 @@ public final class HazelcastConstants {
     public static final int GET_OPERATION = 3;
     public static final int UPDATE_OPERATION = 4;
     public static final int QUERY_OPERATION = 5;
+    public static final int GET_ALL_OPERATION = 6;
 
     // multimap
     public static final int REMOVEVALUE_OPERATION = 10;

http://git-wip-us.apache.org/repos/asf/camel/blob/778e4b0e/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 7d4196d..0122097 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
@@ -18,6 +18,7 @@ package org.apache.camel.component.hazelcast.map;
 
 import java.util.Collection;
 import java.util.Map;
+import java.util.Set;
 
 import com.hazelcast.core.HazelcastInstance;
 import com.hazelcast.core.IMap;
@@ -27,6 +28,7 @@ import org.apache.camel.Exchange;
 import org.apache.camel.component.hazelcast.HazelcastComponentHelper;
 import org.apache.camel.component.hazelcast.HazelcastConstants;
 import org.apache.camel.component.hazelcast.HazelcastDefaultProducer;
+import org.apache.camel.util.ObjectHelper;
 
 public class HazelcastMapProducer extends HazelcastDefaultProducer {
 
@@ -63,6 +65,10 @@ public class HazelcastMapProducer extends HazelcastDefaultProducer {
         case HazelcastConstants.GET_OPERATION:
             this.get(oid, exchange);
             break;
+            
+        case HazelcastConstants.GET_ALL_OPERATION:
+            this.getAll(oid, exchange);
+            break;
 
         case HazelcastConstants.DELETE_OPERATION:
             this.delete(oid);
@@ -89,7 +95,12 @@ public class HazelcastMapProducer extends HazelcastDefaultProducer {
      * query map with a sql like syntax (see http://www.hazelcast.com/)
      */
     private void query(String query, Exchange exchange) {
-        Collection<Object> result = this.cache.values(new SqlPredicate(query));
+        Collection<Object> result;
+        if (ObjectHelper.isNotEmpty(query) && query != null) {
+            result = this.cache.values(new SqlPredicate(query));
+        } else {
+            result = this.cache.values();
+        }
         exchange.getOut().setBody(result);
     }
 
@@ -116,6 +127,14 @@ public class HazelcastMapProducer extends HazelcastDefaultProducer {
     private void get(Object oid, Exchange exchange) {
         exchange.getOut().setBody(this.cache.get(oid));
     }
+    
+    
+    /**
+     * get All objects and give it back
+     */
+    private void getAll(Object oid, Exchange exchange) {
+        exchange.getOut().setBody(this.cache.getAll((Set<Object>) oid));
+    }
 
     /**
      * put a new object into the cache

http://git-wip-us.apache.org/repos/asf/camel/blob/778e4b0e/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 87ae989..02889af 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
@@ -19,11 +19,16 @@ package org.apache.camel.component.hazelcast;
 import java.io.Serializable;
 import java.util.Arrays;
 import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
 
 import com.hazelcast.core.HazelcastInstance;
 import com.hazelcast.core.IMap;
-
 import com.hazelcast.query.SqlPredicate;
+
 import org.apache.camel.CamelExecutionException;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.hazelcast.testutil.Dummy;
@@ -93,6 +98,33 @@ public class HazelcastMapProducerTest extends HazelcastCamelTestSupport
implemen
         verify(map).get("4711");
         assertEquals("my-foo", body);
     }
+    
+    @Test
+    public void testGetAllEmptySet() {
+        Set<Object> l = new HashSet<Object>();
+        Map t = new HashMap();
+        t.put("key1", "value1");
+        t.put("key2", "value2");
+        t.put("key3", "value3");
+        when(map.getAll(anySet())).thenReturn(t);
+        template.sendBodyAndHeader("direct:getAll", null, HazelcastConstants.OBJECT_ID, l);
+        String body = consumer.receiveBody("seda:out", 5000, String.class);
+        verify(map).getAll(l);
+        assertEquals("{key3=value3, key2=value2, key1=value1}", body);
+    }
+    
+    @Test
+    public void testGetAllOnlyOneKey() {
+        Set<Object> l = new HashSet<Object>();
+        l.add("key1");
+        Map t = new HashMap();
+        t.put("key1", "value1");
+        when(map.getAll(l)).thenReturn(t);
+        template.sendBodyAndHeader("direct:getAll", null, HazelcastConstants.OBJECT_ID, l);
+        String body = consumer.receiveBody("seda:out", 5000, String.class);
+        verify(map).getAll(l);
+        assertEquals("{key1=value1}", body);
+    }
 
     @Test
     public void testDelete() {
@@ -113,6 +145,18 @@ public class HazelcastMapProducerTest extends HazelcastCamelTestSupport
implemen
         assertNotNull(b1);
         assertEquals(2, b1.size());
     }
+    
+    @Test
+    public void testEmptyQuery() {
+        when(map.values()).thenReturn(Arrays.<Object>asList(new Dummy("beta", 2000),
new Dummy("gamma", 3000), new Dummy("delta", 4000)));
+        template.sendBody("direct:query", null);
+        verify(map).values();
+
+        Collection<?> b1 = consumer.receiveBody("seda:out", 5000, Collection.class);
+
+        assertNotNull(b1);
+        assertEquals(3, b1.size());
+    }
 
     @Override
     protected RouteBuilder createRouteBuilder() throws Exception {
@@ -129,6 +173,9 @@ public class HazelcastMapProducerTest extends HazelcastCamelTestSupport
implemen
                 from("direct:get").setHeader(HazelcastConstants.OPERATION, constant(HazelcastConstants.GET_OPERATION)).to(String.format("hazelcast:%sfoo",
HazelcastConstants.MAP_PREFIX))
                         .to("seda:out");
 
+                from("direct:getAll").setHeader(HazelcastConstants.OPERATION, constant(HazelcastConstants.GET_ALL_OPERATION)).to(String.format("hazelcast:%sfoo",
HazelcastConstants.MAP_PREFIX))
+                        .to("seda:out");
+                
                 from("direct:delete").setHeader(HazelcastConstants.OPERATION, constant(HazelcastConstants.DELETE_OPERATION)).to(String.format("hazelcast:%sfoo",
HazelcastConstants.MAP_PREFIX));
 
                 from("direct:query").setHeader(HazelcastConstants.OPERATION, constant(HazelcastConstants.QUERY_OPERATION)).to(String.format("hazelcast:%sfoo",
HazelcastConstants.MAP_PREFIX))
@@ -136,8 +183,6 @@ public class HazelcastMapProducerTest extends HazelcastCamelTestSupport
implemen
 
                 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);
-
-
             }
         };
     }


Mime
View raw message