Performance Tool(4)CSV File Data Feeder

Performance Tool(4)CSV File Data Feeder

Using CSV File Feeder
val callbackDevice = exec(http("push_callback_events")
    .post("/api/brands/"+ brand + "/events")
    .body(EventJSONEntities.pushCallbackEventJson("${deviceId}", "${latitude}","${longitude}", appId, campaignId))
    .headers(headers)
    .check(status.is(200))
    .check(bodyString))

val latlngFeed = csv("latlng_information.csv”)
val multiScn = scenario("Push Callback Events Scenario")
    .repeat(repeatTimes){ feed(latlngFeed).feed(deviceRegFeed).exec(callbackDevice) }


Content of latlng_information.csv
latitude,longitude
-97.741921,30.359960
-97.732911,30.341110
-92.934343,31.313434

Generate CSV File
package apps

import base.Environment
import com.excilys.ebi.gatling.core.Predef._
import events.EventFeeds
import java.util.concurrent.atomic.AtomicInteger
import org.joda.time.DateTime
import java.io.File
import scala.io.Source

/**
 * Created by carl on 7/28/14.
 */
object FailDeviceFinder extends Environment {

  def main(args: Array[String]) {
  val deviceRegFeed = EventFeeds.deviceStableFeeder(5)

  val src = Source.fromFile(new File("userfiles/data/serveraws1_device.csv")).getLines
  //val headerLine = src.take(1).next

  val csvMap = src.toList

  printToFile(new File("userfiles/data/serveraws1_fails.csv"))( p =>{
    p.println("deviceId,regKey")
    while(deviceRegFeed.hasNext) {
    val n = deviceRegFeed.next
    val deviceId = n.getOrElse("deviceId","null")
    val regKey = n.getOrElse("regKey","null")
    if(!csvMap.contains(deviceId)){
      p.println(deviceId + "," + regKey)
    }
    }
  })

  }


  def printToFile(f: java.io.File)(op: java.io.PrintWriter => Unit) {
    val p = new java.io.PrintWriter(f)
    try { op(p) } finally { p.close() }
  }

}

All the example is here:
https://github.com/luohuazju/sillycat-gatling/tree/gatling-1.5.6


References:
http://sillycat.iteye.com/blog/2096198



猜你喜欢

转载自sillycat.iteye.com/blog/2108460