Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

LUCENE-6925: add ForceMergePolicy class in lucene test-framework and RandomForceMergePolicy class in solr test-framework, plus Test[Random]ForceMergePolicy test classes.

Christine Poerschke8575e3fb3a3d
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index 80d24b2b6f1..eaa3398e80d 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -164,6 +164,9 @@ Other
NumericRangeQueryQuery.xml to NumericRangeQuery.xml
(Christine Poerschke)
+* LUCENE-6925: add ForceMergePolicy class in test-framework
+ (Christine Poerschke)
+
======================= Lucene 5.4.0 =======================
New Features
diff --git a/lucene/test-framework/src/java/org/apache/lucene/index/ForceMergePolicy.java b/lucene/test-framework/src/java/org/apache/lucene/index/ForceMergePolicy.java
new file mode 100755
index 00000000000..1337e025cd7
--- /dev/null
+++ b/lucene/test-framework/src/java/org/apache/lucene/index/ForceMergePolicy.java
@@ -0,0 +1,79 @@
+package org.apache.lucene.index;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.io.IOException;
+import java.util.Map;
+
+import org.apache.lucene.index.IndexWriter;
+import org.apache.lucene.index.MergePolicy;
+import org.apache.lucene.index.MergeTrigger;
+import org.apache.lucene.index.SegmentCommitInfo;
+import org.apache.lucene.index.SegmentInfos;
+
+/*
+ * A {@link MergePolicy} that only returns forced merges.
+ * <p><b>NOTE</b>: Use this policy if you wish to disallow background
+ * merges but wish to run optimize/forceMerge segment merges.
+ *
+ * @lucene.experimental
+ */
+public final class ForceMergePolicy extends MergePolicy {
+
+ final MergePolicy in;
+
+ /** Create a new {@code ForceMergePolicy} around the given {@code MergePolicy} */
+ public ForceMergePolicy(MergePolicy in) {
+ this.in = in;
+ }
+
+ @Override
+ public MergeSpecification findMerges(MergeTrigger mergeTrigger,
+ SegmentInfos segmentInfos, IndexWriter writer) throws IOException {
+ return null;
+ }
+
+ @Override
+ public MergeSpecification findForcedMerges(SegmentInfos segmentInfos,
+ int maxSegmentCount, Map<SegmentCommitInfo,Boolean> segmentsToMerge, IndexWriter writer)
+ throws IOException {
+ return in.findForcedMerges(segmentInfos, maxSegmentCount, segmentsToMerge, writer);
+ }
+
+ @Override
+ public MergeSpecification findForcedDeletesMerges(SegmentInfos segmentInfos, IndexWriter writer)
+ throws IOException {
+ return in.findForcedDeletesMerges(segmentInfos, writer);
+ }
+
+ @Override
+ public boolean useCompoundFile(SegmentInfos segments,
+ SegmentCommitInfo newSegment, IndexWriter writer) throws IOException {
+ return in.useCompoundFile(segments, newSegment, writer);
+ }
+
+ @Override
+ protected long size(SegmentCommitInfo info, IndexWriter writer) throws IOException {
+ return in.size(info, writer);
+ }
+
+ @Override
+ public String toString() {
+ return "ForceMergePolicy(" + in + ")";
+ }
+}
diff --git a/lucene/test-framework/src/test/org/apache/lucene/index/TestForceMergePolicy.java b/lucene/test-framework/src/test/org/apache/lucene/index/TestForceMergePolicy.java
new file mode 100755
index 00000000000..f4f0b06d452
--- /dev/null
+++ b/lucene/test-framework/src/test/org/apache/lucene/index/TestForceMergePolicy.java
@@ -0,0 +1,29 @@
+package org.apache.lucene.index;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.apache.lucene.util.LuceneTestCase;
+
+public class TestForceMergePolicy extends LuceneTestCase {
+
+ public void testForceMergePolicy() throws Exception {
+ MergePolicy mp = new ForceMergePolicy(null);
+ assertNull(mp.findMerges(null, (SegmentInfos)null, null));
+ }
+
+}
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 568bc0c995a..6b0eafd6ba0 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -304,6 +304,8 @@ Other Changes
* SOLR-8383: SolrCore.java + QParserPlugin.java container initialCapacity tweaks
(Christine Poerschke, Mike Drob)
+* LUCENE-6925: add RandomForceMergePolicy class in test-framework (Christine Poerschke)
+
================== 5.4.0 ==================
Consult the LUCENE_CHANGES.txt file for additional, low level, changes in this release
diff --git a/solr/core/src/test/org/apache/solr/util/TestRandomForceMergePolicy.java b/solr/core/src/test/org/apache/solr/util/TestRandomForceMergePolicy.java
new file mode 100755
index 00000000000..d818786b438
--- /dev/null
+++ b/solr/core/src/test/org/apache/solr/util/TestRandomForceMergePolicy.java
@@ -0,0 +1,36 @@
+package org.apache.solr.util;
+
+import java.io.IOException;
+
+import org.apache.lucene.index.MergePolicy;
+import org.apache.lucene.index.SegmentInfos;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+public class TestRandomForceMergePolicy extends TestRandomMergePolicy {
+
+ /**
+ * Ensure it finds no merges
+ */
+ public void testFindMerges() throws IOException {
+ MergePolicy mp = new RandomForceMergePolicy();
+ assertNull(mp.findMerges(null, (SegmentInfos)null, null));
+ }
+
+}
+
diff --git a/solr/test-framework/src/java/org/apache/solr/util/RandomForceMergePolicy.java b/solr/test-framework/src/java/org/apache/solr/util/RandomForceMergePolicy.java
new file mode 100755
index 00000000000..a2cace7f3b3
--- /dev/null
+++ b/solr/test-framework/src/java/org/apache/solr/util/RandomForceMergePolicy.java
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.solr.util;
+
+import org.apache.lucene.index.ForceMergePolicy;
+import org.apache.lucene.index.MergePolicy;
+import org.apache.lucene.util.LuceneTestCase;
+
+/**
+ * A {@link MergePolicy} with a no-arg constructor that proxies to a
+ * {@link ForceMergePolicy} wrapped instance retrieved from
+ * {@link LuceneTestCase#newMergePolicy}.
+ * Solr tests utilizing the Lucene randomized test framework can refer
+ * to this class in solrconfig.xml to get a fully randomized merge policy
+ * that only returns forced merges.
+ */
+public final class RandomForceMergePolicy extends RandomMergePolicy {
+
+ public RandomForceMergePolicy() {
+ super(new ForceMergePolicy(LuceneTestCase.newMergePolicy()));
+ }
+
+}
diff --git a/solr/test-framework/src/java/org/apache/solr/util/RandomMergePolicy.java b/solr/test-framework/src/java/org/apache/solr/util/RandomMergePolicy.java
index 9891b7c0805..7c376bfe82c 100644
--- a/solr/test-framework/src/java/org/apache/solr/util/RandomMergePolicy.java
+++ b/solr/test-framework/src/java/org/apache/solr/util/RandomMergePolicy.java
@@ -31,12 +31,12 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
- * A {@link MergePolicy} with a no-arg constructor that proxies to a
- * wrapped instance retrieved from {@link LuceneTestCase#newMergePolicy}.
+ * A {@link MergePolicy} with a no-arg constructor that proxies to an
+ * instance retrieved from {@link LuceneTestCase#newMergePolicy}.
* Solr tests utilizing the Lucene randomized test framework can refer
* to this class in solrconfig.xml to get a fully randomized merge policy.
*/
-public final class RandomMergePolicy extends MergePolicy {
+public class RandomMergePolicy extends MergePolicy {
private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
@@ -49,7 +49,7 @@ public final class RandomMergePolicy extends MergePolicy {
this(LuceneTestCase.newMergePolicy());
}
- private RandomMergePolicy(MergePolicy inner) {
+ protected RandomMergePolicy(MergePolicy inner) {
super(inner.getNoCFSRatio(),
(long) (inner.getMaxCFSSegmentSizeMB() * 1024 * 1024));
this.inner = inner;