From 1383d3cccde1cf754df88276328aa1cdf5ce57a0 Mon Sep 17 00:00:00 2001 From: Julien Viet Date: Wed, 30 Jan 2019 23:30:39 +0100 Subject: [PATCH 1/9] Releasing 3.6.4-SNAPSHOT --- pom.xml | 4 ++-- vertx-mysql-postgresql-client-jasync/pom.xml | 2 +- vertx-mysql-postgresql-client-scala/pom.xml | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/pom.xml b/pom.xml index 7b8969d9..71fcddd7 100644 --- a/pom.xml +++ b/pom.xml @@ -10,12 +10,12 @@ 4.0.0 vertx-mysql-postgresql-client-parent - 3.6.3 + 3.6.4-SNAPSHOT Vert.x MySQL/PostgreSQL Client Parent - 3.6.3 + 3.6.4-SNAPSHOT true diff --git a/vertx-mysql-postgresql-client-jasync/pom.xml b/vertx-mysql-postgresql-client-jasync/pom.xml index 306bc683..d54669ed 100644 --- a/vertx-mysql-postgresql-client-jasync/pom.xml +++ b/vertx-mysql-postgresql-client-jasync/pom.xml @@ -4,7 +4,7 @@ io.vertx vertx-mysql-postgresql-client-parent ../ - 3.6.3 + 3.6.4-SNAPSHOT 4.0.0 diff --git a/vertx-mysql-postgresql-client-scala/pom.xml b/vertx-mysql-postgresql-client-scala/pom.xml index d507f98e..184dd49c 100644 --- a/vertx-mysql-postgresql-client-scala/pom.xml +++ b/vertx-mysql-postgresql-client-scala/pom.xml @@ -4,13 +4,13 @@ io.vertx vertx-mysql-postgresql-client-parent ../ - 3.6.3 + 3.6.4-SNAPSHOT 4.0.0 vertx-mysql-postgresql-client - 3.6.3 + 3.6.4-SNAPSHOT Vert.x MySQL/PostgreSQL Client based on Scala From 6dd73630d5062561aa323d2395b68821102be518 Mon Sep 17 00:00:00 2001 From: Ohad Shai Date: Thu, 7 Feb 2019 12:06:13 +0200 Subject: [PATCH 2/9] update docs for jasync (#141) --- .../src/main/asciidoc/index.adoc | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/vertx-mysql-postgresql-client-jasync/src/main/asciidoc/index.adoc b/vertx-mysql-postgresql-client-jasync/src/main/asciidoc/index.adoc index 130cc496..a92d3318 100644 --- a/vertx-mysql-postgresql-client-jasync/src/main/asciidoc/index.adoc +++ b/vertx-mysql-postgresql-client-jasync/src/main/asciidoc/index.adoc @@ -3,7 +3,7 @@ The Async MySQL / PostgreSQL Client is responsible for providing an interface for Vert.x applications that need to interact with a MySQL or PostgreSQL database. -It uses Mauricio Linhares https://github.com/mauricio/postgresql-async[async driver] to interact with the MySQL +It uses jasync-sql https://github.com/jasync-sql/jasync-sql[async driver] to interact with the MySQL or PostgreSQL databases in a non blocking way. == Using the MySQL and PostgreSQL client @@ -16,8 +16,8 @@ application. To use this client, you need to add the following jar to your `CLASSPATH`: * ${maven.artifactId} ${maven.version} (the client) -* scala-library 2.11.4 -* the postgress-async-2.11 and mysdql-async-2.11 from https://github.com/mauricio/postgresql-async +* kotlin-library 1.3.20 +* the postgress-async and mysdql-async from https://github.com/jasync-sql/jasync-sql * joda time All these jars are downloadable from Maven Central. @@ -32,7 +32,7 @@ If you are building a _Fat-jar_ using Maven or Gradle, just add the following de ---- io.vertx - vertx-mysql-postgresql-client + vertx-mysql-postgresql-client-jasync ${maven.version} ---- @@ -41,7 +41,7 @@ If you are building a _Fat-jar_ using Maven or Gradle, just add the following de [source,groovy,subs="+attributes"] ---- -compile 'io.vertx:vertx-mysql-postgresql-client:${maven.version}' +compile 'io.vertx:vertx-mysql-postgresql-client-jasync:${maven.version}' ---- === In an application using a vert.x distributions @@ -49,7 +49,7 @@ compile 'io.vertx:vertx-mysql-postgresql-client:${maven.version}' If you are using a vert.x distribution, add the jar files listed above to the `$VERTX_HOME/lib` directory. Alternatively, you can edit the `vertx-stack.json` file located in `$VERTX_HOME`, and set `"included": true` -for the `vertx-mysql-postgresql-client` dependency. Once done, launch: `vertx resolve --dir=lib --stack= +for the `vertx-mysql-postgresql-client-jasync` dependency. Once done, launch: `vertx resolve --dir=lib --stack= ./vertx-stack.json`. It downloads the client and its dependencies. == Creating a client From 73294fcfb7949446d83cd13e81db28be8d9d854c Mon Sep 17 00:00:00 2001 From: Andy Chen Date: Thu, 7 Mar 2019 23:45:50 -0800 Subject: [PATCH 3/9] upgrade jasync to 0.9.23 (#144) --- vertx-mysql-postgresql-client-jasync/pom.xml | 2 +- .../java/io/vertx/ext/asyncsql/impl/BaseSQLClient.java | 10 ++++++++-- .../asyncsql/impl/pool/MysqlAsyncConnectionPool.java | 6 +----- .../impl/pool/PostgresqlAsyncConnectionPool.java | 7 +------ 4 files changed, 11 insertions(+), 14 deletions(-) diff --git a/vertx-mysql-postgresql-client-jasync/pom.xml b/vertx-mysql-postgresql-client-jasync/pom.xml index d54669ed..6ac368a3 100644 --- a/vertx-mysql-postgresql-client-jasync/pom.xml +++ b/vertx-mysql-postgresql-client-jasync/pom.xml @@ -14,7 +14,7 @@ Vert.x MySQL/PostgreSQL Client based on jasync-sql/Kotlin - 0.8.62 + 0.9.23 false false diff --git a/vertx-mysql-postgresql-client-jasync/src/main/java/io/vertx/ext/asyncsql/impl/BaseSQLClient.java b/vertx-mysql-postgresql-client-jasync/src/main/java/io/vertx/ext/asyncsql/impl/BaseSQLClient.java index 72cece4d..85460977 100644 --- a/vertx-mysql-postgresql-client-jasync/src/main/java/io/vertx/ext/asyncsql/impl/BaseSQLClient.java +++ b/vertx-mysql-postgresql-client-jasync/src/main/java/io/vertx/ext/asyncsql/impl/BaseSQLClient.java @@ -31,6 +31,7 @@ import io.vertx.core.logging.LoggerFactory; import io.vertx.ext.asyncsql.impl.pool.AsyncConnectionPool; import io.vertx.ext.sql.SQLConnection; +import kotlinx.coroutines.Dispatchers; import java.nio.charset.Charset; import java.time.Duration; @@ -114,6 +115,7 @@ protected ConnectionPoolConfiguration getConnectionConfiguration( long testTimeout = config.getLong("testTimeout", defaultTestTimeout); Long queryTimeout = config.getLong("queryTimeout"); Map sslConfig = buildSslConfig(config); + String applicationName = config.getString("applicationName"); log.info("Creating configuration for " + host + ":" + port); return new ConnectionPoolConfiguration( @@ -122,7 +124,7 @@ protected ConnectionPoolConfiguration getConnectionConfiguration( database, username, password, - 0 /*maxActiveConnections, unused*/, + 1 /*maxActiveConnections, unused*/, 0 /*maxIdleTime, unused*/, 0 /*maxPendingQueries, unused*/, 0 /*connectionValidationInterval*/, @@ -131,8 +133,12 @@ protected ConnectionPoolConfiguration getConnectionConfiguration( queryTimeout, vertx.nettyEventLoopGroup(), vertx.nettyEventLoopGroup(), /*executor: in non-blocking world, we should only have one event loop group*/ + Dispatchers.getDefault(), new SSLConfiguration(sslConfig), - charset); + charset, + 16777216, + PooledByteBufAllocator.DEFAULT, + applicationName); } private Map buildSslConfig(JsonObject config) { diff --git a/vertx-mysql-postgresql-client-jasync/src/main/java/io/vertx/ext/asyncsql/impl/pool/MysqlAsyncConnectionPool.java b/vertx-mysql-postgresql-client-jasync/src/main/java/io/vertx/ext/asyncsql/impl/pool/MysqlAsyncConnectionPool.java index b47c0a15..f16d6f56 100644 --- a/vertx-mysql-postgresql-client-jasync/src/main/java/io/vertx/ext/asyncsql/impl/pool/MysqlAsyncConnectionPool.java +++ b/vertx-mysql-postgresql-client-jasync/src/main/java/io/vertx/ext/asyncsql/impl/pool/MysqlAsyncConnectionPool.java @@ -16,14 +16,12 @@ package io.vertx.ext.asyncsql.impl.pool; -import com.github.jasync.sql.db.Configuration; import com.github.jasync.sql.db.Connection; import com.github.jasync.sql.db.ConnectionPoolConfiguration; import com.github.jasync.sql.db.mysql.MySQLConnection; import com.github.jasync.sql.db.mysql.util.CharsetMapper; import io.vertx.core.Vertx; import io.vertx.core.json.JsonObject; -import io.vertx.ext.asyncsql.impl.ConversionUtils; /** * Implementation of the {@link AsyncConnectionPool} for MySQL. @@ -40,9 +38,7 @@ public MysqlAsyncConnectionPool(Vertx vertx, JsonObject globalConfig, Connection protected Connection create() { return new MySQLConnection( connectionConfig.getConnectionConfiguration(), - CharsetMapper.Companion.getInstance(), - vertx.nettyEventLoopGroup(), - vertx.nettyEventLoopGroup() + CharsetMapper.Companion.getInstance() ); } diff --git a/vertx-mysql-postgresql-client-jasync/src/main/java/io/vertx/ext/asyncsql/impl/pool/PostgresqlAsyncConnectionPool.java b/vertx-mysql-postgresql-client-jasync/src/main/java/io/vertx/ext/asyncsql/impl/pool/PostgresqlAsyncConnectionPool.java index a43712aa..807f1e2f 100644 --- a/vertx-mysql-postgresql-client-jasync/src/main/java/io/vertx/ext/asyncsql/impl/pool/PostgresqlAsyncConnectionPool.java +++ b/vertx-mysql-postgresql-client-jasync/src/main/java/io/vertx/ext/asyncsql/impl/pool/PostgresqlAsyncConnectionPool.java @@ -16,7 +16,6 @@ package io.vertx.ext.asyncsql.impl.pool; -import com.github.jasync.sql.db.Configuration; import com.github.jasync.sql.db.Connection; import com.github.jasync.sql.db.ConnectionPoolConfiguration; import com.github.jasync.sql.db.postgresql.PostgreSQLConnection; @@ -24,7 +23,6 @@ import com.github.jasync.sql.db.postgresql.column.PostgreSQLColumnEncoderRegistry; import io.vertx.core.Vertx; import io.vertx.core.json.JsonObject; -import io.vertx.ext.asyncsql.impl.ConversionUtils; /** * Implementation of the {@link AsyncConnectionPool} for PostGresSQL. @@ -42,10 +40,7 @@ protected Connection create() { return new PostgreSQLConnection( connectionConfig.getConnectionConfiguration(), PostgreSQLColumnEncoderRegistry.Companion.getInstance(), - PostgreSQLColumnDecoderRegistry.Companion.getInstance(), - vertx.nettyEventLoopGroup(), - vertx.nettyEventLoopGroup() - ); + PostgreSQLColumnDecoderRegistry.Companion.getInstance()); } } From cbdbf729ad327834211140112b7958807a449650 Mon Sep 17 00:00:00 2001 From: Iranna Patil Date: Fri, 8 Mar 2019 08:46:25 +0100 Subject: [PATCH 4/9] Adding maxWaitQueueSize for connection waiters, To avoid unlimited growth of waiters queue, which was causing un-expected response times and memory issues as queue grows. (#143) --- .../src/main/asciidoc/index.adoc | 4 +- .../ext/asyncsql/impl/BaseSQLClient.java | 8 -- .../asyncsql/impl/PostgreSQLClientImpl.java | 2 - .../impl/pool/AsyncConnectionPool.java | 21 +++- .../impl/tool/AsyncConnectionPoolTest.java | 101 ++++++++++++++++++ 5 files changed, 123 insertions(+), 13 deletions(-) diff --git a/vertx-mysql-postgresql-client-jasync/src/main/asciidoc/index.adoc b/vertx-mysql-postgresql-client-jasync/src/main/asciidoc/index.adoc index a92d3318..7cfa7b49 100644 --- a/vertx-mysql-postgresql-client-jasync/src/main/asciidoc/index.adoc +++ b/vertx-mysql-postgresql-client-jasync/src/main/asciidoc/index.adoc @@ -206,7 +206,8 @@ Both the PostgreSql and MySql clients take the same configuration: "maxConnectionRetries" : , "connectionRetryDelay" : , "sslMode" : <"disable"|"prefer"|"require"|"verify-ca"|"verify-full">, - "sslRootCert" : + "sslRootCert" : , + "maxWaitQueueSize" : } ---- @@ -237,3 +238,4 @@ Both the PostgreSql and MySql clients take the same configuration: that the server host name matches that in the certificate `sslRootCert` :: Path to SSL root certificate file. Is used if you want to verify privately issued certificate. Refer to https://github.com/mauricio/postgresql-async[postgresql-async] documentation for more details. +`maxWaitQueueSize`:: The maximum requests allowed in the wait queue for connection. Defaults to `-1` (unlimited). diff --git a/vertx-mysql-postgresql-client-jasync/src/main/java/io/vertx/ext/asyncsql/impl/BaseSQLClient.java b/vertx-mysql-postgresql-client-jasync/src/main/java/io/vertx/ext/asyncsql/impl/BaseSQLClient.java index 85460977..0a2a5314 100644 --- a/vertx-mysql-postgresql-client-jasync/src/main/java/io/vertx/ext/asyncsql/impl/BaseSQLClient.java +++ b/vertx-mysql-postgresql-client-jasync/src/main/java/io/vertx/ext/asyncsql/impl/BaseSQLClient.java @@ -16,12 +16,9 @@ package io.vertx.ext.asyncsql.impl; -import com.github.jasync.sql.db.Configuration; import com.github.jasync.sql.db.Connection; import com.github.jasync.sql.db.ConnectionPoolConfiguration; import com.github.jasync.sql.db.SSLConfiguration; -import com.github.jasync.sql.db.pool.PoolConfiguration; -import io.netty.buffer.PooledByteBufAllocator; import io.vertx.core.AsyncResult; import io.vertx.core.Future; import io.vertx.core.Handler; @@ -34,12 +31,8 @@ import kotlinx.coroutines.Dispatchers; import java.nio.charset.Charset; -import java.time.Duration; -import java.time.temporal.ChronoUnit; import java.util.HashMap; import java.util.Map; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.TimeUnit; /** * Base class for the SQL client. @@ -52,7 +45,6 @@ public abstract class BaseSQLClient { protected final Vertx vertx; protected final JsonObject globalConfig; - private long testTimeout; public BaseSQLClient(Vertx vertx, JsonObject globalConfig) { this.vertx = vertx; diff --git a/vertx-mysql-postgresql-client-jasync/src/main/java/io/vertx/ext/asyncsql/impl/PostgreSQLClientImpl.java b/vertx-mysql-postgresql-client-jasync/src/main/java/io/vertx/ext/asyncsql/impl/PostgreSQLClientImpl.java index 372036ef..076e992a 100644 --- a/vertx-mysql-postgresql-client-jasync/src/main/java/io/vertx/ext/asyncsql/impl/PostgreSQLClientImpl.java +++ b/vertx-mysql-postgresql-client-jasync/src/main/java/io/vertx/ext/asyncsql/impl/PostgreSQLClientImpl.java @@ -16,8 +16,6 @@ package io.vertx.ext.asyncsql.impl; -import java.util.concurrent.ExecutorService; - import com.github.jasync.sql.db.Connection; import io.vertx.core.Vertx; import io.vertx.core.json.JsonObject; diff --git a/vertx-mysql-postgresql-client-jasync/src/main/java/io/vertx/ext/asyncsql/impl/pool/AsyncConnectionPool.java b/vertx-mysql-postgresql-client-jasync/src/main/java/io/vertx/ext/asyncsql/impl/pool/AsyncConnectionPool.java index 627c3229..3e8da02b 100644 --- a/vertx-mysql-postgresql-client-jasync/src/main/java/io/vertx/ext/asyncsql/impl/pool/AsyncConnectionPool.java +++ b/vertx-mysql-postgresql-client-jasync/src/main/java/io/vertx/ext/asyncsql/impl/pool/AsyncConnectionPool.java @@ -22,6 +22,7 @@ import io.vertx.core.Future; import io.vertx.core.Handler; import io.vertx.core.Vertx; +import io.vertx.core.http.ConnectionPoolTooBusyException; import io.vertx.core.json.JsonObject; import io.vertx.core.logging.Logger; import io.vertx.core.logging.LoggerFactory; @@ -44,6 +45,7 @@ public abstract class AsyncConnectionPool { public static final int DEFAULT_MAX_CONNECTION_RETRIES = 0; // No connection retries by default public static final int DEFAULT_CONNECTION_RETRY_DELAY = 5_000; // 5 seconds between retries by default public static final int DEFAULT_CONNECTION_RELEASE_DELAY = 0; // never release idle connection by default + public static final int DEFAULT_MAX_WAIT_QUEUE_SIZE = -1; // unlimited queue size private static final Logger logger = LoggerFactory.getLogger(AsyncConnectionPool.class); @@ -51,6 +53,7 @@ public abstract class AsyncConnectionPool { private final int maxConnectionRetries; private final int connectionRetryDelay; private final int connectionReleaseDelay; + private final int maxQueueSize; protected final ConnectionPoolConfiguration connectionConfig; protected final Vertx vertx; @@ -58,7 +61,7 @@ public abstract class AsyncConnectionPool { private int poolSize = 0; private final Deque availableConnections = new ArrayDeque<>(); private final Deque>> waiters = new ArrayDeque<>(); - private final Map timers = new HashMap<>(); + private final Map timers = new HashMap<>(); public AsyncConnectionPool(Vertx vertx, JsonObject globalConfig, ConnectionPoolConfiguration connectionConfig) { this.vertx = vertx; @@ -66,6 +69,7 @@ public AsyncConnectionPool(Vertx vertx, JsonObject globalConfig, ConnectionPoolC this.maxConnectionRetries = globalConfig.getInteger("maxConnectionRetries", DEFAULT_MAX_CONNECTION_RETRIES); this.connectionRetryDelay = globalConfig.getInteger("connectionRetryDelay", DEFAULT_CONNECTION_RETRY_DELAY); this.connectionReleaseDelay = globalConfig.getInteger("connectionReleaseDelay", DEFAULT_CONNECTION_RELEASE_DELAY); + this.maxQueueSize = globalConfig.getInteger("maxWaitQueueSize", DEFAULT_MAX_WAIT_QUEUE_SIZE); this.connectionConfig = connectionConfig; } @@ -75,6 +79,10 @@ public synchronized int getPoolSize() { return poolSize; } + public synchronized int getQueueSize() { + return waiters.size(); + } + private synchronized void createConnection(Handler> handler) { poolSize += 1; createAndConnect(new Handler>() { @@ -128,7 +136,16 @@ private synchronized void createAndConnect(Handler> hand } private synchronized void waitForAvailableConnection(Handler> handler) { - waiters.add(handler); + if (canAddWaiter()) { + waiters.add(handler); + return; + } + + handler.handle(Future.failedFuture(new ConnectionPoolTooBusyException("Connection pool reached max wait queue size of " + maxQueueSize))); + } + + private synchronized boolean canAddWaiter() { + return maxQueueSize < 0 || waiters.size() < maxQueueSize; } private synchronized void createOrWaitForAvailableConnection(Handler> handler) { diff --git a/vertx-mysql-postgresql-client-jasync/src/test/java/io/vertx/ext/asyncsql/impl/tool/AsyncConnectionPoolTest.java b/vertx-mysql-postgresql-client-jasync/src/test/java/io/vertx/ext/asyncsql/impl/tool/AsyncConnectionPoolTest.java index 3aeeaae5..3b161834 100644 --- a/vertx-mysql-postgresql-client-jasync/src/test/java/io/vertx/ext/asyncsql/impl/tool/AsyncConnectionPoolTest.java +++ b/vertx-mysql-postgresql-client-jasync/src/test/java/io/vertx/ext/asyncsql/impl/tool/AsyncConnectionPoolTest.java @@ -232,6 +232,107 @@ public void testRetriesAndSuccess(TestContext context) { }); } + // Try to get 30 connections from connectionPool with 15-connection, should result in queueSize of 15 and once the connections are released/given-back to pool waiters should run and queueSize should become 0 + @Test + public void testQueueSize(TestContext context) throws InterruptedException { + final int TEST_LENGTH = 30; + final AsyncConnectionPool pool = new AsyncConnectionPoolMock( + new JsonObject() + .put("maxPoolSize", MAX_POOL_SIZE), + this::getGoodConnection); + final Queue connectionSet = new LinkedList<>(); + final CountDownLatch countDownLatch = new CountDownLatch(TEST_LENGTH); + + // Ask for 30 connections + for (int i = 0; i < TEST_LENGTH; i++) { + pool.take(result -> { + // We will decrease our CountDownLatch with each obtained connection + countDownLatch.countDown(); + context.assertTrue(result.succeeded()); + connectionSet.add(result.result()); + }); + } + // Wait up to 200 millisecond to obtain the 30 connections (it should not happen) + context.assertFalse(countDownLatch.await(200, TimeUnit.MILLISECONDS)); + final int expectedWaiterQueueSize = TEST_LENGTH - MAX_POOL_SIZE; + context.assertEquals(pool.getQueueSize(), expectedWaiterQueueSize); + context.assertEquals(pool.getPoolSize(), MAX_POOL_SIZE); + + // Now releasing/giving-back connection to the pool should reduce waiter queueSize to 0 + for (int i = 0; i < MAX_POOL_SIZE; i++) { + pool.giveBack(connectionSet.poll()); + } + + // Once the connections available then the waiters should get the connection and run + context.assertTrue(countDownLatch.await(1, TimeUnit.SECONDS)); + context.assertEquals(pool.getQueueSize(), 0); + context.assertEquals(pool.getPoolSize(), MAX_POOL_SIZE); + } + + // Max queue size exceed should fail(maxWaitQueueSize=1, maxPoolSize=1) + @Test + public void testMaxQueueSizeExceeds(TestContext context) throws InterruptedException { + final int TEST_LENGTH = 2; + final int MAX_POOL_SIZE = 1; + final int MAX_WAIT_QUEUE_SIZE = 1; + final AsyncConnectionPool pool = new AsyncConnectionPoolMock( + new JsonObject() + .put("maxPoolSize", MAX_POOL_SIZE) + .put("maxWaitQueueSize", MAX_WAIT_QUEUE_SIZE), + this::getGoodConnection); + + final CountDownLatch countDownLatch = new CountDownLatch(TEST_LENGTH); + + // Ask for 2 connections + for (int i = 0; i < TEST_LENGTH; i++) { + pool.take(result -> { + // We will decrease our CountDownLatch with each obtained connection + countDownLatch.countDown(); + context.assertTrue(result.succeeded()); + }); + } + // Wait up to 200 millisecond to obtain the 2 connections (it should not happen) + context.assertFalse(countDownLatch.await(200, TimeUnit.MILLISECONDS)); + context.assertEquals(pool.getPoolSize(), MAX_POOL_SIZE); + context.assertEquals(pool.getQueueSize(), MAX_WAIT_QUEUE_SIZE); + + // Now when user makes call for new connection request should fail with proper message + final Async waitForCompletion = context.async(); + final String expectedExceptionMessage = "Connection pool reached max wait queue size of " + MAX_WAIT_QUEUE_SIZE; + pool.take(result -> { + context.assertTrue(result.failed()); + context.assertEquals(result.cause().getMessage(), expectedExceptionMessage); + waitForCompletion.complete(); + }); + waitForCompletion.awaitSuccess(200); + } + + // will try to get 1000 connection, 985 should wait in the queue(maxPoolSize=15) + @Test + public void testNoMaxWaitQueueLimitByDefault(TestContext context) throws InterruptedException { + final int TEST_LENGTH = 1000; + final AsyncConnectionPool pool = new AsyncConnectionPoolMock( + new JsonObject() + .put("maxPoolSize", MAX_POOL_SIZE), + this::getGoodConnection); + final CountDownLatch countDownLatch = new CountDownLatch(TEST_LENGTH); + + // Ask for 1000 connections + for (int i = 0; i < TEST_LENGTH; i++) { + pool.take(result -> { + // We will decrease our CountDownLatch with each obtained connection + countDownLatch.countDown(); + context.assertTrue(result.succeeded()); + }); + } + // Wait up to 200 millisecond to obtain the 1000 connections (it should not happen) + context.assertFalse(countDownLatch.await(200, TimeUnit.MILLISECONDS)); + + // Only 15 connection will be provided and remaining should wait in waiters queue + final int expectedWaiterQueueSize = TEST_LENGTH - MAX_POOL_SIZE; + context.assertEquals(pool.getQueueSize(), expectedWaiterQueueSize); + } + private Connection getGoodConnection() { final Connection connection = Mockito.mock(Connection.class); Mockito.when(connection.connect()).thenAnswer(new Answer>(){ From 12a6e6f89478998a6075b34b7b0e8272dc2e6a14 Mon Sep 17 00:00:00 2001 From: Andy Chen Date: Tue, 26 Mar 2019 07:08:23 -0700 Subject: [PATCH 5/9] upgrade jasync to 0.9.24 which fixed two memory leaks (#146) --- vertx-mysql-postgresql-client-jasync/pom.xml | 2 +- .../src/main/java/io/vertx/ext/asyncsql/impl/BaseSQLClient.java | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/vertx-mysql-postgresql-client-jasync/pom.xml b/vertx-mysql-postgresql-client-jasync/pom.xml index 6ac368a3..ff572c79 100644 --- a/vertx-mysql-postgresql-client-jasync/pom.xml +++ b/vertx-mysql-postgresql-client-jasync/pom.xml @@ -14,7 +14,7 @@ Vert.x MySQL/PostgreSQL Client based on jasync-sql/Kotlin - 0.9.23 + 0.9.24 false false diff --git a/vertx-mysql-postgresql-client-jasync/src/main/java/io/vertx/ext/asyncsql/impl/BaseSQLClient.java b/vertx-mysql-postgresql-client-jasync/src/main/java/io/vertx/ext/asyncsql/impl/BaseSQLClient.java index 0a2a5314..b50e157e 100644 --- a/vertx-mysql-postgresql-client-jasync/src/main/java/io/vertx/ext/asyncsql/impl/BaseSQLClient.java +++ b/vertx-mysql-postgresql-client-jasync/src/main/java/io/vertx/ext/asyncsql/impl/BaseSQLClient.java @@ -19,6 +19,7 @@ import com.github.jasync.sql.db.Connection; import com.github.jasync.sql.db.ConnectionPoolConfiguration; import com.github.jasync.sql.db.SSLConfiguration; +import io.netty.buffer.PooledByteBufAllocator; import io.vertx.core.AsyncResult; import io.vertx.core.Future; import io.vertx.core.Handler; From ac3d35373bd813bdf6a8c61a194cf6b8465fd035 Mon Sep 17 00:00:00 2001 From: Andy Chen Date: Mon, 29 Apr 2019 23:00:41 -0700 Subject: [PATCH 6/9] upgrade jasync to 0.9.51 for a charset and collation fix (#154) --- vertx-mysql-postgresql-client-jasync/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vertx-mysql-postgresql-client-jasync/pom.xml b/vertx-mysql-postgresql-client-jasync/pom.xml index ff572c79..9d82e88a 100644 --- a/vertx-mysql-postgresql-client-jasync/pom.xml +++ b/vertx-mysql-postgresql-client-jasync/pom.xml @@ -14,7 +14,7 @@ Vert.x MySQL/PostgreSQL Client based on jasync-sql/Kotlin - 0.9.24 + 0.9.51 false false From f85cf15bc7e647d0b86c756c09415d03f9984348 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=A5=E5=B0=9A=E5=90=9B?= Date: Tue, 28 May 2019 03:37:55 +0800 Subject: [PATCH 7/9] Backported `Catch the exception thrown by the synchronization` to 3.6 (#152) * catch the exception thrown by the synchronization * add a test --- .../ext/asyncsql/impl/AsyncSQLClientImpl.java | 71 ++++++++++++++++++- .../ext/asyncsql/impl/ClientWrapper.java | 52 +++++++++++++- .../vertx/ext/asyncsql/MySQLClientTest.java | 13 ++++ 3 files changed, 132 insertions(+), 4 deletions(-) diff --git a/vertx-mysql-postgresql-client-jasync/src/main/java/io/vertx/ext/asyncsql/impl/AsyncSQLClientImpl.java b/vertx-mysql-postgresql-client-jasync/src/main/java/io/vertx/ext/asyncsql/impl/AsyncSQLClientImpl.java index 8bda55e1..6efe4e58 100644 --- a/vertx-mysql-postgresql-client-jasync/src/main/java/io/vertx/ext/asyncsql/impl/AsyncSQLClientImpl.java +++ b/vertx-mysql-postgresql-client-jasync/src/main/java/io/vertx/ext/asyncsql/impl/AsyncSQLClientImpl.java @@ -17,12 +17,15 @@ package io.vertx.ext.asyncsql.impl; import io.vertx.core.AsyncResult; +import io.vertx.core.Future; import io.vertx.core.Handler; import io.vertx.core.Vertx; +import io.vertx.core.json.JsonArray; import io.vertx.core.json.JsonObject; import io.vertx.ext.asyncsql.AsyncSQLClient; -import io.vertx.ext.sql.SQLClient; -import io.vertx.ext.sql.SQLConnection; +import io.vertx.ext.sql.*; + +import java.util.function.Function; /** * @author Joern Bernhardt. @@ -55,4 +58,68 @@ public SQLClient getConnection(Handler> handler) { return this; } + @Override + public SQLClient query(String sql, Handler> handler) { + executeDirect(conn -> Future.future(f -> conn.query(sql, f)), handler); + return this; + } + + @Override + public SQLClient queryStream(String sql, Handler> handler) { + executeDirect(conn -> Future.future(f -> conn.queryStream(sql, f)), handler); + return this; + } + + @Override + public SQLClient queryStreamWithParams(String sql, JsonArray params, Handler> handler) { + executeDirect(conn -> Future.future(f -> conn.queryStreamWithParams(sql, params, f)), handler); + return this; + } + + @Override + public SQLClient queryWithParams(String sql, JsonArray params, Handler> handler) { + executeDirect(conn -> Future.future(f -> conn.queryWithParams(sql, params, f)), handler); + return this; + } + + @Override + public SQLClient update(String sql, Handler> handler) { + executeDirect(conn -> Future.future(f -> conn.update(sql, f)), handler); + return this; + } + + @Override + public SQLClient updateWithParams(String sql, JsonArray params, Handler> handler) { + executeDirect(conn -> Future.future(f -> conn.updateWithParams(sql, params, f)), handler); + return this; + } + + @Override + public SQLClient call(String sql, Handler> handler) { + executeDirect(conn -> Future.future(f -> conn.call(sql, f)), handler); + return this; + } + + @Override + public SQLClient callWithParams(String sql, JsonArray params, JsonArray outputs, Handler> handler) { + executeDirect(conn -> Future.future(f -> conn.callWithParams(sql, params, outputs, f)), handler); + return this; + } + + private void executeDirect(Function> action, Handler> handler) { + getConnection(getConnection -> { + if (getConnection.failed()) { + handler.handle(Future.failedFuture(getConnection.cause())); + } else { + final SQLConnection conn = getConnection.result(); + Future future; + try { + future = action.apply(conn); + } catch (Throwable e) { + future = Future.failedFuture(e); + } + future.setHandler(handler); + } + }); + } } diff --git a/vertx-mysql-postgresql-client-jasync/src/main/java/io/vertx/ext/asyncsql/impl/ClientWrapper.java b/vertx-mysql-postgresql-client-jasync/src/main/java/io/vertx/ext/asyncsql/impl/ClientWrapper.java index 8e396c89..78553ece 100644 --- a/vertx-mysql-postgresql-client-jasync/src/main/java/io/vertx/ext/asyncsql/impl/ClientWrapper.java +++ b/vertx-mysql-postgresql-client-jasync/src/main/java/io/vertx/ext/asyncsql/impl/ClientWrapper.java @@ -18,9 +18,9 @@ import io.vertx.core.AsyncResult; import io.vertx.core.Handler; +import io.vertx.core.json.JsonArray; import io.vertx.ext.asyncsql.AsyncSQLClient; -import io.vertx.ext.sql.SQLClient; -import io.vertx.ext.sql.SQLConnection; +import io.vertx.ext.sql.*; /** * Wraps a client with the {@link ClientHolder} in order to keep track of the references. @@ -51,4 +51,52 @@ public void close() { public SQLClient getConnection(Handler> handler) { return client.getConnection(handler); } + + @Override + public SQLClient query(String sql, Handler> handler) { + client.query(sql, handler); + return this; + } + + @Override + public SQLClient queryStream(String sql, Handler> handler) { + client.queryStream(sql, handler); + return this; + } + + @Override + public SQLClient queryStreamWithParams(String sql, JsonArray params, Handler> handler) { + client.queryStreamWithParams(sql, params, handler); + return this; + } + + @Override + public SQLClient queryWithParams(String sql, JsonArray params, Handler> handler) { + client.queryWithParams(sql, params, handler); + return this; + } + + @Override + public SQLClient update(String sql, Handler> handler) { + client.update(sql, handler); + return this; + } + + @Override + public SQLClient updateWithParams(String sql, JsonArray params, Handler> handler) { + client.updateWithParams(sql, params, handler); + return this; + } + + @Override + public SQLClient call(String sql, Handler> handler) { + client.call(sql, handler); + return this; + } + + @Override + public SQLClient callWithParams(String sql, JsonArray params, JsonArray outputs, Handler> handler) { + client.callWithParams(sql, params, outputs, handler); + return this; + } } diff --git a/vertx-mysql-postgresql-client-jasync/src/test/java/io/vertx/ext/asyncsql/MySQLClientTest.java b/vertx-mysql-postgresql-client-jasync/src/test/java/io/vertx/ext/asyncsql/MySQLClientTest.java index 057944de..03c1438c 100644 --- a/vertx-mysql-postgresql-client-jasync/src/test/java/io/vertx/ext/asyncsql/MySQLClientTest.java +++ b/vertx-mysql-postgresql-client-jasync/src/test/java/io/vertx/ext/asyncsql/MySQLClientTest.java @@ -16,6 +16,7 @@ package io.vertx.ext.asyncsql; +import com.github.jasync.sql.db.exceptions.InsufficientParametersException; import io.vertx.ext.asyncsql.category.NeedsDocker; import org.junit.*; @@ -116,6 +117,18 @@ public void testInsertedIds(TestContext context) { }); } + @Test + public void test(TestContext context){ + JsonArray arr = new JsonArray().add(1).add(2); + Async async = context.async(); + // a exception will throw. @see https://github.com/jasync-sql/jasync-sql/blob/master/mysql-async/src/main/java/com/github/jasync/sql/db/mysql/MySQLConnection.kt#L288-L301 + client.queryWithParams("?", arr, r -> { + context.assertTrue(r.failed()); + context.assertTrue(r.cause() instanceof InsufficientParametersException); + async.complete(); + }); + } + @Override protected void compareInstantStrings(TestContext context, String result, String expected) { // mysql will perform some rounding since it does not have the precision to store the full TS From 3538bc2043acb58f87d916a05f6e46af12a016b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=A5=E5=B0=9A=E5=90=9B?= Date: Fri, 7 Jun 2019 22:09:55 +0800 Subject: [PATCH 8/9] Revert "Backported `Catch the exception thrown by the synchronization` to 3.6 (#152)" (#159) This reverts commit f85cf15bc7e647d0b86c756c09415d03f9984348. --- .../ext/asyncsql/impl/AsyncSQLClientImpl.java | 71 +------------------ .../ext/asyncsql/impl/ClientWrapper.java | 52 +------------- .../vertx/ext/asyncsql/MySQLClientTest.java | 13 ---- 3 files changed, 4 insertions(+), 132 deletions(-) diff --git a/vertx-mysql-postgresql-client-jasync/src/main/java/io/vertx/ext/asyncsql/impl/AsyncSQLClientImpl.java b/vertx-mysql-postgresql-client-jasync/src/main/java/io/vertx/ext/asyncsql/impl/AsyncSQLClientImpl.java index 6efe4e58..8bda55e1 100644 --- a/vertx-mysql-postgresql-client-jasync/src/main/java/io/vertx/ext/asyncsql/impl/AsyncSQLClientImpl.java +++ b/vertx-mysql-postgresql-client-jasync/src/main/java/io/vertx/ext/asyncsql/impl/AsyncSQLClientImpl.java @@ -17,15 +17,12 @@ package io.vertx.ext.asyncsql.impl; import io.vertx.core.AsyncResult; -import io.vertx.core.Future; import io.vertx.core.Handler; import io.vertx.core.Vertx; -import io.vertx.core.json.JsonArray; import io.vertx.core.json.JsonObject; import io.vertx.ext.asyncsql.AsyncSQLClient; -import io.vertx.ext.sql.*; - -import java.util.function.Function; +import io.vertx.ext.sql.SQLClient; +import io.vertx.ext.sql.SQLConnection; /** * @author Joern Bernhardt. @@ -58,68 +55,4 @@ public SQLClient getConnection(Handler> handler) { return this; } - @Override - public SQLClient query(String sql, Handler> handler) { - executeDirect(conn -> Future.future(f -> conn.query(sql, f)), handler); - return this; - } - - @Override - public SQLClient queryStream(String sql, Handler> handler) { - executeDirect(conn -> Future.future(f -> conn.queryStream(sql, f)), handler); - return this; - } - - @Override - public SQLClient queryStreamWithParams(String sql, JsonArray params, Handler> handler) { - executeDirect(conn -> Future.future(f -> conn.queryStreamWithParams(sql, params, f)), handler); - return this; - } - - @Override - public SQLClient queryWithParams(String sql, JsonArray params, Handler> handler) { - executeDirect(conn -> Future.future(f -> conn.queryWithParams(sql, params, f)), handler); - return this; - } - - @Override - public SQLClient update(String sql, Handler> handler) { - executeDirect(conn -> Future.future(f -> conn.update(sql, f)), handler); - return this; - } - - @Override - public SQLClient updateWithParams(String sql, JsonArray params, Handler> handler) { - executeDirect(conn -> Future.future(f -> conn.updateWithParams(sql, params, f)), handler); - return this; - } - - @Override - public SQLClient call(String sql, Handler> handler) { - executeDirect(conn -> Future.future(f -> conn.call(sql, f)), handler); - return this; - } - - @Override - public SQLClient callWithParams(String sql, JsonArray params, JsonArray outputs, Handler> handler) { - executeDirect(conn -> Future.future(f -> conn.callWithParams(sql, params, outputs, f)), handler); - return this; - } - - private void executeDirect(Function> action, Handler> handler) { - getConnection(getConnection -> { - if (getConnection.failed()) { - handler.handle(Future.failedFuture(getConnection.cause())); - } else { - final SQLConnection conn = getConnection.result(); - Future future; - try { - future = action.apply(conn); - } catch (Throwable e) { - future = Future.failedFuture(e); - } - future.setHandler(handler); - } - }); - } } diff --git a/vertx-mysql-postgresql-client-jasync/src/main/java/io/vertx/ext/asyncsql/impl/ClientWrapper.java b/vertx-mysql-postgresql-client-jasync/src/main/java/io/vertx/ext/asyncsql/impl/ClientWrapper.java index 78553ece..8e396c89 100644 --- a/vertx-mysql-postgresql-client-jasync/src/main/java/io/vertx/ext/asyncsql/impl/ClientWrapper.java +++ b/vertx-mysql-postgresql-client-jasync/src/main/java/io/vertx/ext/asyncsql/impl/ClientWrapper.java @@ -18,9 +18,9 @@ import io.vertx.core.AsyncResult; import io.vertx.core.Handler; -import io.vertx.core.json.JsonArray; import io.vertx.ext.asyncsql.AsyncSQLClient; -import io.vertx.ext.sql.*; +import io.vertx.ext.sql.SQLClient; +import io.vertx.ext.sql.SQLConnection; /** * Wraps a client with the {@link ClientHolder} in order to keep track of the references. @@ -51,52 +51,4 @@ public void close() { public SQLClient getConnection(Handler> handler) { return client.getConnection(handler); } - - @Override - public SQLClient query(String sql, Handler> handler) { - client.query(sql, handler); - return this; - } - - @Override - public SQLClient queryStream(String sql, Handler> handler) { - client.queryStream(sql, handler); - return this; - } - - @Override - public SQLClient queryStreamWithParams(String sql, JsonArray params, Handler> handler) { - client.queryStreamWithParams(sql, params, handler); - return this; - } - - @Override - public SQLClient queryWithParams(String sql, JsonArray params, Handler> handler) { - client.queryWithParams(sql, params, handler); - return this; - } - - @Override - public SQLClient update(String sql, Handler> handler) { - client.update(sql, handler); - return this; - } - - @Override - public SQLClient updateWithParams(String sql, JsonArray params, Handler> handler) { - client.updateWithParams(sql, params, handler); - return this; - } - - @Override - public SQLClient call(String sql, Handler> handler) { - client.call(sql, handler); - return this; - } - - @Override - public SQLClient callWithParams(String sql, JsonArray params, JsonArray outputs, Handler> handler) { - client.callWithParams(sql, params, outputs, handler); - return this; - } } diff --git a/vertx-mysql-postgresql-client-jasync/src/test/java/io/vertx/ext/asyncsql/MySQLClientTest.java b/vertx-mysql-postgresql-client-jasync/src/test/java/io/vertx/ext/asyncsql/MySQLClientTest.java index 03c1438c..057944de 100644 --- a/vertx-mysql-postgresql-client-jasync/src/test/java/io/vertx/ext/asyncsql/MySQLClientTest.java +++ b/vertx-mysql-postgresql-client-jasync/src/test/java/io/vertx/ext/asyncsql/MySQLClientTest.java @@ -16,7 +16,6 @@ package io.vertx.ext.asyncsql; -import com.github.jasync.sql.db.exceptions.InsufficientParametersException; import io.vertx.ext.asyncsql.category.NeedsDocker; import org.junit.*; @@ -117,18 +116,6 @@ public void testInsertedIds(TestContext context) { }); } - @Test - public void test(TestContext context){ - JsonArray arr = new JsonArray().add(1).add(2); - Async async = context.async(); - // a exception will throw. @see https://github.com/jasync-sql/jasync-sql/blob/master/mysql-async/src/main/java/com/github/jasync/sql/db/mysql/MySQLConnection.kt#L288-L301 - client.queryWithParams("?", arr, r -> { - context.assertTrue(r.failed()); - context.assertTrue(r.cause() instanceof InsufficientParametersException); - async.complete(); - }); - } - @Override protected void compareInstantStrings(TestContext context, String result, String expected) { // mysql will perform some rounding since it does not have the precision to store the full TS From 19b71fed1f26c57de71d2ca6b47623c8ebc895dd Mon Sep 17 00:00:00 2001 From: Francesco Guardiani Date: Wed, 12 Jun 2019 17:59:55 +0200 Subject: [PATCH 9/9] Update .travis.yml --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 76838857..c4cfdbfe 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,8 +8,8 @@ services: jobs: include: - stage: test - name: "OracleJDK 8" - jdk: oraclejdk8 + name: "OpenJDK 8" + jdk: openjdk8 script: mvn -q clean verify -B && mvn -P testNativeTransport -q clean verify -B # - if: type != pull_request # name: "OpenJDK 11"