hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From zg...@apache.org
Subject [hbase] 100/133: HBASE-18400 [C++] ConnectionId Equals/Hash should consider service_name (Xiaobing Zhou)
Date Tue, 12 Mar 2019 12:46:28 GMT
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 9736565050e29cb3c549158511c50972afa98001
Author: tedyu <yuzhihong@gmail.com>
AuthorDate: Tue Jul 18 14:11:43 2017 -0700

    HBASE-18400 [C++] ConnectionId Equals/Hash should consider service_name (Xiaobing Zhou)
---
 hbase-native-client/connection/connection-id.h     |  7 +++++-
 .../connection/connection-pool-test.cc             | 26 ++++++++++++++++++++++
 2 files changed, 32 insertions(+), 1 deletion(-)

diff --git a/hbase-native-client/connection/connection-id.h b/hbase-native-client/connection/connection-id.h
index 7381103..059469f 100644
--- a/hbase-native-client/connection/connection-id.h
+++ b/hbase-native-client/connection/connection-id.h
@@ -39,6 +39,10 @@ class ConnectionId {
                const std::string &service_name)
       : user_(user), service_name_(service_name), host_(host), port_(port) {}
 
+  ConnectionId(const std::string &host, uint16_t port,
+               const std::string &service_name)
+        : user_(security::User::defaultUser()), service_name_(service_name), host_(host),
port_(port) {}
+
   virtual ~ConnectionId() = default;
 
   std::shared_ptr<security::User> user() const { return user_; }
@@ -59,7 +63,7 @@ struct ConnectionIdEquals {
   bool operator()(const std::shared_ptr<ConnectionId> &lhs,
                   const std::shared_ptr<ConnectionId> &rhs) const {
     return userEquals(lhs->user(), rhs->user()) && lhs->host() == rhs->host()
&&
-           lhs->port() == rhs->port();
+           lhs->port() == rhs->port() && lhs->service_name() == rhs->service_name();
   }
 
  private:
@@ -78,6 +82,7 @@ struct ConnectionIdHash {
     boost::hash_combine(h, ci->user() == nullptr ? 0 : ci->user()->user_name());
     boost::hash_combine(h, ci->host());
     boost::hash_combine(h, ci->port());
+    boost::hash_combine(h, ci->service_name());
     return h;
   }
 };
diff --git a/hbase-native-client/connection/connection-pool-test.cc b/hbase-native-client/connection/connection-pool-test.cc
index 04ec7f1..63f774b 100644
--- a/hbase-native-client/connection/connection-pool-test.cc
+++ b/hbase-native-client/connection/connection-pool-test.cc
@@ -101,3 +101,29 @@ TEST(TestConnectionPool, TestOnlyCreateMultipleDispose) {
   auto remote_id2 = std::make_shared<ConnectionId>(hostname_two, port);
   auto result_two = cp.GetConnection(remote_id2);
 }
+
+TEST(TestConnectionPool, TestCreateOneConnectionForOneService) {
+  std::string hostname{"hostname"};
+  uint32_t port{999};
+  std::string service1{"service1"};
+  std::string service2{"service2"};
+
+  auto mock_boot = std::make_shared<MockBootstrap>();
+  auto mock_service = std::make_shared<MockService>();
+  auto mock_cf = std::make_shared<MockConnectionFactory>();
+
+  EXPECT_CALL((*mock_cf), Connect(_, _, _)).Times(2).WillRepeatedly(Return(mock_service));
+  EXPECT_CALL((*mock_cf), MakeBootstrap()).Times(2).WillRepeatedly(Return(mock_boot));
+  ConnectionPool cp{mock_cf};
+
+  {
+    auto remote_id = std::make_shared<ConnectionId>(hostname, port, service1);
+    auto result_one = cp.GetConnection(remote_id);
+    auto remote_id2 = std::make_shared<ConnectionId>(hostname, port, service2);
+    auto result_two = cp.GetConnection(remote_id2);
+  }
+  auto remote_id = std::make_shared<ConnectionId>(hostname, port, service1);
+  auto result_one = cp.GetConnection(remote_id);
+  auto remote_id2 = std::make_shared<ConnectionId>(hostname, port, service2);
+  auto result_two = cp.GetConnection(remote_id2);
+}


Mime
View raw message