<commit_before>package com.tinkerpop.gremlin.server.simulation

import io.gatling.core.Predef._
import scala.concurrent.duration._
import akka.actor.ActorRef;
import io.gatling.core.action.builder.ActionBuilder
import io.gatling.core.action.{Chainable, system}
import bootstrap._
import assertions._
import akka.actor.Props
import io.gatling.core.result.message.{RequestMessage, KO, OK}
import io.gatling.core.result.writer.DataWriter
import com.tinkerpop.gremlin.driver.{Client, Cluster}

class GremlinServerSimulation extends Simulation {

  val mine = new ActionBuilder {
    def build(next: ActorRef) = system.actorOf(Props(new GremlinServerAction(next)))
  }

  val usersToSimulate = Integer.getInteger("users", 1).intValue()
  val simulationTime  = Integer.getInteger("time", 30).intValue()

  val scn = scenario("Gremlin Server Test").repeat(2) { exec(mine) }
  setUp(scn.inject(ramp(usersToSimulate users) over (simulationTime seconds)))
    .assertions(global.responseTime.max.lessThan(250),global.successfulRequests.percent.greaterThan(95))
}

class GremlinServerAction(val next: ActorRef) extends Chainable {
  val cluster: Cluster = Cluster.open
  val client: Client = cluster.connect

  def send(session: Session) {
    client.submit("1+1")
  }

  def execute(session: Session) {
    var start: Long = 0L
    var end: Long = 0L
    var status: Status = OK
    var errorMessage: Option[String] = None

    try {
      start = System.currentTimeMillis
      send(session)
      end = System.currentTimeMillis
    } catch {
      case e: Exception =>
        errorMessage = Some(e.getMessage)
        logger.error("Stinks - that FAILED", e)
        status = KO
    } finally {
      DataWriter.tell(
        RequestMessage(session.scenarioName, session.userId, session.groupStack, "Gremlin Server Test Scenario",
          start, start, end, end,
          status, errorMessage, Nil))<commit_msg>Still tinkering with how Gatling simulation will work for Gremlin Server.<commit_after>package com.tinkerpop.gremlin.server.simulation

import io.gatling.core.Predef._
import scala.concurrent.duration._
import akka.actor.ActorRef
import io.gatling.core.action.builder.ActionBuilder
import io.gatling.core.action.{Chainable, system}
import bootstrap._
import assertions._
import akka.actor.Props
import io.gatling.core.result.message.{RequestMessage, KO, OK}
import io.gatling.core.result.writer.DataWriter
import com.tinkerpop.gremlin.driver.{Client, Cluster}

class GremlinServerSimulation extends Simulation {
  val host: String = System.getProperty("host", "localhost")
  val cluster: Cluster = Cluster.create(host).build()

  val addition = new ActionBuilder {
    def build(next: ActorRef) = system.actorOf(Props(new GremlinServerAction(next, cluster, "1+1")))
  }

  val scn = scenario("Gremlin Server Test").randomSwitch(
    50 -> repeat(250) { exec(addition) },
    50 -> repeat(1000) { exec(addition) }
  )

  setUp(
    scn.inject(
      ramp(10 users) over (10 seconds),
      constantRate(20 usersPerSec) during (15 seconds),
      ramp(1000 users) over (5 minutes))
  ).assertions(global.responseTime.max.lessThan(250), global.successfulRequests.percent.greaterThan(95))
}

class GremlinServerAction(val next: ActorRef, val cluster: Cluster, val script: String) extends Chainable {
  val client: Client = cluster.connect

  def send(session: Session) {
    client.submit(script)
  }

  def execute(session: Session) {
    var start: Long = 0L
    var end: Long = 0L
    var status: Status = OK
    var errorMessage: Option[String] = None

    try {
      start = System.currentTimeMillis
      send(session)
      end = System.currentTimeMillis
    } catch {
      case e: Exception =>
        errorMessage = Some(e.getMessage)
        logger.error("Stinks - that FAILED", e)
        status = KO
    } finally {
      DataWriter.tell(
        RequestMessage(session.scenarioName, session.userId, session.groupStack, "Gremlin Server Test Scenario",
          start, start, end, end,
          status, errorMessage, Nil))
{'fraction_non_alphanumeric': 0.10794751176033672, 'fraction_numerical': 0.01138895766278782, 'mean_word_length': 3.855769230769231, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3146398', 'n_tokens_mistral': 1288, 'n_tokens_neox': 1216, 'n_words': 296}