Skip to content
This repository has been archived by the owner on Apr 15, 2018. It is now read-only.

introduce docker-it-scala for etcd tests #155

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,3 @@ sudo: required

services:
- docker

before_install:
- docker run
--detach
--publish 2379:2379
quay.io/coreos/etcd:v2.3.7
--listen-client-urls http://0.0.0.0:2379
--advertise-client-urls http://127.0.0.1:2379
53 changes: 31 additions & 22 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ lazy val core =
project
.enablePlugins(AutomateHeaderPlugin)
.configs(MultiJvm)
.dependsOn(coordination,`coordination-etcd` % "test->compile")
.dependsOn(coordination,`coordination-etcd` % "test->test")
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's because we use DockerEtcdService also in core. And since DockerEtcdService is defined in coordination-etcd test scope we need this change

.settings(settings)
.settings(multiJvmSettings)
.settings(
Expand All @@ -30,7 +30,9 @@ lazy val core =
library.akkaTestkit % Test,
library.log4jCore % Test,
library.mockitoCore % Test,
library.scalaTest % Test
library.scalaTest % Test,
library.dockerTestKit % Test,
library.dockerTestKitSpotify % Test
)
)

Expand All @@ -55,37 +57,44 @@ lazy val `coordination-etcd` =
libraryDependencies ++= Seq(
library.akkaHttp,
library.circeParser,
library.akkaTestkit % Test,
library.scalaTest % Test
library.akkaTestkit % Test,
library.scalaTest % Test,
library.dockerTestKit % Test,
library.dockerTestKitSpotify % Test
)
)

parallelExecution in Global := false
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem was with inter-submodules concurrency. Usually it is that multi nodes tests are run before EtcdCoordinationSpec's afterAll was called. It is not desired because than creating etcd container fails because one is still running (and has not been stopped yet).

It was the easiest fix for that. I am open for any suggestions.


// *****************************************************************************
// Library dependencies
// *****************************************************************************

lazy val library =
new {
object Version {
final val akka = "2.4.17"
final val akkaHttp = "10.0.3"
final val akkaLog4j = "1.3.0"
final val circe = "0.7.0"
final val log4j = "2.8"
final val mockito = "2.6.8"
final val scalaTest = "3.0.1"
final val akka = "2.4.17"
final val akkaHttp = "10.0.3"
final val akkaLog4j = "1.3.0"
final val circe = "0.7.0"
final val log4j = "2.8"
final val mockito = "2.6.8"
final val scalaTest = "3.0.1"
final val dockerTestKit = "0.9.1"
}
val akkaActor = "com.typesafe.akka" %% "akka-actor" % Version.akka
val akkaCluster = "com.typesafe.akka" %% "akka-cluster" % Version.akka
val akkaHttp = "com.typesafe.akka" %% "akka-http" % Version.akkaHttp
val akkaLog4j = "de.heikoseeberger" %% "akka-log4j" % Version.akkaLog4j
val akkaMultiNodeTestkit = "com.typesafe.akka" %% "akka-multi-node-testkit" % Version.akka
val akkaSlf4j = "com.typesafe.akka" %% "akka-slf4j" % Version.akka
val akkaTestkit = "com.typesafe.akka" %% "akka-testkit" % Version.akka
val circeParser = "io.circe" %% "circe-parser" % Version.circe
val log4jCore = "org.apache.logging.log4j" % "log4j-core" % Version.log4j
val mockitoCore = "org.mockito" % "mockito-core" % Version.mockito
val scalaTest = "org.scalatest" %% "scalatest" % Version.scalaTest
val akkaActor = "com.typesafe.akka" %% "akka-actor" % Version.akka
val akkaCluster = "com.typesafe.akka" %% "akka-cluster" % Version.akka
val akkaHttp = "com.typesafe.akka" %% "akka-http" % Version.akkaHttp
val akkaLog4j = "de.heikoseeberger" %% "akka-log4j" % Version.akkaLog4j
val akkaMultiNodeTestkit = "com.typesafe.akka" %% "akka-multi-node-testkit" % Version.akka
val akkaSlf4j = "com.typesafe.akka" %% "akka-slf4j" % Version.akka
val akkaTestkit = "com.typesafe.akka" %% "akka-testkit" % Version.akka
val circeParser = "io.circe" %% "circe-parser" % Version.circe
val log4jCore = "org.apache.logging.log4j" % "log4j-core" % Version.log4j
val mockitoCore = "org.mockito" % "mockito-core" % Version.mockito
val scalaTest = "org.scalatest" %% "scalatest" % Version.scalaTest
val dockerTestKit = "com.whisk" %% "docker-testkit-scalatest" % Version.dockerTestKit
val dockerTestKitSpotify = "com.whisk" %% "docker-testkit-impl-spotify" % Version.dockerTestKit
}

// *****************************************************************************
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@ import akka.Done
import akka.actor.{ ActorSystem, AddressFromURIString }
import akka.testkit.{ TestDuration, TestProbe }
import com.typesafe.config.ConfigFactory
import com.whisk.docker.impl.spotify.DockerKitSpotify
import com.whisk.docker.scalatest.DockerTestKit
import de.heikoseeberger.constructr.coordination.etcd.utils.DockerEtcdService
import org.scalatest.concurrent.ScalaFutures
import org.scalatest.{ BeforeAndAfterAll, Matchers, WordSpec }

import scala.concurrent.duration.{ Duration, DurationInt, FiniteDuration }
import scala.concurrent.{ Await, Awaitable }
import scala.util.Random
Expand All @@ -39,7 +44,10 @@ object EtcdCoordinationSpec {
class EtcdCoordinationSpec
extends WordSpec
with Matchers
with BeforeAndAfterAll {
with BeforeAndAfterAll
with DockerEtcdService
with DockerTestKit
with DockerKitSpotify {
import EtcdCoordinationSpec._

private implicit val system = {
Expand Down Expand Up @@ -78,7 +86,7 @@ class EtcdCoordinationSpec
}
}

override protected def afterAll() = {
override def afterAll() = {
Await.ready(system.terminate(), Duration.Inf)
super.afterAll()
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright 2015 Heiko Seeberger
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package de.heikoseeberger.constructr.coordination.etcd.utils

import com.whisk.docker.{ DockerContainer, DockerKit, DockerReadyChecker }

trait DockerEtcdService extends DockerKit {
val DefaultEtcdPort = 2379

val etcdContainer = DockerContainer("quay.io/coreos/etcd:v2.3.7")
.withPorts(DefaultEtcdPort -> Some(DefaultEtcdPort))
.withReadyChecker(DockerReadyChecker.LogLineContains(
"setting up the initial cluster version to"))
.withCommand("--listen-client-urls",
"http://0.0.0.0:2379",
"--advertise-client-urls",
"http://0.0.0.0:2379")

abstract override def dockerContainers: List[DockerContainer] =
etcdContainer :: super.dockerContainers
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,14 @@ import akka.stream.ActorMaterializer
import akka.testkit.TestDuration
import akka.util.Timeout
import com.typesafe.config.ConfigFactory
import com.whisk.docker.impl.spotify.DockerKitSpotify
import com.whisk.docker.scalatest.DockerTestKit
import de.heikoseeberger.constructr.coordination.etcd.utils.DockerEtcdService
import org.scalatest.{ BeforeAndAfterAll, FreeSpecLike, Matchers }

import scala.concurrent.Await
import scala.concurrent.duration.DurationInt
import scala.util.Success

object ConstructrMultiNodeConfig {
val coordinationHost = {
Expand Down Expand Up @@ -71,7 +76,9 @@ abstract class MultiNodeConstructrSpec(
) extends MultiNodeSpec(new ConstructrMultiNodeConfig(coordinationPort))
with FreeSpecLike
with Matchers
with BeforeAndAfterAll {
with BeforeAndAfterAll
with DockerEtcdService
with DockerKitSpotify {
import ConstructrMultiNodeConfig._
import RequestBuilding._
import system.dispatcher
Expand All @@ -80,6 +87,8 @@ abstract class MultiNodeConstructrSpec(

"Constructr should manage an Akka cluster" in {
runOn(roles.head) {
startAllOrFail()

within(20.seconds.dilated) {
awaitAssert {
val coordinationStatus =
Expand Down Expand Up @@ -146,16 +155,20 @@ abstract class MultiNodeConstructrSpec(
}

enterBarrier("done")

runOn(roles.head) {
stopAllQuietly()
}
}

override def initialParticipants = roles.size

override protected def beforeAll() = {
override def beforeAll() = {
super.beforeAll()
multiNodeSpecBeforeAll()
}

override protected def afterAll() = {
override def afterAll() = {
multiNodeSpecAfterAll()
super.afterAll()
}
Expand Down