Skip to content

Commit 2832bf6

Browse files
authored
Metrics vertx_pool_queue_pending doesn't decrease after connection loss (#1529)
* Metrics vertx_pool_queue_pending doesn't decrease after connection loss See #1494 SqlConnectionPool must invoke dequeueMetric when a connection fails to be acquired Signed-off-by: Thomas Segismont <[email protected]> * Ignore OracleMetricsTest#testConnectionLost Fails on Oracle 2025-06-18T08:12:53.8427877Z [ERROR] tests.oracleclient.tck.OracleMetricsTest.testConnectionLost -- Time elapsed: 20.07 s <<< ERROR! 2025-06-18T08:12:53.8428800Z java.util.concurrent.TimeoutException: Timed out 2025-06-18T08:12:53.8429660Z at [email protected]/io.vertx.ext.unit.impl.CompletionImpl.await(CompletionImpl.java:73) 2025-06-18T08:12:53.8431163Z at io.vertx.tests.sql.client/io.vertx.tests.sqlclient.tck.MetricsTestBase.testConnectionLost(MetricsTestBase.java:232) 2025-06-18T08:12:53.8432547Z at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103) 2025-06-18T08:12:53.8433884Z at java.base/java.lang.reflect.Method.invoke(Method.java:580) 2025-06-18T08:12:53.8434931Z at [email protected]/io.vertx.ext.unit.junit.VertxUnitRunner.invokeTestMethod(VertxUnitRunner.java:95) 2025-06-18T08:12:53.8436414Z at [email protected]/io.vertx.ext.unit.junit.VertxUnitRunner.lambda$invokeExplosively$0(VertxUnitRunner.java:114) 2025-06-18T08:12:53.8437841Z at [email protected]/io.vertx.ext.unit.impl.TestContextImpl.run(TestContextImpl.java:90) 2025-06-18T08:12:53.8439166Z at [email protected]/io.vertx.ext.unit.junit.VertxUnitRunner.invokeExplosively(VertxUnitRunner.java:130) 2025-06-18T08:12:53.8440505Z at [email protected]/io.vertx.ext.unit.junit.VertxUnitRunner$1.evaluate(VertxUnitRunner.java:84) 2025-06-18T08:12:53.8444504Z at [email protected]/io.vertx.ext.unit.junit.VertxUnitRunner$2.evaluate(VertxUnitRunner.java:196) 2025-06-18T08:12:53.8446923Z at [email protected]/io.vertx.ext.unit.junit.VertxUnitRunner$3.evaluate(VertxUnitRunner.java:211) 2025-06-18T08:12:53.8448011Z at [email protected]/org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306) 2025-06-18T08:12:53.8449021Z at [email protected]/org.junit.runners.BlockJUnit4ClassRunner$1.evaluate(BlockJUnit4ClassRunner.java:100) 2025-06-18T08:12:53.8449969Z at [email protected]/org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:366) 2025-06-18T08:12:53.8451715Z at [email protected]/org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:103) 2025-06-18T08:12:53.8453107Z at [email protected]/org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:63) 2025-06-18T08:12:53.8453868Z at [email protected]/org.junit.runners.ParentRunner$4.run(ParentRunner.java:331) 2025-06-18T08:12:53.8454674Z at [email protected]/org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79) 2025-06-18T08:12:53.8455502Z at [email protected]/org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329) 2025-06-18T08:12:53.8456341Z at [email protected]/org.junit.runners.ParentRunner.access$100(ParentRunner.java:66) 2025-06-18T08:12:53.8457153Z at [email protected]/org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293) 2025-06-18T08:12:53.8457997Z at [email protected]/org.junit.rules.ExternalResource$1.evaluate(ExternalResource.java:54) 2025-06-18T08:12:53.8458761Z at [email protected]/org.junit.rules.RunRules.evaluate(RunRules.java:20) 2025-06-18T08:12:53.8459749Z at [email protected]/org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306) 2025-06-18T08:12:53.8460722Z at [email protected]/org.junit.runners.ParentRunner.run(ParentRunner.java:413) 2025-06-18T08:12:53.8461598Z at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:316) 2025-06-18T08:12:53.8462621Z at org.apache.maven.surefire.junit4.JUnit4Provider.executeWithRerun(JUnit4Provider.java:240) 2025-06-18T08:12:53.8463694Z at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:214) 2025-06-18T08:12:53.8464613Z at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:155) 2025-06-18T08:12:53.8465193Z at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:385) 2025-06-18T08:12:53.8465752Z at org.apache.maven.surefire.booter.ForkedBooter.execute(ForkedBooter.java:162) 2025-06-18T08:12:53.8466255Z at org.apache.maven.surefire.booter.ForkedBooter.run(ForkedBooter.java:507) 2025-06-18T08:12:53.8466754Z at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:495) 2025-06-18T08:12:53.8467047Z 2025-06-18T08:13:13.5057371Z Jun 18, 2025 8:13:13 AM oracle.jdbc.driver.PhysicalConnection connect 2025-06-18T08:13:13.5065518Z INFO: entering args (oracle.jdbc.datasource.impl.OracleDataSource$1@6a8b05c5) 2025-06-18T08:13:13.5067705Z Jun 18, 2025 8:13:13 AM oracle.net.ns.NSProtocol connect 2025-06-18T08:13:13.5068225Z INFO: traceId=1E1826C1. 2025-06-18T08:13:13.5068725Z Jun 18, 2025 8:13:13 AM oracle.net.ns.NSProtocol establishConnection 2025-06-18T08:13:13.5069809Z INFO: Session Attributes: 2025-06-18T08:13:13.5070161Z sdu=8192, tdu=2097152 2025-06-18T08:13:13.5071040Z nt: host=localhost, port=32769, socketOptions={0=YES, 1=NO, 17=0, 18=false, 2=0, 20=true, 38=TLS, 23=40, 24=50, 40=false, 25=0} 2025-06-18T08:13:13.5071793Z socket=null 2025-06-18T08:13:13.5073880Z client profile={oracle.net.encryption_types_client=(), oracle.net.crypto_seed=, oracle.net.authentication_services=(), oracle.net.setFIPSMode=false, oracle.net.kerberos5_mutual_authentication=false, oracle.net.encryption_client=ACCEPTED, oracle.net.crypto_checksum_client=ACCEPTED, oracle.net.crypto_checksum_types_client=()} 2025-06-18T08:13:13.5076223Z onBreakReset=false, dataEOF=false, negotiatedOptions=0x0, connected=false 2025-06-18T08:13:13.5076905Z TTIINIT enabled=false, TTC cookie enabled=false 2025-06-18T08:13:13.5077253Z 2025-06-18T08:13:13.5077540Z Jun 18, 2025 8:13:13 AM oracle.net.ns.NSProtocol configureSessionAttsAno 2025-06-18T08:13:13.5078150Z INFO: traceId=1E1826C1, anoEnabled=true. 2025-06-18T08:13:13.5078754Z Jun 18, 2025 8:13:13 AM oracle.net.ns.NSProtocolNIO handleConnectPacketResponse 2025-06-18T08:13:13.5079401Z INFO: Got Refused, SessionTraceId = 1E1826C1 2025-06-18T08:13:13.5080067Z Jun 18, 2025 8:13:13 AM oracle.net.ns.NSProtocolNIO establishConnectionAfterRefusePacket 2025-06-18T08:13:13.5081022Z INFO: Outbound interrupt timer cancelled null 2025-06-18T08:13:13.5081604Z Jun 18, 2025 8:13:13 AM oracle.net.ns.NSProtocol establishConnection 2025-06-18T08:13:13.5082150Z INFO: Session Attributes: 2025-06-18T08:13:13.5082504Z sdu=8192, tdu=2097152 2025-06-18T08:13:13.5083213Z nt: host=localhost, port=32769, socketOptions={0=YES, 1=NO, 17=0, 18=false, 2=0, 20=true, 38=TLS, 23=40, 24=50, 40=false, 25=0} 2025-06-18T08:13:13.5083954Z socket=null 2025-06-18T08:13:13.5085828Z client profile={oracle.net.encryption_types_client=(), oracle.net.crypto_seed=, oracle.net.authentication_services=(), oracle.net.setFIPSMode=false, oracle.net.kerberos5_mutual_authentication=false, oracle.net.encryption_client=ACCEPTED, oracle.net.crypto_checksum_client=ACCEPTED, oracle.net.crypto_checksum_types_client=()} 2025-06-18T08:13:13.5088048Z onBreakReset=false, dataEOF=false, negotiatedOptions=0x0, connected=false 2025-06-18T08:13:13.5088717Z TTIINIT enabled=false, TTC cookie enabled=false 2025-06-18T08:13:13.5089087Z 2025-06-18T08:13:13.5089412Z Jun 18, 2025 8:13:13 AM oracle.net.ns.NSProtocolNIO handleConnectPacketResponse 2025-06-18T08:13:13.5090323Z INFO: Got Refused, SessionTraceId = 1E1826C1 2025-06-18T08:13:13.5091316Z Jun 18, 2025 8:13:13 AM oracle.net.ns.NSProtocolNIO establishConnectionAfterRefusePacket 2025-06-18T08:13:13.5092028Z INFO: Outbound interrupt timer cancelled null 2025-06-18T08:13:13.5092622Z Jun 18, 2025 8:13:13 AM oracle.jdbc.driver.PhysicalConnection connect 2025-06-18T08:13:13.5093155Z INFO: throwing 2025-06-18T08:13:13.5094410Z java.sql.SQLRecoverableException: ORA-12514: Cannot connect to database. Service invalidDatabase is not registered with the listener at host localhost port 32769. (CONNECTION_ID=mow8621wRDKG5TmVDKKOKA==) 2025-06-18T08:13:13.5095939Z https://docs.oracle.com/error-help/db/ora-12514/ 2025-06-18T08:13:13.5096950Z at [email protected]/oracle.jdbc.driver.T4CConnection.handleLogonNetException(T4CConnection.java:1615) 2025-06-18T08:13:13.5098226Z at [email protected]/oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:1137) 2025-06-18T08:13:13.5099436Z at [email protected]/oracle.jdbc.driver.PhysicalConnection.connect(PhysicalConnection.java:1178) 2025-06-18T08:13:13.5100955Z at [email protected]/oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:105) 2025-06-18T08:13:13.5102218Z at [email protected]/oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:886) 2025-06-18T08:13:13.5103600Z at [email protected]/oracle.jdbc.datasource.impl.OracleDataSource.getPhysicalConnection(OracleDataSource.java:707) 2025-06-18T08:13:13.5105399Z at [email protected]/oracle.jdbc.datasource.impl.OracleDataSource.getConnection(OracleDataSource.java:381) 2025-06-18T08:13:13.5106849Z at [email protected]/oracle.jdbc.datasource.impl.OracleDataSource.getConnectionInternal(OracleDataSource.java:2206) 2025-06-18T08:13:13.5108381Z at [email protected]/oracle.jdbc.datasource.impl.OracleDataSource$1.build(OracleDataSource.java:1915) 2025-06-18T08:13:13.5109766Z at [email protected]/oracle.jdbc.datasource.impl.OracleDataSource$1.build(OracleDataSource.java:1849) 2025-06-18T08:13:13.5111178Z at [email protected]/io.vertx.oracleclient.impl.OracleConnectionFactory.lambda$connect$0(OracleConnectionFactory.java:68) 2025-06-18T08:13:13.5112048Z at [email protected]/io.vertx.oracleclient.impl.Helper$SQLBlockingCodeHandler.call(Helper.java:306) 2025-06-18T08:13:13.5112745Z at [email protected]/io.vertx.core.impl.ExecuteBlocking$1.execute(ExecuteBlocking.java:36) 2025-06-18T08:13:13.5113324Z at [email protected]/io.vertx.core.impl.WorkerTask.run(WorkerTask.java:57) 2025-06-18T08:13:13.5113895Z at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144) 2025-06-18T08:13:13.5114494Z at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642) 2025-06-18T08:13:13.5115175Z at [email protected]/io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30) 2025-06-18T08:13:13.5115711Z at java.base/java.lang.Thread.run(Thread.java:1583) 2025-06-18T08:13:13.5116495Z Caused by: oracle.net.ns.NetException: ORA-12514: Cannot connect to database. Service invalidDatabase is not registered with the listener at host localhost port 32769. (CONNECTION_ID=mow8621wRDKG5TmVDKKOKA==) 2025-06-18T08:13:13.5117693Z https://docs.oracle.com/error-help/db/ora-12514/ 2025-06-18T08:13:13.5119748Z at [email protected]/oracle.net.ns.NSProtocolNIO.createRefusePacketException(NSProtocolNIO.java:915) 2025-06-18T08:13:13.5121187Z at [email protected]/oracle.net.ns.NSProtocolNIO.handleConnectPacketResponse(NSProtocolNIO.java:461) 2025-06-18T08:13:13.5122401Z at [email protected]/oracle.net.ns.NSProtocolNIO.negotiateConnection(NSProtocolNIO.java:269) 2025-06-18T08:13:13.5123712Z at [email protected]/oracle.net.ns.NSProtocol.connect(NSProtocol.java:352) 2025-06-18T08:13:13.5124855Z at [email protected]/oracle.jdbc.driver.T4CConnection.connectNetworkSessionProtocol(T4CConnection.java:3411) 2025-06-18T08:13:13.5126233Z at [email protected]/oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:1016) 2025-06-18T08:13:13.5126994Z ... 16 more 2025-06-18T08:13:13.5127176Z 2025-06-18T08:13:13.5127531Z Jun 18, 2025 8:13:13 AM oracle.jdbc.diagnostics.Diagnostic dumpDiagnoseFirstFailure 2025-06-18T08:13:13.5128911Z INFO: properties={LOCALE=en, DriverVersion=23.4.0.24.05, java.library.path: =/usr/java/packages/lib:/usr/lib64:/lib64:/lib:/usr/lib, java.class.path: =, java.version: =21.0.7}. 2025-06-18T08:13:15.6622033Z [ORACLE] 2025-06-18T08:13:15.077401+00:00 2025-06-18T08:13:15.6623347Z [ORACLE] TABLE SYS.WRP$_REPORTS: ADDED AUTOLIST FRAGMENT SYS_P422 (3) VALUES (( 1467203046, TO_DATE(' 2025-06-16 00:00:00', 'syyyy-mm-dd hh24:mi:ss', 'nls_calendar=gregorian') )) 2025-06-18T08:13:15.6625132Z [ORACLE] TABLE SYS.WRP$_REPORTS_DETAILS: ADDED AUTOLIST FRAGMENT SYS_P423 (3) VALUES (( 1467203046, TO_DATE(' 2025-06-16 00:00:00', 'syyyy-mm-dd hh24:mi:ss', 'nls_calendar=gregorian') )) 2025-06-18T08:13:15.6626932Z [ORACLE] TABLE SYS.WRP$_REPORTS_TIME_BANDS: ADDED AUTOLIST FRAGMENT SYS_P426 (3) VALUES (( 1467203046, TO_DATE(' 2025-06-16 00:00:00', 'syyyy-mm-dd hh24:mi:ss', 'nls_calendar=gregorian') )) 2025-06-18T08:13:21.8199194Z [ERROR] Errors: 2025-06-18T08:13:21.8201259Z [ERROR] OracleMetricsTest>MetricsTestBase.testConnectionLost:232 » Timeout Timed out 2025-06-18T08:13:21.8202285Z [ERROR] Tests run: 262, Failures: 0, Errors: 1, Skipped: 21 Signed-off-by: Thomas Segismont <[email protected]> --------- Signed-off-by: Thomas Segismont <[email protected]>
1 parent a196cba commit 2832bf6

File tree

3 files changed

+100
-15
lines changed

3 files changed

+100
-15
lines changed

vertx-oracle-client/src/test/java/tests/oracleclient/tck/OracleMetricsTest.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@
1313

1414
import io.vertx.ext.unit.TestContext;
1515
import io.vertx.oracleclient.OracleBuilder;
16-
import tests.oracleclient.junit.OracleRule;
1716
import io.vertx.sqlclient.ClientBuilder;
1817
import io.vertx.sqlclient.Pool;
1918
import io.vertx.sqlclient.SqlConnectOptions;
2019
import io.vertx.tests.sqlclient.tck.MetricsTestBase;
2120
import org.junit.ClassRule;
2221
import org.junit.Ignore;
2322
import org.junit.Test;
23+
import tests.oracleclient.junit.OracleRule;
2424

2525
public class OracleMetricsTest extends MetricsTestBase {
2626

@@ -55,4 +55,11 @@ public void testPreparedBatchQuery(TestContext ctx) {
5555
public void testPrepareAndBatchQuery(TestContext ctx) {
5656
super.testPrepareAndBatchQuery(ctx);
5757
}
58+
59+
@Test
60+
@Ignore("Implementation of the test does not work with Oracle")
61+
@Override
62+
public void testConnectionLost(TestContext ctx) throws Exception {
63+
super.testConnectionLost(ctx);
64+
}
5865
}

vertx-sql-client/src/main/java/io/vertx/sqlclient/impl/pool/SqlConnectionPool.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,7 @@ public void onEnqueue(PoolWaiter<PooledConnection> waiter) {
255255
pool.cancel(waiter, (res, err) -> {
256256
if (err == null) {
257257
if (res) {
258+
dequeueMetric(metric);
258259
handler.fail("Timeout");
259260
}
260261
} else {

vertx-sql-client/src/test/java/io/vertx/tests/sqlclient/tck/MetricsTestBase.java

Lines changed: 91 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import io.vertx.ext.unit.TestContext;
2424
import io.vertx.ext.unit.junit.VertxUnitRunner;
2525
import io.vertx.sqlclient.*;
26+
import io.vertx.tests.sqlclient.ProxyServer;
2627
import org.junit.After;
2728
import org.junit.Before;
2829
import org.junit.Test;
@@ -36,6 +37,9 @@
3637
import java.util.concurrent.atomic.AtomicReference;
3738
import java.util.function.Function;
3839

40+
import static java.util.concurrent.TimeUnit.MILLISECONDS;
41+
import static java.util.concurrent.TimeUnit.SECONDS;
42+
3943
@RunWith(VertxUnitRunner.class)
4044
public abstract class MetricsTestBase {
4145

@@ -110,15 +114,20 @@ public void close() {
110114
pool.query("SELECT * FROM immutable WHERE id=1").execute().toCompletionStage().toCompletableFuture().get(20, TimeUnit.SECONDS);
111115
ctx.assertEquals(0, closeCount.get());
112116
pool.close();
113-
long now = System.currentTimeMillis();
114-
while (closeCount.get() != 1) {
115-
ctx.assertTrue(System.currentTimeMillis() - now < 20_000);
116-
Thread.sleep(100);
117-
}
117+
awaitQueueSize(ctx, closeCount, 1);
118118
}
119119

120120
@Test
121121
public void testQueuing(TestContext ctx) throws Exception {
122+
testQueuing(ctx, false);
123+
}
124+
125+
@Test
126+
public void testQueuingTimeout(TestContext ctx) throws Exception {
127+
testQueuing(ctx, true);
128+
}
129+
130+
private void testQueuing(TestContext ctx, boolean timeout) throws Exception {
122131
AtomicInteger queueSize = new AtomicInteger();
123132
List<Object> enqueueMetrics = Collections.synchronizedList(new ArrayList<>());
124133
List<Object> dequeueMetrics = Collections.synchronizedList(new ArrayList<>());
@@ -136,26 +145,94 @@ public void dequeue(Object taskMetric) {
136145
queueSize.decrementAndGet();
137146
}
138147
};
139-
Pool pool = createPool(vertx, new PoolOptions().setMaxSize(1).setName("the-pool"));
140-
SqlConnection conn = pool.getConnection().toCompletionStage().toCompletableFuture().get(20, TimeUnit.SECONDS);
148+
PoolOptions poolOptions = new PoolOptions().setMaxSize(1).setName("the-pool");
149+
if (timeout) {
150+
poolOptions.setConnectionTimeout(2).setConnectionTimeoutUnit(SECONDS);
151+
}
152+
Pool pool = createPool(vertx, poolOptions);
153+
SqlConnection conn = pool.getConnection().await(20, SECONDS);
141154
int num = 16;
142155
List<Future<?>> futures = new ArrayList<>();
143156
for (int i = 0;i < num;i++) {
144-
futures.add(pool.query("SELECT * FROM immutable WHERE id=1").execute());
145-
}
146-
long now = System.currentTimeMillis();
147-
while (queueSize.get() != num) {
148-
ctx.assertTrue(System.currentTimeMillis() - now < 20_000);
149-
Thread.sleep(100);
157+
futures.add(pool.withConnection(sqlConn -> sqlConn.query("SELECT * FROM immutable WHERE id=1").execute()));
150158
}
159+
awaitQueueSize(ctx, queueSize, timeout ? 0 : num);
151160
conn.close();
152-
Future.join(futures).toCompletionStage().toCompletableFuture().get(20, TimeUnit.SECONDS);
161+
Future.join(futures).otherwiseEmpty().await(20, SECONDS);
153162
ctx.assertEquals(0, queueSize.get());
154163
ctx.assertEquals(enqueueMetrics, dequeueMetrics);
155164
ctx.assertEquals("sql", poolType);
156165
ctx.assertEquals("the-pool", poolName);
157166
}
158167

168+
private void awaitQueueSize(TestContext ctx, AtomicInteger queueSize, int num) throws InterruptedException {
169+
long now = System.currentTimeMillis();
170+
for (; ; ) {
171+
if (queueSize.get() != num) {
172+
if (System.currentTimeMillis() - now >= 20_000) {
173+
ctx.fail("Timeout waiting for queue size " + queueSize.get() + " to be equal to " + num);
174+
} else {
175+
MILLISECONDS.sleep(500);
176+
}
177+
} else {
178+
break;
179+
}
180+
}
181+
}
182+
183+
@Test
184+
public void testConnectionLost(TestContext ctx) throws Exception {
185+
SqlConnectOptions connectOptions = connectOptions();
186+
ProxyServer proxy = ProxyServer.create(vertx, connectOptions.getPort(), connectOptions.getHost());
187+
AtomicReference<ProxyServer.Connection> firstConnection = new AtomicReference<>();
188+
proxy.proxyHandler(proxiedConn -> {
189+
if (firstConnection.compareAndSet(null, proxiedConn)) {
190+
proxiedConn.connect();
191+
}
192+
});
193+
// Start proxy
194+
Async listenLatch = ctx.async();
195+
proxy.listen(8080, "localhost", ctx.asyncAssertSuccess(res -> listenLatch.complete()));
196+
listenLatch.awaitSuccess(20_000);
197+
198+
199+
AtomicInteger queueSize = new AtomicInteger();
200+
poolMetrics = new PoolMetrics() {
201+
@Override
202+
public Object enqueue() {
203+
queueSize.incrementAndGet();
204+
return null;
205+
}
206+
207+
@Override
208+
public void dequeue(Object taskMetric) {
209+
queueSize.decrementAndGet();
210+
}
211+
};
212+
PoolOptions poolOptions = new PoolOptions()
213+
.setConnectionTimeout(500)
214+
.setConnectionTimeoutUnit(MILLISECONDS)
215+
.setMaxSize(1)
216+
.setName("the-pool");
217+
Pool pool = poolBuilder()
218+
.with(poolOptions)
219+
.using(vertx)
220+
.connectingTo(connectOptions.setHost("localhost").setPort(8080))
221+
.build();
222+
SqlConnection conn = pool.getConnection().await(20, SECONDS);
223+
int num = 16;
224+
Async async = ctx.async(num + 1);
225+
for (int i = 0; i < num; i++) {
226+
pool.withConnection(sqlConn -> sqlConn.query("SELECT * FROM immutable WHERE id=1").execute())
227+
.onComplete(ctx.asyncAssertFailure(t -> async.countDown()));
228+
}
229+
conn.closeHandler(v -> async.countDown());
230+
awaitQueueSize(ctx, queueSize, 16);
231+
firstConnection.get().clientSocket().close();
232+
async.await(20_000);
233+
ctx.assertEquals(0, queueSize.get());
234+
}
235+
159236
@Test
160237
public void testSimpleQuery(TestContext ctx) {
161238
Function<SqlConnection, Future<?>> fn = conn -> conn.query("SELECT * FROM immutable WHERE id=1").execute();

0 commit comments

Comments
 (0)