Google Cloud Bigtable C++ Client 2.13.0
A C++ Client Library for Google Cloud Bigtable
Loading...
Searching...
No Matches
mock_data_connection.h
1// Copyright 2022 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_BIGTABLE_MOCKS_MOCK_DATA_CONNECTION_H
16#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGTABLE_MOCKS_MOCK_DATA_CONNECTION_H
17
18#include "google/cloud/bigtable/data_connection.h"
19#include "google/cloud/version.h"
20#include <gmock/gmock.h>
21
22namespace google {
23namespace cloud {
24namespace bigtable_mocks {
25GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
26
27/**
28 * A class to mock `google::cloud::bigtable::DataConnection`.
29 *
30 * Application developers may want to test their code with simulated responses,
31 * including errors from a `bigtable::Table`. To do so, construct a
32 * `bigtable::Table` with an instance of this class. Then use the Google Test
33 * framework functions to program the behavior of this mock.
34 *
35 * See @ref bigtable-mocking for a complete example that mocks `Table` calls.
36 */
38 public:
40 ON_CALL(*this, ReadRows)
41 .WillByDefault([this](std::string const& table_name,
42 bigtable::RowSet const& row_set,
43 std::int64_t rows_limit,
44 bigtable::Filter const& filter) {
46 table_name,
47 internal::CurrentOptions().get<bigtable::AppProfileIdOption>(),
48 row_set, rows_limit, filter};
49 return this->ReadRowsFull(params);
50 });
51 }
52
53 MOCK_METHOD(Options, options, (), (override));
54
55 MOCK_METHOD(Status, Apply,
56 (std::string const& table_name, bigtable::SingleRowMutation mut),
57 (override));
58
59 MOCK_METHOD(future<Status>, AsyncApply,
60 (std::string const& table_name, bigtable::SingleRowMutation mut),
61 (override));
62
63 MOCK_METHOD(std::vector<bigtable::FailedMutation>, BulkApply,
64 (std::string const& table_name, bigtable::BulkMutation mut),
65 (override));
66
67 MOCK_METHOD(future<std::vector<bigtable::FailedMutation>>, AsyncBulkApply,
68 (std::string const& table_name, bigtable::BulkMutation mut),
69 (override));
70
71 /// Prefer to use `ReadRowsFull()`.
72 MOCK_METHOD(bigtable::RowReader, ReadRows,
73 (std::string const& table_name, bigtable::RowSet row_set,
74 std::int64_t rows_limit, bigtable::Filter filter),
75 (override));
76
77 MOCK_METHOD(bigtable::RowReader, ReadRowsFull, (bigtable::ReadRowsParams),
78 (override));
79
80 MOCK_METHOD((StatusOr<std::pair<bool, bigtable::Row>>), ReadRow,
81 (std::string const& table_name, std::string row_key,
82 bigtable::Filter filter),
83 (override));
84
85 MOCK_METHOD(StatusOr<bigtable::MutationBranch>, CheckAndMutateRow,
86 (std::string const& table_name, std::string row_key,
87 bigtable::Filter filter,
88 std::vector<bigtable::Mutation> true_mutations,
89 std::vector<bigtable::Mutation> false_mutations),
90 (override));
91
92 MOCK_METHOD(future<StatusOr<bigtable::MutationBranch>>,
93 AsyncCheckAndMutateRow,
94 (std::string const& table_name, std::string row_key,
95 bigtable::Filter filter,
96 std::vector<bigtable::Mutation> true_mutations,
97 std::vector<bigtable::Mutation> false_mutations),
98 (override));
99
100 MOCK_METHOD(StatusOr<std::vector<bigtable::RowKeySample>>, SampleRows,
101 (std::string const& table_name), (override));
102
103 MOCK_METHOD(future<StatusOr<std::vector<bigtable::RowKeySample>>>,
104 AsyncSampleRows, (std::string const& table_name), (override));
105
106 MOCK_METHOD(StatusOr<bigtable::Row>, ReadModifyWriteRow,
107 (google::bigtable::v2::ReadModifyWriteRowRequest request),
108 (override));
109
110 MOCK_METHOD(future<StatusOr<bigtable::Row>>, AsyncReadModifyWriteRow,
111 (google::bigtable::v2::ReadModifyWriteRowRequest request),
112 (override));
113
114 MOCK_METHOD(void, AsyncReadRows,
115 (std::string const& table_name,
116 std::function<future<bool>(bigtable::Row)> on_row,
117 std::function<void(Status)> on_finish, bigtable::RowSet row_set,
118 std::int64_t rows_limit, bigtable::Filter filter),
119 (override));
120
121 MOCK_METHOD((future<StatusOr<std::pair<bool, bigtable::Row>>>), AsyncReadRow,
122 (std::string const& table_name, std::string row_key,
123 bigtable::Filter filter),
124 (override));
125};
126
127GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
128} // namespace bigtable_mocks
129} // namespace cloud
130} // namespace google
131
132#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGTABLE_MOCKS_MOCK_DATA_CONNECTION_H
ValueTypeT< T > const & get() const
Represent a set of mutations across multiple rows.
Definition: mutations.h:492
A connection to the Cloud Bigtable Data API.
Definition: data_connection.h:88
A SingleRowMutation that failed.
Definition: mutations.h:409
Define the interfaces to create filter expressions.
Definition: filters.h:52
Object returned by Table::ReadRows(), enumerates rows in the response.
Definition: row_reader.h:54
Represent a (possibly non-continuous) set of row keys.
Definition: row_set.h:33
The in-memory representation of a Bigtable row.
Definition: row.h:34
Represent a single row mutation.
Definition: mutations.h:296
A class to mock google::cloud::bigtable::DataConnection.
Definition: mock_data_connection.h:37
MockDataConnection()
Definition: mock_data_connection.h:39
friend friend class future
Definition: mock_data_connection.h:24
Contains all the Cloud Bigtable C++ client APIs.
Definition: admin_client.h:28
MutationBranch
The branch taken by a Table::CheckAndMutateRow operation.
Definition: mutation_branch.h:26
The application profile id.
Definition: options.h:75
Represent a single change to a specific row in a Table.
Definition: mutations.h:45
Wrap the arguments to ReadRows().
Definition: data_connection.h:46
A simple wrapper to represent the response from Table::SampleRowKeys().
Definition: row_key_sample.h:27