3

ファイルを取得し、特別なメタデータを使用して 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 アプリケーションをどのようにテストしますか?

4

1 に答える 1

2

FileStorageオブジェクトには、次の行があります。

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
}
于 2013-09-16T10:01:26.387 に答える