/Users/deen/code/yugabyte-db/src/yb/integration-tests/yb_mini_cluster_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/yb_mini_cluster_test_base.h" |
15 | | |
16 | | #include "yb/client/client.h" |
17 | | #include "yb/client/session.h" |
18 | | |
19 | | #include "yb/integration-tests/cluster_verifier.h" |
20 | | #include "yb/integration-tests/external_mini_cluster.h" |
21 | | #include "yb/integration-tests/mini_cluster.h" |
22 | | |
23 | | #include "yb/util/result.h" |
24 | | |
25 | | using namespace std::literals; |
26 | | |
27 | | DECLARE_bool(use_priority_thread_pool_for_flushes); |
28 | | DECLARE_bool(allow_preempting_compactions); |
29 | | DECLARE_uint64(index_backfill_upperbound_for_user_enforced_txn_duration_ms); |
30 | | DECLARE_int32(index_backfill_wait_for_old_txns_ms); |
31 | | DECLARE_int32(index_backfill_rpc_timeout_ms); |
32 | | DECLARE_int32(index_backfill_rpc_max_delay_ms); |
33 | | DECLARE_int32(index_backfill_rpc_max_retries); |
34 | | DECLARE_int32(retrying_ts_rpc_max_delay_ms); |
35 | | DECLARE_int32(master_ts_rpc_timeout_ms); |
36 | | |
37 | | /////////////////////////////////////////////////// |
38 | | // YBMiniClusterTestBase |
39 | | /////////////////////////////////////////////////// |
40 | | |
41 | | namespace yb { |
42 | | |
43 | | template <class T> |
44 | 367 | void YBMiniClusterTestBase<T>::SetUp() { |
45 | 367 | YBTest::SetUp(); |
46 | 367 | HybridTime::TEST_SetPrettyToString(true); |
47 | | |
48 | 367 | FLAGS_use_priority_thread_pool_for_flushes = true; |
49 | 367 | FLAGS_allow_preempting_compactions = true; |
50 | | |
51 | | // Note that if a test intends to use user enforced txns then this flag should be |
52 | | // updated accordingly, as having this to be smaller than the client timeout could |
53 | | // be unsafe. We do not want to have this be a large value in tests because it slows |
54 | | // down the normal create index flow. |
55 | 367 | FLAGS_index_backfill_upperbound_for_user_enforced_txn_duration_ms = 0; |
56 | 367 | FLAGS_index_backfill_wait_for_old_txns_ms = 0; |
57 | | |
58 | 367 | FLAGS_index_backfill_rpc_timeout_ms = 6000; |
59 | 367 | FLAGS_index_backfill_rpc_max_delay_ms = 1000; |
60 | 367 | FLAGS_index_backfill_rpc_max_retries = 10; |
61 | 367 | FLAGS_retrying_ts_rpc_max_delay_ms = 1000; |
62 | 367 | FLAGS_master_ts_rpc_timeout_ms = 10000; |
63 | | |
64 | 367 | verify_cluster_before_next_tear_down_ = true; |
65 | 367 | } _ZN2yb21YBMiniClusterTestBaseINS_11MiniClusterEE5SetUpEv Line | Count | Source | 44 | 348 | void YBMiniClusterTestBase<T>::SetUp() { | 45 | 348 | YBTest::SetUp(); | 46 | 348 | HybridTime::TEST_SetPrettyToString(true); | 47 | | | 48 | 348 | FLAGS_use_priority_thread_pool_for_flushes = true; | 49 | 348 | FLAGS_allow_preempting_compactions = true; | 50 | | | 51 | | // Note that if a test intends to use user enforced txns then this flag should be | 52 | | // updated accordingly, as having this to be smaller than the client timeout could | 53 | | // be unsafe. We do not want to have this be a large value in tests because it slows | 54 | | // down the normal create index flow. | 55 | 348 | FLAGS_index_backfill_upperbound_for_user_enforced_txn_duration_ms = 0; | 56 | 348 | FLAGS_index_backfill_wait_for_old_txns_ms = 0; | 57 | | | 58 | 348 | FLAGS_index_backfill_rpc_timeout_ms = 6000; | 59 | 348 | FLAGS_index_backfill_rpc_max_delay_ms = 1000; | 60 | 348 | FLAGS_index_backfill_rpc_max_retries = 10; | 61 | 348 | FLAGS_retrying_ts_rpc_max_delay_ms = 1000; | 62 | 348 | FLAGS_master_ts_rpc_timeout_ms = 10000; | 63 | | | 64 | 348 | verify_cluster_before_next_tear_down_ = true; | 65 | 348 | } |
_ZN2yb21YBMiniClusterTestBaseINS_19ExternalMiniClusterEE5SetUpEv Line | Count | Source | 44 | 19 | void YBMiniClusterTestBase<T>::SetUp() { | 45 | 19 | YBTest::SetUp(); | 46 | 19 | HybridTime::TEST_SetPrettyToString(true); | 47 | | | 48 | 19 | FLAGS_use_priority_thread_pool_for_flushes = true; | 49 | 19 | FLAGS_allow_preempting_compactions = true; | 50 | | | 51 | | // Note that if a test intends to use user enforced txns then this flag should be | 52 | | // updated accordingly, as having this to be smaller than the client timeout could | 53 | | // be unsafe. We do not want to have this be a large value in tests because it slows | 54 | | // down the normal create index flow. | 55 | 19 | FLAGS_index_backfill_upperbound_for_user_enforced_txn_duration_ms = 0; | 56 | 19 | FLAGS_index_backfill_wait_for_old_txns_ms = 0; | 57 | | | 58 | 19 | FLAGS_index_backfill_rpc_timeout_ms = 6000; | 59 | 19 | FLAGS_index_backfill_rpc_max_delay_ms = 1000; | 60 | 19 | FLAGS_index_backfill_rpc_max_retries = 10; | 61 | 19 | FLAGS_retrying_ts_rpc_max_delay_ms = 1000; | 62 | 19 | FLAGS_master_ts_rpc_timeout_ms = 10000; | 63 | | | 64 | 19 | verify_cluster_before_next_tear_down_ = true; | 65 | 19 | } |
|
66 | | |
67 | | template <class T> |
68 | 76 | void YBMiniClusterTestBase<T>::TearDown() { |
69 | 76 | DoBeforeTearDown(); |
70 | 76 | DoTearDown(); |
71 | 76 | } _ZN2yb21YBMiniClusterTestBaseINS_11MiniClusterEE8TearDownEv Line | Count | Source | 68 | 58 | void YBMiniClusterTestBase<T>::TearDown() { | 69 | 58 | DoBeforeTearDown(); | 70 | 58 | DoTearDown(); | 71 | 58 | } |
_ZN2yb21YBMiniClusterTestBaseINS_19ExternalMiniClusterEE8TearDownEv Line | Count | Source | 68 | 18 | void YBMiniClusterTestBase<T>::TearDown() { | 69 | 18 | DoBeforeTearDown(); | 70 | 18 | DoTearDown(); | 71 | 18 | } |
|
72 | | |
73 | | template <class T> |
74 | 76 | void YBMiniClusterTestBase<T>::DoBeforeTearDown() { |
75 | 76 | if (cluster_ && verify_cluster_before_next_tear_down_ && !testing::Test::HasFailure()) { |
76 | 14 | if (cluster_->running()) { |
77 | 12 | LOG(INFO) << "Checking cluster consistency..."; |
78 | 12 | ASSERT_NO_FATALS(ClusterVerifier(cluster_.get()).CheckCluster()); |
79 | 2 | } else { |
80 | 2 | LOG(INFO) << "Not checking cluster consistency: cluster has been shut down or failed to " |
81 | 2 | << "start properly"; |
82 | 2 | } |
83 | 14 | } |
84 | 76 | } _ZN2yb21YBMiniClusterTestBaseINS_11MiniClusterEE16DoBeforeTearDownEv Line | Count | Source | 74 | 58 | void YBMiniClusterTestBase<T>::DoBeforeTearDown() { | 75 | 58 | if (cluster_ && verify_cluster_before_next_tear_down_ && !testing::Test::HasFailure()) { | 76 | 0 | if (cluster_->running()) { | 77 | 0 | LOG(INFO) << "Checking cluster consistency..."; | 78 | 0 | ASSERT_NO_FATALS(ClusterVerifier(cluster_.get()).CheckCluster()); | 79 | 0 | } else { | 80 | 0 | LOG(INFO) << "Not checking cluster consistency: cluster has been shut down or failed to " | 81 | 0 | << "start properly"; | 82 | 0 | } | 83 | 0 | } | 84 | 58 | } |
_ZN2yb21YBMiniClusterTestBaseINS_19ExternalMiniClusterEE16DoBeforeTearDownEv Line | Count | Source | 74 | 18 | void YBMiniClusterTestBase<T>::DoBeforeTearDown() { | 75 | 18 | if (cluster_ && verify_cluster_before_next_tear_down_ && !testing::Test::HasFailure()) { | 76 | 14 | if (cluster_->running()) { | 77 | 12 | LOG(INFO) << "Checking cluster consistency..."; | 78 | 12 | ASSERT_NO_FATALS(ClusterVerifier(cluster_.get()).CheckCluster()); | 79 | 2 | } else { | 80 | 2 | LOG(INFO) << "Not checking cluster consistency: cluster has been shut down or failed to " | 81 | 2 | << "start properly"; | 82 | 2 | } | 83 | 14 | } | 84 | 18 | } |
|
85 | | |
86 | | template <class T> |
87 | 43 | void YBMiniClusterTestBase<T>::DoTearDown() { |
88 | 43 | if (cluster_) { |
89 | 41 | cluster_->Shutdown(); |
90 | 41 | cluster_.reset(); |
91 | 41 | } |
92 | 43 | YBTest::TearDown(); |
93 | 43 | } _ZN2yb21YBMiniClusterTestBaseINS_11MiniClusterEE10DoTearDownEv Line | Count | Source | 87 | 27 | void YBMiniClusterTestBase<T>::DoTearDown() { | 88 | 27 | if (cluster_) { | 89 | 25 | cluster_->Shutdown(); | 90 | 25 | cluster_.reset(); | 91 | 25 | } | 92 | 27 | YBTest::TearDown(); | 93 | 27 | } |
_ZN2yb21YBMiniClusterTestBaseINS_19ExternalMiniClusterEE10DoTearDownEv Line | Count | Source | 87 | 16 | void YBMiniClusterTestBase<T>::DoTearDown() { | 88 | 16 | if (cluster_) { | 89 | 16 | cluster_->Shutdown(); | 90 | 16 | cluster_.reset(); | 91 | 16 | } | 92 | 16 | YBTest::TearDown(); | 93 | 16 | } |
|
94 | | |
95 | | template <class T> |
96 | 5 | void YBMiniClusterTestBase<T>::DontVerifyClusterBeforeNextTearDown() { |
97 | 5 | verify_cluster_before_next_tear_down_ = false; |
98 | 5 | } _ZN2yb21YBMiniClusterTestBaseINS_11MiniClusterEE35DontVerifyClusterBeforeNextTearDownEv Line | Count | Source | 96 | 2 | void YBMiniClusterTestBase<T>::DontVerifyClusterBeforeNextTearDown() { | 97 | 2 | verify_cluster_before_next_tear_down_ = false; | 98 | 2 | } |
_ZN2yb21YBMiniClusterTestBaseINS_19ExternalMiniClusterEE35DontVerifyClusterBeforeNextTearDownEv Line | Count | Source | 96 | 3 | void YBMiniClusterTestBase<T>::DontVerifyClusterBeforeNextTearDown() { | 97 | 3 | verify_cluster_before_next_tear_down_ = false; | 98 | 3 | } |
|
99 | | |
100 | | // Instantiate explicitly to avoid recompilation of a lot of dependent test classes due to template |
101 | | // implementation changes. |
102 | | template class YBMiniClusterTestBase<MiniCluster>; |
103 | | template class YBMiniClusterTestBase<ExternalMiniCluster>; |
104 | | |
105 | | template <class T> |
106 | 18 | Status MiniClusterTestWithClient<T>::CreateClient() { |
107 | | // Connect to the cluster. |
108 | 18 | client_ = VERIFY_RESULT(YBMiniClusterTestBase<T>::cluster_->CreateClient()); |
109 | 18 | return Status::OK(); |
110 | 18 | } _ZN2yb25MiniClusterTestWithClientINS_11MiniClusterEE12CreateClientEv Line | Count | Source | 106 | 8 | Status MiniClusterTestWithClient<T>::CreateClient() { | 107 | | // Connect to the cluster. | 108 | 8 | client_ = VERIFY_RESULT(YBMiniClusterTestBase<T>::cluster_->CreateClient()); | 109 | 8 | return Status::OK(); | 110 | 8 | } |
_ZN2yb25MiniClusterTestWithClientINS_19ExternalMiniClusterEE12CreateClientEv Line | Count | Source | 106 | 10 | Status MiniClusterTestWithClient<T>::CreateClient() { | 107 | | // Connect to the cluster. | 108 | 10 | client_ = VERIFY_RESULT(YBMiniClusterTestBase<T>::cluster_->CreateClient()); | 109 | 10 | return Status::OK(); | 110 | 10 | } |
|
111 | | |
112 | | template <class T> |
113 | 33 | void MiniClusterTestWithClient<T>::DoTearDown() { |
114 | 33 | client_.reset(); |
115 | 33 | YBMiniClusterTestBase<T>::DoTearDown(); |
116 | 33 | } _ZN2yb25MiniClusterTestWithClientINS_11MiniClusterEE10DoTearDownEv Line | Count | Source | 113 | 24 | void MiniClusterTestWithClient<T>::DoTearDown() { | 114 | 24 | client_.reset(); | 115 | 24 | YBMiniClusterTestBase<T>::DoTearDown(); | 116 | 24 | } |
_ZN2yb25MiniClusterTestWithClientINS_19ExternalMiniClusterEE10DoTearDownEv Line | Count | Source | 113 | 9 | void MiniClusterTestWithClient<T>::DoTearDown() { | 114 | 9 | client_.reset(); | 115 | 9 | YBMiniClusterTestBase<T>::DoTearDown(); | 116 | 9 | } |
|
117 | | |
118 | | template <class T> |
119 | 0 | client::YBSessionPtr MiniClusterTestWithClient<T>::NewSession() { |
120 | 0 | auto session = client_->NewSession(); |
121 | 0 | session->SetTimeout(60s); |
122 | 0 | return session; |
123 | 0 | } Unexecuted instantiation: _ZN2yb25MiniClusterTestWithClientINS_11MiniClusterEE10NewSessionEv Unexecuted instantiation: _ZN2yb25MiniClusterTestWithClientINS_19ExternalMiniClusterEE10NewSessionEv |
124 | | |
125 | | // Instantiate explicitly to avoid recompilation of a lot of dependent test classes due to template |
126 | | // implementation changes. |
127 | | template class MiniClusterTestWithClient<MiniCluster>; |
128 | | template class MiniClusterTestWithClient<ExternalMiniCluster>; |
129 | | |
130 | | } // namespace yb |