YugabyteDB (2.13.1.0-b60, 21121d69985fbf76aa6958d8f04a9bfa936293b5)

Coverage Report

Created: 2022-03-22 16:43

/Users/deen/code/yugabyte-db/src/yb/integration-tests/cql_test_base.cc
Line
Count
Source (jump to first uncovered line)
1
// Copyright (c) YugaByte, Inc.
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
4
// in compliance with the License.  You may obtain a copy of the License at
5
//
6
// http://www.apache.org/licenses/LICENSE-2.0
7
//
8
// Unless required by applicable law or agreed to in writing, software distributed under the License
9
// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
10
// or implied.  See the License for the specific language governing permissions and limitations
11
// under the License.
12
//
13
14
#include "yb/integration-tests/cql_test_base.h"
15
16
#include <memory>
17
18
#include "yb/integration-tests/external_mini_cluster.h"
19
#include "yb/integration-tests/mini_cluster.h"
20
#include "yb/integration-tests/yb_mini_cluster_test_base.h"
21
22
#include "yb/rpc/messenger.h"
23
24
#include "yb/tserver/heartbeater.h"
25
#include "yb/tserver/mini_tablet_server.h"
26
#include "yb/tserver/tablet_server.h"
27
28
#include "yb/util/status_log.h"
29
30
namespace yb {
31
32
template <class MiniClusterType>
33
21
void CqlTestBase<MiniClusterType>::SetupClusterOpt() {
34
21
  mini_cluster_opt_.num_masters = num_masters();
35
21
  mini_cluster_opt_.num_tablet_servers = num_tablet_servers();
36
21
}
yb::CqlTestBase<yb::ExternalMiniCluster>::SetupClusterOpt()
Line
Count
Source
33
2
void CqlTestBase<MiniClusterType>::SetupClusterOpt() {
34
2
  mini_cluster_opt_.num_masters = num_masters();
35
2
  mini_cluster_opt_.num_tablet_servers = num_tablet_servers();
36
2
}
yb::CqlTestBase<yb::MiniCluster>::SetupClusterOpt()
Line
Count
Source
33
19
void CqlTestBase<MiniClusterType>::SetupClusterOpt() {
34
19
  mini_cluster_opt_.num_masters = num_masters();
35
19
  mini_cluster_opt_.num_tablet_servers = num_tablet_servers();
36
19
}
37
38
template <>
39
2
void CqlTestBase<ExternalMiniCluster>::SetUp() {
40
2
  YBMiniClusterTestBase<ExternalMiniCluster>::SetUp();
41
2
  SetupClusterOpt();
42
2
  SetUpFlags();
43
2
  cluster_.reset(new ExternalMiniCluster(mini_cluster_opt_));
44
2
  ASSERT_OK(cluster_->Start());
45
46
2
  ASSERT_OK(MiniClusterTestWithClient<ExternalMiniCluster>::CreateClient());
47
48
2
  std::vector<std::string> hosts;
49
6
  for (size_t i = 0; i < cluster_->num_tablet_servers(); 
++i4
) {
50
4
    hosts.push_back(cluster_->tablet_server(i)->bind_host());
51
4
  }
52
53
2
  driver_ = std::make_unique<CppCassandraDriver>(
54
2
      hosts, cluster_->tablet_server(0)->cql_rpc_port(), UsePartitionAwareRouting::kFalse);
55
2
}
56
57
template <>
58
0
Status CqlTestBase<MiniCluster>::StartCQLServer() {
59
0
  auto* mini_tserver = YBMiniClusterTestBase<MiniCluster>::cluster_->mini_tablet_server(0);
60
0
  auto* tserver = mini_tserver->server();
61
62
0
  const auto& tserver_options = tserver->options();
63
0
  cqlserver::CQLServerOptions cql_server_options;
64
0
  cql_server_options.fs_opts = tserver_options.fs_opts;
65
0
  cql_server_options.master_addresses_flag = tserver_options.master_addresses_flag;
66
0
  cql_server_options.SetMasterAddresses(tserver_options.GetMasterAddresses());
67
68
0
  if (cql_port_ == 0) {
69
0
    cql_port_ = YBMiniClusterTestBase<MiniCluster>::cluster_->AllocateFreePort();
70
0
  }
71
0
  cql_host_ = mini_tserver->bound_rpc_addr().address().to_string();
72
0
  cql_server_options.rpc_opts.rpc_bind_addresses = Format("$0:$1", cql_host_, cql_port_);
73
74
0
  cql_server_ = std::make_unique<cqlserver::CQLServer>(
75
0
      cql_server_options,
76
0
      &client_->messenger()->io_service(), tserver);
77
78
0
  return cql_server_->Start();
79
0
}
80
81
template <>
82
19
void CqlTestBase<MiniCluster>::SetUp() {
83
19
  YBMiniClusterTestBase<MiniCluster>::SetUp();
84
19
  SetupClusterOpt();
85
19
  SetUpFlags();
86
19
  cluster_ = std::make_unique<MiniCluster>(mini_cluster_opt_);
87
19
  ASSERT_OK(cluster_->Start());
88
0
  ASSERT_OK(MiniClusterTestWithClient<MiniCluster>::CreateClient());
89
90
0
  ASSERT_OK(StartCQLServer());
91
92
0
  driver_ = std::make_unique<CppCassandraDriver>(
93
0
      std::vector<std::string>{ cql_host_ }, cql_port_, UsePartitionAwareRouting::kTrue);
94
0
}
95
96
template <>
97
3
void CqlTestBase<MiniCluster>::DoTearDown() {
98
3
  WARN_NOT_OK(cluster_->mini_tablet_server(0)->server()->heartbeater()->Stop(),
99
3
              "Failed to stop heartbeater");
100
3
  cql_server_->Shutdown();
101
3
  MiniClusterTestWithClient<MiniCluster>::DoTearDown();
102
3
}
103
104
template <>
105
2
void CqlTestBase<ExternalMiniCluster>::DoTearDown() {
106
2
  MiniClusterTestWithClient<ExternalMiniCluster>::DoTearDown();
107
2
}
108
109
template <>
110
0
Status CqlTestBase<MiniCluster>::RestartCluster() {
111
0
  cql_server_->Shutdown();
112
0
  cql_server_.reset();
113
0
  RETURN_NOT_OK(cluster_->RestartSync());
114
0
  return StartCQLServer();
115
0
}
116
117
template <>
118
0
void CqlTestBase<MiniCluster>::ShutdownCluster() {
119
0
  cql_server_->Shutdown();
120
0
  cql_server_.reset();
121
0
  cluster_->Shutdown();
122
0
}
123
124
template <>
125
0
Status CqlTestBase<MiniCluster>::StartCluster() {
126
0
  RETURN_NOT_OK(cluster_->StartSync());
127
0
  return StartCQLServer();
128
0
}
129
130
} // namespace yb