|
13 | 13 | // limitations under the License. |
14 | 14 |
|
15 | 15 | #include "google/cloud/bigtable/internal/data_connection_impl.h" |
| 16 | +#include "google/cloud/bigtable/data_connection.h" |
| 17 | +#include "google/cloud/bigtable/internal/defaults.h" |
16 | 18 | #include "google/cloud/bigtable/testing/mock_bigtable_stub.h" |
17 | 19 | #include "google/cloud/bigtable/testing/mock_policies.h" |
18 | 20 | #include "google/cloud/common_options.h" |
| 21 | +#include "google/cloud/credentials.h" |
19 | 22 | #include "google/cloud/grpc_options.h" |
20 | 23 | #include "google/cloud/internal/async_streaming_read_rpc_impl.h" |
21 | 24 | #include "google/cloud/testing_util/mock_backoff_policy.h" |
| 25 | +#include "google/cloud/testing_util/scoped_environment.h" |
22 | 26 | #include "google/cloud/testing_util/status_matchers.h" |
23 | 27 | #include <google/protobuf/text_format.h> |
24 | 28 | #include <gmock/gmock.h> |
@@ -184,11 +188,11 @@ ExponentialBackoffPolicy TestBackoffPolicy() { |
184 | 188 |
|
185 | 189 | std::shared_ptr<DataConnectionImpl> TestConnection( |
186 | 190 | std::shared_ptr<BigtableStub> mock) { |
187 | | - auto options = |
| 191 | + auto options = bigtable::internal::DefaultDataOptions( |
188 | 192 | Options{} |
189 | 193 | .set<GrpcCredentialOption>(grpc::InsecureChannelCredentials()) |
190 | 194 | .set<DataRetryPolicyOption>(TestRetryPolicy().clone()) |
191 | | - .set<DataBackoffPolicyOption>(TestBackoffPolicy().clone()); |
| 195 | + .set<DataBackoffPolicyOption>(TestBackoffPolicy().clone())); |
192 | 196 | auto background = internal::MakeBackgroundThreadsFactory(options)(); |
193 | 197 | return std::make_shared<DataConnectionImpl>( |
194 | 198 | std::move(background), std::move(mock), std::move(options)); |
@@ -232,14 +236,6 @@ TEST(TransformReadModifyWriteRowResponse, Basic) { |
232 | 236 | MatchCell(c3), MatchCell(c4))); |
233 | 237 | } |
234 | 238 |
|
235 | | -TEST(DataConnectionTest, Options) { |
236 | | - auto mock = std::make_shared<MockBigtableStub>(); |
237 | | - auto conn = TestConnection(std::move(mock)); |
238 | | - auto options = conn->options(); |
239 | | - EXPECT_TRUE(options.has<GrpcCredentialOption>()); |
240 | | - ASSERT_TRUE(options.has<EndpointOption>()); |
241 | | -} |
242 | | - |
243 | 239 | /** |
244 | 240 | * Verify that call options (provided via an OptionsSpan) take precedence over |
245 | 241 | * connection options (provided to the DataConnection constructor). We will only |
@@ -1636,6 +1632,24 @@ TEST(DataConnectionTest, AsyncReadRowFailure) { |
1636 | 1632 | EXPECT_THAT(resp, StatusIs(StatusCode::kPermissionDenied)); |
1637 | 1633 | } |
1638 | 1634 |
|
| 1635 | +TEST(MakeDataConnection, DefaultsOptions) { |
| 1636 | + using ::google::cloud::testing_util::ScopedEnvironment; |
| 1637 | + ScopedEnvironment emulator_host("BIGTABLE_EMULATOR_HOST", "localhost:1"); |
| 1638 | + |
| 1639 | + auto conn = bigtable::MakeDataConnection( |
| 1640 | + Options{} |
| 1641 | + .set<bigtable::AppProfileIdOption>("user-supplied") |
| 1642 | + // Disable channel refreshing, which is not under test. |
| 1643 | + .set<bigtable::MaxConnectionRefreshOption>(ms(0)) |
| 1644 | + // Create the minimum number of stubs. |
| 1645 | + .set<GrpcNumChannelsOption>(1)); |
| 1646 | + auto options = conn->options(); |
| 1647 | + EXPECT_TRUE(options.has<bigtable::DataRetryPolicyOption>()) |
| 1648 | + << "Options are not defaulted in MakeDataConnection()"; |
| 1649 | + EXPECT_EQ(options.get<bigtable::AppProfileIdOption>(), "user-supplied") |
| 1650 | + << "User supplied Options are overridden in MakeDataConnection()"; |
| 1651 | +} |
| 1652 | + |
1639 | 1653 | } // namespace |
1640 | 1654 | GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END |
1641 | 1655 | } // namespace bigtable_internal |
|
0 commit comments