mirror of https://github.com/apache/lucene.git
tests: track number of searcher open and closes
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1023510 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
613f758c92
commit
d2f30722e6
|
@ -37,6 +37,7 @@ import org.apache.lucene.util.OpenBitSet;
|
|||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
import org.apache.solr.search.function.ValueSource;
|
||||
import org.slf4j.Logger;
|
||||
|
@ -51,6 +52,12 @@ import org.slf4j.LoggerFactory;
|
|||
* @since solr 0.9
|
||||
*/
|
||||
public class SolrIndexSearcher extends IndexSearcher implements SolrInfoMBean {
|
||||
|
||||
// These should *only* be used for debugging or monitoring purposes
|
||||
public static final AtomicLong numOpens = new AtomicLong();
|
||||
public static final AtomicLong numCloses = new AtomicLong();
|
||||
|
||||
|
||||
private static Logger log = LoggerFactory.getLogger(SolrIndexSearcher.class);
|
||||
private final SolrCore core;
|
||||
private final IndexSchema schema;
|
||||
|
@ -191,6 +198,9 @@ public class SolrIndexSearcher extends IndexSearcher implements SolrInfoMBean {
|
|||
optimizer = solrConfig.filtOptEnabled ? new LuceneQueryOptimizer(solrConfig.filtOptCacheSize,solrConfig.filtOptThreshold) : null;
|
||||
|
||||
fieldNames = r.getFieldNames(IndexReader.FieldOption.ALL);
|
||||
|
||||
// do this at the end since an exception in the constructor means we won't close
|
||||
numOpens.incrementAndGet();
|
||||
}
|
||||
|
||||
|
||||
|
@ -239,6 +249,9 @@ public class SolrIndexSearcher extends IndexSearcher implements SolrInfoMBean {
|
|||
for (SolrCache cache : cacheList) {
|
||||
cache.close();
|
||||
}
|
||||
|
||||
// do this at the end so it only gets done if there are no exceptions
|
||||
numCloses.incrementAndGet();
|
||||
}
|
||||
|
||||
/** Direct access to the IndexReader used by this searcher */
|
||||
|
|
|
@ -27,7 +27,9 @@ import org.apache.solr.common.params.ModifiableSolrParams;
|
|||
import org.apache.solr.common.params.SolrParams;
|
||||
import org.apache.solr.common.util.XML;
|
||||
import org.apache.solr.core.SolrConfig;
|
||||
import org.apache.solr.request.LocalSolrQueryRequest;
|
||||
import org.apache.solr.request.SolrQueryRequest;
|
||||
import org.apache.solr.search.SolrIndexSearcher;
|
||||
import org.apache.solr.util.TestHarness;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
|
@ -85,6 +87,7 @@ public abstract class SolrTestCaseJ4 extends LuceneTestCase {
|
|||
/** Call initCore in @BeforeClass to instantiate a solr core in your test class.
|
||||
* deleteCore will be called for you via SolrTestCaseJ4 @AfterClass */
|
||||
public static void initCore(String config, String schema, String solrHome) throws Exception {
|
||||
startTrackingSearchers();
|
||||
configString = config;
|
||||
schemaString = schema;
|
||||
if (solrHome != null) {
|
||||
|
@ -93,6 +96,26 @@ public abstract class SolrTestCaseJ4 extends LuceneTestCase {
|
|||
initCore();
|
||||
}
|
||||
|
||||
|
||||
static long numOpens;
|
||||
static long numCloses;
|
||||
protected static void startTrackingSearchers() {
|
||||
numOpens = SolrIndexSearcher.numOpens.get();
|
||||
numCloses = SolrIndexSearcher.numCloses.get();
|
||||
}
|
||||
|
||||
protected static void endTrackingSearchers() {
|
||||
long endNumOpens = SolrIndexSearcher.numOpens.get();
|
||||
long endNumCloses = SolrIndexSearcher.numCloses.get();
|
||||
|
||||
if (endNumOpens-numOpens != endNumCloses-numCloses) {
|
||||
String msg = "ERROR: SolrIndexSearcher opens=" + (endNumOpens-numOpens) + " closes=" + (endNumCloses-numCloses);
|
||||
log.error(msg);
|
||||
// TODO: make this fail if we manage to clean up
|
||||
// fail(msg);
|
||||
}
|
||||
}
|
||||
|
||||
/** Causes an exception matching the regex pattern to not be logged. */
|
||||
public static void ignoreException(String pattern) {
|
||||
if (SolrException.ignorePatterns == null)
|
||||
|
@ -260,7 +283,9 @@ public abstract class SolrTestCaseJ4 extends LuceneTestCase {
|
|||
solrConfig = null;
|
||||
h = null;
|
||||
lrf = null;
|
||||
configString = schemaString = null;
|
||||
configString = schemaString = null;
|
||||
|
||||
endTrackingSearchers();
|
||||
}
|
||||
|
||||
|
||||
|
@ -528,6 +553,14 @@ public abstract class SolrTestCaseJ4 extends LuceneTestCase {
|
|||
return d;
|
||||
}
|
||||
|
||||
public static ModifiableSolrParams params(String... params) {
|
||||
ModifiableSolrParams msp = new ModifiableSolrParams();
|
||||
for (int i=0; i<params.length; i+=2) {
|
||||
msp.add(params[i], params[i+1]);
|
||||
}
|
||||
return msp;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a SolrQueryRequest using the LocalRequestFactory
|
||||
* @see #lrf
|
||||
|
@ -552,6 +585,17 @@ public abstract class SolrTestCaseJ4 extends LuceneTestCase {
|
|||
return lrf.makeRequest(allParams);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a SolrQueryRequest
|
||||
*/
|
||||
public static SolrQueryRequest req(SolrParams params, String... moreParams) {
|
||||
ModifiableSolrParams mp = new ModifiableSolrParams(params);
|
||||
for (int i=0; i<moreParams.length; i+=2) {
|
||||
mp.add(moreParams[i], moreParams[i+1]);
|
||||
}
|
||||
return new LocalSolrQueryRequest(h.getCore(), mp);
|
||||
}
|
||||
|
||||
/** Neccessary to make method signatures un-ambiguous */
|
||||
public static class Doc {
|
||||
public String xml;
|
||||
|
|
Loading…
Reference in New Issue