camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jstrac...@apache.org
Subject svn commit: r552924 - in /activemq/camel/trunk/camel-core/src: main/java/org/apache/camel/builder/ main/java/org/apache/camel/component/mock/ main/java/org/apache/camel/processor/ test/ide-resources/ test/java/org/apache/camel/processor/
Date Tue, 03 Jul 2007 17:27:39 GMT
Author: jstrachan
Date: Tue Jul  3 10:27:38 2007
New Revision: 552924

URL: http://svn.apache.org/viewvc?view=rev&rev=552924
Log:
added support for the Delayer & a test case to check it actually works for CAMEL-63

Added:
    activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/DelayerTest.java
      - copied, changed from r552852, activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/AggregatorTest.java
Modified:
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/FromBuilder.java
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/mock/MockEndpoint.java
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/DelayerProcessor.java
    activemq/camel/trunk/camel-core/src/test/ide-resources/log4j.properties
    activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/AggregatorTest.java

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/FromBuilder.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/FromBuilder.java?view=diff&rev=552924&r1=552923&r2=552924
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/FromBuilder.java
(original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/FromBuilder.java
Tue Jul  3 10:27:38 2007
@@ -40,6 +40,8 @@
 import java.util.Collections;
 import java.util.List;
 
+import sun.net.smtp.SmtpClient;
+
 /**
  * @version $Revision$
  */
@@ -298,7 +300,21 @@
      */
     @Fluent
     public DelayerBuilder delayer(Expression<Exchange> processAtExpression) {
-        DelayerBuilder answer = new DelayerBuilder(this, processAtExpression, 0L);
+        return delayer(processAtExpression, 0L);
+    }
+
+    /**
+     * A builder for the <a href="http://activemq.apache.org/camel/delayer.html">Delayer</a>
pattern
+     * where an expression is used to calculate the time which the message will be dispatched
on
+     *
+     * @param processAtExpression an expression to calculate the time at which the messages
should be processed
+     * @param delay the delay in milliseconds which is added to the processAtExpression to
determine the time the
+     * message should be processed
+     * @return the builder
+     */
+    @Fluent
+    public DelayerBuilder delayer(Expression<Exchange> processAtExpression, long delay)
{
+        DelayerBuilder answer = new DelayerBuilder(this, processAtExpression, delay);
         setRouteBuilder(answer);
         return answer;
     }
@@ -312,9 +328,7 @@
      */
     @Fluent
     public DelayerBuilder delayer(long delay) {
-        DelayerBuilder answer = new DelayerBuilder(this, null, delay);
-        setRouteBuilder(answer);
-        return answer;
+        return delayer(null, delay);
     }
 
     /**
@@ -573,4 +587,5 @@
     protected void setRouteBuilder(FromBuilder routeBuilder) {
         this.routeBuilder = routeBuilder;
     }
+
 }

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/mock/MockEndpoint.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/mock/MockEndpoint.java?view=diff&rev=552924&r1=552923&r2=552924
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/mock/MockEndpoint.java
(original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/mock/MockEndpoint.java
Tue Jul  3 10:27:38 2007
@@ -52,7 +52,8 @@
     private List<Throwable> failures = new ArrayList<Throwable>();
     private List<Runnable> tests = new ArrayList<Runnable>();
     private CountDownLatch latch;
-    private long sleepForEmptyTest = 0L;
+    private long sleepForEmptyTest = 2000L;
+    private long defaulResultWaitMillis = 10000L;
     private int expectedMinimumCount = -1;
     private List expectedBodyValues;
     private List actualBodyValues = new ArrayList();
@@ -123,15 +124,18 @@
 
     /**
      * Validates that all the available expectations on this endpoint are satisfied; or throw
an exception
+     *
+     * @param timeoutForEmptyEndpoints the timeout in milliseconds that we should wait for
the test to be true
      */
     public void assertIsSatisfied(long timeoutForEmptyEndpoints) throws InterruptedException
{
         if (latch != null) {
             // now lets wait for the results
-            latch.await(10, TimeUnit.SECONDS);
+            latch.await(defaulResultWaitMillis, TimeUnit.MILLISECONDS);
         }
         else if (expectedCount == 0) {
             // lets wait a little bit just in case
             if (timeoutForEmptyEndpoints > 0) {
+                log.debug("Sleeping for: " + timeoutForEmptyEndpoints + " millis to check
there really are no messages received");
                 Thread.sleep(timeoutForEmptyEndpoints);
             }
         }

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/DelayerProcessor.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/DelayerProcessor.java?view=diff&rev=552924&r1=552923&r2=552924
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/DelayerProcessor.java
(original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/DelayerProcessor.java
Tue Jul  3 10:27:38 2007
@@ -105,6 +105,9 @@
             }
             else {
                 try {
+                    if (log.isDebugEnabled()) {
+                        log.debug("Sleeping for: " + delay + " millis");
+                    }
                     Thread.sleep(delay);
                 }
                 catch (InterruptedException e) {

Modified: activemq/camel/trunk/camel-core/src/test/ide-resources/log4j.properties
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/ide-resources/log4j.properties?view=diff&rev=552924&r1=552923&r2=552924
==============================================================================
--- activemq/camel/trunk/camel-core/src/test/ide-resources/log4j.properties (original)
+++ activemq/camel/trunk/camel-core/src/test/ide-resources/log4j.properties Tue Jul  3 10:27:38
2007
@@ -18,7 +18,7 @@
 #
 # The logging properties used for eclipse testing, We want to see debug output on the console.
 #
-log4j.rootLogger=DEBUG, out
+log4j.rootLogger=INFO, out
 
 log4j.logger.org.apache.camel=DEBUG
 log4j.logger.org.apache.camel.impl.converter=INFO

Modified: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/AggregatorTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/AggregatorTest.java?view=diff&rev=552924&r1=552923&r2=552924
==============================================================================
--- activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/AggregatorTest.java
(original)
+++ activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/AggregatorTest.java
Tue Jul  3 10:27:38 2007
@@ -27,7 +27,7 @@
 public class AggregatorTest extends ContextTestSupport {
     protected int messageCount = 100;
 
-    public void testSendMatchingMessage() throws Exception {
+    public void testSendingLotsOfMessagesGetAggregatedToTheLatestMessage() throws Exception
{
         MockEndpoint resultEndpoint = resolveMandatoryEndpoint("mock:result", MockEndpoint.class);
 
         resultEndpoint.expectedBodiesReceived("message:" + messageCount);

Copied: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/DelayerTest.java
(from r552852, activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/AggregatorTest.java)
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/DelayerTest.java?view=diff&rev=552924&p1=activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/AggregatorTest.java&r1=552852&p2=activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/DelayerTest.java&r2=552924
==============================================================================
--- activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/AggregatorTest.java
(original)
+++ activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/DelayerTest.java
Tue Jul  3 10:27:38 2007
@@ -24,20 +24,17 @@
 /**
  * @version $Revision: 1.1 $
  */
-public class AggregatorTest extends ContextTestSupport {
-    protected int messageCount = 100;
+public class DelayerTest extends ContextTestSupport {
 
-    public void testSendMatchingMessage() throws Exception {
+    public void testSendingMessageGetsDelayed() throws Exception {
         MockEndpoint resultEndpoint = resolveMandatoryEndpoint("mock:result", MockEndpoint.class);
+        resultEndpoint.expectedMessageCount(0);
 
-        resultEndpoint.expectedBodiesReceived("message:" + messageCount);
-
-        // lets send a large batch of messages
-        for (int i = 1; i <= messageCount; i++) {
-            String body = "message:" + i;
-            template.sendBody("direct:a", body, "cheese", 123);
-        }
+        template.sendBody("queue:a", "<hello>world!</hello>", "JMSTimestamp",
System.currentTimeMillis());
+        resultEndpoint.assertIsSatisfied(1000);
 
+        // now if we wait a bit longer we should receive the message!
+        resultEndpoint.expectedMessageCount(1);
         resultEndpoint.assertIsSatisfied();
     }
 
@@ -51,7 +48,7 @@
         return new RouteBuilder() {
             public void configure() {
                 // START SNIPPET: ex
-                from("direct:a").aggregator(header("cheese")).to("mock:result");
+                from("queue:a").delayer(header("JMSTimestamp"), 3000).to("mock:result");
                 // END SNIPPET: ex
             }
         };



Mime
View raw message