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

Add tests.

上级 d850a570
...@@ -18,7 +18,9 @@ Change Log ...@@ -18,7 +18,9 @@ Change Log
<h1>Change Log</h1> <h1>Change Log</h1>
<h2>Next Version (unreleased)</h2> <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 cache types WEAK_* and TQ are no longer supported.
</li><li>The file system abstraction no longer throws SQL exceptions. </li><li>The file system abstraction no longer throws SQL exceptions.
</li><li>DatabaseEventListener.diskSpaceIsLow has changed. </li><li>DatabaseEventListener.diskSpaceIsLow has changed.
......
...@@ -1528,6 +1528,7 @@ public class Database implements DataHandler { ...@@ -1528,6 +1528,7 @@ public class Database implements DataHandler {
removeDatabaseObject(session, comment); removeDatabaseObject(session, comment);
} }
obj.getSchema().remove(obj); obj.getSchema().remove(obj);
int id = obj.getId();
if (!starting) { if (!starting) {
Table t = getDependentTable(obj, null); Table t = getDependentTable(obj, null);
if (t != null) { if (t != null) {
...@@ -1536,7 +1537,6 @@ public class Database implements DataHandler { ...@@ -1536,7 +1537,6 @@ public class Database implements DataHandler {
} }
obj.removeChildrenAndResources(session); obj.removeChildrenAndResources(session);
} }
int id = obj.getId();
removeMeta(session, id); removeMeta(session, id);
} }
......
...@@ -548,10 +548,6 @@ public class SessionRemote extends SessionWithState implements SessionFactory, D ...@@ -548,10 +548,6 @@ public class SessionRemote extends SessionWithState implements SessionFactory, D
// ok // ok
} }
public int compareTypeSave(Value a, Value b) {
throw DbException.throwInternalError();
}
public void freeUpDiskSpace() { public void freeUpDiskSpace() {
// nothing to do // nothing to do
} }
......
...@@ -38,7 +38,7 @@ public class FileObjectDiskMapped implements FileObject { ...@@ -38,7 +38,7 @@ public class FileObjectDiskMapped implements FileObject {
reMap(); reMap();
} }
private void unMap() { private void unMap() throws IOException {
if (mapped != null) { if (mapped != null) {
// first write all data // first write all data
mapped.force(); mapped.force();
...@@ -67,7 +67,7 @@ public class FileObjectDiskMapped implements FileObject { ...@@ -67,7 +67,7 @@ public class FileObjectDiskMapped implements FileObject {
long start = System.currentTimeMillis(); long start = System.currentTimeMillis();
while (bufferWeakRef.get() != null) { while (bufferWeakRef.get() != null) {
if (System.currentTimeMillis() - start > GC_TIMEOUT_MS) { 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"); + " ms) reached while trying to GC mapped buffer");
} }
System.gc(); System.gc();
...@@ -83,7 +83,7 @@ public class FileObjectDiskMapped implements FileObject { ...@@ -83,7 +83,7 @@ public class FileObjectDiskMapped implements FileObject {
*/ */
private void reMap() throws IOException { private void reMap() throws IOException {
if (file.length() > Integer.MAX_VALUE) { 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; int oldPos = 0;
if (mapped != null) { if (mapped != null) {
......
...@@ -10,6 +10,7 @@ import java.io.IOException; ...@@ -10,6 +10,7 @@ import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.util.ArrayList; import java.util.ArrayList;
import org.h2.message.DbException;
import org.h2.util.New; import org.h2.util.New;
/** /**
...@@ -54,7 +55,7 @@ public abstract class FileSystem { ...@@ -54,7 +55,7 @@ public abstract class FileSystem {
try { try {
Class.forName(c); Class.forName(c);
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException(e); throw DbException.convert(e);
} }
} }
} }
......
...@@ -291,10 +291,13 @@ java org.h2.test.TestAll timer ...@@ -291,10 +291,13 @@ java org.h2.test.TestAll timer
System.setProperty("h2.check2", "true"); 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 rename Page* classes
move classes to the right packages move classes to the right packages
instead of AVL trees, use general balanced trees
test Row.getMemorySize test Row.getMemorySize
remove CipherFactory
document in performance section: document in performance section:
PreparedStatement prep = conn.prepareStatement( PreparedStatement prep = conn.prepareStatement(
...@@ -511,7 +514,6 @@ kill -9 `jps -l | grep "org.h2.test." | cut -d " " -f 1` ...@@ -511,7 +514,6 @@ kill -9 `jps -l | grep "org.h2.test." | cut -d " " -f 1`
new TestTempTables().runTest(this); new TestTempTables().runTest(this);
new TestTransaction().runTest(this); new TestTransaction().runTest(this);
new TestTriggersConstraints().runTest(this); new TestTriggersConstraints().runTest(this);
new TestTwoPhaseCommit().runTest(this); new TestTwoPhaseCommit().runTest(this);
new TestView().runTest(this); new TestView().runTest(this);
new TestViewAlterTable().runTest(this); new TestViewAlterTable().runTest(this);
......
...@@ -1096,13 +1096,15 @@ public abstract class TestBase { ...@@ -1096,13 +1096,15 @@ public abstract class TestBase {
ArrayList<String> list2 = new ArrayList<String>(); ArrayList<String> list2 = new ArrayList<String>();
while (rs1.next()) { while (rs1.next()) {
String s1 = rs1.getString(1); String s1 = rs1.getString(1);
list1.add(s1);
if (!rs2.next()) { if (!rs2.next()) {
fail("expected: " + s1); fail("expected: " + s1);
} }
String s2 = rs2.getString(1); String s2 = rs2.getString(1);
if (!s1.equals(s2)) {
list1.add(s1);
list2.add(s2); list2.add(s2);
} }
}
for (String s : list1) { for (String s : list1) {
if (!list2.remove(s)) { if (!list2.remove(s)) {
fail("only found in first: " + s); fail("only found in first: " + s);
......
...@@ -43,6 +43,7 @@ public class TestPreparedStatement extends TestBase { ...@@ -43,6 +43,7 @@ public class TestPreparedStatement extends TestBase {
deleteDb("preparedStatement"); deleteDb("preparedStatement");
Connection conn = getConnection("preparedStatement"); Connection conn = getConnection("preparedStatement");
testPrepareExecute(conn);
testUUID(conn); testUUID(conn);
testScopedGeneratedKey(conn); testScopedGeneratedKey(conn);
testLobTempFiles(conn); testLobTempFiles(conn);
...@@ -75,6 +76,15 @@ public class TestPreparedStatement extends TestBase { ...@@ -75,6 +76,15 @@ public class TestPreparedStatement extends TestBase {
deleteDb("preparedStatement"); 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 { private void testLobTempFiles(Connection conn) throws SQLException {
Statement stat = conn.createStatement(); Statement stat = conn.createStatement();
stat.execute("CREATE TABLE TEST(ID INT PRIMARY KEY, DATA CLOB)"); stat.execute("CREATE TABLE TEST(ID INT PRIMARY KEY, DATA CLOB)");
......
...@@ -6,6 +6,8 @@ ...@@ -6,6 +6,8 @@
*/ */
package org.h2.test.unit; package org.h2.test.unit;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import java.sql.Connection; import java.sql.Connection;
import java.sql.SQLException; import java.sql.SQLException;
import java.sql.Statement; import java.sql.Statement;
...@@ -28,26 +30,53 @@ public class TestRecovery extends TestBase { ...@@ -28,26 +30,53 @@ public class TestRecovery extends TestBase {
} }
public void test() throws SQLException { public void test() throws SQLException {
testRunScript();
}
private void testRunScript() throws SQLException {
DeleteDbFiles.execute(baseDir, "recovery", true); DeleteDbFiles.execute(baseDir, "recovery", true);
DeleteDbFiles.execute(baseDir, "recovery2", true);
org.h2.Driver.load(); org.h2.Driver.load();
Connection conn = getConnection("recovery"); Connection conn = getConnection("recovery");
Statement stat = conn.createStatement(); Statement stat = conn.createStatement();
stat.execute("create table test as select * from system_range(1, 100)"); 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 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 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)"); 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(); conn.close();
Recover.execute(baseDir, "recovery"); Recover rec = new Recover();
DeleteDbFiles.execute(baseDir, "recovery", true); 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", ""); Connection conn2 = getConnection("recovery2", "diff", "");
stat = conn.createStatement(); Statement stat2 = conn2.createStatement();
String name = "recovery.h2.sql"; String name = "recovery.h2.sql";
stat.execute("runscript from '" + baseDir + "/" + name + "'"); stat2.execute("runscript from '" + baseDir + "/" + name + "'");
stat.execute("select * from test"); 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(); conn.close();
conn2.close();
Recover.execute(baseDir, "recovery");
} }
} }
...@@ -13,6 +13,7 @@ import java.math.BigDecimal; ...@@ -13,6 +13,7 @@ import java.math.BigDecimal;
import java.net.ServerSocket; import java.net.ServerSocket;
import java.net.Socket; import java.net.Socket;
import java.sql.Connection; import java.sql.Connection;
import java.sql.Date;
import java.sql.DriverManager; import java.sql.DriverManager;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
...@@ -34,6 +35,7 @@ import org.h2.tools.Restore; ...@@ -34,6 +35,7 @@ import org.h2.tools.Restore;
import org.h2.tools.RunScript; import org.h2.tools.RunScript;
import org.h2.tools.Script; import org.h2.tools.Script;
import org.h2.tools.Server; import org.h2.tools.Server;
import org.h2.tools.SimpleResultSet;
import org.h2.util.IOUtils; import org.h2.util.IOUtils;
import org.h2.util.JdbcUtils; import org.h2.util.JdbcUtils;
...@@ -57,6 +59,7 @@ public class TestTools extends TestBase { ...@@ -57,6 +59,7 @@ public class TestTools extends TestBase {
if (config.networked) { if (config.networked) {
return; return;
} }
testSimpleResultSet();
org.h2.Driver.load(); org.h2.Driver.load();
testJdbcDriverUtils(); testJdbcDriverUtils();
testWrongServer(); testWrongServer();
...@@ -76,6 +79,49 @@ public class TestTools extends TestBase { ...@@ -76,6 +79,49 @@ public class TestTools extends TestBase {
deleteDb("utils"); 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() { private void testJdbcDriverUtils() {
assertEquals("org.h2.Driver", JdbcUtils.getDriver("jdbc:h2:~/test")); assertEquals("org.h2.Driver", JdbcUtils.getDriver("jdbc:h2:~/test"));
assertEquals("org.postgresql.Driver", JdbcUtils.getDriver("jdbc:postgresql:test")); assertEquals("org.postgresql.Driver", JdbcUtils.getDriver("jdbc:postgresql:test"));
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论