Work with derby internal caching of "derby.system.home" system property.
+ Turns out, changing "derby.system.home" is unreliable. + Using 'directory' based jdbc urls for derby to avoid finding content in the classloader too. + Use a common derby "System Home" for all tests. + Segregate all database creation into own, test-specific, database.
This commit is contained in:
parent
a09d05ee9d
commit
e9a77b6ac7
|
@ -73,13 +73,8 @@ public class DataSourceLoginServiceTest
|
|||
out.write(_content.getBytes("utf-8"));
|
||||
out.close();
|
||||
|
||||
_dbRoot = new File(_docRoot, "derby");
|
||||
String dbPath = _dbRoot.getAbsolutePath();
|
||||
System.setProperty("derby.system.home", dbPath);
|
||||
FS.ensureEmpty(_dbRoot);
|
||||
|
||||
File scriptFile = MavenTestingUtils.getTestResourceFile("createdb.sql");
|
||||
DatabaseLoginServiceTestServer.createDB(dbPath, scriptFile, "jdbc:derby:dstest;create=true");
|
||||
_dbRoot = DatabaseLoginServiceTestServer.createDB(scriptFile,"dstest");
|
||||
|
||||
_testServer = new DatabaseLoginServiceTestServer();
|
||||
_testServer.setResourceBase(_docRoot.getAbsolutePath());
|
||||
|
@ -120,8 +115,7 @@ public class DataSourceLoginServiceTest
|
|||
|
||||
//create a datasource
|
||||
EmbeddedDataSource ds = new EmbeddedDataSource();
|
||||
File db = new File (_dbRoot, "dstest");
|
||||
ds.setDatabaseName(db.getAbsolutePath());
|
||||
ds.setDatabaseName(_dbRoot.getAbsolutePath());
|
||||
org.eclipse.jetty.plus.jndi.Resource binding = new org.eclipse.jetty.plus.jndi.Resource(null, "dstest",
|
||||
ds);
|
||||
assertThat("Created binding for dstest", binding, notNullValue());
|
||||
|
|
|
@ -54,6 +54,7 @@ import org.eclipse.jetty.servlet.DefaultServlet;
|
|||
import org.eclipse.jetty.servlet.ServletContextHandler;
|
||||
import org.eclipse.jetty.servlet.ServletHolder;
|
||||
import org.eclipse.jetty.toolchain.test.FS;
|
||||
import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
|
||||
import org.eclipse.jetty.util.IO;
|
||||
import org.eclipse.jetty.util.Loader;
|
||||
import org.eclipse.jetty.util.security.Constraint;
|
||||
|
@ -70,10 +71,20 @@ public class DatabaseLoginServiceTestServer
|
|||
protected LoginService _loginService;
|
||||
protected String _resourceBase;
|
||||
protected TestHandler _handler;
|
||||
private static File commonDerbySystemHome;
|
||||
protected static String _requestContent;
|
||||
|
||||
protected static void createDB(String homeDir, File scriptFile, String dbUrl) throws Exception
|
||||
protected static File createDB(File scriptFile, String dbName) throws Exception
|
||||
{
|
||||
if(commonDerbySystemHome == null)
|
||||
{
|
||||
commonDerbySystemHome = MavenTestingUtils.getTargetTestingDir("derby-system-common");
|
||||
FS.ensureEmpty(commonDerbySystemHome);
|
||||
System.setProperty("derby.system.home", commonDerbySystemHome.getAbsolutePath());
|
||||
}
|
||||
|
||||
String dbUrl = "jdbc:derby:directory:" + dbName + ";create=true";
|
||||
|
||||
try (FileInputStream fileStream = new FileInputStream(scriptFile))
|
||||
{
|
||||
Loader.loadClass(fileStream.getClass(), "org.apache.derby.jdbc.EmbeddedDriver").newInstance();
|
||||
|
@ -83,6 +94,10 @@ public class DatabaseLoginServiceTestServer
|
|||
int result = ij.runScript(connection, fileStream, "UTF-8", out, "UTF-8");
|
||||
|
||||
assertThat("runScript result",result, is(0));
|
||||
|
||||
File dbRoot = new File(commonDerbySystemHome, dbName);
|
||||
assertThat("exists: " + dbRoot, dbRoot.exists(), is(true));
|
||||
return dbRoot;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -81,14 +81,9 @@ public class JdbcLoginServiceTest
|
|||
{
|
||||
out.write(_content.getBytes("utf-8"));
|
||||
}
|
||||
|
||||
File dbRoot = new File(_docRoot, "derby");
|
||||
String dbPath = dbRoot.getAbsolutePath();
|
||||
System.setProperty("derby.system.home", dbPath);
|
||||
FS.ensureEmpty(dbRoot);
|
||||
|
||||
File scriptFile = MavenTestingUtils.getTestResourceFile("createdb.sql");
|
||||
DatabaseLoginServiceTestServer.createDB(dbPath, scriptFile, "jdbc:derby:jdbcrealm;create=true");
|
||||
DatabaseLoginServiceTestServer.createDB(scriptFile,"jdbcrealm");
|
||||
|
||||
File jdbcRealmFile = MavenTestingUtils.getTestResourceFile("jdbcrealm.properties");
|
||||
|
||||
|
|
Loading…
Reference in New Issue