Reputation: 789
I have written a code to do DIFF of two text files in Java/Eclipse using org.apache.commons.io.FileUtils and Set operations. The code is working fine. but the same code is not working in JMeter's BeanShell Assertion. Lines with Set operations giving error. Code:
import org.apache.commons.io.FileUtils;
import java.io.*;
import java.util.Date;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.concurrent.TimeUnit;
import java.util.ArrayList;
import java.util.Collection;
DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm");
Date startdate = new Date();
Date enddate = null;
PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("C://Work//JMeter//Logs//D2MDS.txt")));
out.println("Automated ETL Validator -- START -- " + dateFormat.format(startdate));
out.println("=========================================================================");
try {
Set<String> Slines = new TreeSet<String>(FileUtils.readLines(new File ("C://Work//JMeter//Data//SourceSQLLog.csv")));
//Set<String> Tlines = new TreeSet<String>(FileUtils.readLines(new File ("C://Work//JMeter//Data//TargetSQLLog.csv")));
//Slines.removeAll(Tlines);
//out.println(Slines);
}
catch (Exception e) {
out.println(ExceptionUtils.getStackTrace(e));
}
Date enddate = new Date();
enddate = new Date();
long duration = enddate.getTime() - startdate.getTime();
long diffInMinutes = TimeUnit.MILLISECONDS.toMinutes(duration);
out.println("=========================================================================");
out.println("Automated ETL Validator -- END -- " + dateFormat.format(enddate));
out.println("\n\n\n*************************************************************************");
out.println("EXECUTION SUMMARY");
out.println("====================");
out.println("Total Lines in Extract File: " + ${__V(ret_val_#)});
out.println("Total Failures in Extract File: " + fail_cnt);
out.println("Failed Lines of Extract File = " + fail_ln);
out.println("Extract Validation -- END -- " + dateFormat.format(enddate) + " -- Duration: " + diffInMinutes + " Minutes");
out.close();
Beanshell Assertion is throwing obscure error:
Assertion failure message: org.apache.jorphan.util.JMeterException: Error invoking bsh method: eval In file: inline evaluation of: ``import org.apache.commons.io.FileUtils; import java.io.*; import java.util.Date; . . . '' Encountered "=" at line 18, column 20.
5 Jar files are present inside JMeter's /lib folder. How do I make JMeter recognize the Set methods.
Thanks
Upvotes: 1
Views: 1360
Reputation: 167992
First:
It isn't connected with FileUtils class usage, the fault point is line 18 as per
Encountered "=" at line 18, column 20.
Change your line #18 from
Date enddate = new Date();
to
enddate = new Date();
as you have already defined it at line #3 Beanshell interpreter fails to parse line 18 as the variable is present in this scope.
Second
Beanshell is not Java so
Set<String> Slines = new TreeSet<String>
will also fail. You will need to remove diamond brackets
Set Slines = new TreeSet...
Third:
Also I don't see where fail_cnt
and fail_ln
are defined and would suggest to substitute
${__V(ret_val_#)}
with
vars.get("ret_val_#");
See How to use BeanShell: JMeter's favorite built-in component guide for Beanshell-related tips and tricks.
Hope this helps.
Upvotes: 1