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

[Atlanta JUG] Testing containers with TestConta...

[Atlanta JUG] Testing containers with TestContainers

You never know how your application performs once deployed to the production. Sure, you have unit tests, and your test coverage is sky high. However, you might depend on external resources like databases, web services, and distributed caches. Moreover, without a proper integration testing, you cannot be confident about the stability of your production environment. A long time ago, long before the invention of Docker, configuring the environment for integration testing was incredibly complicated and tedious. Developers and Ops were using fake database
implementations, mocking servers, and all kinds of weird tricks to implement the environment without the real environment, but it was ugly, bulky, faulty and not cross-platform as well. Thanks to Docker, those days are long gone, now we can quickly prepare the environment with Docker for our tests.

In this talk, I would like to spread the word about awesome project TestContainers – an open source library that exposes API for JUnit tests. It provides lightweight, disposable instances of shared databases, distributed caches or grids, or anything else that can run in a Docker container, all securely and reliably downloaded from your Docker Hub.

Viktor Gamov

July 18, 2017
Tweet

More Decks by Viktor Gamov

Other Decks in Programming

Transcript

  1. @gamussa @hazelcast @testcontainers HELLO! I am Viktor Gamov I am

    here because I love to give presentations.
  2. @gamussa @hazelcast @testcontainers HELLO! I am Viktor Gamov I am

    here because I love to give presentations. You can find me in internetz @gamussa
  3. @gamussa @hazelcast @testcontainers HELLO! I am Viktor Gamov I am

    here because I love to give presentations. You can find me in internetz @gamussa Detailed dossier http:/ /gamov.io
  4. @gamussa @hazelcast @testcontainers Which image? • java • openjdk /

    openjdk-alpine • Oracle Container Repo • Custom Repository • ECS repo • Docker EE • Artifactory
  5. @gamussa @hazelcast @testcontainers How? Designated images per set of tasks

    jdk image for builds jre image for runtime Debug?
  6. @gamussa @hazelcast @testcontainers Gradle import org.gradle.internal.os.OperatingSystem task buildDocker(type: Exec) {

    doFirst { copy { from "src/main/docker/" into "build/docker/" include "*" } copy { from "build/libs" into "build/docker/" include "*.war*" } } if (OperatingSystem.current().isWindows()) { commandLine 'cmd', '/c', 'docker', 'image', 'build', '-f', 'build/docker/Dockerfile', '-t', 'myhipsterapp', 'build/docker/' } else { commandLine 'docker', 'image', 'build', '-f', 'build/docker/Dockerfile', '-t', 'myhipsterapp', 'build/docker/' } }
  7. @gamussa @hazelcast @testcontainers Production check list Reproducible environment Deployment of

    complex stacks without complicated scripts High Availability Monitoring
  8. @gamussa @hazelcast @testcontainers Monitoring docker stats Docker remote API docker

    service logs <service> Prometheus endpoint (since 1.13)
  9. @gamussa @hazelcast @testcontainers Monitoring docker stats Docker remote API docker

    service logs <service> Prometheus endpoint (since 1.13) cAdvisor
  10. @gamussa @hazelcast @testcontainers Monitoring docker stats Docker remote API docker

    service logs <service> Prometheus endpoint (since 1.13) cAdvisor ELK stack
  11. @gamussa @hazelcast @testcontainers Monitoring docker stats Docker remote API docker

    service logs <service> Prometheus endpoint (since 1.13) cAdvisor ELK stack Splunk, Sumologic, DataDog, etc
  12. @gamussa @hazelcast @testcontainers Pros and cons ✓ Real-world isolated testing

    ✓ Can be run during development ✓ Spot the issues before they apear in prod
  13. @gamussa @hazelcast @testcontainers Pros and cons ✓ Real-world isolated testing

    ✓ Can be run during development ✓ Spot the issues before they apear in prod ❌ Have to start real databases
  14. @gamussa @hazelcast @testcontainers Pros and cons ✓ Real-world isolated testing

    ✓ Can be run during development ✓ Spot the issues before they apear in prod ❌ Have to start real databases ❌ Should be cross platform
  15. @gamussa @hazelcast @testcontainers Pros and cons ✓ Real-world isolated testing

    ✓ Can be run during development ✓ Spot the issues before they apear in prod ❌ Have to start real databases ❌ Should be cross platform ❌ Slower than unit testing
  16. @gamussa @hazelcast @testcontainers Solution – Docker! Abstraction layer CI friendly

    Cross-platform Docker Compose FTW! services: hazelcast-client: image: hazelcast_client_app volumes: - ../resources:/configFolder environment: - JAVA_OPTS=-Dhazelcast.client.config=/configFolder/hazelcast- client.xml -Dhazelcast.member.address=hazelcast -Dgroup.name=hz- compose -Dgroup.password=s3crEt hazelcast: image: hazelcast/hazelcast volumes: - ../resources:/configFolder environment: - JAVA_OPTS=-Dhazelcast.config=/configFolder/hazelcast.xml - Dhazelcast.mancenter.url=http://mancenter:8080/mancenter - Dgroup.name=hz-compose -Dgroup.password=s3crEt links: - "management-center:mancenter" management-center: image: hazelcast/management-center volumes: - ~/mancenter3.8:/mancenter-3.8 environment: - MANCENTER_DATA=/mancenter-3.8 - JAVA_OPTS=-Dhazelcast.mc.rest.enabled=true ports: - 8080:8080
  17. @gamussa @hazelcast @testcontainers What to expect More testing frameworks support

    Chaos Testing via Pumba Integration / Merge with Arquillian Cube