add UUID plugin

add UUID plugin
This commit is contained in:
coderfengyun 2014-06-23 09:44:54 +08:00
parent d33e8552c5
commit c4c5724fa6
4 changed files with 62 additions and 22 deletions

View File

@ -38,16 +38,15 @@ public class MongoDBPlugin {
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
@Behavior(value = "Insert", type = BehaviorType.USER_BEHAVIOR) @Behavior(value = "Insert", type = BehaviorType.USER_BEHAVIOR)
public MongoDBReturn insert( public MongoDBReturn insert(
@Parameter(value = "id", type = SupportTypes.Field) String id, @Parameter(value = "key", type = SupportTypes.Field) String key,
@Parameter(value = "value", type = SupportTypes.Field) String value) { @Parameter(value = "value", type = SupportTypes.Field) String value) {
// int recordsum = 0;
Mongo mongo = null; Mongo mongo = null;
try { try {
mongo = new Mongo(hostName, port); mongo = new Mongo(hostName, port);
DB db = mongo.getDB(dbName); DB db = mongo.getDB(dbName);
DBCollection table = db.getCollection(this.tableUnderTest); DBCollection table = db.getCollection(this.tableUnderTest);
DBObject valueToInsert = new BasicDBObject(); DBObject valueToInsert = new BasicDBObject();
valueToInsert.put("_id", id); valueToInsert.put("key", key);
valueToInsert.put("value", value); valueToInsert.put("value", value);
table.save(valueToInsert); table.save(valueToInsert);
return new MongoDBReturn(true); return new MongoDBReturn(true);

View File

@ -0,0 +1,32 @@
package org.bench4q.agent.plugin.basic.UUID;
import org.bench4q.agent.plugin.Constructor;
import org.bench4q.agent.plugin.Parameter;
import org.bench4q.agent.plugin.ParameterBarn;
import org.bench4q.agent.plugin.Plugin;
import org.bench4q.agent.plugin.behavior.Behavior;
import org.bench4q.agent.plugin.behavior.BehaviorType;
import org.bench4q.agent.utils.Type.SupportTypes;
@Plugin("UUID")
public class UUID extends ParameterBarn {
private java.util.UUID uuid;
@Constructor
public UUID(
@Parameter(value = "testId", type = SupportTypes.Field) String testId) {
super(testId);
uuid = java.util.UUID.randomUUID();
}
@Behavior(value = "Next", type = BehaviorType.CONTROL_BEHAVIOR)
public void next() {
this.uuid = java.util.UUID.randomUUID();
}
@Override
public String getValue(String var) {
return this.uuid.toString();
}
}

View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE ui SYSTEM "../../dtd/ui.dtd">
<ui>
<plugin name="UUID">
<params>
</params>
</plugin>
<control name="next">
<params />
</control>
</ui>

View File

@ -34,21 +34,12 @@ public class Test_MongoDBPlugin extends TestBase {
@Test @Test
public void test_Insert() { public void test_Insert() {
MongoDBPlugin mongoDBPlugin = new MongoDBPlugin("localhost", 27017,
"temp");
MongoDBReturn result = mongoDBPlugin.insert(this.testId.toString(),
"value1");
result = mongoDBPlugin.query("propertyName=_id|propertyValue="
+ this.testId.toString() + "|;");
assertTrue(result.getSuccessCount() > 0);
}
@Test
public void test_query() {
MongoDBPlugin mongoDBPlugin = new MongoDBPlugin("localhost", 27017, MongoDBPlugin mongoDBPlugin = new MongoDBPlugin("localhost", 27017,
"temp"); "temp");
MongoDBReturn result = mongoDBPlugin MongoDBReturn result = mongoDBPlugin
.query("propertyName=_id|propertyValue=" .insert(this.testId.toString(),
"value1AAAAAAAAAAAAAAAAAAAAAAASFFFAFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF");
result = mongoDBPlugin.query("propertyName=key|propertyValue="
+ this.testId.toString() + "|;"); + this.testId.toString() + "|;");
assertTrue(result.getSuccessCount() > 0); assertTrue(result.getSuccessCount() > 0);
} }
@ -72,16 +63,23 @@ public class Test_MongoDBPlugin extends TestBase {
page1.getBatches().add(batch); page1.getBatches().add(batch);
scenarioModel.getPages().add(page1); scenarioModel.getPages().add(page1);
batch.getBehaviors().add( batch.getBehaviors()
BehaviorModel.UserBehaviorBuilder(0, "Insert", pluginId, Arrays .add(BehaviorModel.UserBehaviorBuilder(
.asList(ParameterModel.createParameter("id", 0,
this.testId.toString()), ParameterModel "Insert",
.createParameter("value", "value2")))); pluginId,
Arrays.asList(
ParameterModel.createParameter("key",
this.testId.toString()),
ParameterModel
.createParameter(
"value",
"ZXZXCZXVZXZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ"))));
batch.getBehaviors().add( batch.getBehaviors().add(
BehaviorModel.UserBehaviorBuilder(1, "Query", pluginId, Arrays BehaviorModel.UserBehaviorBuilder(1, "Query", pluginId, Arrays
.asList(ParameterModel.createParameter( .asList(ParameterModel.createParameter(
"properties", "properties",
"propertyName=_id|propertyValue=" "propertyName=key|propertyValue="
+ this.testId.toString() + "|;")))); + this.testId.toString() + "|;"))));
String scriptContent = MarshalHelper.tryMarshal(scenarioModel); String scriptContent = MarshalHelper.tryMarshal(scenarioModel);
System.out.println(scriptContent); System.out.println(scriptContent);