camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r1360527 - in /camel/trunk/camel-core/src: main/java/org/apache/camel/impl/ScheduledBatchPollingConsumer.java test/java/org/apache/camel/processor/aggregator/AggregateCompletedByBatchConsumerSendEmptyMessageWhenIdleTest.java
Date Thu, 12 Jul 2012 05:21:55 GMT
Author: davsclaus
Date: Thu Jul 12 05:21:54 2012
New Revision: 1360527

URL: http://svn.apache.org/viewvc?rev=1360527&view=rev
Log:
CAMEL-5437: Fixed using sendEmptyMessageWhenIdle=true on a batch consumer such as File now
working with Aggregate EIP when using completionFromBatchConsumer

Added:
    camel/trunk/camel-core/src/test/java/org/apache/camel/processor/aggregator/AggregateCompletedByBatchConsumerSendEmptyMessageWhenIdleTest.java
Modified:
    camel/trunk/camel-core/src/main/java/org/apache/camel/impl/ScheduledBatchPollingConsumer.java

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/impl/ScheduledBatchPollingConsumer.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/ScheduledBatchPollingConsumer.java?rev=1360527&r1=1360526&r2=1360527&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/impl/ScheduledBatchPollingConsumer.java
(original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/impl/ScheduledBatchPollingConsumer.java
Thu Jul 12 05:21:54 2012
@@ -20,6 +20,7 @@ import java.util.concurrent.ScheduledExe
 
 import org.apache.camel.BatchConsumer;
 import org.apache.camel.Endpoint;
+import org.apache.camel.Exchange;
 import org.apache.camel.Processor;
 import org.apache.camel.ShutdownRunningTask;
 import org.apache.camel.spi.ShutdownAware;
@@ -112,4 +113,15 @@ public abstract class ScheduledBatchPoll
         // we are shutting down so only continue if we are configured to complete all tasks
         return ShutdownRunningTask.CompleteAllTasks == shutdownRunningTask;
     }
+
+    @Override
+    protected void processEmptyMessage() throws Exception {
+        Exchange exchange = getEndpoint().createExchange();
+        // enrich exchange, so we send an empty message with the batch details
+        exchange.setProperty(Exchange.BATCH_INDEX, 0);
+        exchange.setProperty(Exchange.BATCH_SIZE, 1);
+        exchange.setProperty(Exchange.BATCH_COMPLETE, true);
+        log.debug("Sending empty message as there were no messages from polling: {}", this.getEndpoint());
+        getProcessor().process(exchange);
+    }
 }

Added: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/aggregator/AggregateCompletedByBatchConsumerSendEmptyMessageWhenIdleTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/aggregator/AggregateCompletedByBatchConsumerSendEmptyMessageWhenIdleTest.java?rev=1360527&view=auto
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/processor/aggregator/AggregateCompletedByBatchConsumerSendEmptyMessageWhenIdleTest.java
(added)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/processor/aggregator/AggregateCompletedByBatchConsumerSendEmptyMessageWhenIdleTest.java
Thu Jul 12 05:21:54 2012
@@ -0,0 +1,52 @@
+/**
+ * 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.processor.aggregator;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.Exchange;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.processor.aggregate.UseLatestAggregationStrategy;
+
+/**
+ *
+ */
+public class AggregateCompletedByBatchConsumerSendEmptyMessageWhenIdleTest extends ContextTestSupport
{
+
+    public void testBatchConsumerSendEmptyMessageWhenIdle() throws Exception {
+        MockEndpoint mock = getMockEndpoint("mock:result");
+        mock.expectedMinimumMessageCount(1);
+        mock.allMessages().body().isNull();
+        mock.allMessages().header(Exchange.AGGREGATED_COMPLETED_BY).isEqualTo("consumer");
+        mock.allMessages().header(Exchange.AGGREGATED_SIZE).isEqualTo(1);
+
+        assertMockEndpointsSatisfied();
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("file:target/batch?sendEmptyMessageWhenIdle=true&delay=250")
+                    .aggregate(constant(true), new UseLatestAggregationStrategy()).completionFromBatchConsumer()
+                        .to("mock:result");
+
+            }
+        };
+    }
+}



Mime
View raw message