Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Testing containers with TestContainers @ AJUG 7/18/2017

388 views

Published on

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.

Published in: Software
  • Hi there! Get Your Professional Job-Winning Resume Here - Check our website! http://bit.ly/resumpro
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Be the first to like this

Testing containers with TestContainers @ AJUG 7/18/2017

  1. 1. @gamussa @hazelcast @testcontainers Testing containers with testcontainers
  2. 2. @gamussa @hazelcast @testcontainers HELLO!
  3. 3. @gamussa @hazelcast @testcontainers HELLO! I am Viktor Gamov
  4. 4. @gamussa @hazelcast @testcontainers HELLO! I am Viktor Gamov I am here because I love to give presentations.
  5. 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. 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. 7. @gamussa @hazelcast @testcontainers Disclaimer:
 
 I build highly

  8. 8. @gamussa @hazelcast @testcontainers A quick roadmap of today’s journey
  9. 9. @gamussa @hazelcast @testcontainers Development How Docker helps Java developers
  10. 10. @gamussa @hazelcast @testcontainers Let’s start with why?
  11. 11. @gamussa @hazelcast @testcontainers The Promise
  12. 12. @gamussa @hazelcast @testcontainers
  13. 13. @gamussa @hazelcast @testcontainers
  14. 14. @gamussa @hazelcast @testcontainers Which image?
  15. 15. @gamussa @hazelcast @testcontainers Which image? • java
  16. 16. @gamussa @hazelcast @testcontainers Which image? • java • openjdk / openjdk-alpine
  17. 17. @gamussa @hazelcast @testcontainers Which image? • java • openjdk / openjdk-alpine • Oracle Container Repo
  18. 18. @gamussa @hazelcast @testcontainers Which image? • java • openjdk / openjdk-alpine • Oracle Container Repo • Custom Repository • ECS repo • Docker EE • Artifactory
  19. 19. @gamussa @hazelcast @testcontainers How?
  20. 20. @gamussa @hazelcast @testcontainers How? Designated images per set of tasks
  21. 21. @gamussa @hazelcast @testcontainers How? Designated images per set of tasks jdk image for builds
  22. 22. @gamussa @hazelcast @testcontainers How? Designated images per set of tasks jdk image for builds jre image for runtime
  23. 23. @gamussa @hazelcast @testcontainers How? Designated images per set of tasks jdk image for builds jre image for runtime Debug?
  24. 24. @gamussa @hazelcast @testcontainers Tooling Automation for image creation
  25. 25. @gamussa @hazelcast @testcontainers Maven <groupId>com.spotify</groupId> <artifactId>docker-maven-plugin</artifactId> <version>${docker-maven-plugin.version}</version>
  26. 26. @gamussa @hazelcast @testcontainers Maven
  27. 27. @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/' } }
  28. 28. @gamussa @hazelcast @testcontainers Gradle
  29. 29. @gamussa @hazelcast @testcontainers Multi-container application on the single host
  30. 30. @gamussa @hazelcast @testcontainers Why compose? Why I can’t do all in one image? Script file to run them all?
  31. 31. Images are like onions Images have layers
  32. 32. @gamussa @hazelcast @testcontainers Production How Docker help to be in production
  33. 33. @gamussa @hazelcast @testcontainers Production check list
  34. 34. @gamussa @hazelcast @testcontainers Production check list Reproducible environment
  35. 35. @gamussa @hazelcast @testcontainers Production check list Reproducible environment Deployment of complex stacks without complicated scripts
  36. 36. @gamussa @hazelcast @testcontainers Production check list Reproducible environment Deployment of complex stacks without complicated scripts High Availability
  37. 37. @gamussa @hazelcast @testcontainers Production check list Reproducible environment Deployment of complex stacks without complicated scripts High Availability Monitoring
  38. 38. @gamussa @hazelcast @testcontainers Monitoring
  39. 39. @gamussa @hazelcast @testcontainers Monitoring docker stats
  40. 40. @gamussa @hazelcast @testcontainers Monitoring docker stats Docker remote API
  41. 41. @gamussa @hazelcast @testcontainers Monitoring docker stats Docker remote API docker service logs <service>
  42. 42. @gamussa @hazelcast @testcontainers Monitoring docker stats Docker remote API docker service logs <service> Prometheus endpoint (since 1.13)
  43. 43. @gamussa @hazelcast @testcontainers Monitoring docker stats Docker remote API docker service logs <service> Prometheus endpoint (since 1.13) cAdvisor
  44. 44. @gamussa @hazelcast @testcontainers Monitoring docker stats Docker remote API docker service logs <service> Prometheus endpoint (since 1.13) cAdvisor ELK stack
  45. 45. @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
  46. 46. @gamussa @hazelcast @testcontainers One more thing…
  47. 47. @gamussa @hazelcast @testcontainers
  48. 48. @gamussa @hazelcast @testcontainers
  49. 49. @gamussa @hazelcast @testcontainers
  50. 50. @gamussa @hazelcast @testcontainers
  51. 51. @gamussa @hazelcast @testcontainers Integration Testing How Docker helps easy transition from Development to Production
  52. 52. @gamussa @hazelcast @testcontainers Verify how software product will behave in real-world conditions Why?
  53. 53. @gamussa @hazelcast @testcontainers Pros and cons
  54. 54. @gamussa @hazelcast @testcontainers Pros and cons ✓ Real-world isolated testing
  55. 55. @gamussa @hazelcast @testcontainers Pros and cons ✓ Real-world isolated testing ✓ Can be run during development
  56. 56. @gamussa @hazelcast @testcontainers Pros and cons ✓ Real-world isolated testing ✓ Can be run during development ✓ Spot the issues before they apear in prod
  57. 57. @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
  58. 58. @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
  59. 59. @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
  60. 60. @gamussa @hazelcast @testcontainers Solution – Docker!
  61. 61. @gamussa @hazelcast @testcontainers Solution – Docker! Abstraction layer
  62. 62. @gamussa @hazelcast @testcontainers Solution – Docker! Abstraction layer CI friendly
  63. 63. @gamussa @hazelcast @testcontainers Solution – Docker! Abstraction layer CI friendly Cross-platform
  64. 64. @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
  65. 65. @gamussa @hazelcast @testcontainers But…
  66. 66. @gamussa @hazelcast @testcontainers But… No port randomization
  67. 67. @gamussa @hazelcast @testcontainers But… No port randomization Fighting with docker env
  68. 68. @gamussa @hazelcast @testcontainers But… No port randomization Fighting with docker env localhost?
  69. 69. Remove the database
  70. 70. @gamussa @hazelcast @testcontainers
  71. 71. @gamussa @hazelcast @testcontainers Demo
  72. 72. @gamussa @hazelcast @testcontainers What to expect
  73. 73. @gamussa @hazelcast @testcontainers What to expect More testing frameworks support
  74. 74. @gamussa @hazelcast @testcontainers What to expect More testing frameworks support Chaos Testing via Pumba
  75. 75. @gamussa @hazelcast @testcontainers What to expect More testing frameworks support Chaos Testing via Pumba Integration / Merge with Arquillian Cube
  76. 76. DEVELOPMENT AND DEPLOYMENT WITH CLASSIC TOOLS
  77. 77. DEVELOPMENT AND DEPLOYMENT WITH CLASSIC TOOLS EXPLORE 
 THE
 WORLD OF CONTAINERS
  78. 78. @gamussa @hazelcast @testcontainers Thanks! QA? @gamussa http://gamov.io

×