Using DefaultReactiveMongoApi instead of ReactiveMongoApi

178 views
Skip to first unread message

felix.pallud...@lego.com

unread,
Jan 18, 2016, 3:40:23 AM1/18/16
to ReactiveMongo - http://reactivemongo.org
I have a problem with the ReactiveMongoApi being a singleton (http://reactivemongo.org/releases/0.11/play-api/index.html#play.modules.reactivemongo.ReactiveMongoModule)

To my huge lack of surprise, this makes testing a nightmare. I am starting an in-memory instance of MongoDB for each unit test to keep tests separated and creating a new connection each time, however, 
I get the following errors:

...

[info] - should create any non-empty alphanumeric word from a form

[error] - reactivemongo.core.actors.MongoDBSystem - The entire node set is unreachable, is there a network problem?

[error] - reactivemongo.core.actors.MongoDBSystem - The entire node set is unreachable, is there a network problem?

[info] - should be able to serve a frontpage

[info] - should be able to create a user

[error] - reactivemongo.core.actors.MongoDBSystem - The entire node set is unreachable, is there a network problem?

[error] - reactivemongo.core.actors.MongoDBSystem - The entire node set is unreachable, is there a network problem?

[info] - should be able to log in a user

[error] - reactivemongo.core.actors.MongoDBSystem - The entire node set is unreachable, is there a network problem?

[error] - reactivemongo.core.actors.MongoDBSystem - The entire node set is unreachable, is there a network problem?

[info] MagicWordsSpec:

[info] createMagicWord

[info] - application - ReactiveMongoApi starting...

[info] - application - ReactiveMongoApi successfully started with DB 'clutchpower'! Servers:

[localhost:27017]

[info] - should return the created word

[error] - reactivemongo.core.actors.MongoDBSystem - The entire node set is unreachable, is there a network problem?

[error] - reactivemongo.core.actors.MongoDBSystem - The entire node set is unreachable, is there a network problem?

[info] MagicWordsRepo

[info] - should have created words with no user available in the free-words list

[error] - reactivemongo.core.actors.MongoDBSystem - The entire node set is unreachable, is there a network problem?

[error] - reactivemongo.core.actors.MongoDBSystem - The entire node set is unreachable, is there a network problem?

[error] - reactivemongo.core.actors.MongoDBSystem - The entire node set is unreachable, is there a network problem?

...


When I try to change the module in application.conf from  play.modules.enabled += "play.modules.reactivemongo.ReactiveMongoModule"
to play.modules.enabled += "play.modules.reactivemongo.DefaultReactiveMongoModule" it simply fails to instantiate the API altogether. How do I use 
ReactiveMongoAPI as a transient type instead of a singleton?

Cédric Chantepie

unread,
Jan 18, 2016, 2:48:00 PM1/18/16
to ReactiveMongo - http://reactivemongo.org
Hi,

There are several way to improve that.

Using the latest 0.11.9, you can use the function api.database, instead api.db. The new one clearly states the DB resolution is asynchronous (Future[DefaultDB]).

Instead of instantiating the ReactiveMongo API for each test scope using a FakeApplication, the driver for tests can be managed directly as in: https://github.com/ReactiveMongo/Play-ReactiveMongo/blob/master/src/test/scala/Common.scala (see SBT test cleanup: https://github.com/ReactiveMongo/Play-ReactiveMongo/blob/master/project/Play2-ReactiveMongo.scala#L16 ).

Best regards

Reply all
Reply to author
Forward
0 new messages