lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rm...@apache.org
Subject svn commit: r1648189 - in /lucene/dev/branches/branch_5x: ./ lucene/ lucene/test-framework/ lucene/test-framework/src/java/org/apache/lucene/index/ lucene/test-framework/src/java/org/apache/lucene/util/
Date Sun, 28 Dec 2014 11:21:05 GMT
Author: rmuir
Date: Sun Dec 28 11:21:05 2014
New Revision: 1648189

URL: http://svn.apache.org/r1648189
Log:
LUCENE-6135: renumber fields randomly in tests

Added:
    lucene/dev/branches/branch_5x/lucene/test-framework/src/java/org/apache/lucene/index/MismatchedDirectoryReader.java
      - copied unchanged from r1648188, lucene/dev/trunk/lucene/test-framework/src/java/org/apache/lucene/index/MismatchedDirectoryReader.java
    lucene/dev/branches/branch_5x/lucene/test-framework/src/java/org/apache/lucene/index/MismatchedLeafReader.java
      - copied unchanged from r1648188, lucene/dev/trunk/lucene/test-framework/src/java/org/apache/lucene/index/MismatchedLeafReader.java
Modified:
    lucene/dev/branches/branch_5x/   (props changed)
    lucene/dev/branches/branch_5x/lucene/   (props changed)
    lucene/dev/branches/branch_5x/lucene/test-framework/   (props changed)
    lucene/dev/branches/branch_5x/lucene/test-framework/src/java/org/apache/lucene/index/BaseStoredFieldsFormatTestCase.java
    lucene/dev/branches/branch_5x/lucene/test-framework/src/java/org/apache/lucene/index/MockRandomMergePolicy.java
    lucene/dev/branches/branch_5x/lucene/test-framework/src/java/org/apache/lucene/util/LuceneTestCase.java

Modified: lucene/dev/branches/branch_5x/lucene/test-framework/src/java/org/apache/lucene/index/BaseStoredFieldsFormatTestCase.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/test-framework/src/java/org/apache/lucene/index/BaseStoredFieldsFormatTestCase.java?rev=1648189&r1=1648188&r2=1648189&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/test-framework/src/java/org/apache/lucene/index/BaseStoredFieldsFormatTestCase.java
(original)
+++ lucene/dev/branches/branch_5x/lucene/test-framework/src/java/org/apache/lucene/index/BaseStoredFieldsFormatTestCase.java
Sun Dec 28 11:21:05 2014
@@ -56,6 +56,7 @@ import org.apache.lucene.store.MMapDirec
 import org.apache.lucene.store.MockDirectoryWrapper;
 import org.apache.lucene.store.MockDirectoryWrapper.Throttling;
 import org.apache.lucene.util.BytesRef;
+import org.apache.lucene.util.IOUtils;
 import org.apache.lucene.util.TestUtil;
 
 import com.carrotsearch.randomizedtesting.generators.RandomInts;
@@ -763,4 +764,51 @@ public abstract class BaseStoredFieldsFo
     dir.close();
   }
 
+  /** mix up field numbers, merge, and check that data is correct */
+  public void testMismatchedFields() throws Exception {
+    Directory dirs[] = new Directory[10];
+    for (int i = 0; i < dirs.length; i++) {
+      Directory dir = newDirectory();
+      IndexWriterConfig iwc = new IndexWriterConfig(null);
+      IndexWriter iw = new IndexWriter(dir, iwc);
+      Document doc = new Document();
+      for (int j = 0; j < 10; j++) {
+        // add fields where name=value (e.g. 3=3) so we can detect if stuff gets screwed
up.
+        doc.add(new StringField(Integer.toString(j), Integer.toString(j), Field.Store.YES));
+      }
+      for (int j = 0; j < 10; j++) {
+        iw.addDocument(doc);
+      }
+      
+      DirectoryReader reader = DirectoryReader.open(iw, true);
+      // mix up fields explicitly
+      if (random().nextBoolean()) {
+        reader = new MismatchedDirectoryReader(reader, random());
+      }
+      dirs[i] = newDirectory();
+      IndexWriter adder = new IndexWriter(dirs[i], new IndexWriterConfig(null));
+      adder.addIndexes(reader);
+      adder.commit();
+      adder.close();
+      
+      IOUtils.close(reader, iw, dir);
+    }
+    
+    Directory everything = newDirectory();
+    IndexWriter iw = new IndexWriter(everything, new IndexWriterConfig(null));
+    iw.addIndexes(dirs);
+    iw.forceMerge(1);
+    
+    LeafReader ir = getOnlySegmentReader(DirectoryReader.open(iw, true));
+    for (int i = 0; i < ir.maxDoc(); i++) {
+      Document doc = ir.document(i);
+      assertEquals(10, doc.getFields().size());
+      for (int j = 0; j < 10; j++) {
+        assertEquals(Integer.toString(j), doc.get(Integer.toString(j)));
+      }
+    }
+
+    IOUtils.close(iw, ir, everything);
+    IOUtils.close(dirs);
+  }
 }

Modified: lucene/dev/branches/branch_5x/lucene/test-framework/src/java/org/apache/lucene/index/MockRandomMergePolicy.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/test-framework/src/java/org/apache/lucene/index/MockRandomMergePolicy.java?rev=1648189&r1=1648188&r2=1648189&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/test-framework/src/java/org/apache/lucene/index/MockRandomMergePolicy.java
(original)
+++ lucene/dev/branches/branch_5x/lucene/test-framework/src/java/org/apache/lucene/index/MockRandomMergePolicy.java
Sun Dec 28 11:21:05 2014
@@ -73,7 +73,7 @@ public class MockRandomMergePolicy exten
       // TODO: sometimes make more than 1 merge?
       mergeSpec = new MergeSpecification();
       final int segsToMerge = TestUtil.nextInt(random, 1, numSegments);
-      if (doNonBulkMerges) {
+      if (doNonBulkMerges && random.nextBoolean()) {
         mergeSpec.add(new MockRandomOneMerge(segments.subList(0, segsToMerge),random.nextLong()));
       } else {
         mergeSpec.add(new OneMerge(segments.subList(0, segsToMerge)));
@@ -106,7 +106,7 @@ public class MockRandomMergePolicy exten
       while(upto < eligibleSegments.size()) {
         int max = Math.min(10, eligibleSegments.size()-upto);
         int inc = max <= 2 ? max : TestUtil.nextInt(random, 2, max);
-        if (doNonBulkMerges) {
+        if (doNonBulkMerges && random.nextBoolean()) {
           mergeSpec.add(new MockRandomOneMerge(eligibleSegments.subList(upto, upto+inc),
random.nextLong()));
         } else {
           mergeSpec.add(new OneMerge(eligibleSegments.subList(upto, upto+inc)));
@@ -151,9 +151,18 @@ public class MockRandomMergePolicy exten
         readers = new ArrayList<LeafReader>(super.getMergeReaders());
         for (int i = 0; i < readers.size(); i++) {
           // wrap it (e.g. prevent bulk merge etc)
-          if (r.nextInt(4) == 0) {
+          int thingToDo = r.nextInt(7);
+          if (thingToDo == 0) {
+            // simple no-op FilterReader
             readers.set(i, new FilterLeafReader(readers.get(i)));
+          } else if (thingToDo == 1) {
+            // renumber fields
+            // NOTE: currently this only "blocks" bulk merges just by
+            // being a FilterReader. But it might find bugs elsewhere, 
+            // and maybe the situation can be improved in the future.
+            readers.set(i, new MismatchedLeafReader(readers.get(i), r));
           }
+          // otherwise, reader is unchanged
         }
       }
       return readers;

Modified: lucene/dev/branches/branch_5x/lucene/test-framework/src/java/org/apache/lucene/util/LuceneTestCase.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/test-framework/src/java/org/apache/lucene/util/LuceneTestCase.java?rev=1648189&r1=1648188&r2=1648189&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/test-framework/src/java/org/apache/lucene/util/LuceneTestCase.java
(original)
+++ lucene/dev/branches/branch_5x/lucene/test-framework/src/java/org/apache/lucene/util/LuceneTestCase.java
Sun Dec 28 11:21:05 2014
@@ -91,6 +91,8 @@ import org.apache.lucene.index.LogDocMer
 import org.apache.lucene.index.LogMergePolicy;
 import org.apache.lucene.index.MergePolicy;
 import org.apache.lucene.index.MergeScheduler;
+import org.apache.lucene.index.MismatchedDirectoryReader;
+import org.apache.lucene.index.MismatchedLeafReader;
 import org.apache.lucene.index.MockRandomMergePolicy;
 import org.apache.lucene.index.MultiDocValues;
 import org.apache.lucene.index.MultiFields;
@@ -1587,7 +1589,7 @@ public abstract class LuceneTestCase ext
       // TODO: remove this, and fix those tests to wrap before putting slow around:
       final boolean wasOriginallyAtomic = r instanceof LeafReader;
       for (int i = 0, c = random.nextInt(6)+1; i < c; i++) {
-        switch(random.nextInt(5)) {
+        switch(random.nextInt(6)) {
           case 0:
             r = SlowCompositeReaderWrapper.wrap(r);
             break;
@@ -1628,6 +1630,13 @@ public abstract class LuceneTestCase ext
               r = new AssertingDirectoryReader((DirectoryReader)r);
             }
             break;
+          case 5:
+            if (r instanceof LeafReader) {
+              r = new MismatchedLeafReader((LeafReader)r, random);
+            } else if (r instanceof DirectoryReader) {
+              r = new MismatchedDirectoryReader((DirectoryReader)r, random);
+            }
+            break;
           default:
             fail("should not get here");
         }



Mime
View raw message