reduce number of fleeting threads created by this test

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1466884 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael McCandless 2013-04-11 13:38:33 +00:00
parent 4c0f248b19
commit c197d2d420
1 changed files with 14 additions and 1 deletions

View File

@ -298,6 +298,9 @@ public class TestStressNRT extends LuceneTestCase {
@Override @Override
public void run() { public void run() {
try { try {
IndexReader lastReader = null;
IndexSearcher lastSearcher = null;
while (operations.decrementAndGet() >= 0) { while (operations.decrementAndGet() >= 0) {
// bias toward a recently changed doc // bias toward a recently changed doc
int id = rand.nextInt(100) < 25 ? lastId : rand.nextInt(ndocs); int id = rand.nextInt(100) < 25 ? lastId : rand.nextInt(ndocs);
@ -318,7 +321,17 @@ public class TestStressNRT extends LuceneTestCase {
} }
// sreq = req("wt","json", "q","id:"+Integer.toString(id), "omitHeader","true"); // sreq = req("wt","json", "q","id:"+Integer.toString(id), "omitHeader","true");
IndexSearcher searcher = newSearcher(r); IndexSearcher searcher;
if (r == lastReader) {
// Just re-use lastSearcher, else
// newSearcher may create too many thread
// pools (ExecutorService):
searcher = lastSearcher;
} else {
searcher = newSearcher(r);
lastReader = r;
lastSearcher = searcher;
}
Query q = new TermQuery(new Term("id",Integer.toString(id))); Query q = new TermQuery(new Term("id",Integer.toString(id)));
TopDocs results = searcher.search(q, 10); TopDocs results = searcher.search(q, 10);