< Summary

Information
Class: IceRpc.ClientProtocolConnectionFactory
Assembly: IceRpc
File(s): /home/runner/work/icerpc-csharp/icerpc-csharp/src/IceRpc/ClientProtocolConnectionFactory.cs
Tag: 275_13775359185
Line coverage
100%
Covered lines: 53
Uncovered lines: 0
Coverable lines: 53
Total lines: 99
Line coverage: 100%
Branch coverage
93%
Covered branches: 15
Total branches: 16
Branch coverage: 93.7%
Method coverage
100%
Covered methods: 2
Total methods: 2
Method coverage: 100%

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)90%1010100%
CreateConnection(...)100%66100%

File(s)

/home/runner/work/icerpc-csharp/icerpc-csharp/src/IceRpc/ClientProtocolConnectionFactory.cs

#LineLine coverage
 1// Copyright (c) ZeroC, Inc.
 2
 3using IceRpc.Internal;
 4using IceRpc.Transports;
 5using Microsoft.Extensions.Logging;
 6using Microsoft.Extensions.Logging.Abstractions;
 7using System.Net.Security;
 8
 9namespace IceRpc;
 10
 11/// <summary>Default implementation of <see cref="IClientProtocolConnectionFactory" />.</summary>
 12public sealed class ClientProtocolConnectionFactory : IClientProtocolConnectionFactory
 13{
 14    private readonly SslClientAuthenticationOptions? _clientAuthenticationOptions;
 15    private readonly ConnectionOptions _connectionOptions;
 16    private readonly IDuplexClientTransport _duplexClientTransport;
 17    private readonly DuplexConnectionOptions _duplexConnectionOptions;
 18    private readonly ILogger _logger;
 19    private readonly IMultiplexedClientTransport _multiplexedClientTransport;
 20    private readonly MultiplexedConnectionOptions _multiplexedConnectionOptions;
 21
 22    /// <summary>Constructs a client protocol connection factory.</summary>
 23    /// <param name="connectionOptions">The connection options.</param>
 24    /// <param name="clientAuthenticationOptions">The client authentication options.</param>
 25    /// <param name="duplexClientTransport">The duplex client transport. <see langword="null" /> is equivalent to <see
 26    /// cref="IDuplexClientTransport.Default" />.</param>
 27    /// <param name="multiplexedClientTransport">The multiplexed client transport. <see langword="null" /> is equivalent
 28    /// to <see cref="IMultiplexedClientTransport.Default" />.</param>
 29    /// <param name="logger">The logger. <see langword="null" /> is equivalent to <see cref="NullLogger.Instance" />.</p
 15530    public ClientProtocolConnectionFactory(
 15531        ConnectionOptions connectionOptions,
 15532        SslClientAuthenticationOptions? clientAuthenticationOptions = null,
 15533        IDuplexClientTransport? duplexClientTransport = null,
 15534        IMultiplexedClientTransport? multiplexedClientTransport = null,
 15535        ILogger? logger = null)
 15536    {
 15537        _clientAuthenticationOptions = clientAuthenticationOptions;
 15538        _connectionOptions = connectionOptions;
 39
 15540        _duplexClientTransport = duplexClientTransport ?? IDuplexClientTransport.Default;
 15541        _duplexConnectionOptions = new DuplexConnectionOptions
 15542        {
 15543            Pool = connectionOptions.Pool,
 15544            MinSegmentSize = connectionOptions.MinSegmentSize,
 15545        };
 46
 15547        _multiplexedClientTransport = multiplexedClientTransport ?? IMultiplexedClientTransport.Default;
 48
 49        // If the dispatcher is null, we don't allow the peer to open streams for incoming requests. The only stream
 50        // which is accepted locally is the control stream created by the peer.
 15551        _multiplexedConnectionOptions = new MultiplexedConnectionOptions
 15552        {
 15553            MaxBidirectionalStreams = connectionOptions.Dispatcher is null ? 0 :
 15554                connectionOptions.MaxIceRpcBidirectionalStreams,
 15555
 15556            // Add an additional stream for the icerpc protocol control stream.
 15557            MaxUnidirectionalStreams = connectionOptions.Dispatcher is null ? 1 :
 15558                connectionOptions.MaxIceRpcUnidirectionalStreams + 1,
 15559
 15560            Pool = connectionOptions.Pool,
 15561            MinSegmentSize = connectionOptions.MinSegmentSize,
 15562        };
 63
 15564        _logger = logger ?? NullLogger.Instance;
 15565    }
 66
 67    /// <summary>Creates a protocol connection to the specified server address.</summary>
 68    /// <param name="serverAddress">The address of the server.</param>
 69    /// <returns>The new protocol connection.</returns>
 70    /// <remarks>The protocol connection returned by this factory method is not connected. The caller must call
 71    /// <see cref="IProtocolConnection.ConnectAsync" /> exactly once on this connection before calling
 72    /// <see cref="IInvoker.InvokeAsync" />.</remarks>
 73    public IProtocolConnection CreateConnection(ServerAddress serverAddress)
 16474    {
 16475        IProtocolConnection connection =
 16476            serverAddress.Protocol == Protocol.Ice ?
 16477                new IceProtocolConnection(
 16478                    _duplexClientTransport.CreateConnection(
 16479                        serverAddress,
 16480                        _duplexConnectionOptions,
 16481                        _clientAuthenticationOptions),
 16482                    transportConnectionInformation: null,
 16483                    _connectionOptions) :
 16484                new IceRpcProtocolConnection(
 16485                    _multiplexedClientTransport.CreateConnection(
 16486                        serverAddress,
 16487                        _multiplexedConnectionOptions,
 16488                        _clientAuthenticationOptions),
 16489                    transportConnectionInformation: null,
 16490                    _connectionOptions,
 16491                    taskExceptionObserver: _logger == NullLogger.Instance ? null :
 16492                        new LogTaskExceptionObserver(_logger));
 93
 16494        connection = new MetricsProtocolConnectionDecorator(connection, Metrics.ClientMetrics, connectStarted: false);
 95
 16496        return _logger == NullLogger.Instance ? connection :
 16497            new LogProtocolConnectionDecorator(connection, serverAddress, remoteNetworkAddress: null, _logger);
 16498    }
 99}