Search code examples
scalaspecs2scalikejdbc

Connection pool is not initialized in unit test with scalikejdbc 2.4.1


I have a problem when running unit test using specs2with scalikejdbc 2.4.1, scalikejdbc-config2.4.1 Here is my code:

    object PostDAOImplSpec extends Specification{

  sequential

  DBs.setupAll
  implicit val session = AutoSession

  "resolveAll shoudn't have any syntax error" in new AutoRollback {

    val postIds = DB readOnly { implicit session =>
      sql"select post_id from posts".map(_.long(1)).list.apply()
    }

  }

  DBs.closeAll()

}

Here is logs:

    09:11:16.931 [main] DEBUG scalikejdbc.ConnectionPool$ - Registered connection pool : ConnectionPool(url:jdbc:mysql://localhost/bbs, user:root) using factory : <default>
09:11:17.130 [main] DEBUG scalikejdbc.ConnectionPool$ - Registered connection pool : ConnectionPool(url:jdbc:mysql://localhost/bbs, user:root) using factory : <default>

java.lang.IllegalStateException: Connection pool is not yet initialized.(name:'default)
java.lang.IllegalStateException: Connection pool is not yet initialized.(name:'default)

As you can see from the first two of lines, scalikejdbc found database's configuration, but it can't initilize connection pool. Do you have any idea? Thanks.


Solution

  • The DBs.closeAll() closes your connection pools before running your tests.