Need to update Mongo related jars to latest version
Expected behavior
Current version of Jmeter is having " ApacheJMeter_mongodb.jar " & "mongo-java-driver-2.11.3.jar" in lib folder of Jmeter . With these given version of these jar we canot connect to mongo atlas using connection string with groovy .
Expected behaviour is the given jar should allow us to connect with mongo but its not working as expected.
Actual behavior
Here is the sample of groovy code which is required to connect with mongo -
import com.mongodb.MongoClient; import com.mongodb.MongoClientURI; import com.mongodb.client.MongoDatabase; import com.mongodb.client.MongoCollection; import org.bson.Document; import static com.mongodb.client.model.Filters.eq import com.mongodb.client.MongoClients; import com.mongodb.MongoClientSettings;
String connectionString = "
Currently if we run the above code after passing the right details of connection name , DB name and collection name there will be compilation issues like :-
Response message:javax.script.ScriptException: javax.script.ScriptException: org.bson.json.JsonParseException: JSON reader was expecting a value but found '$'.
Response message:javax.script.ScriptException: javax.script.ScriptException: groovy.lang.MissingMethodException: No signature of method: org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.$() is applicable for argument types: (Script12$_run_closure1) values: [Script12$_run_closure1@995f58e] Possible solutions: is(java.lang.Object), any(), get(java.lang.String), use([Ljava.lang.Object;), any(groovy.lang.Closure), tap(groovy.lang.Closure)
To reslove all these issues and to connect with Mongo atlas using connection string in groovy code :-
-
we need to replace "ApacheJMeter_mongodb.jar" with "ApacheJMeter_mongodb-5.6.jar in lib folder of JMeter . this jar can be downloaded from https://mvnrepository.com/artifact/org.apache.jmeter/ApacheJMeter_mongodb/5.6
-
we need to replace "mongo-java-driver-2.11.3.jar" with "mongo-java-driver-3.12.13.jar " in lib folder of JMeter.this jar can be downloaded from https://mvnrepository.com/artifact/org.mongodb/mongo-java-driver/3.12.13
-
Add "bson-4.9.1.jar " to lib folder of Jmeter . download link https://mvnrepository.com/artifact/org.mongodb/bson/4.9.1
-
Copy the ApacheJMeter_mongodb-5.6.jar , mongo-java-driver-3.12.13.jar and bson-4.9.1.jar to ext folder as well in lib of JMeter
Steps to reproduce the problem
Install the JMeter 5.6 ,using groovy code in JSR223 sampler try to connect with mongo atlas using the connection string rather than host and port .
you will run into mullipr issues as mention above .
After adding /replacing the files as mentioned above will resolve all these issues and a successful connection can be set up .
JMeter Version
5.6
Java Version
openjdk 17
OS Version
macOS - Ventura 13.4.1
This issue keeps coming up. All these issues are related to this MongoDB driver version
- https://github.com/apache/jmeter/pull/390
- https://github.com/apache/jmeter/issues/4928
- https://github.com/apache/jmeter/pull/5865
The history suggests that these mongo test elements were meant to be removed in version 3.1. They have been deprecated and prevented from being displayed in the UI through the not in menu configuration:
not_in_menu=org.apache.jmeter.protocol.mongodb.sampler.MongoScriptSampler,org.apache.jmeter.protocol.mongodb.config.MongoSourceElement
I will make a PR to remove these two Mongo test elements.
In case this may help others. I stumbled upon this when trying to run an Azure Load Testing JMeter test that uses Azure Cosmos DB for MongoDB.
Azure controls the JMeter image and you have limited control over user classpath. The easiest way to get around this limitation was to use the Maven shade plugin to remap the Mongo Driver and it's embedded dependencies. For my case it was the following.
`
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.6.1</version>
<!-- Use the latest stable version -->
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<relocations>
<relocation>
<pattern>com.mongodb</pattern>
<shadedPattern>com.shaded.mongodb</shadedPattern>
</relocation>
<relocation>
<pattern>org.bson</pattern>
<shadedPattern>org.shaded.bson</shadedPattern>
</relocation>
</relocations>
</configuration>
</execution>
</executions>
</plugin>
</plugins>