-1

I created two CSV Config files one for Tax Rate and another for Description. The Tax Rate CSV gets written first using this code that I wrote in a JSR223 PostProcessor.

temp_tax = new FileOutputStream("temp_tax_rate.csv", true); 
file = new PrintStream(temp_tax);
String tax_rate = source[parent]["tax_rate"]
file.println(tax_rate+","+tax_rate+","+tax_rate)

file.close();
temp_tax.close();`

Then another JSR223 PostProcessor to write into the Description CSV

def input_data(webSite,productClass,cityOrTown,stateOrProvince,postalCode,final_tax-1,final_tax-2,final_tax-3,taxable_amount-1,taxable_amount-2,taxable_amount-3,tax_amount-1,tax_amount-2,tax_amount-3)
{

temp_data = new FileOutputStream("Tax_Description_D1_Non-Reseller.csv", true);
file = new PrintStream(temp_data);

file.println(webSite+","+productClass+","+cityOrTown+","+stateOrProvince+","+postalCode+","
        +final_tax-1+","+final_tax-2+","+final_tax-3+","
        +taxable_amount-1+","+taxable_amount-2+","+taxable_amount-3+","
        +tax_amount-1+","+tax_amount-2+","+tax_amount-3);

file.close();
temp_data.close();

}

After writing to the Tax Rate csv the Description Postprocessor also needs to call the tax_rate variable from the CSV config to do some computation but every time it is called it returns an error which i logged

2021-08-20 17:02:51,208 INFO o.a.j.e.J.JSR223 PostProcessor for Description: Tax Rate<EOF>

My guess is that the description postprocessor is still looking at the outdated Tax Rate csv where nothing has been written on it yet instead of the written version of it. This is my current project file structure

maxim
  • 23
  • 1
  • 5

1 Answers1

0

Your guess is wrong, as per CSV Data Set Config documentation:

Lines are read at the start of each test iteration. The file name and mode are resolved in the first iteration.

If you're updating the CSV file in the runtime and want to evaluate the variable(s) you either need to wait for the next iteration or consider using __CSVRead() function or read the line in Groovy.

Also your approach will work only for a single thread, if you run the test with 2+ virtual users you will run into a race condition and the file will contain corrupt data so it might worth looking at i.e. Flexible File Writer

Dmitri T
  • 159,985
  • 5
  • 83
  • 133