diff --git a/pom.xml b/pom.xml index 72e5b32..ad6dc02 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ 4.0.0 org.apache.camel camel-data-provider - 1.0.2 + 1.0.3 jar diff --git a/src/main/java/org/apache/camel/component/dataprovider/DataProviderConstants.java b/src/main/java/org/apache/camel/component/dataprovider/DataProviderConstants.java index 1ee0e8a..f94f1a1 100644 --- a/src/main/java/org/apache/camel/component/dataprovider/DataProviderConstants.java +++ b/src/main/java/org/apache/camel/component/dataprovider/DataProviderConstants.java @@ -19,6 +19,22 @@ private DataProviderConstants() { */ public final static String LAST_BATCH = DataProviderConstants.class.getName() + ".LastBatch"; + /** + * Constant to specify the index (relative to {@link IDataProvider#getSize()}) of current {@link org.apache.camel.Exchange}. + *

+ * Value stored should be a int or associated object. + *

+ */ + public final static String INDEX = DataProviderConstants.class.getName() + ".Index"; + + /** + * Constant to specify total number of {@link org.apache.camel.Exchange} which will be generated. + *

+ * Value stored should be a int or associated object. + *

+ */ + public final static String SIZE = DataProviderConstants.class.getName() + ".Size"; + /** * Constant to specify whether current {@link org.apache.camel.Exchange} is the last one. *

diff --git a/src/main/java/org/apache/camel/component/dataprovider/DataProviderConsumer.java b/src/main/java/org/apache/camel/component/dataprovider/DataProviderConsumer.java index 0de4dfc..1f73e0f 100644 --- a/src/main/java/org/apache/camel/component/dataprovider/DataProviderConsumer.java +++ b/src/main/java/org/apache/camel/component/dataprovider/DataProviderConsumer.java @@ -74,6 +74,7 @@ protected int poll() throws Exception { DataProviderEndpoint endpoint = getDataProviderEndoint(); IDataProvider dataProvider = endpoint.getDataProvider(); final Range range = this.rangeReference.get(); + int index = range.lowerEndpoint(); if (range.isEmpty()) { if (!finished.getAndSet(true)) { LogUtils.info(LOG, () -> "Nothing to poll. Last range handled."); @@ -85,6 +86,8 @@ protected int poll() throws Exception { Queue exchanges = new LinkedList<>(); for (Object item : dataProvider.partition(range)) { Exchange exchange = endpoint.createExchange(); + exchange.setProperty(DataProviderConstants.INDEX, index++); + exchange.setProperty(DataProviderConstants.SIZE, size); exchange.setProperty(DataProviderConstants.LAST_BATCH, range.upperEndpoint() == size); exchange.getIn().setBody(item); exchanges.add(exchange); diff --git a/src/test/java/org/apache/camel/component/dataprovider/DataProviderComponentTest.java b/src/test/java/org/apache/camel/component/dataprovider/DataProviderComponentTest.java index 804d64d..b1c87f3 100644 --- a/src/test/java/org/apache/camel/component/dataprovider/DataProviderComponentTest.java +++ b/src/test/java/org/apache/camel/component/dataprovider/DataProviderComponentTest.java @@ -37,6 +37,8 @@ public void testDataProvider() throws Exception { assertEquals(lastExchange.getProperty(Exchange.BATCH_COMPLETE), true); assertEquals(lastExchange.getProperty(Exchange.BATCH_SIZE), 20); assertEquals(lastExchange.getProperty(Exchange.BATCH_INDEX), 19); + assertEquals(lastExchange.getProperty(DataProviderConstants.SIZE), 100); + assertEquals(lastExchange.getProperty(DataProviderConstants.INDEX), 99); // First Exchange firstExchange = exchanges.get(0); assertNotNull(firstExchange); @@ -45,6 +47,8 @@ public void testDataProvider() throws Exception { assertEquals(firstExchange.getProperty(Exchange.BATCH_COMPLETE), false); assertEquals(firstExchange.getProperty(Exchange.BATCH_SIZE), 20); assertEquals(firstExchange.getProperty(Exchange.BATCH_INDEX), 0); + assertEquals(firstExchange.getProperty(DataProviderConstants.INDEX), 0); + assertEquals(firstExchange.getProperty(DataProviderConstants.SIZE), 100); } @Test