mirror of https://github.com/apache/lucene.git
LUCENE-5176: remove _TestUtil.keepFullyDeletedSegments
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1514052 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
a5c0445b88
commit
d686fd8f02
|
@ -490,7 +490,8 @@ public class TestIndexWriterOnDiskFull extends LuceneTestCase {
|
|||
setReaderPooling(true).
|
||||
setMergePolicy(newLogMergePolicy(2))
|
||||
);
|
||||
_TestUtil.keepFullyDeletedSegments(w);
|
||||
// we can do this because we add/delete/add (and dont merge to "nothing")
|
||||
w.setKeepFullyDeletedSegments(true);
|
||||
|
||||
Document doc = new Document();
|
||||
|
||||
|
|
|
@ -37,7 +37,8 @@ public class TestMultiFields extends LuceneTestCase {
|
|||
Directory dir = newDirectory();
|
||||
|
||||
IndexWriter w = new IndexWriter(dir, newIndexWriterConfig( TEST_VERSION_CURRENT, new MockAnalyzer(random())).setMergePolicy(NoMergePolicy.COMPOUND_FILES));
|
||||
_TestUtil.keepFullyDeletedSegments(w);
|
||||
// we can do this because we use NoMergePolicy (and dont merge to "nothing")
|
||||
w.setKeepFullyDeletedSegments(true);
|
||||
|
||||
Map<BytesRef,List<Integer>> docs = new HashMap<BytesRef,List<Integer>>();
|
||||
Set<Integer> deleted = new HashSet<Integer>();
|
||||
|
|
|
@ -173,7 +173,6 @@ public class TestCachingWrapperFilter extends LuceneTestCase {
|
|||
// asserts below requires no unexpected merges:
|
||||
setMergePolicy(newLogMergePolicy(10))
|
||||
);
|
||||
_TestUtil.keepFullyDeletedSegments(writer.w);
|
||||
|
||||
// NOTE: cannot use writer.getReader because RIW (on
|
||||
// flipping a coin) may give us a newly opened reader,
|
||||
|
|
|
@ -0,0 +1,42 @@
|
|||
package org.apache.lucene.index;
|
||||
|
||||
import org.apache.lucene.util.Bits;
|
||||
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Filters the incoming reader and makes all documents appear deleted.
|
||||
*/
|
||||
public class AllDeletedFilterReader extends FilterAtomicReader {
|
||||
final Bits liveDocs;
|
||||
|
||||
public AllDeletedFilterReader(AtomicReader in) {
|
||||
super(in);
|
||||
liveDocs = new Bits.MatchNoBits(in.maxDoc());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Bits getLiveDocs() {
|
||||
return liveDocs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int numDocs() {
|
||||
return 0;
|
||||
}
|
||||
}
|
|
@ -25,6 +25,7 @@ import junit.framework.Assert;
|
|||
|
||||
import org.apache.lucene.analysis.MockAnalyzer;
|
||||
import org.apache.lucene.document.Document;
|
||||
import org.apache.lucene.index.AllDeletedFilterReader;
|
||||
import org.apache.lucene.index.AtomicReader;
|
||||
import org.apache.lucene.index.AtomicReaderContext;
|
||||
import org.apache.lucene.index.IndexReader;
|
||||
|
@ -38,7 +39,6 @@ import org.apache.lucene.store.MockDirectoryWrapper;
|
|||
import org.apache.lucene.store.RAMDirectory;
|
||||
import org.apache.lucene.util.Bits;
|
||||
import org.apache.lucene.util.LuceneTestCase;
|
||||
import org.apache.lucene.util._TestUtil;
|
||||
|
||||
import static org.apache.lucene.util.LuceneTestCase.TEST_VERSION_CURRENT;
|
||||
|
||||
|
@ -193,7 +193,7 @@ public class QueryUtils {
|
|||
static final IndexReader[] emptyReaders = new IndexReader[8];
|
||||
static {
|
||||
try {
|
||||
emptyReaders[0] = makeEmptyIndex(new Random(0), 0);
|
||||
emptyReaders[0] = new MultiReader();
|
||||
emptyReaders[4] = makeEmptyIndex(new Random(0), 4);
|
||||
emptyReaders[5] = makeEmptyIndex(new Random(0), 5);
|
||||
emptyReaders[7] = makeEmptyIndex(new Random(0), 7);
|
||||
|
@ -202,31 +202,18 @@ public class QueryUtils {
|
|||
}
|
||||
}
|
||||
|
||||
private static DirectoryReader makeEmptyIndex(Random random, final int numDeletedDocs)
|
||||
throws IOException {
|
||||
private static IndexReader makeEmptyIndex(Random random, final int numDocs) throws IOException {
|
||||
assert numDocs > 0;
|
||||
Directory d = new MockDirectoryWrapper(random, new RAMDirectory());
|
||||
IndexWriter w = new IndexWriter(d, new IndexWriterConfig(
|
||||
TEST_VERSION_CURRENT, new MockAnalyzer(random)));
|
||||
for (int i = 0; i < numDeletedDocs; i++) {
|
||||
IndexWriter w = new IndexWriter(d, new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random)));
|
||||
for (int i = 0; i < numDocs; i++) {
|
||||
w.addDocument(new Document());
|
||||
}
|
||||
w.forceMerge(1);
|
||||
w.commit();
|
||||
w.deleteDocuments( new MatchAllDocsQuery() );
|
||||
_TestUtil.keepFullyDeletedSegments(w);
|
||||
w.commit();
|
||||
|
||||
if (0 < numDeletedDocs)
|
||||
Assert.assertTrue("writer has no deletions", w.hasDeletions());
|
||||
|
||||
Assert.assertEquals("writer is missing some deleted docs",
|
||||
numDeletedDocs, w.maxDoc());
|
||||
Assert.assertEquals("writer has non-deleted docs",
|
||||
0, w.numDocs());
|
||||
w.close();
|
||||
DirectoryReader r = DirectoryReader.open(d);
|
||||
Assert.assertEquals("reader has wrong number of deleted docs",
|
||||
numDeletedDocs, r.numDeletedDocs());
|
||||
return r;
|
||||
DirectoryReader reader = DirectoryReader.open(d);
|
||||
return new AllDeletedFilterReader(LuceneTestCase.getOnlySegmentReader(reader));
|
||||
}
|
||||
|
||||
/** alternate scorer skipTo(),skipTo(),next(),next(),skipTo(),skipTo(), etc
|
||||
|
|
|
@ -25,7 +25,6 @@ import java.io.IOException;
|
|||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.io.PrintStream;
|
||||
import java.lang.reflect.Method;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.BigInteger;
|
||||
import java.nio.CharBuffer;
|
||||
|
@ -789,19 +788,6 @@ public class _TestUtil {
|
|||
Assert.assertEquals("Reflection does not produce same map", reflectedValues, map);
|
||||
}
|
||||
|
||||
public static void keepFullyDeletedSegments(IndexWriter w) {
|
||||
try {
|
||||
// Carefully invoke what is a package-private (test
|
||||
// only, internal) method on IndexWriter:
|
||||
Method m = IndexWriter.class.getDeclaredMethod("setKeepFullyDeletedSegments", boolean.class);
|
||||
m.setAccessible(true);
|
||||
m.invoke(w, Boolean.TRUE);
|
||||
} catch (Exception e) {
|
||||
// Should not happen?
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* insecure, fast version of File.createTempFile
|
||||
* uses Random instead of SecureRandom.
|
||||
|
|
Loading…
Reference in New Issue