/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 | 89 | void LibPqTestBase::SetUp() { |
30 | | // YSQL has very verbose logging in case of conflicts |
31 | | // TODO: reduce the verbosity of that logging. |
32 | 89 | FLAGS_external_mini_cluster_max_log_bytes = 512_MB; |
33 | 89 | PgWrapperTestBase::SetUp(); |
34 | 89 | } |
35 | | |
36 | 270 | Result<PGConn> LibPqTestBase::Connect(bool simple_query_protocol) { |
37 | 270 | return PGConn::Connect( |
38 | 270 | HostPort(pg_ts->bind_host(), pg_ts->pgsql_rpc_port()), simple_query_protocol); |
39 | 270 | } |
40 | | |
41 | 68 | Result<PGConn> LibPqTestBase::ConnectToDB(const string& db_name, bool simple_query_protocol) { |
42 | 68 | return PGConn::Connect( |
43 | 68 | HostPort(pg_ts->bind_host(), pg_ts->pgsql_rpc_port()), db_name, simple_query_protocol); |
44 | 68 | } |
45 | | |
46 | | Result<PGConn> LibPqTestBase::ConnectToDBAsUser( |
47 | 7 | const string& db_name, const string& user, bool simple_query_protocol) { |
48 | 7 | return PGConn::Connect( |
49 | 7 | HostPort(pg_ts->bind_host(), pg_ts->pgsql_rpc_port()), db_name, user, simple_query_protocol); |
50 | 7 | } |
51 | | |
52 | | Result<PGConn> LibPqTestBase::ConnectUsingString( |
53 | 10 | const string& conn_str, CoarseTimePoint deadline, bool simple_query_protocol) { |
54 | 10 | return PGConn::Connect(conn_str, deadline, simple_query_protocol); |
55 | 10 | } |
56 | | |
57 | 2.92k | bool LibPqTestBase::TransactionalFailure(const Status& status) { |
58 | 2.92k | const uint8_t* pgerr = status.ErrorData(PgsqlErrorTag::kCategory); |
59 | 2.92k | if (pgerr == nullptr) { |
60 | 0 | return false; |
61 | 0 | } |
62 | 2.92k | YBPgErrorCode code = PgsqlErrorTag::Decode(pgerr); |
63 | 2.92k | return code == YBPgErrorCode::YB_PG_T_R_SERIALIZATION_FAILURE; |
64 | 2.92k | } |
65 | | |
66 | | } // namespace pgwrapper |
67 | | } // namespace yb |