You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by te...@apache.org on 2017/07/18 21:11:58 UTC
hbase git commit: HBASE-18400 [C++] ConnectionId Equals/Hash should
consider service_name (Xiaobing Zhou)
Repository: hbase
Updated Branches:
refs/heads/HBASE-14850 a499d6a81 -> 166e49dcd
HBASE-18400 [C++] ConnectionId Equals/Hash should consider service_name (Xiaobing Zhou)
Project: http://git-wip-us.apache.org/repos/asf/hbase/repo
Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/166e49dc
Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/166e49dc
Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/166e49dc
Branch: refs/heads/HBASE-14850
Commit: 166e49dcd59ff9dfb1947f5c269041f9dee46b51
Parents: a499d6a
Author: tedyu <yu...@gmail.com>
Authored: Tue Jul 18 14:11:43 2017 -0700
Committer: tedyu <yu...@gmail.com>
Committed: Tue Jul 18 14:11:43 2017 -0700
----------------------------------------------------------------------
hbase-native-client/connection/connection-id.h | 7 +++++-
.../connection/connection-pool-test.cc | 26 ++++++++++++++++++++
2 files changed, 32 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/hbase/blob/166e49dc/hbase-native-client/connection/connection-id.h
----------------------------------------------------------------------
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;
}
};
http://git-wip-us.apache.org/repos/asf/hbase/blob/166e49dc/hbase-native-client/connection/connection-pool-test.cc
----------------------------------------------------------------------
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);
+}