parent
d33e8552c5
commit
c4c5724fa6
|
@ -38,16 +38,15 @@ public class MongoDBPlugin {
|
|||
@SuppressWarnings("deprecation")
|
||||
@Behavior(value = "Insert", type = BehaviorType.USER_BEHAVIOR)
|
||||
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) {
|
||||
// int recordsum = 0;
|
||||
Mongo mongo = null;
|
||||
try {
|
||||
mongo = new Mongo(hostName, port);
|
||||
DB db = mongo.getDB(dbName);
|
||||
DBCollection table = db.getCollection(this.tableUnderTest);
|
||||
DBObject valueToInsert = new BasicDBObject();
|
||||
valueToInsert.put("_id", id);
|
||||
valueToInsert.put("key", key);
|
||||
valueToInsert.put("value", value);
|
||||
table.save(valueToInsert);
|
||||
return new MongoDBReturn(true);
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
|
@ -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>
|
|
@ -34,21 +34,12 @@ public class Test_MongoDBPlugin extends TestBase {
|
|||
|
||||
@Test
|
||||
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,
|
||||
"temp");
|
||||
MongoDBReturn result = mongoDBPlugin
|
||||
.query("propertyName=_id|propertyValue="
|
||||
.insert(this.testId.toString(),
|
||||
"value1AAAAAAAAAAAAAAAAAAAAAAASFFFAFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF");
|
||||
result = mongoDBPlugin.query("propertyName=key|propertyValue="
|
||||
+ this.testId.toString() + "|;");
|
||||
assertTrue(result.getSuccessCount() > 0);
|
||||
}
|
||||
|
@ -72,16 +63,23 @@ public class Test_MongoDBPlugin extends TestBase {
|
|||
page1.getBatches().add(batch);
|
||||
scenarioModel.getPages().add(page1);
|
||||
|
||||
batch.getBehaviors().add(
|
||||
BehaviorModel.UserBehaviorBuilder(0, "Insert", pluginId, Arrays
|
||||
.asList(ParameterModel.createParameter("id",
|
||||
this.testId.toString()), ParameterModel
|
||||
.createParameter("value", "value2"))));
|
||||
batch.getBehaviors()
|
||||
.add(BehaviorModel.UserBehaviorBuilder(
|
||||
0,
|
||||
"Insert",
|
||||
pluginId,
|
||||
Arrays.asList(
|
||||
ParameterModel.createParameter("key",
|
||||
this.testId.toString()),
|
||||
ParameterModel
|
||||
.createParameter(
|
||||
"value",
|
||||
"ZXZXCZXVZXZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ"))));
|
||||
batch.getBehaviors().add(
|
||||
BehaviorModel.UserBehaviorBuilder(1, "Query", pluginId, Arrays
|
||||
.asList(ParameterModel.createParameter(
|
||||
"properties",
|
||||
"propertyName=_id|propertyValue="
|
||||
"propertyName=key|propertyValue="
|
||||
+ this.testId.toString() + "|;"))));
|
||||
String scriptContent = MarshalHelper.tryMarshal(scenarioModel);
|
||||
System.out.println(scriptContent);
|
||||
|
|
Loading…
Reference in New Issue