当前位置: 首页>>代码示例>>Scala>>正文


Scala TestActors类代码示例

本文整理汇总了Scala中akka.testkit.TestActors的典型用法代码示例。如果您正苦于以下问题:Scala TestActors类的具体用法?Scala TestActors怎么用?Scala TestActors使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了TestActors类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。

示例1: MySpec

//设置package包名称以及导入依赖的类
package docs.testkit

//#plain-spec
import akka.actor.ActorSystem
import akka.actor.Actor
import akka.actor.Props
import akka.testkit.{ TestActors, TestKit, ImplicitSender }
import org.scalatest.WordSpecLike
import org.scalatest.Matchers
import org.scalatest.BeforeAndAfterAll

//#implicit-sender
class MySpec(_system: ActorSystem) extends TestKit(_system) with ImplicitSender
  with WordSpecLike with Matchers with BeforeAndAfterAll {
  //#implicit-sender

  def this() = this(ActorSystem("MySpec"))

  override def afterAll {
    TestKit.shutdownActorSystem(system)
  }

  "An Echo actor" must {

    "send back messages unchanged" in {
      val echo = system.actorOf(TestActors.echoActorProps)
      echo ! "hello world"
      expectMsg("hello world")
    }

  }
}
//#plain-spec 
开发者ID:love1314sea,项目名称:akka-2.3.16,代码行数:34,代码来源:PlainWordSpec.scala

示例2: CrawlerActorSpec

//设置package包名称以及导入依赖的类
import akka.actor.{Props, ActorSystem}
import akka.testkit.TestActors.EchoActor
import akka.testkit.{ ImplicitSender, TestActors, TestKit }
import org.scalatest.{ BeforeAndAfterAll, Matchers, WordSpecLike }
import wipro.crawler.actors.Crawler


class CrawlerActorSpec() extends TestKit(ActorSystem("Crawler")) with ImplicitSender
with WordSpecLike with Matchers with BeforeAndAfterAll {

  override def afterAll {
    TestKit.shutdownActorSystem(system)
  }

  "An Crawler actor" must {

    "start creating other actors on start " in {
      val crawlerRef = system.actorOf(Props(new Crawler("http://wiprodigital.com",1)))
      crawlerRef ! "start"
      expectNoMsg()
    }

  }
} 
开发者ID:adityahalabe,项目名称:webCrawler,代码行数:25,代码来源:CrawlerActorSpec.scala

示例3: MinNodeTest

//设置package包名称以及导入依赖的类
import akka.actor.{ActorSystem, Props}
import akka.testkit.{ImplicitSender, TestActors, TestKit}
import hu.bme.mit.ire.messages.ChangeSet
import hu.bme.mit.ire.nodes.unary.MinNode
import org.scalatest.{BeforeAndAfterAll, Matchers, WordSpecLike}

class MinNodeTest(_system: ActorSystem) extends TestKit(_system) with ImplicitSender
  with WordSpecLike with Matchers with BeforeAndAfterAll {

  def this() = this(ActorSystem("MySpec"))

  override def afterAll {
    TestKit.shutdownActorSystem(system)
  }

  import hu.bme.mit.ire.util.TestUtil._

  "Min" must {
    "do simple min 0" in {
      val changeSet = ChangeSet(
        positive = Vector(
          tuple("a", 1),
          tuple("a", 2),
          tuple("a", 1.1),
          tuple("b", 3)
        )
      )
      val echoActor = system.actorOf(TestActors.echoActorProps)
      val min = system.actorOf(Props(new MinNode(echoActor ! _,Vector(0), 1)))

      min ! changeSet
      expectMsg(ChangeSet(positive = Vector(
        tuple("a", 1), tuple("b", 3)
      )))

      min ! ChangeSet(negative = Vector(tuple("a", 1)))
      expectMsg(ChangeSet(
        positive = Vector(tuple("a", 1.1)),
        negative = Vector(tuple("a", 1))
      ))
    }
  }
} 
开发者ID:FTSRG,项目名称:ire,代码行数:44,代码来源:MinNodeTest.scala

示例4: UnionNodeTest

//设置package包名称以及导入依赖的类
import akka.actor.{ActorSystem, Props}
import akka.testkit.{ImplicitSender, TestActors, TestKit}
import hu.bme.mit.ire.messages.{ChangeSet, Primary, Secondary}
import hu.bme.mit.ire.nodes.binary.UnionNode
import org.scalatest.{BeforeAndAfterAll, Matchers, WordSpecLike}

class UnionNodeTest(_system: ActorSystem) extends TestKit(_system) with ImplicitSender
  with WordSpecLike with Matchers with BeforeAndAfterAll {

  def this() = this(ActorSystem("MySpec"))

  override def afterAll {
    TestKit.shutdownActorSystem(system)
  }

  import hu.bme.mit.ire.util.TestUtil._

  "Union" must {
    "do simple unions 0" in {
      val prim = ChangeSet(
        positive = Vector(tuple(1, 2), tuple(1, 3))
      )
      val sec = ChangeSet(
        positive = Vector(tuple(1, 2), tuple(1, 4))
      )
      val echoActor = system.actorOf(TestActors.echoActorProps)
      val union = system.actorOf(Props(new UnionNode(echoActor ! _)))

      union ! Primary(prim)
      expectMsg(ChangeSet(positive = Vector(tuple(1, 2), tuple(1, 3))))
      union ! Secondary(sec)
      expectMsg(ChangeSet(positive = Vector(tuple(1, 4))))
    }
  }
} 
开发者ID:FTSRG,项目名称:ire,代码行数:36,代码来源:UnionNodeTest.scala

示例5: ListSelectorNodeTest

//设置package包名称以及导入依赖的类
import akka.actor.{ActorSystem, Props}
import akka.testkit.{ImplicitSender, TestActors, TestKit}
import hu.bme.mit.ire.messages.ChangeSet
import hu.bme.mit.ire.nodes.unary.MapperNode
import org.scalatest.{BeforeAndAfterAll, Matchers, WordSpecLike}

class ListSelectorNodeTest(_system: ActorSystem) extends TestKit(_system) with ImplicitSender
  with WordSpecLike with Matchers with BeforeAndAfterAll {

  def this() = this(ActorSystem("MySpec"))

  override def afterAll {
    TestKit.shutdownActorSystem(system)
  }

  import hu.bme.mit.ire.util.TestUtil._

  "ListSelector" must {
    "do select items in lists 0" in {
      val changeSet = ChangeSet(
        positive = Vector(
          tuple(List("a","b","c"))
        )
      )

      val function = (n: Any) => n match {
        case s: List[Any] => s(1)
      }
      val echoActor = system.actorOf(TestActors.echoActorProps)
      val listSelector = system.actorOf(Props(new MapperNode(echoActor ! _, function, 0)))

      listSelector ! changeSet
      expectMsg(ChangeSet(positive = Vector(tuple("b"))))
    }
  }
} 
开发者ID:FTSRG,项目名称:ire,代码行数:37,代码来源:ListSelectorNodeTest.scala

示例6: SelectionTest

//设置package包名称以及导入依赖的类
import akka.actor.{ActorSystem, Props}
import akka.testkit.{ImplicitSender, TestActors, TestKit}
import hu.bme.mit.ire.datatypes.Tuple
import hu.bme.mit.ire.messages.ChangeSet
import hu.bme.mit.ire.nodes.unary.{EqualityNode, InequalityNode, SelectionNode}
import hu.bme.mit.ire.util.TestUtil._
import org.scalatest.{BeforeAndAfterAll, Matchers, WordSpecLike}

class SelectionTest(_system: ActorSystem) extends TestKit(_system) with ImplicitSender
  with WordSpecLike with Matchers with BeforeAndAfterAll {

  def this() = this(ActorSystem("MySpec"))

  override def afterAll {
    TestKit.shutdownActorSystem(system)
  }

  "Selection" must {
    "check the condition properly" in {
      val changeSet = ChangeSet(Vector(tuple(0, "something"), tuple(0, "something else")))
      val echoActor = system.actorOf(TestActors.echoActorProps)
      val condition = (n: Tuple) => {
        n(1) == "something"
      }
      val checker = system.actorOf(Props(new SelectionNode(echoActor ! _, condition)))

      checker ! changeSet
      expectMsg(ChangeSet(positive = Vector(tuple(0, "something"))))
    }
  }
  "EqualityChecker" must {
    "check equality properly" in {
      val changeSet = ChangeSet(Vector(tuple(0, 2, 1), tuple(0, 0, 0), tuple(0, 2, 0)))
      val echoActor = system.actorOf(TestActors.echoActorProps)
      val equalityChecker = system.actorOf(Props(new EqualityNode(echoActor ! _, 0, Vector(1, 2))))

      equalityChecker ! changeSet
      expectMsg(ChangeSet(Vector(tuple(0, 0, 0))))
    }
  }
  "InequalityChecker" must {
    "check inequality properly" in {
      val changeSet = ChangeSet(Vector(tuple(0, 2, 1), tuple(0, 3, 0), tuple(0, 0, 0)))
      val echoActor = system.actorOf(TestActors.echoActorProps)
      val inequalityChecker = system.actorOf(Props(new InequalityNode(echoActor ! _, 0, Vector(1, 2))))

      inequalityChecker ! changeSet
      expectMsg(ChangeSet(Vector(tuple(0, 2, 1))))
    }
  }
} 
开发者ID:FTSRG,项目名称:ire,代码行数:52,代码来源:SelectionTest.scala

示例7: MaxNodeTest

//设置package包名称以及导入依赖的类
import akka.actor.{ActorSystem, Props}
import akka.testkit.{ImplicitSender, TestActors, TestKit}
import hu.bme.mit.ire.messages.ChangeSet
import hu.bme.mit.ire.nodes.unary.MaxNode
import org.scalatest.{BeforeAndAfterAll, Matchers, WordSpecLike}

class MaxNodeTest(_system: ActorSystem) extends TestKit(_system) with ImplicitSender
  with WordSpecLike with Matchers with BeforeAndAfterAll {

  def this() = this(ActorSystem("MySpec"))

  override def afterAll {
    TestKit.shutdownActorSystem(system)
  }

  import hu.bme.mit.ire.util.TestUtil._

  "Max" must {
    "do simple max 0" in {
      val changeSet = ChangeSet(
        positive = Vector(
          tuple("a", 1),
          tuple("a", 2),
          tuple("a", 1.1),
          tuple("b", 3)
        )
      )
      val echoActor = system.actorOf(TestActors.echoActorProps)
      val max = system.actorOf(Props(new MaxNode(echoActor ! _,Vector(0), 1)))

      max ! changeSet
      expectMsg(ChangeSet(positive = Vector(
        tuple("a", 2), tuple("b", 3)
      )))

      max ! ChangeSet(negative = Vector(tuple("a", 2)))
      expectMsg(ChangeSet(
        positive = Vector(tuple("a", 1.1)),
        negative = Vector(tuple("a", 2))
      ))
    }
  }
} 
开发者ID:FTSRG,项目名称:ire,代码行数:44,代码来源:MaxNodeTest.scala

示例8: MapperTest

//设置package包名称以及导入依赖的类
import akka.actor.{ActorSystem, Props}
import akka.testkit.{ImplicitSender, TestActors, TestKit}
import hu.bme.mit.ire.messages.ChangeSet
import hu.bme.mit.ire.nodes.unary.MapperNode
import hu.bme.mit.ire.util.TestUtil._
import org.scalatest.{BeforeAndAfterAll, Matchers, WordSpecLike}

class MapperTest(_system: ActorSystem) extends TestKit(_system) with ImplicitSender
  with WordSpecLike with Matchers with BeforeAndAfterAll {

  def this() = this(ActorSystem("MySpec"))

  override def afterAll {
    TestKit.shutdownActorSystem(system)
  }

  "MapperNode" must {
    "map values" in {
      val changeSet = ChangeSet(positive=Vector(tuple(0, "something")), negative=Vector(tuple(0, "something else")))
      val echoActor = system.actorOf(TestActors.echoActorProps)
      val function = (n: Any) => n match {
        case s: String => s.length
      }
      val checker = system.actorOf(Props(new MapperNode(echoActor ! _, function, 1)))

      checker ! changeSet
      expectMsg(ChangeSet(
        positive = Vector(tuple(0, "something".length)),
        negative = Vector(tuple(0, "something else".length))
      ))
    }
  }
} 
开发者ID:FTSRG,项目名称:ire,代码行数:34,代码来源:MapperTest.scala

示例9: TransactionFactoryTest

//设置package包名称以及导入依赖的类
import akka.actor.{ActorSystem, actorRef2Scala}
import akka.testkit.{ImplicitSender, TestActors, TestKit}
import hu.bme.mit.ire.TransactionFactory
import hu.bme.mit.ire.messages.ChangeSet
import hu.bme.mit.ire.util.TestUtil._
import org.scalatest.{BeforeAndAfterAll, Matchers, WordSpecLike}

class TransactionFactoryTest(_system: ActorSystem) extends TestKit(_system) with ImplicitSender
  with WordSpecLike with Matchers with BeforeAndAfterAll {
  def this() = this(ActorSystem("MySpec"))

  override def afterAll {
    TestKit.shutdownActorSystem(system)
  }

  "TransactionFactory" must {

    "send incoming data after subscription" in {
      val input = new TransactionFactory(messageSize = 4)
      val echoActor = system.actorOf(TestActors.echoActorProps)
      input.subscribe(Map("test" -> (echoActor ! _)))
      val tran = input.newBatchTransaction()
      tran.add("test", tuple(6, 1L))
      tran.add("test", tuple(6, 2L))
      tran.close()
      expectMsg(ChangeSet(positive = Vector(tuple(6, 2), tuple(6, 1))))
    }

    "do no splitting in batch" in {
      val input = new TransactionFactory(messageSize = 2)
      val echoActor = system.actorOf(TestActors.echoActorProps)
      input.subscribe(Map("test" -> (echoActor ! _)))
      val tran = input.newBatchTransaction()
      for (i <- 1 to 3) {
        tran.add("test", tuple(6, i))
      }
      tran.close()
      expectMsg(ChangeSet(positive = Vector(tuple(6, 3), tuple(6, 2), tuple(6, 1))))
    }
    "send messageSize sized messages when using continuous transactions" in {
      val input = new TransactionFactory(messageSize = 2)
      val echoActor = system.actorOf(TestActors.echoActorProps)
      input.subscribe(Map("test" -> (echoActor ! _)))
      val tran = input.newContinousTransaction()
      for (i <- 1 to 3) {
        tran.add("test", tuple(6, i))
      }
      tran.close()
      expectMsg(ChangeSet(positive = Vector(tuple(6, 2), tuple(6, 1))))
      expectMsg(ChangeSet(positive = Vector(tuple(6, 3))))
    }
  }
} 
开发者ID:FTSRG,项目名称:ire,代码行数:54,代码来源:TransactionFactoryTest.scala

示例10: EchoActorSpec

//设置package包名称以及导入依赖的类
import akka.actor.ActorSystem
import akka.testkit.{ ImplicitSender, TestActors, TestKit }
import org.scalatest.{ BeforeAndAfterAll, Matchers, WordSpecLike }

class EchoActorSpec extends TestKit(ActorSystem("MySpec")) //the actor system passed here is exposed via system in the test
  with ImplicitSender // provides a TestActor that will be receiving all the msg send to sender() which can be checked via expectMsg() assertions
  with WordSpecLike
  with Matchers
  with BeforeAndAfterAll {

  override def afterAll {
    TestKit.shutdownActorSystem(system) // Mus be done!
  }

  "An Echo actor" must {

    "send back messages unchanged" in {
      val echo = system.actorOf(TestActors.echoActorProps)
      echo ! "hello world"
      expectMsg("hello world")
      // see http://doc.akka.io/docs/akka/current/scala/testing.html#built-in-assertions for the list of available assertions
      //as with actors we deal with asynchronous calls, we always operate within limits of timeouts -> if not defined explicitly
      //we always have a timeout of 3sec
    }

  }
} 
开发者ID:lplotni,项目名称:akka-testing-example,代码行数:28,代码来源:EchoActorSpec.scala

示例11: EchoUsageSpec

//设置package包名称以及导入依赖的类
import akka.actor.ActorSystem
import akka.testkit.{DefaultTimeout, ImplicitSender, TestActors, TestKit}
import com.typesafe.config.ConfigFactory
import org.scalatest.{BeforeAndAfterAll, Matchers, WordSpecLike}

import scala.concurrent.duration._


class EchoUsageSpec extends TestKit(ActorSystem(
  "EchoUsageSpec",
  ConfigFactory.parseString(EchoUsageSpec.config))) with DefaultTimeout with ImplicitSender
  with WordSpecLike with Matchers with BeforeAndAfterAll {


  val echoRef = system.actorOf(TestActors.echoActorProps)

  override def afterAll {
    shutdown()
  }

  "An EchoActor" should {
    "Respond with the same message it receives" in {
      within(50 millis) {
        echoRef ! "test"
        expectMsg("test")
      }
    }
  }
}


object EchoUsageSpec {
  // Define your test specific configuration here
  val config =
  """
    akka {
      loglevel = "WARNING"
    }
  """

} 
开发者ID:PuspenduBanerjee,项目名称:ScalaAkkaBlah,代码行数:42,代码来源:EchoUsageSpec.scala

示例12: AsynchronousTest

//设置package包名称以及导入依赖的类
package com.shashank.akka.testing

import akka.actor.{Actor, ActorSystem, PoisonPill, Props}
import akka.testkit.{ImplicitSender, TestActors, TestKit, TestProbe}
import org.scalatest.WordSpecLike
import org.scalatest.Matchers
import org.scalatest.BeforeAndAfterAll


class AsynchronousTest extends TestKit(ActorSystem("MySpec")) with ImplicitSender
  with WordSpecLike with Matchers with BeforeAndAfterAll {

  override def afterAll {
    TestKit.shutdownActorSystem(system)
  }

  "Testing actors" must {

    "echo actor" in {
      val echo = system.actorOf(TestActors.echoActorProps)
      echo ! "hello world"
      expectMsg("hello world")
    }

    "buffer actor adds values to buffer" in {
      val bufferActor = system.actorOf(Props[ActorBasedBuffer], "bufferactor")
      bufferActor ! (10)
      expectNoMsg()
      bufferActor ! (20)
      expectNoMsg()

      bufferActor ! ("sum")
      expectMsg(30)

      println(bufferActor.path.name)
      bufferActor.path.name shouldEqual "bufferactor"
    }

    "killing actor" in {
      val echo = system.actorOf(TestActors.echoActorProps)
      val probe = TestProbe()
      probe watch echo
      echo ! PoisonPill
      probe.expectTerminated(echo)

    }

  }
} 
开发者ID:shashankgowdal,项目名称:introduction-to-concurrentprogramming-with-akka,代码行数:50,代码来源:AsynchronousTest.scala

示例13: ProcessingActorTest

//设置package包名称以及导入依赖的类
package actors

import akka.actor.ActorSystem
import akka.testkit.{ImplicitSender, TestActors, TestKit}
import org.scalatest.{BeforeAndAfterAll, Matchers, WordSpecLike}


class ProcessingActorTest extends TestKit(ActorSystem("testActorSystem")) with ImplicitSender
  with WordSpecLike with Matchers with BeforeAndAfterAll {

  override def afterAll: Unit = {
    TestKit.shutdownActorSystem(system)
  }

  "Processing actors" must {
    "Kick off Extracting Actor" in {
      val processingActor = system.actorOf(TestActors.echoActorProps)
      processingActor ! "echo"
    }
  }

} 
开发者ID:oginskis,项目名称:play-vo-flats,代码行数:23,代码来源:ProcessingActorTest.scala


注:本文中的akka.testkit.TestActors类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。