Conflicts:

Bench4Q-Agent/src/main/java/org/bench4q/agent/scenario/engine/ScenarioCo
ntext.java

Bench4Q-Agent/src/main/java/org/bench4q/agent/scenario/engine/ScenarioEn
gine.java

Bench4Q-Master/src/main/java/org/bench4q/master/api/TestPlanController.j
ava

Bench4Q-Web/src/main/java/org/bench4q/web/masterMessager/TestPlanMessage
r.java

Bench4Q-Web/src/test/java/org/bench4q/web/test/masterMessager/TestPlanMe
ssageTest.java
This commit is contained in:
coderfengyun 2014-09-01 16:18:08 +08:00
commit 70985ffdef
12 changed files with 191 additions and 27 deletions

View File

@ -19,7 +19,12 @@
<param name="respVarsToSaveInSession"
label="The regular expression of extracting variables from response" required="false">
<table cols="varName|varRegularExpression|leftBoundry|rightBoundry" />
</param>
<param name="expResCode" label="The expected code of response" required="false">
<field size="7" />
</param>
<param name="expResCnttype" label="The expected content-type of response" required="false">
<field size="7" />
</param>
</params>
</behavior>
@ -39,6 +44,12 @@
required="false">
<table cols="varName|varRegularExpression|leftBoundry|rightBoundry" />
</param>
<param name="expResCode" label="The expected code of response" required="false">
<field size="7" />
</param>
<param name="expResCnttype" label="The expected content-type of response" required="false">
<field size="7" />
</param>
</params>
</behavior>
<behavior name="Post">
@ -63,6 +74,12 @@
required="false">
<table cols="varName|varRegularExpression|leftBoundry|rightBoundry" />
</param>
<param name="expResCode" label="The expected code of response" required="false">
<field size="7" />
</param>
<param name="expResCnttype" label="The expected content-type of response" required="false">
<field size="7" />
</param>
</params>
</behavior>
<behavior name="Put">
@ -87,6 +104,12 @@
required="false">
<table cols="varName|varRegularExpression|leftBoundry|rightBoundry" />
</param>
<param name="expResCode" label="The expected code of response" required="false">
<field size="7" />
</param>
<param name="expResCnttype" label="The expected content-type of response" required="false">
<field size="7" />
</param>
</params>
</behavior>
</ui>

View File

@ -0,0 +1,65 @@
@@ -0,0 +1,64 @@
package org.bench4q.agent.scenario;
import java.util.LinkedList;
import java.util.List;
import org.bench4q.share.models.agent.scriptrecord.ScheduleModel;
import org.bench4q.share.models.agent.scriptrecord.ScheduleModel.PointModel;
public class TestSchedule {
private List<Segment> points;
public List<Segment> getPoints() {
return points;
}
public void setPoints(List<Segment> points) {
this.points = points;
}
public static class Segment {
private final Point start;
private final Point end;
private final int growthUnit;
public Segment(Point startPoint, Point endPoint) {
this.start = new Point(startPoint.time, startPoint.load);
}
}
public static class Point {
private final int time;
private final int load;
public int getTime() {
return time;
}
public int getLoad() {
return load;
}
public Point(int time, int load) {
// TODO Auto-generated constructor stub
this.time = time;
this.load = load;
}
}
public static TestSchedule build(TestScheduleModel scheduleModel) {
TestSchedule schedule = new TestSchedule();
schedule.setPoints(extractPoints(scheduleModel.getPoints()));
return null;
}
private static List<Point> extractPoints(List<PointModel> points) {
List<Point> result = new LinkedList<TestSchedule.Point>();
for (PointModel model : points) {
result.add(new Point(model.getTime(), model.getLoad()));
}
return result;
}
}

View File

@ -102,14 +102,14 @@ public class ScriptController extends BaseController {
if (!this.checkScope(UserService.NORAML_AUTHENTICATION)) {
return buildReponseModel(false,
"has no power for recording script!!!", "", -1, null, null,
null);
null,null);
}
Port port = new Port();
synchronized (PORT_LOCK) {
port = this.getPortPoolService().getAPortNotInUse();
if (port == null) {
return buildReponseModel(false, "port is in use!", "", -1,
null, null, null);
null, null, null,null);
}
}
UUID uuid = UUID.randomUUID();
@ -118,7 +118,7 @@ public class ScriptController extends BaseController {
return buildReponseModel(true, "", this.getScriptCapturer()
.getIpHttpCaptureServerAdress(), port.getPort(), null, null,
uuid.toString());
uuid.toString(),null);
}
@RequestMapping(value = "/startScriptRecording", method = {
@ -129,13 +129,13 @@ public class ScriptController extends BaseController {
if (!checkScope(UserService.NORAML_AUTHENTICATION)) {
return buildReponseModel(false,
"has no power for stopScriptCapture!!!", "", -1, null,
null, null);
null, null,null);
}
this.getScriptCapturer().startRecording(port);
return buildReponseModel(true, "RecordServer stop", "", port, null,
null, fileNameUUID);
null, fileNameUUID,null);
}
private String buildScriptSavePath() {
@ -158,7 +158,7 @@ public class ScriptController extends BaseController {
if (!checkScope(UserService.NORAML_AUTHENTICATION)) {
return buildReponseModel(false,
"has no power for stopScriptCapture!!!", "", -1, null,
null, null);
null, null,null);
}
this.getScriptCapturer().stopCurrentRecord(port);
@ -167,7 +167,7 @@ public class ScriptController extends BaseController {
}
return buildReponseModel(true, "RecordServer stop", "", port, null,
null, fileNameUUID);
null, fileNameUUID,null);
}
@RequestMapping(value = "/saveScriptToDB", method = { RequestMethod.GET,
@ -179,14 +179,14 @@ public class ScriptController extends BaseController {
if (!this.checkScope(UserService.NORAML_AUTHENTICATION)) {
return buildReponseModel(false,
"saveScriptToDB check your scope fail!", "", -1, null,
null, null);
null, null,null);
}
File file = new File(buildScriptSavePath()
+ System.getProperty("file.separator") + fileNameUUID + ".xml");
if (!file.exists()) {
return buildReponseModel(false, "no that script", null, -1, null,
null, fileNameUUID);
null, fileNameUUID,null);
}
try {
String content = FileUtils.readFileToString(file);
@ -195,10 +195,10 @@ public class ScriptController extends BaseController {
this.getPrincipal().getId(), content, null);
// this.getUserService().add
return buildReponseModel(success, "Save to DataBase!!", "", port,
null, null, null);
null, null, null,null);
} catch (Exception e) {
return buildReponseModel(false, "exception when read from file",
null, -1, null, null, fileNameUUID);
null, -1, null, null, fileNameUUID,null);
}
}
@ -218,12 +218,12 @@ public class ScriptController extends BaseController {
boolean success = this.getScriptService().saveScript(scriptName,
this.getPrincipal().getId(), scenarioModel, paramFiles);
logger.info("upload script:" + scenarioModel);
return buildReponseModel(success, null, null, -1, null, null, null);
return buildReponseModel(success, null, null, -1, null, null, null,null);
} catch (Exception e) {
this.logger.error(ExceptionLog.getStackTrace(e));
return buildReponseModel(false,
"The script is not in the right format", null, -1, null,
null, null);
null, null,null);
}
}
@ -238,8 +238,22 @@ public class ScriptController extends BaseController {
this.getPrincipal());
return this.buildReponseModel(true, null, null, 0,
dealWithCollection(scripts), null, null);
dealWithCollection(scripts), null, null,null);
}
@RequestMapping(value = "/loadFilterTypeList", method = { RequestMethod.POST,
RequestMethod.GET })
@ResponseBody
public OperateScriptServerResponseModel loadFilterTypeList() {
if (!this.checkScope(UserService.NORAML_AUTHENTICATION)) {
return null;
}
String[] filterTypeList = this.getScriptService().loadFilterTypeList();
return this.buildReponseModel(true, null, null, 0,
null, null, null,filterTypeList);
}
@RequestMapping(value = "/queryScriptsByDate", method = RequestMethod.POST)
@ResponseBody
@ -252,7 +266,7 @@ public class ScriptController extends BaseController {
.queryScriptsByCreateTime(startDate, endDate,
this.getPrincipal());
return this.buildReponseModel(true, null, null, 0,
dealWithCollection(scripts), null, null);
dealWithCollection(scripts), null, null,null);
}
private List<ScriptModel> dealWithCollection(Collection<Script> scripts) {
@ -273,7 +287,7 @@ public class ScriptController extends BaseController {
}
return this.buildReponseModel(true, null, null, 0, null,
BusinessModelMapFactory.toModel(this.getScriptService()
.getScript(scriptId)), null);
.getScript(scriptId)), null,null);
}
@RequestMapping(value = "/queryScriptByName", method = { RequestMethod.GET,
@ -287,7 +301,7 @@ public class ScriptController extends BaseController {
}
return this.buildReponseModel(true, null, null, 0, null,
BusinessModelMapFactory.toModel(this.getScriptService()
.getScriptByName(name)), null);
.getScriptByName(name)), null,null);
}
@RequestMapping(value = "/deleteScript", method = { RequestMethod.GET,
@ -301,7 +315,7 @@ public class ScriptController extends BaseController {
return this.buildReponseModel(
this.getScriptService().deleteScript(scriptId,
this.getPrincipal().getId()), "", "", 0, null, null,
null);
null,null);
}
@RequestMapping(value = "updateScript/{scriptId}", method = {
@ -316,7 +330,7 @@ public class ScriptController extends BaseController {
return this.buildReponseModel(
this.getScriptService().alterScriptContent(scriptId,
this.getPrincipal().getId(),content,scriptName), "", "", 0, null,
null, null);
null, null,null);
}
// @RequestMapping(value = "updateScript/{scriptId}", method = {
@ -347,7 +361,7 @@ public class ScriptController extends BaseController {
private OperateScriptServerResponseModel buildReponseModel(
boolean isSuccess, String failCauseString, String hostName,
int port, List<ScriptModel> scriptModels, ScriptModel scriptModel,
String fileName) {
String fileName,String[] filterTypeList) {
OperateScriptServerResponseModel responseModel = new OperateScriptServerResponseModel();
responseModel.setSuccess(isSuccess);
responseModel.setFailCauseString(failCauseString);
@ -359,6 +373,7 @@ public class ScriptController extends BaseController {
scriptModels.add(scriptModel);
}
responseModel.setScriptModels(scriptModels);
responseModel.setFilterTypeList(filterTypeList);
return responseModel;
}

View File

@ -287,7 +287,7 @@ public class PluginEntityFactory {
ParamType parentContainer) {
ChoiceType choiceType = new ChoiceType();
choiceType.setValue(XmlParseHelper.getAttribute(element, "value"));
choiceType.setDefaultValue(Boolean.getBoolean(XmlParseHelper
choiceType.setDefaultValue(Boolean.parseBoolean(XmlParseHelper
.getAttribute(element, "default")));
choiceType.setParentContainer(parentContainer);
return choiceType;

View File

@ -1,7 +1,10 @@
package org.bench4q.master.domain.service;
import java.io.IOException;
import java.io.InputStream;
import java.util.Date;
import java.util.List;
import java.util.Properties;
import javax.xml.bind.JAXBException;
@ -18,12 +21,15 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;
@Component
public class ScriptService {
private ScriptRepositoty scriptRepositoty;
private UserRepository userRepository;
private Logger logger = Logger.getLogger(ScriptService.class);
private Properties properties = null;
private ScriptRepositoty getScriptRepositoty() {
return scriptRepositoty;
}
@ -75,6 +81,11 @@ public class ScriptService {
public List<Script> loadScripts(User user) {
return this.getScriptRepositoty().loadEntities(user);
}
public String[] loadFilterTypeList() {
return getFilterTypeList();
}
public List<Script> queryScriptsByCreateTime(Date startDate, Date endDate,
User user) {
@ -119,4 +130,20 @@ public class ScriptService {
script.setScriptContent(content);
return this.getScriptRepositoty().update(script);
}
private String[] getFilterTypeList(){
if(properties == null){
try {
properties = new Properties();
InputStream inputStream = ScriptService.class.getClassLoader()
.getResourceAsStream(
"org/bench4q/master/config/FilterType.properties");
properties.load(inputStream);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return properties.getProperty("filter.type.list","").split(",");
}
}

View File

@ -0,0 +1 @@
filter.type.list=text/css,text/html,text/plain,image/*,*javascript,application/json,application/xml

View File

@ -163,8 +163,8 @@ public class RequestHandler implements Runnable {
this.serverIn = serverConnection.getInputStream();
synchronized (mutex) {
this.proxyServer.processRequest(this.header, requestBody);
log.trace("processed request");
// this.proxyServer.processRequest(this.header, requestBody);
// log.trace("processed request");
this.buffer.reset();
int len;

View File

@ -173,7 +173,7 @@ public abstract class AbstractCodeGenerator implements IScriptGenerator,
// doParseRequest(header, requestBody);
}
private void doParseRequest(HttpRequestHeader header, byte[] requestBody)
private void doParseRequest(HttpRequestHeader header, byte[] requestBody, int respCode, String respContentType)
throws UserException, UnsupportedEncodingException {
Param[] params;
int i;
@ -342,7 +342,7 @@ public abstract class AbstractCodeGenerator implements IScriptGenerator,
&& responseHeader.isHtmlContentType()
&& hasHtmlTag(responseParser)) {
dealWithHtmlResponse(header, responseParser);
doParseRequest(header, requestBody);
doParseRequest(header, requestBody, responseHeader.getRespCode(), responseHeader.getContentType());
response.setResponse(responseParser.encodeCoent(doParseHtmlContent(responseParser.getResponseBody(), header.url)));
setStruts(new String(response.getResponse()).toLowerCase().indexOf(
@ -357,7 +357,7 @@ public abstract class AbstractCodeGenerator implements IScriptGenerator,
log.debug("Ignoring response because content type is not known: "
+ responseHeader.getRespCode());
}
doParseRequest(header, requestBody);
doParseRequest(header, requestBody, responseHeader.getRespCode(), responseHeader.getContentType());
}
private boolean hasHtmlTag(ResponseParser responseParser) {

View File

@ -19,6 +19,7 @@ public class OperateScriptServerResponseModel {
private int port;
private String fileName;
private List<ScriptModel> scriptModels;
private String[] filterTypeList;
@XmlElement
public boolean isSuccess() {
@ -74,4 +75,13 @@ public class OperateScriptServerResponseModel {
this.scriptModels = scriptModels;
}
@XmlElement
public String[] getFilterTypeList() {
return filterTypeList;
}
public void setFilterTypeList(String[] filterTypeList) {
this.filterTypeList = filterTypeList;
}
}

View File

@ -1,6 +1,7 @@
package org.bench4q.share.models.master;
import java.util.Date;
import java.util.List;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

View File

@ -6,6 +6,7 @@ import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.xml.bind.JAXBException;
import org.apache.log4j.Logger;
@ -357,6 +358,21 @@ public class ScriptController extends BaseController {
return map;
}
@RequestMapping("loadFilterTypeList")
public @ResponseBody
Map<String, Object> loadFilterTypeList(HttpServletRequest request,
@ModelAttribute("accessToken") String accessToken) {
OperateScriptServerResponseModel responseModel = this.getScriptMessager().loadFilterTypeList(accessToken);
Map<String,Object> map = new HashMap<String, Object>();
if(responseModel.isSuccess()){
map.put("filterTypeList", responseModel.getFilterTypeList());
success(map);
}else{
fail(map, responseModel.getFailCauseString());
}
return map;
}
private void updateRunScenarioModel(RunScenarioModel runScenarioModel) {
List<BehaviorModel> behaviorModels = new LinkedList<BehaviorModel>();

View File

@ -189,6 +189,12 @@ public class ScriptMessager extends MasterMessager {
accessToken);
}
public OperateScriptServerResponseModel loadFilterTypeList(String accessToken) {
String url = this.getBaseUrl() + "/loadFilterTypeList";
return this.getOperateScriptServerResponseModelByPost(url, null,
accessToken);
}
private OperateScriptServerResponseModel getOperateScriptServerResponseModelByPost(
String url, Map<String, String> params, String accessToken) {
HttpResponse httpResponse = null;