SOLR-2057: DataImportHandler never calls UpdateRequestProcessor.finish()

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1030098 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Koji Sekiguchi 2010-11-02 16:09:05 +00:00
parent 56583c70ab
commit 5b27b08048
8 changed files with 128 additions and 1 deletions

View File

@ -540,6 +540,9 @@ Bug Fixes
* SOLR-2190: change xpath from RSS 0.9 to 1.0 in slashdot sample. (koji)
* SOLR-1962: SolrCore#initIndex should not use a mix of indexPath and newIndexPath (Mark Miller)
* SOLR-2057: DataImportHandler never calls UpdateRequestProcessor.finish()
(Drew Farris via koji)
Other Changes
----------------------

View File

@ -205,6 +205,11 @@ public class DocBuilder {
// Finished operation normally, commit now
finish(lastIndexTimeProps);
}
if (writer != null) {
writer.finish();
}
if (document.onImportEnd != null) {
invokeEventListener(document.onImportEnd);
}

View File

@ -125,6 +125,15 @@ public class SolrWriter {
}
}
void finish() {
try {
processor.finish();
} catch (IOException e) {
throw new DataImportHandlerException(DataImportHandlerException.SEVERE,
"Unable to call finish() on UpdateRequestProcessor", e);
}
}
Properties readIndexerProperties() {
Properties props = new Properties();
InputStream propInput = null;

View File

@ -19,6 +19,15 @@ package org.apache.solr.handler.dataimport;
import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.core.SolrCore;
import org.apache.solr.request.LocalSolrQueryRequest;
import org.apache.solr.request.SolrQueryRequest;
import org.apache.solr.response.SolrQueryResponse;
import org.apache.solr.update.AddUpdateCommand;
import org.apache.solr.update.CommitUpdateCommand;
import org.apache.solr.update.DeleteUpdateCommand;
import org.apache.solr.update.MergeIndexesCommand;
import org.apache.solr.update.RollbackUpdateCommand;
import org.apache.solr.update.processor.UpdateRequestProcessor;
import org.apache.solr.update.processor.UpdateRequestProcessorFactory;
import org.apache.solr.common.util.NamedList;
import org.junit.After;
import org.junit.Before;
@ -270,4 +279,69 @@ public abstract class AbstractDataImportHandlerTestCase extends
return delegate.replaceTokens(template);
}
}
public static class TestUpdateRequestProcessorFactory extends UpdateRequestProcessorFactory {
@Override
public UpdateRequestProcessor getInstance(SolrQueryRequest req,
SolrQueryResponse rsp, UpdateRequestProcessor next) {
return new TestUpdateRequestProcessor(next);
}
}
public static class TestUpdateRequestProcessor extends UpdateRequestProcessor {
public static boolean finishCalled = false;
public static boolean processAddCalled = false;
public static boolean processCommitCalled = false;
public static boolean processDeleteCalled = false;
public static boolean mergeIndexesCalled = false;
public static boolean rollbackCalled = false;
public static void reset() {
finishCalled = false;
processAddCalled = false;
processCommitCalled = false;
processDeleteCalled = false;
mergeIndexesCalled = false;
rollbackCalled = false;
}
public TestUpdateRequestProcessor(UpdateRequestProcessor next) {
super(next);
reset();
}
public void finish() throws IOException {
finishCalled = true;
super.finish();
}
public void processAdd(AddUpdateCommand cmd) throws IOException {
processAddCalled = true;
super.processAdd(cmd);
}
public void processCommit(CommitUpdateCommand cmd) throws IOException {
processCommitCalled = true;
super.processCommit(cmd);
}
public void processDelete(DeleteUpdateCommand cmd) throws IOException {
processDeleteCalled = true;
super.processDelete(cmd);
}
public void processMergeIndexes(MergeIndexesCommand cmd) throws IOException {
mergeIndexesCalled = true;
super.processMergeIndexes(cmd);
}
public void processRollback(RollbackUpdateCommand cmd) throws IOException {
rollbackCalled = true;
super.processRollback(cmd);
}
}
}

View File

@ -60,6 +60,7 @@ public class TestDocBuilder extends AbstractDataImportHandlerTestCase {
di.runCmd(rp, swi);
assertEquals(Boolean.TRUE, swi.deleteAllCalled);
assertEquals(Boolean.TRUE, swi.commitCalled);
assertEquals(Boolean.TRUE, swi.finishCalled);
assertEquals(0, swi.docs.size());
assertEquals(1, di.getDocBuilder().importStatistics.queryCount.get());
assertEquals(0, di.getDocBuilder().importStatistics.docCount.get());
@ -81,6 +82,7 @@ public class TestDocBuilder extends AbstractDataImportHandlerTestCase {
di.runCmd(rp, swi);
assertEquals(Boolean.FALSE, swi.deleteAllCalled);
assertEquals(Boolean.FALSE, swi.commitCalled);
assertEquals(Boolean.TRUE, swi.finishCalled);
assertEquals(0, swi.docs.size());
assertEquals(1, di.getDocBuilder().importStatistics.queryCount.get());
assertEquals(0, di.getDocBuilder().importStatistics.docCount.get());
@ -104,6 +106,7 @@ public class TestDocBuilder extends AbstractDataImportHandlerTestCase {
di.runCmd(rp, swi);
assertEquals(Boolean.TRUE, swi.deleteAllCalled);
assertEquals(Boolean.TRUE, swi.commitCalled);
assertEquals(Boolean.TRUE, swi.finishCalled);
assertEquals(1, swi.docs.size());
assertEquals(1, di.getDocBuilder().importStatistics.queryCount.get());
assertEquals(1, di.getDocBuilder().importStatistics.docCount.get());
@ -134,6 +137,7 @@ public class TestDocBuilder extends AbstractDataImportHandlerTestCase {
di.runCmd(rp, swi);
assertEquals(Boolean.FALSE, swi.deleteAllCalled);
assertEquals(Boolean.TRUE, swi.commitCalled);
assertEquals(Boolean.TRUE, swi.finishCalled);
assertEquals(1, swi.docs.size());
assertEquals(1, di.getDocBuilder().importStatistics.queryCount.get());
assertEquals(1, di.getDocBuilder().importStatistics.docCount.get());
@ -168,6 +172,7 @@ public class TestDocBuilder extends AbstractDataImportHandlerTestCase {
di.runCmd(rp, swi);
assertEquals(Boolean.TRUE, swi.deleteAllCalled);
assertEquals(Boolean.TRUE, swi.commitCalled);
assertEquals(Boolean.TRUE, swi.finishCalled);
assertEquals(3, swi.docs.size());
for (int i = 0; i < l.size(); i++) {
Map<String, Object> map = (Map<String, Object>) l.get(i);
@ -189,6 +194,8 @@ public class TestDocBuilder extends AbstractDataImportHandlerTestCase {
Boolean commitCalled = Boolean.FALSE;
Boolean finishCalled = Boolean.FALSE;
public SolrWriterImpl() {
super(null, ".");
}
@ -208,6 +215,10 @@ public class TestDocBuilder extends AbstractDataImportHandlerTestCase {
public void commit(boolean b) {
commitCalled = Boolean.TRUE;
}
public void finish() {
finishCalled = Boolean.TRUE;
}
}
public static final String dc_singleEntity = "<dataConfig>\n"

View File

@ -52,6 +52,10 @@ public class TestDocBuilder2 extends AbstractDataImportHandlerTestCase {
runFullImport(loadDataConfig("single-entity-data-config.xml"));
assertQ(req("id:1"), "//*[@numFound='1']");
assertTrue("Update request processor processAdd was not called", TestUpdateRequestProcessor.processAddCalled);
assertTrue("Update request processor processCommit was not callled", TestUpdateRequestProcessor.processCommitCalled);
assertTrue("Update request processor finish was not called", TestUpdateRequestProcessor.finishCalled);
}
@Test
@ -66,6 +70,8 @@ public class TestDocBuilder2 extends AbstractDataImportHandlerTestCase {
assertQ(req("id:1"), "//*[@numFound='1']");
assertTrue("Start event listener was not called", StartEventListener.executed);
assertTrue("End event listener was not called", EndEventListener.executed);
assertTrue("Update request processor processAdd was not called", TestUpdateRequestProcessor.processAddCalled);
assertTrue("Update request processor finish was not called", TestUpdateRequestProcessor.finishCalled);
}
@Test
@ -200,6 +206,9 @@ public class TestDocBuilder2 extends AbstractDataImportHandlerTestCase {
assertQ(req("id:2"), "//*[@numFound='0']");
assertQ(req("id:3"), "//*[@numFound='1']");
assertTrue("Update request processor processDelete was not called", TestUpdateRequestProcessor.processDeleteCalled);
assertTrue("Update request processor finish was not called", TestUpdateRequestProcessor.finishCalled);
MockDataSource.clearCache();
rows = new ArrayList();
rows.add(createMap("id", "1", "desc", "one"));
@ -212,6 +221,10 @@ public class TestDocBuilder2 extends AbstractDataImportHandlerTestCase {
assertQ(req("id:1"), "//*[@numFound='0']");
assertQ(req("id:2"), "//*[@numFound='0']");
assertQ(req("id:3"), "//*[@numFound='1']");
assertTrue("Update request processor processDelete was not called", TestUpdateRequestProcessor.processDeleteCalled);
assertTrue("Update request processor finish was not called", TestUpdateRequestProcessor.finishCalled);
}
@Test

View File

@ -385,7 +385,7 @@
<str name="update.processor.class">org.apache.solr.handler.UpdateRequestProcessor</str>
-->
</requestHandler>
<!-- config for the admin interface -->
<admin>
<defaultQuery>*:*</defaultQuery>
@ -395,5 +395,11 @@
-->
</admin>
<updateRequestProcessorChain key="contentstream" default="true">
<processor class="org.apache.solr.handler.dataimport.AbstractDataImportHandlerTestCase$TestUpdateRequestProcessorFactory"/>
<processor class="solr.RunUpdateProcessorFactory"/>
<processor class="solr.LogUpdateProcessorFactory"/>
</updateRequestProcessorChain>
</config>

View File

@ -391,5 +391,11 @@
-->
</admin>
<updateRequestProcessorChain key="dataimport" default="true">
<processor class="org.apache.solr.handler.dataimport.AbstractDataImportHandlerTestCase$TestUpdateRequestProcessorFactory"/>
<processor class="solr.RunUpdateProcessorFactory"/>
<processor class="solr.LogUpdateProcessorFactory"/>
</updateRequestProcessorChain>
</config>