mercredi 17 août 2016

gatling/Scala: Write custom feeder (read csv from url) - random iterator?

I am new to scala and I try to write a custom feeder for gatling that reads a csv file from a url (similar jsonUrl-Feeder).

I am insecure about how to do this. I tried the following, but now I need to implement additional methods:

package common

import scala.io.Source
import scala.collection.mutable.ListBuffer

class CsvURLFeeder(url: String) extends Map[String, String] {

 val source = Source.fromURL(url)
 val reader = source.bufferedReader()

 val attributeName = reader.readLine()

 var list : ListBuffer[Map[String, String]] = new ListBuffer[Map[String, String]]() 

 val input = Stream.continually(reader readLine)
 //println(input)


 for( line <- input){
   //println(line)
   list += Map(attributeName-> line) 
 }

 def getFeeder() : Iterator[Map[String, String]]  = {
   return list.iterator
 }

}

missing methods:

// Members declared in scala.collection.immutable.Map
def +[B1 >: String](kv: (String, B1)): scala.collection.immutable.Map[String,B1] = ???

// Members declared in scala.collection.MapLike
def -(key: String): scala.collection.immutable.Map[String,String] = ???
def get(key: String): Option[String] = ???
1def iterator: Iterator[(String, String)] = ???

Also, I have no idea how to make the iterator random. I don't want to go through the list one by one.

Isn't there a similar feeder who does the same stuff for me? Or what would be the best way to implement such a feeder?

Thanks in advance.




Aucun commentaire:

Enregistrer un commentaire