|
28 | 28 | import io.r2dbc.spi.Result.UpdateCount; |
29 | 29 | import io.r2dbc.spi.Row; |
30 | 30 | import io.r2dbc.spi.RowMetadata; |
| 31 | +import io.r2dbc.spi.Statement; |
| 32 | +import oracle.r2dbc.OracleR2dbcWarning; |
31 | 33 | import org.junit.jupiter.api.Test; |
32 | 34 | import org.reactivestreams.Publisher; |
33 | 35 | import reactor.core.publisher.Flux; |
|
55 | 57 | import static oracle.r2dbc.util.Awaits.tryAwaitExecution; |
56 | 58 | import static oracle.r2dbc.util.Awaits.tryAwaitNone; |
57 | 59 | import static org.junit.jupiter.api.Assertions.assertEquals; |
| 60 | +import static org.junit.jupiter.api.Assertions.assertFalse; |
| 61 | +import static org.junit.jupiter.api.Assertions.assertInstanceOf; |
| 62 | +import static org.junit.jupiter.api.Assertions.assertSame; |
58 | 63 | import static org.junit.jupiter.api.Assertions.assertThrows; |
59 | 64 | import static org.junit.jupiter.api.Assertions.assertTrue; |
60 | 65 | import static org.junit.jupiter.api.Assertions.fail; |
@@ -624,4 +629,60 @@ else if (index == 1) { |
624 | 629 | } |
625 | 630 | } |
626 | 631 |
|
| 632 | + /** |
| 633 | + * Verifies that a warnings are emitted as {@code Message} segments with an |
| 634 | + * {@link oracle.r2dbc.OracleR2dbcWarning}. |
| 635 | + */ |
| 636 | + @Test |
| 637 | + public void testOracleR2dbcWarning() { |
| 638 | + Connection connection = awaitOne(sharedConnection()); |
| 639 | + try { |
| 640 | + |
| 641 | + // Expect a warning for forcing a view that references a non-existant |
| 642 | + // table |
| 643 | + String sql = "CREATE OR REPLACE FORCE VIEW testOracleR2dbcWarning AS" + |
| 644 | + " SELECT x FROM thisdoesnotexist"; |
| 645 | + Statement warningStatement = connection.createStatement(sql); |
| 646 | + |
| 647 | + // Collect the segments |
| 648 | + List<Result.Segment> segments = |
| 649 | + awaitMany(Flux.from(warningStatement.execute()) |
| 650 | + .flatMap(result -> result.flatMap(Mono::just))); |
| 651 | + |
| 652 | + // Expect the update count segment first. Warnings are always emitted |
| 653 | + // after any result values. |
| 654 | + Result.Segment firstSegment = segments.get(0); |
| 655 | + assertEquals(0, |
| 656 | + assertInstanceOf(UpdateCount.class, firstSegment).value()); |
| 657 | + assertFalse(OracleR2dbcWarning.isWarning(firstSegment)); |
| 658 | + assertThrows(IllegalArgumentException.class, () -> |
| 659 | + OracleR2dbcWarning.getWarning(firstSegment)); |
| 660 | + |
| 661 | + // Expect the message segment next. Expect it to have the fixed message |
| 662 | + // and error number used by Oracle JDBC for all warnings. |
| 663 | + Result.Segment secondSegment = segments.get(1); |
| 664 | + Message message = assertInstanceOf(Message.class, secondSegment); |
| 665 | + assertEquals( |
| 666 | + message.message(), "Warning: execution completed with warning"); |
| 667 | + assertEquals(message.errorCode(), 17110); |
| 668 | + assertEquals("", message.sqlState()); |
| 669 | + OracleR2dbcWarning warning = |
| 670 | + assertInstanceOf(OracleR2dbcWarning.class, message.exception()); |
| 671 | + assertEquals(message.message(), warning.getMessage()); |
| 672 | + assertEquals(message.errorCode(), warning.getErrorCode()); |
| 673 | + assertEquals(message.sqlState(), warning.getSqlState()); |
| 674 | + assertEquals(sql, warning.getSql()); |
| 675 | + assertTrue(OracleR2dbcWarning.isWarning(secondSegment)); |
| 676 | + assertSame(warning, OracleR2dbcWarning.getWarning(secondSegment)); |
| 677 | + |
| 678 | + // Verify that there are not any more segments |
| 679 | + assertEquals(2, segments.size()); |
| 680 | + } |
| 681 | + finally { |
| 682 | + tryAwaitExecution( |
| 683 | + connection.createStatement("DROP VIEW testOracleR2dbcWarning")); |
| 684 | + tryAwaitNone(connection.close()); |
| 685 | + } |
| 686 | + } |
| 687 | + |
627 | 688 | } |
0 commit comments