GenRocket Runtime Real Time Socket Engine helper classes

The GenRocket runtime comes with a few helper classes that can be used to call the GenRocket Realtime Socket Engine. The helper classes are written in Groovy but are compiled down to a Java binary; they are the following:

  • com.genRocket.tdl.LoaderDTO: A data transfer object used to transfer generated test data.
  • com.genRocket.tdl.ScenarioParams: An object used to pass parameters to the socket.
  • com.genRocket.tdl.TestDataLoader: Contains helper classes to connect to the socket.

These helper classes exist in the GenRocket runtime jar. Make sure to download the GenRocket runtime to your local computer. For more information on how to install the GenRocket runtime visit this article for Windows installation or this article for MacOS/Linux installation. Unzip the runtime and pull the genrocket.jar from the lib folder and place in your Grails project lib folder.



LoaderDTO

 

package com.genRocket.tdl

class LoaderDTO {
  Long parentId
 Object object
 Map<String, Object> map = [:]
}

 

ScenarioParams

   

package com.genRocket.tdl

class ScenarioParams {
  def accessKey // The name of an environment variable that contains the accessKey.
  def scenarioPath // The name of an environment variable that contais the scenarioPath.
  def scenario
  def scenarioDomain
  def loopCount = 0
  def inMemory = true
  def host = 'localhost'
  def port = 4444

  def ScenarioParams(accessKey, scenarioPath, scenario, scenarioDomain) {
    this.accessKey = accessKey
    this.scenarioPath = scenarioPath
    this.scenario = "${scenario}.grs"
    this.scenarioDomain = "${scenarioDomain}"
  }

  def ScenarioParams(scenario, scenarioDomain) {
    this.scenario = "${scenario}.grs"
    this.scenarioDomain = "${scenarioDomain}"
  }
}

   

TestDataLoader

    

package com.genRocket.tdl

import static com.genRocket.utils.ScenarioRunner.executeOverSocket

class TestDataLoader {

  static socket(ScenarioParams params) {
    def accessKey = System.getenv()[params.accessKey]
    def scenarioPath = System.getenv()[params.scenarioPath]

    def result = executeOverSocket(
      scenarioPath,
      accessKey,
      params.scenario,
      params.scenarioDomain,
      params.inMemory,
      params.loopCount,
      params.host,
      params.port
    )

    if (result.responseType == 'data' || result.responseType == 'message') {
      return result.response
    } else {
      throw new Exception((String) result.response)
    }
  }
}

    

Example Test Data Loader

The following code is an example of a Groovy class using the TestDataLoader Design Pattern (TDL) with the GenRocket helper classes to call the GenRocket Real Time Socket Engine to generate user data.

   

package genrocketDemo.testDataLoader

import genrocketDemo.User
import com.genRocket.tdl.LoaderDTO
import com.genRocket.tdl.TestDataLoader
import com.genRocket.tdl.ScenarioParams

class UserTestDataLoader {
  static ACCESS_KEY = 'GENROCKET_ACCESS_KEY'
  static SCENARIO_PATH = 'GENROCKET_DEMO_SCENARIOS'
  static SCENARIO = 'UserScenario'
  static SCENARIO_DOMAIN = 'User'

  static load() {
    def scenarioParams = new ScenarioParams(
        ACCESS_KEY, SCENARIO_PATH, SCENARIO, SCENARIO_DOMAIN
    ​)
    def data = TestDataLoader.socket(scenarioParams)
    def testData = []

    data.each { node ->
      def dto = new LoaderDTO()
      dto.object = new User(node)
      testData.add(dto)
    }

    return testData
  }
}