【发布时间】:2017-03-21 16:42:34
【问题描述】:
我希望能够将参数传递给 Gatling Simulation。我已经尝试过了,但是它失败了。 (问题似乎是由于内部类)
object PerfTestManager extends App {
run("trymain", 10, 2, 3);
def run(dcName: String, minutes: Int, threads: Int, maxThreads: Int) = {
class BasicSimul extends Simulation {
val scn = scenario("a").feed(QueryFeeder.myfeeder)
.exec(http("test").get(s => SolrEnv.getPath(s("params").validate[String].get)));
private val hostport = SolrEnv.hostport
val httpConf = http.baseURL(hostport)
.acceptHeader("text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8")
.acceptEncodingHeader("gzip, deflate")
.acceptLanguageHeader("en-US,en;q=0.5")
.userAgentHeader("Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:16.0) Gecko/20100101 Firefox/16.0");
setUp(scn.inject(atOnceUsers(threads)).protocols(httpConf))
}
val simClass = classOf[BasicSimulation].getName
val props = new GatlingPropertiesBuilder
props.dataDirectory(Paths2.dataDirectory.toString)
props.resultsDirectory(Paths2.resultsDirectory.toString)
props.bodiesDirectory(Paths2.bodiesDirectory.toString)
props.binariesDirectory(Paths2.mavenBinariesDirectory.toString)
props.simulationClass(simClass)
props.runDescription("runonce")
props.outputDirectoryBaseName("0")
Gatling.fromMap(props.build) // <-- failing line
}
}
我的意图是最终运行一个 web 服务,该服务将用于从 UI 调度和参数化模拟。虽然我有一些可以尝试的替代方案,但更接近上述代码的东西似乎最容易维护。上述代码失败,因为 gatling 无法创建 BasicSimul 的实例
Caused by: java.lang.NoSuchMethodException: computerdatabase.PerfTestManager$BasicSimul$1.<init>()
at java.lang.Class.getConstructor0(Class.java:3082)
at java.lang.Class.newInstance(Class.java:412)
我也尝试将参数传递给 BasicSimulation,但是,该框架需要一个默认构造函数,因此也没有成功。
我的替代方法是在 object 中声明以下内容
val q = 新队列
调度webservice会根据参数入队一个新的TestConfig,BasicSimulation会dequeue()得到它的TestConfig。同步构造可用于避免竞争条件。
【问题讨论】: