提交 21b02e28 authored 作者: Thomas Mueller's avatar Thomas Mueller

Add tests.

上级 d850a570
......@@ -18,7 +18,9 @@ Change Log
<h1>Change Log</h1>
<h2>Next Version (unreleased)</h2>
<ul><li>Hash indexes now are only used for single column indexes.
<ul><li>CREATE ALIAS: error message when compiling Java code have been improved.
</li><li>MVCC: creating a table with an incorrect constraint could cause strange errors.
</li><li>Hash indexes now are only used for single column indexes.
</li><li>The cache types WEAK_* and TQ are no longer supported.
</li><li>The file system abstraction no longer throws SQL exceptions.
</li><li>DatabaseEventListener.diskSpaceIsLow has changed.
......
......@@ -1528,6 +1528,7 @@ public class Database implements DataHandler {
removeDatabaseObject(session, comment);
}
obj.getSchema().remove(obj);
int id = obj.getId();
if (!starting) {
Table t = getDependentTable(obj, null);
if (t != null) {
......@@ -1536,7 +1537,6 @@ public class Database implements DataHandler {
}
obj.removeChildrenAndResources(session);
}
int id = obj.getId();
removeMeta(session, id);
}
......
......@@ -548,10 +548,6 @@ public class SessionRemote extends SessionWithState implements SessionFactory, D
// ok
}
public int compareTypeSave(Value a, Value b) {
throw DbException.throwInternalError();
}
public void freeUpDiskSpace() {
// nothing to do
}
......
......@@ -38,7 +38,7 @@ public class FileObjectDiskMapped implements FileObject {
reMap();
}
private void unMap() {
private void unMap() throws IOException {
if (mapped != null) {
// first write all data
mapped.force();
......@@ -67,7 +67,7 @@ public class FileObjectDiskMapped implements FileObject {
long start = System.currentTimeMillis();
while (bufferWeakRef.get() != null) {
if (System.currentTimeMillis() - start > GC_TIMEOUT_MS) {
throw new RuntimeException("Timeout (" + GC_TIMEOUT_MS
throw new IOException("Timeout (" + GC_TIMEOUT_MS
+ " ms) reached while trying to GC mapped buffer");
}
System.gc();
......@@ -83,7 +83,7 @@ public class FileObjectDiskMapped implements FileObject {
*/
private void reMap() throws IOException {
if (file.length() > Integer.MAX_VALUE) {
throw new RuntimeException("File over 2GB is not supported yet");
throw new IOException("File over 2GB is not supported yet");
}
int oldPos = 0;
if (mapped != null) {
......
......@@ -10,6 +10,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import org.h2.message.DbException;
import org.h2.util.New;
/**
......@@ -54,7 +55,7 @@ public abstract class FileSystem {
try {
Class.forName(c);
} catch (Exception e) {
throw new RuntimeException(e);
throw DbException.convert(e);
}
}
}
......
......@@ -291,10 +291,13 @@ java org.h2.test.TestAll timer
System.setProperty("h2.check2", "true");
/*
test recovery of large pages and transaction log
test recovery with 'trace' mode (btree data)
test runscript with setCheckResults, execute, process, setShowResults
rename Page* classes
move classes to the right packages
instead of AVL trees, use general balanced trees
test Row.getMemorySize
remove CipherFactory
document in performance section:
PreparedStatement prep = conn.prepareStatement(
......@@ -511,7 +514,6 @@ kill -9 `jps -l | grep "org.h2.test." | cut -d " " -f 1`
new TestTempTables().runTest(this);
new TestTransaction().runTest(this);
new TestTriggersConstraints().runTest(this);
new TestTwoPhaseCommit().runTest(this);
new TestView().runTest(this);
new TestViewAlterTable().runTest(this);
......
......@@ -1096,13 +1096,15 @@ public abstract class TestBase {
ArrayList<String> list2 = new ArrayList<String>();
while (rs1.next()) {
String s1 = rs1.getString(1);
list1.add(s1);
if (!rs2.next()) {
fail("expected: " + s1);
}
String s2 = rs2.getString(1);
if (!s1.equals(s2)) {
list1.add(s1);
list2.add(s2);
}
}
for (String s : list1) {
if (!list2.remove(s)) {
fail("only found in first: " + s);
......
......@@ -43,6 +43,7 @@ public class TestPreparedStatement extends TestBase {
deleteDb("preparedStatement");
Connection conn = getConnection("preparedStatement");
testPrepareExecute(conn);
testUUID(conn);
testScopedGeneratedKey(conn);
testLobTempFiles(conn);
......@@ -75,6 +76,15 @@ public class TestPreparedStatement extends TestBase {
deleteDb("preparedStatement");
}
private void testPrepareExecute(Connection conn) throws SQLException {
Statement stat = conn.createStatement();
stat.execute("prepare test(int, int) as select ?1*?2");
ResultSet rs = stat.executeQuery("execute test(3, 2)");
rs.next();
assertEquals(6, rs.getInt(1));
stat.execute("deallocate test");
}
private void testLobTempFiles(Connection conn) throws SQLException {
Statement stat = conn.createStatement();
stat.execute("CREATE TABLE TEST(ID INT PRIMARY KEY, DATA CLOB)");
......
......@@ -6,6 +6,8 @@
*/
package org.h2.test.unit;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
......@@ -28,26 +30,53 @@ public class TestRecovery extends TestBase {
}
public void test() throws SQLException {
testRunScript();
}
private void testRunScript() throws SQLException {
DeleteDbFiles.execute(baseDir, "recovery", true);
DeleteDbFiles.execute(baseDir, "recovery2", true);
org.h2.Driver.load();
Connection conn = getConnection("recovery");
Statement stat = conn.createStatement();
stat.execute("create table test as select * from system_range(1, 100)");
stat.execute("create table a(id int primary key) as select * from system_range(1, 100)");
stat.execute("create table b(id int references a(id)) as select * from system_range(1, 100)");
stat.execute("create table c(d clob) as select space(10000) || 'end'");
stat.execute("create table d(d varchar) as select space(10000) || 'end'");
stat.execute("alter table a add foreign key(id) references b(id)");
// all rows have the same value - so that SCRIPT can't re-order the rows
stat.execute("create table e(id varchar) as select space(10) from system_range(1, 1000)");
stat.execute("create index idx_e_id on e(id)");
conn.close();
Recover.execute(baseDir, "recovery");
DeleteDbFiles.execute(baseDir, "recovery", true);
Recover rec = new Recover();
ByteArrayOutputStream buff = new ByteArrayOutputStream();
rec.setOut(new PrintStream(buff));
rec.runTool("-dir", baseDir, "-db", "recovery", "-trace");
String out = new String(buff.toByteArray());
assertTrue(out.indexOf("Created file") >= 0);
conn = getConnection("recovery", "diff", "");
stat = conn.createStatement();
Connection conn2 = getConnection("recovery2", "diff", "");
Statement stat2 = conn2.createStatement();
String name = "recovery.h2.sql";
stat.execute("runscript from '" + baseDir + "/" + name + "'");
stat.execute("select * from test");
stat2.execute("runscript from '" + baseDir + "/" + name + "'");
stat2.execute("select * from test");
stat2.execute("drop user diff");
conn2.close();
conn = getConnection("recovery");
stat = conn.createStatement();
conn2 = getConnection("recovery2");
stat2 = conn2.createStatement();
assertEqualDatabases(stat, stat2);
conn.close();
conn2.close();
Recover.execute(baseDir, "recovery");
}
}
......@@ -13,6 +13,7 @@ import java.math.BigDecimal;
import java.net.ServerSocket;
import java.net.Socket;
import java.sql.Connection;
import java.sql.Date;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
......@@ -34,6 +35,7 @@ import org.h2.tools.Restore;
import org.h2.tools.RunScript;
import org.h2.tools.Script;
import org.h2.tools.Server;
import org.h2.tools.SimpleResultSet;
import org.h2.util.IOUtils;
import org.h2.util.JdbcUtils;
......@@ -57,6 +59,7 @@ public class TestTools extends TestBase {
if (config.networked) {
return;
}
testSimpleResultSet();
org.h2.Driver.load();
testJdbcDriverUtils();
testWrongServer();
......@@ -76,6 +79,49 @@ public class TestTools extends TestBase {
deleteDb("utils");
}
private void testSimpleResultSet() throws SQLException {
SimpleResultSet rs;
rs = new SimpleResultSet();
rs.addColumn("a", Types.BIGINT, 0, 0);
rs.addColumn("b", Types.BINARY, 0, 0);
rs.addColumn("c", Types.BOOLEAN, 0, 0);
rs.addColumn("d", Types.DATE, 0, 0);
rs.addColumn("e", Types.DECIMAL, 0, 0);
rs.addColumn("f", Types.FLOAT, 0, 0);
rs.addColumn("g", Types.VARCHAR, 0, 0);
Date d = Date.valueOf("2001-02-03");
byte[] b = new byte[]{(byte) 0xab};
rs.addRow(1, b, true, d, "10.3", Math.PI, "-3");
rs.next();
assertEquals(1, rs.getLong(1));
assertEquals((byte) 1, rs.getByte(1));
assertEquals((short) 1, rs.getShort(1));
assertEquals(1, rs.getLong("a"));
assertEquals((byte) 1, rs.getByte("a"));
assertEquals((short) 1, rs.getShort("a"));
assertEquals(b, rs.getBytes(2));
assertEquals(b, rs.getBytes("b"));
assertTrue(rs.getBoolean(3));
assertTrue(rs.getBoolean("c"));
assertEquals(d.getTime(), rs.getDate(4).getTime());
assertEquals(d.getTime(), rs.getDate("d").getTime());
assertTrue(new BigDecimal("10.3").equals(rs.getBigDecimal(5)));
assertTrue(new BigDecimal("10.3").equals(rs.getBigDecimal("e")));
assertEquals(10.3, rs.getDouble(5));
assertEquals((float) 10.3, rs.getFloat(5));
assertTrue(Math.PI == rs.getDouble(6));
assertTrue(Math.PI == rs.getDouble("f"));
assertTrue((float) Math.PI == rs.getFloat(6));
assertTrue((float) Math.PI == rs.getFloat("f"));
assertEquals(-3, rs.getInt(7));
assertEquals(-3, rs.getByte(7));
assertEquals(-3, rs.getShort(7));
assertEquals(-3, rs.getLong(7));
rs.beforeFirst();
assertTrue(rs.next());
assertFalse(rs.next());
}
private void testJdbcDriverUtils() {
assertEquals("org.h2.Driver", JdbcUtils.getDriver("jdbc:h2:~/test"));
assertEquals("org.postgresql.Driver", JdbcUtils.getDriver("jdbc:postgresql:test"));
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论