Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Testing with Docker

Testing with Docker

Presented at Warsaw Scala Enthusiasts meetup

Maciej Biłas

November 18, 2015
Tweet

More Decks by Maciej Biłas

Other Decks in Programming

Transcript

  1. TESTING WITH DOCKER WHO AM I ▸ Software engineer at

    Adform Research ▸ ~10 years of JVM programming ▸ ~3 years commercial experience with Scala (+2 as hobby language) @maciejb Speaker Deck: maciejb /maciej
  2. TESTING WITH DOCKER WHAT IS DOCKER? Docker containers wrap up

    a piece of software in a complete filesystem that contains everything it needs to run: code, runtime, system tools, system libraries – anything you can install on a server. This guarantees that it will always run the same, regardless of the environment it is running in. docker.com
  3. TESTING WITH DOCKER CONTAINERS > docker run mongo:latest 2015-11-01T21:43:08.287+0000 I

    JOURNAL [initandlisten] journal dir=/data/db/ journal 2015-11-01T21:43:08.288+0000 I JOURNAL [initandlisten] recover : no journal files present, no recovery needed 2015-11-01T21:43:08.337+0000 I JOURNAL [durability] Durability thread started …
  4. TESTING WITH DOCKER APPROACHES ▸ Writing a long “Testing setup”

    chapter in project’s README ▸ VMs, Vagrant ▸ Running docker outside of the build (+ Docker Compose) ▸ SBT: testOptions in Test += Tests.Setup( () => ??? ) ▸ Testing against an environment ▸ Running Docker from ScalaTest
  5. TESTING WITH DOCKER REDIS TESTKIT "DockerRedisService" should "start a usable

    Redis server" in {
 val fut = redisExec { redis =>
 redis.set("foo", "bar") flatMap { _ =>
 redis.get[String]("foo")
 }
 }
 
 whenReady(fut) { resultOpt =>
 resultOpt shouldEqual Some("bar")
 }
 }

  6. TESTING WITH DOCKER REDIS CONTAINER STARTUP TIME ▸ Native startup

    time.
 Mean 10.739ms, median: 11.131ms, stdev: 1.006ms. ▸ Docker startup time.
 Mean 262.751ms, median: 277.653ms, stdev: 29.649ms. Poor man’s benchmark [gist].
 15 runs, 5 discarded, assuming normal distribution. Late 2013 15’ MBP, Intel(R) Core(TM) i7-4960HQ CPU @ 2.60GHz, 16GiB
 Docker 1.8.3 in docker-machine running VirtualBox 4.3.32
  7. TESTING WITH DOCKER CASSANDRA STARTUP TIME ▸ Cassandra startup time.


    Mean 6435.166ms,
 median: 6427.594ms,
 stdev: 176.389ms. Using spotify/cassandra:latest image
  8. TESTING WITH DOCKER REDIS TESTKIT trait DockerRedisService extends DockerKit {

    val DefaultRedisPort = 6379
 
 val redisContainer = DockerContainer("redis:3.0.5")
 .withPorts(DefaultRedisPort -> None)
 .withReadyChecker( DockerReadyChecker.LogLineContains("* The server is now ready to accept connections”) )
 abstract override def dockerContainers: List[DockerContainer] = redisContainer :: super.dockerContainers
 }
  9. TESTING WITH DOCKER CHAIN SERVICES class MySpec extends FlatSpec with

    DockerElasticsearchService 
 with DockerCassandraService with DockerNeo4jService with DockerMongodbService
  10. TESTING WITH DOCKER FAKE-S3 implicit lazy val s3Client = {


    val clientFut = fakeS3PortFut map { port =>
 val c = new AmazonS3Client(new BasicAWSCredentials("fake", "fake"))
 c.setEndpoint(s"http://${docker.host}:$port")
 c.setS3ClientOptions(new S3ClientOptions().withPathStyleAccess(true))
 c
 }
 
 Await.result(clientFut, 30.seconds)
 }
  11. TESTING WITH DOCKER RESOURCES ▸ docker-it-scala ▸ Integration Testing with

    Docker and Scala ▸ Container startup benchmark IPython notebook ▸ etaty/rediscala ▸ jubos/fake-s3