HBASE-17219 [C++] Reformat the code according to the style guidelines - ADDENDUM after HBASE-17395
Project: http://git-wip-us.apache.org/repos/asf/hbase/repo Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/fe69c81d Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/fe69c81d Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/fe69c81d Branch: refs/heads/HBASE-14850 Commit: fe69c81d0ac8d11f22c6fac0d68b2c6d57bdb04d Parents: 15a5115 Author: Enis Soztutar <e...@apache.org> Authored: Fri Jan 13 17:42:10 2017 -0800 Committer: Enis Soztutar <e...@apache.org> Committed: Fri Jan 13 17:42:10 2017 -0800 ---------------------------------------------------------------------- .../connection/client-dispatcher.cc | 4 +- .../connection/client-dispatcher.h | 3 +- .../connection/client-handler.cc | 10 ++- hbase-native-client/connection/client-handler.h | 12 ++-- .../connection/connection-factory.cc | 13 ++-- .../connection/connection-factory.h | 6 +- hbase-native-client/connection/connection-id.h | 15 ++--- .../connection/connection-pool-test.cc | 28 +++----- .../connection/connection-pool.cc | 9 +-- .../connection/connection-pool.h | 23 +++---- hbase-native-client/connection/pipeline.h | 6 +- hbase-native-client/connection/request.cc | 14 ++-- hbase-native-client/connection/response.h | 4 +- hbase-native-client/connection/rpc-client.cc | 67 +++++++------------- hbase-native-client/connection/rpc-client.h | 29 ++++----- hbase-native-client/connection/rpc-connection.h | 8 +-- hbase-native-client/core/cell-test.cc | 21 ++---- hbase-native-client/core/cell.cc | 14 ++-- hbase-native-client/core/cell.h | 5 +- hbase-native-client/core/client-test.cc | 6 +- hbase-native-client/core/client.h | 4 +- hbase-native-client/core/configuration.cc | 33 ++++------ hbase-native-client/core/configuration.h | 9 +-- hbase-native-client/core/get-test.cc | 9 +-- hbase-native-client/core/get.cc | 15 ++--- .../core/hbase_configuration-test.cc | 45 +++++-------- .../core/hbase_configuration_loader.cc | 27 +++----- .../core/hbase_configuration_loader.h | 8 +-- hbase-native-client/core/location-cache.cc | 36 ++++------- hbase-native-client/core/location-cache.h | 4 +- hbase-native-client/core/meta-utils.cc | 10 ++- hbase-native-client/core/meta-utils.h | 6 +- hbase-native-client/core/region-location.h | 3 +- hbase-native-client/core/response_converter.h | 2 +- hbase-native-client/core/result-test.cc | 54 ++++++++-------- hbase-native-client/core/result.cc | 28 ++++---- hbase-native-client/core/result.h | 20 +++--- hbase-native-client/core/scan-test.cc | 6 +- hbase-native-client/core/scan.cc | 21 ++---- hbase-native-client/core/simple-client.cc | 28 ++++---- hbase-native-client/core/time_range.cc | 7 +- hbase-native-client/security/BUCK | 12 ++-- hbase-native-client/security/user.h | 13 ++-- .../serde/client-deserializer-test.cc | 3 +- hbase-native-client/serde/rpc.cc | 13 ++-- hbase-native-client/serde/rpc.h | 12 ++-- hbase-native-client/serde/server-name-test.cc | 4 +- hbase-native-client/serde/zk.cc | 3 +- 48 files changed, 270 insertions(+), 462 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/hbase/blob/fe69c81d/hbase-native-client/connection/client-dispatcher.cc ---------------------------------------------------------------------- diff --git a/hbase-native-client/connection/client-dispatcher.cc b/hbase-native-client/connection/client-dispatcher.cc index 0a03396..1ace99c 100644 --- a/hbase-native-client/connection/client-dispatcher.cc +++ b/hbase-native-client/connection/client-dispatcher.cc @@ -57,6 +57,4 @@ Future<Response> ClientDispatcher::operator()(std::unique_ptr<Request> arg) { Future<Unit> ClientDispatcher::close() { return ClientDispatcherBase::close(); } -Future<Unit> ClientDispatcher::close(Context *ctx) { - return ClientDispatcherBase::close(ctx); -} +Future<Unit> ClientDispatcher::close(Context *ctx) { return ClientDispatcherBase::close(ctx); } http://git-wip-us.apache.org/repos/asf/hbase/blob/fe69c81d/hbase-native-client/connection/client-dispatcher.h ---------------------------------------------------------------------- diff --git a/hbase-native-client/connection/client-dispatcher.h b/hbase-native-client/connection/client-dispatcher.h index 67e604e..0489717 100644 --- a/hbase-native-client/connection/client-dispatcher.h +++ b/hbase-native-client/connection/client-dispatcher.h @@ -36,8 +36,7 @@ namespace hbase { * future. */ class ClientDispatcher - : public wangle::ClientDispatcherBase<SerializePipeline, - std::unique_ptr<Request>, Response> { + : public wangle::ClientDispatcherBase<SerializePipeline, std::unique_ptr<Request>, Response> { public: /** Create a new ClientDispatcher */ ClientDispatcher(); http://git-wip-us.apache.org/repos/asf/hbase/blob/fe69c81d/hbase-native-client/connection/client-handler.cc ---------------------------------------------------------------------- diff --git a/hbase-native-client/connection/client-handler.cc b/hbase-native-client/connection/client-handler.cc index e445444..5a6dce2 100644 --- a/hbase-native-client/connection/client-handler.cc +++ b/hbase-native-client/connection/client-handler.cc @@ -41,8 +41,8 @@ ClientHandler::ClientHandler(std::string user_name) serde_(), once_flag_(std::make_unique<std::once_flag>()), resp_msgs_( - make_unique<folly::AtomicHashMap< - uint32_t, std::shared_ptr<google::protobuf::Message>>>(5000)) {} + make_unique<folly::AtomicHashMap<uint32_t, std::shared_ptr<google::protobuf::Message>>>( + 5000)) {} void ClientHandler::read(Context *ctx, std::unique_ptr<IOBuf> buf) { if (LIKELY(buf != nullptr)) { @@ -51,8 +51,7 @@ void ClientHandler::read(Context *ctx, std::unique_ptr<IOBuf> buf) { ResponseHeader header; int used_bytes = serde_.ParseDelimited(buf.get(), &header); - LOG(INFO) << "Read ResponseHeader size=" << used_bytes - << " call_id=" << header.call_id() + LOG(INFO) << "Read ResponseHeader size=" << used_bytes << " call_id=" << header.call_id() << " has_exception=" << header.has_exception(); // Get the response protobuf from the map @@ -96,6 +95,5 @@ Future<Unit> ClientHandler::write(Context *ctx, std::unique_ptr<Request> r) { // Now store the call id to response. resp_msgs_->insert(r->call_id(), r->resp_msg()); // Send the data down the pipeline. - return ctx->fireWrite( - serde_.Request(r->call_id(), r->method(), r->req_msg().get())); + return ctx->fireWrite(serde_.Request(r->call_id(), r->method(), r->req_msg().get())); } http://git-wip-us.apache.org/repos/asf/hbase/blob/fe69c81d/hbase-native-client/connection/client-handler.h ---------------------------------------------------------------------- diff --git a/hbase-native-client/connection/client-handler.h b/hbase-native-client/connection/client-handler.h index 7306c9a..d860cc1 100644 --- a/hbase-native-client/connection/client-handler.h +++ b/hbase-native-client/connection/client-handler.h @@ -50,9 +50,9 @@ namespace hbase { * This class deals with sending the connection header and preamble * on first request. */ -class ClientHandler : public wangle::Handler<std::unique_ptr<folly::IOBuf>, - Response, std::unique_ptr<Request>, - std::unique_ptr<folly::IOBuf>> { +class ClientHandler + : public wangle::Handler<std::unique_ptr<folly::IOBuf>, Response, std::unique_ptr<Request>, + std::unique_ptr<folly::IOBuf>> { public: /** * Create the handler @@ -70,8 +70,7 @@ class ClientHandler : public wangle::Handler<std::unique_ptr<folly::IOBuf>, /** * Write the data down the wire. */ - folly::Future<folly::Unit> write(Context *ctx, - std::unique_ptr<Request> r) override; + folly::Future<folly::Unit> write(Context *ctx, std::unique_ptr<Request> r) override; private: std::unique_ptr<std::once_flag> once_flag_; @@ -79,8 +78,7 @@ class ClientHandler : public wangle::Handler<std::unique_ptr<folly::IOBuf>, RpcSerde serde_; // in flight requests - std::unique_ptr<folly::AtomicHashMap< - uint32_t, std::shared_ptr<google::protobuf::Message>>> + std::unique_ptr<folly::AtomicHashMap<uint32_t, std::shared_ptr<google::protobuf::Message>>> resp_msgs_; }; } // namespace hbase http://git-wip-us.apache.org/repos/asf/hbase/blob/fe69c81d/hbase-native-client/connection/connection-factory.cc ---------------------------------------------------------------------- diff --git a/hbase-native-client/connection/connection-factory.cc b/hbase-native-client/connection/connection-factory.cc index beec6d5..ff83212 100644 --- a/hbase-native-client/connection/connection-factory.cc +++ b/hbase-native-client/connection/connection-factory.cc @@ -26,13 +26,10 @@ using namespace folly; using namespace hbase; -ConnectionFactory::ConnectionFactory( - std::shared_ptr<wangle::IOThreadPoolExecutor> io_pool) - : io_pool_(io_pool), - pipeline_factory_(std::make_shared<RpcPipelineFactory>()) {} +ConnectionFactory::ConnectionFactory(std::shared_ptr<wangle::IOThreadPoolExecutor> io_pool) + : io_pool_(io_pool), pipeline_factory_(std::make_shared<RpcPipelineFactory>()) {} -std::shared_ptr<wangle::ClientBootstrap<SerializePipeline>> -ConnectionFactory::MakeBootstrap() { +std::shared_ptr<wangle::ClientBootstrap<SerializePipeline>> ConnectionFactory::MakeBootstrap() { auto client = std::make_shared<wangle::ClientBootstrap<SerializePipeline>>(); client->group(io_pool_); client->pipelineFactory(pipeline_factory_); @@ -40,8 +37,8 @@ ConnectionFactory::MakeBootstrap() { return client; } std::shared_ptr<HBaseService> ConnectionFactory::Connect( - std::shared_ptr<wangle::ClientBootstrap<SerializePipeline>> client, - const std::string &hostname, int port) { + std::shared_ptr<wangle::ClientBootstrap<SerializePipeline>> client, const std::string &hostname, + int port) { // Yes this will block however it makes dealing with connection pool soooooo // much nicer. // TODO see about using shared promise for this. http://git-wip-us.apache.org/repos/asf/hbase/blob/fe69c81d/hbase-native-client/connection/connection-factory.h ---------------------------------------------------------------------- diff --git a/hbase-native-client/connection/connection-factory.h b/hbase-native-client/connection/connection-factory.h index 17d9941..da44c35 100644 --- a/hbase-native-client/connection/connection-factory.h +++ b/hbase-native-client/connection/connection-factory.h @@ -40,16 +40,14 @@ class ConnectionFactory { * Constructor. * There should only be one ConnectionFactory per client. */ - explicit ConnectionFactory( - std::shared_ptr<wangle::IOThreadPoolExecutor> io_pool); + explicit ConnectionFactory(std::shared_ptr<wangle::IOThreadPoolExecutor> io_pool); /** Default Desctructor */ virtual ~ConnectionFactory() = default; /** * Create a BootStrap from which a connection can be made. */ - virtual std::shared_ptr<wangle::ClientBootstrap<SerializePipeline>> - MakeBootstrap(); + virtual std::shared_ptr<wangle::ClientBootstrap<SerializePipeline>> MakeBootstrap(); /** * Connect a ClientBootstrap to a server and return the pipeline. http://git-wip-us.apache.org/repos/asf/hbase/blob/fe69c81d/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 62fe222..78b9780 100644 --- a/hbase-native-client/connection/connection-id.h +++ b/hbase-native-client/connection/connection-id.h @@ -21,9 +21,9 @@ #include "if/HBase.pb.h" #include "security/user.h" +#include <boost/functional/hash.hpp> #include <memory> #include <utility> -#include <boost/functional/hash.hpp> using hbase::pb::ServerName; using hbase::security::User; @@ -34,12 +34,11 @@ class ConnectionId { ConnectionId(const std::string &host, uint16_t port) : ConnectionId(host, port, User::defaultUser(), "") {} - ConnectionId(const std::string &host, uint16_t port, - std::shared_ptr<User> user) + ConnectionId(const std::string &host, uint16_t port, std::shared_ptr<User> user) : ConnectionId(host, port, user, "") {} - ConnectionId(const std::string &host, uint16_t port, - std::shared_ptr<User> user, const std::string &service_name) + ConnectionId(const std::string &host, uint16_t port, std::shared_ptr<User> user, + const std::string &service_name) : user_(user), service_name_(service_name), host_(host), port_(port) {} virtual ~ConnectionId() = default; @@ -66,11 +65,9 @@ struct ConnectionIdEquals { } private: - bool userEquals(const std::shared_ptr<User> &lhs, - const std::shared_ptr<User> &rhs) const { + bool userEquals(const std::shared_ptr<User> &lhs, const std::shared_ptr<User> &rhs) const { return lhs == nullptr ? rhs == nullptr - : (rhs == nullptr ? false : lhs->user_name() == - rhs->user_name()); + : (rhs == nullptr ? false : lhs->user_name() == rhs->user_name()); } }; http://git-wip-us.apache.org/repos/asf/hbase/blob/fe69c81d/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 4547b30..0930095 100644 --- a/hbase-native-client/connection/connection-pool-test.cc +++ b/hbase-native-client/connection/connection-pool-test.cc @@ -17,9 +17,9 @@ * */ -#include "connection/connection-id.h" #include "connection/connection-pool.h" #include "connection/connection-factory.h" +#include "connection/connection-id.h" #include "if/HBase.pb.h" #include "serde/server-name.h" @@ -37,12 +37,10 @@ using hbase::ConnectionId; class MockConnectionFactory : public ConnectionFactory { public: MockConnectionFactory() : ConnectionFactory(nullptr) {} - MOCK_METHOD0(MakeBootstrap, - std::shared_ptr<wangle::ClientBootstrap<SerializePipeline>>()); - MOCK_METHOD3(Connect, - std::shared_ptr<HBaseService>( - std::shared_ptr<wangle::ClientBootstrap<SerializePipeline>>, - const std::string &hostname, int port)); + MOCK_METHOD0(MakeBootstrap, std::shared_ptr<wangle::ClientBootstrap<SerializePipeline>>()); + MOCK_METHOD3(Connect, std::shared_ptr<HBaseService>( + std::shared_ptr<wangle::ClientBootstrap<SerializePipeline>>, + const std::string &hostname, int port)); }; class MockBootstrap : public wangle::ClientBootstrap<SerializePipeline> {}; @@ -69,12 +67,8 @@ TEST(TestConnectionPool, TestOnlyCreateOnce) { auto mock_cf = std::make_shared<MockConnectionFactory>(); uint32_t port{999}; - EXPECT_CALL((*mock_cf), Connect(_, _, _)) - .Times(1) - .WillRepeatedly(Return(mock_service)); - EXPECT_CALL((*mock_cf), MakeBootstrap()) - .Times(1) - .WillRepeatedly(Return(mock_boot)); + EXPECT_CALL((*mock_cf), Connect(_, _, _)).Times(1).WillRepeatedly(Return(mock_service)); + EXPECT_CALL((*mock_cf), MakeBootstrap()).Times(1).WillRepeatedly(Return(mock_boot)); ConnectionPool cp{mock_cf}; auto remote_id = std::make_shared<ConnectionId>(hostname, port); @@ -92,12 +86,8 @@ TEST(TestConnectionPool, TestOnlyCreateMultipleDispose) { 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)); + 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}; { http://git-wip-us.apache.org/repos/asf/hbase/blob/fe69c81d/hbase-native-client/connection/connection-pool.cc ---------------------------------------------------------------------- diff --git a/hbase-native-client/connection/connection-pool.cc b/hbase-native-client/connection/connection-pool.cc index ee14c9d..07518c5 100644 --- a/hbase-native-client/connection/connection-pool.cc +++ b/hbase-native-client/connection/connection-pool.cc @@ -33,8 +33,7 @@ using hbase::HBaseService; using folly::SharedMutexWritePriority; using folly::SocketAddress; -ConnectionPool::ConnectionPool( - std::shared_ptr<wangle::IOThreadPoolExecutor> io_executor) +ConnectionPool::ConnectionPool(std::shared_ptr<wangle::IOThreadPoolExecutor> io_executor) : cf_(std::make_shared<ConnectionFactory>(io_executor)), clients_(), connections_(), @@ -95,8 +94,7 @@ std::shared_ptr<RpcConnection> ConnectionPool::GetNewConnection( /* create new connection */ auto clientBootstrap = cf_->MakeBootstrap(); - auto dispatcher = - cf_->Connect(clientBootstrap, remote_id->host(), remote_id->port()); + auto dispatcher = cf_->Connect(clientBootstrap, remote_id->host(), remote_id->port()); auto conneciton = std::make_shared<RpcConnection>(remote_id, dispatcher); @@ -118,5 +116,4 @@ void ConnectionPool::Close(std::shared_ptr<ConnectionId> remote_id) { connections_.erase(found); } -void ConnectionPool::Close() { -} +void ConnectionPool::Close() {} http://git-wip-us.apache.org/repos/asf/hbase/blob/fe69c81d/hbase-native-client/connection/connection-pool.h ---------------------------------------------------------------------- diff --git a/hbase-native-client/connection/connection-pool.h b/hbase-native-client/connection/connection-pool.h index 5101c68..1f2a182 100644 --- a/hbase-native-client/connection/connection-pool.h +++ b/hbase-native-client/connection/connection-pool.h @@ -30,7 +30,6 @@ #include "connection/service.h" #include "if/HBase.pb.h" - using hbase::ConnectionId; using hbase::ConnectionIdEquals; using hbase::ConnectionIdHash; @@ -47,8 +46,7 @@ namespace hbase { class ConnectionPool { public: /** Create connection pool wit default connection factory */ - explicit ConnectionPool( - std::shared_ptr<wangle::IOThreadPoolExecutor> io_executor); + explicit ConnectionPool(std::shared_ptr<wangle::IOThreadPoolExecutor> io_executor); /** * Desctructor. @@ -67,8 +65,7 @@ class ConnectionPool { * Get a connection to the server name. Start time is ignored. * This can be a blocking operation for a short time. */ - std::shared_ptr<RpcConnection> GetConnection( - std::shared_ptr<ConnectionId> remote_id); + std::shared_ptr<RpcConnection> GetConnection(std::shared_ptr<ConnectionId> remote_id); /** * Close/remove a connection. @@ -81,18 +78,14 @@ class ConnectionPool { void Close(); private: - std::shared_ptr<RpcConnection> GetCachedConnection( - std::shared_ptr<ConnectionId> remote_id); - std::shared_ptr<RpcConnection> GetNewConnection( - std::shared_ptr<ConnectionId> remote_id); + std::shared_ptr<RpcConnection> GetCachedConnection(std::shared_ptr<ConnectionId> remote_id); + std::shared_ptr<RpcConnection> GetNewConnection(std::shared_ptr<ConnectionId> remote_id); + std::unordered_map<std::shared_ptr<ConnectionId>, std::shared_ptr<RpcConnection>, + ConnectionIdHash, ConnectionIdEquals> + connections_; std::unordered_map<std::shared_ptr<ConnectionId>, - std::shared_ptr<RpcConnection>, ConnectionIdHash, + std::shared_ptr<wangle::ClientBootstrap<SerializePipeline>>, ConnectionIdHash, ConnectionIdEquals> - connections_; - std::unordered_map< - std::shared_ptr<ConnectionId>, - std::shared_ptr<wangle::ClientBootstrap<SerializePipeline>>, - ConnectionIdHash, ConnectionIdEquals> clients_; folly::SharedMutexWritePriority map_mutex_; std::shared_ptr<ConnectionFactory> cf_; http://git-wip-us.apache.org/repos/asf/hbase/blob/fe69c81d/hbase-native-client/connection/pipeline.h ---------------------------------------------------------------------- diff --git a/hbase-native-client/connection/pipeline.h b/hbase-native-client/connection/pipeline.h index c4f3bbb..343219d 100644 --- a/hbase-native-client/connection/pipeline.h +++ b/hbase-native-client/connection/pipeline.h @@ -30,8 +30,7 @@ namespace hbase { /** Pipeline to turn IOBuf into requests */ -using SerializePipeline = - wangle::Pipeline<folly::IOBufQueue &, std::unique_ptr<Request>>; +using SerializePipeline = wangle::Pipeline<folly::IOBufQueue &, std::unique_ptr<Request>>; /** * Factory to create new pipelines for HBase RPC's. @@ -52,8 +51,7 @@ class RpcPipelineFactory : public wangle::PipelineFactory<SerializePipeline> { * - Length Field Based Frame Decoder * - Client Handler */ - SerializePipeline::Ptr newPipeline( - std::shared_ptr<folly::AsyncTransportWrapper> sock) override; + SerializePipeline::Ptr newPipeline(std::shared_ptr<folly::AsyncTransportWrapper> sock) override; private: UserUtil user_util_; http://git-wip-us.apache.org/repos/asf/hbase/blob/fe69c81d/hbase-native-client/connection/request.cc ---------------------------------------------------------------------- diff --git a/hbase-native-client/connection/request.cc b/hbase-native-client/connection/request.cc index d4a4603..189130e 100644 --- a/hbase-native-client/connection/request.cc +++ b/hbase-native-client/connection/request.cc @@ -24,22 +24,18 @@ using namespace hbase; Request::Request(std::shared_ptr<google::protobuf::Message> req, - std::shared_ptr<google::protobuf::Message> resp, - std::string method) + std::shared_ptr<google::protobuf::Message> resp, std::string method) : req_msg_(req), resp_msg_(resp), method_(method), call_id_(0) {} std::unique_ptr<Request> Request::get() { return std::make_unique<Request>(std::make_shared<hbase::pb::GetRequest>(), - std::make_shared<hbase::pb::GetResponse>(), - "Get"); + std::make_shared<hbase::pb::GetResponse>(), "Get"); } std::unique_ptr<Request> Request::mutate() { - return std::make_unique<Request>( - std::make_shared<hbase::pb::MutateRequest>(), - std::make_shared<hbase::pb::MutateResponse>(), "Mutate"); + return std::make_unique<Request>(std::make_shared<hbase::pb::MutateRequest>(), + std::make_shared<hbase::pb::MutateResponse>(), "Mutate"); } std::unique_ptr<Request> Request::scan() { return std::make_unique<Request>(std::make_shared<hbase::pb::ScanRequest>(), - std::make_shared<hbase::pb::ScanResponse>(), - "Scan"); + std::make_shared<hbase::pb::ScanResponse>(), "Scan"); } http://git-wip-us.apache.org/repos/asf/hbase/blob/fe69c81d/hbase-native-client/connection/response.h ---------------------------------------------------------------------- diff --git a/hbase-native-client/connection/response.h b/hbase-native-client/connection/response.h index f032d09..560387c 100644 --- a/hbase-native-client/connection/response.h +++ b/hbase-native-client/connection/response.h @@ -55,9 +55,7 @@ class Response { * The caller is reponsible for knowing the type. In practice the call id is * used to figure out the type. */ - std::shared_ptr<google::protobuf::Message> resp_msg() const { - return resp_msg_; - } + std::shared_ptr<google::protobuf::Message> resp_msg() const { return resp_msg_; } /** Set the response message. */ void set_resp_msg(std::shared_ptr<google::protobuf::Message> response) { http://git-wip-us.apache.org/repos/asf/hbase/blob/fe69c81d/hbase-native-client/connection/rpc-client.cc ---------------------------------------------------------------------- diff --git a/hbase-native-client/connection/rpc-client.cc b/hbase-native-client/connection/rpc-client.cc index 3f0cfaf..9cfefb8 100644 --- a/hbase-native-client/connection/rpc-client.cc +++ b/hbase-native-client/connection/rpc-client.cc @@ -28,41 +28,32 @@ namespace hbase { class RpcChannelImplementation : public AbstractRpcChannel { public: - RpcChannelImplementation(std::shared_ptr<RpcClient> rpc_client, - const std::string& host, uint16_t port, - std::shared_ptr<User> ticket, int rpc_timeout) + RpcChannelImplementation(std::shared_ptr<RpcClient> rpc_client, const std::string& host, + uint16_t port, std::shared_ptr<User> ticket, int rpc_timeout) : AbstractRpcChannel(rpc_client, host, port, ticket, rpc_timeout) {} - void CallMethod(const MethodDescriptor* method, RpcController* controller, - const Message* request, Message* response, - Closure* done) override { - rpc_client_->CallMethod(method, controller, request, response, done, host_, - port_, ticket_); + void CallMethod(const MethodDescriptor* method, RpcController* controller, const Message* request, + Message* response, Closure* done) override { + rpc_client_->CallMethod(method, controller, request, response, done, host_, port_, ticket_); } }; } // namespace hbase RpcClient::RpcClient() { - io_executor_ = std::make_shared<wangle::IOThreadPoolExecutor>( - sysconf(_SC_NPROCESSORS_ONLN)); + io_executor_ = std::make_shared<wangle::IOThreadPoolExecutor>(sysconf(_SC_NPROCESSORS_ONLN)); cp_ = std::make_shared<ConnectionPool>(io_executor_); } -void RpcClient::Close() { - io_executor_->stop(); -} +void RpcClient::Close() { io_executor_->stop(); } -std::shared_ptr<Response> RpcClient::SyncCall(const std::string& host, - uint16_t port, +std::shared_ptr<Response> RpcClient::SyncCall(const std::string& host, uint16_t port, std::unique_ptr<Request> req, std::shared_ptr<User> ticket) { - return std::make_shared<Response>( - AsyncCall(host, port, std::move(req), ticket).get()); + return std::make_shared<Response>(AsyncCall(host, port, std::move(req), ticket).get()); } -std::shared_ptr<Response> RpcClient::SyncCall(const std::string& host, - uint16_t port, +std::shared_ptr<Response> RpcClient::SyncCall(const std::string& host, uint16_t port, std::unique_ptr<Request> req, std::shared_ptr<User> ticket, const std::string& service_name) { @@ -70,54 +61,44 @@ std::shared_ptr<Response> RpcClient::SyncCall(const std::string& host, AsyncCall(host, port, std::move(req), ticket, service_name).get()); } -folly::Future<Response> RpcClient::AsyncCall(const std::string& host, - uint16_t port, +folly::Future<Response> RpcClient::AsyncCall(const std::string& host, uint16_t port, std::unique_ptr<Request> req, std::shared_ptr<User> ticket) { auto remote_id = std::make_shared<ConnectionId>(host, port, ticket); return GetConnection(remote_id)->SendRequest(std::move(req)); } -folly::Future<Response> RpcClient::AsyncCall(const std::string& host, - uint16_t port, +folly::Future<Response> RpcClient::AsyncCall(const std::string& host, uint16_t port, std::unique_ptr<Request> req, std::shared_ptr<User> ticket, const std::string& service_name) { - auto remote_id = - std::make_shared<ConnectionId>(host, port, ticket, service_name); + auto remote_id = std::make_shared<ConnectionId>(host, port, ticket, service_name); return GetConnection(remote_id)->SendRequest(std::move(req)); } -std::shared_ptr<RpcConnection> RpcClient::GetConnection( - std::shared_ptr<ConnectionId> remote_id) { +std::shared_ptr<RpcConnection> RpcClient::GetConnection(std::shared_ptr<ConnectionId> remote_id) { return cp_->GetConnection(remote_id); } -std::shared_ptr<RpcChannel> RpcClient::CreateRpcChannel( - const std::string& host, uint16_t port, std::shared_ptr<User> ticket, - int rpc_timeout) { - std::shared_ptr<RpcChannelImplementation> channel = - std::make_shared<RpcChannelImplementation>(shared_from_this(), host, port, - ticket, rpc_timeout); +std::shared_ptr<RpcChannel> RpcClient::CreateRpcChannel(const std::string& host, uint16_t port, + std::shared_ptr<User> ticket, + int rpc_timeout) { + std::shared_ptr<RpcChannelImplementation> channel = std::make_shared<RpcChannelImplementation>( + shared_from_this(), host, port, ticket, rpc_timeout); /* static_pointer_cast is safe since RpcChannelImplementation derives * from RpcChannel, otherwise, dynamic_pointer_cast should be used. */ return std::static_pointer_cast<RpcChannel>(channel); } -void RpcClient::CallMethod(const MethodDescriptor* method, - RpcController* controller, const Message* req_msg, - Message* resp_msg, Closure* done, - const std::string& host, uint16_t port, - std::shared_ptr<User> ticket) { +void RpcClient::CallMethod(const MethodDescriptor* method, RpcController* controller, + const Message* req_msg, Message* resp_msg, Closure* done, + const std::string& host, uint16_t port, std::shared_ptr<User> ticket) { std::shared_ptr<Message> shared_req(const_cast<Message*>(req_msg)); std::shared_ptr<Message> shared_resp(resp_msg); - std::unique_ptr<Request> req = - std::make_unique<Request>(shared_req, shared_resp, method->name()); + std::unique_ptr<Request> req = std::make_unique<Request>(shared_req, shared_resp, method->name()); AsyncCall(host, port, std::move(req), ticket, method->service()->name()) - .then([done, this](Response resp) { - done->Run(); - }); + .then([done, this](Response resp) { done->Run(); }); } http://git-wip-us.apache.org/repos/asf/hbase/blob/fe69c81d/hbase-native-client/connection/rpc-client.h ---------------------------------------------------------------------- diff --git a/hbase-native-client/connection/rpc-client.h b/hbase-native-client/connection/rpc-client.h index dbf857d..407d588 100644 --- a/hbase-native-client/connection/rpc-client.h +++ b/hbase-native-client/connection/rpc-client.h @@ -53,41 +53,35 @@ class RpcClient : public std::enable_shared_from_this<RpcClient> { virtual ~RpcClient() { Close(); } - virtual std::shared_ptr<Response> SyncCall(const std::string &host, - uint16_t port, + virtual std::shared_ptr<Response> SyncCall(const std::string &host, uint16_t port, std::unique_ptr<Request> req, std::shared_ptr<User> ticket); - virtual std::shared_ptr<Response> SyncCall(const std::string &host, - uint16_t port, + virtual std::shared_ptr<Response> SyncCall(const std::string &host, uint16_t port, std::unique_ptr<Request> req, std::shared_ptr<User> ticket, const std::string &service_name); - virtual folly::Future<Response> AsyncCall(const std::string &host, - uint16_t port, + virtual folly::Future<Response> AsyncCall(const std::string &host, uint16_t port, std::unique_ptr<Request> req, std::shared_ptr<User> ticket); - virtual folly::Future<Response> AsyncCall(const std::string &host, - uint16_t port, + virtual folly::Future<Response> AsyncCall(const std::string &host, uint16_t port, std::unique_ptr<Request> req, std::shared_ptr<User> ticket, const std::string &service_name); virtual void Close(); - virtual std::shared_ptr<RpcChannel> CreateRpcChannel( - const std::string &host, uint16_t port, std::shared_ptr<User> ticket, - int rpc_timeout); + virtual std::shared_ptr<RpcChannel> CreateRpcChannel(const std::string &host, uint16_t port, + std::shared_ptr<User> ticket, + int rpc_timeout); private: - void CallMethod(const MethodDescriptor *method, RpcController *controller, - const Message *req_msg, Message *resp_msg, Closure *done, - const std::string &host, uint16_t port, + void CallMethod(const MethodDescriptor *method, RpcController *controller, const Message *req_msg, + Message *resp_msg, Closure *done, const std::string &host, uint16_t port, std::shared_ptr<User> ticket); - std::shared_ptr<RpcConnection> GetConnection( - std::shared_ptr<ConnectionId> remote_id); + std::shared_ptr<RpcConnection> GetConnection(std::shared_ptr<ConnectionId> remote_id); private: std::shared_ptr<ConnectionPool> cp_; @@ -96,8 +90,7 @@ class RpcClient : public std::enable_shared_from_this<RpcClient> { class AbstractRpcChannel : public RpcChannel { public: - AbstractRpcChannel(std::shared_ptr<RpcClient> rpc_client, - const std::string &host, uint16_t port, + AbstractRpcChannel(std::shared_ptr<RpcClient> rpc_client, const std::string &host, uint16_t port, std::shared_ptr<User> ticket, int rpc_timeout) : rpc_client_(rpc_client), host_(host), http://git-wip-us.apache.org/repos/asf/hbase/blob/fe69c81d/hbase-native-client/connection/rpc-connection.h ---------------------------------------------------------------------- diff --git a/hbase-native-client/connection/rpc-connection.h b/hbase-native-client/connection/rpc-connection.h index 2e06ec3..e2500b2 100644 --- a/hbase-native-client/connection/rpc-connection.h +++ b/hbase-native-client/connection/rpc-connection.h @@ -37,13 +37,9 @@ class RpcConnection { virtual ~RpcConnection() { Close(); } - virtual std::shared_ptr<ConnectionId> remote_id() const { - return connection_id_; - } + virtual std::shared_ptr<ConnectionId> remote_id() const { return connection_id_; } - virtual std::shared_ptr<HBaseService> get_service() const { - return hbase_service_; - } + virtual std::shared_ptr<HBaseService> get_service() const { return hbase_service_; } virtual folly::Future<Response> SendRequest(std::unique_ptr<Request> req) { return (*hbase_service_)(std::move(req)); http://git-wip-us.apache.org/repos/asf/hbase/blob/fe69c81d/hbase-native-client/core/cell-test.cc ---------------------------------------------------------------------- diff --git a/hbase-native-client/core/cell-test.cc b/hbase-native-client/core/cell-test.cc index 53574e8..fb4d033 100644 --- a/hbase-native-client/core/cell-test.cc +++ b/hbase-native-client/core/cell-test.cc @@ -32,8 +32,7 @@ TEST(CellTest, CellFailureTest) { std::string value = "value"; int64_t timestamp = std::numeric_limits<int64_t>::max(); std::string tags = ""; - std::unique_ptr<Cell> cell( - new Cell(row, family, column, timestamp, value, cell_type)); + std::unique_ptr<Cell> cell(new Cell(row, family, column, timestamp, value, cell_type)); if (cell.get()) { EXPECT_NE("row-value", cell.get()->Row()); EXPECT_NE("family-value", cell.get()->Family()); @@ -51,8 +50,7 @@ TEST(CellTest, CellSuceessTest) { std::string value = "value-value"; int64_t timestamp = std::numeric_limits<int64_t>::max(); CellType cell_type = CellType::PUT; - const std::unique_ptr<Cell> cell( - new Cell(row, family, column, timestamp, value, cell_type)); + const std::unique_ptr<Cell> cell(new Cell(row, family, column, timestamp, value, cell_type)); if (cell.get()) { EXPECT_EQ(row, cell.get()->Row()); EXPECT_EQ(family, cell.get()->Family()); @@ -74,8 +72,7 @@ TEST(CellTest, MultipleCellsTest) { row += std::to_string(i); value += std::to_string(i); CellType cell_type = CellType::PUT; - const Cell *cell = - new Cell(row, family, column, timestamp, value, cell_type); + const Cell *cell = new Cell(row, family, column, timestamp, value, cell_type); cells.push_back(cell); } int i = 0; @@ -105,8 +102,7 @@ TEST(CellTest, CellRowTest) { std::string value = ""; int64_t timestamp = std::numeric_limits<int64_t>::max(); CellType cell_type = CellType::PUT; - std::unique_ptr<Cell> cell( - new Cell(row, family, column, timestamp, value, cell_type)); + std::unique_ptr<Cell> cell(new Cell(row, family, column, timestamp, value, cell_type)); if (cell.get()) { EXPECT_EQ(row, cell.get()->Row()); EXPECT_EQ(family, cell.get()->Family()); @@ -124,8 +120,7 @@ TEST(CellTest, CellRowFamilyTest) { std::string value = ""; int64_t timestamp = std::numeric_limits<int64_t>::max(); CellType cell_type = CellType::PUT; - const std::unique_ptr<Cell> cell( - new Cell(row, family, column, timestamp, value, cell_type)); + const std::unique_ptr<Cell> cell(new Cell(row, family, column, timestamp, value, cell_type)); if (cell.get()) { EXPECT_EQ(row, cell.get()->Row()); EXPECT_EQ(family, cell.get()->Family()); @@ -143,8 +138,7 @@ TEST(CellTest, CellRowFamilyValueTest) { std::string value = "only-value"; int64_t timestamp = std::numeric_limits<int64_t>::max(); CellType cell_type = CellType::PUT; - const std::unique_ptr<Cell> cell( - new Cell(row, family, column, timestamp, value, cell_type)); + const std::unique_ptr<Cell> cell(new Cell(row, family, column, timestamp, value, cell_type)); if (cell.get()) { EXPECT_EQ(row, cell.get()->Row()); EXPECT_EQ(family, cell.get()->Family()); @@ -162,8 +156,7 @@ TEST(CellTest, CellRowFamilyColumnValueTest) { std::string value = "only-value"; int64_t timestamp = std::numeric_limits<int64_t>::max(); CellType cell_type = CellType::PUT; - std::unique_ptr<Cell> cell( - new Cell(row, family, column, timestamp, value, cell_type)); + std::unique_ptr<Cell> cell(new Cell(row, family, column, timestamp, value, cell_type)); if (cell.get()) { EXPECT_EQ(row, cell.get()->Row()); EXPECT_EQ(family, cell.get()->Family()); http://git-wip-us.apache.org/repos/asf/hbase/blob/fe69c81d/hbase-native-client/core/cell.cc ---------------------------------------------------------------------- diff --git a/hbase-native-client/core/cell.cc b/hbase-native-client/core/cell.cc index 3102e53..4982406 100644 --- a/hbase-native-client/core/cell.cc +++ b/hbase-native-client/core/cell.cc @@ -22,9 +22,8 @@ namespace hbase { -Cell::Cell(const std::string &row, const std::string &family, - const std::string &qualifier, const int64_t timestamp, - const std::string &value, const hbase::CellType &cell_type) +Cell::Cell(const std::string &row, const std::string &family, const std::string &qualifier, + const int64_t timestamp, const std::string &value, const hbase::CellType &cell_type) : row_(row), family_(family), qualifier_(qualifier), @@ -32,14 +31,11 @@ Cell::Cell(const std::string &row, const std::string &family, cell_type_(cell_type), value_(value), sequence_id_(0) { - if (0 == row.size()) - throw std::runtime_error("Row size should be greater than 0"); + if (0 == row.size()) throw std::runtime_error("Row size should be greater than 0"); - if (0 == family.size()) - throw std::runtime_error("Column family size should be greater than 0"); + if (0 == family.size()) throw std::runtime_error("Column family size should be greater than 0"); - if (0 >= timestamp) - throw std::runtime_error("Timestamp should be greater than 0"); + if (0 >= timestamp) throw std::runtime_error("Timestamp should be greater than 0"); } Cell::~Cell() {} http://git-wip-us.apache.org/repos/asf/hbase/blob/fe69c81d/hbase-native-client/core/cell.h ---------------------------------------------------------------------- diff --git a/hbase-native-client/core/cell.h b/hbase-native-client/core/cell.h index f55655c..5a39dc3 100644 --- a/hbase-native-client/core/cell.h +++ b/hbase-native-client/core/cell.h @@ -36,9 +36,8 @@ enum CellType { class Cell { public: - Cell(const std::string &row, const std::string &family, - const std::string &qualifier, const int64_t timestamp, - const std::string &value, const hbase::CellType &cell_type); + Cell(const std::string &row, const std::string &family, const std::string &qualifier, + const int64_t timestamp, const std::string &value, const hbase::CellType &cell_type); virtual ~Cell(); const std::string &Row() const; const std::string &Family() const; http://git-wip-us.apache.org/repos/asf/hbase/blob/fe69c81d/hbase-native-client/core/client-test.cc ---------------------------------------------------------------------- diff --git a/hbase-native-client/core/client-test.cc b/hbase-native-client/core/client-test.cc index 0fe0225..28eec6f 100644 --- a/hbase-native-client/core/client-test.cc +++ b/hbase-native-client/core/client-test.cc @@ -17,8 +17,8 @@ * */ -#include <gtest/gtest.h> #include "core/client.h" +#include <gtest/gtest.h> #include "core/configuration.h" #include "core/get.h" #include "core/hbase_configuration_loader.h" @@ -84,9 +84,7 @@ const std::string ClientTest::kHBaseXmlData( "the License.\n " "*/\n-->\n<configuration>\n\n</configuration>"); -TEST(Client, EmptyConfigurationPassedToClient) { - ASSERT_ANY_THROW(hbase::Client client); -} +TEST(Client, EmptyConfigurationPassedToClient) { ASSERT_ANY_THROW(hbase::Client client); } TEST(Client, ConfigurationPassedToClient) { // Remove already configured env if present. http://git-wip-us.apache.org/repos/asf/hbase/blob/fe69c81d/hbase-native-client/core/client.h ---------------------------------------------------------------------- diff --git a/hbase-native-client/core/client.h b/hbase-native-client/core/client.h index 2bb506b..da71624 100644 --- a/hbase-native-client/core/client.h +++ b/hbase-native-client/core/client.h @@ -27,13 +27,13 @@ #include <memory> #include <string> +#include "connection/rpc-client.h" #include "core/configuration.h" #include "core/hbase_configuration_loader.h" #include "core/location-cache.h" -#include "connection/rpc-client.h" #include "core/table.h" -#include "serde/table-name.h" #include "if/Cell.pb.h" +#include "serde/table-name.h" using hbase::pb::TableName; http://git-wip-us.apache.org/repos/asf/hbase/blob/fe69c81d/hbase-native-client/core/configuration.cc ---------------------------------------------------------------------- diff --git a/hbase-native-client/core/configuration.cc b/hbase-native-client/core/configuration.cc index 134f05f..bd582d8 100644 --- a/hbase-native-client/core/configuration.cc +++ b/hbase-native-client/core/configuration.cc @@ -28,13 +28,11 @@ namespace hbase { -Configuration::Configuration(ConfigMap &config_map) - : hb_property_(std::move(config_map)) {} +Configuration::Configuration(ConfigMap &config_map) : hb_property_(std::move(config_map)) {} Configuration::~Configuration() {} -size_t Configuration::IsSubVariable(const std::string &expr, - std::string &sub_variable) const { +size_t Configuration::IsSubVariable(const std::string &expr, std::string &sub_variable) const { size_t start_pos = expr.find("${"); if (std::string::npos != start_pos) { size_t pos_next = expr.find("}", start_pos + 1); @@ -57,8 +55,7 @@ std::string Configuration::SubstituteVars(const std::string &expr) const { if (start_pos != std::string::npos) { // We are blindly checking for environment property at first. // If we don't get any value from GetEnv, check in hbase-site.xml. - value_to_be_replaced = - GetEnv(var).value_or(GetProperty(var).value_or("")); + value_to_be_replaced = GetEnv(var).value_or(GetProperty(var).value_or("")); // we haven't found any value yet so we are returning eval if (0 == value_to_be_replaced.size()) { @@ -148,8 +145,7 @@ optional<std::string> Configuration::Get(const std::string &key) const { } } -std::string Configuration::Get(const std::string &key, - const std::string &default_value) const { +std::string Configuration::Get(const std::string &key, const std::string &default_value) const { return Get(key).value_or(default_value); } @@ -157,8 +153,7 @@ optional<int32_t> Configuration::GetInt(const std::string &key) const { optional<std::string> raw = Get(key); if (raw) { try { - return std::experimental::make_optional( - boost::lexical_cast<int32_t>(*raw)); + return std::experimental::make_optional(boost::lexical_cast<int32_t>(*raw)); } catch (const boost::bad_lexical_cast &blex) { throw std::runtime_error(blex.what()); } @@ -166,8 +161,7 @@ optional<int32_t> Configuration::GetInt(const std::string &key) const { return optional<int32_t>(); } -int32_t Configuration::GetInt(const std::string &key, - int32_t default_value) const { +int32_t Configuration::GetInt(const std::string &key, int32_t default_value) const { return GetInt(key).value_or(default_value); } @@ -175,8 +169,7 @@ optional<int64_t> Configuration::GetLong(const std::string &key) const { optional<std::string> raw = Get(key); if (raw) { try { - return std::experimental::make_optional( - boost::lexical_cast<int64_t>(*raw)); + return std::experimental::make_optional(boost::lexical_cast<int64_t>(*raw)); } catch (const boost::bad_lexical_cast &blex) { throw std::runtime_error(blex.what()); } @@ -184,8 +177,7 @@ optional<int64_t> Configuration::GetLong(const std::string &key) const { return optional<int64_t>(); } -int64_t Configuration::GetLong(const std::string &key, - int64_t default_value) const { +int64_t Configuration::GetLong(const std::string &key, int64_t default_value) const { return GetLong(key).value_or(default_value); } @@ -193,8 +185,7 @@ optional<double> Configuration::GetDouble(const std::string &key) const { optional<std::string> raw = Get(key); if (raw) { try { - return std::experimental::make_optional( - boost::lexical_cast<double>(*raw)); + return std::experimental::make_optional(boost::lexical_cast<double>(*raw)); } catch (const boost::bad_lexical_cast &blex) { throw std::runtime_error(blex.what()); } @@ -202,8 +193,7 @@ optional<double> Configuration::GetDouble(const std::string &key) const { return optional<double>(); } -double Configuration::GetDouble(const std::string &key, - double default_value) const { +double Configuration::GetDouble(const std::string &key, double default_value) const { return GetDouble(key).value_or(default_value); } @@ -215,8 +205,7 @@ optional<bool> Configuration::GetBool(const std::string &key) const { } else if (!strcasecmp((*raw).c_str(), "false")) { return std::experimental::make_optional(false); } else { - throw std::runtime_error( - "Unexpected value found while conversion to bool."); + throw std::runtime_error("Unexpected value found while conversion to bool."); } } return optional<bool>(); http://git-wip-us.apache.org/repos/asf/hbase/blob/fe69c81d/hbase-native-client/core/configuration.h ---------------------------------------------------------------------- diff --git a/hbase-native-client/core/configuration.h b/hbase-native-client/core/configuration.h index f09bbac..69bef75 100644 --- a/hbase-native-client/core/configuration.h +++ b/hbase-native-client/core/configuration.h @@ -41,8 +41,7 @@ class Configuration { * @param key Property whose value is to be fetched. SubstituteVars will be * called for any variable expansion. */ - std::string Get(const std::string &key, - const std::string &default_value) const; + std::string Get(const std::string &key, const std::string &default_value) const; /** * @brief Returns int32_t identified by key in ConfigMap else default value if @@ -89,8 +88,7 @@ class Configuration { std::string value; bool final; ConfigData() : final(false) {} - explicit ConfigData(const std::string &value) - : value(value), final(false) {} + explicit ConfigData(const std::string &value) : value(value), final(false) {} void operator=(const std::string &new_value) { value = new_value; final = false; @@ -174,8 +172,7 @@ class Configuration { * @param sub_variable Extracted variable from expr which will be checked * against environment value or ConfigMap values. */ - size_t IsSubVariable(const std::string &expr, - std::string &sub_variable) const; + size_t IsSubVariable(const std::string &expr, std::string &sub_variable) const; /** * @brief This method will fetch value for key from environment if present. http://git-wip-us.apache.org/repos/asf/hbase/blob/fe69c81d/hbase-native-client/core/get-test.cc ---------------------------------------------------------------------- diff --git a/hbase-native-client/core/get-test.cc b/hbase-native-client/core/get-test.cc index cef99b9..07d0003 100644 --- a/hbase-native-client/core/get-test.cc +++ b/hbase-native-client/core/get-test.cc @@ -121,8 +121,7 @@ void GetMethods(Get &get, const std::string &row) { // Test initial values EXPECT_EQ(0, get.Timerange().MinTimeStamp()); - EXPECT_EQ(std::numeric_limits<int64_t>::max(), - get.Timerange().MaxTimeStamp()); + EXPECT_EQ(std::numeric_limits<int64_t>::max(), get.Timerange().MaxTimeStamp()); // Set & Test new values using TimeRange and TimeStamp get.SetTimeRange(1000, 2000); @@ -136,13 +135,11 @@ void GetMethods(Get &get, const std::string &row) { ASSERT_THROW(get.SetTimeRange(-1000, 2000), std::runtime_error); ASSERT_THROW(get.SetTimeRange(1000, -2000), std::runtime_error); ASSERT_THROW(get.SetTimeRange(1000, 200), std::runtime_error); - ASSERT_THROW(get.SetTimeStamp(std::numeric_limits<int64_t>::max()), - std::runtime_error); + ASSERT_THROW(get.SetTimeStamp(std::numeric_limits<int64_t>::max()), std::runtime_error); // Test some exceptions ASSERT_THROW(get.SetMaxVersions(0), std::runtime_error); - ASSERT_THROW(get.SetMaxVersions(std::numeric_limits<uint32_t>::max() + 1), - std::runtime_error); + ASSERT_THROW(get.SetMaxVersions(std::numeric_limits<uint32_t>::max() + 1), std::runtime_error); } TEST(Get, SingleGet) { http://git-wip-us.apache.org/repos/asf/hbase/blob/fe69c81d/hbase-native-client/core/get.cc ---------------------------------------------------------------------- diff --git a/hbase-native-client/core/get.cc b/hbase-native-client/core/get.cc index 6ba4e86..5c5f446 100644 --- a/hbase-native-client/core/get.cc +++ b/hbase-native-client/core/get.cc @@ -34,8 +34,7 @@ Get::Get(const Get &get) { cache_blocks_ = get.cache_blocks_; check_existence_only_ = get.check_existence_only_; consistency_ = get.consistency_; - tr_.reset(new TimeRange(get.Timerange().MinTimeStamp(), - get.Timerange().MaxTimeStamp())); + tr_.reset(new TimeRange(get.Timerange().MinTimeStamp(), get.Timerange().MaxTimeStamp())); family_map_.insert(get.family_map_.begin(), get.family_map_.end()); } @@ -45,8 +44,7 @@ Get &Get::operator=(const Get &get) { cache_blocks_ = get.cache_blocks_; check_existence_only_ = get.check_existence_only_; consistency_ = get.consistency_; - tr_.reset(new TimeRange(get.Timerange().MinTimeStamp(), - get.Timerange().MaxTimeStamp())); + tr_.reset(new TimeRange(get.Timerange().MinTimeStamp(), get.Timerange().MaxTimeStamp())); family_map_.insert(get.family_map_.begin(), get.family_map_.end()); return *this; } @@ -68,8 +66,7 @@ Get &Get::AddFamily(const std::string &family) { } Get &Get::AddColumn(const std::string &family, const std::string &qualifier) { - const auto &it = std::find(family_map_[family].begin(), - family_map_[family].end(), qualifier); + const auto &it = std::find(family_map_[family].begin(), family_map_[family].end(), qualifier); /** * Check if any qualifiers are already present or not. @@ -97,8 +94,7 @@ const FamilyMap &Get::Family() const { return family_map_; } int Get::MaxVersions() const { return max_versions_; } Get &Get::SetMaxVersions(int32_t max_versions) { - if (0 == max_versions) - throw std::runtime_error("max_versions must be positive"); + if (0 == max_versions) throw std::runtime_error("max_versions must be positive"); max_versions_ = max_versions; return *this; @@ -130,8 +126,7 @@ void Get::CheckRow(const std::string &row) { throw std::runtime_error("Row length can't be 0"); } if (row_length > kMaxRowLength) { - throw std::runtime_error("Length of " + row + - " is greater than max row size: " + + throw std::runtime_error("Length of " + row + " is greater than max row size: " + std::to_string(kMaxRowLength)); } } http://git-wip-us.apache.org/repos/asf/hbase/blob/fe69c81d/hbase-native-client/core/hbase_configuration-test.cc ---------------------------------------------------------------------- diff --git a/hbase-native-client/core/hbase_configuration-test.cc b/hbase-native-client/core/hbase_configuration-test.cc index eec500e..07a6358 100644 --- a/hbase-native-client/core/hbase_configuration-test.cc +++ b/hbase-native-client/core/hbase_configuration-test.cc @@ -28,10 +28,8 @@ using namespace hbase; -const std::string kDefHBaseConfPath( - "./build/test-data/hbase-configuration-test/conf/"); -const std::string kHBaseConfPath( - "./build/test-data/hbase-configuration-test/custom-conf/"); +const std::string kDefHBaseConfPath("./build/test-data/hbase-configuration-test/conf/"); +const std::string kHBaseConfPath("./build/test-data/hbase-configuration-test/custom-conf/"); const std::string kHBaseDefaultXml("hbase-default.xml"); const std::string kHBaseSiteXml("hbase-site.xml"); @@ -121,8 +119,7 @@ void WriteDataToFile(const std::string &file, const std::string &xml_data) { hbase_conf.close(); } -void CreateHBaseConf(const std::string &dir, const std::string &file, - const std::string xml_data) { +void CreateHBaseConf(const std::string &dir, const std::string &file, const std::string xml_data) { // Directory will be created if not present if (!boost::filesystem::exists(dir)) { boost::filesystem::create_directories(dir); @@ -153,10 +150,8 @@ TEST(Configuration, LoadConfFromDefaultLocation) { HBaseConfigurationLoader loader; hbase::optional<Configuration> conf = loader.LoadDefaultResources(); ASSERT_TRUE(conf) << "No configuration object present."; - EXPECT_STREQ((*conf).Get("custom-prop", "Set this value").c_str(), - "custom-value"); - EXPECT_STREQ((*conf).Get("default-prop", "Set this value").c_str(), - "default-value"); + EXPECT_STREQ((*conf).Get("custom-prop", "Set this value").c_str(), "custom-value"); + EXPECT_STREQ((*conf).Get("default-prop", "Set this value").c_str(), "default-value"); } /* @@ -170,8 +165,7 @@ TEST(Configuration, LoadConfFromCustomLocation) { HBaseConfigurationLoader loader; std::vector<std::string> resources{kHBaseSiteXml}; - hbase::optional<Configuration> conf = - loader.LoadResources(kHBaseConfPath, resources); + hbase::optional<Configuration> conf = loader.LoadResources(kHBaseConfPath, resources); ASSERT_TRUE(conf) << "No configuration object present."; EXPECT_STREQ((*conf).Get("custom-prop", "").c_str(), "custom-value"); EXPECT_STRNE((*conf).Get("custom-prop", "").c_str(), "some-value"); @@ -192,11 +186,9 @@ TEST(Configuration, LoadConfFromMultipleLocatons) { HBaseConfigurationLoader loader; std::string conf_paths = kDefHBaseConfPath + ":" + kHBaseConfPath; std::vector<std::string> resources{kHBaseDefaultXml, kHBaseSiteXml}; - hbase::optional<Configuration> conf = - loader.LoadResources(conf_paths, resources); + hbase::optional<Configuration> conf = loader.LoadResources(conf_paths, resources); ASSERT_TRUE(conf) << "No configuration object present."; - EXPECT_STREQ((*conf).Get("default-prop", "From hbase-default.xml").c_str(), - "default-value"); + EXPECT_STREQ((*conf).Get("default-prop", "From hbase-default.xml").c_str(), "default-value"); EXPECT_STREQ((*conf).Get("custom-prop", "").c_str(), "custom-value"); EXPECT_STRNE((*conf).Get("custom-prop", "").c_str(), "some-value"); } @@ -215,10 +207,8 @@ TEST(Configuration, DefaultValues) { HBaseConfigurationLoader loader; hbase::optional<Configuration> conf = loader.LoadDefaultResources(); ASSERT_TRUE(conf) << "No configuration object present."; - EXPECT_STREQ((*conf).Get("default-prop", "Set this value.").c_str(), - "default-value"); - EXPECT_STREQ((*conf).Get("custom-prop", "Set this value.").c_str(), - "custom-value"); + EXPECT_STREQ((*conf).Get("default-prop", "Set this value.").c_str(), "default-value"); + EXPECT_STREQ((*conf).Get("custom-prop", "Set this value.").c_str(), "custom-value"); } TEST(Configuration, FinalValues) { @@ -229,12 +219,10 @@ TEST(Configuration, FinalValues) { HBaseConfigurationLoader loader; hbase::optional<Configuration> conf = loader.LoadDefaultResources(); ASSERT_TRUE(conf) << "No configuration object present."; - EXPECT_STREQ((*conf).Get("hbase.rootdir", "").c_str(), - "/root/hbase-docker/apps/hbase/data"); + EXPECT_STREQ((*conf).Get("hbase.rootdir", "").c_str(), "/root/hbase-docker/apps/hbase/data"); EXPECT_STREQ((*conf).Get("hbase.zookeeper.property.datadir", "").c_str(), "/root/hbase-docker/zookeeper"); - EXPECT_STRNE((*conf).Get("hbase.rootdir", "").c_str(), - "This value will not be be overwritten"); + EXPECT_STRNE((*conf).Get("hbase.rootdir", "").c_str(), "This value will not be be overwritten"); EXPECT_STRNE((*conf).Get("hbase.zookeeper.property.datadir", "").c_str(), "This value will be overwritten"); } @@ -253,10 +241,8 @@ TEST(Configuration, EnvVars) { HBaseConfigurationLoader loader; hbase::optional<Configuration> conf = loader.LoadDefaultResources(); ASSERT_TRUE(conf) << "No configuration object present."; - EXPECT_STREQ((*conf).Get("hbase-client.user.name", "").c_str(), - "${user.name}"); - EXPECT_STRNE((*conf).Get("hbase-client.user.name", "root").c_str(), - "test-user"); + EXPECT_STREQ((*conf).Get("hbase-client.user.name", "").c_str(), "${user.name}"); + EXPECT_STRNE((*conf).Get("hbase-client.user.name", "root").c_str(), "test-user"); } TEST(Configuration, SelfRef) { @@ -292,8 +278,7 @@ TEST(Configuration, VarExpansionException) { HBaseConfigurationLoader loader; hbase::optional<Configuration> conf = loader.LoadDefaultResources(); ASSERT_TRUE(conf) << "No configuration object present."; - ASSERT_THROW((*conf).Get("foo.substs.exception", "foo-value").c_str(), - std::runtime_error); + ASSERT_THROW((*conf).Get("foo.substs.exception", "foo-value").c_str(), std::runtime_error); } TEST(Configuration, GetInt) { http://git-wip-us.apache.org/repos/asf/hbase/blob/fe69c81d/hbase-native-client/core/hbase_configuration_loader.cc ---------------------------------------------------------------------- diff --git a/hbase-native-client/core/hbase_configuration_loader.cc b/hbase-native-client/core/hbase_configuration_loader.cc index 20d0449..38a617b 100644 --- a/hbase-native-client/core/hbase_configuration_loader.cc +++ b/hbase-native-client/core/hbase_configuration_loader.cc @@ -94,8 +94,7 @@ void HBaseConfigurationLoader::AddToSearchPath(const std::string &search_path) { if (search_path.back() != kFileSeparator) { path_to_add += kFileSeparator; } - if (std::find(search_paths_.begin(), search_paths_.end(), path_to_add) == - search_paths_.end()) + if (std::find(search_paths_.begin(), search_paths_.end(), path_to_add) == search_paths_.end()) search_paths_.push_back(path_to_add); } @@ -105,8 +104,7 @@ void HBaseConfigurationLoader::AddDefaultResources() { } void HBaseConfigurationLoader::AddResources(const std::string &filename) { - if (std::find(resources_.begin(), resources_.end(), filename) == - resources_.end()) + if (std::find(resources_.begin(), resources_.end(), filename) == resources_.end()) resources_.push_back(filename); } @@ -127,8 +125,7 @@ optional<Configuration> HBaseConfigurationLoader::LoadDefaultResources() { } } if (success) { - return std::experimental::make_optional<Configuration>( - Configuration(conf_property)); + return std::experimental::make_optional<Configuration>(Configuration(conf_property)); } else { return optional<Configuration>(); } @@ -152,15 +149,13 @@ optional<Configuration> HBaseConfigurationLoader::LoadResources( } } if (success) { - return std::experimental::make_optional<Configuration>( - Configuration(conf_property)); + return std::experimental::make_optional<Configuration>(Configuration(conf_property)); } else { return optional<Configuration>(); } } -bool HBaseConfigurationLoader::LoadProperties(const std::string &file, - ConfigMap &property_map) { +bool HBaseConfigurationLoader::LoadProperties(const std::string &file, ConfigMap &property_map) { // Create empty property tree object using boost::property_tree::ptree; ptree pt; @@ -179,23 +174,21 @@ bool HBaseConfigurationLoader::LoadProperties(const std::string &file, std::string name_node = v.second.get<std::string>("name"); std::string value_node = v.second.get<std::string>("value"); if ((name_node.size() > 0) && (value_node.size() > 0)) { - boost::optional<std::string> final_node = - v.second.get_optional<std::string>("final"); + boost::optional<std::string> final_node = v.second.get_optional<std::string>("final"); UpdateMapWithValue(property_map, name_node, value_node, final_node); } } } } catch (std::exception &ex) { - DLOG(WARNING) << "Exception in parsing file [" << file << "]:[" << ex.what() - << "]"; + DLOG(WARNING) << "Exception in parsing file [" << file << "]:[" << ex.what() << "]"; return false; } return true; } -bool HBaseConfigurationLoader::UpdateMapWithValue( - ConfigMap &map, const std::string &key, const std::string &value, - boost::optional<std::string> final_text) { +bool HBaseConfigurationLoader::UpdateMapWithValue(ConfigMap &map, const std::string &key, + const std::string &value, + boost::optional<std::string> final_text) { auto map_value = map.find(key); if (map_value != map.end() && map_value->second.final) { return false; http://git-wip-us.apache.org/repos/asf/hbase/blob/fe69c81d/hbase-native-client/core/hbase_configuration_loader.h ---------------------------------------------------------------------- diff --git a/hbase-native-client/core/hbase_configuration_loader.h b/hbase-native-client/core/hbase_configuration_loader.h index 49dc2b9..a1c1d3f 100644 --- a/hbase-native-client/core/hbase_configuration_loader.h +++ b/hbase-native-client/core/hbase_configuration_loader.h @@ -58,9 +58,8 @@ class HBaseConfigurationLoader { * @param search_path - ':' search paths to load resources. * @param resources - list of resources used to load configuration properties. */ - optional<Configuration> LoadResources( - const std::string &search_path, - const std::vector<std::string> &resources); + optional<Configuration> LoadResources(const std::string &search_path, + const std::vector<std::string> &resources); private: using ConfigMap = Configuration::ConfigMap; @@ -137,8 +136,7 @@ class HBaseConfigurationLoader { * @param value value of value node. * @param final_text value of final node true or false if present */ - bool UpdateMapWithValue(ConfigMap &map, const std::string &key, - const std::string &value, + bool UpdateMapWithValue(ConfigMap &map, const std::string &key, const std::string &value, boost::optional<std::string> final_text); }; http://git-wip-us.apache.org/repos/asf/hbase/blob/fe69c81d/hbase-native-client/core/location-cache.cc ---------------------------------------------------------------------- diff --git a/hbase-native-client/core/location-cache.cc b/hbase-native-client/core/location-cache.cc index 4c29a61..6c2a790 100644 --- a/hbase-native-client/core/location-cache.cc +++ b/hbase-native-client/core/location-cache.cc @@ -53,10 +53,9 @@ using hbase::pb::RegionInfo; // TODO(eclark): make this configurable on client creation static const char META_ZNODE_NAME[] = "/hbase/meta-region-server"; -LocationCache::LocationCache( - std::string quorum_spec, - std::shared_ptr<wangle::CPUThreadPoolExecutor> cpu_executor, - std::shared_ptr<wangle::IOThreadPoolExecutor> io_executor) +LocationCache::LocationCache(std::string quorum_spec, + std::shared_ptr<wangle::CPUThreadPoolExecutor> cpu_executor, + std::shared_ptr<wangle::IOThreadPoolExecutor> io_executor) : quorum_spec_(quorum_spec), cpu_executor_(cpu_executor), meta_promise_(nullptr), @@ -91,9 +90,7 @@ void LocationCache::InvalidateMeta() { /// MUST hold the meta_lock_ void LocationCache::RefreshMetaLocation() { meta_promise_ = make_unique<SharedPromise<ServerName>>(); - cpu_executor_->add([&] { - meta_promise_->setWith([&] { return this->ReadMetaLocation(); }); - }); + cpu_executor_->add([&] { meta_promise_->setWith([&] { return this->ReadMetaLocation(); }); }); } ServerName LocationCache::ReadMetaLocation() { @@ -103,9 +100,8 @@ ServerName LocationCache::ReadMetaLocation() { // This needs to be int rather than size_t as that's what ZK expects. int len = buf->capacity(); // TODO(elliott): handle disconnects/reconntion as needed. - int zk_result = - zoo_get(this->zk_, META_ZNODE_NAME, 0, - reinterpret_cast<char *>(buf->writableData()), &len, nullptr); + int zk_result = zoo_get(this->zk_, META_ZNODE_NAME, 0, + reinterpret_cast<char *>(buf->writableData()), &len, nullptr); if (zk_result != ZOK || len < 9) { LOG(ERROR) << "Error getting meta location."; throw runtime_error("Error getting meta location"); @@ -119,18 +115,16 @@ ServerName LocationCache::ReadMetaLocation() { return mrs.server(); } -Future<std::shared_ptr<RegionLocation>> LocationCache::LocateFromMeta( - const TableName &tn, const string &row) { +Future<std::shared_ptr<RegionLocation>> LocationCache::LocateFromMeta(const TableName &tn, + const string &row) { return this->LocateMeta() .via(cpu_executor_.get()) .then([this](ServerName sn) { - auto remote_id = - std::make_shared<ConnectionId>(sn.host_name(), sn.port()); + auto remote_id = std::make_shared<ConnectionId>(sn.host_name(), sn.port()); return this->cp_.GetConnection(remote_id); }) .then([tn, row, this](std::shared_ptr<RpcConnection> rpc_connection) { - return (*rpc_connection->get_service())( - std::move(meta_util_.MetaRequest(tn, row))); + return (*rpc_connection->get_service())(std::move(meta_util_.MetaRequest(tn, row))); }) .then([this](Response resp) { // take the protobuf response and make it into @@ -146,16 +140,15 @@ Future<std::shared_ptr<RegionLocation>> LocationCache::LocateFromMeta( return rl; }) .then([this](std::shared_ptr<RegionLocation> rl) { - auto remote_id = std::make_shared<ConnectionId>( - rl->server_name().host_name(), rl->server_name().port()); + auto remote_id = + std::make_shared<ConnectionId>(rl->server_name().host_name(), rl->server_name().port()); // Now fill out the connection. rl->set_service(cp_.GetConnection(remote_id)->get_service()); return rl; }); } -std::shared_ptr<RegionLocation> LocationCache::CreateLocation( - const Response &resp) { +std::shared_ptr<RegionLocation> LocationCache::CreateLocation(const Response &resp) { auto resp_msg = static_pointer_cast<ScanResponse>(resp.resp_msg()); auto &results = resp_msg->results().Get(0); auto &cells = results.cell(); @@ -168,6 +161,5 @@ std::shared_ptr<RegionLocation> LocationCache::CreateLocation( auto region_info = folly::to<RegionInfo>(cell_zero); auto server_name = folly::to<ServerName>(cell_one); - return std::make_shared<RegionLocation>(row, std::move(region_info), - server_name, nullptr); + return std::make_shared<RegionLocation>(row, std::move(region_info), server_name, nullptr); } http://git-wip-us.apache.org/repos/asf/hbase/blob/fe69c81d/hbase-native-client/core/location-cache.h ---------------------------------------------------------------------- diff --git a/hbase-native-client/core/location-cache.h b/hbase-native-client/core/location-cache.h index 53e41ab..b290a1f 100644 --- a/hbase-native-client/core/location-cache.h +++ b/hbase-native-client/core/location-cache.h @@ -79,8 +79,8 @@ class LocationCache { * @param row of the table to look up. This object must live until after the * future is returned */ - folly::Future<std::shared_ptr<RegionLocation>> LocateFromMeta( - const hbase::pb::TableName &tn, const std::string &row); + folly::Future<std::shared_ptr<RegionLocation>> LocateFromMeta(const hbase::pb::TableName &tn, + const std::string &row); /** * Remove the cached location of meta. http://git-wip-us.apache.org/repos/asf/hbase/blob/fe69c81d/hbase-native-client/core/meta-utils.cc ---------------------------------------------------------------------- diff --git a/hbase-native-client/core/meta-utils.cc b/hbase-native-client/core/meta-utils.cc index e1946d6..f92300c 100644 --- a/hbase-native-client/core/meta-utils.cc +++ b/hbase-native-client/core/meta-utils.cc @@ -37,13 +37,11 @@ using hbase::pb::RegionSpecifier_RegionSpecifierType; static const std::string META_REGION = "1588230740"; -std::string MetaUtil::RegionLookupRowkey(const TableName &tn, - const std::string &row) const { +std::string MetaUtil::RegionLookupRowkey(const TableName &tn, const std::string &row) const { return folly::to<std::string>(tn, ",", row, ",", "999999999999999999"); } -std::unique_ptr<Request> MetaUtil::MetaRequest(const TableName tn, - const std::string &row) const { +std::unique_ptr<Request> MetaUtil::MetaRequest(const TableName tn, const std::string &row) const { auto request = Request::scan(); auto msg = std::static_pointer_cast<ScanRequest>(request->req_msg()); @@ -53,8 +51,8 @@ std::unique_ptr<Request> MetaUtil::MetaRequest(const TableName tn, // Set the region this scan goes to auto region = msg->mutable_region(); region->set_value(META_REGION); - region->set_type(RegionSpecifier_RegionSpecifierType:: - RegionSpecifier_RegionSpecifierType_ENCODED_REGION_NAME); + region->set_type( + RegionSpecifier_RegionSpecifierType::RegionSpecifier_RegionSpecifierType_ENCODED_REGION_NAME); auto scan = msg->mutable_scan(); // We don't care about before, just now. http://git-wip-us.apache.org/repos/asf/hbase/blob/fe69c81d/hbase-native-client/core/meta-utils.h ---------------------------------------------------------------------- diff --git a/hbase-native-client/core/meta-utils.h b/hbase-native-client/core/meta-utils.h index 33da1a8..075215e 100644 --- a/hbase-native-client/core/meta-utils.h +++ b/hbase-native-client/core/meta-utils.h @@ -36,14 +36,12 @@ class MetaUtil { * Given a table and a row give the row key from which to start a scan to find * region locations. */ - std::string RegionLookupRowkey(const hbase::pb::TableName &tn, - const std::string &row) const; + std::string RegionLookupRowkey(const hbase::pb::TableName &tn, const std::string &row) const; /** * Given a row we're trying to access create a request to look up the * location. */ - std::unique_ptr<Request> MetaRequest(const hbase::pb::TableName tn, - const std::string &row) const; + std::unique_ptr<Request> MetaRequest(const hbase::pb::TableName tn, const std::string &row) const; }; } // namespace hbase http://git-wip-us.apache.org/repos/asf/hbase/blob/fe69c81d/hbase-native-client/core/region-location.h ---------------------------------------------------------------------- diff --git a/hbase-native-client/core/region-location.h b/hbase-native-client/core/region-location.h index f0295b1..e7b76d3 100644 --- a/hbase-native-client/core/region-location.h +++ b/hbase-native-client/core/region-location.h @@ -42,8 +42,7 @@ class RegionLocation { * this region. * @param service the connected service to the regionserver. */ - RegionLocation(std::string region_name, hbase::pb::RegionInfo ri, - hbase::pb::ServerName sn, + RegionLocation(std::string region_name, hbase::pb::RegionInfo ri, hbase::pb::ServerName sn, std::shared_ptr<HBaseService> service) : region_name_(region_name), ri_(ri), sn_(sn), service_(service) {} http://git-wip-us.apache.org/repos/asf/hbase/blob/fe69c81d/hbase-native-client/core/response_converter.h ---------------------------------------------------------------------- diff --git a/hbase-native-client/core/response_converter.h b/hbase-native-client/core/response_converter.h index 7cbde81..86fb632 100644 --- a/hbase-native-client/core/response_converter.h +++ b/hbase-native-client/core/response_converter.h @@ -20,8 +20,8 @@ #pragma once #include <memory> -#include "core/result.h" #include "connection/response.h" +#include "core/result.h" namespace hbase { http://git-wip-us.apache.org/repos/asf/hbase/blob/fe69c81d/hbase-native-client/core/result-test.cc ---------------------------------------------------------------------- diff --git a/hbase-native-client/core/result-test.cc b/hbase-native-client/core/result-test.cc index 134e80f..09d4e15 100644 --- a/hbase-native-client/core/result-test.cc +++ b/hbase-native-client/core/result-test.cc @@ -19,11 +19,11 @@ #include "core/result.h" +#include <gtest/gtest.h> #include <limits> #include <memory> -#include <vector> #include <string> -#include <gtest/gtest.h> +#include <vector> #include "core/cell.h" using namespace hbase; @@ -41,36 +41,35 @@ void PopulateCells(std::vector<std::shared_ptr<Cell> > &cells) { switch (i) { case 5: { - cells.push_back(std::make_shared<Cell>( - row, family, column, 1482113040506, "value-5", CellType::PUT)); - cells.push_back(std::make_shared<Cell>( - row, family, column, 1482111803856, "value-X", CellType::PUT)); + cells.push_back( + std::make_shared<Cell>(row, family, column, 1482113040506, "value-5", CellType::PUT)); + cells.push_back( + std::make_shared<Cell>(row, family, column, 1482111803856, "value-X", CellType::PUT)); break; } case 8: { - cells.push_back(std::make_shared<Cell>( - row, family, column, 1482113040506, "value-8", CellType::PUT)); - cells.push_back(std::make_shared<Cell>( - row, family, column, 1482111803856, "value-X", CellType::PUT)); - cells.push_back(std::make_shared<Cell>( - row, family, column, 1482110969958, "value-Y", CellType::PUT)); + cells.push_back( + std::make_shared<Cell>(row, family, column, 1482113040506, "value-8", CellType::PUT)); + cells.push_back( + std::make_shared<Cell>(row, family, column, 1482111803856, "value-X", CellType::PUT)); + cells.push_back( + std::make_shared<Cell>(row, family, column, 1482110969958, "value-Y", CellType::PUT)); break; } case 9: { - cells.push_back(std::make_shared<Cell>( - row, family, column, 1482113040506, "value-9", CellType::PUT)); - cells.push_back(std::make_shared<Cell>( - row, family, column, 1482111803856, "value-X", CellType::PUT)); - cells.push_back(std::make_shared<Cell>( - row, family, column, 1482110969958, "value-Y", CellType::PUT)); - cells.push_back(std::make_shared<Cell>( - row, family, column, 1482110876075, "value-Z", CellType::PUT)); + cells.push_back( + std::make_shared<Cell>(row, family, column, 1482113040506, "value-9", CellType::PUT)); + cells.push_back( + std::make_shared<Cell>(row, family, column, 1482111803856, "value-X", CellType::PUT)); + cells.push_back( + std::make_shared<Cell>(row, family, column, 1482110969958, "value-Y", CellType::PUT)); + cells.push_back( + std::make_shared<Cell>(row, family, column, 1482110876075, "value-Z", CellType::PUT)); break; } default: { - cells.push_back(std::make_shared<Cell>(row, family, column, - std::numeric_limits<long>::max(), - value, CellType::PUT)); + cells.push_back(std::make_shared<Cell>( + row, family, column, std::numeric_limits<long>::max(), value, CellType::PUT)); } } } @@ -111,12 +110,9 @@ TEST(Result, FilledResult) { // Value will be present as family and qualifier is present ASSERT_TRUE(result.Value("family-4", "column-4")); // Value should be present and match. - EXPECT_EQ(latest_cell->Value(), - (*result.ColumnLatestCell("family-4", "column-4")).Value()); - EXPECT_EQ("value-5", - (*result.ColumnLatestCell("family-5", "column-5")).Value()); - EXPECT_EQ("value-8", - (*result.ColumnLatestCell("family-8", "column-8")).Value()); + EXPECT_EQ(latest_cell->Value(), (*result.ColumnLatestCell("family-4", "column-4")).Value()); + EXPECT_EQ("value-5", (*result.ColumnLatestCell("family-5", "column-5")).Value()); + EXPECT_EQ("value-8", (*result.ColumnLatestCell("family-8", "column-8")).Value()); EXPECT_EQ("value-7", *result.Value("family-7", "column-7")); // Get cells for the given family and qualifier http://git-wip-us.apache.org/repos/asf/hbase/blob/fe69c81d/hbase-native-client/core/result.cc ---------------------------------------------------------------------- diff --git a/hbase-native-client/core/result.cc b/hbase-native-client/core/result.cc index 9842915..d73a5b2 100644 --- a/hbase-native-client/core/result.cc +++ b/hbase-native-client/core/result.cc @@ -23,15 +23,14 @@ namespace hbase { Result::~Result() {} -Result::Result(const std::vector<std::shared_ptr<Cell> > &cells, bool exists, - bool stale, bool partial) +Result::Result(const std::vector<std::shared_ptr<Cell> > &cells, bool exists, bool stale, + bool partial) : exists_(exists), stale_(stale), partial_(partial) { for (const auto &cell : cells) { cells_.push_back(cell); // We create the map when cells are added. unlike java where map is created // when result.getMap() is called - result_map_[cell->Family()][cell->Qualifier()][cell->Timestamp()] = - cell->Value(); + result_map_[cell->Family()][cell->Qualifier()][cell->Timestamp()] = cell->Value(); } row_ = (cells_.size() == 0 ? "" : cells_[0]->Row()); } @@ -44,17 +43,14 @@ Result::Result(const Result &result) { if (!result.cells_.empty()) { for (const auto &cell : result.cells_) { cells_.push_back(cell); - result_map_[cell->Family()][cell->Qualifier()][cell->Timestamp()] = - cell->Value(); + result_map_[cell->Family()][cell->Qualifier()][cell->Timestamp()] = cell->Value(); } } } -const std::vector<std::shared_ptr<Cell> > &Result::Cells() const { - return cells_; -} +const std::vector<std::shared_ptr<Cell> > &Result::Cells() const { return cells_; } -std::vector<std::shared_ptr<Cell> > Result::ColumnCells( - const std::string &family, const std::string &qualifier) const { +std::vector<std::shared_ptr<Cell> > Result::ColumnCells(const std::string &family, + const std::string &qualifier) const { std::vector<std::shared_ptr<Cell> > column_cells; // TODO implement a BinarySearch here ? for (const auto &cell : cells_) { @@ -65,8 +61,8 @@ std::vector<std::shared_ptr<Cell> > Result::ColumnCells( return column_cells; } -const std::shared_ptr<Cell> Result::ColumnLatestCell( - const std::string &family, const std::string &qualifier) const { +const std::shared_ptr<Cell> Result::ColumnLatestCell(const std::string &family, + const std::string &qualifier) const { // TODO implement a BinarySearch here ? for (const auto &cell : cells_) { // We find the latest(first) occurrence of the Cell for a given column and @@ -100,10 +96,8 @@ const ResultFamilyMap Result::FamilyMap(const std::string &family) const { if (!IsEmpty()) { for (auto itr = result_map_.begin(); itr != result_map_.end(); ++itr) { if (family == itr->first) { - for (auto qitr = itr->second.begin(); qitr != itr->second.end(); - ++qitr) { - for (auto vitr = qitr->second.begin(); vitr != qitr->second.end(); - ++vitr) { + for (auto qitr = itr->second.begin(); qitr != itr->second.end(); ++qitr) { + for (auto vitr = qitr->second.begin(); vitr != qitr->second.end(); ++vitr) { // We break after inserting the first value. Result.java takes only // the first value family_map[qitr->first] = vitr->second; http://git-wip-us.apache.org/repos/asf/hbase/blob/fe69c81d/hbase-native-client/core/result.h ---------------------------------------------------------------------- diff --git a/hbase-native-client/core/result.h b/hbase-native-client/core/result.h index ecfdd55..cd41cf0 100644 --- a/hbase-native-client/core/result.h +++ b/hbase-native-client/core/result.h @@ -34,9 +34,9 @@ namespace hbase { * We need to have a reverse ordered map, when storing TS -> value, so that the * most recent value is stored first */ -using ResultMap = std::map< - std::string, std::map<std::string, std::map<int64_t, std::string, - std::greater<int64_t> > > >; +using ResultMap = + std::map<std::string, + std::map<std::string, std::map<int64_t, std::string, std::greater<int64_t> > > >; /** * @brief Map of qualifiers to values. @@ -48,8 +48,7 @@ class Result { /** * Constructors */ - Result(const std::vector<std::shared_ptr<Cell> > &cells, bool exists, - bool stale, bool partial); + Result(const std::vector<std::shared_ptr<Cell> > &cells, bool exists, bool stale, bool partial); Result(const Result &result); ~Result(); @@ -67,8 +66,8 @@ class Result { * @param family - column family * @param qualifier - column qualifier */ - std::vector<std::shared_ptr<Cell> > ColumnCells( - const std::string &family, const std::string &qualifier) const; + std::vector<std::shared_ptr<Cell> > ColumnCells(const std::string &family, + const std::string &qualifier) const; /** * @brief Returns the Cell for the most recent timestamp for a given family @@ -77,16 +76,15 @@ class Result { * @param family - column family. * @param qualifier - column qualifier */ - const std::shared_ptr<Cell> ColumnLatestCell( - const std::string &family, const std::string &qualifier) const; + const std::shared_ptr<Cell> ColumnLatestCell(const std::string &family, + const std::string &qualifier) const; /** * @brief Get the latest version of the specified family and qualifier. * @param family - column family * @param qualifier - column qualifier */ - std::shared_ptr<std::string> Value(const std::string &family, - const std::string &qualifier) const; + std::shared_ptr<std::string> Value(const std::string &family, const std::string &qualifier) const; /** * @brief Returns if the underlying Cell vector is empty or not http://git-wip-us.apache.org/repos/asf/hbase/blob/fe69c81d/hbase-native-client/core/scan-test.cc ---------------------------------------------------------------------- diff --git a/hbase-native-client/core/scan-test.cc b/hbase-native-client/core/scan-test.cc index 0a4001a..9a26407 100644 --- a/hbase-native-client/core/scan-test.cc +++ b/hbase-native-client/core/scan-test.cc @@ -154,8 +154,7 @@ void ScanMethods(Scan &scan) { // Test initial values EXPECT_EQ(0, scan.Timerange().MinTimeStamp()); - EXPECT_EQ(std::numeric_limits<int64_t>::max(), - scan.Timerange().MaxTimeStamp()); + EXPECT_EQ(std::numeric_limits<int64_t>::max(), scan.Timerange().MaxTimeStamp()); // Set & Test new values using TimeRange and TimeStamp scan.SetTimeRange(1000, 2000); @@ -169,8 +168,7 @@ void ScanMethods(Scan &scan) { ASSERT_THROW(scan.SetTimeRange(-1000, 2000), std::runtime_error); ASSERT_THROW(scan.SetTimeRange(1000, -2000), std::runtime_error); ASSERT_THROW(scan.SetTimeRange(1000, 200), std::runtime_error); - ASSERT_THROW(scan.SetTimeStamp(std::numeric_limits<int64_t>::max()), - std::runtime_error); + ASSERT_THROW(scan.SetTimeStamp(std::numeric_limits<int64_t>::max()), std::runtime_error); } TEST(Scan, Object) {