-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Dynamic pool configuration for Oracle Client
- Loading branch information
1 parent
028fff5
commit 3980b35
Showing
5 changed files
with
172 additions
and
22 deletions.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
...ployment/src/test/java/io/quarkus/reactive/oracle/client/ChangingCredentialsProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package io.quarkus.reactive.oracle.client; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import jakarta.enterprise.context.ApplicationScoped; | ||
|
||
import org.jboss.logging.Logger; | ||
|
||
import io.quarkus.credentials.CredentialsProvider; | ||
|
||
@ApplicationScoped | ||
public class ChangingCredentialsProvider implements CredentialsProvider { | ||
|
||
private static final Logger log = Logger.getLogger(ChangingCredentialsProvider.class.getName()); | ||
|
||
private volatile Map<String, String> properties; | ||
|
||
public ChangingCredentialsProvider() { | ||
properties = new HashMap<>(); | ||
properties.put(USER_PROPERTY_NAME, "SYSTEM"); | ||
properties.put(PASSWORD_PROPERTY_NAME, "hibernate_orm_test"); | ||
} | ||
|
||
public void changeProperties() { | ||
properties = new HashMap<>(); | ||
properties.put(USER_PROPERTY_NAME, "user2"); | ||
properties.put(PASSWORD_PROPERTY_NAME, "user2"); | ||
} | ||
|
||
@Override | ||
public Map<String, String> getCredentials(String credentialsProviderName) { | ||
log.info("credentials provider returning " + properties); | ||
return properties; | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
...t/deployment/src/test/java/io/quarkus/reactive/oracle/client/ChangingCredentialsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package io.quarkus.reactive.oracle.client; | ||
|
||
import static io.restassured.RestAssured.given; | ||
import static java.util.concurrent.TimeUnit.SECONDS; | ||
|
||
import org.hamcrest.CoreMatchers; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
public class ChangingCredentialsTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest config = new QuarkusUnitTest() | ||
.withApplicationRoot((jar) -> jar | ||
.addClass(ChangingCredentialsProvider.class) | ||
.addClass(ChangingCredentialsTestResource.class) | ||
.addAsResource("application-changing-credentials.properties", "application.properties")); | ||
|
||
@Test | ||
public void testConnect() throws Exception { | ||
given() | ||
.when().get("/test") | ||
.then() | ||
.statusCode(200) | ||
.body(CoreMatchers.equalTo("SYSTEM")); | ||
|
||
SECONDS.sleep(2); // sleep longer than pool idle connection timeout | ||
|
||
given() | ||
.when().get("/test") | ||
.then() | ||
.statusCode(200) | ||
.body(CoreMatchers.equalTo("USER2")); | ||
} | ||
|
||
} |
41 changes: 41 additions & 0 deletions
41
...ment/src/test/java/io/quarkus/reactive/oracle/client/ChangingCredentialsTestResource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package io.quarkus.reactive.oracle.client; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import jakarta.annotation.PostConstruct; | ||
import jakarta.inject.Inject; | ||
import jakarta.ws.rs.GET; | ||
import jakarta.ws.rs.Path; | ||
import jakarta.ws.rs.Produces; | ||
import jakarta.ws.rs.core.MediaType; | ||
import jakarta.ws.rs.core.Response; | ||
|
||
import io.smallrye.mutiny.Uni; | ||
import io.vertx.mutiny.oracleclient.OraclePool; | ||
|
||
@Path("/test") | ||
public class ChangingCredentialsTestResource { | ||
|
||
@Inject | ||
OraclePool client; | ||
|
||
@Inject | ||
ChangingCredentialsProvider credentialsProvider; | ||
|
||
@PostConstruct | ||
void addUser() { | ||
client.query("CREATE USER user2 IDENTIFIED BY user2").executeAndForget(); | ||
client.query("GRANT CREATE SESSION TO user2").executeAndForget(); | ||
} | ||
|
||
@GET | ||
@Produces(MediaType.TEXT_PLAIN) | ||
public Uni<Response> connect() { | ||
return client.query("SELECT USER FROM DUAL").execute() | ||
.map(rowSet -> { | ||
assertEquals(1, rowSet.size()); | ||
return Response.ok(rowSet.iterator().next().getString(0)).build(); | ||
}).eventually(credentialsProvider::changeProperties); | ||
} | ||
|
||
} |
5 changes: 5 additions & 0 deletions
5
...e-oracle-client/deployment/src/test/resources/application-changing-credentials.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
quarkus.datasource.db-kind=oracle | ||
quarkus.datasource.credentials-provider=changing | ||
quarkus.datasource.reactive.url=${reactive-oracledb.url} | ||
quarkus.datasource.reactive.max-size=1 | ||
quarkus.datasource.reactive.idle-timeout=PT1S |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters