Repository: kudu
Updated Branches:
  refs/heads/master dfe96efda -> a03a2f380


[tools] introduced GetKuduCtlAbsolutePath()

This is a small clean-up on the tests for the Kudu command-line tools.
Separated the code which returns the absolute path to the top-level
kudu admin tool into GetKuduCtlAbsolutePath() utility library to avoid
code duplication.

Change-Id: Ib7109859fd4cbc6d380c358fd2c4dc3d00c6e874
Reviewed-on: http://gerrit.cloudera.org:8080/4547
Reviewed-by: Adar Dembo <[email protected]>
Tested-by: Kudu Jenkins


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

Branch: refs/heads/master
Commit: a03a2f380c177fa6ba490c792829897f02d7689f
Parents: dfe96ef
Author: Alexey Serbin <[email protected]>
Authored: Tue Sep 27 17:06:43 2016 -0700
Committer: Alexey Serbin <[email protected]>
Committed: Wed Sep 28 02:47:24 2016 +0000

----------------------------------------------------------------------
 src/kudu/tools/CMakeLists.txt      | 11 ++++++++-
 src/kudu/tools/kudu-admin-test.cc  | 26 +++++---------------
 src/kudu/tools/kudu-tool-test.cc   | 10 +++-----
 src/kudu/tools/kudu-ts-cli-test.cc | 22 +++--------------
 src/kudu/tools/tool_test_util.cc   | 43 +++++++++++++++++++++++++++++++++
 src/kudu/tools/tool_test_util.h    | 31 ++++++++++++++++++++++++
 6 files changed, 97 insertions(+), 46 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/kudu/blob/a03a2f38/src/kudu/tools/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/src/kudu/tools/CMakeLists.txt b/src/kudu/tools/CMakeLists.txt
index 54159dc..47f7ae8 100644
--- a/src/kudu/tools/CMakeLists.txt
+++ b/src/kudu/tools/CMakeLists.txt
@@ -31,7 +31,8 @@ set(LINK_LIBS
 
 add_library(kudu_tools_util
   color.cc
-  data_gen_util.cc)
+  data_gen_util.cc
+)
 target_link_libraries(kudu_tools_util
   ${LINK_LIBS})
 
@@ -90,9 +91,17 @@ target_link_libraries(kudu
   ${KUDU_BASE_LIBS}
 )
 
+add_library(kudu_tools_test_util
+  tool_test_util.cc
+)
+target_link_libraries(kudu_tools_test_util
+  kudu_util
+)
+
 set(KUDU_TEST_LINK_LIBS
   ksck
   kudu_tools_util
+  kudu_tools_test_util
   integration-tests
   ${KUDU_MIN_TEST_LIBS})
 ADD_KUDU_TEST(ksck-test)

http://git-wip-us.apache.org/repos/asf/kudu/blob/a03a2f38/src/kudu/tools/kudu-admin-test.cc
----------------------------------------------------------------------
diff --git a/src/kudu/tools/kudu-admin-test.cc 
b/src/kudu/tools/kudu-admin-test.cc
index daada31..b5aac2c 100644
--- a/src/kudu/tools/kudu-admin-test.cc
+++ b/src/kudu/tools/kudu-admin-test.cc
@@ -25,6 +25,7 @@
 #include "kudu/gutil/strings/substitute.h"
 #include "kudu/integration-tests/test_workload.h"
 #include "kudu/integration-tests/ts_itest-base.h"
+#include "kudu/tools/tool_test_util.h"
 #include "kudu/util/subprocess.h"
 #include "kudu/util/test_util.h"
 
@@ -42,24 +43,9 @@ using std::string;
 using std::vector;
 using strings::Substitute;
 
-static const char* const kAdminToolName = "kudu";
-
 class AdminCliTest : public tserver::TabletServerIntegrationTestBase {
- protected:
-  // Figure out where the tool is.
-  string GetAdminToolPath() const;
 };
 
-string AdminCliTest::GetAdminToolPath() const {
-  string exe;
-  CHECK_OK(Env::Default()->GetExecutablePath(&exe));
-  string binroot = DirName(exe);
-  string tool_path = JoinPathSegments(binroot, kAdminToolName);
-  CHECK(Env::Default()->FileExists(tool_path))
-      << kAdminToolName << " tool not found at " << tool_path;
-  return tool_path;
-}
-
 // Test config change while running a workload.
 // 1. Instantiate external mini cluster with 3 TS.
 // 2. Create table with 2 replicas.
@@ -114,7 +100,7 @@ TEST_F(AdminCliTest, TestChangeConfig) {
 
   LOG(INFO) << "Adding tserver with uuid " << new_node->uuid() << " as 
VOTER...";
   ASSERT_OK(Subprocess::Call({
-    GetAdminToolPath(),
+    GetKuduCtlAbsolutePath(),
     "tablet",
     "change_config",
     "add_replica",
@@ -152,7 +138,7 @@ TEST_F(AdminCliTest, TestChangeConfig) {
   // Now remove the server once again.
   LOG(INFO) << "Removing tserver with uuid " << new_node->uuid() << " from the 
config...";
   ASSERT_OK(Subprocess::Call({
-    GetAdminToolPath(),
+    GetKuduCtlAbsolutePath(),
     "tablet",
     "change_config",
     "remove_replica",
@@ -179,7 +165,7 @@ TEST_F(AdminCliTest, TestDeleteTable) {
             .Build(&client));
 
   ASSERT_OK(Subprocess::Call({
-    GetAdminToolPath(),
+    GetKuduCtlAbsolutePath(),
     "table",
     "delete",
     master_address,
@@ -199,7 +185,7 @@ TEST_F(AdminCliTest, TestListTables) {
 
   string stdout;
   ASSERT_OK(Subprocess::Call({
-    GetAdminToolPath(),
+    GetKuduCtlAbsolutePath(),
     "table",
     "list",
     cluster_->master()->bound_rpc_addr().ToString()
@@ -236,7 +222,7 @@ TEST_F(AdminCliTest, TestListTablesDetail) {
 
   string stdout;
   ASSERT_OK(Subprocess::Call({
-    GetAdminToolPath(),
+    GetKuduCtlAbsolutePath(),
     "table",
     "list",
     "--list_tablets",

http://git-wip-us.apache.org/repos/asf/kudu/blob/a03a2f38/src/kudu/tools/kudu-tool-test.cc
----------------------------------------------------------------------
diff --git a/src/kudu/tools/kudu-tool-test.cc b/src/kudu/tools/kudu-tool-test.cc
index 1db59df..3353aae 100644
--- a/src/kudu/tools/kudu-tool-test.cc
+++ b/src/kudu/tools/kudu-tool-test.cc
@@ -46,6 +46,7 @@
 #include "kudu/tablet/local_tablet_writer.h"
 #include "kudu/tablet/tablet-harness.h"
 #include "kudu/tablet/tablet_metadata.h"
+#include "kudu/tools/tool_test_util.h"
 #include "kudu/tserver/tserver.pb.h"
 #include "kudu/util/async_util.h"
 #include "kudu/util/env.h"
@@ -81,13 +82,8 @@ using tserver::WriteRequestPB;
 
 class ToolTest : public KuduTest {
  public:
-  ToolTest() {
-    string exe;
-    CHECK_OK(env_->GetExecutablePath(&exe));
-    string bin_root = DirName(exe);
-    string tool_path = JoinPathSegments(bin_root, "kudu");
-    CHECK(env_->FileExists(tool_path)) << "kudu tool not found at " << 
tool_path;
-    tool_path_ = tool_path;
+  ToolTest()
+      : tool_path_(GetKuduCtlAbsolutePath()) {
   }
 
   Status RunTool(const string& arg_str,

http://git-wip-us.apache.org/repos/asf/kudu/blob/a03a2f38/src/kudu/tools/kudu-ts-cli-test.cc
----------------------------------------------------------------------
diff --git a/src/kudu/tools/kudu-ts-cli-test.cc 
b/src/kudu/tools/kudu-ts-cli-test.cc
index cbcf190..b3e36a2 100644
--- a/src/kudu/tools/kudu-ts-cli-test.cc
+++ b/src/kudu/tools/kudu-ts-cli-test.cc
@@ -24,6 +24,7 @@
 #include "kudu/integration-tests/cluster_itest_util.h"
 #include "kudu/integration-tests/external_mini_cluster-itest-base.h"
 #include "kudu/integration-tests/test_workload.h"
+#include "kudu/tools/tool_test_util.h"
 #include "kudu/util/path_util.h"
 #include "kudu/util/subprocess.h"
 #include "kudu/util/test_macros.h"
@@ -36,24 +37,9 @@ using strings::Substitute;
 namespace kudu {
 namespace tools {
 
-static const char* const kTsCliToolName = "kudu";
-
 class KuduTsCliTest : public ExternalMiniClusterITestBase {
- protected:
-  // Figure out where the tool is.
-  string GetTsCliToolPath() const;
 };
 
-string KuduTsCliTest::GetTsCliToolPath() const {
-  string exe;
-  CHECK_OK(Env::Default()->GetExecutablePath(&exe));
-  string binroot = DirName(exe);
-  string tool_path = JoinPathSegments(binroot, kTsCliToolName);
-  CHECK(Env::Default()->FileExists(tool_path))
-      << kTsCliToolName << " tool not found at " << tool_path;
-  return tool_path;
-}
-
 // Test deleting a tablet using kudu-ts-cli tool.
 TEST_F(KuduTsCliTest, TestDeleteTablet) {
   MonoDelta timeout = MonoDelta::FromSeconds(30);
@@ -77,7 +63,7 @@ TEST_F(KuduTsCliTest, TestDeleteTablet) {
   }
   string out;
   ASSERT_OK(Subprocess::Call({
-    GetTsCliToolPath(),
+    GetKuduCtlAbsolutePath(),
     "remote_replica",
     "delete",
     cluster_->tablet_server(0)->bound_rpc_addr().ToString(),
@@ -116,7 +102,7 @@ TEST_F(KuduTsCliTest, TestDumpTablet) {
   string out;
   // Test for dump_tablet when there is no data in tablet.
   ASSERT_OK(Subprocess::Call({
-    GetTsCliToolPath(),
+    GetKuduCtlAbsolutePath(),
     "remote_replica",
     "dump",
     cluster_->tablet_server(0)->bound_rpc_addr().ToString(),
@@ -132,7 +118,7 @@ TEST_F(KuduTsCliTest, TestDumpTablet) {
   workload.StopAndJoin();
   ASSERT_OK(WaitForServersToAgree(timeout, ts_map_, tablet_id, 
workload.batches_completed()));
   ASSERT_OK(Subprocess::Call({
-    GetTsCliToolPath(),
+    GetKuduCtlAbsolutePath(),
     "remote_replica",
     "dump",
     cluster_->tablet_server(0)->bound_rpc_addr().ToString(),

http://git-wip-us.apache.org/repos/asf/kudu/blob/a03a2f38/src/kudu/tools/tool_test_util.cc
----------------------------------------------------------------------
diff --git a/src/kudu/tools/tool_test_util.cc b/src/kudu/tools/tool_test_util.cc
new file mode 100644
index 0000000..0610c9e
--- /dev/null
+++ b/src/kudu/tools/tool_test_util.cc
@@ -0,0 +1,43 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+//
+// Utility functions for generating data for use by tools and tests.
+
+#include "kudu/tools/tool_test_util.h"
+
+#include "kudu/util/env.h"
+#include "kudu/util/path_util.h"
+#include "kudu/util/status.h"
+
+using std::string;
+
+namespace kudu {
+namespace tools {
+
+string GetKuduCtlAbsolutePath() {
+  static const string kKuduCtlFileName = "kudu";
+  string exe;
+  CHECK_OK(Env::Default()->GetExecutablePath(&exe));
+  const string binroot = DirName(exe);
+  const string tool_abs_path = JoinPathSegments(binroot, kKuduCtlFileName);
+  CHECK(Env::Default()->FileExists(tool_abs_path))
+      << kKuduCtlFileName << " binary not found at " << tool_abs_path;
+  return tool_abs_path;
+}
+
+} // namespace tools
+} // namespace kudu

http://git-wip-us.apache.org/repos/asf/kudu/blob/a03a2f38/src/kudu/tools/tool_test_util.h
----------------------------------------------------------------------
diff --git a/src/kudu/tools/tool_test_util.h b/src/kudu/tools/tool_test_util.h
new file mode 100644
index 0000000..6a89281
--- /dev/null
+++ b/src/kudu/tools/tool_test_util.h
@@ -0,0 +1,31 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+//
+// Utility functions for generating data for use by tools and tests.
+
+#pragma once
+
+#include <string>
+
+namespace kudu {
+namespace tools {
+
+// Get full path to the top-level 'kudu' tool binary.
+std::string GetKuduCtlAbsolutePath();
+
+} // namespace tools
+} // namespace kudu

Reply via email to