LUCENE-2858: fix benchmarks

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/branches/lucene2858@1237335 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Robert Muir 2012-01-29 16:42:21 +00:00
parent acefe212c1
commit adf080e451
5 changed files with 21 additions and 16 deletions

View File

@ -37,6 +37,7 @@ import org.apache.lucene.benchmark.byTask.utils.FileUtils;
import org.apache.lucene.benchmark.byTask.tasks.NewAnalyzerTask;
import org.apache.lucene.facet.taxonomy.TaxonomyReader;
import org.apache.lucene.facet.taxonomy.TaxonomyWriter;
import org.apache.lucene.index.DirectoryReader;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.search.IndexSearcher;
@ -90,7 +91,7 @@ public class PerfRunData implements Closeable {
private HashMap<Class<? extends ReadTask>,QueryMaker> readTaskQueryMaker;
private Class<? extends QueryMaker> qmkrClass;
private IndexReader indexReader;
private DirectoryReader indexReader;
private IndexSearcher indexSearcher;
private IndexWriter indexWriter;
private Config config;
@ -288,7 +289,7 @@ public class PerfRunData implements Closeable {
* reference. You must call IndexReader.decRef() when
* you're done.
*/
public synchronized IndexReader getIndexReader() {
public synchronized DirectoryReader getIndexReader() {
if (indexReader != null) {
indexReader.incRef();
}
@ -314,7 +315,7 @@ public class PerfRunData implements Closeable {
* the reader will remain open).
* @param indexReader The indexReader to set.
*/
public synchronized void setIndexReader(IndexReader indexReader) throws IOException {
public synchronized void setIndexReader(DirectoryReader indexReader) throws IOException {
if (indexReader == this.indexReader) {
return;
}

View File

@ -18,6 +18,7 @@ package org.apache.lucene.benchmark.byTask.tasks;
*/
import org.apache.lucene.benchmark.byTask.PerfRunData;
import org.apache.lucene.index.DirectoryReader;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.util.ArrayUtil;
@ -59,7 +60,7 @@ public class NearRealtimeReaderTask extends PerfTask {
}
long t = System.currentTimeMillis();
IndexReader r = IndexReader.open(w, true);
DirectoryReader r = IndexReader.open(w, true);
runData.setIndexReader(r);
// Transfer our reference to runData
r.decRef();
@ -77,7 +78,7 @@ public class NearRealtimeReaderTask extends PerfTask {
}
t = System.currentTimeMillis();
final IndexReader newReader = IndexReader.openIfChanged(r);
final DirectoryReader newReader = DirectoryReader.openIfChanged(r);
if (newReader != null) {
final int delay = (int) (System.currentTimeMillis()-t);
if (reopenTimes.length == reopenCount) {

View File

@ -22,6 +22,7 @@ import java.util.Collection;
import java.util.Map;
import org.apache.lucene.benchmark.byTask.PerfRunData;
import org.apache.lucene.index.DirectoryReader;
import org.apache.lucene.index.IndexCommit;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.store.Directory;
@ -42,7 +43,7 @@ public class OpenReaderTask extends PerfTask {
@Override
public int doLogic() throws IOException {
Directory dir = getRunData().getDirectory();
IndexReader r = null;
DirectoryReader r = null;
if (commitUserData != null) {
r = IndexReader.open(OpenReaderTask.findIndexCommit(dir, commitUserData));
} else {
@ -71,7 +72,7 @@ public class OpenReaderTask extends PerfTask {
}
public static IndexCommit findIndexCommit(Directory dir, String userData) throws IOException {
Collection<IndexCommit> commits = IndexReader.listCommits(dir);
Collection<IndexCommit> commits = DirectoryReader.listCommits(dir);
for (final IndexCommit ic : commits) {
Map<String,String> map = ic.getUserData();
String ud = null;

View File

@ -20,6 +20,7 @@ package org.apache.lucene.benchmark.byTask.tasks;
import java.io.IOException;
import org.apache.lucene.benchmark.byTask.PerfRunData;
import org.apache.lucene.index.DirectoryReader;
import org.apache.lucene.index.IndexReader;
/**
@ -33,8 +34,8 @@ public class ReopenReaderTask extends PerfTask {
@Override
public int doLogic() throws IOException {
IndexReader r = getRunData().getIndexReader();
IndexReader nr = IndexReader.openIfChanged(r);
DirectoryReader r = getRunData().getIndexReader();
DirectoryReader nr = DirectoryReader.openIfChanged(r);
if (nr != null) {
getRunData().setIndexReader(nr);
nr.decRef();

View File

@ -39,6 +39,7 @@ import org.apache.lucene.benchmark.byTask.tasks.CountingSearchTestTask;
import org.apache.lucene.benchmark.byTask.tasks.WriteLineDocTask;
import org.apache.lucene.collation.CollationKeyAnalyzer;
import org.apache.lucene.facet.taxonomy.TaxonomyReader;
import org.apache.lucene.index.DirectoryReader;
import org.apache.lucene.index.DocsEnum;
import org.apache.lucene.index.Fields;
import org.apache.lucene.index.FieldsEnum;
@ -51,7 +52,7 @@ import org.apache.lucene.index.LogMergePolicy;
import org.apache.lucene.index.MultiFields;
import org.apache.lucene.index.SegmentInfos;
import org.apache.lucene.index.SerialMergeScheduler;
import org.apache.lucene.index.SlowMultiReaderWrapper;
import org.apache.lucene.index.SlowCompositeReaderWrapper;
import org.apache.lucene.index.Terms;
import org.apache.lucene.index.TermsEnum;
import org.apache.lucene.search.FieldCache.DocTermsIndex;
@ -97,7 +98,7 @@ public class TestPerfTasksLogic extends BenchmarkTestCase {
// 4. test specific checks after the benchmark run completed.
assertEquals("TestSearchTask was supposed to be called!",279,CountingSearchTestTask.numSearches);
assertTrue("Index does not exist?...!", IndexReader.indexExists(benchmark.getRunData().getDirectory()));
assertTrue("Index does not exist?...!", DirectoryReader.indexExists(benchmark.getRunData().getDirectory()));
// now we should be able to open the index for write.
IndexWriter iw = new IndexWriter(benchmark.getRunData().getDirectory(),
new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random))
@ -185,7 +186,7 @@ public class TestPerfTasksLogic extends BenchmarkTestCase {
//we probably should use a different doc/query maker, but...
assertTrue("TestSearchTask was supposed to be called!", CountingHighlighterTestTask.numDocsRetrieved >= CountingHighlighterTestTask.numHighlightedResults && CountingHighlighterTestTask.numHighlightedResults > 0);
assertTrue("Index does not exist?...!", IndexReader.indexExists(benchmark.getRunData().getDirectory()));
assertTrue("Index does not exist?...!", DirectoryReader.indexExists(benchmark.getRunData().getDirectory()));
// now we should be able to open the index for write.
IndexWriter iw = new IndexWriter(benchmark.getRunData().getDirectory(), new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random)).setOpenMode(OpenMode.APPEND));
iw.close();
@ -224,7 +225,7 @@ public class TestPerfTasksLogic extends BenchmarkTestCase {
//we probably should use a different doc/query maker, but...
assertTrue("TestSearchTask was supposed to be called!", CountingHighlighterTestTask.numDocsRetrieved >= CountingHighlighterTestTask.numHighlightedResults && CountingHighlighterTestTask.numHighlightedResults > 0);
assertTrue("Index does not exist?...!", IndexReader.indexExists(benchmark.getRunData().getDirectory()));
assertTrue("Index does not exist?...!", DirectoryReader.indexExists(benchmark.getRunData().getDirectory()));
// now we should be able to open the index for write.
IndexWriter iw = new IndexWriter(benchmark.getRunData().getDirectory(), new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random)).setOpenMode(OpenMode.APPEND));
iw.close();
@ -297,7 +298,7 @@ public class TestPerfTasksLogic extends BenchmarkTestCase {
// 4. test specific checks after the benchmark run completed.
assertEquals("TestSearchTask was supposed to be called!",139,CountingSearchTestTask.numSearches);
assertTrue("Index does not exist?...!", IndexReader.indexExists(benchmark.getRunData().getDirectory()));
assertTrue("Index does not exist?...!", DirectoryReader.indexExists(benchmark.getRunData().getDirectory()));
// now we should be able to open the index for write.
IndexWriter iw = new IndexWriter(benchmark.getRunData().getDirectory(), new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random)).setOpenMode(OpenMode.APPEND));
iw.close();
@ -332,8 +333,8 @@ public class TestPerfTasksLogic extends BenchmarkTestCase {
// 3. execute the algorithm (required in every "logic" test)
Benchmark benchmark = execBenchmark(algLines);
IndexReader r = IndexReader.open(benchmark.getRunData().getDirectory());
DocTermsIndex idx = FieldCache.DEFAULT.getTermsIndex(new SlowMultiReaderWrapper(r), "country");
DirectoryReader r = IndexReader.open(benchmark.getRunData().getDirectory());
DocTermsIndex idx = FieldCache.DEFAULT.getTermsIndex(new SlowCompositeReaderWrapper(r), "country");
final int maxDoc = r.maxDoc();
assertEquals(1000, maxDoc);
BytesRef br = new BytesRef();