kudu-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jdcry...@apache.org
Subject [2/2] kudu git commit: [flags] fixed typo in group flag validation logic
Date Fri, 12 May 2017 15:05:47 GMT
[flags] fixed typo in group flag validation logic

This is a follow-up for e7334c2e6607ac0fa778499eda2df3f4cfcd3fe3.

This patch fixes the typo in the original commit and adds test coverage
for the case of multiple group validators in the validation pipeline.

Change-Id: Idfdc25d491941674fd7b86d8ffa33ff2e046703b
Reviewed-on: http://gerrit.cloudera.org:8080/6860
Reviewed-by: Adar Dembo <adar@cloudera.com>
Tested-by: Kudu Jenkins
(cherry picked from commit a0006dbaa77c276c6498dc4edc0228cae049738c)
Reviewed-on: http://gerrit.cloudera.org:8080/6864
Reviewed-by: Jean-Daniel Cryans <jdcryans@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/kudu/repo
Commit: http://git-wip-us.apache.org/repos/asf/kudu/commit/a1234c05
Tree: http://git-wip-us.apache.org/repos/asf/kudu/tree/a1234c05
Diff: http://git-wip-us.apache.org/repos/asf/kudu/diff/a1234c05

Branch: refs/heads/branch-1.3.x
Commit: a1234c05a03c2fbb23cd28b60b4061d9aa20761b
Parents: 436b3a4
Author: Alexey Serbin <aserbin@cloudera.com>
Authored: Thu May 11 12:20:59 2017 -0700
Committer: Jean-Daniel Cryans <jdcryans@apache.org>
Committed: Fri May 12 15:03:37 2017 +0000

----------------------------------------------------------------------
 src/kudu/util/flag_validators-test.cc | 81 ++++++++++++++++++++++++++++--
 src/kudu/util/flags.cc                |  2 +-
 2 files changed, 78 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/kudu/blob/a1234c05/src/kudu/util/flag_validators-test.cc
----------------------------------------------------------------------
diff --git a/src/kudu/util/flag_validators-test.cc b/src/kudu/util/flag_validators-test.cc
index 0bf553f..3e7fb5b 100644
--- a/src/kudu/util/flag_validators-test.cc
+++ b/src/kudu/util/flag_validators-test.cc
@@ -28,10 +28,12 @@
 
 DEFINE_string(grouped_0, "", "First flag to set.");
 DEFINE_string(grouped_1, "", "Second flag to set.");
+DEFINE_string(grouped_2, "", "Third flag to set.");
+DEFINE_string(grouped_3, "", "Fourth flag to set.");
 
 namespace kudu {
 
-static bool CheckGroupedFlags() {
+static bool CheckGroupedFlags01() {
   const bool is_set_0 = !FLAGS_grouped_0.empty();
   const bool is_set_1 = !FLAGS_grouped_1.empty();
 
@@ -42,7 +44,20 @@ static bool CheckGroupedFlags() {
 
   return true;
 }
-GROUP_FLAG_VALIDATOR(test_group_validator, CheckGroupedFlags)
+GROUP_FLAG_VALIDATOR(test_group_validator01, CheckGroupedFlags01)
+
+static bool CheckGroupedFlags23() {
+  const bool is_set_2 = !FLAGS_grouped_2.empty();
+  const bool is_set_3 = !FLAGS_grouped_3.empty();
+
+  if (is_set_2 != is_set_3) {
+    LOG(ERROR) << "--grouped_2 and --grouped_3 must be set as a group";
+    return false;
+  }
+
+  return true;
+}
+GROUP_FLAG_VALIDATOR(test_group_validator23, CheckGroupedFlags23)
 
 class FlagsValidatorsBasicTest : public KuduTest {
  public:
@@ -55,8 +70,10 @@ class FlagsValidatorsBasicTest : public KuduTest {
 
 TEST_F(FlagsValidatorsBasicTest, Grouped) {
   const auto& validators = GetFlagValidators();
-  ASSERT_EQ(1, validators.size());
-  const auto& validator = validators.begin()->second;
+  ASSERT_EQ(2, validators.size());
+  const auto& it = validators.find("test_group_validator01");
+  ASSERT_NE(validators.end(), it);
+  const auto& validator = it->second;
   EXPECT_TRUE(validator());
   FLAGS_grouped_0 = "0";
   EXPECT_FALSE(validator());
@@ -117,6 +134,16 @@ TEST_F(FlagsValidatorsDeathTest, GroupedSuccessSimple) {
       "--grouped_1=",
       "--grouped_0=",
     },
+    {
+      "argv_set_4",
+      "--grouped_2=2",
+      "--grouped_3=3",
+    },
+    {
+      "argv_set_5",
+      "--grouped_3=",
+      "--grouped_2=",
+    },
   };
   for (auto argv : argv_sets) {
     RunSuccess(argv, kArgvSize);
@@ -134,6 +161,52 @@ TEST_F(FlagsValidatorsDeathTest, GroupedFailureSimple) {
       "argv_set_1",
       "--grouped_1=b",
     },
+    {
+      "argv_set_2",
+      "--grouped_2=2",
+    },
+    {
+      "argv_set_3",
+      "--grouped_3=3",
+    },
+  };
+  for (auto argv : argv_sets) {
+    RunFailure(argv, kArgvSize);
+  }
+}
+
+// Test for correct behavior when only one of two group validators is failing.
+TEST_F(FlagsValidatorsDeathTest, GroupedFailureOneOfTwoValidators) {
+  static const size_t kArgvSize = 4 + 1;
+  const char* argv_sets[][kArgvSize] = {
+    {
+      "argv_set_0",
+      "--grouped_0=0",
+      "--grouped_1=1",
+      "--grouped_2=",
+      "--grouped_3=3",
+    },
+    {
+      "argv_set_1",
+      "--grouped_2=",
+      "--grouped_3=3",
+      "--grouped_0=0",
+      "--grouped_1=1",
+    },
+    {
+      "argv_set_2",
+      "--grouped_0=0",
+      "--grouped_1=",
+      "--grouped_2=2",
+      "--grouped_3=3",
+    },
+    {
+      "argv_set_3",
+      "--grouped_3=3",
+      "--grouped_2=2",
+      "--grouped_1=1",
+      "--grouped_0=",
+    },
   };
   for (auto argv : argv_sets) {
     RunFailure(argv, kArgvSize);

http://git-wip-us.apache.org/repos/asf/kudu/blob/a1234c05/src/kudu/util/flags.cc
----------------------------------------------------------------------
diff --git a/src/kudu/util/flags.cc b/src/kudu/util/flags.cc
index ed9b34b..6be68ac 100644
--- a/src/kudu/util/flags.cc
+++ b/src/kudu/util/flags.cc
@@ -425,7 +425,7 @@ void RunCustomValidators() {
   const auto& validators(GetFlagValidators());
   bool found_inconsistency = false;
   for (const auto& e : validators) {
-    found_inconsistency = !e.second();
+    found_inconsistency |= !e.second();
   }
   if (found_inconsistency) {
     LOG(ERROR) << "Detected inconsistency in command-line flags; exiting";


Mime
View raw message