提交 38b2f3a7 authored 作者: Thomas Mueller's avatar Thomas Mueller

Make tests more file system independent.

上级 8473a1f5
...@@ -6,7 +6,6 @@ ...@@ -6,7 +6,6 @@
*/ */
package org.h2.test.db; package org.h2.test.db;
import java.io.File;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.sql.Connection; import java.sql.Connection;
import java.sql.DriverManager; import java.sql.DriverManager;
...@@ -17,7 +16,9 @@ import java.sql.SQLException; ...@@ -17,7 +16,9 @@ import java.sql.SQLException;
import java.sql.Statement; import java.sql.Statement;
import java.sql.Timestamp; import java.sql.Timestamp;
import org.h2.constant.SysProperties; import org.h2.constant.SysProperties;
import org.h2.store.fs.FileSystem;
import org.h2.test.TestBase; import org.h2.test.TestBase;
import org.h2.util.IOUtils;
/** /**
* Tests the linked table feature (CREATE LINKED TABLE). * Tests the linked table feature (CREATE LINKED TABLE).
...@@ -609,12 +610,14 @@ public class TestLinkedTable extends TestBase { ...@@ -609,12 +610,14 @@ public class TestLinkedTable extends TestBase {
stat.execute("CREATE TABLE TEST(ID INT PRIMARY KEY)"); stat.execute("CREATE TABLE TEST(ID INT PRIMARY KEY)");
conn.close(); conn.close();
File[] files = new File(getBaseDir()).listFiles(); String[] files = IOUtils.listFiles(getBaseDir());
for (File file : files) { for (String file : files) {
if ((file.getName().startsWith("testLinkedTableInReadOnlyDb")) && (!file.getName().endsWith(".trace.db"))) { String name = IOUtils.getFileName(file);
boolean isReadOnly = file.setReadOnly(); if ((name.startsWith("testLinkedTableInReadOnlyDb")) && (!name.endsWith(".trace.db"))) {
FileSystem.getInstance(file).setReadOnly(file);
boolean isReadOnly = FileSystem.getInstance(file).isReadOnly(file);
if (!isReadOnly) { if (!isReadOnly) {
fail("File " + file.getAbsolutePath() + " is not read only. Can't test it."); fail("File " + file + " is not read only. Can't test it.");
} }
} }
} }
......
...@@ -11,12 +11,10 @@ import java.sql.ResultSet; ...@@ -11,12 +11,10 @@ import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.sql.Savepoint; import java.sql.Savepoint;
import java.sql.Statement; import java.sql.Statement;
import org.h2.constant.SysProperties; import org.h2.constant.SysProperties;
import org.h2.jdbc.JdbcStatement; import org.h2.jdbc.JdbcStatement;
import org.h2.store.fs.FileObject;
import org.h2.store.fs.FileSystem;
import org.h2.test.TestBase; import org.h2.test.TestBase;
import org.h2.util.IOUtils;
/** /**
* Tests for the Statement implementation. * Tests for the Statement implementation.
...@@ -65,14 +63,13 @@ public class TestStatement extends TestBase { ...@@ -65,14 +63,13 @@ public class TestStatement extends TestBase {
} catch (SQLException e) { } catch (SQLException e) {
// ignore // ignore
} }
FileObject trace = FileSystem.getInstance(fileName).openFileObject(fileName, "r"); long lengthBefore = IOUtils.length(fileName);
long lengthBefore = trace.length();
try { try {
stat.execute("ERROR"); stat.execute("ERROR");
} catch (SQLException e) { } catch (SQLException e) {
// ignore // ignore
} }
long error = trace.length(); long error = IOUtils.length(fileName);
assertSmaller(lengthBefore, error); assertSmaller(lengthBefore, error);
lengthBefore = error; lengthBefore = error;
try { try {
...@@ -80,7 +77,7 @@ public class TestStatement extends TestBase { ...@@ -80,7 +77,7 @@ public class TestStatement extends TestBase {
} catch (SQLException e) { } catch (SQLException e) {
// ignore // ignore
} }
error = trace.length(); error = IOUtils.length(fileName);
assertEquals(lengthBefore, error); assertEquals(lengthBefore, error);
stat.execute("DROP TABLE TEST IF EXISTS"); stat.execute("DROP TABLE TEST IF EXISTS");
} }
......
...@@ -6,7 +6,6 @@ ...@@ -6,7 +6,6 @@
*/ */
package org.h2.test.unit; package org.h2.test.unit;
import java.io.FileOutputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.sql.Connection; import java.sql.Connection;
import java.sql.DriverManager; import java.sql.DriverManager;
...@@ -19,6 +18,7 @@ import java.util.List; ...@@ -19,6 +18,7 @@ import java.util.List;
import org.h2.jdbc.JdbcConnection; import org.h2.jdbc.JdbcConnection;
import org.h2.store.fs.FileSystem; import org.h2.store.fs.FileSystem;
import org.h2.test.TestBase; import org.h2.test.TestBase;
import org.h2.util.IOUtils;
import org.h2.util.SortedProperties; import org.h2.util.SortedProperties;
/** /**
...@@ -209,7 +209,7 @@ public class TestFileLockSerialized extends TestBase { ...@@ -209,7 +209,7 @@ public class TestFileLockSerialized extends TestBase {
SortedProperties p = SortedProperties.loadProperties(propFile); SortedProperties p = SortedProperties.loadProperties(propFile);
p.setProperty("changePending", "true"); p.setProperty("changePending", "true");
p.setProperty("modificationDataId", "1000"); p.setProperty("modificationDataId", "1000");
OutputStream out = new FileOutputStream(propFile, false); OutputStream out = IOUtils.openFileOutputStream(propFile, false);
try { try {
p.store(out, "test"); p.store(out, "test");
} finally { } finally {
......
...@@ -8,11 +8,10 @@ package org.h2.test.unit; ...@@ -8,11 +8,10 @@ package org.h2.test.unit;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Random; import java.util.Random;
import org.h2.compress.LZFInputStream; import org.h2.compress.LZFInputStream;
import org.h2.compress.LZFOutputStream; import org.h2.compress.LZFOutputStream;
import org.h2.test.TestBase; import org.h2.test.TestBase;
...@@ -55,10 +54,12 @@ public class TestStreams extends TestBase { ...@@ -55,10 +54,12 @@ public class TestStreams extends TestBase {
private void testLZFStreamClose() throws IOException { private void testLZFStreamClose() throws IOException {
String fileName = getBaseDir() + "/temp"; String fileName = getBaseDir() + "/temp";
IOUtils.createDirs(fileName); IOUtils.createDirs(fileName);
LZFOutputStream out = new LZFOutputStream(new FileOutputStream(fileName)); OutputStream fo = IOUtils.openFileOutputStream(fileName, false);
LZFOutputStream out = new LZFOutputStream(fo);
out.write("Hello".getBytes()); out.write("Hello".getBytes());
out.close(); out.close();
LZFInputStream in = new LZFInputStream(new FileInputStream(fileName)); InputStream fi = IOUtils.openFileInputStream(fileName);
LZFInputStream in = new LZFInputStream(fi);
byte[] buff = new byte[100]; byte[] buff = new byte[100];
assertEquals(5, in.read(buff)); assertEquals(5, in.read(buff));
in.read(); in.read();
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论