debug and add some things about tasklist

This commit is contained in:
coderfengyun 2013-08-13 10:36:51 +08:00
parent 6e596d7f95
commit 4ba0d9ed0f
6 changed files with 95 additions and 11 deletions

View File

@ -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
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;
}

View File

@ -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<ScriptIdRequireLoadModel> scriptIdRequireLoads;
@XmlElementWrapper(name = "scriptIdRequireLoads")

View File

@ -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 {

View File

@ -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<TestPlanModel> taskList = new ArrayList<TestPlanModel>();
public AgentService getAgentService() {
return agentService;
@ -71,6 +72,41 @@ public class TestPlanRunner {
this.agentContext = agentContext;
}
@Autowired
public void setTaskList(List<TestPlanModel> 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<RunScenarioResultModel> runTestWithRunScenarioModel(
RunScenarioModel runScenarioModel, int requireLoad)
throws JAXBException {
@ -226,4 +262,5 @@ public class TestPlanRunner {
.getTotalCount());
return result;
}
}

View File

@ -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<String, String> properties = new HashMap<String, String>();
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<String, String> properties = new HashMap<String, String>();
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();
}
}

View File

@ -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 ";