append to session Map

473 views
Skip to first unread message

Shree Chatterjee

unread,
Nov 16, 2013, 2:25:03 AM11/16/13
to gat...@googlegroups.com
Hi,

How to I achieve this in Gatling (with reference to the code below):

1/Append to a session Map as we go through chain of execs 
2/Use a session Map value in http call body or header.


for e.g. :
I'd like to use PERSON_INFO_MAP("payloadMDM") in the subsequent subsequent http .body,
and subsequently 'wd like to capture the response (.check(bodyString.saveAs("soapReply"))), and append to the same session map like say append ("soapReplyXML", "soapReply)
to PERSON_INFO_MAP, which can be used as payload in some subsequent api call.

Thank you
shree



                              //part of .exec(session=>{ function
                               var payload=Payloads.requestMDM//a XML String
val PERSON_INFO_MAP = Map(
("firstName", firstName.trim()),
("lastName", lastName.trim()),
("middleName", middleName.trim()),
("company", company),
("state", state),
("city", city),
("addressLine", addressLine.trim()),
("zip", zip.trim()),
("email", email.trim()),
("username", username.trim()),
("phoneNo1", "858-215-5555"),
("phoneNo2", "858-215-5553"),
("acName", acName),
("country", "US"),
("payloadMDM",payload)
);

session.set("PERSON_INFO_MAP",PERSON_INFO_MAP);
})
.exec(
http("my_call")
.header("Content-Type"," text/xml; charset=UTF-8")
.header("SOAPAction","syncAccount")
.body(StringBody("""${session("PERSON_INFO_MAP").as[Map[String, String]]("payloadMDM")}""")) //------->>>>>>This throws ERROR !!!
.check(status.is(200))
.check(bodyString.saveAs("soapReply"))
                                         //------>>would like to append this response as key to the PERSON_INFO_MAP
                                         //--->> to be used as input to subsequent api call. This resets the session. I loose PERSON_INFO_MAP !!!

)

Stefan Magnus Landrø

unread,
Nov 16, 2013, 3:23:11 PM11/16/13
to gat...@googlegroups.com
I've never added a map to the session, but you can certainly add individual attributes.

The it would lookk something like this:

SringBody("${payloadMDM}")

HTH

Stefan

Shree Chatterjee

unread,
Nov 16, 2013, 10:15:53 PM11/16/13
to gat...@googlegroups.com
Thank you Stefan. Let me generalize the problem. I'm new to Scala and Gatling, so I may be missing things.
The scenario consists of multiple execs like below.
In each of .execs I do some processing, and generate key, value pairs which can be needed by any of the subsequent execs.

In any .exec only the latest session.set value is available to the subsequent execs (see illustration below)

1/So what is the best practice here to persist multiple attributes in a session ?

To solve this problem I was trying to use maps.
But in subsequent http() DSL, I was not able to get the key value by SringBody("${PERSON_INFO_MAP("payloadMDM")}")
2/I see support for Lists bout not Maps


.exec(session=>{

..
session.set("key1","value1")
session.set("key2",value2")

})
.exec(session=>{
..
//This throws error- key not found
val myKey= session("key1").as[String]

//This works
val myKey= session("key2").as[String]


})
.exec(
 http("api_call")
          ...
)
.exec(session=>{

})
.exec(
 http("api_call")


Thank you
shree

Stefan Magnus Landrø

unread,
Nov 17, 2013, 2:07:10 AM11/17/13
to gat...@googlegroups.com
set returns a new session. Functional style. No side effects. 

Sendt fra min iPhone
--
You received this message because you are subscribed to a topic in the Google Groups "Gatling User Group" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/gatling/WoNidZYZVT8/unsubscribe.
To unsubscribe from this group and all its topics, send an email to gatling+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Stéphane Landelle

unread,
Nov 17, 2013, 7:43:12 AM11/17/13
to gat...@googlegroups.com
You're misunderstanding how Gatling EL works.
As stated in the documentation, Gatling EL is very simple and just a convenient way to build simple dynamic things instead of writing functions. This is absolutely not a full fledged dynamic language.

So, real scala code cannot be embedded into Gatling EL like you did.
Moreover, Gatling EL and functions cannot be mixed as EL strings are implicitly compiled into functions and that compilation is not triggered inside function.

Now, back to your problem:

StringBody(session => session("PERSON_INFO_MAP").as[Map[String, String]]("payloadMDM"))

Cheers,

Stéphane

2013/11/17 Stefan Magnus Landrø <stefan...@gmail.com>

--
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.

Shree Chatterjee

unread,
Nov 18, 2013, 12:21:26 PM11/18/13
to gat...@googlegroups.com
Thank you for the clarifications.
Reply all
Reply to author
Forward
0 new messages