2015-03-25 166 views
0

我已經編寫了一個代碼,使用 org.apache.commons.io.FileUtils和Set操作在Java/Eclipse中執行兩個文本文件的DIFF。代碼工作正常。 但是相同的代碼在JMeter的BeanShell聲明中不起作用。 設置操作給出錯誤的行。 代碼:JMeter BeanShell Assertion無法識別FileUtil方法

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 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文件都存在裏面JMeter的/ lib文件夾。如何讓JMeter識別Set方法。

感謝

回答

1

第一:

它不與文件實用程序類使用連接,故障點是18行每

Encountered "=" at line 18, column 20.

更改線#18
Date enddate = new Date(); 

enddate = new Date(); 

因爲您已經在#3行中定義了它,所以Beanshell解釋器無法解析第18行,因爲該變量存在於此範圍內。

BeanShell的不是Java這樣

Set<String> Slines = new TreeSet<String> 

也將失敗。你將需要刪除的鑽石括號

Set Slines = new TreeSet... 

三:

我也看不出fail_cntfail_ln定義和建議替代

${__V(ret_val_#)} 

vars.get("ret_val_#"); 

請參閱How to use BeanShell: JMeter's favorite built-in component Beanshell相關提示和技巧指南。

希望這會有所幫助。