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:24:23 UTC

svn commit: r1390469 - in /lucene/dev/branches/branch_4x: ./ lucene/ lucene/core/ lucene/core/src/test/org/apache/lucene/index/TestBackwardsCompatibility.java lucene/core/src/test/org/apache/lucene/index/TestBackwardsCompatibility3x.java

Author: rmuir
Date: Wed Sep 26 13:24:23 2012
New Revision: 1390469

URL: http://svn.apache.org/viewvc?rev=1390469&view=rev
Log:
LUCENE-4435: add test for Constants.LUCENE_MAIN_VERSION

Modified:
    lucene/dev/branches/branch_4x/   (props changed)
    lucene/dev/branches/branch_4x/lucene/   (props changed)
    lucene/dev/branches/branch_4x/lucene/core/   (props changed)
    lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/index/TestBackwardsCompatibility.java   (contents, props changed)
    lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/index/TestBackwardsCompatibility3x.java

Modified: lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/index/TestBackwardsCompatibility.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/index/TestBackwardsCompatibility.java?rev=1390469&r1=1390468&r2=1390469&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/index/TestBackwardsCompatibility.java (original)
+++ lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/index/TestBackwardsCompatibility.java Wed Sep 26 13:24:23 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;
@@ -739,6 +741,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) {
       

Modified: lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/index/TestBackwardsCompatibility3x.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/index/TestBackwardsCompatibility3x.java?rev=1390469&r1=1390468&r2=1390469&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/index/TestBackwardsCompatibility3x.java (original)
+++ lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/index/TestBackwardsCompatibility3x.java Wed Sep 26 13:24:23 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;
@@ -64,6 +65,7 @@ import org.apache.lucene.store.RAMDirect
 import org.apache.lucene.util.Bits;
 import org.apache.lucene.util.BytesRef;
 import org.apache.lucene.util.Constants;
+import org.apache.lucene.util.StringHelper;
 import org.apache.lucene.util.LuceneTestCase.SuppressCodecs;
 import org.apache.lucene.util.LuceneTestCase;
 import org.apache.lucene.util._TestUtil;
@@ -791,6 +793,41 @@ public class TestBackwardsCompatibility3
     }
   }
   
+  /** 
+   * 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();
+        // TODO: does preflex codec actually set "3.0" here? This is safe to do I think.
+        // assertNotNull(oldVersion);
+        assertTrue("current Constants.LUCENE_MAIN_VERSION is <= an old index: did you forget to bump it?!",
+            oldVersion == null || comparator.compare(oldVersion, currentVersion) < 0);
+      }
+      r.close();
+    }
+  }
+  
   public void testNumericFields() throws Exception {
     for (String name : oldNames) {