提交 b562327f authored 作者: Thomas Mueller's avatar Thomas Mueller

Tests.

上级 52184120
......@@ -272,6 +272,7 @@ See also <a href="build.html#providing_patches">Providing Patches</a>.
</li><li>Javadoc: document design patterns used
</li><li>Write an article about SQLInjection (h2/src/docsrc/html/images/SQLInjection.txt)
</li><li>Convert SQL-injection-2.txt to html document, include SQLInjection.java sample
</li><li>Support OUT parameters in user-defined procedures.
</li><li>Improve LOB in directories performance
</li><li>Web site design: http://www.igniterealtime.org/projects/openfire/index.jsp
</li><li>HSQLDB compatibility: Openfire server uses: CREATE SCHEMA PUBLIC AUTHORIZATION DBA;
......@@ -307,7 +308,6 @@ See also <a href="build.html#providing_patches">Providing Patches</a>.
</li><li>H2 Console: support CLOB/BLOB download using a link.
</li><li>Support flashback queries as in Oracle.
</li><li>Import / Export of fixed with text files.
</li><li>Support OUT parameters in user-defined procedures.
</li><li>Support getGeneratedKeys to return multiple rows when used with batch updates.
This is supported by MySQL, but not Derby. Both PostgreSQL and HSQLDB don't support getGeneratedKeys.
Also support it when using INSERT ... SELECT.
......@@ -482,6 +482,7 @@ See also <a href="build.html#providing_patches">Providing Patches</a>.
</li><li>Logback: write a native DBAppender.
</li><li>Cache size: don't use more cache than what is available.
</li><li>Use the Java service provider mechanism to register file systems and function libraries.
</li><li>Tree index: Instead of an AVL tree, use a general balanced trees or a scapegoat tree.
</li></ul>
<h2>Not Planned</h2>
......
......@@ -183,11 +183,6 @@ java org.h2.test.TestAll timer
*/
public boolean memory;
/**
* If index files should be deleted before re-opening the database.
*/
public boolean deleteIndex;
/**
* If code coverage is enabled.
*/
......@@ -292,29 +287,16 @@ java org.h2.test.TestAll timer
System.setProperty("h2.check2", "true");
/*
test recovery of large pages and transaction log
test recovery with 'trace' mode (many secondary indexes, small data rows)
improve Row.getMemorySize
maybe remove ValueHashMap
rename Page* classes
move classes to the right packages
instead of AVL trees, use general balanced trees
test Row.getMemorySize
review package and class level javadocs
TestAll deleteIndex
power failure test: larger binaries and additional index.
power failure test: larger binaries and additional indexes
(with many columns).
outer join bug
rename Page* classes
move classes to the right packages
// System.setProperty("h2.pageSize", "64");
test with small freeList pages, page size 64
test if compact always works as expected
google app engine
documentation: review package and class level javadocs
documentation: rolling review at jaqu.html
-------------
......@@ -382,14 +364,13 @@ kill -9 `jps -l | grep "org.h2.test." | cut -d " " -f 1`
} else {
cipher = "AES";
}
for (int a = 0; a < 128; a++) {
for (int a = 0; a < 64; a++) {
smallLog = (a & 1) != 0;
big = (a & 2) != 0;
networked = (a & 4) != 0;
memory = (a & 8) != 0;
ssl = (a & 16) != 0;
diskResult = (a & 32) != 0;
deleteIndex = (a & 64) != 0;
for (int trace = 0; trace < 3; trace++) {
traceLevelFile = trace;
test();
......@@ -404,7 +385,7 @@ kill -9 `jps -l | grep "org.h2.test." | cut -d " " -f 1`
private void runTests() throws SQLException {
jdk14 = true;
smallLog = big = networked = memory = ssl = false;
diskResult = deleteIndex = traceSystemOut = diskUndo = false;
diskResult = traceSystemOut = diskUndo = false;
mvcc = traceTest = stopOnError = false;
traceLevelFile = throttle = 0;
cipher = null;
......@@ -421,7 +402,6 @@ kill -9 `jps -l | grep "org.h2.test." | cut -d " " -f 1`
diskUndo = true;
diskResult = true;
deleteIndex = true;
traceLevelFile = 3;
throttle = 1;
cacheType = "SOFT_LRU";
......@@ -430,7 +410,6 @@ kill -9 `jps -l | grep "org.h2.test." | cut -d " " -f 1`
diskUndo = false;
diskResult = false;
deleteIndex = false;
traceLevelFile = 1;
throttle = 0;
cacheType = null;
......@@ -693,7 +672,6 @@ kill -9 `jps -l | grep "org.h2.test." | cut -d " " -f 1`
appendIf(buff, throttle > 0, "throttle:" + throttle);
appendIf(buff, traceTest, "traceTest");
appendIf(buff, stopOnError, "stopOnError");
appendIf(buff, deleteIndex, "deleteIndex");
return buff.toString();
}
......
......@@ -191,16 +191,6 @@ public abstract class TestBase {
return getPassword("123");
}
private void deleteIndexFiles(String name) {
if (name.indexOf(";") > 0) {
name = name.substring(0, name.indexOf(';'));
}
name += ".index.db";
if (new File(name).canWrite()) {
new File(name).delete();
}
}
/**
* Get the database URL for the given database name using the current
* configuration options.
......@@ -220,9 +210,6 @@ public abstract class TestBase {
if (!name.startsWith("memFS:") && !name.startsWith(baseDir + "/")) {
name = baseDir + "/" + name;
}
if (config.deleteIndex) {
deleteIndexFiles(name);
}
}
if (config.networked) {
if (config.ssl) {
......
......@@ -40,16 +40,11 @@ public class TestReadOnly extends TestBase {
if (!config.googleAppEngine) {
testReadOnlyFiles(true);
}
if (!config.deleteIndex) {
testReadOnlyFiles(false);
}
deleteDb("readonly");
}
private void testReadOnlyDbCreate() throws SQLException {
if (config.deleteIndex) {
return;
}
deleteDb("readonly");
Connection conn = getConnection("readonly");
conn.close();
......
......@@ -21,6 +21,7 @@ import javax.transaction.xa.XAResource;
import javax.transaction.xa.Xid;
import org.h2.jdbcx.JdbcDataSource;
import org.h2.jdbcx.JdbcDataSourceFactory;
import org.h2.jdbcx.JdbcXAConnection;
import org.h2.test.TestBase;
/**
......@@ -96,10 +97,19 @@ public class TestDataSource extends TestBase {
private void testXAConnection() throws Exception {
deleteDb("dataSource");
JdbcDataSource ds = new JdbcDataSource();
ds.setURL(getURL("dataSource", true));
ds.setUser(getUser());
String url = getURL("dataSource", true);
String user = getUser();
ds.setURL(url);
ds.setUser(user);
ds.setPassword(getPassword());
assertEquals("ds" + ds.getTraceId() + ": url=" + url + " user=" + user, ds.toString());
XAConnection xaConn = ds.getXAConnection();
int traceId = ((JdbcXAConnection) xaConn).getTraceId();
assertEquals("xads" + traceId + ": url=" + url + " user=" + user, xaConn.toString());
xaConn.addConnectionEventListener(new ConnectionEventListener() {
public void connectionClosed(ConnectionEvent event) {
// nothing to do
......
......@@ -38,6 +38,7 @@ import org.h2.util.New;
*/
public class TestRecover {
private static final int MAX_STRING_LENGTH = 10000;
private static final String NODE = System.getProperty("test.node", "");
private static final String DIR = System.getProperty("test.dir", "/temp/db");
......@@ -185,7 +186,8 @@ public class TestRecover {
Connection conn = DriverManager.getConnection(URL, "sa", "sa");
Statement stat = conn.createStatement();
try {
stat.execute("CREATE TABLE TEST(ID INT PRIMARY KEY, NAME VARCHAR(255))");
stat.execute("CREATE TABLE TEST(ID INT PRIMARY KEY, D INT, NAME VARCHAR("+MAX_STRING_LENGTH+"))");
stat.execute("CREATE INDEX IDX_TEST_D ON TEST(D)");
} catch (SQLException e) {
// ignore
}
......@@ -231,8 +233,8 @@ public class TestRecover {
// make the length odd
len++;
}
// byte[] data = new byte[len];
// random.nextBytes(data);
// byte[] data = new byte[len];
// random.nextBytes(data);
int op = random.nextInt();
if (op % 1000000 == 0) {
closeConnection(conn);
......@@ -243,10 +245,32 @@ public class TestRecover {
}
if (random.nextBoolean()) {
if (prepInsert == null) {
prepInsert = conn.prepareStatement("INSERT INTO TEST(ID, NAME) VALUES(?, ?)");
prepInsert = conn.prepareStatement("INSERT INTO TEST(ID, D, NAME) VALUES(?, ?, ?)");
}
prepInsert.setInt(1, id);
prepInsert.setString(2, "" + len);
prepInsert.setInt(2, random.nextInt(10000));
StringBuilder buff = new StringBuilder();
buff.append(len);
switch (random.nextInt(10)) {
case 0:
len = random.nextInt(MAX_STRING_LENGTH);
break;
case 1:
case 2:
case 3:
len = random.nextInt(MAX_STRING_LENGTH / 20);
break;
default:
len = 0;
}
len -= 10;
while (len > 0) {
buff.append('-');
len--;
}
buff.append("->");
String s = buff.toString();
prepInsert.setString(3, s);
prepInsert.execute();
} else {
ResultSet rs = conn.createStatement().executeQuery("SELECT COUNT(*) FROM TEST");
......@@ -283,22 +307,9 @@ public class TestRecover {
Connection conn = null;
try {
conn = openConnection();
ResultSet rs = conn.createStatement().executeQuery("SELECT * FROM TEST");
int max = 0;
int count = 0;
while (rs.next()) {
count++;
int id = rs.getInt("ID");
String name = rs.getString("NAME");
int value = Integer.parseInt(name);
if (value % 2 != 0) {
throw new Exception("unexpected odd entry " + id + " value " + value);
}
max = Math.max(max, id);
}
rs.close();
test(conn, "");
test(conn, "ORDER BY D");
closeConnection(conn);
System.out.println("max row id: " + max + " rows: " + count);
return true;
} catch (Throwable t) {
t.printStackTrace();
......@@ -319,4 +330,30 @@ public class TestRecover {
}
}
private void test(Connection conn, String order) throws Exception {
ResultSet rs;
rs = conn.createStatement().executeQuery("SELECT * FROM TEST " + order);
int max = 0;
int count = 0;
while (rs.next()) {
count++;
int id = rs.getInt("ID");
String name = rs.getString("NAME");
if (!name.endsWith(">")) {
throw new Exception("unexpected entry " + id + " value " + name);
}
int idx = name.indexOf('-');
if (idx < 0) {
throw new Exception("unexpected entry " + id + " value " + name);
}
int value = Integer.parseInt(name.substring(0, idx));
if (value % 2 != 0) {
throw new Exception("unexpected odd entry " + id + " value " + value);
}
max = Math.max(max, id);
}
rs.close();
System.out.println("max row id: " + max + " rows: " + count);
}
}
......@@ -5,6 +5,14 @@
* Initial Developer: H2 Group
*/
-- TO_DATE
create alias TO_DATE as $$
java.util.Date toDate(String s) throws Exception {
return new java.text.SimpleDateFormat("yyyy.MM.dd").parse(s);
}
$$;
call TO_DATE('1990.02.03')
-- update all rows in all tables
select 'update ' || table_schema || '.' || table_name || ' set ' || column_name || '=' || column_name || ';'
from information_schema.columns where ORDINAL_POSITION = 1 and table_schema <> 'INFORMATION_SCHEMA';
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论