Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not prefix already prefixed format with 8 #48139

Merged
merged 5 commits into from
Oct 17, 2019
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
2 changes: 2 additions & 0 deletions server/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ check.dependsOn(testScriptDocValuesMissingV7Behaviour)
unitTest {
// these are tested explicitly in separate test tasks
exclude '**/*ScriptDocValuesMissingV7BehaviourTests.class'
jvmArg '-Djava.locale.providers=COMPAT'

}

forbiddenPatterns {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class JavaDateFormatter implements DateFormatter {
throw new IllegalArgumentException("formatters must have the same locale");
}
this.printer = printer;
this.format = "8" + format;
this.format = format.startsWith("8") ? format : "8" + format;

if (parsers.length == 0) {
this.parsers = Collections.singletonList(printer);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import org.elasticsearch.test.ESIntegTestCase;
import org.elasticsearch.test.ESIntegTestCase.ClusterScope;
import org.elasticsearch.test.ESIntegTestCase.Scope;
import org.hamcrest.Matchers;

import java.util.HashMap;
import java.util.List;
Expand All @@ -56,8 +57,6 @@
import static org.hamcrest.Matchers.allOf;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.lessThanOrEqualTo;
import static org.hamcrest.core.IsNull.notNullValue;

Expand Down Expand Up @@ -385,21 +384,38 @@ public void testIndexNameInResponse() {
}

public void testCreateIndexWithJava8Date() throws Exception {
String jodaIncompatibleFormat = "8yyyy-MM-dd HH:mm:ssXX";
XContentBuilder builder = jsonBuilder().startObject().startObject("properties")
.startObject("time")
.field("type", "date")
.field("format", jodaIncompatibleFormat)
.endObject().endObject().endObject();

CreateIndexRequestBuilder requestBuilder = client().admin().indices().prepareCreate("test");
assertAcked(requestBuilder.addMapping("doc", builder).get());
BiFunction<XContentBuilder, String, List<Object>> createIndex = (xContentBuilder, propertyToBeReturned) -> {
String indexName = "test" + xContentBuilder.hashCode();
CreateIndexRequestBuilder requestBuilder = client().admin().indices().prepareCreate(indexName);
assertAcked(requestBuilder.addMapping("doc", xContentBuilder).get());

GetMappingsResponse response = client().admin().indices().prepareGetMappings(indexName).get();
List<Object> formats = XContentMapValues.extractRawValues(propertyToBeReturned, response
.getMappings()
.get(indexName)
.get("doc")
.getSourceAsMap());
return formats;
};

GetMappingsResponse response = client().admin().indices().prepareGetMappings("test").get();
List<Object> formats =
XContentMapValues.extractRawValues("properties.time.format", response.getMappings().get("test").get("doc").getSourceAsMap());
assertThat(formats, hasSize(1));
assertThat(formats.get(0), is(jodaIncompatibleFormat));
XContentBuilder builder = jsonBuilder().startObject().startObject("properties")
.startObject("time")
.field("type", "date")
.field("format", "8yyyy-MM-dd-MM-dd HH:mm:ssXX")
.endObject()
.endObject().endObject();

assertThat(createIndex.apply(builder, "properties.time.format"), Matchers.contains("8yyyy-MM-dd-MM-dd HH:mm:ssXX"));


builder = jsonBuilder().startObject().startObject("properties")
.startObject("time")
.field("type", "date")
.field("format", "8yyyy-MM-dd-MM-dd HH:mm:ssXX")
.field("locale", "de")
.endObject()
.endObject().endObject();
assertThat(createIndex.apply(builder, "properties.time.locale"), Matchers.contains("de"));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,18 @@ public void testFloatEpochFormat() throws IOException {
assertEquals(epochMillis, pointField.numericValue().longValue());
}

public void testChangeLocaleWith8Prefix() throws IOException {
String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type")
.startObject("properties").startObject("field").field("type", "date")
.field("format", "8E, d MMM uuuu HH:mm:ss Z")
.field("locale", "de")
.endObject().endObject().endObject().endObject());

DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping));

assertEquals(mapping, mapper.mappingSource().toString());
}

public void testChangeLocale() throws IOException {
String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type")
.startObject("properties").startObject("field").field("type", "date").field("locale", "fr").endObject().endObject()
Expand Down