Skip to content

Commit f22460f

Browse files

File tree

4 files changed

+23
-28
lines changed

4 files changed

+23
-28
lines changed

.travis.yml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,6 @@ sudo: false
99
script:
1010
- sbt "++ ${TRAVIS_SCALA_VERSION}!" test
1111
- git diff --exit-code # check scalariform
12-
addons:
13-
postgresql: '9.3'
1412
before_script:
1513
- rm project/pgp.sbt && rm project/sbt-updates.sbt && rm project/sonatype.sbt
1614
- git add . --all
17-
- psql -c "CREATE ROLE sa WITH SUPERUSER LOGIN PASSWORD 'sa';" -U postgres
18-
- psql -c "CREATE DATABASE scalikejdbc;" -U postgres
19-
- psql -c "CREATE DATABASE scalikejdbc2;" -U postgres
20-
- mysql -e 'GRANT ALL ON *.* TO sa@"localhost"IDENTIFIED BY "sa";FLUSH PRIVILEGES;'
21-
-uroot
22-
- mysql -e "CREATE DATABASE scalikejdbc;" -usa -psa

build.sbt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ lazy val _version = "0.11.1-SNAPSHOT"
22
lazy val scalikejdbcVersion = "3.3.5"
33
lazy val mauricioVersion = "0.2.21" // provided
44
lazy val postgresqlVersion = "42.2.2"
5+
lazy val testContainer = "1.11.3"
56
val Scala211 = "2.11.12"
67
val Scala212 = "2.12.8"
78

@@ -24,6 +25,9 @@ lazy val core = (project in file("core")).settings(
2425
"org.scalikejdbc" %% "scalikejdbc-joda-time" % scalikejdbcVersion % "test",
2526
"com.github.mauricio" %% "postgresql-async" % mauricioVersion % "provided",
2627
"com.github.mauricio" %% "mysql-async" % mauricioVersion % "provided",
28+
"com.dimafeng" %% "testcontainers-scala" % "0.27.0" % "test",
29+
"org.testcontainers" % "mysql" % testContainer % "test",
30+
"org.testcontainers" % "postgresql" % testContainer % "test",
2731
"org.postgresql" % "postgresql" % postgresqlVersion % "test",
2832
"mysql" % "mysql-connector-java" % "5.1.+" % "test",
2933
"org.scalatest" %% "scalatest" % "3.0.+" % "test",

core/src/test/scala/programmerlist/ExampleSpec.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,11 @@ class ExampleSpec extends FlatSpec with Matchers with DBSettings with Logging {
6464
it should "work for more than pool size items" in {
6565

6666
val MaxPoolSize = 2
67-
AsyncConnectionPool.add('test, "jdbc:postgresql://localhost:5432/scalikejdbc", "sa", "sa",
67+
val name = Symbol("test")
68+
AsyncConnectionPool.add(name, postgres.jdbcUrl, postgres.username, postgres.password,
6869
AsyncConnectionPoolSettings(maxPoolSize = MaxPoolSize))
6970

70-
implicit val session = NamedAsyncDB('test).sharedSession
71+
implicit val session = NamedAsyncDB(name).sharedSession
7172

7273
val futureProgrammers = Future.sequence((1 to MaxPoolSize * 2) map { i => Programmer.create(s"p$i", Some(1)) })
7374
val programmers = Await.result(futureProgrammers, 5.seconds)
Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,34 @@
11
package unit
22

3-
import scalikejdbc._, async._
4-
5-
trait DBSettings {
6-
DBSettings.initialize()
7-
}
8-
9-
object DBSettings {
10-
11-
private var isInitialized = false
12-
13-
def initialize(): Unit = this.synchronized {
14-
if (isInitialized) return
3+
import scalikejdbc._
4+
import async._
5+
import com.dimafeng.testcontainers.{ ForAllTestContainer, MultipleContainers, MySQLContainer, PostgreSQLContainer }
6+
import org.scalatest.Suite
7+
8+
trait DBSettings extends ForAllTestContainer { self: Suite =>
9+
// TODO update mysql version
10+
protected[this] final val mysql = MySQLContainer(mysqlImageVersion = "mysql:5.6.44")
11+
protected[this] final val postgres = PostgreSQLContainer("postgres:11.4")
12+
override val container = MultipleContainers(mysql, postgres)
13+
14+
override def afterStart(): Unit = {
1515
GlobalSettings.loggingSQLErrors = false
1616

1717
// default: PostgreSQL
18-
ConnectionPool.singleton("jdbc:postgresql://localhost:5432/scalikejdbc", "sa", "sa")
19-
AsyncConnectionPool.singleton("jdbc:postgresql://localhost:5432/scalikejdbc", "sa", "sa")
18+
ConnectionPool.singleton(url = postgres.jdbcUrl, user = postgres.username, password = postgres.password)
19+
AsyncConnectionPool.singleton(url = postgres.jdbcUrl, user = postgres.username, password = postgres.password)
2020

2121
SampleDBInitializer.initPostgreSQL()
2222
PgListDBInitializer.initPostgreSQL()
2323

2424
// MySQL
25-
ConnectionPool.add('mysql, "jdbc:mysql://localhost:3306/scalikejdbc", "sa", "sa")
26-
AsyncConnectionPool.add('mysql, "jdbc:mysql://localhost:3306/scalikejdbc", "sa", "sa")
25+
ConnectionPool.add(Symbol("mysql"), url = mysql.jdbcUrl, user = mysql.username, password = mysql.password)
26+
AsyncConnectionPool.add(Symbol("mysql"), url = mysql.jdbcUrl, user = mysql.username, password = mysql.password)
2727

2828
SampleDBInitializer.initMySQL()
2929
PgListDBInitializer.initMySQL()
3030
PersonDBInitializer.initMySQL()
3131
AccountDBInitializer.initMySQL()
32-
33-
isInitialized = true
3432
}
3533

3634
}

0 commit comments

Comments
 (0)