|
21 | 21 | import io.vertx.ext.sql.ResultSet; |
22 | 22 | import io.vertx.ext.unit.Async; |
23 | 23 | import io.vertx.ext.unit.TestContext; |
| 24 | +import java.time.Instant; |
24 | 25 | import org.junit.Before; |
25 | 26 | import org.junit.Test; |
26 | 27 |
|
@@ -128,4 +129,29 @@ public void testUpdatingNumericField(TestContext context) { |
128 | 129 | }); |
129 | 130 | } |
130 | 131 |
|
| 132 | + @Test |
| 133 | + public void testInstant(TestContext context) { |
| 134 | + Async async = context.async(); |
| 135 | + client.getConnection(ar -> { |
| 136 | + ensureSuccess(context, ar); |
| 137 | + conn = ar.result(); |
| 138 | + conn.execute("DROP TABLE IF EXISTS test_table", ar1 -> { |
| 139 | + ensureSuccess(context, ar1); |
| 140 | + conn.execute("CREATE TABLE test_table (instant TIMESTAMP)", ar2 -> { |
| 141 | + ensureSuccess(context, ar2); |
| 142 | + Instant now = Instant.now(); |
| 143 | + conn.queryWithParams("INSERT INTO test_table (instant) VALUES (?)", new JsonArray().add(now), ar3 -> { |
| 144 | + ensureSuccess(context, ar3); |
| 145 | + conn.query("SELECT instant FROM test_table", ar4 -> { |
| 146 | + ensureSuccess(context, ar4); |
| 147 | + // timestamps with out time zone are returned as strings, so we must compare to the original instant |
| 148 | + // ignoring the timezone offset (meaning ignore everything after char 23) |
| 149 | + context.assertEquals(ar4.result().getResults().get(0).getString(0), now.toString().substring(0, 23)); |
| 150 | + async.complete(); |
| 151 | + }); |
| 152 | + }); |
| 153 | + }); |
| 154 | + }); |
| 155 | + }); |
| 156 | + } |
131 | 157 | } |
0 commit comments