From b1cc057f4d9a8169ff4d2f61a273c781191dbdac Mon Sep 17 00:00:00 2001 From: coderfengyun Date: Fri, 21 Mar 2014 18:33:59 +0800 Subject: [PATCH] refactor the parameterization and parameterparer part refactor the parameterization and parameterparer part --- .../configure/agent-config.properties | 3 +- .../src/main/java/org/bench4q/agent/Main.java | 12 ++- ...Controler.java => InstanceController.java} | 52 +++++++----- .../impl/MyFileClassLoader.java | 56 +++++-------- .../impl/ParameterFormat.java | 82 +++++++++++++++++++ .../impl/ParameterizationParser.java | 3 +- .../impl/ParametersFactory.java | 3 +- .../org/bench4q/agent/plugin/Parameter.java | 2 +- .../agent/plugin/basic/CommandLinePlugin.java | 2 +- .../plugin/basic/ConstantTimerPlugin.java | 2 +- .../bench4q/agent/plugin/basic/LogPlugin.java | 2 +- .../agent/plugin/basic/http/HttpPlugin.java | 6 +- .../agent/scenario/ScenarioEngine.java | 14 ++-- .../agent/scenario/util/types/CheckBox.java | 5 -- .../agent/scenario/util/types/Filed.java | 7 -- .../agent/scenario/util/types/NField.java | 5 -- .../agent/scenario/util/types/Radio.java | 5 -- .../http => utils}/ParameterConstant.java | 2 +- .../util => utils}/ParameterParser.java | 16 ++-- .../agent/{scenario/util => utils}/Type.java | 2 +- .../bench4q/agent/utils/types/CheckBox.java | 5 ++ .../org/bench4q/agent/utils/types/Filed.java | 7 ++ .../org/bench4q/agent/utils/types/NField.java | 5 ++ .../org/bench4q/agent/utils/types/Radio.java | 5 ++ .../{scenario/util => utils}/types/Table.java | 8 +- .../parameterization/TEST_HelloThread.java | 8 +- ...rName.java => Test_InstanceCotroller.java} | 11 ++- .../Test_MyFileClassLoader.java | 33 ++++++++ .../Test_ParameterFormat.java | 30 +++++++ .../Test_ParameterizationParser.java | 7 +- .../scenario/utils/Test_ParameterParser.java | 22 +++-- .../org/bench4q/share/helper/TestHelper.java | 9 ++ 32 files changed, 302 insertions(+), 129 deletions(-) rename Bench4Q-Agent/src/main/java/org/bench4q/agent/parameterization/impl/{InstanceControler.java => InstanceController.java} (80%) create mode 100644 Bench4Q-Agent/src/main/java/org/bench4q/agent/parameterization/impl/ParameterFormat.java delete mode 100644 Bench4Q-Agent/src/main/java/org/bench4q/agent/scenario/util/types/CheckBox.java delete mode 100644 Bench4Q-Agent/src/main/java/org/bench4q/agent/scenario/util/types/Filed.java delete mode 100644 Bench4Q-Agent/src/main/java/org/bench4q/agent/scenario/util/types/NField.java delete mode 100644 Bench4Q-Agent/src/main/java/org/bench4q/agent/scenario/util/types/Radio.java rename Bench4Q-Agent/src/main/java/org/bench4q/agent/{plugin/basic/http => utils}/ParameterConstant.java (63%) rename Bench4Q-Agent/src/main/java/org/bench4q/agent/{scenario/util => utils}/ParameterParser.java (88%) rename Bench4Q-Agent/src/main/java/org/bench4q/agent/{scenario/util => utils}/Type.java (71%) create mode 100644 Bench4Q-Agent/src/main/java/org/bench4q/agent/utils/types/CheckBox.java create mode 100644 Bench4Q-Agent/src/main/java/org/bench4q/agent/utils/types/Filed.java create mode 100644 Bench4Q-Agent/src/main/java/org/bench4q/agent/utils/types/NField.java create mode 100644 Bench4Q-Agent/src/main/java/org/bench4q/agent/utils/types/Radio.java rename Bench4Q-Agent/src/main/java/org/bench4q/agent/{scenario/util => utils}/types/Table.java (94%) rename Bench4Q-Agent/src/test/java/org/bench4q/agent/test/parameterization/{TEST_UserName.java => Test_InstanceCotroller.java} (79%) create mode 100644 Bench4Q-Agent/src/test/java/org/bench4q/agent/test/parameterization/Test_MyFileClassLoader.java create mode 100644 Bench4Q-Agent/src/test/java/org/bench4q/agent/test/parameterization/Test_ParameterFormat.java diff --git a/Bench4Q-Agent/configure/agent-config.properties b/Bench4Q-Agent/configure/agent-config.properties index 3c09e025..7590b5f4 100644 --- a/Bench4Q-Agent/configure/agent-config.properties +++ b/Bench4Q-Agent/configure/agent-config.properties @@ -1,3 +1,4 @@ isToSaveDetailResult=false servePort=6565 -userDefinedParamFolder=userDefinedParams \ No newline at end of file +userDefinedParamFolder=userDefinedParams +scenarioParamFolder=ScenarioParameters \ No newline at end of file diff --git a/Bench4Q-Agent/src/main/java/org/bench4q/agent/Main.java b/Bench4Q-Agent/src/main/java/org/bench4q/agent/Main.java index 45c45d7b..ca55bbe0 100644 --- a/Bench4Q-Agent/src/main/java/org/bench4q/agent/Main.java +++ b/Bench4Q-Agent/src/main/java/org/bench4q/agent/Main.java @@ -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!"); diff --git a/Bench4Q-Agent/src/main/java/org/bench4q/agent/parameterization/impl/InstanceControler.java b/Bench4Q-Agent/src/main/java/org/bench4q/agent/parameterization/impl/InstanceController.java similarity index 80% rename from Bench4Q-Agent/src/main/java/org/bench4q/agent/parameterization/impl/InstanceControler.java rename to Bench4Q-Agent/src/main/java/org/bench4q/agent/parameterization/impl/InstanceController.java index 91f6ba09..2d6c2163 100644 --- a/Bench4Q-Agent/src/main/java/org/bench4q/agent/parameterization/impl/InstanceControler.java +++ b/Bench4Q-Agent/src/main/java/org/bench4q/agent/parameterization/impl/InstanceController.java @@ -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 usedClassName = new HashSet(); private Map objMap = new HashMap(); - private Map runtimeParaMap = new HashMap(); + private Map runtimeParamMap = new HashMap(); private Map cacheObjMap = new HashMap(); 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 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"); diff --git a/Bench4Q-Agent/src/main/java/org/bench4q/agent/parameterization/impl/MyFileClassLoader.java b/Bench4Q-Agent/src/main/java/org/bench4q/agent/parameterization/impl/MyFileClassLoader.java index 44448d68..0dff5e15 100644 --- a/Bench4Q-Agent/src/main/java/org/bench4q/agent/parameterization/impl/MyFileClassLoader.java +++ b/Bench4Q-Agent/src/main/java/org/bench4q/agent/parameterization/impl/MyFileClassLoader.java @@ -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); } /** - * ��������ַ��ָ����Ŀ¼�����࣬����������� + * 锟斤拷锟斤拷锟斤拷锟斤拷址锟斤拷指锟斤拷锟斤拷目录锟斤拷锟斤拷锟洁,锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟� */ @Override protected Class findClass(String name) throws ClassNotFoundException { @@ -46,11 +36,11 @@ public class MyFileClassLoader extends ClassLoader { } /** - * ��������ַ������ byte ����� + * 锟斤拷锟斤拷锟斤拷锟斤拷址锟斤拷锟斤拷锟斤拷 byte 锟斤拷锟斤拷锟� * * @param name - * �����ַ� ���磺 com.cmw.entity.SysEntity - * @return �������ļ� byte ����� + * 锟斤拷锟斤拷锟街凤拷 锟斤拷锟界: com.cmw.entity.SysEntity + * @return 锟斤拷锟斤拷锟斤拷锟侥硷拷 byte 锟斤拷锟斤拷锟� * @throws IOException */ private byte[] loadClassData(String name) throws IOException { @@ -63,17 +53,17 @@ public class MyFileClassLoader extends ClassLoader { } /** - * ��������ַ���һ�� File ���� + * 锟斤拷锟斤拷锟斤拷锟斤拷址锟斤拷锟揭伙拷锟�File 锟斤拷锟斤拷 * * @param name - * �����ַ� - * @return File ���� + * 锟斤拷锟斤拷锟街凤拷 + * @return File 锟斤拷锟斤拷 * @throws FileNotFoundException */ private File getFile(String name) throws FileNotFoundException { File dir = new File(classPath); if (!dir.exists()) - throw new FileNotFoundException(classPath + " Ŀ¼�����ڣ�"); + 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 + " �����ڣ�"); + throw new FileNotFoundException(dir + " 锟斤拷锟斤拷锟节o拷"); return dir; } - public String getClassPath() { - return classPath; - } - - public void setClassPath(String classPath) { - this.classPath = classPath; - } - } diff --git a/Bench4Q-Agent/src/main/java/org/bench4q/agent/parameterization/impl/ParameterFormat.java b/Bench4Q-Agent/src/main/java/org/bench4q/agent/parameterization/impl/ParameterFormat.java new file mode 100644 index 00000000..706ba001 --- /dev/null +++ b/Bench4Q-Agent/src/main/java/org/bench4q/agent/parameterization/impl/ParameterFormat.java @@ -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 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 getArgs() { + return args; + } + + private void setArgs(List 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; + } +} diff --git a/Bench4Q-Agent/src/main/java/org/bench4q/agent/parameterization/impl/ParameterizationParser.java b/Bench4Q-Agent/src/main/java/org/bench4q/agent/parameterization/impl/ParameterizationParser.java index ff6f6684..ace54644 100644 --- a/Bench4Q-Agent/src/main/java/org/bench4q/agent/parameterization/impl/ParameterizationParser.java +++ b/Bench4Q-Agent/src/main/java/org/bench4q/agent/parameterization/impl/ParameterizationParser.java @@ -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(""); 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("")) diff --git a/Bench4Q-Agent/src/main/java/org/bench4q/agent/parameterization/impl/ParametersFactory.java b/Bench4Q-Agent/src/main/java/org/bench4q/agent/parameterization/impl/ParametersFactory.java index 8b7b081f..8d6072ec 100644 --- a/Bench4Q-Agent/src/main/java/org/bench4q/agent/parameterization/impl/ParametersFactory.java +++ b/Bench4Q-Agent/src/main/java/org/bench4q/agent/parameterization/impl/ParametersFactory.java @@ -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(); diff --git a/Bench4Q-Agent/src/main/java/org/bench4q/agent/plugin/Parameter.java b/Bench4Q-Agent/src/main/java/org/bench4q/agent/plugin/Parameter.java index caaa3769..2fdb3a91 100644 --- a/Bench4Q-Agent/src/main/java/org/bench4q/agent/plugin/Parameter.java +++ b/Bench4Q-Agent/src/main/java/org/bench4q/agent/plugin/Parameter.java @@ -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) diff --git a/Bench4Q-Agent/src/main/java/org/bench4q/agent/plugin/basic/CommandLinePlugin.java b/Bench4Q-Agent/src/main/java/org/bench4q/agent/plugin/basic/CommandLinePlugin.java index 3c7e03e0..9ec70c8b 100644 --- a/Bench4Q-Agent/src/main/java/org/bench4q/agent/plugin/basic/CommandLinePlugin.java +++ b/Bench4Q-Agent/src/main/java/org/bench4q/agent/plugin/basic/CommandLinePlugin.java @@ -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 { diff --git a/Bench4Q-Agent/src/main/java/org/bench4q/agent/plugin/basic/ConstantTimerPlugin.java b/Bench4Q-Agent/src/main/java/org/bench4q/agent/plugin/basic/ConstantTimerPlugin.java index c81333bf..7f0a44f7 100644 --- a/Bench4Q-Agent/src/main/java/org/bench4q/agent/plugin/basic/ConstantTimerPlugin.java +++ b/Bench4Q-Agent/src/main/java/org/bench4q/agent/plugin/basic/ConstantTimerPlugin.java @@ -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 { diff --git a/Bench4Q-Agent/src/main/java/org/bench4q/agent/plugin/basic/LogPlugin.java b/Bench4Q-Agent/src/main/java/org/bench4q/agent/plugin/basic/LogPlugin.java index 03e46e31..499e7acf 100644 --- a/Bench4Q-Agent/src/main/java/org/bench4q/agent/plugin/basic/LogPlugin.java +++ b/Bench4Q-Agent/src/main/java/org/bench4q/agent/plugin/basic/LogPlugin.java @@ -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 { diff --git a/Bench4Q-Agent/src/main/java/org/bench4q/agent/plugin/basic/http/HttpPlugin.java b/Bench4Q-Agent/src/main/java/org/bench4q/agent/plugin/basic/http/HttpPlugin.java index 69358a0f..4b3b34ad 100644 --- a/Bench4Q-Agent/src/main/java/org/bench4q/agent/plugin/basic/http/HttpPlugin.java +++ b/Bench4Q-Agent/src/main/java/org/bench4q/agent/plugin/basic/http/HttpPlugin.java @@ -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 { diff --git a/Bench4Q-Agent/src/main/java/org/bench4q/agent/scenario/ScenarioEngine.java b/Bench4Q-Agent/src/main/java/org/bench4q/agent/scenario/ScenarioEngine.java index 141b1e23..d76576ce 100644 --- a/Bench4Q-Agent/src/main/java/org/bench4q/agent/scenario/ScenarioEngine.java +++ b/Bench4Q-Agent/src/main/java/org/bench4q/agent/scenario/ScenarioEngine.java @@ -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()))); } } }); diff --git a/Bench4Q-Agent/src/main/java/org/bench4q/agent/scenario/util/types/CheckBox.java b/Bench4Q-Agent/src/main/java/org/bench4q/agent/scenario/util/types/CheckBox.java deleted file mode 100644 index 118bfa13..00000000 --- a/Bench4Q-Agent/src/main/java/org/bench4q/agent/scenario/util/types/CheckBox.java +++ /dev/null @@ -1,5 +0,0 @@ -package org.bench4q.agent.scenario.util.types; - -public class CheckBox { - -} diff --git a/Bench4Q-Agent/src/main/java/org/bench4q/agent/scenario/util/types/Filed.java b/Bench4Q-Agent/src/main/java/org/bench4q/agent/scenario/util/types/Filed.java deleted file mode 100644 index b420c411..00000000 --- a/Bench4Q-Agent/src/main/java/org/bench4q/agent/scenario/util/types/Filed.java +++ /dev/null @@ -1,7 +0,0 @@ -package org.bench4q.agent.scenario.util.types; - -import org.bench4q.agent.scenario.util.Type; - -public class Filed extends Type { - -} diff --git a/Bench4Q-Agent/src/main/java/org/bench4q/agent/scenario/util/types/NField.java b/Bench4Q-Agent/src/main/java/org/bench4q/agent/scenario/util/types/NField.java deleted file mode 100644 index ef9cbca4..00000000 --- a/Bench4Q-Agent/src/main/java/org/bench4q/agent/scenario/util/types/NField.java +++ /dev/null @@ -1,5 +0,0 @@ -package org.bench4q.agent.scenario.util.types; - -public class NField { - -} diff --git a/Bench4Q-Agent/src/main/java/org/bench4q/agent/scenario/util/types/Radio.java b/Bench4Q-Agent/src/main/java/org/bench4q/agent/scenario/util/types/Radio.java deleted file mode 100644 index b82c9856..00000000 --- a/Bench4Q-Agent/src/main/java/org/bench4q/agent/scenario/util/types/Radio.java +++ /dev/null @@ -1,5 +0,0 @@ -package org.bench4q.agent.scenario.util.types; - -public class Radio { - -} diff --git a/Bench4Q-Agent/src/main/java/org/bench4q/agent/plugin/basic/http/ParameterConstant.java b/Bench4Q-Agent/src/main/java/org/bench4q/agent/utils/ParameterConstant.java similarity index 63% rename from Bench4Q-Agent/src/main/java/org/bench4q/agent/plugin/basic/http/ParameterConstant.java rename to Bench4Q-Agent/src/main/java/org/bench4q/agent/utils/ParameterConstant.java index 691565f5..bea21e33 100644 --- a/Bench4Q-Agent/src/main/java/org/bench4q/agent/plugin/basic/http/ParameterConstant.java +++ b/Bench4Q-Agent/src/main/java/org/bench4q/agent/utils/ParameterConstant.java @@ -1,4 +1,4 @@ -package org.bench4q.agent.plugin.basic.http; +package org.bench4q.agent.utils; public class ParameterConstant { public static final String escape = "\\"; diff --git a/Bench4Q-Agent/src/main/java/org/bench4q/agent/scenario/util/ParameterParser.java b/Bench4Q-Agent/src/main/java/org/bench4q/agent/utils/ParameterParser.java similarity index 88% rename from Bench4Q-Agent/src/main/java/org/bench4q/agent/scenario/util/ParameterParser.java rename to Bench4Q-Agent/src/main/java/org/bench4q/agent/utils/ParameterParser.java index e13bedf0..ba876655 100644 --- a/Bench4Q-Agent/src/main/java/org/bench4q/agent/scenario/util/ParameterParser.java +++ b/Bench4Q-Agent/src/main/java/org/bench4q/agent/utils/ParameterParser.java @@ -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 buildNField(String value) { - StringTokenizer st = new StringTokenizer(value, NFIELD_SEPARATOR, false); - List result = new ArrayList(); - while (st.hasMoreTokens()) { - String token = st.nextToken(); + List result = new LinkedList(); + List 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; diff --git a/Bench4Q-Agent/src/main/java/org/bench4q/agent/scenario/util/Type.java b/Bench4Q-Agent/src/main/java/org/bench4q/agent/utils/Type.java similarity index 71% rename from Bench4Q-Agent/src/main/java/org/bench4q/agent/scenario/util/Type.java rename to Bench4Q-Agent/src/main/java/org/bench4q/agent/utils/Type.java index c7e52b13..c9b1b4e4 100644 --- a/Bench4Q-Agent/src/main/java/org/bench4q/agent/scenario/util/Type.java +++ b/Bench4Q-Agent/src/main/java/org/bench4q/agent/utils/Type.java @@ -1,4 +1,4 @@ -package org.bench4q.agent.scenario.util; +package org.bench4q.agent.utils; public class Type { public static enum SupportTypes { diff --git a/Bench4Q-Agent/src/main/java/org/bench4q/agent/utils/types/CheckBox.java b/Bench4Q-Agent/src/main/java/org/bench4q/agent/utils/types/CheckBox.java new file mode 100644 index 00000000..158bd5f5 --- /dev/null +++ b/Bench4Q-Agent/src/main/java/org/bench4q/agent/utils/types/CheckBox.java @@ -0,0 +1,5 @@ +package org.bench4q.agent.utils.types; + +public class CheckBox { + +} diff --git a/Bench4Q-Agent/src/main/java/org/bench4q/agent/utils/types/Filed.java b/Bench4Q-Agent/src/main/java/org/bench4q/agent/utils/types/Filed.java new file mode 100644 index 00000000..b54e2a01 --- /dev/null +++ b/Bench4Q-Agent/src/main/java/org/bench4q/agent/utils/types/Filed.java @@ -0,0 +1,7 @@ +package org.bench4q.agent.utils.types; + +import org.bench4q.agent.utils.Type; + +public class Filed extends Type { + +} diff --git a/Bench4Q-Agent/src/main/java/org/bench4q/agent/utils/types/NField.java b/Bench4Q-Agent/src/main/java/org/bench4q/agent/utils/types/NField.java new file mode 100644 index 00000000..c27f49a0 --- /dev/null +++ b/Bench4Q-Agent/src/main/java/org/bench4q/agent/utils/types/NField.java @@ -0,0 +1,5 @@ +package org.bench4q.agent.utils.types; + +public class NField { + +} diff --git a/Bench4Q-Agent/src/main/java/org/bench4q/agent/utils/types/Radio.java b/Bench4Q-Agent/src/main/java/org/bench4q/agent/utils/types/Radio.java new file mode 100644 index 00000000..53165f2d --- /dev/null +++ b/Bench4Q-Agent/src/main/java/org/bench4q/agent/utils/types/Radio.java @@ -0,0 +1,5 @@ +package org.bench4q.agent.utils.types; + +public class Radio { + +} diff --git a/Bench4Q-Agent/src/main/java/org/bench4q/agent/scenario/util/types/Table.java b/Bench4Q-Agent/src/main/java/org/bench4q/agent/utils/types/Table.java similarity index 94% rename from Bench4Q-Agent/src/main/java/org/bench4q/agent/scenario/util/types/Table.java rename to Bench4Q-Agent/src/main/java/org/bench4q/agent/utils/types/Table.java index 40b16764..4be3ebb2 100644 --- a/Bench4Q-Agent/src/main/java/org/bench4q/agent/scenario/util/types/Table.java +++ b/Bench4Q-Agent/src/main/java/org/bench4q/agent/utils/types/Table.java @@ -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 = "|;"; diff --git a/Bench4Q-Agent/src/test/java/org/bench4q/agent/test/parameterization/TEST_HelloThread.java b/Bench4Q-Agent/src/test/java/org/bench4q/agent/test/parameterization/TEST_HelloThread.java index b93f6413..b56d0b05 100644 --- a/Bench4Q-Agent/src/test/java/org/bench4q/agent/test/parameterization/TEST_HelloThread.java +++ b/Bench4Q-Agent/src/test/java/org/bench4q/agent/test/parameterization/TEST_HelloThread.java @@ -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() { diff --git a/Bench4Q-Agent/src/test/java/org/bench4q/agent/test/parameterization/TEST_UserName.java b/Bench4Q-Agent/src/test/java/org/bench4q/agent/test/parameterization/Test_InstanceCotroller.java similarity index 79% rename from Bench4Q-Agent/src/test/java/org/bench4q/agent/test/parameterization/TEST_UserName.java rename to Bench4Q-Agent/src/test/java/org/bench4q/agent/test/parameterization/Test_InstanceCotroller.java index 89e4f2f2..8eb74d4a 100644 --- a/Bench4Q-Agent/src/test/java/org/bench4q/agent/test/parameterization/TEST_UserName.java +++ b/Bench4Q-Agent/src/test/java/org/bench4q/agent/test/parameterization/Test_InstanceCotroller.java @@ -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(""); System.out.println(passwordName); assertNotNull(passwordName); - InstanceControler instanceControler = new InstanceControler(); + InstanceController instanceControler = new InstanceController( + UUID.randomUUID(), UUID.randomUUID()); String password2 = instanceControler .getParam(""); System.out.println(password2); diff --git a/Bench4Q-Agent/src/test/java/org/bench4q/agent/test/parameterization/Test_MyFileClassLoader.java b/Bench4Q-Agent/src/test/java/org/bench4q/agent/test/parameterization/Test_MyFileClassLoader.java new file mode 100644 index 00000000..b2285f3f --- /dev/null +++ b/Bench4Q-Agent/src/test/java/org/bench4q/agent/test/parameterization/Test_MyFileClassLoader.java @@ -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); + } + +} diff --git a/Bench4Q-Agent/src/test/java/org/bench4q/agent/test/parameterization/Test_ParameterFormat.java b/Bench4Q-Agent/src/test/java/org/bench4q/agent/test/parameterization/Test_ParameterFormat.java new file mode 100644 index 00000000..68943064 --- /dev/null +++ b/Bench4Q-Agent/src/test/java/org/bench4q/agent/test/parameterization/Test_ParameterFormat.java @@ -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 = ""; + + @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)); + } +} diff --git a/Bench4Q-Agent/src/test/java/org/bench4q/agent/test/parameterization/Test_ParameterizationParser.java b/Bench4Q-Agent/src/test/java/org/bench4q/agent/test/parameterization/Test_ParameterizationParser.java index a802129b..9c808ca4 100644 --- a/Bench4Q-Agent/src/test/java/org/bench4q/agent/test/parameterization/Test_ParameterizationParser.java +++ b/Bench4Q-Agent/src/test/java/org/bench4q/agent/test/parameterization/Test_ParameterizationParser.java @@ -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( "", new InstanceControler()); + + " type=\"crossThread\"/>", new InstanceController( + UUID.randomUUID(), UUID.randomUUID())); System.out.println(result); } } diff --git a/Bench4Q-Agent/src/test/java/org/bench4q/agent/test/scenario/utils/Test_ParameterParser.java b/Bench4Q-Agent/src/test/java/org/bench4q/agent/test/scenario/utils/Test_ParameterParser.java index 3900fcaf..ff6947ee 100644 --- a/Bench4Q-Agent/src/test/java/org/bench4q/agent/test/scenario/utils/Test_ParameterParser.java +++ b/Bench4Q-Agent/src/test/java/org/bench4q/agent/test/scenario/utils/Test_ParameterParser.java @@ -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> result = (List>) TestHelper - .invokePrivate(null, "extractValueFromWellFormedTable", + .invokeStaticPrivate(Table.class, + "extractValueFromWellFormedTable", new Class[] { List.class }, new Object[] { new LinkedList>() { private static final long serialVersionUID = 1L; @@ -93,8 +94,9 @@ public class Test_ParameterParser { @SuppressWarnings("unchecked") private List invokeGetRealTokens(String separator, String value, boolean toUnescapeSeparator) throws Exception { - return (List) TestHelper.invokePrivate(null, "getRealTokens", - new Class[] { String.class, String.class, boolean.class }, + return (List) 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 result = ParameterParser + .buildNField("file;ScenarioParameters\\\\param1.txt;0;sequence;\\;;~;2"); + assertEquals(7, result.size()); + assertEquals(";", result.get(4)); + } } diff --git a/Bench4Q-Share/src/main/java/org/bench4q/share/helper/TestHelper.java b/Bench4Q-Share/src/main/java/org/bench4q/share/helper/TestHelper.java index 45826b05..c38c2bdd 100644 --- a/Bench4Q-Share/src/main/java/org/bench4q/share/helper/TestHelper.java +++ b/Bench4Q-Share/src/main/java/org/bench4q/share/helper/TestHelper.java @@ -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;