【问题标题】:Parameterized simulation in Gatling load testsGatling 负载测试中的参数化仿真
【发布时间】: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,BasicSimulationdequeue()得到它的TestConfig。同步构造可用于避免竞争条件。

【问题讨论】:

    标签: scala gatling


    【解决方案1】:

    我认为你可以通过创建一个简单的 Scala 类来更好地实现上述行为。基本上你可以创建一个对象

    object Configuration{
     val file = getClass.getResource("data/config.properties").getFile()
     val prop = new Properties()
     prop.load(new FileInputStream(file))
     ENV =prop.getProperty("env");
    }
    

    现在在你的模拟课上

    class TestSimulation extends Simulation {
       val ALL_STOP_STATUS = Configuration.ENV;
     }
    

    使用路径变量同样专门化它

    【讨论】:

    • 当我的应用程序尝试运行基于相同模拟类但具有不同设置的并行负载测试时,问题就出现了。这将需要我对环境变量进行某种同步
    • 不需要同步...只需更改逻辑以从类路径读取并用类实例替换对象
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多