DBZ-7085 Fix default value handling in tests

This commit is contained in:
Chris Cranford 2023-11-08 09:22:33 -05:00 committed by Jiri Pechanec
parent 2bff852174
commit da9c2bfeb4

View File

@ -689,7 +689,7 @@ public void dateAndTimeTest() throws InterruptedException {
String value1 = "1970-01-01 00:00:01"; String value1 = "1970-01-01 00:00:01";
ZonedDateTime t = java.sql.Timestamp.valueOf(value1).toInstant().atZone(ZoneId.systemDefault()); ZonedDateTime t = java.sql.Timestamp.valueOf(value1).toInstant().atZone(ZoneId.systemDefault());
String isoString = ZonedTimestamp.toIsoString(t, ZoneId.systemDefault(), MySqlValueConverters::adjustTemporal, null); String isoString = getZonedDateTimeIsoString(t);
assertThat(schemaB.defaultValue()).isEqualTo(isoString); assertThat(schemaB.defaultValue()).isEqualTo(isoString);
String value2 = "2018-01-03 00:00:10"; String value2 = "2018-01-03 00:00:10";
@ -758,7 +758,7 @@ public void timeTypeWithConnectMode() throws Exception {
String value1 = "1970-01-01 00:00:01"; String value1 = "1970-01-01 00:00:01";
ZonedDateTime t = java.sql.Timestamp.valueOf(value1).toInstant().atZone(ZoneId.systemDefault()); ZonedDateTime t = java.sql.Timestamp.valueOf(value1).toInstant().atZone(ZoneId.systemDefault());
String isoString = ZonedTimestamp.toIsoString(t, ZoneId.systemDefault(), MySqlValueConverters::adjustTemporal, null); String isoString = getZonedDateTimeIsoString(t);
assertThat(schemaB.defaultValue()).isEqualTo(isoString); assertThat(schemaB.defaultValue()).isEqualTo(isoString);
LocalDateTime localDateTimeC = LocalDateTime.from(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss").parse("2018-01-03 00:00:10")); LocalDateTime localDateTimeC = LocalDateTime.from(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss").parse("2018-01-03 00:00:10"));
@ -1022,4 +1022,21 @@ private void assertFieldDefaultValue(Struct value, String fieldName, Object defa
assertThat(value.schema().field(fieldName).schema().defaultValue()).isEqualTo(defaultValue); assertThat(value.schema().field(fieldName).schema().defaultValue()).isEqualTo(defaultValue);
} }
private static String getZonedDateTimeIsoString(ZonedDateTime zdt) {
if (MySqlTestConnection.isMariaDb()) {
// MariaDB applies the time-zone shift to the SHOW CREATE TABLE response when generating
// the SQL for the default value resolution which MySQL does not. This is because MariaDB
// pushes the "timezone=auto" connection argument to the server level whereas the MySQL
// "connectionTimeZone" is managed at the driver level on data responses only. In this
// case, MariaDB's default value resolution will always account for the current host
// time-zone difference with the host-system's time-zone.
long serverOffsetSecs = UniqueDatabase.TIMEZONE.getRules().getOffset(zdt.toInstant()).getTotalSeconds();
long hostOffsetSecs = ZoneOffset.systemDefault().getRules().getOffset(zdt.toInstant()).getTotalSeconds();
long timeDelta = serverOffsetSecs - hostOffsetSecs;
zdt = zdt.minusSeconds(timeDelta);
return ZonedTimestamp.toIsoString(zdt, UniqueDatabase.TIMEZONE, MySqlValueConverters::adjustTemporal, null);
}
return ZonedTimestamp.toIsoString(zdt, ZoneId.systemDefault(), MySqlValueConverters::adjustTemporal, null);
}
} }