public virtual void TestOldVersions() { // first create a little index with the current code and get the version Directory currentDir = NewDirectory(); RandomIndexWriter riw = new RandomIndexWriter(Random(), currentDir); riw.AddDocument(new Document()); riw.Dispose(); DirectoryReader ir = DirectoryReader.Open(currentDir); SegmentReader air = (SegmentReader)ir.Leaves()[0].Reader(); string currentVersion = air.SegmentInfo.Info.Version; Assert.IsNotNull(currentVersion); // only 3.0 segments can have a null version ir.Dispose(); currentDir.Dispose(); IComparer <string> comparator = StringHelper.VersionComparator; // now check all the old indexes, their version should be < the current version foreach (string name in OldNames) { Directory dir = OldIndexDirs[name]; DirectoryReader r = DirectoryReader.Open(dir); foreach (AtomicReaderContext context in r.Leaves()) { air = (SegmentReader)context.Reader(); string oldVersion = air.SegmentInfo.Info.Version; // TODO: does preflex codec actually set "3.0" here? this is safe to do I think. // Assert.IsNotNull(oldVersion); Assert.IsTrue(oldVersion == null || comparator.Compare(oldVersion, currentVersion) < 0, "current Constants.LUCENE_MAIN_VERSION is <= an old index: did you forget to bump it?!"); } r.Dispose(); } }