Testing 2 services in unit test

147 views
Skip to first unread message

Tim Pigden

unread,
Jan 31, 2017, 12:41:14 PM1/31/17
to Lagom Framework Users
Hi,
I have 2 services.
One of them contains a persistententity - ModelService
One of them subscribes to a topic from ModelService. This is ModelReaderService

I'm trying to run a service test from test branch of ../modelreader/impl 

But it seems I'm not starting up the model service because I get a message

Service model was not found by service locator
java.lang.IllegalStateException: Service model was not found by service locator
at com.lightbend.lagom.internal.client.ClientServiceCallInvoker$$anonfun$doInvoke$2.apply(ClientServiceCallInvoker.scala:75)

Frankly I have no idea what to do so this was my best guess

class ModelReaderServiceTest extends AsyncWordSpec with Matchers with BeforeAndAfterAll {

private val server = ServiceTest.startServer(
ServiceTest.defaultSetup
.withCassandra(true)
) { ctx =>
new ModelReaderApplication(ctx) with LocalServiceLocator
}

val modelService = server.serviceClient.implement[ModelService]
val modelReaderService = server.serviceClient.implement[ModelReaderService]
val product1 = Product("product1", 1, "g1")

override protected def afterAll() = server.stop()

val modelId = UUIDs.timeBased()

implicit val mat = server.materializer

"model service" should {
"create model" in {
for {
created <- modelService.createModel(modelId).invoke("my model")
addedProduct <- modelService.addProduct(modelId).invoke(product1)
fromReader <- {
Thread.sleep(2000)
modelReaderService.getModel(modelId).invoke()
}
any help much appreciated!

Tim Pigden

unread,
Jan 31, 2017, 12:50:57 PM1/31/17
to Lagom Framework Users

ok - found this - can anyone tell me if there is anything I can do?

How to test several services

Lagom will provide support for writing integration tests that involve several interacting services. This feature is not yet implemented.

Tim Pigden

unread,
Jan 31, 2017, 12:57:58 PM1/31/17
to Lagom Framework Users
And it's issue #38 from March in case anyone's interested

Tim Moore

unread,
Feb 7, 2017, 8:21:54 PM2/7/17
to Tim Pigden, Lagom Framework Users
Hi Tim,

What we've typically done is mock one service when testing another one. This lets you test each service in isolation, which is usually what you want to do in a unit test.

In Lagom 1.3.0-RC1, a new feature was added for testing topic subscriptions: http://www.lagomframework.com/documentation/1.3.x/scala/MessageBrokerTesting.html

True integration tests are a more complex beast, and the approach to this in Lagom is still to be determined. In most micro service systems, a full integration test with everything running is generally infeasible. For that reason, testing single services with others mocked out is a very common approach. We do hope, however, to eventually support integration testing of all of the services within a single Lagom project.

Cheers,
Tim

--
You received this message because you are subscribed to the Google Groups "Lagom Framework Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lagom-framework+unsubscribe@googlegroups.com.
To post to this group, send email to lagom-framework@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/lagom-framework/5fac9b71-41e5-4ed9-a796-39e558ff4a51%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Tim Moore
Senior Engineer, Lagom, Lightbend, Inc.


Kiran Dhanireddy

unread,
Mar 19, 2018, 3:49:38 AM3/19/18
to Lagom Framework Users [deprecated]
Hi Tim
Were you able to resolve this issue ?

Regards
Kiran
Reply all
Reply to author
Forward
0 new messages