@@ -342,4 +342,65 @@ public void requestReset(Object requestMetric) {
342342 }));
343343 });
344344 }
345+
346+ @ Test
347+ public void testGetConnectionFailure (TestContext ctx ) throws Exception {
348+ testConnectionFailure (ctx , true );
349+ }
350+
351+ @ Test
352+ public void testPooledConnectionFailure (TestContext ctx ) throws Exception {
353+ testConnectionFailure (ctx , false );
354+ }
355+
356+ private void testConnectionFailure (TestContext ctx , boolean useGetConnection ) throws Exception {
357+ AtomicInteger queueSize = new AtomicInteger ();
358+ List <Object > enqueueMetrics = Collections .synchronizedList (new ArrayList <>());
359+ List <Object > dequeueMetrics = Collections .synchronizedList (new ArrayList <>());
360+ poolMetrics = new PoolMetrics () {
361+ @ Override
362+ public Object enqueue () {
363+ Object metric = new Object ();
364+ enqueueMetrics .add (metric );
365+ queueSize .incrementAndGet ();
366+ return metric ;
367+ }
368+
369+ @ Override
370+ public void dequeue (Object taskMetric ) {
371+ dequeueMetrics .add (taskMetric );
372+ queueSize .decrementAndGet ();
373+ }
374+
375+ @ Override
376+ public Object begin () {
377+ throw new IllegalStateException ("Shouldn't be invoked" );
378+ }
379+
380+ @ Override
381+ public void end (Object usageMetric ) {
382+ throw new IllegalStateException ("Shouldn't be invoked" );
383+ }
384+ };
385+ PoolOptions poolOptions = new PoolOptions ().setMaxSize (1 ).setName ("the-pool" );
386+ SqlConnectOptions connectOptions = connectOptions ().setHost ("does.not.exist.com" );
387+ Pool pool = poolBuilder ().with (poolOptions ).using (vertx ).connectingTo (connectOptions ).build ();
388+ int num = 16 ;
389+ List <Future <?>> futures = new ArrayList <>();
390+ for (int i = 0 ; i < num ; i ++) {
391+ Future <RowSet <Row >> future ;
392+ if (useGetConnection ) {
393+ future = pool .withConnection (sqlConn -> sqlConn .query ("SELECT * FROM immutable WHERE id=1" ).execute ());
394+ } else {
395+ future = pool .query ("SELECT * FROM immutable WHERE id=1" ).execute ();
396+ }
397+ futures .add (future );
398+ }
399+ Future .join (futures ).otherwiseEmpty ().await (20 , SECONDS );
400+ ctx .assertEquals (0 , queueSize .get ());
401+ ctx .assertEquals (num , enqueueMetrics .size ());
402+ ctx .assertEquals (enqueueMetrics , dequeueMetrics );
403+ ctx .assertEquals ("sql" , poolType );
404+ ctx .assertEquals ("the-pool" , poolName );
405+ }
345406}
0 commit comments