mirror of https://github.com/apache/lucene.git
SOLR-6845: Suggester tests start new cores instead of reloading
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1653784 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
d921424a9c
commit
8c50bc2fde
|
@ -129,8 +129,10 @@ public class SolrSuggester implements Accountable {
|
|||
}
|
||||
if (!storeDir.exists()) {
|
||||
storeDir.mkdirs();
|
||||
} else {
|
||||
// attempt reload of the stored lookup
|
||||
} else if (getStoreFile().exists()) {
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("attempt reload of the stored lookup from file " + getStoreFile());
|
||||
}
|
||||
try {
|
||||
lookup.load(new FileInputStream(getStoreFile()));
|
||||
} catch (IOException e) {
|
||||
|
@ -155,7 +157,7 @@ public class SolrSuggester implements Accountable {
|
|||
|
||||
/** Build the underlying Lucene Suggester */
|
||||
public void build(SolrCore core, SolrIndexSearcher searcher) throws IOException {
|
||||
LOG.info("build()");
|
||||
LOG.info("build(" + name + ")");
|
||||
|
||||
dictionary = dictionaryFactory.create(core, searcher);
|
||||
lookup.build(dictionary);
|
||||
|
@ -171,7 +173,7 @@ public class SolrSuggester implements Accountable {
|
|||
|
||||
/** Reloads the underlying Lucene Suggester */
|
||||
public void reload(SolrCore core, SolrIndexSearcher searcher) throws IOException {
|
||||
LOG.info("reload()");
|
||||
LOG.info("reload(" + name + ")");
|
||||
if (dictionary == null && storeDir != null) {
|
||||
File lookupFile = getStoreFile();
|
||||
if (lookupFile.exists()) {
|
||||
|
|
|
@ -42,6 +42,11 @@ public class SuggestComponentTest extends SolrTestCaseJ4 {
|
|||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
|
||||
assertQ(req("qt", "standard",
|
||||
"q", "*:*"),
|
||||
"//*[@numFound='0']"
|
||||
);
|
||||
|
||||
// id, cat, price, weight
|
||||
assertU(adoc("id", "0", "cat", "This is a title", "price", "5", "weight", "10"));
|
||||
assertU(adoc("id", "1", "cat", "This is another title", "price", "10", "weight", "10"));
|
||||
|
@ -55,13 +60,13 @@ public class SuggestComponentTest extends SolrTestCaseJ4 {
|
|||
assertU(adoc("id", "9", "cat", "blah in blah", "price", "50", "weight", "40"));
|
||||
assertU(adoc("id", "10", "cat", "another blah in blah", "price", "55", "weight", "40"));
|
||||
assertU((commit()));
|
||||
waitForWarming();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tearDown() throws Exception {
|
||||
super.tearDown();
|
||||
assertU(delQ("*:*"));
|
||||
optimize();
|
||||
assertU((commit()));
|
||||
// rebuild suggesters with empty index
|
||||
assertQ(req("qt", rh,
|
||||
|
@ -223,7 +228,7 @@ public class SuggestComponentTest extends SolrTestCaseJ4 {
|
|||
"//lst[@name='suggest']/lst[@name='" + suggester + "']/lst[@name='example']/int[@name='numFound'][.='2']"
|
||||
);
|
||||
|
||||
// add one more doc, this should not be seen after a core reload (not until the suggester is manually rebuilt)
|
||||
// add one more doc, should be visible after core reload
|
||||
assertU(adoc("id", "10", "cat", "example data extra ", "price", "40", "weight", "35"));
|
||||
assertU((commit()));
|
||||
|
||||
|
@ -450,7 +455,7 @@ public class SuggestComponentTest extends SolrTestCaseJ4 {
|
|||
}
|
||||
|
||||
private void reloadCore(boolean createNewCore) throws Exception {
|
||||
if (createNewCore) {
|
||||
// if (createNewCore) {
|
||||
CoreContainer cores = h.getCoreContainer();
|
||||
SolrCore core = h.getCore();
|
||||
String dataDir1 = core.getDataDir();
|
||||
|
@ -459,13 +464,25 @@ public class SuggestComponentTest extends SolrTestCaseJ4 {
|
|||
SolrCore createdCore = cores.create(cd);
|
||||
assertEquals(dataDir1, createdCore.getDataDir());
|
||||
assertEquals(createdCore, h.getCore());
|
||||
} else {
|
||||
h.reload();
|
||||
// On regular reloading, wait until the new searcher is registered
|
||||
// } else {
|
||||
// h.reload();
|
||||
// // On regular reloading, wait until the new searcher is registered
|
||||
// waitForWarming();
|
||||
// }
|
||||
|
||||
assertQ(req("qt", "standard",
|
||||
"q", "*:*"),
|
||||
"//*[@numFound='11']"
|
||||
);
|
||||
}
|
||||
|
||||
private void waitForWarming() throws InterruptedException {
|
||||
RefCounted<SolrIndexSearcher> registeredSearcher = h.getCore().getRegisteredSearcher();
|
||||
RefCounted<SolrIndexSearcher> newestSearcher = h.getCore().getNewestSearcher(false);;
|
||||
while (registeredSearcher.get() != newestSearcher.get()) {
|
||||
while (registeredSearcher == null || registeredSearcher.get() != newestSearcher.get()) {
|
||||
if (registeredSearcher != null) {
|
||||
registeredSearcher.decref();
|
||||
}
|
||||
newestSearcher.decref();
|
||||
Thread.sleep(50);
|
||||
registeredSearcher = h.getCore().getRegisteredSearcher();
|
||||
|
@ -475,10 +492,4 @@ public class SuggestComponentTest extends SolrTestCaseJ4 {
|
|||
newestSearcher.decref();
|
||||
}
|
||||
|
||||
assertQ(req("qt", "standard",
|
||||
"q", "*:*"),
|
||||
"//*[@numFound='11']"
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue