diff --git a/lucene/src/test/org/apache/lucene/search/BaseTestRangeFilter.java b/lucene/src/test/org/apache/lucene/search/BaseTestRangeFilter.java index 75833c2683e..0ac5192350b 100644 --- a/lucene/src/test/org/apache/lucene/search/BaseTestRangeFilter.java +++ b/lucene/src/test/org/apache/lucene/search/BaseTestRangeFilter.java @@ -115,10 +115,6 @@ public class BaseTestRangeFilter extends LuceneTestCase { private static IndexReader build(Random random, TestIndex index) throws IOException { /* build an index */ - RandomIndexWriter writer = new RandomIndexWriter(random, index.index, - newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()) - .setOpenMode(OpenMode.CREATE).setMaxBufferedDocs(_TestUtil.nextInt(random, 50, 1000))); - _TestUtil.reduceOpenFiles(writer.w); Document doc = new Document(); Field idField = newField(random, "id", "", Field.Store.YES, Field.Index.NOT_ANALYZED); @@ -128,11 +124,16 @@ public class BaseTestRangeFilter extends LuceneTestCase { doc.add(randField); doc.add(bodyField); - int minCount = 0; - int maxCount = 0; - + RandomIndexWriter writer = new RandomIndexWriter(random, index.index, + newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()) + .setOpenMode(OpenMode.CREATE).setMaxBufferedDocs(_TestUtil.nextInt(random, 50, 1000))); while(true) { + int minCount = 0; + int maxCount = 0; + + _TestUtil.reduceOpenFiles(writer.w); + for (int d = minId; d <= maxId; d++) { idField.setValue(pad(d)); int r = index.allowNegativeRandomInts ? random.nextInt() : random @@ -160,15 +161,14 @@ public class BaseTestRangeFilter extends LuceneTestCase { // 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; + IndexReader ir = writer.getReader(); + writer.close(); + return ir; } // try again + writer.deleteAll(); } - - IndexReader ir = writer.getReader(); - writer.close(); - return ir; } @Test