You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by tf...@apache.org on 2018/08/27 21:07:01 UTC
lucene-solr:branch_7x: SOLR-10028: Fix and improvements to
SegmentsInfoRequestHandlerTest
Repository: lucene-solr
Updated Branches:
refs/heads/branch_7x e50be7ee3 -> cc110264b
SOLR-10028: Fix and improvements to SegmentsInfoRequestHandlerTest
Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/cc110264
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/cc110264
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/cc110264
Branch: refs/heads/branch_7x
Commit: cc110264b3edaa54f393e83334d71ec43c6944c0
Parents: e50be7e
Author: Tomas Fernandez Lobbe <tf...@apache.org>
Authored: Mon Aug 27 14:05:50 2018 -0700
Committer: Tomas Fernandez Lobbe <tf...@apache.org>
Committed: Mon Aug 27 14:06:49 2018 -0700
----------------------------------------------------------------------
solr/CHANGES.txt | 2 +
.../admin/SegmentsInfoRequestHandlerTest.java | 59 +++++++++++++++++---
2 files changed, 52 insertions(+), 9 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/cc110264/solr/CHANGES.txt
----------------------------------------------------------------------
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 26f915e..43d4bed 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -211,6 +211,8 @@ Bug Fixes
* SOLR-12683: HashQuery will throw an exception if more than 4 partitionKeys is specified.
Earlier after the 4th partitionKey the keys would be silently ignored. (Varun Thacker)
+* SOLR-10028: Fix and improvements to SegmentsInfoRequestHandlerTest (Christine Poerschke, Tomás Fernández Löbbe)
+
Optimizations
----------------------
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/cc110264/solr/core/src/test/org/apache/solr/handler/admin/SegmentsInfoRequestHandlerTest.java
----------------------------------------------------------------------
diff --git a/solr/core/src/test/org/apache/solr/handler/admin/SegmentsInfoRequestHandlerTest.java b/solr/core/src/test/org/apache/solr/handler/admin/SegmentsInfoRequestHandlerTest.java
index 3173c12..e2a4c6d 100644
--- a/solr/core/src/test/org/apache/solr/handler/admin/SegmentsInfoRequestHandlerTest.java
+++ b/solr/core/src/test/org/apache/solr/handler/admin/SegmentsInfoRequestHandlerTest.java
@@ -16,10 +16,13 @@
*/
package org.apache.solr.handler.admin;
+import java.io.IOException;
+import org.apache.lucene.index.SegmentCommitInfo;
+import org.apache.lucene.index.SegmentInfos;
import org.apache.lucene.util.Version;
-import org.apache.solr.index.LogDocMergePolicyFactory;
import org.apache.solr.SolrTestCaseJ4;
-
+import org.apache.solr.index.NoMergePolicyFactory;
+import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
@@ -31,13 +34,18 @@ public class SegmentsInfoRequestHandlerTest extends SolrTestCaseJ4 {
private static final int DEL_COUNT = 1;
+ private static final int NUM_SEGMENTS = 2;
+
@BeforeClass
public static void beforeClass() throws Exception {
// we need a consistent segmentation to ensure we don't get a random
// merge that reduces the total num docs in all segments, or the number of deletes
//
- systemSetPropertySolrTestsMergePolicyFactory(LogDocMergePolicyFactory.class.getName());
+ systemSetPropertySolrTestsMergePolicyFactory(NoMergePolicyFactory.class.getName());
+ // Also prevent flushes
+ System.setProperty("solr.tests.maxBufferedDocs", "1000");
+ System.setProperty("solr.tests.ramBufferSizeMB", "5000");
System.setProperty("enable.update.log", "false"); // no _version_ in our schema
initCore("solrconfig.xml", "schema12.xml"); // segments API shouldn't depend on _version_ or ulog
@@ -54,25 +62,58 @@ public class SegmentsInfoRequestHandlerTest extends SolrTestCaseJ4 {
assertU(adoc("id","SOLR200" + i, "name","Apache Solr:" + i));
}
assertU(commit());
+ h.getCore().withSearcher((searcher) -> {
+ int numSegments = SegmentInfos.readLatestCommit(searcher.getIndexReader().directory()).size();
+ // if this is not NUM_SEGMENTS, there was some unexpected flush or merge
+ assertEquals("Unexpected number of segment in the index: " + numSegments,
+ NUM_SEGMENTS, numSegments);
+ return null;
+ });
+
+ }
+
+ @AfterClass
+ public static void afterClass() {
+ systemClearPropertySolrTestsMergePolicyFactory();
+ System.clearProperty("solr.tests.maxBufferedDocs");
+ System.clearProperty("solr.tests.ramBufferSizeMB");
}
@Test
public void testSegmentInfos() {
- assertQ("No segments mentioned in result",
+ assertQ("Unexpected number of segments returned",
req("qt","/admin/segments"),
- "0<count(//lst[@name='segments']/lst)");
+ NUM_SEGMENTS + "=count(//lst[@name='segments']/lst)");
}
@Test
public void testSegmentInfosVersion() {
- assertQ("No segments mentioned in result",
+ assertQ("Unexpected number of segments returned",
+ req("qt","/admin/segments"),
+ NUM_SEGMENTS + "=count(//lst[@name='segments']/lst/str[@name='version'][.='" + Version.LATEST + "'])");
+ }
+
+ @Test
+ public void testSegmentNames() throws IOException {
+ String[] segmentNamePatterns = new String[NUM_SEGMENTS];
+ h.getCore().withSearcher((searcher) -> {
+ int i = 0;
+ for (SegmentCommitInfo sInfo : SegmentInfos.readLatestCommit(searcher.getIndexReader().directory())) {
+ assertTrue("Unexpected number of segment in the index: " + i, i < NUM_SEGMENTS);
+ segmentNamePatterns[i] = "//lst[@name='segments']/lst/str[@name='name'][.='" + sInfo.info.name + "']";
+ i++;
+ }
+
+ return null;
+ });
+ assertQ("Unexpected segment names returned",
req("qt","/admin/segments"),
- "2=count(//lst[@name='segments']/lst/str[@name='version'][.='"+Version.LATEST+"'])");
+ segmentNamePatterns);
}
@Test
- public void testSegmentInfosData() {
- assertQ("No segments mentioned in result",
+ public void testSegmentInfosData() {
+ assertQ("Unexpected document counts in result",
req("qt","/admin/segments"),
//#Document
(DOC_COUNT*2)+"=sum(//lst[@name='segments']/lst/int[@name='size'])",