mirror of https://github.com/apache/lucene.git
Close index readers in tests (#12544)
There are a few places where tests don't close index readers. This has not caused problems so far, but it becomes an issue when the reader gets an executor, because its shutdown happens as a closing listener of the reader. This has become more evident since we now offload sequential execution to the executor. If there's an executor, but it's never used, no threads are created, and no threads are leaked. If we do use the executor, and the reader is not closed, the test leaks threads.
This commit is contained in:
parent
ef42af65f2
commit
a7202e2e6f
|
@ -849,11 +849,10 @@ public class TestSort extends LuceneTestCase {
|
|||
}
|
||||
|
||||
public void testRewrite() throws IOException {
|
||||
try (Directory dir = newDirectory()) {
|
||||
RandomIndexWriter writer = new RandomIndexWriter(random(), dir);
|
||||
IndexSearcher searcher = newSearcher(writer.getReader());
|
||||
writer.close();
|
||||
|
||||
try (Directory dir = newDirectory();
|
||||
RandomIndexWriter writer = new RandomIndexWriter(random(), dir);
|
||||
DirectoryReader reader = writer.getReader()) {
|
||||
IndexSearcher searcher = newSearcher(reader);
|
||||
LongValuesSource longSource = LongValuesSource.constant(1L);
|
||||
Sort sort = new Sort(longSource.getSortField(false));
|
||||
|
||||
|
|
|
@ -30,7 +30,6 @@ import org.apache.lucene.index.Term;
|
|||
import org.apache.lucene.search.PrefixQuery;
|
||||
import org.apache.lucene.search.Query;
|
||||
import org.apache.lucene.search.TermQuery;
|
||||
import org.apache.lucene.store.ByteBuffersDirectory;
|
||||
import org.apache.lucene.store.Directory;
|
||||
import org.apache.lucene.tests.util.LuceneTestCase;
|
||||
|
||||
|
@ -52,7 +51,7 @@ public class TestForceNoBulkScoringQuery extends LuceneTestCase {
|
|||
|
||||
public void testRewrite() throws IOException {
|
||||
|
||||
try (Directory dir = new ByteBuffersDirectory();
|
||||
try (Directory dir = newDirectory();
|
||||
IndexWriter iw = new IndexWriter(dir, new IndexWriterConfig(new StandardAnalyzer()))) {
|
||||
|
||||
Document doc = new Document();
|
||||
|
@ -60,18 +59,18 @@ public class TestForceNoBulkScoringQuery extends LuceneTestCase {
|
|||
iw.addDocument(doc);
|
||||
iw.commit();
|
||||
|
||||
IndexReader reader = DirectoryReader.open(dir);
|
||||
try (IndexReader reader = DirectoryReader.open(dir)) {
|
||||
PrefixQuery pq = new PrefixQuery(new Term("field", "term"));
|
||||
ForceNoBulkScoringQuery q = new ForceNoBulkScoringQuery(pq);
|
||||
|
||||
PrefixQuery pq = new PrefixQuery(new Term("field", "term"));
|
||||
ForceNoBulkScoringQuery q = new ForceNoBulkScoringQuery(pq);
|
||||
assertEquals(q.getWrappedQuery(), pq);
|
||||
|
||||
assertEquals(q.getWrappedQuery(), pq);
|
||||
Query rewritten = q.rewrite(newSearcher(reader));
|
||||
assertTrue(rewritten instanceof ForceNoBulkScoringQuery);
|
||||
|
||||
Query rewritten = q.rewrite(newSearcher(reader));
|
||||
assertTrue(rewritten instanceof ForceNoBulkScoringQuery);
|
||||
|
||||
Query inner = ((ForceNoBulkScoringQuery) rewritten).getWrappedQuery();
|
||||
assertNotEquals(inner, pq);
|
||||
Query inner = ((ForceNoBulkScoringQuery) rewritten).getWrappedQuery();
|
||||
assertNotEquals(inner, pq);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -60,15 +60,22 @@ public class TestPayloadSpans extends LuceneTestCase {
|
|||
protected IndexReader indexReader;
|
||||
private IndexReader closeIndexReader;
|
||||
private Directory directory;
|
||||
private PayloadHelper helper;
|
||||
|
||||
@Override
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
PayloadHelper helper = new PayloadHelper();
|
||||
helper = new PayloadHelper();
|
||||
searcher = helper.setUp(random(), similarity, 1000);
|
||||
indexReader = searcher.getIndexReader();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tearDown() throws Exception {
|
||||
helper.tearDown();
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
public void testSpanTermQuery() throws Exception {
|
||||
SpanTermQuery stq;
|
||||
Spans spans;
|
||||
|
|
Loading…
Reference in New Issue