提交 8351b1c6 authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov

Move TestFileSystem to testUtils() section

上级 e273bff1
...@@ -928,7 +928,6 @@ kill -9 `jps -l | grep "org.h2.test." | cut -d " " -f 1` ...@@ -928,7 +928,6 @@ kill -9 `jps -l | grep "org.h2.test." | cut -d " " -f 1`
addTest(new TestCluster()); addTest(new TestCluster());
addTest(new TestFileLockSerialized()); addTest(new TestFileLockSerialized());
addTest(new TestFileLockProcess()); addTest(new TestFileLockProcess());
addTest(new TestFileSystem());
addTest(new TestDefrag()); addTest(new TestDefrag());
addTest(new TestTools()); addTest(new TestTools());
addTest(new TestSampleApps()); addTest(new TestSampleApps());
...@@ -973,6 +972,7 @@ kill -9 `jps -l | grep "org.h2.test." | cut -d " " -f 1` ...@@ -973,6 +972,7 @@ kill -9 `jps -l | grep "org.h2.test." | cut -d " " -f 1`
addTest(new TestDateIso8601()); addTest(new TestDateIso8601());
addTest(new TestDbException()); addTest(new TestDbException());
addTest(new TestFile()); addTest(new TestFile());
addTest(new TestFileSystem());
addTest(new TestFtp()); addTest(new TestFtp());
addTest(new TestGeometryUtils()); addTest(new TestGeometryUtils());
addTest(new TestInterval()); addTest(new TestInterval());
......
...@@ -16,6 +16,7 @@ import java.nio.channels.FileChannel.MapMode; ...@@ -16,6 +16,7 @@ import java.nio.channels.FileChannel.MapMode;
import java.nio.channels.FileLock; import java.nio.channels.FileLock;
import java.nio.channels.NonWritableChannelException; import java.nio.channels.NonWritableChannelException;
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;
...@@ -32,7 +33,6 @@ import org.h2.store.fs.FilePathEncrypt; ...@@ -32,7 +33,6 @@ import org.h2.store.fs.FilePathEncrypt;
import org.h2.store.fs.FilePathRec; import org.h2.store.fs.FilePathRec;
import org.h2.store.fs.FileUtils; import org.h2.store.fs.FileUtils;
import org.h2.test.TestBase; import org.h2.test.TestBase;
import org.h2.test.TestDb;
import org.h2.test.utils.AssertThrows; import org.h2.test.utils.AssertThrows;
import org.h2.test.utils.FilePathDebug; import org.h2.test.utils.FilePathDebug;
import org.h2.tools.Backup; import org.h2.tools.Backup;
...@@ -43,7 +43,7 @@ import org.h2.util.Task; ...@@ -43,7 +43,7 @@ import org.h2.util.Task;
/** /**
* Tests various file system. * Tests various file system.
*/ */
public class TestFileSystem extends TestDb { public class TestFileSystem extends TestBase {
/** /**
* Run just this test. * Run just this test.
...@@ -251,7 +251,7 @@ public class TestFileSystem extends TestDb { ...@@ -251,7 +251,7 @@ public class TestFileSystem extends TestDb {
FileUtils.deleteRecursive(dir, false); FileUtils.deleteRecursive(dir, false);
Connection conn; Connection conn;
Statement stat; Statement stat;
conn = getConnection("jdbc:h2:split:18:"+dir+"/test"); conn = DriverManager.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 +260,7 @@ public class TestFileSystem extends TestDb { ...@@ -260,7 +260,7 @@ public class TestFileSystem extends TestDb {
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 = getConnection( conn = DriverManager.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();
...@@ -269,22 +269,22 @@ public class TestFileSystem extends TestDb { ...@@ -269,22 +269,22 @@ public class TestFileSystem extends TestDb {
private void testDatabaseInMemFileSys() throws SQLException { private void testDatabaseInMemFileSys() throws SQLException {
org.h2.Driver.load(); org.h2.Driver.load();
deleteDb("fsMem"); String dir = getBaseDir() + "/fsMem";
String url = "jdbc:h2:" + getBaseDir() + "/fsMem"; FileUtils.deleteRecursive(dir, false);
Connection conn = getConnection(url, "sa", "sa"); String url = "jdbc:h2:" + dir + "/fsMem";
Connection conn = DriverManager.getConnection(url, "sa", "sa");
conn.createStatement().execute( conn.createStatement().execute(
"CREATE TABLE TEST AS SELECT * FROM DUAL"); "CREATE TABLE TEST AS SELECT * FROM DUAL");
conn.createStatement().execute( conn.createStatement().execute(
"BACKUP TO '" + getBaseDir() + "/fsMem.zip'"); "BACKUP TO '" + getBaseDir() + "/fsMem.zip'");
conn.close(); conn.close();
org.h2.tools.Restore.main("-file", getBaseDir() + "/fsMem.zip", "-dir", org.h2.tools.Restore.main("-file", getBaseDir() + "/fsMem.zip", "-dir", "memFS:");
"memFS:"); conn = DriverManager.getConnection("jdbc:h2:memFS:fsMem", "sa", "sa");
conn = getConnection("jdbc:h2:memFS:fsMem", "sa", "sa");
ResultSet rs = conn.createStatement() ResultSet rs = conn.createStatement()
.executeQuery("SELECT * FROM TEST"); .executeQuery("SELECT * FROM TEST");
rs.close(); rs.close();
conn.close(); conn.close();
deleteDb("fsMem"); FileUtils.deleteRecursive(dir, false);
FileUtils.delete(getBaseDir() + "/fsMem.zip"); FileUtils.delete(getBaseDir() + "/fsMem.zip");
FileUtils.delete("memFS:fsMem.mv.db"); FileUtils.delete("memFS:fsMem.mv.db");
} }
...@@ -297,8 +297,9 @@ public class TestFileSystem extends TestDb { ...@@ -297,8 +297,9 @@ public class TestFileSystem extends TestDb {
return; return;
} }
org.h2.Driver.load(); org.h2.Driver.load();
String url = "jdbc:h2:" + getBaseDir() + "/fsJar"; String dir = getBaseDir() + "/fsJar";
Connection conn = getConnection(url, "sa", "sa"); String url = "jdbc:h2:" + dir + "/fsJar";
Connection conn = DriverManager.getConnection(url, "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, " +
"name varchar, b blob, c clob)"); "name varchar, b blob, c clob)");
...@@ -310,12 +311,12 @@ public class TestFileSystem extends TestDb { ...@@ -310,12 +311,12 @@ public class TestFileSystem extends TestDb {
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 = getConnection(url, "sa", "sa"); conn = DriverManager.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();
deleteDb("fsJar"); FileUtils.deleteRecursive(dir, false);
for (String f : FileUtils.newDirectoryStream( for (String f : FileUtils.newDirectoryStream(
"zip:" + getBaseDir() + "/fsJar.zip")) { "zip:" + getBaseDir() + "/fsJar.zip")) {
assertFalse(FileUtils.isAbsolute(f)); assertFalse(FileUtils.isAbsolute(f));
...@@ -334,7 +335,7 @@ public class TestFileSystem extends TestDb { ...@@ -334,7 +335,7 @@ public class TestFileSystem extends TestDb {
testReadOnly(f); testReadOnly(f);
} }
String urlJar = "jdbc:h2:zip:" + getBaseDir() + "/fsJar.zip!/fsJar"; String urlJar = "jdbc:h2:zip:" + getBaseDir() + "/fsJar.zip!/fsJar";
conn = getConnection(urlJar, "sa", "sa"); conn = DriverManager.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();
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论