LUCENE-2512: fix DeleteByPercentTask to work again post flex

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@957486 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael McCandless 2010-06-24 10:13:45 +00:00
parent a9947aeb8d
commit f81a5d9bf6
2 changed files with 40 additions and 1 deletions

View File

@ -77,10 +77,15 @@ public class DeleteByPercentTask extends PerfTask {
Bits delDocs = MultiFields.getDeletedDocs(r);
int doc = 0;
while (doc < maxDoc && numDeleted < numToDelete) {
if (!delDocs.get(doc) && random.nextDouble() <= delRate) {
if ((delDocs == null || !delDocs.get(doc)) && random.nextDouble() <= delRate) {
r.deleteDocument(doc);
numDeleted++;
if (delDocs == null) {
delDocs = MultiFields.getDeletedDocs(r);
assert delDocs != null;
}
}
doc++;
}
}
System.out.println("--> processed (delete) " + numDeleted + " docs");

View File

@ -606,6 +606,40 @@ public class TestPerfTasksLogic extends BenchmarkTestCase {
}
}
public void testDeleteByPercent() throws Exception {
// 1. alg definition (required in every "logic" test)
String algLines[] = {
"# ----- properties ",
"content.source=org.apache.lucene.benchmark.byTask.feeds.LineDocSource",
"docs.file=" + getReuters20LinesFile(),
"ram.flush.mb=-1",
"max.buffered=2",
"content.source.log.step=3",
"doc.term.vector=false",
"content.source.forever=false",
"directory=RAMDirectory",
"doc.stored=false",
"doc.tokenized=false",
"debug.level=1",
"# ----- alg ",
"CreateIndex",
"{ \"AddDocs\" AddDoc > : * ",
"CloseIndex()",
"OpenReader(false)",
"DeleteByPercent(20)",
"CloseReader"
};
// 2. execute the algorithm (required in every "logic" test)
Benchmark benchmark = execBenchmark(algLines);
// 3. test number of docs in the index
IndexReader ir = IndexReader.open(benchmark.getRunData().getDirectory(), true);
int ndocsExpected = 16; // first 20 reuters docs, minus 20%
assertEquals("wrong number of docs in the index!", ndocsExpected, ir.numDocs());
ir.close();
}
/**
* Test that we can set merge scheduler".
*/