Repository: camel
Updated Branches:
  refs/heads/master e20ae861b -> 359bf0e45


CAMEL-8868 Camel-Hazelcast: Add remainingCapacity operation to queue


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

Branch: refs/heads/master
Commit: a8f71ae32366087d6e8e5cdc559eaa9d04cec786
Parents: e20ae86
Author: Andrea Cosentino <anco...@gmail.com>
Authored: Sun Jun 14 13:30:13 2015 +0200
Committer: Andrea Cosentino <anco...@gmail.com>
Committed: Sun Jun 14 13:30:42 2015 +0200

----------------------------------------------------------------------
 .../camel/component/hazelcast/HazelcastConstants.java    |  3 ++-
 .../hazelcast/queue/HazelcastQueueProducer.java          |  8 ++++++++
 .../component/hazelcast/HazelcastQueueProducerTest.java  | 11 +++++++++++
 3 files changed, 21 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/a8f71ae3/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 fcc7256..11c775e 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
@@ -83,9 +83,10 @@ public final class HazelcastConstants {
     public static final int OFFER_OPERATION = 32;
     public static final int PEEK_OPERATION = 33;
     public static final int POLL_OPERATION = 34;
+    public static final int REMAINING_CAPACITY_OPERATION = 35;
 
     // topic
-    public static final int PUBLISH_OPERATION = 35;
+    public static final int PUBLISH_OPERATION = 36;
 
     /*
      * header values

http://git-wip-us.apache.org/repos/asf/camel/blob/a8f71ae3/components/camel-hazelcast/src/main/java/org/apache/camel/component/hazelcast/queue/HazelcastQueueProducer.java
----------------------------------------------------------------------
diff --git 
a/components/camel-hazelcast/src/main/java/org/apache/camel/component/hazelcast/queue/HazelcastQueueProducer.java
 
b/components/camel-hazelcast/src/main/java/org/apache/camel/component/hazelcast/queue/HazelcastQueueProducer.java
index 46c7488..4575439 100644
--- 
a/components/camel-hazelcast/src/main/java/org/apache/camel/component/hazelcast/queue/HazelcastQueueProducer.java
+++ 
b/components/camel-hazelcast/src/main/java/org/apache/camel/component/hazelcast/queue/HazelcastQueueProducer.java
@@ -69,6 +69,10 @@ public class HazelcastQueueProducer extends 
HazelcastDefaultProducer {
             this.remove(exchange);
             break;
 
+        case HazelcastConstants.REMAINING_CAPACITY_OPERATION:
+            this.remainingCapacity(exchange);
+            break;
+            
         default:
             throw new IllegalArgumentException(String.format("The value '%s' 
is not allowed for parameter '%s' on the QUEUE cache.", operation, 
HazelcastConstants.OPERATION));
         }
@@ -109,4 +113,8 @@ public class HazelcastQueueProducer extends 
HazelcastDefaultProducer {
             this.queue.remove();
         }
     }
+    
+    private void remainingCapacity(Exchange exchange) {
+       exchange.getOut().setBody(this.queue.remainingCapacity());
+    }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/camel/blob/a8f71ae3/components/camel-hazelcast/src/test/java/org/apache/camel/component/hazelcast/HazelcastQueueProducerTest.java
----------------------------------------------------------------------
diff --git 
a/components/camel-hazelcast/src/test/java/org/apache/camel/component/hazelcast/HazelcastQueueProducerTest.java
 
b/components/camel-hazelcast/src/test/java/org/apache/camel/component/hazelcast/HazelcastQueueProducerTest.java
index 76e47ef..3807e98 100644
--- 
a/components/camel-hazelcast/src/test/java/org/apache/camel/component/hazelcast/HazelcastQueueProducerTest.java
+++ 
b/components/camel-hazelcast/src/test/java/org/apache/camel/component/hazelcast/HazelcastQueueProducerTest.java
@@ -114,6 +114,14 @@ public class HazelcastQueueProducerTest extends 
HazelcastCamelTestSupport {
         verify(queue).peek();
         assertEquals("foo", answer);
     }
+    
+    @Test
+    public void remainingCapacity() throws InterruptedException {
+        when(queue.remainingCapacity()).thenReturn(10);
+        int answer = template.requestBody("direct:remainingCapacity", null, 
Integer.class);
+        verify(queue).remainingCapacity();
+        assertEquals(10, answer);
+    }
 
     @Override
     protected RouteBuilder createRouteBuilder() throws Exception {
@@ -137,6 +145,9 @@ public class HazelcastQueueProducerTest extends 
HazelcastCamelTestSupport {
                 
from("direct:removevalue").setHeader(HazelcastConstants.OPERATION, 
constant(HazelcastConstants.REMOVEVALUE_OPERATION)).to(
                         String.format("hazelcast:%sbar", 
HazelcastConstants.QUEUE_PREFIX));
 
+                
from("direct:remainingCapacity").setHeader(HazelcastConstants.OPERATION, 
constant(HazelcastConstants.REMAINING_CAPACITY_OPERATION)).to(
+                        String.format("hazelcast:%sbar", 
HazelcastConstants.QUEUE_PREFIX));
+                
                 
from("direct:putWithOperationNumber").toF(String.format("hazelcast:%sbar?operation=%s",
 HazelcastConstants.QUEUE_PREFIX, HazelcastConstants.PUT_OPERATION));
 
                 
from("direct:putWithOperationName").toF(String.format("hazelcast:%sbar?operation=put",
 HazelcastConstants.QUEUE_PREFIX));

Reply via email to