Skip to content

Commit

Permalink
Ignore DBStoreSpec
Browse files Browse the repository at this point in the history
  • Loading branch information
alekslitvinenk committed Dec 19, 2023
1 parent 84baa35 commit 086e4fd
Show file tree
Hide file tree
Showing 4 changed files with 129 additions and 42 deletions.
1 change: 1 addition & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,6 @@ lazy val root = (project in file("."))
"org.slf4j" % "slf4j-simple" % "1.7.36",
"org.scalatest" %% "scalatest" % "3.2.15" % Test,
"org.scalamock" %% "scalamock" % "5.2.0" % Test,
"com.h2database" % "h2" % "2.2.224" % Test
)
)
13 changes: 12 additions & 1 deletion src/test/resources/db-test.conf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
slick {
slick-mariadb {
connectionPool = "HikariCP"
numThreads = 25
url = "jdbc:mariadb://localhost:3306/metastore"
Expand All @@ -8,4 +8,15 @@ slick {
password = "jobjob@3"
}
keepAliveConnection = true
}

slick-h2 {
connectionPool = "HikariCP"
numThreads = 25
url = "jdbc:h2:mem"
properties = {
user = ""
password = ""
}
keepAliveConnection = true
}
42 changes: 3 additions & 39 deletions src/test/scala/io/dockovpn/metastore/store/DBStoreSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@ import org.scalatest.BeforeAndAfter
import org.scalatest.concurrent.ScalaFutures
import org.scalatest.matchers.should.Matchers._
import org.scalatest.wordspec.AnyWordSpec
import slick.jdbc.MySQLProfile.api._

import java.sql.Timestamp
import java.time.Instant
import scala.concurrent.Await
import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.duration.DurationInt
import scala.concurrent.{Await, Future}

class DBStoreSpec extends AnyWordSpec
with ScalaFutures
Expand All @@ -23,45 +22,10 @@ class DBStoreSpec extends AnyWordSpec
private val baseInstant = Instant.parse("2023-12-18T21:22:34Z")

before {
val f = Future.sequence(List(
dbRef.run {
sql"""TRUNCATE TABLE int_records
|""".stripMargin.as[Unit]
},
dbRef.run {
sql"""TRUNCATE TABLE long_records
|""".stripMargin.as[Unit]
},
dbRef.run {
sql"""TRUNCATE TABLE string_records
|""".stripMargin.as[Unit]
},
dbRef.run {
sql"""TRUNCATE TABLE timestamp_records
|""".stripMargin.as[Unit]
},
dbRef.run {
sql"""TRUNCATE TABLE opt_int_records
|""".stripMargin.as[Unit]
},
dbRef.run {
sql"""TRUNCATE TABLE opt_long_records
|""".stripMargin.as[Unit]
},
dbRef.run {
sql"""TRUNCATE TABLE opt_string_records
|""".stripMargin.as[Unit]
},
dbRef.run {
sql"""TRUNCATE TABLE opt_timestamp_records
|""".stripMargin.as[Unit]
},
))

Await.ready(f, 10.seconds)
Await.ready(Queries.cleanTables(), 10.seconds)
}

"DBStore" must {
"DBStore" ignore {
"put value successfully" when {
"value is IntRecord" in {
val testStore: AbstractStore[IntRecord] = StoreProvider.getStoreByType(dbStoreType)
Expand Down
115 changes: 113 additions & 2 deletions src/test/scala/io/dockovpn/metastore/store/TestData.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@ import slick.jdbc.GetResult

import java.sql.Timestamp
import scala.reflect.ClassTag

import slick.jdbc.MySQLProfile.api._

import scala.concurrent.ExecutionContext.Implicits.global

import scala.concurrent.Future

object TestData {

case class IntRecord(id: String, value: Int)
Expand Down Expand Up @@ -115,5 +118,113 @@ object TestData {

private val cfg = ConfigFactory.load("db-test.conf")

implicit val dbRef: DBRef = lazily { Database.forConfig("slick", cfg) }
implicit val dbRef: DBRef = lazily { Database.forConfig("slick-mariadb", cfg) }

object Queries {
def initDB(): Future[Unit] = {
Future.sequence(List(
dbRef.run {
sql"""CREATE TABLE `int_records` (
| `id` varchar(100) NOT NULL,
| `value` int(11) NOT NULL,
| PRIMARY KEY (`id`)
|) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
|""".stripMargin.as[Unit]
},
dbRef.run {
sql"""CREATE TABLE `long_records` (
| `id` varchar(100) NOT NULL,
| `value` bigint(20) NOT NULL,
| PRIMARY KEY (`id`)
|) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
|""".stripMargin.as[Unit]
},
dbRef.run {
sql"""CREATE TABLE `string_records` (
| `id` varchar(100) NOT NULL,
| `value` varchar(100) NOT NULL,
| PRIMARY KEY (`id`)
|) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
|""".stripMargin.as[Unit]
},
dbRef.run {
sql"""CREATE TABLE `timestamp_records` (
| `id` varchar(100) NOT NULL,
| `value` timestamp NOT NULL,
| PRIMARY KEY (`id`)
|) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
|""".stripMargin.as[Unit]
},
dbRef.run {
sql"""CREATE TABLE `opt_int_records` (
| `id` varchar(100) NOT NULL,
| `value` int(11) DEFAULT NULL,
| PRIMARY KEY (`id`)
|) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
|""".stripMargin.as[Unit]
},
dbRef.run {
sql"""CREATE TABLE `opt_long_records` (
| `id` varchar(100) NOT NULL,
| `value` bigint(20) DEFAULT NULL,
| PRIMARY KEY (`id`)
|) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
|""".stripMargin.as[Unit]
},
dbRef.run {
sql"""CREATE TABLE `opt_string_records` (
| `id` varchar(100) NOT NULL,
| `value` varchar(100) DEFAULT NULL,
| PRIMARY KEY (`id`)
|) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
|""".stripMargin.as[Unit]
},
dbRef.run {
sql"""CREATE TABLE `opt_timestamp_records` (
| `id` varchar(100) NOT NULL,
| `value` timestamp NULL DEFAULT NULL,
| PRIMARY KEY (`id`)
|) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
|""".stripMargin.as[Unit]
},
)).map(_ => ())
}

def cleanTables(): Future[Unit] = {
Future.sequence(List(
dbRef.run {
sql"""TRUNCATE TABLE int_records
|""".stripMargin.as[Unit]
},
dbRef.run {
sql"""TRUNCATE TABLE long_records
|""".stripMargin.as[Unit]
},
dbRef.run {
sql"""TRUNCATE TABLE string_records
|""".stripMargin.as[Unit]
},
dbRef.run {
sql"""TRUNCATE TABLE timestamp_records
|""".stripMargin.as[Unit]
},
dbRef.run {
sql"""TRUNCATE TABLE opt_int_records
|""".stripMargin.as[Unit]
},
dbRef.run {
sql"""TRUNCATE TABLE opt_long_records
|""".stripMargin.as[Unit]
},
dbRef.run {
sql"""TRUNCATE TABLE opt_string_records
|""".stripMargin.as[Unit]
},
dbRef.run {
sql"""TRUNCATE TABLE opt_timestamp_records
|""".stripMargin.as[Unit]
},
)).map(_ => ())
}
}
}

0 comments on commit 086e4fd

Please sign in to comment.