scala-gatling - 如何在 Gatling Simulation 中断言 couchbase 中的记录计数
问题描述
我正在尝试捕获在运行加特林模拟测试时创建的记录。
我的情况是
从 csv 读取 json 数据并发布到由微服务使用的 kafka 并将数据存储到 couchbase 中,
由于kafka以异步模式发布消息,所以我们无法知道在数据库中创建了多少记录。
有什么办法可以从 couchabse 获取数据并断言,如果 couchbase 中的记录不等于请求,那么模拟应该失败?
val scn = scenario("Order test sceanrio")
.feed(csv("TestOrder.csv").circular)
.exec(ProducerBuilder[Array[Byte], Array[Byte]]())
setUp(scn.inject(atOnceUsers(count))).protocols(kafkaProtocol)
//.assertion(getCouchbaseOrderCount == count) // not supported by
加特林
解决方案
我已经通过在模拟中使用 tearDown 解决了这个问题。下面是加特林的拆解代码,
after {
println("**************** Asserting scenario *****************")
assert(orderCount() == count)
}
def orderCount(): Int = {
val cluster = openConnection
val bucket: Bucket = cluster.openBucket("Order", "password");
println(bucket)
val query = "SELECT meta().id FROM `Order`"
Thread.sleep(1000)
val orderCount: Int = bucket.query(N1qlQuery.simple(query)).allRows().size();
println(" Order Count :: " + orderCount)
orderCount
}
推荐阅读
- python - 超过最大递归深度 google colab
- swift - 如何从关联的帐户对 Stripe 客户进行收费
- windows - Windows服务器上的xampp phpmyadmin错误代码500
- indexing - 如何让 __index 和 __newindex 检测 table.index
- mongodb - 如何将我的 mongo 数据库的副本创建到远程服务器
- ruby - Ruby Sort_by 多个参数相反 asc/desc
- eclipse - 如何更改 Eclipse IDE 标题栏
- c# - 如何在 XUnit 中编写端到端测试
- javascript - 通过单击图表Chart js + react打印列表
- azure - Azure C# (.NET) 计时器功能未按计划或手动运行