This is an automated email from the ASF dual-hosted git repository.

dsmiley pushed a commit to branch branch_9x
in repository https://gitbox.apache.org/repos/asf/solr.git

commit fd54d2a7e692d30f01a341030c3401880d2c586d
Author: David Smiley <[email protected]>
AuthorDate: Wed Apr 10 08:48:05 2024 -0400

    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.
    
    (cherry picked from commit 453a23b7e9e0610a17ceb8b6eed56946c57ffadf)
---
 .../java/org/apache/solr/bench/BaseBenchState.java | 37 +++++++++++++---------
 .../apache/solr/bench/generators/StringsDSL.java   | 23 ++++++++++----
 2 files changed, 39 insertions(+), 21 deletions(-)

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 e3b5012366b..f45ffaf8aa1 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 @@ import org.slf4j.LoggerFactory;
 @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 @@ public class BaseBenchState {
       }
     }
   }
-
-  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 33d573c173e..df296727aa0 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 @@ public class StringsDSL {
         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 @@ public class StringsDSL {
   }
 
   /**
-   * 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 @@ public class StringsDSL {
                 .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));
   }
 
   /**

Reply via email to