mirror of https://github.com/apache/lucene.git
LUCENE-5537: Fix version checks in TestCheckIndex -> TestConstants
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1578930 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
1eb6447bcf
commit
040adbbb00
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,7 +32,6 @@ import org.apache.lucene.document.Document;
|
|||
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 LuceneTestCase {
|
|||
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));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
||||
}
|
|
@ -48,4 +48,14 @@ public class TestVersion extends LuceneTestCase {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
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]);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue