Skip to content

Commit 390f408

Browse files
committed
Remove callback usage in tests
1 parent 53b09ae commit 390f408

File tree

108 files changed

+824
-676
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

108 files changed

+824
-676
lines changed

vertx-db2-client/src/test/java/io/vertx/db2client/DB2DataTypeTest.java

Lines changed: 76 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,12 @@
3737
public class DB2DataTypeTest extends DB2TestBase {
3838

3939

40-
// Enum for enum testing
40+
// Enum for enum testing
4141
enum Days {
4242
MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY
4343
}
4444

45-
45+
4646
/**
4747
* In DB2 the FLOAT and DOUBLE column types both map to an 8-byte
4848
* double-precision column (i.e. Java double). Ensure that a Java
@@ -51,10 +51,14 @@ enum Days {
5151
@Test
5252
public void testFloatIntoFloatColumn(TestContext ctx) {
5353
connect(ctx.asyncAssertSuccess(conn -> {
54-
conn.preparedQuery("INSERT INTO db2_types (id,test_float) VALUES (?, ?)")
55-
.execute(Tuple.of(1, 5.0f), ctx.asyncAssertSuccess(insertResult -> {
56-
conn.preparedQuery("SELECT id,test_float FROM db2_types WHERE id = 1")
57-
.execute(ctx.asyncAssertSuccess(rows -> {
54+
conn
55+
.preparedQuery("INSERT INTO db2_types (id,test_float) VALUES (?, ?)")
56+
.execute(Tuple.of(1, 5.0f))
57+
.onComplete(ctx.asyncAssertSuccess(insertResult -> {
58+
conn
59+
.preparedQuery("SELECT id,test_float FROM db2_types WHERE id = 1")
60+
.execute()
61+
.onComplete(ctx.asyncAssertSuccess(rows -> {
5862
ctx.assertEquals(1, rows.size());
5963
Row row = rows.iterator().next();
6064
ctx.assertEquals(1, row.getInteger(0));
@@ -72,10 +76,14 @@ public void testFloatIntoFloatColumn(TestContext ctx) {
7276
@Test
7377
public void testByteIntoSmallIntColumn(TestContext ctx) {
7478
connect(ctx.asyncAssertSuccess(conn -> {
75-
conn.preparedQuery("INSERT INTO db2_types (id,test_byte) VALUES (?, ?)")
76-
.execute(Tuple.of(2, (byte) 0xCA), ctx.asyncAssertSuccess(insertResult -> {
77-
conn.preparedQuery("SELECT id,test_byte FROM db2_types WHERE id = 2")
78-
.execute(ctx.asyncAssertSuccess(rows -> {
79+
conn
80+
.preparedQuery("INSERT INTO db2_types (id,test_byte) VALUES (?, ?)")
81+
.execute(Tuple.of(2, (byte) 0xCA))
82+
.onComplete(ctx.asyncAssertSuccess(insertResult -> {
83+
conn
84+
.preparedQuery("SELECT id,test_byte FROM db2_types WHERE id = 2")
85+
.execute()
86+
.onComplete(ctx.asyncAssertSuccess(rows -> {
7987
ctx.assertEquals(1, rows.size());
8088
Row row = rows.iterator().next();
8189
ctx.assertEquals(2, row.getInteger(0));
@@ -89,10 +97,14 @@ public void testByteIntoSmallIntColumn(TestContext ctx) {
8997
public void testByteArrayIntoVarchar(TestContext ctx) {
9098
byte[] expected = "hello world".getBytes();
9199
connect(ctx.asyncAssertSuccess(conn -> {
92-
conn.preparedQuery("INSERT INTO db2_types (id,test_bytes) VALUES (?, ?)")
93-
.execute(Tuple.of(3, "hello world".getBytes()), ctx.asyncAssertSuccess(insertResult -> {
94-
conn.preparedQuery("SELECT id,test_bytes FROM db2_types WHERE id = 3")
95-
.execute(ctx.asyncAssertSuccess(rows -> {
100+
conn
101+
.preparedQuery("INSERT INTO db2_types (id,test_bytes) VALUES (?, ?)")
102+
.execute(Tuple.of(3, "hello world".getBytes()))
103+
.onComplete(ctx.asyncAssertSuccess(insertResult -> {
104+
conn
105+
.preparedQuery("SELECT id,test_bytes FROM db2_types WHERE id = 3")
106+
.execute()
107+
.onComplete(ctx.asyncAssertSuccess(rows -> {
96108
ctx.assertEquals(1, rows.size());
97109
Row row = rows.iterator().next();
98110
ctx.assertEquals(3, row.getInteger(0));
@@ -108,10 +120,14 @@ public void testByteArrayIntoVarchar(TestContext ctx) {
108120
public void testByteBufIntoVarchar(TestContext ctx) {
109121
byte[] expected = "hello world".getBytes();
110122
connect(ctx.asyncAssertSuccess(conn -> {
111-
conn.preparedQuery("INSERT INTO db2_types (id,test_bytes) VALUES (?, ?)")
112-
.execute(Tuple.of(4, Buffer.buffer(expected)), ctx.asyncAssertSuccess(insertResult -> {
113-
conn.preparedQuery("SELECT id,test_bytes FROM db2_types WHERE id = 4")
114-
.execute(ctx.asyncAssertSuccess(rows -> {
123+
conn
124+
.preparedQuery("INSERT INTO db2_types (id,test_bytes) VALUES (?, ?)")
125+
.execute(Tuple.of(4, Buffer.buffer(expected)))
126+
.onComplete(ctx.asyncAssertSuccess(insertResult -> {
127+
conn
128+
.preparedQuery("SELECT id,test_bytes FROM db2_types WHERE id = 4")
129+
.execute()
130+
.onComplete(ctx.asyncAssertSuccess(rows -> {
115131
ctx.assertEquals(1, rows.size());
116132
Row row = rows.iterator().next();
117133
ctx.assertEquals(4, row.getInteger(0));
@@ -127,10 +143,14 @@ public void testByteBufIntoVarchar(TestContext ctx) {
127143
public void testTimestamp(TestContext ctx) {
128144
LocalDateTime now = LocalDateTime.now();
129145
connect(ctx.asyncAssertSuccess(conn -> {
130-
conn.preparedQuery("INSERT INTO db2_types (id,test_tstamp) VALUES (?,?)")
131-
.execute(Tuple.of(5, now), ctx.asyncAssertSuccess(insertResult -> {
132-
conn.preparedQuery("SELECT id,test_tstamp FROM db2_types WHERE id = ?")
133-
.execute(Tuple.of(5), ctx.asyncAssertSuccess(rows -> {
146+
conn
147+
.preparedQuery("INSERT INTO db2_types (id,test_tstamp) VALUES (?,?)")
148+
.execute(Tuple.of(5, now))
149+
.onComplete(ctx.asyncAssertSuccess(insertResult -> {
150+
conn
151+
.preparedQuery("SELECT id,test_tstamp FROM db2_types WHERE id = ?")
152+
.execute(Tuple.of(5))
153+
.onComplete(ctx.asyncAssertSuccess(rows -> {
134154
ctx.assertEquals(1, rows.size());
135155
Row row = rows.iterator().next();
136156
int nowNanos = now.getNano() - (1000 * now.get(ChronoField.MICRO_OF_SECOND));
@@ -146,9 +166,15 @@ public void testTimestamp(TestContext ctx) {
146166
public void testUUID(TestContext ctx) {
147167
UUID uuid = UUID.randomUUID();
148168
connect(ctx.asyncAssertSuccess(conn -> {
149-
conn.preparedQuery("INSERT INTO db2_types (id,test_vchar) VALUES (?,?)").execute(Tuple.of(6, uuid),
169+
conn
170+
.preparedQuery("INSERT INTO db2_types (id,test_vchar) VALUES (?,?)")
171+
.execute(Tuple.of(6, uuid))
172+
.onComplete(
150173
ctx.asyncAssertSuccess(insertResult -> {
151-
conn.preparedQuery("SELECT id,test_vchar FROM db2_types WHERE id = ?").execute(Tuple.of(6),
174+
conn
175+
.preparedQuery("SELECT id,test_vchar FROM db2_types WHERE id = ?")
176+
.execute(Tuple.of(6))
177+
.onComplete(
152178
ctx.asyncAssertSuccess(rows -> {
153179
ctx.assertEquals(1, rows.size());
154180
Row row = rows.iterator().next();
@@ -168,32 +194,41 @@ public void testRowId(TestContext ctx) {
168194
final String msg = "insert data for testRowId";
169195
connect(ctx.asyncAssertSuccess(conn -> {
170196
// Insert some data
171-
conn.preparedQuery("INSERT INTO ROWTEST (message) VALUES ('" + msg + "')")
172-
.execute(ctx.asyncAssertSuccess(insertResult -> {
197+
conn
198+
.preparedQuery("INSERT INTO ROWTEST (message) VALUES ('" + msg + "')")
199+
.execute()
200+
.onComplete(ctx.asyncAssertSuccess(insertResult -> {
173201
// Find it by msg
174-
conn.preparedQuery("SELECT * FROM ROWTEST WHERE message = '" + msg + "'")
175-
.execute(ctx.asyncAssertSuccess(rows -> {
202+
conn
203+
.preparedQuery("SELECT * FROM ROWTEST WHERE message = '" + msg + "'")
204+
.execute()
205+
.onComplete(ctx.asyncAssertSuccess(rows -> {
176206
RowId rowId = verifyRowId(ctx, rows, msg);
177207
// Now find it by rowid
178-
conn.preparedQuery("SELECT * FROM ROWTEST WHERE id = ?")
179-
.execute(Tuple.of(rowId), ctx.asyncAssertSuccess(rows2 -> {
208+
conn
209+
.preparedQuery("SELECT * FROM ROWTEST WHERE id = ?")
210+
.execute(Tuple.of(rowId))
211+
.onComplete(ctx.asyncAssertSuccess(rows2 -> {
180212
verifyRowId(ctx, rows2, msg);
181213
}));
182214
}));
183215
}));
184216
}));
185217
}
186-
218+
187219
/**
188220
* Test to support using enum string values in the Row and Tuple methods.
189221
*/
190222
@Test
191223
public void testUsingEnumNameValue(TestContext ctx) {
192224
connect(ctx.asyncAssertSuccess(conn -> {
193225
conn.preparedQuery("INSERT INTO db2_types (id,test_vchar) VALUES (?, ?)")
194-
.execute(Tuple.of(10, Days.WEDNESDAY), ctx.asyncAssertSuccess(insertResult -> {
195-
conn.preparedQuery("SELECT id,test_vchar FROM db2_types WHERE id = 10")
196-
.execute(ctx.asyncAssertSuccess(rows -> {
226+
.execute(Tuple.of(10, Days.WEDNESDAY))
227+
.onComplete(ctx.asyncAssertSuccess(insertResult -> {
228+
conn
229+
.preparedQuery("SELECT id,test_vchar FROM db2_types WHERE id = 10")
230+
.execute()
231+
.onComplete(ctx.asyncAssertSuccess(rows -> {
197232
ctx.assertEquals(1, rows.size());
198233
Row row = rows.iterator().next();
199234
ctx.assertEquals(10, row.getInteger(0));
@@ -210,9 +245,12 @@ public void testUsingEnumNameValue(TestContext ctx) {
210245
public void testUsingEnumOrdinalValue(TestContext ctx) {
211246
connect(ctx.asyncAssertSuccess(conn -> {
212247
conn.preparedQuery("INSERT INTO db2_types (id,test_int) VALUES (?, ?)")
213-
.execute(Tuple.of(11, Days.FRIDAY.ordinal()), ctx.asyncAssertSuccess(insertResult -> {
214-
conn.preparedQuery("SELECT id,test_int FROM db2_types WHERE id = 11")
215-
.execute(ctx.asyncAssertSuccess(rows -> {
248+
.execute(Tuple.of(11, Days.FRIDAY.ordinal()))
249+
.onComplete(ctx.asyncAssertSuccess(insertResult -> {
250+
conn
251+
.preparedQuery("SELECT id,test_int FROM db2_types WHERE id = 11")
252+
.execute()
253+
.onComplete(ctx.asyncAssertSuccess(rows -> {
216254
ctx.assertEquals(1, rows.size());
217255
Row row = rows.iterator().next();
218256
ctx.assertEquals(11, row.getInteger(0));
@@ -221,7 +259,7 @@ public void testUsingEnumOrdinalValue(TestContext ctx) {
221259
}));
222260
}));
223261
}
224-
262+
225263
private RowId verifyRowId(TestContext ctx, RowSet<Row> rows, String msg) {
226264
ctx.assertEquals(1, rows.size());
227265
Row row = rows.iterator().next();

vertx-db2-client/src/test/java/io/vertx/db2client/DB2ErrorMessageTest.java

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public class DB2ErrorMessageTest extends DB2TestBase {
3131
@Test
3232
public void testConnectInvalidDatabase(TestContext ctx) {
3333
options.setDatabase("DB_DOES_NOT_EXIST");
34-
DB2Connection.connect(vertx, options, ctx.asyncAssertFailure(err -> {
34+
DB2Connection.connect(vertx, options).onComplete(ctx.asyncAssertFailure(err -> {
3535
if (err instanceof DB2Exception) {
3636
DB2Exception ex = (DB2Exception) err;
3737
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) {
4848
@Test
4949
public void testConnectInvalidUsername(TestContext ctx) {
5050
options.setUser("INVALID_USER_FOR_TESTING");
51-
DB2Connection.connect(vertx, options, ctx.asyncAssertFailure(err -> {
51+
DB2Connection.connect(vertx, options).onComplete(ctx.asyncAssertFailure(err -> {
5252
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());
5353
DB2Exception ex = (DB2Exception) err;
5454
assertContains(ctx, ex.getMessage(), "Invalid credentials");
@@ -60,7 +60,7 @@ public void testConnectInvalidUsername(TestContext ctx) {
6060
@Test
6161
public void testConnectInvalidPassword(TestContext ctx) {
6262
options.setPassword("INVALID_PASSWORD_FOR_TESTING");
63-
DB2Connection.connect(vertx, options, ctx.asyncAssertFailure(err -> {
63+
DB2Connection.connect(vertx, options).onComplete(ctx.asyncAssertFailure(err -> {
6464
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());
6565
DB2Exception ex = (DB2Exception) err;
6666
assertContains(ctx, ex.getMessage(), "Invalid credentials");
@@ -108,7 +108,7 @@ public void testQueryBlankPassword(TestContext ctx) {
108108
@Test
109109
// This should cause sqlCode=-104 sqlState=42601 to be returned from the server
110110
public void testQueryBlankTable(TestContext ctx) {
111-
DB2Connection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> {
111+
DB2Connection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> {
112112
conn.query("SELECT id, message FROM ").execute(ctx.asyncAssertFailure(err -> {
113113
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());
114114
DB2Exception ex = (DB2Exception) err;
@@ -122,7 +122,7 @@ public void testQueryBlankTable(TestContext ctx) {
122122
@Test
123123
// This should cause sqlCode=-204 sqlState=42704 to be returned from the server
124124
public void testInvalidTableQuery(TestContext ctx) {
125-
DB2Connection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> {
125+
DB2Connection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> {
126126
conn.query("SELECT id, message FROM TABLE_DOES_NOT_EXIST").execute(ctx.asyncAssertFailure(err -> {
127127
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());
128128
DB2Exception ex = (DB2Exception) err;
@@ -136,7 +136,7 @@ public void testInvalidTableQuery(TestContext ctx) {
136136
@Test
137137
// This should cause sqlCode=-206 sqlState=42703 to be returned from the server
138138
public void testInvalidColumnQuery(TestContext ctx) {
139-
DB2Connection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> {
139+
DB2Connection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> {
140140
conn.query("SELECT INVALID_COLUMN FROM immutable").execute(ctx.asyncAssertFailure(err -> {
141141
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());
142142
DB2Exception ex = (DB2Exception) err;
@@ -150,7 +150,7 @@ public void testInvalidColumnQuery(TestContext ctx) {
150150
@Test
151151
// This should cause sqlCode=-104 sqlState=42601 to be returned from the server
152152
public void testInvalidQuery(TestContext ctx) {
153-
DB2Connection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> {
153+
DB2Connection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> {
154154
conn.query("KJHDKJAHDQWEUWHQDDA:SHDL:KASHDJ").execute(ctx.asyncAssertFailure(err -> {
155155
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());
156156
DB2Exception ex = (DB2Exception) err;
@@ -167,7 +167,7 @@ public void testInvalidQuery(TestContext ctx) {
167167
*/
168168
@Test
169169
public void testMismatchingInsertedColumns(TestContext ctx) {
170-
DB2Connection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> {
170+
DB2Connection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> {
171171
conn.query("INSERT INTO basicdatatype (id, test_int_2) VALUES (99,24,25)").execute(ctx.asyncAssertFailure(err -> {
172172
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());
173173
DB2Exception ex = (DB2Exception) err;
@@ -183,7 +183,7 @@ public void testMismatchingInsertedColumns(TestContext ctx) {
183183
*/
184184
@Test
185185
public void testRepeatedColumnReference(TestContext ctx) {
186-
DB2Connection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> {
186+
DB2Connection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> {
187187
conn.query("INSERT INTO basicdatatype (id, test_int_2, test_int_2) VALUES (99,24,25)").execute(ctx.asyncAssertFailure(err -> {
188188
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());
189189
DB2Exception ex = (DB2Exception) err;
@@ -200,7 +200,7 @@ public void testRepeatedColumnReference(TestContext ctx) {
200200
*/
201201
@Test
202202
public void testAmbiguousColumnName(TestContext ctx) {
203-
DB2Connection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> {
203+
DB2Connection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> {
204204
conn.query("SELECT immutable.id AS IMM_ID," +
205205
"Fortune.id AS FORT_ID," +
206206
"message FROM immutable " +
@@ -220,7 +220,7 @@ public void testAmbiguousColumnName(TestContext ctx) {
220220
*/
221221
@Test
222222
public void testDuplicateKeys(TestContext ctx) {
223-
DB2Connection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> {
223+
DB2Connection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> {
224224
conn.query("INSERT INTO immutable (id, message) VALUES (1, 'a duplicate key')").execute(ctx.asyncAssertFailure(err -> {
225225
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());
226226
DB2Exception ex = (DB2Exception) err;
@@ -237,7 +237,7 @@ public void testDuplicateKeys(TestContext ctx) {
237237
*/
238238
@Test
239239
public void testCreateTableNullPrimaryKey(TestContext ctx) {
240-
DB2Connection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> {
240+
DB2Connection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> {
241241
conn.query("CREATE TABLE fruits (id INTEGER PRIMARY KEY, name VARCHAR(50) NOT NULL)").execute(ctx.asyncAssertFailure(err -> {
242242
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());
243243
DB2Exception ex = (DB2Exception) err;
@@ -254,7 +254,7 @@ public void testCreateTableNullPrimaryKey(TestContext ctx) {
254254
*/
255255
@Test
256256
public void testInsertIntoGeneratedAlwaysColumn(TestContext ctx) {
257-
DB2Connection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> {
257+
DB2Connection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> {
258258
conn.query("INSERT INTO Fortune (id,message) VALUES (25, 'hello world')").execute(ctx.asyncAssertFailure(err -> {
259259
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());
260260
DB2Exception ex = (DB2Exception) err;
@@ -266,7 +266,7 @@ public void testInsertIntoGeneratedAlwaysColumn(TestContext ctx) {
266266

267267
@Test
268268
public void testDuplicateObject(TestContext ctx) {
269-
DB2Connection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> {
269+
DB2Connection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> {
270270
conn.query("CREATE TABLE Fortune (\n" +
271271
" id integer NOT NULL GENERATED AS IDENTITY (START WITH 1, INCREMENT BY 1),\n" +
272272
" message varchar(2048),\n" +
@@ -287,7 +287,7 @@ public void testDuplicateObject(TestContext ctx) {
287287
//During the 60 second wait call 'docker kill <container_id>', docker stop will end gracefully, so it has to be docker kill.
288288
//@Test
289289
public void testInflightCommandsFailWhenConnectionClosed(TestContext ctx) {
290-
DB2Connection.connect(vertx, options, ctx.asyncAssertSuccess(conn1 -> {
290+
DB2Connection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn1 -> {
291291
conn1.query("CALL dbms_alert.sleep(60)").execute(ctx.asyncAssertFailure(t -> {
292292
ctx.assertEquals("Failed to read any response from the server, the underlying connection may have been lost unexpectedly.", t.getMessage());
293293
}));

0 commit comments

Comments
 (0)