forked from quarkusio/quarkus
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Provide a way for users to customize PgPool creation
Resolves: quarkusio#29348
- Loading branch information
Showing
7 changed files
with
208 additions
and
1 deletion.
There are no files selected for viewing
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
14 changes: 14 additions & 0 deletions
14
...client/deployment/src/test/java/io/quarkus/reactive/pg/client/LocalhostPgPoolCreator.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,14 @@ | ||
package io.quarkus.reactive.pg.client; | ||
|
||
import javax.inject.Singleton; | ||
|
||
import io.vertx.pgclient.PgPool; | ||
|
||
@Singleton | ||
public class LocalhostPgPoolCreator implements PgPoolCreator { | ||
|
||
@Override | ||
public PgPool create(Input input) { | ||
return PgPool.pool(input.vertx(), input.pgConnectOptions().setHost("localhost").setPort(5431), input.poolOptions()); | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
...nt/deployment/src/test/java/io/quarkus/reactive/pg/client/MultiplePgPoolCreatorsTest.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,40 @@ | ||
package io.quarkus.reactive.pg.client; | ||
|
||
import static org.junit.jupiter.api.Assertions.fail; | ||
|
||
import javax.enterprise.inject.spi.DeploymentException; | ||
import javax.inject.Singleton; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.test.QuarkusUnitTest; | ||
import io.vertx.pgclient.PgPool; | ||
|
||
public class MultiplePgPoolCreatorsTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest config = new QuarkusUnitTest() | ||
.withApplicationRoot((jar) -> jar | ||
.addClass(CustomCredentialsProvider.class) | ||
.addClass(CredentialsTestResource.class) | ||
.addClass(LocalhostPgPoolCreator.class) | ||
.addClass(AnotherPgPoolCreator.class) | ||
.addAsResource("application-credentials-with-erroneous-url.properties", "application.properties")) | ||
.setExpectedException(DeploymentException.class); | ||
|
||
@Test | ||
public void test() { | ||
fail("Should never have been called"); | ||
} | ||
|
||
@Singleton | ||
public static class AnotherPgPoolCreator implements PgPoolCreator { | ||
|
||
@Override | ||
public PgPool create(Input input) { | ||
return PgPool.pool(input.vertx(), input.pgConnectOptions(), input.poolOptions()); | ||
} | ||
} | ||
|
||
} |
30 changes: 30 additions & 0 deletions
30
...e-pg-client/deployment/src/test/java/io/quarkus/reactive/pg/client/PgPoolCreatorTest.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,30 @@ | ||
package io.quarkus.reactive.pg.client; | ||
|
||
import static io.restassured.RestAssured.given; | ||
|
||
import org.hamcrest.CoreMatchers; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
public class PgPoolCreatorTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest config = new QuarkusUnitTest() | ||
.withApplicationRoot((jar) -> jar | ||
.addClass(CustomCredentialsProvider.class) | ||
.addClass(CredentialsTestResource.class) | ||
.addClass(LocalhostPgPoolCreator.class) | ||
.addAsResource("application-credentials-with-erroneous-url.properties", "application.properties")); | ||
|
||
@Test | ||
public void testConnect() { | ||
given() | ||
.when().get("/test") | ||
.then() | ||
.statusCode(200) | ||
.body(CoreMatchers.equalTo("OK")); | ||
} | ||
|
||
} |
3 changes: 3 additions & 0 deletions
3
...lient/deployment/src/test/resources/application-credentials-with-erroneous-url.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,3 @@ | ||
quarkus.datasource.db-kind=postgresql | ||
quarkus.datasource.credentials-provider=custom | ||
quarkus.datasource.reactive.url=vertx-reactive:postgresql://test:12345/hibernate_orm_test |
34 changes: 34 additions & 0 deletions
34
...reactive-pg-client/runtime/src/main/java/io/quarkus/reactive/pg/client/PgPoolCreator.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,34 @@ | ||
package io.quarkus.reactive.pg.client; | ||
|
||
import io.vertx.core.Vertx; | ||
import io.vertx.pgclient.PgConnectOptions; | ||
import io.vertx.pgclient.PgPool; | ||
import io.vertx.sqlclient.PoolOptions; | ||
|
||
/** | ||
* This interface is an integration point that allows users to use {@link Vertx}, {@link PoolOptions} and | ||
* {@link PgConnectOptions} | ||
* configured automatically by Quarkus, but provide on a custom strategy for creating the final {@link PgPool}, instead of | ||
* letting Quarkus create it (by calling {@link PgPool#pool(Vertx, PgConnectOptions, PoolOptions)}). | ||
* | ||
* Implementations of this class are meant to be used as CDI beans - if a single implementation marked as a CDI bean, | ||
* it will be picked up by Quarkus and used to create the pool. | ||
*/ | ||
public interface PgPoolCreator { | ||
|
||
PgPool create(Input input); | ||
|
||
interface Input { | ||
|
||
Vertx vertx(); | ||
|
||
PoolOptions poolOptions(); | ||
|
||
PgConnectOptions pgConnectOptions(); | ||
|
||
/** | ||
* The datasource name for which the pool is being created | ||
*/ | ||
String dataSourceName(); | ||
} | ||
} |
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