In-memory MariaDB4j for testing Liquibase changesets

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(;
  	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
  	String url = config.getURL(dbName);
  	props.setProperty(Environment.URL, url);
  	props.setProperty(Environment.USER, "root");
  	props.setProperty(Environment.PASS, "");

I can see in the logs that the mysql database is installed and running, However, I got this error in my test method :

DatabaseUpdater.executeChangelog(“liquibase.xml”, null);

The error is :

java.sql.SQLException: Unknown system variable 'REFERENTIAL_INTEGRITY'

Here is my pom :




Thanks a lot in advance, in cc @mksd @dkayiwa (I putted you in copy because I saw that you did some job with MariaDb4j :slight_smile: )

1 Like

Does the full stack trace give more clues?

here are full logs

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()) {

Or rather this is for H2:


… and apparently this is for MySQL/MariaDB:

SET @@foreign_key_checks = 0/1;

See here.

Exactly, it looks like it is version problem. But, I tried many version dependencies but still getting the same error.

Ok, very good to know, so it looks like we can use only H2 as in memory db, because it is almost hardcoded in openmrs core, right ?

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.

1 Like

it makes sense , thanks a lot @mksd

FWIW, @wolf is replacing H2 with mariadb4j while working on this ticket:


Well, it’s worth quite a lot in the context of what @amine’s up to :slight_smile: Great stuff.

@dkayiwa this is a good news, thanks for the info.

By the way, I have found this dependency which allow to “hack” H2 database and add missed MySql functions.

However, in my test class I have to call this method to update my datasource :


How can we get the DataSource object from _Test Class ?

Thanks again,


update : just for info, it works like that :

Properties props = getRuntimeProperties();

JdbcDataSource dataSource = new JdbcDataSource();


dataSource.setUser(props.getProperty(Environment.USER)); dataSource.setPassword(props.getProperty(Environment.PASS)); H2FunctionsLoader.loadMysqlFunctions(dataSource); DatabaseUpdater.executeChangelog(“liquibase.xml”, null);

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.


Hello, Am trying to embed mysql with mariaDB4J in openmrs standalone via this ticket, with my new commits here however when am trying to test it, i fall into errors, As suggested by @dkayiwa to have changes in this file suggested here, after building the standalone the same logs it seems that for us to run on mariaDB4J we need to replace this line with equivalent url for mariaDB4J . Am still blocked your help will be appreciated thanks cc @dkayiwa @ibacher @mksd

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 :+1:

@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:

Any objections there? @ibacher @mseaton?

1 Like

This is awesome! :slight_smile:

No objections from me.

1 Like

Great, I created

  • TRUNK-5980: BaseContextSensitiveTest to allow further protected overrides

Cc @gcliff @sharif

1 Like

Thanks @mksd Pr here