You are on page 1of 16

http://www.unicomlearning.

com/2016/NFT_Con/
Reactive Paradigm

RESPONSIVE

ELASTIC RESILIENT

MESSAGE-DRIVEN

http://www.unicomlearning.com/2016/NFT_Con/
Akka Framework
• A Framework to Build Reactive Systems on the
Java Virtual Machine
• Developed at TypeSafe (now renamed Lightbend)
– Company founded by Martin Odersky
• Open Source (Apache Licensed)
– First Release: 2009
• Inspired by Erlang

http://www.unicomlearning.com/2016/NFT_Con/
Akka Actors
ACTOR SYSTEM
MESSAGES

ACTOR ACTOR
1 2

MAILBOX

DISPATCHER

THREAD POOL
Building an Akka-Based System
• Not Just Message Passing
– Actor Hierarchies
– Actor Life-cycle
– Events
– FSM
– Persistence
– Streams
– Scheduling
Test-Driven Development
• Actor TDD consists of two parts
• Test the functionality
– Regardless of timing dependencies, etc.
• Test the asynchronous behavior
– This is the challenging part (compared to good old
JUnit-style testing)
• That’s where akka-testkit comes in
Testing Behavior
• An Actor’s underlying object can be retrieved
using TestActorRef
• Thereafter apply traditional unit test on the
underlying object
• Use any test framework that gels well with
akka-testkit
Testing Message Passing
• Use ‘ImplicitSender’ to isolate the actor from
the rest of the environment
• Akka-testkit offers several methods to test for
expected messages
• Includes conditions on message arrival times
and sequences
• Includes patter matching on the retrieved
message
Testing Message Passing
• ‘Expected’ Messages can be retrieved using
– expectMsg
– expectMsgType
– expectMsgPF // Partial Function for pattern match
• Variants for setting an expected duration:
– expectMsg(duration, msg)
– expectMsgType(duration)
Conditions on Message Passing
• Various conditions can be applied (for example
on a sequence of messages)
– receiveN(num, duration)
– awaitCondition
– within(minDuration, maxDuration)
– Intercept // for handling exceptions
Message Probe
• We have tested whether a message was
received by an Actor
• Most often there is a two-way message flow
• Does the actor respond back with a desired
message?
• ‘TestProbe’ can be used to create dummy
receivers for these responses
CallingThreadDispatcher
• In an Actor system, message is sent and
received in two different threads
• This might make unit-tests non-deterministic
• akka-testkit uses a specialized dispatcher to
run sender and receiver in the same thread
• This dispatcher is known as
CallingThreadDispatcher
Multi-Node Testing
• Akka is essentially a distributed computing
framework
• Actors are dispatched to run on a cluster of
nodes
• The system behavior is location-independent
• Multi-node testing ensures that system
functionality is unaltered as we scale up
Multi-node Testing
• The module that supports multi-node testing
is ‘TestConductor’
• It supports
– Node Address Lookup
– Node Barrier Coordination
– Node Failure Injection
Multi-Node Testing Architecture

Source: http://doc.akka.io/
World Conference
NFTConNext
2016Generation Testing 2015
- Bangalore

THANK
YOU
monojit@techyugadi.com

Organized by
UNICOM Trainings & Seminars Pvt. Ltd.
contact@unicomlearning.com

http://www.unicomlearning.com/2016/NFT_Con/

You might also like