提交 03fc1e6f authored 作者: Thomas Mueller's avatar Thomas Mueller

Allow to run most tests in parallel (not enabled right now)

上级 f6397d84
...@@ -18,6 +18,8 @@ import java.lang.reflect.InvocationTargetException; ...@@ -18,6 +18,8 @@ import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.lang.reflect.Modifier; import java.lang.reflect.Modifier;
import java.lang.reflect.Proxy; import java.lang.reflect.Proxy;
import java.nio.channels.FileChannel;
import java.nio.channels.FileLock;
import java.sql.Connection; import java.sql.Connection;
import java.sql.DriverManager; import java.sql.DriverManager;
import java.sql.ResultSet; import java.sql.ResultSet;
...@@ -32,8 +34,7 @@ import java.util.LinkedList; ...@@ -32,8 +34,7 @@ import java.util.LinkedList;
import java.util.SimpleTimeZone; import java.util.SimpleTimeZone;
import org.h2.jdbc.JdbcConnection; import org.h2.jdbc.JdbcConnection;
import org.h2.message.DbException; import org.h2.message.DbException;
import org.h2.message.TraceSystem; import org.h2.store.fs.FilePath;
import org.h2.store.FileLock;
import org.h2.store.fs.FileUtils; import org.h2.store.fs.FileUtils;
import org.h2.test.utils.ProxyCodeGenerator; import org.h2.test.utils.ProxyCodeGenerator;
import org.h2.test.utils.ResultVerifier; import org.h2.test.utils.ResultVerifier;
...@@ -52,7 +53,7 @@ public abstract class TestBase { ...@@ -52,7 +53,7 @@ public abstract class TestBase {
/** /**
* The temporary directory. * The temporary directory.
*/ */
protected static final String TEMP_DIR = "./data/temp"; private static final String TEMP_DIR = "./data/temp";
/** /**
* An id used to create unique file names. * An id used to create unique file names.
...@@ -115,6 +116,7 @@ public abstract class TestBase { ...@@ -115,6 +116,7 @@ public abstract class TestBase {
*/ */
public TestBase init(TestAll conf) throws Exception { public TestBase init(TestAll conf) throws Exception {
baseDir = getTestDir(""); baseDir = getTestDir("");
FileUtils.createDirectories(baseDir);
System.setProperty("java.io.tmpdir", TEMP_DIR); System.setProperty("java.io.tmpdir", TEMP_DIR);
this.config = conf; this.config = conf;
return this; return this;
...@@ -154,15 +156,6 @@ public abstract class TestBase { ...@@ -154,15 +156,6 @@ public abstract class TestBase {
if (e instanceof OutOfMemoryError) { if (e instanceof OutOfMemoryError) {
throw (OutOfMemoryError) e; throw (OutOfMemoryError) e;
} }
} finally {
try {
FileUtils.deleteRecursive("memFS:", false);
FileUtils.deleteRecursive("nioMemFS:", false);
FileUtils.deleteRecursive("memLZF:", false);
FileUtils.deleteRecursive("nioMemLZF:", false);
} catch (RuntimeException e) {
e.printStackTrace();
}
} }
} }
...@@ -473,19 +466,32 @@ public abstract class TestBase { ...@@ -473,19 +466,32 @@ public abstract class TestBase {
System.err.println("ERROR: " + s + " " + e.toString() System.err.println("ERROR: " + s + " " + e.toString()
+ " ------------------------------"); + " ------------------------------");
e.printStackTrace(); e.printStackTrace();
// synchronize on this class, because file locks are only visible to
// other JVMs
synchronized (TestBase.class) {
try { try {
TraceSystem ts = new TraceSystem(null); // lock
FileLock lock = new FileLock(ts, "error.lock", 1000); FileChannel fc = FilePath.get("error.lock").open("rw");
lock.lock(FileLock.LOCK_FILE); FileLock lock;
while (true) {
lock = fc.tryLock();
if (lock != null) {
break;
}
Thread.sleep(10);
}
// append
FileWriter fw = new FileWriter("error.txt", true); FileWriter fw = new FileWriter("error.txt", true);
PrintWriter pw = new PrintWriter(fw); PrintWriter pw = new PrintWriter(fw);
e.printStackTrace(pw); e.printStackTrace(pw);
pw.close(); pw.close();
fw.close(); fw.close();
lock.unlock(); // unlock
lock.release();
} catch (Throwable t) { } catch (Throwable t) {
t.printStackTrace(); t.printStackTrace();
} }
}
System.err.flush(); System.err.flush();
} }
...@@ -509,7 +515,7 @@ public abstract class TestBase { ...@@ -509,7 +515,7 @@ public abstract class TestBase {
* @param millis the time in milliseconds * @param millis the time in milliseconds
* @param s the message * @param s the message
*/ */
static void printlnWithTime(long millis, String s) { static synchronized void printlnWithTime(long millis, String s) {
SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss"); SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");
s = dateFormat.format(new java.util.Date()) + " " + s = dateFormat.format(new java.util.Date()) + " " +
formatTime(millis) + " " + s; formatTime(millis) + " " + s;
...@@ -1578,4 +1584,8 @@ public abstract class TestBase { ...@@ -1578,4 +1584,8 @@ public abstract class TestBase {
throw (E) e; throw (E) e;
} }
protected String getTestName() {
return getClass().getSimpleName();
}
} }
...@@ -33,8 +33,8 @@ public class TestAlter extends TestBase { ...@@ -33,8 +33,8 @@ public class TestAlter extends TestBase {
@Override @Override
public void test() throws Exception { public void test() throws Exception {
deleteDb("alter"); deleteDb(getTestName());
conn = getConnection("alter"); conn = getConnection(getTestName());
stat = conn.createStatement(); stat = conn.createStatement();
testAlterTableAlterColumnAsSelfColumn(); testAlterTableAlterColumnAsSelfColumn();
testAlterTableDropColumnWithReferences(); testAlterTableDropColumnWithReferences();
...@@ -49,7 +49,7 @@ public class TestAlter extends TestBase { ...@@ -49,7 +49,7 @@ public class TestAlter extends TestBase {
testAlterTableAddColumnAfter(); testAlterTableAddColumnAfter();
testAlterTableModifyColumn(); testAlterTableModifyColumn();
conn.close(); conn.close();
deleteDb("alter"); deleteDb(getTestName());
} }
private void testAlterTableAlterColumnAsSelfColumn() throws SQLException { private void testAlterTableAlterColumnAsSelfColumn() throws SQLException {
...@@ -121,7 +121,7 @@ public class TestAlter extends TestBase { ...@@ -121,7 +121,7 @@ public class TestAlter extends TestBase {
stat.execute("alter table test alter id rename to id2"); stat.execute("alter table test alter id rename to id2");
// disconnect and reconnect // disconnect and reconnect
conn.close(); conn.close();
conn = getConnection("alter"); conn = getConnection(getTestName());
stat = conn.createStatement(); stat = conn.createStatement();
stat.execute("insert into test values(1)"); stat.execute("insert into test values(1)");
assertThrows(ErrorCode.CHECK_CONSTRAINT_VIOLATED_1, stat). assertThrows(ErrorCode.CHECK_CONSTRAINT_VIOLATED_1, stat).
......
...@@ -32,8 +32,8 @@ public class TestAlterSchemaRename extends TestBase { ...@@ -32,8 +32,8 @@ public class TestAlterSchemaRename extends TestBase {
@Override @Override
public void test() throws Exception { public void test() throws Exception {
deleteDb("alter"); deleteDb(getTestName());
conn = getConnection("alter"); conn = getConnection(getTestName());
stat = conn.createStatement(); stat = conn.createStatement();
testTryToRenameSystemSchemas(); testTryToRenameSystemSchemas();
testSimpleRename(); testSimpleRename();
...@@ -41,7 +41,7 @@ public class TestAlterSchemaRename extends TestBase { ...@@ -41,7 +41,7 @@ public class TestAlterSchemaRename extends TestBase {
testCrossSchemaViews(); testCrossSchemaViews();
testAlias(); testAlias();
conn.close(); conn.close();
deleteDb("alter"); deleteDb(getTestName());
} }
private void testTryToRenameSystemSchemas() throws SQLException { private void testTryToRenameSystemSchemas() throws SQLException {
...@@ -93,7 +93,7 @@ public class TestAlterSchemaRename extends TestBase { ...@@ -93,7 +93,7 @@ public class TestAlterSchemaRename extends TestBase {
assertEquals(6, rs.getInt(1)); assertEquals(6, rs.getInt(1));
if (!config.memory) { if (!config.memory) {
conn.close(); conn.close();
conn = getConnection("alter"); conn = getConnection(getTestName());
stat = conn.createStatement(); stat = conn.createStatement();
stat.executeQuery("select * from s2_new.v1"); stat.executeQuery("select * from s2_new.v1");
} }
...@@ -116,7 +116,7 @@ public class TestAlterSchemaRename extends TestBase { ...@@ -116,7 +116,7 @@ public class TestAlterSchemaRename extends TestBase {
assertEquals("4321", rs.getString(1)); assertEquals("4321", rs.getString(1));
if (!config.memory) { if (!config.memory) {
conn.close(); conn.close();
conn = getConnection("alter"); conn = getConnection(getTestName());
stat = conn.createStatement(); stat = conn.createStatement();
stat.executeQuery("CALL S2.REVERSE('1234')"); stat.executeQuery("CALL S2.REVERSE('1234')");
} }
......
...@@ -21,7 +21,7 @@ import org.h2.tools.Server; ...@@ -21,7 +21,7 @@ import org.h2.tools.Server;
import org.h2.util.JdbcUtils; import org.h2.util.JdbcUtils;
/** /**
* Test for the cluster feature. * Test the cluster feature.
*/ */
public class TestCluster extends TestBase { public class TestCluster extends TestBase {
......
...@@ -6,12 +6,17 @@ ...@@ -6,12 +6,17 @@
package org.h2.test.db; package org.h2.test.db;
import java.sql.Connection; import java.sql.Connection;
import java.sql.Date;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.sql.Statement; import java.sql.Statement;
import java.sql.Time;
import java.sql.Timestamp; import java.sql.Timestamp;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.SimpleTimeZone;
import java.util.TimeZone; import java.util.TimeZone;
import org.h2.engine.SysProperties; import org.h2.engine.SysProperties;
...@@ -37,12 +42,116 @@ public class TestDateStorage extends TestBase { ...@@ -37,12 +42,116 @@ public class TestDateStorage extends TestBase {
@Override @Override
public void test() throws SQLException { public void test() throws SQLException {
deleteDb("date"); deleteDb(getTestName());
testDateTimeTimestampWithCalendar();
testMoveDatabaseToAnotherTimezone(); testMoveDatabaseToAnotherTimezone();
testAllTimeZones(); testAllTimeZones();
testCurrentTimeZone(); testCurrentTimeZone();
} }
private void testDateTimeTimestampWithCalendar() throws SQLException {
Connection conn = getConnection(getTestName());
Statement stat = conn.createStatement();
stat.execute("create table ts(x timestamp primary key)");
stat.execute("create table t(x time primary key)");
stat.execute("create table d(x date)");
Calendar utcCalendar = new GregorianCalendar(new SimpleTimeZone(0, "Z"));
TimeZone old = TimeZone.getDefault();
DateTimeUtils.resetCalendar();
TimeZone.setDefault(TimeZone.getTimeZone("PST"));
try {
Timestamp ts1 = Timestamp.valueOf("2010-03-13 18:15:00");
Time t1 = new Time(ts1.getTime());
Date d1 = new Date(ts1.getTime());
// when converted to UTC, this is 03:15, which doesn't actually
// exist because of summer time change at that day
Timestamp ts2 = Timestamp.valueOf("2010-03-13 19:15:00");
Time t2 = new Time(ts2.getTime());
Date d2 = new Date(ts2.getTime());
PreparedStatement prep;
ResultSet rs;
prep = conn.prepareStatement("insert into ts values(?)");
prep.setTimestamp(1, ts1, utcCalendar);
prep.execute();
prep.setTimestamp(1, ts2, utcCalendar);
prep.execute();
prep = conn.prepareStatement("insert into t values(?)");
prep.setTime(1, t1, utcCalendar);
prep.execute();
prep.setTime(1, t2, utcCalendar);
prep.execute();
prep = conn.prepareStatement("insert into d values(?)");
prep.setDate(1, d1, utcCalendar);
prep.execute();
prep.setDate(1, d2, utcCalendar);
prep.execute();
rs = stat.executeQuery("select * from ts order by x");
rs.next();
assertEquals("2010-03-14 02:15:00.0",
rs.getString(1));
assertEquals("2010-03-13 18:15:00.0",
rs.getTimestamp(1, utcCalendar).toString());
assertEquals("2010-03-14 03:15:00.0",
rs.getTimestamp(1).toString());
assertEquals("2010-03-14 02:15:00.0",
rs.getString("x"));
assertEquals("2010-03-13 18:15:00.0",
rs.getTimestamp("x", utcCalendar).toString());
assertEquals("2010-03-14 03:15:00.0",
rs.getTimestamp("x").toString());
rs.next();
assertEquals("2010-03-14 03:15:00.0",
rs.getString(1));
assertEquals("2010-03-13 19:15:00.0",
rs.getTimestamp(1, utcCalendar).toString());
assertEquals("2010-03-14 03:15:00.0",
rs.getTimestamp(1).toString());
assertEquals("2010-03-14 03:15:00.0",
rs.getString("x"));
assertEquals("2010-03-13 19:15:00.0",
rs.getTimestamp("x", utcCalendar).toString());
assertEquals("2010-03-14 03:15:00.0",
rs.getTimestamp("x").toString());
rs = stat.executeQuery("select * from t order by x");
rs.next();
assertEquals("02:15:00", rs.getString(1));
assertEquals("18:15:00", rs.getTime(1, utcCalendar).toString());
assertEquals("02:15:00", rs.getTime(1).toString());
assertEquals("02:15:00", rs.getString("x"));
assertEquals("18:15:00", rs.getTime("x", utcCalendar).toString());
assertEquals("02:15:00", rs.getTime("x").toString());
rs.next();
assertEquals("03:15:00", rs.getString(1));
assertEquals("19:15:00", rs.getTime(1, utcCalendar).toString());
assertEquals("03:15:00", rs.getTime(1).toString());
assertEquals("03:15:00", rs.getString("x"));
assertEquals("19:15:00", rs.getTime("x", utcCalendar).toString());
assertEquals("03:15:00", rs.getTime("x").toString());
rs = stat.executeQuery("select * from d order by x");
rs.next();
assertEquals("2010-03-14", rs.getString(1));
assertEquals("2010-03-13", rs.getDate(1, utcCalendar).toString());
assertEquals("2010-03-14", rs.getDate(1).toString());
assertEquals("2010-03-14", rs.getString("x"));
assertEquals("2010-03-13", rs.getDate("x", utcCalendar).toString());
assertEquals("2010-03-14", rs.getDate("x").toString());
rs.next();
assertEquals("2010-03-14", rs.getString(1));
assertEquals("2010-03-13", rs.getDate(1, utcCalendar).toString());
assertEquals("2010-03-14", rs.getDate(1).toString());
assertEquals("2010-03-14", rs.getString("x"));
assertEquals("2010-03-13", rs.getDate("x", utcCalendar).toString());
assertEquals("2010-03-14", rs.getDate("x").toString());
} finally {
TimeZone.setDefault(old);
DateTimeUtils.resetCalendar();
}
stat.execute("drop table ts");
stat.execute("drop table t");
stat.execute("drop table d");
conn.close();
}
private void testMoveDatabaseToAnotherTimezone() throws SQLException { private void testMoveDatabaseToAnotherTimezone() throws SQLException {
if (config.memory) { if (config.memory) {
return; return;
...@@ -50,7 +159,7 @@ public class TestDateStorage extends TestBase { ...@@ -50,7 +159,7 @@ public class TestDateStorage extends TestBase {
if (!SysProperties.STORE_LOCAL_TIME) { if (!SysProperties.STORE_LOCAL_TIME) {
return; return;
} }
String db = "date;LOG=0;FILE_LOCK=NO"; String db = getTestName() + ";LOG=0;FILE_LOCK=NO";
Connection conn = getConnection(db); Connection conn = getConnection(db);
Statement stat; Statement stat;
stat = conn.createStatement(); stat = conn.createStatement();
...@@ -128,7 +237,7 @@ public class TestDateStorage extends TestBase { ...@@ -128,7 +237,7 @@ public class TestDateStorage extends TestBase {
} }
private void testAllTimeZones() throws SQLException { private void testAllTimeZones() throws SQLException {
Connection conn = getConnection("date"); Connection conn = getConnection(getTestName());
TimeZone defaultTimeZone = TimeZone.getDefault(); TimeZone defaultTimeZone = TimeZone.getDefault();
PreparedStatement prep = conn.prepareStatement("CALL CAST(? AS DATE)"); PreparedStatement prep = conn.prepareStatement("CALL CAST(? AS DATE)");
try { try {
...@@ -146,7 +255,7 @@ public class TestDateStorage extends TestBase { ...@@ -146,7 +255,7 @@ public class TestDateStorage extends TestBase {
DateTimeUtils.resetCalendar(); DateTimeUtils.resetCalendar();
} }
conn.close(); conn.close();
deleteDb("date"); deleteDb(getTestName());
} }
private void test(PreparedStatement prep, int d) throws SQLException { private void test(PreparedStatement prep, int d) throws SQLException {
......
...@@ -94,11 +94,8 @@ public class TestFunctions extends TestBase implements AggregateFunction { ...@@ -94,11 +94,8 @@ public class TestFunctions extends TestBase implements AggregateFunction {
testToCharFromText(); testToCharFromText();
testTranslate(); testTranslate();
testGenerateSeries(); testGenerateSeries();
// TODO
// testCachingOfDeterministicFunctionAlias();
deleteDb("functions"); deleteDb("functions");
FileUtils.deleteRecursive(TEMP_DIR, true);
} }
private void testDataType() throws SQLException { private void testDataType() throws SQLException {
......
...@@ -22,14 +22,12 @@ import java.sql.ResultSet; ...@@ -22,14 +22,12 @@ 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 java.util.List;
import java.util.Random; import java.util.Random;
import org.h2.api.ErrorCode; import org.h2.api.ErrorCode;
import org.h2.engine.SysProperties; import org.h2.engine.SysProperties;
import org.h2.jdbc.JdbcConnection; import org.h2.jdbc.JdbcConnection;
import org.h2.message.DbException; import org.h2.message.DbException;
import org.h2.store.fs.FileUtils;
import org.h2.test.TestBase; import org.h2.test.TestBase;
import org.h2.util.IOUtils; import org.h2.util.IOUtils;
import org.h2.util.JdbcUtils; import org.h2.util.JdbcUtils;
...@@ -81,8 +79,6 @@ public class TestLob extends TestBase { ...@@ -81,8 +79,6 @@ public class TestLob extends TestBase {
testConvert(); testConvert();
testCreateAsSelect(); testCreateAsSelect();
testDelete(); testDelete();
testTempFilesDeleted(true);
testTempFilesDeleted(false);
testLobServerMemory(); testLobServerMemory();
testUpdatingLobRow(); testUpdatingLobRow();
if (config.memory) { if (config.memory) {
...@@ -110,7 +106,6 @@ public class TestLob extends TestBase { ...@@ -110,7 +106,6 @@ public class TestLob extends TestBase {
testLob(true); testLob(true);
testJavaObject(); testJavaObject();
deleteDb("lob"); deleteDb("lob");
FileUtils.deleteRecursive(TEMP_DIR, true);
} }
private void testRemovedAfterTimeout() throws Exception { private void testRemovedAfterTimeout() throws Exception {
...@@ -669,41 +664,6 @@ public class TestLob extends TestBase { ...@@ -669,41 +664,6 @@ public class TestLob extends TestBase {
conn.close(); conn.close();
} }
private void testTempFilesDeleted(boolean stream) throws Exception {
FileUtils.deleteRecursive(TEMP_DIR, true);
FileUtils.createDirectories(TEMP_DIR);
List<String> list = FileUtils.newDirectoryStream(TEMP_DIR);
assertEquals("Unexpected temp file: " + list, 0, list.size());
deleteDb("lob");
Connection conn = getConnection("lob");
Statement stat;
stat = conn.createStatement();
stat.execute("create table test(id int primary key, name text)");
PreparedStatement prep = conn.prepareStatement(
"insert into test values(2, ?)");
if (stream) {
String large = new String(new char[1024 * 1024 * 2]).replace((char) 0, 'x');
prep.setCharacterStream(1, new StringReader(large), -1);
large = null;
prep.execute();
} else {
stat.execute("insert into test values(1, space(100000))");
}
/*
list = FileUtils.newDirectoryStream(TEMP_DIR);
assertEquals("Unexpected temp file: " + list, 0, list.size());
*/
ResultSet rs;
rs = stat.executeQuery("select * from test");
while (rs.next()) {
rs.getCharacterStream("name").close();
}
prep.close();
conn.close();
list = FileUtils.newDirectoryStream(TEMP_DIR);
assertEquals("Unexpected temp file: " + list, 0, list.size());
}
private void testLobUpdateMany() throws SQLException { private void testLobUpdateMany() throws SQLException {
deleteDb("lob"); deleteDb("lob");
Connection conn = getConnection("lob"); Connection conn = getConnection("lob");
......
...@@ -64,7 +64,7 @@ public class TestMultiThread extends TestBase implements Runnable { ...@@ -64,7 +64,7 @@ public class TestMultiThread extends TestBase implements Runnable {
} }
private void testConcurrentSchemaChange() throws Exception { private void testConcurrentSchemaChange() throws Exception {
String db = "testConcurrentSchemaChange"; String db = getTestName();
deleteDb(db); deleteDb(db);
final String url = getURL(db + ";MULTI_THREADED=1", true); final String url = getURL(db + ";MULTI_THREADED=1", true);
Connection conn = getConnection(url); Connection conn = getConnection(url);
...@@ -98,7 +98,7 @@ public class TestMultiThread extends TestBase implements Runnable { ...@@ -98,7 +98,7 @@ public class TestMultiThread extends TestBase implements Runnable {
} }
private void testConcurrentLobAdd() throws Exception { private void testConcurrentLobAdd() throws Exception {
String db = "concurrentLobAdd"; String db = getTestName();
deleteDb(db); deleteDb(db);
final String url = getURL(db + ";MULTI_THREADED=1", true); final String url = getURL(db + ";MULTI_THREADED=1", true);
Connection conn = getConnection(url); Connection conn = getConnection(url);
...@@ -137,7 +137,7 @@ public class TestMultiThread extends TestBase implements Runnable { ...@@ -137,7 +137,7 @@ public class TestMultiThread extends TestBase implements Runnable {
if (config.mvcc) { if (config.mvcc) {
return; return;
} }
String db = "concurrentView"; String db = getTestName();
deleteDb(db); deleteDb(db);
final String url = getURL(db + ";MULTI_THREADED=1", true); final String url = getURL(db + ";MULTI_THREADED=1", true);
final Random r = new Random(); final Random r = new Random();
...@@ -176,8 +176,8 @@ public class TestMultiThread extends TestBase implements Runnable { ...@@ -176,8 +176,8 @@ public class TestMultiThread extends TestBase implements Runnable {
} }
private void testConcurrentAlter() throws Exception { private void testConcurrentAlter() throws Exception {
deleteDb("concurrentAlter"); deleteDb(getTestName());
final Connection conn = getConnection("concurrentAlter"); final Connection conn = getConnection(getTestName());
Statement stat = conn.createStatement(); Statement stat = conn.createStatement();
Task t = new Task() { Task t = new Task() {
@Override @Override
...@@ -195,14 +195,13 @@ public class TestMultiThread extends TestBase implements Runnable { ...@@ -195,14 +195,13 @@ public class TestMultiThread extends TestBase implements Runnable {
} }
t.get(); t.get();
conn.close(); conn.close();
deleteDb("concurrentAlter");
} }
private void testConcurrentAnalyze() throws Exception { private void testConcurrentAnalyze() throws Exception {
if (config.mvcc) { if (config.mvcc) {
return; return;
} }
deleteDb("concurrentAnalyze"); deleteDb(getTestName());
final String url = getURL("concurrentAnalyze;MULTI_THREADED=1", true); final String url = getURL("concurrentAnalyze;MULTI_THREADED=1", true);
Connection conn = getConnection(url); Connection conn = getConnection(url);
Statement stat = conn.createStatement(); Statement stat = conn.createStatement();
...@@ -227,7 +226,6 @@ public class TestMultiThread extends TestBase implements Runnable { ...@@ -227,7 +226,6 @@ public class TestMultiThread extends TestBase implements Runnable {
t.get(); t.get();
stat.execute("drop table test"); stat.execute("drop table test");
conn.close(); conn.close();
deleteDb("concurrentAnalyze");
} }
private void testConcurrentInsertUpdateSelect() throws Exception { private void testConcurrentInsertUpdateSelect() throws Exception {
...@@ -255,7 +253,7 @@ public class TestMultiThread extends TestBase implements Runnable { ...@@ -255,7 +253,7 @@ public class TestMultiThread extends TestBase implements Runnable {
} }
private Connection getConnection() throws SQLException { private Connection getConnection() throws SQLException {
return getConnection("jdbc:h2:mem:multiThread"); return getConnection("jdbc:h2:mem:" + getTestName());
} }
@Override @Override
......
...@@ -31,8 +31,8 @@ public class TestViewAlterTable extends TestBase { ...@@ -31,8 +31,8 @@ public class TestViewAlterTable extends TestBase {
@Override @Override
public void test() throws Exception { public void test() throws Exception {
deleteDb("alter"); deleteDb(getTestName());
conn = getConnection("alter"); conn = getConnection(getTestName());
stat = conn.createStatement(); stat = conn.createStatement();
testDropColumnWithoutViews(); testDropColumnWithoutViews();
...@@ -47,7 +47,7 @@ public class TestViewAlterTable extends TestBase { ...@@ -47,7 +47,7 @@ public class TestViewAlterTable extends TestBase {
testForeignKey(); testForeignKey();
conn.close(); conn.close();
deleteDb("alter"); deleteDb(getTestName());
} }
private void testDropColumnWithoutViews() throws SQLException { private void testDropColumnWithoutViews() throws SQLException {
......
...@@ -32,8 +32,8 @@ public class TestViewDropView extends TestBase { ...@@ -32,8 +32,8 @@ public class TestViewDropView extends TestBase {
@Override @Override
public void test() throws Exception { public void test() throws Exception {
deleteDb("alter"); deleteDb(getTestName());
conn = getConnection("alter"); conn = getConnection(getTestName());
stat = conn.createStatement(); stat = conn.createStatement();
testDropViewDefaultBehaviour(); testDropViewDefaultBehaviour();
...@@ -45,7 +45,7 @@ public class TestViewDropView extends TestBase { ...@@ -45,7 +45,7 @@ public class TestViewDropView extends TestBase {
testCreateOrReplaceForceViewWithNowInvalidDependentViews(); testCreateOrReplaceForceViewWithNowInvalidDependentViews();
conn.close(); conn.close();
deleteDb("alter"); deleteDb(getTestName());
} }
private void testCreateForceView() throws SQLException { private void testCreateForceView() throws SQLException {
......
...@@ -5,8 +5,6 @@ ...@@ -5,8 +5,6 @@
*/ */
package org.h2.test.jdbc; package org.h2.test.jdbc;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import java.sql.BatchUpdateException; import java.sql.BatchUpdateException;
import java.sql.CallableStatement; import java.sql.CallableStatement;
import java.sql.Connection; import java.sql.Connection;
...@@ -156,16 +154,9 @@ public class TestBatchUpdates extends TestBase { ...@@ -156,16 +154,9 @@ public class TestBatchUpdates extends TestBase {
} }
try { try {
prep.executeBatch(); prep.executeBatch();
fail();
} catch (BatchUpdateException e) { } catch (BatchUpdateException e) {
PrintStream temp = System.err; // expected
try {
ByteArrayOutputStream buff = new ByteArrayOutputStream();
PrintStream p = new PrintStream(buff);
System.setErr(p);
e.printStackTrace();
} finally {
System.setErr(temp);
}
} }
conn.close(); conn.close();
} }
......
...@@ -45,12 +45,12 @@ public class TestLobApi extends TestBase { ...@@ -45,12 +45,12 @@ public class TestLobApi extends TestBase {
@Override @Override
public void test() throws Exception { public void test() throws Exception {
deleteDb("lob"); deleteDb(getTestName());
testUnsupportedOperations(); testUnsupportedOperations();
testLobStaysOpenUntilCommitted(); testLobStaysOpenUntilCommitted();
testInputStreamThrowsException(true); testInputStreamThrowsException(true);
testInputStreamThrowsException(false); testInputStreamThrowsException(false);
conn = (JdbcConnection) getConnection("lob"); conn = (JdbcConnection) getConnection(getTestName());
stat = conn.createStatement(); stat = conn.createStatement();
stat.execute("create table test(id int, x blob)"); stat.execute("create table test(id int, x blob)");
testBlob(0); testBlob(0);
...@@ -68,7 +68,7 @@ public class TestLobApi extends TestBase { ...@@ -68,7 +68,7 @@ public class TestLobApi extends TestBase {
} }
private void testUnsupportedOperations() throws Exception { private void testUnsupportedOperations() throws Exception {
Connection conn = getConnection("lob"); Connection conn = getConnection(getTestName());
stat = conn.createStatement(); stat = conn.createStatement();
stat.execute("create table test(id int, c clob, b blob)"); stat.execute("create table test(id int, c clob, b blob)");
stat.execute("insert into test values(1, 'x', x'00')"); stat.execute("insert into test values(1, 'x', x'00')");
...@@ -118,7 +118,7 @@ public class TestLobApi extends TestBase { ...@@ -118,7 +118,7 @@ public class TestLobApi extends TestBase {
* the result set is closed (see ResultSet.close). * the result set is closed (see ResultSet.close).
*/ */
private void testLobStaysOpenUntilCommitted() throws Exception { private void testLobStaysOpenUntilCommitted() throws Exception {
Connection conn = getConnection("lob"); Connection conn = getConnection(getTestName());
stat = conn.createStatement(); stat = conn.createStatement();
stat.execute("create table test(id identity, c clob, b blob)"); stat.execute("create table test(id identity, c clob, b blob)");
PreparedStatement prep = conn.prepareStatement( PreparedStatement prep = conn.prepareStatement(
...@@ -163,7 +163,7 @@ public class TestLobApi extends TestBase { ...@@ -163,7 +163,7 @@ public class TestLobApi extends TestBase {
private void testInputStreamThrowsException(final boolean ioException) private void testInputStreamThrowsException(final boolean ioException)
throws Exception { throws Exception {
Connection conn = getConnection("lob"); Connection conn = getConnection(getTestName());
stat = conn.createStatement(); stat = conn.createStatement();
stat.execute("create table test(id identity, c clob, b blob)"); stat.execute("create table test(id identity, c clob, b blob)");
PreparedStatement prep = conn.prepareStatement( PreparedStatement prep = conn.prepareStatement(
......
...@@ -13,7 +13,6 @@ import java.math.BigDecimal; ...@@ -13,7 +13,6 @@ import java.math.BigDecimal;
import java.net.URL; import java.net.URL;
import java.sql.Array; import java.sql.Array;
import java.sql.Connection; import java.sql.Connection;
import java.sql.Date;
import java.sql.ParameterMetaData; import java.sql.ParameterMetaData;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
...@@ -21,19 +20,13 @@ import java.sql.ResultSetMetaData; ...@@ -21,19 +20,13 @@ import java.sql.ResultSetMetaData;
import java.sql.RowId; import java.sql.RowId;
import java.sql.SQLException; import java.sql.SQLException;
import java.sql.Statement; import java.sql.Statement;
import java.sql.Time;
import java.sql.Timestamp; import java.sql.Timestamp;
import java.sql.Types; import java.sql.Types;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.SimpleTimeZone;
import java.util.TimeZone;
import java.util.UUID; import java.util.UUID;
import org.h2.api.ErrorCode; import org.h2.api.ErrorCode;
import org.h2.api.Trigger; import org.h2.api.Trigger;
import org.h2.test.TestBase; import org.h2.test.TestBase;
import org.h2.util.DateTimeUtils;
import org.h2.util.Task; import org.h2.util.Task;
/** /**
...@@ -59,7 +52,6 @@ public class TestPreparedStatement extends TestBase { ...@@ -59,7 +52,6 @@ public class TestPreparedStatement extends TestBase {
testUnwrap(conn); testUnwrap(conn);
testUnsupportedOperations(conn); testUnsupportedOperations(conn);
testChangeType(conn); testChangeType(conn);
testDateTimeTimestampWithCalendar(conn);
testCallTablePrepared(conn); testCallTablePrepared(conn);
testValues(conn); testValues(conn);
testToString(conn); testToString(conn);
...@@ -169,108 +161,6 @@ public class TestPreparedStatement extends TestBase { ...@@ -169,108 +161,6 @@ public class TestPreparedStatement extends TestBase {
prep.executeQuery(); prep.executeQuery();
} }
private void testDateTimeTimestampWithCalendar(Connection conn)
throws SQLException {
Statement stat = conn.createStatement();
stat.execute("create table ts(x timestamp primary key)");
stat.execute("create table t(x time primary key)");
stat.execute("create table d(x date)");
Calendar utcCalendar = new GregorianCalendar(new SimpleTimeZone(0, "Z"));
TimeZone old = TimeZone.getDefault();
DateTimeUtils.resetCalendar();
TimeZone.setDefault(TimeZone.getTimeZone("PST"));
try {
Timestamp ts1 = Timestamp.valueOf("2010-03-13 18:15:00");
Time t1 = new Time(ts1.getTime());
Date d1 = new Date(ts1.getTime());
// when converted to UTC, this is 03:15, which doesn't actually
// exist because of summer time change at that day
Timestamp ts2 = Timestamp.valueOf("2010-03-13 19:15:00");
Time t2 = new Time(ts2.getTime());
Date d2 = new Date(ts2.getTime());
PreparedStatement prep;
ResultSet rs;
prep = conn.prepareStatement("insert into ts values(?)");
prep.setTimestamp(1, ts1, utcCalendar);
prep.execute();
prep.setTimestamp(1, ts2, utcCalendar);
prep.execute();
prep = conn.prepareStatement("insert into t values(?)");
prep.setTime(1, t1, utcCalendar);
prep.execute();
prep.setTime(1, t2, utcCalendar);
prep.execute();
prep = conn.prepareStatement("insert into d values(?)");
prep.setDate(1, d1, utcCalendar);
prep.execute();
prep.setDate(1, d2, utcCalendar);
prep.execute();
rs = stat.executeQuery("select * from ts order by x");
rs.next();
assertEquals("2010-03-14 02:15:00.0",
rs.getString(1));
assertEquals("2010-03-13 18:15:00.0",
rs.getTimestamp(1, utcCalendar).toString());
assertEquals("2010-03-14 03:15:00.0",
rs.getTimestamp(1).toString());
assertEquals("2010-03-14 02:15:00.0",
rs.getString("x"));
assertEquals("2010-03-13 18:15:00.0",
rs.getTimestamp("x", utcCalendar).toString());
assertEquals("2010-03-14 03:15:00.0",
rs.getTimestamp("x").toString());
rs.next();
assertEquals("2010-03-14 03:15:00.0",
rs.getString(1));
assertEquals("2010-03-13 19:15:00.0",
rs.getTimestamp(1, utcCalendar).toString());
assertEquals("2010-03-14 03:15:00.0",
rs.getTimestamp(1).toString());
assertEquals("2010-03-14 03:15:00.0",
rs.getString("x"));
assertEquals("2010-03-13 19:15:00.0",
rs.getTimestamp("x", utcCalendar).toString());
assertEquals("2010-03-14 03:15:00.0",
rs.getTimestamp("x").toString());
rs = stat.executeQuery("select * from t order by x");
rs.next();
assertEquals("02:15:00", rs.getString(1));
assertEquals("18:15:00", rs.getTime(1, utcCalendar).toString());
assertEquals("02:15:00", rs.getTime(1).toString());
assertEquals("02:15:00", rs.getString("x"));
assertEquals("18:15:00", rs.getTime("x", utcCalendar).toString());
assertEquals("02:15:00", rs.getTime("x").toString());
rs.next();
assertEquals("03:15:00", rs.getString(1));
assertEquals("19:15:00", rs.getTime(1, utcCalendar).toString());
assertEquals("03:15:00", rs.getTime(1).toString());
assertEquals("03:15:00", rs.getString("x"));
assertEquals("19:15:00", rs.getTime("x", utcCalendar).toString());
assertEquals("03:15:00", rs.getTime("x").toString());
rs = stat.executeQuery("select * from d order by x");
rs.next();
assertEquals("2010-03-14", rs.getString(1));
assertEquals("2010-03-13", rs.getDate(1, utcCalendar).toString());
assertEquals("2010-03-14", rs.getDate(1).toString());
assertEquals("2010-03-14", rs.getString("x"));
assertEquals("2010-03-13", rs.getDate("x", utcCalendar).toString());
assertEquals("2010-03-14", rs.getDate("x").toString());
rs.next();
assertEquals("2010-03-14", rs.getString(1));
assertEquals("2010-03-13", rs.getDate(1, utcCalendar).toString());
assertEquals("2010-03-14", rs.getDate(1).toString());
assertEquals("2010-03-14", rs.getString("x"));
assertEquals("2010-03-13", rs.getDate("x", utcCalendar).toString());
assertEquals("2010-03-14", rs.getDate("x").toString());
} finally {
TimeZone.setDefault(old);
DateTimeUtils.resetCalendar();
}
stat.execute("drop table ts");
stat.execute("drop table t");
stat.execute("drop table d");
}
private static void testCallTablePrepared(Connection conn) throws SQLException { private static void testCallTablePrepared(Connection conn) throws SQLException {
PreparedStatement prep = conn.prepareStatement("call table(x int = (1))"); PreparedStatement prep = conn.prepareStatement("call table(x int = (1))");
prep.executeQuery(); prep.executeQuery();
......
...@@ -32,7 +32,6 @@ import java.sql.Timestamp; ...@@ -32,7 +32,6 @@ import java.sql.Timestamp;
import java.sql.Types; import java.sql.Types;
import java.util.Calendar; import java.util.Calendar;
import java.util.Collections; import java.util.Collections;
import java.util.Locale;
import java.util.TimeZone; import java.util.TimeZone;
import org.h2.api.ErrorCode; import org.h2.api.ErrorCode;
...@@ -70,7 +69,6 @@ public class TestResultSet extends TestBase { ...@@ -70,7 +69,6 @@ public class TestResultSet extends TestBase {
testInsertRowWithUpdatableResultSetDefault(); testInsertRowWithUpdatableResultSetDefault();
testBeforeFirstAfterLast(); testBeforeFirstAfterLast();
testParseSpecialValues(); testParseSpecialValues();
testSpecialLocale();
testSubstringPrecision(); testSubstringPrecision();
testSubstringDataType(); testSubstringDataType();
testColumnLabelColumnName(); testColumnLabelColumnName();
...@@ -347,26 +345,6 @@ public class TestResultSet extends TestBase { ...@@ -347,26 +345,6 @@ public class TestResultSet extends TestBase {
assertTrue(expected.equals(o)); assertTrue(expected.equals(o));
} }
private void testSpecialLocale() throws SQLException {
Locale old = Locale.getDefault();
try {
// when using Turkish as the default locale, "i".toUpperCase() is
// not "I"
Locale.setDefault(new Locale("tr"));
stat.execute("create table test(I1 int, i2 int, b int, c int, d int) " +
"as select 1, 1, 1, 1, 1");
ResultSet rs = stat.executeQuery("select * from test");
rs.next();
rs.getString("I1");
rs.getString("i1");
rs.getString("I2");
rs.getString("i2");
stat.execute("drop table test");
} finally {
Locale.setDefault(old);
}
}
private void testSubstringDataType() throws SQLException { private void testSubstringDataType() throws SQLException {
ResultSet rs = stat.executeQuery("select substr(x, 1, 1) from dual"); ResultSet rs = stat.executeQuery("select substr(x, 1, 1) from dual");
rs.next(); rs.next();
......
...@@ -38,8 +38,8 @@ public class TestMvccMultiThreaded extends TestBase { ...@@ -38,8 +38,8 @@ public class TestMvccMultiThreaded extends TestBase {
} }
private void testMergeWithUniqueKeyViolation() throws Exception { private void testMergeWithUniqueKeyViolation() throws Exception {
deleteDb("mvccMultiThreaded"); deleteDb(getTestName());
Connection conn = getConnection("mvccMultiThreaded"); Connection conn = getConnection(getTestName());
Statement stat = conn.createStatement(); Statement stat = conn.createStatement();
stat.execute("create table test(x int primary key, y int unique)"); stat.execute("create table test(x int primary key, y int unique)");
stat.execute("insert into test values(1, 1)"); stat.execute("insert into test values(1, 1)");
...@@ -51,12 +51,12 @@ public class TestMvccMultiThreaded extends TestBase { ...@@ -51,12 +51,12 @@ public class TestMvccMultiThreaded extends TestBase {
} }
private void testConcurrentMerge() throws Exception { private void testConcurrentMerge() throws Exception {
deleteDb("mvccMultiThreaded"); deleteDb(getTestName());
int len = 3; int len = 3;
final Connection[] connList = new Connection[len]; final Connection[] connList = new Connection[len];
for (int i = 0; i < len; i++) { for (int i = 0; i < len; i++) {
Connection conn = getConnection( Connection conn = getConnection(
"mvccMultiThreaded;MVCC=TRUE;LOCK_TIMEOUT=500"); getTestName() + ";MVCC=TRUE;LOCK_TIMEOUT=500");
connList[i] = conn; connList[i] = conn;
} }
Connection conn = connList[0]; Connection conn = connList[0];
...@@ -88,16 +88,16 @@ public class TestMvccMultiThreaded extends TestBase { ...@@ -88,16 +88,16 @@ public class TestMvccMultiThreaded extends TestBase {
for (int i = 0; i < len; i++) { for (int i = 0; i < len; i++) {
connList[i].close(); connList[i].close();
} }
deleteDb("mvccMultiThreaded"); deleteDb(getTestName());
} }
private void testConcurrentUpdate(String suffix) throws Exception { private void testConcurrentUpdate(String suffix) throws Exception {
deleteDb("mvccMultiThreaded"); deleteDb(getTestName());
int len = 2; int len = 2;
final Connection[] connList = new Connection[len]; final Connection[] connList = new Connection[len];
for (int i = 0; i < len; i++) { for (int i = 0; i < len; i++) {
connList[i] = getConnection( connList[i] = getConnection(
"mvccMultiThreaded;MVCC=TRUE" + suffix); getTestName() + ";MVCC=TRUE" + suffix);
} }
Connection conn = connList[0]; Connection conn = connList[0];
conn.createStatement().execute( conn.createStatement().execute(
...@@ -133,7 +133,6 @@ public class TestMvccMultiThreaded extends TestBase { ...@@ -133,7 +133,6 @@ public class TestMvccMultiThreaded extends TestBase {
for (int i = 0; i < len; i++) { for (int i = 0; i < len; i++) {
connList[i].close(); connList[i].close();
} }
deleteDb("mvccMultiThreaded");
} }
} }
...@@ -39,12 +39,12 @@ public class TestRowLocks extends TestBase { ...@@ -39,12 +39,12 @@ public class TestRowLocks extends TestBase {
public void test() throws Exception { public void test() throws Exception {
testSetMode(); testSetMode();
testCases(); testCases();
deleteDb("rowLocks"); deleteDb(getTestName());
} }
private void testSetMode() throws SQLException { private void testSetMode() throws SQLException {
deleteDb("rowLocks"); deleteDb(getTestName());
c1 = getConnection("rowLocks"); c1 = getConnection(getTestName());
Statement stat = c1.createStatement(); Statement stat = c1.createStatement();
stat.execute("SET LOCK_MODE 2"); stat.execute("SET LOCK_MODE 2");
ResultSet rs = stat.executeQuery("call lock_mode()"); ResultSet rs = stat.executeQuery("call lock_mode()");
...@@ -54,8 +54,8 @@ public class TestRowLocks extends TestBase { ...@@ -54,8 +54,8 @@ public class TestRowLocks extends TestBase {
} }
private void testCases() throws Exception { private void testCases() throws Exception {
deleteDb("rowLocks"); deleteDb(getTestName());
c1 = getConnection("rowLocks;MVCC=TRUE"); c1 = getConnection(getTestName() + ";MVCC=TRUE");
s1 = c1.createStatement(); s1 = c1.createStatement();
s1.execute("SET LOCK_TIMEOUT 10000"); s1.execute("SET LOCK_TIMEOUT 10000");
s1.execute("CREATE TABLE TEST AS " + s1.execute("CREATE TABLE TEST AS " +
...@@ -64,7 +64,7 @@ public class TestRowLocks extends TestBase { ...@@ -64,7 +64,7 @@ public class TestRowLocks extends TestBase {
c1.setAutoCommit(false); c1.setAutoCommit(false);
s1.execute("UPDATE TEST SET NAME='Hallo' WHERE ID=1"); s1.execute("UPDATE TEST SET NAME='Hallo' WHERE ID=1");
c2 = getConnection("rowLocks"); c2 = getConnection(getTestName());
c2.setAutoCommit(false); c2.setAutoCommit(false);
s2 = c2.createStatement(); s2 = c2.createStatement();
......
...@@ -43,10 +43,10 @@ public class TestAutoServer extends TestBase { ...@@ -43,10 +43,10 @@ public class TestAutoServer extends TestBase {
private void testUnsupportedCombinations() throws SQLException { private void testUnsupportedCombinations() throws SQLException {
String[] urls = { String[] urls = {
"jdbc:h2:test;file_lock=no;auto_server=true", "jdbc:h2:" + getTestName() + ";file_lock=no;auto_server=true",
"jdbc:h2:test;file_lock=serialized;auto_server=true", "jdbc:h2:" + getTestName() + ";file_lock=serialized;auto_server=true",
"jdbc:h2:test;access_mode_data=r;auto_server=true", "jdbc:h2:" + getTestName() + ";access_mode_data=r;auto_server=true",
"jdbc:h2:mem:test;auto_server=true" "jdbc:h2:mem:" + getTestName() + ";auto_server=true"
}; };
for (String url : urls) { for (String url : urls) {
assertThrows(SQLException.class, this).getConnection(url); assertThrows(SQLException.class, this).getConnection(url);
...@@ -63,8 +63,8 @@ public class TestAutoServer extends TestBase { ...@@ -63,8 +63,8 @@ public class TestAutoServer extends TestBase {
if (config.memory || config.networked) { if (config.memory || config.networked) {
return; return;
} }
deleteDb("autoServer"); deleteDb(getTestName());
String url = getURL("autoServer;AUTO_SERVER=TRUE", true); String url = getURL(getTestName() + ";AUTO_SERVER=TRUE", true);
if (port) { if (port) {
url += ";AUTO_SERVER_PORT=11111"; url += ";AUTO_SERVER_PORT=11111";
} }
...@@ -76,7 +76,7 @@ public class TestAutoServer extends TestBase { ...@@ -76,7 +76,7 @@ public class TestAutoServer extends TestBase {
for (; i > 0; i--) { for (; i > 0; i--) {
Thread.sleep(100); Thread.sleep(100);
SortedProperties prop = SortedProperties.loadProperties( SortedProperties prop = SortedProperties.loadProperties(
getBaseDir() + "/autoServer.lock.db"); getBaseDir() + "/" + getTestName() + ".lock.db");
String key = prop.getProperty("id"); String key = prop.getProperty("id");
String server = prop.getProperty("server"); String server = prop.getProperty("server");
if (server != null) { if (server != null) {
...@@ -117,10 +117,10 @@ public class TestAutoServer extends TestBase { ...@@ -117,10 +117,10 @@ public class TestAutoServer extends TestBase {
if (config.memory || config.networked) { if (config.memory || config.networked) {
return; return;
} }
deleteDb("autoServerLinkedTable1"); deleteDb(getTestName() + "1");
deleteDb("autoServerLinkedTable2"); deleteDb(getTestName() + "2");
String url = getURL("autoServerLinkedTable1;AUTO_SERVER=TRUE", true); String url = getURL(getTestName() + "1;AUTO_SERVER=TRUE", true);
String urlLinked = getURL("autoServerLinkedTable2", true); String urlLinked = getURL(getTestName() + "2", true);
String user = getUser(), password = getPassword(); String user = getUser(), password = getPassword();
Connection connLinked = getConnection(urlLinked, user, password); Connection connLinked = getConnection(urlLinked, user, password);
...@@ -163,8 +163,8 @@ public class TestAutoServer extends TestBase { ...@@ -163,8 +163,8 @@ public class TestAutoServer extends TestBase {
// ignore // ignore
} }
deleteDb("autoServerLinkedTable1"); deleteDb(getTestName() + "1");
deleteDb("autoServerLinkedTable2"); deleteDb(getTestName() + "2");
} }
/** /**
......
...@@ -6,11 +6,7 @@ ...@@ -6,11 +6,7 @@
package org.h2.test.server; package org.h2.test.server;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.PrintStream; import java.io.PrintStream;
import java.io.PrintWriter; import java.io.PrintWriter;
...@@ -47,7 +43,6 @@ import org.h2.store.fs.FileUtils; ...@@ -47,7 +43,6 @@ import org.h2.store.fs.FileUtils;
import org.h2.test.TestBase; import org.h2.test.TestBase;
import org.h2.test.utils.AssertThrows; import org.h2.test.utils.AssertThrows;
import org.h2.tools.Server; import org.h2.tools.Server;
import org.h2.util.IOUtils;
import org.h2.util.StringUtils; import org.h2.util.StringUtils;
import org.h2.util.Task; import org.h2.util.Task;
...@@ -72,7 +67,6 @@ public class TestWeb extends TestBase { ...@@ -72,7 +67,6 @@ public class TestWeb extends TestBase {
testServlet(); testServlet();
testWrongParameters(); testWrongParameters();
testTools(); testTools();
testTransfer();
testAlreadyRunning(); testAlreadyRunning();
testStartWebServerWithConnection(); testStartWebServerWithConnection();
testServer(); testServer();
...@@ -164,8 +158,8 @@ public class TestWeb extends TestBase { ...@@ -164,8 +158,8 @@ public class TestWeb extends TestBase {
if (config.memory || config.cipher != null) { if (config.memory || config.cipher != null) {
return; return;
} }
deleteDb("web"); deleteDb(getTestName());
Connection conn = getConnection("web"); Connection conn = getConnection(getTestName());
conn.createStatement().execute( conn.createStatement().execute(
"create table test(id int) as select 1"); "create table test(id int) as select 1");
conn.close(); conn.close();
...@@ -183,14 +177,14 @@ public class TestWeb extends TestBase { ...@@ -183,14 +177,14 @@ public class TestWeb extends TestBase {
result = client.get(url, "tools.jsp"); result = client.get(url, "tools.jsp");
FileUtils.delete(getBaseDir() + "/backup.zip"); FileUtils.delete(getBaseDir() + "/backup.zip");
result = client.get(url, "tools.do?tool=Backup&args=-dir," + result = client.get(url, "tools.do?tool=Backup&args=-dir," +
getBaseDir() + ",-db,web,-file," + getBaseDir() + ",-db," + getTestName() + ",-file," +
getBaseDir() + "/backup.zip"); getBaseDir() + "/backup.zip");
deleteDb("web"); deleteDb(getTestName());
assertTrue(FileUtils.exists(getBaseDir() + "/backup.zip")); assertTrue(FileUtils.exists(getBaseDir() + "/backup.zip"));
result = client.get(url, result = client.get(url,
"tools.do?tool=DeleteDbFiles&args=-dir," + "tools.do?tool=DeleteDbFiles&args=-dir," +
getBaseDir() + ",-db,web"); getBaseDir() + ",-db," + getTestName());
String fn = getBaseDir() + "/web"; String fn = getBaseDir() + "/" + getTestName();
if (config.mvStore) { if (config.mvStore) {
fn += Constants.SUFFIX_MV_FILE; fn += Constants.SUFFIX_MV_FILE;
} else { } else {
...@@ -198,53 +192,23 @@ public class TestWeb extends TestBase { ...@@ -198,53 +192,23 @@ public class TestWeb extends TestBase {
} }
assertFalse(FileUtils.exists(fn)); assertFalse(FileUtils.exists(fn));
result = client.get(url, "tools.do?tool=Restore&args=-dir," + result = client.get(url, "tools.do?tool=Restore&args=-dir," +
getBaseDir() + ",-db,web,-file," + getBaseDir() + getBaseDir() + ",-db," + getTestName() +",-file," + getBaseDir() +
"/backup.zip"); "/backup.zip");
assertTrue(FileUtils.exists(fn)); assertTrue(FileUtils.exists(fn));
FileUtils.delete(getBaseDir() + "/web.h2.sql"); FileUtils.delete(getBaseDir() + "/web.h2.sql");
FileUtils.delete(getBaseDir() + "/backup.zip"); FileUtils.delete(getBaseDir() + "/backup.zip");
result = client.get(url, "tools.do?tool=Recover&args=-dir," + result = client.get(url, "tools.do?tool=Recover&args=-dir," +
getBaseDir() + ",-db,web"); getBaseDir() + ",-db," + getTestName());
assertTrue(FileUtils.exists(getBaseDir() + "/web.h2.sql")); assertTrue(FileUtils.exists(getBaseDir() + "/" + getTestName() + ".h2.sql"));
FileUtils.delete(getBaseDir() + "/web.h2.sql"); FileUtils.delete(getBaseDir() + "/web.h2.sql");
result = client.get(url, "tools.do?tool=RunScript&args=-script," + result = client.get(url, "tools.do?tool=RunScript&args=-script," +
getBaseDir() + "/web.h2.sql,-url," + getURL("web", true) + getBaseDir() + "/" + getTestName() + ".h2.sql,-url," + getURL(getTestName(), true) +
",-user," + getUser() + ",-password," + getPassword()); ",-user," + getUser() + ",-password," + getPassword());
FileUtils.delete(getBaseDir() + "/web.h2.sql"); FileUtils.delete(getBaseDir() + "/" + getTestName() + ".h2.sql");
assertTrue(FileUtils.exists(fn)); assertTrue(FileUtils.exists(fn));
deleteDb("web"); deleteDb(getTestName());
} finally {
server.shutdown();
}
}
private void testTransfer() throws Exception {
Server server = new Server();
server.setOut(new PrintStream(new ByteArrayOutputStream()));
server.runTool("-web", "-webPort", "8182", "-properties", "null");
File transfer = new File("transfer");
transfer.mkdirs();
try {
FileOutputStream f = new FileOutputStream("transfer/test.txt");
f.write("Hello World".getBytes());
f.close();
WebClient client = new WebClient();
String url = "http://localhost:8182";
String result = client.get(url);
client.readSessionId(result);
String test = client.get(url, "transfer/test.txt");
assertEquals("Hello World", test);
new File("transfer/testUpload.txt").delete();
client.upload(url + "/transfer/testUpload.txt",
"testUpload.txt", new ByteArrayInputStream(
"Hallo Welt".getBytes()));
byte[] d = IOUtils.readBytesAndClose(
new FileInputStream("transfer/testUpload.txt"), -1);
assertEquals("Hallo Welt", new String(d));
new File("transfer/testUpload.txt").delete();
} finally { } finally {
server.shutdown(); server.shutdown();
FileUtils.deleteRecursive("transfer", true);
} }
} }
...@@ -289,7 +253,7 @@ public class TestWeb extends TestBase { ...@@ -289,7 +253,7 @@ public class TestWeb extends TestBase {
} }
private void testIfExists() throws Exception { private void testIfExists() throws Exception {
Connection conn = getConnection("jdbc:h2:mem:webExists", Connection conn = getConnection("jdbc:h2:mem:" + getTestName(),
getUser(), getPassword()); getUser(), getPassword());
Server server = new Server(); Server server = new Server();
server.setOut(new PrintStream(new ByteArrayOutputStream())); server.setOut(new PrintStream(new ByteArrayOutputStream()));
...@@ -304,12 +268,12 @@ public class TestWeb extends TestBase { ...@@ -304,12 +268,12 @@ public class TestWeb extends TestBase {
client.readSessionId(result); client.readSessionId(result);
result = client.get(url, "login.jsp"); result = client.get(url, "login.jsp");
result = client.get(url, "test.do?driver=org.h2.Driver" + result = client.get(url, "test.do?driver=org.h2.Driver" +
"&url=jdbc:h2:mem:webExists" + "&url=jdbc:h2:mem:" + getTestName() +
"&user=" + getUser() + "&password=" + "&user=" + getUser() + "&password=" +
getPassword() + "&name=_test_"); getPassword() + "&name=_test_");
assertTrue(result.indexOf("Exception") < 0); assertTrue(result.indexOf("Exception") < 0);
result = client.get(url, "test.do?driver=org.h2.Driver" + result = client.get(url, "test.do?driver=org.h2.Driver" +
"&url=jdbc:h2:mem:web" + "&url=jdbc:h2:mem:" + getTestName() + "Wrong" +
"&user=" + getUser() + "&password=" + "&user=" + getUser() + "&password=" +
getPassword() + "&name=_test_"); getPassword() + "&name=_test_");
assertContains(result, "Exception"); assertContains(result, "Exception");
...@@ -340,13 +304,16 @@ public class TestWeb extends TestBase { ...@@ -340,13 +304,16 @@ public class TestWeb extends TestBase {
result = client.get(url, "login.jsp"); result = client.get(url, "login.jsp");
assertTrue(result.indexOf("Einstellung") < 0); assertTrue(result.indexOf("Einstellung") < 0);
result = client.get(url, "test.do?driver=abc" + result = client.get(url, "test.do?driver=abc" +
"&url=jdbc:abc:mem:web&user=sa&password=sa&name=_test_"); "&url=jdbc:abc:mem: " + getTestName() +
"&user=sa&password=sa&name=_test_");
assertContains(result, "Exception"); assertContains(result, "Exception");
result = client.get(url, "test.do?driver=org.h2.Driver" + result = client.get(url, "test.do?driver=org.h2.Driver" +
"&url=jdbc:h2:mem:web&user=sa&password=sa&name=_test_"); "&url=jdbc:h2:mem:" + getTestName() +
"&user=sa&password=sa&name=_test_");
assertTrue(result.indexOf("Exception") < 0); assertTrue(result.indexOf("Exception") < 0);
result = client.get(url, "login.do?driver=org.h2.Driver" + result = client.get(url, "login.do?driver=org.h2.Driver" +
"&url=jdbc:h2:mem:web&user=sa&password=sa&name=_test_"); "&url=jdbc:h2:mem:" + getTestName() +
"&user=sa&password=sa&name=_test_");
result = client.get(url, "header.jsp"); result = client.get(url, "header.jsp");
result = client.get(url, "query.do?sql=" + result = client.get(url, "query.do?sql=" +
"create table test(id int primary key, name varchar);" + "create table test(id int primary key, name varchar);" +
...@@ -561,7 +528,8 @@ public class TestWeb extends TestBase { ...@@ -561,7 +528,8 @@ public class TestWeb extends TestBase {
result = client.get(url, "logout.do"); result = client.get(url, "logout.do");
result = client.get(url, "login.do?driver=org.h2.Driver&" + result = client.get(url, "login.do?driver=org.h2.Driver&" +
"url=jdbc:h2:mem:web&user=sa&password=sa&name=_test_"); "url=jdbc:h2:mem:" + getTestName() +
"&user=sa&password=sa&name=_test_");
result = client.get(url, "logout.do"); result = client.get(url, "logout.do");
result = client.get(url, "settingRemove.do?name=_test_"); result = client.get(url, "settingRemove.do?name=_test_");
...@@ -580,7 +548,7 @@ public class TestWeb extends TestBase { ...@@ -580,7 +548,7 @@ public class TestWeb extends TestBase {
Server.openBrowser("testUrl"); Server.openBrowser("testUrl");
assertEquals("testUrl", lastUrl); assertEquals("testUrl", lastUrl);
String oldUrl = lastUrl; String oldUrl = lastUrl;
final Connection conn = getConnection("testWeb"); final Connection conn = getConnection(getTestName());
Task t = new Task() { Task t = new Task() {
@Override @Override
public void call() throws Exception { public void call() throws Exception {
...@@ -611,7 +579,6 @@ public class TestWeb extends TestBase { ...@@ -611,7 +579,6 @@ public class TestWeb extends TestBase {
} else { } else {
System.clearProperty(SysProperties.H2_BROWSER); System.clearProperty(SysProperties.H2_BROWSER);
} }
deleteDb("testWeb");
} }
} }
......
...@@ -46,10 +46,7 @@ public class TestConcurrent extends TestMVStore { ...@@ -46,10 +46,7 @@ public class TestConcurrent extends TestMVStore {
@Override @Override
public void test() throws Exception { public void test() throws Exception {
FileUtils.deleteRecursive(getBaseDir(), true);
FileUtils.createDirectories(getBaseDir()); FileUtils.createDirectories(getBaseDir());
FileUtils.deleteRecursive("memFS:", false);
testInterruptReopen(); testInterruptReopen();
testConcurrentSaveCompact(); testConcurrentSaveCompact();
testConcurrentDataType(); testConcurrentDataType();
...@@ -68,7 +65,7 @@ public class TestConcurrent extends TestMVStore { ...@@ -68,7 +65,7 @@ public class TestConcurrent extends TestMVStore {
} }
private void testInterruptReopen() throws Exception { private void testInterruptReopen() throws Exception {
String fileName = "retry:nio:" + getBaseDir() + "/testInterruptReopen.h3"; String fileName = "retry:nio:" + getBaseDir() + "/" + getTestName();
FileUtils.delete(fileName); FileUtils.delete(fileName);
final MVStore s = new MVStore.Builder(). final MVStore s = new MVStore.Builder().
fileName(fileName). fileName(fileName).
...@@ -99,7 +96,7 @@ public class TestConcurrent extends TestMVStore { ...@@ -99,7 +96,7 @@ public class TestConcurrent extends TestMVStore {
} }
private void testConcurrentSaveCompact() throws Exception { private void testConcurrentSaveCompact() throws Exception {
String fileName = "memFS:testConcurrentSaveCompact"; String fileName = "memFS:" + getTestName();
FileUtils.delete(fileName); FileUtils.delete(fileName);
final MVStore s = new MVStore.Builder(). final MVStore s = new MVStore.Builder().
fileName(fileName). fileName(fileName).
...@@ -188,7 +185,7 @@ public class TestConcurrent extends TestMVStore { ...@@ -188,7 +185,7 @@ public class TestConcurrent extends TestMVStore {
} }
private void testConcurrentAutoCommitAndChange() throws InterruptedException { private void testConcurrentAutoCommitAndChange() throws InterruptedException {
String fileName = "memFS:testConcurrentChangeAndBackgroundCompact"; String fileName = "memFS:" + getTestName();
FileUtils.delete(fileName); FileUtils.delete(fileName);
final MVStore s = new MVStore.Builder(). final MVStore s = new MVStore.Builder().
fileName(fileName).pageSplitSize(1000). fileName(fileName).pageSplitSize(1000).
...@@ -268,7 +265,7 @@ public class TestConcurrent extends TestMVStore { ...@@ -268,7 +265,7 @@ public class TestConcurrent extends TestMVStore {
} }
private void testConcurrentChangeAndCompact() throws InterruptedException { private void testConcurrentChangeAndCompact() throws InterruptedException {
String fileName = "memFS:testConcurrentChangeAndBackgroundCompact"; String fileName = "memFS:" + getTestName();
FileUtils.delete(fileName); FileUtils.delete(fileName);
final MVStore s = new MVStore.Builder().fileName( final MVStore s = new MVStore.Builder().fileName(
fileName). fileName).
...@@ -346,11 +343,10 @@ public class TestConcurrent extends TestMVStore { ...@@ -346,11 +343,10 @@ public class TestConcurrent extends TestMVStore {
s.commit(); s.commit();
s.close(); s.close();
} }
FileUtils.deleteRecursive("memFS:", false);
} }
private void testConcurrentFree() throws InterruptedException { private void testConcurrentFree() throws InterruptedException {
String fileName = "memFS:testConcurrentFree.h3"; String fileName = "memFS:" + getTestName();
for (int test = 0; test < 10; test++) { for (int test = 0; test < 10; test++) {
FileUtils.delete(fileName); FileUtils.delete(fileName);
final MVStore s1 = new MVStore.Builder(). final MVStore s1 = new MVStore.Builder().
...@@ -425,11 +421,11 @@ public class TestConcurrent extends TestMVStore { ...@@ -425,11 +421,11 @@ public class TestConcurrent extends TestMVStore {
assertTrue("" + chunkCount, chunkCount < 3); assertTrue("" + chunkCount, chunkCount < 3);
s.close(); s.close();
} }
FileUtils.deleteRecursive("memFS:", false);
} }
private void testConcurrentStoreAndRemoveMap() throws InterruptedException { private void testConcurrentStoreAndRemoveMap() throws InterruptedException {
String fileName = "memFS:testConcurrentStoreAndRemoveMap.h3"; String fileName = "memFS:" + getTestName();
FileUtils.delete(fileName);
final MVStore s = openStore(fileName); final MVStore s = openStore(fileName);
int count = 200; int count = 200;
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
...@@ -458,11 +454,10 @@ public class TestConcurrent extends TestMVStore { ...@@ -458,11 +454,10 @@ public class TestConcurrent extends TestMVStore {
} }
task.get(); task.get();
s.close(); s.close();
FileUtils.deleteRecursive("memFS:", false);
} }
private void testConcurrentStoreAndClose() throws InterruptedException { private void testConcurrentStoreAndClose() throws InterruptedException {
String fileName = "memFS:testConcurrentStoreAndClose"; String fileName = "memFS:" + getTestName();
for (int i = 0; i < 10; i++) { for (int i = 0; i < 10; i++) {
FileUtils.delete(fileName); FileUtils.delete(fileName);
final MVStore s = openStore(fileName); final MVStore s = openStore(fileName);
...@@ -500,7 +495,6 @@ public class TestConcurrent extends TestMVStore { ...@@ -500,7 +495,6 @@ public class TestConcurrent extends TestMVStore {
} }
s.close(); s.close();
} }
FileUtils.deleteRecursive("memFS:", false);
} }
/** /**
...@@ -557,8 +551,8 @@ public class TestConcurrent extends TestMVStore { ...@@ -557,8 +551,8 @@ public class TestConcurrent extends TestMVStore {
} }
private void testConcurrentOnlineBackup() throws Exception { private void testConcurrentOnlineBackup() throws Exception {
String fileName = getBaseDir() + "/onlineBackup.h3"; String fileName = getBaseDir() + "/" + getTestName();
String fileNameRestore = getBaseDir() + "/onlineRestore.h3"; String fileNameRestore = getBaseDir() + "/" + getTestName() + "2";
final MVStore s = openStore(fileName); final MVStore s = openStore(fileName);
final MVMap<Integer, byte[]> map = s.openMap("test"); final MVMap<Integer, byte[]> map = s.openMap("test");
final Random r = new Random(); final Random r = new Random();
......
...@@ -44,9 +44,6 @@ public class TestMVRTree extends TestMVStore { ...@@ -44,9 +44,6 @@ public class TestMVRTree extends TestMVStore {
@Override @Override
public void test() { public void test() {
FileUtils.deleteRecursive(getBaseDir(), true);
FileUtils.createDirectories(getBaseDir());
testRemoveAll(); testRemoveAll();
testRandomInsert(); testRandomInsert();
testSpatialKey(); testSpatialKey();
...@@ -58,7 +55,7 @@ public class TestMVRTree extends TestMVStore { ...@@ -58,7 +55,7 @@ public class TestMVRTree extends TestMVStore {
} }
private void testRemoveAll() { private void testRemoveAll() {
String fileName = getBaseDir() + "/testRemoveAll.h3"; String fileName = getBaseDir() + "/" + getTestName();
FileUtils.delete(fileName); FileUtils.delete(fileName);
MVStore s; MVStore s;
s = new MVStore.Builder().fileName(fileName). s = new MVStore.Builder().fileName(fileName).
...@@ -77,7 +74,7 @@ public class TestMVRTree extends TestMVStore { ...@@ -77,7 +74,7 @@ public class TestMVRTree extends TestMVStore {
} }
private void testRandomInsert() { private void testRandomInsert() {
String fileName = getBaseDir() + "/testMany.h3"; String fileName = getBaseDir() + "/" + getTestName();
FileUtils.delete(fileName); FileUtils.delete(fileName);
MVStore s; MVStore s;
s = new MVStore.Builder().fileName(fileName). s = new MVStore.Builder().fileName(fileName).
...@@ -143,7 +140,7 @@ public class TestMVRTree extends TestMVStore { ...@@ -143,7 +140,7 @@ public class TestMVRTree extends TestMVStore {
} }
private void testMany() { private void testMany() {
String fileName = getBaseDir() + "/testMany.h3"; String fileName = getBaseDir() + "/" + getTestName();
FileUtils.delete(fileName); FileUtils.delete(fileName);
MVStore s; MVStore s;
s = openStore(fileName); s = openStore(fileName);
...@@ -209,7 +206,7 @@ public class TestMVRTree extends TestMVStore { ...@@ -209,7 +206,7 @@ public class TestMVRTree extends TestMVStore {
} }
private void testSimple() { private void testSimple() {
String fileName = getBaseDir() + "/testTree.h3"; String fileName = getBaseDir() + "/" + getTestName();
FileUtils.delete(fileName); FileUtils.delete(fileName);
MVStore s; MVStore s;
s = openStore(fileName); s = openStore(fileName);
...@@ -387,7 +384,7 @@ public class TestMVRTree extends TestMVStore { ...@@ -387,7 +384,7 @@ public class TestMVRTree extends TestMVStore {
} }
private void testRandom(boolean quadraticSplit) { private void testRandom(boolean quadraticSplit) {
String fileName = getBaseDir() + "/testRandom.h3"; String fileName = getBaseDir() + "/" + getTestName();
FileUtils.delete(fileName); FileUtils.delete(fileName);
MVStore s = openStore(fileName); MVStore s = openStore(fileName);
......
...@@ -41,8 +41,6 @@ public class TestStreamStore extends TestBase { ...@@ -41,8 +41,6 @@ public class TestStreamStore extends TestBase {
@Override @Override
public void test() throws IOException { public void test() throws IOException {
FileUtils.deleteRecursive(getBaseDir(), true);
FileUtils.createDirectories(getBaseDir());
testIOException(); testIOException();
testSaveCount(); testSaveCount();
testExceptionDuringStore(); testExceptionDuringStore();
......
...@@ -27,7 +27,7 @@ public class BnfRandom implements BnfVisitor { ...@@ -27,7 +27,7 @@ public class BnfRandom implements BnfVisitor {
private int level; private int level;
private String sql; private String sql;
BnfRandom() throws Exception { public BnfRandom() throws Exception {
Bnf config = Bnf.getInstance(null); Bnf config = Bnf.getInstance(null);
config.linkStatements(); config.linkStatements();
......
...@@ -43,8 +43,8 @@ public class TestBtreeIndex extends TestBase { ...@@ -43,8 +43,8 @@ public class TestBtreeIndex extends TestBase {
} }
private void testAddDelete() throws SQLException { private void testAddDelete() throws SQLException {
deleteDb("index"); deleteDb(getTestName());
Connection conn = getConnection("index"); Connection conn = getConnection(getTestName());
try { try {
Statement stat = conn.createStatement(); Statement stat = conn.createStatement();
stat.execute("CREATE TABLE TEST(ID bigint primary key)"); stat.execute("CREATE TABLE TEST(ID bigint primary key)");
...@@ -54,7 +54,7 @@ public class TestBtreeIndex extends TestBase { ...@@ -54,7 +54,7 @@ public class TestBtreeIndex extends TestBase {
count + ")"); count + ")");
if (!config.memory) { if (!config.memory) {
conn.close(); conn.close();
conn = getConnection("index"); conn = getConnection(getTestName());
stat = conn.createStatement(); stat = conn.createStatement();
} }
for (int i = 1; i < count; i++) { for (int i = 1; i < count; i++) {
...@@ -68,7 +68,7 @@ public class TestBtreeIndex extends TestBase { ...@@ -68,7 +68,7 @@ public class TestBtreeIndex extends TestBase {
} finally { } finally {
conn.close(); conn.close();
} }
deleteDb("index"); deleteDb(getTestName());
} }
@Override @Override
...@@ -78,7 +78,7 @@ public class TestBtreeIndex extends TestBase { ...@@ -78,7 +78,7 @@ public class TestBtreeIndex extends TestBase {
private void testOne(int seed) throws SQLException { private void testOne(int seed) throws SQLException {
org.h2.Driver.load(); org.h2.Driver.load();
deleteDb("index"); deleteDb(getTestName());
printTime("testIndex " + seed); printTime("testIndex " + seed);
Random random = new Random(seed); Random random = new Random(seed);
int distinct, prefixLength; int distinct, prefixLength;
...@@ -101,8 +101,8 @@ public class TestBtreeIndex extends TestBase { ...@@ -101,8 +101,8 @@ public class TestBtreeIndex extends TestBase {
} }
} }
String prefix = buff.toString().substring(0, prefixLength); String prefix = buff.toString().substring(0, prefixLength);
DeleteDbFiles.execute(getBaseDir() + "/index", null, true); DeleteDbFiles.execute(getBaseDir() + "/" + getTestName(), null, true);
Connection conn = getConnection("index"); Connection conn = getConnection(getTestName());
try { try {
Statement stat = conn.createStatement(); Statement stat = conn.createStatement();
stat.execute("CREATE TABLE a(text VARCHAR PRIMARY KEY)"); stat.execute("CREATE TABLE a(text VARCHAR PRIMARY KEY)");
...@@ -192,7 +192,7 @@ public class TestBtreeIndex extends TestBase { ...@@ -192,7 +192,7 @@ public class TestBtreeIndex extends TestBase {
} finally { } finally {
conn.close(); conn.close();
} }
deleteDb("index"); deleteDb(getTestName());
} }
private void printError(int seed, String message) { private void printError(int seed, String message) {
......
...@@ -38,15 +38,15 @@ public class TestFuzzOptimizations extends TestBase { ...@@ -38,15 +38,15 @@ public class TestFuzzOptimizations extends TestBase {
@Override @Override
public void test() throws Exception { public void test() throws Exception {
deleteDb("optimizations"); deleteDb(getTestName());
conn = getConnection("optimizations"); conn = getConnection(getTestName());
if (!config.diskResult) { if (!config.diskResult) {
testIn(); testIn();
} }
testGroupSorted(); testGroupSorted();
testInSelect(); testInSelect();
conn.close(); conn.close();
deleteDb("optimizations"); deleteDb(getTestName());
} }
/* /*
......
...@@ -13,7 +13,6 @@ import org.h2.engine.SysProperties; ...@@ -13,7 +13,6 @@ import org.h2.engine.SysProperties;
import org.h2.store.fs.FileUtils; import org.h2.store.fs.FileUtils;
import org.h2.test.TestAll; import org.h2.test.TestAll;
import org.h2.test.TestBase; import org.h2.test.TestBase;
import org.h2.tools.DeleteDbFiles;
import org.h2.util.MathUtils; import org.h2.util.MathUtils;
/** /**
...@@ -44,8 +43,8 @@ public class TestRandomSQL extends TestBase { ...@@ -44,8 +43,8 @@ public class TestRandomSQL extends TestBase {
} }
} }
private String getDatabaseName() { protected String getDatabaseName() {
return "dataRandomSQL/randomSql" + seed; return getTestName() + "/db" + seed;
} }
private Connection connect() throws SQLException { private Connection connect() throws SQLException {
...@@ -53,13 +52,7 @@ public class TestRandomSQL extends TestBase { ...@@ -53,13 +52,7 @@ public class TestRandomSQL extends TestBase {
} }
private void deleteDb() { private void deleteDb() {
String name = getDatabaseName(); FileUtils.delete(getDatabaseName());
if (name.startsWith("memFS:")) {
DeleteDbFiles.execute("memFS:/", name, true);
} else {
DeleteDbFiles.execute(getBaseDir() + "/dataRandomSQL", null, true);
FileUtils.delete(getBaseDir() + "/dataRandomSQL");
}
} }
@Override @Override
...@@ -111,7 +104,8 @@ public class TestRandomSQL extends TestBase { ...@@ -111,7 +104,8 @@ public class TestRandomSQL extends TestBase {
public void testCase(int i) throws Exception { public void testCase(int i) throws Exception {
String old = SysProperties.getScriptDirectory(); String old = SysProperties.getScriptDirectory();
try { try {
System.setProperty(SysProperties.H2_SCRIPT_DIRECTORY, "dataScript/"); System.setProperty(SysProperties.H2_SCRIPT_DIRECTORY,
getBaseDir() + "/" + getTestName());
seed = i; seed = i;
printTime("seed: " + seed); printTime("seed: " + seed);
deleteDb(); deleteDb();
......
...@@ -56,28 +56,28 @@ public class TestAutoReconnect extends TestBase { ...@@ -56,28 +56,28 @@ public class TestAutoReconnect extends TestBase {
testReconnect(); testReconnect();
autoServer = false; autoServer = false;
testReconnect(); testReconnect();
deleteDb("autoReconnect"); deleteDb(getTestName());
} }
private void testWrongUrl() throws Exception { private void testWrongUrl() throws Exception {
deleteDb("autoReconnect"); deleteDb(getTestName());
Server tcp = Server.createTcpServer().start(); Server tcp = Server.createTcpServer().start();
try { try {
conn = getConnection("jdbc:h2:" + getBaseDir() + conn = getConnection("jdbc:h2:" + getBaseDir() +
"/autoReconnect;AUTO_SERVER=TRUE"); "/" + getTestName() + ";AUTO_SERVER=TRUE");
assertThrows(ErrorCode.DATABASE_ALREADY_OPEN_1, this). assertThrows(ErrorCode.DATABASE_ALREADY_OPEN_1, this).
getConnection("jdbc:h2:" + getBaseDir() + getConnection("jdbc:h2:" + getBaseDir() +
"/autoReconnect;OPEN_NEW=TRUE"); "/" + getTestName() + ";OPEN_NEW=TRUE");
assertThrows(ErrorCode.DATABASE_ALREADY_OPEN_1, this). assertThrows(ErrorCode.DATABASE_ALREADY_OPEN_1, this).
getConnection("jdbc:h2:" + getBaseDir() + getConnection("jdbc:h2:" + getBaseDir() +
"/autoReconnect;OPEN_NEW=TRUE"); "/" + getTestName() + ";OPEN_NEW=TRUE");
conn.close(); conn.close();
conn = getConnection("jdbc:h2:tcp://localhost/" + getBaseDir() + conn = getConnection("jdbc:h2:tcp://localhost/" + getBaseDir() +
"/autoReconnect"); "/" + getTestName());
assertThrows(ErrorCode.DATABASE_ALREADY_OPEN_1, this). assertThrows(ErrorCode.DATABASE_ALREADY_OPEN_1, this).
getConnection("jdbc:h2:" + getBaseDir() + getConnection("jdbc:h2:" + getBaseDir() +
"/autoReconnect;AUTO_SERVER=TRUE;OPEN_NEW=TRUE"); "/" + getTestName() + ";AUTO_SERVER=TRUE;OPEN_NEW=TRUE");
conn.close(); conn.close();
} finally { } finally {
tcp.stop(); tcp.stop();
...@@ -85,15 +85,15 @@ public class TestAutoReconnect extends TestBase { ...@@ -85,15 +85,15 @@ public class TestAutoReconnect extends TestBase {
} }
private void testReconnect() throws Exception { private void testReconnect() throws Exception {
deleteDb("autoReconnect"); deleteDb(getTestName());
if (autoServer) { if (autoServer) {
url = "jdbc:h2:" + getBaseDir() + "/autoReconnect;" + url = "jdbc:h2:" + getBaseDir() + "/" + getTestName() + ";" +
"FILE_LOCK=SOCKET;" + "FILE_LOCK=SOCKET;" +
"AUTO_SERVER=TRUE;OPEN_NEW=TRUE"; "AUTO_SERVER=TRUE;OPEN_NEW=TRUE";
restart(); restart();
} else { } else {
server = Server.createTcpServer("-tcpPort", "8181").start(); server = Server.createTcpServer("-tcpPort", "8181").start();
url = "jdbc:h2:tcp://localhost:8181/" + getBaseDir() + "/autoReconnect;" + url = "jdbc:h2:tcp://localhost:8181/" + getBaseDir() + "/" + getTestName() + ";" +
"FILE_LOCK=SOCKET;AUTO_RECONNECT=TRUE"; "FILE_LOCK=SOCKET;AUTO_RECONNECT=TRUE";
} }
......
...@@ -44,12 +44,12 @@ public class TestConnectionInfo extends TestBase { ...@@ -44,12 +44,12 @@ public class TestConnectionInfo extends TestBase {
return; return;
} }
assertThrows(ErrorCode.URL_RELATIVE_TO_CWD, this). assertThrows(ErrorCode.URL_RELATIVE_TO_CWD, this).
getConnection("jdbc:h2:test"); getConnection("jdbc:h2:" + getTestName());
assertThrows(ErrorCode.URL_RELATIVE_TO_CWD, this). assertThrows(ErrorCode.URL_RELATIVE_TO_CWD, this).
getConnection("jdbc:h2:data/test"); getConnection("jdbc:h2:data/" + getTestName());
getConnection("jdbc:h2:./testDatabase").close(); getConnection("jdbc:h2:./data/" + getTestName()).close();
DeleteDbFiles.execute(".", "testDatabase", true); DeleteDbFiles.execute("data", getTestName(), true);
} }
private void testConnectInitError() throws Exception { private void testConnectInitError() throws Exception {
...@@ -62,14 +62,14 @@ public class TestConnectionInfo extends TestBase { ...@@ -62,14 +62,14 @@ public class TestConnectionInfo extends TestBase {
private void testConnectionInfo() { private void testConnectionInfo() {
Properties info = new Properties(); Properties info = new Properties();
ConnectionInfo connectionInfo = new ConnectionInfo( ConnectionInfo connectionInfo = new ConnectionInfo(
"jdbc:h2:mem:test" + "jdbc:h2:mem:" + getTestName() +
";LOG=2" + ";LOG=2" +
";ACCESS_MODE_DATA=rws" + ";ACCESS_MODE_DATA=rws" +
";INIT=CREATE this...\\;INSERT that..." + ";INIT=CREATE this...\\;INSERT that..." +
";IFEXISTS=TRUE", ";IFEXISTS=TRUE",
info); info);
assertEquals("jdbc:h2:mem:test", assertEquals("jdbc:h2:mem:" + getTestName(),
connectionInfo.getURL()); connectionInfo.getURL());
assertEquals("2", assertEquals("2",
......
...@@ -17,7 +17,7 @@ import org.h2.util.SmallLRUCache; ...@@ -17,7 +17,7 @@ import org.h2.util.SmallLRUCache;
import org.h2.util.TempFileDeleter; import org.h2.util.TempFileDeleter;
/** /**
* Tests the in-memory file system. * Tests the in-memory file store.
*/ */
public class TestFile extends TestBase implements DataHandler { public class TestFile extends TestBase implements DataHandler {
......
/*
* Copyright 2004-2014 H2 Group. Multiple-Licensed under the MPL 2.0,
* and the EPL 1.0 (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
*/
package org.h2.test.unit;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Locale;
import org.h2.test.TestBase;
public class TestLocale extends TestBase {
/**
* Run just this test.
*
* @param a ignored
*/
public static void main(String... a) throws Exception {
// System.setProperty("h2.storeLocalTime", "true");
TestBase.createCaller().init().test();
}
@Override
public void test() throws SQLException {
testSpecialLocale();
}
private void testSpecialLocale() throws SQLException {
deleteDb(getTestName());
Connection conn = getConnection(getTestName());
Statement stat = conn.createStatement();
Locale old = Locale.getDefault();
try {
// when using Turkish as the default locale, "i".toUpperCase() is
// not "I"
Locale.setDefault(new Locale("tr"));
stat.execute("create table test(I1 int, i2 int, b int, c int, d int) " +
"as select 1, 1, 1, 1, 1");
ResultSet rs = stat.executeQuery("select * from test");
rs.next();
rs.getString("I1");
rs.getString("i1");
rs.getString("I2");
rs.getString("i2");
stat.execute("drop table test");
} finally {
Locale.setDefault(old);
}
conn.close();
}
}
...@@ -38,18 +38,18 @@ public class TestSampleApps extends TestBase { ...@@ -38,18 +38,18 @@ public class TestSampleApps extends TestBase {
if (!getBaseDir().startsWith(TestBase.BASE_TEST_DIR)) { if (!getBaseDir().startsWith(TestBase.BASE_TEST_DIR)) {
return; return;
} }
deleteDb("optimizations"); deleteDb(getTestName());
InputStream in = getClass().getClassLoader().getResourceAsStream( InputStream in = getClass().getClassLoader().getResourceAsStream(
"org/h2/samples/optimizations.sql"); "org/h2/samples/optimizations.sql");
new File(getBaseDir()).mkdirs(); new File(getBaseDir()).mkdirs();
FileOutputStream out = new FileOutputStream(getBaseDir() + FileOutputStream out = new FileOutputStream(getBaseDir() +
"/optimizations.sql"); "/optimizations.sql");
IOUtils.copyAndClose(in, out); IOUtils.copyAndClose(in, out);
String url = "jdbc:h2:" + getBaseDir() + "/optimizations"; String url = "jdbc:h2:" + getBaseDir() + "/" + getTestName();
testApp("", org.h2.tools.RunScript.class, "-url", url, "-user", "sa", testApp("", org.h2.tools.RunScript.class, "-url", url, "-user", "sa",
"-password", "sa", "-script", getBaseDir() + "-password", "sa", "-script", getBaseDir() +
"/optimizations.sql", "-checkResults"); "/optimizations.sql", "-checkResults");
deleteDb("optimizations"); deleteDb(getTestName());
testApp("Compacting...\nDone.", org.h2.samples.Compact.class); testApp("Compacting...\nDone.", org.h2.samples.Compact.class);
testApp("NAME: Bob Meier\n" + testApp("NAME: Bob Meier\n" +
"EMAIL: bob.meier@abcde.abc\n" + "EMAIL: bob.meier@abcde.abc\n" +
......
...@@ -517,6 +517,13 @@ public class TestTools extends TestBase { ...@@ -517,6 +517,13 @@ public class TestTools extends TestBase {
} }
private void testServerMain() throws SQLException { private void testServerMain() throws SQLException {
testNonSSL();
if (!config.fast) {
testSSL();
}
}
private void testNonSSL() throws SQLException {
String result; String result;
Connection conn; Connection conn;
...@@ -538,6 +545,11 @@ public class TestTools extends TestBase { ...@@ -538,6 +545,11 @@ public class TestTools extends TestBase {
result = runServer(0, new String[]{"-tcpShutdown", result = runServer(0, new String[]{"-tcpShutdown",
"tcp://localhost:9001", "-tcpPassword", "abc", "-tcpShutdownForce"}); "tcp://localhost:9001", "-tcpPassword", "abc", "-tcpShutdownForce"});
assertTrue(result.contains("Shutting down")); assertTrue(result.contains("Shutting down"));
}
private void testSSL() throws SQLException {
String result;
Connection conn;
result = runServer(0, new String[]{"-tcp", result = runServer(0, new String[]{"-tcp",
"-tcpAllowOthers", "-tcpPort", "9001", "-tcpPassword", "abcdef", "-tcpSSL"}); "-tcpAllowOthers", "-tcpPort", "9001", "-tcpPassword", "abcdef", "-tcpSSL"});
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论