< Summary - AsyncResponse (Release / net8.0+net10.0 / unit+integration)

Information
Class: AsyncResponse.Transports.GooglePubSub.GooglePubSubPublisherClientAdapter
Assembly: AsyncResponse.Transports.GooglePubSub
File(s): /_/src/Transports/AsyncResponse.Transports.GooglePubSub/GooglePubSubClientAdapters.cs
Line coverage
100%
Covered lines: 4
Uncovered lines: 0
Coverable lines: 4
Total lines: 46
Line coverage: 100%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
PublishAsync(...)100%11100%
ShutdownAsync(...)100%11100%

File(s)

/_/src/Transports/AsyncResponse.Transports.GooglePubSub/GooglePubSubClientAdapters.cs

#LineLine coverage
 1using Google.Cloud.PubSub.V1;
 2
 3namespace AsyncResponse.Transports.GooglePubSub;
 4
 5internal interface IGooglePubSubPublisherClient
 6{
 7    Task<string> PublishAsync(PubsubMessage message, CancellationToken cancellationToken);
 8    Task ShutdownAsync(TimeSpan timeout);
 9}
 10
 19411internal sealed class GooglePubSubPublisherClientAdapter(PublisherClient inner) : IGooglePubSubPublisherClient
 12{
 13    /// <summary>Publishes the supplied message.</summary>
 14    public Task<string> PublishAsync(PubsubMessage message, CancellationToken cancellationToken)
 15    {
 16        // PublisherClient exposes no cancellation: once handed over, the message sits in the
 17        // client's local batch queue and WILL be flushed (DisposeAsync's ShutdownAsync completes
 18        // only "when all queued messages have been published"). Checking before the hand-off keeps
 19        // a publish cancelled at shutdown from being enqueued-then-delivered while its caller was
 20        // told nothing was sent; a token firing mid-flight still only abandons the wait — that
 21        // residual at-least-once window is inherent to the SDK.
 40722        cancellationToken.ThrowIfCancellationRequested();
 40723        return inner.PublishAsync(message).WaitAsync(cancellationToken);
 24    }
 25
 26    /// <summary>Runs the ShutdownAsync operation.</summary>
 27    public Task ShutdownAsync(TimeSpan timeout)
 19428        => inner.ShutdownAsync(timeout);
 29}
 30
 31internal interface IGooglePubSubSubscriberClient
 32{
 33    Task StartAsync(Func<PubsubMessage, CancellationToken, Task<SubscriberClient.Reply>> handler);
 34    Task StopAsync(SubscriberClient.ShutdownOptions options, CancellationToken cancellationToken);
 35}
 36
 37internal sealed class GooglePubSubSubscriberClientAdapter(SubscriberClient inner) : IGooglePubSubSubscriberClient
 38{
 39    /// <summary>Starts this service.</summary>
 40    public Task StartAsync(Func<PubsubMessage, CancellationToken, Task<SubscriberClient.Reply>> handler)
 41        => inner.StartAsync(handler);
 42
 43    /// <summary>Stops this service.</summary>
 44    public Task StopAsync(SubscriberClient.ShutdownOptions options, CancellationToken cancellationToken)
 45        => inner.StopAsync(options, cancellationToken);
 46}