Configuring overrides to use H2 for testing

We recently made the decision to move our persistence from Cassandra to Postgres and, as such, we need a way to use H2 in our self-contained tests. We have the following configuration overrides present in our test setup:

 override def additionalConfiguration: AdditionalConfiguration =
          super.additionalConfiguration ++ Configuration.from(
            Map(
              "db.default.driver" -> "org.h2.Driver",
              "db.default.url" -> "jdbc:h2:mem:test",
              "jdbc-defaults.slick.profile" -> "slick.jdbc.H2Profile$"
            ))

But when we attempt to run the tests we receive the following error:

com.typesafe.config.ConfigException$Missing: No configuration setting found for key 'slick.profile'

Could not find a huge number of resources for using H2 with Lagom specifically, but every reference I could find on using H2 via Slick in Scala generally shows that this configuration is sensible, assuming that Lagom is forwarding the configuration correctly. Is it perhaps that Lagom is not mapping the configuration correctly?

@dkushner, this config seems to be correct.

Do you have more context on the ConfigException? From where it’s coming?
Could you also provide a reproducer for it?

And are you using Slick yourself? By that I mean, are you initializing a Slick Database yourself somewhere in your code? If so, instead you should inject the one that is configured by Lagom.

Here is the full stack I was given:

[info]   com.typesafe.config.ConfigException$Missing: No configuration setting found for key 'slick.profile'
[info]   at com.typesafe.config.impl.SimpleConfig.findKeyOrNull(SimpleConfig.java:156)
[info]   at com.typesafe.config.impl.SimpleConfig.findOrNull(SimpleConfig.java:174)
[info]   at com.typesafe.config.impl.SimpleConfig.findOrNull(SimpleConfig.java:180)
[info]   at com.typesafe.config.impl.SimpleConfig.find(SimpleConfig.java:188)
[info]   at com.typesafe.config.impl.SimpleConfig.find(SimpleConfig.java:193)
[info]   at com.typesafe.config.impl.SimpleConfig.getString(SimpleConfig.java:250)
[info]   at slick.basic.DatabaseConfig$.$anonfun$forConfig$4(DatabaseConfig.scala:88)
[info]   at scala.Option.getOrElse(Option.scala:121)
[info]   at slick.basic.DatabaseConfig$.$anonfun$forConfig$1(DatabaseConfig.scala:88)
[info]   at scala.Option.getOrElse(Option.scala:121)

Apologies for the log level leader. We’re not doing anthing exotic with Slick directly, I literally just followed the guide to convert our project from using Cassandra for snapshot storage to JDBC. Any help would be greatly appreciated as the documentation about how Slick fits into this is a bit limited.

This exception is being thrown from inside Slick code which means that at some point the wrong config is being passed to Slick.

And that doesn’t make much sense. If it’s working for Postgres, it should work for H2. We will need to have a reproducer. Would it be possible to publish a small project on GitHub where you can reproduce this?

Btw, you will need to use the following for the DB URL.

jdbc:h2:mem:test;DB_CLOSE_DELAY=-1

From H2 documentation

By default, closing the last connection to a database closes the
database. For an in-memory database, this means the content is lost.
To keep the database open, add ;DB_CLOSE_DELAY=-1 to the database URL.
To keep the content of an in-memory database as long as the virtual
machine is alive, use jdbc:h2:mem:test;DB_CLOSE_DELAY=-1.

(see this SO thread: java - in memory database h2 how long keep connection open? - Stack Overflow)

Thank you for the reply. I will work on a reproduction case. In the mean time, perhaps being able to view the full stack will make it more obvious what component is failing to forward my configuration correctly. Is there some configuration available for the Lagom logger to display the full stack trace?