Skip to content

Commit

Permalink
Bug 54584 - MongoDB plugin
Browse files Browse the repository at this point in the history
Fix Exception
Bugzilla Id: 54584

git-svn-id: https://svn.apache.org/repos/asf/jmeter/trunk@1451963 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
pmouawad committed Mar 3, 2013
1 parent f09c40a commit 1802938
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 21 deletions.
Expand Up @@ -18,6 +18,8 @@


package org.apache.jmeter.protocol.mongodb.config; package org.apache.jmeter.protocol.mongodb.config;


import java.net.UnknownHostException;

import org.apache.jmeter.config.ConfigElement; import org.apache.jmeter.config.ConfigElement;
import org.apache.jmeter.protocol.mongodb.mongo.MongoDB; import org.apache.jmeter.protocol.mongodb.mongo.MongoDB;
import org.apache.jmeter.protocol.mongodb.mongo.MongoUtils; import org.apache.jmeter.protocol.mongodb.mongo.MongoUtils;
Expand Down Expand Up @@ -240,7 +242,11 @@ public void testStarted() {
if(log.isDebugEnabled()) { if(log.isDebugEnabled()) {
log.debug(getSource() + " is being defined."); 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);
}
} }
} }


Expand Down
Expand Up @@ -21,35 +21,24 @@
import java.net.UnknownHostException; import java.net.UnknownHostException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;

import java.util.List;
import org.apache.jorphan.logging.LoggingManager;
import org.apache.log.Logger;


import com.mongodb.ServerAddress; import com.mongodb.ServerAddress;


/** /**
*/ */
public class MongoUtils { public class MongoUtils {


private static final Logger log = LoggingManager.getLoggerForClass(); public static List<ServerAddress> toServerAddresses(String connections) throws UnknownHostException {

public static ArrayList<ServerAddress> toServerAddresses(String connections) {


ArrayList<ServerAddress> addresses = new ArrayList<ServerAddress>(); List<ServerAddress> addresses = new ArrayList<ServerAddress>();
try { for(String connection : Arrays.asList(connections.split(","))) {
for(String connection : Arrays.asList(connections.split(","))) { int port = 27017;
int port = 27017; String[] hostPort = connection.split(":");
String[] hostPort = connection.split(":"); if(hostPort.length > 1 && hostPort[1] != null) {
if(hostPort.length > 1 && hostPort[1] != null) { port = Integer.parseInt(hostPort[1].trim());
port = Integer.parseInt(hostPort[1].trim());
}
addresses.add(new ServerAddress(hostPort[0], port));
}
}
catch(UnknownHostException uhe) {
if(log.isWarnEnabled()) {
log.warn("", uhe);
} }
addresses.add(new ServerAddress(hostPort[0], port));
} }
return addresses; return addresses;
} }
Expand Down

0 comments on commit 1802938

Please sign in to comment.