camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ningji...@apache.org
Subject [2/2] git commit: Fix CAMEL-7850 : Allow to set the id of the indexed document via a header Use indexId if it is provided by the header Add unit test that check that returned indexId is equals of the provided one.
Date Tue, 23 Sep 2014 02:42:19 GMT
Fix CAMEL-7850 : Allow to set the id of the indexed document via a header
Use indexId if it is provided by the header
Add unit test that check that returned indexId is equals of the provided one.


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

Branch: refs/heads/master
Commit: 8edd70ad84ebaea12516474b7d6d036df66e79b5
Parents: d3299ce
Author: sebbrousse <seb.brousse@gmail.com>
Authored: Mon Sep 22 20:14:15 2014 +0200
Committer: Willem Jiang <willem.jiang@gmail.com>
Committed: Tue Sep 23 10:38:11 2014 +0800

----------------------------------------------------------------------
 .../elasticsearch/ElasticsearchProducer.java    | 12 +++++----
 .../ElasticsearchComponentTest.java             | 26 ++++++++++++++++----
 2 files changed, 28 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/8edd70ad/components/camel-elasticsearch/src/main/java/org/apache/camel/component/elasticsearch/ElasticsearchProducer.java
----------------------------------------------------------------------
diff --git a/components/camel-elasticsearch/src/main/java/org/apache/camel/component/elasticsearch/ElasticsearchProducer.java
b/components/camel-elasticsearch/src/main/java/org/apache/camel/component/elasticsearch/ElasticsearchProducer.java
index 60b9c47..9745eba 100644
--- a/components/camel-elasticsearch/src/main/java/org/apache/camel/component/elasticsearch/ElasticsearchProducer.java
+++ b/components/camel-elasticsearch/src/main/java/org/apache/camel/component/elasticsearch/ElasticsearchProducer.java
@@ -16,10 +16,6 @@
  */
 package org.apache.camel.component.elasticsearch;
 
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-
 import org.apache.camel.Exchange;
 import org.apache.camel.ExpectedBodyTypeException;
 import org.apache.camel.Message;
@@ -35,6 +31,10 @@ import org.elasticsearch.action.index.IndexResponse;
 import org.elasticsearch.client.Client;
 import org.elasticsearch.common.xcontent.XContentBuilder;
 
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+
 /**
  * Represents an Elasticsearch producer.
  */
@@ -119,7 +119,9 @@ public class ElasticsearchProducer extends DefaultProducer {
             indexType = getEndpoint().getConfig().getIndexType();
         }
 
-        IndexRequestBuilder prepareIndex = client.prepareIndex(indexName, indexType);
+        String indexId = exchange.getIn().getHeader(ElasticsearchConfiguration.PARAM_INDEX_ID,
String.class);
+
+        IndexRequestBuilder prepareIndex = client.prepareIndex(indexName, indexType, indexId);
 
         Object document = extractDocumentFromMessage(exchange.getIn());
 

http://git-wip-us.apache.org/repos/asf/camel/blob/8edd70ad/components/camel-elasticsearch/src/test/java/org/apache/camel/component/elasticsearch/ElasticsearchComponentTest.java
----------------------------------------------------------------------
diff --git a/components/camel-elasticsearch/src/test/java/org/apache/camel/component/elasticsearch/ElasticsearchComponentTest.java
b/components/camel-elasticsearch/src/test/java/org/apache/camel/component/elasticsearch/ElasticsearchComponentTest.java
index 7e96c93..565772f 100644
--- a/components/camel-elasticsearch/src/test/java/org/apache/camel/component/elasticsearch/ElasticsearchComponentTest.java
+++ b/components/camel-elasticsearch/src/test/java/org/apache/camel/component/elasticsearch/ElasticsearchComponentTest.java
@@ -16,11 +16,6 @@
  */
 package org.apache.camel.component.elasticsearch;
 
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.test.junit4.CamelTestSupport;
 import org.elasticsearch.action.delete.DeleteResponse;
@@ -29,6 +24,11 @@ import org.junit.Before;
 import org.junit.Ignore;
 import org.junit.Test;
 
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
 public class ElasticsearchComponentTest extends CamelTestSupport {
 
     @Override
@@ -122,6 +122,22 @@ public class ElasticsearchComponentTest extends CamelTestSupport {
     }
 
     @Test
+    public void testIndexWithIDInHeader() throws Exception {
+        Map<String, String> map = new HashMap<String, String>();
+        map.put("content", "test");
+
+        Map<String, Object> headers = new HashMap<String, Object>();
+        headers.put(ElasticsearchConfiguration.PARAM_OPERATION, ElasticsearchConfiguration.OPERATION_INDEX);
+        headers.put(ElasticsearchConfiguration.PARAM_INDEX_NAME, "twitter");
+        headers.put(ElasticsearchConfiguration.PARAM_INDEX_TYPE, "tweet");
+        headers.put(ElasticsearchConfiguration.PARAM_INDEX_ID, "123");
+
+        String indexId = template.requestBodyAndHeaders("direct:start", map, headers, String.class);
+        assertNotNull("indexId should be set", indexId);
+        assertEquals("indexId should be equals to the provided id", "123", indexId);
+    }
+
+    @Test
     @Ignore("need to setup the cluster IP for this test")
     public void indexWithIp()  throws Exception {
         Map<String, String> map = new HashMap<String, String>();


Mime
View raw message