scenario( name )
.exec(
http( desc )
.get( path )
.check( jsonPath( "$.result[*]" ).saveAs( OBJECT_LIST ) )
)
// pick one of the objects at random
.set( OBJECT_JSON ).from( OBJECT_LIST ) // I may change the syntax to make it more obvious
.extract( "$.id" ).from( $(OBJECT_JSON) ).into( OBJECT_ID )
import scala.util.Random
import io.gatling.core.session.{ Expression, Session }
import io.gatling.core.Predef._
import io.gatling.core.validation._
import io.gatling.core.structure.ChainBuilder
import io.gatling.core.json.Boon
import io.gatling.core.check.extractor.jsonpath._
object SessionManagement {
implicit class SessionManagementExtensions( val c : ChainBuilder ) {
trait SetSessionVariableAPI {
def from( src: String ) : ChainBuilder
def to[T]( value: Expression[T] ) : ChainBuilder
}
def set( dest: String ) = new SetSessionVariableAPI {
def from( src: String ) =
c.exec( session => {
val list = session( src ).as[Vector[String]]
val i = if ( list.size == 0 ) -1 else Random.nextInt( list.size )
val value = if ( i > 0 ) list(i) else "INVALID_" + dest
session.set( dest, value )
})
def to[T]( value: Expression[T] ) =
c.exec( session => session.set( dest, value(session) ) )
}
trait ExtractFromInto { def into( name: String ) : ChainBuilder }
trait ExtractFrom { def from( json: Expression[String] ) : ExtractFromInto }
def extract( path: String ) = new ExtractFrom {
def from( json: Expression[String] ) = new ExtractFromInto {
def into( name: String ) =
c.exec( session => {
val parsed = Boon.parse( json(session).toString )
session.set( name, JsonPathExtractor.extractAll[String]( parsed, path ).get )
})
}
}
}
}11:56:52.169 [ERROR] i.g.a.ZincCompiler$ - /src/rtde-testing/performance/rtde/simulations/com/cigna/rtde/scenarios/sandbox.scala:17: value set is not a member of io.gatling.core.structure.ChainBuilder
possible cause: maybe a semicolon is missing before `value set'?
11:56:52.172 [ERROR] i.g.a.ZincCompiler$ - .set( "FOO" ).to("bar")
11:56:52.173 [ERROR] i.g.a.ZincCompiler$ - ^Can you see what I'm doing wrong that might cause me to get this kind of an error?
--
You received this message because you are subscribed to the Google Groups "Gatling User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gatling+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
object SessionManagement {
implicit class SessionManagementExtensions( val c : ChainBuilder ) {
def evaluate( session: Session, string: Expression[String] ) : Any = string(session) match {
case Success(x) => x
case Failure(msg) => throw new Error(msg)
}
trait SetSessionVariableAPI {
def from( src: String ) : ChainBuilder
def to( value: Any ) : ChainBuilder
}
def set( dest: String ) = new SetSessionVariableAPI {
def from( src: String ) =
c.exec( session => {
session.set( dest, session.attributes(src) match {
case s:String => s
case list:Vector[String] => {
val i = if ( list.size == 0 ) -1 else Random.nextInt( list.size )
if ( i >= 0 ) list(i)
else "INVALID_" + dest
}
}
)
} )
def to( value: Any ) =
c.exec( session => session.set( dest, value match {
case s:String => evaluate( session, s )
case _ => value
} ) )
}
trait ExtractFromInto { def into( name: String ) : ChainBuilder }
trait ExtractFrom { def from( json: String ) : ExtractFromInto }
def extract( path: String ) = new ExtractFrom {
def from( json: String ) = new ExtractFromInto {
def into( name: String ) =
c.exec( session => {
val parsed = Boon.parse( evaluate( session, json ).toString )
session.set( name,
JsonPathExtractor.extractAll[String]( parsed, path ) match {
case Success(x) => {
if ( x.isEmpty ) ""
else {
val list = x.toList
if ( list.size > 1 ) list.toVector
else list.head
}
}
case Failure(msg) => throw new Error(msg)
}
)
})
}
}
}
}