akka-testkit

How to test client-side Akka HTTP

别等时光非礼了梦想. 提交于 2021-02-17 21:33:35
问题 I've just started testing out the Akka HTTP Request-Level Client-Side API (Future-Based). One thing I've been struggling to figure out is how to write a unit test for this. Is there a way to mock the response and have the future completed without having to actually do an HTTP request? I was looking at the API and the testkit package, trying to see how I could use that, only to find in the docs that it actually says: akka-http-testkit A test harness and set of utilities for verifying server

How to test client-side Akka HTTP

霸气de小男生 提交于 2021-02-17 21:32:13
问题 I've just started testing out the Akka HTTP Request-Level Client-Side API (Future-Based). One thing I've been struggling to figure out is how to write a unit test for this. Is there a way to mock the response and have the future completed without having to actually do an HTTP request? I was looking at the API and the testkit package, trying to see how I could use that, only to find in the docs that it actually says: akka-http-testkit A test harness and set of utilities for verifying server

how to resolve conflict of ActorSystem in akka http test and akka test kit

▼魔方 西西 提交于 2020-12-26 11:11:17
问题 i have a test class in which i need to use both akka testkit and akka http test kit so i am doing it like this class MyTest extends TestKit(ActorSystem("testsys")) with ScalaFutures with ImplicitSender with AnyWordSpecLike with Matchers with BeforeAndAfterAll with ScalatestRouteTest { //tests here } but i am getting a compile time error implicit val system: akka.actor.ActorSystem (defined in class TestKit) and [error] implicit val system: akka.actor.ActorSystem (defined in trait RouteTest)

how to resolve conflict of ActorSystem in akka http test and akka test kit

雨燕双飞 提交于 2020-12-26 11:08:14
问题 i have a test class in which i need to use both akka testkit and akka http test kit so i am doing it like this class MyTest extends TestKit(ActorSystem("testsys")) with ScalaFutures with ImplicitSender with AnyWordSpecLike with Matchers with BeforeAndAfterAll with ScalatestRouteTest { //tests here } but i am getting a compile time error implicit val system: akka.actor.ActorSystem (defined in class TestKit) and [error] implicit val system: akka.actor.ActorSystem (defined in trait RouteTest)

How to create a TestActorRef inside a test class for an Actor with constructor params?

倾然丶 夕夏残阳落幕 提交于 2019-12-23 01:41:32
问题 How does one create a TestActorRef inside a test class. Specifically, I have the following test set up... class MatchingEngineSpec extends TestKit(ActorSystem("Securities-Exchange")) with FeatureSpecLike with GivenWhenThen with Matchers { val google = Security("GOOG") val ticker = Agent(Tick(google, None, None, None)) val marketRef = TestActorRef(new DoubleAuctionMarket(google, ticker) with BasicMatchingEngine) val market = marketRef.underlyingActor ...when I run the tests everything passes,

How to create a TestActorRef inside a test class for an Actor with constructor params?

别来无恙 提交于 2019-12-23 01:41:12
问题 How does one create a TestActorRef inside a test class. Specifically, I have the following test set up... class MatchingEngineSpec extends TestKit(ActorSystem("Securities-Exchange")) with FeatureSpecLike with GivenWhenThen with Matchers { val google = Security("GOOG") val ticker = Agent(Tick(google, None, None, None)) val marketRef = TestActorRef(new DoubleAuctionMarket(google, ticker) with BasicMatchingEngine) val market = marketRef.underlyingActor ...when I run the tests everything passes,

Ensure message order in test when mixing futures with actor messages

落爺英雄遲暮 提交于 2019-12-11 08:50:04
问题 I'm testing an actor that uses an asnychronous future-based API. The actor uses the pipe pattern to send a message to itself when a future completes: import akka.pattern.pipe // ... // somewhere in the actor's receive method futureBasedApi.doSomething().pipeTo(self) In my test I mock the API so I control future completion via promises. However, this is interleaved with other messages sent directly to the actor: myActor ! Message("A") promiseFromApiCall.success(Message("B")) myActor ! Message(

How to create a TestActorRef inside a test class for an Actor with constructor params?

女生的网名这么多〃 提交于 2019-12-07 03:15:29
How does one create a TestActorRef inside a test class. Specifically, I have the following test set up... class MatchingEngineSpec extends TestKit(ActorSystem("Securities-Exchange")) with FeatureSpecLike with GivenWhenThen with Matchers { val google = Security("GOOG") val ticker = Agent(Tick(google, None, None, None)) val marketRef = TestActorRef(new DoubleAuctionMarket(google, ticker) with BasicMatchingEngine) val market = marketRef.underlyingActor ...when I run the tests everything passes, but after shutting down the ActorSystem I get this long error trace... [ERROR] [03/10/2015 15:07:55.571

How to mock an Akka Actor to Unit Test a class?

限于喜欢 提交于 2019-12-05 01:06:24
问题 I have a Controller class which controls the requests sent to a Akka actor which is injected in to the controller. Controller's code: class Controller(actor: ActorRef) { def control(msg: String): Future[String] = { actor.ask(msg)(Timeout(2 seconds)).mapTo[String] } } And my Actor's code is: class ActorA extends Actor { override def receive: Receive = { case msg: String => sender ! msg case msg: Int => sender ! msg.toString case _ => "Invalid command!" } Now I need to mock ActorA's behaviour

Uncaught error from default dispatcher causes fatal error with JavaTestKit

允我心安 提交于 2019-12-01 13:45:43
I'm just getting my feet wet with Akka. I'm trying to write a JUNit test using the JavaTestKit from this Maven dependency: <dependency> <groupId>com.typesafe.akka</groupId> <artifactId>akka-actor_2.10</artifactId> <version>2.3.12</version> </dependency> <dependency> <groupId>com.typesafe.akka</groupId> <artifactId>akka-testkit_2.11</artifactId> <version>2.3.12</version> </dependency> Even a JavaTestKit instance that does nothing will throw a fatal exception, so I suspect there's a configuration issue. This class will reproduce the problem: import akka.actor.ActorSystem; import akka.event