Reklund3
(Robert Eklund)
July 9, 2019, 12:18am
1
Hello,
I am trying to used the new Typed ActorTestKit with a custom ActorSystemSetup. In the untyped TestKit, it was easy because you could provide the actor system in the constructor:
* constructor as shown above, which makes this a non-issue, otherwise take
* care not to run tests within a single test class instance in parallel.
*
* It should be noted that for CI servers and the like all maximum Durations
* are scaled using their Duration.dilated method, which uses the
* TestKitExtension.Settings.TestTimeFactor settable via akka.conf entry "akka.test.timefactor".
*
* @since 1.1
*/
@silent // 'early initializers' are deprecated on 2.13 and will be replaced with trait parameters on 2.14. https://github.com/akka/akka/issues/26753
class TestKit(_system: ActorSystem) extends { implicit val system = _system } with TestKitBase
object TestKit {
private[testkit] val testActorId = new AtomicInteger(0)
/**
* Await until the given condition evaluates to `true` or the timeout
* expires, whichever comes first.
*/
def awaitCond(p: => Boolean, max: Duration, interval: Duration = 100.millis, noThrow: Boolean = false): Boolean = {
val stop = now + max
But with the typed ActorTestKit you can only specify custom config settings:
/**
* Create a named testkit, and use a custom config for the actor system,
* and a custom [[akka.actor.testkit.typed.TestKitSettings]]
*
* It will create an [[akka.actor.typed.ActorSystem]] with this name,
* e.g. threads will include the name.
* When the test has completed you should terminate the `ActorSystem` and
* the testkit with [[ActorTestKit#shutdownTestKit]].
*/
def apply(name: String, customConfig: Config, settings: TestKitSettings): ActorTestKit =
new ActorTestKit(name = TestKitUtils.scrubActorSystemName(name), config = customConfig, settings = Some(settings))
/**
* Shutdown the given [[akka.actor.typed.ActorSystem]] and block until it shuts down,
* if more time than `TestKitSettings.DefaultActorSystemShutdownTimeout` passes an exception is thrown
*/
def shutdown(system: ActorSystem[_]): Unit = {
val settings = TestKitSettings(system)
TestKitUtils.shutdown(system, settings.DefaultActorSystemShutdownTimeout, settings.ThrowOnShutdownTimeout)
}
For reference, I am trying to use Typed actors along side Lagom Persistent Entites, and it requires you to provide a serializer for each class on actor system setup (See here: https://www.lagomframework.com/documentation/1.5.x/scala/PersistentEntity.html#Unit-Testing ).
How would I go about testing typed actor and persistent entity interactions?
Regards,
1 Like
Looks like that would require some changes and an additional factory method, please create an issue about it!
1 Like
Reklund3
(Robert Eklund)
July 12, 2019, 4:23am
3
Thank you Mr. Andren. I have created an issue over in the Akka/Akka Github page.
Please see reference at: https://github.com/akka/akka/issues/27338
Regards,
Robert