Skip to content
This repository has been archived by the owner on Dec 9, 2022. It is now read-only.

Commit

Permalink
Change JVM time zone in tests to better test corner cases
Browse files Browse the repository at this point in the history
See prestodb#10078 for discussion.
  • Loading branch information
findepi committed Jun 29, 2018
1 parent 729d01a commit 7718da3
Show file tree
Hide file tree
Showing 11 changed files with 23 additions and 33 deletions.
10 changes: 8 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,14 @@
<dep.testng.version>6.10</dep.testng.version>
<dep.assertj-core.version>3.8.0</dep.assertj-core.version>

<!-- use a fractional hour timezone offset for tests -->
<air.test.timezone>Asia/Katmandu</air.test.timezone>
<!--
America/Bahia_Banderas has:
- offset change since 1970 (offset Jan 1970: -08:00, offset Jan 2018: -06:00)
- DST (e.g. at 2017-04-02 02:00:00 clocks turned forward 1 hour; 2017-10-29 02:00:00 clocks turned backward 1 hour)
- has forward offset change on first day of epoch (1970-01-01 00:00:00 clocks turned forward 1 hour)
- had forward change at midnight (1970-01-01 00:00:00 clocks turned forward 1 hour)
-->
<air.test.timezone>America/Bahia_Banderas</air.test.timezone>
<air.test.parallel>methods</air.test.parallel>
<air.test.thread-count>2</air.test.thread-count>
<air.test.jvmsize>2g</air.test.jvmsize>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ private HiveQueryRunner()
public static final String HIVE_BUCKETED_CATALOG = "hive_bucketed";
public static final String TPCH_SCHEMA = "tpch";
private static final String TPCH_BUCKETED_SCHEMA = "tpch_bucketed";
private static final DateTimeZone TIME_ZONE = DateTimeZone.forID("Asia/Kathmandu");
private static final DateTimeZone TIME_ZONE = DateTimeZone.forID("America/Bahia_Banderas");

public static DistributedQueryRunner createQueryRunner(TpchTable<?>... tables)
throws Exception
Expand All @@ -77,7 +77,7 @@ public static DistributedQueryRunner createQueryRunner(Iterable<TpchTable<?>> ta
public static DistributedQueryRunner createQueryRunner(Iterable<TpchTable<?>> tables, Map<String, String> extraProperties, String security, Map<String, String> extraHiveProperties)
throws Exception
{
assertEquals(DateTimeZone.getDefault(), TIME_ZONE, "Timezone not configured correctly. Add -Duser.timezone=Asia/Katmandu to your JVM arguments");
assertEquals(DateTimeZone.getDefault(), TIME_ZONE, "Timezone not configured correctly. Add -Duser.timezone=America/Bahia_Banderas to your JVM arguments");

DistributedQueryRunner queryRunner = new DistributedQueryRunner(createSession(), 4, extraProperties);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public class TestHiveFileFormats
private static TestingConnectorSession parquetPageSourceSession = new TestingConnectorSession(new HiveSessionProperties(new HiveClientConfig().setParquetOptimizedReaderEnabled(true).setParquetPredicatePushdownEnabled(false), new OrcFileWriterConfig()).getSessionProperties());
private static TestingConnectorSession parquetPageSourcePushdown = new TestingConnectorSession(new HiveSessionProperties(new HiveClientConfig().setParquetOptimizedReaderEnabled(true).setParquetPredicatePushdownEnabled(true), new OrcFileWriterConfig()).getSessionProperties());

private static final DateTimeZone HIVE_STORAGE_TIME_ZONE = DateTimeZone.forID("Asia/Katmandu");
private static final DateTimeZone HIVE_STORAGE_TIME_ZONE = DateTimeZone.forID("America/Bahia_Banderas");

@DataProvider(name = "rowCount")
public static Object[][] rowCountProvider()
Expand All @@ -119,8 +119,8 @@ public void setUp()
{
// ensure the expected timezone is configured for this VM
assertEquals(TimeZone.getDefault().getID(),
"Asia/Katmandu",
"Timezone not configured correctly. Add -Duser.timezone=Asia/Katmandu to your JVM arguments");
"America/Bahia_Banderas",
"Timezone not configured correctly. Add -Duser.timezone=America/Bahia_Banderas to your JVM arguments");
}

@Test(dataProvider = "rowCount")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@

public class ParquetTester
{
public static final DateTimeZone HIVE_STORAGE_TIME_ZONE = DateTimeZone.forID("Asia/Katmandu");
public static final DateTimeZone HIVE_STORAGE_TIME_ZONE = DateTimeZone.forID("America/Bahia_Banderas");
private static final boolean OPTIMIZED = true;
private static final HiveClientConfig HIVE_CLIENT_CONFIG = getHiveClientConfig();
private static final HdfsEnvironment HDFS_ENVIRONMENT = createTestHdfsEnvironment(HIVE_CLIENT_CONFIG);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,9 @@ public void testObjectTypes()
});

checkRepresentation("TIME '09:39:07 +01:00'", Types.TIME /* TODO TIME_WITH_TIMEZONE */, (rs, column) -> {
assertEquals(rs.getObject(column), Time.valueOf(LocalTime.of(14, 9, 7))); // TODO this should represent TIME '09:39:07 +01:00'
assertEquals(rs.getObject(column), Time.valueOf(LocalTime.of(1, 39, 7))); // TODO this should represent TIME '09:39:07 +01:00'
assertThrows(() -> rs.getDate(column));
assertEquals(rs.getTime(column), Time.valueOf(LocalTime.of(14, 9, 7))); // TODO this should fail, or represent TIME '09:39:07 +01:00'
assertEquals(rs.getTime(column), Time.valueOf(LocalTime.of(1, 39, 7))); // TODO this should fail, or represent TIME '09:39:07 +01:00'
assertThrows(() -> rs.getTimestamp(column));
});

Expand All @@ -146,10 +146,10 @@ public void testObjectTypes()
});

checkRepresentation("TIMESTAMP '2018-02-13 13:14:15.227 Europe/Warsaw'", Types.TIMESTAMP /* TODO TIMESTAMP_WITH_TIMEZONE */, (rs, column) -> {
assertEquals(rs.getObject(column), Timestamp.valueOf(LocalDateTime.of(2018, 2, 13, 17, 59, 15, 227_000_000))); // TODO this should represent TIMESTAMP '2018-02-13 13:14:15.227 Europe/Warsaw'
assertEquals(rs.getObject(column), Timestamp.valueOf(LocalDateTime.of(2018, 2, 13, 6, 14, 15, 227_000_000))); // TODO this should represent TIMESTAMP '2018-02-13 13:14:15.227 Europe/Warsaw'
assertThrows(() -> rs.getDate(column));
assertThrows(() -> rs.getTime(column));
assertEquals(rs.getTimestamp(column), Timestamp.valueOf(LocalDateTime.of(2018, 2, 13, 17, 59, 15, 227_000_000))); // TODO this should fail or represent TIMESTAMP '2018-02-13 13:14:15.227 Europe/Warsaw'
assertEquals(rs.getTimestamp(column), Timestamp.valueOf(LocalDateTime.of(2018, 2, 13, 6, 14, 15, 227_000_000))); // TODO this should fail or represent TIMESTAMP '2018-02-13 13:14:15.227 Europe/Warsaw'
});
}

Expand Down
8 changes: 0 additions & 8 deletions presto-mysql/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,6 @@

<properties>
<air.main.basedir>${project.parent.basedir}</air.main.basedir>
<!--
America/Bahia_Banderas has:
- offset change since 1970 (offset Jan 1970: -08:00, offset Jan 2018: -06:00)
- DST (e.g. in July 2018)
- has changed offset on first day of epoch (Thursday, 1 January 1970, 00:00:00 clocks were turned forward 1 hour)
- had forward change at midnight (Thursday, 1 January 1970, 00:00:00 clocks were turned forward 1 hour)
-->
<air.test.timezone>America/Bahia_Banderas</air.test.timezone>
</properties>

<dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@
public class OrcTester
{
public static final DataSize MAX_BLOCK_SIZE = new DataSize(1, Unit.MEGABYTE);
public static final DateTimeZone HIVE_STORAGE_TIME_ZONE = DateTimeZone.forID("Asia/Katmandu");
public static final DateTimeZone HIVE_STORAGE_TIME_ZONE = DateTimeZone.forID("America/Bahia_Banderas");

private static final TypeManager TYPE_MANAGER = new TypeRegistry();

Expand Down
8 changes: 0 additions & 8 deletions presto-postgresql/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,6 @@

<properties>
<air.main.basedir>${project.parent.basedir}</air.main.basedir>
<!--
America/Bahia_Banderas has:
- offset change since 1970 (offset Jan 1970: -08:00, offset Jan 2018: -06:00)
- DST (e.g. in July 2018)
- has changed offset on first day of epoch (Thursday, 1 January 1970, 00:00:00 clocks were turned forward 1 hour)
- had forward change at midnight (Thursday, 1 January 1970, 00:00:00 clocks were turned forward 1 hour)
-->
<air.test.timezone>America/Bahia_Banderas</air.test.timezone>
</properties>

<dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ public class RcFileTester
HadoopNative.requireHadoopNative();
}

public static final DateTimeZone HIVE_STORAGE_TIME_ZONE = DateTimeZone.forID("Asia/Katmandu");
public static final DateTimeZone HIVE_STORAGE_TIME_ZONE = DateTimeZone.forID("America/Bahia_Banderas");

public enum Format
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,14 @@ public void testTimeLiterals()
@Test
public void testLocallyUnrepresentableTimeLiterals()
{
LocalDateTime localTimeThatDidNotExist = LocalDateTime.of(1986, 1, 1, 0, 10);
LocalDateTime localTimeThatDidNotExist = LocalDateTime.of(2017, 4, 2, 2, 10);
checkState(ZoneId.systemDefault().getRules().getValidOffsets(localTimeThatDidNotExist).isEmpty(), "This test assumes certain JVM time zone");
// This tests that both Presto runner and H2 can return TIMESTAMP value that never happened in JVM's zone (e.g. is not representable using java.sql.Timestamp)
@Language("SQL") String sql = DateTimeFormatter.ofPattern("'SELECT TIMESTAMP '''uuuu-MM-dd HH:mm:ss''").format(localTimeThatDidNotExist);
assertEquals(computeScalar(sql), localTimeThatDidNotExist); // this tests Presto and the QueryRunner
assertQuery(sql); // this tests H2QueryRunner

LocalDate localDateThatDidNotHaveMidnight = LocalDate.of(1986, 1, 1);
LocalDate localDateThatDidNotHaveMidnight = LocalDate.of(1970, 1, 1);
checkState(ZoneId.systemDefault().getRules().getValidOffsets(localDateThatDidNotHaveMidnight.atStartOfDay()).isEmpty(), "This test assumes certain JVM time zone");
// This tests that both Presto runner and H2 can return DATE value for a day which midnight never happened in JVM's zone (e.g. is not exactly representable using java.sql.Date)
sql = DateTimeFormatter.ofPattern("'SELECT DATE '''uuuu-MM-dd''").format(localDateThatDidNotHaveMidnight);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public void testDateToTimestampCoercion()
assertEquals(rows.getOnlyValue(), LocalDate.of(2018, 1, 13).atStartOfDay());

// date, which midnight was skipped in JVM zone
LocalDate forwardOffsetChangeAtMidnightInJvmZone = LocalDate.of(1986, 1, 1);
LocalDate forwardOffsetChangeAtMidnightInJvmZone = LocalDate.of(1970, 1, 1);
checkState(ZoneId.systemDefault().getRules().getValidOffsets(forwardOffsetChangeAtMidnightInJvmZone.atStartOfDay()).size() == 0, "This test assumes certain JVM time zone");
rows = h2QueryRunner.execute(TEST_SESSION, DateTimeFormatter.ofPattern("'SELECT DATE '''uuuu-MM-dd''").format(forwardOffsetChangeAtMidnightInJvmZone), ImmutableList.of(TIMESTAMP));
assertEquals(rows.getOnlyValue(), forwardOffsetChangeAtMidnightInJvmZone.atStartOfDay());
Expand Down

0 comments on commit 7718da3

Please sign in to comment.