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