Index: CHANGES.txt =================================================================== --- CHANGES.txt (revision 927086) +++ CHANGES.txt (working copy) @@ -17,6 +17,10 @@ * LUCENE-2222: FixedIntBlockIndexInput incorrectly read one block of 0s before the actual data. (Renaud Delbru via Mike McCandless) + +* LUCENE-2344: PostingsConsumer.merge was failing to call finishDoc, + which caused corruption for sep codec. Also fixed several tests to + test all 4 core codecs. (Renaud Delbru via Mike McCandless) New features Index: src/test/org/apache/lucene/index/TestStressIndexing2.java =================================================================== --- src/test/org/apache/lucene/index/TestStressIndexing2.java (revision 927086) +++ src/test/org/apache/lucene/index/TestStressIndexing2.java (working copy) @@ -37,7 +37,7 @@ import org.apache.lucene.store.Directory; import org.apache.lucene.store.MockRAMDirectory; -public class TestStressIndexing2 extends LuceneTestCase { +public class TestStressIndexing2 extends MultiCodecTestCase { static int maxFields=4; static int bigFieldSize=10; static boolean sameFieldOrder=false; Index: src/test/org/apache/lucene/index/TestCodecs.java =================================================================== --- src/test/org/apache/lucene/index/TestCodecs.java (revision 927086) +++ src/test/org/apache/lucene/index/TestCodecs.java (working copy) @@ -17,12 +17,34 @@ * limitations under the License. */ -import org.apache.lucene.util.*; -import org.apache.lucene.index.codecs.*; -import org.apache.lucene.index.codecs.standard.*; -import org.apache.lucene.store.*; -import java.util.*; +import java.io.IOException; +import java.util.Arrays; +import java.util.HashSet; +import java.util.Random; +import org.apache.lucene.analysis.WhitespaceAnalyzer; +import org.apache.lucene.document.Document; +import org.apache.lucene.document.Field; +import org.apache.lucene.document.Field.Store; +import org.apache.lucene.index.codecs.Codec; +import org.apache.lucene.index.codecs.CodecProvider; +import org.apache.lucene.index.codecs.FieldsConsumer; +import org.apache.lucene.index.codecs.FieldsProducer; +import org.apache.lucene.index.codecs.PostingsConsumer; +import org.apache.lucene.index.codecs.TermsConsumer; +import org.apache.lucene.index.codecs.sep.SepCodec; +import org.apache.lucene.search.DocIdSetIterator; +import org.apache.lucene.search.IndexSearcher; +import org.apache.lucene.search.PhraseQuery; +import org.apache.lucene.search.Query; +import org.apache.lucene.search.ScoreDoc; +import org.apache.lucene.store.Directory; +import org.apache.lucene.store.MockRAMDirectory; +import org.apache.lucene.store.RAMDirectory; +import org.apache.lucene.util.BytesRef; +import org.apache.lucene.util.MultiCodecTestCase; +import org.apache.lucene.util.Version; + // TODO: test multiple codecs here? // TODO @@ -41,7 +63,7 @@ // - skipTo(term) // - skipTo(doc) -public class TestCodecs extends LuceneTestCase { +public class TestCodecs extends MultiCodecTestCase { private Random RANDOM; private static String[] fieldNames = new String[] {"one", "two", "three", "four"}; @@ -54,20 +76,20 @@ private final static int TERM_DOC_FREQ_RAND = 20; // start is inclusive and end is exclusive - public int nextInt(int start, int end) { + public int nextInt(final int start, final int end) { return start + RANDOM.nextInt(end-start); } - private int nextInt(int lim) { + private int nextInt(final int lim) { return RANDOM.nextInt(lim); } char[] getRandomText() { - final int len = 1+nextInt(10); - char[] buffer = new char[len+1]; + final int len = 1+this.nextInt(10); + final char[] buffer = new char[len+1]; for(int i=0;i termsSeen = new HashSet(); @@ -192,16 +214,16 @@ char[] text; String text2; while(true) { - text = getRandomText(); + text = this.getRandomText(); text2 = new String(text, 0, text.length-1); if (!termsSeen.contains(text2)) { termsSeen.add(text2); break; } } - - final int docFreq = 1+nextInt(DOC_FREQ_RAND); - int[] docs = new int[docFreq]; + + final int docFreq = 1+this.nextInt(DOC_FREQ_RAND); + final int[] docs = new int[docFreq]; PositionData[][] positions; if (!omitTF) @@ -211,21 +233,21 @@ int docID = 0; for(int j=0;j= 1) { - int inc = 1+nextInt(left-1); + if (TestCodecs.this.nextInt(3) == 1 && left >= 1) { + final int inc = 1+TestCodecs.this.nextInt(left-1); upto2 += inc; if (Codec.DEBUG) { - System.out.println("TEST [" + getDesc(field, term) + "]: skip: " + left + " docs left; skip to doc=" + term.docs[upto2] + " [" + upto2 + " of " + term.docs.length + "]"); + System.out.println("TEST [" + TestCodecs.this.getDesc(field, term) + "]: skip: " + left + " docs left; skip to doc=" + term.docs[upto2] + " [" + upto2 + " of " + term.docs.length + "]"); } - if (nextInt(2) == 1) { + if (TestCodecs.this.nextInt(2) == 1) { doc = docsEnum.advance(term.docs[upto2]); assertEquals(term.docs[upto2], doc); } else { doc = docsEnum.advance(1+term.docs[upto2]); - if (doc == DocsEnum.NO_MORE_DOCS) { + if (doc == DocIdSetIterator.NO_MORE_DOCS) { // skipped past last doc assert upto2 == term.docs.length-1; break; @@ -548,18 +641,18 @@ doc = docsEnum.nextDoc(); assertTrue(doc != -1); if (Codec.DEBUG) { - System.out.println("TEST [" + getDesc(field, term) + "]: got next doc..."); + System.out.println("TEST [" + TestCodecs.this.getDesc(field, term) + "]: got next doc..."); } upto2++; } assertEquals(term.docs[upto2], doc); if (!field.omitTF) { assertEquals(term.positions[upto2].length, docsEnum.freq()); - if (nextInt(2) == 1) { + if (TestCodecs.this.nextInt(2) == 1) { if (Codec.DEBUG) { - System.out.println("TEST [" + getDesc(field, term, term.docs[upto2]) + "]: check positions for doc " + term.docs[upto2] + "..."); + System.out.println("TEST [" + TestCodecs.this.getDesc(field, term, term.docs[upto2]) + "]: check positions for doc " + term.docs[upto2] + "..."); } - verifyPositions(term.positions[upto2], postings); + this.verifyPositions(term.positions[upto2], postings); } else if (Codec.DEBUG) { System.out.println("TEST: skip positions..."); } @@ -568,10 +661,10 @@ } } - assertEquals(DocsEnum.NO_MORE_DOCS, docsEnum.nextDoc()); + assertEquals(DocIdSetIterator.NO_MORE_DOCS, docsEnum.nextDoc()); } else if (Codec.DEBUG) { - System.out.println("\nTEST [" + getDesc(field, term) + "]: skip docs"); + System.out.println("\nTEST [" + TestCodecs.this.getDesc(field, term) + "]: skip docs"); } upto++; @@ -582,17 +675,17 @@ } } - private void write(FieldInfos fieldInfos, Directory dir, FieldData[] fields) throws Throwable { + private void write(final FieldInfos fieldInfos, final Directory dir, final FieldData[] fields) throws Throwable { - final int termIndexInterval = nextInt(13, 27); + final int termIndexInterval = this.nextInt(13, 27); - SegmentWriteState state = new SegmentWriteState(null, dir, SEGMENT, fieldInfos, null, 10000, 10000, termIndexInterval, + final SegmentWriteState state = new SegmentWriteState(null, dir, SEGMENT, fieldInfos, null, 10000, 10000, termIndexInterval, CodecProvider.getDefault()); final FieldsConsumer consumer = state.codec.fieldsConsumer(state); Arrays.sort(fields); - for(int i=0;i knownExtensions = new HashSet(); + private static String defaultCodec = "Standard"; + + public final static String[] CORE_CODECS = new String[] {"Standard", "Sep", "Pulsing", "IntBlock"}; + public void register(Codec codec) { if (codec.name == null) { throw new IllegalArgumentException("code.name is null"); @@ -74,6 +78,15 @@ public static CodecProvider getDefault() { return defaultCodecs; } + + /** Used for testing. @lucene.internal */ + public static void setDefaultCodec(String s) { + defaultCodec = s; + } + /** Used for testing. @lucene.internal */ + public static String getDefaultCodec() { + return defaultCodec; + } } class DefaultCodecProvider extends CodecProvider { @@ -87,7 +100,7 @@ @Override public Codec getWriter(SegmentWriteState state) { - return lookup("Standard"); + return lookup(CodecProvider.getDefaultCodec()); //return lookup("Pulsing"); //return lookup("Sep"); //return lookup("IntBlock");