首页 > 解决方案 > 如何在 Gatling Simulation 中断言 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

加特林

标签: scala-gatling

解决方案


我已经通过在模拟中使用 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

}


推荐阅读