@@ -83,85 +83,6 @@ libraryDependencies += Seq(
8383
8484Mix-in ` FlywaySpecSupport ` then, put the sql files in ` src/resources/flyway ` (` src/resources/** ` can be set to any string.), run ` flywayContext.flyway.migrate() ` in ` afterStartContainers ` method.
8585
86- ``` scala
87- class MySQLControllerSpec extends AnyFreeSpec with DockerControllerSpecSupport with FlywaySpecSupport {
88- val testTimeFactor : Int = sys.env.getOrElse(" TEST_TIME_FACTOR" , " 1" ).toInt
89- logger.debug(s " testTimeFactor = $testTimeFactor" )
90-
91- val hostPort : Int = temporaryServerPort()
92- val dbName : String . = " test"
93- val rootUserName : String = " root"
94- val rootPassword : String = " test"
95-
96- override protected def flywayDriverClassName : String = classOf [com.mysql.cj.jdbc.Driver ].getName
97- override protected def flywayDbHost : String = dockerHost
98- override protected def flywayDbHostPort : Int = hostPort
99- override protected def flywayDbName : String = dbName
100- override protected def flywayDbUserName : String = rootUserName
101- override protected def flywayDbPassword : String = rootPassword
102-
103- override protected def flywayJDBCUrl : String =
104- s " jdbc:mysql:// $flywayDbHost: $flywayDbHostPort/ $flywayDbName?useSSL=false&user= $flywayDbUserName&password= $flywayDbPassword"
105-
106- val controller : MySQLController = MySQLController (dockerClient)(hostPort, rootPassword, databaseName = Some (dbName))
107-
108- override protected val dockerControllers : Vector [DockerController ] = Vector (controller)
109-
110- override protected val waitPredicatesSettings : Map [DockerController , WaitPredicateSetting ] =
111- Map (
112- controller -> WaitPredicateSetting (
113- Duration .Inf ,
114- WaitPredicates .forListeningHostTcpPort(
115- dockerHost,
116- hostPort,
117- (1 * testTimeFactor).seconds,
118- Some ((5 * testTimeFactor).seconds)
119- )
120- )
121- )
122-
123- override protected def afterStartContainers (): Unit = {
124- // Configure the sql files in `src/reosources/flyway`.
125- val flywayContext = createFlywayContext(FlywayConfig (Seq (" flyway" )))
126- // Execute flywayMigrate command
127- flywayContext.flyway.migrate()
128- }
129-
130- " MySQLController" - {
131- " run" in {
132- var conn : Connection = null
133- var stmt : Statement = null
134- var resultSet : ResultSet = null
135- try {
136- Class .forName(flywayDriverClassName)
137- conn = DriverManager .getConnection(flywayJDBCUrl)
138- stmt = conn.createStatement
139- val result = stmt.executeUpdate(" INSERT INTO users VALUES(1, 'kato')" )
140- assert(result == 1 )
141- resultSet = stmt.executeQuery(" SELECT * FROM users" )
142- while (resultSet.next()) {
143- val id = resultSet.getInt(" id" )
144- val name = resultSet.getString(" name" )
145- println(s " id = $id, name = $name" )
146- }
147- } catch {
148- case NonFatal (ex) =>
149- ex.printStackTrace()
150- fail(" occurred error" , ex)
151- } finally {
152- if (resultSet != null )
153- resultSet.close()
154- if (stmt != null )
155- stmt.close()
156- if (conn != null )
157- conn.close()
158- }
159- }
160- }
161-
162- }
163- ```
164-
16586### How to test with DockerController your customized
16687
16788To launch a docker container for testing
0 commit comments