refactor the parameterization and parameterparer part

refactor the parameterization and parameterparer part
This commit is contained in:
coderfengyun 2014-03-21 18:33:59 +08:00
parent 98525d2c7d
commit b1cc057f4d
32 changed files with 302 additions and 129 deletions

View File

@ -1,3 +1,4 @@
isToSaveDetailResult=false
servePort=6565
userDefinedParamFolder=userDefinedParams
scenarioParamFolder=ScenarioParameters

View File

@ -9,6 +9,7 @@ import java.util.Properties;
import org.apache.log4j.Logger;
public class Main {
private static String LINE_SEPARATOR = System.getProperty("line.separator");
private static final String CONFIG_FILE_NAME = "agent-config.properties";
private static String DIR_PATH = "configure"
+ System.getProperty("file.separator");
@ -16,6 +17,7 @@ public class Main {
private static int PORT_TO_SERVE;
public static boolean IS_TO_SAVE_DETAIL;
public static String USER_DEFINED_PARAMS_FOLDER;
public static String SCENARIO_PARAMETERS_FOLDER;
static {
init();
@ -46,9 +48,11 @@ public class Main {
try {
if (configFile.createNewFile()) {
FileOutputStream outputStream = new FileOutputStream(configFile);
String content = "isToSaveDetailResult=false" + "\n"
+ "servePort=6565" + "\n"
+ "userDefinedParamFolder=userDefinedParams";
String content = "isToSaveDetailResult=false" + LINE_SEPARATOR
+ "servePort=6565" + LINE_SEPARATOR
+ "userDefinedParamFolder=userDefinedParams"
+ LINE_SEPARATOR
+ "scenarioParamFolder=ScenarioParameters";
outputStream.write(content.getBytes());
outputStream.flush();
outputStream.close();
@ -69,6 +73,8 @@ public class Main {
.get("isToSaveDetailResult"));
USER_DEFINED_PARAMS_FOLDER = properties
.getProperty("userDefinedParamFolder");
SCENARIO_PARAMETERS_FOLDER = properties
.getProperty("scenarioParamFolder");
guardUserDefinedFolderExists();
} catch (IOException e) {
logger.error("There is an error when getPortToServe!");

View File

@ -11,15 +11,29 @@ import java.util.concurrent.locks.ReentrantReadWriteLock;
import org.bench4q.agent.parameterization.SessionObject;
public class InstanceControler implements SessionObject {
public class InstanceController implements SessionObject {
private String userDefineParameterFolderPath = "/home/yxsh/git/Bench4Q-Agent/parameterClass/";
private UUID instandid = java.util.UUID.randomUUID();
private UUID testRunId;
private UUID id = java.util.UUID.randomUUID();
private Set<String> usedClassName = new HashSet<String>();
private Map<String, Object> objMap = new HashMap<String, Object>();
private Map<String, String> runtimeParaMap = new HashMap<String, String>();
private Map<String, String> runtimeParamMap = new HashMap<String, String>();
private Map<String, Object> cacheObjMap = new HashMap<String, Object>();
private ReentrantReadWriteLock mapRWLock = new ReentrantReadWriteLock();
private InstanceController() {
}
protected UUID getRunId() {
return testRunId;
}
public InstanceController(UUID testRunId, UUID controllerId) {
this();
this.id = controllerId;
this.testRunId = testRunId;
}
String instanceLevelGetParameter(String name, String className,
String functionName, Object[] args) {
@ -34,10 +48,10 @@ public class InstanceControler implements SessionObject {
Object result = null;
try {
Class<?>[] argTypeArr = new Class<?>[args.length + 2];
argTypeArr[0] = instandid.getClass();
argTypeArr[0] = id.getClass();
argTypeArr[1] = this.cacheObjMap.getClass();
Object[] totalArgs = new Object[args.length + 2];
totalArgs[0] = instandid;
totalArgs[0] = id;
totalArgs[1] = this.cacheObjMap;
for (int i = 2; i < args.length + 2; i++) {
argTypeArr[i] = args[i - 2].getClass();
@ -51,23 +65,23 @@ public class InstanceControler implements SessionObject {
.getTargetException().getMessage());
return null;
}
runtimeParaMap.put(name, (String) result);
runtimeParamMap.put(name, (String) result);
return (String) result;
}
String getParameterByContext(String name) {
if (false == this.runtimeParaMap.containsKey(name)) {
if (false == this.runtimeParamMap.containsKey(name)) {
return null;
}
return runtimeParaMap.get(name);
return runtimeParamMap.get(name);
}
private boolean createObj(String className) {
try {
MyFileClassLoader cl = new MyFileClassLoader();
cl.setClassPath(userDefineParameterFolderPath);
Class<?> cls = cl.loadClass(className);
MyFileClassLoader classLoader = new MyFileClassLoader(
userDefineParameterFolderPath);
Class<?> cls = classLoader.loadClass(className);
Object instance = cls.newInstance();
mapRWLock.writeLock().lock();
objMap.put(className, instance);
@ -89,7 +103,6 @@ public class InstanceControler implements SessionObject {
String getParameter(String name, String className, String functionName,
Object[] args) {
ParametersFactory paramFactor = ParametersFactory.getInstance();
boolean hasThisClass = paramFactor.containObj(className);
if (false == hasThisClass) {
@ -100,10 +113,10 @@ public class InstanceControler implements SessionObject {
Object result = null;
try {
Class<?>[] argTypeArr = new Class<?>[args.length + 2];
argTypeArr[0] = instandid.getClass();
argTypeArr[0] = id.getClass();
argTypeArr[1] = this.cacheObjMap.getClass();
Object[] totalArgs = new Object[args.length + 2];
totalArgs[0] = instandid;
totalArgs[0] = id;
totalArgs[1] = this.cacheObjMap;
for (int i = 2; i < args.length + 2; i++) {
argTypeArr[i] = args[i - 2].getClass();
@ -122,7 +135,7 @@ public class InstanceControler implements SessionObject {
}
usedClassName.add(className);
runtimeParaMap.put(name, (String) result);
runtimeParamMap.put(name, (String) result);
return (String) result;
}
@ -137,11 +150,11 @@ public class InstanceControler implements SessionObject {
}
public void saveRuntimeParam(String name, String value) {
runtimeParaMap.put(name, value);
runtimeParamMap.put(name, value);
}
public void saveRuntimeParams(Map<String, String> runTimeParams) {
runtimeParaMap.putAll(runTimeParams);
runtimeParamMap.putAll(runTimeParams);
}
public void doCleanUp() {
@ -169,10 +182,9 @@ public class InstanceControler implements SessionObject {
try {
Method m = instance.getClass().getMethod("unreg",
instandid.getClass());
Method m = instance.getClass().getMethod("unreg", id.getClass());
m.invoke(instance, instandid);
m.invoke(instance, id);
} catch (Exception ex) {
System.out.println("realse failed");

View File

@ -4,35 +4,25 @@ import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
public class MyFileClassLoader extends ClassLoader {
private String classPath;
public static void main(String[] args) throws ClassNotFoundException,
InstantiationException, IllegalAccessException,
IllegalArgumentException, InvocationTargetException {
MyFileClassLoader fileClsLoader = new MyFileClassLoader();
fileClsLoader
.setClassPath("E:\\j2ee_proj\\skythink\\WebContent\\WEB-INF\\classes\\");
Class<?> cls = fileClsLoader
.loadClass("com.cmw.entity.sys.AccordionEntity");
Object obj = cls.newInstance();
Method[] mthds = cls.getMethods();
for (Method mthd : mthds) {
String methodName = mthd.getName();
System.out.println("mthd.name=" + methodName);
}
System.out.println("obj.class=" + obj.getClass().getName());
System.out.println("obj.class=" + cls.getClassLoader().toString());
System.out.println("obj.class="
+ cls.getClassLoader().getParent().toString());
private void setClassPath(String classPath) {
this.classPath = classPath;
}
private MyFileClassLoader() {
}
public MyFileClassLoader(String classPath) {
this();
this.setClassPath(classPath);
}
/**
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŀ¼<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* 锟斤拷锟斤拷锟斤拷锟斤拷址锟斤拷指锟斤拷锟斤拷目录锟斤拷锟斤拷锟洁锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟<EFBFBD>
*/
@Override
protected Class<?> findClass(String name) throws ClassNotFoundException {
@ -46,11 +36,11 @@ public class MyFileClassLoader extends ClassLoader {
}
/**
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> byte <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* 锟斤拷锟斤拷锟斤拷锟斤拷址锟斤拷锟斤拷锟斤拷 byte 锟斤拷锟斤拷锟<EFBFBD>
*
* @param name
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD> <EFBFBD><EFBFBD><EFBFBD> com.cmw.entity.SysEntity
* @return <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD> byte <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* 锟斤拷锟斤拷锟街凤拷 锟斤拷锟界 com.cmw.entity.SysEntity
* @return 锟斤拷锟斤拷锟斤拷锟侥硷拷 byte 锟斤拷锟斤拷锟<EFBFBD>
* @throws IOException
*/
private byte[] loadClassData(String name) throws IOException {
@ -63,17 +53,17 @@ public class MyFileClassLoader extends ClassLoader {
}
/**
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD> File <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* 锟斤拷锟斤拷锟斤拷锟斤拷址锟斤拷锟揭伙拷锟<EFBFBD>File 锟斤拷锟斤拷
*
* @param name
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD>
* @return File <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* 锟斤拷锟斤拷锟街凤拷
* @return File 锟斤拷锟斤拷
* @throws FileNotFoundException
*/
private File getFile(String name) throws FileNotFoundException {
File dir = new File(classPath);
if (!dir.exists())
throw new FileNotFoundException(classPath + " Ŀ¼<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڣ<EFBFBD>");
throw new FileNotFoundException(classPath + " 目录锟斤拷锟斤拷锟节o拷");
String _classPath = classPath.replaceAll("[\\\\]", "/");
int offset = _classPath.lastIndexOf("/");
name = name.replaceAll("[.]", "/");
@ -83,16 +73,8 @@ public class MyFileClassLoader extends ClassLoader {
_classPath += name + ".class";
dir = new File(_classPath);
if (!dir.exists())
throw new FileNotFoundException(dir + " <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڣ<EFBFBD>");
throw new FileNotFoundException(dir + " 锟斤拷锟斤拷锟节o拷");
return dir;
}
public String getClassPath() {
return classPath;
}
public void setClassPath(String classPath) {
this.classPath = classPath;
}
}

View File

@ -0,0 +1,82 @@
package org.bench4q.agent.parameterization.impl;
import java.util.List;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlRootElement;
import org.bench4q.agent.utils.ParameterParser;
import org.bench4q.share.helper.MarshalHelper;
@XmlRootElement(name = "parameters")
public class ParameterFormat {
private String name;
private String className;
private String methodName;
private String argsString;
private String paramType;
private List<String> args;
@XmlAttribute(name = "name")
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@XmlAttribute(name = "class")
public String getClassName() {
return className;
}
public void setClassName(String className) {
this.className = className;
}
@XmlAttribute(name = "method")
public String getMethodName() {
return methodName;
}
public void setMethodName(String methodName) {
this.methodName = methodName;
}
@XmlAttribute(name = "args")
public String getArgsString() {
return argsString;
}
public void setArgsString(String argsString) {
this.argsString = argsString;
}
@XmlAttribute(name = "type")
public String getParamType() {
return paramType;
}
public void setParamType(String paramType) {
this.paramType = paramType;
}
public List<String> getArgs() {
return args;
}
private void setArgs(List<String> args) {
this.args = args;
}
private ParameterFormat() {
}
public static ParameterFormat parseInputParameter(String inputContent) {
ParameterFormat result = (ParameterFormat) MarshalHelper.tryUnmarshal(
ParameterFormat.class, inputContent);
result.setArgs(ParameterParser.buildNField(result.getArgsString()));
return result;
}
}

View File

@ -11,7 +11,7 @@ import org.xml.sax.InputSource;
public class ParameterizationParser {
public static String parse(String text, InstanceControler insCon) {
public static String parse(String text, InstanceController insCon) {
// Pattern pattern = Pattern.compile("<parameter className=""/>");
String result = "";
try {
@ -23,6 +23,7 @@ public class ParameterizationParser {
String className = root.getAttribute("class");
String methodName = root.getAttribute("method");
String argString = root.getAttribute("args");
String type = root.getAttribute("type");
String[] args = argString.split(",");
if (argString.trim().equals(""))

View File

@ -35,8 +35,7 @@ public class ParametersFactory {
public boolean createObj(String className) {
try {
MyFileClassLoader cl = new MyFileClassLoader();
cl.setClassPath(rootFilePath);
MyFileClassLoader cl = new MyFileClassLoader(rootFilePath);
Class<?> cls = cl.loadClass(className);
Object instance = cls.newInstance();
mapRWLock.writeLock().lock();

View File

@ -5,7 +5,7 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.bench4q.agent.scenario.util.Type.SupportTypes;
import org.bench4q.agent.utils.Type.SupportTypes;
@Target(ElementType.PARAMETER)
@Retention(RetentionPolicy.RUNTIME)

View File

@ -7,7 +7,7 @@ import org.bench4q.agent.plugin.Behavior;
import org.bench4q.agent.plugin.Parameter;
import org.bench4q.agent.plugin.Plugin;
import org.bench4q.agent.plugin.result.CommandLineReturn;
import org.bench4q.agent.scenario.util.Type.SupportTypes;
import org.bench4q.agent.utils.Type.SupportTypes;
@Plugin("CommandLine")
public class CommandLinePlugin {

View File

@ -5,7 +5,7 @@ import org.bench4q.agent.plugin.Behavior;
import org.bench4q.agent.plugin.Parameter;
import org.bench4q.agent.plugin.Plugin;
import org.bench4q.agent.plugin.result.TimerReturn;
import org.bench4q.agent.scenario.util.Type.SupportTypes;
import org.bench4q.agent.utils.Type.SupportTypes;
@Plugin("ConstantTimer")
public class ConstantTimerPlugin {

View File

@ -4,7 +4,7 @@ import org.bench4q.agent.plugin.Behavior;
import org.bench4q.agent.plugin.Parameter;
import org.bench4q.agent.plugin.Plugin;
import org.bench4q.agent.plugin.result.LogReturn;
import org.bench4q.agent.scenario.util.Type.SupportTypes;
import org.bench4q.agent.utils.Type.SupportTypes;
@Plugin("Log")
public class LogPlugin {

View File

@ -33,9 +33,9 @@ import org.bench4q.agent.plugin.Behavior;
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.Type.SupportTypes;
import org.bench4q.agent.scenario.util.types.Table;
import org.bench4q.agent.utils.ParameterParser;
import org.bench4q.agent.utils.Type.SupportTypes;
import org.bench4q.agent.utils.types.Table;
@Plugin("Http")
public class HttpPlugin {

View File

@ -6,7 +6,7 @@ import java.util.UUID;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import org.apache.log4j.Logger;
import org.bench4q.agent.parameterization.impl.InstanceControler;
import org.bench4q.agent.parameterization.impl.InstanceController;
import org.bench4q.agent.storage.StorageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@ -66,10 +66,11 @@ public class ScenarioEngine {
return false;
}
final ScenarioContext context = this.getRunningTests().get(runId);
return runWith(context);
return runWith(context, runId);
}
private boolean runWith(final ScenarioContext scenarioContext) {
private boolean runWith(final ScenarioContext scenarioContext,
final UUID runId) {
if (scenarioContext == null) {
logger.error("The context required is null");
return false;
@ -79,10 +80,9 @@ public class ScenarioEngine {
taskMaker.execute(new Runnable() {
public void run() {
while (!scenarioContext.isFinished()) {
scenarioContext.getExecutor()
.execute(
new Worker(scenarioContext,
new InstanceControler()));
scenarioContext.getExecutor().execute(
new Worker(scenarioContext, new InstanceController(
runId, UUID.randomUUID())));
}
}
});

View File

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

View File

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

View File

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

View File

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

View File

@ -1,4 +1,4 @@
package org.bench4q.agent.plugin.basic.http;
package org.bench4q.agent.utils;
public class ParameterConstant {
public static final String escape = "\\";

View File

@ -1,11 +1,10 @@
package org.bench4q.agent.scenario.util;
package org.bench4q.agent.utils;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.StringTokenizer;
import org.bench4q.agent.plugin.basic.http.ParameterConstant;
import org.bench4q.agent.scenario.util.types.Table;
import org.bench4q.agent.utils.types.Table;
/**
*
@ -17,10 +16,9 @@ public abstract class ParameterParser {
private static final String NFIELD_SEPARATOR = RadioGroup_SEPARATOR;
static public List<String> buildNField(String value) {
StringTokenizer st = new StringTokenizer(value, NFIELD_SEPARATOR, false);
List<String> result = new ArrayList<String>();
while (st.hasMoreTokens()) {
String token = st.nextToken();
List<String> result = new LinkedList<String>();
List<String> realTokens = getRealTokens(NFIELD_SEPARATOR, value, false);
for (String token : realTokens) {
result.add(token.trim());
}
return result;
@ -89,6 +87,8 @@ public abstract class ParameterParser {
entry = entry.substring(0, entry.length() - 1) + separator;
}
}
if (entry.isEmpty())
continue;
result.add(entry);
}
return result;

View File

@ -1,4 +1,4 @@
package org.bench4q.agent.scenario.util;
package org.bench4q.agent.utils;
public class Type {
public static enum SupportTypes {

View File

@ -0,0 +1,5 @@
package org.bench4q.agent.utils.types;
public class CheckBox {
}

View File

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

View File

@ -0,0 +1,5 @@
package org.bench4q.agent.utils.types;
public class NField {
}

View File

@ -0,0 +1,5 @@
package org.bench4q.agent.utils.types;
public class Radio {
}

View File

@ -1,12 +1,12 @@
package org.bench4q.agent.scenario.util.types;
package org.bench4q.agent.utils.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;
import org.bench4q.agent.utils.ParameterConstant;
import org.bench4q.agent.utils.ParameterParser;
import org.bench4q.agent.utils.Type;
public class Table extends Type {
public static final String ROW_SEPARATOR = "|;";

View File

@ -1,13 +1,15 @@
package org.bench4q.agent.test.parameterization;
import org.bench4q.agent.parameterization.impl.InstanceControler;
import java.util.UUID;
import org.bench4q.agent.parameterization.impl.InstanceController;
import org.bench4q.share.helper.TestHelper;
public class TEST_HelloThread extends Thread {
InstanceControler ic;
InstanceController ic;
public TEST_HelloThread() {
ic = new InstanceControler();
ic = new InstanceController(UUID.randomUUID(), UUID.randomUUID());
}
public void run() {

View File

@ -3,13 +3,14 @@ package org.bench4q.agent.test.parameterization;
import static org.junit.Assert.*;
import java.util.HashMap;
import java.util.UUID;
import org.bench4q.agent.parameterization.impl.InstanceControler;
import org.bench4q.agent.parameterization.impl.InstanceController;
import org.bench4q.agent.parameterization.impl.Para_Table;
import org.bench4q.share.helper.TestHelper;
import org.junit.Test;
public class TEST_UserName {
public class Test_InstanceCotroller {
@Test
public void testGetParam() throws Exception {
@ -20,12 +21,14 @@ public class TEST_UserName {
"2");
System.out.println(ret);
InstanceControler ic = new InstanceControler();
InstanceController ic = new InstanceController(UUID.randomUUID(),
UUID.randomUUID());
String passwordName = ic
.getParam("<parameters name=\"useNamePassword\" class=\"Para_Table\" type=\"crossThread\" method=\"getTableColumnValue\" args=\"file,ScenarioParameters\\param1.txt,0,sequence,;,~,2\" />");
System.out.println(passwordName);
assertNotNull(passwordName);
InstanceControler instanceControler = new InstanceControler();
InstanceController instanceControler = new InstanceController(
UUID.randomUUID(), UUID.randomUUID());
String password2 = instanceControler
.getParam("<parameters name=\"useNamePassword\" class=\"Para_Table\" type=\"crossThread\" method=\"getTableColumnValue\" args=\"file,ScenarioParameters\\param1.txt,0,sequence,;,~,2\" />");
System.out.println(password2);

View File

@ -0,0 +1,33 @@
package org.bench4q.agent.test.parameterization;
import static org.junit.Assert.*;
import java.lang.reflect.Method;
import org.bench4q.agent.parameterization.impl.MyFileClassLoader;
import org.junit.Test;
public class Test_MyFileClassLoader {
private String Test_ClassPath = "E:\\j2ee_proj\\skythink\\WebContent\\WEB-INF\\classes\\";
@Test
public void test() throws ClassNotFoundException, InstantiationException,
IllegalAccessException {
MyFileClassLoader fileClsLoader = new MyFileClassLoader(Test_ClassPath);
Class<?> cls = fileClsLoader
.loadClass("com.cmw.entity.sys.AccordionEntity");
Object obj = cls.newInstance();
Method[] mthds = cls.getMethods();
for (Method mthd : mthds) {
String methodName = mthd.getName();
System.out.println("mthd.name=" + methodName);
}
System.out.println("obj.class=" + obj.getClass().getName());
System.out.println("obj.class=" + cls.getClassLoader().toString());
System.out.println("obj.class="
+ cls.getClassLoader().getParent().toString());
assertTrue(true);
}
}

View File

@ -0,0 +1,30 @@
package org.bench4q.agent.test.parameterization;
import static org.junit.Assert.*;
import org.bench4q.agent.parameterization.impl.ParameterFormat;
import org.junit.After;
import org.junit.Test;
public class Test_ParameterFormat {
private static String testcase = "<parameters name=\"useNamePassword\" class=\"Para_Table\" type=\"crossThread\" method=\"getTableColumnValue\" args=\"file;ScenarioParameters\\param1.txt;0;sequence;\\;;~;2\" />";
@After
public void tearDown() throws Exception {
}
@Test
public void test() {
ParameterFormat format = ParameterFormat.parseInputParameter(testcase);
assertNotNull(format);
assertEquals("useNamePassword", format.getName());
assertEquals("Para_Table", format.getClassName());
assertEquals("getTableColumnValue", format.getMethodName());
assertEquals("crossThread", format.getParamType());
assertEquals("file;ScenarioParameters\\param1.txt;0;sequence;\\;;~;2",
format.getArgsString());
assertEquals(7, format.getArgs().size());
assertEquals("file", format.getArgs().get(0));
assertEquals(";", format.getArgs().get(4));
}
}

View File

@ -2,7 +2,9 @@ package org.bench4q.agent.test.parameterization;
import static org.junit.Assert.assertEquals;
import org.bench4q.agent.parameterization.impl.InstanceControler;
import java.util.UUID;
import org.bench4q.agent.parameterization.impl.InstanceController;
import org.bench4q.agent.parameterization.impl.ParameterizationParser;
import org.bench4q.share.helper.TestHelper;
import org.junit.Test;
@ -20,7 +22,8 @@ public class Test_ParameterizationParser {
public void testParse() {
String result = ParameterizationParser.parse(
"<parameter class=\"Para_IteratorNumber\" method=\"getIteratorNumber\""
+ " type=\"crossThread\"/>", new InstanceControler());
+ " type=\"crossThread\"/>", new InstanceController(
UUID.randomUUID(), UUID.randomUUID()));
System.out.println(result);
}
}

View File

@ -8,8 +8,8 @@ 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.types.Table;
import org.bench4q.agent.utils.ParameterParser;
import org.bench4q.agent.utils.types.Table;
import org.bench4q.share.helper.TestHelper;
import org.junit.Test;
@ -40,7 +40,7 @@ public class Test_ParameterParser {
@Test
public void testGetNumberOfEscapeCharacter() throws Exception {
assertEquals(3, "\\\\\\".length());
assertEquals(2, TestHelper.invokePrivate(null,
assertEquals(2, TestHelper.invokeStaticPrivate(ParameterParser.class,
"getNumberOfEscapeCharacter", new Class[] { String.class },
new Object[] { "\\\\" }));
}
@ -69,7 +69,8 @@ public class Test_ParameterParser {
columnList.get(1));
@SuppressWarnings("unchecked")
List<List<String>> result = (List<List<String>>) TestHelper
.invokePrivate(null, "extractValueFromWellFormedTable",
.invokeStaticPrivate(Table.class,
"extractValueFromWellFormedTable",
new Class<?>[] { List.class },
new Object[] { new LinkedList<List<String>>() {
private static final long serialVersionUID = 1L;
@ -93,8 +94,9 @@ public class Test_ParameterParser {
@SuppressWarnings("unchecked")
private List<String> invokeGetRealTokens(String separator, String value,
boolean toUnescapeSeparator) throws Exception {
return (List<String>) TestHelper.invokePrivate(null, "getRealTokens",
new Class[] { String.class, String.class, boolean.class },
return (List<String>) TestHelper.invokeStaticPrivate(
ParameterParser.class, "getRealTokens", new Class[] {
String.class, String.class, boolean.class },
new Object[] { separator, value, true });
}
@ -199,4 +201,12 @@ public class Test_ParameterParser {
public void testParseResponseVariables() {
}
@Test
public void testParseNFields() {
List<String> result = ParameterParser
.buildNField("file;ScenarioParameters\\\\param1.txt;0;sequence;\\;;~;2");
assertEquals(7, result.size());
assertEquals(";", result.get(4));
}
}

View File

@ -13,6 +13,15 @@ public class TestHelper {
return method.invoke(targetObject, params);
}
public static Object invokeStaticPrivate(Class<?> containerClass,
String methodName, Class<?>[] paramClasses, Object[] params)
throws Exception {
Method method = containerClass.getDeclaredMethod(methodName,
paramClasses);
method.setAccessible(true);
return method.invoke(null, params);
}
public static void createFileIfNotExist(File file) {
if (file.exists()) {
return;