提交 2c35d8c3 authored 作者: Thomas Mueller's avatar Thomas Mueller

MVStore bugfixes / tests

上级 b5f469e3
......@@ -18,13 +18,15 @@ Change Log
<h1>Change Log</h1>
<h2>Next Version (unreleased)</h2>
<ul><li>The profiler tool can now process files with full thread dumps.
<ul><li>Issue 545: Unnecessary duplicate code was removed.
</li><li>The profiler tool can now process files with full thread dumps.
</li><li>MVStore mode: the CLOB and BLOB storage was re-implemented and is
now much faster than with the PageStore (which is still the default storage).
</li><li>MVStore mode: creating indexes is now much faster
(in many cases faster than with the default PageStore).
</li><li>Various bugs in the MVStore storage and have been fixed,
including a bug in the R-tree implementation.
The database could get corrupt if there were transient IO exceptions while storing.
</li><li>The method org.h2.expression.Function.getCost could throw a NullPointException.
</li><li>Storing LOBs in separate files (outside of the main database file)
is no longer supported for new databases.
......
......@@ -41,6 +41,7 @@ See also <a href="build.html#providing_patches">Providing Patches</a>.
</li><li>Remove support for the old-style outer join syntax using "(+)" because it is buggy.
</li><li>Change license to MPL 2.0.
</li><li>Not allow relative database URLs like jdbc:h2:test; instead, require using jdbc:h2:./test.
</li><li>Document that FILE_LOCK=SERIALIZED is not supported with the MVStore mode.
</li></ul>
<h2>Priority 1</h2>
......
......@@ -660,7 +660,16 @@ public class MVStore {
header.position(BLOCK_SIZE);
header.put(bytes);
header.rewind();
fileStore.writeFully(0, header);
write(0, header);
}
private void write(long pos, ByteBuffer buffer) {
try {
fileStore.writeFully(pos, buffer);
} catch (IllegalStateException e) {
close();
throw e;
}
}
/**
......@@ -945,8 +954,7 @@ public class MVStore {
buff.put(new byte[BLOCK_SIZE - header.length]);
buff.position(0);
fileStore.writeFully(filePos, buff.getBuffer());
write(filePos, buff.getBuffer());
releaseWriteBuffer(buff);
// overwrite the header if required
......@@ -1214,7 +1222,7 @@ public class MVStore {
// fill the header with zeroes
buff.put(new byte[BLOCK_SIZE - header.length]);
buff.position(0);
fileStore.writeFully(end, buff.getBuffer());
write(end, buff.getBuffer());
releaseWriteBuffer(buff);
markMetaChanged();
meta.put("chunk." + c.id, c.asString());
......@@ -1252,7 +1260,7 @@ public class MVStore {
// fill the header with zeroes
buff.put(new byte[BLOCK_SIZE - header.length]);
buff.position(0);
fileStore.writeFully(pos, buff.getBuffer());
write(pos, buff.getBuffer());
releaseWriteBuffer(buff);
markMetaChanged();
meta.put("chunk." + c.id, c.asString());
......@@ -1772,7 +1780,7 @@ public class MVStore {
ByteBuffer header = ByteBuffer.allocate(BLOCK_SIZE);
header.put(bytes);
header.rewind();
fileStore.writeFully(fileStore.size(), header);
write(fileStore.size(), header);
readStoreHeader();
readMeta();
}
......
......@@ -99,7 +99,9 @@ public class FilePathCache extends FilePathWrapper {
}
}
dst.put(buff.array(), off, len);
return len;
; // add test to TestFileSystem
// return len;
return len == 0 ? -1 : len;
}
private static long getCachePos(long pos) {
......
......@@ -306,19 +306,23 @@ public class MVTableEngine implements TableEngine {
* @param maxCompactTime the maximum time in milliseconds to compact
*/
public void close(long maxCompactTime) {
if (!store.isClosed() && store.getFileStore() != null) {
if (!store.getFileStore().isReadOnly()) {
transactionStore.close();
long start = System.currentTimeMillis();
while (store.compact(90)) {
long time = System.currentTimeMillis() - start;
if (time > maxCompactTime) {
break;
try {
if (!store.isClosed() && store.getFileStore() != null) {
if (!store.getFileStore().isReadOnly()) {
transactionStore.close();
long start = System.currentTimeMillis();
while (store.compact(90)) {
long time = System.currentTimeMillis() - start;
if (time > maxCompactTime) {
break;
}
}
}
store.close();
}
store.close();
}
} catch (IllegalStateException e) {
throw DbException.get(ErrorCode.IO_EXCEPTION_1, e, "Closing");
}
}
/**
......
......@@ -6,13 +6,16 @@
*/
package org.h2.store;
import java.nio.channels.FileChannel;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import org.h2.constant.ErrorCode;
import org.h2.engine.Constants;
import org.h2.message.DbException;
import org.h2.message.TraceSystem;
import org.h2.store.fs.FilePath;
import org.h2.store.fs.FileUtils;
import org.h2.util.New;
......@@ -44,6 +47,15 @@ public class FileLister {
throw DbException.get(
ErrorCode.CANNOT_CHANGE_SETTING_WHEN_OPEN_1, message).getSQLException();
}
} else if (fileName.endsWith(Constants.SUFFIX_MV_FILE)) {
try {
FileChannel f = FilePath.get(fileName).open("r");
java.nio.channels.FileLock lock = f.tryLock(0, Long.MAX_VALUE, true);
lock.release();
} catch (Exception e) {
throw DbException.get(
ErrorCode.CANNOT_CHANGE_SETTING_WHEN_OPEN_1, e, message).getSQLException();
}
}
}
}
......
......@@ -729,7 +729,6 @@ kill -9 `jps -l | grep "org.h2.test." | cut -d " " -f 1`
new TestBtreeIndex().runTest(this);
new TestDiskFull().runTest(this);
new TestCrashAPI().runTest(this);
new TestFuzzOptimizations().runTest(this);
new TestLimit().runTest(this);
new TestRandomSQL().runTest(this);
......
......@@ -95,7 +95,7 @@ public class TestIndex extends TestBase {
}
private void testIndexTypes() throws SQLException {
Connection conn = getConnection("index;MV_STORE=false");
Connection conn = getConnection("index");
stat = conn.createStatement();
for (String type : new String[] { "unique", "hash", "unique hash" }) {
stat.execute("create table test(id int)");
......
......@@ -54,17 +54,10 @@ public class TestSpatial extends TestBase {
return;
}
if (DataType.GEOMETRY_CLASS != null) {
deleteDb("spatial");
url = "spatial";
testSpatial();
deleteDb("spatial");
if (!config.mvcc) {
url = "spatial;MV_STORE=false";
testSpatial();
deleteDb("spatial");
}
}
}
......
......@@ -55,6 +55,7 @@ public class TestDiskFull extends TestBase {
String url = "jdbc:h2:unstable:memFS:diskFull" + x +
";FILE_LOCK=NO;TRACE_LEVEL_FILE=0;WRITE_DELAY=10;" +
"LOCK_TIMEOUT=100;CACHE_SIZE=4096";
url = getURL(url, true);
Connection conn = null;
Statement stat = null;
boolean opened = false;
......@@ -90,7 +91,8 @@ public class TestDiskFull extends TestBase {
conn.close();
} catch (SQLException e2) {
if (e2.getErrorCode() != ErrorCode.IO_EXCEPTION_1
&& e2.getErrorCode() != ErrorCode.IO_EXCEPTION_2) {
&& e2.getErrorCode() != ErrorCode.IO_EXCEPTION_2
&& e2.getErrorCode() != ErrorCode.DATABASE_IS_CLOSED) {
throw e2;
}
}
......
......@@ -7,7 +7,6 @@
package org.h2.test.unit;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
......@@ -44,7 +43,7 @@ public class TestAutoReconnect extends TestBase {
connServer.close();
}
org.h2.Driver.load();
connServer = DriverManager.getConnection(url);
connServer = getConnection(url);
} else {
server.stop();
server.start();
......@@ -95,12 +94,12 @@ public class TestAutoReconnect extends TestBase {
}
// test the database event listener
conn = DriverManager.getConnection(url + ";DATABASE_EVENT_LISTENER='" + MyDatabaseEventListener.class.getName() + "'");
conn = getConnection(url + ";DATABASE_EVENT_LISTENER='" + MyDatabaseEventListener.class.getName() + "'");
conn.close();
Statement stat;
conn = DriverManager.getConnection(url);
conn = getConnection(url);
restart();
stat = conn.createStatement();
restart();
......
......@@ -35,10 +35,11 @@ public class TestExit extends TestBase {
return;
}
deleteDb("exit");
String url = getURL(OPEN_WITH_CLOSE_ON_EXIT);
String selfDestruct = SelfDestructor.getPropertyString(60);
String[] procDef = { "java", selfDestruct,
"-cp", getClassPath(),
getClass().getName(), "" + OPEN_WITH_CLOSE_ON_EXIT };
getClass().getName(), url };
Process proc = Runtime.getRuntime().exec(procDef);
while (true) {
int ch = proc.getErrorStream().read();
......@@ -59,9 +60,10 @@ public class TestExit extends TestBase {
if (!getClosedFile().exists()) {
fail("did not close database");
}
url = getURL(OPEN_WITHOUT_CLOSE_ON_EXIT);
procDef = new String[] { "java",
"-cp", getClassPath(), getClass().getName(),
"" + OPEN_WITHOUT_CLOSE_ON_EXIT };
url };
proc = Runtime.getRuntime().exec(procDef);
proc.waitFor();
Thread.sleep(100);
......@@ -70,6 +72,23 @@ public class TestExit extends TestBase {
}
deleteDb("exit");
}
private String getURL(int action) {
String url = "";
switch (action) {
case OPEN_WITH_CLOSE_ON_EXIT:
url = "jdbc:h2:" + getBaseDir() + "/exit;database_event_listener='" + MyDatabaseEventListener.class.getName()
+ "';db_close_on_exit=true";
break;
case OPEN_WITHOUT_CLOSE_ON_EXIT:
url = "jdbc:h2:" + getBaseDir() + "/exit;database_event_listener='" + MyDatabaseEventListener.class.getName()
+ "';db_close_on_exit=false";
break;
default:
}
url = getURL(url, true);
return url;
}
/**
* This method is called when executing this application from the command
......@@ -82,25 +101,12 @@ public class TestExit extends TestBase {
if (args.length == 0) {
System.exit(1);
}
int action = Integer.parseInt(args[0]);
TestExit app = new TestExit();
app.execute(action);
String url = args[0];
TestExit.execute(url);
}
private void execute(int action) throws SQLException {
private static void execute(String url) throws SQLException {
org.h2.Driver.load();
String url = "";
switch (action) {
case OPEN_WITH_CLOSE_ON_EXIT:
url = "jdbc:h2:" + getBaseDir() + "/exit;database_event_listener='" + MyDatabaseEventListener.class.getName()
+ "';db_close_on_exit=true";
break;
case OPEN_WITHOUT_CLOSE_ON_EXIT:
url = "jdbc:h2:" + getBaseDir() + "/exit;database_event_listener='" + MyDatabaseEventListener.class.getName()
+ "';db_close_on_exit=false";
break;
default:
}
conn = open(url);
Connection conn2 = open(url);
conn2.close();
......
......@@ -71,7 +71,8 @@ public class TestFileLockProcess extends TestBase {
}
private void test(int count, String url) throws Exception {
Connection conn = DriverManager.getConnection(url);
url = getURL(url, true);
Connection conn = getConnection(url);
String selfDestruct = SelfDestructor.getPropertyString(60);
String[] procDef = { "java", selfDestruct,
"-cp", getClassPath(),
......
......@@ -8,7 +8,6 @@ package org.h2.test.unit;
import java.io.OutputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
......@@ -39,6 +38,9 @@ public class TestFileLockSerialized extends TestBase {
@Override
public void test() throws Exception {
if (config.mvStore) {
return;
}
println("testSequence");
testSequence();
println("testAutoIncrement");
......@@ -81,7 +83,7 @@ public class TestFileLockSerialized extends TestBase {
String url = "jdbc:h2:" + getBaseDir() + "/fileLockSerialized" +
";FILE_LOCK=SERIALIZED;OPEN_NEW=TRUE;RECONNECT_CHECK_DELAY=10";
ResultSet rs;
Connection conn1 = DriverManager.getConnection(url);
Connection conn1 = getConnection(url);
Statement stat1 = conn1.createStatement();
stat1.execute("create sequence seq");
// 5 times RECONNECT_CHECK_DELAY
......@@ -95,13 +97,13 @@ public class TestFileLockSerialized extends TestBase {
deleteDb("fileLockSerialized");
String url = "jdbc:h2:" + getBaseDir() + "/fileLockSerialized;FILE_LOCK=SERIALIZED;OPEN_NEW=TRUE";
ResultSet rs;
Connection conn1 = DriverManager.getConnection(url);
Connection conn1 = getConnection(url);
Statement stat1 = conn1.createStatement();
stat1.execute("create sequence seq");
rs = stat1.executeQuery("call seq.nextval");
rs.next();
assertEquals(1, rs.getInt(1));
Connection conn2 = DriverManager.getConnection(url);
Connection conn2 = getConnection(url);
Statement stat2 = conn2.createStatement();
rs = stat2.executeQuery("call seq.nextval");
rs.next();
......@@ -115,7 +117,7 @@ public class TestFileLockSerialized extends TestBase {
deleteDb("fileLockSerialized");
final String url = "jdbc:h2:" + getBaseDir() + "/fileLockSerialized;FILE_LOCK=SERIALIZED;OPEN_NEW=TRUE";
Connection conn = DriverManager.getConnection(url);
Connection conn = getConnection(url);
conn.createStatement().execute("create table test(id int) as select 1");
conn.close();
......@@ -128,7 +130,7 @@ public class TestFileLockSerialized extends TestBase {
@Override
public void run() {
try {
Connection c = DriverManager.getConnection(url);
Connection c = getConnection(url);
PreparedStatement p = c.prepareStatement("select * from test where id = ?");
while (!stop[0]) {
Thread.sleep(100);
......@@ -162,28 +164,28 @@ public class TestFileLockSerialized extends TestBase {
if (ex[0] != null) {
throw ex[0];
}
DriverManager.getConnection(url).close();
getConnection(url).close();
}
private void testTwoReaders() throws Exception {
deleteDb("fileLockSerialized");
String url = "jdbc:h2:" + getBaseDir() + "/fileLockSerialized;FILE_LOCK=SERIALIZED;OPEN_NEW=TRUE";
Connection conn1 = DriverManager.getConnection(url);
Connection conn1 = getConnection(url);
conn1.createStatement().execute("create table test(id int)");
Connection conn2 = DriverManager.getConnection(url);
Connection conn2 = getConnection(url);
Statement stat2 = conn2.createStatement();
stat2.execute("drop table test");
stat2.execute("create table test(id identity) as select 1");
conn2.close();
conn1.close();
DriverManager.getConnection(url).close();
getConnection(url).close();
}
private void testTwoWriters() throws Exception {
deleteDb("fileLockSerialized");
String url = "jdbc:h2:" + getBaseDir() + "/fileLockSerialized";
final String writeUrl = url + ";FILE_LOCK=SERIALIZED;OPEN_NEW=TRUE";
Connection conn = DriverManager.getConnection(writeUrl, "sa", "sa");
Connection conn = getConnection(writeUrl, "sa", "sa");
conn.createStatement().execute("create table test(id identity) as select x from system_range(1, 100)");
conn.close();
Task task = new Task() {
......@@ -191,7 +193,7 @@ public class TestFileLockSerialized extends TestBase {
public void call() throws Exception {
while (!stop) {
Thread.sleep(10);
Connection c = DriverManager.getConnection(writeUrl, "sa", "sa");
Connection c = getConnection(writeUrl, "sa", "sa");
c.createStatement().execute("select * from test");
c.close();
}
......@@ -199,7 +201,7 @@ public class TestFileLockSerialized extends TestBase {
}.execute();
Thread.sleep(20);
for (int i = 0; i < 2; i++) {
conn = DriverManager.getConnection(writeUrl, "sa", "sa");
conn = getConnection(writeUrl, "sa", "sa");
Statement stat = conn.createStatement();
stat.execute("drop table test");
stat.execute("create table test(id identity) as select x from system_range(1, 100)");
......@@ -207,7 +209,7 @@ public class TestFileLockSerialized extends TestBase {
conn.close();
}
Thread.sleep(100);
conn = DriverManager.getConnection(writeUrl, "sa", "sa");
conn = getConnection(writeUrl, "sa", "sa");
conn.createStatement().execute("select * from test");
conn.close();
task.get();
......@@ -218,7 +220,7 @@ public class TestFileLockSerialized extends TestBase {
String url = "jdbc:h2:" + getBaseDir() + "/fileLockSerialized";
String writeUrl = url + ";FILE_LOCK=SERIALIZED;OPEN_NEW=TRUE;WRITE_DELAY=0";
Connection conn = DriverManager.getConnection(writeUrl, "sa", "sa");
Connection conn = getConnection(writeUrl, "sa", "sa");
Statement stat = conn.createStatement();
stat.execute("create table test(id int primary key)");
Thread.sleep(100);
......@@ -242,14 +244,14 @@ public class TestFileLockSerialized extends TestBase {
String url = "jdbc:h2:" + getBaseDir() + "/fileLockSerialized";
String writeUrl = url + ";FILE_LOCK=SERIALIZED;OPEN_NEW=TRUE;WRITE_DELAY=0";
Connection conn = DriverManager.getConnection(writeUrl, "sa", "sa");
Connection conn = getConnection(writeUrl, "sa", "sa");
Statement stat = conn.createStatement();
stat.execute("create table test(id int primary key)");
((JdbcConnection) conn).setPowerOffCount(1);
assertThrows(ErrorCode.DATABASE_IS_CLOSED, stat).
execute("insert into test values(1)");
Connection conn2 = DriverManager.getConnection(writeUrl, "sa", "sa");
Connection conn2 = getConnection(writeUrl, "sa", "sa");
Statement stat2 = conn2.createStatement();
stat2.execute("insert into test values(1)");
printResult(stat2, "select * from test");
......@@ -269,14 +271,14 @@ public class TestFileLockSerialized extends TestBase {
trace(" create database");
Class.forName("org.h2.Driver");
Connection conn = DriverManager.getConnection(writeUrl, "sa", "sa");
Connection conn = getConnection(writeUrl, "sa", "sa");
Statement stat = conn.createStatement();
stat.execute("create table test(id int primary key)");
Connection conn3 = DriverManager.getConnection(writeUrl, "sa", "sa");
Connection conn3 = getConnection(writeUrl, "sa", "sa");
PreparedStatement prep3 = conn3.prepareStatement("insert into test values(?)");
Connection conn2 = DriverManager.getConnection(writeUrl, "sa", "sa");
Connection conn2 = getConnection(writeUrl, "sa", "sa");
Statement stat2 = conn2.createStatement();
printResult(stat2, "select * from test");
......@@ -339,7 +341,7 @@ public class TestFileLockSerialized extends TestBase {
final String url = "jdbc:h2:" + getBaseDir() + "/fileLockSerialized;FILE_LOCK=SERIALIZED;OPEN_NEW=TRUE;" +
"AUTO_RECONNECT=TRUE;MAX_LENGTH_INPLACE_LOB=8192;COMPRESS_LOB=DEFLATE;CACHE_SIZE=65536";
Connection conn = DriverManager.getConnection(url);
Connection conn = getConnection(url);
conn.createStatement().execute("create table test(id int auto_increment, id2 int)");
conn.close();
......@@ -355,7 +357,7 @@ public class TestFileLockSerialized extends TestBase {
@Override
public void run() {
try {
Connection c = DriverManager.getConnection(url);
Connection c = getConnection(url);
connList[finalNrOfConnection] = c;
while (!stop[0]) {
synchronized (nextInt) {
......@@ -401,7 +403,7 @@ public class TestFileLockSerialized extends TestBase {
if (ex[0] != null) {
throw ex[0];
}
DriverManager.getConnection(url).close();
getConnection(url).close();
deleteDb("fileLockSerialized");
}
......@@ -411,7 +413,7 @@ public class TestFileLockSerialized extends TestBase {
final String url = "jdbc:h2:" + getBaseDir() + "/fileLockSerialized;FILE_LOCK=SERIALIZED;OPEN_NEW=TRUE;" +
"AUTO_RECONNECT=TRUE;MAX_LENGTH_INPLACE_LOB=8192;COMPRESS_LOB=DEFLATE;CACHE_SIZE=65536";
Connection conn = DriverManager.getConnection(url);
Connection conn = getConnection(url);
conn.createStatement().execute("create table test(id int)");
conn.createStatement().execute("insert into test values(1)");
conn.close();
......@@ -428,7 +430,7 @@ public class TestFileLockSerialized extends TestBase {
@Override
public void run() {
try {
Connection c = DriverManager.getConnection(url);
Connection c = getConnection(url);
connList[finalNrOfConnection] = c;
while (!stop[0]) {
ResultSet rs = c.createStatement().executeQuery("select * from test");
......@@ -464,7 +466,7 @@ public class TestFileLockSerialized extends TestBase {
if (ex[0] != null) {
throw ex[0];
}
DriverManager.getConnection(url).close();
getConnection(url).close();
deleteDb("fileLockSerialized");
}
......@@ -480,7 +482,7 @@ public class TestFileLockSerialized extends TestBase {
deleteDb("fileLockSerialized");
String url = "jdbc:h2:" + getBaseDir() + "/fileLockSerialized;FILE_LOCK=SERIALIZED;OPEN_NEW=TRUE";
Connection conn = DriverManager.getConnection(url);
Connection conn = getConnection(url);
conn.createStatement().execute("create table test(id int)");
conn.createStatement().execute("insert into test values(1)");
for (int i = 0; i < (longRun ? 10000 : 5); i++) {
......@@ -500,9 +502,9 @@ public class TestFileLockSerialized extends TestBase {
String urlShared = "jdbc:h2:" + getBaseDir() + "/fileLockSerialized;FILE_LOCK=SERIALIZED";
Connection connShared1 = DriverManager.getConnection(urlShared);
Connection connShared1 = getConnection(urlShared);
Statement statement1 = connShared1.createStatement();
Connection connShared2 = DriverManager.getConnection(urlShared);
Connection connShared2 = getConnection(urlShared);
Statement statement2 = connShared2.createStatement();
statement1.execute("create table test1(id int)");
......@@ -532,10 +534,10 @@ public class TestFileLockSerialized extends TestBase {
String urlShared = "jdbc:h2:" + getBaseDir() + "/fileLockSerialized;FILE_LOCK=SERIALIZED";
String urlForNew = urlShared + ";OPEN_NEW=TRUE";
Connection connShared1 = DriverManager.getConnection(urlShared);
Connection connShared1 = getConnection(urlShared);
Statement statement1 = connShared1.createStatement();
Connection connShared2 = DriverManager.getConnection(urlShared);
Connection connNew = DriverManager.getConnection(urlForNew);
Connection connShared2 = getConnection(urlShared);
Connection connNew = getConnection(urlForNew);
statement1.execute("create table test1(id int)");
connShared1.close();
connShared2.close();
......@@ -559,7 +561,7 @@ public class TestFileLockSerialized extends TestBase {
final Task importUpdateTask = new Task() {
@Override
public void call() throws Exception {
Connection conn = DriverManager.getConnection(url);
Connection conn = getConnection(url);
Statement stat = conn.createStatement();
stat.execute("create table test(id int, id2 int)");
for (int i = 0; i < howMuchRows; i++) {
......@@ -578,7 +580,7 @@ public class TestFileLockSerialized extends TestBase {
Task selectTask = new Task() {
@Override
public void call() throws Exception {
Connection conn = DriverManager.getConnection(url);
Connection conn = getConnection(url);
Statement stat = conn.createStatement();
importFinishedLatch.await();
......@@ -613,7 +615,7 @@ public class TestFileLockSerialized extends TestBase {
// without serialized
String url;
url = "jdbc:h2:" + getBaseDir() + "/fileLockSerialized";
Connection conn = DriverManager.getConnection(url);
Connection conn = getConnection(url);
Statement stat = conn.createStatement();
stat.execute("create table test(id int)");
stat.execute("insert into test values(0)");
......@@ -624,7 +626,7 @@ public class TestFileLockSerialized extends TestBase {
// with serialized
url = "jdbc:h2:" + getBaseDir() + "/fileLockSerialized;FILE_LOCK=SERIALIZED";
conn = DriverManager.getConnection(url);
conn = getConnection(url);
stat = conn.createStatement();
stat.execute("create table test(id int)");
Thread.sleep(500);
......
......@@ -16,7 +16,6 @@ import java.nio.channels.FileChannel;
import java.nio.channels.FileChannel.MapMode;
import java.nio.channels.FileLock;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
......@@ -251,7 +250,7 @@ public class TestFileSystem extends TestBase {
FileUtils.deleteRecursive(dir, false);
Connection conn;
Statement stat;
conn = DriverManager.getConnection("jdbc:h2:split:18:"+dir+"/test");
conn = getConnection("jdbc:h2:split:18:"+dir+"/test");
stat = conn.createStatement();
stat.execute(
"create table test(id int primary key, name varchar) " +
......@@ -260,7 +259,7 @@ public class TestFileSystem extends TestBase {
conn.close();
Backup.execute(dir + "/test.zip", dir, "", true);
DeleteDbFiles.execute("split:" + dir, "test", true);
conn = DriverManager.getConnection(
conn = getConnection(
"jdbc:h2:split:zip:"+dir+"/test.zip!/test");
conn.createStatement().execute("select * from test where id=1");
conn.close();
......@@ -271,12 +270,12 @@ public class TestFileSystem extends TestBase {
org.h2.Driver.load();
deleteDb("fsMem");
String url = "jdbc:h2:" + getBaseDir() + "/fsMem";
Connection conn = DriverManager.getConnection(url, "sa", "sa");
Connection conn = getConnection(url, "sa", "sa");
conn.createStatement().execute("CREATE TABLE TEST AS SELECT * FROM DUAL");
conn.createStatement().execute("BACKUP TO '" + getBaseDir() + "/fsMem.zip'");
conn.close();
org.h2.tools.Restore.main("-file", getBaseDir() + "/fsMem.zip", "-dir", "memFS:");
conn = DriverManager.getConnection("jdbc:h2:memFS:fsMem", "sa", "sa");
conn = getConnection("jdbc:h2:memFS:fsMem", "sa", "sa");
ResultSet rs = conn.createStatement().executeQuery("SELECT * FROM TEST");
rs.close();
conn.close();
......@@ -293,7 +292,7 @@ public class TestFileSystem extends TestBase {
}
org.h2.Driver.load();
String url = "jdbc:h2:" + getBaseDir() + "/fsJar";
Connection conn = DriverManager.getConnection(url, "sa", "sa");
Connection conn = getConnection(url, "sa", "sa");
Statement stat = conn.createStatement();
stat.execute("create table test(id int primary key, name varchar, b blob, c clob)");
stat.execute("insert into test values(1, 'Hello', SECURE_RAND(2000), space(2000))");
......@@ -303,7 +302,7 @@ public class TestFileSystem extends TestBase {
byte[] b1 = rs.getBytes(3);
String s1 = rs.getString(4);
conn.close();
conn = DriverManager.getConnection(url, "sa", "sa");
conn = getConnection(url, "sa", "sa");
stat = conn.createStatement();
stat.execute("backup to '" + getBaseDir() + "/fsJar.zip'");
conn.close();
......@@ -326,7 +325,7 @@ public class TestFileSystem extends TestBase {
testReadOnly(f);
}
String urlJar = "jdbc:h2:zip:" + getBaseDir() + "/fsJar.zip!/fsJar";
conn = DriverManager.getConnection(urlJar, "sa", "sa");
conn = getConnection(urlJar, "sa", "sa");
stat = conn.createStatement();
rs = stat.executeQuery("select * from test");
rs.next();
......
......@@ -41,6 +41,9 @@ public class TestOldVersion extends TestBase {
@Override
public void test() throws Exception {
if (config.mvStore) {
return;
}
cl = getClassLoader("file:ext/h2-1.2.127.jar");
driver = getDriver(cl);
if (driver == null) {
......
......@@ -70,7 +70,6 @@ public class TestPageStore extends TestBase {
testLargeInserts();
testLargeDatabaseFastOpen();
testUniqueIndexReopen();
testExistingOld();
testLargeRows();
testRecoverDropIndex();
testDropPk();
......@@ -526,26 +525,6 @@ public class TestPageStore extends TestBase {
conn.close();
}
private void testExistingOld() throws SQLException {
if (config.memory) {
return;
}
Connection conn;
deleteDb("pageStoreExistingOld");
String url;
url = "jdbc:h2:" + getBaseDir() + "/pageStoreExistingOld";
conn = DriverManager.getConnection(url);
conn.createStatement().execute("create table test(id int) as select 1");
conn.close();
conn = DriverManager.getConnection(url);
conn.createStatement().execute("select * from test");
conn.close();
// the database is automatically converted
conn = DriverManager.getConnection(url);
assertResult("1", conn.createStatement(), "select * from test");
conn.close();
}
private void testLargeRows() throws Exception {
if (config.memory) {
return;
......
......@@ -96,9 +96,12 @@ public class TestRecovery extends TestBase {
}
private void testRedoTransactions() throws Exception {
if (config.mvStore) {
// not needed for MV_STORE=TRUE
return;
}
DeleteDbFiles.execute(getBaseDir(), "recovery", true);
// not needed for MV_STORE=TRUE
Connection conn = getConnection("recovery;MV_STORE=false");
Connection conn = getConnection("recovery");
Statement stat = conn.createStatement();
stat.execute("set write_delay 0");
stat.execute("create table test(id int primary key, name varchar)");
......@@ -136,9 +139,12 @@ public class TestRecovery extends TestBase {
}
private void testCorrupt() throws Exception {
if (config.mvStore) {
// not needed for MV_STORE=TRUE
return;
}
DeleteDbFiles.execute(getBaseDir(), "recovery", true);
// not needed for MV_STORE=TRUE
Connection conn = getConnection("recovery;MV_STORE=false");
Connection conn = getConnection("recovery");
Statement stat = conn.createStatement();
stat.execute("create table test(id int, name varchar) as select 1, 'Hello World1'");
conn.close();
......@@ -163,9 +169,12 @@ public class TestRecovery extends TestBase {
}
private void testWithTransactionLog() throws SQLException {
if (config.mvStore) {
// not needed for MV_STORE=TRUE
return;
}
DeleteDbFiles.execute(getBaseDir(), "recovery", true);
// not needed for MV_STORE=TRUE
Connection conn = getConnection("recovery;MV_STORE=false");
Connection conn = getConnection("recovery");
Statement stat = conn.createStatement();
stat.execute("create table truncate(id int primary key) as select x from system_range(1, 1000)");
stat.execute("create table test(id int primary key, data int, text varchar)");
......@@ -198,10 +207,10 @@ public class TestRecovery extends TestBase {
// expected
}
Recover.main("-dir", getBaseDir(), "-db", "recovery");
conn = getConnection("recovery;MV_STORE=false");
conn = getConnection("recovery");
conn.close();
Recover.main("-dir", getBaseDir(), "-db", "recovery", "-removePassword");
conn = getConnection("recovery;MV_STORE=false", getUser(), "");
conn = getConnection("recovery", getUser(), "");
conn.close();
DeleteDbFiles.execute(getBaseDir(), "recovery", true);
}
......
......@@ -24,7 +24,6 @@ import java.sql.Blob;
import java.sql.Clob;
import java.sql.Connection;
import java.sql.Date;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
......@@ -35,6 +34,7 @@ import java.sql.Timestamp;
import java.sql.Types;
import java.util.ArrayList;
import java.util.Random;
import org.h2.constant.ErrorCode;
import org.h2.constant.SysProperties;
import org.h2.store.FileLister;
......@@ -503,7 +503,7 @@ public class TestTools extends TestBase {
assertTrue(result.indexOf(":9001") >= 0);
assertTrue(result.indexOf("only local") >= 0);
assertTrue(result.indexOf("Starts the H2 Console") < 0);
conn = DriverManager.getConnection("jdbc:h2:tcp://localhost:9001/mem:", "sa", "sa");
conn = getConnection("jdbc:h2:tcp://localhost:9001/mem:", "sa", "sa");
conn.close();
result = runServer(0, new String[]{"-tcpShutdown", "tcp://localhost:9001", "-tcpPassword", "abc", "-tcpShutdownForce"});
assertTrue(result.indexOf("Shutting down") >= 0);
......@@ -513,7 +513,7 @@ public class TestTools extends TestBase {
assertTrue(result.indexOf(":9001") >= 0);
assertTrue(result.indexOf("others can") >= 0);
assertTrue(result.indexOf("Starts the H2 Console") < 0);
conn = DriverManager.getConnection("jdbc:h2:ssl://localhost:9001/mem:", "sa", "sa");
conn = getConnection("jdbc:h2:ssl://localhost:9001/mem:", "sa", "sa");
conn.close();
result = runServer(0, new String[]{"-tcpShutdown", "ssl://localhost:9001", "-tcpPassword", "abcdef"});
......@@ -535,7 +535,7 @@ public class TestTools extends TestBase {
assertTrue(result.indexOf("tcp://") >= 0);
assertTrue(result.indexOf(":9006") >= 0);
conn = DriverManager.getConnection("jdbc:h2:tcp://localhost:9006/mem:", "sa", "sa");
conn = getConnection("jdbc:h2:tcp://localhost:9006/mem:", "sa", "sa");
conn.close();
result = runServer(0, new String[]{"-tcpShutdown", "tcp://localhost:9006", "-tcpPassword", "abc", "-tcpShutdownForce"});
......@@ -567,7 +567,8 @@ public class TestTools extends TestBase {
deleteDb("toolsConvertTraceFile");
org.h2.Driver.load();
String url = "jdbc:h2:" + getBaseDir() + "/toolsConvertTraceFile";
Connection conn = DriverManager.getConnection(url + ";TRACE_LEVEL_FILE=3", "sa", "sa");
url = getURL(url, true);
Connection conn = getConnection(url + ";TRACE_LEVEL_FILE=3", "sa", "sa");
Statement stat = conn.createStatement();
stat.execute("create table test(id int primary key, name varchar, amount decimal)");
PreparedStatement prep = conn.prepareStatement("insert into test values(?, ?, ?)");
......@@ -618,7 +619,7 @@ public class TestTools extends TestBase {
private void testTraceFile(String url) throws SQLException {
Connection conn;
Recover.main("-removePassword", "-dir", getBaseDir(), "-db", "toolsConvertTraceFile");
conn = DriverManager.getConnection(url, "sa", "");
conn = getConnection(url, "sa", "");
Statement stat = conn.createStatement();
ResultSet rs;
rs = stat.executeQuery("select * from test");
......@@ -643,16 +644,19 @@ public class TestTools extends TestBase {
}
private void testRemove() throws SQLException {
if (config.mvStore) {
return;
}
deleteDb("toolsRemove");
org.h2.Driver.load();
String url = "jdbc:h2:" + getBaseDir() + "/toolsRemove";
Connection conn = DriverManager.getConnection(url, "sa", "sa");
Connection conn = getConnection(url, "sa", "sa");
Statement stat = conn.createStatement();
stat.execute("create table test(id int primary key, name varchar)");
stat.execute("insert into test values(1, 'Hello')");
conn.close();
Recover.main("-dir", getBaseDir(), "-db", "toolsRemove", "-removePassword");
conn = DriverManager.getConnection(url, "sa", "");
conn = getConnection(url, "sa", "");
stat = conn.createStatement();
ResultSet rs;
rs = stat.executeQuery("select * from test");
......@@ -668,7 +672,7 @@ public class TestTools extends TestBase {
deleteDb("toolsRecover");
org.h2.Driver.load();
String url = getURL("toolsRecover", true);
Connection conn = DriverManager.getConnection(url, "sa", "sa");
Connection conn = getConnection(url, "sa", "sa");
Statement stat = conn.createStatement();
stat.execute("create table test(id int primary key, name varchar, b blob, c clob)");
stat.execute("create table \"test 2\"(id int primary key, name varchar)");
......@@ -692,7 +696,7 @@ public class TestTools extends TestBase {
}
}
conn = DriverManager.getConnection(url);
conn = getConnection(url);
stat = conn.createStatement();
String suffix = ".h2.sql";
stat.execute("runscript from '" + getBaseDir() + "/toolsRecover" + suffix + "'");
......@@ -729,10 +733,10 @@ public class TestTools extends TestBase {
private void testScriptRunscriptLob() throws Exception {
org.h2.Driver.load();
String url = "jdbc:h2:" + getBaseDir() + "/utils";
String url = getURL("jdbc:h2:" + getBaseDir() + "/utils", true);
String user = "sa", password = "abc";
String fileName = getBaseDir() + "/b2.sql";
Connection conn = DriverManager.getConnection(url, user, password);
Connection conn = getConnection(url, user, password);
conn.createStatement().execute("CREATE TABLE TEST(ID INT PRIMARY KEY, BDATA BLOB, CDATA CLOB)");
PreparedStatement prep = conn.prepareStatement("INSERT INTO TEST VALUES(?, ?, ?)");
......@@ -775,7 +779,7 @@ public class TestTools extends TestBase {
Script.main("-url", url, "-user", user, "-password", password, "-script", fileName);
DeleteDbFiles.main("-dir", getBaseDir(), "-db", "utils", "-quiet");
RunScript.main("-url", url, "-user", user, "-password", password, "-script", fileName);
conn = DriverManager.getConnection("jdbc:h2:" + getBaseDir() + "/utils", "sa", "abc");
conn = getConnection("jdbc:h2:" + getBaseDir() + "/utils", "sa", "abc");
}
conn.close();
......@@ -783,11 +787,11 @@ public class TestTools extends TestBase {
private void testScriptRunscript() throws SQLException {
org.h2.Driver.load();
String url = "jdbc:h2:" + getBaseDir() + "/utils";
String url = getURL("jdbc:h2:" + getBaseDir() + "/utils", true);
String user = "sa", password = "abc";
String fileName = getBaseDir() + "/b2.sql";
DeleteDbFiles.main("-dir", getBaseDir(), "-db", "utils", "-quiet");
Connection conn = DriverManager.getConnection(url, user, password);
Connection conn = getConnection(url, user, password);
conn.createStatement().execute("CREATE TABLE \u00f6()");
conn.createStatement().execute("CREATE TABLE TEST(ID INT PRIMARY KEY, NAME VARCHAR)");
conn.createStatement().execute("INSERT INTO TEST VALUES(1, 'Hello')");
......@@ -798,7 +802,7 @@ public class TestTools extends TestBase {
DeleteDbFiles.main("-dir", getBaseDir(), "-db", "utils", "-quiet");
RunScript.main("-url", url, "-user", user, "-password", password, "-script", fileName,
"-options", "compression", "lzf", "cipher", "xtea", "password", "'123'", "charset", "'utf-8'");
conn = DriverManager.getConnection("jdbc:h2:" + getBaseDir() + "/utils", "sa", "abc");
conn = getConnection("jdbc:h2:" + getBaseDir() + "/utils", "sa", "abc");
ResultSet rs = conn.createStatement().executeQuery("SELECT * FROM TEST");
assertFalse(rs.next());
rs = conn.createStatement().executeQuery("SELECT * FROM \u00f6");
......@@ -820,14 +824,14 @@ public class TestTools extends TestBase {
String user = "sa", password = "abc";
final String fileName = getBaseDir() + "/b2.zip";
DeleteDbFiles.main("-dir", getBaseDir(), "-db", "utils", "-quiet");
Connection conn = DriverManager.getConnection(url, user, password);
Connection conn = getConnection(url, user, password);
conn.createStatement().execute("CREATE TABLE TEST(ID INT PRIMARY KEY, NAME VARCHAR)");
conn.createStatement().execute("INSERT INTO TEST VALUES(1, 'Hello')");
conn.close();
Backup.main("-file", fileName, "-dir", getBaseDir(), "-db", "utils", "-quiet");
DeleteDbFiles.main("-dir", getBaseDir(), "-db", "utils", "-quiet");
Restore.main("-file", fileName, "-dir", getBaseDir(), "-db", "utils", "-quiet");
conn = DriverManager.getConnection("jdbc:h2:" + getBaseDir() + "/utils", "sa", "abc");
conn = getConnection("jdbc:h2:" + getBaseDir() + "/utils", "sa", "abc");
ResultSet rs = conn.createStatement().executeQuery("SELECT * FROM TEST");
assertTrue(rs.next());
assertFalse(rs.next());
......@@ -847,7 +851,7 @@ public class TestTools extends TestBase {
final String dir = (split ? "split:19:" : "") + getBaseDir();
String url = "jdbc:h2:" + dir;
DeleteDbFiles.execute(dir, "utils", true);
Connection conn = DriverManager.getConnection(url + "/utils;CIPHER=XTEA", "sa", "abc 123");
Connection conn = getConnection(url + "/utils;CIPHER=XTEA", "sa", "abc 123");
Statement stat = conn.createStatement();
stat.execute("CREATE TABLE TEST(ID INT PRIMARY KEY, DATA CLOB) " +
"AS SELECT X, SPACE(3000) FROM SYSTEM_RANGE(1, 300)");
......@@ -856,7 +860,7 @@ public class TestTools extends TestBase {
ChangeFileEncryption.main(args);
args = new String[] { "-dir", dir, "-db", "utils", "-cipher", "AES", "-encrypt", "def", "-quiet" };
ChangeFileEncryption.main(args);
conn = DriverManager.getConnection(url + "/utils;CIPHER=AES", "sa", "def 123");
conn = getConnection(url + "/utils;CIPHER=AES", "sa", "def 123");
stat = conn.createStatement();
stat.execute("SELECT * FROM TEST");
new AssertThrows(ErrorCode.CANNOT_CHANGE_SETTING_WHEN_OPEN_1) {
......@@ -878,7 +882,7 @@ public class TestTools extends TestBase {
"-baseDir", getBaseDir(),
"-tcpPort", "9192",
"-tcpAllowOthers").start();
conn = DriverManager.getConnection("jdbc:h2:tcp://localhost:9192/test", "sa", "");
conn = getConnection("jdbc:h2:tcp://localhost:9192/test", "sa", "");
conn.close();
// must not be able to use a different base dir
new AssertThrows(ErrorCode.IO_EXCEPTION_1) {
......@@ -908,14 +912,14 @@ public class TestTools extends TestBase {
public void test() throws SQLException {
getConnection("jdbc:h2:tcp://localhost:9192/test2;ifexists=false", "sa", "");
}};
conn = DriverManager.getConnection("jdbc:h2:tcp://localhost:9192/test", "sa", "");
conn = getConnection("jdbc:h2:tcp://localhost:9192/test", "sa", "");
conn.close();
new AssertThrows(ErrorCode.WRONG_USER_OR_PASSWORD) {
@Override
public void test() throws SQLException {
Server.shutdownTcpServer("tcp://localhost:9192", "", true, false);
}};
conn = DriverManager.getConnection("jdbc:h2:tcp://localhost:9192/test", "sa", "");
conn = getConnection("jdbc:h2:tcp://localhost:9192/test", "sa", "");
// conn.close();
Server.shutdownTcpServer("tcp://localhost:9192", "abc", true, false);
// check that the database is closed
......@@ -930,7 +934,7 @@ public class TestTools extends TestBase {
"-baseDir", getBaseDir(),
"-tcpPort", "9192",
"-tcpAllowOthers").start();
conn = DriverManager.getConnection("jdbc:h2:tcp://localhost:9192/split:testSplit", "sa", "");
conn = getConnection("jdbc:h2:tcp://localhost:9192/split:testSplit", "sa", "");
conn.close();
assertThrows(ErrorCode.IO_EXCEPTION_1, this).
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论