最近再做一个跟海量存储相关的项目测试,需要通过LR模拟用户大量上传和下载文件,请求是Rest或Soap,同时还要模拟多种大小尺寸不一的文件
通常情况下,都是使用简单的post协议即可:
方法一:
web_submit_data("importStudent.do",
"Action=https://testserver/console/importStudent.do",
"Method=POST",
"EncType=multipart/form-data",
"RecContentType=text/html",
"Referer=https://testserver/console/displayStudentList.do",
"Snapshot=t12.inf",
"Mode=HTTP",
ITEMDATA,
"Name=uploadFile", "Value=D://Excel//data161955.zip", "File=yes", ENDITEM,
LAST);
|
后续对上传的文件进行MD5值比较,发现不一致,仔细查看后,发现上传的文件内容被loadrunner添加了几行额外的值,content-type等,无奈下,重写读文件的方式,我通过如下程序实现了1到10M文本文件的上传,如果上传二进制文件,body的写法有变化:
方法二:
vuser_init()
{
char fileName[] = "D:/Script/CreateObj_10M/tools.zip";
int len = 0;
int readLen=0;
int tmpLen=1;
int runLen =104857;
int cLen = 0;
if ( (file_stream = fopen(fileName, "rb")) == NULL)
{
lr_message("open file failed!\n");
return -1;
}
fseek(file_stream, 0, 2);
len = ftell(file_stream);
lr_message("file length is: %d bytes", len);
readbuf = (char *) malloc(len+1);
memset(readbuf, 0, len+1);
if ( runLen > len) {
runLen = len;
}
fseek(file_stream, 0, 0);
while(feof(file_stream)== 0){
tmpLen = fread(readbuf + readLen, 1,runLen , file_stream);
readLen += tmpLen;
cLen = readLen + runLen;
if (cLen > len) {
runLen = cLen - len;
}
if (tmpLen==0) {
break;
}
}
|