• Documentation
  • Tutorials
  • Case studies
  • Blogs
  • Product

What's on this Page

  • Create a custom RTM transaction from a plan
  • Select For Update (atomic transaction)
  • Copy a file from a path to another
  • REST call with JSON response
  • step
  • Libraries
  • Groovy library
Categories: LIBRARIES GROOVY
This article references one of our previous releases, click here to go to our latest version instead.

Groovy library

Create a custom RTM transaction from a plan

The idea here is to create and insert directly a custom RTM transaction using Groovy from the plan itself. A RTM custom transaction is represented by a map of String and Object and requires below fields fulfilled into the map to be inserted :

  • begin : the beginning of the measurement point as a Unix Epoch value (ms) as an Integer
  • value : the measurement point duration in ms as an Integer
  • name : the transaction name as a String
  • eId : the test plan execution ID as a String

You can also add any custom attribute to your map which could give more details about the transaction.

You can find below an example of the Groovy code used to create the transaction as well as an example plan.

// Get the measurement accessor instance and create the transaction map
measurementAccessor = org.rtm.commons.MeasurementAccessor.getInstance()
Map<String, Object> map = new HashMap();

// Get current time
startTime = System.System.currentTimeMillis()

// Execute the instruction(s) you want to measure...
myCode.executeMyInstructions()
// Instructions executed

// Get current time
endTime = System.currentTimeMillis()

// Insert required fields and an additional custom attribute to the transaction map
map.put('begin', startTime );
map.put('eId', report.executionID);
map.put('value', endTime - startTime);
map.put('name', 'MyCustomTransaction');
map.put('myCustomAttribute', 'myCustomValue');

// Insert the transaction in database
measurementAccessor.sendStructuredMeasurement(map);

Custom_RTM_Transaction.json

Select For Update (atomic transaction)

Below an example of Groovy script used to open an sql connection, update a column of the first row of a table, then close the connection.

sql = groovy.sql.Sql.newInstance('jdbc:mysql://localhost/step','step','init')
sql.execute('begin')
sql.firstRow('select myColumn from myTable for update')[0]
sql.execute('update myTable set myColumn = myColumn + 1');
sql.execute('commit')
sql.close()

Copy a file from a path to another

java.nio.file.Files.copy(java.nio.file.Paths.get(file), java.nio.file.Paths.get(file+'2'))

REST call with JSON response

response = new URL("http://localhost:8080/rest/grid/agent").text
json = new com.fasterxml.jackson.databind.ObjectMapper().readValue(response, Class.forName('java.util.List'))
  • Home
  • Whats new?
  • Admin guide
  • User guide
  • Developer guide
  • Plugins
  • Libraries
    • Plan library
    • Groovy library
Step Logo
    • Documentation
    • Tutorials
    • Case studies
    • Blogs
    • Product
    • Home
    • Whats new?
    • Admin guide
    • User guide
    • Developer guide
    • Plugins
    • Libraries
      • Plan library
      • Groovy library