SQL: day and month name functions tests locale providers enforcement (#33653)
DAYNAME and MONTHNAME functions tests will be skipped if the right JVM parameter (-Djava.locale.providers=COMPAT) is not used in unit testing environment
This commit is contained in:
parent
0cf0d73813
commit
c6e3231ef3
|
@ -5,16 +5,20 @@
|
||||||
*/
|
*/
|
||||||
package org.elasticsearch.xpack.sql.expression.function.scalar.datetime;
|
package org.elasticsearch.xpack.sql.expression.function.scalar.datetime;
|
||||||
|
|
||||||
|
import org.elasticsearch.bootstrap.JavaVersion;
|
||||||
|
import org.elasticsearch.common.Strings;
|
||||||
import org.elasticsearch.common.io.stream.Writeable.Reader;
|
import org.elasticsearch.common.io.stream.Writeable.Reader;
|
||||||
import org.elasticsearch.test.AbstractWireSerializingTestCase;
|
import org.elasticsearch.test.AbstractWireSerializingTestCase;
|
||||||
import org.elasticsearch.xpack.sql.expression.function.scalar.datetime.NamedDateTimeProcessor.NameExtractor;
|
import org.elasticsearch.xpack.sql.expression.function.scalar.datetime.NamedDateTimeProcessor.NameExtractor;
|
||||||
import org.joda.time.DateTime;
|
import org.joda.time.DateTime;
|
||||||
import org.joda.time.DateTimeZone;
|
import org.joda.time.DateTimeZone;
|
||||||
|
import org.junit.Assume;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.TimeZone;
|
import java.util.TimeZone;
|
||||||
|
|
||||||
public class NamedDateTimeProcessorTests extends AbstractWireSerializingTestCase<NamedDateTimeProcessor> {
|
public class NamedDateTimeProcessorTests extends AbstractWireSerializingTestCase<NamedDateTimeProcessor> {
|
||||||
|
|
||||||
private static final TimeZone UTC = TimeZone.getTimeZone("UTC");
|
private static final TimeZone UTC = TimeZone.getTimeZone("UTC");
|
||||||
|
|
||||||
public static NamedDateTimeProcessor randomNamedDateTimeProcessor() {
|
public static NamedDateTimeProcessor randomNamedDateTimeProcessor() {
|
||||||
|
@ -37,8 +41,8 @@ public class NamedDateTimeProcessorTests extends AbstractWireSerializingTestCase
|
||||||
return new NamedDateTimeProcessor(replaced, UTC);
|
return new NamedDateTimeProcessor(replaced, UTC);
|
||||||
}
|
}
|
||||||
|
|
||||||
@AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/33621")
|
|
||||||
public void testValidDayNamesInUTC() {
|
public void testValidDayNamesInUTC() {
|
||||||
|
assumeJava9PlusAndCompatLocaleProviderSetting();
|
||||||
NamedDateTimeProcessor proc = new NamedDateTimeProcessor(NameExtractor.DAY_NAME, UTC);
|
NamedDateTimeProcessor proc = new NamedDateTimeProcessor(NameExtractor.DAY_NAME, UTC);
|
||||||
assertEquals("Thursday", proc.process("0"));
|
assertEquals("Thursday", proc.process("0"));
|
||||||
assertEquals("Saturday", proc.process("-64164233612338"));
|
assertEquals("Saturday", proc.process("-64164233612338"));
|
||||||
|
@ -50,8 +54,8 @@ public class NamedDateTimeProcessorTests extends AbstractWireSerializingTestCase
|
||||||
assertEquals("Tuesday", proc.process(new DateTime(10902, 8, 22, 11, 11, DateTimeZone.UTC)));
|
assertEquals("Tuesday", proc.process(new DateTime(10902, 8, 22, 11, 11, DateTimeZone.UTC)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/33621")
|
|
||||||
public void testValidDayNamesWithNonUTCTimeZone() {
|
public void testValidDayNamesWithNonUTCTimeZone() {
|
||||||
|
assumeJava9PlusAndCompatLocaleProviderSetting();
|
||||||
NamedDateTimeProcessor proc = new NamedDateTimeProcessor(NameExtractor.DAY_NAME, TimeZone.getTimeZone("GMT-10:00"));
|
NamedDateTimeProcessor proc = new NamedDateTimeProcessor(NameExtractor.DAY_NAME, TimeZone.getTimeZone("GMT-10:00"));
|
||||||
assertEquals("Wednesday", proc.process("0"));
|
assertEquals("Wednesday", proc.process("0"));
|
||||||
assertEquals("Friday", proc.process("-64164233612338"));
|
assertEquals("Friday", proc.process("-64164233612338"));
|
||||||
|
@ -64,8 +68,8 @@ public class NamedDateTimeProcessorTests extends AbstractWireSerializingTestCase
|
||||||
assertEquals("Monday", proc.process(new DateTime(10902, 8, 22, 9, 59, DateTimeZone.UTC)));
|
assertEquals("Monday", proc.process(new DateTime(10902, 8, 22, 9, 59, DateTimeZone.UTC)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/33621")
|
|
||||||
public void testValidMonthNamesInUTC() {
|
public void testValidMonthNamesInUTC() {
|
||||||
|
assumeJava9PlusAndCompatLocaleProviderSetting();
|
||||||
NamedDateTimeProcessor proc = new NamedDateTimeProcessor(NameExtractor.MONTH_NAME, UTC);
|
NamedDateTimeProcessor proc = new NamedDateTimeProcessor(NameExtractor.MONTH_NAME, UTC);
|
||||||
assertEquals("January", proc.process("0"));
|
assertEquals("January", proc.process("0"));
|
||||||
assertEquals("September", proc.process("-64164233612338"));
|
assertEquals("September", proc.process("-64164233612338"));
|
||||||
|
@ -77,8 +81,8 @@ public class NamedDateTimeProcessorTests extends AbstractWireSerializingTestCase
|
||||||
assertEquals("August", proc.process(new DateTime(10902, 8, 22, 11, 11, DateTimeZone.UTC)));
|
assertEquals("August", proc.process(new DateTime(10902, 8, 22, 11, 11, DateTimeZone.UTC)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/33621")
|
|
||||||
public void testValidMonthNamesWithNonUTCTimeZone() {
|
public void testValidMonthNamesWithNonUTCTimeZone() {
|
||||||
|
assumeJava9PlusAndCompatLocaleProviderSetting();
|
||||||
NamedDateTimeProcessor proc = new NamedDateTimeProcessor(NameExtractor.MONTH_NAME, TimeZone.getTimeZone("GMT-3:00"));
|
NamedDateTimeProcessor proc = new NamedDateTimeProcessor(NameExtractor.MONTH_NAME, TimeZone.getTimeZone("GMT-3:00"));
|
||||||
assertEquals("December", proc.process("0"));
|
assertEquals("December", proc.process("0"));
|
||||||
assertEquals("August", proc.process("-64165813612338")); // GMT: Tuesday, September 1, -0064 2:53:07.662 AM
|
assertEquals("August", proc.process("-64165813612338")); // GMT: Tuesday, September 1, -0064 2:53:07.662 AM
|
||||||
|
@ -90,4 +94,23 @@ public class NamedDateTimeProcessorTests extends AbstractWireSerializingTestCase
|
||||||
assertEquals("July", proc.process(new DateTime(10902, 8, 1, 2, 59, DateTimeZone.UTC)));
|
assertEquals("July", proc.process(new DateTime(10902, 8, 1, 2, 59, DateTimeZone.UTC)));
|
||||||
assertEquals("August", proc.process(new DateTime(10902, 8, 1, 3, 00, DateTimeZone.UTC)));
|
assertEquals("August", proc.process(new DateTime(10902, 8, 1, 3, 00, DateTimeZone.UTC)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This method checks the existence of a jvm parameter that should exist in ES jvm.options for Java 9+. If the parameter is
|
||||||
|
* missing, the tests will be skipped. Not doing this, the tests will fail because the day and month names will be in the narrow
|
||||||
|
* format (Mon, Tue, Jan, Feb etc) instead of full format (Monday, Tuesday, January, February etc).
|
||||||
|
*
|
||||||
|
* Related infra issue: https://github.com/elastic/elasticsearch/issues/33796
|
||||||
|
*/
|
||||||
|
private void assumeJava9PlusAndCompatLocaleProviderSetting() {
|
||||||
|
// at least Java 9
|
||||||
|
if (JavaVersion.current().compareTo(JavaVersion.parse("9")) < 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
String beforeJava9CompatibleLocale = System.getProperty("java.locale.providers");
|
||||||
|
// and COMPAT setting needs to be first on the list
|
||||||
|
boolean isBeforeJava9Compatible = beforeJava9CompatibleLocale != null
|
||||||
|
&& Strings.tokenizeToStringArray(beforeJava9CompatibleLocale, ",")[0].equals("COMPAT");
|
||||||
|
Assume.assumeTrue(isBeforeJava9Compatible);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue