public virtual void TestUpdateOldSegments()
{
OLD_FORMAT_IMPERSONATION_IS_ACTIVE = true;
Codec[] oldCodecs = new Codec[] { new Lucene40RWCodec(OLD_FORMAT_IMPERSONATION_IS_ACTIVE), new Lucene41RWCodec(OLD_FORMAT_IMPERSONATION_IS_ACTIVE), new Lucene42RWCodec(OLD_FORMAT_IMPERSONATION_IS_ACTIVE), new Lucene45RWCodec(OLD_FORMAT_IMPERSONATION_IS_ACTIVE) };
Directory dir = NewDirectory();
bool oldValue = OLD_FORMAT_IMPERSONATION_IS_ACTIVE;
// create a segment with an old Codec
IndexWriterConfig conf = NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random()));
conf.SetCodec(oldCodecs[Random().Next(oldCodecs.Length)]);
IndexWriter writer = new IndexWriter(dir, conf);
Document doc = new Document();
doc.Add(new StringField("id", "doc", Store.NO));
doc.Add(new NumericDocValuesField("f", 5));
writer.AddDocument(doc);
writer.Dispose();
conf = NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random()));
writer = new IndexWriter(dir, conf);
writer.UpdateNumericDocValue(new Term("id", "doc"), "f", 4L);
OLD_FORMAT_IMPERSONATION_IS_ACTIVE = false;
try
{
writer.Dispose();
Assert.Fail("should not have succeeded to update a segment written with an old Codec");
}
catch (System.NotSupportedException e)
{
writer.Rollback();
}
finally
{
OLD_FORMAT_IMPERSONATION_IS_ACTIVE = oldValue;
}
dir.Dispose();
}