提交 eb1babad authored 作者: Thomas Mueller's avatar Thomas Mueller

Improved test case; undoing some unrelated changes.

上级 b4713b27
...@@ -353,11 +353,6 @@ public class Constants { ...@@ -353,11 +353,6 @@ public class Constants {
* The file name suffix of trace files. * The file name suffix of trace files.
*/ */
public static final String SUFFIX_TRACE_FILE = ".trace.db"; public static final String SUFFIX_TRACE_FILE = ".trace.db";
/**
* The file name suffix of split files.
*/
public static final String SUFFIX_SPLIT_FILE = ".part";
/** /**
* The delay that is to be used if throttle has been enabled. * The delay that is to be used if throttle has been enabled.
......
...@@ -107,8 +107,6 @@ public class FileLister { ...@@ -107,8 +107,6 @@ public class FileLister {
ok = true; ok = true;
} else if (f.endsWith(Constants.SUFFIX_TRACE_FILE)) { } else if (f.endsWith(Constants.SUFFIX_TRACE_FILE)) {
ok = true; ok = true;
} else if (f.endsWith(Constants.SUFFIX_SPLIT_FILE)) {
ok = true;
} }
} }
if (ok) { if (ok) {
......
...@@ -13,7 +13,6 @@ import java.io.SequenceInputStream; ...@@ -13,7 +13,6 @@ import java.io.SequenceInputStream;
import java.util.ArrayList; import java.util.ArrayList;
import org.h2.constant.SysProperties; import org.h2.constant.SysProperties;
import org.h2.engine.Constants;
import org.h2.message.DbException; import org.h2.message.DbException;
import org.h2.util.New; import org.h2.util.New;
...@@ -25,6 +24,8 @@ public class FileSystemSplit extends FileSystem { ...@@ -25,6 +24,8 @@ public class FileSystemSplit extends FileSystem {
private static final String PREFIX = "split:"; private static final String PREFIX = "split:";
private static final String PART_SUFFIX = ".part";
private long defaultMaxSize = 1L << SysProperties.SPLIT_FILE_SIZE_SHIFT; private long defaultMaxSize = 1L << SysProperties.SPLIT_FILE_SIZE_SHIFT;
static { static {
...@@ -174,7 +175,7 @@ public class FileSystemSplit extends FileSystem { ...@@ -174,7 +175,7 @@ public class FileSystemSplit extends FileSystem {
ArrayList<String> list = New.arrayList(); ArrayList<String> list = New.arrayList();
for (int i = 0; i < array.length; i++) { for (int i = 0; i < array.length; i++) {
String f = array[i]; String f = array[i];
if (f.endsWith(Constants.SUFFIX_SPLIT_FILE)) { if (f.endsWith(PART_SUFFIX)) {
continue; continue;
} }
array[i] = f = PREFIX + f; array[i] = f = PREFIX + f;
...@@ -312,7 +313,7 @@ public class FileSystemSplit extends FileSystem { ...@@ -312,7 +313,7 @@ public class FileSystemSplit extends FileSystem {
*/ */
static String getFileName(String fileName, int id) { static String getFileName(String fileName, int id) {
if (id > 0) { if (id > 0) {
fileName += "." + id + Constants.SUFFIX_SPLIT_FILE; fileName += "." + id + PART_SUFFIX;
} }
return fileName; return fileName;
} }
......
...@@ -184,7 +184,16 @@ public abstract class TestBase { ...@@ -184,7 +184,16 @@ public abstract class TestBase {
* @return the login password * @return the login password
*/ */
protected String getPassword(String userPassword) { protected String getPassword(String userPassword) {
return config == null || config.cipher == null ? userPassword : "filePassword " + userPassword; return config == null || config.cipher == null ? userPassword : getFilePassword() + " " + userPassword;
}
/**
* Get the file password (only required if file encryption is used).
*
* @return the file password
*/
protected String getFilePassword() {
return "filePassword";
} }
/** /**
......
...@@ -6,7 +6,6 @@ ...@@ -6,7 +6,6 @@
*/ */
package org.h2.test.db; package org.h2.test.db;
import java.io.File;
import java.sql.Connection; import java.sql.Connection;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.SQLException; import java.sql.SQLException;
...@@ -151,14 +150,9 @@ public class TestRunscript extends TestBase implements Trigger { ...@@ -151,14 +150,9 @@ public class TestRunscript extends TestBase implements Trigger {
private void test(boolean password) throws SQLException { private void test(boolean password) throws SQLException {
deleteDb("runscript"); deleteDb("runscript");
Connection conn1, conn2, conn3; Connection conn1, conn2;
Statement stat1, stat2, stat3; Statement stat1, stat2;
String connectionString1 = "jdbc:h2:split:16:" + getBaseDir() + "/runscript;MAX_LENGTH_INPLACE_LOB=1"; conn1 = getConnection("runscript");
String connectionString2 = "jdbc:h2:split:16:" + getBaseDir() + "/runscriptRestore;MAX_LENGTH_INPLACE_LOB=1";
String connectionString3 = "jdbc:h2:split:16:" + getBaseDir() + "/runscriptRestoreRecover;MAX_LENGTH_INPLACE_LOB=1";
conn1 = getConnection(connectionString1 + ";CIPHER=AES", "user", "pw pw");
stat1 = conn1.createStatement(); stat1 = conn1.createStatement();
stat1.execute("create table test (id identity, name varchar(12))"); stat1.execute("create table test (id identity, name varchar(12))");
stat1.execute("insert into test (name) values ('first'), ('second')"); stat1.execute("insert into test (name) values ('first'), ('second')");
...@@ -171,8 +165,7 @@ public class TestRunscript extends TestBase implements Trigger { ...@@ -171,8 +165,7 @@ public class TestRunscript extends TestBase implements Trigger {
stat1.execute("create schema testSchema authorization testAdmin"); stat1.execute("create schema testSchema authorization testAdmin");
stat1.execute("create table testSchema.parent(id int primary key, name varchar)"); stat1.execute("create table testSchema.parent(id int primary key, name varchar)");
stat1.execute("create index idxname on testSchema.parent(name)"); stat1.execute("create index idxname on testSchema.parent(name)");
stat1 stat1.execute("create table testSchema.child(id int primary key, parentId int, name varchar, foreign key(parentId) references parent(id))");
.execute("create table testSchema.child(id int primary key, parentId int, name varchar, foreign key(parentId) references parent(id))");
stat1.execute("create user testUser salt '02' hash '03'"); stat1.execute("create user testUser salt '02' hash '03'");
stat1.execute("create role testRole"); stat1.execute("create role testRole");
stat1.execute("grant all on testSchema.child to testUser"); stat1.execute("grant all on testSchema.child to testUser");
...@@ -187,9 +180,9 @@ public class TestRunscript extends TestBase implements Trigger { ...@@ -187,9 +180,9 @@ public class TestRunscript extends TestBase implements Trigger {
sql += " CIPHER AES PASSWORD 't1e2s3t4'"; sql += " CIPHER AES PASSWORD 't1e2s3t4'";
} }
stat1.execute(sql); stat1.execute(sql);
deleteDb("runscriptRestore"); deleteDb("runscriptRestore");
conn2 = getConnection(connectionString2, "user", "pw pw"); conn2 = getConnection("runscriptRestore");
stat2 = conn2.createStatement(); stat2 = conn2.createStatement();
sql = "runscript from '" + getBaseDir() + "/backup.2.sql'"; sql = "runscript from '" + getBaseDir() + "/backup.2.sql'";
if (password) { if (password) {
...@@ -209,39 +202,46 @@ public class TestRunscript extends TestBase implements Trigger { ...@@ -209,39 +202,46 @@ public class TestRunscript extends TestBase implements Trigger {
} }
stat2.execute(sql); stat2.execute(sql);
stat2.execute("script to '" + getBaseDir() + "/backup.3.sql'"); stat2.execute("script to '" + getBaseDir() + "/backup.3.sql'");
conn1.close();
ChangeFileEncryption.execute("split:" + getBaseDir(), "runscript", "AES", "pw".toCharArray(), null, true);
Recover.execute("split:" + getBaseDir(), "runscript");
deleteDb("runscriptRestoreRecover");
conn3 = getConnection(connectionString3, "abc", "pw");
stat3 = conn3.createStatement();
stat3.execute("runscript from '" + getBaseDir() + "/runscript.h2.sql'");
conn3.close();
conn3 = getConnection(connectionString3, "user", "pw");
stat3 = conn3.createStatement();
stat3.execute("drop user abc");
conn1 = getConnection(connectionString1, "user", "pw");
stat1 = conn1.createStatement();
assertEqualDatabases(stat1, stat2); assertEqualDatabases(stat1, stat2);
assertEqualDatabases(stat1, stat3);
if (!config.memory) {
conn1.close();
if (config.cipher != null) {
ChangeFileEncryption.execute(getBaseDir(), "runscript", config.cipher, getFilePassword().toCharArray(), null, true);
}
Recover.execute(getBaseDir(), "runscript");
deleteDb("runscriptRestoreRecover");
Connection conn3 = getConnection("runscriptRestoreRecover", "tempUser", getPassword());
Statement stat3 = conn3.createStatement();
stat3.execute("runscript from '" + getBaseDir() + "/runscript.h2.sql'");
conn3.close();
conn3 = getConnection("runscriptRestoreRecover");
stat3 = conn3.createStatement();
stat3.execute("drop user tempUser");
if (config.cipher != null) {
ChangeFileEncryption.execute(getBaseDir(), "runscript", config.cipher, null, getFilePassword().toCharArray(), true);
}
conn1 = getConnection("runscript");
stat1 = conn1.createStatement();
assertEqualDatabases(stat1, stat3);
conn3.close();
}
assertEqualDatabases(stat1, stat2);
conn1.close(); conn1.close();
conn2.close(); conn2.close();
conn3.close();
// .txt file from recovery
File[] files = new File(getBaseDir() + "/runscript.lobs.db").listFiles();
for (File file : files) {
IOUtils.delete(file.getAbsolutePath());
}
IOUtils.delete(getBaseDir() + "/backup.2.sql");
IOUtils.delete(getBaseDir() + "/backup.3.sql");
IOUtils.delete(getBaseDir() + "/runscript.h2.sql");
deleteDb("runscript");
deleteDb("runscriptRestore"); deleteDb("runscriptRestore");
deleteDb("runscriptRestoreRecover"); deleteDb("runscriptRestoreRecover");
IOUtils.delete(getBaseDir() + "/backup.2.sql");
IOUtils.delete(getBaseDir() + "/backup.3.sql");
} }
public void init(Connection conn, String schemaName, String triggerName, String tableName, boolean before, int type) { public void init(Connection conn, String schemaName, String triggerName, String tableName, boolean before, int type) {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论