【发布时间】:2016-07-12 18:28:17
【问题描述】:
这是我的测试套装的配置方式。
"test payments" should {
"Add 100 credits" in {
runTeamTest { team =>
withRunningKafka {
val addCreditsRequest = AddCreditsRequest(team.id.stringify, member1Email, 100)
TestCommon.makeRequestAndCheck(
member1Email,
TeamApiGenerated.addCredits().url,
Helpers.POST,
Json.toJson(addCreditsRequest),
OK
)
val foundTeam = TestCommon.waitForFuture(TeamDao.findOneById(team.id))
foundTeam.get.credits mustEqual initialCreditAmount + 100
}
}
}
"deduct 100 credits" in {
runTeamTest { team =>
withRunningKafka {
val deductCreditsRequest = DeductCreditsRequest(team.id.stringify, member1Email, 100)
TestCommon.makeRequestAndCheck(
member1Email,
TeamApiGenerated.deductCredits().url,
Helpers.POST,
Json.toJson(deductCreditsRequest),
OK
)
val foundTeam = TestCommon.waitForFuture(TeamDao.findOneById(team.id))
foundTeam.get.credits mustEqual initialCreditAmount - 100
}
}
}
在 Scalatest 中,总体套装名称是 "test payments",其中的后续测试在运行第一个测试后会出现问题。如果我分别运行这两个测试中的每一个,它们都会成功,但如果我运行整个套装,第一个成功,第二个返回 org.apache.kafka.common.errors.UnknownTopicOrPartitionException: This server does not host this topic-partition. 异常。上面的代码没有显示正在测试的控制器中的代码,但是在控制器中,我有一个不断轮询的 kafka 消费者,并且在测试中没有调用 close()。
【问题讨论】: