提交 d605b46f authored 作者: Noel Grandin's avatar Noel Grandin 提交者: GitHub

Merge pull request #366 from reftel/feature/test_time

Tests for timestamps
......@@ -113,6 +113,9 @@ public class TestFunctions extends TestBase implements AggregateFunction {
testTranslate();
testGenerateSeries();
testFileWrite();
testThatCurrentTimestampIsSane();
testThatCurrentTimestampStaysTheSameWithinATransaction();
testThatCurrentTimestampUpdatesOutsideATransaction();
testAnnotationProcessorsOutput();
deleteDb("functions");
......@@ -2002,6 +2005,77 @@ public class TestFunctions extends TestBase implements AggregateFunction {
}
}
private void testThatCurrentTimestampIsSane() throws SQLException, InterruptedException, ParseException {
deleteDb("functions");
Date before = new Date();
Connection conn = getConnection("functions");
conn.setAutoCommit(false);
Statement stat = conn.createStatement();
final String formatted;
try (final ResultSet rs = stat.executeQuery("select to_char(current_timestamp(9), 'YYYY MM DD HH24 MI SS FF3') from dual")) {
rs.next();
formatted = rs.getString(1);
}
Date after = new Date();
Date parsed = new SimpleDateFormat("y M d H m s S").parse(formatted);
assertFalse(parsed.before(before));
assertFalse(parsed.after(after));
}
private void testThatCurrentTimestampStaysTheSameWithinATransaction() throws SQLException, InterruptedException {
deleteDb("functions");
Connection conn = getConnection("functions");
conn.setAutoCommit(false);
Statement stat = conn.createStatement();
final Timestamp first;
try (final ResultSet rs = stat.executeQuery("select CURRENT_TIMESTAMP from DUAL")) {
rs.next();
first = rs.getTimestamp(1);
}
Thread.sleep(1);
final Timestamp second;
try (final ResultSet rs = stat.executeQuery("select CURRENT_TIMESTAMP from DUAL")) {
rs.next();
second = rs.getTimestamp(1);
}
assertEquals(first, second);
}
private void testThatCurrentTimestampUpdatesOutsideATransaction() throws SQLException, InterruptedException {
deleteDb("functions");
Connection conn = getConnection("functions");
conn.setAutoCommit(true);
Statement stat = conn.createStatement();
final Timestamp first;
try (final ResultSet rs = stat.executeQuery("select CURRENT_TIMESTAMP from DUAL")) {
rs.next();
first = rs.getTimestamp(1);
}
Thread.sleep(1);
final Timestamp second;
try (final ResultSet rs = stat.executeQuery("select CURRENT_TIMESTAMP from DUAL")) {
rs.next();
second = rs.getTimestamp(1);
}
assertTrue(second.after(first));
}
private void callCompiledFunction(String functionName) throws SQLException {
deleteDb("functions");
Connection conn = getConnection("functions");
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论