From 0934c803c0d283899589bca029b326ba42311554 Mon Sep 17 00:00:00 2001 From: Julien Viet Date: Sun, 12 Mar 2023 22:28:58 +0100 Subject: [PATCH 1/3] Remove callback usage from examples --- .../main/java/examples/DB2ClientExamples.java | 143 ++++---- .../main/java/examples/SqlClientExamples.java | 48 ++- .../java/examples/MSSQLClientExamples.java | 53 +-- .../main/java/examples/SqlClientExamples.java | 49 ++- .../java/examples/MySQLClientExamples.java | 305 ++++++++++-------- .../main/java/examples/SqlClientExamples.java | 40 ++- .../java/examples/OracleClientExamples.java | 155 +++++---- .../main/java/examples/SqlClientExamples.java | 40 ++- .../main/java/examples/PgClientExamples.java | 132 +++++--- .../main/java/examples/SqlClientExamples.java | 53 ++- .../java/io/vertx/pgclient/PgConnection.java | 5 + .../vertx/pgclient/impl/PgConnectionImpl.java | 5 + .../main/java/examples/SqlClientExamples.java | 81 +++-- 13 files changed, 676 insertions(+), 433 deletions(-) diff --git a/vertx-db2-client/src/main/java/examples/DB2ClientExamples.java b/vertx-db2-client/src/main/java/examples/DB2ClientExamples.java index ae774dde5..10b70dd7f 100644 --- a/vertx-db2-client/src/main/java/examples/DB2ClientExamples.java +++ b/vertx-db2-client/src/main/java/examples/DB2ClientExamples.java @@ -57,7 +57,8 @@ public void gettingStarted() { // A simple query client .query("SELECT * FROM users WHERE id='julien'") - .execute(ar -> { + .execute() + .onComplete(ar -> { if (ar.succeeded()) { RowSet result = ar.result(); System.out.println("Got " + result.size() + " rows "); @@ -86,9 +87,10 @@ public void configureFromDataObject(Vertx vertx) { // Create the pool from the data object DB2Pool pool = DB2Pool.pool(vertx, connectOptions, poolOptions); - pool.getConnection(ar -> { - // Handling your connection - }); + pool.getConnection() + .onComplete(ar -> { + // Handling your connection + }); } public void configureFromUri(Vertx vertx) { @@ -100,9 +102,10 @@ public void configureFromUri(Vertx vertx) { DB2Pool pool = DB2Pool.pool(connectionUri); // Create the connection from the connection URI - DB2Connection.connect(vertx, connectionUri, res -> { - // Handling your connection - }); + DB2Connection.connect(vertx, connectionUri) + .onComplete(res -> { + // Handling your connection + }); } public void connecting01() { @@ -259,44 +262,45 @@ public void connectSsl(Vertx vertx) { .setPath("/path/to/keystore.p12") .setPassword("keystoreSecret")); - DB2Connection.connect(vertx, options, res -> { - if (res.succeeded()) { - // Connected with SSL - } else { - System.out.println("Could not connect " + res.cause()); - } - }); + DB2Connection.connect(vertx, options) + .onComplete(res -> { + if (res.succeeded()) { + // Connected with SSL + } else { + System.out.println("Could not connect " + res.cause()); + } + }); } public void generatedKeys(SqlClient client) { client .preparedQuery("SELECT color_id FROM FINAL TABLE ( INSERT INTO color (color_name) VALUES (?), (?), (?) )") - .execute(Tuple.of("white", "red", "blue"), ar -> { - if (ar.succeeded()) { - RowSet rows = ar.result(); - System.out.println("Inserted " + rows.rowCount() + " new rows."); - for (Row row : rows) { - System.out.println("generated key: " + row.getInteger("color_id")); + .execute(Tuple.of("white", "red", "blue")) + .onComplete(ar -> { + if (ar.succeeded()) { + RowSet rows = ar.result(); + System.out.println("Inserted " + rows.rowCount() + " new rows."); + for (Row row : rows) { + System.out.println("generated key: " + row.getInteger("color_id")); + } + } else { + System.out.println("Failure: " + ar.cause().getMessage()); } - } else { - System.out.println("Failure: " + ar.cause().getMessage()); - } - }); + }); } public void typeMapping01(Pool pool) { pool .query("SELECT an_int_column FROM exampleTable") - .execute(ar -> { - RowSet rowSet = ar.result(); - Row row = rowSet.iterator().next(); + .execute().onSuccess(rowSet -> { + Row row = rowSet.iterator().next(); - // Stored as INTEGER column type and represented as java.lang.Integer - Object value = row.getValue(0); + // Stored as INTEGER column type and represented as java.lang.Integer + Object value = row.getValue(0); - // Convert to java.lang.Long - Long longValue = row.getLong(0); - }); + // Convert to java.lang.Long + Long longValue = row.getLong(0); + }); } public void collector01Example(SqlClient client) { @@ -309,17 +313,18 @@ public void collector01Example(SqlClient client) { // Run the query with the collector client.query("SELECT * FROM users") .collecting(collector) - .execute(ar -> { - if (ar.succeeded()) { - SqlResult> result = ar.result(); + .execute() + .onComplete(ar -> { + if (ar.succeeded()) { + SqlResult> result = ar.result(); - // Get the map created by the collector - Map map = result.value(); - System.out.println("Got " + map); - } else { - System.out.println("Failure: " + ar.cause().getMessage()); - } - }); + // Get the map created by the collector + Map map = result.value(); + System.out.println("Got " + map); + } else { + System.out.println("Failure: " + ar.cause().getMessage()); + } + }); } public void collector02Example(SqlClient client) { @@ -331,7 +336,11 @@ public void collector02Example(SqlClient client) { ); // Run the query with the collector - client.query("SELECT * FROM users").collecting(collector).execute(ar -> { + client + .query("SELECT * FROM users") + .collecting(collector) + .execute() + .onComplete(ar -> { if (ar.succeeded()) { SqlResult result = ar.result(); @@ -353,18 +362,19 @@ enum Days { * Using an enum as a string value in the Row and Tuple methods. */ public void enumStringValues(SqlClient client) { - client.preparedQuery("SELECT day_name FROM FINAL TABLE ( INSERT INTO days (day_name) VALUES (?), (?), (?) )") - .execute(Tuple.of(Days.FRIDAY, Days.SATURDAY, Days.SUNDAY), ar -> { - if (ar.succeeded()) { - RowSet rows = ar.result(); - System.out.println("Inserted " + rows.rowCount() + " new rows"); - for (Row row : rows) { - System.out.println("Day: " + row.get(Days.class, "day_name")); - } - } else { - System.out.println("Failure: " + ar.cause().getMessage()); - } - }); + client.preparedQuery("SELECT day_name FROM FINAL TABLE ( INSERT INTO days (day_name) VALUES (?), (?), (?) )") + .execute(Tuple.of(Days.FRIDAY, Days.SATURDAY, Days.SUNDAY)) + .onComplete(ar -> { + if (ar.succeeded()) { + RowSet rows = ar.result(); + System.out.println("Inserted " + rows.rowCount() + " new rows"); + for (Row row : rows) { + System.out.println("Day: " + row.get(Days.class, "day_name")); + } + } else { + System.out.println("Failure: " + ar.cause().getMessage()); + } + }); } /** @@ -372,17 +382,18 @@ public void enumStringValues(SqlClient client) { * The row.get() method returns the corresponding enum's name() value at the ordinal position of the integer value retrieved. */ public void enumIntValues(SqlClient client) { - client.preparedQuery("SELECT day_num FROM FINAL TABLE ( INSERT INTO days (day_num) VALUES (?), (?), (?) )") - .execute(Tuple.of(Days.FRIDAY.ordinal(), Days.SATURDAY.ordinal(), Days.SUNDAY.ordinal()), ar -> { - if (ar.succeeded()) { - RowSet rows = ar.result(); - System.out.println("Inserted " + rows.rowCount() + " new rows"); - for (Row row : rows) { - System.out.println("Day: " + row.get(Days.class, "day_num")); - } - } else { - System.out.println("Failure: " + ar.cause().getMessage()); - } + client.preparedQuery("SELECT day_num FROM FINAL TABLE ( INSERT INTO days (day_num) VALUES (?), (?), (?) )") + .execute(Tuple.of(Days.FRIDAY.ordinal(), Days.SATURDAY.ordinal(), Days.SUNDAY.ordinal())) + .onComplete(ar -> { + if (ar.succeeded()) { + RowSet rows = ar.result(); + System.out.println("Inserted " + rows.rowCount() + " new rows"); + for (Row row : rows) { + System.out.println("Day: " + row.get(Days.class, "day_num")); + } + } else { + System.out.println("Failure: " + ar.cause().getMessage()); + } }); } diff --git a/vertx-db2-client/src/main/java/examples/SqlClientExamples.java b/vertx-db2-client/src/main/java/examples/SqlClientExamples.java index 148645474..fe9e08cfb 100644 --- a/vertx-db2-client/src/main/java/examples/SqlClientExamples.java +++ b/vertx-db2-client/src/main/java/examples/SqlClientExamples.java @@ -45,7 +45,8 @@ public class SqlClientExamples { public void queries01(SqlClient client) { client .query("SELECT * FROM users WHERE id='andy'") - .execute(ar -> { + .execute() + .onComplete(ar -> { if (ar.succeeded()) { RowSet result = ar.result(); System.out.println("Got " + result.size() + " rows "); @@ -59,7 +60,8 @@ public void queries01(SqlClient client) { public void queries02(SqlClient client) { client .preparedQuery("SELECT * FROM users WHERE id=?") - .execute(Tuple.of("andy"), ar -> { + .execute(Tuple.of("andy")) + .onComplete(ar -> { if (ar.succeeded()) { RowSet rows = ar.result(); System.out.println("Got " + rows.size() + " rows "); @@ -72,7 +74,8 @@ public void queries02(SqlClient client) { public void queries03(SqlClient client) { client .preparedQuery("SELECT first_name, last_name FROM users") - .execute(ar -> { + .execute() + .onComplete(ar -> { if (ar.succeeded()) { RowSet rows = ar.result(); for (Row row : rows) { @@ -87,7 +90,8 @@ public void queries03(SqlClient client) { public void queries04(SqlClient client) { client .preparedQuery("INSERT INTO users (first_name, last_name) VALUES (?, ?)") - .execute(Tuple.of("Andy", "Guibert"), ar -> { + .execute(Tuple.of("Andy", "Guibert")) + .onComplete(ar -> { if (ar.succeeded()) { RowSet rows = ar.result(); System.out.println(rows.rowCount()); @@ -126,7 +130,8 @@ public void queries08(SqlClient client) { // Execute the prepared batch client .preparedQuery("INSERT INTO USERS (id, name) VALUES (?, ?)") - .executeBatch(batch, res -> { + .executeBatch(batch) + .onComplete(res -> { if (res.succeeded()) { // Process rows @@ -143,7 +148,8 @@ public void queries09(SqlClient client, SqlConnectOptions connectOptions) { connectOptions.setCachePreparedStatements(true); client .preparedQuery("SELECT * FROM users WHERE id = ?") - .execute(Tuple.of("julien"), ar -> { + .execute(Tuple.of("julien")) + .onComplete(ar -> { if (ar.succeeded()) { RowSet rows = ar.result(); System.out.println("Got " + rows.size() + " rows "); @@ -155,11 +161,13 @@ public void queries09(SqlClient client, SqlConnectOptions connectOptions) { public void queries10(SqlConnection sqlConnection) { sqlConnection - .prepare("SELECT * FROM users WHERE id = ?", ar -> { + .prepare("SELECT * FROM users WHERE id = ?") + .onComplete(ar -> { if (ar.succeeded()) { PreparedStatement preparedStatement = ar.result(); preparedStatement.query() - .execute(Tuple.of("julien"), ar2 -> { + .execute(Tuple.of("julien")) + .onComplete(ar2 -> { if (ar2.succeeded()) { RowSet rows = ar2.result(); System.out.println("Got " + rows.size() + " rows "); @@ -272,12 +280,16 @@ public void transaction03(Pool pool) { } public void usingCursors01(SqlConnection connection) { - connection.prepare("SELECT * FROM users WHERE first_name LIKE ?", ar0 -> { + connection + .prepare("SELECT * FROM users WHERE first_name LIKE ?") + .onComplete(ar0 -> { if (ar0.succeeded()) { PreparedStatement pq = ar0.result(); // Cursors require to run within a transaction - connection.begin(ar1 -> { + connection + .begin() + .onComplete(ar1 -> { if (ar1.succeeded()) { Transaction tx = ar1.result(); @@ -285,7 +297,9 @@ public void usingCursors01(SqlConnection connection) { Cursor cursor = pq.cursor(Tuple.of("julien")); // Read 50 rows - cursor.read(50, ar2 -> { + cursor + .read(50) + .onComplete(ar2 -> { if (ar2.succeeded()) { RowSet rows = ar2.result(); @@ -305,7 +319,9 @@ public void usingCursors01(SqlConnection connection) { } public void usingCursors02(Cursor cursor) { - cursor.read(50, ar2 -> { + cursor + .read(50) + .onComplete(ar2 -> { if (ar2.succeeded()) { // Close the cursor cursor.close(); @@ -314,12 +330,16 @@ public void usingCursors02(Cursor cursor) { } public void usingCursors03(SqlConnection connection) { - connection.prepare("SELECT * FROM users WHERE first_name LIKE ?", ar0 -> { + connection + .prepare("SELECT * FROM users WHERE first_name LIKE ?") + .onComplete(ar0 -> { if (ar0.succeeded()) { PreparedStatement pq = ar0.result(); // Streams require to run within a transaction - connection.begin(ar1 -> { + connection + .begin() + .onComplete(ar1 -> { if (ar1.succeeded()) { Transaction tx = ar1.result(); diff --git a/vertx-mssql-client/src/main/java/examples/MSSQLClientExamples.java b/vertx-mssql-client/src/main/java/examples/MSSQLClientExamples.java index 9f99cc305..9b65d1606 100644 --- a/vertx-mssql-client/src/main/java/examples/MSSQLClientExamples.java +++ b/vertx-mssql-client/src/main/java/examples/MSSQLClientExamples.java @@ -46,17 +46,18 @@ public void gettingStarted() { // A simple query client .query("SELECT * FROM users WHERE id='julien'") - .execute(ar -> { - if (ar.succeeded()) { - RowSet result = ar.result(); - System.out.println("Got " + result.size() + " rows "); - } else { - System.out.println("Failure: " + ar.cause().getMessage()); - } + .execute() + .onComplete(ar -> { + if (ar.succeeded()) { + RowSet result = ar.result(); + System.out.println("Got " + result.size() + " rows "); + } else { + System.out.println("Failure: " + ar.cause().getMessage()); + } - // Now close the pool - client.close(); - }); + // Now close the pool + client.close(); + }); } public void configureFromDataObject(Vertx vertx) { @@ -75,9 +76,10 @@ public void configureFromDataObject(Vertx vertx) { // Create the pool from the data object MSSQLPool pool = MSSQLPool.pool(vertx, connectOptions, poolOptions); - pool.getConnection(ar -> { - // Handling your connection - }); + pool.getConnection() + .onComplete(ar -> { + // Handling your connection + }); } public void configureFromUri(Vertx vertx) { @@ -89,9 +91,10 @@ public void configureFromUri(Vertx vertx) { MSSQLPool pool = MSSQLPool.pool(connectionUri); // Create the connection from the connection URI - MSSQLConnection.connect(vertx, connectionUri, res -> { - // Handling your connection - }); + MSSQLConnection.connect(vertx, connectionUri) + .onComplete(res -> { + // Handling your connection + }); } public void connecting01() { @@ -195,7 +198,8 @@ public void collector01Example(SqlClient client) { // Run the query with the collector client.query("SELECT * FROM users") .collecting(collector) - .execute(ar -> { + .execute() + .onComplete(ar -> { if (ar.succeeded()) { SqlResult> result = ar.result(); @@ -219,7 +223,8 @@ public void collector02Example(SqlClient client) { // Run the query with the collector client.query("SELECT * FROM users") .collecting(collector) - .execute(ar -> { + .execute() + .onComplete(ar -> { if (ar.succeeded()) { SqlResult result = ar.result(); @@ -239,7 +244,8 @@ enum Color { public void enumeratedType01Example(SqlClient client) { client .preparedQuery("INSERT INTO colors VALUES (@p1)") - .execute(Tuple.of(Color.red), res -> { + .execute(Tuple.of(Color.red)) + .onComplete(res -> { // ... }); } @@ -265,7 +271,8 @@ public void transparentNullHandling(SqlClient client) { .addString(null); client .preparedQuery("INSERT INTO movies (id, title, plot) VALUES (@p1, @p2, @p3)") - .execute(tuple, res -> { + .execute(tuple) + .onComplete(res -> { // ... }); } @@ -274,7 +281,8 @@ public void explicitNullHandling(SqlClient client) { Tuple tuple = Tuple.of(17, "The Man Who Knew Too Much", NullValue.String); client .preparedQuery("INSERT INTO movies (id, title, plot) VALUES (@p1, @p2, @p3)") - .execute(tuple, res -> { + .execute(tuple) + .onComplete(res -> { // ... }); } @@ -282,7 +290,8 @@ public void explicitNullHandling(SqlClient client) { public void identityColumn(SqlClient client) { client .preparedQuery("INSERT INTO movies (title) OUTPUT INSERTED.id VALUES (@p1)") - .execute(Tuple.of("The Man Who Knew Too Much"), res -> { + .execute(Tuple.of("The Man Who Knew Too Much")) + .onComplete(res -> { if (res.succeeded()) { Row row = res.result().iterator().next(); System.out.println(row.getLong("id")); diff --git a/vertx-mssql-client/src/main/java/examples/SqlClientExamples.java b/vertx-mssql-client/src/main/java/examples/SqlClientExamples.java index 0a9ca9da0..c2b3ae78b 100644 --- a/vertx-mssql-client/src/main/java/examples/SqlClientExamples.java +++ b/vertx-mssql-client/src/main/java/examples/SqlClientExamples.java @@ -35,7 +35,8 @@ public class SqlClientExamples { public void queries01(SqlClient client) { client .query("SELECT * FROM users WHERE id='julien'") - .execute(ar -> { + .execute() + .onComplete(ar -> { if (ar.succeeded()) { RowSet result = ar.result(); System.out.println("Got " + result.size() + " rows "); @@ -49,7 +50,8 @@ public void queries01(SqlClient client) { public void queries02(SqlClient client) { client .preparedQuery("SELECT * FROM users WHERE id=@p1") - .execute(Tuple.of("julien"), ar -> { + .execute(Tuple.of("julien")) + .onComplete(ar -> { if (ar.succeeded()) { RowSet rows = ar.result(); System.out.println("Got " + rows.size() + " rows "); @@ -62,7 +64,8 @@ public void queries02(SqlClient client) { public void queries03(SqlClient client) { client .preparedQuery("SELECT first_name, last_name FROM users") - .execute(ar -> { + .execute() + .onComplete(ar -> { if (ar.succeeded()) { RowSet rows = ar.result(); for (Row row : rows) { @@ -77,7 +80,8 @@ public void queries03(SqlClient client) { public void queries04(SqlClient client) { client .preparedQuery("INSERT INTO users (first_name, last_name) VALUES (@p1, @p2)") - .execute(Tuple.of("Julien", "Viet"), ar -> { + .execute(Tuple.of("Julien", "Viet")) + .onComplete(ar -> { if (ar.succeeded()) { RowSet rows = ar.result(); System.out.println(rows.rowCount()); @@ -115,7 +119,8 @@ public void queries08(SqlClient client) { // Execute the prepared batch client .preparedQuery("INSERT INTO USERS (id, name) VALUES (@p1, @p2)") - .executeBatch(batch, res -> { + .executeBatch(batch) + .onComplete(res -> { if (res.succeeded()) { // Process rows @@ -132,7 +137,8 @@ public void queries09(SqlClient client, SqlConnectOptions connectOptions) { connectOptions.setCachePreparedStatements(true); client .preparedQuery("SELECT * FROM users WHERE id = @p1") - .execute(Tuple.of("julien"), ar -> { + .execute(Tuple.of("julien")) + .onComplete(ar -> { if (ar.succeeded()) { RowSet rows = ar.result(); System.out.println("Got " + rows.size() + " rows "); @@ -144,11 +150,13 @@ public void queries09(SqlClient client, SqlConnectOptions connectOptions) { public void queries10(SqlConnection sqlConnection) { sqlConnection - .prepare("SELECT * FROM users WHERE id = @p1", ar -> { + .prepare("SELECT * FROM users WHERE id = @p1") + .onComplete(ar -> { if (ar.succeeded()) { PreparedStatement preparedStatement = ar.result(); preparedStatement.query() - .execute(Tuple.of("julien"), ar2 -> { + .execute(Tuple.of("julien")) + .onComplete(ar2 -> { if (ar2.succeeded()) { RowSet rows = ar2.result(); System.out.println("Got " + rows.size() + " rows "); @@ -217,18 +225,22 @@ public void usingConnections03(Pool pool) { } public void usingConnections03(SqlConnection connection) { - connection.prepare("INSERT INTO USERS (id, name) VALUES (@p1, @p2)", ar1 -> { + connection.prepare("INSERT INTO USERS (id, name) VALUES (@p1, @p2)") + .onComplete(ar1 -> { if (ar1.succeeded()) { PreparedStatement prepared = ar1.result(); // Create a query : bind parameters - List batch = new ArrayList(); + List batch = new ArrayList<>(); // Add commands to the createBatch batch.add(Tuple.of("julien", "Julien Viet")); batch.add(Tuple.of("emad", "Emad Alblueshi")); - prepared.query().executeBatch(batch, res -> { + prepared + .query() + .executeBatch(batch) + .onComplete(res -> { if (res.succeeded()) { // Process rows @@ -286,7 +298,8 @@ public void transaction03(Pool pool) { } public void usingCursors01(SqlConnection connection) { - connection.prepare("SELECT * FROM users WHERE age > @p1", ar1 -> { + connection.prepare("SELECT * FROM users WHERE age > @p1") + .onComplete(ar1 -> { if (ar1.succeeded()) { PreparedStatement pq = ar1.result(); @@ -294,7 +307,9 @@ public void usingCursors01(SqlConnection connection) { Cursor cursor = pq.cursor(Tuple.of(18)); // Read 50 rows - cursor.read(50, ar2 -> { + cursor + .read(50) + .onComplete(ar2 -> { if (ar2.succeeded()) { RowSet rows = ar2.result(); @@ -312,7 +327,9 @@ public void usingCursors01(SqlConnection connection) { } public void usingCursors02(Cursor cursor) { - cursor.read(50, ar2 -> { + cursor + .read(50) + .onComplete(ar2 -> { if (ar2.succeeded()) { // Close the cursor cursor.close(); @@ -321,7 +338,9 @@ public void usingCursors02(Cursor cursor) { } public void usingCursors03(SqlConnection connection) { - connection.prepare("SELECT * FROM users WHERE age > @p1", ar1 -> { + connection + .prepare("SELECT * FROM users WHERE age > @p1") + .onComplete(ar1 -> { if (ar1.succeeded()) { PreparedStatement pq = ar1.result(); diff --git a/vertx-mysql-client/src/main/java/examples/MySQLClientExamples.java b/vertx-mysql-client/src/main/java/examples/MySQLClientExamples.java index 20ee58b5e..b61d8ebe6 100644 --- a/vertx-mysql-client/src/main/java/examples/MySQLClientExamples.java +++ b/vertx-mysql-client/src/main/java/examples/MySQLClientExamples.java @@ -51,17 +51,18 @@ public void gettingStarted() { // A simple query client .query("SELECT * FROM users WHERE id='julien'") - .execute(ar -> { - if (ar.succeeded()) { - RowSet result = ar.result(); - System.out.println("Got " + result.size() + " rows "); - } else { - System.out.println("Failure: " + ar.cause().getMessage()); - } + .execute() + .onComplete(ar -> { + if (ar.succeeded()) { + RowSet result = ar.result(); + System.out.println("Got " + result.size() + " rows "); + } else { + System.out.println("Failure: " + ar.cause().getMessage()); + } - // Now close the pool - client.close(); - }); + // Now close the pool + client.close(); + }); } public void configureFromDataObject(Vertx vertx) { @@ -80,9 +81,10 @@ public void configureFromDataObject(Vertx vertx) { // Create the pool from the data object MySQLPool pool = MySQLPool.pool(vertx, connectOptions, poolOptions); - pool.getConnection(ar -> { - // Handling your connection - }); + pool.getConnection() + .onComplete(ar -> { + // Handling your connection + }); } public void configureConnectionCharset() { @@ -124,9 +126,10 @@ public void configureFromUri(Vertx vertx) { MySQLPool pool = MySQLPool.pool(connectionUri); // Create the connection from the connection URI - MySQLConnection.connect(vertx, connectionUri, res -> { - // Handling your connection - }); + MySQLConnection.connect(vertx, connectionUri) + .onComplete(res -> { + // Handling your connection + }); } public void connecting01() { @@ -263,7 +266,8 @@ public void reconnectAttempts(MySQLConnectOptions options) { public void lastInsertId(SqlClient client) { client .query("INSERT INTO test(val) VALUES ('v1')") - .execute(ar -> { + .execute() + .onComplete(ar -> { if (ar.succeeded()) { RowSet rows = ar.result(); long lastInsertId = rows.property(MySQLClient.LAST_INSERTED_ID); @@ -277,44 +281,48 @@ public void lastInsertId(SqlClient client) { public void implicitTypeConversionExample(SqlClient client) { client .preparedQuery("SELECT * FROM students WHERE updated_time = ?") - .execute(Tuple.of(LocalTime.of(19, 10, 25)), ar -> { - // handle the results - }); + .execute(Tuple.of(LocalTime.of(19, 10, 25))) + .onComplete(ar -> { + // handle the results + }); // this will also work with implicit type conversion client .preparedQuery("SELECT * FROM students WHERE updated_time = ?") - .execute(Tuple.of("19:10:25"), ar -> { - // handle the results - }); + .execute(Tuple.of("19:10:25")) + .onComplete(ar -> { + // handle the results + }); } public void booleanExample01(SqlClient client) { client .query("SELECT graduated FROM students WHERE id = 0") - .execute(ar -> { - if (ar.succeeded()) { - RowSet rowSet = ar.result(); - for (Row row : rowSet) { - int pos = row.getColumnIndex("graduated"); - Byte value = row.get(Byte.class, pos); - Boolean graduated = row.getBoolean("graduated"); + .execute() + .onComplete(ar -> { + if (ar.succeeded()) { + RowSet rowSet = ar.result(); + for (Row row : rowSet) { + int pos = row.getColumnIndex("graduated"); + Byte value = row.get(Byte.class, pos); + Boolean graduated = row.getBoolean("graduated"); + } + } else { + System.out.println("Failure: " + ar.cause().getMessage()); } - } else { - System.out.println("Failure: " + ar.cause().getMessage()); - } - }); + }); } public void booleanExample02(SqlClient client) { client .preparedQuery("UPDATE students SET graduated = ? WHERE id = 0") - .execute(Tuple.of(true), ar -> { - if (ar.succeeded()) { - System.out.println("Updated with the boolean value"); - } else { - System.out.println("Failure: " + ar.cause().getMessage()); - } - }); + .execute(Tuple.of(true)) + .onComplete(ar -> { + if (ar.succeeded()) { + System.out.println("Updated with the boolean value"); + } else { + System.out.println("Failure: " + ar.cause().getMessage()); + } + }); } public void jsonExample() { @@ -352,7 +360,8 @@ enum Color { public void enumeratedType01Example(SqlClient client) { client .preparedQuery("INSERT INTO colors VALUES (?)") - .execute(Tuple.of(Color.red), res -> { + .execute(Tuple.of(Color.red)) + .onComplete(res -> { // ... }); } @@ -374,51 +383,54 @@ public void enumeratedType02Example(SqlClient client) { public void geometryExample01(SqlClient client) { client .query("SELECT ST_AsText(g) FROM geom;") - .execute(ar -> { - if (ar.succeeded()) { - // Fetch the spatial data in WKT format - RowSet result = ar.result(); - for (Row row : result) { - String wktString = row.getString(0); + .execute() + .onComplete(ar -> { + if (ar.succeeded()) { + // Fetch the spatial data in WKT format + RowSet result = ar.result(); + for (Row row : result) { + String wktString = row.getString(0); + } + } else { + System.out.println("Failure: " + ar.cause().getMessage()); } - } else { - System.out.println("Failure: " + ar.cause().getMessage()); - } - }); + }); } public void geometryExample02(SqlClient client) { client .query("SELECT ST_AsBinary(g) FROM geom;") - .execute(ar -> { - if (ar.succeeded()) { - // Fetch the spatial data in WKB format - RowSet result = ar.result(); - for (Row row : result) { - Buffer wkbValue = row.getBuffer(0); + .execute() + .onComplete(ar -> { + if (ar.succeeded()) { + // Fetch the spatial data in WKB format + RowSet result = ar.result(); + for (Row row : result) { + Buffer wkbValue = row.getBuffer(0); + } + } else { + System.out.println("Failure: " + ar.cause().getMessage()); } - } else { - System.out.println("Failure: " + ar.cause().getMessage()); - } - }); + }); } public void geometryExample03(SqlClient client) { client .query("SELECT g FROM geom;") - .execute(ar -> { - if (ar.succeeded()) { - // Fetch the spatial data as a Vert.x Data Object - RowSet result = ar.result(); - for (Row row : result) { - Point point = row.get(Point.class, 0); - System.out.println("Point x: " + point.getX()); - System.out.println("Point y: " + point.getY()); + .execute() + .onComplete(ar -> { + if (ar.succeeded()) { + // Fetch the spatial data as a Vert.x Data Object + RowSet result = ar.result(); + for (Row row : result) { + Point point = row.get(Point.class, 0); + System.out.println("Point x: " + point.getX()); + System.out.println("Point y: " + point.getY()); + } + } else { + System.out.println("Failure: " + ar.cause().getMessage()); } - } else { - System.out.println("Failure: " + ar.cause().getMessage()); - } - }); + }); } public void geometryExample04(SqlClient client) { @@ -426,13 +438,14 @@ public void geometryExample04(SqlClient client) { // Send as a WKB representation client .preparedQuery("INSERT INTO geom VALUES (ST_GeomFromWKB(?))") - .execute(Tuple.of(point), ar -> { - if (ar.succeeded()) { - System.out.println("Success"); - } else { - System.out.println("Failure: " + ar.cause().getMessage()); - } - }); + .execute(Tuple.of(point)) + .onComplete(ar -> { + if (ar.succeeded()) { + System.out.println("Success"); + } else { + System.out.println("Failure: " + ar.cause().getMessage()); + } + }); } public void collector01Example(SqlClient client) { @@ -443,7 +456,10 @@ public void collector01Example(SqlClient client) { row -> row.getString("last_name")); // Run the query with the collector - client.query("SELECT * FROM users").collecting(collector).execute(ar -> { + client.query("SELECT * FROM users") + .collecting(collector) + .execute() + .onComplete(ar -> { if (ar.succeeded()) { SqlResult> result = ar.result(); @@ -465,7 +481,10 @@ public void collector02Example(SqlClient client) { ); // Run the query with the collector - client.query("SELECT * FROM users").collecting(collector).execute(ar -> { + client.query("SELECT * FROM users") + .collecting(collector) + .execute() + .onComplete(ar -> { if (ar.succeeded()) { SqlResult result = ar.result(); @@ -484,12 +503,15 @@ public void storedProcedureExample(SqlClient client) { " SELECT 1;\n" + " INSERT INTO ins VALUES (1);\n" + " INSERT INTO ins VALUES (2);\n" + - "END;").execute(ar1 -> { + "END;") + .execute() + .onComplete(ar1 -> { if (ar1.succeeded()) { // create stored procedure success client .query("CALL multi();") - .execute(ar2 -> { + .execute() + .onComplete(ar2 -> { if (ar2.succeeded()) { // handle the result RowSet result1 = ar2.result(); @@ -560,29 +582,32 @@ public void tlsExample(Vertx vertx) { .setSslMode(SslMode.VERIFY_CA) .setPemTrustOptions(new PemTrustOptions().addCertPath("/path/to/cert.pem")); - MySQLConnection.connect(vertx, options, res -> { - if (res.succeeded()) { - // Connected with SSL - } else { - System.out.println("Could not connect " + res.cause()); - } - }); + MySQLConnection.connect(vertx, options) + .onComplete(res -> { + if (res.succeeded()) { + // Connected with SSL + } else { + System.out.println("Could not connect " + res.cause()); + } + }); } public void pingExample(MySQLConnection connection) { - connection.ping(ar -> { + connection.ping().onComplete(ar -> { System.out.println("The server has responded to the PING"); }); } public void resetConnectionExample(MySQLConnection connection) { - connection.resetConnection(ar -> { - if (ar.succeeded()) { - System.out.println("Connection has been reset now"); - } else { - System.out.println("Failure: " + ar.cause().getMessage()); - } - }); + connection + .resetConnection() + .onComplete(ar -> { + if (ar.succeeded()) { + System.out.println("Connection has been reset now"); + } else { + System.out.println("Failure: " + ar.cause().getMessage()); + } + }); } public void changeUserExample(MySQLConnection connection) { @@ -590,52 +615,62 @@ public void changeUserExample(MySQLConnection connection) { .setUser("newuser") .setPassword("newpassword") .setDatabase("newdatabase"); - connection.changeUser(authenticationOptions, ar -> { - if (ar.succeeded()) { - System.out.println("User of current connection has been changed."); - } else { - System.out.println("Failure: " + ar.cause().getMessage()); - } - }); + connection + .changeUser(authenticationOptions) + .onComplete(ar -> { + if (ar.succeeded()) { + System.out.println("User of current connection has been changed."); + } else { + System.out.println("Failure: " + ar.cause().getMessage()); + } + }); } public void initDbExample(MySQLConnection connection) { - connection.specifySchema("newschema", ar -> { - if (ar.succeeded()) { - System.out.println("Default schema changed to newschema"); - } else { - System.out.println("Failure: " + ar.cause().getMessage()); - } - }); + connection + .specifySchema("newschema") + .onComplete(ar -> { + if (ar.succeeded()) { + System.out.println("Default schema changed to newschema"); + } else { + System.out.println("Failure: " + ar.cause().getMessage()); + } + }); } public void statisticsExample(MySQLConnection connection) { - connection.getInternalStatistics(ar -> { - if (ar.succeeded()) { - System.out.println("Statistics: " + ar.result()); - } else { - System.out.println("Failure: " + ar.cause().getMessage()); - } - }); + connection + .getInternalStatistics() + .onComplete(ar -> { + if (ar.succeeded()) { + System.out.println("Statistics: " + ar.result()); + } else { + System.out.println("Failure: " + ar.cause().getMessage()); + } + }); } public void debugExample(MySQLConnection connection) { - connection.debug(ar -> { - if (ar.succeeded()) { - System.out.println("Debug info dumped to server's STDOUT"); - } else { - System.out.println("Failure: " + ar.cause().getMessage()); - } - }); + connection + .debug() + .onComplete(ar -> { + if (ar.succeeded()) { + System.out.println("Debug info dumped to server's STDOUT"); + } else { + System.out.println("Failure: " + ar.cause().getMessage()); + } + }); } public void setOptionExample01(MySQLConnection connection) { - connection.setOption(MySQLSetOption.MYSQL_OPTION_MULTI_STATEMENTS_OFF, ar -> { - if (ar.succeeded()) { - System.out.println("CLIENT_MULTI_STATEMENTS is off now"); - } else { - System.out.println("Failure: " + ar.cause().getMessage()); - } - }); + connection + .setOption(MySQLSetOption.MYSQL_OPTION_MULTI_STATEMENTS_OFF) + .onComplete(ar -> { + if (ar.succeeded()) { + System.out.println("CLIENT_MULTI_STATEMENTS is off now"); + } else { + System.out.println("Failure: " + ar.cause().getMessage()); + } + }); } } diff --git a/vertx-mysql-client/src/main/java/examples/SqlClientExamples.java b/vertx-mysql-client/src/main/java/examples/SqlClientExamples.java index 7b39a3dfb..898010274 100644 --- a/vertx-mysql-client/src/main/java/examples/SqlClientExamples.java +++ b/vertx-mysql-client/src/main/java/examples/SqlClientExamples.java @@ -46,7 +46,8 @@ public class SqlClientExamples { public void queries01(SqlClient client) { client .query("SELECT * FROM users WHERE id='julien'") - .execute(ar -> { + .execute() + .onComplete(ar -> { if (ar.succeeded()) { RowSet result = ar.result(); System.out.println("Got " + result.size() + " rows "); @@ -60,7 +61,8 @@ public void queries01(SqlClient client) { public void queries02(SqlClient client) { client .preparedQuery("SELECT * FROM users WHERE id=?") - .execute(Tuple.of("julien"), ar -> { + .execute(Tuple.of("julien")) + .onComplete(ar -> { if (ar.succeeded()) { RowSet rows = ar.result(); System.out.println("Got " + rows.size() + " rows "); @@ -73,7 +75,8 @@ public void queries02(SqlClient client) { public void queries03(SqlClient client) { client .preparedQuery("SELECT first_name, last_name FROM users") - .execute(ar -> { + .execute() + .onComplete(ar -> { if (ar.succeeded()) { RowSet rows = ar.result(); for (Row row : rows) { @@ -88,7 +91,8 @@ public void queries03(SqlClient client) { public void queries04(SqlClient client) { client .preparedQuery("INSERT INTO users (first_name, last_name) VALUES (?, ?)") - .execute(Tuple.of("Julien", "Viet"), ar -> { + .execute(Tuple.of("Julien", "Viet")) + .onComplete(ar -> { if (ar.succeeded()) { RowSet rows = ar.result(); System.out.println(rows.rowCount()); @@ -126,7 +130,8 @@ public void queries08(SqlClient client) { // Execute the prepared batch client .preparedQuery("INSERT INTO USERS (id, name) VALUES (?, ?)") - .executeBatch(batch, res -> { + .executeBatch(batch) + .onComplete(res -> { if (res.succeeded()) { // Process rows @@ -143,7 +148,8 @@ public void queries09(SqlClient client, SqlConnectOptions connectOptions) { connectOptions.setCachePreparedStatements(true); client .preparedQuery("SELECT * FROM users WHERE id = ?") - .execute(Tuple.of("julien"), ar -> { + .execute(Tuple.of("julien")) + .onComplete(ar -> { if (ar.succeeded()) { RowSet rows = ar.result(); System.out.println("Got " + rows.size() + " rows "); @@ -155,11 +161,13 @@ public void queries09(SqlClient client, SqlConnectOptions connectOptions) { public void queries10(SqlConnection sqlConnection) { sqlConnection - .prepare("SELECT * FROM users WHERE id = ?", ar -> { + .prepare("SELECT * FROM users WHERE id = ?") + .onComplete(ar -> { if (ar.succeeded()) { PreparedStatement preparedStatement = ar.result(); preparedStatement.query() - .execute(Tuple.of("julien"), ar2 -> { + .execute(Tuple.of("julien")) + .onComplete(ar2 -> { if (ar2.succeeded()) { RowSet rows = ar2.result(); System.out.println("Got " + rows.size() + " rows "); @@ -271,7 +279,9 @@ public void transaction03(Pool pool) { } public void usingCursors01(SqlConnection connection) { - connection.prepare("SELECT * FROM users WHERE age > ?", ar1 -> { + connection + .prepare("SELECT * FROM users WHERE age > ?") + .onComplete(ar1 -> { if (ar1.succeeded()) { PreparedStatement pq = ar1.result(); @@ -279,7 +289,9 @@ public void usingCursors01(SqlConnection connection) { Cursor cursor = pq.cursor(Tuple.of(18)); // Read 50 rows - cursor.read(50, ar2 -> { + cursor + .read(50) + .onComplete(ar2 -> { if (ar2.succeeded()) { RowSet rows = ar2.result(); @@ -297,7 +309,9 @@ public void usingCursors01(SqlConnection connection) { } public void usingCursors02(Cursor cursor) { - cursor.read(50, ar2 -> { + cursor + .read(50) + .onComplete(ar2 -> { if (ar2.succeeded()) { // Close the cursor cursor.close(); @@ -306,7 +320,9 @@ public void usingCursors02(Cursor cursor) { } public void usingCursors03(SqlConnection connection) { - connection.prepare("SELECT * FROM users WHERE age > ?", ar1 -> { + connection + .prepare("SELECT * FROM users WHERE age > ?") + .onComplete(ar1 -> { if (ar1.succeeded()) { PreparedStatement pq = ar1.result(); diff --git a/vertx-oracle-client/src/main/java/examples/OracleClientExamples.java b/vertx-oracle-client/src/main/java/examples/OracleClientExamples.java index 8408348ff..de4afaaaa 100644 --- a/vertx-oracle-client/src/main/java/examples/OracleClientExamples.java +++ b/vertx-oracle-client/src/main/java/examples/OracleClientExamples.java @@ -54,17 +54,18 @@ public void gettingStarted() { // A simple query client .query("SELECT * FROM users WHERE id='julien'") - .execute(ar -> { - if (ar.succeeded()) { - RowSet result = ar.result(); - System.out.println("Got " + result.size() + " rows "); - } else { - System.out.println("Failure: " + ar.cause().getMessage()); - } + .execute() + .onComplete(ar -> { + if (ar.succeeded()) { + RowSet result = ar.result(); + System.out.println("Got " + result.size() + " rows "); + } else { + System.out.println("Failure: " + ar.cause().getMessage()); + } - // Now close the pool - client.close(); - }); + // Now close the pool + client.close(); + }); } public void configureFromDataObject(Vertx vertx) { @@ -83,9 +84,11 @@ public void configureFromDataObject(Vertx vertx) { // Create the pool from the data object OraclePool pool = OraclePool.pool(vertx, connectOptions, poolOptions); - pool.getConnection(ar -> { - // Handling your connection - }); + pool + .getConnection() + .onComplete(ar -> { + // Handling your connection + }); } public void configureFromUri(Vertx vertx) { @@ -216,21 +219,24 @@ public void reconnectAttempts(OracleConnectOptions options) { public void implicitTypeConversionExample(SqlClient client) { client .preparedQuery("SELECT * FROM students WHERE updated_time = ?") - .execute(Tuple.of(LocalTime.of(19, 10, 25)), ar -> { - // handle the results - }); + .execute(Tuple.of(LocalTime.of(19, 10, 25))) + .onComplete(ar -> { + // handle the results + }); // this will also work with implicit type conversion client .preparedQuery("SELECT * FROM students WHERE updated_time = ?") - .execute(Tuple.of("19:10:25"), ar -> { - // handle the results - }); + .execute(Tuple.of("19:10:25")) + .onComplete(ar -> { + // handle the results + }); } public void booleanExample01(SqlClient client) { client .query("SELECT graduated FROM students WHERE id = 0") - .execute(ar -> { + .execute() + .onComplete(ar -> { if (ar.succeeded()) { RowSet rowSet = ar.result(); for (Row row : rowSet) { @@ -247,13 +253,14 @@ public void booleanExample01(SqlClient client) { public void booleanExample02(SqlClient client) { client .preparedQuery("UPDATE students SET graduated = ? WHERE id = 0") - .execute(Tuple.of(true), ar -> { - if (ar.succeeded()) { - System.out.println("Updated with the boolean value"); - } else { - System.out.println("Failure: " + ar.cause().getMessage()); - } - }); + .execute(Tuple.of(true)) + .onComplete(ar -> { + if (ar.succeeded()) { + System.out.println("Updated with the boolean value"); + } else { + System.out.println("Failure: " + ar.cause().getMessage()); + } + }); } public void jsonExample() { @@ -291,7 +298,8 @@ enum Color { public void enumeratedType01Example(SqlClient client) { client .preparedQuery("INSERT INTO colors VALUES (?)") - .execute(Tuple.of(Color.red), res -> { + .execute(Tuple.of(Color.red)) + .onComplete(res -> { // ... }); } @@ -313,33 +321,35 @@ public void enumeratedType02Example(SqlClient client) { public void geometryExample01(SqlClient client) { client .query("SELECT ST_AsText(g) FROM geom;") - .execute(ar -> { - if (ar.succeeded()) { - // Fetch the spatial data in WKT format - RowSet result = ar.result(); - for (Row row : result) { - String wktString = row.getString(0); + .execute() + .onComplete(ar -> { + if (ar.succeeded()) { + // Fetch the spatial data in WKT format + RowSet result = ar.result(); + for (Row row : result) { + String wktString = row.getString(0); + } + } else { + System.out.println("Failure: " + ar.cause().getMessage()); } - } else { - System.out.println("Failure: " + ar.cause().getMessage()); - } - }); + }); } public void geometryExample02(SqlClient client) { client .query("SELECT ST_AsBinary(g) FROM geom;") - .execute(ar -> { - if (ar.succeeded()) { - // Fetch the spatial data in WKB format - RowSet result = ar.result(); - for (Row row : result) { - Buffer wkbValue = row.getBuffer(0); + .execute() + .onComplete(ar -> { + if (ar.succeeded()) { + // Fetch the spatial data in WKB format + RowSet result = ar.result(); + for (Row row : result) { + Buffer wkbValue = row.getBuffer(0); + } + } else { + System.out.println("Failure: " + ar.cause().getMessage()); } - } else { - System.out.println("Failure: " + ar.cause().getMessage()); - } - }); + }); } public void collector01Example(SqlClient client) { @@ -350,7 +360,10 @@ public void collector01Example(SqlClient client) { row -> row.getString("last_name")); // Run the query with the collector - client.query("SELECT * FROM users").collecting(collector).execute(ar -> { + client.query("SELECT * FROM users") + .collecting(collector) + .execute() + .onComplete(ar -> { if (ar.succeeded()) { SqlResult> result = ar.result(); @@ -372,7 +385,10 @@ public void collector02Example(SqlClient client) { ); // Run the query with the collector - client.query("SELECT * FROM users").collecting(collector).execute(ar -> { + client.query("SELECT * FROM users") + .collecting(collector) + .execute() + .onComplete(ar -> { if (ar.succeeded()) { SqlResult result = ar.result(); @@ -391,12 +407,15 @@ public void storedProcedureExample(SqlClient client) { " SELECT 1;\n" + " INSERT INTO ins VALUES (1);\n" + " INSERT INTO ins VALUES (2);\n" + - "END;").execute(ar1 -> { + "END;") + .execute() + .onComplete(ar1 -> { if (ar1.succeeded()) { // create stored procedure success client .query("CALL multi();") - .execute(ar2 -> { + .execute() + .onComplete(ar2 -> { if (ar2.succeeded()) { // handle the result RowSet result1 = ar2.result(); @@ -426,14 +445,16 @@ public void retrieveGeneratedKeyByName(SqlClient client) { OraclePrepareOptions options = new OraclePrepareOptions() .setAutoGeneratedKeysIndexes(new JsonArray().add("ID")); - client.preparedQuery(sql, options).execute(Tuple.of("john", 3), ar -> { - if (ar.succeeded()) { - RowSet result = ar.result(); + client.preparedQuery(sql, options) + .execute(Tuple.of("john", 3)) + .onComplete(ar -> { + if (ar.succeeded()) { + RowSet result = ar.result(); - Row generated = result.property(OracleClient.GENERATED_KEYS); - Long id = generated.getLong("ID"); - } - }); + Row generated = result.property(OracleClient.GENERATED_KEYS); + Long id = generated.getLong("ID"); + } + }); } public void retrieveGeneratedKeyByIndex(SqlClient client) { @@ -443,14 +464,16 @@ public void retrieveGeneratedKeyByIndex(SqlClient client) { OraclePrepareOptions options = new OraclePrepareOptions() .setAutoGeneratedKeysIndexes(new JsonArray().add("1")); - client.preparedQuery(sql, options).execute(Tuple.of("john", 3), ar -> { - if (ar.succeeded()) { - RowSet result = ar.result(); + client.preparedQuery(sql, options) + .execute(Tuple.of("john", 3)) + .onComplete(ar -> { + if (ar.succeeded()) { + RowSet result = ar.result(); - Row generated = result.property(OracleClient.GENERATED_KEYS); - Long id = generated.getLong("ID"); - } - }); + Row generated = result.property(OracleClient.GENERATED_KEYS); + Long id = generated.getLong("ID"); + } + }); } public void blobUsage(SqlClient client, Buffer imageBuffer, Long id) { diff --git a/vertx-oracle-client/src/main/java/examples/SqlClientExamples.java b/vertx-oracle-client/src/main/java/examples/SqlClientExamples.java index 82ed584d7..139b3a119 100644 --- a/vertx-oracle-client/src/main/java/examples/SqlClientExamples.java +++ b/vertx-oracle-client/src/main/java/examples/SqlClientExamples.java @@ -42,7 +42,8 @@ public class SqlClientExamples { public void queries01(SqlClient client) { client .query("SELECT * FROM users WHERE id='julien'") - .execute(ar -> { + .execute() + .onComplete(ar -> { if (ar.succeeded()) { RowSet result = ar.result(); System.out.println("Got " + result.size() + " rows "); @@ -56,7 +57,8 @@ public void queries01(SqlClient client) { public void queries02(SqlClient client) { client .preparedQuery("SELECT * FROM users WHERE id=?") - .execute(Tuple.of("julien"), ar -> { + .execute(Tuple.of("julien")) + .onComplete(ar -> { if (ar.succeeded()) { RowSet rows = ar.result(); System.out.println("Got " + rows.size() + " rows "); @@ -69,7 +71,8 @@ public void queries02(SqlClient client) { public void queries03(SqlClient client) { client .preparedQuery("SELECT first_name, last_name FROM users") - .execute(ar -> { + .execute() + .onComplete(ar -> { if (ar.succeeded()) { RowSet rows = ar.result(); for (Row row : rows) { @@ -84,7 +87,8 @@ public void queries03(SqlClient client) { public void queries04(SqlClient client) { client .preparedQuery("INSERT INTO users (first_name, last_name) VALUES (?, ?)") - .execute(Tuple.of("Julien", "Viet"), ar -> { + .execute(Tuple.of("Julien", "Viet")) + .onComplete(ar -> { if (ar.succeeded()) { RowSet rows = ar.result(); System.out.println(rows.rowCount()); @@ -122,7 +126,8 @@ public void queries08(SqlClient client) { // Execute the prepared batch client .preparedQuery("INSERT INTO USERS (id, name) VALUES (?, ?)") - .executeBatch(batch, res -> { + .executeBatch(batch) + .onComplete(res -> { if (res.succeeded()) { // Process rows @@ -139,7 +144,8 @@ public void queries09(SqlClient client, SqlConnectOptions connectOptions) { connectOptions.setCachePreparedStatements(true); client .preparedQuery("SELECT * FROM users WHERE id = ?") - .execute(Tuple.of("julien"), ar -> { + .execute(Tuple.of("julien")) + .onComplete(ar -> { if (ar.succeeded()) { RowSet rows = ar.result(); System.out.println("Got " + rows.size() + " rows "); @@ -151,11 +157,13 @@ public void queries09(SqlClient client, SqlConnectOptions connectOptions) { public void queries10(SqlConnection sqlConnection) { sqlConnection - .prepare("SELECT * FROM users WHERE id = ?", ar -> { + .prepare("SELECT * FROM users WHERE id = ?") + .onComplete(ar -> { if (ar.succeeded()) { PreparedStatement preparedStatement = ar.result(); preparedStatement.query() - .execute(Tuple.of("julien"), ar2 -> { + .execute(Tuple.of("julien")) + .onComplete(ar2 -> { if (ar2.succeeded()) { RowSet rows = ar2.result(); System.out.println("Got " + rows.size() + " rows "); @@ -267,7 +275,9 @@ public void transaction03(Pool pool) { } public void usingCursors01(SqlConnection connection) { - connection.prepare("SELECT * FROM users WHERE age > ?", ar1 -> { + connection + .prepare("SELECT * FROM users WHERE age > ?") + .onComplete(ar1 -> { if (ar1.succeeded()) { PreparedStatement pq = ar1.result(); @@ -275,7 +285,9 @@ public void usingCursors01(SqlConnection connection) { Cursor cursor = pq.cursor(Tuple.of(18)); // Read 50 rows - cursor.read(50, ar2 -> { + cursor + .read(50) + .onComplete(ar2 -> { if (ar2.succeeded()) { RowSet rows = ar2.result(); @@ -293,7 +305,9 @@ public void usingCursors01(SqlConnection connection) { } public void usingCursors02(Cursor cursor) { - cursor.read(50, ar2 -> { + cursor + .read(50) + .onComplete(ar2 -> { if (ar2.succeeded()) { // Close the cursor cursor.close(); @@ -302,7 +316,9 @@ public void usingCursors02(Cursor cursor) { } public void usingCursors03(SqlConnection connection) { - connection.prepare("SELECT * FROM users WHERE age > ?", ar1 -> { + connection + .prepare("SELECT * FROM users WHERE age > ?") + .onComplete(ar1 -> { if (ar1.succeeded()) { PreparedStatement pq = ar1.result(); diff --git a/vertx-pg-client/src/main/java/examples/PgClientExamples.java b/vertx-pg-client/src/main/java/examples/PgClientExamples.java index 02b323330..0080d3a87 100644 --- a/vertx-pg-client/src/main/java/examples/PgClientExamples.java +++ b/vertx-pg-client/src/main/java/examples/PgClientExamples.java @@ -64,17 +64,18 @@ public void gettingStarted() { // A simple query client .query("SELECT * FROM users WHERE id='julien'") - .execute(ar -> { - if (ar.succeeded()) { - RowSet result = ar.result(); - System.out.println("Got " + result.size() + " rows "); - } else { - System.out.println("Failure: " + ar.cause().getMessage()); - } + .execute() + .onComplete(ar -> { + if (ar.succeeded()) { + RowSet result = ar.result(); + System.out.println("Got " + result.size() + " rows "); + } else { + System.out.println("Failure: " + ar.cause().getMessage()); + } - // Now close the pool - client.close(); - }); + // Now close the pool + client.close(); + }); } public void configureFromEnv(Vertx vertx) { @@ -83,9 +84,10 @@ public void configureFromEnv(Vertx vertx) { PgPool pool = PgPool.pool(); // Create the connection from the environment variables - PgConnection.connect(vertx, res -> { - // Handling your connection - }); + PgConnection.connect(vertx) + .onComplete(res -> { + // Handling your connection + }); } public void configureFromDataObject(Vertx vertx) { @@ -104,9 +106,10 @@ public void configureFromDataObject(Vertx vertx) { // Create the pool from the data object PgPool pool = PgPool.pool(vertx, connectOptions, poolOptions); - pool.getConnection(ar -> { - // Handling your connection - }); + pool.getConnection() + .onComplete(ar -> { + // Handling your connection + }); } public void configureDefaultSchema() { @@ -128,9 +131,11 @@ public void configureFromUri(Vertx vertx) { PgPool pool = PgPool.pool(connectionUri); // Create the connection from the connection URI - PgConnection.connect(vertx, connectionUri, res -> { - // Handling your connection - }); + PgConnection + .connect(vertx, connectionUri) + .onComplete(res -> { + // Handling your connection + }); } public void connecting01() { @@ -303,31 +308,33 @@ public void reconnectAttempts(PgConnectOptions options) { public void typeMapping01(Pool pool) { pool .query("SELECT 1::BIGINT \"VAL\"") - .execute(ar -> { - RowSet rowSet = ar.result(); - Row row = rowSet.iterator().next(); + .execute() + .onComplete(ar -> { + RowSet rowSet = ar.result(); + Row row = rowSet.iterator().next(); - // Stored as java.lang.Long - Object value = row.getValue(0); + // Stored as java.lang.Long + Object value = row.getValue(0); - // Convert to java.lang.Integer - Integer intValue = row.getInteger(0); - }); + // Convert to java.lang.Integer + Integer intValue = row.getInteger(0); + }); } public void typeMapping02(Pool pool) { pool .query("SELECT 1::BIGINT \"VAL\"") - .execute(ar -> { - RowSet rowSet = ar.result(); - Row row = rowSet.iterator().next(); + .execute() + .onComplete(ar -> { + RowSet rowSet = ar.result(); + Row row = rowSet.iterator().next(); - // Stored as java.lang.Long - Object value = row.getValue(0); + // Stored as java.lang.Long + Object value = row.getValue(0); - // Convert to java.lang.Integer - Integer intValue = row.getInteger(0); - }); + // Convert to java.lang.Integer + Integer intValue = row.getInteger(0); + }); } public void pubsub01(PgConnection connection) { @@ -338,7 +345,8 @@ public void pubsub01(PgConnection connection) { connection .query("LISTEN some-channel") - .execute(ar -> { + .execute() + .onComplete(ar -> { System.out.println("Subscribed to channel"); }); } @@ -358,7 +366,9 @@ public void pubsub02(Vertx vertx) { System.out.println("Received " + payload); }); - subscriber.connect(ar -> { + subscriber + .connect() + .onComplete(ar -> { if (ar.succeeded()) { // Or you can set the channel after connect @@ -379,7 +389,9 @@ public void pubsub03(Vertx vertx) { .setPassword("secret") ); - subscriber.connect(ar -> { + subscriber + .connect() + .onComplete(ar -> { if (ar.succeeded()) { // Complex channel name - name in PostgreSQL requires a quoted ID subscriber.channel("Complex.Channel.Name").handler(payload -> { @@ -388,7 +400,8 @@ public void pubsub03(Vertx vertx) { subscriber.channel("Complex.Channel.Name").subscribeHandler(subscribed -> { subscriber.actualConnection() .query("NOTIFY \"Complex.Channel.Name\", 'msg'") - .execute(notified -> { + .execute() + .onComplete(notified -> { System.out.println("Notified \"Complex.Channel.Name\""); }); }); @@ -401,7 +414,8 @@ public void pubsub03(Vertx vertx) { // The following simple channel identifier is forced to lower case subscriber.actualConnection() .query("NOTIFY Simple_CHANNEL, 'msg'") - .execute(notified -> { + .execute() + .onComplete(notified -> { System.out.println("Notified simple_channel"); }); }); @@ -453,7 +467,9 @@ public void ex10(Vertx vertx) { .setSslMode(SslMode.VERIFY_CA) .setPemTrustOptions(new PemTrustOptions().addCertPath("/path/to/cert.pem")); - PgConnection.connect(vertx, options, res -> { + PgConnection + .connect(vertx, options) + .onComplete(res -> { if (res.succeeded()) { // Connected with SSL } else { @@ -504,7 +520,8 @@ public void arrayExample() { public void infinitySpecialValue(SqlClient client) { client .query("SELECT 'infinity'::DATE \"LocalDate\"") - .execute(ar -> { + .execute() + .onComplete(ar -> { if (ar.succeeded()) { Row row = ar.result().iterator().next(); System.out.println(row.getLocalDate("LocalDate").equals(LocalDate.MAX)); @@ -517,7 +534,8 @@ public void infinitySpecialValue(SqlClient client) { public void customType01Example(SqlClient client) { client .preparedQuery("SELECT address, (address).city FROM address_book WHERE id=$1") - .execute(Tuple.of(3), ar -> { + .execute(Tuple.of(3)) + .onComplete(ar -> { if (ar.succeeded()) { RowSet rows = ar.result(); for (Row row : rows) { @@ -532,7 +550,8 @@ public void customType01Example(SqlClient client) { public void customType02Example(SqlClient client) { client .preparedQuery("INSERT INTO address_book (id, address) VALUES ($1, $2)") - .execute(Tuple.of(3, "('Anytown', 'Second Ave', false)"), ar -> { + .execute(Tuple.of(3, "('Anytown', 'Second Ave', false)")) + .onComplete(ar -> { if (ar.succeeded()) { RowSet rows = ar.result(); System.out.println(rows.rowCount()); @@ -546,7 +565,8 @@ public void customType02Example(SqlClient client) { public void tsQuery01Example(SqlClient client) { client .preparedQuery("SELECT to_tsvector( $1 ) @@ to_tsquery( $2 )") - .execute(Tuple.of("fat cats ate fat rats", "fat & rat"), ar -> { + .execute(Tuple.of("fat cats ate fat rats", "fat & rat")) + .onComplete(ar -> { if (ar.succeeded()) { RowSet rows = ar.result(); for (Row row : rows) { @@ -561,7 +581,8 @@ public void tsQuery01Example(SqlClient client) { public void tsQuery02Example(SqlClient client) { client .preparedQuery("SELECT to_tsvector( $1 ), to_tsquery( $2 )") - .execute(Tuple.of("fat cats ate fat rats", "fat & rat"), ar -> { + .execute(Tuple.of("fat cats ate fat rats", "fat & rat")) + .onComplete(ar -> { if (ar.succeeded()) { RowSet rows = ar.result(); for (Row row : rows) { @@ -576,7 +597,8 @@ public void tsQuery02Example(SqlClient client) { public void enumeratedType01Example(SqlClient client) { client .preparedQuery("INSERT INTO colors VALUES ($2)") - .execute(Tuple.of("red"), res -> { + .execute(Tuple.of("red")) + .onComplete(res -> { // ... }); } @@ -613,7 +635,8 @@ public void collector01Example(SqlClient client) { // Run the query with the collector client.query("SELECT * FROM users") .collecting(collector) - .execute(ar -> { + .execute() + .onComplete(ar -> { if (ar.succeeded()) { SqlResult> result = ar.result(); @@ -635,7 +658,11 @@ public void collector02Example(SqlClient client) { ); // Run the query with the collector - client.query("SELECT * FROM users").collecting(collector).execute(ar -> { + client + .query("SELECT * FROM users") + .collecting(collector) + .execute() + .onComplete(ar -> { if (ar.succeeded()) { SqlResult result = ar.result(); @@ -651,7 +678,8 @@ public void collector02Example(SqlClient client) { public void cancelRequest(PgConnection connection) { connection .query("SELECT pg_sleep(20)") - .execute(ar -> { + .execute() + .onComplete(ar -> { if (ar.succeeded()) { // imagine this is a long query and is still running System.out.println("Query success"); @@ -660,7 +688,9 @@ public void cancelRequest(PgConnection connection) { System.out.println("Failed to query due to " + ar.cause().getMessage()); } }); - connection.cancelRequest(ar -> { + connection + .cancelRequest() + .onComplete(ar -> { if (ar.succeeded()) { System.out.println("Cancelling request has been sent"); } else { diff --git a/vertx-pg-client/src/main/java/examples/SqlClientExamples.java b/vertx-pg-client/src/main/java/examples/SqlClientExamples.java index f9fe80b92..a0890bebc 100644 --- a/vertx-pg-client/src/main/java/examples/SqlClientExamples.java +++ b/vertx-pg-client/src/main/java/examples/SqlClientExamples.java @@ -46,7 +46,8 @@ public class SqlClientExamples { public void queries01(SqlClient client) { client .query("SELECT * FROM users WHERE id='julien'") - .execute(ar -> { + .execute() + .onComplete(ar -> { if (ar.succeeded()) { RowSet result = ar.result(); System.out.println("Got " + result.size() + " rows "); @@ -60,7 +61,8 @@ public void queries01(SqlClient client) { public void queries02(SqlClient client) { client .preparedQuery("SELECT * FROM users WHERE id=$1") - .execute(Tuple.of("julien"), ar -> { + .execute(Tuple.of("julien")) + .onComplete(ar -> { if (ar.succeeded()) { RowSet rows = ar.result(); System.out.println("Got " + rows.size() + " rows "); @@ -73,7 +75,8 @@ public void queries02(SqlClient client) { public void queries03(SqlClient client) { client .preparedQuery("SELECT first_name, last_name FROM users") - .execute(ar -> { + .execute() + .onComplete(ar -> { if (ar.succeeded()) { RowSet rows = ar.result(); for (Row row : rows) { @@ -88,7 +91,8 @@ public void queries03(SqlClient client) { public void queries04(SqlClient client) { client .preparedQuery("INSERT INTO users (first_name, last_name) VALUES ($1, $2)") - .execute(Tuple.of("Julien", "Viet"), ar -> { + .execute(Tuple.of("Julien", "Viet")) + .onComplete(ar -> { if (ar.succeeded()) { RowSet rows = ar.result(); System.out.println(rows.rowCount()); @@ -126,7 +130,8 @@ public void queries08(SqlClient client) { // Execute the prepared batch client .preparedQuery("INSERT INTO USERS (id, name) VALUES ($1, $2)") - .executeBatch(batch, res -> { + .executeBatch(batch) + .onComplete(res -> { if (res.succeeded()) { // Process rows @@ -143,7 +148,8 @@ public void queries09(SqlClient client, SqlConnectOptions connectOptions) { connectOptions.setCachePreparedStatements(true); client .preparedQuery("SELECT * FROM users WHERE id = $1") - .execute(Tuple.of("julien"), ar -> { + .execute(Tuple.of("julien")) + .onComplete(ar -> { if (ar.succeeded()) { RowSet rows = ar.result(); System.out.println("Got " + rows.size() + " rows "); @@ -155,11 +161,13 @@ public void queries09(SqlClient client, SqlConnectOptions connectOptions) { public void queries10(SqlConnection sqlConnection) { sqlConnection - .prepare("SELECT * FROM users WHERE id = $1", ar -> { + .prepare("SELECT * FROM users WHERE id = $1") + .onComplete(ar -> { if (ar.succeeded()) { PreparedStatement preparedStatement = ar.result(); preparedStatement.query() - .execute(Tuple.of("julien"), ar2 -> { + .execute(Tuple.of("julien")) + .onComplete(ar2 -> { if (ar2.succeeded()) { RowSet rows = ar2.result(); System.out.println("Got " + rows.size() + " rows "); @@ -271,12 +279,16 @@ public void transaction03(Pool pool) { } public void usingCursors01(SqlConnection connection) { - connection.prepare("SELECT * FROM users WHERE first_name LIKE $1", ar0 -> { + connection + .prepare("SELECT * FROM users WHERE first_name LIKE $1") + .onComplete(ar0 -> { if (ar0.succeeded()) { PreparedStatement pq = ar0.result(); // Cursors require to run within a transaction - connection.begin(ar1 -> { + connection + .begin() + .onComplete(ar1 -> { if (ar1.succeeded()) { Transaction tx = ar1.result(); @@ -284,7 +296,7 @@ public void usingCursors01(SqlConnection connection) { Cursor cursor = pq.cursor(Tuple.of("julien")); // Read 50 rows - cursor.read(50, ar2 -> { + cursor.read(50).onComplete(ar2 -> { if (ar2.succeeded()) { RowSet rows = ar2.result(); @@ -304,7 +316,9 @@ public void usingCursors01(SqlConnection connection) { } public void usingCursors02(Cursor cursor) { - cursor.read(50, ar2 -> { + cursor + .read(50) + .onComplete(ar2 -> { if (ar2.succeeded()) { // Close the cursor cursor.close(); @@ -313,12 +327,16 @@ public void usingCursors02(Cursor cursor) { } public void usingCursors03(SqlConnection connection) { - connection.prepare("SELECT * FROM users WHERE first_name LIKE $1", ar0 -> { + connection + .prepare("SELECT * FROM users WHERE first_name LIKE $1") + .onComplete(ar0 -> { if (ar0.succeeded()) { PreparedStatement pq = ar0.result(); // Streams require to run within a transaction - connection.begin(ar1 -> { + connection + .begin() + .onComplete(ar1 -> { if (ar1.succeeded()) { Transaction tx = ar1.result(); @@ -331,8 +349,11 @@ public void usingCursors03(SqlConnection connection) { }); stream.endHandler(v -> { // Close the stream to release the resources in the database - stream.close(closed -> { - tx.commit(committed -> { + stream + .close() + .onComplete(closed -> { + tx.commit() + .onComplete(committed -> { System.out.println("End of stream"); }); }); diff --git a/vertx-pg-client/src/main/java/io/vertx/pgclient/PgConnection.java b/vertx-pg-client/src/main/java/io/vertx/pgclient/PgConnection.java index 172eeef99..57c7de2f3 100644 --- a/vertx-pg-client/src/main/java/io/vertx/pgclient/PgConnection.java +++ b/vertx-pg-client/src/main/java/io/vertx/pgclient/PgConnection.java @@ -128,6 +128,11 @@ static Future connect(Vertx vertx, String connectionUri) { @Deprecated PgConnection cancelRequest(Handler> handler); + /** + * Like {@link #cancelRequest(Handler)} but returns a {@code Future} of the asynchronous result + */ + Future cancelRequest(); + /** * @return The process ID of the target backend */ diff --git a/vertx-pg-client/src/main/java/io/vertx/pgclient/impl/PgConnectionImpl.java b/vertx-pg-client/src/main/java/io/vertx/pgclient/impl/PgConnectionImpl.java index b327c8559..013cb662e 100644 --- a/vertx-pg-client/src/main/java/io/vertx/pgclient/impl/PgConnectionImpl.java +++ b/vertx-pg-client/src/main/java/io/vertx/pgclient/impl/PgConnectionImpl.java @@ -126,6 +126,11 @@ public int secretKey() { return conn.getSecretKey(); } + @Override + public Future cancelRequest() { + return Future.future(this::cancelRequest); + } + @Override public PgConnection cancelRequest(Handler> handler) { Context current = Vertx.currentContext(); diff --git a/vertx-sql-client/src/main/java/examples/SqlClientExamples.java b/vertx-sql-client/src/main/java/examples/SqlClientExamples.java index a330d7013..663b7c0f0 100644 --- a/vertx-sql-client/src/main/java/examples/SqlClientExamples.java +++ b/vertx-sql-client/src/main/java/examples/SqlClientExamples.java @@ -46,7 +46,8 @@ public class SqlClientExamples { public void queries01(SqlClient client) { client .query("SELECT * FROM users WHERE id='julien'") - .execute(ar -> { + .execute() + .onComplete(ar -> { if (ar.succeeded()) { RowSet result = ar.result(); System.out.println("Got " + result.size() + " rows "); @@ -60,7 +61,8 @@ public void queries01(SqlClient client) { public void queries02(SqlClient client) { client .preparedQuery("SELECT * FROM users WHERE id=$1") - .execute(Tuple.of("julien"), ar -> { + .execute(Tuple.of("julien")) + .onComplete(ar -> { if (ar.succeeded()) { RowSet rows = ar.result(); System.out.println("Got " + rows.size() + " rows "); @@ -73,7 +75,8 @@ public void queries02(SqlClient client) { public void queries03(SqlClient client) { client .preparedQuery("SELECT first_name, last_name FROM users") - .execute(ar -> { + .execute() + .onComplete(ar -> { if (ar.succeeded()) { RowSet rows = ar.result(); for (Row row : rows) { @@ -88,7 +91,8 @@ public void queries03(SqlClient client) { public void queries04(SqlClient client) { client .preparedQuery("INSERT INTO users (first_name, last_name) VALUES ($1, $2)") - .execute(Tuple.of("Julien", "Viet"), ar -> { + .execute(Tuple.of("Julien", "Viet")) + .onComplete(ar -> { if (ar.succeeded()) { RowSet rows = ar.result(); System.out.println(rows.rowCount()); @@ -126,7 +130,8 @@ public void queries08(SqlClient client) { // Execute the prepared batch client .preparedQuery("INSERT INTO USERS (id, name) VALUES ($1, $2)") - .executeBatch(batch, res -> { + .executeBatch(batch) + .onComplete(res -> { if (res.succeeded()) { // Process rows @@ -143,7 +148,8 @@ public void queries09(SqlClient client, SqlConnectOptions connectOptions) { connectOptions.setCachePreparedStatements(true); client .preparedQuery("SELECT * FROM users WHERE id=$1") - .execute(Tuple.of("julien"), ar -> { + .execute(Tuple.of("julien")) + .onComplete(ar -> { if (ar.succeeded()) { RowSet rows = ar.result(); System.out.println("Got " + rows.size() + " rows "); @@ -155,11 +161,13 @@ public void queries09(SqlClient client, SqlConnectOptions connectOptions) { public void queries10(SqlConnection sqlConnection) { sqlConnection - .prepare("SELECT * FROM users WHERE id=$1", ar -> { + .prepare("SELECT * FROM users WHERE id=$1") + .onComplete(ar -> { if (ar.succeeded()) { PreparedStatement preparedStatement = ar.result(); preparedStatement.query() - .execute(Tuple.of("julien"), ar2 -> { + .execute(Tuple.of("julien")) + .onComplete(ar2 -> { if (ar2.succeeded()) { RowSet rows = ar2.result(); System.out.println("Got " + rows.size() + " rows "); @@ -176,17 +184,20 @@ public void queries10(SqlConnection sqlConnection) { public void usingConnections01(Vertx vertx, Pool pool) { - pool.getConnection(ar1 -> { + pool.getConnection() + .onComplete(ar1 -> { if (ar1.succeeded()) { SqlConnection connection = ar1.result(); connection .query("SELECT * FROM users WHERE id='julien'") - .execute(ar2 -> { + .execute() + .onComplete(ar2 -> { if (ar1.succeeded()) { connection .query("SELECT * FROM users WHERE id='paulo'") - .execute(ar3 -> { + .execute() + .onComplete(ar3 -> { // Do something with rows and return the connection to the pool connection.close(); }); @@ -200,10 +211,13 @@ public void usingConnections01(Vertx vertx, Pool pool) { } public void usingConnections02(SqlConnection connection) { - connection.prepare("SELECT * FROM users WHERE first_name LIKE $1", ar1 -> { + connection.prepare("SELECT * FROM users WHERE first_name LIKE $1") + .onComplete(ar1 -> { if (ar1.succeeded()) { PreparedStatement pq = ar1.result(); - pq.query().execute(Tuple.of("julien"), ar2 -> { + pq.query() + .execute(Tuple.of("julien")) + .onComplete(ar2 -> { if (ar2.succeeded()) { // All rows RowSet rows = ar2.result(); @@ -232,28 +246,35 @@ public void usingConnections03(Pool pool) { } public void transaction01(Pool pool) { - pool.getConnection(res -> { + pool + .getConnection() + .onComplete(res -> { if (res.succeeded()) { // Transaction must use a connection SqlConnection conn = res.result(); // Begin the transaction - conn.begin(ar0 -> { + conn + .begin() + .onComplete(ar0 -> { if (ar0.succeeded()) { Transaction tx = ar0.result(); // Various statements conn .query("INSERT INTO Users (first_name,last_name) VALUES ('Julien','Viet')") - .execute(ar1 -> { + .execute() + .onComplete(ar1 -> { if (ar1.succeeded()) { conn .query("INSERT INTO Users (first_name,last_name) VALUES ('Emad','Alblueshi')") - .execute(ar2 -> { + .execute() + .onComplete(ar2 -> { if (ar2.succeeded()) { // Commit the transaction - tx.commit(ar3 -> { + tx.commit() + .onComplete(ar3 -> { if (ar3.succeeded()) { System.out.println("Transaction succeeded"); } else { @@ -312,12 +333,16 @@ public void transaction03(Pool pool) { } public void usingCursors01(SqlConnection connection) { - connection.prepare("SELECT * FROM users WHERE first_name LIKE $1", ar0 -> { + connection + .prepare("SELECT * FROM users WHERE first_name LIKE $1") + .onComplete(ar0 -> { if (ar0.succeeded()) { PreparedStatement pq = ar0.result(); // Cursors require to run within a transaction - connection.begin(ar1 -> { + connection + .begin() + .onComplete(ar1 -> { if (ar1.succeeded()) { Transaction tx = ar1.result(); @@ -325,7 +350,9 @@ public void usingCursors01(SqlConnection connection) { Cursor cursor = pq.cursor(Tuple.of("julien")); // Read 50 rows - cursor.read(50, ar2 -> { + cursor + .read(50) + .onComplete(ar2 -> { if (ar2.succeeded()) { RowSet rows = ar2.result(); @@ -345,7 +372,9 @@ public void usingCursors01(SqlConnection connection) { } public void usingCursors02(Cursor cursor) { - cursor.read(50, ar2 -> { + cursor + .read(50) + .onComplete(ar2 -> { if (ar2.succeeded()) { // Close the cursor cursor.close(); @@ -354,12 +383,16 @@ public void usingCursors02(Cursor cursor) { } public void usingCursors03(SqlConnection connection) { - connection.prepare("SELECT * FROM users WHERE first_name LIKE $1", ar0 -> { + connection + .prepare("SELECT * FROM users WHERE first_name LIKE $1") + .onComplete(ar0 -> { if (ar0.succeeded()) { PreparedStatement pq = ar0.result(); // Streams require to run within a transaction - connection.begin(ar1 -> { + connection + .begin() + .onComplete(ar1 -> { if (ar1.succeeded()) { Transaction tx = ar1.result(); From 98a435dca381f2de3ed4d60166f2767b8d426de3 Mon Sep 17 00:00:00 2001 From: Julien Viet Date: Sun, 12 Mar 2023 22:40:47 +0100 Subject: [PATCH 2/3] Remove callbase usage in implementation --- .../impl/MySQLSocketConnection.java | 5 +++-- .../codec/InitialHandshakeCommandCodec.java | 2 +- .../pgclient/impl/InitiateSslHandler.java | 19 +++++++++---------- .../pgclient/impl/PgSocketConnection.java | 2 +- .../impl/pubsub/PgSubscriberImpl.java | 8 ++++---- .../templates/impl/SqlTemplateImpl.java | 6 ++++-- .../io/vertx/sqlclient/impl/PoolImpl.java | 2 +- .../vertx/sqlclient/impl/RowStreamImpl.java | 4 ++-- 8 files changed, 25 insertions(+), 23 deletions(-) diff --git a/vertx-mysql-client/src/main/java/io/vertx/mysqlclient/impl/MySQLSocketConnection.java b/vertx-mysql-client/src/main/java/io/vertx/mysqlclient/impl/MySQLSocketConnection.java index e1471f551..e422efdfe 100644 --- a/vertx-mysql-client/src/main/java/io/vertx/mysqlclient/impl/MySQLSocketConnection.java +++ b/vertx-mysql-client/src/main/java/io/vertx/mysqlclient/impl/MySQLSocketConnection.java @@ -19,6 +19,7 @@ import io.netty.channel.ChannelPipeline; import io.vertx.core.AsyncResult; +import io.vertx.core.Future; import io.vertx.core.Handler; import io.vertx.core.Promise; import io.vertx.core.buffer.Buffer; @@ -99,8 +100,8 @@ protected void doSchedule(CommandBase cmd, Handler> handle } } - public void upgradeToSsl(Handler> completionHandler) { - socket.upgradeToSsl(completionHandler); + public Future upgradeToSsl() { + return socket.upgradeToSsl(); } @Override diff --git a/vertx-mysql-client/src/main/java/io/vertx/mysqlclient/impl/codec/InitialHandshakeCommandCodec.java b/vertx-mysql-client/src/main/java/io/vertx/mysqlclient/impl/codec/InitialHandshakeCommandCodec.java index 1a8e7134c..0973fce36 100644 --- a/vertx-mysql-client/src/main/java/io/vertx/mysqlclient/impl/codec/InitialHandshakeCommandCodec.java +++ b/vertx-mysql-client/src/main/java/io/vertx/mysqlclient/impl/codec/InitialHandshakeCommandCodec.java @@ -143,7 +143,7 @@ private void handleInitialHandshake(ByteBuf payload) { encoder.clientCapabilitiesFlag |= CLIENT_SSL; sendSslRequest(); - encoder.socketConnection.upgradeToSsl(upgrade -> { + encoder.socketConnection.upgradeToSsl().onComplete(upgrade -> { if (upgrade.succeeded()) { doSendHandshakeResponseMessage(serverAuthPluginName, cmd.authenticationPlugin(), authPluginData, serverCapabilitiesFlags); } else { diff --git a/vertx-pg-client/src/main/java/io/vertx/pgclient/impl/InitiateSslHandler.java b/vertx-pg-client/src/main/java/io/vertx/pgclient/impl/InitiateSslHandler.java index 45e260092..b4819dc0a 100644 --- a/vertx-pg-client/src/main/java/io/vertx/pgclient/impl/InitiateSslHandler.java +++ b/vertx-pg-client/src/main/java/io/vertx/pgclient/impl/InitiateSslHandler.java @@ -59,18 +59,17 @@ public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception byteBuf.release(); switch (b) { case PgProtocolConstants.MESSAGE_TYPE_SSL_YES: { - Handler handler = o -> { - if (o instanceof AsyncResult) { - AsyncResult res = (AsyncResult) o; - if (res.failed()) { + conn + .socket() + .upgradeToSsl() + .onComplete(ar -> { + if (ar.succeeded()) { + ctx.pipeline().remove(this); + upgradePromise.complete(); + } else { // Connection close will fail the promise - return; } - } - ctx.pipeline().remove(this); - upgradePromise.complete(); - }; - conn.socket().upgradeToSsl(handler); + }); break; } case PgProtocolConstants.MESSAGE_TYPE_SSL_NO: { diff --git a/vertx-pg-client/src/main/java/io/vertx/pgclient/impl/PgSocketConnection.java b/vertx-pg-client/src/main/java/io/vertx/pgclient/impl/PgSocketConnection.java index 8047b4608..2680e3ac2 100644 --- a/vertx-pg-client/src/main/java/io/vertx/pgclient/impl/PgSocketConnection.java +++ b/vertx-pg-client/src/main/java/io/vertx/pgclient/impl/PgSocketConnection.java @@ -85,7 +85,7 @@ void sendCancelRequestMessage(int processId, int secretKey, Handler { + socket.write(buffer).onComplete(ar -> { if (ar.succeeded()) { // directly close this connection if (status == Status.CONNECTED) { diff --git a/vertx-pg-client/src/main/java/io/vertx/pgclient/impl/pubsub/PgSubscriberImpl.java b/vertx-pg-client/src/main/java/io/vertx/pgclient/impl/pubsub/PgSubscriberImpl.java index e3f449a82..7856b7378 100644 --- a/vertx-pg-client/src/main/java/io/vertx/pgclient/impl/pubsub/PgSubscriberImpl.java +++ b/vertx-pg-client/src/main/java/io/vertx/pgclient/impl/pubsub/PgSubscriberImpl.java @@ -168,7 +168,7 @@ private void tryConnect(long delayMillis, Handler> handler) { } private void doConnect(Handler> completionHandler) { - PgConnection.connect(vertx, options, ar -> handleConnectResult(completionHandler, ar)); + PgConnection.connect(vertx, options).onComplete(ar -> handleConnectResult(completionHandler, ar)); } private synchronized void handleConnectResult(Handler> completionHandler, AsyncResult ar1) { @@ -191,7 +191,7 @@ private synchronized void handleConnectResult(Handler> complet return channel.quotedName; }) .collect(Collectors.joining(";LISTEN ", "LISTEN ", "")); - conn.query(sql).execute(ar2 -> { + conn.query(sql).execute().onComplete(ar2 -> { if (ar2.failed()) { log.error("Cannot LISTEN to channels", ar2.cause()); conn.close(); @@ -224,7 +224,7 @@ void add(ChannelImpl sub) { if (conn != null) { subscribed = true; String sql = "LISTEN " + quotedName; - conn.query(sql).execute(ar -> { + conn.query(sql).execute().onComplete(ar -> { if (ar.succeeded()) { Handler handler = sub.subscribeHandler; if (handler != null) { @@ -243,7 +243,7 @@ void remove(ChannelImpl sub) { if (subs.isEmpty()) { channels.remove(name, this); if (conn != null) { - conn.query("UNLISTEN " + quotedName).execute(ar -> { + conn.query("UNLISTEN " + quotedName).execute().onComplete(ar -> { if (ar.failed()) { log.error("Cannot UNLISTEN channel " + name, ar.cause()); } diff --git a/vertx-sql-client-templates/src/main/java/io/vertx/sqlclient/templates/impl/SqlTemplateImpl.java b/vertx-sql-client-templates/src/main/java/io/vertx/sqlclient/templates/impl/SqlTemplateImpl.java index f16134bcb..bcd11a20f 100644 --- a/vertx-sql-client-templates/src/main/java/io/vertx/sqlclient/templates/impl/SqlTemplateImpl.java +++ b/vertx-sql-client-templates/src/main/java/io/vertx/sqlclient/templates/impl/SqlTemplateImpl.java @@ -70,7 +70,8 @@ public void execute(I parameters, Handler> handler) { queryMapper .apply(client.preparedQuery(sqlTemplate.getSql())) - .execute(tupleMapper.apply(parameters), handler); + .execute(tupleMapper.apply(parameters)) + .onComplete(handler); } @Override @@ -86,7 +87,8 @@ public void executeBatch(List batch, Handler> handler) { .executeBatch(batch .stream() .map(tupleMapper) - .collect(Collectors.toList()), handler); + .collect(Collectors.toList())) + .onComplete(handler); } @Override diff --git a/vertx-sql-client/src/main/java/io/vertx/sqlclient/impl/PoolImpl.java b/vertx-sql-client/src/main/java/io/vertx/sqlclient/impl/PoolImpl.java index 833b10dd7..f6e84bf8f 100644 --- a/vertx-sql-client/src/main/java/io/vertx/sqlclient/impl/PoolImpl.java +++ b/vertx-sql-client/src/main/java/io/vertx/sqlclient/impl/PoolImpl.java @@ -175,7 +175,7 @@ public Future getConnection() { .compose(v -> context.failedFuture(err), failure -> context.failedFuture(err)); } })) - .onComplete(ar -> conn.close(v -> context.removeLocal(PROPAGATABLE_CONNECTION)))); + .onComplete(ar -> conn.close().onComplete(v -> context.removeLocal(PROPAGATABLE_CONNECTION)))); } @Override diff --git a/vertx-sql-client/src/main/java/io/vertx/sqlclient/impl/RowStreamImpl.java b/vertx-sql-client/src/main/java/io/vertx/sqlclient/impl/RowStreamImpl.java index fff7bb78d..99b3a53d3 100644 --- a/vertx-sql-client/src/main/java/io/vertx/sqlclient/impl/RowStreamImpl.java +++ b/vertx-sql-client/src/main/java/io/vertx/sqlclient/impl/RowStreamImpl.java @@ -90,7 +90,7 @@ public RowStream handler(Handler handler) { return this; } } - c.read(fetch, this); + c.read(fetch).onComplete(this); return this; } @@ -206,7 +206,7 @@ private void checkPending() { break; } else if (cursor.hasMore()) { readInProgress = true; - cursor.read(fetch, this); + cursor.read(fetch).onComplete(this); break; } else { cursor.close(); From 807ca6c520992717b8cfdfdf95067b064b10cabc Mon Sep 17 00:00:00 2001 From: Julien Viet Date: Mon, 13 Mar 2023 13:16:41 +0100 Subject: [PATCH 3/3] Remove callback usage in tests --- .../io/vertx/db2client/DB2DataTypeTest.java | 114 ++++--- .../vertx/db2client/DB2ErrorMessageTest.java | 92 ++++-- .../java/io/vertx/db2client/DB2PingTest.java | 4 +- .../io/vertx/db2client/DB2SecureTest.java | 5 +- .../db2client/DB2SimpleQueryUriTest.java | 2 +- .../java/io/vertx/db2client/DB2TestBase.java | 7 +- .../io/vertx/db2client/GeneratedKeysTest.java | 12 +- .../vertx/db2client/QueryVariationsTest.java | 102 +++--- .../io/vertx/db2client/TableJoinTest.java | 25 +- .../io/vertx/db2client/tck/ClientConfig.java | 6 +- .../tck/DB2BinaryDataTypeDecodeTest.java | 3 +- .../tck/DB2BinaryDataTypeEncodeTest.java | 6 +- .../db2client/tck/DB2PreparedBatchTest.java | 5 +- .../tck/DB2PreparedQueryCachedTest.java | 5 +- .../tck/DB2PreparedQueryTestBase.java | 5 +- .../tck/DB2SimpleQueryPooledTest.java | 5 +- .../db2client/tck/DB2SimpleQueryTest.java | 5 +- .../tck/DB2TextDataTypeDecodeTest.java | 5 +- .../db2client/tck/DB2TransactionTest.java | 7 +- .../mssqlclient/MSSQLConnectionTest.java | 23 +- .../mssqlclient/MSSQLEncryptionTestBase.java | 7 +- .../io/vertx/mssqlclient/MSSQLInfoTest.java | 8 +- .../MSSQLMultipleTdsPacketsTest.java | 10 +- .../vertx/mssqlclient/MSSQLQueriesTest.java | 64 ++-- .../data/MSSQLDataTypeTestBase.java | 30 +- .../vertx/mssqlclient/tck/ClientConfig.java | 4 +- .../tck/MSSQLPreparedQueryTest.java | 18 +- .../tck/MSSQLPreparedQueryTestBase.java | 14 +- .../io/vertx/mysqlclient/MySQLSetOption.java | 2 +- .../MySQLAuthenticationPluginTest.java | 9 +- .../MySQLBatchInsertExceptionTestBase.java | 9 +- .../MySQLClientCapabilitiesTest.java | 13 +- .../vertx/mysqlclient/MySQLCollationTest.java | 58 +++- .../mysqlclient/MySQLConnectionTest.java | 27 +- .../mysqlclient/MySQLConnectionTestBase.java | 77 +++-- .../io/vertx/mysqlclient/MySQLPoolTest.java | 85 +++-- .../MySQLPooledConnectionTest.java | 26 +- .../MySQLPreparedStatementTest.java | 120 +++++-- .../io/vertx/mysqlclient/MySQLQueryTest.java | 199 ++++++++--- .../mysqlclient/MySQLStoredProgramsTest.java | 112 +++++-- .../io/vertx/mysqlclient/MySQLTLSTest.java | 82 +++-- .../io/vertx/mysqlclient/MySQLTestBase.java | 6 +- .../MySQLUnixDomainSocketTest.java | 17 +- .../mysqlclient/MySQLUtilityCommandTest.java | 109 ++++-- .../data/DateTimeBinaryCodecTest.java | 38 ++- .../data/DateTimeTextCodecTest.java | 14 +- .../mysqlclient/data/JsonBinaryCodecTest.java | 43 ++- .../mysqlclient/data/JsonTextCodecTest.java | 26 +- .../data/MySQLDataTypeTestBase.java | 49 ++- .../data/SpatialBinaryCodecTest.java | 7 +- .../mysqlclient/data/StringDataTypeTest.java | 7 +- .../vertx/mysqlclient/tck/ClientConfig.java | 4 +- .../tck/MySQLBinaryDataTypeDecodeTest.java | 12 +- .../tck/MySQLBinaryDataTypeEncodeTest.java | 10 +- .../tck/MySQLTextDataTypeDecodeTest.java | 5 +- .../test/OracleBinaryDataTypesTest.java | 20 +- .../OracleBrokenPooledConnectionTest.java | 17 +- .../test/OracleColumnDescriptorTest.java | 24 +- .../test/OracleErrorSimpleTest.java | 8 +- .../test/OracleGeneratedKeysTest.java | 2 +- .../test/OracleGeneratedKeysTestBase.java | 12 +- .../oracleclient/test/OraclePoolTest.java | 100 ++++-- .../oracleclient/test/OracleQueriesTest.java | 7 +- .../oracleclient/test/tck/ClientConfig.java | 4 +- .../tck/OracleBinaryDataTypeEncodeTest.java | 6 +- .../test/tck/OracleCollectorTest.java | 19 +- .../test/tck/OraclePreparedBatchTest.java | 41 ++- .../test/tck/OracleTransactionTest.java | 6 +- .../vertx/pgclient/CloseConnectionTest.java | 10 +- .../java/io/vertx/pgclient/NoticeTest.java | 7 +- .../io/vertx/pgclient/PgClientTestBase.java | 39 ++- .../io/vertx/pgclient/PgConnectionTest.java | 48 ++- .../vertx/pgclient/PgConnectionTestBase.java | 72 ++-- .../pgclient/PgDatabaseMetadataTest.java | 4 +- .../io/vertx/pgclient/PgPipeliningTest.java | 8 +- .../java/io/vertx/pgclient/PgPoolTest.java | 127 +++++-- .../io/vertx/pgclient/PgPoolTestBase.java | 78 +++-- .../pgclient/PgPooledConnectionTest.java | 22 +- .../vertx/pgclient/PgScramConnectionTest.java | 4 +- .../java/io/vertx/pgclient/PgTestBase.java | 8 +- .../java/io/vertx/pgclient/PoolMultiTest.java | 9 +- .../pgclient/PreparedStatementCachedTest.java | 41 ++- .../pgclient/PreparedStatementTestBase.java | 151 +++++---- .../java/io/vertx/pgclient/PubSubTest.java | 46 ++- .../test/java/io/vertx/pgclient/RowTest.java | 52 +-- .../io/vertx/pgclient/SharedPoolTest.java | 17 +- .../test/java/io/vertx/pgclient/TLSTest.java | 21 +- .../vertx/pgclient/UnixDomainSocketTest.java | 19 +- .../vertx/pgclient/context/ContextTest.java | 15 +- .../BinaryDataTypesExtendedCodecTest.java | 14 +- .../data/BooleanTypeExtendedCodecTest.java | 32 +- .../data/CharacterTypesExtendedCodecTest.java | 69 ++-- .../data/CustomTypesExtendedCodecTest.java | 11 +- .../data/CustomTypesSimpleCodecTest.java | 6 +- .../vertx/pgclient/data/DataTypeTestBase.java | 2 +- .../data/DateTimeTypesExtendedCodecTest.java | 201 +++++------ .../data/DateTimeTypesSimpleCodecTest.java | 50 ++- .../EnumeratedTypesExtendedCodecTest.java | 71 ++-- .../data/EnumeratedTypesSimpleCodecTest.java | 6 +- .../ExtendedQueryDataTypeCodecTestBase.java | 24 +- .../data/GeometricTypesExtendedCodecTest.java | 31 +- .../io/vertx/pgclient/data/InetCodecTest.java | 34 +- .../io/vertx/pgclient/data/JavaEnumTest.java | 20 +- .../data/JsonTypesExtendedCodecTest.java | 29 +- .../data/JsonTypesSimpleCodecTest.java | 10 +- .../pgclient/data/NullSimpleCodecTest.java | 6 +- .../data/NumericTypesExtendedCodecTest.java | 312 +++++++++++------- .../data/NumericTypesSimpleCodecTest.java | 45 ++- .../PreparedStatementParamCoercionTest.java | 18 +- .../SimpleQueryDataTypeCodecTestBase.java | 32 +- .../data/TsTypesExtendedCodecTest.java | 55 +-- .../pgclient/data/TsTypesSimpleCodecTest.java | 49 ++- .../data/UUIDTypeExtendedCodecTest.java | 21 +- .../io/vertx/pgclient/tck/ClientConfig.java | 4 +- .../vertx/pgclient/tck/PgTransactionTest.java | 14 +- .../templates/DataObjectTypesTest.java | 2 +- .../sqlclient/templates/PgClientTest.java | 46 ++- .../templates/PgTemplateTestBase.java | 8 +- .../io/vertx/sqlclient/impl/PoolBase.java | 4 +- .../java/io/vertx/sqlclient/ProxyServer.java | 4 +- .../tck/BinaryDataTypeDecodeTestBase.java | 15 +- .../tck/BinaryDataTypeEncodeTestBase.java | 12 +- .../sqlclient/tck/CollectorTestBase.java | 11 +- .../tck/ConnectionAutoRetryTestBase.java | 2 +- .../sqlclient/tck/ConnectionTestBase.java | 18 +- .../vertx/sqlclient/tck/DataTypeTestBase.java | 2 +- .../vertx/sqlclient/tck/DriverTestBase.java | 12 +- .../vertx/sqlclient/tck/MetricsTestBase.java | 10 +- .../tck/NullValueEncodeTestBase.java | 7 +- .../tck/PipeliningQueryTestBase.java | 9 +- .../sqlclient/tck/PreparedBatchTestBase.java | 47 ++- .../tck/PreparedQueryCachedTestBase.java | 71 +++- .../sqlclient/tck/PreparedQueryTestBase.java | 105 ++++-- .../sqlclient/tck/SimpleQueryTestBase.java | 38 ++- .../tck/TextDataTypeDecodeTestBase.java | 5 +- .../vertx/sqlclient/tck/TracingTestBase.java | 24 +- .../sqlclient/tck/TransactionTestBase.java | 146 +++++--- 137 files changed, 3097 insertions(+), 1490 deletions(-) diff --git a/vertx-db2-client/src/test/java/io/vertx/db2client/DB2DataTypeTest.java b/vertx-db2-client/src/test/java/io/vertx/db2client/DB2DataTypeTest.java index a07ffc9fd..354fac8ea 100644 --- a/vertx-db2-client/src/test/java/io/vertx/db2client/DB2DataTypeTest.java +++ b/vertx-db2-client/src/test/java/io/vertx/db2client/DB2DataTypeTest.java @@ -37,12 +37,12 @@ public class DB2DataTypeTest extends DB2TestBase { - // Enum for enum testing + // Enum for enum testing enum Days { MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY } - + /** * In DB2 the FLOAT and DOUBLE column types both map to an 8-byte * double-precision column (i.e. Java double). Ensure that a Java @@ -51,10 +51,14 @@ enum Days { @Test public void testFloatIntoFloatColumn(TestContext ctx) { connect(ctx.asyncAssertSuccess(conn -> { - conn.preparedQuery("INSERT INTO db2_types (id,test_float) VALUES (?, ?)") - .execute(Tuple.of(1, 5.0f), ctx.asyncAssertSuccess(insertResult -> { - conn.preparedQuery("SELECT id,test_float FROM db2_types WHERE id = 1") - .execute(ctx.asyncAssertSuccess(rows -> { + conn + .preparedQuery("INSERT INTO db2_types (id,test_float) VALUES (?, ?)") + .execute(Tuple.of(1, 5.0f)) + .onComplete(ctx.asyncAssertSuccess(insertResult -> { + conn + .preparedQuery("SELECT id,test_float FROM db2_types WHERE id = 1") + .execute() + .onComplete(ctx.asyncAssertSuccess(rows -> { ctx.assertEquals(1, rows.size()); Row row = rows.iterator().next(); ctx.assertEquals(1, row.getInteger(0)); @@ -72,10 +76,14 @@ public void testFloatIntoFloatColumn(TestContext ctx) { @Test public void testByteIntoSmallIntColumn(TestContext ctx) { connect(ctx.asyncAssertSuccess(conn -> { - conn.preparedQuery("INSERT INTO db2_types (id,test_byte) VALUES (?, ?)") - .execute(Tuple.of(2, (byte) 0xCA), ctx.asyncAssertSuccess(insertResult -> { - conn.preparedQuery("SELECT id,test_byte FROM db2_types WHERE id = 2") - .execute(ctx.asyncAssertSuccess(rows -> { + conn + .preparedQuery("INSERT INTO db2_types (id,test_byte) VALUES (?, ?)") + .execute(Tuple.of(2, (byte) 0xCA)) + .onComplete(ctx.asyncAssertSuccess(insertResult -> { + conn + .preparedQuery("SELECT id,test_byte FROM db2_types WHERE id = 2") + .execute() + .onComplete(ctx.asyncAssertSuccess(rows -> { ctx.assertEquals(1, rows.size()); Row row = rows.iterator().next(); ctx.assertEquals(2, row.getInteger(0)); @@ -89,10 +97,14 @@ public void testByteIntoSmallIntColumn(TestContext ctx) { public void testByteArrayIntoVarchar(TestContext ctx) { byte[] expected = "hello world".getBytes(); connect(ctx.asyncAssertSuccess(conn -> { - conn.preparedQuery("INSERT INTO db2_types (id,test_bytes) VALUES (?, ?)") - .execute(Tuple.of(3, "hello world".getBytes()), ctx.asyncAssertSuccess(insertResult -> { - conn.preparedQuery("SELECT id,test_bytes FROM db2_types WHERE id = 3") - .execute(ctx.asyncAssertSuccess(rows -> { + conn + .preparedQuery("INSERT INTO db2_types (id,test_bytes) VALUES (?, ?)") + .execute(Tuple.of(3, "hello world".getBytes())) + .onComplete(ctx.asyncAssertSuccess(insertResult -> { + conn + .preparedQuery("SELECT id,test_bytes FROM db2_types WHERE id = 3") + .execute() + .onComplete(ctx.asyncAssertSuccess(rows -> { ctx.assertEquals(1, rows.size()); Row row = rows.iterator().next(); ctx.assertEquals(3, row.getInteger(0)); @@ -108,10 +120,14 @@ public void testByteArrayIntoVarchar(TestContext ctx) { public void testByteBufIntoVarchar(TestContext ctx) { byte[] expected = "hello world".getBytes(); connect(ctx.asyncAssertSuccess(conn -> { - conn.preparedQuery("INSERT INTO db2_types (id,test_bytes) VALUES (?, ?)") - .execute(Tuple.of(4, Buffer.buffer(expected)), ctx.asyncAssertSuccess(insertResult -> { - conn.preparedQuery("SELECT id,test_bytes FROM db2_types WHERE id = 4") - .execute(ctx.asyncAssertSuccess(rows -> { + conn + .preparedQuery("INSERT INTO db2_types (id,test_bytes) VALUES (?, ?)") + .execute(Tuple.of(4, Buffer.buffer(expected))) + .onComplete(ctx.asyncAssertSuccess(insertResult -> { + conn + .preparedQuery("SELECT id,test_bytes FROM db2_types WHERE id = 4") + .execute() + .onComplete(ctx.asyncAssertSuccess(rows -> { ctx.assertEquals(1, rows.size()); Row row = rows.iterator().next(); ctx.assertEquals(4, row.getInteger(0)); @@ -127,10 +143,14 @@ public void testByteBufIntoVarchar(TestContext ctx) { public void testTimestamp(TestContext ctx) { LocalDateTime now = LocalDateTime.now(); connect(ctx.asyncAssertSuccess(conn -> { - conn.preparedQuery("INSERT INTO db2_types (id,test_tstamp) VALUES (?,?)") - .execute(Tuple.of(5, now), ctx.asyncAssertSuccess(insertResult -> { - conn.preparedQuery("SELECT id,test_tstamp FROM db2_types WHERE id = ?") - .execute(Tuple.of(5), ctx.asyncAssertSuccess(rows -> { + conn + .preparedQuery("INSERT INTO db2_types (id,test_tstamp) VALUES (?,?)") + .execute(Tuple.of(5, now)) + .onComplete(ctx.asyncAssertSuccess(insertResult -> { + conn + .preparedQuery("SELECT id,test_tstamp FROM db2_types WHERE id = ?") + .execute(Tuple.of(5)) + .onComplete(ctx.asyncAssertSuccess(rows -> { ctx.assertEquals(1, rows.size()); Row row = rows.iterator().next(); int nowNanos = now.getNano() - (1000 * now.get(ChronoField.MICRO_OF_SECOND)); @@ -146,9 +166,15 @@ public void testTimestamp(TestContext ctx) { public void testUUID(TestContext ctx) { UUID uuid = UUID.randomUUID(); connect(ctx.asyncAssertSuccess(conn -> { - conn.preparedQuery("INSERT INTO db2_types (id,test_vchar) VALUES (?,?)").execute(Tuple.of(6, uuid), + conn + .preparedQuery("INSERT INTO db2_types (id,test_vchar) VALUES (?,?)") + .execute(Tuple.of(6, uuid)) + .onComplete( ctx.asyncAssertSuccess(insertResult -> { - conn.preparedQuery("SELECT id,test_vchar FROM db2_types WHERE id = ?").execute(Tuple.of(6), + conn + .preparedQuery("SELECT id,test_vchar FROM db2_types WHERE id = ?") + .execute(Tuple.of(6)) + .onComplete( ctx.asyncAssertSuccess(rows -> { ctx.assertEquals(1, rows.size()); Row row = rows.iterator().next(); @@ -168,22 +194,28 @@ public void testRowId(TestContext ctx) { final String msg = "insert data for testRowId"; connect(ctx.asyncAssertSuccess(conn -> { // Insert some data - conn.preparedQuery("INSERT INTO ROWTEST (message) VALUES ('" + msg + "')") - .execute(ctx.asyncAssertSuccess(insertResult -> { + conn + .preparedQuery("INSERT INTO ROWTEST (message) VALUES ('" + msg + "')") + .execute() + .onComplete(ctx.asyncAssertSuccess(insertResult -> { // Find it by msg - conn.preparedQuery("SELECT * FROM ROWTEST WHERE message = '" + msg + "'") - .execute(ctx.asyncAssertSuccess(rows -> { + conn + .preparedQuery("SELECT * FROM ROWTEST WHERE message = '" + msg + "'") + .execute() + .onComplete(ctx.asyncAssertSuccess(rows -> { RowId rowId = verifyRowId(ctx, rows, msg); // Now find it by rowid - conn.preparedQuery("SELECT * FROM ROWTEST WHERE id = ?") - .execute(Tuple.of(rowId), ctx.asyncAssertSuccess(rows2 -> { + conn + .preparedQuery("SELECT * FROM ROWTEST WHERE id = ?") + .execute(Tuple.of(rowId)) + .onComplete(ctx.asyncAssertSuccess(rows2 -> { verifyRowId(ctx, rows2, msg); })); })); })); })); } - + /** * Test to support using enum string values in the Row and Tuple methods. */ @@ -191,9 +223,12 @@ public void testRowId(TestContext ctx) { public void testUsingEnumNameValue(TestContext ctx) { connect(ctx.asyncAssertSuccess(conn -> { conn.preparedQuery("INSERT INTO db2_types (id,test_vchar) VALUES (?, ?)") - .execute(Tuple.of(10, Days.WEDNESDAY), ctx.asyncAssertSuccess(insertResult -> { - conn.preparedQuery("SELECT id,test_vchar FROM db2_types WHERE id = 10") - .execute(ctx.asyncAssertSuccess(rows -> { + .execute(Tuple.of(10, Days.WEDNESDAY)) + .onComplete(ctx.asyncAssertSuccess(insertResult -> { + conn + .preparedQuery("SELECT id,test_vchar FROM db2_types WHERE id = 10") + .execute() + .onComplete(ctx.asyncAssertSuccess(rows -> { ctx.assertEquals(1, rows.size()); Row row = rows.iterator().next(); ctx.assertEquals(10, row.getInteger(0)); @@ -210,9 +245,12 @@ public void testUsingEnumNameValue(TestContext ctx) { public void testUsingEnumOrdinalValue(TestContext ctx) { connect(ctx.asyncAssertSuccess(conn -> { conn.preparedQuery("INSERT INTO db2_types (id,test_int) VALUES (?, ?)") - .execute(Tuple.of(11, Days.FRIDAY.ordinal()), ctx.asyncAssertSuccess(insertResult -> { - conn.preparedQuery("SELECT id,test_int FROM db2_types WHERE id = 11") - .execute(ctx.asyncAssertSuccess(rows -> { + .execute(Tuple.of(11, Days.FRIDAY.ordinal())) + .onComplete(ctx.asyncAssertSuccess(insertResult -> { + conn + .preparedQuery("SELECT id,test_int FROM db2_types WHERE id = 11") + .execute() + .onComplete(ctx.asyncAssertSuccess(rows -> { ctx.assertEquals(1, rows.size()); Row row = rows.iterator().next(); ctx.assertEquals(11, row.getInteger(0)); @@ -221,7 +259,7 @@ public void testUsingEnumOrdinalValue(TestContext ctx) { })); })); } - + private RowId verifyRowId(TestContext ctx, RowSet rows, String msg) { ctx.assertEquals(1, rows.size()); Row row = rows.iterator().next(); diff --git a/vertx-db2-client/src/test/java/io/vertx/db2client/DB2ErrorMessageTest.java b/vertx-db2-client/src/test/java/io/vertx/db2client/DB2ErrorMessageTest.java index 28c3ad950..33bdd04d5 100644 --- a/vertx-db2-client/src/test/java/io/vertx/db2client/DB2ErrorMessageTest.java +++ b/vertx-db2-client/src/test/java/io/vertx/db2client/DB2ErrorMessageTest.java @@ -31,7 +31,7 @@ public class DB2ErrorMessageTest extends DB2TestBase { @Test public void testConnectInvalidDatabase(TestContext ctx) { options.setDatabase("DB_DOES_NOT_EXIST"); - DB2Connection.connect(vertx, options, ctx.asyncAssertFailure(err -> { + DB2Connection.connect(vertx, options).onComplete(ctx.asyncAssertFailure(err -> { if (err instanceof DB2Exception) { DB2Exception ex = (DB2Exception) err; assertContains(ctx, ex.getMessage(), "provided was not found", "The connection was closed by the database server"); @@ -48,7 +48,7 @@ public void testConnectInvalidDatabase(TestContext ctx) { @Test public void testConnectInvalidUsername(TestContext ctx) { options.setUser("INVALID_USER_FOR_TESTING"); - DB2Connection.connect(vertx, options, ctx.asyncAssertFailure(err -> { + DB2Connection.connect(vertx, options).onComplete(ctx.asyncAssertFailure(err -> { ctx.assertTrue(err instanceof DB2Exception, "The error message returned is of the wrong type. It should be a DB2Exception, but it was of type " + err.getClass().getSimpleName()); DB2Exception ex = (DB2Exception) err; assertContains(ctx, ex.getMessage(), "Invalid credentials"); @@ -60,7 +60,7 @@ public void testConnectInvalidUsername(TestContext ctx) { @Test public void testConnectInvalidPassword(TestContext ctx) { options.setPassword("INVALID_PASSWORD_FOR_TESTING"); - DB2Connection.connect(vertx, options, ctx.asyncAssertFailure(err -> { + DB2Connection.connect(vertx, options).onComplete(ctx.asyncAssertFailure(err -> { ctx.assertTrue(err instanceof DB2Exception, "The error message returned is of the wrong type. It should be a DB2Exception, but it was of type " + err.getClass().getSimpleName()); DB2Exception ex = (DB2Exception) err; assertContains(ctx, ex.getMessage(), "Invalid credentials"); @@ -108,8 +108,11 @@ public void testQueryBlankPassword(TestContext ctx) { @Test // This should cause sqlCode=-104 sqlState=42601 to be returned from the server public void testQueryBlankTable(TestContext ctx) { - DB2Connection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.query("SELECT id, message FROM ").execute(ctx.asyncAssertFailure(err -> { + DB2Connection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> { + conn + .query("SELECT id, message FROM ") + .execute() + .onComplete(ctx.asyncAssertFailure(err -> { ctx.assertTrue(err instanceof DB2Exception, "The error message returned is of the wrong type. It should be a DB2Exception, but it was of type " + err.getClass().getSimpleName()); DB2Exception ex = (DB2Exception) err; assertContains(ctx, ex.getMessage(), "The SQL syntax provided was invalid"); @@ -122,8 +125,9 @@ public void testQueryBlankTable(TestContext ctx) { @Test // This should cause sqlCode=-204 sqlState=42704 to be returned from the server public void testInvalidTableQuery(TestContext ctx) { - DB2Connection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.query("SELECT id, message FROM TABLE_DOES_NOT_EXIST").execute(ctx.asyncAssertFailure(err -> { + DB2Connection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> { + conn.query("SELECT id, message FROM TABLE_DOES_NOT_EXIST").execute() + .onComplete(ctx.asyncAssertFailure(err -> { ctx.assertTrue(err instanceof DB2Exception, "The error message returned is of the wrong type. It should be a DB2Exception, but it was of type " + err.getClass().getSimpleName()); DB2Exception ex = (DB2Exception) err; assertContains(ctx, ex.getMessage(), "provided is not defined"); @@ -136,8 +140,11 @@ public void testInvalidTableQuery(TestContext ctx) { @Test // This should cause sqlCode=-206 sqlState=42703 to be returned from the server public void testInvalidColumnQuery(TestContext ctx) { - DB2Connection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.query("SELECT INVALID_COLUMN FROM immutable").execute(ctx.asyncAssertFailure(err -> { + DB2Connection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> { + conn + .query("SELECT INVALID_COLUMN FROM immutable") + .execute() + .onComplete(ctx.asyncAssertFailure(err -> { ctx.assertTrue(err instanceof DB2Exception, "The error message returned is of the wrong type. It should be a DB2Exception, but it was of type " + err.getClass().getSimpleName()); DB2Exception ex = (DB2Exception) err; assertContains(ctx, ex.getMessage(), "provided does not exist"); @@ -150,8 +157,11 @@ public void testInvalidColumnQuery(TestContext ctx) { @Test // This should cause sqlCode=-104 sqlState=42601 to be returned from the server public void testInvalidQuery(TestContext ctx) { - DB2Connection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.query("KJHDKJAHDQWEUWHQDDA:SHDL:KASHDJ").execute(ctx.asyncAssertFailure(err -> { + DB2Connection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> { + conn + .query("KJHDKJAHDQWEUWHQDDA:SHDL:KASHDJ") + .execute() + .onComplete(ctx.asyncAssertFailure(err -> { ctx.assertTrue(err instanceof DB2Exception, "The error message returned is of the wrong type. It should be a DB2Exception, but it was of type " + err.getClass().getSimpleName()); DB2Exception ex = (DB2Exception) err; assertContains(ctx, ex.getMessage(), "The SQL syntax provided was invalid"); @@ -167,8 +177,11 @@ public void testInvalidQuery(TestContext ctx) { */ @Test public void testMismatchingInsertedColumns(TestContext ctx) { - DB2Connection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.query("INSERT INTO basicdatatype (id, test_int_2) VALUES (99,24,25)").execute(ctx.asyncAssertFailure(err -> { + DB2Connection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> { + conn + .query("INSERT INTO basicdatatype (id, test_int_2) VALUES (99,24,25)") + .execute() + .onComplete(ctx.asyncAssertFailure(err -> { ctx.assertTrue(err instanceof DB2Exception, "The error message returned is of the wrong type. It should be a DB2Exception, but it was of type " + err.getClass().getSimpleName()); DB2Exception ex = (DB2Exception) err; assertContains(ctx, ex.getMessage(), "An INSERT statement contained a different number of insert columns from the number of insert values that were supplied"); @@ -183,8 +196,11 @@ public void testMismatchingInsertedColumns(TestContext ctx) { */ @Test public void testRepeatedColumnReference(TestContext ctx) { - DB2Connection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.query("INSERT INTO basicdatatype (id, test_int_2, test_int_2) VALUES (99,24,25)").execute(ctx.asyncAssertFailure(err -> { + DB2Connection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> { + conn + .query("INSERT INTO basicdatatype (id, test_int_2, test_int_2) VALUES (99,24,25)") + .execute() + .onComplete(ctx.asyncAssertFailure(err -> { ctx.assertTrue(err instanceof DB2Exception, "The error message returned is of the wrong type. It should be a DB2Exception, but it was of type " + err.getClass().getSimpleName()); DB2Exception ex = (DB2Exception) err; assertContains(ctx, ex.getMessage(), "An INSERT or UPDATE statement listed the same column name (TEST_INT_2) more than one time in its update list"); @@ -200,12 +216,15 @@ public void testRepeatedColumnReference(TestContext ctx) { */ @Test public void testAmbiguousColumnName(TestContext ctx) { - DB2Connection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.query("SELECT immutable.id AS IMM_ID," + + DB2Connection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> { + conn + .query("SELECT immutable.id AS IMM_ID," + "Fortune.id AS FORT_ID," + "message FROM immutable " + "INNER JOIN Fortune ON immutable.id = Fortune.id " + - "WHERE immutable.id=1").execute(ctx.asyncAssertFailure(err -> { + "WHERE immutable.id=1") + .execute() + .onComplete(ctx.asyncAssertFailure(err -> { ctx.assertTrue(err instanceof DB2Exception, "The error message returned is of the wrong type. It should be a DB2Exception, but it was of type " + err.getClass().getSimpleName()); DB2Exception ex = (DB2Exception) err; assertContains(ctx, ex.getMessage(), "A reference to the column name 'MESSAGE' is ambiguous"); @@ -220,8 +239,11 @@ public void testAmbiguousColumnName(TestContext ctx) { */ @Test public void testDuplicateKeys(TestContext ctx) { - DB2Connection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.query("INSERT INTO immutable (id, message) VALUES (1, 'a duplicate key')").execute(ctx.asyncAssertFailure(err -> { + DB2Connection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> { + conn + .query("INSERT INTO immutable (id, message) VALUES (1, 'a duplicate key')") + .execute() + .onComplete(ctx.asyncAssertFailure(err -> { ctx.assertTrue(err instanceof DB2Exception, "The error message returned is of the wrong type. It should be a DB2Exception, but it was of type " + err.getClass().getSimpleName()); DB2Exception ex = (DB2Exception) err; @@ -237,8 +259,11 @@ public void testDuplicateKeys(TestContext ctx) { */ @Test public void testCreateTableNullPrimaryKey(TestContext ctx) { - DB2Connection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.query("CREATE TABLE fruits (id INTEGER PRIMARY KEY, name VARCHAR(50) NOT NULL)").execute(ctx.asyncAssertFailure(err -> { + DB2Connection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> { + conn + .query("CREATE TABLE fruits (id INTEGER PRIMARY KEY, name VARCHAR(50) NOT NULL)") + .execute() + .onComplete(ctx.asyncAssertFailure(err -> { ctx.assertTrue(err instanceof DB2Exception, "The error message returned is of the wrong type. It should be a DB2Exception, but it was of type " + err.getClass().getSimpleName()); DB2Exception ex = (DB2Exception) err; assertContains(ctx, ex.getMessage(), "The column 'ID' cannot be a column of a primary key because it can contain null values"); @@ -254,8 +279,11 @@ public void testCreateTableNullPrimaryKey(TestContext ctx) { */ @Test public void testInsertIntoGeneratedAlwaysColumn(TestContext ctx) { - DB2Connection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.query("INSERT INTO Fortune (id,message) VALUES (25, 'hello world')").execute(ctx.asyncAssertFailure(err -> { + DB2Connection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> { + conn + .query("INSERT INTO Fortune (id,message) VALUES (25, 'hello world')") + .execute() + .onComplete(ctx.asyncAssertFailure(err -> { ctx.assertTrue(err instanceof DB2Exception, "The error message returned is of the wrong type. It should be a DB2Exception, but it was of type " + err.getClass().getSimpleName()); DB2Exception ex = (DB2Exception) err; assertContains(ctx, ex.getMessage(), "A value cannot be specified for column 'ID' which is identified as GENERATED ALWAYS"); @@ -266,12 +294,15 @@ public void testInsertIntoGeneratedAlwaysColumn(TestContext ctx) { @Test public void testDuplicateObject(TestContext ctx) { - DB2Connection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.query("CREATE TABLE Fortune (\n" + + DB2Connection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> { + conn + .query("CREATE TABLE Fortune (\n" + " id integer NOT NULL GENERATED AS IDENTITY (START WITH 1, INCREMENT BY 1),\n" + " message varchar(2048),\n" + " PRIMARY KEY (id)\n" + - ")").execute(ctx.asyncAssertFailure(err -> { + ")") + .execute() + .onComplete(ctx.asyncAssertFailure(err -> { ctx.assertTrue(err instanceof DB2Exception, "The error message returned is of the wrong type. It should be a DB2Exception, but it was of type " + err.getClass().getSimpleName()); DB2Exception ex = (DB2Exception) err; assertContains(ctx, ex.getMessage(), "The object with the name '"); @@ -287,8 +318,11 @@ public void testDuplicateObject(TestContext ctx) { //During the 60 second wait call 'docker kill ', docker stop will end gracefully, so it has to be docker kill. //@Test public void testInflightCommandsFailWhenConnectionClosed(TestContext ctx) { - DB2Connection.connect(vertx, options, ctx.asyncAssertSuccess(conn1 -> { - conn1.query("CALL dbms_alert.sleep(60)").execute(ctx.asyncAssertFailure(t -> { + DB2Connection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn1 -> { + conn1 + .query("CALL dbms_alert.sleep(60)") + .execute() + .onComplete(ctx.asyncAssertFailure(t -> { ctx.assertEquals("Failed to read any response from the server, the underlying connection may have been lost unexpectedly.", t.getMessage()); })); })); diff --git a/vertx-db2-client/src/test/java/io/vertx/db2client/DB2PingTest.java b/vertx-db2-client/src/test/java/io/vertx/db2client/DB2PingTest.java index 74a7af31c..cc91ff4af 100644 --- a/vertx-db2-client/src/test/java/io/vertx/db2client/DB2PingTest.java +++ b/vertx-db2-client/src/test/java/io/vertx/db2client/DB2PingTest.java @@ -26,8 +26,8 @@ public class DB2PingTest extends DB2TestBase { @Test public void testPingCommand(TestContext ctx) { - DB2Connection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.ping(ctx.asyncAssertSuccess(v -> { + DB2Connection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> { + conn.ping().onComplete(ctx.asyncAssertSuccess(v -> { conn.close(); })); })); diff --git a/vertx-db2-client/src/test/java/io/vertx/db2client/DB2SecureTest.java b/vertx-db2-client/src/test/java/io/vertx/db2client/DB2SecureTest.java index a9f7baca2..1014e6915 100644 --- a/vertx-db2-client/src/test/java/io/vertx/db2client/DB2SecureTest.java +++ b/vertx-db2-client/src/test/java/io/vertx/db2client/DB2SecureTest.java @@ -37,7 +37,10 @@ protected void initConnector() { protected void cleanTestTable(TestContext ctx) { // use DELETE FROM because DB2 does not support TRUNCATE TABLE connect(ctx.asyncAssertSuccess(conn -> { - conn.query("DELETE FROM mutable").execute(ctx.asyncAssertSuccess(result -> { + conn + .query("DELETE FROM mutable") + .execute() + .onComplete(ctx.asyncAssertSuccess(result -> { conn.close(); })); })); diff --git a/vertx-db2-client/src/test/java/io/vertx/db2client/DB2SimpleQueryUriTest.java b/vertx-db2-client/src/test/java/io/vertx/db2client/DB2SimpleQueryUriTest.java index 061f3afe7..478a0c69f 100644 --- a/vertx-db2-client/src/test/java/io/vertx/db2client/DB2SimpleQueryUriTest.java +++ b/vertx-db2-client/src/test/java/io/vertx/db2client/DB2SimpleQueryUriTest.java @@ -42,7 +42,7 @@ protected void initConnector() { connector = new Connector() { @Override public void connect(Handler> handler) { - DB2Connection.connect(vertx, uri, ar -> { + DB2Connection.connect(vertx, uri).onComplete(ar -> { if (ar.succeeded()) { handler.handle(Future.succeededFuture(ar.result())); } else { diff --git a/vertx-db2-client/src/test/java/io/vertx/db2client/DB2TestBase.java b/vertx-db2-client/src/test/java/io/vertx/db2client/DB2TestBase.java index 03e5b55a2..6fa3ca5c0 100644 --- a/vertx-db2-client/src/test/java/io/vertx/db2client/DB2TestBase.java +++ b/vertx-db2-client/src/test/java/io/vertx/db2client/DB2TestBase.java @@ -57,7 +57,7 @@ public void setUp(TestContext ctx) throws Exception { @After public void tearDown(TestContext ctx) { connector.close(); - vertx.close(ctx.asyncAssertSuccess()); + vertx.close().onComplete(ctx.asyncAssertSuccess()); } protected void initConnector() { @@ -71,7 +71,10 @@ protected void connect(Handler> handler) { protected void cleanTestTable(TestContext ctx, String table) { connect(ctx.asyncAssertSuccess(conn -> { - conn.query("DELETE FROM " + table).execute(ctx.asyncAssertSuccess(result -> { + conn + .query("DELETE FROM " + table) + .execute() + .onComplete(ctx.asyncAssertSuccess(result -> { conn.close(); })); })); diff --git a/vertx-db2-client/src/test/java/io/vertx/db2client/GeneratedKeysTest.java b/vertx-db2-client/src/test/java/io/vertx/db2client/GeneratedKeysTest.java index 23d7d8279..fc85b88ab 100644 --- a/vertx-db2-client/src/test/java/io/vertx/db2client/GeneratedKeysTest.java +++ b/vertx-db2-client/src/test/java/io/vertx/db2client/GeneratedKeysTest.java @@ -15,8 +15,10 @@ public class GeneratedKeysTest extends DB2TestBase { public void testSelectGeneratedKeyPrepared(TestContext ctx) { final String msg = "Some data from testSelectGeneratedKeyPrepared"; connect(ctx.asyncAssertSuccess(conn -> { - conn.preparedQuery("SELECT * FROM FINAL TABLE ( INSERT INTO Fortune (message) VALUES (?) )") - .execute(Tuple.of(msg), ctx.asyncAssertSuccess(rowSet -> { + conn + .preparedQuery("SELECT * FROM FINAL TABLE ( INSERT INTO Fortune (message) VALUES (?) )") + .execute(Tuple.of(msg)) + .onComplete(ctx.asyncAssertSuccess(rowSet -> { ctx.assertEquals(1, rowSet.size()); Row row = rowSet.iterator().next(); // Generated ID should be >= 13 because init.sql always adds the first 12 rows @@ -31,8 +33,10 @@ public void testSelectGeneratedKeyPrepared(TestContext ctx) { public void testSelectGeneratedKey(TestContext ctx) { final String msg = "Some data from testSelectGeneratedKey"; connect(ctx.asyncAssertSuccess(conn -> { - conn.query("SELECT * FROM FINAL TABLE ( INSERT INTO Fortune (message) VALUES ('" + msg + "') )").execute( - ctx.asyncAssertSuccess(rowSet -> { + conn + .query("SELECT * FROM FINAL TABLE ( INSERT INTO Fortune (message) VALUES ('" + msg + "') )") + .execute() + .onComplete(ctx.asyncAssertSuccess(rowSet -> { ctx.assertEquals(1, rowSet.size()); Row row = rowSet.iterator().next(); // Generated ID should be >= 13 because init.sql always adds the first 12 rows diff --git a/vertx-db2-client/src/test/java/io/vertx/db2client/QueryVariationsTest.java b/vertx-db2-client/src/test/java/io/vertx/db2client/QueryVariationsTest.java index 7e9fd82ea..2e3798758 100644 --- a/vertx-db2-client/src/test/java/io/vertx/db2client/QueryVariationsTest.java +++ b/vertx-db2-client/src/test/java/io/vertx/db2client/QueryVariationsTest.java @@ -25,8 +25,10 @@ public class QueryVariationsTest extends DB2TestBase { @Test public void testFetchFirst(TestContext ctx) { connect(ctx.asyncAssertSuccess(conn -> { - conn.query("select message from immutable order by id fetch first 1 rows only").execute( - ctx.asyncAssertSuccess(rowSet -> { + conn + .query("select message from immutable order by id fetch first 1 rows only") + .execute() + .onComplete(ctx.asyncAssertSuccess(rowSet -> { ctx.assertEquals(1, rowSet.size()); ctx.assertEquals(Arrays.asList("MESSAGE"), rowSet.columnsNames()); RowIterator rows = rowSet.iterator(); @@ -42,11 +44,13 @@ public void testFetchFirst(TestContext ctx) { @Test public void testRenamedColumns(TestContext ctx) { connect(ctx.asyncAssertSuccess(conn -> { - conn.query("SELECT id AS THE_ID," + + conn + .query("SELECT id AS THE_ID," + "message AS \"the message\"" + "FROM immutable " + - "WHERE id = 10").execute( - ctx.asyncAssertSuccess(rowSet -> { + "WHERE id = 10") + .execute() + .onComplete(ctx.asyncAssertSuccess(rowSet -> { ctx.assertEquals(1, rowSet.size()); ctx.assertEquals(Arrays.asList("THE_ID", "the message"), rowSet.columnsNames()); RowIterator rows = rowSet.iterator(); @@ -65,10 +69,12 @@ public void testRenamedColumns(TestContext ctx) { @Test public void testSubquery(TestContext ctx) { connect(ctx.asyncAssertSuccess(conn -> { - conn.query("SELECT id,message FROM immutable " + + conn + .query("SELECT id,message FROM immutable " + "WHERE message IN " + - "(SELECT message FROM immutable WHERE id = '4' OR id = '7')").execute( - ctx.asyncAssertSuccess(rowSet -> { + "(SELECT message FROM immutable WHERE id = '4' OR id = '7')") + .execute() + .onComplete(ctx.asyncAssertSuccess(rowSet -> { ctx.assertEquals(2, rowSet.size()); ctx.assertEquals(Arrays.asList("ID", "MESSAGE"), rowSet.columnsNames()); RowIterator rows = rowSet.iterator(); @@ -88,11 +94,12 @@ public void testSubquery(TestContext ctx) { @Test public void testSubqueryPrepared(TestContext ctx) { connect(ctx.asyncAssertSuccess(conn -> { - conn.preparedQuery("SELECT id,message FROM immutable " + + conn + .preparedQuery("SELECT id,message FROM immutable " + "WHERE message IN " + - "(SELECT message FROM immutable WHERE id = ? OR id = ?)").execute( - Tuple.of(4, 7), - ctx.asyncAssertSuccess(rowSet -> { + "(SELECT message FROM immutable WHERE id = ? OR id = ?)") + .execute(Tuple.of(4, 7)) + .onComplete(ctx.asyncAssertSuccess(rowSet -> { ctx.assertEquals(2, rowSet.size()); ctx.assertEquals(Arrays.asList("ID", "MESSAGE"), rowSet.columnsNames()); RowIterator rows = rowSet.iterator(); @@ -112,9 +119,11 @@ public void testSubqueryPrepared(TestContext ctx) { @Test public void testLikeQuery(TestContext ctx) { connect(ctx.asyncAssertSuccess(conn -> { - conn.query("SELECT id,message FROM immutable " + - "WHERE message LIKE '%computer%'").execute( - ctx.asyncAssertSuccess(rowSet -> { + conn + .query("SELECT id,message FROM immutable " + + "WHERE message LIKE '%computer%'") + .execute() + .onComplete(ctx.asyncAssertSuccess(rowSet -> { ctx.assertEquals(2, rowSet.size()); ctx.assertEquals(Arrays.asList("ID", "MESSAGE"), rowSet.columnsNames()); RowIterator rows = rowSet.iterator(); @@ -174,18 +183,24 @@ public void testSequenceQuery(TestContext ctx) { assumeFalse("TODO: Sequences behave differently on DB2/z and need to be implemented properly", rule.isZOS()); connect(ctx.asyncAssertSuccess(con -> { - con.query("values nextval for my_seq") - .execute(ctx.asyncAssertSuccess(rowSet1 -> { + con + .query("values nextval for my_seq") + .execute() + .onComplete(ctx.asyncAssertSuccess(rowSet1 -> { // Initially the sequence should be N (where N >= 1) int startingSeq = assertSequenceResult(ctx, rowSet1, seqVal -> { ctx.assertTrue(seqVal >= 1, "Sequence value was not >= 1. Value: " + seqVal); }); - con.query("VALUES nextval for my_seq") - .execute(ctx.asyncAssertSuccess(rowSet2 -> { + con + .query("VALUES nextval for my_seq") + .execute() + .onComplete(ctx.asyncAssertSuccess(rowSet2 -> { // Next the sequence should be N+1 assertSequenceResult(ctx, rowSet2, seqVal -> ctx.assertEquals(startingSeq + 1, seqVal)); - con.query("VALUES nextval for my_seq") - .execute(ctx.asyncAssertSuccess(rowSet3 -> { + con + .query("VALUES nextval for my_seq") + .execute() + .onComplete(ctx.asyncAssertSuccess(rowSet3 -> { // Finally, the sequence should be N+2 assertSequenceResult(ctx, rowSet3, seqVal -> ctx.assertEquals(startingSeq + 2, seqVal)); })); @@ -202,18 +217,24 @@ public void testSequenceQueryPrepared(TestContext ctx) { assumeFalse("TODO: Sequences behave differently on DB2/z and need to be implemented properly", rule.isZOS()); connect(ctx.asyncAssertSuccess(con -> { - con.preparedQuery("VALUES nextval for my_seq") - .execute(ctx.asyncAssertSuccess(rowSet1 -> { + con + .preparedQuery("VALUES nextval for my_seq") + .execute() + .onComplete(ctx.asyncAssertSuccess(rowSet1 -> { // Initially the sequence should be N (where N >= 1) int startingSeq = assertSequenceResult(ctx, rowSet1, seqVal -> { ctx.assertTrue(seqVal >= 1, "Sequence value was not >= 1. Value: " + seqVal); }); - con.preparedQuery("values nextval for my_seq") - .execute(ctx.asyncAssertSuccess(rowSet2 -> { + con + .preparedQuery("values nextval for my_seq") + .execute() + .onComplete(ctx.asyncAssertSuccess(rowSet2 -> { // Next the sequence should be N+1 assertSequenceResult(ctx, rowSet2, seqVal -> ctx.assertEquals(startingSeq + 1, seqVal)); - con.preparedQuery("values nextval for my_seq") - .execute(ctx.asyncAssertSuccess(rowSet3 -> { + con + .preparedQuery("values nextval for my_seq") + .execute() + .onComplete(ctx.asyncAssertSuccess(rowSet3 -> { // Finally, the sequence should be N+2 assertSequenceResult(ctx, rowSet3, seqVal -> ctx.assertEquals(startingSeq + 2, seqVal)); })); @@ -221,27 +242,33 @@ public void testSequenceQueryPrepared(TestContext ctx) { })); })); } - + /** * Test comment in query */ @Test public void testComment(TestContext ctx) { connect(ctx.asyncAssertSuccess(con -> { - con.query("SELECT id,message FROM immutable " + + con + .query("SELECT id,message FROM immutable " + "WHERE message IN " + - "(SELECT message FROM immutable WHERE id = '4' OR id = '7') -- comment").execute( - ctx.asyncAssertSuccess(rowSet -> { + "(SELECT message FROM immutable WHERE id = '4' OR id = '7') -- comment") + .execute() + .onComplete(ctx.asyncAssertSuccess(rowSet -> { ctx.assertEquals(2, rowSet.size()); - con.query("SELECT id,message FROM immutable " + + con + .query("SELECT id,message FROM immutable " + "WHERE message IN " + - "(SELECT message FROM immutable WHERE id = '4' OR id = '7') /* test comment */").execute( - ctx.asyncAssertSuccess(rowSet2 -> { + "(SELECT message FROM immutable WHERE id = '4' OR id = '7') /* test comment */") + .execute() + .onComplete(ctx.asyncAssertSuccess(rowSet2 -> { ctx.assertEquals(2, rowSet.size()); - con.query("/* /* test comment */*/ /* /* Overly */ /*Complicated*/ /* Comment */*/SELECT id,message FROM immutable " + + con + .query("/* /* test comment */*/ /* /* Overly */ /*Complicated*/ /* Comment */*/SELECT id,message FROM immutable " + "WHERE message IN " + - "(SELECT message FROM immutable WHERE id = '4' OR id = '7')").execute( - ctx.asyncAssertSuccess(rowSet3 -> { + "(SELECT message FROM immutable WHERE id = '4' OR id = '7')") + .execute() + .onComplete(ctx.asyncAssertSuccess(rowSet3 -> { ctx.assertEquals(2, rowSet.size()); })); })); @@ -259,5 +286,4 @@ private int assertSequenceResult(TestContext ctx, RowSet rowSet, Consumer { - conn.query("SELECT immutable.id AS \"IMM ID\"," + + conn + .query("SELECT immutable.id AS \"IMM ID\"," + "immutable.message AS IMM_MSG," + "Fortune.id AS FORT_ID," + "Fortune.message AS \"fortune msg\" FROM immutable " + "INNER JOIN Fortune ON (immutable.id + 1) = Fortune.id " + - "WHERE immutable.id=1").execute( - ctx.asyncAssertSuccess(rowSet -> { + "WHERE immutable.id=1") + .execute() + .onComplete(ctx.asyncAssertSuccess(rowSet -> { ctx.assertEquals(1, rowSet.size()); ctx.assertEquals(Arrays.asList("IMM ID", "IMM_MSG", "FORT_ID", "fortune msg"), rowSet.columnsNames()); Row row = rowSet.iterator().next(); @@ -47,10 +49,12 @@ public void testColumnRename(TestContext ctx) { @Test public void testInnerJoin(TestContext ctx) { connect(ctx.asyncAssertSuccess(conn -> { - conn.query("SELECT immutable.id,immutable.message,Fortune.id,Fortune.message FROM immutable " + + conn + .query("SELECT immutable.id,immutable.message,Fortune.id,Fortune.message FROM immutable " + "INNER JOIN Fortune ON (immutable.id + 1) = Fortune.id " + - "WHERE immutable.id=1").execute( - ctx.asyncAssertSuccess(rowSet -> { + "WHERE immutable.id=1") + .execute() + .onComplete(ctx.asyncAssertSuccess(rowSet -> { ctx.assertEquals(1, rowSet.size()); ctx.assertEquals(Arrays.asList("ID", "MESSAGE", "ID", "MESSAGE"), rowSet.columnsNames()); Row row = rowSet.iterator().next(); @@ -86,10 +90,12 @@ public void testFullOuterJoin(TestContext ctx) { private void testJoin(TestContext ctx, String joinType) { connect(ctx.asyncAssertSuccess(conn -> { - conn.preparedQuery("SELECT * FROM immutable " + + conn + .preparedQuery("SELECT * FROM immutable " + joinType + " Fortune ON (immutable.id + 1) = Fortune.id " + - "WHERE immutable.id=1").execute( - ctx.asyncAssertSuccess(rowSet -> { + "WHERE immutable.id=1") + .execute() + .onComplete(ctx.asyncAssertSuccess(rowSet -> { ctx.assertEquals(1, rowSet.size()); ctx.assertEquals(Arrays.asList("ID", "MESSAGE", "ID", "MESSAGE"), rowSet.columnsNames()); Row row = rowSet.iterator().next(); @@ -101,5 +107,4 @@ private void testJoin(TestContext ctx, String joinType) { })); })); } - } diff --git a/vertx-db2-client/src/test/java/io/vertx/db2client/tck/ClientConfig.java b/vertx-db2-client/src/test/java/io/vertx/db2client/tck/ClientConfig.java index 0f9c2e318..6f25c7902 100644 --- a/vertx-db2-client/src/test/java/io/vertx/db2client/tck/ClientConfig.java +++ b/vertx-db2-client/src/test/java/io/vertx/db2client/tck/ClientConfig.java @@ -38,7 +38,7 @@ public Connector connect(Vertx vertx, SqlConnectOptions options) return new Connector() { @Override public void connect(Handler> handler) { - DB2Connection.connect(vertx, new DB2ConnectOptions(options), ar -> { + DB2Connection.connect(vertx, new DB2ConnectOptions(options)).onComplete(ar -> { if (ar.succeeded()) { handler.handle(Future.succeededFuture(ar.result())); } else { @@ -61,7 +61,9 @@ public Connector connect(Vertx vertx, SqlConnectOptions options) return new Connector() { @Override public void connect(Handler> handler) { - pool.getConnection(ar -> { + pool + .getConnection() + .onComplete(ar -> { if (ar.succeeded()) { handler.handle(Future.succeededFuture(ar.result())); } else { diff --git a/vertx-db2-client/src/test/java/io/vertx/db2client/tck/DB2BinaryDataTypeDecodeTest.java b/vertx-db2-client/src/test/java/io/vertx/db2client/tck/DB2BinaryDataTypeDecodeTest.java index 0a67da7e9..c94ebb72c 100644 --- a/vertx-db2-client/src/test/java/io/vertx/db2client/tck/DB2BinaryDataTypeDecodeTest.java +++ b/vertx-db2-client/src/test/java/io/vertx/db2client/tck/DB2BinaryDataTypeDecodeTest.java @@ -73,7 +73,8 @@ public void testBoolean(TestContext ctx) { connector.connect(ctx.asyncAssertSuccess(conn -> { conn .preparedQuery("SELECT test_boolean FROM basicdatatype WHERE id = 1") - .execute(ctx.asyncAssertSuccess(result -> { + .execute() + .onComplete(ctx.asyncAssertSuccess(result -> { ctx.assertEquals(1, result.size()); Row row = result.iterator().next(); ctx.assertEquals((short) 1, row.getValue(0)); diff --git a/vertx-db2-client/src/test/java/io/vertx/db2client/tck/DB2BinaryDataTypeEncodeTest.java b/vertx-db2-client/src/test/java/io/vertx/db2client/tck/DB2BinaryDataTypeEncodeTest.java index 41482770a..29ccfa6a0 100644 --- a/vertx-db2-client/src/test/java/io/vertx/db2client/tck/DB2BinaryDataTypeEncodeTest.java +++ b/vertx-db2-client/src/test/java/io/vertx/db2client/tck/DB2BinaryDataTypeEncodeTest.java @@ -84,10 +84,12 @@ public void testBoolean(TestContext ctx) { connector.connect(ctx.asyncAssertSuccess(conn -> { conn .preparedQuery("UPDATE basicdatatype SET test_boolean = ? WHERE id = 2") - .execute(Tuple.tuple().addValue(false), ctx.asyncAssertSuccess(updateResult -> { + .execute(Tuple.tuple().addValue(false)) + .onComplete(ctx.asyncAssertSuccess(updateResult -> { conn .preparedQuery("SELECT test_boolean FROM basicdatatype WHERE id = 2") - .execute(ctx.asyncAssertSuccess(result -> { + .execute() + .onComplete(ctx.asyncAssertSuccess(result -> { ctx.assertEquals(1, result.size()); Row row = result.iterator().next(); ctx.assertEquals((short) 0, row.getValue(0)); diff --git a/vertx-db2-client/src/test/java/io/vertx/db2client/tck/DB2PreparedBatchTest.java b/vertx-db2-client/src/test/java/io/vertx/db2client/tck/DB2PreparedBatchTest.java index 8c46e74d4..b1db78903 100644 --- a/vertx-db2-client/src/test/java/io/vertx/db2client/tck/DB2PreparedBatchTest.java +++ b/vertx-db2-client/src/test/java/io/vertx/db2client/tck/DB2PreparedBatchTest.java @@ -33,7 +33,10 @@ protected void initConnector() { protected void cleanTestTable(TestContext ctx) { // use DELETE FROM because DB2 does not support TRUNCATE TABLE connect(ctx.asyncAssertSuccess(conn -> { - conn.query("DELETE FROM mutable").execute(ctx.asyncAssertSuccess(result -> { + conn + .query("DELETE FROM mutable") + .execute() + .onComplete(ctx.asyncAssertSuccess(result -> { conn.close(); })); })); diff --git a/vertx-db2-client/src/test/java/io/vertx/db2client/tck/DB2PreparedQueryCachedTest.java b/vertx-db2-client/src/test/java/io/vertx/db2client/tck/DB2PreparedQueryCachedTest.java index 6e28cda24..167e72804 100644 --- a/vertx-db2-client/src/test/java/io/vertx/db2client/tck/DB2PreparedQueryCachedTest.java +++ b/vertx-db2-client/src/test/java/io/vertx/db2client/tck/DB2PreparedQueryCachedTest.java @@ -45,7 +45,10 @@ protected boolean cursorRequiresTx() { protected void cleanTestTable(TestContext ctx) { // use DELETE FROM because DB2 does not support TRUNCATE TABLE connect(ctx.asyncAssertSuccess(conn -> { - conn.query("DELETE FROM mutable").execute(ctx.asyncAssertSuccess(result -> { + conn + .query("DELETE FROM mutable") + .execute() + .onComplete(ctx.asyncAssertSuccess(result -> { conn.close(); })); })); diff --git a/vertx-db2-client/src/test/java/io/vertx/db2client/tck/DB2PreparedQueryTestBase.java b/vertx-db2-client/src/test/java/io/vertx/db2client/tck/DB2PreparedQueryTestBase.java index 8a90a1d3b..726442d2e 100644 --- a/vertx-db2-client/src/test/java/io/vertx/db2client/tck/DB2PreparedQueryTestBase.java +++ b/vertx-db2-client/src/test/java/io/vertx/db2client/tck/DB2PreparedQueryTestBase.java @@ -26,7 +26,10 @@ public void printTestName(TestContext ctx) throws Exception { protected void cleanTestTable(TestContext ctx) { // use DELETE FROM because DB2 does not support TRUNCATE TABLE connect(ctx.asyncAssertSuccess(conn -> { - conn.query("DELETE FROM mutable").execute(ctx.asyncAssertSuccess(result -> { + conn + .query("DELETE FROM mutable") + .execute() + .onComplete(ctx.asyncAssertSuccess(result -> { conn.close(); })); })); diff --git a/vertx-db2-client/src/test/java/io/vertx/db2client/tck/DB2SimpleQueryPooledTest.java b/vertx-db2-client/src/test/java/io/vertx/db2client/tck/DB2SimpleQueryPooledTest.java index a7c961d15..982091526 100644 --- a/vertx-db2-client/src/test/java/io/vertx/db2client/tck/DB2SimpleQueryPooledTest.java +++ b/vertx-db2-client/src/test/java/io/vertx/db2client/tck/DB2SimpleQueryPooledTest.java @@ -34,7 +34,10 @@ protected void initConnector() { @Override protected void cleanTestTable(TestContext ctx) { connect(ctx.asyncAssertSuccess(conn -> { - conn.query("DELETE FROM mutable").execute(ctx.asyncAssertSuccess(result -> { + conn + .query("DELETE FROM mutable") + .execute() + .onComplete(ctx.asyncAssertSuccess(result -> { conn.close(); })); })); diff --git a/vertx-db2-client/src/test/java/io/vertx/db2client/tck/DB2SimpleQueryTest.java b/vertx-db2-client/src/test/java/io/vertx/db2client/tck/DB2SimpleQueryTest.java index 686ce4c1a..754c834b2 100644 --- a/vertx-db2-client/src/test/java/io/vertx/db2client/tck/DB2SimpleQueryTest.java +++ b/vertx-db2-client/src/test/java/io/vertx/db2client/tck/DB2SimpleQueryTest.java @@ -50,7 +50,10 @@ protected void initConnector() { protected void cleanTestTable(TestContext ctx) { // use DELETE FROM because DB2 does not support TRUNCATE TABLE connect(ctx.asyncAssertSuccess(conn -> { - conn.query("DELETE FROM mutable").execute(ctx.asyncAssertSuccess(result -> { + conn + .query("DELETE FROM mutable") + .execute() + .onComplete(ctx.asyncAssertSuccess(result -> { conn.close(); })); })); diff --git a/vertx-db2-client/src/test/java/io/vertx/db2client/tck/DB2TextDataTypeDecodeTest.java b/vertx-db2-client/src/test/java/io/vertx/db2client/tck/DB2TextDataTypeDecodeTest.java index 50313d16e..dca3e0573 100644 --- a/vertx-db2-client/src/test/java/io/vertx/db2client/tck/DB2TextDataTypeDecodeTest.java +++ b/vertx-db2-client/src/test/java/io/vertx/db2client/tck/DB2TextDataTypeDecodeTest.java @@ -72,7 +72,10 @@ public void testBoolean(TestContext ctx) { // DB2/LUW has a BOOLEAN column type but it is an alias for TINYINT Async async = ctx.async(); connector.connect(ctx.asyncAssertSuccess(conn -> { - conn.query("SELECT test_boolean FROM basicdatatype WHERE id = 1").execute(ctx.asyncAssertSuccess(result -> { + conn + .query("SELECT test_boolean FROM basicdatatype WHERE id = 1") + .execute() + .onComplete(ctx.asyncAssertSuccess(result -> { ctx.assertEquals(1, result.size()); Row row = result.iterator().next(); ctx.assertEquals((short) 1, row.getValue(0)); diff --git a/vertx-db2-client/src/test/java/io/vertx/db2client/tck/DB2TransactionTest.java b/vertx-db2-client/src/test/java/io/vertx/db2client/tck/DB2TransactionTest.java index b0edbff15..c868bf8ef 100644 --- a/vertx-db2-client/src/test/java/io/vertx/db2client/tck/DB2TransactionTest.java +++ b/vertx-db2-client/src/test/java/io/vertx/db2client/tck/DB2TransactionTest.java @@ -60,7 +60,10 @@ protected Pool nonTxPool() { @Override protected void cleanTestTable(TestContext ctx) { // use DELETE FROM because DB2 does not support TRUNCATE TABLE - getPool().query("DELETE FROM mutable").execute(ctx.asyncAssertSuccess()); + getPool() + .query("DELETE FROM mutable") + .execute() + .onComplete(ctx.asyncAssertSuccess()); } @Override @@ -73,7 +76,7 @@ public void testDelayedCommit(TestContext ctx) { assumeFalse("DB2 on Z holds write locks on inserted columns with isolation level = 2", rule.isZOS()); super.testDelayedCommit(ctx); } - + @Test public void testFailureWithPendingQueries(TestContext ctx) { assumeFalse("DB2 on Z holds write locks on inserted columns with isolation level = 2", rule.isZOS()); diff --git a/vertx-mssql-client/src/test/java/io/vertx/mssqlclient/MSSQLConnectionTest.java b/vertx-mssql-client/src/test/java/io/vertx/mssqlclient/MSSQLConnectionTest.java index 72afa56c2..55825dd83 100644 --- a/vertx-mssql-client/src/test/java/io/vertx/mssqlclient/MSSQLConnectionTest.java +++ b/vertx-mssql-client/src/test/java/io/vertx/mssqlclient/MSSQLConnectionTest.java @@ -40,31 +40,40 @@ public void setup() { @After public void tearDown(TestContext ctx) { - vertx.close(ctx.asyncAssertSuccess()); + vertx.close().onComplete(ctx.asyncAssertSuccess()); } @Test public void testConnectWithEmptyProperties(TestContext ctx) { options.setProperties(new HashMap<>()); - MSSQLConnection.connect(vertx, options, ctx.asyncAssertSuccess(SqlConnection::close)); + MSSQLConnection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(SqlConnection::close)); } @Test public void testInflightCommandsFailWhenConnectionClosed(TestContext ctx) { - MSSQLConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn1 -> { - conn1.query("WAITFOR DELAY '00:00:20'").execute(ctx.asyncAssertFailure(t -> { + MSSQLConnection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn1 -> { + conn1 + .query("WAITFOR DELAY '00:00:20'") + .execute() + .onComplete(ctx.asyncAssertFailure(t -> { ctx.verify(v -> { assertThat(t, instanceOf(MSSQLException.class)); assertEquals("Cannot continue the execution because the session is in the kill state.", ((MSSQLException) t).errorMessage()); }); })); - MSSQLConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn2 -> { - conn2.preparedQuery("EXEC sp_who;").execute(ctx.asyncAssertSuccess(processRes -> { + MSSQLConnection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn2 -> { + conn2 + .preparedQuery("EXEC sp_who;") + .execute() + .onComplete(ctx.asyncAssertSuccess(processRes -> { for (Row row : processRes) { Short spid = row.getShort("spid"); String cmd = row.getString("cmd"); if (cmd.contains("WAITFOR")) { - conn2.query(String.format("KILL %d", spid)).execute(ctx.asyncAssertSuccess(v -> conn2.close())); + conn2 + .query(String.format("KILL %d", spid)) + .execute() + .onComplete(ctx.asyncAssertSuccess(v -> conn2.close())); break; } } diff --git a/vertx-mssql-client/src/test/java/io/vertx/mssqlclient/MSSQLEncryptionTestBase.java b/vertx-mssql-client/src/test/java/io/vertx/mssqlclient/MSSQLEncryptionTestBase.java index aaab5b116..cc1e060b9 100644 --- a/vertx-mssql-client/src/test/java/io/vertx/mssqlclient/MSSQLEncryptionTestBase.java +++ b/vertx-mssql-client/src/test/java/io/vertx/mssqlclient/MSSQLEncryptionTestBase.java @@ -46,9 +46,9 @@ public void setup() { @After public void tearDown(TestContext ctx) { if (connection != null) { - connection.close(ctx.asyncAssertSuccess()); + connection.close().onComplete(ctx.asyncAssertSuccess()); } - vertx.close(ctx.asyncAssertSuccess()); + vertx.close().onComplete(ctx.asyncAssertSuccess()); } protected void connect(Handler> handler) { @@ -68,7 +68,8 @@ protected void asyncAssertConnectionUnencrypted(TestContext ctx) { private void asyncAssertConnectionEncrypted(TestContext ctx, boolean expected) { connect(ctx.asyncAssertSuccess(conn -> { conn.query("SELECT encrypt_option FROM sys.dm_exec_connections WHERE session_id = @@SPID") - .execute(ctx.asyncAssertSuccess(rows -> { + .execute() + .onComplete(ctx.asyncAssertSuccess(rows -> { ctx.assertEquals(1, rows.size()); Row row = rows.iterator().next(); String encryptOption = row.getString("encrypt_option"); diff --git a/vertx-mssql-client/src/test/java/io/vertx/mssqlclient/MSSQLInfoTest.java b/vertx-mssql-client/src/test/java/io/vertx/mssqlclient/MSSQLInfoTest.java index 237de4c61..b01ca881e 100644 --- a/vertx-mssql-client/src/test/java/io/vertx/mssqlclient/MSSQLInfoTest.java +++ b/vertx-mssql-client/src/test/java/io/vertx/mssqlclient/MSSQLInfoTest.java @@ -40,15 +40,15 @@ public class MSSQLInfoTest extends MSSQLTestBase { public void setup(TestContext ctx) { vertx = Vertx.vertx(); options = new MSSQLConnectOptions(MSSQLTestBase.options); - MSSQLConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> this.connection = conn)); + MSSQLConnection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> this.connection = conn)); } @After public void tearDown(TestContext ctx) { if (connection != null) { - connection.close(ctx.asyncAssertSuccess()); + connection.close().onComplete(ctx.asyncAssertSuccess()); } - vertx.close(ctx.asyncAssertSuccess()); + vertx.close().onComplete(ctx.asyncAssertSuccess()); } @Test @@ -61,7 +61,7 @@ public void testHandleInfo(TestContext ctx) { infos.add(e); async.complete(); }); - connection.query(String.format("PRINT '%s'", msg)).execute(ctx.asyncAssertSuccess()); + connection.query(String.format("PRINT '%s'", msg)).execute().onComplete(ctx.asyncAssertSuccess()); async.await(); diff --git a/vertx-mssql-client/src/test/java/io/vertx/mssqlclient/MSSQLMultipleTdsPacketsTest.java b/vertx-mssql-client/src/test/java/io/vertx/mssqlclient/MSSQLMultipleTdsPacketsTest.java index c9341f556..5d5262c1c 100644 --- a/vertx-mssql-client/src/test/java/io/vertx/mssqlclient/MSSQLMultipleTdsPacketsTest.java +++ b/vertx-mssql-client/src/test/java/io/vertx/mssqlclient/MSSQLMultipleTdsPacketsTest.java @@ -37,15 +37,15 @@ public class MSSQLMultipleTdsPacketsTest extends MSSQLTestBase { public void setup(TestContext ctx) { vertx = Vertx.vertx(); options = new MSSQLConnectOptions(MSSQLTestBase.options); - MSSQLConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> this.connection = conn)); + MSSQLConnection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> this.connection = conn)); } @After public void tearDown(TestContext ctx) { if (connection != null) { - connection.close(ctx.asyncAssertSuccess()); + connection.close().onComplete(ctx.asyncAssertSuccess()); } - vertx.close(ctx.asyncAssertSuccess()); + vertx.close().onComplete(ctx.asyncAssertSuccess()); } @Test @@ -54,9 +54,9 @@ public void testLargeBatch(TestContext ctx) { .mapToObj(i -> Tuple.of(UUID.randomUUID().toString())) .collect(toList()); connection.query("TRUNCATE TABLE EntityWithIdentity") - .execute(ctx.asyncAssertSuccess(truncate -> { + .execute().onComplete(ctx.asyncAssertSuccess(truncate -> { connection.preparedQuery("INSERT INTO EntityWithIdentity (name) OUTPUT INSERTED.id, INSERTED.name VALUES (@p1)") - .executeBatch(batch, ctx.asyncAssertSuccess(result -> { + .executeBatch(batch).onComplete(ctx.asyncAssertSuccess(result -> { for (Tuple tuple : batch) { Row row = result.iterator().next(); ctx.assertNotNull(row.getInteger("id")); diff --git a/vertx-mssql-client/src/test/java/io/vertx/mssqlclient/MSSQLQueriesTest.java b/vertx-mssql-client/src/test/java/io/vertx/mssqlclient/MSSQLQueriesTest.java index 56cfb6dc2..3c7fea258 100644 --- a/vertx-mssql-client/src/test/java/io/vertx/mssqlclient/MSSQLQueriesTest.java +++ b/vertx-mssql-client/src/test/java/io/vertx/mssqlclient/MSSQLQueriesTest.java @@ -50,35 +50,41 @@ public class MSSQLQueriesTest extends MSSQLTestBase { public void setup(TestContext ctx) { vertx = Vertx.vertx(); options = new MSSQLConnectOptions(MSSQLTestBase.options); - MSSQLConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> this.connection = conn)); + MSSQLConnection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> this.connection = conn)); } @After public void tearDown(TestContext ctx) { if (connection != null) { - connection.close(ctx.asyncAssertSuccess()); + connection.close().onComplete(ctx.asyncAssertSuccess()); } - vertx.close(ctx.asyncAssertSuccess()); + vertx.close().onComplete(ctx.asyncAssertSuccess()); } @Test public void testSimpleQueryOrderBy(TestContext ctx) { - connection.query("SELECT message FROM immutable ORDER BY message DESC") - .execute(ctx.asyncAssertSuccess(rs -> ctx.assertTrue(rs.size() > 1))); + connection + .query("SELECT message FROM immutable ORDER BY message DESC") + .execute() + .onComplete(ctx.asyncAssertSuccess(rs -> ctx.assertTrue(rs.size() > 1))); } @Test public void testPreparedQueryOrderBy(TestContext ctx) { - connection.preparedQuery("SELECT message FROM immutable WHERE id BETWEEN @p1 AND @p2 ORDER BY message DESC") - .execute(Tuple.of(4, 9), ctx.asyncAssertSuccess(rs -> ctx.assertEquals(6, rs.size()))); + connection + .preparedQuery("SELECT message FROM immutable WHERE id BETWEEN @p1 AND @p2 ORDER BY message DESC") + .execute(Tuple.of(4, 9)) + .onComplete( ctx.asyncAssertSuccess(rs -> ctx.assertEquals(6, rs.size()))); } @Test @Repeat(50) public void testQueryCurrentTimestamp(TestContext ctx) { LocalDateTime start = LocalDateTime.now(Clock.systemUTC()); - connection.query("SELECT current_timestamp") - .execute(ctx.asyncAssertSuccess(rs -> { + connection + .query("SELECT current_timestamp") + .execute() + .onComplete(ctx.asyncAssertSuccess(rs -> { Object value = rs.iterator().next().getValue(0); ctx.assertTrue(value instanceof LocalDateTime); LocalDateTime localDateTime = (LocalDateTime) value; @@ -88,20 +94,28 @@ public void testQueryCurrentTimestamp(TestContext ctx) { @Test public void testCreateTable(TestContext ctx) { - connection.query("drop table if exists Basic") - .execute(ctx.asyncAssertSuccess(drop -> { - connection.preparedQuery("create table Basic (id int, dessimal numeric(19,2), primary key (id))") - .execute(ctx.asyncAssertSuccess(create -> { - connection.preparedQuery("INSERT INTO Basic (id, dessimal) values (3, @p1)") - .execute(Tuple.of(NullValue.BigDecimal), ctx.asyncAssertSuccess()); + connection + .query("drop table if exists Basic") + .execute() + .onComplete(ctx.asyncAssertSuccess(drop -> { + connection + .preparedQuery("create table Basic (id int, dessimal numeric(19,2), primary key (id))") + .execute() + .onComplete(ctx.asyncAssertSuccess(create -> { + connection + .preparedQuery("INSERT INTO Basic (id, dessimal) values (3, @p1)") + .execute(Tuple.of(NullValue.BigDecimal)) + .onComplete(ctx.asyncAssertSuccess()); })); })); } @Test public void testInsertReturning(TestContext ctx) { - connection.preparedQuery("insert into EntityWithIdentity (name) OUTPUT INSERTED.id, INSERTED.name VALUES (@p1)") - .execute(Tuple.of("John"), ctx.asyncAssertSuccess(result -> { + connection + .preparedQuery("insert into EntityWithIdentity (name) OUTPUT INSERTED.id, INSERTED.name VALUES (@p1)") + .execute(Tuple.of("John")) + .onComplete(ctx.asyncAssertSuccess(result -> { Row row = result.iterator().next(); ctx.assertNotNull(row.getInteger("id")); ctx.assertEquals("John", row.getString("name")); @@ -110,8 +124,10 @@ public void testInsertReturning(TestContext ctx) { @Test public void testQueryNonExisting(TestContext ctx) { - connection.preparedQuery("DELETE FROM Fonky.Family") - .execute(Tuple.tuple(), ctx.asyncAssertFailure(t -> { + connection + .preparedQuery("DELETE FROM Fonky.Family") + .execute(Tuple.tuple()) + .onComplete(ctx.asyncAssertFailure(t -> { ctx.verify(unused -> { assertThat(t, is(instanceOf(MSSQLException.class))); }); @@ -135,8 +151,10 @@ public void testMultiplePacketsDecoding(TestContext ctx) { "FROM information_schema.columns\n" + "ORDER BY table_catalog, table_schema, table_name, column_name, ordinal_position"; - connection.preparedQuery(sql) - .execute(Tuple.tuple(), ctx.asyncAssertSuccess(rows -> { + connection + .preparedQuery(sql) + .execute(Tuple.tuple()) + .onComplete( ctx.asyncAssertSuccess(rows -> { ctx.assertTrue(rows.size() > 0); })); } @@ -145,7 +163,9 @@ public void testMultiplePacketsDecoding(TestContext ctx) { public void testExecuteStoredProcedure(TestContext ctx) { Async async = ctx.async(); List rows = Collections.synchronizedList(new ArrayList<>()); - connection.prepare("EXEC GetFortune", ctx.asyncAssertSuccess(ps -> { + connection + .prepare("EXEC GetFortune") + .onComplete(ctx.asyncAssertSuccess(ps -> { ps.createStream(2) .exceptionHandler(ctx::fail) .endHandler(v -> { diff --git a/vertx-mssql-client/src/test/java/io/vertx/mssqlclient/data/MSSQLDataTypeTestBase.java b/vertx-mssql-client/src/test/java/io/vertx/mssqlclient/data/MSSQLDataTypeTestBase.java index 98a59c6e1..08f2f14d2 100644 --- a/vertx-mssql-client/src/test/java/io/vertx/mssqlclient/data/MSSQLDataTypeTestBase.java +++ b/vertx-mssql-client/src/test/java/io/vertx/mssqlclient/data/MSSQLDataTypeTestBase.java @@ -85,7 +85,7 @@ public void setup() { @After public void tearDown(TestContext ctx) { - vertx.close(ctx.asyncAssertSuccess()); + vertx.close().onComplete(ctx.asyncAssertSuccess()); } protected void testQueryDecodeGenericWithoutTable(TestContext ctx, @@ -93,10 +93,11 @@ protected void testQueryDecodeGenericWithoutTable(TestContext ctx, String type, String value, Consumer checker) { - MSSQLConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { + MSSQLConnection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> { conn .query("SELECT CAST(" + value + " AS " + type + ") AS " + columnName) - .execute(ctx.asyncAssertSuccess(result -> { + .execute() + .onComplete(ctx.asyncAssertSuccess(result -> { ctx.assertEquals(1, result.size()); Row row = result.iterator().next(); checker.accept(row); @@ -121,10 +122,11 @@ protected void testPreparedQueryDecodeGenericWithoutTable(TestContext ctx, String type, String value, Consumer checker) { - MSSQLConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { + MSSQLConnection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> { conn .preparedQuery("SELECT CAST(" + value + " AS " + type + ") AS " + columnName) - .execute(ctx.asyncAssertSuccess(result -> { + .execute() + .onComplete(ctx.asyncAssertSuccess(result -> { ctx.assertEquals(1, result.size()); Row row = result.iterator().next(); checker.accept(row); @@ -149,10 +151,11 @@ protected void testQueryDecodeGeneric(TestContext ctx, String columnName, String rowIdentifier, Consumer checker) { - MSSQLConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { + MSSQLConnection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> { conn .query(String.format("SELECT %s FROM %s WHERE id = %s", columnName, tableName, rowIdentifier)) - .execute(ctx.asyncAssertSuccess(result -> { + .execute() + .onComplete(ctx.asyncAssertSuccess(result -> { ctx.assertEquals(1, result.size()); Row row = result.iterator().next(); checker.accept(row); @@ -167,10 +170,11 @@ protected void testPreparedQueryDecodeGeneric(TestContext ctx, String columnName, String rowIdentifier, Consumer checker) { - MSSQLConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { + MSSQLConnection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> { conn .preparedQuery(String.format("SELECT %s FROM %s WHERE id = %s", columnName, tableName, rowIdentifier)) - .execute(ctx.asyncAssertSuccess(result -> { + .execute() + .onComplete(ctx.asyncAssertSuccess(result -> { ctx.assertEquals(1, result.size()); Row row = result.iterator().next(); checker.accept(row); @@ -184,12 +188,14 @@ protected void testPreparedQueryEncodeGeneric(TestContext ctx, String columnName, T param, Consumer checker) { - MSSQLConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { + MSSQLConnection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> { conn .preparedQuery(String.format("UPDATE %s SET %s = @p1 WHERE id = 2", tableName, columnName)) - .execute(Tuple.of(param), ctx.asyncAssertSuccess(updateRes -> { + .execute(Tuple.of(param)) + .onComplete(ctx.asyncAssertSuccess(updateRes -> { conn.preparedQuery(String.format("SELECT %s FROM %s WHERE id = 2", columnName, tableName)) - .execute(ctx.asyncAssertSuccess(result -> { + .execute() + .onComplete(ctx.asyncAssertSuccess(result -> { ctx.assertEquals(1, result.size()); Row row = result.iterator().next(); checker.accept(row); diff --git a/vertx-mssql-client/src/test/java/io/vertx/mssqlclient/tck/ClientConfig.java b/vertx-mssql-client/src/test/java/io/vertx/mssqlclient/tck/ClientConfig.java index 76fd5cc78..573a5ce09 100644 --- a/vertx-mssql-client/src/test/java/io/vertx/mssqlclient/tck/ClientConfig.java +++ b/vertx-mssql-client/src/test/java/io/vertx/mssqlclient/tck/ClientConfig.java @@ -33,7 +33,7 @@ Connector connect(Vertx vertx, SqlConnectOptions options) { public void connect(Handler> handler) { //TODO remove this when we have data object support for connect options MSSQLConnectOptions connectOptions = new MSSQLConnectOptions(options); - MSSQLConnection.connect(vertx, connectOptions, ar -> { + MSSQLConnection.connect(vertx, connectOptions).onComplete(ar -> { if (ar.succeeded()) { handler.handle(Future.succeededFuture(ar.result())); } else { @@ -56,7 +56,7 @@ Connector connect(Vertx vertx, SqlConnectOptions options) { return new Connector() { @Override public void connect(Handler> handler) { - pool.getConnection(ar -> { + pool.getConnection().onComplete(ar -> { if (ar.succeeded()) { handler.handle(Future.succeededFuture(ar.result())); } else { diff --git a/vertx-mssql-client/src/test/java/io/vertx/mssqlclient/tck/MSSQLPreparedQueryTest.java b/vertx-mssql-client/src/test/java/io/vertx/mssqlclient/tck/MSSQLPreparedQueryTest.java index 289c0ffc8..e8b71cfbc 100644 --- a/vertx-mssql-client/src/test/java/io/vertx/mssqlclient/tck/MSSQLPreparedQueryTest.java +++ b/vertx-mssql-client/src/test/java/io/vertx/mssqlclient/tck/MSSQLPreparedQueryTest.java @@ -37,8 +37,8 @@ protected void initConnector() { @Test public void closePreparedNotExecuted(TestContext ctx) { connector.connect(ctx.asyncAssertSuccess(conn -> { - conn.prepare("SELECT * FROM IMMUTABLE WHERE id = @p1", ctx.asyncAssertSuccess(ps -> { - ps.close(ctx.asyncAssertSuccess()); + conn.prepare("SELECT * FROM IMMUTABLE WHERE id = @p1").onComplete(ctx.asyncAssertSuccess(ps -> { + ps.close().onComplete(ctx.asyncAssertSuccess()); })); })); } @@ -46,16 +46,22 @@ public void closePreparedNotExecuted(TestContext ctx) { @Test public void closePreparedExecuted(TestContext ctx) { connector.connect(ctx.asyncAssertSuccess(conn -> { - conn.prepare("SELECT * FROM IMMUTABLE WHERE id = @p1", ctx.asyncAssertSuccess(ps -> { - ps.query().execute(Tuple.of(3), ctx.asyncAssertSuccess(rs -> { + conn.prepare("SELECT * FROM IMMUTABLE WHERE id = @p1").onComplete(ctx.asyncAssertSuccess(ps -> { + ps + .query() + .execute(Tuple.of(3)) + .onComplete( ctx.asyncAssertSuccess(rs -> { Row row = rs.iterator().next(); ctx.assertEquals(3, row.getInteger(0)); ctx.assertEquals("After enough decimal places, nobody gives a damn.", row.getString(1)); - ps.query().execute(Tuple.of(7), ctx.asyncAssertSuccess(rs2 -> { + ps + .query() + .execute(Tuple.of(7)) + .onComplete(ctx.asyncAssertSuccess(rs2 -> { Row row2 = rs2.iterator().next(); ctx.assertEquals(7, row2.getInteger(0)); ctx.assertEquals("Any program that runs right is obsolete.", row2.getString(1)); - ps.close(ctx.asyncAssertSuccess()); + ps.close().onComplete(ctx.asyncAssertSuccess()); })); })); })); diff --git a/vertx-mssql-client/src/test/java/io/vertx/mssqlclient/tck/MSSQLPreparedQueryTestBase.java b/vertx-mssql-client/src/test/java/io/vertx/mssqlclient/tck/MSSQLPreparedQueryTestBase.java index cd15bb5f0..b50aa60d6 100644 --- a/vertx-mssql-client/src/test/java/io/vertx/mssqlclient/tck/MSSQLPreparedQueryTestBase.java +++ b/vertx-mssql-client/src/test/java/io/vertx/mssqlclient/tck/MSSQLPreparedQueryTestBase.java @@ -32,7 +32,10 @@ protected boolean cursorRequiresTx() { protected void cleanTestTable(TestContext ctx) { connect(ctx.asyncAssertSuccess(conn -> { - conn.query("TRUNCATE TABLE mutable;").execute(ctx.asyncAssertSuccess(result -> { + conn + .query("TRUNCATE TABLE mutable;") + .execute() + .onComplete(ctx.asyncAssertSuccess(result -> { conn.close(); })); })); @@ -53,8 +56,11 @@ protected String statement(String... parts) { @Test public void testPrepareError(TestContext ctx) { connect(ctx.asyncAssertSuccess(conn -> { - conn.prepare("SELECT whatever FROM DOES_NOT_EXIST", ctx.asyncAssertSuccess(ps -> { - ps.query().execute(ctx.asyncAssertFailure(error -> { + conn.prepare("SELECT whatever FROM DOES_NOT_EXIST").onComplete(ctx.asyncAssertSuccess(ps -> { + ps + .query() + .execute() + .onComplete(ctx.asyncAssertFailure(error -> { ctx.assertTrue(error instanceof MSSQLException); MSSQLException e = (MSSQLException) error; ctx.assertEquals("Invalid object name 'DOES_NOT_EXIST'.", e.errorMessage()); @@ -83,7 +89,7 @@ public void testPreparedQueryParamCoercionTypeError(TestContext ctx) { public void failureWhenPreparingCursor(TestContext ctx) { Async async = ctx.async(); connect(ctx.asyncAssertSuccess(conn -> { - conn.prepare("SELECT invalid_function()", ctx.asyncAssertSuccess(ps -> { + conn.prepare("SELECT invalid_function()").onComplete(ctx.asyncAssertSuccess(ps -> { ps.createStream(50) .exceptionHandler(error -> { ctx.assertTrue(error instanceof MSSQLException); diff --git a/vertx-mysql-client/src/main/java/io/vertx/mysqlclient/MySQLSetOption.java b/vertx-mysql-client/src/main/java/io/vertx/mysqlclient/MySQLSetOption.java index 7f4529c2f..d4d7ed700 100644 --- a/vertx-mysql-client/src/main/java/io/vertx/mysqlclient/MySQLSetOption.java +++ b/vertx-mysql-client/src/main/java/io/vertx/mysqlclient/MySQLSetOption.java @@ -15,7 +15,7 @@ import io.vertx.core.Handler; /** - * MySQL set options which can be used by {@link MySQLConnection#setOption(MySQLSetOption, Handler)}. + * MySQL set options which can be used by {@link MySQLConnection#setOption(MySQLSetOption)}. */ @VertxGen public enum MySQLSetOption { diff --git a/vertx-mysql-client/src/test/java/io/vertx/mysqlclient/MySQLAuthenticationPluginTest.java b/vertx-mysql-client/src/test/java/io/vertx/mysqlclient/MySQLAuthenticationPluginTest.java index d6a626204..cc9835222 100644 --- a/vertx-mysql-client/src/test/java/io/vertx/mysqlclient/MySQLAuthenticationPluginTest.java +++ b/vertx-mysql-client/src/test/java/io/vertx/mysqlclient/MySQLAuthenticationPluginTest.java @@ -33,7 +33,7 @@ public void setup() { @After public void tearDown(TestContext ctx) { - vertx.close(ctx.asyncAssertSuccess()); + vertx.close().onComplete(ctx.asyncAssertSuccess()); } @Test @@ -67,8 +67,11 @@ public void testCachingSha2Plugin(TestContext ctx) { } private void verifyConnection(TestContext ctx, MySQLConnectOptions connectOptions) { - MySQLConnection.connect(vertx, connectOptions, ctx.asyncAssertSuccess(conn -> { - conn.query("SELECT 1;").execute(ctx.asyncAssertSuccess(res -> { + MySQLConnection.connect(vertx, connectOptions).onComplete(ctx.asyncAssertSuccess(conn -> { + conn + .query("SELECT 1;") + .execute() + .onComplete(ctx.asyncAssertSuccess(res -> { Row row = res.iterator().next(); ctx.assertEquals(1, row.size()); ctx.assertEquals(1, row.getInteger(0)); diff --git a/vertx-mysql-client/src/test/java/io/vertx/mysqlclient/MySQLBatchInsertExceptionTestBase.java b/vertx-mysql-client/src/test/java/io/vertx/mysqlclient/MySQLBatchInsertExceptionTestBase.java index f52bcf88d..2c793a61c 100644 --- a/vertx-mysql-client/src/test/java/io/vertx/mysqlclient/MySQLBatchInsertExceptionTestBase.java +++ b/vertx-mysql-client/src/test/java/io/vertx/mysqlclient/MySQLBatchInsertExceptionTestBase.java @@ -45,7 +45,7 @@ protected MySQLConnectOptions createOptions() { @After public void teardown(TestContext ctx) { - vertx.close(ctx.asyncAssertSuccess()); + vertx.close().onComplete(ctx.asyncAssertSuccess()); } @Test @@ -94,8 +94,11 @@ private void testBatchInsertException(TestContext ctx, SqlClient client) { } private void cleanTestTable(TestContext ctx) { - MySQLConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.query("TRUNCATE TABLE mutable;").execute(ctx.asyncAssertSuccess(result -> { + MySQLConnection.connect(vertx, options).onComplete( ctx.asyncAssertSuccess(conn -> { + conn + .query("TRUNCATE TABLE mutable;") + .execute() + .onComplete(ctx.asyncAssertSuccess(result -> { conn.close(); })); })); diff --git a/vertx-mysql-client/src/test/java/io/vertx/mysqlclient/MySQLClientCapabilitiesTest.java b/vertx-mysql-client/src/test/java/io/vertx/mysqlclient/MySQLClientCapabilitiesTest.java index 18faba4f8..165218291 100644 --- a/vertx-mysql-client/src/test/java/io/vertx/mysqlclient/MySQLClientCapabilitiesTest.java +++ b/vertx-mysql-client/src/test/java/io/vertx/mysqlclient/MySQLClientCapabilitiesTest.java @@ -38,7 +38,7 @@ public void setup() { @After public void tearDown(TestContext ctx) { - vertx.close(ctx.asyncAssertSuccess()); + vertx.close().onComplete(ctx.asyncAssertSuccess()); } @@ -54,10 +54,15 @@ public void testAffectedRowsDisabledClientCapability(TestContext ctx) { private void testAffectedRowsClientCapability(TestContext ctx, boolean useAffectedRows, int expectedRowCount) { MySQLConnectOptions connectOptions = options.setUseAffectedRows(useAffectedRows); - MySQLConnection.connect(vertx, connectOptions, ctx.asyncAssertSuccess(conn -> { - conn.query(PREPARE_TESTING_TABLE_DATA).execute(ctx.asyncAssertSuccess(res0 -> { + MySQLConnection.connect(vertx, connectOptions).onComplete( ctx.asyncAssertSuccess(conn -> { + conn + .query(PREPARE_TESTING_TABLE_DATA) + .execute() + .onComplete(ctx.asyncAssertSuccess(res0 -> { conn - .query("UPDATE vehicle SET type = 'bike' WHERE id = 1;").execute(ctx.asyncAssertSuccess(res1 -> { + .query("UPDATE vehicle SET type = 'bike' WHERE id = 1;") + .execute() + .onComplete(ctx.asyncAssertSuccess(res1 -> { ctx.assertEquals(expectedRowCount, res1.rowCount()); conn.close(); })); diff --git a/vertx-mysql-client/src/test/java/io/vertx/mysqlclient/MySQLCollationTest.java b/vertx-mysql-client/src/test/java/io/vertx/mysqlclient/MySQLCollationTest.java index 5fb9d9ce3..090c22824 100644 --- a/vertx-mysql-client/src/test/java/io/vertx/mysqlclient/MySQLCollationTest.java +++ b/vertx-mysql-client/src/test/java/io/vertx/mysqlclient/MySQLCollationTest.java @@ -54,15 +54,18 @@ public void setup() { @After public void tearDown(TestContext ctx) { - vertx.close(ctx.asyncAssertSuccess()); + vertx.close().onComplete(ctx.asyncAssertSuccess()); } @Test public void testConnectionCollation(TestContext ctx) { MySQLConnectOptions connectOptions = options.setCollation("gbk_chinese_ci"); - MySQLConnection.connect(vertx, connectOptions, ctx.asyncAssertSuccess(conn -> { - conn.query("SHOW VARIABLES LIKE 'collation_connection';").execute(ctx.asyncAssertSuccess(res -> { + MySQLConnection.connect(vertx, connectOptions).onComplete(ctx.asyncAssertSuccess(conn -> { + conn + .query("SHOW VARIABLES LIKE 'collation_connection';") + .execute() + .onComplete(ctx.asyncAssertSuccess(res -> { Row row = res.iterator().next(); ctx.assertEquals("gbk_chinese_ci", row.getString("Value")); conn.close(); @@ -73,10 +76,16 @@ public void testConnectionCollation(TestContext ctx) { @Test public void testConnectionCharset(TestContext ctx) { MySQLConnectOptions connectOptions = options.setCollation(null).setCharset("gbk"); - MySQLConnection.connect(vertx, connectOptions, ctx.asyncAssertSuccess(conn -> { - conn.query("SHOW VARIABLES LIKE 'collation_connection';").execute(ctx.asyncAssertSuccess(res -> { + MySQLConnection.connect(vertx, connectOptions).onComplete(ctx.asyncAssertSuccess(conn -> { + conn + .query("SHOW VARIABLES LIKE 'collation_connection';") + .execute() + .onComplete(ctx.asyncAssertSuccess(res -> { ctx.assertEquals("gbk_chinese_ci", res.iterator().next().getString("Value")); - conn.query("SHOW VARIABLES LIKE 'character_set_connection';").execute(ctx.asyncAssertSuccess(res2 -> { + conn + .query("SHOW VARIABLES LIKE 'character_set_connection';") + .execute() + .onComplete(ctx.asyncAssertSuccess(res2 -> { ctx.assertEquals("gbk", res2.iterator().next().getString("Value")); conn.close(); })); @@ -127,8 +136,9 @@ public void testColumnCharsetText(TestContext ctx) { @Test public void testEmoji(TestContext ctx) { // use these for tests 😀🤣😊😇😳😱👍🖐⚽ - MySQLConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.query("CREATE TEMPORARY TABLE emoji(\n" + + MySQLConnection.connect(vertx, options).onComplete( ctx.asyncAssertSuccess(conn -> { + conn + .query("CREATE TEMPORARY TABLE emoji(\n" + "\tid INTEGER,\n" + "\texpression VARCHAR(10)\n" + ");\n" + @@ -140,8 +150,13 @@ public void testEmoji(TestContext ctx) { "INSERT INTO emoji VALUES (6, '\uD83D\uDE31');\n" + "INSERT INTO emoji VALUES (7, '\uD83D\uDC4D');\n" + "INSERT INTO emoji VALUES (8, '\uD83D\uDD90');\n" + - "INSERT INTO emoji VALUES (9, '\u26bd');").execute(ctx.asyncAssertSuccess(res0 -> { - conn.query("SELECT id, expression FROM emoji").execute(ctx.asyncAssertSuccess(res1 -> { + "INSERT INTO emoji VALUES (9, '\u26bd');") + .execute() + .onComplete(ctx.asyncAssertSuccess(res0 -> { + conn + .query("SELECT id, expression FROM emoji") + .execute() + .onComplete(ctx.asyncAssertSuccess(res1 -> { RowIterator iterator = res1.iterator(); Row row1 = iterator.next(); ctx.assertEquals(1, row1.getInteger("id")); @@ -177,9 +192,14 @@ public void testEmoji(TestContext ctx) { } private void testBinary(TestContext ctx, String prepareDataSql) { - MySQLConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.query(prepareDataSql).execute(ctx.asyncAssertSuccess(res0 -> { - conn.preparedQuery("SELECT id, city_name FROM chinese_city where city_name = ?").execute(Tuple.tuple().addString("\u5317\u4EAC"), ctx.asyncAssertSuccess(res1 -> { + MySQLConnection.connect(vertx, options).onComplete( ctx.asyncAssertSuccess(conn -> { + conn + .query(prepareDataSql) + .execute() + .onComplete(ctx.asyncAssertSuccess(res0 -> { + conn.preparedQuery("SELECT id, city_name FROM chinese_city where city_name = ?") + .execute(Tuple.tuple().addString("\u5317\u4EAC")) + .onComplete(ctx.asyncAssertSuccess(res1 -> { ctx.assertEquals(1, res1.size()); Row row = res1.iterator().next(); ctx.assertEquals(1, row.getInteger("id")); @@ -191,9 +211,15 @@ private void testBinary(TestContext ctx, String prepareDataSql) { } private void testText(TestContext ctx, String prepareDataSql) { - MySQLConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.query(prepareDataSql).execute(ctx.asyncAssertSuccess(res0 -> { - conn.query("SELECT id, city_name FROM chinese_city").execute(ctx.asyncAssertSuccess(res1 -> { + MySQLConnection.connect(vertx, options).onComplete( ctx.asyncAssertSuccess(conn -> { + conn + .query(prepareDataSql) + .execute() + .onComplete(ctx.asyncAssertSuccess(res0 -> { + conn + .query("SELECT id, city_name FROM chinese_city") + .execute() + .onComplete(ctx.asyncAssertSuccess(res1 -> { ctx.assertEquals(6, res1.size()); RowIterator iterator = res1.iterator(); Row row1 = iterator.next(); diff --git a/vertx-mysql-client/src/test/java/io/vertx/mysqlclient/MySQLConnectionTest.java b/vertx-mysql-client/src/test/java/io/vertx/mysqlclient/MySQLConnectionTest.java index 049feff4d..c4106f239 100644 --- a/vertx-mysql-client/src/test/java/io/vertx/mysqlclient/MySQLConnectionTest.java +++ b/vertx-mysql-client/src/test/java/io/vertx/mysqlclient/MySQLConnectionTest.java @@ -35,7 +35,7 @@ public void setup() { @After public void tearDown(TestContext ctx) { - vertx.close(ctx.asyncAssertSuccess()); + vertx.close().onComplete(ctx.asyncAssertSuccess()); } @Test @@ -49,7 +49,7 @@ public void testAuthenticationWithEncryptPasswordByServerPublicKey(TestContext c "7ha1P+ZOgPBlV037KDQMS6cUh9vTablEHsMLhDZanymXzzjBkL+wH/b9cdL16LkQ\n" + "5QIDAQAB\n" + "-----END PUBLIC KEY-----\n")); - MySQLConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { + MySQLConnection.connect(vertx, options).onComplete( ctx.asyncAssertSuccess(conn -> { conn.close(); })); } @@ -57,7 +57,7 @@ public void testAuthenticationWithEncryptPasswordByServerPublicKey(TestContext c @Test public void testAuthenticationWithEncryptPasswordByServerPublicKeyInPath(TestContext ctx) { options.setServerRsaPublicKeyPath("tls/files/public_key.pem"); - MySQLConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { + MySQLConnection.connect(vertx, options).onComplete( ctx.asyncAssertSuccess(conn -> { conn.close(); })); } @@ -67,26 +67,35 @@ public void testConnectWithEmptyPassword(TestContext ctx) { options.setUser("emptypassuser") .setPassword("") .setDatabase("emptyschema"); - MySQLConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { + MySQLConnection.connect(vertx, options).onComplete( ctx.asyncAssertSuccess(conn -> { conn.close(); })); } @Test public void testInflightCommandsFailWhenConnectionClosed(TestContext ctx) { - MySQLConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn1 -> { - conn1.query("DO SLEEP(20)").execute(ctx.asyncAssertFailure(t -> { + MySQLConnection.connect(vertx, options).onComplete( ctx.asyncAssertSuccess(conn1 -> { + conn1 + .query("DO SLEEP(20)") + .execute() + .onComplete(ctx.asyncAssertFailure(t -> { ctx.assertTrue(t instanceof ClosedConnectionException); })); - MySQLConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn2 -> { - conn2.query("SHOW PROCESSLIST").execute(ctx.asyncAssertSuccess(processRes -> { + MySQLConnection.connect(vertx, options).onComplete( ctx.asyncAssertSuccess(conn2 -> { + conn2 + .query("SHOW PROCESSLIST") + .execute() + .onComplete(ctx.asyncAssertSuccess(processRes -> { for (Row row : processRes) { Long id = row.getLong("Id"); String state = row.getString("State"); String info = row.getString("Info"); if ("User sleep".equals(state) || "DO SLEEP(10)".equals(info)) { // kill the connection - conn2.query("KILL CONNECTION " + id).execute(ctx.asyncAssertSuccess(v -> conn2.close())); + conn2 + .query("KILL CONNECTION " + id) + .execute() + .onComplete(ctx.asyncAssertSuccess(v -> conn2.close())); break; } } diff --git a/vertx-mysql-client/src/test/java/io/vertx/mysqlclient/MySQLConnectionTestBase.java b/vertx-mysql-client/src/test/java/io/vertx/mysqlclient/MySQLConnectionTestBase.java index 151caea98..41977182e 100644 --- a/vertx-mysql-client/src/test/java/io/vertx/mysqlclient/MySQLConnectionTestBase.java +++ b/vertx-mysql-client/src/test/java/io/vertx/mysqlclient/MySQLConnectionTestBase.java @@ -39,17 +39,23 @@ public void setup() { @After public void teardown(TestContext ctx) { - vertx.close(ctx.asyncAssertSuccess()); + vertx.close().onComplete(ctx.asyncAssertSuccess()); } @Test public void testTx(TestContext ctx) { Async async = ctx.async(); - MySQLConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.query("BEGIN").execute(ctx.asyncAssertSuccess(result1 -> { + MySQLConnection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> { + conn + .query("BEGIN") + .execute() + .onComplete(ctx.asyncAssertSuccess(result1 -> { ctx.assertEquals(0, result1.size()); ctx.assertNotNull(result1.iterator()); - conn.query("COMMIT").execute(ctx.asyncAssertSuccess(result2 -> { + conn + .query("COMMIT") + .execute() + .onComplete(ctx.asyncAssertSuccess(result2 -> { ctx.assertEquals(0, result2.size()); async.complete(); })); @@ -69,22 +75,32 @@ public void testTransactionCommitFromAnotherThread(TestContext ctx) { private void testTransactionCommit(TestContext ctx, Executor exec) { Async done = ctx.async(); - MySQLConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { + MySQLConnection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> { deleteFromMutableTable(ctx, conn, () -> { exec.execute(() -> { conn.begin().onComplete(ctx.asyncAssertSuccess(tx -> { AtomicInteger u1 = new AtomicInteger(); AtomicInteger u2 = new AtomicInteger(); - conn.query("INSERT INTO mutable (id, val) VALUES (1, 'val-1')").execute(ctx.asyncAssertSuccess(res1 -> { + conn + .query("INSERT INTO mutable (id, val) VALUES (1, 'val-1')") + .execute() + .onComplete(ctx.asyncAssertSuccess(res1 -> { u1.addAndGet(res1.rowCount()); exec.execute(() -> { - conn.query("INSERT INTO mutable (id, val) VALUES (2, 'val-2')").execute(ctx.asyncAssertSuccess(res2 -> { + conn + .query("INSERT INTO mutable (id, val) VALUES (2, 'val-2')") + .execute() + .onComplete(ctx.asyncAssertSuccess(res2 -> { u2.addAndGet(res2.rowCount()); exec.execute(() -> { - tx.commit(ctx.asyncAssertSuccess(v -> { + tx.commit() + .onComplete(ctx.asyncAssertSuccess(v -> { ctx.assertEquals(1, u1.get()); ctx.assertEquals(1, u2.get()); - conn.query("SELECT id FROM mutable WHERE id=1 OR id=2").execute(ctx.asyncAssertSuccess(result -> { + conn + .query("SELECT id FROM mutable WHERE id=1 OR id=2") + .execute() + .onComplete(ctx.asyncAssertSuccess(result -> { ctx.assertEquals(2, result.size()); done.complete(); })); @@ -111,24 +127,34 @@ public void testTransactionRollbackFromAnotherThread(TestContext ctx) { private void testTransactionRollback(TestContext ctx, Executor exec) { Async done = ctx.async(); - MySQLConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { + MySQLConnection.connect(vertx, options).onComplete( ctx.asyncAssertSuccess(conn -> { deleteFromMutableTable(ctx, conn, () -> { exec.execute(() -> { conn.begin().onComplete(ctx.asyncAssertSuccess(tx -> { AtomicInteger u1 = new AtomicInteger(); AtomicInteger u2 = new AtomicInteger(); - conn.query("INSERT INTO mutable (id, val) VALUES (1, 'val-1')").execute(ctx.asyncAssertSuccess(res1 -> { + conn + .query("INSERT INTO mutable (id, val) VALUES (1, 'val-1')") + .execute() + .onComplete(ctx.asyncAssertSuccess(res1 -> { u1.addAndGet(res1.rowCount()); exec.execute(() -> { }); - conn.query("INSERT INTO mutable (id, val) VALUES (2, 'val-2')").execute(ctx.asyncAssertSuccess(res2 -> { + conn + .query("INSERT INTO mutable (id, val) VALUES (2, 'val-2')") + .execute() + .onComplete(ctx.asyncAssertSuccess(res2 -> { u2.addAndGet(res2.rowCount()); exec.execute(() -> { - tx.rollback(ctx.asyncAssertSuccess(v -> { + tx.rollback() + .onComplete(ctx.asyncAssertSuccess(v -> { ctx.assertEquals(1, u1.get()); ctx.assertEquals(1, u2.get()); - conn.query("SELECT id FROM mutable WHERE id=1 OR id=2").execute(ctx.asyncAssertSuccess(result -> { + conn + .query("SELECT id FROM mutable WHERE id=1 OR id=2") + .execute() + .onComplete(ctx.asyncAssertSuccess(result -> { ctx.assertEquals(0, result.size()); done.complete(); })); @@ -145,7 +171,7 @@ private void testTransactionRollback(TestContext ctx, Executor exec) { @Test public void testTransactionAbort(TestContext ctx) { Async done = ctx.async(2); - MySQLConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { + MySQLConnection.connect(vertx, options).onComplete( ctx.asyncAssertSuccess(conn -> { deleteFromMutableTable(ctx, conn, () -> { conn.begin().onComplete(ctx.asyncAssertSuccess(tx -> { tx.completion().onComplete(ctx.asyncAssertFailure(err -> { @@ -154,21 +180,32 @@ public void testTransactionAbort(TestContext ctx) { })); AtomicReference queryAfterFailed = new AtomicReference<>(); AtomicReference commit = new AtomicReference<>(); - conn.query("INSERT INTO mutable (id, val) VALUES (1, 'val-1')").execute(ar1 -> { }); - conn.query("INSERT INTO mutable (id, val) VALUES (1, 'val-2')").execute(ar2 -> { + conn.query("INSERT INTO mutable (id, val) VALUES (1, 'val-1')").execute(); + conn + .query("INSERT INTO mutable (id, val) VALUES (1, 'val-2')") + .execute() + .onComplete(ar2 -> { ctx.assertNotNull(queryAfterFailed.get()); ctx.assertTrue(queryAfterFailed.get()); ctx.assertNotNull(commit.get()); ctx.assertTrue(commit.get()); ctx.assertTrue(ar2.failed()); // This query won't be made in the same TX - conn.query("SELECT id FROM mutable WHERE id=1").execute(ctx.asyncAssertSuccess(result -> { + conn + .query("SELECT id FROM mutable WHERE id=1") + .execute() + .onComplete(ctx.asyncAssertSuccess(result -> { ctx.assertEquals(0, result.size()); done.complete(); })); }); - conn.query("SELECT id FROM mutable").execute(result -> queryAfterFailed.set(result.failed())); - tx.commit(result -> commit.set(result.failed())); + conn + .query("SELECT id FROM mutable") + .execute() + .onComplete(result -> queryAfterFailed.set(result.failed())); + tx + .commit() + .onComplete(result -> commit.set(result.failed())); })); }); })); diff --git a/vertx-mysql-client/src/test/java/io/vertx/mysqlclient/MySQLPoolTest.java b/vertx-mysql-client/src/test/java/io/vertx/mysqlclient/MySQLPoolTest.java index 85f73f5ce..13dad8a03 100644 --- a/vertx-mysql-client/src/test/java/io/vertx/mysqlclient/MySQLPoolTest.java +++ b/vertx-mysql-client/src/test/java/io/vertx/mysqlclient/MySQLPoolTest.java @@ -59,30 +59,45 @@ public void tearDown(TestContext ctx) { if (pool != null) { pool.close(); } - vertx.close(ctx.asyncAssertSuccess()); + vertx.close().onComplete(ctx.asyncAssertSuccess()); } @Test public void testContinuouslyConnecting(TestContext ctx) { Async async = ctx.async(3); - pool.getConnection(ctx.asyncAssertSuccess(conn1 -> async.countDown())); - pool.getConnection(ctx.asyncAssertSuccess(conn2 -> async.countDown())); - pool.getConnection(ctx.asyncAssertSuccess(conn3 -> async.countDown())); + pool + .getConnection() + .onComplete(ctx.asyncAssertSuccess(conn1 -> async.countDown())); + pool + .getConnection() + .onComplete(ctx.asyncAssertSuccess(conn2 -> async.countDown())); + pool + .getConnection() + .onComplete(ctx.asyncAssertSuccess(conn3 -> async.countDown())); async.await(); } @Test public void testContinuouslyQuery(TestContext ctx) { Async async = ctx.async(3); - pool.preparedQuery("SELECT 1").execute(ctx.asyncAssertSuccess(res1 -> { + pool + .preparedQuery("SELECT 1") + .execute() + .onComplete(ctx.asyncAssertSuccess(res1 -> { ctx.assertEquals(1, res1.size()); async.countDown(); })); - pool.preparedQuery("SELECT 2").execute(ctx.asyncAssertSuccess(res1 -> { + pool + .preparedQuery("SELECT 2") + .execute() + .onComplete(ctx.asyncAssertSuccess(res1 -> { ctx.assertEquals(1, res1.size()); async.countDown(); })); - pool.preparedQuery("SELECT 3").execute(ctx.asyncAssertSuccess(res1 -> { + pool + .preparedQuery("SELECT 3") + .execute() + .onComplete(ctx.asyncAssertSuccess(res1 -> { ctx.assertEquals(1, res1.size()); async.countDown(); })); @@ -99,7 +114,10 @@ public void testConcurrentMultipleConnection(TestContext ctx) { int numRequests = 1500; Async async = ctx.async(numRequests); for (int i = 0;i < numRequests;i++) { - pool.preparedQuery("SELECT * FROM Fortune WHERE id=?").execute(Tuple.of(1), ctx.asyncAssertSuccess(results -> { + pool + .preparedQuery("SELECT * FROM Fortune WHERE id=?") + .execute(Tuple.of(1)) + .onComplete(ctx.asyncAssertSuccess(results -> { ctx.assertEquals(1, results.size()); Tuple row = results.iterator().next(); ctx.assertEquals(1, row.getInteger(0)); @@ -118,13 +136,24 @@ public void testBorrowedPooledConnectionClosedByServer(TestContext ctx) { Async async = ctx.async(); PoolOptions poolOptions = new PoolOptions().setMaxSize(1); MySQLPool pool = MySQLPool.pool(vertx, new MySQLConnectOptions(this.options).setCachePreparedStatements(false), poolOptions); - pool.getConnection(ctx.asyncAssertSuccess(conn -> { - conn.query("SET SESSION wait_timeout=3;").execute(ctx.asyncAssertSuccess(wait -> { + pool + .getConnection() + .onComplete(ctx.asyncAssertSuccess(conn -> { + conn + .query("SET SESSION wait_timeout=3;") + .execute() + .onComplete(ctx.asyncAssertSuccess(wait -> { vertx.setTimer(5000, id -> { - conn.query("SELECT 'vertx'").execute(ctx.asyncAssertFailure(err -> { + conn + .query("SELECT 'vertx'") + .execute() + .onComplete(ctx.asyncAssertFailure(err -> { ctx.assertEquals("Connection is not active now, current status: CLOSED", err.getMessage()); conn.close(); // close should have no effect here - pool.query("SELECT 'mysql'").execute(ctx.asyncAssertSuccess(res -> { + pool + .query("SELECT 'mysql'") + .execute() + .onComplete(ctx.asyncAssertSuccess(res -> { // the pool will construct a new connection and use it ctx.assertEquals(1, res.size()); Row row = res.iterator().next(); @@ -142,12 +171,20 @@ public void testPooledConnectionClosedByServer(TestContext ctx) { Async async = ctx.async(); PoolOptions poolOptions = new PoolOptions().setMaxSize(1); MySQLPool pool = MySQLPool.pool(vertx, new MySQLConnectOptions(this.options).setCachePreparedStatements(false), poolOptions); - pool.getConnection(ctx.asyncAssertSuccess(conn -> { - conn.query("SET SESSION wait_timeout=3;").execute(ctx.asyncAssertSuccess(wait -> { + pool + .getConnection() + .onComplete(ctx.asyncAssertSuccess(conn -> { + conn + .query("SET SESSION wait_timeout=3;") + .execute() + .onComplete(ctx.asyncAssertSuccess(wait -> { conn.close(); // return it back to the pool vertx.setTimer(5000, id -> { // the query should succeed using a new connection - pool.query("SELECT 'vertx'").execute(ctx.asyncAssertSuccess(res -> { + pool + .query("SELECT 'vertx'") + .execute() + .onComplete(ctx.asyncAssertSuccess(res -> { ctx.assertEquals(1, res.size()); Row row = res.iterator().next(); ctx.assertEquals("vertx", row.getString(0)); @@ -164,10 +201,14 @@ public void testNoConnectionLeaks(TestContext ctx) { Tuple params = Tuple.of(options.getUser(), options.getDatabase()); Async killConnections = ctx.async(); - MySQLConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { + MySQLConnection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> { String sql = "SELECT ID FROM INFORMATION_SCHEMA.PROCESSLIST WHERE ID <> CONNECTION_ID() AND User = ? AND db = ?"; Collector> collector = mapping(row -> row.getInteger(0), toList()); - conn.preparedQuery(sql).collecting(collector).execute(params, ctx.asyncAssertSuccess(ids -> { + conn + .preparedQuery(sql) + .collecting(collector) + .execute(params) + .onComplete(ctx.asyncAssertSuccess(ids -> { CompositeFuture killAll = ids.value().stream() .map(connId -> conn.query("KILL " + connId).execute()) .collect(Collectors.collectingAndThen(toList(), CompositeFuture::all)); @@ -189,12 +230,18 @@ public void testNoConnectionLeaks(TestContext ctx) { Async async = ctx.async(); AtomicInteger cid = new AtomicInteger(); vertx.getOrCreateContext().runOnContext(v -> { - pool.preparedQuery(sql).execute(params, ctx.asyncAssertSuccess(rs1 -> { + pool + .preparedQuery(sql) + .execute(params) + .onComplete(ctx.asyncAssertSuccess(rs1 -> { Row row1 = rs1.iterator().next(); cid.set(row1.getInteger("cid")); ctx.assertEquals(1, row1.getInteger("cnt")); vertx.setTimer(2 * idleTimeout, l -> { - pool.preparedQuery(sql).execute(params, ctx.asyncAssertSuccess(rs2 -> { + pool + .preparedQuery(sql) + .execute(params) + .onComplete(ctx.asyncAssertSuccess(rs2 -> { Row row2 = rs2.iterator().next(); ctx.assertEquals(1, row2.getInteger("cnt")); ctx.assertNotEquals(cid.get(), row2.getInteger("cid")); diff --git a/vertx-mysql-client/src/test/java/io/vertx/mysqlclient/MySQLPooledConnectionTest.java b/vertx-mysql-client/src/test/java/io/vertx/mysqlclient/MySQLPooledConnectionTest.java index df627b48c..6c7cfc234 100644 --- a/vertx-mysql-client/src/test/java/io/vertx/mysqlclient/MySQLPooledConnectionTest.java +++ b/vertx-mysql-client/src/test/java/io/vertx/mysqlclient/MySQLPooledConnectionTest.java @@ -45,7 +45,9 @@ public void setup() { if (pool == null) { pool = MySQLPool.pool(vertx, options, new PoolOptions().setMaxSize(1)); } - pool.getConnection(handler); + pool + .getConnection() + .onComplete(handler); }; } @@ -54,7 +56,7 @@ public void tearDown(TestContext ctx) { if (pool != null) { pool.close(); } - vertx.close(ctx.asyncAssertSuccess()); + vertx.close().onComplete(ctx.asyncAssertSuccess()); } @Test @@ -66,17 +68,29 @@ public void testTransactionRollbackUnfinishedOnRecycle(TestContext ctx) { connector.accept(ctx.asyncAssertSuccess(conn1 -> { deleteFromMutableTable(ctx, conn1, () -> { conn1.begin(); - conn1.query("INSERT INTO mutable (id, val) VALUES (5, 'some-value')").execute(ctx.asyncAssertSuccess()); - conn1.query(txnIdSql).execute(ctx.asyncAssertSuccess(result -> { + conn1 + .query("INSERT INTO mutable (id, val) VALUES (5, 'some-value')") + .execute() + .onComplete(ctx.asyncAssertSuccess()); + conn1 + .query(txnIdSql) + .execute() + .onComplete(ctx.asyncAssertSuccess(result -> { Object txid1 = result.iterator().next().getValue(0); conn1.close(); // It will be the same connection connector.accept(ctx.asyncAssertSuccess(conn2 -> { - conn2.query("SELECT id FROM mutable WHERE id=5").execute(ctx.asyncAssertSuccess(result2 -> { + conn2 + .query("SELECT id FROM mutable WHERE id=5") + .execute() + .onComplete(ctx.asyncAssertSuccess(result2 -> { ctx.assertEquals(0, result2.size()); done.countDown(); })); - conn2.query(txnIdSql).execute(ctx.asyncAssertSuccess(result2 -> { + conn2 + .query(txnIdSql) + .execute() + .onComplete(ctx.asyncAssertSuccess(result2 -> { Object txid2 = result.iterator().next().getValue(0); ctx.assertEquals(txid1, txid2); done.countDown(); diff --git a/vertx-mysql-client/src/test/java/io/vertx/mysqlclient/MySQLPreparedStatementTest.java b/vertx-mysql-client/src/test/java/io/vertx/mysqlclient/MySQLPreparedStatementTest.java index a61cf964f..457491c61 100644 --- a/vertx-mysql-client/src/test/java/io/vertx/mysqlclient/MySQLPreparedStatementTest.java +++ b/vertx-mysql-client/src/test/java/io/vertx/mysqlclient/MySQLPreparedStatementTest.java @@ -39,16 +39,22 @@ public void setup() { @After public void tearDown(TestContext ctx) { - vertx.close(ctx.asyncAssertSuccess()); + vertx.close().onComplete(ctx.asyncAssertSuccess()); } @Test public void testContinuousPreparedQueriesWithSameTypeParameters(TestContext ctx) { - MySQLConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.prepare("SELECT id, message FROM immutable WHERE id = ? AND message = ?", ctx.asyncAssertSuccess(preparedQuery -> { - preparedQuery.query().execute(Tuple.of(1, "fortune: No such file or directory"), ctx.asyncAssertSuccess(res1 -> { + MySQLConnection.connect(vertx, options).onComplete( ctx.asyncAssertSuccess(conn -> { + conn.prepare("SELECT id, message FROM immutable WHERE id = ? AND message = ?").onComplete(ctx.asyncAssertSuccess(preparedQuery -> { + preparedQuery + .query() + .execute(Tuple.of(1, "fortune: No such file or directory")) + .onComplete(ctx.asyncAssertSuccess(res1 -> { ctx.assertEquals(1, res1.size()); - preparedQuery.query().execute(Tuple.of(4, "After enough decimal places, nobody gives a damn."), ctx.asyncAssertSuccess(res2 -> { + preparedQuery + .query() + .execute(Tuple.of(4, "After enough decimal places, nobody gives a damn.")) + .onComplete(ctx.asyncAssertSuccess(res2 -> { ctx.assertEquals(0, res2.size()); conn.close(); })); @@ -59,11 +65,17 @@ public void testContinuousPreparedQueriesWithSameTypeParameters(TestContext ctx) @Test public void testContinuousPreparedQueriesWithDifferentTypeParameters(TestContext ctx) { - MySQLConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.prepare("SELECT id, message FROM immutable WHERE id = ? AND message = ?", ctx.asyncAssertSuccess(preparedQuery -> { - preparedQuery.query().execute(Tuple.of("1", "fortune: No such file or directory"), ctx.asyncAssertSuccess(res1 -> { + MySQLConnection.connect(vertx, options).onComplete( ctx.asyncAssertSuccess(conn -> { + conn.prepare("SELECT id, message FROM immutable WHERE id = ? AND message = ?").onComplete(ctx.asyncAssertSuccess(preparedQuery -> { + preparedQuery + .query() + .execute(Tuple.of("1", "fortune: No such file or directory")) + .onComplete(ctx.asyncAssertSuccess(res1 -> { ctx.assertEquals(1, res1.size()); - preparedQuery.query().execute(Tuple.of(4, "A bad random number generator: 1, 1, 1, 1, 1, 4.33e+67, 1, 1, 1"), ctx.asyncAssertSuccess(res2 -> { + preparedQuery + .query() + .execute(Tuple.of(4, "A bad random number generator: 1, 1, 1, 1, 1, 4.33e+67, 1, 1, 1")) + .onComplete(ctx.asyncAssertSuccess(res2 -> { ctx.assertEquals(1, res2.size()); conn.close(); })); @@ -75,15 +87,19 @@ public void testContinuousPreparedQueriesWithDifferentTypeParameters(TestContext @Test public void testContinuousOneShotPreparedQueriesWithDifferentTypeParameters(TestContext ctx) { options.setCachePreparedStatements(true); - MySQLConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.preparedQuery("SELECT id, message FROM immutable WHERE id = ?") - .execute(Tuple.of(1), ctx.asyncAssertSuccess(res1 -> { + MySQLConnection.connect(vertx, options).onComplete( ctx.asyncAssertSuccess(conn -> { + conn + .preparedQuery("SELECT id, message FROM immutable WHERE id = ?") + .execute(Tuple.of(1)) + .onComplete(ctx.asyncAssertSuccess(res1 -> { ctx.assertEquals(1, res1.size()); Row row = res1.iterator().next(); ctx.assertEquals("fortune: No such file or directory", row.getString("message")); - conn.preparedQuery("SELECT id, message FROM immutable WHERE id = ?") - .execute(Tuple.of("3"), ctx.asyncAssertSuccess(res2 -> { + conn + .preparedQuery("SELECT id, message FROM immutable WHERE id = ?") + .execute(Tuple.of("3")) + .onComplete(ctx.asyncAssertSuccess(res2 -> { ctx.assertEquals(1, res2.size()); Row row2 = res2.iterator().next(); ctx.assertEquals("After enough decimal places, nobody gives a damn.", row2.getString("message")); @@ -96,18 +112,25 @@ public void testContinuousOneShotPreparedQueriesWithDifferentTypeParameters(Test @Test public void testContinuousOneShotPreparedQueriesWithBindingFailure(TestContext ctx) { options.setCachePreparedStatements(true); - MySQLConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.preparedQuery("SELECT id, message FROM immutable WHERE id = ?") - .execute(Tuple.of(1), ctx.asyncAssertSuccess(res1 -> { + MySQLConnection.connect(vertx, options).onComplete( ctx.asyncAssertSuccess(conn -> { + conn + .preparedQuery("SELECT id, message FROM immutable WHERE id = ?") + .execute(Tuple.of(1)) + .onComplete(ctx.asyncAssertSuccess(res1 -> { ctx.assertEquals(1, res1.size()); Row row = res1.iterator().next(); ctx.assertEquals("fortune: No such file or directory", row.getString("message")); - conn.preparedQuery("SELECT id, message FROM immutable WHERE id = ?") - .execute(Tuple.of(3, "USELESS PARAM"), ctx.asyncAssertFailure(err -> { + conn + .preparedQuery("SELECT id, message FROM immutable WHERE id = ?") + .execute(Tuple.of(3, "USELESS PARAM")) + .onComplete(ctx.asyncAssertFailure(err -> { ctx.assertEquals("The number of parameters to execute should be consistent with the expected number of parameters = [1] but the actual number is [2].", err.getMessage()); // check the connection is not corrupt - conn.query("SELECT 1").execute(ctx.asyncAssertSuccess(check -> { + conn + .query("SELECT 1") + .execute() + .onComplete(ctx.asyncAssertSuccess(check -> { conn.close(); })); })); @@ -118,18 +141,25 @@ public void testContinuousOneShotPreparedQueriesWithBindingFailure(TestContext c @Test public void testContinuousOneShotPreparedBatchWithBindingFailure(TestContext ctx) { options.setCachePreparedStatements(true); - MySQLConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.preparedQuery("SELECT id, message FROM immutable WHERE id = ?") - .execute(Tuple.of(1), ctx.asyncAssertSuccess(res1 -> { + MySQLConnection.connect(vertx, options).onComplete( ctx.asyncAssertSuccess(conn -> { + conn + .preparedQuery("SELECT id, message FROM immutable WHERE id = ?") + .execute(Tuple.of(1)) + .onComplete(ctx.asyncAssertSuccess(res1 -> { ctx.assertEquals(1, res1.size()); Row row = res1.iterator().next(); ctx.assertEquals("fortune: No such file or directory", row.getString("message")); - conn.preparedQuery("SELECT id, message FROM immutable WHERE id = ?") - .executeBatch(Arrays.asList(Tuple.of(3), Tuple.of(4, "USELESS PARAM"), Tuple.of(6)), ctx.asyncAssertFailure(err -> { + conn + .preparedQuery("SELECT id, message FROM immutable WHERE id = ?") + .executeBatch(Arrays.asList(Tuple.of(3), Tuple.of(4, "USELESS PARAM"), Tuple.of(6))) + .onComplete(ctx.asyncAssertFailure(err -> { ctx.assertEquals("The number of parameters to execute should be consistent with the expected number of parameters = [1] but the actual number is [2].", err.getMessage()); // check the connection is not corrupt - conn.query("SELECT 1").execute(ctx.asyncAssertSuccess(check -> { + conn + .query("SELECT 1") + .execute() + .onComplete(ctx.asyncAssertSuccess(check -> { conn.close(); })); })); @@ -150,20 +180,29 @@ public void testOneShotPreparedStatements(TestContext ctx) { private void testPreparedStatements(TestContext ctx, MySQLConnectOptions options, int num, int expected) { Assume.assumeFalse(MySQLTestBase.rule.isUsingMySQL5_6() || MySQLTestBase.rule.isUsingMariaDB()); Async async = ctx.async(); - MySQLConnection.connect(vertx, options.setUser("root").setPassword("password"), ctx.asyncAssertSuccess(conn -> { - conn.query("SELECT * FROM performance_schema.prepared_statements_instances").execute(ctx.asyncAssertSuccess(res1 -> { + MySQLConnection.connect(vertx, options.setUser("root").setPassword("password")).onComplete( ctx.asyncAssertSuccess(conn -> { + conn + .query("SELECT * FROM performance_schema.prepared_statements_instances") + .execute() + .onComplete(ctx.asyncAssertSuccess(res1 -> { ctx.assertEquals(0, res1.size()); AtomicInteger count = new AtomicInteger(num); for (int i = 0;i < num;i++) { int val = i; - conn.preparedQuery("SELECT " + i).execute(Tuple.tuple(), ctx.asyncAssertSuccess(res2 -> { + conn + .preparedQuery("SELECT " + i) + .execute(Tuple.tuple()) + .onComplete(ctx.asyncAssertSuccess(res2 -> { ctx.assertEquals(1, res2.size()); ctx.assertEquals(val, res2.iterator().next().getInteger(0)); if (count.decrementAndGet() == 0) { ctx.assertEquals(num - 1, val); - conn.query("SELECT * FROM performance_schema.prepared_statements_instances").execute(ctx.asyncAssertSuccess(res3 -> { + conn + .query("SELECT * FROM performance_schema.prepared_statements_instances") + .execute() + .onComplete(ctx.asyncAssertSuccess(res3 -> { ctx.assertEquals(expected, res3.size()); - conn.close(ctx.asyncAssertSuccess(v -> { + conn.close().onComplete(ctx.asyncAssertSuccess(v -> { async.complete(); })); })); @@ -182,10 +221,16 @@ public void testPreparedStatementCleaned(TestContext ctx) { .setPassword("password") .setCachePreparedStatements(false); Async async = ctx.async(); - MySQLConnection.connect(vertx, connectOptions, ctx.asyncAssertSuccess(conn -> { - conn.query("SELECT * FROM performance_schema.prepared_statements_instances").execute(ctx.asyncAssertSuccess(res1 -> { + MySQLConnection.connect(vertx, connectOptions).onComplete( ctx.asyncAssertSuccess(conn -> { + conn + .query("SELECT * FROM performance_schema.prepared_statements_instances") + .execute() + .onComplete(ctx.asyncAssertSuccess(res1 -> { ctx.assertEquals(0, res1.size()); - conn.preparedQuery("INSERT INTO duplicate_test VALUES (?)").execute(Tuple.of(1), ctx.asyncAssertFailure(failure -> { + conn + .preparedQuery("INSERT INTO duplicate_test VALUES (?)") + .execute(Tuple.of(1)) + .onComplete(ctx.asyncAssertFailure(failure -> { if (!(failure instanceof MySQLException)) { ctx.fail(failure); return; @@ -193,9 +238,12 @@ public void testPreparedStatementCleaned(TestContext ctx) { MySQLException e = (MySQLException) failure; ctx.assertEquals(1062, e.getErrorCode()); ctx.assertEquals("23000", e.getSqlState()); - conn.query("SELECT * FROM performance_schema.prepared_statements_instances").execute(ctx.asyncAssertSuccess(res2 -> { + conn + .query("SELECT * FROM performance_schema.prepared_statements_instances") + .execute() + .onComplete(ctx.asyncAssertSuccess(res2 -> { ctx.assertEquals(0, res2.size()); - conn.close(ctx.asyncAssertSuccess(v -> { + conn.close().onComplete(ctx.asyncAssertSuccess(v -> { async.complete(); })); })); diff --git a/vertx-mysql-client/src/test/java/io/vertx/mysqlclient/MySQLQueryTest.java b/vertx-mysql-client/src/test/java/io/vertx/mysqlclient/MySQLQueryTest.java index 3012ab467..22480201b 100644 --- a/vertx-mysql-client/src/test/java/io/vertx/mysqlclient/MySQLQueryTest.java +++ b/vertx-mysql-client/src/test/java/io/vertx/mysqlclient/MySQLQueryTest.java @@ -43,7 +43,7 @@ public void setup() { @After public void teardown(TestContext ctx) { - vertx.close(ctx.asyncAssertSuccess()); + vertx.close().onComplete(ctx.asyncAssertSuccess()); } @@ -51,14 +51,23 @@ public void teardown(TestContext ctx) { public void testLastInsertIdWithDefaultValue(TestContext ctx) { // Test with our own property PropertyKind property = PropertyKind.create("last-inserted-id", Long.class); - MySQLConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.query("CREATE TEMPORARY TABLE last_insert_id(id INTEGER PRIMARY KEY AUTO_INCREMENT, val VARCHAR(20));").execute(ctx.asyncAssertSuccess(createTableResult -> { + MySQLConnection.connect(vertx, options).onComplete( ctx.asyncAssertSuccess(conn -> { + conn + .query("CREATE TEMPORARY TABLE last_insert_id(id INTEGER PRIMARY KEY AUTO_INCREMENT, val VARCHAR(20));") + .execute() + .onComplete(ctx.asyncAssertSuccess(createTableResult -> { Long lastInsertId1 = createTableResult.property(property); ctx.assertNull(lastInsertId1); - conn.query("INSERT INTO last_insert_id(val) VALUES('test')").execute(ctx.asyncAssertSuccess(insertResult1 -> { + conn + .query("INSERT INTO last_insert_id(val) VALUES('test')") + .execute() + .onComplete(ctx.asyncAssertSuccess(insertResult1 -> { Long lastInsertId2 = insertResult1.property(property); ctx.assertEquals(1L, lastInsertId2); - conn.query("INSERT INTO last_insert_id(val) VALUES('test2')").execute(ctx.asyncAssertSuccess(insertResult2 -> { + conn + .query("INSERT INTO last_insert_id(val) VALUES('test2')") + .execute() + .onComplete(ctx.asyncAssertSuccess(insertResult2 -> { Long lastInsertId3 = insertResult2.property(property); ctx.assertEquals(2L, lastInsertId3); conn.close(); @@ -70,17 +79,29 @@ public void testLastInsertIdWithDefaultValue(TestContext ctx) { @Test public void testLastInsertIdWithSpecifiedValue(TestContext ctx) { - MySQLConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.query("CREATE TEMPORARY TABLE last_insert_id(id INTEGER PRIMARY KEY AUTO_INCREMENT, val VARCHAR(20));").execute(ctx.asyncAssertSuccess(createTableResult -> { + MySQLConnection.connect(vertx, options).onComplete( ctx.asyncAssertSuccess(conn -> { + conn + .query("CREATE TEMPORARY TABLE last_insert_id(id INTEGER PRIMARY KEY AUTO_INCREMENT, val VARCHAR(20));") + .execute() + .onComplete(ctx.asyncAssertSuccess(createTableResult -> { Long lastInsertId1 = createTableResult.property(MySQLClient.LAST_INSERTED_ID); ctx.assertNull(lastInsertId1); - conn.query("ALTER TABLE last_insert_id AUTO_INCREMENT=1234").execute(ctx.asyncAssertSuccess(alterTableResult -> { + conn + .query("ALTER TABLE last_insert_id AUTO_INCREMENT=1234") + .execute() + .onComplete(ctx.asyncAssertSuccess(alterTableResult -> { Long lastInsertId2 = createTableResult.property(MySQLClient.LAST_INSERTED_ID); ctx.assertNull(lastInsertId2); - conn.query("INSERT INTO last_insert_id(val) VALUES('test')").execute(ctx.asyncAssertSuccess(insertResult1 -> { + conn + .query("INSERT INTO last_insert_id(val) VALUES('test')") + .execute() + .onComplete(ctx.asyncAssertSuccess(insertResult1 -> { Long lastInsertId3 = insertResult1.property(MySQLClient.LAST_INSERTED_ID); ctx.assertEquals(1234L, lastInsertId3); - conn.query("INSERT INTO last_insert_id(val) VALUES('test2')").execute(ctx.asyncAssertSuccess(insertResult2 -> { + conn + .query("INSERT INTO last_insert_id(val) VALUES('test2')") + .execute() + .onComplete(ctx.asyncAssertSuccess(insertResult2 -> { Long lastInsertId4 = insertResult2.property(MySQLClient.LAST_INSERTED_ID); ctx.assertEquals(1235L, lastInsertId4); conn.close(); @@ -94,9 +115,14 @@ public void testLastInsertIdWithSpecifiedValue(TestContext ctx) { @Test public void testCachePreparedStatementWithDifferentSql(TestContext ctx) { // we set the cache size to be the same with max_prepared_stmt_count - MySQLConnection.connect(vertx, options.setCachePreparedStatements(true) - .setPreparedStatementCacheMaxSize(1024), ctx.asyncAssertSuccess(conn -> { - conn.query("SHOW VARIABLES LIKE 'max_prepared_stmt_count'").execute(ctx.asyncAssertSuccess(res1 -> { + MySQLConnection + .connect(vertx, options.setCachePreparedStatements(true) + .setPreparedStatementCacheMaxSize(1024)) + .onComplete(ctx.asyncAssertSuccess(conn -> { + conn + .query("SHOW VARIABLES LIKE 'max_prepared_stmt_count'") + .execute() + .onComplete(ctx.asyncAssertSuccess(res1 -> { Row row = res1.iterator().next(); int maxPreparedStatementCount = Integer.parseInt(row.getString(1)); ctx.assertEquals("max_prepared_stmt_count", row.getString(0)); @@ -104,7 +130,10 @@ public void testCachePreparedStatementWithDifferentSql(TestContext ctx) { for (int i = 0; i < (1024 + 256); i++) { String value = "value-" + i; for (int j = 0; j < 2; j++) { - conn.preparedQuery("SELECT '" + value + "'").execute(ctx.asyncAssertSuccess(res2 -> { + conn + .preparedQuery("SELECT '" + value + "'") + .execute() + .onComplete(ctx.asyncAssertSuccess(res2 -> { ctx.assertEquals(value, res2.iterator().next().getString(0)); })); } @@ -115,15 +144,21 @@ public void testCachePreparedStatementWithDifferentSql(TestContext ctx) { @Test public void testCachePreparedStatementWithSameSql(TestContext ctx) { - MySQLConnection.connect(vertx, options.setCachePreparedStatements(true), ctx.asyncAssertSuccess(conn -> { - conn.query("SHOW VARIABLES LIKE 'max_prepared_stmt_count'").execute(ctx.asyncAssertSuccess(res1 -> { + MySQLConnection.connect(vertx, options.setCachePreparedStatements(true)).onComplete( ctx.asyncAssertSuccess(conn -> { + conn + .query("SHOW VARIABLES LIKE 'max_prepared_stmt_count'") + .execute() + .onComplete(ctx.asyncAssertSuccess(res1 -> { Row row = res1.iterator().next(); int maxPreparedStatementCount = Integer.parseInt(row.getString(1)); ctx.assertEquals("max_prepared_stmt_count", row.getString(0)); ctx.assertEquals(1024, maxPreparedStatementCount); for (int i = 0; i < 2000; i++) { - conn.preparedQuery("SELECT 'test'").execute(ctx.asyncAssertSuccess(res2 -> { + conn + .preparedQuery("SELECT 'test'") + .execute() + .onComplete(ctx.asyncAssertSuccess(res2 -> { ctx.assertEquals("test", res2.iterator().next().getString(0)); })); } @@ -133,8 +168,11 @@ public void testCachePreparedStatementWithSameSql(TestContext ctx) { @Test public void testCachePreparedStatementBatchWithSameSql(TestContext ctx) { - MySQLConnection.connect(vertx, options.setCachePreparedStatements(true), ctx.asyncAssertSuccess(conn -> { - conn.query("SHOW VARIABLES LIKE 'max_prepared_stmt_count'").execute(ctx.asyncAssertSuccess(res1 -> { + MySQLConnection.connect(vertx, options.setCachePreparedStatements(true)).onComplete( ctx.asyncAssertSuccess(conn -> { + conn + .query("SHOW VARIABLES LIKE 'max_prepared_stmt_count'") + .execute() + .onComplete(ctx.asyncAssertSuccess(res1 -> { Row row = res1.iterator().next(); int maxPreparedStatementCount = Integer.parseInt(row.getString(1)); ctx.assertEquals("max_prepared_stmt_count", row.getString(0)); @@ -145,7 +183,10 @@ public void testCachePreparedStatementBatchWithSameSql(TestContext ctx) { List tuples = new ArrayList<>(); tuples.add(Tuple.of(val)); tuples.add(Tuple.of(val + 1)); - conn.preparedQuery("Select cast(? AS CHAR)").executeBatch(tuples, ctx.asyncAssertSuccess(res2 -> { + conn + .preparedQuery("Select cast(? AS CHAR)") + .executeBatch(tuples) + .onComplete(ctx.asyncAssertSuccess(res2 -> { String v1 = res2.iterator().next().getString(0); String v2 = res2.next().iterator().next().getString(0); ctx.assertEquals("" + val, v1); @@ -158,8 +199,11 @@ public void testCachePreparedStatementBatchWithSameSql(TestContext ctx) { @Test public void testAutoClosingNonCacheOneShotPreparedQueryStatement(TestContext ctx) { - MySQLConnection.connect(vertx, options.setCachePreparedStatements(false), ctx.asyncAssertSuccess(conn -> { - conn.query("SHOW VARIABLES LIKE 'max_prepared_stmt_count'").execute(ctx.asyncAssertSuccess(res1 -> { + MySQLConnection.connect(vertx, options.setCachePreparedStatements(false)).onComplete( ctx.asyncAssertSuccess(conn -> { + conn + .query("SHOW VARIABLES LIKE 'max_prepared_stmt_count'") + .execute() + .onComplete(ctx.asyncAssertSuccess(res1 -> { Row row = res1.iterator().next(); int maxPreparedStatementCount = Integer.parseInt(row.getString(1)); ctx.assertEquals("max_prepared_stmt_count", row.getString(0)); @@ -167,7 +211,10 @@ public void testAutoClosingNonCacheOneShotPreparedQueryStatement(TestContext ctx for (int i = 0; i < 2000; i++) { // if we don't close the statement automatically in the codec, the statement handles would leak and raise an statement limit error - conn.preparedQuery("SELECT 'test'").execute(ctx.asyncAssertSuccess(res2 -> { + conn + .preparedQuery("SELECT 'test'") + .execute() + .onComplete(ctx.asyncAssertSuccess(res2 -> { ctx.assertEquals("test", res2.iterator().next().getString(0)); })); } @@ -177,8 +224,11 @@ public void testAutoClosingNonCacheOneShotPreparedQueryStatement(TestContext ctx @Test public void testAutoClosingNonCacheOneShotPreparedBatchStatement(TestContext ctx) { - MySQLConnection.connect(vertx, options.setCachePreparedStatements(false), ctx.asyncAssertSuccess(conn -> { - conn.query("SHOW VARIABLES LIKE 'max_prepared_stmt_count'").execute(ctx.asyncAssertSuccess(res0 -> { + MySQLConnection.connect(vertx, options.setCachePreparedStatements(false)).onComplete( ctx.asyncAssertSuccess(conn -> { + conn + .query("SHOW VARIABLES LIKE 'max_prepared_stmt_count'") + .execute() + .onComplete(ctx.asyncAssertSuccess(res0 -> { Row row = res0.iterator().next(); int maxPreparedStatementCount = Integer.parseInt(row.getString(1)); ctx.assertEquals("max_prepared_stmt_count", row.getString(0)); @@ -187,7 +237,10 @@ public void testAutoClosingNonCacheOneShotPreparedBatchStatement(TestContext ctx for (int i = 0; i < 2000; i++) { // if we don't close the statement automatically in the codec, the statement handles would leak and raise an statement limit error List params = Arrays.asList(Tuple.of(1), Tuple.of(2), Tuple.of(3)); - conn.preparedQuery("SELECT CAST(? AS CHAR)").executeBatch(params, ctx.asyncAssertSuccess(res1 -> { + conn + .preparedQuery("SELECT CAST(? AS CHAR)") + .executeBatch(params) + .onComplete(ctx.asyncAssertSuccess(res1 -> { ctx.assertEquals("1", res1.iterator().next().getString(0)); RowSet res2 = res1.next(); ctx.assertEquals("2", res2.iterator().next().getString(0)); @@ -207,8 +260,11 @@ public void testDecodePacketSizeMoreThan16MB(TestContext ctx) { } String expected = sb.toString(); - MySQLConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.query("SELECT REPEAT('abcde', 4000000)").execute(ctx.asyncAssertSuccess(rowSet -> { + MySQLConnection.connect(vertx, options).onComplete( ctx.asyncAssertSuccess(conn -> { + conn + .query("SELECT REPEAT('abcde', 4000000)") + .execute() + .onComplete(ctx.asyncAssertSuccess(rowSet -> { ctx.assertEquals(1, rowSet.size()); Row row = rowSet.iterator().next(); ctx.assertTrue(row.getString(0).getBytes().length > 0xFFFFFF); @@ -228,9 +284,15 @@ public void testEncodePacketSizeMoreThan16MB(TestContext ctx) { Buffer buffer = Buffer.buffer(data); ctx.assertTrue(buffer.length() > 0xFFFFFF); - MySQLConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.preparedQuery("UPDATE datatype SET `LongBlob` = ? WHERE id = 2").execute(Tuple.of(buffer), ctx.asyncAssertSuccess(v -> { - conn.preparedQuery("SELECT id, `LongBlob` FROM datatype WHERE id = 2").execute(ctx.asyncAssertSuccess(rowSet -> { + MySQLConnection.connect(vertx, options).onComplete( ctx.asyncAssertSuccess(conn -> { + conn + .preparedQuery("UPDATE datatype SET `LongBlob` = ? WHERE id = 2") + .execute(Tuple.of(buffer)) + .onComplete(ctx.asyncAssertSuccess(v -> { + conn + .preparedQuery("SELECT id, `LongBlob` FROM datatype WHERE id = 2") + .execute() + .onComplete(ctx.asyncAssertSuccess(rowSet -> { Row row = rowSet.iterator().next(); ctx.assertEquals(2, row.getInteger(0)); ctx.assertEquals(2, row.getInteger("id")); @@ -254,12 +316,25 @@ public void testLocalInfileRequest(TestContext ctx) { .appendString("Whistler,Gwen,bird,NULL,1997-12-09,NULL") .appendString("\n"); } - fileSystem.createTempFile(null, null, ctx.asyncAssertSuccess(filename -> { - fileSystem.writeFile(filename, fileData, ctx.asyncAssertSuccess(write -> { - MySQLConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.query("TRUNCATE TABLE localinfile").execute(ctx.asyncAssertSuccess(cleanup -> { - conn.query("LOAD DATA LOCAL INFILE '" + filename + "' INTO TABLE localinfile FIELDS TERMINATED BY ',' ENCLOSED BY '\"' LINES TERMINATED BY '\\n';").execute(ctx.asyncAssertSuccess(v -> { - conn.query("SELECT * FROM localinfile").execute(ctx.asyncAssertSuccess(rowSet -> { + fileSystem + .createTempFile(null, null) + .onComplete(ctx.asyncAssertSuccess(filename -> { + fileSystem + .writeFile(filename, fileData) + .onComplete(ctx.asyncAssertSuccess(write -> { + MySQLConnection.connect(vertx, options).onComplete( ctx.asyncAssertSuccess(conn -> { + conn + .query("TRUNCATE TABLE localinfile") + .execute() + .onComplete(ctx.asyncAssertSuccess(cleanup -> { + conn + .query("LOAD DATA LOCAL INFILE '" + filename + "' INTO TABLE localinfile FIELDS TERMINATED BY ',' ENCLOSED BY '\"' LINES TERMINATED BY '\\n';") + .execute() + .onComplete(ctx.asyncAssertSuccess(v -> { + conn + .query("SELECT * FROM localinfile") + .execute() + .onComplete(ctx.asyncAssertSuccess(rowSet -> { ctx.assertEquals(30000, rowSet.size()); RowIterator iterator = rowSet.iterator(); for (int i = 0; i < 10000; i++) { @@ -298,12 +373,25 @@ public void testLocalInfileRequest(TestContext ctx) { public void testLocalInfileRequestEmptyFile(TestContext ctx) { FileSystem fileSystem = vertx.fileSystem(); Buffer fileData = Buffer.buffer(); - fileSystem.createTempFile(null, null, ctx.asyncAssertSuccess(filename -> { - fileSystem.writeFile(filename, fileData, ctx.asyncAssertSuccess(write -> { - MySQLConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.query("TRUNCATE TABLE localinfile").execute(ctx.asyncAssertSuccess(cleanup -> { - conn.query("LOAD DATA LOCAL INFILE '" + filename + "' INTO TABLE localinfile FIELDS TERMINATED BY ',' ENCLOSED BY '\"' LINES TERMINATED BY '\\n';").execute(ctx.asyncAssertSuccess(v -> { - conn.query("SELECT * FROM localinfile").execute(ctx.asyncAssertSuccess(rowSet -> { + fileSystem + .createTempFile(null, null) + .onComplete(ctx.asyncAssertSuccess(filename -> { + fileSystem + .writeFile(filename, fileData) + .onComplete(ctx.asyncAssertSuccess(write -> { + MySQLConnection.connect(vertx, options).onComplete( ctx.asyncAssertSuccess(conn -> { + conn + .query("TRUNCATE TABLE localinfile") + .execute() + .onComplete(ctx.asyncAssertSuccess(cleanup -> { + conn + .query("LOAD DATA LOCAL INFILE '" + filename + "' INTO TABLE localinfile FIELDS TERMINATED BY ',' ENCLOSED BY '\"' LINES TERMINATED BY '\\n';") + .execute() + .onComplete(ctx.asyncAssertSuccess(v -> { + conn + .query("SELECT * FROM localinfile") + .execute() + .onComplete(ctx.asyncAssertSuccess(rowSet -> { ctx.assertEquals(0, rowSet.size()); conn.close(); })); @@ -327,12 +415,25 @@ public void testLocalInfileRequestInPackets(TestContext ctx) { .appendString("\n"); } ctx.assertTrue(fileData.length() > 0xFFFFFF); - fileSystem.createTempFile(null, null, ctx.asyncAssertSuccess(filename -> { - fileSystem.writeFile(filename, fileData, ctx.asyncAssertSuccess(write -> { - MySQLConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.query("TRUNCATE TABLE localinfile").execute(ctx.asyncAssertSuccess(cleanup -> { - conn.query("LOAD DATA LOCAL INFILE '" + filename + "' INTO TABLE localinfile FIELDS TERMINATED BY ',' ENCLOSED BY '\"' LINES TERMINATED BY '\\n';").execute(ctx.asyncAssertSuccess(v -> { - conn.query("SELECT * FROM localinfile").execute(ctx.asyncAssertSuccess(rowSet -> { + fileSystem + .createTempFile(null, null) + .onComplete(ctx.asyncAssertSuccess(filename -> { + fileSystem + .writeFile(filename, fileData) + .onComplete(ctx.asyncAssertSuccess(write -> { + MySQLConnection.connect(vertx, options).onComplete( ctx.asyncAssertSuccess(conn -> { + conn + .query("TRUNCATE TABLE localinfile") + .execute() + .onComplete(ctx.asyncAssertSuccess(cleanup -> { + conn + .query("LOAD DATA LOCAL INFILE '" + filename + "' INTO TABLE localinfile FIELDS TERMINATED BY ',' ENCLOSED BY '\"' LINES TERMINATED BY '\\n';") + .execute() + .onComplete(ctx.asyncAssertSuccess(v -> { + conn + .query("SELECT * FROM localinfile") + .execute() + .onComplete(ctx.asyncAssertSuccess(rowSet -> { ctx.assertEquals(600000, rowSet.size()); RowIterator iterator = rowSet.iterator(); for (int i = 0; i < 200000; i++) { diff --git a/vertx-mysql-client/src/test/java/io/vertx/mysqlclient/MySQLStoredProgramsTest.java b/vertx-mysql-client/src/test/java/io/vertx/mysqlclient/MySQLStoredProgramsTest.java index bd02d980b..bb2f9b493 100644 --- a/vertx-mysql-client/src/test/java/io/vertx/mysqlclient/MySQLStoredProgramsTest.java +++ b/vertx-mysql-client/src/test/java/io/vertx/mysqlclient/MySQLStoredProgramsTest.java @@ -35,13 +35,16 @@ public void setup() { @After public void tearDown(TestContext ctx) { - vertx.close(ctx.asyncAssertSuccess()); + vertx.close().onComplete(ctx.asyncAssertSuccess()); } @Test public void testMultiStatement(TestContext ctx) { - MySQLConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.query("SELECT 1; SELECT \'test\';").execute(ctx.asyncAssertSuccess(result -> { + MySQLConnection.connect(vertx, options).onComplete( ctx.asyncAssertSuccess(conn -> { + conn + .query("SELECT 1; SELECT \'test\';") + .execute() + .onComplete(ctx.asyncAssertSuccess(result -> { Row row1 = result.iterator().next(); ctx.assertEquals(1, row1.getInteger(0)); Row row2 = result.next().iterator().next(); @@ -54,17 +57,29 @@ public void testMultiStatement(TestContext ctx) { @Test public void testMultiResult(TestContext ctx) { - MySQLConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.query("CREATE TEMPORARY TABLE ins ( id INT );").execute(ctx.asyncAssertSuccess(createTable -> { - conn.query("DROP PROCEDURE IF EXISTS multi;").execute(ctx.asyncAssertSuccess(cleanProcedure -> { - conn.query("CREATE PROCEDURE multi()\n" + + MySQLConnection.connect(vertx, options).onComplete( ctx.asyncAssertSuccess(conn -> { + conn + .query("CREATE TEMPORARY TABLE ins ( id INT );") + .execute() + .onComplete(ctx.asyncAssertSuccess(createTable -> { + conn + .query("DROP PROCEDURE IF EXISTS multi;") + .execute() + .onComplete(ctx.asyncAssertSuccess(cleanProcedure -> { + conn + .query("CREATE PROCEDURE multi()\n" + "BEGIN\n" + " SELECT 123;\n" + " SELECT 456;\n" + " INSERT INTO ins VALUES (1);\n" + " INSERT INTO ins VALUES (2);\n" + - "END;").execute(ctx.asyncAssertSuccess(createProcedure -> { - conn.query("CALL multi();").execute(ctx.asyncAssertSuccess(result -> { + "END;") + .execute() + .onComplete(ctx.asyncAssertSuccess(createProcedure -> { + conn + .query("CALL multi();") + .execute() + .onComplete(ctx.asyncAssertSuccess(result -> { // example borrowed from https://dev.mysql.com/doc/dev/mysql-server/8.0.12/page_protocol_command_phase_sp.html#sect_protocol_command_phase_sp_multi_resultset ctx.assertEquals(1, result.size()); ctx.assertEquals(123, result.iterator().next().getInteger(0)); @@ -81,7 +96,10 @@ public void testMultiResult(TestContext ctx) { ctx.assertEquals(1, thirdResult.rowCount()); // will only return the affected_rows of the last INSERT statement } - conn.query("SELECT id FROM ins").execute(ctx.asyncAssertSuccess(queryRes -> { + conn + .query("SELECT id FROM ins") + .execute() + .onComplete(ctx.asyncAssertSuccess(queryRes -> { ctx.assertEquals(2, queryRes.size()); RowIterator rowIterator = queryRes.iterator(); Row row1 = rowIterator.next(); @@ -100,17 +118,29 @@ public void testMultiResult(TestContext ctx) { @Test public void testInParameters(TestContext ctx) { // example borrowed from https://dev.mysql.com/doc/refman/8.0/en/stored-programs-defining.html - MySQLConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.query("DROP PROCEDURE IF EXISTS dorepeat;").execute(ctx.asyncAssertSuccess(cleanProcedure -> { - conn.query("CREATE PROCEDURE dorepeat(p1 INT)\n" + + MySQLConnection.connect(vertx, options).onComplete( ctx.asyncAssertSuccess(conn -> { + conn + .query("DROP PROCEDURE IF EXISTS dorepeat;") + .execute() + .onComplete(ctx.asyncAssertSuccess(cleanProcedure -> { + conn + .query("CREATE PROCEDURE dorepeat(p1 INT)\n" + "BEGIN\n" + " SET @x = 0;\n" + " REPEAT\n" + " SET @x = @x + 1;\n" + " UNTIL @x > p1 END REPEAT;\n" + - "end;").execute(ctx.asyncAssertSuccess(createProcedure -> { - conn.query("CALL dorepeat(1000);").execute(ctx.asyncAssertSuccess(callProcedure -> { - conn.query("SELECT @x;").execute(ctx.asyncAssertSuccess(result -> { + "end;") + .execute() + .onComplete(ctx.asyncAssertSuccess(createProcedure -> { + conn + .query("CALL dorepeat(1000);") + .execute() + .onComplete(ctx.asyncAssertSuccess(callProcedure -> { + conn + .query("SELECT @x;") + .execute() + .onComplete(ctx.asyncAssertSuccess(result -> { ctx.assertEquals(1, result.size()); Row row = result.iterator().next(); ctx.assertEquals(1001, row.getInteger(0)); @@ -124,14 +154,26 @@ public void testInParameters(TestContext ctx) { @Test public void testOutParameters(TestContext ctx) { - MySQLConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.query("DROP PROCEDURE IF EXISTS test_out_parameter;").execute(ctx.asyncAssertSuccess(cleanProcedure -> { - conn.query("CREATE PROCEDURE test_out_parameter(OUT p1 VARCHAR(20))\n" + + MySQLConnection.connect(vertx, options).onComplete( ctx.asyncAssertSuccess(conn -> { + conn + .query("DROP PROCEDURE IF EXISTS test_out_parameter;") + .execute() + .onComplete(ctx.asyncAssertSuccess(cleanProcedure -> { + conn + .query("CREATE PROCEDURE test_out_parameter(OUT p1 VARCHAR(20))\n" + "BEGIN\n" + " SELECT 'hello,world!' INTO p1;\n" + - "end;").execute(ctx.asyncAssertSuccess(createProcedure -> { - conn.query("CALL test_out_parameter(@OUT);").execute(ctx.asyncAssertSuccess(callProcedure -> { - conn.query("SELECT @OUT;").execute(ctx.asyncAssertSuccess(result -> { + "end;") + .execute() + .onComplete(ctx.asyncAssertSuccess(createProcedure -> { + conn + .query("CALL test_out_parameter(@OUT);") + .execute() + .onComplete(ctx.asyncAssertSuccess(callProcedure -> { + conn + .query("SELECT @OUT;") + .execute() + .onComplete(ctx.asyncAssertSuccess(result -> { ctx.assertEquals(1, result.size()); Row row = result.iterator().next(); ctx.assertEquals("hello,world!", row.getValue(0)); @@ -146,15 +188,27 @@ public void testOutParameters(TestContext ctx) { @Test public void testInOutParameters(TestContext ctx) { - MySQLConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.query("DROP PROCEDURE IF EXISTS test_inout_parameter;").execute(ctx.asyncAssertSuccess(cleanProcedure -> { - conn.query("CREATE PROCEDURE test_inout_parameter(INOUT p1 INT)\n" + + MySQLConnection.connect(vertx, options).onComplete( ctx.asyncAssertSuccess(conn -> { + conn + .query("DROP PROCEDURE IF EXISTS test_inout_parameter;") + .execute() + .onComplete(ctx.asyncAssertSuccess(cleanProcedure -> { + conn + .query("CREATE PROCEDURE test_inout_parameter(INOUT p1 INT)\n" + "BEGIN\n" + " SET p1 = p1 + 12345;\n" + - "end;").execute(ctx.asyncAssertSuccess(createProcedure -> { - conn.query("SET @INOUT = 98765;\n" + - "CALL test_inout_parameter(@INOUT);").execute(ctx.asyncAssertSuccess(callProcedure -> { - conn.query("SELECT @INOUT;").execute(ctx.asyncAssertSuccess(result -> { + "end;") + .execute() + .onComplete(ctx.asyncAssertSuccess(createProcedure -> { + conn + .query("SET @INOUT = 98765;\n" + + "CALL test_inout_parameter(@INOUT);") + .execute() + .onComplete(ctx.asyncAssertSuccess(callProcedure -> { + conn + .query("SELECT @INOUT;") + .execute() + .onComplete(ctx.asyncAssertSuccess(result -> { ctx.assertEquals(1, result.size()); Row row = result.iterator().next(); ctx.assertEquals(111110, row.getInteger(0)); diff --git a/vertx-mysql-client/src/test/java/io/vertx/mysqlclient/MySQLTLSTest.java b/vertx-mysql-client/src/test/java/io/vertx/mysqlclient/MySQLTLSTest.java index 4edc9d69e..04221d630 100644 --- a/vertx-mysql-client/src/test/java/io/vertx/mysqlclient/MySQLTLSTest.java +++ b/vertx-mysql-client/src/test/java/io/vertx/mysqlclient/MySQLTLSTest.java @@ -58,14 +58,14 @@ public void setup() { @After public void tearDown(TestContext ctx) { - vertx.close(ctx.asyncAssertSuccess()); + vertx.close().onComplete(ctx.asyncAssertSuccess()); } // @Test // @Ignore("We do not configure to enforce TLS on the client side for the testing") // public void testFailWithTlsDisabled(TestContext ctx) { // options.setSslMode(SslMode.DISABLED); -// MySQLConnection.connect(vertx, options, ctx.asyncAssertFailure(error -> { +// MySQLConnection.connect(vertx, options).onComplete(ctx.asyncAssertFailure(error -> { // // TLS support is forced to be enabled on the client side // })); // } @@ -73,9 +73,12 @@ public void tearDown(TestContext ctx) { @Test public void testSuccessWithDisabledSslMode(TestContext ctx) { options.setSslMode(SslMode.DISABLED); - MySQLConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { + MySQLConnection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> { ctx.assertFalse(conn.isSSL()); - conn.query("SELECT 1").execute(ctx.asyncAssertSuccess(res -> { + conn + .query("SELECT 1") + .execute() + .onComplete(ctx.asyncAssertSuccess(res -> { ctx.assertEquals(1, res.size()); conn.close(); })); @@ -90,9 +93,12 @@ public void testTlsSuccessWithPreferredSslMode(TestContext ctx) { .setCertPath("tls/files/client-cert.pem") .setKeyPath("tls/files/client-key.pem")); - MySQLConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { + MySQLConnection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> { ctx.assertTrue(conn.isSSL()); - conn.query("SELECT 1").execute(ctx.asyncAssertSuccess(res -> { + conn + .query("SELECT 1") + .execute() + .onComplete(ctx.asyncAssertSuccess(res -> { ctx.assertEquals(1, res.size()); conn.close(); })); @@ -107,9 +113,12 @@ public void testTlsHandshakeFailWithPreferredSslMode(TestContext ctx) { .setCertPath("tls/files/client-cert.pem") .setKeyPath("tls/files/client-key.pem")); - MySQLConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { + MySQLConnection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> { ctx.assertFalse(conn.isSSL()); - conn.query("SELECT 1").execute(ctx.asyncAssertSuccess(res -> { + conn + .query("SELECT 1") + .execute() + .onComplete(ctx.asyncAssertSuccess(res -> { ctx.assertEquals(1, res.size()); conn.close(); })); @@ -124,9 +133,12 @@ public void testNonTlsConnWithPreferredSslMode(TestContext ctx) { .setCertPath("tls/files/client-cert.pem") .setKeyPath("tls/files/client-key.pem")); - MySQLConnection.connect(vertx, nonTlsOptions, ctx.asyncAssertSuccess(conn -> { + MySQLConnection.connect(vertx, nonTlsOptions).onComplete( ctx.asyncAssertSuccess(conn -> { ctx.assertFalse(conn.isSSL()); - conn.query("SELECT 1").execute(ctx.asyncAssertSuccess(res -> { + conn + .query("SELECT 1") + .execute() + .onComplete(ctx.asyncAssertSuccess(res -> { ctx.assertEquals(1, res.size()); conn.close(); })); @@ -141,9 +153,12 @@ public void testSuccessWithRequiredSslMode(TestContext ctx) { .setCertPath("tls/files/client-cert.pem") .setKeyPath("tls/files/client-key.pem")); - MySQLConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { + MySQLConnection.connect(vertx, options).onComplete( ctx.asyncAssertSuccess(conn -> { ctx.assertTrue(conn.isSSL()); - conn.query("SELECT 1").execute(ctx.asyncAssertSuccess(res -> { + conn + .query("SELECT 1") + .execute() + .onComplete(ctx.asyncAssertSuccess(res -> { ctx.assertEquals(1, res.size()); conn.close(); })); @@ -155,9 +170,12 @@ public void testSuccessWithOnlyCertificate(TestContext ctx) { options.setSslMode(SslMode.REQUIRED); options.setPemTrustOptions(new PemTrustOptions().addCertPath("tls/files/ca.pem")); - MySQLConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { + MySQLConnection.connect(vertx, options).onComplete( ctx.asyncAssertSuccess(conn -> { ctx.assertTrue(conn.isSSL()); - conn.query("SELECT 1").execute(ctx.asyncAssertSuccess(res -> { + conn + .query("SELECT 1") + .execute() + .onComplete(ctx.asyncAssertSuccess(res -> { ctx.assertEquals(1, res.size()); conn.close(); })); @@ -169,9 +187,12 @@ public void testSuccessWithoutCertificate(TestContext ctx) { options.setSslMode(SslMode.REQUIRED); options.setTrustAll(true); - MySQLConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { + MySQLConnection.connect(vertx, options).onComplete( ctx.asyncAssertSuccess(conn -> { ctx.assertTrue(conn.isSSL()); - conn.query("SELECT 1").execute(ctx.asyncAssertSuccess(res -> { + conn + .query("SELECT 1") + .execute() + .onComplete(ctx.asyncAssertSuccess(res -> { ctx.assertEquals(1, res.size()); conn.close(); })); @@ -186,9 +207,12 @@ public void testSuccessWithVerifyCaSslMode(TestContext ctx) { .setCertPath("tls/files/client-cert.pem") .setKeyPath("tls/files/client-key.pem")); - MySQLConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { + MySQLConnection.connect(vertx, options).onComplete( ctx.asyncAssertSuccess(conn -> { ctx.assertTrue(conn.isSSL()); - conn.query("SELECT 1").execute(ctx.asyncAssertSuccess(res -> { + conn + .query("SELECT 1") + .execute() + .onComplete(ctx.asyncAssertSuccess(res -> { ctx.assertEquals(1, res.size()); conn.close(); })); @@ -203,7 +227,7 @@ public void testConnFailWithVerifyCaSslMode(TestContext ctx) { .setCertPath("tls/files/client-cert.pem") .setKeyPath("tls/files/client-key.pem")); - MySQLConnection.connect(vertx, options, ctx.asyncAssertFailure(error -> { + MySQLConnection.connect(vertx, options).onComplete( ctx.asyncAssertFailure(error -> { ctx.assertEquals("Trust options must be specified under VERIFY_CA ssl-mode.", error.getMessage()); })); } @@ -231,7 +255,7 @@ public void testConnFailWithVerifyIdentitySslMode(TestContext ctx) { .setCertPath("tls/files/client-cert.pem") .setKeyPath("tls/files/client-key.pem")); - MySQLConnection.connect(vertx, options, ctx.asyncAssertFailure(error -> { + MySQLConnection.connect(vertx, options).onComplete( ctx.asyncAssertFailure(error -> { ctx.assertEquals("Host verification algorithm must be specified under VERIFY_IDENTITY ssl-mode.", error.getMessage()); })); } @@ -240,7 +264,7 @@ public void testConnFailWithVerifyIdentitySslMode(TestContext ctx) { public void testConnFail(TestContext ctx) { options.setSslMode(SslMode.REQUIRED); - MySQLConnection.connect(vertx, options, ctx.asyncAssertFailure(error -> { + MySQLConnection.connect(vertx, options).onComplete( ctx.asyncAssertFailure(error -> { })); } @@ -249,8 +273,11 @@ public void testChangeUser(TestContext ctx) { options.setSslMode(SslMode.REQUIRED); options.setPemTrustOptions(new PemTrustOptions().addCertPath("tls/files/ca.pem")); - MySQLConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.query("SELECT current_user()").execute(ctx.asyncAssertSuccess(res1 -> { + MySQLConnection.connect(vertx, options).onComplete( ctx.asyncAssertSuccess(conn -> { + conn + .query("SELECT current_user()") + .execute() + .onComplete(ctx.asyncAssertSuccess(res1 -> { Row row1 = res1.iterator().next(); String username = row1.getString(0); ctx.assertEquals("mysql", username.substring(0, username.lastIndexOf('@'))); @@ -258,8 +285,13 @@ public void testChangeUser(TestContext ctx) { .setUser("superuser") .setPassword("password") .setDatabase("emptyschema"); - conn.changeUser(changeUserOptions, ctx.asyncAssertSuccess(v2 -> { - conn.query("SELECT current_user();SELECT database();").execute(ctx.asyncAssertSuccess(res2 -> { + conn + .changeUser(changeUserOptions) + .onComplete(ctx.asyncAssertSuccess(v2 -> { + conn + .query("SELECT current_user();SELECT database();") + .execute() + .onComplete(ctx.asyncAssertSuccess(res2 -> { ctx.assertEquals("superuser@%", res2.iterator().next().getString(0)); ctx.assertEquals("emptyschema", res2.next().iterator().next().getValue(0)); conn.close(); diff --git a/vertx-mysql-client/src/test/java/io/vertx/mysqlclient/MySQLTestBase.java b/vertx-mysql-client/src/test/java/io/vertx/mysqlclient/MySQLTestBase.java index 03fef155a..a213d06cf 100644 --- a/vertx-mysql-client/src/test/java/io/vertx/mysqlclient/MySQLTestBase.java +++ b/vertx-mysql-client/src/test/java/io/vertx/mysqlclient/MySQLTestBase.java @@ -30,7 +30,9 @@ public static void before() { } static void deleteFromMutableTable(TestContext ctx, SqlClient client, Runnable completionHandler) { - client.query( - "TRUNCATE TABLE mutable").execute(ctx.asyncAssertSuccess(result -> completionHandler.run())); + client + .query("TRUNCATE TABLE mutable") + .execute() + .onComplete(ctx.asyncAssertSuccess(result -> completionHandler.run())); } } diff --git a/vertx-mysql-client/src/test/java/io/vertx/mysqlclient/MySQLUnixDomainSocketTest.java b/vertx-mysql-client/src/test/java/io/vertx/mysqlclient/MySQLUnixDomainSocketTest.java index 55a54af67..ec010f502 100644 --- a/vertx-mysql-client/src/test/java/io/vertx/mysqlclient/MySQLUnixDomainSocketTest.java +++ b/vertx-mysql-client/src/test/java/io/vertx/mysqlclient/MySQLUnixDomainSocketTest.java @@ -16,6 +16,7 @@ import io.vertx.ext.unit.TestContext; import io.vertx.ext.unit.junit.VertxUnitRunner; import io.vertx.sqlclient.PoolOptions; +import io.vertx.sqlclient.SqlClient; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -69,13 +70,17 @@ public void uriSocketAttributeTest(TestContext context) throws UnsupportedEncodi private void uriTest(TestContext context, String uri) throws UnsupportedEncodingException { client = MySQLPool.pool(uri); - client.getConnection(context.asyncAssertSuccess(conn -> conn.close())); + client + .getConnection() + .onComplete(context.asyncAssertSuccess(SqlClient::close)); } @Test public void simpleConnect(TestContext context) { client = MySQLPool.pool(new MySQLConnectOptions(options), new PoolOptions()); - client.getConnection(context.asyncAssertSuccess(conn -> conn.close())); + client + .getConnection() + .onComplete(context.asyncAssertSuccess(SqlClient::close)); } @Test @@ -84,7 +89,9 @@ public void connectWithVertxInstance(TestContext context) { try { client = MySQLPool.pool(vertx, new MySQLConnectOptions(options), new PoolOptions()); Async async = context.async(); - client.getConnection(context.asyncAssertSuccess(conn -> { + client + .getConnection() + .onComplete(context.asyncAssertSuccess(conn -> { async.complete(); conn.close(); })); @@ -97,7 +104,9 @@ public void connectWithVertxInstance(TestContext context) { @Test public void testIgnoreSslMode(TestContext context) { client = MySQLPool.pool(new MySQLConnectOptions(options).setSslMode(SslMode.REQUIRED), new PoolOptions()); - client.getConnection(context.asyncAssertSuccess(conn -> { + client + .getConnection() + .onComplete(context.asyncAssertSuccess(conn -> { assertFalse(conn.isSSL()); conn.close(); })); diff --git a/vertx-mysql-client/src/test/java/io/vertx/mysqlclient/MySQLUtilityCommandTest.java b/vertx-mysql-client/src/test/java/io/vertx/mysqlclient/MySQLUtilityCommandTest.java index b6a43e558..66c453143 100644 --- a/vertx-mysql-client/src/test/java/io/vertx/mysqlclient/MySQLUtilityCommandTest.java +++ b/vertx-mysql-client/src/test/java/io/vertx/mysqlclient/MySQLUtilityCommandTest.java @@ -37,13 +37,15 @@ public void setup() { @After public void teardown(TestContext ctx) { - vertx.close(ctx.asyncAssertSuccess()); + vertx.close().onComplete(ctx.asyncAssertSuccess()); } @Test public void testPingCommand(TestContext ctx) { - MySQLConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.ping(ctx.asyncAssertSuccess(v -> { + MySQLConnection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> { + conn + .ping() + .onComplete(ctx.asyncAssertSuccess(v -> { conn.close(); })); })); @@ -51,11 +53,19 @@ public void testPingCommand(TestContext ctx) { @Test public void testChangeSchema(TestContext ctx) { - MySQLConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.query("SELECT DATABASE();").execute(ctx.asyncAssertSuccess(result -> { + MySQLConnection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> { + conn + .query("SELECT DATABASE();") + .execute() + .onComplete(ctx.asyncAssertSuccess(result -> { ctx.assertEquals("testschema", result.iterator().next().getString(0)); - conn.specifySchema("emptyschema", ctx.asyncAssertSuccess(v -> { - conn.query("SELECT DATABASE();").execute(ctx.asyncAssertSuccess(result2 -> { + conn + .specifySchema("emptyschema") + .onComplete(ctx.asyncAssertSuccess(v -> { + conn + .query("SELECT DATABASE();") + .execute() + .onComplete(ctx.asyncAssertSuccess(result2 -> { ctx.assertEquals("emptyschema", result2.iterator().next().getString(0)); conn.close(); })); @@ -66,10 +76,15 @@ public void testChangeSchema(TestContext ctx) { @Test public void testChangeToInvalidSchema(TestContext ctx) { - MySQLConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.query("SELECT DATABASE();").execute(ctx.asyncAssertSuccess(result -> { + MySQLConnection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> { + conn + .query("SELECT DATABASE();") + .execute() + .onComplete(ctx.asyncAssertSuccess(result -> { ctx.assertEquals("testschema", result.iterator().next().getString(0)); - conn.specifySchema("invalidschema", ctx.asyncAssertFailure(error -> { + conn + .specifySchema("invalidschema") + .onComplete(ctx.asyncAssertFailure(error -> { conn.close(); })); })); @@ -78,8 +93,10 @@ public void testChangeToInvalidSchema(TestContext ctx) { @Test public void testStatistics(TestContext ctx) { - MySQLConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.getInternalStatistics(ctx.asyncAssertSuccess(result -> { + MySQLConnection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> { + conn + .getInternalStatistics() + .onComplete(ctx.asyncAssertSuccess(result -> { ctx.assertTrue(!result.isEmpty()); conn.close(); })); @@ -88,9 +105,11 @@ public void testStatistics(TestContext ctx) { @Test public void testSetOption(TestContext ctx) { - MySQLConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { + MySQLConnection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> { // CLIENT_MULTI_STATEMENTS is on by default - conn.query("SELECT 1; SELECT 2;").execute(ctx.asyncAssertSuccess(rowSet1 -> { + conn.query("SELECT 1; SELECT 2;") + .execute() + .onComplete(ctx.asyncAssertSuccess(rowSet1 -> { ctx.assertEquals(1, rowSet1.size()); Row row1 = rowSet1.iterator().next(); ctx.assertEquals(1, row1.getInteger(0)); @@ -99,9 +118,14 @@ public void testSetOption(TestContext ctx) { Row row2 = rowSet2.iterator().next(); ctx.assertEquals(2, row2.getInteger(0)); - conn.setOption(MySQLSetOption.MYSQL_OPTION_MULTI_STATEMENTS_OFF, ctx.asyncAssertSuccess(v -> { + conn + .setOption(MySQLSetOption.MYSQL_OPTION_MULTI_STATEMENTS_OFF) + .onComplete(ctx.asyncAssertSuccess(v -> { // CLIENT_MULTI_STATEMENTS is off now - conn.query("SELECT 1; SELECT 2;").execute(ctx.asyncAssertFailure(error -> { + conn + .query("SELECT 1; SELECT 2;") + .execute() + .onComplete(ctx.asyncAssertFailure(error -> { conn.close(); })); })); @@ -112,11 +136,22 @@ public void testSetOption(TestContext ctx) { @Test public void testResetConnection(TestContext ctx) { Assume.assumeFalse(rule.isUsingMySQL5_6()); - MySQLConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.query("CREATE TEMPORARY TABLE temp (temp INTEGER)").execute(ctx.asyncAssertSuccess(res1 -> { - conn.query("SELECT * FROM temp").execute(ctx.asyncAssertSuccess(res2 -> { - conn.resetConnection(ctx.asyncAssertSuccess(res3 -> { - conn.query("SELECT * FROM temp").execute(ctx.asyncAssertFailure(error -> { + MySQLConnection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> { + conn + .query("CREATE TEMPORARY TABLE temp (temp INTEGER)") + .execute() + .onComplete(ctx.asyncAssertSuccess(res1 -> { + conn + .query("SELECT * FROM temp") + .execute() + .onComplete(ctx.asyncAssertSuccess(res2 -> { + conn + .resetConnection() + .onComplete(ctx.asyncAssertSuccess(res3 -> { + conn + .query("SELECT * FROM temp") + .execute() + .onComplete(ctx.asyncAssertFailure(error -> { conn.close(); })); })); @@ -127,8 +162,11 @@ public void testResetConnection(TestContext ctx) { @Test public void testChangeUser(TestContext ctx) { - MySQLConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.query("SELECT current_user()").execute(ctx.asyncAssertSuccess(res1 -> { + MySQLConnection.connect(vertx, options).onComplete( ctx.asyncAssertSuccess(conn -> { + conn + .query("SELECT current_user()") + .execute() + .onComplete(ctx.asyncAssertSuccess(res1 -> { Row row1 = res1.iterator().next(); String username = row1.getString(0); ctx.assertEquals("mysql", username.substring(0, username.lastIndexOf('@'))); @@ -136,8 +174,13 @@ public void testChangeUser(TestContext ctx) { .setUser("superuser") .setPassword("password") .setDatabase("emptyschema"); - conn.changeUser(changeUserOptions, ctx.asyncAssertSuccess(v2 -> { - conn.query("SELECT current_user();SELECT database();").execute(ctx.asyncAssertSuccess(res2 -> { + conn + .changeUser(changeUserOptions) + .onComplete(ctx.asyncAssertSuccess(v2 -> { + conn + .query("SELECT current_user();SELECT database();") + .execute() + .onComplete(ctx.asyncAssertSuccess(res2 -> { ctx.assertEquals("superuser@%", res2.iterator().next().getString(0)); ctx.assertEquals("emptyschema", res2.next().iterator().next().getValue(0)); conn.close(); @@ -149,8 +192,11 @@ public void testChangeUser(TestContext ctx) { @Test public void testChangeUserAuthWithServerRsaPublicKey(TestContext ctx) { - MySQLConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.query("SELECT current_user()").execute(ctx.asyncAssertSuccess(res1 -> { + MySQLConnection.connect(vertx, options).onComplete( ctx.asyncAssertSuccess(conn -> { + conn + .query("SELECT current_user()") + .execute() + .onComplete(ctx.asyncAssertSuccess(res1 -> { Row row1 = res1.iterator().next(); String username = row1.getString(0); ctx.assertEquals("mysql", username.substring(0, username.lastIndexOf('@'))); @@ -167,8 +213,13 @@ public void testChangeUserAuthWithServerRsaPublicKey(TestContext ctx) { "7ha1P+ZOgPBlV037KDQMS6cUh9vTablEHsMLhDZanymXzzjBkL+wH/b9cdL16LkQ\n" + "5QIDAQAB\n" + "-----END PUBLIC KEY-----\n")); - conn.changeUser(changeUserOptions, ctx.asyncAssertSuccess(v2 -> { - conn.query("SELECT current_user();SELECT database();").execute(ctx.asyncAssertSuccess(res2 -> { + conn + .changeUser(changeUserOptions) + .onComplete(ctx.asyncAssertSuccess(v2 -> { + conn + .query("SELECT current_user();SELECT database();") + .execute() + .onComplete(ctx.asyncAssertSuccess(res2 -> { ctx.assertEquals("superuser@%", res2.iterator().next().getString(0)); ctx.assertEquals("emptyschema", res2.next().iterator().next().getValue(0)); conn.close(); diff --git a/vertx-mysql-client/src/test/java/io/vertx/mysqlclient/data/DateTimeBinaryCodecTest.java b/vertx-mysql-client/src/test/java/io/vertx/mysqlclient/data/DateTimeBinaryCodecTest.java index 55be936b8..7b5d52858 100644 --- a/vertx-mysql-client/src/test/java/io/vertx/mysqlclient/data/DateTimeBinaryCodecTest.java +++ b/vertx-mysql-client/src/test/java/io/vertx/mysqlclient/data/DateTimeBinaryCodecTest.java @@ -30,8 +30,11 @@ public class DateTimeBinaryCodecTest extends DateTimeCodecTest { @Test public void testBinaryDecodeAll(TestContext ctx) { - MySQLConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.preparedQuery("SELECT `test_year`, `test_timestamp`, `test_datetime` FROM datatype WHERE id = 1").execute(ctx.asyncAssertSuccess(result -> { + MySQLConnection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> { + conn + .preparedQuery("SELECT `test_year`, `test_timestamp`, `test_datetime` FROM datatype WHERE id = 1") + .execute() + .onComplete(ctx.asyncAssertSuccess(result -> { ctx.assertEquals(1, result.size()); Row row = result.iterator().next(); ctx.assertEquals(3, row.size()); @@ -157,9 +160,15 @@ public void testEncodeCastStringToTime(TestContext ctx) { } private void testEncodeTime(TestContext ctx, Duration param, Duration expected) { - MySQLConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.preparedQuery("UPDATE basicdatatype SET `test_time` = ?" + " WHERE id = 2").execute(Tuple.tuple().addValue(param), ctx.asyncAssertSuccess(updateResult -> { - conn.preparedQuery("SELECT `test_time` FROM basicdatatype WHERE id = 2").execute(ctx.asyncAssertSuccess(result -> { + MySQLConnection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> { + conn + .preparedQuery("UPDATE basicdatatype SET `test_time` = ?" + " WHERE id = 2") + .execute(Tuple.tuple().addValue(param)) + .onComplete(ctx.asyncAssertSuccess(updateResult -> { + conn + .preparedQuery("SELECT `test_time` FROM basicdatatype WHERE id = 2") + .execute() + .onComplete(ctx.asyncAssertSuccess(result -> { ctx.assertEquals(1, result.size()); Row row = result.iterator().next(); ctx.assertEquals(expected, row.getValue(0)); @@ -171,9 +180,15 @@ private void testEncodeTime(TestContext ctx, Duration param, Duration expected) } private void testEncodeTime(TestContext ctx, LocalTime param, Duration expectedDuration, LocalTime expectedLocalTime) { - MySQLConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.preparedQuery("UPDATE basicdatatype SET `test_time` = ?" + " WHERE id = 2").execute(Tuple.tuple().addValue(param), ctx.asyncAssertSuccess(updateResult -> { - conn.preparedQuery("SELECT `test_time` FROM basicdatatype WHERE id = 2").execute(ctx.asyncAssertSuccess(result -> { + MySQLConnection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> { + conn + .preparedQuery("UPDATE basicdatatype SET `test_time` = ?" + " WHERE id = 2") + .execute(Tuple.tuple().addValue(param)) + .onComplete(ctx.asyncAssertSuccess(updateResult -> { + conn + .preparedQuery("SELECT `test_time` FROM basicdatatype WHERE id = 2") + .execute() + .onComplete(ctx.asyncAssertSuccess(result -> { ctx.assertEquals(1, result.size()); Row row = result.iterator().next(); ctx.assertEquals(expectedDuration, row.getValue(0)); @@ -196,8 +211,11 @@ protected void testDecodeGeneric(TestContext ctx, String data, String dataTy @Override protected void testDecodeGeneric(TestContext ctx, String data, String dataType, Consumer valueAccessor, String columnName) { - MySQLConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.preparedQuery("SELECT CAST(\'" + data + "\' AS " + dataType + ") " + columnName).execute(ctx.asyncAssertSuccess(result -> { + MySQLConnection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> { + conn + .preparedQuery("SELECT CAST(\'" + data + "\' AS " + dataType + ") " + columnName) + .execute() + .onComplete(ctx.asyncAssertSuccess(result -> { ctx.assertEquals(1, result.size()); Row row = result.iterator().next(); valueAccessor.accept(row); diff --git a/vertx-mysql-client/src/test/java/io/vertx/mysqlclient/data/DateTimeTextCodecTest.java b/vertx-mysql-client/src/test/java/io/vertx/mysqlclient/data/DateTimeTextCodecTest.java index b941c1585..5b96d92f8 100644 --- a/vertx-mysql-client/src/test/java/io/vertx/mysqlclient/data/DateTimeTextCodecTest.java +++ b/vertx-mysql-client/src/test/java/io/vertx/mysqlclient/data/DateTimeTextCodecTest.java @@ -25,8 +25,11 @@ public class DateTimeTextCodecTest extends DateTimeCodecTest { @Test public void testTextDecodeAll(TestContext ctx) { - MySQLConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.query("SELECT `test_year`, `test_timestamp`, `test_datetime` FROM datatype WHERE id = 1").execute(ctx.asyncAssertSuccess(result -> { + MySQLConnection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> { + conn + .query("SELECT `test_year`, `test_timestamp`, `test_datetime` FROM datatype WHERE id = 1") + .execute() + .onComplete(ctx.asyncAssertSuccess(result -> { ctx.assertEquals(1, result.size()); Row row = result.iterator().next(); ctx.assertEquals(3, row.size()); @@ -58,8 +61,11 @@ protected void testDecodeGeneric(TestContext ctx, String data, String dataTy @Override protected void testDecodeGeneric(TestContext ctx, String data, String dataType, Consumer valueAccessor, String columnName) { - MySQLConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.query("SELECT CAST(\'" + data + "\' AS " + dataType + ") " + columnName).execute(ctx.asyncAssertSuccess(result -> { + MySQLConnection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> { + conn + .query("SELECT CAST(\'" + data + "\' AS " + dataType + ") " + columnName) + .execute() + .onComplete(ctx.asyncAssertSuccess(result -> { ctx.assertEquals(1, result.size()); Row row = result.iterator().next(); valueAccessor.accept(row); diff --git a/vertx-mysql-client/src/test/java/io/vertx/mysqlclient/data/JsonBinaryCodecTest.java b/vertx-mysql-client/src/test/java/io/vertx/mysqlclient/data/JsonBinaryCodecTest.java index 22ca89553..24bef4351 100644 --- a/vertx-mysql-client/src/test/java/io/vertx/mysqlclient/data/JsonBinaryCodecTest.java +++ b/vertx-mysql-client/src/test/java/io/vertx/mysqlclient/data/JsonBinaryCodecTest.java @@ -131,11 +131,20 @@ public void testEncodeJsonArray(TestContext ctx) { @Test public void testDecodeJsonUsingTable(TestContext ctx) { - MySQLConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.query("CREATE TEMPORARY TABLE json_test(test_json JSON);").execute(ctx.asyncAssertSuccess(c -> { - conn.query("INSERT INTO json_test VALUE ('{\"phrase\": \"à tout à l''heure\"}');\n" + - "INSERT INTO json_test VALUE ('{\"emoji\": \"\uD83D\uDE00\uD83E\uDD23\uD83D\uDE0A\uD83D\uDE07\uD83D\uDE33\uD83D\uDE31\"}');").execute(ctx.asyncAssertSuccess(i -> { - conn.preparedQuery("SELECT test_json FROM json_test").execute(ctx.asyncAssertSuccess(res -> { + MySQLConnection.connect(vertx, options).onComplete( ctx.asyncAssertSuccess(conn -> { + conn + .query("CREATE TEMPORARY TABLE json_test(test_json JSON);") + .execute() + .onComplete(ctx.asyncAssertSuccess(c -> { + conn + .query("INSERT INTO json_test VALUE ('{\"phrase\": \"à tout à l''heure\"}');\n" + + "INSERT INTO json_test VALUE ('{\"emoji\": \"\uD83D\uDE00\uD83E\uDD23\uD83D\uDE0A\uD83D\uDE07\uD83D\uDE33\uD83D\uDE31\"}');") + .execute() + .onComplete(ctx.asyncAssertSuccess(i -> { + conn + .preparedQuery("SELECT test_json FROM json_test") + .execute() + .onComplete(ctx.asyncAssertSuccess(res -> { ctx.assertEquals(2, res.size()); RowIterator iterator = res.iterator(); Row row1 = iterator.next(); @@ -158,8 +167,11 @@ public void testDecodeJsonUsingTable(TestContext ctx) { @Override protected void testDecodeJson(TestContext ctx, String script, Object expected, Consumer checker) { - MySQLConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.preparedQuery(script).execute(ctx.asyncAssertSuccess(result -> { + MySQLConnection.connect(vertx, options).onComplete( ctx.asyncAssertSuccess(conn -> { + conn + .preparedQuery(script) + .execute() + .onComplete(ctx.asyncAssertSuccess(result -> { ctx.assertEquals(1, result.size()); Row row = result.iterator().next(); ctx.assertEquals(expected, row.getValue(0)); @@ -179,10 +191,19 @@ private void testEncodeJsonWithCast(TestContext ctx, Tuple params, Object expect } private void testEncodeJson(TestContext ctx, Tuple params, Object expected, Consumer checker, String insertScript) { - MySQLConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.preparedQuery(CREATE_TABLE).execute(ctx.asyncAssertSuccess(createTable -> { - conn.preparedQuery(insertScript).execute(params, ctx.asyncAssertSuccess(insert -> { - conn.preparedQuery(QUERY_JSON).execute(ctx.asyncAssertSuccess(result -> { + MySQLConnection.connect(vertx, options).onComplete( ctx.asyncAssertSuccess(conn -> { + conn + .preparedQuery(CREATE_TABLE) + .execute() + .onComplete(ctx.asyncAssertSuccess(createTable -> { + conn + .preparedQuery(insertScript) + .execute(params) + .onComplete(ctx.asyncAssertSuccess(insert -> { + conn + .preparedQuery(QUERY_JSON) + .execute() + .onComplete(ctx.asyncAssertSuccess(result -> { ctx.assertEquals(1, result.size()); Row row = result.iterator().next(); ctx.assertEquals(expected, row.getValue(0)); diff --git a/vertx-mysql-client/src/test/java/io/vertx/mysqlclient/data/JsonTextCodecTest.java b/vertx-mysql-client/src/test/java/io/vertx/mysqlclient/data/JsonTextCodecTest.java index e08633c7e..348e9e9a6 100644 --- a/vertx-mysql-client/src/test/java/io/vertx/mysqlclient/data/JsonTextCodecTest.java +++ b/vertx-mysql-client/src/test/java/io/vertx/mysqlclient/data/JsonTextCodecTest.java @@ -27,11 +27,20 @@ public class JsonTextCodecTest extends JsonDataTypeTest { @Test public void testDecodeJsonUsingTable(TestContext ctx) { - MySQLConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.query("CREATE TEMPORARY TABLE json_test(test_json JSON);").execute(ctx.asyncAssertSuccess(c -> { - conn.query("INSERT INTO json_test VALUE ('{\"phrase\": \"à tout à l''heure\"}');\n" + - "INSERT INTO json_test VALUE ('{\"emoji\": \"\uD83D\uDE00\uD83E\uDD23\uD83D\uDE0A\uD83D\uDE07\uD83D\uDE33\uD83D\uDE31\"}');").execute(ctx.asyncAssertSuccess(i -> { - conn.query("SELECT test_json FROM json_test").execute(ctx.asyncAssertSuccess(res -> { + MySQLConnection.connect(vertx, options).onComplete( ctx.asyncAssertSuccess(conn -> { + conn + .query("CREATE TEMPORARY TABLE json_test(test_json JSON);") + .execute() + .onComplete(ctx.asyncAssertSuccess(c -> { + conn + .query("INSERT INTO json_test VALUE ('{\"phrase\": \"à tout à l''heure\"}');\n" + + "INSERT INTO json_test VALUE ('{\"emoji\": \"\uD83D\uDE00\uD83E\uDD23\uD83D\uDE0A\uD83D\uDE07\uD83D\uDE33\uD83D\uDE31\"}');") + .execute() + .onComplete(ctx.asyncAssertSuccess(i -> { + conn + .query("SELECT test_json FROM json_test") + .execute() + .onComplete(ctx.asyncAssertSuccess(res -> { ctx.assertEquals(2, res.size()); RowIterator iterator = res.iterator(); Row row1 = iterator.next(); @@ -54,8 +63,11 @@ public void testDecodeJsonUsingTable(TestContext ctx) { @Override protected void testDecodeJson(TestContext ctx, String script, Object expected, Consumer checker) { - MySQLConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.query(script).execute(ctx.asyncAssertSuccess(result -> { + MySQLConnection.connect(vertx, options).onComplete( ctx.asyncAssertSuccess(conn -> { + conn + .query(script) + .execute() + .onComplete(ctx.asyncAssertSuccess(result -> { ctx.assertEquals(1, result.size()); Row row = result.iterator().next(); ctx.assertEquals(expected, row.getValue(0)); diff --git a/vertx-mysql-client/src/test/java/io/vertx/mysqlclient/data/MySQLDataTypeTestBase.java b/vertx-mysql-client/src/test/java/io/vertx/mysqlclient/data/MySQLDataTypeTestBase.java index 2766e7f23..17e62e8e8 100644 --- a/vertx-mysql-client/src/test/java/io/vertx/mysqlclient/data/MySQLDataTypeTestBase.java +++ b/vertx-mysql-client/src/test/java/io/vertx/mysqlclient/data/MySQLDataTypeTestBase.java @@ -37,7 +37,7 @@ public void setup() { @After public void teardown(TestContext ctx) { - vertx.close(ctx.asyncAssertSuccess()); + vertx.close().onComplete(ctx.asyncAssertSuccess()); } protected void testTextDecodeGenericWithTable(TestContext ctx, @@ -52,8 +52,11 @@ protected void testTextDecodeGenericWithTable(TestContext ctx, protected void testTextDecodeGenericWithTable(TestContext ctx, String columnName, BiConsumer expected) { - MySQLConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.query("SELECT `" + columnName + "` FROM datatype WHERE id = 1").execute(ctx.asyncAssertSuccess(result -> { + MySQLConnection.connect(vertx, options).onComplete( ctx.asyncAssertSuccess(conn -> { + conn + .query("SELECT `" + columnName + "` FROM datatype WHERE id = 1") + .execute() + .onComplete(ctx.asyncAssertSuccess(result -> { ctx.assertEquals(1, result.size()); Row row = result.iterator().next(); expected.accept(row, columnName); @@ -74,8 +77,11 @@ protected void testBinaryDecodeGenericWithTable(TestContext ctx, protected void testBinaryDecodeGenericWithTable(TestContext ctx, String columnName, BiConsumer expected) { - MySQLConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.preparedQuery("SELECT `" + columnName + "` FROM datatype WHERE id = 1").execute(ctx.asyncAssertSuccess(result -> { + MySQLConnection.connect(vertx, options).onComplete( ctx.asyncAssertSuccess(conn -> { + conn + .preparedQuery("SELECT `" + columnName + "` FROM datatype WHERE id = 1") + .execute() + .onComplete(ctx.asyncAssertSuccess(result -> { ctx.assertEquals(1, result.size()); Row row = result.iterator().next(); expected.accept(row, columnName); @@ -88,9 +94,15 @@ protected void testBinaryEncodeGeneric(TestContext ctx, String columnName, Object param, BiConsumer valueAccessor) { - MySQLConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.preparedQuery("UPDATE datatype SET `" + columnName + "` = ?" + " WHERE id = 2").execute(Tuple.tuple().addValue(param), ctx.asyncAssertSuccess(updateResult -> { - conn.preparedQuery("SELECT `" + columnName + "` FROM datatype WHERE id = 2").execute(ctx.asyncAssertSuccess(result -> { + MySQLConnection.connect(vertx, options).onComplete( ctx.asyncAssertSuccess(conn -> { + conn + .preparedQuery("UPDATE datatype SET `" + columnName + "` = ?" + " WHERE id = 2") + .execute(Tuple.tuple().addValue(param)) + .onComplete(ctx.asyncAssertSuccess(updateResult -> { + conn + .preparedQuery("SELECT `" + columnName + "` FROM datatype WHERE id = 2") + .execute() + .onComplete(ctx.asyncAssertSuccess(result -> { ctx.assertEquals(1, result.size()); Row row = result.iterator().next(); valueAccessor.accept(row, columnName); @@ -110,8 +122,11 @@ protected void testBinaryEncodeGeneric(TestContext ctx, } protected void testBinaryDecode(TestContext ctx, String sql, Tuple params, Consumer> checker) { - MySQLConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.preparedQuery(sql).execute(params, ctx.asyncAssertSuccess(result -> { + MySQLConnection.connect(vertx, options).onComplete( ctx.asyncAssertSuccess(conn -> { + conn + .preparedQuery(sql) + .execute(params) + .onComplete(ctx.asyncAssertSuccess(result -> { checker.accept(result); conn.close(); })); @@ -119,8 +134,11 @@ protected void testBinaryDecode(TestContext ctx, String sql, Tuple params, Consu } protected void testBinaryDecode(TestContext ctx, String sql, Consumer> checker) { - MySQLConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.preparedQuery(sql).execute(ctx.asyncAssertSuccess(result -> { + MySQLConnection.connect(vertx, options).onComplete( ctx.asyncAssertSuccess(conn -> { + conn + .preparedQuery(sql) + .execute() + .onComplete(ctx.asyncAssertSuccess(result -> { checker.accept(result); conn.close(); })); @@ -128,8 +146,11 @@ protected void testBinaryDecode(TestContext ctx, String sql, Consumer> checker) { - MySQLConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.query(sql).execute(ctx.asyncAssertSuccess(result -> { + MySQLConnection.connect(vertx, options).onComplete( ctx.asyncAssertSuccess(conn -> { + conn + .query(sql) + .execute() + .onComplete(ctx.asyncAssertSuccess(result -> { checker.accept(result); conn.close(); })); diff --git a/vertx-mysql-client/src/test/java/io/vertx/mysqlclient/data/SpatialBinaryCodecTest.java b/vertx-mysql-client/src/test/java/io/vertx/mysqlclient/data/SpatialBinaryCodecTest.java index 31d0b308d..645de8c42 100644 --- a/vertx-mysql-client/src/test/java/io/vertx/mysqlclient/data/SpatialBinaryCodecTest.java +++ b/vertx-mysql-client/src/test/java/io/vertx/mysqlclient/data/SpatialBinaryCodecTest.java @@ -188,8 +188,11 @@ public void testEncodeGeometryCollection(TestContext ctx) { } private void testBinaryEncodeGeometry(TestContext ctx, Object param, Consumer> checker) { - MySQLConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.preparedQuery("SELECT ST_AsText(ST_GeomFromWKB(?)) AS test_geometry;").execute(Tuple.of(param), ctx.asyncAssertSuccess(res -> { + MySQLConnection.connect(vertx, options).onComplete( ctx.asyncAssertSuccess(conn -> { + conn + .preparedQuery("SELECT ST_AsText(ST_GeomFromWKB(?)) AS test_geometry;") + .execute(Tuple.of(param)) + .onComplete(ctx.asyncAssertSuccess(res -> { checker.accept(res); conn.close(); })); diff --git a/vertx-mysql-client/src/test/java/io/vertx/mysqlclient/data/StringDataTypeTest.java b/vertx-mysql-client/src/test/java/io/vertx/mysqlclient/data/StringDataTypeTest.java index 76b71e6c1..6f77a193a 100644 --- a/vertx-mysql-client/src/test/java/io/vertx/mysqlclient/data/StringDataTypeTest.java +++ b/vertx-mysql-client/src/test/java/io/vertx/mysqlclient/data/StringDataTypeTest.java @@ -27,8 +27,11 @@ private enum Size { @Test public void testBinaryDecodeAll(TestContext ctx) { - MySQLConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.preparedQuery("SELECT * FROM datatype WHERE id = 1").execute(ctx.asyncAssertSuccess(result -> { + MySQLConnection.connect(vertx, options).onComplete( ctx.asyncAssertSuccess(conn -> { + conn + .preparedQuery("SELECT * FROM datatype WHERE id = 1") + .execute() + .onComplete(ctx.asyncAssertSuccess(result -> { ctx.assertEquals(1, result.size()); Row row = result.iterator().next(); ctx.assertEquals(1, row.getValue(0)); diff --git a/vertx-mysql-client/src/test/java/io/vertx/mysqlclient/tck/ClientConfig.java b/vertx-mysql-client/src/test/java/io/vertx/mysqlclient/tck/ClientConfig.java index 12cb8a426..59527b43f 100644 --- a/vertx-mysql-client/src/test/java/io/vertx/mysqlclient/tck/ClientConfig.java +++ b/vertx-mysql-client/src/test/java/io/vertx/mysqlclient/tck/ClientConfig.java @@ -37,7 +37,7 @@ Connector connect(Vertx vertx, SqlConnectOptions options) { return new Connector() { @Override public void connect(Handler> handler) { - MySQLConnection.connect(vertx, new MySQLConnectOptions(options), ar -> { + MySQLConnection.connect(vertx, new MySQLConnectOptions(options)).onComplete(ar -> { if (ar.succeeded()) { handler.handle(Future.succeededFuture(ar.result())); } else { @@ -60,7 +60,7 @@ Connector connect(Vertx vertx, SqlConnectOptions options) { return new Connector() { @Override public void connect(Handler> handler) { - pool.getConnection(ar -> { + pool.getConnection().onComplete(ar -> { if (ar.succeeded()) { handler.handle(Future.succeededFuture(ar.result())); } else { diff --git a/vertx-mysql-client/src/test/java/io/vertx/mysqlclient/tck/MySQLBinaryDataTypeDecodeTest.java b/vertx-mysql-client/src/test/java/io/vertx/mysqlclient/tck/MySQLBinaryDataTypeDecodeTest.java index 1b81052ed..e7451f402 100644 --- a/vertx-mysql-client/src/test/java/io/vertx/mysqlclient/tck/MySQLBinaryDataTypeDecodeTest.java +++ b/vertx-mysql-client/src/test/java/io/vertx/mysqlclient/tck/MySQLBinaryDataTypeDecodeTest.java @@ -59,7 +59,10 @@ protected void initConnector() { @Override public void testBoolean(TestContext ctx) { connector.connect(ctx.asyncAssertSuccess(conn -> { - conn.preparedQuery("SELECT test_boolean FROM basicdatatype WHERE id = 1").execute(ctx.asyncAssertSuccess(result -> { + conn + .preparedQuery("SELECT test_boolean FROM basicdatatype WHERE id = 1") + .execute() + .onComplete(ctx.asyncAssertSuccess(result -> { ctx.assertEquals(1, result.size()); Row row = result.iterator().next(); ctx.assertEquals(true, row.getBoolean(0)); @@ -82,7 +85,8 @@ public void testTime(TestContext ctx) { public void testSelectAll(TestContext ctx) { // MySQL TIME type is mapped to java.time.Duration so we need to override here connector.connect(ctx.asyncAssertSuccess(conn -> { - conn.preparedQuery("SELECT " + + conn + .preparedQuery("SELECT " + "test_int_2," + "test_int_4," + "test_int_8," + @@ -95,7 +99,9 @@ public void testSelectAll(TestContext ctx) { "test_varchar," + "test_date," + "test_time " + - "from basicdatatype where id = 1").execute(ctx.asyncAssertSuccess(result -> { + "from basicdatatype where id = 1") + .execute() + .onComplete(ctx.asyncAssertSuccess(result -> { ctx.assertEquals(1, result.size()); Row row = result.iterator().next(); ctx.assertEquals(12, row.size()); diff --git a/vertx-mysql-client/src/test/java/io/vertx/mysqlclient/tck/MySQLBinaryDataTypeEncodeTest.java b/vertx-mysql-client/src/test/java/io/vertx/mysqlclient/tck/MySQLBinaryDataTypeEncodeTest.java index 18bf4d2fb..5667a0ac7 100644 --- a/vertx-mysql-client/src/test/java/io/vertx/mysqlclient/tck/MySQLBinaryDataTypeEncodeTest.java +++ b/vertx-mysql-client/src/test/java/io/vertx/mysqlclient/tck/MySQLBinaryDataTypeEncodeTest.java @@ -64,8 +64,14 @@ protected String statement(String... parts) { @Override public void testBoolean(TestContext ctx) { connector.connect(ctx.asyncAssertSuccess(conn -> { - conn.preparedQuery("UPDATE basicdatatype SET test_boolean = ? WHERE id = 2").execute(Tuple.tuple().addValue(true), ctx.asyncAssertSuccess(updateResult -> { - conn.preparedQuery("SELECT test_boolean FROM basicdatatype WHERE id = 2").execute(ctx.asyncAssertSuccess(result -> { + conn + .preparedQuery("UPDATE basicdatatype SET test_boolean = ? WHERE id = 2") + .execute(Tuple.tuple().addValue(true)) + .onComplete(ctx.asyncAssertSuccess(updateResult -> { + conn + .preparedQuery("SELECT test_boolean FROM basicdatatype WHERE id = 2") + .execute() + .onComplete(ctx.asyncAssertSuccess(result -> { ctx.assertEquals(1, result.size()); Row row = result.iterator().next(); ctx.assertEquals(true, row.getBoolean(0)); diff --git a/vertx-mysql-client/src/test/java/io/vertx/mysqlclient/tck/MySQLTextDataTypeDecodeTest.java b/vertx-mysql-client/src/test/java/io/vertx/mysqlclient/tck/MySQLTextDataTypeDecodeTest.java index 71c1a650c..1acb2d76e 100644 --- a/vertx-mysql-client/src/test/java/io/vertx/mysqlclient/tck/MySQLTextDataTypeDecodeTest.java +++ b/vertx-mysql-client/src/test/java/io/vertx/mysqlclient/tck/MySQLTextDataTypeDecodeTest.java @@ -58,7 +58,10 @@ protected void initConnector() { @Override public void testBoolean(TestContext ctx) { connector.connect(ctx.asyncAssertSuccess(conn -> { - conn.query("SELECT test_boolean FROM basicdatatype WHERE id = 1").execute(ctx.asyncAssertSuccess(result -> { + conn + .query("SELECT test_boolean FROM basicdatatype WHERE id = 1") + .execute() + .onComplete(ctx.asyncAssertSuccess(result -> { ctx.assertEquals(1, result.size()); Row row = result.iterator().next(); ctx.assertEquals(true, row.getBoolean(0)); diff --git a/vertx-oracle-client/src/test/java/io/vertx/oracleclient/test/OracleBinaryDataTypesTest.java b/vertx-oracle-client/src/test/java/io/vertx/oracleclient/test/OracleBinaryDataTypesTest.java index 7b5382af3..46de7e64a 100644 --- a/vertx-oracle-client/src/test/java/io/vertx/oracleclient/test/OracleBinaryDataTypesTest.java +++ b/vertx-oracle-client/src/test/java/io/vertx/oracleclient/test/OracleBinaryDataTypesTest.java @@ -45,7 +45,7 @@ public void setUp() throws Exception { @After public void tearDown(TestContext ctx) throws Exception { - pool.close(ctx.asyncAssertSuccess()); + pool.close().onComplete(ctx.asyncAssertSuccess()); } @Test @@ -61,10 +61,12 @@ public void testEncodeBlob(TestContext ctx) { private void testEncode(TestContext ctx, String columnName, Buffer expected, Function input) { pool .preparedQuery("UPDATE binary_data_types SET " + columnName + " = ? WHERE id = 2") - .execute(Tuple.of(input.apply(expected)), ctx.asyncAssertSuccess(updateResult -> { + .execute(Tuple.of(input.apply(expected))) + .onComplete(ctx.asyncAssertSuccess(updateResult -> { pool .preparedQuery("SELECT " + columnName + " FROM binary_data_types WHERE id = 2") - .execute(ctx.asyncAssertSuccess(result -> { + .execute() + .onComplete(ctx.asyncAssertSuccess(result -> { ctx.assertEquals(1, result.size()); Row row = result.iterator().next(); ctx.assertEquals(1, row.size()); @@ -87,7 +89,8 @@ public void testDecodeBlob(TestContext ctx) { private void testDecode(TestContext ctx, String columnName, JDBCType jdbcType, Buffer expected) { pool .preparedQuery("SELECT " + columnName + " FROM binary_data_types WHERE id = 1") - .execute(ctx.asyncAssertSuccess(result -> { + .execute() + .onComplete(ctx.asyncAssertSuccess(result -> { ctx.assertEquals(1, result.size()); Row row = result.iterator().next(); ctx.assertEquals(expected, row.get(Buffer.class, 0)); @@ -102,10 +105,12 @@ private void testDecode(TestContext ctx, String columnName, JDBCType jdbcTyp public void testEncodeNull(TestContext ctx) { pool .preparedQuery("UPDATE binary_data_types SET test_raw = ?, test_blob = ? WHERE id = 2") - .execute(Tuple.tuple().addValue(null).addValue(null), ctx.asyncAssertSuccess(updateResult -> { + .execute(Tuple.tuple().addValue(null).addValue(null)) + .onComplete(ctx.asyncAssertSuccess(updateResult -> { pool .preparedQuery("SELECT * FROM binary_data_types WHERE id = 2") - .execute(ctx.asyncAssertSuccess(result -> { + .execute() + .onComplete(ctx.asyncAssertSuccess(result -> { ctx.assertEquals(1, result.size()); Row row = result.iterator().next(); ctx.assertEquals(3, row.size()); @@ -121,7 +126,8 @@ public void testEncodeNull(TestContext ctx) { public void testDecodeNull(TestContext ctx) { pool .preparedQuery("SELECT test_raw, test_blob FROM binary_data_types WHERE id = 3") - .execute(ctx.asyncAssertSuccess(result -> { + .execute() + .onComplete(ctx.asyncAssertSuccess(result -> { ctx.assertEquals(1, result.size()); Row row = result.iterator().next(); ctx.assertEquals(2, row.size()); diff --git a/vertx-oracle-client/src/test/java/io/vertx/oracleclient/test/OracleBrokenPooledConnectionTest.java b/vertx-oracle-client/src/test/java/io/vertx/oracleclient/test/OracleBrokenPooledConnectionTest.java index 46ca1cbfc..53612fdb8 100644 --- a/vertx-oracle-client/src/test/java/io/vertx/oracleclient/test/OracleBrokenPooledConnectionTest.java +++ b/vertx-oracle-client/src/test/java/io/vertx/oracleclient/test/OracleBrokenPooledConnectionTest.java @@ -38,7 +38,7 @@ public class OracleBrokenPooledConnectionTest extends OracleTestBase { @After public void tearDown(TestContext ctx) throws Exception { if (pool != null) { - pool.close(ctx.asyncAssertSuccess()); + pool.close().onComplete(ctx.asyncAssertSuccess()); } } @@ -52,13 +52,22 @@ public void testBrokenConnectionEvicted(TestContext ctx) { }); pool = OraclePool.pool(vertx, new OracleConnectOptions(options).setPort(8080), new PoolOptions().setMaxSize(1)); proxy.listen(8080, options.getHost(), ctx.asyncAssertSuccess(listen -> { - pool.query("SELECT 1 FROM DUAL").execute(ctx.asyncAssertSuccess(executed -> { + pool + .query("SELECT 1 FROM DUAL") + .execute() + .onComplete(ctx.asyncAssertSuccess(executed -> { ProxyServer.Connection proxyConn1 = proxyConn.get(); ctx.assertNotNull(proxyConn1); Async async = ctx.async(); proxyConn1.clientCloseHandler(onClose1 -> { - pool.query("SELECT 1 FROM DUAL").execute(ctx.asyncAssertFailure(ignored -> { - pool.query("SELECT 1 FROM DUAL").execute(ar -> { + pool + .query("SELECT 1 FROM DUAL") + .execute() + .onComplete(ctx.asyncAssertFailure(ignored -> { + pool + .query("SELECT 1 FROM DUAL") + .execute() + .onComplete(ar -> { if (ar.succeeded()) { async.complete(); } else { diff --git a/vertx-oracle-client/src/test/java/io/vertx/oracleclient/test/OracleColumnDescriptorTest.java b/vertx-oracle-client/src/test/java/io/vertx/oracleclient/test/OracleColumnDescriptorTest.java index 22ef55606..fd03389df 100644 --- a/vertx-oracle-client/src/test/java/io/vertx/oracleclient/test/OracleColumnDescriptorTest.java +++ b/vertx-oracle-client/src/test/java/io/vertx/oracleclient/test/OracleColumnDescriptorTest.java @@ -37,19 +37,23 @@ public void setUp() throws Exception { @Test public void testMetadata(TestContext ctx) { - pool.withConnection(conn -> conn.query("SELECT id, val FROM mutable").execute(), ctx.asyncAssertSuccess(rows -> { - ctx.assertNotNull(rows.columnDescriptors()); - ctx.assertNotNull(rows.columnsNames()); - ctx.assertEquals("ID", rows.columnsNames().get(0)); - ctx.assertEquals("VAL", rows.columnsNames().get(1)); - ctx.assertEquals(2, rows.columnDescriptors().size()); - ctx.assertEquals("NUMBER", rows.columnDescriptors().get(0).typeName()); - ctx.assertEquals("VARCHAR2", rows.columnDescriptors().get(1).typeName()); - })); + pool + .withConnection(conn -> conn + .query("SELECT id, val FROM mutable") + .execute()) + .onComplete(ctx.asyncAssertSuccess(rows -> { + ctx.assertNotNull(rows.columnDescriptors()); + ctx.assertNotNull(rows.columnsNames()); + ctx.assertEquals("ID", rows.columnsNames().get(0)); + ctx.assertEquals("VAL", rows.columnsNames().get(1)); + ctx.assertEquals(2, rows.columnDescriptors().size()); + ctx.assertEquals("NUMBER", rows.columnDescriptors().get(0).typeName()); + ctx.assertEquals("VARCHAR2", rows.columnDescriptors().get(1).typeName()); + })); } @After public void tearDown(TestContext ctx) throws Exception { - pool.close(ctx.asyncAssertSuccess()); + pool.close().onComplete(ctx.asyncAssertSuccess()); } } diff --git a/vertx-oracle-client/src/test/java/io/vertx/oracleclient/test/OracleErrorSimpleTest.java b/vertx-oracle-client/src/test/java/io/vertx/oracleclient/test/OracleErrorSimpleTest.java index d2fbf74d9..2b43becd2 100644 --- a/vertx-oracle-client/src/test/java/io/vertx/oracleclient/test/OracleErrorSimpleTest.java +++ b/vertx-oracle-client/src/test/java/io/vertx/oracleclient/test/OracleErrorSimpleTest.java @@ -40,7 +40,11 @@ public void setUp() throws Exception { @Test public void testMetadata(TestContext ctx) { - pool.withConnection(conn -> conn.query("DROP TABLE u_dont_exist").execute(), ctx.asyncAssertFailure(t -> { + pool + .withConnection(conn -> conn + .query("DROP TABLE u_dont_exist") + .execute()) + .onComplete(ctx.asyncAssertFailure(t -> { if (!(t instanceof OracleException)) { fail(t.getClass().getName()); } @@ -54,6 +58,6 @@ public void testMetadata(TestContext ctx) { @After public void tearDown(TestContext ctx) throws Exception { - pool.close(ctx.asyncAssertSuccess()); + pool.close().onComplete(ctx.asyncAssertSuccess()); } } diff --git a/vertx-oracle-client/src/test/java/io/vertx/oracleclient/test/OracleGeneratedKeysTest.java b/vertx-oracle-client/src/test/java/io/vertx/oracleclient/test/OracleGeneratedKeysTest.java index 79838b426..661b5f91f 100644 --- a/vertx-oracle-client/src/test/java/io/vertx/oracleclient/test/OracleGeneratedKeysTest.java +++ b/vertx-oracle-client/src/test/java/io/vertx/oracleclient/test/OracleGeneratedKeysTest.java @@ -22,6 +22,6 @@ public class OracleGeneratedKeysTest extends OracleGeneratedKeysTestBase { @Override protected void withSqlClient(Function> function, Handler> handler) { - pool.withConnection(function::apply, handler); + pool.withConnection(function::apply).onComplete(handler); } } diff --git a/vertx-oracle-client/src/test/java/io/vertx/oracleclient/test/OracleGeneratedKeysTestBase.java b/vertx-oracle-client/src/test/java/io/vertx/oracleclient/test/OracleGeneratedKeysTestBase.java index 5de0b53a8..b4c360419 100644 --- a/vertx-oracle-client/src/test/java/io/vertx/oracleclient/test/OracleGeneratedKeysTestBase.java +++ b/vertx-oracle-client/src/test/java/io/vertx/oracleclient/test/OracleGeneratedKeysTestBase.java @@ -59,11 +59,15 @@ public abstract class OracleGeneratedKeysTestBase extends OracleTestBase { @Before public void setUp(TestContext ctx) throws Exception { pool = OraclePool.pool(vertx, oracle.options(), new PoolOptions()); - pool.withConnection(conn -> { - return conn.query(DROP).execute() + pool + .withConnection(conn -> { + return conn + .query(DROP) + .execute() .otherwiseEmpty() .compose(v -> conn.query(CREATE).execute()); - }, ctx.asyncAssertSuccess()); + }) + .onComplete(ctx.asyncAssertSuccess()); } @Test @@ -115,6 +119,6 @@ private void verifyGenerated(Row generated, String expectedColumnName, Class @After public void tearDown(TestContext ctx) throws Exception { - pool.close(ctx.asyncAssertSuccess()); + pool.close().onComplete(ctx.asyncAssertSuccess()); } } diff --git a/vertx-oracle-client/src/test/java/io/vertx/oracleclient/test/OraclePoolTest.java b/vertx-oracle-client/src/test/java/io/vertx/oracleclient/test/OraclePoolTest.java index 0875fec76..9698ea807 100644 --- a/vertx-oracle-client/src/test/java/io/vertx/oracleclient/test/OraclePoolTest.java +++ b/vertx-oracle-client/src/test/java/io/vertx/oracleclient/test/OraclePoolTest.java @@ -53,7 +53,9 @@ public void tearDown(TestContext ctx) throws Exception { if (!pools.isEmpty()) { Async async = ctx.async(pools.size()); for (OraclePool pool : pools) { - pool.close(ar -> { + pool + .close() + .onComplete(ar -> { async.countDown(); }); } @@ -79,8 +81,13 @@ public void testPool(TestContext ctx) { Async async = ctx.async(num); OraclePool pool = createPool(options, 40); for (int i = 0; i < num; i++) { - pool.getConnection(ctx.asyncAssertSuccess(conn -> { - conn.query("SELECT id, randomnumber FROM WORLD").execute(ctx.asyncAssertSuccess(rows -> { + pool + .getConnection() + .onComplete(ctx.asyncAssertSuccess(conn -> { + conn + .query("SELECT id, randomnumber FROM WORLD") + .execute() + .onComplete(ctx.asyncAssertSuccess(rows -> { ctx.assertEquals(100, rows.size()); conn.close(); async.countDown(); @@ -95,7 +102,10 @@ public void testQuery(TestContext ctx) { Async async = ctx.async(num); OraclePool pool = createPool(options, 40); for (int i = 0; i < num; i++) { - pool.query("SELECT id, randomnumber FROM WORLD").execute(ctx.asyncAssertSuccess(rows -> { + pool + .query("SELECT id, randomnumber FROM WORLD") + .execute() + .onComplete(ctx.asyncAssertSuccess(rows -> { ctx.assertEquals(100, rows.size()); async.countDown(); })); @@ -109,7 +119,9 @@ public void testQueryWithParams(TestContext ctx) { OraclePool pool = createPool(options, 1); for (int i = 0; i < num; i++) { PreparedQuery> preparedQuery = pool.preparedQuery("SELECT id, randomnumber FROM WORLD WHERE id=?"); - preparedQuery.execute(Tuple.of(i + 1), ctx.asyncAssertSuccess(rows -> { + preparedQuery + .execute(Tuple.of(i + 1)) + .onComplete(ctx.asyncAssertSuccess(rows -> { ctx.assertEquals(1, rows.size()); async.countDown(); })); @@ -122,7 +134,10 @@ public void testUpdate(TestContext ctx) { Async async = ctx.async(num); OraclePool pool = createPool(options, 4); for (int i = 0; i < num; i++) { - pool.query("UPDATE Fortune SET message = 'Whatever' WHERE id = 9").execute(ctx.asyncAssertSuccess(rows -> { + pool + .query("UPDATE Fortune SET message = 'Whatever' WHERE id = 9") + .execute() + .onComplete(ctx.asyncAssertSuccess(rows -> { ctx.assertEquals(1, rows.rowCount()); async.countDown(); })); @@ -135,7 +150,10 @@ public void testUpdateWithParams(TestContext ctx) { Async async = ctx.async(num); OraclePool pool = createPool(options, 4); for (int i = 0; i < num; i++) { - pool.preparedQuery("UPDATE Fortune SET message = 'Whatever' WHERE id = ?").execute(Tuple.of(9), ar -> { + pool + .preparedQuery("UPDATE Fortune SET message = 'Whatever' WHERE id = ?") + .execute(Tuple.of(9)) + .onComplete(ar -> { if (ar.succeeded()) { RowSet result = ar.result(); ctx.assertEquals(1, result.rowCount()); @@ -155,9 +173,13 @@ public void testWithConnection(TestContext ctx) { Function>> failure = conn -> conn.query("SELECT 1 FROM does_not_exist").execute(); for (int i = 0; i < 10; i++) { if (i % 2 == 0) { - pool.withConnection(success, ctx.asyncAssertSuccess(v -> async.countDown())); + pool + .withConnection(success) + .onComplete(ctx.asyncAssertSuccess(v -> async.countDown())); } else { - pool.withConnection(failure, ctx.asyncAssertFailure(v -> async.countDown())); + pool + .withConnection(failure) + .onComplete(ctx.asyncAssertFailure(v -> async.countDown())); } } } @@ -166,7 +188,10 @@ public void testWithConnection(TestContext ctx) { public void testAuthFailure(TestContext ctx) { Async async = ctx.async(); OraclePool pool = createPool(new OracleConnectOptions(options).setPassword("wrong"), 1); - pool.query("SELECT id, randomnumber FROM WORLD").execute(ctx.asyncAssertFailure(v2 -> { + pool + .query("SELECT id, randomnumber FROM WORLD") + .execute() + .onComplete(ctx.asyncAssertFailure(v2 -> { async.complete(); })); } @@ -188,7 +213,10 @@ public void testRunWithExisting(TestContext ctx) { public void testRunStandalone(TestContext ctx) { Async async = ctx.async(); OraclePool pool = createPool(new OracleConnectOptions(options), new PoolOptions()); - pool.query("SELECT id, randomnumber FROM WORLD").execute(ctx.asyncAssertSuccess(v -> { + pool + .query("SELECT id, randomnumber FROM WORLD") + .execute() + .onComplete(ctx.asyncAssertSuccess(v -> { async.complete(); })); async.await(4000); @@ -198,8 +226,12 @@ public void testRunStandalone(TestContext ctx) { public void testMaxWaitQueueSize(TestContext ctx) { Async async = ctx.async(); OraclePool pool = createPool(options, new PoolOptions().setMaxSize(1).setMaxWaitQueueSize(0)); - pool.getConnection(ctx.asyncAssertSuccess(v -> { - pool.getConnection(ctx.asyncAssertFailure(err -> { + pool + .getConnection() + .onComplete(ctx.asyncAssertSuccess(v -> { + pool + .getConnection() + .onComplete(ctx.asyncAssertFailure(err -> { async.complete(); })); })); @@ -214,7 +246,10 @@ public void testConcurrentMultipleConnection(TestContext ctx) { int numRequests = 2; Async async = ctx.async(numRequests); for (int i = 0; i < numRequests; i++) { - pool.preparedQuery("SELECT * FROM Fortune WHERE id=?").execute(Tuple.of(1), ctx.asyncAssertSuccess(results -> { + pool + .preparedQuery("SELECT * FROM Fortune WHERE id=?") + .execute(Tuple.of(1)) + .onComplete(ctx.asyncAssertSuccess(results -> { ctx.assertEquals(1, results.size()); Tuple row = results.iterator().next(); ctx.assertEquals(1, row.getInteger(0)); @@ -234,10 +269,15 @@ public void testConnectionHook(TestContext ctx) { }); }; OraclePool pool = createPool(options, new PoolOptions().setMaxSize(1)).connectHandler(hook); - pool.getConnection(ctx.asyncAssertSuccess(conn -> { + pool + .getConnection() + .onComplete(ctx.asyncAssertSuccess(conn -> { ctx.assertEquals(1, hookCount.get()); - conn.query("SELECT id, randomnumber FROM WORLD").execute(ctx.asyncAssertSuccess(v2 -> { - conn.close(ctx.asyncAssertSuccess()); + conn + .query("SELECT id, randomnumber FROM WORLD") + .execute() + .onComplete(ctx.asyncAssertSuccess(v2 -> { + conn.close().onComplete(ctx.asyncAssertSuccess()); })); })); } @@ -248,11 +288,17 @@ public void testDirectQueryFromDuplicatedContext(TestContext ctx) { Async async = ctx.async(); vertx.runOnContext(v1 -> { ContextInternal current = (ContextInternal) Vertx.currentContext(); - pool.query("SELECT 1 FROM DUAL").execute(ctx.asyncAssertSuccess(res1 -> { + pool + .query("SELECT 1 FROM DUAL") + .execute() + .onComplete(ctx.asyncAssertSuccess(res1 -> { ctx.assertTrue(Vertx.currentContext() == current); ContextInternal duplicated = current.duplicate(); duplicated.runOnContext(v2 -> { - pool.query("SELECT 1 FROM DUAL").execute(ctx.asyncAssertSuccess(res2 -> { + pool + .query("SELECT 1 FROM DUAL") + .execute() + .onComplete(ctx.asyncAssertSuccess(res2 -> { ctx.assertTrue(Vertx.currentContext() == duplicated); async.complete(); })); @@ -267,15 +313,23 @@ public void testQueryFromDuplicatedContext(TestContext ctx) { Async async = ctx.async(); vertx.runOnContext(v1 -> { ContextInternal current = (ContextInternal) Vertx.currentContext(); - pool.query("SELECT 1 FROM DUAL").execute(ctx.asyncAssertSuccess(res1 -> { + pool + .query("SELECT 1 FROM DUAL") + .execute() + .onComplete(ctx.asyncAssertSuccess(res1 -> { ctx.assertTrue(Vertx.currentContext() == current); ContextInternal duplicated = current.duplicate(); duplicated.runOnContext(v2 -> { - pool.getConnection(ctx.asyncAssertSuccess(conn -> { + pool + .getConnection() + .onComplete(ctx.asyncAssertSuccess(conn -> { ctx.assertTrue(Vertx.currentContext() == duplicated); - conn.query("SELECT 1 FROM DUAL").execute(ctx.asyncAssertSuccess(res2 -> { + conn + .query("SELECT 1 FROM DUAL") + .execute() + .onComplete(ctx.asyncAssertSuccess(res2 -> { ctx.assertTrue(Vertx.currentContext() == duplicated); - conn.close(ctx.asyncAssertSuccess(v -> { + conn.close().onComplete(ctx.asyncAssertSuccess(v -> { ctx.assertTrue(Vertx.currentContext() == duplicated); async.complete(); })); diff --git a/vertx-oracle-client/src/test/java/io/vertx/oracleclient/test/OracleQueriesTest.java b/vertx-oracle-client/src/test/java/io/vertx/oracleclient/test/OracleQueriesTest.java index 93bb865b3..15458d233 100644 --- a/vertx-oracle-client/src/test/java/io/vertx/oracleclient/test/OracleQueriesTest.java +++ b/vertx-oracle-client/src/test/java/io/vertx/oracleclient/test/OracleQueriesTest.java @@ -48,7 +48,10 @@ public void setUp() throws Exception { @Test public void testCurrentTimestampType(TestContext ctx) { - pool.query("SELECT CURRENT_TIMESTAMP FROM dual").execute(ctx.asyncAssertSuccess(rows -> { + pool + .query("SELECT CURRENT_TIMESTAMP FROM dual") + .execute() + .onComplete(ctx.asyncAssertSuccess(rows -> { ctx.verify(v -> { assertEquals(1, rows.size()); Object value = rows.iterator().next().getValue(0); @@ -71,6 +74,6 @@ public void testInsertSelectQuery(TestContext ctx) { @After public void tearDown(TestContext ctx) throws Exception { - pool.close(ctx.asyncAssertSuccess()); + pool.close().onComplete(ctx.asyncAssertSuccess()); } } diff --git a/vertx-oracle-client/src/test/java/io/vertx/oracleclient/test/tck/ClientConfig.java b/vertx-oracle-client/src/test/java/io/vertx/oracleclient/test/tck/ClientConfig.java index f212cc504..802be67be 100644 --- a/vertx-oracle-client/src/test/java/io/vertx/oracleclient/test/tck/ClientConfig.java +++ b/vertx-oracle-client/src/test/java/io/vertx/oracleclient/test/tck/ClientConfig.java @@ -32,7 +32,7 @@ Connector connect(Vertx vertx, SqlConnectOptions options) { @Override public void connect(Handler> handler) { - OracleConnection.connect(vertx, new OracleConnectOptions(options), ar -> { + OracleConnection.connect(vertx, new OracleConnectOptions(options)).onComplete(ar -> { if (ar.succeeded()) { handler.handle(Future.succeededFuture(ar.result())); } else { @@ -56,7 +56,7 @@ Connector connect(Vertx vertx, SqlConnectOptions options) { return new Connector<>() { @Override public void connect(Handler> handler) { - pool.getConnection(ar -> { + pool.getConnection().onComplete(ar -> { if (ar.succeeded()) { handler.handle(Future.succeededFuture(ar.result())); } else { diff --git a/vertx-oracle-client/src/test/java/io/vertx/oracleclient/test/tck/OracleBinaryDataTypeEncodeTest.java b/vertx-oracle-client/src/test/java/io/vertx/oracleclient/test/tck/OracleBinaryDataTypeEncodeTest.java index adf91755d..c503d594c 100644 --- a/vertx-oracle-client/src/test/java/io/vertx/oracleclient/test/tck/OracleBinaryDataTypeEncodeTest.java +++ b/vertx-oracle-client/src/test/java/io/vertx/oracleclient/test/tck/OracleBinaryDataTypeEncodeTest.java @@ -136,10 +136,12 @@ protected void testEncodeGeneric(TestContext ctx, connector.connect(ctx.asyncAssertSuccess(conn -> { conn .preparedQuery(statement("UPDATE basicdatatype SET " + columnName + " = ", " WHERE id = 2")) - .execute(Tuple.tuple().addValue(expected), ctx.asyncAssertSuccess(updateResult -> { + .execute(Tuple.tuple().addValue(expected)) + .onComplete(ctx.asyncAssertSuccess(updateResult -> { conn .preparedQuery("SELECT " + columnName + " FROM basicdatatype WHERE id = 2") - .execute(ctx.asyncAssertSuccess(result -> { + .execute() + .onComplete(ctx.asyncAssertSuccess(result -> { ctx.assertEquals(1, result.size()); Row row = result.iterator().next(); ctx.assertEquals(1, row.size()); diff --git a/vertx-oracle-client/src/test/java/io/vertx/oracleclient/test/tck/OracleCollectorTest.java b/vertx-oracle-client/src/test/java/io/vertx/oracleclient/test/tck/OracleCollectorTest.java index 3ba7a9657..fedbd915b 100644 --- a/vertx-oracle-client/src/test/java/io/vertx/oracleclient/test/tck/OracleCollectorTest.java +++ b/vertx-oracle-client/src/test/java/io/vertx/oracleclient/test/tck/OracleCollectorTest.java @@ -50,8 +50,11 @@ public void testSimpleQuery(TestContext ctx) { TestingCollectorObject expected = new TestingCollectorObject(1, (short) 32767, 2147483647, 9223372036854775807L, 123.456F, 1.234567D, "HELLO,WORLD"); this.connector.connect(ctx.asyncAssertSuccess((conn) -> { - conn.query("SELECT * FROM test_collector WHERE id = 1").collecting(collector) - .execute(ctx.asyncAssertSuccess((result) -> { + conn + .query("SELECT * FROM test_collector WHERE id = 1") + .collecting(collector) + .execute() + .onComplete(ctx.asyncAssertSuccess((result) -> { Map map = result.value(); TestingCollectorObject actual = map.get(1); ctx.assertEquals(expected, actual); @@ -79,9 +82,11 @@ public void testPreparedQuery(TestContext ctx) { 123.456f, 1.234567d, "HELLO,WORLD"); connector.connect(ctx.asyncAssertSuccess(conn -> { - conn.preparedQuery("SELECT * FROM test_collector WHERE id = 1") + conn + .preparedQuery("SELECT * FROM test_collector WHERE id = 1") .collecting(collector) - .execute(ctx.asyncAssertSuccess(result -> { + .execute() + .onComplete(ctx.asyncAssertSuccess(result -> { Map map = result.value(); TestingCollectorObject actual = map.get(1); ctx.assertEquals(expected, actual); @@ -166,9 +171,11 @@ public Function finisher() { private void testCollectorFailure(Async async, TestContext ctx, Throwable cause, Collector collector) { connector.connect(ctx.asyncAssertSuccess(conn -> { - conn.query("SELECT * FROM test_collector WHERE id = 1") + conn + .query("SELECT * FROM test_collector WHERE id = 1") .collecting(collector) - .execute(ctx.asyncAssertFailure(result -> { + .execute() + .onComplete(ctx.asyncAssertFailure(result -> { ctx.assertEquals(cause, result); conn.close(); async.complete(); diff --git a/vertx-oracle-client/src/test/java/io/vertx/oracleclient/test/tck/OraclePreparedBatchTest.java b/vertx-oracle-client/src/test/java/io/vertx/oracleclient/test/tck/OraclePreparedBatchTest.java index a0cb1f82f..854f29fcb 100644 --- a/vertx-oracle-client/src/test/java/io/vertx/oracleclient/test/tck/OraclePreparedBatchTest.java +++ b/vertx-oracle-client/src/test/java/io/vertx/oracleclient/test/tck/OraclePreparedBatchTest.java @@ -46,7 +46,10 @@ protected String statement(String... parts) { @Override public void cleanTestTable(TestContext ctx) { connect(ctx.asyncAssertSuccess(conn -> { - conn.preparedQuery("TRUNCATE TABLE mutable").execute(result -> { + conn + .preparedQuery("TRUNCATE TABLE mutable") + .execute() + .onComplete(result -> { conn.close(); }); })); @@ -68,18 +71,26 @@ public void testInsert(TestContext ctx) { fut.onComplete(result -> { ctx.assertFalse(result.failed()); ctx.assertEquals(4, result.result().rowCount()); - conn.preparedQuery("SELECT * FROM mutable WHERE id=?") - .execute(Tuple.of(79991), ctx.asyncAssertSuccess(rows1 -> { + conn + .preparedQuery("SELECT * FROM mutable WHERE id=?") + .execute(Tuple.of(79991)) + .onComplete(ctx.asyncAssertSuccess(rows1 -> { verify(rows1, ctx, 79991, "batch one"); - conn.preparedQuery("SELECT * FROM mutable WHERE id=?") - .execute(Tuple.of(79992), ctx.asyncAssertSuccess((ar2) -> { + conn + .preparedQuery("SELECT * FROM mutable WHERE id=?") + .execute(Tuple.of(79992)) + .onComplete(ctx.asyncAssertSuccess((ar2) -> { verify(ar2, ctx, 79992, "batch two"); - conn.preparedQuery(this.statement("SELECT * FROM mutable WHERE id=", "")) - .execute(Tuple.of(79993), ctx.asyncAssertSuccess((ar3) -> { + conn + .preparedQuery(this.statement("SELECT * FROM mutable WHERE id=", "")) + .execute(Tuple.of(79993)) + .onComplete(ctx.asyncAssertSuccess((ar3) -> { verify(ar3, ctx, 79993, "batch three"); - conn.preparedQuery( + conn + .preparedQuery( this.statement("SELECT * FROM mutable WHERE id=", "")) - .execute(Tuple.of(79994), ctx.asyncAssertSuccess((ar4) -> { + .execute(Tuple.of(79994)) + .onComplete(ctx.asyncAssertSuccess((ar4) -> { verify(ar4, ctx, 79994, "batch four"); async.complete(); })); @@ -108,8 +119,10 @@ public void testEmptyBatch(TestContext ctx) { Async async = ctx.async(); connector.connect(ctx.asyncAssertSuccess(conn -> { List batch = new ArrayList<>(); - conn.preparedQuery(statement("SELECT * FROM immutable WHERE id=", "")) - .executeBatch(batch, ctx.asyncAssertFailure(err -> { + conn + .preparedQuery(statement("SELECT * FROM immutable WHERE id=", "")) + .executeBatch(batch) + .onComplete(ctx.asyncAssertFailure(err -> { async.complete(); })); })); @@ -121,8 +134,10 @@ public void testIncorrectNumBatchArguments(TestContext ctx) { connector.connect(ctx.asyncAssertSuccess(conn -> { List batch = new ArrayList<>(); batch.add(Tuple.of(1, 2)); - conn.preparedQuery(statement("SELECT * FROM immutable WHERE id=", "")) - .executeBatch(batch, ctx.asyncAssertFailure(err -> { + conn + .preparedQuery(statement("SELECT * FROM immutable WHERE id=", "")) + .executeBatch(batch) + .onComplete(ctx.asyncAssertFailure(err -> { async.complete(); })); })); diff --git a/vertx-oracle-client/src/test/java/io/vertx/oracleclient/test/tck/OracleTransactionTest.java b/vertx-oracle-client/src/test/java/io/vertx/oracleclient/test/tck/OracleTransactionTest.java index 9200b70b8..eb3cdfdd1 100644 --- a/vertx-oracle-client/src/test/java/io/vertx/oracleclient/test/tck/OracleTransactionTest.java +++ b/vertx-oracle-client/src/test/java/io/vertx/oracleclient/test/tck/OracleTransactionTest.java @@ -60,9 +60,9 @@ public void testTransactionDoNotLeaveOpenCursors(TestContext ctx) { int count = 5000; Async async = ctx.async(count); for (int i = 0; i < count; i++) { - pool.withTransaction(conn -> { - return conn.query("SELECT 1 FROM DUAL").execute(); - }, ctx.asyncAssertSuccess(v -> async.countDown())); + pool + .withTransaction(conn -> conn.query("SELECT 1 FROM DUAL").execute()) + .onComplete(ctx.asyncAssertSuccess(v -> async.countDown())); } } } diff --git a/vertx-pg-client/src/test/java/io/vertx/pgclient/CloseConnectionTest.java b/vertx-pg-client/src/test/java/io/vertx/pgclient/CloseConnectionTest.java index cffb12771..20e5eb765 100644 --- a/vertx-pg-client/src/test/java/io/vertx/pgclient/CloseConnectionTest.java +++ b/vertx-pg-client/src/test/java/io/vertx/pgclient/CloseConnectionTest.java @@ -26,14 +26,14 @@ public void setup() throws Exception { @After public void tearDown(TestContext ctx) { - vertx.close(ctx.asyncAssertSuccess()); + vertx.close().onComplete(ctx.asyncAssertSuccess()); } @Test public void testCloseConnection(TestContext ctx) { testCloseConnection(ctx, () -> { PgConnection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> { - conn.close(ctx.asyncAssertSuccess()); + conn.close().onComplete(ctx.asyncAssertSuccess()); })); }); } @@ -43,8 +43,8 @@ public void testClosePooledConnection(TestContext ctx) { testCloseConnection(ctx, () -> { PgPool pool = PgPool.pool(vertx, options, new PoolOptions().setMaxSize(1)); pool.getConnection().onComplete(ctx.asyncAssertSuccess(conn -> { - conn.close(ctx.asyncAssertSuccess(v -> { - pool.close(ctx.asyncAssertSuccess()); + conn.close().onComplete(ctx.asyncAssertSuccess(v -> { + pool.close().onComplete(ctx.asyncAssertSuccess()); })); })); }); @@ -57,7 +57,7 @@ public void testCloseNetSocket(TestContext ctx) { ConnectionFactory factory = PgDriver.INSTANCE.createConnectionFactory(vertx, options); pool.connectionProvider(factory::connect); pool.getConnection().onComplete(ctx.asyncAssertSuccess(conn -> { - conn.close(ctx.asyncAssertSuccess(v -> { + conn.close().onComplete(ctx.asyncAssertSuccess(v -> { factory.close(Promise.promise()); })); })); diff --git a/vertx-pg-client/src/test/java/io/vertx/pgclient/NoticeTest.java b/vertx-pg-client/src/test/java/io/vertx/pgclient/NoticeTest.java index 17a3e0c2f..f9300a046 100644 --- a/vertx-pg-client/src/test/java/io/vertx/pgclient/NoticeTest.java +++ b/vertx-pg-client/src/test/java/io/vertx/pgclient/NoticeTest.java @@ -45,18 +45,19 @@ public void setup() throws Exception { @After public void teardown(TestContext ctx) { - vertx.close(ctx.asyncAssertSuccess()); + vertx.close().onComplete(ctx.asyncAssertSuccess()); } @Test public void testHandleNotice(TestContext ctx) { Async async = ctx.async(); - PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { + PgConnection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> { List notices = new ArrayList<>(); conn.noticeHandler(notices::add); conn .query("SELECT raise_message('the message')") - .execute(ctx.asyncAssertSuccess(result1 -> { + .execute() + .onComplete(ctx.asyncAssertSuccess(result1 -> { ctx.assertEquals(1, notices.size()); PgNotice notice = notices.get(0); ctx.assertEquals("the message", notice.getMessage()); diff --git a/vertx-pg-client/src/test/java/io/vertx/pgclient/PgClientTestBase.java b/vertx-pg-client/src/test/java/io/vertx/pgclient/PgClientTestBase.java index c15d5f211..90160aa82 100644 --- a/vertx-pg-client/src/test/java/io/vertx/pgclient/PgClientTestBase.java +++ b/vertx-pg-client/src/test/java/io/vertx/pgclient/PgClientTestBase.java @@ -58,7 +58,7 @@ public void setup() throws Exception { @After public void tearDown(TestContext ctx) { - vertx.close(ctx.asyncAssertSuccess()); + vertx.close().onComplete(ctx.asyncAssertSuccess()); } @Test @@ -75,8 +75,10 @@ public void testConnectNonSSLServer(TestContext ctx) { public void testMultipleQuery(TestContext ctx) { Async async = ctx.async(); connector.accept(ctx.asyncAssertSuccess(conn -> { - conn.query("SELECT id, message from FORTUNE LIMIT 1;SELECT message, id from FORTUNE LIMIT 1") - .execute(ctx.asyncAssertSuccess(result1 -> { + conn + .query("SELECT id, message from FORTUNE LIMIT 1;SELECT message, id from FORTUNE LIMIT 1") + .execute() + .onComplete(ctx.asyncAssertSuccess(result1 -> { ctx.assertEquals(1, result1.size()); ctx.assertEquals(Arrays.asList("id", "message"), result1.columnsNames()); Tuple row1 = result1.iterator().next(); @@ -102,7 +104,8 @@ public void testInsertReturning(TestContext ctx) { deleteFromTestTable(ctx, client, () -> { client .preparedQuery("INSERT INTO Test (id, val) VALUES ($1, $2) RETURNING id") - .execute(Tuple.of(14, "SomeMessage"), ctx.asyncAssertSuccess(result -> { + .execute(Tuple.of(14, "SomeMessage")) + .onComplete(ctx.asyncAssertSuccess(result -> { ctx.assertEquals(14, result.iterator().next().getInteger("id")); async.complete(); })); @@ -120,7 +123,8 @@ public void testInsertReturningBatch(TestContext ctx) { Tuple.of(15, "SomeMessage2")); client .preparedQuery("INSERT INTO Test (id, val) VALUES ($1, $2) RETURNING id") - .executeBatch(batch, ctx.asyncAssertSuccess(r1 -> { + .executeBatch(batch) + .onComplete(ctx.asyncAssertSuccess(r1 -> { ctx.assertEquals(14, r1.iterator().next().getInteger("id")); RowSet r2 = r1.next(); ctx.assertEquals(15, r2.iterator().next().getInteger("id")); @@ -136,11 +140,13 @@ public void testInsertReturningError(TestContext ctx) { connector.accept(ctx.asyncAssertSuccess(client -> { deleteFromTestTable(ctx, client, () -> { client.preparedQuery("INSERT INTO Test (id, val) VALUES ($1, $2) RETURNING id") - .execute(Tuple.of(15, "SomeMessage"), ctx.asyncAssertSuccess(result -> { + .execute(Tuple.of(15, "SomeMessage")) + .onComplete(ctx.asyncAssertSuccess(result -> { ctx.assertEquals(15, result.iterator().next().getInteger("id")); client .preparedQuery("INSERT INTO Test (id, val) VALUES ($1, $2) RETURNING id") - .execute(Tuple.of(15, "SomeMessage"), ctx.asyncAssertFailure(err -> { + .execute(Tuple.of(15, "SomeMessage")) + .onComplete(ctx.asyncAssertFailure(err -> { ctx.assertEquals("23505", ((PgException) err).getSqlState()); async.complete(); })); @@ -184,7 +190,8 @@ public void testBatchSelect(TestContext ctx) { batch.add(Tuple.tuple()); conn .preparedQuery("SELECT count(id) FROM World") - .executeBatch(batch, ctx.asyncAssertSuccess(result -> { + .executeBatch(batch) + .onComplete(ctx.asyncAssertSuccess(result -> { ctx.assertEquals(result.size(), result.next().size()); async.complete(); })); @@ -214,12 +221,14 @@ public void testTx(TestContext ctx) { connector.accept(ctx.asyncAssertSuccess(conn -> { conn .query("BEGIN") - .execute(ctx.asyncAssertSuccess(result1 -> { + .execute() + .onComplete(ctx.asyncAssertSuccess(result1 -> { ctx.assertEquals(0, result1.size()); ctx.assertNotNull(result1.iterator()); conn .query("COMMIT") - .execute(ctx.asyncAssertSuccess(result2 -> { + .execute() + .onComplete(ctx.asyncAssertSuccess(result2 -> { ctx.assertEquals(0, result2.size()); async.complete(); })); @@ -231,12 +240,18 @@ public void testTx(TestContext ctx) { public void testGrouping(TestContext ctx) { connector.accept(ctx.asyncAssertSuccess(conn -> { ((SqlClientInternal)conn).group(client -> { - client.query("SHOW TIME ZONE").execute(ctx.asyncAssertSuccess(res -> { + client + .query("SHOW TIME ZONE") + .execute() + .onComplete(ctx.asyncAssertSuccess(res -> { ctx.assertEquals(1, res.size()); Row row = res.iterator().next(); ctx.assertEquals("PST8PDT", row.getString(0)); })); - conn.query("SET TIME ZONE 'PST8PDT'").execute(ctx.asyncAssertSuccess()); + conn + .query("SET TIME ZONE 'PST8PDT'") + .execute() + .onComplete(ctx.asyncAssertSuccess()); }); })); } diff --git a/vertx-pg-client/src/test/java/io/vertx/pgclient/PgConnectionTest.java b/vertx-pg-client/src/test/java/io/vertx/pgclient/PgConnectionTest.java index 9de1c5618..5eefe5426 100644 --- a/vertx-pg-client/src/test/java/io/vertx/pgclient/PgConnectionTest.java +++ b/vertx-pg-client/src/test/java/io/vertx/pgclient/PgConnectionTest.java @@ -19,10 +19,7 @@ import io.vertx.ext.unit.Async; import io.vertx.ext.unit.TestContext; -import io.vertx.sqlclient.ClosedConnectionException; -import io.vertx.sqlclient.Row; -import io.vertx.sqlclient.SqlResult; -import io.vertx.sqlclient.Tuple; +import io.vertx.sqlclient.*; import org.junit.Test; import java.util.ArrayList; @@ -34,7 +31,7 @@ public class PgConnectionTest extends PgConnectionTestBase { public PgConnectionTest() { - connector = (handler) -> PgConnection.connect(vertx, options, ar -> { + connector = (handler) -> PgConnection.connect(vertx, options).onComplete(ar -> { handler.handle(ar.map(p -> p)); }); } @@ -43,7 +40,10 @@ public PgConnectionTest() { public void testSettingSchema(TestContext ctx) { options.addProperty("search_path", "myschema"); connector.accept(ctx.asyncAssertSuccess(conn -> { - conn.query("SHOW search_path;").execute(ctx.asyncAssertSuccess(pgRowSet -> { + conn + .query("SHOW search_path;") + .execute() + .onComplete(ctx.asyncAssertSuccess(pgRowSet -> { ctx.assertEquals("myschema", pgRowSet.iterator().next().getString("search_path")); })); })); @@ -55,17 +55,20 @@ public void testBatchUpdate(TestContext ctx) { connector.accept(ctx.asyncAssertSuccess(conn -> { deleteFromTestTable(ctx, conn, () -> { insertIntoTestTable(ctx, conn, 10, () -> { - conn.prepare("UPDATE Test SET val=$1 WHERE id=$2", ctx.asyncAssertSuccess(ps -> { + conn.prepare("UPDATE Test SET val=$1 WHERE id=$2").onComplete(ctx.asyncAssertSuccess(ps -> { List batch = new ArrayList<>(); batch.add(Tuple.of("val0", 0)); batch.add(Tuple.of("val1", 1)); - ps.query().executeBatch(batch, ctx.asyncAssertSuccess(result -> { + ps + .query() + .executeBatch(batch) + .onComplete(ctx.asyncAssertSuccess(result -> { for (int i = 0;i < 2;i++) { ctx.assertEquals(1, result.rowCount()); result = result.next(); } ctx.assertNull(result); - ps.close(ctx.asyncAssertSuccess(v -> { + ps.close().onComplete(ctx.asyncAssertSuccess(v -> { async.complete(); })); })); @@ -83,9 +86,10 @@ public void testQueueQueries(TestContext ctx) { for (int i = 0;i < num;i++) { conn .query("SELECT id, randomnumber from WORLD") - .execute(ar -> { + .execute() + .onComplete(ar -> { if (ar.succeeded()) { - SqlResult result = ar.result(); + RowSet result = ar.result(); ctx.assertEquals(10000, result.size()); } else { ctx.assertEquals("closed", ar.cause().getMessage()); @@ -107,11 +111,14 @@ public void testCancelRequest(TestContext ctx) { connector.accept(ctx.asyncAssertSuccess(conn -> { conn .query("SELECT pg_sleep(10)") - .execute(ctx.asyncAssertFailure(error -> { + .execute() + .onComplete(ctx.asyncAssertFailure(error -> { ctx.assertTrue(hasSqlstateCode(error, ERRCODE_QUERY_CANCELED), error.getMessage()); async.countDown(); })); - ((PgConnection)conn).cancelRequest(ctx.asyncAssertSuccess()); + ((PgConnection)conn) + .cancelRequest() + .onComplete(ctx.asyncAssertSuccess()); conn.closeHandler(v -> { ctx.assertEquals(1, async.count()); @@ -124,15 +131,24 @@ public void testCancelRequest(TestContext ctx) { @Test public void testInflightCommandsFailWhenConnectionClosed(TestContext ctx) { connector.accept(ctx.asyncAssertSuccess(conn1 -> { - conn1.query("SELECT pg_sleep(20)").execute(ctx.asyncAssertFailure(t -> { + conn1 + .query("SELECT pg_sleep(20)") + .execute() + .onComplete(ctx.asyncAssertFailure(t -> { ctx.assertTrue(t instanceof ClosedConnectionException); })); connector.accept(ctx.asyncAssertSuccess(conn2 -> { - conn2.query("SELECT * FROM pg_stat_activity WHERE state = 'active' AND query = 'SELECT pg_sleep(20)'").execute(ctx.asyncAssertSuccess(statRes -> { + conn2 + .query("SELECT * FROM pg_stat_activity WHERE state = 'active' AND query = 'SELECT pg_sleep(20)'") + .execute() + .onComplete(ctx.asyncAssertSuccess(statRes -> { for (Row row : statRes) { Integer id = row.getInteger("pid"); // kill the connection - conn2.query(String.format("SELECT pg_terminate_backend(%d);", id)).execute(ctx.asyncAssertSuccess(v -> conn2.close())); + conn2 + .query(String.format("SELECT pg_terminate_backend(%d);", id)) + .execute() + .onComplete(ctx.asyncAssertSuccess(v -> conn2.close())); break; } })); diff --git a/vertx-pg-client/src/test/java/io/vertx/pgclient/PgConnectionTestBase.java b/vertx-pg-client/src/test/java/io/vertx/pgclient/PgConnectionTestBase.java index 510285ee8..f34d65a43 100644 --- a/vertx-pg-client/src/test/java/io/vertx/pgclient/PgConnectionTestBase.java +++ b/vertx-pg-client/src/test/java/io/vertx/pgclient/PgConnectionTestBase.java @@ -104,12 +104,14 @@ public void testTx(TestContext ctx) { connector.accept(ctx.asyncAssertSuccess(conn -> { conn .query("BEGIN") - .execute(ctx.asyncAssertSuccess(result1 -> { + .execute() + .onComplete(ctx.asyncAssertSuccess(result1 -> { ctx.assertEquals(0, result1.size()); ctx.assertNotNull(result1.iterator()); conn .query("COMMIT") - .execute(ctx.asyncAssertSuccess(result2 -> { + .execute() + .onComplete(ctx.asyncAssertSuccess(result2 -> { ctx.assertEquals(0, result2.size()); async.complete(); })); @@ -278,11 +280,13 @@ public void testUpdateError(TestContext ctx) { connector.accept(ctx.asyncAssertSuccess(conn -> { conn .query("INSERT INTO Fortune (id, message) VALUES (1, 'Duplicate')") - .execute(ctx.asyncAssertFailure(err -> { + .execute() + .onComplete(ctx.asyncAssertFailure(err -> { ctx.assertEquals("23505", ((PgException) err).getSqlState()); conn .query("SELECT 1000") - .execute(ctx.asyncAssertSuccess(result -> { + .execute() + .onComplete(ctx.asyncAssertSuccess(result -> { ctx.assertEquals(1, result.size()); ctx.assertEquals(1000, result.iterator().next().getInteger(0)); async.complete(); @@ -300,11 +304,13 @@ public void testBatchInsertError(TestContext ctx) throws Exception { batch.add(Tuple.of(id, 3)); conn .preparedQuery("INSERT INTO World (id, randomnumber) VALUES ($1, $2)") - .executeBatch(batch, ctx.asyncAssertFailure(err -> { + .executeBatch(batch) + .onComplete(ctx.asyncAssertFailure(err -> { ctx.assertEquals("23505", ((PgException) err).getSqlState()); conn .preparedQuery("SELECT 1000") - .execute(ctx.asyncAssertSuccess(result -> { + .execute() + .onComplete(ctx.asyncAssertSuccess(result -> { ctx.assertEquals(1, result.size()); ctx.assertEquals(1000, result.iterator().next().getInteger(0)); async.complete(); @@ -326,7 +332,7 @@ public void start(Promise startPromise) throws Exception { startPromise.complete(); })); } - }, ctx.asyncAssertSuccess(id -> { + }).onComplete(ctx.asyncAssertSuccess(id -> { vertx.undeploy(id); })); } @@ -354,20 +360,24 @@ private void testTransactionCommit(TestContext ctx, Executor exec) { })); conn .query("INSERT INTO Test (id, val) VALUES (1, 'val-1')") - .execute(ctx.asyncAssertSuccess(res1 -> { + .execute() + .onComplete(ctx.asyncAssertSuccess(res1 -> { u1.addAndGet(res1.rowCount()); exec.execute(() -> { conn .query("INSERT INTO Test (id, val) VALUES (2, 'val-2')") - .execute(ctx.asyncAssertSuccess(res2 -> { + .execute() + .onComplete(ctx.asyncAssertSuccess(res2 -> { u2.addAndGet(res2.rowCount()); exec.execute(() -> { - tx.commit(ctx.asyncAssertSuccess(v -> { + tx.commit() + .onComplete(ctx.asyncAssertSuccess(v -> { ctx.assertEquals(1, u1.get()); ctx.assertEquals(1, u2.get()); conn .query("SELECT id FROM Test WHERE id=1 OR id=2") - .execute(ctx.asyncAssertSuccess(result -> { + .execute() + .onComplete(ctx.asyncAssertSuccess(result -> { ctx.assertEquals(2, result.size()); done.complete(); })); @@ -405,22 +415,26 @@ private void testTransactionRollback(TestContext ctx, Executor exec) { })); conn .query("INSERT INTO Test (id, val) VALUES (1, 'val-1')") - .execute(ctx.asyncAssertSuccess(res1 -> { + .execute() + .onComplete(ctx.asyncAssertSuccess(res1 -> { u1.addAndGet(res1.rowCount()); exec.execute(() -> { }); conn .query("INSERT INTO Test (id, val) VALUES (2, 'val-2')") - .execute(ctx.asyncAssertSuccess(res2 -> { + .execute() + .onComplete(ctx.asyncAssertSuccess(res2 -> { u2.addAndGet(res2.rowCount()); exec.execute(() -> { - tx.rollback(ctx.asyncAssertSuccess(v -> { + tx.rollback() + .onComplete(ctx.asyncAssertSuccess(v -> { ctx.assertEquals(1, u1.get()); ctx.assertEquals(1, u2.get()); conn .query("SELECT id FROM Test WHERE id=1 OR id=2") - .execute(ctx.asyncAssertSuccess(result -> { + .execute() + .onComplete(ctx.asyncAssertSuccess(result -> { ctx.assertEquals(0, result.size()); done.complete(); })); @@ -446,21 +460,31 @@ public void testTransactionAbort(TestContext ctx) { })); AtomicReference>> queryAfterFailed = new AtomicReference<>(); AtomicReference> commit = new AtomicReference<>(); - conn.query("INSERT INTO Test (id, val) VALUES (1, 'val-1')").execute(ar1 -> { }); - conn.query("INSERT INTO Test (id, val) VALUES (1, 'val-2')").execute(ar2 -> { + conn.query("INSERT INTO Test (id, val) VALUES (1, 'val-1')").execute(); + conn + .query("INSERT INTO Test (id, val) VALUES (1, 'val-2')") + .execute() + .onComplete(ar2 -> { ctx.assertNull(queryAfterFailed.get()); ctx.assertNull(commit.get()); ctx.assertTrue(ar2.failed()); }); - conn.query("SELECT id FROM Test").execute(abc -> { + conn + .query("SELECT id FROM Test") + .execute() + .onComplete(abc -> { queryAfterFailed.set(abc); // This query won't be made in the same TX - conn.query("SELECT id FROM Test WHERE id=1").execute(ctx.asyncAssertSuccess(result -> { + conn + .query("SELECT id FROM Test WHERE id=1") + .execute() + .onComplete(ctx.asyncAssertSuccess(result -> { ctx.assertEquals(0, result.size()); done.countDown(); })); }); - tx.commit(ar -> { + tx.commit() + .onComplete(ar -> { commit.set(ar); }); })); @@ -472,11 +496,15 @@ public void testTransactionAbort(TestContext ctx) { public void testCloseConnectionFromDifferentContext(TestContext ctx) { Async done = ctx.async(1); connector.accept(ctx.asyncAssertSuccess(conn -> { - conn.query("SELECT 1").execute(ctx.asyncAssertSuccess(res -> { + conn + .query("SELECT 1") + .execute() + .onComplete(ctx.asyncAssertSuccess(res -> { ctx.assertEquals(1, res.size()); // schedule from another context new Thread(() -> { - conn.close(v2 -> { + conn.close() + .onComplete(v2 -> { done.complete(); }); }).start(); diff --git a/vertx-pg-client/src/test/java/io/vertx/pgclient/PgDatabaseMetadataTest.java b/vertx-pg-client/src/test/java/io/vertx/pgclient/PgDatabaseMetadataTest.java index 77d5e418f..17c999d59 100644 --- a/vertx-pg-client/src/test/java/io/vertx/pgclient/PgDatabaseMetadataTest.java +++ b/vertx-pg-client/src/test/java/io/vertx/pgclient/PgDatabaseMetadataTest.java @@ -34,7 +34,7 @@ public void setUp() { @After public void tearDown(TestContext ctx) { - vertx.close(ctx.asyncAssertSuccess()); + vertx.close().onComplete(ctx.asyncAssertSuccess()); } @Test @@ -60,7 +60,7 @@ private void test(TestContext ctx, Async async = ctx.async(); try { PgConnectOptions options = rule.startServer(containerVersion); - PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { + PgConnection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> { ctx.assertEquals(expectedFull, conn.databaseMetadata().fullVersion()); ctx.assertEquals(expectedMajor, conn.databaseMetadata().majorVersion()); ctx.assertEquals(expectedMinor, conn.databaseMetadata().minorVersion()); diff --git a/vertx-pg-client/src/test/java/io/vertx/pgclient/PgPipeliningTest.java b/vertx-pg-client/src/test/java/io/vertx/pgclient/PgPipeliningTest.java index 42e98a8f6..46bba35e2 100644 --- a/vertx-pg-client/src/test/java/io/vertx/pgclient/PgPipeliningTest.java +++ b/vertx-pg-client/src/test/java/io/vertx/pgclient/PgPipeliningTest.java @@ -47,7 +47,8 @@ public void testPreparedStatementValidationFailure(TestContext ctx) { repeat(ctx, (conn, async) -> { conn .preparedQuery("SELECT $1 :: VARCHAR") - .execute(Tuple.of(3), ctx.asyncAssertFailure(err -> { + .execute(Tuple.of(3)) + .onComplete(ctx.asyncAssertFailure(err -> { async.countDown(); })); }); @@ -58,7 +59,8 @@ public void testPrepareFailure(TestContext ctx) { repeat(ctx, (conn, async) -> { conn .preparedQuery("invalid") - .execute(ctx.asyncAssertFailure(err -> { + .execute() + .onComplete(ctx.asyncAssertFailure(err -> { async.countDown(); })); }); @@ -68,7 +70,7 @@ public void repeat(TestContext ctx, BiConsumer operation) { int times = 128; Async async = ctx.async(times); PgConnectOptions options = new PgConnectOptions(this.options).setPipeliningLimit(1); - PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { + PgConnection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> { for (int i = 0;i < times;i++) { operation.accept(conn, async); } diff --git a/vertx-pg-client/src/test/java/io/vertx/pgclient/PgPoolTest.java b/vertx-pg-client/src/test/java/io/vertx/pgclient/PgPoolTest.java index d5dac763e..5c61b0804 100644 --- a/vertx-pg-client/src/test/java/io/vertx/pgclient/PgPoolTest.java +++ b/vertx-pg-client/src/test/java/io/vertx/pgclient/PgPoolTest.java @@ -66,7 +66,9 @@ public void tearDown(TestContext ctx) { Set pools = this.pools; this.pools = new HashSet<>(); pools.forEach(pool -> { - pool.close(ar -> { + pool + .close() + .onComplete(ar -> { async.countDown(); }); }); @@ -86,9 +88,13 @@ protected PgPool createPool(PgConnectOptions connectOptions, PoolOptions poolOpt public void testClosePool(TestContext ctx) { Async async = ctx.async(); PgPool pool = createPool(options, new PoolOptions().setMaxSize(1).setMaxWaitQueueSize(0)); - pool.getConnection(ctx.asyncAssertSuccess(conn -> { - conn.close(ctx.asyncAssertSuccess(v1 -> { - pool.close(v2 -> { + pool + .getConnection() + .onComplete(ctx.asyncAssertSuccess(conn -> { + conn.close().onComplete(ctx.asyncAssertSuccess(v1 -> { + pool + .close() + .onComplete(v2 -> { async.complete(); }); })); @@ -107,11 +113,18 @@ public void testReconnectQueued(TestContext ctx) { }); proxy.listen(8080, "localhost", ctx.asyncAssertSuccess(v1 -> { PgPool pool = createPool(new PgConnectOptions(options).setPort(8080).setHost("localhost"), 1); - pool.getConnection(ctx.asyncAssertSuccess(conn -> { + pool + .getConnection() + .onComplete(ctx.asyncAssertSuccess(conn -> { proxyConn.get().close(); })); - pool.getConnection(ctx.asyncAssertSuccess(conn -> { - conn.query("SELECT id, randomnumber from WORLD").execute(ctx.asyncAssertSuccess(v2 -> { + pool + .getConnection() + .onComplete(ctx.asyncAssertSuccess(conn -> { + conn + .query("SELECT id, randomnumber from WORLD") + .execute() + .onComplete(ctx.asyncAssertSuccess(v2 -> { async.complete(); })); })); @@ -122,7 +135,10 @@ public void testReconnectQueued(TestContext ctx) { public void testAuthFailure(TestContext ctx) { Async async = ctx.async(); PgPool pool = createPool(new PgConnectOptions(options).setPassword("wrong"), 1); - pool.query("SELECT id, randomnumber from WORLD").execute(ctx.asyncAssertFailure(v2 -> { + pool + .query("SELECT id, randomnumber from WORLD") + .execute() + .onComplete(ctx.asyncAssertFailure(v2 -> { async.complete(); })); } @@ -141,9 +157,13 @@ public void testConnectionFailure(TestContext ctx) { .setMaxSize(1) .setMaxWaitQueueSize(0) ); - pool.getConnection(ctx.asyncAssertFailure(err -> { + pool + .getConnection() + .onComplete(ctx.asyncAssertFailure(err -> { proxy.listen(8080, "localhost", ctx.asyncAssertSuccess(v1 -> { - pool.getConnection(ctx.asyncAssertSuccess(conn -> { + pool + .getConnection() + .onComplete(ctx.asyncAssertSuccess(conn -> { async.complete(); })); })); @@ -167,7 +187,10 @@ public void testRunWithExisting(TestContext ctx) { public void testRunStandalone(TestContext ctx) { Async async = ctx.async(); PgPool pool = createPool(new PgConnectOptions(options), new PoolOptions()); - pool.query("SELECT id, randomnumber from WORLD").execute(ctx.asyncAssertSuccess(v -> { + pool + .query("SELECT id, randomnumber from WORLD") + .execute() + .onComplete(ctx.asyncAssertSuccess(v -> { async.complete(); })); async.await(4000); @@ -177,9 +200,13 @@ public void testRunStandalone(TestContext ctx) { public void testMaxWaitQueueSize(TestContext ctx) { Async async = ctx.async(); PgPool pool = createPool(options, new PoolOptions().setMaxSize(1).setMaxWaitQueueSize(0)); - pool.getConnection(ctx.asyncAssertSuccess(v -> { - pool.getConnection(ctx.asyncAssertFailure(err -> { - v.close(ctx.asyncAssertSuccess(vv -> { + pool + .getConnection() + .onComplete(ctx.asyncAssertSuccess(v -> { + pool + .getConnection() + .onComplete(ctx.asyncAssertFailure(err -> { + v.close().onComplete(ctx.asyncAssertSuccess(vv -> { async.complete(); })); })); @@ -195,7 +222,10 @@ public void testConcurrentMultipleConnection(TestContext ctx) { int numRequests = 2; Async async = ctx.async(numRequests); for (int i = 0; i < numRequests; i++) { - pool.preparedQuery("SELECT * FROM Fortune WHERE id=$1").execute(Tuple.of(1), ctx.asyncAssertSuccess(results -> { + pool + .preparedQuery("SELECT * FROM Fortune WHERE id=$1") + .execute(Tuple.of(1)) + .onComplete(ctx.asyncAssertSuccess(results -> { ctx.assertEquals(1, results.size()); Tuple row = results.iterator().next(); ctx.assertEquals(1, row.getInteger(0)); @@ -211,15 +241,21 @@ public void testUseAvailableResources(TestContext ctx) { Async async = ctx.async(poolSize + 1); PgPool pool = PgPool.pool(options, new PoolOptions().setMaxSize(poolSize)); AtomicReference ctrlConnRef = new AtomicReference<>(); - PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(ctrlConn -> { + PgConnection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(ctrlConn -> { ctrlConnRef.set(ctrlConn); for (int i = 0; i < poolSize; i++) { vertx.setTimer(10 * (i + 1), l -> { - pool.query("select pg_sleep(5)").execute(ctx.asyncAssertSuccess(res -> async.countDown())); + pool + .query("select pg_sleep(5)") + .execute() + .onComplete(ctx.asyncAssertSuccess(res -> async.countDown())); }); } vertx.setTimer(10 * poolSize + 50, event -> { - ctrlConn.query("select count(*) as cnt from pg_stat_activity where application_name like '%vertx%'").execute(ctx.asyncAssertSuccess(rows -> { + ctrlConn + .query("select count(*) as cnt from pg_stat_activity where application_name like '%vertx%'") + .execute() + .onComplete(ctx.asyncAssertSuccess(rows -> { Integer count = rows.iterator().next().getInteger("cnt"); ctx.assertEquals(poolSize + 1, count); async.countDown(); @@ -245,7 +281,9 @@ public void testEventLoopSize(TestContext ctx) { Set eventLoops = Collections.synchronizedSet(new HashSet<>()); Async async = ctx.async(size); for (int i = 0;i < size;i++) { - pool.getConnection(ctx.asyncAssertSuccess(conn -> { + pool + .getConnection() + .onComplete(ctx.asyncAssertSuccess(conn -> { PgSocketConnection c = (PgSocketConnection) ((SqlConnectionInternal) conn).unwrap().unwrap(); EventLoop eventLoop = ((ContextInternal) c.context()).nettyEventLoop(); eventLoops.add(eventLoop); @@ -288,12 +326,18 @@ public void testPipelining(TestContext ctx) { SqlClient pool = PgPool.client(options, new PoolOptions().setMaxSize(1)); AtomicLong start = new AtomicLong(); // Connect to the database - pool.query("select 1").execute(ctx.asyncAssertSuccess(res1 -> { + pool + .query("select 1") + .execute() + .onComplete(ctx.asyncAssertSuccess(res1 -> { // We have a connection in the pool start.set(System.currentTimeMillis()); latency.set(1000); for (int i = 0; i < num; i++) { - pool.query("select 1").execute(ctx.asyncAssertSuccess(res2 -> async.countDown())); + pool + .query("select 1") + .execute() + .onComplete(ctx.asyncAssertSuccess(res2 -> async.countDown())); } })); @@ -305,7 +349,9 @@ public void testPipelining(TestContext ctx) { @Test public void testCannotAcquireConnectionOnPipelinedPool(TestContext ctx) { PgPool pool = (PgPool) PgPool.client(options, new PoolOptions().setMaxSize(1)); - pool.getConnection(ctx.asyncAssertFailure()); + pool + .getConnection() + .onComplete(ctx.asyncAssertFailure()); } /* @Test @@ -402,7 +448,8 @@ public void testPoolConnectTimeout(TestContext ctx) { // Create a connection that remains in the pool long now = System.currentTimeMillis(); pool - .getConnection(ctx.asyncAssertFailure(err -> { + .getConnection() + .onComplete(ctx.asyncAssertFailure(err -> { ctx.assertTrue(System.currentTimeMillis() - now > 900); async.countDown(); })); @@ -415,7 +462,7 @@ public void testPoolConnectTimeout(TestContext ctx) { @Repeat(50) public void testNoConnectionLeaks(TestContext ctx) { Async killConnections = ctx.async(); - PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { + PgConnection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> { Collector> collector = mapping(row -> row.getInteger(0), toList()); String sql = "SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE pid <> pg_backend_pid() AND datname = $1"; PreparedQuery>> preparedQuery = conn.preparedQuery(sql).collecting(collector); @@ -437,12 +484,18 @@ public void testNoConnectionLeaks(TestContext ctx) { Async async = ctx.async(); AtomicInteger pid = new AtomicInteger(); vertx.getOrCreateContext().runOnContext(v -> { - pool.query(sql).execute(ctx.asyncAssertSuccess(rs1 -> { + pool + .query(sql) + .execute() + .onComplete(ctx.asyncAssertSuccess(rs1 -> { Row row1 = rs1.iterator().next(); pid.set(row1.getInteger("pid")); ctx.assertEquals(1, row1.getInteger("cnt")); vertx.setTimer(2 * idleTimeout, l -> { - pool.query(sql).execute(ctx.asyncAssertSuccess(rs2 -> { + pool + .query(sql) + .execute() + .onComplete(ctx.asyncAssertSuccess(rs2 -> { Row row2 = rs2.iterator().next(); ctx.assertEquals(1, row2.getInteger("cnt")); ctx.assertNotEquals(pid.get(), row2.getInteger("pid")); @@ -463,8 +516,13 @@ public void testConnectionHook1(TestContext ctx) { }); }; PgPool pool = createPool(options, new PoolOptions().setMaxSize(1)).connectHandler(hook); - pool.getConnection(ctx.asyncAssertSuccess(conn -> { - conn.query("SELECT id, randomnumber from WORLD").execute(ctx.asyncAssertSuccess(v2 -> { + pool + .getConnection() + .onComplete(ctx.asyncAssertSuccess(conn -> { + conn + .query("SELECT id, randomnumber from WORLD") + .execute() + .onComplete(ctx.asyncAssertSuccess(v2 -> { async.countDown(); })); })); @@ -479,7 +537,10 @@ public void testConnectionHook2(TestContext ctx) { }); }; PgPool pool = createPool(options, new PoolOptions().setMaxSize(1)).connectHandler(hook); - pool.query("SELECT id, randomnumber from WORLD").execute(ctx.asyncAssertSuccess(v2 -> { + pool + .query("SELECT id, randomnumber from WORLD") + .execute() + .onComplete(ctx.asyncAssertSuccess(v2 -> { async.countDown(); })); } @@ -501,7 +562,9 @@ public void testConnectionClosedInHook(TestContext ctx) { proxyConn.get().close(); }; PgPool pool = createPool(new PgConnectOptions(options).setPort(8080).setHost("localhost"), new PoolOptions().setMaxSize(1)).connectHandler(hook); - pool.getConnection(ctx.asyncAssertFailure(conn -> { + pool + .getConnection() + .onComplete(ctx.asyncAssertFailure(conn -> { async.countDown(); })); })); @@ -540,7 +603,9 @@ private void testConnectionClosedInProvider(TestContext ctx, boolean immediately return fut.flatMap(conn -> conn.close().map(conn)); } }); - pool.getConnection(ctx.asyncAssertFailure(conn -> { + pool + .getConnection() + .onComplete(ctx.asyncAssertFailure(conn -> { vertx.runOnContext(v -> { ctx.assertEquals(0, pool.size()); async.complete(); diff --git a/vertx-pg-client/src/test/java/io/vertx/pgclient/PgPoolTestBase.java b/vertx-pg-client/src/test/java/io/vertx/pgclient/PgPoolTestBase.java index 9fdd2d820..0391e6f7e 100644 --- a/vertx-pg-client/src/test/java/io/vertx/pgclient/PgPoolTestBase.java +++ b/vertx-pg-client/src/test/java/io/vertx/pgclient/PgPoolTestBase.java @@ -44,7 +44,7 @@ public void setup() throws Exception { @After public void tearDown(TestContext ctx) { - vertx.close(ctx.asyncAssertSuccess()); + vertx.close().onComplete(ctx.asyncAssertSuccess()); } protected PgPool createPool(PgConnectOptions connectOptions, int size) { @@ -59,10 +59,15 @@ public void testPool(TestContext ctx) { Async async = ctx.async(num); PgPool pool = createPool(options, 4); for (int i = 0;i < num;i++) { - pool.getConnection(ctx.asyncAssertSuccess(conn -> { - conn.query("SELECT id, randomnumber from WORLD").execute(ar -> { + pool + .getConnection() + .onComplete(ctx.asyncAssertSuccess(conn -> { + conn + .query("SELECT id, randomnumber from WORLD") + .execute() + .onComplete(ar -> { if (ar.succeeded()) { - SqlResult result = ar.result(); + RowSet result = ar.result(); ctx.assertEquals(10000, result.size()); } else { ctx.assertEquals("closed", ar.cause().getMessage()); @@ -80,7 +85,10 @@ public void testQuery(TestContext ctx) { Async async = ctx.async(num); PgPool pool = createPool(options, 4); for (int i = 0;i < num;i++) { - pool.query("SELECT id, randomnumber from WORLD").execute(ar -> { + pool + .query("SELECT id, randomnumber from WORLD") + .execute() + .onComplete(ar -> { if (ar.succeeded()) { SqlResult result = ar.result(); ctx.assertEquals(10000, result.size()); @@ -107,9 +115,12 @@ private void testQueryWithParams(TestContext ctx, PgConnectOptions options) { Async async = ctx.async(num); PgPool pool = createPool(options, 1); for (int i = 0;i < num;i++) { - pool.preparedQuery("SELECT id, randomnumber from WORLD where id=$1").execute(Tuple.of(i + 1), ar -> { + pool + .preparedQuery("SELECT id, randomnumber from WORLD where id=$1") + .execute(Tuple.of(i + 1)) + .onComplete(ar -> { if (ar.succeeded()) { - SqlResult result = ar.result(); + RowSet result = ar.result(); ctx.assertEquals(1, result.size()); } else { ar.cause().printStackTrace(); @@ -126,9 +137,12 @@ public void testUpdate(TestContext ctx) { Async async = ctx.async(num); PgPool pool = createPool(options, 4); for (int i = 0;i < num;i++) { - pool.query("UPDATE Fortune SET message = 'Whatever' WHERE id = 9").execute(ar -> { + pool + .query("UPDATE Fortune SET message = 'Whatever' WHERE id = 9") + .execute() + .onComplete(ar -> { if (ar.succeeded()) { - SqlResult result = ar.result(); + RowSet result = ar.result(); ctx.assertEquals(1, result.rowCount()); } else { ctx.assertEquals("closed", ar.cause().getMessage()); @@ -144,9 +158,12 @@ public void testUpdateWithParams(TestContext ctx) { Async async = ctx.async(num); PgPool pool = createPool(options, 4); for (int i = 0;i < num;i++) { - pool.preparedQuery("UPDATE Fortune SET message = 'Whatever' WHERE id = $1").execute(Tuple.of(9), ar -> { + pool + .preparedQuery("UPDATE Fortune SET message = 'Whatever' WHERE id = $1") + .execute(Tuple.of(9)) + .onComplete(ar -> { if (ar.succeeded()) { - SqlResult result = ar.result(); + RowSet result = ar.result(); ctx.assertEquals(1, result.rowCount()); } else { ctx.assertEquals("closed", ar.cause().getMessage()); @@ -167,12 +184,22 @@ public void testReconnect(TestContext ctx) { }); proxy.listen(8080, "localhost", ctx.asyncAssertSuccess(v1 -> { PgPool pool = createPool(new PgConnectOptions(options).setPort(8080).setHost("localhost"), 1); - pool.getConnection(ctx.asyncAssertSuccess(conn1 -> { + pool + .getConnection() + .onComplete(ctx.asyncAssertSuccess(conn1 -> { proxyConn.get().close(); conn1.closeHandler(v2 -> { - conn1.query("never-read").execute(ctx.asyncAssertFailure(err -> { - pool.getConnection(ctx.asyncAssertSuccess(conn2 -> { - conn2.query("SELECT id, randomnumber from WORLD").execute(ctx.asyncAssertSuccess(v3 -> { + conn1 + .query("never-read") + .execute() + .onComplete(ctx.asyncAssertFailure(err -> { + pool + .getConnection() + .onComplete(ctx.asyncAssertSuccess(conn2 -> { + conn2 + .query("SELECT id, randomnumber from WORLD") + .execute() + .onComplete(ctx.asyncAssertSuccess(v3 -> { async.complete(); })); })); @@ -186,13 +213,20 @@ public void testReconnect(TestContext ctx) { public void testCancelRequest(TestContext ctx) { Async async = ctx.async(); PgPool pool = createPool(options, 4); - pool.getConnection(ctx.asyncAssertSuccess(conn -> { - conn.query("SELECT pg_sleep(10)").execute(ctx.asyncAssertFailure(error -> { + pool + .getConnection() + .onComplete(ctx.asyncAssertSuccess(conn -> { + conn + .query("SELECT pg_sleep(10)") + .execute() + .onComplete(ctx.asyncAssertFailure(error -> { ctx.assertTrue(hasSqlstateCode(error, ERRCODE_QUERY_CANCELED), error.getMessage()); conn.close(); async.complete(); })); - ((PgConnection)conn).cancelRequest(ctx.asyncAssertSuccess()); + ((PgConnection)conn) + .cancelRequest() + .onComplete(ctx.asyncAssertSuccess()); })); } @@ -204,9 +238,13 @@ public void testWithConnection(TestContext ctx) { Function>> failure = conn -> conn.query("SELECT does_not_exist").execute(); for (int i = 0;i < 10;i++) { if (i % 2 == 0) { - pool.withConnection(success, ctx.asyncAssertSuccess(v -> async.countDown())); + pool + .withConnection(success) + .onComplete(ctx.asyncAssertSuccess(v -> async.countDown())); } else { - pool.withConnection(failure, ctx.asyncAssertFailure(v -> async.countDown())); + pool + .withConnection(failure) + .onComplete(ctx.asyncAssertFailure(v -> async.countDown())); } } } diff --git a/vertx-pg-client/src/test/java/io/vertx/pgclient/PgPooledConnectionTest.java b/vertx-pg-client/src/test/java/io/vertx/pgclient/PgPooledConnectionTest.java index 32b807b1f..b21387a3c 100644 --- a/vertx-pg-client/src/test/java/io/vertx/pgclient/PgPooledConnectionTest.java +++ b/vertx-pg-client/src/test/java/io/vertx/pgclient/PgPooledConnectionTest.java @@ -34,7 +34,7 @@ public PgPooledConnectionTest() { if (pool == null) { pool = PgPool.pool(vertx, new PgConnectOptions(options), new PoolOptions().setMaxSize(1)); } - pool.getConnection(handler); + pool.getConnection().onComplete(handler); }; } @@ -62,17 +62,29 @@ public void testTransactionRollbackUnfinishedOnRecycle(TestContext ctx) { connector.accept(ctx.asyncAssertSuccess(conn1 -> { deleteFromTestTable(ctx, conn1, () -> { conn1.begin(); - conn1.query("INSERT INTO Test (id, val) VALUES (5, 'some-value')").execute(ctx.asyncAssertSuccess()); - conn1.query("SELECT txid_current()").execute(ctx.asyncAssertSuccess(result -> { + conn1 + .query("INSERT INTO Test (id, val) VALUES (5, 'some-value')") + .execute() + .onComplete(ctx.asyncAssertSuccess()); + conn1 + .query("SELECT txid_current()") + .execute() + .onComplete(ctx.asyncAssertSuccess(result -> { Long txid1 = result.iterator().next().getLong(0); conn1.close(); // It will be the same connection connector.accept(ctx.asyncAssertSuccess(conn2 -> { - conn2.query("SELECT id FROM Test WHERE id=5").execute(ctx.asyncAssertSuccess(result2 -> { + conn2 + .query("SELECT id FROM Test WHERE id=5") + .execute() + .onComplete(ctx.asyncAssertSuccess(result2 -> { ctx.assertEquals(0, result2.size()); done.countDown(); })); - conn2.query("SELECT txid_current()").execute(ctx.asyncAssertSuccess(result2 -> { + conn2 + .query("SELECT txid_current()") + .execute() + .onComplete(ctx.asyncAssertSuccess(result2 -> { Long txid2 = result.iterator().next().getLong(0); ctx.assertEquals(txid1, txid2); done.countDown(); diff --git a/vertx-pg-client/src/test/java/io/vertx/pgclient/PgScramConnectionTest.java b/vertx-pg-client/src/test/java/io/vertx/pgclient/PgScramConnectionTest.java index b5f6e73de..3bbd33f23 100644 --- a/vertx-pg-client/src/test/java/io/vertx/pgclient/PgScramConnectionTest.java +++ b/vertx-pg-client/src/test/java/io/vertx/pgclient/PgScramConnectionTest.java @@ -59,7 +59,7 @@ public void testSaslConnection(TestContext ctx) throws InterruptedException { options.setUser("saslscram"); options.setPassword("saslscrampwd"); - PgConnection.connect(vertx, options, + PgConnection.connect(vertx, options).onComplete( ctx.asyncAssertSuccess(ar -> { ctx.assertNotNull(ar); async.complete(); @@ -69,7 +69,7 @@ public void testSaslConnection(TestContext ctx) throws InterruptedException { @After public void teardown(TestContext ctx) { - vertx.close(ctx.asyncAssertSuccess()); + vertx.close().onComplete(ctx.asyncAssertSuccess()); } } diff --git a/vertx-pg-client/src/test/java/io/vertx/pgclient/PgTestBase.java b/vertx-pg-client/src/test/java/io/vertx/pgclient/PgTestBase.java index a959b4f17..7d6bbdeff 100644 --- a/vertx-pg-client/src/test/java/io/vertx/pgclient/PgTestBase.java +++ b/vertx-pg-client/src/test/java/io/vertx/pgclient/PgTestBase.java @@ -48,7 +48,10 @@ public void setup() throws Exception { } static void deleteFromTestTable(TestContext ctx, SqlClient client, Runnable completionHandler) { - client.query("DELETE FROM Test").execute(ctx.asyncAssertSuccess(result -> completionHandler.run())); + client + .query("DELETE FROM Test") + .execute() + .onComplete(ctx.asyncAssertSuccess(result -> completionHandler.run())); } static void insertIntoTestTable(TestContext ctx, SqlClient client, int amount, Runnable completionHandler) { @@ -56,7 +59,8 @@ static void insertIntoTestTable(TestContext ctx, SqlClient client, int amount, R for (int i = 0;i < 10;i++) { client .query("INSERT INTO Test (id, val) VALUES (" + i + ", 'Whatever-" + i + "')") - .execute(ctx.asyncAssertSuccess(r1 -> { + .execute() + .onComplete(ctx.asyncAssertSuccess(r1 -> { ctx.assertEquals(1, r1.rowCount()); if (count.incrementAndGet() == amount) { completionHandler.run(); diff --git a/vertx-pg-client/src/test/java/io/vertx/pgclient/PoolMultiTest.java b/vertx-pg-client/src/test/java/io/vertx/pgclient/PoolMultiTest.java index 743f88720..7c0f6ec8d 100644 --- a/vertx-pg-client/src/test/java/io/vertx/pgclient/PoolMultiTest.java +++ b/vertx-pg-client/src/test/java/io/vertx/pgclient/PoolMultiTest.java @@ -44,7 +44,7 @@ public void setup() throws Exception { @After public void teardown(TestContext ctx) { - vertx.close(ctx.asyncAssertSuccess()); + vertx.close().onComplete(ctx.asyncAssertSuccess()); } @Test @@ -78,9 +78,12 @@ private void testLoadBalancing(TestContext ctx, PgPool pool) { CompositeFuture.all((List)futures).onComplete(ctx.asyncAssertSuccess(c -> { for (int i = 0;i < count;i++) { SqlConnection conn = futures.get(i).result(); - conn.query("SELECT user").execute(ctx.asyncAssertSuccess(res -> { + conn + .query("SELECT user") + .execute() + .onComplete(ctx.asyncAssertSuccess(res -> { users.add(res.iterator().next().getString(0)); - conn.close(ctx.asyncAssertSuccess(v -> { + conn.close().onComplete(ctx.asyncAssertSuccess(v -> { async.countDown(); })); })); diff --git a/vertx-pg-client/src/test/java/io/vertx/pgclient/PreparedStatementCachedTest.java b/vertx-pg-client/src/test/java/io/vertx/pgclient/PreparedStatementCachedTest.java index 94246da7a..7d71d1bb8 100644 --- a/vertx-pg-client/src/test/java/io/vertx/pgclient/PreparedStatementCachedTest.java +++ b/vertx-pg-client/src/test/java/io/vertx/pgclient/PreparedStatementCachedTest.java @@ -37,19 +37,31 @@ protected PgConnectOptions options() { @Test public void testOneShotPreparedQueryCacheRefreshOnTableSchemaChange(TestContext ctx) { Async async = ctx.async(); - PgConnection.connect(vertx, options(), ctx.asyncAssertSuccess(conn -> { - conn.preparedQuery("SELECT * FROM unstable WHERE id=$1").execute(Tuple.of(1), ctx.asyncAssertSuccess(res1 -> { + PgConnection.connect(vertx, options()).onComplete(ctx.asyncAssertSuccess(conn -> { + conn + .preparedQuery("SELECT * FROM unstable WHERE id=$1") + .execute(Tuple.of(1)) + .onComplete(ctx.asyncAssertSuccess(res1 -> { ctx.assertEquals(1, res1.size()); Tuple row1 = res1.iterator().next(); ctx.assertEquals(1, row1.getInteger(0)); ctx.assertEquals("fortune: No such file or directory", row1.getString(1)); // change table schema - conn.query("ALTER TABLE unstable DROP COLUMN message").execute(ctx.asyncAssertSuccess(dropColumn -> { + conn + .query("ALTER TABLE unstable DROP COLUMN message") + .execute() + .onComplete(ctx.asyncAssertSuccess(dropColumn -> { // failure due to schema change - conn.preparedQuery("SELECT * FROM unstable WHERE id=$1").execute(Tuple.of(1), ctx.asyncAssertFailure(failure -> { + conn + .preparedQuery("SELECT * FROM unstable WHERE id=$1") + .execute(Tuple.of(1)) + .onComplete(ctx.asyncAssertFailure(failure -> { // recover because the cache is refreshed - conn.preparedQuery("SELECT * FROM unstable WHERE id=$1").execute(Tuple.of(1), ctx.asyncAssertSuccess(res2 -> { + conn + .preparedQuery("SELECT * FROM unstable WHERE id=$1") + .execute(Tuple.of(1)) + .onComplete(ctx.asyncAssertSuccess(res2 -> { ctx.assertEquals(1, res2.size()); Tuple row2 = res2.iterator().next(); ctx.assertEquals(1, row2.getInteger(0)); @@ -83,20 +95,29 @@ public void testPreparedStatementCacheFiltering(TestContext ctx) { private void testPreparedStatements(TestContext ctx, PgConnectOptions options, int num, int expected) { Async async = ctx.async(); - PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.query("SELECT * FROM pg_prepared_statements").execute(ctx.asyncAssertSuccess(res1 -> { + PgConnection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> { + conn + .query("SELECT * FROM pg_prepared_statements") + .execute() + .onComplete(ctx.asyncAssertSuccess(res1 -> { ctx.assertEquals(0, res1.size()); AtomicInteger count = new AtomicInteger(num); for (int i = 0;i < num;i++) { int val = i; - conn.preparedQuery("SELECT " + i).execute(Tuple.tuple(), ctx.asyncAssertSuccess(res2 -> { + conn + .preparedQuery("SELECT " + i) + .execute(Tuple.tuple()) + .onComplete(ctx.asyncAssertSuccess(res2 -> { ctx.assertEquals(1, res2.size()); ctx.assertEquals(val, res2.iterator().next().getInteger(0)); if (count.decrementAndGet() == 0) { ctx.assertEquals(num - 1, val); - conn.query("SELECT * FROM pg_prepared_statements").execute(ctx.asyncAssertSuccess(res3 -> { + conn + .query("SELECT * FROM pg_prepared_statements") + .execute() + .onComplete(ctx.asyncAssertSuccess(res3 -> { ctx.assertEquals(expected, res3.size()); - conn.close(ctx.asyncAssertSuccess(v -> { + conn.close().onComplete(ctx.asyncAssertSuccess(v -> { async.complete(); })); })); diff --git a/vertx-pg-client/src/test/java/io/vertx/pgclient/PreparedStatementTestBase.java b/vertx-pg-client/src/test/java/io/vertx/pgclient/PreparedStatementTestBase.java index 461b4be86..a3a82577c 100644 --- a/vertx-pg-client/src/test/java/io/vertx/pgclient/PreparedStatementTestBase.java +++ b/vertx-pg-client/src/test/java/io/vertx/pgclient/PreparedStatementTestBase.java @@ -74,20 +74,23 @@ public void setup() throws Exception { @After public void teardown(TestContext ctx) { - vertx.close(ctx.asyncAssertSuccess()); + vertx.close().onComplete(ctx.asyncAssertSuccess()); } @Test public void testQuery1Param(TestContext ctx) { Async async = ctx.async(); - PgConnection.connect(vertx, options(), ctx.asyncAssertSuccess(conn -> { - conn.prepare("SELECT * FROM Fortune WHERE id=$1", ctx.asyncAssertSuccess(ps -> { - ps.query().execute(Tuple.of(1), ctx.asyncAssertSuccess(results -> { + PgConnection.connect(vertx, options()).onComplete(ctx.asyncAssertSuccess(conn -> { + conn.prepare("SELECT * FROM Fortune WHERE id=$1").onComplete(ctx.asyncAssertSuccess(ps -> { + ps + .query() + .execute(Tuple.of(1)) + .onComplete(ctx.asyncAssertSuccess(results -> { ctx.assertEquals(1, results.size()); Tuple row = results.iterator().next(); ctx.assertEquals(1, row.getInteger(0)); ctx.assertEquals("fortune: No such file or directory", row.getString(1)); - ps.close(ctx.asyncAssertSuccess(ar -> { + ps.close().onComplete(ctx.asyncAssertSuccess(ar -> { async.complete(); })); })); @@ -98,12 +101,14 @@ public void testQuery1Param(TestContext ctx) { @Test public void testQuery(TestContext ctx) { Async async = ctx.async(); - PgConnection.connect(vertx, options(), ctx.asyncAssertSuccess(conn -> { - conn.prepare("SELECT * FROM Fortune WHERE id=$1 OR id=$2 OR id=$3 OR id=$4 OR id=$5 OR id=$6", ctx.asyncAssertSuccess(ps -> { - ps.query() - .execute(Tuple.of(1, 8, 4, 11, 2, 9), ctx.asyncAssertSuccess(results -> { + PgConnection.connect(vertx, options()).onComplete(ctx.asyncAssertSuccess(conn -> { + conn.prepare("SELECT * FROM Fortune WHERE id=$1 OR id=$2 OR id=$3 OR id=$4 OR id=$5 OR id=$6").onComplete(ctx.asyncAssertSuccess(ps -> { + ps + .query() + .execute(Tuple.of(1, 8, 4, 11, 2, 9)) + .onComplete(ctx.asyncAssertSuccess(results -> { ctx.assertEquals(6, results.size()); - ps.close(ctx.asyncAssertSuccess(result -> { + ps.close().onComplete(ctx.asyncAssertSuccess(result -> { async.complete(); })); })); @@ -114,14 +119,18 @@ public void testQuery(TestContext ctx) { @Test public void testCollectorQuery(TestContext ctx) { Async async = ctx.async(); - PgConnection.connect(vertx, options(), ctx.asyncAssertSuccess(conn -> { - conn.prepare("SELECT * FROM Fortune WHERE id=$1 OR id=$2 OR id=$3 OR id=$4 OR id=$5 OR id=$6", ctx.asyncAssertSuccess(ps -> { - ps.query().collecting(Collectors.toList()).execute(Tuple.of(1, 8, 4, 11, 2, 9), ctx.asyncAssertSuccess(results -> { + PgConnection.connect(vertx, options()).onComplete(ctx.asyncAssertSuccess(conn -> { + conn.prepare("SELECT * FROM Fortune WHERE id=$1 OR id=$2 OR id=$3 OR id=$4 OR id=$5 OR id=$6").onComplete(ctx.asyncAssertSuccess(ps -> { + ps + .query() + .collecting(Collectors.toList()) + .execute(Tuple.of(1, 8, 4, 11, 2, 9)) + .onComplete(ctx.asyncAssertSuccess(results -> { ctx.assertEquals(6, results.size()); List list = results.value(); ctx.assertEquals(list.size(), 6); ctx.assertEquals(6L, list.stream().distinct().count()); - ps.close(ctx.asyncAssertSuccess(result -> { + ps.close().onComplete(ctx.asyncAssertSuccess(result -> { async.complete(); })); })); @@ -132,17 +141,19 @@ public void testCollectorQuery(TestContext ctx) { @Test public void testMappedQuery(TestContext ctx) { Async async = ctx.async(); - PgConnection.connect(vertx, options(), ctx.asyncAssertSuccess(conn -> { - conn.prepare("SELECT $1 :: INT4", ctx.asyncAssertSuccess(ps -> { - ps.query() + PgConnection.connect(vertx, options()).onComplete(ctx.asyncAssertSuccess(conn -> { + conn.prepare("SELECT $1 :: INT4").onComplete(ctx.asyncAssertSuccess(ps -> { + ps + .query() .mapping(row -> "" + row.getInteger(0)) - .execute(Tuple.of(1), ctx.asyncAssertSuccess(results -> { + .execute(Tuple.of(1)) + .onComplete(ctx.asyncAssertSuccess(results -> { ctx.assertEquals(1, results.size()); RowSet rows = results.value(); ctx.assertEquals(rows.size(), 1); RowIterator it = rows.iterator(); ctx.assertEquals("1", it.next()); - ps.close(ctx.asyncAssertSuccess(result -> { + ps.close().onComplete(ctx.asyncAssertSuccess(result -> { async.complete(); })); })); @@ -154,14 +165,14 @@ public void testMappedQuery(TestContext ctx) { @Test public void testQueryStream(TestContext ctx) { Async async = ctx.async(); - PgConnection.connect(vertx, options(), (ctx.asyncAssertSuccess(conn -> { - conn.prepare("SELECT * FROM Fortune WHERE id=$1 OR id=$2 OR id=$3 OR id=$4 OR id=$5 OR id=$6", ctx.asyncAssertSuccess(ps -> { + PgConnection.connect(vertx, options()).onComplete((ctx.asyncAssertSuccess(conn -> { + conn.prepare("SELECT * FROM Fortune WHERE id=$1 OR id=$2 OR id=$3 OR id=$4 OR id=$5 OR id=$6").onComplete(ctx.asyncAssertSuccess(ps -> { PgQuery createStream = ps.query(1, 8, 4, 11, 2, 9); LinkedList results = new LinkedList<>(); createStream.exceptionHandler(ctx::fail); createStream.endHandler(v -> { ctx.assertEquals(6, results.size()); - ps.close(ctx.asyncAssertSuccess(result -> { + ps.close().onComplete(ctx.asyncAssertSuccess(result -> { async.complete(); })); }); @@ -173,8 +184,8 @@ public void testQueryStream(TestContext ctx) { @Test public void testQueryParseError(TestContext ctx) { Async async = ctx.async(); - PgConnection.connect(vertx, options(), ctx.asyncAssertSuccess(conn -> { - conn.prepare("invalid", ctx.asyncAssertFailure(err -> { + PgConnection.connect(vertx, options()).onComplete(ctx.asyncAssertSuccess(conn -> { + conn.prepare("invalid").onComplete(ctx.asyncAssertFailure(err -> { PgException pgErr = (PgException) err; ctx.assertEquals(ErrorCodes.syntax_error, pgErr.getSqlState()); async.complete(); @@ -188,7 +199,7 @@ private void testValidationError(TestContext ctx, BiConsumer check = failure -> ctx.assertEquals("Parameter at position[0] with class = [java.lang.String] and value = [invalid-id] can not be coerced to the expected class = [java.lang.Number] for encoding.", failure.getMessage()); - PgConnection.connect(vertx, options(), ctx.asyncAssertSuccess(conn -> { + PgConnection.connect(vertx, options()).onComplete(ctx.asyncAssertSuccess(conn -> { // This will test with pipelining for (int i = 0;i < times;i++) { test.accept(conn, failure1 -> { @@ -208,8 +219,11 @@ private void testValidationError(TestContext ctx, BiConsumer { - conn.prepare("SELECT * FROM Fortune WHERE id=$1", ctx.asyncAssertSuccess(ps -> { - ps.query().execute(INVALID_TUPLE, ctx.asyncAssertFailure(cont)); + conn.prepare("SELECT * FROM Fortune WHERE id=$1").onComplete(ctx.asyncAssertSuccess(ps -> { + ps + .query() + .execute(INVALID_TUPLE) + .onComplete(ctx.asyncAssertFailure(cont)); })); }); } @@ -219,7 +233,8 @@ public void testPreparedQueryValidationError(TestContext ctx) { testValidationError(ctx, (conn, cont) -> { conn .preparedQuery("SELECT * FROM Fortune WHERE id=$1") - .execute(INVALID_TUPLE, ctx.asyncAssertFailure(cont)); + .execute(INVALID_TUPLE) + .onComplete(ctx.asyncAssertFailure(cont)); }); } @@ -228,16 +243,18 @@ public void testPreparedQueryValidationError_(TestContext ctx) { testValidationError(ctx, (conn, cont) -> { conn .preparedQuery("SELECT * FROM Fortune WHERE id=$1") - .execute(INVALID_TUPLE, ctx.asyncAssertFailure(cont)); + .execute(INVALID_TUPLE) + .onComplete(ctx.asyncAssertFailure(cont)); }); } @Test public void testPrepareCursorValidationError(TestContext ctx) { testValidationError(ctx, (conn, cont) -> { - conn.prepare("SELECT * FROM Fortune WHERE id=$1", ctx.asyncAssertSuccess(ps -> { + conn.prepare("SELECT * FROM Fortune WHERE id=$1").onComplete(ctx.asyncAssertSuccess(ps -> { Cursor cursor = ps.cursor(INVALID_TUPLE); - cursor.read(10, ctx.asyncAssertFailure(cont)); + cursor.read(10) + .onComplete(ctx.asyncAssertFailure(cont)); })); }); } @@ -245,8 +262,11 @@ public void testPrepareCursorValidationError(TestContext ctx) { @Test public void testPrepareBatchValidationError(TestContext ctx) { testValidationError(ctx, (conn, cont) -> { - conn.prepare("SELECT * FROM Fortune WHERE id=$1", ctx.asyncAssertSuccess(ps -> { - ps.query().executeBatch(Collections.singletonList(INVALID_TUPLE), ctx.asyncAssertFailure(cont)); + conn.prepare("SELECT * FROM Fortune WHERE id=$1").onComplete(ctx.asyncAssertSuccess(ps -> { + ps + .query() + .executeBatch(Collections.singletonList(INVALID_TUPLE)) + .onComplete(ctx.asyncAssertFailure(cont)); })); }); } @@ -254,20 +274,25 @@ public void testPrepareBatchValidationError(TestContext ctx) { @Test public void testPreparedBatchValidationError(TestContext ctx) { testValidationError(ctx, (conn, cont) -> { - conn.prepare("SELECT * FROM Fortune WHERE id=$1", ctx.asyncAssertSuccess(ps -> ps + conn + .prepare("SELECT * FROM Fortune WHERE id=$1").onComplete(ctx.asyncAssertSuccess(ps -> ps .query() - .executeBatch(Collections.singletonList(INVALID_TUPLE), ctx.asyncAssertFailure(cont)))); + .executeBatch(Collections.singletonList(INVALID_TUPLE)) + .onComplete(ctx.asyncAssertFailure(cont)))); }); } @Test public void testNullValueIsAlwaysValid(TestContext ctx) { Async async = ctx.async(); - PgConnection.connect(vertx, options(), ctx.asyncAssertSuccess(conn -> { + PgConnection.connect(vertx, options()).onComplete(ctx.asyncAssertSuccess(conn -> { conn - .prepare("SELECT 1 WHERE $1::INT4 IS NULL", ctx.asyncAssertSuccess(ps -> - ps.query() - .execute(Tuple.tuple().addInteger(null), ctx.asyncAssertSuccess(result -> { + .prepare("SELECT 1 WHERE $1::INT4 IS NULL") + .onComplete(ctx.asyncAssertSuccess(ps -> + ps + .query() + .execute(Tuple.tuple().addInteger(null)) + .onComplete(ctx.asyncAssertSuccess(result -> { ctx.assertEquals(1, result.size()); async.complete(); })))); @@ -277,8 +302,8 @@ public void testNullValueIsAlwaysValid(TestContext ctx) { @Test public void testStreamQueryError(TestContext ctx) { Async async = ctx.async(); - PgConnection.connect(vertx, options(), ctx.asyncAssertSuccess(conn -> { - conn.prepare("SELECT * FROM Fortune", ctx.asyncAssertSuccess(ps -> { + PgConnection.connect(vertx, options()).onComplete(ctx.asyncAssertSuccess(conn -> { + conn.prepare("SELECT * FROM Fortune").onComplete(ctx.asyncAssertSuccess(ps -> { RowStream stream = ps.createStream(4, Tuple.tuple()); stream.endHandler(v -> ctx.fail()); AtomicInteger rowCount = new AtomicInteger(); @@ -293,11 +318,15 @@ public void testStreamQueryError(TestContext ctx) { @Test public void testCursorNoTx(TestContext ctx) { - PgConnection.connect(vertx, options(), ctx.asyncAssertSuccess(conn -> { - conn.prepare("SELECT * FROM Fortune", ctx.asyncAssertSuccess(ps -> { + PgConnection.connect(vertx, options()).onComplete(ctx.asyncAssertSuccess(conn -> { + conn.prepare("SELECT * FROM Fortune").onComplete(ctx.asyncAssertSuccess(ps -> { Cursor cursor = ps.cursor(Tuple.tuple()); - cursor.read(1, ctx.asyncAssertSuccess(rowSet -> { - cursor.read(1, ctx.asyncAssertFailure(err -> { + cursor + .read(1) + .onComplete(ctx.asyncAssertSuccess(rowSet -> { + cursor + .read(1) + .onComplete(ctx.asyncAssertFailure(err -> { PgException pgErr = (PgException) err; // This fails expectedly because the portal is closed ctx.assertEquals("34000", pgErr.getSqlState()); // invalid_cursor_name @@ -312,9 +341,9 @@ public void testCursorNoTx(TestContext ctx) { @Test public void testStreamQueryCancel(TestContext ctx) { Async async = ctx.async(); - PgConnection.connect(vertx, options(), (ctx.asyncAssertSuccess(conn -> { + PgConnection.connect(vertx, options()).onComplete((ctx.asyncAssertSuccess(conn -> { conn.query("BEGIN").execute(ctx.asyncAssertSuccess(begin -> { - conn.prepare("SELECT * FROM Fortune", ctx.asyncAssertSuccess(ps -> { + conn.prepare("SELECT * FROM Fortune").onComplete(ctx.asyncAssertSuccess(ps -> { PgStream createStream = ps.createStream(Tuple.tuple()); AtomicInteger count = new AtomicInteger(); createStream.handler(tuple -> { @@ -329,9 +358,12 @@ public void testStreamQueryCancel(TestContext ctx) { @Test public void testCloseStatement(TestContext ctx) { - PgConnection.connect(vertx, options(), ctx.asyncAssertSuccess(conn -> { - conn.prepare("SELECT * FROM Fortune WHERE id=$1", ctx.asyncAssertSuccess(ps -> { - conn.query("SELECT * FROM pg_prepared_statements").execute(ctx.asyncAssertSuccess(res1 -> { + PgConnection.connect(vertx, options()).onComplete(ctx.asyncAssertSuccess(conn -> { + conn.prepare("SELECT * FROM Fortune WHERE id=$1").onComplete(ctx.asyncAssertSuccess(ps -> { + conn + .query("SELECT * FROM pg_prepared_statements") + .execute() + .onComplete(ctx.asyncAssertSuccess(res1 -> { boolean isStatementPrepared = false; for (Row row : res1) { String statement = row.getString("statement"); @@ -342,8 +374,11 @@ public void testCloseStatement(TestContext ctx) { if (!isStatementPrepared) { ctx.fail("Statement is not prepared"); } - ps.close(ctx.asyncAssertSuccess(v -> { - conn.query("SELECT * FROM pg_prepared_statements").execute(ctx.asyncAssertSuccess(res2 -> { + ps.close().onComplete(ctx.asyncAssertSuccess(v -> { + conn + .query("SELECT * FROM pg_prepared_statements") + .execute() + .onComplete(ctx.asyncAssertSuccess(res2 -> { for (Row row : res2) { String statement = row.getString("statement"); if (statement.equals("SELECT * FROM Fortune WHERE id=$1")) { @@ -491,7 +526,7 @@ private void testInferDataType42P18(TestContext ctx, Class type, T value, private void testInferDataType42P18(TestContext ctx, Class type, T value, String suffix1, String suffix2) { Object array = Array.newInstance(type, 1); Array.set(array, 0, value); - PgConnection.connect(vertx, options(), ctx.asyncAssertSuccess(conn -> { + PgConnection.connect(vertx, options()).onComplete(ctx.asyncAssertSuccess(conn -> { conn .preparedQuery("SELECT CONCAT('HELLO ', $1)").execute(Tuple.of(value)) .map(result1 -> { @@ -512,7 +547,7 @@ private void testInferDataType42P18(TestContext ctx, Class type, T value, @Test public void testInferDataTypeLazy42P18(TestContext ctx) { - PgConnection.connect(vertx, options(), ctx.asyncAssertSuccess(conn -> { + PgConnection.connect(vertx, options()).onComplete(ctx.asyncAssertSuccess(conn -> { conn .prepare("SELECT CONCAT('HELLO', $1)") .compose(ps -> ps.query().execute(Tuple.of("__"))) @@ -527,7 +562,7 @@ public void testInferDataTypeLazy42P18(TestContext ctx) { @Test public void testInferDataTypeFailure42P18(TestContext ctx) { - PgConnection.connect(vertx, options(), ctx.asyncAssertSuccess(conn -> { + PgConnection.connect(vertx, options()).onComplete(ctx.asyncAssertSuccess(conn -> { conn.preparedQuery("SELECT CONCAT('HELLO', $1)") .execute(Tuple.of(null)) .eventually(v -> conn.close()) @@ -537,7 +572,7 @@ public void testInferDataTypeFailure42P18(TestContext ctx) { @Test public void testInferDataTypeLazyFailure42P18(TestContext ctx) { - PgConnection.connect(vertx, options(), ctx.asyncAssertSuccess(conn -> { + PgConnection.connect(vertx, options()).onComplete(ctx.asyncAssertSuccess(conn -> { conn .prepare("SELECT CONCAT('HELLO', $1)") .compose(ps -> ps.query().execute(Tuple.of(null))) @@ -548,7 +583,7 @@ public void testInferDataTypeLazyFailure42P18(TestContext ctx) { @Test public void testInferDataTypeLazy42804(TestContext ctx) { - PgConnection.connect(vertx, options(), ctx.asyncAssertSuccess(conn -> { + PgConnection.connect(vertx, options()).onComplete(ctx.asyncAssertSuccess(conn -> { conn .prepare("SELECT to_jsonb($1)") .compose(ps -> ps.query().execute(Tuple.of("foo"))) @@ -563,7 +598,7 @@ public void testInferDataTypeLazy42804(TestContext ctx) { @Test public void testInferDataTypeLazy42P08(TestContext ctx) { - PgConnection.connect(vertx, options(), ctx.asyncAssertSuccess(conn -> { + PgConnection.connect(vertx, options()).onComplete(ctx.asyncAssertSuccess(conn -> { conn .prepare("UPDATE Fortune SET message=$2 WHERE id=$1 AND (Fortune.*) IS DISTINCT FROM ($1, $2)") .compose(ps -> ps.query().execute(Tuple.of(9, "Feature: A bug with seniority."))) diff --git a/vertx-pg-client/src/test/java/io/vertx/pgclient/PubSubTest.java b/vertx-pg-client/src/test/java/io/vertx/pgclient/PubSubTest.java index 57cbac8cc..8c45c9079 100644 --- a/vertx-pg-client/src/test/java/io/vertx/pgclient/PubSubTest.java +++ b/vertx-pg-client/src/test/java/io/vertx/pgclient/PubSubTest.java @@ -47,7 +47,7 @@ public void teardown(TestContext ctx) { if (subscriber != null) { subscriber.close(); } - vertx.close(ctx.asyncAssertSuccess()); + vertx.close().onComplete(ctx.asyncAssertSuccess()); } @Test @@ -63,10 +63,11 @@ public void testNotifyChannelRequiresQuotedID(TestContext ctx) { public void testNotify(TestContext ctx, String channelName) { String quotedChannelName = "\"" + channelName.replace("\"", "\"\"") + "\""; Async async = ctx.async(2); - PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { + PgConnection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> { conn .query("LISTEN " + quotedChannelName) - .execute(ctx.asyncAssertSuccess(result1 -> { + .execute() + .onComplete(ctx.asyncAssertSuccess(result1 -> { conn.notificationHandler(notification -> { ctx.assertEquals(channelName, notification.getChannel()); ctx.assertEquals("the message", notification.getPayload()); @@ -74,7 +75,8 @@ public void testNotify(TestContext ctx, String channelName) { }); conn .query("NOTIFY " + quotedChannelName + ", 'the message'") - .execute(ctx.asyncAssertSuccess(result2 -> { + .execute() + .onComplete(ctx.asyncAssertSuccess(result2 -> { async.countDown(); })); })); @@ -107,10 +109,18 @@ private void testConnect(TestContext ctx, String channel1Name, String channel2Na notifiedLatch.countDown(); }); Async connectLatch = ctx.async(); - subscriber.connect(ctx.asyncAssertSuccess(v -> connectLatch.complete())); + subscriber.connect().onComplete(ctx.asyncAssertSuccess(v -> connectLatch.complete())); connectLatch.awaitSuccess(10000); - subscriber.actualConnection().query("NOTIFY " + quotedChannel1Name + ", 'msg1'").execute(ctx.asyncAssertSuccess()); - subscriber.actualConnection().query("NOTIFY " + quotedChannel2Name + ", 'msg2'").execute(ctx.asyncAssertSuccess()); + subscriber + .actualConnection() + .query("NOTIFY " + quotedChannel1Name + ", 'msg1'") + .execute() + .onComplete(ctx.asyncAssertSuccess()); + subscriber + .actualConnection() + .query("NOTIFY " + quotedChannel2Name + ", 'msg2'") + .execute() + .onComplete(ctx.asyncAssertSuccess()); notifiedLatch.awaitSuccess(10000); } @@ -143,7 +153,7 @@ public void testSubscribe(TestContext ctx, String channelName) { String quotedChannelName = "\"" + channelName.replace("\"", "\"\"") + "\""; subscriber = PgSubscriber.subscriber(vertx, options); Async connectLatch = ctx.async(); - subscriber.connect(ctx.asyncAssertSuccess(v -> connectLatch.complete())); + subscriber.connect().onComplete(ctx.asyncAssertSuccess(v -> connectLatch.complete())); connectLatch.awaitSuccess(10000); PgChannel channel = subscriber.channel(channelName); Async subscribedLatch = ctx.async(); @@ -154,7 +164,11 @@ public void testSubscribe(TestContext ctx, String channelName) { notifiedLatch.countDown(); }); subscribedLatch.awaitSuccess(10000); - subscriber.actualConnection().query("NOTIFY " + quotedChannelName + ", 'msg'").execute(ctx.asyncAssertSuccess()); + subscriber + .actualConnection() + .query("NOTIFY " + quotedChannelName + ", 'msg'") + .execute() + .onComplete(ctx.asyncAssertSuccess()); notifiedLatch.awaitSuccess(10000); } @@ -162,7 +176,7 @@ public void testSubscribe(TestContext ctx, String channelName) { public void testSubscribeNotifyWithUnquotedId(TestContext ctx) { subscriber = PgSubscriber.subscriber(vertx, options); Async connectLatch = ctx.async(); - subscriber.connect(ctx.asyncAssertSuccess(v -> connectLatch.complete())); + subscriber.connect().onComplete(ctx.asyncAssertSuccess(v -> connectLatch.complete())); connectLatch.awaitSuccess(10000); PgChannel channel = subscriber.channel("the_channel"); Async subscribedLatch = ctx.async(); @@ -173,7 +187,11 @@ public void testSubscribeNotifyWithUnquotedId(TestContext ctx) { notifiedLatch.countDown(); }); subscribedLatch.awaitSuccess(10000); - subscriber.actualConnection().query("NOTIFY The_Channel, 'msg'").execute(ctx.asyncAssertSuccess()); + subscriber + .actualConnection() + .query("NOTIFY The_Channel, 'msg'") + .execute() + .onComplete(ctx.asyncAssertSuccess()); notifiedLatch.awaitSuccess(10000); } @@ -190,7 +208,7 @@ public void testUnsubscribeChannelRequiresQuotedID(TestContext ctx) { public void testUnsubscribe(TestContext ctx, String channelName) { subscriber = PgSubscriber.subscriber(vertx, options); Async connectLatch = ctx.async(); - subscriber.connect(ctx.asyncAssertSuccess(v -> connectLatch.complete())); + subscriber.connect().onComplete(ctx.asyncAssertSuccess(v -> connectLatch.complete())); connectLatch.awaitSuccess(10000); PgChannel sub = subscriber.channel("the_channel"); Async endLatch = ctx.async(); @@ -256,7 +274,7 @@ public void testReconnect(TestContext ctx, long delay, String channelName) { break; } }); - subscriber.connect(ar -> { }); + subscriber.connect(); sub.handler(notif -> { }); connect1Latch.awaitSuccess(10000); AtomicInteger count = new AtomicInteger(); @@ -299,7 +317,7 @@ public void testClose(TestContext ctx, String channelName) { sub.handler(notif -> { }); Async connectLatch = ctx.async(); - subscriber.connect(ctx.asyncAssertSuccess(v -> connectLatch.complete())); + subscriber.connect().onComplete(ctx.asyncAssertSuccess(v -> connectLatch.complete())); connectLatch.awaitSuccess(10000); Async closeLatch = ctx.async(); subscriber.closeHandler(v -> closeLatch.complete()); diff --git a/vertx-pg-client/src/test/java/io/vertx/pgclient/RowTest.java b/vertx-pg-client/src/test/java/io/vertx/pgclient/RowTest.java index 195bc7579..d76d1a1f1 100644 --- a/vertx-pg-client/src/test/java/io/vertx/pgclient/RowTest.java +++ b/vertx-pg-client/src/test/java/io/vertx/pgclient/RowTest.java @@ -55,7 +55,7 @@ public void setup() throws Exception { @After public void teardown(TestContext ctx) { - vertx.close(ctx.asyncAssertSuccess()); + vertx.close().onComplete(ctx.asyncAssertSuccess()); } private static Function accessor(Row row, Class type) { @@ -81,9 +81,11 @@ private static Function arrayAccessor(Row row, Class type) { @Test public void testGetNonExistingRows(TestContext ctx) { Async async = ctx.async(); - PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.query("SELECT 1 \"foo\"").execute( - ctx.asyncAssertSuccess(result -> { + PgConnection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> { + conn + .query("SELECT 1 \"foo\"") + .execute() + .onComplete(ctx.asyncAssertSuccess(result -> { Row row = result.iterator().next(); List> functions = Arrays.asList( row::getValue, @@ -156,9 +158,11 @@ public void testGetNonExistingRows(TestContext ctx) { @Test public void testGetColumnNameRows(TestContext ctx) { Async async = ctx.async(); - PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.query("SELECT 2 \"foo\"").execute( - ctx.asyncAssertSuccess(result -> { + PgConnection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> { + conn + .query("SELECT 2 \"foo\"") + .execute() + .onComplete(ctx.asyncAssertSuccess(result -> { Row row = result.iterator().next(); ctx.assertEquals("foo",row.getColumnName(0)); async.complete(); @@ -169,9 +173,11 @@ public void testGetColumnNameRows(TestContext ctx) { @Test public void testNotEqualGetColumnNameRows(TestContext ctx) { Async async = ctx.async(); - PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.query("SELECT 2 \"foo\"").execute( - ctx.asyncAssertSuccess(result -> { + PgConnection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> { + conn + .query("SELECT 2 \"foo\"") + .execute() + .onComplete(ctx.asyncAssertSuccess(result -> { Row row = result.iterator().next(); ctx.assertNotEquals("bar",row.getColumnName(0)); async.complete(); @@ -182,9 +188,11 @@ public void testNotEqualGetColumnNameRows(TestContext ctx) { @Test public void testNegativeGetColumnNameRows(TestContext ctx) { Async async = ctx.async(); - PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.query("SELECT 2 \"foo\"").execute( - ctx.asyncAssertSuccess(result -> { + PgConnection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> { + conn + .query("SELECT 2 \"foo\"") + .execute() + .onComplete(ctx.asyncAssertSuccess(result -> { Row row = result.iterator().next(); ctx.assertNull(row.getColumnName(-1)); async.complete(); @@ -195,9 +203,11 @@ public void testNegativeGetColumnNameRows(TestContext ctx) { @Test public void testPreventLengthMaxIndexOutOfBoundGetColumnNameRows(TestContext ctx) { Async async = ctx.async(); - PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.query("SELECT 2 \"foo\"").execute( - ctx.asyncAssertSuccess(result -> { + PgConnection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> { + conn + .query("SELECT 2 \"foo\"") + .execute() + .onComplete(ctx.asyncAssertSuccess(result -> { Row row = result.iterator().next(); ctx.assertNull(row.getColumnName(1)); async.complete(); @@ -208,8 +218,9 @@ public void testPreventLengthMaxIndexOutOfBoundGetColumnNameRows(TestContext ctx @Test public void testToJsonObject(TestContext ctx) { Async async = ctx.async(); - PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.query("SELECT " + + PgConnection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> { + conn + .query("SELECT " + "2::smallint \"small_int\"," + "2::integer \"integer\"," + "2::bigint \"bigint\"," + @@ -226,8 +237,9 @@ public void testToJsonObject(TestContext ctx) { "E'\\\\x010203'::bytea \"buffer\"," + "'a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11'::uuid \"uuid\"," + "ARRAY[1, 2, 3] \"array\"" - ).execute( - ctx.asyncAssertSuccess(result -> { + ) + .execute() + .onComplete(ctx.asyncAssertSuccess(result -> { Row row = result.iterator().next(); JsonObject json = row.toJson(); ctx.assertEquals((short)2, json.getValue("small_int")); diff --git a/vertx-pg-client/src/test/java/io/vertx/pgclient/SharedPoolTest.java b/vertx-pg-client/src/test/java/io/vertx/pgclient/SharedPoolTest.java index 2c3a66a72..971318a29 100644 --- a/vertx-pg-client/src/test/java/io/vertx/pgclient/SharedPoolTest.java +++ b/vertx-pg-client/src/test/java/io/vertx/pgclient/SharedPoolTest.java @@ -43,7 +43,7 @@ public void setup() throws Exception { @After public void tearDown(TestContext ctx) { - vertx.close(ctx.asyncAssertSuccess()); + vertx.close().onComplete(ctx.asyncAssertSuccess()); } @Test @@ -57,11 +57,12 @@ public void start() { pool = PgPool.pool(vertx, options, new PoolOptions().setMaxSize(maxSize).setShared(true)); pool .query("SELECT pg_sleep(0.5);SELECT count(*) FROM pg_stat_activity WHERE application_name LIKE '%vertx%'") - .execute(ctx.asyncAssertSuccess(rows -> { + .execute() + .onComplete(ctx.asyncAssertSuccess(rows -> { ctx.assertTrue(rows.next().iterator().next().getInteger(0) <= maxSize); })); } - }, new DeploymentOptions().setInstances(instances), ctx.asyncAssertSuccess()); + }, new DeploymentOptions().setInstances(instances)).onComplete(ctx.asyncAssertSuccess()); } @Test @@ -78,9 +79,10 @@ public void start() { pool = PgPool.pool(vertx, options, new PoolOptions().setMaxSize(maxSize).setShared(true)); pool .query("SELECT 1") - .execute(ctx.asyncAssertSuccess(res -> latch.countDown())); + .execute() + .onComplete(ctx.asyncAssertSuccess(res -> latch.countDown())); } - }, new DeploymentOptions().setInstances(instances), ctx.asyncAssertSuccess(deployment::set)); + }, new DeploymentOptions().setInstances(instances)).onComplete(ctx.asyncAssertSuccess(deployment::set)); latch.awaitSuccess(20_000); vertx.undeploy(deployment.get()) .compose(v -> PgConnection.connect(vertx, options)) @@ -121,10 +123,11 @@ public void start(Promise startPromise) { .mapEmpty() .onComplete(startPromise); } - }, new DeploymentOptions().setInstances(instances), ctx.asyncAssertSuccess(id -> { + }, new DeploymentOptions().setInstances(instances)).onComplete(ctx.asyncAssertSuccess(id -> { pool .query(COUNT_CONNECTIONS_QUERY) - .execute(ctx.asyncAssertSuccess(res1 -> { + .execute() + .onComplete(ctx.asyncAssertSuccess(res1 -> { int num1 = res1.iterator().next().getInteger(0); ctx.assertTrue(num1 <= maxSize); vertx.undeploy(id) diff --git a/vertx-pg-client/src/test/java/io/vertx/pgclient/TLSTest.java b/vertx-pg-client/src/test/java/io/vertx/pgclient/TLSTest.java index 77b1b2e32..9f7d34cfe 100644 --- a/vertx-pg-client/src/test/java/io/vertx/pgclient/TLSTest.java +++ b/vertx-pg-client/src/test/java/io/vertx/pgclient/TLSTest.java @@ -45,7 +45,7 @@ public void setup() { @After public void teardown(TestContext ctx) { - vertx.close(ctx.asyncAssertSuccess()); + vertx.close().onComplete(ctx.asyncAssertSuccess()); } @Test @@ -55,11 +55,12 @@ public void testTLS(TestContext ctx) { PgConnectOptions options = new PgConnectOptions(rule.options()) .setSslMode(SslMode.REQUIRE) .setPemTrustOptions(new PemTrustOptions().addCertPath("tls/server.crt")); - PgConnection.connect(vertx, options.setSslMode(SslMode.REQUIRE), ctx.asyncAssertSuccess(conn -> { + PgConnection.connect(vertx, options.setSslMode(SslMode.REQUIRE)).onComplete(ctx.asyncAssertSuccess(conn -> { ctx.assertTrue(conn.isSSL()); conn .query("SELECT * FROM Fortune WHERE id=1") - .execute(ctx.asyncAssertSuccess(result -> { + .execute() + .onComplete(ctx.asyncAssertSuccess(result -> { ctx.assertEquals(1, result.size()); Tuple row = result.iterator().next(); ctx.assertEquals(1, row.getInteger(0)); @@ -72,7 +73,7 @@ public void testTLS(TestContext ctx) { @Test public void testTLSTrustAll(TestContext ctx) { Async async = ctx.async(); - PgConnection.connect(vertx, rule.options().setSslMode(SslMode.REQUIRE).setTrustAll(true), ctx.asyncAssertSuccess(conn -> { + PgConnection.connect(vertx, rule.options().setSslMode(SslMode.REQUIRE).setTrustAll(true)).onComplete(ctx.asyncAssertSuccess(conn -> { ctx.assertTrue(conn.isSSL()); async.complete(); })); @@ -81,7 +82,7 @@ public void testTLSTrustAll(TestContext ctx) { @Test public void testTLSInvalidCertificate(TestContext ctx) { Async async = ctx.async(); - PgConnection.connect(vertx, rule.options().setSslMode(SslMode.REQUIRE), ctx.asyncAssertFailure(err -> { + PgConnection.connect(vertx, rule.options().setSslMode(SslMode.REQUIRE)).onComplete(ctx.asyncAssertFailure(err -> { // ctx.assertEquals(err.getClass(), VertxException.class); ctx.assertEquals(err.getMessage(), "SSL handshake failed"); async.complete(); @@ -93,7 +94,7 @@ public void testSslModeDisable(TestContext ctx) { Async async = ctx.async(); PgConnectOptions options = rule.options() .setSslMode(SslMode.DISABLE); - PgConnection.connect(vertx, new PgConnectOptions(options), ctx.asyncAssertSuccess(conn -> { + PgConnection.connect(vertx, new PgConnectOptions(options)).onComplete(ctx.asyncAssertSuccess(conn -> { ctx.assertFalse(conn.isSSL()); async.complete(); })); @@ -104,7 +105,7 @@ public void testSslModeAllow(TestContext ctx) { Async async = ctx.async(); PgConnectOptions options = rule.options() .setSslMode(SslMode.ALLOW); - PgConnection.connect(vertx, new PgConnectOptions(options), ctx.asyncAssertSuccess(conn -> { + PgConnection.connect(vertx, new PgConnectOptions(options)).onComplete(ctx.asyncAssertSuccess(conn -> { ctx.assertFalse(conn.isSSL()); async.complete(); })); @@ -116,7 +117,7 @@ public void testSslModePrefer(TestContext ctx) { PgConnectOptions options = rule.options() .setSslMode(SslMode.PREFER) .setTrustAll(true); - PgConnection.connect(vertx, new PgConnectOptions(options), ctx.asyncAssertSuccess(conn -> { + PgConnection.connect(vertx, new PgConnectOptions(options)).onComplete(ctx.asyncAssertSuccess(conn -> { ctx.assertTrue(conn.isSSL()); async.complete(); })); @@ -127,7 +128,7 @@ public void testSslModeVerifyCaConf(TestContext ctx) { PgConnectOptions options = rule.options() .setSslMode(SslMode.VERIFY_CA) .setTrustAll(true); - PgConnection.connect(vertx, new PgConnectOptions(options), ctx.asyncAssertFailure(error -> { + PgConnection.connect(vertx, new PgConnectOptions(options)).onComplete(ctx.asyncAssertFailure(error -> { ctx.assertEquals("Trust options must be specified under verify-full or verify-ca sslmode", error.getMessage()); })); } @@ -136,7 +137,7 @@ public void testSslModeVerifyCaConf(TestContext ctx) { public void testSslModeVerifyFullConf(TestContext ctx) { PgConnectOptions options = rule.options() .setSslMode(SslMode.VERIFY_FULL); - PgConnection.connect(vertx, new PgConnectOptions(options), ctx.asyncAssertFailure(error -> { + PgConnection.connect(vertx, new PgConnectOptions(options)).onComplete(ctx.asyncAssertFailure(error -> { ctx.assertEquals("Host verification algorithm must be specified under verify-full sslmode", error.getMessage()); })); } diff --git a/vertx-pg-client/src/test/java/io/vertx/pgclient/UnixDomainSocketTest.java b/vertx-pg-client/src/test/java/io/vertx/pgclient/UnixDomainSocketTest.java index 67f455395..2f9eacb90 100644 --- a/vertx-pg-client/src/test/java/io/vertx/pgclient/UnixDomainSocketTest.java +++ b/vertx-pg-client/src/test/java/io/vertx/pgclient/UnixDomainSocketTest.java @@ -23,6 +23,7 @@ import io.vertx.ext.unit.TestContext; import io.vertx.ext.unit.junit.VertxUnitRunner; import io.vertx.sqlclient.PoolOptions; +import io.vertx.sqlclient.SqlClient; import io.vertx.sqlclient.impl.ConnectionFactoryBase; import org.junit.*; import org.junit.runner.RunWith; @@ -64,7 +65,7 @@ public void before() { @After public void after(TestContext ctx) { if (client != null) { - client.close(ctx.asyncAssertSuccess()); + client.close().onComplete(ctx.asyncAssertSuccess()); } } @@ -73,14 +74,18 @@ public void uriTest(TestContext context) { assumeTrue(options.isUsingDomainSocket()); String uri = "postgresql://postgres:postgres@/postgres?host=" + options.getHost() + "&port=" + options.getPort(); client = PgPool.pool(uri); - client.getConnection(context.asyncAssertSuccess(pgConnection -> pgConnection.close())); + client + .getConnection() + .onComplete(context.asyncAssertSuccess(SqlClient::close)); } @Test public void simpleConnect(TestContext context) { assumeTrue(options.isUsingDomainSocket()); client = PgPool.pool(new PgConnectOptions(options), new PoolOptions()); - client.getConnection(context.asyncAssertSuccess(pgConnection -> pgConnection.close(context.asyncAssertSuccess()))); + client + .getConnection() + .onComplete(context.asyncAssertSuccess(pgConnection -> pgConnection.close().onComplete(context.asyncAssertSuccess()))); } @Test @@ -90,7 +95,9 @@ public void connectWithVertxInstance(TestContext context) { try { client = PgPool.pool(vertx, new PgConnectOptions(options), new PoolOptions()); Async async = context.async(); - client.getConnection(context.asyncAssertSuccess(pgConnection -> { + client + .getConnection() + .onComplete(context.asyncAssertSuccess(pgConnection -> { async.complete(); pgConnection.close(); })); @@ -104,7 +111,9 @@ public void connectWithVertxInstance(TestContext context) { public void testIgnoreSslMode(TestContext context) { assumeTrue(options.isUsingDomainSocket()); client = PgPool.pool(new PgConnectOptions(options).setSslMode(SslMode.REQUIRE), new PoolOptions()); - client.getConnection(context.asyncAssertSuccess(pgConnection -> { + client + .getConnection() + .onComplete(context.asyncAssertSuccess(pgConnection -> { assertFalse(pgConnection.isSSL()); pgConnection.close(); })); diff --git a/vertx-pg-client/src/test/java/io/vertx/pgclient/context/ContextTest.java b/vertx-pg-client/src/test/java/io/vertx/pgclient/context/ContextTest.java index 1641b9e9b..83210b519 100644 --- a/vertx-pg-client/src/test/java/io/vertx/pgclient/context/ContextTest.java +++ b/vertx-pg-client/src/test/java/io/vertx/pgclient/context/ContextTest.java @@ -24,7 +24,7 @@ public void setup() throws Exception { @After public void teardown(TestContext ctx) { - vertx.close(ctx.asyncAssertSuccess()); + vertx.close().onComplete(ctx.asyncAssertSuccess()); } protected abstract Context createContext(); @@ -34,11 +34,12 @@ public void testConnection(TestContext testCtx) { Async async = testCtx.async(); Context connCtx = createContext(); connCtx.runOnContext(v1 -> { - PgConnection.connect(vertx, options, testCtx.asyncAssertSuccess(conn -> { + PgConnection.connect(vertx, options).onComplete(testCtx.asyncAssertSuccess(conn -> { testCtx.assertEquals(connCtx, Vertx.currentContext()); conn .query("SELECT * FROM (VALUES ('Hello world')) t1 (col1) WHERE 1 = 1") - .execute(testCtx.asyncAssertSuccess(result -> { + .execute() + .onComplete(testCtx.asyncAssertSuccess(result -> { testCtx.assertEquals(connCtx, Vertx.currentContext()); async.complete(); })); @@ -54,11 +55,12 @@ public void testPooledConnection(TestContext testCtx) { connCtx.runOnContext(v1 -> { PgPool pool = PgPool.pool(vertx, options, new PoolOptions()); appCtx.runOnContext(v -> { - pool.getConnection(testCtx.asyncAssertSuccess(conn -> { + pool.getConnection().onComplete(testCtx.asyncAssertSuccess(conn -> { testCtx.assertEquals(appCtx, Vertx.currentContext()); conn .query("SELECT * FROM (VALUES ('Hello world')) t1 (col1) WHERE 1 = 1") - .execute(testCtx.asyncAssertSuccess(result -> { + .execute() + .onComplete(testCtx.asyncAssertSuccess(result -> { testCtx.assertEquals(appCtx, Vertx.currentContext()); async.complete(); })); @@ -77,7 +79,8 @@ public void testPoolQuery(TestContext testCtx) { appCtx.runOnContext(v -> { pool .query("SELECT * FROM (VALUES ('Hello world')) t1 (col1) WHERE 1 = 1") - .execute(testCtx.asyncAssertSuccess(result -> { + .execute() + .onComplete(testCtx.asyncAssertSuccess(result -> { testCtx.assertEquals(appCtx, Vertx.currentContext()); async.complete(); })); diff --git a/vertx-pg-client/src/test/java/io/vertx/pgclient/data/BinaryDataTypesExtendedCodecTest.java b/vertx-pg-client/src/test/java/io/vertx/pgclient/data/BinaryDataTypesExtendedCodecTest.java index bab9bee72..6a5555cdc 100644 --- a/vertx-pg-client/src/test/java/io/vertx/pgclient/data/BinaryDataTypesExtendedCodecTest.java +++ b/vertx-pg-client/src/test/java/io/vertx/pgclient/data/BinaryDataTypesExtendedCodecTest.java @@ -22,10 +22,12 @@ public void testBytea(TestContext ctx) { byte[] bytes = new byte[len]; r.nextBytes(bytes); Async async = ctx.async(); - PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.prepare("SELECT $1::BYTEA \"Bytea\"", + PgConnection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> { + conn.prepare("SELECT $1::BYTEA \"Bytea\"").onComplete( ctx.asyncAssertSuccess(p -> { - p.query().execute(Tuple.of(Buffer.buffer(bytes)), ctx.asyncAssertSuccess(result -> { + p.query() + .execute(Tuple.of(Buffer.buffer(bytes))) + .onComplete(ctx.asyncAssertSuccess(result -> { ColumnChecker.checkColumn(0, "Bytea") .returns(Tuple::getValue, Row::getValue, Buffer.buffer(bytes)) .returns(Tuple::getBuffer, Row::getBuffer, buffer -> { @@ -46,10 +48,10 @@ public void testBufferArray(TestContext ctx) { byte[] bytes = new byte[len]; r.nextBytes(bytes); Async async = ctx.async(); - PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.prepare("SELECT ARRAY[$1::BYTEA] \"Bytea\"", + PgConnection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> { + conn.prepare("SELECT ARRAY[$1::BYTEA] \"Bytea\"").onComplete( ctx.asyncAssertSuccess(p -> { - p.query().execute(Tuple.of(Buffer.buffer(bytes)), ctx.asyncAssertSuccess(result -> { + p.query().execute(Tuple.of(Buffer.buffer(bytes))).onComplete(ctx.asyncAssertSuccess(result -> { ColumnChecker.checkColumn(0, "Bytea") .returns(Tuple::getValue, Row::getValue, new Buffer[]{Buffer.buffer(bytes)}) .returns(Tuple::getArrayOfBuffers, Row::getArrayOfBuffers, new Buffer[]{Buffer.buffer(bytes)}) diff --git a/vertx-pg-client/src/test/java/io/vertx/pgclient/data/BooleanTypeExtendedCodecTest.java b/vertx-pg-client/src/test/java/io/vertx/pgclient/data/BooleanTypeExtendedCodecTest.java index fa57085c8..5fdf9bbd6 100644 --- a/vertx-pg-client/src/test/java/io/vertx/pgclient/data/BooleanTypeExtendedCodecTest.java +++ b/vertx-pg-client/src/test/java/io/vertx/pgclient/data/BooleanTypeExtendedCodecTest.java @@ -18,13 +18,13 @@ public void testDecodeBoolean(TestContext ctx) { @Test public void testEncodeBoolean(TestContext ctx) { Async async = ctx.async(); - PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.prepare("UPDATE \"NumericDataType\" SET \"Boolean\" = $1 WHERE \"id\" = $2 RETURNING \"Boolean\"", + PgConnection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> { + conn.prepare("UPDATE \"NumericDataType\" SET \"Boolean\" = $1 WHERE \"id\" = $2 RETURNING \"Boolean\"").onComplete( ctx.asyncAssertSuccess(p -> { - p.query().execute(Tuple.tuple() - .addBoolean(Boolean.FALSE) - .addInteger(2) - , ctx.asyncAssertSuccess(result -> { + p.query() + .execute(Tuple.tuple().addBoolean(Boolean.FALSE).addInteger(2)) + .onComplete( + ctx.asyncAssertSuccess(result -> { ctx.assertEquals(1, result.size()); ctx.assertEquals(1, result.rowCount()); Row row = result.iterator().next(); @@ -46,11 +46,12 @@ public void testDecodeBooleanArray(TestContext ctx) { @Test public void testDecodeBooleanArray_(TestContext ctx) { Async async = ctx.async(); - PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.prepare("SELECT \"Boolean\" FROM \"ArrayDataType\" WHERE \"id\" = $1", + PgConnection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> { + conn.prepare("SELECT \"Boolean\" FROM \"ArrayDataType\" WHERE \"id\" = $1").onComplete( ctx.asyncAssertSuccess(p -> { - p.query().execute(Tuple.tuple() - .addInteger(1), ctx.asyncAssertSuccess(result -> { + p.query() + .execute(Tuple.tuple().addInteger(1)) + .onComplete(ctx.asyncAssertSuccess(result -> { ColumnChecker.checkColumn(0, "Boolean") .returns(Tuple::getValue, Row::getValue, ColumnChecker.toObjectArray(new boolean[]{Boolean.TRUE})) .returns(Tuple::getArrayOfBooleans, Row::getArrayOfBooleans, ColumnChecker.toObjectArray(new boolean[]{Boolean.TRUE})) @@ -64,13 +65,12 @@ public void testDecodeBooleanArray_(TestContext ctx) { @Test public void testEncodeBooleanArray(TestContext ctx) { Async async = ctx.async(); - PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.prepare("UPDATE \"ArrayDataType\" SET \"Boolean\" = $1 WHERE \"id\" = $2 RETURNING \"Boolean\"", + PgConnection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> { + conn.prepare("UPDATE \"ArrayDataType\" SET \"Boolean\" = $1 WHERE \"id\" = $2 RETURNING \"Boolean\"").onComplete( ctx.asyncAssertSuccess(p -> { - p.query().execute(Tuple.tuple() - .addArrayOfBoolean(new Boolean[]{Boolean.FALSE, Boolean.TRUE}) - .addInteger(2) - , ctx.asyncAssertSuccess(result -> { + p.query() + .execute(Tuple.tuple().addArrayOfBoolean(new Boolean[]{Boolean.FALSE, Boolean.TRUE}).addInteger(2)) + .onComplete(ctx.asyncAssertSuccess(result -> { ColumnChecker.checkColumn(0, "Boolean") .returns(Tuple::getValue, Row::getValue, ColumnChecker.toObjectArray(new boolean[]{Boolean.FALSE, Boolean.TRUE})) .returns(Tuple::getArrayOfBooleans, Row::getArrayOfBooleans, ColumnChecker.toObjectArray(new boolean[]{Boolean.FALSE, Boolean.TRUE})) diff --git a/vertx-pg-client/src/test/java/io/vertx/pgclient/data/CharacterTypesExtendedCodecTest.java b/vertx-pg-client/src/test/java/io/vertx/pgclient/data/CharacterTypesExtendedCodecTest.java index 35939eff2..b30d10cf4 100644 --- a/vertx-pg-client/src/test/java/io/vertx/pgclient/data/CharacterTypesExtendedCodecTest.java +++ b/vertx-pg-client/src/test/java/io/vertx/pgclient/data/CharacterTypesExtendedCodecTest.java @@ -18,12 +18,12 @@ public void testDecodeName(TestContext ctx) { @Test public void testEncodeName(TestContext ctx) { Async async = ctx.async(); - PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.prepare("UPDATE \"CharacterDataType\" SET \"Name\" = upper($1) WHERE \"id\" = $2 RETURNING \"Name\"", + PgConnection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> { + conn.prepare("UPDATE \"CharacterDataType\" SET \"Name\" = upper($1) WHERE \"id\" = $2 RETURNING \"Name\"").onComplete( ctx.asyncAssertSuccess(p -> { - p.query().execute(Tuple.tuple() - .addString("vert.x") - .addInteger(2), ctx.asyncAssertSuccess(result -> { + p.query() + .execute(Tuple.tuple().addString("vert.x").addInteger(2)) + .onComplete(ctx.asyncAssertSuccess(result -> { ctx.assertEquals(1, result.size()); ctx.assertEquals(1, result.rowCount()); Row row = result.iterator().next(); @@ -46,12 +46,12 @@ public void testDecodeChar(TestContext ctx) { @Test public void testEncodeChar(TestContext ctx) { Async async = ctx.async(); - PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.prepare("UPDATE \"CharacterDataType\" SET \"SingleChar\" = upper($1) WHERE \"id\" = $2 RETURNING \"SingleChar\"", + PgConnection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> { + conn.prepare("UPDATE \"CharacterDataType\" SET \"SingleChar\" = upper($1) WHERE \"id\" = $2 RETURNING \"SingleChar\"").onComplete( ctx.asyncAssertSuccess(p -> { - p.query().execute(Tuple.tuple() - .addString("b") - .addInteger(2), ctx.asyncAssertSuccess(result -> { + p.query() + .execute(Tuple.tuple().addString("b").addInteger(2)) + .onComplete(ctx.asyncAssertSuccess(result -> { ctx.assertEquals(1, result.size()); ctx.assertEquals(1, result.rowCount()); Row row = result.iterator().next(); @@ -74,12 +74,12 @@ public void testDecodeFixedChar(TestContext ctx) { @Test public void testEncodeFixedChar(TestContext ctx) { Async async = ctx.async(); - PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.prepare("UPDATE \"CharacterDataType\" SET \"FixedChar\" = upper($1) WHERE \"id\" = $2 RETURNING \"FixedChar\"", + PgConnection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> { + conn.prepare("UPDATE \"CharacterDataType\" SET \"FixedChar\" = upper($1) WHERE \"id\" = $2 RETURNING \"FixedChar\"").onComplete( ctx.asyncAssertSuccess(p -> { - p.query().execute(Tuple.tuple() - .addString("no") - .addInteger(2), ctx.asyncAssertSuccess(result -> { + p.query() + .execute(Tuple.tuple().addString("no").addInteger(2)) + .onComplete(ctx.asyncAssertSuccess(result -> { ctx.assertEquals(1, result.size()); ctx.assertEquals(1, result.rowCount()); Row row = result.iterator().next(); @@ -102,12 +102,12 @@ public void testDecodeText(TestContext ctx) { @Test public void testEncodeText(TestContext ctx) { Async async = ctx.async(); - PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.prepare("UPDATE \"CharacterDataType\" SET \"Text\" = upper($1) WHERE \"id\" = $2 RETURNING \"Text\"", + PgConnection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> { + conn.prepare("UPDATE \"CharacterDataType\" SET \"Text\" = upper($1) WHERE \"id\" = $2 RETURNING \"Text\"").onComplete( ctx.asyncAssertSuccess(p -> { - p.query().execute(Tuple.tuple() - .addString("Hello World") - .addInteger(2), ctx.asyncAssertSuccess(result -> { + p.query() + .execute(Tuple.tuple().addString("Hello World").addInteger(2)) + .onComplete(ctx.asyncAssertSuccess(result -> { ctx.assertEquals(1, result.size()); ctx.assertEquals(1, result.rowCount()); Row row = result.iterator().next(); @@ -130,12 +130,12 @@ public void testDecodeVarchar(TestContext ctx) { @Test public void testEncodeVarCharacter(TestContext ctx) { Async async = ctx.async(); - PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.prepare("UPDATE \"CharacterDataType\" SET \"VarCharacter\" = upper($1) WHERE \"id\" = $2 RETURNING \"VarCharacter\"", + PgConnection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> { + conn.prepare("UPDATE \"CharacterDataType\" SET \"VarCharacter\" = upper($1) WHERE \"id\" = $2 RETURNING \"VarCharacter\"").onComplete( ctx.asyncAssertSuccess(p -> { - p.query().execute(Tuple.tuple() - .addString("Great!") - .addInteger(2), ctx.asyncAssertSuccess(result -> { + p.query() + .execute(Tuple.tuple().addString("Great!").addInteger(2)) + .onComplete(ctx.asyncAssertSuccess(result -> { ctx.assertEquals(1, result.size()); ctx.assertEquals(1, result.rowCount()); Row row = result.iterator().next(); @@ -159,10 +159,12 @@ public void testEncodeLargeVarchar(TestContext ctx) { } String value = builder.toString(); Async async = ctx.async(); - PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.prepare("SELECT $1::VARCHAR(" + len + ")", + PgConnection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> { + conn.prepare("SELECT $1::VARCHAR(" + len + ")").onComplete( ctx.asyncAssertSuccess(p -> { - p.query().execute(Tuple.of(value), ctx.asyncAssertSuccess(result -> { + p.query() + .execute(Tuple.of(value)) + .onComplete(ctx.asyncAssertSuccess(result -> { ctx.assertEquals(value, result.iterator().next().getString(0)); async.complete(); })); @@ -178,13 +180,12 @@ public void testDecodeTextArray(TestContext ctx) { @Test public void testEncodeStringArray(TestContext ctx) { Async async = ctx.async(); - PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.prepare("UPDATE \"ArrayDataType\" SET \"Text\" = $1 WHERE \"id\" = $2 RETURNING \"Text\"", + PgConnection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> { + conn.prepare("UPDATE \"ArrayDataType\" SET \"Text\" = $1 WHERE \"id\" = $2 RETURNING \"Text\"").onComplete( ctx.asyncAssertSuccess(p -> { - p.query().execute(Tuple.tuple() - .addArrayOfString(new String[]{"Knock, knock.Who’s there?"}) - .addInteger(2) - , ctx.asyncAssertSuccess(result -> { + p.query() + .execute(Tuple.tuple().addArrayOfString(new String[]{"Knock, knock.Who’s there?"}).addInteger(2)) + .onComplete(ctx.asyncAssertSuccess(result -> { ColumnChecker.checkColumn(0, "Text") .returns(Tuple::getValue, Row::getValue, new String[]{"Knock, knock.Who’s there?"}) .returns(Tuple::getArrayOfStrings, Row::getArrayOfStrings, new String[]{"Knock, knock.Who’s there?"}) diff --git a/vertx-pg-client/src/test/java/io/vertx/pgclient/data/CustomTypesExtendedCodecTest.java b/vertx-pg-client/src/test/java/io/vertx/pgclient/data/CustomTypesExtendedCodecTest.java index b5a3d6c35..2822e15c9 100644 --- a/vertx-pg-client/src/test/java/io/vertx/pgclient/data/CustomTypesExtendedCodecTest.java +++ b/vertx-pg-client/src/test/java/io/vertx/pgclient/data/CustomTypesExtendedCodecTest.java @@ -13,13 +13,12 @@ public class CustomTypesExtendedCodecTest extends ExtendedQueryDataTypeCodecTest public void testEncodeCustomType(TestContext ctx) { Async async = ctx.async(); String actual = "('Othercity',\" 'Second Ave'\",f)"; - PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.prepare("UPDATE \"CustomDataType\" SET \"address\" = $1 WHERE \"id\" = $2 RETURNING \"address\"", + PgConnection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> { + conn.prepare("UPDATE \"CustomDataType\" SET \"address\" = $1 WHERE \"id\" = $2 RETURNING \"address\"").onComplete( ctx.asyncAssertSuccess(p -> { - p.query().execute(Tuple.tuple() - .addString("('Othercity', 'Second Ave', false)") - .addInteger(2) - , ctx.asyncAssertSuccess(result -> { + p.query() + .execute(Tuple.tuple().addString("('Othercity', 'Second Ave', false)").addInteger(2)) + .onComplete(ctx.asyncAssertSuccess(result -> { ctx.assertEquals(1, result.size()); ctx.assertEquals(1, result.rowCount()); Row row = result.iterator().next(); diff --git a/vertx-pg-client/src/test/java/io/vertx/pgclient/data/CustomTypesSimpleCodecTest.java b/vertx-pg-client/src/test/java/io/vertx/pgclient/data/CustomTypesSimpleCodecTest.java index ae3e9ada5..b50a01adf 100644 --- a/vertx-pg-client/src/test/java/io/vertx/pgclient/data/CustomTypesSimpleCodecTest.java +++ b/vertx-pg-client/src/test/java/io/vertx/pgclient/data/CustomTypesSimpleCodecTest.java @@ -13,9 +13,11 @@ public class CustomTypesSimpleCodecTest extends SimpleQueryDataTypeCodecTestBase public void testCustomType(TestContext ctx) { Async async = ctx.async(); String expected = "Anytown"; - PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { + PgConnection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> { conn - .query("SELECT (address).city FROM \"CustomDataType\"").execute(ctx.asyncAssertSuccess(result -> { + .query("SELECT (address).city FROM \"CustomDataType\"") + .execute() + .onComplete(ctx.asyncAssertSuccess(result -> { ctx.assertEquals(2, result.size()); Row row = result.iterator().next(); ColumnChecker.checkColumn(0, "city") diff --git a/vertx-pg-client/src/test/java/io/vertx/pgclient/data/DataTypeTestBase.java b/vertx-pg-client/src/test/java/io/vertx/pgclient/data/DataTypeTestBase.java index 1064dd242..d53d46639 100644 --- a/vertx-pg-client/src/test/java/io/vertx/pgclient/data/DataTypeTestBase.java +++ b/vertx-pg-client/src/test/java/io/vertx/pgclient/data/DataTypeTestBase.java @@ -158,6 +158,6 @@ public void setup() throws Exception { @After public void teardown(TestContext ctx) { - vertx.close(ctx.asyncAssertSuccess()); + vertx.close().onComplete(ctx.asyncAssertSuccess()); } } diff --git a/vertx-pg-client/src/test/java/io/vertx/pgclient/data/DateTimeTypesExtendedCodecTest.java b/vertx-pg-client/src/test/java/io/vertx/pgclient/data/DateTimeTypesExtendedCodecTest.java index 2cfb38234..91da3b445 100644 --- a/vertx-pg-client/src/test/java/io/vertx/pgclient/data/DateTimeTypesExtendedCodecTest.java +++ b/vertx-pg-client/src/test/java/io/vertx/pgclient/data/DateTimeTypesExtendedCodecTest.java @@ -35,13 +35,14 @@ public void testDecodeDateMinuxInfinity(TestContext ctx) { @Test public void testEncodeDateBeforePgEpoch(TestContext ctx) { Async async = ctx.async(); - PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.prepare("UPDATE \"TemporalDataType\" SET \"Date\" = $1 WHERE \"id\" = $2 RETURNING \"Date\"", + PgConnection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> { + conn.prepare("UPDATE \"TemporalDataType\" SET \"Date\" = $1 WHERE \"id\" = $2 RETURNING \"Date\"").onComplete( ctx.asyncAssertSuccess(p -> { LocalDate ld = LocalDate.parse("1981-06-30"); - p.query().execute(Tuple.tuple() - .addLocalDate(ld) - .addInteger(1), ctx.asyncAssertSuccess(result -> { + p + .query() + .execute(Tuple.tuple().addLocalDate(ld).addInteger(1)) + .onComplete(ctx.asyncAssertSuccess(result -> { ctx.assertEquals(1, result.size()); ctx.assertEquals(1, result.rowCount()); Row row = result.iterator().next(); @@ -64,14 +65,14 @@ public void testDecodeDateAfterPgEpoch(TestContext ctx) { @Test public void testEncodeDateAfterPgEpoch(TestContext ctx) { Async async = ctx.async(); - PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.prepare("UPDATE \"TemporalDataType\" SET \"Date\" = $1 WHERE \"id\" = $2 RETURNING \"Date\"", + PgConnection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> { + conn.prepare("UPDATE \"TemporalDataType\" SET \"Date\" = $1 WHERE \"id\" = $2 RETURNING \"Date\"").onComplete( ctx.asyncAssertSuccess(p -> { LocalDate ld = LocalDate.parse("2018-05-30"); - p.query().execute(Tuple.tuple() - .addLocalDate(ld) - .addInteger(4) - , ctx.asyncAssertSuccess(result -> { + p + .query() + .execute(Tuple.tuple().addLocalDate(ld).addInteger(4)) + .onComplete(ctx.asyncAssertSuccess(result -> { ctx.assertEquals(1, result.size()); ctx.assertEquals(1, result.rowCount()); Row row = result.iterator().next(); @@ -94,14 +95,14 @@ public void testDecodeTime(TestContext ctx) { @Test public void testEncodeTime(TestContext ctx) { Async async = ctx.async(); - PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.prepare("UPDATE \"TemporalDataType\" SET \"Time\" = $1 WHERE \"id\" = $2 RETURNING \"Time\"", + PgConnection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> { + conn.prepare("UPDATE \"TemporalDataType\" SET \"Time\" = $1 WHERE \"id\" = $2 RETURNING \"Time\"").onComplete( ctx.asyncAssertSuccess(p -> { LocalTime lt = LocalTime.parse("22:55:04.905120"); - p.query().execute(Tuple.tuple() - .addLocalTime(lt) - .addInteger(2) - , ctx.asyncAssertSuccess(result -> { + p + .query() + .execute(Tuple.tuple().addLocalTime(lt).addInteger(2)) + .onComplete(ctx.asyncAssertSuccess(result -> { ctx.assertEquals(1, result.size()); ctx.assertEquals(1, result.rowCount()); Row row = result.iterator().next(); @@ -124,13 +125,14 @@ public void testDecodeTimeTz(TestContext ctx) { @Test public void testEncodeTimeTz(TestContext ctx) { Async async = ctx.async(); - PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.prepare("UPDATE \"TemporalDataType\" SET \"TimeTz\" = $1 WHERE \"id\" = $2 RETURNING \"TimeTz\"", + PgConnection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> { + conn.prepare("UPDATE \"TemporalDataType\" SET \"TimeTz\" = $1 WHERE \"id\" = $2 RETURNING \"TimeTz\"").onComplete( ctx.asyncAssertSuccess(p -> { OffsetTime ot = OffsetTime.parse("20:55:04.905120+03:07"); - p.query().execute(Tuple.tuple() - .addOffsetTime(ot) - .addInteger(2), ctx.asyncAssertSuccess(result -> { + p + .query() + .execute(Tuple.tuple().addOffsetTime(ot).addInteger(2)) + .onComplete(ctx.asyncAssertSuccess(result -> { ctx.assertEquals(1, result.size()); ctx.assertEquals(1, result.rowCount()); Row row = result.iterator().next(); @@ -184,13 +186,12 @@ public void testDecodeTimestampMinusInfinity(TestContext ctx) { @Test public void testEncodeTimestampBeforePgEpoch(TestContext ctx) { Async async = ctx.async(); - PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.prepare("UPDATE \"TemporalDataType\" SET \"Timestamp\" = $1 WHERE \"id\" = $2 RETURNING \"Timestamp\"", + PgConnection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> { + conn.prepare("UPDATE \"TemporalDataType\" SET \"Timestamp\" = $1 WHERE \"id\" = $2 RETURNING \"Timestamp\"").onComplete( ctx.asyncAssertSuccess(p -> { LocalDateTime ldt = LocalDateTime.parse("1900-02-01T23:57:53.237666"); - p.query().execute(Tuple.tuple() - .addLocalDateTime(ldt) - .addInteger(4), ctx.asyncAssertSuccess(result -> { + p.query() + .execute(Tuple.tuple().addLocalDateTime(ldt).addInteger(4)).onComplete(ctx.asyncAssertSuccess(result -> { ctx.assertEquals(1, result.size()); ctx.assertEquals(1, result.rowCount()); Row row = result.iterator().next(); @@ -221,13 +222,12 @@ public void testDecodeTimestampAfterPgEpoch(TestContext ctx) { @Test public void testEncodeTimestampAfterPgEpoch(TestContext ctx) { Async async = ctx.async(); - PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.prepare("UPDATE \"TemporalDataType\" SET \"Timestamp\" =$1 WHERE \"id\" = $2 RETURNING \"Timestamp\"", + PgConnection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> { + conn.prepare("UPDATE \"TemporalDataType\" SET \"Timestamp\" =$1 WHERE \"id\" = $2 RETURNING \"Timestamp\"").onComplete( ctx.asyncAssertSuccess(p -> { - p.query().execute(Tuple.tuple() - .addLocalDateTime(LocalDateTime.parse("2017-05-14T19:35:58.237666")) - .addInteger(2) - , ctx.asyncAssertSuccess(result -> { + p.query() + .execute(Tuple.tuple().addLocalDateTime(LocalDateTime.parse("2017-05-14T19:35:58.237666")).addInteger(2)) + .onComplete(ctx.asyncAssertSuccess(result -> { ctx.assertEquals(1, result.size()); LocalDateTime ldt = LocalDateTime.parse("2017-05-14T19:35:58.237666"); Row row = result.iterator().next(); @@ -289,14 +289,17 @@ public void testDecodeTimestampTzMinusInfinity(TestContext ctx) { @Test public void testEncodeTimestampTzBeforePgEpoch(TestContext ctx) { Async async = ctx.async(); - PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.query("SET TIME ZONE 'UTC'").execute(ctx.asyncAssertSuccess(v -> { - conn.prepare("UPDATE \"TemporalDataType\" SET \"TimestampTz\" =$1 WHERE \"id\" = $2 RETURNING \"TimestampTz\"", + PgConnection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> { + conn + .query("SET TIME ZONE 'UTC'") + .execute() + .onComplete(ctx.asyncAssertSuccess(v -> { + conn.prepare("UPDATE \"TemporalDataType\" SET \"TimestampTz\" =$1 WHERE \"id\" = $2 RETURNING \"TimestampTz\"").onComplete( ctx.asyncAssertSuccess(p -> { - p.query().execute(Tuple.tuple() - .addOffsetDateTime(OffsetDateTime.parse("1800-02-01T23:59:59.237666-03:00")) - .addInteger(3) - , ctx.asyncAssertSuccess(result -> { + p + .query() + .execute(Tuple.tuple().addOffsetDateTime(OffsetDateTime.parse("1800-02-01T23:59:59.237666-03:00")).addInteger(3)) + .onComplete(ctx.asyncAssertSuccess(result -> { OffsetDateTime odt = OffsetDateTime.parse("1800-02-02T02:59:59.237666Z"); ctx.assertEquals(1, result.rowCount()); ctx.assertEquals(1, result.size()); @@ -334,14 +337,17 @@ public void testDecodeTimestampTzAfterPgEpoch(TestContext ctx) { @Test public void testEncodeTimestampTzAfterPgEpoch(TestContext ctx) { Async async = ctx.async(); - PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.query("SET TIME ZONE 'UTC'").execute(ctx.asyncAssertSuccess(v -> { - conn.prepare("UPDATE \"TemporalDataType\" SET \"TimestampTz\" = $1 WHERE \"id\" = $2 RETURNING \"TimestampTz\"", + PgConnection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> { + conn + .query("SET TIME ZONE 'UTC'") + .execute() + .onComplete(ctx.asyncAssertSuccess(v -> { + conn.prepare("UPDATE \"TemporalDataType\" SET \"TimestampTz\" = $1 WHERE \"id\" = $2 RETURNING \"TimestampTz\"").onComplete( ctx.asyncAssertSuccess(p -> { - p.query().execute(Tuple.tuple() - .addOffsetDateTime(OffsetDateTime.parse("2017-06-14T23:59:59.237666-03:00")) - .addInteger(1) - , ctx.asyncAssertSuccess(result -> { + p + .query() + .execute(Tuple.tuple().addOffsetDateTime(OffsetDateTime.parse("2017-06-14T23:59:59.237666-03:00")).addInteger(1)) + .onComplete(ctx.asyncAssertSuccess(result -> { ctx.assertEquals(1, result.size()); ctx.assertEquals(1, result.rowCount()); OffsetDateTime odt = OffsetDateTime.parse("2017-06-15T02:59:59.237666Z"); @@ -374,10 +380,13 @@ public void testDecodeInterval(TestContext ctx) { .microseconds(999999); Async async = ctx.async(); - PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.prepare("SELECT $1 :: INTERVAL \"Interval\"", + PgConnection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> { + conn.prepare("SELECT $1 :: INTERVAL \"Interval\"").onComplete( ctx.asyncAssertSuccess(p -> { - p.query().execute(Tuple.tuple().addValue(interval), ctx.asyncAssertSuccess(result -> { + p + .query() + .execute(Tuple.tuple().addValue(interval)) + .onComplete(ctx.asyncAssertSuccess(result -> { ctx.assertEquals(1, result.size()); ctx.assertEquals(1, result.rowCount()); Row row = result.iterator().next(); @@ -394,8 +403,8 @@ public void testDecodeInterval(TestContext ctx) { @Test public void testEncodeInterval(TestContext ctx) { Async async = ctx.async(); - PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.prepare("UPDATE \"TemporalDataType\" SET \"Interval\" = $1 WHERE \"id\" = $2 RETURNING \"Interval\"", + PgConnection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> { + conn.prepare("UPDATE \"TemporalDataType\" SET \"Interval\" = $1 WHERE \"id\" = $2 RETURNING \"Interval\"").onComplete( ctx.asyncAssertSuccess(p -> { // 2000 years 1 months 403 days 59 hours 35 minutes 13.999998 seconds Interval expected = Interval.of() @@ -406,9 +415,10 @@ public void testEncodeInterval(TestContext ctx) { .minutes(35) .seconds(13) .microseconds(999998); - p.query().execute(Tuple.tuple() - .addValue(expected) - .addInteger(2), ctx.asyncAssertSuccess(result -> { + p + .query() + .execute(Tuple.tuple().addValue(expected).addInteger(2)) + .onComplete(ctx.asyncAssertSuccess(result -> { ctx.assertEquals(1, result.size()); ctx.assertEquals(1, result.rowCount()); Row row = result.iterator().next(); @@ -430,14 +440,14 @@ public void testDecodeLocalDateArray(TestContext ctx) { @Test public void testEncodeLocalDateArray(TestContext ctx) { Async async = ctx.async(); - PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.prepare("UPDATE \"ArrayDataType\" SET \"LocalDate\" = $1 WHERE \"id\" = $2 RETURNING \"LocalDate\"", + PgConnection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> { + conn.prepare("UPDATE \"ArrayDataType\" SET \"LocalDate\" = $1 WHERE \"id\" = $2 RETURNING \"LocalDate\"").onComplete( ctx.asyncAssertSuccess(p -> { final LocalDate dt = LocalDate.parse("1998-05-12"); - p.query().execute(Tuple.tuple() - .addArrayOfLocalDate(new LocalDate[]{dt}) - .addInteger(2) - , ctx.asyncAssertSuccess(result -> { + p + .query() + .execute(Tuple.tuple().addArrayOfLocalDate(new LocalDate[]{dt}).addInteger(2)) + .onComplete(ctx.asyncAssertSuccess(result -> { ColumnChecker.checkColumn(0, "LocalDate") .returns(Tuple::getValue, Row::getValue, new LocalDate[]{dt}) .returns(Tuple::getArrayOfLocalDates, Row::getArrayOfLocalDates, new LocalDate[]{dt}) @@ -456,15 +466,15 @@ public void testDecodeLocalTimeArray(TestContext ctx) { @Test public void testEncodeLocalTimeArray(TestContext ctx) { Async async = ctx.async(); - PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.prepare("UPDATE \"ArrayDataType\" SET \"LocalTime\" = $1 WHERE \"id\" = $2 RETURNING \"LocalTime\"", + PgConnection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> { + conn.prepare("UPDATE \"ArrayDataType\" SET \"LocalTime\" = $1 WHERE \"id\" = $2 RETURNING \"LocalTime\"").onComplete( ctx.asyncAssertSuccess(p -> { final DateTimeFormatter dtf = DateTimeFormatter.ofPattern("HH:mm:ss.SSSSS"); final LocalTime dt = LocalTime.parse("17:55:04.90512", dtf); - p.query().execute(Tuple.tuple() - .addArrayOfLocalTime(new LocalTime[]{dt}) - .addInteger(2) - , ctx.asyncAssertSuccess(result -> { + p + .query() + .execute(Tuple.tuple().addArrayOfLocalTime(new LocalTime[]{dt}).addInteger(2)) + .onComplete(ctx.asyncAssertSuccess(result -> { ColumnChecker.checkColumn(0, "LocalTime") .returns(Tuple::getValue, Row::getValue, new LocalTime[]{dt}) .returns(Tuple::getArrayOfLocalTimes, Row::getArrayOfLocalTimes, new LocalTime[]{dt}) @@ -483,14 +493,14 @@ public void testDecodeOffsetTimeArray(TestContext ctx) { @Test public void testEncodeOffsetTimeArray(TestContext ctx) { Async async = ctx.async(); - PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.prepare("UPDATE \"ArrayDataType\" SET \"OffsetTime\" = $1 WHERE \"id\" = $2 RETURNING \"OffsetTime\"", + PgConnection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> { + conn.prepare("UPDATE \"ArrayDataType\" SET \"OffsetTime\" = $1 WHERE \"id\" = $2 RETURNING \"OffsetTime\"").onComplete( ctx.asyncAssertSuccess(p -> { final OffsetTime dt = OffsetTime.parse("17:56:04.90512+03:07"); - p.query().execute(Tuple.tuple() - .addArrayOfOffsetTime(new OffsetTime[]{dt}) - .addInteger(2) - , ctx.asyncAssertSuccess(result -> { + p + .query() + .execute(Tuple.tuple().addArrayOfOffsetTime(new OffsetTime[]{dt}).addInteger(2)) + .onComplete(ctx.asyncAssertSuccess(result -> { ColumnChecker.checkColumn(0, "OffsetTime") .returns(Tuple::getValue, Row::getValue, new OffsetTime[]{dt}) .returns(Tuple::getArrayOfOffsetTimes, Row::getArrayOfOffsetTimes, new OffsetTime[]{dt}) @@ -509,14 +519,14 @@ public void testDecodeLocalDateTimeArray(TestContext ctx) { @Test public void testEncodeLocalDateTimeArray(TestContext ctx) { Async async = ctx.async(); - PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.prepare("UPDATE \"ArrayDataType\" SET \"LocalDateTime\" = $1 WHERE \"id\" = $2 RETURNING \"LocalDateTime\"", + PgConnection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> { + conn.prepare("UPDATE \"ArrayDataType\" SET \"LocalDateTime\" = $1 WHERE \"id\" = $2 RETURNING \"LocalDateTime\"").onComplete( ctx.asyncAssertSuccess(p -> { final LocalDateTime dt = LocalDateTime.parse("2017-05-14T19:35:58.237666"); - p.query().execute(Tuple.tuple() - .addArrayOfLocalDateTime(new LocalDateTime[]{dt}) - .addInteger(2) - , ctx.asyncAssertSuccess(result -> { + p + .query() + .execute(Tuple.tuple().addArrayOfLocalDateTime(new LocalDateTime[]{dt}).addInteger(2)) + .onComplete(ctx.asyncAssertSuccess(result -> { ColumnChecker.checkColumn(0, "LocalDateTime") .returns(Tuple::getValue, Row::getValue, new LocalDateTime[]{dt}) .returns(Tuple::getArrayOfLocalTimes, Row::getArrayOfLocalTimes, new LocalTime[]{dt.toLocalTime()}) @@ -537,14 +547,14 @@ public void testDecodeOffsetDateTimeArray(TestContext ctx) { @Test public void testEncodeOffsetDateTimeArray(TestContext ctx) { Async async = ctx.async(); - PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.prepare("UPDATE \"ArrayDataType\" SET \"OffsetDateTime\" = $1 WHERE \"id\" = $2 RETURNING \"OffsetDateTime\"", + PgConnection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> { + conn.prepare("UPDATE \"ArrayDataType\" SET \"OffsetDateTime\" = $1 WHERE \"id\" = $2 RETURNING \"OffsetDateTime\"").onComplete( ctx.asyncAssertSuccess(p -> { final OffsetDateTime dt = OffsetDateTime.parse("2017-05-14T19:35:58.237666Z"); - p.query().execute(Tuple.tuple() - .addArrayOfOffsetDateTime(new OffsetDateTime[]{dt}) - .addInteger(2) - , ctx.asyncAssertSuccess(result -> { + p + .query() + .execute(Tuple.tuple().addArrayOfOffsetDateTime(new OffsetDateTime[]{dt}).addInteger(2)) + .onComplete(ctx.asyncAssertSuccess(result -> { ColumnChecker.checkColumn(0, "OffsetDateTime") .returns(Tuple::getValue, Row::getValue, new OffsetDateTime[]{dt}) .returns(Tuple::getArrayOfOffsetTimes, Row::getArrayOfOffsetTimes, new OffsetTime[]{dt.toOffsetTime()}) @@ -564,8 +574,8 @@ public void testDecodeIntervalArray(TestContext ctx) { @Test public void testEncodeIntervalArray(TestContext ctx) { Async async = ctx.async(); - PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.prepare("UPDATE \"ArrayDataType\" SET \"Interval\" = $1 WHERE \"id\" = $2 RETURNING \"Interval\"", + PgConnection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> { + conn.prepare("UPDATE \"ArrayDataType\" SET \"Interval\" = $1 WHERE \"id\" = $2 RETURNING \"Interval\"").onComplete( ctx.asyncAssertSuccess(p -> { Interval[] intervals = new Interval[]{ Interval.of().years(10).months(3).days(332).hours(20).minutes(20).seconds(20).microseconds(999991), @@ -573,10 +583,10 @@ public void testEncodeIntervalArray(TestContext ctx) { Interval.of().years(-2).months(-6), Interval.of() }; - p.query().execute(Tuple.tuple() - .addValue(intervals) - .addInteger(2) - , ctx.asyncAssertSuccess(result -> { + p + .query() + .execute(Tuple.tuple().addValue(intervals).addInteger(2)) + .onComplete(ctx.asyncAssertSuccess(result -> { ColumnChecker.checkColumn(0, "Interval") .returns(Tuple::getValue, Row::getValue, intervals) .returns(Interval.class, intervals) @@ -605,10 +615,13 @@ private void testDecodeDataTimeGeneric(TestContext ctx, ColumnChecker checker, T expected) { Async async = ctx.async(); - PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.prepare("SELECT $1 :: " + dataType + " \"" + columnName + "\"", + PgConnection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> { + conn.prepare("SELECT $1 :: " + dataType + " \"" + columnName + "\"").onComplete( ctx.asyncAssertSuccess(p -> { - p.query().execute(Tuple.tuple().addValue(expected), ctx.asyncAssertSuccess(result -> { + p + .query() + .execute(Tuple.tuple().addValue(expected)) + .onComplete(ctx.asyncAssertSuccess(result -> { ctx.assertEquals(1, result.size()); ctx.assertEquals(1, result.rowCount()); Row row = result.iterator().next(); diff --git a/vertx-pg-client/src/test/java/io/vertx/pgclient/data/DateTimeTypesSimpleCodecTest.java b/vertx-pg-client/src/test/java/io/vertx/pgclient/data/DateTimeTypesSimpleCodecTest.java index a27f52bca..0d3b77a25 100644 --- a/vertx-pg-client/src/test/java/io/vertx/pgclient/data/DateTimeTypesSimpleCodecTest.java +++ b/vertx-pg-client/src/test/java/io/vertx/pgclient/data/DateTimeTypesSimpleCodecTest.java @@ -42,9 +42,15 @@ public void testDateMinusInfinity(TestContext ctx) { private void testDate(TestContext ctx, String value, LocalDate ld) { Async async = ctx.async(); - PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.query("SET TIME ZONE 'UTC'").execute(ctx.asyncAssertSuccess(v -> { - conn.query("SELECT '" + value + "'::DATE \"LocalDate\"").execute(ctx.asyncAssertSuccess(result -> { + PgConnection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> { + conn + .query("SET TIME ZONE 'UTC'") + .execute() + .onComplete(ctx.asyncAssertSuccess(v -> { + conn + .query("SELECT '" + value + "'::DATE \"LocalDate\"") + .execute() + .onComplete(ctx.asyncAssertSuccess(result -> { ctx.assertEquals(1, result.size()); Row row = result.iterator().next(); ColumnChecker.checkColumn(0, "LocalDate") @@ -61,9 +67,11 @@ private void testDate(TestContext ctx, String value, LocalDate ld) { @Test public void testTime(TestContext ctx) { Async async = ctx.async(); - PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { + PgConnection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> { conn - .query("SELECT '17:55:04.905120'::TIME \"LocalTime\"").execute(ctx.asyncAssertSuccess(result -> { + .query("SELECT '17:55:04.905120'::TIME \"LocalTime\"") + .execute() + .onComplete(ctx.asyncAssertSuccess(result -> { LocalTime lt = LocalTime.parse("17:55:04.905120"); ctx.assertEquals(1, result.size()); Row row = result.iterator().next(); @@ -80,9 +88,11 @@ public void testTime(TestContext ctx) { @Test public void testTimeTz(TestContext ctx) { Async async = ctx.async(); - PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { + PgConnection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> { conn - .query("SELECT '17:55:04.90512+03:07'::TIMETZ \"OffsetTime\"").execute(ctx.asyncAssertSuccess(result -> { + .query("SELECT '17:55:04.90512+03:07'::TIMETZ \"OffsetTime\"") + .execute() + .onComplete(ctx.asyncAssertSuccess(result -> { OffsetTime ot = OffsetTime.parse("17:55:04.905120+03:07"); ctx.assertEquals(1, result.size()); Row row = result.iterator().next(); @@ -118,9 +128,11 @@ public void testTimestampMinusInfinity(TestContext ctx) { private void testTimestamp(TestContext ctx, String value, LocalDateTime expected) { Async async = ctx.async(); - PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { + PgConnection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> { conn - .query("SELECT '" + value + "'::TIMESTAMP \"LocalDateTime\"").execute(ctx.asyncAssertSuccess(result -> { + .query("SELECT '" + value + "'::TIMESTAMP \"LocalDateTime\"") + .execute() + .onComplete(ctx.asyncAssertSuccess(result -> { ctx.assertEquals(1, result.size()); Row row = result.iterator().next(); ColumnChecker.checkColumn(0, "LocalDateTime") @@ -157,9 +169,15 @@ public void testTimestampTzMinusInfinity(TestContext ctx) { private void testTimestampTz(TestContext ctx, String value, OffsetDateTime expected) { Async async = ctx.async(); - PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.query("SET TIME ZONE 'UTC'").execute(ctx.asyncAssertSuccess(v -> { - conn.query("SELECT '" + value + "'::TIMESTAMPTZ \"OffsetDateTime\"").execute(ctx.asyncAssertSuccess(result -> { + PgConnection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> { + conn + .query("SET TIME ZONE 'UTC'") + .execute() + .onComplete(ctx.asyncAssertSuccess(v -> { + conn + .query("SELECT '" + value + "'::TIMESTAMPTZ \"OffsetDateTime\"") + .execute() + .onComplete(ctx.asyncAssertSuccess(result -> { ctx.assertEquals(1, result.size()); Row row = result.iterator().next(); ColumnChecker.checkColumn(0, "OffsetDateTime") @@ -180,9 +198,11 @@ private void testTimestampTz(TestContext ctx, String value, OffsetDateTime expec @Test public void testInterval(TestContext ctx) { Async async = ctx.async(); - PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.query("SELECT '10 years 3 months 332 days 20 hours 20 minutes 20.999991 seconds'::INTERVAL \"Interval\"") - .execute(ctx.asyncAssertSuccess(result -> { + PgConnection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> { + conn + .query("SELECT '10 years 3 months 332 days 20 hours 20 minutes 20.999991 seconds'::INTERVAL \"Interval\"") + .execute() + .onComplete(ctx.asyncAssertSuccess(result -> { ctx.assertEquals(1, result.size()); Row row = result.iterator().next(); Interval interval = Interval.of() diff --git a/vertx-pg-client/src/test/java/io/vertx/pgclient/data/EnumeratedTypesExtendedCodecTest.java b/vertx-pg-client/src/test/java/io/vertx/pgclient/data/EnumeratedTypesExtendedCodecTest.java index be3a74839..17ed768cf 100644 --- a/vertx-pg-client/src/test/java/io/vertx/pgclient/data/EnumeratedTypesExtendedCodecTest.java +++ b/vertx-pg-client/src/test/java/io/vertx/pgclient/data/EnumeratedTypesExtendedCodecTest.java @@ -12,11 +12,13 @@ public class EnumeratedTypesExtendedCodecTest extends ExtendedQueryDataTypeCodec @Test public void testDecodeEnum(TestContext ctx) { Async async = ctx.async(); - PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.prepare("SELECT \"currentMood\" FROM \"EnumDataType\" WHERE \"id\" = $1", + PgConnection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> { + conn.prepare("SELECT \"currentMood\" FROM \"EnumDataType\" WHERE \"id\" = $1").onComplete( ctx.asyncAssertSuccess(p -> { - p.query().execute(Tuple.tuple() - .addInteger(1), ctx.asyncAssertSuccess(result -> { + p. + query() + .execute(Tuple.tuple().addInteger(1)) + .onComplete(ctx.asyncAssertSuccess(result -> { ctx.assertEquals(1, result.size()); ctx.assertEquals(1, result.rowCount()); Row row = result.iterator().next(); @@ -33,13 +35,13 @@ public void testDecodeEnum(TestContext ctx) { @Test public void testEncodeEnum(TestContext ctx) { Async async = ctx.async(); - PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.prepare("UPDATE \"EnumDataType\" SET \"currentMood\" = $1 WHERE \"id\" = $2 RETURNING \"currentMood\"", + PgConnection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> { + conn.prepare("UPDATE \"EnumDataType\" SET \"currentMood\" = $1 WHERE \"id\" = $2 RETURNING \"currentMood\"").onComplete( ctx.asyncAssertSuccess(p -> { - p.query().execute(Tuple.tuple() - .addString("happy") - .addInteger(2) - , ctx.asyncAssertSuccess(result -> { + p + .query() + .execute(Tuple.tuple().addString("happy").addInteger(2)) + .onComplete(ctx.asyncAssertSuccess(result -> { ctx.assertEquals(1, result.size()); ctx.assertEquals(1, result.rowCount()); Row row = result.iterator().next(); @@ -57,11 +59,13 @@ public void testEncodeEnum(TestContext ctx) { public void testDecodeEnumArray(TestContext ctx) { final String[] expected = new String[]{"ok", "unhappy", "happy"}; Async async = ctx.async(); - PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.prepare("SELECT \"Enum\" FROM \"ArrayDataType\" WHERE \"id\" = $1", + PgConnection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> { + conn.prepare("SELECT \"Enum\" FROM \"ArrayDataType\" WHERE \"id\" = $1").onComplete( ctx.asyncAssertSuccess(p -> { - p.query().execute(Tuple.tuple() - .addInteger(1), ctx.asyncAssertSuccess(result -> { + p + .query() + .execute(Tuple.tuple().addInteger(1)) + .onComplete(ctx.asyncAssertSuccess(result -> { ColumnChecker.checkColumn(0, "Enum") .returns(Tuple::getValue, Row::getValue, expected) .returns(Tuple::getArrayOfStrings, Row::getArrayOfStrings, expected) @@ -75,13 +79,13 @@ public void testDecodeEnumArray(TestContext ctx) { @Test public void testEncodeEnumArray(TestContext ctx) { Async async = ctx.async(); - PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.prepare("UPDATE \"ArrayDataType\" SET \"Enum\" = $1 WHERE \"id\" = $2 RETURNING \"Enum\"", + PgConnection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> { + conn.prepare("UPDATE \"ArrayDataType\" SET \"Enum\" = $1 WHERE \"id\" = $2 RETURNING \"Enum\"").onComplete( ctx.asyncAssertSuccess(p -> { - p.query().execute(Tuple.tuple() - .addArrayOfString(new String[]{"unhappy"}) - .addInteger(2) - , ctx.asyncAssertSuccess(result -> { + p + .query() + .execute(Tuple.tuple().addArrayOfString(new String[]{"unhappy"}).addInteger(2)) + .onComplete(ctx.asyncAssertSuccess(result -> { ColumnChecker.checkColumn(0, "Enum") .returns(Tuple::getValue, Row::getValue, new String[]{"unhappy"}) .returns(Tuple::getArrayOfStrings, Row::getArrayOfStrings, new String[]{"unhappy"}) @@ -95,13 +99,13 @@ public void testEncodeEnumArray(TestContext ctx) { @Test public void testEncodeEnumArrayMultipleValues(TestContext ctx) { Async async = ctx.async(); - PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.prepare("UPDATE \"ArrayDataType\" SET \"Enum\" = $1 WHERE \"id\" = $2 RETURNING \"Enum\"", + PgConnection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> { + conn.prepare("UPDATE \"ArrayDataType\" SET \"Enum\" = $1 WHERE \"id\" = $2 RETURNING \"Enum\"").onComplete( ctx.asyncAssertSuccess(p -> { - p.query().execute(Tuple.tuple() - .addArrayOfString(new String[]{"unhappy", "ok"}) - .addInteger(2) - , ctx.asyncAssertSuccess(result -> { + p + .query() + .execute(Tuple.tuple().addArrayOfString(new String[]{"unhappy", "ok"}).addInteger(2)) + .onComplete(ctx.asyncAssertSuccess(result -> { ColumnChecker.checkColumn(0, "Enum") .returns(Tuple::getValue, Row::getValue, new String[]{"unhappy", "ok"}) .returns(Tuple::getArrayOfStrings, Row::getArrayOfStrings, new String[]{"unhappy", "ok"}) @@ -115,13 +119,14 @@ public void testEncodeEnumArrayMultipleValues(TestContext ctx) { @Test public void testEncodeEnumArrayEmptyValues(TestContext ctx) { Async async = ctx.async(); - PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.prepare("UPDATE \"ArrayDataType\" SET \"Enum\" = $1 WHERE \"id\" = $2 RETURNING \"Enum\", \"Boolean\"", - ctx.asyncAssertSuccess(p -> { - p.query().execute(Tuple.tuple() - .addArrayOfString(new String[]{}) - .addInteger(2) - , ctx.asyncAssertSuccess(result -> { + PgConnection + .connect(vertx, options) + .onComplete(ctx.asyncAssertSuccess(conn -> { + conn.prepare("UPDATE \"ArrayDataType\" SET \"Enum\" = $1 WHERE \"id\" = $2 RETURNING \"Enum\", \"Boolean\"") + .onComplete(ctx.asyncAssertSuccess(p -> { + p.query() + .execute(Tuple.tuple().addArrayOfString(new String[]{}).addInteger(2)) + .onComplete(ctx.asyncAssertSuccess(result -> { ColumnChecker.checkColumn(0, "Enum") .returns(Tuple::getValue, Row::getValue, new String[]{}) .returns(Tuple::getArrayOfStrings, Row::getArrayOfStrings, new String[]{}) diff --git a/vertx-pg-client/src/test/java/io/vertx/pgclient/data/EnumeratedTypesSimpleCodecTest.java b/vertx-pg-client/src/test/java/io/vertx/pgclient/data/EnumeratedTypesSimpleCodecTest.java index bee9e7184..3d17ba887 100644 --- a/vertx-pg-client/src/test/java/io/vertx/pgclient/data/EnumeratedTypesSimpleCodecTest.java +++ b/vertx-pg-client/src/test/java/io/vertx/pgclient/data/EnumeratedTypesSimpleCodecTest.java @@ -12,9 +12,11 @@ public class EnumeratedTypesSimpleCodecTest extends SimpleQueryDataTypeCodecTest @Test public void testEnum(TestContext ctx) { Async async = ctx.async(); - PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { + PgConnection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> { conn - .query("SELECT \"currentMood\" FROM \"EnumDataType\" WHERE \"id\" = 5").execute(ctx.asyncAssertSuccess(result -> { + .query("SELECT \"currentMood\" FROM \"EnumDataType\" WHERE \"id\" = 5") + .execute() + .onComplete(ctx.asyncAssertSuccess(result -> { ctx.assertEquals(1, result.size()); Row row = result.iterator().next(); ColumnChecker.checkColumn(0, "currentMood") diff --git a/vertx-pg-client/src/test/java/io/vertx/pgclient/data/ExtendedQueryDataTypeCodecTestBase.java b/vertx-pg-client/src/test/java/io/vertx/pgclient/data/ExtendedQueryDataTypeCodecTestBase.java index 124ef315a..328a3d73a 100644 --- a/vertx-pg-client/src/test/java/io/vertx/pgclient/data/ExtendedQueryDataTypeCodecTestBase.java +++ b/vertx-pg-client/src/test/java/io/vertx/pgclient/data/ExtendedQueryDataTypeCodecTestBase.java @@ -46,10 +46,12 @@ protected void testGenericArray(TestContext ctx, String sql, T[][] expected, protected void testGeneric(TestContext ctx, String sql, T[] expected, BiFunction getter) { Async async = ctx.async(); - PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { + PgConnection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> { List batch = Stream.of(expected).map(Tuple::of).collect(Collectors.toList()); - conn.preparedQuery(sql).executeBatch(batch, - ctx.asyncAssertSuccess(result -> { + conn + .preparedQuery(sql) + .executeBatch(batch) + .onComplete(ctx.asyncAssertSuccess(result -> { for (T n : expected) { ctx.assertEquals(result.size(), 1); Iterator it = result.iterator(); @@ -66,9 +68,11 @@ protected void testGeneric(TestContext ctx, String sql, T[] expected, BiFunc protected void testDecode(TestContext ctx, String sql, BiFunction getter, T... expected) { Async async = ctx.async(); - PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.preparedQuery(sql).execute( - ctx.asyncAssertSuccess(result -> { + PgConnection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> { + conn + .preparedQuery(sql) + .execute() + .onComplete(ctx.asyncAssertSuccess(result -> { ctx.assertEquals(result.size(), 1); Iterator it = result.iterator(); Row row = it.next(); @@ -84,9 +88,11 @@ protected void testDecode(TestContext ctx, String sql, BiFunction void testEncode(TestContext ctx, String sql, Tuple tuple, String... expected) { Async async = ctx.async(); - PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.preparedQuery(sql).execute(tuple, - ctx.asyncAssertSuccess(result -> { + PgConnection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> { + conn + .preparedQuery(sql) + .execute(tuple) + .onComplete(ctx.asyncAssertSuccess(result -> { ctx.assertEquals(result.size(), 1); Iterator it = result.iterator(); Row row = it.next(); diff --git a/vertx-pg-client/src/test/java/io/vertx/pgclient/data/GeometricTypesExtendedCodecTest.java b/vertx-pg-client/src/test/java/io/vertx/pgclient/data/GeometricTypesExtendedCodecTest.java index 652c11dd3..e01f4d534 100644 --- a/vertx-pg-client/src/test/java/io/vertx/pgclient/data/GeometricTypesExtendedCodecTest.java +++ b/vertx-pg-client/src/test/java/io/vertx/pgclient/data/GeometricTypesExtendedCodecTest.java @@ -105,8 +105,9 @@ public void testDecodeCircleArray(TestContext ctx) { @Test public void testEncodeGeometric(TestContext ctx) { Async async = ctx.async(); - PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.prepare("UPDATE \"" + "GeometricDataType" + "\" SET " + + PgConnection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> { + conn + .prepare("UPDATE \"" + "GeometricDataType" + "\" SET " + "\"Point\" = $1, " + "\"Line\" = $2, " + "\"Lseg\" = $3, " + @@ -115,8 +116,8 @@ public void testEncodeGeometric(TestContext ctx) { "\"OpenPath\" = $6, " + "\"Polygon\" = $7, " + "\"Circle\" = $8 " + - "WHERE \"id\" = $9 RETURNING \"Point\", \"Line\", \"Lseg\", \"Box\", \"ClosedPath\", \"OpenPath\", \"Polygon\", \"Circle\"", - ctx.asyncAssertSuccess(p -> { + "WHERE \"id\" = $9 RETURNING \"Point\", \"Line\", \"Lseg\", \"Box\", \"ClosedPath\", \"OpenPath\", \"Polygon\", \"Circle\"") + .onComplete(ctx.asyncAssertSuccess(p -> { Point point = new Point(2.0, 3.0); Line line = new Line(2.0, 3.0, 4.0); LineSegment lineSegment = new LineSegment(new Point(2.0, 2.0), new Point(3.0, 3.0)); @@ -126,7 +127,8 @@ public void testEncodeGeometric(TestContext ctx) { Polygon polygon = new Polygon(Arrays.asList(new Point(2.0, 2.0), new Point(3.0, 3.0), new Point(4.0, 2.0))); Circle circle = new Circle(new Point(1.0, 1.0), 3.0); int id = 2; - p.query().execute(Tuple.tuple() + p.query() + .execute(Tuple.tuple() .addValue(point) .addValue(line) .addValue(lineSegment) @@ -135,7 +137,8 @@ public void testEncodeGeometric(TestContext ctx) { .addValue(closedPath) .addValue(polygon) .addValue(circle) - .addInteger(id), ctx.asyncAssertSuccess(result -> { + .addInteger(id)) + .onComplete(ctx.asyncAssertSuccess(result -> { ctx.assertEquals(1, result.size()); ctx.assertEquals(1, result.rowCount()); Row row = result.iterator().next(); @@ -180,8 +183,9 @@ public void testEncodeGeometric(TestContext ctx) { @Test public void testEncodeGeometricArray(TestContext ctx) { Async async = ctx.async(); - PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.prepare("UPDATE \"" + "ArrayDataType" + "\" SET " + + PgConnection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> { + conn + .prepare("UPDATE \"" + "ArrayDataType" + "\" SET " + "\"Point\" = $1, " + "\"Line\" = $2, " + "\"Lseg\" = $3, " + @@ -190,8 +194,8 @@ public void testEncodeGeometricArray(TestContext ctx) { "\"OpenPath\" = $6, " + "\"Polygon\" = $7, " + "\"Circle\" = $8 " + - "WHERE \"id\" = $9 RETURNING \"Point\", \"Line\", \"Lseg\", \"Box\", \"ClosedPath\", \"OpenPath\", \"Polygon\", \"Circle\"", - ctx.asyncAssertSuccess(p -> { + "WHERE \"id\" = $9 RETURNING \"Point\", \"Line\", \"Lseg\", \"Box\", \"ClosedPath\", \"OpenPath\", \"Polygon\", \"Circle\"") + .onComplete(ctx.asyncAssertSuccess(p -> { Point[] points = {new Point(2.0, 2.0), new Point(1.0, 1.0)}; Line[] lines = {new Line(3.0, 2.0, 1.0), new Line(2.0, 3.0, 4.0)}; LineSegment[] lineSegments = {new LineSegment(new Point(1.0, 1.0), new Point(-3.0, -2.0)), new LineSegment(new Point(2.0, 2.0), new Point(3.0, 3.0))}; @@ -204,7 +208,9 @@ public void testEncodeGeometricArray(TestContext ctx) { new Polygon(Arrays.asList(new Point(0.0, 0.0), new Point(0.0, 1.0), new Point(1.0, 2.0), new Point(2.0, 1.0), new Point(2.0, 0.0)))}; Circle[] circles = {new Circle(new Point(1.0, 1.0), 3.0), new Circle(new Point(2.0, 2.0), 2.0)}; int id = 2; - p.query().execute(Tuple.tuple() + p + .query() + .execute(Tuple.tuple() .addValue(points) .addValue(lines) .addValue(lineSegments) @@ -213,7 +219,8 @@ public void testEncodeGeometricArray(TestContext ctx) { .addValue(closedPaths) .addValue(polygons) .addValue(circles) - .addInteger(id), ctx.asyncAssertSuccess(result -> { + .addInteger(id)) + .onComplete(ctx.asyncAssertSuccess(result -> { ctx.assertEquals(1, result.size()); ctx.assertEquals(1, result.rowCount()); Row row = result.iterator().next(); diff --git a/vertx-pg-client/src/test/java/io/vertx/pgclient/data/InetCodecTest.java b/vertx-pg-client/src/test/java/io/vertx/pgclient/data/InetCodecTest.java index 93f93b37c..bc43109ad 100644 --- a/vertx-pg-client/src/test/java/io/vertx/pgclient/data/InetCodecTest.java +++ b/vertx-pg-client/src/test/java/io/vertx/pgclient/data/InetCodecTest.java @@ -29,12 +29,14 @@ public void testTextDecodeINET(TestContext ctx) throws Exception { private void testDecodeINET(TestContext ctx, BiFunction>> a) throws Exception { InetAddress addr1 = Inet4Address.getByName("0.1.2.3"); InetAddress addr2 = Inet6Address.getByName("2001:0db8:0a0b:12f0:0000:0000:0000:0001"); - PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { + PgConnection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> { a.apply(conn, "SELECT " + "'0.1.2.3'::INET," + "'0.1.2.3/4'::INET," + "'2001:0db8:0a0b:12f0:0000:0000:0000:0001'::INET," + - "'2001:0db8:0a0b:12f0:0000:0000:0000:0001/4'::INET").execute(ctx.asyncAssertSuccess(rows -> { + "'2001:0db8:0a0b:12f0:0000:0000:0000:0001/4'::INET") + .execute() + .onComplete(ctx.asyncAssertSuccess(rows -> { ctx.assertEquals(1, rows.size()); Row row = rows.iterator().next(); Inet v1 = (Inet) row.getValue(0); @@ -57,14 +59,16 @@ private void testDecodeINET(TestContext ctx, BiFunction { - conn.preparedQuery("SELECT ($1::INET)::VARCHAR, ($2::INET)::VARCHAR, ($3::INET)::VARCHAR, ($4::INET)::VARCHAR").execute(Tuple.of( + PgConnection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> { + conn + .preparedQuery("SELECT ($1::INET)::VARCHAR, ($2::INET)::VARCHAR, ($3::INET)::VARCHAR, ($4::INET)::VARCHAR") + .execute(Tuple.of( new Inet().setAddress(addr1), new Inet().setAddress(addr1).setNetmask(4), new Inet().setAddress(addr2), new Inet().setAddress(addr2).setNetmask(4) - ), - ctx.asyncAssertSuccess(rows -> { + )) + .onComplete(ctx.asyncAssertSuccess(rows -> { ctx.assertEquals(1, rows.size()); Row row = rows.iterator().next(); String v1 = row.getString(0); @@ -82,9 +86,11 @@ public void testBinaryEncodeINET(TestContext ctx) throws Exception { @Test public void testBinaryDecodeINETArray(TestContext ctx) throws Exception { InetAddress addr1 = Inet4Address.getByName("0.1.2.3"); - PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.preparedQuery("SELECT ARRAY['0.1.2.3'::INET,'0.1.2.3/4'::INET]") - .execute(ctx.asyncAssertSuccess(rows -> { + PgConnection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> { + conn + .preparedQuery("SELECT ARRAY['0.1.2.3'::INET,'0.1.2.3/4'::INET]") + .execute() + .onComplete(ctx.asyncAssertSuccess(rows -> { ctx.assertEquals(1, rows.size()); Row row = rows.iterator().next(); Inet[] array = (Inet[]) row.getValue(0); @@ -101,11 +107,11 @@ public void testBinaryDecodeINETArray(TestContext ctx) throws Exception { @Test public void testBinaryEncodeINETArray(TestContext ctx) throws Exception { InetAddress addr1 = Inet4Address.getByName("0.1.2.3"); - PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.preparedQuery("SELECT ($1::INET[])::VARCHAR[]").execute(Tuple.of( - new Inet[]{new Inet().setAddress(addr1), new Inet().setAddress(addr1).setNetmask(4)} - ), - ctx.asyncAssertSuccess(rows -> { + PgConnection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> { + conn + .preparedQuery("SELECT ($1::INET[])::VARCHAR[]") + .execute(Tuple.of(new Inet[]{new Inet().setAddress(addr1), new Inet().setAddress(addr1).setNetmask(4)})) + .onComplete(ctx.asyncAssertSuccess(rows -> { ctx.assertEquals(1, rows.size()); Row row = rows.iterator().next(); String[] array = row.getArrayOfStrings(0); diff --git a/vertx-pg-client/src/test/java/io/vertx/pgclient/data/JavaEnumTest.java b/vertx-pg-client/src/test/java/io/vertx/pgclient/data/JavaEnumTest.java index 29c61ef24..f1cfcbf55 100644 --- a/vertx-pg-client/src/test/java/io/vertx/pgclient/data/JavaEnumTest.java +++ b/vertx-pg-client/src/test/java/io/vertx/pgclient/data/JavaEnumTest.java @@ -34,10 +34,11 @@ public void testJavaEnumToINT4Column(TestContext ctx) { } private void testJavaEnumToColumn(TestContext ctx, String value, String sqlType) { - PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { + PgConnection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> { conn .preparedQuery("SELECT * FROM (VALUES (" + value + " :: " + sqlType + ")) AS t (c)") - .execute(ctx.asyncAssertSuccess(v -> { + .execute() + .onComplete(ctx.asyncAssertSuccess(v -> { RowIterator it = v.iterator(); ctx.assertTrue(it.hasNext()); Row row = it.next(); @@ -67,10 +68,11 @@ public void testJavaEnumToINT4ArrayColumn(TestContext ctx) { } private void testJavaEnumToArrayColumn(TestContext ctx, String value, String sqlType) { - PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { + PgConnection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> { conn .preparedQuery("SELECT * FROM (VALUES (" + value + " :: " + sqlType + ")) AS t (c)") - .execute(ctx.asyncAssertSuccess(v -> { + .execute() + .onComplete(ctx.asyncAssertSuccess(v -> { RowIterator it = v.iterator(); ctx.assertTrue(it.hasNext()); Row row = it.next(); @@ -112,10 +114,11 @@ public void testJavaEnumToINT8Param(TestContext ctx) { } private void testJavaEnumToParam(TestContext ctx, Object expected, String sqlType) { - PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { + PgConnection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> { conn .preparedQuery("SELECT $1 :: " + sqlType + " \"c\"") - .execute(Tuple.of(Mood.happy), ctx.asyncAssertSuccess(v -> { + .execute(Tuple.of(Mood.happy)) + .onComplete(ctx.asyncAssertSuccess(v -> { RowIterator it = v.iterator(); ctx.assertTrue(it.hasNext()); Row row = it.next(); @@ -155,10 +158,11 @@ public void testJavaEnumToINT8ArrayParam(TestContext ctx) { } private void testJavaEnumToArrayParam(TestContext ctx, Object expected, String sqlType) { - PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { + PgConnection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> { conn .preparedQuery("SELECT $1 :: " + sqlType + " \"c\"") - .execute(Tuple.of(new Mood[]{Mood.happy}), ctx.asyncAssertSuccess(v -> { + .execute(Tuple.of(new Mood[]{Mood.happy})) + .onComplete(ctx.asyncAssertSuccess(v -> { RowIterator it = v.iterator(); ctx.assertTrue(it.hasNext()); Row row = it.next(); diff --git a/vertx-pg-client/src/test/java/io/vertx/pgclient/data/JsonTypesExtendedCodecTest.java b/vertx-pg-client/src/test/java/io/vertx/pgclient/data/JsonTypesExtendedCodecTest.java index aee788731..50a73a970 100644 --- a/vertx-pg-client/src/test/java/io/vertx/pgclient/data/JsonTypesExtendedCodecTest.java +++ b/vertx-pg-client/src/test/java/io/vertx/pgclient/data/JsonTypesExtendedCodecTest.java @@ -69,10 +69,17 @@ public void testDecodeJsonb(TestContext ctx) { private void testDecodeJson(TestContext ctx, String tableName) { Async async = ctx.async(); - PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.prepare("SELECT \"JsonObject\", \"JsonArray\", \"Number\", \"String\", \"BooleanTrue\", \"BooleanFalse\", \"NullValue\", \"Null\" FROM \"" + tableName + "\" WHERE \"id\" = $1", + PgConnection + .connect(vertx, options) + .onComplete(ctx.asyncAssertSuccess(conn -> { + conn + .prepare("SELECT \"JsonObject\", \"JsonArray\", \"Number\", \"String\", \"BooleanTrue\", \"BooleanFalse\", \"NullValue\", \"Null\" FROM \"" + tableName + "\" WHERE \"id\" = $1") + .onComplete( ctx.asyncAssertSuccess(p -> { - p.query().execute(Tuple.tuple().addInteger(1), ctx.asyncAssertSuccess(result -> { + p + .query() + .execute(Tuple.tuple().addInteger(1)) + .onComplete(ctx.asyncAssertSuccess(result -> { ctx.assertEquals(1, result.size()); ctx.assertEquals(1, result.rowCount()); Row row = result.iterator().next(); @@ -145,8 +152,9 @@ public void testEncodeJsonb(TestContext ctx) { private void testEncodeJson(TestContext ctx, String tableName) { Async async = ctx.async(); - PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.prepare("UPDATE \"" + tableName + "\" SET " + + PgConnection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> { + conn + .prepare("UPDATE \"" + tableName + "\" SET " + "\"JsonObject\" = $1, " + "\"JsonArray\" = $2, " + "\"Number\" = $3, " + @@ -155,11 +163,13 @@ private void testEncodeJson(TestContext ctx, String tableName) { "\"BooleanFalse\" = $6, " + "\"NullValue\" = $7, " + "\"Null\" = $8 " + - "WHERE \"id\" = $9 RETURNING \"JsonObject\", \"JsonArray\", \"Number\", \"String\", \"BooleanTrue\", \"BooleanFalse\", \"NullValue\", \"Null\"", - ctx.asyncAssertSuccess(p -> { + "WHERE \"id\" = $9 RETURNING \"JsonObject\", \"JsonArray\", \"Number\", \"String\", \"BooleanTrue\", \"BooleanFalse\", \"NullValue\", \"Null\"") + .onComplete(ctx.asyncAssertSuccess(p -> { JsonObject object = new JsonObject("{\"str\":\"blah\", \"int\" : 1, \"float\" : 3.5, \"object\": {}, \"array\" : []}"); JsonArray array = new JsonArray("[1,true,null,9.5,\"Hi\"]"); - p.query().execute(Tuple.tuple() + p + .query() + .execute(Tuple.tuple() .addValue(object) .addValue(array) .addValue(4) @@ -168,7 +178,8 @@ private void testEncodeJson(TestContext ctx, String tableName) { .addValue(false) .addValue(Tuple.JSON_NULL) .addValue(null) - .addInteger(2), ctx.asyncAssertSuccess(result -> { + .addInteger(2)) + .onComplete(ctx.asyncAssertSuccess(result -> { ctx.assertEquals(1, result.size()); ctx.assertEquals(1, result.rowCount()); Row row = result.iterator().next(); diff --git a/vertx-pg-client/src/test/java/io/vertx/pgclient/data/JsonTypesSimpleCodecTest.java b/vertx-pg-client/src/test/java/io/vertx/pgclient/data/JsonTypesSimpleCodecTest.java index 44b5363e2..0e6568b12 100644 --- a/vertx-pg-client/src/test/java/io/vertx/pgclient/data/JsonTypesSimpleCodecTest.java +++ b/vertx-pg-client/src/test/java/io/vertx/pgclient/data/JsonTypesSimpleCodecTest.java @@ -27,8 +27,9 @@ public void testJSON(TestContext ctx) { private void testJson(TestContext ctx, String type) { Async async = ctx.async(); - PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.query("SELECT " + + PgConnection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> { + conn + .query("SELECT " + "' {\"str\":\"blah\", \"int\" : 1, \"float\" : 3.5, \"object\": {}, \"array\" : [] }'::" + type + " \"JsonObject\"," + "' [1,true,null,9.5,\"Hi\" ] '::" + type + " \"JsonArray\"," + "' true '::" + type + " \"TrueValue\"," + @@ -37,8 +38,9 @@ private void testJson(TestContext ctx, String type) { "' 7.502 '::" + type + " \"Number1\"," + "' 8 '::" + type + " \"Number2\"," + "'\" Really Awesome! \"'::" + type + " \"Text\"," + - "NULL::" + type + " \"Null\"").execute( - ctx.asyncAssertSuccess(result -> { + "NULL::" + type + " \"Null\"") + .execute() + .onComplete(ctx.asyncAssertSuccess(result -> { JsonObject object = new JsonObject("{\"str\":\"blah\", \"int\" : 1, \"float\" : 3.5, \"object\": {}, \"array\" : []}"); JsonArray array = new JsonArray("[1,true,null,9.5,\"Hi\"]"); ctx.assertEquals(1, result.size()); diff --git a/vertx-pg-client/src/test/java/io/vertx/pgclient/data/NullSimpleCodecTest.java b/vertx-pg-client/src/test/java/io/vertx/pgclient/data/NullSimpleCodecTest.java index e7ab3ace4..ef0075c1f 100644 --- a/vertx-pg-client/src/test/java/io/vertx/pgclient/data/NullSimpleCodecTest.java +++ b/vertx-pg-client/src/test/java/io/vertx/pgclient/data/NullSimpleCodecTest.java @@ -12,9 +12,11 @@ public class NullSimpleCodecTest extends SimpleQueryDataTypeCodecTestBase { @Test public void testNull(TestContext ctx) { Async async = ctx.async(); - PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { + PgConnection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> { conn - .query("SELECT null \"NullValue\"").execute(ctx.asyncAssertSuccess(result -> { + .query("SELECT null \"NullValue\"") + .execute() + .onComplete(ctx.asyncAssertSuccess(result -> { ctx.assertEquals(1, result.size()); Row row = result.iterator().next(); ColumnChecker.checkColumn(0, "NullValue").returnsNull().forRow(row); diff --git a/vertx-pg-client/src/test/java/io/vertx/pgclient/data/NumericTypesExtendedCodecTest.java b/vertx-pg-client/src/test/java/io/vertx/pgclient/data/NumericTypesExtendedCodecTest.java index b495badb6..a28102bdf 100644 --- a/vertx-pg-client/src/test/java/io/vertx/pgclient/data/NumericTypesExtendedCodecTest.java +++ b/vertx-pg-client/src/test/java/io/vertx/pgclient/data/NumericTypesExtendedCodecTest.java @@ -15,10 +15,13 @@ public class NumericTypesExtendedCodecTest extends ExtendedQueryDataTypeCodecTes @Test public void testDecodeInt2(TestContext ctx) { Async async = ctx.async(); - PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.prepare("SELECT $1 :: INT2 \"Short\"", + PgConnection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> { + conn.prepare("SELECT $1 :: INT2 \"Short\"").onComplete( ctx.asyncAssertSuccess(p -> { - p.query().execute(Tuple.tuple().addShort((short) 32767), ctx.asyncAssertSuccess(result -> { + p + .query() + .execute(Tuple.tuple().addShort((short) 32767)) + .onComplete(ctx.asyncAssertSuccess(result -> { ctx.assertEquals(1, result.size()); ctx.assertEquals(1, result.rowCount()); Row row = result.iterator().next(); @@ -41,10 +44,13 @@ public void testDecodeInt2(TestContext ctx) { @Test public void testEncodeInt2(TestContext ctx) { Async async = ctx.async(); - PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.prepare("UPDATE \"NumericDataType\" SET \"Short\" = $1 WHERE \"id\" = $2 RETURNING \"Short\"", + PgConnection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> { + conn.prepare("UPDATE \"NumericDataType\" SET \"Short\" = $1 WHERE \"id\" = $2 RETURNING \"Short\"").onComplete( ctx.asyncAssertSuccess(p -> { - p.query().execute(Tuple.of(Short.MIN_VALUE, 2), ctx.asyncAssertSuccess(result -> { + p + .query() + .execute(Tuple.of(Short.MIN_VALUE, 2)) + .onComplete(ctx.asyncAssertSuccess(result -> { ctx.assertEquals(1, result.size()); ctx.assertEquals(1, result.rowCount()); Row row = result.iterator().next(); @@ -67,10 +73,13 @@ public void testEncodeInt2(TestContext ctx) { @Test public void testDecodeInt4(TestContext ctx) { Async async = ctx.async(); - PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.prepare("SELECT $1 :: INT4 \"Integer\"", + PgConnection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> { + conn.prepare("SELECT $1 :: INT4 \"Integer\"").onComplete( ctx.asyncAssertSuccess(p -> { - p.query().execute(Tuple.tuple().addInteger(Integer.MAX_VALUE), ctx.asyncAssertSuccess(result -> { + p + .query() + .execute(Tuple.tuple().addInteger(Integer.MAX_VALUE)) + .onComplete(ctx.asyncAssertSuccess(result -> { ctx.assertEquals(1, result.size()); ctx.assertEquals(1, result.rowCount()); Row row = result.iterator().next(); @@ -93,13 +102,15 @@ public void testDecodeInt4(TestContext ctx) { @Test public void testEncodeInt4(TestContext ctx) { Async async = ctx.async(); - PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.prepare("UPDATE \"NumericDataType\" SET \"Integer\" = $1 WHERE \"id\" = $2 RETURNING \"Integer\"", + PgConnection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> { + conn.prepare("UPDATE \"NumericDataType\" SET \"Integer\" = $1 WHERE \"id\" = $2 RETURNING \"Integer\"").onComplete( ctx.asyncAssertSuccess(p -> { - p.query().execute(Tuple.tuple() + p + .query() + .execute(Tuple.tuple() .addInteger(Integer.MIN_VALUE) - .addInteger(2) - , ctx.asyncAssertSuccess(result -> { + .addInteger(2)) + .onComplete(ctx.asyncAssertSuccess(result -> { ctx.assertEquals(1, result.size()); ctx.assertEquals(1, result.rowCount()); Row row = result.iterator().next(); @@ -122,10 +133,13 @@ public void testEncodeInt4(TestContext ctx) { @Test public void testDecodeInt8(TestContext ctx) { Async async = ctx.async(); - PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.prepare("SELECT $1 :: INT8 \"Long\"", + PgConnection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> { + conn.prepare("SELECT $1 :: INT8 \"Long\"").onComplete( ctx.asyncAssertSuccess(p -> { - p.query().execute(Tuple.tuple().addLong(Long.MAX_VALUE), ctx.asyncAssertSuccess(result -> { + p + .query() + .execute(Tuple.tuple().addLong(Long.MAX_VALUE)) + .onComplete(ctx.asyncAssertSuccess(result -> { ctx.assertEquals(1, result.size()); ctx.assertEquals(1, result.rowCount()); Row row = result.iterator().next(); @@ -148,13 +162,15 @@ public void testDecodeInt8(TestContext ctx) { @Test public void testEncodeInt8(TestContext ctx) { Async async = ctx.async(); - PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.prepare("UPDATE \"NumericDataType\" SET \"Long\" = $1 WHERE \"id\" = $2 RETURNING \"Long\"", + PgConnection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> { + conn.prepare("UPDATE \"NumericDataType\" SET \"Long\" = $1 WHERE \"id\" = $2 RETURNING \"Long\"").onComplete( ctx.asyncAssertSuccess(p -> { - p.query().execute(Tuple.tuple() + p + .query() + .execute(Tuple.tuple() .addLong(Long.MIN_VALUE) - .addInteger(2) - , ctx.asyncAssertSuccess(result -> { + .addInteger(2)) + .onComplete(ctx.asyncAssertSuccess(result -> { ctx.assertEquals(1, result.size()); ctx.assertEquals(1, result.rowCount()); Row row = result.iterator().next(); @@ -177,10 +193,13 @@ public void testEncodeInt8(TestContext ctx) { @Test public void testDecodeFloat4(TestContext ctx) { Async async = ctx.async(); - PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.prepare("SELECT $1 :: FLOAT4\"Float\"", + PgConnection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> { + conn.prepare("SELECT $1 :: FLOAT4\"Float\"").onComplete( ctx.asyncAssertSuccess(p -> { - p.query().execute(Tuple.tuple().addFloat(Float.MAX_VALUE), ctx.asyncAssertSuccess(result -> { + p + .query() + .execute(Tuple.tuple().addFloat(Float.MAX_VALUE)) + .onComplete(ctx.asyncAssertSuccess(result -> { ctx.assertEquals(1, result.size()); ctx.assertEquals(1, result.rowCount()); Row row = result.iterator().next(); @@ -203,13 +222,15 @@ public void testDecodeFloat4(TestContext ctx) { @Test public void testEncodeFloat4(TestContext ctx) { Async async = ctx.async(); - PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.prepare("UPDATE \"NumericDataType\" SET \"Float\" = $1 WHERE \"id\" = $2 RETURNING \"Float\"", + PgConnection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> { + conn.prepare("UPDATE \"NumericDataType\" SET \"Float\" = $1 WHERE \"id\" = $2 RETURNING \"Float\"").onComplete( ctx.asyncAssertSuccess(p -> { - p.query().execute(Tuple.tuple() + p + .query() + .execute(Tuple.tuple() .addFloat(Float.MIN_VALUE) - .addInteger(2) - , ctx.asyncAssertSuccess(result -> { + .addInteger(2)) + .onComplete(ctx.asyncAssertSuccess(result -> { ctx.assertEquals(1, result.size()); ctx.assertEquals(1, result.rowCount()); Row row = result.iterator().next(); @@ -232,10 +253,13 @@ public void testEncodeFloat4(TestContext ctx) { @Test public void testDecodeFloat8(TestContext ctx) { Async async = ctx.async(); - PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.prepare("SELECT $1 :: FLOAT8\"Double\"", + PgConnection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> { + conn.prepare("SELECT $1 :: FLOAT8\"Double\"").onComplete( ctx.asyncAssertSuccess(p -> { - p.query().execute(Tuple.tuple().addDouble(Double.MAX_VALUE), ctx.asyncAssertSuccess(result -> { + p + .query() + .execute(Tuple.tuple().addDouble(Double.MAX_VALUE)) + .onComplete(ctx.asyncAssertSuccess(result -> { ctx.assertEquals(1, result.size()); ctx.assertEquals(1, result.rowCount()); Row row = result.iterator().next(); @@ -258,13 +282,15 @@ public void testDecodeFloat8(TestContext ctx) { @Test public void testEncodeFloat8(TestContext ctx) { Async async = ctx.async(); - PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.prepare("UPDATE \"NumericDataType\" SET \"Double\" = $1 WHERE \"id\" = $2 RETURNING \"Double\"", + PgConnection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> { + conn.prepare("UPDATE \"NumericDataType\" SET \"Double\" = $1 WHERE \"id\" = $2 RETURNING \"Double\"").onComplete( ctx.asyncAssertSuccess(p -> { - p.query().execute(Tuple.tuple() + p + .query() + .execute(Tuple.tuple() .addDouble(Double.MIN_VALUE) - .addInteger(2) - , ctx.asyncAssertSuccess(result -> { + .addInteger(2)) + .onComplete(ctx.asyncAssertSuccess(result -> { ctx.assertEquals(1, result.size()); ctx.assertEquals(1, result.rowCount()); Row row = result.iterator().next(); @@ -287,10 +313,13 @@ public void testEncodeFloat8(TestContext ctx) { @Test public void testDecodeSerial2(TestContext ctx) { Async async = ctx.async(); - PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.prepare("SELECT \"SmallSerial\" FROM \"NumericDataType\" WHERE \"id\" = $1", + PgConnection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> { + conn.prepare("SELECT \"SmallSerial\" FROM \"NumericDataType\" WHERE \"id\" = $1").onComplete( ctx.asyncAssertSuccess(p -> { - p.query().execute(Tuple.of(1), ctx.asyncAssertSuccess(result -> { + p + .query() + .execute(Tuple.of(1)) + .onComplete(ctx.asyncAssertSuccess(result -> { ctx.assertEquals(1, result.size()); ctx.assertEquals(1, result.rowCount()); Row row = result.iterator().next(); @@ -313,10 +342,13 @@ public void testDecodeSerial2(TestContext ctx) { @Test public void testEncodeSerial2(TestContext ctx) { Async async = ctx.async(); - PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.prepare("UPDATE \"NumericDataType\" SET \"SmallSerial\" = $1 WHERE \"id\" = $2 RETURNING \"SmallSerial\"", + PgConnection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> { + conn.prepare("UPDATE \"NumericDataType\" SET \"SmallSerial\" = $1 WHERE \"id\" = $2 RETURNING \"SmallSerial\"").onComplete( ctx.asyncAssertSuccess(p -> { - p.query().execute(Tuple.of(Short.MIN_VALUE, 2), ctx.asyncAssertSuccess(result -> { + p + .query() + .execute(Tuple.of(Short.MIN_VALUE, 2)) + .onComplete(ctx.asyncAssertSuccess(result -> { ctx.assertEquals(1, result.size()); ctx.assertEquals(1, result.rowCount()); Row row = result.iterator().next(); @@ -339,10 +371,13 @@ public void testEncodeSerial2(TestContext ctx) { @Test public void testDecodeSerial4(TestContext ctx) { Async async = ctx.async(); - PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.prepare("SELECT \"Serial\" FROM \"NumericDataType\" WHERE \"id\" = $1", + PgConnection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> { + conn.prepare("SELECT \"Serial\" FROM \"NumericDataType\" WHERE \"id\" = $1").onComplete( ctx.asyncAssertSuccess(p -> { - p.query().execute(Tuple.tuple().addInteger(1), ctx.asyncAssertSuccess(result -> { + p + .query() + .execute(Tuple.tuple().addInteger(1)) + .onComplete(ctx.asyncAssertSuccess(result -> { ctx.assertEquals(1, result.size()); ctx.assertEquals(1, result.rowCount()); Row row = result.iterator().next(); @@ -365,13 +400,15 @@ public void testDecodeSerial4(TestContext ctx) { @Test public void testEncodeSerial4(TestContext ctx) { Async async = ctx.async(); - PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.prepare("UPDATE \"NumericDataType\" SET \"Serial\" = $1 WHERE \"id\" = $2 RETURNING \"Serial\"", + PgConnection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> { + conn.prepare("UPDATE \"NumericDataType\" SET \"Serial\" = $1 WHERE \"id\" = $2 RETURNING \"Serial\"").onComplete( ctx.asyncAssertSuccess(p -> { - p.query().execute(Tuple.tuple() + p + .query() + .execute(Tuple.tuple() .addInteger(Integer.MIN_VALUE) - .addInteger(2) - , ctx.asyncAssertSuccess(result -> { + .addInteger(2)) + .onComplete(ctx.asyncAssertSuccess(result -> { ctx.assertEquals(1, result.size()); ctx.assertEquals(1, result.rowCount()); Row row = result.iterator().next(); @@ -394,10 +431,13 @@ public void testEncodeSerial4(TestContext ctx) { @Test public void testDecodeSerial8(TestContext ctx) { Async async = ctx.async(); - PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.prepare("SELECT \"BigSerial\" FROM \"NumericDataType\" WHERE \"id\" = $1", + PgConnection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> { + conn.prepare("SELECT \"BigSerial\" FROM \"NumericDataType\" WHERE \"id\" = $1").onComplete( ctx.asyncAssertSuccess(p -> { - p.query().execute(Tuple.tuple().addInteger(1), ctx.asyncAssertSuccess(result -> { + p + .query() + .execute(Tuple.tuple().addInteger(1)) + .onComplete(ctx.asyncAssertSuccess(result -> { ctx.assertEquals(1, result.size()); ctx.assertEquals(1, result.rowCount()); Row row = result.iterator().next(); @@ -420,13 +460,15 @@ public void testDecodeSerial8(TestContext ctx) { @Test public void testEncodeSerial8(TestContext ctx) { Async async = ctx.async(); - PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.prepare("UPDATE \"NumericDataType\" SET \"BigSerial\" = $1 WHERE \"id\" = $2 RETURNING \"BigSerial\"", + PgConnection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> { + conn.prepare("UPDATE \"NumericDataType\" SET \"BigSerial\" = $1 WHERE \"id\" = $2 RETURNING \"BigSerial\"").onComplete( ctx.asyncAssertSuccess(p -> { - p.query().execute(Tuple.tuple() + p + .query() + .execute(Tuple.tuple() .addLong(Long.MIN_VALUE) - .addInteger(2) - , ctx.asyncAssertSuccess(result -> { + .addInteger(2)) + .onComplete(ctx.asyncAssertSuccess(result -> { ctx.assertEquals(1, result.size()); ctx.assertEquals(1, result.rowCount()); Row row = result.iterator().next(); @@ -501,11 +543,14 @@ public void testFloatArray(TestContext ctx) { @Test public void testDecodeShortArray(TestContext ctx) { Async async = ctx.async(); - PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.prepare("SELECT \"Short\" FROM \"ArrayDataType\" WHERE \"id\" = $1", + PgConnection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> { + conn.prepare("SELECT \"Short\" FROM \"ArrayDataType\" WHERE \"id\" = $1").onComplete( ctx.asyncAssertSuccess(p -> { - p.query().execute(Tuple.tuple() - .addInteger(1), ctx.asyncAssertSuccess(result -> { + p + .query() + .execute(Tuple.tuple() + .addInteger(1)) + .onComplete(ctx.asyncAssertSuccess(result -> { ColumnChecker.checkColumn(0, "Short") .returns(Tuple::getValue, Row::getValue, ColumnChecker.toObjectArray(new short[]{1})) .returns(Tuple::getArrayOfShorts, Row::getArrayOfShorts, ColumnChecker.toObjectArray(new short[]{1})) @@ -524,13 +569,15 @@ public void testDecodeShortArray(TestContext ctx) { @Test public void testEncodeShortArray(TestContext ctx) { Async async = ctx.async(); - PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.prepare("UPDATE \"ArrayDataType\" SET \"Short\" = $1 WHERE \"id\" = $2 RETURNING \"Short\"", + PgConnection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> { + conn.prepare("UPDATE \"ArrayDataType\" SET \"Short\" = $1 WHERE \"id\" = $2 RETURNING \"Short\"").onComplete( ctx.asyncAssertSuccess(p -> { - p.query().execute(Tuple.tuple() + p + .query() + .execute(Tuple.tuple() .addArrayOfShort(new Short[]{2, 3, 4}) - .addInteger(2) - , ctx.asyncAssertSuccess(result -> { + .addInteger(2)) + .onComplete(ctx.asyncAssertSuccess(result -> { ColumnChecker.checkColumn(0, "Short") .returns(Tuple::getValue, Row::getValue, ColumnChecker.toObjectArray(new short[]{2, 3, 4})) .returns(Tuple::getArrayOfShorts, Row::getArrayOfShorts, ColumnChecker.toObjectArray(new short[]{2, 3, 4})) @@ -549,11 +596,14 @@ public void testEncodeShortArray(TestContext ctx) { @Test public void testDecodeIntArray(TestContext ctx) { Async async = ctx.async(); - PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.prepare("SELECT \"Integer\" FROM \"ArrayDataType\" WHERE \"id\" = $1", + PgConnection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> { + conn.prepare("SELECT \"Integer\" FROM \"ArrayDataType\" WHERE \"id\" = $1").onComplete( ctx.asyncAssertSuccess(p -> { - p.query().execute(Tuple.tuple() - .addInteger(1), ctx.asyncAssertSuccess(result -> { + p + .query() + .execute(Tuple.tuple() + .addInteger(1)) + .onComplete(ctx.asyncAssertSuccess(result -> { ColumnChecker.checkColumn(0, "Integer") .returns(Tuple::getValue, Row::getValue, ColumnChecker.toObjectArray(new int[]{2})) .returns(Tuple::getArrayOfShorts, Row::getArrayOfShorts, ColumnChecker.toObjectArray(new short[]{2})) @@ -572,13 +622,15 @@ public void testDecodeIntArray(TestContext ctx) { @Test public void testEncodeIntArray(TestContext ctx) { Async async = ctx.async(); - PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.prepare("UPDATE \"ArrayDataType\" SET \"Integer\" = $1 WHERE \"id\" = $2 RETURNING \"Integer\"", + PgConnection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> { + conn.prepare("UPDATE \"ArrayDataType\" SET \"Integer\" = $1 WHERE \"id\" = $2 RETURNING \"Integer\"").onComplete( ctx.asyncAssertSuccess(p -> { - p.query().execute(Tuple.tuple() + p + .query() + .execute(Tuple.tuple() .addArrayOfInteger(new Integer[]{3, 4, 5, 6}) - .addInteger(2) - , ctx.asyncAssertSuccess(result -> { + .addInteger(2)) + .onComplete(ctx.asyncAssertSuccess(result -> { ColumnChecker.checkColumn(0, "Integer") .returns(Tuple::getValue, Row::getValue, ColumnChecker.toObjectArray(new int[]{3, 4, 5, 6})) .returns(Tuple::getArrayOfShorts, Row::getArrayOfShorts, ColumnChecker.toObjectArray(new short[]{3, 4, 5, 6})) @@ -597,11 +649,14 @@ public void testEncodeIntArray(TestContext ctx) { @Test public void testDecodeLongArray(TestContext ctx) { Async async = ctx.async(); - PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.prepare("SELECT \"Long\" FROM \"ArrayDataType\" WHERE \"id\" = $1", + PgConnection.connect(vertx, options).onComplete( ctx.asyncAssertSuccess(conn -> { + conn.prepare("SELECT \"Long\" FROM \"ArrayDataType\" WHERE \"id\" = $1").onComplete( ctx.asyncAssertSuccess(p -> { - p.query().execute(Tuple.tuple() - .addInteger(1), ctx.asyncAssertSuccess(result -> { + p + .query() + .execute(Tuple.tuple() + .addInteger(1)) + .onComplete(ctx.asyncAssertSuccess(result -> { ColumnChecker.checkColumn(0, "Long") .returns(Tuple::getValue, Row::getValue, new Long[]{3L}) .returns(Tuple::getArrayOfShorts, Row::getArrayOfShorts, new Short[]{(short)3}) @@ -620,13 +675,15 @@ public void testDecodeLongArray(TestContext ctx) { @Test public void testEncodeLongArray(TestContext ctx) { Async async = ctx.async(); - PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.prepare("UPDATE \"ArrayDataType\" SET \"Long\" = $1 WHERE \"id\" = $2 RETURNING \"Long\"", + PgConnection.connect(vertx, options).onComplete( ctx.asyncAssertSuccess(conn -> { + conn.prepare("UPDATE \"ArrayDataType\" SET \"Long\" = $1 WHERE \"id\" = $2 RETURNING \"Long\"").onComplete( ctx.asyncAssertSuccess(p -> { - p.query().execute(Tuple.tuple() + p + .query() + .execute(Tuple.tuple() .addArrayOfLong(new Long[]{4L, 5L, 6L, 7L, 8L}) - .addInteger(2) - , ctx.asyncAssertSuccess(result -> { + .addInteger(2)) + .onComplete(ctx.asyncAssertSuccess(result -> { ColumnChecker.checkColumn(0, "Long") .returns(Tuple::getValue, Row::getValue, ColumnChecker.toObjectArray(new long[]{4, 5, 6, 7, 8})) .returns(Tuple::getArrayOfShorts, Row::getArrayOfShorts, ColumnChecker.toObjectArray(new short[]{4, 5, 6, 7, 8})) @@ -645,11 +702,14 @@ public void testEncodeLongArray(TestContext ctx) { @Test public void testDecodeFloatArray(TestContext ctx) { Async async = ctx.async(); - PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.prepare("SELECT \"Float\" FROM \"ArrayDataType\" WHERE \"id\" = $1", + PgConnection.connect(vertx, options).onComplete( ctx.asyncAssertSuccess(conn -> { + conn.prepare("SELECT \"Float\" FROM \"ArrayDataType\" WHERE \"id\" = $1").onComplete( ctx.asyncAssertSuccess(p -> { - p.query().execute(Tuple.tuple() - .addInteger(1), ctx.asyncAssertSuccess(result -> { + p + .query() + .execute(Tuple.tuple() + .addInteger(1)) + .onComplete(ctx.asyncAssertSuccess(result -> { ColumnChecker.checkColumn(0, "Float") .returns(Tuple::getValue, Row::getValue, ColumnChecker.toObjectArray(new float[]{4.1f})) .returns(Tuple::getArrayOfShorts, Row::getArrayOfShorts, ColumnChecker.toObjectArray(new short[]{(short)4.1f})) @@ -668,13 +728,15 @@ public void testDecodeFloatArray(TestContext ctx) { @Test public void testEncodeFloatArray(TestContext ctx) { Async async = ctx.async(); - PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.prepare("UPDATE \"ArrayDataType\" SET \"Float\" = $1 WHERE \"id\" = $2 RETURNING \"Float\"", + PgConnection.connect(vertx, options).onComplete( ctx.asyncAssertSuccess(conn -> { + conn.prepare("UPDATE \"ArrayDataType\" SET \"Float\" = $1 WHERE \"id\" = $2 RETURNING \"Float\"").onComplete( ctx.asyncAssertSuccess(p -> { - p.query().execute(Tuple.tuple() + p + .query() + .execute(Tuple.tuple() .addArrayOfFloat(new Float[]{5.2f, 5.3f, 5.4f}) - .addInteger(2) - , ctx.asyncAssertSuccess(result -> { + .addInteger(2)) + .onComplete(ctx.asyncAssertSuccess(result -> { ColumnChecker.checkColumn(0, "Float") .returns(Tuple::getValue, Row::getValue, ColumnChecker.toObjectArray(new float[]{5.2f, 5.3f, 5.4f})) .returns(Tuple::getArrayOfShorts, Row::getArrayOfShorts, ColumnChecker.toObjectArray(new short[]{(short)5.2f, (short)5.3f, (short)5.4f})) @@ -693,11 +755,14 @@ public void testEncodeFloatArray(TestContext ctx) { @Test public void testDecodeDoubleArray(TestContext ctx) { Async async = ctx.async(); - PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.prepare("SELECT \"Double\" FROM \"ArrayDataType\" WHERE \"id\" = $1", + PgConnection.connect(vertx, options).onComplete( ctx.asyncAssertSuccess(conn -> { + conn.prepare("SELECT \"Double\" FROM \"ArrayDataType\" WHERE \"id\" = $1").onComplete( ctx.asyncAssertSuccess(p -> { - p.query().execute(Tuple.tuple() - .addInteger(1), ctx.asyncAssertSuccess(result -> { + p + .query() + .execute(Tuple.tuple() + .addInteger(1)) + .onComplete(ctx.asyncAssertSuccess(result -> { ColumnChecker.checkColumn(0, "Double") .returns(Tuple::getValue, Row::getValue, ColumnChecker.toObjectArray(new double[]{5.2})) .returns(Tuple::getArrayOfShorts, Row::getArrayOfShorts, ColumnChecker.toObjectArray(new short[]{(short)5})) @@ -716,13 +781,15 @@ public void testDecodeDoubleArray(TestContext ctx) { @Test public void testEncodeDoubleArray(TestContext ctx) { Async async = ctx.async(); - PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.prepare("UPDATE \"ArrayDataType\" SET \"Double\" = $1 WHERE \"id\" = $2 RETURNING \"Double\"", + PgConnection.connect(vertx, options).onComplete( ctx.asyncAssertSuccess(conn -> { + conn.prepare("UPDATE \"ArrayDataType\" SET \"Double\" = $1 WHERE \"id\" = $2 RETURNING \"Double\"").onComplete( ctx.asyncAssertSuccess(p -> { - p.query().execute(Tuple.tuple() + p + .query() + .execute(Tuple.tuple() .addArrayOfDouble(new Double[]{6.3}) - .addInteger(2) - , ctx.asyncAssertSuccess(result -> { + .addInteger(2)) + .onComplete(ctx.asyncAssertSuccess(result -> { ColumnChecker.checkColumn(0, "Double") .returns(Tuple::getValue, Row::getValue, ColumnChecker.toObjectArray(new double[]{6.3})) .returns(Tuple::getArrayOfShorts, Row::getArrayOfShorts, ColumnChecker.toObjectArray(new short[]{(short)6.3})) @@ -741,13 +808,15 @@ public void testEncodeDoubleArray(TestContext ctx) { @Test public void testEncodeEmptyArray(TestContext ctx) { Async async = ctx.async(); - PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.prepare("UPDATE \"ArrayDataType\" SET \"Double\" = $1 WHERE \"id\" = $2 RETURNING \"Double\"", + PgConnection.connect(vertx, options).onComplete( ctx.asyncAssertSuccess(conn -> { + conn.prepare("UPDATE \"ArrayDataType\" SET \"Double\" = $1 WHERE \"id\" = $2 RETURNING \"Double\"").onComplete( ctx.asyncAssertSuccess(p -> { - p.query().execute(Tuple.tuple() + p + .query() + .execute(Tuple.tuple() .addArrayOfDouble(new Double[]{}) - .addInteger(2) - , ctx.asyncAssertSuccess(result -> { + .addInteger(2)) + .onComplete(ctx.asyncAssertSuccess(result -> { ColumnChecker.checkColumn(0, "Double") .returns(Tuple::getValue, Row::getValue, ColumnChecker.toObjectArray(new double[]{})) .returns(Tuple::getArrayOfShorts, Row::getArrayOfShorts, ColumnChecker.toObjectArray(new short[]{})) @@ -766,11 +835,14 @@ public void testEncodeEmptyArray(TestContext ctx) { @Test public void testDecodeNumericArray(TestContext ctx) { Async async = ctx.async(); - PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.prepare("SELECT \"Numeric\" FROM \"ArrayDataType\" WHERE \"id\" = $1", + PgConnection.connect(vertx, options).onComplete( ctx.asyncAssertSuccess(conn -> { + conn.prepare("SELECT \"Numeric\" FROM \"ArrayDataType\" WHERE \"id\" = $1").onComplete( ctx.asyncAssertSuccess(p -> { - p.query().execute(Tuple.tuple() - .addInteger(1), ctx.asyncAssertSuccess(result -> { + p + .query() + .execute(Tuple.tuple() + .addInteger(1)) + .onComplete(ctx.asyncAssertSuccess(result -> { Numeric[] expected = { Numeric.create(0), Numeric.create(1), @@ -795,17 +867,19 @@ public void testDecodeNumericArray(TestContext ctx) { @Test public void testEncodeNumericArray(TestContext ctx) { Async async = ctx.async(); - PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.prepare("UPDATE \"ArrayDataType\" SET \"Numeric\" = $1 WHERE \"id\" = $2 RETURNING \"Numeric\"", + PgConnection.connect(vertx, options).onComplete( ctx.asyncAssertSuccess(conn -> { + conn.prepare("UPDATE \"ArrayDataType\" SET \"Numeric\" = $1 WHERE \"id\" = $2 RETURNING \"Numeric\"").onComplete( ctx.asyncAssertSuccess(p -> { Numeric[] expected = { Numeric.create(0), Numeric.create(10000), }; - p.query().execute(Tuple.tuple() + p + .query() + .execute(Tuple.tuple() .addValue(expected) - .addInteger(2) - , ctx.asyncAssertSuccess(result -> { + .addInteger(2)) + .onComplete(ctx.asyncAssertSuccess(result -> { ColumnChecker.checkColumn(0, "Numeric") .returns(Tuple::getValue, Row::getValue, expected) .returns(Tuple::getArrayOfShorts, Row::getArrayOfShorts, new Short[]{expected[0].shortValue(), expected[1].shortValue()}) diff --git a/vertx-pg-client/src/test/java/io/vertx/pgclient/data/NumericTypesSimpleCodecTest.java b/vertx-pg-client/src/test/java/io/vertx/pgclient/data/NumericTypesSimpleCodecTest.java index f72693f98..e0c995c71 100644 --- a/vertx-pg-client/src/test/java/io/vertx/pgclient/data/NumericTypesSimpleCodecTest.java +++ b/vertx-pg-client/src/test/java/io/vertx/pgclient/data/NumericTypesSimpleCodecTest.java @@ -40,9 +40,11 @@ public void testFloat8(TestContext ctx) { @Test public void testSerial2(TestContext ctx) { Async async = ctx.async(); - PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { + PgConnection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> { conn - .query("SELECT \"SmallSerial\" FROM \"NumericDataType\" WHERE \"id\" = 1").execute(ctx.asyncAssertSuccess(result -> { + .query("SELECT \"SmallSerial\" FROM \"NumericDataType\" WHERE \"id\" = 1") + .execute() + .onComplete(ctx.asyncAssertSuccess(result -> { ctx.assertEquals(1, result.size()); ctx.assertEquals(1, result.rowCount()); Row row = result.iterator().next(); @@ -64,9 +66,11 @@ public void testSerial2(TestContext ctx) { @Test public void testSerial4(TestContext ctx) { Async async = ctx.async(); - PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { + PgConnection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> { conn - .query("SELECT \"Serial\" FROM \"NumericDataType\" WHERE \"id\" = 1").execute(ctx.asyncAssertSuccess(result -> { + .query("SELECT \"Serial\" FROM \"NumericDataType\" WHERE \"id\" = 1") + .execute() + .onComplete(ctx.asyncAssertSuccess(result -> { ctx.assertEquals(1, result.size()); ctx.assertEquals(1, result.rowCount()); Row row = result.iterator().next(); @@ -88,9 +92,11 @@ public void testSerial4(TestContext ctx) { @Test public void testSerial8(TestContext ctx) { Async async = ctx.async(); - PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { + PgConnection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> { conn - .query("SELECT \"BigSerial\" FROM \"NumericDataType\" WHERE \"id\" = 1").execute(ctx.asyncAssertSuccess(result -> { + .query("SELECT \"BigSerial\" FROM \"NumericDataType\" WHERE \"id\" = 1") + .execute() + .onComplete(ctx.asyncAssertSuccess(result -> { ctx.assertEquals(1, result.size()); ctx.assertEquals(1, result.rowCount()); Row row = result.iterator().next(); @@ -112,9 +118,11 @@ public void testSerial8(TestContext ctx) { @Test public void testNumeric(TestContext ctx) { Async async = ctx.async(); - PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { + PgConnection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> { conn - .query("SELECT 919.999999999999999999999999999999999999::NUMERIC \"Numeric\", 'NaN'::NUMERIC \"NaN\"").execute(ctx.asyncAssertSuccess(result -> { + .query("SELECT 919.999999999999999999999999999999999999::NUMERIC \"Numeric\", 'NaN'::NUMERIC \"NaN\"") + .execute() + .onComplete(ctx.asyncAssertSuccess(result -> { Numeric numeric = Numeric.parse("919.999999999999999999999999999999999999"); Numeric nan = Numeric.parse("NaN"); ctx.assertEquals(1, result.size()); @@ -146,10 +154,12 @@ public void testNumeric(TestContext ctx) { private void testNumber(TestContext ctx, Number[] values, String type) { Async async = ctx.async(values.length); - PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { + PgConnection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> { for (Number value : values) { conn - .query("SELECT " + value + "::" + type + " \"col\"").execute(ctx.asyncAssertSuccess(result -> { + .query("SELECT " + value + "::" + type + " \"col\"") + .execute() + .onComplete(ctx.asyncAssertSuccess(result -> { ctx.assertEquals(1, result.size()); Row row = result.iterator().next(); ColumnChecker.checkColumn(0, "col") @@ -198,8 +208,11 @@ protected void testDecodeNumberArray(TestContext ctx, String columnName, Number... value) { Async async = ctx.async(); - PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.query("SELECT " + arrayData + " \"" + columnName + "\"").execute(ctx.asyncAssertSuccess(result -> { + PgConnection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> { + conn + .query("SELECT " + arrayData + " \"" + columnName + "\"") + .execute() + .onComplete(ctx.asyncAssertSuccess(result -> { ctx.assertEquals(1, result.size()); Row row = result.iterator().next(); ColumnChecker.checkColumn(0, columnName) @@ -219,11 +232,13 @@ protected void testDecodeNumberArray(TestContext ctx, @Test public void testDecodeEmptyArray(TestContext ctx) { Async async = ctx.async(); - PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { + PgConnection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> { // The extra column makes sure that reading the array remains confined in the value since we are doing // parsing of the array value - conn.query("SELECT '{}'::bigint[] \"array\", 1 \"Extra\"").execute( - ctx.asyncAssertSuccess(result -> { + conn + .query("SELECT '{}'::bigint[] \"array\", 1 \"Extra\"") + .execute() + .onComplete(ctx.asyncAssertSuccess(result -> { ColumnChecker.checkColumn(0, "array") .returns(Tuple::getValue, Row::getValue, (Object[]) new Long[0]) .returns(Tuple::getArrayOfShorts, Row::getArrayOfShorts, (Object[]) new Short[0]) diff --git a/vertx-pg-client/src/test/java/io/vertx/pgclient/data/PreparedStatementParamCoercionTest.java b/vertx-pg-client/src/test/java/io/vertx/pgclient/data/PreparedStatementParamCoercionTest.java index bc2db2152..9dd1a19a0 100644 --- a/vertx-pg-client/src/test/java/io/vertx/pgclient/data/PreparedStatementParamCoercionTest.java +++ b/vertx-pg-client/src/test/java/io/vertx/pgclient/data/PreparedStatementParamCoercionTest.java @@ -22,7 +22,7 @@ public class PreparedStatementParamCoercionTest extends DataTypeTestBase { @Test public void testCoerceSingleParam(TestContext ctx) { Async async = ctx.async(VALUES_TO_COERCE.length * SQL_TYPES_TO_COERCE_TO.length); - PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { + PgConnection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> { for (String sqlType : SQL_TYPES_TO_COERCE_TO) { for (Object value: VALUES_TO_COERCE) { assertCoerceParam(conn, ctx, "SELECT 1 \"result\" WHERE $1::" + sqlType + "=5", value, async::countDown); @@ -34,7 +34,7 @@ public void testCoerceSingleParam(TestContext ctx) { @Test public void testCoerceArrayParam(TestContext ctx) { Async async = ctx.async(VALUES_TO_COERCE.length * SQL_TYPES_TO_COERCE_TO.length); - PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { + PgConnection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> { for (String sqlType : SQL_TYPES_TO_COERCE_TO) { for (Object value: VALUES_TO_COERCE) { Object array = Array.newInstance(value.getClass(), 1); @@ -47,8 +47,9 @@ public void testCoerceArrayParam(TestContext ctx) { private void assertCoerceParam(PgConnection conn, TestContext ctx, String query, Object value, Runnable cont) { conn - .preparedQuery(query).execute(Tuple.of(value), - ctx.asyncAssertSuccess(result -> { + .preparedQuery(query) + .execute(Tuple.of(value)) + .onComplete(ctx.asyncAssertSuccess(result -> { ctx.assertEquals(1, result.size()); ctx.assertEquals(1, result.iterator().next().getInteger(0)); cont.run(); @@ -57,9 +58,12 @@ private void assertCoerceParam(PgConnection conn, TestContext ctx, String query, @Test public void testCoercionError(TestContext ctx) { - PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.prepare("SELECT $1::UUID", ctx.asyncAssertSuccess(pq -> { - pq.query().execute(Tuple.of("not-an-uuid"), ctx.asyncAssertFailure(res -> { + PgConnection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> { + conn.prepare("SELECT $1::UUID").onComplete(ctx.asyncAssertSuccess(pq -> { + pq + .query() + .execute(Tuple.of("not-an-uuid")) + .onComplete(ctx.asyncAssertFailure(res -> { })); })); })); diff --git a/vertx-pg-client/src/test/java/io/vertx/pgclient/data/SimpleQueryDataTypeCodecTestBase.java b/vertx-pg-client/src/test/java/io/vertx/pgclient/data/SimpleQueryDataTypeCodecTestBase.java index f30f3f5bc..5c0f9b4af 100644 --- a/vertx-pg-client/src/test/java/io/vertx/pgclient/data/SimpleQueryDataTypeCodecTestBase.java +++ b/vertx-pg-client/src/test/java/io/vertx/pgclient/data/SimpleQueryDataTypeCodecTestBase.java @@ -35,8 +35,11 @@ protected void testDecodeGeneric(TestContext ctx, ColumnChecker.SerializableBiFunction byNameGetter, T expected) { Async async = ctx.async(); - PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.query("SELECT '" + data + "' :: " + dataType + " \"" + columnName + "\"").execute(ctx.asyncAssertSuccess(result -> { + PgConnection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> { + conn + .query("SELECT '" + data + "' :: " + dataType + " \"" + columnName + "\"") + .execute() + .onComplete(ctx.asyncAssertSuccess(result -> { ctx.assertEquals(1, result.size()); Row row = result.iterator().next(); ColumnChecker.checkColumn(0, columnName) @@ -75,10 +78,15 @@ protected void testDecodeGenericArray(TestContext ctx, String columnName, ColumnChecker checker) { Async async = ctx.async(); - PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.query("SET TIME ZONE 'UTC'").execute( - ctx.asyncAssertSuccess(res -> { - conn.query("SELECT " + arrayData + " \"" + columnName + "\"").execute(ctx.asyncAssertSuccess(result -> { + PgConnection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> { + conn + .query("SET TIME ZONE 'UTC'") + .execute() + .onComplete(ctx.asyncAssertSuccess(res -> { + conn + .query("SELECT " + arrayData + " \"" + columnName + "\"") + .execute() + .onComplete(ctx.asyncAssertSuccess(result -> { ctx.assertEquals(1, result.size()); Row row = result.iterator().next(); checker.forRow(row); @@ -95,10 +103,16 @@ protected void testDecodeXXXArray(TestContext ctx, ColumnChecker.SerializableBiFunction byNameGetter, Object... expected) { Async async = ctx.async(); - PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.query("SET TIME ZONE 'UTC'").execute( + PgConnection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> { + conn + .query("SET TIME ZONE 'UTC'") + .execute() + .onComplete( ctx.asyncAssertSuccess(res -> { - conn.query("SELECT \"" + columnName + "\" FROM \"" + tableName + "\" WHERE \"id\" = 1").execute( + conn + .query("SELECT \"" + columnName + "\" FROM \"" + tableName + "\" WHERE \"id\" = 1") + .execute() + .onComplete( ctx.asyncAssertSuccess(result -> { ColumnChecker.checkColumn(0, columnName) .returns(Tuple::getValue, Row::getValue, expected) diff --git a/vertx-pg-client/src/test/java/io/vertx/pgclient/data/TsTypesExtendedCodecTest.java b/vertx-pg-client/src/test/java/io/vertx/pgclient/data/TsTypesExtendedCodecTest.java index a147436b6..ffa53bcd1 100644 --- a/vertx-pg-client/src/test/java/io/vertx/pgclient/data/TsTypesExtendedCodecTest.java +++ b/vertx-pg-client/src/test/java/io/vertx/pgclient/data/TsTypesExtendedCodecTest.java @@ -13,12 +13,15 @@ public class TsTypesExtendedCodecTest extends ExtendedQueryDataTypeCodecTestBase @Test public void test_tsquery_and_tsvector(TestContext ctx) { Async async = ctx.async(); - PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.prepare("SELECT to_tsvector('english', $1 ) @@ to_tsquery('english', $2 ) as \"TsQuery\"", + PgConnection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> { + conn.prepare("SELECT to_tsvector('english', $1 ) @@ to_tsquery('english', $2 ) as \"TsQuery\"").onComplete( ctx.asyncAssertSuccess(p -> { - p.query().execute(Tuple.tuple() + p + .query() + .execute(Tuple.tuple() .addString("postgraduate") - .addString("postgres:*"), ctx.asyncAssertSuccess(result -> { + .addString("postgres:*")) + .onComplete(ctx.asyncAssertSuccess(result -> { ctx.assertEquals(1, result.size()); ctx.assertEquals(1, result.rowCount()); Row row = result.iterator().next(); @@ -35,11 +38,14 @@ public void test_tsquery_and_tsvector(TestContext ctx) { @Test public void test_tsvector(TestContext ctx) { Async async = ctx.async(); - PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.prepare("SELECT c \"TsVector\" FROM ( VALUES ( to_tsvector ('english', $1 ) )) as t (c)", + PgConnection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> { + conn.prepare("SELECT c \"TsVector\" FROM ( VALUES ( to_tsvector ('english', $1 ) )) as t (c)").onComplete( ctx.asyncAssertSuccess(p -> { - p.query().execute(Tuple.tuple() - .addString("postgraduate"), ctx.asyncAssertSuccess(result -> { + p + .query() + .execute(Tuple.tuple() + .addString("postgraduate")) + .onComplete(ctx.asyncAssertSuccess(result -> { ctx.assertEquals(1, result.size()); ctx.assertEquals(1, result.rowCount()); Row row = result.iterator().next(); @@ -57,12 +63,15 @@ public void test_tsvector(TestContext ctx) { @Test public void test_tsvector_array(TestContext ctx) { Async async = ctx.async(); - PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.prepare("SELECT c \"TsVector\" FROM ( VALUES ( ARRAY[to_tsvector ('english', $1 ), to_tsvector ('english', $2 )] )) as t (c) GROUP BY c", + PgConnection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> { + conn.prepare("SELECT c \"TsVector\" FROM ( VALUES ( ARRAY[to_tsvector ('english', $1 ), to_tsvector ('english', $2 )] )) as t (c) GROUP BY c").onComplete( ctx.asyncAssertSuccess(p -> { - p.query().execute(Tuple.tuple() + p + .query() + .execute(Tuple.tuple() .addString("postgraduate") - .addString("a fat cat sat on a mat and ate a fat rat"), ctx.asyncAssertSuccess(result -> { + .addString("a fat cat sat on a mat and ate a fat rat")) + .onComplete(ctx.asyncAssertSuccess(result -> { ctx.assertEquals(1, result.size()); ctx.assertEquals(1, result.rowCount()); Row row = result.iterator().next(); @@ -81,11 +90,14 @@ public void test_tsvector_array(TestContext ctx) { @Test public void test_tsquery(TestContext ctx) { Async async = ctx.async(); - PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.prepare("SELECT c \"TsQuery\" FROM ( VALUES ( to_tsquery ('english', $1 ) )) as t (c)", + PgConnection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> { + conn.prepare("SELECT c \"TsQuery\" FROM ( VALUES ( to_tsquery ('english', $1 ) )) as t (c)").onComplete( ctx.asyncAssertSuccess(p -> { - p.query().execute(Tuple.tuple() - .addString("Fat:ab & Cats"), ctx.asyncAssertSuccess(result -> { + p + .query() + .execute(Tuple.tuple() + .addString("Fat:ab & Cats")) + .onComplete(ctx.asyncAssertSuccess(result -> { ctx.assertEquals(1, result.size()); ctx.assertEquals(1, result.rowCount()); Row row = result.iterator().next(); @@ -103,12 +115,15 @@ public void test_tsquery(TestContext ctx) { @Test public void test_tsquery_array(TestContext ctx) { Async async = ctx.async(); - PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.prepare("SELECT c \"TsQuery\" FROM ( VALUES ( ARRAY[to_tsquery ('english', $1 ), to_tsquery ('english', $2 )] )) as t (c)", + PgConnection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> { + conn.prepare("SELECT c \"TsQuery\" FROM ( VALUES ( ARRAY[to_tsquery ('english', $1 ), to_tsquery ('english', $2 )] )) as t (c)").onComplete( ctx.asyncAssertSuccess(p -> { - p.query().execute(Tuple.tuple() + p + .query() + .execute(Tuple.tuple() .addString("Fat:ab & Cats") - .addString("super:*"), ctx.asyncAssertSuccess(result -> { + .addString("super:*")) + .onComplete(ctx.asyncAssertSuccess(result -> { ctx.assertEquals(1, result.size()); ctx.assertEquals(1, result.rowCount()); Row row = result.iterator().next(); diff --git a/vertx-pg-client/src/test/java/io/vertx/pgclient/data/TsTypesSimpleCodecTest.java b/vertx-pg-client/src/test/java/io/vertx/pgclient/data/TsTypesSimpleCodecTest.java index b4c0c24f5..347384dc8 100644 --- a/vertx-pg-client/src/test/java/io/vertx/pgclient/data/TsTypesSimpleCodecTest.java +++ b/vertx-pg-client/src/test/java/io/vertx/pgclient/data/TsTypesSimpleCodecTest.java @@ -16,8 +16,11 @@ public class TsTypesSimpleCodecTest extends SimpleQueryDataTypeCodecTestBase { @Test public void test_ts_query(TestContext ctx) { Async async = ctx.async(); - PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.query("SELECT 'fat & rat'::tsquery as \"TsQuery\"").execute(ctx.asyncAssertSuccess(result -> { + PgConnection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> { + conn + .query("SELECT 'fat & rat'::tsquery as \"TsQuery\"") + .execute() + .onComplete(ctx.asyncAssertSuccess(result -> { ctx.assertEquals(1, result.size()); Row row = result.iterator().next(); String expected = "'fat' & 'rat'"; @@ -34,8 +37,11 @@ public void test_ts_query(TestContext ctx) { @Test public void test_ts_query_null(TestContext ctx) { Async async = ctx.async(); - PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.query("SELECT null::tsquery as \"TsQuery\"").execute(ctx.asyncAssertSuccess(result -> { + PgConnection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> { + conn + .query("SELECT null::tsquery as \"TsQuery\"") + .execute() + .onComplete(ctx.asyncAssertSuccess(result -> { ctx.assertEquals(1, result.size()); Row row = result.iterator().next(); String expected = null; @@ -50,8 +56,11 @@ public void test_ts_query_null(TestContext ctx) { @Test public void test_ts_query_array(TestContext ctx) { Async async = ctx.async(); - PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.query("SELECT ARRAY ['fat & rat'::tsquery ] as \"TsQuery\"").execute(ctx.asyncAssertSuccess(result -> { + PgConnection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> { + conn + .query("SELECT ARRAY ['fat & rat'::tsquery ] as \"TsQuery\"") + .execute() + .onComplete(ctx.asyncAssertSuccess(result -> { ctx.assertEquals(1, result.size()); Row row = result.iterator().next(); System.out.println(row.getValue(0)); @@ -70,8 +79,11 @@ public void test_ts_query_array(TestContext ctx) { @Test public void test_ts_vector_simple(TestContext ctx) { Async async = ctx.async(); - PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.query("SELECT 'a fat cat sat on a mat and ate a fat rat'::tsvector as \"TsVector\"").execute(ctx.asyncAssertSuccess(result -> { + PgConnection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> { + conn + .query("SELECT 'a fat cat sat on a mat and ate a fat rat'::tsvector as \"TsVector\"") + .execute() + .onComplete(ctx.asyncAssertSuccess(result -> { ctx.assertEquals(1, result.size()); Row row = result.iterator().next(); String expected = "'a' 'and' 'ate' 'cat' 'fat' 'mat' 'on' 'rat' 'sat'"; @@ -88,8 +100,11 @@ public void test_ts_vector_simple(TestContext ctx) { @Test public void test_ts_vector_null(TestContext ctx) { Async async = ctx.async(); - PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.query("SELECT null::tsvector as \"TsVector\"").execute(ctx.asyncAssertSuccess(result -> { + PgConnection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> { + conn + .query("SELECT null::tsvector as \"TsVector\"") + .execute() + .onComplete(ctx.asyncAssertSuccess(result -> { ctx.assertEquals(1, result.size()); Row row = result.iterator().next(); ColumnChecker.checkColumn(0, "TsVector") @@ -103,8 +118,11 @@ public void test_ts_vector_null(TestContext ctx) { @Test public void test_ts_vector_parsed(TestContext ctx) { Async async = ctx.async(); - PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.query("SELECT to_tsvector('english', 'The Fat Rats') as \"TsVector\"").execute(ctx.asyncAssertSuccess(result -> { + PgConnection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> { + conn + .query("SELECT to_tsvector('english', 'The Fat Rats') as \"TsVector\"") + .execute() + .onComplete(ctx.asyncAssertSuccess(result -> { ctx.assertEquals(1, result.size()); Row row = result.iterator().next(); String expected = "'fat':2 'rat':3"; @@ -121,8 +139,11 @@ public void test_ts_vector_parsed(TestContext ctx) { @Test public void test_ts_vector_array(TestContext ctx) { Async async = ctx.async(); - PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.query("SELECT ARRAY['a fat cat sat on a mat and ate a fat rat'::tsvector] as \"TsVector\"").execute(ctx.asyncAssertSuccess(result -> { + PgConnection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> { + conn + .query("SELECT ARRAY['a fat cat sat on a mat and ate a fat rat'::tsvector] as \"TsVector\"") + .execute() + .onComplete(ctx.asyncAssertSuccess(result -> { ctx.assertEquals(1, result.size()); Row row = result.iterator().next(); String[] expected = new String[]{"'a' 'and' 'ate' 'cat' 'fat' 'mat' 'on' 'rat' 'sat'"}; diff --git a/vertx-pg-client/src/test/java/io/vertx/pgclient/data/UUIDTypeExtendedCodecTest.java b/vertx-pg-client/src/test/java/io/vertx/pgclient/data/UUIDTypeExtendedCodecTest.java index 852568ed9..0b05c0ee0 100644 --- a/vertx-pg-client/src/test/java/io/vertx/pgclient/data/UUIDTypeExtendedCodecTest.java +++ b/vertx-pg-client/src/test/java/io/vertx/pgclient/data/UUIDTypeExtendedCodecTest.java @@ -20,13 +20,13 @@ public void testDecodeUUID(TestContext ctx) { @Test public void testEncodeUUID(TestContext ctx) { Async async = ctx.async(); - PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.prepare("UPDATE \"CharacterDataType\" SET \"uuid\" = $1 WHERE \"id\" = $2 RETURNING \"uuid\"", + PgConnection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> { + conn.prepare("UPDATE \"CharacterDataType\" SET \"uuid\" = $1 WHERE \"id\" = $2 RETURNING \"uuid\"").onComplete( ctx.asyncAssertSuccess(p -> { UUID uuid = UUID.fromString("92b53cf1-2ad0-49f9-be9d-ca48966e43ee"); - p.query().execute(Tuple.tuple() - .addUUID(uuid) - .addInteger(2), ctx.asyncAssertSuccess(result -> { + p.query() + .execute(Tuple.tuple().addUUID(uuid).addInteger(2)) + .onComplete(ctx.asyncAssertSuccess(result -> { ctx.assertEquals(1, result.size()); ctx.assertEquals(1, result.rowCount()); Row row = result.iterator().next(); @@ -48,14 +48,13 @@ public void testDecodeUUIDArray(TestContext ctx) { @Test public void testEncodeUUIDArray(TestContext ctx) { Async async = ctx.async(); - PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { - conn.prepare("UPDATE \"ArrayDataType\" SET \"UUID\" = $1 WHERE \"id\" = $2 RETURNING \"UUID\"", + PgConnection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> { + conn.prepare("UPDATE \"ArrayDataType\" SET \"UUID\" = $1 WHERE \"id\" = $2 RETURNING \"UUID\"").onComplete( ctx.asyncAssertSuccess(p -> { final UUID uuid = UUID.fromString("6f790482-b5bd-438b-a8b7-4a0bed747011"); - p.query().execute(Tuple.tuple() - .addArrayOfUUID(new UUID[]{uuid}) - .addInteger(2) - , ctx.asyncAssertSuccess(result -> { + p.query() + .execute(Tuple.tuple().addArrayOfUUID(new UUID[]{uuid}).addInteger(2)) + .onComplete(ctx.asyncAssertSuccess(result -> { ColumnChecker.checkColumn(0, "UUID") .returns(Tuple::getValue, Row::getValue, new UUID[]{uuid}) .returns(Tuple::getArrayOfUUIDs, Row::getArrayOfUUIDs, new UUID[]{uuid}) diff --git a/vertx-pg-client/src/test/java/io/vertx/pgclient/tck/ClientConfig.java b/vertx-pg-client/src/test/java/io/vertx/pgclient/tck/ClientConfig.java index c6da6f955..da2d04def 100644 --- a/vertx-pg-client/src/test/java/io/vertx/pgclient/tck/ClientConfig.java +++ b/vertx-pg-client/src/test/java/io/vertx/pgclient/tck/ClientConfig.java @@ -36,7 +36,7 @@ Connector connect(Vertx vertx, SqlConnectOptions options) { return new Connector() { @Override public void connect(Handler> handler) { - PgConnection.connect(vertx, new PgConnectOptions(options), ar -> { + PgConnection.connect(vertx, new PgConnectOptions(options)).onComplete(ar -> { if (ar.succeeded()) { handler.handle(Future.succeededFuture(ar.result())); } else { @@ -58,7 +58,7 @@ Connector connect(Vertx vertx, SqlConnectOptions options) { return new Connector() { @Override public void connect(Handler> handler) { - pool.getConnection(ar -> { + pool.getConnection().onComplete(ar -> { if (ar.succeeded()) { handler.handle(Future.succeededFuture(ar.result())); } else { diff --git a/vertx-pg-client/src/test/java/io/vertx/pgclient/tck/PgTransactionTest.java b/vertx-pg-client/src/test/java/io/vertx/pgclient/tck/PgTransactionTest.java index f098f50ed..9dc33bafd 100644 --- a/vertx-pg-client/src/test/java/io/vertx/pgclient/tck/PgTransactionTest.java +++ b/vertx-pg-client/src/test/java/io/vertx/pgclient/tck/PgTransactionTest.java @@ -64,10 +64,18 @@ protected String statement(String... parts) { public void testFailureWithPendingQueries(TestContext ctx) { Async async = ctx.async(); connector.accept(ctx.asyncAssertSuccess(res -> { - res.client.query("SELECT whatever from DOES_NOT_EXIST").execute(ctx.asyncAssertFailure(v -> { + res.client + .query("SELECT whatever from DOES_NOT_EXIST") + .execute() + .onComplete(ctx.asyncAssertFailure(v -> { })); - res.client.query("SELECT id, val FROM mutable").execute(ctx.asyncAssertFailure(err -> { - res.tx.rollback(ctx.asyncAssertSuccess(v -> { + res.client + .query("SELECT id, val FROM mutable") + .execute() + .onComplete(ctx.asyncAssertFailure(err -> { + res.tx + .rollback() + .onComplete(ctx.asyncAssertSuccess(v -> { async.complete(); })); })); diff --git a/vertx-sql-client-templates/src/test/java/io/vertx/sqlclient/templates/DataObjectTypesTest.java b/vertx-sql-client-templates/src/test/java/io/vertx/sqlclient/templates/DataObjectTypesTest.java index cba0690d5..e3f145b51 100644 --- a/vertx-sql-client-templates/src/test/java/io/vertx/sqlclient/templates/DataObjectTypesTest.java +++ b/vertx-sql-client-templates/src/test/java/io/vertx/sqlclient/templates/DataObjectTypesTest.java @@ -140,7 +140,7 @@ private void testNumber(TestContext ctx, String sqlType, I value, O expec SqlTemplate, RowSet> template = SqlTemplate .forQuery(connection, "SELECT #{value} :: " + sqlType + " \"" + column + "\"") .mapTo(TestDataObjectRowMapper.INSTANCE); - template.execute(Collections.singletonMap("value", value), ctx.asyncAssertSuccess(result -> { + template.execute(Collections.singletonMap("value", value)).onComplete(ctx.asyncAssertSuccess(result -> { ctx.assertEquals(1, result.size()); ctx.assertEquals(expected, getter.apply(result.iterator().next())); async.complete(); diff --git a/vertx-sql-client-templates/src/test/java/io/vertx/sqlclient/templates/PgClientTest.java b/vertx-sql-client-templates/src/test/java/io/vertx/sqlclient/templates/PgClientTest.java index 6288c2b67..58481b76c 100644 --- a/vertx-sql-client-templates/src/test/java/io/vertx/sqlclient/templates/PgClientTest.java +++ b/vertx-sql-client-templates/src/test/java/io/vertx/sqlclient/templates/PgClientTest.java @@ -42,7 +42,9 @@ public void testQuery(TestContext ctx) { Map params = new HashMap<>(); params.put("id", 1); params.put("randomnumber", 10); - template.execute(params, ctx.asyncAssertSuccess(res -> { + template + .execute(params) + .onComplete(ctx.asyncAssertSuccess(res -> { ctx.assertEquals(1, res.size()); Row row = res.iterator().next(); ctx.assertEquals(1, row.getInteger(0)); @@ -60,7 +62,9 @@ public void testBatch(TestContext ctx) { Map params2 = new HashMap<>(); params1.put("id", 2); params1.put("randomnumber", 20); - template.executeBatch(Arrays.asList(params1, params2), ctx.asyncAssertSuccess(res -> { + template + .executeBatch(Arrays.asList(params1, params2)) + .onComplete(ctx.asyncAssertSuccess(res -> { ctx.assertEquals(1, res.size()); Row row = res.iterator().next(); ctx.assertEquals(2, row.getInteger(0)); @@ -83,7 +87,9 @@ public void testQueryMap(TestContext ctx) { .forQuery(connection, "SELECT #{id} :: INT4 \"id\", #{randomnumber} :: INT4 \"randomnumber\"") .mapFrom(World.class) .mapTo(World.class); - template.execute(w, ctx.asyncAssertSuccess(res -> { + template + .execute(w) + .onComplete(ctx.asyncAssertSuccess(res -> { ctx.assertEquals(1, res.size()); World world = res.iterator().next(); ctx.assertEquals(1, world.id); @@ -98,7 +104,9 @@ public void testLocalDateTimeWithJackson(TestContext ctx) { .forQuery(connection, "SELECT #{value} :: TIMESTAMP WITHOUT TIME ZONE \"localDateTime\"") .mapTo(LocalDateTimePojo.class); LocalDateTime ldt = LocalDateTime.parse("2017-05-14T19:35:58.237666"); - template.execute(Collections.singletonMap("value", ldt), ctx.asyncAssertSuccess(result -> { + template + .execute(Collections.singletonMap("value", ldt)) + .onComplete(ctx.asyncAssertSuccess(result -> { ctx.assertEquals(1, result.size()); ctx.assertEquals(ldt, result.iterator().next().localDateTime); })); @@ -110,7 +118,9 @@ public void testLocalDateTimeWithCodegen(TestContext ctx) { .forQuery(connection, "SELECT #{value} :: TIMESTAMP WITHOUT TIME ZONE \"localDateTime\"") .mapTo(LocalDateTimeDataObjectRowMapper.INSTANCE); LocalDateTime ldt = LocalDateTime.parse("2017-05-14T19:35:58.237666"); - template.execute(Collections.singletonMap("value", ldt), ctx.asyncAssertSuccess(result -> { + template + .execute(Collections.singletonMap("value", ldt)) + .onComplete(ctx.asyncAssertSuccess(result -> { ctx.assertEquals(1, result.size()); ctx.assertEquals(ldt, result.iterator().next().getLocalDateTime()); })); @@ -122,7 +132,9 @@ public void testLocalDateTimeWithCodegenCollector(TestContext ctx) { .forQuery(connection, "SELECT #{value} :: TIMESTAMP WITHOUT TIME ZONE \"localDateTime\"") .collecting(LocalDateTimeDataObjectRowMapper.COLLECTOR); LocalDateTime ldt = LocalDateTime.parse("2017-05-14T19:35:58.237666"); - template.execute(Collections.singletonMap("value", ldt), ctx.asyncAssertSuccess(result -> { + template + .execute(Collections.singletonMap("value", ldt)) + .onComplete(ctx.asyncAssertSuccess(result -> { ctx.assertEquals(1, result.size()); ctx.assertEquals(ldt, result.value().get(0).getLocalDateTime()); })); @@ -161,7 +173,9 @@ public void testAnemicJson(TestContext ctx) { .put("integer", 4) .put("string", "hello world") .put("boolean", true); - template.execute(params, ctx.asyncAssertSuccess(res -> { + template + .execute(params) + .onComplete(ctx.asyncAssertSuccess(res -> { ctx.assertEquals(1, res.size()); Row row = res.iterator().next(); ctx.assertEquals(4, row.getInteger(0)); @@ -172,8 +186,14 @@ public void testAnemicJson(TestContext ctx) { @Test public void testInsertJsonObject(TestContext ctx) { - connection.query("DROP TABLE IF EXISTS distributors").execute(ctx.asyncAssertSuccess(dropped -> { - connection.query("CREATE TABLE distributors(name VARCHAR(40), attrs JSONB)").execute(ctx.asyncAssertSuccess(created -> { + connection + .query("DROP TABLE IF EXISTS distributors") + .execute() + .onComplete(ctx.asyncAssertSuccess(dropped -> { + connection + .query("CREATE TABLE distributors(name VARCHAR(40), attrs JSONB)") + .execute() + .onComplete(ctx.asyncAssertSuccess(created -> { MyObject value = new MyObject(); value.setName("foo"); @@ -188,8 +208,12 @@ public void testInsertJsonObject(TestContext ctx) { SqlTemplate .forQuery(connection, "INSERT INTO distributors (name,attrs) VALUES(#{name},#{attributes})") .mapFrom(MyObject.class) - .execute(value, ctx.asyncAssertSuccess(inserted -> { - connection.query("SELECT name, attrs FROM distributors").execute(ctx.asyncAssertSuccess(rows -> { + .execute(value) + .onComplete(ctx.asyncAssertSuccess(inserted -> { + connection + .query("SELECT name, attrs FROM distributors") + .execute() + .onComplete(ctx.asyncAssertSuccess(rows -> { ctx.verify(v -> { assertEquals(1, rows.size()); Row row = rows.iterator().next(); diff --git a/vertx-sql-client-templates/src/test/java/io/vertx/sqlclient/templates/PgTemplateTestBase.java b/vertx-sql-client-templates/src/test/java/io/vertx/sqlclient/templates/PgTemplateTestBase.java index f031869a2..c4addaa2d 100644 --- a/vertx-sql-client-templates/src/test/java/io/vertx/sqlclient/templates/PgTemplateTestBase.java +++ b/vertx-sql-client-templates/src/test/java/io/vertx/sqlclient/templates/PgTemplateTestBase.java @@ -59,7 +59,7 @@ public static PgConnectOptions connectOptions() { public void setup(TestContext ctx) { vertx = Vertx.vertx(); Async async = ctx.async(); - PgConnection.connect(vertx, connectOptions(), ctx.asyncAssertSuccess(conn -> { + PgConnection.connect(vertx, connectOptions()).onComplete(ctx.asyncAssertSuccess(conn -> { connection = conn; async.complete(); })); @@ -71,7 +71,7 @@ public void teardown(TestContext ctx) { if (connection != null) { connection.close(); } - vertx.close(ctx.asyncAssertSuccess()); + vertx.close().onComplete(ctx.asyncAssertSuccess()); } protected void testGet(TestContext ctx, @@ -88,7 +88,9 @@ protected void testGet(TestContext ctx, .forQuery(connection, "SELECT #{" + paramName + "} :: " + sqlType + " \"" + column + "\"") .mapFrom(paramsMapper) .mapTo(rowMapper); - template.execute(params, ctx.asyncAssertSuccess(result -> { + template + .execute(params) + .onComplete(ctx.asyncAssertSuccess(result -> { ctx.assertEquals(1, result.size()); ctx.assertEquals(expected, extractor.apply(result.iterator().next())); async.complete(); diff --git a/vertx-sql-client/src/main/java/io/vertx/sqlclient/impl/PoolBase.java b/vertx-sql-client/src/main/java/io/vertx/sqlclient/impl/PoolBase.java index fa0992b51..25f8a4628 100644 --- a/vertx-sql-client/src/main/java/io/vertx/sqlclient/impl/PoolBase.java +++ b/vertx-sql-client/src/main/java/io/vertx/sqlclient/impl/PoolBase.java @@ -53,7 +53,9 @@ public void group(Handler block) { @Override public void getConnection(Handler> handler) { - delegate.getConnection(handler); + delegate + .getConnection() + .onComplete(handler); } @Override diff --git a/vertx-sql-client/src/test/java/io/vertx/sqlclient/ProxyServer.java b/vertx-sql-client/src/test/java/io/vertx/sqlclient/ProxyServer.java index 020500e2c..0ffd41a8c 100644 --- a/vertx-sql-client/src/test/java/io/vertx/sqlclient/ProxyServer.java +++ b/vertx-sql-client/src/test/java/io/vertx/sqlclient/ProxyServer.java @@ -125,12 +125,12 @@ public ProxyServer proxyHandler(Handler proxyHandler) { } public void listen(int port, String host, Handler> completionHandler) { - server.listen(port, host, ar -> completionHandler.handle(ar.mapEmpty())); + server.listen(port, host).onComplete(ar -> completionHandler.handle(ar.mapEmpty())); } private void handle(NetSocket clientSocket) { clientSocket.pause(); - client.connect(port, host, ar -> { + client.connect(port, host).onComplete(ar -> { if (ar.succeeded()) { NetSocket serverSocket = ar.result(); serverSocket.pause(); diff --git a/vertx-sql-client/src/test/java/io/vertx/sqlclient/tck/BinaryDataTypeDecodeTestBase.java b/vertx-sql-client/src/test/java/io/vertx/sqlclient/tck/BinaryDataTypeDecodeTestBase.java index 362962cf1..8c9ee5a80 100644 --- a/vertx-sql-client/src/test/java/io/vertx/sqlclient/tck/BinaryDataTypeDecodeTestBase.java +++ b/vertx-sql-client/src/test/java/io/vertx/sqlclient/tck/BinaryDataTypeDecodeTestBase.java @@ -91,7 +91,8 @@ protected void testDecodeGeneric(TestContext ctx, connector.connect(ctx.asyncAssertSuccess(conn -> { conn .preparedQuery("SELECT " + columnName + " FROM basicdatatype WHERE id = 1") - .execute(ctx.asyncAssertSuccess(result -> { + .execute() + .onComplete(ctx.asyncAssertSuccess(result -> { ctx.assertEquals(1, result.size()); Row row = result.iterator().next(); ctx.assertEquals(expected, row.getValue(0)); @@ -120,7 +121,9 @@ public void testNullValues(TestContext ctx) { "test_varchar," + "test_date," + "test_time " + - "from basicdatatype where id = 3").execute(ctx.asyncAssertSuccess(result -> { + "from basicdatatype where id = 3") + .execute() + .onComplete(ctx.asyncAssertSuccess(result -> { ctx.assertEquals(1, result.size()); Row row = result.iterator().next(); ctx.assertEquals(12, row.size()); @@ -148,7 +151,9 @@ public void testSelectAll(TestContext ctx) { "test_varchar," + "test_date," + "test_time " + - "from basicdatatype where id = 1").execute(ctx.asyncAssertSuccess(result -> { + "from basicdatatype where id = 1") + .execute() + .onComplete(ctx.asyncAssertSuccess(result -> { ctx.assertEquals(1, result.size()); Row row = result.iterator().next(); ctx.assertEquals(12, row.size()); @@ -196,7 +201,9 @@ public void testToJsonObject(TestContext ctx) { "test_char," + "test_varchar," + "test_date " + - "from basicdatatype where id = 1").execute(ctx.asyncAssertSuccess(result -> { + "from basicdatatype where id = 1") + .execute() + .onComplete(ctx.asyncAssertSuccess(result -> { ctx.assertEquals(1, result.size()); Row row = result.iterator().next(); JsonObject json = row.toJson(); diff --git a/vertx-sql-client/src/test/java/io/vertx/sqlclient/tck/BinaryDataTypeEncodeTestBase.java b/vertx-sql-client/src/test/java/io/vertx/sqlclient/tck/BinaryDataTypeEncodeTestBase.java index 13b770086..c7b2797db 100644 --- a/vertx-sql-client/src/test/java/io/vertx/sqlclient/tck/BinaryDataTypeEncodeTestBase.java +++ b/vertx-sql-client/src/test/java/io/vertx/sqlclient/tck/BinaryDataTypeEncodeTestBase.java @@ -113,11 +113,13 @@ public void testNullValues(TestContext ctx) { .addValue(null) .addValue(null) .addValue(null) - .addValue(null), + .addValue(null)) + .onComplete( ctx.asyncAssertSuccess(updateResult -> { conn .preparedQuery("SELECT * FROM basicdatatype WHERE id = 2") - .execute(ctx.asyncAssertSuccess(result -> { + .execute() + .onComplete(ctx.asyncAssertSuccess(result -> { ctx.assertEquals(1, result.size()); Row row = result.iterator().next(); ctx.assertEquals(13, row.size()); @@ -139,10 +141,12 @@ protected void testEncodeGeneric(TestContext ctx, connector.connect(ctx.asyncAssertSuccess(conn -> { conn .preparedQuery(statement("UPDATE basicdatatype SET " + columnName + " = ", " WHERE id = 2")) - .execute(Tuple.tuple().addValue(expected), ctx.asyncAssertSuccess(updateResult -> { + .execute(Tuple.tuple().addValue(expected)) + .onComplete(ctx.asyncAssertSuccess(updateResult -> { conn .preparedQuery("SELECT " + columnName + " FROM basicdatatype WHERE id = 2") - .execute(ctx.asyncAssertSuccess(result -> { + .execute() + .onComplete(ctx.asyncAssertSuccess(result -> { ctx.assertEquals(1, result.size()); Row row = result.iterator().next(); ctx.assertEquals(1, row.size()); diff --git a/vertx-sql-client/src/test/java/io/vertx/sqlclient/tck/CollectorTestBase.java b/vertx-sql-client/src/test/java/io/vertx/sqlclient/tck/CollectorTestBase.java index 5a13c897a..d1cf6a69e 100644 --- a/vertx-sql-client/src/test/java/io/vertx/sqlclient/tck/CollectorTestBase.java +++ b/vertx-sql-client/src/test/java/io/vertx/sqlclient/tck/CollectorTestBase.java @@ -50,7 +50,7 @@ public void setUp() throws Exception { @After public void tearDown(TestContext ctx) { connector.close(); - vertx.close(ctx.asyncAssertSuccess()); + vertx.close().onComplete(ctx.asyncAssertSuccess()); } @Test @@ -72,7 +72,8 @@ public void testSimpleQuery(TestContext ctx) { connector.connect(ctx.asyncAssertSuccess(conn -> { conn.query("SELECT * FROM collector_test WHERE id = 1") .collecting(collector) - .execute(ctx.asyncAssertSuccess(result -> { + .execute() + .onComplete(ctx.asyncAssertSuccess(result -> { Map map = result.value(); TestingCollectorObject actual = map.get(1); ctx.assertEquals(expected, actual); @@ -100,7 +101,8 @@ public void testPreparedQuery(TestContext ctx) { connector.connect(ctx.asyncAssertSuccess(conn -> { conn.preparedQuery("SELECT * FROM collector_test WHERE id = 1") .collecting(collector) - .execute(ctx.asyncAssertSuccess(result -> { + .execute() + .onComplete(ctx.asyncAssertSuccess(result -> { Map map = result.value(); TestingCollectorObject actual = map.get(1); ctx.assertEquals(expected, actual); @@ -185,7 +187,8 @@ private void testCollectorFailure(TestContext ctx, Throwable cause, Collector { conn.query("SELECT * FROM collector_test WHERE id = 1") .collecting(collector) - .execute(ctx.asyncAssertFailure(result -> { + .execute() + .onComplete(ctx.asyncAssertFailure(result -> { ctx.assertEquals(cause, result); conn.close(); })); diff --git a/vertx-sql-client/src/test/java/io/vertx/sqlclient/tck/ConnectionAutoRetryTestBase.java b/vertx-sql-client/src/test/java/io/vertx/sqlclient/tck/ConnectionAutoRetryTestBase.java index ce4749890..e045aa40d 100644 --- a/vertx-sql-client/src/test/java/io/vertx/sqlclient/tck/ConnectionAutoRetryTestBase.java +++ b/vertx-sql-client/src/test/java/io/vertx/sqlclient/tck/ConnectionAutoRetryTestBase.java @@ -49,7 +49,7 @@ public void setUp() throws Exception { @After public void tearDown(TestContext ctx) { - vertx.close(ctx.asyncAssertSuccess()); + vertx.close().onComplete(ctx.asyncAssertSuccess()); } protected abstract void initialConnector(int proxyPort); diff --git a/vertx-sql-client/src/test/java/io/vertx/sqlclient/tck/ConnectionTestBase.java b/vertx-sql-client/src/test/java/io/vertx/sqlclient/tck/ConnectionTestBase.java index b54bc1e36..36351b0d7 100644 --- a/vertx-sql-client/src/test/java/io/vertx/sqlclient/tck/ConnectionTestBase.java +++ b/vertx-sql-client/src/test/java/io/vertx/sqlclient/tck/ConnectionTestBase.java @@ -41,7 +41,7 @@ public void setUp() throws Exception { @After public void tearDown(TestContext ctx) { - vertx.close(ctx.asyncAssertSuccess()); + vertx.close().onComplete(ctx.asyncAssertSuccess()); } @Test @@ -79,7 +79,7 @@ public void testClose(TestContext ctx) { conn.closeHandler(v -> { closedAsync.complete(); }); - conn.close(ctx.asyncAssertSuccess(v -> closeAsync.complete())); + conn.close().onComplete(ctx.asyncAssertSuccess(v -> closeAsync.complete())); })); closedAsync.await(); } @@ -89,7 +89,9 @@ public void testClose(TestContext ctx) { public void testCloseWithErrorInProgress(TestContext ctx) { Async async = ctx.async(2); connect(ctx.asyncAssertSuccess(conn -> { - conn.query("SELECT whatever from DOES_NOT_EXIST").execute(ctx.asyncAssertFailure(err -> { + conn.query("SELECT whatever from DOES_NOT_EXIST") + .execute() + .onComplete(ctx.asyncAssertFailure(err -> { ctx.assertEquals(2, async.count()); async.countDown(); })); @@ -106,7 +108,9 @@ public void testCloseWithErrorInProgress(TestContext ctx) { public void testCloseWithQueryInProgress(TestContext ctx) { Async async = ctx.async(2); connect(ctx.asyncAssertSuccess(conn -> { - conn.query("SELECT id, message from immutable").execute(ctx.asyncAssertSuccess(result -> { + conn.query("SELECT id, message from immutable") + .execute() + .onComplete(ctx.asyncAssertSuccess(result -> { ctx.assertEquals(2, async.count()); ctx.assertEquals(12, result.size()); async.countDown(); @@ -119,7 +123,7 @@ public void testCloseWithQueryInProgress(TestContext ctx) { })); async.await(); } - + @Test public void testDatabaseMetaData(TestContext ctx) { connect(ctx.asyncAssertSuccess(conn -> { @@ -132,7 +136,7 @@ public void testDatabaseMetaData(TestContext ctx) { validateDatabaseMetaData(ctx, md); })); } - + protected abstract void validateDatabaseMetaData(TestContext ctx, DatabaseMetadata md); - + } diff --git a/vertx-sql-client/src/test/java/io/vertx/sqlclient/tck/DataTypeTestBase.java b/vertx-sql-client/src/test/java/io/vertx/sqlclient/tck/DataTypeTestBase.java index 14f82378f..61a1c0925 100644 --- a/vertx-sql-client/src/test/java/io/vertx/sqlclient/tck/DataTypeTestBase.java +++ b/vertx-sql-client/src/test/java/io/vertx/sqlclient/tck/DataTypeTestBase.java @@ -50,7 +50,7 @@ public void setUp(TestContext ctx) throws Exception { @After public void tearDown(TestContext ctx) { connector.close(); - vertx.close(ctx.asyncAssertSuccess()); + vertx.close().onComplete(ctx.asyncAssertSuccess()); } protected void verifyTypeName(TestContext ctx, ColumnDescriptor columnDescriptor) { diff --git a/vertx-sql-client/src/test/java/io/vertx/sqlclient/tck/DriverTestBase.java b/vertx-sql-client/src/test/java/io/vertx/sqlclient/tck/DriverTestBase.java index c0428cff7..f578f29c0 100644 --- a/vertx-sql-client/src/test/java/io/vertx/sqlclient/tck/DriverTestBase.java +++ b/vertx-sql-client/src/test/java/io/vertx/sqlclient/tck/DriverTestBase.java @@ -94,8 +94,10 @@ private void testCreatePoolWithVertx(TestContext ctx, Function fact try { Async async = ctx.async(); Pool pool = fact.apply(vertx); - pool.getConnection(ctx.asyncAssertSuccess(ar -> { - ar.close(ctx.asyncAssertSuccess(v -> async.complete())); + pool + .getConnection() + .onComplete(ctx.asyncAssertSuccess(conn -> { + conn.close().onComplete(ctx.asyncAssertSuccess(v -> async.complete())); })); async.await(20_000); } finally { @@ -107,8 +109,10 @@ private void testCreatePool(TestContext ctx, Supplier fact) { Pool pool = fact.get(); try { Async async = ctx.async(); - pool.getConnection(ctx.asyncAssertSuccess(ar -> { - ar.close(ctx.asyncAssertSuccess(v -> async.complete())); + pool + .getConnection() + .onComplete(ctx.asyncAssertSuccess(conn -> { + conn.close().onComplete(ctx.asyncAssertSuccess(v -> async.complete())); })); async.await(20_000); } finally { diff --git a/vertx-sql-client/src/test/java/io/vertx/sqlclient/tck/MetricsTestBase.java b/vertx-sql-client/src/test/java/io/vertx/sqlclient/tck/MetricsTestBase.java index cdf82913b..b5a794e1e 100644 --- a/vertx-sql-client/src/test/java/io/vertx/sqlclient/tck/MetricsTestBase.java +++ b/vertx-sql-client/src/test/java/io/vertx/sqlclient/tck/MetricsTestBase.java @@ -55,7 +55,7 @@ public void setup() { @After public void teardown(TestContext ctx) { - vertx.close(ctx.asyncAssertSuccess()); + vertx.close().onComplete(ctx.asyncAssertSuccess()); } protected Pool getPool() { @@ -80,7 +80,7 @@ public void close() { }; Pool pool = createPool(vertx); ctx.assertEquals(0, closeCount.get()); - pool.close(ctx.asyncAssertSuccess(v -> { + pool.close().onComplete(ctx.asyncAssertSuccess(v -> { ctx.assertEquals(1, closeCount.get()); })); } @@ -162,10 +162,12 @@ public void requestReset(Object requestMetric) { Pool pool = getPool(); Async async = ctx.async(); vertx.runOnContext(v1 -> { - pool.getConnection(ctx.asyncAssertSuccess(conn -> { + pool + .getConnection() + .onComplete(ctx.asyncAssertSuccess(conn -> { fn.apply(conn).onComplete(ar -> { ctx.assertEquals(!fail, ar.succeeded()); - conn.close(ctx.asyncAssertSuccess(v3 -> { + conn.close().onComplete(ctx.asyncAssertSuccess(v3 -> { vertx.runOnContext(v4 -> { if (fail) { ctx.assertNull(responseMetric.get()); diff --git a/vertx-sql-client/src/test/java/io/vertx/sqlclient/tck/NullValueEncodeTestBase.java b/vertx-sql-client/src/test/java/io/vertx/sqlclient/tck/NullValueEncodeTestBase.java index 88eda1e15..7f3274880 100644 --- a/vertx-sql-client/src/test/java/io/vertx/sqlclient/tck/NullValueEncodeTestBase.java +++ b/vertx-sql-client/src/test/java/io/vertx/sqlclient/tck/NullValueEncodeTestBase.java @@ -43,7 +43,7 @@ public void setup(TestContext ctx) throws Exception { @After public void tearDown(TestContext ctx) { connector.close(); - vertx.close(ctx.asyncAssertSuccess()); + vertx.close().onComplete(ctx.asyncAssertSuccess()); } @Test @@ -229,7 +229,10 @@ public void testEncodeNullArrayOfBigDecimal(TestContext ctx) { private void testEncodeNull(TestContext ctx, NullValue nullValue) { connector.connect(ctx.asyncAssertSuccess(conn -> { Tuple.tuple(); - conn.preparedQuery(statement("SELECT ", "")).execute(Tuple.of(nullValue), ctx.asyncAssertSuccess(rs -> { + conn + .preparedQuery(statement("SELECT ", "")) + .execute(Tuple.of(nullValue)) + .onComplete(ctx.asyncAssertSuccess(rs -> { Row row = rs.iterator().next(); ctx.assertNull(row.getValue(0)); })); diff --git a/vertx-sql-client/src/test/java/io/vertx/sqlclient/tck/PipeliningQueryTestBase.java b/vertx-sql-client/src/test/java/io/vertx/sqlclient/tck/PipeliningQueryTestBase.java index ee15969d8..77b669bf0 100644 --- a/vertx-sql-client/src/test/java/io/vertx/sqlclient/tck/PipeliningQueryTestBase.java +++ b/vertx-sql-client/src/test/java/io/vertx/sqlclient/tck/PipeliningQueryTestBase.java @@ -35,7 +35,7 @@ public void setup(TestContext ctx) { @After public void teardown(TestContext ctx) { - vertx.close(ctx.asyncAssertSuccess()); + vertx.close().onComplete(ctx.asyncAssertSuccess()); } protected abstract void init(); @@ -140,7 +140,7 @@ public void testPrepareAndExecuteWithDifferentSql(TestContext ctx) { conn.prepare("SELECT " + currentIter).onComplete(ctx.asyncAssertSuccess(ps -> { ps.query().execute().onComplete(ctx.asyncAssertSuccess(res -> { checkSequentialQueryResult(ctx, res, currentIter, orderCheckCounter); - ps.close(ctx.asyncAssertSuccess(v -> { + ps.close().onComplete(ctx.asyncAssertSuccess(v -> { latch.countDown(); })); })); @@ -230,7 +230,10 @@ private void testOneShotPreparedBatchInsert(TestContext ctx, SqlClient client) { private void cleanTestTable(TestContext ctx) { connectionConnector.connect(ctx.asyncAssertSuccess(conn -> { - conn.query("TRUNCATE TABLE mutable;").execute(ctx.asyncAssertSuccess(result -> { + conn + .query("TRUNCATE TABLE mutable;") + .execute() + .onComplete(ctx.asyncAssertSuccess(result -> { conn.close(); })); })); diff --git a/vertx-sql-client/src/test/java/io/vertx/sqlclient/tck/PreparedBatchTestBase.java b/vertx-sql-client/src/test/java/io/vertx/sqlclient/tck/PreparedBatchTestBase.java index 6c59da8cd..cf0d16542 100644 --- a/vertx-sql-client/src/test/java/io/vertx/sqlclient/tck/PreparedBatchTestBase.java +++ b/vertx-sql-client/src/test/java/io/vertx/sqlclient/tck/PreparedBatchTestBase.java @@ -49,7 +49,7 @@ public void setUp(TestContext ctx) throws Exception { @After public void tearDown(TestContext ctx) { connector.close(); - vertx.close(ctx.asyncAssertSuccess()); + vertx.close().onComplete(ctx.asyncAssertSuccess()); } @Test @@ -61,24 +61,39 @@ public void testInsert(TestContext ctx) { batch.add(Tuple.wrap(Arrays.asList(79993, "batch three"))); batch.add(Tuple.wrap(Arrays.asList(79994, "batch four"))); - conn.preparedQuery(statement("INSERT INTO mutable (id, val) VALUES (", ", ", ")")).executeBatch(batch, ctx.asyncAssertSuccess(result -> { + conn + .preparedQuery(statement("INSERT INTO mutable (id, val) VALUES (", ", ", ")")) + .executeBatch(batch) + .onComplete(ctx.asyncAssertSuccess(result -> { ctx.assertEquals(1, result.rowCount()); - conn.preparedQuery(statement("SELECT * FROM mutable WHERE id=", "")).executeBatch(Collections.singletonList(Tuple.of(79991)), ctx.asyncAssertSuccess(ar1 -> { + conn + .preparedQuery(statement("SELECT * FROM mutable WHERE id=", "")) + .executeBatch(Collections.singletonList(Tuple.of(79991))) + .onComplete(ctx.asyncAssertSuccess(ar1 -> { ctx.assertEquals(1, ar1.size()); Row one = ar1.iterator().next(); ctx.assertEquals(79991, one.getInteger("id")); ctx.assertEquals("batch one", one.getString("val")); - conn.preparedQuery(statement("SELECT * FROM mutable WHERE id=", "")).executeBatch(Collections.singletonList(Tuple.of(79992)), ctx.asyncAssertSuccess(ar2 -> { + conn + .preparedQuery(statement("SELECT * FROM mutable WHERE id=", "")) + .executeBatch(Collections.singletonList(Tuple.of(79992))) + .onComplete(ctx.asyncAssertSuccess(ar2 -> { ctx.assertEquals(1, ar2.size()); Row two = ar2.iterator().next(); ctx.assertEquals(79992, two.getInteger("id")); ctx.assertEquals("batch two", two.getString("val")); - conn.preparedQuery(statement("SELECT * FROM mutable WHERE id=", "")).executeBatch(Collections.singletonList(Tuple.of(79993)), ctx.asyncAssertSuccess(ar3 -> { + conn + .preparedQuery(statement("SELECT * FROM mutable WHERE id=", "")) + .executeBatch(Collections.singletonList(Tuple.of(79993))) + .onComplete(ctx.asyncAssertSuccess(ar3 -> { ctx.assertEquals(1, ar3.size()); Row three = ar3.iterator().next(); ctx.assertEquals(79993, three.getInteger("id")); ctx.assertEquals("batch three", three.getString("val")); - conn.preparedQuery(statement("SELECT * FROM mutable WHERE id=", "")).executeBatch(Collections.singletonList(Tuple.of(79994)), ctx.asyncAssertSuccess(ar4 -> { + conn + .preparedQuery(statement("SELECT * FROM mutable WHERE id=", "")) + .executeBatch(Collections.singletonList(Tuple.of(79994))) + .onComplete(ctx.asyncAssertSuccess(ar4 -> { ctx.assertEquals(1, ar4.size()); Row four = ar4.iterator().next(); ctx.assertEquals(79994, four.getInteger("id")); @@ -99,7 +114,10 @@ public void testBatchQuery(TestContext ctx) { batch.add(Tuple.of(3)); batch.add(Tuple.of(5)); - conn.preparedQuery(statement("SELECT * FROM immutable WHERE id=", "")).executeBatch(batch, ctx.asyncAssertSuccess(result -> { + conn + .preparedQuery(statement("SELECT * FROM immutable WHERE id=", "")) + .executeBatch(batch) + .onComplete(ctx.asyncAssertSuccess(result -> { ctx.assertEquals(1, result.size()); Row row = result.iterator().next(); ctx.assertEquals(1, row.getInteger(0)); @@ -124,7 +142,10 @@ public void testBatchQuery(TestContext ctx) { public void testEmptyBatch(TestContext ctx) { connector.connect(ctx.asyncAssertSuccess(conn -> { List batch = new ArrayList<>(); - conn.preparedQuery(statement("SELECT * FROM immutable WHERE id=", "")).executeBatch(batch, ctx.asyncAssertFailure(err -> { + conn + .preparedQuery(statement("SELECT * FROM immutable WHERE id=", "")) + .executeBatch(batch) + .onComplete(ctx.asyncAssertFailure(err -> { })); })); } @@ -134,14 +155,20 @@ public void testIncorrectNumBatchArguments(TestContext ctx) { connector.connect(ctx.asyncAssertSuccess(conn -> { List batch = new ArrayList<>(); batch.add(Tuple.of(1, 2)); - conn.preparedQuery(statement("SELECT * FROM immutable WHERE id=", "")).executeBatch(batch, ctx.asyncAssertFailure(err -> { + conn + .preparedQuery(statement("SELECT * FROM immutable WHERE id=", "")) + .executeBatch(batch) + .onComplete(ctx.asyncAssertFailure(err -> { })); })); } protected void cleanTestTable(TestContext ctx) { connect(ctx.asyncAssertSuccess(conn -> { - conn.preparedQuery("TRUNCATE TABLE mutable;").execute(ctx.asyncAssertSuccess(result -> { + conn + .preparedQuery("TRUNCATE TABLE mutable;") + .execute() + .onComplete(ctx.asyncAssertSuccess(result -> { conn.close(); })); })); diff --git a/vertx-sql-client/src/test/java/io/vertx/sqlclient/tck/PreparedQueryCachedTestBase.java b/vertx-sql-client/src/test/java/io/vertx/sqlclient/tck/PreparedQueryCachedTestBase.java index b84d54f06..addeaa144 100644 --- a/vertx-sql-client/src/test/java/io/vertx/sqlclient/tck/PreparedQueryCachedTestBase.java +++ b/vertx-sql-client/src/test/java/io/vertx/sqlclient/tck/PreparedQueryCachedTestBase.java @@ -32,8 +32,13 @@ public void testConcurrent(TestContext ctx) { } for (int i = 0; i < 10; i++) { Async async = asyncs[i]; - conn.prepare(statement("SELECT * FROM Fortune WHERE id=", ""), ctx.asyncAssertSuccess(ps -> { - ps.query().execute(Tuple.of(1), ctx.asyncAssertSuccess(results -> { + conn + .prepare(statement("SELECT * FROM Fortune WHERE id=", "")) + .onComplete(ctx.asyncAssertSuccess(ps -> { + ps + .query() + .execute(Tuple.of(1)) + .onComplete(ctx.asyncAssertSuccess(results -> { ctx.assertEquals(1, results.size()); Tuple row = results.iterator().next(); ctx.assertEquals(1, row.getInteger(0)); @@ -52,13 +57,19 @@ public void testClosedPreparedStatementEvictedFromCache(TestContext ctx) { options.setPreparedStatementCacheMaxSize(1024); connector.connect(ctx.asyncAssertSuccess(conn -> { - conn.prepare("SELECT * FROM immutable", ctx.asyncAssertSuccess(preparedStatement1 -> { - preparedStatement1.query().execute(ctx.asyncAssertSuccess(res1 -> { + conn.prepare("SELECT * FROM immutable").onComplete(ctx.asyncAssertSuccess(preparedStatement1 -> { + preparedStatement1 + .query() + .execute() + .onComplete(ctx.asyncAssertSuccess(res1 -> { ctx.assertEquals(12, res1.size()); preparedStatement1.close(); // no response from server, we need to wait for some time here vertx.setTimer(2000, id -> { - conn.prepare("SELECT * FROM immutable", ctx.asyncAssertSuccess(preparedStatement2 -> { - preparedStatement2.query().execute(ctx.asyncAssertSuccess(res2 -> { + conn.prepare("SELECT * FROM immutable").onComplete(ctx.asyncAssertSuccess(preparedStatement2 -> { + preparedStatement2 + .query() + .execute() + .onComplete(ctx.asyncAssertSuccess(res2 -> { ctx.assertEquals(12, res2.size()); conn.close(); async.complete(); @@ -74,13 +85,19 @@ public void testClosedPreparedStatementEvictedFromCache(TestContext ctx) { @Test public void testConcurrentClose(TestContext ctx) { connector.connect(ctx.asyncAssertSuccess(conn -> { - conn.prepare("SELECT * FROM immutable", ctx.asyncAssertSuccess(preparedStatement1 -> { - preparedStatement1.query().execute(ctx.asyncAssertSuccess(res1 -> { + conn.prepare("SELECT * FROM immutable").onComplete(ctx.asyncAssertSuccess(preparedStatement1 -> { + preparedStatement1 + .query() + .execute() + .onComplete(ctx.asyncAssertSuccess(res1 -> { ctx.assertEquals(12, res1.size()); preparedStatement1.close(); // send another prepare command directly - conn.prepare("SELECT * FROM immutable", ctx.asyncAssertSuccess(preparedStatement2 -> { - preparedStatement2.query().execute(ctx.asyncAssertSuccess(res2 -> { + conn.prepare("SELECT * FROM immutable").onComplete(ctx.asyncAssertSuccess(preparedStatement2 -> { + preparedStatement2 + .query() + .execute() + .onComplete(ctx.asyncAssertSuccess(res2 -> { ctx.assertEquals(12, res2.size()); conn.close(); })); @@ -94,7 +111,10 @@ public void testConcurrentClose(TestContext ctx) { public void testSqlLimitDoesNotAffectQuery(TestContext ctx) { options.setPreparedStatementCacheSqlLimit(1); connector.connect(ctx.asyncAssertSuccess(conn -> { - conn.preparedQuery("SELECT * FROM immutable").execute(ctx.asyncAssertSuccess(res -> { + conn + .preparedQuery("SELECT * FROM immutable") + .execute() + .onComplete(ctx.asyncAssertSuccess(res -> { ctx.assertEquals(12, res.size()); conn.close(); })); @@ -107,11 +127,20 @@ public void testEvictedStmtClosing(TestContext ctx) { options.setPreparedStatementCacheMaxSize(1); connector.connect(ctx.asyncAssertSuccess(conn -> { - conn.preparedQuery("SELECT * FROM immutable").execute(ctx.asyncAssertSuccess(res1 -> { + conn + .preparedQuery("SELECT * FROM immutable") + .execute() + .onComplete(ctx.asyncAssertSuccess(res1 -> { ctx.assertEquals(12, res1.size()); - conn.preparedQuery("SELECT * FROM mutable").execute(ctx.asyncAssertSuccess(res2 -> { + conn + .preparedQuery("SELECT * FROM mutable") + .execute() + .onComplete(ctx.asyncAssertSuccess(res2 -> { // the first stmt should be evicted, query again to check if it's ok - conn.preparedQuery("SELECT * FROM immutable").execute(ctx.asyncAssertSuccess(res3 -> { + conn + .preparedQuery("SELECT * FROM immutable") + .execute() + .onComplete(ctx.asyncAssertSuccess(res3 -> { ctx.assertEquals(12, res1.size()); conn.close(); })); @@ -123,10 +152,18 @@ public void testEvictedStmtClosing(TestContext ctx) { @Test public void testPreparedQueryParamInitiallyNull(TestContext ctx) { connect(ctx.asyncAssertSuccess(conn -> { - conn.prepare(statement("SELECT * FROM immutable WHERE id=", ""), ctx.asyncAssertSuccess(ps -> { - ps.query().execute(Tuple.of(null), ctx.asyncAssertSuccess(r1 -> { + conn + .prepare(statement("SELECT * FROM immutable WHERE id=", "")) + .onComplete(ctx.asyncAssertSuccess(ps -> { + ps + .query() + .execute(Tuple.of(null)) + .onComplete(ctx.asyncAssertSuccess(r1 -> { ctx.assertEquals(0, r1.size()); - ps.query().execute(Tuple.of(1), ctx.asyncAssertSuccess(r2 -> { + ps + .query() + .execute(Tuple.of(1)) + .onComplete(ctx.asyncAssertSuccess(r2 -> { ctx.assertEquals(1, r2.size()); })); })); diff --git a/vertx-sql-client/src/test/java/io/vertx/sqlclient/tck/PreparedQueryTestBase.java b/vertx-sql-client/src/test/java/io/vertx/sqlclient/tck/PreparedQueryTestBase.java index e6a897e12..1f02aa11c 100644 --- a/vertx-sql-client/src/test/java/io/vertx/sqlclient/tck/PreparedQueryTestBase.java +++ b/vertx-sql-client/src/test/java/io/vertx/sqlclient/tck/PreparedQueryTestBase.java @@ -43,7 +43,8 @@ private static void insertIntoTestTable(TestContext ctx, SqlClient client, int a for (int i = 0; i < 10; i++) { client .query("INSERT INTO mutable (id, val) VALUES (" + i + ", 'Whatever-" + i + "')") - .execute(ctx.asyncAssertSuccess(r1 -> { + .execute() + .onComplete(ctx.asyncAssertSuccess(r1 -> { ctx.assertEquals(1, r1.rowCount()); if (count.incrementAndGet() == amount) { completionHandler.run(); @@ -75,13 +76,15 @@ public void setUp(TestContext ctx) throws Exception { public void tearDown(TestContext ctx) { msgVerifier = null; connector.close(); - vertx.close(ctx.asyncAssertSuccess()); + vertx.close().onComplete(ctx.asyncAssertSuccess()); } @Test public void testPrepare(TestContext ctx) { connect(ctx.asyncAssertSuccess(conn -> { - conn.prepare(statement("SELECT id, message from immutable where id=", ""), ctx.asyncAssertSuccess(result -> { + conn + .prepare(statement("SELECT id, message from immutable where id=", "")) + .onComplete(ctx.asyncAssertSuccess(result -> { conn.close(); })); })); @@ -90,7 +93,7 @@ public void testPrepare(TestContext ctx) { @Test public void testPrepareError(TestContext ctx) { connect(ctx.asyncAssertSuccess(conn -> { - conn.prepare("SELECT whatever from DOES_NOT_EXIST", ctx.asyncAssertFailure(error -> { + conn.prepare("SELECT whatever from DOES_NOT_EXIST").onComplete(ctx.asyncAssertFailure(error -> { if (msgVerifier != null) { msgVerifier.accept(error); } @@ -103,7 +106,8 @@ public void testPreparedQuery(TestContext ctx) { connect(ctx.asyncAssertSuccess(conn -> { conn .preparedQuery(statement("SELECT * FROM immutable WHERE id=", "")) - .execute(Tuple.of(1), ctx.asyncAssertSuccess(rowSet -> { + .execute(Tuple.of(1)) + .onComplete(ctx.asyncAssertSuccess(rowSet -> { ctx.assertEquals(1, rowSet.size()); Tuple row = rowSet.iterator().next(); ctx.assertEquals(1, row.getInteger(0)); @@ -118,7 +122,8 @@ public void testPreparedQueryWithWrappedParams(TestContext ctx) { connect(ctx.asyncAssertSuccess(conn -> { conn .preparedQuery(statement("SELECT * FROM immutable WHERE id=", "")) - .execute(Tuple.wrap(Arrays.asList(1)), ctx.asyncAssertSuccess(rowSet -> { + .execute(Tuple.wrap(Arrays.asList(1))) + .onComplete(ctx.asyncAssertSuccess(rowSet -> { ctx.assertEquals(1, rowSet.size()); Tuple row = rowSet.iterator().next(); ctx.assertEquals(1, row.getInteger(0)); @@ -131,8 +136,13 @@ public void testPreparedQueryWithWrappedParams(TestContext ctx) { @Test public void testPreparedQueryParamCoercionTypeError(TestContext ctx) { connect(ctx.asyncAssertSuccess(conn -> { - conn.prepare(statement("SELECT * FROM immutable WHERE id=", ""), ctx.asyncAssertSuccess(ps -> { - ps.query().execute(Tuple.of("1"), ctx.asyncAssertFailure(error -> { + conn + .prepare(statement("SELECT * FROM immutable WHERE id=", "")) + .onComplete(ctx.asyncAssertSuccess(ps -> { + ps + .query() + .execute(Tuple.of("1")) + .onComplete(ctx.asyncAssertFailure(error -> { if (msgVerifier != null) { msgVerifier.accept(error); } else { @@ -146,8 +156,13 @@ public void testPreparedQueryParamCoercionTypeError(TestContext ctx) { @Test public void testPreparedQueryParamCoercionQuantityError(TestContext ctx) { connect(ctx.asyncAssertSuccess(conn -> { - conn.prepare(statement("SELECT * FROM immutable WHERE id=", ""), ctx.asyncAssertSuccess(ps -> { - ps.query().execute(Tuple.of(1, 2), ctx.asyncAssertFailure(error -> { + conn + .prepare(statement("SELECT * FROM immutable WHERE id=", "")) + .onComplete(ctx.asyncAssertSuccess(ps -> { + ps + .query() + .execute(Tuple.of(1, 2)) + .onComplete(ctx.asyncAssertFailure(error -> { if (msgVerifier != null) { msgVerifier.accept(error); } else { @@ -163,15 +178,18 @@ public void testPreparedUpdate(TestContext ctx) { connector.connect(ctx.asyncAssertSuccess(conn -> { conn .preparedQuery("INSERT INTO mutable (id, val) VALUES (2, 'Whatever')") - .execute(ctx.asyncAssertSuccess(r1 -> { + .execute() + .onComplete(ctx.asyncAssertSuccess(r1 -> { ctx.assertEquals(1, r1.rowCount()); conn .preparedQuery("UPDATE mutable SET val = 'Rocks!' WHERE id = 2") - .execute(ctx.asyncAssertSuccess(res1 -> { + .execute() + .onComplete(ctx.asyncAssertSuccess(res1 -> { ctx.assertEquals(1, res1.rowCount()); conn .preparedQuery("SELECT val FROM mutable WHERE id = 2") - .execute(ctx.asyncAssertSuccess(res2 -> { + .execute() + .onComplete(ctx.asyncAssertSuccess(res2 -> { ctx.assertEquals("Rocks!", res2.iterator().next().getValue(0)); conn.close(); })); @@ -185,15 +203,18 @@ public void testPreparedUpdateWithParams(TestContext ctx) { connector.connect(ctx.asyncAssertSuccess(conn -> { conn .preparedQuery("INSERT INTO mutable (id, val) VALUES (2, 'Whatever')") - .execute(ctx.asyncAssertSuccess(r1 -> { + .execute() + .onComplete(ctx.asyncAssertSuccess(r1 -> { ctx.assertEquals(1, r1.rowCount()); conn .preparedQuery(statement("UPDATE mutable SET val = ", " WHERE id = ", "")) - .execute(Tuple.of("Rocks Again!!", 2), ctx.asyncAssertSuccess(res1 -> { + .execute(Tuple.of("Rocks Again!!", 2)) + .onComplete(ctx.asyncAssertSuccess(res1 -> { ctx.assertEquals(1, res1.rowCount()); conn .preparedQuery(statement("SELECT val FROM mutable WHERE id = ", "")) - .execute(Tuple.of(2), ctx.asyncAssertSuccess(res2 -> { + .execute(Tuple.of(2)) + .onComplete(ctx.asyncAssertSuccess(res2 -> { ctx.assertEquals("Rocks Again!!", res2.iterator().next().getValue(0)); conn.close(); })); @@ -207,8 +228,8 @@ public void testPreparedUpdateWithNullParams(TestContext ctx) { connector.connect(ctx.asyncAssertSuccess(conn -> { conn.preparedQuery( statement("INSERT INTO mutable (val, id) VALUES (", ",", ")")) - .execute(Tuple.of(null, 1), - ctx.asyncAssertFailure(error -> { + .execute(Tuple.of(null, 1)) + .onComplete(ctx.asyncAssertFailure(error -> { if (msgVerifier != null) { msgVerifier.accept(error); } @@ -220,7 +241,10 @@ public void testPreparedUpdateWithNullParams(TestContext ctx) { private void testCursor(TestContext ctx, Handler test) { connector.connect(ctx.asyncAssertSuccess(conn -> { if (cursorRequiresTx()) { - conn.query("BEGIN").execute(ctx.asyncAssertSuccess(begin -> { + conn + .query("BEGIN") + .execute() + .onComplete(ctx.asyncAssertSuccess(begin -> { test.handle(conn); })); } else { @@ -234,13 +258,19 @@ private void testCursor(TestContext ctx, Handler test) { public void testQueryCursor(TestContext ctx) { Async async = ctx.async(); testCursor(ctx, conn -> { - conn.prepare(statement("SELECT * FROM immutable WHERE id=", " OR id=", " OR id=", " OR id=", " OR id=", " OR id=", ""), ctx.asyncAssertSuccess(ps -> { + conn + .prepare(statement("SELECT * FROM immutable WHERE id=", " OR id=", " OR id=", " OR id=", " OR id=", " OR id=", "")) + .onComplete(ctx.asyncAssertSuccess(ps -> { Cursor query = ps.cursor(Tuple.of(1, 8, 4, 11, 2, 9)); - query.read(4, ctx.asyncAssertSuccess(result -> { + query + .read(4) + .onComplete(ctx.asyncAssertSuccess(result -> { ctx.assertNotNull(result.columnsNames()); ctx.assertEquals(4, result.size()); ctx.assertTrue(query.hasMore()); - query.read(4, ctx.asyncAssertSuccess(result2 -> { + query + .read(4) + .onComplete(ctx.asyncAssertSuccess(result2 -> { ctx.assertNotNull(result2.columnsNames()); ctx.assertEquals(2, result2.size()); ctx.assertFalse(query.hasMore()); @@ -255,13 +285,17 @@ public void testQueryCursor(TestContext ctx) { public void testQueryCloseCursor(TestContext ctx) { Async async = ctx.async(); testCursor(ctx, conn -> { - conn.prepare(statement("SELECT * FROM immutable WHERE id="," OR id=", " OR id=", " OR id=", " OR id=", " OR id=",""), ctx.asyncAssertSuccess(ps -> { + conn + .prepare(statement("SELECT * FROM immutable WHERE id="," OR id=", " OR id=", " OR id=", " OR id=", " OR id=","")) + .onComplete(ctx.asyncAssertSuccess(ps -> { Cursor cursor = ps.cursor(Tuple.of(1, 8, 4, 11, 2, 9)); - cursor.read(4, ctx.asyncAssertSuccess(results -> { + cursor + .read(4) + .onComplete(ctx.asyncAssertSuccess(results -> { ctx.assertEquals(4, results.size()); - cursor.close(ctx.asyncAssertSuccess(v1 -> { + cursor.close().onComplete(ctx.asyncAssertSuccess(v1 -> { ctx.assertTrue(cursor.isClosed()); - ps.close(ctx.asyncAssertSuccess(v2 -> { + ps.close().onComplete(ctx.asyncAssertSuccess(v2 -> { async.complete(); })); })); @@ -274,7 +308,9 @@ public void testQueryCloseCursor(TestContext ctx) { public void testQueryStreamCloseCursor(TestContext ctx) { Async async = ctx.async(); testCursor(ctx, conn -> { - conn.prepare(statement("SELECT * FROM immutable WHERE id=", " OR id=", " OR id=", " OR id=", " OR id=", " OR id=", ""), ctx.asyncAssertSuccess(ps -> { + conn + .prepare(statement("SELECT * FROM immutable WHERE id=", " OR id=", " OR id=", " OR id=", " OR id=", " OR id=", "")) + .onComplete(ctx.asyncAssertSuccess(ps -> { RowStream stream = ps.createStream(4, Tuple.of(1, 8, 4, 11, 2, 9)); List rows = new ArrayList<>(); stream.handler(row -> { @@ -282,9 +318,9 @@ public void testQueryStreamCloseCursor(TestContext ctx) { if (rows.size() == 4) { Cursor cursor = ((RowStreamInternal) stream).cursor(); ctx.assertFalse(cursor.isClosed()); - stream.close(ctx.asyncAssertSuccess(v1 -> { + stream.close().onComplete(ctx.asyncAssertSuccess(v1 -> { ctx.assertTrue(cursor.isClosed()); - ps.close(ctx.asyncAssertSuccess(v2 -> { + ps.close().onComplete(ctx.asyncAssertSuccess(v2 -> { async.complete(); })); })); @@ -298,7 +334,7 @@ public void testQueryStreamCloseCursor(TestContext ctx) { public void testStreamQuery(TestContext ctx) { Async async = ctx.async(); testCursor(ctx, conn -> { - conn.prepare("SELECT * FROM immutable", ctx.asyncAssertSuccess(ps -> { + conn.prepare("SELECT * FROM immutable").onComplete(ctx.asyncAssertSuccess(ps -> { RowStream stream = ps.createStream(4, Tuple.tuple()); List rows = new ArrayList<>(); AtomicInteger ended = new AtomicInteger(); @@ -330,7 +366,7 @@ public void testStreamQueryPauseInBatchFromAnotherThread(TestContext ctx) { private void testStreamQueryPauseInBatch(TestContext ctx, Executor executor) { Async async = ctx.async(); testCursor(ctx, conn -> { - conn.prepare("SELECT * FROM immutable", ctx.asyncAssertSuccess(ps -> { + conn.prepare("SELECT * FROM immutable").onComplete(ctx.asyncAssertSuccess(ps -> { RowStream stream = ps.createStream(4, Tuple.tuple()); List rows = Collections.synchronizedList(new ArrayList<>()); AtomicInteger ended = new AtomicInteger(); @@ -360,7 +396,7 @@ private void testStreamQueryPauseInBatch(TestContext ctx, Executor executor) { public void testStreamQueryPauseResume(TestContext ctx) { Async async = ctx.async(); testCursor(ctx, conn -> { - conn.prepare("SELECT * FROM immutable", ctx.asyncAssertSuccess(ps -> { + conn.prepare("SELECT * FROM immutable").onComplete(ctx.asyncAssertSuccess(ps -> { RowStream stream = ps.createStream(4, Tuple.tuple()); List rows = new ArrayList<>(); AtomicInteger ended = new AtomicInteger(); @@ -379,7 +415,10 @@ public void testStreamQueryPauseResume(TestContext ctx) { protected void cleanTestTable(TestContext ctx) { connect(ctx.asyncAssertSuccess(conn -> { - conn.preparedQuery("TRUNCATE TABLE mutable").execute(ctx.asyncAssertSuccess(result -> { + conn + .preparedQuery("TRUNCATE TABLE mutable") + .execute() + .onComplete(ctx.asyncAssertSuccess(result -> { conn.close(); })); })); diff --git a/vertx-sql-client/src/test/java/io/vertx/sqlclient/tck/SimpleQueryTestBase.java b/vertx-sql-client/src/test/java/io/vertx/sqlclient/tck/SimpleQueryTestBase.java index b871bb23d..b09d6f033 100644 --- a/vertx-sql-client/src/test/java/io/vertx/sqlclient/tck/SimpleQueryTestBase.java +++ b/vertx-sql-client/src/test/java/io/vertx/sqlclient/tck/SimpleQueryTestBase.java @@ -40,7 +40,8 @@ private static void insertIntoTestTable(TestContext ctx, SqlClient client, int a for (int i = 0; i < 10; i++) { client .query("INSERT INTO mutable (id, val) VALUES (" + i + ", 'Whatever-" + i + "')") - .execute(ctx.asyncAssertSuccess(r1 -> { + .execute() + .onComplete(ctx.asyncAssertSuccess(r1 -> { ctx.assertEquals(1, r1.rowCount()); if (count.incrementAndGet() == amount) { completionHandler.run(); @@ -65,7 +66,7 @@ public void setUp(TestContext ctx) throws Exception { @After public void tearDown(TestContext ctx) { connector.close(); - vertx.close(ctx.asyncAssertSuccess()); + vertx.close().onComplete(ctx.asyncAssertSuccess()); } @Test @@ -73,7 +74,8 @@ public void testQuery(TestContext ctx) { connect(ctx.asyncAssertSuccess(conn -> { conn .query("SELECT id, message from immutable") - .execute(ctx.asyncAssertSuccess(result -> { + .execute() + .onComplete(ctx.asyncAssertSuccess(result -> { //TODO we need to figure how to handle PgResult#rowCount() method in common API, // MySQL returns affected rows as 0 for SELECT query but Postgres returns queried amount // ctx.assertEquals(12, result.rowCount()); this line does not pass in MySQL but passes in PG @@ -88,7 +90,10 @@ public void testQuery(TestContext ctx) { @Test public void testQueryError(TestContext ctx) { connect(ctx.asyncAssertSuccess(conn -> { - conn.query("SELECT whatever from DOES_NOT_EXIST").execute(ctx.asyncAssertFailure(err -> { + conn + .query("SELECT whatever from DOES_NOT_EXIST") + .execute() + .onComplete(ctx.asyncAssertFailure(err -> { })); })); } @@ -97,9 +102,15 @@ public void testQueryError(TestContext ctx) { public void testUpdate(TestContext ctx) { Async async = ctx.async(); connector.connect(ctx.asyncAssertSuccess(conn -> { - conn.query("INSERT INTO mutable (id, val) VALUES (1, 'Whatever')").execute(ctx.asyncAssertSuccess(r1 -> { + conn + .query("INSERT INTO mutable (id, val) VALUES (1, 'Whatever')") + .execute() + .onComplete(ctx.asyncAssertSuccess(r1 -> { ctx.assertEquals(1, r1.rowCount()); - conn.query("UPDATE mutable SET val = 'newValue' WHERE id = 1").execute(ctx.asyncAssertSuccess(r2 -> { + conn + .query("UPDATE mutable SET val = 'newValue' WHERE id = 1") + .execute() + .onComplete(ctx.asyncAssertSuccess(r2 -> { ctx.assertEquals(1, r2.rowCount()); async.complete(); })); @@ -111,7 +122,10 @@ public void testUpdate(TestContext ctx) { public void testInsert(TestContext ctx) { Async async = ctx.async(); connector.connect(ctx.asyncAssertSuccess(conn -> { - conn.query("INSERT INTO mutable (id, val) VALUES (1, 'Whatever')").execute(ctx.asyncAssertSuccess(r1 -> { + conn + .query("INSERT INTO mutable (id, val) VALUES (1, 'Whatever')") + .execute() + .onComplete(ctx.asyncAssertSuccess(r1 -> { ctx.assertEquals(1, r1.rowCount()); async.complete(); })); @@ -124,7 +138,10 @@ public void testDelete(TestContext ctx) { Async async = ctx.async(); connector.connect(ctx.asyncAssertSuccess(conn -> { insertIntoTestTable(ctx, conn, 10, () -> { - conn.query("DELETE FROM mutable where id = 6").execute(ctx.asyncAssertSuccess(result -> { + conn + .query("DELETE FROM mutable where id = 6") + .execute() + .onComplete(ctx.asyncAssertSuccess(result -> { ctx.assertEquals(1, result.rowCount()); async.complete(); })); @@ -134,7 +151,10 @@ public void testDelete(TestContext ctx) { protected void cleanTestTable(TestContext ctx) { connect(ctx.asyncAssertSuccess(conn -> { - conn.query("TRUNCATE TABLE mutable").execute(ctx.asyncAssertSuccess(result -> { + conn + .query("TRUNCATE TABLE mutable") + .execute() + .onComplete(ctx.asyncAssertSuccess(result -> { conn.close(); })); })); diff --git a/vertx-sql-client/src/test/java/io/vertx/sqlclient/tck/TextDataTypeDecodeTestBase.java b/vertx-sql-client/src/test/java/io/vertx/sqlclient/tck/TextDataTypeDecodeTestBase.java index 5f5158a4e..5f977bc53 100644 --- a/vertx-sql-client/src/test/java/io/vertx/sqlclient/tck/TextDataTypeDecodeTestBase.java +++ b/vertx-sql-client/src/test/java/io/vertx/sqlclient/tck/TextDataTypeDecodeTestBase.java @@ -86,7 +86,10 @@ protected void testDecodeGeneric(TestContext ctx, T expected) { Async async = ctx.async(); connector.connect(ctx.asyncAssertSuccess(conn -> { - conn.query("SELECT " + columnName + " FROM basicdatatype WHERE id = 1").execute(ctx.asyncAssertSuccess(result -> { + conn + .query("SELECT " + columnName + " FROM basicdatatype WHERE id = 1") + .execute() + .onComplete(ctx.asyncAssertSuccess(result -> { ctx.assertEquals(1, result.size()); Row row = result.iterator().next(); ctx.assertEquals(expected, row.getValue(0)); diff --git a/vertx-sql-client/src/test/java/io/vertx/sqlclient/tck/TracingTestBase.java b/vertx-sql-client/src/test/java/io/vertx/sqlclient/tck/TracingTestBase.java index 26464188b..f1240ab7b 100644 --- a/vertx-sql-client/src/test/java/io/vertx/sqlclient/tck/TracingTestBase.java +++ b/vertx-sql-client/src/test/java/io/vertx/sqlclient/tck/TracingTestBase.java @@ -64,7 +64,7 @@ public void receiveResponse(Context context, Object response, Object payload, Th @After public void teardown(TestContext ctx) { - vertx.close(ctx.asyncAssertSuccess()); + vertx.close().onComplete(ctx.asyncAssertSuccess()); } protected abstract Pool createPool(Vertx vertx); @@ -125,9 +125,11 @@ public void receiveResponse(Context context, R response, Object payload, Thr Async async = ctx.async(); vertx.runOnContext(v1 -> { Context context = Vertx.currentContext(); - pool.getConnection(ctx.asyncAssertSuccess(conn -> { + pool + .getConnection() + .onComplete(ctx.asyncAssertSuccess(conn -> { fn.apply(conn).onComplete(ctx.asyncAssertSuccess(v2 -> { - conn.close(ctx.asyncAssertSuccess(v3 -> { + conn.close().onComplete(ctx.asyncAssertSuccess(v3 -> { vertx.runOnContext(v4 -> { completed.await(2000); ctx.assertEquals(context, requestContext.get()); @@ -156,10 +158,13 @@ public void receiveResponse(Context context, R response, Object payload, Thr completed.complete(); } }; - pool.getConnection(ctx.asyncAssertSuccess(conn -> { + pool + .getConnection() + .onComplete(ctx.asyncAssertSuccess(conn -> { conn .preparedQuery(statement("SELECT * FROM undefined_table WHERE id = ", "")) - .execute(Tuple.of(0), ctx.asyncAssertFailure(err -> { + .execute(Tuple.of(0)) + .onComplete(ctx.asyncAssertFailure(err -> { conn.close(); })); })); @@ -183,14 +188,17 @@ public void receiveResponse(Context context, R response, Object payload, Thr } }; Async async = ctx.async(); - pool.getConnection(ctx.asyncAssertSuccess(conn -> { + pool + .getConnection() + .onComplete(ctx.asyncAssertSuccess(conn -> { conn .preparedQuery(sql) .mapping(row -> { throw failure; }) - .execute(Tuple.of(1), ctx.asyncAssertFailure(err -> { - conn.close(ctx.asyncAssertSuccess(v1 -> { + .execute(Tuple.of(1)) + .onComplete(ctx.asyncAssertFailure(err -> { + conn.close().onComplete(ctx.asyncAssertSuccess(v1 -> { vertx.runOnContext(v2 -> { completed.await(2000); ctx.assertEquals(1, called.get()); diff --git a/vertx-sql-client/src/test/java/io/vertx/sqlclient/tck/TransactionTestBase.java b/vertx-sql-client/src/test/java/io/vertx/sqlclient/tck/TransactionTestBase.java index 2428e0a70..2997f76d3 100644 --- a/vertx-sql-client/src/test/java/io/vertx/sqlclient/tck/TransactionTestBase.java +++ b/vertx-sql-client/src/test/java/io/vertx/sqlclient/tck/TransactionTestBase.java @@ -51,10 +51,14 @@ protected synchronized Pool getPool() { protected void initConnector() { connector = handler -> { Pool pool = getPool(); - pool.getConnection(ar1 -> { + pool + .getConnection() + .onComplete(ar1 -> { if (ar1.succeeded()) { SqlConnection conn = ar1.result(); - conn.begin(ar2 -> { + conn + .begin() + .onComplete(ar2 -> { if (ar2.succeeded()) { Transaction tx = ar2.result(); tx.completion().onComplete(ar3 -> { @@ -85,13 +89,16 @@ public void setUp(TestContext ctx) throws Exception { @After public void tearDown(TestContext ctx) { - vertx.close(ctx.asyncAssertSuccess()); + vertx.close().onComplete(ctx.asyncAssertSuccess()); } protected void cleanTestTable(TestContext ctx) { connector.accept(ctx.asyncAssertSuccess(res -> { - res.client.query("TRUNCATE TABLE mutable").execute(ctx.asyncAssertSuccess(result -> { - res.tx.commit(ctx.asyncAssertSuccess()); + res.client + .query("TRUNCATE TABLE mutable") + .execute() + .onComplete(ctx.asyncAssertSuccess(result -> { + res.tx.commit().onComplete(ctx.asyncAssertSuccess()); })); })); } @@ -100,11 +107,18 @@ protected void cleanTestTable(TestContext ctx) { public void testReleaseConnectionOnCommit(TestContext ctx) { Async async = ctx.async(); connector.accept(ctx.asyncAssertSuccess(res -> { - res.client.query("UPDATE Fortune SET message = 'Whatever' WHERE id = 9").execute(ctx.asyncAssertSuccess(result -> { + res.client + .query("UPDATE Fortune SET message = 'Whatever' WHERE id = 9") + .execute() + .onComplete(ctx.asyncAssertSuccess(result -> { ctx.assertEquals(1, result.rowCount()); - res.tx.commit(ctx.asyncAssertSuccess(v1 -> { + res.tx + .commit() + .onComplete(ctx.asyncAssertSuccess(v1 -> { // Try acquire a connection - pool.getConnection(ctx.asyncAssertSuccess(v2 -> { + pool + .getConnection() + .onComplete(ctx.asyncAssertSuccess(v2 -> { async.complete(); })); })); @@ -117,11 +131,18 @@ public void testReleaseConnectionOnRollback(TestContext ctx) { Async async = ctx.async(); connector.accept(ctx.asyncAssertSuccess(res -> { res.tx.completion().onComplete(ctx.asyncAssertFailure(err -> ctx.assertEquals(TransactionRollbackException.INSTANCE, err))); - res.client.query("UPDATE Fortune SET message = 'Whatever' WHERE id = 9").execute(ctx.asyncAssertSuccess(result -> { + res.client + .query("UPDATE Fortune SET message = 'Whatever' WHERE id = 9") + .execute() + .onComplete(ctx.asyncAssertSuccess(result -> { ctx.assertEquals(1, result.rowCount()); - res.tx.rollback(ctx.asyncAssertSuccess(v1 -> { + res.tx + .rollback() + .onComplete(ctx.asyncAssertSuccess(v1 -> { // Try acquire a connection - pool.getConnection(ctx.asyncAssertSuccess(v2 -> { + pool + .getConnection() + .onComplete(ctx.asyncAssertSuccess(v2 -> { async.complete(); })); })); @@ -133,11 +154,18 @@ public void testReleaseConnectionOnRollback(TestContext ctx) { public void testCommitWithPreparedQuery(TestContext ctx) { Async async = ctx.async(); connector.accept(ctx.asyncAssertSuccess(res -> { - res.client.preparedQuery(statement("INSERT INTO mutable (id, val) VALUES (", ",", ")")) - .execute(Tuple.of(13, "test message1"), ctx.asyncAssertSuccess(result -> { + res.client + .preparedQuery(statement("INSERT INTO mutable (id, val) VALUES (", ",", ")")) + .execute(Tuple.of(13, "test message1")) + .onComplete(ctx.asyncAssertSuccess(result -> { ctx.assertEquals(1, result.rowCount()); - res.tx.commit(ctx.asyncAssertSuccess(v1 -> { - res.client.query("SELECT id, val from mutable where id = 13").execute(ctx.asyncAssertSuccess(rowSet -> { + res.tx + .commit() + .onComplete(ctx.asyncAssertSuccess(v1 -> { + res.client + .query("SELECT id, val from mutable where id = 13") + .execute() + .onComplete(ctx.asyncAssertSuccess(rowSet -> { ctx.assertEquals(1, rowSet.size()); Row row = rowSet.iterator().next(); ctx.assertEquals(13, row.getInteger("id")); @@ -153,12 +181,18 @@ public void testCommitWithPreparedQuery(TestContext ctx) { public void testCommitWithQuery(TestContext ctx) { Async async = ctx.async(); connector.accept(ctx.asyncAssertSuccess(res -> { - res.client.query("INSERT INTO mutable (id, val) VALUES (14, 'test message2')") - .execute(ctx.asyncAssertSuccess(result -> { + res.client + .query("INSERT INTO mutable (id, val) VALUES (14, 'test message2')") + .execute() + .onComplete(ctx.asyncAssertSuccess(result -> { ctx.assertEquals(1, result.rowCount()); - res.tx.commit(ctx.asyncAssertSuccess(v1 -> { - res.client.query("SELECT id, val from mutable where id = 14") - .execute(ctx.asyncAssertSuccess(rowSet -> { + res.tx + .commit() + .onComplete(ctx.asyncAssertSuccess(v1 -> { + res.client + .query("SELECT id, val from mutable where id = 14") + .execute() + .onComplete(ctx.asyncAssertSuccess(rowSet -> { ctx.assertEquals(1, rowSet.size()); Row row = rowSet.iterator().next(); ctx.assertEquals(14, row.getInteger("id")); @@ -174,12 +208,18 @@ public void testCommitWithQuery(TestContext ctx) { public void testRollbackData(TestContext ctx) { Async async = ctx.async(); connector.accept(ctx.asyncAssertSuccess(res -> { - res.client.query("UPDATE immutable SET message = 'roll me back' WHERE id = 7") - .execute(ctx.asyncAssertSuccess(result -> { + res.client + .query("UPDATE immutable SET message = 'roll me back' WHERE id = 7") + .execute() + .onComplete(ctx.asyncAssertSuccess(result -> { ctx.assertEquals(1, result.rowCount()); - res.tx.rollback(ctx.asyncAssertSuccess(v1 -> { - res.client.query("SELECT id, message from immutable where id = 7") - .execute(ctx.asyncAssertSuccess(rowSet -> { + res.tx + .rollback() + .onComplete(ctx.asyncAssertSuccess(v1 -> { + res.client + .query("SELECT id, message from immutable where id = 7") + .execute() + .onComplete(ctx.asyncAssertSuccess(rowSet -> { ctx.assertEquals(1, rowSet.size()); Row row = rowSet.iterator().next(); ctx.assertEquals(7, row.getInteger("id")); @@ -196,23 +236,33 @@ public void testDelayedCommit(TestContext ctx) { Pool nonTxPool = nonTxPool(); Async async = ctx.async(); connector.accept(ctx.asyncAssertSuccess(res -> { - res.client.query("INSERT INTO mutable (id, val) VALUES (15, 'wait for it...')") - .execute(ctx.asyncAssertSuccess(result -> { + res.client + .query("INSERT INTO mutable (id, val) VALUES (15, 'wait for it...')") + .execute() + .onComplete(ctx.asyncAssertSuccess(result -> { ctx.assertEquals(1, result.rowCount()); // Should find the data within the same transaction - res.client.query("SELECT id, val from mutable WHERE id = 15") - .execute(ctx.asyncAssertSuccess(txRows -> { + res.client + .query("SELECT id, val from mutable WHERE id = 15") + .execute() + .onComplete(ctx.asyncAssertSuccess(txRows -> { ctx.assertEquals(1, txRows.size()); Row r = txRows.iterator().next(); ctx.assertEquals(15, r.getInteger("id")); ctx.assertEquals("wait for it...", r.getString("val")); // Should NOT find the data from outside of the transaction - nonTxPool.query("SELECT id, val from mutable WHERE id = 15") - .execute(ctx.asyncAssertSuccess(notFound -> { + nonTxPool + .query("SELECT id, val from mutable WHERE id = 15") + .execute() + .onComplete(ctx.asyncAssertSuccess(notFound -> { ctx.assertEquals(0, notFound.size()); - res.tx.commit(ctx.asyncAssertSuccess(nonTxRows -> { - nonTxPool.query("SELECT id, val from mutable WHERE id = 15") - .execute(ctx.asyncAssertSuccess(nonTxFound -> { + res.tx + .commit() + .onComplete(ctx.asyncAssertSuccess(nonTxRows -> { + nonTxPool + .query("SELECT id, val from mutable WHERE id = 15") + .execute() + .onComplete(ctx.asyncAssertSuccess(nonTxFound -> { // After commiting the transaction, the data should be visible from other connections ctx.assertEquals(1, nonTxFound.size()); Row nonTxRow = nonTxFound.iterator().next(); @@ -231,10 +281,17 @@ public void testDelayedCommit(TestContext ctx) { public void testFailureWithPendingQueries(TestContext ctx) { Async async = ctx.async(); connector.accept(ctx.asyncAssertSuccess(res -> { - res.client.query("SELECT whatever from DOES_NOT_EXIST").execute(ctx.asyncAssertFailure(v -> { + res.client + .query("SELECT whatever from DOES_NOT_EXIST") + .execute() + .onComplete(ctx.asyncAssertFailure(v -> { })); - res.client.query("SELECT id, val FROM mutable").execute(ctx.asyncAssertSuccess(err -> { - res.tx.commit(ctx.asyncAssertSuccess(v -> { + res.client + .query("SELECT id, val FROM mutable") + .execute() + .onComplete(ctx.asyncAssertSuccess(err -> { + res.tx.commit() + .onComplete(ctx.asyncAssertSuccess(v -> { async.complete(); })); })); @@ -256,7 +313,8 @@ public void testWithTransactionCommit(TestContext ctx) { .onComplete(ctx.asyncAssertSuccess(v -> { pool .query("SELECT id, val FROM mutable") - .execute(ctx.asyncAssertSuccess(rows -> { + .execute() + .onComplete(ctx.asyncAssertSuccess(rows -> { ctx.assertEquals(2, rows.size()); async.complete(); })); @@ -278,7 +336,8 @@ public void testWithTransactionRollback(TestContext ctx) { ctx.assertEquals(failure, err); pool .query("SELECT id, val FROM mutable") - .execute(ctx.asyncAssertSuccess(rows -> { + .execute() + .onComplete(ctx.asyncAssertSuccess(rows -> { ctx.assertEquals(0, rows.size()); async.complete(); })); @@ -302,7 +361,8 @@ public void testWithTransactionImplicitRollback(TestContext ctx) { ctx.assertEquals(err, failure.get()); pool .query("SELECT id, val FROM mutable") - .execute(ctx.asyncAssertSuccess(rows -> { + .execute() + .onComplete(ctx.asyncAssertSuccess(rows -> { ctx.assertEquals(0, rows.size()); async.complete(); })); @@ -322,7 +382,8 @@ public void testWithPropagatableConnectionTransactionCommit(TestContext ctx) { c.query("INSERT INTO mutable (id, val) VALUES (3, 'hello-3')").execute().mapEmpty()) ).onComplete(ctx.asyncAssertSuccess(v -> pool .query("SELECT id, val FROM mutable") - .execute(ctx.asyncAssertSuccess(rows -> { + .execute() + .onComplete(ctx.asyncAssertSuccess(rows -> { ctx.assertEquals(3, rows.size()); ctx.assertNull(Vertx.currentContext().getLocal("propagatable_connection")); async.complete(); @@ -342,7 +403,8 @@ public void testWithPropagatableConnectionTransactionRollback(TestContext ctx) { v -> Future.failedFuture(failure))) ).onComplete(ctx.asyncAssertFailure(v -> pool .query("SELECT id, val FROM mutable") - .execute(ctx.asyncAssertSuccess(rows -> { + .execute() + .onComplete(ctx.asyncAssertSuccess(rows -> { ctx.assertEquals(0, rows.size()); ctx.assertNull(Vertx.currentContext().getLocal("propagatable_connection")); async.complete();