|
1 | 1 | /* |
2 | | - * Copyright (C) 2017 Julien Viet |
| 2 | + * Copyright (c) 2011-2026 Contributors to the Eclipse Foundation |
3 | 3 | * |
4 | | - * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | | - * you may not use this file except in compliance with the License. |
6 | | - * You may obtain a copy of the License at |
7 | | - * |
8 | | - * http://www.apache.org/licenses/LICENSE-2.0 |
9 | | - * |
10 | | - * Unless required by applicable law or agreed to in writing, software |
11 | | - * distributed under the License is distributed on an "AS IS" BASIS, |
12 | | - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
13 | | - * See the License for the specific language governing permissions and |
14 | | - * limitations under the License. |
| 4 | + * This program and the accompanying materials are made available under the |
| 5 | + * terms of the Eclipse Public License 2.0 which is available at |
| 6 | + * http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 |
| 7 | + * which is available at https://www.apache.org/licenses/LICENSE-2.0. |
15 | 8 | * |
| 9 | + * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 |
16 | 10 | */ |
17 | 11 |
|
18 | 12 | package io.vertx.pgclient; |
|
24 | 18 | import io.vertx.core.json.JsonObject; |
25 | 19 | import io.vertx.ext.unit.Async; |
26 | 20 | import io.vertx.ext.unit.TestContext; |
27 | | -import io.vertx.pgclient.data.Box; |
28 | | -import io.vertx.pgclient.data.Circle; |
29 | | -import io.vertx.pgclient.data.Interval; |
30 | | -import io.vertx.pgclient.data.Line; |
31 | | -import io.vertx.pgclient.data.LineSegment; |
32 | | -import io.vertx.pgclient.data.Path; |
33 | | -import io.vertx.pgclient.data.Point; |
34 | | -import io.vertx.pgclient.data.Polygon; |
35 | | -import io.vertx.sqlclient.Cursor; |
36 | | -import io.vertx.sqlclient.Row; |
37 | | -import io.vertx.sqlclient.RowIterator; |
38 | | -import io.vertx.sqlclient.RowSet; |
39 | | -import io.vertx.sqlclient.RowStream; |
40 | | -import io.vertx.sqlclient.Tuple; |
| 21 | +import io.vertx.ext.unit.junit.Repeat; |
| 22 | +import io.vertx.ext.unit.junit.RepeatRule; |
| 23 | +import io.vertx.pgclient.data.*; |
| 24 | +import io.vertx.sqlclient.*; |
41 | 25 | import org.junit.After; |
42 | 26 | import org.junit.Before; |
| 27 | +import org.junit.Rule; |
43 | 28 | import org.junit.Test; |
44 | 29 |
|
45 | 30 | import java.lang.reflect.Array; |
46 | | -import java.time.LocalDate; |
47 | | -import java.time.LocalDateTime; |
48 | | -import java.time.LocalTime; |
49 | | -import java.time.OffsetDateTime; |
50 | | -import java.time.ZoneOffset; |
| 31 | +import java.time.*; |
51 | 32 | import java.time.format.DateTimeFormatter; |
52 | 33 | import java.util.Collections; |
53 | 34 | import java.util.List; |
|
62 | 43 | */ |
63 | 44 | public abstract class PreparedStatementTestBase extends PgTestBase { |
64 | 45 |
|
| 46 | + @Rule |
| 47 | + public RepeatRule rule = new RepeatRule(); |
| 48 | + |
65 | 49 | Vertx vertx; |
66 | 50 |
|
67 | 51 | protected abstract PgConnectOptions options(); |
@@ -359,126 +343,148 @@ public void testCloseStatement(TestContext ctx) { |
359 | 343 | } |
360 | 344 |
|
361 | 345 | @Test |
| 346 | + @Repeat(10) |
362 | 347 | public void testInferDataTypeString42P18(TestContext ctx) { |
363 | 348 | testInferDataType42P18(ctx, String.class, "WORLD", "WORLD"); |
364 | 349 | } |
365 | 350 |
|
366 | 351 | @Test |
| 352 | + @Repeat(10) |
367 | 353 | public void testInferDataTypeBoolean42P18(TestContext ctx) { |
368 | 354 | testInferDataType42P18(ctx, Boolean.class, true, "t"); |
369 | 355 | } |
370 | 356 |
|
371 | 357 | @Test |
| 358 | + @Repeat(10) |
372 | 359 | public void testInferDataTypeShort42P18(TestContext ctx) { |
373 | 360 | testInferDataType42P18(ctx, Short.class, (short)2, "2"); |
374 | 361 | } |
375 | 362 |
|
376 | 363 | @Test |
| 364 | + @Repeat(10) |
377 | 365 | public void testInferDataTypeInteger42P18(TestContext ctx) { |
378 | 366 | testInferDataType42P18(ctx, Integer.class, Integer.MAX_VALUE, "" + Integer.MAX_VALUE); |
379 | 367 | } |
380 | 368 |
|
381 | 369 | @Test |
| 370 | + @Repeat(10) |
382 | 371 | public void testInferDataTypeLong42P18(TestContext ctx) { |
383 | 372 | testInferDataType42P18(ctx, Long.class, Long.MAX_VALUE, "" + Long.MAX_VALUE); |
384 | 373 | } |
385 | 374 |
|
386 | 375 | @Test |
| 376 | + @Repeat(10) |
387 | 377 | public void testInferDataTypeFloat42P18(TestContext ctx) { |
388 | 378 | testInferDataType42P18(ctx, Float.class, 0F, "0"); |
389 | 379 | } |
390 | 380 |
|
391 | 381 | @Test |
| 382 | + @Repeat(10) |
392 | 383 | public void testInferDataTypeDouble42P18(TestContext ctx) { |
393 | 384 | testInferDataType42P18(ctx, Double.class, 0D, "0"); |
394 | 385 | } |
395 | 386 |
|
396 | 387 | @Test |
| 388 | + @Repeat(10) |
397 | 389 | public void testInferDataTypeLocalDate42P18(TestContext ctx) { |
398 | 390 | LocalDate value = LocalDate.now(); |
399 | 391 | testInferDataType42P18(ctx, LocalDate.class, value, value.toString()); |
400 | 392 | } |
401 | 393 |
|
402 | 394 | @Test |
| 395 | + @Repeat(10) |
403 | 396 | public void testInferDataTypeLocalDateTime42P18(TestContext ctx) { |
404 | 397 | LocalDateTime value = LocalDateTime.of(LocalDate.now(), LocalTime.NOON); |
405 | 398 | String suffix = value.toLocalDate() + " " + value.toLocalTime().format(DateTimeFormatter.ISO_LOCAL_TIME); |
406 | 399 | testInferDataType42P18(ctx, LocalDateTime.class, value, suffix, "{\"" + suffix + "\"}"); |
407 | 400 | } |
408 | 401 |
|
409 | 402 | @Test |
| 403 | + @Repeat(10) |
410 | 404 | public void testInferDataTypeOffsetDateTime42P18(TestContext ctx) { |
411 | 405 | OffsetDateTime value = OffsetDateTime.of(LocalDateTime.of(LocalDate.now(), LocalTime.NOON), ZoneOffset.UTC); |
412 | 406 | String suffix = value.toLocalDate() + " " + value.toLocalTime().format(DateTimeFormatter.ISO_LOCAL_TIME) + "+00"; |
413 | 407 | testInferDataType42P18(ctx, OffsetDateTime.class, value, suffix, "{\"" + suffix + "\"}"); |
414 | 408 | } |
415 | 409 |
|
416 | 410 | @Test |
| 411 | + @Repeat(10) |
417 | 412 | public void testInferDataTypeOffsetInterval42P18(TestContext ctx) { |
418 | 413 | Interval value = Interval.of(1); |
419 | 414 | testInferDataType42P18(ctx, Interval.class, value, "1 year", "{\"1 year\"}"); |
420 | 415 | } |
421 | 416 |
|
422 | 417 | @Test |
| 418 | + @Repeat(10) |
423 | 419 | public void testInferDataTypeBuffer42P18(TestContext ctx) { |
424 | 420 | testInferDataType42P18(ctx, Buffer.class, Buffer.buffer("WORLD"), "\\x574f524c44", "{\"\\\\x574f524c44\"}"); |
425 | 421 | } |
426 | 422 |
|
427 | 423 | @Test |
| 424 | + @Repeat(10) |
428 | 425 | public void testInferDataTypeUUID42P18(TestContext ctx) { |
429 | 426 | UUID value = UUID.randomUUID(); |
430 | 427 | testInferDataType42P18(ctx, UUID.class, value, "" + value); |
431 | 428 | } |
432 | 429 |
|
433 | 430 | @Test |
| 431 | + @Repeat(10) |
434 | 432 | public void testInferDataTypeJsonObject42P18(TestContext ctx) { |
435 | 433 | JsonObject value = new JsonObject().put("foo", "bar"); |
436 | 434 | testInferDataType42P18(ctx, JsonObject.class, value, "" + value, "{\"{\\\"foo\\\":\\\"bar\\\"}\"}"); |
437 | 435 | } |
438 | 436 |
|
439 | 437 | @Test |
| 438 | + @Repeat(10) |
440 | 439 | public void testInferDataTypeJsonArray42P18(TestContext ctx) { |
441 | 440 | JsonArray value = new JsonArray().add(1).add("foo").add(true); |
442 | 441 | testInferDataType42P18(ctx, JsonArray.class, value, "" + value, "{\"[1,\\\"foo\\\",true]\"}"); |
443 | 442 | } |
444 | 443 |
|
445 | 444 | @Test |
| 445 | + @Repeat(10) |
446 | 446 | public void testInferDataTypePoint42P18(TestContext ctx) { |
447 | 447 | Point value = new Point(); |
448 | 448 | testInferDataType42P18(ctx, Point.class, value, "(0,0)", "{\"(0,0)\"}"); |
449 | 449 | } |
450 | 450 |
|
451 | 451 | @Test |
| 452 | + @Repeat(10) |
452 | 453 | public void testInferDataTypeLine42P18(TestContext ctx) { |
453 | 454 | Line value = new Line(1.0, 0.0, 0.0); |
454 | 455 | testInferDataType42P18(ctx, Line.class, value, "{1,0,0}", "{\"{1,0,0}\"}"); |
455 | 456 | } |
456 | 457 |
|
457 | 458 | @Test |
| 459 | + @Repeat(10) |
458 | 460 | public void testInferDataTypeLineSegment42P18(TestContext ctx) { |
459 | 461 | LineSegment value = new LineSegment(); |
460 | 462 | testInferDataType42P18(ctx, LineSegment.class, value, "[(0,0),(0,0)]", "{\"[(0,0),(0,0)]\"}"); |
461 | 463 | } |
462 | 464 |
|
463 | 465 | @Test |
| 466 | + @Repeat(10) |
464 | 467 | public void testInferDataTypeBox42P18(TestContext ctx) { |
465 | 468 | Box value = new Box(); |
466 | 469 | testInferDataType42P18(ctx, Box.class, value, "(0,0),(0,0)"); |
467 | 470 | } |
468 | 471 |
|
469 | 472 | @Test |
| 473 | + @Repeat(10) |
470 | 474 | public void testInferDataTypePath42P18(TestContext ctx) { |
471 | 475 | Path value = new Path().addPoint(new Point()); |
472 | 476 | testInferDataType42P18(ctx, Path.class, value, "((0,0))", "{\"((0,0))\"}"); |
473 | 477 | } |
474 | 478 |
|
475 | 479 | @Test |
| 480 | + @Repeat(10) |
476 | 481 | public void testInferDataTypePolygon42P18(TestContext ctx) { |
477 | 482 | Polygon value = new Polygon().addPoint(new Point()).addPoint(new Point()).addPoint(new Point()); |
478 | 483 | testInferDataType42P18(ctx, Polygon.class, value, "((0,0),(0,0),(0,0))", "{\"((0,0),(0,0),(0,0))\"}"); |
479 | 484 | } |
480 | 485 |
|
481 | 486 | @Test |
| 487 | + @Repeat(10) |
482 | 488 | public void testInferDataTypeCircle42P18(TestContext ctx) { |
483 | 489 | Circle value = new Circle(); |
484 | 490 | testInferDataType42P18(ctx, Circle.class, value, "<(0,0),0>", "{\"<(0,0),0>\"}"); |
@@ -510,14 +516,21 @@ private <T> void testInferDataType42P18(TestContext ctx, Class<T> type, T value, |
510 | 516 | })); |
511 | 517 | })); |
512 | 518 | PgConnection.connect(vertx, options()).onComplete(ctx.asyncAssertSuccess(conn -> { |
| 519 | + Async async = ctx.async(); |
513 | 520 | conn.begin() |
514 | | - .flatMap(tx -> conn.preparedQuery("SELECT CONCAT('HELLO ', $1)").execute(Tuple.of(value)) |
515 | | - .eventually(() -> conn.close()) |
516 | | - .onComplete(ctx.asyncAssertFailure(failure -> { |
517 | | - if (!hasSqlstateCode(failure, "42P18")) { |
518 | | - ctx.fail(failure); |
519 | | - } |
520 | | - }))); |
| 521 | + .compose(tx -> conn.preparedQuery("SELECT CONCAT('HELLO ', $1)").execute(Tuple.of(value))) |
| 522 | + .onComplete(ar -> { |
| 523 | + if (ar.succeeded()) { |
| 524 | + conn.close().onComplete(v -> ctx.fail("Expected failure with SQLSTATE 42P18")); |
| 525 | + return; |
| 526 | + } |
| 527 | + Throwable failure = ar.cause(); |
| 528 | + if (!hasSqlstateCode(failure, "42P18")) { |
| 529 | + conn.close().onComplete(ctx.asyncAssertSuccess(v -> ctx.fail(failure))); |
| 530 | + return; |
| 531 | + } |
| 532 | + conn.close().onComplete(v -> async.complete()); |
| 533 | + }); |
521 | 534 | })); |
522 | 535 | } |
523 | 536 |
|
|
0 commit comments