Apache Lucene open-source search software
LUCENE-2586: move the mock intblock/sep codecs out of core, into test
Michael McCandlessf36a069d11d7
diff --git a/lucene/src/java/org/apache/lucene/index/codecs/CodecProvider.java b/lucene/src/java/org/apache/lucene/index/codecs/CodecProvider.javaindex dcc132cf684..4c71c0c0b12 100644--- a/lucene/src/java/org/apache/lucene/index/codecs/CodecProvider.java+++ b/lucene/src/java/org/apache/lucene/index/codecs/CodecProvider.java@@ -23,10 +23,8 @@ import java.util.HashSet;import java.util.Set;import org.apache.lucene.index.SegmentWriteState;-import org.apache.lucene.index.codecs.intblock.IntBlockCodec;import org.apache.lucene.index.codecs.preflex.PreFlexCodec;import org.apache.lucene.index.codecs.pulsing.PulsingCodec;-import org.apache.lucene.index.codecs.sep.SepCodec;import org.apache.lucene.index.codecs.standard.StandardCodec;/** Holds a set of codecs, keyed by name. You subclass@@ -47,7 +45,7 @@ public abstract class CodecProvider {private static String defaultCodec = "Standard";- public final static String[] CORE_CODECS = new String[] {"Standard", "Sep", "Pulsing", "IntBlock", "PreFlex"};+ public final static String[] CORE_CODECS = new String[] {"Standard", "Pulsing", "PreFlex"};public synchronized void register(Codec codec) {if (codec.name == null) {@@ -116,10 +114,8 @@ public abstract class CodecProvider {class DefaultCodecProvider extends CodecProvider {DefaultCodecProvider() {register(new StandardCodec());- register(new IntBlockCodec());register(new PreFlexCodec());register(new PulsingCodec());- register(new SepCodec());}@Overridediff --git a/lucene/src/java/org/apache/lucene/index/codecs/sep/SepPostingsReaderImpl.java b/lucene/src/java/org/apache/lucene/index/codecs/sep/SepPostingsReaderImpl.javaindex 4c529570244..5b40d4a1975 100644--- a/lucene/src/java/org/apache/lucene/index/codecs/sep/SepPostingsReaderImpl.java+++ b/lucene/src/java/org/apache/lucene/index/codecs/sep/SepPostingsReaderImpl.java@@ -59,15 +59,15 @@ public class SepPostingsReaderImpl extends StandardPostingsReader {boolean success = false;try {- final String docFileName = IndexFileNames.segmentFileName(segmentInfo.name, "", SepCodec.DOC_EXTENSION);+ final String docFileName = IndexFileNames.segmentFileName(segmentInfo.name, "", SepPostingsWriterImpl.DOC_EXTENSION);docIn = intFactory.openInput(dir, docFileName);- skipIn = dir.openInput(IndexFileNames.segmentFileName(segmentInfo.name, "", SepCodec.SKIP_EXTENSION), readBufferSize);+ skipIn = dir.openInput(IndexFileNames.segmentFileName(segmentInfo.name, "", SepPostingsWriterImpl.SKIP_EXTENSION), readBufferSize);if (segmentInfo.getHasProx()) {- freqIn = intFactory.openInput(dir, IndexFileNames.segmentFileName(segmentInfo.name, "", SepCodec.FREQ_EXTENSION));- posIn = intFactory.openInput(dir, IndexFileNames.segmentFileName(segmentInfo.name, "", SepCodec.POS_EXTENSION), readBufferSize);- payloadIn = dir.openInput(IndexFileNames.segmentFileName(segmentInfo.name, "", SepCodec.PAYLOAD_EXTENSION), readBufferSize);+ freqIn = intFactory.openInput(dir, IndexFileNames.segmentFileName(segmentInfo.name, "", SepPostingsWriterImpl.FREQ_EXTENSION));+ posIn = intFactory.openInput(dir, IndexFileNames.segmentFileName(segmentInfo.name, "", SepPostingsWriterImpl.POS_EXTENSION), readBufferSize);+ payloadIn = dir.openInput(IndexFileNames.segmentFileName(segmentInfo.name, "", SepPostingsWriterImpl.PAYLOAD_EXTENSION), readBufferSize);} else {posIn = null;payloadIn = null;@@ -82,13 +82,13 @@ public class SepPostingsReaderImpl extends StandardPostingsReader {}public static void files(SegmentInfo segmentInfo, Collection<String> files) {- files.add(IndexFileNames.segmentFileName(segmentInfo.name, "", SepCodec.DOC_EXTENSION));- files.add(IndexFileNames.segmentFileName(segmentInfo.name, "", SepCodec.SKIP_EXTENSION));+ files.add(IndexFileNames.segmentFileName(segmentInfo.name, "", SepPostingsWriterImpl.DOC_EXTENSION));+ files.add(IndexFileNames.segmentFileName(segmentInfo.name, "", SepPostingsWriterImpl.SKIP_EXTENSION));if (segmentInfo.getHasProx()) {- files.add(IndexFileNames.segmentFileName(segmentInfo.name, "", SepCodec.FREQ_EXTENSION));- files.add(IndexFileNames.segmentFileName(segmentInfo.name, "", SepCodec.POS_EXTENSION));- files.add(IndexFileNames.segmentFileName(segmentInfo.name, "", SepCodec.PAYLOAD_EXTENSION));+ files.add(IndexFileNames.segmentFileName(segmentInfo.name, "", SepPostingsWriterImpl.FREQ_EXTENSION));+ files.add(IndexFileNames.segmentFileName(segmentInfo.name, "", SepPostingsWriterImpl.POS_EXTENSION));+ files.add(IndexFileNames.segmentFileName(segmentInfo.name, "", SepPostingsWriterImpl.PAYLOAD_EXTENSION));}}diff --git a/lucene/src/java/org/apache/lucene/index/codecs/sep/SepPostingsWriterImpl.java b/lucene/src/java/org/apache/lucene/index/codecs/sep/SepPostingsWriterImpl.javaindex bc063ece5d9..bc48482f0d0 100644--- a/lucene/src/java/org/apache/lucene/index/codecs/sep/SepPostingsWriterImpl.java+++ b/lucene/src/java/org/apache/lucene/index/codecs/sep/SepPostingsWriterImpl.java@@ -18,6 +18,7 @@ u * contributor license agreements. See the NOTICE file distributed with*/import java.io.IOException;+import java.util.Set;import org.apache.lucene.index.CorruptIndexException;import org.apache.lucene.index.FieldInfo;@@ -35,6 +36,12 @@ import org.apache.lucene.util.CodecUtil;public final class SepPostingsWriterImpl extends StandardPostingsWriter {final static String CODEC = "SepDocFreqSkip";+ final static String DOC_EXTENSION = "doc";+ final static String SKIP_EXTENSION = "skp";+ final static String FREQ_EXTENSION = "frq";+ final static String POS_EXTENSION = "pos";+ final static String PAYLOAD_EXTENSION = "pyl";+// Increment version to change it:final static int VERSION_START = 0;final static int VERSION_CURRENT = VERSION_START;@@ -76,24 +83,24 @@ public final class SepPostingsWriterImpl extends StandardPostingsWriter {public SepPostingsWriterImpl(SegmentWriteState state, IntStreamFactory factory) throws IOException {super();- final String docFileName = IndexFileNames.segmentFileName(state.segmentName, "", SepCodec.DOC_EXTENSION);+ final String docFileName = IndexFileNames.segmentFileName(state.segmentName, "", DOC_EXTENSION);state.flushedFiles.add(docFileName);docOut = factory.createOutput(state.directory, docFileName);docIndex = docOut.index();if (state.fieldInfos.hasProx()) {- final String frqFileName = IndexFileNames.segmentFileName(state.segmentName, "", SepCodec.FREQ_EXTENSION);+ final String frqFileName = IndexFileNames.segmentFileName(state.segmentName, "", FREQ_EXTENSION);state.flushedFiles.add(frqFileName);freqOut = factory.createOutput(state.directory, frqFileName);freqIndex = freqOut.index();- final String posFileName = IndexFileNames.segmentFileName(state.segmentName, "", SepCodec.POS_EXTENSION);+ final String posFileName = IndexFileNames.segmentFileName(state.segmentName, "", POS_EXTENSION);posOut = factory.createOutput(state.directory, posFileName);state.flushedFiles.add(posFileName);posIndex = posOut.index();// TODO: -- only if at least one field stores payloads?- final String payloadFileName = IndexFileNames.segmentFileName(state.segmentName, "", SepCodec.PAYLOAD_EXTENSION);+ final String payloadFileName = IndexFileNames.segmentFileName(state.segmentName, "", PAYLOAD_EXTENSION);state.flushedFiles.add(payloadFileName);payloadOut = state.directory.createOutput(payloadFileName);@@ -105,7 +112,7 @@ public final class SepPostingsWriterImpl extends StandardPostingsWriter {payloadOut = null;}- final String skipFileName = IndexFileNames.segmentFileName(state.segmentName, "", SepCodec.SKIP_EXTENSION);+ final String skipFileName = IndexFileNames.segmentFileName(state.segmentName, "", SKIP_EXTENSION);state.flushedFiles.add(skipFileName);skipOut = state.directory.createOutput(skipFileName);@@ -284,4 +291,12 @@ public final class SepPostingsWriterImpl extends StandardPostingsWriter {}}}++ public static void getExtensions(Set<String> extensions) {+ extensions.add(DOC_EXTENSION);+ extensions.add(FREQ_EXTENSION);+ extensions.add(SKIP_EXTENSION);+ extensions.add(POS_EXTENSION);+ extensions.add(PAYLOAD_EXTENSION);+ }}diff --git a/lucene/src/test/org/apache/lucene/index/TestCodecs.java b/lucene/src/test/org/apache/lucene/index/TestCodecs.javaindex f6e06dc4a93..c22a68e2bef 100644--- a/lucene/src/test/org/apache/lucene/index/TestCodecs.java+++ b/lucene/src/test/org/apache/lucene/index/TestCodecs.java@@ -32,7 +32,7 @@ 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.index.codecs.mocksep.MockSepCodec;import org.apache.lucene.search.DocIdSetIterator;import org.apache.lucene.search.IndexSearcher;import org.apache.lucene.search.PhraseQuery;@@ -344,7 +344,7 @@ public class TestCodecs extends MultiCodecTestCase {final Directory dir = new RAMDirectory();final IndexWriterConfig config = new IndexWriterConfig(Version.LUCENE_31,new MockAnalyzer());- config.setCodecProvider(new SepCodecs());+ config.setCodecProvider(new MockSepCodecs());final IndexWriter writer = new IndexWriter(dir, config);try {@@ -397,15 +397,15 @@ public class TestCodecs extends MultiCodecTestCase {}}- public static class SepCodecs extends CodecProvider {+ public static class MockSepCodecs extends CodecProvider {- protected SepCodecs() {- this.register(new SepCodec());+ protected MockSepCodecs() {+ this.register(new MockSepCodec());}@Overridepublic Codec getWriter(final SegmentWriteState state) {- return this.lookup("Sep");+ return this.lookup("MockSep");}}diff --git a/lucene/src/test/org/apache/lucene/index/codecs/intblock/TestIntBlockCodec.java b/lucene/src/test/org/apache/lucene/index/codecs/intblock/TestIntBlockCodec.javaindex 8ba714e7926..dd552181ea4 100644--- a/lucene/src/test/org/apache/lucene/index/codecs/intblock/TestIntBlockCodec.java+++ b/lucene/src/test/org/apache/lucene/index/codecs/intblock/TestIntBlockCodec.java@@ -20,19 +20,20 @@ package org.apache.lucene.index.codecs.intblock;import org.apache.lucene.util.LuceneTestCase;import org.apache.lucene.store.*;import org.apache.lucene.index.codecs.sep.*;+import org.apache.lucene.index.codecs.mockintblock.*;public class TestIntBlockCodec extends LuceneTestCase {public void testSimpleIntBlocks() throws Exception {Directory dir = new MockRAMDirectory();- IntIndexOutput out = new SimpleIntBlockIndexOutput(dir, "test", 128);+ IntIndexOutput out = new MockFixedIntBlockIndexOutput(dir, "test", 128);for(int i=0;i<11777;i++) {out.write(i);}out.close();- IntIndexInput in = new SimpleIntBlockIndexInput(dir, "test", 128);+ IntIndexInput in = new MockFixedIntBlockIndexInput(dir, "test", 128);IntIndexInput.Reader r = in.reader();for(int i=0;i<11777;i++) {@@ -46,11 +47,11 @@ public class TestIntBlockCodec extends LuceneTestCase {public void testEmptySimpleIntBlocks() throws Exception {Directory dir = new MockRAMDirectory();- IntIndexOutput out = new SimpleIntBlockIndexOutput(dir, "test", 128);+ IntIndexOutput out = new MockFixedIntBlockIndexOutput(dir, "test", 128);// write no intsout.close();- IntIndexInput in = new SimpleIntBlockIndexInput(dir, "test", 128);+ IntIndexInput in = new MockFixedIntBlockIndexInput(dir, "test", 128);in.reader();// read no intsin.close();diff --git a/lucene/src/java/org/apache/lucene/index/codecs/intblock/IntBlockCodec.java b/lucene/src/test/org/apache/lucene/index/codecs/mockintblock/MockFixedIntBlockCodec.javasimilarity index 89%rename from lucene/src/java/org/apache/lucene/index/codecs/intblock/IntBlockCodec.javarename to lucene/src/test/org/apache/lucene/index/codecs/mockintblock/MockFixedIntBlockCodec.javaindex 2b5c0a618be..77603be4336 100644--- a/lucene/src/java/org/apache/lucene/index/codecs/intblock/IntBlockCodec.java+++ b/lucene/src/test/org/apache/lucene/index/codecs/mockintblock/MockFixedIntBlockCodec.java@@ -1,4 +1,4 @@-package org.apache.lucene.index.codecs.intblock;+package org.apache.lucene.index.codecs.mockintblock;/*** Licensed to the Apache Software Foundation (ASF) under one or more@@ -26,7 +26,6 @@ import org.apache.lucene.index.SegmentReadState;import org.apache.lucene.index.codecs.Codec;import org.apache.lucene.index.codecs.FieldsConsumer;import org.apache.lucene.index.codecs.FieldsProducer;-import org.apache.lucene.index.codecs.sep.SepCodec;import org.apache.lucene.index.codecs.sep.SepPostingsReaderImpl;import org.apache.lucene.index.codecs.sep.SepPostingsWriterImpl;import org.apache.lucene.index.codecs.standard.SimpleStandardTermsIndexReader;@@ -42,17 +41,20 @@ import org.apache.lucene.store.Directory;import org.apache.lucene.util.BytesRef;/**- * @lucene.experimental+ * A silly codec that simply writes each block as a series+ * of vInts. Don't use this (performance will be poor)!+ * This is here just to test the core intblock codec+ * classes.*/-public class IntBlockCodec extends Codec {+public class MockFixedIntBlockCodec extends Codec {- public IntBlockCodec() {- name = "IntBlock";+ public MockFixedIntBlockCodec() {+ name = "MockFixedIntBlock";}@Overridepublic FieldsConsumer fieldsConsumer(SegmentWriteState state) throws IOException {- StandardPostingsWriter postingsWriter = new SepPostingsWriterImpl(state, new SimpleIntBlockFactory(1024));+ StandardPostingsWriter postingsWriter = new SepPostingsWriterImpl(state, new MockFixedIntBlockFactory(1024));boolean success = false;StandardTermsIndexWriter indexWriter;@@ -86,7 +88,7 @@ public class IntBlockCodec extends Codec {StandardPostingsReader postingsReader = new SepPostingsReaderImpl(state.dir,state.segmentInfo,state.readBufferSize,- new SimpleIntBlockFactory(1024));+ new MockFixedIntBlockFactory(1024));StandardTermsIndexReader indexReader;boolean success = false;@@ -135,6 +137,8 @@ public class IntBlockCodec extends Codec {@Overridepublic void getExtensions(Set<String> extensions) {- SepCodec.getSepExtensions(extensions);+ SepPostingsWriterImpl.getExtensions(extensions);+ StandardTermsDictReader.getExtensions(extensions);+ SimpleStandardTermsIndexReader.getIndexExtensions(extensions);}}diff --git a/lucene/src/java/org/apache/lucene/index/codecs/sep/SingleIntFactory.java b/lucene/src/test/org/apache/lucene/index/codecs/mockintblock/MockFixedIntBlockFactory.javasimilarity index 59%rename from lucene/src/java/org/apache/lucene/index/codecs/sep/SingleIntFactory.javarename to lucene/src/test/org/apache/lucene/index/codecs/mockintblock/MockFixedIntBlockFactory.javaindex 02a70f0371d..0796b6a7297 100644--- a/lucene/src/java/org/apache/lucene/index/codecs/sep/SingleIntFactory.java+++ b/lucene/src/test/org/apache/lucene/index/codecs/mockintblock/MockFixedIntBlockFactory.java@@ -1,4 +1,4 @@-package org.apache.lucene.index.codecs.sep;+package org.apache.lucene.index.codecs.mockintblock;/*** Licensed to the Apache Software Foundation (ASF) under one or more@@ -18,16 +18,27 @@ package org.apache.lucene.index.codecs.sep;*/import org.apache.lucene.store.Directory;+import org.apache.lucene.index.codecs.sep.IntStreamFactory;+import org.apache.lucene.index.codecs.sep.IntIndexInput;+import org.apache.lucene.index.codecs.sep.IntIndexOutput;+import java.io.IOException;-/** @lucene.experimental */-public class SingleIntFactory extends IntStreamFactory {+/** Silly int factory that reads/writes block of ints by+ * simply encoding each as vInt. Don't use this+ * (performance will be poor)! This is here just to test+ * the core intblock codec classes.*/+public class MockFixedIntBlockFactory extends IntStreamFactory {+ private final int blockSize;+ public MockFixedIntBlockFactory(int blockSize) {+ this.blockSize = blockSize;+ }@Overridepublic IntIndexInput openInput(Directory dir, String fileName, int readBufferSize) throws IOException {- return new SingleIntIndexInput(dir, fileName, readBufferSize);+ return new MockFixedIntBlockIndexInput(dir, fileName, readBufferSize);}@Overridepublic IntIndexOutput createOutput(Directory dir, String fileName) throws IOException {- return new SingleIntIndexOutput(dir, fileName);+ return new MockFixedIntBlockIndexOutput(dir, fileName, blockSize);}}diff --git a/lucene/src/java/org/apache/lucene/index/codecs/intblock/SimpleIntBlockIndexInput.java b/lucene/src/test/org/apache/lucene/index/codecs/mockintblock/MockFixedIntBlockIndexInput.javasimilarity index 75%rename from lucene/src/java/org/apache/lucene/index/codecs/intblock/SimpleIntBlockIndexInput.javarename to lucene/src/test/org/apache/lucene/index/codecs/mockintblock/MockFixedIntBlockIndexInput.javaindex d03fc49fbae..63774b2bb4f 100644--- a/lucene/src/java/org/apache/lucene/index/codecs/intblock/SimpleIntBlockIndexInput.java+++ b/lucene/src/test/org/apache/lucene/index/codecs/mockintblock/MockFixedIntBlockIndexInput.java@@ -1,4 +1,4 @@-package org.apache.lucene.index.codecs.intblock;+package org.apache.lucene.index.codecs.mockintblock;/*** Licensed to the Apache Software Foundation (ASF) under one or more@@ -24,21 +24,18 @@ package org.apache.lucene.index.codecs.intblock;import org.apache.lucene.util.CodecUtil;import org.apache.lucene.store.Directory;import org.apache.lucene.store.IndexInput;+import org.apache.lucene.index.codecs.intblock.FixedIntBlockIndexInput;import java.io.IOException;-/**- * Don't use this class!! It naively encodes ints one vInt- * at a time. Use it only for testing.- *- * @lucene.experimental- */-public class SimpleIntBlockIndexInput extends FixedIntBlockIndexInput {+/** Don't use this class!! It naively encodes ints one vInt+ * at a time. Use it only for testing. */+public class MockFixedIntBlockIndexInput extends FixedIntBlockIndexInput {- public SimpleIntBlockIndexInput(Directory dir, String fileName, int readBufferSize) throws IOException {+ public MockFixedIntBlockIndexInput(Directory dir, String fileName, int readBufferSize) throws IOException {IndexInput in = dir.openInput(fileName, readBufferSize);- CodecUtil.checkHeader(in, SimpleIntBlockIndexOutput.CODEC,- SimpleIntBlockIndexOutput.VERSION_START, SimpleIntBlockIndexOutput.VERSION_START);+ CodecUtil.checkHeader(in, MockFixedIntBlockIndexOutput.CODEC,+ MockFixedIntBlockIndexOutput.VERSION_START, MockFixedIntBlockIndexOutput.VERSION_START);init(in);}diff --git a/lucene/src/java/org/apache/lucene/index/codecs/intblock/SimpleIntBlockIndexOutput.java b/lucene/src/test/org/apache/lucene/index/codecs/mockintblock/MockFixedIntBlockIndexOutput.javasimilarity index 79%rename from lucene/src/java/org/apache/lucene/index/codecs/intblock/SimpleIntBlockIndexOutput.javarename to lucene/src/test/org/apache/lucene/index/codecs/mockintblock/MockFixedIntBlockIndexOutput.javaindex d0ae63fce6f..9394077c5c2 100644--- a/lucene/src/java/org/apache/lucene/index/codecs/intblock/SimpleIntBlockIndexOutput.java+++ b/lucene/src/test/org/apache/lucene/index/codecs/mockintblock/MockFixedIntBlockIndexOutput.java@@ -1,4 +1,4 @@-package org.apache.lucene.index.codecs.intblock;+package org.apache.lucene.index.codecs.mockintblock;/*** Licensed to the Apache Software Foundation (ASF) under one or more@@ -24,22 +24,19 @@ package org.apache.lucene.index.codecs.intblock;import org.apache.lucene.util.CodecUtil;import org.apache.lucene.store.Directory;import org.apache.lucene.store.IndexOutput;+import org.apache.lucene.index.codecs.intblock.FixedIntBlockIndexOutput;import java.io.IOException;-/**- * Don't use this class!! It naively encodes ints one vInt- * at a time. Use it only for testing.- *- * @lucene.experimental- */-public class SimpleIntBlockIndexOutput extends FixedIntBlockIndexOutput {+/** Don't use this class!! It naively encodes ints one vInt+ * at a time. Use it only for testing. */+public class MockFixedIntBlockIndexOutput extends FixedIntBlockIndexOutput {public final static String CODEC = "SIMPLE_INT_BLOCKS";public final static int VERSION_START = 0;public final static int VERSION_CURRENT = VERSION_START;- public SimpleIntBlockIndexOutput(Directory dir, String fileName, int blockSize) throws IOException {+ public MockFixedIntBlockIndexOutput(Directory dir, String fileName, int blockSize) throws IOException {IndexOutput out = dir.createOutput(fileName);CodecUtil.writeHeader(out, CODEC, VERSION_CURRENT);init(out, blockSize);diff --git a/lucene/src/java/org/apache/lucene/index/codecs/sep/SepCodec.java b/lucene/src/test/org/apache/lucene/index/codecs/mocksep/MockSepCodec.javasimilarity index 87%rename from lucene/src/java/org/apache/lucene/index/codecs/sep/SepCodec.javarename to lucene/src/test/org/apache/lucene/index/codecs/mocksep/MockSepCodec.javaindex f5041ae56cf..11c3150e336 100644--- a/lucene/src/java/org/apache/lucene/index/codecs/sep/SepCodec.java+++ b/lucene/src/test/org/apache/lucene/index/codecs/mocksep/MockSepCodec.java@@ -1,4 +1,4 @@-package org.apache.lucene.index.codecs.sep;+package org.apache.lucene.index.codecs.mocksep;/*** Licensed to the Apache Software Foundation (ASF) under one or more@@ -35,20 +35,27 @@ import org.apache.lucene.index.codecs.standard.StandardTermsDictWriter;import org.apache.lucene.index.codecs.standard.StandardTermsIndexReader;import org.apache.lucene.index.codecs.standard.StandardTermsIndexWriter;import org.apache.lucene.index.codecs.standard.StandardCodec;+import org.apache.lucene.index.codecs.sep.SepPostingsWriterImpl;+import org.apache.lucene.index.codecs.sep.SepPostingsReaderImpl;import org.apache.lucene.store.Directory;import org.apache.lucene.util.BytesRef;-/** @lucene.experimental */-public class SepCodec extends Codec {+/**+ * A silly codec that simply writes each file separately as+ * single vInts. Don't use this (performance will be poor)!+ * This is here just to test the core sep codec+ * classes.+ */+public class MockSepCodec extends Codec {- public SepCodec() {- name = "Sep";+ public MockSepCodec() {+ name = "MockSep";}@Overridepublic FieldsConsumer fieldsConsumer(SegmentWriteState state) throws IOException {- StandardPostingsWriter postingsWriter = new SepPostingsWriterImpl(state, new SingleIntFactory());+ StandardPostingsWriter postingsWriter = new SepPostingsWriterImpl(state, new MockSingleIntFactory());boolean success = false;StandardTermsIndexWriter indexWriter;@@ -77,16 +84,10 @@ public class SepCodec extends Codec {}}- final static String DOC_EXTENSION = "doc";- final static String SKIP_EXTENSION = "skp";- final static String FREQ_EXTENSION = "frq";- final static String POS_EXTENSION = "pos";- final static String PAYLOAD_EXTENSION = "pyl";-@Overridepublic FieldsProducer fieldsProducer(SegmentReadState state) throws IOException {- StandardPostingsReader postingsReader = new SepPostingsReaderImpl(state.dir, state.segmentInfo, state.readBufferSize, new SingleIntFactory());+ StandardPostingsReader postingsReader = new SepPostingsReaderImpl(state.dir, state.segmentInfo, state.readBufferSize, new MockSingleIntFactory());StandardTermsIndexReader indexReader;boolean success = false;@@ -139,11 +140,7 @@ public class SepCodec extends Codec {}public static void getSepExtensions(Set<String> extensions) {- extensions.add(DOC_EXTENSION);- extensions.add(FREQ_EXTENSION);- extensions.add(SKIP_EXTENSION);- extensions.add(POS_EXTENSION);- extensions.add(PAYLOAD_EXTENSION);+ SepPostingsWriterImpl.getExtensions(extensions);StandardTermsDictReader.getExtensions(extensions);SimpleStandardTermsIndexReader.getIndexExtensions(extensions);}diff --git a/lucene/src/java/org/apache/lucene/index/codecs/intblock/SimpleIntBlockFactory.java b/lucene/src/test/org/apache/lucene/index/codecs/mocksep/MockSingleIntFactory.javasimilarity index 78%rename from lucene/src/java/org/apache/lucene/index/codecs/intblock/SimpleIntBlockFactory.javarename to lucene/src/test/org/apache/lucene/index/codecs/mocksep/MockSingleIntFactory.javaindex 974a80e6a58..092db1269cd 100644--- a/lucene/src/java/org/apache/lucene/index/codecs/intblock/SimpleIntBlockFactory.java+++ b/lucene/src/test/org/apache/lucene/index/codecs/mocksep/MockSingleIntFactory.java@@ -1,4 +1,4 @@-package org.apache.lucene.index.codecs.intblock;+package org.apache.lucene.index.codecs.mocksep;/*** Licensed to the Apache Software Foundation (ASF) under one or more@@ -25,17 +25,13 @@ import org.apache.lucene.index.codecs.sep.IntIndexOutput;import java.io.IOException;/** @lucene.experimental */-public class SimpleIntBlockFactory extends IntStreamFactory {- private final int blockSize;- public SimpleIntBlockFactory(int blockSize) {- this.blockSize = blockSize;- }+public class MockSingleIntFactory extends IntStreamFactory {@Overridepublic IntIndexInput openInput(Directory dir, String fileName, int readBufferSize) throws IOException {- return new SimpleIntBlockIndexInput(dir, fileName, readBufferSize);+ return new MockSingleIntIndexInput(dir, fileName, readBufferSize);}@Overridepublic IntIndexOutput createOutput(Directory dir, String fileName) throws IOException {- return new SimpleIntBlockIndexOutput(dir, fileName, blockSize);+ return new MockSingleIntIndexOutput(dir, fileName);}}diff --git a/lucene/src/java/org/apache/lucene/index/codecs/sep/SingleIntIndexInput.java b/lucene/src/test/org/apache/lucene/index/codecs/mocksep/MockSingleIntIndexInput.javasimilarity index 85%rename from lucene/src/java/org/apache/lucene/index/codecs/sep/SingleIntIndexInput.javarename to lucene/src/test/org/apache/lucene/index/codecs/mocksep/MockSingleIntIndexInput.javaindex 4a639e3334a..b8e26f0651e 100644--- a/lucene/src/java/org/apache/lucene/index/codecs/sep/SingleIntIndexInput.java+++ b/lucene/src/test/org/apache/lucene/index/codecs/mocksep/MockSingleIntIndexInput.java@@ -1,4 +1,4 @@-package org.apache.lucene.index.codecs.sep;+package org.apache.lucene.index.codecs.mocksep;/*** Licensed to the Apache Software Foundation (ASF) under one or more@@ -22,6 +22,7 @@ import java.io.IOException;import org.apache.lucene.store.Directory;import org.apache.lucene.store.IndexInput;import org.apache.lucene.util.CodecUtil;+import org.apache.lucene.index.codecs.sep.IntIndexInput;/** Reads IndexInputs written with {@link* SingleIntIndexOutput}. NOTE: this class is just for@@ -30,14 +31,15 @@ import org.apache.lucene.util.CodecUtil;** @lucene.experimental*/-public class SingleIntIndexInput extends IntIndexInput {+public class MockSingleIntIndexInput extends IntIndexInput {private final IndexInput in;- public SingleIntIndexInput(Directory dir, String fileName, int readBufferSize)+ public MockSingleIntIndexInput(Directory dir, String fileName, int readBufferSize)throws IOException {in = dir.openInput(fileName, readBufferSize);- CodecUtil.checkHeader(in, SingleIntIndexOutput.CODEC,- SingleIntIndexOutput.VERSION_START, SingleIntIndexOutput.VERSION_START);+ CodecUtil.checkHeader(in, MockSingleIntIndexOutput.CODEC,+ MockSingleIntIndexOutput.VERSION_START,+ MockSingleIntIndexOutput.VERSION_START);}@Overridediff --git a/lucene/src/java/org/apache/lucene/index/codecs/sep/SingleIntIndexOutput.java b/lucene/src/test/org/apache/lucene/index/codecs/mocksep/MockSingleIntIndexOutput.javasimilarity index 89%rename from lucene/src/java/org/apache/lucene/index/codecs/sep/SingleIntIndexOutput.javarename to lucene/src/test/org/apache/lucene/index/codecs/mocksep/MockSingleIntIndexOutput.javaindex ebfb36c599f..0ebf5653485 100644--- a/lucene/src/java/org/apache/lucene/index/codecs/sep/SingleIntIndexOutput.java+++ b/lucene/src/test/org/apache/lucene/index/codecs/mocksep/MockSingleIntIndexOutput.java@@ -1,4 +1,4 @@-package org.apache.lucene.index.codecs.sep;+package org.apache.lucene.index.codecs.mocksep;/*** Licensed to the Apache Software Foundation (ASF) under one or more@@ -20,7 +20,7 @@ package org.apache.lucene.index.codecs.sep;import org.apache.lucene.store.IndexOutput;import org.apache.lucene.store.Directory;import org.apache.lucene.util.CodecUtil;-+import org.apache.lucene.index.codecs.sep.IntIndexOutput;import java.io.IOException;/** Writes ints directly to the file (not in blocks) as@@ -28,13 +28,13 @@ import java.io.IOException;** @lucene.experimental*/-public class SingleIntIndexOutput extends IntIndexOutput {+public class MockSingleIntIndexOutput extends IntIndexOutput {private final IndexOutput out;final static String CODEC = "SINGLE_INTS";final static int VERSION_START = 0;final static int VERSION_CURRENT = VERSION_START;- public SingleIntIndexOutput(Directory dir, String fileName) throws IOException {+ public MockSingleIntIndexOutput(Directory dir, String fileName) throws IOException {out = dir.createOutput(fileName);CodecUtil.writeHeader(out, CODEC, VERSION_CURRENT);}diff --git a/lucene/src/test/org/apache/lucene/util/LuceneTestCase.java b/lucene/src/test/org/apache/lucene/util/LuceneTestCase.javaindex 17eac777b23..e284167878e 100644--- a/lucene/src/test/org/apache/lucene/util/LuceneTestCase.java+++ b/lucene/src/test/org/apache/lucene/util/LuceneTestCase.java@@ -36,8 +36,6 @@ import org.apache.lucene.search.BooleanQuery;import org.apache.lucene.search.FieldCache;import org.apache.lucene.search.FieldCache.CacheEntry;import org.apache.lucene.util.FieldCacheSanityChecker.Insanity;-import org.apache.lucene.index.codecs.CodecProvider;-import org.apache.lucene.index.codecs.Codec;/*** Base class for all Lucene unit tests.@@ -85,9 +83,7 @@ public abstract class LuceneTestCase extends TestCase {private volatile Thread.UncaughtExceptionHandler savedUncaughtExceptionHandler = null;- private String savedDefaultCodec;private String codec;- private Codec preFlexSav;/** Used to track if setUp and tearDown are called correctly from subclasses */private boolean setup;@@ -127,19 +123,7 @@ public abstract class LuceneTestCase extends TestCase {ConcurrentMergeScheduler.setTestMode();savedBoolMaxClauseCount = BooleanQuery.getMaxClauseCount();- savedDefaultCodec = CodecProvider.getDefaultCodec();-- codec = TEST_CODEC;- if (codec.equals("random"))- codec = CodecProvider.CORE_CODECS[seedRnd.nextInt(CodecProvider.CORE_CODECS.length)];-- // If we're running w/ PreFlex codec we must swap in the- // test-only PreFlexRW codec (since core PreFlex can- // only read segments):- if (codec.equals("PreFlex")) {- preFlexSav = LuceneTestCaseJ4.installPreFlexRW();- }- CodecProvider.setDefaultCodec(codec);+ codec = LuceneTestCaseJ4.installTestCodecs();}/**@@ -165,11 +149,7 @@ public abstract class LuceneTestCase extends TestCase {assertTrue("ensure your setUp() calls super.setUp()!!!", setup);setup = false;BooleanQuery.setMaxClauseCount(savedBoolMaxClauseCount);- // Restore read-only PreFlex codec:- if (codec.equals("PreFlex")) {- LuceneTestCaseJ4.restorePreFlex(preFlexSav);- }- CodecProvider.setDefaultCodec(savedDefaultCodec);+ LuceneTestCaseJ4.removeTestCodecs(codec);try {Thread.setDefaultUncaughtExceptionHandler(savedUncaughtExceptionHandler);diff --git a/lucene/src/test/org/apache/lucene/util/LuceneTestCaseJ4.java b/lucene/src/test/org/apache/lucene/util/LuceneTestCaseJ4.javaindex 854bd9e23ea..016101ad972 100644--- a/lucene/src/test/org/apache/lucene/util/LuceneTestCaseJ4.java+++ b/lucene/src/test/org/apache/lucene/util/LuceneTestCaseJ4.java@@ -30,6 +30,9 @@ import org.apache.lucene.util.FieldCacheSanityChecker.Insanity;import org.apache.lucene.index.codecs.CodecProvider;import org.apache.lucene.index.codecs.Codec;import org.apache.lucene.index.codecs.preflexrw.PreFlexRWCodec;+import org.apache.lucene.index.codecs.preflex.PreFlexCodec;+import org.apache.lucene.index.codecs.mocksep.MockSepCodec;+import org.apache.lucene.index.codecs.mockintblock.MockFixedIntBlockCodec;import org.junit.After;import org.junit.AfterClass;@@ -152,51 +155,81 @@ public class LuceneTestCaseJ4 {// saves default codec: we do this statically as many build indexes in @beforeClassprivate static String savedDefaultCodec;private static String codec;- private static Codec preFlexSav;- // returns current PreFlex codec- public static Codec installPreFlexRW() {- final Codec preFlex = CodecProvider.getDefault().lookup("PreFlex");- if (preFlex != null) {- CodecProvider.getDefault().unregister(preFlex);+ private static final String[] TEST_CODECS = new String[] {"MockSep", "MockFixedIntBlock"};++ private static void swapCodec(Codec c) {+ final CodecProvider cp = CodecProvider.getDefault();+ Codec prior = null;+ try {+ prior = cp.lookup(c.name);+ } catch (IllegalArgumentException iae) {+ }+ if (prior != null) {+ cp.unregister(prior);}- CodecProvider.getDefault().register(new PreFlexRWCodec());- return preFlex;+ cp.register(c);+ }++ // returns current default codec+ static String installTestCodecs() {+ final CodecProvider cp = CodecProvider.getDefault();++ savedDefaultCodec = CodecProvider.getDefaultCodec();+ String codec = TEST_CODEC;+ if (codec.equals("random")) {+ codec = pickRandomCodec(seedRnd);+ }+ CodecProvider.setDefaultCodec(codec);++ if (codec.equals("PreFlex")) {+ // If we're running w/ PreFlex codec we must swap in the+ // test-only PreFlexRW codec (since core PreFlex can+ // only read segments):+ swapCodec(new PreFlexRWCodec());+ }++ swapCodec(new MockSepCodec());+ swapCodec(new MockFixedIntBlockCodec());++ return codec;}// returns current PreFlex codec- public static void restorePreFlex(Codec preFlex) {- Codec preFlexRW = CodecProvider.getDefault().lookup("PreFlex");- if (preFlexRW != null) {- CodecProvider.getDefault().unregister(preFlexRW);+ static void removeTestCodecs(String codec) {+ System.out.println("remove");+ final CodecProvider cp = CodecProvider.getDefault();+ if (codec.equals("PreFlex")) {+ final Codec preFlex = cp.lookup("PreFlex");+ if (preFlex != null) {+ cp.unregister(preFlex);+ }+ cp.register(new PreFlexCodec());+ }+ cp.unregister(cp.lookup("MockSep"));+ cp.unregister(cp.lookup("MockFixedIntBlock"));+ CodecProvider.setDefaultCodec(savedDefaultCodec);+ }++ // randomly picks from core and test codecs+ static String pickRandomCodec(Random rnd) {+ int idx = rnd.nextInt(CodecProvider.CORE_CODECS.length ++ TEST_CODECS.length);+ if (idx < CodecProvider.CORE_CODECS.length) {+ return CodecProvider.CORE_CODECS[idx];+ } else {+ return TEST_CODECS[idx - CodecProvider.CORE_CODECS.length];}- CodecProvider.getDefault().register(preFlex);}@BeforeClasspublic static void beforeClassLuceneTestCaseJ4() {- savedDefaultCodec = CodecProvider.getDefaultCodec();- codec = TEST_CODEC;- if (codec.equals("random"))- codec = CodecProvider.CORE_CODECS[seedRnd.nextInt(CodecProvider.CORE_CODECS.length)];-- // If we're running w/ PreFlex codec we must swap in the- // test-only PreFlexRW codec (since core PreFlex can- // only read segments):- if (codec.equals("PreFlex")) {- preFlexSav = installPreFlexRW();- }-- CodecProvider.setDefaultCodec(codec);+ codec = installTestCodecs();}@AfterClasspublic static void afterClassLuceneTestCaseJ4() {- // Restore read-only PreFlex codec:- if (codec.equals("PreFlex")) {- restorePreFlex(preFlexSav);- }- CodecProvider.setDefaultCodec(savedDefaultCodec);+ removeTestCodecs(codec);}// This is how we get control when errors occur.