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

Make tests more file system independent.

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