mirror of https://github.com/apache/lucene.git
LUCENE-3786: fix test to not rely on wall clock
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1466610 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
2ef117e3cd
commit
8e6108528b
|
@ -48,12 +48,15 @@ public class TestSearcherTaxonomyManager extends LuceneTestCase {
|
||||||
final FacetFields facetFields = new FacetFields(tw);
|
final FacetFields facetFields = new FacetFields(tw);
|
||||||
final AtomicBoolean stop = new AtomicBoolean();
|
final AtomicBoolean stop = new AtomicBoolean();
|
||||||
|
|
||||||
|
// How many unique facets to index before stopping:
|
||||||
|
final int ordLimit = TEST_NIGHTLY ? 100000 : 6000;
|
||||||
|
|
||||||
Thread indexer = new Thread() {
|
Thread indexer = new Thread() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
Set<String> seen = new HashSet<String>();
|
Set<String> seen = new HashSet<String>();
|
||||||
List<String> paths = new ArrayList<String>();
|
List<String> paths = new ArrayList<String>();
|
||||||
while (!stop.get()) {
|
while (true) {
|
||||||
Document doc = new Document();
|
Document doc = new Document();
|
||||||
List<CategoryPath> docPaths = new ArrayList<CategoryPath>();
|
List<CategoryPath> docPaths = new ArrayList<CategoryPath>();
|
||||||
int numPaths = _TestUtil.nextInt(random(), 1, 5);
|
int numPaths = _TestUtil.nextInt(random(), 1, 5);
|
||||||
|
@ -82,6 +85,11 @@ public class TestSearcherTaxonomyManager extends LuceneTestCase {
|
||||||
} catch (IOException ioe) {
|
} catch (IOException ioe) {
|
||||||
throw new RuntimeException(ioe);
|
throw new RuntimeException(ioe);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (tw.getSize() >= ordLimit) {
|
||||||
|
stop.set(true);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -113,24 +121,16 @@ public class TestSearcherTaxonomyManager extends LuceneTestCase {
|
||||||
};
|
};
|
||||||
reopener.start();
|
reopener.start();
|
||||||
|
|
||||||
float runTimeSec = TEST_NIGHTLY ? 10.0f : 2.0f;
|
|
||||||
|
|
||||||
long stopTime = System.currentTimeMillis() + (int) (runTimeSec*1000);
|
|
||||||
|
|
||||||
indexer.start();
|
indexer.start();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
while (System.currentTimeMillis() < stopTime) {
|
while (!stop.get()) {
|
||||||
SearcherAndTaxonomy pair = mgr.acquire();
|
SearcherAndTaxonomy pair = mgr.acquire();
|
||||||
try {
|
try {
|
||||||
//System.out.println("search maxOrd=" + pair.taxonomyReader.getSize());
|
//System.out.println("search maxOrd=" + pair.taxonomyReader.getSize());
|
||||||
int topN;
|
int topN = _TestUtil.nextInt(random(), 1, 20);
|
||||||
if (random().nextBoolean()) {
|
CountFacetRequest cfr = new CountFacetRequest(new CategoryPath("field"), topN);
|
||||||
topN = _TestUtil.nextInt(random(), 1, 20);
|
FacetSearchParams fsp = new FacetSearchParams(cfr);
|
||||||
} else {
|
|
||||||
topN = Integer.MAX_VALUE;
|
|
||||||
}
|
|
||||||
FacetSearchParams fsp = new FacetSearchParams(new CountFacetRequest(new CategoryPath("field"), topN));
|
|
||||||
FacetsCollector fc = FacetsCollector.create(fsp, pair.searcher.getIndexReader(), pair.taxonomyReader);
|
FacetsCollector fc = FacetsCollector.create(fsp, pair.searcher.getIndexReader(), pair.taxonomyReader);
|
||||||
pair.searcher.search(new MatchAllDocsQuery(), fc);
|
pair.searcher.search(new MatchAllDocsQuery(), fc);
|
||||||
List<FacetResult> results = fc.getFacetResults();
|
List<FacetResult> results = fc.getFacetResults();
|
||||||
|
@ -139,9 +139,11 @@ public class TestSearcherTaxonomyManager extends LuceneTestCase {
|
||||||
assertTrue(root.ordinal != 0);
|
assertTrue(root.ordinal != 0);
|
||||||
|
|
||||||
if (pair.searcher.getIndexReader().numDocs() > 0) {
|
if (pair.searcher.getIndexReader().numDocs() > 0) {
|
||||||
|
//System.out.println(pair.taxonomyReader.getSize());
|
||||||
assertTrue(fr.getNumValidDescendants() > 0);
|
assertTrue(fr.getNumValidDescendants() > 0);
|
||||||
assertFalse(root.subResults.isEmpty());
|
assertFalse(root.subResults.isEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
//if (VERBOSE) {
|
//if (VERBOSE) {
|
||||||
//System.out.println("TEST: facets=" + FacetTestUtils.toSimpleString(results.get(0)));
|
//System.out.println("TEST: facets=" + FacetTestUtils.toSimpleString(results.get(0)));
|
||||||
//}
|
//}
|
||||||
|
@ -150,7 +152,6 @@ public class TestSearcherTaxonomyManager extends LuceneTestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
stop.set(true);
|
|
||||||
indexer.join();
|
indexer.join();
|
||||||
reopener.join();
|
reopener.join();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue