提交 3c57fec3 authored 作者: Thomas Mueller's avatar Thomas Mueller

JdbcConnectionPool.setLoginTimeout with 0 now uses the default timeout.

Creating a pool is now simpler.
The connection pool did not re-use connections.
上级 b9bcaaed
......@@ -7,6 +7,7 @@
package org.h2.test.jdbcx;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
......@@ -30,11 +31,45 @@ public class TestConnectionPool extends TestBase {
public void test() throws Exception {
deleteDb("connectionPool");
testPerformance();
testKeepOpen();
testConnect();
testThreads();
deleteDb("connectionPool");
}
private void testPerformance() throws SQLException {
String url = getURL("connectionPool", true), user = getUser(), password = getPassword();
JdbcConnectionPool man = JdbcConnectionPool.create(url, user, password);
Connection conn = man.getConnection();
int len = 1000;
long start = System.currentTimeMillis();
for (int i = 0; i < len; i++) {
man.getConnection().close();
}
trace((int) (System.currentTimeMillis() - start));
man.dispose();
start = System.currentTimeMillis();
for (int i = 0; i < len; i++) {
DriverManager.getConnection(url, user, password).close();
}
trace((int) (System.currentTimeMillis() - start));
conn.close();
}
private void testKeepOpen() throws Exception {
JdbcConnectionPool man = getConnectionPool(1);
Connection conn = man.getConnection();
Statement stat = conn.createStatement();
stat.execute("create local temporary table test(id int)");
conn.close();
conn = man.getConnection();
stat = conn.createStatement();
stat.execute("select * from test");
conn.close();
man.dispose();
}
private void testThreads() throws Exception {
final int len = getSize(4, 20);
final JdbcConnectionPool man = getConnectionPool(len - 2);
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论