Merge branch 'master' of github.com:jboner/akka

This commit is contained in:
Derek Williams 2011-05-02 16:56:48 -06:00
commit 23d85e4627
3 changed files with 88 additions and 2 deletions

View file

@ -44,10 +44,10 @@ pygments:
@echo "Custom pygments styles have been installed."
@echo
$(LOCALPACKAGES)/akkastyles-0.1-py2.6.egg:
$(LOCALPACKAGES):
$(MAKE) pygments
html: $(LOCALPACKAGES)/akkastyles-0.1-py2.6.egg
html: $(LOCALPACKAGES)
$(SPHINXBUILD) -a -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html
@echo
@echo "Build finished. The HTML pages are in $(BUILDDIR)/html."

View file

@ -0,0 +1,51 @@
.. _Duration:
########
Duration
########
Module stability: **SOLID**
Durations are used throughout the Akka library, wherefore this concept is
represented by a special data type, :class:`Duration`. Values of this type may
represent infinite (:obj:`Duration.Inf`, :obj:`Duration.MinusInf`) or finite
durations.
Scala
=====
In Scala durations are constructable using a mini-DSL and support all expected operations:
.. code-block:: scala
import akka.util.duration._ // notice the small d
val fivesec = 5.seconds
val threemillis = 3.millis
val diff = fivesec - threemillis
assert (diff < fivesec)
val fourmillis = threemillis * 4 / 3 // though you cannot write it the other way around
val n = threemillis / (1 millisecond)
.. note::
You may leave out the dot if the expression is clearly delimited (e.g.
within parentheses or in an argument list), but it is recommended to use it
if the time unit is the last token on a line, otherwise semi-colon inference
might go wrong, depending on what starts the next line.
Java
====
Java provides less syntactic sugar, so you have to spell out the operations as
method calls instead:
.. code-block:: java
final Duration fivesec = Duration.create(5, "seconds");
final Duration threemillis = Duration.parse("3 millis");
final Duration diff = fivesec.minus(threemillis);
assert (diff.lt(fivesec));
assert (Duration.Zero().lt(Duration.Inf()));

View file

@ -40,6 +40,10 @@ encompass functional tests of complete actor networks. The important
distinction lies in whether concurrency concerns are part of the test or not.
The tools offered are described in detail in the following sections.
.. note::
Be sure to add the module :mod:`akka-testkit` to your dependencies.
Unit Testing with :class:`TestActorRef`
=======================================
@ -68,6 +72,8 @@ reference is done like this:
.. code-block:: scala
import akka.testkit.TestActorRef
val actorRef = TestActorRef[MyActor]
val actor = actorRef.underlyingActor
@ -169,6 +175,10 @@ common task easy:
.. code-block:: scala
import akka.testkit.TestKit
import org.scalatest.WordSpec
import org.scalatest.matchers.MustMatchers
class MySpec extends WordSpec with MustMatchers with TestKit {
"An Echo actor" must {
@ -252,6 +262,31 @@ runs everything which would normally be queued directly on the current thread,
the full history of a message's processing chain is recorded on the call stack,
so long as all intervening actors run on this dispatcher.
How to use it
-------------
Just set the dispatcher as you normally would, either from within the actor
.. code-block:: scala
import akka.testkit.CallingThreadDispatcher
class MyActor extends Actor {
self.dispatcher = CallingThreadDispatcher.global
...
}
or from the client code
.. code-block:: scala
val ref = Actor.actorOf[MyActor]
ref.dispatcher = CallingThreadDispatcher.global
ref.start()
As the :class:`CallingThreadDispatcher` does not have any configurable state,
you may always use the (lazily) preallocated one as shown in the examples.
How it works
------------