I have some integration tests querying an OrientDB plocal Graph database.
I have a fixture which loads some data to the database. If the fixture is loaded as part of each test's setUp()
method then everything works and the tests run as expected.
Since the fixture is the same for all the tests, it makes sense to load the fixture only once, right before the execution of the tests begins.
I'm building the project using maven. During the pre-integration-test
phase I invoke a java class (via the exec-maven-plugin
) which does something like this:
String[] consoleArgs = { scriptUrl.getPath() };
OConsoleDatabaseApp consoleApp = new OConsoleDatabaseApp(consoleArgs);
try {
consoleApp.dropDatabase(iURL, TESTDB_USER, TESTDB_PASSWORD, storageType);
consoleApp.createDatabase(iURL, TESTDB_USER, TESTDB_PASSWORD, storageType, "graph");
} catch (IOException e1) {
throw new IllegalStateException(e1);
}
if (consoleApp.run() != 1) {
throw new IllegalStateException(ERROR_LOADING_SCHEMA);
}
consoleApp.disconnect();
consoleApp.close();
The invocation of this class ends fine, but when the first integration test tries to access the database I get a failure.
The exception:
com.orientechnologies.orient.core.exception.OStorageException: Cannot open local storage 'target/databases/benchmark-integration' with mode=rw
Caused by: com.orientechnologies.orient.core.exception.OSerializationException: Cannot load database's configuration. The database seems to be corrupted.
Caused by: com.orientechnologies.common.concur.lock.OLockException: File 'target\databases\benchmark-integration\database.ocf' is locked by another process, maybe the database is in use by another process.
It seems I'm forgetting to release something after loading the fixture.
Found an answer while looking at the static main
method in the OConsoleDatabaseApp
implementation.
After instantiating and using the console, the next line is executed.
Orient.instance().shutdown();
This seems to release the locked database.