Skip to content

Apache Lucene open-source search software

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

Michael McCandless51f9b759faaa
diff --git a/contrib/benchmark/CHANGES.txt b/contrib/benchmark/CHANGES.txt
index e14b72d6032..1f4ac0115f0 100644
--- a/contrib/benchmark/CHANGES.txt
+++ b/contrib/benchmark/CHANGES.txt
@@ -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.
diff --git a/contrib/benchmark/src/test/org/apache/lucene/benchmark/byTask/TestPerfTasksLogic.java b/contrib/benchmark/src/test/org/apache/lucene/benchmark/byTask/TestPerfTasksLogic.java
index 70e45d1ff35..95b096e4e29 100755
--- a/contrib/benchmark/src/test/org/apache/lucene/benchmark/byTask/TestPerfTasksLogic.java
+++ b/contrib/benchmark/src/test/org/apache/lucene/benchmark/byTask/TestPerfTasksLogic.java
@@ -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 {
diff --git a/contrib/benchmark/src/test/org/apache/lucene/benchmark/byTask/tasks/CountingSearchTestTask.java b/contrib/benchmark/src/test/org/apache/lucene/benchmark/byTask/tasks/CountingSearchTestTask.java
index 41569891c19..9d199375bf6 100755
--- a/contrib/benchmark/src/test/org/apache/lucene/benchmark/byTask/tasks/CountingSearchTestTask.java
+++ b/contrib/benchmark/src/test/org/apache/lucene/benchmark/byTask/tasks/CountingSearchTestTask.java
@@ -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;
+ }
}