MongoDB Plugin,Changed to can connect a set of mongo servers

This commit is contained in:
rzs840707 2014-08-27 15:57:14 +08:00
parent df7e03f7e3
commit 86dbdfad95
1 changed files with 26 additions and 3 deletions

View File

@ -1,6 +1,8 @@
package org.bench4q.agent.plugin.basic.MongoDB;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.apache.log4j.Logger;
import org.bench4q.agent.plugin.Constructor;
@ -46,9 +48,20 @@ public class MongoDBPlugin {
@Parameter(value = "value", type = SupportTypes.Field) String value) {
Mongo mongo = null;
try {
mongo = new Mongo(new ServerAddress(hostName, port),
List<ServerAddress> hostsList = new ArrayList<ServerAddress>();
String[] hosts = hostName.split(",");
for(String host : hosts)
{
hostsList.add(new ServerAddress(host));
}
mongo = new Mongo(hostsList ,
new MongoOptions(new MongoClientOptions.Builder()
.maxWaitTime(1000 * 40).build()));
/*mongo = new Mongo(new ServerAddress(hostName, port),
new MongoOptions(new MongoClientOptions.Builder()
.maxWaitTime(1000 * 40).build()));
*/
DB db = mongo.getDB(dbName);
DBCollection table = db.getCollection(this.tableUnderTest);
DBObject valueToInsert = new BasicDBObject();
@ -72,7 +85,17 @@ public class MongoDBPlugin {
@Parameter(value = "properties", type = SupportTypes.Table) String properties) {
Mongo mongo = null;
try {
mongo = new Mongo(hostName, port);
List<ServerAddress> hostsList = new ArrayList<ServerAddress>();
String[] hosts = hostName.split(",");
for(String host : hosts)
{
hostsList.add(new ServerAddress(host));
}
mongo = new Mongo(hostsList ,
new MongoOptions(new MongoClientOptions.Builder()
.maxWaitTime(1000 * 40).build()));
//mongo = new Mongo(hostName, port);
DB db = mongo.getDB(dbName);
DBCollection table = db.getCollection(this.tableUnderTest);
Table propertiesTable = Table.buildTable(properties,