I am writing a sort of integration testing using Scala driver for Mongodb (1.1.1).
I have a simple insert query and I am able to manage it using either a future
or observer
in this way:
// with observer
driver.myCollection.insertOne(doc).subscribe(new Observer[Completed] {
override def onNext(result: Completed) = /* do something */
override def onComplete() = /* do something */
override def onError(e: Throwable) = /* do something */
})
// with future
val f = driver.myCollection.insertOne(doc).toFuture()
f onComplete {
case Success(successMsg) => /* do something */
case Failure(failureMsg) => /* do something */
}
}
How can I test onError
in the Observer
and/or Failure
in the Future
?
How can I trigger this condition?
At the moment I am using Mongodb Embedded (flapdoodle)
.
If I shutdown the Mongodb at the beginning of the test, I get a timeout which doesn't look related to that errors.
UPDATE
I have added WriteConcern
to the collection:
database.getCollection(myCollection).withWriteConcern(WriteConcern.ACKNOWLEDGED)
but it doesn't change anything.
Are the errors returned by futures/observers including timeout errors (caused when the db or network are down for some reasons)?