You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by us...@apache.org on 2014/03/18 15:41:17 UTC
svn commit: r1578930 - in /lucene/dev/trunk/lucene/core/src:
java/org/apache/lucene/util/Constants.java
test/org/apache/lucene/index/TestCheckIndex.java
test/org/apache/lucene/util/TestConstants.java
test/org/apache/lucene/util/TestVersion.java
Author: uschindler
Date: Tue Mar 18 14:41:16 2014
New Revision: 1578930
URL: http://svn.apache.org/r1578930
Log:
LUCENE-5537: Fix version checks in TestCheckIndex -> TestConstants
Added:
lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/util/TestConstants.java (with props)
Modified:
lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/util/Constants.java
lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/index/TestCheckIndex.java
lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/util/TestVersion.java
Modified: lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/util/Constants.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/util/Constants.java?rev=1578930&r1=1578929&r2=1578930&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/util/Constants.java (original)
+++ lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/util/Constants.java Tue Mar 18 14:41:16 2014
@@ -99,11 +99,14 @@ public final class Constants {
return s.toString();
}
- // NOTE: we track per-segment version as a String with the "X.Y" format, e.g.
- // "4.0", "3.1", "3.0". Therefore when we change this constant, we should keep
- // the format.
+ // We should never change index format with minor versions, so it should always be x.y or x.y.0.z for alpha/beta versions!
/**
* This is the internal Lucene version, recorded into each segment.
+ * NOTE: we track per-segment version as a String with the {@code "X.Y"} format
+ * (no minor version), e.g. {@code "4.0", "3.1", "3.0"}.
+ * <p>Alpha and Beta versions will have numbers like {@code "X.Y.0.Z"},
+ * anything else is not allowed. This is done to prevent people from
+ * using indexes created with ALPHA/BETA versions with the released version.
*/
public static final String LUCENE_MAIN_VERSION = ident("5.0");
@@ -115,15 +118,20 @@ public final class Constants {
Package pkg = LucenePackage.get();
String v = (pkg == null) ? null : pkg.getImplementationVersion();
if (v == null) {
- String parts[] = LUCENE_MAIN_VERSION.split("\\.");
- if (parts.length == 4) {
- // alpha/beta
- assert parts[2].equals("0");
- v = parts[0] + "." + parts[1] + "-SNAPSHOT";
- } else {
- v = LUCENE_MAIN_VERSION + "-SNAPSHOT";
- }
+ v = mainVersionWithoutAlphaBeta() + "-SNAPSHOT";
}
LUCENE_VERSION = ident(v);
}
+
+ /**
+ * Returns a LUCENE_MAIN_VERSION without any ALPHA/BETA qualifier
+ * Used by test only!
+ */
+ static String mainVersionWithoutAlphaBeta() {
+ final String parts[] = LUCENE_MAIN_VERSION.split("\\.");
+ if (parts.length == 4 && "0".equals(parts[2])) {
+ return parts[0] + "." + parts[1];
+ }
+ return LUCENE_MAIN_VERSION;
+ }
}
Modified: lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/index/TestCheckIndex.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/index/TestCheckIndex.java?rev=1578930&r1=1578929&r2=1578930&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/index/TestCheckIndex.java (original)
+++ lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/index/TestCheckIndex.java Tue Mar 18 14:41:16 2014
@@ -32,7 +32,6 @@ import org.apache.lucene.document.Docume
import org.apache.lucene.document.Field;
import org.apache.lucene.document.FieldType;
import org.apache.lucene.document.TextField;
-import org.apache.lucene.util.Constants;
public class TestCheckIndex extends LuceneTestCase {
@@ -114,26 +113,4 @@ public class TestCheckIndex extends Luce
iw.close();
dir.close(); // checkindex
}
-
- public void testLuceneConstantVersion() throws IOException {
- // common-build.xml sets lucene.version
- String version = System.getProperty("lucene.version");
- assertNotNull( "null version", version);
- // remove anything after a "-" from the version string:
- version = version.replaceAll("-.*$", "");
- final String constantVersion;
- String parts[] = Constants.LUCENE_MAIN_VERSION.split("\\.");
- if (parts.length == 4) {
- // alpha/beta version: pull the real portion
- assert parts[2].equals("0");
- constantVersion = parts[0] + "." + parts[1];
- } else {
- // normal version
- constantVersion = Constants.LUCENE_MAIN_VERSION;
- }
- assertTrue("Invalid version: "+version,
- version.equals(constantVersion));
- assertTrue(Constants.LUCENE_VERSION + " should start with: "+version,
- Constants.LUCENE_VERSION.startsWith(version));
- }
}
Added: lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/util/TestConstants.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/util/TestConstants.java?rev=1578930&view=auto
==============================================================================
--- lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/util/TestConstants.java (added)
+++ lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/util/TestConstants.java Tue Mar 18 14:41:16 2014
@@ -0,0 +1,48 @@
+package org.apache.lucene.util;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+public class TestConstants extends LuceneTestCase {
+
+ private String getVersionDetails() {
+ return " (LUCENE_MAIN_VERSION=" + Constants.LUCENE_MAIN_VERSION +
+ ", LUCENE_MAIN_VERSION(without alpha/beta)=" + Constants.mainVersionWithoutAlphaBeta() +
+ ", LUCENE_VERSION=" + Constants.LUCENE_VERSION + ")";
+ }
+
+ public void testLuceneMainVersionConstant() {
+ assertTrue("LUCENE_MAIN_VERSION does not follow pattern: 'x.y' (stable release) or 'x.y.0.z' (alpha/beta version)" + getVersionDetails(),
+ Constants.LUCENE_MAIN_VERSION.matches("\\d+\\.\\d+(|\\.0\\.\\d+)"));
+ assertTrue("LUCENE_VERSION does not start with LUCENE_MAIN_VERSION (without alpha/beta marker)" + getVersionDetails(),
+ Constants.LUCENE_VERSION.startsWith(Constants.mainVersionWithoutAlphaBeta()));
+ }
+
+ public void testBuildSetup() {
+ // common-build.xml sets lucene.version, if not, we skip this test!
+ String version = System.getProperty("lucene.version");
+ assumeTrue("Null lucene.version test property. You should run the tests with the official Lucene build file",
+ version != null);
+
+ // remove anything after a "-" from the version string:
+ version = version.replaceAll("-.*$", "");
+ String versionConstant = Constants.LUCENE_VERSION.replaceAll("-.*$", "");
+ assertTrue("LUCENE_VERSION should share the same prefix with lucene.version test property ('" + version + "')." + getVersionDetails(),
+ versionConstant.startsWith(version) || version.startsWith(versionConstant));
+ }
+
+}
Modified: lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/util/TestVersion.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/util/TestVersion.java?rev=1578930&r1=1578929&r2=1578930&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/util/TestVersion.java (original)
+++ lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/util/TestVersion.java Tue Mar 18 14:41:16 2014
@@ -48,4 +48,14 @@ public class TestVersion extends LuceneT
}
}
}
+
+ public void testAgainstMainVersionConstant() {
+ final Version values[] = Version.values();
+ assertTrue(values.length >= 2);
+ final String mainVersionWithoutAlphaBeta = Constants.mainVersionWithoutAlphaBeta();
+ final Version mainVersionParsed = Version.parseLeniently(mainVersionWithoutAlphaBeta);
+ assertSame("Constant one before last must be the same as the parsed LUCENE_MAIN_VERSION (without alpha/beta) constant: " +
+ mainVersionWithoutAlphaBeta,
+ mainVersionParsed, values[values.length - 2]);
+ }
}