mirror of https://github.com/apache/lucene.git
test untested class
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1334738 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
d61238d528
commit
ec23612490
|
@ -45,11 +45,12 @@ public class BalancedSegmentMergePolicy extends LogByteSizeMergePolicy {
|
|||
|
||||
public void setMergePolicyParams(MergePolicyParams params) {
|
||||
if (params!=null) {
|
||||
// note: this order is important!
|
||||
setMergeFactor(params._mergeFactor);
|
||||
setPartialExpunge(params._doPartialExpunge);
|
||||
setNumLargeSegments(params._numLargeSegments);
|
||||
setMaxSmallSegments(params._maxSmallSegments);
|
||||
setPartialExpunge(params._doPartialExpunge);
|
||||
setMergeFactor(params._mergeFactor);
|
||||
setUseCompoundFile(params._useCompoundFile);
|
||||
setMaxMergeDocs(params._maxMergeDocs);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,87 @@
|
|||
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.util.Random;
|
||||
|
||||
import org.apache.lucene.analysis.MockAnalyzer;
|
||||
import org.apache.lucene.codecs.Codec;
|
||||
import org.apache.lucene.index.BalancedSegmentMergePolicy.MergePolicyParams;
|
||||
import org.apache.lucene.store.Directory;
|
||||
import org.apache.lucene.util.LineFileDocs;
|
||||
import org.apache.lucene.util.LuceneTestCase;
|
||||
import org.apache.lucene.util._TestUtil;
|
||||
|
||||
/**
|
||||
* Simple tests for {@link BalancedSegmentMergePolicy}
|
||||
* doesn't actually test that this thing does what it says it should,
|
||||
* just merges with it!
|
||||
*/
|
||||
public class TestBalancedSegmentMergePolicy extends LuceneTestCase {
|
||||
Directory dir;
|
||||
RandomIndexWriter iw;
|
||||
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
dir = newDirectory();
|
||||
IndexWriterConfig iwc = newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random()));
|
||||
BalancedSegmentMergePolicy mp = new BalancedSegmentMergePolicy();
|
||||
mp.setMergePolicyParams(newMergePolicyParams(random()));
|
||||
iwc.setMergePolicy(mp);
|
||||
iw = new RandomIndexWriter(random(), dir, iwc);
|
||||
LineFileDocs docs = new LineFileDocs(random(), !Codec.getDefault().getName().equals("Lucene3x"));
|
||||
int numDocs = atLeast(200);
|
||||
for (int i = 0; i < numDocs; i++) {
|
||||
iw.addDocument(docs.nextDoc());
|
||||
if (random().nextInt(6) == 0) {
|
||||
iw.deleteDocuments(new Term("docid", Integer.toString(i)));
|
||||
}
|
||||
if (random().nextInt(10) == 0) {
|
||||
iw.commit();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void tearDown() throws Exception {
|
||||
iw.close();
|
||||
dir.close();
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
public void testForceMerge() throws Exception {
|
||||
int numSegments = _TestUtil.nextInt(random(), 1, 4);
|
||||
iw.forceMerge(numSegments);
|
||||
DirectoryReader ir = iw.getReader();
|
||||
assertTrue(ir.getSequentialSubReaders().length <= numSegments);
|
||||
ir.close();
|
||||
}
|
||||
|
||||
private static MergePolicyParams newMergePolicyParams(Random random) {
|
||||
MergePolicyParams params = new MergePolicyParams();
|
||||
if (rarely(random)) {
|
||||
params.setMergeFactor(_TestUtil.nextInt(random, 2, 9));
|
||||
} else {
|
||||
params.setMergeFactor(_TestUtil.nextInt(random, 10, 50));
|
||||
}
|
||||
int mergeFactor = params.getMergeFactor();
|
||||
params.setMaxSmallSegments(_TestUtil.nextInt(random, mergeFactor, mergeFactor*2));
|
||||
params.setNumLargeSegments(_TestUtil.nextInt(random, 2, 3));
|
||||
params.setUseCompoundFile(random.nextBoolean());
|
||||
return params;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue