java 生成压测数据

询价接口压测,需要批量生成数据,

数据包括4个字段(车牌号,车架号,发动机号,支付号)licenseNo,vehicleFrameNo,engineNo,payFlowId

需符合LoadRunner 读取数据的格式

 

 

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Random;


public class Pattern{

public static void main(String [] agrs) throws IOException{

  File file = new File("D:\\testXml.txt");
  if(!file.exists()){
  try {
file.createNewFile();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
FileWriter writer;
try {
writer = new FileWriter(file);
for (int i = 0; i < 10000; i++) {
String payFlowId = "A"+getRandomString(14,"A");
String engineNo = "AWL"+getRandomString(3,"A")+getRandomString(1,"B")+getRandomString(5,"A");
String vehicleFrameNo = "LSV"+getRandomString(4,"A")+getRandomString(2,"B")+getRandomString(8,"A");
String licenseNo = "*";
System.out.println(licenseNo+","+vehicleFrameNo+","+engineNo+","+payFlowId);
writer.write(licenseNo+","+vehicleFrameNo+","+engineNo+","+payFlowId+"\n");// 写内容 

}

writer.flush();// 清空缓冲区,立即将输出流里的内容写到文件里 
writer.close();// 关闭输出流,施放资源 
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

public static String getRandomString(int length,String flg) { //length表示生成字符串的长度 
String baseall = "ABCDEFGHJKLMNPRSTUVWXY0123456789"; 
String base = "ABCDEFGHJKLMNPRSTUVWXY"; 
String intbase = "0123456789";
Random random = new Random(); 
StringBuffer sb = new StringBuffer(); 
for (int i = 0; i < length; i++) { 
int number;
if("A".equals(flg)){
number =    random.nextInt(intbase.length());
sb.append(intbase.charAt(number)); 
}
else if("B".equals(flg)){
number =    random.nextInt(base.length());
sb.append(base.charAt(number)); 
}else {
number = random.nextInt(baseall.length()); 
sb.append(baseall.charAt(number)); 
} 
} 
return sb.toString(); 
} 
}

 

转载于:https://www.cnblogs.com/liuyitan/p/6871804.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值