[ML] Mute test failing due to Java 11 date time format parsing bug (#31899)

This commit is contained in:
David Kyle 2018-07-11 10:17:44 +01:00 committed by GitHub
parent dadf96a840
commit d268b494d7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 6 deletions

View File

@ -353,7 +353,8 @@ public class DataDescription implements ToXContentObject, Writeable {
try {
DateTimeFormatterTimestampConverter.ofPattern(format, ZoneOffset.UTC);
} catch (IllegalArgumentException e) {
throw ExceptionsHelper.badRequestException(Messages.getMessage(Messages.JOB_CONFIG_INVALID_TIMEFORMAT, format));
throw ExceptionsHelper.badRequestException(
Messages.getMessage(Messages.JOB_CONFIG_INVALID_TIMEFORMAT, format), e.getCause());
}
}
timeFormat = format;

View File

@ -54,9 +54,9 @@ public class DateTimeFormatterTimestampConverter implements TimestampConverter {
.parseDefaulting(ChronoField.YEAR_OF_ERA, LocalDate.now(defaultTimezone).getYear())
.toFormatter();
String now = formatter.format(ZonedDateTime.ofInstant(Instant.ofEpochSecond(0), ZoneOffset.UTC));
String formattedTime = formatter.format(ZonedDateTime.ofInstant(Instant.ofEpochSecond(0), ZoneOffset.UTC));
try {
TemporalAccessor parsed = formatter.parse(now);
TemporalAccessor parsed = formatter.parse(formattedTime);
boolean hasTimeZone = parsed.isSupported(ChronoField.INSTANT_SECONDS);
if (hasTimeZone) {
Instant.from(parsed);
@ -67,7 +67,7 @@ public class DateTimeFormatterTimestampConverter implements TimestampConverter {
return new DateTimeFormatterTimestampConverter(formatter, hasTimeZone, defaultTimezone);
}
catch (DateTimeException e) {
throw new IllegalArgumentException("Timestamp cannot be derived from pattern: " + pattern);
throw new IllegalArgumentException("Timestamp cannot be derived from pattern: " + pattern, e);
}
}

View File

@ -17,6 +17,8 @@ import org.elasticsearch.test.AbstractSerializingTestCase;
import org.elasticsearch.xpack.core.ml.job.config.DataDescription.DataFormat;
import org.elasticsearch.xpack.core.ml.job.messages.Messages;
import java.time.DateTimeException;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.instanceOf;
@ -51,8 +53,12 @@ public class DataDescriptionTests extends AbstractSerializingTestCase<DataDescri
description.setTimeFormat("epoch");
description.setTimeFormat("epoch_ms");
description.setTimeFormat("yyyy-MM-dd HH");
String goodFormat = "yyyy.MM.dd G 'at' HH:mm:ss z";
description.setTimeFormat(goodFormat);
}
@AwaitsFix(bugUrl = "https://bugs.java.com/bugdatabase/view_bug.do?bug_id=JDK-8206980")
public void testVerify_GivenValidFormat_Java11Bug() {
DataDescription.Builder description = new DataDescription.Builder();
description.setTimeFormat("yyyy.MM.dd G 'at' HH:mm:ss z");
}
public void testVerify_GivenInValidFormat() {
@ -68,6 +74,10 @@ public class DataDescriptionTests extends AbstractSerializingTestCase<DataDescri
e = expectThrows(ElasticsearchException.class, () -> description.setTimeFormat("y-M-dd"));
assertEquals(Messages.getMessage(Messages.JOB_CONFIG_INVALID_TIMEFORMAT, "y-M-dd"), e.getMessage());
expectThrows(ElasticsearchException.class, () -> description.setTimeFormat("YYY-mm-UU hh:mm:ssY"));
Throwable cause = e.getCause();
assertNotNull(cause);
assertThat(cause, instanceOf(DateTimeException.class));
}
public void testTransform_GivenDelimitedAndEpoch() {