5
5
*/
6
6
package org .elasticsearch .xpack .sql .expression .function .scalar .datetime ;
7
7
8
+ import org .elasticsearch .bootstrap .JavaVersion ;
9
+ import org .elasticsearch .common .Strings ;
8
10
import org .elasticsearch .common .io .stream .Writeable .Reader ;
9
11
import org .elasticsearch .test .AbstractWireSerializingTestCase ;
10
12
import org .elasticsearch .xpack .sql .expression .function .scalar .datetime .NamedDateTimeProcessor .NameExtractor ;
11
13
import org .joda .time .DateTime ;
12
14
import org .joda .time .DateTimeZone ;
15
+ import org .junit .Assume ;
13
16
14
17
import java .io .IOException ;
15
18
import java .util .TimeZone ;
16
19
17
20
public class NamedDateTimeProcessorTests extends AbstractWireSerializingTestCase <NamedDateTimeProcessor > {
21
+
18
22
private static final TimeZone UTC = TimeZone .getTimeZone ("UTC" );
19
23
20
24
public static NamedDateTimeProcessor randomNamedDateTimeProcessor () {
@@ -37,21 +41,21 @@ protected NamedDateTimeProcessor mutateInstance(NamedDateTimeProcessor instance)
37
41
return new NamedDateTimeProcessor (replaced , UTC );
38
42
}
39
43
40
- @ AwaitsFix (bugUrl = "https://github.com/elastic/elasticsearch/issues/33621" )
41
44
public void testValidDayNamesInUTC () {
45
+ assumeJava9PlusAndCompatLocaleProviderSetting ();
42
46
NamedDateTimeProcessor proc = new NamedDateTimeProcessor (NameExtractor .DAY_NAME , UTC );
43
47
assertEquals ("Thursday" , proc .process ("0" ));
44
48
assertEquals ("Saturday" , proc .process ("-64164233612338" ));
45
49
assertEquals ("Monday" , proc .process ("64164233612338" ));
46
-
50
+
47
51
assertEquals ("Thursday" , proc .process (new DateTime (0L , DateTimeZone .UTC )));
48
52
assertEquals ("Thursday" , proc .process (new DateTime (-5400 , 12 , 25 , 2 , 0 , DateTimeZone .UTC )));
49
53
assertEquals ("Friday" , proc .process (new DateTime (30 , 2 , 1 , 12 , 13 , DateTimeZone .UTC )));
50
54
assertEquals ("Tuesday" , proc .process (new DateTime (10902 , 8 , 22 , 11 , 11 , DateTimeZone .UTC )));
51
55
}
52
56
53
- @ AwaitsFix (bugUrl = "https://github.com/elastic/elasticsearch/issues/33621" )
54
57
public void testValidDayNamesWithNonUTCTimeZone () {
58
+ assumeJava9PlusAndCompatLocaleProviderSetting ();
55
59
NamedDateTimeProcessor proc = new NamedDateTimeProcessor (NameExtractor .DAY_NAME , TimeZone .getTimeZone ("GMT-10:00" ));
56
60
assertEquals ("Wednesday" , proc .process ("0" ));
57
61
assertEquals ("Friday" , proc .process ("-64164233612338" ));
@@ -64,9 +68,9 @@ public void testValidDayNamesWithNonUTCTimeZone() {
64
68
assertEquals ("Monday" , proc .process (new DateTime (10902 , 8 , 22 , 9 , 59 , DateTimeZone .UTC )));
65
69
}
66
70
67
- @ AwaitsFix (bugUrl = "https://github.com/elastic/elasticsearch/issues/33621" )
68
71
public void testValidMonthNamesInUTC () {
69
- NamedDateTimeProcessor proc = new NamedDateTimeProcessor (NameExtractor .MONTH_NAME , UTC );
72
+ assumeJava9PlusAndCompatLocaleProviderSetting ();
73
+ NamedDateTimeProcessor proc = new NamedDateTimeProcessor (NameExtractor .MONTH_NAME , UTC );
70
74
assertEquals ("January" , proc .process ("0" ));
71
75
assertEquals ("September" , proc .process ("-64164233612338" ));
72
76
assertEquals ("April" , proc .process ("64164233612338" ));
@@ -76,9 +80,9 @@ public void testValidMonthNamesInUTC() {
76
80
assertEquals ("February" , proc .process (new DateTime (30 , 2 , 1 , 12 , 13 , DateTimeZone .UTC )));
77
81
assertEquals ("August" , proc .process (new DateTime (10902 , 8 , 22 , 11 , 11 , DateTimeZone .UTC )));
78
82
}
79
-
80
- @ AwaitsFix (bugUrl = "https://github.com/elastic/elasticsearch/issues/33621" )
83
+
81
84
public void testValidMonthNamesWithNonUTCTimeZone () {
85
+ assumeJava9PlusAndCompatLocaleProviderSetting ();
82
86
NamedDateTimeProcessor proc = new NamedDateTimeProcessor (NameExtractor .MONTH_NAME , TimeZone .getTimeZone ("GMT-3:00" ));
83
87
assertEquals ("December" , proc .process ("0" ));
84
88
assertEquals ("August" , proc .process ("-64165813612338" )); // GMT: Tuesday, September 1, -0064 2:53:07.662 AM
@@ -90,4 +94,23 @@ public void testValidMonthNamesWithNonUTCTimeZone() {
90
94
assertEquals ("July" , proc .process (new DateTime (10902 , 8 , 1 , 2 , 59 , DateTimeZone .UTC )));
91
95
assertEquals ("August" , proc .process (new DateTime (10902 , 8 , 1 , 3 , 00 , DateTimeZone .UTC )));
92
96
}
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
+ }
93
116
}
0 commit comments