LUCENE-2858: Fix facets module

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/branches/lucene2858@1237618 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Uwe Schindler 2012-01-30 12:19:21 +00:00
parent bfa1dec595
commit 721de54e8c
6 changed files with 61 additions and 50 deletions

View File

@ -39,8 +39,6 @@ import org.apache.lucene.util.LuceneTestCase;
import org.junit.Test;
import org.junit.Ignore;
@Ignore("This test does not work, as PerDirPayloadProcessor is currently broken (see nocommit in SegmentMerger): "+
"SegmentReader/AtomicReader does not know its directory. This is borken, it should be a PayLoadProcessorProvider per AtomicReader!")
public class TestPayloadProcessorProvider extends LuceneTestCase {
private static final class PerDirPayloadProcessor extends PayloadProcessorProvider {
@ -217,6 +215,8 @@ public class TestPayloadProcessorProvider extends LuceneTestCase {
dir.close();
}
@Ignore("This test does not work, as PerDirPayloadProcessor is currently broken (see nocommit in SegmentMerger): "+
"SegmentReader/AtomicReader does not know its directory. This is broken, it should be a PayLoadProcessorProvider per AtomicReader!")
@Test
public void testAddIndexes() throws Exception {
// addIndexes - single commit in each
@ -226,6 +226,8 @@ public class TestPayloadProcessorProvider extends LuceneTestCase {
doTest(random, true, 0, true);
}
@Ignore("This test does not work, as PerDirPayloadProcessor is currently broken (see nocommit in SegmentMerger): "+
"SegmentReader/AtomicReader does not know its directory. This is broken, it should be a PayLoadProcessorProvider per AtomicReader!")
@Test
public void testAddIndexesIntoExisting() throws Exception {
// addIndexes - single commit in each
@ -235,6 +237,8 @@ public class TestPayloadProcessorProvider extends LuceneTestCase {
doTest(random, false, NUM_DOCS, true);
}
@Ignore("This test does not work, as PerDirPayloadProcessor is currently broken (see nocommit in SegmentMerger): "+
"SegmentReader/AtomicReader does not know its directory. This is broken, it should be a PayLoadProcessorProvider per AtomicReader!")
@Test
public void testRegularMerges() throws Exception {
Directory dir = newDirectory();

View File

@ -128,7 +128,7 @@ public class DirectoryTaxonomyReader implements TaxonomyReader {
}
protected DirectoryReader openIndexReader(Directory directory) throws CorruptIndexException, IOException {
return IndexReader.open(directory);
return DirectoryReader.open(directory);
}
/**
@ -558,7 +558,7 @@ public class DirectoryTaxonomyReader implements TaxonomyReader {
*
* @return lucene indexReader
*/
IndexReader getInternalIndexReader() {
DirectoryReader getInternalIndexReader() {
ensureOpen();
return this.indexReader;
}

View File

@ -283,7 +283,7 @@ public class DirectoryTaxonomyWriter implements TaxonomyWriter {
* this method to return their own {@link IndexReader}.
*/
protected DirectoryReader openReader() throws IOException {
return IndexReader.open(indexWriter, true);
return DirectoryReader.open(indexWriter, true);
}
/**
@ -617,7 +617,7 @@ public class DirectoryTaxonomyWriter implements TaxonomyWriter {
}
}
private synchronized void refreshReader() throws IOException {
protected synchronized void refreshReader() throws IOException {
if (reader != null) {
DirectoryReader r2 = DirectoryReader.openIfChanged(reader);
if (r2 != null) {
@ -985,6 +985,18 @@ public class DirectoryTaxonomyWriter implements TaxonomyWriter {
}
}
/**
* Expert: This method is only for expert use.
* Note also that any call to refresh() will invalidate the returned reader,
* so the caller needs to take care of appropriate locking.
*
* @return lucene indexReader
*/
DirectoryReader getInternalIndexReader() {
ensureOpen();
return this.reader;
}
/**
* Mapping from old ordinal to new ordinals, used when merging indexes
* wit separate taxonomies.

View File

@ -13,6 +13,7 @@ import org.apache.lucene.index.RandomIndexWriter;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.MatchAllDocsQuery;
import org.apache.lucene.store.Directory;
import org.junit.Ignore;
import org.junit.Test;
import org.apache.lucene.util.LuceneTestCase;
@ -47,6 +48,8 @@ public class FacetsPayloadProcessorProviderTest extends LuceneTestCase {
private static final int NUM_DOCS = 100;
@Ignore("This test does not work, as PerDirPayloadProcessor is currently broken (see nocommit in SegmentMerger): "+
"SegmentReader/AtomicReader does not know its directory. This is broken, it should be a PayLoadProcessorProvider per AtomicReader!")
@Test
public void testTaxonomyMergeUtils() throws Exception {
Directory dir = newDirectory();

View File

@ -6,6 +6,7 @@ import java.util.List;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.MultiReader;
import org.apache.lucene.index.ParallelReader;
import org.apache.lucene.index.SlowCompositeReaderWrapper;
import org.apache.lucene.search.MatchAllDocsQuery;
import org.apache.lucene.search.Query;
import org.junit.After;
@ -68,7 +69,7 @@ public class TestFacetsAccumulatorWithComplement extends FacetTestBase {
public void testComplementsWithParallerReader() throws Exception {
IndexReader origReader = indexReader;
ParallelReader pr = new ParallelReader(true);
pr.add(origReader);
pr.add(SlowCompositeReaderWrapper.wrap(origReader));
indexReader = pr;
try {
doTestComplements();

View File

@ -2,22 +2,25 @@ package org.apache.lucene.facet.taxonomy.directory;
import java.io.IOException;
import java.util.HashSet;
import java.util.IdentityHashMap;
import java.util.Set;
import org.apache.lucene.index.CorruptIndexException;
import org.apache.lucene.index.FilterIndexReader;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.DirectoryReader;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.index.IndexWriterConfig;
import org.apache.lucene.index.IndexWriterConfig.OpenMode;
import org.apache.lucene.store.AlreadyClosedException;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.LockObtainFailedException;
import org.junit.Test;
import org.apache.lucene.util.LuceneTestCase;
import org.apache.lucene.util.MapBackedSet;
import org.apache.lucene.analysis.MockAnalyzer;
import org.apache.lucene.analysis.MockTokenizer;
import org.apache.lucene.facet.taxonomy.CategoryPath;
import org.apache.lucene.facet.taxonomy.InconsistentTaxonomyException;
import org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyReader;
import org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyWriter;
@ -92,8 +95,7 @@ public class TestIndexClose extends LuceneTestCase {
}
private static class LeakChecker {
int ireader=0;
Set<Integer> openReaders = new HashSet<Integer>();
Set<DirectoryReader> readers = new MapBackedSet<DirectoryReader>(new IdentityHashMap<DirectoryReader,Boolean>());
int iwriter=0;
Set<Integer> openWriters = new HashSet<Integer>();
@ -110,9 +112,15 @@ public class TestIndexClose extends LuceneTestCase {
public int nopen() {
int ret=0;
for (int i: openReaders) {
System.err.println("reader "+i+" still open");
ret++;
for (DirectoryReader r: readers) {
try {
// this should throw ex, if already closed!
r.getTopReaderContext();
System.err.println("reader "+r+" still open");
ret++;
} catch (AlreadyClosedException e) {
// fine
}
}
for (int i: openWriters) {
System.err.println("writer "+i+" still open");
@ -126,8 +134,16 @@ public class TestIndexClose extends LuceneTestCase {
super(dir);
}
@Override
protected IndexReader openReader() throws IOException {
return new InstrumentedIndexReader(super.openReader());
protected DirectoryReader openReader() throws IOException {
DirectoryReader r = super.openReader();
readers.add(r);
return r;
}
@Override
protected synchronized void refreshReader() throws IOException {
super.refreshReader();
final DirectoryReader r = getInternalIndexReader();
if (r != null) readers.add(r);
}
@Override
protected IndexWriter openIndexWriter (Directory directory, IndexWriterConfig config) throws IOException {
@ -146,44 +162,19 @@ public class TestIndexClose extends LuceneTestCase {
super(dir);
}
@Override
protected IndexReader openIndexReader(Directory dir) throws CorruptIndexException, IOException {
return new InstrumentedIndexReader(IndexReader.open(dir));
}
}
private class InstrumentedIndexReader extends FilterIndexReader {
int mynum;
public InstrumentedIndexReader(IndexReader in) {
super(in);
this.in = in;
mynum = ireader++;
openReaders.add(mynum);
// System.err.println("opened "+mynum);
protected DirectoryReader openIndexReader(Directory dir) throws CorruptIndexException, IOException {
DirectoryReader r = super.openIndexReader(dir);
readers.add(r);
return r;
}
@Override
protected synchronized IndexReader doOpenIfChanged() throws CorruptIndexException, IOException {
IndexReader n = IndexReader.openIfChanged(in);
if (n == null) {
return null;
}
return new InstrumentedIndexReader(n);
}
// Unfortunately, IndexReader.close() is marked final so we can't
// change it! Fortunately, close() calls (if the object wasn't
// already closed) doClose() so we can override it to do our thing -
// just like FilterIndexReader does.
@Override
public void doClose() throws IOException {
in.close();
if (!openReaders.contains(mynum)) { // probably can't happen...
fail("Reader #"+mynum+" was closed twice!");
}
openReaders.remove(mynum);
// System.err.println("closed "+mynum);
public synchronized boolean refresh() throws IOException, InconsistentTaxonomyException {
final boolean ret = super.refresh();
readers.add(getInternalIndexReader());
return ret;
}
}
private class InstrumentedIndexWriter extends IndexWriter {
int mynum;
public InstrumentedIndexWriter(Directory d, IndexWriterConfig conf) throws CorruptIndexException, LockObtainFailedException, IOException {