mirror of https://github.com/apache/lucene.git
add test case
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1166850 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
0d34e80016
commit
9cae51e472
|
@ -164,6 +164,15 @@ public class _TestUtil {
|
|||
}
|
||||
}
|
||||
|
||||
// NOTE: only works for TMP and LMP!!
|
||||
public static void setUseCompoundFile(MergePolicy mp, boolean v) {
|
||||
if (mp instanceof TieredMergePolicy) {
|
||||
((TieredMergePolicy) mp).setUseCompoundFile(v);
|
||||
} else if (mp instanceof LogMergePolicy) {
|
||||
((LogMergePolicy) mp).setUseCompoundFile(v);
|
||||
}
|
||||
}
|
||||
|
||||
/** start and end are BOTH inclusive */
|
||||
public static int nextInt(Random r, int start, int end) {
|
||||
return start + r.nextInt(end-start+1);
|
||||
|
|
|
@ -0,0 +1,112 @@
|
|||
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.File;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.lucene.analysis.MockAnalyzer;
|
||||
import org.apache.lucene.document.Document;
|
||||
import org.apache.lucene.document.StringField;
|
||||
import org.apache.lucene.document.TextField;
|
||||
import org.apache.lucene.store.MockDirectoryWrapper;
|
||||
import org.apache.lucene.util.LuceneTestCase;
|
||||
import org.apache.lucene.util._TestUtil;
|
||||
|
||||
// Make sure if you use NoDeletionPolicy that no file
|
||||
// referenced by a commit point is ever deleted
|
||||
|
||||
public class TestNeverDelete extends LuceneTestCase {
|
||||
|
||||
public void testIndexing() throws Exception {
|
||||
final File tmpDir = _TestUtil.getTempDir("TestNeverDelete");
|
||||
final MockDirectoryWrapper d = newFSDirectory(tmpDir);
|
||||
|
||||
// We want to "see" files removed if Lucene removed
|
||||
// them. This is still worth running on Windows since
|
||||
// some files the IR opens and closes.
|
||||
d.setNoDeleteOpenFile(false);
|
||||
final RandomIndexWriter w = new RandomIndexWriter(random,
|
||||
d,
|
||||
newIndexWriterConfig(TEST_VERSION_CURRENT,
|
||||
new MockAnalyzer(random))
|
||||
.setIndexDeletionPolicy(NoDeletionPolicy.INSTANCE));
|
||||
w.w.getConfig().setMaxBufferedDocs(_TestUtil.nextInt(random, 5, 30));
|
||||
|
||||
w.w.setInfoStream(VERBOSE ? System.out : null);
|
||||
w.commit();
|
||||
Thread[] indexThreads = new Thread[random.nextInt(4)];
|
||||
final long stopTime = System.currentTimeMillis() + atLeast(1000);
|
||||
for (int x=0; x < indexThreads.length; x++) {
|
||||
indexThreads[x] = new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
int docCount = 0;
|
||||
while (System.currentTimeMillis() < stopTime) {
|
||||
final Document doc = new Document();
|
||||
doc.add(newField("dc", ""+docCount, StringField.TYPE_STORED));
|
||||
doc.add(newField("field", "here is some text", TextField.TYPE_STORED));
|
||||
w.addDocument(doc);
|
||||
|
||||
if (docCount % 13 == 0) {
|
||||
w.commit();
|
||||
}
|
||||
docCount++;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
};
|
||||
indexThreads[x].setName("Thread " + x);
|
||||
indexThreads[x].start();
|
||||
}
|
||||
|
||||
final Set<String> allFiles = new HashSet<String>();
|
||||
|
||||
IndexReader r = IndexReader.open(d);
|
||||
while(System.currentTimeMillis() < stopTime) {
|
||||
final IndexCommit ic = r.getIndexCommit();
|
||||
if (VERBOSE) {
|
||||
System.out.println("TEST: check files: " + ic.getFileNames());
|
||||
}
|
||||
allFiles.addAll(ic.getFileNames());
|
||||
// Make sure no old files were removed
|
||||
for(String fileName : allFiles) {
|
||||
assertTrue("file " + fileName + " does not exist", d.fileExists(fileName));
|
||||
}
|
||||
IndexReader r2 = r.reopen();
|
||||
if (r2 != r) {
|
||||
r.close();
|
||||
r = r2;
|
||||
}
|
||||
Thread.sleep(1);
|
||||
}
|
||||
r.close();
|
||||
|
||||
for(Thread t : indexThreads) {
|
||||
t.join();
|
||||
}
|
||||
w.close();
|
||||
d.close();
|
||||
|
||||
_TestUtil.rmDir(tmpDir);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue