Updated Branches: refs/heads/master 40804738c -> d93ed7645
Blur-20 Fixed. Project: http://git-wip-us.apache.org/repos/asf/incubator-blur/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-blur/commit/d93ed764 Tree: http://git-wip-us.apache.org/repos/asf/incubator-blur/tree/d93ed764 Diff: http://git-wip-us.apache.org/repos/asf/incubator-blur/diff/d93ed764 Branch: refs/heads/master Commit: d93ed764544032c234e78d9e79a270ed0f5cf432 Parents: d18932d Author: Aaron McCurry <[email protected]> Authored: Mon Sep 24 17:10:42 2012 -0400 Committer: Aaron McCurry <[email protected]> Committed: Mon Sep 24 17:10:42 2012 -0400 ---------------------------------------------------------------------- .../java/org/apache/blur/thrift/Connection.java | 25 +++++++++----- .../org/apache/blur/thrift/ConnectionTest.java | 26 +++++++++++++++ 2 files changed, 42 insertions(+), 9 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/d93ed764/src/blur-thrift/src/main/java/org/apache/blur/thrift/Connection.java ---------------------------------------------------------------------- diff --git a/src/blur-thrift/src/main/java/org/apache/blur/thrift/Connection.java b/src/blur-thrift/src/main/java/org/apache/blur/thrift/Connection.java index 54e9318..e9ce24b 100644 --- a/src/blur-thrift/src/main/java/org/apache/blur/thrift/Connection.java +++ b/src/blur-thrift/src/main/java/org/apache/blur/thrift/Connection.java @@ -16,23 +16,30 @@ package org.apache.blur.thrift; * License for the specific language governing permissions and limitations under * the License. */ - public class Connection { - private int _port; - private String _host; - private String _proxyHost; - private int _proxyPort; + private String _host = null; + private int _port = -1; + private String _proxyHost = null; + private int _proxyPort = -1; private boolean _proxy = false; public Connection(String connectionStr) { int index = connectionStr.indexOf(':'); if (index >= 0) { - _host = connectionStr.substring(0, index); - _port = Integer.parseInt(connectionStr.substring(index + 1)); - // @TODO make this connection parse proxy ports as well + int slashIndex = connectionStr.indexOf('/'); + if (slashIndex > 0) { + _host = connectionStr.substring(0, index); + _port = Integer.parseInt(connectionStr.substring(index + 1, slashIndex)); + int indexOfProxyPort = connectionStr.indexOf(':', slashIndex); + _proxyHost = connectionStr.substring(slashIndex + 1, indexOfProxyPort); + _proxyPort = Integer.parseInt(connectionStr.substring(indexOfProxyPort + 1)); + } else { + _host = connectionStr.substring(0, index); + _port = Integer.parseInt(connectionStr.substring(index + 1)); + } } else { - throw new RuntimeException("Connection string of [" + connectionStr + "] does not match 'host1:port,host2:port,...'"); + throw new RuntimeException("Connection string of [" + connectionStr + "] does not match 'host1:port' or 'host1:port/proxyhost1:proxyport'"); } } http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/d93ed764/src/blur-thrift/src/test/java/org/apache/blur/thrift/ConnectionTest.java ---------------------------------------------------------------------- diff --git a/src/blur-thrift/src/test/java/org/apache/blur/thrift/ConnectionTest.java b/src/blur-thrift/src/test/java/org/apache/blur/thrift/ConnectionTest.java new file mode 100644 index 0000000..295fc8e --- /dev/null +++ b/src/blur-thrift/src/test/java/org/apache/blur/thrift/ConnectionTest.java @@ -0,0 +1,26 @@ +package org.apache.blur.thrift; + +import static org.junit.Assert.*; + +import org.junit.Test; + +public class ConnectionTest { + + @Test + public void testConnectionParsingWithOutProxy() { + Connection connection = new Connection("host:1000"); + assertEquals("host",connection.getHost()); + assertEquals(1000,connection.getPort()); + assertNull(connection.getProxyHost()); + assertEquals(-1,connection.getProxyPort()); + } + + @Test + public void testConnectionParsingWithProxy() { + Connection connection = new Connection("host:1000/proxyhost:2000"); + assertEquals("host",connection.getHost()); + assertEquals(1000,connection.getPort()); + assertEquals("proxyhost",connection.getProxyHost()); + assertEquals(2000,connection.getProxyPort()); + } +}
