Skip to content

Commit

Permalink
Merge pull request #50 from karolchmist/test-fixing
Browse files Browse the repository at this point in the history
Fix tests for scala 2.13
  • Loading branch information
lastland authored Apr 24, 2020
2 parents fbb0b90 + 3ec6414 commit cfed58d
Show file tree
Hide file tree
Showing 12 changed files with 284 additions and 114 deletions.
58 changes: 58 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
version: 2
jobs:
build:
working_directory: ~/scala-forklift
docker:
- image: circleci/openjdk:8
- image: circleci/mysql:5.7.29
environment:
MYSQL_DATABASE: circle_test
MYSQL_USER: root
MYSQL_ALLOW_EMPTY_PASSWORD: true
- image: circleci/postgres:9.6.9
environment:
POSTGRES_USER: circleci
POSTGRES_DB: circle_test
environment:
SBT_VERSION: 1.3.7
steps:
- run: echo 'export ARTIFACT_BUILD=$CIRCLE_PROJECT_REPONAME-$CIRCLE_BUILD_NUM.zip' >> $BASH_ENV
- run:
name: Get sbt binary
command: |
apt update && apt install -y curl
curl -L -o sbt-$SBT_VERSION.deb https://dl.bintray.com/sbt/debian/sbt-$SBT_VERSION.deb
sudo dpkg -i sbt-$SBT_VERSION.deb
rm sbt-$SBT_VERSION.deb
sudo apt-get update
sudo apt-get install -y sbt python-pip git
pip install awscli
sudo apt-get clean && sudo apt-get autoclean
- checkout
- restore_cache:
# Read about caching dependencies: https://circleci.com/docs/2.0/caching/
key: sbt-cache
- run:
name: Crossompile scala-forklift
command: sbt +compile
- run:
name: Compile tests
command: |
sbt +test:compile
sbt +publishLocal
- run:
name: Test scala-forklift scala 2.12
command: sbt '++ 2.12.11; test:test'
environment:
JAVA_OPTS: "-Xms256m -Xmx512m"
- run:
name: Test scala-forklift scala 2.13
command: sbt '++ 2.13.1; test:test'
environment:
JAVA_OPTS: "-Xms256m -Xmx512m"
- save_cache:
key: sbt-cache
paths:
- "~/.ivy2/cache"
- "~/.sbt"
- "~/.m2"
44 changes: 28 additions & 16 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@ val repoKind = SettingKey[String]("repo-kind",

lazy val slickVersion = "3.3.2"

def coreDependencies(scalaVersion: String) = List(
"org.scala-lang" % "scala-compiler" % scalaVersion,
lazy val scala212 = "2.12.11"
lazy val scala213 = "2.13.1"
lazy val supportedScalaVersions = List(scala212, scala213)

lazy val coreDependencies = libraryDependencies ++= List(
"org.scala-lang" % "scala-compiler" % scalaVersion.value,
"com.typesafe" % "config" % "1.3.0",
"org.eclipse.jgit" % "org.eclipse.jgit" % "4.0.1.201506240215-r"
)
Expand All @@ -21,22 +25,23 @@ lazy val slickDependenciesWithTests = slickDependencies ++ List(
"commons-io" % "commons-io" % "2.6",
"com.typesafe.slick" %% "slick-hikaricp" % slickVersion,
"com.h2database" % "h2" % "1.4.200",
"org.xerial" % "sqlite-jdbc" % "3.30.1",
"mysql" % "mysql-connector-java" % "8.0.18",
"org.xerial" % "sqlite-jdbc" % "3.8.11.2",// 3.30.1 crashes SQLiteCommandTests
"mysql" % "mysql-connector-java" % "5.1.38",
"org.postgresql" % "postgresql" % "42.2.9",
"org.hsqldb" % "hsqldb" % "2.5.0",
"org.apache.derby" % "derby" % "10.15.1.3"
"org.apache.derby" % "derby" % "10.14.2.0",
"ch.qos.logback" % "logback-classic" % "1.2.3"
).map(_ % "test")

lazy val commonSettings = Seq(
organization := "com.liyaos",
licenses := Seq("Apache 2.0" ->
url("https://github.com/lastland/scala-forklift/blob/master/LICENSE")),
homepage := Some(url("https://github.com/lastland/scala-forklift")),
scalaVersion := "2.13.1",
scalaVersion := scala213,
scalacOptions += "-deprecation",
scalacOptions += "-feature",
resolvers += Resolver.bintrayRepo("naftoligug", "maven"),
resolvers += Resolver.jcenterRepo,
publishMavenStyle := true,
publishArtifact in Test := false,
repoKind := { if (version.value.trim.endsWith("SNAPSHOT")) "snapshots"
Expand All @@ -60,28 +65,35 @@ lazy val commonSettings = Seq(
</developer>
</developers>))

// Derby is running is secured mode since version 10.12.1.1, so security manager must be disabled for tests
// https://stackoverflow.com/questions/48008343/sbt-test-does-not-work-for-spark-test
// https://issues.apache.org/jira/browse/DERBY-6648
Test / testOptions += Tests.Setup(() => System.setSecurityManager(null))

lazy val root = Project(
"scala-forklift", file(".")).settings(
crossScalaVersions := Seq("2.13.1", "2.12.1"),
crossScalaVersions := Nil,
publishArtifact := false).aggregate(
coreProject, slickMigrationProject, plainMigrationProject, gitToolProject)

lazy val coreProject = Project(
"scala-forklift-core", file("core")).settings(
commonSettings:_*).settings {
libraryDependencies ++= coreDependencies(scalaVersion.value)
}
commonSettings:_*).settings {Seq(
crossScalaVersions := supportedScalaVersions,
coreDependencies
)}

lazy val slickMigrationProject = Project(
"scala-forklift-slick", file("migrations/slick")).dependsOn(
coreProject).settings(commonSettings:_*).settings {
libraryDependencies ++= slickDependenciesWithTests
}
coreProject).settings(commonSettings:_*).settings { Seq(
crossScalaVersions := supportedScalaVersions,
libraryDependencies ++= slickDependenciesWithTests
)}

lazy val plainMigrationProject = Project(
"scala-forklift-plain", file("migrations/plain")).dependsOn(
coreProject).settings(commonSettings:_*)
coreProject).settings(commonSettings:_*).settings(crossScalaVersions := supportedScalaVersions)

lazy val gitToolProject = Project(
"scala-forklift-git-tools", file("tools/git")).dependsOn(
coreProject).settings(commonSettings:_*)
coreProject).settings(commonSettings:_*).settings(crossScalaVersions := supportedScalaVersions)
2 changes: 1 addition & 1 deletion core/src/main/scala/Commands.scala
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ trait MigrationFilesHandler[T] {
toMove.toStream
}

def handleMigrationFile(file: File, cflag: Boolean) {
def handleMigrationFile(file: File, cflag: Boolean) : Unit = {
val target = new File(handledLoc + "/" + file.getName)
val source = new File(unhandledLoc + "/" + file.getName).getAbsoluteFile.toPath
if (!target.exists) {
Expand Down
10 changes: 6 additions & 4 deletions example/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,19 @@ addCommandAlias("mgm", "migration_manager/run")
addCommandAlias("mg", "migrations/run")


lazy val slickVersion = "3.2.1"
lazy val slickVersion = "3.3.2"

lazy val forkliftVersion = "0.3.2-SNAPSHOT"

lazy val commonSettings = Seq(
organization := "com.liyaos",
version := "2.0",
scalaVersion := "2.12.1",
scalaVersion := "2.13.1",
scalacOptions += "-deprecation",
scalacOptions += "-feature",
resolvers += Resolver.sonatypeRepo("snapshots")
resolvers += Resolver.sonatypeRepo("snapshots"),
resolvers += Resolver.jcenterRepo,

)

lazy val loggingDependencies = List(
Expand All @@ -28,7 +30,7 @@ lazy val slickDependencies = List(

lazy val dbDependencies = List(
"com.typesafe.slick" %% "slick-hikaricp" % slickVersion
,"com.h2database" % "h2" % "1.4.192"
,"com.h2database" % "h2" % "1.4.200"
)

lazy val forkliftDependencies = List(
Expand Down
2 changes: 1 addition & 1 deletion example/project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version=0.13.13
sbt.version=1.3.7
36 changes: 18 additions & 18 deletions migrations/slick/src/main/scala/Commands.scala
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ trait SlickMigrationFilesHandler extends MigrationFilesHandler[Int] {
trait SlickRescueCommands extends RescueCommands[Int] with SlickMigrationFilesHandler {
this: SlickCodegen =>

private def deleteRecursively(f: File) {
private def deleteRecursively(f: File) : Unit = {
if (f.isDirectory) {
for {
files <- Option(f.listFiles)
Expand All @@ -64,7 +64,7 @@ trait SlickRescueCommands extends RescueCommands[Int] with SlickMigrationFilesHa
f.delete
}

override def rescueCommand {
override def rescueCommand : Unit = {
super.rescueCommand
deleteRecursively(new File(generatedDir))
}
Expand All @@ -84,7 +84,7 @@ trait SlickMigrationCommands

override def applyOps: Seq[() => Unit] = List(() => applyOp, () => codegenOp)

override def statusOp {
override def statusOp : Unit = {
val mf = migrationFiles(alreadyAppliedIds)
if (!mf.isEmpty) {
println("you still have unhandled migrations")
Expand All @@ -103,15 +103,15 @@ trait SlickMigrationCommands
}
}

override def statusCommand {
override def statusCommand : Unit = {
try {
super.statusCommand
} finally {
db.close()
}
}

override def previewOp {
override def previewOp : Unit = {
println("-" * 80)
println("NOT YET APPLIED MIGRATIONS PREVIEW:")
println("")
Expand All @@ -135,64 +135,64 @@ trait SlickMigrationCommands
println("-" * 80)
}

override def previewCommand {
override def previewCommand : Unit = {
try {
super.previewCommand
} finally {
db.close()
}
}

override def applyOp {
override def applyOp : Unit = {
val ids = notYetAppliedMigrations.map(_.id)
println("applying migrations: " + ids.mkString(", "))
up()
}

override def applyCommand {
override def applyCommand : Unit = {
try {
super.applyCommand
} finally {
db.close()
}
}

override def migrateCommand(options: Seq[String]) {
override def migrateCommand(options: Seq[String]) : Unit = {
try {
super.migrateCommand(options)
} finally {
db.close()
}
}

override def initOp {
override def initOp : Unit = {
super.initOp
init
}

override def initCommand {
override def initCommand : Unit = {
try {
super.initCommand
} finally {
db.close()
}
}

override def resetOp {
override def resetOp : Unit = {
super.resetOp
reset
remove()
}

override def resetCommand {
override def resetCommand : Unit = {
try {
super.resetCommand
} finally {
db.close()
}
}

override def updateCommand(options: Seq[String]) {
override def updateCommand(options: Seq[String]) : Unit = {
try super.updateCommand(options)
finally {
db.close()
Expand All @@ -208,7 +208,7 @@ trait SlickMigrationCommands
// }
// }

def addMigrationOp(tpe: MigrationType, version: Int) {
def addMigrationOp(tpe: MigrationType, version: Int) : Unit = {
val migrationObject = config.getString("migrations.migration_object")
val driverName = dbConfig.profileName
val dbName = driverName.substring("slick.jdbc.".length, driverName.length - "Profile".length)
Expand Down Expand Up @@ -258,7 +258,7 @@ object M${version} {
bw.close()
}

def addMigrationCommand(options: Seq[String]) {
def addMigrationCommand(options: Seq[String]) : Unit = {
val tpe = options.headOption.toTry(CommandExceptions.WrongNumberOfArgumentsException(1, 0)) flatMap {
s =>
MigrationType.getType(s).toTry(CommandExceptions.WrongArgumentException(s))
Expand All @@ -267,11 +267,11 @@ object M${version} {
addMigrationOp(t, nextId)
}

def codegenOp {
def codegenOp : Unit = {
genCode(this)
}

def codegenCommand {
def codegenCommand : Unit = {
try {
codegenOp
} finally {
Expand Down
14 changes: 14 additions & 0 deletions migrations/slick/src/test/resources/logback-test.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>

<!-- <logger name="slick.jdbc.JdbcBackend.statement" level="DEBUG"/>-->
<!-- <logger name="slick.jdbc.JdbcBackend.parameter" level="DEBUG"/>-->

<root level="warn">
<appender-ref ref="STDOUT"/>
</root>
</configuration>
Loading

0 comments on commit cfed58d

Please sign in to comment.