Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

package org.elasticsearch.tools.launchers;

import org.elasticsearch.tools.java_version_checker.JavaVersion;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;
Expand Down Expand Up @@ -60,11 +62,26 @@ static List<String> systemJvmOptions() {
// log4j 2
"-Dlog4j.shutdownHookEnabled=false",
"-Dlog4j2.disable.jmx=true",
/*
* Due to internationalization enhancements in JDK 9 Elasticsearch need to set the provider to COMPAT otherwise time/date
* parsing will break in an incompatible way for some date patterns and locales.
*/
"-Djava.locale.providers=COMPAT"));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why can't we keep this in system jvm options? Shouldn't this be something a user doesn't need to think about?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you are right, it is better to stay in SystemJvmOptions. We can always check the version running with JavaVersion.majorVersion(JavaVersion.CURRENT) == 8 to choose the right settings


javaLocaleProviders()));
}

private static String javaLocaleProviders() {
/**
* SPI setting is used to allow loading custom CalendarDataProvider
* in jdk8 it has to be loaded from jre/lib/ext,
* in jdk9+ it is already within ES project and on a classpath
*
* Due to internationalization enhancements in JDK 9 Elasticsearch need to set the provider to COMPAT otherwise time/date
* parsing will break in an incompatible way for some date patterns and locales.
* //TODO COMPAT will be deprecated in jdk14 https://bugs.openjdk.java.net/browse/JDK-8232906
* See also: documentation in <code>server/org.elasticsearch.common.time.IsoCalendarDataProvider</code>
*/
if(JavaVersion.majorVersion(JavaVersion.CURRENT) == 8){
return "-Djava.locale.providers=SPI,JRE";
} else {
return "-Djava.locale.providers=SPI,COMPAT";
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@

setup:
- skip:
version: " - 7.5.99"
reason: "Start of the week Monday was backported to 7.6"
features: "spi_on_classpath_jdk9"

- do:
indices.create:
index: test
body:
mappings:
properties:
date:
type: date
- do:
index:
index: test
id: 1
body: { "date": "2009-11-15T14:12:12" }
- do:
indices.refresh:
index: [test]
---
# The inserted document has a field date=2009-11-15T14:12:12 which is Sunday.
# When aggregating per day of the week this should be considered as last day of the week (7)
# and this value should be used in 'key_as_string'
"Date aggregation per day of week":
- do:
search:
rest_total_hits_as_int: true
index: test
body:
aggregations:
test:
"date_histogram": {
"field": "date",
"calendar_interval": "day",
"format": "e",
"offset": 0
}
- match: {hits.total: 1}
- length: { aggregations.test.buckets: 1 }
- match: { aggregations.test.buckets.0.key_as_string: "7" }
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@
import java.util.Locale;
import java.util.spi.CalendarDataProvider;

/**
* This class is loaded by JVM SPI mechanism in order to provide ISO compatible behaviour for week calculations using java.time.
* It defines start of the week as Monday and requires 4 days in the first week of the year.
* This class overrides default behaviour for Locale.ROOT (start of the week Sunday, minimum 1 day in the first week of the year).
* Java SPI mechanism requires java.locale.providers to contain SPI value (i.e. java.locale.providers=SPI,COMPAT)
* @see <a href="https://en.wikipedia.org/wiki/ISO_week_date">ISO week date</a>
*/
public class IsoCalendarDataProvider extends CalendarDataProvider {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
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;
Expand All @@ -47,6 +48,14 @@ protected boolean enableWarningsCheck() {
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";
}

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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@

package org.elasticsearch.test.rest.yaml;

import org.elasticsearch.bootstrap.JavaVersion;
import org.elasticsearch.test.rest.ESRestTestCase;

import java.util.Arrays;
import java.util.List;

import org.elasticsearch.test.rest.ESRestTestCase;

import static java.util.Collections.unmodifiableList;

/**
Expand All @@ -50,6 +51,7 @@ public final class Features {
"transform_and_set",
"arbitrary_key"
));
private static final String SPI_ON_CLASSPATH_SINCE_JDK_9 = "spi_on_classpath_jdk9";

private Features() {

Expand All @@ -68,10 +70,18 @@ public static boolean areAllSupported(List<String> features) {
if (ESRestTestCase.hasXPack()) {
return false;
}
} else if (false == SUPPORTED.contains(feature)) {
} else if (false == isSupported(feature)) {
return false;
}
}
return true;
}

private static boolean isSupported(String feature) {
if(feature.equals(SPI_ON_CLASSPATH_SINCE_JDK_9) &&
JavaVersion.current().compareTo(JavaVersion.parse("9")) >= 0) {
return true;
}
return SUPPORTED.contains(feature) ;
}
}