LUCENE-1495: fix time-based test to reduce change of false failure

git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@728425 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael McCandless 2008-12-21 11:07:28 +00:00
parent 7abe0311bc
commit 51f9b759fa
3 changed files with 15 additions and 5 deletions

View File

@ -3,6 +3,9 @@ Lucene Benchmark Contrib Change Log
The Benchmark contrib package contains code for benchmarking Lucene in a variety of ways.
$Id:$
12/20/08
LUCENE-1495: Allow task sequence to run for specfied number of seconds by adding ": 2.7s" (for example).
12/16/08
LUCENE-1493: Stop using deprecated Hits API for searching; add new
param search.num.hits to set top N docs to collect.

View File

@ -112,13 +112,12 @@ public class TestPerfTasksLogic extends TestCase {
"{ CountingSearchTest } : 1.5s",
"CloseReader",
};
long t0 = System.currentTimeMillis();
CountingSearchTestTask.numSearches = 0;
Benchmark benchmark = execBenchmark(algLines);
long t1 = System.currentTimeMillis();
assertTrue(CountingSearchTestTask.numSearches > 0);
long elapsed = t1-t0;
assertTrue(elapsed > 1500 && elapsed < 2000);
long elapsed = CountingSearchTestTask.lastMillis - CountingSearchTestTask.startMillis;
assertTrue("elapsed time was " + elapsed + " msec", elapsed < 2000);
}
public void testHighlighting() throws Exception {

View File

@ -25,6 +25,8 @@ import org.apache.lucene.benchmark.byTask.PerfRunData;
public class CountingSearchTestTask extends SearchTask {
public static int numSearches = 0;
public static long startMillis;
public static long lastMillis;
public CountingSearchTestTask(PerfRunData runData) {
super(runData);
@ -37,7 +39,13 @@ public class CountingSearchTestTask extends SearchTask {
}
private static synchronized void incrNumSearches() {
lastMillis = System.currentTimeMillis();
if (0 == numSearches)
startMillis = lastMillis;
numSearches++;
}
public long getElapsedMillis() {
return lastMillis - startMillis;
}
}