diff --git a/Bench4Q-Agent/src/main/java/org/bench4q/agent/plugin/basic/MongoDB/MongoDBPlugin.java b/Bench4Q-Agent/src/main/java/org/bench4q/agent/plugin/basic/MongoDB/MongoDBPlugin.java index b7f28613..a2ef3c09 100644 --- a/Bench4Q-Agent/src/main/java/org/bench4q/agent/plugin/basic/MongoDB/MongoDBPlugin.java +++ b/Bench4Q-Agent/src/main/java/org/bench4q/agent/plugin/basic/MongoDB/MongoDBPlugin.java @@ -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); diff --git a/Bench4Q-Agent/src/main/java/org/bench4q/agent/plugin/basic/UUID/UUID.java b/Bench4Q-Agent/src/main/java/org/bench4q/agent/plugin/basic/UUID/UUID.java new file mode 100644 index 00000000..ce34fa2b --- /dev/null +++ b/Bench4Q-Agent/src/main/java/org/bench4q/agent/plugin/basic/UUID/UUID.java @@ -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(); + } + +} diff --git a/Bench4Q-Agent/src/main/java/org/bench4q/agent/plugin/basic/UUID/ui.xml b/Bench4Q-Agent/src/main/java/org/bench4q/agent/plugin/basic/UUID/ui.xml new file mode 100644 index 00000000..cec3acf4 --- /dev/null +++ b/Bench4Q-Agent/src/main/java/org/bench4q/agent/plugin/basic/UUID/ui.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/Bench4Q-Agent/src/test/java/org/bench4q/agent/test/plugin/Test_MongoDBPlugin.java b/Bench4Q-Agent/src/test/java/org/bench4q/agent/test/plugin/Test_MongoDBPlugin.java index aaf3fa3f..81ab2682 100644 --- a/Bench4Q-Agent/src/test/java/org/bench4q/agent/test/plugin/Test_MongoDBPlugin.java +++ b/Bench4Q-Agent/src/test/java/org/bench4q/agent/test/plugin/Test_MongoDBPlugin.java @@ -34,22 +34,13 @@ 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=" - + this.testId.toString() + "|;"); + .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);