incubator-droids-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From t...@apache.org
Subject svn commit: r1461977 - in /incubator/droids/branches/0.2.x-cleanup/droids-solr: ./ conf/ example/ src/documentation/ src/main/java/org/apache/droids/solr/ src/test/java/org/apache/droids/solr/ src/test/resources/ src/test/resources/example/ src/test/re...
Date Thu, 28 Mar 2013 08:29:29 GMT
Author: tobr
Date: Thu Mar 28 08:29:28 2013
New Revision: 1461977

URL: http://svn.apache.org/r1461977
Log:
refactored the solr handler module

Added:
    incubator/droids/branches/0.2.x-cleanup/droids-solr/src/main/java/org/apache/droids/solr/SolrHandlerImpl.java
  (with props)
    incubator/droids/branches/0.2.x-cleanup/droids-solr/src/test/java/org/apache/droids/solr/SolrTask.java
  (with props)
    incubator/droids/branches/0.2.x-cleanup/droids-solr/src/test/resources/example/
      - copied from r1461504, incubator/droids/branches/0.2.x-cleanup/droids-solr/example/
    incubator/droids/branches/0.2.x-cleanup/droids-solr/src/test/resources/logback.xml   (with
props)
Removed:
    incubator/droids/branches/0.2.x-cleanup/droids-solr/conf/
    incubator/droids/branches/0.2.x-cleanup/droids-solr/example/
    incubator/droids/branches/0.2.x-cleanup/droids-solr/forrest.properties
    incubator/droids/branches/0.2.x-cleanup/droids-solr/src/documentation/
    incubator/droids/branches/0.2.x-cleanup/droids-solr/src/test/java/org/apache/droids/solr/MockContentEntity.java
Modified:
    incubator/droids/branches/0.2.x-cleanup/droids-solr/pom.xml
    incubator/droids/branches/0.2.x-cleanup/droids-solr/src/main/java/org/apache/droids/solr/AdvancedSolrHandler.java
    incubator/droids/branches/0.2.x-cleanup/droids-solr/src/main/java/org/apache/droids/solr/SolrHandler.java
    incubator/droids/branches/0.2.x-cleanup/droids-solr/src/test/java/org/apache/droids/solr/AdvancedSolrHandleTest.java
    incubator/droids/branches/0.2.x-cleanup/droids-solr/src/test/java/org/apache/droids/solr/SolrHandleTest.java
    incubator/droids/branches/0.2.x-cleanup/droids-solr/src/test/resources/example/conf/schema.xml
    incubator/droids/branches/0.2.x-cleanup/droids-solr/src/test/resources/example/conf/solrconfig.xml

Modified: incubator/droids/branches/0.2.x-cleanup/droids-solr/pom.xml
URL: http://svn.apache.org/viewvc/incubator/droids/branches/0.2.x-cleanup/droids-solr/pom.xml?rev=1461977&r1=1461976&r2=1461977&view=diff
==============================================================================
--- incubator/droids/branches/0.2.x-cleanup/droids-solr/pom.xml (original)
+++ incubator/droids/branches/0.2.x-cleanup/droids-solr/pom.xml Thu Mar 28 08:29:28 2013
@@ -15,26 +15,39 @@
    See the License for the specific language governing permissions and
    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">
-
+<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
+         xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
     <modelVersion>4.0.0</modelVersion>
+    <packaging>jar</packaging>
+
     <parent>
-        <artifactId>droids</artifactId>
         <groupId>org.apache.droids</groupId>
+        <artifactId>droids</artifactId>
         <version>0.3.0-incubating-SNAPSHOT</version>
-        <relativePath>../pom.xml</relativePath>
     </parent>
+
     <artifactId>droids-solr</artifactId>
-    <name>Apache Droids Solr</name>
-    <inceptionYear>2007</inceptionYear>
-    <description>Apache Droids Solr Integration</description>
-    <packaging>jar</packaging>
+    <name>APACHE DROIDS SOLR HANDLER</name>
 
     <properties>
-        <solr-release-version>3.6.0</solr-release-version>
+        <solr.version>3.6.0</solr.version>
     </properties>
 
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-surefire-plugin</artifactId>
+                <configuration>
+                    <systemPropertyVariables>
+                        <solr.solr.home>${project.build.testOutputDirectory}/example</solr.solr.home>
+                    </systemPropertyVariables>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+
     <dependencies>
         <dependency>
             <groupId>org.apache.droids</groupId>
@@ -44,13 +57,12 @@
         <dependency>
             <groupId>org.apache.solr</groupId>
             <artifactId>solr-solrj</artifactId>
-            <version>${solr-release-version}</version>
-            <exclusions>
-                <exclusion>
-                    <artifactId>commons-logging</artifactId>
-                    <groupId>commons-logging</groupId>
-                </exclusion>
-            </exclusions>
+            <version>${solr.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>net.sourceforge.nekohtml</groupId>
+            <artifactId>nekohtml</artifactId>
+            <version>1.9.18</version>
         </dependency>
         <!-- FOR TESTING -->
         <dependency>
@@ -62,19 +74,13 @@
         <dependency>
             <groupId>org.apache.solr</groupId>
             <artifactId>solr-core</artifactId>
-            <version>${solr-release-version}</version>
-            <scope>test</scope>
-        </dependency>
-        <dependency>
-            <groupId>javax.servlet</groupId>
-            <artifactId>servlet-api</artifactId>
-            <version>2.3</version>
+            <version>${solr.version}</version>
             <scope>test</scope>
         </dependency>
         <dependency>
-            <groupId>org.slf4j</groupId>
-            <artifactId>slf4j-simple</artifactId>
-            <version>1.6.4</version>
+            <groupId>ch.qos.logback</groupId>
+            <artifactId>logback-classic</artifactId>
+            <version>${logback.version}</version>
             <scope>test</scope>
         </dependency>
     </dependencies>

Modified: incubator/droids/branches/0.2.x-cleanup/droids-solr/src/main/java/org/apache/droids/solr/AdvancedSolrHandler.java
URL: http://svn.apache.org/viewvc/incubator/droids/branches/0.2.x-cleanup/droids-solr/src/main/java/org/apache/droids/solr/AdvancedSolrHandler.java?rev=1461977&r1=1461976&r2=1461977&view=diff
==============================================================================
--- incubator/droids/branches/0.2.x-cleanup/droids-solr/src/main/java/org/apache/droids/solr/AdvancedSolrHandler.java
(original)
+++ incubator/droids/branches/0.2.x-cleanup/droids-solr/src/main/java/org/apache/droids/solr/AdvancedSolrHandler.java
Thu Mar 28 08:29:28 2013
@@ -17,7 +17,6 @@
 package org.apache.droids.solr;
 
 import java.io.IOException;
-import java.net.URI;
 import java.util.Arrays;
 import java.util.HashMap;
 import java.util.Iterator;
@@ -28,9 +27,8 @@ import java.util.Map.Entry;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
-import org.apache.droids.api.ContentEntity;
-import org.apache.droids.api.Handler;
-import org.apache.droids.exception.DroidsException;
+import org.apache.droids.core.DroidsException;
+import org.apache.droids.core.Task;
 import org.apache.solr.client.solrj.SolrServer;
 import org.apache.solr.client.solrj.SolrServerException;
 import org.apache.solr.common.SolrInputDocument;
@@ -57,13 +55,7 @@ import org.xml.sax.SAXNotSupportedExcept
  * - /html[0]/div[0]/p[0]
  * - /html[0]/div[1]/p[2]
  */
-public class AdvancedSolrHandler implements Handler {
-
-    /**
-     * A solr server
-     */
-    private SolrServer server;
-
+public class AdvancedSolrHandler extends SolrHandler {
     /**
      * The selectors allow to save specific parts of the document in the index.
      * The HashMap's key matches the Solr field.
@@ -81,20 +73,16 @@ public class AdvancedSolrHandler impleme
      */
     private SAXParser parser;
 
-    /**
-     * @return the current solr server
-     */
-    public SolrServer getServer() {
-        return server;
+
+    public AdvancedSolrHandler(String solrUrl) {
+        super(solrUrl);
     }
 
-    /**
-     * @param solr a solr server
-     */
-    public void setServer(SolrServer solr) {
-        this.server = solr;
+    public AdvancedSolrHandler(SolrServer solrServer) {
+        super(solrServer);
     }
 
+
     /**
      * @return the current path selectors
      */
@@ -111,34 +99,32 @@ public class AdvancedSolrHandler impleme
     }
 
     /*
-     * @see org.apache.droids.api.Handler#handle(java.net.URI, org.apache.droids.api.ContentEntity)
+     * @see org.apache.droids.api.Handler#handle(java.net.URI, org.apache.droids.api.DroidsContentEntity)
      */
     @Override
-    public void handle(URI uri, ContentEntity entity) throws IOException, DroidsException
{
-        SolrInputDocument doc = createSolrInputDocument(uri, entity);
+    public void handle(Task task) throws DroidsException, IOException {
+        SolrInputDocument doc = createSolrInputDocument(task);
         try {
-            server.add(doc);
+            getSolrServer().add(doc);
         } catch (SolrServerException e) {
             throw new DroidsException(e);
         }
     }
 
     /**
-     * Generates a SolrInputDocument from an URI and a ContentEntity
+     * Generates a SolrInputDocument from an URI and a DroidsContentEntity
      * which correspond to the document which need to be saved in the index
      *
-     * @param uri    an uri
-     * @param entity an entity
+     * @param task   the task
      * @return
      */
-    private SolrInputDocument createSolrInputDocument(URI uri, ContentEntity entity) {
+    private SolrInputDocument createSolrInputDocument(Task task) {
         SolrInputDocument doc = new SolrInputDocument();
 
-        doc.setField("id", uri.getPath());
-        doc.setField("name", uri.toASCIIString());
-        doc.setField("host", uri.getHost());
-        doc.setField("mime", entity.getMimeType());
-        doc.setField("content", entity.getParse().getText());
+        doc.setField("id", task.getURI().getPath());
+        doc.setField("name", task.getURI().toASCIIString());
+        doc.setField("contentType", task.getContentEntity().getContentType());
+        doc.setField("content", task.getParserData().getText());
 
         if (parser == null) initParser();
 
@@ -146,7 +132,7 @@ public class AdvancedSolrHandler impleme
             contentHandler.initDocument(doc);
             try {
                 parser.setContentHandler(contentHandler);
-                parser.parse(new InputSource(entity.obtainContent()));
+                parser.parse(new InputSource(task.getContentEntity().getContent()));
             } catch (IOException e) {
                 e.printStackTrace();
             } catch (SAXException e) {
@@ -177,6 +163,16 @@ public class AdvancedSolrHandler impleme
         return parser;
     }
 
+    @Override
+    public void finish() {
+
+    }
+
+    @Override
+    public void cleanUp(String query) {
+
+    }
+
     /**
      * A class that implements a SAX ContentHandler and uses patterns to record documents
      * elements in a SolrInputDocuement.

Modified: incubator/droids/branches/0.2.x-cleanup/droids-solr/src/main/java/org/apache/droids/solr/SolrHandler.java
URL: http://svn.apache.org/viewvc/incubator/droids/branches/0.2.x-cleanup/droids-solr/src/main/java/org/apache/droids/solr/SolrHandler.java?rev=1461977&r1=1461976&r2=1461977&view=diff
==============================================================================
--- incubator/droids/branches/0.2.x-cleanup/droids-solr/src/main/java/org/apache/droids/solr/SolrHandler.java
(original)
+++ incubator/droids/branches/0.2.x-cleanup/droids-solr/src/main/java/org/apache/droids/solr/SolrHandler.java
Thu Mar 28 08:29:28 2013
@@ -16,39 +16,139 @@
  */
 package org.apache.droids.solr;
 
-import java.io.IOException;
-import java.net.URI;
-
-import org.apache.droids.api.ContentEntity;
-import org.apache.droids.api.Handler;
-import org.apache.droids.exception.DroidsException;
+import org.apache.droids.core.Handler;
 import org.apache.solr.client.solrj.SolrServer;
 import org.apache.solr.client.solrj.SolrServerException;
-import org.apache.solr.common.SolrInputDocument;
+import org.apache.solr.client.solrj.impl.HttpSolrServer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
 
+/**
+ *
+ *
+ *
+ */
+public abstract class SolrHandler implements Handler {
+
+    private SolrServer solrServer;
+    protected String solrUrl;
 
-public class SolrHandler implements Handler {
+    protected final static Logger logger = LoggerFactory.getLogger(SolrHandler.class);
 
-    private SolrServer solr;
 
-    @Override
-    public void handle(URI uri, ContentEntity entity)
-            throws IOException, DroidsException {
-        SolrInputDocument doc = createSolrInputDocument(uri, entity);
+    /**
+     * Constructor using a url to set up the connection
+     * to the solr server.
+     *
+     * @param solrUrl the url to the solr server
+     */
+    public SolrHandler(String solrUrl) {
+        this.setSolrUrl(solrUrl);
+    }
+
+    /**
+     * Constructor with the solr server.
+     *
+     * @param solrServer the solr server
+     */
+    public SolrHandler(SolrServer solrServer) {
+        this.solrServer = solrServer;
+    }
+
+
+    /**
+     * Clean the index with the provided query.
+     */
+    public void cleanUp(String query) {
         try {
-            solr.add(doc);
+            solrServer.deleteByQuery(query);
+            solrServer.optimize();
+            solrServer.commit();
         } catch (SolrServerException e) {
-            throw new DroidsException(e);
+            e.printStackTrace();
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+    }
+
+    /**
+     * Finish the handling by committing the data
+     * and optimizing the index.
+     */
+    public void finish() {
+        try {
+            solrServer.commit();
+            solrServer.optimize();
+        } catch (Exception e) {
+            e.printStackTrace();
         }
     }
 
-    public SolrInputDocument createSolrInputDocument(URI url, ContentEntity entity) {
-        SolrInputDocument doc = new SolrInputDocument();
-        doc.setField("id", url.getPath());
-        doc.setField("name", url.toASCIIString());
-        doc.setField("host", url.getHost());
-        doc.setField("mime", entity.getMimeType());
-        doc.setField("content", entity.getParse().getText());
-        return doc;
+    /**
+     * Checks the availability of the solr server.
+     *
+     * @return the availability
+     */
+    public boolean isSolrServerAvailable() throws IOException, SolrServerException {
+        boolean isAvailable = false;
+        if (solrServer.ping().getStatus() < 400) {
+            isAvailable = true;
+        }
+        return isAvailable;
+    }
+
+    /**
+     * Create a new SolrServer instance based on the solr url
+     */
+    private SolrServer createHttpSolrServer() {
+        SolrServer server = null;
+        if (solrUrl != null) {
+            server = new HttpSolrServer(solrUrl);
+            logger.info("created connection to solr server: " + solrUrl);
+        }
+        return server;
+    }
+
+    /**
+     * Set the solr server.
+     *
+     * @param solrServer the solr server
+     */
+    public void setSolrServer(SolrServer solrServer) {
+        this.solrServer = solrServer;
+    }
+
+    /**
+     * Get the solr server.
+     *
+     * @return the solr server instance
+     */
+    public SolrServer getSolrServer() {
+        return solrServer;
     }
+
+    /**
+     * Set the url of the solr server
+     *
+     * @param solrUrl the url of the solr server
+     */
+    public void setSolrUrl(String solrUrl) {
+        this.solrUrl = solrUrl;
+        this.solrServer = createHttpSolrServer();
+    }
+
+    /**
+     * Get the url of the solr server.
+     * Can also be null, if the solr server has no url.
+     *
+     * @return the solr url
+     */
+    public String getSolrUrl() {
+        return solrUrl;
+    }
+
 }
+
+

Added: incubator/droids/branches/0.2.x-cleanup/droids-solr/src/main/java/org/apache/droids/solr/SolrHandlerImpl.java
URL: http://svn.apache.org/viewvc/incubator/droids/branches/0.2.x-cleanup/droids-solr/src/main/java/org/apache/droids/solr/SolrHandlerImpl.java?rev=1461977&view=auto
==============================================================================
--- incubator/droids/branches/0.2.x-cleanup/droids-solr/src/main/java/org/apache/droids/solr/SolrHandlerImpl.java
(added)
+++ incubator/droids/branches/0.2.x-cleanup/droids-solr/src/main/java/org/apache/droids/solr/SolrHandlerImpl.java
Thu Mar 28 08:29:28 2013
@@ -0,0 +1,65 @@
+package org.apache.droids.solr;
+
+import org.apache.droids.core.DroidsException;
+import org.apache.droids.core.ParserData;
+import org.apache.droids.core.Task;
+import org.apache.solr.client.solrj.SolrServer;
+import org.apache.solr.client.solrj.SolrServerException;
+import org.apache.solr.common.SolrInputDocument;
+
+import java.io.IOException;
+
+/**
+ * Implementation of the SolrHandler for handling basic
+ * properties of the task
+ */
+public class SolrHandlerImpl extends SolrHandler {
+
+    public SolrHandlerImpl(String solrUrl) {
+        super(solrUrl);
+    }
+
+    public SolrHandlerImpl(SolrServer solrServer) {
+        super(solrServer);
+    }
+
+    @Override
+    public void handle(Task task) throws DroidsException, IOException {
+        try {
+            if (isSolrServerAvailable()) {
+                getSolrServer().add(createSolrInputDocument(task));
+            }
+        } catch (SolrServerException e) {
+            throw new DroidsException(e);
+        }
+
+    }
+
+    private SolrInputDocument createSolrInputDocument(Task task) {
+        SolrInputDocument doc = new SolrInputDocument();
+        doc.setField("id", task.getURI().getPath());
+        doc.setField("name", task.getURI().toASCIIString());
+        doc.setField("content", task.getParserData().getText());
+        doc.setField("contentType", task.getContentEntity().getContentType());
+        doc.setField("taskDate", task.getTaskDate());
+        doc.setField("depth", task.getDepth());
+        doc.setField("contentLength", task.getContentEntity().getContentLength());
+        doc.setField("charset", task.getContentEntity().getCharset());
+
+        ParserData parserData = task.getParserData();
+        for (String name : parserData.names()) {
+            Object[] values = parserData.getValues(name);
+            if (values.length > 1) {
+                doc.setField(name, parserData.getValues(name));
+            } else {
+                doc.setField(name, parserData.get(name));
+            }
+        }
+
+
+
+        return doc;
+    }
+
+
+}

Propchange: incubator/droids/branches/0.2.x-cleanup/droids-solr/src/main/java/org/apache/droids/solr/SolrHandlerImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/droids/branches/0.2.x-cleanup/droids-solr/src/main/java/org/apache/droids/solr/SolrHandlerImpl.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: incubator/droids/branches/0.2.x-cleanup/droids-solr/src/main/java/org/apache/droids/solr/SolrHandlerImpl.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: incubator/droids/branches/0.2.x-cleanup/droids-solr/src/test/java/org/apache/droids/solr/AdvancedSolrHandleTest.java
URL: http://svn.apache.org/viewvc/incubator/droids/branches/0.2.x-cleanup/droids-solr/src/test/java/org/apache/droids/solr/AdvancedSolrHandleTest.java?rev=1461977&r1=1461976&r2=1461977&view=diff
==============================================================================
--- incubator/droids/branches/0.2.x-cleanup/droids-solr/src/test/java/org/apache/droids/solr/AdvancedSolrHandleTest.java
(original)
+++ incubator/droids/branches/0.2.x-cleanup/droids-solr/src/test/java/org/apache/droids/solr/AdvancedSolrHandleTest.java
Thu Mar 28 08:29:28 2013
@@ -16,14 +16,15 @@
  */
 package org.apache.droids.solr;
 
+import java.io.ByteArrayInputStream;
 import java.io.IOException;
 import java.net.URI;
 import java.net.URISyntaxException;
 import java.util.HashMap;
 
-import junit.framework.TestCase;
-
-import org.apache.droids.exception.DroidsException;
+import org.apache.droids.core.ContentEntity;
+import org.apache.droids.core.DroidsException;
+import org.apache.droids.core.Task;
 import org.apache.solr.client.solrj.SolrQuery;
 import org.apache.solr.client.solrj.SolrServer;
 import org.apache.solr.client.solrj.SolrServerException;
@@ -31,11 +32,13 @@ import org.apache.solr.client.solrj.embe
 import org.apache.solr.client.solrj.response.QueryResponse;
 import org.apache.solr.common.SolrDocument;
 import org.apache.solr.core.CoreContainer;
-import org.apache.solr.core.CoreDescriptor;
-import org.apache.solr.core.SolrCore;
-import org.apache.solr.core.SolrResourceLoader;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.*;
 
-public class AdvancedSolrHandleTest extends TestCase {
+public class AdvancedSolrHandleTest {
 
     SolrServer solr;
 
@@ -59,19 +62,14 @@ public class AdvancedSolrHandleTest exte
         return "example";
     }
 
-    @Override
+    @Before
     public void setUp() throws Exception {
-        super.setUp();
-
-        SolrResourceLoader loader = new SolrResourceLoader(getSolrHome());
-        CoreContainer container = new CoreContainer(loader);
-        CoreDescriptor descriptor = new CoreDescriptor(container, "cname", ".");
-        SolrCore core = container.create(descriptor);
-        container.register(core.getName(), core, false);
-
-        solr = new EmbeddedSolrServer(container, core.getName());
+        CoreContainer.Initializer initializer = new CoreContainer.Initializer();
+        CoreContainer coreContainer = initializer.initialize();
+        solr = new EmbeddedSolrServer(coreContainer, "");
     }
 
+    @After
     public void tearDown() throws Exception {
         // remove everything....
         solr.deleteByQuery("*:*");
@@ -79,19 +77,20 @@ public class AdvancedSolrHandleTest exte
     }
 
     public void performSelection(String html, String field, String selector, String expectedValue)
throws IOException, DroidsException, URISyntaxException, SolrServerException {
-        AdvancedSolrHandler handler = new AdvancedSolrHandler();
-        handler.setServer(solr);
+        AdvancedSolrHandler handler = new AdvancedSolrHandler(solr);
 
         HashMap<String, String> selectors = new HashMap<String, String>();
         selectors.put(field, selector);
         handler.setSelectors(selectors);
 
-        MockContentEntity contentEntity = new MockContentEntity();
+        Task task = new SolrTask(new URI("http://localhost/"));
+
+        ContentEntity contentEntity = task.getContentEntity();
+        contentEntity.setContentType("text/html");
         contentEntity.setCharset("UTF-8");
-        contentEntity.setMimeType("text/html");
-        contentEntity.setText(html);
+        contentEntity.setContent(new ByteArrayInputStream(html.getBytes("UTF-8")));
 
-        handler.handle(new URI("http://localhost/"), contentEntity);
+        handler.handle(task);
         solr.commit();
 
         SolrQuery query = new SolrQuery();
@@ -105,14 +104,17 @@ public class AdvancedSolrHandleTest exte
         assertEquals(expectedValue, value);
     }
 
+    @Test
     public void testSelectorA() throws Exception {
         performSelection(simpleHtmlPage, "selector", "/html[0]/body[0]/div[0]/p[0]", "p0");
     }
 
+    @Test
     public void testSelectorB() throws Exception {
         performSelection(simpleHtmlPage, "selector", "/html[0]/body[0]/div[1]/p[1]", "p4");
     }
 
+    @Test
     public void testSelectorC() throws Exception {
         performSelection(simpleHtmlPage, "selector", "/html[0]/body[0]/div[1]", "p3p4p5");
     }

Modified: incubator/droids/branches/0.2.x-cleanup/droids-solr/src/test/java/org/apache/droids/solr/SolrHandleTest.java
URL: http://svn.apache.org/viewvc/incubator/droids/branches/0.2.x-cleanup/droids-solr/src/test/java/org/apache/droids/solr/SolrHandleTest.java?rev=1461977&r1=1461976&r2=1461977&view=diff
==============================================================================
--- incubator/droids/branches/0.2.x-cleanup/droids-solr/src/test/java/org/apache/droids/solr/SolrHandleTest.java
(original)
+++ incubator/droids/branches/0.2.x-cleanup/droids-solr/src/test/java/org/apache/droids/solr/SolrHandleTest.java
Thu Mar 28 08:29:28 2013
@@ -16,60 +16,43 @@
  */
 package org.apache.droids.solr;
 
-import junit.framework.TestCase;
-
+import org.apache.droids.core.Task;
 import org.apache.solr.client.solrj.SolrQuery;
 import org.apache.solr.client.solrj.SolrServer;
 import org.apache.solr.client.solrj.embedded.EmbeddedSolrServer;
-import org.apache.solr.common.SolrInputDocument;
 import org.apache.solr.core.CoreContainer;
-import org.apache.solr.core.CoreDescriptor;
-import org.apache.solr.core.SolrCore;
-import org.apache.solr.core.SolrResourceLoader;
-
-public class SolrHandleTest extends TestCase {
+import org.junit.Test;
+import org.xml.sax.SAXException;
 
-    SolrServer solr;
+import javax.xml.parsers.ParserConfigurationException;
+import java.io.IOException;
+import java.net.URI;
 
-    protected String getSolrHome() {
-        return "example";
-    }
+import static junit.framework.Assert.assertEquals;
 
-    @Override
-    public void setUp() throws Exception {
-        super.setUp();
-
-        SolrResourceLoader loader = new SolrResourceLoader(getSolrHome());
-        CoreContainer container = new CoreContainer(loader);
-        CoreDescriptor descriptor = new CoreDescriptor(container,
-                "cname", ".");
-        SolrCore core = container.create(descriptor);
-        container.register(core.getName(), core, false);
+public class SolrHandleTest {
 
-        solr = new EmbeddedSolrServer(container, core.getName());
-    }
+    SolrHandler solrHandler;
 
-    public void tearDown() throws Exception {
-        // remove everything....
-        solr.deleteByQuery("*:*");
-        solr.commit();
+    public SolrHandleTest() throws ParserConfigurationException, SAXException, IOException
{
+        CoreContainer.Initializer initializer = new CoreContainer.Initializer();
+        CoreContainer coreContainer = initializer.initialize();
+        SolrServer solr = new EmbeddedSolrServer(coreContainer, "");
+        solrHandler = new SolrHandlerImpl(solr);
     }
 
-    public void testHello() throws Exception {
-        SolrInputDocument doc = new SolrInputDocument();
-        doc.addField("id", "aaaa");
-        solr.add(doc);
-        solr.commit();
 
-        assertEquals(1, solr.query(new SolrQuery("*:*")).getResults().getNumFound());
-    }
+    @Test
+    public void testHandling() throws Exception {
+        Task task = new SolrTask(new URI("http://localhost/"));
+        solrHandler.handle(task);
+        assertEquals(0, solrHandler.getSolrServer().query(new SolrQuery("*:*")).getResults().getNumFound());
+        solrHandler.finish();
+        assertEquals(1, solrHandler.getSolrServer().query(new SolrQuery("*:*")).getResults().getNumFound());
 
-    public void testAfter() throws Exception {
-        SolrInputDocument doc = new SolrInputDocument();
-        doc.addField("id", "bbbb");
-        solr.add(doc);
-        solr.commit();
 
-        assertEquals(1, solr.query(new SolrQuery("*:*")).getResults().getNumFound());
+        solrHandler.cleanUp("*:*");
+        assertEquals(0, solrHandler.getSolrServer().query(new SolrQuery("*:*")).getResults().getNumFound());
     }
+
 }
\ No newline at end of file

Added: incubator/droids/branches/0.2.x-cleanup/droids-solr/src/test/java/org/apache/droids/solr/SolrTask.java
URL: http://svn.apache.org/viewvc/incubator/droids/branches/0.2.x-cleanup/droids-solr/src/test/java/org/apache/droids/solr/SolrTask.java?rev=1461977&view=auto
==============================================================================
--- incubator/droids/branches/0.2.x-cleanup/droids-solr/src/test/java/org/apache/droids/solr/SolrTask.java
(added)
+++ incubator/droids/branches/0.2.x-cleanup/droids-solr/src/test/java/org/apache/droids/solr/SolrTask.java
Thu Mar 28 08:29:28 2013
@@ -0,0 +1,70 @@
+package org.apache.droids.solr;
+
+import org.apache.droids.core.ContentEntity;
+import org.apache.droids.core.ParserData;
+import org.apache.droids.core.Task;
+
+import java.net.URI;
+import java.util.Date;
+
+public class SolrTask implements Task {
+    private URI uri;
+    private ContentEntity contentEntity;
+    private ParserData parserData;
+    private int depth;
+    private Date taskDate;
+    private boolean abort;
+
+    public SolrTask(URI uri) {
+        this(uri, 0);
+    }
+
+    public SolrTask(URI uri, int depth) {
+        this.uri = uri;
+        this.depth = depth;
+        this.taskDate = new Date();
+        this.contentEntity = new ContentEntity();
+        this.parserData = new ParserData();
+    }
+
+    @Override
+    public URI getURI() {
+        return uri;
+    }
+
+    @Override
+    public ContentEntity getContentEntity() {
+        return contentEntity;
+    }
+
+    @Override
+    public ParserData getParserData() {
+        return parserData;
+    }
+
+    @Override
+    public int getDepth() {
+        return depth;
+    }
+
+    @Override
+    public Date getTaskDate() {
+        return taskDate;
+    }
+
+    @Override
+    public void abort() {
+        abort = true;
+    }
+
+    @Override
+    public boolean isAborted() {
+        return abort;
+    }
+
+    @SuppressWarnings("unchecked")
+    @Override
+    public Task createTask(URI uri) {
+        return new SolrTask(uri);
+    }
+}

Propchange: incubator/droids/branches/0.2.x-cleanup/droids-solr/src/test/java/org/apache/droids/solr/SolrTask.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/droids/branches/0.2.x-cleanup/droids-solr/src/test/java/org/apache/droids/solr/SolrTask.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: incubator/droids/branches/0.2.x-cleanup/droids-solr/src/test/java/org/apache/droids/solr/SolrTask.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: incubator/droids/branches/0.2.x-cleanup/droids-solr/src/test/resources/example/conf/schema.xml
URL: http://svn.apache.org/viewvc/incubator/droids/branches/0.2.x-cleanup/droids-solr/src/test/resources/example/conf/schema.xml?rev=1461977&r1=1461504&r2=1461977&view=diff
==============================================================================
--- incubator/droids/branches/0.2.x-cleanup/droids-solr/src/test/resources/example/conf/schema.xml
(original)
+++ incubator/droids/branches/0.2.x-cleanup/droids-solr/src/test/resources/example/conf/schema.xml
Thu Mar 28 08:29:28 2013
@@ -63,10 +63,16 @@
     <fields>
         <field name="id" type="string" indexed="true" stored="true" required="true"/>
         <field name="name" type="string" indexed="true" stored="true"/>
-        <field name="host" type="string" indexed="true" stored="true"/>
         <field name="mime" type="string" indexed="true" stored="true"/>
         <field name="content" type="text" indexed="true" stored="true"/>
+        <field name="contentType" type="string" indexed="true" stored="true"/>
         <field name="selector" type="text" indexed="true" stored="true"/>
+        <field name="taskDate" type="date" indexed="true" stored="true"/>
+        <field name="depth" type="integer" indexed="true" stored="true"/>
+        <field name="contentLength" type="long" indexed="true" stored="true"/>
+        <field name="charset" type="string" indexed="true" stored="true"/>
+
+
 
     </fields>
 

Modified: incubator/droids/branches/0.2.x-cleanup/droids-solr/src/test/resources/example/conf/solrconfig.xml
URL: http://svn.apache.org/viewvc/incubator/droids/branches/0.2.x-cleanup/droids-solr/src/test/resources/example/conf/solrconfig.xml?rev=1461977&r1=1461504&r2=1461977&view=diff
==============================================================================
--- incubator/droids/branches/0.2.x-cleanup/droids-solr/src/test/resources/example/conf/solrconfig.xml
(original)
+++ incubator/droids/branches/0.2.x-cleanup/droids-solr/src/test/resources/example/conf/solrconfig.xml
Thu Mar 28 08:29:28 2013
@@ -171,7 +171,7 @@
       -->
     <requestDispatcher handleSelect="true"/>
 
-    <requestHandler name="standard" class="solr.SearchHandler" default="true">
+    <requestHandler name="search" class="solr.SearchHandler" default="true">
         <!-- default values for query parameters -->
         <lst name="defaults">
             <str name="echoParams">explicit</str>
@@ -186,5 +186,13 @@
 
     <requestHandler name="/update" class="solr.XmlUpdateRequestHandler"/>
     <requestHandler name="/admin/" class="org.apache.solr.handler.admin.AdminHandlers"/>
+    <!-- ping/healthcheck -->
+    <requestHandler name="/admin/ping" class="solr.PingRequestHandler">
+        <lst name="defaults">
+            <str name="qt">search</str>
+            <str name="q">solrpingquery</str>
+            <str name="echoParams">all</str>
+        </lst>
+    </requestHandler>
 
 </config>

Added: incubator/droids/branches/0.2.x-cleanup/droids-solr/src/test/resources/logback.xml
URL: http://svn.apache.org/viewvc/incubator/droids/branches/0.2.x-cleanup/droids-solr/src/test/resources/logback.xml?rev=1461977&view=auto
==============================================================================
--- incubator/droids/branches/0.2.x-cleanup/droids-solr/src/test/resources/logback.xml (added)
+++ incubator/droids/branches/0.2.x-cleanup/droids-solr/src/test/resources/logback.xml Thu
Mar 28 08:29:28 2013
@@ -0,0 +1,17 @@
+<configuration>
+
+    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
+        <!-- encoders are assigned the type
+             ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
+        <encoder>
+            <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
+        </encoder>
+    </appender>
+
+    <logger name="org.apache.droids" level="info"/>
+
+
+    <root level="error">
+        <appender-ref ref="STDOUT"/>
+    </root>
+</configuration>
\ No newline at end of file

Propchange: incubator/droids/branches/0.2.x-cleanup/droids-solr/src/test/resources/logback.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/droids/branches/0.2.x-cleanup/droids-solr/src/test/resources/logback.xml
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: incubator/droids/branches/0.2.x-cleanup/droids-solr/src/test/resources/logback.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml



Mime
View raw message