LUCENE-4398: add test case

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1386922 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael McCandless 2012-09-18 00:10:04 +00:00
parent 2cbfdb7f00
commit 0ee3cb69e7
2 changed files with 48 additions and 2 deletions

View File

@ -1889,4 +1889,50 @@ public class TestIndexWriter extends LuceneTestCase {
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();
}
}

View File

@ -80,7 +80,7 @@ public class RandomCodec extends Lucene40Codec {
}
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 Lucene40Codec {
Collections.shuffle(formats, random);
// Avoid too many open files:
formats.subList(4, formats.size()).clear();
formats = formats.subList(0, 4);
}
public RandomCodec(Random random) {