提交 9752cf23 authored 作者: Thomas Mueller's avatar Thomas Mueller

Tests

上级 f0ab8c9e
......@@ -70,7 +70,8 @@ public class TestDrop extends TestBase {
stat.execute("set schema public");
stat.execute("create schema test_run");
stat.execute("set schema test_run");
stat.execute("create table test2 (vid int, address varchar(20), constraint a_cons check (vid in (select id from table_view.test1)))");
stat.execute("create table test2 (id int, address varchar(20), " +
"constraint a_cons check (id in (select id from table_view.test1)))");
stat.execute("set schema public");
stat.execute("drop all objects");
}
......
......@@ -42,23 +42,31 @@ public class TestDuplicateKeyUpdate extends TestBase {
Statement stat = conn.createStatement();
ResultSet rs;
stat.execute("CREATE TABLE `table_test` (\n" + " `id` bigint(20) NOT NULL ,\n"
+ " `a_text` varchar(254) NOT NULL,\n" + " `some_text` varchar(254) NULL,\n"
+ " PRIMARY KEY (`id`)\n" + ") ;");
stat.execute("INSERT INTO table_test ( id, a_text, some_text ) VALUES (1, 'aaaaaaaaaa', 'aaaaaaaaaa')");
stat.execute("INSERT INTO table_test ( id, a_text, some_text ) VALUES (2, 'bbbbbbbbbb', 'bbbbbbbbbb')");
stat.execute("INSERT INTO table_test ( id, a_text, some_text ) VALUES (3, 'cccccccccc', 'cccccccccc')");
stat.execute("INSERT INTO table_test ( id, a_text, some_text ) VALUES (4, 'dddddddddd', 'dddddddddd')");
stat.execute("INSERT INTO table_test ( id, a_text, some_text ) VALUES (5, 'eeeeeeeeee', 'eeeeeeeeee')");
stat.execute("INSERT INTO table_test ( id , a_text, some_text ) VALUES (1, 'zzzzzzzzzz', 'abcdefghij') ON DUPLICATE KEY UPDATE some_text='UPDATE'");
stat.execute("CREATE TABLE `table_test` (\n" +
" `id` bigint(20) NOT NULL ,\n" +
" `a_text` varchar(254) NOT NULL,\n" +
" `some_text` varchar(254) NULL,\n" +
" PRIMARY KEY (`id`)\n" +
") ;");
stat.execute("INSERT INTO table_test ( id, a_text, some_text ) VALUES " +
"(1, 'aaaaaaaaaa', 'aaaaaaaaaa'), " +
"(2, 'bbbbbbbbbb', 'bbbbbbbbbb'), "+
"(3, 'cccccccccc', 'cccccccccc'), " +
"(4, 'dddddddddd', 'dddddddddd'), " +
"(5, 'eeeeeeeeee', 'eeeeeeeeee')");
stat.execute("INSERT INTO table_test ( id , a_text, some_text ) " +
"VALUES (1, 'zzzzzzzzzz', 'abcdefghij') " +
"ON DUPLICATE KEY UPDATE some_text='UPDATE'");
rs = stat.executeQuery("SELECT some_text FROM table_test where id = 1");
rs.next();
assertEquals("UPDATE", rs.getNString(1));
stat.execute("INSERT INTO table_test ( id , a_text, some_text ) VALUES (3, 'zzzzzzzzzz', 'SOME TEXT') ON DUPLICATE KEY UPDATE some_text=values(some_text)");
stat.execute("INSERT INTO table_test ( id , a_text, some_text ) " +
"VALUES (3, 'zzzzzzzzzz', 'SOME TEXT') " +
"ON DUPLICATE KEY UPDATE some_text=values(some_text)");
rs = stat.executeQuery("SELECT some_text FROM table_test where id = 3");
rs.next();
assertEquals("SOME TEXT", rs.getNString(1));
......@@ -80,36 +88,47 @@ public class TestDuplicateKeyUpdate extends TestBase {
stat.execute("INSERT INTO table_test2 ( a_text, some_text, updatable_text ) VALUES ('d', 'd', '4')");
stat.execute("INSERT INTO table_test2 ( a_text, some_text, updatable_text ) VALUES ('e', 'e', '5')");
stat.execute("INSERT INTO table_test2 ( a_text, some_text ) VALUES ('e', 'e') ON DUPLICATE KEY UPDATE updatable_text='UPDATE'");
stat.execute("INSERT INTO table_test2 ( a_text, some_text ) " +
"VALUES ('e', 'e') ON DUPLICATE KEY UPDATE updatable_text='UPDATE'");
rs = stat.executeQuery("SELECT updatable_text FROM table_test2 where a_text = 'e'");
rs.next();
assertEquals("UPDATE", rs.getNString(1));
stat.execute("INSERT INTO table_test2 (a_text, some_text, updatable_text ) VALUES ('b', 'b', 'jfno') ON DUPLICATE KEY UPDATE updatable_text=values(updatable_text)");
stat.execute("INSERT INTO table_test2 (a_text, some_text, updatable_text ) " +
"VALUES ('b', 'b', 'test') " +
"ON DUPLICATE KEY UPDATE updatable_text=values(updatable_text)");
rs = stat.executeQuery("SELECT updatable_text FROM table_test2 where a_text = 'b'");
rs.next();
assertEquals("jfno", rs.getNString(1));
assertEquals("test", rs.getNString(1));
}
private void testDuplicateCache(Connection conn) throws SQLException {
Statement stat = conn.createStatement();
ResultSet rs;
stat.execute("CREATE TABLE `table_test3` (\n" + " `id` bigint(20) NOT NULL ,\n"
+ " `a_text` varchar(254) NOT NULL,\n" + " `some_text` varchar(254) NULL,\n"
+ " PRIMARY KEY (`id`)\n" + ") ;");
stat.execute("CREATE TABLE `table_test3` (\n" +
" `id` bigint(20) NOT NULL ,\n" +
" `a_text` varchar(254) NOT NULL,\n" +
" `some_text` varchar(254) NULL,\n" +
" PRIMARY KEY (`id`)\n" +
") ;");
stat.execute("INSERT INTO table_test3 ( id, a_text, some_text ) VALUES (1, 'aaaaaaaaaa', 'aaaaaaaaaa')");
stat.execute("INSERT INTO table_test3 ( id, a_text, some_text ) " +
"VALUES (1, 'aaaaaaaaaa', 'aaaaaaaaaa')");
stat.execute("INSERT INTO table_test3 ( id , a_text, some_text ) VALUES (1, 'zzzzzzzzzz', 'SOME TEXT') ON DUPLICATE KEY UPDATE some_text=values(some_text)");
stat.execute("INSERT INTO table_test3 ( id , a_text, some_text ) " +
"VALUES (1, 'zzzzzzzzzz', 'SOME TEXT') " +
"ON DUPLICATE KEY UPDATE some_text=values(some_text)");
rs = stat.executeQuery("SELECT some_text FROM table_test3 where id = 1");
rs.next();
assertEquals("SOME TEXT", rs.getNString(1));
// Execute twice the same query to use the one from cache without
// parsing, caused the values parameter to be seen as ammbiguous
stat.execute("INSERT INTO table_test3 ( id , a_text, some_text ) VALUES (1, 'zzzzzzzzzz', 'SOME TEXT') ON DUPLICATE KEY UPDATE some_text=values(some_text)");
// parsing, caused the values parameter to be seen as ambiguous
stat.execute("INSERT INTO table_test3 ( id , a_text, some_text ) " +
"VALUES (1, 'zzzzzzzzzz', 'SOME TEXT') " +
"ON DUPLICATE KEY UPDATE some_text=values(some_text)");
rs = stat.executeQuery("SELECT some_text FROM table_test3 where id = 1");
rs.next();
assertEquals("SOME TEXT", rs.getNString(1));
......@@ -119,16 +138,24 @@ public class TestDuplicateKeyUpdate extends TestBase {
Statement stat = conn.createStatement();
ResultSet rs;
stat.execute("CREATE TABLE `table_test4` (\n" + " `id` bigint(20) NOT NULL ,\n"
+ " `a_text` varchar(254) NOT NULL,\n" + " `some_value` int(10) NULL,\n" + " PRIMARY KEY (`id`)\n"
+ ") ;");
stat.execute("INSERT INTO table_test4 ( id, a_text, some_value ) VALUES (1, 'aaaaaaaaaa', 5)");
stat.execute("INSERT INTO table_test4 ( id, a_text, some_value ) VALUES (2, 'aaaaaaaaaa', 5)");
stat.execute("INSERT INTO table_test4 ( id , a_text, some_value ) VALUES (1, 'b', 1) ON DUPLICATE KEY UPDATE some_value=some_value + values(some_value)");
stat.execute("INSERT INTO table_test4 ( id , a_text, some_value ) VALUES (1, 'b', 1) ON DUPLICATE KEY UPDATE some_value=some_value + 100");
stat.execute("INSERT INTO table_test4 ( id , a_text, some_value ) VALUES (2, 'b', 1) ON DUPLICATE KEY UPDATE some_value=values(some_value) + 1");
stat.execute("CREATE TABLE `table_test4` (\n" +
" `id` bigint(20) NOT NULL ,\n" +
" `a_text` varchar(254) NOT NULL,\n" +
" `some_value` int(10) NULL,\n" +
" PRIMARY KEY (`id`)\n" +
") ;");
stat.execute("INSERT INTO table_test4 ( id, a_text, some_value ) " +
"VALUES (1, 'aaaaaaaaaa', 5)");
stat.execute("INSERT INTO table_test4 ( id, a_text, some_value ) " +
"VALUES (2, 'aaaaaaaaaa', 5)");
stat.execute("INSERT INTO table_test4 ( id , a_text, some_value ) VALUES (1, 'b', 1) " +
"ON DUPLICATE KEY UPDATE some_value=some_value + values(some_value)");
stat.execute("INSERT INTO table_test4 ( id , a_text, some_value ) VALUES (1, 'b', 1) " +
"ON DUPLICATE KEY UPDATE some_value=some_value + 100");
stat.execute("INSERT INTO table_test4 ( id , a_text, some_value ) VALUES (2, 'b', 1) " +
"ON DUPLICATE KEY UPDATE some_value=values(some_value) + 1");
rs = stat.executeQuery("SELECT some_value FROM table_test4 where id = 1");
rs.next();
assertEquals(106, rs.getInt(1));
......
......@@ -28,6 +28,7 @@ import java.util.ArrayList;
import java.util.Calendar;
import java.util.Currency;
import java.util.Date;
import java.util.HashMap;
import java.util.Locale;
import java.util.Properties;
import java.util.TimeZone;
......@@ -702,7 +703,22 @@ public class TestFunctions extends TestBase implements AggregateFunction {
assertEquals(2, array.length);
assertEquals(0, ((Integer) array[0]).intValue());
assertEquals("Hello", (String) array[1]);
ResultSet rs2 = a.getResultSet();
assertThrows(ErrorCode.INVALID_VALUE_2, a).getArray(1, -1);
assertThrows(ErrorCode.INVALID_VALUE_2, a).getArray(1, 3);
assertEquals(0, ((Object[]) a.getArray(1, 0)).length);
assertEquals(0, ((Object[]) a.getArray(2, 0)).length);
assertThrows(ErrorCode.INVALID_VALUE_2, a).getArray(0, 0);
assertThrows(ErrorCode.INVALID_VALUE_2, a).getArray(3, 0);
HashMap<String, Class<?>> map = New.hashMap();
assertEquals(0, ((Object[]) a.getArray(1, 0, map)).length);
assertEquals(2, ((Object[]) a.getArray(map)).length);
assertEquals(2, ((Object[]) a.getArray(null)).length);
map.put("x", Object.class);
assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, a).getArray(1, 0, map);
assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, a).getArray(map);
ResultSet rs2;
rs2 = a.getResultSet();
rs2.next();
assertEquals(1, rs2.getInt(1));
assertEquals(0, rs2.getInt(2));
......@@ -711,6 +727,36 @@ public class TestFunctions extends TestBase implements AggregateFunction {
assertEquals("Hello", rs2.getString(2));
assertFalse(rs.next());
map.clear();
rs2 = a.getResultSet(map);
rs2.next();
assertEquals(1, rs2.getInt(1));
assertEquals(0, rs2.getInt(2));
rs2.next();
assertEquals(2, rs2.getInt(1));
assertEquals("Hello", rs2.getString(2));
assertFalse(rs.next());
rs2 = a.getResultSet(2, 1);
rs2.next();
assertEquals(2, rs2.getInt(1));
assertEquals("Hello", rs2.getString(2));
assertFalse(rs.next());
rs2 = a.getResultSet(1, 1, map);
rs2.next();
assertEquals(1, rs2.getInt(1));
assertEquals(0, rs2.getInt(2));
assertFalse(rs.next());
map.put("x", Object.class);
assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, a).getResultSet(map);
assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, a).getResultSet(0, 1, map);
a.free();
assertThrows(ErrorCode.OBJECT_CLOSED, a).getArray();
assertThrows(ErrorCode.OBJECT_CLOSED, a).getResultSet();
stat.execute("CREATE ALIAS ROOT FOR \"" + getClass().getName() + ".root\"");
rs = stat.executeQuery("CALL ROOT(9)");
rs.next();
......@@ -1174,12 +1220,12 @@ public class TestFunctions extends TestBase implements AggregateFunction {
assertResult(" 230 ", stat, "SELECT TO_CHAR(230, '999PR') FROM DUAL");
assertResult("230", stat, "SELECT TO_CHAR(230, 'FM999PR') FROM DUAL");
assertResult("0", stat, "SELECT TO_CHAR(0, 'fm999pr') FROM DUAL");
assertResult(" CCXXXVIII", stat, "SELECT TO_CHAR(238, 'RN') FROM DUAL");
assertResult("CCXXXVIII", stat, "SELECT TO_CHAR(238, 'FMRN') FROM DUAL");
assertResult("cxlix", stat, "SELECT TO_CHAR(149, 'FMrN') FROM DUAL");
assertResult(" MCMLXXIX", stat, "SELECT TO_CHAR(1979, 'RN') FROM DUAL;");
assertResult(" xliv", stat, "SELECT TO_CHAR(44, 'rN') FROM DUAL");
assertResult(" mdcclxxvi", stat, "SELECT TO_CHAR(1776, 'rn') FROM DUAL");
assertResult(" XI", stat, "SELECT TO_CHAR(11, 'RN') FROM DUAL");
assertResult("XI", stat, "SELECT TO_CHAR(11, 'FMRN') FROM DUAL");
assertResult("xi", stat, "SELECT TO_CHAR(11, 'FMrN') FROM DUAL");
assertResult(" XI", stat, "SELECT TO_CHAR(11, 'RN') FROM DUAL;");
assertResult(" xi", stat, "SELECT TO_CHAR(11, 'rN') FROM DUAL");
assertResult(" xi", stat, "SELECT TO_CHAR(11, 'rn') FROM DUAL");
assertResult(" +42", stat, "SELECT TO_CHAR(42, 'S999') FROM DUAL");
assertResult(" +42", stat, "SELECT TO_CHAR(42, 's999') FROM DUAL");
assertResult(" 42+", stat, "SELECT TO_CHAR(42, '999S') FROM DUAL");
......
......@@ -1561,7 +1561,7 @@ public class TestLob extends TestBase {
buffer[count] = ch;
}
} else if (ch >= 56192 && ch <= 56319) {
// private high surrogate, no effing clue, so skip it
// private high surrogate: no clue, so skip it
count++;
} else {
buffer[count] = ch;
......
......@@ -34,7 +34,7 @@ import org.h2.value.ValueGeometry;
*/
public class TestSpatial extends TestBase {
String url = "spatial";
private String url = "spatial";
/**
* Run just this test.
......@@ -51,14 +51,19 @@ public class TestSpatial extends TestBase {
return;
}
if (DataType.GEOMETRY_CLASS != null) {
deleteDb("spatial");
url = "spatial";
testSpatial();
deleteDb("spatial");
if (!config.mvcc) {
url = "spatial;MV_STORE=false";
testSpatial();
deleteDb("spatial");
}
}
}
private void testSpatial() throws SQLException {
testSpatialValues();
......@@ -626,12 +631,19 @@ public class TestSpatial extends TestBase {
deleteDb("spatial");
}
/**
* This method is called via reflection from the database.
*
* @param x the x position of the point
* @param y the y position of the point
* @return a result set with this point
*/
public static ResultSet pointTable(double x, double y) {
GeometryFactory factory = new GeometryFactory();
SimpleResultSet srs = new SimpleResultSet();
srs.addColumn("THE_GEOM", Types.JAVA_OBJECT, "GEOMETRY", 0, 0);
srs.addRow(factory.createPoint(new Coordinate(x, y)));
return srs;
SimpleResultSet rs = new SimpleResultSet();
rs.addColumn("THE_GEOM", Types.JAVA_OBJECT, "GEOMETRY", 0, 0);
rs.addRow(factory.createPoint(new Coordinate(x, y)));
return rs;
}
}
......@@ -377,6 +377,7 @@ public class TestCallableStatement extends TestBase {
* @param a the value a
* @param b the value b
* @param c the value c
* @param d the value d
* @return a result set
*/
public static ResultSet testCall(Connection conn, int a, String b, Timestamp c, Timestamp d) throws SQLException {
......
......@@ -1034,24 +1034,41 @@ public class TestPreparedStatement extends TestBase {
rs.next();
assertEquals(1, rs.getInt(1));
assertFalse(rs.next());
prep = conn.prepareStatement("INSERT INTO TEST VALUES(NEXT VALUE FOR SEQ)", Statement.RETURN_GENERATED_KEYS);
prep = conn.prepareStatement("INSERT INTO TEST VALUES(NEXT VALUE FOR SEQ)",
Statement.RETURN_GENERATED_KEYS);
prep.execute();
rs = prep.getGeneratedKeys();
rs.next();
assertEquals(2, rs.getInt(1));
assertFalse(rs.next());
prep = conn.prepareStatement("INSERT INTO TEST VALUES(NEXT VALUE FOR SEQ)", new int[] { 1 });
prep = conn.prepareStatement("INSERT INTO TEST VALUES(NEXT VALUE FOR SEQ)",
new int[] { 1 });
prep.execute();
rs = prep.getGeneratedKeys();
rs.next();
assertEquals(3, rs.getInt(1));
assertFalse(rs.next());
prep = conn.prepareStatement("INSERT INTO TEST VALUES(NEXT VALUE FOR SEQ)", new String[] { "ID" });
prep = conn.prepareStatement("INSERT INTO TEST VALUES(NEXT VALUE FOR SEQ)",
new String[] { "ID" });
prep.execute();
rs = prep.getGeneratedKeys();
rs.next();
assertEquals(4, rs.getInt(1));
assertFalse(rs.next());
prep = conn.prepareStatement("INSERT INTO TEST VALUES(NEXT VALUE FOR SEQ)",
ResultSet.TYPE_FORWARD_ONLY,
ResultSet.CONCUR_READ_ONLY,
ResultSet.HOLD_CURSORS_OVER_COMMIT);
prep.execute();
rs = prep.getGeneratedKeys();
rs.next();
assertEquals(5, rs.getInt(1));
assertFalse(rs.next());
stat.execute("DROP TABLE TEST");
}
......
......@@ -8,14 +8,19 @@ package org.h2.test.jdbc;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLClientInfoException;
import java.sql.SQLException;
import java.sql.Savepoint;
import java.sql.Statement;
import java.util.HashMap;
import java.util.Properties;
import org.h2.constant.ErrorCode;
import org.h2.constant.SysProperties;
import org.h2.jdbc.JdbcStatement;
import org.h2.store.fs.FileUtils;
import org.h2.test.TestBase;
import org.h2.util.New;
/**
* Tests for the Statement implementation.
......@@ -52,6 +57,15 @@ public class TestStatement extends TestBase {
Statement stat = conn.createStatement();
assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, stat).isWrapperFor(Object.class);
assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, stat).unwrap(Object.class);
conn.setTypeMap(null);
HashMap<String, Class<?>> map = New.hashMap();
conn.setTypeMap(map);
map.put("x", Object.class);
assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, conn).setTypeMap(map);
assertThrows(SQLClientInfoException.class, conn).setClientInfo("X", "Y");
assertThrows(SQLClientInfoException.class, conn).setClientInfo(new Properties());
}
private void testTraceError() throws Exception {
......@@ -120,6 +134,7 @@ public class TestStatement extends TestBase {
assertTrue(id1 != id2);
stat.execute("UPDATE TEST SET NAME='Hallo' WHERE NAME='Hello'");
Savepoint savepointTest = conn.setSavepoint("Joe's");
assertTrue(savepointTest.toString().endsWith("name=Joe's"));
stat.execute("DELETE FROM TEST");
assertEquals(savepointTest.getSavepointName(), "Joe's");
assertThrows(ErrorCode.SAVEPOINT_IS_NAMED, savepointTest).
......@@ -145,6 +160,10 @@ public class TestStatement extends TestBase {
conn.setHoldability(ResultSet.CLOSE_CURSORS_AT_COMMIT);
assertEquals(ResultSet.CLOSE_CURSORS_AT_COMMIT, conn.getHoldability());
assertFalse(stat.isPoolable());
stat.setPoolable(true);
assertFalse(stat.isPoolable());
// ignored
stat.setCursorName("x");
// fixed return value
......
......@@ -502,7 +502,16 @@ public class TestUpdatableResultSet extends TestBase {
for (int i = 0; i < max; i++) {
stat.execute("INSERT INTO TEST VALUES(" + i + ", 'Hello" + i + "')");
}
ResultSet rs = stat.executeQuery("SELECT * FROM TEST");
ResultSet rs;
rs = stat.executeQuery("SELECT * FROM TEST ORDER BY ID");
rs.next();
assertEquals(0, rs.getInt(1));
rs.moveToInsertRow();
rs.updateInt(1, 100);
rs.moveToCurrentRow();
assertEquals(0, rs.getInt(1));
rs = stat.executeQuery("SELECT * FROM TEST");
int j = max;
while (rs.next()) {
int id = rs.getInt(1);
......
......@@ -9,15 +9,8 @@ import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.Statement;
import org.h2.mvstore.Chunk;
import org.h2.mvstore.MVStore;
import org.h2.mvstore.Page;
import org.h2.mvstore.db.TransactionStore;
import org.h2.store.fs.FileUtils;
import org.h2.test.TestBase;
import org.h2.util.Profiler;
import org.h2.value.ValueLong;
import org.h2.value.ValueString;
/**
* Tests performance and helps analyze bottlenecks.
......@@ -44,6 +37,10 @@ public class TestBenchmark extends TestBase {
}
private void test(boolean mvStore) throws Exception {
;
// TODO this test is currently disabled
FileUtils.deleteRecursive(getBaseDir(), true);
Connection conn;
Statement stat;
......@@ -51,20 +48,18 @@ public class TestBenchmark extends TestBase {
if (mvStore) {
url += ";MV_STORE=TRUE;LOG=0";
}
// 2033 mvstore
// 2313 (2075?) default
url = getURL(url, true);
conn = getConnection(url);
stat = conn.createStatement();
stat.execute("create table test(id bigint primary key, name varchar)");
conn.setAutoCommit(false);
PreparedStatement prep = conn.prepareStatement("insert into test values(?, ?)");
PreparedStatement prep = conn
.prepareStatement("insert into test values(?, ?)");
String data = "Hello World";
int rowCount = 100000;
int readCount = 20* rowCount;
int readCount = 20 * rowCount;
for (int i = 0; i < rowCount; i++) {
prep.setInt(1, i);
......@@ -76,44 +71,16 @@ public class TestBenchmark extends TestBase {
}
long start = System.currentTimeMillis();
// Profiler prof = new Profiler();
// prof.sumClasses=true;
// prof.startCollecting();
;
prep = conn.prepareStatement("select * from test where id = ?");
for (int i = 0; i < readCount; i++) {
prep.setInt(1, i % rowCount);
prep.executeQuery();
}
//System.out.println("Transactionstore.counter " + ValueLong.counter);
//System.out.println("count " + Page.writeCount + " avgLen " + (1.0*Page.writeLength/Page.writeCount) + " avgSize " + (1.0*Page.writeSize/Page.writeCount));
//System.out.println(prof.getTop(5));
//System.out.println("ountUnc:" + counterUnc);
//System.out.println("ount:" + counter);
System.out.println((System.currentTimeMillis() - start) + " " + (mvStore ? "mvstore" : "default"));
System.out.println((System.currentTimeMillis() - start) + " "
+ (mvStore ? "mvstore" : "default"));
conn.close();
// MVStore s = new MVStore.Builder().fileName(getBaseDir() + "/mvstore.mv.db").open();
// int count = 0;
// long length = 0;
// for(String k : s.getMetaMap().keyList()) {
// if (k.startsWith("chunk.")) {
// String x = s.getMetaMap().get(k);
// Chunk c = Chunk.fromString(x);
// if (c.length < Integer.MAX_VALUE) {
// count++;
// length += c.length;
// }
// }
// }
// if (count > 0) {
// System.out.println("chunks: " + count + " average length: " + (length / count));
// }
// s.close();
}
}
......@@ -38,6 +38,7 @@ public class TestBnf extends TestBase {
deleteDb("bnf");
Connection conn = getConnection("bnf");
try {
testModes(conn);
testProcedures(conn, false);
} finally {
conn.close();
......@@ -50,6 +51,34 @@ public class TestBnf extends TestBase {
}
}
private void testModes(Connection conn) throws Exception {
DbContents dbContents;
dbContents = new DbContents();
dbContents.readContents("jdbc:h2:test", conn);
assertTrue(dbContents.isH2());
dbContents = new DbContents();
dbContents.readContents("jdbc:derby:test", conn);
assertTrue(dbContents.isDerby());
dbContents = new DbContents();
dbContents.readContents("jdbc:firebirdsql:test", conn);
assertTrue(dbContents.isFirebird());
dbContents = new DbContents();
dbContents.readContents("jdbc:sqlserver:test", conn);
assertTrue(dbContents.isMSSQLServer());
dbContents = new DbContents();
dbContents.readContents("jdbc:mysql:test", conn);
assertTrue(dbContents.isMySQL());
dbContents = new DbContents();
dbContents.readContents("jdbc:oracle:test", conn);
assertTrue(dbContents.isOracle());
dbContents = new DbContents();
dbContents.readContents("jdbc:postgresql:test", conn);
assertTrue(dbContents.isPostgreSQL());
dbContents = new DbContents();
dbContents.readContents("jdbc:sqlite:test", conn);
assertTrue(dbContents.isSQLite());
}
private void testProcedures(Connection conn, boolean isMySQLMode) throws Exception {
// Register a procedure and check if it is present in DbContents
conn.createStatement().execute("DROP ALIAS IF EXISTS CUSTOM_PRINT");
......@@ -57,7 +86,7 @@ public class TestBnf extends TestBase {
conn.createStatement().execute("DROP TABLE IF EXISTS TABLE_WITH_STRING_FIELD");
conn.createStatement().execute("CREATE TABLE TABLE_WITH_STRING_FIELD (STRING_FIELD VARCHAR(50), INT_FIELD integer)");
DbContents dbContents = new DbContents();
dbContents.readContents(conn.getMetaData());
dbContents.readContents("jdbc:h2:test", conn);
assertTrue(dbContents.isH2());
assertFalse(dbContents.isDerby());
assertFalse(dbContents.isFirebird());
......
......@@ -31,6 +31,7 @@ import org.h2.mvstore.DataUtils;
import org.h2.mvstore.cache.FilePathCache;
import org.h2.store.fs.FilePath;
import org.h2.store.fs.FilePathEncrypt;
import org.h2.store.fs.FilePathRec;
import org.h2.store.fs.FileUtils;
import org.h2.test.TestBase;
import org.h2.test.utils.AssertThrows;
......@@ -65,6 +66,7 @@ public class TestFileSystem extends TestBase {
testUnsupportedFeatures(getBaseDir());
FilePathZip2.register();
FilePath.register(new FilePathCache());
FilePathRec.register();
testZipFileSystem("zip:");
testZipFileSystem("cache:zip:");
testZipFileSystem("zip2:");
......@@ -85,6 +87,7 @@ public class TestFileSystem extends TestBase {
testFileSystem("memLZF:");
testFileSystem("nioMemFS:");
testFileSystem("nioMemLZF:");
testFileSystem("rec:memFS:");
testUserHome();
try {
testFileSystem("nio:" + getBaseDir() + "/fs");
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论