提交 87792db5 authored 作者: Noel Grandin's avatar Noel Grandin

improve unit test cleanup

上级 7f3e1936
...@@ -245,71 +245,74 @@ public class TestFullText extends TestBase { ...@@ -245,71 +245,74 @@ public class TestFullText extends TestBase {
trace("Testing multithreaded " + prefix); trace("Testing multithreaded " + prefix);
deleteDb("fullText"); deleteDb("fullText");
ArrayList<Connection> connList = new ArrayList<Connection>(); ArrayList<Connection> connList = new ArrayList<Connection>();
int len = 2; try {
Task[] task = new Task[len]; int len = 2;
for (int i = 0; i < len; i++) { Task[] task = new Task[len];
// final Connection conn = for (int i = 0; i < len; i++) {
// getConnection("fullText;MULTI_THREADED=1;LOCK_TIMEOUT=10000"); // final Connection conn =
final Connection conn = getConnection("fullText", connList); // getConnection("fullText;MULTI_THREADED=1;LOCK_TIMEOUT=10000");
Statement stat = conn.createStatement(); final Connection conn = getConnection("fullText", connList);
initFullText(stat, lucene); Statement stat = conn.createStatement();
initFullText(stat, lucene); initFullText(stat, lucene);
final String tableName = "TEST" + i; initFullText(stat, lucene);
stat.execute("CREATE TABLE " + tableName + final String tableName = "TEST" + i;
"(ID INT PRIMARY KEY, DATA VARCHAR)"); stat.execute("CREATE TABLE " + tableName +
stat.execute("CALL " + prefix + "(ID INT PRIMARY KEY, DATA VARCHAR)");
"_CREATE_INDEX('PUBLIC', '" + tableName + "', NULL)"); stat.execute("CALL " + prefix +
task[i] = new Task() { "_CREATE_INDEX('PUBLIC', '" + tableName + "', NULL)");
@Override task[i] = new Task() {
public void call() throws SQLException { @Override
trace("starting thread " + Thread.currentThread()); public void call() throws SQLException {
PreparedStatement prep = conn.prepareStatement( trace("starting thread " + Thread.currentThread());
"INSERT INTO " + tableName + " VALUES(?, ?)"); PreparedStatement prep = conn.prepareStatement(
Statement stat = conn.createStatement(); "INSERT INTO " + tableName + " VALUES(?, ?)");
Random random = new Random(); Statement stat = conn.createStatement();
int x = 0; Random random = new Random();
while (!stop) { int x = 0;
trace("stop = " + stop + " for " + Thread.currentThread()); while (!stop) {
StringBuilder buff = new StringBuilder(); trace("stop = " + stop + " for " + Thread.currentThread());
for (int j = 0; j < 1000; j++) { StringBuilder buff = new StringBuilder();
buff.append(" ").append(random.nextInt(10000)); for (int j = 0; j < 1000; j++) {
buff.append(" x").append(j); buff.append(" ").append(random.nextInt(10000));
buff.append(" ").append(KNOWN_WORDS[j % KNOWN_WORDS.length]); buff.append(" x").append(j);
buff.append(" ").append(KNOWN_WORDS[j % KNOWN_WORDS.length]);
}
prep.setInt(1, x);
prep.setString(2, buff.toString());
prep.execute();
x++;
for (String knownWord : KNOWN_WORDS) {
trace("searching for " + knownWord + " with " +
Thread.currentThread());
ResultSet rs = stat.executeQuery("SELECT * FROM " +
prefix + "_SEARCH('" + knownWord +
"', 0, 0)");
assertTrue(rs.next());
}
} }
prep.setInt(1, x); trace("closing connection");
prep.setString(2, buff.toString()); if (!config.memory) {
prep.execute(); conn.close();
x++;
for (String knownWord : KNOWN_WORDS) {
trace("searching for " + knownWord + " with " +
Thread.currentThread());
ResultSet rs = stat.executeQuery("SELECT * FROM " +
prefix + "_SEARCH('" + knownWord +
"', 0, 0)");
assertTrue(rs.next());
} }
trace("completed thread " + Thread.currentThread());
} }
trace("closing connection"); };
if (!config.memory) { }
conn.close(); for (Task t : task) {
} t.execute();
trace("completed thread " + Thread.currentThread()); }
} trace("sleeping");
}; Thread.sleep(1000);
}
for (Task t : task) { trace("setting stop to true");
t.execute(); for (Task t : task) {
} trace("joining " + t);
trace("sleeping"); t.get();
Thread.sleep(1000); trace("done joining " + t);
}
trace("setting stop to true"); } finally {
for (Task t : task) { close(connList);
trace("joining " + t);
t.get();
trace("done joining " + t);
} }
close(connList);
} }
private void testStreamLob() throws SQLException { private void testStreamLob() throws SQLException {
......
...@@ -64,43 +64,43 @@ public class TestRights extends TestBase { ...@@ -64,43 +64,43 @@ public class TestRights extends TestBase {
private void testLinkedTableMeta() throws SQLException { private void testLinkedTableMeta() throws SQLException {
deleteDb("rights"); deleteDb("rights");
Connection conn = getConnection("rights"); try (Connection conn = getConnection("rights")) {
stat = conn.createStatement(); stat = conn.createStatement();
stat.execute("create user test password 'test'"); stat.execute("create user test password 'test'");
stat.execute("create linked table test" + stat.execute("create linked table test" +
"(null, 'jdbc:h2:mem:', 'sa', 'sa', 'DUAL')"); "(null, 'jdbc:h2:mem:', 'sa', 'sa', 'DUAL')");
// password is invisible to non-admin // password is invisible to non-admin
Connection conn2 = getConnection( Connection conn2 = getConnection(
"rights", "test", getPassword("test")); "rights", "test", getPassword("test"));
Statement stat2 = conn2.createStatement(); Statement stat2 = conn2.createStatement();
ResultSet rs = stat2.executeQuery( ResultSet rs = stat2.executeQuery(
"select * from information_schema.tables " + "select * from information_schema.tables " +
"where table_name = 'TEST'"); "where table_name = 'TEST'");
assertTrue(rs.next()); assertTrue(rs.next());
ResultSetMetaData meta = rs.getMetaData(); ResultSetMetaData meta = rs.getMetaData();
for (int i = 1; i <= meta.getColumnCount(); i++) { for (int i = 1; i <= meta.getColumnCount(); i++) {
String s = rs.getString(i); String s = rs.getString(i);
assertFalse(s != null && s.contains("'sa'")); assertFalse(s != null && s.contains("'sa'"));
} }
conn2.close(); conn2.close();
// password is visible to admin // password is visible to admin
rs = stat.executeQuery( rs = stat.executeQuery(
"select * from information_schema.tables " + "select * from information_schema.tables " +
"where table_name = 'TEST'"); "where table_name = 'TEST'");
assertTrue(rs.next()); assertTrue(rs.next());
meta = rs.getMetaData(); meta = rs.getMetaData();
boolean foundPassword = false; boolean foundPassword = false;
for (int i = 1; i <= meta.getColumnCount(); i++) { for (int i = 1; i <= meta.getColumnCount(); i++) {
String s = rs.getString(i); String s = rs.getString(i);
if (s != null && s.contains("'sa'")) { if (s != null && s.contains("'sa'")) {
foundPassword = true; foundPassword = true;
}
} }
assertTrue(foundPassword);
conn2.close();
stat.execute("drop table test");
} }
assertTrue(foundPassword);
conn2.close();
stat.execute("drop table test");
conn.close();
} }
private void testGrantMore() throws SQLException { private void testGrantMore() throws SQLException {
......
...@@ -111,17 +111,16 @@ public class TestMVTableEngine extends TestBase { ...@@ -111,17 +111,16 @@ public class TestMVTableEngine extends TestBase {
private void testLobReuse() throws Exception { private void testLobReuse() throws Exception {
deleteDb(getTestName()); deleteDb(getTestName());
Connection conn = getConnection(getTestName()); Connection conn1 = getConnection(getTestName());
Statement stat = conn.createStatement(); Statement stat = conn1.createStatement();
stat.execute("create table test(id identity primary key, lob clob)"); stat.execute("create table test(id identity primary key, lob clob)");
conn.close();
byte[] buffer = new byte[8192]; byte[] buffer = new byte[8192];
for (int i = 0; i < 20; i++) { for (int i = 0; i < 20; i++) {
conn = getConnection(getTestName()); Connection conn2 = getConnection(getTestName());
stat = conn.createStatement(); stat = conn2.createStatement();
stat.execute("insert into test(lob) select space(1025) from system_range(1, 10)"); stat.execute("insert into test(lob) select space(1025) from system_range(1, 10)");
stat.execute("delete from test where random() > 0.5"); stat.execute("delete from test where random() > 0.5");
ResultSet rs = conn.createStatement().executeQuery( ResultSet rs = conn2.createStatement().executeQuery(
"select lob from test"); "select lob from test");
while (rs.next()) { while (rs.next()) {
InputStream is = rs.getBinaryStream(1); InputStream is = rs.getBinaryStream(1);
...@@ -129,8 +128,9 @@ public class TestMVTableEngine extends TestBase { ...@@ -129,8 +128,9 @@ public class TestMVTableEngine extends TestBase {
// ignore // ignore
} }
} }
conn.close(); conn2.close();
} }
conn1.close();
} }
private void testShutdownDuringLobCreation() throws Exception { private void testShutdownDuringLobCreation() throws Exception {
...@@ -175,6 +175,7 @@ public class TestMVTableEngine extends TestBase { ...@@ -175,6 +175,7 @@ public class TestMVTableEngine extends TestBase {
stat.execute("shutdown immediately"); stat.execute("shutdown immediately");
Exception ex = t.getException(); Exception ex = t.getException();
assertTrue(ex != null); assertTrue(ex != null);
ex.printStackTrace();
try { try {
conn.close(); conn.close();
} catch (Exception e) { } catch (Exception e) {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论