Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mongodb 第二场及;ReactiveMongo测试问题:测试失败后立即连接数据库_Mongodb_Scala_Testing_Playframework 2.0_Reactivemongo - Fatal编程技术网

Mongodb 第二场及;ReactiveMongo测试问题:测试失败后立即连接数据库

Mongodb 第二场及;ReactiveMongo测试问题:测试失败后立即连接数据库,mongodb,scala,testing,playframework-2.0,reactivemongo,Mongodb,Scala,Testing,Playframework 2.0,Reactivemongo,我正在实现一个文件存储服务,它获取一个文件并用特殊的元数据将其保存到gridFS中。当然,我想确保所有的东西都在集成中工作——文件确实存储在数据库中,然后从中检索 我使用Play Framework 2.1.3 Scala和ReactiveMongo 0.9 我的测试用例如下所示: "show empty uploaded size on init" in { running(FakeApplication()) { Await.result(FileStorage.getFiles

我正在实现一个文件存储服务,它获取一个文件并用特殊的元数据将其保存到gridFS中。当然,我想确保所有的东西都在集成中工作——文件确实存储在数据库中,然后从中检索

我使用Play Framework 2.1.3 Scala和ReactiveMongo 0.9

我的测试用例如下所示:

"show empty uploaded size on init" in {
  running(FakeApplication()) {
    Await.result(FileStorage.getFilesSize(profileId), duration) must beNone
  }
}
我试图用
running
包装每个案例,或者包装所有案例,甚至
Thread.sleep
。但在测试失败后,数据库总是处于启动状态

[error] There is no started application
[error] play.api.Play$$anonfun$current$1.apply(Play.scala:51)
[error] play.api.Play$$anonfun$current$1.apply(Play.scala:51)
[error] play.api.Play$.current(Play.scala:51)
[error] content.FileStorage$.db$lzycompute(FileStorage.scala:32)

...

[info] Total for specification FileStorageSpec
[info] Finished in 21 ms
[info] 5 examples, 1 failure, 4 errors
[info] 
[info] application - ReactiveMongoPlugin starting...
[info] application - ReactiveMongoPlugin successfully started with db 'test'! Servers:
        [localhost:27017]
[info] play - Starting application default Akka system.
[info] play - Shutdown application default Akka system.

我做错了什么?如何测试ReactiveMongo应用程序?

文件存储
对象中有以下几行:

lazy val db = ReactiveMongoPlugin.db

val gridFS = GridFS(db, "file")
val collection = db.collection[JSONCollection]("file.files")

collection.indexesManager.ensure(Index(Seq("metadata.profileId" -> IndexType.Ascending)))
当对象被实例化时,执行上述代码行。由于您无法控制对象实例化,因此无法确定何时发生

将这些行更改为以下内容可能会有所帮助:

def db = ReactiveMongoPlugin.db

def gridFS = GridFS(db, "file")
def collection = {
  val collection = db.collection[JSONCollection]("file.files")
  collection.indexesManager.ensure(Index(Seq("metadata.profileId" -> IndexType.Ascending)))
  collection
}

这个问题可能在
文件存储
类中找到。你能把它的内容贴在一张纸上吗?@EECOLOR它很琐碎。。。粘贴到它没有帮助:([info]文件存储应该[error]!在init上显示空上传大小[error]RuntimeException:没有启动的应用程序(package.scala:27)[error]play.api.play$$anonfun$current$1.apply(play.scala:51)[error]play.api.play$$anonfun$current$1.apply(play.scala:51)[error]play.api.play$.play$.current(play.scala:51)[错误]content.FileStorage$.db$lzycompute(FileStorage.scala:36)[错误]content.FileStorage$.db(FileStorage.scala:36)[错误]content.FileStorage$.getfilesize(FileStorage.scala:71)它看起来像是在初始化应用程序之前运行测试用例。FileStorage表示启动测试时没有启动的应用程序,因此插件未准备好,无法访问DB对象。它看起来像“正在运行(FakeApplication())”在一个线程中调用app init,但在另一个线程中执行测试。你能再次发布
文件存储
对象的源代码吗?看起来我并不孤单:我已经复制粘贴了它:我认为只有“val db=ReactiveMongoPlugin.db”才重要