2016.5.10 随笔——Jmeter架入 java中使用 说明

其一:

下个 apache-jmeter-2.13  随便什么版本都行

其二:

 

java工程必须的3个jar。

在apache-jmeter-2.13的 lib - ext 中可以找到

其三:

写代码啊  例子如下

 1 public class MemcachedTest extends AbstractJavaSamplerClient{
 2     private static CacheData cacheData = CacheFactory.getCacheData("memcached");
 3     
 4     private static final String DEFINE_MAIN_TYPE = "zyw";
 5     private static AtomicInteger sums = new AtomicInteger(0);
 6     private static AtomicInteger sumst = new AtomicInteger(0);
 7 //    private static int i=0;
 8     
 9     public void setupTest(JavaSamplerContext arg0) {}
10 
11     public void teardownTest(JavaSamplerContext arg0) {}
12 
13     
14     public Arguments getDefaultParameters() {
15         Arguments args = new Arguments();
16         return args;
17     }
18     
19     @Override
20     public SampleResult runTest(JavaSamplerContext arg0) {
21         
22         SampleResult sr = new SampleResult();
23         Random rand = new Random();
24         int i = rand.nextInt(100000);
25 ////        i++;
26 //        i=getRandom(i);
27         int startDbid = 30001138;
28         int id = startDbid + i;
29         String idstr = String.valueOf(id);
30         try {
31             // Start
32             long l = System.currentTimeMillis();
33             sr.sampleStart();
34             
35             UserExtend userExtend = getUserExtend(idstr);
36             //System.out.println("This userextend's UserDbid is "+ userExtend.getUserExtendDbid());
37             if(userExtend == null){
38                 System.out.print(idstr+"出错");
39             }
40             sr.setSuccessful(true);
41         } catch (Exception e) {
42             e.printStackTrace();
43             sr.setSuccessful(false);
44         } finally {
45             // End
46             sr.sampleEnd();
47         }
48         return sr;
49     }
简要说明:
setupTest(JavaSamplerContext arg0) {} 开始前执行 public void teardownTest(JavaSamplerContext arg0) {} 结束后执行 public Arguments getDefaultParameters(){} 参数显示在Jmeter 图形页面上
基本形式:

@override
public SampleResult runTest(JavaSamplerContext arg0){
SampleResult sr = new SampleResult();
try {
sr.sampleStart();
sr.setSuccessful(true);
}catch(Exception e){
e.printStackTrace();
sr.setSuccessful(false);
}finally{
sr.sampleEnd();
}
return sr;
}


posted @ 2016-05-10 19:53  zzfufuyy  阅读(129)  评论(0编辑  收藏  举报