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

[JAX NYC] Microservice Testing Techniques: Mock...

danielbryantuk
September 26, 2023

[JAX NYC] Microservice Testing Techniques: Mocks vs Service Virtualization vs Remocal Tools

When enterprise organizations adopt microservices, containers, and cloud native development, the technologies and architectures may change, but the fact remains that we all still add the occasional bug to our code. The main challenge you now face is how to perform integration or end-to-end testing without spinning up all of your microservices locally and driving your laptop fans at high speed! Join me for a tour of your microservices testing options using a series of Java-friendly tools. Explore challenges with scaling container-based application development (you can only run so many microservices locally before minikube melts your laptop). Learn about effective unit testing with mocks, and how to use TestContainers for dependency testing, and Telepresence to extend your local testing environment into the cloud. Understand when to use each type of test and tooling based on your use case and requirements for realism, speed, and practicality. See how Telepresence can "intercept" or reroute traffic from a specified service in a remote K8s cluster to your local dev machine.

danielbryantuk

September 26, 2023
Tweet

More Decks by danielbryantuk

Other Decks in Technology

Transcript

  1. @danielbryantuk tl;dr 2 • The inner dev/test loop can be

    painful with microservices & Kubernetes • The pain increases as the number of services within your system increase • You have options with +/- : mocks, service virtualisation, remocal tools • Telepresence enables remote-to-local “remocal” development • Choose your dev/test approach wisely!
  2. @danielbryantuk Testing Microservices: What to use, when 3 Mocks Service

    virtualization Remocal Unit tests ✅ Integration tests ✅ ✅ Component tests ✅ ✅ ✅ End-to-end tests ✅ ✅ Inner loop exploration ✅
  3. @danielbryantuk Inner and outer dev loops 6 Hat tip to

    Mitch Denny (now 404): https://mitchdenny.com/the-inner-loop/ http://jorgemoral.es/posts/2020_03_17-develop_apps… Local: “You’ll pry localhost from my cold dead hands!" Remote: CI/CD/env as a Service”
  4. @danielbryantuk tl;dr 10 “My laptop only has 16GB RAM and

    you’re asking it to run Kubernetes and a JVM and a database???”
  5. @danielbryantuk Inner and outer dev loops with K8s can be

    the same 12 • Write code • Build container • Push to registry • Deploy to cluster • Test And can be …. SLOW.
  6. @danielbryantuk tl;dr 16 And you want to avoid the “works

    on my machine” production vs local dev debacle
  7. @danielbryantuk What are your options? 19 • Mocks • Mockito,

    PowerMock(ito), EasyMock, JMockit • Service virtualisation • TestContainers, LocalStack, (Embedded Datastore/middleware?) • Hover fl y, WireMock, Mountebank • Remocal tooling • Devspace, Okteto • Telepresence, mirrord, Gefyra
  8. @danielbryantuk Mocks 21 • Good • Idiomatic (familiar language constructs

    etc) • Quick and cheap • Can help build your mental model (TDD-like) • Bad • Implicit assumptions coded in (“the three realities conundrum”) • Dif fi cult to keep up to date and share/coordinate • Needs a test runner
  9. @danielbryantuk Testing Microservices: What to use, when 22 Mocks Unit

    tests ✅ Integration tests ✅ Component tests ✅ End-to-end tests Inner loop exploration
  10. @danielbryantuk Service virtualisation 26 • Good • More realistic than

    mocks (can be the “real thing”, albeit resource constrained) • Enables (wire-level) deterministic test of failure scenarios • Easy to use large(r) amounts of data • Bad • Slower than mocks to initialise • Can be tricky to con fi gure • Challenging to keep up to date and share (unless dedicated tooling/SaaS used)
  11. @danielbryantuk Testing Microservices: What to use, when 27 Service virtualization

    Unit tests Integration tests ✅ Component tests ✅ End-to-end tests ✅ Inner loop exploration
  12. @danielbryantuk Remocal tooling 29 • Good • Enables testing against

    (and poking of) the real thing • Data sets can be large scale (as resources can be scaled on remote cluster) • No need to build mental model of dependency (both good and bad!) • Bad • Need a solid network connection • Mutating remote shared state can be an issue • Lack of language bindings
  13. @danielbryantuk Testing Microservices: What to use, when 30 Remocal Unit

    tests Integration tests Component tests ✅ End-to-end tests ✅ Inner loop exploration ✅
  14. @danielbryantuk What is Telepresence 32 • “Fancy Kubernetes VPN for

    development” • “kubectl port-forward on steroids” • “kubectl proxy all-the-things” • A network bridge between your laptop and the Kubernetes cluster
  15. @danielbryantuk Telepresence: Local-to-Remote bridge 36 telepresence connect • Open a

    tunnel to the remote cluster; exposes “in-cluster” services/network/DNS telepresence intercept my-service —port 3000 • Re-routes (intercepts) traf fi c to my-service in the remote cluster to my local machine telepresence login & telepresence intercept • Create preview URL to isolate and share results of the intercept
  16. @danielbryantuk Telepresence: Local-to-Remote bridge $ telepresence intercept dataprocessingnodeservice --port 3000

    37 Using deployment dataprocessingnodeservice intercepted State : ACTIVE Destination : 127.0.0.1:3000 Intercepting: HTTP requests that match all of: header("x-telepresence-intercept-id") ~= regexp ("76a1e848-1829-74x-1138-e3294c1e9119:dataprocessingnodeservice") Preview URL : https://[random-subdomain].preview.edgestack.me www.youtube.com/watch?v=W_a3aErN3NU
  17. 40

  18. @danielbryantuk Testing Microservices: What to use, when 42 Mocks Service

    virtualization Remocal Unit tests ✅ Integration tests ✅ ✅ Component tests ✅ ✅ ✅ End-to-end tests ✅ ✅ Inner loop exploration ✅
  19. @danielbryantuk Conclusion 43 • The inner dev/test loop can be

    painful with microservices & Kubernetes • The pain increases as the number of services within your system increase • You have options with +/- : mocks, service virtualisation, remocal tools • Telepresence enables remote-to-local “remocal” development • Choose your dev/test approach wisely!