lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mikemcc...@apache.org
Subject svn commit: r1040293 - in /lucene/dev/branches/branch_3x: ./ lucene/ lucene/src/test/org/apache/lucene/index/ lucene/src/test/org/apache/lucene/search/ lucene/src/test/org/apache/lucene/store/ solr/
Date Mon, 29 Nov 2010 21:04:37 GMT
Author: mikemccand
Date: Mon Nov 29 21:04:37 2010
New Revision: 1040293

URL: http://svn.apache.org/viewvc?rev=1040293&view=rev
Log:
fix false random test failure; make private random instance for RandomIndexWriter and MockDirWrapper
so tests are reproducible from seeds when using eg CMS

Modified:
    lucene/dev/branches/branch_3x/   (props changed)
    lucene/dev/branches/branch_3x/lucene/   (props changed)
    lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/RandomIndexWriter.java
    lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/search/BaseTestRangeFilter.java
    lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/store/MockDirectoryWrapper.java
    lucene/dev/branches/branch_3x/solr/   (props changed)

Modified: lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/RandomIndexWriter.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/RandomIndexWriter.java?rev=1040293&r1=1040292&r2=1040293&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/RandomIndexWriter.java
(original)
+++ lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/RandomIndexWriter.java
Mon Nov 29 21:04:37 2010
@@ -55,7 +55,10 @@ public class RandomIndexWriter implement
 
     public MockIndexWriter(Random r,Directory dir, IndexWriterConfig conf) throws IOException
{
       super(dir, conf);
-      this.r = r;
+      // must make a private random since our methods are
+      // called from different threads; else test failures may
+      // not be reproducible from the original seed
+      this.r = new Random(r.nextInt());
     }
 
     @Override

Modified: lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/search/BaseTestRangeFilter.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/search/BaseTestRangeFilter.java?rev=1040293&r1=1040292&r2=1040293&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/search/BaseTestRangeFilter.java
(original)
+++ lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/search/BaseTestRangeFilter.java
Mon Nov 29 21:04:37 2010
@@ -127,20 +127,43 @@ public class BaseTestRangeFilter extends
     doc.add(idField);
     doc.add(randField);
     doc.add(bodyField);
-    
-    for (int d = minId; d <= maxId; d++) {
-      idField.setValue(pad(d));
-      int r = index.allowNegativeRandomInts ? random.nextInt() : random
+
+    int minCount = 0;
+    int maxCount = 0;
+
+    while(true) {
+
+      for (int d = minId; d <= maxId; d++) {
+        idField.setValue(pad(d));
+        int r = index.allowNegativeRandomInts ? random.nextInt() : random
           .nextInt(Integer.MAX_VALUE);
-      if (index.maxR < r) {
-        index.maxR = r;
+        if (index.maxR < r) {
+          index.maxR = r;
+          maxCount = 1;
+        } else if (index.maxR == r) {
+          maxCount++;
+        }
+
+        if (r < index.minR) {
+          index.minR = r;
+          minCount = 1;
+        } else if (r == index.minR) {
+          minCount++;
+        }
+        randField.setValue(pad(r));
+        bodyField.setValue("body");
+        writer.addDocument(doc);
       }
-      if (r < index.minR) {
-        index.minR = r;
+
+      if (minCount == 1 && maxCount == 1) {
+        // our subclasses rely on only 1 doc having the min or
+        // max, so, we loop until we satisfy that.  it should be
+        // exceedingly rare (Yonik calculates 1 in ~429,000)
+        // times) that this loop requires more than one try:
+        break;
       }
-      randField.setValue(pad(r));
-      bodyField.setValue("body");
-      writer.addDocument(doc);
+
+      // try again
     }
     
     IndexReader ir = writer.getReader();

Modified: lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/store/MockDirectoryWrapper.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/store/MockDirectoryWrapper.java?rev=1040293&r1=1040292&r2=1040293&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/store/MockDirectoryWrapper.java
(original)
+++ lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/store/MockDirectoryWrapper.java
Mon Nov 29 21:04:37 2010
@@ -80,7 +80,10 @@ public class MockDirectoryWrapper extend
 
   public MockDirectoryWrapper(Random random, Directory delegate) {
     this.delegate = delegate;
-    this.randomState = random;
+    // must make a private random since our methods are
+    // called from different threads; else test failures may
+    // not be reproducible from the original seed
+    this.randomState = new Random(random.nextInt());
     init();
   }
 



Mime
View raw message