public void Should_be_comparable(string url1, string url2, bool expected) { var r1 = new TopologyReplica(UrlParser.Parse(url1)); var r2 = new TopologyReplica(UrlParser.Parse(url2)); r1.Equals(r2).Should().Be(expected); if (expected) { r1.GetHashCode().Should().Be(r2.GetHashCode()); } }
private IEnumerable <TopologyKey> ResolveInner(Uri url, string environment, string service) { if (!url.IsAbsoluteUri) { return(Enumerable.Empty <TopologyKey>()); } var replica = new TopologyReplica(ResolveHost(url.DnsSafeHost), url.Port, url.AbsolutePath); if (!topologies.TryGetValue((replica.Host, replica.Port), out var candidate) || !candidate.Any()) { return(Enumerable.Empty <TopologyKey>()); } var filteredByService = candidate.Where(c => c.Key.Service == service).ToList(); if (filteredByService.Any()) { candidate = filteredByService; } var filteredByEnvironment = candidate.Where(c => c.Key.Environment == environment).ToList(); if (filteredByEnvironment.Any()) { candidate = filteredByEnvironment; } var filteredByPath = candidate.Where(c => url.AbsolutePath.StartsWith(c.Replica.Path)).ToList(); if (!filteredByPath.Any()) { return(Enumerable.Empty <TopologyKey>()); } candidate = filteredByPath; var filteredBySource = candidate.Where(c => c.Source == TopologyReplicaMeta.SdSource).ToList(); if (filteredBySource.Any()) { candidate = filteredBySource; } var maxMatch = candidate.Max(c => c.Replica.Path.Length); candidate = candidate.Where(c => c.Replica.Path.Length == maxMatch).ToList(); return(candidate.Select(c => c.Key)); }
public TopologyReplicaMeta(TopologyKey key, TopologyReplica replica, int source) { Key = key; Replica = replica; Source = source; }