Problems creating relationships in neo4j using gatling using the node UUID

Hi,

I’m new to scala and gatling but I am trying to load test an existing neo4j dB with gatling by doing the following:

  1. Create a node with a UUID
  2. Create another node with a UUID
  3. Create a relationship between the two nodes by matching on the UUID
    repeat…

I tried to do this using the following method:

package neo_test

import com.excilys.ebi.gatling.core.Predef._
import com.excilys.ebi.gatling.http.Predef._
import akka.util.duration._
import bootstrap._
import util.parsing.json.JSONObject

class testSession1 extends Simulation{

val httpConf = httpConfig
.baseURL(“http://localhost:7474”)
.acceptHeader(“application/json”)
.requestInfoExtractor(request => {
println(request.getStringData)
Nil
})

// Create node1 UUID.
val createNode1UUID = exec((session) => {
session.setAttribute(“node1_uuid”, java.util.UUID.randomUUID.toString)
})

// Create node2 UUID.
val createNode2UUID = exec((session) => {
session.setAttribute(“node2_uuid”, java.util.UUID.randomUUID.toString)
})

// Create node1’s
val createNode1s = exec(createNode1UUID)
.exec((session) => {
session.setAttribute(
“node1_params”, JSONObject(
Map(
“UUID” → session.getAttribute(“node1_uuid”),
“nodeType” → “Node1”,
“other” → “null”
)
))
})

// Create node2’s
val createNode2s = exec(createNode2UUID)
.exec((session) => {
session.setAttribute(
“node2_params”, JSONObject(
Map(
“UUID” → session.getAttribute(“node2_uuid”),
“nodeType” → “Node2”,
“other” → “null”
)
))
})

val node1 = “{“params”: %s}”.format("${node1_params}")
val node2 = “{“params”: %s}”.format("${node2_params}")
val relationship = “{“uuidA”: “%s”,“uuidB”: “%s”,“relationship”: “knows”}”.format("${node1_uuid}", “${node2_uuid}”)

val scn = scenario(“Create Stuff”)
.during(1) {
exec(createNode1s)
.exec(
http(“create node1s”)
.post("/example/specialservice/createnode")
.header(“X-Stream”, “true”)
.body(node1)
.asJSON
.check(status.is(201))
)
.pause(0 milliseconds, 10 milliseconds)
.exec(createNode2s)
.exec(
http(“create node2s”)
.post("/example/specialservice/createnode")
.header(“X-Stream”, “true”)
.body(node2)
.asJSON
.check(status.is(201)))
.pause(0 milliseconds, 10 milliseconds)
.exec(createNode1UUID, createNode2UUID)
.exec(
http(“create relationships”)
.post("/example/specialservice/createrelationship")
.header(“X-Stream”, “true”)
.body(relationship)
.asJSON
.check(status.is(204)))
.pause(0 milliseconds, 10 milliseconds)
}

setUp(
scn.users(1).ramp(1).protocolConfig(httpConf)
)
}

However the relationship creation fails because the UUID’s have changed from the ones used to create the nodes. Am I completely barking up the wrong tree or is there any way of doing this?

Thanks for your help,

Ian

Hi,

Did a bit of rewriting to understand the simulation.
Is it on purpose that you have this line: .exec(createNode1UUID, createNode2UUID) ??
You’re creating the UUID twice, and so, you have the problem you describe.

cheers
Nicolas

package neo_test

import com.excilys.ebi.gatling.core.Predef._
import com.excilys.ebi.gatling.http.Predef._
import akka.util.duration._
import bootstrap._
import util.parsing.json.JSONObject

class testSession1 extends Simulation{

val httpConf = httpConfig
.baseURL(“http://localhost:7474”)
.acceptHeader(“application/json”)
.requestInfoExtractor(request => {
println(request.getStringData)
Nil
})

def createUUID(nodeName:String) = exec((session) =>
session.setAttribute(nodeName + “_uuid”, java.util.UUID.randomUUID.toString)
)

def createNode(nodeName:String) =
exec(createUUID(nodeName))
.exec((session) => {
session.setAttribute(
nodeName+"_params", JSONObject(
Map(
“UUID” → session.getAttribute(nodeName+"_uuid"),
“nodeType” → nodeName,
“other” → null
)
).toString)
})

val createNode1s = createNode(“node1”)
val createNode2s = createNode(“node2”)

val node1 = “”"{“params”: ${node1_params}}"""
val node2 = “”"{“params”: ${node1_params}}"""
val relationship = “”"{“uuidA”: “${node1_uuid}”,“uuidB”: “${node2_uuid}”,“relationship”: “knows”}"""

val scn = scenario(“Create Stuff”)
.during(1) {
exec(createNode1s)
.exec(
http(“create node1s”)
.post("/example/specialservice/createnode")
.header(“X-Stream”, “true”)
.body(node1)
.asJSON
.check(status.is(201))
)
.pause(0 milliseconds, 10 milliseconds)
.exec(createNode2s)
.exec(
http(“create node2s”)
.post("/example/specialservice/createnode")
.header(“X-Stream”, “true”)
.body(node2)
.asJSON
.check(status.is(201)))
.pause(0 milliseconds, 10 milliseconds)
//.exec(createNode1UUID, createNode2UUID)
.exec(
http(“create relationships”)
.post("/example/specialservice/createrelationship")
.header(“X-Stream”, “true”)
.body(relationship)
.asJSON
.check(status.is(204)))
.pause(0 milliseconds, 10 milliseconds)
}

setUp(
scn.users(1).ramp(1).protocolConfig(httpConf)
)
}

Like Nicolas, I don’t get why you’re purposely recreate new UUIDs that are different from the ones used to create the nodes:
.exec(createNode1UUID, createNode2UUID)

I’m not very familiar with Neo4J, so if it really makes sense to recreate them, could you please explain?

Hi,

Thank you both for the replies. You were right, I didn’t need the line :

.exec(createNode1UUID, createNode2UUID)

which was causing the new GUID generation. I thought I needed that line to be able to access the session values. It’s working now.

Thanks again for your help!

Ian