remove the bug in recording script
This commit is contained in:
parent
015e6e67d9
commit
ff3ed52c7d
|
@ -2,10 +2,13 @@ package org.bench4q.master.api;
|
|||
|
||||
import java.io.File;
|
||||
import java.net.UnknownHostException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.bench4q.master.api.model.OperateScriptServerResponseModel;
|
||||
import org.bench4q.master.entity.db.Port;
|
||||
import org.bench4q.master.entity.db.Script;
|
||||
|
@ -65,33 +68,32 @@ public class ScriptController extends BaseController {
|
|||
public OperateScriptServerResponseModel startScriptRecordServer()
|
||||
throws UnknownHostException {
|
||||
if (!this.checkScope(UserService.NORAML_AUTHENTICATION)) {
|
||||
return _buildReponseModel(false,
|
||||
"has no power for recording script!!!", "", -1, null, null);
|
||||
return buildReponseModel(false,
|
||||
"has no power for recording script!!!", "", -1, 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);
|
||||
return buildReponseModel(false, "port is in use!", "", -1,
|
||||
null, null, null);
|
||||
}
|
||||
}
|
||||
|
||||
// this.setScriptCapturer(new ScriptCapturer(port.getPort(), System
|
||||
// .getProperty("user.dir") + File.separator, this.getPrincipal()
|
||||
// .getUserName()));
|
||||
|
||||
UUID uuid = UUID.randomUUID();
|
||||
this.getScriptCapturer().startRecord(port.getPort(),
|
||||
buildScriptSavePath());
|
||||
buildScriptSavePath(), uuid.toString());
|
||||
|
||||
return _buildReponseModel(true, "", this.getScriptCapturer()
|
||||
.getIpHttpCaptureServerAdress(), port.getPort(), null, null);
|
||||
return buildReponseModel(true, "", this.getScriptCapturer()
|
||||
.getIpHttpCaptureServerAdress(), port.getPort(), null, null,
|
||||
uuid.toString());
|
||||
}
|
||||
|
||||
private String buildScriptSavePath() {
|
||||
String dirString = "Scripts" + System.getProperty("file.separator")
|
||||
+ this.getPrincipal().getUserName()
|
||||
+ System.getProperty("file.separator") + new Date().getTime();
|
||||
+ System.getProperty("file.separator")
|
||||
+ new SimpleDateFormat("yyyyMMdd").format(new Date());
|
||||
File dirFile = new File(dirString);
|
||||
if (!dirFile.exists()) {
|
||||
dirFile.mkdirs();
|
||||
|
@ -103,41 +105,54 @@ public class ScriptController extends BaseController {
|
|||
RequestMethod.POST, RequestMethod.GET })
|
||||
@ResponseBody
|
||||
public OperateScriptServerResponseModel stopScriptRecordServer(
|
||||
@RequestParam int port) {
|
||||
|
||||
@RequestParam int port, @RequestParam String fileNameUUID) {
|
||||
if (!checkScope(UserService.NORAML_AUTHENTICATION)) {
|
||||
return _buildReponseModel(false,
|
||||
"has no power for stopScriptCapture!!!", "", -1, null, null);
|
||||
return buildReponseModel(false,
|
||||
"has no power for stopScriptCapture!!!", "", -1, null,
|
||||
null, null);
|
||||
}
|
||||
|
||||
if (this.getScriptCapturer() == null) {
|
||||
return _buildReponseModel(false,
|
||||
"there is no RecordingServer to stop", "", -1, null, null);
|
||||
return buildReponseModel(false,
|
||||
"there is no RecordingServer to stop", "", -1, null, null,
|
||||
null);
|
||||
}
|
||||
|
||||
this.getScriptCapturer().stopCurrentRecord(port);
|
||||
this.getScriptCapturer().shutHttpCaptureProxyServer(port);
|
||||
this.getPortPoolService().backThePortToPool(port);
|
||||
return _buildReponseModel(true, "RecordServer stop", "", port, null,
|
||||
null);
|
||||
return buildReponseModel(true, "RecordServer stop", "", port, null,
|
||||
null, fileNameUUID);
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/saveScriptToDB", method = { RequestMethod.GET,
|
||||
RequestMethod.POST })
|
||||
@ResponseBody
|
||||
public OperateScriptServerResponseModel saveScriptToDB(
|
||||
@RequestParam String scriptName, @RequestParam int port) {
|
||||
@RequestParam String scriptName, @RequestParam int port,
|
||||
@RequestParam String fileNameUUID) {
|
||||
|
||||
if (!this.checkScope(UserService.NORAML_AUTHENTICATION)) {
|
||||
return _buildReponseModel(false,
|
||||
"saveScriptToDB check your scope fail!", "", -1, null, null);
|
||||
return buildReponseModel(false,
|
||||
"saveScriptToDB check your scope fail!", "", -1, null,
|
||||
null, null);
|
||||
}
|
||||
|
||||
return _buildReponseModel(
|
||||
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);
|
||||
}
|
||||
try {
|
||||
return buildReponseModel(
|
||||
this.getScriptService().saveScriptToDB(scriptName,
|
||||
this.getPrincipal().getId(),
|
||||
this.getScriptCapturer().getScriptContent(port)),
|
||||
"Save to DataBase!!", "", port, null, null);
|
||||
FileUtils.readFileToString(file)),
|
||||
"Save to DataBase!!", "", port, null, null, null);
|
||||
} catch (Exception e) {
|
||||
return buildReponseModel(false, "exception when read from file",
|
||||
null, -1, null, null, fileNameUUID);
|
||||
}
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/uploadScriptToDB", method = { RequestMethod.GET,
|
||||
|
@ -153,8 +168,9 @@ public class ScriptController extends BaseController {
|
|||
if (!this.checkScope(UserService.NORAML_AUTHENTICATION)) {
|
||||
return null;
|
||||
}
|
||||
return this._buildReponseModel(true, null, null, 0, this
|
||||
.getScriptService().loadScripts(this.getPrincipal()), null);
|
||||
return this.buildReponseModel(true, null, null, 0, this
|
||||
.getScriptService().loadScripts(this.getPrincipal()), null,
|
||||
null);
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/queryScriptsByDate", method = RequestMethod.POST)
|
||||
|
@ -164,9 +180,9 @@ public class ScriptController extends BaseController {
|
|||
if (!this.checkScope(UserService.NORAML_AUTHENTICATION)) {
|
||||
return null;
|
||||
}
|
||||
return this._buildReponseModel(true, null, null, 0, this
|
||||
return this.buildReponseModel(true, null, null, 0, this
|
||||
.getScriptService()
|
||||
.queryScriptsByCreateTime(startDate, endDate), null);
|
||||
.queryScriptsByCreateTime(startDate, endDate), null, null);
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/queryScriptById", method = { RequestMethod.GET,
|
||||
|
@ -177,8 +193,8 @@ public class ScriptController extends BaseController {
|
|||
if (!this.checkScope(UserService.NORAML_AUTHENTICATION)) {
|
||||
return null;
|
||||
}
|
||||
return this._buildReponseModel(true, null, null, 0, null, this
|
||||
.getScriptService().getScriptById(scriptId));
|
||||
return this.buildReponseModel(true, null, null, 0, null, this
|
||||
.getScriptService().getScriptById(scriptId), null);
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/queryScriptByName", method = { RequestMethod.GET,
|
||||
|
@ -202,9 +218,9 @@ public class ScriptController extends BaseController {
|
|||
if (!this.checkScope(UserService.NORAML_AUTHENTICATION)) {
|
||||
return null;
|
||||
}
|
||||
return this._buildReponseModel(
|
||||
return this.buildReponseModel(
|
||||
this.getScriptService().deleteScript(scriptId), "", "", 0,
|
||||
null, null);
|
||||
null, null, null);
|
||||
}
|
||||
|
||||
@RequestMapping(value = "updateScript", method = { RequestMethod.GET,
|
||||
|
@ -215,19 +231,20 @@ public class ScriptController extends BaseController {
|
|||
if (!this.checkScope(UserService.NORAML_AUTHENTICATION)) {
|
||||
return null;
|
||||
}
|
||||
return this._buildReponseModel(
|
||||
return this.buildReponseModel(
|
||||
this.getScriptService().updateScript(scriptId, content), "",
|
||||
"", 0, null, null);
|
||||
"", 0, null, null, null);
|
||||
}
|
||||
|
||||
private OperateScriptServerResponseModel _buildReponseModel(
|
||||
private OperateScriptServerResponseModel buildReponseModel(
|
||||
boolean isSuccess, String failCauseString, String hostName,
|
||||
int port, List<Script> scripts, Script script) {
|
||||
int port, List<Script> scripts, Script script, String fileName) {
|
||||
OperateScriptServerResponseModel responseModel = new OperateScriptServerResponseModel();
|
||||
responseModel.setSuccess(isSuccess);
|
||||
responseModel.setFailCauseString(failCauseString);
|
||||
responseModel.setHostName(hostName);
|
||||
responseModel.setPort(port);
|
||||
responseModel.setFileName(fileName);
|
||||
if (scripts == null || scripts.size() == 0) {
|
||||
scripts = new ArrayList<Script>();
|
||||
scripts.add(script);
|
||||
|
|
|
@ -226,9 +226,8 @@ public class TestPlanController extends BaseController {
|
|||
response.setHeader("Content-disposition", "attachment; filename=\""
|
||||
+ testPlanRunID.toString() + ".pdf\"");
|
||||
response.addHeader("Content-Length", "" + pdfBuffer.length);
|
||||
// this.logger.info("report of test plan " +
|
||||
// testPlanRunID.toString()
|
||||
// + " length is: " + pdfBuffer.length);
|
||||
this.logger.info("report of test plan " + testPlanRunID.toString()
|
||||
+ " length is: " + pdfBuffer.length);
|
||||
response.setContentType("application/pdf");
|
||||
outputStream.write(pdfBuffer);
|
||||
outputStream.flush();
|
||||
|
|
|
@ -13,6 +13,7 @@ public class OperateScriptServerResponseModel {
|
|||
private String failCauseString;
|
||||
private String hostNameString;
|
||||
private int port;
|
||||
private String fileName;
|
||||
private List<Script> scripts;
|
||||
|
||||
@XmlElement
|
||||
|
@ -51,6 +52,15 @@ public class OperateScriptServerResponseModel {
|
|||
this.port = port;
|
||||
}
|
||||
|
||||
@XmlElement
|
||||
public String getFileName() {
|
||||
return fileName;
|
||||
}
|
||||
|
||||
public void setFileName(String fileName) {
|
||||
this.fileName = fileName;
|
||||
}
|
||||
|
||||
@XmlElement
|
||||
public List<Script> getScripts() {
|
||||
return scripts;
|
||||
|
|
|
@ -35,11 +35,11 @@ public class ScriptCapturer {
|
|||
}
|
||||
|
||||
public ScriptCapturer() {
|
||||
this.setIpHttpCaptureServerAdress(this._getLocalHostIp());
|
||||
this.setIpHttpCaptureServerAdress(this.getLocalHostIp());
|
||||
this.setHttpCaptureMap(new HashMap<Integer, HttpCapture>());
|
||||
}
|
||||
|
||||
private String _getLocalHostIp() {
|
||||
private String getLocalHostIp() {
|
||||
InetAddress addr;
|
||||
try {
|
||||
addr = InetAddress.getLocalHost();
|
||||
|
@ -51,45 +51,11 @@ public class ScriptCapturer {
|
|||
|
||||
}
|
||||
|
||||
private void startHttpCaptureProxyServer(int port, String filePath) {
|
||||
public void startRecord(int port, String fileDir, String fileName) {
|
||||
try {
|
||||
this.getHttpCaptureMap().get(new Integer(port)).startProxyServer();
|
||||
} catch (IOException e1) {
|
||||
System.out.println("Error When build the proxy server!");
|
||||
e1.printStackTrace();
|
||||
} catch (UserException e1) {
|
||||
System.out.println("Error When build the proxy server!");
|
||||
e1.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void shutHttpCaptureProxyServer(int port) {
|
||||
try {
|
||||
HttpCapture httpCapture = this.getHttpCaptureMap().get(
|
||||
new Integer(port));
|
||||
if (httpCapture == null) {
|
||||
return;
|
||||
}
|
||||
httpCapture.shutProxyServer();
|
||||
// if (httpCapture.isRecording()) {
|
||||
// httpCapture.stopRecording();
|
||||
// }
|
||||
// httpCapture.shutProxyServer();
|
||||
// this.setProxyServerRunning(false);
|
||||
} catch (IOException e1) {
|
||||
System.out.println("Error When shut the httpCapture proxy server!");
|
||||
e1.printStackTrace();
|
||||
} catch (UserException e1) {
|
||||
System.out.println("Error When shut the httpCapture proxy server!");
|
||||
e1.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void startRecord(int port, String filePath) {
|
||||
try {
|
||||
HttpCapture httpCapture = getCaptureDealWithNull(port, filePath);
|
||||
this.startHttpCaptureProxyServer(port, filePath);
|
||||
// this.startHttpCaptureProxyServer(this.getPortForRecord());
|
||||
HttpCapture httpCapture = getCaptureDealWithNull(port, fileDir,
|
||||
fileName);
|
||||
httpCapture.startProxyServer();
|
||||
httpCapture.startRecording();
|
||||
} catch (IOException e1) {
|
||||
System.out.println("Error When start recording!");
|
||||
|
@ -100,14 +66,15 @@ public class ScriptCapturer {
|
|||
}
|
||||
}
|
||||
|
||||
private HttpCapture getCaptureDealWithNull(int port, String filePath) {
|
||||
private HttpCapture getCaptureDealWithNull(int port, String filePath,
|
||||
String fileName) {
|
||||
HttpCapture httpCapture = this.getHttpCaptureMap().get(
|
||||
new Integer(port));
|
||||
if (httpCapture == null) {
|
||||
this.getHttpCaptureMap().put(
|
||||
new Integer(port),
|
||||
new HttpCapture(filePath, port, HTTPCATUREGENERATOR_STRING,
|
||||
new JTextArea()));
|
||||
new HttpCapture(filePath, fileName, port,
|
||||
HTTPCATUREGENERATOR_STRING, new JTextArea()));
|
||||
}
|
||||
return this.getHttpCaptureMap().get(new Integer(port));
|
||||
}
|
||||
|
@ -121,12 +88,9 @@ public class ScriptCapturer {
|
|||
}
|
||||
assert (httpCapture.isRecording());
|
||||
httpCapture.stopRecording();
|
||||
// assert (this.httpCapture.isRecording());
|
||||
// httpCapture.stopRecording();
|
||||
} catch (IOException e1) {
|
||||
System.out.println("Error When stop recording!");
|
||||
e1.printStackTrace();
|
||||
} catch (UserException e1) {
|
||||
httpCapture.shutProxyServer();
|
||||
this.getHttpCaptureMap().remove(new Integer(port));
|
||||
} catch (Exception e1) {
|
||||
System.out.println("Error When stop recording!");
|
||||
e1.printStackTrace();
|
||||
}
|
||||
|
@ -139,6 +103,5 @@ public class ScriptCapturer {
|
|||
return null;
|
||||
}
|
||||
return httpCapture.getScriptContent();
|
||||
// return this.httpCapture.getScriptContent();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,9 +2,12 @@ package org.bench4q.master.scriptrecord.httpcapture;
|
|||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
import javax.swing.JTextArea;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.bench4q.master.communication.agent.RunScenarioModel;
|
||||
|
||||
public class HttpCapture {
|
||||
|
@ -13,7 +16,9 @@ public class HttpCapture {
|
|||
private Test currentTest;
|
||||
private ProxyServer proxy;
|
||||
private File resultFile;
|
||||
private boolean proxyServerRuning;
|
||||
private ExecutorService executorService;
|
||||
private String scriptContent;
|
||||
private static Logger logger = Logger.getLogger(HttpCapture.class);
|
||||
|
||||
public int getLocalport() {
|
||||
return localport;
|
||||
|
@ -55,23 +60,23 @@ public class HttpCapture {
|
|||
this.resultFile = resultFile;
|
||||
}
|
||||
|
||||
public String getScriptContent() {
|
||||
return scriptContent;
|
||||
}
|
||||
|
||||
private void setScriptContent(String scriptContent) {
|
||||
this.scriptContent = scriptContent;
|
||||
}
|
||||
|
||||
public boolean isRecording() {
|
||||
return this.getCurrentTest().isRecording();
|
||||
}
|
||||
|
||||
public boolean isProxyServerRuning() {
|
||||
return proxyServerRuning;
|
||||
}
|
||||
|
||||
public void setProxyServerRuning(boolean proxyServerRuning) {
|
||||
this.proxyServerRuning = proxyServerRuning;
|
||||
}
|
||||
|
||||
public HttpCapture(String filepath, int localport, String generator,
|
||||
JTextArea textArea) {
|
||||
public HttpCapture(String filepath, String fileName, int localport,
|
||||
String generator, JTextArea textArea) {
|
||||
this.localport = localport;
|
||||
System.out.println(filepath + System.getProperty("file.separator")
|
||||
+ "Script.xml");
|
||||
+ fileName + ".xml");
|
||||
|
||||
File file = new File(filepath);
|
||||
if (!file.exists()) {
|
||||
|
@ -79,7 +84,7 @@ public class HttpCapture {
|
|||
}
|
||||
|
||||
this.resultFile = new File(filepath
|
||||
+ System.getProperty("file.separator") + "Script.xml");
|
||||
+ System.getProperty("file.separator") + fileName + ".xml");
|
||||
this.config = Config.getConfig();
|
||||
try {
|
||||
this.config.completeInit();
|
||||
|
@ -92,8 +97,9 @@ public class HttpCapture {
|
|||
}
|
||||
|
||||
public void startProxyServer() throws IOException, Utils.UserException {
|
||||
this.proxy.start();
|
||||
this.setProxyServerRuning(true);
|
||||
logger.info("enter startProxyServer!");
|
||||
this.executorService = Executors.newCachedThreadPool();
|
||||
this.executorService.execute(this.proxy);
|
||||
}
|
||||
|
||||
public void startRecording() throws IOException, Utils.UserException {
|
||||
|
@ -110,12 +116,13 @@ public class HttpCapture {
|
|||
public void shutProxyServer() throws IOException, Utils.UserException {
|
||||
if (this.proxy.getServerSocket() != null) {
|
||||
this.proxy.getServerSocket().close();
|
||||
this.proxy.interrupt();
|
||||
}
|
||||
this.executorService.shutdownNow();
|
||||
this.currentTest.close();
|
||||
this.retrieveScriptContent();
|
||||
}
|
||||
|
||||
public String getScriptContent() {
|
||||
return this.currentTest.getScriptContent();
|
||||
private void retrieveScriptContent() {
|
||||
this.setScriptContent(this.currentTest.getScriptContent());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,76 +2,72 @@ package org.bench4q.master.scriptrecord.httpcapture;
|
|||
|
||||
import java.io.IOException;
|
||||
import java.net.ServerSocket;
|
||||
import java.net.Socket;
|
||||
import java.util.Enumeration;
|
||||
import java.util.Vector;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
public class ProxyServer extends Thread {
|
||||
public class ProxyServer implements Runnable {
|
||||
private Vector<Observer> listeners;
|
||||
private ServerSocket srvSock;
|
||||
private int count;
|
||||
private static final Log log = LogFactory.getLog(ProxyServer.class);
|
||||
|
||||
public ProxyServer() throws IOException
|
||||
{
|
||||
public ProxyServer() throws IOException {
|
||||
this(0);
|
||||
}
|
||||
|
||||
public ProxyServer(int port)
|
||||
throws IOException
|
||||
{
|
||||
public ProxyServer(int port) throws IOException {
|
||||
this.srvSock = new ServerSocket(port);
|
||||
this.listeners = new Vector<Observer>();
|
||||
}
|
||||
|
||||
public void addObserver(Observer proxy)
|
||||
{
|
||||
public void addObserver(Observer proxy) {
|
||||
this.listeners.addElement(proxy);
|
||||
}
|
||||
|
||||
public void removeObserver(Observer proxy)
|
||||
{
|
||||
public void removeObserver(Observer proxy) {
|
||||
this.listeners.removeElement(proxy);
|
||||
}
|
||||
|
||||
public void processRequest(HttpRequestHeader header, byte[] requestBody) throws Exception
|
||||
{
|
||||
for (Enumeration<Observer> e = this.listeners.elements(); e.hasMoreElements(); ) {
|
||||
Observer pl = (Observer)e.nextElement();
|
||||
public void processRequest(HttpRequestHeader header, byte[] requestBody)
|
||||
throws Exception {
|
||||
for (Enumeration<Observer> e = this.listeners.elements(); e
|
||||
.hasMoreElements();) {
|
||||
Observer pl = (Observer) e.nextElement();
|
||||
pl.processRequest(header, requestBody);
|
||||
}
|
||||
}
|
||||
|
||||
public void processResponse(HttpRequestHeader header, byte[] response) throws Exception
|
||||
{
|
||||
for (Enumeration<Observer> e = this.listeners.elements(); e.hasMoreElements(); ) {
|
||||
Observer pl = (Observer)e.nextElement();
|
||||
public void processResponse(HttpRequestHeader header, byte[] response)
|
||||
throws Exception {
|
||||
for (Enumeration<Observer> e = this.listeners.elements(); e
|
||||
.hasMoreElements();) {
|
||||
Observer pl = (Observer) e.nextElement();
|
||||
pl.processResponse(header, response);
|
||||
}
|
||||
}
|
||||
|
||||
public void run()
|
||||
{
|
||||
System.out.println(" in run");
|
||||
while (!Thread.interrupted())
|
||||
if (!this.srvSock.isClosed())
|
||||
public void run() {
|
||||
if (this.getServerSocket().isClosed()) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
Socket s = this.srvSock.accept();
|
||||
RequestHandler handler = new RequestHandler(this, s);
|
||||
while (true) {
|
||||
RequestHandler handler = new RequestHandler(this, this
|
||||
.getServerSocket().accept());
|
||||
log.trace("New connection. Creating new RequestHandler thread.");
|
||||
Thread t = new Thread(handler, "MaxQRequestHandler #" + this.count);
|
||||
Thread t = new Thread(handler, "Bench4QRequestHandler #"
|
||||
+ this.getLocalPort() + "#" + this.count);
|
||||
t.start();
|
||||
this.count += 1;
|
||||
}
|
||||
catch (Throwable localThrowable)
|
||||
{
|
||||
} catch (Exception e) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
int getLocalPort()
|
||||
{
|
||||
int getLocalPort() {
|
||||
return this.srvSock.getLocalPort();
|
||||
}
|
||||
|
||||
|
@ -79,12 +75,13 @@ public class ProxyServer extends Thread {
|
|||
return this.srvSock;
|
||||
}
|
||||
|
||||
public static abstract interface Observer
|
||||
{
|
||||
public abstract void processRequest(HttpRequestHeader paramHttpRequestHeader, byte[] paramArrayOfByte)
|
||||
throws Exception;
|
||||
public static abstract interface Observer {
|
||||
public abstract void processRequest(
|
||||
HttpRequestHeader paramHttpRequestHeader,
|
||||
byte[] paramArrayOfByte) throws Exception;
|
||||
|
||||
public abstract void processResponse(HttpRequestHeader paramHttpRequestHeader, byte[] paramArrayOfByte)
|
||||
throws Exception;
|
||||
public abstract void processResponse(
|
||||
HttpRequestHeader paramHttpRequestHeader,
|
||||
byte[] paramArrayOfByte) throws Exception;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,7 +13,6 @@ public class Test {
|
|||
private IScriptAdapter scriptAdapter;
|
||||
private boolean isRecording;
|
||||
private File testFile;
|
||||
private String testName;
|
||||
ProxyServer proxyServer;
|
||||
|
||||
public Test(ProxyServer proxy, IScriptAdapter adapter, String generatorClass) {
|
||||
|
@ -57,11 +56,7 @@ public class Test {
|
|||
adapter.setText(script);
|
||||
this.generator = GeneratorFactory.newGenerator(generatorClass, adapter);
|
||||
this.generator.doLoad();
|
||||
this.testName = this.generator.parseTestName();
|
||||
}
|
||||
|
||||
public String getTestName() {
|
||||
return this.testName;
|
||||
this.generator.parseTestName();
|
||||
}
|
||||
|
||||
public File getTestFile() {
|
||||
|
@ -72,17 +67,6 @@ public class Test {
|
|||
this.testFile = file;
|
||||
}
|
||||
|
||||
public String getCurrentPath() {
|
||||
if (this.testFile == null) {
|
||||
return System.getProperty("user.dir");
|
||||
}
|
||||
return stripFileName(this.testFile.getAbsolutePath());
|
||||
}
|
||||
|
||||
public String[] getvalidTestFileExtensions() {
|
||||
return this.generator.getValidFileExtensions();
|
||||
}
|
||||
|
||||
public boolean isRecording() {
|
||||
return this.isRecording;
|
||||
}
|
||||
|
@ -122,10 +106,6 @@ public class Test {
|
|||
this.generator.close();
|
||||
}
|
||||
|
||||
public IScriptGenerator getGenerator() {
|
||||
return this.generator;
|
||||
}
|
||||
|
||||
public String getScriptContent() {
|
||||
return this.scriptAdapter.getText();
|
||||
}
|
||||
|
|
|
@ -106,20 +106,19 @@ public class PortPoolService {
|
|||
Session session = this.getSessionHelper().openSession();
|
||||
Transaction transaction = session.beginTransaction();
|
||||
try {
|
||||
System.out.println("back the port " + port + " to DB!");
|
||||
Port portEntity = (Port) session.createCriteria(Port.class)
|
||||
.add(Restrictions.eq("port", port)).uniqueResult();
|
||||
|
||||
if (portEntity == null) {
|
||||
if (portEntity == null || !portEntity.isInUse()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
portEntity.setInUse(false);
|
||||
transaction.commit();
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
transaction.rollback();
|
||||
return true;
|
||||
return false;
|
||||
} finally {
|
||||
if (session != null) {
|
||||
session.close();
|
||||
|
|
|
@ -63,6 +63,7 @@ public class LoadBallancer {
|
|||
UUID testPlanId) {
|
||||
synchronized (this.highAvailableAgentPool.getHighAvailablePool()) {
|
||||
if (!hasEnoughLoad(testPlanContext)) {
|
||||
logger.info("There is no enough load agent in the pool!");
|
||||
return false;
|
||||
}
|
||||
for (RunningScriptModel scriptInputModel : testPlanContext
|
||||
|
|
|
@ -2,10 +2,13 @@ package ModelTest;
|
|||
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
public class IpTest {
|
||||
public static void main(String[] args) throws UnknownHostException {
|
||||
InetAddress addr = InetAddress.getLocalHost();
|
||||
System.out.println(addr.getHostAddress().toString());
|
||||
System.out.println(new SimpleDateFormat("yyyyMMdd").format(new Date()));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,21 +0,0 @@
|
|||
package org.bench4q.master.test;
|
||||
|
||||
import javax.swing.JTextArea;
|
||||
|
||||
import org.bench4q.master.scriptrecord.httpcapture.HttpCapture;
|
||||
|
||||
public class HttpCaptureTest {
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
HttpCapture m = new HttpCapture("C:\\Temp", 8090,
|
||||
"maxq.generator.IsacCodeGenerator", new JTextArea());
|
||||
m.startProxyServer();
|
||||
m.startRecording();
|
||||
m.stopRecording();
|
||||
m.startRecording();
|
||||
m.stopRecording();
|
||||
m.shutProxyServer();
|
||||
} catch (Exception localException) {
|
||||
}
|
||||
}
|
||||
}
|
|
@ -35,9 +35,11 @@ public class RecordScriptControllerTest extends TestBase {
|
|||
|
||||
public void stopRecord(OperateScriptServerResponseModel model)
|
||||
throws IOException, JAXBException {
|
||||
Map<String, String> paramsMap = buildParams("port",
|
||||
String.valueOf(model.getPort()));
|
||||
paramsMap.put("fileNameUUID", model.getFileName());
|
||||
HttpResponse httpResponse = this.httpRequester.sendPost(this.SCRIPT_URL
|
||||
+ "/stopScriptRecordServer",
|
||||
buildParams("port", String.valueOf(model.getPort())),
|
||||
+ "/stopScriptRecordServer", paramsMap,
|
||||
this.makeAccessTockenMap(this.accessTocken));
|
||||
System.out.println(httpResponse.getContent());
|
||||
}
|
||||
|
@ -53,6 +55,7 @@ public class RecordScriptControllerTest extends TestBase {
|
|||
Map<String, String> params = new HashMap<String, String>();
|
||||
params.put("scriptName", scriptName);
|
||||
params.put("port", String.valueOf(model.getPort()));
|
||||
params.put("fileNameUUID", model.getFileName());
|
||||
HttpResponse httpResponse = this.httpRequester.sendPost(this.SCRIPT_URL
|
||||
+ "/saveScriptToDB", params,
|
||||
this.makeAccessTockenMap(this.getAccessTocken()));
|
||||
|
|
|
@ -26,10 +26,58 @@ import org.bench4q.master.service.TestPlanService;
|
|||
public class TestPlanTester extends TestBase {
|
||||
private TestPlanModel testPlan = new TestPlanModel();
|
||||
private String _url = TestBase.BASE_URL + "/testPlan";
|
||||
private static int SCRIPTID = 1;
|
||||
private int scriptSumNum;
|
||||
private static int SCRIPTID1 = 1;
|
||||
private static int SCRIPTID2 = 2;
|
||||
private static String Monitor_Host_Name = "127.0.0.1";
|
||||
private static String monitor_port = "5556";
|
||||
|
||||
public TestPlanModel getTestPlan() {
|
||||
return testPlan;
|
||||
}
|
||||
|
||||
public void setTestPlan(TestPlanModel testPlan) {
|
||||
this.testPlan = testPlan;
|
||||
}
|
||||
|
||||
public int getScriptSumNum() {
|
||||
return scriptSumNum;
|
||||
}
|
||||
|
||||
public void setScriptSumNum(int scriptSumNum) {
|
||||
this.scriptSumNum = scriptSumNum;
|
||||
}
|
||||
|
||||
public TestPlanTester(int scriptSumNum) {
|
||||
this.setScriptSumNum(scriptSumNum);
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws JAXBException, IOException,
|
||||
InterruptedException {
|
||||
TestPlanTester tester = new TestPlanTester(2);
|
||||
tester.setAccessTocken(tester.login());
|
||||
tester.runAndGetBrief();
|
||||
// tester.loadTestPlans();
|
||||
}
|
||||
|
||||
public void runAndGetBrief() throws IOException, JAXBException,
|
||||
InterruptedException {
|
||||
UUID testPlanID = this.testWithTestPlanModel();
|
||||
Thread.sleep(10000);
|
||||
TestPlanResultModel testPlanResultModel = this
|
||||
.getRunningInfo(testPlanID);
|
||||
while (testPlanResultModel.getCurrentStatus() != TestPlanService.TEST_PLAN_STATUS_IN_RUNNING) {
|
||||
Thread.sleep(6000);
|
||||
}
|
||||
for (int i = 0; i < 3; i++) {
|
||||
Thread.sleep(15000);
|
||||
this.getScriptBrief(testPlanID, SCRIPTID1);
|
||||
}
|
||||
|
||||
this.getMonitorBrief(testPlanID, Monitor_Host_Name, monitor_port);
|
||||
this.getTestPlanReport(testPlanID);
|
||||
}
|
||||
|
||||
public UUID testWithTestPlanModel() throws JAXBException, IOException {
|
||||
String content;
|
||||
TestPlanResultModel result = new TestPlanResultModel();
|
||||
|
@ -59,35 +107,52 @@ public class TestPlanTester extends TestBase {
|
|||
}
|
||||
|
||||
private void _createATestPlan() {
|
||||
if (this.getScriptSumNum() == 1) {
|
||||
this.testPlan.setRunningScriptModels(createOneScriptList());
|
||||
} else if (getScriptSumNum() == 2) {
|
||||
this.testPlan.setRunningScriptModels(createTowScriptList());
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
this.testPlan.setMonitorModles(createOneMonitorList());
|
||||
}
|
||||
|
||||
private List<MonitorModel> createOneMonitorList() {
|
||||
List<MonitorModel> monitors = new ArrayList<MonitorModel>();
|
||||
monitors.add(buildMonitorModel());
|
||||
return monitors;
|
||||
}
|
||||
|
||||
private List<RunningScriptModel> createOneScriptList() {
|
||||
List<RunningScriptModel> list = new ArrayList<RunningScriptModel>();
|
||||
list.add(buildScriptModel(SCRIPTID1));
|
||||
return list;
|
||||
}
|
||||
|
||||
private List<RunningScriptModel> createTowScriptList() {
|
||||
List<RunningScriptModel> list = new ArrayList<RunningScriptModel>();
|
||||
list.add(buildScriptModel(SCRIPTID1));
|
||||
list.add(buildScriptModel(SCRIPTID2));
|
||||
return list;
|
||||
}
|
||||
|
||||
private MonitorModel buildMonitorModel() {
|
||||
MonitorModel monitorModel = new MonitorModel();
|
||||
monitorModel.setHostName(Monitor_Host_Name);
|
||||
monitorModel.setPort(Integer.parseInt(monitor_port));
|
||||
return monitorModel;
|
||||
}
|
||||
|
||||
private RunningScriptModel buildScriptModel(int scriptID) {
|
||||
RunningScriptModel model = new RunningScriptModel();
|
||||
model.setScriptId(SCRIPTID);
|
||||
model.setRequireLoad(200);
|
||||
model.setScriptId(scriptID);
|
||||
model.setRequireLoad(400);
|
||||
TestScriptConfig config = new TestScriptConfig();
|
||||
config.setWarmUp(20);
|
||||
config.setExecuteRange(120);
|
||||
config.setCoolDown(10);
|
||||
model.setConfig(config);
|
||||
list.add(model);
|
||||
List<MonitorModel> monitors = new ArrayList<MonitorModel>();
|
||||
MonitorModel monitorModel = new MonitorModel();
|
||||
monitorModel.setHostName("127.0.0.1");
|
||||
monitorModel.setPort(5556);
|
||||
monitors.add(monitorModel);
|
||||
this.testPlan.setMonitorModles(monitors);
|
||||
this.testPlan.setRunningScriptModels(list);
|
||||
}
|
||||
|
||||
public String getAccessTocken() {
|
||||
return accessTocken;
|
||||
}
|
||||
|
||||
public void setAccessTocken(String accessTocken) {
|
||||
this.accessTocken = accessTocken;
|
||||
}
|
||||
|
||||
public TestPlanModel getTestPlan() {
|
||||
return testPlan;
|
||||
return model;
|
||||
}
|
||||
|
||||
public TestPlanResultModel getRunningInfo(UUID testPlanId)
|
||||
|
@ -184,15 +249,6 @@ public class TestPlanTester extends TestBase {
|
|||
System.out.println(httpResponse.getContent());
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws JAXBException, IOException,
|
||||
InterruptedException {
|
||||
TestPlanTester tester = new TestPlanTester();
|
||||
String accessTocken = tester.login();
|
||||
tester.setAccessTocken(accessTocken);
|
||||
tester.runAndGetBrief();
|
||||
// tester.loadTestPlans();
|
||||
}
|
||||
|
||||
public void loadTestPlans() throws IOException {
|
||||
HttpResponse httpResponse = this.httpRequester.sendGet(this._url
|
||||
+ "/loadTestPlans", null,
|
||||
|
@ -207,24 +263,4 @@ public class TestPlanTester extends TestBase {
|
|||
this.makeAccessTockenMap(this.getAccessTocken()));
|
||||
}
|
||||
|
||||
public void runAndGetBrief() throws IOException, JAXBException,
|
||||
InterruptedException {
|
||||
UUID testPlanID = this.testWithTestPlanModel();
|
||||
|
||||
Thread.sleep(10000);
|
||||
|
||||
TestPlanResultModel testPlanResultModel = this
|
||||
.getRunningInfo(testPlanID);
|
||||
if (testPlanResultModel.getCurrentStatus() != TestPlanService.TEST_PLAN_STATUS_IN_RUNNING) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i = 0; i < 3; i++) {
|
||||
Thread.sleep(15000);
|
||||
this.getScriptBrief(testPlanID, SCRIPTID);
|
||||
}
|
||||
|
||||
this.getMonitorBrief(testPlanID, Monitor_Host_Name, monitor_port);
|
||||
this.getTestPlanReport(testPlanID);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue