Skip to content

Commit cd06ec9

Browse files
Merge branch 'main' of https://github.com/oracle/oracle-r2dbc into spi-0-9-0-M2
2 parents a39c32f + 8ad9e14 commit cd06ec9

File tree

4 files changed

+40
-11
lines changed

4 files changed

+40
-11
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ behavior of that Publisher in regards to deferred execution and multiple Subscri
197197
subscribes, supports multiple Subscribers, and caches the result of a database call
198198
(the same result of the same call is emitted to each Subscriber).
199199
- Typically, a Publisher of multiple items defers execution until a Subscriber
200-
signals demand, and does not support mulitple subscribers.
200+
signals demand, and does not support multiple subscribers.
201201

202202
### Errors
203203
- The error code of an R2dbcException is an [Oracle Database
@@ -224,7 +224,7 @@ of each row affected by an INSERT or UPDATE.
224224
- This behavior may change in a later release.
225225
- Programmers are advised not to use the ROWID as if it were a primary key.
226226
- The ROWID of a row may change.
227-
- After a row is deleted, it's ROWID may be reassigned to a new row.
227+
- After a row is deleted, its ROWID may be reassigned to a new row.
228228
- Further Reading: https://asktom.oracle.com/pls/apex/asktom.search?tag=is-it-safe-to-use-rowid-to-locate-a-row
229229
- A **blocking database call** is executed by a Statement returning generated
230230
values for a non-empty set of column names.
@@ -324,7 +324,7 @@ The following security guidelines should be followed when programming with the O
324324
- Option.sensitiveValueOf(OracleConnection.CONNECTION_PROPERTY_THIN_JAVAX_NET_SSL_KEYSTOREPASSWORD)
325325
- Option.sensitiveValueOf(OracleConnection.CONNECTION_PROPERTY_THIN_JAVAX_NET_SSL_TRUSTSTOREPASSWORD)
326326
### Defend Against Denial-of-Service Attacks
327-
- Use a connection pool and configure a maximum size to limit the amount of database sessions created by ConnectionFactory.create()
327+
- Use a connection pool and configure a maximum size to limit the number of database sessions created by ConnectionFactory.create()
328328
- Enforce a maximum batch size to limit invocations of Statement.add() or Batch.add(String).
329329
- Enforce a maximum fetch size to limit values supplied to Statement.fetchSize(int).
330330
- Enforce a maximum buffer size to limit memory usage when reading Blob and Clob objects.

src/main/java/oracle/r2dbc/impl/OracleReactiveJdbcAdapter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ private static void configureStandardOptions(
489489
oracleDataSource.setLoginTimeout(
490490
Math.toIntExact(timeout.getSeconds())
491491
// Round up to nearest whole second
492-
+ timeout.getNano() == 0 ? 0 : 1));
492+
+ (timeout.getNano() == 0 ? 0 : 1)));
493493
}
494494

495495
}

src/test/java/oracle/r2dbc/impl/OracleReactiveJdbcAdapterTest.java

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,7 @@
2929
import io.r2dbc.spi.Result;
3030
import oracle.jdbc.OracleConnection;
3131
import oracle.jdbc.datasource.OracleDataSource;
32-
import oracle.jdbc.driver.DatabaseError;
33-
import oracle.r2dbc.test.DatabaseConfig;
3432
import org.junit.jupiter.api.Test;
35-
import reactor.core.publisher.Flux;
3633
import reactor.core.publisher.Mono;
3734

3835
import java.io.IOException;
@@ -58,7 +55,6 @@
5855
import static io.r2dbc.spi.ConnectionFactoryOptions.PORT;
5956
import static io.r2dbc.spi.ConnectionFactoryOptions.STATEMENT_TIMEOUT;
6057
import static io.r2dbc.spi.ConnectionFactoryOptions.USER;
61-
6258
import static oracle.r2dbc.test.DatabaseConfig.connectTimeout;
6359
import static oracle.r2dbc.test.DatabaseConfig.host;
6460
import static oracle.r2dbc.test.DatabaseConfig.password;
@@ -67,7 +63,6 @@
6763
import static oracle.r2dbc.test.DatabaseConfig.sharedConnection;
6864
import static oracle.r2dbc.test.DatabaseConfig.sqlTimeout;
6965
import static oracle.r2dbc.test.DatabaseConfig.user;
70-
7166
import static oracle.r2dbc.util.Awaits.awaitError;
7267
import static oracle.r2dbc.util.Awaits.awaitExecution;
7368
import static oracle.r2dbc.util.Awaits.awaitNone;
@@ -78,6 +73,7 @@
7873
import static org.junit.jupiter.api.Assertions.assertEquals;
7974
import static org.junit.jupiter.api.Assertions.assertThrows;
8075
import static org.junit.jupiter.api.Assertions.assertTrue;
76+
import static org.junit.jupiter.api.Assertions.fail;
8177

8278
/**
8379
* Verifies that
@@ -333,7 +329,19 @@ public void testConnectTimeout()
333329
.option(HOST, "localhost")
334330
.option(PORT, listeningChannel.socket().getLocalPort())
335331
.option(DATABASE, serviceName())
336-
.option(CONNECT_TIMEOUT, Duration.ofMillis(500L))
332+
.option(CONNECT_TIMEOUT, Duration.ofSeconds(2))
333+
.build());
334+
335+
verifyConnectTimeout(listeningChannel, ConnectionFactoryOptions.parse(
336+
"r2dbc:oracle://localhost:" + listeningChannel.socket().getLocalPort()
337+
+ "?connectTimeout=PT2S")); // The value is parsed as a Duration
338+
339+
verifyConnectTimeout(listeningChannel, ConnectionFactoryOptions.builder()
340+
.option(DRIVER, "oracle")
341+
.option(HOST, "localhost")
342+
.option(PORT, listeningChannel.socket().getLocalPort())
343+
.option(DATABASE, serviceName())
344+
.option(CONNECT_TIMEOUT, Duration.ofMillis(500))
337345
.build());
338346

339347
verifyConnectTimeout(listeningChannel, ConnectionFactoryOptions.parse(
@@ -430,8 +438,27 @@ private void verifyConnectTimeout(
430438

431439
// Try to connect
432440
try {
441+
long start = System.currentTimeMillis();
433442
awaitError(R2dbcTimeoutException.class,
434443
ConnectionFactories.get(options).create());
444+
445+
// Compare the actual duration to the configured timeout
446+
Duration timeoutDelta =
447+
Duration.ofMillis(System.currentTimeMillis() - start)
448+
.minus(Duration.parse(
449+
options.getValue(Option.valueOf("connectTimeout")).toString()));
450+
451+
// Expect the actual duration to be at least as much as the configured
452+
// timeout
453+
if (timeoutDelta.isNegative())
454+
fail("Timeout triggered too soon: " + timeoutDelta);
455+
456+
// Expect the actual duration to be no more than two seconds longer
457+
// than the configured timeout. This should be a generous enough offset
458+
// to allow for testing on slow systems
459+
if (timeoutDelta.toSeconds() > 2)
460+
fail("Timeout triggered too late: " + timeoutDelta);
461+
435462
}
436463
catch (Throwable unexpected) {
437464
unexpected.printStackTrace();

src/test/java/oracle/r2dbc/test/DatabaseConfig.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
package oracle.r2dbc.test;
2323

24+
import io.r2dbc.spi.ColumnMetadata;
2425
import io.r2dbc.spi.Connection;
2526
import io.r2dbc.spi.ConnectionFactories;
2627
import io.r2dbc.spi.ConnectionFactory;
@@ -189,8 +190,9 @@ public static void showErrors(Connection connection) {
189190
.execute())
190191
.flatMap(result ->
191192
result.map((row, metadata) ->
192-
metadata.getColumnNames()
193+
metadata.getColumnMetadatas()
193194
.stream()
195+
.map(ColumnMetadata::getName)
194196
.map(name -> name + ": " + row.get(name))
195197
.collect(Collectors.joining("\n"))))
196198
.toStream()

0 commit comments

Comments
 (0)