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());
            }
        }
  • 相关阅读:
    CSS中:display:none与visible:hidden的区别
    $(function(){})和$(document).ready(function(){}) 的用法
    JavaScript 全选函数的实现
    HTML:关于a标签的target属性
    CSS:给 input 中 type="text" 设置CSS样式
    JavaScript中“javascript:void(0) ”是什么意思
    Oracle数据库——数据库安全性管理
    使用JavaScript根据从后台获取来的数据打开一个新的页面
    java reflect反射---Java高级开发必须懂的
    Java 类加载机制
  • 原文地址:https://www.cnblogs.com/zipon/p/9965369.html
Copyright © 2011-2022 走看看