55 */
66package org .elasticsearch .xpack .sql .expression .function .scalar .datetime ;
77
8+ import org .elasticsearch .bootstrap .JavaVersion ;
9+ import org .elasticsearch .common .Strings ;
810import org .elasticsearch .common .io .stream .Writeable .Reader ;
911import org .elasticsearch .test .AbstractWireSerializingTestCase ;
1012import org .elasticsearch .xpack .sql .expression .function .scalar .datetime .NamedDateTimeProcessor .NameExtractor ;
1113import org .joda .time .DateTime ;
1214import org .joda .time .DateTimeZone ;
15+ import org .junit .Assume ;
1316
1417import java .io .IOException ;
1518import java .util .TimeZone ;
1619
1720public class NamedDateTimeProcessorTests extends AbstractWireSerializingTestCase <NamedDateTimeProcessor > {
21+
1822 private static final TimeZone UTC = TimeZone .getTimeZone ("UTC" );
1923
2024 public static NamedDateTimeProcessor randomNamedDateTimeProcessor () {
@@ -37,21 +41,21 @@ protected NamedDateTimeProcessor mutateInstance(NamedDateTimeProcessor instance)
3741 return new NamedDateTimeProcessor (replaced , UTC );
3842 }
3943
40- @ AwaitsFix (bugUrl = "https://github.com/elastic/elasticsearch/issues/33621" )
4144 public void testValidDayNamesInUTC () {
45+ assumeJava9PlusAndCompatLocaleProviderSetting ();
4246 NamedDateTimeProcessor proc = new NamedDateTimeProcessor (NameExtractor .DAY_NAME , UTC );
4347 assertEquals ("Thursday" , proc .process ("0" ));
4448 assertEquals ("Saturday" , proc .process ("-64164233612338" ));
4549 assertEquals ("Monday" , proc .process ("64164233612338" ));
46-
50+
4751 assertEquals ("Thursday" , proc .process (new DateTime (0L , DateTimeZone .UTC )));
4852 assertEquals ("Thursday" , proc .process (new DateTime (-5400 , 12 , 25 , 2 , 0 , DateTimeZone .UTC )));
4953 assertEquals ("Friday" , proc .process (new DateTime (30 , 2 , 1 , 12 , 13 , DateTimeZone .UTC )));
5054 assertEquals ("Tuesday" , proc .process (new DateTime (10902 , 8 , 22 , 11 , 11 , DateTimeZone .UTC )));
5155 }
5256
53- @ AwaitsFix (bugUrl = "https://github.com/elastic/elasticsearch/issues/33621" )
5457 public void testValidDayNamesWithNonUTCTimeZone () {
58+ assumeJava9PlusAndCompatLocaleProviderSetting ();
5559 NamedDateTimeProcessor proc = new NamedDateTimeProcessor (NameExtractor .DAY_NAME , TimeZone .getTimeZone ("GMT-10:00" ));
5660 assertEquals ("Wednesday" , proc .process ("0" ));
5761 assertEquals ("Friday" , proc .process ("-64164233612338" ));
@@ -64,9 +68,9 @@ public void testValidDayNamesWithNonUTCTimeZone() {
6468 assertEquals ("Monday" , proc .process (new DateTime (10902 , 8 , 22 , 9 , 59 , DateTimeZone .UTC )));
6569 }
6670
67- @ AwaitsFix (bugUrl = "https://github.com/elastic/elasticsearch/issues/33621" )
6871 public void testValidMonthNamesInUTC () {
69- NamedDateTimeProcessor proc = new NamedDateTimeProcessor (NameExtractor .MONTH_NAME , UTC );
72+ assumeJava9PlusAndCompatLocaleProviderSetting ();
73+ NamedDateTimeProcessor proc = new NamedDateTimeProcessor (NameExtractor .MONTH_NAME , UTC );
7074 assertEquals ("January" , proc .process ("0" ));
7175 assertEquals ("September" , proc .process ("-64164233612338" ));
7276 assertEquals ("April" , proc .process ("64164233612338" ));
@@ -77,8 +81,8 @@ public void testValidMonthNamesInUTC() {
7781 assertEquals ("August" , proc .process (new DateTime (10902 , 8 , 22 , 11 , 11 , DateTimeZone .UTC )));
7882 }
7983
80- @ AwaitsFix (bugUrl = "https://github.com/elastic/elasticsearch/issues/33621" )
8184 public void testValidMonthNamesWithNonUTCTimeZone () {
85+ assumeJava9PlusAndCompatLocaleProviderSetting ();
8286 NamedDateTimeProcessor proc = new NamedDateTimeProcessor (NameExtractor .MONTH_NAME , TimeZone .getTimeZone ("GMT-3:00" ));
8387 assertEquals ("December" , proc .process ("0" ));
8488 assertEquals ("August" , proc .process ("-64165813612338" )); // GMT: Tuesday, September 1, -0064 2:53:07.662 AM
@@ -90,4 +94,23 @@ public void testValidMonthNamesWithNonUTCTimeZone() {
9094 assertEquals ("July" , proc .process (new DateTime (10902 , 8 , 1 , 2 , 59 , DateTimeZone .UTC )));
9195 assertEquals ("August" , proc .process (new DateTime (10902 , 8 , 1 , 3 , 00 , DateTimeZone .UTC )));
9296 }
97+
98+ /*
99+ * This method checks the existence of a jvm parameter that should exist in ES jvm.options for Java 9+. If the parameter is
100+ * missing, the tests will be skipped. Not doing this, the tests will fail because the day and month names will be in the narrow
101+ * format (Mon, Tue, Jan, Feb etc) instead of full format (Monday, Tuesday, January, February etc).
102+ *
103+ * Related infra issue: https://github.com/elastic/elasticsearch/issues/33796
104+ */
105+ private void assumeJava9PlusAndCompatLocaleProviderSetting () {
106+ // at least Java 9
107+ if (JavaVersion .current ().compareTo (JavaVersion .parse ("9" )) < 0 ) {
108+ return ;
109+ }
110+ String beforeJava9CompatibleLocale = System .getProperty ("java.locale.providers" );
111+ // and COMPAT setting needs to be first on the list
112+ boolean isBeforeJava9Compatible = beforeJava9CompatibleLocale != null
113+ && Strings .tokenizeToStringArray (beforeJava9CompatibleLocale , "," )[0 ].equals ("COMPAT" );
114+ Assume .assumeTrue (isBeforeJava9Compatible );
115+ }
93116}
0 commit comments