add code and edit the usepluginmodel

add code and edit the usepluginmodel
This commit is contained in:
coderfengyun 2014-08-15 13:57:09 +08:00
parent 58b3b56d1d
commit c2e661733f
10 changed files with 450 additions and 45 deletions

View File

@ -102,6 +102,11 @@
<artifactId>jdom</artifactId>
<version>b7</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.2.4</version>
</dependency>
</dependencies>
<build>
<plugins>

View File

@ -0,0 +1,82 @@
package org.bench4q.agent.plugin.basic.http;
import java.util.List;
public class BatchRequest {
private List<BatchItem> batchItems;
public List<BatchItem> getBatchItems() {
return batchItems;
}
public void setBatchItems(List<BatchItem> batchItems) {
this.batchItems = batchItems;
}
public static class BatchItem {
private String method;
private String url;
private String queryParams;
private String headers;
private String bodyContent;
private String bodyparameters;
private String respVarsToSaveInSession;
public String getMethod() {
return method;
}
public void setMethod(String method) {
this.method = method;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public String getQueryParams() {
return queryParams;
}
public void setQueryParams(String queryParams) {
this.queryParams = queryParams;
}
public String getHeaders() {
return headers;
}
public void setHeaders(String headers) {
this.headers = headers;
}
public String getBodyContent() {
return bodyContent;
}
public void setBodyContent(String bodyContent) {
this.bodyContent = bodyContent;
}
public String getBodyparameters() {
return bodyparameters;
}
public void setBodyparameters(String bodyparameters) {
this.bodyparameters = bodyparameters;
}
public String getRespVarsToSaveInSession() {
return respVarsToSaveInSession;
}
public void setRespVarsToSaveInSession(String respVarsToSaveInSession) {
this.respVarsToSaveInSession = respVarsToSaveInSession;
}
}
}

View File

@ -40,12 +40,13 @@ import org.bench4q.agent.plugin.ParameterBarn;
import org.bench4q.agent.plugin.Constructor;
import org.bench4q.agent.plugin.Parameter;
import org.bench4q.agent.plugin.Plugin;
import org.bench4q.agent.plugin.basic.http.BatchRequest.BatchItem;
import org.bench4q.agent.plugin.behavior.Behavior;
import org.bench4q.agent.plugin.behavior.BehaviorType;
import org.bench4q.agent.utils.ParameterParser;
import org.bench4q.agent.utils.Type.SupportTypes;
import org.bench4q.agent.utils.types.Table;
import org.bench4q.agent.utils.types.Table.Row;
import com.google.gson.Gson;
@Plugin("Http")
public class HttpPlugin extends ParameterBarn {
@ -116,22 +117,24 @@ public class HttpPlugin extends ParameterBarn {
return uri;
}
public List<HttpReturn> batch_request(
@Behavior(value = "Get", type = BehaviorType.USER_BEHAVIOR)
public List<HttpReturn> batchRequest(
@Parameter(value = "requests", type = SupportTypes.Table) String requests) {
ExecutorService executorService = Executors.newFixedThreadPool(2);
List<HttpReturn> result = new LinkedList<HttpReturn>();
try {
Table requestTable = Table.buildTable(requests,
Arrays.asList("Method", "Url"));
List<Future<HttpReturn>> results = new LinkedList<Future<HttpReturn>>();
for (final Row row : requestTable.getRows()) {
Callable<HttpReturn> task = buildTas(row);
Gson gson = new Gson();
BatchRequest batchRequest = gson.fromJson(requests,
BatchRequest.class);
List<Future<HttpReturn>> futures = new LinkedList<Future<HttpReturn>>();
for (BatchItem item : batchRequest.getBatchItems()) {
Callable<HttpReturn> task = buildTasks(item);
if (task == null) {
continue;
}
results.add(executorService.submit(task));
futures.add(executorService.submit(task));
}
for (Future<HttpReturn> future : results) {
for (Future<HttpReturn> future : futures) {
try {
result.add(future.get());
} catch (Exception e) {
@ -146,41 +149,50 @@ public class HttpPlugin extends ParameterBarn {
}
private Callable<HttpReturn> buildTas(final Row row) {
// switch (row.getCell(0).toLowerCase()) {
// case "get":
// return new Callable<HttpReturn>() {
// @Override
// public HttpReturn call() throws Exception {
// return get(row.getCell(1), null, null, null);
// }
// };
// case "post":
// return new Callable<HttpReturn>() {
// @Override
// public HttpReturn call() throws Exception {
// return post(row.getCell(1), null, null, null, null, null);
// }
// };
// case "put":
// return new Callable<HttpReturn>() {
// @Override
// public HttpReturn call() throws Exception {
// return put(row.getCell(1), null, null, null, null, null);
// }
// };
// case "delete":
// return new Callable<HttpReturn>() {
// @Override
// public HttpReturn call() throws Exception {
// return delete(row.getCell(1), null, null, null);
// }
// };
// default:
// return null;
// }
private Callable<HttpReturn> buildTasks(final BatchItem item) {
switch (item.getMethod().toLowerCase()) {
case "get":
return new Callable<HttpReturn>() {
@Override
public HttpReturn call() throws Exception {
return get(item.getUrl(), item.getQueryParams(),
item.getHeaders(),
item.getRespVarsToSaveInSession());
}
};
case "post":
return new Callable<HttpReturn>() {
@Override
public HttpReturn call() throws Exception {
return post(item.getUrl(), item.getQueryParams(),
item.getHeaders(), item.getBodyContent(),
item.getBodyparameters(),
item.getRespVarsToSaveInSession());
}
};
case "put":
return new Callable<HttpReturn>() {
@Override
public HttpReturn call() throws Exception {
return put(item.getUrl(), item.getQueryParams(),
item.getHeaders(), item.getBodyContent(),
item.getBodyparameters(),
item.getRespVarsToSaveInSession());
}
};
case "delete":
return new Callable<HttpReturn>() {
@Override
public HttpReturn call() throws Exception {
return delete(item.getUrl(), item.getQueryParams(),
item.getHeaders(),
item.getRespVarsToSaveInSession());
}
};
default:
return null;
}
}
/**
*

View File

@ -1,5 +1,8 @@
package org.bench4q.agent.plugin.basic.http;
import java.util.HashMap;
import java.util.Map;
import org.apache.commons.httpclient.Header;
import org.bench4q.agent.plugin.basic.PluginReturn;
@ -79,4 +82,11 @@ public class HttpReturn extends PluginReturn {
this.setUrl(url);
}
public Map<String, String> getExtraResult() {
Map<String, String> result = new HashMap<String, String>();
result.put("contentLength", this.getContentLength() + "");
result.put("contentType", this.getContentType());
result.put("statusCode", this.getStatusCode() + "");
return result;
}
}

View File

@ -7,6 +7,7 @@ import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Set;
@ -178,4 +179,9 @@ public class Solution {
builder.setCharAt(1, 'a');
System.out.println(builder.toString());
}
@Test
public void test3() {
PriorityQueue<Integer> queue = new PriorityQueue<Integer>();
}
}

View File

@ -2,7 +2,9 @@ package org.bench4q.agent.test.plugin;
import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
@ -10,6 +12,7 @@ import org.apache.commons.httpclient.Cookie;
import org.apache.commons.httpclient.cookie.MalformedCookieException;
import org.apache.commons.io.FileUtils;
import org.bench4q.agent.plugin.basic.PluginReturn;
import org.bench4q.agent.plugin.basic.http.BatchRequest;
import org.bench4q.agent.plugin.basic.http.HttpPlugin;
import org.bench4q.agent.plugin.basic.http.HttpReturn;
import org.bench4q.agent.scenario.Scenario;
@ -23,6 +26,8 @@ import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import com.google.gson.Gson;
import static org.junit.Assert.*;
@RunWith(SpringJUnit4ClassRunner.class)
@ -153,4 +158,33 @@ public class Test_HttpPlugin extends TestBase {
UUID.randomUUID());
vUser.run();
}
@Test
public void test_BatchRequest() {
BatchRequest.BatchItem batchItem = buildItem("Get",
"http://www.baidu.com");
BatchRequest batchRequest = new BatchRequest();
batchRequest.setBatchItems(Arrays.asList(batchItem,
buildItem("Get", "http://www.csdn.net/")));
String batchItemInJson = new Gson().toJson(batchRequest);
System.out.println(batchItemInJson);
List<HttpReturn> returns = this.httpPlugin
.batchRequest(batchItemInJson);
for (HttpReturn return1 : returns) {
System.out.println(return1.getUrl());
assertEquals(200, return1.getStatusCode());
}
}
private BatchRequest.BatchItem buildItem(String method, String url) {
BatchRequest.BatchItem batchItem = new BatchRequest.BatchItem();
batchItem.setMethod(method);
batchItem.setUrl(url);
batchItem.setHeaders("");
batchItem.setQueryParams("");
batchItem.setBodyContent("");
batchItem.setBodyparameters("");
batchItem.setRespVarsToSaveInSession("");
return batchItem;
}
}

View File

@ -147,7 +147,7 @@ public class PluginController extends BaseController {
"addPlugin/{pluginName}/{methodName}");
}
String pluginUIContent = plugin;
System.out.println(pluginUIContent);
logger.info(pluginUIContent);
PluginResponseModel pluginResponseModel = new PluginResponseModel();
pluginResponseModel.setSuccess(this.getPluginService().addPlugin(
pluginUIContent));

View File

@ -0,0 +1,247 @@
<?xml version="1.0" encoding="UTF-8"?>
<class-diagram version="1.1.6" icons="true" always-add-relationships="false" generalizations="true" realizations="true"
associations="true" dependencies="false" nesting-relationships="true">
<class id="1" language="java" name="org.bench4q.master.domain.entity.Agent" project="bench4q-master"
file="/bench4q-master/src/main/java/org/bench4q/master/domain/entity/Agent.java" binary="false"
corner="BOTTOM_RIGHT">
<position height="54" width="179" x="122" y="256"/>
<display autosize="false" stereotype="true" package="true" initial-value="false" signature="true" accessors="true"
visibility="true">
<attributes public="true" package="true" protected="true" private="true" static="true"/>
<operations public="true" package="true" protected="true" private="true" static="true"/>
</display>
</class>
<class id="2" language="java" name="org.bench4q.master.domain.entity.RunningAgentDB" project="bench4q-master"
file="/bench4q-master/src/main/java/org/bench4q/master/domain/entity/RunningAgentDB.java" binary="false"
corner="BOTTOM_RIGHT">
<position height="53" width="177" x="111" y="140"/>
<display autosize="false" stereotype="true" package="true" initial-value="false" signature="true" accessors="true"
visibility="true">
<attributes public="true" package="true" protected="true" private="true" static="true"/>
<operations public="true" package="true" protected="true" private="true" static="true"/>
</display>
</class>
<class id="3" language="java" name="org.bench4q.master.domain.entity.TestPlanScript" project="bench4q-master"
file="/bench4q-master/src/main/java/org/bench4q/master/domain/entity/TestPlanScript.java" binary="false"
corner="BOTTOM_RIGHT">
<position height="53" width="176" x="150" y="7"/>
<display autosize="false" stereotype="true" package="true" initial-value="false" signature="true" accessors="true"
visibility="true">
<attributes public="true" package="true" protected="true" private="true" static="true"/>
<operations public="true" package="true" protected="true" private="true" static="true"/>
</display>
</class>
<class id="4" language="java" name="org.bench4q.master.domain.entity.TestPlan" project="bench4q-master"
file="/bench4q-master/src/main/java/org/bench4q/master/domain/entity/TestPlan.java" binary="false"
corner="BOTTOM_RIGHT">
<position height="53" width="242" x="318" y="-145"/>
<display autosize="false" stereotype="true" package="true" initial-value="false" signature="true" accessors="true"
visibility="true">
<attributes public="true" package="true" protected="true" private="true" static="true"/>
<operations public="true" package="true" protected="true" private="true" static="true"/>
</display>
</class>
<class id="5" language="java" name="org.bench4q.master.domain.entity.Monitor" project="bench4q-master"
file="/bench4q-master/src/main/java/org/bench4q/master/domain/entity/Monitor.java" binary="false"
corner="BOTTOM_RIGHT">
<position height="54" width="208" x="561" y="1"/>
<display autosize="false" stereotype="true" package="true" initial-value="false" signature="true" accessors="true"
visibility="true">
<attributes public="true" package="true" protected="true" private="true" static="true"/>
<operations public="true" package="true" protected="true" private="true" static="true"/>
</display>
</class>
<class id="6" language="java" name="org.bench4q.master.domain.entity.MonitorResult" project="bench4q-master"
file="/bench4q-master/src/main/java/org/bench4q/master/domain/entity/MonitorResult.java" binary="false"
corner="BOTTOM_RIGHT">
<position height="54" width="153" x="510" y="137"/>
<display autosize="false" stereotype="true" package="true" initial-value="false" signature="true" accessors="true"
visibility="true">
<attributes public="true" package="true" protected="true" private="true" static="true"/>
<operations public="true" package="true" protected="true" private="true" static="true"/>
</display>
</class>
<class id="7" language="java" name="org.bench4q.master.domain.entity.PlanedConfig" project="bench4q-master"
file="/bench4q-master/src/main/java/org/bench4q/master/domain/entity/PlanedConfig.java" binary="false"
corner="BOTTOM_RIGHT">
<position height="53" width="162" x="305" y="140"/>
<display autosize="false" stereotype="true" package="true" initial-value="false" signature="true" accessors="true"
visibility="true">
<attributes public="true" package="true" protected="true" private="true" static="true"/>
<operations public="true" package="true" protected="true" private="true" static="true"/>
</display>
</class>
<class id="8" language="java" name="org.bench4q.master.domain.entity.Script" project="bench4q-master"
file="/bench4q-master/src/main/java/org/bench4q/master/domain/entity/Script.java" binary="false"
corner="BOTTOM_RIGHT">
<position height="53" width="153" x="-50" y="8"/>
<display autosize="false" stereotype="true" package="true" initial-value="false" signature="true" accessors="true"
visibility="true">
<attributes public="true" package="true" protected="true" private="true" static="true"/>
<operations public="true" package="true" protected="true" private="true" static="true"/>
</display>
</class>
<class id="9" language="java" name="org.bench4q.master.domain.entity.User" project="bench4q-master"
file="/bench4q-master/src/main/java/org/bench4q/master/domain/entity/User.java" binary="false" corner="BOTTOM_RIGHT">
<position height="54" width="153" x="187" y="-230"/>
<display autosize="false" stereotype="true" package="true" initial-value="false" signature="true" accessors="true"
visibility="true">
<attributes public="true" package="true" protected="true" private="true" static="true"/>
<operations public="true" package="true" protected="true" private="true" static="true"/>
</display>
</class>
<interface id="10" language="java" name="org.bench4q.master.domain.RunningAgentInterface" project="bench4q-master"
file="/bench4q-master/src/main/java/org/bench4q/master/domain/RunningAgentInterface.java" binary="false"
corner="BOTTOM_RIGHT">
<position height="53" width="154" x="-76" y="140"/>
<display autosize="false" stereotype="true" package="true" initial-value="false" signature="true" accessors="true"
visibility="true">
<attributes public="true" package="true" protected="true" private="true" static="true"/>
<operations public="true" package="true" protected="true" private="true" static="true"/>
</display>
</interface>
<interface id="11" language="java" name="org.bench4q.master.domain.RunningScriptInterface" project="bench4q-master"
file="/bench4q-master/src/main/java/org/bench4q/master/domain/RunningScriptInterface.java" binary="false"
corner="BOTTOM_RIGHT">
<position height="55" width="160" x="356" y="6"/>
<display autosize="false" stereotype="true" package="true" initial-value="false" signature="true" accessors="true"
visibility="true">
<attributes public="true" package="true" protected="true" private="true" static="true"/>
<operations public="true" package="true" protected="true" private="true" static="true"/>
</display>
</interface>
<association id="12">
<end type="SOURCE" refId="2" navigable="false">
<attribute id="13" name="agent"/>
<multiplicity id="14" minimum="0" maximum="1"/>
</end>
<end type="TARGET" refId="1" navigable="true"/>
<display labels="true" multiplicity="true"/>
</association>
<association id="15">
<end type="SOURCE" refId="4" navigable="false">
<attribute id="16" name="monitors"/>
<multiplicity id="17" minimum="0" maximum="2147483647"/>
</end>
<end type="TARGET" refId="5" navigable="true"/>
<display labels="true" multiplicity="true"/>
</association>
<realization id="18">
<end type="SOURCE" refId="3"/>
<end type="TARGET" refId="11"/>
</realization>
<association id="19">
<end type="SOURCE" refId="5" navigable="false">
<attribute id="20" name="results"/>
<multiplicity id="21" minimum="0" maximum="2147483647"/>
</end>
<end type="TARGET" refId="6" navigable="true"/>
<display labels="true" multiplicity="true"/>
</association>
<association id="22">
<end type="SOURCE" refId="3" navigable="false">
<attribute id="23" name="testPlan"/>
<multiplicity id="24" minimum="0" maximum="1"/>
</end>
<end type="TARGET" refId="4" navigable="true"/>
<display labels="true" multiplicity="true"/>
</association>
<association id="25">
<end type="SOURCE" refId="3" navigable="false">
<attribute id="26" name="planedConfig"/>
<multiplicity id="27" minimum="0" maximum="1"/>
</end>
<end type="TARGET" refId="7" navigable="true"/>
<display labels="true" multiplicity="true"/>
</association>
<association id="28">
<end type="SOURCE" refId="2" navigable="false">
<attribute id="29" name="script"/>
<multiplicity id="30" minimum="0" maximum="1"/>
</end>
<end type="TARGET" refId="8" navigable="true"/>
<display labels="true" multiplicity="true"/>
</association>
<association id="31">
<end type="SOURCE" refId="8" navigable="false">
<attribute id="32" name="user"/>
<multiplicity id="33" minimum="0" maximum="1"/>
</end>
<end type="TARGET" refId="9" navigable="true"/>
<display labels="true" multiplicity="true"/>
</association>
<association id="34">
<end type="SOURCE" refId="6" navigable="false">
<attribute id="35" name="testPlanDB"/>
<multiplicity id="36" minimum="0" maximum="1"/>
</end>
<end type="TARGET" refId="4" navigable="true"/>
<display labels="true" multiplicity="true"/>
</association>
<association id="37">
<end type="SOURCE" refId="3" navigable="false">
<attribute id="38" name="runningAgents"/>
<multiplicity id="39" minimum="0" maximum="2147483647"/>
</end>
<end type="TARGET" refId="2" navigable="true"/>
<display labels="true" multiplicity="true"/>
</association>
<association id="40">
<end type="SOURCE" refId="6" navigable="false">
<attribute id="41" name="monitor"/>
<multiplicity id="42" minimum="0" maximum="1"/>
</end>
<end type="TARGET" refId="5" navigable="true"/>
<display labels="true" multiplicity="true"/>
</association>
<association id="43">
<end type="SOURCE" refId="2" navigable="false">
<attribute id="44" name="testPlanScript"/>
<multiplicity id="45" minimum="0" maximum="1"/>
</end>
<end type="TARGET" refId="3" navigable="true"/>
<display labels="true" multiplicity="true"/>
</association>
<realization id="46">
<end type="SOURCE" refId="2"/>
<end type="TARGET" refId="10"/>
</realization>
<association id="47">
<end type="SOURCE" refId="4" navigable="false">
<attribute id="48" name="testPlanScripts"/>
<multiplicity id="49" minimum="0" maximum="2147483647"/>
</end>
<end type="TARGET" refId="3" navigable="true"/>
<display labels="true" multiplicity="true"/>
</association>
<association id="50">
<end type="SOURCE" refId="3" navigable="false">
<attribute id="51" name="script"/>
<multiplicity id="52" minimum="0" maximum="1"/>
</end>
<end type="TARGET" refId="8" navigable="true"/>
<display labels="true" multiplicity="true"/>
</association>
<association id="53">
<end type="SOURCE" refId="5" navigable="false">
<attribute id="54" name="testPlan"/>
<multiplicity id="55" minimum="0" maximum="1"/>
</end>
<end type="TARGET" refId="4" navigable="true"/>
<display labels="true" multiplicity="true"/>
</association>
<association id="56">
<end type="SOURCE" refId="4" navigable="false">
<attribute id="57" name="user"/>
<multiplicity id="58" minimum="0" maximum="1"/>
</end>
<end type="TARGET" refId="9" navigable="true"/>
<display labels="true" multiplicity="true"/>
</association>
<classifier-display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
accessors="true" visibility="true">
<attributes public="true" package="true" protected="true" private="true" static="true"/>
<operations public="true" package="true" protected="true" private="true" static="true"/>
</classifier-display>
<association-display labels="true" multiplicity="true"/>
</class-diagram>

View File

@ -12,6 +12,7 @@ import org.bench4q.share.models.agent.ParameterModel;
@XmlRootElement(name = "usePlugin")
public class UsePluginModel {
private String id;
private String nickName;
private String name;
private List<ParameterModel> parameters;
@ -24,6 +25,15 @@ public class UsePluginModel {
this.id = id;
}
@XmlElement
public String getNickName() {
return nickName;
}
public void setNickName(String nickName) {
this.nickName = nickName;
}
@XmlElement
public String getName() {
return name;

View File

@ -60,7 +60,6 @@ public class PluginMessager extends MasterMessager {
public PluginResponseModel addPlugin(String accessToken, String plugin) {
String url = this.getBaseUrl() + "/addPlugin";
System.out.println(plugin);
HttpResponse httpResponse = null;
try {