Skip to content

Commit

Permalink
PR review fixups.
Browse files Browse the repository at this point in the history
  • Loading branch information
lukebakken committed Dec 7, 2023
1 parent b1b86f5 commit 15f7d65
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 38 deletions.
39 changes: 20 additions & 19 deletions projects/RabbitMQ.Client/client/api/ConnectionFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ public IConnection CreateConnection()
/// When the configured hostname was not reachable.
/// </exception>
public ValueTask<IConnection> CreateConnectionAsync(
CancellationToken cancellationToken = default(CancellationToken))
CancellationToken cancellationToken = default)
{
return CreateConnectionAsync(ClientProvidedName, cancellationToken);
}
Expand Down Expand Up @@ -466,7 +466,7 @@ public IConnection CreateConnection(string clientProvidedName)
/// When the configured hostname was not reachable.
/// </exception>
public ValueTask<IConnection> CreateConnectionAsync(string clientProvidedName,
CancellationToken cancellationToken = default(CancellationToken))
CancellationToken cancellationToken = default)
{
return CreateConnectionAsync(EndpointResolverFactory(LocalEndpoints()), clientProvidedName, cancellationToken);
}
Expand Down Expand Up @@ -506,7 +506,7 @@ public IConnection CreateConnection(IEnumerable<string> hostnames)
/// When no hostname was reachable.
/// </exception>
public ValueTask<IConnection> CreateConnectionAsync(IEnumerable<string> hostnames,
CancellationToken cancellationToken = default(CancellationToken))
CancellationToken cancellationToken = default)
{
return CreateConnectionAsync(hostnames, ClientProvidedName, cancellationToken);
}
Expand Down Expand Up @@ -559,7 +559,7 @@ public IConnection CreateConnection(IEnumerable<string> hostnames, string client
/// When no hostname was reachable.
/// </exception>
public ValueTask<IConnection> CreateConnectionAsync(IEnumerable<string> hostnames, string clientProvidedName,
CancellationToken cancellationToken = default(CancellationToken))
CancellationToken cancellationToken = default)
{
IEnumerable<AmqpTcpEndpoint> endpoints = hostnames.Select(h => new AmqpTcpEndpoint(h, Port, Ssl, MaxMessageSize));
return CreateConnectionAsync(EndpointResolverFactory(endpoints), clientProvidedName, cancellationToken);
Expand Down Expand Up @@ -598,7 +598,7 @@ public IConnection CreateConnection(IEnumerable<AmqpTcpEndpoint> endpoints)
/// When no hostname was reachable.
/// </exception>
public ValueTask<IConnection> CreateConnectionAsync(IEnumerable<AmqpTcpEndpoint> endpoints,
CancellationToken cancellationToken = default(CancellationToken))
CancellationToken cancellationToken = default)
{
return CreateConnectionAsync(endpoints, ClientProvidedName, cancellationToken);
}
Expand Down Expand Up @@ -648,7 +648,7 @@ public IConnection CreateConnection(IEnumerable<AmqpTcpEndpoint> endpoints, stri
/// When no hostname was reachable.
/// </exception>
public ValueTask<IConnection> CreateConnectionAsync(IEnumerable<AmqpTcpEndpoint> endpoints, string clientProvidedName,
CancellationToken cancellationToken = default(CancellationToken))
CancellationToken cancellationToken = default)
{
return CreateConnectionAsync(EndpointResolverFactory(endpoints), clientProvidedName, cancellationToken);
}
Expand Down Expand Up @@ -687,9 +687,9 @@ public IConnection CreateConnection(IEndpointResolver endpointResolver, string c
return (Connection)c.Open();
}
}
catch (Exception e)
catch (Exception ex)
{
throw new BrokerUnreachableException(e);
throw new BrokerUnreachableException(ex);
}
}

Expand All @@ -711,7 +711,7 @@ public IConnection CreateConnection(IEndpointResolver endpointResolver, string c
/// When no hostname was reachable.
/// </exception>
public async ValueTask<IConnection> CreateConnectionAsync(IEndpointResolver endpointResolver, string clientProvidedName,
CancellationToken cancellationToken = default(CancellationToken))
CancellationToken cancellationToken = default)
{
ConnectionConfig config = CreateConfig(clientProvidedName);
try
Expand All @@ -731,19 +731,20 @@ public async ValueTask<IConnection> CreateConnectionAsync(IEndpointResolver endp
.ConfigureAwait(false);
}
}
// TODO is this correct?
catch (TaskCanceledException)
catch (OperationCanceledException ex)
{
throw;
}
// TODO is this correct?
catch (AggregateException)
{
throw;
if (cancellationToken.IsCancellationRequested)
{
throw;
}
else
{
throw new BrokerUnreachableException(ex);
}
}
catch (Exception e)
catch (Exception ex)
{
throw new BrokerUnreachableException(e);
throw new BrokerUnreachableException(ex);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ namespace RabbitMQ.Client
public class DefaultEndpointResolver : IEndpointResolver
{
#if !NET6_0_OR_GREATER
private static readonly Random s_rnd = new Random();
private readonly Random s_rnd = new Random();
#endif
private readonly List<AmqpTcpEndpoint> _endpoints;

Expand Down
12 changes: 6 additions & 6 deletions projects/RabbitMQ.Client/client/api/IConnectionFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public interface IConnectionFactory
/// Asynchronously create a connection to the specified endpoint.
/// </summary>
/// <param name="cancellationToken">Cancellation token for this connection</param>
ValueTask<IConnection> CreateConnectionAsync(CancellationToken cancellationToken);
ValueTask<IConnection> CreateConnectionAsync(CancellationToken cancellationToken = default);

/// <summary>
/// Create a connection to the specified endpoint.
Expand All @@ -132,7 +132,7 @@ public interface IConnectionFactory
/// </param>
/// <param name="cancellationToken">Cancellation token for this connection</param>
/// <returns>Open connection</returns>
ValueTask<IConnection> CreateConnectionAsync(string clientProvidedName, CancellationToken cancellationToken);
ValueTask<IConnection> CreateConnectionAsync(string clientProvidedName, CancellationToken cancellationToken = default);

/// <summary>
/// Connects to the first reachable hostname from the list.
Expand All @@ -147,7 +147,7 @@ public interface IConnectionFactory
/// <param name="hostnames">List of host names to use</param>
/// <param name="cancellationToken">Cancellation token for this connection</param>
/// <returns>Open connection</returns>
ValueTask<IConnection> CreateConnectionAsync(IEnumerable<string> hostnames, CancellationToken cancellationToken);
ValueTask<IConnection> CreateConnectionAsync(IEnumerable<string> hostnames, CancellationToken cancellationToken = default);

/// <summary>
/// Connects to the first reachable hostname from the list.
Expand Down Expand Up @@ -175,7 +175,7 @@ public interface IConnectionFactory
/// <param name="cancellationToken">Cancellation token for this connection</param>
/// <returns>Open connection</returns>
ValueTask<IConnection> CreateConnectionAsync(IEnumerable<string> hostnames, string clientProvidedName,
CancellationToken cancellationToken);
CancellationToken cancellationToken = default);

/// <summary>
/// Create a connection using a list of endpoints.
Expand Down Expand Up @@ -204,7 +204,7 @@ ValueTask<IConnection> CreateConnectionAsync(IEnumerable<string> hostnames, stri
/// <exception cref="BrokerUnreachableException">
/// When no hostname was reachable.
/// </exception>
ValueTask<IConnection> CreateConnectionAsync(IEnumerable<AmqpTcpEndpoint> endpoints, CancellationToken cancellationToken);
ValueTask<IConnection> CreateConnectionAsync(IEnumerable<AmqpTcpEndpoint> endpoints, CancellationToken cancellationToken = default);

/// <summary>
/// Create a connection using a list of endpoints.
Expand Down Expand Up @@ -246,7 +246,7 @@ ValueTask<IConnection> CreateConnectionAsync(IEnumerable<string> hostnames, stri
/// When no hostname was reachable.
/// </exception>
ValueTask<IConnection> CreateConnectionAsync(IEnumerable<AmqpTcpEndpoint> endpoints, string clientProvidedName,
CancellationToken cancellationToken);
CancellationToken cancellationToken = default);

/// <summary>
/// Amount of time protocol handshake operations are allowed to take before
Expand Down
2 changes: 1 addition & 1 deletion projects/RabbitMQ.Client/client/api/ITcpClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public interface ITcpClient : IDisposable

Socket Client { get; }

Task ConnectAsync(IPAddress host, int port, CancellationToken cancellationToken);
Task ConnectAsync(IPAddress host, int port, CancellationToken cancellationToken = default);

NetworkStream GetStream();

Expand Down
4 changes: 2 additions & 2 deletions projects/RabbitMQ.Client/client/api/TcpClientAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ public TcpClientAdapter(Socket socket)
}

#if NET6_0_OR_GREATER
public virtual Task ConnectAsync(IPAddress ep, int port, CancellationToken cancellationToken)
public virtual Task ConnectAsync(IPAddress ep, int port, CancellationToken cancellationToken = default)
{
AssertSocket();
return _sock.ConnectAsync(ep, port, cancellationToken).AsTask();
}
#else
public virtual Task ConnectAsync(IPAddress ep, int port, CancellationToken cancellationToken)
public virtual Task ConnectAsync(IPAddress ep, int port, CancellationToken cancellationToken = default)
{
return _sock.ConnectAsync(ep, port).WithCancellation(cancellationToken);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ private async ValueTask StartAndTuneAsync(CancellationToken cancellationToken)
{
var connectionStartCell = new TaskCompletionSource<ConnectionStartDetails>(TaskCreationOptions.RunContinuationsAsynchronously);

cancellationToken.Register(() =>
using CancellationTokenRegistration ctr = cancellationToken.Register(() =>
{
if (connectionStartCell.TrySetCanceled())
{
Expand Down
16 changes: 8 additions & 8 deletions projects/Test/Unit/APIApproval.Approve.verified.txt
Original file line number Diff line number Diff line change
Expand Up @@ -599,12 +599,12 @@ namespace RabbitMQ.Client
RabbitMQ.Client.IConnection CreateConnection(string clientProvidedName);
RabbitMQ.Client.IConnection CreateConnection(System.Collections.Generic.IEnumerable<RabbitMQ.Client.AmqpTcpEndpoint> endpoints, string clientProvidedName);
RabbitMQ.Client.IConnection CreateConnection(System.Collections.Generic.IEnumerable<string> hostnames, string clientProvidedName);
System.Threading.Tasks.ValueTask<RabbitMQ.Client.IConnection> CreateConnectionAsync(System.Threading.CancellationToken cancellationToken);
System.Threading.Tasks.ValueTask<RabbitMQ.Client.IConnection> CreateConnectionAsync(System.Collections.Generic.IEnumerable<RabbitMQ.Client.AmqpTcpEndpoint> endpoints, System.Threading.CancellationToken cancellationToken);
System.Threading.Tasks.ValueTask<RabbitMQ.Client.IConnection> CreateConnectionAsync(System.Collections.Generic.IEnumerable<string> hostnames, System.Threading.CancellationToken cancellationToken);
System.Threading.Tasks.ValueTask<RabbitMQ.Client.IConnection> CreateConnectionAsync(string clientProvidedName, System.Threading.CancellationToken cancellationToken);
System.Threading.Tasks.ValueTask<RabbitMQ.Client.IConnection> CreateConnectionAsync(System.Collections.Generic.IEnumerable<RabbitMQ.Client.AmqpTcpEndpoint> endpoints, string clientProvidedName, System.Threading.CancellationToken cancellationToken);
System.Threading.Tasks.ValueTask<RabbitMQ.Client.IConnection> CreateConnectionAsync(System.Collections.Generic.IEnumerable<string> hostnames, string clientProvidedName, System.Threading.CancellationToken cancellationToken);
System.Threading.Tasks.ValueTask<RabbitMQ.Client.IConnection> CreateConnectionAsync(System.Threading.CancellationToken cancellationToken = default);
System.Threading.Tasks.ValueTask<RabbitMQ.Client.IConnection> CreateConnectionAsync(System.Collections.Generic.IEnumerable<RabbitMQ.Client.AmqpTcpEndpoint> endpoints, System.Threading.CancellationToken cancellationToken = default);
System.Threading.Tasks.ValueTask<RabbitMQ.Client.IConnection> CreateConnectionAsync(System.Collections.Generic.IEnumerable<string> hostnames, System.Threading.CancellationToken cancellationToken = default);
System.Threading.Tasks.ValueTask<RabbitMQ.Client.IConnection> CreateConnectionAsync(string clientProvidedName, System.Threading.CancellationToken cancellationToken = default);
System.Threading.Tasks.ValueTask<RabbitMQ.Client.IConnection> CreateConnectionAsync(System.Collections.Generic.IEnumerable<RabbitMQ.Client.AmqpTcpEndpoint> endpoints, string clientProvidedName, System.Threading.CancellationToken cancellationToken = default);
System.Threading.Tasks.ValueTask<RabbitMQ.Client.IConnection> CreateConnectionAsync(System.Collections.Generic.IEnumerable<string> hostnames, string clientProvidedName, System.Threading.CancellationToken cancellationToken = default);
}
public interface ICredentialsProvider
{
Expand Down Expand Up @@ -712,7 +712,7 @@ namespace RabbitMQ.Client
bool Connected { get; }
System.TimeSpan ReceiveTimeout { get; set; }
void Close();
System.Threading.Tasks.Task ConnectAsync(System.Net.IPAddress host, int port, System.Threading.CancellationToken cancellationToken);
System.Threading.Tasks.Task ConnectAsync(System.Net.IPAddress host, int port, System.Threading.CancellationToken cancellationToken = default);
System.Net.Sockets.NetworkStream GetStream();
}
public class PlainMechanism : RabbitMQ.Client.IAuthMechanism
Expand Down Expand Up @@ -831,7 +831,7 @@ namespace RabbitMQ.Client
public virtual bool Connected { get; }
public virtual System.TimeSpan ReceiveTimeout { get; set; }
public virtual void Close() { }
public virtual System.Threading.Tasks.Task ConnectAsync(System.Net.IPAddress ep, int port, System.Threading.CancellationToken cancellationToken) { }
public virtual System.Threading.Tasks.Task ConnectAsync(System.Net.IPAddress ep, int port, System.Threading.CancellationToken cancellationToken = default) { }
public void Dispose() { }
protected virtual void Dispose(bool disposing) { }
public virtual System.Net.Sockets.NetworkStream GetStream() { }
Expand Down

0 comments on commit 15f7d65

Please sign in to comment.