# Extracting method with session

**URL:** <https://community.gatling.io/t/extracting-method-with-session/1169>\
**Category:** Gatling (Open-Source)\
**Created:** [July 14, 2014, 10:41am UTC](https://community.gatling.io/t/extracting-method-with-session/1169 "2014-07-14T10:41:44Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Andrei\_Proskurin](https://avatars.discourse-cdn.com/v4/letter/a/977dab/32.png) [@Andrei\_Proskurin](https://community.gatling.io/u/Andrei_Proskurin)\
**Post date:** [July 14, 2014, 10:41am UTC](https://community.gatling.io/t/extracting-method-with-session/1169/1 "2014-07-14T10:41:44Z")

</div>

I have this method that works perfectly:

.exec(http(“Vajuta kustuta”)  
.get(session =\> “/?0-1.ILinkListener-bodyPanel-contentComponent-vat\_declarations-” + someCounter + “-delete”)  
)  
.pause(2)

For each user it increments the counter which is defined:

def someCounter = deleteCounter.getAndIncrement

But when I create a method:

def testGetIt(requestTitle: String,  
requestURL: String,  
pause: Int) = {  
exec(http(requestTitle).get(session =\> requestURL)  
).pause(pause)  
}

and when I call it, it doesn’t get incremented and instead of deleting any number of rows from DB it only deletes 1.

---

<div class="post-metadata">

**Author:** ![Andrei\_Proskurin](https://avatars.discourse-cdn.com/v4/letter/a/977dab/32.png) [@Andrei\_Proskurin](https://community.gatling.io/u/Andrei_Proskurin)\
**Post date:** [July 14, 2014, 1:12pm UTC](https://community.gatling.io/t/extracting-method-with-session/1169/2 "2014-07-14T13:12:52Z")

</div>

Still haven’t found the solution. The same problem occurs with my post request method:

def postMePlease(requestTitle: String,  
requestURL: String,  
pause: Int,  
listOfParams: Seq[(String, String)]) = {  
exec(http(requestTitle)  
.post(requestURL)  
.formParamSeq(listOfParams))  
.pause(pause)  
}

Where the list of params is:

Seq((“transactionsWithRate20”, someNumber.toString),  
(“someParam”, “someValue”))

And someNumber is def someNumber = randomNumber.nextInt(40)

The value is the same for all sessions. What could I do so someNumber would acquire different values?

---

<div class="post-metadata">

**Author:** ![Excilys](https://avatars.discourse-cdn.com/v4/letter/e/8797f3/32.png) [@Excilys](https://community.gatling.io/u/Excilys)\
**Post date:** [July 14, 2014, 3:56pm UTC](https://community.gatling.io/t/extracting-method-with-session/1169/3 "2014-07-14T15:56:48Z")

</div>

It’s just impossible to get a picture of what you’re doing with just those fragments.  
Could you post a [gist](https://gist.github.com/), please?

---

<div class="post-metadata">

**Author:** ![Andrei\_Proskurin](https://avatars.discourse-cdn.com/v4/letter/a/977dab/32.png) [@Andrei\_Proskurin](https://community.gatling.io/u/Andrei_Proskurin)\
**Post date:** [July 15, 2014, 7:39am UTC](https://community.gatling.io/t/extracting-method-with-session/1169/4 "2014-07-15T07:39:45Z")

</div>

Thank you for a reply! Here is a sample of what I’m trying to do:  
[https://gist.github.com/anonymous/f26b7a0334ce15a6fe17](https://gist.github.com/anonymous/f26b7a0334ce15a6fe17)

---

<div class="post-metadata">

**Author:** ![Excilys](https://avatars.discourse-cdn.com/v4/letter/e/8797f3/32.png) [@Excilys](https://community.gatling.io/u/Excilys)\
**Post date:** [July 15, 2014, 7:50am UTC](https://community.gatling.io/t/extracting-method-with-session/1169/5 "2014-07-15T07:50:04Z")

</div>

Your gist doesn’t compile!

[https://gist.github.com/anonymous/f26b7a0334ce15a6fe17#file-loadtest-scala-L37](https://gist.github.com/anonymous/f26b7a0334ce15a6fe17#file-loadtest-scala-L37): getIt expects 3 parameters and you pass 4

[https://gist.github.com/anonymous/f26b7a0334ce15a6fe17#file-loadtest-scala-L42](https://gist.github.com/anonymous/f26b7a0334ce15a6fe17#file-loadtest-scala-L42): what is this leading dot doing here?!

---

<div class="post-metadata">

**Author:** ![Andrei\_Proskurin](https://avatars.discourse-cdn.com/v4/letter/a/977dab/32.png) [@Andrei\_Proskurin](https://community.gatling.io/u/Andrei_Proskurin)\
**Post date:** [July 15, 2014, 8:08am UTC](https://community.gatling.io/t/extracting-method-with-session/1169/6 "2014-07-15T08:08:16Z")

</div>

Sorry for that, this should compile:  
[https://gist.github.com/anonymous/57570cbeba8c42a58da4](https://gist.github.com/anonymous/57570cbeba8c42a58da4)

---

<div class="post-metadata">

**Author:** ![Excilys](https://avatars.discourse-cdn.com/v4/letter/e/8797f3/32.png) [@Excilys](https://community.gatling.io/u/Excilys)\
**Post date:** [July 15, 2014, 8:21am UTC](https://community.gatling.io/t/extracting-method-with-session/1169/7 "2014-07-15T08:21:03Z")

</div>

Here’s the sequence of what happens:

- Gatling loads the Simulation and build the whole scenario workflow

- It hits .exec(delete), so delete gets called ONCE, when the scenario is built

- delete calls getId with the requestUrl String parameter set with “SomeUrlPart\_1\_” + deleteCounter.getAndIncrement + “\_SomeUrlPart\_2”  
So clearly, this can not work.  
You have to make requestUrl an Expression[String]:

requestURL: io.gatling.core.session.Expression[String]

and indeed pass it a function:

getIt(“delete”, session =\> “SomeUrlPart\_1\_” + deleteCounter.getAndIncrement + “\_SomeUrlPart\_2”, 3)

---

<div class="post-metadata">

**Author:** ![Andrei\_Proskurin](https://avatars.discourse-cdn.com/v4/letter/a/977dab/32.png) [@Andrei\_Proskurin](https://community.gatling.io/u/Andrei_Proskurin)\
**Post date:** [July 15, 2014, 8:38am UTC](https://community.gatling.io/t/extracting-method-with-session/1169/8 "2014-07-15T08:38:30Z")

</div>

Thanks a lot. Works flawlessly. Couldn’t do it without you.
