lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mikemcc...@apache.org
Subject svn commit: r1386921 - in /lucene/dev/branches/branch_4x/lucene: core/src/test/org/apache/lucene/index/TestIndexWriter.java test-framework/src/java/org/apache/lucene/index/RandomCodec.java
Date Tue, 18 Sep 2012 00:09:08 GMT
Author: mikemccand
Date: Tue Sep 18 00:09:08 2012
New Revision: 1386921

URL: http://svn.apache.org/viewvc?rev=1386921&view=rev
Log:
LUCENE-4398: add test case

Modified:
    lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/index/TestIndexWriter.java
    lucene/dev/branches/branch_4x/lucene/test-framework/src/java/org/apache/lucene/index/RandomCodec.java

Modified: lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/index/TestIndexWriter.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/index/TestIndexWriter.java?rev=1386921&r1=1386920&r2=1386921&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/index/TestIndexWriter.java
(original)
+++ lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/index/TestIndexWriter.java
Tue Sep 18 00:09:08 2012
@@ -1889,4 +1889,50 @@ public class TestIndexWriter extends Luc
       dir.close();
     }
   }
+
+  // LUCENE-4398
+  public void testRotatingFieldNames() throws Exception {
+    Directory dir = newFSDirectory(_TestUtil.getTempDir("TestIndexWriter.testChangingFields"));
+    IndexWriterConfig iwc = new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random()));
+    iwc.setRAMBufferSizeMB(0.2);
+    iwc.setMaxBufferedDocs(-1);
+    IndexWriter w = new IndexWriter(dir, iwc);
+    int upto = 0;
+
+    FieldType ft = new FieldType(TextField.TYPE_NOT_STORED);
+    ft.setOmitNorms(true);
+
+    int firstDocCount = -1;
+    for(int iter=0;iter<10;iter++) {
+      final int startFlushCount = w.getFlushCount();
+      int docCount = 0;
+      while(w.getFlushCount() == startFlushCount) {
+        Document doc = new Document();
+        for(int i=0;i<10;i++) {
+          doc.add(new Field("field" + (upto++), "content", ft));
+        }
+        w.addDocument(doc);
+        docCount++;
+      }
+
+      if (VERBOSE) {
+        System.out.println("TEST: iter=" + iter + " flushed after docCount=" + docCount);
+      }
+
+      if (iter == 0) {
+        firstDocCount = docCount;
+      }
+
+      assertTrue("flushed after too few docs: first segment flushed at docCount=" + firstDocCount
+ ", but current segment flushed after docCount=" + docCount + "; iter=" + iter, ((float)
docCount) / firstDocCount > 0.9);
+
+      if (upto > 5000) {
+        // Start re-using field names after a while
+        // ... important because otherwise we can OOME due
+        // to too many FieldInfo instances.
+        upto = 0;
+      }
+    }
+    w.close();
+    dir.close();
+  }
 }

Modified: lucene/dev/branches/branch_4x/lucene/test-framework/src/java/org/apache/lucene/index/RandomCodec.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/test-framework/src/java/org/apache/lucene/index/RandomCodec.java?rev=1386921&r1=1386920&r2=1386921&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/test-framework/src/java/org/apache/lucene/index/RandomCodec.java
(original)
+++ lucene/dev/branches/branch_4x/lucene/test-framework/src/java/org/apache/lucene/index/RandomCodec.java
Tue Sep 18 00:09:08 2012
@@ -80,7 +80,7 @@ public class RandomCodec extends Lucene4
       }
       previousMappings.put(name, codec);
       // Safety:
-      assert previousMappings.size() < 10000;
+      assert previousMappings.size() < 10000: "test went insane";
     }
     return codec;
   }
@@ -119,7 +119,7 @@ public class RandomCodec extends Lucene4
     Collections.shuffle(formats, random);
 
     // Avoid too many open files:
-    formats.subList(4, formats.size()).clear();
+    formats = formats.subList(0, 4);
   }
 
   public RandomCodec(Random random) {



Mime
View raw message