Contributions
Connecting to mongo database through SSH tunnel
Here's what I have. def sshHost = '' def sshUser = '' def sshPort = '' def localPort = ?? def mongoPort=27017 //default MongoPort JSch jSch=new JSch(); jSch.addIdentity( sshUser, // String userName prvkey, // byte[] privateKey null, // byte[] publicKey emptyPassPhrase // byte[] passPhrase ); Session session = jSch.getSession(sshUser, sshHost, sshPort); session.setConfig("StrictHostKeyChecking", "no") try{ session.connect() session.setPortForwardingL(sshPort, mongohost, mongoPort); log.info ("SSH connection set up") //connect to mongo def mongo= new GMongo (new MongoURI(mongoendpoint)) def db = mongo.getDB(mongocollection) def collection = db.getCollection(collection) def result = collection.findOne() mongo.close() } finally{ session.disconnect() log.info ("SSH disconnected") null } Looks like SSH connections is established successfully, but it can't connect to Mongo. The closest solution I found ishttps://community.smartbear.com/t5/SoapUI-Open-Source/Tunnel-via-ssh-port-22-then-port-forward-3306-to-access-the/m-p/130765#M22383 Not sure, but I think the problem is in this line: session.setPortForwardingL(localPort, mongohost, mongoPort); So how do I know what the local port is? and also what should be in mongohost if I'm connection to replice?1.2KViews0likes0CommentsRe: Fail to Run SoapUI Testrunner from Jenkins: ERROR [SoapUIProTestCaseRunner] java.lang.Exception: Fai
Solved myself: Jenkins (as a service) doesn't pick up project located on shared drive. Copied project to C:/ and it works now without any other changes.7 years agoPlace ReadyAPI QuestionsReadyAPI Questions1.6KViews0likes0CommentsFail to Run SoapUI Testrunner from Jenkins: ERROR [SoapUIProTestCaseRunner] java.lang.Exception: Fai
Trying to run my tests in Jenkins. Tests run from GUI and from Windows command line (I've copied testrunner command from interface): However, when I run the same batch command from Jenkins, I'm getting: Test #14 Console [Jenkins] ERROR [SoapUIProTestCaseRunner] java.lang.Exception: Failed to load the project file Any ideas how to fix it?1.7KViews0likes1CommentRe: how to close mongodb connection
The solution is mongo.close() try {mongo.getDatabaseNames() } catch (Exception e) {log.info "Connection already closed" } Got stuck as I didn't explicitely define MongoClient, but looks like new Gmongo() actually creates MongoClient object7 years agoPlace ReadyAPI QuestionsReadyAPI Questions8.9KViews0likes0Commentshow to close mongodb connection
I have a script that fetches data from mongodb @Grab(group='com.gmongo', module='gmongo', version='1.5') import com.gmongo.GMongo import com.mongodb.MongoCredential import com.mongodb.* import com.mongodb.ServerAddress import com.gmongo.* import com.mongodb.MongoURI import com.mongodb.DBCursor; import com.mongodb.BasicDBObject; import com.mongodb.BasicDBList import org.bson.types.ObjectId //define variables from mongo document def mongo_name def mongo_description def mongo_type //define mongo_variables and initiate mongo connection def mongoendpoint = context.expand( '${#Project#mongoendpoint}' ) def mongocollection=context.expand( '${#Project#mongocollection_products}' ) def mongo= new GMongo (new MongoURI(mongoendpoint)) def db = mongo.getDB(mongocollection) def collection = db.getCollection("ProductItems") //define elements from API response def api_productId = context.expand('${#Project#package_parent}') //get document from mongo DBCursor cursor=collection.find(_id : api_productId) //log.info cursor if (cursor.hasNext() ) { DBObject obj = cursor.next() //mongo_name=obj.name.toString() } //close cursor cursor.close() My problem is that connection stays open until I shut down ReadyAPI which leads to too many open (and not closed) connections. Is it anyway to explicitly close connection? (googled, but couldn't find a solution which would work)7 years agoPlace ReadyAPI QuestionsReadyAPI Questions9KViews0likes2CommentsMongoDB connection fails in ReadyAPI 2.2.0
Hi! I have a following script to connect to Mongo which I am using in SoapUI Free version and it's working fine: @Grab(group='com.gmongo', module='gmongo', version='1.5') import com.gmongo.GMongo import com.mongodb.MongoCredential import com.mongodb.* import com.mongodb.ServerAddress import com.gmongo.* import com.mongodb.MongoURI import com.mongodb.DBCursor; import com.mongodb.BasicDBObject; import com.mongodb.BasicDBList def mongoendpoint = context.expand( '${#Project#mongoendpoint}' ) def mongocollection=context.expand( '${#Project#mongocollection_ignition}' ) def mongo= new GMongo (new MongoURI(mongoendpoint)) def clientId = context.expand( '${#Project#clientId}' ) def db = mongo.getDB(mongocollection) def collection = db.getCollection("Collection") def test=collection.findOne(_id:clientId).toString() log.info ("Mongodb parsing finished") We recently upgraded to paid version (ReadyAPI 2.2.0) and I'm getting errors when executing the same script: Username/password are supplied as part of mongoendpoint variable. Is ReadyAPI using a different approach? Was trying using mongoClient authentification instead. Connection is set up, but I'm getting timeouts when it actually fetches data def credential = MongoCredential.createMongoCRCredential('s**','admin', '**'.toCharArray()) def mongoClient = new MongoClient( new ServerAddress("**", **), [ credential ] ) def db = mongoClient.getDB(mongocollection) def collection = db.getCollection("**") assert collection instanceof com.mongodb.DBCollection // get timeout if try to execute findOne collection.findOne(**).config7 years agoPlace ReadyAPI QuestionsReadyAPI Questions993Views0likes1CommentGroovy Script to fetch latest document in collection returns inconsistent results
I'm trying to fetch the latest document from MongoDB collection. The Groovy code is here @Grab(group='com.gmongo', module='gmongo', version='1.5') import com.gmongo.GMongo import com.mongodb.MongoCredential import com.mongodb.* import com.mongodb.ServerAddress import com.gmongo.* import com.mongodb.MongoURI import com.mongodb.DBCursor; import com.mongodb.BasicDBObject; import com.mongodb.BasicDBList def mongoendpoint = context.expand( '${#Project#mongoendpoint}' ) def mongocollection=context.expand( '${#Project#mongocollection_jobs}' ) def mongo= new GMongo (new MongoURI(mongoendpoint)) def db = mongo.getDB(mongocollection) def collection = db.getCollection("**") DBCursor test = db.**.find().sort($natural:-1).limit(1); if (test.hasNext() ) { DBObject obj = test.next() String res=obj._id log.info(res) } My problem is that results I'm getting are inconsistent, e.g. if I run script multiple time, approximately half of the times I'm getting correct document and half - another document, which if for sure not latest. If I run the same query from mongo shell results are pretty consistent and correct. Have anyone seen that before? Trying to understand if there's any error in my code etc... Thanks797Views0likes0Comments