connect with agent

This commit is contained in:
coderfengyun 2013-07-17 09:40:09 +08:00
parent 0258ffbbb4
commit 688de7d51f
16 changed files with 764 additions and 22 deletions

View File

@ -1,15 +1,18 @@
package org.bench4q.master;
import org.bench4q.master.service.AgentPoolService;
import org.eclipse.jetty.server.Connector;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.bio.SocketConnector;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.servlet.ServletHolder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.servlet.DispatcherServlet;
public class MasterServer {
private Server server;
private int port;
private AgentPoolService agentPoolService = new AgentPoolService();
private Server getServer() {
return server;
@ -31,6 +34,15 @@ public class MasterServer {
this.setPort(port);
}
public AgentPoolService getAgentPoolService() {
return agentPoolService;
}
@Autowired
public void setAgentPoolService(AgentPoolService agentPoolService) {
this.agentPoolService = agentPoolService;
}
public boolean start() {
try {
this.setServer(new Server());
@ -40,10 +52,12 @@ public class MasterServer {
ServletContextHandler servletContextHandler = new ServletContextHandler();
ServletHolder servletHolder = servletContextHandler.addServlet(
DispatcherServlet.class, "/");
servletHolder.setInitParameter("contextConfigLocation",
"classpath*:org/bench4q/master/config/application-context.xml");
servletHolder
.setInitParameter("contextConfigLocation",
"classpath*:org/bench4q/master/config/application-context.xml");
this.getServer().setHandler(servletContextHandler);
this.getServer().start();
this.getAgentPoolService().loadAgentPoolFromDB();
return true;
} catch (Exception e) {
e.printStackTrace();
@ -64,4 +78,5 @@ public class MasterServer {
this.setServer(null);
}
}
}

View File

@ -1,8 +1,17 @@
package org.bench4q.master.api;
import java.io.IOException;
import java.io.InputStream;
import java.util.Iterator;
import java.util.UUID;
import org.bench4q.master.api.model.AgentResponseModel;
import org.bench4q.master.api.model.RunScenarioResultModel;
import org.bench4q.master.entity.AgentInfo;
import org.bench4q.master.entity.Constant;
import org.bench4q.master.entity.HttpRequester;
import org.bench4q.master.entity.HttpRequester.HttpResponse;
import org.bench4q.master.entity.XMLSerial;
import org.bench4q.master.service.AgentPoolService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
@ -14,6 +23,8 @@ import org.springframework.web.bind.annotation.RequestParam;
@RequestMapping("/agentManage")
public class AgentController extends BaseController {
private AgentPoolService agentPoolService = new AgentPoolService();
private HttpRequester httpRequester = new HttpRequester();
private UUID runId;
private AgentPoolService getAgentPoolService() {
return agentPoolService;
@ -24,6 +35,23 @@ public class AgentController extends BaseController {
this.agentPoolService = agentPoolService;
}
public HttpRequester getHttpRequester() {
return httpRequester;
}
@Autowired
public void setHttpRequester(HttpRequester httpRequester) {
this.httpRequester = httpRequester;
}
public UUID getRunId() {
return runId;
}
private void setRunId(UUID runId) {
this.runId = runId;
}
@RequestMapping(value = "/AddAgentToPool", method = RequestMethod.POST)
public AgentResponseModel addAgentToPool(@RequestParam AgentInfo agentInfo) {
synchronized (Constant.getAgentLockInteger) {
@ -41,14 +69,13 @@ public class AgentController extends BaseController {
@RequestMapping(value = "/RemoveAgentFromPool", method = RequestMethod.POST)
public AgentResponseModel removeAgentFromPool(
@RequestParam AgentInfo agentInfo, @RequestParam String accessToken) {
@RequestParam String hostNameString) {
synchronized (Constant.getAgentLockInteger) {
if (!this.getAgentPoolService().removeAgentFromPool(
agentInfo.getIpAdress())) {
if (!this.getAgentPoolService().removeAgentFromPool(hostNameString)) {
return setAgentResponseModel(false,
"remove agent from DB fails in removeAgentFromPool");
}
Constant.AgentPool.remove(agentInfo.getIpAdress());
Constant.AgentPool.remove(hostNameString);
return setAgentResponseModel(true, "");
}
}
@ -72,7 +99,6 @@ public class AgentController extends BaseController {
}
public AgentResponseModel removeLoadFromAgentPool(AgentInfo agentInfo) {
// TODO:nowtimes, the lock is gross, we need a fineGrained.
AgentInfo agentInfo2 = Constant.AgentPool.get(agentInfo.getIpAdress());
if (agentInfo2 == null) {
return setAgentResponseModel(false,
@ -89,6 +115,29 @@ public class AgentController extends BaseController {
}
}
public boolean sendScriptContentToAgent(String hostNameString, int port, String scriptContent) {
try {
HttpResponse httpResponse = httpRequester.sendPostXml(hostNameString + ":" + port + "/test/run", scriptContent);
String responseContent = httpResponse.getContent();
RunScenarioResultModel runScenarioResultModel = XMLSerial.readObjectFromXML(InputStream.class.getResourceAsStream(responseContent));
this.setRunId(runScenarioResultModel.getRunId());
return true;
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return false;
}
}
public boolean askIsLivingMsgForAll() {
Iterator<AgentInfo> iterator = Constant.AgentPool.values().iterator();
while (iterator.hasNext()) {
iterator.next().askIsLiving();
}
return true;
}
private AgentResponseModel setAgentResponseModel(boolean isSuccess,
String failCauseString) {
AgentResponseModel agentResponseModel = new AgentResponseModel();
@ -96,5 +145,5 @@ public class AgentController extends BaseController {
agentResponseModel.setFailCauseString(failCauseString);
return agentResponseModel;
}
}

View File

@ -23,7 +23,6 @@ public class RecordScriptController extends BaseController {
return portForRecord;
}
@Autowired
public void setPortForRecord(int portForRecord) {
this.portForRecord = portForRecord;
}

View File

@ -1,6 +1,11 @@
package org.bench4q.master.api;
import java.util.Iterator;
import org.bench4q.master.entity.AgentInfo;
import org.bench4q.master.entity.Constant;
import org.bench4q.master.service.ScriptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@ -8,17 +13,58 @@ import org.springframework.web.bind.annotation.RequestParam;
@Controller
@RequestMapping("/testPlan")
public class TestPlanController extends BaseController{
public class TestPlanController extends BaseController {
private ScriptService scriptService = new ScriptService();
private AgentController agentController = new AgentController();
public ScriptService getScriptService() {
return scriptService;
}
@Autowired
public void setScriptService(ScriptService scriptService) {
this.scriptService = scriptService;
}
public AgentController getAgentController() {
return agentController;
}
@Autowired
public void setAgentController(AgentController agentController) {
this.agentController = agentController;
}
@RequestMapping(value = "/runTestPlanWithScriptId", method = RequestMethod.GET)
public void runTestPlanWithScriptId(@RequestParam String accessToken, @RequestParam int scriptId,
@RequestParam int requireLoad)
{
public void runTestPlanWithScriptId(@RequestParam int scriptId,
@RequestParam int requireLoad) {
String scriptContentString = this.getScriptService()
.getScriptContentById(scriptId);
this.runTestWithScriptContent(scriptContentString, requireLoad);
}
@RequestMapping(value = "/runTestPlanWithScriptFile", method = RequestMethod.POST)
public void runTestPlanWithScriptFile(@RequestParam String accessToken,
@RequestParam String scriptFile) {
}
@RequestMapping(value="/runTestPlanWithScriptFile", method = RequestMethod.POST)
public void runTestPlanWithScriptFile(@RequestParam String accessToken, @RequestParam String scriptFile)
public void runTestWithScriptContent(String scriptContentString, int requireLoad)
{
Iterator<AgentInfo> iterator;
for (iterator = Constant.AgentPool.values().iterator(); iterator
.hasNext();) {
AgentInfo agentInfo = iterator.next();
if (!agentInfo.askIsLiving()) {
continue;
}
if (agentInfo.getRemainLoad() > requireLoad) {
this.getAgentController().sendScriptContentToAgent(
agentInfo.getIpAdress(),
agentInfo.getPort(), scriptContentString);
}
}
}
}

View File

@ -0,0 +1,29 @@
package org.bench4q.master.api.model;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement(name = "parameter")
public class ParameterModel {
private String key;
private String value;
@XmlElement
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
@XmlElement
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
}

View File

@ -0,0 +1,53 @@
package org.bench4q.master.api.model;
import java.util.List;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement(name = "runScenario")
public class RunScenarioModel {
private int poolSize;
private int totalCount;
private List<UsePluginModel> usePlugins;
private List<UserBehaviorModel> userBehaviors;
@XmlElement
public int getPoolSize() {
return poolSize;
}
public void setPoolSize(int poolSize) {
this.poolSize = poolSize;
}
@XmlElement
public int getTotalCount() {
return totalCount;
}
public void setTotalCount(int totalCount) {
this.totalCount = totalCount;
}
@XmlElementWrapper(name = "usePlugins")
@XmlElement(name = "usePlugin")
public List<UsePluginModel> getUsePlugins() {
return usePlugins;
}
public void setUsePlugins(List<UsePluginModel> usePlugins) {
this.usePlugins = usePlugins;
}
@XmlElementWrapper(name = "userBehaviors")
@XmlElement(name = "userBehavior")
public List<UserBehaviorModel> getUserBehaviors() {
return userBehaviors;
}
public void setUserBehaviors(List<UserBehaviorModel> userBehaviors) {
this.userBehaviors = userBehaviors;
}
}

View File

@ -0,0 +1,21 @@
package org.bench4q.master.api.model;
import java.util.UUID;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement(name = "runScenarioResult")
public class RunScenarioResultModel {
private UUID runId;
@XmlElement
public UUID getRunId() {
return runId;
}
public void setRunId(UUID runId) {
this.runId = runId;
}
}

View File

@ -0,0 +1,43 @@
package org.bench4q.master.api.model;
import java.util.List;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement(name = "usePlugin")
public class UsePluginModel {
private String id;
private String name;
private List<ParameterModel> parameters;
@XmlElement
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
@XmlElement
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@XmlElementWrapper(name = "parameters")
@XmlElement(name = "parameter")
public List<ParameterModel> getParameters() {
return parameters;
}
public void setParameters(List<ParameterModel> parameters) {
this.parameters = parameters;
}
}

View File

@ -0,0 +1,42 @@
package org.bench4q.master.api.model;
import java.util.List;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement(name = "userBehavior")
public class UserBehaviorModel {
private String use;
private String name;
private List<ParameterModel> parameters;
@XmlElement
public String getUse() {
return use;
}
public void setUse(String use) {
this.use = use;
}
@XmlElement
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@XmlElementWrapper(name = "parameters")
@XmlElement(name = "parameter")
public List<ParameterModel> getParameters() {
return parameters;
}
public void setParameters(List<ParameterModel> parameters) {
this.parameters = parameters;
}
}

View File

@ -1,5 +1,8 @@
package org.bench4q.master.entity;
import java.io.IOException;
import org.bench4q.master.entity.HttpRequester.HttpResponse;
import org.springframework.beans.factory.annotation.Autowired;
public class AgentInfo {
@ -7,6 +10,7 @@ public class AgentInfo {
private int port;
private int maxLoad;
private int remainLoad;
private boolean isLiving;
private Object sync;
public AgentInfo(int port, int maxLoad, int remianLoad, String ipAdress) {
@ -56,4 +60,31 @@ public class AgentInfo {
private void setSync(Object sync) {
this.sync = sync;
}
public boolean getIsLiving() {
return isLiving;
}
public void setIsLiving(boolean b) {
this.isLiving = b;
}
public boolean askIsLiving() {
HttpRequester httpRequester = new HttpRequester();
try {
HttpResponse httpResponse = httpRequester
.sendGet(this.getIpAdress() + ":" + this.getPort() + "/",
null, null);
if (httpResponse.getCode() == 404) {
this.setIsLiving(false);
return false;
}
this.setIsLiving(true);
return true;
} catch (IOException e) {
e.printStackTrace();
this.setIsLiving(false);
return false;
}
}
}

View File

@ -0,0 +1,275 @@
package org.bench4q.master.entity;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.charset.Charset;
import java.util.HashMap;
import java.util.Map;
import java.util.Vector;
import org.springframework.stereotype.Component;
@Component
public class HttpRequester {
private String defaultContentEncoding;
public HttpRequester()
{
this.setDefaultContentEncoding(Charset.defaultCharset().name());
}
public String getDefaultContentEncoding() {
return defaultContentEncoding;
}
public void setDefaultContentEncoding(String defaultContentEncoding) {
this.defaultContentEncoding = defaultContentEncoding;
}
public HttpResponse sendPost(String urlString, Map<String, String> params)
throws IOException {
return this.send(urlString, "POST", params, "", null);
}
public HttpResponse sendPostXml(String urlString, String contentString) throws IOException
{
HashMap<String, String> hashMap = new HashMap<String, String>();
hashMap.put("Content-Type", "application/xml");
return this.send(urlString, "POST", null, contentString, hashMap);
}
public HttpResponse sendGet(String urlString, Map<String, String> params,
Map<String, String> properties) throws IOException {
return this.send(urlString, "GET", params, "", properties);
}
private HttpResponse send(String urlString, String method,
Map<String, String> parameters, String Content, Map<String, String> propertys)
throws IOException {
HttpURLConnection urlConnection = null;
if (method.equalsIgnoreCase("GET") && parameters != null) {
StringBuffer param = new StringBuffer();
int i = 0;
for (String key : parameters.keySet()) {
if (i == 0)
param.append("?");
else
param.append("&");
param.append(key).append("=").append(parameters.get(key));
i++;
}
urlString += param;
}
if (!urlString.startsWith("http://")) {
urlString = "http://" + urlString;
}
//urlString = URLEncoder.encode(urlString, "UTF-8");
URL url = new URL(urlString);
urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.setRequestMethod(method);
urlConnection.setDoOutput(true);
urlConnection.setDoInput(true);
urlConnection.setUseCaches(false);
if (propertys != null)
for (String key : propertys.keySet()) {
urlConnection.addRequestProperty(key, propertys.get(key));
}
if (method.equalsIgnoreCase("POST") && parameters != null) {
StringBuffer param = new StringBuffer();
for (String key : parameters.keySet()) {
param.append("&");
param.append(key).append("=").append(parameters.get(key));
}
urlConnection.getOutputStream().write(param.toString().getBytes());
urlConnection.getOutputStream().flush();
urlConnection.getOutputStream().close();
}
else if (method.equalsIgnoreCase("POST") && !Content.isEmpty()) {
urlConnection.getOutputStream().write(Content.getBytes());
urlConnection.getOutputStream().flush();
urlConnection.getOutputStream().close();
}
return this.makeContent(urlString, urlConnection);
}
private HttpResponse makeContent(String urlString,
HttpURLConnection urlConnection) {
// TODO Auto-generated method stub
HttpResponse httpResponser = new HttpResponse();
try {
InputStream in = urlConnection.getInputStream();
BufferedReader bufferedReader = new BufferedReader(
new InputStreamReader(in));
httpResponser.contentCollection = new Vector<String>();
StringBuffer temp = new StringBuffer();
String line = bufferedReader.readLine();
while (line != null) {
httpResponser.contentCollection.add(line);
temp.append(line).append("\r\n");
line = bufferedReader.readLine();
}
bufferedReader.close();
String ecod = urlConnection.getContentEncoding();
if (ecod == null)
ecod = this.defaultContentEncoding;
httpResponser.setUrlString(urlString);
httpResponser.setDefaultPort(urlConnection.getURL()
.getDefaultPort());
httpResponser.setPort(urlConnection.getURL().getPort());
httpResponser.setProtocol(urlConnection.getURL().getProtocol());
httpResponser.setContent(new String(temp.toString().getBytes(),
ecod));
httpResponser.setContentEncoding(ecod);
httpResponser.setCode(urlConnection.getResponseCode());
httpResponser.setMessage(urlConnection.getResponseMessage());
httpResponser.setContentType(urlConnection.getContentType());
httpResponser.setConnectTimeout(urlConnection.getConnectTimeout());
httpResponser.setReadTimeout(urlConnection.getReadTimeout());
return httpResponser;
} catch (IOException e) {
e.printStackTrace();
} finally {
if (urlConnection != null)
urlConnection.disconnect();
}
return null;
}
public class HttpResponse {
String urlString;
int defaultPort;
int port;
String protocol;
String contentEncoding;
String content;
String contentType;
int code;
String message;
int connectTimeout;
int readTimeout;
Vector<String> contentCollection;
public String getUrlString() {
return urlString;
}
public void setUrlString(String urlString) {
this.urlString = urlString;
}
public int getDefaultPort() {
return defaultPort;
}
public void setDefaultPort(int defaultPort) {
this.defaultPort = defaultPort;
}
public int getPort() {
return port;
}
public void setPort(int port) {
this.port = port;
}
public String getProtocol() {
return protocol;
}
public void setProtocol(String protocol) {
this.protocol = protocol;
}
public String getContentEncoding() {
return contentEncoding;
}
public void setContentEncoding(String contentEncoding) {
this.contentEncoding = contentEncoding;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
public String getContentType() {
return contentType;
}
public void setContentType(String contentType) {
this.contentType = contentType;
}
public int getCode() {
return code;
}
public void setCode(int code) {
this.code = code;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public int getConnectTimeout() {
return connectTimeout;
}
public void setConnectTimeout(int connectTimeout) {
this.connectTimeout = connectTimeout;
}
public int getReadTimeout() {
return readTimeout;
}
public void setReadTimeout(int readTimeout) {
this.readTimeout = readTimeout;
}
public Vector<String> getContentCollection() {
return contentCollection;
}
public void setContentCollection(Vector<String> contentCollection) {
this.contentCollection = contentCollection;
}
}
}

View File

@ -7,7 +7,8 @@ import javax.swing.JTextArea;
import org.bench4q.master.entity.httpcapture.HttpCapture;
import org.bench4q.master.entity.httpcapture.Utils.UserException;
import org.springframework.stereotype.Component;
@Component
public class ScriptCapturer {
//private HttpCapture httpCapture = null;
@ -19,6 +20,8 @@ public class ScriptCapturer {
private HttpCapture httpCapture;
private String scriptContentString;
public ScriptCapturer(){}
public ScriptCapturer(int portForRecord, String scriptParentPath, String userName)
{
this.setPortForRecord(portForRecord);

View File

@ -0,0 +1,35 @@
package org.bench4q.master.entity;
import java.beans.XMLDecoder;
import java.beans.XMLEncoder;
import java.io.InputStream;
import java.io.OutputStream;
public class XMLSerial {
public static <T> void writeObjectToXML(OutputStream out, T obj){
XMLEncoder xmlEncoder = null;
try{
xmlEncoder = new XMLEncoder(out);
xmlEncoder.writeObject(obj);
}finally{
if(null != xmlEncoder)
xmlEncoder.close();
}
}
@SuppressWarnings("unchecked")
public static <T> T readObjectFromXML(InputStream in){
T obj = null;
XMLDecoder xmlDecoder = null;
try{
xmlDecoder = new XMLDecoder(in);
obj = (T) xmlDecoder.readObject();
}finally{
if(null != xmlDecoder)
xmlDecoder.close();
}
return obj;
}
}

View File

@ -6,12 +6,13 @@ import org.bench4q.master.entity.db.Script;
import org.bench4q.master.helper.SessionHelper;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.criterion.Restrictions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@Component
public class ScriptService {
private SessionHelper sessionHelper = new SessionHelper();
private SessionHelper getSessionHelper() {
@ -23,8 +24,8 @@ public class ScriptService {
this.sessionHelper = sessionHelper;
}
public boolean saveScriptToDB(String scriptName, int userId, String scriptContentString)
{
public boolean saveScriptToDB(String scriptName, int userId,
String scriptContentString) {
Session session = this.getSessionHelper().openSession();
Transaction transaction = session.beginTransaction();
try {
@ -45,4 +46,26 @@ public class ScriptService {
}
}
}
public String getScriptContentById(int scriptId) {
Session session = this.getSessionHelper().openSession();
Transaction transaction = session.beginTransaction();
try {
Script script = (Script) session.createCriteria(Script.class)
.add(Restrictions.eq("id", scriptId)).uniqueResult();
if (script == null) {
return null;
}
return script.getScriptContent();
} catch (Exception e) {
e.printStackTrace();
transaction.rollback();
return null;
} finally {
if (session != null) {
session.close();
}
}
}
}

View File

@ -8,13 +8,15 @@ public class AgentPoolControllerTest {
public static void main(String[] args)
{
//(new AgentController()).addAgentToPool(new AgentInfo(6565, 500, 500, "133.133.12.6"));
(new AgentPoolService()).loadAgentPoolFromDB();
(new AgentController()).askIsLivingMsgForAll();
}
public void agentControllerTest()
{
AgentController agentController = new AgentController();
agentController.addAgentToPool(new AgentInfo(6565, 500, 500, "133.133.133.6"));
agentController.addAgentToPool(new AgentInfo(6565, 500, 500, "133.133.12.6"));
}
public void agentPoolServiceTest()

View File

@ -0,0 +1,76 @@
package org.bench4q.master.test;
import java.io.StringWriter;
import java.util.ArrayList;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import org.bench4q.master.api.TestPlanController;
import org.bench4q.master.api.model.ParameterModel;
import org.bench4q.master.api.model.RunScenarioModel;
import org.bench4q.master.api.model.UsePluginModel;
import org.bench4q.master.api.model.UserBehaviorModel;
import org.bench4q.master.service.AgentPoolService;
public class TestPlanTester {
public static void main(String[] args) throws JAXBException {
(new AgentPoolService()).loadAgentPoolFromDB();
RunScenarioModel runScenarioModel = new RunScenarioModel();
runScenarioModel.setTotalCount(100);
runScenarioModel.setPoolSize(100);
runScenarioModel.setUsePlugins(new ArrayList<UsePluginModel>());
runScenarioModel.setUserBehaviors(new ArrayList<UserBehaviorModel>());
UsePluginModel httpUsePluginModel = new UsePluginModel();
httpUsePluginModel.setId("http");
httpUsePluginModel.setName("Http");
httpUsePluginModel.setParameters(new ArrayList<ParameterModel>());
UsePluginModel timerUsePluginModel = new UsePluginModel();
timerUsePluginModel.setId("timer");
timerUsePluginModel.setName("ConstantTimer");
timerUsePluginModel.setParameters(new ArrayList<ParameterModel>());
runScenarioModel.getUsePlugins().add(httpUsePluginModel);
runScenarioModel.getUsePlugins().add(timerUsePluginModel);
UserBehaviorModel getUserBehaviorModel = new UserBehaviorModel();
getUserBehaviorModel.setName("Get");
getUserBehaviorModel.setUse("http");
getUserBehaviorModel.setParameters(new ArrayList<ParameterModel>());
ParameterModel parameterModelOne = new ParameterModel();
parameterModelOne.setKey("url");
parameterModelOne.setValue("http://133.133.12.6:6565");
getUserBehaviorModel.getParameters().add(parameterModelOne);
runScenarioModel.getUserBehaviors().add(getUserBehaviorModel);
UserBehaviorModel timerUserBehaviorModel = new UserBehaviorModel();
timerUserBehaviorModel.setName("Sleep");
timerUserBehaviorModel.setUse("timer");
timerUserBehaviorModel.setParameters(new ArrayList<ParameterModel>());
ParameterModel parameterModelTwo = new ParameterModel();
parameterModelTwo.setKey("time");
parameterModelTwo.setValue("1000");
timerUserBehaviorModel.getParameters().add(parameterModelTwo);
runScenarioModel.getUserBehaviors().add(timerUserBehaviorModel);
UserBehaviorModel postUserBehaviorModel = new UserBehaviorModel();
postUserBehaviorModel.setName("Post");
postUserBehaviorModel.setUse("http");
postUserBehaviorModel.setParameters(new ArrayList<ParameterModel>());
ParameterModel parameterModelThree = new ParameterModel();
parameterModelThree.setKey("url");
parameterModelThree.setValue("http://133.133.12.6:6565");
postUserBehaviorModel.getParameters().add(parameterModelThree);
ParameterModel parameterModelFour = new ParameterModel();
parameterModelFour.setKey("content");
parameterModelFour.setValue("Hello,world!");
postUserBehaviorModel.getParameters().add(parameterModelFour);
runScenarioModel.getUserBehaviors().add(postUserBehaviorModel);
Marshaller marshaller = JAXBContext.newInstance(
runScenarioModel.getClass()).createMarshaller();
StringWriter stringWriter = new StringWriter();
marshaller.marshal(runScenarioModel, stringWriter);
String content = stringWriter.toString();
(new TestPlanController()).runTestWithScriptContent(content, 100);
}
}