|
34 | 34 | import oracle.r2dbc.OracleR2dbcOptions;
|
35 | 35 | import oracle.r2dbc.test.DatabaseConfig;
|
36 | 36 | import oracle.r2dbc.util.TestContextFactory;
|
37 |
| -import org.junit.jupiter.api.Assumptions; |
38 | 37 | import org.junit.jupiter.api.Test;
|
39 | 38 | import reactor.core.publisher.Flux;
|
40 | 39 | import reactor.core.publisher.Mono;
|
41 | 40 |
|
| 41 | +import javax.sql.DataSource; |
42 | 42 | import java.io.IOException;
|
43 | 43 | import java.nio.channels.ServerSocketChannel;
|
44 | 44 | import java.nio.channels.SocketChannel;
|
|
49 | 49 | import java.time.Duration;
|
50 | 50 | import java.time.ZonedDateTime;
|
51 | 51 | import java.util.List;
|
| 52 | +import java.util.Map; |
52 | 53 | import java.util.Objects;
|
53 | 54 | import java.util.Optional;
|
54 | 55 | import java.util.Properties;
|
|
63 | 64 | import java.util.concurrent.TimeUnit;
|
64 | 65 | import java.util.concurrent.TimeoutException;
|
65 | 66 | import java.util.concurrent.atomic.AtomicInteger;
|
| 67 | +import java.util.function.Function; |
66 | 68 | import java.util.stream.Collectors;
|
67 | 69 |
|
68 | 70 | import static io.r2dbc.spi.ConnectionFactoryOptions.CONNECT_TIMEOUT;
|
|
78 | 80 | import static oracle.r2dbc.test.DatabaseConfig.connectTimeout;
|
79 | 81 | import static oracle.r2dbc.test.DatabaseConfig.connectionFactoryOptions;
|
80 | 82 | import static oracle.r2dbc.test.DatabaseConfig.host;
|
81 |
| -import static oracle.r2dbc.test.DatabaseConfig.jdbcVersion; |
82 | 83 | import static oracle.r2dbc.test.DatabaseConfig.password;
|
83 | 84 | import static oracle.r2dbc.test.DatabaseConfig.port;
|
84 | 85 | import static oracle.r2dbc.test.DatabaseConfig.protocol;
|
@@ -119,23 +120,7 @@ public void testCreateDataSource() throws SQLException {
|
119 | 120 | // properties. The defaultProperties variable contains properties that
|
120 | 121 | // are set to default values by OracleReactiveJdbcAdapter and the Oracle
|
121 | 122 | // JDBC Driver
|
122 |
| - Properties defaultProperties = new Properties(); |
123 |
| - defaultProperties.setProperty( |
124 |
| - OracleConnection.CONNECTION_PROPERTY_J2EE13_COMPLIANT, "true"); |
125 |
| - defaultProperties.setProperty( |
126 |
| - OracleConnection.CONNECTION_PROPERTY_IMPLICIT_STATEMENT_CACHE_SIZE, "25"); |
127 |
| - defaultProperties.setProperty( |
128 |
| - OracleConnection.CONNECTION_PROPERTY_DEFAULT_LOB_PREFETCH_SIZE, |
129 |
| - "1048576"); |
130 |
| - defaultProperties.setProperty( |
131 |
| - OracleConnection.CONNECTION_PROPERTY_THIN_NET_USE_ZERO_COPY_IO, |
132 |
| - "false"); |
133 |
| - |
134 |
| - if (jdbcVersion() == 21) { |
135 |
| - // Oracle JDBC no longer sets this AC property by default in 23.3 |
136 |
| - defaultProperties.setProperty( |
137 |
| - OracleConnection.CONNECTION_PROPERTY_ENABLE_AC_SUPPORT, "false"); |
138 |
| - } |
| 123 | + Properties defaultProperties = getJdbcDefaultProperties(); |
139 | 124 |
|
140 | 125 | // Expect only default connection properties when no extended
|
141 | 126 | // options are supplied
|
@@ -681,7 +666,7 @@ public void testTimezoneAsRegion() {
|
681 | 666 | */
|
682 | 667 | @Test
|
683 | 668 | public void testEmptyProtocol() {
|
684 |
| - Assumptions.assumeTrue( |
| 669 | + assumeTrue( |
685 | 670 | DatabaseConfig.protocol() == null,
|
686 | 671 | "Test requires no PROTOCOL in config.properties");
|
687 | 672 |
|
@@ -713,6 +698,100 @@ public void testEmptyProtocol() {
|
713 | 698 | }
|
714 | 699 | }
|
715 | 700 |
|
| 701 | + @Test |
| 702 | + public void testJdbcPropertyOptions() throws SQLException { |
| 703 | + |
| 704 | + // Create a map where every Option of OracleR2dbcOptions is assigned to a |
| 705 | + // value. The values are not necessarily valid, or even of the right class |
| 706 | + // (every option is cast to Option<String>). That's OK because this test |
| 707 | + // just wants to make sure the values are transferred to OracleDataSource, |
| 708 | + // and it won't actually attempt to create a connection with these values. |
| 709 | + Map<Option<String>, String> optionValues = |
| 710 | + OracleR2dbcOptions.options() |
| 711 | + .stream() |
| 712 | + .map(option -> { |
| 713 | + @SuppressWarnings("unchecked") |
| 714 | + Option<String> stringOption = (Option<String>)option; |
| 715 | + return stringOption; |
| 716 | + }) |
| 717 | + .collect(Collectors.toMap( |
| 718 | + Function.identity(), |
| 719 | + option -> "VALUE OF " + option.name() |
| 720 | + )); |
| 721 | + |
| 722 | + ConnectionFactoryOptions.Builder optionsBuilder = |
| 723 | + ConnectionFactoryOptions.builder(); |
| 724 | + optionValues.forEach(optionsBuilder::option); |
| 725 | + |
| 726 | + DataSource dataSource = |
| 727 | + OracleReactiveJdbcAdapter.getInstance() |
| 728 | + .createDataSource(optionsBuilder.build()); |
| 729 | + assumeTrue(dataSource.isWrapperFor(OracleDataSource.class)); |
| 730 | + |
| 731 | + Properties actualProperties = |
| 732 | + dataSource.unwrap(OracleDataSource.class) |
| 733 | + .getConnectionProperties(); |
| 734 | + |
| 735 | + Properties expectedProperties = getJdbcDefaultProperties(); |
| 736 | + optionValues.forEach((option, value) -> |
| 737 | + expectedProperties.setProperty(option.name(), value)); |
| 738 | + |
| 739 | + expectedProperties.entrySet() |
| 740 | + .removeAll(actualProperties.entrySet()); |
| 741 | + |
| 742 | + // Don't expect OracleDataSource.getConnectionProperties() to have entries |
| 743 | + // for options that Oracle R2DBC doesn't set as connection properties. |
| 744 | + expectedProperties.entrySet() |
| 745 | + .removeIf(entry -> |
| 746 | + entry.getKey().toString().startsWith("oracle.r2dbc.")); |
| 747 | + |
| 748 | + // Don't expect OracleDataSource.getConnectionProperties() to have entries |
| 749 | + // for options of security sensitive values. |
| 750 | + expectedProperties.entrySet() |
| 751 | + .removeIf(entry -> |
| 752 | + entry.getKey().toString().toLowerCase().contains("password")); |
| 753 | + |
| 754 | + assertTrue( |
| 755 | + expectedProperties.isEmpty(), |
| 756 | + "One or more properties were not set: " + expectedProperties); |
| 757 | + } |
| 758 | + |
| 759 | + /** |
| 760 | + * Returns the connection properties that will be set by default when an |
| 761 | + * {@link OracleDataSource} is created. Tests which verify the setting of |
| 762 | + * properties can assume these default properties will be set as well. |
| 763 | + * |
| 764 | + * @return Properties that OracleDataSource sets by default. |
| 765 | + */ |
| 766 | + private static Properties getJdbcDefaultProperties() throws SQLException { |
| 767 | + |
| 768 | + // Start with any properties that JDBC will set by default. For example, the |
| 769 | + // 21 driver would set CONNECTION_PROPERTY_ENABLE_AC_SUPPORT="false" by |
| 770 | + // default. |
| 771 | + Properties defaultProperties = |
| 772 | + new oracle.jdbc.datasource.impl.OracleDataSource() |
| 773 | + .getConnectionProperties(); |
| 774 | + |
| 775 | + if (defaultProperties == null) |
| 776 | + defaultProperties = new Properties(); |
| 777 | + |
| 778 | + // Set the properties that Oracle R2DBC will set by default |
| 779 | + // Not referencing the deprecated |
| 780 | + // OracleConnection.CONNECTION_PROPERTY_J2EE13_COMPLIANT field, just in case |
| 781 | + // it gets removed in a future release of Oracle JDBC. |
| 782 | + defaultProperties.setProperty("oracle.jdbc.J2EE13Compliant", "true"); |
| 783 | + defaultProperties.setProperty( |
| 784 | + OracleConnection.CONNECTION_PROPERTY_IMPLICIT_STATEMENT_CACHE_SIZE, "25"); |
| 785 | + defaultProperties.setProperty( |
| 786 | + OracleConnection.CONNECTION_PROPERTY_DEFAULT_LOB_PREFETCH_SIZE, |
| 787 | + "1048576"); |
| 788 | + defaultProperties.setProperty( |
| 789 | + OracleConnection.CONNECTION_PROPERTY_THIN_NET_USE_ZERO_COPY_IO, |
| 790 | + "false"); |
| 791 | + |
| 792 | + return defaultProperties; |
| 793 | + } |
| 794 | + |
716 | 795 | /**
|
717 | 796 | * Returns an Oracle Net Descriptor having the values configured by
|
718 | 797 | * {@link DatabaseConfig}
|
|
0 commit comments