add those ui definitions of Plugins and refactor

add those ui definitions of Plugins and refactor
This commit is contained in:
coderfengyun 2014-04-16 15:14:58 +08:00
parent 038056b284
commit 46fee631f3
18 changed files with 141 additions and 55 deletions

View File

@ -14,7 +14,7 @@ import org.bench4q.agent.Main;
* @author coderfengyun
*
*/
public abstract class BaseParameterization {
public abstract class ParameterBarn {
private UUID testId;
protected UUID getTestId() {
@ -25,7 +25,7 @@ public abstract class BaseParameterization {
this.testId = testId;
}
protected BaseParameterization(String testId) {
protected ParameterBarn(String testId) {
this.setTestId(UUID.fromString(testId));
}

View File

@ -188,7 +188,7 @@ public class PluginManager {
}
private boolean needExtraParameters(Class<?> plugin) {
return plugin.getSuperclass().equals(BaseParameterization.class);
return plugin.getSuperclass().equals(ParameterBarn.class);
}
private Constructor<?> getConstructor(Constructor<?>[] ctConstructors) {
@ -255,7 +255,6 @@ public class PluginManager {
Object[] params = prepareParameters(method, parameters);
return method.invoke(plugin, params);
} catch (Exception e) {
return null;
}
}

View File

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE ui SYSTEM "../../dtd/ui.dtd">
<ui>
<plugin name="commandline">
<params />
</plugin>
<behavior name="Command">
<params>
<param name="command">
<field size="6"></field>
</param>
</params>
</behavior>
</ui>

View File

@ -11,7 +11,7 @@ import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.bench4q.agent.plugin.BaseParameterization;
import org.bench4q.agent.plugin.ParameterBarn;
import org.bench4q.agent.plugin.Behavior;
import org.bench4q.agent.plugin.Constructor;
import org.bench4q.agent.plugin.Parameter;
@ -20,7 +20,7 @@ import org.bench4q.agent.utils.ParameterParser;
import org.bench4q.agent.utils.Type.SupportTypes;
@Plugin(value = "CsvProvider")
public class CsvProvider extends BaseParameterization {
public class CsvProvider extends ParameterBarn {
private static final String ENABLE_CheckBox = "enable";
static final String LINES_GET = "#";

View File

@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE ui SYSTEM "../../dtd/ui.dtd">
<ui>
<plugin name="HBase">
<params>
</params>
</plugin>
<behavior name="Send">
<params>
<param name="beginTime">
<field size="5"></field>
</param>
<param name="endTime">
<field size="5"></field>
</param>
<param name="beginUser">
<field size="5"></field>
</param>
<param name="endTime">
<field size="5"></field>
</param>
</params>
</behavior>
</ui>

View File

@ -31,7 +31,7 @@ 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.ParameterBarn;
import org.bench4q.agent.plugin.Behavior;
import org.bench4q.agent.plugin.Constructor;
import org.bench4q.agent.plugin.Parameter;
@ -41,7 +41,7 @@ import org.bench4q.agent.utils.Type.SupportTypes;
import org.bench4q.agent.utils.types.Table;
@Plugin("Http")
public class HttpPlugin extends BaseParameterization {
public class HttpPlugin extends ParameterBarn {
private HttpClient httpClient;
private Map<String, String> variables = new HashMap<String, String>();

View File

@ -1,6 +1,6 @@
package org.bench4q.agent.plugin.basic.iterator;
import org.bench4q.agent.plugin.BaseParameterization;
import org.bench4q.agent.plugin.ParameterBarn;
import org.bench4q.agent.plugin.Behavior;
import org.bench4q.agent.plugin.Constructor;
import org.bench4q.agent.plugin.Parameter;
@ -8,7 +8,7 @@ import org.bench4q.agent.plugin.Plugin;
import org.bench4q.agent.utils.Type.SupportTypes;
@Plugin(value = "IteratorNumber")
public class IteratorNumber extends BaseParameterization {
public class IteratorNumber extends ParameterBarn {
private Long iteratorNum;
private String format;

View File

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE ui SYSTEM "../../dtd/ui.dtd">
<ui>
<plugin name="Log">
<params />
</plugin>
<behavior name="Log">
<params>
<param name="message">
<field size="4" />
</param>
</params>
</behavior>
</ui>

View File

@ -1,6 +1,6 @@
package org.bench4q.agent.plugin.basic.random;
import org.bench4q.agent.plugin.BaseParameterization;
import org.bench4q.agent.plugin.ParameterBarn;
import org.bench4q.agent.plugin.Behavior;
import org.bench4q.agent.plugin.Constructor;
import org.bench4q.agent.plugin.Parameter;
@ -8,7 +8,7 @@ import org.bench4q.agent.plugin.Plugin;
import org.bench4q.agent.utils.Type.SupportTypes;
@Plugin(value = "Random")
public class Random extends BaseParameterization {
public class Random extends ParameterBarn {
private String format;
private int begin;
private int end;

View File

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE ui SYSTEM "../../dtd/ui.dtd">
<ui>
<plugin name="ConstantTimer">
<params />
</plugin>
<behavior name="Sleep">
<params>
<param name="time">
<field size="6" />
</param>
</params>
</behavior>
</ui>

View File

@ -1,6 +1,6 @@
package org.bench4q.agent.plugin.basic.unique;
import org.bench4q.agent.plugin.BaseParameterization;
import org.bench4q.agent.plugin.ParameterBarn;
import org.bench4q.agent.plugin.Behavior;
import org.bench4q.agent.plugin.Constructor;
import org.bench4q.agent.plugin.Parameter;
@ -8,7 +8,7 @@ import org.bench4q.agent.plugin.Plugin;
import org.bench4q.agent.utils.Type.SupportTypes;
@Plugin(value = "UniqueNumber")
public class UniqueNumber extends BaseParameterization {
public class UniqueNumber extends ParameterBarn {
private Integer currentNumber;
private String format;

View File

@ -34,6 +34,15 @@ public class Parameter {
this.paramParts = paramParts;
}
public Parameter() {
}
public Parameter(String key, String value) {
this();
this.setKey(key);
this.setValue(value);
}
public void compileToGenerateParts() {
List<ParamPart> paramParts = DFA.resolveMaltipleParamPart(this
.getValue());

View File

@ -5,13 +5,11 @@ import java.util.Collections;
import java.util.List;
import org.bench4q.agent.scenario.behavior.Behavior;
import org.bench4q.agent.scenario.behavior.BehaviorFactory;
import org.bench4q.share.helper.MarshalHelper;
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;
import org.bench4q.share.models.agent.scriptrecord.BehaviorModel;
import org.bench4q.share.models.agent.scriptrecord.PageModel;
import org.bench4q.share.models.agent.scriptrecord.UsePluginModel;
@ -148,8 +146,8 @@ public class Scenario {
}
batch.setBehaviors(new Behavior[batchModel.getBehaviors().size()]);
for (int i = 0; i < batchModel.getBehaviors().size(); ++i) {
batch.getBehaviors()[i] = extractBehavior(batchModel.getBehaviors()
.get(i));
batch.getBehaviors()[i] = Behavior.buildWith(batchModel
.getBehaviors().get(i));
}
return batch;
}
@ -165,23 +163,22 @@ public class Scenario {
}
}
public static Behavior extractBehavior(BehaviorModel behaviorModel) {
Behavior behavior = BehaviorFactory.getBuisinessObject(behaviorModel);
behavior.setName(behaviorModel.getName());
behavior.setUse(behaviorModel.getUse());
behavior.setId(behaviorModel.getId());
behavior.setParameters(new Parameter[behaviorModel.getParameters()
.size()]);
int k = 0;
for (k = 0; k < behaviorModel.getParameters().size(); k++) {
ParameterModel parameterModel = behaviorModel.getParameters()
.get(k);
Parameter parameter = extractParameter(parameterModel);
behavior.getParameters()[k] = parameter;
}
return behavior;
}
// private static Behavior extractBehavior(BehaviorModel behaviorModel) {
// Behavior behavior = Behavior.buildWith(behaviorModel);
// behavior.setName(behaviorModel.getName());
// behavior.setUse(behaviorModel.getUse());
// behavior.setId(behaviorModel.getId());
// behavior.setParameters(new Parameter[behaviorModel.getParameters()
// .size()]);
//
// for (int k = 0; k < behaviorModel.getParameters().size(); k++) {
// ParameterModel parameterModel = behaviorModel.getParameters()
// .get(k);
// Parameter parameter = extractParameter(parameterModel);
// behavior.getParameters()[k] = parameter;
// }
// return behavior;
// }
private static UsePlugin extractUsePlugin(UsePluginModel usePluginModel) {
UsePlugin usePlugin = new UsePlugin();

View File

@ -10,7 +10,7 @@ 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.plugin.BaseParameterization;
import org.bench4q.agent.plugin.ParameterBarn;
import org.bench4q.agent.plugin.Plugin;
import org.bench4q.agent.plugin.PluginManager;
import org.bench4q.agent.plugin.basic.PluginReturn;
@ -137,8 +137,8 @@ public class VUser implements Runnable {
if (dpObj == null) {
throw new RuntimeException("No such plug-in id: "
+ parts[i].getPluginIdForContextCallType());
} else if (dpObj instanceof BaseParameterization) {
buf.append(((BaseParameterization) dpObj).getValue(parts[i]
} else if (dpObj instanceof ParameterBarn) {
buf.append(((ParameterBarn) dpObj).getValue(parts[i]
.getVariableForContextCallAndProperty()));
} else {
throw new RuntimeException("Plug-in "

View File

@ -5,6 +5,8 @@ import java.util.Map;
import org.bench4q.agent.datacollector.DataCollector;
import org.bench4q.agent.datacollector.impl.BehaviorStatusCodeResult;
import org.bench4q.agent.scenario.Parameter;
import org.bench4q.share.models.agent.ParameterModel;
import org.bench4q.share.models.agent.scriptrecord.BehaviorModel;
public abstract class Behavior {
private int id;
@ -64,4 +66,28 @@ public abstract class Behavior {
}
}
public static Behavior buildWith(BehaviorModel behaviorModel) {
Behavior behavior = null;
if (behaviorModel.getType().equalsIgnoreCase("TIMERBEHAVIOR")) {
behavior = new TimerBehavior();
} else if (behaviorModel.getType().equalsIgnoreCase("USERBEHAVIOR")) {
behavior = new UserBehavior();
} else {
throw new IllegalArgumentException(
"The input BehaviorModel's type is not proper");
}
behavior.setName(behaviorModel.getName());
behavior.setUse(behaviorModel.getUse());
behavior.setId(behaviorModel.getId());
behavior.setParameters(new Parameter[behaviorModel.getParameters()
.size()]);
for (int k = 0; k < behaviorModel.getParameters().size(); k++) {
ParameterModel parameterModel = behaviorModel.getParameters()
.get(k);
behavior.getParameters()[k] = new Parameter(
parameterModel.getKey(), parameterModel.getValue());
}
return behavior;
}
}

View File

@ -1,14 +0,0 @@
package org.bench4q.agent.scenario.behavior;
import org.bench4q.share.models.agent.scriptrecord.BehaviorModel;
public class BehaviorFactory {
public static Behavior getBuisinessObject(BehaviorModel modelInput) {
if (modelInput.getType().equalsIgnoreCase("TIMERBEHAVIOR")) {
return new TimerBehavior();
} else if (modelInput.getType().equalsIgnoreCase("USERBEHAVIOR")) {
return new UserBehavior();
}
return null;
}
}

View File

@ -7,7 +7,7 @@ import java.util.List;
import java.util.UUID;
import org.apache.commons.io.FileUtils;
import org.bench4q.agent.plugin.BaseParameterization;
import org.bench4q.agent.plugin.ParameterBarn;
import org.bench4q.share.helper.TestHelper;
import org.bench4q.share.models.agent.ParameterModel;
import org.bench4q.share.models.agent.RunScenarioModel;
@ -17,11 +17,11 @@ import org.bench4q.share.models.agent.scriptrecord.PageModel;
import org.bench4q.share.models.agent.scriptrecord.UsePluginModel;
public abstract class TestBase_Parameterization {
private BaseParameterization basePara;
private ParameterBarn basePara;
protected void createFileAndWriteContent(UUID testId, String paramName,
String content) throws IOException {
basePara = new BaseParameterization(testId.toString()) {
basePara = new ParameterBarn(testId.toString()) {
@Override
public String getValue(String var) {
return null;

View File

@ -36,6 +36,9 @@ public class Test_Scenario extends TestBase_Parameterization {
Scenario scenario = Scenario.scenarioBuilderWithCompile(inputModel);
assertNotNull(scenario.getDefinedParameters());
for (Behavior behavior : scenario.getAllBehaviors()) {
assertEquals("first", behavior.getName());
assertEquals(0, behavior.getId());
assertEquals("http", behavior.getUse());
for (Parameter parameter : behavior.getParameters()) {
assertNotNull(parameter.getParamParts());
List<ParamPart> result = Arrays.asList(parameter