SOLR-2186 -- DataImportHandler's multi-threaded option throws NPE

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1147023 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Shalin Shekhar Mangar 2011-07-15 08:41:26 +00:00
parent 2e14617e19
commit 80d436e29f
4 changed files with 52 additions and 21 deletions

View File

@ -18,12 +18,44 @@ package org.apache.solr.handler.dataimport;
import org.junit.BeforeClass;
import org.junit.Test;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.xml.sax.InputSource;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import java.io.StringReader;
import java.io.StringWriter;
/**Testcase for TikaEntityProcessor
*
* @since solr 1.5
* @since solr 3.1
*/
public class TestTikaEntityProcessor extends AbstractDataImportHandlerTestCase {
private String conf =
"<dataConfig>" +
" <dataSource type=\"BinFileDataSource\"/>" +
" <document>" +
" <entity processor=\"TikaEntityProcessor\" url=\"" + getFile("solr-word.pdf").getAbsolutePath() + "\" >" +
" <field column=\"Author\" meta=\"true\" name=\"author\"/>" +
" <field column=\"title\" meta=\"true\" name=\"title\"/>" +
" <field column=\"text\"/>" +
" </entity>" +
" </document>" +
"</dataConfig>";
private String[] tests = {
"//*[@numFound='1']"
,"//str[@name='author'][.='Grant Ingersoll']"
,"//str[@name='title'][.='solr-word']"
,"//str[@name='text']"
};
@BeforeClass
public static void beforeClass() throws Exception {
initCore("dataimport-solrconfig.xml", "dataimport-schema-no-unique-key.xml", getFile("solr-dihextras").getAbsolutePath());
@ -31,23 +63,21 @@ public class TestTikaEntityProcessor extends AbstractDataImportHandlerTestCase {
@Test
public void testIndexingWithTikaEntityProcessor() throws Exception {
String conf =
"<dataConfig>" +
" <dataSource type=\"BinFileDataSource\"/>" +
" <document>" +
" <entity processor=\"TikaEntityProcessor\" url=\"" + getFile("solr-word.pdf").getAbsolutePath() + "\" >" +
" <field column=\"Author\" meta=\"true\" name=\"author\"/>" +
" <field column=\"title\" meta=\"true\" name=\"title\"/>" +
" <field column=\"text\"/>" +
" </entity>" +
" </document>" +
"</dataConfig>";
runFullImport(conf);
assertQ(req("*:*")
,"//*[@numFound='1']"
,"//str[@name='author'][.='Grant Ingersoll']"
,"//str[@name='title'][.='solr-word']"
,"//str[@name='text']"
);
assertQ(req("*:*"), tests );
}
@Test
public void testIndexingWithTikaEntityProcessorThreaded() throws Exception {
DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document doc = builder.parse(new InputSource(new StringReader(conf)));
((Element) doc.getElementsByTagName("entity").item(0)).setAttribute("threads", "1");
Transformer trans = TransformerFactory.newInstance().newTransformer();
StringWriter writer = new StringWriter();
trans.transform(new DOMSource(doc), new StreamResult(writer));
runFullImport(writer.toString());
assertQ(req("*:*"), tests );
}
}

View File

@ -18,6 +18,7 @@ Bug Fixes
----------------------
* SOLR-2644: When using threads=2 the default logging is set too high (Bill Bell via shalin)
* SOLR-2492: DIH does not commit if only deletes are processed (James Dyer via shalin)
* SOLR-2186: DataImportHandler's multi-threaded option throws NPE (Lance Norskog, Frank Wesemann, shalin)
================== 3.3.0 ==================

View File

@ -33,7 +33,7 @@ import java.util.concurrent.ConcurrentHashMap;
* @since solr 1.3
*/
public class ContextImpl extends Context {
private DataConfig.Entity entity;
protected DataConfig.Entity entity;
private ContextImpl parent;

View File

@ -28,7 +28,7 @@ public class ThreadedContext extends ContextImpl{
public ThreadedContext(DocBuilder.EntityRunner entityRunner, DocBuilder docBuilder) {
super(entityRunner.entity,
null,//to be fethed realtime
null,//to be fetched realtime
null,
null,
docBuilder.session,
@ -75,7 +75,7 @@ public class ThreadedContext extends ContextImpl{
@Override
public String getResolvedEntityAttribute(String name) {
checkLimited();
return super.getResolvedEntityAttribute(name);
return entity == null ? null : getVariableResolver().replaceTokens(entity.allAttributes.get(name));
}
@Override