Beruflich Dokumente
Kultur Dokumente
I Introduction
I Event Sourcing 101
I A Formal Model for Event Sourcing
I Consumer-Driven Contract Testing
I Beyond CDCT
I Conclusion
Part I
Introduction
Why?
Why?
or:
Who we are?
What?
I Is . . . well . . . ubiquitous
Ubiquitous Language
I Is . . . well . . . ubiquitous
I Carries the business language into the code and beyond
Ubiquitous Language
I Is . . . well . . . ubiquitous
I Carries the business language into the code and beyond
I Allows everybody to understand everybody else
Ubiquitous Language
I Is . . . well . . . ubiquitous
I Carries the business language into the code and beyond
I Allows everybody to understand everybody else
I Understanding without (even unconscious) translation steps
Ubiquitous Language
I Is . . . well . . . ubiquitous
I Carries the business language into the code and beyond
I Allows everybody to understand everybody else
I Understanding without (even unconscious) translation steps
I Should be made explicit in a glossary
Commands and Events
State
Command Event
Pure
Impure
Interact Persist
World
Example: An Event-Sourced Pet Store
data Input =
-- Commands
Add { pet :: Pet }
| Remove { pet :: Pet }
-- Queries
| ListPets
Outputs: Events & Answers
data Output =
-- Events
PetAdded { pet :: Pet }
| PetRemoved { pet :: Pet }
-- Answers
| Pets { pets :: [ Pet ] }
| Error { reason :: PetStoreError }
-- some errors
data PetStoreError = PetAlreadyAdded
| PetDoesNotExist
Part III
AddPet p1/
PetAlreadyAdded
RemovePet p2/
PetRemoved p2
PetAdded p2
AddPet p2/
RemovePet p2/
PetDoesNotExist
{p2}
Part IV
map
Communication
map
Layer
Problems:
I Frontend development is blocked
I Integration tests are slow
I Full integration testing does not scale
Standard Approach: “Still Quite Naïve”
Problems:
I Frontend relies on mocks for backend API
I Do the mocks reflect the backend’s actual behaviour?
I Usually, backend behaviour changes
I Frontend does not notice because mocks still look good
Standard “Industry-Strength” Approach
Consumer Provider
(Frontend) (Backend)
Standard “Industry-Strength” Approach
Consumer Provider
(Frontend) (Backend)
Standard “Industry-Strength” Approach
Consumer Provider
(Frontend) (Backend)
Generate
Stub
Standard “Industry-Strength” Approach
Consumer Provider
(Frontend) (Backend)
Use in Dev
Generate
Stub
Standard “Industry-Strength” Approach
Consumer Provider
(Frontend) (Backend)
Use in Dev
Generate Generate
Stub Tests
Standard “Industry-Strength” Approach
Consumer Provider
(Frontend) (Backend)
Stub Tests
Standard “Industry-Strength” Approach
Consumer Provider
(Frontend) (Backend)
Stub Tests
Example: Pet Store Contracts
{
"description": "a request for all pets",
"providerState": "i have no pets",
"request": {
"method": "GET",
"path": "/pets",
"headers": { "Accept": "application/json" }
},
"response": {
"status": 200,
"headers": { "Content-Type": "application/json" },
"body": {
"tag": "Pets",
"pets": []
}
}
}
Example: Pet Store Contracts
{
"description": "a request for all pets",
"providerState": "i have a list of pets",
"request": {
"method": "GET",
"path": "/pets",
"headers": { "Accept": "application/json" }
},
"response": {
"status": 200,
"headers": { "Content-Type": "application/json" },
"body": {
"tag": "Pets",
"pets": [
{ "petName": "Fifi", "petType": "Dog" },
{ "petName": "Minki", "petType": "Cat" }
]
}
}
}
The Problem with CDCT
Beyond CDCT
Back to Formal Language
Front end
Model
Model-Based Interaction Testing
Front end
Check Inputs
Model
Model-Based Interaction Testing
Front end
Generate Valid
Check Inputs
Outputs
Model
Model-Based Interaction Testing
Front end
Model
Generate Inputs
Back end
Model-Based Interaction Testing
Front end
Model
Back end
Example: PetStore Model
petStore :: Input
-> PetStore
-> (Maybe Output, PetStore)
| otherwise =
(Just $ Error PetAlreadyAdded, store)
Demo
https://github.com/aleryo/homomorphic-event-sourcing
Bug Trophy
Conclusion
Event Sourcing & Formal Methods
Arnaud Bailly
E-Mail arnaud@aleryo.com
Twitter @dr_c0d3
Web http://aleryo.com
Web http://symbiont.io
Nicole Rauch
E-Mail info@nicole-rauch.de
Twitter @NicoleRauch
Web http://www.nicole-rauch.de