YugabyteDB (2.13.0.0-b42, bfc6a6643e7399ac8a0e81d06a3ee6d6571b33ab)

Coverage Report

Created: 2022-03-09 17:30

/Users/deen/code/yugabyte-db/src/yb/integration-tests/external_mini_cluster-itest-base.h
Line
Count
Source (jump to first uncovered line)
1
// Licensed to the Apache Software Foundation (ASF) under one
2
// or more contributor license agreements.  See the NOTICE file
3
// distributed with this work for additional information
4
// regarding copyright ownership.  The ASF licenses this file
5
// to you under the Apache License, Version 2.0 (the
6
// "License"); you may not use this file except in compliance
7
// with the License.  You may obtain a copy of the License at
8
//
9
//   http://www.apache.org/licenses/LICENSE-2.0
10
//
11
// Unless required by applicable law or agreed to in writing,
12
// software distributed under the License is distributed on an
13
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
// KIND, either express or implied.  See the License for the
15
// specific language governing permissions and limitations
16
// under the License.
17
//
18
// The following only applies to changes made to this file as part of YugaByte development.
19
//
20
// Portions Copyright (c) YugaByte, Inc.
21
//
22
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
23
// in compliance with the License.  You may obtain a copy of the License at
24
//
25
// http://www.apache.org/licenses/LICENSE-2.0
26
//
27
// Unless required by applicable law or agreed to in writing, software distributed under the License
28
// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
29
// or implied.  See the License for the specific language governing permissions and limitations
30
// under the License.
31
//
32
33
#ifndef YB_INTEGRATION_TESTS_EXTERNAL_MINI_CLUSTER_ITEST_BASE_H_
34
#define YB_INTEGRATION_TESTS_EXTERNAL_MINI_CLUSTER_ITEST_BASE_H_
35
36
#include <string>
37
#include <unordered_map>
38
#include <vector>
39
#include <gtest/gtest.h>
40
41
#include "yb/client/client.h"
42
#include "yb/gutil/stl_util.h"
43
#include "yb/integration-tests/cluster_itest_util.h"
44
#include "yb/integration-tests/external_mini_cluster.h"
45
#include "yb/integration-tests/external_mini_cluster_fs_inspector.h"
46
47
#include "yb/master/master_cluster.proxy.h"
48
49
#include "yb/util/pstack_watcher.h"
50
#include "yb/util/status_log.h"
51
#include "yb/util/test_util.h"
52
53
namespace yb {
54
55
// Simple base utility class to provide an external mini cluster with common
56
// setup routines useful for integration tests.
57
class ExternalMiniClusterITestBase : public YBTest {
58
 public:
59
88
  virtual void SetUpCluster(ExternalMiniClusterOptions* opts) {
60
    // Fsync causes flakiness on EC2.
61
88
    CHECK_NOTNULL(opts)->extra_tserver_flags.push_back("--never_fsync");
62
88
  }
63
64
68
  virtual void TearDown() override {
65
68
    client_.reset();
66
68
    if (cluster_) {
67
65
      if (HasFatalFailure()) {
68
7
        LOG(INFO) << "Found fatal failure";
69
28
        for (size_t i = 0; i < cluster_->num_tablet_servers(); i++) {
70
21
          if (!cluster_->tablet_server(i)->IsProcessAlive()) {
71
0
            LOG(INFO) << "Tablet server " << i << " is not running. Cannot dump its stacks.";
72
0
            continue;
73
0
          }
74
21
          LOG(INFO) << "Attempting to dump stacks of TS " << i
75
21
                    << " with UUID " << cluster_->tablet_server(i)->uuid()
76
21
                    << " and pid " << cluster_->tablet_server(i)->pid();
77
21
          WARN_NOT_OK(PstackWatcher::DumpPidStacks(cluster_->tablet_server(i)->pid()),
78
21
                      "Couldn't dump stacks");
79
21
        }
80
7
      }
81
65
      cluster_->Shutdown();
82
65
    }
83
68
    YBTest::TearDown();
84
68
    ts_map_.clear();
85
68
  }
86
87
 protected:
88
  void StartCluster(const std::vector<std::string>& extra_ts_flags = std::vector<std::string>(),
89
                    const std::vector<std::string>& extra_master_flags = std::vector<std::string>(),
90
                    int num_tablet_servers = 3,
91
                    int num_masters = 1,
92
                    bool enable_ysql = false);
93
94
  std::unique_ptr<ExternalMiniCluster> cluster_;
95
  std::unique_ptr<itest::ExternalMiniClusterFsInspector> inspect_;
96
  std::unique_ptr<client::YBClient> client_;
97
  itest::TabletServerMap ts_map_;
98
};
99
100
void ExternalMiniClusterITestBase::StartCluster(const std::vector<std::string>& extra_ts_flags,
101
                                                const std::vector<std::string>& extra_master_flags,
102
                                                int num_tablet_servers,
103
                                                int num_masters,
104
88
                                                bool enable_ysql) {
105
88
  ExternalMiniClusterOptions opts;
106
88
  opts.num_masters = num_masters;
107
88
  opts.num_tablet_servers = num_tablet_servers;
108
88
  opts.extra_master_flags = extra_master_flags;
109
88
  opts.extra_tserver_flags = extra_ts_flags;
110
88
  opts.enable_ysql = enable_ysql;
111
88
  SetUpCluster(&opts);
112
113
88
  cluster_.reset(new ExternalMiniCluster(opts));
114
88
  ASSERT_OK(cluster_->Start());
115
88
  inspect_.reset(new itest::ExternalMiniClusterFsInspector(cluster_.get()));
116
88
  ts_map_ = ASSERT_RESULT(itest::CreateTabletServerMap(cluster_.get()));
117
87
  client_ = ASSERT_RESULT(cluster_->CreateClient());
118
87
}
119
120
}  // namespace yb
121
122
#endif // YB_INTEGRATION_TESTS_EXTERNAL_MINI_CLUSTER_ITEST_BASE_H_