YugabyteDB (2.13.0.0-b42, bfc6a6643e7399ac8a0e81d06a3ee6d6571b33ab)

Coverage Report

Created: 2022-03-09 17:30

/Users/deen/code/yugabyte-db/src/yb/yql/pgwrapper/libpq_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
#include "yb/yql/pgwrapper/libpq_test_base.h"
13
14
#include <string>
15
16
#include "yb/common/common.pb.h"
17
#include "yb/common/pgsql_error.h"
18
#include "yb/util/monotime.h"
19
#include "yb/util/size_literals.h"
20
#include "yb/yql/pgwrapper/libpq_utils.h"
21
22
using namespace std::literals;
23
24
DECLARE_int64(external_mini_cluster_max_log_bytes);
25
26
namespace yb {
27
namespace pgwrapper {
28
29
0
void LibPqTestBase::SetUp() {
30
  // YSQL has very verbose logging in case of conflicts
31
  // TODO: reduce the verbosity of that logging.
32
0
  FLAGS_external_mini_cluster_max_log_bytes = 512_MB;
33
0
  PgWrapperTestBase::SetUp();
34
0
}
35
36
0
Result<PGConn> LibPqTestBase::Connect(bool simple_query_protocol) {
37
0
  return PGConn::Connect(
38
0
      HostPort(pg_ts->bind_host(), pg_ts->pgsql_rpc_port()), simple_query_protocol);
39
0
}
40
41
0
Result<PGConn> LibPqTestBase::ConnectToDB(const string& db_name, bool simple_query_protocol) {
42
0
  return PGConn::Connect(
43
0
      HostPort(pg_ts->bind_host(), pg_ts->pgsql_rpc_port()), db_name, simple_query_protocol);
44
0
}
45
46
Result<PGConn> LibPqTestBase::ConnectToDBAsUser(
47
0
    const string& db_name, const string& user, bool simple_query_protocol) {
48
0
  return PGConn::Connect(
49
0
      HostPort(pg_ts->bind_host(), pg_ts->pgsql_rpc_port()), db_name, user, simple_query_protocol);
50
0
}
51
52
Result<PGConn> LibPqTestBase::ConnectUsingString(
53
0
    const string& conn_str, CoarseTimePoint deadline, bool simple_query_protocol) {
54
0
  return PGConn::Connect(conn_str, deadline, simple_query_protocol);
55
0
}
56
57
0
bool LibPqTestBase::TransactionalFailure(const Status& status) {
58
0
  const uint8_t* pgerr = status.ErrorData(PgsqlErrorTag::kCategory);
59
0
  if (pgerr == nullptr) {
60
0
    return false;
61
0
  }
62
0
  YBPgErrorCode code = PgsqlErrorTag::Decode(pgerr);
63
0
  return code == YBPgErrorCode::YB_PG_T_R_SERIALIZATION_FAILURE;
64
0
}
65
66
} // namespace pgwrapper
67
} // namespace yb