提交 810a0771 authored 作者: Noel Grandin's avatar Noel Grandin 提交者: GitHub

Merge pull request #563 from andreitokar/issue#556.2

Issue#556 close connections in tests (at least in case of successful execution)
...@@ -23,6 +23,7 @@ import java.util.concurrent.TimeUnit; ...@@ -23,6 +23,7 @@ import java.util.concurrent.TimeUnit;
import org.h2.fulltext.FullText; import org.h2.fulltext.FullText;
import org.h2.store.fs.FileUtils; import org.h2.store.fs.FileUtils;
import org.h2.test.TestBase; import org.h2.test.TestBase;
import org.h2.util.IOUtils;
import org.h2.util.Task; import org.h2.util.Task;
/** /**
...@@ -90,9 +91,9 @@ public class TestFullText extends TestBase { ...@@ -90,9 +91,9 @@ public class TestFullText extends TestBase {
deleteDb("fullTextReopen"); deleteDb("fullTextReopen");
} }
private static void close(Collection<Connection> list) throws SQLException { private static void close(Collection<Connection> list) {
for (Connection conn : list) { for (Connection conn : list) {
conn.close(); IOUtils.closeSilently(conn);
} }
} }
...@@ -491,8 +492,7 @@ public class TestFullText extends TestBase { ...@@ -491,8 +492,7 @@ public class TestFullText extends TestBase {
return; return;
} }
deleteDb("fullText"); deleteDb("fullText");
ArrayList<Connection> connList = new ArrayList<Connection>(); Connection conn = getConnection("fullText");
Connection conn = getConnection("fullText", connList);
String prefix = lucene ? "FTL_" : "FT_"; String prefix = lucene ? "FTL_" : "FT_";
Statement stat = conn.createStatement(); Statement stat = conn.createStatement();
String className = lucene ? "FullTextLucene" : "FullText"; String className = lucene ? "FullTextLucene" : "FullText";
...@@ -590,15 +590,15 @@ public class TestFullText extends TestBase { ...@@ -590,15 +590,15 @@ public class TestFullText extends TestBase {
if (!config.memory) { if (!config.memory) {
conn.close(); conn.close();
conn = getConnection("fullText");
} }
conn = getConnection("fullText", connList);
stat = conn.createStatement(); stat = conn.createStatement();
stat.executeQuery("SELECT * FROM " + prefix + "SEARCH('World', 0, 0)"); stat.executeQuery("SELECT * FROM " + prefix + "SEARCH('World', 0, 0)");
stat.execute("CALL " + prefix + "DROP_ALL()"); stat.execute("CALL " + prefix + "DROP_ALL()");
close(connList); conn.close();
} }
private void testDropIndex(boolean lucene) throws SQLException { private void testDropIndex(boolean lucene) throws SQLException {
...@@ -625,7 +625,6 @@ public class TestFullText extends TestBase { ...@@ -625,7 +625,6 @@ public class TestFullText extends TestBase {
"_CREATE_INDEX('PUBLIC', 'TEST', 'NAME1, NAME2')"); "_CREATE_INDEX('PUBLIC', 'TEST', 'NAME1, NAME2')");
stat.execute("UPDATE TEST SET NAME2=NULL WHERE ID=1"); stat.execute("UPDATE TEST SET NAME2=NULL WHERE ID=1");
stat.execute("UPDATE TEST SET NAME2='Hello World' WHERE ID=1"); stat.execute("UPDATE TEST SET NAME2='Hello World' WHERE ID=1");
conn.close();
conn.close(); conn.close();
FileUtils.deleteRecursive(getBaseDir() + "/fullTextDropIndex", false); FileUtils.deleteRecursive(getBaseDir() + "/fullTextDropIndex", false);
......
...@@ -1285,6 +1285,7 @@ public class TestFunctions extends TestBase implements AggregateFunction { ...@@ -1285,6 +1285,7 @@ public class TestFunctions extends TestBase implements AggregateFunction {
String.format("SELECT ORA_HASH('%s', 0) FROM DUAL", testStr)); String.format("SELECT ORA_HASH('%s', 0) FROM DUAL", testStr));
assertResult(String.valueOf("foo".hashCode()), stat, assertResult(String.valueOf("foo".hashCode()), stat,
String.format("SELECT ORA_HASH('%s', 0, 0) FROM DUAL", testStr)); String.format("SELECT ORA_HASH('%s', 0, 0) FROM DUAL", testStr));
conn.close();
} }
private void testToDateException() { private void testToDateException() {
...@@ -2058,6 +2059,7 @@ public class TestFunctions extends TestBase implements AggregateFunction { ...@@ -2058,6 +2059,7 @@ public class TestFunctions extends TestBase implements AggregateFunction {
assertFalse(parsed.before(before)); assertFalse(parsed.before(before));
assertFalse(parsed.after(after)); assertFalse(parsed.after(after));
conn.close();
} }
...@@ -2083,6 +2085,7 @@ public class TestFunctions extends TestBase implements AggregateFunction { ...@@ -2083,6 +2085,7 @@ public class TestFunctions extends TestBase implements AggregateFunction {
rs.close(); rs.close();
assertEquals(first, second); assertEquals(first, second);
conn.close();
} }
private void testThatCurrentTimestampUpdatesOutsideATransaction() private void testThatCurrentTimestampUpdatesOutsideATransaction()
...@@ -2107,11 +2110,12 @@ public class TestFunctions extends TestBase implements AggregateFunction { ...@@ -2107,11 +2110,12 @@ public class TestFunctions extends TestBase implements AggregateFunction {
rs.close(); rs.close();
assertTrue(second.after(first)); assertTrue(second.after(first));
conn.close();
} }
private void callCompiledFunction(String functionName) throws SQLException { private void callCompiledFunction(String functionName) throws SQLException {
deleteDb("functions"); deleteDb("functions");
Connection conn = getConnection("functions"); try (Connection conn = getConnection("functions")) {
Statement stat = conn.createStatement(); Statement stat = conn.createStatement();
ResultSet rs; ResultSet rs;
stat.execute("create alias " + functionName + " AS " stat.execute("create alias " + functionName + " AS "
...@@ -2125,8 +2129,7 @@ public class TestFunctions extends TestBase implements AggregateFunction { ...@@ -2125,8 +2129,7 @@ public class TestFunctions extends TestBase implements AggregateFunction {
assertEquals(Boolean.class.getName(), rs.getObject(1).getClass().getName()); assertEquals(Boolean.class.getName(), rs.getObject(1).getClass().getName());
stat.execute("drop alias " + functionName + ""); stat.execute("drop alias " + functionName + "");
}
conn.close();
} }
private void assertCallResult(String expected, Statement stat, String sql) private void assertCallResult(String expected, Statement stat, String sql)
......
...@@ -38,20 +38,15 @@ public class TestMultiThread extends TestBase implements Runnable { ...@@ -38,20 +38,15 @@ public class TestMultiThread extends TestBase implements Runnable {
private boolean stop; private boolean stop;
private TestMultiThread parent; private TestMultiThread parent;
private Random random; private Random random;
private Connection threadConn;
private Statement threadStat;
public TestMultiThread() { public TestMultiThread() {
// nothing to do // nothing to do
} }
private TestMultiThread(TestAll config, TestMultiThread parent) private TestMultiThread(TestAll config, TestMultiThread parent) {
throws SQLException {
this.config = config; this.config = config;
this.parent = parent; this.parent = parent;
random = new Random(); random = new Random();
threadConn = getConnection();
threadStat = threadConn.createStatement();
} }
/** /**
...@@ -81,7 +76,7 @@ public class TestMultiThread extends TestBase implements Runnable { ...@@ -81,7 +76,7 @@ public class TestMultiThread extends TestBase implements Runnable {
String db = getTestName(); String db = getTestName();
deleteDb(db); deleteDb(db);
final String url = getURL(db + ";MULTI_THREADED=1;LOCK_TIMEOUT=10000", true); final String url = getURL(db + ";MULTI_THREADED=1;LOCK_TIMEOUT=10000", true);
Connection conn = getConnection(url); try (Connection conn = getConnection(url)) {
Task[] tasks = new Task[2]; Task[] tasks = new Task[2];
for (int i = 0; i < tasks.length; i++) { for (int i = 0; i < tasks.length; i++) {
final int x = i; final int x = i;
...@@ -105,14 +100,14 @@ public class TestMultiThread extends TestBase implements Runnable { ...@@ -105,14 +100,14 @@ public class TestMultiThread extends TestBase implements Runnable {
for (Task t : tasks) { for (Task t : tasks) {
t.get(); t.get();
} }
conn.close(); }
} }
private void testConcurrentLobAdd() throws Exception { private void testConcurrentLobAdd() throws Exception {
String db = getTestName(); String db = getTestName();
deleteDb(db); deleteDb(db);
final String url = getURL(db + ";MULTI_THREADED=1", true); final String url = getURL(db + ";MULTI_THREADED=1", true);
Connection conn = getConnection(url); try (Connection conn = getConnection(url)) {
Statement stat = conn.createStatement(); Statement stat = conn.createStatement();
stat.execute("create table test(id identity, data clob)"); stat.execute("create table test(id identity, data clob)");
Task[] tasks = new Task[2]; Task[] tasks = new Task[2];
...@@ -138,7 +133,7 @@ public class TestMultiThread extends TestBase implements Runnable { ...@@ -138,7 +133,7 @@ public class TestMultiThread extends TestBase implements Runnable {
for (Task t : tasks) { for (Task t : tasks) {
t.get(); t.get();
} }
conn.close(); }
} }
private void testConcurrentView() throws Exception { private void testConcurrentView() throws Exception {
...@@ -149,7 +144,7 @@ public class TestMultiThread extends TestBase implements Runnable { ...@@ -149,7 +144,7 @@ public class TestMultiThread extends TestBase implements Runnable {
deleteDb(db); deleteDb(db);
final String url = getURL(db + ";MULTI_THREADED=1", true); final String url = getURL(db + ";MULTI_THREADED=1", true);
final Random r = new Random(); final Random r = new Random();
Connection conn = getConnection(url); try (Connection conn = getConnection(url)) {
Statement stat = conn.createStatement(); Statement stat = conn.createStatement();
StringBuilder buff = new StringBuilder(); StringBuilder buff = new StringBuilder();
buff.append("create table test(id int"); buff.append("create table test(id int");
...@@ -180,12 +175,12 @@ public class TestMultiThread extends TestBase implements Runnable { ...@@ -180,12 +175,12 @@ public class TestMultiThread extends TestBase implements Runnable {
} }
t.get(); t.get();
SynchronizedVerifier.setDetect(SmallLRUCache.class, false); SynchronizedVerifier.setDetect(SmallLRUCache.class, false);
conn.close(); }
} }
private void testConcurrentAlter() throws Exception { private void testConcurrentAlter() throws Exception {
deleteDb(getTestName()); deleteDb(getTestName());
final Connection conn = getConnection(getTestName()); try (final Connection conn = getConnection(getTestName())) {
Statement stat = conn.createStatement(); Statement stat = conn.createStatement();
Task t = new Task() { Task t = new Task() {
@Override @Override
...@@ -202,7 +197,7 @@ public class TestMultiThread extends TestBase implements Runnable { ...@@ -202,7 +197,7 @@ public class TestMultiThread extends TestBase implements Runnable {
stat.execute("alter table test drop column x"); stat.execute("alter table test drop column x");
} }
t.get(); t.get();
conn.close(); }
} }
private void testConcurrentAnalyze() throws Exception { private void testConcurrentAnalyze() throws Exception {
...@@ -211,19 +206,18 @@ public class TestMultiThread extends TestBase implements Runnable { ...@@ -211,19 +206,18 @@ public class TestMultiThread extends TestBase implements Runnable {
} }
deleteDb(getTestName()); deleteDb(getTestName());
final String url = getURL("concurrentAnalyze;MULTI_THREADED=1", true); final String url = getURL("concurrentAnalyze;MULTI_THREADED=1", true);
Connection conn = getConnection(url); try (Connection conn = getConnection(url)) {
Statement stat = conn.createStatement(); Statement stat = conn.createStatement();
stat.execute("create table test(id bigint primary key) " + stat.execute("create table test(id bigint primary key) " +
"as select x from system_range(1, 1000)"); "as select x from system_range(1, 1000)");
Task t = new Task() { Task t = new Task() {
@Override @Override
public void call() throws SQLException { public void call() throws SQLException {
Connection conn2; try (Connection conn2 = getConnection(url)) {
conn2 = getConnection(url);
for (int i = 0; i < 1000; i++) { for (int i = 0; i < 1000; i++) {
conn2.createStatement().execute("analyze"); conn2.createStatement().execute("analyze");
} }
conn2.close(); }
} }
}; };
t.execute(); t.execute();
...@@ -233,13 +227,13 @@ public class TestMultiThread extends TestBase implements Runnable { ...@@ -233,13 +227,13 @@ public class TestMultiThread extends TestBase implements Runnable {
} }
t.get(); t.get();
stat.execute("drop table test"); stat.execute("drop table test");
conn.close(); }
} }
private void testConcurrentInsertUpdateSelect() throws Exception { private void testConcurrentInsertUpdateSelect() throws Exception {
threadConn = getConnection(); try (Connection conn = getConnection()) {
threadStat = threadConn.createStatement(); Statement stmt = conn.createStatement();
threadStat.execute("CREATE TABLE TEST(ID IDENTITY, NAME VARCHAR)"); stmt.execute("CREATE TABLE TEST(ID IDENTITY, NAME VARCHAR)");
int len = getSize(10, 200); int len = getSize(10, 200);
Thread[] threads = new Thread[len]; Thread[] threads = new Thread[len];
for (int i = 0; i < len; i++) { for (int i = 0; i < len; i++) {
...@@ -254,10 +248,10 @@ public class TestMultiThread extends TestBase implements Runnable { ...@@ -254,10 +248,10 @@ public class TestMultiThread extends TestBase implements Runnable {
for (int i = 0; i < len; i++) { for (int i = 0; i < len; i++) {
threads[i].join(); threads[i].join();
} }
ResultSet rs = threadStat.executeQuery("SELECT COUNT(*) FROM TEST"); ResultSet rs = stmt.executeQuery("SELECT COUNT(*) FROM TEST");
rs.next(); rs.next();
trace("max id=" + rs.getInt(1)); trace("max id=" + rs.getInt(1));
threadConn.close(); }
} }
private Connection getConnection() throws SQLException { private Connection getConnection() throws SQLException {
...@@ -266,22 +260,22 @@ public class TestMultiThread extends TestBase implements Runnable { ...@@ -266,22 +260,22 @@ public class TestMultiThread extends TestBase implements Runnable {
@Override @Override
public void run() { public void run() {
try { try (Connection conn = getConnection()) {
Statement stmt = conn.createStatement();
while (!parent.stop) { while (!parent.stop) {
threadStat.execute("SELECT COUNT(*) FROM TEST"); stmt.execute("SELECT COUNT(*) FROM TEST");
threadStat.execute("INSERT INTO TEST VALUES(NULL, 'Hi')"); stmt.execute("INSERT INTO TEST VALUES(NULL, 'Hi')");
PreparedStatement prep = threadConn.prepareStatement( PreparedStatement prep = conn.prepareStatement(
"UPDATE TEST SET NAME='Hello' WHERE ID=?"); "UPDATE TEST SET NAME='Hello' WHERE ID=?");
prep.setInt(1, random.nextInt(10000)); prep.setInt(1, random.nextInt(10000));
prep.execute(); prep.execute();
prep = threadConn.prepareStatement("SELECT * FROM TEST WHERE ID=?"); prep = conn.prepareStatement("SELECT * FROM TEST WHERE ID=?");
prep.setInt(1, random.nextInt(10000)); prep.setInt(1, random.nextInt(10000));
ResultSet rs = prep.executeQuery(); ResultSet rs = prep.executeQuery();
while (rs.next()) { while (rs.next()) {
rs.getString("NAME"); rs.getString("NAME");
} }
} }
threadConn.close();
} catch (Exception e) { } catch (Exception e) {
logError("multi", e); logError("multi", e);
} }
...@@ -292,11 +286,11 @@ public class TestMultiThread extends TestBase implements Runnable { ...@@ -292,11 +286,11 @@ public class TestMultiThread extends TestBase implements Runnable {
// is not supported // is not supported
deleteDb("lockMode"); deleteDb("lockMode");
final String url = getURL("lockMode;MULTI_THREADED=1", true); final String url = getURL("lockMode;MULTI_THREADED=1", true);
Connection conn = getConnection(url); try (Connection conn = getConnection(url)) {
DatabaseMetaData meta = conn.getMetaData(); DatabaseMetaData meta = conn.getMetaData();
assertFalse(meta.supportsTransactionIsolationLevel( assertFalse(meta.supportsTransactionIsolationLevel(
Connection.TRANSACTION_READ_UNCOMMITTED)); Connection.TRANSACTION_READ_UNCOMMITTED));
conn.close(); }
deleteDb("lockMode"); deleteDb("lockMode");
} }
...@@ -307,8 +301,10 @@ public class TestMultiThread extends TestBase implements Runnable { ...@@ -307,8 +301,10 @@ public class TestMultiThread extends TestBase implements Runnable {
final String url = getURL("lockMode;MULTI_THREADED=1", true); final String url = getURL("lockMode;MULTI_THREADED=1", true);
// create some common tables and views // create some common tables and views
final Connection conn = getConnection(url); ExecutorService executor = Executors.newFixedThreadPool(8);
final Statement stat = conn.createStatement(); Connection conn = getConnection(url);
try {
Statement stat = conn.createStatement();
stat.execute( stat.execute(
"CREATE TABLE INVOICE(INVOICE_ID INT PRIMARY KEY, AMOUNT DECIMAL)"); "CREATE TABLE INVOICE(INVOICE_ID INT PRIMARY KEY, AMOUNT DECIMAL)");
stat.execute("CREATE VIEW INVOICE_VIEW as SELECT * FROM INVOICE"); stat.execute("CREATE VIEW INVOICE_VIEW as SELECT * FROM INVOICE");
...@@ -322,15 +318,13 @@ public class TestMultiThread extends TestBase implements Runnable { ...@@ -322,15 +318,13 @@ public class TestMultiThread extends TestBase implements Runnable {
stat.close(); stat.close();
// create views that reference the common views in different threads // create views that reference the common views in different threads
final ExecutorService executor = Executors.newFixedThreadPool(8); ArrayList<Future<Void>> jobs = new ArrayList<Future<Void>>();
try {
final ArrayList<Future<Void>> jobs = new ArrayList<Future<Void>>();
for (int i = 0; i < 1000; i++) { for (int i = 0; i < 1000; i++) {
final int j = i; final int j = i;
jobs.add(executor.submit(new Callable<Void>() { jobs.add(executor.submit(new Callable<Void>() {
@Override @Override
public Void call() throws Exception { public Void call() throws Exception {
final Connection conn2 = getConnection(url); try (Connection conn2 = getConnection(url)) {
Statement stat2 = conn2.createStatement(); Statement stat2 = conn2.createStatement();
stat2.execute("CREATE VIEW INVOICE_VIEW" + j stat2.execute("CREATE VIEW INVOICE_VIEW" + j
...@@ -354,8 +348,8 @@ public class TestMultiThread extends TestBase implements Runnable { ...@@ -354,8 +348,8 @@ public class TestMultiThread extends TestBase implements Runnable {
rs.next(); rs.next();
rs.close(); rs.close();
stat.close(); stat2.close();
conn.close(); }
return null; return null;
} }
})); }));
...@@ -388,37 +382,36 @@ public class TestMultiThread extends TestBase implements Runnable { ...@@ -388,37 +382,36 @@ public class TestMultiThread extends TestBase implements Runnable {
deleteDb("lockMode"); deleteDb("lockMode");
final String url = getURL("lockMode;MULTI_THREADED=1", true); final String url = getURL("lockMode;MULTI_THREADED=1", true);
final Connection conn = getConnection(url); int threadCount = 25;
ExecutorService executor = Executors.newFixedThreadPool(threadCount);
Connection conn = getConnection(url);
try {
conn.createStatement().execute( conn.createStatement().execute(
"CREATE TABLE IF NOT EXISTS TRAN (ID NUMBER(18,0) not null PRIMARY KEY)"); "CREATE TABLE IF NOT EXISTS TRAN (ID NUMBER(18,0) not null PRIMARY KEY)");
final int threadCount = 25;
final ArrayList<Callable<Void>> callables = new ArrayList<Callable<Void>>(); final ArrayList<Callable<Void>> callables = new ArrayList<Callable<Void>>();
for (int i = 0; i < threadCount; i++) { for (int i = 0; i < threadCount; i++) {
final Connection taskConn = getConnection(url);
taskConn.setAutoCommit(false);
final PreparedStatement insertTranStmt = taskConn
.prepareStatement("INSERT INTO tran (id) values(?)");
// to guarantee uniqueness
final long initialTransactionId = i * 1000000L; final long initialTransactionId = i * 1000000L;
callables.add(new Callable<Void>() { callables.add(new Callable<Void>() {
@Override @Override
public Void call() throws Exception { public Void call() throws Exception {
try (Connection taskConn = getConnection(url)) {
taskConn.setAutoCommit(false);
PreparedStatement insertTranStmt = taskConn
.prepareStatement("INSERT INTO tran (id) VALUES(?)");
// to guarantee uniqueness
long tranId = initialTransactionId; long tranId = initialTransactionId;
for (int j = 0; j < 1000; j++) { for (int j = 0; j < 1000; j++) {
insertTranStmt.setLong(1, tranId++); insertTranStmt.setLong(1, tranId++);
insertTranStmt.execute(); insertTranStmt.execute();
taskConn.commit(); taskConn.commit();
} }
taskConn.close(); }
return null; return null;
} }
}); });
} }
final ExecutorService executor = Executors
.newFixedThreadPool(threadCount);
try {
final ArrayList<Future<Void>> jobs = new ArrayList<Future<Void>>(); final ArrayList<Future<Void>> jobs = new ArrayList<Future<Void>>();
for (int i = 0; i < threadCount; i++) { for (int i = 0; i < threadCount; i++) {
jobs.add(executor.submit(callables.get(i))); jobs.add(executor.submit(callables.get(i)));
...@@ -441,7 +434,10 @@ public class TestMultiThread extends TestBase implements Runnable { ...@@ -441,7 +434,10 @@ public class TestMultiThread extends TestBase implements Runnable {
final int objectCount = 10000; final int objectCount = 10000;
final String url = getURL("lockMode;MULTI_THREADED=1;LOCK_TIMEOUT=10000", true); final String url = getURL("lockMode;MULTI_THREADED=1;LOCK_TIMEOUT=10000", true);
final Connection conn = getConnection(url); int threadCount = 25;
ExecutorService executor = Executors.newFixedThreadPool(threadCount);
Connection conn = getConnection(url);
try {
conn.createStatement().execute( conn.createStatement().execute(
"CREATE TABLE IF NOT EXISTS ACCOUNT" + "CREATE TABLE IF NOT EXISTS ACCOUNT" +
"(ID NUMBER(18,0) not null PRIMARY KEY, BALANCE NUMBER null)"); "(ID NUMBER(18,0) not null PRIMARY KEY, BALANCE NUMBER null)");
...@@ -453,30 +449,27 @@ public class TestMultiThread extends TestBase implements Runnable { ...@@ -453,30 +449,27 @@ public class TestMultiThread extends TestBase implements Runnable {
mergeAcctStmt.execute(); mergeAcctStmt.execute();
} }
final int threadCount = 25;
final ArrayList<Callable<Void>> callables = new ArrayList<Callable<Void>>(); final ArrayList<Callable<Void>> callables = new ArrayList<Callable<Void>>();
for (int i = 0; i < threadCount; i++) { for (int i = 0; i < threadCount; i++) {
final Connection taskConn = getConnection(url);
taskConn.setAutoCommit(false);
final PreparedStatement updateAcctStmt = taskConn
.prepareStatement("UPDATE account set balance = ? where id = ?");
callables.add(new Callable<Void>() { callables.add(new Callable<Void>() {
@Override @Override
public Void call() throws Exception { public Void call() throws Exception {
try (Connection taskConn = getConnection(url)) {
taskConn.setAutoCommit(false);
final PreparedStatement updateAcctStmt = taskConn
.prepareStatement("UPDATE account SET balance = ? WHERE id = ?");
for (int j = 0; j < 1000; j++) { for (int j = 0; j < 1000; j++) {
updateAcctStmt.setDouble(1, Math.random()); updateAcctStmt.setDouble(1, Math.random());
updateAcctStmt.setLong(2, (int) (Math.random() * objectCount)); updateAcctStmt.setLong(2, (int) (Math.random() * objectCount));
updateAcctStmt.execute(); updateAcctStmt.execute();
taskConn.commit(); taskConn.commit();
} }
taskConn.close(); }
return null; return null;
} }
}); });
} }
final ExecutorService executor = Executors.newFixedThreadPool(threadCount);
try {
final ArrayList<Future<Void>> jobs = new ArrayList<Future<Void>>(); final ArrayList<Future<Void>> jobs = new ArrayList<Future<Void>>();
for (int i = 0; i < threadCount; i++) { for (int i = 0; i < threadCount; i++) {
jobs.add(executor.submit(callables.get(i))); jobs.add(executor.submit(callables.get(i)));
......
...@@ -36,7 +36,7 @@ public class TestQueryCache extends TestBase { ...@@ -36,7 +36,7 @@ public class TestQueryCache extends TestBase {
} }
private void test1() throws Exception { private void test1() throws Exception {
Connection conn = getConnection("queryCache;QUERY_CACHE_SIZE=10"); try (Connection conn = getConnection("queryCache;QUERY_CACHE_SIZE=10")) {
Statement stat = conn.createStatement(); Statement stat = conn.createStatement();
stat.execute("create table test(id int, name varchar)"); stat.execute("create table test(id int, name varchar)");
PreparedStatement prep; PreparedStatement prep;
...@@ -91,11 +91,11 @@ public class TestQueryCache extends TestBase { ...@@ -91,11 +91,11 @@ public class TestQueryCache extends TestBase {
// usually this is true // usually this is true
assertSmaller(firstSmaller, firstGreater); assertSmaller(firstSmaller, firstGreater);
stat.execute("drop table test"); stat.execute("drop table test");
conn.close(); }
} }
private void testClearingCacheWithTableStructureChanges() throws Exception { private void testClearingCacheWithTableStructureChanges() throws Exception {
Connection conn = getConnection("queryCache;QUERY_CACHE_SIZE=10"); try (Connection conn = getConnection("queryCache;QUERY_CACHE_SIZE=10")) {
assertThrows(ErrorCode.TABLE_OR_VIEW_NOT_FOUND_1, conn). assertThrows(ErrorCode.TABLE_OR_VIEW_NOT_FOUND_1, conn).
prepareStatement("SELECT * FROM TEST"); prepareStatement("SELECT * FROM TEST");
Statement stat = conn.createStatement(); Statement stat = conn.createStatement();
...@@ -105,6 +105,6 @@ public class TestQueryCache extends TestBase { ...@@ -105,6 +105,6 @@ public class TestQueryCache extends TestBase {
stat.executeUpdate("DROP TABLE TEST"); stat.executeUpdate("DROP TABLE TEST");
assertThrows(ErrorCode.TABLE_OR_VIEW_NOT_FOUND_1, conn). assertThrows(ErrorCode.TABLE_OR_VIEW_NOT_FOUND_1, conn).
prepareStatement("SELECT * FROM TEST"); prepareStatement("SELECT * FROM TEST");
conn.close(); }
} }
} }
...@@ -33,7 +33,7 @@ public class TestShow extends TestBase { ...@@ -33,7 +33,7 @@ public class TestShow extends TestBase {
} }
private void testPgCompatibility() throws SQLException { private void testPgCompatibility() throws SQLException {
Connection conn = getConnection("mem:pg"); try (Connection conn = getConnection("mem:pg")) {
Statement stat = conn.createStatement(); Statement stat = conn.createStatement();
assertResult("UNICODE", stat, "SHOW CLIENT_ENCODING"); assertResult("UNICODE", stat, "SHOW CLIENT_ENCODING");
...@@ -43,9 +43,10 @@ public class TestShow extends TestBase { ...@@ -43,9 +43,10 @@ public class TestShow extends TestBase {
assertResult("8.1.4", stat, "SHOW SERVER_VERSION"); assertResult("8.1.4", stat, "SHOW SERVER_VERSION");
assertResult("UTF8", stat, "SHOW SERVER_ENCODING"); assertResult("UTF8", stat, "SHOW SERVER_ENCODING");
} }
}
private void testMysqlCompatibility() throws SQLException { private void testMysqlCompatibility() throws SQLException {
Connection conn = getConnection("mem:pg"); try (Connection conn = getConnection("mem:pg")) {
Statement stat = conn.createStatement(); Statement stat = conn.createStatement();
ResultSet rs; ResultSet rs;
...@@ -63,4 +64,5 @@ public class TestShow extends TestBase { ...@@ -63,4 +64,5 @@ public class TestShow extends TestBase {
// columns // columns
assertResultRowCount(2, stat.executeQuery("SHOW COLUMNS FROM person")); assertResultRowCount(2, stat.executeQuery("SHOW COLUMNS FROM person"));
} }
}
} }
...@@ -1064,7 +1064,7 @@ public class TestSpatial extends TestBase { ...@@ -1064,7 +1064,7 @@ public class TestSpatial extends TestBase {
private void testInsertNull() throws SQLException { private void testInsertNull() throws SQLException {
deleteDb("spatial"); deleteDb("spatial");
Connection conn = getConnection(URL); try (Connection conn = getConnection(URL)) {
Statement stat = conn.createStatement(); Statement stat = conn.createStatement();
stat.execute("\n" + stat.execute("\n" +
"drop table if exists PUBLIC.DUMMY_12;\n" + "drop table if exists PUBLIC.DUMMY_12;\n" +
...@@ -1137,12 +1137,13 @@ public class TestSpatial extends TestBase { ...@@ -1137,12 +1137,13 @@ public class TestSpatial extends TestBase {
try (ResultSet rs = stat.executeQuery("select * from DUMMY_12")) { try (ResultSet rs = stat.executeQuery("select * from DUMMY_12")) {
assertTrue(rs.next()); assertTrue(rs.next());
} }
}
deleteDb("spatial");
} }
private void testSpatialIndexWithOrder() throws SQLException { private void testSpatialIndexWithOrder() throws SQLException {
deleteDb("spatial"); deleteDb("spatial");
Connection conn = getConnection(URL); try (Connection conn = getConnection(URL)) {
Statement stat = conn.createStatement(); Statement stat = conn.createStatement();
stat.execute("DROP TABLE IF EXISTS BUILDINGS;" + stat.execute("DROP TABLE IF EXISTS BUILDINGS;" +
"CREATE TABLE BUILDINGS (PK serial, THE_GEOM geometry);" + "CREATE TABLE BUILDINGS (PK serial, THE_GEOM geometry);" +
...@@ -1156,4 +1157,6 @@ public class TestSpatial extends TestBase { ...@@ -1156,4 +1157,6 @@ public class TestSpatial extends TestBase {
assertTrue(rs.getString(1).contains("PRIMARY_KEY")); assertTrue(rs.getString(1).contains("PRIMARY_KEY"));
} }
} }
deleteDb("spatial");
}
} }
...@@ -45,6 +45,7 @@ public class TestConnection extends TestBase { ...@@ -45,6 +45,7 @@ public class TestConnection extends TestBase {
assertThrows(SQLClientInfoException.class, conn).setClientInfo("numServers", "SomeValue"); assertThrows(SQLClientInfoException.class, conn).setClientInfo("numServers", "SomeValue");
assertThrows(SQLClientInfoException.class, conn).setClientInfo("server23", "SomeValue"); assertThrows(SQLClientInfoException.class, conn).setClientInfo("server23", "SomeValue");
conn.close();
} }
private void testSetUnsupportedClientInfoProperties() throws SQLException { private void testSetUnsupportedClientInfoProperties() throws SQLException {
...@@ -54,6 +55,7 @@ public class TestConnection extends TestBase { ...@@ -54,6 +55,7 @@ public class TestConnection extends TestBase {
properties.put("ClientUser", "someUser"); properties.put("ClientUser", "someUser");
assertThrows(SQLClientInfoException.class, conn).setClientInfo(properties); assertThrows(SQLClientInfoException.class, conn).setClientInfo(properties);
conn.close();
} }
private void testSetSupportedClientInfoProperties() throws SQLException { private void testSetSupportedClientInfoProperties() throws SQLException {
...@@ -67,6 +69,7 @@ public class TestConnection extends TestBase { ...@@ -67,6 +69,7 @@ public class TestConnection extends TestBase {
assertNull(conn.getClientInfo("ApplicationName")); assertNull(conn.getClientInfo("ApplicationName"));
// new property has been set // new property has been set
assertEquals(conn.getClientInfo("ClientUser"), "someUser"); assertEquals(conn.getClientInfo("ClientUser"), "someUser");
conn.close();
} }
private void testSetSupportedClientInfo() throws SQLException { private void testSetSupportedClientInfo() throws SQLException {
...@@ -74,17 +77,20 @@ public class TestConnection extends TestBase { ...@@ -74,17 +77,20 @@ public class TestConnection extends TestBase {
conn.setClientInfo("ApplicationName", "Connection Test"); conn.setClientInfo("ApplicationName", "Connection Test");
assertEquals(conn.getClientInfo("ApplicationName"), "Connection Test"); assertEquals(conn.getClientInfo("ApplicationName"), "Connection Test");
conn.close();
} }
private void testSetUnsupportedClientInfo() throws SQLException { private void testSetUnsupportedClientInfo() throws SQLException {
Connection conn = getConnection("clientInfoDB2;MODE=DB2"); Connection conn = getConnection("clientInfoDB2;MODE=DB2");
assertThrows(SQLClientInfoException.class, conn).setClientInfo( assertThrows(SQLClientInfoException.class, conn).setClientInfo(
"UnsupportedName", "SomeValue"); "UnsupportedName", "SomeValue");
conn.close();
} }
private void testGetUnsupportedClientInfo() throws SQLException { private void testGetUnsupportedClientInfo() throws SQLException {
Connection conn = getConnection("clientInfo"); Connection conn = getConnection("clientInfo");
assertNull(conn.getClientInfo("UnknownProperty")); assertNull(conn.getClientInfo("UnknownProperty"));
conn.close();
} }
private void testSetGetSchema() throws SQLException { private void testSetGetSchema() throws SQLException {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论