Repository: hbase Updated Branches: refs/heads/HBASE-14850 7e4a52dd9 -> e2bb10a87
HBASE-18861 [C++] Use boost::optional instead of std::experimental::optional Project: http://git-wip-us.apache.org/repos/asf/hbase/repo Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/e2bb10a8 Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/e2bb10a8 Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/e2bb10a8 Branch: refs/heads/HBASE-14850 Commit: e2bb10a8708e7a675558ca0aad9e340823573ff6 Parents: 7e4a52d Author: Enis Soztutar <e...@apache.org> Authored: Fri Sep 22 11:23:59 2017 -0700 Committer: Enis Soztutar <e...@apache.org> Committed: Fri Sep 22 11:23:59 2017 -0700 ---------------------------------------------------------------------- .../include/hbase/client/configuration.h | 4 +- .../hbase/client/hbase-configuration-loader.h | 2 - .../include/hbase/utils/optional.h | 7 ++- .../src/hbase/client/client-test.cc | 5 ++- .../src/hbase/client/configuration.cc | 46 ++++++++++---------- .../hbase/client/hbase-configuration-loader.cc | 8 ++-- .../hbase/client/hbase-configuration-test.cc | 36 +++++++-------- .../src/hbase/client/result-test.cc | 5 ++- 8 files changed, 58 insertions(+), 55 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/hbase/blob/e2bb10a8/hbase-native-client/include/hbase/client/configuration.h ---------------------------------------------------------------------- diff --git a/hbase-native-client/include/hbase/client/configuration.h b/hbase-native-client/include/hbase/client/configuration.h index d70941c..06f9c79 100644 --- a/hbase-native-client/include/hbase/client/configuration.h +++ b/hbase-native-client/include/hbase/client/configuration.h @@ -24,12 +24,12 @@ #include <string> #include <vector> -#include <experimental/optional> +#include "hbase/utils/optional.h" namespace hbase { template <class T> -using optional = std::experimental::optional<T>; +using optional = boost::optional<T>; class Configuration { public: http://git-wip-us.apache.org/repos/asf/hbase/blob/e2bb10a8/hbase-native-client/include/hbase/client/hbase-configuration-loader.h ---------------------------------------------------------------------- diff --git a/hbase-native-client/include/hbase/client/hbase-configuration-loader.h b/hbase-native-client/include/hbase/client/hbase-configuration-loader.h index 8792aa2..d46217d 100644 --- a/hbase-native-client/include/hbase/client/hbase-configuration-loader.h +++ b/hbase-native-client/include/hbase/client/hbase-configuration-loader.h @@ -23,8 +23,6 @@ #include <string> #include <vector> -#include <boost/optional.hpp> - #include "hbase/client/configuration.h" #include "hbase/utils/optional.h" http://git-wip-us.apache.org/repos/asf/hbase/blob/e2bb10a8/hbase-native-client/include/hbase/utils/optional.h ---------------------------------------------------------------------- diff --git a/hbase-native-client/include/hbase/utils/optional.h b/hbase-native-client/include/hbase/utils/optional.h index a05eab5..c43fd56 100644 --- a/hbase-native-client/include/hbase/utils/optional.h +++ b/hbase-native-client/include/hbase/utils/optional.h @@ -19,7 +19,8 @@ #pragma once -#include <experimental/optional> +#include <boost/optional.hpp> +#include <boost/none.hpp> namespace hbase { @@ -27,6 +28,8 @@ namespace hbase { * An optional value that may or may not be present. */ template <class T> -using optional = std::experimental::optional<T>; +using optional = boost::optional<T>; + +const boost::none_t none = boost::none; } /* namespace hbase */ http://git-wip-us.apache.org/repos/asf/hbase/blob/e2bb10a8/hbase-native-client/src/hbase/client/client-test.cc ---------------------------------------------------------------------- diff --git a/hbase-native-client/src/hbase/client/client-test.cc b/hbase-native-client/src/hbase/client/client-test.cc index 7141047..0773d3d 100644 --- a/hbase-native-client/src/hbase/client/client-test.cc +++ b/hbase-native-client/src/hbase/client/client-test.cc @@ -34,15 +34,16 @@ #include "hbase/serde/table-name.h" #include "hbase/test-util/test-util.h" #include "hbase/utils/bytes-util.h" +#include "hbase/utils/optional.h" using hbase::Cell; using hbase::Configuration; using hbase::Get; using hbase::RetriesExhaustedException; +using hbase::none; using hbase::Put; using hbase::Table; using hbase::TestUtil; -using std::experimental::nullopt; class ClientTest : public ::testing::Test { public: @@ -202,7 +203,7 @@ TEST_F(ClientTest, PutGetDelete) { result = table->Get(get); ASSERT_TRUE(!result->IsEmpty()) << "Result shouldn't be empty."; ASSERT_FALSE(result->Value("d", "1")) << "Column 1 should be gone"; - ASSERT_TRUE(result->Value("d", "extra") != nullopt) << "Column extra should have value"; + ASSERT_TRUE(result->Value("d", "extra") != none) << "Column extra should have value"; EXPECT_EQ(valExt, *(result->Value("d", "ext"))) << "Column ext should have value"; // delete all cells from "extra" column http://git-wip-us.apache.org/repos/asf/hbase/blob/e2bb10a8/hbase-native-client/src/hbase/client/configuration.cc ---------------------------------------------------------------------- diff --git a/hbase-native-client/src/hbase/client/configuration.cc b/hbase-native-client/src/hbase/client/configuration.cc index d829edc..385ea6a 100644 --- a/hbase-native-client/src/hbase/client/configuration.cc +++ b/hbase-native-client/src/hbase/client/configuration.cc @@ -23,9 +23,9 @@ #include <stdexcept> #include <utility> -#include <glog/logging.h> #include <boost/format.hpp> #include <boost/lexical_cast.hpp> +#include <glog/logging.h> namespace hbase { @@ -94,23 +94,23 @@ optional<std::string> Configuration::GetEnv(const std::string &key) const { if ("user.name" == key) { #ifdef HAVE_GETLOGIN - return std::experimental::make_optional(getlogin()); + return getlogin(); #else DLOG(WARNING) << "Client user.name not implemented"; - return optional<std::string>(); + return none; #endif } if ("user.dir" == key) { #ifdef HAVE_GETCWD if (getcwd(buf, sizeof(buf))) { - return std::experimental::make_optional(buf); + return buf; } else { - return optional<std::string>(); + return none; } #else DLOG(WARNING) << "Client user.dir not implemented"; - return optional<std::string>(); + return none; #endif } @@ -118,33 +118,33 @@ optional<std::string> Configuration::GetEnv(const std::string &key) const { #if defined(HAVE_GETUID) && defined(HAVE_GETPWUID_R) uid = getuid(); if (!getpwuid_r(uid, &pw, buf, sizeof(buf), &pwp)) { - return std::experimental::make_optional(buf); + return buf; } else { - return optional<std::string>(); + return none; } #else DLOG(WARNING) << "Client user.home not implemented"; - return optional<std::string>(); + return none; #endif } - return optional<std::string>(); + return none; } optional<std::string> Configuration::GetProperty(const std::string &key) const { auto found = hb_property_.find(key); if (found != hb_property_.end()) { - return std::experimental::make_optional(found->second.value); + return found->second.value; } else { - return optional<std::string>(); + return none; } } optional<std::string> Configuration::Get(const std::string &key) const { optional<std::string> raw = GetProperty(key); if (raw) { - return std::experimental::make_optional(SubstituteVars(*raw)); + return SubstituteVars(*raw); } else { - return optional<std::string>(); + return none; } } @@ -156,12 +156,12 @@ 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 boost::lexical_cast<int32_t>(*raw); } catch (const boost::bad_lexical_cast &blex) { throw std::runtime_error(blex.what()); } } - return optional<int32_t>(); + return none; } int32_t Configuration::GetInt(const std::string &key, int32_t default_value) const { @@ -172,12 +172,12 @@ 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 boost::lexical_cast<int64_t>(*raw); } catch (const boost::bad_lexical_cast &blex) { throw std::runtime_error(blex.what()); } } - return optional<int64_t>(); + return none; } int64_t Configuration::GetLong(const std::string &key, int64_t default_value) const { @@ -188,12 +188,12 @@ 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 boost::lexical_cast<double>(*raw); } catch (const boost::bad_lexical_cast &blex) { throw std::runtime_error(blex.what()); } } - return optional<double>(); + return none; } double Configuration::GetDouble(const std::string &key, double default_value) const { @@ -204,9 +204,9 @@ optional<bool> Configuration::GetBool(const std::string &key) const { optional<std::string> raw = Get(key); if (raw) { if (!strcasecmp((*raw).c_str(), "true") || !strcasecmp((*raw).c_str(), "1")) { - return std::experimental::make_optional(true); + return true; } else if (!strcasecmp((*raw).c_str(), "false") || !strcasecmp((*raw).c_str(), "0")) { - return std::experimental::make_optional(false); + return false; } else { boost::format what("Unexpected value \"%s\" found being converted to bool for key \"%s\""); what % (*raw); @@ -214,7 +214,7 @@ optional<bool> Configuration::GetBool(const std::string &key) const { throw std::runtime_error(what.str()); } } - return optional<bool>(); + return none; } bool Configuration::GetBool(const std::string &key, bool default_value) const { http://git-wip-us.apache.org/repos/asf/hbase/blob/e2bb10a8/hbase-native-client/src/hbase/client/hbase-configuration-loader.cc ---------------------------------------------------------------------- diff --git a/hbase-native-client/src/hbase/client/hbase-configuration-loader.cc b/hbase-native-client/src/hbase/client/hbase-configuration-loader.cc index 98ef20e..2233794 100644 --- a/hbase-native-client/src/hbase/client/hbase-configuration-loader.cc +++ b/hbase-native-client/src/hbase/client/hbase-configuration-loader.cc @@ -125,9 +125,9 @@ optional<Configuration> HBaseConfigurationLoader::LoadDefaultResources() { } } if (success) { - return std::experimental::make_optional<Configuration>(Configuration(conf_property)); + return Configuration(conf_property); } else { - return optional<Configuration>(); + return none; } } @@ -149,9 +149,9 @@ optional<Configuration> HBaseConfigurationLoader::LoadResources( } } if (success) { - return std::experimental::make_optional<Configuration>(Configuration(conf_property)); + return Configuration(conf_property); } else { - return optional<Configuration>(); + return none; } } http://git-wip-us.apache.org/repos/asf/hbase/blob/e2bb10a8/hbase-native-client/src/hbase/client/hbase-configuration-test.cc ---------------------------------------------------------------------- diff --git a/hbase-native-client/src/hbase/client/hbase-configuration-test.cc b/hbase-native-client/src/hbase/client/hbase-configuration-test.cc index 173c4df..afa9c06 100644 --- a/hbase-native-client/src/hbase/client/hbase-configuration-test.cc +++ b/hbase-native-client/src/hbase/client/hbase-configuration-test.cc @@ -25,9 +25,9 @@ #include <boost/filesystem.hpp> #include "hbase/client/configuration.h" #include "hbase/client/hbase-configuration-loader.h" +#include "hbase/utils/optional.h" using namespace hbase; -using std::experimental::nullopt; const std::string kDefHBaseConfPath("./build/test-data/hbase-configuration-test/conf/"); const std::string kHBaseConfPath("./build/test-data/hbase-configuration-test/custom-conf/"); @@ -150,7 +150,7 @@ TEST(Configuration, LoadConfFromDefaultLocation) { HBaseConfigurationLoader loader; hbase::optional<Configuration> conf = loader.LoadDefaultResources(); - ASSERT_TRUE(conf != nullopt) << "No configuration object present."; + ASSERT_TRUE(conf != none) << "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"); } @@ -167,7 +167,7 @@ TEST(Configuration, LoadConfFromCustomLocation) { HBaseConfigurationLoader loader; std::vector<std::string> resources{kHBaseSiteXml}; hbase::optional<Configuration> conf = loader.LoadResources(kHBaseConfPath, resources); - ASSERT_TRUE(conf != nullopt) << "No configuration object present."; + ASSERT_TRUE(conf != none) << "No configuration object present."; EXPECT_STREQ((*conf).Get("custom-prop", "").c_str(), "custom-value"); EXPECT_STRNE((*conf).Get("custom-prop", "").c_str(), "some-value"); } @@ -188,7 +188,7 @@ TEST(Configuration, LoadConfFromMultipleLocatons) { std::string conf_paths = kDefHBaseConfPath + ":" + kHBaseConfPath; std::vector<std::string> resources{kHBaseDefaultXml, kHBaseSiteXml}; hbase::optional<Configuration> conf = loader.LoadResources(conf_paths, resources); - ASSERT_TRUE(conf != nullopt) << "No configuration object present."; + ASSERT_TRUE(conf != none) << "No configuration object present."; 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"); @@ -207,7 +207,7 @@ TEST(Configuration, DefaultValues) { HBaseConfigurationLoader loader; hbase::optional<Configuration> conf = loader.LoadDefaultResources(); - ASSERT_TRUE(conf != nullopt) << "No configuration object present."; + ASSERT_TRUE(conf != none) << "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"); } @@ -219,7 +219,7 @@ TEST(Configuration, FinalValues) { HBaseConfigurationLoader loader; hbase::optional<Configuration> conf = loader.LoadDefaultResources(); - ASSERT_TRUE(conf != nullopt) << "No configuration object present."; + ASSERT_TRUE(conf != none) << "No configuration object present."; 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"); @@ -241,7 +241,7 @@ TEST(Configuration, EnvVars) { HBaseConfigurationLoader loader; hbase::optional<Configuration> conf = loader.LoadDefaultResources(); - ASSERT_TRUE(conf != nullopt) << "No configuration object present."; + ASSERT_TRUE(conf != none) << "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"); } @@ -253,7 +253,7 @@ TEST(Configuration, SelfRef) { HBaseConfigurationLoader loader; hbase::optional<Configuration> conf = loader.LoadDefaultResources(); - ASSERT_TRUE(conf != nullopt) << "No configuration object present."; + ASSERT_TRUE(conf != none) << "No configuration object present."; EXPECT_STREQ((*conf).Get("selfRef", "${selfRef}").c_str(), "${selfRef}"); } @@ -264,7 +264,7 @@ TEST(Configuration, VarExpansion) { HBaseConfigurationLoader loader; hbase::optional<Configuration> conf = loader.LoadDefaultResources(); - ASSERT_TRUE(conf != nullopt) << "No configuration object present."; + ASSERT_TRUE(conf != none) << "No configuration object present."; EXPECT_STREQ((*conf).Get("foo.substs", "foo-value").c_str(), "bar-value,bar-value,bar-value,bar-value,bar-value,bar-value," "bar-value,bar-value,bar-value,bar-value,"); @@ -278,7 +278,7 @@ TEST(Configuration, VarExpansionException) { HBaseConfigurationLoader loader; hbase::optional<Configuration> conf = loader.LoadDefaultResources(); - ASSERT_TRUE(conf != nullopt) << "No configuration object present."; + ASSERT_TRUE(conf != none) << "No configuration object present."; ASSERT_THROW((*conf).Get("foo.substs.exception", "foo-value").c_str(), std::runtime_error); } @@ -289,7 +289,7 @@ TEST(Configuration, GetInt) { HBaseConfigurationLoader loader; hbase::optional<Configuration> conf = loader.LoadDefaultResources(); - ASSERT_TRUE(conf != nullopt) << "No configuration object present."; + ASSERT_TRUE(conf != none) << "No configuration object present."; EXPECT_EQ(16000, (*conf).GetInt("int", 0)); EXPECT_EQ(2147483646, (*conf).GetInt("int.largevalue", 0)); } @@ -301,7 +301,7 @@ TEST(Configuration, GetLong) { HBaseConfigurationLoader loader; hbase::optional<Configuration> conf = loader.LoadDefaultResources(); - ASSERT_TRUE(conf != nullopt) << "No configuration object present."; + ASSERT_TRUE(conf != none) << "No configuration object present."; EXPECT_EQ(2147483850, (*conf).GetLong("long", 0)); EXPECT_EQ(9223372036854775807, (*conf).GetLong("long.largevalue", 0)); } @@ -313,7 +313,7 @@ TEST(Configuration, GetDouble) { HBaseConfigurationLoader loader; hbase::optional<Configuration> conf = loader.LoadDefaultResources(); - ASSERT_TRUE(conf != nullopt) << "No configuration object present."; + ASSERT_TRUE(conf != none) << "No configuration object present."; EXPECT_DOUBLE_EQ(17.9769e+100, (*conf).GetDouble("double", 0.0)); EXPECT_DOUBLE_EQ(170.769e+200, (*conf).GetDouble("double.largevalue", 0.0)); } @@ -325,7 +325,7 @@ TEST(Configuration, GetBool) { HBaseConfigurationLoader loader; hbase::optional<Configuration> conf = loader.LoadDefaultResources(); - ASSERT_TRUE(conf != nullopt) << "No configuration object present."; + ASSERT_TRUE(conf != none) << "No configuration object present."; EXPECT_EQ(true, (*conf).GetBool("bool.true", true)); EXPECT_EQ(false, (*conf).GetBool("bool.false", false)); } @@ -337,7 +337,7 @@ TEST(Configuration, GetIntException) { HBaseConfigurationLoader loader; hbase::optional<Configuration> conf = loader.LoadDefaultResources(); - ASSERT_TRUE(conf != nullopt) << "No configuration object present."; + ASSERT_TRUE(conf != none) << "No configuration object present."; ASSERT_THROW((*conf).GetInt("int.exception", 0), std::runtime_error); } @@ -348,7 +348,7 @@ TEST(Configuration, GetLongException) { HBaseConfigurationLoader loader; hbase::optional<Configuration> conf = loader.LoadDefaultResources(); - ASSERT_TRUE(conf != nullopt) << "No configuration object present."; + ASSERT_TRUE(conf != none) << "No configuration object present."; ASSERT_THROW((*conf).GetLong("long.exception", 0), std::runtime_error); } @@ -359,7 +359,7 @@ TEST(Configuration, GetDoubleException) { HBaseConfigurationLoader loader; hbase::optional<Configuration> conf = loader.LoadDefaultResources(); - ASSERT_TRUE(conf != nullopt) << "No configuration object present."; + ASSERT_TRUE(conf != none) << "No configuration object present."; ASSERT_THROW((*conf).GetDouble("double.exception", 0), std::runtime_error); } @@ -370,6 +370,6 @@ TEST(Configuration, GetBoolException) { HBaseConfigurationLoader loader; hbase::optional<Configuration> conf = loader.LoadDefaultResources(); - ASSERT_TRUE(conf != nullopt) << "No configuration object present."; + ASSERT_TRUE(conf != none) << "No configuration object present."; ASSERT_THROW((*conf).GetBool("bool.exception", false), std::runtime_error); } http://git-wip-us.apache.org/repos/asf/hbase/blob/e2bb10a8/hbase-native-client/src/hbase/client/result-test.cc ---------------------------------------------------------------------- diff --git a/hbase-native-client/src/hbase/client/result-test.cc b/hbase-native-client/src/hbase/client/result-test.cc index 684c08d..3857d7b 100644 --- a/hbase-native-client/src/hbase/client/result-test.cc +++ b/hbase-native-client/src/hbase/client/result-test.cc @@ -26,11 +26,12 @@ #include "hbase/client/cell.h" #include "hbase/client/result.h" +#include "hbase/utils/optional.h" using hbase::Cell; using hbase::CellType; +using hbase::none; using hbase::Result; -using std::experimental::nullopt; void PopulateCells(std::vector<std::shared_ptr<Cell> > &cells) { // Populate some Results @@ -112,7 +113,7 @@ TEST(Result, FilledResult) { // Value will be nullptr as no such family and qualifier is present ASSERT_FALSE(result.Value("family-4", "qualifier")); // Value will be present as family and qualifier is present - ASSERT_TRUE(result.Value("family-4", "column-4") != nullopt); + ASSERT_TRUE(result.Value("family-4", "column-4") != none); // 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());