提交 0324fd77 authored 作者: Thomas Mueller's avatar Thomas Mueller

Test

上级 344f2633
...@@ -49,63 +49,64 @@ public class TestReadOnly extends TestBase { ...@@ -49,63 +49,64 @@ public class TestReadOnly extends TestBase {
testReadOnlyFiles(true); testReadOnlyFiles(true);
} }
testReadOnlyFiles(false); testReadOnlyFiles(false);
deleteDb("readonly");
} }
private void testReadOnlyInZip() throws SQLException { private void testReadOnlyInZip() throws SQLException {
if (config.cipher != null) { if (config.cipher != null) {
return; return;
} }
deleteDb("readonly"); deleteDb("readonlyInZip");
String dir = getBaseDir(); String dir = getBaseDir();
Connection conn = getConnection("readonly"); Connection conn = getConnection("readonlyInZip");
Statement stat = conn.createStatement(); Statement stat = conn.createStatement();
stat.execute("CREATE TABLE TEST(ID INT) AS SELECT X FROM SYSTEM_RANGE(1, 20)"); stat.execute("CREATE TABLE TEST(ID INT) AS SELECT X FROM SYSTEM_RANGE(1, 20)");
conn.close(); conn.close();
Backup.execute(dir + "/readonly.zip", dir, "readonly", true); Backup.execute(dir + "/readonly.zip", dir, "readonlyInZip", true);
conn = getConnection( conn = getConnection(
"jdbc:h2:zip:"+dir+"/readonly.zip!/readonly", getUser(), getPassword()); "jdbc:h2:zip:"+dir+"/readonly.zip!/readonlyInZip", getUser(), getPassword());
conn.createStatement().execute("select * from test where id=1"); conn.createStatement().execute("select * from test where id=1");
conn.close(); conn.close();
Server server = Server.createTcpServer("-tcpPort", "9081", "-baseDir", dir); Server server = Server.createTcpServer("-tcpPort", "9081", "-baseDir", dir);
server.start(); server.start();
try { try {
conn = getConnection( conn = getConnection(
"jdbc:h2:tcp://localhost:9081/zip:readonly.zip!/readonly", "jdbc:h2:tcp://localhost:9081/zip:readonly.zip!/readonlyInZip",
getUser(), getPassword()); getUser(), getPassword());
conn.createStatement().execute("select * from test where id=1"); conn.createStatement().execute("select * from test where id=1");
conn.close(); conn.close();
FilePathZip2.register(); FilePathZip2.register();
conn = getConnection( conn = getConnection(
"jdbc:h2:tcp://localhost:9081/zip2:readonly.zip!/readonly", "jdbc:h2:tcp://localhost:9081/zip2:readonly.zip!/readonlyInZip",
getUser(), getPassword()); getUser(), getPassword());
conn.createStatement().execute("select * from test where id=1"); conn.createStatement().execute("select * from test where id=1");
conn.close(); conn.close();
} finally { } finally {
server.stop(); server.stop();
} }
deleteDb("readonlyInZip");
} }
private void testReadOnlyTempTableResult() throws SQLException { private void testReadOnlyTempTableResult() throws SQLException {
deleteDb("readonly"); deleteDb("readonlyTemp");
Connection conn = getConnection("readonly"); Connection conn = getConnection("readonlyTemp");
Statement stat = conn.createStatement(); Statement stat = conn.createStatement();
stat.execute("CREATE TABLE TEST(ID INT) AS SELECT X FROM SYSTEM_RANGE(1, 20)"); stat.execute("CREATE TABLE TEST(ID INT) AS SELECT X FROM SYSTEM_RANGE(1, 20)");
conn.close(); conn.close();
conn = getConnection("readonly;ACCESS_MODE_DATA=r;MAX_MEMORY_ROWS_DISTINCT=10"); conn = getConnection("readonlyTemp;ACCESS_MODE_DATA=r;MAX_MEMORY_ROWS_DISTINCT=10");
stat = conn.createStatement(); stat = conn.createStatement();
stat.execute("SELECT DISTINCT ID FROM TEST"); stat.execute("SELECT DISTINCT ID FROM TEST");
conn.close(); conn.close();
deleteDb("readonlyTemp");
} }
private void testReadOnlyDbCreate() throws SQLException { private void testReadOnlyDbCreate() throws SQLException {
deleteDb("readonly"); deleteDb("readonlyDbCreate");
Connection conn = getConnection("readonly"); Connection conn = getConnection("readonlyDbCreate");
Statement stat = conn.createStatement(); Statement stat = conn.createStatement();
stat.execute("create table a(id int)"); stat.execute("create table a(id int)");
stat.execute("create index ai on a(id)"); stat.execute("create index ai on a(id)");
conn.close(); conn.close();
conn = getConnection("readonly;ACCESS_MODE_DATA=r"); conn = getConnection("readOnlyDbCreate;ACCESS_MODE_DATA=r");
stat = conn.createStatement(); stat = conn.createStatement();
stat.execute("create table if not exists a(id int)"); stat.execute("create table if not exists a(id int)");
stat.execute("create index if not exists ai on a(id)"); stat.execute("create index if not exists ai on a(id)");
...@@ -136,8 +137,8 @@ public class TestReadOnly extends TestBase { ...@@ -136,8 +137,8 @@ public class TestReadOnly extends TestBase {
assertTrue(!f.canWrite()); assertTrue(!f.canWrite());
f.delete(); f.delete();
deleteDb("readonly"); deleteDb("readonlyFiles");
Connection conn = getConnection("readonly"); Connection conn = getConnection("readonlyFiles");
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')");
...@@ -147,9 +148,9 @@ public class TestReadOnly extends TestBase { ...@@ -147,9 +148,9 @@ public class TestReadOnly extends TestBase {
if (setReadOnly) { if (setReadOnly) {
setReadOnly(); setReadOnly();
conn = getConnection("readonly"); conn = getConnection("readonlyFiles");
} else { } else {
conn = getConnection("readonly;ACCESS_MODE_DATA=r"); conn = getConnection("readonlyFiles;ACCESS_MODE_DATA=r");
} }
assertTrue(conn.isReadOnly()); assertTrue(conn.isReadOnly());
stat = conn.createStatement(); stat = conn.createStatement();
...@@ -159,9 +160,9 @@ public class TestReadOnly extends TestBase { ...@@ -159,9 +160,9 @@ public class TestReadOnly extends TestBase {
conn.close(); conn.close();
if (setReadOnly) { if (setReadOnly) {
conn = getConnection("readonly;DB_CLOSE_DELAY=1"); conn = getConnection("readonlyFiles;DB_CLOSE_DELAY=1");
} else { } else {
conn = getConnection("readonly;DB_CLOSE_DELAY=1;ACCESS_MODE_DATA=r"); conn = getConnection("readonlyFiles;DB_CLOSE_DELAY=1;ACCESS_MODE_DATA=r");
} }
stat = conn.createStatement(); stat = conn.createStatement();
stat.execute("SELECT * FROM TEST"); stat.execute("SELECT * FROM TEST");
...@@ -172,22 +173,22 @@ public class TestReadOnly extends TestBase { ...@@ -172,22 +173,22 @@ public class TestReadOnly extends TestBase {
} }
private void setReadOnly() { private void setReadOnly() {
ArrayList<String> list = FileLister.getDatabaseFiles(getBaseDir(), "readonly", true); ArrayList<String> list = FileLister.getDatabaseFiles(getBaseDir(), "readonlyFiles", true);
for (String fileName : list) { for (String fileName : list) {
FileUtils.setReadOnly(fileName); FileUtils.setReadOnly(fileName);
} }
} }
private void testReadOnlyConnect() throws SQLException { private void testReadOnlyConnect() throws SQLException {
deleteDb("readonly"); deleteDb("readonlyConnect");
Connection conn = getConnection("readonly;OPEN_NEW=TRUE"); Connection conn = getConnection("readonlyConnect;OPEN_NEW=TRUE");
Statement stat = conn.createStatement(); Statement stat = conn.createStatement();
stat.execute("create table test(id identity)"); stat.execute("create table test(id identity)");
stat.execute("insert into test select x from system_range(1, 11)"); stat.execute("insert into test select x from system_range(1, 11)");
assertThrows(ErrorCode.DATABASE_ALREADY_OPEN_1, this). assertThrows(ErrorCode.DATABASE_ALREADY_OPEN_1, this).
getConnection("readonly;ACCESS_MODE_DATA=r;OPEN_NEW=TRUE"); getConnection("readonlyConnect;ACCESS_MODE_DATA=r;OPEN_NEW=TRUE");
conn.close(); conn.close();
deleteDb("readonly"); deleteDb("readonlyConnect");
} }
} }
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论