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,20 +18,25 @@ package org.apache.solr.handler.dataimport;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.Test; 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 /**Testcase for TikaEntityProcessor
* *
* @since solr 1.5 * @since solr 3.1
*/ */
public class TestTikaEntityProcessor extends AbstractDataImportHandlerTestCase { public class TestTikaEntityProcessor extends AbstractDataImportHandlerTestCase {
@BeforeClass private String conf =
public static void beforeClass() throws Exception {
initCore("dataimport-solrconfig.xml", "dataimport-schema-no-unique-key.xml", getFile("solr-dihextras").getAbsolutePath());
}
@Test
public void testIndexingWithTikaEntityProcessor() throws Exception {
String conf =
"<dataConfig>" + "<dataConfig>" +
" <dataSource type=\"BinFileDataSource\"/>" + " <dataSource type=\"BinFileDataSource\"/>" +
" <document>" + " <document>" +
@ -42,12 +47,37 @@ public class TestTikaEntityProcessor extends AbstractDataImportHandlerTestCase {
" </entity>" + " </entity>" +
" </document>" + " </document>" +
"</dataConfig>"; "</dataConfig>";
runFullImport(conf);
assertQ(req("*:*") private String[] tests = {
,"//*[@numFound='1']" "//*[@numFound='1']"
,"//str[@name='author'][.='Grant Ingersoll']" ,"//str[@name='author'][.='Grant Ingersoll']"
,"//str[@name='title'][.='solr-word']" ,"//str[@name='title'][.='solr-word']"
,"//str[@name='text']" ,"//str[@name='text']"
); };
@BeforeClass
public static void beforeClass() throws Exception {
initCore("dataimport-solrconfig.xml", "dataimport-schema-no-unique-key.xml", getFile("solr-dihextras").getAbsolutePath());
} }
@Test
public void testIndexingWithTikaEntityProcessor() throws Exception {
runFullImport(conf);
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-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-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 ================== ================== 3.3.0 ==================

View File

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

View File

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