File tree Expand file tree Collapse file tree 1 file changed +25
-0
lines changed
vertx-mysql-client/src/test/java/io/vertx/mysqlclient Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Original file line number Diff line number Diff line change 1616import io .vertx .ext .unit .TestContext ;
1717import io .vertx .ext .unit .junit .VertxUnitRunner ;
1818import io .vertx .sqlclient .PoolOptions ;
19+ import io .vertx .sqlclient .Tuple ;
1920import org .junit .After ;
2021import org .junit .Before ;
2122import org .junit .Test ;
@@ -66,4 +67,28 @@ public void testContinuouslyQuery(TestContext ctx) {
6667 }));
6768 async .await ();
6869 }
70+
71+ // This test check that when using pooled connections, the preparedQuery pool operation
72+ // will actually use the same connection for the prepare and the query commands
73+ @ Test
74+ public void testConcurrentMultipleConnection (TestContext ctx ) {
75+ PoolOptions poolOptions = new PoolOptions ().setMaxSize (2 );
76+ MySQLPool pool = MySQLPool .pool (vertx , new MySQLConnectOptions (this .options ).setCachePreparedStatements (false ), poolOptions );
77+ try {
78+ int numRequests = 1500 ;
79+ Async async = ctx .async (numRequests );
80+ for (int i = 0 ;i < numRequests ;i ++) {
81+ pool .preparedQuery ("SELECT * FROM Fortune WHERE id=?" ).execute (Tuple .of (1 ), ctx .asyncAssertSuccess (results -> {
82+ ctx .assertEquals (1 , results .size ());
83+ Tuple row = results .iterator ().next ();
84+ ctx .assertEquals (1 , row .getInteger (0 ));
85+ ctx .assertEquals ("fortune: No such file or directory" , row .getString (1 ));
86+ async .countDown ();
87+ }));
88+ }
89+ async .awaitSuccess (10_000 );
90+ } finally {
91+ pool .close ();
92+ }
93+ }
6994}
You can’t perform that action at this time.
0 commit comments