Saturday 15 February 2014

scala - Getting the String out of a Gatling expression -



scala - Getting the String out of a Gatling expression -

i want write function format vaadin messages. these messages have format

108|0ff1255e-e2be-4e7b-ac5c-1ff2709ce886[["0_11_12_13_login_username","v","v",["text",["s","agent00232"]]]]

the first number length there kind of session id (later called vaadin_security_key) followed payload. (in illustration set value "agent00232" textfield connector id "0_11_12_13_login_username") wrote function this:

def sendmessage(name: string, vaadincommand: string) = { def createmessage(session: session) = { val message = session("vaadin_security_key").as[string] + "\u001d" + vaadincommand val message2 = elcompiler.compile(message)(classtag[string])(session).tostring val message3 = message2.substring(8, message2.length - 2) val len = message3.length val completemessage = len.tostring() + "|" + message3 completemessage } exec( ws(name) .sendtext(createmessage) .check(wsawait .within(vaadin.defaulttimeout) .until(1) .regex("""(.+)""") .saveas("lastresult"))) .exec { session => println(session("lastresult").as[string]) session } }

i'd utilize method , utilize el expressions in string:

exec(vaadin.sendmessage("setting name", "[[\"0_11_12_13_login_username\",\"v\",\"v\",[\"text\",[\"s\",\"${username}\"]]]]"))

therefore have evaluate string before calculating length. method elcompiler.compile()... returns expression[string]. problem need string , concat calculated length. when message2.tostring returns success(0ff1255e-e2be-4e7b-ac5c-1ff2709ce886[["0_11_12_13_login_username","v","v",["text",["s","agent00232"]]]]) , therefor have utilize substring(8, message2.length - 2) evaluated payload (with security key) calculate length of it.

is there improve (more elegant) way extract string out of look utilize of substring(...)?

don't explicitly pass classtag elcompiler.compile. if utilize yourself, utilize elcompiler.compile[string] elcompiler.compile returns expression[string], alias function of session validation[string], if apply it, validation[string] (because evaluation fail), hence tostring prints success, not value contains. want map validation container. you're compiling look on , on again, on each function execution. move outside function. beware session("lastresult").as[string] crash if lastresult not saved. utilize validate instead. use triple quotes don't have escape inner double quotes

the first part of code like:

import io.gatling.core.session._ import io.gatling.core.session.el._ def sendmessage(name: string, vaadincommand: string) = { val message = ("${vaadin_security_key}\u001d" + vaadincommand).el[string] def createmessage = message.map { resolvedmessage => resolvedmessage.length + "|" + resolvedmessage } exec( ws(name) .sendtext(createmessage) .check(wsawait .within(vaadin.defaulttimeout) .until(1) .regex("""(.+)""") .saveas("lastresult"))) .exec { session => println(session("lastresult").validate[string]) session }

}

then you'd phone call with:

exec(vaadin.sendmessage("setting name", """[["0_11_12_13_login_username","v","v",["text",["s","${username}"]]]]"""))

scala vaadin gatling

No comments:

Post a Comment