Navigation Menu

Skip to content

Commit

Permalink
Changes related to GC-463
Browse files Browse the repository at this point in the history
  - all test (including integration) are now running by default with H2 in memory
  - travis has been configured to run all test in postgres by passing url and driver as a argument property of the SBT command.
  - simplified the DatabaseConfigWrapper, just a little.
  • Loading branch information
jpocalan-collective committed Jul 28, 2015
1 parent 399fe20 commit 333f35a
Show file tree
Hide file tree
Showing 16 changed files with 39 additions and 72 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Expand Up @@ -17,7 +17,7 @@ jdk:
- oraclejdk8

script:
- sbt ++$TRAVIS_SCALA_VERSION -J-Xmx2512m clean test it:test
- sbt ++$TRAVIS_SCALA_VERSION -J-Xmx2512m -Dmodelmatrix.catalog.db.url="jdbc:postgresql://localhost/modelmatrix?user=modelmatrix&password=modelmatrix" -Dmodelmatrix.catalog.db.driver="org.postgresql.Driver" clean test it:test

# Tricks to avoid unnecessary cache updates
- find $HOME/.sbt -name "*.lock" | xargs rm
Expand Down
13 changes: 3 additions & 10 deletions modelmatrix-core/src/it/resources/database_it.conf
Expand Up @@ -4,16 +4,9 @@

modelmatrix {
catalog.db {
h2 {
url = "jdbc:h2:mem:modelmatrix;DATABASE_TO_UPPER=FALSE"
driver = org.h2.Driver
keepAliveConnection = true
}
pg {
url = "jdbc:postgresql://localhost/modelmatrix?user=modelmatrix&password=modelmatrix"
driver = org.postgresql.Driver
keepAliveConnection = truee
}
url = "jdbc:h2:mem:modelmatrix;DATABASE_TO_UPPER=FALSE"
driver = org.h2.Driver
keepAliveConnection = true
}
}

2 changes: 1 addition & 1 deletion modelmatrix-core/src/it/resources/pg.conf
@@ -1,5 +1,5 @@
pgdev = {
url = "jdbc:postgresql://localhost/modelmatrix?user=modelmatrix&password=modelmatrix"
url = "jdbc:postgresql://localhost/modelmatrix?user=modelmatrix&password=modelmatrix"
driver = org.postgresql.Driver
keepAliveConnection = true
}

This file was deleted.

This file was deleted.

@@ -0,0 +1,5 @@
package com.collective.modelmatrix.catalog

class ModelDefinitionCatalogSpecIT extends ModelDefinitionCatalogSpec with ITDatabase with InstallSchemaBefore


@@ -0,0 +1,6 @@
package com.collective.modelmatrix.catalog


class ModelInstanceCatalogSpecIT extends ModelInstanceCatalogSpec with ITDatabase with InstallSchemaBefore


This file was deleted.

This file was deleted.

Expand Up @@ -16,15 +16,15 @@ class DatabaseConfig(n: String, dc: String, sd: JdbcProfile) {

// database configuration wrapper class that read the configuration files and
// determines the proper slick driver to use
case class DatabaseConfigWrapper(configPath: String = "modelmatrix.catalog.db", configFilePath: String = "") {
case class DatabaseConfigWrapper(configFilePath: String = "") {
val PG = new DatabaseConfig("pg", "org.postgresql.Driver", PostgresDriver)
val H2 = new DatabaseConfig("h2", "org.h2.Driver", H2Driver)
lazy val currentDB: DatabaseConfig = getCurrentDB

val dbConfigPath: String = configPath
val dbConfigPath: String = "modelmatrix.catalog.db"
lazy val dbConfig: Config =
if (configFilePath.isEmpty) ConfigFactory.load().getConfig(dbConfigPath)
else ConfigFactory.load(configFilePath).getConfig(dbConfigPath)
else ConfigFactory.systemProperties().withFallback(ConfigFactory.load(configFilePath)).getConfig(dbConfigPath)

// do not need to expose this as user have access to the current db config using attribute currentDB
private def getCurrentDB = {
Expand Down
13 changes: 3 additions & 10 deletions modelmatrix-core/src/test/resources/database_test.conf
Expand Up @@ -4,16 +4,9 @@

modelmatrix {
catalog.db {
h2 {
url = "jdbc:h2:mem:modelmatrix;DATABASE_TO_UPPER=FALSE"
driver = org.h2.Driver
keepAliveConnection = true
}
pg {
url = "jdbc:postgresql://localhost/modelmatrix?user=modelmatrix&password=modelmatrix"
driver = org.postgresql.Driver
keepAliveConnection = truee
}
url = "jdbc:h2:mem:modelmatrix;DATABASE_TO_UPPER=FALSE"
driver = org.h2.Driver
keepAliveConnection = true
}
}

Expand Up @@ -6,7 +6,7 @@ import com.collective.modelmatrix.ModelFeature
import com.collective.modelmatrix.transform.{Bins, Identity, Index, Top}
import org.scalatest.{BeforeAndAfterAll, FlatSpec, GivenWhenThen}

class H2ModelDefinitionCatalogSpec extends ModelDefinitionCatalogSpec with H2Database with InstallSchemaBefore
class ModelDefinitionCatalogSpecTest extends ModelDefinitionCatalogSpec with TestDatabase with InstallSchemaBefore

trait ModelDefinitionCatalogSpec extends FlatSpec with GivenWhenThen with BeforeAndAfterAll with CatalogDatabase {

Expand Down
Expand Up @@ -8,7 +8,7 @@ import org.apache.spark.sql.types.{DoubleType, IntegerType, StringType}
import org.scalatest.{BeforeAndAfterAll, FlatSpec, GivenWhenThen}


class H2ModelInstanceCatalogSpec extends ModelInstanceCatalogSpec with H2Database with InstallSchemaBefore
class ModelInstanceCatalogSpecTest extends ModelInstanceCatalogSpec with TestDatabase with InstallSchemaBefore


trait ModelInstanceCatalogSpec extends FlatSpec with GivenWhenThen with BeforeAndAfterAll with CatalogDatabase {
Expand Down

This file was deleted.

Expand Up @@ -3,23 +3,23 @@ package com.collective.modelmatrix.catalog
import com.collective.modelmatrix.db.DatabaseConfigWrapper
import org.scalatest.{BeforeAndAfterAll, FlatSpec}

trait H2Database extends CatalogDatabase {
trait ITDatabase extends CatalogDatabase {
self: FlatSpec with BeforeAndAfterAll =>

val dbConfigWrapper: DatabaseConfigWrapper = H2ConfigWrapper
val dbConfigWrapper: DatabaseConfigWrapper = ITConfigWrapper
val driver = dbConfigWrapper.getSlickDriver
override val db = dbConfigWrapper.getDatabase
}

trait H2DatabaseIT extends CatalogDatabase {
trait TestDatabase extends CatalogDatabase {
self: FlatSpec with BeforeAndAfterAll =>

val dbConfigWrapper: DatabaseConfigWrapper = H2ConfigWrapperIT
val dbConfigWrapper: DatabaseConfigWrapper = TestConfigWrapper
val driver = dbConfigWrapper.getSlickDriver
override val db = dbConfigWrapper.getDatabase
}

object H2ConfigWrapperIT extends DatabaseConfigWrapper("modelmatrix.catalog.db.h2", "./database_it.conf")
object H2ConfigWrapper extends DatabaseConfigWrapper("modelmatrix.catalog.db.h2", "./database_test.conf")
object ITConfigWrapper extends DatabaseConfigWrapper("./database_it.conf")
object TestConfigWrapper extends DatabaseConfigWrapper("./database_test.conf")


9 changes: 9 additions & 0 deletions project/TestSettings.scala
Expand Up @@ -15,8 +15,13 @@ object TestSettings {
// Run Scalastyle as a part of tests
checkScalastyle := ScalastylePlugin.scalastyle.in(Compile).toTask("").value,
test in Test <<= (test in Test) dependsOn checkScalastyle,

// Disable logging in all tests
javaOptions in Test += "-Dlog4j.configuration=log4j-turned-off.properties",

// Read extra properties passed as argument to sbt
javaOptions in Test ++= sys.props.map(pair => "-D"+pair._1+"="+pair._2).toSeq,

// Generate JUnit test reports
testOptions in Test <+= (target in Test) map {
t => Tests.Argument(TestFrameworks.ScalaTest, "-u", (t / "test-reports").toString)
Expand All @@ -30,6 +35,10 @@ object TestSettings {
test in IntegrationTest <<= (test in IntegrationTest) dependsOn checkScalastyle,
// Disable logging in all tests
javaOptions in IntegrationTest += "-Dlog4j.configuration=log4j-turned-off.properties",

// Read extra properties passed as argument to sbt
javaOptions in Test ++= sys.props.map(pair => "-D"+pair._1+"="+pair._2).toSeq,

// Generate JUnit test reports
testOptions in IntegrationTest <+= (target in IntegrationTest) map {
t => Tests.Argument(TestFrameworks.ScalaTest, "-u", (t / "test-reports").toString)
Expand Down

0 comments on commit 333f35a

Please sign in to comment.