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/03/03 01:04:32 UTC

svn commit: r1451963 - in /jmeter/trunk/src/protocol/mongodb/org/apache/jmeter/protocol/mongodb: config/MongoSourceElement.java mongo/MongoUtils.java

Author: pmouawad
Date: Sun Mar  3 00:04:31 2013
New Revision: 1451963

URL: http://svn.apache.org/r1451963
Log:
Bug 54584 - MongoDB plugin
Fix Exception
Bugzilla Id: 54584

Modified:
    jmeter/trunk/src/protocol/mongodb/org/apache/jmeter/protocol/mongodb/config/MongoSourceElement.java
    jmeter/trunk/src/protocol/mongodb/org/apache/jmeter/protocol/mongodb/mongo/MongoUtils.java

Modified: jmeter/trunk/src/protocol/mongodb/org/apache/jmeter/protocol/mongodb/config/MongoSourceElement.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/protocol/mongodb/org/apache/jmeter/protocol/mongodb/config/MongoSourceElement.java?rev=1451963&r1=1451962&r2=1451963&view=diff
==============================================================================
--- jmeter/trunk/src/protocol/mongodb/org/apache/jmeter/protocol/mongodb/config/MongoSourceElement.java (original)
+++ jmeter/trunk/src/protocol/mongodb/org/apache/jmeter/protocol/mongodb/config/MongoSourceElement.java Sun Mar  3 00:04:31 2013
@@ -18,6 +18,8 @@
 
 package org.apache.jmeter.protocol.mongodb.config;
 
+import java.net.UnknownHostException;
+
 import org.apache.jmeter.config.ConfigElement;
 import org.apache.jmeter.protocol.mongodb.mongo.MongoDB;
 import org.apache.jmeter.protocol.mongodb.mongo.MongoUtils;
@@ -240,7 +242,11 @@ public class MongoSourceElement
             if(log.isDebugEnabled()) {
                 log.debug(getSource() + "  is being defined.");
             }
-            getThreadContext().getVariables().putObject(getSource(), new MongoDB(MongoUtils.toServerAddresses(getConnection()), mongoOptions));
+            try {
+                getThreadContext().getVariables().putObject(getSource(), new MongoDB(MongoUtils.toServerAddresses(getConnection()), mongoOptions));
+            } catch (UnknownHostException e) {
+                throw new IllegalStateException(e);
+            }
         }
     }
 

Modified: jmeter/trunk/src/protocol/mongodb/org/apache/jmeter/protocol/mongodb/mongo/MongoUtils.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/protocol/mongodb/org/apache/jmeter/protocol/mongodb/mongo/MongoUtils.java?rev=1451963&r1=1451962&r2=1451963&view=diff
==============================================================================
--- jmeter/trunk/src/protocol/mongodb/org/apache/jmeter/protocol/mongodb/mongo/MongoUtils.java (original)
+++ jmeter/trunk/src/protocol/mongodb/org/apache/jmeter/protocol/mongodb/mongo/MongoUtils.java Sun Mar  3 00:04:31 2013
@@ -21,9 +21,7 @@ package org.apache.jmeter.protocol.mongo
 import java.net.UnknownHostException;
 import java.util.ArrayList;
 import java.util.Arrays;
-
-import org.apache.jorphan.logging.LoggingManager;
-import org.apache.log.Logger;
+import java.util.List;
 
 import com.mongodb.ServerAddress;
 
@@ -31,25 +29,16 @@ import com.mongodb.ServerAddress;
  */
 public class MongoUtils {
 
-    private static final Logger log = LoggingManager.getLoggerForClass();
-
-    public static ArrayList<ServerAddress> toServerAddresses(String connections) {
+    public static List<ServerAddress> toServerAddresses(String connections) throws UnknownHostException {
 
-        ArrayList<ServerAddress> addresses = new ArrayList<ServerAddress>();
-        try {
-            for(String connection : Arrays.asList(connections.split(","))) {
-                int port = 27017;
-                String[] hostPort = connection.split(":");
-                if(hostPort.length > 1 && hostPort[1] != null) {
-                    port = Integer.parseInt(hostPort[1].trim());
-                }
-                addresses.add(new ServerAddress(hostPort[0], port));
-            }
-        }
-        catch(UnknownHostException uhe) {
-            if(log.isWarnEnabled()) {
-                log.warn("", uhe);
+        List<ServerAddress> addresses = new ArrayList<ServerAddress>();
+        for(String connection : Arrays.asList(connections.split(","))) {
+            int port = 27017;
+            String[] hostPort = connection.split(":");
+            if(hostPort.length > 1 && hostPort[1] != null) {
+                port = Integer.parseInt(hostPort[1].trim());
             }
+            addresses.add(new ServerAddress(hostPort[0], port));
         }
         return addresses;
     }



Re: svn commit: r1451963 - in /jmeter/trunk/src/protocol/mongodb/org/apache/jmeter/protocol/mongodb: config/MongoSourceElement.java mongo/MongoUtils.java

Posted by sebb <se...@gmail.com>.
On 3 March 2013 00:04,  <pm...@apache.org> wrote:
> Author: pmouawad
> Date: Sun Mar  3 00:04:31 2013
> New Revision: 1451963
>
> URL: http://svn.apache.org/r1451963
> Log:
> Bug 54584 - MongoDB plugin
> Fix Exception
> Bugzilla Id: 54584
>
> Modified:
>     jmeter/trunk/src/protocol/mongodb/org/apache/jmeter/protocol/mongodb/config/MongoSourceElement.java
>     jmeter/trunk/src/protocol/mongodb/org/apache/jmeter/protocol/mongodb/mongo/MongoUtils.java
>
> Modified: jmeter/trunk/src/protocol/mongodb/org/apache/jmeter/protocol/mongodb/config/MongoSourceElement.java
> URL: http://svn.apache.org/viewvc/jmeter/trunk/src/protocol/mongodb/org/apache/jmeter/protocol/mongodb/config/MongoSourceElement.java?rev=1451963&r1=1451962&r2=1451963&view=diff
> ==============================================================================
> --- jmeter/trunk/src/protocol/mongodb/org/apache/jmeter/protocol/mongodb/config/MongoSourceElement.java (original)
> +++ jmeter/trunk/src/protocol/mongodb/org/apache/jmeter/protocol/mongodb/config/MongoSourceElement.java Sun Mar  3 00:04:31 2013
> @@ -18,6 +18,8 @@
>
>  package org.apache.jmeter.protocol.mongodb.config;
>
> +import java.net.UnknownHostException;
> +
>  import org.apache.jmeter.config.ConfigElement;
>  import org.apache.jmeter.protocol.mongodb.mongo.MongoDB;
>  import org.apache.jmeter.protocol.mongodb.mongo.MongoUtils;
> @@ -240,7 +242,11 @@ public class MongoSourceElement
>              if(log.isDebugEnabled()) {
>                  log.debug(getSource() + "  is being defined.");
>              }
> -            getThreadContext().getVariables().putObject(getSource(), new MongoDB(MongoUtils.toServerAddresses(getConnection()), mongoOptions));
> +            try {
> +                getThreadContext().getVariables().putObject(getSource(), new MongoDB(MongoUtils.toServerAddresses(getConnection()), mongoOptions));
> +            } catch (UnknownHostException e) {
> +                throw new IllegalStateException(e);
> +            }
>          }
>      }
>
>
> Modified: jmeter/trunk/src/protocol/mongodb/org/apache/jmeter/protocol/mongodb/mongo/MongoUtils.java
> URL: http://svn.apache.org/viewvc/jmeter/trunk/src/protocol/mongodb/org/apache/jmeter/protocol/mongodb/mongo/MongoUtils.java?rev=1451963&r1=1451962&r2=1451963&view=diff
> ==============================================================================
> --- jmeter/trunk/src/protocol/mongodb/org/apache/jmeter/protocol/mongodb/mongo/MongoUtils.java (original)
> +++ jmeter/trunk/src/protocol/mongodb/org/apache/jmeter/protocol/mongodb/mongo/MongoUtils.java Sun Mar  3 00:04:31 2013
> @@ -21,9 +21,7 @@ package org.apache.jmeter.protocol.mongo
>  import java.net.UnknownHostException;
>  import java.util.ArrayList;
>  import java.util.Arrays;
> -
> -import org.apache.jorphan.logging.LoggingManager;
> -import org.apache.log.Logger;
> +import java.util.List;
>
>  import com.mongodb.ServerAddress;
>
> @@ -31,25 +29,16 @@ import com.mongodb.ServerAddress;
>   */
>  public class MongoUtils {
>
> -    private static final Logger log = LoggingManager.getLoggerForClass();
> -
> -    public static ArrayList<ServerAddress> toServerAddresses(String connections) {
> +    public static List<ServerAddress> toServerAddresses(String connections) throws UnknownHostException {
>
> -        ArrayList<ServerAddress> addresses = new ArrayList<ServerAddress>();
> -        try {
> -            for(String connection : Arrays.asList(connections.split(","))) {
> -                int port = 27017;
> -                String[] hostPort = connection.split(":");
> -                if(hostPort.length > 1 && hostPort[1] != null) {
> -                    port = Integer.parseInt(hostPort[1].trim());
> -                }
> -                addresses.add(new ServerAddress(hostPort[0], port));
> -            }
> -        }
> -        catch(UnknownHostException uhe) {
> -            if(log.isWarnEnabled()) {
> -                log.warn("", uhe);
> +        List<ServerAddress> addresses = new ArrayList<ServerAddress>();
> +        for(String connection : Arrays.asList(connections.split(","))) {
> +            int port = 27017;

What is this magic number?
Please document and/or use a constant (plus Javadoc) for it.

> +            String[] hostPort = connection.split(":");
> +            if(hostPort.length > 1 && hostPort[1] != null) {
> +                port = Integer.parseInt(hostPort[1].trim());
>              }
> +            addresses.add(new ServerAddress(hostPort[0], port));
>          }
>          return addresses;
>      }
>
>