Consumer-Driven Contracts with Pact (Sydney API Days 2015)
-
Upload
bethesque -
Category
Technology
-
view
673 -
download
0
Transcript of Consumer-Driven Contracts with Pact (Sydney API Days 2015)
![Page 1: Consumer-Driven Contracts with Pact (Sydney API Days 2015)](https://reader031.fdocuments.in/reader031/viewer/2022020123/55a6c77c1a28ab9d048b46da/html5/thumbnails/1.jpg)
Pacts to the rescue!Making your microservices play nicely together
with Consumer Driven Contracts
Beth Skurrie@bethesque / @[email protected]
![Page 2: Consumer-Driven Contracts with Pact (Sydney API Days 2015)](https://reader031.fdocuments.in/reader031/viewer/2022020123/55a6c77c1a28ab9d048b46da/html5/thumbnails/2.jpg)
“Integrated tests are a scam. A self replicating virus that threatens the very health of your codebase, your sanity, and I'm not exaggerating when I say, your life.”
- JB Rainsberger
![Page 3: Consumer-Driven Contracts with Pact (Sydney API Days 2015)](https://reader031.fdocuments.in/reader031/viewer/2022020123/55a6c77c1a28ab9d048b46da/html5/thumbnails/3.jpg)
Integrated Tests: The Problems
! Slow! Easy to break! Hard to fix! Scales combinatorially
3 classes, 4 code paths each4 * 4 * 4 = 64 tests
![Page 4: Consumer-Driven Contracts with Pact (Sydney API Days 2015)](https://reader031.fdocuments.in/reader031/viewer/2022020123/55a6c77c1a28ab9d048b46da/html5/thumbnails/4.jpg)
A B
mock
Test Symmetry… how it works
![Page 5: Consumer-Driven Contracts with Pact (Sydney API Days 2015)](https://reader031.fdocuments.in/reader031/viewer/2022020123/55a6c77c1a28ab9d048b46da/html5/thumbnails/5.jpg)
Test 1
Test 2
Test 3
Integrated tests
![Page 6: Consumer-Driven Contracts with Pact (Sydney API Days 2015)](https://reader031.fdocuments.in/reader031/viewer/2022020123/55a6c77c1a28ab9d048b46da/html5/thumbnails/6.jpg)
![Page 7: Consumer-Driven Contracts with Pact (Sydney API Days 2015)](https://reader031.fdocuments.in/reader031/viewer/2022020123/55a6c77c1a28ab9d048b46da/html5/thumbnails/7.jpg)
! Lack of automated tools! Relies on developer eternal vigilance! Does not scale
Test Symmetry: The Problem
![Page 8: Consumer-Driven Contracts with Pact (Sydney API Days 2015)](https://reader031.fdocuments.in/reader031/viewer/2022020123/55a6c77c1a28ab9d048b46da/html5/thumbnails/8.jpg)
Do we have the technology to achieve test symmetry?
Posed to DiUS
![Page 9: Consumer-Driven Contracts with Pact (Sydney API Days 2015)](https://reader031.fdocuments.in/reader031/viewer/2022020123/55a6c77c1a28ab9d048b46da/html5/thumbnails/9.jpg)
Slower Easier to break
Harder to fix Scales BADLY
Lots of infrastructure
False negativesLots of set up
System Integration Tests
![Page 10: Consumer-Driven Contracts with Pact (Sydney API Days 2015)](https://reader031.fdocuments.in/reader031/viewer/2022020123/55a6c77c1a28ab9d048b46da/html5/thumbnails/10.jpg)
Pact to the rescue!!!
![Page 11: Consumer-Driven Contracts with Pact (Sydney API Days 2015)](https://reader031.fdocuments.in/reader031/viewer/2022020123/55a6c77c1a28ab9d048b46da/html5/thumbnails/11.jpg)
A B
mock
C P
pact
Pact… how it works
![Page 12: Consumer-Driven Contracts with Pact (Sydney API Days 2015)](https://reader031.fdocuments.in/reader031/viewer/2022020123/55a6c77c1a28ab9d048b46da/html5/thumbnails/12.jpg)
Slower Easier to break
Harder to fix Scales BADLY
Lots of infrastructure
False negativesLots of set up
System Integration Tests
![Page 13: Consumer-Driven Contracts with Pact (Sydney API Days 2015)](https://reader031.fdocuments.in/reader031/viewer/2022020123/55a6c77c1a28ab9d048b46da/html5/thumbnails/13.jpg)
Fast Stable
Easy to debug Reliable
No extra infrastructure
Low setupScales linearly
Pact
![Page 14: Consumer-Driven Contracts with Pact (Sydney API Days 2015)](https://reader031.fdocuments.in/reader031/viewer/2022020123/55a6c77c1a28ab9d048b46da/html5/thumbnails/14.jpg)
Better API design!
![Page 15: Consumer-Driven Contracts with Pact (Sydney API Days 2015)](https://reader031.fdocuments.in/reader031/viewer/2022020123/55a6c77c1a28ab9d048b46da/html5/thumbnails/15.jpg)
Arrange - set up mock server
![Page 16: Consumer-Driven Contracts with Pact (Sydney API Days 2015)](https://reader031.fdocuments.in/reader031/viewer/2022020123/55a6c77c1a28ab9d048b46da/html5/thumbnails/16.jpg)
Arrange - set up mock server
![Page 17: Consumer-Driven Contracts with Pact (Sydney API Days 2015)](https://reader031.fdocuments.in/reader031/viewer/2022020123/55a6c77c1a28ab9d048b46da/html5/thumbnails/17.jpg)
Arrange - set up mock server
![Page 18: Consumer-Driven Contracts with Pact (Sydney API Days 2015)](https://reader031.fdocuments.in/reader031/viewer/2022020123/55a6c77c1a28ab9d048b46da/html5/thumbnails/18.jpg)
Arrange - set up expectations
![Page 19: Consumer-Driven Contracts with Pact (Sydney API Days 2015)](https://reader031.fdocuments.in/reader031/viewer/2022020123/55a6c77c1a28ab9d048b46da/html5/thumbnails/19.jpg)
Arrange - set up expectations
![Page 20: Consumer-Driven Contracts with Pact (Sydney API Days 2015)](https://reader031.fdocuments.in/reader031/viewer/2022020123/55a6c77c1a28ab9d048b46da/html5/thumbnails/20.jpg)
Arrange - set up expectations
![Page 21: Consumer-Driven Contracts with Pact (Sydney API Days 2015)](https://reader031.fdocuments.in/reader031/viewer/2022020123/55a6c77c1a28ab9d048b46da/html5/thumbnails/21.jpg)
Act and Assert
![Page 22: Consumer-Driven Contracts with Pact (Sydney API Days 2015)](https://reader031.fdocuments.in/reader031/viewer/2022020123/55a6c77c1a28ab9d048b46da/html5/thumbnails/22.jpg)
Act and Assert
![Page 23: Consumer-Driven Contracts with Pact (Sydney API Days 2015)](https://reader031.fdocuments.in/reader031/viewer/2022020123/55a6c77c1a28ab9d048b46da/html5/thumbnails/23.jpg)
![Page 24: Consumer-Driven Contracts with Pact (Sydney API Days 2015)](https://reader031.fdocuments.in/reader031/viewer/2022020123/55a6c77c1a28ab9d048b46da/html5/thumbnails/24.jpg)
Act and Assert
![Page 25: Consumer-Driven Contracts with Pact (Sydney API Days 2015)](https://reader031.fdocuments.in/reader031/viewer/2022020123/55a6c77c1a28ab9d048b46da/html5/thumbnails/25.jpg)
Act and Assert
![Page 26: Consumer-Driven Contracts with Pact (Sydney API Days 2015)](https://reader031.fdocuments.in/reader031/viewer/2022020123/55a6c77c1a28ab9d048b46da/html5/thumbnails/26.jpg)
Act and Assert
![Page 27: Consumer-Driven Contracts with Pact (Sydney API Days 2015)](https://reader031.fdocuments.in/reader031/viewer/2022020123/55a6c77c1a28ab9d048b46da/html5/thumbnails/27.jpg)
Set up test data
Consumer assumed:
Provider complies:
![Page 28: Consumer-Driven Contracts with Pact (Sydney API Days 2015)](https://reader031.fdocuments.in/reader031/viewer/2022020123/55a6c77c1a28ab9d048b46da/html5/thumbnails/28.jpg)
Set up test data
Consumer assumed:
Provider complies:
![Page 29: Consumer-Driven Contracts with Pact (Sydney API Days 2015)](https://reader031.fdocuments.in/reader031/viewer/2022020123/55a6c77c1a28ab9d048b46da/html5/thumbnails/29.jpg)
Verify: Fail
![Page 30: Consumer-Driven Contracts with Pact (Sydney API Days 2015)](https://reader031.fdocuments.in/reader031/viewer/2022020123/55a6c77c1a28ab9d048b46da/html5/thumbnails/30.jpg)
Verify: Success!
![Page 31: Consumer-Driven Contracts with Pact (Sydney API Days 2015)](https://reader031.fdocuments.in/reader031/viewer/2022020123/55a6c77c1a28ab9d048b46da/html5/thumbnails/31.jpg)
Postel’s law
![Page 32: Consumer-Driven Contracts with Pact (Sydney API Days 2015)](https://reader031.fdocuments.in/reader031/viewer/2022020123/55a6c77c1a28ab9d048b46da/html5/thumbnails/32.jpg)
Sharing pacts
![Page 33: Consumer-Driven Contracts with Pact (Sydney API Days 2015)](https://reader031.fdocuments.in/reader031/viewer/2022020123/55a6c77c1a28ab9d048b46da/html5/thumbnails/33.jpg)
P
publish pact latest pact
C
Pact Broker
Pact Broker - Share pacts
![Page 34: Consumer-Driven Contracts with Pact (Sydney API Days 2015)](https://reader031.fdocuments.in/reader031/viewer/2022020123/55a6c77c1a28ab9d048b46da/html5/thumbnails/34.jpg)
Pact Broker - Autogenerated documentation
![Page 35: Consumer-Driven Contracts with Pact (Sydney API Days 2015)](https://reader031.fdocuments.in/reader031/viewer/2022020123/55a6c77c1a28ab9d048b46da/html5/thumbnails/35.jpg)
Pact Broker - Network graph
![Page 36: Consumer-Driven Contracts with Pact (Sydney API Days 2015)](https://reader031.fdocuments.in/reader031/viewer/2022020123/55a6c77c1a28ab9d048b46da/html5/thumbnails/36.jpg)
Support
! JSON is language independent! Ruby! JVM (Java and Scala)! .net! Javascript (consumer side, provider side WIP)! Pact specification
![Page 37: Consumer-Driven Contracts with Pact (Sydney API Days 2015)](https://reader031.fdocuments.in/reader031/viewer/2022020123/55a6c77c1a28ab9d048b46da/html5/thumbnails/37.jpg)
“How is it working for you?”
![Page 38: Consumer-Driven Contracts with Pact (Sydney API Days 2015)](https://reader031.fdocuments.in/reader031/viewer/2022020123/55a6c77c1a28ab9d048b46da/html5/thumbnails/38.jpg)
Fast feedback in isolation +
Early detection +
Rapid recovery
![Page 39: Consumer-Driven Contracts with Pact (Sydney API Days 2015)](https://reader031.fdocuments.in/reader031/viewer/2022020123/55a6c77c1a28ab9d048b46da/html5/thumbnails/39.jpg)
Pact allows you to:
! Combine the advantages of integrated tests and test symmetry! Mitigates the shortcomings of each method! Allows you to modify components with agility - quick feedback
on potential breakages! Have confidence that all the services in your system will work
together! Throw away your integration tests!!!
![Page 40: Consumer-Driven Contracts with Pact (Sydney API Days 2015)](https://reader031.fdocuments.in/reader031/viewer/2022020123/55a6c77c1a28ab9d048b46da/html5/thumbnails/40.jpg)
PactMakes your microservices play nicely together with Consumer Driven Contracts
github.com/realestate-com-au/pact@pact_up
Beth [email protected] @bethesque
• Regular expressions & type based matching
• Why doesn’t Pact use JSON Schema?
• How to avoid versioning APIs • How to use Pact between teams • Should I use Pact for testing external APIs?
• How not to do it • And moar!