mirror of https://github.com/apache/lucene.git
LUCENE-2649 -- Adding a test to check for changing the parser.
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1001567 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
b849d518a0
commit
e071186aa3
|
@ -76,11 +76,15 @@ public class ByteValuesCreator extends CachedArrayCreator<ByteValues>
|
|||
@Override
|
||||
public ByteValues validate(ByteValues entry, IndexReader reader) throws IOException {
|
||||
boolean ok = false;
|
||||
|
||||
if( hasOption(OPTION_CACHE_VALUES) ) {
|
||||
ok = true;
|
||||
if( entry.values == null ) {
|
||||
fillByteValues(entry, reader, field);
|
||||
}
|
||||
else {
|
||||
assertSameParser( entry, parser );
|
||||
}
|
||||
}
|
||||
if( hasOption(OPTION_CACHE_BITS) ) {
|
||||
ok = true;
|
||||
|
@ -99,7 +103,7 @@ public class ByteValuesCreator extends CachedArrayCreator<ByteValues>
|
|||
if( parser == null ) {
|
||||
parser = FieldCache.DEFAULT_BYTE_PARSER;
|
||||
}
|
||||
assertSameParserAndResetCounts(vals, parser);
|
||||
setParserAndResetCounts(vals, parser);
|
||||
|
||||
Terms terms = MultiFields.getTerms(reader, field);
|
||||
int maxDoc = reader.maxDoc();
|
||||
|
|
|
@ -75,7 +75,7 @@ public abstract class CachedArrayCreator<T extends CachedArray> extends EntryCre
|
|||
public abstract Parser getParser();
|
||||
public abstract int getSortTypeID();
|
||||
|
||||
protected void assertSameParserAndResetCounts(T value, Parser parser)
|
||||
protected void setParserAndResetCounts(T value, Parser parser)
|
||||
{
|
||||
int parserHashCode = parser.hashCode();
|
||||
if( value.parserHashCode != null && value.parserHashCode != parserHashCode ) {
|
||||
|
@ -86,6 +86,17 @@ public abstract class CachedArrayCreator<T extends CachedArray> extends EntryCre
|
|||
value.numDocs = value.numTerms = 0;
|
||||
}
|
||||
|
||||
protected void assertSameParser(T value, Parser parser)
|
||||
{
|
||||
if( parser != null && value.parserHashCode != null ) {
|
||||
int parserHashCode = parser.hashCode();
|
||||
if( value.parserHashCode != parserHashCode ) {
|
||||
throw new RuntimeException( "Parser changed in subsequet call. "
|
||||
+value.parserHashCode+" != "+parserHashCode + " :: " + parser );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Utility function to help check what bits are valid
|
||||
*/
|
||||
|
|
|
@ -76,11 +76,15 @@ public class DoubleValuesCreator extends CachedArrayCreator<DoubleValues>
|
|||
@Override
|
||||
public DoubleValues validate(DoubleValues entry, IndexReader reader) throws IOException {
|
||||
boolean ok = false;
|
||||
|
||||
if( hasOption(OPTION_CACHE_VALUES) ) {
|
||||
ok = true;
|
||||
if( entry.values == null ) {
|
||||
fillDoubleValues(entry, reader, field);
|
||||
}
|
||||
else {
|
||||
assertSameParser( entry, parser );
|
||||
}
|
||||
}
|
||||
if( hasOption(OPTION_CACHE_BITS) ) {
|
||||
ok = true;
|
||||
|
@ -109,7 +113,7 @@ public class DoubleValuesCreator extends CachedArrayCreator<DoubleValues>
|
|||
return;
|
||||
}
|
||||
}
|
||||
assertSameParserAndResetCounts(vals, parser);
|
||||
setParserAndResetCounts(vals, parser);
|
||||
|
||||
Terms terms = MultiFields.getTerms(reader, field);
|
||||
int maxDoc = reader.maxDoc();
|
||||
|
|
|
@ -77,11 +77,15 @@ public class FloatValuesCreator extends CachedArrayCreator<FloatValues>
|
|||
@Override
|
||||
public FloatValues validate(FloatValues entry, IndexReader reader) throws IOException {
|
||||
boolean ok = false;
|
||||
|
||||
if( hasOption(OPTION_CACHE_VALUES) ) {
|
||||
ok = true;
|
||||
if( entry.values == null ) {
|
||||
fillFloatValues(entry, reader, field);
|
||||
}
|
||||
else {
|
||||
assertSameParser( entry, parser );
|
||||
}
|
||||
}
|
||||
if( hasOption(OPTION_CACHE_BITS) ) {
|
||||
ok = true;
|
||||
|
@ -110,7 +114,7 @@ public class FloatValuesCreator extends CachedArrayCreator<FloatValues>
|
|||
return;
|
||||
}
|
||||
}
|
||||
assertSameParserAndResetCounts(vals, parser);
|
||||
setParserAndResetCounts(vals, parser);
|
||||
|
||||
Terms terms = MultiFields.getTerms(reader, field);
|
||||
int maxDoc = reader.maxDoc();
|
||||
|
|
|
@ -77,11 +77,15 @@ public class IntValuesCreator extends CachedArrayCreator<IntValues>
|
|||
@Override
|
||||
public IntValues validate(IntValues entry, IndexReader reader) throws IOException {
|
||||
boolean ok = false;
|
||||
|
||||
if( hasOption(OPTION_CACHE_VALUES) ) {
|
||||
ok = true;
|
||||
if( entry.values == null ) {
|
||||
fillIntValues(entry, reader, field);
|
||||
}
|
||||
else {
|
||||
assertSameParser( entry, parser );
|
||||
}
|
||||
}
|
||||
if( hasOption(OPTION_CACHE_BITS) ) {
|
||||
ok = true;
|
||||
|
@ -110,7 +114,7 @@ public class IntValuesCreator extends CachedArrayCreator<IntValues>
|
|||
return;
|
||||
}
|
||||
}
|
||||
assertSameParserAndResetCounts(vals, parser);
|
||||
setParserAndResetCounts(vals, parser);
|
||||
|
||||
Terms terms = MultiFields.getTerms(reader, field);
|
||||
int maxDoc = reader.maxDoc();
|
||||
|
|
|
@ -77,11 +77,15 @@ public class LongValuesCreator extends CachedArrayCreator<LongValues>
|
|||
@Override
|
||||
public LongValues validate(LongValues entry, IndexReader reader) throws IOException {
|
||||
boolean ok = false;
|
||||
|
||||
if( hasOption(OPTION_CACHE_VALUES) ) {
|
||||
ok = true;
|
||||
if( entry.values == null ) {
|
||||
fillLongValues(entry, reader, field);
|
||||
}
|
||||
else {
|
||||
assertSameParser( entry, parser );
|
||||
}
|
||||
}
|
||||
if( hasOption(OPTION_CACHE_BITS) ) {
|
||||
ok = true;
|
||||
|
@ -110,7 +114,7 @@ public class LongValuesCreator extends CachedArrayCreator<LongValues>
|
|||
return;
|
||||
}
|
||||
}
|
||||
assertSameParserAndResetCounts(vals, parser);
|
||||
setParserAndResetCounts(vals, parser);
|
||||
|
||||
Terms terms = MultiFields.getTerms(reader, field);
|
||||
int maxDoc = reader.maxDoc();
|
||||
|
|
|
@ -77,11 +77,15 @@ public class ShortValuesCreator extends CachedArrayCreator<ShortValues>
|
|||
@Override
|
||||
public ShortValues validate(ShortValues entry, IndexReader reader) throws IOException {
|
||||
boolean ok = false;
|
||||
|
||||
if( hasOption(OPTION_CACHE_VALUES) ) {
|
||||
ok = true;
|
||||
if( entry.values == null ) {
|
||||
fillShortValues(entry, reader, field);
|
||||
}
|
||||
else {
|
||||
assertSameParser( entry, parser );
|
||||
}
|
||||
}
|
||||
if( hasOption(OPTION_CACHE_BITS) ) {
|
||||
ok = true;
|
||||
|
@ -100,7 +104,7 @@ public class ShortValuesCreator extends CachedArrayCreator<ShortValues>
|
|||
if( parser == null ) {
|
||||
parser = FieldCache.DEFAULT_SHORT_PARSER;
|
||||
}
|
||||
assertSameParserAndResetCounts(vals, parser);
|
||||
setParserAndResetCounts(vals, parser);
|
||||
|
||||
Terms terms = MultiFields.getTerms(reader, field);
|
||||
int maxDoc = reader.maxDoc();
|
||||
|
|
|
@ -28,8 +28,6 @@ import org.apache.lucene.index.IndexReader;
|
|||
import org.apache.lucene.index.RandomIndexWriter;
|
||||
import org.apache.lucene.search.FieldCache;
|
||||
import org.apache.lucene.search.FieldCache.*;
|
||||
import org.apache.lucene.search.FieldCache.Parser;
|
||||
import org.apache.lucene.search.FieldCache.ShortParser;
|
||||
import org.apache.lucene.store.Directory;
|
||||
import org.apache.lucene.util.LuceneTestCase;
|
||||
import org.apache.lucene.util.OpenBitSet;
|
||||
|
@ -147,6 +145,7 @@ public class TestEntryCreators extends LuceneTestCase {
|
|||
// Check the Different CachedArray Types
|
||||
CachedArray last = null;
|
||||
CachedArray justbits = null;
|
||||
String field;
|
||||
|
||||
for( NumberTypeTester tester : typeTests ) {
|
||||
justbits = getWithReflection( cache, tester, CachedArrayCreator.OPTION_CACHE_BITS );
|
||||
|
@ -160,6 +159,41 @@ public class TestEntryCreators extends LuceneTestCase {
|
|||
assertNotNull( "Validate=true should add the Array : "+tester, justbits.getRawArray() );
|
||||
checkCachedArrayValuesAndBits( tester, last );
|
||||
}
|
||||
|
||||
// Now switch the the parser (for the same type) and expect an error
|
||||
cache.purgeAllCaches();
|
||||
int flags = CachedArrayCreator.CACHE_VALUES_AND_BITS_VALIDATE;
|
||||
field = "theRandomInt";
|
||||
last = cache.getInts(reader, field, new IntValuesCreator( field, FieldCache.DEFAULT_INT_PARSER, flags ) );
|
||||
checkCachedArrayValuesAndBits( typeTests[2], last );
|
||||
try {
|
||||
cache.getInts(reader, field, new IntValuesCreator( field, FieldCache.NUMERIC_UTILS_INT_PARSER, flags ) );
|
||||
fail( "Should fail if you ask for the same type with a different parser : " + field );
|
||||
} catch( Exception ex ) {} // expected
|
||||
|
||||
field = "theRandomLong";
|
||||
last = cache.getLongs(reader, field, new LongValuesCreator( field, FieldCache.DEFAULT_LONG_PARSER, flags ) );
|
||||
checkCachedArrayValuesAndBits( typeTests[3], last );
|
||||
try {
|
||||
cache.getLongs(reader, field, new LongValuesCreator( field, FieldCache.NUMERIC_UTILS_LONG_PARSER, flags ) );
|
||||
fail( "Should fail if you ask for the same type with a different parser : " + field );
|
||||
} catch( Exception ex ) {} // expected
|
||||
|
||||
field = "theRandomFloat";
|
||||
last = cache.getFloats(reader, field, new FloatValuesCreator( field, FieldCache.DEFAULT_FLOAT_PARSER, flags ) );
|
||||
checkCachedArrayValuesAndBits( typeTests[4], last );
|
||||
try {
|
||||
cache.getFloats(reader, field, new FloatValuesCreator( field, FieldCache.NUMERIC_UTILS_FLOAT_PARSER, flags ) );
|
||||
fail( "Should fail if you ask for the same type with a different parser : " + field );
|
||||
} catch( Exception ex ) {} // expected
|
||||
|
||||
field = "theRandomDouble";
|
||||
last = cache.getDoubles(reader, field, new DoubleValuesCreator( field, FieldCache.DEFAULT_DOUBLE_PARSER, flags ) );
|
||||
checkCachedArrayValuesAndBits( typeTests[5], last );
|
||||
try {
|
||||
cache.getDoubles(reader, field, new DoubleValuesCreator( field, FieldCache.NUMERIC_UTILS_DOUBLE_PARSER, flags ) );
|
||||
fail( "Should fail if you ask for the same type with a different parser : " + field );
|
||||
} catch( Exception ex ) {} // expected
|
||||
}
|
||||
|
||||
private void checkCachedArrayValuesAndBits( NumberTypeTester tester, CachedArray cachedVals )
|
||||
|
|
Loading…
Reference in New Issue