Skip to content

Commit

Permalink
delete param()
Browse files Browse the repository at this point in the history
  • Loading branch information
sunjun-qima committed Apr 16, 2019
1 parent 24e5433 commit 567efad
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 34 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# Gatling-Dubbo 2.0
`【招聘】Java开发、测试开发等岗位,有意者请将简历投递至<sunjun【@】youzan.com>`
`【招聘】Java开发、测试开发等岗位,有意者请将简历投递至<canyuns【@】163.com>`

Gatling的非官方Dubbo压测插件,基于Gatling 2.3.1,插件已在Dubbo 2.6.5上测试,但理论上所有Dubbo版本都适用,`2.0插件采用普通API调用方式执行压测请求,如果你想使用泛化调用方式执行压测请求,请参考`[1.0插件](https://github.com/youzan/gatling-dubbo/tree/v1.0)`,推荐使用2.0插件,即采用普通API调用方式,因为 dubbo 官方推荐生产上使用该方式,所以以同样的方式压测得到的结果,更具有参考意义,且2.0插件无需 dubbo 框架做任何改造。`

> 区别于 Gatling-Dubbo 1.0 只支持 dubbo 压测,Gatling-Dubbo 2.0 不仅支持 dubbo 压测,还支持非 dubbo 的其他 java 调用压测,因为脚本中的 `f、param` 怎么写控制权在你手里,就像使用 Jmeter 压测 java 一样。
> 区别于 Gatling-Dubbo 1.0 只支持 dubbo 压测,Gatling-Dubbo 2.0 不仅支持 dubbo 压测,还支持非 dubbo 的其他 java 调用压测,因为脚本中的 `f` 怎么写控制权在你手里,就像使用 Jmeter 压测 java 一样。
## 使用方法

Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/io/gatling/dubbo/DubboDsl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import scala.language.implicitConversions

trait DubboDsl extends DubboCheckSupport {

def dubbo[A](requestName: Expression[String], f: (Array[Object], Session) => A, param: Array[Object]) = DubboProcessBuilder[A](requestName, f, param)
def dubbo[A](requestName: Expression[String], f: (Session) => A) = DubboProcessBuilder[A](requestName, f)

implicit def dubboProcessBuilder2ActionBuilder[A](builder: DubboProcessBuilder[A]): ActionBuilder = builder.build()

Expand Down
5 changes: 2 additions & 3 deletions src/main/scala/io/gatling/dubbo/action/DubboAction.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ import scala.util.{ Success, Failure => UFailure }

class DubboAction[A](
requestName: Expression[String],
f: (Array[Object], Session) => A,
param: Array[Object],
f: (Session) => A,
val executor: ExecutorService,
val objectMapper: ObjectMapper,
checks: List[DubboCheck],
Expand All @@ -40,7 +39,7 @@ class DubboAction[A](
val startTime = System.currentTimeMillis()
val fu = Future {
try {
f(param, session)
f(session)
} finally {
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ import io.gatling.core.session.Expression
import io.gatling.core.structure.ScenarioContext
import io.gatling.dubbo.DubboCheck

case class DubboActionBuilder[A](requestName: Expression[String], f: (Array[Object], Session) => A, param: Array[Object], checks: List[DubboCheck], threadPoolSize: Int) extends ActionBuilder {
case class DubboActionBuilder[A](requestName: Expression[String], f: (Session) => A, checks: List[DubboCheck], threadPoolSize: Int) extends ActionBuilder {

override def build(ctx: ScenarioContext, next: Action): Action = {
import ctx._
val executor = Executors.newFixedThreadPool(threadPoolSize)
val objectMapper: ObjectMapper = new ObjectMapper()
new DubboAction[A](requestName, f, param, executor, objectMapper, checks, coreComponents, throttled, next)
new DubboAction[A](requestName, f, executor, objectMapper, checks, coreComponents, throttled, next)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import io.gatling.dubbo.DubboCheck
import io.gatling.dubbo.action.DubboActionBuilder
import io.gatling.dubbo.check.DubboCheckSupport

case class DubboProcessBuilder[A](requestName: Expression[String], f: (Array[Object], Session) => A, param: Array[Object], checks: List[DubboCheck] = Nil, threadPoolSize: Int = 200) extends DubboCheckSupport {
case class DubboProcessBuilder[A](requestName: Expression[String], f: (Session) => A, checks: List[DubboCheck] = Nil, threadPoolSize: Int = 200) extends DubboCheckSupport {

def check(dubboChecks: DubboCheck*): DubboProcessBuilder[A] = copy[A](checks = checks ::: dubboChecks.toList)

def threadPoolSize(threadPoolSize: Int): DubboProcessBuilder[A] = copy[A](threadPoolSize = threadPoolSize)

def build(): ActionBuilder = DubboActionBuilder[A](requestName, f, param, checks, threadPoolSize)
def build(): ActionBuilder = DubboActionBuilder[A](requestName, f, checks, threadPoolSize)
}
31 changes: 7 additions & 24 deletions src/test/scala/DubboTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
//
//import com.youzan.xxx.XxxService //引入应用 API
//
//import com.alibaba.dubbo.config.utils.ReferenceConfigCache
//import com.alibaba.dubbo.config.utils.ReferenceConfigCache.KeyGenerator
//import com.alibaba.dubbo.config.{ApplicationConfig, ReferenceConfig}
//import io.gatling.core.Predef._
//import io.gatling.core.session.Session
Expand All @@ -27,29 +25,20 @@
// // reference.setVersion("1.0.0") //设置版本号,可以不设置
// // reference.setTimeout(3000) //设置超时时间,可以不设置
//
// //缓存逻辑
// val keyGenerator = new KeyGenerator {
// def generateKey(referenceConfig: ReferenceConfig[_]): String = {
// referenceConfig.getUrl
// }
// }
// val cache = ReferenceConfigCache.getCache("_DEFAULT_", keyGenerator)
// val xxxService = cache.get(reference) //已缓存就直接返回, 未缓存的话就初始化并放入缓存, 下次就可以直接返回
//
//
// val xxxService = reference.get()
//
// /**
// * gatling 压测逻辑
// * dubbo 压测插件的 api 只有一个,即 dubbo("com.youzan.xxx.XxxService", f, param())
// * dubbo 压测插件的 api 只有一个,即 dubbo("com.youzan.xxx.XxxService", f)
// * 第一个参数可以是任意字符串,不过为了方便统计接口级的性能基线,建议设置为全限定接口名
// * 第二、第三个参数的作用下面会讲述,名字也可以自行设置
// * 第二个参数的作用下面会讲述,名字也可以自行设置
// */
// val jsonFileFeeder = jsonFile("data.json").circular
// val dubboScenario = scenario("scenario of xxx")
// .forever("tripsCount") {
// feed(jsonFileFeeder)
// .exec(
// dubbo("com.youzan.xxx.XxxService", f, param())
// dubbo("com.youzan.xxx.XxxService", f)
// .check(jsonPath("$.success").is("true")) //基于 jsonpath 校验返回结果
// .check(jsonPath("$.data.totalCount").is("9")) //更多校验
// // .threadPoolSize(200) //4C8G施压机默认使用200线程池,你也可以根据施压机资源情况自行设置,一般不需要设置
Expand All @@ -63,15 +52,9 @@
// holdFor(30 seconds))
// )
//
//
//
// //为 f 提供参数(非动态参数,即不需要从外部json文件读入的参数,如设置DTO的部分固定字段),参数都放到 Array[Object] 里返回
// def param(): Array[Object] = {
// Array.empty[Object]
// }
//
// //接口调用逻辑,这里从param取出各个参数,并使用session中的动态参数设置完全这些参数;或者直接从session取参数设置,注意参数类型需一致,不一致就做相应的转化
// def f(param: Array[Object], session: Session): Object = {
// //接口调用逻辑,包括入参构造和设置. 注意参数类型需一致,不一致就做相应的转化
// def f(session: Session): Object = {
// //如果方法的入参是复杂对象, 必须在这里 new 对象和 set 字段
// xxxService.getXxxList(session.attributes("kdtId").asInstanceOf[Integer].toLong, session.attributes("page").asInstanceOf[Integer])
// }
//
Expand Down

0 comments on commit 567efad

Please sign in to comment.