SlideShare a Scribd company logo
Consumer Driven Contracts
A Deep Dive
Ramya Authappan
Lead SDET, Freshworks
Few Things About Myself
www.facebook.com/at.ramya
@atramya
https://www.linkedin.com/in/ramy
aat/
ramya.authappan@freshworks.c
om
http://tiny.cc/ramya_talks
Lead SDET @ Freshworks
Passionate about
building/designing Test
Frameworks/Tools
Believes in building “Simple, yet
Powerful” tools
Loves to play with Sharon
About Freshworks
• SAAS Startup
• Believes in building software that’s ready to go, easy to setup and use, and
requires minimal customization.
• Global Presence:
• Investors:
• Products:
CDC - Consumer Driven Contract!
• Microservices @ Amazon
• Talks to each other via HTTP Requests
• How do I make sure that a simple change does not break
anything in the application? An integration nightmare!
• In such a system, how do I independently AND
confidently make changes?
• CDC to the RESCUE!
CDC - Consumer Driven Contract!
• Consumer-Driven Contracts is a pattern defined by Martin Fowler.
• In Consumer-Driven Contracts, each consumer captures their expectations of the provider in a separate contract
(pact).
• All of these contracts are shared with the provider so they gain insight into the obligations they must fulfil for each
individual client.
• Implementations:
• Pact - https://docs.pact.io/ - This is what we will use in this session.
• Pacto - https://github.com/thoughtworks/pacto
• Janus - https://github.com/gga/janus
• Spring Cloud Contract - https://cloud.spring.io/spring-cloud-contract/ - Found this implementation few days
back. - Java Implementation
CDC - Consumer Driven Contract!
• What is Pact? - An opensource library implementing CDC
• Available as ruby gems (gem: ‘pact’) and as npm packages
(‘pact’)
• Supports: Ruby, Java, .NET
• Beta: JS,Python, Swift, Go
• Its called “Asynchronous” Integration Tests - No extra setup
needed.
• As simple as unit tests but as powerful as E2E tests.
• Pact is run on both sides - On “Consumer” side and on
“Provider” side.
CDC - Consumer Side
Sends
response
for
assertions
Tests
Set
Expectations
Pact Mock Provider
Tests
invoke
code
Source Code
Sends
HTTP
Requests
Sends
expected
response
CDC - Pact File
DevPortal Activities
Request
Response
Consumer Provider
CDC - Pact File!
• Every HTTP Request and Response is
captured
• Standard way of representing interactions -
JSON file
• This is shared with the Provider.
• Explains everything that a consumer expects
from the Provider - the endpoints, query
params, header and the response objects.
CDC - Provider Side
Activities
Replay each HTTP Request
Get real HTTP Response
Provider
Pact File Compares real and
mock responses
CDC - Provider States
• Get activities of user with id=777
DevPortal Activities
Request
Response
Consumer Provider
Request
Response
?
CDC - Provider Side
state: cust_id=777 @ DB
• Get activities of user with id=777
DevPortal Activities
Request
Response
Consumer
Provider
Request
Response
state: cust_id=777 @ DB
state: cust_id=777 @ DB
CDC - Sharing Pact Files
Filesystem Cloud Pact BrokerCI Build
Artefact
CDC - Advantages!
• Eliminates Wrong Assumptions
• Enables communication
• Very less setup time!
• No extra infrastructure
• Need not start the dependent services to test!
• Fast in Execution
• Fails Fast - Identifies integration issues even before you actually
integrate!
• No flakiness!
• Easy to debug
Demo
Consumer Side : Setup Mock Server
Pact.service_consumer 'DevPortal' do
end
Consumer Side : Setup Mock Server
Pact.service_consumer 'DevPortal' do
has_pact_with "Freshapps Activities" do
end
end
Consumer Side : Setup Mock Server
Pact.service_consumer 'DevPortal' do
has_pact_with "Freshapps Activities" do
mock_service :freshapps_activities do
port 3005
end
end
end
Consumer Side : Setup Expectations
freshapps_activities.given(“all activities without role param")
Consumer Side : Setup Expectations
freshapps_activities.given(“all activities without role param")
.upon_receiving("a request for all activities")
.with(
method: :get,
path: '/all/activities.json',
query: {
page: '1',
account_id: '1' },
headers: {'Content-Type' => 'application/json', 'Accept' => 'application/json'} )
Consumer Side : Setup Expectations
freshapps_activities.given(“all activities without role param")
.upon_receiving("a request for all activities")
.with(
method: :get,
path: '/all/activities.json',
query: {
page: '1',
account_id: '1' },
headers: {'Content-Type' => 'application/json', 'Accept' => 'application/json'} )
.will_respond_with(
status: 422,
headers: {
'Content-Type' => 'application/json; charset=utf-8' },
body: { "error_msg" => "Required parameter missing" } )
Consumer Side : Make Request &
Assert
resp = FreshappsActivitiesClient.get_activities(path, query, header)
Consumer Side : Make Request &
Assert
resp = FreshappsActivitiesClient.get_activities(path, query, header)
expected_response = { "error_msg" => "Required parameter missing" }
expect(resp.parsed_response.inspect).to eq(expected_response.inspect)
Generated Pact File
Provider Side : Make Request & Assert
Pact.service_provider 'Freshapps Activities' do
end
Provider Side : Make Request & Assert
Pact.service_provider 'Freshapps Activities' do
honours_pact_with 'DevPortal' do
end
end
Provider Side : Make Request & Assert
Pact.service_provider 'Freshapps Activities' do
honours_pact_with 'DevPortal' do
pact_uri "../freshapps_devportal/spec/pacts/devportal-freshapps_activities.json"
end
end
end
Provider Side : Setup Test Data
Pact.provider_states_for "DevPortal" do
provider_state "all activities without role param" do
end
end
Remember:
Consumer Assumed:
freshapps_activities.given(“
all activities without role
param")
Provider Side : Setup Test Data
Remember:
Consumer Assumed:
freshapps_activities.given(“
all activities without role
param")
Pact.provider_states_for "DevPortal" do
provider_state "all activities without role param" do
set_up do
factory :activity do
account_id 1
user_id 1
extension_id 2
version_id 2
activity_type 'Extension'
visibility 1
activity { 'extension_id' => '2', 'name' => 'Sample Extension’}
end
end
end
end
Provider Side : Pact Verify Failure
Provider Side : Pact Verify Success
•My Upcoming Talks:
• WomenWhoCode August Meetup at Freshworks, Aug 19th - on “Docker and
CI”
Questions?
Thank you!

More Related Content

What's hot

React introduction
React introductionReact introduction
React introduction
Kashyap Parmar
 
I Know It Was MEAN, But I Cut the Cord to LAMP Anyway
I Know It Was MEAN, But I Cut the Cord to LAMP AnywayI Know It Was MEAN, But I Cut the Cord to LAMP Anyway
I Know It Was MEAN, But I Cut the Cord to LAMP Anyway
All Things Open
 
React && React Native workshop
React && React Native workshopReact && React Native workshop
React && React Native workshop
Stacy Goh
 
JOSA TechTalks - Better Web Apps with React and Redux
JOSA TechTalks - Better Web Apps with React and ReduxJOSA TechTalks - Better Web Apps with React and Redux
JOSA TechTalks - Better Web Apps with React and Redux
Jordan Open Source Association
 
Consume Spring Data Rest with Angularjs
Consume Spring Data Rest with AngularjsConsume Spring Data Rest with Angularjs
Consume Spring Data Rest with Angularjs
Corneil du Plessis
 
React js
React jsReact js
React js
Rajesh Kolla
 
Building Modern Web Applications using React and Redux
 Building Modern Web Applications using React and Redux Building Modern Web Applications using React and Redux
Building Modern Web Applications using React and Redux
Maxime Najim
 
29
2929
London React August - GraphQL at The Financial Times - Viktor Charypar
London React August - GraphQL at The Financial Times - Viktor CharyparLondon React August - GraphQL at The Financial Times - Viktor Charypar
London React August - GraphQL at The Financial Times - Viktor Charypar
React London Community
 
Introduction to ReactJs & fundamentals
Introduction to ReactJs & fundamentalsIntroduction to ReactJs & fundamentals
Introduction to ReactJs & fundamentals
websyndicate
 
A Brief Introduction to React.js
A Brief Introduction to React.jsA Brief Introduction to React.js
A Brief Introduction to React.js
Doug Neiner
 
From ActiveRecord to EventSourcing
From ActiveRecord to EventSourcingFrom ActiveRecord to EventSourcing
From ActiveRecord to EventSourcing
Emanuele DelBono
 
I Know It Was MEAN, But I Cut the Cord to LAMP Anyway
I Know It Was MEAN, But I Cut the Cord to LAMP AnywayI Know It Was MEAN, But I Cut the Cord to LAMP Anyway
I Know It Was MEAN, But I Cut the Cord to LAMP Anyway
POSSCON
 
SignalR tutorial & best practices
SignalR tutorial & best practicesSignalR tutorial & best practices
SignalR tutorial & best practices
Minh Ng
 
Entity framework db model的驗證機制 20130914
Entity framework db model的驗證機制 20130914Entity framework db model的驗證機制 20130914
Entity framework db model的驗證機制 20130914LearningTech
 
ReactJs
ReactJsReactJs
Jumpstarting Testing In Your Organization with Selenium, Cucumber, & WebdriverIO
Jumpstarting Testing In Your Organization with Selenium, Cucumber, & WebdriverIOJumpstarting Testing In Your Organization with Selenium, Cucumber, & WebdriverIO
Jumpstarting Testing In Your Organization with Selenium, Cucumber, & WebdriverIO
Josh Cypher
 
20150309 seven core principles of meteor
20150309 seven core principles of meteor20150309 seven core principles of meteor
20150309 seven core principles of meteor
Rick Wehrle
 

What's hot (18)

React introduction
React introductionReact introduction
React introduction
 
I Know It Was MEAN, But I Cut the Cord to LAMP Anyway
I Know It Was MEAN, But I Cut the Cord to LAMP AnywayI Know It Was MEAN, But I Cut the Cord to LAMP Anyway
I Know It Was MEAN, But I Cut the Cord to LAMP Anyway
 
React && React Native workshop
React && React Native workshopReact && React Native workshop
React && React Native workshop
 
JOSA TechTalks - Better Web Apps with React and Redux
JOSA TechTalks - Better Web Apps with React and ReduxJOSA TechTalks - Better Web Apps with React and Redux
JOSA TechTalks - Better Web Apps with React and Redux
 
Consume Spring Data Rest with Angularjs
Consume Spring Data Rest with AngularjsConsume Spring Data Rest with Angularjs
Consume Spring Data Rest with Angularjs
 
React js
React jsReact js
React js
 
Building Modern Web Applications using React and Redux
 Building Modern Web Applications using React and Redux Building Modern Web Applications using React and Redux
Building Modern Web Applications using React and Redux
 
29
2929
29
 
London React August - GraphQL at The Financial Times - Viktor Charypar
London React August - GraphQL at The Financial Times - Viktor CharyparLondon React August - GraphQL at The Financial Times - Viktor Charypar
London React August - GraphQL at The Financial Times - Viktor Charypar
 
Introduction to ReactJs & fundamentals
Introduction to ReactJs & fundamentalsIntroduction to ReactJs & fundamentals
Introduction to ReactJs & fundamentals
 
A Brief Introduction to React.js
A Brief Introduction to React.jsA Brief Introduction to React.js
A Brief Introduction to React.js
 
From ActiveRecord to EventSourcing
From ActiveRecord to EventSourcingFrom ActiveRecord to EventSourcing
From ActiveRecord to EventSourcing
 
I Know It Was MEAN, But I Cut the Cord to LAMP Anyway
I Know It Was MEAN, But I Cut the Cord to LAMP AnywayI Know It Was MEAN, But I Cut the Cord to LAMP Anyway
I Know It Was MEAN, But I Cut the Cord to LAMP Anyway
 
SignalR tutorial & best practices
SignalR tutorial & best practicesSignalR tutorial & best practices
SignalR tutorial & best practices
 
Entity framework db model的驗證機制 20130914
Entity framework db model的驗證機制 20130914Entity framework db model的驗證機制 20130914
Entity framework db model的驗證機制 20130914
 
ReactJs
ReactJsReactJs
ReactJs
 
Jumpstarting Testing In Your Organization with Selenium, Cucumber, & WebdriverIO
Jumpstarting Testing In Your Organization with Selenium, Cucumber, & WebdriverIOJumpstarting Testing In Your Organization with Selenium, Cucumber, & WebdriverIO
Jumpstarting Testing In Your Organization with Selenium, Cucumber, & WebdriverIO
 
20150309 seven core principles of meteor
20150309 seven core principles of meteor20150309 seven core principles of meteor
20150309 seven core principles of meteor
 

Similar to Consumer Driven Contracts - A Deep Dive

"Asynchronous" Integration Tests for Microservices - RootConf 2017
"Asynchronous" Integration Tests for Microservices - RootConf 2017"Asynchronous" Integration Tests for Microservices - RootConf 2017
"Asynchronous" Integration Tests for Microservices - RootConf 2017
Ramya Authappan
 
ATAGTR2017 CDC Tests - Integration Tests cant be made simpler than this!
ATAGTR2017 CDC Tests - Integration Tests cant be made simpler than this!ATAGTR2017 CDC Tests - Integration Tests cant be made simpler than this!
ATAGTR2017 CDC Tests - Integration Tests cant be made simpler than this!
Agile Testing Alliance
 
MongoDB.local Berlin: App development in a Serverless World
MongoDB.local Berlin: App development in a Serverless WorldMongoDB.local Berlin: App development in a Serverless World
MongoDB.local Berlin: App development in a Serverless World
MongoDB
 
Building Your First App with MongoDB
Building Your First App with MongoDBBuilding Your First App with MongoDB
Building Your First App with MongoDB
MongoDB
 
Switch to Backend 2023
Switch to Backend 2023Switch to Backend 2023
Service workers and their role in PWAs
Service workers and their role in PWAsService workers and their role in PWAs
Service workers and their role in PWAs
Ipsha Bhidonia
 
REST API 20.2 - Appworks Gateway Integration.pptx
REST API 20.2 - Appworks Gateway Integration.pptxREST API 20.2 - Appworks Gateway Integration.pptx
REST API 20.2 - Appworks Gateway Integration.pptx
Jason452803
 
InterConnect 2016 Java EE 7 Overview (PEJ-5296)
InterConnect 2016 Java EE 7 Overview (PEJ-5296)InterConnect 2016 Java EE 7 Overview (PEJ-5296)
InterConnect 2016 Java EE 7 Overview (PEJ-5296)
Kevin Sutter
 
Engineering Velocity @indeed eng presented on Sept 24 2014 at Beyond Agile
Engineering Velocity @indeed eng presented on Sept 24 2014 at Beyond AgileEngineering Velocity @indeed eng presented on Sept 24 2014 at Beyond Agile
Engineering Velocity @indeed eng presented on Sept 24 2014 at Beyond Agile
KenAtIndeed
 
Creating Rich Server API’s for your Mobile Apps - Best Practices and Guidelines
Creating Rich Server API’s for your Mobile Apps - Best Practices and GuidelinesCreating Rich Server API’s for your Mobile Apps - Best Practices and Guidelines
Creating Rich Server API’s for your Mobile Apps - Best Practices and Guidelines
Jonathan Guthrie
 
Starting Your DevOps Journey – Practical Tips for Ops
Starting Your DevOps Journey – Practical Tips for OpsStarting Your DevOps Journey – Practical Tips for Ops
Starting Your DevOps Journey – Practical Tips for Ops
Dynatrace
 
Uncovering breaking changes behind UI on mobile applications
Uncovering breaking changes behind UI on mobile applicationsUncovering breaking changes behind UI on mobile applications
Uncovering breaking changes behind UI on mobile applications
Kazuaki Matsuo
 
Timings API: Performance Assertion during the functional testing
 Timings API: Performance Assertion during the functional testing Timings API: Performance Assertion during the functional testing
Timings API: Performance Assertion during the functional testing
PetrosPlakogiannis
 
REST API Best Practices & Implementing in Codeigniter
REST API Best Practices & Implementing in CodeigniterREST API Best Practices & Implementing in Codeigniter
REST API Best Practices & Implementing in Codeigniter
Sachin G Kulkarni
 
Pinterest like site using REST and Bottle
Pinterest like site using REST and Bottle Pinterest like site using REST and Bottle
Pinterest like site using REST and Bottle Gaurav Bhardwaj
 
Bdd with Cucumber and Mocha
Bdd with Cucumber and MochaBdd with Cucumber and Mocha
Bdd with Cucumber and Mocha
Atish Narlawar
 
Consumer-driven contracts with Pact and PHP
Consumer-driven contracts with Pact and PHPConsumer-driven contracts with Pact and PHP
Consumer-driven contracts with Pact and PHP
Andy Kelk
 
Performance testing jmeter
Performance testing jmeterPerformance testing jmeter
Performance testing jmeterBhojan Rajan
 

Similar to Consumer Driven Contracts - A Deep Dive (20)

"Asynchronous" Integration Tests for Microservices - RootConf 2017
"Asynchronous" Integration Tests for Microservices - RootConf 2017"Asynchronous" Integration Tests for Microservices - RootConf 2017
"Asynchronous" Integration Tests for Microservices - RootConf 2017
 
ATAGTR2017 CDC Tests - Integration Tests cant be made simpler than this!
ATAGTR2017 CDC Tests - Integration Tests cant be made simpler than this!ATAGTR2017 CDC Tests - Integration Tests cant be made simpler than this!
ATAGTR2017 CDC Tests - Integration Tests cant be made simpler than this!
 
MongoDB.local Berlin: App development in a Serverless World
MongoDB.local Berlin: App development in a Serverless WorldMongoDB.local Berlin: App development in a Serverless World
MongoDB.local Berlin: App development in a Serverless World
 
Building Your First App with MongoDB
Building Your First App with MongoDBBuilding Your First App with MongoDB
Building Your First App with MongoDB
 
Cqrs api v2
Cqrs api v2Cqrs api v2
Cqrs api v2
 
Switch to Backend 2023
Switch to Backend 2023Switch to Backend 2023
Switch to Backend 2023
 
Service workers and their role in PWAs
Service workers and their role in PWAsService workers and their role in PWAs
Service workers and their role in PWAs
 
REST API 20.2 - Appworks Gateway Integration.pptx
REST API 20.2 - Appworks Gateway Integration.pptxREST API 20.2 - Appworks Gateway Integration.pptx
REST API 20.2 - Appworks Gateway Integration.pptx
 
InterConnect 2016 Java EE 7 Overview (PEJ-5296)
InterConnect 2016 Java EE 7 Overview (PEJ-5296)InterConnect 2016 Java EE 7 Overview (PEJ-5296)
InterConnect 2016 Java EE 7 Overview (PEJ-5296)
 
Engineering Velocity @indeed eng presented on Sept 24 2014 at Beyond Agile
Engineering Velocity @indeed eng presented on Sept 24 2014 at Beyond AgileEngineering Velocity @indeed eng presented on Sept 24 2014 at Beyond Agile
Engineering Velocity @indeed eng presented on Sept 24 2014 at Beyond Agile
 
Creating Rich Server API’s for your Mobile Apps - Best Practices and Guidelines
Creating Rich Server API’s for your Mobile Apps - Best Practices and GuidelinesCreating Rich Server API’s for your Mobile Apps - Best Practices and Guidelines
Creating Rich Server API’s for your Mobile Apps - Best Practices and Guidelines
 
Starting Your DevOps Journey – Practical Tips for Ops
Starting Your DevOps Journey – Practical Tips for OpsStarting Your DevOps Journey – Practical Tips for Ops
Starting Your DevOps Journey – Practical Tips for Ops
 
Uncovering breaking changes behind UI on mobile applications
Uncovering breaking changes behind UI on mobile applicationsUncovering breaking changes behind UI on mobile applications
Uncovering breaking changes behind UI on mobile applications
 
Timings API: Performance Assertion during the functional testing
 Timings API: Performance Assertion during the functional testing Timings API: Performance Assertion during the functional testing
Timings API: Performance Assertion during the functional testing
 
REST API Best Practices & Implementing in Codeigniter
REST API Best Practices & Implementing in CodeigniterREST API Best Practices & Implementing in Codeigniter
REST API Best Practices & Implementing in Codeigniter
 
Pinterest like site using REST and Bottle
Pinterest like site using REST and Bottle Pinterest like site using REST and Bottle
Pinterest like site using REST and Bottle
 
Bdd with Cucumber and Mocha
Bdd with Cucumber and MochaBdd with Cucumber and Mocha
Bdd with Cucumber and Mocha
 
Consumer-driven contracts with Pact and PHP
Consumer-driven contracts with Pact and PHPConsumer-driven contracts with Pact and PHP
Consumer-driven contracts with Pact and PHP
 
APITalkMeetupSharable
APITalkMeetupSharableAPITalkMeetupSharable
APITalkMeetupSharable
 
Performance testing jmeter
Performance testing jmeterPerformance testing jmeter
Performance testing jmeter
 

Recently uploaded

BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdfBPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
MIGUELANGEL966976
 
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdf
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdfGoverning Equations for Fundamental Aerodynamics_Anderson2010.pdf
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdf
WENKENLI1
 
Harnessing WebAssembly for Real-time Stateless Streaming Pipelines
Harnessing WebAssembly for Real-time Stateless Streaming PipelinesHarnessing WebAssembly for Real-time Stateless Streaming Pipelines
Harnessing WebAssembly for Real-time Stateless Streaming Pipelines
Christina Lin
 
Modelagem de um CSTR com reação endotermica.pdf
Modelagem de um CSTR com reação endotermica.pdfModelagem de um CSTR com reação endotermica.pdf
Modelagem de um CSTR com reação endotermica.pdf
camseq
 
NUMERICAL SIMULATIONS OF HEAT AND MASS TRANSFER IN CONDENSING HEAT EXCHANGERS...
NUMERICAL SIMULATIONS OF HEAT AND MASS TRANSFER IN CONDENSING HEAT EXCHANGERS...NUMERICAL SIMULATIONS OF HEAT AND MASS TRANSFER IN CONDENSING HEAT EXCHANGERS...
NUMERICAL SIMULATIONS OF HEAT AND MASS TRANSFER IN CONDENSING HEAT EXCHANGERS...
ssuser7dcef0
 
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressionsKuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
Victor Morales
 
Online aptitude test management system project report.pdf
Online aptitude test management system project report.pdfOnline aptitude test management system project report.pdf
Online aptitude test management system project report.pdf
Kamal Acharya
 
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
bakpo1
 
Technical Drawings introduction to drawing of prisms
Technical Drawings introduction to drawing of prismsTechnical Drawings introduction to drawing of prisms
Technical Drawings introduction to drawing of prisms
heavyhaig
 
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
insn4465
 
ACEP Magazine edition 4th launched on 05.06.2024
ACEP Magazine edition 4th launched on 05.06.2024ACEP Magazine edition 4th launched on 05.06.2024
ACEP Magazine edition 4th launched on 05.06.2024
Rahul
 
[JPP-1] - (JEE 3.0) - Kinematics 1D - 14th May..pdf
[JPP-1] - (JEE 3.0) - Kinematics 1D - 14th May..pdf[JPP-1] - (JEE 3.0) - Kinematics 1D - 14th May..pdf
[JPP-1] - (JEE 3.0) - Kinematics 1D - 14th May..pdf
awadeshbabu
 
digital fundamental by Thomas L.floydl.pdf
digital fundamental by Thomas L.floydl.pdfdigital fundamental by Thomas L.floydl.pdf
digital fundamental by Thomas L.floydl.pdf
drwaing
 
Literature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptxLiterature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptx
Dr Ramhari Poudyal
 
DfMAy 2024 - key insights and contributions
DfMAy 2024 - key insights and contributionsDfMAy 2024 - key insights and contributions
DfMAy 2024 - key insights and contributions
gestioneergodomus
 
Fundamentals of Induction Motor Drives.pptx
Fundamentals of Induction Motor Drives.pptxFundamentals of Induction Motor Drives.pptx
Fundamentals of Induction Motor Drives.pptx
manasideore6
 
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&BDesign and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Sreedhar Chowdam
 
ACRP 4-09 Risk Assessment Method to Support Modification of Airfield Separat...
ACRP 4-09 Risk Assessment Method to Support Modification of Airfield Separat...ACRP 4-09 Risk Assessment Method to Support Modification of Airfield Separat...
ACRP 4-09 Risk Assessment Method to Support Modification of Airfield Separat...
Mukeshwaran Balu
 
6th International Conference on Machine Learning & Applications (CMLA 2024)
6th International Conference on Machine Learning & Applications (CMLA 2024)6th International Conference on Machine Learning & Applications (CMLA 2024)
6th International Conference on Machine Learning & Applications (CMLA 2024)
ClaraZara1
 
spirit beverages ppt without graphics.pptx
spirit beverages ppt without graphics.pptxspirit beverages ppt without graphics.pptx
spirit beverages ppt without graphics.pptx
Madan Karki
 

Recently uploaded (20)

BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdfBPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
 
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdf
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdfGoverning Equations for Fundamental Aerodynamics_Anderson2010.pdf
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdf
 
Harnessing WebAssembly for Real-time Stateless Streaming Pipelines
Harnessing WebAssembly for Real-time Stateless Streaming PipelinesHarnessing WebAssembly for Real-time Stateless Streaming Pipelines
Harnessing WebAssembly for Real-time Stateless Streaming Pipelines
 
Modelagem de um CSTR com reação endotermica.pdf
Modelagem de um CSTR com reação endotermica.pdfModelagem de um CSTR com reação endotermica.pdf
Modelagem de um CSTR com reação endotermica.pdf
 
NUMERICAL SIMULATIONS OF HEAT AND MASS TRANSFER IN CONDENSING HEAT EXCHANGERS...
NUMERICAL SIMULATIONS OF HEAT AND MASS TRANSFER IN CONDENSING HEAT EXCHANGERS...NUMERICAL SIMULATIONS OF HEAT AND MASS TRANSFER IN CONDENSING HEAT EXCHANGERS...
NUMERICAL SIMULATIONS OF HEAT AND MASS TRANSFER IN CONDENSING HEAT EXCHANGERS...
 
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressionsKuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
 
Online aptitude test management system project report.pdf
Online aptitude test management system project report.pdfOnline aptitude test management system project report.pdf
Online aptitude test management system project report.pdf
 
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
 
Technical Drawings introduction to drawing of prisms
Technical Drawings introduction to drawing of prismsTechnical Drawings introduction to drawing of prisms
Technical Drawings introduction to drawing of prisms
 
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
 
ACEP Magazine edition 4th launched on 05.06.2024
ACEP Magazine edition 4th launched on 05.06.2024ACEP Magazine edition 4th launched on 05.06.2024
ACEP Magazine edition 4th launched on 05.06.2024
 
[JPP-1] - (JEE 3.0) - Kinematics 1D - 14th May..pdf
[JPP-1] - (JEE 3.0) - Kinematics 1D - 14th May..pdf[JPP-1] - (JEE 3.0) - Kinematics 1D - 14th May..pdf
[JPP-1] - (JEE 3.0) - Kinematics 1D - 14th May..pdf
 
digital fundamental by Thomas L.floydl.pdf
digital fundamental by Thomas L.floydl.pdfdigital fundamental by Thomas L.floydl.pdf
digital fundamental by Thomas L.floydl.pdf
 
Literature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptxLiterature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptx
 
DfMAy 2024 - key insights and contributions
DfMAy 2024 - key insights and contributionsDfMAy 2024 - key insights and contributions
DfMAy 2024 - key insights and contributions
 
Fundamentals of Induction Motor Drives.pptx
Fundamentals of Induction Motor Drives.pptxFundamentals of Induction Motor Drives.pptx
Fundamentals of Induction Motor Drives.pptx
 
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&BDesign and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
 
ACRP 4-09 Risk Assessment Method to Support Modification of Airfield Separat...
ACRP 4-09 Risk Assessment Method to Support Modification of Airfield Separat...ACRP 4-09 Risk Assessment Method to Support Modification of Airfield Separat...
ACRP 4-09 Risk Assessment Method to Support Modification of Airfield Separat...
 
6th International Conference on Machine Learning & Applications (CMLA 2024)
6th International Conference on Machine Learning & Applications (CMLA 2024)6th International Conference on Machine Learning & Applications (CMLA 2024)
6th International Conference on Machine Learning & Applications (CMLA 2024)
 
spirit beverages ppt without graphics.pptx
spirit beverages ppt without graphics.pptxspirit beverages ppt without graphics.pptx
spirit beverages ppt without graphics.pptx
 

Consumer Driven Contracts - A Deep Dive

  • 1. Consumer Driven Contracts A Deep Dive Ramya Authappan Lead SDET, Freshworks
  • 2. Few Things About Myself www.facebook.com/at.ramya @atramya https://www.linkedin.com/in/ramy aat/ ramya.authappan@freshworks.c om http://tiny.cc/ramya_talks Lead SDET @ Freshworks Passionate about building/designing Test Frameworks/Tools Believes in building “Simple, yet Powerful” tools Loves to play with Sharon
  • 3. About Freshworks • SAAS Startup • Believes in building software that’s ready to go, easy to setup and use, and requires minimal customization. • Global Presence: • Investors: • Products:
  • 4. CDC - Consumer Driven Contract! • Microservices @ Amazon • Talks to each other via HTTP Requests • How do I make sure that a simple change does not break anything in the application? An integration nightmare! • In such a system, how do I independently AND confidently make changes? • CDC to the RESCUE!
  • 5. CDC - Consumer Driven Contract! • Consumer-Driven Contracts is a pattern defined by Martin Fowler. • In Consumer-Driven Contracts, each consumer captures their expectations of the provider in a separate contract (pact). • All of these contracts are shared with the provider so they gain insight into the obligations they must fulfil for each individual client. • Implementations: • Pact - https://docs.pact.io/ - This is what we will use in this session. • Pacto - https://github.com/thoughtworks/pacto • Janus - https://github.com/gga/janus • Spring Cloud Contract - https://cloud.spring.io/spring-cloud-contract/ - Found this implementation few days back. - Java Implementation
  • 6. CDC - Consumer Driven Contract! • What is Pact? - An opensource library implementing CDC • Available as ruby gems (gem: ‘pact’) and as npm packages (‘pact’) • Supports: Ruby, Java, .NET • Beta: JS,Python, Swift, Go • Its called “Asynchronous” Integration Tests - No extra setup needed. • As simple as unit tests but as powerful as E2E tests. • Pact is run on both sides - On “Consumer” side and on “Provider” side.
  • 7. CDC - Consumer Side Sends response for assertions Tests Set Expectations Pact Mock Provider Tests invoke code Source Code Sends HTTP Requests Sends expected response
  • 8. CDC - Pact File DevPortal Activities Request Response Consumer Provider
  • 9. CDC - Pact File! • Every HTTP Request and Response is captured • Standard way of representing interactions - JSON file • This is shared with the Provider. • Explains everything that a consumer expects from the Provider - the endpoints, query params, header and the response objects.
  • 10. CDC - Provider Side Activities Replay each HTTP Request Get real HTTP Response Provider Pact File Compares real and mock responses
  • 11. CDC - Provider States • Get activities of user with id=777 DevPortal Activities Request Response Consumer Provider Request Response ?
  • 12. CDC - Provider Side state: cust_id=777 @ DB • Get activities of user with id=777 DevPortal Activities Request Response Consumer Provider Request Response state: cust_id=777 @ DB state: cust_id=777 @ DB
  • 13. CDC - Sharing Pact Files Filesystem Cloud Pact BrokerCI Build Artefact
  • 14. CDC - Advantages! • Eliminates Wrong Assumptions • Enables communication • Very less setup time! • No extra infrastructure • Need not start the dependent services to test! • Fast in Execution • Fails Fast - Identifies integration issues even before you actually integrate! • No flakiness! • Easy to debug
  • 15. Demo
  • 16. Consumer Side : Setup Mock Server Pact.service_consumer 'DevPortal' do end
  • 17. Consumer Side : Setup Mock Server Pact.service_consumer 'DevPortal' do has_pact_with "Freshapps Activities" do end end
  • 18. Consumer Side : Setup Mock Server Pact.service_consumer 'DevPortal' do has_pact_with "Freshapps Activities" do mock_service :freshapps_activities do port 3005 end end end
  • 19. Consumer Side : Setup Expectations freshapps_activities.given(“all activities without role param")
  • 20. Consumer Side : Setup Expectations freshapps_activities.given(“all activities without role param") .upon_receiving("a request for all activities") .with( method: :get, path: '/all/activities.json', query: { page: '1', account_id: '1' }, headers: {'Content-Type' => 'application/json', 'Accept' => 'application/json'} )
  • 21. Consumer Side : Setup Expectations freshapps_activities.given(“all activities without role param") .upon_receiving("a request for all activities") .with( method: :get, path: '/all/activities.json', query: { page: '1', account_id: '1' }, headers: {'Content-Type' => 'application/json', 'Accept' => 'application/json'} ) .will_respond_with( status: 422, headers: { 'Content-Type' => 'application/json; charset=utf-8' }, body: { "error_msg" => "Required parameter missing" } )
  • 22. Consumer Side : Make Request & Assert resp = FreshappsActivitiesClient.get_activities(path, query, header)
  • 23. Consumer Side : Make Request & Assert resp = FreshappsActivitiesClient.get_activities(path, query, header) expected_response = { "error_msg" => "Required parameter missing" } expect(resp.parsed_response.inspect).to eq(expected_response.inspect)
  • 25. Provider Side : Make Request & Assert Pact.service_provider 'Freshapps Activities' do end
  • 26. Provider Side : Make Request & Assert Pact.service_provider 'Freshapps Activities' do honours_pact_with 'DevPortal' do end end
  • 27. Provider Side : Make Request & Assert Pact.service_provider 'Freshapps Activities' do honours_pact_with 'DevPortal' do pact_uri "../freshapps_devportal/spec/pacts/devportal-freshapps_activities.json" end end end
  • 28. Provider Side : Setup Test Data Pact.provider_states_for "DevPortal" do provider_state "all activities without role param" do end end Remember: Consumer Assumed: freshapps_activities.given(“ all activities without role param")
  • 29. Provider Side : Setup Test Data Remember: Consumer Assumed: freshapps_activities.given(“ all activities without role param") Pact.provider_states_for "DevPortal" do provider_state "all activities without role param" do set_up do factory :activity do account_id 1 user_id 1 extension_id 2 version_id 2 activity_type 'Extension' visibility 1 activity { 'extension_id' => '2', 'name' => 'Sample Extension’} end end end end
  • 30. Provider Side : Pact Verify Failure
  • 31. Provider Side : Pact Verify Success
  • 32. •My Upcoming Talks: • WomenWhoCode August Meetup at Freshworks, Aug 19th - on “Docker and CI”