标签:serial example continue 演示 应该 url front 脚本编写 nal
表述性状态传输(REST)作为对基于 SOAP 和 Web 服务描述语言(WSDL)的 Web 服务的简单替代,在 Web 开发上得到了广泛的接受。package com.crunchify.restjersey;
import java.io.FileNotFoundException;
import java.io.IOException;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
/**
* @author Crunchify
*
*/
@Path("/index")
public class CrunchifyJMeterTest {
@GET
@Produces("text/html")
public String checkECV() throws InterruptedException, FileNotFoundException, IOException {
String result = "<br><div align=‘center‘><h2>Hey This is Crunchify‘s JMeter Test...</h2></div>";
System.out.println(result);
Thread.sleep(1000);
return result;
}
}<?xml version="1.0" encoding="UTF-8"?>
<jmeterTestPlan version="1.2" properties="2.4" jmeter="2.9 r1437961">
<hashTree>
<TestPlan guiclass="TestPlanGui" testclass="TestPlan" testname="App Shah Desktop Test" enabled="true">
<stringProp name="TestPlan.comments"></stringProp>
<boolProp name="TestPlan.functional_mode">false</boolProp>
<boolProp name="TestPlan.serialize_threadgroups">false</boolProp>
<elementProp name="TestPlan.user_defined_variables" elementType="Arguments" guiclass="ArgumentsPanel" testclass="Arguments" testname="User Defined Variables" enabled="true">
<collectionProp name="Arguments.arguments"/>
</elementProp>
<stringProp name="TestPlan.user_define_classpath"></stringProp>
</TestPlan>
<hashTree>
<ThreadGroup guiclass="ThreadGroupGui" testclass="ThreadGroup" testname="Crunchify‘s REST Service JMeter Test" enabled="true">
<stringProp name="ThreadGroup.on_sample_error">continue</stringProp>
<elementProp name="ThreadGroup.main_controller" elementType="LoopController" guiclass="LoopControlPanel" testclass="LoopController" testname="Loop Controller" enabled="true">
<boolProp name="LoopController.continue_forever">false</boolProp>
<intProp name="LoopController.loops">-1</intProp>
</elementProp>
<stringProp name="ThreadGroup.num_threads">5</stringProp>
<stringProp name="ThreadGroup.ramp_time">2</stringProp>
<longProp name="ThreadGroup.start_time">1367432020000</longProp>
<longProp name="ThreadGroup.end_time">1367432020000</longProp>
<boolProp name="ThreadGroup.scheduler">false</boolProp>
<stringProp name="ThreadGroup.duration"></stringProp>
<stringProp name="ThreadGroup.delay"></stringProp>
</ThreadGroup>
<hashTree>
<HTTPSamplerProxy guiclass="HttpTestSampleGui" testclass="HTTPSamplerProxy" testname="HTTP Request" enabled="true">
<boolProp name="HTTPSampler.postBodyRaw">true</boolProp>
<elementProp name="HTTPsampler.Arguments" elementType="Arguments">
<collectionProp name="Arguments.arguments">
<elementProp name="" elementType="HTTPArgument">
<boolProp name="HTTPArgument.always_encode">false</boolProp>
<stringProp name="Argument.value"></stringProp>
<stringProp name="Argument.metadata">=</stringProp>
</elementProp>
</collectionProp>
</elementProp>
<stringProp name="HTTPSampler.domain">localhost</stringProp>
<stringProp name="HTTPSampler.port">8080</stringProp>
<stringProp name="HTTPSampler.connect_timeout">10000</stringProp>
<stringProp name="HTTPSampler.response_timeout">10000</stringProp>
<stringProp name="HTTPSampler.protocol"></stringProp>
<stringProp name="HTTPSampler.contentEncoding"></stringProp>
<stringProp name="HTTPSampler.path">/CrunchifyRESTJerseyExample/crunchify/index</stringProp>
<stringProp name="HTTPSampler.method">GET</stringProp>
<boolProp name="HTTPSampler.follow_redirects">true</boolProp>
<boolProp name="HTTPSampler.auto_redirects">false</boolProp>
<boolProp name="HTTPSampler.use_keepalive">true</boolProp>
<boolProp name="HTTPSampler.DO_MULTIPART_POST">false</boolProp>
<boolProp name="HTTPSampler.monitor">false</boolProp>
<stringProp name="HTTPSampler.embedded_url_re"></stringProp>
</HTTPSamplerProxy>
<hashTree/>
<ResultCollector guiclass="StatGraphVisualizer" testclass="ResultCollector" testname="Aggregate Graph" enabled="true">
<boolProp name="ResultCollector.error_logging">false</boolProp>
<objProp>
<name>saveConfig</name>
<value class="SampleSaveConfiguration">
<time>true</time>
<latency>true</latency>
<timestamp>true</timestamp>
<success>true</success>
<label>true</label>
<code>true</code>
<message>true</message>
<threadName>true</threadName>
<dataType>true</dataType>
<encoding>false</encoding>
<assertions>true</assertions>
<subresults>true</subresults>
<responseData>false</responseData>
<samplerData>false</samplerData>
<xml>true</xml>
<fieldNames>false</fieldNames>
<responseHeaders>false</responseHeaders>
<requestHeaders>false</requestHeaders>
<responseDataOnError>false</responseDataOnError>
<saveAssertionResultsFailureMessage>false</saveAssertionResultsFailureMessage>
<assertionsResultsToSave>0</assertionsResultsToSave>
<bytes>true</bytes>
</value>
</objProp>
<stringProp name="filename"></stringProp>
</ResultCollector>
<hashTree/>
<ResultCollector guiclass="StatVisualizer" testclass="ResultCollector" testname="Aggregate Report" enabled="true">
<boolProp name="ResultCollector.error_logging">false</boolProp>
<objProp>
<name>saveConfig</name>
<value class="SampleSaveConfiguration">
<time>true</time>
<latency>true</latency>
<timestamp>true</timestamp>
<success>true</success>
<label>true</label>
<code>true</code>
<message>true</message>
<threadName>true</threadName>
<dataType>true</dataType>
<encoding>false</encoding>
<assertions>true</assertions>
<subresults>true</subresults>
<responseData>false</responseData>
<samplerData>false</samplerData>
<xml>false</xml>
<fieldNames>false</fieldNames>
<responseHeaders>false</responseHeaders>
<requestHeaders>false</requestHeaders>
<responseDataOnError>false</responseDataOnError>
<saveAssertionResultsFailureMessage>false</saveAssertionResultsFailureMessage>
<assertionsResultsToSave>0</assertionsResultsToSave>
<bytes>true</bytes>
</value>
</objProp>
<stringProp name="filename"></stringProp>
</ResultCollector>
<hashTree/>
</hashTree>
</hashTree>
</hashTree>
</jmeterTestPlan>将其部署后,访问 wadl 地址 http://192.168.23.204/uas/resource/application.wadl:
/**
* 数据初始化
* @param request
* @return
*/
@Override
@POST
@Produces(MediaType.APPLICATION_JSON)
@Path("push")
public UserPushResponse push( UserPushRequest request) {
logger.info(">>>>用户" + request.getToken() + "信息初始化!");
logger.info(">>>>数据初始化请求报文:{}",
new Object[]{JsonUtils.object2jsonString(request)});
//返回报文
UserPushResponse response;
try {
//请求报文校验
userPushService.validateRequest(request);
//数据库操作
redisDao.set(request.getToken(), request.getValue(),
new Long(request.getTimeOut()));
//组织成功报文
response = userPushService.buildSucessResponse(request);
} catch (Exception e) {
logger.info(e.getMessage(), e);
response = userPushService.buildFailResposne(e);
}
logger.info("用户信息初始化响应报文:{}"
, new Object[]{JsonUtils.object2jsonString(response)});
return response;
} UserResource userResource = RESTfulJsonClientFactory.createClient(UserResource.class, VIP);
Logger logger = LoggerFactory.getLogger(this.getClass());
@Test
public void testResource() {
UserPushRequest pushRequest = new UserPushRequest();
pushRequest.setToken("mytest004");
UserInfoAndMenu userInfoAndMenu = new UserInfoAndMenu();
UserInfo userInfo = new UserInfo();
userInfo.setMerCode("102239");
userInfo.setAccountList(getAccountList());
userInfoAndMenu.setUserInfo(userInfo);
pushRequest.setValue(JsonUtils.object2jsonString(userInfoAndMenu));
pushRequest.setTimeOut(10000);
System.out.println("请求报文:{}"+JsonUtils.object2jsonString(pushRequest));
UserPushResponse response = userResource.push(pushRequest);
System.out.println("响应报文:{}"+JsonUtils.object2jsonString(response));
}TPS 数据:
Web Service 的压力测试脚本其实很好写,但是如果从建立 Web Service 的客户端比如写 BeanShell 实现本地执行远程服务调用的角度出发往往会落入复杂而繁琐的脚本开发调试中。换个思路,比如从协议的角度出发,Web Service 再复杂也脱离不了 HTTP 吧?然后借助合理的协议工具帮助下,看似复杂的脚本编写就会变得非常简单了。
如何使用 JMeter 调用你的 Restful Web Service?进行简单的压力测试和自动化测试
标签:serial example continue 演示 应该 url front 脚本编写 nal
原文地址:http://blog.csdn.net/defonds/article/details/54586338