fix nocommits

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/branches/lucene4547@1441644 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael McCandless 2013-02-01 21:38:01 +00:00
parent e5f22c7bef
commit 481139b490
2 changed files with 115 additions and 21 deletions

View File

@ -163,7 +163,14 @@ public class FieldInfos implements Iterable<FieldInfo> {
private final Map<Integer,String> numberToName; private final Map<Integer,String> numberToName;
private final Map<String,Integer> nameToNumber; private final Map<String,Integer> nameToNumber;
// We use this to enforce that a given field never
// changes DV type, even across segments / IndexWriter
// sessions:
private final Map<String,DocValuesType> docValuesType; private final Map<String,DocValuesType> docValuesType;
// TODO: we should similarly catch an attempt to turn
// norms back on after they were already ommitted; today
// we silently discard the norm but this is badly trappy
private int lowestUnassignedFieldNumber = -1; private int lowestUnassignedFieldNumber = -1;
FieldNumbers() { FieldNumbers() {
@ -209,26 +216,8 @@ public class FieldInfos implements Iterable<FieldInfo> {
return fieldNumber.intValue(); return fieldNumber.intValue();
} }
/** // nocommit: do we need better tests for attempt to
* Sets the given field number and name if not yet set. // change doc value type across segments...
*/
// nocommit: why is docvalues involved with global field numbers?
// nocommit: and is it even tested...
/*
synchronized void setIfNotSet(int fieldNumber, String fieldName, DocValuesType dvType) {
final Integer boxedFieldNumber = Integer.valueOf(fieldNumber);
if (!numberToName.containsKey(boxedFieldNumber)
&& !nameToNumber.containsKey(fieldName)
&& !docValuesType.containsKey(dvType)) {
numberToName.put(boxedFieldNumber, fieldName);
nameToNumber.put(fieldName, boxedFieldNumber);
docValuesType.put(fieldName, dvType);
} else {
// nocommit should this be a real check?
assert containsConsistent(boxedFieldNumber, fieldName, dvType);
}
}
*/
// used by assert // used by assert
synchronized boolean containsConsistent(Integer number, String name, DocValuesType dvType) { synchronized boolean containsConsistent(Integer number, String name, DocValuesType dvType) {

View File

@ -610,11 +610,116 @@ public class TestDocValuesIndexing extends LuceneTestCase {
writer.close(); writer.close();
conf.setOpenMode(IndexWriterConfig.OpenMode.CREATE); conf.setOpenMode(IndexWriterConfig.OpenMode.CREATE);
writer = new IndexWriter(dir, conf); writer = new IndexWriter(dir, conf);
writer.deleteAll();
doc = new Document(); doc = new Document();
doc.add(new SortedDocValuesField("dv", new BytesRef("foo"))); doc.add(new SortedDocValuesField("dv", new BytesRef("foo")));
writer.addDocument(doc); writer.addDocument(doc);
writer.close(); writer.close();
dir.close(); dir.close();
} }
public void testTypeChangeViaAddIndexes() throws Exception {
Directory dir = newDirectory();
IndexWriterConfig conf = newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random()));
IndexWriter writer = new IndexWriter(dir, conf);
Document doc = new Document();
doc.add(new NumericDocValuesField("dv", 0L));
writer.addDocument(doc);
writer.close();
Directory dir2 = newDirectory();
writer = new IndexWriter(dir2, conf);
doc = new Document();
doc.add(new SortedDocValuesField("dv", new BytesRef("foo")));
writer.addDocument(doc);
try {
writer.addIndexes(dir);
fail("did not hit exception");
} catch (IllegalArgumentException iae) {
// expected
}
writer.close();
dir.close();
dir2.close();
}
public void testTypeChangeViaAddIndexesIR() throws Exception {
Directory dir = newDirectory();
IndexWriterConfig conf = newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random()));
IndexWriter writer = new IndexWriter(dir, conf);
Document doc = new Document();
doc.add(new NumericDocValuesField("dv", 0L));
writer.addDocument(doc);
writer.close();
Directory dir2 = newDirectory();
writer = new IndexWriter(dir2, conf);
doc = new Document();
doc.add(new SortedDocValuesField("dv", new BytesRef("foo")));
writer.addDocument(doc);
IndexReader[] readers = new IndexReader[] {DirectoryReader.open(dir)};
try {
writer.addIndexes(readers);
fail("did not hit exception");
} catch (IllegalArgumentException iae) {
// expected
}
readers[0].close();
writer.close();
dir.close();
dir2.close();
}
public void testTypeChangeViaAddIndexes2() throws Exception {
Directory dir = newDirectory();
IndexWriterConfig conf = newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random()));
IndexWriter writer = new IndexWriter(dir, conf);
Document doc = new Document();
doc.add(new NumericDocValuesField("dv", 0L));
writer.addDocument(doc);
writer.close();
Directory dir2 = newDirectory();
writer = new IndexWriter(dir2, conf);
writer.addIndexes(dir);
doc = new Document();
doc.add(new SortedDocValuesField("dv", new BytesRef("foo")));
try {
writer.addDocument(doc);
fail("did not hit exception");
} catch (IllegalArgumentException iae) {
// expected
}
writer.close();
dir2.close();
dir.close();
}
public void testTypeChangeViaAddIndexesIR2() throws Exception {
Directory dir = newDirectory();
IndexWriterConfig conf = newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random()));
IndexWriter writer = new IndexWriter(dir, conf);
Document doc = new Document();
doc.add(new NumericDocValuesField("dv", 0L));
writer.addDocument(doc);
writer.close();
Directory dir2 = newDirectory();
writer = new IndexWriter(dir2, conf);
IndexReader[] readers = new IndexReader[] {DirectoryReader.open(dir)};
writer.addIndexes(readers);
readers[0].close();
doc = new Document();
doc.add(new SortedDocValuesField("dv", new BytesRef("foo")));
try {
writer.addDocument(doc);
fail("did not hit exception");
} catch (IllegalArgumentException iae) {
// expected
}
writer.close();
dir2.close();
dir.close();
}
} }