mirror of https://github.com/apache/lucene.git
LUCENE-10473: Make tests a bit faster when running nightly. (#754)
This commit is contained in:
parent
fcacd22a80
commit
1b890ab5f9
|
@ -151,9 +151,6 @@ public final class CompetitiveImpactAccumulator {
|
|||
|
||||
// Only called by assertions
|
||||
private boolean assertConsistent() {
|
||||
for (int freq : maxFreqs) {
|
||||
assert freq >= 0;
|
||||
}
|
||||
int previousFreq = 0;
|
||||
long previousNorm = 0;
|
||||
for (Impact impact : otherFreqNormPairs) {
|
||||
|
|
|
@ -259,7 +259,7 @@ public abstract class BaseSpatialTestCase extends LuceneTestCase {
|
|||
Set<Integer> deleted = new HashSet<>();
|
||||
for (int id = 0; id < shapes.length; ++id) {
|
||||
Document doc = new Document();
|
||||
doc.add(newStringField("id", "" + id, Field.Store.NO));
|
||||
doc.add(new StringField("id", "" + id, Field.Store.NO));
|
||||
doc.add(new NumericDocValuesField("id", id));
|
||||
if (shapes[id] != null) {
|
||||
addShapeToDoc(FIELD_NAME, doc, shapes[id]);
|
||||
|
|
|
@ -37,6 +37,7 @@ import org.apache.lucene.codecs.lucene90.Lucene90PointsWriter;
|
|||
import org.apache.lucene.document.Document;
|
||||
import org.apache.lucene.document.Field;
|
||||
import org.apache.lucene.document.NumericDocValuesField;
|
||||
import org.apache.lucene.document.StringField;
|
||||
import org.apache.lucene.geo.Polygon;
|
||||
import org.apache.lucene.geo.Rectangle;
|
||||
import org.apache.lucene.index.DirectoryReader;
|
||||
|
@ -610,8 +611,9 @@ public class TestGeo3DPoint extends LuceneTestCase {
|
|||
|
||||
boolean haveRealDoc = false;
|
||||
|
||||
Random random = random();
|
||||
for (int docID = 0; docID < numPoints; docID++) {
|
||||
int x = random().nextInt(20);
|
||||
int x = random.nextInt(20);
|
||||
if (x == 17) {
|
||||
// Some docs don't have a point:
|
||||
lats[docID] = Double.NaN;
|
||||
|
@ -624,7 +626,7 @@ public class TestGeo3DPoint extends LuceneTestCase {
|
|||
if (docID > 0 && x < 3 && haveRealDoc) {
|
||||
int oldDocID;
|
||||
while (true) {
|
||||
oldDocID = random().nextInt(docID);
|
||||
oldDocID = random.nextInt(docID);
|
||||
if (Double.isNaN(lats[oldDocID]) == false) {
|
||||
break;
|
||||
}
|
||||
|
@ -992,7 +994,7 @@ public class TestGeo3DPoint extends LuceneTestCase {
|
|||
IndexWriter w = new IndexWriter(dir, iwc);
|
||||
for (int id = 0; id < points.length; id++) {
|
||||
Document doc = new Document();
|
||||
doc.add(newStringField("id", "" + id, Field.Store.NO));
|
||||
doc.add(new StringField("id", "" + id, Field.Store.NO));
|
||||
doc.add(new NumericDocValuesField("id", id));
|
||||
GeoPoint point = points[id];
|
||||
if (point != null) {
|
||||
|
|
|
@ -652,7 +652,7 @@ public abstract class BaseGeoPointTestCase extends LuceneTestCase {
|
|||
Document doc = new Document();
|
||||
lats[2 * id] = quantizeLat(nextLatitude());
|
||||
lons[2 * id] = quantizeLon(nextLongitude());
|
||||
doc.add(newStringField("id", "" + id, Field.Store.YES));
|
||||
doc.add(new StringField("id", "" + id, Field.Store.YES));
|
||||
addPointToDoc(FIELD_NAME, doc, lats[2 * id], lons[2 * id]);
|
||||
lats[2 * id + 1] = quantizeLat(nextLatitude());
|
||||
lons[2 * id + 1] = quantizeLon(nextLongitude());
|
||||
|
@ -909,6 +909,8 @@ public abstract class BaseGeoPointTestCase extends LuceneTestCase {
|
|||
}
|
||||
Directory dir;
|
||||
if (lats.length > 100000) {
|
||||
// Avoid slow codecs like SimpleText
|
||||
iwc.setCodec(TestUtil.getDefaultCodec());
|
||||
dir = newFSDirectory(createTempDir(getClass().getSimpleName()));
|
||||
} else {
|
||||
dir = newDirectory();
|
||||
|
@ -992,6 +994,8 @@ public abstract class BaseGeoPointTestCase extends LuceneTestCase {
|
|||
}
|
||||
Directory dir;
|
||||
if (lats.length > 100000) {
|
||||
// Avoid slow codecs like SimpleText
|
||||
iwc.setCodec(TestUtil.getDefaultCodec());
|
||||
dir = newFSDirectory(createTempDir(getClass().getSimpleName()));
|
||||
} else {
|
||||
dir = newDirectory();
|
||||
|
@ -1095,6 +1099,8 @@ public abstract class BaseGeoPointTestCase extends LuceneTestCase {
|
|||
}
|
||||
Directory dir;
|
||||
if (lats.length > 100000) {
|
||||
// Avoid slow codecs like SimpleText
|
||||
iwc.setCodec(TestUtil.getDefaultCodec());
|
||||
dir = newFSDirectory(createTempDir(getClass().getSimpleName()));
|
||||
} else {
|
||||
dir = newDirectory();
|
||||
|
@ -1179,6 +1185,8 @@ public abstract class BaseGeoPointTestCase extends LuceneTestCase {
|
|||
}
|
||||
Directory dir;
|
||||
if (lats.length > 100000) {
|
||||
// Avoid slow codecs like SimpleText
|
||||
iwc.setCodec(TestUtil.getDefaultCodec());
|
||||
dir = newFSDirectory(createTempDir(getClass().getSimpleName()));
|
||||
} else {
|
||||
dir = newDirectory();
|
||||
|
@ -1259,7 +1267,7 @@ public abstract class BaseGeoPointTestCase extends LuceneTestCase {
|
|||
throws IOException {
|
||||
for (int id = 0; id < lats.length; id++) {
|
||||
Document doc = new Document();
|
||||
doc.add(newStringField("id", "" + id, Field.Store.NO));
|
||||
doc.add(new StringField("id", "" + id, Field.Store.NO));
|
||||
doc.add(new NumericDocValuesField("id", id));
|
||||
if (Double.isNaN(lats[id]) == false) {
|
||||
addPointToDoc(FIELD_NAME, doc, lats[id], lons[id]);
|
||||
|
|
|
@ -594,7 +594,7 @@ public abstract class BaseXYPointTestCase extends LuceneTestCase {
|
|||
Document doc = new Document();
|
||||
xs[2 * id] = nextX();
|
||||
ys[2 * id] = nextY();
|
||||
doc.add(newStringField("id", "" + id, Field.Store.YES));
|
||||
doc.add(new StringField("id", "" + id, Field.Store.YES));
|
||||
addPointToDoc(FIELD_NAME, doc, xs[2 * id], ys[2 * id]);
|
||||
xs[2 * id + 1] = nextX();
|
||||
ys[2 * id + 1] = nextY();
|
||||
|
@ -805,6 +805,8 @@ public abstract class BaseXYPointTestCase extends LuceneTestCase {
|
|||
}
|
||||
Directory dir;
|
||||
if (xs.length > 100000) {
|
||||
// Avoid slow codecs like SimpleText
|
||||
iwc.setCodec(TestUtil.getDefaultCodec());
|
||||
dir = newFSDirectory(createTempDir(getClass().getSimpleName()));
|
||||
} else {
|
||||
dir = newDirectory();
|
||||
|
@ -887,6 +889,8 @@ public abstract class BaseXYPointTestCase extends LuceneTestCase {
|
|||
}
|
||||
Directory dir;
|
||||
if (xs.length > 100000) {
|
||||
// Avoid slow codecs like SimpleText
|
||||
iwc.setCodec(TestUtil.getDefaultCodec());
|
||||
dir = newFSDirectory(createTempDir(getClass().getSimpleName()));
|
||||
} else {
|
||||
dir = newDirectory();
|
||||
|
@ -986,6 +990,8 @@ public abstract class BaseXYPointTestCase extends LuceneTestCase {
|
|||
}
|
||||
Directory dir;
|
||||
if (xs.length > 100000) {
|
||||
// Avoid slow codecs like SimpleText
|
||||
iwc.setCodec(TestUtil.getDefaultCodec());
|
||||
dir = newFSDirectory(createTempDir(getClass().getSimpleName()));
|
||||
} else {
|
||||
dir = newDirectory();
|
||||
|
@ -1069,6 +1075,8 @@ public abstract class BaseXYPointTestCase extends LuceneTestCase {
|
|||
}
|
||||
Directory dir;
|
||||
if (xs.length > 100000) {
|
||||
// Avoid slow codecs like SimpleText
|
||||
iwc.setCodec(TestUtil.getDefaultCodec());
|
||||
dir = newFSDirectory(createTempDir(getClass().getSimpleName()));
|
||||
} else {
|
||||
dir = newDirectory();
|
||||
|
@ -1146,7 +1154,7 @@ public abstract class BaseXYPointTestCase extends LuceneTestCase {
|
|||
throws IOException {
|
||||
for (int id = 0; id < xs.length; id++) {
|
||||
Document doc = new Document();
|
||||
doc.add(newStringField("id", "" + id, Field.Store.NO));
|
||||
doc.add(new StringField("id", "" + id, Field.Store.NO));
|
||||
doc.add(new NumericDocValuesField("id", id));
|
||||
if (Float.isNaN(xs[id]) == false && Float.isNaN(ys[id]) == false) {
|
||||
addPointToDoc(FIELD_NAME, doc, xs[id], ys[id]);
|
||||
|
|
|
@ -23,6 +23,7 @@ import java.util.Set;
|
|||
import org.apache.lucene.document.Document;
|
||||
import org.apache.lucene.document.Field;
|
||||
import org.apache.lucene.document.NumericDocValuesField;
|
||||
import org.apache.lucene.document.StringField;
|
||||
import org.apache.lucene.index.DirectoryReader;
|
||||
import org.apache.lucene.index.IndexReader;
|
||||
import org.apache.lucene.index.IndexWriter;
|
||||
|
@ -230,6 +231,8 @@ public abstract class BaseRangeFieldQueryTestCase extends LuceneTestCase {
|
|||
}
|
||||
Directory dir;
|
||||
if (ranges.length > 50000) {
|
||||
// Avoid slow codecs like SimpleText
|
||||
iwc.setCodec(TestUtil.getDefaultCodec());
|
||||
dir = newFSDirectory(createTempDir(getClass().getSimpleName()));
|
||||
} else {
|
||||
dir = newDirectory();
|
||||
|
@ -239,7 +242,7 @@ public abstract class BaseRangeFieldQueryTestCase extends LuceneTestCase {
|
|||
IndexWriter w = new IndexWriter(dir, iwc);
|
||||
for (int id = 0; id < ranges.length; ++id) {
|
||||
Document doc = new Document();
|
||||
doc.add(newStringField("id", "" + id, Field.Store.NO));
|
||||
doc.add(new StringField("id", "" + id, Field.Store.NO));
|
||||
doc.add(new NumericDocValuesField("id", id));
|
||||
if (ranges[id][0].isMissing == false) {
|
||||
for (int n = 0; n < ranges[id].length; ++n) {
|
||||
|
|
|
@ -402,12 +402,6 @@ public abstract class LuceneTestCase extends Assert {
|
|||
/** Enables or disables dumping of {@link InfoStream} messages. */
|
||||
public static final boolean INFOSTREAM = systemPropertyAsBoolean("tests.infostream", VERBOSE);
|
||||
|
||||
/**
|
||||
* A random multiplier which you should use when writing random tests: multiply it by the number
|
||||
* of iterations to scale your tests (for nightly builds).
|
||||
*/
|
||||
public static final int RANDOM_MULTIPLIER = systemPropertyAsInt("tests.multiplier", 1);
|
||||
|
||||
public static final boolean TEST_ASSERTS_ENABLED = systemPropertyAsBoolean("tests.asserts", true);
|
||||
|
||||
/**
|
||||
|
@ -474,6 +468,13 @@ public abstract class LuceneTestCase extends Assert {
|
|||
public static final Throttling TEST_THROTTLING =
|
||||
TEST_NIGHTLY ? Throttling.SOMETIMES : Throttling.NEVER;
|
||||
|
||||
/**
|
||||
* A random multiplier which you should use when writing random tests: multiply it by the number
|
||||
* of iterations to scale your tests (for nightly builds).
|
||||
*/
|
||||
public static final int RANDOM_MULTIPLIER =
|
||||
systemPropertyAsInt("tests.multiplier", TEST_NIGHTLY ? 2 : 1);
|
||||
|
||||
/** Leave temporary files on disk, even on successful runs. */
|
||||
public static final boolean LEAVE_TEMPORARY;
|
||||
|
||||
|
@ -873,7 +874,7 @@ public abstract class LuceneTestCase extends Assert {
|
|||
* {@link #RANDOM_MULTIPLIER}, but also with some random fudge.
|
||||
*/
|
||||
public static int atLeast(Random random, int i) {
|
||||
int min = (TEST_NIGHTLY ? 2 * i : i) * RANDOM_MULTIPLIER;
|
||||
int min = i * RANDOM_MULTIPLIER;
|
||||
int max = min + (min / 2);
|
||||
return TestUtil.nextInt(random, min, max);
|
||||
}
|
||||
|
@ -889,9 +890,9 @@ public abstract class LuceneTestCase extends Assert {
|
|||
* {@link #RANDOM_MULTIPLIER}.
|
||||
*/
|
||||
public static boolean rarely(Random random) {
|
||||
int p = TEST_NIGHTLY ? 10 : 1;
|
||||
int p = TEST_NIGHTLY ? 5 : 1;
|
||||
p += (p * Math.log(RANDOM_MULTIPLIER));
|
||||
int min = 100 - Math.min(p, 50); // never more than 50
|
||||
int min = 100 - Math.min(p, 20); // never more than 20
|
||||
return random.nextInt(100) >= min;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue