You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2012/02/24 15:31:35 UTC

svn commit: r1293268 - in /camel/trunk/camel-core/src: main/java/org/apache/camel/component/timer/ test/java/org/apache/camel/component/timer/

Author: davsclaus
Date: Fri Feb 24 14:31:34 2012
New Revision: 1293268

URL: http://svn.apache.org/viewvc?rev=1293268&view=rev
Log:
CAMEL-5038: Timer endpoint should support multiple consumers.

Added:
    camel/trunk/camel-core/src/test/java/org/apache/camel/component/timer/TimerMultipleConsumerStopRouteTest.java
    camel/trunk/camel-core/src/test/java/org/apache/camel/component/timer/TimerMultipleConsumerTest.java
Modified:
    camel/trunk/camel-core/src/main/java/org/apache/camel/component/timer/TimerEndpoint.java

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/timer/TimerEndpoint.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/timer/TimerEndpoint.java?rev=1293268&r1=1293267&r2=1293268&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/component/timer/TimerEndpoint.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/timer/TimerEndpoint.java Fri Feb 24 14:31:34 2012
@@ -21,6 +21,7 @@ import java.util.Timer;
 
 import org.apache.camel.Component;
 import org.apache.camel.Consumer;
+import org.apache.camel.MultipleConsumersSupport;
 import org.apache.camel.Processor;
 import org.apache.camel.Producer;
 import org.apache.camel.RuntimeCamelException;
@@ -34,7 +35,7 @@ import org.apache.camel.impl.DefaultEndp
  * @version 
  */
 @ManagedResource(description = "Managed TimerEndpoint")
-public class TimerEndpoint extends DefaultEndpoint {
+public class TimerEndpoint extends DefaultEndpoint implements MultipleConsumersSupport {
     private String timerName;
     private Date time;
     private long period = 1000;
@@ -72,6 +73,11 @@ public class TimerEndpoint extends Defau
         super.doStop();
     }
 
+    @ManagedAttribute
+    public boolean isMultipleConsumersSupported() {
+        return true;
+    }
+
     @ManagedAttribute(description = "Timer Name")
     public String getTimerName() {
         if (timerName == null) {

Added: camel/trunk/camel-core/src/test/java/org/apache/camel/component/timer/TimerMultipleConsumerStopRouteTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/component/timer/TimerMultipleConsumerStopRouteTest.java?rev=1293268&view=auto
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/component/timer/TimerMultipleConsumerStopRouteTest.java (added)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/component/timer/TimerMultipleConsumerStopRouteTest.java Fri Feb 24 14:31:34 2012
@@ -0,0 +1,55 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.timer;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.builder.RouteBuilder;
+
+/**
+ *
+ */
+public class TimerMultipleConsumerStopRouteTest extends ContextTestSupport {
+    
+    public void testMultipleConsumers() throws Exception {
+        getMockEndpoint("mock:foo").expectedMinimumMessageCount(1);
+        getMockEndpoint("mock:bar").expectedMinimumMessageCount(1);
+
+        assertMockEndpointsSatisfied();
+
+        context.stopRoute("bar");
+
+        resetMocks();
+
+        // stopping bar route, we should still keep getting messages to foo
+        getMockEndpoint("mock:foo").expectedMinimumMessageCount(2);
+        getMockEndpoint("mock:bar").expectedMessageCount(0);
+
+        assertMockEndpointsSatisfied();
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("timer:mytimer?period=100").routeId("foo").to("mock:foo");
+
+                from("timer:mytimer?period=100").routeId("bar").to("mock:bar");
+            }
+        };
+    }
+}

Added: camel/trunk/camel-core/src/test/java/org/apache/camel/component/timer/TimerMultipleConsumerTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/component/timer/TimerMultipleConsumerTest.java?rev=1293268&view=auto
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/component/timer/TimerMultipleConsumerTest.java (added)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/component/timer/TimerMultipleConsumerTest.java Fri Feb 24 14:31:34 2012
@@ -0,0 +1,45 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.timer;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.builder.RouteBuilder;
+
+/**
+ *
+ */
+public class TimerMultipleConsumerTest extends ContextTestSupport {
+    
+    public void testMultipleConsumers() throws Exception {
+        getMockEndpoint("mock:foo").expectedMinimumMessageCount(1);
+        getMockEndpoint("mock:bar").expectedMinimumMessageCount(1);
+
+        assertMockEndpointsSatisfied();
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("timer:mytimer").to("mock:foo");
+
+                from("timer:mytimer").to("mock:bar");
+            }
+        };
+    }
+}