-
Notifications
You must be signed in to change notification settings - Fork 59
Fix date time and a bit refactoring #37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
14bb98b
testcase for psql query of a column with type 'timestamp with time zo…
augeneinblick b6d0d97
quickfix for selecting psql column type 'timezone without time zone'.
augeneinblick 91f0afe
test both timestamp types.
augeneinblick cf38c62
clean timestamp testtable after test.
augeneinblick fd8d731
Use vertx-unit and make code more consistent
McHunkyTrunk 3c7b243
Organize imports
McHunkyTrunk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,64 +18,83 @@ | |
|
|
||
| import io.vertx.core.json.JsonArray; | ||
| import io.vertx.core.json.JsonObject; | ||
| import io.vertx.test.core.VertxTestBase; | ||
| import io.vertx.ext.sql.ResultSet; | ||
| import io.vertx.ext.unit.Async; | ||
| import io.vertx.ext.unit.TestContext; | ||
| import org.junit.Before; | ||
| import org.junit.Test; | ||
|
|
||
| import java.util.concurrent.CountDownLatch; | ||
|
|
||
| /** | ||
| * @author <a href="http://www.campudus.com">Joern Bernhardt</a>. | ||
| */ | ||
| public class PostgreSQLTest extends VertxTestBase { | ||
|
|
||
| AsyncSQLClient asyncSqlClient; | ||
|
|
||
| final String address = "campudus.postgresql"; | ||
| public class PostgreSQLTest extends AbstractTestBase { | ||
|
|
||
| final JsonObject config = new JsonObject() | ||
| .put("host", System.getProperty("db.host", "localhost")) | ||
| .put("postgresql", new JsonObject().put("address", address)); | ||
| .put("host", System.getProperty("db.host", "localhost")); | ||
|
|
||
| @Override | ||
| public void setUp() throws Exception { | ||
| super.setUp(); | ||
| asyncSqlClient = PostgreSQLClient.createNonShared(vertx, config); | ||
| @Before | ||
| public void init() { | ||
| client = PostgreSQLClient.createNonShared(vertx, config); | ||
| } | ||
|
|
||
| @Override | ||
| public void tearDown() throws Exception { | ||
| CountDownLatch latch; | ||
| if (this.asyncSqlClient != null) { | ||
| latch = new CountDownLatch(1); | ||
| this.asyncSqlClient.close((ar) -> { | ||
| latch.countDown(); | ||
| @Test | ||
| public void someTest(TestContext context) throws Exception { | ||
| Async async = context.async(); | ||
| client.getConnection(connAr -> { | ||
| ensureSuccess(context, connAr); | ||
| conn = connAr.result(); | ||
| conn.query("SELECT 1 AS something", resultSetAr -> { | ||
| ensureSuccess(context, resultSetAr); | ||
| ResultSet resultSet = resultSetAr.result(); | ||
| context.assertNotNull(resultSet); | ||
| context.assertNotNull(resultSet.getColumnNames()); | ||
| context.assertNotNull(resultSet.getResults()); | ||
| context.assertEquals(new JsonArray().add(1), resultSet.getResults().get(0)); | ||
| async.complete(); | ||
| }); | ||
| this.awaitLatch(latch); | ||
| } | ||
|
|
||
| super.tearDown(); | ||
| }); | ||
| } | ||
|
|
||
| @Test | ||
| public void someTest() throws Exception { | ||
| asyncSqlClient.getConnection(onSuccess(conn -> { | ||
| conn.query("SELECT 1 AS something", onSuccess(resultSet -> { | ||
| System.out.println(resultSet.getResults()); | ||
| assertNotNull(resultSet); | ||
| assertNotNull(resultSet.getColumnNames()); | ||
| assertNotNull(resultSet.getResults()); | ||
| assertEquals(new JsonArray().add(1), resultSet.getResults().get(0)); | ||
| conn.close((ar) -> { | ||
| if (ar.succeeded()) { | ||
| testComplete(); | ||
| } else { | ||
| fail("should be able to close the asyncSqlClient"); | ||
| } | ||
| }); | ||
| public void queryTypeTimestampWithTimezoneTest(TestContext context) throws Exception { | ||
| Async async = context.async(); | ||
| client.getConnection(connAr -> { | ||
| ensureSuccess(context, connAr); | ||
| conn = connAr.result(); | ||
| conn.execute("DROP TABLE IF EXISTS test_table", onSuccess(context, dropped -> { | ||
| conn.execute("CREATE TABLE IF NOT EXISTS test_table (ts timestamp with time zone)", onSuccess(context, created -> { | ||
| conn.execute("INSERT INTO test_table (ts) VALUES (now())", onSuccess(context, inserted -> { | ||
| conn.query("SELECT * FROM test_table;", onSuccess(context, timestampSelect -> { | ||
| context.assertNotNull(timestampSelect); | ||
| context.assertNotNull(timestampSelect.getResults()); | ||
| context.assertTrue(timestampSelect.getResults().get(0).getString(0).matches("\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}\\.\\d{3}(Z|[+-]\\d{2}:\\d{2})")); | ||
| async.complete(); | ||
| })); | ||
| })); | ||
| })); | ||
| })); | ||
| })); | ||
| }); | ||
| } | ||
|
|
||
| await(); | ||
| @Test | ||
| public void queryTypeTimestampWithoutTimezoneTest(TestContext context) throws Exception { | ||
| Async async = context.async(); | ||
| client.getConnection(connAr -> { | ||
| ensureSuccess(context, connAr); | ||
| conn = connAr.result(); | ||
| conn.execute("DROP TABLE IF EXISTS test_table", onSuccess(context, dropped -> { | ||
| conn.execute("CREATE TABLE IF NOT EXISTS test_table (ts timestamp without time zone)", onSuccess(context, created -> { | ||
| conn.execute("INSERT INTO test_table (ts) VALUES (now())", onSuccess(context, inserted -> { | ||
| conn.query("SELECT * FROM test_table;", onSuccess(context, timestampSelect -> { | ||
| context.assertNotNull(timestampSelect); | ||
| context.assertNotNull(timestampSelect.getResults()); | ||
| context.assertTrue(timestampSelect.getResults().get(0).getString(0).matches("\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}\\.\\d{3}")); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @pmlopes and this checks that there is no timezone info available here. |
||
| async.complete(); | ||
| })); | ||
| })); | ||
| })); | ||
| })); | ||
| }); | ||
| } | ||
|
|
||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pmlopes this would be the check I mentioned over there: 14bb98b#commitcomment-16058891