You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by jp...@apache.org on 2015/08/05 16:50:33 UTC

svn commit: r1694237 - /lucene/dev/branches/branch_5x/lucene/misc/src/test/org/apache/lucene/search/TestEarlyTerminatingSortingCollector.java

Author: jpountz
Date: Wed Aug  5 14:50:32 2015
New Revision: 1694237

URL: http://svn.apache.org/r1694237
Log:
Fix test bug: the test was expecting a sorted segment but could sometimes generate a single unsorted flush segment.

Modified:
    lucene/dev/branches/branch_5x/lucene/misc/src/test/org/apache/lucene/search/TestEarlyTerminatingSortingCollector.java

Modified: lucene/dev/branches/branch_5x/lucene/misc/src/test/org/apache/lucene/search/TestEarlyTerminatingSortingCollector.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/misc/src/test/org/apache/lucene/search/TestEarlyTerminatingSortingCollector.java?rev=1694237&r1=1694236&r2=1694237&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/misc/src/test/org/apache/lucene/search/TestEarlyTerminatingSortingCollector.java (original)
+++ lucene/dev/branches/branch_5x/lucene/misc/src/test/org/apache/lucene/search/TestEarlyTerminatingSortingCollector.java Wed Aug  5 14:50:32 2015
@@ -83,7 +83,7 @@ public class TestEarlyTerminatingSorting
     return doc;
   }
 
-  private void createRandomIndex(Integer maxSegmentCount) throws IOException {
+  private void createRandomIndex(boolean singleSortedSegment) throws IOException {
     dir = newDirectory();
     numDocs = atLeast(150);
     final int numTerms = TestUtil.nextInt(random(), 1, numDocs / 5);
@@ -110,8 +110,12 @@ public class TestEarlyTerminatingSorting
         iw.deleteDocuments(new Term("s", term));
       }
     }
-    if (maxSegmentCount != null) {
-      iw.forceMerge(maxSegmentCount.intValue());
+    if (singleSortedSegment) {
+      // because of deletions, there might still be a single flush segment in
+      // the index, although want want a sorted segment so it needs to be merged
+      iw.getReader().close(); // refresh
+      iw.addDocument(new Document());
+      iw.forceMerge(1);
     }
     else if (random().nextBoolean()) {
       iw.forceMerge(forceMergeMaxSegmentCount);
@@ -128,7 +132,7 @@ public class TestEarlyTerminatingSorting
   public void testEarlyTermination() throws IOException {
     final int iters = atLeast(8);
     for (int i = 0; i < iters; ++i) {
-      createRandomIndex(null);
+      createRandomIndex(false);
       for (int j = 0; j < iters; ++j) {
         final IndexSearcher searcher = newSearcher(reader);
         final int numHits = TestUtil.nextInt(random(), 1, numDocs);
@@ -185,7 +189,7 @@ public class TestEarlyTerminatingSorting
   }
 
   public void testEarlyTerminationDifferentSorter() throws IOException {
-    createRandomIndex(null);
+    createRandomIndex(false);
     final int iters = atLeast(3);
     for (int i = 0; i < iters; ++i) {
       final IndexSearcher searcher = newSearcher(reader);
@@ -275,7 +279,7 @@ public class TestEarlyTerminatingSorting
   public void testTerminatedEarly() throws IOException {
     final int iters = atLeast(8);
     for (int i = 0; i < iters; ++i) {
-      createRandomIndex(1);
+      createRandomIndex(true);
 
       final IndexSearcher searcher = newSearcherForTestTerminatedEarly(reader); // future TODO: use newSearcher(reader);
       final Query query = new MatchAllDocsQuery(); // search for everything/anything