add new tests about parameterization and pass them
add new tests about parameterization and pass them
This commit is contained in:
parent
380e5b633f
commit
6307f1c841
|
@ -6,6 +6,7 @@ import org.bench4q.agent.Main;
|
||||||
|
|
||||||
public abstract class BasePara {
|
public abstract class BasePara {
|
||||||
private UUID testId;
|
private UUID testId;
|
||||||
|
protected int lastIndex;
|
||||||
|
|
||||||
protected UUID getTestId() {
|
protected UUID getTestId() {
|
||||||
return testId;
|
return testId;
|
||||||
|
@ -15,6 +16,14 @@ public abstract class BasePara {
|
||||||
this.testId = testId;
|
this.testId = testId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getLastIndex() {
|
||||||
|
return lastIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void setLastIndex(int lastIndex) {
|
||||||
|
this.lastIndex = lastIndex;
|
||||||
|
}
|
||||||
|
|
||||||
public BasePara(UUID testId) {
|
public BasePara(UUID testId) {
|
||||||
this.setTestId(testId);
|
this.setTestId(testId);
|
||||||
}
|
}
|
||||||
|
@ -26,4 +35,6 @@ public abstract class BasePara {
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract String getCurrentValue();
|
public abstract String getCurrentValue();
|
||||||
|
|
||||||
|
protected abstract int getNextIndex(int size);
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,8 +14,22 @@ import org.bench4q.agent.utils.ParameterParser;
|
||||||
@ParameterizedClass(name = "Para_File")
|
@ParameterizedClass(name = "Para_File")
|
||||||
public class Para_File extends BasePara {
|
public class Para_File extends BasePara {
|
||||||
private String currentValue;
|
private String currentValue;
|
||||||
|
private String paramName;
|
||||||
|
private PickOrder pickOrder;
|
||||||
|
private UpdateStrategy updateStrategy;
|
||||||
|
|
||||||
|
private String getParamName() {
|
||||||
|
return paramName;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setParamName(String paramName) {
|
||||||
|
this.paramName = paramName;
|
||||||
|
}
|
||||||
|
|
||||||
public String getCurrentValue() {
|
public String getCurrentValue() {
|
||||||
|
if (this.getUpdateStrategy() == UpdateStrategy.EACH_OCCURRENCE) {
|
||||||
|
initialValue();
|
||||||
|
}
|
||||||
return currentValue;
|
return currentValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,15 +37,34 @@ public class Para_File extends BasePara {
|
||||||
this.currentValue = currentValue;
|
this.currentValue = currentValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Para_File(UUID testId, PickOrder pickOrder,
|
private PickOrder getPickOrder() {
|
||||||
UpdateStrategy updateStrategy, String paramName) {
|
return pickOrder;
|
||||||
super(testId);
|
|
||||||
initialValue(paramName);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initialValue(String paramName) {
|
private void setPickOrder(PickOrder pickOrder) {
|
||||||
// In a sequential way
|
this.pickOrder = pickOrder;
|
||||||
File paramFile = new File(getParamFileFullPath(paramName));
|
}
|
||||||
|
|
||||||
|
private UpdateStrategy getUpdateStrategy() {
|
||||||
|
return updateStrategy;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setUpdateStrategy(UpdateStrategy updateStrategy) {
|
||||||
|
this.updateStrategy = updateStrategy;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Para_File(UUID testId, PickOrder pickOrder,
|
||||||
|
UpdateStrategy updateStrategy, String paramName, int currentIndex) {
|
||||||
|
super(testId);
|
||||||
|
this.setParamName(paramName);
|
||||||
|
this.setPickOrder(pickOrder);
|
||||||
|
this.setUpdateStrategy(updateStrategy);
|
||||||
|
this.setLastIndex(currentIndex);
|
||||||
|
initialValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initialValue() {
|
||||||
|
File paramFile = new File(getParamFileFullPath(this.getParamName()));
|
||||||
List<String> nField = null;
|
List<String> nField = null;
|
||||||
try {
|
try {
|
||||||
String content = FileUtils.readFileToString(paramFile);
|
String content = FileUtils.readFileToString(paramFile);
|
||||||
|
@ -39,12 +72,32 @@ public class Para_File extends BasePara {
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
Random random = new Random();
|
|
||||||
if (nField.size() == 0) {
|
if (nField.size() == 0) {
|
||||||
throw new NullPointerException(
|
throw new NullPointerException(
|
||||||
"The parameter file has no valid content");
|
"The parameter file has no valid content");
|
||||||
}
|
}
|
||||||
this.setCurrentValue(nField.get(random.nextInt(nField.size())
|
this.setCurrentValue(nField.get(getNextIndex(nField.size())
|
||||||
% nField.size()));
|
% nField.size()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected int getNextIndex(int size) {
|
||||||
|
int result = 0;
|
||||||
|
switch (this.getPickOrder()) {
|
||||||
|
case RANDOM:
|
||||||
|
result = new Random().nextInt(size);
|
||||||
|
break;
|
||||||
|
case SEQUENTIAL:
|
||||||
|
result = this.getLastIndex() + 1;
|
||||||
|
break;
|
||||||
|
case UNIQUE:
|
||||||
|
result = this.getLastIndex() + 1;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
this.setLastIndex(result);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -247,4 +247,9 @@ public class Para_Table extends BasePara {
|
||||||
public String getCurrentValue() {
|
public String getCurrentValue() {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected int getNextIndex(int size) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,31 +1,22 @@
|
||||||
package org.bench4q.agent.parameterization.impl;
|
package org.bench4q.agent.parameterization.impl;
|
||||||
|
|
||||||
import java.lang.reflect.Constructor;
|
import java.lang.reflect.Constructor;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
|
||||||
|
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
import org.bench4q.agent.Main;
|
|
||||||
import org.bench4q.agent.helper.ApplicationContextHelper;
|
import org.bench4q.agent.helper.ApplicationContextHelper;
|
||||||
import org.bench4q.agent.helper.ClassHelper;
|
import org.bench4q.agent.helper.ClassHelper;
|
||||||
import org.bench4q.agent.helper.ClassLoadRestriction;
|
import org.bench4q.agent.helper.ClassLoadRestriction;
|
||||||
import org.bench4q.agent.parameterization.ParameterizedClass;
|
import org.bench4q.agent.parameterization.ParameterizedClass;
|
||||||
import org.bench4q.agent.parameterization.PickOrder;
|
import org.bench4q.agent.parameterization.PickOrder;
|
||||||
import org.bench4q.agent.parameterization.SessionObject;
|
|
||||||
import org.bench4q.agent.parameterization.UpdateStrategy;
|
import org.bench4q.agent.parameterization.UpdateStrategy;
|
||||||
import org.bench4q.agent.parameterization.UpdateStrategy.UpdateRestriction;
|
import org.bench4q.agent.parameterization.UpdateStrategy.UpdateRestriction;
|
||||||
import org.bench4q.agent.scenario.DefinedParameter;
|
import org.bench4q.agent.scenario.DefinedParameter;
|
||||||
|
|
||||||
public class ParameterizationManager {
|
public class ParameterizationManager {
|
||||||
private static final String PARAMETER_PACKAGE = "org.bench4q.agent.parameterization.impl";
|
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, Class<?>> paraClasses;
|
||||||
private Map<String, Object> parameterMap;
|
|
||||||
private ClassHelper classHelper;
|
private ClassHelper classHelper;
|
||||||
|
|
||||||
private UUID testId;
|
private UUID testId;
|
||||||
|
@ -46,14 +37,6 @@ public class ParameterizationManager {
|
||||||
this.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() {
|
private Map<String, Class<?>> getParaClasses() {
|
||||||
return paraClasses;
|
return paraClasses;
|
||||||
}
|
}
|
||||||
|
@ -82,62 +65,10 @@ public class ParameterizationManager {
|
||||||
public ParameterizationManager(UUID testId, int parameterCount) {
|
public ParameterizationManager(UUID testId, int parameterCount) {
|
||||||
this();
|
this();
|
||||||
this.setTestId(testId);
|
this.setTestId(testId);
|
||||||
this.setParameterMap(new HashMap<String, Object>(parameterCount));
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public SessionObject buildVUserContext() {
|
|
||||||
return new VUserContext(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void cleanUp() {
|
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();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -150,23 +81,25 @@ public class ParameterizationManager {
|
||||||
DefinedParameter[] definedParameters,
|
DefinedParameter[] definedParameters,
|
||||||
UpdateRestriction updateRestriction) {
|
UpdateRestriction updateRestriction) {
|
||||||
Map<String, BasePara> result = new LinkedHashMap<String, BasePara>();
|
Map<String, BasePara> result = new LinkedHashMap<String, BasePara>();
|
||||||
if (definedParameters == null || definedParameters.length == 0) {
|
// TODO: initial it
|
||||||
|
int currentIndex = -1;
|
||||||
|
if (definedParameters == null
|
||||||
|
|| definedParameters.length == currentIndex) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
for (DefinedParameter definedParameter : definedParameters) {
|
for (DefinedParameter definedParameter : definedParameters) {
|
||||||
try {
|
try {
|
||||||
UpdateStrategy updateStrategy = UpdateStrategy
|
if (!updateRestriction.isSatisfiedBy(UpdateStrategy
|
||||||
.valueOf(definedParameter.getUpdateStrategy());
|
.valueOf(definedParameter.getUpdateStrategy()))) {
|
||||||
PickOrder pickOrder = PickOrder.valueOf(definedParameter
|
|
||||||
.getPickOrder());
|
|
||||||
if (!updateRestriction.isSatisfiedBy(updateStrategy)) {
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
result.put(
|
result.put(
|
||||||
definedParameter.getName(),
|
definedParameter.getName(),
|
||||||
createInstanceWith(definedParameter.getType(),
|
createInstanceWith(definedParameter.getType(),
|
||||||
definedParameter.getName(), pickOrder,
|
definedParameter.getName(),
|
||||||
updateStrategy));
|
definedParameter.getPickOrder(),
|
||||||
|
definedParameter.getUpdateStrategy(),
|
||||||
|
currentIndex));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Logger.getLogger(ParameterizationManager.class).error(e, e);
|
Logger.getLogger(ParameterizationManager.class).error(e, e);
|
||||||
}
|
}
|
||||||
|
@ -174,54 +107,25 @@ public class ParameterizationManager {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean createParaInstanceWith(DefinedParameter definedParameter) {
|
public BasePara createInstanceWith(String className, String paramName,
|
||||||
try {
|
String pickOrder, String updateStrategy, int currentIndex) {
|
||||||
this.getParameterMap().put(
|
|
||||||
definedParameter.getName(),
|
|
||||||
createInstanceWith(definedParameter.getType(),
|
|
||||||
definedParameter.getName(), PickOrder
|
|
||||||
.valueOf(definedParameter.getPickOrder()),
|
|
||||||
UpdateStrategy.valueOf(definedParameter
|
|
||||||
.getUpdateStrategy())));
|
|
||||||
|
|
||||||
return true;
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private BasePara createInstanceWith(String className, String paramName,
|
|
||||||
PickOrder pickOrder, UpdateStrategy updateStrategy) {
|
|
||||||
if (!this.getParaClasses().containsKey(className)) {
|
if (!this.getParaClasses().containsKey(className)) {
|
||||||
throw new NullPointerException("There's no class with " + className);
|
throw new NullPointerException("There's no class with " + className);
|
||||||
}
|
}
|
||||||
Class<?> clazz = this.getParaClasses().get(className);
|
Class<?> clazz = this.getParaClasses().get(className);
|
||||||
try {
|
try {
|
||||||
Constructor<?> constructor = clazz.getConstructor(UUID.class,
|
Constructor<?> constructor = clazz.getConstructor(UUID.class,
|
||||||
PickOrder.class, UpdateStrategy.class, String.class);
|
PickOrder.class, UpdateStrategy.class, String.class,
|
||||||
|
int.class);
|
||||||
return (BasePara) constructor.newInstance(this.getTestId(),
|
return (BasePara) constructor.newInstance(this.getTestId(),
|
||||||
pickOrder, updateStrategy, paramName);
|
PickOrder.valueOf(pickOrder),
|
||||||
|
UpdateStrategy.valueOf(updateStrategy), paramName,
|
||||||
|
currentIndex);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new NullPointerException(
|
throw new NullPointerException(
|
||||||
"There's no constructor with four params whose className is "
|
"There's no constructor with five params whose className is "
|
||||||
+ className);
|
+ className);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @param paramName
|
|
||||||
* @return the currentValue of the parameter
|
|
||||||
* @throws NullPointerException
|
|
||||||
* if not find the parameter with name paramName
|
|
||||||
*/
|
|
||||||
public String getParameterValue(String paramName) {
|
|
||||||
if (!this.getParameterMap().containsKey(paramName)) {
|
|
||||||
throw new NullPointerException("There is not parameter with name "
|
|
||||||
+ paramName);
|
|
||||||
}
|
|
||||||
BasePara para = (BasePara) this.getParameterMap().get(paramName);
|
|
||||||
return para.getCurrentValue();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,210 +0,0 @@
|
||||||
package org.bench4q.agent.parameterization.impl;
|
|
||||||
|
|
||||||
import java.lang.reflect.InvocationTargetException;
|
|
||||||
import java.lang.reflect.Method;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.UUID;
|
|
||||||
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
|
||||||
import org.apache.log4j.Logger;
|
|
||||||
import org.bench4q.agent.Main;
|
|
||||||
import org.bench4q.agent.parameterization.SessionObject;
|
|
||||||
|
|
||||||
public class VUserContext implements SessionObject {
|
|
||||||
private UUID id = UUID.randomUUID();
|
|
||||||
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>();
|
|
||||||
private Map<String, Object> cacheObjMap = new HashMap<String, Object>();
|
|
||||||
private ReentrantReadWriteLock mapRWLock = new ReentrantReadWriteLock();
|
|
||||||
private Logger logger = Logger.getLogger(VUserContext.class);
|
|
||||||
|
|
||||||
private ParameterizationManager getParamterFactory() {
|
|
||||||
return paramterFactory;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void setParamterFactory(ParameterizationManager paramterFactory) {
|
|
||||||
this.paramterFactory = paramterFactory;
|
|
||||||
}
|
|
||||||
|
|
||||||
private VUserContext() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public VUserContext(ParameterizationManager parameterizationManager) {
|
|
||||||
this();
|
|
||||||
this.setParamterFactory(parameterizationManager);
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getParameter(ParamFormatParser paraFormat) {
|
|
||||||
String result = this.getParameterByContext(paraFormat.getName());
|
|
||||||
if (result != null)
|
|
||||||
return result;
|
|
||||||
String[] argsArray = paraFormat.getArgsArray();
|
|
||||||
if (paraFormat.getParamType().equals("crossThread")) {
|
|
||||||
result = this.getParameterCrossThread(paraFormat.getName(),
|
|
||||||
paraFormat.getClassName(), paraFormat.getMethodName(),
|
|
||||||
argsArray);
|
|
||||||
} else if (paraFormat.getParamType().equals("inThread")) {
|
|
||||||
result = this.getParameterInThread(paraFormat.getName(),
|
|
||||||
ParamFormatParser.buildFullPath(paraFormat.getClassName()),
|
|
||||||
paraFormat.getMethodName(), argsArray);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getParameterInThread(String name, String className,
|
|
||||||
String functionName, Object[] args) {
|
|
||||||
boolean hasThisClass = false;
|
|
||||||
mapRWLock.readLock().lock();
|
|
||||||
hasThisClass = objMap.containsKey(className);
|
|
||||||
mapRWLock.readLock().unlock();
|
|
||||||
if (false == hasThisClass) {
|
|
||||||
createObj(className);
|
|
||||||
}
|
|
||||||
Object instance = getObj(className);
|
|
||||||
Object result = null;
|
|
||||||
try {
|
|
||||||
Class<?>[] argTypeArr = new Class<?>[args.length + 2];
|
|
||||||
Object[] totalArgs = prepareTypeArrayAndArgArray(args, argTypeArr);
|
|
||||||
Method m = instance.getClass().getMethod(functionName, argTypeArr);
|
|
||||||
result = m.invoke(instance, totalArgs);
|
|
||||||
} catch (Exception ex) {
|
|
||||||
System.out.println(ex.getMessage() + ex.getStackTrace());
|
|
||||||
System.out.println(((InvocationTargetException) ex)
|
|
||||||
.getTargetException().getMessage());
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
runtimeParamMap.put(name, (String) result);
|
|
||||||
return (String) result;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getParameterByContext(String name) {
|
|
||||||
if (false == this.runtimeParamMap.containsKey(name)) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return runtimeParamMap.get(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean createObj(String className) {
|
|
||||||
try {
|
|
||||||
UserDefinedClassLoader classLoader = new UserDefinedClassLoader(
|
|
||||||
Main.USER_DEFINED_PARAMS_FOLDER);
|
|
||||||
Class<?> cls = classLoader.loadClass(className);
|
|
||||||
Object instance = cls.newInstance();
|
|
||||||
mapRWLock.writeLock().lock();
|
|
||||||
objMap.put(className, instance);
|
|
||||||
} catch (Exception ex) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
mapRWLock.writeLock().unlock();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private Object getObj(String className) {
|
|
||||||
Object result = null;
|
|
||||||
mapRWLock.readLock().lock();
|
|
||||||
objMap.get(className);
|
|
||||||
mapRWLock.readLock().unlock();
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getParameterCrossThread(String name, String className,
|
|
||||||
String functionName, Object[] args) {
|
|
||||||
try {
|
|
||||||
Object instance = this.getParamterFactory().getObjWithGuardExist(
|
|
||||||
className);
|
|
||||||
Class<?>[] argTypeArr = new Class<?>[args.length + 2];
|
|
||||||
Object[] totalArgs = prepareTypeArrayAndArgArray(args, argTypeArr);
|
|
||||||
Method m = instance.getClass().getMethod(functionName, argTypeArr);
|
|
||||||
Object result = m.invoke(instance, totalArgs);
|
|
||||||
fillToContext(name, className, result);
|
|
||||||
return (String) result;
|
|
||||||
} catch (Exception ex) {
|
|
||||||
logger.error(ex, ex);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void fillToContext(String name, String className, Object result) {
|
|
||||||
usedClassName.add(className);
|
|
||||||
runtimeParamMap.put(name, (String) result);
|
|
||||||
}
|
|
||||||
|
|
||||||
private Object[] prepareTypeArrayAndArgArray(Object[] args,
|
|
||||||
Class<?>[] argTypeArr) {
|
|
||||||
argTypeArr[0] = this.id.getClass();
|
|
||||||
argTypeArr[1] = this.cacheObjMap.getClass();
|
|
||||||
|
|
||||||
for (int i = 2; i < args.length + 2; i++) {
|
|
||||||
argTypeArr[i] = args[i - 2].getClass();
|
|
||||||
}
|
|
||||||
|
|
||||||
Object[] totalArgs = new Object[args.length + 2];
|
|
||||||
totalArgs[0] = id;
|
|
||||||
totalArgs[1] = this.cacheObjMap;
|
|
||||||
for (int i = 2; i < args.length + 2; i++) {
|
|
||||||
totalArgs[i] = args[i - 2];
|
|
||||||
}
|
|
||||||
return totalArgs;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Implement SessionObject begin
|
|
||||||
*/
|
|
||||||
|
|
||||||
public String getParam(String name) {
|
|
||||||
if (!isParamStyle(name))
|
|
||||||
return name;
|
|
||||||
return this.getParameter(ParamFormatParser.parseInputParameter(name));
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean isParamStyle(String name) {
|
|
||||||
return name.startsWith("<parameters") && name.endsWith("/>");
|
|
||||||
}
|
|
||||||
|
|
||||||
public void saveRuntimeParam(String name, String value) {
|
|
||||||
runtimeParamMap.put(name, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void saveRuntimeParams(Map<String, String> runTimeParams) {
|
|
||||||
runtimeParamMap.putAll(runTimeParams);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void doCleanUp() {
|
|
||||||
this.releaseAll();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Implement SessionObject end
|
|
||||||
*/
|
|
||||||
|
|
||||||
private void releaseAll() {
|
|
||||||
for (String xx : usedClassName) {
|
|
||||||
release(xx);
|
|
||||||
}
|
|
||||||
this.getParamterFactory().cleanUp();
|
|
||||||
cleanUp();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void cleanUp() {
|
|
||||||
this.cacheObjMap.clear();
|
|
||||||
this.objMap.clear();
|
|
||||||
this.runtimeParamMap.clear();
|
|
||||||
this.usedClassName.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void release(String className) {
|
|
||||||
try {
|
|
||||||
Object instance = this.getParamterFactory().getObjWithGuardExist(
|
|
||||||
className);
|
|
||||||
Method m = instance.getClass().getMethod("unreg", id.getClass());
|
|
||||||
m.invoke(instance, id);
|
|
||||||
} catch (Exception ex) {
|
|
||||||
System.out.println("realse failed");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -21,14 +21,15 @@ import org.bench4q.agent.parameterization.impl.VuserContextNew;
|
||||||
|
|
||||||
public class ScenarioContext {
|
public class ScenarioContext {
|
||||||
private static final long keepAliveTime = 10;
|
private static final long keepAliveTime = 10;
|
||||||
Map<String, BasePara> updateOnceParameters;
|
private Map<String, BasePara> updateOnceParameters;
|
||||||
|
private Map<String, BasePara> updateEachIterationParameters;
|
||||||
private Date startDate;
|
private Date startDate;
|
||||||
private Date endDate;
|
private Date endDate;
|
||||||
private ThreadPoolExecutor executor;
|
private ThreadPoolExecutor executor;
|
||||||
private Scenario scenario;
|
private Scenario scenario;
|
||||||
private boolean finished;
|
private boolean finished;
|
||||||
private DataCollector dataStatistics;
|
private DataCollector dataStatistics;
|
||||||
private ParameterizationManager parameterFactory;
|
private ParameterizationManager parameterizationManager;
|
||||||
|
|
||||||
public Date getStartDate() {
|
public Date getStartDate() {
|
||||||
return startDate;
|
return startDate;
|
||||||
|
@ -78,12 +79,13 @@ public class ScenarioContext {
|
||||||
this.dataStatistics = dataStatistics;
|
this.dataStatistics = dataStatistics;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ParameterizationManager getParameterFactory() {
|
public ParameterizationManager getParameterManager() {
|
||||||
return parameterFactory;
|
return parameterizationManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setParameterFactory(ParameterizationManager parameterFactory) {
|
private void setParameterManager(
|
||||||
this.parameterFactory = parameterFactory;
|
ParameterizationManager parameterizationManager) {
|
||||||
|
this.parameterizationManager = parameterizationManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Map<String, BasePara> getUpdateOnceParameters() {
|
private Map<String, BasePara> getUpdateOnceParameters() {
|
||||||
|
@ -95,8 +97,18 @@ public class ScenarioContext {
|
||||||
this.updateOnceParameters = updateOnceParameters;
|
this.updateOnceParameters = updateOnceParameters;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Map<String, BasePara> getUpdateEachIterationParameters() {
|
||||||
|
return updateEachIterationParameters;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setUpdateEachIterationParameters(
|
||||||
|
Map<String, BasePara> updateEachIterationParameters) {
|
||||||
|
this.updateEachIterationParameters = updateEachIterationParameters;
|
||||||
|
}
|
||||||
|
|
||||||
private ScenarioContext() {
|
private ScenarioContext() {
|
||||||
this.setUpdateOnceParameters(new HashMap<String, BasePara>());
|
this.setUpdateOnceParameters(new LinkedHashMap<String, BasePara>());
|
||||||
|
this.setUpdateEachIterationParameters(new LinkedHashMap<String, BasePara>());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ScenarioContext buildScenarioContext(UUID testId,
|
public static ScenarioContext buildScenarioContext(UUID testId,
|
||||||
|
@ -110,7 +122,7 @@ public class ScenarioContext {
|
||||||
scenarioContext.setStartDate(new Date(System.currentTimeMillis()));
|
scenarioContext.setStartDate(new Date(System.currentTimeMillis()));
|
||||||
scenarioContext.setExecutorService(executor);
|
scenarioContext.setExecutorService(executor);
|
||||||
scenarioContext.setDataStatistics(new ScenarioResultCollector(testId));
|
scenarioContext.setDataStatistics(new ScenarioResultCollector(testId));
|
||||||
scenarioContext.setParameterFactory(new ParameterizationManager(testId,
|
scenarioContext.setParameterManager(new ParameterizationManager(testId,
|
||||||
scenario.getDefinedParameters().length));
|
scenario.getDefinedParameters().length));
|
||||||
scenarioContext.initForUpdateOnce();
|
scenarioContext.initForUpdateOnce();
|
||||||
return scenarioContext;
|
return scenarioContext;
|
||||||
|
@ -123,17 +135,42 @@ public class ScenarioContext {
|
||||||
|
|
||||||
private Map<String, BasePara> initForParameterization(
|
private Map<String, BasePara> initForParameterization(
|
||||||
UpdateRestriction updateRestriction) {
|
UpdateRestriction updateRestriction) {
|
||||||
|
Map<String, BasePara> result = new LinkedHashMap<String, BasePara>();
|
||||||
if (scenario.getDefinedParameters() == null)
|
if (scenario.getDefinedParameters() == null)
|
||||||
return new LinkedHashMap<String, BasePara>();
|
return new LinkedHashMap<String, BasePara>();
|
||||||
|
for (DefinedParameter definedParameter : this.getScenario()
|
||||||
|
.getDefinedParameters()) {
|
||||||
|
if (!updateRestriction.isSatisfiedBy(UpdateStrategy
|
||||||
|
.valueOf(definedParameter.getUpdateStrategy()))) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
BasePara parameter = this.getParameterManager().createInstanceWith(
|
||||||
|
definedParameter.getType(), definedParameter.getName(),
|
||||||
|
definedParameter.getPickOrder(),
|
||||||
|
definedParameter.getUpdateStrategy(),
|
||||||
|
getParameterLastIndex(definedParameter));
|
||||||
|
result.put(definedParameter.getName(), parameter);
|
||||||
|
}
|
||||||
|
|
||||||
return this.getParameterFactory().createParaInstancesWith(
|
return result;
|
||||||
scenario.getDefinedParameters(), updateRestriction);
|
}
|
||||||
|
|
||||||
|
private int getParameterLastIndex(DefinedParameter definedParameter) {
|
||||||
|
return this.getUpdateEachIterationParameters().containsKey(
|
||||||
|
definedParameter.getName()) ? this
|
||||||
|
.getUpdateEachIterationParameters()
|
||||||
|
.get(definedParameter.getName()).getLastIndex() : -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SessionObject buildVUserContext() {
|
public SessionObject buildVUserContext() {
|
||||||
Map<String, BasePara> initParameters = new HashMap<String, BasePara>();
|
Map<String, BasePara> initParameters = new HashMap<String, BasePara>();
|
||||||
initParameters.putAll(getUpdateOnceParameters());
|
initParameters.putAll(getUpdateOnceParameters());
|
||||||
initParameters.putAll(initForUpdateEachIteration());
|
Map<String, BasePara> initForUpdateEachIteration = initForUpdateEachIteration();
|
||||||
|
initParameters.putAll(initForUpdateEachIteration);
|
||||||
|
this.getUpdateEachIterationParameters().putAll(
|
||||||
|
initForUpdateEachIteration);
|
||||||
|
initParameters
|
||||||
|
.putAll(initForParameterization(new UpdateStrategy.OccurrenceRestriction()));
|
||||||
VuserContextNew vuserContextNew = new VuserContextNew(initParameters);
|
VuserContextNew vuserContextNew = new VuserContextNew(initParameters);
|
||||||
return vuserContextNew;
|
return vuserContextNew;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,66 +0,0 @@
|
||||||
package org.bench4q.agent.test.parameterization;
|
|
||||||
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
import org.bench4q.agent.parameterization.impl.VUserContext;
|
|
||||||
import org.bench4q.agent.parameterization.impl.ParameterizationManager;
|
|
||||||
import org.bench4q.share.helper.TestHelper;
|
|
||||||
|
|
||||||
public class TEST_HelloThread extends Thread {
|
|
||||||
VUserContext ic;
|
|
||||||
|
|
||||||
public TEST_HelloThread() {
|
|
||||||
UUID testId = UUID.randomUUID();
|
|
||||||
ic = new VUserContext(new ParameterizationManager(testId, 4));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void run() {
|
|
||||||
java.util.Random r = new java.util.Random();
|
|
||||||
int t = r.nextInt(10000);
|
|
||||||
System.out.print(Thread.currentThread().getId());
|
|
||||||
System.out.println(":" + t);
|
|
||||||
try {
|
|
||||||
Thread.sleep(t);
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
// TODO Auto-generated catch block
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
System.out.print(Thread.currentThread().getId());
|
|
||||||
System.out.print("\t");
|
|
||||||
|
|
||||||
String userName = ic
|
|
||||||
.getParam("<parameters class=\"Para_UserNameAndPassword\" method=\"getUserName\" args=\"\" />");
|
|
||||||
String passwordName = ic
|
|
||||||
.getParam("<parameters class=\"Para_UserNameAndPassword\" method=\"getPassword\" args=\"\" />");
|
|
||||||
System.out.print(userName);
|
|
||||||
System.out.print("\t");
|
|
||||||
System.out.println(passwordName);
|
|
||||||
try {
|
|
||||||
Thread.sleep(r.nextInt(10000));
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
// TODO Auto-generated catch block
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
// ic.releaseAll();
|
|
||||||
try {
|
|
||||||
TestHelper.invokePrivate(ic, "releaseAll", null, null);
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
while (true) {
|
|
||||||
TEST_HelloThread h1 = new TEST_HelloThread();
|
|
||||||
|
|
||||||
h1.start();
|
|
||||||
try {
|
|
||||||
Thread.sleep(1000);
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -28,30 +28,6 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||||
@ContextConfiguration(locations = { "classpath:application-context.xml" })
|
@ContextConfiguration(locations = { "classpath:application-context.xml" })
|
||||||
public class Test_ParameterManager {
|
public class Test_ParameterManager {
|
||||||
|
|
||||||
@Test
|
|
||||||
public void test_createParaInstanceWith() throws Exception {
|
|
||||||
UUID testId = UUID.randomUUID();
|
|
||||||
String paramName = "param1";
|
|
||||||
ParameterizationManager parameterizationManager = new ParameterizationManager(
|
|
||||||
testId, 1);
|
|
||||||
createFileAndWriteContent(testId, paramName);
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
Map<String, Object> parameterMapBeforeCreate = (Map<String, Object>) TestHelper
|
|
||||||
.invokePrivate(parameterizationManager, "getParameterMap",
|
|
||||||
null, null);
|
|
||||||
assertEquals(0, parameterMapBeforeCreate.size());
|
|
||||||
|
|
||||||
assertTrue(parameterizationManager
|
|
||||||
.createParaInstanceWith(new DefinedParameter(paramName,
|
|
||||||
"Para_File", PickOrder.SEQUENTIAL.name(),
|
|
||||||
UpdateStrategy.ONCE.name())));
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
Map<String, Object> parameterMapAfterCreate = (Map<String, Object>) TestHelper
|
|
||||||
.invokePrivate(parameterizationManager, "getParameterMap",
|
|
||||||
null, null);
|
|
||||||
assertEquals(1, parameterMapAfterCreate.size());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test_createParaInstancesWith_Null() throws IOException {
|
public void test_createParaInstancesWith_Null() throws IOException {
|
||||||
UUID testId = UUID.randomUUID();
|
UUID testId = UUID.randomUUID();
|
||||||
|
@ -66,21 +42,17 @@ public class Test_ParameterManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test_createParaInstancesWith_ONCE() throws IOException {
|
public void test_createParaInstanceWith_ONCE() throws IOException {
|
||||||
UUID testId = UUID.randomUUID();
|
UUID testId = UUID.randomUUID();
|
||||||
final String paramName = "param1";
|
final String paramName = "param1";
|
||||||
ParameterizationManager parameterizationManager = new ParameterizationManager(
|
ParameterizationManager parameterizationManager = new ParameterizationManager(
|
||||||
testId, 1);
|
testId, 1);
|
||||||
createFileAndWriteContent(testId, paramName);
|
createFileAndWriteContent(testId, paramName);
|
||||||
Map<String, BasePara> parameterMap = parameterizationManager
|
BasePara param = parameterizationManager.createInstanceWith(
|
||||||
.createParaInstancesWith(
|
"Para_File", paramName, PickOrder.SEQUENTIAL.toString(),
|
||||||
new DefinedParameter[] { new DefinedParameter(
|
UpdateStrategy.ONCE.toString(), -1);
|
||||||
paramName, "Para_File", PickOrder.SEQUENTIAL
|
assertNotNull(param);
|
||||||
.toString(), UpdateStrategy.ONCE
|
assertEquals("12", param.getCurrentValue());
|
||||||
.toString()) },
|
|
||||||
new UpdateStrategy.OnceRestriction());
|
|
||||||
assertEquals(1, parameterMap.size());
|
|
||||||
assertEquals("12", parameterMap.get(paramName).getCurrentValue());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -114,6 +86,11 @@ public class Test_ParameterManager {
|
||||||
public String getCurrentValue() {
|
public String getCurrentValue() {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected int getNextIndex(int size) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
}).getParamFileFullPath(paramName));
|
}).getParamFileFullPath(paramName));
|
||||||
TestHelper.createFileIfNotExist(paramFile);
|
TestHelper.createFileIfNotExist(paramFile);
|
||||||
FileUtils.writeStringToFile(paramFile, "12;13;14;15");
|
FileUtils.writeStringToFile(paramFile, "12;13;14;15");
|
||||||
|
@ -144,6 +121,24 @@ public class Test_ParameterManager {
|
||||||
assertNotEquals(v1_firstValue, v2_firstValue);
|
assertNotEquals(v1_firstValue, v2_firstValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test_createParaInstanceWith_UpdateStrategy_EACH_OCCURRENCE()
|
||||||
|
throws IOException {
|
||||||
|
UUID testId = UUID.randomUUID();
|
||||||
|
String paramName = "param1";
|
||||||
|
createFileAndWriteContent(testId, paramName);
|
||||||
|
Scenario scenario = Scenario
|
||||||
|
.scenarioBuilder(buildATestScenarioModelWith(new DefinedParameter(
|
||||||
|
paramName, "Para_File", PickOrder.SEQUENTIAL.name(),
|
||||||
|
UpdateStrategy.EACH_OCCURRENCE.name())));
|
||||||
|
ScenarioContext scenarioContext = ScenarioContext.buildScenarioContext(
|
||||||
|
testId, scenario, 1);
|
||||||
|
VUser vUser = new VUser(scenarioContext);
|
||||||
|
String vuserFirstValue = vUser.getParam(paramName);
|
||||||
|
String vuserSecondeValue = vUser.getParam(paramName);
|
||||||
|
assertNotEquals(vuserFirstValue, vuserSecondeValue);
|
||||||
|
}
|
||||||
|
|
||||||
private RunScenarioModel buildATestScenarioModelWith(
|
private RunScenarioModel buildATestScenarioModelWith(
|
||||||
DefinedParameter definedParameter) {
|
DefinedParameter definedParameter) {
|
||||||
RunScenarioModel runScenarioModel = new RunScenarioModel();
|
RunScenarioModel runScenarioModel = new RunScenarioModel();
|
||||||
|
|
|
@ -10,10 +10,7 @@ import java.util.UUID;
|
||||||
import org.apache.commons.io.FileUtils;
|
import org.apache.commons.io.FileUtils;
|
||||||
import org.bench4q.agent.parameterization.PickOrder;
|
import org.bench4q.agent.parameterization.PickOrder;
|
||||||
import org.bench4q.agent.parameterization.UpdateStrategy;
|
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.Para_Table;
|
||||||
import org.bench4q.agent.parameterization.impl.ParamFormatParser;
|
|
||||||
import org.bench4q.agent.parameterization.impl.ParameterizationManager;
|
|
||||||
import org.bench4q.share.helper.TestHelper;
|
import org.bench4q.share.helper.TestHelper;
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
@ -28,7 +25,9 @@ public class Test_VUserContext {
|
||||||
// private static final String NEW_TEST_CASE =
|
// private static final String NEW_TEST_CASE =
|
||||||
// "<parameters name=\"useNamePassword\" class=\"Para_Table\" type=\"crossThread\" method=\"getTableColumnValue\" args=\"file;ScenarioParameters\\param1.txt;0;sequence;\\;;~;2\" />";
|
// "<parameters name=\"useNamePassword\" class=\"Para_Table\" type=\"crossThread\" method=\"getTableColumnValue\" args=\"file;ScenarioParameters\\param1.txt;0;sequence;\\;;~;2\" />";
|
||||||
private static final String file_CONTENT = "row1;10;11~row2;20;21~row3,30,31~";
|
private static final String file_CONTENT = "row1;10;11~row2;20;21~row3,30,31~";
|
||||||
private static final String Test_CASE1 = "<parameters name=\"param1\" class=\"Para_Table\" type=\"crossThread\" method=\"getTableColumnValue\" args=\"param1;0;sequence;\\;;~;2\" />";
|
|
||||||
|
// private static final String Test_CASE1 =
|
||||||
|
// "<parameters name=\"param1\" class=\"Para_Table\" type=\"crossThread\" method=\"getTableColumnValue\" args=\"param1;0;sequence;\\;;~;2\" />";
|
||||||
|
|
||||||
@After
|
@After
|
||||||
public void cleanUp() {
|
public void cleanUp() {
|
||||||
|
@ -55,68 +54,68 @@ public class Test_VUserContext {
|
||||||
FileUtils.writeStringToFile(file, file_CONTENT);
|
FileUtils.writeStringToFile(file, file_CONTENT);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
// @Test
|
||||||
public void testGetParam2() throws Exception {
|
// public void testGetParam2() throws Exception {
|
||||||
UUID testId = UUID.randomUUID();
|
// UUID testId = UUID.randomUUID();
|
||||||
ParameterizationManager parametersFactory = new ParameterizationManager(
|
// ParameterizationManager parametersFactory = new ParameterizationManager(
|
||||||
testId, 4);
|
// testId, 4);
|
||||||
VUserContext ic = new VUserContext(parametersFactory);
|
// VUserContext ic = new VUserContext(parametersFactory);
|
||||||
createParamFileFor(new Para_Table(testId, PickOrder.SEQUENTIAL,
|
// createParamFileFor(new Para_Table(testId, PickOrder.SEQUENTIAL,
|
||||||
UpdateStrategy.EACH_ITERATION).getParamFileFullPath("param1"));
|
// UpdateStrategy.EACH_ITERATION).getParamFileFullPath("param1"));
|
||||||
String passwordName = ic.getParam(Test_CASE1);
|
// String passwordName = ic.getParam(Test_CASE1);
|
||||||
System.out.println(passwordName);
|
// System.out.println(passwordName);
|
||||||
assertNotNull(passwordName);
|
// assertNotNull(passwordName);
|
||||||
assertEquals(11, Integer.parseInt(passwordName));
|
// assertEquals(11, Integer.parseInt(passwordName));
|
||||||
|
//
|
||||||
VUserContext ic2 = new VUserContext(parametersFactory);
|
// VUserContext ic2 = new VUserContext(parametersFactory);
|
||||||
String password2 = ic2.getParam(Test_CASE1);
|
// String password2 = ic2.getParam(Test_CASE1);
|
||||||
System.out.println(password2);
|
// System.out.println(password2);
|
||||||
assertNotNull(password2);
|
// assertNotNull(password2);
|
||||||
assertEquals(Integer.parseInt(passwordName) + 10,
|
// assertEquals(Integer.parseInt(passwordName) + 10,
|
||||||
Integer.parseInt(password2));
|
// Integer.parseInt(password2));
|
||||||
ic.doCleanUp();
|
// ic.doCleanUp();
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
@Test
|
// @Test
|
||||||
public void testGetParamWithUpdateOnEachOccurrence() {
|
// public void testGetParamWithUpdateOnEachOccurrence() {
|
||||||
|
//
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
@Test
|
// @Test
|
||||||
public void testGetParameter() throws Exception {
|
// public void testGetParameter() throws Exception {
|
||||||
UUID testId = UUID.randomUUID();
|
// UUID testId = UUID.randomUUID();
|
||||||
createParamFileFor(new Para_Table(testId, PickOrder.SEQUENTIAL,
|
// createParamFileFor(new Para_Table(testId, PickOrder.SEQUENTIAL,
|
||||||
UpdateStrategy.EACH_ITERATION).getParamFileFullPath("param1"));
|
// UpdateStrategy.EACH_ITERATION).getParamFileFullPath("param1"));
|
||||||
VUserContext paracCoor = new VUserContext(new ParameterizationManager(
|
// VUserContext paracCoor = new VUserContext(new ParameterizationManager(
|
||||||
testId, 4));
|
// testId, 4));
|
||||||
ParamFormatParser paramFormatParser = ParamFormatParser
|
// ParamFormatParser paramFormatParser = ParamFormatParser
|
||||||
.parseInputParameter(Test_CASE1);
|
// .parseInputParameter(Test_CASE1);
|
||||||
String result = (String) TestHelper.invokePrivate(paracCoor,
|
// String result = (String) TestHelper.invokePrivate(paracCoor,
|
||||||
"getParameter", new Class[] { ParamFormatParser.class },
|
// "getParameter", new Class[] { ParamFormatParser.class },
|
||||||
new Object[] { paramFormatParser });
|
// new Object[] { paramFormatParser });
|
||||||
assertEquals("11", result);
|
// assertEquals("11", result);
|
||||||
paracCoor.doCleanUp();
|
// paracCoor.doCleanUp();
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
@Test
|
// @Test
|
||||||
public void testGetParameterCrossThread() throws Exception {
|
// public void testGetParameterCrossThread() throws Exception {
|
||||||
UUID testId = UUID.randomUUID();
|
// UUID testId = UUID.randomUUID();
|
||||||
createParamFileFor(new Para_Table(testId, PickOrder.SEQUENTIAL,
|
// createParamFileFor(new Para_Table(testId, PickOrder.SEQUENTIAL,
|
||||||
UpdateStrategy.EACH_ITERATION).getParamFileFullPath("param1"));
|
// UpdateStrategy.EACH_ITERATION).getParamFileFullPath("param1"));
|
||||||
VUserContext paracCoor = new VUserContext(new ParameterizationManager(
|
// VUserContext paracCoor = new VUserContext(new ParameterizationManager(
|
||||||
testId, 4));
|
// testId, 4));
|
||||||
ParamFormatParser paramFormatParser = ParamFormatParser
|
// ParamFormatParser paramFormatParser = ParamFormatParser
|
||||||
.parseInputParameter(Test_CASE1);
|
// .parseInputParameter(Test_CASE1);
|
||||||
String result = (String) TestHelper.invokePrivate(
|
// String result = (String) TestHelper.invokePrivate(
|
||||||
paracCoor,
|
// paracCoor,
|
||||||
"getParameterCrossThread",
|
// "getParameterCrossThread",
|
||||||
new Class[] { String.class, String.class, String.class,
|
// new Class[] { String.class, String.class, String.class,
|
||||||
Object[].class },
|
// Object[].class },
|
||||||
new Object[] { paramFormatParser.getName(),
|
// new Object[] { paramFormatParser.getName(),
|
||||||
paramFormatParser.getClassName(),
|
// paramFormatParser.getClassName(),
|
||||||
paramFormatParser.getMethodName(),
|
// paramFormatParser.getMethodName(),
|
||||||
paramFormatParser.getArgsArray() });
|
// paramFormatParser.getArgsArray() });
|
||||||
assertEquals("11", result);
|
// assertEquals("11", result);
|
||||||
paracCoor.doCleanUp();
|
// paracCoor.doCleanUp();
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue