import org.apache.commons.dbcp.PoolableConnectionFactory;\r
import org.apache.commons.dbcp.PoolingDataSource;\r
import org.apache.commons.pool.impl.GenericObjectPool;\r
+import org.hsqldb.persist.HsqlProperties;\r
import org.junit.Assert;\r
import org.junit.runner.JUnitCore;\r
import org.junit.runner.Result;\r
private static final TestDb[] TEST_DBS = {\r
new TestDb("H2", true, true, "jdbc:h2:mem:iciql"),\r
new TestDb("H2", true, false, "jdbc:h2:file:testdbs/h2/iciql"),\r
+ new TestDb("H2", false, false, "jdbc:h2:tcp://localhost/"\r
+ + new File(System.getProperty("user.dir")).getAbsolutePath() + "/testdbs/h2tcp/iciql"),\r
new TestDb("HSQL", true, true, "jdbc:hsqldb:mem:iciql"),\r
new TestDb("HSQL", true, false, "jdbc:hsqldb:file:testdbs/hsql/iciql"),\r
+ new TestDb("HSQL", false, false, "jdbc:hsqldb:hsql://localhost/iciql"),\r
new TestDb("Derby", true, true, "jdbc:derby:memory:iciql;create=true"),\r
new TestDb("Derby", true, false, "jdbc:derby:directory:testdbs/derby/iciql;create=true"),\r
- new TestDb("MySQL", false, false, "jdbc:mysql://localhost:3306/iciql"),\r
- new TestDb("PostgreSQL", false, false, "jdbc:postgresql://localhost:5432/iciql") };\r
+ new TestDb("MySQL", false, false, "jdbc:mysql://localhost:7000/iciql", "sa", "sa"),\r
+ new TestDb("PostgreSQL", false, false, "jdbc:postgresql://localhost:5432/iciql", "sa", "sa") };\r
\r
private static final TestDb DEFAULT_TEST_DB = TEST_DBS[0];\r
\r
private static final PrintStream ERR = System.err;\r
\r
- private static String username = "sa";\r
-\r
- private static String password = "sa";\r
-\r
private static PrintStream out = System.out;\r
\r
- private static Map<String, PoolableConnectionFactory> connectionFactories = Utils.newSynchronizedHashMap();\r
+ private static Map<String, PoolableConnectionFactory> connectionFactories = Utils\r
+ .newSynchronizedHashMap();\r
\r
private static Map<String, PoolingDataSource> dataSources = Utils.newSynchronizedHashMap();\r
\r
* @return a fresh Db object\r
*/\r
public static Db openNewDb() {\r
- String testUrl = System.getProperty("iciql.url");\r
- if (testUrl == null) {\r
- testUrl = DEFAULT_TEST_DB.url;\r
- }\r
+ String testUrl = System.getProperty("iciql.url", DEFAULT_TEST_DB.url);\r
+ String testUser = System.getProperty("iciql.user", DEFAULT_TEST_DB.username);\r
+ String testPassword = System.getProperty("iciql.password", DEFAULT_TEST_DB.password);\r
+\r
Db db = null;\r
PoolingDataSource dataSource = dataSources.get(testUrl);\r
if (dataSource == null) {\r
- ConnectionFactory connectionFactory = new DriverManagerConnectionFactory(testUrl, username,\r
- password);\r
+ ConnectionFactory connectionFactory = new DriverManagerConnectionFactory(testUrl, testUser,\r
+ testPassword);\r
GenericObjectPool pool = new GenericObjectPool();\r
pool.setWhenExhaustedAction(GenericObjectPool.WHEN_EXHAUSTED_GROW);\r
PoolableConnectionFactory factory = new PoolableConnectionFactory(connectionFactory, pool, null,\r
* @return the current database\r
*/\r
public static Db openCurrentDb() {\r
- String testUrl = System.getProperty("iciql.url");\r
- if (testUrl == null) {\r
- testUrl = DEFAULT_TEST_DB.url;\r
- }\r
- return Db.open(testUrl, username, password);\r
+ String testUrl = System.getProperty("iciql.url", DEFAULT_TEST_DB.url);\r
+ String testUser = System.getProperty("iciql.user", DEFAULT_TEST_DB.username);\r
+ String testPassword = System.getProperty("iciql.password", DEFAULT_TEST_DB.password);\r
+ return Db.open(testUrl, testUser, testPassword);\r
}\r
\r
/**\r
public static String getDefaultSchema(Db db) {\r
if (isDerby(db)) {\r
// Derby sets default schema name to username\r
- return username.toUpperCase();\r
+ return "SA";\r
} else if (isMySQL(db)) {\r
// MySQL does not have schemas\r
return null;\r
\r
deleteRecursively(new File("testdbs"));\r
\r
+ // Start the HSQL and H2 servers in-process\r
+ org.hsqldb.Server hsql = startHSQL();\r
+ org.h2.tools.Server h2 = startH2();\r
+\r
// Statement logging\r
final FileWriter statementWriter;\r
if (StringUtils.isNullOrEmpty(params.sqlStatementsFile)) {\r
out.println("Skipping. Could not find " + testDb.url);\r
out.println();\r
} else {\r
- // Test database\r
+ // Setup system properties\r
System.setProperty("iciql.url", testDb.url);\r
+ System.setProperty("iciql.user", testDb.username);\r
+ System.setProperty("iciql.password", testDb.password);\r
+\r
+ // Test database\r
Result result = JUnitCore.runClasses(suiteClasses.value());\r
+\r
+ // Report results\r
testDb.runtime = result.getRunTime();\r
if (testDb.runtime < quickestDatabase) {\r
quickestDatabase = testDb.runtime;\r
if (statementWriter != null) {\r
statementWriter.close();\r
}\r
+ hsql.stop();\r
+ h2.stop();\r
System.exit(0);\r
}\r
\r
f.delete();\r
}\r
\r
+ /**\r
+ * Start an HSQL tcp server.\r
+ * \r
+ * @return an HSQL server instance\r
+ * @throws Exception\r
+ */\r
+ private static org.hsqldb.Server startHSQL() throws Exception {\r
+ HsqlProperties p = new HsqlProperties();\r
+ String db = new File(System.getProperty("user.dir")).getAbsolutePath() + "/testdbs/hsqltcp/iciql";\r
+ p.setProperty("server.database.0", "file:" + db);\r
+ p.setProperty("server.dbname.0", "iciql");\r
+ // set up the rest of properties\r
+\r
+ // alternative to the above is\r
+ org.hsqldb.Server server = new org.hsqldb.Server(); \r
+ server.setProperties(p);\r
+ server.setLogWriter(null);\r
+ server.setErrWriter(null);\r
+ server.start();\r
+ return server;\r
+ }\r
+\r
+ /**\r
+ * Start the H2 tcp server.\r
+ * \r
+ * @return an H2 server instance\r
+ * @throws Exception\r
+ */\r
+ private static org.h2.tools.Server startH2() throws Exception {\r
+ org.h2.tools.Server server = org.h2.tools.Server.createTcpServer();\r
+ server.start();\r
+ return server;\r
+ }\r
+\r
/**\r
* Represents a test database url.\r
*/\r
boolean isEmbedded;\r
boolean isMemory;\r
final String url;\r
+ final String username;\r
+ final String password;\r
String version;\r
long runtime;\r
long statements;\r
\r
TestDb(String name, boolean isEmbedded, boolean isMemory, String url) {\r
+ this(name, isEmbedded, isMemory, url, "sa", "");\r
+ }\r
+\r
+ TestDb(String name, boolean isEmbedded, boolean isMemory, String url, String username, String password) {\r
this.name = name;\r
this.isEmbedded = isEmbedded;\r
this.isMemory = isMemory;\r
this.url = url;\r
+ this.username = username;\r
+ this.password = password;\r
}\r
\r
double getRuntime() {\r