SOLR-5190: SolrEntityProcessor substitutes variables only once in child entities

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1518161 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Shalin Shekhar Mangar 2013-08-28 11:20:56 +00:00
parent 082f6e4d2e
commit 2dc5b2a02c
3 changed files with 30 additions and 21 deletions

View File

@ -155,6 +155,9 @@ Bug Fixes
* SOLR-5112: Show full message in Admin UI Logging View (Matthew Keeney via
steffkes)
* SOLR-5190: SolrEntityProcessor substitutes variables only once in child entities
(Harsh Chawla, shalin)
Optimizations
----------------------

View File

@ -71,8 +71,6 @@ public class SolrEntityProcessor extends EntityProcessorBase {
private String[] fields;
private String requestHandler;// 'qt' param
private int timeout = TIMEOUT_SECS;
private boolean initDone = false;
/**
* Factory method that returns a {@link HttpClient} instance used for interfacing with a source Solr service.
@ -122,28 +120,22 @@ public class SolrEntityProcessor extends EntityProcessorBase {
* external synchronization.
*/
private void buildIterator() {
if (rowIterator == null) {
// We could use an AtomicBoolean but there's no need since this method
// would require anyway external synchronization
if (!initDone) {
initDone = true;
SolrDocumentList solrDocumentList = doQuery(0);
if (rowIterator != null) {
SolrDocumentListIterator documentListIterator = (SolrDocumentListIterator) rowIterator;
if (!documentListIterator.hasNext() && documentListIterator.hasMoreRows()) {
SolrDocumentList solrDocumentList = doQuery(documentListIterator
.getStart() + documentListIterator.getSize());
if (solrDocumentList != null) {
rowIterator = new SolrDocumentListIterator(solrDocumentList);
}
}
return;
}
SolrDocumentListIterator documentListIterator = (SolrDocumentListIterator) rowIterator;
if (!documentListIterator.hasNext() && documentListIterator.hasMoreRows()) {
SolrDocumentList solrDocumentList = doQuery(documentListIterator
.getStart() + documentListIterator.getSize());
} else {
SolrDocumentList solrDocumentList = doQuery(0);
if (solrDocumentList != null) {
rowIterator = new SolrDocumentListIterator(solrDocumentList);
}
return;
}
}
protected SolrDocumentList doQuery(int start) {

View File

@ -62,7 +62,7 @@ public class TestSolrEntityProcessorEndToEnd extends AbstractDataImportHandlerTe
dbDoc.put("dbid_s", "1");
dbDoc.put("dbdesc_s", "DbDescription");
DB_DOCS.add(dbDoc);
Map<String,Object> solrDoc = new HashMap<String,Object>();
solrDoc.put("id", "1");
solrDoc.put("desc", "SolrDescription");
@ -202,8 +202,19 @@ public class TestSolrEntityProcessorEndToEnd extends AbstractDataImportHandlerTe
assertQ(req("*:*"), "//result[@numFound='0']");
try {
MockDataSource.setIterator("select * from x", DB_DOCS.iterator());
addDocumentsToSolr(SOLR_DOCS);
List<Map<String,Object>> DOCS = new ArrayList<Map<String,Object>>(DB_DOCS);
Map<String, Object> doc = new HashMap<String, Object>();
doc.put("dbid_s", "2");
doc.put("dbdesc_s", "DbDescription2");
DOCS.add(doc);
MockDataSource.setIterator("select * from x", DOCS.iterator());
DOCS = new ArrayList<Map<String,Object>>(SOLR_DOCS);
Map<String,Object> solrDoc = new HashMap<String,Object>();
solrDoc.put("id", "2");
solrDoc.put("desc", "SolrDescription2");
DOCS.add(solrDoc);
addDocumentsToSolr(DOCS);
runFullImport(getDihConfigTagsInnerEntity());
} catch (Exception e) {
LOG.error(e.getMessage(), e);
@ -212,12 +223,15 @@ public class TestSolrEntityProcessorEndToEnd extends AbstractDataImportHandlerTe
MockDataSource.clearCache();
}
assertQ(req("*:*"), "//result[@numFound='1']");
assertQ(req("*:*"), "//result[@numFound='2']");
assertQ(req("id:1"), "//result/doc/str[@name='id'][.='1']",
"//result/doc/str[@name='dbdesc_s'][.='DbDescription']",
"//result/doc/str[@name='dbid_s'][.='1']",
"//result/doc/arr[@name='desc'][.='SolrDescription']");
assertQ(req("id:2"), "//result/doc/str[@name='id'][.='2']",
"//result/doc/str[@name='dbdesc_s'][.='DbDescription2']",
"//result/doc/str[@name='dbid_s'][.='2']",
"//result/doc/arr[@name='desc'][.='SolrDescription2']");
}
public void testFullImportWrongSolrUrl() {