Skip to content

Commit

Permalink
Implement Equals for ProxyRoute & Cluster (#366)
Browse files Browse the repository at this point in the history
* Implement Equals for ProxyRoute & Cluster

* Add copyright license

* Address review points

* Fix test merge conflicts

Co-authored-by: Chris Ross <[email protected]>
  • Loading branch information
Kahbazi and Tratcher authored Sep 17, 2020
1 parent 585427d commit c06d818
Show file tree
Hide file tree
Showing 30 changed files with 1,215 additions and 105 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,21 @@ internal CircuitBreakerOptions DeepClone()
MaxConcurrentRetries = MaxConcurrentRetries,
};
}

internal static bool Equals(CircuitBreakerOptions options1, CircuitBreakerOptions options2)
{
if (options1 == null && options2 == null)
{
return true;
}

if (options1 == null || options2 == null)
{
return false;
}

return options1.MaxConcurrentRequests == options2.MaxConcurrentRequests
&& options1.MaxConcurrentRetries == options2.MaxConcurrentRetries;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

using System;
using System.Collections.Generic;
using Microsoft.ReverseProxy.Abstractions.ClusterDiscovery.Contract;
using Microsoft.ReverseProxy.Utilities;

namespace Microsoft.ReverseProxy.Abstractions
{
Expand Down Expand Up @@ -82,5 +82,29 @@ Cluster IDeepCloneable<Cluster>.DeepClone()
Metadata = Metadata?.DeepClone(StringComparer.OrdinalIgnoreCase),
};
}

internal static bool Equals(Cluster cluster1, Cluster cluster2)
{
if (cluster1 == null && cluster2 == null)
{
return true;
}

if (cluster1 == null || cluster2 == null)
{
return false;
}

return string.Equals(cluster1.Id, cluster2.Id, StringComparison.OrdinalIgnoreCase)
&& CircuitBreakerOptions.Equals(cluster1.CircuitBreaker, cluster2.CircuitBreaker)
&& QuotaOptions.Equals(cluster1.Quota, cluster2.Quota)
&& ClusterPartitioningOptions.Equals(cluster1.Partitioning, cluster2.Partitioning)
&& LoadBalancingOptions.Equals(cluster1.LoadBalancing, cluster2.LoadBalancing)
&& SessionAffinityOptions.Equals(cluster1.SessionAffinity, cluster2.SessionAffinity)
&& HealthCheckOptions.Equals(cluster1.HealthCheck, cluster2.HealthCheck)
&& ProxyHttpClientOptions.Equals(cluster1.HttpClient, cluster2.HttpClient)
&& CaseInsensitiveEqualHelper.Equals(cluster1.Destinations, cluster2.Destinations, Destination.Equals)
&& CaseInsensitiveEqualHelper.Equals(cluster1.Metadata, cluster2.Metadata);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

using System;

namespace Microsoft.ReverseProxy.Abstractions
{
/// <summary>
Expand Down Expand Up @@ -33,5 +35,22 @@ internal ClusterPartitioningOptions DeepClone()
PartitioningAlgorithm = PartitioningAlgorithm,
};
}

internal static bool Equals(ClusterPartitioningOptions options1, ClusterPartitioningOptions options2)
{
if (options1 == null && options2 == null)
{
return true;
}

if (options1 == null || options2 == null)
{
return false;
}

return options1.PartitionCount == options2.PartitionCount
&& string.Equals(options1.PartitionKeyExtractor, options2.PartitionKeyExtractor, StringComparison.OrdinalIgnoreCase)
&& string.Equals(options1.PartitioningAlgorithm, options2.PartitioningAlgorithm, StringComparison.OrdinalIgnoreCase);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) Microsoft Corporation.
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

using System;
Expand Down Expand Up @@ -47,5 +47,24 @@ internal HealthCheckOptions DeepClone()
Path = Path,
};
}

internal static bool Equals(HealthCheckOptions options1, HealthCheckOptions options2)
{
if (options1 == null && options2 == null)
{
return true;
}

if (options1 == null || options2 == null)
{
return false;
}

return options1.Enabled == options2.Enabled
&& options1.Interval == options2.Interval
&& options1.Timeout == options2.Timeout
&& options1.Port == options2.Port
&& string.Equals(options1.Path, options2.Path, StringComparison.OrdinalIgnoreCase);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,20 @@ internal LoadBalancingOptions DeepClone()
Mode = Mode,
};
}

internal static bool Equals(LoadBalancingOptions options1, LoadBalancingOptions options2)
{
if (options1 == null && options2 == null)
{
return true;
}

if (options1 == null || options2 == null)
{
return false;
}

return options1.Mode == options2.Mode;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

using System;
using System.Security.Authentication;
using System.Security.Cryptography.X509Certificates;

Expand Down Expand Up @@ -30,5 +31,38 @@ internal ProxyHttpClientOptions DeepClone()
MaxConnectionsPerServer = MaxConnectionsPerServer
};
}

internal static bool Equals(ProxyHttpClientOptions options1, ProxyHttpClientOptions options2)
{
if (options1 == null && options2 == null)
{
return true;
}

if (options1 == null || options2 == null)
{
return false;
}

return options1.SslProtocols == options2.SslProtocols
&& Equals(options1.ClientCertificate, options2.ClientCertificate)
&& options1.DangerousAcceptAnyServerCertificate == options2.DangerousAcceptAnyServerCertificate
&& options1.MaxConnectionsPerServer == options2.MaxConnectionsPerServer;
}

private static bool Equals(X509Certificate2 certificate1, X509Certificate2 certificate2)
{
if (certificate1 == null && certificate2 == null)
{
return true;
}

if (certificate1 == null || certificate2 == null)
{
return false;
}

return string.Equals(certificate1.Thumbprint, certificate2.Thumbprint, StringComparison.OrdinalIgnoreCase);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) Microsoft Corporation.
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

namespace Microsoft.ReverseProxy.Abstractions
Expand Down Expand Up @@ -27,5 +27,21 @@ internal QuotaOptions DeepClone()
Burst = Burst,
};
}

internal static bool Equals(QuotaOptions options1, QuotaOptions options2)
{
if (options1 == null && options2 == null)
{
return true;
}

if (options1 == null || options2 == null)
{
return false;
}

return options1.Average == options2.Average
&& options1.Burst == options2.Burst;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System;
using System.Collections.Generic;
using Microsoft.ReverseProxy.Utilities;

namespace Microsoft.ReverseProxy.Abstractions
{
Expand Down Expand Up @@ -41,5 +42,23 @@ internal SessionAffinityOptions DeepClone()
Settings = Settings?.DeepClone(StringComparer.OrdinalIgnoreCase)
};
}

internal static bool Equals(SessionAffinityOptions options1, SessionAffinityOptions options2)
{
if (options1 == null && options2 == null)
{
return true;
}

if (options1 == null || options2 == null)
{
return false;
}

return options1.Enabled == options2.Enabled
&& string.Equals(options1.Mode, options2.Mode, StringComparison.OrdinalIgnoreCase)
&& string.Equals(options1.FailurePolicy, options2.FailurePolicy, StringComparison.OrdinalIgnoreCase)
&& CaseInsensitiveEqualHelper.Equals(options1.Settings, options2.Settings);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System;
using System.Collections.Generic;
using Microsoft.ReverseProxy.Utilities;

namespace Microsoft.ReverseProxy.Abstractions
{
Expand Down Expand Up @@ -30,5 +31,21 @@ Destination IDeepCloneable<Destination>.DeepClone()
Metadata = Metadata?.DeepClone(StringComparer.OrdinalIgnoreCase),
};
}

internal static bool Equals(Destination destination1, Destination destination2)
{
if (destination1 == null && destination2 == null)
{
return true;
}

if (destination1 == null || destination2 == null)
{
return false;
}

return string.Equals(destination1.Address, destination2.Address, StringComparison.OrdinalIgnoreCase)
&& CaseInsensitiveEqualHelper.Equals(destination1.Metadata, destination2.Metadata);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.ReverseProxy.Utilities;

namespace Microsoft.ReverseProxy.Abstractions
{
/// <summary>
/// Describes the matching criteria for a route.
/// </summary>
/// <summary>
/// Describes the matching criteria for a route.
/// </summary>
public class ProxyMatch : IDeepCloneable<ProxyMatch>
{
/// <summary>
Expand Down Expand Up @@ -48,5 +50,22 @@ ProxyMatch IDeepCloneable<ProxyMatch>.DeepClone()
// Headers = Headers.DeepClone(); // TODO:
};
}

internal static bool Equals(ProxyMatch proxyMatch1, ProxyMatch proxyMatch2)
{
if (proxyMatch1 == null && proxyMatch2 == null)
{
return true;
}

if (proxyMatch1 == null || proxyMatch2 == null)
{
return false;
}

return string.Equals(proxyMatch1.Path, proxyMatch2.Path, StringComparison.OrdinalIgnoreCase)
&& CaseInsensitiveEqualHelper.Equals(proxyMatch1.Hosts, proxyMatch2.Hosts)
&& CaseInsensitiveEqualHelper.Equals(proxyMatch1.Methods, proxyMatch2.Methods);
}
}
}
Loading

0 comments on commit c06d818

Please sign in to comment.