Skip to content

Commit

Permalink
add custom check
Browse files Browse the repository at this point in the history
  • Loading branch information
sunjun committed Jun 13, 2019
1 parent d2133a5 commit 8db745c
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 3 deletions.
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,17 @@ assemblyOption in assembly := (assemblyOption in assembly).value.copy(includeSca
参考gatling-dubbo/src/test/scala目录下的DubboTest.scala和data.json

`DubboTest.scala`具体说明请参考示例
> 示例中展示的是单接口的例子,如果你想探测应用单机的真实水位,可以结合使用 gatling 的 randomSwitch 混合多接口且按生产环境真实的接口比例同时进行压测。

> check 说明
目前 check 支持两种,jsonPath 和 custom,如果 dubbo 返回值可以转化为 json(如 PlainResult、Map 等),则推荐使用 jsonPath 校验结果,如果 dubbo 返回值是 String 等类型,则推荐使用 custom 校验结果,即自定义校验逻辑,custom 的示例如下:
```scala
.check(custom((response: String) => {
print(response)
response == "expected response"
}, "option error message"))
```

> 示例中展示的是单接口的例子,如果你想探测应用单机的真实水位,可以结合使用 gatling 的 randomSwitch 混合多接口且按生产环境真实的接口比例同时进行压测。
`data.json`
```json
Expand Down
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

name := "gatling-dubbo"

version := "2.0.1"
version := "2.0.2"

scalaVersion := "2.12.6"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ trait DubboCheckSupport {
def jsonPath(path: Expression[String])(implicit extractorFactory: JsonPathExtractorFactory, jsonParsers: JsonParsers) =
DubboJsonPathCheckBuilder.jsonPath(path)

}
def custom = DubboCustomCheck
}
17 changes: 17 additions & 0 deletions src/main/scala/io/gatling/dubbo/check/DubboCustomCheck.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package io.gatling.dubbo.check

import io.gatling.commons.validation._
import io.gatling.core.check.CheckResult
import io.gatling.core.session.Session
import io.gatling.dubbo.DubboCheck

import scala.collection.mutable

case class DubboCustomCheck(func: String => Boolean, failureMessage: String = "Dubbo check failed") extends DubboCheck {
override def check(response: String, session: Session)(implicit cache: mutable.Map[Any, Any]): Validation[CheckResult] = {
func(response) match {
case true => CheckResult.NoopCheckResultSuccess
case _ => Failure(failureMessage)
}
}
}

0 comments on commit 8db745c

Please sign in to comment.