You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jmeter.apache.org by pm...@apache.org on 2013/07/14 23:01:34 UTC

svn commit: r1503051 - in /jmeter/trunk: src/protocol/mongodb/org/apache/jmeter/protocol/mongodb/config/MongoDBHolder.java xdocs/usermanual/component_reference.xml

Author: pmouawad
Date: Sun Jul 14 21:01:33 2013
New Revision: 1503051

URL: http://svn.apache.org/r1503051
Log:
Bug 54584 - MongoDB plugin 
Add MongoDBHolder to allow easier access to DB api
Bugzilla Id: 54584

Added:
    jmeter/trunk/src/protocol/mongodb/org/apache/jmeter/protocol/mongodb/config/MongoDBHolder.java   (with props)
Modified:
    jmeter/trunk/xdocs/usermanual/component_reference.xml

Added: jmeter/trunk/src/protocol/mongodb/org/apache/jmeter/protocol/mongodb/config/MongoDBHolder.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/protocol/mongodb/org/apache/jmeter/protocol/mongodb/config/MongoDBHolder.java?rev=1503051&view=auto
==============================================================================
--- jmeter/trunk/src/protocol/mongodb/org/apache/jmeter/protocol/mongodb/config/MongoDBHolder.java (added)
+++ jmeter/trunk/src/protocol/mongodb/org/apache/jmeter/protocol/mongodb/config/MongoDBHolder.java Sun Jul 14 21:01:33 2013
@@ -0,0 +1,53 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.jmeter.protocol.mongodb.config;
+
+import org.apache.jmeter.protocol.mongodb.mongo.MongoDB;
+import org.apache.jmeter.threads.JMeterContextService;
+
+import com.mongodb.DB;
+
+/**
+ * Public API to access MongoDB {@link DB} object created by {@link MongoSourceElement}
+ */
+public final class MongoDBHolder {
+
+    /**
+     * Get access to MongoDB object
+     * @param varName String MongoDB source
+     * @param dbName Mongo DB database name
+     * @return {@link DB}
+     */
+    public static DB getDBFromSource(String varName, String dbName) {
+        return getDBFromSource(varName, dbName, null, null);
+    }
+    
+    /**
+     * Get access to MongoDB object
+     * @param varName String MongoDB source
+     * @param dbName Mongo DB database name
+     * @param login
+     * @param password 
+     * @return {@link DB}
+     */
+    public static DB getDBFromSource(String varName, String dbName, String login, String password) {
+        MongoDB mongodb = (MongoDB) JMeterContextService.getContext().getVariables().getObject(varName);
+        return mongodb.getDB(dbName, login, password);
+    }
+}

Propchange: jmeter/trunk/src/protocol/mongodb/org/apache/jmeter/protocol/mongodb/config/MongoDBHolder.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: jmeter/trunk/xdocs/usermanual/component_reference.xml
URL: http://svn.apache.org/viewvc/jmeter/trunk/xdocs/usermanual/component_reference.xml?rev=1503051&r1=1503050&r2=1503051&view=diff
==============================================================================
--- jmeter/trunk/xdocs/usermanual/component_reference.xml (original)
+++ jmeter/trunk/xdocs/usermanual/component_reference.xml Sun Jul 14 21:01:33 2013
@@ -3962,6 +3962,15 @@ GUI that they can use while developing n
      from the supplied Connection settings. Each thread gets its own connection.
      The connection configuration name is used by the JDBC Sampler to select the appropriate
      connection.
+     You can then access com.mongodb.DB object in Beanshell or JSR223 Test Elements through the element <a href="../api/org/apache/jmeter/protocol/mongodb/config/MongoDBHolder.html">MongoDBHolder</a> 
+     using this code<br/>
+     
+	<code>
+	import com.mongodb.DB;<br/>
+	import org.apache.jmeter.protocol.mongodb.config.MongoDBHolder;<br/>
+	DB db = MongoDBHolder.getDBFromSource("value of property MongoDB Source", "value of property Database Name");<br/>
+	...
+	</code>
     </description>
     <properties>
         <property name="Name" required="No">Descriptive name for the connection configuration that is shown in the tree.</property>