zoukankan      html  css  js  c++  java
  • 更新

    stopAll:function(){
    let that = this;
    that.axios.post("/test/stressFile/stopAll")
    .then(function (res) {
    if (res.data.code==0){that.$notify.success({title:"Success", message:"停止成功"});}
    else{that.$notify.error({title:"Error", message:"停止失败,错误信息:"+res.data.msg});}
    }).catch(function (error) {
    that.$notify.error({title:"Error", message:"删除失败,错误信息:"+error});
    });
    },



    /**
         * 根据模板生成OSP压测脚本
         */
        @RequestMapping("/generateJmx")
        public void generateJmx(HttpServletRequest request){
            Long caseId = Long.valueOf(request.getParameter("caseId"));
            String jmxName = request.getParameter("jmxName");
            Map contextMap = new HashMap();
            String contextStr = request.getParameter("context");
            Gson gson = new Gson();
            contextMap = gson.fromJson(contextStr,contextMap.getClass());
            StressTestFileEntity stressCaseFile = new StressTestFileEntity();
            try {
                //获取case信息
                StressTestEntity stressTestEntity = stressTestService.queryObject(caseId);
                String casePath = stressTestUtils.getCasePath();
                //filePath=E:/worktools/apache-jmeter-4.0/stressTestCases/2018110915275893/case20181109152758960.jmx
                String filePath;
                Map<String, Object> query = new HashMap<String, Object>();
                query.put("originName", jmxName);
                // fileList中最多有一条记录
                List<StressTestFileEntity> fileList = stressTestFileService.queryList(query);
                if (!fileList.isEmpty()){
                    throw new RRException("系统中已经存在此文件记录!不允许生成同名文件!");
                }else{
                    stressCaseFile.setOriginName(jmxName+".jmx");
                    Date caseAddTime = stressTestEntity.getAddTime();
                    String caseAddTimeStr = DateUtils.format(caseAddTime, DateUtils.DATE_TIME_PATTERN_4DIR);
                    String caseFilePath;
    
                    if (StringUtils.isEmpty(stressTestEntity.getCaseDir())) {
                        //random使用时间种子的随机数,避免了轻度并发造成文件夹重名.
                        caseFilePath = caseAddTimeStr + new Random(System.nanoTime()).nextInt(1000);
                        stressTestEntity.setCaseDir(caseFilePath);
                    } else {
                        caseFilePath = stressTestEntity.getCaseDir();
                    }
    
                    String jmxRealName = "case" + caseAddTimeStr +
                            new Random(System.nanoTime()).nextInt(1000) + ".jmx";
    //                    stressCaseFile.setFileName(caseFilePath + "/" + jmxRealName);
                    filePath = casePath + "/" + caseFilePath + "/" + jmxRealName;
                    stressCaseFile.setFileName(filePath);
                    stressCaseFile.setCaseId(caseId);
                }
    
                //freemaker的配置
                Configuration cfg = new Configuration(Configuration.VERSION_2_3_28);
                cfg.setClassForTemplateLoading(this.getClass(),"/templates");
                cfg.setDefaultEncoding("UTF-8");
                cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
                //freemaker的模板文件
                Template temp = cfg.getTemplate("jmxTemp.ftl");
    
                // 输出流
                //Writer writer = new BufferedWriter(new FileWriter("report.html"));
                OutputStream out=new FileOutputStream(filePath);
                Writer writer = new BufferedWriter(new OutputStreamWriter(out,"utf-8"));//解决乱码问题
    
                temp.process(contextMap,writer);
    
                stressTestFileService.save(stressCaseFile);
            } catch (IOException e) {
                throw new RRException("IO异常,可能找不到模板文件。"+e.getMessage());
            } catch (TemplateException e) {
                throw new RRException("模板生成文件异常:"+e.getMessage());
            }
        }
  • 相关阅读:
    my live health
    network / switchboard / jiaohuanji / switch
    my live boadband
    proxyServer Squid 3.5.5 / 20181111
    db mysql / mysql cluster 5.7.19 / performance
    MPTCP v0.92 Release
    MPTCP
    外国专家:区块链是新的Linux 而非新的互联网
    为什么用 Unity 3D 开发游戏是用 C# || JS 开发而不是用C++
    树莓派、 Arduino 、传统单片机开发板该如何选择?
  • 原文地址:https://www.cnblogs.com/zipon/p/9965369.html
Copyright © 2011-2022 走看看