From 4ba0d9ed0fbf9594e08b31f37d244d43df3837c8 Mon Sep 17 00:00:00 2001 From: coderfengyun Date: Tue, 13 Aug 2013 10:36:51 +0800 Subject: [PATCH] debug and add some things about tasklist --- .../master/api/RecordScriptController.java | 14 ++++--- .../master/api/model/TestPlanModel.java | 3 ++ .../entity/httpcapture/HttpCapture.java | 7 ++++ .../master/testPlan/TestPlanRunner.java | 41 ++++++++++++++++++- .../test/RecordScriptControllerTest.java | 39 +++++++++++++++++- .../org/bench4q/master/test/TestBase.java | 2 +- 6 files changed, 95 insertions(+), 11 deletions(-) diff --git a/src/main/java/org/bench4q/master/api/RecordScriptController.java b/src/main/java/org/bench4q/master/api/RecordScriptController.java index a292676c..e05ce843 100644 --- a/src/main/java/org/bench4q/master/api/RecordScriptController.java +++ b/src/main/java/org/bench4q/master/api/RecordScriptController.java @@ -1,5 +1,7 @@ package org.bench4q.master.api; +import java.io.File; + import org.bench4q.master.api.model.OperateScriptServerResponseModel; import org.bench4q.master.entity.ScriptCapturer; import org.bench4q.master.entity.db.Port; @@ -41,10 +43,9 @@ public class RecordScriptController extends BaseController { this._portPoolService = portPoolService; } - @RequestMapping(value = "/startScriptRecordServer", method = RequestMethod.GET) + @RequestMapping(value = "/startScriptRecordServer", method = RequestMethod.POST) @ResponseBody public OperateScriptServerResponseModel startScriptRecordServer() { - if (!this.checkScope(UserService.NORAML_AUTHENTICATION)) { return setResponseModel(false, "has no power for recording script!!!", "", -1); @@ -58,18 +59,18 @@ public class RecordScriptController extends BaseController { this.setPortForRecord(port.getPort()); } - _scriptCapturer = new ScriptCapturer(this._portForRecord, null, this - .getPrincipal().getUserName()); + this._scriptCapturer = new ScriptCapturer(this._portForRecord, + System.getProperty("user.dir") + File.separator, this + .getPrincipal().getUserName()); _scriptCapturer.startCurrentRecord(); - System.out.println("server started and begin to wait!"); return setResponseModel(true, "", this._scriptCapturer.getIpHttpCaptureServerAdress(), this._scriptCapturer.getPortForRecord()); } - @RequestMapping(value = "/stopScriptRecordServer", method = RequestMethod.GET) + @RequestMapping(value = "/stopScriptRecordServer", method = RequestMethod.POST) @ResponseBody public OperateScriptServerResponseModel stopScriptRecordServer() { @@ -111,6 +112,7 @@ public class RecordScriptController extends BaseController { responseModel.setSuccess(isSuccess); responseModel.setFailCauseString(failCauseString); responseModel.setHostName(hostName); + responseModel.setPort(port); return responseModel; } diff --git a/src/main/java/org/bench4q/master/api/model/TestPlanModel.java b/src/main/java/org/bench4q/master/api/model/TestPlanModel.java index 112989de..69aa77b2 100644 --- a/src/main/java/org/bench4q/master/api/model/TestPlanModel.java +++ b/src/main/java/org/bench4q/master/api/model/TestPlanModel.java @@ -4,8 +4,11 @@ import java.util.List; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlElementWrapper; +import javax.xml.bind.annotation.XmlRootElement; +@XmlRootElement(name = "testPlanModel") public class TestPlanModel { + // private UUID private List scriptIdRequireLoads; @XmlElementWrapper(name = "scriptIdRequireLoads") diff --git a/src/main/java/org/bench4q/master/entity/httpcapture/HttpCapture.java b/src/main/java/org/bench4q/master/entity/httpcapture/HttpCapture.java index 8abf3c5a..c74d9b16 100644 --- a/src/main/java/org/bench4q/master/entity/httpcapture/HttpCapture.java +++ b/src/main/java/org/bench4q/master/entity/httpcapture/HttpCapture.java @@ -16,6 +16,13 @@ public class HttpCapture { public HttpCapture(String filepath, int localport, String generator, JTextArea textArea) { this.localport = localport; + System.out.println(filepath + "\\Script.xml"); + + File file = new File(filepath); + if (!file.exists()) { + file.mkdirs(); + } + this.resultFile = new File(filepath + "\\Script.xml"); this.config = Config.getConfig(); try { diff --git a/src/main/java/org/bench4q/master/testPlan/TestPlanRunner.java b/src/main/java/org/bench4q/master/testPlan/TestPlanRunner.java index b7799bac..aca997b2 100644 --- a/src/main/java/org/bench4q/master/testPlan/TestPlanRunner.java +++ b/src/main/java/org/bench4q/master/testPlan/TestPlanRunner.java @@ -14,6 +14,7 @@ import javax.xml.bind.Marshaller; import javax.xml.bind.Unmarshaller; import org.bench4q.master.api.model.AgentBriefModel; +import org.bench4q.master.api.model.TestPlanModel; import org.bench4q.master.communication.AgentStateService; import org.bench4q.master.communication.HttpRequester; import org.bench4q.master.communication.HttpRequester.HttpResponse; @@ -26,14 +27,14 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @Component -public class TestPlanRunner { +public class TestPlanRunner implements Runnable { private AgentService agentService; private AgentStateService agentStateService; private HttpRequester httpRequester; private AgentContext agentContext; - private static final int port = 6565; + private List taskList = new ArrayList(); public AgentService getAgentService() { return agentService; @@ -71,6 +72,41 @@ public class TestPlanRunner { this.agentContext = agentContext; } + @Autowired + public void setTaskList(List taskList) { + this.taskList = taskList; + } + + public void addATask(TestPlanModel task) { + synchronized (this.taskList) { + this.taskList.add(task); + this.taskList.notifyAll(); + } + + } + + public void removeATask(int index) { + this.taskList.remove(index); + } + + public void run() { + // TODO Auto-generated method stub + try { + while (!Thread.interrupted()) { + synchronized (this.taskList) { + if (this.taskList.size() == 0) { + this.taskList.wait(); + } + while (this.taskList.size() > 0) { + removeATask(0); + } + } + } + } catch (Exception e) { + // TODO: handle exception + } + } + public List runTestWithRunScenarioModel( RunScenarioModel runScenarioModel, int requireLoad) throws JAXBException { @@ -226,4 +262,5 @@ public class TestPlanRunner { .getTotalCount()); return result; } + } diff --git a/src/test/java/org/bench4q/master/test/RecordScriptControllerTest.java b/src/test/java/org/bench4q/master/test/RecordScriptControllerTest.java index 6c8fd634..b91099f2 100644 --- a/src/test/java/org/bench4q/master/test/RecordScriptControllerTest.java +++ b/src/test/java/org/bench4q/master/test/RecordScriptControllerTest.java @@ -1,7 +1,42 @@ package org.bench4q.master.test; +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; + +import javax.xml.bind.JAXBException; + +import org.bench4q.master.communication.HttpRequester.HttpResponse; + public class RecordScriptControllerTest extends TestBase { - public void startRecord() { - // this.httpRequester.sendGet(urlString, params, properties) + private final String SCRIPT_URL = this.BASEURL + "/RecordScript"; + + public void startRecord() throws IOException, JAXBException { + String accesTocken = this.login(); + Map properties = new HashMap(); + properties.put(this.AUTH_HEADER_PROPERTY, this.ACCES_TOCKEN_STARTER + + accesTocken); + HttpResponse httpResponse = this.httpRequester.sendPost(this.SCRIPT_URL + + "/startScriptRecordServer", null, properties); + System.out.println(httpResponse.getContent()); + } + + public void stopRecord() throws IOException, JAXBException { + String accesTocken = this.login(); + Map properties = new HashMap(); + properties.put(this.AUTH_HEADER_PROPERTY, this.ACCES_TOCKEN_STARTER + + accesTocken); + HttpResponse httpResponse = this.httpRequester.sendPost(this.SCRIPT_URL + + "/stopScriptRecordServer", null, properties); + System.out.println(httpResponse.getContent()); + } + + public static void main(String[] args) throws IOException, JAXBException, + InterruptedException { + RecordScriptControllerTest test = new RecordScriptControllerTest(); + test.startRecord(); + Thread.sleep(60000); + System.out.println("Thread has waken up"); + test.stopRecord(); } } diff --git a/src/test/java/org/bench4q/master/test/TestBase.java b/src/test/java/org/bench4q/master/test/TestBase.java index b4265de3..17fcf0bc 100644 --- a/src/test/java/org/bench4q/master/test/TestBase.java +++ b/src/test/java/org/bench4q/master/test/TestBase.java @@ -17,7 +17,7 @@ public class TestBase { protected HttpRequester httpRequester = new HttpRequester(); private final String USERNAME = "chen"; private final String PASSWORD = "123"; - private final String BASEURL = "http://localhost:8080"; + protected final String BASEURL = "http://localhost:8080"; protected final String AUTH_HEADER_PROPERTY = "Authorization"; protected final String ACCES_TOCKEN_STARTER = "Bearer ";