add types to Agent

add types named Type, Filed, Table to Types
This commit is contained in:
coderfengyun 2014-03-21 15:30:46 +08:00
parent 457560d2ca
commit e3303781f8
9 changed files with 45 additions and 34 deletions

View File

@ -90,13 +90,13 @@ public class InstanceControler implements SessionObject {
String getParameter(String name, String className, String functionName,
Object[] args) {
ParametersFactory pf = ParametersFactory.getInstance();
boolean hasThisClass = pf.containObj(className);
ParametersFactory paramFactor = ParametersFactory.getInstance();
boolean hasThisClass = paramFactor.containObj(className);
if (false == hasThisClass) {
pf.createObj(className);
paramFactor.createObj(className);
}
Object instance = pf.getObj(className);
Object instance = paramFactor.getObj(className);
Object result = null;
try {
Class<?>[] argTypeArr = new Class<?>[args.length + 2];

View File

@ -5,19 +5,18 @@ import java.util.Map;
import java.util.concurrent.locks.ReentrantReadWriteLock;
public class ParametersFactory {
private static final ParametersFactory instance = new ParametersFactory();
private Map<String, Object> objMap = new HashMap<String, Object>();
private ReentrantReadWriteLock mapRWLock = new ReentrantReadWriteLock();
private String rootFilePath = "/home/yxsh/git/Bench4Q-Agent/parameterClass/";
private ParametersFactory() {
};
static private final ParametersFactory instance = new ParametersFactory();
static String lockObj = "";
}
static public ParametersFactory getInstance() {
return instance;
}
private Map<String, Object> objMap = new HashMap<String, Object>();
public boolean containObj(String className) {
boolean ret = false;
mapRWLock.readLock().lock();
@ -34,10 +33,6 @@ public class ParametersFactory {
return result;
}
private String rootFilePath = "/home/yxsh/git/Bench4Q-Agent/parameterClass/";
ReentrantReadWriteLock mapRWLock = new ReentrantReadWriteLock();
public boolean createObj(String className) {
try {
MyFileClassLoader cl = new MyFileClassLoader();

View File

@ -51,7 +51,7 @@ public class PluginManager {
this.plugins = plugins;
}
public Map<String, Class<?>> loadPlugins(String packageName) {
private Map<String, Class<?>> loadPlugins(String packageName) {
try {
List<String> classNames = this.getClassHelper().getClassNames(
packageName, true);

View File

@ -19,7 +19,6 @@ import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.commons.httpclient.Cookie;
import org.apache.commons.httpclient.Header;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
@ -35,7 +34,7 @@ import org.bench4q.agent.plugin.Parameter;
import org.bench4q.agent.plugin.Plugin;
import org.bench4q.agent.plugin.result.HttpReturn;
import org.bench4q.agent.scenario.util.ParameterParser;
import org.bench4q.agent.scenario.util.Table;
import org.bench4q.agent.scenario.util.types.Table;
@Plugin("Http")
public class HttpPlugin {
@ -59,17 +58,18 @@ public class HttpPlugin {
for (NameValuePair nv : nvPairs) {
method.addRequestHeader(nv.getName(), nv.getValue());
}
// New add
String cookieValue = "";
for (Cookie cookie : this.getHttpClient().getState().getCookies()) {
if (!cookieValue.isEmpty()) {
cookieValue += ";";
}
cookieValue += cookie.getName() + "=" + cookie.getValue();
}
if (!cookieValue.isEmpty()) {
method.addRequestHeader("Cookie", cookieValue);
}
// // New add
// String cookieValue = "";
// for (Cookie cookie :
// this.getHttpClient().getState().getCookies()) {
// if (!cookieValue.isEmpty()) {
// cookieValue += ";";
// }
// cookieValue += cookie.getName() + "=" + cookie.getValue();
// }
// if (!cookieValue.isEmpty()) {
// method.addRequestHeader("Cookie", cookieValue);
// }
}
}

View File

@ -5,6 +5,7 @@ import java.util.List;
import java.util.StringTokenizer;
import org.bench4q.agent.plugin.basic.http.ParameterConstant;
import org.bench4q.agent.scenario.util.types.Table;
/**
*
@ -76,7 +77,7 @@ public abstract class ParameterParser {
* The string value to be split
* @return The vector containing each token
*/
static List<String> getRealTokens(String separator, String value,
public static List<String> getRealTokens(String separator, String value,
boolean toUnescapeSeparator) {
List<String> result = new ArrayList<String>();
for (String entry : value.split(separator)) {

View File

@ -0,0 +1,5 @@
package org.bench4q.agent.scenario.util;
public class Type {
}

View File

@ -0,0 +1,7 @@
package org.bench4q.agent.scenario.util.types;
import org.bench4q.agent.scenario.util.Type;
public class Filed extends Type {
}

View File

@ -1,12 +1,14 @@
package org.bench4q.agent.scenario.util;
package org.bench4q.agent.scenario.util.types;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import org.bench4q.agent.plugin.basic.http.ParameterConstant;
import org.bench4q.agent.scenario.util.ParameterParser;
import org.bench4q.agent.scenario.util.Type;
public class Table {
public class Table extends Type {
public static final String ROW_SEPARATOR = "|;";
public static final String COLUMN_SEPARATOR = "|";
public static final String ROW_SEPARATOR_TAIL = ";";
@ -38,7 +40,8 @@ public class Table {
this.setColumnLables(new LinkedList<String>());
}
static Table buildTable(String value, List<String> columnLablesInSequence) {
public static Table buildTable(String value,
List<String> columnLablesInSequence) {
Table result = new Table();
result.setRealContent(buildTableContent(value));
result.setColumnLables(columnLablesInSequence);

View File

@ -9,7 +9,7 @@ import java.util.List;
import org.apache.commons.httpclient.NameValuePair;
import org.bench4q.agent.plugin.basic.http.HttpPlugin;
import org.bench4q.agent.scenario.util.ParameterParser;
import org.bench4q.agent.scenario.util.Table;
import org.bench4q.agent.scenario.util.types.Table;
import org.bench4q.share.helper.TestHelper;
import org.junit.Test;