Author: boday
Date: Thu Mar  8 21:10:28 2012
New Revision: 1298581

URL: http://svn.apache.org/viewvc?rev=1298581&view=rev
Log:
CAMEL-4881/CAMEL-5071 merged from trunk (2.10.0 enhancement) to 2.9.X branch 
(for future 2.9.2 release)

Modified:
    camel/branches/camel-2.9.x/components/camel-solr/   (props changed)
    camel/branches/camel-2.9.x/components/camel-solr/pom.xml
    
camel/branches/camel-2.9.x/components/camel-solr/src/main/java/org/apache/camel/component/solr/SolrComponent.java
    
camel/branches/camel-2.9.x/components/camel-solr/src/main/java/org/apache/camel/component/solr/SolrConstants.java
    
camel/branches/camel-2.9.x/components/camel-solr/src/main/java/org/apache/camel/component/solr/SolrEndpoint.java
    
camel/branches/camel-2.9.x/components/camel-solr/src/main/java/org/apache/camel/component/solr/SolrProducer.java
    
camel/branches/camel-2.9.x/components/camel-solr/src/test/java/org/apache/camel/component/solr/InitSolrEndpointTest.java
    
camel/branches/camel-2.9.x/components/camel-solr/src/test/java/org/apache/camel/component/solr/SolrComponentTestSupport.java
    
camel/branches/camel-2.9.x/components/camel-solr/src/test/java/org/apache/camel/component/solr/SolrSpringTest.java
    
camel/branches/camel-2.9.x/components/camel-solr/src/test/java/org/apache/camel/component/solr/SolrUpdateTest.java
    
camel/branches/camel-2.9.x/components/camel-solr/src/test/resources/SolrSpringTest-context.xml

Propchange: camel/branches/camel-2.9.x/components/camel-solr/
------------------------------------------------------------------------------
    svn:mergeinfo = /camel/trunk/components/camel-solr:1227197-1298579

Modified: camel/branches/camel-2.9.x/components/camel-solr/pom.xml
URL: 
http://svn.apache.org/viewvc/camel/branches/camel-2.9.x/components/camel-solr/pom.xml?rev=1298581&r1=1298580&r2=1298581&view=diff
==============================================================================
--- camel/branches/camel-2.9.x/components/camel-solr/pom.xml (original)
+++ camel/branches/camel-2.9.x/components/camel-solr/pom.xml Thu Mar  8 
21:10:28 2012
@@ -17,14 +17,14 @@
     limitations under the License.
 
 -->
-<project xmlns="http://maven.apache.org/POM/4.0.0"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/maven-v4_0_0.xsd";>
-
-    <modelVersion>4.0.0</modelVersion>
+<project xmlns="http://maven.apache.org/POM/4.0.0"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
+  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/maven-v4_0_0.xsd";>
 
+  <modelVersion>4.0.0</modelVersion>
   <parent>
     <artifactId>components</artifactId>
     <groupId>org.apache.camel</groupId>
-    <version>2.9.2-SNAPSHOT</version>
+    <version>2.10-SNAPSHOT</version>
   </parent>
 
   <groupId>org.apache.camel</groupId>
@@ -33,100 +33,98 @@
   <name>Camel :: Solr</name>
   <description>Camel Solr Support</description>
 
-    <properties>
-        <camel.osgi.export.pkg>
-            org.apache.camel.component.solr.*;${camel.osgi.version}
-        </camel.osgi.export.pkg>
-    </properties>
-
-    <dependencies>
-        <dependency>
-            <groupId>org.apache.camel</groupId>
-            <artifactId>camel-core</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>commons-codec</groupId>
-            <artifactId>commons-codec</artifactId>
-            <version>${commons-codec-version}</version>
-        </dependency>
-        <dependency>
-            <groupId>org.apache.solr</groupId>
-            <artifactId>solr-solrj</artifactId>
-            <version>${solr-version}</version>
-        </dependency>
-
-        <!-- testing -->
-        <dependency>
-            <groupId>org.apache.camel</groupId>
-            <artifactId>camel-test</artifactId>
-            <scope>test</scope>
-        </dependency>
-
-        <dependency>
-            <groupId>org.apache.solr</groupId>
-            <artifactId>solr-core</artifactId>
-            <version>${solr-version}</version>
-            <scope>test</scope>
-          <exclusions>
-            <!-- exclude jdk14 as we want to use log4j -->
-            <exclusion>
-              <groupId>org.slf4j</groupId>
-              <artifactId>slf4j-jdk14</artifactId>
-            </exclusion>
-          </exclusions>
-        </dependency>
-
-        <dependency>
-            <groupId>org.apache.solr</groupId>
-            <artifactId>solr-cell</artifactId>
-            <version>${solr-version}</version>
-            <scope>test</scope>
-            <exclusions>
-              <!-- exclude netcdf as it has a slf4j binding -->
-              <exclusion>
-                <groupId>edu.ucar</groupId>
-                <artifactId>netcdf</artifactId>
-              </exclusion>
-            </exclusions>
-        </dependency>
-
-        <dependency>
-            <groupId>org.mortbay.jetty</groupId>
-            <artifactId>jetty</artifactId>
-            <version>6.1.24</version>
-            <scope>test</scope>
-        </dependency>
-
-        <dependency>
-            <groupId>org.springframework</groupId>
-            <artifactId>spring-test</artifactId>
-            <scope>test</scope>
-        </dependency>
-
-        <dependency>
-            <groupId>org.apache.camel</groupId>
-            <artifactId>camel-jms</artifactId>
-            <scope>test</scope>
-        </dependency>
-
-        <dependency>
-            <groupId>org.apache.camel</groupId>
-            <artifactId>camel-script</artifactId>
-            <scope>test</scope>
-        </dependency>
-
-        <dependency>
-            <groupId>org.codehaus.groovy</groupId>
-            <artifactId>groovy-all</artifactId>
-            <scope>test</scope>
-        </dependency>
-
-        <!-- logging -->
-        <dependency>
+  <properties>
+    <camel.osgi.export.pkg>
+      org.apache.camel.component.solr.*;${camel.osgi.version}
+    </camel.osgi.export.pkg>
+  </properties>
+
+  <dependencies>
+    <dependency>
+      <groupId>org.apache.camel</groupId>
+      <artifactId>camel-core</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>commons-codec</groupId>
+      <artifactId>commons-codec</artifactId>
+      <version>${commons-codec-version}</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.solr</groupId>
+      <artifactId>solr-solrj</artifactId>
+      <version>${solr-version}</version>
+    </dependency>
+
+    <!-- testing -->
+    <dependency>
+      <groupId>org.apache.camel</groupId>
+      <artifactId>camel-core-xml</artifactId>
+      <scope>test</scope>
+    </dependency>
+
+    <dependency>
+      <groupId>org.apache.camel</groupId>
+      <artifactId>camel-test-spring</artifactId>
+      <scope>test</scope>
+    </dependency>
+
+    <dependency>
+      <groupId>org.apache.solr</groupId>
+      <artifactId>solr-core</artifactId>
+      <version>${solr-version}</version>
+      <scope>test</scope>
+      <exclusions>
+        <!-- exclude jdk14 as we want to use log4j -->
+        <exclusion>
           <groupId>org.slf4j</groupId>
-          <artifactId>slf4j-log4j12</artifactId>
-          <scope>test</scope>
-        </dependency>
-
-    </dependencies>
+          <artifactId>slf4j-jdk14</artifactId>
+        </exclusion>
+      </exclusions>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.solr</groupId>
+      <artifactId>solr-cell</artifactId>
+      <version>${solr-version}</version>
+      <scope>test</scope>
+      <exclusions>
+        <!-- exclude netcdf as it has a slf4j binding -->
+        <exclusion>
+          <groupId>edu.ucar</groupId>
+          <artifactId>netcdf</artifactId>
+        </exclusion>
+      </exclusions>
+    </dependency>
+    <dependency>
+      <groupId>org.mortbay.jetty</groupId>
+      <artifactId>jetty</artifactId>
+      <version>6.1.24</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.springframework</groupId>
+      <artifactId>spring-context</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.springframework</groupId>
+      <artifactId>spring-test</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.camel</groupId>
+      <artifactId>camel-script</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.codehaus.groovy</groupId>
+      <artifactId>groovy-all</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <!-- logging -->
+    <dependency>
+      <groupId>org.slf4j</groupId>
+      <artifactId>slf4j-log4j12</artifactId>
+      <scope>test</scope>
+    </dependency>
+  </dependencies>
 </project>

Modified: 
camel/branches/camel-2.9.x/components/camel-solr/src/main/java/org/apache/camel/component/solr/SolrComponent.java
URL: 
http://svn.apache.org/viewvc/camel/branches/camel-2.9.x/components/camel-solr/src/main/java/org/apache/camel/component/solr/SolrComponent.java?rev=1298581&r1=1298580&r2=1298581&view=diff
==============================================================================
--- 
camel/branches/camel-2.9.x/components/camel-solr/src/main/java/org/apache/camel/component/solr/SolrComponent.java
 (original)
+++ 
camel/branches/camel-2.9.x/components/camel-solr/src/main/java/org/apache/camel/component/solr/SolrComponent.java
 Thu Mar  8 21:10:28 2012
@@ -26,7 +26,7 @@ import org.apache.camel.impl.DefaultComp
 public class SolrComponent extends DefaultComponent {
 
     protected Endpoint createEndpoint(String uri, String remaining, 
Map<String, Object> parameters) throws Exception {
-        Endpoint endpoint = new SolrEndpoint(uri, this, remaining);
+        Endpoint endpoint = new SolrEndpoint(uri, this, remaining, parameters);
         setProperties(endpoint, parameters);
         return endpoint;
     }

Modified: 
camel/branches/camel-2.9.x/components/camel-solr/src/main/java/org/apache/camel/component/solr/SolrConstants.java
URL: 
http://svn.apache.org/viewvc/camel/branches/camel-2.9.x/components/camel-solr/src/main/java/org/apache/camel/component/solr/SolrConstants.java?rev=1298581&r1=1298580&r2=1298581&view=diff
==============================================================================
--- 
camel/branches/camel-2.9.x/components/camel-solr/src/main/java/org/apache/camel/component/solr/SolrConstants.java
 (original)
+++ 
camel/branches/camel-2.9.x/components/camel-solr/src/main/java/org/apache/camel/component/solr/SolrConstants.java
 Thu Mar  8 21:10:28 2012
@@ -25,10 +25,16 @@ public final class SolrConstants {
     public static final String OPERATION_ROLLBACK = "ROLLBACK";
     public static final String OPERATION_OPTIMIZE = "OPTIMIZE";
     public static final String OPERATION_INSERT = "INSERT";
+    public static final String OPERATION_INSERT_STREAMING = "INSERT_STREAMING";
     public static final String OPERATION_ADD_BEAN = "ADD_BEAN";
     public static final String OPERATION_DELETE_BY_ID = "DELETE_BY_ID";
     public static final String OPERATION_DELETE_BY_QUERY = "DELETE_BY_QUERY";
 
+    public static final String PARAM_STREAMING_QUEUE_SIZE = 
"streamingQueueSize";
+    public static final String PARAM_STREAMING_THREAD_COUNT = 
"streamingThreadCount";
+    public static final int DEFUALT_STREAMING_QUEUE_SIZE = 10;
+    public static final int DEFAULT_STREAMING_THREAD_COUNT = 2;
+
     private SolrConstants() {
         throw new AssertionError();
     }

Modified: 
camel/branches/camel-2.9.x/components/camel-solr/src/main/java/org/apache/camel/component/solr/SolrEndpoint.java
URL: 
http://svn.apache.org/viewvc/camel/branches/camel-2.9.x/components/camel-solr/src/main/java/org/apache/camel/component/solr/SolrEndpoint.java?rev=1298581&r1=1298580&r2=1298581&view=diff
==============================================================================
--- 
camel/branches/camel-2.9.x/components/camel-solr/src/main/java/org/apache/camel/component/solr/SolrEndpoint.java
 (original)
+++ 
camel/branches/camel-2.9.x/components/camel-solr/src/main/java/org/apache/camel/component/solr/SolrEndpoint.java
 Thu Mar  8 21:10:28 2012
@@ -16,11 +16,13 @@
  */
 package org.apache.camel.component.solr;
 
+import java.util.Map;
 import org.apache.camel.Consumer;
 import org.apache.camel.Processor;
 import org.apache.camel.Producer;
 import org.apache.camel.impl.DefaultEndpoint;
 import org.apache.solr.client.solrj.impl.CommonsHttpSolrServer;
+import org.apache.solr.client.solrj.impl.StreamingUpdateSolrServer;
 
 /**
  * Represents a Solr endpoint.
@@ -28,22 +30,25 @@ import org.apache.solr.client.solrj.impl
 public class SolrEndpoint extends DefaultEndpoint {
 
     private CommonsHttpSolrServer solrServer;
+    private CommonsHttpSolrServer streamingSolrServer;
     private String requestHandler;
+    private int streamingThreadCount;
+    private int streamingQueueSize;
 
-    public SolrEndpoint() {
-    }
-
-    public SolrEndpoint(String uri, SolrComponent component) {
-        super(uri, component);
-    }
+    public SolrEndpoint(String endpointUri, SolrComponent component, String 
address, Map<String, Object> parameters) throws Exception {
+        super(endpointUri, component);
 
-    public SolrEndpoint(String endpointUri) {
-        super(endpointUri);
+        solrServer = new CommonsHttpSolrServer("http://"; + address);
+        streamingQueueSize = getIntFromString((String) 
parameters.get(SolrConstants.PARAM_STREAMING_QUEUE_SIZE), 
SolrConstants.DEFUALT_STREAMING_QUEUE_SIZE);
+        streamingThreadCount = getIntFromString((String) 
parameters.get(SolrConstants.PARAM_STREAMING_THREAD_COUNT), 
SolrConstants.DEFAULT_STREAMING_THREAD_COUNT);
+        streamingSolrServer = new StreamingUpdateSolrServer("http://"; + 
address, streamingQueueSize, streamingThreadCount);
     }
 
-    public SolrEndpoint(String endpointUri, SolrComponent component, String 
address) throws Exception {
-        super(endpointUri, component);
-        solrServer = new CommonsHttpSolrServer("http://"; + address);
+    public static int getIntFromString(String value, int defaultValue) {
+        if (value != null && value.length() > 0) {
+            return Integer.parseInt(value);
+        }
+        return defaultValue;
     }
 
     @Override
@@ -65,32 +70,47 @@ public class SolrEndpoint extends Defaul
         return solrServer;
     }
 
+    public CommonsHttpSolrServer getStreamingSolrServer() {
+        return streamingSolrServer;
+    }
+
+    public void setStreamingSolrServer(CommonsHttpSolrServer 
streamingSolrServer) {
+        this.streamingSolrServer = streamingSolrServer;
+    }
+
     public void setMaxRetries(int maxRetries) {
         solrServer.setMaxRetries(maxRetries);
+        streamingSolrServer.setMaxRetries(maxRetries);
     }
 
     public void setSoTimeout(int soTimeout) {
         solrServer.setSoTimeout(soTimeout);
+        streamingSolrServer.setSoTimeout(soTimeout);
     }
 
     public void setConnectionTimeout(int connectionTimeout) {
         solrServer.setConnectionTimeout(connectionTimeout);
+        streamingSolrServer.setConnectionTimeout(connectionTimeout);
     }
 
     public void setDefaultMaxConnectionsPerHost(int 
defaultMaxConnectionsPerHost) {
         
solrServer.setDefaultMaxConnectionsPerHost(defaultMaxConnectionsPerHost);
+        
streamingSolrServer.setDefaultMaxConnectionsPerHost(defaultMaxConnectionsPerHost);
     }
 
     public void setMaxTotalConnections(int maxTotalConnections) {
         solrServer.setMaxTotalConnections(maxTotalConnections);
+        streamingSolrServer.setMaxTotalConnections(maxTotalConnections);
     }
 
     public void setFollowRedirects(boolean followRedirects) {
         solrServer.setFollowRedirects(followRedirects);
+        streamingSolrServer.setFollowRedirects(followRedirects);
     }
 
     public void setAllowCompression(boolean allowCompression) {
         solrServer.setAllowCompression(allowCompression);
+        streamingSolrServer.setAllowCompression(allowCompression);
     }
 
     public void setRequestHandler(String requestHandler) {
@@ -100,4 +120,20 @@ public class SolrEndpoint extends Defaul
     public String getRequestHandler() {
         return requestHandler;
     }
+
+    public int getStreamingThreadCount() {
+        return streamingThreadCount;
+    }
+
+    public void setStreamingThreadCount(int streamingThreadCount) {
+        this.streamingThreadCount = streamingThreadCount;
+    }
+
+    public int getStreamingQueueSize() {
+        return streamingQueueSize;
+    }
+
+    public void setStreamingQueueSize(int streamingQueueSize) {
+        this.streamingQueueSize = streamingQueueSize;
+    }
 }

Modified: 
camel/branches/camel-2.9.x/components/camel-solr/src/main/java/org/apache/camel/component/solr/SolrProducer.java
URL: 
http://svn.apache.org/viewvc/camel/branches/camel-2.9.x/components/camel-solr/src/main/java/org/apache/camel/component/solr/SolrProducer.java?rev=1298581&r1=1298580&r2=1298581&view=diff
==============================================================================
--- 
camel/branches/camel-2.9.x/components/camel-solr/src/main/java/org/apache/camel/component/solr/SolrProducer.java
 (original)
+++ 
camel/branches/camel-2.9.x/components/camel-solr/src/main/java/org/apache/camel/component/solr/SolrProducer.java
 Thu Mar  8 21:10:28 2012
@@ -22,21 +22,22 @@ import org.apache.camel.Exchange;
 import org.apache.camel.impl.DefaultProducer;
 import org.apache.solr.client.solrj.SolrServer;
 import org.apache.solr.client.solrj.request.ContentStreamUpdateRequest;
+import org.apache.solr.client.solrj.request.DirectXmlRequest;
 import org.apache.solr.client.solrj.request.UpdateRequest;
+import org.apache.solr.common.SolrException;
 import org.apache.solr.common.SolrInputDocument;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
 /**
  * The Solr producer.
  */
 public class SolrProducer extends DefaultProducer {
-    private static final transient Logger LOG = 
LoggerFactory.getLogger(SolrProducer.class);
     private SolrServer solrServer;
+    private SolrServer streamingSolrServer;
 
     public SolrProducer(SolrEndpoint endpoint) {
         super(endpoint);
         solrServer = endpoint.getSolrServer();
+        streamingSolrServer = endpoint.getStreamingSolrServer();
     }
 
     @Override
@@ -49,7 +50,9 @@ public class SolrProducer extends Defaul
         }
 
         if (operation.equalsIgnoreCase(SolrConstants.OPERATION_INSERT)) {
-            insert(exchange);
+            insert(exchange, false);
+        } else if 
(operation.equalsIgnoreCase(SolrConstants.OPERATION_INSERT_STREAMING)) {
+            insert(exchange, true);
         } else if 
(operation.equalsIgnoreCase(SolrConstants.OPERATION_DELETE_BY_ID)) {
             solrServer.deleteById(exchange.getIn().getBody(String.class));
         } else if 
(operation.equalsIgnoreCase(SolrConstants.OPERATION_DELETE_BY_QUERY)) {
@@ -67,11 +70,18 @@ public class SolrProducer extends Defaul
         }
     }
 
-    private void insert(Exchange exchange) throws Exception {
+    private void insert(Exchange exchange, boolean isStreaming) throws 
Exception {
 
         Object body = exchange.getIn().getBody();
 
+        boolean hasSolrHeaders = false;
+        Map<String, Object> headers = exchange.getIn().getHeaders();
+        if (headers != null && headers.containsKey(SolrConstants.FIELD + 
"id")) {
+            hasSolrHeaders = true;
+        }
+
         if (body instanceof File) {
+
             ContentStreamUpdateRequest updateRequest = new 
ContentStreamUpdateRequest(getRequestHandler());
             updateRequest.addFile((File) body);
 
@@ -82,8 +92,27 @@ public class SolrProducer extends Defaul
                 }
             }
 
-            updateRequest.process(solrServer);
-        } else {
+            if (isStreaming) {
+                updateRequest.process(streamingSolrServer);
+            } else {
+                updateRequest.process(solrServer);
+            }
+
+        } else if (body instanceof SolrInputDocument) {
+
+            UpdateRequest updateRequest = new 
UpdateRequest(getRequestHandler());
+            updateRequest.add((SolrInputDocument) body);
+
+            if (isStreaming) {
+                updateRequest.process(streamingSolrServer);
+            } else {
+                updateRequest.process(solrServer);
+            }
+
+        } else if (hasSolrHeaders) {
+
+            UpdateRequest updateRequest = new 
UpdateRequest(getRequestHandler());
+
             SolrInputDocument doc = new SolrInputDocument();
             for (Map.Entry<String, Object> entry : 
exchange.getIn().getHeaders().entrySet()) {
                 if (entry.getKey().startsWith(SolrConstants.FIELD)) {
@@ -91,10 +120,32 @@ public class SolrProducer extends Defaul
                     doc.setField(fieldName, entry.getValue());
                 }
             }
-
-            UpdateRequest updateRequest = new 
UpdateRequest(getRequestHandler());
             updateRequest.add(doc);
-            updateRequest.process(solrServer);
+
+            if (isStreaming) {
+                updateRequest.process(streamingSolrServer);
+            } else {
+                updateRequest.process(solrServer);
+            }
+
+        } else if (body instanceof String) {
+
+            String bodyAsString = (String) body;
+
+            if (!bodyAsString.startsWith("<add")) {
+                bodyAsString = "<add>" + bodyAsString + "</add>";
+            }
+
+            DirectXmlRequest xmlRequest = new 
DirectXmlRequest(getRequestHandler(), bodyAsString);
+
+            if (isStreaming) {
+                streamingSolrServer.request(xmlRequest);
+            } else {
+                solrServer.request(xmlRequest);
+            }
+
+        } else {
+            throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, 
"unable to find data in Exchange to update Solr");
         }
     }
 

Modified: 
camel/branches/camel-2.9.x/components/camel-solr/src/test/java/org/apache/camel/component/solr/InitSolrEndpointTest.java
URL: 
http://svn.apache.org/viewvc/camel/branches/camel-2.9.x/components/camel-solr/src/test/java/org/apache/camel/component/solr/InitSolrEndpointTest.java?rev=1298581&r1=1298580&r2=1298581&view=diff
==============================================================================
--- 
camel/branches/camel-2.9.x/components/camel-solr/src/test/java/org/apache/camel/component/solr/InitSolrEndpointTest.java
 (original)
+++ 
camel/branches/camel-2.9.x/components/camel-solr/src/test/java/org/apache/camel/component/solr/InitSolrEndpointTest.java
 Thu Mar  8 21:10:28 2012
@@ -27,16 +27,27 @@ public class InitSolrEndpointTest extend
     @Test
     public void endpointCreatedCorrectlyWithAllOptions() throws Exception {
         SolrEndpoint solrEndpoint = context.getEndpoint(solrUrl + 
getFullOptions(), SolrEndpoint.class);
+        assertEquals("queue size incorrect", 5, 
solrEndpoint.getStreamingQueueSize());
+        assertEquals("thread count incorrect", 1, 
solrEndpoint.getStreamingThreadCount());
         assertNotNull(solrEndpoint);
     }
 
+    @Test
+    public void streamingEndpointCreatedCorrectly() throws Exception {
+        SolrEndpoint solrEndpoint = context.getEndpoint(solrUrl, 
SolrEndpoint.class);
+        assertNotNull(solrEndpoint);
+        assertEquals("queue size incorrect", 
SolrConstants.DEFUALT_STREAMING_QUEUE_SIZE, 
solrEndpoint.getStreamingQueueSize());
+        assertEquals("thread count incorrect", 
SolrConstants.DEFAULT_STREAMING_THREAD_COUNT, 
solrEndpoint.getStreamingThreadCount());
+    }
+
     @Test(expected = ResolveEndpointFailedException.class)
     public void wrongURLFormatFailsEndpointCreation() throws Exception {
         context.getEndpoint("solr://localhost:-99/solr");
     }
 
     private String getFullOptions() {
-        return "?maxRetries=1&soTimeout=100&connectionTimeout=100"
+        return "?streamingQueueSize=5&streamingThreadCount=1"
+                + "&maxRetries=1&soTimeout=100&connectionTimeout=100"
                 + "&defaultMaxConnectionsPerHost=100&maxTotalConnections=100"
                 + "&followRedirects=false&allowCompression=true"
                 + "&requestHandler=/update";

Modified: 
camel/branches/camel-2.9.x/components/camel-solr/src/test/java/org/apache/camel/component/solr/SolrComponentTestSupport.java
URL: 
http://svn.apache.org/viewvc/camel/branches/camel-2.9.x/components/camel-solr/src/test/java/org/apache/camel/component/solr/SolrComponentTestSupport.java?rev=1298581&r1=1298580&r2=1298581&view=diff
==============================================================================
--- 
camel/branches/camel-2.9.x/components/camel-solr/src/test/java/org/apache/camel/component/solr/SolrComponentTestSupport.java
 (original)
+++ 
camel/branches/camel-2.9.x/components/camel-solr/src/test/java/org/apache/camel/component/solr/SolrComponentTestSupport.java
 Thu Mar  8 21:10:28 2012
@@ -17,6 +17,8 @@
 package org.apache.camel.component.solr;
 
 import java.util.HashMap;
+import java.util.Map;
+
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.test.AvailablePortFinder;
 import org.apache.camel.test.junit4.CamelTestSupport;
@@ -38,7 +40,7 @@ public class SolrComponentTestSupport ex
     protected static CommonsHttpSolrServer solrServer;
 
     protected void solrInsertTestEntry() {
-        HashMap<String, Object> headers = new HashMap<String, Object>();
+        Map<String, Object> headers = new HashMap<String, Object>();
         headers.put(SolrConstants.OPERATION, SolrConstants.OPERATION_INSERT);
         headers.put("SolrField.id", TEST_ID);
         template.sendBodyAndHeaders("direct:start", null, headers);

Modified: 
camel/branches/camel-2.9.x/components/camel-solr/src/test/java/org/apache/camel/component/solr/SolrSpringTest.java
URL: 
http://svn.apache.org/viewvc/camel/branches/camel-2.9.x/components/camel-solr/src/test/java/org/apache/camel/component/solr/SolrSpringTest.java?rev=1298581&r1=1298580&r2=1298581&view=diff
==============================================================================
--- 
camel/branches/camel-2.9.x/components/camel-solr/src/test/java/org/apache/camel/component/solr/SolrSpringTest.java
 (original)
+++ 
camel/branches/camel-2.9.x/components/camel-solr/src/test/java/org/apache/camel/component/solr/SolrSpringTest.java
 Thu Mar  8 21:10:28 2012
@@ -26,7 +26,9 @@ import org.apache.solr.client.solrj.Solr
 import org.apache.solr.client.solrj.embedded.JettySolrRunner;
 import org.apache.solr.client.solrj.impl.CommonsHttpSolrServer;
 import org.apache.solr.client.solrj.response.QueryResponse;
+import org.apache.solr.client.solrj.util.ClientUtils;
 import org.apache.solr.common.SolrDocument;
+import org.apache.solr.common.SolrInputDocument;
 import org.junit.AfterClass;
 import org.junit.Before;
 import org.junit.BeforeClass;
@@ -45,12 +47,35 @@ public class SolrSpringTest extends Abst
     private static JettySolrRunner solrRunner;
     private static CommonsHttpSolrServer solrServer;
 
+    @Produce(uri = "direct:direct-xml-start")
+    protected ProducerTemplate directXmlRoute;
+
     @Produce(uri = "direct:xml-start")
     protected ProducerTemplate xmlRoute;
 
+    @Produce(uri = "direct:xml-start-streaming")
+    protected ProducerTemplate xmlRouteStreaming;
+
     @Produce(uri = "direct:pdf-start")
     protected ProducerTemplate pdfRoute;
 
+    @Produce(uri = "direct:pdf-start-streaming")
+    protected ProducerTemplate pdfRouteStreaming;
+
+
+    @DirtiesContext
+    @Test
+    public void endToEndIndexDirectXML() throws Exception {
+        SolrInputDocument doc = new SolrInputDocument();
+        doc.addField("id", "MA147LL/A", 1.0f);
+        String docAsXml = ClientUtils.toXML(doc);
+        directXmlRoute.sendBody(docAsXml);
+
+        QueryResponse response = executeSolrQuery("id:MA147LL/A");
+        assertEquals(0, response.getStatus());
+        assertEquals(1, response.getResults().getNumFound());
+    }
+    
     @DirtiesContext
     @Test
     public void endToEndIndexXMLDocuments() throws Exception {
@@ -70,6 +95,26 @@ public class SolrSpringTest extends Abst
         assertEquals(Arrays.asList("Web", "Technology", "Computers"), 
doc.getFieldValue("cat"));
     }
 
+
+    @DirtiesContext
+    @Test
+    public void endToEndIndexXMLDocumentsStreaming() throws Exception {
+        xmlRouteStreaming.sendBody(new 
File("src/test/resources/data/books.xml"));
+
+        // Check things were indexed.
+        QueryResponse response = executeSolrQuery("*:*");
+
+        assertEquals(0, response.getStatus());
+        assertEquals(4, response.getResults().getNumFound());
+
+        // Check fields were indexed correctly.
+        response = executeSolrQuery("title:Learning XML");
+
+        SolrDocument doc = response.getResults().get(0);
+        assertEquals("Learning XML", doc.getFieldValue("id"));
+        assertEquals(Arrays.asList("Web", "Technology", "Computers"), 
doc.getFieldValue("cat"));
+    }
+
     @DirtiesContext
     @Test
     public void endToEndIndexPDFDocument() throws Exception {
@@ -86,6 +131,22 @@ public class SolrSpringTest extends Abst
         assertEquals(Arrays.asList("application/pdf"), 
doc.getFieldValue("content_type"));
     }
 
+    @DirtiesContext
+    @Test
+    public void endToEndIndexPDFDocumentStreaming() throws Exception {
+        pdfRouteStreaming.sendBody(new 
File("src/test/resources/data/tutorial.pdf"));
+
+        QueryResponse response = executeSolrQuery("*:*");
+
+        assertEquals(0, response.getStatus());
+        assertEquals(1, response.getResults().getNumFound());
+
+        SolrDocument doc = response.getResults().get(0);
+        assertEquals("Solr", doc.getFieldValue("subject"));
+        assertEquals("tutorial.pdf", doc.getFieldValue("id"));
+        assertEquals(Arrays.asList("application/pdf"), 
doc.getFieldValue("content_type"));
+    }
+
     @BeforeClass
     public static void beforeClass() throws Exception {
         // Set appropriate paths for Solr to use.

Modified: 
camel/branches/camel-2.9.x/components/camel-solr/src/test/java/org/apache/camel/component/solr/SolrUpdateTest.java
URL: 
http://svn.apache.org/viewvc/camel/branches/camel-2.9.x/components/camel-solr/src/test/java/org/apache/camel/component/solr/SolrUpdateTest.java?rev=1298581&r1=1298580&r2=1298581&view=diff
==============================================================================
--- 
camel/branches/camel-2.9.x/components/camel-solr/src/test/java/org/apache/camel/component/solr/SolrUpdateTest.java
 (original)
+++ 
camel/branches/camel-2.9.x/components/camel-solr/src/test/java/org/apache/camel/component/solr/SolrUpdateTest.java
 Thu Mar  8 21:10:28 2012
@@ -19,11 +19,12 @@ package org.apache.camel.component.solr;
 import java.io.File;
 import java.util.Arrays;
 import java.util.List;
-import org.apache.camel.EndpointInject;
 import org.apache.camel.Exchange;
 import org.apache.solr.client.solrj.response.QueryResponse;
+import org.apache.solr.client.solrj.util.ClientUtils;
 import org.apache.solr.common.SolrDocument;
 import org.apache.solr.common.SolrException;
+import org.apache.solr.common.SolrInputDocument;
 import org.junit.Before;
 import org.junit.Ignore;
 import org.junit.Test;
@@ -40,6 +41,65 @@ public class SolrUpdateTest extends Solr
     }
 
     @Test
+    public void testInsertSolrInputDocumentAsXMLWithoutAddRoot() throws 
Exception {
+
+        SolrInputDocument doc = new SolrInputDocument();
+        doc.addField("id", "MA147LL/A", 1.0f);
+        String docAsXml = ClientUtils.toXML(doc);
+        template.sendBodyAndHeader("direct:start", docAsXml, 
SolrConstants.OPERATION, SolrConstants.OPERATION_INSERT);
+        solrCommit();
+
+        QueryResponse response = executeSolrQuery("id:MA147LL/A");
+        assertEquals(0, response.getStatus());
+        assertEquals(1, response.getResults().getNumFound());
+    }
+
+    @Test
+    public void testInsertSolrInputDocumentAsXMLWithAddRoot() throws Exception 
{
+
+        SolrInputDocument doc = new SolrInputDocument();
+        doc.addField("id", "MA147LL/A", 1.0f);
+        String docAsXml = "<add>" + ClientUtils.toXML(doc) + "</add>";
+        template.sendBodyAndHeader("direct:start", docAsXml, 
SolrConstants.OPERATION, SolrConstants.OPERATION_INSERT);
+        solrCommit();
+
+        QueryResponse response = executeSolrQuery("id:MA147LL/A");
+        assertEquals(0, response.getStatus());
+        assertEquals(1, response.getResults().getNumFound());
+    }
+
+    @Test
+    public void testInsertSolrInputDocument() throws Exception {
+
+        SolrInputDocument doc = new SolrInputDocument();
+        doc.addField("id", "MA147LL/A", 1.0f);
+        template.sendBodyAndHeader("direct:start", doc, 
SolrConstants.OPERATION, SolrConstants.OPERATION_INSERT);
+
+        solrCommit();
+
+        QueryResponse response = executeSolrQuery("id:MA147LL/A");
+        assertEquals(0, response.getStatus());
+        assertEquals(1, response.getResults().getNumFound());
+    }
+
+    @Test
+    public void testInsertStreaming() throws Exception {
+
+        Exchange exchange = createExchangeWithBody(null);
+        exchange.getIn().setHeader(SolrConstants.OPERATION, 
SolrConstants.OPERATION_INSERT_STREAMING);
+        exchange.getIn().setHeader("SolrField.id", "MA147LL/A");
+        template.send("direct:start", exchange);
+
+        Thread.sleep(500);
+
+        solrCommit();
+
+        QueryResponse response = executeSolrQuery("id:MA147LL/A");
+        assertEquals(0, response.getStatus());
+        assertEquals(1, response.getResults().getNumFound());
+    }
+
+    @Test
     public void indexSingleDocumentOnlyWithId() throws Exception {
         Exchange exchange = createExchangeWithBody(null);
         exchange.getIn().setHeader(SolrConstants.OPERATION, 
SolrConstants.OPERATION_INSERT);
@@ -105,7 +165,7 @@ public class SolrUpdateTest extends Solr
         assertEquals(1, response.getResults().getNumFound());
 
         SolrDocument doc = response.getResults().get(0);
-        assertArrayEquals(categories, ((List) 
doc.getFieldValue("cat")).toArray());
+        assertArrayEquals(categories, ((List<?>) 
doc.getFieldValue("cat")).toArray());
     }
 
     @Test

Modified: 
camel/branches/camel-2.9.x/components/camel-solr/src/test/resources/SolrSpringTest-context.xml
URL: 
http://svn.apache.org/viewvc/camel/branches/camel-2.9.x/components/camel-solr/src/test/resources/SolrSpringTest-context.xml?rev=1298581&r1=1298580&r2=1298581&view=diff
==============================================================================
--- 
camel/branches/camel-2.9.x/components/camel-solr/src/test/resources/SolrSpringTest-context.xml
 (original)
+++ 
camel/branches/camel-2.9.x/components/camel-solr/src/test/resources/SolrSpringTest-context.xml
 Thu Mar  8 21:10:28 2012
@@ -7,6 +7,18 @@
     <bean id="properties" 
class="org.apache.camel.component.properties.PropertiesComponent"/>
 
     <camelContext xmlns="http://camel.apache.org/schema/spring";>
+        <route id="DirectXMLRoute">
+            <from uri="direct:direct-xml-start" />
+            <setHeader headerName="SolrOperation">
+                <constant>INSERT</constant>
+            </setHeader>
+            <to uri="solr://localhost:{{SolrServer.Port}}/solr"/>
+            <setHeader headerName="SolrOperation">
+                <constant>COMMIT</constant>
+            </setHeader>
+            <to uri="solr://localhost:{{SolrServer.Port}}/solr"/>
+        </route>
+
         <route id="XMLRoute">
             <from uri="direct:xml-start" />
             <split>
@@ -35,6 +47,35 @@
             <to uri="solr://localhost:{{SolrServer.Port}}/solr"/>
         </route>
 
+        <route id="XMLRoute-Streaming">
+            <from uri="direct:xml-start-streaming" />
+            <split>
+                <xpath>/bookstore/book</xpath>
+                <convertBodyTo type="java.lang.String"/>
+                <setHeader headerName="SolrOperation">
+                    <constant>INSERT_STREAMING</constant>
+                </setHeader>
+                <setHeader headerName="SolrField.id">
+                    <xpath resultType="java.lang.String">//title/text()</xpath>
+                </setHeader>
+                <setHeader headerName="SolrField.title">
+                    <xpath resultType="java.lang.String">//title/text()</xpath>
+                </setHeader>
+                <setHeader headerName="SolrField.cat">
+                    <groovy>
+                        def book = new XmlParser().parseText(request.body)
+                        book.cat.collect{ it.text() } as String[]
+                    </groovy>
+                </setHeader>
+                <to uri="solr://localhost:{{SolrServer.Port}}/solr"/>
+            </split>
+            <delay><constant>500</constant></delay>
+            <setHeader headerName="SolrOperation">
+                <constant>COMMIT</constant>
+            </setHeader>
+            <to uri="solr://localhost:{{SolrServer.Port}}/solr"/>
+        </route>
+
         <route id="PDFRoute">
             <from uri="direct:pdf-start" />
             <setHeader headerName="SolrOperation">
@@ -49,6 +90,23 @@
             </setHeader>
             <to uri="solr://localhost:{{SolrServer.Port}}/solr"/>
         </route>
+
+        <route id="PDFRoute-Streaming">
+            <from uri="direct:pdf-start-streaming" />
+            <setHeader headerName="SolrOperation">
+                <constant>INSERT_STREAMING</constant>
+            </setHeader>
+            <setHeader headerName="SolrParam.literal.id">
+                <simple>${body.name}</simple>
+            </setHeader>
+            <to 
uri="solr://localhost:{{SolrServer.Port}}/solr?requestHandler=/update/extract" 
/>
+            <delay><constant>500</constant></delay>
+            <setHeader headerName="SolrOperation">
+                <constant>COMMIT</constant>
+            </setHeader>
+            <to uri="solr://localhost:{{SolrServer.Port}}/solr"/>
+        </route>
+
     </camelContext>
 
 </beans>


Reply via email to