i am using JMeter BeanShell Preprocessor to generate unique date value in each iteration. I am using two (2) users for my load test on database . for user 1 the date value generating as expected but when the user change to 2 then date variable value reset to default. what should i do to prevent the reset of date variable value as on insertion i am facing violation of unique key constraint error.[enter image description here](https://i.stack.imgur.com/euEc9.png)
i have mentioned in the screen shot what I tried . I need help to solve my problem
Your problem is that both users are adding 1 day to the date and if the database is configured that way it doesn't allow the same dates - the insert or update will fail.
I don't know the details of your test scenario but you could consider adding current iteration number and/or current virtual user number to the date from the User Defined Variables, the relevant functions are:
vars.getIteration()- for the iteration numberctx.getThreadNum()- for the user numberHowever the best option would be pre-generating the list of dates somewhere in setUp Thread Group
Example Groovy code:
And then use CSV Data Set Config to read the generated dates from the
dates.csvfile in your main Thread GroupGiven you have 2 users and 100k iterations which means that the last date would be
2570-08-11so make sure it matches your requirements and the database is capable of accepting the date such far in the future