SlideShare a Scribd company logo
Prod-Like Integration Testing for
Distributed Containerized Applications
Maria Gabriella Brodi ⸱ @BrodiMg
Staff Solutions Engineer, VMware
⸺
Cora Iberkleid ⸱ @ciberkleid
Developer Advocate, VMware
Abstract
Integration testing for distributed containerized applications poses new challenges in terms of
practices, tools, and environments for developers who want to carry out more prod-like
integration testing earlier in the development lifecycle.
In-memory databases are useful but cannot provide the level of assurance needed as you test
against a real database. This option is also limited to data services, but not all services provide
an in-memory alternative.
Testcontainers is a framework for instantiating standalone containers for any number of
services to test against. The framework offers some out-of-the-box options, but you can also
provide your own image, and even your own Dockerfile to instantiate the service of your choice.
In this talk, we'll explore testcontainers and push the boundaries in order to explore how they
may be used in conjunction with Cloud Native Buildpacks. This approach has the added benefit
of ensuring that all testing is carried out on the same container stack.
Agenda
- Intro
- Testcontainers 101
- DB integration testing
- Network affinity testing
- Environment parity
- Takeaways
INTRO
What do we mean by “prod-like” integration testing?
● Integration vs Unit tests
● Greater fidelity to run-time conditions
● Type of system
● Network reliability
● OS environment
● Shifted left
● Local developer machine
● Iterate locally
Common Approaches to Integration Test
In Integration tests we are interested in verifying the behavior and interactions of
multiple modules.
For this purpose we can use:
- Shared instances
- Local installation
- In memory solutions
In-memory testing
App
Mock server or
in-memory service
Options:
● Mock server (Wiremock, Loki…)
● In-memory service (h2, hsql...)
Limitations of in-memory testing
App
Mock server or
in-memory service
Limitations:
● Requires framework support
● Behavior differences to real system
● Latency/bandwidth testing can be challenging
● Not every service has an in-memory option
● Differences in security configuration
New challenges with in-memory testing
App
Challenge exacerbated with explosion in microservices
and variety of service options over the last 10 years.
Mock server or
in-memory service
Limitations:
● Requires framework support
● Behavior differences to real system
● Latency/bandwidth testing can be challenging
● Not every service has an in-memory option
● Differences in security configuration
New challenges with in-memory testing
App
Challenge exacerbated with explosion in microservices
and variety of service options over the last 10 years.
Mock server or
in-memory service
Limitations:
● Requires framework support
● Behavior differences to real system
● Latency/bandwidth testing can be challenging
● Not every service has an in-memory option
● Differences in security configuration
Containerization Helps!
● Containerization per se is a big part of the solution
● Docker Compose - works for any framework
However…
● Cumbersome lifecycle management
● Additional skill set for developers to learn
However!
● There is an easier solution :)
Testcontainers: easy testing with external services
Service on Docker
App
Testcontainers
dependency
TESTCONTAINERS 101
Testcontainers intro/overview
● Java library that creates instances of Docker containers for testing
● Supports JUnit4, JUnit5, and Spock
Support for other languages
(check GitHub for more complete information)
Available Modules
● Provides lightweight,
throwaway instances
of common
databases, Selenium
web browsers, and
more
● Can start anything
else that can run in a
Docker container
Why Testcontainers? Where to use them?
● Prod-like systems:
● Easier instantiation of disposable services that lack an in-memory option
● Test against any application that can run as a container
● Integration testing:
● Data access layer integration
● Application integration
● Browser-based acceptance
inspiration...
package org.testcontainers.junit.jupiter;
import ...
class TestcontainersExtension implements BeforeEachCallback, BeforeAllCallback,
AfterEachCallback, AfterAllCallback, ExecutionCondition, TestInstancePostProcessor {
@Testcontainers (JUnit 5)
JUnit5 Extension - intercepts JUnit lifecycle
events and manages container lifecycles
@Testcontainers
public class MyIntegrationTests {
@Container // In JUnit 4, use @Rule/@ClassRule
static PostgreSQLContainer<?> db = new PostgreSQLContainer<>("postgres");
...
@ExtendWith({TestcontainersExtension.class})
@Container (JUnit 5) / @Rule (JUnit 4)
@Testcontainers
public class MyIntegrationTests {
@Container // In JUnit 4, use @Rule/@ClassRule
PostgreSQLContainer<?> db = new PostgreSQLContainer<>("postgres");
...
Flags TestcontainersExtension about a container to manage
● New container is started/stopped for every test
● Declare as static to re-use the same container
DEMO TIME
TESTCONTAINERS BASICS
“REAL” DATABASE
INTEGRATION TESTING
Close...but different!
...ish
Elephant by Anton from the Noun Project
DEMO TIME
DB INTEGRATION TESTING
NETWORK RELIABILITY
Which Challenges in a Real Environment?
Network can misbehave:
- Increase Latency
- Decrease Bandwidth
- Unexpected Closed Connections
- Changes in Packet Size
And Everything goes … BANANAS
Toxiproxy
A framework for simulating network conditions. It's
made specifically to work in testing, CI and
development environments.
https://github.com/Shopify/toxiproxy
Toxiproxy & Testcontainers
Toxiproxy available as a Testcontainers Module
Started as separate container on the Docker daemon
The toxiproxy container proxies all the traffics to the service container
Requires toxiproxy and service containers to be on the same network
Network Definition
Service on Docker
(e.g. postgres)
Toxiproxy
Network
We can facilitate connections between
containers without exposing ports on the
hosts by using a Network object
App testcontainers
Network Definition
Service on Docker
(e.g. postgres)
Toxiproxy
Network
App testcontainers
A maximum of one network can be shared
between containers.
Service on Docker
(e.g. redis)
DEMO
NETWORK RELIABILITY
ENVIRONMENT
AFFINITY
OS Base Layer
Path to Production - Environment Parity
CI Test Job CI Build Job
Build Layer 1
Build Layer N
OS = ?
Runtime= ?
OS = ?
Runtime= ?
OS = ?
Runtime= ?
Common Approaches
● Test and Build and Run environments often configured separately
○ Test job environment in CI toolchain
○ Build job environment in CI toolchain (separately, sometimes)
○ Run environment often configure in Dockerfile (‘FROM’ base image)
○ Very hard to keep synchronized
● Two-stage Dockerfiles help with specifying same build and run base images
○ Two ‘FROM’ statements in the same Dockerfile
○ Stil, hard to manage across applications at scale
A Better Way: Cloud Native Buildpacks
● Buildpacks provide a consistent way to build images at scale
● Build and run stacks guaranteed to be the same
● Distributed as a standalone “builder” image - easily shared across an
organization
● Polyglot
● Choice in user experience
○ CLI, Maven/Gradle plugin, Kubernetes operator, and more…
● Default configuration of Maven Buildpack:
BP_MAVEN_BUILD_ARGUMENTS='-Dmaven.test.skip=true package'
Cloud Native Buildpacks (CNB)
CNB Run Image
CI Test Job CNB Builder
CNB BP Layer(s)
CNB App Layer(s)
OS = ✅
Runtime= ✅
OS = ?
Runtime= ?
OS = ✅
Runtime= ✅
● Custom configuration:
BP_MAVEN_BUILD_ARGUMENTS='-Dmaven.test.skip=false package'
Cloud Native Buildpacks (CNB)
CNB Run Image
Test & Build!
CNB Builder CNB BP Layer(s)
CNB App Layer(s)
OS = ✅
Runtime= ✅
OS = ✅
Runtime= ✅
Test & Build!
CNB Builder
pack build my-springone-app 
--builder paketobuildpacks/builder:base 
--env BP_MAVEN_BUILD_ARGUMENTS='Dtest=Demo2_Toxiproxy_Tst test package'
Test & Build!
CNB Builder
mvn package
CNB Builder
testcontainers-java
CNB Builder
Hold your horses…
buildpacks can’t start
containers on Docker
Postgres
DOCKER_HOST = unix:///var/run/docker.sock
testcontainers-java
CNB Builder
Postgres
TCP
DOCKER_HOST = unix:///var/run/docker.sock
testcontainers-java
CNB Builder
Postgres
TCP
DOCKER_HOST = unix:///var/run/docker.sock
DOCKER_HOST = tcp://${DOCKER_HOST_IP}:${DOCKER_PORT}
Still respects security
guardrails of CNB ✅
Pack + Testcontainers Docker Host Detection
● We use a common utility (socat) to map the TCP port to the Unix socket
socat TCP-LISTEN:2375,reuseaddr,fork UNIX-CONNECT:/var/run/docker.sock &
pack build my-springone-app 
--builder paketobuildpacks/builder:base 
--env BP_MAVEN_BUILD_ARGUMENTS='Dtest=Demo2_Toxiproxy_Tst test package' 
--env DOCKER_HOST=tcp://${DOCKER_HOST_IP}:2375
pkill socat
DEMO TIME
ENVIRONMENT AFFINITY
TAKEAWAYS
Get more “prod-like” integration testing using...
★ Testcontainers for improved system affinity
★ Toxiproxy for network resiliency testing
★ CNB with pack CLI and Paketo Buildpacks
Get more “prod-like” integration testing using...
★ Testcontainers for improved system affinity
★ Toxiproxy for network resiliency testing
★ CNB with pack CLI and Paketo Buildpacks
★ And… all from the comfort of your local machine!
Links
Demos:
https://github.com/springone-2021-testcontainers/testcontainers-demo
Testcontainers:
https://www.testcontainers.org
Toxiproxy:
https://github.com/Shopify/toxiproxy
Cloud Native Buildpacks:
https://buildpacks.io
Thank you!
Please join us on Slack
for 15 min of Q&A

More Related Content

PDF
Writing the Container Network Interface(CNI) plugin in golang
PDF
Gitlab CI : Integration et Déploiement Continue
PPTX
Jenkins CI presentation
PDF
Using GitLab CI
PPTX
Introduction to CNI (Container Network Interface)
PPTX
Selenium Tutorial For Beginners | Selenium Automation Testing Tutorial | Sele...
PPTX
CI/CD
PPTX
Introduction to helm
Writing the Container Network Interface(CNI) plugin in golang
Gitlab CI : Integration et Déploiement Continue
Jenkins CI presentation
Using GitLab CI
Introduction to CNI (Container Network Interface)
Selenium Tutorial For Beginners | Selenium Automation Testing Tutorial | Sele...
CI/CD
Introduction to helm

What's hot (20)

DOCX
What is jenkins
PPTX
Jenkins CI
ODP
Kubernetes Architecture
PDF
Introduction to kubernetes
PPTX
Gitlab CI/CD
PDF
쿠버네티스를 이용한 기능 브랜치별 테스트 서버 만들기 (GitOps CI/CD)
PDF
Prometheus Overview
PPTX
Introduction to CI/CD
PDF
[DPE Summit] How Improving the Testing Experience Goes Beyond Quality: A Deve...
PPTX
Why Docker
PDF
[오픈소스컨설팅] 쿠버네티스와 쿠버네티스 on 오픈스택 비교 및 구축 방법
PPTX
Fundamentals of DevOps and CI/CD
PDF
Docker Introduction
PPTX
Introduction to the Container Network Interface (CNI)
PDF
Hands On Introduction To Ansible Configuration Management With Ansible Comple...
PPT
presentation on Docker
PDF
Introduction to CICD
PDF
Learn O11y from Grafana ecosystem.
PDF
[OpenStack Days Korea 2016] Track1 - 카카오는 오픈스택 기반으로 어떻게 5000VM을 운영하고 있을까?
PPTX
Flusso Continuous Integration & Continuous Delivery
What is jenkins
Jenkins CI
Kubernetes Architecture
Introduction to kubernetes
Gitlab CI/CD
쿠버네티스를 이용한 기능 브랜치별 테스트 서버 만들기 (GitOps CI/CD)
Prometheus Overview
Introduction to CI/CD
[DPE Summit] How Improving the Testing Experience Goes Beyond Quality: A Deve...
Why Docker
[오픈소스컨설팅] 쿠버네티스와 쿠버네티스 on 오픈스택 비교 및 구축 방법
Fundamentals of DevOps and CI/CD
Docker Introduction
Introduction to the Container Network Interface (CNI)
Hands On Introduction To Ansible Configuration Management With Ansible Comple...
presentation on Docker
Introduction to CICD
Learn O11y from Grafana ecosystem.
[OpenStack Days Korea 2016] Track1 - 카카오는 오픈스택 기반으로 어떻게 5000VM을 운영하고 있을까?
Flusso Continuous Integration & Continuous Delivery
Ad

Similar to Prod-Like Integration Testing for Distributed Containerized Applications (20)

PDF
Level Up Your Integration Testing With Testcontainers
PDF
Containerised Testing at Demonware : PyCon Ireland 2016
PPTX
JBCN_Testing_With_Containers
PPTX
JLove - Replicating production on your laptop using the magic of containers
PDF
Cloud Native Dünyada CI/CD
PPTX
Continuous Delivery with Jenkins declarative pipeline XPDays-2018-12-08
PDF
Kubernetes and Hybrid Deployments
PDF
Mete Atamel "Resilient microservices with kubernetes"
PDF
Extensible dev secops pipelines with Jenkins, Docker, Terraform, and a kitche...
PPTX
Kubernetes @ meetic
PDF
Developers Testing - Girl Code at bloomon
PPTX
Anatomy of a Build Pipeline
PPTX
Slow, Flaky and Legacy Tests: FTFY - Our New Testing Strategy at Net-A-Porter...
PDF
Efficient Parallel Testing with Docker
PDF
KubeCon EU 2016: Leveraging ephemeral namespaces in a CI/CD pipeline
PDF
DCEU 18: Building Your Development Pipeline
PDF
Velocity NYC 2016 - Containers @ Netflix
PPTX
ma-formation-en-Docker-jlklk,nknkjn.pptx
PDF
Augmenting Software Development with Containerization in Automation Testing.pdf
PDF
Creating Realistic Unit Tests with Testcontainers
Level Up Your Integration Testing With Testcontainers
Containerised Testing at Demonware : PyCon Ireland 2016
JBCN_Testing_With_Containers
JLove - Replicating production on your laptop using the magic of containers
Cloud Native Dünyada CI/CD
Continuous Delivery with Jenkins declarative pipeline XPDays-2018-12-08
Kubernetes and Hybrid Deployments
Mete Atamel "Resilient microservices with kubernetes"
Extensible dev secops pipelines with Jenkins, Docker, Terraform, and a kitche...
Kubernetes @ meetic
Developers Testing - Girl Code at bloomon
Anatomy of a Build Pipeline
Slow, Flaky and Legacy Tests: FTFY - Our New Testing Strategy at Net-A-Porter...
Efficient Parallel Testing with Docker
KubeCon EU 2016: Leveraging ephemeral namespaces in a CI/CD pipeline
DCEU 18: Building Your Development Pipeline
Velocity NYC 2016 - Containers @ Netflix
ma-formation-en-Docker-jlklk,nknkjn.pptx
Augmenting Software Development with Containerization in Automation Testing.pdf
Creating Realistic Unit Tests with Testcontainers
Ad

More from VMware Tanzu (20)

PDF
Spring into AI presented by Dan Vega 5/14
PDF
What AI Means For Your Product Strategy And What To Do About It
PDF
Make the Right Thing the Obvious Thing at Cardinal Health 2023
PPTX
Enhancing DevEx and Simplifying Operations at Scale
PDF
Spring Update | July 2023
PPTX
Platforms, Platform Engineering, & Platform as a Product
PPTX
Building Cloud Ready Apps
PDF
Spring Boot 3 And Beyond
PDF
Spring Cloud Gateway - SpringOne Tour 2023 Charles Schwab.pdf
PDF
Simplify and Scale Enterprise Apps in the Cloud | Boston 2023
PDF
Simplify and Scale Enterprise Apps in the Cloud | Seattle 2023
PPTX
tanzu_developer_connect.pptx
PDF
Tanzu Virtual Developer Connect Workshop - French
PDF
Tanzu Developer Connect Workshop - English
PDF
Virtual Developer Connect Workshop - English
PDF
Tanzu Developer Connect - French
PDF
Simplify and Scale Enterprise Apps in the Cloud | Dallas 2023
PDF
SpringOne Tour: Deliver 15-Factor Applications on Kubernetes with Spring Boot
PDF
SpringOne Tour: The Influential Software Engineer
PDF
SpringOne Tour: Domain-Driven Design: Theory vs Practice
Spring into AI presented by Dan Vega 5/14
What AI Means For Your Product Strategy And What To Do About It
Make the Right Thing the Obvious Thing at Cardinal Health 2023
Enhancing DevEx and Simplifying Operations at Scale
Spring Update | July 2023
Platforms, Platform Engineering, & Platform as a Product
Building Cloud Ready Apps
Spring Boot 3 And Beyond
Spring Cloud Gateway - SpringOne Tour 2023 Charles Schwab.pdf
Simplify and Scale Enterprise Apps in the Cloud | Boston 2023
Simplify and Scale Enterprise Apps in the Cloud | Seattle 2023
tanzu_developer_connect.pptx
Tanzu Virtual Developer Connect Workshop - French
Tanzu Developer Connect Workshop - English
Virtual Developer Connect Workshop - English
Tanzu Developer Connect - French
Simplify and Scale Enterprise Apps in the Cloud | Dallas 2023
SpringOne Tour: Deliver 15-Factor Applications on Kubernetes with Spring Boot
SpringOne Tour: The Influential Software Engineer
SpringOne Tour: Domain-Driven Design: Theory vs Practice

Recently uploaded (20)

PPTX
ManageIQ - Sprint 268 Review - Slide Deck
PDF
Softaken Excel to vCard Converter Software.pdf
PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PDF
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
PDF
medical staffing services at VALiNTRY
PPTX
Operating system designcfffgfgggggggvggggggggg
PPTX
VVF-Customer-Presentation2025-Ver1.9.pptx
PDF
Digital Strategies for Manufacturing Companies
PDF
How to Migrate SBCGlobal Email to Yahoo Easily
PDF
Understanding Forklifts - TECH EHS Solution
PDF
PTS Company Brochure 2025 (1).pdf.......
PDF
Wondershare Filmora 15 Crack With Activation Key [2025
PPTX
Introduction to Artificial Intelligence
PPTX
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
PPTX
history of c programming in notes for students .pptx
PPTX
CHAPTER 12 - CYBER SECURITY AND FUTURE SKILLS (1) (1).pptx
PPTX
Odoo POS Development Services by CandidRoot Solutions
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
PDF
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
PPTX
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
ManageIQ - Sprint 268 Review - Slide Deck
Softaken Excel to vCard Converter Software.pdf
Adobe Illustrator 28.6 Crack My Vision of Vector Design
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
medical staffing services at VALiNTRY
Operating system designcfffgfgggggggvggggggggg
VVF-Customer-Presentation2025-Ver1.9.pptx
Digital Strategies for Manufacturing Companies
How to Migrate SBCGlobal Email to Yahoo Easily
Understanding Forklifts - TECH EHS Solution
PTS Company Brochure 2025 (1).pdf.......
Wondershare Filmora 15 Crack With Activation Key [2025
Introduction to Artificial Intelligence
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
history of c programming in notes for students .pptx
CHAPTER 12 - CYBER SECURITY AND FUTURE SKILLS (1) (1).pptx
Odoo POS Development Services by CandidRoot Solutions
Upgrade and Innovation Strategies for SAP ERP Customers
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises

Prod-Like Integration Testing for Distributed Containerized Applications

  • 1. Prod-Like Integration Testing for Distributed Containerized Applications Maria Gabriella Brodi ⸱ @BrodiMg Staff Solutions Engineer, VMware ⸺ Cora Iberkleid ⸱ @ciberkleid Developer Advocate, VMware
  • 2. Abstract Integration testing for distributed containerized applications poses new challenges in terms of practices, tools, and environments for developers who want to carry out more prod-like integration testing earlier in the development lifecycle. In-memory databases are useful but cannot provide the level of assurance needed as you test against a real database. This option is also limited to data services, but not all services provide an in-memory alternative. Testcontainers is a framework for instantiating standalone containers for any number of services to test against. The framework offers some out-of-the-box options, but you can also provide your own image, and even your own Dockerfile to instantiate the service of your choice. In this talk, we'll explore testcontainers and push the boundaries in order to explore how they may be used in conjunction with Cloud Native Buildpacks. This approach has the added benefit of ensuring that all testing is carried out on the same container stack.
  • 3. Agenda - Intro - Testcontainers 101 - DB integration testing - Network affinity testing - Environment parity - Takeaways
  • 5. What do we mean by “prod-like” integration testing? ● Integration vs Unit tests ● Greater fidelity to run-time conditions ● Type of system ● Network reliability ● OS environment ● Shifted left ● Local developer machine ● Iterate locally
  • 6. Common Approaches to Integration Test In Integration tests we are interested in verifying the behavior and interactions of multiple modules. For this purpose we can use: - Shared instances - Local installation - In memory solutions
  • 7. In-memory testing App Mock server or in-memory service Options: ● Mock server (Wiremock, Loki…) ● In-memory service (h2, hsql...)
  • 8. Limitations of in-memory testing App Mock server or in-memory service Limitations: ● Requires framework support ● Behavior differences to real system ● Latency/bandwidth testing can be challenging ● Not every service has an in-memory option ● Differences in security configuration
  • 9. New challenges with in-memory testing App Challenge exacerbated with explosion in microservices and variety of service options over the last 10 years. Mock server or in-memory service Limitations: ● Requires framework support ● Behavior differences to real system ● Latency/bandwidth testing can be challenging ● Not every service has an in-memory option ● Differences in security configuration
  • 10. New challenges with in-memory testing App Challenge exacerbated with explosion in microservices and variety of service options over the last 10 years. Mock server or in-memory service Limitations: ● Requires framework support ● Behavior differences to real system ● Latency/bandwidth testing can be challenging ● Not every service has an in-memory option ● Differences in security configuration
  • 11. Containerization Helps! ● Containerization per se is a big part of the solution ● Docker Compose - works for any framework However… ● Cumbersome lifecycle management ● Additional skill set for developers to learn However! ● There is an easier solution :)
  • 12. Testcontainers: easy testing with external services Service on Docker App Testcontainers dependency
  • 14. Testcontainers intro/overview ● Java library that creates instances of Docker containers for testing ● Supports JUnit4, JUnit5, and Spock
  • 15. Support for other languages (check GitHub for more complete information)
  • 16. Available Modules ● Provides lightweight, throwaway instances of common databases, Selenium web browsers, and more ● Can start anything else that can run in a Docker container
  • 17. Why Testcontainers? Where to use them? ● Prod-like systems: ● Easier instantiation of disposable services that lack an in-memory option ● Test against any application that can run as a container ● Integration testing: ● Data access layer integration ● Application integration ● Browser-based acceptance
  • 19. package org.testcontainers.junit.jupiter; import ... class TestcontainersExtension implements BeforeEachCallback, BeforeAllCallback, AfterEachCallback, AfterAllCallback, ExecutionCondition, TestInstancePostProcessor { @Testcontainers (JUnit 5) JUnit5 Extension - intercepts JUnit lifecycle events and manages container lifecycles @Testcontainers public class MyIntegrationTests { @Container // In JUnit 4, use @Rule/@ClassRule static PostgreSQLContainer<?> db = new PostgreSQLContainer<>("postgres"); ... @ExtendWith({TestcontainersExtension.class})
  • 20. @Container (JUnit 5) / @Rule (JUnit 4) @Testcontainers public class MyIntegrationTests { @Container // In JUnit 4, use @Rule/@ClassRule PostgreSQLContainer<?> db = new PostgreSQLContainer<>("postgres"); ... Flags TestcontainersExtension about a container to manage ● New container is started/stopped for every test ● Declare as static to re-use the same container
  • 23. Close...but different! ...ish Elephant by Anton from the Noun Project
  • 26. Which Challenges in a Real Environment? Network can misbehave: - Increase Latency - Decrease Bandwidth - Unexpected Closed Connections - Changes in Packet Size And Everything goes … BANANAS
  • 27. Toxiproxy A framework for simulating network conditions. It's made specifically to work in testing, CI and development environments. https://github.com/Shopify/toxiproxy
  • 28. Toxiproxy & Testcontainers Toxiproxy available as a Testcontainers Module Started as separate container on the Docker daemon The toxiproxy container proxies all the traffics to the service container Requires toxiproxy and service containers to be on the same network
  • 29. Network Definition Service on Docker (e.g. postgres) Toxiproxy Network We can facilitate connections between containers without exposing ports on the hosts by using a Network object App testcontainers
  • 30. Network Definition Service on Docker (e.g. postgres) Toxiproxy Network App testcontainers A maximum of one network can be shared between containers. Service on Docker (e.g. redis)
  • 33. OS Base Layer Path to Production - Environment Parity CI Test Job CI Build Job Build Layer 1 Build Layer N OS = ? Runtime= ? OS = ? Runtime= ? OS = ? Runtime= ?
  • 34. Common Approaches ● Test and Build and Run environments often configured separately ○ Test job environment in CI toolchain ○ Build job environment in CI toolchain (separately, sometimes) ○ Run environment often configure in Dockerfile (‘FROM’ base image) ○ Very hard to keep synchronized ● Two-stage Dockerfiles help with specifying same build and run base images ○ Two ‘FROM’ statements in the same Dockerfile ○ Stil, hard to manage across applications at scale
  • 35. A Better Way: Cloud Native Buildpacks ● Buildpacks provide a consistent way to build images at scale ● Build and run stacks guaranteed to be the same ● Distributed as a standalone “builder” image - easily shared across an organization ● Polyglot ● Choice in user experience ○ CLI, Maven/Gradle plugin, Kubernetes operator, and more…
  • 36. ● Default configuration of Maven Buildpack: BP_MAVEN_BUILD_ARGUMENTS='-Dmaven.test.skip=true package' Cloud Native Buildpacks (CNB) CNB Run Image CI Test Job CNB Builder CNB BP Layer(s) CNB App Layer(s) OS = ✅ Runtime= ✅ OS = ? Runtime= ? OS = ✅ Runtime= ✅
  • 37. ● Custom configuration: BP_MAVEN_BUILD_ARGUMENTS='-Dmaven.test.skip=false package' Cloud Native Buildpacks (CNB) CNB Run Image Test & Build! CNB Builder CNB BP Layer(s) CNB App Layer(s) OS = ✅ Runtime= ✅ OS = ✅ Runtime= ✅
  • 38. Test & Build! CNB Builder pack build my-springone-app --builder paketobuildpacks/builder:base --env BP_MAVEN_BUILD_ARGUMENTS='Dtest=Demo2_Toxiproxy_Tst test package'
  • 39. Test & Build! CNB Builder
  • 41. testcontainers-java CNB Builder Hold your horses… buildpacks can’t start containers on Docker Postgres DOCKER_HOST = unix:///var/run/docker.sock
  • 43. testcontainers-java CNB Builder Postgres TCP DOCKER_HOST = unix:///var/run/docker.sock DOCKER_HOST = tcp://${DOCKER_HOST_IP}:${DOCKER_PORT} Still respects security guardrails of CNB ✅
  • 44. Pack + Testcontainers Docker Host Detection ● We use a common utility (socat) to map the TCP port to the Unix socket socat TCP-LISTEN:2375,reuseaddr,fork UNIX-CONNECT:/var/run/docker.sock & pack build my-springone-app --builder paketobuildpacks/builder:base --env BP_MAVEN_BUILD_ARGUMENTS='Dtest=Demo2_Toxiproxy_Tst test package' --env DOCKER_HOST=tcp://${DOCKER_HOST_IP}:2375 pkill socat
  • 47. Get more “prod-like” integration testing using... ★ Testcontainers for improved system affinity ★ Toxiproxy for network resiliency testing ★ CNB with pack CLI and Paketo Buildpacks
  • 48. Get more “prod-like” integration testing using... ★ Testcontainers for improved system affinity ★ Toxiproxy for network resiliency testing ★ CNB with pack CLI and Paketo Buildpacks ★ And… all from the comfort of your local machine!
  • 50. Thank you! Please join us on Slack for 15 min of Q&A