zoukankan      html  css  js  c++  java
  • 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+"
    ");// 写内容 
    
    }
    
    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(); 
    } 
    }
  • 相关阅读:
    魅族17系列真机谍照泄露 前摄挖孔将添新功能
    联想在S规则债券市场完成了里程碑式的新债券发行
    王小二切饼、马拦过河卒
    Codeforces Round #561 (Div. 2) A Tale of Two Lands 【二分】
    19年省赛后总结
    Winner Winner【模拟、位运算】
    GCDLCM 【米勒_拉宾素数检验 (判断大素数)】
    Floating-Point Hazard【求导公式】
    Communication【floyd判环+并查集】
    Largest Allowed Area【模拟+二分】
  • 原文地址:https://www.cnblogs.com/liuyitan/p/6871804.html
Copyright © 2011-2022 走看看