SlideShare a Scribd company logo
1
Testing a Service
Fabric solution and
live happy!!!
Massimo Bonanni
Paranormal Developer, with the head in the Cloud and all the
REST in microservices!
@massimobonanni
massimo.bonanni@microsoft.com
@cloudgen_verona
#CodeGen
#dotnetconf
3
Main sponsor
4
Community sponsors
5
6
Unit testing
8
Programming
Models
Dev & Ops
Tooling
Orchestration Lifecycle
Management
Health &
Monitoring
Always On
Availability
Auto
Scaling
AzureOn-premises infrastructureAny cloudDev machine
Service Fabric: Microservices platform
ExecutablesReliable Services (.NET, Java)
Reliable Actors (.NET, Java)ASP.NET Core
Containers
9
F5 is our friend….
It is the most used test tools
It's free and you can find it in all Visual
Studio versions
You don’t have to write any additional code
10
F5 is not useful …. with Service Fabric
Resources – you need a local cluster
Time – you need to publish the app
Code complete – you need all the
microservices you interact with
11
Why unit test…
A unit test is an automated piece
of code that invokes a unit of work
in the system and then checks a
single assumption about the
behavior of that unit of work.
Roy Osherove – The Art Of Unit Testing
Microservices are small, perform
single functionality and loosely
coupled.
Microservices Architecture
12
Why unit test…
A unit test is an automated piece
of code that invokes a unit of work
in the system and then checks a
single assumption about the
behavior of that unit of work.
Roy Osherove – The Art Of Unit Testing
Microservices are small, perform
single functionality and loosely
coupled.
Microservices Architecture
A microservice is
your Unit of
Work to test!!!
13
The three obstacles
Your
µService
Service Fabric Platform
Replicas Partitioning State Management……
File System Database Web Service
External Components Others µServices
14
Real case: Shopping Cart & Order
We model 3 typical shopping cart scenarios
• The cart can be created only if it is a new cart
Creating the shopping cart
• Need to check if the product is still available
Adding a product to the cart
• The order is created starting from the cart and only if the order is new
Creating an order from the cart
15
Scenario : Creating the shopping cart
We must "replace" the
Service Fabric platform, so
our tests doesn’t need the
cluster.
Service Fabric Platform
Replicas Partitioning
State
Management
……
16
Scenario : Creating the shopping cart
this.StateManager.TryGetStateAsync<State>(StateKeyName,
cancellationToken);
this.StateManager.SetStateAsync(StateKeyName,
state, cancellationToken);
this.RegisterReminderAsync(ExpiredReminderName, null,
CartExpiredTimeout, TimeSpan.FromMilliseconds(-1));
17
Scenario : Adding a product to the cart
We need to decouple our
microservice from external
components, so that our tests can
verify only the actor's logic.
File System Database Web Service
External Components
18
Scenario : Adding a product to the cart
private async Task<ProductData> GetProductFromStorageAsync(string productId,
double quantity, CancellationToken cancellationToken)
{
ProductData result = null;
try
{
using (SqlConnection conn = new SqlConnection(connectionString))
using (SqlCommand cmd = new SqlCommand("CheckProduct", conn))
{
// Database code
}
}
catch
{
result = null;
}
return result;
}
19
Scenario : Creating an order from the cart
We must to replace the static
classes ActorProxy and
ServiceProxy used in the
creation of communication
proxies.
Others µServices
20
Scenario : Creating an order from the cart
var orderProxy = ActorProxy.Create<IOrderActor>(this.Id,
new Uri("fabric:/TestingApp/OrderActor"));
Demo:
Unit test
22
The three obstacles….three solutions!
Your
µService
Service Fabric Platform
Replicas Partitioning
State
Management
……
File System Database Web Service
External Components Others µServices
Mock the platform
(ServiceFabric.Mocks)
Abstract the proxy
factories
Create a layer of
indirection
The CHAOS
24
Keep the stability!!!!
Solutions based on distributed architectures such as cloud infrastructures
must be:
This is why you need to be able to test the stability of your solutions when
complex state transitions due to errors occur in the underlying
infrastructure.
•able to withstand or recover quickly from difficult conditionsResilient
• its status does not get corrupted as a result of a problemReliable
25
What can go wrong in production?
Restarting a
node
Restarting a
distributed
code package
Removing a
replica
Restarting a
replica
Moving a
primary
replica
Moving a
secondary
replica
Remove a
node
Add a node
26
27
Start-ServiceFabricChaos
Chaos induces faults in the cluster based on the received input
parameters.
Chaos runs in multiple iterations: each iteration consists of faults
and cluster validation.
You can control:
• how long Chaos runs,
• how long it waits between
iterations,
• how many faults it can induce
during an iteration,
• how long it waits between faults.
• ….
Demo:
Chaos test
29
Take away….
Keep the microservices simple….they will be
testability simply!
When design a solution, keep in mind the
testability!
Mock, fake and shim are your best friends!
If car companies launch expensive cars
against a wall to test them, why should not
you do it with your code?
Grazie
massimobonanni @massimobonanni massimobonanni

More Related Content

PDF
The art of Azure Functions (unit) testing and monitoring
PDF
Empower every Azure Function to achieve more!!
PDF
The art of Azure Functions (unit) testing and monitoring
PDF
Workflow as code with Azure Durable Functions
PDF
Stateful pattern con Azure Functions
PDF
Stateful patterns in Azure Functions
PDF
Durable Functions vs Logic App : la guerra dei workflow!!
PDF
IoT in salsa Serverless
The art of Azure Functions (unit) testing and monitoring
Empower every Azure Function to achieve more!!
The art of Azure Functions (unit) testing and monitoring
Workflow as code with Azure Durable Functions
Stateful pattern con Azure Functions
Stateful patterns in Azure Functions
Durable Functions vs Logic App : la guerra dei workflow!!
IoT in salsa Serverless

What's hot (20)

PDF
Designing an effective hybrid apps automation framework
PDF
Tales of an open source library
PDF
Mobx Internals
PPTX
Spring boot
PPTX
Visualforce remoteobject
PPTX
Progressive Web App Testing With Cypress.io
PPTX
End to end test automation with cypress
PPTX
What is Spring Boot and Why Spring Boot ?
PPTX
Why I am hooked on the future of React
PDF
Cypress - Best Practices
PPTX
Automated Testing for Websites With Selenium IDE
PPTX
Leveraging Azure for Performance Testing
PDF
Microservices with Spring Boot Tutorial | Edureka
PDF
Xmas Serverless Transformation: when the elf doesn’t scale!
PPTX
Angular Unit Testing
PPTX
Windows Azure Acid Test
PPTX
Introduction to Integration Testing With Cypress
PPTX
Fullstack workshop
PPTX
Protractor overview
PDF
KKBOX WWDC17 Performance and Testing - Hokila
Designing an effective hybrid apps automation framework
Tales of an open source library
Mobx Internals
Spring boot
Visualforce remoteobject
Progressive Web App Testing With Cypress.io
End to end test automation with cypress
What is Spring Boot and Why Spring Boot ?
Why I am hooked on the future of React
Cypress - Best Practices
Automated Testing for Websites With Selenium IDE
Leveraging Azure for Performance Testing
Microservices with Spring Boot Tutorial | Edureka
Xmas Serverless Transformation: when the elf doesn’t scale!
Angular Unit Testing
Windows Azure Acid Test
Introduction to Integration Testing With Cypress
Fullstack workshop
Protractor overview
KKBOX WWDC17 Performance and Testing - Hokila
Ad

Similar to Testing a Service Fabric solution and live happy!! (20)

PPTX
Building strong foundations apex enterprise patterns
PPTX
GemFire In-Memory Data Grid
PPTX
Azure development
PPTX
Oracle appsloadtestbestpractices
PDF
Kubernetes & Co, beyond the hype
DOC
E catt tutorial
PDF
How to upgrade to MongoDB 4.0 - Percona Europe 2018
PPTX
GemFire In Memory Data Grid
PPT
Muves3 Elastic Grid Java One2009 Final
PPTX
Architecting .NET solutions in a Docker ecosystem - .NET Fest Kyiv 2019
PPTX
Coldbox developer training – session 4
PDF
Architecture Patterns with Python 1st Edition Harry Percival
PPTX
Aws meetup systems_manager
PPTX
patchVantage Cloud Starter Pack
PDF
Instant download Architecture Patterns with Python 1st Edition Harry Percival...
PPTX
Tips for Developing and Testing IBM HATS Applications
PDF
Infrastructure as code managing servers in the cloud Morris
PDF
Infrastructure as code managing servers in the cloud Morris
PDF
API Performance testing with Gatling
PPTX
Windows 2012 R2 Multi Server Management
Building strong foundations apex enterprise patterns
GemFire In-Memory Data Grid
Azure development
Oracle appsloadtestbestpractices
Kubernetes & Co, beyond the hype
E catt tutorial
How to upgrade to MongoDB 4.0 - Percona Europe 2018
GemFire In Memory Data Grid
Muves3 Elastic Grid Java One2009 Final
Architecting .NET solutions in a Docker ecosystem - .NET Fest Kyiv 2019
Coldbox developer training – session 4
Architecture Patterns with Python 1st Edition Harry Percival
Aws meetup systems_manager
patchVantage Cloud Starter Pack
Instant download Architecture Patterns with Python 1st Edition Harry Percival...
Tips for Developing and Testing IBM HATS Applications
Infrastructure as code managing servers in the cloud Morris
Infrastructure as code managing servers in the cloud Morris
API Performance testing with Gatling
Windows 2012 R2 Multi Server Management
Ad

More from Massimo Bonanni (20)

PDF
Architetture Serverless con SQL Server e Azure Functions
PDF
IoT in salsa serverless
PDF
Tutto quello che avreste voluto sapere sull'API Management (e non avete mai o...
PDF
Empower every Azure Function to achieve more!!
PDF
Everything you always wanted to know about API Management (but were afraid to...
PPTX
Welcome Azure Functions 2. 0
PPTX
Discovering the Service Fabric's actor model
PPTX
Discovering the Service Fabric's actor model
PPTX
Soluzioni IoT con le tecnologie Microsoft
PPTX
Project Gesture & Real Sense: il potere nelle mani!!
PPTX
Project Gesture & RealSense: gestures in a simple way!!
PPTX
Project Prague & RealSense: il potere nelle mani!!
PPTX
L'approccio ai microservizi secondo Service Fabric
PPTX
The Microservices world in. NET Core and. NET framework
PPTX
Microservices architecture & Service Fabric
PPTX
Introduzione allo sviluppo UWP per xBox
PPTX
Cognitive Services & LUIS
PPTX
Service Fabric: la potenza dei micro servizi
PPTX
Automated UI testing for iOs and Android mobile apps
PPTX
Soluzioni IoT con le tecnologie Microsoft
Architetture Serverless con SQL Server e Azure Functions
IoT in salsa serverless
Tutto quello che avreste voluto sapere sull'API Management (e non avete mai o...
Empower every Azure Function to achieve more!!
Everything you always wanted to know about API Management (but were afraid to...
Welcome Azure Functions 2. 0
Discovering the Service Fabric's actor model
Discovering the Service Fabric's actor model
Soluzioni IoT con le tecnologie Microsoft
Project Gesture & Real Sense: il potere nelle mani!!
Project Gesture & RealSense: gestures in a simple way!!
Project Prague & RealSense: il potere nelle mani!!
L'approccio ai microservizi secondo Service Fabric
The Microservices world in. NET Core and. NET framework
Microservices architecture & Service Fabric
Introduzione allo sviluppo UWP per xBox
Cognitive Services & LUIS
Service Fabric: la potenza dei micro servizi
Automated UI testing for iOs and Android mobile apps
Soluzioni IoT con le tecnologie Microsoft

Recently uploaded (20)

PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Approach and Philosophy of On baking technology
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
KodekX | Application Modernization Development
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Encapsulation_ Review paper, used for researhc scholars
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PPTX
Big Data Technologies - Introduction.pptx
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Empathic Computing: Creating Shared Understanding
PDF
Machine learning based COVID-19 study performance prediction
PDF
Encapsulation theory and applications.pdf
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
20250228 LYD VKU AI Blended-Learning.pptx
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Approach and Philosophy of On baking technology
Diabetes mellitus diagnosis method based random forest with bat algorithm
KodekX | Application Modernization Development
Digital-Transformation-Roadmap-for-Companies.pptx
Encapsulation_ Review paper, used for researhc scholars
“AI and Expert System Decision Support & Business Intelligence Systems”
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
NewMind AI Weekly Chronicles - August'25 Week I
Dropbox Q2 2025 Financial Results & Investor Presentation
Big Data Technologies - Introduction.pptx
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Empathic Computing: Creating Shared Understanding
Machine learning based COVID-19 study performance prediction
Encapsulation theory and applications.pdf
Understanding_Digital_Forensics_Presentation.pptx
Advanced methodologies resolving dimensionality complications for autism neur...

Testing a Service Fabric solution and live happy!!

  • 1. 1 Testing a Service Fabric solution and live happy!!! Massimo Bonanni Paranormal Developer, with the head in the Cloud and all the REST in microservices! @massimobonanni massimo.bonanni@microsoft.com
  • 5. 5
  • 6. 6
  • 8. 8 Programming Models Dev & Ops Tooling Orchestration Lifecycle Management Health & Monitoring Always On Availability Auto Scaling AzureOn-premises infrastructureAny cloudDev machine Service Fabric: Microservices platform ExecutablesReliable Services (.NET, Java) Reliable Actors (.NET, Java)ASP.NET Core Containers
  • 9. 9 F5 is our friend…. It is the most used test tools It's free and you can find it in all Visual Studio versions You don’t have to write any additional code
  • 10. 10 F5 is not useful …. with Service Fabric Resources – you need a local cluster Time – you need to publish the app Code complete – you need all the microservices you interact with
  • 11. 11 Why unit test… A unit test is an automated piece of code that invokes a unit of work in the system and then checks a single assumption about the behavior of that unit of work. Roy Osherove – The Art Of Unit Testing Microservices are small, perform single functionality and loosely coupled. Microservices Architecture
  • 12. 12 Why unit test… A unit test is an automated piece of code that invokes a unit of work in the system and then checks a single assumption about the behavior of that unit of work. Roy Osherove – The Art Of Unit Testing Microservices are small, perform single functionality and loosely coupled. Microservices Architecture A microservice is your Unit of Work to test!!!
  • 13. 13 The three obstacles Your µService Service Fabric Platform Replicas Partitioning State Management…… File System Database Web Service External Components Others µServices
  • 14. 14 Real case: Shopping Cart & Order We model 3 typical shopping cart scenarios • The cart can be created only if it is a new cart Creating the shopping cart • Need to check if the product is still available Adding a product to the cart • The order is created starting from the cart and only if the order is new Creating an order from the cart
  • 15. 15 Scenario : Creating the shopping cart We must "replace" the Service Fabric platform, so our tests doesn’t need the cluster. Service Fabric Platform Replicas Partitioning State Management ……
  • 16. 16 Scenario : Creating the shopping cart this.StateManager.TryGetStateAsync<State>(StateKeyName, cancellationToken); this.StateManager.SetStateAsync(StateKeyName, state, cancellationToken); this.RegisterReminderAsync(ExpiredReminderName, null, CartExpiredTimeout, TimeSpan.FromMilliseconds(-1));
  • 17. 17 Scenario : Adding a product to the cart We need to decouple our microservice from external components, so that our tests can verify only the actor's logic. File System Database Web Service External Components
  • 18. 18 Scenario : Adding a product to the cart private async Task<ProductData> GetProductFromStorageAsync(string productId, double quantity, CancellationToken cancellationToken) { ProductData result = null; try { using (SqlConnection conn = new SqlConnection(connectionString)) using (SqlCommand cmd = new SqlCommand("CheckProduct", conn)) { // Database code } } catch { result = null; } return result; }
  • 19. 19 Scenario : Creating an order from the cart We must to replace the static classes ActorProxy and ServiceProxy used in the creation of communication proxies. Others µServices
  • 20. 20 Scenario : Creating an order from the cart var orderProxy = ActorProxy.Create<IOrderActor>(this.Id, new Uri("fabric:/TestingApp/OrderActor"));
  • 22. 22 The three obstacles….three solutions! Your µService Service Fabric Platform Replicas Partitioning State Management …… File System Database Web Service External Components Others µServices Mock the platform (ServiceFabric.Mocks) Abstract the proxy factories Create a layer of indirection
  • 24. 24 Keep the stability!!!! Solutions based on distributed architectures such as cloud infrastructures must be: This is why you need to be able to test the stability of your solutions when complex state transitions due to errors occur in the underlying infrastructure. •able to withstand or recover quickly from difficult conditionsResilient • its status does not get corrupted as a result of a problemReliable
  • 25. 25 What can go wrong in production? Restarting a node Restarting a distributed code package Removing a replica Restarting a replica Moving a primary replica Moving a secondary replica Remove a node Add a node
  • 26. 26
  • 27. 27 Start-ServiceFabricChaos Chaos induces faults in the cluster based on the received input parameters. Chaos runs in multiple iterations: each iteration consists of faults and cluster validation. You can control: • how long Chaos runs, • how long it waits between iterations, • how many faults it can induce during an iteration, • how long it waits between faults. • ….
  • 29. 29 Take away…. Keep the microservices simple….they will be testability simply! When design a solution, keep in mind the testability! Mock, fake and shim are your best friends! If car companies launch expensive cars against a wall to test them, why should not you do it with your code?