Add note how to run locale sensitive unit test (#49491)

Some unit test checking locale sensitive functionality require the
-Djava.locale.providers=SPI,COMPAT flag to be set. When running tests though
gradle we pass this already to the BuildPlugin, but running from the IDE this
might need to be set manually. Adding a note explaining this to the
CONTRIBUTING.md doc and leaving a note in the test comment of
SearchQueryIT.testRangeQueryWithLocaleMapping which is a test we know
that suffers from this issue.
This commit is contained in:
Christoph Büscher 2019-12-02 11:21:34 +01:00
parent d363b6b8ae
commit 04ace7a6da
2 changed files with 14 additions and 0 deletions

View File

@ -153,6 +153,10 @@ For IntelliJ, go to
For Eclipse, go to `Preferences->Java->Installed JREs` and add `-ea` to
`VM Arguments`.
Some tests related to locale testing also require the flag
`-Djava.locale.providers` to be set. Set the VM options/VM arguments for
IntelliJ or Eclipse like describe above to use
`-Djava.locale.providers=SPI,COMPAT`.
### Java Language Formatting Guidelines

View File

@ -1668,8 +1668,18 @@ public class SearchQueryIT extends ESIntegTestCase {
assertThat(searchResponse.getHits().getAt(0).getId(), is("4"));
}
/**
* Test range with a custom locale, e.g. "de" in this case. Documents here mention the day of week
* as "Mi" for "Mittwoch (Wednesday" and "Do" for "Donnerstag (Thursday)" and the month in the query
* as "Dez" for "Dezember (December)".
* Note: this test currently needs the JVM arg `-Djava.locale.providers=SPI,COMPAT` to be set.
* When running with gradle this is done implicitly through the BuildPlugin, but when running from
* an IDE this might need to be set manually in the run configuration. See also CONTRIBUTING.md section
* 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(prepareCreate("test")
.addMapping("type1", jsonBuilder().startObject().startObject("properties").startObject("date_field")