You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kudu.apache.org by mp...@apache.org on 2017/07/13 06:33:12 UTC

[3/3] kudu git commit: mini cluster: Test infrastructure improvements

mini cluster: Test infrastructure improvements

This patch adds a couple small improvements to the MiniCluster infra.

* Add base class helpers to MiniClusterITestBase to avoid code
  duplication, including StopCluster() and ts_map_ for convenience and
  consistency with ExternalMiniClusterITestBase.
* Add ListTablets() helper function to MiniTabletServer.

Change-Id: I6bc6a04b113e59243fb788fec15b9935c3dcf069
Reviewed-on: http://gerrit.cloudera.org:8080/6959
Tested-by: Kudu Jenkins
Reviewed-by: Alexey Serbin <as...@cloudera.com>


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

Branch: refs/heads/master
Commit: b62608a8e1fa1406f7ffcd7a35cd70c177c67b2c
Parents: bbea22e
Author: Mike Percy <mp...@apache.org>
Authored: Sat May 20 22:04:46 2017 -0700
Committer: Mike Percy <mp...@apache.org>
Committed: Thu Jul 13 06:32:50 2017 +0000

----------------------------------------------------------------------
 src/kudu/integration-tests/CMakeLists.txt       |  1 +
 .../integration-tests/delete_tablet-itest.cc    |  7 +--
 .../internal_mini_cluster-itest-base.cc         | 52 ++++++++++++++++++++
 .../internal_mini_cluster-itest-base.h          | 27 +++++-----
 src/kudu/tserver/mini_tablet_server.cc          | 13 ++++-
 src/kudu/tserver/mini_tablet_server.h           |  7 ++-
 6 files changed, 82 insertions(+), 25 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/kudu/blob/b62608a8/src/kudu/integration-tests/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/src/kudu/integration-tests/CMakeLists.txt b/src/kudu/integration-tests/CMakeLists.txt
index bbe56f1..d13d396 100644
--- a/src/kudu/integration-tests/CMakeLists.txt
+++ b/src/kudu/integration-tests/CMakeLists.txt
@@ -26,6 +26,7 @@ set(INTEGRATION_TESTS_SRCS
   external_mini_cluster-itest-base.cc
   external_mini_cluster.cc
   external_mini_cluster_fs_inspector.cc
+  internal_mini_cluster-itest-base.cc
   internal_mini_cluster.cc
   log_verifier.cc
   mini_cluster.cc

http://git-wip-us.apache.org/repos/asf/kudu/blob/b62608a8/src/kudu/integration-tests/delete_tablet-itest.cc
----------------------------------------------------------------------
diff --git a/src/kudu/integration-tests/delete_tablet-itest.cc b/src/kudu/integration-tests/delete_tablet-itest.cc
index b7b2c85..c0ea6c3 100644
--- a/src/kudu/integration-tests/delete_tablet-itest.cc
+++ b/src/kudu/integration-tests/delete_tablet-itest.cc
@@ -45,13 +45,8 @@ TEST_F(DeleteTabletITest, TestDeleteFailedReplica) {
   workload.set_num_replicas(1);
   workload.Setup();
 
-  std::unordered_map<std::string, itest::TServerDetails*> ts_map;
-  ValueDeleter del(&ts_map);
-  ASSERT_OK(itest::CreateTabletServerMap(cluster_->master_proxy(),
-                                         cluster_->messenger(),
-                                         &ts_map));
   auto* mts = cluster_->mini_tablet_server(0);
-  auto* ts = ts_map[mts->uuid()];
+  auto* ts = ts_map_[mts->uuid()];
 
   scoped_refptr<TabletReplica> tablet_replica;
   ASSERT_EVENTUALLY([&] {

http://git-wip-us.apache.org/repos/asf/kudu/blob/b62608a8/src/kudu/integration-tests/internal_mini_cluster-itest-base.cc
----------------------------------------------------------------------
diff --git a/src/kudu/integration-tests/internal_mini_cluster-itest-base.cc b/src/kudu/integration-tests/internal_mini_cluster-itest-base.cc
new file mode 100644
index 0000000..c8775b4
--- /dev/null
+++ b/src/kudu/integration-tests/internal_mini_cluster-itest-base.cc
@@ -0,0 +1,52 @@
+// 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.
+
+#include "kudu/integration-tests/internal_mini_cluster-itest-base.h"
+
+#include <gtest/gtest.h>
+
+#include "kudu/gutil/stl_util.h"
+#include "kudu/integration-tests/cluster_itest_util.h"
+
+namespace kudu {
+
+void MiniClusterITestBase::TearDown() {
+  StopCluster();
+  KuduTest::TearDown();
+}
+
+void MiniClusterITestBase::StartCluster(int num_tablet_servers) {
+  InternalMiniClusterOptions opts;
+  opts.num_tablet_servers = num_tablet_servers;
+  cluster_.reset(new InternalMiniCluster(env_, opts));
+  ASSERT_OK(cluster_->Start());
+  ASSERT_OK(cluster_->CreateClient(nullptr, &client_));
+  ASSERT_OK(itest::CreateTabletServerMap(cluster_->master_proxy(),
+                                         cluster_->messenger(),
+                                         &ts_map_));
+}
+
+void MiniClusterITestBase::StopCluster() {
+  if (!cluster_) return;
+
+  cluster_->Shutdown();
+  cluster_.reset();
+  client_.reset();
+  STLDeleteValues(&ts_map_);
+}
+
+} // namespace kudu

http://git-wip-us.apache.org/repos/asf/kudu/blob/b62608a8/src/kudu/integration-tests/internal_mini_cluster-itest-base.h
----------------------------------------------------------------------
diff --git a/src/kudu/integration-tests/internal_mini_cluster-itest-base.h b/src/kudu/integration-tests/internal_mini_cluster-itest-base.h
index 5931cfd..0a69fb1 100644
--- a/src/kudu/integration-tests/internal_mini_cluster-itest-base.h
+++ b/src/kudu/integration-tests/internal_mini_cluster-itest-base.h
@@ -17,9 +17,9 @@
 
 #pragma once
 
+#include <memory>
 #include <string>
 #include <unordered_map>
-#include <vector>
 
 #include <gtest/gtest.h>
 
@@ -29,28 +29,23 @@
 
 namespace kudu {
 
+namespace itest {
+struct TServerDetails;
+}
+
 // Simple base utility class to provide a mini cluster with common setup
 // routines useful for integration tests.
 class MiniClusterITestBase : public KuduTest {
  public:
-  virtual void TearDown() OVERRIDE {
-    if (cluster_) {
-      cluster_->Shutdown();
-    }
-    KuduTest::TearDown();
-  }
+  void TearDown() override;
 
  protected:
-  void StartCluster(int num_tablet_servers = 3) {
-    InternalMiniClusterOptions opts;
-    opts.num_tablet_servers = num_tablet_servers;
-    cluster_.reset(new InternalMiniCluster(env_, opts));
-    ASSERT_OK(cluster_->Start());
-    ASSERT_OK(cluster_->CreateClient(nullptr, &client_));
-  }
-
-  gscoped_ptr<InternalMiniCluster> cluster_;
+  void StartCluster(int num_tablet_servers = 3);
+  void StopCluster();
+
+  std::unique_ptr<InternalMiniCluster> cluster_;
   client::sp::shared_ptr<client::KuduClient> client_;
+  std::unordered_map<std::string, itest::TServerDetails*> ts_map_;
 };
 
 } // namespace kudu

http://git-wip-us.apache.org/repos/asf/kudu/blob/b62608a8/src/kudu/tserver/mini_tablet_server.cc
----------------------------------------------------------------------
diff --git a/src/kudu/tserver/mini_tablet_server.cc b/src/kudu/tserver/mini_tablet_server.cc
index 1c77082..452281a 100644
--- a/src/kudu/tserver/mini_tablet_server.cc
+++ b/src/kudu/tserver/mini_tablet_server.cc
@@ -17,7 +17,6 @@
 
 #include "kudu/tserver/mini_tablet_server.h"
 
-#include <string>
 #include <utility>
 #include <vector>
 
@@ -26,6 +25,7 @@
 #include "kudu/consensus/metadata.pb.h"
 #include "kudu/gutil/strings/substitute.h"
 #include "kudu/tablet/tablet-test-util.h"
+#include "kudu/tablet/tablet_replica.h"
 #include "kudu/tserver/tablet_server.h"
 #include "kudu/tserver/ts_tablet_manager.h"
 #include "kudu/util/env_util.h"
@@ -38,6 +38,7 @@ DECLARE_bool(rpc_server_allow_ephemeral_ports);
 
 using kudu::consensus::RaftConfigPB;
 using kudu::consensus::RaftPeerPB;
+using kudu::tablet::TabletReplica;
 using std::pair;
 using std::string;
 using std::unique_ptr;
@@ -137,6 +138,16 @@ Status MiniTabletServer::AddTestTablet(const std::string& table_id,
       schema_with_ids, partition.first, config, nullptr);
 }
 
+vector<string> MiniTabletServer::ListTablets() const {
+  vector<string> tablet_ids;
+  vector<scoped_refptr<TabletReplica>> replicas;
+  server_->tablet_manager()->GetTabletReplicas(&replicas);
+  for (const auto& replica : replicas) {
+    tablet_ids.push_back(replica->tablet_id());
+  }
+  return tablet_ids;
+}
+
 void MiniTabletServer::FailHeartbeats() {
   server_->set_fail_heartbeats_for_tests(true);
 }

http://git-wip-us.apache.org/repos/asf/kudu/blob/b62608a8/src/kudu/tserver/mini_tablet_server.h
----------------------------------------------------------------------
diff --git a/src/kudu/tserver/mini_tablet_server.h b/src/kudu/tserver/mini_tablet_server.h
index f2f0231..b60d7e8 100644
--- a/src/kudu/tserver/mini_tablet_server.h
+++ b/src/kudu/tserver/mini_tablet_server.h
@@ -19,16 +19,16 @@
 
 #include <memory>
 #include <string>
+#include <vector>
 
 #include "kudu/common/schema.h"
 #include "kudu/gutil/macros.h"
 #include "kudu/tserver/tablet_server_options.h"
 #include "kudu/util/net/sockaddr.h"
-#include "kudu/util/status.h"
 
 namespace kudu {
-
 class FsManager;
+class Status;
 
 namespace consensus {
 class RaftConfigPB;
@@ -81,6 +81,9 @@ class MiniTabletServer {
                        const Schema& schema,
                        const consensus::RaftConfigPB& config);
 
+  // Return the ids of all non-tombstoned tablets on this server.
+  std::vector<std::string> ListTablets() const;
+
   // Create a RaftConfigPB which should be used to create a local-only
   // tablet on the given tablet server.
   consensus::RaftConfigPB CreateLocalConfig() const;