refactor and can get the variable saved by plugin
refactor and can get the variable saved by plugin
This commit is contained in:
parent
110780d7fd
commit
ae4c3caf28
|
@ -1,62 +0,0 @@
|
|||
package org.bench4q.agent.api;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.bench4q.agent.parameterization.ParameterizationInfo;
|
||||
import org.bench4q.agent.parameterization.ParameterizationManager;
|
||||
import org.bench4q.agent.parameterization.PickOrder;
|
||||
import org.bench4q.agent.parameterization.UpdateStrategy;
|
||||
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;
|
||||
}
|
||||
}
|
|
@ -9,7 +9,7 @@ import java.util.UUID;
|
|||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.bench4q.agent.datacollector.impl.BehaviorStatusCodeResult;
|
||||
import org.bench4q.agent.parameterization.ParameterFileCollector;
|
||||
import org.bench4q.agent.plugin.ParameterFileCollector;
|
||||
import org.bench4q.agent.scenario.Scenario;
|
||||
import org.bench4q.agent.scenario.ScenarioContext;
|
||||
import org.bench4q.agent.scenario.ScenarioEngine;
|
||||
|
|
|
@ -1,53 +0,0 @@
|
|||
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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,98 +0,0 @@
|
|||
package org.bench4q.agent.parameterization;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bench4q.agent.helper.ClassHelper;
|
||||
import org.bench4q.agent.helper.ClassLoadRestriction;
|
||||
import org.bench4q.agent.parameterization.impl.BasePara;
|
||||
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 ClassHelper getClassHelper() {
|
||||
return classHelper;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private void setClassHelper(ClassHelper classHelper) {
|
||||
this.classHelper = classHelper;
|
||||
}
|
||||
|
||||
private Map<String, Class<?>> getParaClasses() {
|
||||
return paraClasses;
|
||||
}
|
||||
|
||||
private void setParaClasses(Map<String, Class<?>> paraClasses) {
|
||||
this.paraClasses = paraClasses;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public ParameterizationManager(ClassHelper classHelper) {
|
||||
this.setClassHelper(classHelper);
|
||||
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();
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param className
|
||||
* @param paramName
|
||||
* @param pickOrder
|
||||
* @param updateStrategy
|
||||
* @param currentIndex
|
||||
* @return
|
||||
*/
|
||||
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);
|
||||
}
|
||||
Class<?> clazz = this.getParaClasses().get(className);
|
||||
try {
|
||||
Constructor<?> constructor = clazz.getConstructor(UUID.class,
|
||||
PickOrder.class, UpdateStrategy.class, String.class,
|
||||
int.class);
|
||||
return (BasePara) constructor.newInstance(testId,
|
||||
PickOrder.valueOf(pickOrder),
|
||||
UpdateStrategy.valueOf(updateStrategy), paramName,
|
||||
currentIndex);
|
||||
} catch (Exception e) {
|
||||
throw new NullPointerException(
|
||||
"There's no constructor with five params whose className is "
|
||||
+ className);
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
|
@ -1,16 +0,0 @@
|
|||
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();
|
||||
|
||||
PickOrder[] permittedPickOrders();
|
||||
|
||||
UpdateStrategy[] permittedUpdateStrategies();
|
||||
}
|
|
@ -1,5 +0,0 @@
|
|||
package org.bench4q.agent.parameterization;
|
||||
|
||||
public enum PickOrder {
|
||||
UNIQUE, SEQUENTIAL, RANDOM
|
||||
}
|
|
@ -1,14 +0,0 @@
|
|||
package org.bench4q.agent.parameterization;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public interface SessionObject {
|
||||
|
||||
public String getParam(String name);
|
||||
|
||||
public void saveRuntimeParam(String name, String value);
|
||||
|
||||
public void doCleanUp();
|
||||
|
||||
public void saveRuntimeParams(Map<String, String> runTimeParams);
|
||||
}
|
|
@ -1,32 +0,0 @@
|
|||
package org.bench4q.agent.parameterization;
|
||||
|
||||
public enum UpdateStrategy {
|
||||
ONCE, EACH_ITERATION, EACH_OCCURRENCE;
|
||||
|
||||
public static interface UpdateRestriction {
|
||||
public boolean isSatisfiedBy(UpdateStrategy updateStrategy);
|
||||
}
|
||||
|
||||
public static class OnceRestriction implements UpdateRestriction {
|
||||
public boolean isSatisfiedBy(UpdateStrategy updateStrategy) {
|
||||
return doesMeet(ONCE, updateStrategy);
|
||||
}
|
||||
}
|
||||
|
||||
public static class IterationRestriction implements UpdateRestriction {
|
||||
public boolean isSatisfiedBy(UpdateStrategy updateStrategy) {
|
||||
return doesMeet(EACH_ITERATION, updateStrategy);
|
||||
}
|
||||
}
|
||||
|
||||
public static class OccurrenceRestriction implements UpdateRestriction {
|
||||
public boolean isSatisfiedBy(UpdateStrategy updateStrategy) {
|
||||
return doesMeet(EACH_OCCURRENCE, updateStrategy);
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean doesMeet(UpdateStrategy expected,
|
||||
UpdateStrategy actual) {
|
||||
return expected == actual;
|
||||
}
|
||||
}
|
|
@ -1,92 +0,0 @@
|
|||
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;
|
||||
private String paramName;
|
||||
private PickOrder pickOrder;
|
||||
private UpdateStrategy updateStrategy;
|
||||
private int lastIndex;
|
||||
|
||||
protected UUID getTestId() {
|
||||
return testId;
|
||||
}
|
||||
|
||||
private void setTestId(UUID testId) {
|
||||
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;
|
||||
}
|
||||
|
||||
private void setLastIndex(int lastIndex) {
|
||||
this.lastIndex = lastIndex;
|
||||
}
|
||||
|
||||
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) {
|
||||
String FILE_SEPARATOR = System.getProperty("file.separator");
|
||||
return Main.SCENARIO_PARAMETERS_FOLDER + FILE_SEPARATOR
|
||||
+ testId.toString() + FILE_SEPARATOR + paramName + ".txt";
|
||||
}
|
||||
|
||||
public abstract String getCurrentValue();
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
|
@ -1,18 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<root>
|
||||
<property name="source" type="option">
|
||||
<value>file</value>
|
||||
</property>
|
||||
<property name="sourceValue" type="string">
|
||||
</property>
|
||||
<property name="firstRow" type="integer">
|
||||
</property>
|
||||
<property name="nextRow" type="option">
|
||||
<value>sequence</value>
|
||||
<value>random</value>
|
||||
</property>
|
||||
<property name="splitChar" type="char">
|
||||
</property>
|
||||
<property name="lineChar" type="char">
|
||||
</property>
|
||||
</root>
|
|
@ -1,23 +0,0 @@
|
|||
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;
|
||||
import org.bench4q.agent.plugin.Constructor;
|
||||
|
||||
@ParameterizedClass(name = "Para_UniqueNumber", permittedPickOrders = { PickOrder.UNIQUE }, permittedUpdateStrategies = {
|
||||
UpdateStrategy.EACH_ITERATION, UpdateStrategy.EACH_OCCURRENCE,
|
||||
UpdateStrategy.ONCE })
|
||||
public class Para_UniqueNumber {
|
||||
int currentNumber = 0;
|
||||
|
||||
@Constructor
|
||||
public Para_UniqueNumber() {
|
||||
}
|
||||
|
||||
synchronized String getNumber(UUID id) {
|
||||
return String.valueOf(currentNumber++);
|
||||
}
|
||||
}
|
|
@ -1,44 +0,0 @@
|
|||
package org.bench4q.agent.parameterization.impl;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.bench4q.agent.parameterization.SessionObject;
|
||||
|
||||
public class VuserContext implements SessionObject {
|
||||
private Map<String, BasePara> staticParameters;
|
||||
|
||||
private Map<String, BasePara> getStaticParameters() {
|
||||
return staticParameters;
|
||||
}
|
||||
|
||||
private void setStaticParameters(Map<String, BasePara> staticParameters) {
|
||||
this.staticParameters = staticParameters;
|
||||
}
|
||||
|
||||
public VuserContext(Map<String, BasePara> initStaticParameters) {
|
||||
this.setStaticParameters(initStaticParameters);
|
||||
}
|
||||
|
||||
public String getParam(String name) {
|
||||
try {
|
||||
return this.getStaticParameters().get(name).getCurrentValue();
|
||||
} catch (Exception e) {
|
||||
Logger.getLogger(VuserContext.class).error(e, e);
|
||||
return name;
|
||||
}
|
||||
}
|
||||
|
||||
public void saveRuntimeParam(String name, String value) {
|
||||
|
||||
}
|
||||
|
||||
public void doCleanUp() {
|
||||
this.getStaticParameters().clear();
|
||||
}
|
||||
|
||||
public void saveRuntimeParams(Map<String, String> runTimeParams) {
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package org.bench4q.agent.parameterization;
|
||||
package org.bench4q.agent.plugin;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
|
@ -9,6 +9,7 @@ package org.bench4q.agent.plugin.basic.http;
|
|||
|
||||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
|
@ -29,6 +30,8 @@ import org.apache.commons.httpclient.methods.GetMethod;
|
|||
import org.apache.commons.httpclient.methods.PostMethod;
|
||||
import org.apache.commons.httpclient.methods.PutMethod;
|
||||
import org.apache.commons.httpclient.methods.StringRequestEntity;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.bench4q.agent.plugin.BaseParameterization;
|
||||
import org.bench4q.agent.plugin.Behavior;
|
||||
import org.bench4q.agent.plugin.Constructor;
|
||||
import org.bench4q.agent.plugin.Parameter;
|
||||
|
@ -38,8 +41,9 @@ import org.bench4q.agent.utils.Type.SupportTypes;
|
|||
import org.bench4q.agent.utils.types.Table;
|
||||
|
||||
@Plugin("Http")
|
||||
public class HttpPlugin {
|
||||
public class HttpPlugin extends BaseParameterization {
|
||||
private HttpClient httpClient;
|
||||
private Map<String, String> variables = new HashMap<String, String>();
|
||||
|
||||
public HttpClient getHttpClient() {
|
||||
return httpClient;
|
||||
|
@ -50,7 +54,9 @@ public class HttpPlugin {
|
|||
}
|
||||
|
||||
@Constructor
|
||||
public HttpPlugin() {
|
||||
public HttpPlugin(
|
||||
@Parameter(type = SupportTypes.Field, value = "testId") String testId) {
|
||||
super(testId);
|
||||
this.setHttpClient(new HttpClient());
|
||||
}
|
||||
|
||||
|
@ -139,7 +145,6 @@ public class HttpPlugin {
|
|||
int responseCode = -1;
|
||||
long contentLength = 0;
|
||||
String contentType = "";
|
||||
Map<String, String> respVars = new LinkedHashMap<String, String>();
|
||||
|
||||
try {
|
||||
responseCode = this.getHttpClient().executeMethod(method);
|
||||
|
@ -154,16 +159,17 @@ public class HttpPlugin {
|
|||
.getValue();
|
||||
}
|
||||
if (isValid(respVarsToSaveInSession)) {
|
||||
respVars = doExtractResponseVariables(respVarsToSaveInSession,
|
||||
method.getResponseBodyAsString());
|
||||
this.variables.putAll(doExtractResponseVariables(
|
||||
respVarsToSaveInSession,
|
||||
method.getResponseBodyAsString()));
|
||||
}
|
||||
return new HttpReturn(responseCode > 0, responseCode,
|
||||
contentLength, contentType, responseHeaders, respVars);
|
||||
contentLength, contentType, responseHeaders);
|
||||
} catch (HttpException e) {
|
||||
e.printStackTrace();
|
||||
Logger.getLogger(HttpPlugin.class).error(e, e);
|
||||
return new HttpReturn(false, 400, contentLength, contentType);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
Logger.getLogger(HttpPlugin.class).error(e, e);
|
||||
return new HttpReturn(false, 400, contentLength, contentType);
|
||||
} finally {
|
||||
method.releaseConnection();
|
||||
|
@ -330,4 +336,13 @@ public class HttpPlugin {
|
|||
method.getParams().makeLenient();
|
||||
return excuteMethod(method, respVarToSaveInSession);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implement the BaseParameterization's getValue
|
||||
*/
|
||||
@Override
|
||||
public String getValue(String var) {
|
||||
String result = this.variables.get(var);
|
||||
return result == null ? "" : result;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
package org.bench4q.agent.plugin.basic.http;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.httpclient.Header;
|
||||
import org.bench4q.agent.plugin.basic.PluginReturn;
|
||||
|
||||
|
@ -57,11 +55,19 @@ public class HttpReturn extends PluginReturn {
|
|||
this.setContentType(contentType);
|
||||
}
|
||||
|
||||
public HttpReturn(boolean success, int responseCode, long contentLength2,
|
||||
String contentType2, Header[] responseHeaders,
|
||||
Map<String, String> runTimeParams) {
|
||||
this(success, responseCode, contentLength2, contentType2);
|
||||
/**
|
||||
*
|
||||
* @param success
|
||||
* @param responseCode
|
||||
* @param contentLength
|
||||
* @param contentType
|
||||
* @param responseHeaders
|
||||
* @param runTimeParams
|
||||
* !! to be removed
|
||||
*/
|
||||
public HttpReturn(boolean success, int responseCode, long contentLength,
|
||||
String contentType, Header[] responseHeaders) {
|
||||
this(success, responseCode, contentLength, contentType);
|
||||
this.setHeaders(responseHeaders);
|
||||
this.getRunTimeParams().putAll(runTimeParams);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
</param>
|
||||
<param name="respVarsToSaveInSession"
|
||||
label="The regular expression of extracting variables from response">
|
||||
<field size="7" />
|
||||
<table cols="varName;varRegularExpression;leftBoundry;rightBoundry" />
|
||||
</param>
|
||||
</params>
|
||||
</behavior>
|
||||
|
@ -35,7 +35,7 @@
|
|||
</param>
|
||||
<param name="respVarsToSaveInSession"
|
||||
label="The regular expression of extracting variables from response">
|
||||
<field size="7" />
|
||||
<table cols="varName;varRegularExpression;leftBoundry;rightBoundry" />
|
||||
</param>
|
||||
</params>
|
||||
</behavior>
|
||||
|
@ -58,7 +58,7 @@
|
|||
</param>
|
||||
<param name="respVarsToSaveInSession"
|
||||
label="The regular expression of extracting variables from response">
|
||||
<field size="7" />
|
||||
<table cols="varName;varRegularExpression;leftBoundry;rightBoundry" />
|
||||
</param>
|
||||
</params>
|
||||
</behavior>
|
||||
|
@ -81,7 +81,7 @@
|
|||
</param>
|
||||
<param name="respVarsToSaveInSession"
|
||||
label="The regular expression of extracting variables from response">
|
||||
<field size="7" />
|
||||
<table cols="varName;varRegularExpression;leftBoundry;rightBoundry" />
|
||||
</param>
|
||||
</params>
|
||||
</behavior>
|
||||
|
|
|
@ -0,0 +1,42 @@
|
|||
package org.bench4q.agent.plugin.basic.unique;
|
||||
|
||||
import org.bench4q.agent.plugin.BaseParameterization;
|
||||
import org.bench4q.agent.plugin.Behavior;
|
||||
import org.bench4q.agent.plugin.Constructor;
|
||||
import org.bench4q.agent.plugin.Parameter;
|
||||
import org.bench4q.agent.plugin.Plugin;
|
||||
import org.bench4q.agent.utils.Type.SupportTypes;
|
||||
|
||||
@Plugin(value = "UniqueNumber")
|
||||
public class UniqueNumber extends BaseParameterization {
|
||||
private Integer currentNumber;
|
||||
private String format;
|
||||
|
||||
@Constructor
|
||||
public UniqueNumber(
|
||||
@Parameter(type = SupportTypes.Field, value = "testId") String testId,
|
||||
@Parameter(type = SupportTypes.Field, value = "begin") String begin,
|
||||
@Parameter(type = SupportTypes.Field, value = "format") String format) {
|
||||
super(testId);
|
||||
this.format = format;
|
||||
try {
|
||||
currentNumber = Integer.parseInt(begin);
|
||||
} catch (Exception e) {
|
||||
currentNumber = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@Behavior(value = "next")
|
||||
public void next() {
|
||||
synchronized (currentNumber) {
|
||||
currentNumber++;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getValue(String var) {
|
||||
return (this.format == null || this.format.isEmpty()) ? String
|
||||
.valueOf(this.currentNumber) : String.format(this.format,
|
||||
this.currentNumber);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE ui SYSTEM "../../dtd/ui.dtd">
|
||||
<ui>
|
||||
<plugin name="UniqueNumber">
|
||||
<params>
|
||||
<param name="begin" label="The Beginning of the Iteration">
|
||||
<field size="5"></field>
|
||||
</param>
|
||||
<param name="format" label="The format of the value">
|
||||
<field size="5"></field>
|
||||
</param>
|
||||
</params>
|
||||
</plugin>
|
||||
<behavior name="next">
|
||||
<params />
|
||||
</behavior>
|
||||
</ui>
|
|
@ -1,9 +1,6 @@
|
|||
package org.bench4q.agent.scenario;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.SynchronousQueue;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
|
@ -12,18 +9,9 @@ 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.ParameterizationManager;
|
||||
import org.bench4q.agent.parameterization.SessionObject;
|
||||
import org.bench4q.agent.parameterization.UpdateStrategy;
|
||||
import org.bench4q.agent.parameterization.UpdateStrategy.UpdateRestriction;
|
||||
import org.bench4q.agent.parameterization.impl.BasePara;
|
||||
import org.bench4q.agent.parameterization.impl.VuserContext;
|
||||
|
||||
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;
|
||||
|
@ -31,7 +19,6 @@ public class ScenarioContext {
|
|||
private Scenario scenario;
|
||||
private boolean finished;
|
||||
private DataCollector dataStatistics;
|
||||
private ParameterizationManager parameterizationManager;
|
||||
|
||||
public UUID getTestId() {
|
||||
return testId;
|
||||
|
@ -89,36 +76,7 @@ public class ScenarioContext {
|
|||
this.dataStatistics = dataStatistics;
|
||||
}
|
||||
|
||||
public ParameterizationManager getParameterManager() {
|
||||
return parameterizationManager;
|
||||
}
|
||||
|
||||
private void setParameterManager(
|
||||
ParameterizationManager parameterizationManager) {
|
||||
this.parameterizationManager = parameterizationManager;
|
||||
}
|
||||
|
||||
private Map<String, BasePara> getUpdateOnceParameters() {
|
||||
return updateOnceParameters;
|
||||
}
|
||||
|
||||
private void setUpdateOnceParameters(
|
||||
Map<String, BasePara> updateOnceParameters) {
|
||||
this.updateOnceParameters = updateOnceParameters;
|
||||
}
|
||||
|
||||
private Map<String, BasePara> getUpdateEachIterationParameters() {
|
||||
return updateEachIterationParameters;
|
||||
}
|
||||
|
||||
private void setUpdateEachIterationParameters(
|
||||
Map<String, BasePara> updateEachIterationParameters) {
|
||||
this.updateEachIterationParameters = updateEachIterationParameters;
|
||||
}
|
||||
|
||||
private ScenarioContext() {
|
||||
this.setUpdateOnceParameters(new LinkedHashMap<String, BasePara>());
|
||||
this.setUpdateEachIterationParameters(new LinkedHashMap<String, BasePara>());
|
||||
}
|
||||
|
||||
public static ScenarioContext buildScenarioContext(UUID testId,
|
||||
|
@ -133,61 +91,7 @@ public class ScenarioContext {
|
|||
scenarioContext.setStartDate(new Date(System.currentTimeMillis()));
|
||||
scenarioContext.setExecutorService(executor);
|
||||
scenarioContext.setDataStatistics(new ScenarioResultCollector(testId));
|
||||
scenarioContext.setParameterManager(ApplicationContextHelper
|
||||
.getContext().getBean(ParameterizationManager.class));
|
||||
scenarioContext.initForUpdateOnce();
|
||||
return scenarioContext;
|
||||
}
|
||||
|
||||
private void initForUpdateOnce() {
|
||||
this.getUpdateOnceParameters().putAll(
|
||||
initForParameterization(new UpdateStrategy.OnceRestriction()));
|
||||
}
|
||||
|
||||
private Map<String, BasePara> initForParameterization(
|
||||
UpdateRestriction updateRestriction) {
|
||||
Map<String, BasePara> result = new LinkedHashMap<String, BasePara>();
|
||||
if (scenario.getDefinedParameters() == null)
|
||||
return new LinkedHashMap<String, BasePara>();
|
||||
for (DefinedParameter definedParameter : this.getScenario()
|
||||
.getDefinedParameters()) {
|
||||
if (!updateRestriction.isSatisfiedBy(UpdateStrategy
|
||||
.valueOf(definedParameter.getUpdateStrategy()))) {
|
||||
continue;
|
||||
}
|
||||
BasePara parameter = this.getParameterManager().createInstanceWith(
|
||||
this.getTestId(), definedParameter.getType(),
|
||||
definedParameter.getName(),
|
||||
definedParameter.getPickOrder(),
|
||||
definedParameter.getUpdateStrategy(),
|
||||
getParameterLastIndex(definedParameter));
|
||||
result.put(definedParameter.getName(), parameter);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private int getParameterLastIndex(DefinedParameter definedParameter) {
|
||||
return this.getUpdateEachIterationParameters().containsKey(
|
||||
definedParameter.getName()) ? this
|
||||
.getUpdateEachIterationParameters()
|
||||
.get(definedParameter.getName()).getLastIndex() : -1;
|
||||
}
|
||||
|
||||
public SessionObject buildVUserContext() {
|
||||
Map<String, BasePara> initParameters = new HashMap<String, BasePara>();
|
||||
initParameters.putAll(getUpdateOnceParameters());
|
||||
Map<String, BasePara> initForUpdateEachIteration = initForUpdateEachIteration();
|
||||
initParameters.putAll(initForUpdateEachIteration);
|
||||
this.getUpdateEachIterationParameters().putAll(
|
||||
initForUpdateEachIteration);
|
||||
initParameters
|
||||
.putAll(initForParameterization(new UpdateStrategy.OccurrenceRestriction()));
|
||||
VuserContext vuserContextNew = new VuserContext(initParameters);
|
||||
return vuserContextNew;
|
||||
}
|
||||
|
||||
private Map<String, BasePara> initForUpdateEachIteration() {
|
||||
return initForParameterization(new UpdateStrategy.IterationRestriction());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,7 +10,6 @@ import java.util.Map;
|
|||
import org.apache.log4j.Logger;
|
||||
import org.bench4q.agent.datacollector.DataCollector;
|
||||
import org.bench4q.agent.helper.ApplicationContextHelper;
|
||||
import org.bench4q.agent.parameterization.SessionObject;
|
||||
import org.bench4q.agent.plugin.BaseParameterization;
|
||||
import org.bench4q.agent.plugin.Plugin;
|
||||
import org.bench4q.agent.plugin.PluginManager;
|
||||
|
@ -21,7 +20,6 @@ import org.bench4q.agent.scenario.dfa.ParamPart;
|
|||
|
||||
public class VUser implements Runnable {
|
||||
private ScenarioContext scenarioContext;
|
||||
private SessionObject sessionObject;
|
||||
private int currentIterationId;
|
||||
|
||||
private PluginManager pluginManager;
|
||||
|
@ -42,14 +40,6 @@ public class VUser implements Runnable {
|
|||
this.scenarioContext = scenarioContext;
|
||||
}
|
||||
|
||||
private SessionObject getSessionObject() {
|
||||
return sessionObject;
|
||||
}
|
||||
|
||||
private void setSessionObject(SessionObject sessionObject) {
|
||||
this.sessionObject = sessionObject;
|
||||
}
|
||||
|
||||
private PluginManager getPluginManager() {
|
||||
return pluginManager;
|
||||
}
|
||||
|
@ -62,7 +52,6 @@ public class VUser implements Runnable {
|
|||
this.setScenarioContext(scenarioContext);
|
||||
this.setPluginManager(ApplicationContextHelper.getContext().getBean(
|
||||
PluginManager.class));
|
||||
this.setSessionObject(scenarioContext.buildVUserContext());
|
||||
this.setCurrentIterationId(currentIterationId);
|
||||
}
|
||||
|
||||
|
@ -72,8 +61,6 @@ public class VUser implements Runnable {
|
|||
}
|
||||
|
||||
private void doCleanUp() {
|
||||
this.sessionObject.doCleanUp();
|
||||
this.setSessionObject(null);
|
||||
this.setScenarioContext(null);
|
||||
}
|
||||
|
||||
|
@ -104,15 +91,11 @@ public class VUser implements Runnable {
|
|||
Batch batch, DataCollector dataCollector) {
|
||||
List<BehaviorResult> results = new ArrayList<BehaviorResult>();
|
||||
for (Behavior behavior : batch.getBehaviors()) {
|
||||
behavior.distillParams(this.getSessionObject());
|
||||
Object plugin = plugins.get(behavior.getUse());
|
||||
Date startDate = new Date(System.currentTimeMillis());
|
||||
PluginReturn pluginReturn = (PluginReturn) this.getPluginManager()
|
||||
.doBehavior(plugin, behavior.getName(),
|
||||
reassamblyParameters(behavior, plugins));
|
||||
|
||||
extractRunTimeParams(pluginReturn);
|
||||
|
||||
Date endDate = new Date(System.currentTimeMillis());
|
||||
if (!behavior.shouldBeCountResponseTime()) {
|
||||
continue;
|
||||
|
@ -180,13 +163,6 @@ public class VUser implements Runnable {
|
|||
return buf.toString();
|
||||
}
|
||||
|
||||
private void extractRunTimeParams(PluginReturn pluginReturn) {
|
||||
if (pluginReturn == null || !pluginReturn.hasRunTimeParams())
|
||||
return;
|
||||
this.getSessionObject().saveRuntimeParams(
|
||||
pluginReturn.getRunTimeParams());
|
||||
}
|
||||
|
||||
private BehaviorResult buildBehaviorResult(Behavior behavior,
|
||||
Object plugin, Date startDate, PluginReturn pluginReturn,
|
||||
Date endDate) {
|
||||
|
@ -235,7 +211,4 @@ public class VUser implements Runnable {
|
|||
}
|
||||
}
|
||||
|
||||
public String getParam(String name) {
|
||||
return this.sessionObject.getParam(name);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,7 +4,6 @@ import java.util.Map;
|
|||
|
||||
import org.bench4q.agent.datacollector.DataCollector;
|
||||
import org.bench4q.agent.datacollector.impl.BehaviorStatusCodeResult;
|
||||
import org.bench4q.agent.parameterization.SessionObject;
|
||||
import org.bench4q.agent.scenario.Parameter;
|
||||
|
||||
public abstract class Behavior {
|
||||
|
@ -65,13 +64,4 @@ public abstract class Behavior {
|
|||
}
|
||||
}
|
||||
|
||||
public void distillParams(SessionObject session) {
|
||||
for (Parameter parameter : this.getParameters()) {
|
||||
String s = parameter.getValue();
|
||||
System.out.println("before Change :" + s);
|
||||
String re = session.getParam(s);
|
||||
System.out.println("after Change : " + re);
|
||||
parameter.setValue(re);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -72,7 +72,6 @@ public abstract class State {
|
|||
}
|
||||
|
||||
public static class LiteralState extends State {
|
||||
|
||||
@Override
|
||||
public State digest(char c) {
|
||||
if (c == '$') {
|
||||
|
@ -90,7 +89,6 @@ public abstract class State {
|
|||
}
|
||||
|
||||
public static class ContextState extends State {
|
||||
|
||||
@Override
|
||||
public State digest(char c) {
|
||||
switch (c) {
|
||||
|
@ -111,6 +109,14 @@ public abstract class State {
|
|||
}
|
||||
|
||||
public static class PluginIdState extends State {
|
||||
/**
|
||||
* When arrive at the PluginIdState, the char before must be '$'.
|
||||
*
|
||||
* In PluginIdState, if recognize a ':', then should convertTo
|
||||
* VariableState. Else if recognize a '}', then it's a PROPERTY's
|
||||
* terminal
|
||||
*
|
||||
*/
|
||||
@Override
|
||||
public State digest(char c) {
|
||||
switch (c) {
|
||||
|
|
|
@ -16,7 +16,7 @@ import javax.xml.bind.JAXBException;
|
|||
import javax.xml.bind.Unmarshaller;
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.bench4q.agent.parameterization.ParameterFileCollector;
|
||||
import org.bench4q.agent.plugin.ParameterFileCollector;
|
||||
import org.bench4q.share.communication.HttpRequester;
|
||||
import org.bench4q.share.communication.HttpRequester.HttpResponse;
|
||||
import org.bench4q.share.helper.MarshalHelper;
|
||||
|
|
|
@ -1,143 +0,0 @@
|
|||
package org.bench4q.agent.test.parameterization;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bench4q.agent.helper.ApplicationContextHelper;
|
||||
import org.bench4q.agent.helper.ClassHelper;
|
||||
import org.bench4q.agent.parameterization.ParameterizationManager;
|
||||
import org.bench4q.agent.parameterization.PickOrder;
|
||||
import org.bench4q.agent.parameterization.UpdateStrategy;
|
||||
import org.bench4q.agent.parameterization.impl.BasePara;
|
||||
import org.bench4q.agent.scenario.DefinedParameter;
|
||||
import org.bench4q.agent.scenario.Scenario;
|
||||
import org.bench4q.agent.scenario.ScenarioContext;
|
||||
import org.bench4q.agent.scenario.VUser;
|
||||
import org.bench4q.agent.test.TestBase_Parameterization;
|
||||
import org.bench4q.share.helper.TestHelper;
|
||||
import org.bench4q.share.models.agent.DefinedParameterModel;
|
||||
import org.bench4q.share.models.agent.RunScenarioModel;
|
||||
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 extends TestBase_Parameterization {
|
||||
|
||||
@Test
|
||||
public void test_createParaInstanceWith_ONCE() throws IOException {
|
||||
UUID testId = UUID.randomUUID();
|
||||
final String paramName = "param1";
|
||||
ParameterizationManager parameterizationManager = new ParameterizationManager(
|
||||
ApplicationContextHelper.getContext()
|
||||
.getBean(ClassHelper.class));
|
||||
createFileAndWriteContent(testId, paramName, "12;13;14;15");
|
||||
BasePara param = parameterizationManager.createInstanceWith(testId,
|
||||
"Para_List", paramName, PickOrder.SEQUENTIAL.toString(),
|
||||
UpdateStrategy.ONCE.toString(), -1);
|
||||
assertNotNull(param);
|
||||
assertEquals("12", param.getCurrentValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_createParaInstanceWith_UpdateStrategy_Once()
|
||||
throws Exception {
|
||||
UUID testId = UUID.randomUUID();
|
||||
String paramName = "param1";
|
||||
createFileAndWriteContent(testId, paramName, "12;13;14;15");
|
||||
Scenario scenario = Scenario
|
||||
.scenarioBuilderWithCompile(buildATestScenarioModelWith(new DefinedParameter(
|
||||
paramName, "Para_List", PickOrder.SEQUENTIAL.name(),
|
||||
UpdateStrategy.ONCE.name())));
|
||||
ScenarioContext scenarioContext = ScenarioContext.buildScenarioContext(
|
||||
testId, scenario, 1);
|
||||
VUser vUser = new VUser(scenarioContext, 1);
|
||||
String v1_firstValue = vUser.getParam(paramName);
|
||||
String v1_secondValue = vUser.getParam(paramName);
|
||||
assertEquals("12", v1_firstValue);
|
||||
assertEquals(v1_firstValue, v1_secondValue);
|
||||
VUser vUser2 = new VUser(scenarioContext, 1);
|
||||
String v2_firstValue = vUser2.getParam(paramName);
|
||||
String v2_secondValue = vUser2.getParam(paramName);
|
||||
assertEquals(v1_firstValue, v2_firstValue);
|
||||
assertEquals(v2_firstValue, v2_secondValue);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_createParaInstanceWith_UpdateStrategy_EACH_ITERATION()
|
||||
throws IOException {
|
||||
UUID testId = UUID.randomUUID();
|
||||
String paramName = "param1";
|
||||
createFileAndWriteContent(testId, paramName, "12;13;14;15");
|
||||
Scenario scenario = Scenario
|
||||
.scenarioBuilderWithCompile(buildATestScenarioModelWith(new DefinedParameter(
|
||||
paramName, "Para_List", PickOrder.SEQUENTIAL.name(),
|
||||
UpdateStrategy.EACH_ITERATION.name())));
|
||||
ScenarioContext scenarioContext = ScenarioContext.buildScenarioContext(
|
||||
testId, scenario, 1);
|
||||
VUser vUser = new VUser(scenarioContext, 1);
|
||||
String v1_firstValue = vUser.getParam(paramName);
|
||||
String v1_secondeValue = vUser.getParam(paramName);
|
||||
assertNotEquals(paramName, v1_firstValue);
|
||||
assertEquals(v1_firstValue, v1_secondeValue);
|
||||
VUser vUser2 = new VUser(scenarioContext, 1);
|
||||
String v2_firstValue = vUser2.getParam(paramName);
|
||||
String v2_secondValue = vUser2.getParam(paramName);
|
||||
assertNotEquals(paramName, v2_firstValue);
|
||||
assertEquals(v2_firstValue, v2_secondValue);
|
||||
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, "12;13;14;15");
|
||||
Scenario scenario = Scenario
|
||||
.scenarioBuilderWithCompile(buildATestScenarioModelWith(new DefinedParameter(
|
||||
paramName, "Para_List", PickOrder.SEQUENTIAL.name(),
|
||||
UpdateStrategy.EACH_OCCURRENCE.name())));
|
||||
ScenarioContext scenarioContext = ScenarioContext.buildScenarioContext(
|
||||
testId, scenario, 1);
|
||||
VUser vUser = new VUser(scenarioContext, 1);
|
||||
String vuserFirstValue = vUser.getParam(paramName);
|
||||
String vuserSecondeValue = vUser.getParam(paramName);
|
||||
assertNotEquals(vuserFirstValue, vuserSecondeValue);
|
||||
}
|
||||
|
||||
private RunScenarioModel buildATestScenarioModelWith(
|
||||
DefinedParameter definedParameter) {
|
||||
RunScenarioModel runScenarioModel = new RunScenarioModel();
|
||||
runScenarioModel.getDefinedParameters().add(
|
||||
new DefinedParameterModel(definedParameter.getName(),
|
||||
definedParameter.getType(), definedParameter
|
||||
.getPickOrder(), definedParameter
|
||||
.getUpdateStrategy()));
|
||||
return runScenarioModel;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_getParaClasses() throws Exception {
|
||||
ParameterizationManager parameterizationManager = new ParameterizationManager(
|
||||
ApplicationContextHelper.getContext()
|
||||
.getBean(ClassHelper.class));
|
||||
;
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, Class<?>> paraClasses = (Map<String, Class<?>>) TestHelper
|
||||
.invokePrivate(parameterizationManager, "getParaClasses", null,
|
||||
null);
|
||||
assertEquals(5, paraClasses.size());
|
||||
assertTrue(paraClasses.containsKey("Para_Table"));
|
||||
assertTrue(paraClasses.containsKey("Para_IteratorNumber"));
|
||||
assertTrue(paraClasses.containsKey("Para_RandomNumber"));
|
||||
assertTrue(paraClasses.containsKey("Para_UniqueNumber"));
|
||||
assertTrue(paraClasses.containsKey("Para_List"));
|
||||
}
|
||||
|
||||
}
|
|
@ -1,59 +0,0 @@
|
|||
package org.bench4q.agent.test.parameterization;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
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.Para_Table;
|
||||
import org.bench4q.share.helper.TestHelper;
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
|
||||
public class Test_VUserContext {
|
||||
/**
|
||||
* The old test case is splited by ',', but it's not robust The new test
|
||||
* case is splited by ParameterParser.parseNField, It's more robust
|
||||
*/
|
||||
// private static final String OLD_TEST_CASE =
|
||||
// "<parameters name=\"useNamePassword\" class=\"Para_Table\" type=\"crossThread\" method=\"getTableColumnValue\" args=\"file,ScenarioParameters\\param1.txt,0,sequence,;,~,2\" />";
|
||||
// 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\" />";
|
||||
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\" />";
|
||||
|
||||
@After
|
||||
public void cleanUp() {
|
||||
|
||||
}
|
||||
|
||||
@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, paramName, -1);
|
||||
|
||||
createParamFileFor(table.getParamFileFullPath(paramName));
|
||||
String ret = table.getTableColumnValue(java.util.UUID.randomUUID(),
|
||||
new HashMap<String, Object>(), paramName, "0", "sequence", ";",
|
||||
"~", "2");
|
||||
System.out.println(ret);
|
||||
assertEquals(11, Integer.parseInt(ret));
|
||||
}
|
||||
|
||||
private void createParamFileFor(String paramFileFullPath)
|
||||
throws IOException {
|
||||
File file = new File(paramFileFullPath);
|
||||
TestHelper.createFileIfNotExist(file);
|
||||
FileUtils.writeStringToFile(file, file_CONTENT);
|
||||
}
|
||||
|
||||
}
|
|
@ -24,7 +24,7 @@ public class Test_ClassHelper {
|
|||
.value();
|
||||
}
|
||||
});
|
||||
assertEquals(6, plugins.size());
|
||||
assertEquals(9, plugins.size());
|
||||
assertEquals(true, plugins.containsKey("Http"));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,12 +11,9 @@ 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;
|
||||
import org.bench4q.share.models.agent.DefinedParameterModel;
|
||||
import org.bench4q.share.models.agent.ParameterModel;
|
||||
import org.bench4q.share.models.agent.RunScenarioModel;
|
||||
import org.bench4q.share.models.agent.scriptrecord.BatchModel;
|
||||
|
@ -29,9 +26,6 @@ public class Test_HBasePlugin {
|
|||
public void testBuildScenario() {
|
||||
int behaviorSize = 20;
|
||||
RunScenarioModel result = buildScenario(behaviorSize);
|
||||
assertEquals(1, result.getDefinedParameters().size());
|
||||
assertEquals("param_HBase", result.getDefinedParameters().get(0)
|
||||
.getName());
|
||||
assertEquals(2, result.getUsePlugins().size());
|
||||
assertEquals("hBase", result.getUsePlugins().get(0).getId());
|
||||
assertEquals("Hbase", result.getUsePlugins().get(0).getName());
|
||||
|
@ -89,13 +83,6 @@ public class Test_HBasePlugin {
|
|||
|
||||
public static RunScenarioModel buildScenario(int behaviorSize) {
|
||||
RunScenarioModel runScenarioModel = new RunScenarioModel();
|
||||
DefinedParameterModel dp = new DefinedParameterModel("param_HBase",
|
||||
"Para_Table", PickOrder.SEQUENTIAL.name(),
|
||||
UpdateStrategy.EACH_OCCURRENCE.name());
|
||||
List<DefinedParameterModel> definedParamters = new ArrayList<DefinedParameterModel>();
|
||||
definedParamters.add(dp);
|
||||
runScenarioModel.setDefinedParameters(definedParamters);
|
||||
|
||||
List<UsePluginModel> usePluginList = new ArrayList<UsePluginModel>();
|
||||
usePluginList.add(buildUpPlugin("hBase", "Hbase"));
|
||||
usePluginList.add(buildUpPlugin("timer", "ConstantTimer"));
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package org.bench4q.agent.test.plugin;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.apache.commons.httpclient.Cookie;
|
||||
import org.apache.commons.httpclient.cookie.MalformedCookieException;
|
||||
|
@ -25,7 +26,7 @@ public class Test_HttpPlugin {
|
|||
}
|
||||
|
||||
public Test_HttpPlugin() {
|
||||
this.setHttpPlugin(new HttpPlugin());
|
||||
this.setHttpPlugin(new HttpPlugin(UUID.randomUUID().toString()));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -99,9 +100,8 @@ public class Test_HttpPlugin {
|
|||
null,
|
||||
"varName=ticket|varExpression=\"ticket\":\\s*?\"\\w+\",|leftBoundry=\"ticket\"\": \"|rightBoundry=\",|;");
|
||||
assertEquals(200, ticketReturn.getStatusCode());
|
||||
assertNotNull(ticketReturn.getRunTimeParams());
|
||||
assertEquals(1, ticketReturn.getRunTimeParams().size());
|
||||
System.out.println(ticketReturn.getRunTimeParams().get("ticket"));
|
||||
assertNotNull(this.getHttpPlugin().getValue("ticket"));
|
||||
System.out.println(this.getHttpPlugin().getValue("ticket"));
|
||||
}
|
||||
|
||||
private void logTheCookie(String times) {
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package org.bench4q.agent.test.plugin;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bench4q.agent.helper.ClassHelper;
|
||||
import org.bench4q.agent.plugin.Plugin;
|
||||
import org.bench4q.agent.plugin.PluginManager;
|
||||
|
@ -15,7 +17,7 @@ public class Test_PluginManager {
|
|||
public void test_getInit() {
|
||||
PluginManager pluginManager = new PluginManager(new ClassHelper(),
|
||||
new TypeConverter());
|
||||
assertEquals(6, pluginManager.getPlugins().size());
|
||||
assertEquals(9, pluginManager.getPlugins().size());
|
||||
assertTrue(pluginManager.getPlugins().containsKey("Http"));
|
||||
}
|
||||
|
||||
|
@ -24,8 +26,13 @@ public class Test_PluginManager {
|
|||
PluginManager pluginManager = new PluginManager(new ClassHelper(),
|
||||
new TypeConverter());
|
||||
HttpPlugin httpPlugin = (HttpPlugin) pluginManager.initializePlugin(
|
||||
pluginManager.getPlugins().get("Http"), null,
|
||||
new HashMap<String, String>());
|
||||
pluginManager.getPlugins().get("Http"),
|
||||
new HashMap<String, String>(), new HashMap<String, String>() {
|
||||
private static final long serialVersionUID = 1L;
|
||||
{
|
||||
put("testId", UUID.randomUUID().toString());
|
||||
}
|
||||
});
|
||||
assertNotNull(httpPlugin);
|
||||
}
|
||||
|
||||
|
|
|
@ -12,8 +12,6 @@ import org.bench4q.agent.scenario.behavior.Behavior;
|
|||
import org.bench4q.agent.scenario.dfa.ParamPart;
|
||||
import org.bench4q.agent.scenario.dfa.ParamPart.ParamPartType;
|
||||
import org.bench4q.agent.test.TestBase_Parameterization;
|
||||
import org.bench4q.agent.test.plugin.Test_HBasePlugin;
|
||||
import org.bench4q.share.models.agent.DefinedParameterModel;
|
||||
import org.bench4q.share.models.agent.ParameterModel;
|
||||
import org.bench4q.share.models.agent.RunScenarioModel;
|
||||
import org.bench4q.share.models.agent.scriptrecord.BehaviorModel;
|
||||
|
@ -23,35 +21,6 @@ import org.junit.Test;
|
|||
public class Test_Scenario extends TestBase_Parameterization {
|
||||
private static final String TEST_CASE = "${csvProvider0:userName}$#okOrNot${file.separator}";
|
||||
|
||||
@Test
|
||||
public void testScenarioBuilderWithZeroDefinedParameter() {
|
||||
RunScenarioModel inputModel = Test_HBasePlugin.buildScenario(10);
|
||||
Scenario scenario = Scenario.scenarioBuilderWithCompile(inputModel);
|
||||
assertNotNull(scenario.getDefinedParameters());
|
||||
assertEquals(1, scenario.getDefinedParameters().length);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testScenarioBuilderWithOneDefinedParameter() {
|
||||
RunScenarioModel inputModel = Test_HBasePlugin.buildScenario(10);
|
||||
inputModel.getDefinedParameters().add(
|
||||
buildDefinedParameterModel("param1", "table", "sequencial",
|
||||
"each_iteration"));
|
||||
Scenario scenario = Scenario.scenarioBuilderWithCompile(inputModel);
|
||||
assertNotNull(scenario.getDefinedParameters());
|
||||
assertEquals(2, scenario.getDefinedParameters().length);
|
||||
}
|
||||
|
||||
private DefinedParameterModel buildDefinedParameterModel(String name,
|
||||
String type, String pickOrder, String updateStrategy) {
|
||||
DefinedParameterModel result = new DefinedParameterModel();
|
||||
result.setName(name);
|
||||
result.setType(type);
|
||||
result.setPickOrder(pickOrder);
|
||||
result.setUpdateStrategy(updateStrategy);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_ScenarioCompile() {
|
||||
RunScenarioModel inputModel = buildRunScenarioModelWith(
|
||||
|
|
|
@ -7,15 +7,12 @@ import java.util.UUID;
|
|||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.bench4q.agent.plugin.basic.PluginReturn;
|
||||
import org.bench4q.agent.plugin.basic.csvprovider.CsvProvider;
|
||||
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.scenario.behavior.Behavior;
|
||||
import org.bench4q.agent.test.TestBase_Parameterization;
|
||||
import org.bench4q.agent.test.plugin.Test_HBasePlugin;
|
||||
import org.bench4q.share.helper.TestHelper;
|
||||
import org.bench4q.share.models.agent.ParameterModel;
|
||||
import org.bench4q.share.models.agent.RunScenarioModel;
|
||||
|
@ -31,83 +28,6 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
|||
public class Test_VUser extends TestBase_Parameterization {
|
||||
static final String TEST_CASE = "${csvProvider0:userName}$#okOrNot${file.separator}";
|
||||
|
||||
@Test
|
||||
public void testExtractRunTimeParamsWithiNullPluginReturn() {
|
||||
VUser testWorker = createAWorker();
|
||||
try {
|
||||
TestHelper.invokePrivate(testWorker, "extractRunTimeParams",
|
||||
new Class[] { PluginReturn.class }, new Object[] { null });
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
fail();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExtractRunTimeParamsWithNullRunTimeParams() {
|
||||
VUser testWorker = createAWorker();
|
||||
try {
|
||||
HttpReturn httpReturn = new HttpReturn(true, 200, 100, "text/html");
|
||||
httpReturn.setRunTimeParams(null);
|
||||
TestHelper.invokePrivate(testWorker, "extractRunTimeParams",
|
||||
new Class[] { PluginReturn.class },
|
||||
new Object[] { httpReturn });
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
fail();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExtractRunTimeParamsWithZeroRunTimeParams() {
|
||||
VUser testWorker = createAWorker();
|
||||
try {
|
||||
HttpReturn httpReturn = new HttpReturn(true, 200, 100, "text/html");
|
||||
httpReturn.setRunTimeParams(new HashMap<String, String>());
|
||||
TestHelper.invokePrivate(testWorker, "extractRunTimeParams",
|
||||
new Class[] { PluginReturn.class },
|
||||
new Object[] { httpReturn });
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
fail();
|
||||
}
|
||||
}
|
||||
|
||||
// @Test
|
||||
// public void testExtractRunTimeParamsWithOneRunTimeParams() {
|
||||
// VUser testWorker = createAWorker();
|
||||
// try {
|
||||
// HttpReturn httpReturn = new HttpReturn(true, 200, 100, "text/html");
|
||||
// httpReturn.setRunTimeParams(new HashMap<String, String>() {
|
||||
// private static final long serialVersionUID = 1L;
|
||||
// {
|
||||
// put("key", "value");
|
||||
// }
|
||||
// });
|
||||
// TestHelper.invokePrivate(testWorker, "extractRunTimeParams",
|
||||
// new Class[] { PluginReturn.class },
|
||||
// new Object[] { httpReturn });
|
||||
// SessionObject sessionObject = (SessionObject) TestHelper
|
||||
// .invokePrivate(testWorker, "getSessionObject", null, null);
|
||||
// assertEquals(
|
||||
// "value",
|
||||
// sessionObject
|
||||
// .getParam("<parameters name=\"key\" class=\"extracted\" />"));
|
||||
// } catch (Exception e) {
|
||||
// e.printStackTrace();
|
||||
// fail();
|
||||
// }
|
||||
// }
|
||||
|
||||
private static VUser createAWorker() {
|
||||
return createVUser(getTestScenario(), UUID.randomUUID());
|
||||
}
|
||||
|
||||
private static Scenario getTestScenario() {
|
||||
return Scenario.scenarioBuilderWithCompile(Test_HBasePlugin
|
||||
.buildScenario(10));
|
||||
}
|
||||
|
||||
public static VUser createVUser(Scenario scenario, UUID testId) {
|
||||
return new VUser(ScenarioContext.buildScenarioContext(testId, scenario,
|
||||
10), 1);
|
||||
|
|
|
@ -5,6 +5,7 @@ import static org.junit.Assert.*;
|
|||
import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.apache.commons.httpclient.NameValuePair;
|
||||
import org.bench4q.agent.plugin.basic.http.HttpPlugin;
|
||||
|
@ -164,8 +165,8 @@ public class Test_ParameterParser {
|
|||
public void testGetHeadersWithRightCase() throws Exception {
|
||||
@SuppressWarnings("unchecked")
|
||||
List<NameValuePair> nvPairs = (List<NameValuePair>) TestHelper
|
||||
.invokePrivate(new HttpPlugin(), "parseHeaders",
|
||||
new Class[] { String.class },
|
||||
.invokePrivate(new HttpPlugin(UUID.randomUUID().toString()),
|
||||
"parseHeaders", new Class[] { String.class },
|
||||
new Object[] { testHeaders });
|
||||
|
||||
assertEquals(3, nvPairs.size());
|
||||
|
@ -183,8 +184,8 @@ public class Test_ParameterParser {
|
|||
public void testGetHeadersWithUpperCase() throws Exception {
|
||||
@SuppressWarnings("unchecked")
|
||||
List<NameValuePair> nvPairs = (List<NameValuePair>) TestHelper
|
||||
.invokePrivate(new HttpPlugin(), "parseHeaders",
|
||||
new Class[] { String.class },
|
||||
.invokePrivate(new HttpPlugin(UUID.randomUUID().toString()),
|
||||
"parseHeaders", new Class[] { String.class },
|
||||
new Object[] { testheaderWithUpperCase });
|
||||
assertEquals(3, nvPairs.size());
|
||||
assertEquals("Content-Type", nvPairs.get(0).getName());
|
||||
|
|
Loading…
Reference in New Issue