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

MVStore bugfixes / tests

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