You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by zg...@apache.org on 2019/03/12 12:45:14 UTC
[hbase] 26/133: HBASE-15761 Add on more server name tests
This is an automated email from the ASF dual-hosted git repository.
zghao pushed a commit to branch HBASE-14850
in repository https://gitbox.apache.org/repos/asf/hbase.git
commit d1067f5a7dfe77cda46d13b1a2d2bc3ea2178109
Author: Elliott Clark <ec...@apache.org>
AuthorDate: Wed May 4 12:04:18 2016 -0700
HBASE-15761 Add on more server name tests
---
hbase-native-client/serde/server-name-test.cc | 18 ++++++++++++++++++
hbase-native-client/serde/server-name.h | 4 +++-
2 files changed, 21 insertions(+), 1 deletion(-)
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());
+
+}
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)));