Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,15 @@ public void apply(Project project) {
buildOptions.addIntOption("tests.timeoutSuite", "Timeout (in millis) for an entire suite.");
optionsInheritedAsProperties.add("tests.timeoutSuite");

buildOptions.addIntOption(
"tests.random.maxcalls",
"Max number of calls to Randoms returned by LuceneTestCase.random()");
optionsInheritedAsProperties.add("tests.random.maxcalls");

buildOptions.addIntOption(
"tests.random.maxacquires", "Max number of per-test calls to LuceneTestCase.random()");
optionsInheritedAsProperties.add("tests.random.maxacquires");

Provider<Boolean> assertsOption =
buildOptions.addBooleanOption(
"tests.asserts",
Expand Down
8 changes: 5 additions & 3 deletions lucene/CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,6 @@ Improvements
This avoids clashes with other ASM versions on classpath because it removes the dependency.
(Uwe Schindler)



* GITHUB#15002: Remove synchronized WeakHashMap from IndexReader. This was added to help prevent
SIGSEGV with the old unsafe "mmap hack", which has been replaced by MemorySegments.
(Uwe Schindler, Robert Muir)
Expand Down Expand Up @@ -106,7 +104,11 @@ Changes in Runtime Behavior

Build
---------------------
* GITHUB#15325: Run the tests with assertions disabled ~25% of the time #15325 (Dawid Weiss)
* GITHUB#15327: New low-level build options to detect abuse of LuceneTestCase.random():
tests.random.maxacquires and tests.random.maxcalls (Robert Muir, Dawid Weiss)

* GITHUB#15325: Run the tests with assertions disabled ~25% of the time #15325
(Robert Muir, Dawid Weiss)

* GITHUB#14804: Detect and ban wildcard imports in Java (Robert Muir, Dawid Weiss)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public void test() throws Exception {

RollingCharBuffer buffer = new RollingCharBuffer();

Random random = random();
Random random = nonAssertingRandom(random());
for (int iter = 0; iter < ITERS; iter++) {
final int stringLen = random.nextBoolean() ? random.nextInt(50) : random.nextInt(20000);
final String s;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ static byte[] randomArray(Random random) {
}

static byte[] randomArray(Random random, int length, int max) {
random = nonAssertingRandom(random);
final byte[] arr = new byte[length];
for (int i = 0; i < arr.length; ++i) {
arr[i] = (byte) RandomNumbers.randomIntBetween(random, 0, max);
Expand Down Expand Up @@ -83,7 +84,7 @@ byte[] decompress(byte[] compressed, int originalLength, int offset, int length)
}

public void testDecompress() throws IOException {
Random random = random();
Random random = nonAssertingRandom(random());
final int iterations = atLeast(random, 3);
for (int i = 0; i < iterations; ++i) {
final byte[] decompressed = randomArray(random);
Expand All @@ -99,7 +100,7 @@ public void testDecompress() throws IOException {
}

public void testPartialDecompress() throws IOException {
Random random = random();
Random random = nonAssertingRandom(random());
final int iterations = atLeast(random, 3);
for (int i = 0; i < iterations; ++i) {
final byte[] decompressed = randomArray(random);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public void setUp() throws Exception {
ft.setStoreTermVectorPositions(true);

Document doc;
Random rnd = random();
Random rnd = nonAssertingRandom(random());
int numDocs = atLeast(100);
for (int i = 0; i < numDocs; i++) {
doc = new Document();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,19 +76,20 @@ public void testLargePartiallyMatchingToken() throws Exception {
};

StringBuilder builder = new StringBuilder();
int numChars = TestUtil.nextInt(random(), 100 * 1024, 1024 * 1024);
var rnd = nonAssertingRandom(random());
int numChars = TestUtil.nextInt(rnd, 100 * 1024, 1024 * 1024);
for (int i = 0; i < numChars; ) {
builder.append(
WordBreak_ExtendNumLet_chars[random().nextInt(WordBreak_ExtendNumLet_chars.length)]);
WordBreak_ExtendNumLet_chars[rnd.nextInt(WordBreak_ExtendNumLet_chars.length)]);
++i;
if (random().nextBoolean()) {
int numFormatExtendChars = TestUtil.nextInt(random(), 1, 8);
if (rnd.nextBoolean()) {
int numFormatExtendChars = TestUtil.nextInt(rnd, 1, 8);
for (int j = 0; j < numFormatExtendChars; ++j) {
int codepoint;
if (random().nextBoolean()) {
codepoint = WordBreak_Format_chars[random().nextInt(WordBreak_Format_chars.length)];
if (rnd.nextBoolean()) {
codepoint = WordBreak_Format_chars[rnd.nextInt(WordBreak_Format_chars.length)];
} else {
codepoint = WordBreak_Extend_chars[random().nextInt(WordBreak_Extend_chars.length)];
codepoint = WordBreak_Extend_chars[rnd.nextInt(WordBreak_Extend_chars.length)];
}
char[] chars = Character.toChars(codepoint);
builder.append(chars);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,10 @@ private void testTrieLookup(Supplier<byte[]> randomBytesSupplier, int round) thr
}

private static byte[] randomBytes() {
byte[] bytes = new byte[random().nextInt(256) + 1];
var random = nonAssertingRandom(random());
byte[] bytes = new byte[random.nextInt(256) + 1];
for (int i = 1; i < bytes.length; i++) {
bytes[i] = (byte) random().nextInt(1 << (i % 9));
bytes[i] = (byte) random.nextInt(1 << (i % 9));
}
return bytes;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import static org.apache.lucene.geo.GeoUtils.MIN_LAT_INCL;
import static org.apache.lucene.geo.GeoUtils.MIN_LON_INCL;

import com.carrotsearch.randomizedtesting.RandomizedTest;
import java.util.Random;
import org.apache.lucene.tests.util.LuceneTestCase;
import org.apache.lucene.tests.util.TestUtil;
Expand All @@ -42,8 +43,8 @@ public class TestGeoEncodingUtils extends LuceneTestCase {
*/
public void testLatitudeQuantization() throws Exception {
final double LATITUDE_DECODE = 180.0D / (0x1L << 32);
Random random = random();
for (int i = 0; i < 10000; i++) {
Random random = nonAssertingRandom(random());
for (int i = 0; i < RandomizedTest.randomIntBetween(1000, 10000); i++) {
int encoded = random.nextInt();
double min = MIN_LAT_INCL + (encoded - (long) Integer.MIN_VALUE) * LATITUDE_DECODE;
double decoded = decodeLatitude(encoded);
Expand Down Expand Up @@ -92,8 +93,8 @@ public void testLatitudeQuantization() throws Exception {
*/
public void testLongitudeQuantization() throws Exception {
final double LONGITUDE_DECODE = 360.0D / (0x1L << 32);
Random random = random();
for (int i = 0; i < 10000; i++) {
Random random = nonAssertingRandom(random());
for (int i = 0; i < RandomizedTest.randomIntBetween(1000, 10000); i++) {
int encoded = random.nextInt();
double min = MIN_LON_INCL + (encoded - (long) Integer.MIN_VALUE) * LONGITUDE_DECODE;
double decoded = decodeLongitude(encoded);
Expand Down
24 changes: 13 additions & 11 deletions lucene/core/src/test/org/apache/lucene/geo/TestXYRectangle.java
Original file line number Diff line number Diff line change
Expand Up @@ -139,17 +139,19 @@ public void testEqualsAndHashCode() {

/** make sure that if a point is inside a circle, it is inside of the bbox as well */
public void testRandomCircleToBBox() {
var random = nonAssertingRandom(random());

int iters = atLeast(100);
for (int iter = 0; iter < iters; iter++) {

float centerX = ShapeTestUtil.nextFloat(random());
float centerY = ShapeTestUtil.nextFloat(random());
float centerX = ShapeTestUtil.nextFloat(random);
float centerY = ShapeTestUtil.nextFloat(random);

final float radius;
if (random().nextBoolean()) {
radius = random().nextFloat() * TestUtil.nextInt(random(), 1, 100000);
if (random.nextBoolean()) {
radius = random.nextFloat() * TestUtil.nextInt(random, 1, 100000);
} else {
radius = Math.abs(ShapeTestUtil.nextFloat(random()));
radius = Math.abs(ShapeTestUtil.nextFloat(random));
}

XYRectangle bbox = XYRectangle.fromPointDistance(centerX, centerY, radius);
Expand All @@ -159,16 +161,16 @@ public void testRandomCircleToBBox() {
for (int i = 0; i < numPointsToTry; i++) {

double x;
if (random().nextBoolean()) {
x = Math.min(Float.MAX_VALUE, centerX + radius + random().nextDouble());
if (random.nextBoolean()) {
x = Math.min(Float.MAX_VALUE, centerX + radius + random.nextDouble());
} else {
x = Math.max(-Float.MAX_VALUE, centerX + radius - random().nextDouble());
x = Math.max(-Float.MAX_VALUE, centerX + radius - random.nextDouble());
}
double y;
if (random().nextBoolean()) {
y = Math.min(Float.MAX_VALUE, centerY + radius + random().nextDouble());
if (random.nextBoolean()) {
y = Math.min(Float.MAX_VALUE, centerY + radius + random.nextDouble());
} else {
y = Math.max(-Float.MAX_VALUE, centerY + radius - random().nextDouble());
y = Math.max(-Float.MAX_VALUE, centerY + radius - random.nextDouble());
}

// cartesian says it's within the circle:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,14 @@ private static DirectoryReader reader(Directory dir) throws IOException {
private static <C extends Collector> Object collectAll(
LeafReaderContext ctx, Collection<Integer> values, CollectorManager<C, ?> collectorManager)
throws IOException {
var rnd = nonAssertingRandom(random());

List<C> collectors = new ArrayList<>();
C collector = collectorManager.newCollector();
collectors.add(collector);
LeafCollector leafCollector = collector.getLeafCollector(ctx);
for (Integer v : values) {
if (random().nextInt(10) == 1) {
if (rnd.nextInt(10) == 1) {
collector = collectorManager.newCollector();
collectors.add(collector);
leafCollector = collector.getLeafCollector(ctx);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,21 +160,21 @@ public float getMaxScore(int upTo) throws IOException {
}

private static FixedBitSet randomSet(int maxDoc) {
final int step = TestUtil.nextInt(random(), 1, 10);
var random = nonAssertingRandom(random());
final int step = TestUtil.nextInt(random, 1, 10);
FixedBitSet set = new FixedBitSet(maxDoc);
for (int doc = random().nextInt(step);
doc < maxDoc;
doc += TestUtil.nextInt(random(), 1, step)) {
for (int doc = random.nextInt(step); doc < maxDoc; doc += TestUtil.nextInt(random, 1, step)) {
set.set(doc);
}
return set;
}

private static FixedBitSet clearRandomBits(FixedBitSet other) {
var random = nonAssertingRandom(random());
final FixedBitSet set = new FixedBitSet(other.length());
set.or(other);
for (int i = 0; i < set.length(); ++i) {
if (random().nextBoolean()) {
if (random.nextBoolean()) {
set.clear(i);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,9 @@ private static <C extends Collector> Object collectAll(
C collector = collectorManager.newCollector();
collectors.add(collector);
LeafCollector leafCollector = collector.getLeafCollector(ctx);
Random random = nonAssertingRandom(random());
for (Integer v : values) {
if (random().nextInt(10) == 1) {
if (random.nextInt(10) == 1) {
collector = collectorManager.newCollector();
collectors.add(collector);
leafCollector = collector.getLeafCollector(ctx);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public void testRandomizedWrites() throws IOException {
protected static List<IOConsumer<DataInput>> addRandomData(
DataOutput dst, Random rnd, int maxAddCalls) throws IOException {
try {
rnd = LuceneTestCase.nonAssertingRandom(rnd);
List<IOConsumer<DataInput>> reply = new ArrayList<>();
for (int i = 0; i < maxAddCalls; i++) {
reply.add(RandomPicks.randomFrom(rnd, GENERATORS).apply(dst, rnd));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
*/
package org.apache.lucene.store;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static com.carrotsearch.randomizedtesting.RandomizedTest.randomBoolean;
import static com.carrotsearch.randomizedtesting.RandomizedTest.randomBytesOfLength;
import static com.carrotsearch.randomizedtesting.RandomizedTest.randomIntBetween;
import static com.carrotsearch.randomizedtesting.RandomizedTest.randomLongBetween;

import com.carrotsearch.randomizedtesting.RandomizedTest;
import com.carrotsearch.randomizedtesting.Xoroshiro128PlusRandom;
import com.carrotsearch.randomizedtesting.annotations.Timeout;
import java.io.EOFException;
import java.io.IOException;
Expand All @@ -32,7 +32,7 @@
import org.apache.lucene.util.IOConsumer;
import org.junit.Test;

public final class TestByteBuffersDataInput extends RandomizedTest {
public final class TestByteBuffersDataInput extends LuceneTestCase {
@Test
public void testSanity() throws IOException {
ByteBuffersDataOutput out = new ByteBuffersDataOutput();
Expand Down Expand Up @@ -69,10 +69,9 @@ public void testSanity() throws IOException {
public void testRandomReads() throws Exception {
ByteBuffersDataOutput dst = new ByteBuffersDataOutput();

long seed = randomLong();
int max = LuceneTestCase.TEST_NIGHTLY ? 1_000_000 : 100_000;
List<IOConsumer<DataInput>> reply =
TestByteBuffersDataOutput.addRandomData(dst, new Xoroshiro128PlusRandom(seed), max);
TestByteBuffersDataOutput.addRandomData(dst, nonAssertingRandom(random()), max);

ByteBuffersDataInput src = dst.toDataInput();
for (IOConsumer<DataInput> c : reply) {
Expand All @@ -94,10 +93,9 @@ public void testRandomReadsOnSlices() throws Exception {
byte[] prefix = new byte[randomIntBetween(0, 1024 * 8)];
dst.writeBytes(prefix);

long seed = randomLong();
int max = 10_000;
int max = atLeast(5000);
List<IOConsumer<DataInput>> reply =
TestByteBuffersDataOutput.addRandomData(dst, new Xoroshiro128PlusRandom(seed), max);
TestByteBuffersDataOutput.addRandomData(dst, nonAssertingRandom(random()), max);

byte[] suffix = new byte[randomIntBetween(0, 1024 * 8)];
dst.writeBytes(suffix);
Expand Down Expand Up @@ -150,10 +148,9 @@ public void testSeekAndSkip() throws Exception {
dst.writeBytes(prefix);
}

long seed = randomLong();
int max = 1000;
List<IOConsumer<DataInput>> reply =
TestByteBuffersDataOutput.addRandomData(dst, new Xoroshiro128PlusRandom(seed), max);
TestByteBuffersDataOutput.addRandomData(dst, random(), max);

ByteBuffersDataInput in = dst.toDataInput().slice(prefix.length, dst.size() - prefix.length);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public void testAceWithThreads() throws Exception {

try (Directory dir = getDirectory(createTempDir("testAceWithThreads"))) {
try (IndexOutput out = dir.createOutput("test", IOContext.DEFAULT)) {
final Random random = random();
final Random random = nonAssertingRandom(random());
for (int i = 0; i < nInts; i++) {
out.writeInt(random.nextInt());
}
Expand Down
27 changes: 10 additions & 17 deletions lucene/core/src/test/org/apache/lucene/util/TestMSBRadixSorter.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,41 +85,34 @@ public void testTwoValues() {
}

private void testRandom(int commonPrefixLen, int maxLen) {
var random = nonAssertingRandom(random());
byte[] commonPrefix = new byte[commonPrefixLen];
random().nextBytes(commonPrefix);
final int len = random().nextInt(100000);
BytesRef[] bytes = new BytesRef[len + random().nextInt(50)];
random.nextBytes(commonPrefix);
final int len = random.nextInt(100000);
BytesRef[] bytes = new BytesRef[len + random.nextInt(50)];
for (int i = 0; i < len; ++i) {
byte[] b = new byte[commonPrefixLen + random().nextInt(maxLen)];
random().nextBytes(b);
byte[] b = new byte[commonPrefixLen + random.nextInt(maxLen)];
random.nextBytes(b);
System.arraycopy(commonPrefix, 0, b, 0, commonPrefixLen);
bytes[i] = new BytesRef(b);
}
test(bytes, len);
}

public void testRandom() {
for (int iter = 0; iter < 10; ++iter) {
testRandom(0, 10);
}
testRandom(0, 10);
}

public void testRandomWithLotsOfDuplicates() {
for (int iter = 0; iter < 10; ++iter) {
testRandom(0, 2);
}
testRandom(0, 2);
}

public void testRandomWithSharedPrefix() {
for (int iter = 0; iter < 10; ++iter) {
testRandom(TestUtil.nextInt(random(), 1, 30), 10);
}
testRandom(TestUtil.nextInt(random(), 1, 30), 10);
}

public void testRandomWithSharedPrefixAndLotsOfDuplicates() {
for (int iter = 0; iter < 10; ++iter) {
testRandom(TestUtil.nextInt(random(), 1, 30), 2);
}
testRandom(TestUtil.nextInt(random(), 1, 30), 2);
}

public void testRandom2() {
Expand Down
Loading
Loading