CAMEL-9699: Only set the expectedMessageCount when the component is used as a producer
Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/acf06f78 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/acf06f78 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/acf06f78 Branch: refs/heads/master Commit: acf06f78e61a4ae39d4ad4d068ba5a7f8b3c43d5 Parents: dea7ef0 Author: Quinn Stevenson <qu...@pronoia-solutions.com> Authored: Thu Mar 10 13:28:20 2016 -0700 Committer: Claus Ibsen <davscl...@apache.org> Committed: Mon Mar 14 19:23:15 2016 +0100 ---------------------------------------------------------------------- .../component/dataset/DataSetEndpoint.java | 19 ++++- .../component/dataset/DataSetConsumeTest.java | 45 ----------- .../component/dataset/DataSetConsumerTest.java | 83 ++++++++++++++++++++ .../component/dataset/DataSetProducerTest.java | 51 ++++++++++++ 4 files changed, 150 insertions(+), 48 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/acf06f78/camel-core/src/main/java/org/apache/camel/component/dataset/DataSetEndpoint.java ---------------------------------------------------------------------- diff --git a/camel-core/src/main/java/org/apache/camel/component/dataset/DataSetEndpoint.java b/camel-core/src/main/java/org/apache/camel/component/dataset/DataSetEndpoint.java index 65ec1a5..57559e8 100644 --- a/camel-core/src/main/java/org/apache/camel/component/dataset/DataSetEndpoint.java +++ b/camel-core/src/main/java/org/apache/camel/component/dataset/DataSetEndpoint.java @@ -23,6 +23,7 @@ import org.apache.camel.Consumer; import org.apache.camel.Exchange; import org.apache.camel.Message; import org.apache.camel.Processor; +import org.apache.camel.Producer; import org.apache.camel.Service; import org.apache.camel.component.mock.MockEndpoint; import org.apache.camel.processor.ThroughputLogger; @@ -85,6 +86,19 @@ public class DataSetEndpoint extends MockEndpoint implements Service { public Consumer createConsumer(Processor processor) throws Exception { Consumer answer = new DataSetConsumer(this, processor); configureConsumer(answer); + + // expectedMessageCount((int) size); + + return answer; + } + + @Override + public Producer createProducer() throws Exception { + Producer answer = super.createProducer(); + + long size = getDataSet().getSize(); + expectedMessageCount((int) size); + return answer; } @@ -234,12 +248,11 @@ public class DataSetEndpoint extends MockEndpoint implements Service { protected void doStart() throws Exception { super.doStart(); - long size = getDataSet().getSize(); - expectedMessageCount((int) size); if (reporter == null) { reporter = createReporter(); } - log.info(this + " expecting " + size + " messages"); + + log.info(this + " expecting " + getExpectedCount() + " messages"); } } http://git-wip-us.apache.org/repos/asf/camel/blob/acf06f78/camel-core/src/test/java/org/apache/camel/component/dataset/DataSetConsumeTest.java ---------------------------------------------------------------------- diff --git a/camel-core/src/test/java/org/apache/camel/component/dataset/DataSetConsumeTest.java b/camel-core/src/test/java/org/apache/camel/component/dataset/DataSetConsumeTest.java deleted file mode 100644 index 84ce252..0000000 --- a/camel-core/src/test/java/org/apache/camel/component/dataset/DataSetConsumeTest.java +++ /dev/null @@ -1,45 +0,0 @@ -/** - * 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.dataset; - -import javax.naming.Context; - -import org.apache.camel.ContextTestSupport; -import org.apache.camel.Exchange; - -/** - * @version - */ -public class DataSetConsumeTest extends ContextTestSupport { - protected SimpleDataSet dataSet = new SimpleDataSet(20); - - public void testSendingMessagesExplicitlyToDataSetEndpoint() throws Exception { - long size = dataSet.getSize(); - for (long i = 0; i < size; i++) { - template.sendBodyAndHeader("dataset:foo", "<hello>world!</hello>", Exchange.DATASET_INDEX, i); - } - - assertMockEndpointsSatisfied(); - } - - @Override - protected Context createJndiContext() throws Exception { - Context context = super.createJndiContext(); - context.bind("foo", dataSet); - return context; - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/camel/blob/acf06f78/camel-core/src/test/java/org/apache/camel/component/dataset/DataSetConsumerTest.java ---------------------------------------------------------------------- diff --git a/camel-core/src/test/java/org/apache/camel/component/dataset/DataSetConsumerTest.java b/camel-core/src/test/java/org/apache/camel/component/dataset/DataSetConsumerTest.java new file mode 100644 index 0000000..93c4014 --- /dev/null +++ b/camel-core/src/test/java/org/apache/camel/component/dataset/DataSetConsumerTest.java @@ -0,0 +1,83 @@ +/** + * 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.dataset; + +import javax.naming.Context; + +import org.apache.camel.ContextTestSupport; +import org.apache.camel.Exchange; +import org.apache.camel.builder.RouteBuilder; + +/** + * @version + */ +public class DataSetConsumerTest extends ContextTestSupport { + static final String dataSetName = "foo"; + static final String dataSetUri = "dataset://" + dataSetName; + static final String resultUri = "mock://result"; + + protected SimpleDataSet dataSet = new SimpleDataSet(20); + + @Override + protected Context createJndiContext() throws Exception { + Context context = super.createJndiContext(); + context.bind(dataSetName, dataSet); + return context; + } + + /** + * Ensure the expected message count for a consumer-only endpoint defaults to zero + */ + public void testConsumerOnlyEndpoint() throws Exception { + + context.addRoutes(new RouteBuilder() { + @Override + public void configure() throws Exception { + from(dataSetUri) + .to(resultUri); + } + }); + context.start(); + + assertEquals( "expectedMessageCount should be -1 for a consumer-only endpoint", -1, getMockEndpoint(dataSetUri).getExpectedCount()); + + getMockEndpoint(resultUri).expectedMessageCount((int)dataSet.getSize()); + + assertMockEndpointsSatisfied(); + } + + /** + * Ensure the expected message count for a consumer-producer endpoint defaults to the size of the dataset + */ + public void testConsumerWithProducer() throws Exception { + context.addRoutes(new RouteBuilder() { + @Override + public void configure() throws Exception { + from(dataSetUri) + .to(dataSetUri) + .to(resultUri); + } + }); + context.start(); + + assertEquals( "expectedMessageCount should be the same as the DataSet size for a consumer-producer endpoint", dataSet.getSize(), getMockEndpoint(dataSetUri).getExpectedCount()); + + getMockEndpoint(resultUri).expectedMessageCount((int)dataSet.getSize()); + + assertMockEndpointsSatisfied(); + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/camel/blob/acf06f78/camel-core/src/test/java/org/apache/camel/component/dataset/DataSetProducerTest.java ---------------------------------------------------------------------- diff --git a/camel-core/src/test/java/org/apache/camel/component/dataset/DataSetProducerTest.java b/camel-core/src/test/java/org/apache/camel/component/dataset/DataSetProducerTest.java new file mode 100644 index 0000000..5ae3a6f --- /dev/null +++ b/camel-core/src/test/java/org/apache/camel/component/dataset/DataSetProducerTest.java @@ -0,0 +1,51 @@ +/** + * 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.dataset; + +import javax.naming.Context; + +import org.apache.camel.ContextTestSupport; +import org.apache.camel.Exchange; +import org.apache.camel.builder.RouteBuilder; + +/** + * @version + */ +public class DataSetProducerTest extends ContextTestSupport { + static final String dataSetName = "foo"; + static final String dataSetUri = "dataset://" + dataSetName; + static final String resultUri = "mock://result"; + + protected SimpleDataSet dataSet = new SimpleDataSet(20); + + @Override + protected Context createJndiContext() throws Exception { + Context context = super.createJndiContext(); + context.bind(dataSetName, dataSet); + return context; + } + + public void testSendingMessagesExplicitlyToDataSetEndpoint() throws Exception { + long size = dataSet.getSize(); + for (long i = 0; i < size; i++) { + template.sendBodyAndHeader(dataSetUri, "<hello>world!</hello>", Exchange.DATASET_INDEX, i); + } + + assertMockEndpointsSatisfied(); + } + +} \ No newline at end of file