我正在使用specs2来测试我的播放应用程序。但是,我遇到了一个奇怪的问题。
下面是我的测试代码(只是忽略中文):
class ThrottlersTest extends PlaySpecification with AroundTimeout {
type EE = ExecutionEnv
val apiKey = ApiKey(99, "taobao.crm.members.get")
trait ThrottlerContext extends WithApplication {
implicit val ee: EE = ExecutionEnv.create(Arguments(), org.specs2.control.consoleLogging, "test")
val throttlersRef = app.injector.instanceOf[InjectedThrottler].actor
}
"一个限速为10次每秒的限流器" should {
"在接收到第一条消息的时候应该初始化自己,并且回复Passed" in new ThrottlerContext {
await((throttlersRef ? apiKey).mapTo[Passed.type]) must equalTo(Passed)
}
"在一秒内发送11条消息时,前十条回复Passed,第11条回复Limited" in new ThrottlerContext {
upTo(1 seconds) {
for (i <- 1 to 10) {
await((throttlersRef ? apiKey).mapTo[Passed.type]) must equalTo(Passed)
}
await((throttlersRef ? apiKey).mapTo[Limited]) must beAnInstanceOf[Limited]
}
}
}
}
object ThrottlersTest {
/**
* 用来注入Throttler. 绑定关系见
* @see modules.TopModule
*/
case class InjectedThrottler @Inject()(@Named("throttlers") actor: ActorRef)
}
如果我在控制台中使用sbt test
,则此代码正确运行。但是,如果我在intellij中使用默认的specs2 runner:
它抛出异常如下:
play.api.db.evolutions.InconsistentDatabase: Database 'default' is in an inconsistent state![An evolution has not been applied properly. Please check the problem and resolve it manually before marking it as resolved.]
@6nl3m44fd: Database 'default' is in an inconsistent state!
at play.api.db.evolutions.DatabaseEvolutions.checkEvolutionsState(EvolutionsApi.scala:269)
at play.api.db.evolutions.DatabaseEvolutions.evolve(EvolutionsApi.scala:226)
Intellij Idea中的执行一定有问题。如果我在代码中只放了一个in new WithApplication
,问题就会消失。
我认为应该有办法解决这个问题。任何解决方案的建议都非常感谢。提前谢谢。