From 1b43db459d8d8ef5884240032e56b7503cdddc46 Mon Sep 17 00:00:00 2001 From: Elliott Clark Date: Fri, 13 May 2016 09:17:49 -0700 Subject: [PATCH] HBASE-15821 Document TestUtil --- hbase-native-client/connection/connection-pool.h | 4 ++-- hbase-native-client/core/location-cache.cc | 2 +- hbase-native-client/core/location-cache.h | 2 +- hbase-native-client/test-util/test-util.cc | 18 ++++++++++++------ hbase-native-client/test-util/test-util.h | 20 +++++++++++++++----- 5 files changed, 31 insertions(+), 15 deletions(-) diff --git a/hbase-native-client/connection/connection-pool.h b/hbase-native-client/connection/connection-pool.h index 605a81b..b8c950b 100644 --- a/hbase-native-client/connection/connection-pool.h +++ b/hbase-native-client/connection/connection-pool.h @@ -88,8 +88,8 @@ public: void Close(const hbase::pb::ServerName &sn); private: - std::shared_ptr GetCached(const hbase::pb::ServerName& sn); - std::shared_ptr GetNew(const hbase::pb::ServerName& sn); + std::shared_ptr GetCached(const hbase::pb::ServerName &sn); + std::shared_ptr GetNew(const hbase::pb::ServerName &sn); std::unordered_map, ServerNameHash, ServerNameEquals> connections_; diff --git a/hbase-native-client/core/location-cache.cc b/hbase-native-client/core/location-cache.cc index 6ba8add..efd2210 100644 --- a/hbase-native-client/core/location-cache.cc +++ b/hbase-native-client/core/location-cache.cc @@ -116,7 +116,7 @@ LocationCache::LocateFromMeta(const TableName &tn, const string &row) { return this->LocateMeta() .via(cpu_executor_.get()) .then([this](ServerName sn) { return this->cp_.Get(sn); }) - .then([tn, row, this](std::shared_ptr service) { + .then([tn, row, this](std::shared_ptr service) { return (*service)(std::move(meta_util_.MetaRequest(tn, row))); }) .then([this](Response resp) { diff --git a/hbase-native-client/core/location-cache.h b/hbase-native-client/core/location-cache.h index d435530..830cd96 100644 --- a/hbase-native-client/core/location-cache.h +++ b/hbase-native-client/core/location-cache.h @@ -55,7 +55,7 @@ public: * @param io_executor executor used to talk to the network */ LocationCache(std::string quorum_spec, - std::shared_ptr cpu_exector, + std::shared_ptr cpu_executor, std::shared_ptr io_executor); /** * Destructor. diff --git a/hbase-native-client/test-util/test-util.cc b/hbase-native-client/test-util/test-util.cc index e5fba48..88ce7c8 100644 --- a/hbase-native-client/test-util/test-util.cc +++ b/hbase-native-client/test-util/test-util.cc @@ -24,13 +24,18 @@ using hbase::TestUtil; using folly::Random; -const static int STR_LEN = 32; +std::string TestUtil::RandString(int len) { + // Create the whole string. + // Filling everything with z's + auto s = std::string(len, 'z'); -std::string TestUtil::RandString() { - auto s = std::string(STR_LEN, 'z'); - - for (int i = 0; i < STR_LEN; i++) { + // Now pick a bunch of random numbers + for (int i = 0; i < len; i++) { + // use Folly's random to get the numbers + // as I don't want to have to learn + // all the cpp rand invocation magic. auto r = Random::rand32('a', 'z'); + // Cast that to ascii. s[i] = static_cast(r); } return s; @@ -42,12 +47,13 @@ TestUtil::TestUtil() : temp_dir_(TestUtil::RandString()) { auto res_code = std::system(cmd.c_str()); CHECK(res_code == 0); } + TestUtil::~TestUtil() { auto res_code = std::system("bin/stop-local-hbase.sh"); CHECK(res_code == 0); } -void TestUtil::RunShellCmd(const std::string& command) { +void TestUtil::RunShellCmd(const std::string &command) { auto cmd_string = folly::sformat("echo \"{}\" | ../bin/hbase shell", command); auto res_code = std::system(cmd_string.c_str()); CHECK(res_code == 0); diff --git a/hbase-native-client/test-util/test-util.h b/hbase-native-client/test-util/test-util.h index 395b157..20e4981 100644 --- a/hbase-native-client/test-util/test-util.h +++ b/hbase-native-client/test-util/test-util.h @@ -30,20 +30,30 @@ namespace hbase { */ class TestUtil { public: - /** * Creating a TestUtil will spin up a cluster. */ TestUtil(); + /** - * Destroying a TestUtil will spin down a cluster. + * Destroying a TestUtil will spin down a cluster and remove the test dir. */ ~TestUtil(); + /** - * Run a command in the hbase shell. + * Run a command in the hbase shell. Command should not include any double + * quotes. + * + * This should only be used until there is a good Admin support from the + * native client */ - void RunShellCmd(const std::string& command); - static std::string RandString(); + void RunShellCmd(const std::string &command); + + /** + * Create a random string. This random string is all letters, as such it is + * very good for use as a directory name. + */ + static std::string RandString(int len = 32); private: folly::test::TemporaryDirectory temp_dir_; -- 2.8.0-rc2