├── .bazelci └── presubmit.yml ├── .bazelignore ├── .bazelrc ├── .clang-format ├── .clang-tidy ├── .cmake-format.py ├── .codecov.yml ├── .dockerignore ├── .github └── ISSUE_TEMPLATE │ ├── bug_report.md │ └── feature_request.md ├── .gitignore ├── BUILD ├── CHANGELOG.md ├── CMakeLists.txt ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── WORKSPACE ├── bazel ├── BUILD ├── google_cloud_cpp_spanner_deps.bzl └── googleapis.BUILD ├── ci ├── check-include-guards.gawk ├── check-markdown.sh ├── check-style.sh ├── colors.sh ├── define-dump-log.sh ├── etc │ ├── install-config.sh │ ├── kokoro │ │ └── install │ │ │ ├── project-config.sh │ │ │ ├── run-installed-programs.sh │ │ │ └── version-config.sh │ ├── publish-refdocs.sh │ └── repo-config.sh ├── generate-markdown │ ├── README.md │ ├── dockerfile2markdown.sh │ ├── extract-install.sh │ ├── generate-packaging.sh │ ├── generate-readme.sh │ └── generate-spanner-readme.sh ├── install-bazel.sh ├── kokoro │ ├── Dockerfile.centos │ ├── Dockerfile.fedora-install │ ├── Dockerfile.fedora-libcxx-msan │ ├── Dockerfile.ubuntu │ ├── Dockerfile.ubuntu-xenial │ ├── define-docker-variables.sh │ ├── docker │ │ ├── README.md │ │ ├── asan-presubmit.cfg │ │ ├── asan.cfg │ │ ├── bazel-dependency-presubmit.cfg │ │ ├── bazel-dependency.cfg │ │ ├── build-in-docker-bazel-dependency.sh │ │ ├── build-in-docker-bazel.sh │ │ ├── build-in-docker-cmake.sh │ │ ├── build.sh │ │ ├── check-api-presubmit.cfg │ │ ├── check-api.cfg │ │ ├── check-api.sh │ │ ├── clang-3.8-presubmit.cfg │ │ ├── clang-3.8.cfg │ │ ├── clang-tidy-presubmit.cfg │ │ ├── clang-tidy.cfg │ │ ├── cmake-presubmit.cfg │ │ ├── cmake-super-presubmit.cfg │ │ ├── cmake-super.cfg │ │ ├── cmake.cfg │ │ ├── common.cfg │ │ ├── coverage-presubmit.cfg │ │ ├── coverage.cfg │ │ ├── cxx17-presubmit.cfg │ │ ├── cxx17.cfg │ │ ├── download-cache.sh │ │ ├── dump-reports.sh │ │ ├── gcc-4.8-presubmit.cfg │ │ ├── gcc-4.8.cfg │ │ ├── integration-presubmit.cfg │ │ ├── integration.cfg │ │ ├── msan-presubmit.cfg │ │ ├── msan.cfg │ │ ├── ninja-presubmit.cfg │ │ ├── ninja.cfg │ │ ├── noex-presubmit.cfg │ │ ├── noex.cfg │ │ ├── publish-refdocs.cfg │ │ ├── publish-refdocs.sh │ │ ├── tsan-presubmit.cfg │ │ ├── tsan.cfg │ │ ├── ubsan-presubmit.cfg │ │ ├── ubsan.cfg │ │ ├── upload-cache.sh │ │ ├── upload-coverage.sh │ │ └── upload-docs.sh │ ├── dump-logs.sh │ ├── gcloud-functions.sh │ ├── install │ │ ├── Dockerfile.centos-7 │ │ ├── Dockerfile.centos-8 │ │ ├── Dockerfile.debian-buster │ │ ├── Dockerfile.debian-stretch │ │ ├── Dockerfile.fedora │ │ ├── Dockerfile.opensuse-leap │ │ ├── Dockerfile.opensuse-tumbleweed │ │ ├── Dockerfile.ubuntu-bionic │ │ ├── Dockerfile.ubuntu-xenial │ │ ├── build.sh │ │ ├── centos-7-presubmit.cfg │ │ ├── centos-7.cfg │ │ ├── centos-8-presubmit.cfg │ │ ├── centos-8.cfg │ │ ├── common.cfg │ │ ├── debian-buster-presubmit.cfg │ │ ├── debian-buster.cfg │ │ ├── debian-stretch-presubmit.cfg │ │ ├── debian-stretch.cfg │ │ ├── fedora-presubmit.cfg │ │ ├── fedora.cfg │ │ ├── opensuse-leap-presubmit.cfg │ │ ├── opensuse-leap.cfg │ │ ├── opensuse-tumbleweed-presubmit.cfg │ │ ├── opensuse-tumbleweed.cfg │ │ ├── ubuntu-bionic-presubmit.cfg │ │ ├── ubuntu-bionic.cfg │ │ ├── ubuntu-xenial-presubmit.cfg │ │ └── ubuntu-xenial.cfg │ ├── macos │ │ ├── bazel-presubmit.cfg │ │ ├── bazel.cfg │ │ ├── build-bazel.sh │ │ ├── build-cmake.sh │ │ ├── build.sh │ │ ├── cmake-super-presubmit.cfg │ │ ├── cmake-super.cfg │ │ └── common.cfg │ └── windows │ │ ├── bazel-presubmit.cfg │ │ ├── bazel.cfg │ │ ├── build-bazel-dependencies.ps1 │ │ ├── build-bazel.ps1 │ │ ├── build-cmake-dependencies.ps1 │ │ ├── build-cmake.ps1 │ │ ├── build.bat │ │ ├── build.ps1 │ │ ├── cmake-presubmit.cfg │ │ ├── cmake.cfg │ │ ├── common.cfg │ │ └── vcpkg-ports │ │ ├── google-cloud-cpp-common │ │ ├── CONTROL │ │ └── portfile.cmake │ │ └── googleapis │ │ ├── CONTROL │ │ ├── portfile.cmake │ │ └── usage ├── retry-command.sh └── test-api │ └── spanner_client.expected.abi.dump.gz ├── cmake ├── CreateBazelConfig.cmake ├── EnableClangTidy.cmake ├── EnableCoverage.cmake ├── EnableCxxExceptions.cmake ├── EnableDoxygen.cmake ├── EnableWerror.cmake ├── GoogleCloudCppCommon.cmake └── SelectMSVCRuntime.cmake ├── doc ├── cutting-a-release.md ├── doxygen-style-guide.md ├── packaging.md ├── setup-cmake-environment.md └── testing-resources.md ├── google └── cloud │ └── spanner │ ├── BUILD │ ├── CMakeLists.txt │ ├── README.md │ ├── backoff_policy.h │ ├── backup.cc │ ├── backup.h │ ├── backup_test.cc │ ├── batch_dml_result.h │ ├── benchmarks │ ├── BUILD │ ├── CMakeLists.txt │ ├── README.md │ ├── benchmarks_config.cc │ ├── benchmarks_config.h │ ├── benchmarks_config_test.cc │ ├── multiple_rows_cpu_benchmark.cc │ ├── single_row_throughput_benchmark.cc │ ├── single_row_throughput_plots.py │ ├── spanner_client_benchmark_programs.bzl │ └── spanner_client_benchmarks.bzl │ ├── bytes.cc │ ├── bytes.h │ ├── bytes_benchmark.cc │ ├── bytes_test.cc │ ├── client.cc │ ├── client.h │ ├── client_options.h │ ├── client_options_test.cc │ ├── client_test.cc │ ├── commit_result.h │ ├── config-version.cmake.in │ ├── config.cmake.in │ ├── config.pc.in │ ├── connection.h │ ├── connection_options.cc │ ├── connection_options.h │ ├── connection_options_test.cc │ ├── create_instance_request_builder.h │ ├── create_instance_request_builder_test.cc │ ├── database.cc │ ├── database.h │ ├── database_admin_client.cc │ ├── database_admin_client.h │ ├── database_admin_client_test.cc │ ├── database_admin_connection.cc │ ├── database_admin_connection.h │ ├── database_admin_connection_test.cc │ ├── database_test.cc │ ├── date.cc │ ├── date.h │ ├── date_test.cc │ ├── doc │ ├── spanner-main.dox │ └── spanner-mocking.dox │ ├── iam_updater.h │ ├── instance.cc │ ├── instance.h │ ├── instance_admin_client.cc │ ├── instance_admin_client.h │ ├── instance_admin_client_test.cc │ ├── instance_admin_connection.cc │ ├── instance_admin_connection.h │ ├── instance_admin_connection_test.cc │ ├── instance_test.cc │ ├── integration_tests │ ├── BUILD │ ├── CMakeLists.txt │ ├── README.md │ ├── backup_integration_test.cc │ ├── client_integration_test.cc │ ├── client_stress_test.cc │ ├── data_types_integration_test.cc │ ├── database_admin_integration_test.cc │ ├── instance_admin_integration_test.cc │ ├── rpc_failure_threshold_integration_test.cc │ ├── session_pool_integration_test.cc │ └── spanner_client_integration_tests.bzl │ ├── internal │ ├── README.md │ ├── api_client_header.cc │ ├── api_client_header.h │ ├── api_client_header_test.cc │ ├── build_info.cc.in │ ├── build_info.h │ ├── build_info_test.cc │ ├── channel.h │ ├── clock.h │ ├── clock_test.cc │ ├── compiler_info.cc │ ├── compiler_info.h │ ├── compiler_info_test.cc │ ├── connection_impl.cc │ ├── connection_impl.h │ ├── connection_impl_test.cc │ ├── database_admin_logging.cc │ ├── database_admin_logging.h │ ├── database_admin_logging_test.cc │ ├── database_admin_metadata.cc │ ├── database_admin_metadata.h │ ├── database_admin_metadata_test.cc │ ├── database_admin_stub.cc │ ├── database_admin_stub.h │ ├── date.cc │ ├── date.h │ ├── date_benchmark.cc │ ├── date_test.cc │ ├── instance_admin_logging.cc │ ├── instance_admin_logging.h │ ├── instance_admin_logging_test.cc │ ├── instance_admin_metadata.cc │ ├── instance_admin_metadata.h │ ├── instance_admin_metadata_test.cc │ ├── instance_admin_stub.cc │ ├── instance_admin_stub.h │ ├── log_wrapper.cc │ ├── log_wrapper.h │ ├── log_wrapper_test.cc │ ├── logging_result_set_reader.cc │ ├── logging_result_set_reader.h │ ├── logging_result_set_reader_test.cc │ ├── logging_spanner_stub.cc │ ├── logging_spanner_stub.h │ ├── logging_spanner_stub_test.cc │ ├── merge_chunk.cc │ ├── merge_chunk.h │ ├── merge_chunk_benchmark.cc │ ├── merge_chunk_test.cc │ ├── metadata_spanner_stub.cc │ ├── metadata_spanner_stub.h │ ├── metadata_spanner_stub_test.cc │ ├── partial_result_set_reader.h │ ├── partial_result_set_resume.cc │ ├── partial_result_set_resume.h │ ├── partial_result_set_resume_test.cc │ ├── partial_result_set_source.cc │ ├── partial_result_set_source.h │ ├── partial_result_set_source_test.cc │ ├── polling_loop.h │ ├── polling_loop_test.cc │ ├── retry_loop.cc │ ├── retry_loop.h │ ├── retry_loop_test.cc │ ├── session.cc │ ├── session.h │ ├── session_pool.cc │ ├── session_pool.h │ ├── session_pool_test.cc │ ├── spanner_stub.cc │ ├── spanner_stub.h │ ├── spanner_stub_test.cc │ ├── status_utils.cc │ ├── status_utils.h │ ├── status_utils_test.cc │ ├── time_format.cc │ ├── time_format.h │ ├── time_format_benchmark.cc │ ├── time_format_test.cc │ ├── time_utils.h │ ├── time_utils_test.cc │ ├── transaction_impl.cc │ ├── transaction_impl.h │ ├── transaction_impl_test.cc │ ├── tuple_utils.h │ └── tuple_utils_test.cc │ ├── keys.cc │ ├── keys.h │ ├── keys_test.cc │ ├── mocks │ ├── mock_database_admin_connection.h │ ├── mock_instance_admin_connection.h │ └── mock_spanner_connection.h │ ├── mutations.cc │ ├── mutations.h │ ├── mutations_test.cc │ ├── partition_options.cc │ ├── partition_options.h │ ├── partition_options_test.cc │ ├── partitioned_dml_result.h │ ├── polling_policy.h │ ├── query_options.h │ ├── query_options_test.cc │ ├── query_partition.cc │ ├── query_partition.h │ ├── query_partition_test.cc │ ├── quickstart │ ├── BUILD │ ├── CMakeLists.txt │ ├── README.md │ ├── WORKSPACE │ └── quickstart.cc │ ├── read_options.h │ ├── read_options_test.cc │ ├── read_partition.cc │ ├── read_partition.h │ ├── read_partition_test.cc │ ├── results.cc │ ├── results.h │ ├── results_test.cc │ ├── retry_policy.h │ ├── retry_policy_test.cc │ ├── row.cc │ ├── row.h │ ├── row_benchmark.cc │ ├── row_test.cc │ ├── samples │ ├── BUILD │ ├── CMakeLists.txt │ ├── README.md │ ├── mock_execute_query.cc │ ├── samples.cc │ ├── spanner_client_integration_samples.bzl │ └── spanner_client_unit_samples.bzl │ ├── session_pool_options.h │ ├── session_pool_options_test.cc │ ├── spanner_client.bzl │ ├── spanner_client_benchmarks.bzl │ ├── spanner_client_mocks.bzl │ ├── spanner_client_testing.bzl │ ├── spanner_client_unit_tests.bzl │ ├── spanner_version_test.cc │ ├── sql_statement.cc │ ├── sql_statement.h │ ├── sql_statement_test.cc │ ├── testing │ ├── cleanup_stale_instances.cc │ ├── cleanup_stale_instances.h │ ├── compiler_supports_regexp.h │ ├── database_integration_test.cc │ ├── database_integration_test.h │ ├── fake_clock.h │ ├── matchers.h │ ├── mock_database_admin_stub.h │ ├── mock_instance_admin_stub.h │ ├── mock_partial_result_set_reader.h │ ├── mock_spanner_stub.h │ ├── pick_instance_config.cc │ ├── pick_instance_config.h │ ├── pick_random_instance.cc │ ├── pick_random_instance.h │ ├── policies.h │ ├── random_backup_name.cc │ ├── random_backup_name.h │ ├── random_database_name.cc │ ├── random_database_name.h │ ├── random_instance_name.cc │ ├── random_instance_name.h │ ├── validate_metadata.cc │ └── validate_metadata.h │ ├── timestamp.cc │ ├── timestamp.h │ ├── timestamp_test.cc │ ├── tracing_options.h │ ├── transaction.cc │ ├── transaction.h │ ├── transaction_test.cc │ ├── update_instance_request_builder.h │ ├── update_instance_request_builder_test.cc │ ├── value.cc │ ├── value.h │ ├── value_test.cc │ ├── version.cc │ ├── version.h │ ├── version_info.h │ └── version_info.h.in └── super ├── CMakeLists.txt ├── ExternalProjectHelper.cmake └── external ├── benchmark.cmake ├── c-ares.cmake ├── google-cloud-cpp-common.cmake ├── googleapis.cmake ├── googletest.cmake ├── grpc.cmake ├── protobuf.cmake ├── ssl.cmake └── zlib.cmake /.bazelci/presubmit.yml: -------------------------------------------------------------------------------- 1 | --- 2 | tasks: 3 | ubuntu1804: 4 | platform: ubuntu1804 5 | build_targets: 6 | - "//google/cloud/spanner/..." 7 | test_flags: 8 | - "--test_tag_filters=-integration-tests" 9 | test_targets: 10 | - "//google/cloud/spanner/..." 11 | -------------------------------------------------------------------------------- /.bazelignore: -------------------------------------------------------------------------------- 1 | ci/ 2 | cmake-out/ 3 | cmake-build-*/ 4 | google/cloud/spanner/quickstart/ 5 | -------------------------------------------------------------------------------- /.clang-format: -------------------------------------------------------------------------------- 1 | # Use the Google style in this project. 2 | BasedOnStyle: Google 3 | 4 | # Some folks prefer to write "int& foo" while others prefer "int &foo". The 5 | # Google Style Guide only asks for consistency within a project, we chose 6 | # "int& foo" for this project: 7 | DerivePointerAlignment: false 8 | PointerAlignment: Left 9 | 10 | IncludeBlocks: Merge 11 | IncludeCategories: 12 | # Matches common headers first, but sorts them after project includes 13 | - Regex: '^\"google/cloud/(internal/|grpc_utils/|testing_util/|[^/]+\.h)' 14 | Priority: 1500 15 | - Regex: '^\"google/cloud/' # project includes should sort first 16 | Priority: 500 17 | - Regex: '^\"' 18 | Priority: 1000 19 | - Regex: '^' 26 | Priority: 5000 27 | 28 | # Format raw string literals with a `pb` or `proto` tag as proto. 29 | RawStringFormats: 30 | - Language: TextProto 31 | Delimiters: 32 | - 'pb' 33 | - 'proto' 34 | BasedOnStyle: Google 35 | 36 | CommentPragmas: '(@copydoc)' 37 | -------------------------------------------------------------------------------- /.cmake-format.py: -------------------------------------------------------------------------------- 1 | # Copyright 2018 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 | # http://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 | tab_size = 4 16 | separate_ctrl_name_with_space = True 17 | enable_sort = True 18 | autosort = True 19 | 20 | additional_commands = { 21 | "externalproject_add": { 22 | "flags": [ 23 | ], 24 | "kwargs": { 25 | "BUILD_COMMAND": "+", 26 | "BUILD_BYPRODUCTS": "+", 27 | "CMAKE_ARGS": "+", 28 | "COMMAND": "+", 29 | "CONFIGURE_COMMAND": "+", 30 | "DEPENDS": "+", 31 | "DOWNLOAD_COMMAND": "+", 32 | "EXCLUDE_FROM_ALL": 1, 33 | "INSTALL_COMMAND": "+", 34 | "INSTALL_DIR": 1, 35 | "LIST_SEPARATOR": 1, 36 | "TEST_COMMAND": "+", 37 | "LOG_BUILD": 1, 38 | "LOG_CONFIGURE": 1, 39 | "LOG_DOWNLOAD": 1, 40 | "LOG_INSTALL": 1, 41 | "PREFIX": 1, 42 | "URL": 1, 43 | "URL_HASH": 1, 44 | "BUILD_ALWAYS": 1, 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /.codecov.yml: -------------------------------------------------------------------------------- 1 | # Disable commit statuses 2 | coverage: 3 | range: 90..100 4 | 5 | ignore: 6 | # Ignore code generated by protobuf, we do not need to test that. 7 | - "*.pb.cc" 8 | - "*.pb.h" 9 | # Also ignore the unit tests. 10 | - "**/*_test.cc$" 11 | -------------------------------------------------------------------------------- /.dockerignore: -------------------------------------------------------------------------------- 1 | # We do not need the git repository in docker images. 2 | .git/ 3 | 4 | # We do not need the typical build directories in docker images. 5 | .idea/ 6 | .build/ 7 | _build/ 8 | build-output/ 9 | cmake-build-*/ 10 | cmake-out/ 11 | 12 | # Skip these directories, the files here are not needed to build any of 13 | # the Docker images. Furthermore, when creating new Dockerfiles the files 14 | # here change a lot, but do not change the image, so they trigger image rebuids 15 | # without any benefit. 16 | ci/kokoro/ 17 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve the Cloud Spanner C++ client library 4 | title: '' 5 | labels: 'triage me, type: bug' 6 | assignees: '' 7 | 8 | --- 9 | 10 | Answering these questions before submitting your bug report will help us give you a quicker answer. Thank you! 11 | 12 | If one or more of these questions are not applicable, feel free to remove them. 13 | 14 | ### Does this issue affect the `google-cloud-cpp-spanner` project? 15 | 16 | If the problem is with the service exposed by the `google-cloud-cpp-spanner` APIs instead of the client libraries you may consider opening a support request instead. The `google-cloud-cpp-spanner` developers cannot help you troubleshoot problems with the service itself. 17 | 18 | ### What version of `google-cloud-cpp-spanner` are you using? 19 | 20 | Please include the output from `git rev-parse HEAD` if you are compiling from source, or the version number from the applicable `*/version.h` file. 21 | 22 | ### What compiler and version are you using? 23 | 24 | Please include the output of `g++ -v` or the equivalent command-line flag. 25 | 26 | ### What operating system and version are you using? 27 | 28 | If you are using a Linux distribution include the name and version of the distribution too. 29 | 30 | ### What were you trying to do? 31 | 32 | If possible, produce a recipe for reproducing the problem. 33 | 34 | ### What did you expect to see? 35 | 36 | What was the behavior you expected from the library? 37 | 38 | ### What did you see instead? 39 | 40 | What was the behavior you actually observed? 41 | 42 | ### Anything else you would like us to know? 43 | 44 | Include here information about your environment that is not captured above, or any other information you think might be relevant. 45 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for the Cloud Spanner C++ client library 4 | title: '' 5 | labels: 'type: feature request' 6 | assignees: '' 7 | 8 | --- 9 | 10 | Answering these questions before submitting your feature request will help us address it more quickly. Thank you! 11 | 12 | If one or more of these questions are not applicable, feel free to remove them. 13 | 14 | ### What issue will the feature address? 15 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 16 | 17 | ### Do you have a preferred solution? 18 | A clear and concise description of what you want to happen. 19 | 20 | ### Have you considered any alternative approaches? 21 | A clear and concise description of any alternative solutions or features you've considered. 22 | 23 | ### Additional context? 24 | Add any other context or screenshots about the feature request here. 25 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Common build output directory names 2 | .build/ 3 | _build/ 4 | build-output/ 5 | cmake-out/ 6 | 7 | # Common bazel output directories 8 | bazel-* 9 | !bazel-*.cfg 10 | 11 | # File used by clang-based refactoring tools 12 | compile_commands.json 13 | 14 | # Backup files for Emacs 15 | *~ 16 | 17 | # Ignore IDEA / IntelliJ files 18 | .idea/ 19 | cmake-build-*/ 20 | 21 | # Ignore Visual Studio code directories. 22 | .vsbuild/ 23 | .vscode/ 24 | 25 | # This is a staging directory used to upload the documents to gihub.io 26 | github-io-staging/ 27 | 28 | google/cloud/storage/testbench/__pycache__/ 29 | google/cloud/storage/testbench/*.pyc 30 | 31 | # Ignore Visual Studio Code files. 32 | .vscode/ 33 | 34 | callgrind.out* 35 | -------------------------------------------------------------------------------- /BUILD: -------------------------------------------------------------------------------- 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 | # http://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 | package(default_visibility = ["//visibility:public"]) 16 | 17 | licenses(["notice"]) # Apache 2.0 18 | 19 | exports_files([ 20 | "LICENSE", 21 | ]) 22 | 23 | cc_library( 24 | name = "spanner_client", 25 | deps = [ 26 | "//google/cloud/spanner:spanner_client", 27 | ], 28 | ) 29 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Code of Conduct 2 | 3 | As contributors and maintainers of this project, and in the interest of fostering an open and welcoming community, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities. 4 | 5 | We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, religion, or nationality. 6 | 7 | Examples of unacceptable behavior by participants include: 8 | 9 | * The use of sexualized language or imagery 10 | * Personal attacks 11 | * Trolling or insulting/derogatory comments 12 | * Public or private harassment 13 | * Publishing other's private information, such as physical or electronic addresses, without explicit permission 14 | * Other unethical or unprofessional conduct 15 | 16 | Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. By adopting this Code of Conduct, project maintainers commit themselves to fairly and consistently applying these principles to every aspect of managing this project. Project maintainers who do not follow or enforce the Code of Conduct may be permanently removed from the project team. 17 | 18 | This code of conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. 19 | 20 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers. 21 | 22 | This Code of Conduct is adapted from the [Contributor Covenant](https://www.contributor-covenant.org), version 1.2.0, available at https://www.contributor-covenant.org/version/1/2/0/code-of-conduct.html 23 | 24 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # This repo has moved 2 | 3 | It now lives in the https://github.com/googleapis/google-cloud-cpp monorepo. 4 | -------------------------------------------------------------------------------- /WORKSPACE: -------------------------------------------------------------------------------- 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 | # http://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 | workspace(name = "com_github_googleapis_google_cloud_cpp_spanner") 16 | 17 | load("//bazel:google_cloud_cpp_spanner_deps.bzl", "google_cloud_cpp_spanner_deps") 18 | 19 | google_cloud_cpp_spanner_deps() 20 | 21 | # Configure @com_google_googleapis to only compile C++ and gRPC libraries. 22 | load("@com_google_googleapis//:repository_rules.bzl", "switched_rules_by_language") 23 | 24 | switched_rules_by_language( 25 | name = "com_google_googleapis_imports", 26 | cc = True, # C++ support is only "Partially implemented", roll our own. 27 | grpc = True, 28 | ) 29 | 30 | # Have to manually call the corresponding function for google-cloud-cpp and 31 | # gRPC: 32 | # https://github.com/bazelbuild/bazel/issues/1550 33 | 34 | load("@com_github_googleapis_google_cloud_cpp_common//bazel:google_cloud_cpp_common_deps.bzl", "google_cloud_cpp_common_deps") 35 | 36 | google_cloud_cpp_common_deps() 37 | 38 | load("@com_github_grpc_grpc//bazel:grpc_deps.bzl", "grpc_deps") 39 | 40 | grpc_deps() 41 | 42 | load("@com_github_grpc_grpc//bazel:grpc_extra_deps.bzl", "grpc_extra_deps") 43 | 44 | grpc_extra_deps() 45 | -------------------------------------------------------------------------------- /bazel/BUILD: -------------------------------------------------------------------------------- 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 | # http://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 | licenses(["notice"]) # Apache v2 16 | 17 | package(default_visibility = ["//:__subpackages__"]) 18 | 19 | exports_files([ 20 | "compiler_id.sh", 21 | "compiler_version.sh", 22 | ]) 23 | -------------------------------------------------------------------------------- /bazel/googleapis.BUILD: -------------------------------------------------------------------------------- 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 | # http://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 | package(default_visibility = ["//visibility:public"]) 16 | 17 | licenses(["notice"]) # Apache 2.0 18 | 19 | load("@com_github_grpc_grpc//bazel:cc_grpc_library.bzl", "cc_grpc_library") 20 | 21 | # This rule is needed by `google-cloud-cpp-common`. It lets us include headers 22 | # from googleapis targets using angle brackets like system includes. 23 | cc_library( 24 | name = "googleapis_system_includes", 25 | includes = [ 26 | ".", 27 | ], 28 | ) 29 | 30 | # TODO(googleapis/google-cloud-cpp#3838): Delete this rule once it's no longer 31 | # used after the next release of -common. 32 | cc_library( 33 | name = "grpc_utils_protos", 34 | deps = [ 35 | ":googleapis_system_includes", 36 | "@com_github_grpc_grpc//:grpc++", 37 | "//google/rpc:status_cc_proto", 38 | ], 39 | ) 40 | -------------------------------------------------------------------------------- /ci/check-markdown.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Copyright 2020 Google LLC 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | set -eu 17 | 18 | if [[ "${CHECK_MARKDOWN}" != "yes" ]]; then 19 | echo "Skipping the generated markdown check as it is disabled for this build." 20 | exit 0 21 | fi 22 | 23 | declare -A -r GENERATOR_MAP=( 24 | ["ci/generate-markdown/generate-readme.sh"]="README.md" 25 | ["ci/generate-markdown/generate-spanner-readme.sh"]="google/cloud/spanner/README.md" 26 | ["ci/generate-markdown/generate-packaging.sh"]="doc/packaging.md" 27 | ) 28 | 29 | exit_status=0 30 | for k in "${!GENERATOR_MAP[@]}"; do 31 | generator="${k}" 32 | file="${GENERATOR_MAP[${k}]}" 33 | out=$(diff <("${generator}") "${file}" || true) 34 | if [[ -n "${out}" ]]; then 35 | echo "Did you forget to run ${generator}?" 36 | echo "Unexpected diff found in ${file}:" 37 | echo "$out" 38 | exit_status=1 39 | fi 40 | done 41 | 42 | exit ${exit_status} 43 | -------------------------------------------------------------------------------- /ci/define-dump-log.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Copyright 2019 Google LLC 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | ################################################ 17 | # Dump a log file to the console without going over CI system limits. 18 | # Globals: 19 | # None 20 | # Arguments: 21 | # logfile: the name of the logfile to print out. 22 | # Returns: 23 | # None 24 | ################################################ 25 | dump_log() { 26 | local -r logfile=$1 27 | shift 28 | local -r base="$(basename "${logfile}")" 29 | 30 | if [ ! -r "${logfile}" ]; then 31 | return 32 | fi 33 | 34 | echo "================ [begin ${base}] ================" 35 | # Travis has a limit of ~10,000 lines, if the file is around 1,000 just print 36 | # the full file. 37 | if [ "$(wc -l "${logfile}" | awk '{print $1}')" -lt 200 ]; then 38 | cat "${logfile}" 39 | else 40 | head -100 "${logfile}" 41 | echo "==== [snip] [snip] [${base}] [snip] [snip] ====" 42 | tail -100 "${logfile}" 43 | fi 44 | echo "================ [end ${base}] ================" 45 | } 46 | -------------------------------------------------------------------------------- /ci/etc/install-config.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Copyright 2019 Google LLC 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | set -eu 17 | 18 | GOOGLE_CLOUD_CPP_BAZEL_VERSION="2.0.0" 19 | readonly GOOGLE_CLOUD_CPP_BAZEL_VERSION 20 | 21 | GOOGLE_CLOUD_CPP_CLOUD_SDK_VERSION="266.0.0" 22 | readonly GOOGLE_CLOUD_CPP_CLOUD_SDK_VERSION 23 | 24 | GOOGLE_CLOUD_CPP_SDK_SHA256="e2b2cd5e49e1dc73ffe1d57ba2bcc1b76620ae9549d2aa27ece05d819a8f4bbc" 25 | readonly GOOGLE_CLOUD_CPP_SDK_SHA256 26 | -------------------------------------------------------------------------------- /ci/etc/kokoro/install/version-config.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Copyright 2020 Google LLC 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | readonly GOOGLE_CLOUD_CPP_COMMON_VERSION=0.25.0 17 | -------------------------------------------------------------------------------- /ci/etc/publish-refdocs.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Copyright 2019 Google LLC 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | set -eu 17 | 18 | # This script is meant to source from ci/kokoro/docker/publish_refdocs.sh. 19 | 20 | upload_docs "google-cloud-spanner" "${BUILD_OUTPUT}/google/cloud/spanner/html" \ 21 | "cloud.tag" "${BRANCH}" "${CREDENTIALS_FILE}" "${STAGING_BUCKET}" 22 | -------------------------------------------------------------------------------- /ci/etc/repo-config.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Copyright 2019 Google LLC 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | set -eu 17 | 18 | # This script is sourced from several other scripts in `ci/` to configure the 19 | # repository name (and short name). It makes those scripts portable across 20 | # `google-cloud-cpp*` repositories. 21 | 22 | GOOGLE_CLOUD_CPP_REPOSITORY="google-cloud-cpp-spanner" 23 | readonly GOOGLE_CLOUD_CPP_REPOSITORY 24 | 25 | GOOGLE_CLOUD_CPP_REPOSITORY_SHORT="spanner" 26 | readonly GOOGLE_CLOUD_CPP_REPOSITORY_SHORT 27 | -------------------------------------------------------------------------------- /ci/generate-markdown/README.md: -------------------------------------------------------------------------------- 1 | # Helper tools to generate certain markdown files. 2 | 3 | ## HOWTO: Generate the doc/packaging.md file. 4 | 5 | This file is generated from the Dockerfiles in `ci/kokoro/install` just run: 6 | 7 | ```bash 8 | cd google-cloud-cpp-spanner 9 | ./ci/test-markdown/generate-packaging.sh > doc/packaging.md 10 | ``` 11 | 12 | and then create a pull request to merge your changes. 13 | 14 | ## HOWTO: Generate the README.md file. 15 | 16 | To generate the README.md file just run: 17 | 18 | ```bash 19 | cd google-cloud-cpp-spanner 20 | ./ci/test-markdown/generate-readme.sh > README.md 21 | ``` 22 | 23 | ## HOWTO: Manually verify the instructions. 24 | 25 | If you need to change the instructions then change the relevant Dockerfile and 26 | execute (for example): 27 | 28 | ```bash 29 | export NCPU=$(nproc) 30 | cd google-cloud-cpp-spanner 31 | ./ci/kokoro/install/build.sh fedora 32 | ``` 33 | 34 | Note that any change to the project contents, including changes to the README, 35 | doc/packaging.md, or any other documentation, starts the docker build almost 36 | from the beginning. This is working as intended, we want these scripts to 37 | simulate the experience of a user downloading the project on their workstation. 38 | -------------------------------------------------------------------------------- /ci/generate-markdown/extract-install.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Copyright 2019 Google LLC 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | set -eu 17 | 18 | readonly BINDIR=$(dirname "$0") 19 | 20 | sed -e '0,/^.*\[START INSTALL.md\].*$/d' \ 21 | -e '/^.*\[END INSTALL.md\].*$/,$d' "$@" | \ 22 | "${BINDIR}/dockerfile2markdown.sh" 23 | -------------------------------------------------------------------------------- /ci/generate-markdown/generate-readme.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # 3 | # Copyright 2019 Google LLC 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | set -eu 18 | 19 | cat <<_EOF_ 20 | # This repo has moved 21 | 22 | It now lives in the https://github.com/googleapis/google-cloud-cpp monorepo. 23 | _EOF_ 24 | -------------------------------------------------------------------------------- /ci/install-bazel.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Copyright 2019 Google LLC 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | set -eu 17 | 18 | readonly PLATFORM=$(printf "%s-%s" "$(uname -s)" "$(uname -m)" \ 19 | | tr '[:upper:]' '[:lower:]') 20 | 21 | readonly BAZEL_VERSION="2.0.0" 22 | readonly GITHUB_DL="https://github.com/bazelbuild/bazel/releases/download" 23 | readonly SCRIPT_NAME="bazel-${BAZEL_VERSION}-installer-${PLATFORM}.sh" 24 | wget -q "${GITHUB_DL}/${BAZEL_VERSION}/${SCRIPT_NAME}" 25 | wget -q "${GITHUB_DL}/${BAZEL_VERSION}/${SCRIPT_NAME}.sha256" 26 | 27 | # We want to protect against accidents (i.e., we don't want to download and 28 | # execute a 404 page), not malice, so downloading the checksum and the file 29 | # from the same source is Okay. 30 | sha256sum --check "${SCRIPT_NAME}.sha256" 31 | 32 | chmod +x "${SCRIPT_NAME}" 33 | if [[ "${USER:-}" = "root" ]] || [[ "${USER+x}" = "" ]]; then 34 | "./${SCRIPT_NAME}" 35 | else 36 | "./${SCRIPT_NAME}" --user 37 | fi 38 | 39 | rm -f "${SCRIPT_NAME}" "${SCRIPT_NAME}.sha256" 40 | -------------------------------------------------------------------------------- /ci/kokoro/Dockerfile.centos: -------------------------------------------------------------------------------- 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 | # http://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 | ARG DISTRO_VERSION=7 16 | FROM centos:${DISTRO_VERSION} 17 | 18 | # We need to install cmake3, which on CentOS-7 requires an extra source 19 | RUN rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm 20 | RUN yum install -y centos-release-scl 21 | RUN yum-config-manager --enable rhel-server-rhscl-7-rpms 22 | 23 | RUN yum makecache && \ 24 | yum install -y automake ccache cmake3 curl-devel gcc gcc-c++ git libtool \ 25 | make openssl-devel pkgconfig tar wget which zlib-devel 26 | RUN ln -sf /usr/bin/cmake3 /usr/bin/cmake && ln -sf /usr/bin/ctest3 /usr/bin/ctest 27 | -------------------------------------------------------------------------------- /ci/kokoro/Dockerfile.ubuntu: -------------------------------------------------------------------------------- 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 | # http://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 | ARG DISTRO_VERSION=18.04 16 | FROM ubuntu:${DISTRO_VERSION} 17 | 18 | RUN apt-get update && \ 19 | apt-get --no-install-recommends install -y \ 20 | apt-transport-https \ 21 | apt-utils \ 22 | automake \ 23 | build-essential \ 24 | ca-certificates \ 25 | ccache \ 26 | clang \ 27 | cmake \ 28 | curl \ 29 | doxygen \ 30 | gawk \ 31 | git \ 32 | gcc \ 33 | g++ \ 34 | libssl-dev \ 35 | libtool \ 36 | lsb-release \ 37 | make \ 38 | ninja-build \ 39 | pkg-config \ 40 | python3 \ 41 | python3-pip \ 42 | shellcheck \ 43 | tar \ 44 | unzip \ 45 | wget \ 46 | zlib1g-dev 47 | 48 | WORKDIR /var/tmp/ci 49 | COPY install-bazel.sh /var/tmp/ci 50 | RUN /var/tmp/ci/install-bazel.sh 51 | -------------------------------------------------------------------------------- /ci/kokoro/Dockerfile.ubuntu-xenial: -------------------------------------------------------------------------------- 1 | # Copyright 2020 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 | # http://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 | ARG DISTRO_VERSION=16.04 16 | FROM ubuntu:${DISTRO_VERSION} 17 | 18 | RUN apt-get update && \ 19 | apt-get --no-install-recommends install -y \ 20 | apt-transport-https \ 21 | apt-utils \ 22 | automake \ 23 | build-essential \ 24 | ca-certificates \ 25 | ccache \ 26 | clang \ 27 | cmake \ 28 | curl \ 29 | doxygen \ 30 | gawk \ 31 | git \ 32 | gcc \ 33 | g++ \ 34 | libssl-dev \ 35 | libtool \ 36 | lsb-release \ 37 | make \ 38 | ninja-build \ 39 | pkg-config \ 40 | python3 \ 41 | python3-pip \ 42 | shellcheck \ 43 | tar \ 44 | unzip \ 45 | wget \ 46 | zlib1g-dev 47 | 48 | WORKDIR /var/tmp/ci 49 | COPY install-bazel.sh /var/tmp/ci 50 | RUN /var/tmp/ci/install-bazel.sh 51 | -------------------------------------------------------------------------------- /ci/kokoro/docker/README.md: -------------------------------------------------------------------------------- 1 | # Bazel Continuous Integration Support Files. 2 | 3 | This directory contains the CI support files to test the Google Cloud Spanner 4 | C++ client library when built using Bazel. 5 | -------------------------------------------------------------------------------- /ci/kokoro/docker/asan-presubmit.cfg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googleapis/google-cloud-cpp-spanner/459937ff3b9d4876c20c0561b13922c7bb36d445/ci/kokoro/docker/asan-presubmit.cfg -------------------------------------------------------------------------------- /ci/kokoro/docker/asan.cfg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googleapis/google-cloud-cpp-spanner/459937ff3b9d4876c20c0561b13922c7bb36d445/ci/kokoro/docker/asan.cfg -------------------------------------------------------------------------------- /ci/kokoro/docker/bazel-dependency-presubmit.cfg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googleapis/google-cloud-cpp-spanner/459937ff3b9d4876c20c0561b13922c7bb36d445/ci/kokoro/docker/bazel-dependency-presubmit.cfg -------------------------------------------------------------------------------- /ci/kokoro/docker/bazel-dependency.cfg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googleapis/google-cloud-cpp-spanner/459937ff3b9d4876c20c0561b13922c7bb36d445/ci/kokoro/docker/bazel-dependency.cfg -------------------------------------------------------------------------------- /ci/kokoro/docker/check-api-presubmit.cfg: -------------------------------------------------------------------------------- 1 | # Format: //devtools/kokoro/config/proto/build.proto 2 | # Copyright 2019 Google LLC 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | action { 17 | define_artifacts { 18 | regex: "**/src_compat_report.html" 19 | strip_prefix: "github/google-cloud-cpp-common/cmake-out/ubuntu-install-18.04-gcc-Debug-shared/compat_reports" 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /ci/kokoro/docker/check-api.cfg: -------------------------------------------------------------------------------- 1 | # Format: //devtools/kokoro/config/proto/build.proto 2 | # Copyright 2019 Google LLC 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | action { 17 | define_artifacts { 18 | regex: "**/src_compat_report.html" 19 | strip_prefix: "github/google-cloud-cpp-common/cmake-out/ubuntu-install-18.04-gcc-Debug-shared/compat_reports" 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /ci/kokoro/docker/clang-3.8-presubmit.cfg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googleapis/google-cloud-cpp-spanner/459937ff3b9d4876c20c0561b13922c7bb36d445/ci/kokoro/docker/clang-3.8-presubmit.cfg -------------------------------------------------------------------------------- /ci/kokoro/docker/clang-3.8.cfg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googleapis/google-cloud-cpp-spanner/459937ff3b9d4876c20c0561b13922c7bb36d445/ci/kokoro/docker/clang-3.8.cfg -------------------------------------------------------------------------------- /ci/kokoro/docker/clang-tidy-presubmit.cfg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googleapis/google-cloud-cpp-spanner/459937ff3b9d4876c20c0561b13922c7bb36d445/ci/kokoro/docker/clang-tidy-presubmit.cfg -------------------------------------------------------------------------------- /ci/kokoro/docker/clang-tidy.cfg: -------------------------------------------------------------------------------- 1 | # Format: //devtools/kokoro/config/proto/build.proto 2 | # Copyright 2019 Google LLC 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | gfile_resources: "/bigstore/cloud-cpp-integration-secrets/google-cloud-cpp-spanner/github-io-upload-token" 17 | -------------------------------------------------------------------------------- /ci/kokoro/docker/cmake-presubmit.cfg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googleapis/google-cloud-cpp-spanner/459937ff3b9d4876c20c0561b13922c7bb36d445/ci/kokoro/docker/cmake-presubmit.cfg -------------------------------------------------------------------------------- /ci/kokoro/docker/cmake-super-presubmit.cfg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googleapis/google-cloud-cpp-spanner/459937ff3b9d4876c20c0561b13922c7bb36d445/ci/kokoro/docker/cmake-super-presubmit.cfg -------------------------------------------------------------------------------- /ci/kokoro/docker/cmake-super.cfg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googleapis/google-cloud-cpp-spanner/459937ff3b9d4876c20c0561b13922c7bb36d445/ci/kokoro/docker/cmake-super.cfg -------------------------------------------------------------------------------- /ci/kokoro/docker/cmake.cfg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googleapis/google-cloud-cpp-spanner/459937ff3b9d4876c20c0561b13922c7bb36d445/ci/kokoro/docker/cmake.cfg -------------------------------------------------------------------------------- /ci/kokoro/docker/common.cfg: -------------------------------------------------------------------------------- 1 | # Format: //devtools/kokoro/config/proto/build.proto 2 | # Copyright 2019 Google LLC 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | build_file: "google-cloud-cpp-spanner/ci/kokoro/docker/build.sh" 17 | timeout_mins: 120 18 | 19 | gfile_resources: "/bigstore/cloud-cpp-integration-secrets/gcr-service-account.json" 20 | gfile_resources: "/bigstore/cloud-cpp-integration-secrets/gcr-configuration.sh" 21 | gfile_resources: "/bigstore/cloud-cpp-integration-secrets/spanner-integration-tests-config.sh" 22 | gfile_resources: "/bigstore/cloud-cpp-integration-secrets/spanner-credentials.json" 23 | gfile_resources: "/bigstore/cloud-cpp-integration-secrets/build-results-service-account.json" 24 | -------------------------------------------------------------------------------- /ci/kokoro/docker/coverage-presubmit.cfg: -------------------------------------------------------------------------------- 1 | # Format: //devtools/kokoro/config/proto/build.proto 2 | # Copyright 2019 Google LLC 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | gfile_resources: "/bigstore/cloud-cpp-integration-secrets/google-cloud-cpp-spanner/codecov-io-upload-token" 17 | gfile_resources: "/bigstore/cloud-cpp-integration-secrets/spanner-integration-tests-config.sh" 18 | gfile_resources: "/bigstore/cloud-cpp-integration-secrets/spanner-credentials.json" 19 | -------------------------------------------------------------------------------- /ci/kokoro/docker/coverage.cfg: -------------------------------------------------------------------------------- 1 | # Format: //devtools/kokoro/config/proto/build.proto 2 | # Copyright 2019 Google LLC 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | gfile_resources: "/bigstore/cloud-cpp-integration-secrets/google-cloud-cpp-spanner/codecov-io-upload-token" 17 | -------------------------------------------------------------------------------- /ci/kokoro/docker/cxx17-presubmit.cfg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googleapis/google-cloud-cpp-spanner/459937ff3b9d4876c20c0561b13922c7bb36d445/ci/kokoro/docker/cxx17-presubmit.cfg -------------------------------------------------------------------------------- /ci/kokoro/docker/cxx17.cfg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googleapis/google-cloud-cpp-spanner/459937ff3b9d4876c20c0561b13922c7bb36d445/ci/kokoro/docker/cxx17.cfg -------------------------------------------------------------------------------- /ci/kokoro/docker/dump-reports.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Copyright 2019 Google LLC 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | set -eu 17 | 18 | if [[ -z "${PROJECT_ROOT+x}" ]]; then 19 | readonly PROJECT_ROOT="$(cd "$(dirname "$0")/../../.."; pwd)" 20 | fi 21 | source "${PROJECT_ROOT}/ci/kokoro/define-docker-variables.sh" 22 | 23 | # If w3m is not installed there is nothing to do. 24 | if ! type w3m >/dev/null 2>&1; then 25 | exit 0 26 | fi 27 | 28 | function dump_report() { 29 | local filename="$1" 30 | 31 | echo 32 | echo "================ ${filename} ================" 33 | w3m -dump "${filename}" 34 | } 35 | 36 | export -f dump_report 37 | 38 | # Find any analysis reports, currently ABI checks and Clang static analysis are 39 | # the two things that produce them. Note that the Clang static analysis reports 40 | # are copied into the scan-cmake-out directory by the build-docker.sh script. 41 | 42 | find "${BUILD_OUTPUT}" -name 'src_compat_report.html' \ 43 | -exec bash -c 'dump_report "$1"' _ {} \; 2>/dev/null || \ 44 | echo "No ABI compatibility reports found." 45 | 46 | find scan-cmake-out/ -name '*.html' \ 47 | -exec bash -c 'dump_report "$1"' _ {} \; 2>/dev/null || \ 48 | echo "No static analysis reports found." 49 | -------------------------------------------------------------------------------- /ci/kokoro/docker/gcc-4.8-presubmit.cfg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googleapis/google-cloud-cpp-spanner/459937ff3b9d4876c20c0561b13922c7bb36d445/ci/kokoro/docker/gcc-4.8-presubmit.cfg -------------------------------------------------------------------------------- /ci/kokoro/docker/gcc-4.8.cfg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googleapis/google-cloud-cpp-spanner/459937ff3b9d4876c20c0561b13922c7bb36d445/ci/kokoro/docker/gcc-4.8.cfg -------------------------------------------------------------------------------- /ci/kokoro/docker/integration-presubmit.cfg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googleapis/google-cloud-cpp-spanner/459937ff3b9d4876c20c0561b13922c7bb36d445/ci/kokoro/docker/integration-presubmit.cfg -------------------------------------------------------------------------------- /ci/kokoro/docker/integration.cfg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googleapis/google-cloud-cpp-spanner/459937ff3b9d4876c20c0561b13922c7bb36d445/ci/kokoro/docker/integration.cfg -------------------------------------------------------------------------------- /ci/kokoro/docker/msan-presubmit.cfg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googleapis/google-cloud-cpp-spanner/459937ff3b9d4876c20c0561b13922c7bb36d445/ci/kokoro/docker/msan-presubmit.cfg -------------------------------------------------------------------------------- /ci/kokoro/docker/msan.cfg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googleapis/google-cloud-cpp-spanner/459937ff3b9d4876c20c0561b13922c7bb36d445/ci/kokoro/docker/msan.cfg -------------------------------------------------------------------------------- /ci/kokoro/docker/ninja-presubmit.cfg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googleapis/google-cloud-cpp-spanner/459937ff3b9d4876c20c0561b13922c7bb36d445/ci/kokoro/docker/ninja-presubmit.cfg -------------------------------------------------------------------------------- /ci/kokoro/docker/ninja.cfg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googleapis/google-cloud-cpp-spanner/459937ff3b9d4876c20c0561b13922c7bb36d445/ci/kokoro/docker/ninja.cfg -------------------------------------------------------------------------------- /ci/kokoro/docker/noex-presubmit.cfg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googleapis/google-cloud-cpp-spanner/459937ff3b9d4876c20c0561b13922c7bb36d445/ci/kokoro/docker/noex-presubmit.cfg -------------------------------------------------------------------------------- /ci/kokoro/docker/noex.cfg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googleapis/google-cloud-cpp-spanner/459937ff3b9d4876c20c0561b13922c7bb36d445/ci/kokoro/docker/noex.cfg -------------------------------------------------------------------------------- /ci/kokoro/docker/publish-refdocs.cfg: -------------------------------------------------------------------------------- 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 | # http://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 | # Format: //devtools/kokoro/config/proto/build.proto 16 | 17 | before_action { 18 | fetch_keystore { 19 | keystore_resource { 20 | keystore_config_id: 73713 21 | keyname: "docuploader_service_account" 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /ci/kokoro/docker/tsan-presubmit.cfg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googleapis/google-cloud-cpp-spanner/459937ff3b9d4876c20c0561b13922c7bb36d445/ci/kokoro/docker/tsan-presubmit.cfg -------------------------------------------------------------------------------- /ci/kokoro/docker/tsan.cfg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googleapis/google-cloud-cpp-spanner/459937ff3b9d4876c20c0561b13922c7bb36d445/ci/kokoro/docker/tsan.cfg -------------------------------------------------------------------------------- /ci/kokoro/docker/ubsan-presubmit.cfg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googleapis/google-cloud-cpp-spanner/459937ff3b9d4876c20c0561b13922c7bb36d445/ci/kokoro/docker/ubsan-presubmit.cfg -------------------------------------------------------------------------------- /ci/kokoro/docker/ubsan.cfg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googleapis/google-cloud-cpp-spanner/459937ff3b9d4876c20c0561b13922c7bb36d445/ci/kokoro/docker/ubsan.cfg -------------------------------------------------------------------------------- /ci/kokoro/dump-logs.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Copyright 2019 Google LLC 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | set -eu 17 | 18 | if [[ -z "${PROJECT_ROOT+x}" ]]; then 19 | readonly PROJECT_ROOT="$(cd "$(dirname "$0")/../.."; pwd)" 20 | fi 21 | source "${PROJECT_ROOT}/ci/kokoro/define-docker-variables.sh" 22 | source "${PROJECT_ROOT}/ci/define-dump-log.sh" 23 | 24 | # Dump the image installation log. 25 | echo 26 | dump_log "cmake-out/install-linux.log" 27 | -------------------------------------------------------------------------------- /ci/kokoro/install/centos-7-presubmit.cfg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googleapis/google-cloud-cpp-spanner/459937ff3b9d4876c20c0561b13922c7bb36d445/ci/kokoro/install/centos-7-presubmit.cfg -------------------------------------------------------------------------------- /ci/kokoro/install/centos-7.cfg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googleapis/google-cloud-cpp-spanner/459937ff3b9d4876c20c0561b13922c7bb36d445/ci/kokoro/install/centos-7.cfg -------------------------------------------------------------------------------- /ci/kokoro/install/centos-8-presubmit.cfg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googleapis/google-cloud-cpp-spanner/459937ff3b9d4876c20c0561b13922c7bb36d445/ci/kokoro/install/centos-8-presubmit.cfg -------------------------------------------------------------------------------- /ci/kokoro/install/centos-8.cfg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googleapis/google-cloud-cpp-spanner/459937ff3b9d4876c20c0561b13922c7bb36d445/ci/kokoro/install/centos-8.cfg -------------------------------------------------------------------------------- /ci/kokoro/install/common.cfg: -------------------------------------------------------------------------------- 1 | # Format: //devtools/kokoro/config/proto/build.proto 2 | # Copyright 2019 Google LLC 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | build_file: "google-cloud-cpp-spanner/ci/kokoro/install/build.sh" 17 | timeout_mins: 120 18 | 19 | gfile_resources: "/bigstore/cloud-cpp-integration-secrets/gcr-service-account.json" 20 | gfile_resources: "/bigstore/cloud-cpp-integration-secrets/gcr-configuration.sh" 21 | gfile_resources: "/bigstore/cloud-cpp-integration-secrets/spanner-integration-tests-config.sh" 22 | gfile_resources: "/bigstore/cloud-cpp-integration-secrets/spanner-credentials.json" 23 | -------------------------------------------------------------------------------- /ci/kokoro/install/debian-buster-presubmit.cfg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googleapis/google-cloud-cpp-spanner/459937ff3b9d4876c20c0561b13922c7bb36d445/ci/kokoro/install/debian-buster-presubmit.cfg -------------------------------------------------------------------------------- /ci/kokoro/install/debian-buster.cfg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googleapis/google-cloud-cpp-spanner/459937ff3b9d4876c20c0561b13922c7bb36d445/ci/kokoro/install/debian-buster.cfg -------------------------------------------------------------------------------- /ci/kokoro/install/debian-stretch-presubmit.cfg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googleapis/google-cloud-cpp-spanner/459937ff3b9d4876c20c0561b13922c7bb36d445/ci/kokoro/install/debian-stretch-presubmit.cfg -------------------------------------------------------------------------------- /ci/kokoro/install/debian-stretch.cfg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googleapis/google-cloud-cpp-spanner/459937ff3b9d4876c20c0561b13922c7bb36d445/ci/kokoro/install/debian-stretch.cfg -------------------------------------------------------------------------------- /ci/kokoro/install/fedora-presubmit.cfg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googleapis/google-cloud-cpp-spanner/459937ff3b9d4876c20c0561b13922c7bb36d445/ci/kokoro/install/fedora-presubmit.cfg -------------------------------------------------------------------------------- /ci/kokoro/install/fedora.cfg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googleapis/google-cloud-cpp-spanner/459937ff3b9d4876c20c0561b13922c7bb36d445/ci/kokoro/install/fedora.cfg -------------------------------------------------------------------------------- /ci/kokoro/install/opensuse-leap-presubmit.cfg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googleapis/google-cloud-cpp-spanner/459937ff3b9d4876c20c0561b13922c7bb36d445/ci/kokoro/install/opensuse-leap-presubmit.cfg -------------------------------------------------------------------------------- /ci/kokoro/install/opensuse-leap.cfg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googleapis/google-cloud-cpp-spanner/459937ff3b9d4876c20c0561b13922c7bb36d445/ci/kokoro/install/opensuse-leap.cfg -------------------------------------------------------------------------------- /ci/kokoro/install/opensuse-tumbleweed-presubmit.cfg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googleapis/google-cloud-cpp-spanner/459937ff3b9d4876c20c0561b13922c7bb36d445/ci/kokoro/install/opensuse-tumbleweed-presubmit.cfg -------------------------------------------------------------------------------- /ci/kokoro/install/opensuse-tumbleweed.cfg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googleapis/google-cloud-cpp-spanner/459937ff3b9d4876c20c0561b13922c7bb36d445/ci/kokoro/install/opensuse-tumbleweed.cfg -------------------------------------------------------------------------------- /ci/kokoro/install/ubuntu-bionic-presubmit.cfg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googleapis/google-cloud-cpp-spanner/459937ff3b9d4876c20c0561b13922c7bb36d445/ci/kokoro/install/ubuntu-bionic-presubmit.cfg -------------------------------------------------------------------------------- /ci/kokoro/install/ubuntu-bionic.cfg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googleapis/google-cloud-cpp-spanner/459937ff3b9d4876c20c0561b13922c7bb36d445/ci/kokoro/install/ubuntu-bionic.cfg -------------------------------------------------------------------------------- /ci/kokoro/install/ubuntu-xenial-presubmit.cfg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googleapis/google-cloud-cpp-spanner/459937ff3b9d4876c20c0561b13922c7bb36d445/ci/kokoro/install/ubuntu-xenial-presubmit.cfg -------------------------------------------------------------------------------- /ci/kokoro/install/ubuntu-xenial.cfg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googleapis/google-cloud-cpp-spanner/459937ff3b9d4876c20c0561b13922c7bb36d445/ci/kokoro/install/ubuntu-xenial.cfg -------------------------------------------------------------------------------- /ci/kokoro/macos/bazel-presubmit.cfg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googleapis/google-cloud-cpp-spanner/459937ff3b9d4876c20c0561b13922c7bb36d445/ci/kokoro/macos/bazel-presubmit.cfg -------------------------------------------------------------------------------- /ci/kokoro/macos/bazel.cfg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googleapis/google-cloud-cpp-spanner/459937ff3b9d4876c20c0561b13922c7bb36d445/ci/kokoro/macos/bazel.cfg -------------------------------------------------------------------------------- /ci/kokoro/macos/cmake-super-presubmit.cfg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googleapis/google-cloud-cpp-spanner/459937ff3b9d4876c20c0561b13922c7bb36d445/ci/kokoro/macos/cmake-super-presubmit.cfg -------------------------------------------------------------------------------- /ci/kokoro/macos/cmake-super.cfg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googleapis/google-cloud-cpp-spanner/459937ff3b9d4876c20c0561b13922c7bb36d445/ci/kokoro/macos/cmake-super.cfg -------------------------------------------------------------------------------- /ci/kokoro/macos/common.cfg: -------------------------------------------------------------------------------- 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 | # http://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 | build_file: "google-cloud-cpp-spanner/ci/kokoro/macos/build.sh" 16 | timeout_mins: 120 17 | 18 | gfile_resources: "/bigstore/cloud-cpp-integration-secrets/spanner-integration-tests-config.sh" 19 | gfile_resources: "/bigstore/cloud-cpp-integration-secrets/spanner-credentials.json" 20 | -------------------------------------------------------------------------------- /ci/kokoro/windows/bazel-presubmit.cfg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googleapis/google-cloud-cpp-spanner/459937ff3b9d4876c20c0561b13922c7bb36d445/ci/kokoro/windows/bazel-presubmit.cfg -------------------------------------------------------------------------------- /ci/kokoro/windows/bazel.cfg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googleapis/google-cloud-cpp-spanner/459937ff3b9d4876c20c0561b13922c7bb36d445/ci/kokoro/windows/bazel.cfg -------------------------------------------------------------------------------- /ci/kokoro/windows/build-bazel-dependencies.ps1: -------------------------------------------------------------------------------- 1 | # !/usr/bin/env powershell 2 | # Copyright 2020 Google LLC 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | Write-Host -ForegroundColor Yellow "`n$(Get-Date -Format o) No dependencies required for Bazel builds." 17 | -------------------------------------------------------------------------------- /ci/kokoro/windows/build.bat: -------------------------------------------------------------------------------- 1 | @REM Copyright 2019 Google LLC 2 | @REM 3 | @REM Licensed under the Apache License, Version 2.0 (the "License"); 4 | @REM you may not use this file except in compliance with the License. 5 | @REM You may obtain a copy of the License at 6 | @REM 7 | @REM http://www.apache.org/licenses/LICENSE-2.0 8 | @REM 9 | @REM Unless required by applicable law or agreed to in writing, software 10 | @REM distributed under the License is distributed on an "AS IS" BASIS, 11 | @REM WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | @REM See the License for the specific language governing permissions and 13 | @REM limitations under the License. 14 | 15 | REM Install Bazel using Chocolatey. 16 | choco install -y bazel --version 2.0.0 17 | 18 | REM Change PATH to use chocolatey's version of Bazel 19 | set PATH=C:\ProgramData\chocolatey\bin;%PATH% 20 | bazel version 21 | 22 | REM Configure the environment to use MSVC 2019 and then switch to PowerShell. 23 | call "c:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvars64.bat" 24 | 25 | REM The remaining of the build script is implemented in PowerShell. 26 | echo %date% %time% 27 | cd github\google-cloud-cpp-spanner 28 | powershell -exec bypass ci\kokoro\windows\build.ps1 29 | if %errorlevel% neq 0 exit /b %errorlevel% 30 | 31 | @echo DONE "=============================================" 32 | @echo %date% %time% 33 | -------------------------------------------------------------------------------- /ci/kokoro/windows/cmake-presubmit.cfg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googleapis/google-cloud-cpp-spanner/459937ff3b9d4876c20c0561b13922c7bb36d445/ci/kokoro/windows/cmake-presubmit.cfg -------------------------------------------------------------------------------- /ci/kokoro/windows/cmake.cfg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googleapis/google-cloud-cpp-spanner/459937ff3b9d4876c20c0561b13922c7bb36d445/ci/kokoro/windows/cmake.cfg -------------------------------------------------------------------------------- /ci/kokoro/windows/common.cfg: -------------------------------------------------------------------------------- 1 | # Format: //devtools/kokoro/config/proto/build.proto 2 | # Copyright 2019 Google LLC 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | build_file: "google-cloud-cpp-spanner/ci/kokoro/windows/build.bat" 17 | timeout_mins: 120 18 | 19 | gfile_resources: "/bigstore/cloud-cpp-integration-secrets/build-results-service-account.json" 20 | gfile_resources: "/bigstore/cloud-cpp-integration-secrets/spanner-credentials.json" 21 | gfile_resources: "/bigstore/cloud-cpp-integration-secrets/spanner-integration-tests-config.bat" 22 | gfile_resources: "/bigstore/cloud-cpp-integration-secrets/google-cloud-cpp-spanner/spanner-integration-tests-config.ps1" 23 | 24 | env_vars { 25 | key: "BUILD_CACHE" 26 | value: "gs://cloud-cpp-kokoro-results/build-artifacts/spanner-vcpkg-installed.zip" 27 | } 28 | 29 | env_vars { 30 | key: "RUN_INTEGRATION_TESTS" 31 | value: "true" 32 | } 33 | -------------------------------------------------------------------------------- /ci/kokoro/windows/vcpkg-ports/google-cloud-cpp-common/CONTROL: -------------------------------------------------------------------------------- 1 | Source: google-cloud-cpp-common 2 | Version: 0.25.0 3 | Build-Depends: grpc, googleapis 4 | Description: Base C++ Libraries for Google Cloud Platform APIs 5 | Homepage: https://github.com/googleapis/google-cloud-cpp-common 6 | 7 | Feature: test 8 | Description: Build test 9 | Build-Depends: gtest 10 | -------------------------------------------------------------------------------- /ci/kokoro/windows/vcpkg-ports/google-cloud-cpp-common/portfile.cmake: -------------------------------------------------------------------------------- 1 | include(vcpkg_common_functions) 2 | 3 | vcpkg_check_linkage(ONLY_STATIC_LIBRARY) 4 | 5 | vcpkg_from_github( 6 | OUT_SOURCE_PATH 7 | SOURCE_PATH 8 | REPO 9 | googleapis/google-cloud-cpp-common 10 | REF 11 | v0.25.0 12 | SHA512 13 | 074294e8b824d7f2b9d6d4051f4fbb28ca83166aad98ff000348abb238488b1c957726d901dae041bf50aa23ab368da5cf1d23ad42454f9ad07153976c0a29fe 14 | HEAD_REF 15 | master) 16 | 17 | vcpkg_check_features(OUT_FEATURE_OPTIONS FEATURE_OPTIONS test BUILD_TESTING) 18 | 19 | vcpkg_configure_cmake( 20 | SOURCE_PATH 21 | ${SOURCE_PATH} 22 | PREFER_NINJA 23 | DISABLE_PARALLEL_CONFIGURE 24 | OPTIONS 25 | ${FEATURE_OPTIONS} 26 | -DGOOGLE_CLOUD_CPP_ENABLE_MACOS_OPENSSL_CHECK=OFF) 27 | 28 | vcpkg_install_cmake(ADD_BIN_TO_PATH) 29 | 30 | file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/debug/include) 31 | vcpkg_fixup_cmake_targets(CONFIG_PATH lib/cmake TARGET_PATH share) 32 | 33 | file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/debug/share) 34 | file( 35 | INSTALL ${SOURCE_PATH}/LICENSE 36 | DESTINATION ${CURRENT_PACKAGES_DIR}/share/google-cloud-cpp-common 37 | RENAME copyright) 38 | 39 | vcpkg_copy_pdbs() 40 | -------------------------------------------------------------------------------- /ci/kokoro/windows/vcpkg-ports/googleapis/CONTROL: -------------------------------------------------------------------------------- 1 | Source: googleapis 2 | Version: 0.9.0 3 | Build-Depends: grpc, protobuf 4 | Description: C++ Proto Libraries for Google APIs. 5 | Homepage: https://github.com/googleapis/cpp-cmakefiles 6 | Supports: !uwp 7 | -------------------------------------------------------------------------------- /ci/kokoro/windows/vcpkg-ports/googleapis/portfile.cmake: -------------------------------------------------------------------------------- 1 | vcpkg_fail_port_install(ON_TARGET "uwp") 2 | 3 | vcpkg_check_linkage(ONLY_STATIC_LIBRARY) 4 | 5 | vcpkg_from_github( 6 | OUT_SOURCE_PATH 7 | SOURCE_PATH 8 | REPO 9 | googleapis/cpp-cmakefiles 10 | REF 11 | v0.9.0 12 | SHA512 13 | 74791d0ae2fcac0a1acdc255e65f7ca46de8b5129f5b9b066efd0d83c5b3bf61e41b9c3ec6924cfbfb77e5496fa9e2db113f8d17dcc0740058bb19f4d1115f18 14 | HEAD_REF 15 | master) 16 | 17 | vcpkg_configure_cmake(SOURCE_PATH ${SOURCE_PATH} PREFER_NINJA) 18 | 19 | vcpkg_install_cmake(ADD_BIN_TO_PATH) 20 | 21 | file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/debug/include) 22 | vcpkg_fixup_cmake_targets(CONFIG_PATH lib/cmake TARGET_PATH share) 23 | 24 | file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/debug/share) 25 | file( 26 | INSTALL ${SOURCE_PATH}/LICENSE 27 | DESTINATION ${CURRENT_PACKAGES_DIR}/share/${PORT} 28 | RENAME copyright) 29 | 30 | vcpkg_copy_pdbs() 31 | 32 | file(COPY ${CMAKE_CURRENT_LIST_DIR}/usage 33 | DESTINATION ${CURRENT_PACKAGES_DIR}/share/${PORT}) 34 | -------------------------------------------------------------------------------- /ci/kokoro/windows/vcpkg-ports/googleapis/usage: -------------------------------------------------------------------------------- 1 | The package googleapis is compatible with built-in CMake targets: 2 | 3 | find_package(googleapis CONFIG REQUIRED) 4 | 5 | # Then link against the proto libraries that you want to use, for example: 6 | target_link_libraries(main PRIVATE googleapis-c++::bigtable_protos gRPC::grpc gRPC::grpc++) 7 | -------------------------------------------------------------------------------- /ci/retry-command.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Copyright 2019 Google LLC 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | set -eu 17 | 18 | # Make three attempts to install the dependencies. It is rare, but from time to 19 | # time the downloading the packages, building the Docker images, or an installer 20 | # Bazel, or the Google Cloud SDK fails. To make the CI build more robust, try 21 | # again when that happens. 22 | 23 | if (( $# < 1 )); then 24 | echo "Usage: $(basename "$0") program [arguments]" 25 | exit 1 26 | fi 27 | readonly PROGRAM=${1} 28 | shift 29 | 30 | # Initially, wait at least 2 minutes (the times are in seconds), because it 31 | # makes no sense to try faster. This used to be 180 seconds, but that ends with 32 | # sleeps close to 10 minutes, and Travis aborts builds that do not output in 33 | # 10m. 34 | min_wait=120 35 | # Do not exit on failures for this loop. 36 | set +e 37 | for i in 1 2 3; do 38 | if "${PROGRAM}" "$@"; then 39 | exit 0 40 | fi 41 | # Sleep for a few minutes before trying again. 42 | period=$(( (RANDOM % 60) + min_wait )) 43 | echo "${PROGRAM} failed (attempt ${i}); trying again in ${period} seconds." 44 | sleep ${period}s 45 | min_wait=$(( min_wait * 2 )) 46 | done 47 | 48 | exit 1 49 | -------------------------------------------------------------------------------- /ci/test-api/spanner_client.expected.abi.dump.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googleapis/google-cloud-cpp-spanner/459937ff3b9d4876c20c0561b13922c7bb36d445/ci/test-api/spanner_client.expected.abi.dump.gz -------------------------------------------------------------------------------- /cmake/EnableClangTidy.cmake: -------------------------------------------------------------------------------- 1 | # ~~~ 2 | # Copyright 2019 Google Inc. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # ~~~ 16 | 17 | option(GOOGLE_CLOUD_CPP_CLANG_TIDY 18 | "If set compiles the Cloud Cloud C++ Libraries with clang-tidy." "") 19 | mark_as_advanced(GOOGLE_CLOUD_CPP_CLANG_TIDY) 20 | 21 | if (${CMAKE_VERSION} VERSION_LESS "3.6") 22 | message(STATUS "clang-tidy is not enabled because cmake version is too old") 23 | else () 24 | if (${CMAKE_VERSION} VERSION_LESS "3.8") 25 | message(WARNING "clang-tidy exit code ignored in this version of cmake") 26 | endif () 27 | find_program( 28 | GOOGLE_CLOUD_CPP_CLANG_TIDY_PROGRAM 29 | NAMES "clang-tidy" 30 | DOC "Path to clang-tidy executable") 31 | mark_as_advanced(GOOGLE_CLOUD_CPP_CLANG_TIDY_PROGRAM) 32 | if (NOT GOOGLE_CLOUD_CPP_CLANG_TIDY_PROGRAM) 33 | message(STATUS "clang-tidy not found.") 34 | else () 35 | message( 36 | STATUS "clang-tidy found: ${GOOGLE_CLOUD_CPP_CLANG_TIDY_PROGRAM}") 37 | endif () 38 | endif () 39 | 40 | function (google_cloud_cpp_add_clang_tidy target) 41 | if (GOOGLE_CLOUD_CPP_CLANG_TIDY_PROGRAM AND GOOGLE_CLOUD_CPP_CLANG_TIDY) 42 | set_target_properties( 43 | ${target} PROPERTIES CXX_CLANG_TIDY 44 | "${GOOGLE_CLOUD_CPP_CLANG_TIDY_PROGRAM}") 45 | endif () 46 | endfunction () 47 | -------------------------------------------------------------------------------- /cmake/EnableCxxExceptions.cmake: -------------------------------------------------------------------------------- 1 | # ~~~ 2 | # Copyright 2018 Google Inc. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # ~~~ 16 | 17 | option(GOOGLE_CLOUD_CPP_ENABLE_CXX_EXCEPTIONS "Enable C++ Exception Support" ON) 18 | 19 | # If the user disabled C++ exceptions we should give them a heads up about the 20 | # consequences. 21 | if (NOT GOOGLE_CLOUD_CPP_ENABLE_CXX_EXCEPTIONS) 22 | message( 23 | WARNING 24 | "C++ Exceptions disabled, any operation that normally" 25 | " raises exceptions will instead log the error and call" 26 | " std::abort(). In addition, some examples and tests will not be" 27 | " compiled.") 28 | if (MSVC) 29 | set(GOOGLE_CLOUD_CPP_EXCEPTIONS_FLAG "/EHs-c-") 30 | else () 31 | set(GOOGLE_CLOUD_CPP_EXCEPTIONS_FLAG "-fno-exceptions") 32 | endif () 33 | else () 34 | set(GOOGLE_CLOUD_CPP_EXCEPTIONS_FLAG "") 35 | endif () 36 | -------------------------------------------------------------------------------- /cmake/SelectMSVCRuntime.cmake: -------------------------------------------------------------------------------- 1 | # ~~~ 2 | # Copyright 2019 Google LLC 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # ~~~ 16 | 17 | # When compiling against *-static vcpkg packages we need to use the static C++ 18 | # runtime with MSVC. The default is to use the dynamic runtime, which does not 19 | # work in this case. This seems to be the recommended way to change the 20 | # runtime: 21 | # 22 | # ~~~ 23 | # https://gitlab.kitware.com/cmake/community/wikis/FAQ#how-can-i-build-my-msvc-application-with-a-static-runtime 24 | # ~~~ 25 | # 26 | # Note that currently we use VCPKG_TARGET_TRIPLET to determine if the static 27 | # runtime is needed. In the future we may need to use a more complex expression 28 | # to determine this, but this is a good start. 29 | # 30 | if (MSVC AND VCPKG_TARGET_TRIPLET MATCHES "-static$") 31 | foreach (flag_var 32 | CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE 33 | CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO) 34 | if (${flag_var} MATCHES "/MD") 35 | string(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}") 36 | endif () 37 | endforeach (flag_var) 38 | unset(flag_var) 39 | endif () 40 | -------------------------------------------------------------------------------- /doc/doxygen-style-guide.md: -------------------------------------------------------------------------------- 1 | # Doxygen Documentation Style Guide 2 | 3 | This document describes how to use Doxygen in this project. The contents are 4 | intended as guidelines for developers in the project, they are not hard rules. 5 | 6 | 1. All types, functions, macros, namespaces in the public API get documentation, 7 | even "obvious" classes and functions. 8 | 9 | 1. Prefer `///` for types or functions that just have a single line of 10 | documentation. For example: 11 | ```C++ 12 | /// This function computes an approximate value for Pi 13 | double ComputePi() { return 3; } 14 | ``` 15 | 16 | 1. For types or functions that get a long comment start with: (a) a one sentence 17 | description of that the thing is or does, then (b) the rest of the 18 | documentation. In other words, we use `JAVADOC_AUTOBRIEF=yes`: 19 | ```C++ 20 | /** 21 | * This function computes an approximate value for Pi 22 | * 23 | * Get a value of Pi adequate for our needs, it may not be super 24 | * accurate, but it is fast. 25 | */ 26 | double ComputePi() { return 3; } 27 | ``` 28 | 29 | 1. We use `/** ... */` for long comments, we do not use `/*! ... */`. 30 | 31 | 1. Use `@command` in preference `\command` for commands, e.g., `@param` or 32 | `@return` instead of `\param` or `\return`. 33 | 34 | 1. For functions, if you document one parameter you need to document all of 35 | them. 36 | 37 | 1. When documenting functions add the `@return` section if non-obvious. 38 | 39 | 1. Large important classes get large documentation, including links to the 40 | relevant docs in `cloud.google.com`, but add those late in the development 41 | cycle. 42 | 43 | 1. Using Doxygen for private members is entirely optional, we do not extract 44 | this documentation, but it is easier to use the same style for all comments. 45 | 46 | ## Additional Information 47 | 48 | * The Doxygen website has detailed information on how to format 49 | [docblocks][docblocks-link]. 50 | 51 | [docblocks-link]: http://www.doxygen.nl/manual/docblocks.html 52 | -------------------------------------------------------------------------------- /doc/testing-resources.md: -------------------------------------------------------------------------------- 1 | # Some rules around Spanner resources 2 | 3 | We're running integration tests and samples on every PR. We've created 4 | pre-defined Spanner instances for speeding up the tests. Also some of our tests 5 | need to create a new Spanner instance. There are certain rules on instance names 6 | and InstanceConfig for those instances. 7 | 8 | Pre-defined Spanner instances have instance ids prefixed with `test-instance-n` 9 | where `n` is just an index number, and they're in `us-central` or `us-east`. 10 | 11 | Temporary Spanner instances have instance ids prefixed with 12 | `temporary-instance-YYY-MM-DD` and they're in `us-west*`. 13 | -------------------------------------------------------------------------------- /google/cloud/spanner/backoff_policy.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 | // http://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_BACKOFF_POLICY_H 16 | #define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_SPANNER_BACKOFF_POLICY_H 17 | 18 | #include "google/cloud/spanner/version.h" 19 | #include "google/cloud/internal/backoff_policy.h" 20 | 21 | namespace google { 22 | namespace cloud { 23 | namespace spanner { 24 | inline namespace SPANNER_CLIENT_NS { 25 | 26 | /// The base class for spanner's backoff policies. 27 | using BackoffPolicy = ::google::cloud::internal::BackoffPolicy; 28 | 29 | /// A truncated exponential backoff policy with randomized periods. 30 | using ExponentialBackoffPolicy = 31 | google::cloud::internal::ExponentialBackoffPolicy; 32 | 33 | } // namespace SPANNER_CLIENT_NS 34 | } // namespace spanner 35 | } // namespace cloud 36 | } // namespace google 37 | 38 | #endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_SPANNER_BACKOFF_POLICY_H 39 | -------------------------------------------------------------------------------- /google/cloud/spanner/backup.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2020 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 | // http://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 | #include "google/cloud/spanner/backup.h" 16 | 17 | namespace google { 18 | namespace cloud { 19 | namespace spanner { 20 | inline namespace SPANNER_CLIENT_NS { 21 | 22 | Backup::Backup(Instance instance, std::string backup_id) 23 | : instance_(std::move(instance)), backup_id_(std::move(backup_id)) {} 24 | 25 | std::string Backup::FullName() const { 26 | return instance().FullName() + "/backups/" + backup_id_; 27 | } 28 | 29 | bool operator==(Backup const& a, Backup const& b) { 30 | return a.instance_ == b.instance_ && a.backup_id_ == b.backup_id_; 31 | } 32 | 33 | bool operator!=(Backup const& a, Backup const& b) { return !(a == b); } 34 | 35 | std::ostream& operator<<(std::ostream& os, Backup const& bn) { 36 | return os << bn.FullName(); 37 | } 38 | 39 | } // namespace SPANNER_CLIENT_NS 40 | } // namespace spanner 41 | } // namespace cloud 42 | } // namespace google 43 | -------------------------------------------------------------------------------- /google/cloud/spanner/benchmarks/benchmarks_config.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 | // http://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_BENCHMARKS_BENCHMARKS_CONFIG_H 16 | #define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_SPANNER_BENCHMARKS_BENCHMARKS_CONFIG_H 17 | 18 | #include "google/cloud/spanner/version.h" 19 | #include "google/cloud/status_or.h" 20 | #include 21 | #include 22 | #include 23 | 24 | namespace google { 25 | namespace cloud { 26 | namespace spanner_benchmarks { 27 | inline namespace SPANNER_CLIENT_NS { 28 | 29 | struct Config { 30 | std::string experiment; 31 | 32 | std::string project_id; 33 | std::string instance_id; 34 | std::string database_id; 35 | 36 | int samples = 2; 37 | std::chrono::seconds iteration_duration = std::chrono::seconds(5); 38 | 39 | int minimum_threads = 1; 40 | int maximum_threads = 1; 41 | // TODO(#1193) change these variable names from `*_clients` to `*_channels` 42 | int minimum_clients = 1; 43 | int maximum_clients = 1; 44 | 45 | std::int64_t table_size = 1000 * 1000L; 46 | std::int64_t query_size = 1000; 47 | 48 | bool use_only_clients = false; 49 | bool use_only_stubs = false; 50 | }; 51 | 52 | std::ostream& operator<<(std::ostream& os, Config const& config); 53 | 54 | google::cloud::StatusOr ParseArgs(std::vector args); 55 | 56 | } // namespace SPANNER_CLIENT_NS 57 | } // namespace spanner_benchmarks 58 | } // namespace cloud 59 | } // namespace google 60 | 61 | #endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_SPANNER_BENCHMARKS_BENCHMARKS_CONFIG_H 62 | -------------------------------------------------------------------------------- /google/cloud/spanner/benchmarks/single_row_throughput_plots.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # Copyright 2019 Google LLC 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | """Summarize the results from running single_row_throughput_benchmark.""" 17 | 18 | # %% 19 | import argparse 20 | import numpy as np 21 | import pandas as pd 22 | import plotnine as p9 23 | 24 | 25 | # %% 26 | def load_benchmark_output(file): 27 | """Loads the output generated by single_row_throughput_benchmark.""" 28 | df = pd.read_csv(file, comment='#', header=0) 29 | # The elapsed time is in microseconds, normalize throughput to events/s 30 | df['Throughput'] = df.EventCount * 1000000 / df.ElapsedTime 31 | return df 32 | 33 | 34 | parser = argparse.ArgumentParser() 35 | parser.add_argument('--input-file', type=argparse.FileType('r'), required=True, 36 | help='the benchmark output file to load') 37 | parser.add_argument('--output-file', type=str, required=True, 38 | help='the name for the output plot') 39 | args = parser.parse_args() 40 | 41 | 42 | # %% 43 | data = load_benchmark_output(args.input_file) 44 | 45 | # %% 46 | print(data.head()) 47 | 48 | # %% 49 | print(data.describe()) 50 | 51 | # %% 52 | (p9.ggplot(data=data, 53 | mapping=p9.aes(x='ThreadCount', y='Throughput')) 54 | + p9.geom_point()).save(args.output_file) 55 | -------------------------------------------------------------------------------- /google/cloud/spanner/benchmarks/spanner_client_benchmark_programs.bzl: -------------------------------------------------------------------------------- 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 | # http://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 | # DO NOT EDIT -- GENERATED BY CMake -- Change the CMakeLists.txt file if needed 16 | 17 | """Automatically generated unit tests list - DO NOT EDIT.""" 18 | 19 | spanner_client_benchmark_programs = [ 20 | "benchmarks_config_test.cc", 21 | "multiple_rows_cpu_benchmark.cc", 22 | "single_row_throughput_benchmark.cc", 23 | ] 24 | -------------------------------------------------------------------------------- /google/cloud/spanner/benchmarks/spanner_client_benchmarks.bzl: -------------------------------------------------------------------------------- 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 | # http://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 | # DO NOT EDIT -- GENERATED BY CMake -- Change the CMakeLists.txt file if needed 16 | 17 | """Automatically generated source lists for spanner_client_benchmarks - DO NOT EDIT.""" 18 | 19 | spanner_client_benchmarks_hdrs = [ 20 | "benchmarks_config.h", 21 | ] 22 | 23 | spanner_client_benchmarks_srcs = [ 24 | "benchmarks_config.cc", 25 | ] 26 | -------------------------------------------------------------------------------- /google/cloud/spanner/client_options_test.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2020 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 | // http://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 | #include "google/cloud/spanner/client_options.h" 16 | #include "google/cloud/spanner/query_options.h" 17 | #include "google/cloud/spanner/version.h" 18 | #include 19 | 20 | namespace google { 21 | namespace cloud { 22 | namespace spanner { 23 | inline namespace SPANNER_CLIENT_NS { 24 | namespace { 25 | 26 | TEST(ClientOptionsTest, OptimizerVersion) { 27 | ClientOptions const default_constructed{}; 28 | EXPECT_EQ(QueryOptions{}, default_constructed.query_options()); 29 | 30 | auto copy = default_constructed; 31 | EXPECT_EQ(copy, default_constructed); 32 | 33 | copy.set_query_options(QueryOptions{}.set_optimizer_version("foo")); 34 | EXPECT_NE(copy, default_constructed); 35 | 36 | copy.set_query_options(QueryOptions{}); 37 | EXPECT_EQ(copy, default_constructed); 38 | } 39 | 40 | } // namespace 41 | } // namespace SPANNER_CLIENT_NS 42 | } // namespace spanner 43 | } // namespace cloud 44 | } // namespace google 45 | -------------------------------------------------------------------------------- /google/cloud/spanner/commit_result.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 | // http://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_COMMIT_RESULT_H 16 | #define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_SPANNER_COMMIT_RESULT_H 17 | 18 | #include "google/cloud/spanner/timestamp.h" 19 | #include "google/cloud/spanner/version.h" 20 | 21 | namespace google { 22 | namespace cloud { 23 | namespace spanner { 24 | inline namespace SPANNER_CLIENT_NS { 25 | 26 | /** 27 | * The result of committing a Transaction. 28 | */ 29 | struct CommitResult { 30 | /// The Cloud Spanner timestamp at which the transaction committed. 31 | Timestamp commit_timestamp; 32 | }; 33 | 34 | } // namespace SPANNER_CLIENT_NS 35 | } // namespace spanner 36 | } // namespace cloud 37 | } // namespace google 38 | 39 | #endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_SPANNER_COMMIT_RESULT_H 40 | -------------------------------------------------------------------------------- /google/cloud/spanner/config-version.cmake.in: -------------------------------------------------------------------------------- 1 | # Copyright 2018 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 | # http://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 | set(PACKAGE_VERSION @DOXYGEN_PROJECT_NUMBER@) 16 | 17 | # This package has not reached 1.0, there are no compatibility guarantees 18 | # before then. 19 | if (@GOOGLE_CLOUD_CPP_VERSION@ EQUAL 0) 20 | if ("${PACKAGE_FIND_VERSION}" STREQUAL "") 21 | set(PACKAGE_VERSION_COMPATIBLE TRUE) 22 | elseif ("${PACKAGE_VERSION}" VERSION_EQUAL "${PACKAGE_FIND_VERSION}") 23 | set(PACKAGE_VERSION_COMPATIBLE TRUE) 24 | set(PACKAGE_VERSION_EXACT TRUE) 25 | else () 26 | set(PACKAGE_VERSION_UNSUITABLE TRUE) 27 | endif () 28 | elseif("${PACKAGE_VERSION}" VERSION_LESS "${PACKAGE_FIND_VERSION}") 29 | set(PACKAGE_VERSION_COMPATIBLE FALSE) 30 | else() 31 | set(PACKAGE_VERSION_COMPATIBLE TRUE) 32 | if ("${PACKAGE_VERSION}" VERSION_EQUAL "${PACKAGE_FIND_VERSION}") 33 | set(PACKAGE_VERSION_EXACT TRUE) 34 | endif() 35 | endif() 36 | -------------------------------------------------------------------------------- /google/cloud/spanner/config.cmake.in: -------------------------------------------------------------------------------- 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 | # http://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 | include(CMakeFindDependencyMacro) 16 | find_dependency(google_cloud_cpp_common) 17 | find_dependency(google_cloud_cpp_grpc_utils) 18 | 19 | include("${CMAKE_CURRENT_LIST_DIR}/spanner-targets.cmake") 20 | 21 | add_library(googleapis-c++::spanner_client IMPORTED INTERFACE) 22 | set_target_properties(googleapis-c++::spanner_client PROPERTIES 23 | INTERFACE_LINK_LIBRARIES "spanner_client") 24 | -------------------------------------------------------------------------------- /google/cloud/spanner/config.pc.in: -------------------------------------------------------------------------------- 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 | # http://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 | prefix=@CMAKE_INSTALL_PREFIX@ 16 | exec_prefix=${prefix}/@CMAKE_INSTALL_BINDIR@ 17 | libdir=${prefix}/@CMAKE_INSTALL_LIBDIR@ 18 | includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@ 19 | 20 | Name: @GOOGLE_CLOUD_CPP_PC_NAME@ 21 | Description: @GOOGLE_CLOUD_CPP_PC_DESCRIPTION@ 22 | Requires: @GOOGLE_CLOUD_CPP_PC_REQUIRES@ 23 | Version: @DOXYGEN_PROJECT_NUMBER@ 24 | 25 | Libs: -L${libdir} @GOOGLE_CLOUD_CPP_PC_LIBS@ 26 | Cflags: -I${includedir} 27 | -------------------------------------------------------------------------------- /google/cloud/spanner/connection_options.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 | // http://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_CONNECTION_OPTIONS_H 16 | #define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_SPANNER_CONNECTION_OPTIONS_H 17 | 18 | #include "google/cloud/spanner/version.h" 19 | #include "google/cloud/connection_options.h" 20 | #include 21 | 22 | namespace google { 23 | namespace cloud { 24 | namespace spanner { 25 | inline namespace SPANNER_CLIENT_NS { 26 | 27 | /** 28 | * The traits to configure `ConnectionOptions` for Cloud Spanner. 29 | * 30 | * See `google::cloud::ConnectionOptions` for more details at 31 | * https://googleapis.dev/cpp/google-cloud-common/latest/ 32 | */ 33 | struct ConnectionOptionsTraits { 34 | static std::string default_endpoint(); 35 | static std::string user_agent_prefix(); 36 | static int default_num_channels(); 37 | }; 38 | 39 | /** 40 | * The options for Cloud Spanner connections. 41 | * 42 | * See `google::cloud::ConnectionOptions` for more details at 43 | * https://googleapis.dev/cpp/google-cloud-common/latest/ 44 | */ 45 | using ConnectionOptions = 46 | google::cloud::ConnectionOptions; 47 | 48 | namespace internal { 49 | ConnectionOptions EmulatorOverrides(ConnectionOptions options); 50 | } // namespace internal 51 | 52 | } // namespace SPANNER_CLIENT_NS 53 | } // namespace spanner 54 | } // namespace cloud 55 | } // namespace google 56 | 57 | #endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_SPANNER_CONNECTION_OPTIONS_H 58 | -------------------------------------------------------------------------------- /google/cloud/spanner/database.cc: -------------------------------------------------------------------------------- 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 | // http://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 | #include "google/cloud/spanner/database.h" 16 | #include 17 | 18 | namespace google { 19 | namespace cloud { 20 | namespace spanner { 21 | inline namespace SPANNER_CLIENT_NS { 22 | 23 | Database::Database(Instance instance, std::string database_id) 24 | : instance_(std::move(instance)), database_id_(std::move(database_id)) {} 25 | 26 | Database::Database(std::string project_id, std::string instance_id, 27 | std::string database_id) 28 | : Database(Instance(std::move(project_id), std::move(instance_id)), 29 | std::move(database_id)) {} 30 | 31 | std::string Database::FullName() const { 32 | return instance().FullName() + "/databases/" + database_id_; 33 | } 34 | 35 | bool operator==(Database const& a, Database const& b) { 36 | return a.instance_ == b.instance_ && a.database_id_ == b.database_id_; 37 | } 38 | 39 | bool operator!=(Database const& a, Database const& b) { return !(a == b); } 40 | 41 | std::ostream& operator<<(std::ostream& os, Database const& dn) { 42 | return os << dn.FullName(); 43 | } 44 | 45 | } // namespace SPANNER_CLIENT_NS 46 | } // namespace spanner 47 | } // namespace cloud 48 | } // namespace google 49 | -------------------------------------------------------------------------------- /google/cloud/spanner/database_test.cc: -------------------------------------------------------------------------------- 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 | // http://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 | #include "google/cloud/spanner/database.h" 16 | #include "google/cloud/spanner/testing/matchers.h" 17 | #include 18 | #include 19 | 20 | namespace google { 21 | namespace cloud { 22 | namespace spanner { 23 | inline namespace SPANNER_CLIENT_NS { 24 | namespace { 25 | 26 | TEST(Database, Basics) { 27 | Instance in("p1", "i1"); 28 | Database db(in, "d1"); 29 | EXPECT_EQ("d1", db.database_id()); 30 | EXPECT_EQ(in, db.instance()); 31 | EXPECT_EQ("projects/p1/instances/i1/databases/d1", db.FullName()); 32 | 33 | auto copy = db; 34 | EXPECT_EQ(copy, db); 35 | EXPECT_EQ("d1", copy.database_id()); 36 | EXPECT_EQ(in, copy.instance()); 37 | EXPECT_EQ("projects/p1/instances/i1/databases/d1", copy.FullName()); 38 | 39 | auto moved = std::move(copy); 40 | EXPECT_EQ(moved, db); 41 | EXPECT_EQ("d1", moved.database_id()); 42 | EXPECT_EQ(in, moved.instance()); 43 | EXPECT_EQ("projects/p1/instances/i1/databases/d1", moved.FullName()); 44 | 45 | Instance in2("p2", "i2"); 46 | Database db2(in2, "d2"); 47 | EXPECT_NE(db2, db); 48 | EXPECT_EQ("d2", db2.database_id()); 49 | EXPECT_EQ(in2, db2.instance()); 50 | EXPECT_EQ("projects/p2/instances/i2/databases/d2", db2.FullName()); 51 | } 52 | 53 | TEST(Database, OutputStream) { 54 | Instance in("p1", "i1"); 55 | Database db(in, "d1"); 56 | std::ostringstream os; 57 | os << db; 58 | EXPECT_EQ("projects/p1/instances/i1/databases/d1", os.str()); 59 | } 60 | 61 | } // namespace 62 | } // namespace SPANNER_CLIENT_NS 63 | } // namespace spanner 64 | } // namespace cloud 65 | } // namespace google 66 | -------------------------------------------------------------------------------- /google/cloud/spanner/date.cc: -------------------------------------------------------------------------------- 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 | // http://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 | #include "google/cloud/spanner/date.h" 16 | #include "google/cloud/spanner/internal/date.h" 17 | #include 18 | 19 | namespace google { 20 | namespace cloud { 21 | namespace spanner { 22 | inline namespace SPANNER_CLIENT_NS { 23 | 24 | namespace { 25 | 26 | bool IsLeapYear(std::int64_t y) { 27 | return y % 4 == 0 && (y % 100 != 0 || y % 400 == 0); 28 | } 29 | 30 | int DaysPerMonth(std::int64_t y, int m) { 31 | static std::array const kKDaysPerMonth = {{ 32 | -1, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 // non leap year 33 | }}; 34 | return kKDaysPerMonth[m] + (m == 2 && IsLeapYear(y) ? 1 : 0); 35 | } 36 | 37 | } // namespace 38 | 39 | Date::Date(std::int64_t year, int month, int day) 40 | : year_(year), month_(month), day_(day) { 41 | year_ += month_ / 12; // 12 months == 1 year 42 | month_ %= 12; 43 | if (month_ <= 0) { 44 | year_ -= 1; 45 | month_ += 12; 46 | } 47 | year_ += (day_ / 146097) * 400; // 146097 days == 400 years 48 | day_ %= 146097; 49 | if (day_ <= 0) { 50 | year_ -= 400; 51 | day_ += 146097; 52 | } 53 | for (int n = DaysPerMonth(year_, month_); day_ > n; 54 | n = DaysPerMonth(year_, month_)) { 55 | day_ -= n; 56 | if (++month_ > 12) { 57 | year_ += 1; 58 | month_ = 1; 59 | } 60 | } 61 | } 62 | 63 | std::ostream& operator<<(std::ostream& os, Date const& date) { 64 | return os << internal::DateToString(date); 65 | } 66 | 67 | } // namespace SPANNER_CLIENT_NS 68 | } // namespace spanner 69 | } // namespace cloud 70 | } // namespace google 71 | -------------------------------------------------------------------------------- /google/cloud/spanner/iam_updater.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 | // http://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_IAM_UPDATER_H 16 | #define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_SPANNER_IAM_UPDATER_H 17 | 18 | #include "google/cloud/spanner/version.h" 19 | #include "google/cloud/optional.h" 20 | #include 21 | #include 22 | 23 | namespace google { 24 | namespace cloud { 25 | namespace spanner { 26 | inline namespace SPANNER_CLIENT_NS { 27 | 28 | using IamUpdater = 29 | std::function(google::iam::v1::Policy)>; 30 | 31 | } // namespace SPANNER_CLIENT_NS 32 | } // namespace spanner 33 | } // namespace cloud 34 | } // namespace google 35 | 36 | #endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_SPANNER_IAM_UPDATER_H 37 | -------------------------------------------------------------------------------- /google/cloud/spanner/instance.cc: -------------------------------------------------------------------------------- 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 | // http://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 | #include "google/cloud/spanner/instance.h" 16 | #include 17 | 18 | namespace google { 19 | namespace cloud { 20 | namespace spanner { 21 | inline namespace SPANNER_CLIENT_NS { 22 | 23 | Instance::Instance(std::string project_id, std::string instance_id) 24 | : project_id_(std::move(project_id)), 25 | instance_id_(std::move(instance_id)) {} 26 | 27 | std::string Instance::FullName() const { 28 | return "projects/" + project_id_ + "/instances/" + instance_id_; 29 | } 30 | 31 | bool operator==(Instance const& a, Instance const& b) { 32 | return a.project_id_ == b.project_id_ && a.instance_id_ == b.instance_id_; 33 | } 34 | 35 | bool operator!=(Instance const& a, Instance const& b) { return !(a == b); } 36 | 37 | std::ostream& operator<<(std::ostream& os, Instance const& dn) { 38 | return os << dn.FullName(); 39 | } 40 | 41 | } // namespace SPANNER_CLIENT_NS 42 | } // namespace spanner 43 | } // namespace cloud 44 | } // namespace google 45 | -------------------------------------------------------------------------------- /google/cloud/spanner/instance_test.cc: -------------------------------------------------------------------------------- 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 | // http://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 | #include "google/cloud/spanner/instance.h" 16 | #include "google/cloud/spanner/testing/matchers.h" 17 | #include 18 | #include 19 | 20 | namespace google { 21 | namespace cloud { 22 | namespace spanner { 23 | inline namespace SPANNER_CLIENT_NS { 24 | namespace { 25 | 26 | TEST(Instance, Basics) { 27 | Instance in("p1", "i1"); 28 | EXPECT_EQ("p1", in.project_id()); 29 | EXPECT_EQ("i1", in.instance_id()); 30 | EXPECT_EQ("projects/p1/instances/i1", in.FullName()); 31 | 32 | auto copy = in; 33 | EXPECT_EQ(copy, in); 34 | EXPECT_EQ("p1", copy.project_id()); 35 | EXPECT_EQ("i1", copy.instance_id()); 36 | EXPECT_EQ("projects/p1/instances/i1", copy.FullName()); 37 | 38 | auto moved = std::move(copy); 39 | EXPECT_EQ(moved, in); 40 | EXPECT_EQ("p1", moved.project_id()); 41 | EXPECT_EQ("i1", moved.instance_id()); 42 | EXPECT_EQ("projects/p1/instances/i1", moved.FullName()); 43 | 44 | Instance in2("p2", "i2"); 45 | EXPECT_NE(in2, in); 46 | EXPECT_EQ("p2", in2.project_id()); 47 | EXPECT_EQ("i2", in2.instance_id()); 48 | EXPECT_EQ("projects/p2/instances/i2", in2.FullName()); 49 | } 50 | 51 | TEST(Instance, OutputStream) { 52 | Instance in("p1", "i1"); 53 | std::ostringstream os; 54 | os << in; 55 | EXPECT_EQ("projects/p1/instances/i1", os.str()); 56 | } 57 | 58 | } // namespace 59 | } // namespace SPANNER_CLIENT_NS 60 | } // namespace spanner 61 | } // namespace cloud 62 | } // namespace google 63 | -------------------------------------------------------------------------------- /google/cloud/spanner/integration_tests/BUILD: -------------------------------------------------------------------------------- 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 | # http://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 | package(default_visibility = ["//visibility:public"]) 16 | 17 | licenses(["notice"]) # Apache 2.0 18 | 19 | load(":spanner_client_integration_tests.bzl", "spanner_client_integration_tests") 20 | 21 | [cc_test( 22 | name = "spanner_client_" + test.replace("/", "_").replace(".cc", ""), 23 | timeout = "long", 24 | srcs = [test], 25 | tags = [ 26 | "integration-tests", 27 | "spanner-integration-tests", 28 | ], 29 | deps = [ 30 | "//google/cloud/spanner:spanner_client", 31 | "//google/cloud/spanner:spanner_client_mocks", 32 | "//google/cloud/spanner:spanner_client_testing", 33 | "@com_github_googleapis_google_cloud_cpp_common//google/cloud:google_cloud_cpp_common", 34 | "@com_github_googleapis_google_cloud_cpp_common//google/cloud/testing_util:google_cloud_cpp_testing", 35 | "@com_google_googletest//:gtest_main", 36 | ], 37 | ) for test in spanner_client_integration_tests] 38 | -------------------------------------------------------------------------------- /google/cloud/spanner/integration_tests/README.md: -------------------------------------------------------------------------------- 1 | # Cloud Spanner C++ Client integration tests. 2 | 3 | This directory contains integration tests for the Cloud Spanner C++ client 4 | library. These tests are written using the Google Test framework, but can only 5 | execute when the environment is properly configured. 6 | 7 | ## Google Cloud Platform Project 8 | 9 | The Google Cloud Platform project for the tests must be configured using the 10 | `GOOGLE_CLOUD_PROJECT` environment variable. 11 | 12 | ## Credentials 13 | 14 | The environment must be configured such that `grpc::GoogleDefaultCredentials` 15 | returns a valid credential with `roles/spanner.admin` permissions on the project 16 | configured via the `GOOGLE_CLOUD_PROJECT` environment variable. 17 | 18 | ## Default Cloud Spanner Instance 19 | 20 | The `GOOGLE_CLOUD_CPP_SPANNER_INSTANCE` environment variable must be the id of a 21 | Cloud Spanner instance in the project. This instance is used by most tests, as 22 | it saves them from creating a new instance for just a few operations. 23 | 24 | ## Test Service Account 25 | 26 | The `GOOGLE_CLOUD_CPP_SPANNER_IAM_TEST_SA` environment variable must be the id 27 | of a Google Cloud Platform service account in the project. This service account 28 | is used to test IAM operations, the account is added to and removed from 29 | standard spanner roles. 30 | -------------------------------------------------------------------------------- /google/cloud/spanner/integration_tests/spanner_client_integration_tests.bzl: -------------------------------------------------------------------------------- 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 | # http://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 | # DO NOT EDIT -- GENERATED BY CMake -- Change the CMakeLists.txt file if needed 16 | 17 | """Automatically generated unit tests list - DO NOT EDIT.""" 18 | 19 | spanner_client_integration_tests = [ 20 | "backup_integration_test.cc", 21 | "client_integration_test.cc", 22 | "client_stress_test.cc", 23 | "data_types_integration_test.cc", 24 | "database_admin_integration_test.cc", 25 | "instance_admin_integration_test.cc", 26 | "rpc_failure_threshold_integration_test.cc", 27 | "session_pool_integration_test.cc", 28 | ] 29 | -------------------------------------------------------------------------------- /google/cloud/spanner/internal/README.md: -------------------------------------------------------------------------------- 1 | # Internal Classes and Functions for Cloud Spanner Client 2 | 3 | This directory (`google/cloud/spanner/internal/`) contains implementation 4 | classes for the Cloud Spanner Client. They are not intended for general use. 5 | They are subject to change without notice. Do not use any class, function, or 6 | type in this directory directly in your own applications. 7 | -------------------------------------------------------------------------------- /google/cloud/spanner/internal/api_client_header.cc: -------------------------------------------------------------------------------- 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 | // http://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 | #include "google/cloud/spanner/internal/api_client_header.h" 16 | #include "google/cloud/spanner/internal/compiler_info.h" 17 | 18 | namespace google { 19 | namespace cloud { 20 | namespace spanner { 21 | inline namespace SPANNER_CLIENT_NS { 22 | namespace internal { 23 | 24 | std::string ApiClientHeader() { 25 | return "gl-cpp/" + google::cloud::spanner::internal::CompilerId() + "-" + 26 | google::cloud::spanner::internal::CompilerVersion() + "-" + 27 | google::cloud::spanner::internal::CompilerFeatures() + "-" + 28 | google::cloud::spanner::internal::LanguageVersion() + " gccl/" + 29 | VersionString(); 30 | } 31 | 32 | } // namespace internal 33 | } // namespace SPANNER_CLIENT_NS 34 | } // namespace spanner 35 | } // namespace cloud 36 | } // namespace google 37 | -------------------------------------------------------------------------------- /google/cloud/spanner/internal/api_client_header.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 | // http://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_INTERNAL_API_CLIENT_HEADER_H 16 | #define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_SPANNER_INTERNAL_API_CLIENT_HEADER_H 17 | 18 | #include "google/cloud/spanner/version.h" 19 | #include 20 | 21 | namespace google { 22 | namespace cloud { 23 | namespace spanner { 24 | inline namespace SPANNER_CLIENT_NS { 25 | namespace internal { 26 | 27 | /// Return the value for the x-goog-api-client header (aka metadata). 28 | std::string ApiClientHeader(); 29 | 30 | } // namespace internal 31 | } // namespace SPANNER_CLIENT_NS 32 | } // namespace spanner 33 | } // namespace cloud 34 | } // namespace google 35 | 36 | #endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_SPANNER_INTERNAL_API_CLIENT_HEADER_H 37 | -------------------------------------------------------------------------------- /google/cloud/spanner/internal/api_client_header_test.cc: -------------------------------------------------------------------------------- 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 | // http://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 | #include "google/cloud/spanner/internal/api_client_header.h" 16 | #include "google/cloud/spanner/internal/compiler_info.h" 17 | #include 18 | 19 | namespace google { 20 | namespace cloud { 21 | namespace spanner { 22 | inline namespace SPANNER_CLIENT_NS { 23 | namespace internal { 24 | namespace { 25 | 26 | using ::testing::HasSubstr; 27 | 28 | TEST(ApiClientHeaderTest, Basic) { 29 | auto actual = ApiClientHeader(); 30 | 31 | EXPECT_THAT(actual, HasSubstr("gccl/" + VersionString())); 32 | EXPECT_THAT(actual, 33 | HasSubstr("gl-cpp/" + CompilerId() + "-" + CompilerVersion() + 34 | "-" + CompilerFeatures() + "-" + LanguageVersion())); 35 | } 36 | 37 | } // namespace 38 | } // namespace internal 39 | } // namespace SPANNER_CLIENT_NS 40 | } // namespace spanner 41 | } // namespace cloud 42 | } // namespace google 43 | -------------------------------------------------------------------------------- /google/cloud/spanner/internal/build_info.cc.in: -------------------------------------------------------------------------------- 1 | // Copyright 2017 Google Inc. 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 | // http://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 | #include "google/cloud/spanner/internal/build_info.h" 16 | #include "google/cloud/internal/port_platform.h" 17 | #include 18 | #include 19 | #include 20 | 21 | namespace google { 22 | namespace cloud { 23 | namespace spanner { 24 | inline namespace SPANNER_CLIENT_NS { 25 | namespace internal { 26 | 27 | std::string BuildFlags() { 28 | static auto const* const kFlags = [] { 29 | auto* flags = new std::string(R"""(@CMAKE_CXX_FLAGS@)"""); 30 | if (!flags->empty()) *flags += ' '; 31 | *flags += 32 | R"""(${CMAKE_CXX_FLAGS_${GOOGLE_CLOUD_CPP_SPANNER_BUILD_TYPE_UPPER}})"""; 33 | return flags; 34 | }(); 35 | return *kFlags; 36 | } 37 | 38 | std::string BuildMetadata() { 39 | return R"""(@GOOGLE_CLOUD_CPP_SPANNER_BUILD_METADATA@)"""; 40 | } 41 | 42 | } // namespace internal 43 | } // namespace GOOGLE_CLOUD_CPP_NS 44 | } // namespace spanner 45 | } // namespace cloud 46 | } // namespace google 47 | -------------------------------------------------------------------------------- /google/cloud/spanner/internal/build_info.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017 Google Inc. 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 | // http://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_INTERNAL_BUILD_INFO_H 16 | #define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_SPANNER_INTERNAL_BUILD_INFO_H 17 | 18 | #include "google/cloud/spanner/version.h" 19 | 20 | namespace google { 21 | namespace cloud { 22 | namespace spanner { 23 | inline namespace SPANNER_CLIENT_NS { 24 | namespace internal { 25 | 26 | /** 27 | * Returns the build flags. 28 | * 29 | * Examples include "-c fastbuild" or "-O2 -DNDEBUG". 30 | */ 31 | std::string BuildFlags(); 32 | 33 | /** 34 | * Returns the metadata injected by the build system. 35 | * 36 | * See https://semver.org/#spec-item-10 for more details about the use and 37 | * format of build metadata. Typically, the the value returned here is a hash 38 | * indicating a git commit. 39 | */ 40 | std::string BuildMetadata(); 41 | 42 | } // namespace internal 43 | } // namespace SPANNER_CLIENT_NS 44 | } // namespace spanner 45 | } // namespace cloud 46 | } // namespace google 47 | 48 | #endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_SPANNER_INTERNAL_BUILD_INFO_H 49 | -------------------------------------------------------------------------------- /google/cloud/spanner/internal/build_info_test.cc: -------------------------------------------------------------------------------- 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 | // http://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 | #include "google/cloud/spanner/internal/build_info.h" 16 | #include 17 | 18 | namespace google { 19 | namespace cloud { 20 | namespace spanner { 21 | inline namespace SPANNER_CLIENT_NS { 22 | namespace internal { 23 | namespace { 24 | 25 | using ::testing::HasSubstr; 26 | using ::testing::Not; 27 | 28 | TEST(BuildInfo, BuildFlags) { 29 | auto bf = BuildFlags(); 30 | EXPECT_THAT(bf, Not(HasSubstr("@"))); 31 | } 32 | 33 | TEST(BuildInfo, BuildMetadata) { 34 | auto const md = BuildMetadata(); 35 | EXPECT_FALSE(md.empty()); 36 | EXPECT_THAT(md, Not(HasSubstr("@"))); 37 | } 38 | 39 | } // namespace 40 | } // namespace internal 41 | } // namespace SPANNER_CLIENT_NS 42 | } // namespace spanner 43 | } // namespace cloud 44 | } // namespace google 45 | -------------------------------------------------------------------------------- /google/cloud/spanner/internal/channel.h: -------------------------------------------------------------------------------- 1 | // Copyright 2020 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 | // http://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_INTERNAL_CHANNEL_H 16 | #define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_SPANNER_INTERNAL_CHANNEL_H 17 | 18 | #include "google/cloud/spanner/internal/spanner_stub.h" 19 | #include "google/cloud/spanner/version.h" 20 | #include 21 | 22 | namespace google { 23 | namespace cloud { 24 | namespace spanner { 25 | inline namespace SPANNER_CLIENT_NS { 26 | namespace internal { 27 | 28 | /** 29 | * `Channel` represents a single gRPC Channel/Stub. 30 | */ 31 | struct Channel { 32 | /// @p stub_param must not be nullptr 33 | explicit Channel(std::shared_ptr stub_param) 34 | : stub(std::move(stub_param)) {} 35 | 36 | // This class is not copyable or movable. 37 | Channel(Channel const&) = delete; 38 | Channel& operator=(Channel const&) = delete; 39 | 40 | std::shared_ptr const stub; 41 | int session_count = 0; 42 | }; 43 | 44 | } // namespace internal 45 | } // namespace SPANNER_CLIENT_NS 46 | } // namespace spanner 47 | } // namespace cloud 48 | } // namespace google 49 | 50 | #endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_SPANNER_INTERNAL_CHANNEL_H 51 | -------------------------------------------------------------------------------- /google/cloud/spanner/internal/compiler_info.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 | // http://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_INTERNAL_COMPILER_INFO_H 16 | #define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_SPANNER_INTERNAL_COMPILER_INFO_H 17 | 18 | #include "google/cloud/spanner/version.h" 19 | 20 | namespace google { 21 | namespace cloud { 22 | namespace spanner { 23 | inline namespace SPANNER_CLIENT_NS { 24 | namespace internal { 25 | 26 | /** 27 | * Returns the compiler ID. 28 | * 29 | * The Compiler ID is a string like "GNU" or "Clang", as described by 30 | * https://cmake.org/cmake/help/v3.5/variable/CMAKE_LANG_COMPILER_ID.html 31 | */ 32 | std::string CompilerId(); 33 | 34 | /** 35 | * Returns the compiler version. 36 | * 37 | * This string will be something like "9.1.1". 38 | */ 39 | std::string CompilerVersion(); 40 | 41 | /** 42 | * Returns certain interesting compiler features. 43 | * 44 | * Currently this returns one of "ex" or "noex" to indicate whether or not 45 | * C++ exceptions are enabled. 46 | */ 47 | std::string CompilerFeatures(); 48 | 49 | /** 50 | * Returns the 4-digit year of the C++ language standard. 51 | */ 52 | std::string LanguageVersion(); 53 | 54 | } // namespace internal 55 | } // namespace SPANNER_CLIENT_NS 56 | } // namespace spanner 57 | } // namespace cloud 58 | } // namespace google 59 | 60 | #endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_SPANNER_INTERNAL_COMPILER_INFO_H 61 | -------------------------------------------------------------------------------- /google/cloud/spanner/internal/compiler_info_test.cc: -------------------------------------------------------------------------------- 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 | // http://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 | #include "google/cloud/spanner/internal/compiler_info.h" 16 | #include 17 | 18 | namespace google { 19 | namespace cloud { 20 | namespace spanner { 21 | inline namespace SPANNER_CLIENT_NS { 22 | namespace internal { 23 | namespace { 24 | 25 | using ::testing::AnyOf; 26 | using ::testing::ContainsRegex; 27 | using ::testing::Eq; 28 | using ::testing::MatchesRegex; 29 | 30 | TEST(CompilerInfo, CompilerId) { 31 | auto cn = CompilerId(); 32 | EXPECT_FALSE(cn.empty()); 33 | #ifndef _WIN32 // gMock's regex brackets don't work on Windows. 34 | EXPECT_THAT(cn, ContainsRegex(R"([A-Za-z]+)")); 35 | #endif 36 | } 37 | 38 | TEST(CompilerInfo, CompilerVersion) { 39 | auto cv = CompilerVersion(); 40 | EXPECT_FALSE(cv.empty()); 41 | #ifndef _WIN32 // gMock's regex brackets don't work on Windows. 42 | // Look for something that looks vaguely like an X.Y version number. 43 | EXPECT_THAT(cv, ContainsRegex(R"([0-9]+.[0-9]+)")); 44 | #endif 45 | } 46 | 47 | TEST(CompilerInfo, CompilerFeatures) { 48 | auto cf = CompilerFeatures(); 49 | EXPECT_FALSE(cf.empty()); 50 | EXPECT_THAT(cf, AnyOf(Eq("noex"), Eq("ex"))); 51 | } 52 | 53 | TEST(CompilerInfo, LanguageVersion) { 54 | auto lv = LanguageVersion(); 55 | EXPECT_FALSE(lv.empty()); 56 | #ifndef _WIN32 // gMock's regex brackets don't work on Windows. 57 | EXPECT_THAT(lv, MatchesRegex(R"([0-9]+)")); 58 | #endif 59 | } 60 | 61 | } // namespace 62 | } // namespace internal 63 | } // namespace SPANNER_CLIENT_NS 64 | } // namespace spanner 65 | } // namespace cloud 66 | } // namespace google 67 | -------------------------------------------------------------------------------- /google/cloud/spanner/internal/date.cc: -------------------------------------------------------------------------------- 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 | // http://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 | #include "google/cloud/spanner/internal/date.h" 16 | #include 17 | #include 18 | #include 19 | 20 | namespace google { 21 | namespace cloud { 22 | namespace spanner { 23 | inline namespace SPANNER_CLIENT_NS { 24 | namespace internal { 25 | 26 | std::string DateToString(Date d) { 27 | std::array buf; 28 | std::snprintf(buf.data(), buf.size(), "%04" PRId64 "-%02d-%02d", d.year(), 29 | d.month(), d.day()); 30 | return std::string(buf.data()); 31 | } 32 | 33 | StatusOr DateFromString(std::string const& s) { 34 | std::int64_t year; 35 | int month; 36 | int day; 37 | char c; 38 | switch (sscanf(s.c_str(), "%" SCNd64 "-%d-%d%c", &year, &month, &day, &c)) { 39 | case 3: 40 | break; 41 | case 4: 42 | return Status(StatusCode::kInvalidArgument, 43 | s + ": Extra data after RFC3339 full-date"); 44 | default: 45 | return Status(StatusCode::kInvalidArgument, 46 | s + ": Failed to match RFC3339 full-date"); 47 | } 48 | Date date(year, month, day); 49 | if (date.month() != month || date.day() != day) { 50 | return Status(StatusCode::kInvalidArgument, 51 | s + ": RFC3339 full-date field out of range"); 52 | } 53 | return date; 54 | } 55 | 56 | } // namespace internal 57 | } // namespace SPANNER_CLIENT_NS 58 | } // namespace spanner 59 | } // namespace cloud 60 | } // namespace google 61 | -------------------------------------------------------------------------------- /google/cloud/spanner/internal/date.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 | // http://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_INTERNAL_DATE_H 16 | #define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_SPANNER_INTERNAL_DATE_H 17 | 18 | #include "google/cloud/spanner/date.h" 19 | #include "google/cloud/spanner/version.h" 20 | #include "google/cloud/status_or.h" 21 | #include 22 | 23 | namespace google { 24 | namespace cloud { 25 | namespace spanner { 26 | inline namespace SPANNER_CLIENT_NS { 27 | namespace internal { 28 | 29 | /** 30 | * Convert a Date to an RFC3339 "full-date". 31 | */ 32 | std::string DateToString(Date d); 33 | 34 | /** 35 | * Convert an RFC3339 "full-date" to a Date. 36 | * 37 | * Returns a a non-OK Status if the input cannot be parsed. 38 | */ 39 | StatusOr DateFromString(std::string const& s); 40 | 41 | } // namespace internal 42 | } // namespace SPANNER_CLIENT_NS 43 | } // namespace spanner 44 | } // namespace cloud 45 | } // namespace google 46 | 47 | #endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_SPANNER_INTERNAL_DATE_H 48 | -------------------------------------------------------------------------------- /google/cloud/spanner/internal/date_benchmark.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2020 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 | // http://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 | #include "google/cloud/spanner/internal/date.h" 16 | #include 17 | #include 18 | 19 | namespace google { 20 | namespace cloud { 21 | namespace spanner { 22 | inline namespace SPANNER_CLIENT_NS { 23 | namespace internal { 24 | namespace { 25 | 26 | // Run on (6 X 2300 MHz CPU s) 27 | // CPU Caches: 28 | // L1 Data 32K (x3) 29 | // L1 Instruction 32K (x3) 30 | // L2 Unified 256K (x3) 31 | // L3 Unified 46080K (x1) 32 | // Load Average: 0.24, 0.44, 0.47 33 | // ------------------------------------------------------------ 34 | // Benchmark Time CPU Iterations 35 | // ------------------------------------------------------------ 36 | // BM_DateToString 202 ns 200 ns 3443720 37 | // BM_DateFromString 227 ns 226 ns 3099798 38 | 39 | void BM_DateToString(benchmark::State& state) { 40 | Date d(2020, 1, 17); 41 | for (auto _ : state) { 42 | benchmark::DoNotOptimize(DateToString(d)); 43 | } 44 | } 45 | BENCHMARK(BM_DateToString); 46 | 47 | void BM_DateFromString(benchmark::State& state) { 48 | std::string s = "2020-01-17"; 49 | for (auto _ : state) { 50 | benchmark::DoNotOptimize(DateFromString(s)); 51 | } 52 | } 53 | BENCHMARK(BM_DateFromString); 54 | 55 | } // namespace 56 | } // namespace internal 57 | } // namespace SPANNER_CLIENT_NS 58 | } // namespace spanner 59 | } // namespace cloud 60 | } // namespace google 61 | -------------------------------------------------------------------------------- /google/cloud/spanner/internal/date_test.cc: -------------------------------------------------------------------------------- 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 | // http://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 | #include "google/cloud/spanner/internal/date.h" 16 | #include 17 | 18 | namespace google { 19 | namespace cloud { 20 | namespace spanner { 21 | inline namespace SPANNER_CLIENT_NS { 22 | namespace internal { 23 | namespace { 24 | 25 | TEST(Date, DateToString) { 26 | EXPECT_EQ("2019-06-21", DateToString(Date(2019, 6, 21))); 27 | EXPECT_EQ("1066-10-14", DateToString(Date(1066, 10, 14))); 28 | EXPECT_EQ("0865-03-21", DateToString(Date(865, 3, 21))); 29 | EXPECT_EQ("0014-08-19", DateToString(Date(14, 8, 19))); 30 | } 31 | 32 | TEST(Date, DateFromString) { 33 | EXPECT_EQ(Date(2019, 6, 21), DateFromString("2019-06-21").value()); 34 | } 35 | 36 | TEST(Date, DateFromStringFailure) { 37 | EXPECT_FALSE(DateFromString("")); 38 | EXPECT_FALSE(DateFromString("garbage in")); 39 | EXPECT_FALSE(DateFromString("2018-13-02")); 40 | EXPECT_FALSE(DateFromString("2019-06-31")); 41 | EXPECT_FALSE(DateFromString("2019-06-21x")); 42 | } 43 | 44 | } // namespace 45 | } // namespace internal 46 | } // namespace SPANNER_CLIENT_NS 47 | } // namespace spanner 48 | } // namespace cloud 49 | } // namespace google 50 | -------------------------------------------------------------------------------- /google/cloud/spanner/internal/log_wrapper.cc: -------------------------------------------------------------------------------- 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 | // http://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 | #include "google/cloud/spanner/internal/log_wrapper.h" 16 | #include 17 | 18 | namespace google { 19 | namespace cloud { 20 | namespace spanner { 21 | inline namespace SPANNER_CLIENT_NS { 22 | namespace internal { 23 | 24 | std::string DebugString(google::protobuf::Message const& m, 25 | TracingOptions const& options) { 26 | std::string str; 27 | google::protobuf::TextFormat::Printer p; 28 | p.SetSingleLineMode(options.single_line_mode()); 29 | p.SetUseShortRepeatedPrimitives(options.use_short_repeated_primitives()); 30 | p.SetTruncateStringFieldLongerThan( 31 | options.truncate_string_field_longer_than()); 32 | p.PrintToString(m, &str); 33 | return str; 34 | } 35 | 36 | } // namespace internal 37 | } // namespace SPANNER_CLIENT_NS 38 | } // namespace spanner 39 | } // namespace cloud 40 | } // namespace google 41 | -------------------------------------------------------------------------------- /google/cloud/spanner/internal/logging_result_set_reader.cc: -------------------------------------------------------------------------------- 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 | // http://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 | #include "google/cloud/spanner/internal/logging_result_set_reader.h" 16 | #include "google/cloud/spanner/internal/log_wrapper.h" 17 | 18 | namespace google { 19 | namespace cloud { 20 | namespace spanner { 21 | inline namespace SPANNER_CLIENT_NS { 22 | namespace internal { 23 | 24 | void LoggingResultSetReader::TryCancel() { 25 | GCP_LOG(DEBUG) << __func__ << "() << (void)"; 26 | impl_->TryCancel(); 27 | GCP_LOG(DEBUG) << __func__ << "() >> (void)"; 28 | } 29 | 30 | optional LoggingResultSetReader::Read() { 31 | GCP_LOG(DEBUG) << __func__ << "() << (void)"; 32 | auto result = impl_->Read(); 33 | if (!result) { 34 | GCP_LOG(DEBUG) << __func__ << "() >> (optional-with-no-value)"; 35 | } else { 36 | GCP_LOG(DEBUG) << __func__ << "() >> " 37 | << DebugString(*result, tracing_options_); 38 | } 39 | return result; 40 | } 41 | 42 | Status LoggingResultSetReader::Finish() { 43 | GCP_LOG(DEBUG) << __func__ << "() << (void)"; 44 | auto status = impl_->Finish(); 45 | GCP_LOG(DEBUG) << __func__ << "() >> " << status; 46 | return status; 47 | } 48 | 49 | } // namespace internal 50 | } // namespace SPANNER_CLIENT_NS 51 | } // namespace spanner 52 | } // namespace cloud 53 | } // namespace google 54 | -------------------------------------------------------------------------------- /google/cloud/spanner/internal/logging_result_set_reader.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 | // http://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_INTERNAL_LOGGING_RESULT_SET_READER_H 16 | #define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_SPANNER_INTERNAL_LOGGING_RESULT_SET_READER_H 17 | 18 | #include "google/cloud/spanner/internal/partial_result_set_reader.h" 19 | #include "google/cloud/spanner/tracing_options.h" 20 | #include 21 | 22 | namespace google { 23 | namespace cloud { 24 | namespace spanner { 25 | inline namespace SPANNER_CLIENT_NS { 26 | namespace internal { 27 | 28 | class LoggingResultSetReader : public PartialResultSetReader { 29 | public: 30 | LoggingResultSetReader(std::unique_ptr impl, 31 | TracingOptions tracing_options) 32 | : impl_(std::move(impl)), tracing_options_(std::move(tracing_options)) {} 33 | ~LoggingResultSetReader() override = default; 34 | 35 | void TryCancel() override; 36 | optional Read() override; 37 | Status Finish() override; 38 | 39 | private: 40 | std::unique_ptr impl_; 41 | TracingOptions tracing_options_; 42 | }; 43 | 44 | } // namespace internal 45 | } // namespace SPANNER_CLIENT_NS 46 | } // namespace spanner 47 | } // namespace cloud 48 | } // namespace google 49 | 50 | #endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_SPANNER_INTERNAL_LOGGING_RESULT_SET_READER_H 51 | -------------------------------------------------------------------------------- /google/cloud/spanner/internal/merge_chunk.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 | // http://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_INTERNAL_MERGE_CHUNK_H 16 | #define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_SPANNER_INTERNAL_MERGE_CHUNK_H 17 | 18 | #include "google/cloud/spanner/version.h" 19 | #include "google/cloud/status.h" 20 | #include 21 | 22 | namespace google { 23 | namespace cloud { 24 | namespace spanner { 25 | inline namespace SPANNER_CLIENT_NS { 26 | namespace internal { 27 | 28 | /** 29 | * Merges @p chunk into @p value, or returns an error. 30 | * 31 | * The official documentation about how to "unchunk" Spanner values is at: 32 | * https://github.com/googleapis/googleapis/blob/master/google/spanner/v1/result_set.proto 33 | * 34 | * A paraphrased summary is as follows: 35 | * 36 | * * bool/number/null are never chunked and therefore cannot be merged 37 | * * strings should be concatenated 38 | * * lists should be concatenated 39 | * 40 | * The above rules should be applied recursively. 41 | * 42 | * @note The above linked documentation explains how to "unchunk" objects, 43 | * which are `google::protobuf::Value` objects with the `struct_value` 44 | * field set. However, Spanner never returns these struct_values, so it is 45 | * therefore an error to try to merge them. 46 | */ 47 | Status MergeChunk(google::protobuf::Value& value, 48 | google::protobuf::Value&& chunk); 49 | 50 | } // namespace internal 51 | } // namespace SPANNER_CLIENT_NS 52 | } // namespace spanner 53 | } // namespace cloud 54 | } // namespace google 55 | 56 | #endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_SPANNER_INTERNAL_MERGE_CHUNK_H 57 | -------------------------------------------------------------------------------- /google/cloud/spanner/internal/partial_result_set_reader.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 | // http://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_INTERNAL_PARTIAL_RESULT_SET_READER_H 16 | #define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_SPANNER_INTERNAL_PARTIAL_RESULT_SET_READER_H 17 | 18 | #include "google/cloud/spanner/version.h" 19 | #include "google/cloud/optional.h" 20 | #include "google/cloud/status.h" 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | namespace google { 27 | namespace cloud { 28 | namespace spanner { 29 | inline namespace SPANNER_CLIENT_NS { 30 | namespace internal { 31 | 32 | /** 33 | * Wrap grpc::ClientReaderInterface. 34 | * 35 | * This defines an interface to handle a streaming RPC returning a sequence of 36 | * `google::spanner::v1::PartialResultSet`. Its main purpose is to simplify 37 | * memory management, as each streaming RPC requires two separate 38 | * `std::unique_ptr<>`. As a side-effect, it is easier to mock this class, as 39 | * it has a narrower interface. 40 | */ 41 | class PartialResultSetReader { 42 | public: 43 | virtual ~PartialResultSetReader() = default; 44 | virtual void TryCancel() = 0; 45 | virtual optional Read() = 0; 46 | virtual Status Finish() = 0; 47 | }; 48 | 49 | } // namespace internal 50 | } // namespace SPANNER_CLIENT_NS 51 | } // namespace spanner 52 | } // namespace cloud 53 | } // namespace google 54 | 55 | #endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_SPANNER_INTERNAL_PARTIAL_RESULT_SET_READER_H 56 | -------------------------------------------------------------------------------- /google/cloud/spanner/internal/partial_result_set_resume.cc: -------------------------------------------------------------------------------- 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 | // http://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 | #include "google/cloud/spanner/internal/partial_result_set_resume.h" 16 | #include 17 | 18 | namespace google { 19 | namespace cloud { 20 | namespace spanner { 21 | inline namespace SPANNER_CLIENT_NS { 22 | namespace internal { 23 | 24 | void PartialResultSetResume::TryCancel() { child_->TryCancel(); } 25 | 26 | optional PartialResultSetResume::Read() { 27 | do { 28 | optional result = child_->Read(); 29 | if (result) { 30 | last_resume_token_ = result->resume_token(); 31 | return result; 32 | } 33 | auto status = Finish(); 34 | if (status.ok()) return {}; 35 | if (is_idempotent_ == Idempotency::kNotIdempotent || 36 | !retry_policy_prototype_->OnFailure(status)) { 37 | return {}; 38 | } 39 | std::this_thread::sleep_for(backoff_policy_prototype_->OnCompletion()); 40 | last_status_.reset(); 41 | child_ = factory_(last_resume_token_); 42 | } while (!retry_policy_prototype_->IsExhausted()); 43 | return {}; 44 | } 45 | 46 | Status PartialResultSetResume::Finish() { 47 | // Finish() can be called only once, so cache the last result. 48 | if (last_status_.has_value()) { 49 | return *last_status_; 50 | } 51 | last_status_ = child_->Finish(); 52 | return *last_status_; 53 | } 54 | 55 | } // namespace internal 56 | } // namespace SPANNER_CLIENT_NS 57 | } // namespace spanner 58 | } // namespace cloud 59 | } // namespace google 60 | -------------------------------------------------------------------------------- /google/cloud/spanner/internal/retry_loop.cc: -------------------------------------------------------------------------------- 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 | // http://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 | #include "google/cloud/spanner/internal/retry_loop.h" 16 | #include 17 | 18 | namespace google { 19 | namespace cloud { 20 | namespace spanner { 21 | inline namespace SPANNER_CLIENT_NS { 22 | namespace internal { 23 | 24 | Status RetryLoopError(char const* loop_message, char const* location, 25 | Status const& last_status) { 26 | std::ostringstream os; 27 | os << loop_message << " " << location << ": " << last_status; 28 | return Status(last_status.code(), std::move(os).str()); 29 | } 30 | 31 | } // namespace internal 32 | } // namespace SPANNER_CLIENT_NS 33 | } // namespace spanner 34 | } // namespace cloud 35 | } // namespace google 36 | -------------------------------------------------------------------------------- /google/cloud/spanner/internal/session.cc: -------------------------------------------------------------------------------- 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 | // http://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 | #include "google/cloud/spanner/internal/session.h" 16 | 17 | namespace google { 18 | namespace cloud { 19 | namespace spanner { 20 | inline namespace SPANNER_CLIENT_NS { 21 | namespace internal { 22 | 23 | SessionHolder MakeDissociatedSessionHolder(std::string session_name) { 24 | return SessionHolder( 25 | new Session(std::move(session_name), /*channel=*/nullptr), 26 | std::default_delete()); 27 | } 28 | 29 | } // namespace internal 30 | } // namespace SPANNER_CLIENT_NS 31 | } // namespace spanner 32 | } // namespace cloud 33 | } // namespace google 34 | -------------------------------------------------------------------------------- /google/cloud/spanner/internal/status_utils.cc: -------------------------------------------------------------------------------- 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 | // http://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 | #include "google/cloud/spanner/internal/status_utils.h" 16 | #include 17 | 18 | namespace google { 19 | namespace cloud { 20 | namespace spanner { 21 | inline namespace SPANNER_CLIENT_NS { 22 | namespace internal { 23 | 24 | bool IsSessionNotFound(google::cloud::Status const& status) { 25 | // "Session not found" in the status message is an API guanantee. 26 | return status.code() == StatusCode::kNotFound && 27 | status.message().find("Session not found") != std::string::npos; 28 | } 29 | 30 | } // namespace internal 31 | } // namespace SPANNER_CLIENT_NS 32 | } // namespace spanner 33 | } // namespace cloud 34 | } // namespace google 35 | -------------------------------------------------------------------------------- /google/cloud/spanner/internal/status_utils.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 | // http://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_INTERNAL_STATUS_UTILS_H 16 | #define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_SPANNER_INTERNAL_STATUS_UTILS_H 17 | 18 | #include "google/cloud/spanner/version.h" 19 | #include "google/cloud/status.h" 20 | 21 | namespace google { 22 | namespace cloud { 23 | namespace spanner { 24 | inline namespace SPANNER_CLIENT_NS { 25 | namespace internal { 26 | 27 | /// Determine if `status` represents a "Session not found" error. 28 | bool IsSessionNotFound(google::cloud::Status const& status); 29 | 30 | } // namespace internal 31 | } // namespace SPANNER_CLIENT_NS 32 | } // namespace spanner 33 | } // namespace cloud 34 | } // namespace google 35 | 36 | #endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_SPANNER_INTERNAL_STATUS_UTILS_H 37 | -------------------------------------------------------------------------------- /google/cloud/spanner/internal/status_utils_test.cc: -------------------------------------------------------------------------------- 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 | // http://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 | #include "google/cloud/spanner/internal/status_utils.h" 16 | #include 17 | 18 | namespace google { 19 | namespace cloud { 20 | namespace spanner { 21 | inline namespace SPANNER_CLIENT_NS { 22 | namespace { 23 | 24 | TEST(StatusUtils, SessionNotFound) { 25 | google::cloud::Status const session_not_found(StatusCode::kNotFound, 26 | "Session not found"); 27 | EXPECT_TRUE(internal::IsSessionNotFound(session_not_found)); 28 | 29 | google::cloud::Status const other_not_found(StatusCode::kNotFound, 30 | "Other not found"); 31 | EXPECT_FALSE(internal::IsSessionNotFound(other_not_found)); 32 | 33 | google::cloud::Status const not_not_found(StatusCode::kUnavailable, 34 | "Session not found"); 35 | EXPECT_FALSE(internal::IsSessionNotFound(not_not_found)); 36 | } 37 | 38 | } // namespace 39 | } // namespace SPANNER_CLIENT_NS 40 | } // namespace spanner 41 | } // namespace cloud 42 | } // namespace google 43 | -------------------------------------------------------------------------------- /google/cloud/spanner/internal/time_utils.h: -------------------------------------------------------------------------------- 1 | // Copyright 2020 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 | // http://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_INTERNAL_TIME_UTILS_H 16 | #define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_SPANNER_INTERNAL_TIME_UTILS_H 17 | 18 | #include "google/cloud/spanner/timestamp.h" 19 | #include "google/cloud/spanner/version.h" 20 | #include "google/cloud/status_or.h" 21 | #include 22 | #include 23 | 24 | namespace google { 25 | namespace cloud { 26 | namespace spanner { 27 | inline namespace SPANNER_CLIENT_NS { 28 | namespace internal { 29 | 30 | template 31 | StatusOr ConvertTimePointToProtoTimestamp( 32 | sys_time time_point) { 33 | auto const ts = MakeTimestamp(time_point); 34 | if (!ts) return std::move(ts).status(); 35 | return TimestampToProto(*ts); 36 | } 37 | 38 | } // namespace internal 39 | } // namespace SPANNER_CLIENT_NS 40 | } // namespace spanner 41 | } // namespace cloud 42 | } // namespace google 43 | 44 | #endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_SPANNER_INTERNAL_TIME_UTILS_H 45 | -------------------------------------------------------------------------------- /google/cloud/spanner/internal/time_utils_test.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2020 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 | // http://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 | #include "google/cloud/spanner/internal/time_utils.h" 16 | #include "google/cloud/testing_util/assert_ok.h" 17 | #include 18 | #include 19 | 20 | namespace google { 21 | namespace cloud { 22 | namespace spanner { 23 | inline namespace SPANNER_CLIENT_NS { 24 | namespace internal { 25 | namespace { 26 | 27 | TEST(TimeUtils, ConvertTimePointToProtoTimestamp) { 28 | auto const epoch = std::chrono::system_clock::from_time_t(0); 29 | auto t = epoch + std::chrono::seconds(123) + std::chrono::nanoseconds(456000); 30 | auto proto_timestamp = ConvertTimePointToProtoTimestamp(t); 31 | EXPECT_STATUS_OK(proto_timestamp); 32 | EXPECT_EQ(123, proto_timestamp->seconds()); 33 | EXPECT_EQ(456000, proto_timestamp->nanos()); 34 | } 35 | 36 | } // namespace 37 | } // namespace internal 38 | } // namespace SPANNER_CLIENT_NS 39 | } // namespace spanner 40 | } // namespace cloud 41 | } // namespace google 42 | -------------------------------------------------------------------------------- /google/cloud/spanner/internal/transaction_impl.cc: -------------------------------------------------------------------------------- 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 | // http://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 | #include "google/cloud/spanner/internal/transaction_impl.h" 16 | 17 | namespace google { 18 | namespace cloud { 19 | namespace spanner { 20 | inline namespace SPANNER_CLIENT_NS { 21 | namespace internal { 22 | 23 | TransactionImpl::~TransactionImpl() = default; 24 | 25 | } // namespace internal 26 | } // namespace SPANNER_CLIENT_NS 27 | } // namespace spanner 28 | } // namespace cloud 29 | } // namespace google 30 | -------------------------------------------------------------------------------- /google/cloud/spanner/mutations.cc: -------------------------------------------------------------------------------- 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 | // http://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 | #include "google/cloud/spanner/mutations.h" 16 | #include 17 | #include 18 | 19 | namespace google { 20 | namespace cloud { 21 | namespace spanner { 22 | inline namespace SPANNER_CLIENT_NS { 23 | 24 | bool operator==(Mutation const& lhs, Mutation const& rhs) { 25 | google::protobuf::util::MessageDifferencer diff; 26 | return diff.Compare(lhs.m_, rhs.m_); 27 | } 28 | 29 | void PrintTo(Mutation const& m, std::ostream* os) { 30 | *os << "Mutation={" << m.m_.DebugString() << "}"; 31 | } 32 | 33 | } // namespace SPANNER_CLIENT_NS 34 | } // namespace spanner 35 | } // namespace cloud 36 | } // namespace google 37 | -------------------------------------------------------------------------------- /google/cloud/spanner/partition_options.cc: -------------------------------------------------------------------------------- 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 | // http://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 | #include "google/cloud/spanner/partition_options.h" 16 | 17 | namespace google { 18 | namespace cloud { 19 | namespace spanner { 20 | inline namespace SPANNER_CLIENT_NS { 21 | 22 | namespace internal { 23 | 24 | google::spanner::v1::PartitionOptions ToProto(PartitionOptions const& po) { 25 | google::spanner::v1::PartitionOptions proto; 26 | if (po.max_partitions) proto.set_max_partitions(*po.max_partitions); 27 | if (po.partition_size_bytes) { 28 | proto.set_partition_size_bytes(*po.partition_size_bytes); 29 | } 30 | return proto; 31 | } 32 | 33 | } // namespace internal 34 | 35 | } // namespace SPANNER_CLIENT_NS 36 | } // namespace spanner 37 | } // namespace cloud 38 | } // namespace google 39 | -------------------------------------------------------------------------------- /google/cloud/spanner/partition_options_test.cc: -------------------------------------------------------------------------------- 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 | // http://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 | #include "google/cloud/spanner/partition_options.h" 16 | #include 17 | 18 | namespace google { 19 | namespace cloud { 20 | namespace spanner { 21 | inline namespace SPANNER_CLIENT_NS { 22 | namespace { 23 | 24 | TEST(PartitionOptionsTest, Regular) { 25 | PartitionOptions a; 26 | PartitionOptions b; 27 | EXPECT_EQ(a, b); 28 | 29 | a.partition_size_bytes = 1; 30 | EXPECT_NE(a, b); 31 | b.partition_size_bytes = 1; 32 | EXPECT_EQ(a, b); 33 | 34 | a.max_partitions = 1; 35 | EXPECT_NE(a, b); 36 | b.max_partitions = 1; 37 | EXPECT_EQ(a, b); 38 | 39 | auto copy = b; 40 | EXPECT_EQ(a, copy); 41 | } 42 | 43 | TEST(PartitionOptionsTest, Proto) { 44 | PartitionOptions po{1, 2}; 45 | auto proto = internal::ToProto(po); 46 | EXPECT_EQ(*po.partition_size_bytes, proto.partition_size_bytes()); 47 | EXPECT_EQ(*po.max_partitions, proto.max_partitions()); 48 | } 49 | 50 | } // namespace 51 | } // namespace SPANNER_CLIENT_NS 52 | } // namespace spanner 53 | } // namespace cloud 54 | } // namespace google 55 | -------------------------------------------------------------------------------- /google/cloud/spanner/partitioned_dml_result.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 | // http://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_PARTITIONED_DML_RESULT_H 16 | #define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_SPANNER_PARTITIONED_DML_RESULT_H 17 | 18 | #include "google/cloud/spanner/timestamp.h" 19 | #include "google/cloud/spanner/version.h" 20 | 21 | namespace google { 22 | namespace cloud { 23 | namespace spanner { 24 | inline namespace SPANNER_CLIENT_NS { 25 | 26 | /** 27 | * The result of executing a Partitioned DML query. 28 | */ 29 | struct PartitionedDmlResult { 30 | /// A lower bound on the number of rows modified. 31 | std::int64_t row_count_lower_bound; 32 | }; 33 | 34 | } // namespace SPANNER_CLIENT_NS 35 | } // namespace spanner 36 | } // namespace cloud 37 | } // namespace google 38 | 39 | #endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_SPANNER_PARTITIONED_DML_RESULT_H 40 | -------------------------------------------------------------------------------- /google/cloud/spanner/query_options_test.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2020 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 | // http://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 | #include "google/cloud/spanner/query_options.h" 16 | #include "google/cloud/spanner/version.h" 17 | #include 18 | 19 | namespace google { 20 | namespace cloud { 21 | namespace spanner { 22 | inline namespace SPANNER_CLIENT_NS { 23 | namespace { 24 | 25 | TEST(QueryOptionsTest, OptimizerVersion) { 26 | QueryOptions const default_constructed{}; 27 | EXPECT_FALSE(default_constructed.optimizer_version().has_value()); 28 | 29 | auto copy = default_constructed; 30 | EXPECT_EQ(copy, default_constructed); 31 | 32 | copy.set_optimizer_version(""); 33 | EXPECT_NE(copy, default_constructed); 34 | copy.set_optimizer_version("foo"); 35 | EXPECT_NE(copy, default_constructed); 36 | 37 | copy.set_optimizer_version(optional{}); 38 | EXPECT_EQ(copy, default_constructed); 39 | } 40 | 41 | } // namespace 42 | } // namespace SPANNER_CLIENT_NS 43 | } // namespace spanner 44 | } // namespace cloud 45 | } // namespace google 46 | -------------------------------------------------------------------------------- /google/cloud/spanner/quickstart/BUILD: -------------------------------------------------------------------------------- 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 | # http://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 | licenses(["notice"]) # Apache 2.0 16 | 17 | cc_binary( 18 | name = "quickstart", 19 | srcs = [ 20 | "quickstart.cc", 21 | ], 22 | deps = [ 23 | "@com_github_googleapis_google_cloud_cpp_spanner//:spanner_client", 24 | ], 25 | ) 26 | -------------------------------------------------------------------------------- /google/cloud/spanner/quickstart/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); you may not 4 | # use this file except in compliance with the License. You may obtain a copy of 5 | # the License at 6 | # 7 | # http://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, WITHOUT 11 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 | # License for the specific language governing permissions and limitations under 13 | # the License. 14 | 15 | # This CMake file shows how to use `google-cloud-cpp-spanner` from a larger 16 | # CMake project. 17 | 18 | cmake_minimum_required(VERSION 3.5) 19 | project(google-cloud-cpp-spanner-quickstart CXX C) 20 | 21 | # In this example we only require C++11, you can use newer versions in your own 22 | # project: 23 | set(CMAKE_CXX_STANDARD 11) 24 | set(CMAKE_CXX_STANDARD_REQUIRED ON) 25 | 26 | # Use find_package() to find a pre-installed version of google-cloud-cpp- 27 | # spanner: 28 | find_package(spanner_client REQUIRED) 29 | 30 | # MSVC requires some additional code to select the correct runtime library 31 | if (VCPKG_TARGET_TRIPLET MATCHES "-static$") 32 | set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>") 33 | else () 34 | set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>DLL") 35 | endif () 36 | 37 | # Define your targets. 38 | add_executable(quickstart quickstart.cc) 39 | target_link_libraries(quickstart googleapis-c++::spanner_client) 40 | -------------------------------------------------------------------------------- /google/cloud/spanner/quickstart/quickstart.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2020 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 | // http://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 | #include "google/cloud/spanner/client.h" 16 | #include 17 | #include 18 | 19 | int main(int argc, char* argv[]) try { 20 | if (argc != 4) { 21 | std::cerr << "Usage: " << argv[0] 22 | << " project-id instance-id database-id\n"; 23 | return 1; 24 | } 25 | 26 | namespace spanner = ::google::cloud::spanner; 27 | spanner::Client client( 28 | spanner::MakeConnection(spanner::Database(argv[1], argv[2], argv[3]))); 29 | 30 | auto rows = 31 | client.ExecuteQuery(spanner::SqlStatement("SELECT 'Hello World'")); 32 | 33 | for (auto const& row : spanner::StreamOf>(rows)) { 34 | if (!row) throw std::runtime_error(row.status().message()); 35 | std::cout << std::get<0>(*row) << "\n"; 36 | } 37 | 38 | return 0; 39 | } catch (std::exception const& ex) { 40 | std::cerr << "Standard exception raised: " << ex.what() << "\n"; 41 | return 1; 42 | } 43 | -------------------------------------------------------------------------------- /google/cloud/spanner/read_options.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 | // http://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_READ_OPTIONS_H 16 | #define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_SPANNER_READ_OPTIONS_H 17 | 18 | #include "google/cloud/spanner/version.h" 19 | #include 20 | #include 21 | 22 | namespace google { 23 | namespace cloud { 24 | namespace spanner { 25 | inline namespace SPANNER_CLIENT_NS { 26 | 27 | /// Options passed to `Client::Read` or `Client::PartitionRead`. 28 | struct ReadOptions { 29 | /** 30 | * If non-empty, the name of an index on a database table. This index is used 31 | * instead of the table primary key when interpreting the `KeySet`and sorting 32 | * result rows. 33 | */ 34 | std::string index_name; 35 | 36 | /** 37 | * Limit on the number of rows to yield, or 0 for no limit. 38 | * A limit cannot be specified when calling `PartitionRead`. 39 | */ 40 | std::int64_t limit = 0; 41 | }; 42 | 43 | inline bool operator==(ReadOptions const& lhs, ReadOptions const& rhs) { 44 | return lhs.limit == rhs.limit && lhs.index_name == rhs.index_name; 45 | } 46 | 47 | inline bool operator!=(ReadOptions const& lhs, ReadOptions const& rhs) { 48 | return !(lhs == rhs); 49 | } 50 | 51 | } // namespace SPANNER_CLIENT_NS 52 | } // namespace spanner 53 | } // namespace cloud 54 | } // namespace google 55 | 56 | #endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_SPANNER_READ_OPTIONS_H 57 | -------------------------------------------------------------------------------- /google/cloud/spanner/read_options_test.cc: -------------------------------------------------------------------------------- 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 | // http://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 | #include "google/cloud/spanner/read_options.h" 16 | #include 17 | 18 | namespace google { 19 | namespace cloud { 20 | namespace spanner { 21 | inline namespace SPANNER_CLIENT_NS { 22 | namespace { 23 | 24 | TEST(ReadOptionsTest, Equality) { 25 | ReadOptions test_options_0{}; 26 | ReadOptions test_options_1{}; 27 | EXPECT_EQ(test_options_0, test_options_1); 28 | test_options_0.index_name = "secondary"; 29 | EXPECT_NE(test_options_0, test_options_1); 30 | test_options_1.index_name = "secondary"; 31 | EXPECT_EQ(test_options_0, test_options_1); 32 | test_options_0.limit = 42; 33 | EXPECT_NE(test_options_0, test_options_1); 34 | test_options_1.limit = 42; 35 | EXPECT_EQ(test_options_0, test_options_1); 36 | test_options_1 = test_options_0; 37 | EXPECT_EQ(test_options_0, test_options_1); 38 | } 39 | 40 | } // namespace 41 | } // namespace SPANNER_CLIENT_NS 42 | } // namespace spanner 43 | } // namespace cloud 44 | } // namespace google 45 | -------------------------------------------------------------------------------- /google/cloud/spanner/samples/BUILD: -------------------------------------------------------------------------------- 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 | # http://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 | """Examples for the Cloud Spanner C++ client library.""" 16 | 17 | package(default_visibility = ["//visibility:public"]) 18 | 19 | licenses(["notice"]) # Apache 2.0 20 | 21 | load(":spanner_client_integration_samples.bzl", "spanner_client_integration_samples") 22 | load(":spanner_client_unit_samples.bzl", "spanner_client_unit_samples") 23 | 24 | [cc_test( 25 | name = test.replace("/", "_").replace(".cc", ""), 26 | timeout = "long", 27 | srcs = [test], 28 | tags = [ 29 | "integration-tests", 30 | "spanner-integration-tests", 31 | ], 32 | deps = [ 33 | "//google/cloud/spanner:spanner_client", 34 | "//google/cloud/spanner:spanner_client_testing", 35 | "@com_github_googleapis_google_cloud_cpp_common//google/cloud:google_cloud_cpp_common", 36 | "@com_github_googleapis_google_cloud_cpp_common//google/cloud/testing_util:google_cloud_cpp_testing", 37 | "@com_google_googletest//:gtest_main", 38 | ], 39 | ) for test in spanner_client_integration_samples] 40 | 41 | [cc_test( 42 | name = test.replace("/", "_").replace(".cc", ""), 43 | srcs = [test], 44 | deps = [ 45 | "//google/cloud/spanner:spanner_client", 46 | "//google/cloud/spanner:spanner_client_testing", 47 | "@com_github_googleapis_google_cloud_cpp_common//google/cloud:google_cloud_cpp_common", 48 | "@com_github_googleapis_google_cloud_cpp_common//google/cloud/testing_util:google_cloud_cpp_testing", 49 | "@com_google_googletest//:gtest_main", 50 | ], 51 | ) for test in spanner_client_unit_samples] 52 | -------------------------------------------------------------------------------- /google/cloud/spanner/samples/spanner_client_integration_samples.bzl: -------------------------------------------------------------------------------- 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 | # http://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 | # DO NOT EDIT -- GENERATED BY CMake -- Change the CMakeLists.txt file if needed 16 | 17 | """Automatically generated unit tests list - DO NOT EDIT.""" 18 | 19 | spanner_client_integration_samples = [ 20 | "samples.cc", 21 | ] 22 | -------------------------------------------------------------------------------- /google/cloud/spanner/samples/spanner_client_unit_samples.bzl: -------------------------------------------------------------------------------- 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 | # http://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 | # DO NOT EDIT -- GENERATED BY CMake -- Change the CMakeLists.txt file if needed 16 | 17 | """Automatically generated unit tests list - DO NOT EDIT.""" 18 | 19 | spanner_client_unit_samples = [ 20 | "mock_execute_query.cc", 21 | ] 22 | -------------------------------------------------------------------------------- /google/cloud/spanner/session_pool_options_test.cc: -------------------------------------------------------------------------------- 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 | // http://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 | #include "google/cloud/spanner/session_pool_options.h" 16 | #include "google/cloud/spanner/version.h" 17 | #include 18 | 19 | namespace google { 20 | namespace cloud { 21 | namespace spanner { 22 | inline namespace SPANNER_CLIENT_NS { 23 | namespace { 24 | 25 | TEST(SessionPoolOptionsTest, MinSessions) { 26 | SessionPoolOptions options; 27 | options.set_min_sessions(-1).EnforceConstraints(/*num_channels=*/1); 28 | EXPECT_EQ(0, options.min_sessions()); 29 | } 30 | 31 | TEST(SessionPoolOptionsTest, MaxSessionsPerChannel) { 32 | SessionPoolOptions options; 33 | options.set_max_sessions_per_channel(0).EnforceConstraints( 34 | /*num_channels=*/1); 35 | EXPECT_EQ(1, options.max_sessions_per_channel()); 36 | } 37 | 38 | TEST(SessionPoolOptionsTest, MaxIdleSessions) { 39 | SessionPoolOptions options; 40 | options.set_max_idle_sessions(-1).EnforceConstraints( 41 | /*num_channels=*/1); 42 | EXPECT_EQ(0, options.max_idle_sessions()); 43 | } 44 | 45 | TEST(SessionPoolOptionsTest, MaxMinSessionsConflict) { 46 | SessionPoolOptions options; 47 | options.set_min_sessions(10) 48 | .set_max_sessions_per_channel(2) 49 | .EnforceConstraints(/*num_channels=*/3); 50 | EXPECT_EQ(6, options.min_sessions()); 51 | EXPECT_EQ(2, options.max_sessions_per_channel()); 52 | } 53 | 54 | } // namespace 55 | } // namespace SPANNER_CLIENT_NS 56 | } // namespace spanner 57 | } // namespace cloud 58 | } // namespace google 59 | -------------------------------------------------------------------------------- /google/cloud/spanner/spanner_client_benchmarks.bzl: -------------------------------------------------------------------------------- 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 | # http://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 | # DO NOT EDIT -- GENERATED BY CMake -- Change the CMakeLists.txt file if needed 16 | 17 | """Automatically generated unit tests list - DO NOT EDIT.""" 18 | 19 | spanner_client_benchmarks = [ 20 | "bytes_benchmark.cc", 21 | "internal/date_benchmark.cc", 22 | "internal/merge_chunk_benchmark.cc", 23 | "internal/time_format_benchmark.cc", 24 | "row_benchmark.cc", 25 | ] 26 | -------------------------------------------------------------------------------- /google/cloud/spanner/spanner_client_mocks.bzl: -------------------------------------------------------------------------------- 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 | # http://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 | # DO NOT EDIT -- GENERATED BY CMake -- Change the CMakeLists.txt file if needed 16 | 17 | """Automatically generated source lists for spanner_client_mocks - DO NOT EDIT.""" 18 | 19 | spanner_client_mocks_hdrs = [ 20 | "mocks/mock_database_admin_connection.h", 21 | "mocks/mock_instance_admin_connection.h", 22 | "mocks/mock_spanner_connection.h", 23 | ] 24 | 25 | spanner_client_mocks_srcs = [ 26 | ] 27 | -------------------------------------------------------------------------------- /google/cloud/spanner/spanner_client_testing.bzl: -------------------------------------------------------------------------------- 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 | # http://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 | # DO NOT EDIT -- GENERATED BY CMake -- Change the CMakeLists.txt file if needed 16 | 17 | """Automatically generated source lists for spanner_client_testing - DO NOT EDIT.""" 18 | 19 | spanner_client_testing_hdrs = [ 20 | "testing/cleanup_stale_instances.h", 21 | "testing/compiler_supports_regexp.h", 22 | "testing/database_integration_test.h", 23 | "testing/fake_clock.h", 24 | "testing/matchers.h", 25 | "testing/mock_database_admin_stub.h", 26 | "testing/mock_instance_admin_stub.h", 27 | "testing/mock_partial_result_set_reader.h", 28 | "testing/mock_spanner_stub.h", 29 | "testing/pick_instance_config.h", 30 | "testing/pick_random_instance.h", 31 | "testing/policies.h", 32 | "testing/random_backup_name.h", 33 | "testing/random_database_name.h", 34 | "testing/random_instance_name.h", 35 | "testing/validate_metadata.h", 36 | ] 37 | 38 | spanner_client_testing_srcs = [ 39 | "testing/cleanup_stale_instances.cc", 40 | "testing/database_integration_test.cc", 41 | "testing/pick_instance_config.cc", 42 | "testing/pick_random_instance.cc", 43 | "testing/random_backup_name.cc", 44 | "testing/random_database_name.cc", 45 | "testing/random_instance_name.cc", 46 | "testing/validate_metadata.cc", 47 | ] 48 | -------------------------------------------------------------------------------- /google/cloud/spanner/testing/cleanup_stale_instances.h: -------------------------------------------------------------------------------- 1 | // Copyright 2020 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 | // http://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_TESTING_CLEANUP_STALE_INSTANCES_H 16 | #define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_SPANNER_TESTING_CLEANUP_STALE_INSTANCES_H 17 | 18 | #include "google/cloud/spanner/version.h" 19 | #include "google/cloud/status.h" 20 | #include 21 | #include 22 | 23 | namespace google { 24 | namespace cloud { 25 | namespace spanner_testing { 26 | inline namespace SPANNER_CLIENT_NS { 27 | Status CleanupStaleInstances(std::string const& project_id, 28 | std::regex const& instance_name_regex); 29 | 30 | } // namespace SPANNER_CLIENT_NS 31 | } // namespace spanner_testing 32 | } // namespace cloud 33 | } // namespace google 34 | 35 | #endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_SPANNER_TESTING_CLEANUP_STALE_INSTANCES_H 36 | -------------------------------------------------------------------------------- /google/cloud/spanner/testing/compiler_supports_regexp.h: -------------------------------------------------------------------------------- 1 | // Copyright 2020 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 | // http://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_TESTING_COMPILER_SUPPORTS_REGEXP_H 16 | #define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_SPANNER_TESTING_COMPILER_SUPPORTS_REGEXP_H 17 | 18 | #include "google/cloud/spanner/version.h" 19 | 20 | namespace google { 21 | namespace cloud { 22 | namespace spanner_testing { 23 | inline namespace SPANNER_CLIENT_NS { 24 | inline bool CompilerSupportsRegexp() { 25 | #if !defined(__clang__) && defined(__GNUC__) && \ 26 | (__GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 9)) 27 | // gcc-4.8 ships with a broken regexp library, it compiles, but does not match 28 | // correctly: 29 | // https://stackoverflow.com/questions/12530406/is-gcc-4-8-or-earlier-buggy-about-regular-expressions 30 | return false; 31 | #else 32 | return true; 33 | #endif 34 | } 35 | 36 | } // namespace SPANNER_CLIENT_NS 37 | } // namespace spanner_testing 38 | } // namespace cloud 39 | } // namespace google 40 | 41 | #endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_SPANNER_TESTING_COMPILER_SUPPORTS_REGEXP_H 42 | -------------------------------------------------------------------------------- /google/cloud/spanner/testing/database_integration_test.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 | // http://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_TESTING_DATABASE_INTEGRATION_TEST_H 16 | #define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_SPANNER_TESTING_DATABASE_INTEGRATION_TEST_H 17 | 18 | #include "google/cloud/spanner/database.h" 19 | #include "google/cloud/spanner/version.h" 20 | #include "google/cloud/internal/random.h" 21 | #include 22 | 23 | namespace google { 24 | namespace cloud { 25 | /// Helper types and functions used in Cloud Spanner C++ client library tests. 26 | namespace spanner_testing { 27 | /// An inlined, versioned namespace for the testing helpers. 28 | inline namespace SPANNER_CLIENT_NS { 29 | 30 | class DatabaseIntegrationTest : public ::testing::Test { 31 | public: 32 | static void SetUpTestSuite(); 33 | static void TearDownTestSuite(); 34 | 35 | static google::cloud::spanner::Database const& GetDatabase() { return *db_; } 36 | 37 | private: 38 | static google::cloud::spanner::Database* db_; 39 | static google::cloud::internal::DefaultPRNG* generator_; 40 | }; 41 | 42 | } // namespace SPANNER_CLIENT_NS 43 | } // namespace spanner_testing 44 | } // namespace cloud 45 | } // namespace google 46 | 47 | #endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_SPANNER_TESTING_DATABASE_INTEGRATION_TEST_H 48 | -------------------------------------------------------------------------------- /google/cloud/spanner/testing/mock_partial_result_set_reader.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 | // http://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_TESTING_MOCK_PARTIAL_RESULT_SET_READER_H 16 | #define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_SPANNER_TESTING_MOCK_PARTIAL_RESULT_SET_READER_H 17 | 18 | #include "google/cloud/spanner/internal/partial_result_set_reader.h" 19 | #include "google/cloud/spanner/version.h" 20 | #include 21 | 22 | namespace google { 23 | namespace cloud { 24 | namespace spanner_testing { 25 | inline namespace SPANNER_CLIENT_NS { 26 | 27 | class MockPartialResultSetReader 28 | : public spanner::internal::PartialResultSetReader { 29 | public: 30 | MOCK_METHOD0(TryCancel, void()); 31 | MOCK_METHOD0(Read, optional()); 32 | MOCK_METHOD0(Finish, Status()); 33 | }; 34 | 35 | } // namespace SPANNER_CLIENT_NS 36 | } // namespace spanner_testing 37 | } // namespace cloud 38 | } // namespace google 39 | 40 | #endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_SPANNER_TESTING_MOCK_PARTIAL_RESULT_SET_READER_H 41 | -------------------------------------------------------------------------------- /google/cloud/spanner/testing/pick_instance_config.h: -------------------------------------------------------------------------------- 1 | // Copyright 2020 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 | // http://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_TESTING_PICK_INSTANCE_CONFIG_H 16 | #define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_SPANNER_TESTING_PICK_INSTANCE_CONFIG_H 17 | 18 | #include "google/cloud/spanner/instance_admin_client.h" 19 | #include "google/cloud/spanner/version.h" 20 | #include "google/cloud/internal/random.h" 21 | #include 22 | 23 | namespace google { 24 | namespace cloud { 25 | namespace spanner_testing { 26 | inline namespace SPANNER_CLIENT_NS { 27 | 28 | /// Pick one instance_config from a list given a PRNG generator, project_id, 29 | /// and a regex for filtering, if none matches the filter, it will return the 30 | /// value for the first element. 31 | std::string PickInstanceConfig(std::string const& project_id, 32 | std::regex const& filter_regex, 33 | google::cloud::internal::DefaultPRNG& generator); 34 | 35 | } // namespace SPANNER_CLIENT_NS 36 | } // namespace spanner_testing 37 | } // namespace cloud 38 | } // namespace google 39 | 40 | #endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_SPANNER_TESTING_PICK_INSTANCE_CONFIG_H 41 | -------------------------------------------------------------------------------- /google/cloud/spanner/testing/pick_random_instance.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 | // http://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_TESTING_PICK_RANDOM_INSTANCE_H 16 | #define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_SPANNER_TESTING_PICK_RANDOM_INSTANCE_H 17 | 18 | #include "google/cloud/spanner/version.h" 19 | #include "google/cloud/internal/random.h" 20 | #include "google/cloud/status_or.h" 21 | #include 22 | 23 | namespace google { 24 | namespace cloud { 25 | namespace spanner_testing { 26 | inline namespace SPANNER_CLIENT_NS { 27 | /// Select one of the instances in @p project_id to run the tests on. 28 | StatusOr PickRandomInstance( 29 | google::cloud::internal::DefaultPRNG& generator, 30 | std::string const& project_id); 31 | 32 | } // namespace SPANNER_CLIENT_NS 33 | } // namespace spanner_testing 34 | } // namespace cloud 35 | } // namespace google 36 | 37 | #endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_SPANNER_TESTING_PICK_RANDOM_INSTANCE_H 38 | -------------------------------------------------------------------------------- /google/cloud/spanner/testing/random_backup_name.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2020 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 | // http://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 | #include "google/cloud/spanner/testing/random_backup_name.h" 16 | 17 | namespace google { 18 | namespace cloud { 19 | namespace spanner_testing { 20 | inline namespace SPANNER_CLIENT_NS { 21 | std::string RandomBackupName(google::cloud::internal::DefaultPRNG& generator) { 22 | // A backup ID must be between 2 and 60 characters, fitting the regular 23 | // expression `[a-z][a-z0-9_\-]*[a-z0-9]` 24 | std::size_t const max_size = 60; 25 | std::string const prefix = "backup-"; 26 | auto size = static_cast(max_size - 1 - prefix.size()); 27 | return prefix + 28 | google::cloud::internal::Sample( 29 | generator, size, "abcdefghijlkmnopqrstuvwxyz012345689_-") + 30 | google::cloud::internal::Sample( 31 | generator, 1, "abcdefghijlkmnopqrstuvwxyz0123456789"); 32 | } 33 | 34 | } // namespace SPANNER_CLIENT_NS 35 | } // namespace spanner_testing 36 | } // namespace cloud 37 | } // namespace google 38 | -------------------------------------------------------------------------------- /google/cloud/spanner/testing/random_backup_name.h: -------------------------------------------------------------------------------- 1 | // Copyright 2020 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 | // http://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_TESTING_RANDOM_BACKUP_NAME_H 16 | #define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_SPANNER_TESTING_RANDOM_BACKUP_NAME_H 17 | 18 | #include "google/cloud/spanner/version.h" 19 | #include "google/cloud/internal/random.h" 20 | #include 21 | 22 | namespace google { 23 | namespace cloud { 24 | namespace spanner_testing { 25 | inline namespace SPANNER_CLIENT_NS { 26 | 27 | /// Create a random backup name given a PRNG generator. 28 | std::string RandomBackupName(google::cloud::internal::DefaultPRNG& generator); 29 | 30 | } // namespace SPANNER_CLIENT_NS 31 | } // namespace spanner_testing 32 | } // namespace cloud 33 | } // namespace google 34 | 35 | #endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_SPANNER_TESTING_RANDOM_BACKUP_NAME_H 36 | -------------------------------------------------------------------------------- /google/cloud/spanner/testing/random_database_name.cc: -------------------------------------------------------------------------------- 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 | // http://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 | #include "google/cloud/spanner/testing/random_database_name.h" 16 | 17 | namespace google { 18 | namespace cloud { 19 | namespace spanner_testing { 20 | inline namespace SPANNER_CLIENT_NS { 21 | std::string RandomDatabaseName( 22 | google::cloud::internal::DefaultPRNG& generator) { 23 | // A database ID must be between 2 and 30 characters, fitting the regular 24 | // expression `[a-z][a-z0-9_\-]*[a-z0-9]` 25 | std::size_t const max_size = 30; 26 | std::string const prefix = "db-"; 27 | auto size = static_cast(max_size - 1 - prefix.size()); 28 | return prefix + 29 | google::cloud::internal::Sample( 30 | generator, size, "abcdefghijlkmnopqrstuvwxyz012345689_-") + 31 | google::cloud::internal::Sample( 32 | generator, 1, "abcdefghijlkmnopqrstuvwxyz0123456789"); 33 | } 34 | 35 | } // namespace SPANNER_CLIENT_NS 36 | } // namespace spanner_testing 37 | } // namespace cloud 38 | } // namespace google 39 | -------------------------------------------------------------------------------- /google/cloud/spanner/testing/random_database_name.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 | // http://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_TESTING_RANDOM_DATABASE_NAME_H 16 | #define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_SPANNER_TESTING_RANDOM_DATABASE_NAME_H 17 | 18 | #include "google/cloud/spanner/version.h" 19 | #include "google/cloud/internal/random.h" 20 | #include 21 | 22 | namespace google { 23 | namespace cloud { 24 | namespace spanner_testing { 25 | inline namespace SPANNER_CLIENT_NS { 26 | 27 | /// Create a random database name given a PRNG generator. 28 | std::string RandomDatabaseName(google::cloud::internal::DefaultPRNG& generator); 29 | 30 | } // namespace SPANNER_CLIENT_NS 31 | } // namespace spanner_testing 32 | } // namespace cloud 33 | } // namespace google 34 | 35 | #endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_SPANNER_TESTING_RANDOM_DATABASE_NAME_H 36 | -------------------------------------------------------------------------------- /google/cloud/spanner/testing/random_instance_name.cc: -------------------------------------------------------------------------------- 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 | // http://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 | #include "google/cloud/spanner/testing/random_instance_name.h" 16 | #include 17 | #include 18 | 19 | namespace google { 20 | namespace cloud { 21 | namespace spanner_testing { 22 | inline namespace SPANNER_CLIENT_NS { 23 | /** 24 | * Generate a random instance name for InstanceAdminClient CRUD tests. 25 | */ 26 | std::string RandomInstanceName( 27 | google::cloud::internal::DefaultPRNG& generator) { 28 | // An instance ID must be between 2 and 64 characters, fitting the regular 29 | // expression `[a-z][-a-z0-9]*[a-z0-9]` 30 | std::size_t const max_size = 64; 31 | auto now = std::chrono::system_clock::now(); 32 | auto time_t = std::chrono::system_clock::to_time_t(now); 33 | std::string date = "1973-03-01"; 34 | std::strftime(&date[0], date.size() + 1, "%Y-%m-%d", std::localtime(&time_t)); 35 | std::string prefix = "temporary-instance-" + date + "-"; 36 | auto size = static_cast(max_size - 1 - prefix.size()); 37 | return prefix + 38 | google::cloud::internal::Sample( 39 | generator, size, "abcdefghijlkmnopqrstuvwxyz012345689-") + 40 | google::cloud::internal::Sample(generator, 1, 41 | "abcdefghijlkmnopqrstuvwxyz"); 42 | } 43 | 44 | } // namespace SPANNER_CLIENT_NS 45 | } // namespace spanner_testing 46 | } // namespace cloud 47 | } // namespace google 48 | -------------------------------------------------------------------------------- /google/cloud/spanner/testing/random_instance_name.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 | // http://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_TESTING_RANDOM_INSTANCE_NAME_H 16 | #define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_SPANNER_TESTING_RANDOM_INSTANCE_NAME_H 17 | 18 | #include "google/cloud/spanner/version.h" 19 | #include "google/cloud/internal/random.h" 20 | #include 21 | 22 | namespace google { 23 | namespace cloud { 24 | namespace spanner_testing { 25 | inline namespace SPANNER_CLIENT_NS { 26 | 27 | /// Create a random instance name given a PRNG generator. 28 | std::string RandomInstanceName(google::cloud::internal::DefaultPRNG& generator); 29 | 30 | } // namespace SPANNER_CLIENT_NS 31 | } // namespace spanner_testing 32 | } // namespace cloud 33 | } // namespace google 34 | 35 | #endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_SPANNER_TESTING_RANDOM_INSTANCE_NAME_H 36 | -------------------------------------------------------------------------------- /google/cloud/spanner/tracing_options.h: -------------------------------------------------------------------------------- 1 | // Copyright 2020 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 | // http://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_TRACING_OPTIONS_H 16 | #define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_SPANNER_TRACING_OPTIONS_H 17 | 18 | #include "google/cloud/spanner/version.h" 19 | #include "google/cloud/tracing_options.h" 20 | 21 | namespace google { 22 | namespace cloud { 23 | namespace spanner { 24 | inline namespace SPANNER_CLIENT_NS { 25 | 26 | /** 27 | * The configuration parameters for RPC/protobuf tracing. 28 | * 29 | * The default options are: 30 | * single_line_mode=on 31 | * use_short_repeated_primitives=on 32 | * truncate_string_field_longer_than=128 33 | */ 34 | using TracingOptions = google::cloud::TracingOptions; 35 | 36 | } // namespace SPANNER_CLIENT_NS 37 | } // namespace spanner 38 | } // namespace cloud 39 | } // namespace google 40 | 41 | #endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_SPANNER_TRACING_OPTIONS_H 42 | -------------------------------------------------------------------------------- /google/cloud/spanner/version.cc: -------------------------------------------------------------------------------- 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 | // http://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 | #include "google/cloud/spanner/version.h" 16 | #include "google/cloud/spanner/internal/build_info.h" 17 | #include "google/cloud/internal/build_info.h" 18 | #include 19 | 20 | namespace google { 21 | namespace cloud { 22 | namespace spanner { 23 | inline namespace SPANNER_CLIENT_NS { 24 | std::string VersionString() { 25 | static std::string const kVersion = [] { 26 | std::ostringstream os; 27 | os << "v" << VersionMajor() << "." << VersionMinor() << "." 28 | << VersionPatch(); 29 | auto metadata = internal::BuildMetadata(); 30 | if (!metadata.empty()) { 31 | os << "+" << metadata; 32 | } 33 | return os.str(); 34 | }(); 35 | return kVersion; 36 | } 37 | } // namespace SPANNER_CLIENT_NS 38 | } // namespace spanner 39 | } // namespace cloud 40 | } // namespace google 41 | -------------------------------------------------------------------------------- /google/cloud/spanner/version_info.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 | // http://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_VERSION_INFO_H 16 | #define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_SPANNER_VERSION_INFO_H 17 | 18 | #define SPANNER_CLIENT_VERSION_MAJOR 1 19 | #define SPANNER_CLIENT_VERSION_MINOR 3 20 | #define SPANNER_CLIENT_VERSION_PATCH 0 21 | 22 | #endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_SPANNER_VERSION_INFO_H 23 | -------------------------------------------------------------------------------- /google/cloud/spanner/version_info.h.in: -------------------------------------------------------------------------------- 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 | // http://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_VERSION_INFO_H 16 | #define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_SPANNER_VERSION_INFO_H 17 | 18 | #define SPANNER_CLIENT_VERSION_MAJOR @GOOGLE_CLOUD_CPP_VERSION_MAJOR@ 19 | #define SPANNER_CLIENT_VERSION_MINOR @GOOGLE_CLOUD_CPP_VERSION_MINOR@ 20 | #define SPANNER_CLIENT_VERSION_PATCH @GOOGLE_CLOUD_CPP_VERSION_PATCH@ 21 | 22 | #endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_SPANNER_VERSION_INFO_H 23 | -------------------------------------------------------------------------------- /super/external/benchmark.cmake: -------------------------------------------------------------------------------- 1 | # ~~~ 2 | # Copyright 2020 Google LLC 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # ~~~ 16 | 17 | include(ExternalProjectHelper) 18 | 19 | if (NOT TARGET benchmark-project) 20 | # Give application developers a hook to configure the version and hash 21 | # downloaded from GitHub. 22 | set(GOOGLE_CLOUD_CPP_BENCHMARK_URL 23 | "https://github.com/google/benchmark/archive/v1.5.0.tar.gz") 24 | set(GOOGLE_CLOUD_CPP_BENCHMARK_SHA256 25 | "3c6a165b6ecc948967a1ead710d4a181d7b0fbcaa183ef7ea84604994966221a") 26 | 27 | set_external_project_build_parallel_level(PARALLEL) 28 | set_external_project_vars() 29 | 30 | include(ExternalProject) 31 | ExternalProject_Add( 32 | benchmark-project 33 | EXCLUDE_FROM_ALL ON 34 | PREFIX "${CMAKE_BINARY_DIR}/external/benchmark" 35 | INSTALL_DIR "${GOOGLE_CLOUD_CPP_EXTERNAL_PREFIX}" 36 | URL ${GOOGLE_CLOUD_CPP_BENCHMARK_URL} 37 | URL_HASH SHA256=${GOOGLE_CLOUD_CPP_BENCHMARK_SHA256} 38 | LIST_SEPARATOR | 39 | CMAKE_ARGS ${GOOGLE_CLOUD_CPP_EXTERNAL_PROJECT_CMAKE_FLAGS} 40 | -DCMAKE_PREFIX_PATH=${GOOGLE_CLOUD_CPP_PREFIX_PATH} 41 | -DCMAKE_INSTALL_RPATH=${GOOGLE_CLOUD_CPP_INSTALL_RPATH} 42 | -DCMAKE_INSTALL_PREFIX= 43 | -DBENCHMARK_ENABLE_TESTING=OFF 44 | BUILD_COMMAND ${CMAKE_COMMAND} --build ${PARALLEL} 45 | LOG_DOWNLOAD ON 46 | LOG_CONFIGURE ON 47 | LOG_BUILD ON 48 | LOG_INSTALL ON) 49 | endif () 50 | -------------------------------------------------------------------------------- /super/external/c-ares.cmake: -------------------------------------------------------------------------------- 1 | # ~~~ 2 | # Copyright 2019 Google LLC 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # ~~~ 16 | 17 | include(ExternalProjectHelper) 18 | 19 | if (NOT TARGET c-ares-project) 20 | # Give application developers a hook to configure the version and hash 21 | # downloaded from GitHub. 22 | set(GOOGLE_CLOUD_CPP_C_ARES_URL 23 | "https://github.com/c-ares/c-ares/archive/cares-1_14_0.tar.gz") 24 | set(GOOGLE_CLOUD_CPP_C_ARES_SHA256 25 | "62dd12f0557918f89ad6f5b759f0bf4727174ae9979499f5452c02be38d9d3e8") 26 | 27 | set_external_project_build_parallel_level(PARALLEL) 28 | set_external_project_vars() 29 | 30 | include(ExternalProject) 31 | ExternalProject_Add( 32 | c-ares-project 33 | EXCLUDE_FROM_ALL ON 34 | PREFIX "${CMAKE_BINARY_DIR}/external/c-ares" 35 | INSTALL_DIR "${GOOGLE_CLOUD_CPP_EXTERNAL_PREFIX}" 36 | URL ${GOOGLE_CLOUD_CPP_C_ARES_URL} 37 | URL_HASH SHA256=${GOOGLE_CLOUD_CPP_C_ARES_SHA256} 38 | LIST_SEPARATOR | 39 | CMAKE_ARGS ${GOOGLE_CLOUD_CPP_EXTERNAL_PROJECT_CMAKE_FLAGS} 40 | -DCMAKE_PREFIX_PATH=${GOOGLE_CLOUD_CPP_PREFIX_PATH} 41 | -DCMAKE_INSTALL_RPATH=${GOOGLE_CLOUD_CPP_INSTALL_RPATH} 42 | -DCMAKE_INSTALL_PREFIX= 43 | BUILD_COMMAND ${CMAKE_COMMAND} --build ${PARALLEL} 44 | LOG_DOWNLOAD ON 45 | LOG_CONFIGURE ON 46 | LOG_BUILD ON 47 | LOG_INSTALL ON) 48 | endif () 49 | -------------------------------------------------------------------------------- /super/external/googletest.cmake: -------------------------------------------------------------------------------- 1 | # ~~~ 2 | # Copyright 2019 Google LLC 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # ~~~ 16 | 17 | include(ExternalProjectHelper) 18 | 19 | if (NOT TARGET googletest-project) 20 | # Give application developers a hook to configure the version and hash 21 | # downloaded from GitHub. 22 | set(GOOGLE_CLOUD_CPP_GOOGLETEST_URL 23 | "https://github.com/google/googletest/archive/release-1.10.0.tar.gz") 24 | set(GOOGLE_CLOUD_CPP_GOOGLETEST_SHA256 25 | "9dc9157a9a1551ec7a7e43daea9a694a0bb5fb8bec81235d8a1e6ef64c716dcb") 26 | 27 | set_external_project_build_parallel_level(PARALLEL) 28 | set_external_project_vars() 29 | 30 | include(ExternalProject) 31 | ExternalProject_Add( 32 | googletest-project 33 | EXCLUDE_FROM_ALL ON 34 | PREFIX "${CMAKE_BINARY_DIR}/external/googletest" 35 | INSTALL_DIR "${GOOGLE_CLOUD_CPP_EXTERNAL_PREFIX}" 36 | URL ${GOOGLE_CLOUD_CPP_GOOGLETEST_URL} 37 | URL_HASH SHA256=${GOOGLE_CLOUD_CPP_GOOGLETEST_SHA256} 38 | LIST_SEPARATOR | 39 | CMAKE_ARGS ${GOOGLE_CLOUD_CPP_EXTERNAL_PROJECT_CMAKE_FLAGS} 40 | -DCMAKE_PREFIX_PATH=${GOOGLE_CLOUD_CPP_PREFIX_PATH} 41 | -DCMAKE_INSTALL_RPATH=${GOOGLE_CLOUD_CPP_INSTALL_RPATH} 42 | -DCMAKE_INSTALL_PREFIX= 43 | BUILD_COMMAND ${CMAKE_COMMAND} --build ${PARALLEL} 44 | LOG_DOWNLOAD ON 45 | LOG_CONFIGURE ON 46 | LOG_BUILD ON 47 | LOG_INSTALL ON) 48 | endif () 49 | -------------------------------------------------------------------------------- /super/external/ssl.cmake: -------------------------------------------------------------------------------- 1 | # ~~~ 2 | # Copyright 2019 Google LLC 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # ~~~ 16 | 17 | if (NOT TARGET ssl-project) 18 | # For OpenSSL we don't really support external projects. OpenSSL build 19 | # system is notoriously finicky. Use vcpkg on Windows, or install OpenSSL 20 | # using your operating system packages instead. 21 | # 22 | # This file is here to simplify the definition of external projects, such as 23 | # curl and gRPC, that depend on a SSL library. 24 | find_package(OpenSSL REQUIRED) 25 | add_custom_target(ssl-project) 26 | endif () 27 | -------------------------------------------------------------------------------- /super/external/zlib.cmake: -------------------------------------------------------------------------------- 1 | # ~~~ 2 | # Copyright 2019 Google LLC 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # ~~~ 16 | 17 | if (NOT TARGET zlib-project) 18 | # Give application developers a hook to configure the version and hash 19 | # downloaded from GitHub. 20 | set(GOOGLE_CLOUD_CPP_ZLIB_URL 21 | "https://github.com/madler/zlib/archive/v1.2.11.tar.gz") 22 | set(GOOGLE_CLOUD_CPP_ZLIB_SHA256 23 | "629380c90a77b964d896ed37163f5c3a34f6e6d897311f1df2a7016355c45eff") 24 | 25 | set_external_project_build_parallel_level(PARALLEL) 26 | set_external_project_vars() 27 | 28 | include(ExternalProject) 29 | ExternalProject_Add( 30 | zlib-project 31 | EXCLUDE_FROM_ALL ON 32 | PREFIX "${CMAKE_BINARY_DIR}/external/zlib" 33 | INSTALL_DIR "${GOOGLE_CLOUD_CPP_EXTERNAL_PREFIX}" 34 | URL ${GOOGLE_CLOUD_CPP_ZLIB_URL} 35 | URL_HASH SHA256=${GOOGLE_CLOUD_CPP_ZLIB_SHA256} 36 | LIST_SEPARATOR | 37 | CMAKE_ARGS ${GOOGLE_CLOUD_CPP_EXTERNAL_PROJECT_CMAKE_FLAGS} 38 | -DCMAKE_PREFIX_PATH=${GOOGLE_CLOUD_CPP_PREFIX_PATH} 39 | -DCMAKE_INSTALL_RPATH=${GOOGLE_CLOUD_CPP_INSTALL_RPATH} 40 | -DCMAKE_INSTALL_PREFIX= 41 | BUILD_COMMAND ${CMAKE_COMMAND} --build ${PARALLEL} 42 | LOG_DOWNLOAD ON 43 | LOG_CONFIGURE ON 44 | LOG_BUILD ON 45 | LOG_INSTALL ON) 46 | endif () 47 | --------------------------------------------------------------------------------