SlideShare ist ein Scribd-Unternehmen logo
1 von 16
Downloaden Sie, um offline zu lesen
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

Weitere ähnliche Inhalte

Was ist angesagt?

Kubernetes: Beyond Baby Steps
Kubernetes: Beyond Baby StepsKubernetes: Beyond Baby Steps
Kubernetes: Beyond Baby StepsDigitalOcean
 
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 floodlightDamascus University
 
Tacker vancouver project update
Tacker vancouver project updateTacker vancouver project update
Tacker vancouver project updateRobin Gong
 
Tacker vancouver project onboarding new
Tacker vancouver project onboarding newTacker vancouver project onboarding new
Tacker vancouver project onboarding newRobin 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 + RetryBruno 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 MunichJürgen Etzlstorfer
 
Self-healing Applications with Ansible
Self-healing Applications with AnsibleSelf-healing Applications with Ansible
Self-healing Applications with AnsibleJü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 keptnJohannes 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 LaptopsPuppet
 
Deploying Containers with Rancher
Deploying Containers with RancherDeploying Containers with Rancher
Deploying Containers with RancherChris Tankersley
 
Networking basics EIGRP
Networking basics EIGRPNetworking basics EIGRP
Networking basics EIGRPHassan Tariq
 
Kubernetes service with ha
Kubernetes service with haKubernetes service with ha
Kubernetes service with haSam 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 MeetupShannon Williams
 

Was ist angesagt? (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
 

Andere mochten auch (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
 

Ähnlich wie Akka Unit Testing Guide: Learn How to Test Actors with the Akka TestKit

Stress Test & Chaos Engineering
Stress Test & Chaos EngineeringStress Test & Chaos Engineering
Stress Test & Chaos EngineeringDiego 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 JavaScriptHazem Saleh
 
Canary deployment with Traefik and K3S
Canary deployment with Traefik and K3SCanary deployment with Traefik and K3S
Canary deployment with Traefik and K3SJakub Hajek
 
Testing as a container
Testing as a containerTesting as a container
Testing as a containerIrfan Ahmad
 
AppSec California 2016 - Making Security Agile
AppSec California 2016 - Making Security AgileAppSec California 2016 - Making Security Agile
AppSec California 2016 - Making Security AgileOleg Gryb
 
Troubleshooting tips from docker support engineers
Troubleshooting tips from docker support engineersTroubleshooting tips from docker support engineers
Troubleshooting tips from docker support engineersDocker, 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
 
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-ModeAkihiro 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.NETGeorge 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 productionjglobal
 
SystemVerilog Assertion.pptx
SystemVerilog Assertion.pptxSystemVerilog Assertion.pptx
SystemVerilog Assertion.pptxNothing!
 
Discovering exoplanets with Deep Leaning
Discovering exoplanets with Deep LeaningDiscovering exoplanets with Deep Leaning
Discovering exoplanets with Deep LeaningRafael 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 RSpecMartin 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 Plumbinglokku
 

Ähnlich wie Akka Unit Testing Guide: Learn How to Test Actors with the Akka TestKit (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
 

Kürzlich hochgeladen

Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Cizo Technology Services
 
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odishasmiwainfosol
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationBradBedford3
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Velvetech LLC
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanyChristoph Pohl
 
PREDICTING RIVER WATER QUALITY ppt presentation
PREDICTING  RIVER  WATER QUALITY  ppt presentationPREDICTING  RIVER  WATER QUALITY  ppt presentation
PREDICTING RIVER WATER QUALITY ppt presentationvaddepallysandeep122
 
Best Web Development Agency- Idiosys USA.pdf
Best Web Development Agency- Idiosys USA.pdfBest Web Development Agency- Idiosys USA.pdf
Best Web Development Agency- Idiosys USA.pdfIdiosysTechnologies1
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Hr365.us smith
 
How to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdfHow to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdfLivetecs LLC
 
Cyber security and its impact on E commerce
Cyber security and its impact on E commerceCyber security and its impact on E commerce
Cyber security and its impact on E commercemanigoyal112
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxTier1 app
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作qr0udbr0
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceBrainSell Technologies
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024StefanoLambiase
 
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...OnePlan Solutions
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Angel Borroy López
 
Xen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfXen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfStefano Stabellini
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEOrtus Solutions, Corp
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...OnePlan Solutions
 

Kürzlich hochgeladen (20)

Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
 
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion Application
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
 
PREDICTING RIVER WATER QUALITY ppt presentation
PREDICTING  RIVER  WATER QUALITY  ppt presentationPREDICTING  RIVER  WATER QUALITY  ppt presentation
PREDICTING RIVER WATER QUALITY ppt presentation
 
Best Web Development Agency- Idiosys USA.pdf
Best Web Development Agency- Idiosys USA.pdfBest Web Development Agency- Idiosys USA.pdf
Best Web Development Agency- Idiosys USA.pdf
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)
 
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort ServiceHot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
 
How to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdfHow to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdf
 
Cyber security and its impact on E commerce
Cyber security and its impact on E commerceCyber security and its impact on E commerce
Cyber security and its impact on E commerce
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. Salesforce
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
 
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
 
Xen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfXen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdf
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
 

Akka Unit Testing Guide: Learn How to Test Actors with the Akka TestKit

  • 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