提交 73d5ca84 authored 作者: Thomas Mueller's avatar Thomas Mueller

The test cases don't access the file system directly. Thanks to Vince Bonfanti!

上级 df786086
......@@ -18,7 +18,9 @@ Change Log
<h1>Change Log</h1>
<h2>Next Version (unreleased)</h2>
<ul><li>More bugs in the server-less multi-connection mode have been fixed.
<ul><li>The test cases don't access the file system directly, this simplifies GAE for Java testing.
Thanks to Vince Bonfanti.
</li><li>More bugs in the server-less multi-connection mode have been fixed.
</li><li>When running against an old database, the SCRIPT statement could generate a
SQL script that contained duplicate indexes (PRIMARY_KEY_E).
</li><li>JdbcConnectionPool.getConnection() could throw a NullPointerException.
......
......@@ -47,13 +47,14 @@ See also <a href="build.html#providing_patches">Providing Patches</a>.
</li><li>Full outer joins
</li><li>Implement INSTEAD OF trigger (for views, tables, metadata tables).
</li><li>Support triggers for INFORMATION_SCHEMA tables (to better support PostgreSQL catalog: rebuild after creating new tables)
</li><li>Support mixed clustering mode (one embedded, others in server mode)
</li><li>Use triggers for metadata tables; use for PostgreSQL catalog
</li><li>Test very large databases and LOBs (up to 256 GB)
</li><li>Support alter table add column if table has views defined
</li><li>Support hints for the optimizer (which index to use, enforce the join order).
</li><li>Change LOB mechanism (less files, keep index of lob files, point to files and row, delete unused files earlier, maybe bundle files into a tar file)
</li><li>Clustering: recovery needs to becomes fully automatic. Global write lock feature.
</li><li>Support mixed clustering mode (one embedded, others in server mode)
</li><li>Clustering: reads should be randomly distributed (optional) or to a designated database on RAM (parameter: READ_FROM=3)
</li><li>Sequence: add features [NO] MINVALUE, MAXVALUE, CYCLE
</li><li>Deferred integrity checking (DEFERRABLE INITIALLY DEFERRED)
</li><li>Groovy Stored Procedures (http://groovy.codehaus.org/Groovy+SQL)
......@@ -76,7 +77,6 @@ See also <a href="build.html#providing_patches">Providing Patches</a>.
</li><li>Pluggable data type (for streaming, hashing, compression, validation, conversion, encryption)
</li><li>CHECK: find out what makes CHECK=TRUE slow, move to CHECK2
</li><li>Index usage for (ID, NAME)=(1, 'Hi'); document
</li><li>Clustering: reads should be randomly distributed (optional) or to a designated database on RAM
</li><li>Make DDL (Data Definition) operations transactional
</li><li>RANK() and DENSE_RANK(), Partition using OVER()
</li><li>Set a connection read only (Connection.setReadOnly) or using a connection parameter
......
......@@ -271,7 +271,7 @@ public class TestCases extends TestBase {
}
private void testUpperCaseLowerCaseDatabase() throws SQLException {
if (File.separatorChar != '\\') {
if (File.separatorChar != '\\' || config.googleAppEngine) {
return;
}
deleteDb("cases");
......@@ -633,7 +633,7 @@ public class TestCases extends TestBase {
}
private void testDoubleRecovery() throws SQLException {
if (config.networked) {
if (config.networked || config.googleAppEngine) {
return;
}
trace("testDoubleRecovery");
......
......@@ -7,8 +7,7 @@
package org.h2.test.db;
import java.io.File;
import java.io.FileReader;
import java.io.RandomAccessFile;
import java.io.InputStreamReader;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
......@@ -18,6 +17,8 @@ import java.sql.Statement;
import java.util.ArrayList;
import java.util.Random;
import org.h2.store.fs.FileObject;
import org.h2.store.fs.FileSystem;
import org.h2.test.TestBase;
import org.h2.tools.Csv;
import org.h2.util.FileUtils;
......@@ -81,16 +82,18 @@ public class TestCsv extends TestBase {
private void testNull() throws Exception {
deleteDb("csv");
File f = new File(baseDir + "/testNull.csv");
FileUtils.delete(f.getAbsolutePath());
RandomAccessFile file = new RandomAccessFile(f, "rw");
String fileName = baseDir + "/testNull.csv";
FileSystem fs = FileSystem.getInstance(fileName);
fs.delete(fileName);
FileObject file = fs.openFileObject(fileName, "rw");
String csvContent = "\"A\",\"B\",\"C\",\"D\"\n\\N,\"\",\"\\N\",";
file.write(csvContent.getBytes("UTF-8"));
byte[] b = csvContent.getBytes("UTF-8");
file.write(b, 0, b.length);
file.close();
Csv csv = Csv.getInstance();
csv.setNullString("\\N");
ResultSet rs = csv.read(f.getPath(), null, "UTF8");
ResultSet rs = csv.read(file.getName(), null, "UTF8");
ResultSetMetaData meta = rs.getMetaData();
assertEquals(4, meta.getColumnCount());
assertEquals("A", meta.getColumnLabel(1));
......@@ -108,15 +111,15 @@ public class TestCsv extends TestBase {
Connection conn = getConnection("csv");
Statement stat = conn.createStatement();
stat.execute("call csvwrite('" + f.getPath() + "', 'select NULL as a, '''' as b, ''\\N'' as c, NULL as d', 'UTF8', ',', '\"', NULL, '\\N', '\n')");
FileReader reader = new FileReader(f);
stat.execute("call csvwrite('" + file.getName() + "', 'select NULL as a, '''' as b, ''\\N'' as c, NULL as d', 'UTF8', ',', '\"', NULL, '\\N', '\n')");
InputStreamReader reader = new InputStreamReader(fs.openFileInputStream(fileName));
// on read, an empty string is treated like null,
// but on write a null is always written with the nullString
String data = IOUtils.readStringAndClose(reader, -1);
assertEquals(csvContent + "\\N", data.trim());
conn.close();
FileUtils.delete(f.getAbsolutePath());
fs.delete(fileName);
}
private void testRandomData() throws SQLException {
......@@ -166,16 +169,16 @@ public class TestCsv extends TestBase {
}
private void testEmptyFieldDelimiter() throws Exception {
File f = new File(baseDir + "/test.csv");
f.delete();
String fileName = baseDir + "/test.csv";
FileUtils.delete(fileName);
Connection conn = getConnection("csv");
Statement stat = conn.createStatement();
stat.execute("call csvwrite('"+baseDir+"/test.csv', 'select 1 id, ''Hello'' name', null, '|', '', null, null, chr(10))");
FileReader reader = new FileReader(baseDir + "/test.csv");
stat.execute("call csvwrite('"+fileName+"', 'select 1 id, ''Hello'' name', null, '|', '', null, null, chr(10))");
InputStreamReader reader = new InputStreamReader(FileUtils.openFileInputStream(fileName));
String text = IOUtils.readStringAndClose(reader, -1).trim();
text = StringUtils.replaceAll(text, "\n", " ");
assertEquals("ID|NAME 1|Hello", text);
ResultSet rs = stat.executeQuery("select * from csvread('" + baseDir + "/test.csv', null, null, '|', '')");
ResultSet rs = stat.executeQuery("select * from csvread('" + fileName + "', null, null, '|', '')");
ResultSetMetaData meta = rs.getMetaData();
assertEquals(2, meta.getColumnCount());
assertEquals("ID", meta.getColumnLabel(1));
......@@ -185,18 +188,21 @@ public class TestCsv extends TestBase {
assertEquals("Hello", rs.getString(2));
assertFalse(rs.next());
conn.close();
FileUtils.delete(baseDir + "/test.csv");
FileUtils.delete(fileName);
}
private void testFieldDelimiter() throws Exception {
File f = new File(baseDir + "/test.csv");
f.delete();
RandomAccessFile file = new RandomAccessFile(f, "rw");
file.write("'A'; 'B'\n\'It\\'s nice\'; '\nHello\\*\n'".getBytes());
String fileName = baseDir + "/test.csv";
String fileName2 = baseDir + "/test2.csv";
FileSystem fs = FileSystem.getInstance(fileName);
fs.delete(fileName);
FileObject file = fs.openFileObject(fileName, "rw");
byte[] b = "'A'; 'B'\n\'It\\'s nice\'; '\nHello\\*\n'".getBytes();
file.write(b, 0, b.length);
file.close();
Connection conn = getConnection("csv");
Statement stat = conn.createStatement();
ResultSet rs = stat.executeQuery("select * from csvread('" + baseDir + "/test.csv', null, null, ';', '''', '\\')");
ResultSet rs = stat.executeQuery("select * from csvread('" + fileName + "', null, null, ';', '''', '\\')");
ResultSetMetaData meta = rs.getMetaData();
assertEquals(2, meta.getColumnCount());
assertEquals("A", meta.getColumnLabel(1));
......@@ -205,8 +211,8 @@ public class TestCsv extends TestBase {
assertEquals("It's nice", rs.getString(1));
assertEquals("\nHello*\n", rs.getString(2));
assertFalse(rs.next());
stat.execute("call csvwrite('" + baseDir + "/test2.csv', 'select * from csvread(''" + baseDir + "/test.csv'', null, null, '';'', '''''''', ''\\'')', null, '+', '*', '#')");
rs = stat.executeQuery("select * from csvread('" + baseDir + "/test2.csv', null, null, '+', '*', '#')");
stat.execute("call csvwrite('" + fileName2 + "', 'select * from csvread(''" + fileName + "'', null, null, '';'', '''''''', ''\\'')', null, '+', '*', '#')");
rs = stat.executeQuery("select * from csvread('" + fileName2 + "', null, null, '+', '*', '#')");
meta = rs.getMetaData();
assertEquals(2, meta.getColumnCount());
assertEquals("A", meta.getColumnLabel(1));
......@@ -216,8 +222,8 @@ public class TestCsv extends TestBase {
assertEquals("\nHello*\n", rs.getString(2));
assertFalse(rs.next());
conn.close();
FileUtils.delete(baseDir + "/test.csv");
FileUtils.delete(baseDir + "/test2.csv");
fs.delete(fileName);
fs.delete(fileName2);
}
private void testPipe() throws SQLException {
......@@ -262,12 +268,14 @@ public class TestCsv extends TestBase {
}
private void testRead() throws Exception {
File f = new File(baseDir + "/test.csv");
f.delete();
RandomAccessFile file = new RandomAccessFile(f, "rw");
file.write("a,b,c,d\n201,-2,0,18\n, \"abc\"\"\" ,,\"\"\n 1 ,2 , 3, 4 \n5, 6, 7, 8".getBytes());
String fileName = baseDir + "/test.csv";
FileSystem fs = FileSystem.getInstance(fileName);
fs.delete(fileName);
FileObject file = fs.openFileObject(fileName, "rw");
byte[] b = "a,b,c,d\n201,-2,0,18\n, \"abc\"\"\" ,,\"\"\n 1 ,2 , 3, 4 \n5, 6, 7, 8".getBytes();
file.write(b, 0, b.length);
file.close();
ResultSet rs = Csv.getInstance().read(baseDir + "/test.csv", null, "UTF8");
ResultSet rs = Csv.getInstance().read(fileName, null, "UTF8");
ResultSetMetaData meta = rs.getMetaData();
assertEquals(4, meta.getColumnCount());
assertEquals("a", meta.getColumnLabel(1));
......@@ -303,7 +311,7 @@ public class TestCsv extends TestBase {
// 201,2,0,18
// 201,2,0,18
// 201,2,0,18
FileUtils.delete(baseDir + "/test.csv");
fs.delete(fileName);
}
private void testWriteRead() throws SQLException {
......
......@@ -31,8 +31,8 @@ public class TestEncryptedDb extends TestBase {
if (config.memory || config.cipher != null) {
return;
}
deleteDb("exclusive");
Connection conn = getConnection("exclusive;CIPHER=AES", "sa", "123 123");
deleteDb("encrypted");
Connection conn = getConnection("encrypted;CIPHER=AES", "sa", "123 123");
Statement stat = conn.createStatement();
stat.execute("CREATE TABLE TEST(ID INT)");
stat.execute("CHECKPOINT");
......@@ -46,13 +46,13 @@ public class TestEncryptedDb extends TestBase {
}
try {
getConnection("exclusive;CIPHER=AES", "sa", "1234 1234");
getConnection("encrypted;CIPHER=AES", "sa", "1234 1234");
fail();
} catch (SQLException e) {
assertKnownException(e);
}
conn = getConnection("exclusive;CIPHER=AES", "sa", "123 123");
conn = getConnection("encrypted;CIPHER=AES", "sa", "123 123");
stat = conn.createStatement();
ResultSet rs = stat.executeQuery("SELECT * FROM TEST");
assertTrue(rs.next());
......@@ -60,7 +60,7 @@ public class TestEncryptedDb extends TestBase {
assertFalse(rs.next());
conn.close();
deleteDb("exclusive");
deleteDb("encrypted");
}
}
......@@ -7,10 +7,9 @@
package org.h2.test.db;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.math.BigDecimal;
import java.sql.Blob;
import java.sql.Connection;
......@@ -27,6 +26,7 @@ import java.util.UUID;
import org.h2.api.AggregateFunction;
import org.h2.test.TestBase;
import org.h2.tools.SimpleResultSet;
import org.h2.util.FileUtils;
import org.h2.util.IOUtils;
import org.h2.util.New;
......@@ -224,26 +224,26 @@ public class TestFunctions extends TestBase implements AggregateFunction {
private void testFileRead() throws Exception {
Connection conn = getConnection("functions");
Statement stat = conn.createStatement();
File f = new File(baseDir + "/test.txt");
String fileName = baseDir + "/test.txt";
Properties prop = System.getProperties();
FileOutputStream out = new FileOutputStream(f);
OutputStream out = FileUtils.openFileOutputStream(fileName, false);
prop.store(out, "");
out.close();
ResultSet rs = stat.executeQuery("SELECT LENGTH(FILE_READ('" + baseDir + "/test.txt')) LEN");
ResultSet rs = stat.executeQuery("SELECT LENGTH(FILE_READ('" + fileName + "')) LEN");
rs.next();
assertEquals(f.length(), rs.getInt(1));
rs = stat.executeQuery("SELECT FILE_READ('" + baseDir + "/test.txt') PROP");
assertEquals(FileUtils.length(fileName), rs.getInt(1));
rs = stat.executeQuery("SELECT FILE_READ('" + fileName + "') PROP");
rs.next();
Properties p2 = new Properties();
p2.load(rs.getBinaryStream(1));
assertEquals(prop.size(), p2.size());
rs = stat.executeQuery("SELECT FILE_READ('" + baseDir + "/test.txt', NULL) PROP");
rs = stat.executeQuery("SELECT FILE_READ('" + fileName + "', NULL) PROP");
rs.next();
String ps = rs.getString(1);
FileReader r = new FileReader(f);
InputStreamReader r = new InputStreamReader(FileUtils.openFileInputStream(fileName));
String ps2 = IOUtils.readStringAndClose(r, -1);
assertEquals(ps, ps2);
f.delete();
FileUtils.delete(fileName);
conn.close();
}
......
......@@ -586,7 +586,7 @@ public class TestLinkedTable extends TestBase {
}
private void testLinkedTableInReadOnlyDb() throws SQLException {
if (config.memory || config.networked) {
if (config.memory || config.networked || config.googleAppEngine) {
return;
}
......
......@@ -8,7 +8,6 @@ package org.h2.test.db;
import java.io.ByteArrayInputStream;
import java.io.CharArrayReader;
import java.io.File;
import java.io.InputStream;
import java.io.Reader;
import java.io.StringReader;
......@@ -27,6 +26,7 @@ import org.h2.constant.SysProperties;
import org.h2.store.FileLister;
import org.h2.test.TestBase;
import org.h2.tools.DeleteDbFiles;
import org.h2.util.FileUtils;
import org.h2.util.IOUtils;
import org.h2.util.ObjectUtils;
import org.h2.util.StringUtils;
......@@ -114,10 +114,10 @@ public class TestLob extends TestBase {
Connection conn = getConnection("lob");
Statement stat = conn.createStatement();
stat.execute("create table test(data clob) as select space(100000) from dual");
assertEquals(1, new File(baseDir + "/lob.lobs.db").listFiles().length);
assertEquals(1, FileUtils.listFiles(baseDir + "/lob.lobs.db").length);
stat.execute("delete from test");
conn.close();
assertEquals(0, new File(baseDir + "/lob.lobs.db").listFiles().length);
assertEquals(0, FileUtils.listFiles(baseDir + "/lob.lobs.db").length);
}
private void testLobServerMemory() throws SQLException {
......
......@@ -16,6 +16,7 @@ import java.util.ArrayList;
import org.h2.constant.SysProperties;
import org.h2.store.FileLister;
import org.h2.test.TestBase;
import org.h2.util.FileUtils;
/**
* Tests the database transaction log file.
......@@ -75,10 +76,10 @@ public class TestLogFile extends TestBase {
deleteDb("logfile");
}
private void checkLogSize() {
for (String name : new File(getTestDir("")).list()) {
private void checkLogSize() throws SQLException {
for (String name : FileUtils.listFiles(getTestDir(""))) {
if (name.startsWith("logfile") && name.endsWith(".log.db")) {
long length = new File(name).length();
long length = FileUtils.length(name);
assertSmaller(length, MAX_LOG_SIZE * 1024 * 1024 * 2);
}
}
......
......@@ -129,7 +129,7 @@ public class TestMultiConn extends TestBase implements DatabaseEventListener {
}
private void testConcurrentOpen() throws Exception {
if (config.memory) {
if (config.memory || config.googleAppEngine) {
return;
}
deleteDb("multiConn");
......
......@@ -46,7 +46,7 @@ public class TestPowerOff extends TestBase {
if (config.memory || config.logMode == 0) {
return;
}
if (config.big) {
if (config.big || config.googleAppEngine) {
dir = baseDir;
} else {
dir = "memFS:";
......
......@@ -37,7 +37,9 @@ public class TestReadOnly extends TestBase {
return;
}
testReadOnlyDbCreate();
testReadOnlyFiles(true);
if (!config.googleAppEngine) {
testReadOnlyFiles(true);
}
if (!config.deleteIndex) {
testReadOnlyFiles(false);
}
......
......@@ -6,7 +6,6 @@
*/
package org.h2.test.jdbc;
import java.io.File;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
......@@ -15,6 +14,8 @@ 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;
/**
......@@ -33,7 +34,7 @@ public class TestStatement extends TestBase {
TestBase.createCaller().init().test();
}
public void test() throws SQLException {
public void test() throws Exception {
deleteDb("statement");
conn = getConnection("statement");
testTraceError();
......@@ -50,12 +51,13 @@ public class TestStatement extends TestBase {
deleteDb("statement");
}
private void testTraceError() throws SQLException {
private void testTraceError() throws Exception {
if (config.memory || config.networked || config.traceLevelFile != 0) {
return;
}
Statement stat = conn.createStatement();
File trace = new File(baseDir + "/statement.trace.db");
String fileName = baseDir + "/statement.trace.db";
FileObject trace = FileSystem.getInstance(fileName).openFileObject(fileName, "r");
stat.execute("DROP TABLE TEST IF EXISTS");
stat.execute("CREATE TABLE TEST(ID INT PRIMARY KEY)");
stat.execute("INSERT INTO TEST VALUES(1)");
......
......@@ -129,7 +129,7 @@ public class TestFile extends TestBase implements DataHandler {
mem.close();
file.close();
}
FileUtils.delete("inmemory:test");
FileUtils.delete(prefix + "test");
FileUtils.delete("~/testFile");
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论