Error Message with the below gatling scala code


#1

Hi,
Below is my code:
package fneperf

import io.gatling.core.scenario.Simulation
import scala.io.Source
import scala.util.Random
import com.flexnet.lm.binary.FeatureInfo
import io.gatling.core.Predef._
import io.gatling.http.Predef._
import scala.concurrent.duration._
import io.gatling.http.response._
import java.nio.charset.StandardCharsets.UTF_8
import com.flexnet.glservice.gatling.request.CapabilityRequestor
import com.flexnet.lm.binary.FeatureInfo

import scala.collection.mutable.ListBuffer
import io.gatling.core.controller.inject._

class finalTry extends Simulation{

var numberOfClients : Int = 0
var duration : Int = 0
var requestEndPoint = " "

object execution {

val lines = Source.fromFile(“Demo.txt”).getLines

val scn1 = " "
lines.foreach {
(i: String) => //println(i)

      var NumberOfInput = i.split(',').length

      var Inputs: Array[String] = new Array[String](NumberOfInput)
      Inputs = i.split(',')
      //print(i)
       numberOfClients = Inputs { 0 }.toInt
      print("newvar1 value is " + Inputs { 0 })

       duration = Inputs { 1 }.toInt
      print(" newvar2 value is " + Inputs { 1 })

      var perClientRequests = Inputs { 2 }.toInt
      print(" newvar3 value is " + Inputs { 2 })
      val instance = Inputs { 3 }
      println(" instance value is " + Inputs { 3 })
      val requestEndPoint = "http://localhost:7070"
      val poolSize = Inputs { 4 }.toInt
      println(" poolSize value is " + Inputs { 4 })
      
      val endPoint = "http://localhost:7070/"+instance
      println(" im printing the endpoint URL" + endPoint)
      

      val rnd = new Random
      val intialSize = 1
      val r1 = intialSize + rnd.nextInt(poolSize)
      println(r1)
      //          val featureName = "f"
      //println(r1)
      //          println(" " + featureName + r1)
      var featureName = "f" + r1
      println(featureName)
      val START_HOSTID = 1
     // val finfo = Array(new FeatureInfo(featureName, "1.0", 1))
       // val capaFeeder = Iterator.from(START_HOSTID).map(i => Map("request" -> new CapabilityRequestor( "clientN-" + i.toString ).withFeatures(featureName, "1.0", 1).toByteArray( )))
      val capaFeeder = Iterator.from(START_HOSTID).map(i => Map("request" -> new CapabilityRequestor( "clientN-" + i.toString ).withFeature( featureName, "1.0", 1 ).toByteArray( )))
        val scn1 = feed(capaFeeder)
        .repeat(perClientRequests) {
        exec(http("request")
            .post("/request"))
      }
      
      
   /*    val scn = scenario("Request single feature, random pause then return.")
// This feeder gives us a count used as client/user id.
.repeat(perClientRequests)
 {*/
      /*val scn1 = exec( CapRequestMaker.capReq(
    // Deliberately not using Tuple2 or sublists in the Arrays below
    //  to avoid boilerplate.
    Array("f1", 1L)) )
  .pause(10, 20)
  .exec( CapRequestMaker.capReq(
    Array("f1", 0L)) )*/

}

}
val httpConf = http.baseURL(requestEndPoint)
//val scn = scenario(“test”).exec(
val scn = scenario(“sc”).exec(execution.scn1)
setUp(

    scn.inject(constantUsersPerSec(numberOfClients) during(duration seconds))

).protocols(httpConf)

/* object CapRequestMaker {
def capReq(features: Array[Any]) = {
println(“executing cap request”)
val finfo = for (i <- features.grouped(2).toArray) yield (
new FeatureInfo(i(0).asInstanceOf[String], “1.0”,
i(1).asInstanceOf[Long]))
exec { session =>
session.set(
“requestor”,
new CapabilityRequestor(“client-” + session(“id”).as[String]).withFeatures(finfo).toByteArray())
}
.exec(http(“cap re”)
.post("/request")
//.body(ByteArrayBody("${requestor}")) <-- EL string doesn’t work!
.body(ByteArrayBody(session => session(“requestor”).validate[Array[Byte]])))

}

}*/

}

Error message seen:

Simulation fneperf.finalTry started…
newvar1 value is 20 newvar2 value is 1 newvar3 value is 60 instance value is asdfsdfsdf
poolSize value is 1
im printing the endpoint URLhttp://localhost:7070/asdfsdfsdf
1
f1
newvar1 value is 20 newvar2 value is 5 newvar3 value is 60 instance value is sadfsdafas
poolSize value is 5
im printing the endpoint URLhttp://localhost:7070/sadfsdafas
4
f4
15:10:18.529 [ERROR] i.g.c.a.b.SessionHookBuilder$$anonfun$build$1$$anon$1 - ‘sessionHook-1’ failed to execute: Can’t cast value of type class java.lang.String into class io.gatling.core.session.Session

================================================================================
2017-11-06 15:10:18 0s elapsed
---- sc ------------------------------------------------------------------------
[ ] 0%
waiting: 100 / active: 0 / done:0
---- Requests ------------------------------------------------------------------

Global (OK=0 KO=0 )

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

15:10:18.607 [ERROR] i.g.c.a.b.SessionHookBuilder$$anonfun$build$1$$anon$1 - ‘sessionHook-1’ failed to execute: Can’t cast value of type class java.lang.String into class io.gatling.core.session.Session
15:10:18.654 [ERROR] i.g.c.a.b.SessionHookBuilder$$anonfun$build$1$$anon$1 - ‘sessionHook-1’ failed to execute: Can’t cast value of type class java.lang.String into class io.gatling.core.session.Session
15:10:18.701 [ERROR] i.g.c.a.b.SessionHookBuilder$$anonfun$build$1$$anon$1 - ‘sessionHook-1’ failed to execute: Can’t cast value of type class java.lang.String into class io.gatling.core.session.Session

Any help is highly appreciated!!