Skip to content

Commit 7eeede5

Browse files
Test v$session options
1 parent 561eda5 commit 7eeede5

File tree

2 files changed

+68
-7
lines changed

2 files changed

+68
-7
lines changed

.github/workflows/startup/01_createUser.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,12 @@
3434
-- tables, and to query some V$ views:
3535
-- v$open_cursor (to verify if cursors are being closed).
3636
-- v$transaction (to verify if TransactionDefinitions are applied).
37+
-- v$session (to verify if VSESSION_* Options are applied).
3738
ALTER SESSION SET CONTAINER=xepdb1;
3839
CREATE ROLE r2dbc_test_user;
3940
GRANT SELECT ON v_$open_cursor TO r2dbc_test_user;
4041
GRANT SELECT ON v_$transaction TO r2dbc_test_user;
42+
GRANT SELECT ON v_$session TO r2dbc_test_user;
4143

4244
CREATE USER test IDENTIFIED BY test;
4345
GRANT connect, resource, unlimited tablespace, r2dbc_test_user TO test;

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

Lines changed: 66 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import oracle.jdbc.OracleConnection;
3131
import oracle.jdbc.datasource.OracleDataSource;
3232
import oracle.r2dbc.OracleR2dbcOptions;
33+
import oracle.r2dbc.test.DatabaseConfig;
3334
import org.junit.jupiter.api.Test;
3435
import reactor.core.publisher.Flux;
3536
import reactor.core.publisher.Mono;
@@ -63,6 +64,7 @@
6364
import static io.r2dbc.spi.ConnectionFactoryOptions.PORT;
6465
import static io.r2dbc.spi.ConnectionFactoryOptions.STATEMENT_TIMEOUT;
6566
import static io.r2dbc.spi.ConnectionFactoryOptions.USER;
67+
import static java.lang.String.format;
6668
import static oracle.r2dbc.test.DatabaseConfig.connectTimeout;
6769
import static oracle.r2dbc.test.DatabaseConfig.host;
6870
import static oracle.r2dbc.test.DatabaseConfig.password;
@@ -210,7 +212,7 @@ public void testCreateDataSource() throws SQLException {
210212
public void testTnsAdmin() throws IOException {
211213

212214
// Create an Oracle Net Descriptor
213-
String descriptor = String.format(
215+
String descriptor = format(
214216
"(DESCRIPTION=(ADDRESS=(HOST=%s)(PORT=%d)(PROTOCOL=tcp))" +
215217
"(CONNECT_DATA=(SERVICE_NAME=%s)))",
216218
host(), port(), serviceName());
@@ -227,13 +229,13 @@ public void testTnsAdmin() throws IOException {
227229
try {
228230
// Expect to connect with the descriptor in the R2DBC URL
229231
awaitNone(awaitOne(
230-
ConnectionFactories.get(String.format(
232+
ConnectionFactories.get(format(
231233
"r2dbc:oracle://%s:%s@?oracle.r2dbc.descriptor=%s",
232234
user(), password(), descriptor))
233235
.create())
234236
.close());
235237
awaitNone(awaitOne(
236-
ConnectionFactories.get(ConnectionFactoryOptions.parse(String.format(
238+
ConnectionFactories.get(ConnectionFactoryOptions.parse(format(
237239
"r2dbc:oracle://@?oracle.r2dbc.descriptor=%s", descriptor))
238240
.mutate()
239241
.option(USER, user())
@@ -245,14 +247,14 @@ public void testTnsAdmin() throws IOException {
245247
// Expect to connect with the tnsnames.ora file, when a URL specifies
246248
// the file path and an alias
247249
awaitNone(awaitOne(
248-
ConnectionFactories.get(String.format(
250+
ConnectionFactories.get(format(
249251
"r2dbc:oracle://%s:%s@?oracle.r2dbc.descriptor=%s&TNS_ADMIN=%s",
250252
user(), password(), "test_alias", userDir))
251253
.create())
252254
.close());
253255
awaitNone(awaitOne(
254256
ConnectionFactories.get(ConnectionFactoryOptions.parse(
255-
String.format(
257+
format(
256258
"r2dbc:oracle://@?oracle.r2dbc.descriptor=%s&TNS_ADMIN=%s",
257259
"test_alias", userDir))
258260
.mutate()
@@ -288,14 +290,14 @@ public void testTnsAdmin() throws IOException {
288290

289291
// Create an ojdbc.properties file containing the user name
290292
Files.writeString(Path.of("ojdbc.properties"),
291-
String.format("user=%s", user()),
293+
format("user=%s", user()),
292294
StandardOpenOption.CREATE_NEW);
293295
try {
294296
// Expect to connect with the tnsnames.ora and ojdbc.properties files,
295297
// when a URL specifies their path and an alias, the properties file
296298
// specifies a user, and a standard option specifies the password.
297299
awaitNone(awaitOne(
298-
ConnectionFactories.get(ConnectionFactoryOptions.parse(String.format(
300+
ConnectionFactories.get(ConnectionFactoryOptions.parse(format(
299301
"r2dbc:oracle://?oracle.r2dbc.descriptor=%s&TNS_ADMIN=%s",
300302
"test_alias", userDir))
301303
.mutate()
@@ -469,6 +471,63 @@ public void testExecutorOption() {
469471
}
470472
}
471473

474+
/**
475+
* Verifies the
476+
* {@link OracleR2dbcOptions#VSESSION_OSUSER},
477+
* {@link OracleR2dbcOptions#VSESSION_TERMINAL},
478+
* {@link OracleR2dbcOptions#VSESSION_PROCESS},
479+
* {@link OracleR2dbcOptions#VSESSION_PROGRAM}, and
480+
* {@link OracleR2dbcOptions#VSESSION_MACHINE} options.
481+
*/
482+
@Test
483+
public void testVSessionOptions() {
484+
String osuser = "test-osuser";
485+
String terminal = "test-terminal";
486+
String process = "test-process";
487+
String program = "test-program";
488+
String machine = "test-machine";
489+
490+
// Verify configuration with URL parameters
491+
Connection connection = awaitOne(ConnectionFactories.get(
492+
ConnectionFactoryOptions.parse(
493+
format("r2dbc:oracle://%s:%d/%s" +
494+
"?v$session.osuser=%s" +
495+
"&v$session.terminal=%s" +
496+
"&v$session.process=%s" +
497+
"&v$session.program=%s" +
498+
"&v$session.machine=%s",
499+
host(), port(), serviceName(),
500+
osuser, terminal, process, program, machine))
501+
.mutate()
502+
.option(USER, user())
503+
.option(PASSWORD, password())
504+
.build())
505+
.create());
506+
try {
507+
Result result = awaitOne(connection.createStatement(
508+
"SELECT count(*)" +
509+
" FROM v$session" +
510+
" WHERE osuser=?" +
511+
" AND terminal=?" +
512+
" AND process=?" +
513+
" AND program=?" +
514+
" AND machine=?")
515+
.bind(0, osuser)
516+
.bind(1, terminal)
517+
.bind(2, process)
518+
.bind(3, program)
519+
.bind(4, machine)
520+
.execute());
521+
522+
assertEquals(
523+
Integer.valueOf(1),
524+
awaitOne(result.map(row -> row.get(0, Integer.class))));
525+
}
526+
finally {
527+
tryAwaitNone(connection.close());
528+
}
529+
}
530+
472531
/**
473532
* Verifies that an attempt to connect with a {@code listeningChannel}
474533
* results in an {@link R2dbcTimeoutException}.

0 commit comments

Comments
 (0)