应用MapReduce制作压测利器

发表于:2013-11-06 11:22

字体: | 上一篇 | 下一篇 | 我要投稿

 作者:凡提    来源:51Testing软件测试网采编

分享:
  测试工具代码是发送http request部分,出于安全考虑,重要部分略过:
while(System.currentTimeMillis() - start <= runtime){
StringBuffer sb = new StringBuffer();
List<String> data = new ArrayList<String>();
HttpURLConnection httpurlconnection = null;
try{
URL url = new URL(this.reportAd);
httpurlconnection = (HttpURLConnection) url.openConnection();
httpurlconnection.setConnectTimeout(5000);
httpurlconnection.setReadTimeout(5000);
httpurlconnection.setDoOutput(true);
httpurlconnection.setRequestMethod("POST");
httpurlconnection.setRequestProperty("Content-type", "text/plain");
for(long i=0; i<this.recordnum; i++){
。。。。。。
s = Math.abs(R.nextLong())%102400000+1024;
staticWriteSize += s;
reporter.incrCounter("TestTool", "Write Size", s);
staticWriteTime += (endTime - startTime);
reporter.incrCounter("TestTool", "Write Time", endTime - startTime);
。。。。。。
}else{
。。。。。。
reporter.incrCounter("TestTool", "Read Size", s);
staticReadTime += (endTime - startTime);
reporter.incrCounter("TestTool", "Read Time", endTime - startTime);
。。。。。。
}
Pair p = value.get(R.nextInt(value.size()));
。。。。。。
staticCount++;
}
reporter.incrCounter("TestTool", "Record num", this.recordnum);
reporter.setStatus("Record: "+staticCount+"("+staticWrite+"w, "+staticRead+"r), Write Size: "
+staticWriteSize+", Write Time: "+staticWriteTime
+", Read Size: "+staticReadSize+", Read Time: "+staticReadTime);
httpurlconnection.getOutputStream().write(sb.toString().getBytes());
httpurlconnection.getOutputStream().flush();
httpurlconnection.getOutputStream().close();
int code = httpurlconnection.getResponseCode();
if(code != 200) {
LOG.warn("send data to master server failed, code=" + code);
}
reporter.incrCounter("TestTool", "Http Post num", 1);
map.staticPost.addAndGet(1);
Thread.sleep(interval);
} catch (Exception e) {
map.staticPost.addAndGet(1);
reporter.incrCounter("TestTool", e.getClass().toString(), 1);
LOG.warn(e.getMessage(), e);
} finally {
if (httpurlconnection != null) {
httpurlconnection.disconnect();
}
}
  有了工具代码之后,我们通过实现Mapper来封装该工具,因此上述代码中我使用了“org.apache.hadoop.mapred.Reporter”的方法“incrCounter(Stringarg0, String arg1, long arg2)”来对测试中的重要过程数据进行计数,该方法会将所有map/reduce task中汇报的arg0|arg1定义的值arg2进行相加,输出到MR的jobtracker页面上,通过观察作业执行页面可以实时获取这些测试执行过程信息。此外,我还调度了“setStatus(String arg0)”方法,该方法可以实时更新当前所处task的页面信息,提供更详细的单个task执行情况信息。jobdetails.jsp页面观察结果如下所示:
42/4<1234>
重磅发布,2022软件测试行业现状调查报告~

关注51Testing

联系我们

快捷面板 站点地图 联系我们 广告服务 关于我们 站长统计

法律顾问:上海漕溪律师事务所 项棋律师
版权所有 上海博为峰软件技术股份有限公司 Copyright©51testing.com 2003-2023
投诉及意见反馈:webmaster@51testing.com; 业务联系:service@51testing.com 021-64471599-8017

沪ICP备05003035号

沪公网安备 31010102002173号