refactor and show the parameterization information to master

refactor and show the parameterization information to master
This commit is contained in:
coderfengyun 2014-04-08 16:40:13 +08:00
parent 6307f1c841
commit 0287a5aac3
23 changed files with 351 additions and 519 deletions

View File

@ -1,8 +1,62 @@
package org.bench4q.agent.api;
import java.util.List;
import org.bench4q.agent.parameterization.ParameterizationInfo;
import org.bench4q.agent.parameterization.PickOrder;
import org.bench4q.agent.parameterization.UpdateStrategy;
import org.bench4q.agent.parameterization.impl.ParameterizationManager;
import org.bench4q.share.models.agent.ParameterizationInfoListModel;
import org.bench4q.share.models.agent.ParameterizationInfoModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
public class ParameterizationController {
private ParameterizationManager parameterizationManager;
private ParameterizationManager getParameterizationManager() {
return parameterizationManager;
}
@Autowired
private void setParameterizationManager(
ParameterizationManager parameterizationManager) {
this.parameterizationManager = parameterizationManager;
}
@RequestMapping(value = "/parameterization", method = RequestMethod.GET)
@ResponseBody
public ParameterizationInfoListModel loadParameterization() {
return convertToDTO(this.getParameterizationManager()
.loadParameterizationInfo());
}
private ParameterizationInfoListModel convertToDTO(
List<ParameterizationInfo> parameterizationInfos) {
ParameterizationInfoListModel result = new ParameterizationInfoListModel();
for (ParameterizationInfo parameterizationInfo : parameterizationInfos) {
result.getParameterizationInfoModels().add(
covertToDTO(parameterizationInfo));
}
return result;
}
private ParameterizationInfoModel covertToDTO(
ParameterizationInfo parameterizationInfo) {
ParameterizationInfoModel result = new ParameterizationInfoModel();
for (PickOrder pickOrder : parameterizationInfo
.getPermittedPickOrders()) {
result.getPickOrders().add(pickOrder.name());
}
for (UpdateStrategy updateStrategy : parameterizationInfo
.getPermittedUpdateStrategies()) {
result.getPermittedUpdateStrategies().add(updateStrategy.name());
}
result.setName(parameterizationInfo.getName());
return result;
}
}

View File

@ -0,0 +1,53 @@
package org.bench4q.agent.parameterization;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
public class ParameterizationInfo {
private String name;
private List<PickOrder> permittedPickOrders;
private List<UpdateStrategy> permittedUpdateStrategies;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public List<PickOrder> getPermittedPickOrders() {
return permittedPickOrders;
}
public void setPermittedPickOrders(List<PickOrder> permittedPickOrders) {
this.permittedPickOrders = permittedPickOrders;
}
public List<UpdateStrategy> getPermittedUpdateStrategies() {
return permittedUpdateStrategies;
}
public void setPermittedUpdateStrategies(
List<UpdateStrategy> permittedUpdateStrategies) {
this.permittedUpdateStrategies = permittedUpdateStrategies;
}
public ParameterizationInfo() {
this.setPermittedPickOrders(new LinkedList<PickOrder>());
this.setPermittedUpdateStrategies(new ArrayList<UpdateStrategy>());
}
public ParameterizationInfo(String name, PickOrder[] permittedPickOrders,
UpdateStrategy[] permittedUpdateStrategies) {
this();
this.setName(name);
for (PickOrder pickOrder : permittedPickOrders) {
this.getPermittedPickOrders().add(pickOrder);
}
for (UpdateStrategy updateStrategy : permittedUpdateStrategies) {
this.getPermittedUpdateStrategies().add(updateStrategy);
}
}
}

View File

@ -9,4 +9,8 @@ import java.lang.annotation.Target;
@Retention(RetentionPolicy.RUNTIME)
public @interface ParameterizedClass {
String name();
PickOrder[] permittedPickOrders();
UpdateStrategy[] permittedUpdateStrategies();
}

View File

@ -1,12 +1,18 @@
package org.bench4q.agent.parameterization.impl;
import java.util.Random;
import java.util.UUID;
import org.bench4q.agent.Main;
import org.bench4q.agent.parameterization.PickOrder;
import org.bench4q.agent.parameterization.UpdateStrategy;
public abstract class BasePara {
private UUID testId;
protected int lastIndex;
private String paramName;
private PickOrder pickOrder;
private UpdateStrategy updateStrategy;
private int lastIndex;
protected UUID getTestId() {
return testId;
@ -16,16 +22,45 @@ public abstract class BasePara {
this.testId = testId;
}
protected String getParamName() {
return paramName;
}
private void setParamName(String paramName) {
this.paramName = paramName;
}
protected PickOrder getPickOrder() {
return pickOrder;
}
private void setPickOrder(PickOrder pickOrder) {
this.pickOrder = pickOrder;
}
protected UpdateStrategy getUpdateStrategy() {
return updateStrategy;
}
private void setUpdateStrategy(UpdateStrategy updateStrategy) {
this.updateStrategy = updateStrategy;
}
public int getLastIndex() {
return lastIndex;
}
protected void setLastIndex(int lastIndex) {
private void setLastIndex(int lastIndex) {
this.lastIndex = lastIndex;
}
public BasePara(UUID testId) {
public BasePara(UUID testId, String parameterName,
UpdateStrategy updateStrategy, PickOrder pickOrder, int lastIndex) {
this.setTestId(testId);
this.setParamName(parameterName);
this.setUpdateStrategy(updateStrategy);
this.setPickOrder(pickOrder);
this.setLastIndex(lastIndex);
}
public String getParamFileFullPath(String paramName) {
@ -36,5 +71,22 @@ public abstract class BasePara {
public abstract String getCurrentValue();
protected abstract int getNextIndex(int size);
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;
}
}

View File

@ -1,35 +0,0 @@
package org.bench4q.agent.parameterization.impl;
import java.util.Date;
import java.util.HashMap;
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 {
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() {
}
public String getBeginUser(UUID id) {
return null;
}
}

View File

@ -4,8 +4,10 @@ import java.util.Map;
import java.util.UUID;
import org.bench4q.agent.parameterization.ParameterizedClass;
import org.bench4q.agent.parameterization.PickOrder;
import org.bench4q.agent.parameterization.UpdateStrategy;
@ParameterizedClass(name = "Para_IteratorNumber")
@ParameterizedClass(name = "Para_IteratorNumber", permittedPickOrders = { PickOrder.SEQUENTIAL }, permittedUpdateStrategies = { UpdateStrategy.EACH_ITERATION })
public class Para_IteratorNumber {
public Long iteratorNum = new Long(0);

View File

@ -2,7 +2,6 @@ package org.bench4q.agent.parameterization.impl;
import java.io.File;
import java.util.List;
import java.util.Random;
import java.util.UUID;
import org.apache.commons.io.FileUtils;
@ -11,20 +10,12 @@ import org.bench4q.agent.parameterization.PickOrder;
import org.bench4q.agent.parameterization.UpdateStrategy;
import org.bench4q.agent.utils.ParameterParser;
@ParameterizedClass(name = "Para_File")
public class Para_File extends BasePara {
@ParameterizedClass(name = "Para_List", permittedPickOrders = {
PickOrder.RANDOM, PickOrder.SEQUENTIAL, PickOrder.UNIQUE }, permittedUpdateStrategies = {
UpdateStrategy.EACH_ITERATION, UpdateStrategy.EACH_OCCURRENCE,
UpdateStrategy.ONCE })
public class Para_List extends BasePara {
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() {
if (this.getUpdateStrategy() == UpdateStrategy.EACH_OCCURRENCE) {
@ -37,29 +28,9 @@ public class Para_File extends BasePara {
this.currentValue = currentValue;
}
private PickOrder getPickOrder() {
return pickOrder;
}
private void setPickOrder(PickOrder pickOrder) {
this.pickOrder = pickOrder;
}
private UpdateStrategy getUpdateStrategy() {
return updateStrategy;
}
private void setUpdateStrategy(UpdateStrategy updateStrategy) {
this.updateStrategy = updateStrategy;
}
public Para_File(UUID testId, PickOrder pickOrder,
public Para_List(UUID testId, PickOrder pickOrder,
UpdateStrategy updateStrategy, String paramName, int currentIndex) {
super(testId);
this.setParamName(paramName);
this.setPickOrder(pickOrder);
this.setUpdateStrategy(updateStrategy);
this.setLastIndex(currentIndex);
super(testId, paramName, updateStrategy, pickOrder, currentIndex);
initialValue();
}
@ -81,23 +52,4 @@ public class Para_File extends BasePara {
% 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;
}
}

View File

@ -4,8 +4,12 @@ import java.util.Random;
import java.util.UUID;
import org.bench4q.agent.parameterization.ParameterizedClass;
import org.bench4q.agent.parameterization.PickOrder;
import org.bench4q.agent.parameterization.UpdateStrategy;
@ParameterizedClass(name = "Para_RandomNumber")
@ParameterizedClass(name = "Para_RandomNumber", permittedPickOrders = { PickOrder.RANDOM }, permittedUpdateStrategies = {
UpdateStrategy.EACH_ITERATION, UpdateStrategy.EACH_OCCURRENCE,
UpdateStrategy.ONCE })
public class Para_RandomNumber {
public String getRandomIntegerNumber(UUID id, String begin, String end,

View File

@ -16,17 +16,17 @@ import org.bench4q.agent.parameterization.ParameterizedClass;
import org.bench4q.agent.parameterization.PickOrder;
import org.bench4q.agent.parameterization.UpdateStrategy;
@ParameterizedClass(name = "Para_Table")
@ParameterizedClass(name = "Para_Table", permittedPickOrders = {
PickOrder.RANDOM, PickOrder.SEQUENTIAL, PickOrder.UNIQUE }, permittedUpdateStrategies = {
UpdateStrategy.EACH_ITERATION, UpdateStrategy.EACH_OCCURRENCE })
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, PickOrder pickOrder,
UpdateStrategy updateStrategy) {
// TODO: Use the pickOrder and updateStrategy to create this parameter
super(testId);
UpdateStrategy updateStrategy, String parameterName, int lastIndex) {
super(testId, parameterName, updateStrategy, pickOrder, lastIndex);
}
public abstract class Reader {

View File

@ -3,8 +3,12 @@ package org.bench4q.agent.parameterization.impl;
import java.util.UUID;
import org.bench4q.agent.parameterization.ParameterizedClass;
import org.bench4q.agent.parameterization.PickOrder;
import org.bench4q.agent.parameterization.UpdateStrategy;
@ParameterizedClass(name = "Para_UniqueNumber")
@ParameterizedClass(name = "Para_UniqueNumber", permittedPickOrders = { PickOrder.UNIQUE }, permittedUpdateStrategies = {
UpdateStrategy.EACH_ITERATION, UpdateStrategy.EACH_OCCURRENCE,
UpdateStrategy.ONCE })
public class Para_UniqueNumber {
int currentNumber = 0;

View File

@ -1,124 +0,0 @@
package org.bench4q.agent.parameterization.impl;
import java.util.HashMap;
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/",
"http://www.163.com/", "http://baike.baidu.com/",
"http://zhidao.baidu.com/", "http://www.sina.com.cn/" };
UUID[] useUUID = new UUID[5];
Map<UUID, Integer> posMap = new HashMap<UUID, Integer>();
ReentrantReadWriteLock mapRWLock = new ReentrantReadWriteLock();
ReentrantReadWriteLock idposLock = new ReentrantReadWriteLock();
public String getUserName(UUID id) {
mapRWLock.readLock().lock();
if (posMap.containsKey(id)) {
mapRWLock.readLock().unlock();
return userName[posMap.get(id)];
}
mapRWLock.readLock().unlock();
int vaildPos = -1;
int tryNum = 0;
while (vaildPos < 0 && tryNum < 100) {
tryNum++;
idposLock.readLock().lock();
for (int i = 0; i < 5; i++) {
if (useUUID[i] == null) {
vaildPos = i;
break;
}
}
idposLock.readLock().unlock();
if (vaildPos < 0) {
try {
Thread.sleep(1000);
} catch (Exception ex) {
}
}
}
idposLock.writeLock().lock();
useUUID[vaildPos] = id;
idposLock.writeLock().unlock();
mapRWLock.writeLock().lock();
posMap.put(id, vaildPos);
mapRWLock.writeLock().unlock();
return userName[vaildPos];
}
public String getPassword(UUID id) {
mapRWLock.readLock().lock();
if (posMap.containsKey(id)) {
mapRWLock.readLock().unlock();
return Password[posMap.get(id)];
}
mapRWLock.readLock().unlock();
int vaildPos = -1;
int tryNum = 0;
while (vaildPos < 0 && tryNum < 100) {
tryNum++;
idposLock.readLock().lock();
for (int i = 0; i < 5; i++) {
if (useUUID[i] == null) {
vaildPos = i;
break;
}
}
idposLock.readLock().unlock();
if (vaildPos < 0) {
try {
Thread.sleep(1000);
} catch (Exception ex) {
}
}
}
idposLock.writeLock().lock();
useUUID[vaildPos] = id;
idposLock.writeLock().unlock();
mapRWLock.writeLock().lock();
posMap.put(id, vaildPos);
mapRWLock.writeLock().unlock();
return Password[vaildPos];
}
public void unreg(UUID id) {
try {
// System.out.println("1");
mapRWLock.writeLock().lock();
// System.out.println("2");
int pos = posMap.get(id);
// System.out.println("3");
posMap.remove(id);
// System.out.println("4");
mapRWLock.writeLock().unlock();
// System.out.println("5");
idposLock.writeLock().lock();
// System.out.println("6");
useUUID[pos] = null;
idposLock.writeLock().unlock();
} catch (Exception ex) {
System.out.println(ex.getClass().getName());
System.out.println(ex.getMessage());
System.out.println(ex.getStackTrace());
mapRWLock.writeLock().unlock();
idposLock.writeLock().unlock();
}
}
}

View File

@ -1,100 +0,0 @@
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 ParamFormatParser {
private String name;
private String className;
private String methodName;
private String argsString;
private String paramType;
private List<String> args;
private static String[] argsArray;
@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;
}
private List<String> getArgs() {
return this.args;
}
private void setArgs(List<String> args) {
this.args = args;
}
public String[] getArgsArray() {
if (argsArray == null)
argsArray = this.getArgs().toArray(new String[] {});
return argsArray;
}
private ParamFormatParser() {
}
public static ParamFormatParser parseInputParameter(String inputContent) {
ParamFormatParser result = (ParamFormatParser) MarshalHelper
.tryUnmarshal(ParamFormatParser.class, inputContent);
if (result.isArgsStringLegal())
result.setArgs(ParameterParser.buildNField(result.getArgsString()));
return result;
}
public boolean isArgsStringLegal() {
return !(this.getArgsString() == null || this.getArgsString().isEmpty());
}
static String buildFullPath(String simpleClassName) {
return ParamFormatParser.class.getName().substring(0,
ParamFormatParser.class.getName().lastIndexOf('.'))
+ "." + simpleClassName;
}
}

View File

@ -1,38 +1,32 @@
package org.bench4q.agent.parameterization.impl;
import java.lang.reflect.Constructor;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.UUID;
import org.apache.log4j.Logger;
import org.bench4q.agent.helper.ApplicationContextHelper;
import org.bench4q.agent.helper.ClassHelper;
import org.bench4q.agent.helper.ClassLoadRestriction;
import org.bench4q.agent.parameterization.ParameterizationInfo;
import org.bench4q.agent.parameterization.ParameterizedClass;
import org.bench4q.agent.parameterization.PickOrder;
import org.bench4q.agent.parameterization.UpdateStrategy;
import org.bench4q.agent.parameterization.UpdateStrategy.UpdateRestriction;
import org.bench4q.agent.scenario.DefinedParameter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@Component
public class ParameterizationManager {
private static final String PARAMETER_PACKAGE = "org.bench4q.agent.parameterization.impl";
private Map<String, Class<?>> paraClasses;
private ClassHelper classHelper;
private UUID testId;
private UUID getTestId() {
return testId;
}
private void setTestId(UUID testId) {
this.testId = testId;
}
private ClassHelper getClassHelper() {
return classHelper;
}
@Autowired
private void setClassHelper(ClassHelper classHelper) {
this.classHelper = classHelper;
}
@ -45,9 +39,9 @@ public class ParameterizationManager {
this.paraClasses = paraClasses;
}
public ParameterizationManager() {
this.setClassHelper(ApplicationContextHelper.getContext().getBean(
ClassHelper.class));
@Autowired
public ParameterizationManager(ClassHelper classHelper) {
this.setClassHelper(classHelper);
this.setParaClasses(this.getClassHelper().loadClasses(
PARAMETER_PACKAGE, new ClassLoadRestriction() {
public boolean accept(Class<?> classUnderTest) {
@ -62,53 +56,18 @@ public class ParameterizationManager {
}));
}
public ParameterizationManager(UUID testId, int parameterCount) {
this();
this.setTestId(testId);
}
public void cleanUp() {
}
/**
* For creating parameter with parameterName as the index
*
* @param definedParameter
* @param className
* @param paramName
* @param pickOrder
* @param updateStrategy
* @param currentIndex
* @return
*/
public Map<String, BasePara> createParaInstancesWith(
DefinedParameter[] definedParameters,
UpdateRestriction updateRestriction) {
Map<String, BasePara> result = new LinkedHashMap<String, BasePara>();
// TODO: initial it
int currentIndex = -1;
if (definedParameters == null
|| definedParameters.length == currentIndex) {
return result;
}
for (DefinedParameter definedParameter : definedParameters) {
try {
if (!updateRestriction.isSatisfiedBy(UpdateStrategy
.valueOf(definedParameter.getUpdateStrategy()))) {
continue;
}
result.put(
definedParameter.getName(),
createInstanceWith(definedParameter.getType(),
definedParameter.getName(),
definedParameter.getPickOrder(),
definedParameter.getUpdateStrategy(),
currentIndex));
} catch (Exception e) {
Logger.getLogger(ParameterizationManager.class).error(e, e);
}
}
return result;
}
public BasePara createInstanceWith(String className, String paramName,
String pickOrder, String updateStrategy, int currentIndex) {
public BasePara createInstanceWith(UUID testId, String className,
String paramName, String pickOrder, String updateStrategy,
int currentIndex) {
if (!this.getParaClasses().containsKey(className)) {
throw new NullPointerException("There's no class with " + className);
}
@ -117,7 +76,7 @@ public class ParameterizationManager {
Constructor<?> constructor = clazz.getConstructor(UUID.class,
PickOrder.class, UpdateStrategy.class, String.class,
int.class);
return (BasePara) constructor.newInstance(this.getTestId(),
return (BasePara) constructor.newInstance(testId,
PickOrder.valueOf(pickOrder),
UpdateStrategy.valueOf(updateStrategy), paramName,
currentIndex);
@ -128,4 +87,15 @@ public class ParameterizationManager {
}
}
public List<ParameterizationInfo> loadParameterizationInfo() {
List<ParameterizationInfo> parameterizationInfos = new LinkedList<ParameterizationInfo>();
for (Entry<String, Class<?>> entry : this.getParaClasses().entrySet()) {
ParameterizedClass annotation = entry.getValue().getAnnotation(
ParameterizedClass.class);
parameterizationInfos.add(new ParameterizationInfo(annotation
.name(), annotation.permittedPickOrders(), annotation
.permittedUpdateStrategies()));
}
return parameterizationInfos;
}
}

View File

@ -34,7 +34,7 @@ public class VuserContextNew implements SessionObject {
}
public void doCleanUp() {
this.getStaticParameters().clear();
}
public void saveRuntimeParams(Map<String, String> runTimeParams) {

View File

@ -12,6 +12,7 @@ import java.util.concurrent.ThreadPoolExecutor.DiscardPolicy;
import org.bench4q.agent.datacollector.DataCollector;
import org.bench4q.agent.datacollector.impl.ScenarioResultCollector;
import org.bench4q.agent.helper.ApplicationContextHelper;
import org.bench4q.agent.parameterization.SessionObject;
import org.bench4q.agent.parameterization.UpdateStrategy;
import org.bench4q.agent.parameterization.UpdateStrategy.UpdateRestriction;
@ -23,6 +24,7 @@ public class ScenarioContext {
private static final long keepAliveTime = 10;
private Map<String, BasePara> updateOnceParameters;
private Map<String, BasePara> updateEachIterationParameters;
private UUID testId;
private Date startDate;
private Date endDate;
private ThreadPoolExecutor executor;
@ -31,6 +33,14 @@ public class ScenarioContext {
private DataCollector dataStatistics;
private ParameterizationManager parameterizationManager;
private UUID getTestId() {
return testId;
}
private void setTestId(UUID testId) {
this.testId = testId;
}
public Date getStartDate() {
return startDate;
}
@ -114,6 +124,7 @@ public class ScenarioContext {
public static ScenarioContext buildScenarioContext(UUID testId,
final Scenario scenario, int poolSize) {
ScenarioContext scenarioContext = new ScenarioContext();
scenarioContext.setTestId(testId);
final SynchronousQueue<Runnable> workQueue = new SynchronousQueue<Runnable>();
ThreadPoolExecutor executor = new ThreadPoolExecutor(poolSize,
poolSize, keepAliveTime, TimeUnit.MINUTES, workQueue,
@ -122,8 +133,8 @@ public class ScenarioContext {
scenarioContext.setStartDate(new Date(System.currentTimeMillis()));
scenarioContext.setExecutorService(executor);
scenarioContext.setDataStatistics(new ScenarioResultCollector(testId));
scenarioContext.setParameterManager(new ParameterizationManager(testId,
scenario.getDefinedParameters().length));
scenarioContext.setParameterManager(ApplicationContextHelper
.getContext().getBean(ParameterizationManager.class));
scenarioContext.initForUpdateOnce();
return scenarioContext;
}
@ -145,7 +156,8 @@ public class ScenarioContext {
continue;
}
BasePara parameter = this.getParameterManager().createInstanceWith(
definedParameter.getType(), definedParameter.getName(),
this.getTestId(), definedParameter.getType(),
definedParameter.getName(),
definedParameter.getPickOrder(),
definedParameter.getUpdateStrategy(),
getParameterLastIndex(definedParameter));

View File

@ -1,30 +0,0 @@
package org.bench4q.agent.test.parameterization;
import static org.junit.Assert.*;
import org.bench4q.agent.parameterization.impl.ParamFormatParser;
import org.junit.After;
import org.junit.Test;
public class Test_ParameterFormat {
private static String testcase = "<parameters name=\"useNamePassword\" class=\"Para_Table\" type=\"crossThread\" method=\"getTableColumnValue\" args=\"file;ScenarioParameters\\param1.txt;0;sequence;\\;;~;2\" />";
@After
public void tearDown() throws Exception {
}
@Test
public void test() {
ParamFormatParser format = ParamFormatParser.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.getArgsArray().length);
assertEquals("file", format.getArgsArray()[0]);
assertEquals(";", format.getArgsArray()[4]);
}
}

View File

@ -8,6 +8,8 @@ import java.util.Map;
import java.util.UUID;
import org.apache.commons.io.FileUtils;
import org.bench4q.agent.helper.ApplicationContextHelper;
import org.bench4q.agent.helper.ClassHelper;
import org.bench4q.agent.parameterization.PickOrder;
import org.bench4q.agent.parameterization.UpdateStrategy;
import org.bench4q.agent.parameterization.impl.BasePara;
@ -28,28 +30,16 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@ContextConfiguration(locations = { "classpath:application-context.xml" })
public class Test_ParameterManager {
@Test
public void test_createParaInstancesWith_Null() throws IOException {
UUID testId = UUID.randomUUID();
final String paramName = "param1";
ParameterizationManager parameterizationManager = new ParameterizationManager(
testId, 1);
createFileAndWriteContent(testId, paramName);
Map<String, BasePara> parameterMap = parameterizationManager
.createParaInstancesWith(null,
new UpdateStrategy.OnceRestriction());
assertEquals(0, parameterMap.size());
}
@Test
public void test_createParaInstanceWith_ONCE() throws IOException {
UUID testId = UUID.randomUUID();
final String paramName = "param1";
ParameterizationManager parameterizationManager = new ParameterizationManager(
testId, 1);
ApplicationContextHelper.getContext()
.getBean(ClassHelper.class));
createFileAndWriteContent(testId, paramName);
BasePara param = parameterizationManager.createInstanceWith(
"Para_File", paramName, PickOrder.SEQUENTIAL.toString(),
BasePara param = parameterizationManager.createInstanceWith(testId,
"Para_List", paramName, PickOrder.SEQUENTIAL.toString(),
UpdateStrategy.ONCE.toString(), -1);
assertNotNull(param);
assertEquals("12", param.getCurrentValue());
@ -63,7 +53,7 @@ public class Test_ParameterManager {
createFileAndWriteContent(testId, paramName);
Scenario scenario = Scenario
.scenarioBuilder(buildATestScenarioModelWith(new DefinedParameter(
paramName, "Para_File", PickOrder.SEQUENTIAL.name(),
paramName, "Para_List", PickOrder.SEQUENTIAL.name(),
UpdateStrategy.ONCE.name())));
ScenarioContext scenarioContext = ScenarioContext.buildScenarioContext(
testId, scenario, 1);
@ -81,7 +71,8 @@ public class Test_ParameterManager {
private void createFileAndWriteContent(UUID testId, String paramName)
throws IOException {
File paramFile = new File((new BasePara(testId) {
File paramFile = new File((new BasePara(testId, paramName,
UpdateStrategy.EACH_ITERATION, PickOrder.SEQUENTIAL, -1) {
@Override
public String getCurrentValue() {
return null;
@ -104,7 +95,7 @@ public class Test_ParameterManager {
createFileAndWriteContent(testId, paramName);
Scenario scenario = Scenario
.scenarioBuilder(buildATestScenarioModelWith(new DefinedParameter(
paramName, "Para_File", PickOrder.SEQUENTIAL.name(),
paramName, "Para_List", PickOrder.SEQUENTIAL.name(),
UpdateStrategy.EACH_ITERATION.name())));
ScenarioContext scenarioContext = ScenarioContext.buildScenarioContext(
testId, scenario, 1);
@ -129,7 +120,7 @@ public class Test_ParameterManager {
createFileAndWriteContent(testId, paramName);
Scenario scenario = Scenario
.scenarioBuilder(buildATestScenarioModelWith(new DefinedParameter(
paramName, "Para_File", PickOrder.SEQUENTIAL.name(),
paramName, "Para_List", PickOrder.SEQUENTIAL.name(),
UpdateStrategy.EACH_OCCURRENCE.name())));
ScenarioContext scenarioContext = ScenarioContext.buildScenarioContext(
testId, scenario, 1);
@ -153,18 +144,19 @@ public class Test_ParameterManager {
@Test
public void test_getParaClasses() throws Exception {
ParameterizationManager parameterizationManager = new ParameterizationManager(
UUID.randomUUID(), 1);
ApplicationContextHelper.getContext()
.getBean(ClassHelper.class));
;
@SuppressWarnings("unchecked")
Map<String, Class<?>> paraClasses = (Map<String, Class<?>>) TestHelper
.invokePrivate(parameterizationManager, "getParaClasses", null,
null);
assertEquals(7, paraClasses.size());
assertEquals(5, 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"));
assertTrue(paraClasses.containsKey("Para_List"));
}
}

View File

@ -37,11 +37,13 @@ public class Test_VUserContext {
@Test
public void testGetParam() throws Exception {
UUID testId = UUID.randomUUID();
String paramName = "param1";
Para_Table table = new Para_Table(testId, PickOrder.SEQUENTIAL,
UpdateStrategy.EACH_ITERATION);
createParamFileFor(table.getParamFileFullPath("param1"));
UpdateStrategy.EACH_ITERATION, paramName, -1);
createParamFileFor(table.getParamFileFullPath(paramName));
String ret = table.getTableColumnValue(java.util.UUID.randomUUID(),
new HashMap<String, Object>(), "param1", "0", "sequence", ";",
new HashMap<String, Object>(), paramName, "0", "sequence", ";",
"~", "2");
System.out.println(ret);
assertEquals(11, Integer.parseInt(ret));
@ -54,68 +56,4 @@ public class Test_VUserContext {
FileUtils.writeStringToFile(file, file_CONTENT);
}
// @Test
// public void testGetParam2() throws Exception {
// UUID testId = UUID.randomUUID();
// ParameterizationManager parametersFactory = new ParameterizationManager(
// testId, 4);
// VUserContext ic = new VUserContext(parametersFactory);
// createParamFileFor(new Para_Table(testId, PickOrder.SEQUENTIAL,
// UpdateStrategy.EACH_ITERATION).getParamFileFullPath("param1"));
// String passwordName = ic.getParam(Test_CASE1);
// System.out.println(passwordName);
// assertNotNull(passwordName);
// assertEquals(11, Integer.parseInt(passwordName));
//
// VUserContext ic2 = new VUserContext(parametersFactory);
// String password2 = ic2.getParam(Test_CASE1);
// System.out.println(password2);
// assertNotNull(password2);
// assertEquals(Integer.parseInt(passwordName) + 10,
// Integer.parseInt(password2));
// ic.doCleanUp();
// }
//
// @Test
// public void testGetParamWithUpdateOnEachOccurrence() {
//
// }
//
// @Test
// public void testGetParameter() throws Exception {
// UUID testId = UUID.randomUUID();
// 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,
// "getParameter", new Class[] { ParamFormatParser.class },
// new Object[] { paramFormatParser });
// assertEquals("11", result);
// paracCoor.doCleanUp();
// }
//
// @Test
// public void testGetParameterCrossThread() throws Exception {
// UUID testId = UUID.randomUUID();
// 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,
// "getParameterCrossThread",
// new Class[] { String.class, String.class, String.class,
// Object[].class },
// new Object[] { paramFormatParser.getName(),
// paramFormatParser.getClassName(),
// paramFormatParser.getMethodName(),
// paramFormatParser.getArgsArray() });
// assertEquals("11", result);
// paracCoor.doCleanUp();
// }
}

View File

@ -11,6 +11,8 @@ import org.junit.Test;
import static org.junit.Assert.*;
import org.apache.commons.io.FileUtils;
import org.bench4q.agent.parameterization.PickOrder;
import org.bench4q.agent.parameterization.UpdateStrategy;
import org.bench4q.agent.plugin.basic.hbase.HBasePlugin;
import org.bench4q.share.helper.MarshalHelper;
import org.bench4q.share.helper.TestHelper;
@ -88,7 +90,8 @@ public class Test_HBasePlugin {
public static RunScenarioModel buildScenario(int behaviorSize) {
RunScenarioModel runScenarioModel = new RunScenarioModel();
DefinedParameterModel dp = new DefinedParameterModel("param_HBase",
"Ppara_Table", "sequencial", "Once");
"Para_Table", PickOrder.SEQUENTIAL.name(),
UpdateStrategy.EACH_OCCURRENCE.name());
List<DefinedParameterModel> definedParamters = new ArrayList<DefinedParameterModel>();
definedParamters.add(dp);
runScenarioModel.setDefinedParameters(definedParamters);

View File

@ -46,7 +46,8 @@ public class Test_ScenarioContext {
model.getDefinedParameters().add(
new DefinedParameterModel(param_name, "Para_Table",
"sequencial", "each_occurrence"));
PickOrder.SEQUENTIAL.name(),
UpdateStrategy.EACH_OCCURRENCE.name()));
ScenarioContext scenarioContext = ScenarioContext.buildScenarioContext(
testId, Scenario.scenarioBuilder(model), 10);
@ -59,8 +60,10 @@ public class Test_ScenarioContext {
private void createParamFileAndFillParamContent(String param_name,
UUID testId) throws IOException {
File parmFile = new File(new Para_Table(testId, PickOrder.SEQUENTIAL,
UpdateStrategy.EACH_ITERATION).getParamFileFullPath(param_name));
File parmFile = new File(
new Para_Table(testId, PickOrder.SEQUENTIAL,
UpdateStrategy.EACH_ITERATION, param_name, -1)
.getParamFileFullPath(param_name));
TestHelper.createFileIfNotExist(parmFile);
FileUtils.writeStringToFile(parmFile,
"row1;10;11~row2;20;21~row3,30,31~");

View File

@ -7,7 +7,7 @@
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<context:component-scan
base-package="org.bench4q.agent.helper, org.bench4q.agent.plugin, org.bench4q.agent.storage" />
base-package="org.bench4q.agent.helper, org.bench4q.agent.plugin, org.bench4q.agent.storage, org.bench4q.agent.parameterization" />
<mvc:annotation-driven />
</beans>

View File

@ -0,0 +1,28 @@
package org.bench4q.share.models.agent;
import java.util.LinkedList;
import java.util.List;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement(name = "parameterizationInfoList")
public class ParameterizationInfoListModel {
private List<ParameterizationInfoModel> parameterizationInfoModels;
@XmlElementWrapper(name = "parameterizationInfos")
@XmlElement(name = "parameterizationInfo")
public List<ParameterizationInfoModel> getParameterizationInfoModels() {
return parameterizationInfoModels;
}
public void setParameterInfoModels(
List<ParameterizationInfoModel> parameterizationInfoModels) {
this.parameterizationInfoModels = parameterizationInfoModels;
}
public ParameterizationInfoListModel() {
this.setParameterInfoModels(new LinkedList<ParameterizationInfoModel>());
}
}

View File

@ -0,0 +1,50 @@
package org.bench4q.share.models.agent;
import java.util.LinkedList;
import java.util.List;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement(name = "parameterizationInfo")
public class ParameterizationInfoModel {
private String name;
private List<String> permittedPickOrders;
private List<String> permittedUpdateStrategies;
@XmlElement
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@XmlElementWrapper
@XmlElement
public List<String> getPickOrders() {
return permittedPickOrders;
}
public void setPermittedPickOrders(List<String> permittedPickOrders) {
this.permittedPickOrders = permittedPickOrders;
}
@XmlElementWrapper
@XmlElement
public List<String> getPermittedUpdateStrategies() {
return permittedUpdateStrategies;
}
public void setPermittedUpdateStrategies(
List<String> permittedUpdateStrategies) {
this.permittedUpdateStrategies = permittedUpdateStrategies;
}
public ParameterizationInfoModel() {
this.setPermittedUpdateStrategies(new LinkedList<String>());
this.setPermittedPickOrders(new LinkedList<String>());
}
}