Dear all,
I want to test liquibase changes throw Junit tests.
I have used Mariadb4j like that :
Properties props = getRuntimeProperties();
if (useInMemoryDatabase()) {
DBConfigurationBuilder config = DBConfigurationBuilder.newBuilder();
config.setPort(0); // 0 => autom. detect free port
DB db = DB.newEmbeddedDB(config.build());
db.start();
String dbName = "openmrs"; // or just "test"
if (!dbName.equals("test")) {
// mysqld out-of-the-box already has a DB named "test"
// in case we need another DB, here's how to create it first
db.createDB(dbName);
}
String url = config.getURL(dbName);
props.setProperty(Environment.URL, url);
props.setProperty(Environment.USER, "root");
props.setProperty(Environment.PASS, "");
}
Context.setRuntimeProperties(props);
I can see in the logs that the mysql database is installed and running, However, I got this error in my test method :
Anyway the quick guess is that the version of MariaDB you’re using doesn’t know of this system variable (REFERENTIAL_INTEGRITY). However it’s referenced here for all Spring tests:
if (useInMemoryDatabase()) {
constraintsOnSql = "SET REFERENTIAL_INTEGRITY TRUE";
}
Right now yes, but the base class for Spring tests could be made smarter for those who need something more sophisticated than H2.
You should try first on a fork of Core that you can make things work by bypassing that MariaDB-incompatible statement. I mean, before doing the investment of suggesting a properly designed change of BaseContextSensitiveTest.
However, not all mysql functions are covered, so if we complicated sql queries, you need to add some alias, or at least use functions which are compatible with both MySql and H2.
Thanks @amine, a lot of your exploratory work reported here. It helped me a lot getting MariaDB up and running for context-sensitive tests with mariaDB4j
@dkayiwa I have been doing that in the context of the upcoming Iniz Validator that will allow to make dry runs on OpenMRS configs as a standalone fatjar tool. For this I needed MariaDB rather than H2 to be able to preload the official CIEL SQL dump before replaying the config.
Long story short, all works well but I found that BaseContextSensitiveTest could be more helpful by letting a couple of methods be (non-final) protected (rather than currently private), namely: