You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by jp...@apache.org on 2022/06/24 16:13:01 UTC
[lucene] 02/02: Rework TestElevationComparator (#980)
This is an automated email from the ASF dual-hosted git repository.
jpountz pushed a commit to branch branch_9x
in repository https://gitbox.apache.org/repos/asf/lucene.git
commit b27220e1eab2f1340d3aca428b91bdf18033cdbc
Author: Luca Cavanna <ja...@users.noreply.github.com>
AuthorDate: Fri Jun 24 18:11:51 2022 +0200
Rework TestElevationComparator (#980)
The test used to leave hanging threads behind following a failure. Also one method was executing two different tests. I split the existing method into two and I am now leveraging setup and teardown to properly close all the resources both when the tests succeed as well as whey they fail.
---
.../lucene/search/TestElevationComparator.java | 34 +++++++++++++++-------
1 file changed, 23 insertions(+), 11 deletions(-)
diff --git a/lucene/core/src/test/org/apache/lucene/search/TestElevationComparator.java b/lucene/core/src/test/org/apache/lucene/search/TestElevationComparator.java
index f39cc095a1f..b385a95b066 100644
--- a/lucene/core/src/test/org/apache/lucene/search/TestElevationComparator.java
+++ b/lucene/core/src/test/org/apache/lucene/search/TestElevationComparator.java
@@ -37,12 +37,15 @@ import org.apache.lucene.tests.util.LuceneTestCase;
import org.apache.lucene.util.BytesRef;
public class TestElevationComparator extends LuceneTestCase {
-
+ private Directory directory;
+ private IndexReader reader;
+ private IndexSearcher searcher;
private final Map<BytesRef, Integer> priority = new HashMap<>();
- // @Test
- public void testSorting() throws Throwable {
- Directory directory = newDirectory();
+ @Override
+ public void setUp() throws Exception {
+ super.setUp();
+ directory = newDirectory();
IndexWriter writer =
new IndexWriter(
directory,
@@ -58,20 +61,29 @@ public class TestElevationComparator extends LuceneTestCase {
writer.addDocument(
adoc(new String[] {"id", "z", "title", "boosted boosted boosted", "str_s", "z"}));
- IndexReader r = DirectoryReader.open(writer);
+ reader = DirectoryReader.open(writer);
writer.close();
- IndexSearcher searcher = newSearcher(r);
+ searcher = newSearcher(reader);
searcher.setSimilarity(new BM25Similarity());
+ }
- runTest(searcher, true);
- runTest(searcher, false);
-
- r.close();
+ @Override
+ public void tearDown() throws Exception {
+ super.tearDown();
+ reader.close();
directory.close();
}
- private void runTest(IndexSearcher searcher, boolean reversed) throws Throwable {
+ public void testSorting() throws Throwable {
+ runTest(false);
+ }
+
+ public void testSortingReversed() throws Throwable {
+ runTest(true);
+ }
+
+ private void runTest(boolean reversed) throws Throwable {
BooleanQuery.Builder newq = new BooleanQuery.Builder();
TermQuery query = new TermQuery(new Term("title", "ipod"));