mirror of https://github.com/apache/lucene.git
SOLR-5783: harden tests
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1581398 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
1dba8a6f6b
commit
83036e1800
|
@ -105,10 +105,13 @@ public class TestIndexSearcher extends SolrTestCaseJ4 {
|
|||
int baseRefCount = rCtx3.reader().getRefCount();
|
||||
assertEquals(1, baseRefCount);
|
||||
|
||||
Object sr3SearcherRegAt = sr3.getSearcher().getStatistics().get("registeredAt");
|
||||
assertU(commit()); // nothing has changed
|
||||
SolrQueryRequest sr4 = req("q","foo");
|
||||
assertSame("nothing changed, searcher should be the same",
|
||||
sr3.getSearcher(), sr4.getSearcher());
|
||||
assertEquals("nothing changed, searcher should not have been re-registered",
|
||||
sr3SearcherRegAt, sr4.getSearcher().getStatistics().get("registeredAt"));
|
||||
IndexReaderContext rCtx4 = sr4.getSearcher().getTopReaderContext();
|
||||
|
||||
// force an index change so the registered searcher won't be the one we are testing (and
|
||||
|
|
|
@ -105,7 +105,7 @@ public class TestSearcherReuse extends SolrTestCaseJ4 {
|
|||
try {
|
||||
// we make no index changes in this block, so the searcher should always be the same
|
||||
// NOTE: we *have* to call getSearcher() in advance, it's a delayed binding
|
||||
final SolrIndexSearcher expectedSearcher = baseReq.getSearcher();
|
||||
final SolrIndexSearcher expectedSearcher = getMainSearcher(baseReq);
|
||||
|
||||
assertU(commit());
|
||||
assertSearcherHasNotChanged(expectedSearcher);
|
||||
|
@ -137,7 +137,8 @@ public class TestSearcherReuse extends SolrTestCaseJ4 {
|
|||
beforeReq = req("q","foo");
|
||||
try {
|
||||
// NOTE: we *have* to call getSearcher() in advance: delayed binding
|
||||
SolrIndexSearcher before = beforeReq.getSearcher();
|
||||
SolrIndexSearcher before = getMainSearcher(beforeReq);
|
||||
|
||||
assertU(delI("1"));
|
||||
assertU(commit());
|
||||
assertSearcherHasChanged(before);
|
||||
|
@ -148,7 +149,8 @@ public class TestSearcherReuse extends SolrTestCaseJ4 {
|
|||
beforeReq = req("q","foo");
|
||||
try {
|
||||
// NOTE: we *have* to call getSearcher() in advance: delayed binding
|
||||
SolrIndexSearcher before = beforeReq.getSearcher();
|
||||
SolrIndexSearcher before = getMainSearcher(beforeReq);
|
||||
|
||||
assertU(adoc("id", "0"));
|
||||
assertU(commit());
|
||||
assertSearcherHasChanged(before);
|
||||
|
@ -159,7 +161,8 @@ public class TestSearcherReuse extends SolrTestCaseJ4 {
|
|||
beforeReq = req("q","foo");
|
||||
try {
|
||||
// NOTE: we *have* to call getSearcher() in advance: delayed binding
|
||||
SolrIndexSearcher before = beforeReq.getSearcher();
|
||||
SolrIndexSearcher before = getMainSearcher(beforeReq);
|
||||
|
||||
assertU(delQ("id:[0 TO 5]"));
|
||||
assertU(commit());
|
||||
assertSearcherHasChanged(before);
|
||||
|
@ -170,7 +173,7 @@ public class TestSearcherReuse extends SolrTestCaseJ4 {
|
|||
beforeReq = req("q","foo");
|
||||
try {
|
||||
// NOTE: we *have* to call getSearcher() in advance: delayed binding
|
||||
SolrIndexSearcher before = beforeReq.getSearcher();
|
||||
SolrIndexSearcher before = getMainSearcher(beforeReq);
|
||||
|
||||
// create a new field & add it.
|
||||
assertTrue("schema not mutable", beforeReq.getSchema().isMutable());
|
||||
|
@ -194,7 +197,7 @@ public class TestSearcherReuse extends SolrTestCaseJ4 {
|
|||
SolrQueryRequest afterReq = req("q","foo");
|
||||
try {
|
||||
assertSame(newSchema, afterReq.getSchema());
|
||||
assertSame(newSchema, afterReq.getSearcher().getSchema());
|
||||
assertSame(newSchema, getMainSearcher(afterReq).getSchema());
|
||||
} finally {
|
||||
afterReq.close();
|
||||
}
|
||||
|
@ -204,7 +207,26 @@ public class TestSearcherReuse extends SolrTestCaseJ4 {
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Helper method to get the searcher from a request, and assert that it's the main searcher
|
||||
*/
|
||||
public static SolrIndexSearcher getMainSearcher(SolrQueryRequest req) {
|
||||
SolrIndexSearcher s = req.getSearcher();
|
||||
assertMainSearcher(s);
|
||||
return s;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sanity check that we didn't get a realtime (non-caching) searcher
|
||||
*/
|
||||
public static void assertMainSearcher(SolrIndexSearcher s) {
|
||||
assertTrue("Searcher isn't 'main': " + s.toString(),
|
||||
// TODO brittle, better solution?
|
||||
s.toString().contains(" main{"));
|
||||
assertTrue("Searcher is non-caching", s.isCachingEnabled());
|
||||
}
|
||||
|
||||
/**
|
||||
* Given an existing searcher, creates a new SolrRequest, and verifies that the
|
||||
* searcher in that request is <b>not</b> the same as the previous searcher --
|
||||
|
@ -213,7 +235,7 @@ public class TestSearcherReuse extends SolrTestCaseJ4 {
|
|||
public static void assertSearcherHasChanged(SolrIndexSearcher previous) {
|
||||
SolrQueryRequest req = req("*:*");
|
||||
try {
|
||||
SolrIndexSearcher newSearcher = req.getSearcher();
|
||||
SolrIndexSearcher newSearcher = getMainSearcher(req);
|
||||
assertNotSame(previous, newSearcher);
|
||||
} finally {
|
||||
req.close();
|
||||
|
@ -228,7 +250,8 @@ public class TestSearcherReuse extends SolrTestCaseJ4 {
|
|||
public static void assertSearcherHasNotChanged(SolrIndexSearcher expected) {
|
||||
SolrQueryRequest req = req("*:*");
|
||||
try {
|
||||
assertSame(expected, req.getSearcher());
|
||||
SolrIndexSearcher newSearcher = getMainSearcher(req);
|
||||
assertSame(expected, newSearcher);
|
||||
} finally {
|
||||
req.close();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue