|
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.tests.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; |
| 21 | +import io.vertx.ext.unit.junit.Repeat; |
| 22 | +import io.vertx.ext.unit.junit.RepeatRule; |
27 | 23 | import io.vertx.pgclient.PgConnectOptions; |
28 | 24 | import io.vertx.pgclient.PgConnection; |
29 | 25 | import io.vertx.pgclient.PgException; |
30 | | -import io.vertx.pgclient.data.Box; |
31 | | -import io.vertx.pgclient.data.Circle; |
32 | | -import io.vertx.pgclient.data.Interval; |
33 | | -import io.vertx.pgclient.data.Line; |
34 | | -import io.vertx.pgclient.data.LineSegment; |
35 | | -import io.vertx.pgclient.data.Path; |
36 | | -import io.vertx.pgclient.data.Point; |
37 | | -import io.vertx.pgclient.data.Polygon; |
38 | | -import io.vertx.sqlclient.Cursor; |
39 | | -import io.vertx.sqlclient.Row; |
40 | | -import io.vertx.sqlclient.RowIterator; |
41 | | -import io.vertx.sqlclient.RowSet; |
42 | | -import io.vertx.sqlclient.RowStream; |
43 | | -import io.vertx.sqlclient.Tuple; |
| 26 | +import io.vertx.pgclient.data.*; |
| 27 | +import io.vertx.sqlclient.*; |
44 | 28 | import org.junit.After; |
45 | 29 | import org.junit.Before; |
| 30 | +import org.junit.Rule; |
46 | 31 | import org.junit.Test; |
47 | 32 |
|
48 | 33 | import java.lang.reflect.Array; |
49 | | -import java.time.LocalDate; |
50 | | -import java.time.LocalDateTime; |
51 | | -import java.time.LocalTime; |
52 | | -import java.time.OffsetDateTime; |
53 | | -import java.time.ZoneOffset; |
| 34 | +import java.time.*; |
54 | 35 | import java.time.format.DateTimeFormatter; |
55 | 36 | import java.util.Collections; |
56 | 37 | import java.util.List; |
|
65 | 46 | */ |
66 | 47 | public abstract class PreparedStatementTestBase extends PgTestBase { |
67 | 48 |
|
| 49 | + @Rule |
| 50 | + public RepeatRule rule = new RepeatRule(); |
| 51 | + |
68 | 52 | Vertx vertx; |
69 | 53 |
|
70 | 54 | protected abstract PgConnectOptions options(); |
@@ -397,126 +381,148 @@ public void testCloseStatement(TestContext ctx) { |
397 | 381 | } |
398 | 382 |
|
399 | 383 | @Test |
| 384 | + @Repeat(10) |
400 | 385 | public void testInferDataTypeString42P18(TestContext ctx) { |
401 | 386 | testInferDataType42P18(ctx, String.class, "WORLD", "WORLD"); |
402 | 387 | } |
403 | 388 |
|
404 | 389 | @Test |
| 390 | + @Repeat(10) |
405 | 391 | public void testInferDataTypeBoolean42P18(TestContext ctx) { |
406 | 392 | testInferDataType42P18(ctx, Boolean.class, true, "t"); |
407 | 393 | } |
408 | 394 |
|
409 | 395 | @Test |
| 396 | + @Repeat(10) |
410 | 397 | public void testInferDataTypeShort42P18(TestContext ctx) { |
411 | 398 | testInferDataType42P18(ctx, Short.class, (short)2, "2"); |
412 | 399 | } |
413 | 400 |
|
414 | 401 | @Test |
| 402 | + @Repeat(10) |
415 | 403 | public void testInferDataTypeInteger42P18(TestContext ctx) { |
416 | 404 | testInferDataType42P18(ctx, Integer.class, Integer.MAX_VALUE, "" + Integer.MAX_VALUE); |
417 | 405 | } |
418 | 406 |
|
419 | 407 | @Test |
| 408 | + @Repeat(10) |
420 | 409 | public void testInferDataTypeLong42P18(TestContext ctx) { |
421 | 410 | testInferDataType42P18(ctx, Long.class, Long.MAX_VALUE, "" + Long.MAX_VALUE); |
422 | 411 | } |
423 | 412 |
|
424 | 413 | @Test |
| 414 | + @Repeat(10) |
425 | 415 | public void testInferDataTypeFloat42P18(TestContext ctx) { |
426 | 416 | testInferDataType42P18(ctx, Float.class, 0F, "0"); |
427 | 417 | } |
428 | 418 |
|
429 | 419 | @Test |
| 420 | + @Repeat(10) |
430 | 421 | public void testInferDataTypeDouble42P18(TestContext ctx) { |
431 | 422 | testInferDataType42P18(ctx, Double.class, 0D, "0"); |
432 | 423 | } |
433 | 424 |
|
434 | 425 | @Test |
| 426 | + @Repeat(10) |
435 | 427 | public void testInferDataTypeLocalDate42P18(TestContext ctx) { |
436 | 428 | LocalDate value = LocalDate.now(); |
437 | 429 | testInferDataType42P18(ctx, LocalDate.class, value, value.toString()); |
438 | 430 | } |
439 | 431 |
|
440 | 432 | @Test |
| 433 | + @Repeat(10) |
441 | 434 | public void testInferDataTypeLocalDateTime42P18(TestContext ctx) { |
442 | 435 | LocalDateTime value = LocalDateTime.of(LocalDate.now(), LocalTime.NOON); |
443 | 436 | String suffix = value.toLocalDate() + " " + value.toLocalTime().format(DateTimeFormatter.ISO_LOCAL_TIME); |
444 | 437 | testInferDataType42P18(ctx, LocalDateTime.class, value, suffix, "{\"" + suffix + "\"}"); |
445 | 438 | } |
446 | 439 |
|
447 | 440 | @Test |
| 441 | + @Repeat(10) |
448 | 442 | public void testInferDataTypeOffsetDateTime42P18(TestContext ctx) { |
449 | 443 | OffsetDateTime value = OffsetDateTime.of(LocalDateTime.of(LocalDate.now(), LocalTime.NOON), ZoneOffset.UTC); |
450 | 444 | String suffix = value.toLocalDate() + " " + value.toLocalTime().format(DateTimeFormatter.ISO_LOCAL_TIME) + "+00"; |
451 | 445 | testInferDataType42P18(ctx, OffsetDateTime.class, value, suffix, "{\"" + suffix + "\"}"); |
452 | 446 | } |
453 | 447 |
|
454 | 448 | @Test |
| 449 | + @Repeat(10) |
455 | 450 | public void testInferDataTypeOffsetInterval42P18(TestContext ctx) { |
456 | 451 | Interval value = Interval.of(1); |
457 | 452 | testInferDataType42P18(ctx, Interval.class, value, "1 year", "{\"1 year\"}"); |
458 | 453 | } |
459 | 454 |
|
460 | 455 | @Test |
| 456 | + @Repeat(10) |
461 | 457 | public void testInferDataTypeBuffer42P18(TestContext ctx) { |
462 | 458 | testInferDataType42P18(ctx, Buffer.class, Buffer.buffer("WORLD"), "\\x574f524c44", "{\"\\\\x574f524c44\"}"); |
463 | 459 | } |
464 | 460 |
|
465 | 461 | @Test |
| 462 | + @Repeat(10) |
466 | 463 | public void testInferDataTypeUUID42P18(TestContext ctx) { |
467 | 464 | UUID value = UUID.randomUUID(); |
468 | 465 | testInferDataType42P18(ctx, UUID.class, value, "" + value); |
469 | 466 | } |
470 | 467 |
|
471 | 468 | @Test |
| 469 | + @Repeat(10) |
472 | 470 | public void testInferDataTypeJsonObject42P18(TestContext ctx) { |
473 | 471 | JsonObject value = new JsonObject().put("foo", "bar"); |
474 | 472 | testInferDataType42P18(ctx, JsonObject.class, value, "" + value, "{\"{\\\"foo\\\":\\\"bar\\\"}\"}"); |
475 | 473 | } |
476 | 474 |
|
477 | 475 | @Test |
| 476 | + @Repeat(10) |
478 | 477 | public void testInferDataTypeJsonArray42P18(TestContext ctx) { |
479 | 478 | JsonArray value = new JsonArray().add(1).add("foo").add(true); |
480 | 479 | testInferDataType42P18(ctx, JsonArray.class, value, "" + value, "{\"[1,\\\"foo\\\",true]\"}"); |
481 | 480 | } |
482 | 481 |
|
483 | 482 | @Test |
| 483 | + @Repeat(10) |
484 | 484 | public void testInferDataTypePoint42P18(TestContext ctx) { |
485 | 485 | Point value = new Point(); |
486 | 486 | testInferDataType42P18(ctx, Point.class, value, "(0,0)", "{\"(0,0)\"}"); |
487 | 487 | } |
488 | 488 |
|
489 | 489 | @Test |
| 490 | + @Repeat(10) |
490 | 491 | public void testInferDataTypeLine42P18(TestContext ctx) { |
491 | 492 | Line value = new Line(1.0, 0.0, 0.0); |
492 | 493 | testInferDataType42P18(ctx, Line.class, value, "{1,0,0}", "{\"{1,0,0}\"}"); |
493 | 494 | } |
494 | 495 |
|
495 | 496 | @Test |
| 497 | + @Repeat(10) |
496 | 498 | public void testInferDataTypeLineSegment42P18(TestContext ctx) { |
497 | 499 | LineSegment value = new LineSegment(); |
498 | 500 | testInferDataType42P18(ctx, LineSegment.class, value, "[(0,0),(0,0)]", "{\"[(0,0),(0,0)]\"}"); |
499 | 501 | } |
500 | 502 |
|
501 | 503 | @Test |
| 504 | + @Repeat(10) |
502 | 505 | public void testInferDataTypeBox42P18(TestContext ctx) { |
503 | 506 | Box value = new Box(); |
504 | 507 | testInferDataType42P18(ctx, Box.class, value, "(0,0),(0,0)"); |
505 | 508 | } |
506 | 509 |
|
507 | 510 | @Test |
| 511 | + @Repeat(10) |
508 | 512 | public void testInferDataTypePath42P18(TestContext ctx) { |
509 | 513 | Path value = new Path().addPoint(new Point()); |
510 | 514 | testInferDataType42P18(ctx, Path.class, value, "((0,0))", "{\"((0,0))\"}"); |
511 | 515 | } |
512 | 516 |
|
513 | 517 | @Test |
| 518 | + @Repeat(10) |
514 | 519 | public void testInferDataTypePolygon42P18(TestContext ctx) { |
515 | 520 | Polygon value = new Polygon().addPoint(new Point()).addPoint(new Point()).addPoint(new Point()); |
516 | 521 | testInferDataType42P18(ctx, Polygon.class, value, "((0,0),(0,0),(0,0))", "{\"((0,0),(0,0),(0,0))\"}"); |
517 | 522 | } |
518 | 523 |
|
519 | 524 | @Test |
| 525 | + @Repeat(10) |
520 | 526 | public void testInferDataTypeCircle42P18(TestContext ctx) { |
521 | 527 | Circle value = new Circle(); |
522 | 528 | testInferDataType42P18(ctx, Circle.class, value, "<(0,0),0>", "{\"<(0,0),0>\"}"); |
@@ -548,14 +554,21 @@ private <T> void testInferDataType42P18(TestContext ctx, Class<T> type, T value, |
548 | 554 | })); |
549 | 555 | })); |
550 | 556 | PgConnection.connect(vertx, options()).onComplete(ctx.asyncAssertSuccess(conn -> { |
| 557 | + Async async = ctx.async(); |
551 | 558 | conn.begin() |
552 | | - .flatMap(tx -> conn.preparedQuery("SELECT CONCAT('HELLO ', $1)").execute(Tuple.of(value)) |
553 | | - .eventually(() -> conn.close()) |
554 | | - .onComplete(ctx.asyncAssertFailure(failure -> { |
555 | | - if (!hasSqlstateCode(failure, "42P18")) { |
556 | | - ctx.fail(failure); |
557 | | - } |
558 | | - }))); |
| 559 | + .compose(tx -> conn.preparedQuery("SELECT CONCAT('HELLO ', $1)").execute(Tuple.of(value))) |
| 560 | + .onComplete(ar -> { |
| 561 | + if (ar.succeeded()) { |
| 562 | + conn.close().onComplete(v -> ctx.fail("Expected failure with SQLSTATE 42P18")); |
| 563 | + return; |
| 564 | + } |
| 565 | + Throwable failure = ar.cause(); |
| 566 | + if (!hasSqlstateCode(failure, "42P18")) { |
| 567 | + conn.close().onComplete(ctx.asyncAssertSuccess(v -> ctx.fail(failure))); |
| 568 | + return; |
| 569 | + } |
| 570 | + conn.close().onComplete(v -> async.complete()); |
| 571 | + }); |
559 | 572 | })); |
560 | 573 | } |
561 | 574 |
|
|
0 commit comments