Slide 1

Slide 1 text

@miciek @miciek Michał Płachta www.michalplachta.com www.michalplachta.com Building testable APIs using functions & meshes @miciek

Slide 2

Slide 2 text

@miciek Reinventing the Test Pyramid ? ? ?

Slide 3

Slide 3 text

@miciek New Testing Pyramid: Part I ? ? Unit?

Slide 4

Slide 4 text

@miciek Unit Tests

Slide 5

Slide 5 text

@miciek What we really want... Fast! Stable! Quick to read/write! Documentation

Slide 6

Slide 6 text

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

Slide 7

Slide 7 text

@miciek Part I ? ? Fast, Stable, Real

Slide 8

Slide 8 text

@miciek Pac-Man Game Server ? Engine ?

Slide 9

Slide 9 text

@miciek Pac-Man Engine Domain

Slide 10

Slide 10 text

@miciek Pac-Man Engine Domain

Slide 11

Slide 11 text

@miciek Pac-Man Engine Domain

Slide 12

Slide 12 text

@miciek Pac-Man Engine Domain

Slide 13

Slide 13 text

@miciek Immutable Pac-Man Engine GameState movePacMan GameState current new GameState changeDir GameState current new

Slide 14

Slide 14 text

@miciek TDDing Pac-Man Engine

Slide 15

Slide 15 text

@miciek TDDing Pac-Man Engine

Slide 16

Slide 16 text

@miciek TDDing Pac-Man Engine Live coding

Slide 17

Slide 17 text

@miciek TDDing Pac-Man Engine

Slide 18

Slide 18 text

@miciek TDDing Pac-Man Engine

Slide 19

Slide 19 text

@miciek TDDing Pac-Man Engine

Slide 20

Slide 20 text

@miciek TDDing Pac-Man Engine

Slide 21

Slide 21 text

@miciek Pure & Immutable

Slide 22

Slide 22 text

@miciek TDDing Pac-Man Engine

Slide 23

Slide 23 text

@miciek New Testing Pyramid: Part II ? Service? Integration? Fast, Stable, Real

Slide 24

Slide 24 text

@miciek Pac-Man Game Server Engine HTTP ?

Slide 25

Slide 25 text

@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

Slide 26

Slide 26 text

@miciek What we always want... Fast! Stable! Quick to read/write! Documentation

Slide 27

Slide 27 text

@miciek Testing HTTP layer Live coding

Slide 28

Slide 28 text

@miciek Fast, Stable, Real, Documenting

Slide 29

Slide 29 text

@miciek Separation of Concerns I only know what I NEED to know...

Slide 30

Slide 30 text

@miciek Pac-Man Game Server State Engine HTTP

Slide 31

Slide 31 text

@miciek Requirements State holds multiple games at once updates (ticks) all the games every 200ms

Slide 32

Slide 32 text

@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

Slide 33

Slide 33 text

@miciek Holding multiple games at once

Slide 34

Slide 34 text

@miciek Ticking all the games every 200ms https://monix.io/docs/2x/execution/scheduler.html#schedule-with-a-delay

Slide 35

Slide 35 text

@miciek Quick integration tests Live coding

Slide 36

Slide 36 text

@miciek New Testing Pyramid: Part II ? Service? Integration? Fast, Stable, Real

Slide 37

Slide 37 text

@miciek New Testing Pyramid: Part II ? Fast, Stable, Real

Slide 38

Slide 38 text

@miciek Only one service so far... State Engine HTTP Backend service

Slide 39

Slide 39 text

@miciek Communicating Services Backend service Frontend service Service Discovery Circuit Breaking Security Scalability & Routing Telemetry

Slide 40

Slide 40 text

@miciek Testing on Production Backend service PROD Frontend service PROD Service Discovery Circuit Breaking Security Scalability & Routing Telemetry App Container App Container

Slide 41

Slide 41 text

@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

Slide 42

Slide 42 text

@miciek Service Mesh Backend service PROD Frontend service PROD Sidecar Sidecar Another Service PROD Sidecar Service Mesh Control Plane

Slide 43

Slide 43 text

@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

Slide 44

Slide 44 text

@miciek Isolated tests on Production Live coding

Slide 45

Slide 45 text

@miciek New Testing Pyramid Real Fast, Stable, Real No HTTP Servers Function parameters Abstracting over data Routing test traffic Isolated tests on PROD

Slide 46

Slide 46 text

@miciek Summary functional programming helps with separation of concerns service meshes may help with isolated testing ...but they are new & unproven

Slide 47

Slide 47 text

@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

Slide 48

Slide 48 text

@miciek @miciek www.michalplachta.com

Slide 49

Slide 49 text

@miciek @miciek Michał Płachta www.michalplachta.com www.michalplachta.com Building testable APIs using functions & meshes @miciek github.com/miciek/pacman-multiplayer-fp