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 ;
98
99
import static org .junit .jupiter .api .Assertions .assertThrows ;
99
100
import static org .junit .jupiter .api .Assertions .assertTrue ;
100
101
import static org .junit .jupiter .api .Assertions .fail ;
102
+ import static org .junit .jupiter .api .Assumptions .assumeTrue ;
101
103
102
104
/**
103
105
* Verifies that
@@ -118,23 +120,7 @@ public void testCreateDataSource() throws SQLException {
118
120
// properties. The defaultProperties variable contains properties that
119
121
// are set to default values by OracleReactiveJdbcAdapter and the Oracle
120
122
// JDBC Driver
121
- Properties defaultProperties = new Properties ();
122
- defaultProperties .setProperty (
123
- OracleConnection .CONNECTION_PROPERTY_J2EE13_COMPLIANT , "true" );
124
- defaultProperties .setProperty (
125
- OracleConnection .CONNECTION_PROPERTY_IMPLICIT_STATEMENT_CACHE_SIZE , "25" );
126
- defaultProperties .setProperty (
127
- OracleConnection .CONNECTION_PROPERTY_DEFAULT_LOB_PREFETCH_SIZE ,
128
- "1048576" );
129
- defaultProperties .setProperty (
130
- OracleConnection .CONNECTION_PROPERTY_THIN_NET_USE_ZERO_COPY_IO ,
131
- "false" );
132
-
133
- if (jdbcVersion () == 21 ) {
134
- // Oracle JDBC no longer sets this AC property by default in 23.3
135
- defaultProperties .setProperty (
136
- OracleConnection .CONNECTION_PROPERTY_ENABLE_AC_SUPPORT , "false" );
137
- }
123
+ Properties defaultProperties = getJdbcDefaultProperties ();
138
124
139
125
// Expect only default connection properties when no extended
140
126
// options are supplied
@@ -672,7 +658,7 @@ public void testTimezoneAsRegion() {
672
658
*/
673
659
@ Test
674
660
public void testEmptyProtocol () {
675
- Assumptions . assumeTrue (
661
+ assumeTrue (
676
662
DatabaseConfig .protocol () == null ,
677
663
"Test requires no PROTOCOL in config.properties" );
678
664
@@ -704,6 +690,100 @@ public void testEmptyProtocol() {
704
690
}
705
691
}
706
692
693
+ @ Test
694
+ public void testJdbcPropertyOptions () throws SQLException {
695
+
696
+ // Create a map where every Option of OracleR2dbcOptions is assigned to a
697
+ // value. The values are not necessarily valid, or even of the right class
698
+ // (every option is cast to Option<String>). That's OK because this test
699
+ // just wants to make sure the values are transferred to OracleDataSource,
700
+ // and it won't actually attempt to create a connection with these values.
701
+ Map <Option <String >, String > optionValues =
702
+ OracleR2dbcOptions .options ()
703
+ .stream ()
704
+ .map (option -> {
705
+ @ SuppressWarnings ("unchecked" )
706
+ Option <String > stringOption = (Option <String >)option ;
707
+ return stringOption ;
708
+ })
709
+ .collect (Collectors .toMap (
710
+ Function .identity (),
711
+ option -> "VALUE OF " + option .name ()
712
+ ));
713
+
714
+ ConnectionFactoryOptions .Builder optionsBuilder =
715
+ ConnectionFactoryOptions .builder ();
716
+ optionValues .forEach (optionsBuilder ::option );
717
+
718
+ DataSource dataSource =
719
+ OracleReactiveJdbcAdapter .getInstance ()
720
+ .createDataSource (optionsBuilder .build ());
721
+ assumeTrue (dataSource .isWrapperFor (OracleDataSource .class ));
722
+
723
+ Properties actualProperties =
724
+ dataSource .unwrap (OracleDataSource .class )
725
+ .getConnectionProperties ();
726
+
727
+ Properties expectedProperties = getJdbcDefaultProperties ();
728
+ optionValues .forEach ((option , value ) ->
729
+ expectedProperties .setProperty (option .name (), value ));
730
+
731
+ expectedProperties .entrySet ()
732
+ .removeAll (actualProperties .entrySet ());
733
+
734
+ // Don't expect OracleDataSource.getConnectionProperties() to have entries
735
+ // for options that Oracle R2DBC doesn't set as connection properties.
736
+ expectedProperties .entrySet ()
737
+ .removeIf (entry ->
738
+ entry .getKey ().toString ().startsWith ("oracle.r2dbc." ));
739
+
740
+ // Don't expect OracleDataSource.getConnectionProperties() to have entries
741
+ // for options of security sensitive values.
742
+ expectedProperties .entrySet ()
743
+ .removeIf (entry ->
744
+ entry .getKey ().toString ().toLowerCase ().contains ("password" ));
745
+
746
+ assertTrue (
747
+ expectedProperties .isEmpty (),
748
+ "One or more properties were not set: " + expectedProperties );
749
+ }
750
+
751
+ /**
752
+ * Returns the connection properties that will be set by default when an
753
+ * {@link OracleDataSource} is created. Tests which verify the setting of
754
+ * properties can assume these default properties will be set as well.
755
+ *
756
+ * @return Properties that OracleDataSource sets by default.
757
+ */
758
+ private static Properties getJdbcDefaultProperties () throws SQLException {
759
+
760
+ // Start with any properties that JDBC will set by default. For example, the
761
+ // 21 driver would set CONNECTION_PROPERTY_ENABLE_AC_SUPPORT="false" by
762
+ // default.
763
+ Properties defaultProperties =
764
+ new oracle .jdbc .datasource .impl .OracleDataSource ()
765
+ .getConnectionProperties ();
766
+
767
+ if (defaultProperties == null )
768
+ defaultProperties = new Properties ();
769
+
770
+ // Set the properties that Oracle R2DBC will set by default
771
+ // Not referencing the deprecated
772
+ // OracleConnection.CONNECTION_PROPERTY_J2EE13_COMPLIANT field, just in case
773
+ // it gets removed in a future release of Oracle JDBC.
774
+ defaultProperties .setProperty ("oracle.jdbc.J2EE13Compliant" , "true" );
775
+ defaultProperties .setProperty (
776
+ OracleConnection .CONNECTION_PROPERTY_IMPLICIT_STATEMENT_CACHE_SIZE , "25" );
777
+ defaultProperties .setProperty (
778
+ OracleConnection .CONNECTION_PROPERTY_DEFAULT_LOB_PREFETCH_SIZE ,
779
+ "1048576" );
780
+ defaultProperties .setProperty (
781
+ OracleConnection .CONNECTION_PROPERTY_THIN_NET_USE_ZERO_COPY_IO ,
782
+ "false" );
783
+
784
+ return defaultProperties ;
785
+ }
786
+
707
787
/**
708
788
* Returns an Oracle Net Descriptor having the values configured by
709
789
* {@link DatabaseConfig}
0 commit comments