Repository: camel
Updated Branches:
  refs/heads/master 4b218f18d -> d4671fda1


[CAMEL-8011] MyBatis consumer ignored maxMessagesPerPoll option.


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

Branch: refs/heads/master
Commit: d4671fda12136fbf75e9031ab1c110ce4f51619a
Parents: 4b218f1
Author: Henryk Konsek <hekon...@gmail.com>
Authored: Fri Nov 7 14:31:51 2014 +0100
Committer: Henryk Konsek <hekon...@gmail.com>
Committed: Fri Nov 7 14:31:51 2014 +0100

----------------------------------------------------------------------
 components/camel-mybatis/pom.xml                |  5 ++
 .../component/mybatis/MyBatisConsumer.java      | 10 ++--
 .../mybatis/MyBatisConsumerIsolatedTest.java    | 53 ++++++++++++++++++++
 3 files changed, 62 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/d4671fda/components/camel-mybatis/pom.xml
----------------------------------------------------------------------
diff --git a/components/camel-mybatis/pom.xml b/components/camel-mybatis/pom.xml
index f1aebdf..cf5e5e3 100644
--- a/components/camel-mybatis/pom.xml
+++ b/components/camel-mybatis/pom.xml
@@ -69,5 +69,10 @@
       <artifactId>junit</artifactId>
       <scope>test</scope>
     </dependency>
+    <dependency>
+      <groupId>org.mockito</groupId>
+      <artifactId>mockito-core</artifactId>
+      <scope>test</scope>
+    </dependency>
   </dependencies>
 </project>

http://git-wip-us.apache.org/repos/asf/camel/blob/d4671fda/components/camel-mybatis/src/main/java/org/apache/camel/component/mybatis/MyBatisConsumer.java
----------------------------------------------------------------------
diff --git 
a/components/camel-mybatis/src/main/java/org/apache/camel/component/mybatis/MyBatisConsumer.java
 
b/components/camel-mybatis/src/main/java/org/apache/camel/component/mybatis/MyBatisConsumer.java
index 5708de3..0b0cd68 100644
--- 
a/components/camel-mybatis/src/main/java/org/apache/camel/component/mybatis/MyBatisConsumer.java
+++ 
b/components/camel-mybatis/src/main/java/org/apache/camel/component/mybatis/MyBatisConsumer.java
@@ -40,11 +40,11 @@ public class MyBatisConsumer extends 
ScheduledBatchPollingConsumer {
 
     private static final Logger LOG = 
LoggerFactory.getLogger(MyBatisConsumer.class);
 
-    private static final class DataHolder {
-        private Exchange exchange;
-        private Object data;
+    static final class DataHolder {
+        Exchange exchange;
+        Object data;
 
-        private DataHolder() {
+        DataHolder() {
         }
     }
 
@@ -66,8 +66,6 @@ public class MyBatisConsumer extends 
ScheduledBatchPollingConsumer {
      */
     private boolean routeEmptyResultSet;
 
-    private int maxMessagesPerPoll;
-
     public MyBatisConsumer(MyBatisEndpoint endpoint, Processor processor) {
         super(endpoint, processor);
     }

http://git-wip-us.apache.org/repos/asf/camel/blob/d4671fda/components/camel-mybatis/src/test/java/org/apache/camel/component/mybatis/MyBatisConsumerIsolatedTest.java
----------------------------------------------------------------------
diff --git 
a/components/camel-mybatis/src/test/java/org/apache/camel/component/mybatis/MyBatisConsumerIsolatedTest.java
 
b/components/camel-mybatis/src/test/java/org/apache/camel/component/mybatis/MyBatisConsumerIsolatedTest.java
new file mode 100644
index 0000000..5daf531
--- /dev/null
+++ 
b/components/camel-mybatis/src/test/java/org/apache/camel/component/mybatis/MyBatisConsumerIsolatedTest.java
@@ -0,0 +1,53 @@
+/**
+ * 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.mybatis;
+
+import java.util.ArrayDeque;
+import java.util.Queue;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.Processor;
+import org.apache.camel.impl.DefaultExchange;
+import org.junit.Assert;
+import org.junit.Test;
+
+import static org.mockito.Mockito.mock;
+
+public class MyBatisConsumerIsolatedTest extends Assert {
+
+    @Test
+    public void shouldRespectBatchSize() throws Exception {
+        // Given
+        int batchSize = 5;
+        MyBatisConsumer consumer = new 
MyBatisConsumer(mock(MyBatisEndpoint.class), mock(Processor.class));
+        consumer.setMaxMessagesPerPoll(batchSize);
+
+        Queue<Object> emptyMessageQueue = new ArrayDeque<Object>();
+        for (int i = 0; i < 10; i++) {
+            MyBatisConsumer.DataHolder dataHolder = new 
MyBatisConsumer.DataHolder();
+            dataHolder.exchange = new 
DefaultExchange(mock(CamelContext.class));
+            emptyMessageQueue.add(dataHolder);
+        }
+
+        // When
+        int processedMessages = consumer.processBatch(emptyMessageQueue);
+
+        // Then
+        assertEquals(batchSize, processedMessages);
+    }
+
+}

Reply via email to