[Atlanta JUG] Testing containers with TestContainers

[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.

0680be1c881abcf19219f09f1e8cf140?s=128

Viktor Gamov

July 18, 2017
Tweet

Transcript

  1. @gamussa @hazelcast @testcontainers Testing containers with testcontainers

  2. @gamussa @hazelcast @testcontainers HELLO!

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

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

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

    here because I love to give presentations. You can find me in internetz @gamussa
  6. @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
  7. @gamussa @hazelcast @testcontainers Disclaimer:
 
 I build highly


  8. @gamussa @hazelcast @testcontainers A quick roadmap of today’s journey

  9. None
  10. @gamussa @hazelcast @testcontainers Development How Docker helps Java developers

  11. None
  12. @gamussa @hazelcast @testcontainers Let’s start with why?

  13. @gamussa @hazelcast @testcontainers The Promise

  14. @gamussa @hazelcast @testcontainers

  15. @gamussa @hazelcast @testcontainers

  16. @gamussa @hazelcast @testcontainers Which image?

  17. @gamussa @hazelcast @testcontainers Which image? • java

  18. @gamussa @hazelcast @testcontainers Which image? • java • openjdk /

    openjdk-alpine
  19. @gamussa @hazelcast @testcontainers Which image? • java • openjdk /

    openjdk-alpine • Oracle Container Repo
  20. @gamussa @hazelcast @testcontainers Which image? • java • openjdk /

    openjdk-alpine • Oracle Container Repo • Custom Repository • ECS repo • Docker EE • Artifactory
  21. @gamussa @hazelcast @testcontainers How?

  22. @gamussa @hazelcast @testcontainers How? Designated images per set of tasks

  23. @gamussa @hazelcast @testcontainers How? Designated images per set of tasks

    jdk image for builds
  24. @gamussa @hazelcast @testcontainers How? Designated images per set of tasks

    jdk image for builds jre image for runtime
  25. @gamussa @hazelcast @testcontainers How? Designated images per set of tasks

    jdk image for builds jre image for runtime Debug?
  26. @gamussa @hazelcast @testcontainers Tooling Automation for image creation

  27. @gamussa @hazelcast @testcontainers Maven <groupId>com.spotify</groupId> <artifactId>docker-maven-plugin</artifactId> <version>${docker-maven-plugin.version}</version>

  28. @gamussa @hazelcast @testcontainers Maven

  29. @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/' } }
  30. @gamussa @hazelcast @testcontainers Gradle

  31. @gamussa @hazelcast @testcontainers Multi-container application on the single host

  32. @gamussa @hazelcast @testcontainers Why compose? Why I can’t do all

    in one image? Script file to run them all?
  33. Images are like onions Images have layers

  34. @gamussa @hazelcast @testcontainers Production How Docker help to be in

    production
  35. None
  36. @gamussa @hazelcast @testcontainers Production check list

  37. @gamussa @hazelcast @testcontainers Production check list Reproducible environment

  38. @gamussa @hazelcast @testcontainers Production check list Reproducible environment Deployment of

    complex stacks without complicated scripts
  39. @gamussa @hazelcast @testcontainers Production check list Reproducible environment Deployment of

    complex stacks without complicated scripts High Availability
  40. @gamussa @hazelcast @testcontainers Production check list Reproducible environment Deployment of

    complex stacks without complicated scripts High Availability Monitoring
  41. @gamussa @hazelcast @testcontainers Monitoring

  42. @gamussa @hazelcast @testcontainers Monitoring docker stats

  43. @gamussa @hazelcast @testcontainers Monitoring docker stats Docker remote API

  44. @gamussa @hazelcast @testcontainers Monitoring docker stats Docker remote API docker

    service logs <service>
  45. @gamussa @hazelcast @testcontainers Monitoring docker stats Docker remote API docker

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

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

    service logs <service> Prometheus endpoint (since 1.13) cAdvisor ELK stack
  48. @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
  49. @gamussa @hazelcast @testcontainers One more thing…

  50. @gamussa @hazelcast @testcontainers

  51. @gamussa @hazelcast @testcontainers

  52. @gamussa @hazelcast @testcontainers

  53. @gamussa @hazelcast @testcontainers

  54. @gamussa @hazelcast @testcontainers Integration Testing How Docker helps easy transition

    from Development to Production
  55. None
  56. @gamussa @hazelcast @testcontainers Verify how software product will behave in

    real-world conditions Why?
  57. @gamussa @hazelcast @testcontainers Pros and cons

  58. @gamussa @hazelcast @testcontainers Pros and cons ✓ Real-world isolated testing

  59. @gamussa @hazelcast @testcontainers Pros and cons ✓ Real-world isolated testing

    ✓ Can be run during development
  60. @gamussa @hazelcast @testcontainers Pros and cons ✓ Real-world isolated testing

    ✓ Can be run during development ✓ Spot the issues before they apear in prod
  61. @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
  62. @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
  63. @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
  64. @gamussa @hazelcast @testcontainers Solution – Docker!

  65. @gamussa @hazelcast @testcontainers Solution – Docker! Abstraction layer

  66. @gamussa @hazelcast @testcontainers Solution – Docker! Abstraction layer CI friendly

  67. @gamussa @hazelcast @testcontainers Solution – Docker! Abstraction layer CI friendly

    Cross-platform
  68. @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
  69. @gamussa @hazelcast @testcontainers But…

  70. @gamussa @hazelcast @testcontainers But… No port randomization

  71. @gamussa @hazelcast @testcontainers But… No port randomization Fighting with docker

    env
  72. @gamussa @hazelcast @testcontainers But… No port randomization Fighting with docker

    env localhost?
  73. None
  74. Remove the database

  75. @gamussa @hazelcast @testcontainers

  76. @gamussa @hazelcast @testcontainers Demo

  77. @gamussa @hazelcast @testcontainers What to expect

  78. @gamussa @hazelcast @testcontainers What to expect More testing frameworks support

  79. @gamussa @hazelcast @testcontainers What to expect More testing frameworks support

    Chaos Testing via Pumba
  80. @gamussa @hazelcast @testcontainers What to expect More testing frameworks support

    Chaos Testing via Pumba Integration / Merge with Arquillian Cube
  81. None
  82. DEVELOPMENT AND DEPLOYMENT WITH CLASSIC TOOLS

  83. DEVELOPMENT AND DEPLOYMENT WITH CLASSIC TOOLS EXPLORE 
 THE
 WORLD

    OF CONTAINERS
  84. @gamussa @hazelcast @testcontainers Thanks! QA? @gamussa http:/ /gamov.io