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

Information
Class: AsyncResponse.Transports.AzureServiceBus.AzureServiceBusOptionsValidator
Assembly: AsyncResponse.Transports.AzureServiceBus
File(s): /_/src/Transports/AsyncResponse.Transports.AzureServiceBus/AzureServiceBusOptionsValidator.cs
Line coverage
100%
Covered lines: 67
Uncovered lines: 0
Coverable lines: 67
Total lines: 123
Line coverage: 100%
Branch coverage
100%
Covered branches: 30
Total branches: 30
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
ValidateCommon(...)100%1010100%
ValidateSubscriber(...)100%1818100%
Required(...)100%22100%

File(s)

/_/src/Transports/AsyncResponse.Transports.AzureServiceBus/AzureServiceBusOptionsValidator.cs

#LineLine coverage
 1namespace AsyncResponse.Transports.AzureServiceBus;
 2
 3internal static class AzureServiceBusOptionsValidator
 4{
 5    public static void ValidateCommon(AzureServiceBusAsyncResponseOptions options)
 6    {
 6527        Required(options.WorkerQueue, nameof(options.WorkerQueue));
 6528        Required(options.ResponseQueue, nameof(options.ResponseQueue));
 6529        Required(options.CorrelationIdProperty, nameof(options.CorrelationIdProperty));
 65210        Required(options.DefaultReplyTargetName, nameof(options.DefaultReplyTargetName));
 11
 65212        if (StringComparer.Ordinal.Equals(options.WorkerQueue, options.ResponseQueue))
 13        {
 214            throw new InvalidOperationException(
 215                $"{nameof(AzureServiceBusAsyncResponseOptions)}.{nameof(options.WorkerQueue)} and " +
 216                $"{nameof(options.ResponseQueue)} must be distinct so worker and response subscribers do not consume eac
 17        }
 18
 65019        if (options.MaxMessagesPerReceive <= 0)
 220            throw new InvalidOperationException($"{nameof(AzureServiceBusAsyncResponseOptions)}.{nameof(options.MaxMessa
 64821        if (options.PublishMaxAttempts <= 0)
 222            throw new InvalidOperationException($"{nameof(AzureServiceBusAsyncResponseOptions)}.{nameof(options.PublishM
 23
 24        // All of these arm timers: ReceiveWaitTime inside the SDK's receive call, the retry
 25        // delays via Task.Delay, and ShutdownTimeout as a CancellationTokenSource budget.
 64626        AsyncResponseChannelOptions.EnsureTimerBacked(options.ReceiveWaitTime, nameof(AzureServiceBusAsyncResponseOption
 64227        AsyncResponseChannelOptions.EnsureTimerBacked(options.PublishRetryBaseDelay, nameof(AzureServiceBusAsyncResponse
 64228        AsyncResponseChannelOptions.EnsureTimerBacked(options.PublishRetryMaxDelay, nameof(AzureServiceBusAsyncResponseO
 64229        AsyncResponseChannelOptions.EnsureTimerBacked(options.SubscriberRetryBaseDelay, nameof(AzureServiceBusAsyncRespo
 64230        AsyncResponseChannelOptions.EnsureTimerBacked(options.SubscriberRetryMaxDelay, nameof(AzureServiceBusAsyncRespon
 64231        AsyncResponseChannelOptions.EnsureTimerBacked(options.ShutdownTimeout, nameof(AzureServiceBusAsyncResponseOption
 32
 64233        if (options.PublishRetryBaseDelay > options.PublishRetryMaxDelay)
 234            throw new InvalidOperationException($"{nameof(AzureServiceBusAsyncResponseOptions)}.{nameof(options.PublishR
 64035        if (options.SubscriberRetryBaseDelay > options.SubscriberRetryMaxDelay)
 236            throw new InvalidOperationException($"{nameof(AzureServiceBusAsyncResponseOptions)}.{nameof(options.Subscrib
 63837    }
 38
 39    public static void ValidateSubscriber(
 40        AzureServiceBusAsyncResponseOptions transportOptions,
 41        AzureServiceBusSubscriberOptions subscriberOptions,
 42        AzureServiceBusSubscriberRole role)
 43    {
 87844        var optionPath = role is AzureServiceBusSubscriberRole.Worker
 87845            ? $"{nameof(AzureServiceBusAsyncResponseOptions)}.{nameof(AzureServiceBusAsyncResponseOptions.WorkerSubscrib
 87846            : $"{nameof(AzureServiceBusAsyncResponseOptions)}.{nameof(AzureServiceBusAsyncResponseOptions.ResponseSubscr
 47
 87848        if (subscriberOptions.MaxDeliveryAttempts < 0)
 249            throw new InvalidOperationException($"{optionPath}.{nameof(AzureServiceBusSubscriberOptions.MaxDeliveryAttem
 87650        if (subscriberOptions.PrefetchCount < 0)
 251            throw new InvalidOperationException($"{optionPath}.{nameof(AzureServiceBusSubscriberOptions.PrefetchCount)} 
 87452        if (subscriberOptions.LockRenewalInterval is { } lockRenewalInterval)
 86653            AsyncResponseChannelOptions.EnsureTimerBacked(lockRenewalInterval, optionPath, nameof(AzureServiceBusSubscri
 54
 87055        switch (subscriberOptions.AckMode)
 56        {
 57            case AzureServiceBusAckMode.AckAfterHandlerCompletes:
 58                // ShutdownTimeout is spent at shutdown even without a background drain (SQS
 59                // parity, and what this option's own XML doc and transport-semantics.md promise
 60                // is validated): the lock-renewal join on the final batch, then the receiver
 61                // close, run SEQUENTIALLY on the stop path, so with renewal on the budget must
 62                // fit two of them. Returning here without summing anything let a raised
 63                // ShutdownTimeout overrun the host's stop budget, force-terminating mid-close and
 64                // redelivering handled-but-uncompleted messages whose locks then lapsed.
 83065                if (subscriberOptions.LockRenewalInterval is not null)
 66                {
 82267                    ShutdownBudgetValidator.Validate(
 82268                        "Azure Service Bus",
 82269                        $"{nameof(AzureServiceBusAsyncResponseOptions)}.{nameof(AzureServiceBusAsyncResponseOptions.Host
 82270                        transportOptions.HostShutdownTimeout,
 82271                        ($"{nameof(AzureServiceBusAsyncResponseOptions)}.{nameof(AzureServiceBusAsyncResponseOptions.Shu
 82272                        ($"{nameof(AzureServiceBusAsyncResponseOptions)}.{nameof(AzureServiceBusAsyncResponseOptions.Shu
 73                }
 74                else
 75                {
 876                    ShutdownBudgetValidator.Validate(
 877                        "Azure Service Bus",
 878                        $"{nameof(AzureServiceBusAsyncResponseOptions)}.{nameof(AzureServiceBusAsyncResponseOptions.Host
 879                        transportOptions.HostShutdownTimeout,
 880                        ($"{nameof(AzureServiceBusAsyncResponseOptions)}.{nameof(AzureServiceBusAsyncResponseOptions.Shu
 81                }
 82
 683                return;
 84
 85            case AzureServiceBusAckMode.AckAfterEnqueue:
 3886                if (subscriberOptions.BackgroundWorkerCount <= 0)
 87                {
 488                    throw new InvalidOperationException(
 489                        $"{optionPath}.{nameof(AzureServiceBusSubscriberOptions.BackgroundWorkerCount)} must be explicit
 490                        $"when {nameof(AzureServiceBusSubscriberOptions.AckMode)} is {nameof(AzureServiceBusAckMode.AckA
 91                }
 92
 3493                if (subscriberOptions.BackgroundQueueCapacity <= 0)
 94                {
 295                    throw new InvalidOperationException(
 296                        $"{optionPath}.{nameof(AzureServiceBusSubscriberOptions.BackgroundQueueCapacity)} must be explic
 297                        $"when {nameof(AzureServiceBusSubscriberOptions.AckMode)} is {nameof(AzureServiceBusAckMode.AckA
 98                }
 99
 32100                AsyncResponseChannelOptions.EnsureTimerBacked(subscriberOptions.BackgroundDrainTimeout, optionPath, name
 101
 102                // Service Bus spends the background drain plus receiver close / renewal-task join
 103                // (ShutdownTimeout) at shutdown; both must fit inside the host budget.
 30104                ShutdownBudgetValidator.Validate(
 30105                    "Azure Service Bus",
 30106                    $"{nameof(AzureServiceBusAsyncResponseOptions)}.{nameof(AzureServiceBusAsyncResponseOptions.HostShut
 30107                    transportOptions.HostShutdownTimeout,
 30108                    ($"{optionPath}.{nameof(AzureServiceBusSubscriberOptions.BackgroundDrainTimeout)}", subscriberOption
 30109                    ($"{nameof(AzureServiceBusAsyncResponseOptions)}.{nameof(AzureServiceBusAsyncResponseOptions.Shutdow
 110
 26111                return;
 112
 113            default:
 2114                throw new InvalidOperationException(
 2115                    $"{optionPath}.{nameof(AzureServiceBusSubscriberOptions.AckMode)} has unsupported value '{subscriber
 116        }
 117    }
 118
 119    public static string Required(string? value, string name)
 3618120        => !string.IsNullOrWhiteSpace(value)
 3618121            ? value
 3618122            : throw new InvalidOperationException($"{nameof(AzureServiceBusAsyncResponseOptions)}.{name} must be configu
 123}