SlideShare a Scribd company logo
AKKA UNIT TESTING
HITCHHIKER GUID TO
HITCHHIKER GUID TO AKKA TESTING
ABOUT ME
▸ Aprox 7 year hands on with scala & akka
▸ Part of Indeni team
▸ mailto: 123avi@gmail.com
▸ 052-3459959
HITCHHIKER GUID TO AKKA TESTING
WHAT WILL BE COVERED
▸ Akka basics
▸ Settings (sbt)
▸ Simple actors app
▸ Actor messages testing
▸ UnderlyingActor
▸ Supervision testing
HITCHHIKER GUID TO AKKA TESTING
THE ACTOR-MESSAGING CONCEPT IS NOT NEW
▸ Formalized in 1973 by Carl Hewitt and refined by Gul
Agha in mid 80s.
▸ The first major adoption is done by Ericsson in mid 80s.
▸ Invented Erlang and later open-sourced in 90s.
▸ Built a distributed, concurrent, and fault-tolerant telcom
system which has 99.9999999% uptime
HITCHHIKER GUID TO AKKA TESTING
WHAT IS AKKA FRAMEWORK - TACHLES
▸ Event driving, messaging
style, concurrent, fault-tolerant
▸ Provides higher abstraction for
concurrency and parallelism
▸ No shared state
▸ Messages are kept in mailbox
and processed in order
▸ Massive scalable and lighting
fast because of the small call
stack.
HITCHHIKER GUID TO AKKA TESTING
SETTINGS - BUILD.SBT
▸ Dependencies
libraryDependencies ++= Seq(
"com.typesafe.akka" %% "akka-actor" % "2.4.8",
"com.typesafe.akka" %% "akka-testkit" % "2.4.8" % "test",
"org.scalatest" %% "scalatest" % "2.2.5" % "test"
)
HITCHHIKER GUID TO AKKA TESTING
AKKA TESTKIT
▸ Library to simplify unit tests on actors
▸ Can be extended by your test class
▸ Inheriting from this trait enables reception of replies from
actors, which are queued by an internal actor and can be
examined using the expectMsg... methods. Assertions and
bounds concerning timing are available in the form of
within blocks.
HITCHHIKER GUID TO AKKA TESTING
TEST EVERYTHING
HITCHHIKER GUID TO AKKA TESTING
MIXING IMPLICIT SENDER
▸ Use implicit sender to get “sender” replies
def receive {
case _ => sender ! “hi
}
class FooActorSpec extends TestKit(ActorSystem("MySpec")) with ImplicitSender
foo ! “do something”
expectMsg(“hi”)
//without implicit sender
foo tell( “do something”, self)
expectMsg(“hi”)
HITCHHIKER GUID TO AKKA TESTING
TESTACTORREF
▸ TestActorRef - a special reference that comes with the
Akka TestKit.
▸ TestActorRef allows interaction with internal actor if
needed via .underlyingActor
▸ obtain reference to the actor
val actorRef = TestActorRef[MyActor]
val actor = actorRef.underlyingActor
actorRef.underlyingActor.someInner
HITCHHIKER GUID TO AKKA TESTING
STICK TO BEHAVIOURAL TESTING
▸ Use messages.
▸ Single responsibility principle.
▸ Use probes
▸ make your tests readable and clear
HITCHHIKER GUID TO AKKA TESTING
DEMO TIME
HITCHHIKER GUID TO AKKA TESTING
USE BUILT IN ASSERTIONS
▸ Expecting messages
▸ Fishing for messages
def expectMsg[T](d: Duration, msg: T): T
def expectMsgPF[T](d: Duration) (pf: PartialFunction[Any, T]): T
def expectNoMsg(d: Duration) // blocks
def receiveN(n: Int, d: Duration): Seq[AnyRef]
def receiveWhile[T](max: Duration, idle: Duration, n: Int) (pf: PartialFunction[Any, T]): Seq[T]
def fishForMessage(max: Duration, hint: String) (pf: PartialFunction[Any, Boolean]): Any
HITCHHIKER GUID TO AKKA TESTING
BUILT IN ASSERTIONS
▸ Waiting
▸ Death watching
def awaitCond(p: => Boolean, max: Duration, interval: Duration)
def eventually[T](fun: => T) (implicit config: PatienceConfig): T //not part of testkit
val probe = TestProbe()
probe watch target
target ! PoisonPill
probe.expectTerminated(target)
HITCHHIKER GUID TO AKKA TESTING
MORE BUILT IN ASSERTIONS …
expectMsg[T](d: Duration, msg: T): T
expectMsgPF[T](d: Duration)(pf: PartialFunction[Any, T]): T
expectMsgClass[T](d: Duration, c: Class[T]): T
expectMsgType[T: Manifest](d: Duration)
expectMsgAnyOf[T](d: Duration, obj: T*): T
expectMsgAnyClassOf[T](d: Duration, obj: Class[_ <: T]*): T
expectMsgAllOf[T](d: Duration, obj: T*): Seq[T]
expectMsgAllClassOf[T](d: Duration, c: Class[_ <: T]*): Seq[T]
expectMsgAllConformingOf[T](d: Duration, c: Class[_ <: T]*): Seq[T]
expectNoMsg(d: Duration)
receiveN(n: Int, d: Duration): Seq[AnyRef]
fishForMessage(max: Duration, hint: String)(pf: PartialFunction[Any, Boolean]): Any
receiveOne(d: Duration): AnyRef
receiveWhile[T](max: Duration, idle: Duration, messages: Int)
HITCHHIKER GUID TO AKKA TESTING
FURTHER READING
▸ Scala test - select your flavor
▸ Testing Actor System
▸ Injecting test probe for child actors
▸ Unit testing akka actors with testkit
▸ ScalaCheck user guide
▸ ScalaCheck examples
▸ Mocks are not Stubs
▸ Akka docs - multi-node-testing

More Related Content

What's hot

Kubernetes: Beyond Baby Steps
Kubernetes: Beyond Baby StepsKubernetes: Beyond Baby Steps
Kubernetes: Beyond Baby Steps
DigitalOcean
 
Helm intro
Helm introHelm intro
More tips and tricks for running containers like a pro - Rancher Online MEetu...
More tips and tricks for running containers like a pro - Rancher Online MEetu...More tips and tricks for running containers like a pro - Rancher Online MEetu...
More tips and tricks for running containers like a pro - Rancher Online MEetu...
Shannon Williams
 
SDN applications with floodlight
SDN applications with floodlightSDN applications with floodlight
SDN applications with floodlight
Damascus University
 
Tacker vancouver project update
Tacker vancouver project updateTacker vancouver project update
Tacker vancouver project update
Robin Gong
 
Tacker vancouver project onboarding new
Tacker vancouver project onboarding newTacker vancouver project onboarding new
Tacker vancouver project onboarding new
Robin Gong
 
Whatthestack using Tempest for testing your OpenStack deployment
Whatthestack using Tempest for testing your OpenStack deploymentWhatthestack using Tempest for testing your OpenStack deployment
Whatthestack using Tempest for testing your OpenStack deploymentChristian Schwede
 
Need to make a horizontal change across 100+ microservices? No worries, Sheph...
Need to make a horizontal change across 100+ microservices? No worries, Sheph...Need to make a horizontal change across 100+ microservices? No worries, Sheph...
Need to make a horizontal change across 100+ microservices? No worries, Sheph...
Aori Nevo, PhD
 
Circuit breakers - Using Spring-Boot + Hystrix + Dashboard + Retry
Circuit breakers - Using Spring-Boot + Hystrix + Dashboard + RetryCircuit breakers - Using Spring-Boot + Hystrix + Dashboard + Retry
Circuit breakers - Using Spring-Boot + Hystrix + Dashboard + Retry
Bruno Henrique Rother
 
How to build your own auto-remediation workflow - Ansible Meetup Munich
How to build your own auto-remediation workflow - Ansible Meetup MunichHow to build your own auto-remediation workflow - Ansible Meetup Munich
How to build your own auto-remediation workflow - Ansible Meetup Munich
Jürgen Etzlstorfer
 
Self-healing Applications with Ansible
Self-healing Applications with AnsibleSelf-healing Applications with Ansible
Self-healing Applications with Ansible
Jürgen Etzlstorfer
 
Building Autonomous Operations for Kubernetes with keptn
Building Autonomous Operations for Kubernetes with keptnBuilding Autonomous Operations for Kubernetes with keptn
Building Autonomous Operations for Kubernetes with keptn
Johannes Bräuer
 
Monitoring as Code: Getting to Monitoring-Driven Development - DEV314 - re:In...
Monitoring as Code: Getting to Monitoring-Driven Development - DEV314 - re:In...Monitoring as Code: Getting to Monitoring-Driven Development - DEV314 - re:In...
Monitoring as Code: Getting to Monitoring-Driven Development - DEV314 - re:In...
Amazon Web Services
 
Sparklens: Understanding the Scalability Limits of Spark Applications with R...
 Sparklens: Understanding the Scalability Limits of Spark Applications with R... Sparklens: Understanding the Scalability Limits of Spark Applications with R...
Sparklens: Understanding the Scalability Limits of Spark Applications with R...
Databricks
 
10 ways to shoot yourself in the foot with kubernetes, #9 will surprise you! ...
10 ways to shoot yourself in the foot with kubernetes, #9 will surprise you! ...10 ways to shoot yourself in the foot with kubernetes, #9 will surprise you! ...
10 ways to shoot yourself in the foot with kubernetes, #9 will surprise you! ...
Laurent Bernaille
 
Boxen: How to Manage an Army of Laptops
Boxen: How to Manage an Army of LaptopsBoxen: How to Manage an Army of Laptops
Boxen: How to Manage an Army of Laptops
Puppet
 
Deploying Containers with Rancher
Deploying Containers with RancherDeploying Containers with Rancher
Deploying Containers with Rancher
Chris Tankersley
 
Networking basics EIGRP
Networking basics EIGRPNetworking basics EIGRP
Networking basics EIGRP
Hassan Tariq
 
Kubernetes service with ha
Kubernetes service with haKubernetes service with ha
Kubernetes service with ha
Sam Zheng
 
Introducing Project Longhorn - April 2016 Rancher Online Meetup
Introducing Project Longhorn - April 2016 Rancher Online MeetupIntroducing Project Longhorn - April 2016 Rancher Online Meetup
Introducing Project Longhorn - April 2016 Rancher Online Meetup
Shannon Williams
 

What's hot (20)

Kubernetes: Beyond Baby Steps
Kubernetes: Beyond Baby StepsKubernetes: Beyond Baby Steps
Kubernetes: Beyond Baby Steps
 
Helm intro
Helm introHelm intro
Helm intro
 
More tips and tricks for running containers like a pro - Rancher Online MEetu...
More tips and tricks for running containers like a pro - Rancher Online MEetu...More tips and tricks for running containers like a pro - Rancher Online MEetu...
More tips and tricks for running containers like a pro - Rancher Online MEetu...
 
SDN applications with floodlight
SDN applications with floodlightSDN applications with floodlight
SDN applications with floodlight
 
Tacker vancouver project update
Tacker vancouver project updateTacker vancouver project update
Tacker vancouver project update
 
Tacker vancouver project onboarding new
Tacker vancouver project onboarding newTacker vancouver project onboarding new
Tacker vancouver project onboarding new
 
Whatthestack using Tempest for testing your OpenStack deployment
Whatthestack using Tempest for testing your OpenStack deploymentWhatthestack using Tempest for testing your OpenStack deployment
Whatthestack using Tempest for testing your OpenStack deployment
 
Need to make a horizontal change across 100+ microservices? No worries, Sheph...
Need to make a horizontal change across 100+ microservices? No worries, Sheph...Need to make a horizontal change across 100+ microservices? No worries, Sheph...
Need to make a horizontal change across 100+ microservices? No worries, Sheph...
 
Circuit breakers - Using Spring-Boot + Hystrix + Dashboard + Retry
Circuit breakers - Using Spring-Boot + Hystrix + Dashboard + RetryCircuit breakers - Using Spring-Boot + Hystrix + Dashboard + Retry
Circuit breakers - Using Spring-Boot + Hystrix + Dashboard + Retry
 
How to build your own auto-remediation workflow - Ansible Meetup Munich
How to build your own auto-remediation workflow - Ansible Meetup MunichHow to build your own auto-remediation workflow - Ansible Meetup Munich
How to build your own auto-remediation workflow - Ansible Meetup Munich
 
Self-healing Applications with Ansible
Self-healing Applications with AnsibleSelf-healing Applications with Ansible
Self-healing Applications with Ansible
 
Building Autonomous Operations for Kubernetes with keptn
Building Autonomous Operations for Kubernetes with keptnBuilding Autonomous Operations for Kubernetes with keptn
Building Autonomous Operations for Kubernetes with keptn
 
Monitoring as Code: Getting to Monitoring-Driven Development - DEV314 - re:In...
Monitoring as Code: Getting to Monitoring-Driven Development - DEV314 - re:In...Monitoring as Code: Getting to Monitoring-Driven Development - DEV314 - re:In...
Monitoring as Code: Getting to Monitoring-Driven Development - DEV314 - re:In...
 
Sparklens: Understanding the Scalability Limits of Spark Applications with R...
 Sparklens: Understanding the Scalability Limits of Spark Applications with R... Sparklens: Understanding the Scalability Limits of Spark Applications with R...
Sparklens: Understanding the Scalability Limits of Spark Applications with R...
 
10 ways to shoot yourself in the foot with kubernetes, #9 will surprise you! ...
10 ways to shoot yourself in the foot with kubernetes, #9 will surprise you! ...10 ways to shoot yourself in the foot with kubernetes, #9 will surprise you! ...
10 ways to shoot yourself in the foot with kubernetes, #9 will surprise you! ...
 
Boxen: How to Manage an Army of Laptops
Boxen: How to Manage an Army of LaptopsBoxen: How to Manage an Army of Laptops
Boxen: How to Manage an Army of Laptops
 
Deploying Containers with Rancher
Deploying Containers with RancherDeploying Containers with Rancher
Deploying Containers with Rancher
 
Networking basics EIGRP
Networking basics EIGRPNetworking basics EIGRP
Networking basics EIGRP
 
Kubernetes service with ha
Kubernetes service with haKubernetes service with ha
Kubernetes service with ha
 
Introducing Project Longhorn - April 2016 Rancher Online Meetup
Introducing Project Longhorn - April 2016 Rancher Online MeetupIntroducing Project Longhorn - April 2016 Rancher Online Meetup
Introducing Project Longhorn - April 2016 Rancher Online Meetup
 

Viewers also liked

Leptospirosis
LeptospirosisLeptospirosis
Leptospirosis
Dej8vu
 
I C N B J R A Biodiversidade1
I C N B  J R A  Biodiversidade1I C N B  J R A  Biodiversidade1
I C N B J R A Biodiversidade1
SGC
 
Group2 part7-opportunity map
Group2 part7-opportunity mapGroup2 part7-opportunity map
Group2 part7-opportunity mapAidenn Mullen
 
fertilizantesFertilizantes
fertilizantesFertilizantesfertilizantesFertilizantes
fertilizantesFertilizantes
prefeitura municipal de logradouro
 
Alaric Compliance
Alaric ComplianceAlaric Compliance
Alaric Compliancechardyl
 
Itapua tripes cavalleri
Itapua tripes cavalleriItapua tripes cavalleri
Itapua tripes cavalleri
avisaassociacao
 
Brasil resumcat
Brasil resumcatBrasil resumcat
Brasil resumcatytrivino
 
Zani et al 2012
Zani et al 2012Zani et al 2012
Zani et al 2012
Valderes Sarnaglia
 
Ancient Greece
Ancient GreeceAncient Greece
Ancient Greeceyapsmail
 
Bagbani gardening hb
Bagbani gardening hbBagbani gardening hb
Bagbani gardening hb
Satish Bhandari
 
Guia de fons de l'Arxiu de Terrassa (2013)
Guia de fons de l'Arxiu de Terrassa (2013)Guia de fons de l'Arxiu de Terrassa (2013)
Guia de fons de l'Arxiu de Terrassa (2013)
ArxiudeTerrassa12
 
Accidentes_aracnidos
Accidentes_aracnidosAccidentes_aracnidos
Accidentes_aracnidos
David Mauricio Ossa R.
 
Bondia.cat 28/02/2013
Bondia.cat 28/02/2013Bondia.cat 28/02/2013
Bondia.cat 28/02/2013
Bondia Lleida Sl
 
Bondia Lleida 19072011
Bondia Lleida 19072011Bondia Lleida 19072011
Bondia Lleida 19072011
Bondia Lleida Sl
 

Viewers also liked (20)

Leptospirosis
LeptospirosisLeptospirosis
Leptospirosis
 
Adonai ufal
Adonai ufalAdonai ufal
Adonai ufal
 
1860-6616-1-PB
1860-6616-1-PB1860-6616-1-PB
1860-6616-1-PB
 
I C N B J R A Biodiversidade1
I C N B  J R A  Biodiversidade1I C N B  J R A  Biodiversidade1
I C N B J R A Biodiversidade1
 
Group2 part7-opportunity map
Group2 part7-opportunity mapGroup2 part7-opportunity map
Group2 part7-opportunity map
 
fertilizantesFertilizantes
fertilizantesFertilizantesfertilizantesFertilizantes
fertilizantesFertilizantes
 
Alaric Compliance
Alaric ComplianceAlaric Compliance
Alaric Compliance
 
Mini ngl law (1) mini dicionário
Mini ngl law (1) mini dicionárioMini ngl law (1) mini dicionário
Mini ngl law (1) mini dicionário
 
Itapua tripes cavalleri
Itapua tripes cavalleriItapua tripes cavalleri
Itapua tripes cavalleri
 
Brasil resumcat
Brasil resumcatBrasil resumcat
Brasil resumcat
 
Zani et al 2012
Zani et al 2012Zani et al 2012
Zani et al 2012
 
Adlerian theraphy
Adlerian theraphyAdlerian theraphy
Adlerian theraphy
 
Ancient Greece
Ancient GreeceAncient Greece
Ancient Greece
 
1891 05
1891 051891 05
1891 05
 
Bagbani gardening hb
Bagbani gardening hbBagbani gardening hb
Bagbani gardening hb
 
Guia de fons de l'Arxiu de Terrassa (2013)
Guia de fons de l'Arxiu de Terrassa (2013)Guia de fons de l'Arxiu de Terrassa (2013)
Guia de fons de l'Arxiu de Terrassa (2013)
 
Accidentes_aracnidos
Accidentes_aracnidosAccidentes_aracnidos
Accidentes_aracnidos
 
Alans
AlansAlans
Alans
 
Bondia.cat 28/02/2013
Bondia.cat 28/02/2013Bondia.cat 28/02/2013
Bondia.cat 28/02/2013
 
Bondia Lleida 19072011
Bondia Lleida 19072011Bondia Lleida 19072011
Bondia Lleida 19072011
 

Similar to Akka testing

Stress Test & Chaos Engineering
Stress Test & Chaos EngineeringStress Test & Chaos Engineering
Stress Test & Chaos Engineering
Diego Pacheco
 
[FullStack NYC 2019] Effective Unit Tests for JavaScript
[FullStack NYC 2019] Effective Unit Tests for JavaScript[FullStack NYC 2019] Effective Unit Tests for JavaScript
[FullStack NYC 2019] Effective Unit Tests for JavaScript
Hazem Saleh
 
Canary deployment with Traefik and K3S
Canary deployment with Traefik and K3SCanary deployment with Traefik and K3S
Canary deployment with Traefik and K3S
Jakub Hajek
 
Testing as a container
Testing as a containerTesting as a container
Testing as a container
Irfan Ahmad
 
Scala test
Scala testScala test
AppSec California 2016 - Making Security Agile
AppSec California 2016 - Making Security AgileAppSec California 2016 - Making Security Agile
AppSec California 2016 - Making Security Agile
Oleg Gryb
 
Troubleshooting tips from docker support engineers
Troubleshooting tips from docker support engineersTroubleshooting tips from docker support engineers
Troubleshooting tips from docker support engineers
Docker, Inc.
 
OpenStack QA Tooling & How to use it for Production Cloud Testing | Ghanshyam...
OpenStack QA Tooling & How to use it for Production Cloud Testing | Ghanshyam...OpenStack QA Tooling & How to use it for Production Cloud Testing | Ghanshyam...
OpenStack QA Tooling & How to use it for Production Cloud Testing | Ghanshyam...
Vietnam Open Infrastructure User Group
 
Testing 101
Testing 101Testing 101
Testing 101
Elango Balusamy
 
Akka london scala_user_group
Akka london scala_user_groupAkka london scala_user_group
Akka london scala_user_groupSkills Matter
 
Parallelizing CI using Docker Swarm-Mode
Parallelizing CI using Docker Swarm-ModeParallelizing CI using Docker Swarm-Mode
Parallelizing CI using Docker Swarm-Mode
Akihiro Suda
 
Tempest scenariotests 20140512
Tempest scenariotests 20140512Tempest scenariotests 20140512
Tempest scenariotests 20140512Masayuki Igawa
 
Async Messaging in CQRS: Part 2 - Akka.NET
Async Messaging in CQRS: Part 2 - Akka.NETAsync Messaging in CQRS: Part 2 - Akka.NET
Async Messaging in CQRS: Part 2 - Akka.NET
George Tourkas
 
Do's and don'ts when deploying akka in production
Do's and don'ts when deploying akka in productionDo's and don'ts when deploying akka in production
Do's and don'ts when deploying akka in production
jglobal
 
SystemVerilog Assertion.pptx
SystemVerilog Assertion.pptxSystemVerilog Assertion.pptx
SystemVerilog Assertion.pptx
Nothing!
 
Discovering exoplanets with Deep Leaning
Discovering exoplanets with Deep LeaningDiscovering exoplanets with Deep Leaning
Discovering exoplanets with Deep Leaning
Rafael Arana
 
Test-Driven Infrastructure with Puppet, Test Kitchen, Serverspec and RSpec
Test-Driven Infrastructure with Puppet, Test Kitchen, Serverspec and RSpecTest-Driven Infrastructure with Puppet, Test Kitchen, Serverspec and RSpec
Test-Driven Infrastructure with Puppet, Test Kitchen, Serverspec and RSpec
Martin Etmajer
 
Resilience Testing
Resilience Testing Resilience Testing
Resilience Testing
Ran Levy
 
LPW 2007 - Perl Plumbing
LPW 2007 - Perl PlumbingLPW 2007 - Perl Plumbing
LPW 2007 - Perl Plumbing
lokku
 

Similar to Akka testing (20)

Stress Test & Chaos Engineering
Stress Test & Chaos EngineeringStress Test & Chaos Engineering
Stress Test & Chaos Engineering
 
[FullStack NYC 2019] Effective Unit Tests for JavaScript
[FullStack NYC 2019] Effective Unit Tests for JavaScript[FullStack NYC 2019] Effective Unit Tests for JavaScript
[FullStack NYC 2019] Effective Unit Tests for JavaScript
 
Canary deployment with Traefik and K3S
Canary deployment with Traefik and K3SCanary deployment with Traefik and K3S
Canary deployment with Traefik and K3S
 
Testing as a container
Testing as a containerTesting as a container
Testing as a container
 
Scala test
Scala testScala test
Scala test
 
Scala test
Scala testScala test
Scala test
 
AppSec California 2016 - Making Security Agile
AppSec California 2016 - Making Security AgileAppSec California 2016 - Making Security Agile
AppSec California 2016 - Making Security Agile
 
Troubleshooting tips from docker support engineers
Troubleshooting tips from docker support engineersTroubleshooting tips from docker support engineers
Troubleshooting tips from docker support engineers
 
OpenStack QA Tooling & How to use it for Production Cloud Testing | Ghanshyam...
OpenStack QA Tooling & How to use it for Production Cloud Testing | Ghanshyam...OpenStack QA Tooling & How to use it for Production Cloud Testing | Ghanshyam...
OpenStack QA Tooling & How to use it for Production Cloud Testing | Ghanshyam...
 
Testing 101
Testing 101Testing 101
Testing 101
 
Akka london scala_user_group
Akka london scala_user_groupAkka london scala_user_group
Akka london scala_user_group
 
Parallelizing CI using Docker Swarm-Mode
Parallelizing CI using Docker Swarm-ModeParallelizing CI using Docker Swarm-Mode
Parallelizing CI using Docker Swarm-Mode
 
Tempest scenariotests 20140512
Tempest scenariotests 20140512Tempest scenariotests 20140512
Tempest scenariotests 20140512
 
Async Messaging in CQRS: Part 2 - Akka.NET
Async Messaging in CQRS: Part 2 - Akka.NETAsync Messaging in CQRS: Part 2 - Akka.NET
Async Messaging in CQRS: Part 2 - Akka.NET
 
Do's and don'ts when deploying akka in production
Do's and don'ts when deploying akka in productionDo's and don'ts when deploying akka in production
Do's and don'ts when deploying akka in production
 
SystemVerilog Assertion.pptx
SystemVerilog Assertion.pptxSystemVerilog Assertion.pptx
SystemVerilog Assertion.pptx
 
Discovering exoplanets with Deep Leaning
Discovering exoplanets with Deep LeaningDiscovering exoplanets with Deep Leaning
Discovering exoplanets with Deep Leaning
 
Test-Driven Infrastructure with Puppet, Test Kitchen, Serverspec and RSpec
Test-Driven Infrastructure with Puppet, Test Kitchen, Serverspec and RSpecTest-Driven Infrastructure with Puppet, Test Kitchen, Serverspec and RSpec
Test-Driven Infrastructure with Puppet, Test Kitchen, Serverspec and RSpec
 
Resilience Testing
Resilience Testing Resilience Testing
Resilience Testing
 
LPW 2007 - Perl Plumbing
LPW 2007 - Perl PlumbingLPW 2007 - Perl Plumbing
LPW 2007 - Perl Plumbing
 

Recently uploaded

Atelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissancesAtelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissances
Neo4j
 
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Mind IT Systems
 
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOMLORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
lorraineandreiamcidl
 
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing SuiteAI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
Google
 
openEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain SecurityopenEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain Security
Shane Coughlan
 
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptxTop Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
rickgrimesss22
 
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI AppAI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
Google
 
Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"
Donna Lenk
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
Paco van Beckhoven
 
Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604
Fermin Galan
 
Graspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code AnalysisGraspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code Analysis
Aftab Hussain
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
Adele Miller
 
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdfAutomated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
timtebeek1
 
APIs for Browser Automation (MoT Meetup 2024)
APIs for Browser Automation (MoT Meetup 2024)APIs for Browser Automation (MoT Meetup 2024)
APIs for Browser Automation (MoT Meetup 2024)
Boni García
 
Launch Your Streaming Platforms in Minutes
Launch Your Streaming Platforms in MinutesLaunch Your Streaming Platforms in Minutes
Launch Your Streaming Platforms in Minutes
Roshan Dwivedi
 
Fundamentals of Programming and Language Processors
Fundamentals of Programming and Language ProcessorsFundamentals of Programming and Language Processors
Fundamentals of Programming and Language Processors
Rakesh Kumar R
 
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdfVitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke
 
E-commerce Application Development Company.pdf
E-commerce Application Development Company.pdfE-commerce Application Development Company.pdf
E-commerce Application Development Company.pdf
Hornet Dynamics
 
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket ManagementUtilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate
 
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Łukasz Chruściel
 

Recently uploaded (20)

Atelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissancesAtelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissances
 
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
 
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOMLORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
 
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing SuiteAI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
 
openEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain SecurityopenEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain Security
 
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptxTop Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
 
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI AppAI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
 
Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
 
Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604
 
Graspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code AnalysisGraspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code Analysis
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
 
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdfAutomated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
 
APIs for Browser Automation (MoT Meetup 2024)
APIs for Browser Automation (MoT Meetup 2024)APIs for Browser Automation (MoT Meetup 2024)
APIs for Browser Automation (MoT Meetup 2024)
 
Launch Your Streaming Platforms in Minutes
Launch Your Streaming Platforms in MinutesLaunch Your Streaming Platforms in Minutes
Launch Your Streaming Platforms in Minutes
 
Fundamentals of Programming and Language Processors
Fundamentals of Programming and Language ProcessorsFundamentals of Programming and Language Processors
Fundamentals of Programming and Language Processors
 
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdfVitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdf
 
E-commerce Application Development Company.pdf
E-commerce Application Development Company.pdfE-commerce Application Development Company.pdf
E-commerce Application Development Company.pdf
 
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket ManagementUtilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
 
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
 

Akka testing

  • 2. HITCHHIKER GUID TO AKKA TESTING ABOUT ME ▸ Aprox 7 year hands on with scala & akka ▸ Part of Indeni team ▸ mailto: 123avi@gmail.com ▸ 052-3459959
  • 3. HITCHHIKER GUID TO AKKA TESTING WHAT WILL BE COVERED ▸ Akka basics ▸ Settings (sbt) ▸ Simple actors app ▸ Actor messages testing ▸ UnderlyingActor ▸ Supervision testing
  • 4. HITCHHIKER GUID TO AKKA TESTING THE ACTOR-MESSAGING CONCEPT IS NOT NEW ▸ Formalized in 1973 by Carl Hewitt and refined by Gul Agha in mid 80s. ▸ The first major adoption is done by Ericsson in mid 80s. ▸ Invented Erlang and later open-sourced in 90s. ▸ Built a distributed, concurrent, and fault-tolerant telcom system which has 99.9999999% uptime
  • 5. HITCHHIKER GUID TO AKKA TESTING WHAT IS AKKA FRAMEWORK - TACHLES ▸ Event driving, messaging style, concurrent, fault-tolerant ▸ Provides higher abstraction for concurrency and parallelism ▸ No shared state ▸ Messages are kept in mailbox and processed in order ▸ Massive scalable and lighting fast because of the small call stack.
  • 6. HITCHHIKER GUID TO AKKA TESTING SETTINGS - BUILD.SBT ▸ Dependencies libraryDependencies ++= Seq( "com.typesafe.akka" %% "akka-actor" % "2.4.8", "com.typesafe.akka" %% "akka-testkit" % "2.4.8" % "test", "org.scalatest" %% "scalatest" % "2.2.5" % "test" )
  • 7. HITCHHIKER GUID TO AKKA TESTING AKKA TESTKIT ▸ Library to simplify unit tests on actors ▸ Can be extended by your test class ▸ Inheriting from this trait enables reception of replies from actors, which are queued by an internal actor and can be examined using the expectMsg... methods. Assertions and bounds concerning timing are available in the form of within blocks.
  • 8. HITCHHIKER GUID TO AKKA TESTING TEST EVERYTHING
  • 9. HITCHHIKER GUID TO AKKA TESTING MIXING IMPLICIT SENDER ▸ Use implicit sender to get “sender” replies def receive { case _ => sender ! “hi } class FooActorSpec extends TestKit(ActorSystem("MySpec")) with ImplicitSender foo ! “do something” expectMsg(“hi”) //without implicit sender foo tell( “do something”, self) expectMsg(“hi”)
  • 10. HITCHHIKER GUID TO AKKA TESTING TESTACTORREF ▸ TestActorRef - a special reference that comes with the Akka TestKit. ▸ TestActorRef allows interaction with internal actor if needed via .underlyingActor ▸ obtain reference to the actor val actorRef = TestActorRef[MyActor] val actor = actorRef.underlyingActor actorRef.underlyingActor.someInner
  • 11. HITCHHIKER GUID TO AKKA TESTING STICK TO BEHAVIOURAL TESTING ▸ Use messages. ▸ Single responsibility principle. ▸ Use probes ▸ make your tests readable and clear
  • 12. HITCHHIKER GUID TO AKKA TESTING DEMO TIME
  • 13. HITCHHIKER GUID TO AKKA TESTING USE BUILT IN ASSERTIONS ▸ Expecting messages ▸ Fishing for messages def expectMsg[T](d: Duration, msg: T): T def expectMsgPF[T](d: Duration) (pf: PartialFunction[Any, T]): T def expectNoMsg(d: Duration) // blocks def receiveN(n: Int, d: Duration): Seq[AnyRef] def receiveWhile[T](max: Duration, idle: Duration, n: Int) (pf: PartialFunction[Any, T]): Seq[T] def fishForMessage(max: Duration, hint: String) (pf: PartialFunction[Any, Boolean]): Any
  • 14. HITCHHIKER GUID TO AKKA TESTING BUILT IN ASSERTIONS ▸ Waiting ▸ Death watching def awaitCond(p: => Boolean, max: Duration, interval: Duration) def eventually[T](fun: => T) (implicit config: PatienceConfig): T //not part of testkit val probe = TestProbe() probe watch target target ! PoisonPill probe.expectTerminated(target)
  • 15. HITCHHIKER GUID TO AKKA TESTING MORE BUILT IN ASSERTIONS … expectMsg[T](d: Duration, msg: T): T expectMsgPF[T](d: Duration)(pf: PartialFunction[Any, T]): T expectMsgClass[T](d: Duration, c: Class[T]): T expectMsgType[T: Manifest](d: Duration) expectMsgAnyOf[T](d: Duration, obj: T*): T expectMsgAnyClassOf[T](d: Duration, obj: Class[_ <: T]*): T expectMsgAllOf[T](d: Duration, obj: T*): Seq[T] expectMsgAllClassOf[T](d: Duration, c: Class[_ <: T]*): Seq[T] expectMsgAllConformingOf[T](d: Duration, c: Class[_ <: T]*): Seq[T] expectNoMsg(d: Duration) receiveN(n: Int, d: Duration): Seq[AnyRef] fishForMessage(max: Duration, hint: String)(pf: PartialFunction[Any, Boolean]): Any receiveOne(d: Duration): AnyRef receiveWhile[T](max: Duration, idle: Duration, messages: Int)
  • 16. HITCHHIKER GUID TO AKKA TESTING FURTHER READING ▸ Scala test - select your flavor ▸ Testing Actor System ▸ Injecting test probe for child actors ▸ Unit testing akka actors with testkit ▸ ScalaCheck user guide ▸ ScalaCheck examples ▸ Mocks are not Stubs ▸ Akka docs - multi-node-testing