日期:2014-05-17  浏览次数:20687 次

SoapUI LoadTest 多线程无法正确读取数据
问题描述:

在LoadTest Setup Script中的以下代码

List<String> someDataList = new ArrayList<String>();  //声明someDataList
racdb.eachRow("select * from table where rownum<10"){row ->  
    someDataList.add(row.ric);  //数据库中读取的数据插入someDataList
    log.info(row.ric)
}  
context.setProperty("someDataList",someDataList);  //设置属性someDataList的值


Test Case Groovy Script中读取该属性

file = new File(context.expand('c:\\aa.txt'))  //声明文件aa.txt,将someDataList的值打印在该文件中
def value = context.LoadTestContext.getProperty('someDataList')
file.append('value is: '+value)
file.append('ThreadIndex is: '+context.ThreadIndex)//记录线程number
file.append("RunCount is: "+context.RunCount) //记录testcase执行的次数

LoadTest中设置Treads为3。运行该loadtest发现在aa.txt文件中显示

value is: [973633X.DEU^B04, 0IZC.PO^L08, ALAN.F^G11, ATOAf.NS, ATOAol.NS, BOBE.P, 5192.JSA, 4534.BE^K03, ABEC.D]ThreadIndex is: 0RunCount is: 0value is: [973633X.DEU^B04, 0IZC.PO^L08, ALAN.F^G11, ATOAf.NS, ATOAol.NS, BOBE.P, 5192.JSA, 4534.BE^K03, ABEC.D]ThreadIndex is: 1RunCount is: 0value is: [973633X.DEU^B04, 0IZC.PO^L08, ALAN.F^G11, ATOAf.NS, ATOAol.NS, BOBE.P, 5192.JSA, 4534.BE^K03, ABEC.D]ThreadIndex is: 2RunCount is: 0value is: [973633X.DEU^B04, 0IZC.PO^L08, ALAN.F^G11, ATOAf.NS, ATOAol.NS, BOBE.P, 5192.JSA, 4534.BE^K03, ABEC.D]
。。。。。。。。。。。。。。
。。。。。。。。。。。。。。
value is: [973633X.DEU^B04, 0IZC.PO^L08, ALAN.F^G11, ATOAf.NS, ATOAol.NS, BOBE.P, 5192.JSA, 4534.BE^K03, ABEC.D]ThreadIndex is: 1RunCount is: 74value is: [973633X.DEU^B04, 0IZC.PO^L08, ALAN.F^G11, ATOAf.NS, ATOAol.NS, BOBE.P, 5192.JSA, 4534.BE^K03, ABEC.D]ThreadIndex is: 2RunCount is: 74value is: nullThreadIndex is: 0RunCount is: 81value is: nullThreadIndex is: 1RunCount is: 75

我的问题是

为什么threadIndex is:0 RunCount is 81开始,无法正确的读取value的值,此时aa.txt文件显示的valie is: null(在之前的所有线程的执行都可以正确的读取loadtest中设置的someDataList属性并且打印到aa.txt文件中)