mirror of https://github.com/apache/lucene.git
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.
This commit is contained in:
parent
831ae2465b
commit
2ccec3deb7
|
@ -37,12 +37,15 @@ import org.apache.lucene.tests.util.LuceneTestCase;
|
||||||
import org.apache.lucene.util.BytesRef;
|
import org.apache.lucene.util.BytesRef;
|
||||||
|
|
||||||
public class TestElevationComparator extends LuceneTestCase {
|
public class TestElevationComparator extends LuceneTestCase {
|
||||||
|
private Directory directory;
|
||||||
|
private IndexReader reader;
|
||||||
|
private IndexSearcher searcher;
|
||||||
private final Map<BytesRef, Integer> priority = new HashMap<>();
|
private final Map<BytesRef, Integer> priority = new HashMap<>();
|
||||||
|
|
||||||
// @Test
|
@Override
|
||||||
public void testSorting() throws Throwable {
|
public void setUp() throws Exception {
|
||||||
Directory directory = newDirectory();
|
super.setUp();
|
||||||
|
directory = newDirectory();
|
||||||
IndexWriter writer =
|
IndexWriter writer =
|
||||||
new IndexWriter(
|
new IndexWriter(
|
||||||
directory,
|
directory,
|
||||||
|
@ -58,20 +61,29 @@ public class TestElevationComparator extends LuceneTestCase {
|
||||||
writer.addDocument(
|
writer.addDocument(
|
||||||
adoc(new String[] {"id", "z", "title", "boosted boosted boosted", "str_s", "z"}));
|
adoc(new String[] {"id", "z", "title", "boosted boosted boosted", "str_s", "z"}));
|
||||||
|
|
||||||
IndexReader r = DirectoryReader.open(writer);
|
reader = DirectoryReader.open(writer);
|
||||||
writer.close();
|
writer.close();
|
||||||
|
|
||||||
IndexSearcher searcher = newSearcher(r);
|
searcher = newSearcher(reader);
|
||||||
searcher.setSimilarity(new BM25Similarity());
|
searcher.setSimilarity(new BM25Similarity());
|
||||||
|
}
|
||||||
|
|
||||||
runTest(searcher, true);
|
@Override
|
||||||
runTest(searcher, false);
|
public void tearDown() throws Exception {
|
||||||
|
super.tearDown();
|
||||||
r.close();
|
reader.close();
|
||||||
directory.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();
|
BooleanQuery.Builder newq = new BooleanQuery.Builder();
|
||||||
TermQuery query = new TermQuery(new Term("title", "ipod"));
|
TermQuery query = new TermQuery(new Term("title", "ipod"));
|
||||||
|
|
Loading…
Reference in New Issue