| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| // Copyright 2017 Google Inc. | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
|
|
||
| #include "bigtable/client/client_options.h" | ||
|
|
||
| namespace bigtable { | ||
| inline namespace BIGTABLE_CLIENT_NS { | ||
| // TODO() resolve issue #52 | ||
| ClientOptions::ClientOptions() { | ||
| char const* emulator = std::getenv("BIGTABLE_EMULATOR_HOST"); | ||
| if (emulator != nullptr) { | ||
| endpoint_ = emulator; | ||
| credentials_ = grpc::InsecureChannelCredentials(); | ||
| } else { | ||
| endpoint_ = "bigtable.googleapis.com"; | ||
| credentials_ = grpc::GoogleDefaultCredentials(); | ||
| } | ||
| channel_arguments_ = grpc::ChannelArguments(); | ||
| } | ||
|
|
||
| } // namespace BIGTABLE_CLIENT_NS | ||
| } // namespace bigtable |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| // Copyright 2017 Google Inc. | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| #ifndef BIGTABLE_CLIENT_CLIENTOPTIONS_H_ | ||
| #define BIGTABLE_CLIENT_CLIENTOPTIONS_H_ | ||
|
|
||
| #include <grpc++/grpc++.h> | ||
|
|
||
| namespace bigtable { | ||
| inline namespace BIGTABLE_CLIENT_NS { | ||
| /** | ||
| * Configuration options for the Bigtable Client. | ||
| * | ||
| * Applications typically configure the client class using: | ||
| * @code | ||
| * auto client = | ||
| * bigtable::Client(bigtable::ClientOptions().SetCredentials(...)); | ||
| * @endcode | ||
| */ | ||
| class ClientOptions { | ||
| public: | ||
| ClientOptions(); | ||
| const std::string& endpoint() const { return endpoint_; } | ||
| ClientOptions& SetEndpoint(const std::string& endpoint) { | ||
| endpoint_ = endpoint; | ||
| return *this; | ||
| } | ||
| std::shared_ptr<grpc::ChannelCredentials> credentials() const { | ||
| return credentials_; | ||
| } | ||
| ClientOptions& SetCredentials( | ||
| std::shared_ptr<grpc::ChannelCredentials> credentials) { | ||
| credentials_ = credentials; | ||
| return *this; | ||
| } | ||
| // TODO() create setter/getter for each channel argument. Issue #53 | ||
| const grpc::ChannelArguments channel_arguments() const { | ||
| return channel_arguments_; | ||
| } | ||
| ClientOptions& SetChannelArguments(grpc::ChannelArguments channel_arguments) { | ||
| channel_arguments_ = channel_arguments; | ||
| return *this; | ||
| } | ||
|
|
||
| private: | ||
| // Endpoint here stands for data endpoint for fetching data. | ||
| std::string endpoint_; | ||
| std::shared_ptr<grpc::ChannelCredentials> credentials_; | ||
| grpc::ChannelArguments channel_arguments_; | ||
| }; | ||
| } // namespace BIGTABLE_CLIENT_NS | ||
| } // namespace bigtable | ||
|
|
||
| #endif // BIGTABLE_CLIENT_CLIENTOPTIONS_H_ | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| // Copyright 2017 Google Inc. | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| #include "bigtable/client/client_options.h" | ||
|
|
||
| #include <gmock/gmock.h> | ||
|
|
||
| TEST(ClientOptionsTest, ClientOptionsDefaultSettings) { | ||
| bigtable::ClientOptions client_options_object = bigtable::ClientOptions(); | ||
| EXPECT_EQ("bigtable.googleapis.com", client_options_object.endpoint()); | ||
| EXPECT_EQ(typeid(grpc::GoogleDefaultCredentials()), | ||
| typeid(client_options_object.credentials())); | ||
| } | ||
|
|
||
| TEST(ClientOptionsTest, ClientOptionsCustomEndpoint) { | ||
| setenv("BIGTABLE_EMULATOR_HOST", "testendpoint.googleapis.com", 1); | ||
| bigtable::ClientOptions client_options_object = bigtable::ClientOptions(); | ||
| EXPECT_EQ("testendpoint.googleapis.com", client_options_object.endpoint()); | ||
| EXPECT_EQ(typeid(grpc::InsecureChannelCredentials()), | ||
| typeid(client_options_object.credentials())); | ||
| unsetenv("BIGTABLE_EMULATOR_HOST"); | ||
| } | ||
|
|
||
| TEST(ClientOptionsTest, EditEndpoint) { | ||
| bigtable::ClientOptions client_options_object = bigtable::ClientOptions(); | ||
| client_options_object = | ||
| client_options_object.SetEndpoint("customendpoint.com"); | ||
| EXPECT_EQ("customendpoint.com", client_options_object.endpoint()); | ||
| } | ||
|
|
||
| TEST(ClientOptionsTest, EditCredentials) { | ||
| bigtable::ClientOptions client_options_object = bigtable::ClientOptions(); | ||
| client_options_object = | ||
| client_options_object.SetCredentials(grpc::InsecureChannelCredentials()); | ||
| EXPECT_EQ(typeid(grpc::InsecureChannelCredentials()), | ||
| typeid(client_options_object.credentials())); | ||
| } |
| Back | FazBrowse Home | New Git URL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityI think typically there is a whitespace before each member function, but don't take my word for it, use clang-format to have the right whitespaces.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityFixed using clang-format.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityThanks!
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.