diff --git a/lucene/core/src/test/org/apache/lucene/search/TestSort.java b/lucene/core/src/test/org/apache/lucene/search/TestSort.java index a160d4a204c..61c202e6884 100644 --- a/lucene/core/src/test/org/apache/lucene/search/TestSort.java +++ b/lucene/core/src/test/org/apache/lucene/search/TestSort.java @@ -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)); diff --git a/lucene/monitor/src/test/org/apache/lucene/monitor/TestForceNoBulkScoringQuery.java b/lucene/monitor/src/test/org/apache/lucene/monitor/TestForceNoBulkScoringQuery.java index 4f5011ba17e..bc6b631a0cd 100644 --- a/lucene/monitor/src/test/org/apache/lucene/monitor/TestForceNoBulkScoringQuery.java +++ b/lucene/monitor/src/test/org/apache/lucene/monitor/TestForceNoBulkScoringQuery.java @@ -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); + } } } } diff --git a/lucene/queries/src/test/org/apache/lucene/queries/payloads/TestPayloadSpans.java b/lucene/queries/src/test/org/apache/lucene/queries/payloads/TestPayloadSpans.java index bd3547faa64..d8920eb5c1a 100644 --- a/lucene/queries/src/test/org/apache/lucene/queries/payloads/TestPayloadSpans.java +++ b/lucene/queries/src/test/org/apache/lucene/queries/payloads/TestPayloadSpans.java @@ -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;