You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ac...@apache.org on 2015/06/08 17:47:48 UTC
camel git commit: CAMEL-8842 Camel-Hazelcast: Add addAll and
removeAll operation to list
Repository: camel
Updated Branches:
refs/heads/master f6ddd5e8e -> 0c2e5df10
CAMEL-8842 Camel-Hazelcast: Add addAll and removeAll operation to list
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/0c2e5df1
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/0c2e5df1
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/0c2e5df1
Branch: refs/heads/master
Commit: 0c2e5df10bfb1643a397492518d371960fb83bcc
Parents: f6ddd5e
Author: Andrea Cosentino <an...@gmail.com>
Authored: Mon Jun 8 10:17:51 2015 +0200
Committer: Andrea Cosentino <an...@gmail.com>
Committed: Mon Jun 8 17:46:55 2015 +0200
----------------------------------------------------------------------
.../component/hazelcast/HazelcastConstants.java | 4 ++-
.../hazelcast/list/HazelcastListProducer.java | 23 +++++++++++++++
.../hazelcast/HazelcastListProducerTest.java | 30 ++++++++++++++++++--
3 files changed, 54 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/0c2e5df1/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 46567b1..6d9218b 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
@@ -62,9 +62,11 @@ public final class HazelcastConstants {
public static final int GET_ALL_OPERATION = 6;
public static final int CLEAR_OPERATION = 7;
public static final int PUT_IF_ABSENT_OPERATION = 8;
+ public static final int ADD_ALL_OPERATION = 9;
+ public static final int REMOVE_ALL_OPERATION = 10;
// multimap
- public static final int REMOVEVALUE_OPERATION = 10;
+ public static final int REMOVEVALUE_OPERATION = 11;
// atomic numbers
public static final int INCREMENT_OPERATION = 20;
http://git-wip-us.apache.org/repos/asf/camel/blob/0c2e5df1/components/camel-hazelcast/src/main/java/org/apache/camel/component/hazelcast/list/HazelcastListProducer.java
----------------------------------------------------------------------
diff --git a/components/camel-hazelcast/src/main/java/org/apache/camel/component/hazelcast/list/HazelcastListProducer.java b/components/camel-hazelcast/src/main/java/org/apache/camel/component/hazelcast/list/HazelcastListProducer.java
index 5a93a66..b29bcc2 100644
--- a/components/camel-hazelcast/src/main/java/org/apache/camel/component/hazelcast/list/HazelcastListProducer.java
+++ b/components/camel-hazelcast/src/main/java/org/apache/camel/component/hazelcast/list/HazelcastListProducer.java
@@ -16,6 +16,7 @@
*/
package org.apache.camel.component.hazelcast.list;
+import java.util.Collection;
import java.util.Map;
import com.hazelcast.core.HazelcastInstance;
@@ -77,6 +78,14 @@ public class HazelcastListProducer extends HazelcastDefaultProducer {
case HazelcastConstants.CLEAR_OPERATION:
this.clear();
break;
+
+ case HazelcastConstants.ADD_ALL_OPERATION:
+ this.addAll(pos, exchange);
+ break;
+
+ case HazelcastConstants.REMOVE_ALL_OPERATION:
+ this.removeAll(exchange);
+ break;
default:
throw new IllegalArgumentException(String.format("The value '%s' is not allowed for parameter '%s' on the LIST cache.", operation, HazelcastConstants.OPERATION));
@@ -125,4 +134,18 @@ public class HazelcastListProducer extends HazelcastDefaultProducer {
private void clear() {
list.clear();
}
+
+ private void addAll(Integer pos, Exchange exchange) {
+ final Object body = exchange.getIn().getBody();
+ if (null == pos) {
+ list.addAll((Collection<? extends Object>) body);
+ } else {
+ list.addAll(pos, (Collection<? extends Object>) body);
+ }
+ }
+
+ private void removeAll(Exchange exchange) {
+ final Object body = exchange.getIn().getBody();
+ list.removeAll((Collection<?>) body);
+ }
}
http://git-wip-us.apache.org/repos/asf/camel/blob/0c2e5df1/components/camel-hazelcast/src/test/java/org/apache/camel/component/hazelcast/HazelcastListProducerTest.java
----------------------------------------------------------------------
diff --git a/components/camel-hazelcast/src/test/java/org/apache/camel/component/hazelcast/HazelcastListProducerTest.java b/components/camel-hazelcast/src/test/java/org/apache/camel/component/hazelcast/HazelcastListProducerTest.java
index 2b5c5a7..74906da 100644
--- a/components/camel-hazelcast/src/test/java/org/apache/camel/component/hazelcast/HazelcastListProducerTest.java
+++ b/components/camel-hazelcast/src/test/java/org/apache/camel/component/hazelcast/HazelcastListProducerTest.java
@@ -16,12 +16,14 @@
*/
package org.apache.camel.component.hazelcast;
-import com.hazelcast.core.HazelcastInstance;
+import java.util.ArrayList;
+import java.util.Collection;
+import com.hazelcast.core.HazelcastInstance;
import com.hazelcast.core.IList;
+
import org.apache.camel.CamelExecutionException;
import org.apache.camel.builder.RouteBuilder;
-
import org.junit.After;
import org.junit.Test;
import org.mockito.Mock;
@@ -108,6 +110,24 @@ public class HazelcastListProducerTest extends HazelcastCamelTestSupport {
template.sendBody("direct:clear", "");
verify(list).clear();
}
+
+ @Test
+ public void addAll() throws InterruptedException {
+ Collection t = new ArrayList();
+ t.add("test1");
+ t.add("test2");
+ template.sendBody("direct:addAll", t);
+ verify(list).addAll(t);
+ }
+
+ @Test
+ public void removeAll() throws InterruptedException {
+ Collection t = new ArrayList();
+ t.add("test1");
+ t.add("test2");
+ template.sendBody("direct:removeAll", t);
+ verify(list).removeAll(t);
+ }
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
@@ -129,6 +149,12 @@ public class HazelcastListProducerTest extends HazelcastCamelTestSupport {
from("direct:clear").setHeader(HazelcastConstants.OPERATION, constant(HazelcastConstants.CLEAR_OPERATION)).toF("hazelcast:%sbar", HazelcastConstants.LIST_PREFIX);
+ from("direct:addAll").setHeader(HazelcastConstants.OPERATION, constant(HazelcastConstants.ADD_ALL_OPERATION)).to(
+ String.format("hazelcast:%sbar", HazelcastConstants.LIST_PREFIX));
+
+ from("direct:removeAll").setHeader(HazelcastConstants.OPERATION, constant(HazelcastConstants.REMOVE_ALL_OPERATION)).to(
+ String.format("hazelcast:%sbar", HazelcastConstants.LIST_PREFIX));
+
from("direct:addWithOperationNumber").toF("hazelcast:%sbar?operation=%s", HazelcastConstants.LIST_PREFIX, HazelcastConstants.ADD_OPERATION);
from("direct:addWithOperationName").toF("hazelcast:%sbar?operation=add", HazelcastConstants.LIST_PREFIX);
}