YugabyteDB (2.13.0.0-b42, bfc6a6643e7399ac8a0e81d06a3ee6d6571b33ab)

Coverage Report

Created: 2022-03-09 17:30

/Users/deen/code/yugabyte-db/src/yb/yql/pggate/test/pggate_test.h
Line
Count
Source (jump to first uncovered line)
1
//--------------------------------------------------------------------------------------------------
2
// Copyright (c) YugaByte, Inc.
3
//
4
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5
// in compliance with the License.  You may obtain a copy of the License at
6
//
7
// http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software distributed under the License
10
// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11
// or implied.  See the License for the specific language governing permissions and limitations
12
// under the License.
13
//
14
//--------------------------------------------------------------------------------------------------
15
16
#ifndef YB_YQL_PGGATE_TEST_PGGATE_TEST_H_
17
#define YB_YQL_PGGATE_TEST_PGGATE_TEST_H_
18
19
#include <dirent.h>
20
#include <stdint.h>
21
22
#include "pg_type_d.h" // NOLINT
23
24
#include "yb/common/value.pb.h"
25
#include "yb/common/ybc_util.h"
26
27
#include "yb/integration-tests/external_mini_cluster.h"
28
29
#include "yb/tserver/tserver_util_fwd.h"
30
31
#include "yb/util/shared_mem.h"
32
#include "yb/util/test_util.h"
33
34
#include "yb/yql/pggate/ybc_pg_typedefs.h"
35
36
// This file comes from this directory:
37
// postgres_build/src/include/catalog
38
// We add a special include path to CMakeLists.txt.
39
40
namespace yb {
41
namespace pggate {
42
43
//--------------------------------------------------------------------------------------------------
44
// Test base class.
45
//--------------------------------------------------------------------------------------------------
46
#define CHECK_YBC_STATUS(s) \
47
0
    ::yb::pggate::PggateTest::CheckYBCStatus((s), __FILE__, __LINE__)
48
49
class PggateTest : public YBTest {
50
 public:
51
  static constexpr int kNumOfTablets = 3;
52
  static constexpr const char* kDefaultDatabase = "pggate_test_database";
53
  static constexpr const char* kDefaultSchema = "pggate_test_schema";
54
  static constexpr YBCPgOid kDefaultDatabaseOid = 1;
55
56
  PggateTest();
57
  virtual ~PggateTest();
58
59
  //------------------------------------------------------------------------------------------------
60
  static void CheckYBCStatus(YBCStatus status, const char* file_name, int line_number);
61
62
  //------------------------------------------------------------------------------------------------
63
  // Test start and cleanup functions.
64
  void SetUp() override;
65
  void TearDown() override;
66
67
  // Init cluster for each test case.
68
  CHECKED_STATUS Init(const char *test_name, int num_tablet_servers = kNumOfTablets);
69
70
  // Create simulated cluster.
71
  CHECKED_STATUS CreateCluster(int num_tablet_servers);
72
73
  //------------------------------------------------------------------------------------------------
74
  // Setup the database for testing.
75
  void SetupDB(const string& db_name = kDefaultDatabase, YBCPgOid db_oid = kDefaultDatabaseOid);
76
  void CreateDB(const string& db_name = kDefaultDatabase, YBCPgOid db_oid = kDefaultDatabaseOid);
77
  void ConnectDB(const string& db_name = kDefaultDatabase);
78
79
 protected:
80
  void BeginDDLTransaction();
81
  void CommitDDLTransaction();
82
  void BeginTransaction();
83
  void CommitTransaction();
84
85
  //------------------------------------------------------------------------------------------------
86
  // Simulated cluster.
87
  std::shared_ptr<ExternalMiniCluster> cluster_;
88
  tserver::TServerSharedObject tserver_shared_object_;
89
};
90
91
//--------------------------------------------------------------------------------------------------
92
// Test type table and other variables.
93
//--------------------------------------------------------------------------------------------------
94
void YBCTestGetTypeTable(const YBCPgTypeEntity **type_table, int *count);
95
96
//--------------------------------------------------------------------------------------------------
97
// Test API
98
//--------------------------------------------------------------------------------------------------
99
typedef uint64_t Datum;
100
101
// Allocation.
102
void *PggateTestAlloc(size_t bytes);
103
104
// Add column.
105
YBCStatus YBCTestCreateTableAddColumn(YBCPgStatement handle, const char *attr_name, int attr_num,
106
                                      DataType yb_type, bool is_hash, bool is_range);
107
108
// Column ref expression.
109
YBCStatus YBCTestNewColumnRef(YBCPgStatement stmt, int attr_num, DataType yb_type,
110
                              YBCPgExpr *expr_handle);
111
112
// Constant expressions.
113
YBCStatus YBCTestNewConstantBool(YBCPgStatement stmt, bool value, bool is_null,
114
                                 YBCPgExpr *expr_handle);
115
YBCStatus YBCTestNewConstantInt1(YBCPgStatement stmt, int8_t value, bool is_null,
116
                                 YBCPgExpr *expr_handle);
117
YBCStatus YBCTestNewConstantInt2(YBCPgStatement stmt, int16_t value, bool is_null,
118
                                 YBCPgExpr *expr_handle);
119
YBCStatus YBCTestNewConstantInt4(YBCPgStatement stmt, int32_t value, bool is_null,
120
                                 YBCPgExpr *expr_handle);
121
YBCStatus YBCTestNewConstantInt8(YBCPgStatement stmt, int64_t value, bool is_null,
122
                                 YBCPgExpr *expr_handle);
123
YBCStatus YBCTestNewConstantInt8Op(YBCPgStatement stmt, int64_t value, bool is_null,
124
                                 YBCPgExpr *expr_handle, bool is_gt);
125
YBCStatus YBCTestNewConstantFloat4(YBCPgStatement stmt, float value, bool is_null,
126
                                   YBCPgExpr *expr_handle);
127
YBCStatus YBCTestNewConstantFloat8(YBCPgStatement stmt, double value, bool is_null,
128
                                   YBCPgExpr *expr_handle);
129
YBCStatus YBCTestNewConstantText(YBCPgStatement stmt, const char *value, bool is_null,
130
                                 YBCPgExpr *expr_handle);
131
132
}  // namespace pggate
133
}  // namespace yb
134
135
#endif // YB_YQL_PGGATE_TEST_PGGATE_TEST_H_