Skip to end of metadata
Go to start of metadata

Create BeanShell PreProcessor

Reset Interpreter: True

Parameters: 1 21 60



import java.text.SimpleDateFormat; 
import java.text.NumberFormat;
import java.util.Date;
import java.util.Random;
int minDay = Integer.parseInt(bsh.args[0]); // get first parameter minimal X Days ago
int maxDay = Integer.parseInt(bsh.args[1]); // get second parameter maximal X Days ago
int maxMinutesActivity = Integer.parseInt(bsh.args[2]); // get maximal duration of activity
int myThreadNum = 0;
int randomDay = 0; // RandomDays ago
int minHour = 0;
int maxHour = 23;
int randomHour = 0;
int minMinute = 0;
int maxMinute = 60;
int randomMinute = 0;
int randomMinuteDuration = 0;
String formattedDate = ""; 
Random randomvar = new Random();
Date datevar = new Date();
Date datevarLastWeek = new Date();
 
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
NumberFormat myFormat = NumberFormat.getInstance();
myFormat.setMinimumIntegerDigits(2); // required to have minimal two digits for Day, Hour, Minute
myThreadNum = ${__threadNum}; // just to show the thread number in debug
vars.put("myThreadNum",myFormat.format(myThreadNum));
randomDay = minDay+randomvar.nextInt(maxDay-minDay+1); // randomDays ago between minDay and maxDay
datevar.setDate(datevar.getDate() - randomDay );
vars.put("randomDay",myFormat.format(randomDay));
randomHour = minHour+randomvar.nextInt(maxHour-minHour+1); // randomHour ago between minHour and maxHour
vars.put("randomHour",myFormat.format(randomHour));
randomMinute = minMinute+randomvar.nextInt(maxMinute-minMinute+1); // randomHour ago between minMinute and maxMinute
vars.put("randomMinute",myFormat.format(randomMinute));
randomMinuteDuration = 1+randomvar.nextInt(maxMinutesActivity); // randomduration between 1 and maxMinutesActivity
vars.put("randomMinuteDuration",myFormat.format(randomMinuteDuration));
datevar.setTime(datevar.getTime() - ((randomMinute + (randomHour * 60 )) * 60 * 1000 ));
//datevar.setTime(datevar.getTime() - ((randomMinute + (randomHour * 60 )) * 60 * 1000 ) + myThreadNum );
formattedDate = df.format(datevar);
vars.put("randomDateTimeStart",formattedDate);
datevar.setTime(datevar.getTime() + (randomMinuteDuration * 60 * 1000 ));
formattedDate = df.format(datevar);
vars.put("randomDateTimeEnd",formattedDate);
// Calculate a Start and End time for last Week
randomDay = 1+randomvar.nextInt(8-1+1); // randomDays ago last Week
datevarLastWeek.setDate(datevarLastWeek.getDate() - randomDay );
datevarLastWeek.setTime(datevarLastWeek.getTime() - ((randomMinute + (randomHour * 60 )) * 60 * 1000 ));
//datevarLastWeek.setTime(datevarLastWeek.getTime() - ((randomMinute + (randomHour * 60 )) * 60 * 1000 ) + myThreadNum );
formattedDate = df.format(datevarLastWeek);
vars.put("randomDateTimeStartLastWeek",formattedDate);
datevarLastWeek.setTime(datevarLastWeek.getTime() + (randomMinuteDuration * 60 * 1000 ));
//datevarLastWeek.setTime(datevarLastWeek.getTime() + (randomMinuteDuration * 60 * 1000 ) + myThreadNum );
formattedDate = df.format(datevarLastWeek);
vars.put("randomDateTimeEndLastWeek",formattedDate);


 

 

  • No labels