Skip to content

Commit 45f2699

Browse files
authored
impl(generator): handle deprecated services (#14849)
1 parent 72d8fd1 commit 45f2699

File tree

113 files changed

+2937
-8
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

113 files changed

+2937
-8
lines changed

generator/integration_tests/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ proto_library(
3030
"common.proto",
3131
"test.proto",
3232
"test2.proto",
33+
"test_deprecated.proto",
3334
"test_request_id.proto",
3435
],
3536
deps = [

generator/integration_tests/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ google_cloud_cpp_grpcpp_library(
3131
${PROJECT_SOURCE_DIR}/generator/integration_tests/test.proto
3232
${PROJECT_SOURCE_DIR}/generator/integration_tests/test2.proto
3333
${PROJECT_SOURCE_DIR}/generator/integration_tests/test_request_id.proto
34+
${PROJECT_SOURCE_DIR}/generator/integration_tests/test_deprecated.proto
3435
PROTO_PATH_DIRECTORIES
3536
${PROTO_INCLUDE_DIR}
3637
${PROJECT_SOURCE_DIR}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// Copyright 2024 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// https://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
// Generated by the Codegen C++ plugin.
16+
// If you make any local changes, they will be lost.
17+
// source: generator/integration_tests/test_deprecated.proto
18+
19+
#include "google/cloud/internal/disable_deprecation_warnings.inc"
20+
#include "generator/integration_tests/golden/v1/deprecated_client.h"
21+
#include <memory>
22+
#include <utility>
23+
24+
namespace google {
25+
namespace cloud {
26+
namespace golden_v1 {
27+
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
28+
29+
DeprecatedServiceClient::DeprecatedServiceClient(
30+
std::shared_ptr<DeprecatedServiceConnection> connection, Options opts)
31+
: connection_(std::move(connection)),
32+
options_(internal::MergeOptions(std::move(opts),
33+
connection_->options())) {}
34+
DeprecatedServiceClient::~DeprecatedServiceClient() = default;
35+
36+
Status
37+
DeprecatedServiceClient::Noop(google::test::deprecated::v1::DeprecatedServiceRequest const& request, Options opts) {
38+
internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_));
39+
return connection_->Noop(request);
40+
}
41+
42+
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
43+
} // namespace golden_v1
44+
} // namespace cloud
45+
} // namespace google
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
// Copyright 2024 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// https://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
// Generated by the Codegen C++ plugin.
16+
// If you make any local changes, they will be lost.
17+
// source: generator/integration_tests/test_deprecated.proto
18+
19+
#ifndef GOOGLE_CLOUD_CPP_GENERATOR_INTEGRATION_TESTS_GOLDEN_V1_DEPRECATED_CLIENT_H
20+
#define GOOGLE_CLOUD_CPP_GENERATOR_INTEGRATION_TESTS_GOLDEN_V1_DEPRECATED_CLIENT_H
21+
22+
#include "google/cloud/internal/disable_deprecation_warnings.inc"
23+
#include "generator/integration_tests/golden/v1/deprecated_connection.h"
24+
#include "google/cloud/future.h"
25+
#include "google/cloud/options.h"
26+
#include "google/cloud/polling_policy.h"
27+
#include "google/cloud/status_or.h"
28+
#include "google/cloud/version.h"
29+
#include <memory>
30+
#include <string>
31+
32+
namespace google {
33+
namespace cloud {
34+
namespace golden_v1 {
35+
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
36+
37+
///
38+
/// Service to test deprecated services.
39+
///
40+
/// @par Equality
41+
///
42+
/// Instances of this class created via copy-construction or copy-assignment
43+
/// always compare equal. Instances created with equal
44+
/// `std::shared_ptr<*Connection>` objects compare equal. Objects that compare
45+
/// equal share the same underlying resources.
46+
///
47+
/// @par Performance
48+
///
49+
/// Creating a new instance of this class is a relatively expensive operation,
50+
/// new objects establish new connections to the service. In contrast,
51+
/// copy-construction, move-construction, and the corresponding assignment
52+
/// operations are relatively efficient as the copies share all underlying
53+
/// resources.
54+
///
55+
/// @par Thread Safety
56+
///
57+
/// Concurrent access to different instances of this class, even if they compare
58+
/// equal, is guaranteed to work. Two or more threads operating on the same
59+
/// instance of this class is not guaranteed to work. Since copy-construction
60+
/// and move-construction is a relatively efficient operation, consider using
61+
/// such a copy when using this class from multiple threads.
62+
///
63+
class
64+
GOOGLE_CLOUD_CPP_DEPRECATED(
65+
"DeprecatedService has been deprecated and will be turned down in the future."
66+
)
67+
DeprecatedServiceClient {
68+
public:
69+
explicit DeprecatedServiceClient(std::shared_ptr<DeprecatedServiceConnection> connection, Options opts = {});
70+
~DeprecatedServiceClient();
71+
72+
///@{
73+
/// @name Copy and move support
74+
DeprecatedServiceClient(DeprecatedServiceClient const&) = default;
75+
DeprecatedServiceClient& operator=(DeprecatedServiceClient const&) = default;
76+
DeprecatedServiceClient(DeprecatedServiceClient&&) = default;
77+
DeprecatedServiceClient& operator=(DeprecatedServiceClient&&) = default;
78+
///@}
79+
80+
///@{
81+
/// @name Equality
82+
friend bool operator==(DeprecatedServiceClient const& a, DeprecatedServiceClient const& b) {
83+
return a.connection_ == b.connection_;
84+
}
85+
friend bool operator!=(DeprecatedServiceClient const& a, DeprecatedServiceClient const& b) {
86+
return !(a == b);
87+
}
88+
///@}
89+
90+
// clang-format off
91+
///
92+
/// Does nothing.
93+
///
94+
/// @param request Unary RPCs, such as the one wrapped by this
95+
/// function, receive a single `request` proto message which includes all
96+
/// the inputs for the RPC. In this case, the proto message is a
97+
/// [google.test.deprecated.v1.DeprecatedServiceRequest].
98+
/// Proto messages are converted to C++ classes by Protobuf, using the
99+
/// [Protobuf mapping rules].
100+
/// @param opts Optional. Override the class-level options, such as retry and
101+
/// backoff policies.
102+
/// @return a [`Status`] object. If the request failed, the
103+
/// status contains the details of the failure.
104+
///
105+
/// [Protobuf mapping rules]: https://protobuf.dev/reference/cpp/cpp-generated/
106+
/// [input iterator requirements]: https://en.cppreference.com/w/cpp/named_req/InputIterator
107+
/// [`std::string`]: https://en.cppreference.com/w/cpp/string/basic_string
108+
/// [`future`]: @ref google::cloud::future
109+
/// [`StatusOr`]: @ref google::cloud::StatusOr
110+
/// [`Status`]: @ref google::cloud::Status
111+
/// [google.test.deprecated.v1.DeprecatedServiceRequest]: @googleapis_reference_link{generator/integration_tests/test_deprecated.proto#L39}
112+
///
113+
// clang-format on
114+
Status
115+
Noop(google::test::deprecated::v1::DeprecatedServiceRequest const& request, Options opts = {});
116+
117+
private:
118+
std::shared_ptr<DeprecatedServiceConnection> connection_;
119+
Options options_;
120+
};
121+
122+
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
123+
} // namespace golden_v1
124+
} // namespace cloud
125+
} // namespace google
126+
127+
#endif // GOOGLE_CLOUD_CPP_GENERATOR_INTEGRATION_TESTS_GOLDEN_V1_DEPRECATED_CLIENT_H
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
// Copyright 2024 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// https://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
// Generated by the Codegen C++ plugin.
16+
// If you make any local changes, they will be lost.
17+
// source: generator/integration_tests/test_deprecated.proto
18+
19+
#include "google/cloud/internal/disable_deprecation_warnings.inc"
20+
#include "generator/integration_tests/golden/v1/deprecated_connection.h"
21+
#include "generator/integration_tests/golden/v1/deprecated_options.h"
22+
#include "generator/integration_tests/golden/v1/internal/deprecated_connection_impl.h"
23+
#include "generator/integration_tests/golden/v1/internal/deprecated_option_defaults.h"
24+
#include "generator/integration_tests/golden/v1/internal/deprecated_stub_factory.h"
25+
#include "generator/integration_tests/golden/v1/internal/deprecated_tracing_connection.h"
26+
#include "google/cloud/background_threads.h"
27+
#include "google/cloud/common_options.h"
28+
#include "google/cloud/credentials.h"
29+
#include "google/cloud/grpc_options.h"
30+
#include "google/cloud/internal/unified_grpc_credentials.h"
31+
#include <memory>
32+
#include <utility>
33+
34+
namespace google {
35+
namespace cloud {
36+
namespace golden_v1 {
37+
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
38+
39+
DeprecatedServiceConnection::~DeprecatedServiceConnection() = default;
40+
41+
Status
42+
DeprecatedServiceConnection::Noop(
43+
google::test::deprecated::v1::DeprecatedServiceRequest const&) {
44+
return Status(StatusCode::kUnimplemented, "not implemented");
45+
}
46+
47+
std::shared_ptr<DeprecatedServiceConnection> MakeDeprecatedServiceConnection(
48+
Options options) {
49+
internal::CheckExpectedOptions<CommonOptionList, GrpcOptionList,
50+
UnifiedCredentialsOptionList,
51+
DeprecatedServicePolicyOptionList>(options, __func__);
52+
options = golden_v1_internal::DeprecatedServiceDefaultOptions(
53+
std::move(options));
54+
auto background = internal::MakeBackgroundThreadsFactory(options)();
55+
auto auth = internal::CreateAuthenticationStrategy(background->cq(), options);
56+
auto stub = golden_v1_internal::CreateDefaultDeprecatedServiceStub(
57+
std::move(auth), options);
58+
return golden_v1_internal::MakeDeprecatedServiceTracingConnection(
59+
std::make_shared<golden_v1_internal::DeprecatedServiceConnectionImpl>(
60+
std::move(background), std::move(stub), std::move(options)));
61+
}
62+
63+
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
64+
} // namespace golden_v1
65+
} // namespace cloud
66+
} // namespace google

0 commit comments

Comments
 (0)