Skip to content

Commit d34a274

Browse files
committed
Revert "Remove callback usage in tests"
This reverts commit 390f408.
1 parent 306bceb commit d34a274

File tree

108 files changed

+676
-824
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

+676
-824
lines changed

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

Lines changed: 38 additions & 76 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,14 +51,10 @@ enum Days {
5151
@Test
5252
public void testFloatIntoFloatColumn(TestContext ctx) {
5353
connect(ctx.asyncAssertSuccess(conn -> {
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 -> {
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 -> {
6258
ctx.assertEquals(1, rows.size());
6359
Row row = rows.iterator().next();
6460
ctx.assertEquals(1, row.getInteger(0));
@@ -76,14 +72,10 @@ public void testFloatIntoFloatColumn(TestContext ctx) {
7672
@Test
7773
public void testByteIntoSmallIntColumn(TestContext ctx) {
7874
connect(ctx.asyncAssertSuccess(conn -> {
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 -> {
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 -> {
8779
ctx.assertEquals(1, rows.size());
8880
Row row = rows.iterator().next();
8981
ctx.assertEquals(2, row.getInteger(0));
@@ -97,14 +89,10 @@ public void testByteIntoSmallIntColumn(TestContext ctx) {
9789
public void testByteArrayIntoVarchar(TestContext ctx) {
9890
byte[] expected = "hello world".getBytes();
9991
connect(ctx.asyncAssertSuccess(conn -> {
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 -> {
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 -> {
10896
ctx.assertEquals(1, rows.size());
10997
Row row = rows.iterator().next();
11098
ctx.assertEquals(3, row.getInteger(0));
@@ -120,14 +108,10 @@ public void testByteArrayIntoVarchar(TestContext ctx) {
120108
public void testByteBufIntoVarchar(TestContext ctx) {
121109
byte[] expected = "hello world".getBytes();
122110
connect(ctx.asyncAssertSuccess(conn -> {
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 -> {
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 -> {
131115
ctx.assertEquals(1, rows.size());
132116
Row row = rows.iterator().next();
133117
ctx.assertEquals(4, row.getInteger(0));
@@ -143,14 +127,10 @@ public void testByteBufIntoVarchar(TestContext ctx) {
143127
public void testTimestamp(TestContext ctx) {
144128
LocalDateTime now = LocalDateTime.now();
145129
connect(ctx.asyncAssertSuccess(conn -> {
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 -> {
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 -> {
154134
ctx.assertEquals(1, rows.size());
155135
Row row = rows.iterator().next();
156136
int nowNanos = now.getNano() - (1000 * now.get(ChronoField.MICRO_OF_SECOND));
@@ -166,15 +146,9 @@ public void testTimestamp(TestContext ctx) {
166146
public void testUUID(TestContext ctx) {
167147
UUID uuid = UUID.randomUUID();
168148
connect(ctx.asyncAssertSuccess(conn -> {
169-
conn
170-
.preparedQuery("INSERT INTO db2_types (id,test_vchar) VALUES (?,?)")
171-
.execute(Tuple.of(6, uuid))
172-
.onComplete(
149+
conn.preparedQuery("INSERT INTO db2_types (id,test_vchar) VALUES (?,?)").execute(Tuple.of(6, uuid),
173150
ctx.asyncAssertSuccess(insertResult -> {
174-
conn
175-
.preparedQuery("SELECT id,test_vchar FROM db2_types WHERE id = ?")
176-
.execute(Tuple.of(6))
177-
.onComplete(
151+
conn.preparedQuery("SELECT id,test_vchar FROM db2_types WHERE id = ?").execute(Tuple.of(6),
178152
ctx.asyncAssertSuccess(rows -> {
179153
ctx.assertEquals(1, rows.size());
180154
Row row = rows.iterator().next();
@@ -194,41 +168,32 @@ public void testRowId(TestContext ctx) {
194168
final String msg = "insert data for testRowId";
195169
connect(ctx.asyncAssertSuccess(conn -> {
196170
// Insert some data
197-
conn
198-
.preparedQuery("INSERT INTO ROWTEST (message) VALUES ('" + msg + "')")
199-
.execute()
200-
.onComplete(ctx.asyncAssertSuccess(insertResult -> {
171+
conn.preparedQuery("INSERT INTO ROWTEST (message) VALUES ('" + msg + "')")
172+
.execute(ctx.asyncAssertSuccess(insertResult -> {
201173
// Find it by msg
202-
conn
203-
.preparedQuery("SELECT * FROM ROWTEST WHERE message = '" + msg + "'")
204-
.execute()
205-
.onComplete(ctx.asyncAssertSuccess(rows -> {
174+
conn.preparedQuery("SELECT * FROM ROWTEST WHERE message = '" + msg + "'")
175+
.execute(ctx.asyncAssertSuccess(rows -> {
206176
RowId rowId = verifyRowId(ctx, rows, msg);
207177
// Now find it by rowid
208-
conn
209-
.preparedQuery("SELECT * FROM ROWTEST WHERE id = ?")
210-
.execute(Tuple.of(rowId))
211-
.onComplete(ctx.asyncAssertSuccess(rows2 -> {
178+
conn.preparedQuery("SELECT * FROM ROWTEST WHERE id = ?")
179+
.execute(Tuple.of(rowId), ctx.asyncAssertSuccess(rows2 -> {
212180
verifyRowId(ctx, rows2, msg);
213181
}));
214182
}));
215183
}));
216184
}));
217185
}
218-
186+
219187
/**
220188
* Test to support using enum string values in the Row and Tuple methods.
221189
*/
222190
@Test
223191
public void testUsingEnumNameValue(TestContext ctx) {
224192
connect(ctx.asyncAssertSuccess(conn -> {
225193
conn.preparedQuery("INSERT INTO db2_types (id,test_vchar) VALUES (?, ?)")
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 -> {
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 -> {
232197
ctx.assertEquals(1, rows.size());
233198
Row row = rows.iterator().next();
234199
ctx.assertEquals(10, row.getInteger(0));
@@ -245,12 +210,9 @@ public void testUsingEnumNameValue(TestContext ctx) {
245210
public void testUsingEnumOrdinalValue(TestContext ctx) {
246211
connect(ctx.asyncAssertSuccess(conn -> {
247212
conn.preparedQuery("INSERT INTO db2_types (id,test_int) VALUES (?, ?)")
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 -> {
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 -> {
254216
ctx.assertEquals(1, rows.size());
255217
Row row = rows.iterator().next();
256218
ctx.assertEquals(11, row.getInteger(0));
@@ -259,7 +221,7 @@ public void testUsingEnumOrdinalValue(TestContext ctx) {
259221
}));
260222
}));
261223
}
262-
224+
263225
private RowId verifyRowId(TestContext ctx, RowSet<Row> rows, String msg) {
264226
ctx.assertEquals(1, rows.size());
265227
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).onComplete(ctx.asyncAssertFailure(err -> {
34+
DB2Connection.connect(vertx, options, 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).onComplete(ctx.asyncAssertFailure(err -> {
51+
DB2Connection.connect(vertx, options, 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).onComplete(ctx.asyncAssertFailure(err -> {
63+
DB2Connection.connect(vertx, options, 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).onComplete(ctx.asyncAssertSuccess(conn -> {
111+
DB2Connection.connect(vertx, options, 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).onComplete(ctx.asyncAssertSuccess(conn -> {
125+
DB2Connection.connect(vertx, options, 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).onComplete(ctx.asyncAssertSuccess(conn -> {
139+
DB2Connection.connect(vertx, options, 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).onComplete(ctx.asyncAssertSuccess(conn -> {
153+
DB2Connection.connect(vertx, options, 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).onComplete(ctx.asyncAssertSuccess(conn -> {
170+
DB2Connection.connect(vertx, options, 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).onComplete(ctx.asyncAssertSuccess(conn -> {
186+
DB2Connection.connect(vertx, options, 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).onComplete(ctx.asyncAssertSuccess(conn -> {
203+
DB2Connection.connect(vertx, options, 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).onComplete(ctx.asyncAssertSuccess(conn -> {
223+
DB2Connection.connect(vertx, options, 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).onComplete(ctx.asyncAssertSuccess(conn -> {
240+
DB2Connection.connect(vertx, options, 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).onComplete(ctx.asyncAssertSuccess(conn -> {
257+
DB2Connection.connect(vertx, options, 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).onComplete(ctx.asyncAssertSuccess(conn -> {
269+
DB2Connection.connect(vertx, options, 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).onComplete(ctx.asyncAssertSuccess(conn1 -> {
290+
DB2Connection.connect(vertx, options, 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)