Remove JavaVersion, use builtin Runtime.Version to deal with runtime versions (#3006)
Signed-off-by: Andriy Redko <andriy.redko@aiven.io>
This commit is contained in:
parent
6915df94c3
commit
3b7e654757
|
@ -36,6 +36,7 @@ import org.opensearch.common.SuppressForbidden;
|
|||
import org.opensearch.common.io.PathUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.Runtime.Version;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URL;
|
||||
|
@ -250,7 +251,9 @@ public class JarHell {
|
|||
}
|
||||
|
||||
public static void checkVersionFormat(String targetVersion) {
|
||||
if (!JavaVersion.isValid(targetVersion)) {
|
||||
try {
|
||||
Version.parse(targetVersion);
|
||||
} catch (final IllegalArgumentException ex) {
|
||||
throw new IllegalStateException(
|
||||
String.format(
|
||||
Locale.ROOT,
|
||||
|
@ -267,16 +270,10 @@ public class JarHell {
|
|||
* required by {@code resource} is compatible with the current installation.
|
||||
*/
|
||||
public static void checkJavaVersion(String resource, String targetVersion) {
|
||||
JavaVersion version = JavaVersion.parse(targetVersion);
|
||||
if (JavaVersion.current().compareTo(version) < 0) {
|
||||
Version version = Version.parse(targetVersion);
|
||||
if (Runtime.version().compareTo(version) < 0) {
|
||||
throw new IllegalStateException(
|
||||
String.format(
|
||||
Locale.ROOT,
|
||||
"%s requires Java %s:, your system: %s",
|
||||
resource,
|
||||
targetVersion,
|
||||
JavaVersion.current().toString()
|
||||
)
|
||||
String.format(Locale.ROOT, "%s requires Java %s:, your system: %s", resource, targetVersion, Runtime.version().toString())
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,146 +0,0 @@
|
|||
/*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* The OpenSearch Contributors require contributions made to
|
||||
* this file be licensed under the Apache-2.0 license or a
|
||||
* compatible open source license.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Licensed to Elasticsearch under one or more contributor
|
||||
* license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright
|
||||
* ownership. Elasticsearch 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Modifications Copyright OpenSearch Contributors. See
|
||||
* GitHub history for details.
|
||||
*/
|
||||
|
||||
package org.opensearch.bootstrap;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class JavaVersion implements Comparable<JavaVersion> {
|
||||
|
||||
private final List<Integer> version;
|
||||
private final String prePart;
|
||||
|
||||
public List<Integer> getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
private JavaVersion(List<Integer> version, String prePart) {
|
||||
this.prePart = prePart;
|
||||
if (version.size() >= 2 && version.get(0) == 1 && version.get(1) == 8) {
|
||||
// for Java 8 there is ambiguity since both 1.8 and 8 are supported,
|
||||
// so we rewrite the former to the latter
|
||||
version = new ArrayList<>(version.subList(1, version.size()));
|
||||
}
|
||||
this.version = Collections.unmodifiableList(version);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses the Java version as it can be retrieved as the value of java.version or
|
||||
* java.specification.version according to JEP 223.
|
||||
*
|
||||
* @param value The version String
|
||||
*/
|
||||
public static JavaVersion parse(String value) {
|
||||
Objects.requireNonNull(value);
|
||||
String prePart = null;
|
||||
if (!isValid(value)) {
|
||||
throw new IllegalArgumentException("Java version string [" + value + "] could not be parsed.");
|
||||
}
|
||||
List<Integer> version = new ArrayList<>();
|
||||
String[] parts = value.split("-");
|
||||
String[] numericComponents;
|
||||
if (parts.length == 1) {
|
||||
numericComponents = value.split("\\.");
|
||||
} else if (parts.length == 2) {
|
||||
numericComponents = parts[0].split("\\.");
|
||||
prePart = parts[1];
|
||||
} else {
|
||||
throw new IllegalArgumentException("Java version string [" + value + "] could not be parsed.");
|
||||
}
|
||||
|
||||
for (String component : numericComponents) {
|
||||
version.add(Integer.valueOf(component));
|
||||
}
|
||||
return new JavaVersion(version, prePart);
|
||||
}
|
||||
|
||||
public static boolean isValid(String value) {
|
||||
return value.matches("^0*[0-9]+(\\.[0-9]+)*(-[a-zA-Z0-9]+)?$");
|
||||
}
|
||||
|
||||
private static final JavaVersion CURRENT = parse(System.getProperty("java.specification.version"));
|
||||
|
||||
public static JavaVersion current() {
|
||||
return CURRENT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(JavaVersion o) {
|
||||
int len = Math.max(version.size(), o.version.size());
|
||||
for (int i = 0; i < len; i++) {
|
||||
int d = (i < version.size() ? version.get(i) : 0);
|
||||
int s = (i < o.version.size() ? o.version.get(i) : 0);
|
||||
if (s < d) return 1;
|
||||
if (s > d) return -1;
|
||||
}
|
||||
if (prePart != null && o.prePart == null) {
|
||||
return -1;
|
||||
} else if (prePart == null && o.prePart != null) {
|
||||
return 1;
|
||||
} else if (prePart != null && o.prePart != null) {
|
||||
return comparePrePart(prePart, o.prePart);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
private int comparePrePart(String prePart, String otherPrePart) {
|
||||
if (prePart.matches("\\d+")) {
|
||||
return otherPrePart.matches("\\d+") ? (new BigInteger(prePart)).compareTo(new BigInteger(otherPrePart)) : -1;
|
||||
} else {
|
||||
return otherPrePart.matches("\\d+") ? 1 : prePart.compareTo(otherPrePart);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (o == null || o.getClass() != getClass()) {
|
||||
return false;
|
||||
}
|
||||
return compareTo((JavaVersion) o) == 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return version.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
final String versionString = version.stream().map(v -> Integer.toString(v)).collect(Collectors.joining("."));
|
||||
return prePart != null ? versionString + "-" + prePart : versionString;
|
||||
}
|
||||
}
|
|
@ -37,6 +37,7 @@ import org.opensearch.common.io.PathUtils;
|
|||
import org.opensearch.test.OpenSearchTestCase;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.Runtime.Version;
|
||||
import java.net.URL;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
@ -156,12 +157,12 @@ public class JarHellTests extends OpenSearchTestCase {
|
|||
|
||||
public void testRequiredJDKVersionTooOld() throws Exception {
|
||||
Path dir = createTempDir();
|
||||
List<Integer> current = JavaVersion.current().getVersion();
|
||||
List<Integer> current = Runtime.version().version();
|
||||
List<Integer> target = new ArrayList<>(current.size());
|
||||
for (int i = 0; i < current.size(); i++) {
|
||||
target.add(current.get(i) + 1);
|
||||
}
|
||||
JavaVersion targetVersion = JavaVersion.parse(Strings.collectionToDelimitedString(target, "."));
|
||||
Version targetVersion = Version.parse(Strings.collectionToDelimitedString(target, "."));
|
||||
|
||||
Manifest manifest = new Manifest();
|
||||
Attributes attributes = manifest.getMainAttributes();
|
||||
|
@ -173,7 +174,7 @@ public class JarHellTests extends OpenSearchTestCase {
|
|||
fail("did not get expected exception");
|
||||
} catch (IllegalStateException e) {
|
||||
assertTrue(e.getMessage().contains("requires Java " + targetVersion.toString()));
|
||||
assertTrue(e.getMessage().contains("your system: " + JavaVersion.current().toString()));
|
||||
assertTrue(e.getMessage().contains("your system: " + Runtime.version().toString()));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -209,7 +210,7 @@ public class JarHellTests extends OpenSearchTestCase {
|
|||
}
|
||||
|
||||
public void testValidVersions() {
|
||||
String[] versions = new String[] { "1.7", "1.7.0", "0.1.7", "1.7.0.80" };
|
||||
String[] versions = new String[] { "12-ea", "13.0.2.3-ea", "14-something", "11.0.2-21002", "11.0.14.1+1", "17.0.2+8" };
|
||||
for (String version : versions) {
|
||||
try {
|
||||
JarHell.checkVersionFormat(version);
|
||||
|
@ -220,7 +221,7 @@ public class JarHellTests extends OpenSearchTestCase {
|
|||
}
|
||||
|
||||
public void testInvalidVersions() {
|
||||
String[] versions = new String[] { "", "1.7.0_80", "1.7." };
|
||||
String[] versions = new String[] { "", "1.7.0_80", "1.7.", "11.2+something-else" };
|
||||
for (String version : versions) {
|
||||
try {
|
||||
JarHell.checkVersionFormat(version);
|
||||
|
|
|
@ -33,15 +33,16 @@
|
|||
package org.opensearch.core.internal.net;
|
||||
|
||||
import org.apache.lucene.util.Constants;
|
||||
import org.opensearch.bootstrap.JavaVersion;
|
||||
import org.opensearch.core.internal.io.IOUtils;
|
||||
import org.opensearch.test.OpenSearchTestCase;
|
||||
|
||||
import java.lang.Runtime.Version;
|
||||
|
||||
public class NetUtilsTests extends OpenSearchTestCase {
|
||||
|
||||
public void testExtendedSocketOptions() {
|
||||
assumeTrue("JDK possibly not supported", Constants.JVM_NAME.contains("HotSpot") || Constants.JVM_NAME.contains("OpenJDK"));
|
||||
assumeTrue("JDK version not supported", JavaVersion.current().compareTo(JavaVersion.parse("11")) >= 0);
|
||||
assumeTrue("JDK version not supported", Runtime.version().compareTo(Version.parse("11")) >= 0);
|
||||
assumeTrue("Platform possibly not supported", IOUtils.LINUX || IOUtils.MAC_OS_X);
|
||||
assertNotNull(NetUtils.getTcpKeepIdleSocketOptionOrNull());
|
||||
assertNotNull(NetUtils.getTcpKeepIntervalSocketOptionOrNull());
|
||||
|
|
|
@ -32,8 +32,6 @@
|
|||
|
||||
package org.opensearch.common.ssl;
|
||||
|
||||
import org.opensearch.bootstrap.JavaVersion;
|
||||
|
||||
import javax.crypto.Cipher;
|
||||
import javax.net.ssl.KeyManagerFactory;
|
||||
import javax.net.ssl.TrustManagerFactory;
|
||||
|
@ -361,7 +359,6 @@ public abstract class SslConfigurationLoader {
|
|||
|
||||
private static List<String> loadDefaultCiphers() {
|
||||
final boolean has256BitAES = has256BitAES();
|
||||
final boolean useGCM = JavaVersion.current().compareTo(JavaVersion.parse("11")) >= 0;
|
||||
final boolean tlsV13Supported = DEFAULT_PROTOCOLS.contains("TLSv1.3");
|
||||
List<String> ciphers = new ArrayList<>();
|
||||
if (tlsV13Supported) { // TLSv1.3 cipher has PFS, AEAD, hardware support
|
||||
|
@ -370,19 +367,18 @@ public abstract class SslConfigurationLoader {
|
|||
}
|
||||
ciphers.add("TLS_AES_128_GCM_SHA256");
|
||||
}
|
||||
if (useGCM) { // PFS, AEAD, hardware support
|
||||
if (has256BitAES) {
|
||||
ciphers.addAll(
|
||||
Arrays.asList(
|
||||
"TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384",
|
||||
"TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256",
|
||||
"TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384",
|
||||
"TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256"
|
||||
)
|
||||
);
|
||||
} else {
|
||||
ciphers.addAll(Arrays.asList("TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256", "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256"));
|
||||
}
|
||||
// use GCM: PFS, AEAD, hardware support
|
||||
if (has256BitAES) {
|
||||
ciphers.addAll(
|
||||
Arrays.asList(
|
||||
"TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384",
|
||||
"TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256",
|
||||
"TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384",
|
||||
"TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256"
|
||||
)
|
||||
);
|
||||
} else {
|
||||
ciphers.addAll(Arrays.asList("TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256", "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256"));
|
||||
}
|
||||
|
||||
// PFS, hardware support
|
||||
|
@ -410,13 +406,11 @@ public abstract class SslConfigurationLoader {
|
|||
);
|
||||
}
|
||||
|
||||
// AEAD, hardware support
|
||||
if (useGCM) {
|
||||
if (has256BitAES) {
|
||||
ciphers.addAll(Arrays.asList("TLS_RSA_WITH_AES_256_GCM_SHA384", "TLS_RSA_WITH_AES_128_GCM_SHA256"));
|
||||
} else {
|
||||
ciphers.add("TLS_RSA_WITH_AES_128_GCM_SHA256");
|
||||
}
|
||||
// use GCM: AEAD, hardware support
|
||||
if (has256BitAES) {
|
||||
ciphers.addAll(Arrays.asList("TLS_RSA_WITH_AES_256_GCM_SHA384", "TLS_RSA_WITH_AES_128_GCM_SHA256"));
|
||||
} else {
|
||||
ciphers.add("TLS_RSA_WITH_AES_128_GCM_SHA256");
|
||||
}
|
||||
|
||||
// hardware support
|
||||
|
|
|
@ -32,7 +32,6 @@
|
|||
|
||||
package org.opensearch.ingest.common;
|
||||
|
||||
import org.opensearch.bootstrap.JavaVersion;
|
||||
import org.opensearch.common.time.DateFormatter;
|
||||
import org.opensearch.common.time.DateUtils;
|
||||
import org.opensearch.test.OpenSearchTestCase;
|
||||
|
@ -96,10 +95,6 @@ public class DateFormatTests extends OpenSearchTestCase {
|
|||
}
|
||||
|
||||
public void testParseWeekBased() {
|
||||
assumeFalse(
|
||||
"won't work in jdk8 " + "because SPI mechanism is not looking at classpath - needs ISOCalendarDataProvider in jre's ext/libs",
|
||||
JavaVersion.current().equals(JavaVersion.parse("8"))
|
||||
);
|
||||
String format = randomFrom("YYYY-ww");
|
||||
ZoneId timezone = DateUtils.of("Europe/Amsterdam");
|
||||
Function<String, ZonedDateTime> javaFunction = DateFormat.Java.getFunction(format, timezone, Locale.ROOT);
|
||||
|
@ -108,10 +103,6 @@ public class DateFormatTests extends OpenSearchTestCase {
|
|||
}
|
||||
|
||||
public void testParseWeekBasedWithLocale() {
|
||||
assumeFalse(
|
||||
"won't work in jdk8 " + "because SPI mechanism is not looking at classpath - needs ISOCalendarDataProvider in jre's ext/libs",
|
||||
JavaVersion.current().equals(JavaVersion.parse("8"))
|
||||
);
|
||||
String format = randomFrom("YYYY-ww");
|
||||
ZoneId timezone = DateUtils.of("Europe/Amsterdam");
|
||||
Function<String, ZonedDateTime> javaFunction = DateFormat.Java.getFunction(format, timezone, Locale.US);
|
||||
|
|
|
@ -33,7 +33,6 @@
|
|||
package org.opensearch.painless;
|
||||
|
||||
import org.apache.lucene.util.Constants;
|
||||
import org.opensearch.bootstrap.JavaVersion;
|
||||
import org.hamcrest.Matcher;
|
||||
|
||||
import java.lang.invoke.MethodHandle;
|
||||
|
@ -55,11 +54,7 @@ public class ArrayTests extends ArrayLikeObjectTestCase {
|
|||
|
||||
@Override
|
||||
protected Matcher<String> outOfBoundsExceptionMessageMatcher(int index, int size) {
|
||||
if (JavaVersion.current().compareTo(JavaVersion.parse("11")) < 0) {
|
||||
return equalTo(Integer.toString(index));
|
||||
} else {
|
||||
return equalTo("Index " + Integer.toString(index) + " out of bounds for length " + Integer.toString(size));
|
||||
}
|
||||
return equalTo("Index " + Integer.toString(index) + " out of bounds for length " + Integer.toString(size));
|
||||
}
|
||||
|
||||
public void testArrayLengthHelper() throws Throwable {
|
||||
|
|
|
@ -34,7 +34,6 @@ package org.opensearch.transport.netty4;
|
|||
|
||||
import org.opensearch.Version;
|
||||
import org.opensearch.action.ActionListener;
|
||||
import org.opensearch.bootstrap.JavaVersion;
|
||||
import org.opensearch.cluster.node.DiscoveryNode;
|
||||
import org.opensearch.common.io.stream.NamedWriteableRegistry;
|
||||
import org.opensearch.common.network.NetworkService;
|
||||
|
@ -121,10 +120,7 @@ public class SimpleNetty4TransportTests extends AbstractSimpleTransportTestCase
|
|||
}
|
||||
|
||||
public void testDefaultKeepAliveSettings() throws IOException {
|
||||
assumeTrue(
|
||||
"setting default keepalive options not supported on this platform",
|
||||
(IOUtils.LINUX || IOUtils.MAC_OS_X) && JavaVersion.current().compareTo(JavaVersion.parse("11")) >= 0
|
||||
);
|
||||
assumeTrue("setting default keepalive options not supported on this platform", (IOUtils.LINUX || IOUtils.MAC_OS_X));
|
||||
try (
|
||||
MockTransportService serviceC = buildService("TS_C", Version.CURRENT, Settings.EMPTY);
|
||||
MockTransportService serviceD = buildService("TS_D", Version.CURRENT, Settings.EMPTY)
|
||||
|
|
|
@ -38,7 +38,6 @@ import com.sun.net.httpserver.Headers;
|
|||
import com.sun.net.httpserver.HttpsConfigurator;
|
||||
import com.sun.net.httpserver.HttpsServer;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.opensearch.bootstrap.JavaVersion;
|
||||
import org.opensearch.cloud.azure.classic.management.AzureComputeService;
|
||||
import org.opensearch.common.SuppressForbidden;
|
||||
import org.opensearch.common.io.FileSystemUtils;
|
||||
|
@ -67,6 +66,7 @@ import java.io.IOException;
|
|||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.io.StringWriter;
|
||||
import java.lang.Runtime.Version;
|
||||
import java.net.InetAddress;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
@ -295,15 +295,13 @@ public class AzureDiscoveryClusterFormationTests extends OpenSearchIntegTestCase
|
|||
* 12.0.1 so we pin to TLSv1.2 when running on an earlier JDK
|
||||
*/
|
||||
private static String getProtocol() {
|
||||
if (JavaVersion.current().compareTo(JavaVersion.parse("11")) < 0) {
|
||||
return "TLS";
|
||||
} else if (JavaVersion.current().compareTo(JavaVersion.parse("12")) < 0) {
|
||||
if (Runtime.version().compareTo(Version.parse("12")) < 0) {
|
||||
return "TLSv1.2";
|
||||
} else {
|
||||
JavaVersion full = AccessController.doPrivileged(
|
||||
(PrivilegedAction<JavaVersion>) () -> JavaVersion.parse(System.getProperty("java.version"))
|
||||
Version full = AccessController.doPrivileged(
|
||||
(PrivilegedAction<Version>) () -> Version.parse(System.getProperty("java.version"))
|
||||
);
|
||||
if (full.compareTo(JavaVersion.parse("12.0.1")) < 0) {
|
||||
if (full.compareTo(Version.parse("12.0.1")) < 0) {
|
||||
return "TLSv1.2";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,7 +42,6 @@ import org.apache.tika.parser.ParserDecorator;
|
|||
import org.opensearch.SpecialPermission;
|
||||
import org.opensearch.bootstrap.FilePermissionUtils;
|
||||
import org.opensearch.bootstrap.JarHell;
|
||||
import org.opensearch.bootstrap.JavaVersion;
|
||||
import org.opensearch.common.SuppressForbidden;
|
||||
import org.opensearch.common.io.PathUtils;
|
||||
|
||||
|
@ -181,14 +180,6 @@ final class TikaImpl {
|
|||
perms.add(new RuntimePermission("accessClassInPackage.sun.java2d.cmm.kcms"));
|
||||
// xmlbeans, use by POI, needs to get the context classloader
|
||||
perms.add(new RuntimePermission("getClassLoader"));
|
||||
// ZipFile needs accessDeclaredMembers on JDK 10; cf. https://bugs.openjdk.java.net/browse/JDK-8187485
|
||||
if (JavaVersion.current().compareTo(JavaVersion.parse("10")) >= 0) {
|
||||
if (JavaVersion.current().compareTo(JavaVersion.parse("11")) < 0) {
|
||||
// TODO remove this and from plugin-security.policy when JDK 11 is the only one we support
|
||||
// this is needed pre 11, but it's fixed in 11 : https://bugs.openjdk.java.net/browse/JDK-8187485
|
||||
perms.add(new RuntimePermission("accessDeclaredMembers"));
|
||||
}
|
||||
}
|
||||
perms.setReadOnly();
|
||||
return perms;
|
||||
}
|
||||
|
|
|
@ -44,7 +44,6 @@ import org.apache.lucene.util.BytesRef;
|
|||
import org.apache.lucene.util.BytesRefBuilder;
|
||||
import org.opensearch.action.ActionRunnable;
|
||||
import org.opensearch.action.support.PlainActionFuture;
|
||||
import org.opensearch.bootstrap.JavaVersion;
|
||||
import org.opensearch.cluster.metadata.RepositoryMetadata;
|
||||
import org.opensearch.cluster.service.ClusterService;
|
||||
import org.opensearch.common.SuppressForbidden;
|
||||
|
@ -67,7 +66,6 @@ import org.opensearch.repositories.Repository;
|
|||
import org.opensearch.repositories.blobstore.BlobStoreRepository;
|
||||
import org.opensearch.repositories.blobstore.OpenSearchMockAPIBasedRepositoryIntegTestCase;
|
||||
|
||||
import org.junit.BeforeClass;
|
||||
import org.threeten.bp.Duration;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -88,22 +86,6 @@ import static org.opensearch.repositories.gcs.GoogleCloudStorageRepository.CLIEN
|
|||
|
||||
@SuppressForbidden(reason = "this test uses a HttpServer to emulate a Google Cloud Storage endpoint")
|
||||
public class GoogleCloudStorageBlobStoreRepositoryTests extends OpenSearchMockAPIBasedRepositoryIntegTestCase {
|
||||
|
||||
public static void assumeNotJava8() {
|
||||
assumeFalse(
|
||||
"This test is flaky on jdk8 - we suspect a JDK bug to trigger some assertion in the HttpServer implementation used "
|
||||
+ "to emulate the server side logic of Google Cloud Storage. See https://bugs.openjdk.java.net/browse/JDK-8180754, "
|
||||
+ "https://github.com/elastic/elasticsearch/pull/51933 and https://github.com/elastic/elasticsearch/issues/52906 "
|
||||
+ "for more background on this issue.",
|
||||
JavaVersion.current().equals(JavaVersion.parse("8"))
|
||||
);
|
||||
}
|
||||
|
||||
@BeforeClass
|
||||
public static void skipJava8() {
|
||||
assumeNotJava8();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String repositoryType() {
|
||||
return GoogleCloudStorageRepository.TYPE;
|
||||
|
|
|
@ -39,7 +39,6 @@ import com.sun.net.httpserver.HttpHandler;
|
|||
import fixture.gcs.FakeOAuth2HttpHandler;
|
||||
import org.apache.http.HttpStatus;
|
||||
|
||||
import org.opensearch.bootstrap.JavaVersion;
|
||||
import org.opensearch.common.Nullable;
|
||||
import org.opensearch.common.Strings;
|
||||
import org.opensearch.common.SuppressForbidden;
|
||||
|
@ -62,7 +61,6 @@ import org.opensearch.repositories.blobstore.AbstractBlobContainerRetriesTestCas
|
|||
import org.opensearch.repositories.blobstore.OpenSearchMockAPIBasedRepositoryIntegTestCase;
|
||||
import org.opensearch.rest.RestStatus;
|
||||
import org.opensearch.rest.RestUtils;
|
||||
import org.junit.BeforeClass;
|
||||
import org.threeten.bp.Duration;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -107,21 +105,6 @@ public class GoogleCloudStorageBlobContainerRetriesTests extends AbstractBlobCon
|
|||
return "http://" + InetAddresses.toUriString(address.getAddress()) + ":" + address.getPort();
|
||||
}
|
||||
|
||||
public static void assumeNotJava8() {
|
||||
assumeFalse(
|
||||
"This test is flaky on jdk8 - we suspect a JDK bug to trigger some assertion in the HttpServer implementation used "
|
||||
+ "to emulate the server side logic of Google Cloud Storage. See https://bugs.openjdk.java.net/browse/JDK-8180754, "
|
||||
+ "https://github.com/elastic/elasticsearch/pull/51933 and https://github.com/elastic/elasticsearch/issues/52906 "
|
||||
+ "for more background on this issue.",
|
||||
JavaVersion.current().equals(JavaVersion.parse("8"))
|
||||
);
|
||||
}
|
||||
|
||||
@BeforeClass
|
||||
public static void skipJava8() {
|
||||
assumeNotJava8();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String downloadStorageEndpoint(String blob) {
|
||||
return "/download/storage/v1/b/bucket/o/" + blob;
|
||||
|
|
|
@ -36,7 +36,6 @@ import org.opensearch.action.admin.cluster.snapshots.create.CreateSnapshotRespon
|
|||
import org.opensearch.action.admin.cluster.snapshots.restore.RestoreSnapshotResponse;
|
||||
|
||||
import org.opensearch.action.support.master.AcknowledgedResponse;
|
||||
import org.opensearch.bootstrap.JavaVersion;
|
||||
import org.opensearch.client.Client;
|
||||
import org.opensearch.cluster.ClusterState;
|
||||
import org.opensearch.common.settings.Settings;
|
||||
|
@ -63,7 +62,6 @@ public class HdfsTests extends OpenSearchSingleNodeTestCase {
|
|||
}
|
||||
|
||||
public void testSimpleWorkflow() {
|
||||
assumeFalse("https://github.com/elastic/elasticsearch/issues/31498", JavaVersion.current().equals(JavaVersion.parse("11")));
|
||||
Client client = client();
|
||||
|
||||
AcknowledgedResponse putRepositoryResponse = client.admin()
|
||||
|
|
|
@ -34,7 +34,6 @@ package org.opensearch.transport.nio;
|
|||
|
||||
import org.opensearch.Version;
|
||||
import org.opensearch.action.ActionListener;
|
||||
import org.opensearch.bootstrap.JavaVersion;
|
||||
import org.opensearch.cluster.node.DiscoveryNode;
|
||||
import org.opensearch.common.io.stream.NamedWriteableRegistry;
|
||||
import org.opensearch.common.network.NetworkService;
|
||||
|
@ -122,10 +121,7 @@ public class SimpleNioTransportTests extends AbstractSimpleTransportTestCase {
|
|||
}
|
||||
|
||||
public void testDefaultKeepAliveSettings() throws IOException {
|
||||
assumeTrue(
|
||||
"setting default keepalive options not supported on this platform",
|
||||
(IOUtils.LINUX || IOUtils.MAC_OS_X) && JavaVersion.current().compareTo(JavaVersion.parse("11")) >= 0
|
||||
);
|
||||
assumeTrue("setting default keepalive options not supported on this platform", (IOUtils.LINUX || IOUtils.MAC_OS_X));
|
||||
try (
|
||||
MockTransportService serviceC = buildService("TS_C", Version.CURRENT, Settings.EMPTY);
|
||||
MockTransportService serviceD = buildService("TS_D", Version.CURRENT, Settings.EMPTY)
|
||||
|
|
|
@ -35,7 +35,6 @@ import org.opensearch.OpenSearchException;
|
|||
import org.opensearch.action.index.IndexRequestBuilder;
|
||||
import org.opensearch.action.search.SearchPhaseExecutionException;
|
||||
import org.opensearch.action.search.SearchResponse;
|
||||
import org.opensearch.bootstrap.JavaVersion;
|
||||
import org.opensearch.common.Strings;
|
||||
import org.opensearch.common.settings.Settings;
|
||||
import org.opensearch.common.time.DateFormatter;
|
||||
|
@ -386,9 +385,6 @@ public class DateHistogramIT extends OpenSearchIntegTestCase {
|
|||
ZonedDateTime expectedKey = keyIterator.next();
|
||||
String bucketKey = bucket.getKeyAsString();
|
||||
String expectedBucketName = Long.toString(expectedKey.toInstant().toEpochMilli() / millisDivider);
|
||||
if (JavaVersion.current().getVersion().get(0) == 8 && bucket.getKeyAsString().endsWith(".0")) {
|
||||
expectedBucketName = expectedBucketName + ".0";
|
||||
}
|
||||
assertThat(bucketKey, equalTo(expectedBucketName));
|
||||
assertThat(((ZonedDateTime) bucket.getKey()), equalTo(expectedKey));
|
||||
assertThat(bucket.getDocCount(), equalTo(1L));
|
||||
|
@ -1509,11 +1505,7 @@ public class DateHistogramIT extends OpenSearchIntegTestCase {
|
|||
assertSearchResponse(response);
|
||||
Histogram histo = response.getAggregations().get("histo");
|
||||
assertThat(histo.getBuckets().size(), equalTo(1));
|
||||
if (JavaVersion.current().getVersion().get(0) == 8 && histo.getBuckets().get(0).getKeyAsString().endsWith(".0")) {
|
||||
assertThat(histo.getBuckets().get(0).getKeyAsString(), equalTo("1477954800000.0"));
|
||||
} else {
|
||||
assertThat(histo.getBuckets().get(0).getKeyAsString(), equalTo("1477954800000"));
|
||||
}
|
||||
assertThat(histo.getBuckets().get(0).getKeyAsString(), equalTo("1477954800000"));
|
||||
assertThat(histo.getBuckets().get(0).getDocCount(), equalTo(1L));
|
||||
|
||||
response = client().prepareSearch(index)
|
||||
|
|
|
@ -44,7 +44,6 @@ import org.opensearch.action.index.IndexRequestBuilder;
|
|||
import org.opensearch.action.search.SearchPhaseExecutionException;
|
||||
import org.opensearch.action.search.SearchResponse;
|
||||
import org.opensearch.action.search.SearchType;
|
||||
import org.opensearch.bootstrap.JavaVersion;
|
||||
import org.opensearch.common.document.DocumentField;
|
||||
import org.opensearch.common.lucene.search.SpanBooleanQueryRewriteWithMaxClause;
|
||||
import org.opensearch.common.regex.Regex;
|
||||
|
@ -1860,7 +1859,6 @@ public class SearchQueryIT extends OpenSearchIntegTestCase {
|
|||
* on "Configuring IDEs And Running Tests".
|
||||
*/
|
||||
public void testRangeQueryWithLocaleMapping() throws Exception {
|
||||
assumeTrue("need java 9 for testing ", JavaVersion.current().compareTo(JavaVersion.parse("9")) >= 0);
|
||||
assert ("SPI,COMPAT".equals(System.getProperty("java.locale.providers"))) : "`-Djava.locale.providers=SPI,COMPAT` needs to be set";
|
||||
|
||||
assertAcked(
|
||||
|
|
|
@ -48,7 +48,6 @@ import org.opensearch.cli.UserException;
|
|||
import org.opensearch.common.PidFile;
|
||||
import org.opensearch.common.SuppressForbidden;
|
||||
import org.opensearch.common.inject.CreationException;
|
||||
import org.opensearch.common.logging.DeprecationLogger;
|
||||
import org.opensearch.common.logging.LogConfigurator;
|
||||
import org.opensearch.common.logging.Loggers;
|
||||
import org.opensearch.common.network.IfConfig;
|
||||
|
@ -78,7 +77,6 @@ import java.nio.file.Path;
|
|||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
|
@ -374,14 +372,6 @@ final class Bootstrap {
|
|||
} catch (IOException e) {
|
||||
throw new BootstrapException(e);
|
||||
}
|
||||
if (JavaVersion.current().compareTo(JavaVersion.parse("11")) < 0) {
|
||||
final String message = String.format(
|
||||
Locale.ROOT,
|
||||
"future versions of OpenSearch will require Java 11; " + "your Java version from [%s] does not meet this requirement",
|
||||
System.getProperty("java.home")
|
||||
);
|
||||
DeprecationLogger.getLogger(Bootstrap.class).deprecate("java_version_11_required", message);
|
||||
}
|
||||
if (environment.pidFile() != null) {
|
||||
try {
|
||||
PidFile.create(environment.pidFile(), true);
|
||||
|
|
|
@ -59,8 +59,6 @@ import java.util.Collections;
|
|||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
|
@ -224,7 +222,6 @@ final class BootstrapChecks {
|
|||
checks.add(new OnErrorCheck());
|
||||
checks.add(new OnOutOfMemoryErrorCheck());
|
||||
checks.add(new EarlyAccessCheck());
|
||||
checks.add(new G1GCCheck());
|
||||
checks.add(new AllPermissionCheck());
|
||||
checks.add(new DiscoveryConfiguredCheck());
|
||||
return Collections.unmodifiableList(checks);
|
||||
|
@ -683,60 +680,6 @@ final class BootstrapChecks {
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* Bootstrap check for versions of HotSpot that are known to have issues that can lead to index corruption when G1GC is enabled.
|
||||
*/
|
||||
static class G1GCCheck implements BootstrapCheck {
|
||||
|
||||
@Override
|
||||
public BootstrapCheckResult check(BootstrapContext context) {
|
||||
if ("Oracle Corporation".equals(jvmVendor()) && isJava8() && isG1GCEnabled()) {
|
||||
final String jvmVersion = jvmVersion();
|
||||
// HotSpot versions on Java 8 match this regular expression; note that this changes with Java 9 after JEP-223
|
||||
final Pattern pattern = Pattern.compile("(\\d+)\\.(\\d+)-b\\d+");
|
||||
final Matcher matcher = pattern.matcher(jvmVersion);
|
||||
final boolean matches = matcher.matches();
|
||||
assert matches : jvmVersion;
|
||||
final int major = Integer.parseInt(matcher.group(1));
|
||||
final int update = Integer.parseInt(matcher.group(2));
|
||||
// HotSpot versions for Java 8 have major version 25, the bad versions are all versions prior to update 40
|
||||
if (major == 25 && update < 40) {
|
||||
final String message = String.format(
|
||||
Locale.ROOT,
|
||||
"JVM version [%s] can cause data corruption when used with G1GC; upgrade to at least Java 8u40",
|
||||
jvmVersion
|
||||
);
|
||||
return BootstrapCheckResult.failure(message);
|
||||
}
|
||||
}
|
||||
return BootstrapCheckResult.success();
|
||||
}
|
||||
|
||||
// visible for testing
|
||||
String jvmVendor() {
|
||||
return Constants.JVM_VENDOR;
|
||||
}
|
||||
|
||||
// visible for testing
|
||||
boolean isG1GCEnabled() {
|
||||
assert "Oracle Corporation".equals(jvmVendor());
|
||||
return JvmInfo.jvmInfo().useG1GC().equals("true");
|
||||
}
|
||||
|
||||
// visible for testing
|
||||
String jvmVersion() {
|
||||
assert "Oracle Corporation".equals(jvmVendor());
|
||||
return Constants.JVM_VERSION;
|
||||
}
|
||||
|
||||
// visible for testing
|
||||
boolean isJava8() {
|
||||
assert "Oracle Corporation".equals(jvmVendor());
|
||||
return JavaVersion.current().equals(JavaVersion.parse("1.8"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static class AllPermissionCheck implements BootstrapCheck {
|
||||
|
||||
@Override
|
||||
|
|
|
@ -52,7 +52,6 @@ import java.util.ArrayList;
|
|||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
@ -654,81 +653,6 @@ public class BootstrapChecksTests extends AbstractBootstrapCheckTestCase {
|
|||
|
||||
}
|
||||
|
||||
public void testG1GCCheck() throws NodeValidationException {
|
||||
final AtomicBoolean isG1GCEnabled = new AtomicBoolean(true);
|
||||
final AtomicBoolean isJava8 = new AtomicBoolean(true);
|
||||
final AtomicReference<String> jvmVersion = new AtomicReference<>(
|
||||
String.format(Locale.ROOT, "25.%d-b%d", randomIntBetween(0, 39), randomIntBetween(1, 128))
|
||||
);
|
||||
final BootstrapChecks.G1GCCheck g1GCCheck = new BootstrapChecks.G1GCCheck() {
|
||||
|
||||
@Override
|
||||
String jvmVendor() {
|
||||
return "Oracle Corporation";
|
||||
}
|
||||
|
||||
@Override
|
||||
boolean isG1GCEnabled() {
|
||||
return isG1GCEnabled.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
String jvmVersion() {
|
||||
return jvmVersion.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
boolean isJava8() {
|
||||
return isJava8.get();
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
final NodeValidationException e = expectThrows(
|
||||
NodeValidationException.class,
|
||||
() -> BootstrapChecks.check(emptyContext, true, Collections.singletonList(g1GCCheck))
|
||||
);
|
||||
assertThat(
|
||||
e.getMessage(),
|
||||
containsString(
|
||||
"JVM version [" + jvmVersion.get() + "] can cause data corruption when used with G1GC; upgrade to at least Java 8u40"
|
||||
)
|
||||
);
|
||||
|
||||
// if G1GC is disabled, nothing should happen
|
||||
isG1GCEnabled.set(false);
|
||||
BootstrapChecks.check(emptyContext, true, Collections.singletonList(g1GCCheck));
|
||||
|
||||
// if on or after update 40, nothing should happen independent of whether or not G1GC is enabled
|
||||
isG1GCEnabled.set(randomBoolean());
|
||||
jvmVersion.set(String.format(Locale.ROOT, "25.%d-b%d", randomIntBetween(40, 112), randomIntBetween(1, 128)));
|
||||
BootstrapChecks.check(emptyContext, true, Collections.singletonList(g1GCCheck));
|
||||
|
||||
final BootstrapChecks.G1GCCheck nonOracleCheck = new BootstrapChecks.G1GCCheck() {
|
||||
|
||||
@Override
|
||||
String jvmVendor() {
|
||||
return randomAlphaOfLength(8);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
// if not on an Oracle JVM, nothing should happen
|
||||
BootstrapChecks.check(emptyContext, true, Collections.singletonList(nonOracleCheck));
|
||||
|
||||
final BootstrapChecks.G1GCCheck nonJava8Check = new BootstrapChecks.G1GCCheck() {
|
||||
|
||||
@Override
|
||||
boolean isJava8() {
|
||||
return false;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
// if not Java 8, nothing should happen
|
||||
BootstrapChecks.check(emptyContext, true, Collections.singletonList(nonJava8Check));
|
||||
}
|
||||
|
||||
public void testAllPermissionCheck() throws NodeValidationException {
|
||||
final AtomicBoolean isAllPermissionGranted = new AtomicBoolean(true);
|
||||
final BootstrapChecks.AllPermissionCheck allPermissionCheck = new BootstrapChecks.AllPermissionCheck() {
|
||||
|
|
|
@ -34,6 +34,7 @@ package org.opensearch.bootstrap;
|
|||
|
||||
import org.opensearch.test.OpenSearchTestCase;
|
||||
|
||||
import java.lang.Runtime.Version;
|
||||
import java.util.List;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.equalTo;
|
||||
|
@ -41,29 +42,22 @@ import static org.hamcrest.CoreMatchers.is;
|
|||
|
||||
public class JavaVersionTests extends OpenSearchTestCase {
|
||||
public void testParse() {
|
||||
JavaVersion javaVersion = JavaVersion.parse("1.7.0");
|
||||
List<Integer> version = javaVersion.getVersion();
|
||||
assertThat(version.size(), is(3));
|
||||
assertThat(version.get(0), is(1));
|
||||
assertThat(version.get(1), is(7));
|
||||
assertThat(version.get(2), is(0));
|
||||
|
||||
JavaVersion javaVersionEarlyAccess = JavaVersion.parse("14.0.1-ea");
|
||||
List<Integer> version14 = javaVersionEarlyAccess.getVersion();
|
||||
Version javaVersionEarlyAccess = Version.parse("14.0.1-ea");
|
||||
List<Integer> version14 = javaVersionEarlyAccess.version();
|
||||
assertThat(version14.size(), is(3));
|
||||
assertThat(version14.get(0), is(14));
|
||||
assertThat(version14.get(1), is(0));
|
||||
assertThat(version14.get(2), is(1));
|
||||
|
||||
JavaVersion javaVersionOtherPrePart = JavaVersion.parse("13.2.4-somethingElseHere");
|
||||
List<Integer> version13 = javaVersionOtherPrePart.getVersion();
|
||||
Version javaVersionOtherPrePart = Version.parse("13.2.4-somethingElseHere");
|
||||
List<Integer> version13 = javaVersionOtherPrePart.version();
|
||||
assertThat(version13.size(), is(3));
|
||||
assertThat(version13.get(0), is(13));
|
||||
assertThat(version13.get(1), is(2));
|
||||
assertThat(version13.get(2), is(4));
|
||||
|
||||
JavaVersion javaVersionNumericPrePart = JavaVersion.parse("13.2.4-something124443");
|
||||
List<Integer> version11 = javaVersionNumericPrePart.getVersion();
|
||||
Version javaVersionNumericPrePart = Version.parse("13.2.4-something124443");
|
||||
List<Integer> version11 = javaVersionNumericPrePart.version();
|
||||
assertThat(version11.size(), is(3));
|
||||
assertThat(version11.get(0), is(13));
|
||||
assertThat(version11.get(1), is(2));
|
||||
|
@ -71,51 +65,36 @@ public class JavaVersionTests extends OpenSearchTestCase {
|
|||
}
|
||||
|
||||
public void testParseInvalidVersions() {
|
||||
final IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> JavaVersion.parse("11.2-something-else"));
|
||||
assertThat(e.getMessage(), equalTo("Java version string [11.2-something-else] could not be parsed."));
|
||||
final IllegalArgumentException e1 = expectThrows(IllegalArgumentException.class, () -> JavaVersion.parse("11.0."));
|
||||
assertThat(e1.getMessage(), equalTo("Java version string [11.0.] could not be parsed."));
|
||||
final IllegalArgumentException e2 = expectThrows(IllegalArgumentException.class, () -> JavaVersion.parse("11.a.3"));
|
||||
assertThat(e2.getMessage(), equalTo("Java version string [11.a.3] could not be parsed."));
|
||||
final IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> Version.parse("11.2+something-else"));
|
||||
assertThat(e.getMessage(), equalTo("Invalid version string: '11.2+something-else'"));
|
||||
final IllegalArgumentException e1 = expectThrows(IllegalArgumentException.class, () -> Version.parse("11.0."));
|
||||
assertThat(e1.getMessage(), equalTo("Invalid version string: '11.0.'"));
|
||||
final IllegalArgumentException e2 = expectThrows(IllegalArgumentException.class, () -> Version.parse("11.a.3"));
|
||||
assertThat(e2.getMessage(), equalTo("Invalid version string: '11.a.3'"));
|
||||
}
|
||||
|
||||
public void testToString() {
|
||||
JavaVersion javaVersion170 = JavaVersion.parse("1.7.0");
|
||||
assertThat(javaVersion170.toString(), is("1.7.0"));
|
||||
JavaVersion javaVersion9 = JavaVersion.parse("9");
|
||||
Version javaVersion9 = Version.parse("9");
|
||||
assertThat(javaVersion9.toString(), is("9"));
|
||||
JavaVersion javaVersion11 = JavaVersion.parse("11.0.1-something09random");
|
||||
Version javaVersion11 = Version.parse("11.0.1-something09random");
|
||||
assertThat(javaVersion11.toString(), is("11.0.1-something09random"));
|
||||
JavaVersion javaVersion12 = JavaVersion.parse("12.2-2019");
|
||||
Version javaVersion12 = Version.parse("12.2-2019");
|
||||
assertThat(javaVersion12.toString(), is("12.2-2019"));
|
||||
JavaVersion javaVersion13ea = JavaVersion.parse("13.1-ea");
|
||||
Version javaVersion13ea = Version.parse("13.1-ea");
|
||||
assertThat(javaVersion13ea.toString(), is("13.1-ea"));
|
||||
}
|
||||
|
||||
public void testCompare() {
|
||||
JavaVersion onePointSix = JavaVersion.parse("1.6");
|
||||
JavaVersion onePointSeven = JavaVersion.parse("1.7");
|
||||
JavaVersion onePointSevenPointZero = JavaVersion.parse("1.7.0");
|
||||
JavaVersion onePointSevenPointOne = JavaVersion.parse("1.7.1");
|
||||
JavaVersion onePointSevenPointTwo = JavaVersion.parse("1.7.2");
|
||||
JavaVersion onePointSevenPointOnePointOne = JavaVersion.parse("1.7.1.1");
|
||||
JavaVersion onePointSevenPointTwoPointOne = JavaVersion.parse("1.7.2.1");
|
||||
JavaVersion thirteen = JavaVersion.parse("13");
|
||||
JavaVersion thirteenPointTwoPointOne = JavaVersion.parse("13.2.1");
|
||||
JavaVersion thirteenPointTwoPointOneTwoThousand = JavaVersion.parse("13.2.1-2000");
|
||||
JavaVersion thirteenPointTwoPointOneThreeThousand = JavaVersion.parse("13.2.1-3000");
|
||||
JavaVersion thirteenPointTwoPointOneA = JavaVersion.parse("13.2.1-aaa");
|
||||
JavaVersion thirteenPointTwoPointOneB = JavaVersion.parse("13.2.1-bbb");
|
||||
JavaVersion fourteen = JavaVersion.parse("14");
|
||||
JavaVersion fourteenPointTwoPointOne = JavaVersion.parse("14.2.1");
|
||||
JavaVersion fourteenPointTwoPointOneEarlyAccess = JavaVersion.parse("14.2.1-ea");
|
||||
Version thirteen = Version.parse("13");
|
||||
Version thirteenPointTwoPointOne = Version.parse("13.2.1");
|
||||
Version thirteenPointTwoPointOneTwoThousand = Version.parse("13.2.1-2000");
|
||||
Version thirteenPointTwoPointOneThreeThousand = Version.parse("13.2.1-3000");
|
||||
Version thirteenPointTwoPointOneA = Version.parse("13.2.1-aaa");
|
||||
Version thirteenPointTwoPointOneB = Version.parse("13.2.1-bbb");
|
||||
Version fourteen = Version.parse("14");
|
||||
Version fourteenPointTwoPointOne = Version.parse("14.2.1");
|
||||
Version fourteenPointTwoPointOneEarlyAccess = Version.parse("14.2.1-ea");
|
||||
|
||||
assertTrue(onePointSix.compareTo(onePointSeven) < 0);
|
||||
assertTrue(onePointSeven.compareTo(onePointSix) > 0);
|
||||
assertTrue(onePointSix.compareTo(onePointSix) == 0);
|
||||
assertTrue(onePointSeven.compareTo(onePointSevenPointZero) == 0);
|
||||
assertTrue(onePointSevenPointOnePointOne.compareTo(onePointSevenPointOne) > 0);
|
||||
assertTrue(onePointSevenPointTwo.compareTo(onePointSevenPointTwoPointOne) < 0);
|
||||
assertTrue(thirteen.compareTo(thirteenPointTwoPointOne) < 0);
|
||||
assertTrue(thirteen.compareTo(fourteen) < 0);
|
||||
assertTrue(thirteenPointTwoPointOneThreeThousand.compareTo(thirteenPointTwoPointOneTwoThousand) > 0);
|
||||
|
@ -129,20 +108,16 @@ public class JavaVersionTests extends OpenSearchTestCase {
|
|||
}
|
||||
|
||||
public void testValidVersions() {
|
||||
String[] versions = new String[] { "1.7", "1.7.0", "0.1.7", "1.7.0.80", "12-ea", "13.0.2.3-ea", "14-something", "11.0.2-21002" };
|
||||
String[] versions = new String[] { "12-ea", "13.0.2.3-ea", "14-something", "11.0.2-21002", "11.0.14.1+1", "17.0.2+8" };
|
||||
for (String version : versions) {
|
||||
assertTrue(JavaVersion.isValid(version));
|
||||
assertNotNull(Version.parse(version));
|
||||
}
|
||||
}
|
||||
|
||||
public void testInvalidVersions() {
|
||||
String[] versions = new String[] { "", "1.7.0_80", "1.7.", "11.2-something-else" };
|
||||
String[] versions = new String[] { "", "1.7.0_80", "1.7.", "11.2+something-else" };
|
||||
for (String version : versions) {
|
||||
assertFalse(JavaVersion.isValid(version));
|
||||
assertThrows(IllegalArgumentException.class, () -> Version.parse(version));
|
||||
}
|
||||
}
|
||||
|
||||
public void testJava8Compat() {
|
||||
assertEquals(JavaVersion.parse("1.8"), JavaVersion.parse("8"));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,12 +32,12 @@
|
|||
|
||||
package org.opensearch.common;
|
||||
|
||||
import org.opensearch.bootstrap.JavaVersion;
|
||||
import org.opensearch.common.LocalTimeOffset.Gap;
|
||||
import org.opensearch.common.LocalTimeOffset.Overlap;
|
||||
import org.opensearch.common.time.DateFormatter;
|
||||
import org.opensearch.test.OpenSearchTestCase;
|
||||
|
||||
import java.lang.Runtime.Version;
|
||||
import java.time.Instant;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZoneOffset;
|
||||
|
@ -278,7 +278,7 @@ public class LocalTimeOffsetTests extends OpenSearchTestCase {
|
|||
assertKnownMovesBacktoPreviousDay("America/Moncton", "2005-10-29T03:01:00");
|
||||
assertKnownMovesBacktoPreviousDay("America/St_Johns", "2010-11-07T02:31:00");
|
||||
assertKnownMovesBacktoPreviousDay("Canada/Newfoundland", "2010-11-07T02:31:00");
|
||||
if (JavaVersion.current().compareTo(JavaVersion.parse("11")) > 0) {
|
||||
if (Runtime.version().compareTo(Version.parse("11")) > 0) {
|
||||
// Added in java 12
|
||||
assertKnownMovesBacktoPreviousDay("Pacific/Guam", "1969-01-25T13:01:00");
|
||||
assertKnownMovesBacktoPreviousDay("Pacific/Saipan", "1969-01-25T13:01:00");
|
||||
|
|
|
@ -33,7 +33,6 @@
|
|||
package org.opensearch.common.joda;
|
||||
|
||||
import org.opensearch.OpenSearchParseException;
|
||||
import org.opensearch.bootstrap.JavaVersion;
|
||||
import org.opensearch.common.time.DateFormatter;
|
||||
import org.opensearch.common.time.DateFormatters;
|
||||
import org.opensearch.common.time.DateMathParser;
|
||||
|
@ -43,7 +42,6 @@ import org.joda.time.DateTime;
|
|||
import org.joda.time.DateTimeZone;
|
||||
import org.joda.time.format.DateTimeFormat;
|
||||
import org.joda.time.format.ISODateTimeFormat;
|
||||
import org.junit.BeforeClass;
|
||||
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZoneOffset;
|
||||
|
@ -62,18 +60,6 @@ public class JavaJodaTimeDuellingTests extends OpenSearchTestCase {
|
|||
return false;
|
||||
}
|
||||
|
||||
@BeforeClass
|
||||
public static void checkJvmProperties() {
|
||||
boolean runtimeJdk8 = JavaVersion.current().getVersion().get(0) == 8;
|
||||
assert (runtimeJdk8 && ("SPI,JRE".equals(System.getProperty("java.locale.providers"))))
|
||||
|| (false == runtimeJdk8 && ("SPI,COMPAT".equals(System.getProperty("java.locale.providers"))))
|
||||
: "`-Djava.locale.providers` needs to be set";
|
||||
assumeFalse(
|
||||
"won't work in jdk8 " + "because SPI mechanism is not looking at classpath - needs ISOCalendarDataProvider in jre's ext/libs",
|
||||
runtimeJdk8
|
||||
);
|
||||
}
|
||||
|
||||
public void testTimezoneParsing() {
|
||||
/** this testcase won't work in joda. See comment in {@link #testPartialTimeParsing()}
|
||||
* assertSameDateAs("2016-11-30T+01", "strict_date_optional_time", "strict_date_optional_time");
|
||||
|
@ -906,14 +892,6 @@ public class JavaJodaTimeDuellingTests extends OpenSearchTestCase {
|
|||
String jodaTimeOut = jodaDateFormatter.formatJoda(jodaDate);
|
||||
|
||||
assertThat(jodaDate.getMillis(), is(javaDate.toInstant().toEpochMilli()));
|
||||
|
||||
if (JavaVersion.current().getVersion().get(0) == 8
|
||||
&& javaTimeOut.endsWith(".0")
|
||||
&& (format.equals("epoch_second") || format.equals("epoch_millis"))) {
|
||||
// java 8 has a bug in DateTimeFormatter usage when printing dates that rely on isSupportedBy for fields, which is
|
||||
// what we use for epoch time. This change accounts for that bug. It should be removed when java 8 support is removed
|
||||
jodaTimeOut += ".0";
|
||||
}
|
||||
String message = String.format(
|
||||
Locale.ROOT,
|
||||
"expected string representation to be equal for format [%s]: joda [%s], java [%s]",
|
||||
|
|
|
@ -32,7 +32,6 @@
|
|||
|
||||
package org.opensearch.common.time;
|
||||
|
||||
import org.opensearch.bootstrap.JavaVersion;
|
||||
import org.opensearch.common.joda.Joda;
|
||||
import org.opensearch.test.OpenSearchTestCase;
|
||||
|
||||
|
@ -56,11 +55,6 @@ import static org.hamcrest.Matchers.sameInstance;
|
|||
public class DateFormattersTests extends OpenSearchTestCase {
|
||||
|
||||
public void testWeekBasedDates() {
|
||||
assumeFalse(
|
||||
"won't work in jdk8 " + "because SPI mechanism is not looking at classpath - needs ISOCalendarDataProvider in jre's ext/libs",
|
||||
JavaVersion.current().equals(JavaVersion.parse("8"))
|
||||
);
|
||||
|
||||
// as per WeekFields.ISO first week starts on Monday and has minimum 4 days
|
||||
DateFormatter dateFormatter = DateFormatters.forPattern("YYYY-ww");
|
||||
|
||||
|
|
|
@ -33,7 +33,6 @@
|
|||
package org.opensearch.common.time;
|
||||
|
||||
import org.opensearch.OpenSearchParseException;
|
||||
import org.opensearch.bootstrap.JavaVersion;
|
||||
import org.opensearch.test.OpenSearchTestCase;
|
||||
|
||||
import java.time.Instant;
|
||||
|
@ -111,11 +110,6 @@ public class JavaDateMathParserTests extends OpenSearchTestCase {
|
|||
}
|
||||
|
||||
public void testWeekDates() {
|
||||
assumeFalse(
|
||||
"won't work in jdk8 " + "because SPI mechanism is not looking at classpath - needs ISOCalendarDataProvider in jre's ext/libs",
|
||||
JavaVersion.current().equals(JavaVersion.parse("8"))
|
||||
);
|
||||
|
||||
DateFormatter formatter = DateFormatter.forPattern("YYYY-ww");
|
||||
assertDateMathEquals(formatter.toDateMathParser(), "2016-01", "2016-01-04T23:59:59.999Z", 0, true, ZoneOffset.UTC);
|
||||
|
||||
|
|
|
@ -34,7 +34,6 @@ package org.opensearch.index.mapper;
|
|||
|
||||
import org.apache.lucene.index.DocValuesType;
|
||||
import org.apache.lucene.index.IndexableField;
|
||||
import org.opensearch.bootstrap.JavaVersion;
|
||||
import org.opensearch.common.collect.List;
|
||||
import org.opensearch.common.time.DateFormatter;
|
||||
import org.opensearch.common.xcontent.XContentBuilder;
|
||||
|
@ -186,8 +185,6 @@ public class DateFieldMapperTests extends MapperTestCase {
|
|||
}
|
||||
|
||||
public void testChangeLocale() throws IOException {
|
||||
assumeTrue("need java 9 for testing ", JavaVersion.current().compareTo(JavaVersion.parse("9")) >= 0);
|
||||
|
||||
DocumentMapper mapper = createDocumentMapper(
|
||||
fieldMapping(b -> b.field("type", "date").field("format", "E, d MMM yyyy HH:mm:ss Z").field("locale", "de"))
|
||||
);
|
||||
|
|
|
@ -33,7 +33,6 @@
|
|||
package org.opensearch.monitor.jvm;
|
||||
|
||||
import org.apache.lucene.util.Constants;
|
||||
import org.opensearch.bootstrap.JavaVersion;
|
||||
import org.opensearch.test.OpenSearchTestCase;
|
||||
|
||||
public class JvmInfoTests extends OpenSearchTestCase {
|
||||
|
@ -53,14 +52,13 @@ public class JvmInfoTests extends OpenSearchTestCase {
|
|||
final String argline = System.getProperty("tests.jvm.argline");
|
||||
final boolean g1GCEnabled = flagIsEnabled(argline, "UseG1GC");
|
||||
// for JDK 9 the default collector when no collector is specified is G1 GC
|
||||
final boolean versionIsAtLeastJava9 = JavaVersion.current().compareTo(JavaVersion.parse("9")) >= 0;
|
||||
final boolean noOtherCollectorSpecified = argline == null
|
||||
|| (!flagIsEnabled(argline, "UseParNewGC")
|
||||
&& !flagIsEnabled(argline, "UseParallelGC")
|
||||
&& !flagIsEnabled(argline, "UseParallelOldGC")
|
||||
&& !flagIsEnabled(argline, "UseSerialGC")
|
||||
&& !flagIsEnabled(argline, "UseConcMarkSweepGC"));
|
||||
return g1GCEnabled || (versionIsAtLeastJava9 && noOtherCollectorSpecified);
|
||||
return g1GCEnabled || noOtherCollectorSpecified;
|
||||
}
|
||||
|
||||
private boolean flagIsEnabled(String argline, String flag) {
|
||||
|
|
|
@ -32,7 +32,6 @@
|
|||
|
||||
package org.opensearch.plugins;
|
||||
|
||||
import org.opensearch.bootstrap.JavaVersion;
|
||||
import org.opensearch.cluster.node.DiscoveryNode;
|
||||
import org.opensearch.cluster.routing.ShardRouting;
|
||||
import org.opensearch.common.settings.Settings;
|
||||
|
@ -134,25 +133,16 @@ public class IndexStorePluginTests extends OpenSearchTestCase {
|
|||
IllegalStateException.class,
|
||||
() -> new MockNode(settings, Arrays.asList(BarStorePlugin.class, FooStorePlugin.class))
|
||||
);
|
||||
if (JavaVersion.current().compareTo(JavaVersion.parse("9")) >= 0) {
|
||||
assertThat(
|
||||
e,
|
||||
hasToString(
|
||||
matches(
|
||||
"java.lang.IllegalStateException: Duplicate key store \\(attempted merging values "
|
||||
+ "org.opensearch.index.store.FsDirectoryFactory@[\\w\\d]+ "
|
||||
+ "and org.opensearch.index.store.FsDirectoryFactory@[\\w\\d]+\\)"
|
||||
)
|
||||
assertThat(
|
||||
e,
|
||||
hasToString(
|
||||
matches(
|
||||
"java.lang.IllegalStateException: Duplicate key store \\(attempted merging values "
|
||||
+ "org.opensearch.index.store.FsDirectoryFactory@[\\w\\d]+ "
|
||||
+ "and org.opensearch.index.store.FsDirectoryFactory@[\\w\\d]+\\)"
|
||||
)
|
||||
);
|
||||
} else {
|
||||
assertThat(
|
||||
e,
|
||||
hasToString(
|
||||
matches("java.lang.IllegalStateException: Duplicate key org.opensearch.index.store.FsDirectoryFactory@[\\w\\d]+")
|
||||
)
|
||||
);
|
||||
}
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public void testDuplicateIndexStoreRecoveryStateFactories() {
|
||||
|
@ -161,18 +151,6 @@ public class IndexStorePluginTests extends OpenSearchTestCase {
|
|||
IllegalStateException.class,
|
||||
() -> new MockNode(settings, Arrays.asList(FooCustomRecoveryStore.class, BarCustomRecoveryStore.class))
|
||||
);
|
||||
if (JavaVersion.current().compareTo(JavaVersion.parse("9")) >= 0) {
|
||||
assertThat(e.getMessage(), containsString("Duplicate key recovery-type"));
|
||||
} else {
|
||||
assertThat(
|
||||
e,
|
||||
hasToString(
|
||||
matches(
|
||||
"java.lang.IllegalStateException: Duplicate key "
|
||||
+ "org.opensearch.plugins.IndexStorePluginTests\\$RecoveryFactory@[\\w\\d]+"
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
assertThat(e.getMessage(), containsString("Duplicate key recovery-type"));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -723,7 +723,7 @@ public class PluginsServiceTests extends OpenSearchTestCase {
|
|||
"desc",
|
||||
"1.0",
|
||||
Version.CURRENT,
|
||||
"1000000.0",
|
||||
"1000000",
|
||||
"FakePlugin",
|
||||
Collections.emptyList(),
|
||||
false
|
||||
|
|
|
@ -70,7 +70,6 @@ import org.opensearch.action.search.ClearScrollResponse;
|
|||
import org.opensearch.action.search.SearchResponse;
|
||||
import org.opensearch.action.support.DefaultShardOperationFailedException;
|
||||
import org.opensearch.action.support.IndicesOptions;
|
||||
import org.opensearch.bootstrap.JavaVersion;
|
||||
import org.opensearch.client.AdminClient;
|
||||
import org.opensearch.client.Client;
|
||||
import org.opensearch.client.ClusterAdminClient;
|
||||
|
@ -166,6 +165,7 @@ import org.junit.Before;
|
|||
import org.junit.BeforeClass;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.Runtime.Version;
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Inherited;
|
||||
|
@ -2403,7 +2403,7 @@ public abstract class OpenSearchIntegTestCase extends OpenSearchTestCase {
|
|||
final boolean anyDebian8Nodes = response.getNodes()
|
||||
.stream()
|
||||
.anyMatch(ni -> ni.getInfo(OsInfo.class).getPrettyName().equals("Debian GNU/Linux 8 (jessie)"));
|
||||
boolean java15Plus = JavaVersion.current().compareTo(JavaVersion.parse("15")) >= 0;
|
||||
boolean java15Plus = Runtime.version().compareTo(Version.parse("15")) >= 0;
|
||||
return anyDebian8Nodes && java15Plus == false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -62,7 +62,6 @@ import org.apache.lucene.tests.util.TestUtil;
|
|||
import org.apache.lucene.tests.util.TimeUnits;
|
||||
import org.opensearch.Version;
|
||||
import org.opensearch.bootstrap.BootstrapForTesting;
|
||||
import org.opensearch.bootstrap.JavaVersion;
|
||||
import org.opensearch.client.Requests;
|
||||
import org.opensearch.cluster.ClusterModule;
|
||||
import org.opensearch.cluster.metadata.IndexMetadata;
|
||||
|
@ -967,17 +966,7 @@ public abstract class OpenSearchTestCase extends LuceneTestCase {
|
|||
* generate a random TimeZone from the ones available in java.time
|
||||
*/
|
||||
public static ZoneId randomZone() {
|
||||
// work around a JDK bug, where java 8 cannot parse the timezone GMT0 back into a temporal accessor
|
||||
// see https://bugs.openjdk.java.net/browse/JDK-8138664
|
||||
if (JavaVersion.current().getVersion().get(0) == 8) {
|
||||
ZoneId timeZone;
|
||||
do {
|
||||
timeZone = ZoneId.of(randomJodaAndJavaSupportedTimezone(JAVA_ZONE_IDS));
|
||||
} while (timeZone.equals(ZoneId.of("GMT0")));
|
||||
return timeZone;
|
||||
} else {
|
||||
return ZoneId.of(randomJodaAndJavaSupportedTimezone(JAVA_ZONE_IDS));
|
||||
}
|
||||
return ZoneId.of(randomJodaAndJavaSupportedTimezone(JAVA_ZONE_IDS));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -35,7 +35,6 @@ import com.carrotsearch.randomizedtesting.ReproduceErrorMessageBuilder;
|
|||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.apache.lucene.util.Constants;
|
||||
import org.opensearch.bootstrap.JavaVersion;
|
||||
import org.opensearch.common.Strings;
|
||||
import org.opensearch.common.SuppressForbidden;
|
||||
import org.opensearch.test.OpenSearchIntegTestCase;
|
||||
|
@ -192,7 +191,7 @@ public class ReproduceInfoPrinter extends RunListener {
|
|||
}
|
||||
appendOpt("tests.locale", Locale.getDefault().toLanguageTag());
|
||||
appendOpt("tests.timezone", TimeZone.getDefault().getID());
|
||||
appendOpt("runtime.java", Integer.toString(JavaVersion.current().getVersion().get(0)));
|
||||
appendOpt("runtime.java", Integer.toString(Runtime.version().version().get(0)));
|
||||
appendOpt(OpenSearchTestCase.FIPS_SYSPROP, System.getProperty(OpenSearchTestCase.FIPS_SYSPROP));
|
||||
return this;
|
||||
}
|
||||
|
|
|
@ -32,8 +32,6 @@
|
|||
|
||||
package org.opensearch.test.rest.yaml;
|
||||
|
||||
import org.opensearch.bootstrap.JavaVersion;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
|
@ -86,7 +84,7 @@ public final class Features {
|
|||
}
|
||||
|
||||
private static boolean isSupported(String feature) {
|
||||
if (feature.equals(SPI_ON_CLASSPATH_SINCE_JDK_9) && JavaVersion.current().compareTo(JavaVersion.parse("9")) >= 0) {
|
||||
if (feature.equals(SPI_ON_CLASSPATH_SINCE_JDK_9)) {
|
||||
return true;
|
||||
}
|
||||
return SUPPORTED.contains(feature);
|
||||
|
|
Loading…
Reference in New Issue