deleteDb("sessionsLocks");
}
private void testLocks() throws SQLException {
deleteDb("sessionsLocks");
Connection conn = getConnection("sessionsLocks;MULTI_THREADED=1");
Statement stat = conn.createStatement();
ResultSet rs;
rs = stat.executeQuery("select * from information_schema.locks order by session_id");
assertFalse(rs.next());
Connection conn2 = getConnection("sessionsLocks");
Statement stat2 = conn2.createStatement();
stat2.execute("create table test(id int primary key, name varchar)");
conn2.setAutoCommit(false);
stat2.execute("insert into test values(1, 'Hello')");
rs = stat.executeQuery("select * from information_schema.locks order by session_id");
rs.next();
assertEquals("PUBLIC", rs.getString("TABLE_SCHEMA"));
assertEquals("TEST", rs.getString("TABLE_NAME"));
rs.getString("SESSION_ID");
if (config.mvcc) {
assertEquals("READ", rs.getString("LOCK_TYPE"));
} else {
assertEquals("WRITE", rs.getString("LOCK_TYPE"));
}
assertFalse(rs.next());
conn2.commit();
conn2.setTransactionIsolation(Connection.TRANSACTION_SERIALIZABLE);
stat2.execute("SELECT * FROM TEST");
rs = stat.executeQuery("select * from information_schema.locks order by session_id");
if (!config.mvcc) {
rs.next();
assertEquals("PUBLIC", rs.getString("TABLE_SCHEMA"));
assertEquals("TEST", rs.getString("TABLE_NAME"));
rs.getString("SESSION_ID");
assertEquals("READ", rs.getString("LOCK_TYPE"));
}
assertFalse(rs.next());
conn2.commit();
rs = stat.executeQuery("select * from information_schema.locks order by session_id");
assertFalse(rs.next());
conn.close();
conn2.close();
}