1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
|
Description: Fixes the compatibility with the version of the MongoDB Java Driver in Debian (untested! feedback welcome)
Author: Emmanuel Bourg <ebourg@apache.org>
Forwarded: no
--- a/src/protocol/mongodb/org/apache/jmeter/protocol/mongodb/config/MongoSourceElement.java
+++ b/src/protocol/mongodb/org/apache/jmeter/protocol/mongodb/config/MongoSourceElement.java
@@ -137,10 +137,8 @@
}
MongoClientOptions.Builder builder = MongoClientOptions.builder()
- .autoConnectRetry(getAutoConnectRetry())
.connectTimeout(getConnectTimeout())
.connectionsPerHost(getConnectionsPerHost())
- .maxAutoConnectRetryTime(getMaxAutoConnectRetryTime())
.maxWaitTime(getMaxWaitTime())
.socketKeepAlive(getSocketKeepAlive())
.socketTimeout(getSocketTimeout())
@@ -154,8 +152,7 @@
getWriteOperationNumberOfServers(),
getWriteOperationTimeout(),
getFsync(),
- getWaitForJournaling(),
- getContinueOnInsertError()
+ getWaitForJournaling()
));
}
MongoClientOptions mongoOptions = builder.build();
--- a/src/protocol/mongodb/org/apache/jmeter/protocol/mongodb/mongo/MongoDB.java
+++ b/src/protocol/mongodb/org/apache/jmeter/protocol/mongodb/mongo/MongoDB.java
@@ -27,6 +27,7 @@
import com.mongodb.Mongo;
import com.mongodb.MongoClient;
import com.mongodb.MongoClientOptions;
+import com.mongodb.MongoCredential;
import com.mongodb.ServerAddress;
/**
@@ -36,12 +37,15 @@
private static final Logger log = LoggingManager.getLoggerForClass();
// Mongo is Thread Safe
- private Mongo mongo = null;
+ private MongoClient mongo = null;
+ private List<ServerAddress> serverAddresses;
+ private MongoClientOptions mongoOptions;
public MongoDB(
List<ServerAddress> serverAddresses,
MongoClientOptions mongoOptions) {
- mongo = new MongoClient(serverAddresses, mongoOptions);
+ this.serverAddresses = serverAddresses;
+ this.mongoOptions = mongoOptions;
}
public DB getDB(String database, String username, String password) {
@@ -49,18 +53,11 @@
if(log.isDebugEnabled()) {
log.debug("username: " + username+", password: " + password+", database: " + database);
}
- DB db = mongo.getDB(database);
- boolean authenticated = db.isAuthenticated();
-
- if(!authenticated) {
- if(username != null && password != null && username.length() > 0 && password.length() > 0) {
- authenticated = db.authenticate(username, password.toCharArray());
- }
- }
- if(log.isDebugEnabled()) {
- log.debug("authenticated: " + authenticated);
+ if (mongo == null) {
+ char[] pwd = password != null && password.length() > 0 ? password.toCharArray() : null;
+ mongo = new MongoClient(serverAddresses, MongoCredential.createCredential(username, database, pwd), mongoOptions);
}
- return db;
+ return mongo.getDB(database);
}
public void clear() {
@@ -68,7 +65,9 @@
log.debug("clearing");
}
- mongo.close();
+ if (mongo != null) {
+ mongo.close();
+ }
//there is no harm in trying to clear up
mongo = null;
}
--- a/src/protocol/mongodb/org/apache/jmeter/protocol/mongodb/sampler/MongoScriptRunner.java
+++ b/src/protocol/mongodb/org/apache/jmeter/protocol/mongodb/sampler/MongoScriptRunner.java
@@ -51,18 +51,11 @@
log.debug("database: " + db.getName()+", script: " + script);
}
- db.requestStart();
- try {
- db.requestEnsureConnection();
-
Object result = db.eval(script);
if(log.isDebugEnabled()) {
log.debug("Result : " + result);
}
return result;
- } finally {
- db.requestDone();
- }
}
}
|