淘宝商城(天猫)高级技术专家.3年研发+3年性能测试调优/系统测试+4年团队管理与测试架构、研发系统实践. 新舞台新气象, 深化测试基础架构及研发架构,希望能在某个技术领域成为真正的技术大牛。欢迎荐才http://bbs.51testing.com/viewthread.php?tid=120496&extra=&page=1 .邮件: jianzhao.liangjz@alibaba-inc.com,MSN:liangjianzhao@163.com.微博:http://t.sina.com.cn/1674816524

IBM RPM项目管理系统性能测试脚本

上一篇 / 下一篇  2008-02-20 23:08:35 / 个人分类:java性能监控与调优

IBM RPM系统是WEB之上包装的非文本方式传输数据的系统。

 

为了开展性能测试,如何构造有效的网络包成为第一个坎。用YATT 嗅探器截获之前的通信包,保存为req.log。

 

 然后借用JAVA 里面HttpURLConnection 发送、接收数据,经测试通过。

 

 

import java.io.*;

import java.net.HttpURLConnection;

import java.util.Map;

import java.net.URL;

import java.util.zip.Deflater;

import java.util.zip.Inflater;

 

public class RpmSender {

     public static void main(String[] args) {

            try {

 

                   String log_dir = "D:\\rpm\\record2\\";

                   int bufferlen =20480;

                    URL url = new                 URL("http://rpm.alibaba-inc.com:9080/webapp/IBMRPM/PMOServlet.wss");

                   //URL url = new URL("http://10.0.32.123:8081/IBMRPM/PMOServlet.wss");

                   OutputStream ōut = null;

                   InputStream is = null;

                   HttpURLConnection httpConnection = null;

                   for (int i = 1; i <= 16; i++) {

                          httpConnection = (HttpURLConnection) url

                                        .openConnection();

 

                          httpConnection.setRequestProperty("Content-Type",

                                        "application/octet-stream");

                          httpConnection.setRequestProperty("Accept", "text/html, */*");

                          httpConnection.setRequestProperty("Pragma", "no-cache");

                          httpConnection.setRequestProperty("Keep-Alive", "Y");

                          httpConnection.setRequestProperty("Accept-Encoding",

                                        "deflate, identity");

                          httpConnection.setRequestProperty("Zip", "D");

                          httpConnection.setRequestProperty("User-Agent", "IBMRPM");

                          httpConnection.setRequestProperty("Method", "POST");

 

                          httpConnection.setDoInput(true);

                          httpConnection.setDoOutput(true);

 

                          out = new BufferedOutputStream(httpConnection.getOutputStream());

 

                          String reqfile = i + "_req.log";

                          String resultfile = "result_" + i + "_reponse.log";

                          FileInputStream fstream = new FileInputStream(log_dir + reqfile);

                          String charset = "UTF-8"; //GBK,ISO-8859-1,GB2312,UTF-8

                          byte[] ōutput = new byte[bufferlen];

                          int readbyte = fstream.read(output);

                          System.out.println(readbyte);

                          //httpConnection.setRequestProperty("Content-Length",new

                          // Integer(readbyte).toString() );

 

                          out.write(output, 0, readbyte);

                          out.flush();

 

                          byte[] buffer = new byte[bufferlen * 3];

                          byte[] tmp = new byte[bufferlen];

                          int length;

                          int total_len = 0;

 

                          is = httpConnection.getInputStream();

                          while ((length = is.read(tmp)) > -1) {

                                 System.arraycopy(tmp, 0, buffer, total_len, length);

                                 total_len += length;

                          }

                          System.out.println(total_len);

                          Inflater decompresser = new Inflater();

 

                          decompresser.setInput(buffer, 0, total_len);

                          byte[] result = new byte[4096];

 

                          int resultLength = decompresser.inflate(result);

                          decompresser.end();

                          FileOutputStream fout = new FileOutputStream(log_dir

                                        + resultfile);

                          fout.write(result, 0, resultLength);

                          fout.close();

                          // Decode the bytes into a String

                          // String ōutputString = new String(result);

                          String ōutputString = new String(result, 0, resultLength,

                                        charset); //"UTF-8");

                          System.out.println(outputString);

                          out.close();

                          is.close();

                          httpConnection.disconnect();

                   }

                   

 

            } catch (Exception e) {

                   e.printStackTrace();

            }

 

     }

}

 


TAG: java loadrunner rpm 脚本 java性能监控与调优

 

评分:0

我来说两句

Open Toolbar