SOLR-17189: Fix DockMakerTest.testRealisticUnicode (#2327)
These strings must not have whitespace.
Includes a fix for the non-repeatability of the randomness. It's not perfect -- the RandomizedContext seed isn't being passed in unless it is set explicitly via the standard tests.seed property.
diff --git a/solr/benchmark/src/java/org/apache/solr/bench/BaseBenchState.java b/solr/benchmark/src/java/org/apache/solr/bench/BaseBenchState.java
index e3b5012..f45ffaf 100644
--- a/solr/benchmark/src/java/org/apache/solr/bench/BaseBenchState.java
+++ b/solr/benchmark/src/java/org/apache/solr/bench/BaseBenchState.java
@@ -41,9 +41,29 @@
@State(Scope.Benchmark)
public class BaseBenchState {
- private static final long RANDOM_SEED = System.nanoTime();
+ public static final long RANDOM_SEED;
- private static final SplittableRandom random = new SplittableRandom(getInitRandomSeed());
+ static {
+ Long seed = Long.getLong("solr.bench.seed");
+
+ if (seed == null) {
+ String prop = System.getProperty("tests.seed"); // RandomizedTesting framework
+ if (prop != null) {
+ // if there is a test failure we remain reproducible based on the test seed:
+ prop = prop.split(":")[0]; // main seed
+ seed = Long.parseUnsignedLong(prop, 16);
+ } else {
+ seed = System.nanoTime();
+ }
+ }
+
+ log("");
+ log("benchmark random seed: " + seed);
+
+ RANDOM_SEED = seed;
+ }
+
+ private static final SplittableRandom random = new SplittableRandom(RANDOM_SEED);
/**
* Gets random seed.
@@ -134,17 +154,4 @@
}
}
}
-
- private static Long getInitRandomSeed() {
- Long seed = Long.getLong("solr.bench.seed");
-
- if (seed == null) {
- seed = RANDOM_SEED;
- }
-
- log("");
- log("benchmark random seed: " + seed);
-
- return seed;
- }
}
diff --git a/solr/benchmark/src/java/org/apache/solr/bench/generators/StringsDSL.java b/solr/benchmark/src/java/org/apache/solr/bench/generators/StringsDSL.java
index 33d573c..df29672 100644
--- a/solr/benchmark/src/java/org/apache/solr/bench/generators/StringsDSL.java
+++ b/solr/benchmark/src/java/org/apache/solr/bench/generators/StringsDSL.java
@@ -58,7 +58,7 @@
words.add(scanner.nextLine());
}
}
- Collections.shuffle(words, new Random(BaseBenchState.getRandomSeed()));
+ Collections.shuffle(words, new Random(BaseBenchState.RANDOM_SEED));
WORD_SIZE = words.size();
}
@@ -108,18 +108,17 @@
}
/**
- * Realistic unicode realistic unicode generator builder.
+ * Realistic unicode generator builder. No whitespace.
*
* @param minLength the min length
* @param maxLength the max length
* @return the realistic unicode generator builder
*/
public RealisticUnicodeGeneratorBuilder realisticUnicode(int minLength, int maxLength) {
- return new RealisticUnicodeGeneratorBuilder(
- new SolrGen<>() {
+ final var randomUnicodeGen =
+ new SolrGen<String>() {
@Override
public String generate(SolrRandomnessSource in) {
-
int block =
integers()
.between(0, blockStarts.length - 1)
@@ -131,7 +130,19 @@
.describedAs("Realistic Unicode")
.generate(in);
}
- });
+ }.assuming(
+ str -> {
+ // The string must not have whitespace
+ for (int i = 0; i < str.length(); i++) {
+ char c = str.charAt(i);
+ if (Character.isWhitespace(c)) {
+ return false;
+ }
+ }
+ return true;
+ });
+ return new RealisticUnicodeGeneratorBuilder(
+ new SolrDescribingGenerator<>(randomUnicodeGen, Objects::toString));
}
/**