-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "Revert "Reactive sql client pool in thread local""
This reverts commit 04663a7.
- Loading branch information
Showing
12 changed files
with
247 additions
and
0 deletions.
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
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
22 changes: 22 additions & 0 deletions
22
...ient/runtime/src/main/java/io/quarkus/reactive/db2/client/runtime/ThreadLocalDB2Pool.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,22 @@ | ||
package io.quarkus.reactive.db2.client.runtime; | ||
|
||
import io.quarkus.reactive.datasource.runtime.ThreadLocalPool; | ||
import io.vertx.core.Vertx; | ||
import io.vertx.db2client.DB2ConnectOptions; | ||
import io.vertx.db2client.DB2Pool; | ||
import io.vertx.sqlclient.PoolOptions; | ||
|
||
public class ThreadLocalDB2Pool extends ThreadLocalPool<DB2Pool> implements DB2Pool { | ||
|
||
private final DB2ConnectOptions db2ConnectOptions; | ||
|
||
public ThreadLocalDB2Pool(Vertx vertx, DB2ConnectOptions db2ConnectOptions, PoolOptions poolOptions) { | ||
super(vertx, poolOptions); | ||
this.db2ConnectOptions = db2ConnectOptions; | ||
} | ||
|
||
@Override | ||
protected DB2Pool createThreadLocalPool() { | ||
return DB2Pool.pool(vertx, db2ConnectOptions, poolOptions); | ||
} | ||
} |
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
22 changes: 22 additions & 0 deletions
22
.../runtime/src/main/java/io/quarkus/reactive/mysql/client/runtime/ThreadLocalMySQLPool.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,22 @@ | ||
package io.quarkus.reactive.mysql.client.runtime; | ||
|
||
import io.quarkus.reactive.datasource.runtime.ThreadLocalPool; | ||
import io.vertx.core.Vertx; | ||
import io.vertx.mysqlclient.MySQLConnectOptions; | ||
import io.vertx.mysqlclient.MySQLPool; | ||
import io.vertx.sqlclient.PoolOptions; | ||
|
||
public class ThreadLocalMySQLPool extends ThreadLocalPool<MySQLPool> implements MySQLPool { | ||
|
||
private final MySQLConnectOptions mySQLConnectOptions; | ||
|
||
public ThreadLocalMySQLPool(Vertx vertx, MySQLConnectOptions mySQLConnectOptions, PoolOptions poolOptions) { | ||
super(vertx, poolOptions); | ||
this.mySQLConnectOptions = mySQLConnectOptions; | ||
} | ||
|
||
@Override | ||
protected MySQLPool createThreadLocalPool() { | ||
return MySQLPool.pool(vertx, mySQLConnectOptions, poolOptions); | ||
} | ||
} |
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
22 changes: 22 additions & 0 deletions
22
...client/runtime/src/main/java/io/quarkus/reactive/pg/client/runtime/ThreadLocalPgPool.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,22 @@ | ||
package io.quarkus.reactive.pg.client.runtime; | ||
|
||
import io.quarkus.reactive.datasource.runtime.ThreadLocalPool; | ||
import io.vertx.core.Vertx; | ||
import io.vertx.pgclient.PgConnectOptions; | ||
import io.vertx.pgclient.PgPool; | ||
import io.vertx.sqlclient.PoolOptions; | ||
|
||
public class ThreadLocalPgPool extends ThreadLocalPool<PgPool> implements PgPool { | ||
|
||
private final PgConnectOptions pgConnectOptions; | ||
|
||
public ThreadLocalPgPool(Vertx vertx, PgConnectOptions pgConnectOptions, PoolOptions poolOptions) { | ||
super(vertx, poolOptions); | ||
this.pgConnectOptions = pgConnectOptions; | ||
} | ||
|
||
@Override | ||
protected PgPool createThreadLocalPool() { | ||
return PgPool.pool(vertx, pgConnectOptions, poolOptions); | ||
} | ||
} |
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
53 changes: 53 additions & 0 deletions
53
...tive-pg-client/src/test/java/io/quarkus/it/reactive/pg/client/HotReloadFruitResource.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,53 @@ | ||
package io.quarkus.it.reactive.pg.client; | ||
|
||
import java.util.concurrent.CompletionStage; | ||
|
||
import javax.annotation.PostConstruct; | ||
import javax.inject.Inject; | ||
import javax.ws.rs.GET; | ||
import javax.ws.rs.Path; | ||
import javax.ws.rs.Produces; | ||
import javax.ws.rs.core.MediaType; | ||
|
||
import io.vertx.core.json.JsonArray; | ||
import io.vertx.core.json.JsonObject; | ||
import io.vertx.mutiny.pgclient.PgPool; | ||
import io.vertx.mutiny.sqlclient.Row; | ||
|
||
@Path("/hot-fruits") | ||
public class HotReloadFruitResource { | ||
|
||
@Inject | ||
PgPool client; | ||
|
||
@PostConstruct | ||
void setupDb() { | ||
client.query("DROP TABLE IF EXISTS fruits").execute() | ||
.flatMap(r -> client.query("CREATE TABLE fruits (id SERIAL PRIMARY KEY, name TEXT NOT NULL)").execute()) | ||
.flatMap(r -> client.query("INSERT INTO fruits (name) VALUES ('Orange')").execute()) | ||
.flatMap(r -> client.query("INSERT INTO fruits (name) VALUES ('Pear')").execute()) | ||
.flatMap(r -> client.query("INSERT INTO fruits (name) VALUES ('Apple')").execute()) | ||
.await().indefinitely(); | ||
} | ||
|
||
@GET | ||
@Produces(MediaType.APPLICATION_JSON) | ||
public CompletionStage<JsonArray> listFruits() { | ||
return client.query("SELECT * FROM fruits").execute() | ||
.map(pgRowSet -> { | ||
JsonArray jsonArray = new JsonArray(); | ||
for (Row row : pgRowSet) { | ||
jsonArray.add(toJson(row)); | ||
} | ||
return jsonArray; | ||
}) | ||
.subscribeAsCompletionStage(); | ||
} | ||
|
||
private JsonObject toJson(Row row) { | ||
return new JsonObject() | ||
.put("id", row.getLong("id")) | ||
.put("name", row.getString("name")); | ||
} | ||
|
||
} |
75 changes: 75 additions & 0 deletions
75
.../reactive-pg-client/src/test/java/io/quarkus/it/reactive/pg/client/HotReloadTestCase.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,75 @@ | ||
package io.quarkus.it.reactive.pg.client; | ||
|
||
import static io.restassured.RestAssured.given; | ||
import static org.hamcrest.CoreMatchers.containsString; | ||
|
||
import java.util.List; | ||
import java.util.function.Function; | ||
import java.util.logging.LogRecord; | ||
|
||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
import org.junit.jupiter.api.AfterAll; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.test.QuarkusDevModeTest; | ||
|
||
public class HotReloadTestCase { | ||
@RegisterExtension | ||
final static QuarkusDevModeTest TEST = new QuarkusDevModeTest() | ||
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class) | ||
.addClasses(HotReloadFruitResource.class) | ||
.addAsResource("application-tl.properties", "application.properties")) | ||
.setLogRecordPredicate(record -> { | ||
return record.getLoggerName().startsWith("io.quarkus.reactive.datasource"); | ||
}); | ||
|
||
@AfterAll | ||
public static void afterAll() { | ||
List<LogRecord> records = TEST.getLogRecords(); | ||
Assertions.assertEquals(8, records.size()); | ||
// make sure that we closed all thread-local pools on reload and close | ||
Assertions.assertEquals("Making pool for thread: %s", records.get(0).getMessage()); | ||
Assertions.assertEquals("Making pool for thread: %s", records.get(1).getMessage()); | ||
Assertions.assertEquals("Closing pool: %s", records.get(2).getMessage()); | ||
Assertions.assertEquals("Closing pool: %s", records.get(3).getMessage()); | ||
Assertions.assertEquals("Making pool for thread: %s", records.get(4).getMessage()); | ||
Assertions.assertEquals("Making pool for thread: %s", records.get(5).getMessage()); | ||
Assertions.assertEquals("Closing pool: %s", records.get(6).getMessage()); | ||
Assertions.assertEquals("Closing pool: %s", records.get(7).getMessage()); | ||
} | ||
|
||
@Test | ||
public void testAddNewFieldToEntity() { | ||
checkRequest("Orange"); | ||
TEST.modifySourceFile(HotReloadFruitResource.class, new Function<String, String>() { | ||
@Override | ||
public String apply(String s) { | ||
return s.replace("'Orange'", "'Strawberry'"); | ||
} | ||
}); | ||
// trigger a pool hot reload by changing the config | ||
TEST.modifyResourceFile("application.properties", new Function<String, String>() { | ||
@Override | ||
public String apply(String s) { | ||
return s.replace("quarkus.datasource.reactive.thread-local=true", | ||
"quarkus.datasource.reactive.thread-local = true"); | ||
} | ||
}); | ||
|
||
checkRequest("Strawberry"); | ||
} | ||
|
||
private void checkRequest(String fruit) { | ||
given() | ||
.when().get("/hot-fruits") | ||
.then() | ||
.statusCode(200) | ||
.body( | ||
containsString(fruit), | ||
containsString("Pear"), | ||
containsString("Apple")); | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
integration-tests/reactive-pg-client/src/test/resources/application-tl.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,6 @@ | ||
quarkus.datasource.db-kind=postgresql | ||
quarkus.datasource.username=hibernate_orm_test | ||
quarkus.datasource.password=hibernate_orm_test | ||
quarkus.datasource.reactive.url=${reactive-postgres.url} | ||
quarkus.datasource.reactive.thread-local=true | ||
quarkus.log.category."io.quarkus.reactive.datasource".level=DEBUG |
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