提交 621b8687 authored 作者: noelgrandin's avatar noelgrandin

move the DatabaseEventLister into inner classes - makes it easier to see what…

move the DatabaseEventLister into inner classes - makes it easier to see what belongs to what, especially when some of the the overriden methods are very similar to methods in the superclass (TestBase)
上级 2084502c
/* /*
* Copyright 2004-2013 H2 Group. Multiple-Licensed under the H2 License, * Copyright 2004-2013 H2 Group. Multiple-Licensed under the H2 License, Version
* Version 1.0, and under the Eclipse Public License, Version 1.0 * 1.0, and under the Eclipse Public License, Version 1.0
* (http://h2database.com/html/license.html). * (http://h2database.com/html/license.html). Initial Developer: H2 Group
* Initial Developer: H2 Group
*/ */
package org.h2.test.db; package org.h2.test.db;
...@@ -10,7 +9,6 @@ import java.sql.Connection; ...@@ -10,7 +9,6 @@ import java.sql.Connection;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.sql.Statement; import java.sql.Statement;
import org.h2.api.DatabaseEventListener; import org.h2.api.DatabaseEventListener;
import org.h2.test.TestBase; import org.h2.test.TestBase;
import org.h2.util.Task; import org.h2.util.Task;
...@@ -18,13 +16,13 @@ import org.h2.util.Task; ...@@ -18,13 +16,13 @@ import org.h2.util.Task;
/** /**
* Multi-connection tests. * Multi-connection tests.
*/ */
public class TestMultiConn extends TestBase implements DatabaseEventListener { public class TestMultiConn extends TestBase {
private static int wait; private static int wait;
/** /**
* Run just this test. * Run just this test.
* *
* @param a ignored * @param a ignored
*/ */
public static void main(String... a) throws Exception { public static void main(String... a) throws Exception {
...@@ -141,7 +139,7 @@ public class TestMultiConn extends TestBase implements DatabaseEventListener { ...@@ -141,7 +139,7 @@ public class TestMultiConn extends TestBase implements DatabaseEventListener {
conn.createStatement().execute("INSERT INTO TEST VALUES(0, 'Hello'), (1, 'World')"); conn.createStatement().execute("INSERT INTO TEST VALUES(0, 'Hello'), (1, 'World')");
conn.createStatement().execute("SHUTDOWN"); conn.createStatement().execute("SHUTDOWN");
conn.close(); conn.close();
final String listener = getClass().getName(); final String listener = MyDatabaseEventListener.class.getName();
Runnable r = new Runnable() { Runnable r = new Runnable() {
@Override @Override
public void run() { public void run() {
...@@ -162,27 +160,6 @@ public class TestMultiConn extends TestBase implements DatabaseEventListener { ...@@ -162,27 +160,6 @@ public class TestMultiConn extends TestBase implements DatabaseEventListener {
thread.join(); thread.join();
} }
@Override
public void exceptionThrown(SQLException e, String sql) {
// do nothing
}
@Override
public void setProgress(int state, String name, int x, int max) {
if (wait > 0) {
try {
Thread.sleep(wait);
} catch (InterruptedException e) {
TestBase.logError("sleep", e);
}
}
}
@Override
public void closingDatabase() {
// do nothing
}
private void testCommitRollback() throws SQLException { private void testCommitRollback() throws SQLException {
deleteDb("multiConn"); deleteDb("multiConn");
Connection c1 = getConnection("multiConn"); Connection c1 = getConnection("multiConn");
...@@ -222,14 +199,38 @@ public class TestMultiConn extends TestBase implements DatabaseEventListener { ...@@ -222,14 +199,38 @@ public class TestMultiConn extends TestBase implements DatabaseEventListener {
} }
@Override public static final class MyDatabaseEventListener implements DatabaseEventListener {
public void init(String url) {
// do nothing
}
@Override @Override
public void opened() { public void exceptionThrown(SQLException e, String sql) {
// do nothing // do nothing
}
@Override
public void setProgress(int state, String name, int x, int max) {
if (wait > 0) {
try {
Thread.sleep(wait);
} catch (InterruptedException e) {
TestBase.logError("sleep", e);
}
}
}
@Override
public void closingDatabase() {
// do nothing
}
@Override
public void init(String url) {
// do nothing
}
@Override
public void opened() {
// do nothing
}
} }
} }
/* /*
* Copyright 2004-2013 H2 Group. Multiple-Licensed under the H2 License, * Copyright 2004-2013 H2 Group. Multiple-Licensed under the H2 License, Version
* Version 1.0, and under the Eclipse Public License, Version 1.0 * 1.0, and under the Eclipse Public License, Version 1.0
* (http://h2database.com/html/license.html). * (http://h2database.com/html/license.html). Initial Developer: H2 Group
* Initial Developer: H2 Group
*/ */
package org.h2.test.db; package org.h2.test.db;
...@@ -24,13 +23,13 @@ import org.h2.util.Task; ...@@ -24,13 +23,13 @@ import org.h2.util.Task;
/** /**
* Tests opening and closing a database. * Tests opening and closing a database.
*/ */
public class TestOpenClose extends TestBase implements DatabaseEventListener { public class TestOpenClose extends TestBase {
private int nextId = 10; private int nextId = 10;
/** /**
* Run just this test. * Run just this test.
* *
* @param a ignored * @param a ignored
*/ */
public static void main(String... a) throws Exception { public static void main(String... a) throws Exception {
...@@ -55,8 +54,8 @@ public class TestOpenClose extends TestBase implements DatabaseEventListener { ...@@ -55,8 +54,8 @@ public class TestOpenClose extends TestBase implements DatabaseEventListener {
deleteDb("openClose"); deleteDb("openClose");
Connection conn; Connection conn;
conn = getConnection("jdbc:h2:" + getBaseDir() + "/openClose;FILE_LOCK=FS"); conn = getConnection("jdbc:h2:" + getBaseDir() + "/openClose;FILE_LOCK=FS");
assertThrows(ErrorCode.DATABASE_ALREADY_OPEN_1, this). assertThrows(ErrorCode.DATABASE_ALREADY_OPEN_1, this).getConnection(
getConnection("jdbc:h2:" + getBaseDir() + "/openClose;FILE_LOCK=FS;OPEN_NEW=TRUE"); "jdbc:h2:" + getBaseDir() + "/openClose;FILE_LOCK=FS;OPEN_NEW=TRUE");
conn.close(); conn.close();
} }
...@@ -73,8 +72,7 @@ public class TestOpenClose extends TestBase implements DatabaseEventListener { ...@@ -73,8 +72,7 @@ public class TestOpenClose extends TestBase implements DatabaseEventListener {
c.position(c.size() * 2 - 1); c.position(c.size() * 2 - 1);
c.write(ByteBuffer.wrap(new byte[1])); c.write(ByteBuffer.wrap(new byte[1]));
c.close(); c.close();
assertThrows(ErrorCode.IO_EXCEPTION_2, this). assertThrows(ErrorCode.IO_EXCEPTION_2, this).getConnection("jdbc:h2:split:18:" + getBaseDir() + "/openClose2");
getConnection("jdbc:h2:split:18:" + getBaseDir() + "/openClose2");
FileUtils.delete("split:" + getBaseDir() + "/openClose2.h2.db"); FileUtils.delete("split:" + getBaseDir() + "/openClose2.h2.db");
} }
...@@ -127,8 +125,7 @@ public class TestOpenClose extends TestBase implements DatabaseEventListener { ...@@ -127,8 +125,7 @@ public class TestOpenClose extends TestBase implements DatabaseEventListener {
deleteDb("openClose"); deleteDb("openClose");
String user = getUser(), password = getPassword(); String user = getUser(), password = getPassword();
String url = getURL("openClose;DATABASE_EVENT_LISTENER='" + TestOpenClose.class.getName() String url = getURL("openClose;DATABASE_EVENT_LISTENER='" + MyDatabaseEventListener.class.getName() + "'", true);
+ "'", true);
Connection conn = DriverManager.getConnection(url, user, password); Connection conn = DriverManager.getConnection(url, user, password);
Statement stat = conn.createStatement(); Statement stat = conn.createStatement();
stat.execute("CREATE TABLE TEST(ID IDENTITY, NAME VARCHAR)"); stat.execute("CREATE TABLE TEST(ID IDENTITY, NAME VARCHAR)");
...@@ -204,51 +201,54 @@ public class TestOpenClose extends TestBase implements DatabaseEventListener { ...@@ -204,51 +201,54 @@ public class TestOpenClose extends TestBase implements DatabaseEventListener {
return nextId++; return nextId++;
} }
@Override public static final class MyDatabaseEventListener implements DatabaseEventListener {
public void exceptionThrown(SQLException e, String sql) {
throw new AssertionError("unexpected: " + e + " sql: " + sql);
}
@Override @Override
public void setProgress(int state, String name, int current, int max) { public void exceptionThrown(SQLException e, String sql) {
String stateName; throw new AssertionError("unexpected: " + e + " sql: " + sql);
switch (state) { }
case STATE_SCAN_FILE:
stateName = "Scan " + name + " " + current + "/" + max; @Override
if (current > 0) { public void setProgress(int state, String name, int current, int max) {
throw new AssertionError("unexpected: " + stateName); String stateName;
} switch (state) {
break; case STATE_SCAN_FILE:
case STATE_STATEMENT_START: stateName = "Scan " + name + " " + current + "/" + max;
break; if (current > 0) {
case STATE_CREATE_INDEX: throw new AssertionError("unexpected: " + stateName);
stateName = "Create Index " + name + " " + current + "/" + max; }
if (!"SYS:SYS_ID".equals(name)) { break;
throw new AssertionError("unexpected: " + stateName); case STATE_STATEMENT_START:
break;
case STATE_CREATE_INDEX:
stateName = "Create Index " + name + " " + current + "/" + max;
if (!"SYS:SYS_ID".equals(name)) {
throw new AssertionError("unexpected: " + stateName);
}
break;
case STATE_RECOVER:
stateName = "Recover " + current + "/" + max;
break;
default:
stateName = "?";
} }
break; // System.out.println(": " + stateName);
case STATE_RECOVER:
stateName = "Recover " + current + "/" + max;
break;
default:
stateName = "?";
} }
// System.out.println(": " + stateName);
}
@Override @Override
public void closingDatabase() { public void closingDatabase() {
// nothing to do // nothing to do
} }
@Override @Override
public void init(String url) { public void init(String url) {
// nothing to do // nothing to do
} }
@Override @Override
public void opened() { public void opened() {
// nothing to do // nothing to do
}
} }
} }
...@@ -20,7 +20,7 @@ import org.h2.test.TestBase; ...@@ -20,7 +20,7 @@ import org.h2.test.TestBase;
/** /**
* Tests the DatabaseEventListener interface. * Tests the DatabaseEventListener interface.
*/ */
public class TestDatabaseEventListener extends TestBase implements DatabaseEventListener { public class TestDatabaseEventListener extends TestBase {
private static boolean calledOpened, calledClosingDatabase, calledScan, calledCreateIndex; private static boolean calledOpened, calledClosingDatabase, calledScan, calledCreateIndex;
private static boolean calledStatementStart, calledStatementEnd, calledStatementProgress; private static boolean calledStatementStart, calledStatementEnd, calledStatementProgress;
...@@ -136,7 +136,7 @@ public class TestDatabaseEventListener extends TestBase implements DatabaseEvent ...@@ -136,7 +136,7 @@ public class TestDatabaseEventListener extends TestBase implements DatabaseEvent
conn = DriverManager.getConnection(url, p); conn = DriverManager.getConnection(url, p);
conn.close(); conn.close();
calledCreateIndex = false; calledCreateIndex = false;
p.put("DATABASE_EVENT_LISTENER", getClass().getName()); p.put("DATABASE_EVENT_LISTENER", MyDatabaseEventListener.class.getName());
conn = org.h2.Driver.load().connect(url, p); conn = org.h2.Driver.load().connect(url, p);
conn.close(); conn.close();
assertTrue(!calledCreateIndex); assertTrue(!calledCreateIndex);
...@@ -168,7 +168,7 @@ public class TestDatabaseEventListener extends TestBase implements DatabaseEvent ...@@ -168,7 +168,7 @@ public class TestDatabaseEventListener extends TestBase implements DatabaseEvent
stat.execute("insert into test select 1"); stat.execute("insert into test select 1");
conn.close(); conn.close();
calledCreateIndex = false; calledCreateIndex = false;
p.put("DATABASE_EVENT_LISTENER", getClass().getName()); p.put("DATABASE_EVENT_LISTENER", MyDatabaseEventListener.class.getName());
conn = org.h2.Driver.load().connect(url, p); conn = org.h2.Driver.load().connect(url, p);
conn.close(); conn.close();
assertTrue(!calledCreateIndex); assertTrue(!calledCreateIndex);
...@@ -195,7 +195,7 @@ public class TestDatabaseEventListener extends TestBase implements DatabaseEvent ...@@ -195,7 +195,7 @@ public class TestDatabaseEventListener extends TestBase implements DatabaseEvent
calledOpened = false; calledOpened = false;
calledScan = false; calledScan = false;
p.put("DATABASE_EVENT_LISTENER", getClass().getName()); p.put("DATABASE_EVENT_LISTENER", MyDatabaseEventListener.class.getName());
conn = org.h2.Driver.load().connect(url, p); conn = org.h2.Driver.load().connect(url, p);
conn.close(); conn.close();
if (calledOpened) { if (calledOpened) {
...@@ -209,7 +209,7 @@ public class TestDatabaseEventListener extends TestBase implements DatabaseEvent ...@@ -209,7 +209,7 @@ public class TestDatabaseEventListener extends TestBase implements DatabaseEvent
p.setProperty("password", "sa"); p.setProperty("password", "sa");
calledOpened = false; calledOpened = false;
calledClosingDatabase = false; calledClosingDatabase = false;
p.put("DATABASE_EVENT_LISTENER", getClass().getName()); p.put("DATABASE_EVENT_LISTENER", MyDatabaseEventListener.class.getName());
org.h2.Driver.load(); org.h2.Driver.load();
String url = "jdbc:h2:mem:databaseEventListener"; String url = "jdbc:h2:mem:databaseEventListener";
Connection conn = org.h2.Driver.load().connect(url, p); Connection conn = org.h2.Driver.load().connect(url, p);
...@@ -225,7 +225,7 @@ public class TestDatabaseEventListener extends TestBase implements DatabaseEvent ...@@ -225,7 +225,7 @@ public class TestDatabaseEventListener extends TestBase implements DatabaseEvent
calledStatementStart = false; calledStatementStart = false;
calledStatementEnd = false; calledStatementEnd = false;
calledStatementProgress = false; calledStatementProgress = false;
p.put("DATABASE_EVENT_LISTENER", getClass().getName()); p.put("DATABASE_EVENT_LISTENER", MyDatabaseEventListener.class.getName());
org.h2.Driver.load(); org.h2.Driver.load();
String url = "jdbc:h2:mem:databaseEventListener"; String url = "jdbc:h2:mem:databaseEventListener";
Connection conn = org.h2.Driver.load().connect(url, p); Connection conn = org.h2.Driver.load().connect(url, p);
...@@ -238,51 +238,55 @@ public class TestDatabaseEventListener extends TestBase implements DatabaseEvent ...@@ -238,51 +238,55 @@ public class TestDatabaseEventListener extends TestBase implements DatabaseEvent
assertTrue(calledStatementProgress); assertTrue(calledStatementProgress);
} }
@Override public static final class MyDatabaseEventListener implements DatabaseEventListener {
public void closingDatabase() {
calledClosingDatabase = true; @Override
} public void closingDatabase() {
calledClosingDatabase = true;
@Override }
public void exceptionThrown(SQLException e, String sql) {
// nothing to do
}
@Override @Override
public void init(String url) { public void exceptionThrown(SQLException e, String sql) {
// nothing to do // nothing to do
} }
@Override @Override
public void opened() { public void init(String url) {
calledOpened = true; // nothing to do
} }
@Override @Override
public void setProgress(int state, String name, int x, int max) { public void opened() {
if (state == DatabaseEventListener.STATE_SCAN_FILE) { calledOpened = true;
calledScan = true;
} }
if (state == DatabaseEventListener.STATE_CREATE_INDEX) {
if (!name.startsWith("SYS:")) { @Override
calledCreateIndex = true; public void setProgress(int state, String name, int x, int max) {
if (state == DatabaseEventListener.STATE_SCAN_FILE) {
calledScan = true;
} }
} if (state == DatabaseEventListener.STATE_CREATE_INDEX) {
if (state == STATE_STATEMENT_START) { if (!name.startsWith("SYS:")) {
if (name.equals("select * from test")) { calledCreateIndex = true;
calledStatementStart = true; }
} }
} if (state == STATE_STATEMENT_START) {
if (state == STATE_STATEMENT_END) { if (name.equals("select * from test")) {
if (name.equals("select * from test")) { calledStatementStart = true;
calledStatementEnd = true; }
} }
} if (state == STATE_STATEMENT_END) {
if (state == STATE_STATEMENT_PROGRESS) { if (name.equals("select * from test")) {
if (name.equals("select * from test")) { calledStatementEnd = true;
calledStatementProgress = true; }
}
if (state == STATE_STATEMENT_PROGRESS) {
if (name.equals("select * from test")) {
calledStatementProgress = true;
}
} }
} }
} }
} }
...@@ -20,7 +20,7 @@ import org.h2.tools.Server; ...@@ -20,7 +20,7 @@ import org.h2.tools.Server;
/** /**
* Tests automatic embedded/server mode. * Tests automatic embedded/server mode.
*/ */
public class TestAutoReconnect extends TestBase implements DatabaseEventListener { public class TestAutoReconnect extends TestBase {
private String url; private String url;
private boolean autoServer; private boolean autoServer;
...@@ -95,7 +95,7 @@ public class TestAutoReconnect extends TestBase implements DatabaseEventListener ...@@ -95,7 +95,7 @@ public class TestAutoReconnect extends TestBase implements DatabaseEventListener
} }
// test the database event listener // test the database event listener
conn = DriverManager.getConnection(url + ";DATABASE_EVENT_LISTENER='" + getClass().getName() + "'"); conn = DriverManager.getConnection(url + ";DATABASE_EVENT_LISTENER='" + MyDatabaseEventListener.class.getName() + "'");
conn.close(); conn.close();
Statement stat; Statement stat;
...@@ -176,29 +176,30 @@ public class TestAutoReconnect extends TestBase implements DatabaseEventListener ...@@ -176,29 +176,30 @@ public class TestAutoReconnect extends TestBase implements DatabaseEventListener
} }
} }
@Override public static final class MyDatabaseEventListener implements DatabaseEventListener {
public void closingDatabase() { @Override
// ignore public void closingDatabase() {
} // ignore
}
@Override @Override
public void exceptionThrown(SQLException e, String sql) { public void exceptionThrown(SQLException e, String sql) {
// ignore // ignore
} }
@Override @Override
public void init(String u) { public void init(String u) {
// ignore // ignore
} }
@Override @Override
public void opened() { public void opened() {
// ignore // ignore
} }
@Override @Override
public void setProgress(int state, String name, int x, int max) { public void setProgress(int state, String name, int x, int max) {
// ignore // ignore
}
} }
} }
...@@ -20,7 +20,7 @@ import org.h2.test.utils.SelfDestructor; ...@@ -20,7 +20,7 @@ import org.h2.test.utils.SelfDestructor;
* Tests the flag db_close_on_exit. * Tests the flag db_close_on_exit.
* A new process is started. * A new process is started.
*/ */
public class TestExit extends TestBase implements DatabaseEventListener { public class TestExit extends TestBase {
public static Connection conn; public static Connection conn;
...@@ -92,11 +92,11 @@ public class TestExit extends TestBase implements DatabaseEventListener { ...@@ -92,11 +92,11 @@ public class TestExit extends TestBase implements DatabaseEventListener {
String url = ""; String url = "";
switch (action) { switch (action) {
case OPEN_WITH_CLOSE_ON_EXIT: case OPEN_WITH_CLOSE_ON_EXIT:
url = "jdbc:h2:" + getBaseDir() + "/exit;database_event_listener='" + getClass().getName() url = "jdbc:h2:" + getBaseDir() + "/exit;database_event_listener='" + MyDatabaseEventListener.class.getName()
+ "';db_close_on_exit=true"; + "';db_close_on_exit=true";
break; break;
case OPEN_WITHOUT_CLOSE_ON_EXIT: case OPEN_WITHOUT_CLOSE_ON_EXIT:
url = "jdbc:h2:" + getBaseDir() + "/exit;database_event_listener='" + getClass().getName() url = "jdbc:h2:" + getBaseDir() + "/exit;database_event_listener='" + MyDatabaseEventListener.class.getName()
+ "';db_close_on_exit=false"; + "';db_close_on_exit=false";
break; break;
default: default:
...@@ -111,37 +111,41 @@ public class TestExit extends TestBase implements DatabaseEventListener { ...@@ -111,37 +111,41 @@ public class TestExit extends TestBase implements DatabaseEventListener {
return DriverManager.getConnection(url, "sa", ""); return DriverManager.getConnection(url, "sa", "");
} }
@Override private static File getClosedFile() {
public void exceptionThrown(SQLException e, String sql) { return new File(TestBase.BASE_TEST_DIR + "/closed.txt");
// nothing to do
} }
@Override public static final class MyDatabaseEventListener implements DatabaseEventListener {
public void closingDatabase() {
try { @Override
getClosedFile().createNewFile(); public void exceptionThrown(SQLException e, String sql) {
} catch (IOException e) { // nothing to do
TestBase.logError("error", e);
} }
}
private static File getClosedFile() { @Override
return new File(TestBase.BASE_TEST_DIR + "/closed.txt"); public void closingDatabase() {
} try {
getClosedFile().createNewFile();
} catch (IOException e) {
TestBase.logError("error", e);
}
}
@Override @Override
public void setProgress(int state, String name, int x, int max) { public void setProgress(int state, String name, int x, int max) {
// nothing to do // nothing to do
} }
@Override @Override
public void init(String url) { public void init(String url) {
// nothing to do // nothing to do
} }
@Override @Override
public void opened() { public void opened() {
// nothing to do // nothing to do
}
} }
} }
/* /*
* Copyright 2004-2013 H2 Group. Multiple-Licensed under the H2 License, * Copyright 2004-2013 H2 Group. Multiple-Licensed under the H2 License, Version
* Version 1.0, and under the Eclipse Public License, Version 1.0 * 1.0, and under the Eclipse Public License, Version 1.0
* (http://h2database.com/html/license.html). * (http://h2database.com/html/license.html). Initial Developer: H2 Group
* Initial Developer: H2 Group
*/ */
package org.h2.test.unit; package org.h2.test.unit;
...@@ -31,13 +30,13 @@ import org.h2.util.New; ...@@ -31,13 +30,13 @@ import org.h2.util.New;
/** /**
* Test the page store. * Test the page store.
*/ */
public class TestPageStore extends TestBase implements DatabaseEventListener { public class TestPageStore extends TestBase {
static StringBuilder eventBuffer = new StringBuilder(); static StringBuilder eventBuffer = new StringBuilder();
/** /**
* Run just this test. * Run just this test.
* *
* @param a ignored * @param a ignored
*/ */
public static void main(String... a) throws Exception { public static void main(String... a) throws Exception {
...@@ -145,11 +144,10 @@ public class TestPageStore extends TestBase implements DatabaseEventListener { ...@@ -145,11 +144,10 @@ public class TestPageStore extends TestBase implements DatabaseEventListener {
stat.execute("set max_log_size 1"); stat.execute("set max_log_size 1");
stat.execute("create table test(x varchar)"); stat.execute("create table test(x varchar)");
for (int i = 0; i < 1000; ++i) { for (int i = 0; i < 1000; ++i) {
stat.execute("insert into test values (space(2000))"); stat.execute("insert into test values (space(2000))");
} }
stat.execute("checkpoint"); stat.execute("checkpoint");
InputStream in = FileUtils.newInputStream(getBaseDir() + InputStream in = FileUtils.newInputStream(getBaseDir() + "/pageStoreLogLimitFalsePositive.trace.db");
"/pageStoreLogLimitFalsePositive.trace.db");
String s = IOUtils.readStringAndClose(new InputStreamReader(in), -1); String s = IOUtils.readStringAndClose(new InputStreamReader(in), -1);
assertFalse(s.indexOf("Transaction log could not be truncated") > 0); assertFalse(s.indexOf("Transaction log could not be truncated") > 0);
conn.close(); conn.close();
...@@ -446,11 +444,10 @@ public class TestPageStore extends TestBase implements DatabaseEventListener { ...@@ -446,11 +444,10 @@ public class TestPageStore extends TestBase implements DatabaseEventListener {
Statement stat = conn.createStatement(); Statement stat = conn.createStatement();
int size = 1500; int size = 1500;
stat.execute("call rand(1)"); stat.execute("call rand(1)");
stat.execute("create table test(id int primary key, data varchar, test int) as " + stat.execute("create table test(id int primary key, data varchar, test int) as "
"select x, '', 123 from system_range(1, " + size + ")"); + "select x, '', 123 from system_range(1, " + size + ")");
Random random = new Random(1); Random random = new Random(1);
PreparedStatement prep = conn.prepareStatement( PreparedStatement prep = conn.prepareStatement("update test set data=space(?) where id=?");
"update test set data=space(?) where id=?");
for (int i = 0; i < 2500; i++) { for (int i = 0; i < 2500; i++) {
int id = random.nextInt(size); int id = random.nextInt(size);
int newSize = random.nextInt(6000); int newSize = random.nextInt(6000);
...@@ -502,7 +499,7 @@ public class TestPageStore extends TestBase implements DatabaseEventListener { ...@@ -502,7 +499,7 @@ public class TestPageStore extends TestBase implements DatabaseEventListener {
// ignore // ignore
} }
eventBuffer.setLength(0); eventBuffer.setLength(0);
conn = getConnection(url + ";DATABASE_EVENT_LISTENER='" + getClass().getName() + "'"); conn = getConnection(url + ";DATABASE_EVENT_LISTENER='" + MyDatabaseEventListener.class.getName() + "'");
assertEquals("init;opened;", eventBuffer.toString()); assertEquals("init;opened;", eventBuffer.toString());
conn.close(); conn.close();
} }
...@@ -520,8 +517,7 @@ public class TestPageStore extends TestBase implements DatabaseEventListener { ...@@ -520,8 +517,7 @@ public class TestPageStore extends TestBase implements DatabaseEventListener {
conn.createStatement().execute("INSERT INTO TEST VALUES(1, 'Hello')"); conn.createStatement().execute("INSERT INTO TEST VALUES(1, 'Hello')");
conn.close(); conn.close();
conn = getConnection(url); conn = getConnection(url);
assertThrows(ErrorCode.DUPLICATE_KEY_1, conn.createStatement()). assertThrows(ErrorCode.DUPLICATE_KEY_1, conn.createStatement()).execute("INSERT INTO TEST VALUES(2, 'Hello')");
execute("INSERT INTO TEST VALUES(2, 'Hello')");
conn.close(); conn.close();
} }
...@@ -742,8 +738,7 @@ public class TestPageStore extends TestBase implements DatabaseEventListener { ...@@ -742,8 +738,7 @@ public class TestPageStore extends TestBase implements DatabaseEventListener {
stat.execute("INSERT INTO TEST VALUES(1)"); stat.execute("INSERT INTO TEST VALUES(1)");
conn.close(); conn.close();
conn = getConnection("pageStoreUniqueIndex"); conn = getConnection("pageStoreUniqueIndex");
assertThrows(ErrorCode.DUPLICATE_KEY_1, conn.createStatement()). assertThrows(ErrorCode.DUPLICATE_KEY_1, conn.createStatement()).execute("INSERT INTO TEST VALUES(1)");
execute("INSERT INTO TEST VALUES(1)");
conn.close(); conn.close();
} }
...@@ -761,7 +756,7 @@ public class TestPageStore extends TestBase implements DatabaseEventListener { ...@@ -761,7 +756,7 @@ public class TestPageStore extends TestBase implements DatabaseEventListener {
conn.close(); conn.close();
} }
private void testFuzzOperations() throws SQLException { private void testFuzzOperations() throws Exception {
int best = Integer.MAX_VALUE; int best = Integer.MAX_VALUE;
for (int i = 0; i < 10; i++) { for (int i = 0; i < 10; i++) {
int x = testFuzzOperationsSeed(i, 10); int x = testFuzzOperationsSeed(i, 10);
...@@ -835,43 +830,44 @@ public class TestPageStore extends TestBase implements DatabaseEventListener { ...@@ -835,43 +830,44 @@ public class TestPageStore extends TestBase implements DatabaseEventListener {
trace(" " + m); trace(" " + m);
} }
@Override public static final class MyDatabaseEventListener implements DatabaseEventListener {
public void closingDatabase() { @Override
event("closing"); public void closingDatabase() {
} event("closing");
}
@Override
public void exceptionThrown(SQLException e, String sql) {
event("exceptionThrown " + e + " " + sql);
}
@Override @Override
public void init(String url) { public void exceptionThrown(SQLException e, String sql) {
event("init"); event("exceptionThrown " + e + " " + sql);
} }
@Override @Override
public void opened() { public void init(String url) {
event("opened"); event("init");
} }
@Override @Override
public void setProgress(int state, String name, int x, int max) { public void opened() {
if (name.startsWith("SYS:SYS_ID")) { event("opened");
// ignore
return;
} }
switch (state) {
case DatabaseEventListener.STATE_STATEMENT_START: @Override
case DatabaseEventListener.STATE_STATEMENT_END: public void setProgress(int state, String name, int x, int max) {
case DatabaseEventListener.STATE_STATEMENT_PROGRESS: if (name.startsWith("SYS:SYS_ID")) {
return; // ignore
return;
}
switch (state) {
case DatabaseEventListener.STATE_STATEMENT_START:
case DatabaseEventListener.STATE_STATEMENT_END:
case DatabaseEventListener.STATE_STATEMENT_PROGRESS:
return;
}
event("setProgress " + state + " " + name + " " + x + " " + max);
} }
event("setProgress " + state + " " + name + " " + x + " " + max);
}
private static void event(String s) { private static void event(String s) {
eventBuffer.append(s).append(';'); eventBuffer.append(s).append(';');
}
} }
} }
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论