Advertisement
Guest User

Untitled

a guest
Mar 11th, 2015
414
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 1.03 KB | None | 0 0
  1. $ cat project/build.properties
  2. sbt.version=0.13.7
  3.  
  4. $ cat build.sbt
  5. name := "test"
  6.  
  7. version := "0.0.1"
  8.  
  9. scalaVersion := "2.11.6"
  10.  
  11. scalacOptions += "-deprecation"
  12.  
  13. libraryDependencies ++= Seq(
  14.   "com.typesafe.akka" %% "akka-actor" % "2.3.9",
  15.   "com.typesafe.akka" %% "akka-testkit" % "2.3.9"
  16. )
  17.  
  18. $ cat test.scala
  19. object Main extends App {
  20.   import akka.actor.ActorSystem
  21.   import akka.testkit.TestActorRef
  22.   import akka.pattern.ask
  23.   import akka.util.Timeout
  24.  
  25.   class Test(i: Int) {
  26.     import akka.actor.Actor
  27.  
  28.     class MyActor(j: Int) extends Actor {
  29.       def receive = {
  30.         case x => sender ! (i, j, x)
  31.       }
  32.     }
  33.   }
  34.  
  35.   val t = new Test(13)
  36.  
  37.   implicit val as = ActorSystem("test");
  38.   import as.dispatcher
  39.  
  40.   val actorRef = TestActorRef(new t.MyActor(666))
  41.  
  42.   implicit val timeout = Timeout.intToTimeout(1000)
  43.  
  44.   val res = actorRef ? 'xxx
  45.  
  46.   res.map(println).onComplete{ x => as.shutdown() }
  47. }
  48.  
  49. $ sbt run
  50. [info] Running Main
  51. (13,666,'xxx)
  52. [success] Total time: 1 s, completed 11.03.2015 9:38:08
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement