8000 Merge pull request #392 from laserdisc-io/upgrades-tests · laserdisc-io/mysql-binlog-stream@e08db11 · GitHub
[go: up one dir, main page]

Skip to content

Commit e08db11

Browse files
authored
Merge pull request #392 from laserdisc-io/upgrades-tests
Upgrades, better type conversion tests
2 parents 34f8d02 + 5fcc3a1 commit e08db11

File tree

4 files changed

+71
-38
lines changed

4 files changed

+71
-38
lines changed

binlog-stream-models/test/io/laserdisc/mysql/binlog/models/SchemaMetadataTest.scala

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,17 @@ class SchemaMetadataTest extends AnyWordSpec with ForAllTestContainer with MySql
1414
"Schema Metadata" should {
1515

1616
"restore schema state from DB" in {
17+
18+
val props = new java.util.Properties()
19+
props.put("user", mySqlContainer.getUsername)
20+
props.put("password", mySqlContainer.getPassword)
21+
1722
implicit val testTransactor: Aux[IO, Unit] =
1823
Transactor.fromDriverManager[IO](
1924
mySqlContainer.getDriverClassName,
2025
s"${mySqlContainer.getJdbcUrl}?useSSL=false",
21-
mySqlContainer.getUsername,
22-
mySqlContainer.getPassword
26+
props,
27+
None
2328
)
2429
val schemaState =
2530
SchemaMetadata.buildSchemaMetadata("test").unsafeRunSync()

binlog-stream/test/io/laserdisc/mysql/binlog/stream/TransactionStateTest.scala

Lines changed: 50 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -140,21 +140,28 @@ class TransactionStateTest extends AnyWordSpec with Matchers with OptionValues {
140140
}
141141

142142
"transform binlog write event into json" in {
143-
val skuMeta =
144-
models.TableMetadata(
145-
"sku",
146-
Map(
147-
1 -> models.ColumnMetadata("id", "int", 1, isPk = true),
148-
2 -> models.ColumnMetadata("sku", "varchar", 2, isPk = false)
149-
)
150-
)
151-
val schemaMeta =
152-
models
153-
.SchemaMetadata(tables = Map("sku" -> skuMeta), idToTable = mutable.Map(123L -> skuMeta))
143+
144+
val TableName = "all_types_table"
145+
146+
val allTypes =
147+
List("int", "tinyint", "bigint", "date", "datetime", "decimal", "float", "text", "tinytext", "mediumtext", "longtext", "varchar")
148+
149+
val columnMeta = allTypes.zipWithIndex.map { case (mType, idx) =>
150+
val colName = s"${mType}Col"
151+
val ordinal = idx + 1
152+
ordinal -> models.ColumnMetadata(colName, mType, ordinal, isPk = colName == "intCol")
153+
}.toMap
154+
155+
val tableMeta = models.TableMetadata(TableName, columnMeta)
156+
157+
val schemaMeta = models.SchemaMetadata(
158+
tables = Map("all_types_table" -> tableMeta),
159+
idToTable = mutable.Map(123L -> tableMeta)
160+
)
154161

155162
val json = TransactionState.convertToJson(
156-
tableMeta = schemaMeta.tables("sku"),
157-
includedColumns = Array(0, 1),
163+
tableMeta = schemaMeta.tables(TableName),
164+
includedColumns = 0.until(columnMeta.size).toArray,
158165
timestamp = 12345L,
159166
action = "create",
160167
fileName = "file.12345",
@@ -163,20 +170,41 @@ class TransactionStateTest extends AnyWordSpec with Matchers with OptionValues {
163170
None,
164171
Some(
165172
Array(
166-
Some(1.asInstanceOf[io.Serializable]),
167-
Some("sku1".getBytes.asInstanceOf[io.Serializable])
173+
Some(100.asInstanceOf[io.Serializable]), // int
174+
Some(200.asInstanceOf[io.Serializable]), // tinyint
175+
Some(Long.MaxValue.asInstanceOf[io.Serializable]), // bigint
176+
Some(1672531200000L.asInstanceOf[io.Serializable]), // date
177+
Some(1672567872000L.asInstanceOf[io.Serializable]), // datetime
178+
Some(java.math.BigDecimal.valueOf(99887766).asInstanceOf[io.Serializable]), // decimal
179+
Some(111.222f.asInstanceOf[io.Serializable]), // float
180+
Some("some text".getBytes.asInstanceOf[io.Serializable]), // text
181+
Some("some tinytext".getBytes.asInstanceOf[io.Serializable]), // tinytext
182+
Some("some mediumtext".getBytes.asInstanceOf[io.Serializable]), // mediumtext
183+
Some("some longtext".getBytes.asInstanceOf[io.Serializable]), // longtext
184+
Some("a varchar".getBytes.asInstanceOf[io.Serializable]) // varchar
168185
)
169186
)
170187
)
171188
)
172-
val _pk = root.id.int
173-
val _id = root.after.id.int
174-
val _sku = root.after.sku.string
175-
json.table should be("sku")
189+
190+
json.table should be(TableName)
176191
json.timestamp should be(12345L)
177-
_id.getOption(json.row).value should be(1)
178-
_sku.getOption(json.row).value should be("sku1")
179-
_pk.getOption(json.pk).value should be(1)
192+
193+
val after = root.after
194+
195+
after.intCol.int.getOption(json.row).value should be(100)
196+
after.tinyintCol.int.getOption(json.row).value should be(200)
197+
after.bigintCol.long.getOption(json.row).value should be(Long.MaxValue)
198+
after.dateCol.long.getOption(json.row).value should be(1672531200000L)
199+
after.datetimeCol.long.getOption(json.row).value should be(1672567872000L)
200+
after.decimalCol.bigDecimal.getOption(json.row).value should be(BigDecimal.valueOf(99887766))
201+
after.floatCol.double.getOption(json.row).value should be(111.222)
202+
after.textCol.string.getOption(json.row).value should be("some text")
203+
after.tinytextCol.string.getOption(json.row).value should be("some tinytext")
204+
after.mediumtextCol.string.getOption(json.row).value should be("some mediumtext")
205+
after.longtextCol.string.getOption(json.row).value should be("some longtext")
206+
after.varcharCol.string.getOption(json.row).value should be("a varchar")
207+
180208
}
181209

182210
"extract 'truncated table sku' from SQL" in {

project/Dependencies.scala

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
import sbt.Keys.{libraryDependencies, _}
2-
import sbt._
1+
import sbt.*
2+
import sbt.Keys.libraryDependencies
33

44
object Dependencies {
5-
val cirisVersion = "3.2.0"
6-
val doobieVersion = "1.0.0-RC2"
5+
val cirisVersion = "3.3.0"
6+
val doobieVersion = "1.0.0-RC4"
77
val circeVersion = "0.14.6"
8-
val catsEffectVersion = "3.5.1"
8+
val catsEffectVersion = "3.5.2"
99

1010
val TestLib = Seq(
1111
libraryDependencies ++= Seq(
1212
"org.scalamock" %% "scalamock" % "5.2.0" % Test,
1313
"org.scalatest" %% "scalatest" % "3.2.17" % Test,
1414
"com.dimafeng" %% "testcontainers-scala" % "0.41.0" % Test,
15-
"org.testcontainers" % "mysql" % "1.19.0" % Test,
16-
"org.testcontainers" % "testcontainers" % "1.19.0" % Test
15+
"org.testcontainers" % "mysql" % "1.19.1" % Test,
16+
"org.testcontainers" % "testcontainers" % "1.19.1" % Test
1717
)
1818
)
1919

@@ -31,26 +31,26 @@ object Dependencies {
3131
"ch.qos.logback" % "logback-core" % "1.4.11",
3232
"org.slf4j" % "jcl-over-slf4j" % "2.0.9",
3333
"org.slf4j" % "jul-to-slf4j" % "2.0.9",
34-
"org.typelevel" %% "log4cats-slf4j" % "2.5.0"
34+
"org.typelevel" %% "log4cats-slf4j" % "2.6.0"
3535
)
3636
)
3737

3838
val Persistence = Seq(
3939
libraryDependencies ++= Seq(
4040
"org.tpolecat" %% "doobie-core" % doobieVersion,
41-
"org.tpolecat" %% "doobie-hikari" % doobieVersion, // HikariCP transactor.
42-
"org.tpolecat" %% "doobie-refined" % doobieVersion, // Postgres driver 42.1.4 + type mappings.
43-
"org.tpolecat" %% "doobie-scalatest" % doobieVersion % Test, // Support for doobie scalatest
41+
"org.tpolecat" %% "doobie-hikari" % doobieVersion,
42+
"org.tpolecat" %% "doobie-refined" % doobieVersion,
43+
"org.tpolecat" %% "doobie-scalatest" % doobieVersion % Test,
4444
"mysql" % "mysql-connector-java" % "8.0.33",
45-
"com.zendesk" % "mysql-binlog-connector-java" % "0.28.1"
45+
"com.zendesk" % "mysql-binlog-connector-java" % "0.28.2"
4646
)
4747
)
4848

4949
val Circe = Seq(
5050
libraryDependencies ++= Seq(
5151
"io.circe" %% "circe-core" % circeVersion,
5252
"io.circe" %% "circe-parser" % circeVersion,
53-
"io.circe" %% "circe-optics" % "0.14.1" % Test
53+
"io.circe" %% "circe-optics" % "0.15.0" % Test
5454
)
5555
)
5656

project/build.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
sbt.version=1.9.4
1+
sbt.version=1.9.6

0 commit comments

Comments
 (0)
0