diff --git a/Google.Api.Generator.Tests/ProtoTest.cs b/Google.Api.Generator.Tests/ProtoTest.cs index 7b7a3a74..7882c9da 100644 --- a/Google.Api.Generator.Tests/ProtoTest.cs +++ b/Google.Api.Generator.Tests/ProtoTest.cs @@ -251,7 +251,7 @@ void CleanUp(string path) public void Paginated0() => ProtoTestSingle("Paginated", ignoreCsProj: true); [Fact] - public void Lro0() => ProtoTestSingle("Lro"); + public void Lro0() => ProtoTestSingle("Lro", ignoreSnippets: true); [Fact] public void ServerStreaming0() => ProtoTestSingle("ServerStreaming", ignoreCsProj: true, ignoreSnippets: true); @@ -365,9 +365,6 @@ public void PublishingSettings() => ProtoTestSingle( [Fact] public void BuildBasic() => BuildTest("Basic", protoPackageVersion: "v1"); - [Fact] - public void BuildLro() => BuildTest("Lro"); - [Fact] public void DuplicateResourceDefinitions() { diff --git a/Google.Api.Generator.Tests/ProtoTests/Lro/Lro.proto b/Google.Api.Generator.Tests/ProtoTests/Lro/Lro.proto index 04bc73e3..0cc44ddf 100644 --- a/Google.Api.Generator.Tests/ProtoTests/Lro/Lro.proto +++ b/Google.Api.Generator.Tests/ProtoTests/Lro/Lro.proto @@ -6,6 +6,7 @@ import "google/api/resource.proto"; package testing.lro; +// LRO service to test. service Lro { option (google.api.default_host) = "lro.example.com"; diff --git a/Google.Api.Generator.Tests/ProtoTests/Lro/LroFakes.cs b/Google.Api.Generator.Tests/ProtoTests/Lro/LroFakes.cs new file mode 100644 index 00000000..d4d2a8db --- /dev/null +++ b/Google.Api.Generator.Tests/ProtoTests/Lro/LroFakes.cs @@ -0,0 +1,66 @@ +// Copyright 2019 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +using Google.LongRunning; +using Google.Protobuf.Reflection; +using Grpc.Core; +using System; + +// Disable warning: Missing XML comment on public members. +// Required to successfully build this generated test project. +#pragma warning disable 1591 + +namespace Testing.Lro; + +// gRPC fakes +public static partial class Lro +{ + public static ServiceDescriptor Descriptor => null; + public partial class LroClient + { + private CallInvoker CallInvoker => throw new NotImplementedException(); + + public LroClient(CallInvoker callInvoker) { } + public virtual AsyncUnaryCall SignatureMethodAsync(Request request, CallOptions options) => throw new NotImplementedException(); + public virtual Operation SignatureMethod(Request request, CallOptions options) => throw new NotImplementedException(); + public virtual AsyncUnaryCall ResourcedMethodAsync(ResourceRequest request, CallOptions options) => throw new NotImplementedException(); + public virtual Operation ResourcedMethod(ResourceRequest request, CallOptions options) => throw new NotImplementedException(); + } +} + +// Protobuf fakes +public class Request : ProtoMsgFake +{ + public string Name { get; set; } +} + +public partial class ResourceRequest : ProtoMsgFake +{ + public string Name { get; set; } +} + +public class LroResponse : ProtoMsgFake { + public class Types + { + public class Nested : ProtoMsgFake { } + } +} + +public class LroMetadata : ProtoMsgFake +{ + public class Types + { + public class Nested : ProtoMsgFake { } + } +} diff --git a/Google.Api.Generator.Tests/ProtoTests/Lro/Testing.Lro.GeneratedSnippets/LroClient.ResourcedMethodAsyncSnippet.g.cs b/Google.Api.Generator.Tests/ProtoTests/Lro/Testing.Lro.GeneratedSnippets/LroClient.ResourcedMethodAsyncSnippet.g.cs deleted file mode 100644 index f160e759..00000000 --- a/Google.Api.Generator.Tests/ProtoTests/Lro/Testing.Lro.GeneratedSnippets/LroClient.ResourcedMethodAsyncSnippet.g.cs +++ /dev/null @@ -1 +0,0 @@ -// TEST_DISABLE diff --git a/Google.Api.Generator.Tests/ProtoTests/Lro/Testing.Lro.GeneratedSnippets/LroClient.ResourcedMethodRequestObjectAsyncSnippet.g.cs b/Google.Api.Generator.Tests/ProtoTests/Lro/Testing.Lro.GeneratedSnippets/LroClient.ResourcedMethodRequestObjectAsyncSnippet.g.cs deleted file mode 100644 index f160e759..00000000 --- a/Google.Api.Generator.Tests/ProtoTests/Lro/Testing.Lro.GeneratedSnippets/LroClient.ResourcedMethodRequestObjectAsyncSnippet.g.cs +++ /dev/null @@ -1 +0,0 @@ -// TEST_DISABLE diff --git a/Google.Api.Generator.Tests/ProtoTests/Lro/Testing.Lro.GeneratedSnippets/LroClient.ResourcedMethodRequestObjectSnippet.g.cs b/Google.Api.Generator.Tests/ProtoTests/Lro/Testing.Lro.GeneratedSnippets/LroClient.ResourcedMethodRequestObjectSnippet.g.cs deleted file mode 100644 index f160e759..00000000 --- a/Google.Api.Generator.Tests/ProtoTests/Lro/Testing.Lro.GeneratedSnippets/LroClient.ResourcedMethodRequestObjectSnippet.g.cs +++ /dev/null @@ -1 +0,0 @@ -// TEST_DISABLE diff --git a/Google.Api.Generator.Tests/ProtoTests/Lro/Testing.Lro.GeneratedSnippets/LroClient.ResourcedMethodResourceNamesAsyncSnippet.g.cs b/Google.Api.Generator.Tests/ProtoTests/Lro/Testing.Lro.GeneratedSnippets/LroClient.ResourcedMethodResourceNamesAsyncSnippet.g.cs deleted file mode 100644 index f160e759..00000000 --- a/Google.Api.Generator.Tests/ProtoTests/Lro/Testing.Lro.GeneratedSnippets/LroClient.ResourcedMethodResourceNamesAsyncSnippet.g.cs +++ /dev/null @@ -1 +0,0 @@ -// TEST_DISABLE diff --git a/Google.Api.Generator.Tests/ProtoTests/Lro/Testing.Lro.GeneratedSnippets/LroClient.ResourcedMethodResourceNamesSnippet.g.cs b/Google.Api.Generator.Tests/ProtoTests/Lro/Testing.Lro.GeneratedSnippets/LroClient.ResourcedMethodResourceNamesSnippet.g.cs deleted file mode 100644 index f160e759..00000000 --- a/Google.Api.Generator.Tests/ProtoTests/Lro/Testing.Lro.GeneratedSnippets/LroClient.ResourcedMethodResourceNamesSnippet.g.cs +++ /dev/null @@ -1 +0,0 @@ -// TEST_DISABLE diff --git a/Google.Api.Generator.Tests/ProtoTests/Lro/Testing.Lro.GeneratedSnippets/LroClient.ResourcedMethodSnippet.g.cs b/Google.Api.Generator.Tests/ProtoTests/Lro/Testing.Lro.GeneratedSnippets/LroClient.ResourcedMethodSnippet.g.cs deleted file mode 100644 index f160e759..00000000 --- a/Google.Api.Generator.Tests/ProtoTests/Lro/Testing.Lro.GeneratedSnippets/LroClient.ResourcedMethodSnippet.g.cs +++ /dev/null @@ -1 +0,0 @@ -// TEST_DISABLE diff --git a/Google.Api.Generator.Tests/ProtoTests/Lro/Testing.Lro.GeneratedSnippets/LroClient.SignatureMethodAsyncSnippet.g.cs b/Google.Api.Generator.Tests/ProtoTests/Lro/Testing.Lro.GeneratedSnippets/LroClient.SignatureMethodAsyncSnippet.g.cs deleted file mode 100644 index f160e759..00000000 --- a/Google.Api.Generator.Tests/ProtoTests/Lro/Testing.Lro.GeneratedSnippets/LroClient.SignatureMethodAsyncSnippet.g.cs +++ /dev/null @@ -1 +0,0 @@ -// TEST_DISABLE diff --git a/Google.Api.Generator.Tests/ProtoTests/Lro/Testing.Lro.GeneratedSnippets/LroClient.SignatureMethodRequestObjectAsyncSnippet.g.cs b/Google.Api.Generator.Tests/ProtoTests/Lro/Testing.Lro.GeneratedSnippets/LroClient.SignatureMethodRequestObjectAsyncSnippet.g.cs deleted file mode 100644 index f160e759..00000000 --- a/Google.Api.Generator.Tests/ProtoTests/Lro/Testing.Lro.GeneratedSnippets/LroClient.SignatureMethodRequestObjectAsyncSnippet.g.cs +++ /dev/null @@ -1 +0,0 @@ -// TEST_DISABLE diff --git a/Google.Api.Generator.Tests/ProtoTests/Lro/Testing.Lro.GeneratedSnippets/LroClient.SignatureMethodRequestObjectSnippet.g.cs b/Google.Api.Generator.Tests/ProtoTests/Lro/Testing.Lro.GeneratedSnippets/LroClient.SignatureMethodRequestObjectSnippet.g.cs deleted file mode 100644 index f160e759..00000000 --- a/Google.Api.Generator.Tests/ProtoTests/Lro/Testing.Lro.GeneratedSnippets/LroClient.SignatureMethodRequestObjectSnippet.g.cs +++ /dev/null @@ -1 +0,0 @@ -// TEST_DISABLE diff --git a/Google.Api.Generator.Tests/ProtoTests/Lro/Testing.Lro.GeneratedSnippets/LroClient.SignatureMethodSnippet.g.cs b/Google.Api.Generator.Tests/ProtoTests/Lro/Testing.Lro.GeneratedSnippets/LroClient.SignatureMethodSnippet.g.cs deleted file mode 100644 index f160e759..00000000 --- a/Google.Api.Generator.Tests/ProtoTests/Lro/Testing.Lro.GeneratedSnippets/LroClient.SignatureMethodSnippet.g.cs +++ /dev/null @@ -1 +0,0 @@ -// TEST_DISABLE diff --git a/Google.Api.Generator.Tests/ProtoTests/Lro/Testing.Lro.GeneratedSnippets/Testing.Lro.GeneratedSnippets.csproj b/Google.Api.Generator.Tests/ProtoTests/Lro/Testing.Lro.GeneratedSnippets/Testing.Lro.GeneratedSnippets.csproj deleted file mode 100644 index 21c8bab1..00000000 --- a/Google.Api.Generator.Tests/ProtoTests/Lro/Testing.Lro.GeneratedSnippets/Testing.Lro.GeneratedSnippets.csproj +++ /dev/null @@ -1,15 +0,0 @@ - - - - - net6.0;net462 - latest - - - - - - - - - diff --git a/Google.Api.Generator.Tests/ProtoTests/Lro/Testing.Lro.GeneratedSnippets/snippet_metadata_testing.lro.json b/Google.Api.Generator.Tests/ProtoTests/Lro/Testing.Lro.GeneratedSnippets/snippet_metadata_testing.lro.json deleted file mode 100644 index 0b224112..00000000 --- a/Google.Api.Generator.Tests/ProtoTests/Lro/Testing.Lro.GeneratedSnippets/snippet_metadata_testing.lro.json +++ /dev/null @@ -1 +0,0 @@ -// TEST_DISABLE \ No newline at end of file diff --git a/Google.Api.Generator.Tests/ProtoTests/Lro/Testing.Lro.Snippets/LroClientSnippets.g.cs b/Google.Api.Generator.Tests/ProtoTests/Lro/Testing.Lro.Snippets/LroClientSnippets.g.cs deleted file mode 100644 index f160e759..00000000 --- a/Google.Api.Generator.Tests/ProtoTests/Lro/Testing.Lro.Snippets/LroClientSnippets.g.cs +++ /dev/null @@ -1 +0,0 @@ -// TEST_DISABLE diff --git a/Google.Api.Generator.Tests/ProtoTests/Lro/Testing.Lro.Snippets/Testing.Lro.Snippets.csproj b/Google.Api.Generator.Tests/ProtoTests/Lro/Testing.Lro.Snippets/Testing.Lro.Snippets.csproj deleted file mode 100644 index 21c8bab1..00000000 --- a/Google.Api.Generator.Tests/ProtoTests/Lro/Testing.Lro.Snippets/Testing.Lro.Snippets.csproj +++ /dev/null @@ -1,15 +0,0 @@ - - - - - net6.0;net462 - latest - - - - - - - - - diff --git a/Google.Api.Generator.Tests/ProtoTests/Lro/Testing.Lro/LroClient.g.cs b/Google.Api.Generator.Tests/ProtoTests/Lro/Testing.Lro/LroClient.g.cs index 4b322854..61296e47 100644 --- a/Google.Api.Generator.Tests/ProtoTests/Lro/Testing.Lro/LroClient.g.cs +++ b/Google.Api.Generator.Tests/ProtoTests/Lro/Testing.Lro/LroClient.g.cs @@ -15,23 +15,289 @@ // Generated code. DO NOT EDIT! #pragma warning disable CS8981 +using gax = Google.Api.Gax; using gaxgrpc = Google.Api.Gax.Grpc; +using grpccore = Grpc.Core; +using grpcinter = Grpc.Core.Interceptors; using lro = Google.LongRunning; +using mel = Microsoft.Extensions.Logging; +using proto = Google.Protobuf; +using scg = System.Collections.Generic; +using sco = System.Collections.ObjectModel; using st = System.Threading; using stt = System.Threading.Tasks; - -// Disable warning: Missing XML comment on public members. -// Required to successfully build this generated test project. -#pragma warning disable 1591 +using sys = System; namespace Testing.Lro { - public abstract class LroClient + /// Settings for instances. + public sealed partial class LroSettings : gaxgrpc::ServiceSettingsBase + { + /// Get a new instance of the default . + /// A new instance of the default . + public static LroSettings GetDefault() => new LroSettings(); + + /// Constructs a new object with default settings. + public LroSettings() + { + } + + private LroSettings(LroSettings existing) : base(existing) + { + gax::GaxPreconditions.CheckNotNull(existing, nameof(existing)); + SignatureMethodSettings = existing.SignatureMethodSettings; + SignatureMethodOperationsSettings = existing.SignatureMethodOperationsSettings.Clone(); + ResourcedMethodSettings = existing.ResourcedMethodSettings; + ResourcedMethodOperationsSettings = existing.ResourcedMethodOperationsSettings.Clone(); + OnCopy(existing); + } + + partial void OnCopy(LroSettings existing); + + /// + /// for synchronous and asynchronous calls to LroClient.SignatureMethod + /// and LroClient.SignatureMethodAsync. + /// + /// + /// + /// This call will not be retried. + /// No timeout is applied. + /// + /// + public gaxgrpc::CallSettings SignatureMethodSettings { get; set; } = gaxgrpc::CallSettings.FromExpiration(gax::Expiration.None); + + /// + /// Long Running Operation settings for calls to LroClient.SignatureMethod and + /// LroClient.SignatureMethodAsync. + /// + /// + /// Uses default of: + /// + /// Initial delay: 20 seconds. + /// Delay multiplier: 1.5 + /// Maximum delay: 45 seconds. + /// Total timeout: 24 hours. + /// + /// + public lro::OperationsSettings SignatureMethodOperationsSettings { get; set; } = new lro::OperationsSettings + { + DefaultPollSettings = new gax::PollSettings(gax::Expiration.FromTimeout(sys::TimeSpan.FromHours(24)), sys::TimeSpan.FromSeconds(20), 1.5, sys::TimeSpan.FromSeconds(45)), + }; + + /// + /// for synchronous and asynchronous calls to LroClient.ResourcedMethod + /// and LroClient.ResourcedMethodAsync. + /// + /// + /// + /// This call will not be retried. + /// No timeout is applied. + /// + /// + public gaxgrpc::CallSettings ResourcedMethodSettings { get; set; } = gaxgrpc::CallSettings.FromExpiration(gax::Expiration.None); + + /// + /// Long Running Operation settings for calls to LroClient.ResourcedMethod and + /// LroClient.ResourcedMethodAsync. + /// + /// + /// Uses default of: + /// + /// Initial delay: 20 seconds. + /// Delay multiplier: 1.5 + /// Maximum delay: 45 seconds. + /// Total timeout: 24 hours. + /// + /// + public lro::OperationsSettings ResourcedMethodOperationsSettings { get; set; } = new lro::OperationsSettings + { + DefaultPollSettings = new gax::PollSettings(gax::Expiration.FromTimeout(sys::TimeSpan.FromHours(24)), sys::TimeSpan.FromSeconds(20), 1.5, sys::TimeSpan.FromSeconds(45)), + }; + + /// Creates a deep clone of this object, with all the same property values. + /// A deep clone of this object. + public LroSettings Clone() => new LroSettings(this); + } + + /// + /// Builder class for to provide simple configuration of credentials, endpoint etc. + /// + public sealed partial class LroClientBuilder : gaxgrpc::ClientBuilderBase { - public lro::Operation SignatureMethod(Request request, gaxgrpc::CallSettings callSettings) => null; - public stt::Task> SignatureMethodAsync(Request request, gaxgrpc::CallSettings callSettings) => null; + /// The settings to use for RPCs, or null for the default settings. + public LroSettings Settings { get; set; } + + /// Creates a new builder with default settings. + public LroClientBuilder() : base(LroClient.ServiceMetadata) + { + } + + partial void InterceptBuild(ref LroClient client); + + partial void InterceptBuildAsync(st::CancellationToken cancellationToken, ref stt::Task task); + + /// Builds the resulting client. + public override LroClient Build() + { + LroClient client = null; + InterceptBuild(ref client); + return client ?? BuildImpl(); + } + + /// Builds the resulting client asynchronously. + public override stt::Task BuildAsync(st::CancellationToken cancellationToken = default) + { + stt::Task task = null; + InterceptBuildAsync(cancellationToken, ref task); + return task ?? BuildAsyncImpl(cancellationToken); + } + + private LroClient BuildImpl() + { + Validate(); + grpccore::CallInvoker callInvoker = CreateCallInvoker(); + return LroClient.Create(callInvoker, GetEffectiveSettings(Settings?.Clone()), Logger); + } + + private async stt::Task BuildAsyncImpl(st::CancellationToken cancellationToken) + { + Validate(); + grpccore::CallInvoker callInvoker = await CreateCallInvokerAsync(cancellationToken).ConfigureAwait(false); + return LroClient.Create(callInvoker, GetEffectiveSettings(Settings?.Clone()), Logger); + } + + /// Returns the channel pool to use when no other options are specified. + protected override gaxgrpc::ChannelPool GetChannelPool() => LroClient.ChannelPool; + } + + /// Lro client wrapper, for convenient use. + /// + /// LRO service to test. + /// + public abstract partial class LroClient + { + /// + /// The default endpoint for the Lro service, which is a host of "lro.example.com" and a port of 443. + /// + public static string DefaultEndpoint { get; } = "lro.example.com:443"; + + /// The default Lro scopes. + /// The default Lro scopes are: + public static scg::IReadOnlyList DefaultScopes { get; } = new sco::ReadOnlyCollection(new string[] { }); + + /// The service metadata associated with this client type. + public static gaxgrpc::ServiceMetadata ServiceMetadata { get; } = new gaxgrpc::ServiceMetadata(Lro.Descriptor, DefaultEndpoint, DefaultScopes, true, gax::ApiTransports.Grpc, PackageApiMetadata.ApiMetadata); + + internal static gaxgrpc::ChannelPool ChannelPool { get; } = new gaxgrpc::ChannelPool(ServiceMetadata); + + /// + /// Asynchronously creates a using the default credentials, endpoint and settings. To + /// specify custom credentials or other settings, use . + /// + /// + /// The to use while creating the client. + /// + /// The task representing the created . + public static stt::Task CreateAsync(st::CancellationToken cancellationToken = default) => + new LroClientBuilder().BuildAsync(cancellationToken); + + /// + /// Synchronously creates a using the default credentials, endpoint and settings. To + /// specify custom credentials or other settings, use . + /// + /// The created . + public static LroClient Create() => new LroClientBuilder().Build(); + + /// + /// Creates a which uses the specified call invoker for remote operations. + /// + /// + /// The for remote operations. Must not be null. + /// + /// Optional . + /// Optional . + /// The created . + internal static LroClient Create(grpccore::CallInvoker callInvoker, LroSettings settings = null, mel::ILogger logger = null) + { + gax::GaxPreconditions.CheckNotNull(callInvoker, nameof(callInvoker)); + grpcinter::Interceptor interceptor = settings?.Interceptor; + if (interceptor != null) + { + callInvoker = grpcinter::CallInvokerExtensions.Intercept(callInvoker, interceptor); + } + Lro.LroClient grpcClient = new Lro.LroClient(callInvoker); + return new LroClientImpl(grpcClient, settings, logger); + } + + /// + /// Shuts down any channels automatically created by and + /// . Channels which weren't automatically created are not + /// affected. + /// + /// + /// After calling this method, further calls to and + /// will create new channels, which could in turn be shut down + /// by another call to this method. + /// + /// A task representing the asynchronous shutdown operation. + public static stt::Task ShutdownDefaultChannelsAsync() => ChannelPool.ShutdownChannelsAsync(); + + /// The underlying gRPC Lro client + public virtual Lro.LroClient GrpcClient => throw new sys::NotImplementedException(); + + /// + /// Test an LRO RPC with a method signature. + /// + /// The request object containing all of the parameters for the API call. + /// If not null, applies overrides to this RPC call. + /// The RPC response. + public virtual lro::Operation SignatureMethod(Request request, gaxgrpc::CallSettings callSettings = null) => + throw new sys::NotImplementedException(); + + /// + /// Test an LRO RPC with a method signature. + /// + /// The request object containing all of the parameters for the API call. + /// If not null, applies overrides to this RPC call. + /// A Task containing the RPC response. + public virtual stt::Task> SignatureMethodAsync(Request request, gaxgrpc::CallSettings callSettings = null) => + throw new sys::NotImplementedException(); + + /// + /// Test an LRO RPC with a method signature. + /// + /// The request object containing all of the parameters for the API call. + /// A to use for this RPC. + /// A Task containing the RPC response. + public virtual stt::Task> SignatureMethodAsync(Request request, st::CancellationToken cancellationToken) => + SignatureMethodAsync(request, gaxgrpc::CallSettings.FromCancellationToken(cancellationToken)); + + /// The long-running operations client for SignatureMethod. + public virtual lro::OperationsClient SignatureMethodOperationsClient => throw new sys::NotImplementedException(); + + /// + /// Poll an operation once, using an operationName from a previous invocation of SignatureMethod. + /// + /// + /// The name of a previously invoked operation. Must not be null or empty. + /// + /// If not null, applies overrides to this RPC call. + /// The result of polling the operation. + public virtual lro::Operation PollOnceSignatureMethod(string operationName, gaxgrpc::CallSettings callSettings = null) => + lro::Operation.PollOnceFromName(gax::GaxPreconditions.CheckNotNullOrEmpty(operationName, nameof(operationName)), SignatureMethodOperationsClient, callSettings); + + /// + /// Asynchronously poll an operation once, using an operationName from a previous invocation of + /// SignatureMethod. + /// + /// + /// The name of a previously invoked operation. Must not be null or empty. + /// + /// If not null, applies overrides to this RPC call. + /// A task representing the result of polling the operation. + public virtual stt::Task> PollOnceSignatureMethodAsync(string operationName, gaxgrpc::CallSettings callSettings = null) => + lro::Operation.PollOnceFromNameAsync(gax::GaxPreconditions.CheckNotNullOrEmpty(operationName, nameof(operationName)), SignatureMethodOperationsClient, callSettings); - // TEST_START /// /// Test an LRO RPC with a method signature. /// @@ -61,12 +327,60 @@ public abstract class LroClient /// A Task containing the RPC response. public virtual stt::Task> SignatureMethodAsync(string name, st::CancellationToken cancellationToken) => SignatureMethodAsync(name, gaxgrpc::CallSettings.FromCancellationToken(cancellationToken)); - // TEST_END - public lro::Operation ResourcedMethod(ResourceRequest request, gaxgrpc::CallSettings callSettings) => null; - public stt::Task> ResourcedMethodAsync(ResourceRequest request, gaxgrpc::CallSettings callSettings) => null; + /// + /// Test an LRO RPC with a method signature that contains resource-names. + /// + /// The request object containing all of the parameters for the API call. + /// If not null, applies overrides to this RPC call. + /// The RPC response. + public virtual lro::Operation ResourcedMethod(ResourceRequest request, gaxgrpc::CallSettings callSettings = null) => + throw new sys::NotImplementedException(); + + /// + /// Test an LRO RPC with a method signature that contains resource-names. + /// + /// The request object containing all of the parameters for the API call. + /// If not null, applies overrides to this RPC call. + /// A Task containing the RPC response. + public virtual stt::Task> ResourcedMethodAsync(ResourceRequest request, gaxgrpc::CallSettings callSettings = null) => + throw new sys::NotImplementedException(); + + /// + /// Test an LRO RPC with a method signature that contains resource-names. + /// + /// The request object containing all of the parameters for the API call. + /// A to use for this RPC. + /// A Task containing the RPC response. + public virtual stt::Task> ResourcedMethodAsync(ResourceRequest request, st::CancellationToken cancellationToken) => + ResourcedMethodAsync(request, gaxgrpc::CallSettings.FromCancellationToken(cancellationToken)); + + /// The long-running operations client for ResourcedMethod. + public virtual lro::OperationsClient ResourcedMethodOperationsClient => throw new sys::NotImplementedException(); + + /// + /// Poll an operation once, using an operationName from a previous invocation of ResourcedMethod. + /// + /// + /// The name of a previously invoked operation. Must not be null or empty. + /// + /// If not null, applies overrides to this RPC call. + /// The result of polling the operation. + public virtual lro::Operation PollOnceResourcedMethod(string operationName, gaxgrpc::CallSettings callSettings = null) => + lro::Operation.PollOnceFromName(gax::GaxPreconditions.CheckNotNullOrEmpty(operationName, nameof(operationName)), ResourcedMethodOperationsClient, callSettings); + + /// + /// Asynchronously poll an operation once, using an operationName from a previous invocation of + /// ResourcedMethod. + /// + /// + /// The name of a previously invoked operation. Must not be null or empty. + /// + /// If not null, applies overrides to this RPC call. + /// A task representing the result of polling the operation. + public virtual stt::Task> PollOnceResourcedMethodAsync(string operationName, gaxgrpc::CallSettings callSettings = null) => + lro::Operation.PollOnceFromNameAsync(gax::GaxPreconditions.CheckNotNullOrEmpty(operationName, nameof(operationName)), ResourcedMethodOperationsClient, callSettings); - // TEST_START /// /// Test an LRO RPC with a method signature that contains resource-names. /// @@ -126,6 +440,125 @@ public abstract class LroClient /// A Task containing the RPC response. public virtual stt::Task> ResourcedMethodAsync(ResourceName name, st::CancellationToken cancellationToken) => ResourcedMethodAsync(name, gaxgrpc::CallSettings.FromCancellationToken(cancellationToken)); - // TEST_END + } + + /// Lro client wrapper implementation, for convenient use. + /// + /// LRO service to test. + /// + public sealed partial class LroClientImpl : LroClient + { + private readonly gaxgrpc::ApiCall _callSignatureMethod; + + private readonly gaxgrpc::ApiCall _callResourcedMethod; + + /// + /// Constructs a client wrapper for the Lro service, with the specified gRPC client and settings. + /// + /// The underlying gRPC client. + /// The base used within this client. + /// Optional to use within this client. + public LroClientImpl(Lro.LroClient grpcClient, LroSettings settings, mel::ILogger logger) + { + GrpcClient = grpcClient; + LroSettings effectiveSettings = settings ?? LroSettings.GetDefault(); + gaxgrpc::ClientHelper clientHelper = new gaxgrpc::ClientHelper(new gaxgrpc::ClientHelper.Options + { + Settings = effectiveSettings, + Logger = logger, + }); + SignatureMethodOperationsClient = new lro::OperationsClientImpl(grpcClient.CreateOperationsClient(), effectiveSettings.SignatureMethodOperationsSettings, logger); + ResourcedMethodOperationsClient = new lro::OperationsClientImpl(grpcClient.CreateOperationsClient(), effectiveSettings.ResourcedMethodOperationsSettings, logger); + _callSignatureMethod = clientHelper.BuildApiCall("SignatureMethod", grpcClient.SignatureMethodAsync, grpcClient.SignatureMethod, effectiveSettings.SignatureMethodSettings); + Modify_ApiCall(ref _callSignatureMethod); + Modify_SignatureMethodApiCall(ref _callSignatureMethod); + _callResourcedMethod = clientHelper.BuildApiCall("ResourcedMethod", grpcClient.ResourcedMethodAsync, grpcClient.ResourcedMethod, effectiveSettings.ResourcedMethodSettings); + Modify_ApiCall(ref _callResourcedMethod); + Modify_ResourcedMethodApiCall(ref _callResourcedMethod); + OnConstruction(grpcClient, effectiveSettings, clientHelper); + } + + partial void Modify_ApiCall(ref gaxgrpc::ApiCall call) where TRequest : class, proto::IMessage where TResponse : class, proto::IMessage; + + partial void Modify_SignatureMethodApiCall(ref gaxgrpc::ApiCall call); + + partial void Modify_ResourcedMethodApiCall(ref gaxgrpc::ApiCall call); + + partial void OnConstruction(Lro.LroClient grpcClient, LroSettings effectiveSettings, gaxgrpc::ClientHelper clientHelper); + + /// The underlying gRPC Lro client + public override Lro.LroClient GrpcClient { get; } + + partial void Modify_Request(ref Request request, ref gaxgrpc::CallSettings settings); + + partial void Modify_ResourceRequest(ref ResourceRequest request, ref gaxgrpc::CallSettings settings); + + /// The long-running operations client for SignatureMethod. + public override lro::OperationsClient SignatureMethodOperationsClient { get; } + + /// + /// Test an LRO RPC with a method signature. + /// + /// The request object containing all of the parameters for the API call. + /// If not null, applies overrides to this RPC call. + /// The RPC response. + public override lro::Operation SignatureMethod(Request request, gaxgrpc::CallSettings callSettings = null) + { + Modify_Request(ref request, ref callSettings); + return new lro::Operation(_callSignatureMethod.Sync(request, callSettings), SignatureMethodOperationsClient); + } + + /// + /// Test an LRO RPC with a method signature. + /// + /// The request object containing all of the parameters for the API call. + /// If not null, applies overrides to this RPC call. + /// A Task containing the RPC response. + public override async stt::Task> SignatureMethodAsync(Request request, gaxgrpc::CallSettings callSettings = null) + { + Modify_Request(ref request, ref callSettings); + return new lro::Operation(await _callSignatureMethod.Async(request, callSettings).ConfigureAwait(false), SignatureMethodOperationsClient); + } + + /// The long-running operations client for ResourcedMethod. + public override lro::OperationsClient ResourcedMethodOperationsClient { get; } + + /// + /// Test an LRO RPC with a method signature that contains resource-names. + /// + /// The request object containing all of the parameters for the API call. + /// If not null, applies overrides to this RPC call. + /// The RPC response. + public override lro::Operation ResourcedMethod(ResourceRequest request, gaxgrpc::CallSettings callSettings = null) + { + Modify_ResourceRequest(ref request, ref callSettings); + return new lro::Operation(_callResourcedMethod.Sync(request, callSettings), ResourcedMethodOperationsClient); + } + + /// + /// Test an LRO RPC with a method signature that contains resource-names. + /// + /// The request object containing all of the parameters for the API call. + /// If not null, applies overrides to this RPC call. + /// A Task containing the RPC response. + public override async stt::Task> ResourcedMethodAsync(ResourceRequest request, gaxgrpc::CallSettings callSettings = null) + { + Modify_ResourceRequest(ref request, ref callSettings); + return new lro::Operation(await _callResourcedMethod.Async(request, callSettings).ConfigureAwait(false), ResourcedMethodOperationsClient); + } + } + + public static partial class Lro + { + public partial class LroClient + { + /// + /// Creates a new instance of using the same call invoker as + /// this client. + /// + /// A new Operations client for the same target as this client. + public virtual lro::Operations.OperationsClient CreateOperationsClient() => + new lro::Operations.OperationsClient(CallInvoker); + } } } diff --git a/Google.Api.Generator.Tests/ProtoTests/Lro/Testing.Lro/LroFakes.cs b/Google.Api.Generator.Tests/ProtoTests/Lro/Testing.Lro/LroFakes.cs deleted file mode 100644 index f92a22ce..00000000 --- a/Google.Api.Generator.Tests/ProtoTests/Lro/Testing.Lro/LroFakes.cs +++ /dev/null @@ -1,60 +0,0 @@ -// Copyright 2019 Google Inc. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -using System; - -// Disable warning: Missing XML comment on public members. -// Required to successfully build this generated test project. -#pragma warning disable 1591 - -namespace Testing.Lro -{ - // (Re-)define this here; required to successfully build this generated test project. - public abstract class ProtoMsgFake : Google.Protobuf.IMessage where T : ProtoMsgFake - { - public Google.Protobuf.Reflection.MessageDescriptor Descriptor => throw new NotImplementedException(); - public int CalculateSize() => throw new NotImplementedException(); - public T Clone() => throw new NotImplementedException(); - public bool Equals(T other) => throw new NotImplementedException(); - public void MergeFrom(T message) => throw new NotImplementedException(); - public void MergeFrom(Google.Protobuf.CodedInputStream input) => throw new NotImplementedException(); - public void WriteTo(Google.Protobuf.CodedOutputStream output) => throw new NotImplementedException(); - } - - public class Request : ProtoMsgFake - { - public string Name { get; set; } - } - - public partial class ResourceRequest : ProtoMsgFake - { - public string Name { get; set; } - } - - public class LroResponse : ProtoMsgFake - { - public class Types - { - public class Nested : ProtoMsgFake { } - } - } - - public class LroMetadata : ProtoMsgFake - { - public class Types - { - public class Nested : ProtoMsgFake { } - } - } -} diff --git a/Google.Api.Generator.Tests/ProtoTests/Lro/Testing.Lro/LroResourceNames.g.cs b/Google.Api.Generator.Tests/ProtoTests/Lro/Testing.Lro/LroResourceNames.g.cs index a08e1b34..0718d83e 100644 --- a/Google.Api.Generator.Tests/ProtoTests/Lro/Testing.Lro/LroResourceNames.g.cs +++ b/Google.Api.Generator.Tests/ProtoTests/Lro/Testing.Lro/LroResourceNames.g.cs @@ -1,4 +1,4 @@ -// Copyright 2019 Google LLC +// Copyright 2019 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License.