From 8c50bc2fdef23c791165cd7a166b3e39fb2b7cdf Mon Sep 17 00:00:00 2001 From: Tomas Eduardo Fernandez Lobbe Date: Thu, 22 Jan 2015 09:02:13 +0000 Subject: [PATCH] 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 --- .../solr/spelling/suggest/SolrSuggester.java | 10 ++-- .../component/SuggestComponentTest.java | 47 ++++++++++++------- 2 files changed, 35 insertions(+), 22 deletions(-) diff --git a/solr/core/src/java/org/apache/solr/spelling/suggest/SolrSuggester.java b/solr/core/src/java/org/apache/solr/spelling/suggest/SolrSuggester.java index 0d4714d9a10..18c4da76175 100644 --- a/solr/core/src/java/org/apache/solr/spelling/suggest/SolrSuggester.java +++ b/solr/core/src/java/org/apache/solr/spelling/suggest/SolrSuggester.java @@ -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()) { diff --git a/solr/core/src/test/org/apache/solr/handler/component/SuggestComponentTest.java b/solr/core/src/test/org/apache/solr/handler/component/SuggestComponentTest.java index eac01e33274..f3610b5b11d 100644 --- a/solr/core/src/test/org/apache/solr/handler/component/SuggestComponentTest.java +++ b/solr/core/src/test/org/apache/solr/handler/component/SuggestComponentTest.java @@ -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,26 +464,32 @@ 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 - RefCounted registeredSearcher = h.getCore().getRegisteredSearcher(); - RefCounted newestSearcher = h.getCore().getNewestSearcher(false);; - while (registeredSearcher.get() != newestSearcher.get()) { - registeredSearcher.decref(); - newestSearcher.decref(); - Thread.sleep(50); - registeredSearcher = h.getCore().getRegisteredSearcher(); - newestSearcher = h.getCore().getNewestSearcher(false); - } - registeredSearcher.decref(); - newestSearcher.decref(); - } +// } 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 registeredSearcher = h.getCore().getRegisteredSearcher(); + RefCounted newestSearcher = h.getCore().getNewestSearcher(false);; + while (registeredSearcher == null || registeredSearcher.get() != newestSearcher.get()) { + if (registeredSearcher != null) { + registeredSearcher.decref(); + } + newestSearcher.decref(); + Thread.sleep(50); + registeredSearcher = h.getCore().getRegisteredSearcher(); + newestSearcher = h.getCore().getNewestSearcher(false); + } + registeredSearcher.decref(); + newestSearcher.decref(); + } }