diff --git a/README.md b/README.md index 4b290a5..f2a879b 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/build.sbt b/build.sbt index fba3b54..b3a2857 100644 --- a/build.sbt +++ b/build.sbt @@ -1,7 +1,7 @@ name := "gatling-dubbo" -version := "2.0.1" +version := "2.0.2" scalaVersion := "2.12.6" diff --git a/src/main/scala/io/gatling/dubbo/check/DubboCheckSupport.scala b/src/main/scala/io/gatling/dubbo/check/DubboCheckSupport.scala index 1619668..a2c6dc8 100644 --- a/src/main/scala/io/gatling/dubbo/check/DubboCheckSupport.scala +++ b/src/main/scala/io/gatling/dubbo/check/DubboCheckSupport.scala @@ -9,4 +9,5 @@ trait DubboCheckSupport { def jsonPath(path: Expression[String])(implicit extractorFactory: JsonPathExtractorFactory, jsonParsers: JsonParsers) = DubboJsonPathCheckBuilder.jsonPath(path) -} \ No newline at end of file + def custom = DubboCustomCheck +} diff --git a/src/main/scala/io/gatling/dubbo/check/DubboCustomCheck.scala b/src/main/scala/io/gatling/dubbo/check/DubboCustomCheck.scala new file mode 100644 index 0000000..8bf281d --- /dev/null +++ b/src/main/scala/io/gatling/dubbo/check/DubboCustomCheck.scala @@ -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) + } + } +}