Skip to content

Commit

Permalink
[ML] Mute test failing due to Java 11 date time format parsing bug (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
davidkyle committed Jul 11, 2018
1 parent dadf96a commit d268b49
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,8 @@ public void setTimeFormat(String format) {
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ public static TimestampConverter ofPattern(String pattern, ZoneId defaultTimezon
.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);
Expand All @@ -67,7 +67,7 @@ public static TimestampConverter ofPattern(String pattern, ZoneId defaultTimezon
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);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
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;
Expand Down Expand Up @@ -51,8 +53,12 @@ public void testVerify_GivenValidFormat() {
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() {
Expand All @@ -68,6 +74,10 @@ public void testVerify_GivenInValidFormat() {
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() {
Expand Down

0 comments on commit d268b49

Please sign in to comment.