add ways to load all the parameterized classes when start
add ways to load all the parameterized classes when start
This commit is contained in:
parent
ecce6f01c4
commit
5df821b788
|
@ -275,13 +275,13 @@ public class TestController {
|
|||
@RequestMapping(value = "/clean/{runId}", method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public CleanTestResultModel clean(@PathVariable UUID runId) {
|
||||
ScenarioContext scenarioContext = this.getScenarioEngine()
|
||||
.getRunningTests().get(runId);
|
||||
if (scenarioContext == null) {
|
||||
return null;
|
||||
}
|
||||
scenarioContext.getExecutor().shutdownNow();
|
||||
this.getScenarioEngine().getRunningTests().remove(runId);
|
||||
// ScenarioContext scenarioContext = this.getScenarioEngine()
|
||||
// .getRunningTests().get(runId);
|
||||
// if (scenarioContext == null) {
|
||||
// return null;
|
||||
// }
|
||||
// scenarioContext.getExecutor().shutdownNow();
|
||||
// this.getScenarioEngine().getRunningTests().remove(runId);
|
||||
System.gc();
|
||||
CleanTestResultModel cleanTestResultModel = new CleanTestResultModel();
|
||||
cleanTestResultModel.setSuccess(true);
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package org.bench4q.agent.plugin;
|
||||
package org.bench4q.agent.helper;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
@ -6,16 +6,38 @@ import java.net.URL;
|
|||
import java.net.URLClassLoader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.jar.JarEntry;
|
||||
import java.util.jar.JarFile;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class ClassHelper {
|
||||
|
||||
public List<String> getClassNames(String packageName,
|
||||
public Map<String, Class<?>> loadClasses(String packageName,
|
||||
ClassLoadRestriction classLoadRestriction) {
|
||||
Map<String, Class<?>> name2ClassMap = new HashMap<String, Class<?>>();
|
||||
try {
|
||||
|
||||
for (String className : getClassNames(packageName, true)) {
|
||||
Class<?> clazz = Class.forName(className);
|
||||
if (classLoadRestriction.accept(clazz)) {
|
||||
name2ClassMap.put(classLoadRestriction.getAcceptKey(clazz),
|
||||
clazz);
|
||||
}
|
||||
}
|
||||
return name2ClassMap;
|
||||
} catch (Exception e) {
|
||||
Logger.getLogger(ClassHelper.class).error(e, e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private List<String> getClassNames(String packageName,
|
||||
boolean searchInChildPackage) {
|
||||
try {
|
||||
List<String> classNames = new ArrayList<String>();
|
|
@ -0,0 +1,7 @@
|
|||
package org.bench4q.agent.helper;
|
||||
|
||||
public interface ClassLoadRestriction {
|
||||
public boolean accept(Class<?> classUnderTest);
|
||||
|
||||
public String getAcceptKey(Class<?> classUnderTest);
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
package org.bench4q.agent.parameterization;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
@Target(ElementType.TYPE)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface ParameterizedClass {
|
||||
String name();
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
package org.bench4q.agent.parameterization;
|
||||
|
||||
public enum PickOrder {
|
||||
UNIQUE, SEQUENTIAL, RANDOM
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
package org.bench4q.agent.parameterization;
|
||||
|
||||
public enum UpdateStrategy {
|
||||
ONCE, EACH_ITERATION, EACH_OCCURRENCE
|
||||
}
|
|
@ -6,21 +6,24 @@ import java.util.Map;
|
|||
import java.util.UUID;
|
||||
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
||||
|
||||
import org.bench4q.agent.parameterization.ParameterizedClass;
|
||||
|
||||
@ParameterizedClass(name = "Para_GetEletronicCombine")
|
||||
public class Para_GetEletronicCombine {
|
||||
|
||||
public class eletronicParas
|
||||
{
|
||||
|
||||
public class eletronicParas {
|
||||
String beginUser;
|
||||
String endUser;
|
||||
String beginTime;
|
||||
String endTime;
|
||||
}
|
||||
|
||||
public Map<UUID, Para_GetEletronicCombine> useInstanceMap = new HashMap<UUID, Para_GetEletronicCombine>();
|
||||
@SuppressWarnings("deprecation")
|
||||
Date currentTimeLoop = new Date("2014-01-01");
|
||||
long currentUser = 10001;
|
||||
ReentrantReadWriteLock timeRWLock = new ReentrantReadWriteLock();
|
||||
|
||||
|
||||
public Para_GetEletronicCombine() {
|
||||
|
||||
}
|
||||
|
|
|
@ -3,6 +3,9 @@ package org.bench4q.agent.parameterization.impl;
|
|||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bench4q.agent.parameterization.ParameterizedClass;
|
||||
|
||||
@ParameterizedClass(name = "Para_IteratorNumber")
|
||||
public class Para_IteratorNumber {
|
||||
public Long iteratorNum = new Long(0);
|
||||
|
||||
|
|
|
@ -3,26 +3,29 @@ package org.bench4q.agent.parameterization.impl;
|
|||
import java.util.Random;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bench4q.agent.parameterization.ParameterizedClass;
|
||||
|
||||
@ParameterizedClass(name = "Para_RandomNumber")
|
||||
public class Para_RandomNumber {
|
||||
|
||||
public String getRandomIntegerNumber(UUID id,String begin, String end, String stringformat)
|
||||
{
|
||||
|
||||
|
||||
public String getRandomIntegerNumber(UUID id, String begin, String end,
|
||||
String stringformat) {
|
||||
|
||||
Random r = new Random();
|
||||
int beginNum = Integer.parseInt(begin);
|
||||
int endNum = Integer.parseInt(end);
|
||||
|
||||
int result = r.nextInt(endNum-beginNum) +beginNum;
|
||||
return String.format(stringformat,result);
|
||||
|
||||
int result = r.nextInt(endNum - beginNum) + beginNum;
|
||||
return String.format(stringformat, result);
|
||||
}
|
||||
|
||||
public String getRandomDouble(UUID id , String begin, String end , String stringformat)
|
||||
{
|
||||
|
||||
public String getRandomDouble(UUID id, String begin, String end,
|
||||
String stringformat) {
|
||||
Random r = new Random();
|
||||
double beginNum = Integer.parseInt(begin);
|
||||
double endNum = Integer.parseInt(end);
|
||||
|
||||
double result = r.nextDouble()*(endNum-beginNum) +beginNum;
|
||||
|
||||
double result = r.nextDouble() * (endNum - beginNum) + beginNum;
|
||||
return String.format(stringformat, result);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,14 +12,20 @@ import java.util.UUID;
|
|||
import java.util.concurrent.ArrayBlockingQueue;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public class Para_Table extends BasePara {
|
||||
import org.bench4q.agent.parameterization.ParameterizedClass;
|
||||
import org.bench4q.agent.parameterization.PickOrder;
|
||||
import org.bench4q.agent.parameterization.UpdateStrategy;
|
||||
|
||||
@ParameterizedClass(name = "Para_Table")
|
||||
public class Para_Table extends BasePara {
|
||||
public final int cacheCap = 5000;// 1 sequence 2 random
|
||||
public final int cacheSize = 1000;// 1 sequence 2 random
|
||||
public final int readCharSize = 10000;
|
||||
public ConcurrentHashMap<String, Reader> readerMap = new ConcurrentHashMap<String, Para_Table.Reader>();
|
||||
|
||||
public Para_Table(UUID testId) {
|
||||
public Para_Table(UUID testId, PickOrder pickOrder,
|
||||
UpdateStrategy updateStrategy) {
|
||||
// TODO: Use the pickOrder and updateStrategy to create this parameter
|
||||
super(testId);
|
||||
}
|
||||
|
||||
|
|
|
@ -2,11 +2,13 @@ package org.bench4q.agent.parameterization.impl;
|
|||
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bench4q.agent.parameterization.ParameterizedClass;
|
||||
|
||||
@ParameterizedClass(name = "Para_UniqueNumber")
|
||||
public class Para_UniqueNumber {
|
||||
int currentNumber = 0;
|
||||
|
||||
synchronized String getNumber(UUID id)
|
||||
{
|
||||
|
||||
synchronized String getNumber(UUID id) {
|
||||
return String.valueOf(currentNumber++);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,6 +5,9 @@ import java.util.Map;
|
|||
import java.util.UUID;
|
||||
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
||||
|
||||
import org.bench4q.agent.parameterization.ParameterizedClass;
|
||||
|
||||
@ParameterizedClass(name = "Para_UserNameAndPassword")
|
||||
public class Para_UserNameAndPassword {
|
||||
String[] Password = new String[] { "a", "b", "c", "d", "e" };
|
||||
String[] userName = new String[] { "http://www.baidu.com/",
|
||||
|
|
|
@ -1,28 +0,0 @@
|
|||
package org.bench4q.agent.parameterization.impl;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class ParameterThreadOption {
|
||||
public final ParameterThreadOption instance = new ParameterThreadOption();
|
||||
Map<String, List<String>> optionMap = new HashMap<String, List<String>>();
|
||||
private List<String> all = Arrays.asList("crossThread", "inThread");
|
||||
// private List<String> justIn = Arrays.asList("inThread");
|
||||
private List<String> justCross = Arrays.asList("crossThread");
|
||||
|
||||
private ParameterThreadOption() {
|
||||
optionMap.put("Para_File", all);
|
||||
optionMap.put("Para_IteratorNumber", justCross);
|
||||
optionMap.put("Para_RandomNumber", all);
|
||||
optionMap.put("Para_UniqueNumber", all);
|
||||
optionMap.put("Para_UserNameAndPassword", justCross);
|
||||
}
|
||||
|
||||
public List<String> getThreadOption(String classname) {
|
||||
if (this.optionMap.containsKey(classname) == false)
|
||||
return all;
|
||||
return optionMap.get(classname);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,177 @@
|
|||
package org.bench4q.agent.parameterization.impl;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.bench4q.agent.Main;
|
||||
import org.bench4q.agent.helper.ApplicationContextHelper;
|
||||
import org.bench4q.agent.helper.ClassHelper;
|
||||
import org.bench4q.agent.helper.ClassLoadRestriction;
|
||||
import org.bench4q.agent.parameterization.ParameterizedClass;
|
||||
import org.bench4q.agent.parameterization.PickOrder;
|
||||
import org.bench4q.agent.parameterization.UpdateStrategy;
|
||||
import org.bench4q.agent.scenario.DefinedParameter;
|
||||
|
||||
public class ParameterizationManager {
|
||||
private static final String PARAMETER_PACKAGE = "org.bench4q.agent.parameterization.impl";
|
||||
private Map<String, Object> objMap = new HashMap<String, Object>();
|
||||
private ReentrantReadWriteLock mapRWLock = new ReentrantReadWriteLock();
|
||||
|
||||
private Map<String, Class<?>> paraClasses;
|
||||
private Map<String, Object> parameterMap;
|
||||
private ClassHelper classHelper;
|
||||
|
||||
private UUID testId;
|
||||
|
||||
private UUID getTestId() {
|
||||
return testId;
|
||||
}
|
||||
|
||||
private void setTestId(UUID testId) {
|
||||
this.testId = testId;
|
||||
}
|
||||
|
||||
private ClassHelper getClassHelper() {
|
||||
return classHelper;
|
||||
}
|
||||
|
||||
private void setClassHelper(ClassHelper classHelper) {
|
||||
this.classHelper = classHelper;
|
||||
}
|
||||
|
||||
private Map<String, Object> getParameterMap() {
|
||||
return parameterMap;
|
||||
}
|
||||
|
||||
private void setParameterMap(Map<String, Object> parameterMap) {
|
||||
this.parameterMap = parameterMap;
|
||||
}
|
||||
|
||||
private Map<String, Class<?>> getParaClasses() {
|
||||
return paraClasses;
|
||||
}
|
||||
|
||||
private void setParaClasses(Map<String, Class<?>> paraClasses) {
|
||||
this.paraClasses = paraClasses;
|
||||
}
|
||||
|
||||
public ParameterizationManager() {
|
||||
this.setClassHelper(ApplicationContextHelper.getContext().getBean(
|
||||
ClassHelper.class));
|
||||
this.setParaClasses(this.getClassHelper().loadClasses(
|
||||
PARAMETER_PACKAGE, new ClassLoadRestriction() {
|
||||
public boolean accept(Class<?> classUnderTest) {
|
||||
return classUnderTest
|
||||
.isAnnotationPresent(ParameterizedClass.class);
|
||||
}
|
||||
|
||||
public String getAcceptKey(Class<?> classUnderTest) {
|
||||
return classUnderTest.getAnnotation(
|
||||
ParameterizedClass.class).name();
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
public ParameterizationManager(UUID testId, int parameterCount) {
|
||||
this();
|
||||
this.setTestId(testId);
|
||||
this.setParameterMap(new HashMap<String, Object>(parameterCount));
|
||||
|
||||
}
|
||||
|
||||
public VUserContext buildVUserContext() {
|
||||
return new VUserContext(this);
|
||||
}
|
||||
|
||||
public void cleanUp() {
|
||||
this.objMap.clear();
|
||||
this.getParameterMap().clear();
|
||||
}
|
||||
|
||||
public Object getObjWithGuardExist(String className) {
|
||||
Object result = null;
|
||||
className = ParamFormatParser.buildFullPath(className);
|
||||
if (!guardClassExist(className))
|
||||
throw new NullPointerException("Not find " + className);
|
||||
mapRWLock.readLock().lock();
|
||||
result = objMap.get(className);
|
||||
mapRWLock.readLock().unlock();
|
||||
return result;
|
||||
}
|
||||
|
||||
private boolean guardClassExist(String className) {
|
||||
return containObj(className) ? true : createObj(className);
|
||||
}
|
||||
|
||||
private boolean containObj(String className) {
|
||||
boolean ret = false;
|
||||
mapRWLock.readLock().lock();
|
||||
ret = objMap.containsKey(className);
|
||||
mapRWLock.readLock().unlock();
|
||||
return ret;
|
||||
}
|
||||
|
||||
private boolean createObj(String fullClassName) {
|
||||
try {
|
||||
UserDefinedClassLoader cl = new UserDefinedClassLoader(
|
||||
Main.USER_DEFINED_PARAMS_FOLDER);
|
||||
Class<?> cls = cl.loadClass(fullClassName);
|
||||
Constructor<?> contructor = cls.getConstructor(new Class[] {
|
||||
UUID.class, PickOrder.class, UpdateStrategy.class });
|
||||
Object instance = contructor.newInstance(new Object[] {
|
||||
this.getTestId(), PickOrder.SEQUENTIAL,
|
||||
UpdateStrategy.EACH_ITERATION });
|
||||
mapRWLock.writeLock().lock();
|
||||
objMap.put(fullClassName, instance);
|
||||
return true;
|
||||
} catch (Exception ex) {
|
||||
Logger.getLogger(ParameterizationManager.class).error(ex, ex);
|
||||
return false;
|
||||
} finally {
|
||||
if (mapRWLock.writeLock().isHeldByCurrentThread())
|
||||
mapRWLock.writeLock().unlock();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* For creating parameter with parameterName as the index
|
||||
*
|
||||
* @param definedParameter
|
||||
*/
|
||||
public boolean createParaInstanceWith(DefinedParameter definedParameter) {
|
||||
try {
|
||||
this.getParameterMap().put(
|
||||
definedParameter.getName(),
|
||||
loadClassWith(definedParameter.getType(), PickOrder
|
||||
.valueOf(definedParameter.getPickOrder()),
|
||||
UpdateStrategy.valueOf(definedParameter
|
||||
.getUpdateStrategy())));
|
||||
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private Object loadClassWith(String name, PickOrder pickOrder,
|
||||
UpdateStrategy updateStrategy) {
|
||||
if (!this.getParaClasses().containsKey(name)) {
|
||||
throw new NullPointerException("There's no class with " + name);
|
||||
}
|
||||
Class<?> clazz = this.getParaClasses().get(name);
|
||||
try {
|
||||
Constructor<?> constructor = clazz.getConstructor(UUID.class,
|
||||
PickOrder.class, UpdateStrategy.class);
|
||||
return constructor.newInstance(this.getTestId(), pickOrder,
|
||||
updateStrategy);
|
||||
} catch (Exception e) {
|
||||
throw new NullPointerException(
|
||||
"There's no constructor with three params");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,85 +0,0 @@
|
|||
package org.bench4q.agent.parameterization.impl;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.bench4q.agent.Main;
|
||||
import org.bench4q.agent.scenario.DefinedParameter;
|
||||
|
||||
public class ParametersFactory {
|
||||
private Map<String, Object> objMap = new HashMap<String, Object>();
|
||||
private ReentrantReadWriteLock mapRWLock = new ReentrantReadWriteLock();
|
||||
private UUID testId;
|
||||
|
||||
private UUID getTestId() {
|
||||
return testId;
|
||||
}
|
||||
|
||||
private void setTestId(UUID testId) {
|
||||
this.testId = testId;
|
||||
}
|
||||
|
||||
public ParametersFactory(UUID testId) {
|
||||
this.setTestId(testId);
|
||||
}
|
||||
|
||||
public VUserContext buildVUserContext() {
|
||||
return new VUserContext(this);
|
||||
}
|
||||
|
||||
public void cleanUp() {
|
||||
this.objMap.clear();
|
||||
}
|
||||
|
||||
public Object getObjWithGuardExist(String className) {
|
||||
Object result = null;
|
||||
className = ParamFormatParser.buildFullPath(className);
|
||||
if (!guardClassExist(className))
|
||||
throw new NullPointerException("Not find " + className);
|
||||
mapRWLock.readLock().lock();
|
||||
result = objMap.get(className);
|
||||
mapRWLock.readLock().unlock();
|
||||
return result;
|
||||
}
|
||||
|
||||
private boolean guardClassExist(String className) {
|
||||
return containObj(className) ? true : createObj(className);
|
||||
}
|
||||
|
||||
private boolean containObj(String className) {
|
||||
boolean ret = false;
|
||||
mapRWLock.readLock().lock();
|
||||
ret = objMap.containsKey(className);
|
||||
mapRWLock.readLock().unlock();
|
||||
return ret;
|
||||
}
|
||||
|
||||
private boolean createObj(String className) {
|
||||
try {
|
||||
UserDefinedClassLoader cl = new UserDefinedClassLoader(
|
||||
Main.USER_DEFINED_PARAMS_FOLDER);
|
||||
Class<?> cls = cl.loadClass(className);
|
||||
Constructor<?> contructor = cls
|
||||
.getConstructor(new Class[] { UUID.class });
|
||||
Object instance = contructor.newInstance(new Object[] { this
|
||||
.getTestId() });
|
||||
mapRWLock.writeLock().lock();
|
||||
objMap.put(className, instance);
|
||||
return true;
|
||||
} catch (Exception ex) {
|
||||
Logger.getLogger(ParametersFactory.class).error(ex, ex);
|
||||
return false;
|
||||
} finally {
|
||||
if (mapRWLock.writeLock().isHeldByCurrentThread())
|
||||
mapRWLock.writeLock().unlock();
|
||||
}
|
||||
}
|
||||
|
||||
public void createParaInstanceWith(DefinedParameter dP) {
|
||||
|
||||
}
|
||||
}
|
|
@ -14,7 +14,7 @@ import org.bench4q.agent.parameterization.SessionObject;
|
|||
|
||||
public class VUserContext implements SessionObject {
|
||||
private UUID id = UUID.randomUUID();
|
||||
private ParametersFactory paramterFactory;
|
||||
private ParameterizationManager paramterFactory;
|
||||
private Set<String> usedClassName = new HashSet<String>();
|
||||
private Map<String, Object> objMap = new HashMap<String, Object>();
|
||||
private Map<String, String> runtimeParamMap = new HashMap<String, String>();
|
||||
|
@ -22,18 +22,18 @@ public class VUserContext implements SessionObject {
|
|||
private ReentrantReadWriteLock mapRWLock = new ReentrantReadWriteLock();
|
||||
private Logger logger = Logger.getLogger(VUserContext.class);
|
||||
|
||||
private ParametersFactory getParamterFactory() {
|
||||
private ParameterizationManager getParamterFactory() {
|
||||
return paramterFactory;
|
||||
}
|
||||
|
||||
private void setParamterFactory(ParametersFactory paramterFactory) {
|
||||
private void setParamterFactory(ParameterizationManager paramterFactory) {
|
||||
this.paramterFactory = paramterFactory;
|
||||
}
|
||||
|
||||
private VUserContext() {
|
||||
}
|
||||
|
||||
public VUserContext(ParametersFactory parametersFactory) {
|
||||
public VUserContext(ParameterizationManager parametersFactory) {
|
||||
this();
|
||||
this.setParamterFactory(parametersFactory);
|
||||
}
|
||||
|
|
|
@ -4,17 +4,19 @@ import java.lang.annotation.Annotation;
|
|||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.bench4q.agent.helper.ClassHelper;
|
||||
import org.bench4q.agent.helper.ClassLoadRestriction;
|
||||
import org.bench4q.agent.share.DealWithLog;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class PluginManager {
|
||||
private static final String PLUGIN_PACKAGE_NAME = "org.bench4q.agent.plugin";
|
||||
private ClassHelper classHelper;
|
||||
private TypeConverter typeConverter;
|
||||
private Map<String, Class<?>> plugins;
|
||||
|
@ -24,7 +26,17 @@ public class PluginManager {
|
|||
public PluginManager(ClassHelper classHelper, TypeConverter typeConverter) {
|
||||
this.setClassHelper(classHelper);
|
||||
this.setTypeConverter(typeConverter);
|
||||
this.setPlugins(this.loadPlugins("org.bench4q.agent.plugin"));
|
||||
this.setPlugins(this.getClassHelper().loadClasses(PLUGIN_PACKAGE_NAME,
|
||||
new ClassLoadRestriction() {
|
||||
public boolean accept(Class<?> classUnderTest) {
|
||||
return classUnderTest.isAnnotationPresent(Plugin.class);
|
||||
}
|
||||
|
||||
public String getAcceptKey(Class<?> classUnderTest) {
|
||||
return classUnderTest.getAnnotation(Plugin.class)
|
||||
.value();
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
private ClassHelper getClassHelper() {
|
||||
|
@ -51,24 +63,6 @@ public class PluginManager {
|
|||
this.plugins = plugins;
|
||||
}
|
||||
|
||||
private Map<String, Class<?>> loadPlugins(String packageName) {
|
||||
try {
|
||||
List<String> classNames = this.getClassHelper().getClassNames(
|
||||
packageName, true);
|
||||
Map<String, Class<?>> ret = new HashMap<String, Class<?>>();
|
||||
for (String className : classNames) {
|
||||
Class<?> plugin = Class.forName(className);
|
||||
if (plugin.isAnnotationPresent(Plugin.class)) {
|
||||
ret.put(plugin.getAnnotation(Plugin.class).value(), plugin);
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public List<PluginInfo> getPluginInfo() {
|
||||
try {
|
||||
Map<String, Class<?>> plugins = this.getPlugins();
|
||||
|
|
|
@ -9,7 +9,7 @@ import java.util.concurrent.ThreadPoolExecutor.DiscardPolicy;
|
|||
|
||||
import org.bench4q.agent.datacollector.DataCollector;
|
||||
import org.bench4q.agent.datacollector.impl.ScenarioResultCollector;
|
||||
import org.bench4q.agent.parameterization.impl.ParametersFactory;
|
||||
import org.bench4q.agent.parameterization.impl.ParameterizationManager;
|
||||
import org.bench4q.agent.parameterization.impl.VUserContext;
|
||||
|
||||
public class ScenarioContext {
|
||||
|
@ -20,7 +20,7 @@ public class ScenarioContext {
|
|||
private Scenario scenario;
|
||||
private boolean finished;
|
||||
private DataCollector dataStatistics;
|
||||
private ParametersFactory parameterFactory;
|
||||
private ParameterizationManager parameterFactory;
|
||||
|
||||
public Date getStartDate() {
|
||||
return startDate;
|
||||
|
@ -70,11 +70,11 @@ public class ScenarioContext {
|
|||
this.dataStatistics = dataStatistics;
|
||||
}
|
||||
|
||||
public ParametersFactory getParameterFactory() {
|
||||
public ParameterizationManager getParameterFactory() {
|
||||
return parameterFactory;
|
||||
}
|
||||
|
||||
private void setParameterFactory(ParametersFactory parameterFactory) {
|
||||
private void setParameterFactory(ParameterizationManager parameterFactory) {
|
||||
this.parameterFactory = parameterFactory;
|
||||
}
|
||||
|
||||
|
@ -92,7 +92,8 @@ public class ScenarioContext {
|
|||
scenarioContext.setStartDate(new Date(System.currentTimeMillis()));
|
||||
scenarioContext.setExecutorService(executor);
|
||||
scenarioContext.setDataStatistics(new ScenarioResultCollector(testId));
|
||||
scenarioContext.setParameterFactory(new ParametersFactory(testId));
|
||||
scenarioContext.setParameterFactory(new ParameterizationManager(testId,
|
||||
scenario.getDefinedParameters().length));
|
||||
scenarioContext.prepareForParameterization();
|
||||
return scenarioContext;
|
||||
}
|
||||
|
|
|
@ -1,28 +0,0 @@
|
|||
package org.bench4q.agent.scenario;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class SessionContext {
|
||||
Map<String, String> variables;
|
||||
|
||||
private Map<String, String> getVariables() {
|
||||
return variables;
|
||||
}
|
||||
|
||||
private void setVariables(Map<String, String> variables) {
|
||||
this.variables = variables;
|
||||
}
|
||||
|
||||
public SessionContext() {
|
||||
this.setVariables(new HashMap<String, String>());
|
||||
}
|
||||
|
||||
public void addAVariable(String entryName, String entryValue) {
|
||||
this.getVariables().put(entryName, entryValue);
|
||||
}
|
||||
|
||||
public String getVariable(String entryName) {
|
||||
return this.getVariable(entryName);
|
||||
}
|
||||
}
|
|
@ -60,9 +60,11 @@ public class VUser implements Runnable {
|
|||
|
||||
private void doCleanUp() {
|
||||
this.sessionObject.doCleanUp();
|
||||
this.setSessionObject(null);
|
||||
this.setScenarioContext(null);
|
||||
}
|
||||
|
||||
public void doRunScenario(ScenarioContext context) {
|
||||
private void doRunScenario(ScenarioContext context) {
|
||||
Map<String, Object> plugins = new LinkedHashMap<String, Object>();
|
||||
preparePlugins(context.getScenario(), plugins);
|
||||
for (int i = 0; i < context.getScenario().getPages().length; i++) {
|
||||
|
|
|
@ -3,7 +3,7 @@ package org.bench4q.agent.test.parameterization;
|
|||
import java.util.UUID;
|
||||
|
||||
import org.bench4q.agent.parameterization.impl.VUserContext;
|
||||
import org.bench4q.agent.parameterization.impl.ParametersFactory;
|
||||
import org.bench4q.agent.parameterization.impl.ParameterizationManager;
|
||||
import org.bench4q.share.helper.TestHelper;
|
||||
|
||||
public class TEST_HelloThread extends Thread {
|
||||
|
@ -11,7 +11,7 @@ public class TEST_HelloThread extends Thread {
|
|||
|
||||
public TEST_HelloThread() {
|
||||
UUID testId = UUID.randomUUID();
|
||||
ic = new VUserContext(new ParametersFactory(testId));
|
||||
ic = new VUserContext(new ParameterizationManager(testId, 4));
|
||||
}
|
||||
|
||||
public void run() {
|
||||
|
|
|
@ -1,33 +0,0 @@
|
|||
package org.bench4q.agent.test.parameterization;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import org.bench4q.agent.parameterization.impl.UserDefinedClassLoader;
|
||||
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 {
|
||||
UserDefinedClassLoader fileClsLoader = new UserDefinedClassLoader(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);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,58 @@
|
|||
package org.bench4q.agent.test.parameterization;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bench4q.agent.parameterization.PickOrder;
|
||||
import org.bench4q.agent.parameterization.UpdateStrategy;
|
||||
import org.bench4q.agent.parameterization.impl.ParameterizationManager;
|
||||
import org.bench4q.agent.scenario.DefinedParameter;
|
||||
import org.bench4q.share.helper.TestHelper;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(locations = { "classpath:application-context.xml" })
|
||||
public class Test_ParameterManager {
|
||||
|
||||
@Test
|
||||
public void test_createParaInstanceWith() throws Exception {
|
||||
ParameterizationManager parameterizationManager = new ParameterizationManager(
|
||||
UUID.randomUUID(), 1);
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, Object> parameterMapBeforeCreate = (Map<String, Object>) TestHelper
|
||||
.invokePrivate(parameterizationManager, "getParameterMap",
|
||||
null, null);
|
||||
assertEquals(0, parameterMapBeforeCreate.size());
|
||||
assertTrue(parameterizationManager
|
||||
.createParaInstanceWith(new DefinedParameter("param1",
|
||||
"Para_Table", PickOrder.SEQUENTIAL.name(),
|
||||
UpdateStrategy.EACH_ITERATION.name())));
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, Object> parameterMapAfterCreate = (Map<String, Object>) TestHelper
|
||||
.invokePrivate(parameterizationManager, "getParameterMap",
|
||||
null, null);
|
||||
assertEquals(1, parameterMapAfterCreate.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_getParaClasses() throws Exception {
|
||||
ParameterizationManager parameterizationManager = new ParameterizationManager(
|
||||
UUID.randomUUID(), 1);
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, Class<?>> paraClasses = (Map<String, Class<?>>) TestHelper
|
||||
.invokePrivate(parameterizationManager, "getParaClasses", null,
|
||||
null);
|
||||
assertEquals(6, paraClasses.size());
|
||||
assertTrue(paraClasses.containsKey("Para_Table"));
|
||||
assertTrue(paraClasses.containsKey("Para_GetEletronicCombine"));
|
||||
assertTrue(paraClasses.containsKey("Para_IteratorNumber"));
|
||||
assertTrue(paraClasses.containsKey("Para_RandomNumber"));
|
||||
assertTrue(paraClasses.containsKey("Para_UniqueNumber"));
|
||||
assertTrue(paraClasses.containsKey("Para_UserNameAndPassword"));
|
||||
}
|
||||
}
|
|
@ -8,10 +8,12 @@ import java.util.HashMap;
|
|||
import java.util.UUID;
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.bench4q.agent.parameterization.PickOrder;
|
||||
import org.bench4q.agent.parameterization.UpdateStrategy;
|
||||
import org.bench4q.agent.parameterization.impl.VUserContext;
|
||||
import org.bench4q.agent.parameterization.impl.Para_Table;
|
||||
import org.bench4q.agent.parameterization.impl.ParamFormatParser;
|
||||
import org.bench4q.agent.parameterization.impl.ParametersFactory;
|
||||
import org.bench4q.agent.parameterization.impl.ParameterizationManager;
|
||||
import org.bench4q.share.helper.TestHelper;
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
|
@ -36,7 +38,8 @@ public class Test_VUserContext {
|
|||
@Test
|
||||
public void testGetParam() throws Exception {
|
||||
UUID testId = UUID.randomUUID();
|
||||
Para_Table table = new Para_Table(testId);
|
||||
Para_Table table = new Para_Table(testId, PickOrder.SEQUENTIAL,
|
||||
UpdateStrategy.EACH_ITERATION);
|
||||
createParamFileFor(table.getParamFileFullPath("param1"));
|
||||
String ret = table.getTableColumnValue(java.util.UUID.randomUUID(),
|
||||
new HashMap<String, Object>(), "param1", "0", "sequence", ";",
|
||||
|
@ -55,10 +58,11 @@ public class Test_VUserContext {
|
|||
@Test
|
||||
public void testGetParam2() throws Exception {
|
||||
UUID testId = UUID.randomUUID();
|
||||
ParametersFactory parametersFactory = new ParametersFactory(testId);
|
||||
ParameterizationManager parametersFactory = new ParameterizationManager(
|
||||
testId, 4);
|
||||
VUserContext ic = new VUserContext(parametersFactory);
|
||||
createParamFileFor(new Para_Table(testId)
|
||||
.getParamFileFullPath("param1"));
|
||||
createParamFileFor(new Para_Table(testId, PickOrder.SEQUENTIAL,
|
||||
UpdateStrategy.EACH_ITERATION).getParamFileFullPath("param1"));
|
||||
String passwordName = ic.getParam(Test_CASE1);
|
||||
System.out.println(passwordName);
|
||||
assertNotNull(passwordName);
|
||||
|
@ -81,9 +85,10 @@ public class Test_VUserContext {
|
|||
@Test
|
||||
public void testGetParameter() throws Exception {
|
||||
UUID testId = UUID.randomUUID();
|
||||
createParamFileFor(new Para_Table(testId)
|
||||
.getParamFileFullPath("param1"));
|
||||
VUserContext paracCoor = new VUserContext(new ParametersFactory(testId));
|
||||
createParamFileFor(new Para_Table(testId, PickOrder.SEQUENTIAL,
|
||||
UpdateStrategy.EACH_ITERATION).getParamFileFullPath("param1"));
|
||||
VUserContext paracCoor = new VUserContext(new ParameterizationManager(
|
||||
testId, 4));
|
||||
ParamFormatParser paramFormatParser = ParamFormatParser
|
||||
.parseInputParameter(Test_CASE1);
|
||||
String result = (String) TestHelper.invokePrivate(paracCoor,
|
||||
|
@ -96,9 +101,10 @@ public class Test_VUserContext {
|
|||
@Test
|
||||
public void testGetParameterCrossThread() throws Exception {
|
||||
UUID testId = UUID.randomUUID();
|
||||
createParamFileFor(new Para_Table(testId)
|
||||
.getParamFileFullPath("param1"));
|
||||
VUserContext paracCoor = new VUserContext(new ParametersFactory(testId));
|
||||
createParamFileFor(new Para_Table(testId, PickOrder.SEQUENTIAL,
|
||||
UpdateStrategy.EACH_ITERATION).getParamFileFullPath("param1"));
|
||||
VUserContext paracCoor = new VUserContext(new ParameterizationManager(
|
||||
testId, 4));
|
||||
ParamFormatParser paramFormatParser = ParamFormatParser
|
||||
.parseInputParameter(Test_CASE1);
|
||||
String result = (String) TestHelper.invokePrivate(
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
package org.bench4q.agent.test.plugin;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.bench4q.agent.helper.ClassHelper;
|
||||
import org.bench4q.agent.helper.ClassLoadRestriction;
|
||||
import org.bench4q.agent.plugin.Plugin;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class Test_ClassHelper {
|
||||
|
||||
@Test
|
||||
public void test_loadClasses() {
|
||||
Map<String, Class<?>> plugins = new ClassHelper().loadClasses(
|
||||
"org.bench4q.agent.plugin", new ClassLoadRestriction() {
|
||||
public boolean accept(Class<?> classUnderTest) {
|
||||
return classUnderTest.isAnnotationPresent(Plugin.class);
|
||||
}
|
||||
|
||||
public String getAcceptKey(Class<?> classUnderTest) {
|
||||
return classUnderTest.getAnnotation(Plugin.class)
|
||||
.value();
|
||||
}
|
||||
});
|
||||
assertEquals(5, plugins.size());
|
||||
assertEquals(true, plugins.containsKey("Http"));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
package org.bench4q.agent.test.plugin;
|
||||
|
||||
import org.bench4q.agent.helper.ClassHelper;
|
||||
import org.bench4q.agent.plugin.PluginManager;
|
||||
import org.bench4q.agent.plugin.TypeConverter;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class Test_PluginManager {
|
||||
@Test
|
||||
public void test_getInit() {
|
||||
PluginManager pluginManager = new PluginManager(new ClassHelper(),
|
||||
new TypeConverter());
|
||||
assertEquals(5, pluginManager.getPlugins().size());
|
||||
assertTrue(pluginManager.getPlugins().containsKey(
|
||||
"org.bench4q.agent.plugin.basic.http.HttpPlugin"));
|
||||
}
|
||||
}
|
|
@ -8,6 +8,8 @@ import java.util.UUID;
|
|||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.bench4q.agent.parameterization.PickOrder;
|
||||
import org.bench4q.agent.parameterization.UpdateStrategy;
|
||||
import org.bench4q.agent.parameterization.impl.Para_Table;
|
||||
import org.bench4q.agent.scenario.Scenario;
|
||||
import org.bench4q.agent.scenario.ScenarioContext;
|
||||
|
@ -57,8 +59,8 @@ public class Test_ScenarioContext {
|
|||
|
||||
private void createParamFileAndFillParamContent(String param_name,
|
||||
UUID testId) throws IOException {
|
||||
File parmFile = new File(
|
||||
new Para_Table(testId).getParamFileFullPath(param_name));
|
||||
File parmFile = new File(new Para_Table(testId, PickOrder.SEQUENTIAL,
|
||||
UpdateStrategy.EACH_ITERATION).getParamFileFullPath(param_name));
|
||||
TestHelper.createFileIfNotExist(parmFile);
|
||||
FileUtils.writeStringToFile(parmFile,
|
||||
"row1;10;11~row2;20;21~row3,30,31~");
|
||||
|
|
|
@ -11,6 +11,7 @@ import org.bench4q.agent.plugin.basic.http.HttpReturn;
|
|||
import org.bench4q.agent.scenario.Scenario;
|
||||
import org.bench4q.agent.scenario.ScenarioContext;
|
||||
import org.bench4q.agent.scenario.VUser;
|
||||
import org.bench4q.agent.test.plugin.Test_HBasePlugin;
|
||||
import org.bench4q.share.helper.TestHelper;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
@ -91,6 +92,14 @@ public class Test_VUser {
|
|||
|
||||
private VUser createAWorker() {
|
||||
return new VUser(ScenarioContext.buildScenarioContext(
|
||||
UUID.randomUUID(), new Scenario(), 10));
|
||||
UUID.randomUUID(),
|
||||
Scenario.scenarioBuilder(Test_HBasePlugin.buildScenario(10)),
|
||||
10));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_run() {
|
||||
VUser vUser = createAWorker();
|
||||
vUser.run();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue