mirror of https://github.com/apache/lucene.git
fix the core tests to pass (with any -Dtests.codec). pull codec randomization from RIW... we should support -Dtests.codec=random instead!
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/branches/preflexfixes@967165 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
3582913027
commit
68fe4bfc74
|
@ -61,6 +61,21 @@ public abstract class CodecProvider {
|
|||
throw new IllegalArgumentException("codec '" + codec.name + "' is already registered as a different codec instance");
|
||||
}
|
||||
}
|
||||
|
||||
/** @lucene.internal */
|
||||
public void unregister(Codec codec) {
|
||||
if (codec.name == null) {
|
||||
throw new IllegalArgumentException("code.name is null");
|
||||
}
|
||||
// nocommit
|
||||
if (codecs.containsKey(codec.name)) {
|
||||
Codec c = codecs.get(codec.name);
|
||||
if (codec.getClass().isAssignableFrom(c.getClass()))
|
||||
codecs.remove(codec.name);
|
||||
else
|
||||
throw new IllegalArgumentException("codec '" + codec.name + "' is being impersonated by a different codec instance!!!");
|
||||
}
|
||||
}
|
||||
|
||||
public Collection<String> getAllExtensions() {
|
||||
return knownExtensions;
|
||||
|
|
|
@ -17,21 +17,14 @@ package org.apache.lucene.index;
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import java.util.Random;
|
||||
import java.io.Closeable;
|
||||
import java.io.IOException;
|
||||
import java.util.Random;
|
||||
|
||||
import org.apache.lucene.util._TestUtil;
|
||||
import org.apache.lucene.store.Directory;
|
||||
import org.apache.lucene.document.Document;
|
||||
import org.apache.lucene.index.codecs.Codec;
|
||||
import org.apache.lucene.index.codecs.CodecProvider;
|
||||
import org.apache.lucene.index.codecs.intblock.IntBlockCodec;
|
||||
import org.apache.lucene.index.codecs.preflex.PreFlexCodec;
|
||||
import org.apache.lucene.index.codecs.preflexrw.PreFlexRWCodec;
|
||||
import org.apache.lucene.index.codecs.pulsing.PulsingCodec;
|
||||
import org.apache.lucene.index.codecs.sep.SepCodec;
|
||||
import org.apache.lucene.index.codecs.standard.StandardCodec;
|
||||
import org.apache.lucene.store.Directory;
|
||||
import org.apache.lucene.util._TestUtil;
|
||||
|
||||
/** Silly class that randomizes the indexing experience. EG
|
||||
* it may swap in a different merge policy/scheduler; may
|
||||
|
@ -69,7 +62,6 @@ public class RandomIndexWriter implements Closeable {
|
|||
}
|
||||
|
||||
c.setReaderPooling(r.nextBoolean());
|
||||
c.setCodecProvider(new RandomCodecProvider(r));
|
||||
w = new IndexWriter(dir, c);
|
||||
flushAt = _TestUtil.nextInt(r, 10, 1000);
|
||||
}
|
||||
|
@ -123,27 +115,4 @@ public class RandomIndexWriter implements Closeable {
|
|||
public void optimize() throws IOException {
|
||||
w.optimize();
|
||||
}
|
||||
|
||||
class RandomCodecProvider extends CodecProvider {
|
||||
final String codec;
|
||||
|
||||
RandomCodecProvider(Random random) {
|
||||
register(new StandardCodec());
|
||||
register(new IntBlockCodec());
|
||||
// nocommit
|
||||
//register(new PreFlexCodec());
|
||||
register(new PreFlexRWCodec());
|
||||
register(new PulsingCodec());
|
||||
register(new SepCodec());
|
||||
// nocommit
|
||||
//codec =
|
||||
//CodecProvider.CORE_CODECS[random.nextInt(CodecProvider.CORE_CODECS.length)];
|
||||
codec = "PreFlex";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Codec getWriter(SegmentWriteState state) {
|
||||
return lookup(codec);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -75,6 +75,7 @@ public abstract class LuceneTestCase extends TestCase {
|
|||
private volatile Thread.UncaughtExceptionHandler savedUncaughtExceptionHandler = null;
|
||||
|
||||
private String savedDefaultCodec;
|
||||
private String codec;
|
||||
|
||||
/** Used to track if setUp and tearDown are called correctly from subclasses */
|
||||
private boolean setup;
|
||||
|
@ -115,7 +116,12 @@ public abstract class LuceneTestCase extends TestCase {
|
|||
ConcurrentMergeScheduler.setTestMode();
|
||||
savedBoolMaxClauseCount = BooleanQuery.getMaxClauseCount();
|
||||
savedDefaultCodec = CodecProvider.getDefaultCodec();
|
||||
CodecProvider.setDefaultCodec(_TestUtil.getTestCodec());
|
||||
codec = _TestUtil.getTestCodec();
|
||||
//nocommit
|
||||
if (codec.equals("PreFlex")) {
|
||||
CodecProvider.getDefault().register(new PreFlexRWCodec());
|
||||
}
|
||||
CodecProvider.setDefaultCodec(codec);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -141,6 +147,10 @@ public abstract class LuceneTestCase extends TestCase {
|
|||
assertTrue("ensure your setUp() calls super.setUp()!!!", setup);
|
||||
setup = false;
|
||||
BooleanQuery.setMaxClauseCount(savedBoolMaxClauseCount);
|
||||
// nocommit
|
||||
if (codec.equals("PreFlex")) {
|
||||
CodecProvider.getDefault().unregister(new PreFlexRWCodec());
|
||||
}
|
||||
CodecProvider.setDefaultCodec(savedDefaultCodec);
|
||||
|
||||
try {
|
||||
|
@ -305,10 +315,4 @@ public abstract class LuceneTestCase extends TestCase {
|
|||
|
||||
// static members
|
||||
private static final Random seedRnd = new Random();
|
||||
|
||||
// register preflex-rw statically.
|
||||
static {
|
||||
CodecProvider.getDefault().register(new PreFlexRWCodec());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -134,15 +134,24 @@ public class LuceneTestCaseJ4 {
|
|||
|
||||
// saves default codec: we do this statically as many build indexes in @beforeClass
|
||||
private static String savedDefaultCodec;
|
||||
private static String codec;
|
||||
|
||||
@BeforeClass
|
||||
public static void beforeClassLuceneTestCaseJ4() {
|
||||
savedDefaultCodec = CodecProvider.getDefaultCodec();
|
||||
CodecProvider.setDefaultCodec(_TestUtil.getTestCodec());
|
||||
codec = _TestUtil.getTestCodec();
|
||||
//nocommit
|
||||
if (codec.equals("PreFlex")) {
|
||||
CodecProvider.getDefault().register(new PreFlexRWCodec());
|
||||
}
|
||||
CodecProvider.setDefaultCodec(codec);
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void afterClassLuceneTestCaseJ4() {
|
||||
//nocommit
|
||||
if (codec.equals("PreFlex"))
|
||||
CodecProvider.getDefault().unregister(new PreFlexRWCodec());
|
||||
CodecProvider.setDefaultCodec(savedDefaultCodec);
|
||||
}
|
||||
|
||||
|
@ -423,9 +432,4 @@ public class LuceneTestCaseJ4 {
|
|||
private static final Random seedRnd = new Random();
|
||||
|
||||
private String name = "<unknown>";
|
||||
|
||||
// register PreFlexRWCodec statically
|
||||
static {
|
||||
CodecProvider.getDefault().register(new PreFlexRWCodec());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue