add url which parent are same into same batch

This commit is contained in:
hmm 2014-09-15 08:53:46 +08:00
parent 21e3cf4f9f
commit ef31716fcd
5 changed files with 56 additions and 32 deletions

View File

@ -55,7 +55,8 @@ public class ScriptCapturer {
try {
HttpCapture httpCapture = buildACapture(port);
httpCapture.startProxyServer();
httpCapture.startRecording( fileDir, fileName);
httpCapture.startRecording( fileDir, fileName,
HTTPCATUREGENERATOR_STRING);
} catch (IOException e1) {
System.out.println("Error When start recording!");
e1.printStackTrace();
@ -79,7 +80,7 @@ public class ScriptCapturer {
public void startRecording(int port, String filePath, String fileName){
try {
HttpCapture httpCapture = this.getHttpCaptureMap().get(new Integer(port));
httpCapture.startRecording( filePath, fileName);
httpCapture.startRecording( filePath, fileName, HTTPCATUREGENERATOR_STRING);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
@ -89,8 +90,7 @@ public class ScriptCapturer {
}
}
private HttpCapture buildACapture(int port) {
HttpCapture httpCapture = new HttpCapture(port,
HTTPCATUREGENERATOR_STRING, new JTextArea());
HttpCapture httpCapture = new HttpCapture(port, new JTextArea());
this.getHttpCaptureMap().put(new Integer(port), httpCapture);
return httpCapture;
}

View File

@ -24,6 +24,7 @@ public class Bench4qTestScriptAdapter implements IScriptAdapter {
private int pageCount;
private RunScenarioModel runScenarioModel;
private List<ChildrenUrl> childrenUrls = new ArrayList<ChildrenUrl>();
private BehaviorModel preTimerBehavior = null;
private static Logger logger = Logger
.getLogger(Bench4qTestScriptAdapter.class);
@ -85,17 +86,30 @@ public class Bench4qTestScriptAdapter implements IScriptAdapter {
return;
}
guardChildBatchExist(batches, parentBatchId);
batches.get(batches.get(parentBatchId).getChildId()).getBehaviors()
getBatchById(batches, getBatchById(batches, parentBatchId).getChildId()).getBehaviors()
.add(model);
}
private void guardChildBatchExist(List<BatchModel> batches,
private BatchModel getBatchById(List<BatchModel> batches, int batchId){
for(BatchModel batchModel : batches){
if(batchModel.getId() == batchId){
return batchModel;
}
}
return null;
}
private boolean guardChildBatchExist(List<BatchModel> batches,
int parentBatchId) {
if (isChildBatchAbsent(batches, parentBatchId)) {
BatchModel batchBehavior = createBatchBehaviorWithProperBatchId();
batchBehavior.setParentId(parentBatchId);
batches.add(batchBehavior);
batches.get(parentBatchId).setChildId(batches.size() - 1);
BatchModel parentBatch = getBatchById(batches,parentBatchId);
if(parentBatch != null){
parentBatch.setChildId(batchBehavior.getId());
}
return false;
}else{
return true;
}
}
@ -129,10 +143,14 @@ public class Bench4qTestScriptAdapter implements IScriptAdapter {
private boolean isChildBatchAbsent(List<BatchModel> batches,
int parentBatchId) {
if (parentBatchId >= batches.size()) {
return false;
// if (parentBatchId >= batches.size()) {
// return false;
// }
BatchModel batchModel = getBatchById(batches, parentBatchId);
if(batchModel != null){
return batchModel.getChildId() < 0;
}
return batches.get(parentBatchId).getChildId() < 0;
return false;
}
private boolean isIndependent(int parentBatchId) {

View File

@ -96,7 +96,7 @@ public class HttpCapture {
// new RunScenarioModel()), generator);
// }
public HttpCapture(int localport, String generator, JTextArea textArea) {
public HttpCapture(int localport,JTextArea textArea) {
this.localport = localport;
this.config = Config.getConfig();
@ -106,8 +106,8 @@ public class HttpCapture {
} catch (Exception e) {
e.printStackTrace();
}
this.currentTest = new Test(this.proxy, new Bench4qTestScriptAdapter(
new RunScenarioModel()), generator);
// this.currentTest = new Test(this.proxy, new Bench4qTestScriptAdapter(
// new RunScenarioModel()), generator);
}
public void startProxyServer() throws IOException, Utils.UserException {
@ -116,8 +116,12 @@ public class HttpCapture {
this.executorService.execute(this.proxy);
}
public void startRecording(String dirPath, String fileName)
public void startRecording(String dirPath, String fileName, String generator)
throws IOException, Utils.UserException {
this.currentTest = new Test(this.proxy, new Bench4qTestScriptAdapter(
new RunScenarioModel()), generator);
System.out.println(dirPath + System.getProperty("file.separator")
+ fileName + ".xml");

View File

@ -48,7 +48,7 @@ public abstract class AbstractCodeGenerator implements IScriptGenerator,
protected boolean headersExist = false;
private IScriptAdapter scriptAdapter;
private String testName;
private boolean ignoreNextResponse;
private boolean ignoreNextResponse = true;
private Pattern[] namePatterns;
private LinkedList<BehaviorModel> outstandingInserts = new LinkedList<BehaviorModel>();
private Thread insertThread;
@ -199,7 +199,7 @@ public abstract class AbstractCodeGenerator implements IScriptGenerator,
String newCharset = null;
newCharset = doForCharset(header.contentType);
//set header in Bench4qCodeGenerator
doHeaders(createHeaders(header));
String url = header.url;
@ -211,6 +211,7 @@ public abstract class AbstractCodeGenerator implements IScriptGenerator,
} else if (method.equals("post")) {
method = "Post";
}
//add url and queryParams to action
int pos = url.indexOf("?");
if ((pos != -1) && (url.length() > pos + 1)) {
setQueryStringParams(action, url.substring(pos + 1));
@ -218,6 +219,7 @@ public abstract class AbstractCodeGenerator implements IScriptGenerator,
} else {
action.setUrl(url);
}
//add request body to action according to request content type
if (requestBody.length > 0) {
if (isMultiPartRequest) {
setMultiPartData(action, header, requestBody);
@ -233,7 +235,7 @@ public abstract class AbstractCodeGenerator implements IScriptGenerator,
}
}
//nothing
if (action.getParamsCount() > 0) {
params = action.getParams();
for (i = 0; i < params.length; ++i) {
@ -244,9 +246,9 @@ public abstract class AbstractCodeGenerator implements IScriptGenerator,
if ((value.indexOf("+") != -1) || (value.indexOf("%") != -1))
params[i].value = HttpTestCase.staticUrlDecode(value);
}
doParameterList(params);
doParameterList(params);//nothing
}
//set the Bench4qCodeGenerator queryStringParameters
if (action.getQueryStringParamCount() > 0) {
params = action.getQueryStringParams();
@ -260,7 +262,7 @@ public abstract class AbstractCodeGenerator implements IScriptGenerator,
}
doQueryStringParameterList(params);
}
//set the Bench4qCodeGenerator bodyParameters
if (action.getBodyParamCount() > 0) {
params = action.getBodyParams();
@ -286,12 +288,12 @@ public abstract class AbstractCodeGenerator implements IScriptGenerator,
String data_str = "";
String cont_len_str = "";
//nothing
if (isMultiPartRequest) {
method = method + "MultiPart";
data_str = ", data";
cont_len_str = ", " + header.contentLength;
doSetData(action.getMultiPartData());
doSetData(action.getMultiPartData());//nothing
}
doCallUrl(action, method, data_str, cont_len_str,respCode,respContentType);
this.requestCount++;
@ -341,14 +343,14 @@ public abstract class AbstractCodeGenerator implements IScriptGenerator,
if (responseHeader.isGoodRequest()
&& responseHeader.isHtmlContentType()
&& hasHtmlTag(responseParser)) {
dealWithHtmlResponse(header, responseParser);
doParseRequest(header, requestBody, responseHeader.getRespCode(), responseHeader.getContentType());
dealWithHtmlResponse(header, responseParser);
response.setResponse(responseParser.encodeCoent(doParseHtmlContent(responseParser.getResponseBody(), header.url)));
setStruts(new String(response.getResponse()).toLowerCase().indexOf(
"org.apache.struts.taglib.html.token") > 0);
doEndTransaction();
return;
}
setStruts(new String(response.getResponse()).toLowerCase().indexOf(
"org.apache.struts.taglib.html.token") > 0);

View File

@ -90,7 +90,7 @@ public class TestParentRequest extends TestRecordBase {
this.getAdapater().insertUserBehaviorsToScenario(
createUserBehaviorModel(parentUrl));
this.getAdapater().getChildrenUrls()
.add(createChildrenUrl(childUrl, 0));
.add(createChildrenUrl(childUrl, 3));
this.getAdapater().insertUserBehaviorsToScenario(
createUserBehaviorModel(childUrl));
RunScenarioModel runScenarioModel = this.getAdapater()
@ -119,7 +119,7 @@ public class TestParentRequest extends TestRecordBase {
createUserBehaviorModel(parentUrl));
this.getAdapater().getChildrenUrls()
.add(createChildrenUrl(childUrl, 0));
.add(createChildrenUrl(childUrl, 3));
this.getAdapater().insertUserBehaviorsToScenario(
createUserBehaviorModel(childUrl));
@ -143,9 +143,9 @@ public class TestParentRequest extends TestRecordBase {
this.getAdapater().insertUserBehaviorsToScenario(
createUserBehaviorModel(parentUrl));
this.getAdapater().getChildrenUrls()
.add(createChildrenUrl(childUrl, 0));
.add(createChildrenUrl(childUrl, 3));
this.getAdapater().getChildrenUrls()
.add(createChildrenUrl(childUrl2, 0));
.add(createChildrenUrl(childUrl2, 3));
this.getAdapater().insertUserBehaviorsToScenario(
createUserBehaviorModel(childUrl));
this.getAdapater().insertUserBehaviorsToScenario(
@ -167,9 +167,9 @@ public class TestParentRequest extends TestRecordBase {
this.getAdapater().insertUserBehaviorsToScenario(
createUserBehaviorModel(parentUrl));
this.getAdapater().getChildrenUrls()
.add(createChildrenUrl(childUrl, 0));
.add(createChildrenUrl(childUrl, 3));
this.getAdapater().getChildrenUrls()
.add(createChildrenUrl(childUrl2, 0));
.add(createChildrenUrl(childUrl2, 3));
this.getAdapater().insertUserBehaviorsToScenario(
createUserBehaviorModel(childUrl));
this.getAdapater().insertUserBehaviorsToScenario(