YugabyteDB (2.13.0.0-b42, bfc6a6643e7399ac8a0e81d06a3ee6d6571b33ab)

Coverage Report

Created: 2022-03-09 17:30

/Users/deen/code/yugabyte-db/src/yb/master/sys_catalog-test_base.h
Line
Count
Source
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_MASTER_SYS_CATALOG_TEST_BASE_H_
34
#define YB_MASTER_SYS_CATALOG_TEST_BASE_H_
35
36
#include <gtest/gtest.h>
37
38
#include "yb/common/wire_protocol.h"
39
#include "yb/master/master.h"
40
#include "yb/master/mini_master.h"
41
#include "yb/master/sys_catalog.h"
42
#include "yb/rpc/messenger.h"
43
#include "yb/rpc/proxy.h"
44
#include "yb/server/rpc_server.h"
45
#include "yb/util/net/sockaddr.h"
46
#include "yb/util/result.h"
47
#include "yb/util/status_fwd.h"
48
#include "yb/util/test_util.h"
49
50
using yb::rpc::Messenger;
51
using yb::rpc::MessengerBuilder;
52
53
namespace yb {
54
namespace master {
55
56
class SysCatalogTest : public YBTest {
57
 protected:
58
15
  void SetUp() override {
59
15
    YBTest::SetUp();
60
61
    // Start master with the create flag on.
62
15
    mini_master_.reset(
63
15
        new MiniMaster(Env::Default(), GetTestPath("Master"), AllocateFreePort(),
64
15
                       AllocateFreePort(), 0));
65
15
    ASSERT_OK(mini_master_->Start());
66
15
    master_ = mini_master_->master();
67
15
    ASSERT_OK(master_->WaitUntilCatalogManagerIsLeaderAndReadyForTests());
68
69
    // Create a client proxy to it.
70
15
    MessengerBuilder bld("Client");
71
15
    client_messenger_ = ASSERT_RESULT(bld.Build());
72
15
    rpc::ProxyCache proxy_cache(client_messenger_.get());
73
15
  }
74
75
14
  void TearDown() override {
76
14
    if (client_messenger_) {
77
14
      client_messenger_->Shutdown();
78
14
    }
79
14
    mini_master_->Shutdown();
80
14
    YBTest::TearDown();
81
14
  }
82
83
  std::unique_ptr<Messenger> client_messenger_;
84
  std::unique_ptr<MiniMaster> mini_master_;
85
  Master* master_;
86
};
87
88
const int64_t kLeaderTerm = 1;
89
90
3
inline bool PbEquals(const google::protobuf::Message& a, const google::protobuf::Message& b) {
91
3
  return a.DebugString() == b.DebugString();
92
3
}
93
94
template<class C>
95
33
std::pair<std::string, std::string> AssertMetadataEqualsHelper(C* ti_a, C* ti_b) {
96
33
  auto l_a = ti_a->LockForRead();
97
33
  auto l_b = ti_b->LockForRead();
98
33
  return std::make_pair(l_a->pb.DebugString(), l_b->pb.DebugString());
99
33
}
_ZN2yb6master26AssertMetadataEqualsHelperINS0_9TableInfoEEENSt3__14pairINS3_12basic_stringIcNS3_11char_traitsIcEENS3_9allocatorIcEEEESA_EEPT_SD_
Line
Count
Source
95
3
std::pair<std::string, std::string> AssertMetadataEqualsHelper(C* ti_a, C* ti_b) {
96
3
  auto l_a = ti_a->LockForRead();
97
3
  auto l_b = ti_b->LockForRead();
98
3
  return std::make_pair(l_a->pb.DebugString(), l_b->pb.DebugString());
99
3
}
_ZN2yb6master26AssertMetadataEqualsHelperINS0_10TabletInfoEEENSt3__14pairINS3_12basic_stringIcNS3_11char_traitsIcEENS3_9allocatorIcEEEESA_EEPT_SD_
Line
Count
Source
95
8
std::pair<std::string, std::string> AssertMetadataEqualsHelper(C* ti_a, C* ti_b) {
96
8
  auto l_a = ti_a->LockForRead();
97
8
  auto l_b = ti_b->LockForRead();
98
8
  return std::make_pair(l_a->pb.DebugString(), l_b->pb.DebugString());
99
8
}
_ZN2yb6master26AssertMetadataEqualsHelperINS0_17ClusterConfigInfoEEENSt3__14pairINS3_12basic_stringIcNS3_11char_traitsIcEENS3_9allocatorIcEEEESA_EEPT_SD_
Line
Count
Source
95
2
std::pair<std::string, std::string> AssertMetadataEqualsHelper(C* ti_a, C* ti_b) {
96
2
  auto l_a = ti_a->LockForRead();
97
2
  auto l_b = ti_b->LockForRead();
98
2
  return std::make_pair(l_a->pb.DebugString(), l_b->pb.DebugString());
99
2
}
_ZN2yb6master26AssertMetadataEqualsHelperINS0_13NamespaceInfoEEENSt3__14pairINS3_12basic_stringIcNS3_11char_traitsIcEENS3_9allocatorIcEEEESA_EEPT_SD_
Line
Count
Source
95
2
std::pair<std::string, std::string> AssertMetadataEqualsHelper(C* ti_a, C* ti_b) {
96
2
  auto l_a = ti_a->LockForRead();
97
2
  auto l_b = ti_b->LockForRead();
98
2
  return std::make_pair(l_a->pb.DebugString(), l_b->pb.DebugString());
99
2
}
_ZN2yb6master26AssertMetadataEqualsHelperINS0_15RedisConfigInfoEEENSt3__14pairINS3_12basic_stringIcNS3_11char_traitsIcEENS3_9allocatorIcEEEESA_EEPT_SD_
Line
Count
Source
95
3
std::pair<std::string, std::string> AssertMetadataEqualsHelper(C* ti_a, C* ti_b) {
96
3
  auto l_a = ti_a->LockForRead();
97
3
  auto l_b = ti_b->LockForRead();
98
3
  return std::make_pair(l_a->pb.DebugString(), l_b->pb.DebugString());
99
3
}
_ZN2yb6master26AssertMetadataEqualsHelperINS0_13SysConfigInfoEEENSt3__14pairINS3_12basic_stringIcNS3_11char_traitsIcEENS3_9allocatorIcEEEESA_EEPT_SD_
Line
Count
Source
95
10
std::pair<std::string, std::string> AssertMetadataEqualsHelper(C* ti_a, C* ti_b) {
96
10
  auto l_a = ti_a->LockForRead();
97
10
  auto l_b = ti_b->LockForRead();
98
10
  return std::make_pair(l_a->pb.DebugString(), l_b->pb.DebugString());
99
10
}
_ZN2yb6master26AssertMetadataEqualsHelperINS0_8RoleInfoEEENSt3__14pairINS3_12basic_stringIcNS3_11char_traitsIcEENS3_9allocatorIcEEEESA_EEPT_SD_
Line
Count
Source
95
2
std::pair<std::string, std::string> AssertMetadataEqualsHelper(C* ti_a, C* ti_b) {
96
2
  auto l_a = ti_a->LockForRead();
97
2
  auto l_b = ti_b->LockForRead();
98
2
  return std::make_pair(l_a->pb.DebugString(), l_b->pb.DebugString());
99
2
}
_ZN2yb6master26AssertMetadataEqualsHelperINS0_10UDTypeInfoEEENSt3__14pairINS3_12basic_stringIcNS3_11char_traitsIcEENS3_9allocatorIcEEEESA_EEPT_SD_
Line
Count
Source
95
1
std::pair<std::string, std::string> AssertMetadataEqualsHelper(C* ti_a, C* ti_b) {
96
1
  auto l_a = ti_a->LockForRead();
97
1
  auto l_b = ti_b->LockForRead();
98
1
  return std::make_pair(l_a->pb.DebugString(), l_b->pb.DebugString());
99
1
}
_ZN2yb6master26AssertMetadataEqualsHelperINS0_13CDCStreamInfoEEENSt3__14pairINS3_12basic_stringIcNS3_11char_traitsIcEENS3_9allocatorIcEEEESA_EEPT_SD_
Line
Count
Source
95
1
std::pair<std::string, std::string> AssertMetadataEqualsHelper(C* ti_a, C* ti_b) {
96
1
  auto l_a = ti_a->LockForRead();
97
1
  auto l_b = ti_b->LockForRead();
98
1
  return std::make_pair(l_a->pb.DebugString(), l_b->pb.DebugString());
99
1
}
_ZN2yb6master26AssertMetadataEqualsHelperINS0_23UniverseReplicationInfoEEENSt3__14pairINS3_12basic_stringIcNS3_11char_traitsIcEENS3_9allocatorIcEEEESA_EEPT_SD_
Line
Count
Source
95
1
std::pair<std::string, std::string> AssertMetadataEqualsHelper(C* ti_a, C* ti_b) {
96
1
  auto l_a = ti_a->LockForRead();
97
1
  auto l_b = ti_b->LockForRead();
98
1
  return std::make_pair(l_a->pb.DebugString(), l_b->pb.DebugString());
99
1
}
100
101
// Similar to ASSERT_EQ but compares string representations of protobufs stored in two system
102
// catalog metadata objects.
103
//
104
// This uses a gtest internal macro for user-friendly output, as it shows the expressions passed to
105
// ASSERT_METADATA_EQ the same way ASSERT_EQ would show them. If the internal macro stops working
106
// the way it does now with a future version of gtest, it could be replaced with:
107
//
108
// ASSERT_EQ(string_reps.first, string_reps.second)
109
//     << "Expecting string representations of metadata protobufs to be the same for "
110
//     << #a << " and " << #b;
111
112
33
#define ASSERT_METADATA_EQ(a, b) do { \
113
33
    auto string_reps = AssertMetadataEqualsHelper((a), (b)); \
114
33
    GTEST_ASSERT_( \
115
33
      ::testing::internal::EqHelper<GTEST_IS_NULL_LITERAL_(a)>::Compare \
116
33
          (#a, #b, string_reps.first, string_reps.second), \
117
66
          GTEST_FATAL_FAILURE_); \
118
33
  } while (false)
119
120
121
122
} // namespace master
123
} // namespace yb
124
125
#endif // YB_MASTER_SYS_CATALOG_TEST_BASE_H_