hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ecl...@apache.org
Subject [2/2] hbase git commit: HBASE-15761 Add on more server name tests
Date Fri, 06 May 2016 16:11:52 GMT
HBASE-15761 Add on more server name tests


Project: http://git-wip-us.apache.org/repos/asf/hbase/repo
Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/7b1786e8
Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/7b1786e8
Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/7b1786e8

Branch: refs/heads/HBASE-14850
Commit: 7b1786e8fb92c75ca9f37fb388b3ba8c4e9c9709
Parents: bce08a5
Author: Elliott Clark <eclark@apache.org>
Authored: Wed May 4 12:04:18 2016 -0700
Committer: Elliott Clark <eclark@apache.org>
Committed: Fri May 6 09:11:38 2016 -0700

----------------------------------------------------------------------
 hbase-native-client/serde/server-name-test.cc | 18 ++++++++++++++++++
 hbase-native-client/serde/server-name.h       |  4 +++-
 2 files changed, 21 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hbase/blob/7b1786e8/hbase-native-client/serde/server-name-test.cc
----------------------------------------------------------------------
diff --git a/hbase-native-client/serde/server-name-test.cc b/hbase-native-client/serde/server-name-test.cc
index 35dcbc1..2281fa2 100644
--- a/hbase-native-client/serde/server-name-test.cc
+++ b/hbase-native-client/serde/server-name-test.cc
@@ -30,3 +30,21 @@ TEST(TestServerName, TestMakeServerName) {
   ASSERT_EQ("test", sn.host_name());
   ASSERT_EQ(123, sn.port());
 }
+
+TEST(TestServerName, TestIps) {
+  auto sn = folly::to<ServerName>("127.0.0.1:999");
+  ASSERT_EQ("127.0.0.1", sn.host_name());
+  ASSERT_EQ(999, sn.port());
+}
+
+TEST(TestServerName, TestThrow) {
+  ASSERT_ANY_THROW(folly::to<ServerName>("Ther's no colon here"));
+}
+
+TEST(TestServerName, TestIPV6) {
+  auto sn = folly::to<ServerName>("[::::1]:123");
+
+  ASSERT_EQ("[::::1]", sn.host_name());
+  ASSERT_EQ(123, sn.port());
+
+}

http://git-wip-us.apache.org/repos/asf/hbase/blob/7b1786e8/hbase-native-client/serde/server-name.h
----------------------------------------------------------------------
diff --git a/hbase-native-client/serde/server-name.h b/hbase-native-client/serde/server-name.h
index bdba087..9844465 100644
--- a/hbase-native-client/serde/server-name.h
+++ b/hbase-native-client/serde/server-name.h
@@ -12,7 +12,9 @@ template <class String> void parseTo(String in, ServerName &out)
{
   std::string s = folly::to<std::string>(in);
 
   auto delim = s.rfind(":");
-  DCHECK(delim != std::string::npos);
+  if (delim == std::string::npos) {
+    throw std::runtime_error("Couldn't parse server name");
+  }
   out.set_host_name(s.substr(0, delim));
   // Now keep everything after the : (delim + 1) to the end.
   out.set_port(folly::to<int>(s.substr(delim + 1)));


Mime
View raw message