从csv文件中获取Gatling

时间:2014-04-28 11:46:56

标签: gatling

我创建了一个Gatling模拟,通过创建一个" .har"来自Google Chrome的文件。我已经改变了输入参数和试图从" .csv"中获取数据文件。 现在,当我运行模拟时,如何检查Gatling模拟是否已从" .csv"中获取数据字段。文件?

2 个答案:

答案 0 :(得分:3)

暂时将日志记录级别降低到conf / logback.xml中的DEBUG,您将看到正在生成的请求。

答案 1 :(得分:1)

Gatling有很好的错误处理/记录连接到馈线。

  1. 当您提供错误的文件名或馈送文件的路径时,您将收到以下错误(java.lang.IllegalArgumentException:无法找到馈送器文件)。请注意,测试不会运行。

    java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at io.gatling.mojo.MainWithArgsInFile.runMain(MainWithArgsInFile.java:50)
    at io.gatling.mojo.MainWithArgsInFile.main(MainWithArgsInFile.java:33)
    Caused by: java.lang.IllegalArgumentException: Could not locate feeder file: file gatling/src/test/resources/data/wrongFile.csv doesn't exist
    at io.gatling.core.feeder.FeederSupport$class.feederBuilder(FeederSupport.scala:53)
    at io.gatling.core.Predef$.feederBuilder(Predef.scala:22)
    at io.gatling.core.feeder.FeederSupport$class.separatedValues(FeederSupport.scala:44)
    at io.gatling.core.Predef$.separatedValues(Predef.scala:22)
    at io.gatling.core.feeder.FeederSupport$class.separatedValues(FeederSupport.scala:41)
    at io.gatling.core.Predef$.separatedValues(Predef.scala:22)
    at io.gatling.core.feeder.FeederSupport$class.csv(FeederSupport.scala:34)
    at io.gatling.core.Predef$.csv(Predef.scala:22)
    at com.scenario.Scenario.<init>(Scenario.scala:10)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at java.lang.Class.newInstance(Class.java:442)
    at io.gatling.app.Gatling$.io$gatling$app$Gatling$$$anonfun$1(Gatling.scala:41)
    at io.gatling.app.Gatling.run(Gatling.scala:92)
    at io.gatling.app.Gatling.runIfNecessary(Gatling.scala:75)
    at io.gatling.app.Gatling.start(Gatling.scala:65)
    at io.gatling.app.Gatling$.start(Gatling.scala:57)
    at io.gatling.app.Gatling$.fromArgs(Gatling.scala:49)
    at io.gatling.app.Gatling$.main(Gatling.scala:43)
    at io.gatling.app.Gatling.main(Gatling.scala)
    
  2. 如果您的属性与Feed中的列名不匹配,则会出现以下错误。所有测试都将以错误结束。

    00:10:07.937 [ERROR] i.g.h.a.s.HttpRequestAction - 'httpRequest-1' failed to execute: No attribute named 'wrongAttributeName' is defined
    
  3. 如果您有带有送纸器数据的空文件,则会出现以下错误。

    java.lang.reflect.InvocationTargetException
       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
       at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
       at java.lang.reflect.Method.invoke(Method.java:498)
       at io.gatling.mojo.MainWithArgsInFile.runMain(MainWithArgsInFile.java:50)
       at io.gatling.mojo.MainWithArgsInFile.main(MainWithArgsInFile.java:33)
    Caused by: java.lang.IllegalStateException: Feeder is now empty, stopping engine
       at io.gatling.core.action.SingletonFeed$$anonfun$receive$1.applyOrElse(SingletonFeed.scala:61)
       at akka.actor.Actor$class.aroundReceive(Actor.scala:482)
       at io.gatling.core.akka.BaseActor.aroundReceive(BaseActor.scala:23)
       at akka.actor.ActorCell.receiveMessage(ActorCell.scala:526)
       at akka.actor.ActorCell.invoke(ActorCell.scala:495)
       at akka.dispatch.Mailbox.processMailbox(Mailbox.scala:257)
       at akka.dispatch.Mailbox.run(Mailbox.scala:224)
       at akka.dispatch.Mailbox.exec(Mailbox.scala:234)
       at scala.concurrent.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260)
       at scala.concurrent.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1339)
       at scala.concurrent.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979)
       at scala.concurrent.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107)
    
  4. 如果没有出现这种情况,您几乎可以确定一切正常。但要验证Gatling发送的参数,您可以查看

    1. 在logback.xml中加载日志(将日志记录级别更改为DEBUG)

      <root level="DEBUG">
          <appender-ref ref="CONSOLE" />
      </root>
      

      然后你会看到类似于

      的日志
      00:13:53.233 [DEBUG] i.g.h.a.s.HttpTx$ - Sending request=Action name uri=http://your-rest-service?param1=value1&param2=value2: scenario=com.scenario.Scenario Scenario name, userId=1
      
    2. 访问服务器上的日志。在Tomcat指令中,您可以获得例如here