Skip to content

Commit 93e6e0f

Browse files
committed
Ported MySQL concurrent pool prepared query test
1 parent 82275e1 commit 93e6e0f

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

vertx-mysql-client/src/test/java/io/vertx/mysqlclient/MySQLPoolTest.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import io.vertx.ext.unit.TestContext;
1717
import io.vertx.ext.unit.junit.VertxUnitRunner;
1818
import io.vertx.sqlclient.PoolOptions;
19+
import io.vertx.sqlclient.Tuple;
1920
import org.junit.After;
2021
import org.junit.Before;
2122
import 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
}

0 commit comments

Comments
 (0)