You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by rj...@apache.org on 2014/09/11 18:26:34 UTC

svn commit: r1624330 - in /lucene/dev/branches/branch_4x: ./ lucene/ lucene/CHANGES.txt lucene/core/ lucene/core/src/java/org/apache/lucene/util/Version.java lucene/core/src/test/org/apache/lucene/index/TestBackwardsCompatibility.java

Author: rjernst
Date: Thu Sep 11 16:26:33 2014
New Revision: 1624330

URL: http://svn.apache.org/r1624330
Log:
LUCENE-5936: Add backcompat checks to verify what is tested matches known versions

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

Modified: lucene/dev/branches/branch_4x/lucene/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/CHANGES.txt?rev=1624330&r1=1624329&r2=1624330&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/CHANGES.txt (original)
+++ lucene/dev/branches/branch_4x/lucene/CHANGES.txt Thu Sep 11 16:26:33 2014
@@ -66,6 +66,11 @@ Bug Fixes
 * LUCENE-5934: Fix backwards compatibility for 4.0 indexes.
   (Ian Lea, Uwe Schindler, Robert Muir, Ryan Ernst)
 
+Tests
+
+* LUCENE-5936: Add backcompat checks to verify what is tested matches known versions
+  (Ryan Ernst)
+
 Build
 
 * LUCENE-5909: Smoke tester now has better command line parsing and

Modified: lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/util/Version.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/util/Version.java?rev=1624330&r1=1624329&r2=1624330&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/util/Version.java (original)
+++ lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/util/Version.java Thu Sep 11 16:26:33 2014
@@ -451,6 +451,15 @@ public final class Version {
     }
   }
 
+  /** Major version, the difference between stable and trunk */
+  public final int major;
+  /** Minor version, incremented within the stable branch */
+  public final int minor;
+  /** Bugfix number, incremented on release branches */
+  public final int bugfix;
+  /** Prerelease version, currently 0 (alpha), 1 (beta), or 2 (final) */
+  public final int prerelease;
+
   // stores the version pieces, with most significant pieces in high bits
   // ie:  | 1 byte | 1 byte | 1 byte |   2 bits   |
   //         major   minor    bugfix   prerelease
@@ -461,6 +470,10 @@ public final class Version {
   }
 
   private Version(int major, int minor, int bugfix, int prerelease) {
+    this.major = major;
+    this.minor = minor;
+    this.bugfix = bugfix;
+    this.prerelease = prerelease;
     if (major > 4 || major < 3) {
       throw new IllegalArgumentException("Lucene 4.x only supports 4.x and 3.x versions");
     }

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=1624330&r1=1624329&r2=1624330&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 Thu Sep 11 16:26:33 2014
@@ -21,12 +21,16 @@ import java.io.ByteArrayOutputStream;
 import java.io.File;
 import java.io.IOException;
 import java.io.PrintStream;
+import java.lang.reflect.Modifier;
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Random;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 
 import org.apache.lucene.analysis.MockAnalyzer;
 import org.apache.lucene.codecs.Codec;
@@ -277,6 +281,126 @@ public class TestBackwardsCompatibility 
     }
     oldIndexDirs = null;
   }
+
+  public void testAllVersionHaveCfsAndNocfs() {
+    // ensure all tested versions with cfs also have nocfs
+    String[] files = new String[oldNames.length];
+    System.arraycopy(oldNames, 0, files, 0, oldNames.length);
+    Arrays.sort(files);
+    String prevFile = "";
+    for (String file : files) {
+      if (prevFile.endsWith(".cfs")) {
+        String prefix = prevFile.replace(".cfs", "");
+        assertEquals("Missing .nocfs for backcompat index " + prefix, prefix + ".nocfs", file);
+      }
+    }
+  }
+
+  public void testAllVersionsTested() throws Exception {
+    Pattern constantPattern = Pattern.compile("LUCENE_(\\d+)_(\\d+)_(\\d+)(_ALPHA|_BETA)?");
+    // find the unique versions according to Version.java
+    List<String> expectedVersions = new ArrayList<>();
+    int lastPrevMinorIndex = -1;
+    Version lastPrevMajorVersion = null;
+    for (java.lang.reflect.Field field : Version.class.getDeclaredFields()) {
+      if (Modifier.isStatic(field.getModifiers()) && field.getType() == Version.class) {
+        Version v = (Version)field.get(Version.class);
+        if (v.equals(Version.LATEST)) continue;
+        if (v.major == 3) continue; // 3x codecs are tested in TestBackwardsCompatilibility3x
+
+        Matcher constant = constantPattern.matcher(field.getName());
+        if (constant.matches() == false) continue;
+
+        if (v.major == Version.LATEST.major - 1 &&
+            (lastPrevMajorVersion == null || v.onOrAfter(lastPrevMajorVersion))) {
+          lastPrevMajorVersion = v;
+          lastPrevMinorIndex = expectedVersions.size();
+        }
+
+        String major = constant.group(1);
+        String minor = constant.group(2);
+        String bugfix = constant.group(3);
+        if (bugfix.equals("0")) {
+          bugfix = "";
+        }
+        String prerelease = constant.group(4);
+        if (prerelease != null) {
+          if (prerelease.equals("_ALPHA")) {
+            prerelease = "a";
+          } else { // _BETA
+            prerelease = "b";
+          }
+        } else {
+          prerelease = "";
+        }
+        expectedVersions.add(major + minor + bugfix + prerelease + ".cfs");
+      }
+    }
+    if (Version.LATEST.minor == 0 && Version.LATEST.bugfix == 0 && Version.LATEST.prerelease == 0) {
+      // we are on trunk (latest is a first major release) so the last minor index
+      // for the previous major version is also not yet tested
+      assertNotNull(lastPrevMajorVersion);
+      expectedVersions.remove(lastPrevMinorIndex);
+    }
+    Collections.sort(expectedVersions);
+
+    // find what versions we are testing
+    List<String> testedVersions = new ArrayList<>();
+    for (String testedVersion : oldNames) {
+      if (testedVersion.endsWith(".cfs") == false) continue;
+      testedVersions.add(testedVersion);
+    }
+    Collections.sort(testedVersions);
+
+
+    int i = 0;
+    int j = 0;
+    List<String> missingFiles = new ArrayList<>();
+    List<String> extraFiles = new ArrayList<>();
+    while (i < expectedVersions.size() && j < testedVersions.size()) {
+      String expectedVersion = expectedVersions.get(i);
+      String testedVersion = testedVersions.get(j);
+      int compare = expectedVersion.compareTo(testedVersion);
+      if (compare == 0) { // equal, we can move on
+        ++i;
+        ++j;
+      } else if (compare < 0) { // didn't find test for version constant
+        missingFiles.add(expectedVersion);
+        ++i;
+      } else { // extra test file
+        extraFiles.add(testedVersion);
+        ++j;
+      }
+    }
+    while (i < expectedVersions.size()) {
+      missingFiles.add(expectedVersions.get(i));
+      ++i;
+    }
+    while (j < testedVersions.size()) {
+      missingFiles.add(testedVersions.get(j));
+      ++j;
+    }
+
+    if (missingFiles.isEmpty() && extraFiles.isEmpty()) {
+      // success
+      return;
+    }
+
+    StringBuffer msg = new StringBuffer();
+    if (missingFiles.isEmpty() == false) {
+      msg.append("Missing backcompat test files:\n");
+      for (String missingFile : missingFiles) {
+        msg.append("  " + missingFile + "\n");
+      }
+    }
+    if (extraFiles.isEmpty() == false) {
+      msg.append("Extra backcompat test files:\n");
+      for (String extraFile : extraFiles) {
+        msg.append("  " + extraFile + "\n");
+      }
+    }
+    fail(msg.toString());
+  }
   
   /** This test checks that *only* IndexFormatTooOldExceptions are thrown when you open and operate on too old indexes! */
   public void testUnsupportedOldIndexes() throws Exception {