String cannot be cast to scala.collection.immutable.List Error

2,010 views
Skip to first unread message

Surekha Anantharaman

unread,
Jul 23, 2014, 2:57:44 PM7/23/14
to gat...@googlegroups.com
Hello,
I am pretty new here so please bear with me. I am extracting a number of eventids into a list and iterate over that list repeatedly to use a unique event id in the subsequent request. However, when I try to simulate this, I am getting a String cannot be cast to scala.collection.immutable.List error. Below is my code. Could you please point out where exactly is the mistake and what kind of array manipulation function could be used here.

                                                .exec(http("Home Page")
.get("/")
.headers(headers_1)
.check(status.is(200))
.check(regex("""\'eventLink\'\shref\=\'\/sales\/(\d+)""").findAll.saveAs("""sales_event_id"""))
)

.repeat(4){
exec((session: Session) => { // use a simple action
val sales_event_id = session.getTypedAttribute[List[String]]("sales_event_id") // retrieve the eventid saved by the previous check
session.setAttribute("sales_event_id", sales_event_id(math.max(rnd.nextInt(sales_event_id.length), 9))) // store in the session a eventid randomly picked
})

.doIf( session => session.isAttributeDefined("sales_event_id"))
{
exec(http("EDP")
.get("/sales/${sales_event_id}")
.headers(headers_1)
.check(status.is(200))
)
}
}

Stéphane Landelle

unread,
Jul 23, 2014, 4:52:52 PM7/23/14
to gat...@googlegroups.com
Which version do you use?
Does the problem occurs compile time, or runtime?
Could you provide the full stacktrace please?


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

Surekha Anantharaman

unread,
Jul 23, 2014, 5:42:41 PM7/23/14
to gat...@googlegroups.com
Thanks for getting back, Stephane. So Im using 1.5.4 and this error happens during runtime. Her eis the full stack trace

14:37:00.331 [INFO ] c.e.e.g.h.a.HttpRequestAction - Sending Request 'Home Page': Scenario 'Storefront Gatling', UserId #1

14:37:00.459 [INFO ] c.e.e.g.h.c.CacheHandling$ - Setting LastModified for url https://abc.com:443

14:37:00.466 [INFO ] c.e.e.g.h.a.HttpRequestAction - Sending Request 'EDP': Scenario 'Storefront Gatling', UserId #1

14:37:02.799 [INFO ] c.e.e.g.h.c.CacheHandling$ - Setting LastModified for url https://abc.com:443/sales/39395

[ERROR] [07/23/2014 14:37:02.802] [GatlingSystem-akka.actor.default-dispatcher-20] [akka://GatlingSystem/user/$Ib] java.lang.String cannot be cast to scala.collection.immutable.List

java.lang.ClassCastException: java.lang.String cannot be cast to scala.collection.immutable.List

    at storefront.StorefrontScenario$$anonfun$1.apply(StorefrontScenario.scala:84)

    at storefront.StorefrontScenario$$anonfun$1.apply(StorefrontScenario.scala:83)

    at com.excilys.ebi.gatling.core.action.SimpleAction.execute(SimpleAction.scala:37)

    at com.excilys.ebi.gatling.core.action.Action$$anonfun$receive$1.apply(Action.scala:31)

    at com.excilys.ebi.gatling.core.action.Action$$anonfun$receive$1.apply(Action.scala:30)

    at akka.actor.Actor$class.apply(Actor.scala:318)

    at com.excilys.ebi.gatling.core.action.SimpleAction.apply(SimpleAction.scala:29)

    at akka.actor.ActorCell.invoke(ActorCell.scala:626)

    at akka.dispatch.Mailbox.processMailbox(Mailbox.scala:197)

    at akka.dispatch.Mailbox.run(Mailbox.scala:179)

    at akka.dispatch.ForkJoinExecutorConfigurator$MailboxExecutionTask.exec(AbstractDispatcher.scala:516)

    at akka.jsr166y.ForkJoinTask.doExec(ForkJoinTask.java:259)

    at akka.jsr166y.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:975)

    at akka.jsr166y.ForkJoinPool.runWorker(ForkJoinPool.java:1479)

    at akka.jsr166y.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:104)

 

 

 

14:37:03.488 [ERROR] c.e.e.g.c.a.SimpleAction - Action SimpleAction crashed, forwarding user to next one

java.lang.ClassCastException: java.lang.String cannot be cast to scala.collection.immutable.List

    at storefront.StorefrontScenario$$anonfun$1.apply(StorefrontScenario.scala:84) ~[na:na]

    at storefront.StorefrontScenario$$anonfun$1.apply(StorefrontScenario.scala:83) ~[na:na]

    at com.excilys.ebi.gatling.core.action.SimpleAction.execute(SimpleAction.scala:37) ~[gatling-core-1.5.4.jar:na]

    at com.excilys.ebi.gatling.core.action.Action$$anonfun$receive$1.apply(Action.scala:31) ~[gatling-core-1.5.4.jar:na]

    at com.excilys.ebi.gatling.core.action.Action$$anonfun$receive$1.apply(Action.scala:30) ~[gatling-core-1.5.4.jar:na]

    at akka.actor.Actor$class.apply(Actor.scala:318) ~[akka-actor-2.0.4.jar:2.0.4]

    at com.excilys.ebi.gatling.core.action.SimpleAction.apply(SimpleAction.scala:29) ~[gatling-core-1.5.4.jar:na]

    at akka.actor.ActorCell.invoke(ActorCell.scala:626) ~[akka-actor-2.0.4.jar:2.0.4]

    at akka.dispatch.Mailbox.processMailbox(Mailbox.scala:197) ~[akka-actor-2.0.4.jar:2.0.4]

    at akka.dispatch.Mailbox.run(Mailbox.scala:179) ~[akka-actor-2.0.4.jar:2.0.4]

    at akka.dispatch.ForkJoinExecutorConfigurator$MailboxExecutionTask.exec(AbstractDispatcher.scala:516) [akka-actor-2.0.4.jar:2.0.4]

    at akka.jsr166y.ForkJoinTask.doExec(ForkJoinTask.java:259) [akka-actor-2.0.4.jar:2.0.4]

    at akka.jsr166y.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:975) [akka-actor-2.0.4.jar:2.0.4]

    at akka.jsr166y.ForkJoinPool.runWorker(ForkJoinPool.java:1479) [akka-actor-2.0.4.jar:2.0.4]

    at akka.jsr166y.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:104) [akka-actor-2.0.4.jar:2.0.4]

14:37:03.488 [INFO ] c.e.e.g.h.a.HttpRequestAction - Sending Request 'EDP': Scenario 'Storefront Gatling', UserId #1

14:37:03.704 [WARN ] c.e.e.g.h.a.GatlingAsyncHandlerActor - Request 'EDP' failed : Check 'is' failed, found 304 but expected 200

14:37:03.712 [DEBUG] c.e.e.g.h.a.GatlingAsyncHandlerActor -

>>>>>>>>>>>>>>>>>>>>>>>>>> 

Request:

EDP: KO Check 'is' failed, found 304 but expected 200

=========================

Session:

scenarioName='Storefront Gatling' userId='1' data='Map(username -> sbs_perfo...@example.com, 2ed9827a-537a-4194-9346-c8e16dce2bf2 -> 0, gatling.core.timeShift -> 72, gatling.http.lastModified -> Map(https://abc.com:443/customers/sign-in.json -> Wed, 23 Jul 2014 21:36:32 GMT, https://abc.com:443 -> Wed, 23 Jul 2014 21:37:00 GMT, https://abc.com:443/sales/39395 -> Wed, 23 Jul 2014 21:37:03 GMT), gatling.core.failed -> , gatling.http.referer -> https://abc.com:443/sales/39395, 2b50e717-7ad9-4fef-87e0-ae65e27ad6e1 -> 3, gatling.core.timer.2ed9827a-537a-4194-9346-c8e16dce2bf2 -> 1406151340807, gatling.http.cookies -> CookieJar(Map(abc.com -> List(biscuit=; domain=abc.com; path=/; expires=0, _session_id=5b58d6571aed0f78f7d4ef4b938cd4ab; domain=abc.com; path=/; expires=1406152623000; HTTPOnly, tst=x2.96; domain=abc.com; path=/; expires=1721770623000, hattie=%7B%221%22%3A%7B%22v%22%3A1%2C%22i%22%3A1%2C%22va%22%3A%22true%22%2C%22a%22%3A1%7D%2C%222%22%3A%7B%22v%22%3A1%2C%22i%22%3A4%2C%22va%22%3A%22false%22%2C%22a%22%3A1%7D%2C%223%22%3A%7B%22v%22%3A1%2C%22i%22%3A5%2C%22va%22%3A%22true%22%2C%22a%22%3A1%7D%7D; domain=abc.com; path=/, search_php=037878a4ac2971ba9fb573678671a709; domain=abc.com; path=/, layout=html; domain=abc.com; path=/; expires=1406165792000, b=C1cs7oez8w9vmtc6c27apiza; domain=abc.com; path=/; expires=1437687392000, clyde=C1cs7oez8w9vmtc6c27apiza; domain=abc.com; path=/; expires=1721770592000, PHPSESSID=k9j0jsam7cjlai229pfmigq631; domain=abc.com; path=/; HTTPOnly, ZDEDebuggerPresent=php,phtml,php3; domain=abc.com; path=/))), password -> password, sales_event_id -> 39395)'

=========================

HTTP request:

GET https://abc.com:443/sales/39395

headers=

User-Agent: Gatling-load-Requests

Connection: keep-alive

Accept-Encoding: gzip,deflate,sdch

If-Modified-Since: Wed, 23 Jul 2014 21:37:03 GMT

Referer: https://abc.com:443/sales/39395

Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8

Accept-Language: en-US,en;q=0.8,ta;q=0.6

cookies=

biscuit=; domain=abc.com; path=/; expires=0

_session_id=5b58d6571aed0f78f7d4ef4b938cd4ab; domain=abc.com; path=/; expires=1406152623000; HTTPOnly

tst=x2.96; domain=abc.com; path=/; expires=1721770623000

hattie=%7B%221%22%3A%7B%22v%22%3A1%2C%22i%22%3A1%2C%22va%22%3A%22true%22%2C%22a%22%3A1%7D%2C%222%22%3A%7B%22v%22%3A1%2C%22i%22%3A4%2C%22va%22%3A%22false%22%2C%22a%22%3A1%7D%2C%223%22%3A%7B%22v%22%3A1%2C%22i%22%3A5%2C%22va%22%3A%22true%22%2C%22a%22%3A1%7D%7D; domain=abc.com; path=/

search_php=037878a4ac2971ba9fb573678671a709; domain=abc.com; path=/

layout=html; domain=abc.com; path=/; expires=1406165792000

b=C1cs7oez8w9vmtc6c27apiza; domain=abc.com; path=/; expires=1437687392000

clyde=C1cs7oez8w9vmtc6c27apiza; domain=abc.com; path=/; expires=1721770592000

PHPSESSID=k9j0jsam7cjlai229pfmigq631; domain=abc.com; path=/; HTTPOnly

ZDEDebuggerPresent=php,phtml,php3; domain=abc.com; path=/

=========================

HTTP response:

status=

304 Not Modified

headers=

Expires: Thu, 20 Jul 1983 04:44:00 GMT

Date: Wed, 23 Jul 2014 21:37:03 GMT

Connection: Keep-Alive

Cache-Control: must-revalidate, no-cache, no-store, private, post-check=0, pre-check=0

Server: Apache

Keep-Alive: timeout=5, max=97

Set-Cookie: tst=x2.96; domain=.abc.com; path=/; expires=Tue, 23-Jul-2024 21:37:03 GMT

Set-Cookie: _session_id=5b58d6571aed0f78f7d4ef4b938cd4ab; path=/; expires=Wed, 23-Jul-2014 21:57:03 GMT; HttpOnly

Set-Cookie: biscuit=; path=/; expires=Thu, 01-Jan-1970 00:00:00 GMT

Stéphane Landelle

unread,
Jul 24, 2014, 2:15:30 AM7/24/14
to gat...@googlegroups.com
This doesn't make sense?!
Are you sure that you're not using "sales_event_id" for storing a single String before that?


Surekha Anantharaman

unread,
Aug 7, 2014, 7:13:22 PM8/7/14
to gat...@googlegroups.com
Nope. This is the first time I am using a sales_event_id variable and my intention is to capture a list of event_ids here. Just for your review, Here is my complete script.


package storefront
import com.excilys.ebi.gatling.core.Predef._
import com.excilys.ebi.gatling.http.Predef._
import StorefrontHeaders._
import akka.util.duration._
import bootstrap._
import scala.util._
import scala.util.Random

object pod1Scenario {

// val r = scala.util.Random
// var x = r.nextInt(20)
val testTimeSecs   = 1800
val minWaitMs      = 10000 milliseconds
  val maxWaitMs      = 30000 milliseconds
  val rnd = new scala.util.Random
  val range = 1 to 20
  val id = (range(rnd.nextInt(range length)))


 

val scn = scenario("Storefront Pod1")

.during(testTimeSecs) {

pauseExp(15 seconds)
.exec(http("XX_LoginPage")
.get("/login")
.headers(headers_1)
)
.pause(minWaitMs, maxWaitMs)



.feed(csv("storefront_users.csv").random)


.pause(minWaitMs, maxWaitMs)

// RAILS Login Request

.exec(http("XX_LoginPOST")
.post("/customers/sign-in.json")
.headers(headers_23)
.param("""email""", "${username}")
.param("""password""", "${password}")
.param("""keepLogIn""", """0""")
.param("""applicationType""", """storefront""")
.param("""format""", """json"""))
// RAILS Login Request

.repeat(4){
pause(minWaitMs, maxWaitMs)
exec(http("Home Page")
.headers(headers_1)
.check(status.is(200))
.check(regex("""\'eventLink\'\shref\=\'\/sales\/(\d+)""").findAll.saveAs("""sales_event_id"""))
)}

.exec((session: Session) => { // use a simple action
val sales_event_id = session.getTypedAttribute[List[String]]("sales_event_id") // retrieve the keywords saved by the previous check
session.setAttribute("sales_event_id", sales_event_id(math.max(rnd.nextInt(sales_event_id.length), 9))) // store in the session a keywork randomly picked
})


.pause(minWaitMs, maxWaitMs)


.doIf( session => session.isAttributeDefined("sales_event_id"))
{
repeat(13){
pause(minWaitMs, maxWaitMs)
exec(http("XX_EDP")
.get("/sales/${sales_event_id}")
.headers(headers_1)
.check(status.is(200))
.check(regex("""data\-product\-id\=\'(\d+)""").find(id).exists.saveAs("""product_id"""))
)
}}


.exec(http("XX_To_Retrieve_SKU")
.get("/product/${sales_event_id}/${product_id}")
.headers(headers_1)
// .check(status.is(200))
.check(regex("""\"id\"\:(\d+)\,\"quantity\"\:[1-9]*[0-9]\,\"reservable\_quantity\"\:\d+\,\"on\_hold\"\:false\,\"price\"\:""").find(0).exists.saveAs("""sku_id"""))
)

.pause(minWaitMs, maxWaitMs)




.doIf( session => session.isAttributeDefined("product_id"))
 {
repeat(13){
pause(minWaitMs, maxWaitMs)
exec(http("XX_PDP Storefront")
.get("/product/${sales_event_id}/${product_id}")
.headers(headers_1)
.check(status.is(200))
// .check(regex("""\'selectSkuId\'\sname\=\'skuId\'\stype\=\'hidden\'\svalue\=\'(\d+)\'\>""").find.exists.saveAs("""sku_id"""))
// .check(regex("""\<input\sid\=\'selectSkuId\'\sname=\'skuId\'\stype\=\'hidden\'\svalue\=\'(\d+)""").find(0).exists.saveAs("""sku_id"""))
//check to see if a product is sold out.  If yes, then dont add to cart
// .check(regex("""\<button class\=\'addToCart trackAddToCart\' type=\'submit\'\>Add To Cart\<\/button\>""").find.exists.saveAs("""available"""))
)
 } }


.exec(http("XX_Logout")
.get("/logout")
.headers(headers_1)
)



}
}


Michelle Burrows

unread,
Aug 8, 2014, 8:16:30 AM8/8/14
to gat...@googlegroups.com
You have two very different snippets of code posted, now. Did you change your code (and are you getting the same error in the same place?), or is it a copy/paste error (and which one is actually correct)? I could tell you exactly what's going wrong with your first piece of code (where the repeat() is around the session function) - on the first iteration, it was setting the sales_event_id attribute to a single element of the list (a string), and then trying to get that string as a list on the second iteration.
...
Message has been deleted

Surekha Anantharaman

unread,
Aug 8, 2014, 7:53:56 PM8/8/14
to gat...@googlegroups.com
Thanks for the reply, Michelle. Sorry about the second code - it is my old code. I understand your explanation about my original snippet. So could you please tell me how do I extract dynamic valuse from the list 'sales_event_id' and use it in the subsequent requests. I also tried the loop{chain} from this example https://gist.github.com/slandelle/2469375, but not much luck there. Getting an error- value loop is not a member of com.excilys.ebi.gatling.core.structure.ChainBuilder'. Appreciate your time.


On Wednesday, July 23, 2014 11:57:44 AM UTC-7, Surekha Anantharaman wrote:

Surekha Anantharaman

unread,
Aug 11, 2014, 5:11:39 PM8/11/14
to gat...@googlegroups.com
Hey Stephane,
I also tried with the loop chain to iterate over the list that I have. Here is the code. However, during compilation I get an error stating that 'value loop is not a member of com.excilys.ebi.gatling.core.structure.ChainBuilder'. Still wondering how to i iterate over a list of sales_event_ids that I extracted from the home page. Appreciate your time.

.exec(http("Home Page")
.headers(headers_1)
.check(regex("""href\=\'\/sales\/(\d+)""").findAll.saveAs("""sales_event_id"""))
)



.loop(
chain
.exec((session: Session) => { // use a simple action
val keywords = session.getTypedAttribute[List[String]]("sales_event_id") // retrieve the keywords saved by the previous check
session.setAttribute("sales_event_id", keywords(math.max(rnd.nextInt(sales_event_id.length), 9))) // store in the session a keywork randomly picked
})
.exec(http("XX_EDP").get("/sales/${sales_event_id}"))) 
.counterName("eventidCounter")
.asLongAs((session: Session) => {
val sales_event_id = session.getTypedAttribute[List[String]]("sales_event_id")
session.getCounterValue("eventidCounter") < math.max(sales_event_id.length, 10)
})

Surekha Anantharaman

unread,
Aug 11, 2014, 5:34:02 PM8/11/14
to gat...@googlegroups.com
Never mind. I figured out how to do it. This piece worked.

.repeat(session => session.getTypedAttribute[List[String]]("sales_event_id").size, "loopIndex") {
            exec(http("XX_EDP for product id")
.get("/sales/${sales_event_id(loopIndex)}"))
Reply all
Reply to author
Forward
0 new messages