Test Data Functions in Java: The IRI RowGen SDK
IRI has completed its first Software Development Kit (SDK) for RowGen that Java programmers can call to generate test data dynamically in applications or across Hadoop nodes. This article introduces the library, and how you can use it to generate custom records with either randomly generated synthetic, and/or randomly-selected real, field values.
Functions for adding the fields are:
- void – addField(Field)
- void – addNonsetField(String, int)
- void – addSetField(String, String)
- void – addSetField(String, String, int)
- void – clearFields()
Functions for generating the records are:
- String – generateRecord()
- ArrayList<String> – generateRecord(int)
- ArrayList<String> – generateRecordArray()
The Java SDK for RowGen allows you to create an ODataGen object that will generate random data for fields inside the ODataGen object, and present them as records.
ODataGen exampleGen = new ODataGen();
The Java SDK for RowGen has four different functions to add fields to an ODataGen object:
- The first way is to create a field and pass it into addField, and now that field will be in your ODataGen object.
- You can use addNonsetField to add a non-set field of your chosen type and length to your ODataGen object.
- You can use addSetField to add a set field of your chosen type and from your chosen set file to your ODataGen object.
- If you wish to add a set field that uses the “ROW” operation, you can pass that field into addSetField, which will add a set field of your chosen type, from your chosen set file, and your chosen column index to your ODataGen object.
You can also use clearFields on your ODataGen Object to remove all fields you added.
The Java SDK for RowGen has 3 different functions which help you create a record for your ODataGen object.
- You can call generateRecord, which will return a single record in String format.
String szExample = exampleGen.generateRecord();
- You can call generateRecord and pass in a numeric value to generate that many records for your ODataGen object.
ArrayList<String> manyRecordsExample = exampleGen.generateRecord(100);
- You can call generateRecordArray, which will return an array where each element in the array is random data for each field you added to your ODataGen object. Note that the elements will be sequenced by the order in which you added them to your ODataGen object.
ArrayList<String> eachFieldExample = exampleGen.generateRecordArray();
The example output below is shown in the console window of the IRI Workbench GUI, built on Eclipse™. Two numeric fields were added (each with a length of five), along with an ‘any’ set field value from a file with twenty names in it (e.g., Mr. Brown and Mrs. Purple), to an ODataGen object:
And here is the code calling the RowGen API that created this test data:
Contact email@example.com if you are interested in working with the SDK.