Skip to content

Commit

Permalink
Ensure that localised dates can really be parsed by the mapper we got
Browse files Browse the repository at this point in the history
  • Loading branch information
DaveCTurner committed Dec 4, 2020
1 parent d44afc0 commit 79ef7b0
Showing 1 changed file with 22 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,25 @@ public void testTimestampRangeRecalculatedOnStalePrimaryAllocation() throws IOEx
public void testTimestampFieldTypeExposedByAllIndicesServices() throws Exception {
internalCluster().startNodes(between(2, 4));

final String locale = randomFrom("", "en_GB", "fr_FR");
final String locale;
final String date;

switch (between(1, 3)) {
case 1:
locale = "";
date = "04 Feb 2020 12:01:23Z";
break;
case 2:
locale = "en_GB";
date = "04 Feb 2020 12:01:23Z";
break;
case 3:
locale = "fr_FR";
date = "04 févr. 2020 12:01:23Z";
break;
default:
throw new AssertionError("impossible");
}

assertAcked(prepareCreate("index")
.setSettings(Settings.builder()
Expand All @@ -114,7 +132,7 @@ public void testTimestampFieldTypeExposedByAllIndicesServices() throws Exception
.setMapping(jsonBuilder().startObject().startObject("_doc").startObject("properties")
.startObject(DataStream.TimestampField.FIXED_TIMESTAMP_FIELD)
.field("type", "date")
.field("format", "strict_date_hour_minute_second_fraction")
.field("format", "dd LLL yyyy HH:mm:ssX")
.field("locale", locale)
.endObject()
.endObject().endObject().endObject()));
Expand All @@ -124,7 +142,7 @@ public void testTimestampFieldTypeExposedByAllIndicesServices() throws Exception

ensureGreen("index");
if (randomBoolean()) {
client().prepareIndex("index").setSource(DataStream.TimestampField.FIXED_TIMESTAMP_FIELD, "2010-01-06T02:03:04.567").get();
client().prepareIndex("index").setSource(DataStream.TimestampField.FIXED_TIMESTAMP_FIELD, date).get();
}

for (final IndicesService indicesService : internalCluster().getInstances(IndicesService.class)) {
Expand All @@ -142,6 +160,7 @@ public void testTimestampFieldTypeExposedByAllIndicesServices() throws Exception
});
assertTrue(timestampFieldTypeFuture.isDone());
assertThat(timestampFieldTypeFuture.get().dateTimeFormatter().locale().toString(), equalTo(locale));
assertThat(timestampFieldTypeFuture.get().dateTimeFormatter().parseMillis(date), equalTo(1580817683000L));
}

assertAcked(client().execute(FreezeIndexAction.INSTANCE, new FreezeRequest("index").setFreeze(false)).actionGet());
Expand Down

0 comments on commit 79ef7b0

Please sign in to comment.