0

I am building an authentication service in Lagom (scala) which consists of a device entity and an event processor. The service uses the JDBC plugin instead of the default Cassandra. While writing the integration tests I found out that the event processor is not being called on events only for initialization. I am not sure how to approach...

abstract class AuthApplication(context: LagomApplicationContext) extends LagomApplication(context)
  with JdbcPersistenceComponents
  with AhcWSComponents
  with HikariCPComponents {
  override lazy val lagomServer = serverFor[AuthService](wire[AuthServiceImpl])
  lazy val jsonSerializerRegistry = AuthSerializerRegistry
  lazy val jwtAuthenticator: PkiAuthenticator = new JwtAuthenticator(config.getConfig("jwt"))
  lazy val tokenRepository = wire[TokenRepository]

  persistentEntityRegistry.register(wire[DeviceEntity])
  readSide.register(wire[DeviceEventProcessor])

  wire[TokenScheduler]
}

The integration test initialization:

override def beforeAll: Unit = {
    server = ServiceTest.startServer(ServiceTest.defaultSetup.withCassandra(true)) { ctx =>
      new ServiceTestApplication(ctx)
    }

    authService = server.serviceClient.implement[AuthService]
  }
idoshamun
  • 1,125
  • 9
  • 21
  • Normally I would use the `withClient` pattern for these types of tests as opposed to a `beforeAll`. Not sure if that will solve anything, but it's just a style point. – erip Jan 02 '18 at 13:23
  • Actually, it might solve something... If `authService` is a `var`, it's initial value will be `null`, so there might be side-effects with how the initialization of the service works. – erip Jan 02 '18 at 13:25
  • What is this function `withClient`, I am not familiar with it? – idoshamun Jan 02 '18 at 13:59
  • Something like [this](https://gist.github.com/erip/7439e8c6ef853eda69487915986e9a14). – erip Jan 02 '18 at 14:10
  • Great! I will give it a shot soon. Thanks – idoshamun Jan 02 '18 at 14:24
  • Unfortunately it didn't help – idoshamun Jan 11 '18 at 14:25

1 Answers1

0

To solve this issue I had to use WordSpec instead of AsyncWordSpec, the default execution context messes with Lagom somehow and in addition I had to add an eventually block to check if the state updated because the event processing is not immediately and takes like 30 seconds.

idoshamun
  • 1,125
  • 9
  • 21