You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by us...@apache.org on 2015/09/08 17:02:01 UTC

svn commit: r1701816 - in /lucene/dev/branches/lucene_solr_5_3: ./ lucene/ lucene/test-framework/ lucene/test-framework/src/java/org/apache/lucene/util/ solr/ solr/core/ solr/core/src/test/org/apache/solr/search/

Author: uschindler
Date: Tue Sep  8 15:02:01 2015
New Revision: 1701816

URL: http://svn.apache.org/r1701816
Log:
Backport:
LUCENE-6760: Prevent test failure in Java 9 b76+
SOLR-7958: Move TestUtil#randomWhitespace to the only Solr test that is using it
LUCENE-6760: if the list of whitspace characters changes again in a future JVM, fail fast with a clear error that the test needs corrected -- even if jvm assertions are disabled OR we get really lucky with the chars radnomly selected (merge r1698227)

Modified:
    lucene/dev/branches/lucene_solr_5_3/   (props changed)
    lucene/dev/branches/lucene_solr_5_3/lucene/   (props changed)
    lucene/dev/branches/lucene_solr_5_3/lucene/CHANGES.txt   (contents, props changed)
    lucene/dev/branches/lucene_solr_5_3/lucene/JRE_VERSION_MIGRATION.txt   (contents, props changed)
    lucene/dev/branches/lucene_solr_5_3/lucene/test-framework/   (props changed)
    lucene/dev/branches/lucene_solr_5_3/lucene/test-framework/src/java/org/apache/lucene/util/TestUtil.java
    lucene/dev/branches/lucene_solr_5_3/solr/   (props changed)
    lucene/dev/branches/lucene_solr_5_3/solr/core/   (props changed)
    lucene/dev/branches/lucene_solr_5_3/solr/core/src/test/org/apache/solr/search/ReturnFieldsTest.java

Modified: lucene/dev/branches/lucene_solr_5_3/lucene/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene_solr_5_3/lucene/CHANGES.txt?rev=1701816&r1=1701815&r2=1701816&view=diff
==============================================================================
--- lucene/dev/branches/lucene_solr_5_3/lucene/CHANGES.txt (original)
+++ lucene/dev/branches/lucene_solr_5_3/lucene/CHANGES.txt Tue Sep  8 15:02:01 2015
@@ -11,6 +11,13 @@ Bug Fixes
 * LUCENE-6774: Remove classloader hack in MorfologikFilter. (Robert Muir,
   Uwe Schindler)
 
+Tests
+
+* LUCENE-6760, SOLR-7958: Move TestUtil#randomWhitespace to the only
+  Solr test that is using it. The method is not useful for Lucene tests
+  (and easily breaks, e.g., in Java 9 caused by Unicode version updates).
+  (Uwe Schindler)
+
 ======================= Lucene 5.3.0 =======================
 
 New Features

Modified: lucene/dev/branches/lucene_solr_5_3/lucene/JRE_VERSION_MIGRATION.txt
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene_solr_5_3/lucene/JRE_VERSION_MIGRATION.txt?rev=1701816&r1=1701815&r2=1701816&view=diff
==============================================================================
--- lucene/dev/branches/lucene_solr_5_3/lucene/JRE_VERSION_MIGRATION.txt (original)
+++ lucene/dev/branches/lucene_solr_5_3/lucene/JRE_VERSION_MIGRATION.txt Tue Sep  8 15:02:01 2015
@@ -17,6 +17,7 @@ For reference, JRE major versions with t
  * Java 6, Unicode 4.0
  * Java 7, Unicode 6.0
  * Java 8, Unicode 6.2
+ * Java 9 (not yet released / offcially supported by Lucene), Unicode 7.0
 
 In general, whether or not you need to re-index largely depends upon the data that
 you are searching, and what was changed in any given Unicode version. For example, 

Modified: lucene/dev/branches/lucene_solr_5_3/lucene/test-framework/src/java/org/apache/lucene/util/TestUtil.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene_solr_5_3/lucene/test-framework/src/java/org/apache/lucene/util/TestUtil.java?rev=1701816&r1=1701815&r2=1701816&view=diff
==============================================================================
--- lucene/dev/branches/lucene_solr_5_3/lucene/test-framework/src/java/org/apache/lucene/util/TestUtil.java (original)
+++ lucene/dev/branches/lucene_solr_5_3/lucene/test-framework/src/java/org/apache/lucene/util/TestUtil.java Tue Sep  8 15:02:01 2015
@@ -1202,24 +1202,6 @@ public final class TestUtil {
     }
   }
 
-  /**
-   * Returns a random string in the specified length range consisting 
-   * entirely of whitespace characters 
-   * @see #WHITESPACE_CHARACTERS
-   */
-  public static String randomWhitespace(Random r, int minLength, int maxLength) {
-    final int end = nextInt(r, minLength, maxLength);
-    StringBuilder out = new StringBuilder();
-    for (int i = 0; i < end; i++) {
-      int offset = nextInt(r, 0, WHITESPACE_CHARACTERS.length-1);
-      char c = WHITESPACE_CHARACTERS[offset];
-      // sanity check
-      Assert.assertTrue("Not really whitespace? (@"+offset+"): " + c, Character.isWhitespace(c));
-      out.append(c);
-    }
-    return out.toString();
-  }
-
   public static String randomAnalysisString(Random random, int maxLength, boolean simple) {
     assert maxLength >= 0;
 
@@ -1319,36 +1301,4 @@ public final class TestUtil {
     }
     return ram;
   }
-  
-  /** List of characters that match {@link Character#isWhitespace} */
-  public static final char[] WHITESPACE_CHARACTERS = new char[] {
-    // :TODO: is this list exhaustive?
-    '\u0009',
-    '\n',    
-    '\u000B',
-    '\u000C',
-    '\r',    
-    '\u001C',
-    '\u001D',
-    '\u001E',
-    '\u001F',
-    '\u0020',
-    // '\u0085', faild sanity check?
-    '\u1680',
-    '\u180E',
-    '\u2000',
-    '\u2001',
-    '\u2002',
-    '\u2003',
-    '\u2004',
-    '\u2005',
-    '\u2006',
-    '\u2008',
-    '\u2009',
-    '\u200A',
-    '\u2028',
-    '\u2029',
-    '\u205F',
-    '\u3000',
-  };
 }

Modified: lucene/dev/branches/lucene_solr_5_3/solr/core/src/test/org/apache/solr/search/ReturnFieldsTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene_solr_5_3/solr/core/src/test/org/apache/solr/search/ReturnFieldsTest.java?rev=1701816&r1=1701815&r2=1701816&view=diff
==============================================================================
--- lucene/dev/branches/lucene_solr_5_3/solr/core/src/test/org/apache/solr/search/ReturnFieldsTest.java (original)
+++ lucene/dev/branches/lucene_solr_5_3/solr/core/src/test/org/apache/solr/search/ReturnFieldsTest.java Tue Sep  8 15:02:01 2015
@@ -20,28 +20,16 @@ package org.apache.solr.search;
 import org.apache.lucene.util.TestUtil;
 import org.apache.solr.SolrTestCaseJ4;
 import org.apache.solr.response.transform.*;
-
 import org.junit.BeforeClass;
 import org.junit.Test;
 
+import java.util.Locale;
 import java.util.Random;
 
 public class ReturnFieldsTest extends SolrTestCaseJ4 {
 
   // :TODO: datatypes produced by the functions used may change
 
-  /**
-   * values of the fl param that mean all real fields
-   */
-  private static String[] ALL_REAL_FIELDS = new String[] { "", "*" };
-
-  /**
-   * values of the fl param that mean all real fields and score
-   */
-  private static String[] SCORE_AND_REAL_FIELDS = new String[] {
-      "score", "score,*", "*,score"
-  };
-
   @BeforeClass
   public static void beforeClass() throws Exception {
     System.setProperty("enable.update.log", "false"); // schema12 doesn't support _version_
@@ -341,14 +329,14 @@ public class ReturnFieldsTest extends So
       final boolean aliasId = r.nextBoolean();
       final boolean aliasFoo = r.nextBoolean();
 
-      final String id = TestUtil.randomWhitespace(r, 0, 3) +
+      final String id = randomWhitespace(r, 0, 3) +
         (aliasId ? "aliasId:" : "") +
         "id" + 
-        TestUtil.randomWhitespace(r, 1, 3);
-      final String foo_i = TestUtil.randomWhitespace(r, 0, 3) +
+        randomWhitespace(r, 1, 3);
+      final String foo_i = randomWhitespace(r, 0, 3) +
         (aliasFoo ? "aliasFoo:" : "") +
         "foo_i" + 
-        TestUtil.randomWhitespace(r, 0, 3);
+        randomWhitespace(r, 0, 3);
 
       final String fl = id + (r.nextBoolean() ? "" : ",") + foo_i;
       ReturnFields rf = new SolrReturnFields(req("fl", fl));
@@ -366,4 +354,67 @@ public class ReturnFieldsTest extends So
     }
   }
 
+  /** List of characters that match {@link Character#isWhitespace} */
+  private static final char[] WHITESPACE_CHARACTERS = new char[] {
+    // :TODO: is this list exhaustive?
+    '\u0009',
+    '\n',    
+    '\u000B',
+    '\u000C',
+    '\r',    
+    '\u001C',
+    '\u001D',
+    '\u001E',
+    '\u001F',
+    '\u0020',
+    // '\u0085', failed sanity check?
+    '\u1680',
+    // '\u180E', no longer whitespace in Unicode 7.0 (Java 9)!
+    '\u2000',
+    '\u2001',
+    '\u2002',
+    '\u2003',
+    '\u2004',
+    '\u2005',
+    '\u2006',
+    '\u2008',
+    '\u2009',
+    '\u200A',
+    '\u2028',
+    '\u2029',
+    '\u205F',
+    '\u3000',
+  };
+
+  static {
+    // if the JVM/unicode can redefine whitespace once (LUCENE-6760), it might happen again
+    // in the future.  if that happens, fail early with a clera msg, even if java asserts
+    // (used in randomWhitespace) are disbled
+    
+    for (int offset = 0; offset < WHITESPACE_CHARACTERS.length; offset++) {
+      char c = WHITESPACE_CHARACTERS[offset];
+      if (! Character.isWhitespace(c) ) {
+        fail(String.format(Locale.ENGLISH, "Not really whitespace? New JVM/Unicode definitions? WHITESPACE_CHARACTERS[%d] is '\\u%04X'", offset, (int) c));
+      }
+    }
+  }
+  
+  /**
+   * Returns a random string in the specified length range consisting 
+   * entirely of whitespace characters 
+   * @see #WHITESPACE_CHARACTERS
+   */
+  public static String randomWhitespace(Random r, int minLength, int maxLength) {
+    final int end = TestUtil.nextInt(r, minLength, maxLength);
+    StringBuilder out = new StringBuilder();
+    for (int i = 0; i < end; i++) {
+      int offset = TestUtil.nextInt(r, 0, WHITESPACE_CHARACTERS.length-1);
+      char c = WHITESPACE_CHARACTERS[offset];
+      // sanity check
+      assert Character.isWhitespace(c) : String.format(Locale.ENGLISH, "Not really whitespace? WHITESPACE_CHARACTERS[%d] is '\\u%04X'", offset, (int) c);
+      out.append(c);
+    }
+    return out.toString();
+  }
+
 }