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

Building testable APIs using functions & meshes

Building testable APIs using functions & meshes

In this live coding talk you will learn about functional techniques that encourage separation of concerns. I will build a stateful HTTP API from highly isolated components that are easier to test than entangled spaghetti-like codebases. I will show you how tests can help us scaffold the architecture and how should we approach testing in the era of microservices. In the session I will use immutability, type parameters and function parameters as tools to implement a very practical example: Pac-Man game web server. I will code in Scala using Akka HTTP and deploy to Kubernetes with Istio service mesh.

Michał Płachta

May 10, 2018
Tweet

More Decks by Michał Płachta

Other Decks in Programming

Transcript

  1. @miciek Mocking and Stubbing... Mocking interfaces with 3, 4, 5+

    functions... Mocking interfaces with 0 or 1 functions...
  2. @miciek HTTP layer requirements POST /games { “gridName”: “msPacManLevel1” }

    200 OK { “gameId”: 1 } 200 OK { "pacMan": { "position": { "x": 2, "y": 1 }, "direction": "east" } } GET /games/1
  3. @miciek Holding multiple games at once A concurrent hash-trie or

    TrieMap is a concurrent thread-safe lock-free implementation of a hash array mapped trie. - Scala documentation http://lampwww.epfl.ch/~prokopec/ctries-snapshot.pdf
  4. @miciek Testing on Production Backend service PROD Frontend service PROD

    Service Discovery Circuit Breaking Security Scalability & Routing Telemetry App Container App Container
  5. @miciek Testing on Production… in Isolation? Backend service PROD Frontend

    service PROD Sidecar Sidecar Service Discovery Circuit Breaking Security Scalability & Routing Telemetry App Container App Container
  6. @miciek Service Mesh Backend service PROD Frontend service PROD Sidecar

    Sidecar Another Service PROD Sidecar Service Mesh Control Plane
  7. @miciek Testing on Production… in Isolation Backend service PROD Frontend

    service PROD Sidecar Sidecar Backend service v2 (test) Sidecar Routing only test traffic to v2
  8. @miciek New Testing Pyramid Real Fast, Stable, Real No HTTP

    Servers Function parameters Abstracting over data Routing test traffic Isolated tests on PROD
  9. @miciek Summary functional programming helps with separation of concerns service

    meshes may help with isolated testing ...but they are new & unproven
  10. @miciek Next steps ➔ Play around with https://www.github.com/miciek/pacman-multiplayer-fp project ➔

    Play with Kubernetes and Istio using Katakoda https://www.katacoda.com/courses/istio/deploy-istio-on-kubernetes