You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by rm...@apache.org on 2012/09/26 15:16:12 UTC
svn commit: r1390459 -
/lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/index/TestBackwardsCompatibility.java
Author: rmuir
Date: Wed Sep 26 13:16:12 2012
New Revision: 1390459
URL: http://svn.apache.org/viewvc?rev=1390459&view=rev
Log:
LUCENE-4435: add test for Constants.LUCENE_MAIN_VERSION
Modified:
lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/index/TestBackwardsCompatibility.java
Modified: lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/index/TestBackwardsCompatibility.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/index/TestBackwardsCompatibility.java?rev=1390459&r1=1390458&r2=1390459&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/index/TestBackwardsCompatibility.java (original)
+++ lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/index/TestBackwardsCompatibility.java Wed Sep 26 13:16:12 2012
@@ -23,6 +23,7 @@ import java.io.IOException;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -63,6 +64,7 @@ import org.apache.lucene.util.Bits;
import org.apache.lucene.util.BytesRef;
import org.apache.lucene.util.Constants;
import org.apache.lucene.util.LuceneTestCase;
+import org.apache.lucene.util.StringHelper;
import org.apache.lucene.util._TestUtil;
import org.apache.lucene.util.LuceneTestCase.SuppressCodecs;
import org.junit.AfterClass;
@@ -747,6 +749,40 @@ public class TestBackwardsCompatibility
}
}
+ /**
+ * Test that we didn't forget to bump the current Constants.LUCENE_MAIN_VERSION.
+ * This is important so that we can determine which version of lucene wrote the segment.
+ */
+ public void testOldVersions() throws Exception {
+ // 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.close();
+ DirectoryReader ir = DirectoryReader.open(currentDir);
+ SegmentReader air = (SegmentReader)ir.leaves().get(0).reader();
+ String currentVersion = air.getSegmentInfo().info.getVersion();
+ assertNotNull(currentVersion); // only 3.0 segments can have a null version
+ ir.close();
+ currentDir.close();
+
+ Comparator<String> comparator = StringHelper.getVersionComparator();
+
+ // now check all the old indexes, their version should be < the current version
+ for (String name : oldNames) {
+ Directory dir = oldIndexDirs.get(name);
+ DirectoryReader r = DirectoryReader.open(dir);
+ for (AtomicReaderContext context : r.leaves()) {
+ air = (SegmentReader) context.reader();
+ String oldVersion = air.getSegmentInfo().info.getVersion();
+ assertNotNull(oldVersion); // only 3.0 segments can have a null version
+ assertTrue("current Constants.LUCENE_MAIN_VERSION is <= an old index: did you forget to bump it?!",
+ comparator.compare(oldVersion, currentVersion) < 0);
+ }
+ r.close();
+ }
+ }
+
public void testNumericFields() throws Exception {
for (String name : oldNames) {