Google Cloud Spanner C++ Client 2.13.0
A C++ Client Library for Google Cloud Spanner
Loading...
Searching...
No Matches
mock_spanner_connection.h
1// Copyright 2019 Google LLC
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// https://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_SPANNER_MOCKS_MOCK_SPANNER_CONNECTION_H
16#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_SPANNER_MOCKS_MOCK_SPANNER_CONNECTION_H
17
18#include "google/cloud/spanner/connection.h"
19#include "google/cloud/spanner/query_partition.h"
20#include "google/cloud/spanner/read_partition.h"
21#include "google/cloud/spanner/row.h"
22#include "google/cloud/spanner/version.h"
23#include <gmock/gmock.h>
24#include <vector>
25
26namespace google {
27namespace cloud {
28/// Define classes to mock the Cloud Spanner C++ client APIs.
29namespace spanner_mocks {
30/// An inlined versioned namespace to avoid dependency diamonds.
31GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
32
33/**
34 * A class to mock `google::cloud::spanner::Connection`.
35 *
36 * Application developers may want to test their code with simulated responses,
37 * including errors from a `spanner::Client`. To do so, construct a
38 * `spanner::Client` with an instance of this class. Then use the Google Test
39 * framework functions to program the behavior of this mock.
40 *
41 * @see @ref spanner-mocking for an example using this class.
42 */
43class MockConnection : public spanner::Connection {
44 public:
45 MOCK_METHOD(Options, options, (), (override));
46 MOCK_METHOD(spanner::RowStream, Read, (ReadParams), (override));
47 MOCK_METHOD(StatusOr<std::vector<spanner::ReadPartition>>, PartitionRead,
49 MOCK_METHOD(spanner::RowStream, ExecuteQuery, (SqlParams), (override));
50 MOCK_METHOD(StatusOr<spanner::DmlResult>, ExecuteDml, (SqlParams),
51 (override));
52 MOCK_METHOD(spanner::ProfileQueryResult, ProfileQuery, (SqlParams),
53 (override));
54 MOCK_METHOD(StatusOr<spanner::ProfileDmlResult>, ProfileDml, (SqlParams),
55 (override));
56 MOCK_METHOD(StatusOr<spanner::ExecutionPlan>, AnalyzeSql, (SqlParams),
57 (override));
58 MOCK_METHOD(StatusOr<spanner::PartitionedDmlResult>, ExecutePartitionedDml,
60 MOCK_METHOD(StatusOr<std::vector<spanner::QueryPartition>>, PartitionQuery,
62 MOCK_METHOD(StatusOr<spanner::BatchDmlResult>, ExecuteBatchDml,
64 MOCK_METHOD(StatusOr<spanner::CommitResult>, Commit, (CommitParams),
65 (override));
66 MOCK_METHOD(Status, Rollback, (RollbackParams), (override));
67};
68
69/**
70 * Mock the results of a ExecuteQuery() or Read() operation.
71 *
72 * @see @ref spanner-mocking for an example using this class.
73 */
75 public:
76 MOCK_METHOD(StatusOr<spanner::Row>, NextRow, (), (override));
77 MOCK_METHOD(absl::optional<google::spanner::v1::ResultSetMetadata>, Metadata,
78 (), (override));
79 MOCK_METHOD(absl::optional<google::spanner::v1::ResultSetStats>, Stats, (),
80 (const, override));
81};
82
83GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
84} // namespace spanner_mocks
85} // namespace cloud
86} // namespace google
87
88#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_SPANNER_MOCKS_MOCK_SPANNER_CONNECTION_H
A connection to a Spanner database instance.
Definition: connection.h:59
Represents the result of a data modifying operation using spanner::Client::ExecuteDml().
Definition: results.h:146
Represents the result and profile stats of a data modifying operation using spanner::Client::ProfileD...
Definition: results.h:244
Represents the stream of Rows and profile stats returned from spanner::Client::ProfileQuery().
Definition: results.h:186
The QueryPartition class is a regular type that represents a single slice of a parallel SQL read.
Definition: query_partition.h:89
The ReadPartition class is a regular type that represents a single slice of a parallel Read operation...
Definition: read_partition.h:90
Defines the interface for RowStream implementations.
Definition: results.h:42
Represents the stream of Rows returned from spanner::Client::Read() or spanner::Client::ExecuteQuery(...
Definition: results.h:101
A Row is a sequence of columns each with a name and an associated Value.
Definition: row.h:84
An inlined versioned namespace to avoid dependency diamonds.
Definition: mock_spanner_connection.h:43
Mock the results of a ExecuteQuery() or Read() operation.
Definition: mock_spanner_connection.h:74
Define classes to mock the Cloud Spanner C++ client APIs.
Definition: mock_database_admin_connection.h:24
Contains all the Cloud Spanner C++ client types and functions.
Definition: backoff_policy.h:23
The result of executing a batch of DML statements.
Definition: batch_dml_result.h:39
The result of committing a Transaction.
Definition: commit_result.h:38
Wrap the arguments to Commit().
Definition: connection.h:121
Wrap the arguments to ExecuteBatchDml().
Definition: connection.h:114
Wrap the arguments to ExecutePartitionedDml().
Definition: connection.h:101
Wrap the arguments to PartitionQuery().
Definition: connection.h:107
Wrap the arguments to PartitionRead().
Definition: connection.h:85
Wrap the arguments to Read().
Definition: connection.h:74
Wrap the arguments to Rollback().
Definition: connection.h:128
Wrap the arguments to ExecuteQuery(), ExecuteDml(), ProfileQuery(), ProfileDml(), and AnalyzeSql().
Definition: connection.h:92
The result of executing a Partitioned DML query.
Definition: partitioned_dml_result.h:29